Aligns with the token-meter vocabulary of recent dsh releases (signed token delta) and with the existing zh label 增量. UI labels, i18n keys, settings schema, client logic and tests all switch from diff to delta. The settings schema is now loose on defaultTrendMode so a stale persisted value degrades to the default instead of throwing, and the client ignores unrecognized values the same way.
45 lines
1.8 KiB
TypeScript
45 lines
1.8 KiB
TypeScript
/**
|
|
* dsh-context user settings — the per-user preference namespace served to
|
|
* browsers through the harness settings seam (`ctx.settings`).
|
|
*
|
|
* Distinct from the cordis `config:` block (config.ts), which is
|
|
* deployment-level: the settings document is per-user and GUI-editable
|
|
* (Settings → Plugins → Plugin configuration, the `settings.plugin.item`
|
|
* card keyed by this namespace). The Host half only REGISTERS the namespace
|
|
* — every field is a client-side display preference, so nothing here is
|
|
* consumed on the Host.
|
|
*
|
|
* Optional composition: a deployment without a settings provider never runs
|
|
* the inject callback and browsers simply see no card (schema defaults win).
|
|
*/
|
|
|
|
import type { Context } from '@deepseek-ai/cordis'
|
|
import { settingsNamespace } from '@deepseek-ai/dsh-settings'
|
|
import z from '@deepseek-ai/schemastery'
|
|
|
|
/** The namespace is the join key between the Host registration and the browser card. */
|
|
export const SETTINGS_NAMESPACE = 'dsh-context'
|
|
|
|
export type DefaultGranularity = 'step' | 'turn'
|
|
|
|
export type DefaultTrendMode = 'total' | 'delta'
|
|
|
|
export interface PluginSettings {
|
|
defaultGranularity: DefaultGranularity
|
|
defaultTrendMode: DefaultTrendMode
|
|
}
|
|
|
|
/** Section schema: also the wire envelope the browser scope validates against. */
|
|
export const SettingsSchema: z<PluginSettings> = z.object({
|
|
defaultGranularity: z.union(['step', 'turn']).default('step'),
|
|
// Loose: a stale persisted value degrades to the default instead of breaking the section.
|
|
defaultTrendMode: z.union(['total', 'delta']).default('total').loose(),
|
|
})
|
|
|
|
/** Serve the namespace while a settings provider is composed; inert otherwise. */
|
|
export function installSettings(ctx: Context): void {
|
|
ctx.inject(['settings'], (sctx) => {
|
|
sctx.settings.register(settingsNamespace(SETTINGS_NAMESPACE), SettingsSchema)
|
|
})
|
|
}
|