@dsh-plus/subagent-model 0.1.7 → 0.1.8

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.
package/lib/client.js CHANGED
@@ -28,6 +28,42 @@ window.__ModuleLoader__.load({
28
28
  return parse(await fetch(ROUTE_CATALOG, { credentials: "same-origin" }));
29
29
  }
30
30
  //#endregion
31
+ //#region src/client/draft.ts
32
+ const EMPTY_ROW = {
33
+ enabled: false,
34
+ provider: "",
35
+ model: "",
36
+ reasoningEffort: "inherit"
37
+ };
38
+ /** 行集 = 目录 subagentProviders ∪ 已配置条目;目录行缺省为空行。 */
39
+ function draftFrom(value, catalog) {
40
+ const rows = {};
41
+ const names = /* @__PURE__ */ new Set();
42
+ for (const name of catalog?.subagentProviders ?? []) names.add(name);
43
+ for (const name of Object.keys(value.entries).sort()) names.add(name);
44
+ for (const name of names) {
45
+ const entry = value.entries[name];
46
+ rows[name] = entry === void 0 ? { ...EMPTY_ROW } : {
47
+ enabled: entry.enabled,
48
+ provider: entry.provider,
49
+ model: entry.model,
50
+ reasoningEffort: entry.reasoningEffort
51
+ };
52
+ }
53
+ return {
54
+ enabled: value.enabled,
55
+ rows
56
+ };
57
+ }
58
+ function toPatch(draft) {
59
+ const entries = {};
60
+ for (const name of Object.keys(draft.rows).sort()) entries[name] = draft.rows[name];
61
+ return {
62
+ enabled: draft.enabled,
63
+ entries
64
+ };
65
+ }
66
+ //#endregion
31
67
  //#region src/client/fields.tsx
32
68
  function CheckRow(props) {
33
69
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -91,39 +127,8 @@ window.__ModuleLoader__.load({
91
127
  kind: "idle",
92
128
  text: ""
93
129
  };
94
- const EMPTY_ROW = {
95
- enabled: false,
96
- provider: "",
97
- model: "",
98
- reasoningEffort: "inherit"
99
- };
100
130
  const EFFORT_INHERIT = "inherit";
101
131
  const EFFORT_DEFAULT = "default";
102
- function draftFrom(value, catalog) {
103
- const rows = {};
104
- const names = /* @__PURE__ */ new Set();
105
- for (const name of catalog?.subagentProviders ?? []) names.add(name);
106
- for (const name of Object.keys(value.entries).sort()) names.add(name);
107
- for (const name of names) {
108
- const entry = value.entries[name];
109
- rows[name] = entry === void 0 ? { ...EMPTY_ROW } : {
110
- enabled: entry.enabled,
111
- provider: entry.provider,
112
- model: entry.model,
113
- reasoningEffort: entry.reasoningEffort
114
- };
115
- }
116
- return {
117
- enabled: value.enabled,
118
- rows
119
- };
120
- }
121
- function toPatch(draft) {
122
- return {
123
- enabled: draft.enabled,
124
- entries: draft.rows
125
- };
126
- }
127
132
  function unknownOption(value, label) {
128
133
  return {
129
134
  value,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-plus/subagent-model",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "dsh-plus service+ui plugin: 为 subagent/subagent_fork 等子代理按提供商配置模型与思考程度(或继承主代理)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -11,6 +11,14 @@ import { type ReactElement, useEffect, useMemo, useState, useSyncExternalStore }
11
11
 
12
12
  import { SETTINGS_NS } from '../ns.ts'
13
13
  import { type CatalogProvider, fetchCatalog, type ModelCatalog } from './api.ts'
14
+ import {
15
+ type ConfigValue,
16
+ type Draft,
17
+ type DraftRow,
18
+ draftFrom,
19
+ EMPTY_ROW,
20
+ toPatch,
21
+ } from './draft.ts'
14
22
  import { CheckRow, SelectField, type SelectOption } from './fields.tsx'
15
23
  import type { Scope, SettingsApi } from './scope.ts'
16
24
 
@@ -20,70 +28,15 @@ export interface CardProps {
20
28
  api: SettingsApi
21
29
  }
22
30
 
23
- /** settings 命名空间的解析值(无 secret 字段)。 */
24
- export interface ConfigValue {
25
- enabled: boolean
26
- entries: Record<string, WireEntry>
27
- }
28
-
29
- export interface WireEntry {
30
- enabled: boolean
31
- provider: string
32
- model: string
33
- reasoningEffort: string
34
- }
35
-
36
- interface DraftRow {
37
- enabled: boolean
38
- provider: string
39
- model: string
40
- reasoningEffort: string
41
- }
42
-
43
- interface Draft {
44
- enabled: boolean
45
- rows: Record<string, DraftRow>
46
- }
47
-
48
31
  interface Status {
49
32
  kind: 'idle' | 'ok' | 'error'
50
33
  text: string
51
34
  }
52
35
 
53
36
  const IDLE_STATUS: Status = { kind: 'idle', text: '' }
54
- const EMPTY_ROW: DraftRow = {
55
- enabled: false,
56
- provider: '',
57
- model: '',
58
- reasoningEffort: 'inherit',
59
- }
60
37
  const EFFORT_INHERIT = 'inherit'
61
38
  const EFFORT_DEFAULT = 'default'
62
39
 
63
- function draftFrom(value: ConfigValue, catalog: ModelCatalog | null): Draft {
64
- const rows: Record<string, DraftRow> = {}
65
- const names = new Set<string>()
66
- for (const name of catalog?.subagentProviders ?? []) names.add(name)
67
- for (const name of Object.keys(value.entries).sort()) names.add(name)
68
- for (const name of names) {
69
- const entry = value.entries[name]
70
- rows[name] =
71
- entry === undefined
72
- ? { ...EMPTY_ROW }
73
- : {
74
- enabled: entry.enabled,
75
- provider: entry.provider,
76
- model: entry.model,
77
- reasoningEffort: entry.reasoningEffort,
78
- }
79
- }
80
- return { enabled: value.enabled, rows }
81
- }
82
-
83
- function toPatch(draft: Draft): Record<string, unknown> {
84
- return { enabled: draft.enabled, entries: draft.rows }
85
- }
86
-
87
40
  function unknownOption(value: string, label: string): SelectOption {
88
41
  return { value, label: `${value}(${label})` }
89
42
  }
@@ -20,7 +20,7 @@ import type { Context } from '@deepseek-ai/cordis'
20
20
  import { SETTINGS_NS } from '../ns.ts'
21
21
  import { SubagentModelCard } from './card.tsx'
22
22
  import { en, NS, zh } from './i18n.ts'
23
- import type { Scope, SettingsApi } from './scope.ts'
23
+ import type { Scope, ScopeSnapshot, SettingsApi } from './scope.ts'
24
24
  import { injectStyle } from './styles.ts'
25
25
 
26
26
  export const name = 'dsh-plus-subagent-model'
@@ -0,0 +1,69 @@
1
+ /**
2
+ * 配置卡片的可编辑草稿模型:ConfigValue ↔ Draft 转换与提交补丁(纯函数,
3
+ * 与渲染分离以便单测)。行集合 = 目录返回的已注册子代理 provider ∪ 已配置条目;
4
+ * 未配置的新 provider 行以默认空值落盘(自文档化)。
5
+ * @module subagent-model/client/draft
6
+ */
7
+ import type { ModelCatalog } from './api.ts'
8
+
9
+ /** settings 命名空间的解析值(无 secret 字段)。 */
10
+ export interface ConfigValue {
11
+ enabled: boolean
12
+ entries: Record<string, WireEntry>
13
+ }
14
+
15
+ export interface WireEntry {
16
+ enabled: boolean
17
+ provider: string
18
+ model: string
19
+ reasoningEffort: string
20
+ }
21
+
22
+ export interface DraftRow {
23
+ enabled: boolean
24
+ provider: string
25
+ model: string
26
+ reasoningEffort: string
27
+ }
28
+
29
+ export interface Draft {
30
+ enabled: boolean
31
+ rows: Record<string, DraftRow>
32
+ }
33
+
34
+ export const EMPTY_ROW: DraftRow = {
35
+ enabled: false,
36
+ provider: '',
37
+ model: '',
38
+ reasoningEffort: 'inherit',
39
+ }
40
+
41
+ /** 行集 = 目录 subagentProviders ∪ 已配置条目;目录行缺省为空行。 */
42
+ export function draftFrom(value: ConfigValue, catalog: ModelCatalog | null): Draft {
43
+ const rows: Record<string, DraftRow> = {}
44
+ const names = new Set<string>()
45
+ for (const name of catalog?.subagentProviders ?? []) names.add(name)
46
+ for (const name of Object.keys(value.entries).sort()) names.add(name)
47
+ for (const name of names) {
48
+ const entry = value.entries[name]
49
+ rows[name] =
50
+ entry === undefined
51
+ ? { ...EMPTY_ROW }
52
+ : {
53
+ enabled: entry.enabled,
54
+ provider: entry.provider,
55
+ model: entry.model,
56
+ reasoningEffort: entry.reasoningEffort,
57
+ }
58
+ }
59
+ return { enabled: value.enabled, rows }
60
+ }
61
+
62
+ export function toPatch(draft: Draft): Record<string, unknown> {
63
+ // entries 按键排序物化:dirty 比较走 JSON.stringify,而草稿的播种路径
64
+ // (先 entries 后补目录空行)与 draftFrom(先目录后 entries)键序不同,
65
+ // 不排序会出现「未改动却永久 dirty」的假阳性。
66
+ const entries: Record<string, DraftRow> = {}
67
+ for (const name of Object.keys(draft.rows).sort()) entries[name] = draft.rows[name]
68
+ return { enabled: draft.enabled, entries }
69
+ }
@@ -35,8 +35,11 @@ export interface SettingsApi {
35
35
  result: {
36
36
  ok: boolean
37
37
  value?: {
38
+ writable: boolean
38
39
  namespaces: Array<{
39
40
  ns: string
41
+ value: unknown
42
+ revision: number
40
43
  secrets: Array<{ path: string[]; set: boolean }>
41
44
  }>
42
45
  }