@linxin666/dsh-liangshen 0.3.24 → 0.4.0
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/README.i18n.yaml +2 -2
- package/README.md +24 -17
- package/README.zh.md +25 -18
- package/cordis.patch.yml +3 -2
- package/icon.svg +3 -0
- package/lib/client.js +381 -77
- package/lib/client.js.map +1 -1
- package/lib/index.js +594 -428
- package/lib/types/announce.test.d.ts +10 -0
- package/lib/types/client/LiangShenSettingsCard.d.ts +27 -10
- package/lib/types/client/PluginSettingsCard.d.ts +4 -0
- package/lib/types/client/index.d.ts +32 -13
- package/lib/types/client/lever-controller.d.ts +16 -2
- package/lib/types/client/locales.d.ts +13 -0
- package/lib/types/client/main-session.d.ts +32 -0
- package/lib/types/client/plugin-card-seat.d.ts +23 -16
- package/lib/types/client/settings-form.d.ts +17 -17
- package/lib/types/composition.d.ts +116 -0
- package/lib/types/composition.test.d.ts +7 -0
- package/lib/types/index.d.ts +146 -31
- package/lib/types/index.test.d.ts +5 -0
- package/package.json +25 -20
- package/presets/liangshen/agent.cordis.yml +44 -10
- package/presets/liangshen/fact-ledger.mjs +141 -0
- package/presets/liangshen/guard.mjs +426 -0
- package/presets/liangshen/minimal-prompt.mjs +2 -2
- package/presets/liangshen/tool-catalog.mjs +24 -20
- package/presets/liangshen/working-context.mjs +10 -2
- package/src/announce.test.ts +248 -55
- package/src/client/LiangShenLever.module.css +2 -0
- package/src/client/LiangShenLever.tsx +37 -9
- package/src/client/LiangShenSettingsCard.tsx +96 -12
- package/src/client/PluginSettingsCard.tsx +7 -2
- package/src/client/index.ts +61 -23
- package/src/client/lever-controller.ts +76 -9
- package/src/client/locales.ts +30 -4
- package/src/client/main-session.ts +43 -0
- package/src/client/plugin-card-seat.ts +24 -17
- package/src/client/settings-form.ts +34 -31
- package/src/composition.test.ts +294 -0
- package/src/composition.ts +554 -0
- package/src/index.test.ts +68 -1
- package/src/index.ts +278 -107
- package/tools/benchmark-live-run.mjs +171 -32
- package/lib/types/schema.d.ts +0 -18
- package/lib/types/schema.test.d.ts +0 -1
- package/lib/types/sync.d.ts +0 -74
- package/lib/types/sync.test.d.ts +0 -1
- package/src/schema.test.ts +0 -64
- package/src/schema.ts +0 -110
- package/src/sync.test.ts +0 -303
- package/src/sync.ts +0 -324
package/src/announce.test.ts
CHANGED
|
@@ -1,76 +1,269 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* The host half against a fake cordis context: announcing (issue #839) and the
|
|
3
|
+
* preset DECLARATION that replaces the pre-0.1.7 preset-file sync.
|
|
4
|
+
*
|
|
5
|
+
* Declare = enabled: activation registers the bundled preset with
|
|
6
|
+
* `ctx.agentPresets` and keeps the returned disposer, a committed settings write
|
|
7
|
+
* re-declares through `loader/volatile-update`, and unloading releases the
|
|
8
|
+
* registration. Each test re-imports the module so the mount-once guard cannot
|
|
9
|
+
* swallow a second apply call.
|
|
6
10
|
*/
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
|
|
12
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
13
|
+
|
|
14
|
+
import type { PresetDefinition } from '@deepseek-ai/dsh-agent-preset-registry'
|
|
15
|
+
import { bundledPresetDir, resolveConfig } from '../src/index.ts'
|
|
16
|
+
|
|
17
|
+
/** Disposer the fake registry hands back for one declaration. */
|
|
18
|
+
interface FakeRegistration {
|
|
19
|
+
/** The definition the plugin declared. */
|
|
20
|
+
definition: PresetDefinition
|
|
21
|
+
/** Whether the plugin released this registration. */
|
|
22
|
+
released: boolean
|
|
15
23
|
}
|
|
16
24
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
/** The host surface `apply` touches, with everything the tests observe. */
|
|
26
|
+
interface FakeHost {
|
|
27
|
+
ctx: never
|
|
28
|
+
/** The sections the announcement registered, in order. */
|
|
29
|
+
sections: { name: string, order: number, text: string }[]
|
|
30
|
+
/** The declarations the plugin submitted, in order. */
|
|
31
|
+
declarations: FakeRegistration[]
|
|
32
|
+
/** Logger lines the plugin emitted. */
|
|
33
|
+
warnings: string[]
|
|
34
|
+
/** Run every disposer the plugin registered through `ctx.effect`. */
|
|
35
|
+
unload(): Promise<void>
|
|
36
|
+
/** Dispatch `loader/volatile-update` to this fiber's listeners. */
|
|
37
|
+
commit(): void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Build a fake host context; `withRegistry: false` models a deployment without one. */
|
|
41
|
+
function makeHost(options: { withRegistry?: boolean } = {}): FakeHost {
|
|
42
|
+
const sections: FakeHost['sections'] = []
|
|
43
|
+
const declarations: FakeRegistration[] = []
|
|
44
|
+
const warnings: string[] = []
|
|
45
|
+
const effects: unknown[] = []
|
|
46
|
+
const listeners = new Map<string, ((...args: unknown[]) => void)[]>()
|
|
47
|
+
const registry = options.withRegistry === false ? undefined : {
|
|
48
|
+
register: async (definition: PresetDefinition) => {
|
|
49
|
+
const record: FakeRegistration = { definition, released: false }
|
|
50
|
+
declarations.push(record)
|
|
51
|
+
return async () => { record.released = true }
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
const ctx = {
|
|
55
|
+
systemPrompt: {
|
|
56
|
+
section: (spec: { name: string, order: number, text: string }) => {
|
|
57
|
+
sections.push(spec)
|
|
58
|
+
return () => {}
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
effect: (fn: () => unknown) => {
|
|
62
|
+
const disposer = fn()
|
|
63
|
+
effects.push(disposer)
|
|
64
|
+
return disposer
|
|
65
|
+
},
|
|
66
|
+
on: (event: string, listener: (...args: unknown[]) => void) => {
|
|
67
|
+
const list = listeners.get(event) ?? []
|
|
68
|
+
list.push(listener)
|
|
69
|
+
listeners.set(event, list)
|
|
70
|
+
return () => { listeners.set(event, (listeners.get(event) ?? []).filter(entry => entry !== listener)) }
|
|
23
71
|
},
|
|
72
|
+
get: (name: string) => (name === 'agentPresets' ? registry : undefined),
|
|
73
|
+
logger: { warn: (message: string) => { warnings.push(message) }, info: () => {} },
|
|
24
74
|
}
|
|
25
75
|
return {
|
|
26
|
-
ctx:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
76
|
+
ctx: ctx as never,
|
|
77
|
+
sections,
|
|
78
|
+
declarations,
|
|
79
|
+
warnings,
|
|
80
|
+
async unload() {
|
|
81
|
+
for (const disposer of effects.splice(0)) {
|
|
82
|
+
if (typeof disposer === 'function') await (disposer as () => unknown)()
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
commit() {
|
|
86
|
+
for (const listener of listeners.get('loader/volatile-update') ?? []) listener([])
|
|
87
|
+
},
|
|
33
88
|
}
|
|
34
89
|
}
|
|
35
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Flush the declaration queue. It is pure promise chaining, so a bounded run of
|
|
93
|
+
* microtask turns settles it without a timer (and without depending on wall
|
|
94
|
+
* clock time).
|
|
95
|
+
*/
|
|
96
|
+
async function settle(): Promise<void> {
|
|
97
|
+
for (let turn = 0; turn < 64; turn += 1) await Promise.resolve()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Hosts mounted by this file, released after each test: the plugin's mount-once
|
|
102
|
+
* guard is process-wide, so a host left mounted would silence the next apply.
|
|
103
|
+
*/
|
|
104
|
+
const mounted: FakeHost[] = []
|
|
105
|
+
|
|
106
|
+
afterEach(async () => {
|
|
107
|
+
for (const host of mounted.splice(0)) await host.unload()
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
/** One loaded module plus the host it was applied to. */
|
|
111
|
+
async function mount(
|
|
112
|
+
config?: Record<string, unknown>,
|
|
113
|
+
options: { withRegistry?: boolean } = {},
|
|
114
|
+
): Promise<{ mod: typeof import('../src/index.ts'), host: FakeHost }> {
|
|
115
|
+
vi.resetModules()
|
|
116
|
+
const mod = await import('../src/index.ts')
|
|
117
|
+
const host = makeHost(options)
|
|
118
|
+
mounted.push(host)
|
|
119
|
+
mod.apply(host.ctx, config as never)
|
|
120
|
+
await settle()
|
|
121
|
+
return { mod, host }
|
|
122
|
+
}
|
|
123
|
+
|
|
36
124
|
describe('dsh-liangshen announcement (issue #839)', () => {
|
|
37
|
-
it('
|
|
125
|
+
it('operator keeps the announcement off until the schema default is changed', async () => {
|
|
126
|
+
// Given the shipped Config schema, When the operator reads its defaults,
|
|
127
|
+
// Then the announcement stays off while the plugin itself stays enabled.
|
|
38
128
|
vi.resetModules()
|
|
39
129
|
const mod = await import('../src/index.ts')
|
|
40
|
-
|
|
41
|
-
expect(value.announceToAgent).toBe(false)
|
|
42
|
-
expect(value.enabled).toBe(true)
|
|
130
|
+
expect(resolveConfig(mod.Config({}))).toMatchObject({ announceToAgent: false, enabled: true })
|
|
43
131
|
})
|
|
44
132
|
|
|
45
|
-
it('
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
133
|
+
it('operator turns the announcement on and the section carries the guidance', async () => {
|
|
134
|
+
// Given a config that announces the plugin, When the operator activates
|
|
135
|
+
// it, Then one system-prompt section carries the guidance text.
|
|
136
|
+
const { mod, host } = await mount({ announceToAgent: true })
|
|
137
|
+
expect(host.sections.length).toBe(1)
|
|
138
|
+
expect(host.sections[0]?.name).toBe('plugin:dsh-liangshen')
|
|
139
|
+
expect(host.sections[0]?.text).toBe(mod.LIANGSHEN_GUIDANCE)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('operator keeps every prompt clean under the default config', async () => {
|
|
143
|
+
// Given an activation with no config at all, When the operator mounts the
|
|
144
|
+
// plugin, Then no announcement section registers.
|
|
145
|
+
const { host } = await mount(undefined)
|
|
146
|
+
expect(host.sections.length).toBe(0)
|
|
147
|
+
})
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
describe('dsh-liangshen preset declaration', () => {
|
|
151
|
+
it('operator gets the bundled preset declared at activation and released on unload', async () => {
|
|
152
|
+
// Given a host whose registry is mounted, When the operator activates the
|
|
153
|
+
// plugin, Then the shipped preset is declared and unload releases it.
|
|
154
|
+
const { host } = await mount(undefined)
|
|
155
|
+
expect(host.declarations.length).toBe(1)
|
|
156
|
+
const { definition } = host.declarations[0]!
|
|
157
|
+
expect(definition.id).toBe('liangshen')
|
|
158
|
+
// Display text comes from the preset's own preset.yml, so the roster shows
|
|
159
|
+
// the same name an installed copy would.
|
|
160
|
+
expect(definition.name).toBe('梁神模式')
|
|
161
|
+
expect(definition.order).toBe(4)
|
|
162
|
+
expect(definition.plugins.length).toBeGreaterThan(20)
|
|
163
|
+
// Relative module names point inside the bundled preset directory: the
|
|
164
|
+
// registry mounts the declaration under its own loader base.
|
|
165
|
+
for (const plugin of definition.plugins) {
|
|
166
|
+
if ((plugin.name ?? '').startsWith('file:')) expect(plugin.name).toContain('presets')
|
|
59
167
|
}
|
|
168
|
+
await host.unload()
|
|
169
|
+
expect(host.declarations[0]?.released).toBe(true)
|
|
60
170
|
})
|
|
61
171
|
|
|
62
|
-
it('
|
|
172
|
+
it('operator gets the committed settings applied to the rows they shape', async () => {
|
|
173
|
+
// Given committed presentation and guard settings, When the operator
|
|
174
|
+
// activates the plugin, Then the declared rows carry those values.
|
|
175
|
+
const { host } = await mount({ presentation: 'ptc', guardEnabled: false, guardEchoFailures: 5 })
|
|
176
|
+
const rows = host.declarations[0]!.definition.plugins as readonly { id?: string, config?: Record<string, unknown> }[]
|
|
177
|
+
expect(rows.find(row => row.id === 'tool-catalog')?.config?.['presentation']).toBe('ptc')
|
|
178
|
+
expect(rows.find(row => row.id === 'guard')?.config).toEqual({
|
|
179
|
+
enabled: false,
|
|
180
|
+
sensitivity: 'balanced',
|
|
181
|
+
stallReasoningChars: 8000,
|
|
182
|
+
globalStallCap: 4,
|
|
183
|
+
echoFailures: 5,
|
|
184
|
+
})
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('operator keeps the roster and the prompt untouched while the master switch is off', async () => {
|
|
188
|
+
// Given a disabled row that still asks for the announcement, When the
|
|
189
|
+
// operator activates it, Then nothing is declared and nothing is announced.
|
|
190
|
+
const { host } = await mount({ enabled: false, announceToAgent: true })
|
|
191
|
+
expect(host.declarations.length).toBe(0)
|
|
192
|
+
expect(host.sections.length).toBe(0)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
it('operator sees a committed settings write re-declare the preset', async () => {
|
|
196
|
+
// Given a running row whose volatile references the Host commits into,
|
|
197
|
+
// When the operator writes a new presentation and the Loader announces it,
|
|
198
|
+
// Then the preset is declared again and the previous declaration released.
|
|
63
199
|
vi.resetModules()
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
200
|
+
const mod = await import('../src/index.ts')
|
|
201
|
+
let presentation = 'both'
|
|
202
|
+
let announceToAgent = false
|
|
203
|
+
const host = makeHost()
|
|
204
|
+
mounted.push(host)
|
|
205
|
+
mod.apply(host.ctx, {
|
|
206
|
+
presentation: { get: () => presentation } as never,
|
|
207
|
+
announceToAgent: { get: () => announceToAgent } as never,
|
|
208
|
+
})
|
|
209
|
+
await settle()
|
|
210
|
+
expect(host.declarations.length).toBe(1)
|
|
211
|
+
|
|
212
|
+
presentation = 'native'
|
|
213
|
+
announceToAgent = true
|
|
214
|
+
host.commit()
|
|
215
|
+
await settle()
|
|
216
|
+
expect(host.declarations.length).toBe(2)
|
|
217
|
+
expect(host.declarations[0]?.released).toBe(true)
|
|
218
|
+
const rows = host.declarations[1]!.definition.plugins as readonly { id?: string, config?: Record<string, unknown> }[]
|
|
219
|
+
expect(rows.find(row => row.id === 'tool-catalog')?.config?.['presentation']).toBe('native')
|
|
220
|
+
expect(host.sections.length).toBe(1)
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
it('operator gets a burst of settings writes settled on the last one', async () => {
|
|
224
|
+
// Given a running row and two committed writes in a row, When the operator
|
|
225
|
+
// lets the declaration queue drain, Then one live declaration holds the
|
|
226
|
+
// last value and every predecessor is released.
|
|
227
|
+
vi.resetModules()
|
|
228
|
+
const mod = await import('../src/index.ts')
|
|
229
|
+
let presentation = 'both'
|
|
230
|
+
const host = makeHost()
|
|
231
|
+
mounted.push(host)
|
|
232
|
+
mod.apply(host.ctx, { presentation: { get: () => presentation } as never })
|
|
233
|
+
await settle()
|
|
234
|
+
presentation = 'native'
|
|
235
|
+
host.commit()
|
|
236
|
+
presentation = 'ptc'
|
|
237
|
+
host.commit()
|
|
238
|
+
await settle()
|
|
239
|
+
const live = host.declarations.filter(record => !record.released)
|
|
240
|
+
expect(live.length).toBe(1)
|
|
241
|
+
const rows = live[0]!.definition.plugins as readonly { id?: string, config?: Record<string, unknown> }[]
|
|
242
|
+
expect(rows.find(row => row.id === 'tool-catalog')?.config?.['presentation']).toBe('ptc')
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
it('operator keeps a registry-less deployment running with a warning', async () => {
|
|
246
|
+
// Given a deployment that composes no agent-preset registry, When the
|
|
247
|
+
// operator activates the plugin, Then it warns instead of failing.
|
|
248
|
+
const { host } = await mount(undefined, { withRegistry: false })
|
|
249
|
+
expect(host.declarations.length).toBe(0)
|
|
250
|
+
expect(host.warnings.join('\n')).toContain('agent-preset registry is unavailable')
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
it('operator gets no declaration when a write lands while the row unloads', async () => {
|
|
254
|
+
// Given an unloaded row, When a settings write still reaches its
|
|
255
|
+
// listener, Then no preset is declared for it.
|
|
256
|
+
const { host } = await mount(undefined)
|
|
257
|
+
await host.unload()
|
|
258
|
+
host.commit()
|
|
259
|
+
await settle()
|
|
260
|
+
// The committed write must not re-declare a preset for an unloaded row.
|
|
261
|
+
expect(host.declarations.filter(record => !record.released).length).toBe(0)
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
it('operator has the bundled preset directory holding the composition', () => {
|
|
265
|
+
// Given the installed package, When the operator reads the bundled preset
|
|
266
|
+
// directory, Then it names the presets tree.
|
|
267
|
+
expect(bundledPresetDir()).toContain('presets')
|
|
75
268
|
})
|
|
76
269
|
})
|
|
@@ -29,13 +29,27 @@ const MORSE = '-.. . . .--. ... . . -.- / .... .- .-. -. . ... ...'
|
|
|
29
29
|
/** One spark per spoke of the burst. */
|
|
30
30
|
const SPARKS = Array.from({ length: 14 }, (_, index) => index)
|
|
31
31
|
|
|
32
|
+
/** Sync the hero preset chip above the composer so both controls always agree. */
|
|
33
|
+
function syncHeroChip(label: string): void {
|
|
34
|
+
try {
|
|
35
|
+
if (typeof document === 'undefined') return
|
|
36
|
+
const chip = document.querySelector<HTMLElement>('button[aria-haspopup="menu"] span[class*="seatLabel"]')
|
|
37
|
+
?? Array.from(document.querySelectorAll<HTMLElement>('button[aria-haspopup="menu"] span')).find(s => s.className.includes('seatLabel'))
|
|
38
|
+
if (chip && chip.textContent !== label) {
|
|
39
|
+
chip.textContent = label
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
// Non-browser or detached element
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
32
46
|
/** Slot entry for `conversation.input.right` (left of the model selector). */
|
|
33
47
|
export function LiangShenLever(face: LeverFace): ReactElement | null {
|
|
34
48
|
const snapshot = useSyncExternalStore(face.store.subscribe, face.store.getSnapshot)
|
|
35
49
|
const { state, restoreLabel, busy, error, burst } = snapshot
|
|
36
50
|
const [burstKey, setBurstKey] = useState(0)
|
|
37
51
|
const seen = useRef(burst)
|
|
38
|
-
const drag = useRef<{ y: number, fired: boolean } | undefined>(undefined)
|
|
52
|
+
const drag = useRef<{ x: number, y: number, fired: boolean } | undefined>(undefined)
|
|
39
53
|
const actionable = !busy && (state === 'on' || state === 'off')
|
|
40
54
|
const on = state === 'on'
|
|
41
55
|
const errorText = error === undefined
|
|
@@ -61,6 +75,17 @@ export function LiangShenLever(face: LeverFace): ReactElement | null {
|
|
|
61
75
|
return () => { clearTimeout(timer) }
|
|
62
76
|
}, [burstKey])
|
|
63
77
|
|
|
78
|
+
// Keep the hero preset chip above the composer in sync with the lever's selection
|
|
79
|
+
const prevState = useRef(state)
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (state === 'on') {
|
|
82
|
+
syncHeroChip(face.t('lever.name'))
|
|
83
|
+
} else if (prevState.current === 'on' && state === 'off' && restoreLabel !== '') {
|
|
84
|
+
syncHeroChip(restoreLabel)
|
|
85
|
+
}
|
|
86
|
+
prevState.current = state
|
|
87
|
+
}, [state, restoreLabel, face])
|
|
88
|
+
|
|
64
89
|
// The lever exists only while the preset can still change, which is the
|
|
65
90
|
// blank-session window: a started session reports `locked`, a deployment
|
|
66
91
|
// without the preset reports `missing`, and both mean the row renders
|
|
@@ -78,20 +103,23 @@ export function LiangShenLever(face: LeverFace): ReactElement | null {
|
|
|
78
103
|
|
|
79
104
|
const onPointerDown = (event: ReactPointerEvent<HTMLButtonElement>): void => {
|
|
80
105
|
if (!actionable) return
|
|
81
|
-
drag.current = { y: event.clientY, fired: false }
|
|
82
|
-
|
|
106
|
+
drag.current = { x: event.clientX, y: event.clientY, fired: false }
|
|
107
|
+
try {
|
|
108
|
+
event.currentTarget.setPointerCapture?.(event.pointerId)
|
|
109
|
+
} catch {
|
|
110
|
+
// Defensive: some environments throw on pointer capture
|
|
111
|
+
}
|
|
83
112
|
}
|
|
84
113
|
|
|
85
114
|
const onPointerMove = (event: ReactPointerEvent<HTMLButtonElement>): void => {
|
|
86
115
|
const pending = drag.current
|
|
87
116
|
if (pending === undefined || pending.fired) return
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
face.pull()
|
|
92
|
-
} else if (travel <= -DRAG_THRESHOLD_PX) {
|
|
117
|
+
const travelY = event.clientY - pending.y
|
|
118
|
+
const travelX = event.clientX - pending.x
|
|
119
|
+
if (Math.hypot(travelX, travelY) >= DRAG_THRESHOLD_PX) {
|
|
93
120
|
pending.fired = true
|
|
94
|
-
face.push()
|
|
121
|
+
if (on) face.push()
|
|
122
|
+
else face.pull()
|
|
95
123
|
}
|
|
96
124
|
}
|
|
97
125
|
|
|
@@ -1,31 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* LiangShen settings card: availability and the wire presentation. Registers
|
|
3
3
|
* into the `web-ui.plugin.item` child slot the Web UI plugin group renders,
|
|
4
|
-
* bound to the `
|
|
4
|
+
* bound to the `liangshen` settings namespace (the Host profile entry id).
|
|
5
5
|
*
|
|
6
|
-
* The presentation field does not act on this client half: the Host
|
|
7
|
-
*
|
|
8
|
-
* This card is the operator's only handle on it, which is why
|
|
9
|
-
* Host schema carries appears here.
|
|
6
|
+
* The presentation field does not act on this client half: the Host applies it
|
|
7
|
+
* to the preset it declares to the agent-preset registry, so a session reads it
|
|
8
|
+
* from its preset. This card is the operator's only handle on it, which is why
|
|
9
|
+
* every field the Host schema carries appears here.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
|
|
13
13
|
import type { SnapshotStore } from '@deepseek-ai/dsh-client-store'
|
|
14
|
-
import type {
|
|
15
|
-
import { BooleanField, ChoiceField, PluginSettingsCard } from './PluginSettingsCard.tsx'
|
|
16
|
-
import { CardForm, booleanField, choiceField, type CardActions, type CardShell, type FieldState as CardFieldState } from './settings-form.ts'
|
|
14
|
+
import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
15
|
+
import { BooleanField, ChoiceField, PluginSettingsCard, ValueField } from './PluginSettingsCard.tsx'
|
|
16
|
+
import { CardForm, booleanField, choiceField, numberField, type CardActions, type CardShell, type FieldState as CardFieldState } from './settings-form.ts'
|
|
17
17
|
|
|
18
18
|
/** Wire presentations the tool catalog accepts (mirrors the Host schema). */
|
|
19
19
|
export const PRESENTATION_CHOICES = ['ptc', 'native', 'both'] as const
|
|
20
20
|
|
|
21
|
+
/** Sensitivity presets for the circuit breaker (mirrors the Host schema). */
|
|
22
|
+
export const SENSITIVITY_CHOICES = ['conservative', 'balanced', 'aggressive'] as const
|
|
23
|
+
|
|
21
24
|
/** The LiangShen fields this card edits (the namespace's full schema). */
|
|
22
25
|
export interface LiangShenSettings {
|
|
23
26
|
/** Master switch for the plugin. */
|
|
24
27
|
enabled?: boolean
|
|
25
28
|
/** Whether the plugin announces itself in every agent's system prompt. */
|
|
26
29
|
announceToAgent?: boolean
|
|
27
|
-
/** Wire presentation
|
|
30
|
+
/** Wire presentation the Host applies to the preset's tool-catalog row. */
|
|
28
31
|
presentation?: string
|
|
32
|
+
/** Master switch for the runtime degeneration circuit breaker. */
|
|
33
|
+
guardEnabled?: boolean
|
|
34
|
+
/** Sensitivity preset scaling the breaker's adaptive thresholds. */
|
|
35
|
+
guardSensitivity?: string
|
|
36
|
+
/** Per-step reasoning-character floor for the breaker's runaway ladder. */
|
|
37
|
+
guardStallReasoningChars?: number
|
|
38
|
+
/** Consecutive output-free reasoning steps for the breaker's slow-burn ladder. */
|
|
39
|
+
guardGlobalStallCap?: number
|
|
40
|
+
/** Identical-argument tool failures for the breaker's echo ladder. */
|
|
41
|
+
guardEchoFailures?: number
|
|
29
42
|
}
|
|
30
43
|
|
|
31
44
|
/** What the LiangShen card renders. */
|
|
@@ -33,6 +46,11 @@ export interface LiangShenSettingsCardState extends CardShell {
|
|
|
33
46
|
enabled: CardFieldState
|
|
34
47
|
announceToAgent: CardFieldState
|
|
35
48
|
presentation: CardFieldState
|
|
49
|
+
guardEnabled: CardFieldState
|
|
50
|
+
guardSensitivity: CardFieldState
|
|
51
|
+
guardStallReasoningChars: CardFieldState
|
|
52
|
+
guardGlobalStallCap: CardFieldState
|
|
53
|
+
guardEchoFailures: CardFieldState
|
|
36
54
|
}
|
|
37
55
|
|
|
38
56
|
/** The registration-side face the card's slot entry injects. */
|
|
@@ -43,17 +61,22 @@ export interface LiangShenSettingsCardFace extends CardActions {
|
|
|
43
61
|
}
|
|
44
62
|
}
|
|
45
63
|
|
|
46
|
-
/** Bridges the `
|
|
64
|
+
/** Bridges the `liangshen` settings form onto the card's staged form. */
|
|
47
65
|
export class LiangShenSettingsCardController {
|
|
48
66
|
private readonly form: CardForm<LiangShenSettings>
|
|
49
67
|
private readonly store: SnapshotStore<LiangShenSettingsCardState>
|
|
50
68
|
|
|
51
|
-
/** @param scope - the bound
|
|
52
|
-
constructor(scope:
|
|
69
|
+
/** @param scope - the bound configuration form of the entry that owns this namespace. */
|
|
70
|
+
constructor(scope: ConfigForm<LiangShenSettings>) {
|
|
53
71
|
this.form = new CardForm(scope, [
|
|
54
72
|
booleanField('enabled'),
|
|
55
73
|
booleanField('announceToAgent'),
|
|
56
74
|
choiceField('presentation', PRESENTATION_CHOICES),
|
|
75
|
+
booleanField('guardEnabled'),
|
|
76
|
+
choiceField('guardSensitivity', SENSITIVITY_CHOICES),
|
|
77
|
+
numberField('guardStallReasoningChars', { integer: true, min: 200 }),
|
|
78
|
+
numberField('guardGlobalStallCap', { integer: true, min: 2 }),
|
|
79
|
+
numberField('guardEchoFailures', { integer: true, min: 2 }),
|
|
57
80
|
])
|
|
58
81
|
this.store = this.form.bind(() => this.projection())
|
|
59
82
|
}
|
|
@@ -64,6 +87,11 @@ export class LiangShenSettingsCardController {
|
|
|
64
87
|
enabled: this.form.field('enabled'),
|
|
65
88
|
announceToAgent: this.form.field('announceToAgent'),
|
|
66
89
|
presentation: this.form.field('presentation'),
|
|
90
|
+
guardEnabled: this.form.field('guardEnabled'),
|
|
91
|
+
guardSensitivity: this.form.field('guardSensitivity'),
|
|
92
|
+
guardStallReasoningChars: this.form.field('guardStallReasoningChars'),
|
|
93
|
+
guardGlobalStallCap: this.form.field('guardGlobalStallCap'),
|
|
94
|
+
guardEchoFailures: this.form.field('guardEchoFailures'),
|
|
67
95
|
}
|
|
68
96
|
}
|
|
69
97
|
|
|
@@ -109,6 +137,8 @@ export function LiangShenSettingsCard(props: LiangShenSettingsCardProps) {
|
|
|
109
137
|
descriptionKey="settings.description"
|
|
110
138
|
defaultOpen={false}
|
|
111
139
|
state={state}
|
|
140
|
+
renderChildrenWhenNotExposed
|
|
141
|
+
hideNotExposedNotice
|
|
112
142
|
onSave={props.save}
|
|
113
143
|
onDiscard={props.discard}
|
|
114
144
|
>
|
|
@@ -144,6 +174,60 @@ export function LiangShenSettingsCard(props: LiangShenSettingsCardProps) {
|
|
|
144
174
|
onEdit={(text) => { props.edit('presentation', text) }}
|
|
145
175
|
onReset={() => { props.resetField('presentation') }}
|
|
146
176
|
/>
|
|
177
|
+
<BooleanField
|
|
178
|
+
id="settings-liangshen-guard-enabled"
|
|
179
|
+
label={t('settings.guardEnabled')}
|
|
180
|
+
hint={t('settings.guardEnabledHint')}
|
|
181
|
+
onLabel={t('settings.on')}
|
|
182
|
+
offLabel={t('settings.off')}
|
|
183
|
+
{...fieldProps}
|
|
184
|
+
{...state.guardEnabled}
|
|
185
|
+
onEdit={(text) => { props.edit('guardEnabled', text) }}
|
|
186
|
+
onReset={() => { props.resetField('guardEnabled') }}
|
|
187
|
+
/>
|
|
188
|
+
<ChoiceField
|
|
189
|
+
id="settings-liangshen-guard-sensitivity"
|
|
190
|
+
label={t('settings.guardSensitivity')}
|
|
191
|
+
hint={t('settings.guardSensitivityHint')}
|
|
192
|
+
choices={SENSITIVITY_CHOICES.map(choice => ({ value: choice, label: t(`sensitivity.${choice}`) }))}
|
|
193
|
+
{...fieldProps}
|
|
194
|
+
{...state.guardSensitivity}
|
|
195
|
+
onEdit={(text) => { props.edit('guardSensitivity', text) }}
|
|
196
|
+
onReset={() => { props.resetField('guardSensitivity') }}
|
|
197
|
+
/>
|
|
198
|
+
<ValueField
|
|
199
|
+
id="settings-liangshen-guard-stall-chars"
|
|
200
|
+
numeric
|
|
201
|
+
label={t('settings.guardStallChars')}
|
|
202
|
+
hint={t('settings.guardStallCharsHint')}
|
|
203
|
+
placeholder="8000"
|
|
204
|
+
{...fieldProps}
|
|
205
|
+
{...state.guardStallReasoningChars}
|
|
206
|
+
onEdit={(text) => { props.edit('guardStallReasoningChars', text) }}
|
|
207
|
+
onReset={() => { props.resetField('guardStallReasoningChars') }}
|
|
208
|
+
/>
|
|
209
|
+
<ValueField
|
|
210
|
+
id="settings-liangshen-guard-global-cap"
|
|
211
|
+
numeric
|
|
212
|
+
label={t('settings.guardGlobalCap')}
|
|
213
|
+
hint={t('settings.guardGlobalCapHint')}
|
|
214
|
+
placeholder="4"
|
|
215
|
+
{...fieldProps}
|
|
216
|
+
{...state.guardGlobalStallCap}
|
|
217
|
+
onEdit={(text) => { props.edit('guardGlobalStallCap', text) }}
|
|
218
|
+
onReset={() => { props.resetField('guardGlobalStallCap') }}
|
|
219
|
+
/>
|
|
220
|
+
<ValueField
|
|
221
|
+
id="settings-liangshen-guard-echo"
|
|
222
|
+
numeric
|
|
223
|
+
label={t('settings.guardEchoFailures')}
|
|
224
|
+
hint={t('settings.guardEchoFailuresHint')}
|
|
225
|
+
placeholder="3"
|
|
226
|
+
{...fieldProps}
|
|
227
|
+
{...state.guardEchoFailures}
|
|
228
|
+
onEdit={(text) => { props.edit('guardEchoFailures', text) }}
|
|
229
|
+
onReset={() => { props.resetField('guardEchoFailures') }}
|
|
230
|
+
/>
|
|
147
231
|
</PluginSettingsCard>
|
|
148
232
|
)
|
|
149
233
|
}
|
|
@@ -64,6 +64,10 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
64
64
|
* edits, so the footer would sit there permanently disabled.
|
|
65
65
|
*/
|
|
66
66
|
hideFooter?: boolean
|
|
67
|
+
/** Render children even when the settings namespace is not exposed by the host. */
|
|
68
|
+
renderChildrenWhenNotExposed?: boolean
|
|
69
|
+
/** Hide the 'not exposed' warning banner when the settings namespace is not exposed. */
|
|
70
|
+
hideNotExposedNotice?: boolean
|
|
67
71
|
/** The plugin's controls. */
|
|
68
72
|
children: ReactNode
|
|
69
73
|
}
|
|
@@ -126,14 +130,15 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
126
130
|
// official settings allowlist omits third-party namespaces): show a card
|
|
127
131
|
// that explains the gap instead of vanishing, so a missing card never
|
|
128
132
|
// reads as a missing plugin.
|
|
129
|
-
if (!state.exposed) {
|
|
133
|
+
if (!state.exposed && props.renderChildrenWhenNotExposed !== true) {
|
|
134
|
+
const showNotice = props.hideNotExposedNotice !== true
|
|
130
135
|
return (
|
|
131
136
|
<li className={cardClass}>
|
|
132
137
|
{header}
|
|
133
138
|
{expanded
|
|
134
139
|
? (
|
|
135
140
|
<div className={css.body}>
|
|
136
|
-
<p className={css.notExposed} role="status">{props.t('settings.notExposed')}</p>
|
|
141
|
+
{showNotice ? <p className={css.notExposed} role="status">{props.t('settings.notExposed')}</p> : null}
|
|
137
142
|
</div>
|
|
138
143
|
)
|
|
139
144
|
: null}
|