dsh-plugin-effort-declare 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CONTRIBUTING.en.md +20 -9
  2. package/CONTRIBUTING.md +24 -13
  3. package/INSTALL.en.md +9 -9
  4. package/INSTALL.md +16 -16
  5. package/README.en.md +25 -20
  6. package/README.md +28 -23
  7. package/lib/client.js +354 -82
  8. package/lib/client.js.map +1 -1
  9. package/lib/types/client/EffortDeclareSection.d.ts +14 -4
  10. package/lib/types/client/EffortDeclareSection.d.ts.map +1 -1
  11. package/lib/types/client/build-info.d.ts +2 -0
  12. package/lib/types/client/build-info.d.ts.map +1 -0
  13. package/lib/types/client/index.d.ts.map +1 -1
  14. package/lib/types/client/load-drafts.d.ts +36 -6
  15. package/lib/types/client/load-drafts.d.ts.map +1 -1
  16. package/lib/types/client/locales.d.ts +1 -1
  17. package/lib/types/client/locales.d.ts.map +1 -1
  18. package/lib/types/core/attribution.d.ts +13 -0
  19. package/lib/types/core/attribution.d.ts.map +1 -0
  20. package/lib/types/core/catalog.d.ts +8 -0
  21. package/lib/types/core/catalog.d.ts.map +1 -1
  22. package/lib/types/core/drafts.d.ts +8 -4
  23. package/lib/types/core/drafts.d.ts.map +1 -1
  24. package/lib/types/core/efforts.d.ts.map +1 -1
  25. package/lib/types/core/input.d.ts +15 -0
  26. package/lib/types/core/input.d.ts.map +1 -0
  27. package/lib/types/core/validate.d.ts +3 -0
  28. package/lib/types/core/validate.d.ts.map +1 -1
  29. package/package.json +2 -2
  30. package/src/README.en.md +2 -2
  31. package/src/README.md +2 -2
  32. package/src/client/EffortDeclareSection.tsx +161 -47
  33. package/src/client/README.en.md +7 -5
  34. package/src/client/README.md +7 -5
  35. package/src/client/build-info.ts +12 -0
  36. package/src/client/effort-declare.module.css +8 -0
  37. package/src/client/globals.d.ts +5 -0
  38. package/src/client/index.ts +13 -11
  39. package/src/client/load-drafts.ts +124 -8
  40. package/src/client/locales.ts +13 -4
  41. package/src/core/README.en.md +10 -8
  42. package/src/core/README.md +10 -8
  43. package/src/core/attribution.ts +24 -0
  44. package/src/core/catalog.ts +11 -0
  45. package/src/core/drafts.ts +40 -26
  46. package/src/core/efforts.ts +4 -1
  47. package/src/core/input.ts +49 -0
  48. package/src/core/validate.ts +8 -0
@@ -7,7 +7,7 @@
7
7
  </samp>
8
8
  </p>
9
9
 
10
- 浏览器半区:在 Web UI 的设置面板注册「推理档位」,并经官方 settings RPC 写入 `llm-pi-ai`。
10
+ 浏览器半区:在 Web UI 的设置面板注册「推理档位」,并经官方 settings RPC `llm-pi-ai` 写入每模型的 `reasoningEfforts` 与 `input`。
11
11
 
12
12
  `apply` 接线失败会抛出,与官方模型页相同;不要整段 `try/catch` 吞掉。卸载时 locale、CSS 与事件订阅随 `ctx.effect` 清理。
13
13
 
@@ -17,10 +17,12 @@
17
17
 
18
18
  | 文件 | 说明 |
19
19
  | --- | --- |
20
- | [`index.ts`](./index.ts) | 注册 zh/en 文案、CSS(`ctx.effect` 插入/移除)与 `settings.section`(id `effort-declare`,order 12)。`describe.subscribe` 只同步 `writable`(任意 namespace 都会触发,含自己的 `acceptView`)。真正重载来自 `settings/document-updated`(仅 `llm-pi-ai`)、`llm/adapters-updated`、`connection/reset`。`locale: NS` 由框架注入 `t`,inject 只传 `api` / `describe` / `schema` / `subscribeInvalidate`。 |
21
- | [`EffortDeclareSection.tsx`](./EffortDeclareSection.tsx) | 路由卡片、预设、Off 三态、高级协议开关、保存与取消。保存互斥到整个 `llm-pi-ai` namespace;`busy` 只给正在 mutate 的卡显示「保存中」,其它卡 `saveLocked`。自己写入成功走 `acceptView` + `applySaveSuccess`,不再全量 reload |
22
- | [`load-drafts.ts`](./load-drafts.ts) | `llm.providers` + 镜像组装草稿;草稿取自 `user`,协议分类可用 `value`。`thinkingFormat` 可选项只来自现场 schema union。 |
23
- | [`locales.ts`](./locales.ts) | 文案 namespace `plugin-effort-declare`。 |
20
+ | [`index.ts`](./index.ts) | 注册 zh/en 文案、CSS(`ctx.effect` 插入/移除)与 `settings.section`(id `effort-declare`,order 12)。`describe.subscribe` 只同步 `writable`(任意 namespace 都会触发,含自己的 `acceptView`)。`settings/document-updated`(仅 `llm-pi-ai`)带上 Host 的 revision;设置页跳过自己这次 mutate 的回声,等镜像 revision **追上**后再 `getSnapshot()`,不把 `ensure()` 当刷新。提供方目录来自 `llm/adapters-updated`;`connection/reset` 走 `ensure()` 以便等待官方镜像的 in-flight `load()`。`locale: NS` 由框架注入 `t`,inject 只传 `api` / `describe` / `schema` / `subscribeInvalidate`。 |
21
+ | [`EffortDeclareSection.tsx`](./EffortDeclareSection.tsx) | 路由卡片、预设、Off 三态、每模型「支持图片输入」、高级协议开关、保存与取消。保存互斥到整个 `llm-pi-ai` namespace(以 ref 防连点);`busy` 只给正在 mutate 的卡显示「保存中」,其它卡 `saveLocked`。保存前用 `modelRowError` 拦截空档位、只开 Off 与非法 `input`。自己写入成功立刻同步 `draftsRef` 并走 `acceptView` + `applySaveSuccess`。保存过程中到达的外部 `document-updated` 会在结束后补刷。无冲突的 reload 清掉该卡 conflict/error notice。页脚显示打包时冻结的版本与版权年。 |
22
+ | [`build-info.ts`](./build-info.ts) | 读取 tsdown `define` 注入的 `package.json` version UTC 打包年,拼出页脚文案。 |
23
+ | [`globals.d.ts`](./globals.d.ts) | `__PLUGIN_VERSION__` / `__COPYRIGHT_TO__` 的类型声明。 |
24
+ | [`load-drafts.ts`](./load-drafts.ts) | 从 `llm.providers` + 镜像组装草稿;草稿取自 `user`,协议分类可用 `value`。`thinkingFormat` 可选项只来自现场 schema union。首屏 `ensure()`;刷新只读 `getSnapshot()`,并提供等 namespace revision 的 helper。 |
25
+ | [`locales.ts`](./locales.ts) | 文案 namespace `plugin-effort-declare`(含档位、图片输入与校验错误)。 |
24
26
  | [`effort-declare.module.css`](./effort-declare.module.css) | 仅使用 `--dsw-alias-*` 设计令牌,保证暗色主题正确。 |
25
27
  | [`schema-ops.ts`](./schema-ops.ts) | 将 `settingsSchema` 收成普通回调(含 `validate`),避免把服务身份带进 React。 |
26
28
 
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Footer line frozen into the client bundle. Do not read the clock or
3
+ * package.json at DSH startup — host apply is empty and the settings page
4
+ * runs in the browser.
5
+ */
6
+ import { COPYRIGHT_FROM, formatAttribution } from '../core/attribution.ts'
7
+
8
+ export const PLUGIN_FOOTER_TEXT = formatAttribution(
9
+ __PLUGIN_VERSION__,
10
+ COPYRIGHT_FROM,
11
+ __COPYRIGHT_TO__,
12
+ )
@@ -276,3 +276,11 @@
276
276
  font-size: 12px;
277
277
  line-height: 18px;
278
278
  }
279
+
280
+ .footer {
281
+ margin: 16px 0 0;
282
+ font-size: 11px;
283
+ line-height: 16px;
284
+ color: var(--dsw-alias-label-tertiary);
285
+ opacity: 0.7;
286
+ }
@@ -0,0 +1,5 @@
1
+ /** `package.json` version, substituted by tsdown `define` at pack time. */
2
+ declare const __PLUGIN_VERSION__: string
3
+
4
+ /** UTC full year at pack time, substituted by tsdown `define`. */
5
+ declare const __COPYRIGHT_TO__: number
@@ -8,7 +8,7 @@ import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
8
8
  import type {} from '@deepseek-ai/dsh-client-locale/client'
9
9
  import type {} from '@deepseek-ai/dsh-api-remotes/client'
10
10
  import { EffortDeclareSection } from './EffortDeclareSection.tsx'
11
- import type { EffortDeclareSectionInjected, InvalidationSource } from './EffortDeclareSection.tsx'
11
+ import type { EffortDeclareSectionInjected, Invalidation } from './EffortDeclareSection.tsx'
12
12
  import { bindSchema } from './schema-ops.ts'
13
13
  import { LLM_PI_AI_NS } from '../core/catalog.ts'
14
14
  import { NS, en, zh, type EffortDeclareKey } from './locales.ts'
@@ -60,23 +60,25 @@ export function apply(ctx: ClientContext): void {
60
60
  })
61
61
  const t = ctx.locale.bind(NS)
62
62
  const describe = ctx.settingsScope.describe()
63
- const invalidation = new Set<(source: InvalidationSource) => void>()
63
+ const invalidation = new Set<(event: Invalidation) => void>()
64
64
 
65
65
  ctx.effect(() => {
66
- const emit = (source: InvalidationSource) => {
67
- for (const listener of invalidation) listener(source)
66
+ const emit = (event: Invalidation) => {
67
+ for (const listener of invalidation) listener(event)
68
68
  }
69
69
  // Mirror subscribe fires on every namespace (theme, locale, own acceptView).
70
- // Only fold writable from that; llm-pi-ai document changes come from the
71
- // Host event below so a dirty card is not treated as a conflict.
70
+ // Only fold writable from that. llm-pi-ai document changes come from
71
+ // settings/document-updated; the section waits until the mirror revision
72
+ // has caught up instead of calling ensure(), and skips the echo of its
73
+ // own mutate. connection/reset uses ensure() so an in-flight load is awaited.
72
74
  const disposers = [
73
- describe.subscribe(() => { emit('writable') }),
74
- ctx.remote.$on('settings/document-updated', (ns: string) => {
75
+ describe.subscribe(() => { emit({ source: 'writable' }) }),
76
+ ctx.remote.$on('settings/document-updated', (ns: string, revision: number) => {
75
77
  if (ns !== LLM_PI_AI_NS) return
76
- emit('settings')
78
+ emit({ source: 'settings', revision })
77
79
  }),
78
- ctx.remote.$on('llm/adapters-updated', () => { emit('directory') }),
79
- ctx.on('connection/reset', () => { emit('directory') }),
80
+ ctx.remote.$on('llm/adapters-updated', () => { emit({ source: 'directory' }) }),
81
+ ctx.on('connection/reset', () => { emit({ source: 'reset' }) }),
80
82
  ]
81
83
  return () => {
82
84
  for (const dispose of disposers) dispose()
@@ -1,6 +1,12 @@
1
1
  /**
2
2
  * Load editable route drafts from llm.providers + the llm-pi-ai namespace.
3
3
  * Drafts come from the user layer; route protocol classification may use effective value.
4
+ *
5
+ * First paint uses `ensure()` (idle-only). Refresh never calls `ensure()`:
6
+ * wait until the mirror subscribe shows a namespace revision at least as new
7
+ * as the Host event, then `getSnapshot()`. Own mutate echoes are identified
8
+ * by revision (including older delayed echoes), not ignored as a generic
9
+ * document-updated.
4
10
  */
5
11
  import type { IApiClient, SettingsNamespaceView } from '@deepseek-ai/dsh-api-remotes/client'
6
12
  import type { SettingsDescribeFace } from '@deepseek-ai/dsh-client-ui-settings/client'
@@ -25,19 +31,115 @@ export interface LoadDraftsResult {
25
31
  error?: string
26
32
  }
27
33
 
34
+ export type LoadDraftsMode = 'ensure' | 'snapshot'
35
+
36
+ type MirrorSnapshot = ReturnType<SettingsDescribeFace['getSnapshot']>
37
+ type MirrorDescribe = Pick<SettingsDescribeFace, 'getSnapshot' | 'subscribe'>
38
+
39
+ /** Namespace revision on a describe snapshot, if that row exists. */
40
+ export function namespaceRevision(snapshot: MirrorSnapshot, ns: string): number | undefined {
41
+ return snapshot.view?.namespaces.find(view => view.ns === ns)?.revision
42
+ }
43
+
28
44
  /**
29
- * First paint: `ensure()` (reads only from idle). Never treat ensure as refresh.
30
- * Callers that must not apply a stale settlement compare generation themselves.
31
- *
32
- * `formats` is the live schema union only. Empty means the dropdown has no
33
- * writable choices (stored values stay visible via `thinkingFormatChoices`).
45
+ * True when `incoming` is the Host echo of a mutate this page already folded,
46
+ * or an older revision the snapshot has already passed. `echoed` is undefined
47
+ * until the first successful write.
34
48
  */
35
- export async function loadDrafts(
49
+ export function isOwnDocumentEcho(echoed: number | undefined, incoming: number): boolean {
50
+ return echoed !== undefined && incoming <= echoed
51
+ }
52
+
53
+ /**
54
+ * After a preserve-dirty reload: conflicted cards get a conflict notice;
55
+ * live cards drop leftover conflict/error; saved notices stay; gone cards drop.
56
+ */
57
+ export function foldReloadNotices<T extends { kind: string }>(
58
+ current: Record<string, T>,
59
+ args: {
60
+ conflicted: readonly string[]
61
+ conflictNotice: T
62
+ liveProviders: readonly string[]
63
+ },
64
+ ): Record<string, T> {
65
+ const live = new Set(args.liveProviders)
66
+ const conflicted = new Set(args.conflicted)
67
+ const next: Record<string, T> = {}
68
+ for (const [provider, notice] of Object.entries(current)) {
69
+ if (!live.has(provider)) continue
70
+ if (conflicted.has(provider)) continue
71
+ if (notice.kind === 'conflict' || notice.kind === 'error') continue
72
+ next[provider] = notice
73
+ }
74
+ for (const provider of args.conflicted) {
75
+ next[provider] = args.conflictNotice
76
+ }
77
+ return next
78
+ }
79
+
80
+ function waitUntil(
81
+ describe: MirrorDescribe,
82
+ predicate: () => boolean,
83
+ signal?: AbortSignal,
84
+ ): Promise<boolean> {
85
+ if (signal?.aborted) return Promise.resolve(false)
86
+ if (predicate()) return Promise.resolve(true)
87
+ return new Promise((resolve) => {
88
+ let settled = false
89
+ const finish = (ok: boolean) => {
90
+ if (settled) return
91
+ settled = true
92
+ stop()
93
+ signal?.removeEventListener('abort', onAbort)
94
+ resolve(ok)
95
+ }
96
+ const onAbort = () => { finish(false) }
97
+ const stop = describe.subscribe(() => {
98
+ if (predicate()) finish(true)
99
+ })
100
+ signal?.addEventListener('abort', onAbort)
101
+ if (predicate()) finish(true)
102
+ else if (signal?.aborted) finish(false)
103
+ })
104
+ }
105
+
106
+ /** Resolve when the mirror's namespace revision is at least `revision`, or abort. */
107
+ export async function waitForNamespaceRevision(
108
+ describe: MirrorDescribe,
109
+ ns: string,
110
+ revision: number,
111
+ signal?: AbortSignal,
112
+ ): Promise<'matched' | 'aborted'> {
113
+ const matched = await waitUntil(
114
+ describe,
115
+ () => {
116
+ const current = namespaceRevision(describe.getSnapshot(), ns)
117
+ return current !== undefined && current >= revision
118
+ },
119
+ signal,
120
+ )
121
+ return matched ? 'matched' : 'aborted'
122
+ }
123
+
124
+ /** Resolve when the namespace revision differs from `previous`, or abort. */
125
+ export async function waitForNamespaceRevisionChange(
126
+ describe: MirrorDescribe,
127
+ ns: string,
128
+ previous: number,
129
+ signal?: AbortSignal,
130
+ ): Promise<'changed' | 'aborted'> {
131
+ const changed = await waitUntil(describe, () => {
132
+ const current = namespaceRevision(describe.getSnapshot(), ns)
133
+ return current !== undefined && current !== previous
134
+ }, signal)
135
+ return changed ? 'changed' : 'aborted'
136
+ }
137
+
138
+ async function assembleDrafts(
36
139
  api: Pick<IApiClient, 'llm'>,
37
- describe: Pick<SettingsDescribeFace, 'ensure' | 'getSnapshot'>,
140
+ describe: Pick<SettingsDescribeFace, 'getSnapshot'>,
38
141
  schema: SchemaOps,
39
142
  ): Promise<LoadDraftsResult> {
40
- await describe.ensure()
41
143
  const mirrored = describe.getSnapshot()
42
144
  if (mirrored.view === undefined) {
43
145
  return { writable: false, formats: [], drafts: [], error: mirrored.error ?? undefined }
@@ -83,3 +185,17 @@ export async function loadDrafts(
83
185
  }
84
186
  return { writable: mirrored.view.writable, formats, drafts }
85
187
  }
188
+
189
+ /**
190
+ * `ensure`: first paint / idle recovery (official ensure only reads from idle).
191
+ * `snapshot`: refresh after the mirror revision already moved — do not ensure.
192
+ */
193
+ export async function loadDrafts(
194
+ api: Pick<IApiClient, 'llm'>,
195
+ describe: Pick<SettingsDescribeFace, 'ensure' | 'getSnapshot'>,
196
+ schema: SchemaOps,
197
+ mode: LoadDraftsMode = 'ensure',
198
+ ): Promise<LoadDraftsResult> {
199
+ if (mode === 'ensure') await describe.ensure()
200
+ return assembleDrafts(api, describe, schema)
201
+ }
@@ -44,13 +44,16 @@ export type EffortDeclareKey =
44
44
  | 'errorBadWire'
45
45
  | 'noModels'
46
46
  | 'reload'
47
+ | 'imageInput'
48
+ | 'imageInputHint'
49
+ | 'errorBadInput'
47
50
 
48
51
  export const NS = 'plugin-effort-declare'
49
52
 
50
53
  export const zh: Record<EffortDeclareKey, string> = {
51
54
  nav: '推理档位',
52
55
  title: '推理档位声明',
53
- intro: '本页声明「这模型能选哪些推理档」。对话里的档位选择仍在输入框模型菜单。没声明 = 和现在一样没有 Effort 行。不会改密钥、目录或当次选择。',
56
+ intro: '声明手工模型可提供的推理档位,以及是否接受图片输入。未声明则不显示 Effort 行,图片附件也会被拒绝。档位仍在输入框菜单中选择;密钥、目录与当前选中项不在本页修改。',
54
57
  empty: '没有可编辑的手工 openai-completions 路由。',
55
58
  emptyHint: '请先到「模型」页添加提供方(llm-pi-ai 手工路由)。官方 DeepSeek 与 catalog 路由不在本页编辑。需要 DSH ≥ 0.1.0-rc.8(providers.declared)。',
56
59
  loadError: '无法加载提供方或设置。',
@@ -60,7 +63,7 @@ export const zh: Record<EffortDeclareKey, string> = {
60
63
  saving: '保存中…',
61
64
  saveBusy: '另有路由正在保存,请稍候。',
62
65
  cancel: '取消',
63
- saved: '已保存。对话选择器会按新的能力声明显示 Effort 行。',
66
+ saved: '已保存。对话会按新的能力声明更新 Effort 行和是否允许贴图。',
64
67
  conflict: '设置已被其他地方改过,请重新加载后再保存。',
65
68
  dirtyConflict: '此路由有未保存修改,设置已在其他地方更新。保存会写到最新文档上,或先取消再改。',
66
69
  presets: '预设',
@@ -89,12 +92,15 @@ export const zh: Record<EffortDeclareKey, string> = {
89
92
  errorBadWire: '思考档必须填写线上拼写;只有 Off 可以留空。不能使用未知档位键。',
90
93
  noModels: '这条路由还没有 models 列表。请先到「模型」页添加模型。',
91
94
  reload: '重新加载',
95
+ imageInput: '支持图片输入',
96
+ imageInputHint: '只在这个模型确实能看图时勾选。勾错了图会进聊天记录,然后被接口打回来。',
97
+ errorBadInput: 'input 只能是 text / image,必须包含 text,不能重复或留空。不支持图片请清除该键,不要写成空列表。',
92
98
  }
93
99
 
94
100
  export const en: Record<EffortDeclareKey, string> = {
95
101
  nav: 'Reasoning efforts',
96
102
  title: 'Reasoning effort declarations',
97
- intro: 'This page declares which reasoning levels a model can offer. The per-turn choice stays in the composer model menu. Undeclared models keep having no Effort row. Keys, catalogs, and the current selection are not edited here.',
103
+ intro: 'Declare reasoning levels and image input for hand-added models. Undeclared models omit the Effort row and refuse image attachments. Effort is still chosen in the composer menu; keys, catalogs, and the current selection are not modified here.',
98
104
  empty: 'No editable hand-declared openai-completions routes.',
99
105
  emptyHint: 'Add a provider on the Models page first (an llm-pi-ai hand-declared route). Official DeepSeek and catalog routes are not edited here. Requires DSH ≥ 0.1.0-rc.8 (providers.declared).',
100
106
  loadError: 'Could not load providers or settings.',
@@ -104,7 +110,7 @@ export const en: Record<EffortDeclareKey, string> = {
104
110
  saving: 'Saving…',
105
111
  saveBusy: 'Another route is saving. Wait, then save this card.',
106
112
  cancel: 'Cancel',
107
- saved: 'Saved. The composer Effort row follows this capability declaration.',
113
+ saved: 'Saved. The composer Effort row and image admission follow this capability declaration.',
108
114
  conflict: 'Settings changed elsewhere. Reload, then save again.',
109
115
  dirtyConflict: 'This route has unsaved edits and settings changed elsewhere. Save writes onto the latest document, or cancel first.',
110
116
  presets: 'Presets',
@@ -133,4 +139,7 @@ export const en: Record<EffortDeclareKey, string> = {
133
139
  errorBadWire: 'Thinking levels need a wire spelling; only Off may be empty. Unknown effort keys are rejected.',
134
140
  noModels: 'This route has no models list yet. Add models on the Models page first.',
135
141
  reload: 'Reload',
142
+ imageInput: 'Accepts image input',
143
+ imageInputHint: 'Check only if this model actually sees images. Over-claiming admits a picture into history, then the gateway rejects the turn.',
144
+ errorBadInput: 'input may only list text and image, must include text, and must not be empty or duplicated. To drop vision, unset the key; do not write [].',
136
145
  }
@@ -7,21 +7,23 @@
7
7
  </samp>
8
8
  </p>
9
9
 
10
- Domain logic for the plugin: no React, no Cordis service instances. The settings page and Vitest both depend on these pure functions, so effort semantics can regress without booting DSH.
10
+ Domain logic for the plugin: no React, no Cordis service instances. The settings page and Vitest both depend on these pure functions, so reasoning-effort and image-input semantics can regress without booting DSH.
11
11
 
12
- Canonical level names and `thinkingFormat` values follow `@deepseek-ai/dsh-llm-pi-ai` (0.1.0-rc.8; 0.1.1-rc.2 uses the same level set). `thinkingFormat` is pinned to the live-schema snapshot in [`tests/fixtures/pi-ai-thinking-format-union.ts`](../../tests/fixtures/pi-ai-thinking-format-union.ts); effort keys stay a locally pinned whitelist. UI choices come only from the live schema union.
12
+ Canonical level names and `thinkingFormat` values follow `@deepseek-ai/dsh-llm-pi-ai` (0.1.0-rc.8; 0.1.1-rc.2 uses the same level set). `thinkingFormat` is pinned to the live-schema snapshot in [`tests/fixtures/pi-ai-thinking-format-union.ts`](../../tests/fixtures/pi-ai-thinking-format-union.ts); effort keys stay a locally pinned whitelist. UI choices come only from the live schema union. Writable `models[].input` modalities are `text` and `image`, matching the official schema.
13
13
 
14
14
  ## What's in this directory
15
15
 
16
16
  | File | Role |
17
17
  | --- | --- |
18
- | [`catalog.ts`](./catalog.ts) | Canonical level order, `thinkingFormat` fallback list, `llm-pi-ai` / DeepSeek constants. |
19
- | [`efforts.ts`](./efforts.ts) | `reasoningEfforts` read/write, Off tri-state, validation (empty object / Off-only / unknown keys return an error code, never throw). |
20
- | [`presets.ts`](./presets.ts) | DeepSeek, OpenAI, and on/off presets; each states all three dialect keys; spread onto existing model rows and route `compat`. |
18
+ | [`catalog.ts`](./catalog.ts) | Canonical level order, `thinkingFormat` fallback list, request modalities (`INPUT_MODALITIES` / `IMAGE_CAPABLE_INPUT`), `llm-pi-ai` / DeepSeek constants. |
19
+ | [`efforts.ts`](./efforts.ts) | `reasoningEfforts` read/write, Off tri-state (value mode stores `trim()`), validation (empty object / Off-only / unknown keys return an error code, never throw). |
20
+ | [`input.ts`](./input.ts) | Per-model `input`: checking writes `['text', 'image']`, unchecking deletes the key; empty list / image-only / duplicates / unknown modalities return an error code. |
21
+ | [`presets.ts`](./presets.ts) | DeepSeek, OpenAI, and on/off presets; each states all three dialect keys; spread onto existing model rows and route `compat`, leaving existing `input` intact. |
21
22
  | [`path-ops.ts`](./path-ops.ts) | Same one-level key diff as the official Models page; `buildSaveOps` uses `settingsPath` and only submits that route’s full `models` table and dirty `compat` keys. |
22
- | [`drafts.ts`](./drafts.ts) | User-layer drafts, dirty aligned with pathOps, post-save revision. On refresh, latest user-layer model membership wins; unsaved `reasoningEfforts` (including a cleared key) overlay by id; `compat` is a per-key 3-way merge. Conflict only when a locally dirty field also moved in originals (revision-only bumps and sibling-card saves do not warn). |
23
+ | [`drafts.ts`](./drafts.ts) | User-layer drafts, dirty aligned with pathOps, post-save revision. On refresh, latest user-layer model membership wins; unsaved overlay keys (`reasoningEfforts` and `input` independently, including a cleared key) overlay by id; `compat` is a per-key 3-way merge. Conflict only when a locally dirty field also moved in originals (revision-only bumps and sibling-card saves do not warn). |
23
24
  | [`paths.ts`](./paths.ts) | Nested reads; clones of objects and model tables (non-object rows skipped). |
24
25
  | [`filter.ts`](./filter.ts) | Which routes are editable: hand-declared `llm-pi-ai` + openai-completions; skip catalog and official DeepSeek. |
25
- | [`validate.ts`](./validate.ts) | Per-row `reasoningEfforts` validation. |
26
+ | [`validate.ts`](./validate.ts) | Per-row validation: `reasoningEfforts` first, then `input`. |
27
+ | [`attribution.ts`](./attribution.ts) | Settings footer line: `version © year Stardust`. Start year is 2026; end year is the UTC year at pack time, not the user’s clock when DSH starts. |
26
28
 
27
- An **absent** field means default-off. Do not encode undeclared as `reasoningEfforts: false` — in official semantics `false` strips reasoning from a catalog model.
29
+ An **absent** field means default-off. Do not encode an undeclared effort as `reasoningEfforts: false` — in official semantics `false` strips reasoning from a catalog model. Do not encode “no vision” as `input: []` — the official resolver treats an empty list as absent, but a bad stamp must not be re-saved. Disabling image input must delete the key; do not write `[text]`.
@@ -7,21 +7,23 @@
7
7
  </samp>
8
8
  </p>
9
9
 
10
- 本插件的领域逻辑:无 React、无 Cordis 服务实例。设置页与 Vitest 都只依赖这些纯函数,因此档位语义可以在不启动 DSH 的情况下回归。
10
+ 本插件的领域逻辑:无 React、无 Cordis 服务实例。设置页与 Vitest 都只依赖这些纯函数,因此推理档位与图片输入语义可以在不启动 DSH 的情况下回归。
11
11
 
12
- 规范键名与 `thinkingFormat` 取值对齐 `@deepseek-ai/dsh-llm-pi-ai`(0.1.0-rc.8;0.1.1-rc.2 档位集合相同)。`thinkingFormat` 由 [`tests/fixtures/pi-ai-thinking-format-union.ts`](../../tests/fixtures/pi-ai-thinking-format-union.ts) 钉现场 schema;档位键由测试钉本地白名单。UI 可选项只来自现场 schema union
12
+ 规范键名与 `thinkingFormat` 取值对齐 `@deepseek-ai/dsh-llm-pi-ai`(0.1.0-rc.8;0.1.1-rc.2 档位集合相同)。`thinkingFormat` 由 [`tests/fixtures/pi-ai-thinking-format-union.ts`](../../tests/fixtures/pi-ai-thinking-format-union.ts) 钉现场 schema;档位键由测试钉本地白名单。UI 可选项只来自现场 schema union。`models[].input` 的可写模态为 `text` 与 `image`,与官方 schema 一致。
13
13
 
14
14
  ## 这个目录里有什么
15
15
 
16
16
  | 文件 | 说明 |
17
17
  | --- | --- |
18
- | [`catalog.ts`](./catalog.ts) | 规范档位顺序、`thinkingFormat` 回退列表、`llm-pi-ai` / DeepSeek 相关常量。 |
19
- | [`efforts.ts`](./efforts.ts) | `reasoningEfforts` 读写、Off 三态、校验(空对象 / 只开 Off / 未知键返回错误码,不抛异常)。 |
20
- | [`presets.ts`](./presets.ts) | DeepSeek、OpenAI、仅开/关三套预设;每套对三个方言键都表态;spread 到已有模型行与路由 `compat`。 |
18
+ | [`catalog.ts`](./catalog.ts) | 规范档位顺序、`thinkingFormat` 回退列表、请求模态(`INPUT_MODALITIES` / `IMAGE_CAPABLE_INPUT`)、`llm-pi-ai` / DeepSeek 相关常量。 |
19
+ | [`efforts.ts`](./efforts.ts) | `reasoningEfforts` 读写、Off 三态(value 模式写入 `trim()` 后的字符串)、校验(空对象 / 只开 Off / 未知键返回错误码,不抛异常)。 |
20
+ | [`input.ts`](./input.ts) | 每模型 `input`:勾选写入 `['text', 'image']`,取消删除该键;空列表 / 仅 image / 重复 / 未知模态返回错误码。 |
21
+ | [`presets.ts`](./presets.ts) | DeepSeek、OpenAI、仅开/关三套预设;每套对三个方言键都表态;spread 到已有模型行与路由 `compat`,保留已有 `input`。 |
21
22
  | [`path-ops.ts`](./path-ops.ts) | 与官方模型页相同的一层键 diff;`buildSaveOps` 使用 `settingsPath`,只提交该路由的 `models` 整表和有差异的 `compat` 键。 |
22
- | [`drafts.ts`](./drafts.ts) | 用户层草稿、dirty 与 pathOps 一致、保存后 revision。刷新时以最新用户层模型名单为成员真理,按 id 贴回未保存的 `reasoningEfforts`(含已清除=删键);`compat` 按键三路合并。冲突仅当本地脏字段的 originals 也变了(只 bump revision 或别的卡保存不报)。 |
23
+ | [`drafts.ts`](./drafts.ts) | 用户层草稿、dirty 与 pathOps 一致、保存后 revision。刷新时以最新用户层模型名单为成员真理,按 id 贴回未保存的 overlay 键(`reasoningEfforts` 与 `input` 独立,含已清除 = 删键);`compat` 按键三路合并。冲突仅当本地脏字段的 originals 也变了(只 bump revision 或别的卡保存不报)。 |
23
24
  | [`paths.ts`](./paths.ts) | 嵌套读取、对象与模型表的 clone(非对象行跳过)。 |
24
25
  | [`filter.ts`](./filter.ts) | 哪些路由可编辑:手工 `llm-pi-ai` + openai-completions;排除 catalog 与官方 DeepSeek。 |
25
- | [`validate.ts`](./validate.ts) | 对单行 `reasoningEfforts` 调用校验。 |
26
+ | [`validate.ts`](./validate.ts) | 对单行先校验 `reasoningEfforts`,再校验 `input`。 |
27
+ | [`attribution.ts`](./attribution.ts) | 设置页页脚:`version © 年 Stardust`。首年写死 2026,结束年由打包时的 UTC 年注入,不是用户打开 DSH 的日期。 |
26
28
 
27
- **缺席字段**表示默认关闭。不要把「未声明」写成 `reasoningEfforts: false`——`false` 在官方语义里是从 catalog 模型上剥掉推理。
29
+ **缺席字段**表示默认关闭。不要把「未声明档位」写成 `reasoningEfforts: false`——`false` 在官方语义里是从 catalog 模型上剥掉推理。不要把「未声明视觉」写成 `input: []`——官方把空列表当成缺席,但坏戳记不应被重新保存。取消图片输入必须删除该键,而不是写成 `[text]`。
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Plugin footer attribution. Version and end-year are frozen into the client
3
+ * bundle at pack time; this module only formats the line.
4
+ */
5
+
6
+ /** First publication year (LICENSE). Not the user's wall clock. */
7
+ export const COPYRIGHT_FROM = 2026
8
+
9
+ export const COPYRIGHT_HOLDER = 'Stardust'
10
+
11
+ /**
12
+ * `0.1.2 © 2026 Stardust` or `0.1.2 © 2026–2027 Stardust`.
13
+ * Throws if version is empty or `to < from` — a bad stamp must not render.
14
+ */
15
+ export function formatAttribution(version: string, from: number, to: number): string {
16
+ if (version.trim() === '') {
17
+ throw new Error('plugin version must be a non-empty string')
18
+ }
19
+ if (!Number.isInteger(from) || !Number.isInteger(to) || to < from) {
20
+ throw new Error(`invalid copyright range: ${String(from)}\u2013${String(to)}`)
21
+ }
22
+ const years = to === from ? String(from) : `${String(from)}\u2013${String(to)}`
23
+ return `${version} \u00a9 ${years} ${COPYRIGHT_HOLDER}`
24
+ }
@@ -61,3 +61,14 @@ export const DEEPSEEK_OFFICIAL = 'deepseek-official'
61
61
 
62
62
  /** Any route key walks a dict schema to the same profile node. */
63
63
  export const SCHEMA_PROBE_ROUTE = '\u0000probe'
64
+
65
+ /** Request modalities llm-pi-ai accepts on `models[].input` / `defaultInput`. */
66
+ export const INPUT_MODALITIES = ['text', 'image'] as const
67
+
68
+ export type InputModality = (typeof INPUT_MODALITIES)[number]
69
+
70
+ /**
71
+ * Canonical write for a hand-declared vision model.
72
+ * Must include `text`; image-only is not a serviceable OpenAI-completions route.
73
+ */
74
+ export const IMAGE_CAPABLE_INPUT: readonly InputModality[] = ['text', 'image']
@@ -112,31 +112,42 @@ function indexById(rows: readonly Record<string, unknown>[]): Map<string, Record
112
112
  return map
113
113
  }
114
114
 
115
- function effortsPresence(row: Record<string, unknown> | undefined): { present: boolean; value: unknown } {
116
- if (row === undefined || !Object.hasOwn(row, 'reasoningEfforts')) {
115
+ /** Model-row fields this page edits; other keys follow the Models page. */
116
+ export const MODEL_OVERLAY_KEYS = ['reasoningEfforts', 'input'] as const
117
+
118
+ export type ModelOverlayKey = (typeof MODEL_OVERLAY_KEYS)[number]
119
+
120
+ function fieldPresence(
121
+ row: Record<string, unknown> | undefined,
122
+ key: ModelOverlayKey,
123
+ ): { present: boolean; value: unknown } {
124
+ if (row === undefined || !Object.hasOwn(row, key)) {
117
125
  return { present: false, value: undefined }
118
126
  }
119
- return { present: true, value: row.reasoningEfforts }
127
+ return { present: true, value: row[key] }
120
128
  }
121
129
 
122
- function effortsEqual(
123
- left: { present: boolean; value: unknown },
124
- right: { present: boolean; value: unknown },
130
+ function fieldEqual(
131
+ left: Record<string, unknown> | undefined,
132
+ right: Record<string, unknown> | undefined,
133
+ key: ModelOverlayKey,
125
134
  ): boolean {
126
- if (left.present !== right.present) return false
127
- if (!left.present) return true
128
- return sliceEqual(left.value, right.value)
135
+ const a = fieldPresence(left, key)
136
+ const b = fieldPresence(right, key)
137
+ if (a.present !== b.present) return false
138
+ if (!a.present) return true
139
+ return sliceEqual(a.value, b.value)
129
140
  }
130
141
 
131
- function overlayLocalEfforts(
142
+ function overlayLocalFields(
132
143
  incomingRow: Record<string, unknown>,
133
144
  prevRow: Record<string, unknown>,
145
+ keys: readonly ModelOverlayKey[],
134
146
  ): Record<string, unknown> {
135
147
  const next = structuredClone(incomingRow)
136
- if (Object.hasOwn(prevRow, 'reasoningEfforts')) {
137
- next.reasoningEfforts = structuredClone(prevRow.reasoningEfforts)
138
- } else {
139
- delete next.reasoningEfforts
148
+ for (const key of keys) {
149
+ if (Object.hasOwn(prevRow, key)) next[key] = structuredClone(prevRow[key])
150
+ else delete next[key]
140
151
  }
141
152
  return next
142
153
  }
@@ -155,7 +166,8 @@ function objectKeyChanged(
155
166
 
156
167
  /**
157
168
  * Membership follows the latest user-layer models list (Models page add/delete).
158
- * Local unsaved `reasoningEfforts` (including a cleared key) overlay by id.
169
+ * Local unsaved overlay keys (including a cleared key) overlay by id; other
170
+ * fields on the row follow incoming.
159
171
  */
160
172
  export function mergeModelsById(args: {
161
173
  prevModels: readonly Record<string, unknown>[]
@@ -174,21 +186,23 @@ export function mergeModelsById(args: {
174
186
  const prevRow = prevById.get(id)
175
187
  if (prevRow === undefined) return structuredClone(incomingRow)
176
188
  const prevOrig = prevOrigById.get(id)
177
- const localDirty = !effortsEqual(effortsPresence(prevRow), effortsPresence(prevOrig))
178
- if (!localDirty) return structuredClone(incomingRow)
189
+ const dirtyKeys = MODEL_OVERLAY_KEYS.filter(key => !fieldEqual(prevRow, prevOrig, key))
190
+ if (dirtyKeys.length === 0) return structuredClone(incomingRow)
179
191
  const incomingOrig = incomingOrigById.get(id)
180
- if (!effortsEqual(effortsPresence(prevOrig), effortsPresence(incomingOrig))) {
181
- conflicted = true
192
+ for (const key of dirtyKeys) {
193
+ if (!fieldEqual(prevOrig, incomingOrig, key)) conflicted = true
182
194
  }
183
- return overlayLocalEfforts(incomingRow, prevRow)
195
+ return overlayLocalFields(incomingRow, prevRow, dirtyKeys)
184
196
  })
185
197
 
186
198
  for (const [id, prevRow] of prevById) {
187
199
  if (incomingIds.has(id)) continue
188
200
  const prevOrig = prevOrigById.get(id)
189
- if (effortsEqual(effortsPresence(prevRow), effortsPresence(prevOrig))) continue
190
- if (!effortsEqual(effortsPresence(prevOrig), effortsPresence(incomingOrigById.get(id)))) {
191
- conflicted = true
201
+ const dirtyKeys = MODEL_OVERLAY_KEYS.filter(key => !fieldEqual(prevRow, prevOrig, key))
202
+ if (dirtyKeys.length === 0) continue
203
+ const incomingOrig = incomingOrigById.get(id)
204
+ for (const key of dirtyKeys) {
205
+ if (!fieldEqual(prevOrig, incomingOrig, key)) conflicted = true
192
206
  }
193
207
  }
194
208
 
@@ -222,9 +236,9 @@ export function mergeCompat(args: {
222
236
 
223
237
  /**
224
238
  * Apply a freshly loaded table. Membership and metadata follow incoming;
225
- * unsaved reasoningEfforts / dirty compat keys overlay by id. Conflict only
226
- * when a locally dirty field also changed in originals (revision-only bumps
227
- * and sibling-card saves do not warn).
239
+ * unsaved overlay keys (`reasoningEfforts`, `input`) / dirty compat keys
240
+ * overlay by id. Conflict only when a locally dirty field also changed in
241
+ * originals (revision-only bumps and sibling-card saves do not warn).
228
242
  */
229
243
  export function mergeLoadedDrafts(
230
244
  current: readonly RouteDraft[],
@@ -26,7 +26,10 @@ export function writeOff(
26
26
  const next: ReasoningEfforts = { ...efforts }
27
27
  delete next.off
28
28
  if (mode === 'empty') next.off = null
29
- else if (mode === 'value') next.off = value.trim().length > 0 ? value : 'none'
29
+ else if (mode === 'value') {
30
+ const trimmed = value.trim()
31
+ next.off = trimmed.length > 0 ? trimmed : 'none'
32
+ }
30
33
  return next
31
34
  }
32
35
 
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Per-model `input` modalities as stored in llm-pi-ai settings.
3
+ * Absence falls through to route `defaultInput` (`[text]`). Empty list is
4
+ * treated as absent by the official resolver — do not write `[]`.
5
+ */
6
+ import { IMAGE_CAPABLE_INPUT, INPUT_MODALITIES } from './catalog.ts'
7
+
8
+ /** Whether the stored `input` list includes image. Absence is false. */
9
+ export function readImageCapable(row: Record<string, unknown>): boolean {
10
+ const value = row.input
11
+ return Array.isArray(value) && value.includes('image')
12
+ }
13
+
14
+ /**
15
+ * Declare or drop image input on a spread row.
16
+ * Enabled writes `[text, image]`; disabled unsets the key (not `[]`, not `[text]`).
17
+ */
18
+ export function writeImageCapable(
19
+ row: Record<string, unknown>,
20
+ enabled: boolean,
21
+ ): Record<string, unknown> {
22
+ const next = { ...row }
23
+ if (enabled) next.input = [...IMAGE_CAPABLE_INPUT]
24
+ else delete next.input
25
+ return next
26
+ }
27
+
28
+ /**
29
+ * Validate a stored `input` field. Returns an error code; never throws.
30
+ * Absence is valid. Empty list is rejected so a bad stamp cannot be re-saved.
31
+ */
32
+ export function validateInput(input: unknown): 'bad-input' | undefined {
33
+ if (input === undefined) return undefined
34
+ if (!Array.isArray(input) || input.length === 0) return 'bad-input'
35
+ const known = new Set<string>(INPUT_MODALITIES)
36
+ const seen = new Set<string>()
37
+ for (const item of input) {
38
+ if (typeof item !== 'string' || !known.has(item) || seen.has(item)) return 'bad-input'
39
+ seen.add(item)
40
+ }
41
+ if (!seen.has('text')) return 'bad-input'
42
+ return undefined
43
+ }
44
+
45
+ /** Per-model client-side check used to show errors without throwing. */
46
+ export function modelInputError(row: Record<string, unknown>): 'bad-input' | undefined {
47
+ if (!('input' in row) || row.input === undefined) return undefined
48
+ return validateInput(row.input)
49
+ }
@@ -1,7 +1,15 @@
1
1
  import { validateReasoningEfforts } from './efforts.ts'
2
+ import { modelInputError } from './input.ts'
3
+
4
+ export type ModelRowError = 'empty' | 'off-only' | 'bad-wire' | 'bad-input'
2
5
 
3
6
  /** Per-model client-side check used to show errors without throwing. */
4
7
  export function modelEffortError(row: Record<string, unknown>): 'empty' | 'off-only' | 'bad-wire' | undefined {
5
8
  if (!('reasoningEfforts' in row) || row.reasoningEfforts === undefined) return undefined
6
9
  return validateReasoningEfforts(row.reasoningEfforts)
7
10
  }
11
+
12
+ /** First blocking error on a model row (efforts, then input). */
13
+ export function modelRowError(row: Record<string, unknown>): ModelRowError | undefined {
14
+ return modelEffortError(row) ?? modelInputError(row)
15
+ }