refactor(gui): features register their own settings surfaces
Settings collaboration direction (recorded in the note): the shell only provides composition faces — feature plugins register themselves. The General section moves into the ui-settings shell (order 0, skeleton rows) and declares the settings.general.item list slot; locale registers the Language row and ui-theme the Appearance row (each with its own store mirror, dictionaries, and ledger-judged deferral); the ui-settings-general package is gone. ui-settings-models becomes ui-models — a feature package that contributes its Settings section rather than a settings-owned satellite. The item-slot SlotMap entry is authored in the ui-settings contract and repeated verbatim in locale/ui-theme (reference-cycle avoidance; declaration merging keeps the copies identical).
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
# @deepseek-ai/dsh-client-ui-settings-general
|
||||
|
||||
General settings section plugin: registers the `general` entry into `settings.section`. Language (中文/English) and Appearance (Light/Dark/System) are live preferences wired to `ctx.locale` / `ctx.theme`; Permission and Tool Call rows are visual skeletons with no write surface.
|
||||
|
||||
## Model Experience
|
||||
|
||||
None, as the section renders browser preference UI; nothing here reaches a model request.
|
||||
|
||||
#### KV Cache effect
|
||||
|
||||
None; this package neither assembles nor sends a provider request.
|
||||
|
||||
## Known Limitations and Deferred Work
|
||||
|
||||
- **Permission and Tool Call are display skeletons** — the backing host services and RPC methods do not exist yet; the controls are disabled and write nothing.
|
||||
@@ -1,70 +0,0 @@
|
||||
{
|
||||
"name": "@deepseek-ai/dsh-client-ui-settings-general",
|
||||
"description": "General settings section plugin: Language and Appearance preferences (live), Permission and Tool Call skeleton rows",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/types/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/types/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./invariant": {
|
||||
"types": "./lib/types/invariant.d.ts",
|
||||
"default": "./lib/invariant.js"
|
||||
},
|
||||
"./client": {
|
||||
"types": "./lib/types/client/index.d.ts",
|
||||
"default": "./lib/client.js"
|
||||
},
|
||||
"./src/*": "./src/*",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"dshClient": {
|
||||
"inject": [
|
||||
"@deepseek-ai/dsh-client-runtime",
|
||||
"@deepseek-ai/dsh-client-ui-settings",
|
||||
"@deepseek-ai/dsh-client-locale",
|
||||
"@deepseek-ai/dsh-client-ui-theme"
|
||||
],
|
||||
"platform": "web"
|
||||
},
|
||||
"scripts": {
|
||||
"bundle": "tsdown",
|
||||
"watch": "tsdown --watch"
|
||||
},
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"clsx": "^2.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@deepseek-ai/dsh-client-runtime": "^0.0.1",
|
||||
"@deepseek-ai/dsh-client-ui-primitives": "^0.0.1",
|
||||
"@deepseek-ai/dsh-client-ui-slots": "^0.0.1",
|
||||
"@deepseek-ai/dsh-invariants": "^0.0.1",
|
||||
"cordis": "^4.0.0-rc.7",
|
||||
"react": "^18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@deepseek-ai/dsh-client-locale": "workspace:^",
|
||||
"@deepseek-ai/dsh-client-runtime": "workspace:^",
|
||||
"@deepseek-ai/dsh-client-ui-primitives": "workspace:^",
|
||||
"@deepseek-ai/dsh-client-ui-settings": "workspace:^",
|
||||
"@deepseek-ai/dsh-client-ui-slots": "workspace:^",
|
||||
"@deepseek-ai/dsh-client-ui-theme": "workspace:^",
|
||||
"@deepseek-ai/dsh-invariants": "workspace:^",
|
||||
"@types/react": "~18.3.1",
|
||||
"cordis": "^4.0.0-rc.7",
|
||||
"react": "^18.2.0"
|
||||
},
|
||||
"files": [
|
||||
"lib/index.js",
|
||||
"lib/invariant.js",
|
||||
"lib/client.js",
|
||||
"lib/types/**/*.d.ts",
|
||||
"lib/types/**/*.d.ts.map",
|
||||
"src"
|
||||
]
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/* General section rows (figma 501:29983 'Options'): four groups, 16px
|
||||
* vertical padding each, hairline separator under all but the last. The
|
||||
* shell's content column owns the outer horizontal padding. */
|
||||
|
||||
.section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Title + trailing control row (figma 'Setting-Cell': gap 8, pad 16/0). */
|
||||
.row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 16px 0;
|
||||
border-bottom: 1px solid var(--dsw-alias-border-l2);
|
||||
}
|
||||
|
||||
/* Title + full-width body group (figma 'Frame 2117131229': column, gap 8). */
|
||||
.group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
padding: 16px 0;
|
||||
border-bottom: 1px solid var(--dsw-alias-border-l2);
|
||||
}
|
||||
|
||||
.last {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
/* Leading text column (figma 'Frame 2036083120': gap 4, pad-right 48). */
|
||||
.rowText {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding-right: 48px;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
line-height: 22px;
|
||||
color: var(--dsw-alias-label-primary);
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
line-height: 18px;
|
||||
color: var(--dsw-alias-label-tertiary);
|
||||
}
|
||||
|
||||
/* Selector pill (figma 'Selector': h36 r18, fill #F5F6F7, pad 0/14, gap 12). */
|
||||
.selector {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
height: 36px;
|
||||
padding: 0 14px;
|
||||
border: none;
|
||||
border-radius: 18px;
|
||||
background: var(--dsw-alias-bg-module-platform);
|
||||
font: inherit;
|
||||
font-size: 14px;
|
||||
line-height: 22px;
|
||||
color: var(--dsw-alias-label-primary);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.selector:disabled {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.chevron {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
/* Cube rows share an 8px gap; cubes stretch to equal height. */
|
||||
.cubeRow {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* Tool Call mode cube (figma '.Selector Cube' 418w r16; horizontal inset =
|
||||
* outer pad 4 + inner .Menu_cell pad 10, vertical = inner pad 8). */
|
||||
.modeCube {
|
||||
box-sizing: border-box;
|
||||
width: 418px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 2px;
|
||||
padding: 8px 14px;
|
||||
border: 1px solid var(--dsw-alias-border-l2);
|
||||
border-radius: 16px;
|
||||
background: transparent;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
/* Appearance cube (figma '.Selector Cube' 276x82 r16, pad 20/32, centered
|
||||
* icon-over-label column, gap 4). */
|
||||
.themeCube {
|
||||
box-sizing: border-box;
|
||||
width: 276px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
padding: 20px 32px;
|
||||
border: 1px solid var(--dsw-alias-border-l2);
|
||||
border-radius: 16px;
|
||||
background: transparent;
|
||||
font: inherit;
|
||||
font-size: 14px;
|
||||
line-height: 22px;
|
||||
color: var(--dsw-alias-label-primary);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Selected cube: #F5F6F7 fill + #ADB2B8 border (static token — the bluish-400
|
||||
* step has no alias-layer name). */
|
||||
.selected {
|
||||
background: var(--dsw-alias-bg-module-platform);
|
||||
border-color: var(--dsw-static-neutral-bluish-400);
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
/**
|
||||
* General settings section: Permission and Tool Call skeleton rows (visual
|
||||
* only, no interaction), live Language and Appearance preference rows wired
|
||||
* through the injected setLocale/setTheme callbacks and the snapshot-mirror
|
||||
* store. Figma: Settings > Content > Options (501:29983).
|
||||
*/
|
||||
import { useState } from 'react'
|
||||
import clsx from 'clsx'
|
||||
import {
|
||||
IconChevronDownOutline14, IconDarkOutline16, IconFollowsystemOutline16, IconLightOutline16,
|
||||
Menu,
|
||||
} from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import type { GeneralSectionComponentProps, ThemePreferenceId } from './contract.ts'
|
||||
import css from './GeneralSection.module.css'
|
||||
|
||||
/** Appearance cube order and icons (figma 501:30015-30017: Light, Dark, System). */
|
||||
const THEME_CUBES: readonly { id: ThemePreferenceId; labelKey: string; Icon: typeof IconLightOutline16 }[] = [
|
||||
{ id: 'light', labelKey: 'appearance.light', Icon: IconLightOutline16 },
|
||||
{ id: 'dark', labelKey: 'appearance.dark', Icon: IconDarkOutline16 },
|
||||
{ id: 'system', labelKey: 'appearance.system', Icon: IconFollowsystemOutline16 },
|
||||
]
|
||||
|
||||
/**
|
||||
* Render the General section content column.
|
||||
* @param props - composed slot props (contract.ts).
|
||||
* @returns the section element tree.
|
||||
*/
|
||||
export function GeneralSection(props: GeneralSectionComponentProps) {
|
||||
const { t, setLocale, setTheme, useStore } = props
|
||||
const localeActive = useStore(s => s.localeActive)
|
||||
const localeOptions = useStore(s => s.localeOptions)
|
||||
const themePreference = useStore(s => s.themePreference)
|
||||
const [languageOpen, setLanguageOpen] = useState(false)
|
||||
|
||||
const activeLocaleLabel = localeOptions.find(l => l.id === localeActive)?.label ?? localeActive
|
||||
|
||||
return (
|
||||
<div className={css.section}>
|
||||
{/* Permission (skeleton): disabled selector pill. */}
|
||||
<div className={css.row}>
|
||||
<div className={css.rowText}>
|
||||
<div className={css.title}>{t('permission.title')}</div>
|
||||
<div className={css.desc}>{t('permission.desc')}</div>
|
||||
</div>
|
||||
<button type="button" className={css.selector} disabled>
|
||||
{t('permission.value')}
|
||||
<IconChevronDownOutline14 className={css.chevron} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Tool Call (skeleton): schema cube pinned selected, code cube unselected. */}
|
||||
<div className={css.group}>
|
||||
<div className={css.title}>{t('toolcall.title')}</div>
|
||||
<div className={css.cubeRow}>
|
||||
<div className={clsx(css.modeCube, css.selected)}>
|
||||
<div className={css.title}>{t('toolcall.schema.title')}</div>
|
||||
<div className={css.desc}>{t('toolcall.schema.desc')}</div>
|
||||
</div>
|
||||
<div className={css.modeCube}>
|
||||
<div className={css.title}>{t('toolcall.code.title')}</div>
|
||||
<div className={css.desc}>{t('toolcall.code.desc')}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Language: selector pill opens the locale menu. */}
|
||||
<div className={css.row}>
|
||||
<div className={css.rowText}>
|
||||
<div className={css.title}>{t('language.title')}</div>
|
||||
</div>
|
||||
<Menu
|
||||
open={languageOpen}
|
||||
onClose={() => { setLanguageOpen(false) }}
|
||||
items={localeOptions.map(l => ({ id: l.id, label: l.label }))}
|
||||
selectedId={localeActive}
|
||||
onSelect={(id) => {
|
||||
setLocale(id)
|
||||
setLanguageOpen(false)
|
||||
}}
|
||||
align="end"
|
||||
portal
|
||||
anchor={(
|
||||
<button
|
||||
type="button"
|
||||
className={css.selector}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={languageOpen}
|
||||
onClick={() => { setLanguageOpen(v => !v) }}
|
||||
>
|
||||
{activeLocaleLabel}
|
||||
<IconChevronDownOutline14 className={css.chevron} />
|
||||
</button>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Appearance: three preference cubes; selection follows the persisted
|
||||
* preference, never the resolved active theme. */}
|
||||
<div className={clsx(css.group, css.last)}>
|
||||
<div className={css.title}>{t('appearance.title')}</div>
|
||||
<div className={css.cubeRow}>
|
||||
{THEME_CUBES.map(({ id, labelKey, Icon }) => (
|
||||
<button
|
||||
key={id}
|
||||
type="button"
|
||||
className={clsx(css.themeCube, themePreference === id && css.selected)}
|
||||
aria-pressed={themePreference === id}
|
||||
onClick={() => { setTheme(id) }}
|
||||
>
|
||||
<Icon />
|
||||
{t(labelKey)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/**
|
||||
* General section component contract: the slot-store state shape, the
|
||||
* injected business face, and the composed props type. The component imports
|
||||
* only from here; service snapshot shapes are mirrored as plain rows so the
|
||||
* presentation layer stays decoupled from the locale/theme packages.
|
||||
*/
|
||||
import type { PropsRuntime, PropsStore } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
// Type-only: pulls the shell's SlotMap merge (the 'settings.section' entry).
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
||||
import type { createGeneralSettingsStore } from './store.ts'
|
||||
|
||||
/** One selectable locale row projected into the store (id + self-described label). */
|
||||
export interface LocaleOptionRow {
|
||||
/** Locale id (the setLocale argument). */
|
||||
id: string
|
||||
/** Display name in its own language (中文 / English). */
|
||||
label: string
|
||||
}
|
||||
|
||||
/** Theme preference union mirrored from the theme service snapshot. */
|
||||
export type ThemePreferenceId = 'light' | 'dark' | 'system'
|
||||
|
||||
/**
|
||||
* Store state: mirrors of the locale/theme service snapshots, written only by
|
||||
* the plugin's apply-world change listeners (components have no write path —
|
||||
* preference writes go through the injected callbacks to the services, and
|
||||
* the resulting change events flow back into this mirror).
|
||||
*/
|
||||
export interface GeneralSettingsState {
|
||||
/** Active locale id. */
|
||||
localeActive: string
|
||||
/** Selectable locales in display order. */
|
||||
localeOptions: LocaleOptionRow[]
|
||||
/** Locale service revision (re-renders translated copy on dictionary/locale changes); -1 until first sync. */
|
||||
localeRevision: number
|
||||
/** Persisted theme preference (selection state reads this, never the resolved active theme). */
|
||||
themePreference: ThemePreferenceId
|
||||
/** Theme service revision; -1 until first sync. */
|
||||
themeRevision: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Registrant-private injected share of the General section (assembled in
|
||||
* apply): the namespace-bound translate function (stable identity — re-render
|
||||
* on locale change comes from the store revision, not from `t`) and the two
|
||||
* preference write callbacks.
|
||||
*/
|
||||
export interface GeneralSectionInjected {
|
||||
/** Translate a `settings.general` dictionary key to the active-locale text. */
|
||||
t: (key: string) => string
|
||||
/** Switch the active locale (a registered locale id). */
|
||||
setLocale: (id: string) => void
|
||||
/** Switch the theme preference. */
|
||||
setTheme: (id: ThemePreferenceId) => void
|
||||
}
|
||||
|
||||
/** Store handle type for the props share (type-only; the factory stays internal to apply and tests). */
|
||||
export type GeneralSettingsStoreHandle = ReturnType<typeof createGeneralSettingsStore>
|
||||
|
||||
/**
|
||||
* Full component props of the General section: the section owner share
|
||||
* (empty marker) plus the store share and the injected face. No child slots
|
||||
* are declared; menu open state is component-local viewing state.
|
||||
*/
|
||||
export type GeneralSectionComponentProps =
|
||||
PropsRuntime<'settings.section'> & PropsStore<GeneralSettingsStoreHandle> & GeneralSectionInjected
|
||||
@@ -1,117 +0,0 @@
|
||||
/**
|
||||
* General settings section plugin, browser half. Registers the `general`
|
||||
* entry into the shell-declared `settings.section` list slot; Language and
|
||||
* Appearance are live preferences projected from ctx.locale / ctx.theme
|
||||
* through this entry's slot store. Export discipline: packages/client/AGENTS.md.
|
||||
*/
|
||||
import type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client'
|
||||
import type { BoundActions } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
// Type-only: pulls the shell's SlotMap merge (the 'settings.section' entry).
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
||||
// Type-only: the locale/theme Context+Events merges and snapshot shapes.
|
||||
import type { LocaleSnapshot } from '@deepseek-ai/dsh-client-locale/client'
|
||||
import type { ThemeSnapshot } from '@deepseek-ai/dsh-client-ui-theme/client'
|
||||
import type { GeneralSectionInjected } from './contract.ts'
|
||||
import { createGeneralSettingsStore } from './store.ts'
|
||||
import { en, zh } from './locales.ts'
|
||||
import { GeneralSection } from './GeneralSection.tsx'
|
||||
|
||||
export type {
|
||||
GeneralSectionComponentProps, GeneralSectionInjected, GeneralSettingsState,
|
||||
GeneralSettingsStoreHandle, LocaleOptionRow, ThemePreferenceId,
|
||||
} from './contract.ts'
|
||||
|
||||
/** Dictionary namespace owned by this section (also the nav-label reference prefix). */
|
||||
const NS = 'settings.general'
|
||||
|
||||
/**
|
||||
* Required services (cordis fiber inject). The target slot is declared by
|
||||
* ui-settings' apply, whose activation order relative to this one is NOT
|
||||
* constrained; registration goes through declaration-aware deferral.
|
||||
*/
|
||||
export const inject = ['slots', 'locale', 'theme']
|
||||
|
||||
/**
|
||||
* Register the `settings.general` dictionaries and the General section entry
|
||||
* once the `settings.section` declaration is on the ledger. The slot store
|
||||
* mirrors the locale/theme snapshots: change listeners attach here in apply,
|
||||
* write through the bound actions captured at inject time, and the inject
|
||||
* factory re-syncs from the getters so no event is lost between registration
|
||||
* and first render (the store's revision guard drops stale duplicates).
|
||||
* @param ctx - client root context.
|
||||
*/
|
||||
export function apply(ctx: ClientContext): void {
|
||||
ctx.effect(() => {
|
||||
const disposeZh = ctx.locale.register(NS, 'zh', zh)
|
||||
const disposeEn = ctx.locale.register(NS, 'en', en)
|
||||
return () => {
|
||||
disposeZh()
|
||||
disposeEn()
|
||||
}
|
||||
}, 'ui-settings-general: dictionaries')
|
||||
|
||||
const store = createGeneralSettingsStore()
|
||||
let bound: BoundActions<typeof store> | undefined
|
||||
|
||||
const syncLocale = (snapshot: LocaleSnapshot): void => {
|
||||
bound?.syncLocale(
|
||||
snapshot.active,
|
||||
snapshot.locales.map(l => ({ id: l.id, label: l.label })),
|
||||
snapshot.revision,
|
||||
)
|
||||
}
|
||||
const syncTheme = (snapshot: ThemeSnapshot): void => {
|
||||
bound?.syncTheme(snapshot.preference, snapshot.revision)
|
||||
}
|
||||
ctx.on('locale/change', syncLocale)
|
||||
ctx.on('theme/change', syncTheme)
|
||||
|
||||
const injected = (actions: BoundActions<typeof store>): GeneralSectionInjected => {
|
||||
bound = actions
|
||||
syncLocale(ctx.locale.getLocale())
|
||||
syncTheme(ctx.theme.getTheme())
|
||||
return {
|
||||
t: ctx.locale.bind(NS),
|
||||
setLocale: (id) => { ctx.locale.setLocale(id) },
|
||||
setTheme: (id) => { ctx.theme.setTheme(id) },
|
||||
}
|
||||
}
|
||||
|
||||
ctx.effect(() => {
|
||||
let dispose: (() => void) | undefined
|
||||
// Presence is judged on the ledger, not on the local disposer: an HMR
|
||||
// collapse of the declaring entry removes this entry from the slot core
|
||||
// while `dispose` stays set (the stale disposer is a no-op), so a local
|
||||
// guard would block the re-registration when the declaration returns.
|
||||
const registered = (): boolean =>
|
||||
ctx.slots.entries('settings.section').some(e => e.component === GeneralSection)
|
||||
const tryRegister = (): void => {
|
||||
if (ctx.slots.spec('settings.section') === undefined || registered()) return
|
||||
dispose = ctx.slots.register({
|
||||
name: 'settings.section',
|
||||
id: 'general',
|
||||
order: 0,
|
||||
label: ctx.locale.bind(NS)('nav'),
|
||||
store,
|
||||
inject: injected,
|
||||
}, GeneralSection)
|
||||
}
|
||||
// Nav labels are registrant-localized: re-register on locale change so
|
||||
// the ledger carries fresh text (the version bump re-renders the shell).
|
||||
// The ledger check mirrors tryRegister: after an HMR collapse `dispose`
|
||||
// stays set while the entry is gone — relabeling then must stay quiet.
|
||||
const offLocale = ctx.on('locale/change', () => {
|
||||
if (dispose === undefined || !registered()) return
|
||||
dispose()
|
||||
dispose = undefined
|
||||
tryRegister()
|
||||
})
|
||||
const unsubscribe = ctx.slots.subscribe('settings.section', () => { tryRegister() })
|
||||
tryRegister()
|
||||
return () => {
|
||||
offLocale()
|
||||
unsubscribe()
|
||||
dispose?.()
|
||||
}
|
||||
}, 'ui-settings-general: section registration')
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/**
|
||||
* `settings.general` namespace dictionaries. Skeleton-row technical copy
|
||||
* (Read only / Schema mode / Code mode and their descriptions) is shared
|
||||
* verbatim across locales per the Figma design.
|
||||
*/
|
||||
import type { LocaleDict } from '@deepseek-ai/dsh-client-locale/client'
|
||||
|
||||
const SHARED = {
|
||||
'permission.value': 'Read only',
|
||||
'toolcall.schema.title': 'Schema mode',
|
||||
'toolcall.schema.desc': 'Traditional function calling — invoke tools one at a time',
|
||||
'toolcall.code.title': 'Code mode',
|
||||
'toolcall.code.desc': 'Chain multiple tools with code — multi-step orchestration',
|
||||
} satisfies LocaleDict
|
||||
|
||||
/** Simplified Chinese dictionary. */
|
||||
export const zh: LocaleDict = {
|
||||
...SHARED,
|
||||
'nav': '通用设置',
|
||||
'permission.title': '权限',
|
||||
'permission.desc': '选择默认权限模式',
|
||||
'toolcall.title': '工具调用',
|
||||
'language.title': '语言',
|
||||
'appearance.title': '外观',
|
||||
'appearance.light': '浅色',
|
||||
'appearance.dark': '深色',
|
||||
'appearance.system': '跟随系统',
|
||||
}
|
||||
|
||||
/** English dictionary. */
|
||||
export const en: LocaleDict = {
|
||||
...SHARED,
|
||||
'nav': 'General',
|
||||
'permission.title': 'Permission',
|
||||
'permission.desc': 'Choose default permission mode',
|
||||
'toolcall.title': 'Tool Call',
|
||||
'language.title': 'Language',
|
||||
'appearance.title': 'Appearance',
|
||||
'appearance.light': 'Light',
|
||||
'appearance.dark': 'Dark',
|
||||
'appearance.system': 'System',
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/**
|
||||
* General section slot store: locale/theme snapshot mirrors. The plugin
|
||||
* creates the handle at apply time (identity follows the fiber) and its
|
||||
* change listeners are the only writers; components read via props.useStore.
|
||||
*/
|
||||
import { defineStore, type EngineStoreHandle } from '@deepseek-ai/dsh-client-runtime/client'
|
||||
import type { GeneralSettingsState, LocaleOptionRow, ThemePreferenceId } from './contract.ts'
|
||||
|
||||
/** Declared action shape used to give the exported factory a stable return type. */
|
||||
type GeneralSettingsActions = {
|
||||
syncLocale: (draft: GeneralSettingsState, active: string, options: LocaleOptionRow[], revision: number) => void
|
||||
syncTheme: (draft: GeneralSettingsState, preference: ThemePreferenceId, revision: number) => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares the General section state and write surface. Revisions start at -1
|
||||
* so the apply-time initial sync (revision 0) always lands as a change.
|
||||
* @returns the store handle.
|
||||
*/
|
||||
export function createGeneralSettingsStore(): EngineStoreHandle<GeneralSettingsState, GeneralSettingsActions> {
|
||||
return defineStore({
|
||||
init: (): GeneralSettingsState => ({
|
||||
localeActive: '',
|
||||
localeOptions: [],
|
||||
localeRevision: -1,
|
||||
themePreference: 'system',
|
||||
themeRevision: -1,
|
||||
}),
|
||||
actions: {
|
||||
syncLocale: (d, active: string, options: LocaleOptionRow[], revision: number) => {
|
||||
if (revision <= d.localeRevision) return
|
||||
d.localeActive = active
|
||||
d.localeOptions = options
|
||||
d.localeRevision = revision
|
||||
},
|
||||
syncTheme: (d, preference: ThemePreferenceId, revision: number) => {
|
||||
if (revision <= d.themeRevision) return
|
||||
d.themePreference = preference
|
||||
d.themeRevision = revision
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
declare module '*.module.css' {
|
||||
const classes: Record<string, string>
|
||||
export default classes
|
||||
}
|
||||
|
||||
declare module '*.css'
|
||||
@@ -1,4 +0,0 @@
|
||||
/** Host loader entry for the browser implementation exported from `./client`. */
|
||||
|
||||
/** Host plugin body — no host-side behavior for the general settings plugin. */
|
||||
export function apply(): void {}
|
||||
@@ -1,32 +0,0 @@
|
||||
/**
|
||||
* Package-owned invariant companion for `@deepseek-ai/dsh-client-ui-settings-general`.
|
||||
* @module @deepseek-ai/dsh-client-ui-settings-general/invariant
|
||||
*/
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-client-ui-settings-general'
|
||||
|
||||
/** Cordis companion plugin name. */
|
||||
export const name = 'client-ui-settings-general-invariant'
|
||||
/** Service required before the companion can reserve package ownership. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/**
|
||||
* No runtime invariant: a section plugin projecting two service change events
|
||||
* into its own slot store — it emits no cordis events of its own and owns no
|
||||
* cross-plugin mutable relation; snapshot/store agreement is asserted by this
|
||||
* package's behavior specs.
|
||||
*/
|
||||
const install: InvariantInstaller = () => {}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
* @param ctx - Cordis context carrying the invariant service.
|
||||
* @returns the installed registration's disposer after setup succeeds.
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
@@ -1,139 +0,0 @@
|
||||
/** apply wiring: dictionary registration, declaration-aware section entry,
|
||||
* snapshot projection into the slot store, locale-driven relabeling, and
|
||||
* recovery after an HMR collapse of the declaring entry. */
|
||||
import { Context } from 'cordis'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { SlotsService } from '@deepseek-ai/dsh-client-runtime/client'
|
||||
import { LocaleService } from '@deepseek-ai/dsh-client-locale/client'
|
||||
import { ThemeService } from '@deepseek-ai/dsh-client-ui-theme/client'
|
||||
import { apply, inject } from '@deepseek-ai/dsh-client-ui-settings-general/client'
|
||||
import type { GeneralSectionInjected } from '@deepseek-ai/dsh-client-ui-settings-general/client'
|
||||
import { GeneralSection } from '../src/client/GeneralSection.tsx'
|
||||
import type { createGeneralSettingsStore } from '../src/client/store.ts'
|
||||
|
||||
const NS = 'settings.general'
|
||||
|
||||
async function bench() {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(SlotsService).await()
|
||||
const locale = new LocaleService(ctx)
|
||||
const theme = new ThemeService(ctx)
|
||||
ctx.provide('locale', locale)
|
||||
ctx.provide('theme', theme)
|
||||
return { ctx, slots: ctx.get('slots') as SlotsService, locale, theme }
|
||||
}
|
||||
|
||||
/** Stand in for the settings shell: declare the section list slot from root. */
|
||||
function declareSection(slots: SlotsService): () => void {
|
||||
return slots.register(
|
||||
{ name: 'root', children: { 'settings.section': { kind: 'list', scope: 'root' } } } as never,
|
||||
() => null,
|
||||
)
|
||||
}
|
||||
|
||||
/** Mirror the framework's inject choreography: bake a real instance from the
|
||||
* declared handle and hand its actions to the entry's inject factory. */
|
||||
function faceOf(slots: SlotsService) {
|
||||
const entry = slots.entries('settings.section')[0]!
|
||||
const handle = entry.store as ReturnType<typeof createGeneralSettingsStore>
|
||||
const instance = handle.create()
|
||||
const face = (entry.inject as unknown as (a: typeof instance.actions) => GeneralSectionInjected)(instance.actions)
|
||||
return { entry, instance, face }
|
||||
}
|
||||
|
||||
describe('ui-settings-general apply', () => {
|
||||
it('declares the slot, locale, and theme services', () => {
|
||||
expect(inject).toEqual(['slots', 'locale', 'theme'])
|
||||
})
|
||||
|
||||
it('registers dictionaries and the section entry for declarations before or after apply', async () => {
|
||||
const before = await bench()
|
||||
declareSection(before.slots)
|
||||
await before.ctx.plugin({ inject: [...inject], apply }).await()
|
||||
const entry = before.slots.entries('settings.section')[0]!
|
||||
expect(entry.component).toBe(GeneralSection)
|
||||
expect(entry.options).toMatchObject({ id: 'general', order: 0, label: '通用设置' })
|
||||
expect(before.locale.bind(NS)('nav')).toBe('通用设置')
|
||||
|
||||
const after = await bench()
|
||||
const fiber = after.ctx.plugin({ inject: [...inject], apply })
|
||||
await fiber.await()
|
||||
expect(after.slots.entries('settings.section')).toHaveLength(0)
|
||||
declareSection(after.slots)
|
||||
await Promise.resolve()
|
||||
expect(after.slots.entries('settings.section')[0]!.component).toBe(GeneralSection)
|
||||
// Teardown without a live registration exercises the undefined-disposer arm.
|
||||
await fiber.dispose()
|
||||
expect(after.slots.entries('settings.section')).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('projects service snapshots into the store and routes face writes back', async () => {
|
||||
const b = await bench()
|
||||
declareSection(b.slots)
|
||||
await b.ctx.plugin({ inject: [...inject], apply }).await()
|
||||
// Events ahead of any inject hit the unbound-actions arm without a store.
|
||||
b.theme.setTheme('dark')
|
||||
|
||||
const { instance, face } = faceOf(b.slots)
|
||||
// The inject-time re-sync sealed the init window: both mirrors are current.
|
||||
expect(instance.getSnapshot().localeActive).toBe('zh')
|
||||
expect(instance.getSnapshot().localeOptions.map(l => l.id)).toEqual(['zh', 'en'])
|
||||
expect(instance.getSnapshot().themePreference).toBe('dark')
|
||||
expect(face.t('nav')).toBe('通用设置')
|
||||
|
||||
face.setLocale('en')
|
||||
expect(b.locale.getLocale().active).toBe('en')
|
||||
expect(instance.getSnapshot().localeActive).toBe('en')
|
||||
expect(face.t('nav')).toBe('General')
|
||||
|
||||
face.setTheme('system')
|
||||
expect(b.theme.getTheme().preference).toBe('system')
|
||||
expect(instance.getSnapshot().themePreference).toBe('system')
|
||||
})
|
||||
|
||||
it('re-registers with a fresh ledger label when the locale changes', async () => {
|
||||
const b = await bench()
|
||||
declareSection(b.slots)
|
||||
await b.ctx.plugin({ inject: [...inject], apply }).await()
|
||||
expect(b.slots.entries('settings.section')[0]!.options.label).toBe('通用设置')
|
||||
b.locale.setLocale('en')
|
||||
const entry = b.slots.entries('settings.section')[0]!
|
||||
expect(entry.options.label).toBe('General')
|
||||
expect(entry.component).toBe(GeneralSection)
|
||||
})
|
||||
|
||||
it('recovers after an HMR collapse of the declaring entry (stale disposer must not block)', async () => {
|
||||
const b = await bench()
|
||||
const host = declareSection(b.slots)
|
||||
await b.ctx.plugin({ inject: [...inject], apply }).await()
|
||||
expect(b.slots.entries('settings.section')).toHaveLength(1)
|
||||
|
||||
// Collapse: the declarer dies, the cascade removes our entry while the
|
||||
// apply closure still holds its (now stale) disposer.
|
||||
host()
|
||||
expect(b.slots.entries('settings.section')).toHaveLength(0)
|
||||
|
||||
// A locale change inside the collapsed window must stay quiet.
|
||||
b.locale.setLocale('en')
|
||||
expect(b.slots.entries('settings.section')).toHaveLength(0)
|
||||
|
||||
// Redeclaration restores the entry — with the current locale's label.
|
||||
declareSection(b.slots)
|
||||
await Promise.resolve()
|
||||
const entry = b.slots.entries('settings.section')[0]!
|
||||
expect(entry.component).toBe(GeneralSection)
|
||||
expect(entry.options.label).toBe('General')
|
||||
})
|
||||
|
||||
it('removes the entry and the dictionaries on teardown', async () => {
|
||||
const b = await bench()
|
||||
declareSection(b.slots)
|
||||
const fiber = b.ctx.plugin({ inject: [...inject], apply })
|
||||
await fiber.await()
|
||||
expect(b.slots.entries('settings.section')).toHaveLength(1)
|
||||
await fiber.dispose()
|
||||
expect(b.slots.entries('settings.section')).toHaveLength(0)
|
||||
// Dictionary disposal: translation falls back to the bare key.
|
||||
expect(b.locale.bind(NS)('nav')).toBe('nav')
|
||||
})
|
||||
})
|
||||
@@ -1,112 +0,0 @@
|
||||
// @vitest-environment jsdom
|
||||
/** GeneralSection behavior: skeleton rows stay inert, Language menu drives
|
||||
* setLocale, Appearance cubes follow the preference and drive setTheme. */
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import { createSnapshotStore, type SessionListState, type WorkspaceListState } from '@deepseek-ai/dsh-client-runtime/client'
|
||||
import { bindSnapshotSelector } from '@deepseek-ai/dsh-client-web-react'
|
||||
import { GeneralSection } from '../src/client/GeneralSection.tsx'
|
||||
import { createGeneralSettingsStore } from '../src/client/store.ts'
|
||||
import { en } from '../src/client/locales.ts'
|
||||
import type { GeneralSectionComponentProps } from '../src/client/contract.ts'
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
const LOCALES = [{ id: 'zh', label: '中文' }, { id: 'en', label: 'English' }]
|
||||
|
||||
/** Empty global standard-kit hooks (the section reads neither). */
|
||||
function emptySessions() {
|
||||
const store = createSnapshotStore<SessionListState>(
|
||||
{ ids: [], byId: {}, current: undefined, intent: undefined, phase: 'ready' })
|
||||
return bindSnapshotSelector(store)
|
||||
}
|
||||
function emptyWorkspaces() {
|
||||
const store = createSnapshotStore<WorkspaceListState>({
|
||||
items: [], intent: undefined, state: 'idle', phase: 'ready', error: null,
|
||||
baselinesReady: true, recentWorkspaceId: undefined,
|
||||
})
|
||||
return bindSnapshotSelector(store)
|
||||
}
|
||||
|
||||
function mount(init?: { active?: string; preference?: 'light' | 'dark' | 'system' }) {
|
||||
// Real store instance — the sanctioned zero-machinery path for tests.
|
||||
const store = createGeneralSettingsStore().create()
|
||||
store.actions.syncLocale(init?.active ?? 'en', LOCALES, 0)
|
||||
store.actions.syncTheme(init?.preference ?? 'system', 0)
|
||||
const setLocale = vi.fn()
|
||||
const setTheme = vi.fn()
|
||||
const props: GeneralSectionComponentProps = {
|
||||
useSessions: emptySessions(),
|
||||
useWorkspaces: emptyWorkspaces(),
|
||||
useStore: bindSnapshotSelector(store),
|
||||
actions: store.actions,
|
||||
t: (key: string) => en[key] ?? key,
|
||||
setLocale,
|
||||
setTheme,
|
||||
}
|
||||
render(<GeneralSection {...props} />)
|
||||
return { store, setLocale, setTheme }
|
||||
}
|
||||
|
||||
const pressed = (name: RegExp): string | null =>
|
||||
screen.getByRole('button', { name }).getAttribute('aria-pressed')
|
||||
|
||||
describe('GeneralSection', () => {
|
||||
it('renders the four groups with skeleton rows inert', () => {
|
||||
const b = mount()
|
||||
// Permission: disabled selector showing the fixed value.
|
||||
const permission = screen.getByRole('button', { name: /Read only/ }) as HTMLButtonElement
|
||||
expect(permission.disabled).toBe(true)
|
||||
fireEvent.click(permission)
|
||||
// Tool Call: both mode cubes render as plain text, no buttons.
|
||||
expect(screen.getByText('Schema mode')).toBeDefined()
|
||||
expect(screen.getByText('Code mode')).toBeDefined()
|
||||
expect(screen.queryByRole('button', { name: /Schema mode/ })).toBeNull()
|
||||
expect(b.setLocale).not.toHaveBeenCalled()
|
||||
expect(b.setTheme).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('opens the language menu, selects a locale, and closes', () => {
|
||||
const b = mount({ active: 'en' })
|
||||
const trigger = screen.getByRole('button', { name: /English/ })
|
||||
expect(trigger.getAttribute('aria-expanded')).toBe('false')
|
||||
fireEvent.click(trigger)
|
||||
expect(trigger.getAttribute('aria-expanded')).toBe('true')
|
||||
fireEvent.click(screen.getByRole('menuitem', { name: '中文' }))
|
||||
expect(b.setLocale).toHaveBeenCalledWith('zh')
|
||||
expect(trigger.getAttribute('aria-expanded')).toBe('false')
|
||||
expect(screen.queryByRole('menuitem', { name: '中文' })).toBeNull()
|
||||
})
|
||||
|
||||
it('closes the language menu on outside pointerdown without selecting', () => {
|
||||
const b = mount({ active: 'en' })
|
||||
const trigger = screen.getByRole('button', { name: /English/ })
|
||||
fireEvent.click(trigger)
|
||||
expect(screen.getByRole('menuitem', { name: '中文' })).toBeDefined()
|
||||
fireEvent.pointerDown(document.body)
|
||||
expect(trigger.getAttribute('aria-expanded')).toBe('false')
|
||||
expect(screen.queryByRole('menuitem', { name: '中文' })).toBeNull()
|
||||
expect(b.setLocale).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('reflects a store locale change in the trigger label (unknown id falls back to the id)', () => {
|
||||
const b = mount({ active: 'en' })
|
||||
act(() => { b.store.actions.syncLocale('zh', LOCALES, 1) })
|
||||
expect(screen.getByRole('button', { name: /中文/ })).toBeDefined()
|
||||
act(() => { b.store.actions.syncLocale('fr', LOCALES, 2) })
|
||||
expect(screen.getByRole('button', { name: /fr/ })).toBeDefined()
|
||||
})
|
||||
|
||||
it('marks the appearance cube matching the preference and switches on click', () => {
|
||||
const b = mount({ preference: 'dark' })
|
||||
expect(pressed(/Dark/)).toBe('true')
|
||||
expect(pressed(/Light/)).toBe('false')
|
||||
expect(pressed(/System/)).toBe('false')
|
||||
fireEvent.click(screen.getByRole('button', { name: /Light/ }))
|
||||
expect(b.setTheme).toHaveBeenCalledWith('light')
|
||||
// Selection follows the store mirror, not the click echo.
|
||||
act(() => { b.store.actions.syncTheme('light', 1) })
|
||||
expect(pressed(/Light/)).toBe('true')
|
||||
expect(pressed(/Dark/)).toBe('false')
|
||||
})
|
||||
})
|
||||
@@ -1,18 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { Context } from 'cordis'
|
||||
import * as GeneralInvariant from '@deepseek-ai/dsh-client-ui-settings-general/invariant'
|
||||
import InvariantService from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
describe('invariant companion', () => {
|
||||
it('registers under the package name with an empty installer', async () => {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(InvariantService, { enabled: true })
|
||||
await expect(ctx.plugin(GeneralInvariant).await()).resolves.toBeDefined()
|
||||
})
|
||||
|
||||
it('node-half apply is a no-op host placeholder', async () => {
|
||||
const { apply } = await import('@deepseek-ai/dsh-client-ui-settings-general')
|
||||
apply()
|
||||
expect(true).toBe(true) // reaching here without throw is the contract
|
||||
})
|
||||
})
|
||||
@@ -1,56 +0,0 @@
|
||||
/** General settings store: snapshot-mirror actions and the revision guard. */
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { createGeneralSettingsStore } from '../src/client/store.ts'
|
||||
|
||||
const LOCALES = [{ id: 'zh', label: '中文' }, { id: 'en', label: 'English' }]
|
||||
|
||||
describe('createGeneralSettingsStore', () => {
|
||||
it('init shape: empty mirrors with revisions at -1', () => {
|
||||
const store = createGeneralSettingsStore().create()
|
||||
expect(store.getSnapshot()).toEqual({
|
||||
localeActive: '',
|
||||
localeOptions: [],
|
||||
localeRevision: -1,
|
||||
themePreference: 'system',
|
||||
themeRevision: -1,
|
||||
})
|
||||
})
|
||||
|
||||
it('syncLocale mirrors the snapshot and advances the revision', () => {
|
||||
const store = createGeneralSettingsStore().create()
|
||||
store.actions.syncLocale('zh', LOCALES, 0)
|
||||
expect(store.getSnapshot().localeActive).toBe('zh')
|
||||
expect(store.getSnapshot().localeOptions).toEqual(LOCALES)
|
||||
expect(store.getSnapshot().localeRevision).toBe(0)
|
||||
|
||||
store.actions.syncLocale('en', LOCALES, 1)
|
||||
expect(store.getSnapshot().localeActive).toBe('en')
|
||||
expect(store.getSnapshot().localeRevision).toBe(1)
|
||||
})
|
||||
|
||||
it('syncLocale revision guard drops stale and duplicate writes', () => {
|
||||
const store = createGeneralSettingsStore().create()
|
||||
store.actions.syncLocale('en', LOCALES, 5)
|
||||
// Stale (lower) and duplicate (equal) revisions leave the mirror intact.
|
||||
store.actions.syncLocale('zh', LOCALES, 4)
|
||||
store.actions.syncLocale('zh', LOCALES, 5)
|
||||
expect(store.getSnapshot().localeActive).toBe('en')
|
||||
expect(store.getSnapshot().localeRevision).toBe(5)
|
||||
})
|
||||
|
||||
it('syncTheme mirrors the preference and guards its revision independently', () => {
|
||||
const store = createGeneralSettingsStore().create()
|
||||
store.actions.syncTheme('dark', 0)
|
||||
expect(store.getSnapshot().themePreference).toBe('dark')
|
||||
expect(store.getSnapshot().themeRevision).toBe(0)
|
||||
|
||||
store.actions.syncTheme('light', 2)
|
||||
expect(store.getSnapshot().themePreference).toBe('light')
|
||||
|
||||
// Stale theme write is dropped; the locale revision axis is untouched.
|
||||
store.actions.syncTheme('system', 1)
|
||||
expect(store.getSnapshot().themePreference).toBe('light')
|
||||
expect(store.getSnapshot().themeRevision).toBe(2)
|
||||
expect(store.getSnapshot().localeRevision).toBe(-1)
|
||||
})
|
||||
})
|
||||
@@ -1,36 +0,0 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.base.client.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "lib/types"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../../vendor/cordis"
|
||||
},
|
||||
{
|
||||
"path": "../ui-slots"
|
||||
},
|
||||
{
|
||||
"path": "../ui-primitives"
|
||||
},
|
||||
{
|
||||
"path": "../runtime"
|
||||
},
|
||||
{
|
||||
"path": "../ui-settings"
|
||||
},
|
||||
{
|
||||
"path": "../locale"
|
||||
},
|
||||
{
|
||||
"path": "../ui-theme"
|
||||
},
|
||||
{
|
||||
"path": "../../support/invariants"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
import { clientBundle } from '../tsdown.client.ts'
|
||||
|
||||
export default clientBundle('@deepseek-ai/dsh-client-ui-settings-general', ['lib/types/index.js', 'lib/types/invariant.js'])
|
||||
Reference in New Issue
Block a user