dsh-client-auto-continue 0.12.1 → 0.13.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.md +26 -10
- package/README.zh.md +26 -10
- package/docs/screenshots/01-settings-section.png +0 -0
- package/docs/screenshots/01-settings-section.zh.png +0 -0
- package/docs/screenshots/02-settings-card.png +0 -0
- package/docs/screenshots/02-settings-card.zh.png +0 -0
- package/docs/screenshots/07-card-panels.png +0 -0
- package/docs/screenshots/07-card-panels.zh.png +0 -0
- package/docs/screenshots/08-composer-toggle.png +0 -0
- package/docs/screenshots/08-composer-toggle.zh.png +0 -0
- package/docs/screenshots/README.md +17 -12
- package/lib/client.js +322 -151
- package/lib/client.js.map +4 -4
- package/lib/index.js +32 -6
- package/lib/types/client/composer-toggle.d.ts +16 -0
- package/lib/types/client/index.d.ts +6 -0
- package/lib/types/client/locales.d.ts +6 -0
- package/lib/types/client/native-switch.d.ts +10 -0
- package/lib/types/client/settings-card.d.ts +10 -0
- package/lib/types/host/engine.d.ts +4 -0
- package/lib/types/index.d.ts +8 -0
- package/lib/types/shared/core.d.ts +3 -1
- package/package.json +3 -3
- package/src/client/composer-toggle.tsx +34 -0
- package/src/client/index.ts +19 -0
- package/src/client/locales.ts +12 -0
- package/src/client/native-switch.tsx +33 -0
- package/src/client/settings-card.tsx +76 -2
- package/src/client/settings-form.ts +12 -10
- package/src/client/styles.ts +14 -0
- package/src/host/engine.ts +30 -6
- package/src/index.ts +2 -0
- package/src/shared/core.ts +5 -1
package/lib/index.js
CHANGED
|
@@ -137,6 +137,7 @@ var DEFAULT_CONFIG = {
|
|
|
137
137
|
backoffMaxMs: 3e5,
|
|
138
138
|
notify: false,
|
|
139
139
|
paused: false,
|
|
140
|
+
showComposerToggle: true,
|
|
140
141
|
loopGuard: true,
|
|
141
142
|
loopShortChars: 40,
|
|
142
143
|
loopWindowMs: 3e4,
|
|
@@ -184,6 +185,7 @@ function resolveConfig(section) {
|
|
|
184
185
|
backoffMaxMs: numberOr(value.backoffMaxMs, DEFAULT_CONFIG.backoffMaxMs),
|
|
185
186
|
notify: booleanOr(value.notify, DEFAULT_CONFIG.notify),
|
|
186
187
|
paused: booleanOr(value.paused, DEFAULT_CONFIG.paused),
|
|
188
|
+
showComposerToggle: booleanOr(value.showComposerToggle, DEFAULT_CONFIG.showComposerToggle),
|
|
187
189
|
loopGuard: booleanOr(value.loopGuard, DEFAULT_CONFIG.loopGuard),
|
|
188
190
|
loopShortChars: Math.max(1, numberOr(value.loopShortChars, DEFAULT_CONFIG.loopShortChars)),
|
|
189
191
|
loopWindowMs: Math.max(1e3, numberOr(value.loopWindowMs, DEFAULT_CONFIG.loopWindowMs)),
|
|
@@ -631,6 +633,7 @@ var LOOP_GUARD_CANCEL_CAUSE = {
|
|
|
631
633
|
};
|
|
632
634
|
var LOOP_COMPLETED_REASON = "turn/end:completed";
|
|
633
635
|
var LOOP_SILENT_REASON = "turn/end:loop-silent";
|
|
636
|
+
var MANUAL_NOTIFICATION_REASON = "manual:notification";
|
|
634
637
|
var isLoopReason = (reason) => reason === LOOP_COMPLETED_REASON || reason === LOOP_SILENT_REASON;
|
|
635
638
|
var STREAM_NEAR_DUPLICATE_MAX_CHARS = 2048;
|
|
636
639
|
var STREAM_TAIL_MAX_CHARS = 4096;
|
|
@@ -798,12 +801,31 @@ var AutoContinueRunner = class {
|
|
|
798
801
|
}
|
|
799
802
|
return state;
|
|
800
803
|
}
|
|
804
|
+
/** Mark a child session and clear queued grace/cooldown sends. */
|
|
805
|
+
markSubagent(sessionId, state) {
|
|
806
|
+
state.subagent = true;
|
|
807
|
+
this.cancelPending(sessionId, "子代理会话");
|
|
808
|
+
}
|
|
809
|
+
/** Read durable origin from the live agent for direct action paths as well. */
|
|
810
|
+
isSubagent(sessionId, state) {
|
|
811
|
+
if (state.subagent) return true;
|
|
812
|
+
const agent = this.ctx.agents.get(sessionId);
|
|
813
|
+
if (agent?.session?.header?.origin !== "subagent") return false;
|
|
814
|
+
this.markSubagent(sessionId, state);
|
|
815
|
+
return true;
|
|
816
|
+
}
|
|
801
817
|
/**
|
|
802
818
|
* 事件入口(host 单实例): 预处理工具调用/结果/模型消息(护栏与循环信号),
|
|
803
819
|
* 然后交给回合状态机。
|
|
804
820
|
*/
|
|
805
821
|
onHostEvent(session, event) {
|
|
806
822
|
const sessionId = session.id;
|
|
823
|
+
const sessionState = this.states.get(sessionId);
|
|
824
|
+
if (session.header?.origin === "subagent") {
|
|
825
|
+
this.markSubagent(sessionId, sessionState ?? this.state(sessionId));
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
if (sessionState?.subagent) return;
|
|
807
829
|
if ((event.type === "user/message" || event.type === "assistant/message") && typeof event.surfaceOp === "object" && event.surfaceOp !== null) {
|
|
808
830
|
this.state(sessionId).tools.recordSurfaceReplacement(event.seq);
|
|
809
831
|
return;
|
|
@@ -1004,6 +1026,7 @@ var AutoContinueRunner = class {
|
|
|
1004
1026
|
* 才会用 loopText 重启回合——DSH 的 first-cause 语义保证用户 Stop 优先。
|
|
1005
1027
|
*/
|
|
1006
1028
|
interruptLoop(sessionId, state) {
|
|
1029
|
+
if (this.isSubagent(sessionId, state)) return;
|
|
1007
1030
|
if (state.loopFired) return;
|
|
1008
1031
|
if (Date.now() - state.lastAttemptAt < this.cooldownFor(state)) {
|
|
1009
1032
|
this.log(`跳过循环打断 ${sessionId}: 处于冷却期`);
|
|
@@ -1238,13 +1261,13 @@ var AutoContinueRunner = class {
|
|
|
1238
1261
|
async resumeNow(sessionId) {
|
|
1239
1262
|
if (this.disposed) return;
|
|
1240
1263
|
const state = this.state(sessionId);
|
|
1241
|
-
if (state
|
|
1264
|
+
if (this.isSubagent(sessionId, state)) return;
|
|
1242
1265
|
if (state.pendingTimer !== void 0) {
|
|
1243
1266
|
clearTimeout(state.pendingTimer);
|
|
1244
1267
|
state.pendingTimer = void 0;
|
|
1245
1268
|
}
|
|
1246
1269
|
try {
|
|
1247
|
-
await this.fire(sessionId,
|
|
1270
|
+
await this.fire(sessionId, MANUAL_NOTIFICATION_REASON, true);
|
|
1248
1271
|
} catch (error) {
|
|
1249
1272
|
console.error(`[auto-continue] 手动续跑异常 ${sessionId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1250
1273
|
}
|
|
@@ -1262,7 +1285,7 @@ var AutoContinueRunner = class {
|
|
|
1262
1285
|
schedule(sessionId, reason, force = false) {
|
|
1263
1286
|
const state = this.state(sessionId);
|
|
1264
1287
|
const config = this.getConfig();
|
|
1265
|
-
if (state
|
|
1288
|
+
if (this.isSubagent(sessionId, state)) return;
|
|
1266
1289
|
if (config.paused) {
|
|
1267
1290
|
this.log(`跳过 ${sessionId}(${reason}): 全局暂停中`);
|
|
1268
1291
|
return;
|
|
@@ -1344,14 +1367,15 @@ var AutoContinueRunner = class {
|
|
|
1344
1367
|
if (this.disposed) return;
|
|
1345
1368
|
const state = this.state(sessionId);
|
|
1346
1369
|
const config = this.getConfig();
|
|
1370
|
+
const manualResume = force && reason === MANUAL_NOTIFICATION_REASON;
|
|
1347
1371
|
if (reason.endsWith(":silent") && !config.resumeSilentTurns) return;
|
|
1348
1372
|
if (isLoopReason(reason) && !config.resumeCompletedTurns) return;
|
|
1349
|
-
if (state
|
|
1350
|
-
if (config.paused) {
|
|
1373
|
+
if (this.isSubagent(sessionId, state)) return;
|
|
1374
|
+
if (config.paused && !manualResume) {
|
|
1351
1375
|
this.log(`跳过 ${sessionId}(${reason}): 全局暂停中`);
|
|
1352
1376
|
return;
|
|
1353
1377
|
}
|
|
1354
|
-
if (Date.now() < (this.pauseUntil.get(sessionId) ?? 0)) {
|
|
1378
|
+
if (!manualResume && Date.now() < (this.pauseUntil.get(sessionId) ?? 0)) {
|
|
1355
1379
|
this.log(`跳过 ${sessionId}(${reason}): 会话暂停中`);
|
|
1356
1380
|
return;
|
|
1357
1381
|
}
|
|
@@ -1607,6 +1631,8 @@ var AutoContinueSchema = z2.object({
|
|
|
1607
1631
|
notify: z2.boolean().default(false),
|
|
1608
1632
|
/** Globally pause auto-continue: no live or scan send. */
|
|
1609
1633
|
paused: z2.boolean().default(false),
|
|
1634
|
+
/** Show the global auto-continue switch in the conversation composer. */
|
|
1635
|
+
showComposerToggle: z2.boolean().default(true),
|
|
1610
1636
|
/** Loop guard: detect a running turn spinning in place and restart it. */
|
|
1611
1637
|
loopGuard: z2.boolean().default(true),
|
|
1612
1638
|
/** A model message shorter than this many chars counts as a short sentence (loop signal). */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
|
+
import type { SnapshotStore } from './dsh-store-compat.ts';
|
|
3
|
+
export interface ComposerToggleState {
|
|
4
|
+
visible: boolean;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
writable: boolean;
|
|
7
|
+
saving: boolean;
|
|
8
|
+
failed: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ComposerToggleFace {
|
|
11
|
+
hooks: {
|
|
12
|
+
autoContinueComposer: SnapshotStore<ComposerToggleState>;
|
|
13
|
+
};
|
|
14
|
+
setEnabled: (enabled: boolean) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function AutoContinueComposerToggle(props: PropsLocale<'auto-continue'> & InjectFace<ComposerToggleFace>): import("react").JSX.Element | null;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Since 0.8.0 the auto-continue ENGINE runs inside the host process (single
|
|
5
5
|
* instance — see src/host/engine.ts), so this half only:
|
|
6
6
|
* - registers the `auto-continue` settings card in the available plugin UI,
|
|
7
|
+
* - adds a native composer switch backed by the same global pause setting,
|
|
7
8
|
* - subscribes to the host status bridge (SSE) and shows browser
|
|
8
9
|
* notifications with action buttons (Resume now / Pause 1h) via the bridge
|
|
9
10
|
* action endpoint,
|
|
@@ -13,6 +14,11 @@ import type { Context as ClientContext } from '@deepseek-ai/cordis';
|
|
|
13
14
|
import { type SettingsCardKey } from './locales.ts';
|
|
14
15
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
15
16
|
interface SlotMap {
|
|
17
|
+
/** Official compact composer tools; never occupy the resident single slot. */
|
|
18
|
+
'conversation.input.left': {
|
|
19
|
+
kind: 'list';
|
|
20
|
+
scope: 'session';
|
|
21
|
+
};
|
|
16
22
|
/** DSH 0.1.7's bundle configuration seat; only the owner props we consume. */
|
|
17
23
|
'plugins.bundle.config': {
|
|
18
24
|
kind: 'keyed';
|
|
@@ -20,6 +20,12 @@ export declare const zh: {
|
|
|
20
20
|
'section.live.title': string;
|
|
21
21
|
'section.live.description': string;
|
|
22
22
|
'field.paused': string;
|
|
23
|
+
'field.showComposerToggle': string;
|
|
24
|
+
'field.showComposerToggleHint': string;
|
|
25
|
+
'composer.label': string;
|
|
26
|
+
'composer.scope': string;
|
|
27
|
+
'composer.saving': string;
|
|
28
|
+
'composer.saveFailed': string;
|
|
23
29
|
'field.pausedHint': string;
|
|
24
30
|
'field.continueText': string;
|
|
25
31
|
'field.continueTextHint': string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
interface SwitchProps {
|
|
3
|
+
checked: boolean;
|
|
4
|
+
onChange: (checked: boolean) => void;
|
|
5
|
+
label: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
title?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const NativeSwitch: ComponentType<SwitchProps>;
|
|
10
|
+
export {};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
2
|
import { type AutoContinueSettings } from './engine.ts';
|
|
3
|
+
import type { ComposerToggleFace } from './composer-toggle.tsx';
|
|
3
4
|
import { type SettingsScope, type SnapshotStore } from './dsh-store-compat.ts';
|
|
4
5
|
import { type CardActions, type CardFieldState, type CardShell } from './settings-form.ts';
|
|
5
6
|
/** What the auto-continue card renders. */
|
|
6
7
|
export interface AutoContinueSettingsCardState extends CardShell {
|
|
7
8
|
paused: CardFieldState;
|
|
9
|
+
showComposerToggle: CardFieldState;
|
|
8
10
|
continueText: CardFieldState;
|
|
9
11
|
continueTextMaxTokens: CardFieldState;
|
|
10
12
|
resumeSilentTurns: CardFieldState;
|
|
@@ -43,8 +45,13 @@ export interface AutoContinueSettingsCardFace extends CardActions {
|
|
|
43
45
|
}
|
|
44
46
|
/** Bridges the `auto-continue` scope onto the card's staged form. */
|
|
45
47
|
export declare class AutoContinueSettingsCardController {
|
|
48
|
+
private readonly scope;
|
|
46
49
|
private readonly form;
|
|
47
50
|
private readonly store;
|
|
51
|
+
private readonly composer;
|
|
52
|
+
private composerSaving;
|
|
53
|
+
private composerFailed;
|
|
54
|
+
private disposed;
|
|
48
55
|
/**
|
|
49
56
|
* @param scope - the bound settings scope for the `auto-continue` namespace.
|
|
50
57
|
*/
|
|
@@ -55,6 +62,9 @@ export declare class AutoContinueSettingsCardController {
|
|
|
55
62
|
* @returns the card's snapshot and its form actions.
|
|
56
63
|
*/
|
|
57
64
|
inject(): AutoContinueSettingsCardFace;
|
|
65
|
+
injectComposer(): ComposerToggleFace;
|
|
66
|
+
private composerProjection;
|
|
67
|
+
private setEnabled;
|
|
58
68
|
/** Release this card's subscription to the provider-owned settings form. */
|
|
59
69
|
dispose(): void;
|
|
60
70
|
}
|
|
@@ -68,6 +68,10 @@ export declare class AutoContinueRunner {
|
|
|
68
68
|
handleNoticeAction(sessionId: SessionId | undefined, action: string): void;
|
|
69
69
|
dispose(): void;
|
|
70
70
|
private state;
|
|
71
|
+
/** Mark a child session and clear queued grace/cooldown sends. */
|
|
72
|
+
private markSubagent;
|
|
73
|
+
/** Read durable origin from the live agent for direct action paths as well. */
|
|
74
|
+
private isSubagent;
|
|
71
75
|
/**
|
|
72
76
|
* 事件入口(host 单实例): 预处理工具调用/结果/模型消息(护栏与循环信号),
|
|
73
77
|
* 然后交给回合状态机。
|
package/lib/types/index.d.ts
CHANGED
|
@@ -63,6 +63,8 @@ export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
|
|
|
63
63
|
notify: z<boolean, boolean>;
|
|
64
64
|
/** Globally pause auto-continue: no live or scan send. */
|
|
65
65
|
paused: z<boolean, boolean>;
|
|
66
|
+
/** Show the global auto-continue switch in the conversation composer. */
|
|
67
|
+
showComposerToggle: z<boolean, boolean>;
|
|
66
68
|
/** Loop guard: detect a running turn spinning in place and restart it. */
|
|
67
69
|
loopGuard: z<boolean, boolean>;
|
|
68
70
|
/** A model message shorter than this many chars counts as a short sentence (loop signal). */
|
|
@@ -124,6 +126,8 @@ export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
|
|
|
124
126
|
notify: z<boolean, boolean>;
|
|
125
127
|
/** Globally pause auto-continue: no live or scan send. */
|
|
126
128
|
paused: z<boolean, boolean>;
|
|
129
|
+
/** Show the global auto-continue switch in the conversation composer. */
|
|
130
|
+
showComposerToggle: z<boolean, boolean>;
|
|
127
131
|
/** Loop guard: detect a running turn spinning in place and restart it. */
|
|
128
132
|
loopGuard: z<boolean, boolean>;
|
|
129
133
|
/** A model message shorter than this many chars counts as a short sentence (loop signal). */
|
|
@@ -190,6 +194,8 @@ export declare const Config: z<Schemastery.ObjectS<{
|
|
|
190
194
|
notify: z<boolean, boolean>;
|
|
191
195
|
/** Globally pause auto-continue: no live or scan send. */
|
|
192
196
|
paused: z<boolean, boolean>;
|
|
197
|
+
/** Show the global auto-continue switch in the conversation composer. */
|
|
198
|
+
showComposerToggle: z<boolean, boolean>;
|
|
193
199
|
/** Loop guard: detect a running turn spinning in place and restart it. */
|
|
194
200
|
loopGuard: z<boolean, boolean>;
|
|
195
201
|
/** A model message shorter than this many chars counts as a short sentence (loop signal). */
|
|
@@ -251,6 +257,8 @@ export declare const Config: z<Schemastery.ObjectS<{
|
|
|
251
257
|
notify: z<boolean, boolean>;
|
|
252
258
|
/** Globally pause auto-continue: no live or scan send. */
|
|
253
259
|
paused: z<boolean, boolean>;
|
|
260
|
+
/** Show the global auto-continue switch in the conversation composer. */
|
|
261
|
+
showComposerToggle: z<boolean, boolean>;
|
|
254
262
|
/** Loop guard: detect a running turn spinning in place and restart it. */
|
|
255
263
|
loopGuard: z<boolean, boolean>;
|
|
256
264
|
/** A model message shorter than this many chars counts as a short sentence (loop signal). */
|
|
@@ -76,6 +76,8 @@ export interface AutoContinueSettings {
|
|
|
76
76
|
notify?: boolean;
|
|
77
77
|
/** Globally pause auto-continue: no live or scan send, queued pending sends cancelled. */
|
|
78
78
|
paused?: boolean;
|
|
79
|
+
/** Show the global auto-continue switch in the conversation composer. */
|
|
80
|
+
showComposerToggle?: boolean;
|
|
79
81
|
/** Loop guard: detect a running turn spinning in place (short talk without tools, or the same tool repeating) and restart it. */
|
|
80
82
|
loopGuard?: boolean;
|
|
81
83
|
/** A model message shorter than this many chars counts as a "short sentence" (loop signal). */
|
|
@@ -289,7 +291,7 @@ export interface SessionState {
|
|
|
289
291
|
running: boolean | undefined;
|
|
290
292
|
/** 当前排队消息数(来自 session/queue 帧)。 */
|
|
291
293
|
queued: number;
|
|
292
|
-
/** 子代理会话(
|
|
294
|
+
/** 子代理会话(session header origin is `subagent`). */
|
|
293
295
|
subagent: boolean;
|
|
294
296
|
/** 最近一次回合失败的事实(用于分类与模板填充)。 */
|
|
295
297
|
lastFailure: FailureFacts | undefined;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-client-auto-continue",
|
|
3
3
|
"description": "DSH Web UI plugin: automatically sends a localized continue prompt when a request is interrupted by network errors or other non-human causes",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.13.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/types/index.d.ts",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"build": "node build.mjs && tsc -p tsconfig.build.json",
|
|
47
47
|
"watch": "node build.mjs --watch",
|
|
48
48
|
"typecheck": "tsc --noEmit",
|
|
49
|
-
"test:runtime": "node tests/settings-host-live.mjs 0.1.7 && node tests/settings-host-live.mjs 0.2.0 && node tests/profile-compatibility.mjs && node tests/client-settings-services.mjs 0.2.0",
|
|
50
|
-
"test": "node tests/scan-on-boot.mjs && node tests/silent-turn-boundaries.mjs && node tests/autonomous-loop.mjs && node tests/stats-freshness.mjs && node tests/simulate-host.mjs && node tests/settings-host-compat.mjs && node tests/simulate-client-loader.mjs && node tests/client-settings-services.mjs && node tests/locale-mirror-bounded.mjs && node tests/settings-card-ui.mjs && node tests/prepare-github-package.mjs",
|
|
49
|
+
"test:runtime": "node tests/settings-host-live.mjs 0.1.7 && node tests/settings-host-live.mjs 0.2.0 && node tests/settings-host-live.mjs 0.2.1 && node tests/profile-compatibility.mjs 0.2.0 && node tests/profile-compatibility.mjs 0.2.1 && node tests/client-settings-services.mjs 0.2.0 && node tests/client-settings-services.mjs 0.2.1",
|
|
50
|
+
"test": "node tests/scan-on-boot.mjs && node tests/silent-turn-boundaries.mjs && node tests/autonomous-loop.mjs && node tests/manual-resume-pauses.mjs && node tests/stats-freshness.mjs && node tests/simulate-host.mjs && node tests/settings-host-compat.mjs && node tests/simulate-client-loader.mjs && node tests/client-settings-services.mjs && node tests/client-settings-form.mjs && node tests/locale-mirror-bounded.mjs && node tests/settings-card-ui.mjs && node tests/composer-toggle.mjs && node tests/prepare-github-package.mjs",
|
|
51
51
|
"prepack": "npm run build"
|
|
52
52
|
},
|
|
53
53
|
"keywords": [
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
|
+
import type { SnapshotStore } from './dsh-store-compat.ts';
|
|
3
|
+
import { NativeSwitch } from './native-switch.tsx';
|
|
4
|
+
|
|
5
|
+
export interface ComposerToggleState {
|
|
6
|
+
visible: boolean;
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
writable: boolean;
|
|
9
|
+
saving: boolean;
|
|
10
|
+
failed: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ComposerToggleFace {
|
|
14
|
+
hooks: { autoContinueComposer: SnapshotStore<ComposerToggleState> };
|
|
15
|
+
setEnabled: (enabled: boolean) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function AutoContinueComposerToggle(props: PropsLocale<'auto-continue'> & InjectFace<ComposerToggleFace>) {
|
|
19
|
+
const state = props.useAutoContinueComposer((snapshot) => snapshot);
|
|
20
|
+
if (!state.visible) return null;
|
|
21
|
+
const title = props.t(!state.writable ? 'chrome.readOnly' : state.saving ? 'composer.saving' : 'composer.scope');
|
|
22
|
+
return (
|
|
23
|
+
<div className="dshAcComposer" title={title}>
|
|
24
|
+
<span className="dshAcComposerLabel">{props.t('composer.label')}</span>
|
|
25
|
+
<span className="dshAcSwitchTarget">
|
|
26
|
+
<NativeSwitch checked={state.enabled} onChange={props.setEnabled}
|
|
27
|
+
disabled={!state.writable || state.saving} label={props.t('composer.label')} title={title} />
|
|
28
|
+
</span>
|
|
29
|
+
<span className="dshAcComposerError" role="status">
|
|
30
|
+
{state.failed ? props.t('composer.saveFailed') : null}
|
|
31
|
+
</span>
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Since 0.8.0 the auto-continue ENGINE runs inside the host process (single
|
|
5
5
|
* instance — see src/host/engine.ts), so this half only:
|
|
6
6
|
* - registers the `auto-continue` settings card in the available plugin UI,
|
|
7
|
+
* - adds a native composer switch backed by the same global pause setting,
|
|
7
8
|
* - subscribes to the host status bridge (SSE) and shows browser
|
|
8
9
|
* notifications with action buttons (Resume now / Pause 1h) via the bridge
|
|
9
10
|
* action endpoint,
|
|
@@ -24,6 +25,7 @@ import {
|
|
|
24
25
|
AutoContinueSettingsPage,
|
|
25
26
|
} from './settings-card.tsx';
|
|
26
27
|
import { startBridge } from './bridge.ts';
|
|
28
|
+
import { AutoContinueComposerToggle } from './composer-toggle.tsx';
|
|
27
29
|
import type { SettingsScope } from './dsh-store-compat.ts';
|
|
28
30
|
|
|
29
31
|
/** Dictionary namespace owned by this plugin. */
|
|
@@ -34,6 +36,11 @@ const SETTINGS_NS = 'auto-continue';
|
|
|
34
36
|
|
|
35
37
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
36
38
|
interface SlotMap {
|
|
39
|
+
/** Official compact composer tools; never occupy the resident single slot. */
|
|
40
|
+
'conversation.input.left': {
|
|
41
|
+
kind: 'list';
|
|
42
|
+
scope: 'session';
|
|
43
|
+
};
|
|
37
44
|
/** DSH 0.1.7's bundle configuration seat; only the owner props we consume. */
|
|
38
45
|
'plugins.bundle.config': {
|
|
39
46
|
kind: 'keyed';
|
|
@@ -137,6 +144,18 @@ function mountSettings(ctx: ClientContext, scope: SettingsScope<AutoContinueSett
|
|
|
137
144
|
const controller = new AutoContinueSettingsCardController(scope);
|
|
138
145
|
ctx.effect(() => () => controller.dispose(), 'auto-continue: settings form');
|
|
139
146
|
|
|
147
|
+
ctx.slots.inject('conversation.input.left', () =>
|
|
148
|
+
ctx.slots.register(
|
|
149
|
+
{
|
|
150
|
+
name: 'conversation.input.left',
|
|
151
|
+
id: 'auto-continue',
|
|
152
|
+
locale: NS,
|
|
153
|
+
inject: () => controller.injectComposer(),
|
|
154
|
+
},
|
|
155
|
+
AutoContinueComposerToggle,
|
|
156
|
+
),
|
|
157
|
+
);
|
|
158
|
+
|
|
140
159
|
// Slot injection waits for the matching UI declaration. Keep the old
|
|
141
160
|
// settings card and the new bundle page independent of service migration.
|
|
142
161
|
ctx.slots.inject('settings.plugin.item', () =>
|
package/src/client/locales.ts
CHANGED
|
@@ -27,6 +27,12 @@ export const zh = {
|
|
|
27
27
|
'section.live.title': '现场状态',
|
|
28
28
|
'section.live.description': '看看今天接住了多少次,以及哪些会话还在暂停。',
|
|
29
29
|
'field.paused': '暂停自动继续',
|
|
30
|
+
'field.showComposerToggle': '在会话区显示自动继续开关',
|
|
31
|
+
'field.showComposerToggleHint': '默认显示。隐藏开关不会暂停自动继续;点击保存后生效。',
|
|
32
|
+
'composer.label': '自动继续',
|
|
33
|
+
'composer.scope': '控制当前配置下所有会话的自动继续,修改立即保存。',
|
|
34
|
+
'composer.saving': '正在保存自动继续设置…',
|
|
35
|
+
'composer.saveFailed': '保存失败,请重试',
|
|
30
36
|
'field.pausedHint': '全局暂停: 实时与扫描都不会再自动发送, 已排队的待发送也会取消。',
|
|
31
37
|
'field.continueText': '继续文本',
|
|
32
38
|
'field.continueTextHint': '中断后自动发送的消息内容。',
|
|
@@ -148,6 +154,12 @@ export const en: Record<SettingsCardKey, string> = {
|
|
|
148
154
|
'section.live.title': 'Live signal',
|
|
149
155
|
'section.live.description': 'See what the relay caught today and which sessions are still paused.',
|
|
150
156
|
'field.paused': 'Pause auto-continue',
|
|
157
|
+
'field.showComposerToggle': 'Show auto-continue switch in the composer',
|
|
158
|
+
'field.showComposerToggleHint': 'Shown by default. Hiding the switch does not pause auto-continue. Click Save to apply.',
|
|
159
|
+
'composer.label': 'Auto-continue',
|
|
160
|
+
'composer.scope': 'Controls auto-continue for all sessions in this profile. Changes save immediately.',
|
|
161
|
+
'composer.saving': 'Saving auto-continue setting…',
|
|
162
|
+
'composer.saveFailed': 'Could not save. Try again.',
|
|
151
163
|
'field.pausedHint': 'Globally pause: no live or scan auto-send fires, and queued pending sends are cancelled.',
|
|
152
164
|
'field.continueText': 'Continue text',
|
|
153
165
|
'field.continueTextHint': 'Message automatically sent after an interruption.',
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
interface SwitchProps {
|
|
4
|
+
checked: boolean;
|
|
5
|
+
onChange: (checked: boolean) => void;
|
|
6
|
+
label: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
title?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// DSH 0.1.0-rc.7 predates this export. Keep its settings page usable while
|
|
12
|
+
// current hosts render their own Switch, including the active theme's styles.
|
|
13
|
+
function legacySwitch(props: SwitchProps) {
|
|
14
|
+
return (
|
|
15
|
+
<button type="button" role="switch" className="dshAcSwitch"
|
|
16
|
+
aria-checked={props.checked} aria-label={props.label} disabled={props.disabled}
|
|
17
|
+
title={props.title} onClick={() => props.onChange(!props.checked)}>
|
|
18
|
+
<span />
|
|
19
|
+
</button>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function resolveSwitch(): ComponentType<SwitchProps> {
|
|
24
|
+
try {
|
|
25
|
+
const { Switch } = require('@deepseek-ai/dsh-client-ui-primitives') as { Switch?: ComponentType<SwitchProps> };
|
|
26
|
+
if (typeof Switch === 'function') return Switch;
|
|
27
|
+
} catch {
|
|
28
|
+
// Legacy hosts can omit the primitives module from their client graph.
|
|
29
|
+
}
|
|
30
|
+
return legacySwitch;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const NativeSwitch = resolveSwitch();
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { useEffect, useState, type ReactNode } from 'react';
|
|
11
11
|
import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
12
|
-
import { type AutoContinueSettings } from './engine.ts';
|
|
12
|
+
import { DEFAULT_CONFIG, type AutoContinueSettings } from './engine.ts';
|
|
13
|
+
import type { ComposerToggleFace, ComposerToggleState } from './composer-toggle.tsx';
|
|
14
|
+
import { NativeSwitch } from './native-switch.tsx';
|
|
13
15
|
import { createSnapshotStore, type SettingsScope, type SnapshotStore } from './dsh-store-compat.ts';
|
|
14
16
|
import {
|
|
15
17
|
pausedSessions,
|
|
@@ -37,6 +39,7 @@ injectStyles();
|
|
|
37
39
|
/** What the auto-continue card renders. */
|
|
38
40
|
export interface AutoContinueSettingsCardState extends CardShell {
|
|
39
41
|
paused: CardFieldState;
|
|
42
|
+
showComposerToggle: CardFieldState;
|
|
40
43
|
continueText: CardFieldState;
|
|
41
44
|
continueTextMaxTokens: CardFieldState;
|
|
42
45
|
resumeSilentTurns: CardFieldState;
|
|
@@ -79,13 +82,18 @@ export interface AutoContinueSettingsCardFace extends CardActions {
|
|
|
79
82
|
export class AutoContinueSettingsCardController {
|
|
80
83
|
private readonly form: CardForm<AutoContinueSettings>;
|
|
81
84
|
private readonly store: SnapshotStore<AutoContinueSettingsCardState>;
|
|
85
|
+
private readonly composer: SnapshotStore<ComposerToggleState>;
|
|
86
|
+
private composerSaving = false;
|
|
87
|
+
private composerFailed = false;
|
|
88
|
+
private disposed = false;
|
|
82
89
|
|
|
83
90
|
/**
|
|
84
91
|
* @param scope - the bound settings scope for the `auto-continue` namespace.
|
|
85
92
|
*/
|
|
86
|
-
constructor(scope: SettingsScope<AutoContinueSettings>) {
|
|
93
|
+
constructor(private readonly scope: SettingsScope<AutoContinueSettings>) {
|
|
87
94
|
this.form = new CardForm(scope, [
|
|
88
95
|
booleanField('paused'),
|
|
96
|
+
booleanField('showComposerToggle'),
|
|
89
97
|
textField('continueText'),
|
|
90
98
|
textField('continueTextMaxTokens'),
|
|
91
99
|
booleanField('resumeSilentTurns'),
|
|
@@ -116,12 +124,14 @@ export class AutoContinueSettingsCardController {
|
|
|
116
124
|
textField('loopText'),
|
|
117
125
|
]);
|
|
118
126
|
this.store = this.form.bind(() => this.projection(), createSnapshotStore);
|
|
127
|
+
this.composer = this.form.bind(() => this.composerProjection(), createSnapshotStore);
|
|
119
128
|
}
|
|
120
129
|
|
|
121
130
|
private projection(): AutoContinueSettingsCardState {
|
|
122
131
|
return {
|
|
123
132
|
...this.form.shell(),
|
|
124
133
|
paused: this.form.field('paused'),
|
|
134
|
+
showComposerToggle: this.form.field('showComposerToggle'),
|
|
125
135
|
continueText: this.form.field('continueText'),
|
|
126
136
|
continueTextMaxTokens: this.form.field('continueTextMaxTokens'),
|
|
127
137
|
resumeSilentTurns: this.form.field('resumeSilentTurns'),
|
|
@@ -161,8 +171,40 @@ export class AutoContinueSettingsCardController {
|
|
|
161
171
|
return { hooks: { autoContinueSettingsCard: this.store }, ...this.form.actions() };
|
|
162
172
|
}
|
|
163
173
|
|
|
174
|
+
injectComposer(): ComposerToggleFace {
|
|
175
|
+
return { hooks: { autoContinueComposer: this.composer }, setEnabled: (enabled) => void this.setEnabled(enabled) };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private composerProjection(): ComposerToggleState {
|
|
179
|
+
const snapshot = this.scope.getSnapshot();
|
|
180
|
+
return {
|
|
181
|
+
visible: snapshot.status === 'ready' && (snapshot.value?.showComposerToggle ?? DEFAULT_CONFIG.showComposerToggle),
|
|
182
|
+
enabled: !(snapshot.value?.paused ?? DEFAULT_CONFIG.paused),
|
|
183
|
+
writable: snapshot.status === 'ready' && snapshot.writable && snapshot.mode === 'host',
|
|
184
|
+
saving: this.composerSaving,
|
|
185
|
+
failed: this.composerFailed,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private async setEnabled(enabled: boolean): Promise<void> {
|
|
190
|
+
if (this.disposed || this.composerSaving || !this.composerProjection().writable) return;
|
|
191
|
+
this.composerSaving = true;
|
|
192
|
+
this.composerFailed = false;
|
|
193
|
+
this.composer.set(this.composerProjection());
|
|
194
|
+
try {
|
|
195
|
+
const result = await this.scope.set('paused', !enabled);
|
|
196
|
+
this.composerFailed = result === false || this.composerProjection().enabled !== enabled;
|
|
197
|
+
} catch {
|
|
198
|
+
this.composerFailed = true;
|
|
199
|
+
} finally {
|
|
200
|
+
this.composerSaving = false;
|
|
201
|
+
if (!this.disposed) this.composer.set(this.composerProjection());
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
164
205
|
/** Release this card's subscription to the provider-owned settings form. */
|
|
165
206
|
dispose(): void {
|
|
207
|
+
this.disposed = true;
|
|
166
208
|
this.form.dispose();
|
|
167
209
|
}
|
|
168
210
|
}
|
|
@@ -418,6 +460,29 @@ function BooleanField(props: FieldProps) {
|
|
|
418
460
|
);
|
|
419
461
|
}
|
|
420
462
|
|
|
463
|
+
/** Visibility is staged with the rest of the form, including Reset/Discard. */
|
|
464
|
+
function ComposerVisibilityField(props: FieldProps) {
|
|
465
|
+
return (
|
|
466
|
+
<div className="dshAcField dshAcFieldWide">
|
|
467
|
+
<div className="dshAcHead">
|
|
468
|
+
<span className="dshAcLabel">{props.label}</span>
|
|
469
|
+
<span className="dshAcBadges">
|
|
470
|
+
{props.overridden ? <>
|
|
471
|
+
<span className="dshAcBadge">{props.t('chrome.overridden')}</span>
|
|
472
|
+
<button type="button" className="dshAcReset" disabled={props.disabled}
|
|
473
|
+
onClick={props.onReset}>{props.t('chrome.reset')}</button>
|
|
474
|
+
</> : null}
|
|
475
|
+
<span className="dshAcSwitchTarget">
|
|
476
|
+
<NativeSwitch checked={props.text === '' ? DEFAULT_CONFIG.showComposerToggle : props.text === 'true'}
|
|
477
|
+
onChange={(checked) => props.onEdit(String(checked))} label={props.label} disabled={props.disabled} />
|
|
478
|
+
</span>
|
|
479
|
+
</span>
|
|
480
|
+
</div>
|
|
481
|
+
<p className="dshAcHint">{props.hint}</p>
|
|
482
|
+
</div>
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
|
|
421
486
|
type SettingsSectionTone = 'handoff' | 'autoloop' | 'safety' | 'recovery' | 'loop' | 'live';
|
|
422
487
|
|
|
423
488
|
/** A real behavior group, not a decorative divider: each section maps to one phase of the relay. */
|
|
@@ -585,6 +650,15 @@ export function AutoContinueSettingsCard(props: AutoContinueSettingsCardProps) {
|
|
|
585
650
|
onEdit={(text) => props.edit('paused', text)}
|
|
586
651
|
onReset={() => props.resetField('paused')}
|
|
587
652
|
/>
|
|
653
|
+
<ComposerVisibilityField
|
|
654
|
+
id="auto-continue-show-composer-toggle"
|
|
655
|
+
label={t('field.showComposerToggle')}
|
|
656
|
+
hint={t('field.showComposerToggleHint')}
|
|
657
|
+
{...shared}
|
|
658
|
+
{...state.showComposerToggle}
|
|
659
|
+
onEdit={(text) => props.edit('showComposerToggle', text)}
|
|
660
|
+
onReset={() => props.resetField('showComposerToggle')}
|
|
661
|
+
/>
|
|
588
662
|
<ValueField
|
|
589
663
|
id="auto-continue-continue-text"
|
|
590
664
|
label={t('field.continueText')}
|
|
@@ -214,9 +214,9 @@ export class CardForm<T> {
|
|
|
214
214
|
const plan = this.plan();
|
|
215
215
|
const writes = plan.flatMap((item) => (item.run === undefined ? [] : [item.run]));
|
|
216
216
|
if (plan.length === 0 || this.saving || writes.length !== plan.length) return;
|
|
217
|
-
//
|
|
218
|
-
//
|
|
219
|
-
const
|
|
217
|
+
// Keep the staged edits this save writes. A field can be staged again
|
|
218
|
+
// while a write is pending, so clear it only if that exact edit remains.
|
|
219
|
+
const edits = plan.map(({ field, staged }) => ({ field, staged }));
|
|
220
220
|
this.saving = true;
|
|
221
221
|
this.failed = false;
|
|
222
222
|
this.publish();
|
|
@@ -225,7 +225,9 @@ export class CardForm<T> {
|
|
|
225
225
|
landed = (await write()) && landed;
|
|
226
226
|
}
|
|
227
227
|
if (landed) {
|
|
228
|
-
for (const field of
|
|
228
|
+
for (const { field, staged } of edits) {
|
|
229
|
+
if (this.staged.get(field) === staged) this.staged.delete(field);
|
|
230
|
+
}
|
|
229
231
|
}
|
|
230
232
|
this.saving = false;
|
|
231
233
|
this.failed = !landed;
|
|
@@ -238,19 +240,19 @@ export class CardForm<T> {
|
|
|
238
240
|
* refuses rather than dropping the edit. A staged edit that matches the
|
|
239
241
|
* effective section is not a write at all.
|
|
240
242
|
*/
|
|
241
|
-
private plan(): { field: string; run: (() => Promise<boolean>) | undefined }[] {
|
|
242
|
-
const plan: { field: string; run: (() => Promise<boolean>) | undefined }[] = [];
|
|
243
|
+
private plan(): { field: string; staged: StagedEdit; run: (() => Promise<boolean>) | undefined }[] {
|
|
244
|
+
const plan: { field: string; staged: StagedEdit; run: (() => Promise<boolean>) | undefined }[] = [];
|
|
243
245
|
for (const [field, staged] of this.staged) {
|
|
244
246
|
const spec = this.specOf(field);
|
|
245
247
|
if (staged.clear) {
|
|
246
|
-
if (this.stored(field)) plan.push({ field, run: () => this.clear(field) });
|
|
248
|
+
if (this.stored(field)) plan.push({ field, staged, run: () => this.clear(field) });
|
|
247
249
|
continue;
|
|
248
250
|
}
|
|
249
251
|
if (staged.text === spec.format(this.sectionValue(field))) continue;
|
|
250
252
|
const write = spec.parse(staged.text);
|
|
251
|
-
if (write === undefined) plan.push({ field, run: undefined });
|
|
252
|
-
else if (write.kind === 'clear') plan.push({ field, run: () => this.clear(field) });
|
|
253
|
-
else plan.push({ field, run: () => this.store(field, write.value) });
|
|
253
|
+
if (write === undefined) plan.push({ field, staged, run: undefined });
|
|
254
|
+
else if (write.kind === 'clear') plan.push({ field, staged, run: () => this.clear(field) });
|
|
255
|
+
else plan.push({ field, staged, run: () => this.store(field, write.value) });
|
|
254
256
|
}
|
|
255
257
|
return plan;
|
|
256
258
|
}
|