dsh-client-auto-continue 0.15.0 → 0.16.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/CHANGELOG.md +35 -0
- package/README.md +30 -17
- package/README.zh.md +30 -17
- package/docs/releases/v0.16.0.md +75 -0
- package/docs/third-party-notices.md +19 -0
- package/lib/client.js +123 -45
- package/lib/client.js.map +2 -2
- package/lib/index.js +7560 -117
- package/lib/types/client/bridge.d.ts +3 -1
- package/lib/types/client/composer-toggle.d.ts +6 -4
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/client/locales.d.ts +6 -0
- package/lib/types/client/settings-card.d.ts +5 -4
- package/lib/types/host/engine.d.ts +2 -0
- package/lib/types/host/settings-migration.d.ts +14 -0
- package/lib/types/index.d.ts +14 -8
- package/lib/types/shared/core.d.ts +13 -1
- package/package.json +21 -13
- package/src/client/bridge.ts +35 -4
- package/src/client/composer-toggle.tsx +20 -12
- package/src/client/index.ts +4 -2
- package/src/client/locales.ts +24 -12
- package/src/client/settings-card.tsx +26 -17
- package/src/client/styles.ts +4 -1
- package/src/host/engine.ts +54 -12
- package/src/host/settings-migration.ts +117 -0
- package/src/index.ts +63 -12
- package/src/shared/core.ts +23 -1
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* to `/api/auto-continue-action`) and runtime state (today's stats and the
|
|
7
7
|
* paused-sessions list) consumed by the settings card's live panels.
|
|
8
8
|
*/
|
|
9
|
-
import type { RecoveryAttempt } from '../shared/core.ts';
|
|
9
|
+
import type { RecoveryAttempt, SessionMode, SessionPolicy } from '../shared/core.ts';
|
|
10
10
|
/** 今日统计视图(与 host 引擎的 DayStats 对应)。 */
|
|
11
11
|
export interface DayStatsView {
|
|
12
12
|
date: string;
|
|
@@ -28,6 +28,8 @@ export declare function pausedSessions(): PausedSessionView[];
|
|
|
28
28
|
/** 当前桥状态里的今日统计(卡片面板用)。 */
|
|
29
29
|
export declare function readTodayStats(): DayStatsView;
|
|
30
30
|
export declare function readRecoveryAttempts(): RecoveryAttempt[];
|
|
31
|
+
export declare function readSessionPolicy(): SessionPolicy | undefined;
|
|
32
|
+
export declare function setSessionMode(sessionId: string, mode: SessionMode): Promise<void>;
|
|
31
33
|
/** 清零今日统计(经动作端点交给 host 引擎执行)。 */
|
|
32
34
|
export declare function resetTodayStats(): void;
|
|
33
35
|
/** 解除某个会话的暂停(经动作端点交给 host 引擎执行)。 */
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
2
|
import type { SnapshotStore } from './dsh-store-compat.ts';
|
|
3
|
+
import { type SessionMode, type SessionPolicy } from '../shared/core.ts';
|
|
3
4
|
export interface ComposerToggleState {
|
|
4
5
|
visible: boolean;
|
|
5
|
-
|
|
6
|
+
policy: SessionPolicy | undefined;
|
|
6
7
|
writable: boolean;
|
|
7
|
-
saving:
|
|
8
|
-
failed:
|
|
8
|
+
saving: ReadonlySet<string>;
|
|
9
|
+
failed: ReadonlySet<string>;
|
|
9
10
|
}
|
|
10
11
|
export interface ComposerToggleFace {
|
|
11
12
|
hooks: {
|
|
12
13
|
autoContinueComposer: SnapshotStore<ComposerToggleState>;
|
|
13
14
|
};
|
|
14
|
-
|
|
15
|
+
sessionId: string;
|
|
16
|
+
setMode: (mode: SessionMode) => void;
|
|
15
17
|
}
|
|
16
18
|
export declare function AutoContinueComposerToggle(props: PropsLocale<'auto-continue'> & InjectFace<ComposerToggleFace>): import("react").JSX.Element | null;
|
|
@@ -4,7 +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
|
|
7
|
+
* - adds a per-session composer mode selector backed by host settings,
|
|
8
8
|
* - subscribes to the host status bridge (SSE) and shows browser
|
|
9
9
|
* notifications with action buttons (Resume now / Pause 1h) via the bridge
|
|
10
10
|
* action endpoint,
|
|
@@ -34,6 +34,12 @@ export declare const zh: {
|
|
|
34
34
|
'field.showComposerToggleHint': string;
|
|
35
35
|
'composer.label': string;
|
|
36
36
|
'composer.scope': string;
|
|
37
|
+
'composer.default': string;
|
|
38
|
+
'composer.off': string;
|
|
39
|
+
'composer.recover': string;
|
|
40
|
+
'composer.loop': string;
|
|
41
|
+
'composer.paused': string;
|
|
42
|
+
'composer.unavailable': string;
|
|
37
43
|
'composer.saving': string;
|
|
38
44
|
'composer.saveFailed': string;
|
|
39
45
|
'field.pausedHint': string;
|
|
@@ -56,8 +56,9 @@ export declare class AutoContinueSettingsCardController {
|
|
|
56
56
|
private readonly form;
|
|
57
57
|
private readonly store;
|
|
58
58
|
private readonly composer;
|
|
59
|
-
private composerSaving;
|
|
60
|
-
private composerFailed;
|
|
59
|
+
private readonly composerSaving;
|
|
60
|
+
private readonly composerFailed;
|
|
61
|
+
private readonly stopComposer;
|
|
61
62
|
private disposed;
|
|
62
63
|
private saveSequence;
|
|
63
64
|
private notificationFeedback;
|
|
@@ -72,9 +73,9 @@ export declare class AutoContinueSettingsCardController {
|
|
|
72
73
|
*/
|
|
73
74
|
inject(): AutoContinueSettingsCardFace;
|
|
74
75
|
private save;
|
|
75
|
-
injectComposer(): ComposerToggleFace;
|
|
76
|
+
injectComposer(sessionId: string): ComposerToggleFace;
|
|
76
77
|
private composerProjection;
|
|
77
|
-
private
|
|
78
|
+
private setMode;
|
|
78
79
|
/** Release this card's subscription to the provider-owned settings form. */
|
|
79
80
|
dispose(): void;
|
|
80
81
|
}
|
|
@@ -73,6 +73,8 @@ export declare class AutoContinueRunner {
|
|
|
73
73
|
/** 对外(状态桥): 订阅运行时状态变化(统计/暂停列表)。 */
|
|
74
74
|
subscribeState(listener: () => void): () => void;
|
|
75
75
|
private emitState;
|
|
76
|
+
private sessionConfig;
|
|
77
|
+
configurationChanged(): void;
|
|
76
78
|
/** 对外(状态桥): 消费待展示的通知。 */
|
|
77
79
|
drainNotices(): HostNotice[];
|
|
78
80
|
/** 通知动作(browser 通知按钮回传): 立即续跑 / 暂停该会话 / 解除暂停 / 清零统计。 */
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { AutoContinueSettings } from '../shared/core.ts';
|
|
3
|
+
/** Recover an import interrupted between the profile save and completion file. */
|
|
4
|
+
export declare const LEGACY_SETTINGS_IMPORTED = "_legacySettingsImported";
|
|
5
|
+
export type EntrySettings = AutoContinueSettings & {
|
|
6
|
+
_legacySettingsImported?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type LiveEntrySettings = {
|
|
9
|
+
get(): EntrySettings | undefined;
|
|
10
|
+
};
|
|
11
|
+
/** Import the mixed desktop host's legacy document through the profile editor.
|
|
12
|
+
* The original file stays untouched, including other plugins' settings.
|
|
13
|
+
*/
|
|
14
|
+
export declare function migrateLegacySettings(ctx: Context, config: LiveEntrySettings, fields: readonly string[], validate: (value: AutoContinueSettings) => unknown): () => EntrySettings | undefined;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import type { Context } from '@deepseek-ai/cordis';
|
|
14
14
|
import z from '@deepseek-ai/schemastery';
|
|
15
|
+
import { type EntrySettings, type LiveEntrySettings } from './host/settings-migration.ts';
|
|
15
16
|
import { type AutoContinueSettings } from './shared/core.ts';
|
|
16
17
|
/** Settings namespace of the auto-continue plugin (lowercase kebab-case). */
|
|
17
18
|
export declare const AUTO_CONTINUE_NS = "auto-continue";
|
|
18
|
-
/** Wire schema; blank localized text fields tell resolveConfig() to select the active locale's defaults. */
|
|
19
19
|
export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
|
|
20
20
|
/** Active browser/UI locale mirrored by the client. */
|
|
21
21
|
locale: z<string, string>;
|
|
@@ -65,7 +65,9 @@ export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
|
|
|
65
65
|
notify: z<boolean, boolean>;
|
|
66
66
|
/** Globally pause auto-continue: no live or scan send. */
|
|
67
67
|
paused: z<boolean, boolean>;
|
|
68
|
-
/**
|
|
68
|
+
/** Persist choices by session, including an explicit return to the profile default. */
|
|
69
|
+
sessionModes: z<import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>, import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>>;
|
|
70
|
+
/** Show the session mode selector in the conversation composer. */
|
|
69
71
|
showComposerToggle: z<boolean, boolean>;
|
|
70
72
|
/** Loop guard: detect a running turn spinning in place and restart it. */
|
|
71
73
|
loopGuard: z<boolean, boolean>;
|
|
@@ -130,7 +132,9 @@ export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
|
|
|
130
132
|
notify: z<boolean, boolean>;
|
|
131
133
|
/** Globally pause auto-continue: no live or scan send. */
|
|
132
134
|
paused: z<boolean, boolean>;
|
|
133
|
-
/**
|
|
135
|
+
/** Persist choices by session, including an explicit return to the profile default. */
|
|
136
|
+
sessionModes: z<import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>, import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>>;
|
|
137
|
+
/** Show the session mode selector in the conversation composer. */
|
|
134
138
|
showComposerToggle: z<boolean, boolean>;
|
|
135
139
|
/** Loop guard: detect a running turn spinning in place and restart it. */
|
|
136
140
|
loopGuard: z<boolean, boolean>;
|
|
@@ -148,9 +152,7 @@ export declare const AutoContinueSchema: z<Schemastery.ObjectS<{
|
|
|
148
152
|
loopText: z<string, string>;
|
|
149
153
|
}>>;
|
|
150
154
|
/** Loader config is a live reference on DSH 0.1.7, and a plain object on older hosts. */
|
|
151
|
-
export type AutoContinueEntryConfig =
|
|
152
|
-
get(): AutoContinueSettings | undefined;
|
|
153
|
-
};
|
|
155
|
+
export type AutoContinueEntryConfig = EntrySettings | LiveEntrySettings;
|
|
154
156
|
export declare const Config: z<Schemastery.ObjectS<{
|
|
155
157
|
/** Active browser/UI locale mirrored by the client. */
|
|
156
158
|
locale: z<string, string>;
|
|
@@ -200,7 +202,9 @@ export declare const Config: z<Schemastery.ObjectS<{
|
|
|
200
202
|
notify: z<boolean, boolean>;
|
|
201
203
|
/** Globally pause auto-continue: no live or scan send. */
|
|
202
204
|
paused: z<boolean, boolean>;
|
|
203
|
-
/**
|
|
205
|
+
/** Persist choices by session, including an explicit return to the profile default. */
|
|
206
|
+
sessionModes: z<import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>, import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>>;
|
|
207
|
+
/** Show the session mode selector in the conversation composer. */
|
|
204
208
|
showComposerToggle: z<boolean, boolean>;
|
|
205
209
|
/** Loop guard: detect a running turn spinning in place and restart it. */
|
|
206
210
|
loopGuard: z<boolean, boolean>;
|
|
@@ -265,7 +269,9 @@ export declare const Config: z<Schemastery.ObjectS<{
|
|
|
265
269
|
notify: z<boolean, boolean>;
|
|
266
270
|
/** Globally pause auto-continue: no live or scan send. */
|
|
267
271
|
paused: z<boolean, boolean>;
|
|
268
|
-
/**
|
|
272
|
+
/** Persist choices by session, including an explicit return to the profile default. */
|
|
273
|
+
sessionModes: z<import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>, import("@deepseek-ai/cosmokit").Dict<"default" | "off" | "recover" | "loop", string>>;
|
|
274
|
+
/** Show the session mode selector in the conversation composer. */
|
|
269
275
|
showComposerToggle: z<boolean, boolean>;
|
|
270
276
|
/** Loop guard: detect a running turn spinning in place and restart it. */
|
|
271
277
|
loopGuard: z<boolean, boolean>;
|
|
@@ -7,6 +7,15 @@
|
|
|
7
7
|
import type { SessionEvent } from '@deepseek-ai/dsh-session/types';
|
|
8
8
|
/** Supported UI/config locales. Any unknown browser locale falls back to Chinese. */
|
|
9
9
|
export type AutoContinueLocale = 'en' | 'zh';
|
|
10
|
+
export type SessionMode = 'default' | 'off' | 'recover' | 'loop';
|
|
11
|
+
export interface SessionPolicy {
|
|
12
|
+
modes: Record<string, SessionMode>;
|
|
13
|
+
defaultMode: 'recover' | 'loop';
|
|
14
|
+
paused: boolean;
|
|
15
|
+
writable: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const isSessionMode: (value: unknown) => value is SessionMode;
|
|
18
|
+
export declare function sessionMode(modes: Record<string, SessionMode>, sessionId: string): SessionMode;
|
|
10
19
|
/** Locale-owned defaults for the user-editable text fields. */
|
|
11
20
|
export declare const LOCALIZED_TEXT_DEFAULTS: {
|
|
12
21
|
readonly zh: {
|
|
@@ -80,7 +89,9 @@ export interface AutoContinueSettings {
|
|
|
80
89
|
notify?: boolean;
|
|
81
90
|
/** Globally pause auto-continue: no live or scan send, queued pending sends cancelled. */
|
|
82
91
|
paused?: boolean;
|
|
83
|
-
/**
|
|
92
|
+
/** Persistent per-session overrides; default explicitly inherits the profile default. */
|
|
93
|
+
sessionModes?: Record<string, SessionMode>;
|
|
94
|
+
/** Show the session mode selector in the conversation composer. */
|
|
84
95
|
showComposerToggle?: boolean;
|
|
85
96
|
/** Loop guard: detect a running turn spinning in place (short talk without tools, or the same tool repeating) and restart it. */
|
|
86
97
|
loopGuard?: boolean;
|
|
@@ -298,6 +309,7 @@ export interface SessionState {
|
|
|
298
309
|
pendingEchoMessageIds: Map<string, number>;
|
|
299
310
|
/** 宽限期定时器(进行中的待发送)。 */
|
|
300
311
|
pendingTimer: ReturnType<typeof setTimeout> | undefined;
|
|
312
|
+
pendingReason?: string;
|
|
301
313
|
/** 宿主权威 running 位(来自 host/session-status 与回合事件)。 */
|
|
302
314
|
running: boolean | undefined;
|
|
303
315
|
/** 当前排队消息数(来自 session/queue 帧)。 */
|
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.16.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/types/index.d.ts",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"tsconfig.build.json",
|
|
27
27
|
"README.md",
|
|
28
28
|
"README.zh.md",
|
|
29
|
+
"CHANGELOG.md",
|
|
29
30
|
"LICENSE"
|
|
30
31
|
],
|
|
31
32
|
"dsh": {
|
|
@@ -46,8 +47,8 @@
|
|
|
46
47
|
"build": "node build.mjs && tsc -p tsconfig.build.json",
|
|
47
48
|
"watch": "node build.mjs --watch",
|
|
48
49
|
"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/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 && node tests/boot-scan-host-live.mjs 0.2.0-rc.2 && node tests/boot-scan-host-live.mjs 0.2.1 && node tests/settings-host-live.mjs 0.2.1-rc.2 && node tests/profile-compatibility.mjs 0.2.1-rc.2 && node tests/boot-scan-restart-live.mjs",
|
|
50
|
-
"test": "node tests/boot-scan-stored-sweep.mjs && node tests/loop-guard-progress.mjs && node tests/scan-on-boot.mjs && node tests/boot-scan-isolation.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/settings-notifications.mjs && node tests/prepare-github-package.mjs",
|
|
50
|
+
"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 && node tests/boot-scan-host-live.mjs 0.2.0-rc.2 && node tests/boot-scan-host-live.mjs 0.2.1 && node tests/settings-host-live.mjs 0.2.1-rc.2 && node tests/profile-compatibility.mjs 0.2.1-rc.2 && node tests/boot-scan-restart-live.mjs && node tests/settings-host-live.mjs 0.2.1-rc.2 mixed && node tests/settings-migration.mjs",
|
|
51
|
+
"test": "node tests/boot-scan-stored-sweep.mjs && node tests/loop-guard-progress.mjs && node tests/scan-on-boot.mjs && node tests/boot-scan-isolation.mjs && node tests/silent-turn-boundaries.mjs && node tests/autonomous-loop.mjs && node tests/session-modes.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/settings-notifications.mjs && node tests/prepare-github-package.mjs",
|
|
51
52
|
"prepack": "npm run build"
|
|
52
53
|
},
|
|
53
54
|
"keywords": [
|
|
@@ -67,16 +68,23 @@
|
|
|
67
68
|
"esbuild": "^0.25.0",
|
|
68
69
|
"typescript": "~5.8.0",
|
|
69
70
|
"@types/react": "~18.3.1",
|
|
70
|
-
"@deepseek-ai/cordis": "
|
|
71
|
-
"@deepseek-ai/dsh-client-connection": "
|
|
72
|
-
"@deepseek-ai/dsh-client-locale": "
|
|
73
|
-
"@deepseek-ai/dsh-client-ui-settings": "
|
|
74
|
-
"@deepseek-ai/dsh-client-ui-settings-plugins": "
|
|
75
|
-
"@deepseek-ai/dsh-client-ui-slots": "
|
|
76
|
-
"@deepseek-ai/dsh-session": "
|
|
77
|
-
"@deepseek-ai/dsh-settings": "
|
|
78
|
-
"@deepseek-ai/schemastery": "
|
|
79
|
-
"@types/node": "^22.0.0"
|
|
71
|
+
"@deepseek-ai/cordis": "4.0.2",
|
|
72
|
+
"@deepseek-ai/dsh-client-connection": "0.1.2-rc.1",
|
|
73
|
+
"@deepseek-ai/dsh-client-locale": "0.1.2-rc.1",
|
|
74
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.1.2-rc.1",
|
|
75
|
+
"@deepseek-ai/dsh-client-ui-settings-plugins": "0.1.2-rc.1",
|
|
76
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.1.2-rc.1",
|
|
77
|
+
"@deepseek-ai/dsh-session": "0.1.2-rc.1",
|
|
78
|
+
"@deepseek-ai/dsh-settings": "0.1.2-rc.1",
|
|
79
|
+
"@deepseek-ai/schemastery": "3.18.2",
|
|
80
|
+
"@types/node": "^22.0.0",
|
|
81
|
+
"yaml": "2.9.1",
|
|
82
|
+
"@deepseek-ai/dsh-agent": "0.1.2-rc.1",
|
|
83
|
+
"@deepseek-ai/dsh-client-store": "0.1.2-rc.1",
|
|
84
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.1.2-rc.1",
|
|
85
|
+
"@deepseek-ai/dsh-host-webserver": "0.1.2-rc.1",
|
|
86
|
+
"@deepseek-ai/dsh-llm": "0.1.2-rc.1",
|
|
87
|
+
"react-dom": "^18.2.0"
|
|
80
88
|
},
|
|
81
89
|
"license": "MIT",
|
|
82
90
|
"peerDependencies": {
|
package/src/client/bridge.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* paused-sessions list) consumed by the settings card's live panels.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { RecoveryAttempt } from '../shared/core.ts';
|
|
10
|
+
import type { RecoveryAttempt, SessionMode, SessionPolicy } from '../shared/core.ts';
|
|
11
11
|
|
|
12
12
|
/** 今日统计视图(与 host 引擎的 DayStats 对应)。 */
|
|
13
13
|
export interface DayStatsView {
|
|
@@ -31,6 +31,7 @@ interface BridgeState {
|
|
|
31
31
|
stats: DayStatsView;
|
|
32
32
|
paused: PausedSessionView[];
|
|
33
33
|
recoveryAttempts: RecoveryAttempt[];
|
|
34
|
+
sessionPolicy?: SessionPolicy;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
interface BridgeNotice {
|
|
@@ -70,6 +71,23 @@ export function readRecoveryAttempts(): RecoveryAttempt[] {
|
|
|
70
71
|
return state.recoveryAttempts;
|
|
71
72
|
}
|
|
72
73
|
|
|
74
|
+
export function readSessionPolicy(): SessionPolicy | undefined {
|
|
75
|
+
return state.sessionPolicy;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function setSessionMode(sessionId: string, mode: SessionMode): Promise<void> {
|
|
79
|
+
if (!state.sessionPolicy?.writable) throw new Error('Session settings are unavailable');
|
|
80
|
+
const response = await fetch('/api/auto-continue-action', {
|
|
81
|
+
method: 'POST',
|
|
82
|
+
headers: { 'content-type': 'application/json' },
|
|
83
|
+
body: JSON.stringify({ action: 'set-session-mode', sessionId, mode }),
|
|
84
|
+
});
|
|
85
|
+
const result = await response.json();
|
|
86
|
+
if (!response.ok || result?.ok !== true || result.sessionId !== sessionId || result.mode !== mode) {
|
|
87
|
+
throw new Error('Session mode was not saved');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
73
91
|
/** 清零今日统计(经动作端点交给 host 引擎执行)。 */
|
|
74
92
|
export function resetTodayStats(): void {
|
|
75
93
|
void postAction({ action: 'reset-stats' });
|
|
@@ -101,12 +119,16 @@ async function postAction(payload: { action: string; sessionId?: string }): Prom
|
|
|
101
119
|
}
|
|
102
120
|
}
|
|
103
121
|
|
|
104
|
-
function handleEvent(event: { type: string; notice?: BridgeNotice; stats?: DayStatsView; paused?: PausedSessionView[]; recoveryAttempts?: RecoveryAttempt[] }): void {
|
|
122
|
+
function handleEvent(event: { type: string; notice?: BridgeNotice; stats?: DayStatsView; paused?: PausedSessionView[]; recoveryAttempts?: RecoveryAttempt[]; sessionPolicy?: SessionPolicy }): void {
|
|
105
123
|
if (event.type === 'state') {
|
|
124
|
+
const policy = event.sessionPolicy;
|
|
106
125
|
state = {
|
|
107
126
|
stats: event.stats ?? EMPTY_STATS,
|
|
108
127
|
paused: event.paused ?? [],
|
|
109
128
|
recoveryAttempts: event.recoveryAttempts ?? [],
|
|
129
|
+
sessionPolicy: policy && typeof policy.modes === 'object' && policy.modes !== null && !Array.isArray(policy.modes) &&
|
|
130
|
+
(policy.defaultMode === 'recover' || policy.defaultMode === 'loop') && typeof policy.paused === 'boolean' && typeof policy.writable === 'boolean'
|
|
131
|
+
? policy : undefined,
|
|
110
132
|
};
|
|
111
133
|
for (const listener of listeners) listener();
|
|
112
134
|
} else if (event.type === 'notice' && event.notice !== undefined) {
|
|
@@ -165,6 +187,11 @@ function showNotification(notice: BridgeNotice): void {
|
|
|
165
187
|
export function startBridge(): () => void {
|
|
166
188
|
let stopped = false;
|
|
167
189
|
let controller: AbortController | undefined;
|
|
190
|
+
const disconnected = () => {
|
|
191
|
+
state = { ...state, sessionPolicy: undefined };
|
|
192
|
+
for (const listener of listeners) listener();
|
|
193
|
+
};
|
|
194
|
+
disconnected();
|
|
168
195
|
|
|
169
196
|
const loop = async (): Promise<void> => {
|
|
170
197
|
while (!stopped) {
|
|
@@ -177,7 +204,7 @@ export function startBridge(): () => void {
|
|
|
177
204
|
let buffer = '';
|
|
178
205
|
for (;;) {
|
|
179
206
|
const { done, value } = await reader.read();
|
|
180
|
-
if (done) break;
|
|
207
|
+
if (done || stopped) break;
|
|
181
208
|
buffer += decoder.decode(value, { stream: true });
|
|
182
209
|
let idx = buffer.indexOf('\n\n');
|
|
183
210
|
while (idx !== -1) {
|
|
@@ -198,7 +225,10 @@ export function startBridge(): () => void {
|
|
|
198
225
|
} catch {
|
|
199
226
|
/* 断线: 退避重连 */
|
|
200
227
|
}
|
|
201
|
-
if (!stopped)
|
|
228
|
+
if (!stopped) {
|
|
229
|
+
disconnected();
|
|
230
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
231
|
+
}
|
|
202
232
|
}
|
|
203
233
|
};
|
|
204
234
|
void loop();
|
|
@@ -206,5 +236,6 @@ export function startBridge(): () => void {
|
|
|
206
236
|
return () => {
|
|
207
237
|
stopped = true;
|
|
208
238
|
controller?.abort();
|
|
239
|
+
disconnected();
|
|
209
240
|
};
|
|
210
241
|
}
|
|
@@ -1,33 +1,41 @@
|
|
|
1
1
|
import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
2
|
import type { SnapshotStore } from './dsh-store-compat.ts';
|
|
3
|
-
import {
|
|
3
|
+
import { isSessionMode, sessionMode, type SessionMode, type SessionPolicy } from '../shared/core.ts';
|
|
4
4
|
|
|
5
5
|
export interface ComposerToggleState {
|
|
6
6
|
visible: boolean;
|
|
7
|
-
|
|
7
|
+
policy: SessionPolicy | undefined;
|
|
8
8
|
writable: boolean;
|
|
9
|
-
saving:
|
|
10
|
-
failed:
|
|
9
|
+
saving: ReadonlySet<string>;
|
|
10
|
+
failed: ReadonlySet<string>;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface ComposerToggleFace {
|
|
14
14
|
hooks: { autoContinueComposer: SnapshotStore<ComposerToggleState> };
|
|
15
|
-
|
|
15
|
+
sessionId: string;
|
|
16
|
+
setMode: (mode: SessionMode) => void;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export function AutoContinueComposerToggle(props: PropsLocale<'auto-continue'> & InjectFace<ComposerToggleFace>) {
|
|
19
20
|
const state = props.useAutoContinueComposer((snapshot) => snapshot);
|
|
20
|
-
if (!state.visible) return null;
|
|
21
|
-
const
|
|
21
|
+
if (!state.visible || !props.sessionId) return null;
|
|
22
|
+
const saving = state.saving.has(props.sessionId);
|
|
23
|
+
const policy = state.policy;
|
|
24
|
+
const title = props.t(!policy ? 'composer.unavailable' : !state.writable ? 'chrome.readOnly' : saving ? 'composer.saving' : 'composer.scope');
|
|
22
25
|
return (
|
|
23
26
|
<div className="dshAcComposer" title={title}>
|
|
24
27
|
<span className="dshAcComposerLabel">{props.t('composer.label')}</span>
|
|
25
|
-
<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
<select className="dshAcMode" aria-label={props.t('composer.label')} title={title}
|
|
29
|
+
disabled={!state.writable || saving} value={sessionMode(policy?.modes ?? {}, props.sessionId)}
|
|
30
|
+
onChange={event => { if (isSessionMode(event.target.value)) props.setMode(event.target.value); }}>
|
|
31
|
+
<option value="default">{props.t('composer.default')}{policy ? ` (${props.t(`composer.${policy.defaultMode}`)})` : ''}</option>
|
|
32
|
+
<option value="off">{props.t('composer.off')}</option>
|
|
33
|
+
<option value="recover">{props.t('composer.recover')}</option>
|
|
34
|
+
<option value="loop">{props.t('composer.loop')}</option>
|
|
35
|
+
</select>
|
|
36
|
+
{policy?.paused && <span className="dshAcComposerLabel">{props.t('composer.paused')}</span>}
|
|
29
37
|
<span className="dshAcComposerError" role="status">
|
|
30
|
-
{state.failed ? props.t('composer.saveFailed') : null}
|
|
38
|
+
{state.failed.has(props.sessionId) ? props.t('composer.saveFailed') : saving ? props.t('composer.saving') : !policy ? props.t('composer.unavailable') : null}
|
|
31
39
|
</span>
|
|
32
40
|
</div>
|
|
33
41
|
);
|
package/src/client/index.ts
CHANGED
|
@@ -4,13 +4,15 @@
|
|
|
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
|
|
7
|
+
* - adds a per-session composer mode selector backed by host settings,
|
|
8
8
|
* - subscribes to the host status bridge (SSE) and shows browser
|
|
9
9
|
* notifications with action buttons (Resume now / Pause 1h) via the bridge
|
|
10
10
|
* action endpoint,
|
|
11
11
|
* - feeds the card's stats / paused-sessions panels from the bridge state.
|
|
12
12
|
*/
|
|
13
13
|
import type { Context as ClientContext } from '@deepseek-ai/cordis';
|
|
14
|
+
// Type-only: the slot service is declared by the renderer in newer DSH SDKs.
|
|
15
|
+
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client';
|
|
14
16
|
// Type-only: pulls the locale plugin's Context merge (ctx.locale).
|
|
15
17
|
import type {} from '@deepseek-ai/dsh-client-locale/client';
|
|
16
18
|
// Type-only: pulls the settings-surface SlotMap merge and ctx.settingsScope.
|
|
@@ -152,7 +154,7 @@ function mountSettings(ctx: ClientContext, scope: SettingsScope<AutoContinueSett
|
|
|
152
154
|
name: 'conversation.input.left',
|
|
153
155
|
id: 'auto-continue',
|
|
154
156
|
locale: NS,
|
|
155
|
-
inject: () => controller.injectComposer(),
|
|
157
|
+
inject: (sessionId) => controller.injectComposer(sessionId),
|
|
156
158
|
},
|
|
157
159
|
AutoContinueComposerToggle,
|
|
158
160
|
),
|
package/src/client/locales.ts
CHANGED
|
@@ -36,11 +36,17 @@ export const zh = {
|
|
|
36
36
|
'category.safety.description': '避免重复执行工具,识别并打断无效循环。',
|
|
37
37
|
'category.status.title': '状态与日志',
|
|
38
38
|
'category.status.description': '查看活动记录与暂停的会话。',
|
|
39
|
-
'field.paused': '
|
|
40
|
-
'field.showComposerToggle': '
|
|
41
|
-
'field.showComposerToggleHint': '
|
|
39
|
+
'field.paused': '全局启用自动继续',
|
|
40
|
+
'field.showComposerToggle': '在会话区显示模式选择',
|
|
41
|
+
'field.showComposerToggleHint': '默认显示。隐藏控件不会改变会话模式;点击保存后生效。',
|
|
42
42
|
'composer.label': '自动继续',
|
|
43
|
-
'composer.scope': '
|
|
43
|
+
'composer.scope': '只控制当前会话,立即保存并同步到其他标签页。关闭后也不再自动打断循环。',
|
|
44
|
+
'composer.default': '跟随默认',
|
|
45
|
+
'composer.off': '关闭',
|
|
46
|
+
'composer.recover': '仅故障恢复',
|
|
47
|
+
'composer.loop': '自主循环',
|
|
48
|
+
'composer.paused': '全局已暂停',
|
|
49
|
+
'composer.unavailable': '等待宿主连接',
|
|
44
50
|
'composer.saving': '正在保存自动继续设置…',
|
|
45
51
|
'composer.saveFailed': '保存失败,请重试',
|
|
46
52
|
'field.pausedHint': '恢复意外中断的会话。关闭并保存后,全局暂停恢复并取消已排队的继续。循环守卫独立运行;如需停止自动打断,请同时关闭循环守卫。',
|
|
@@ -52,8 +58,8 @@ export const zh = {
|
|
|
52
58
|
'default.continueTextMaxTokens': LOCALIZED_TEXT_DEFAULTS.zh.continueTextMaxTokens,
|
|
53
59
|
'field.resumeSilentTurns': '续跑无输出回合',
|
|
54
60
|
'field.resumeSilentTurnsHint': '已观察到模型活动但没有可见输出时续跑;不把空回合、图片或扩展内容误判为静默,冷却与连续上限照常生效。',
|
|
55
|
-
'field.resumeCompletedTurns': '
|
|
56
|
-
'field.resumeCompletedTurnsHint': '
|
|
61
|
+
'field.resumeCompletedTurns': '默认会话模式',
|
|
62
|
+
'field.resumeCompletedTurnsHint': '用于没有单独设置模式的会话。仅故障恢复不会接力正常完成的回合;自主循环会在正常完成后继续。无输出和失败回合仍受重试预算约束。',
|
|
57
63
|
'field.continueTextLoop': '自主循环的继续文本',
|
|
58
64
|
'field.continueTextLoopHint': '自主循环每次续跑时发送的文本。',
|
|
59
65
|
'default.continueTextLoop': LOCALIZED_TEXT_DEFAULTS.zh.continueTextLoop,
|
|
@@ -188,11 +194,17 @@ export const en: Record<SettingsCardKey, string> = {
|
|
|
188
194
|
'category.safety.description': 'Avoid duplicate tool actions and break unproductive loops.',
|
|
189
195
|
'category.status.title': 'Status and logs',
|
|
190
196
|
'category.status.description': 'View activity and paused sessions.',
|
|
191
|
-
'field.paused': '
|
|
192
|
-
'field.showComposerToggle': 'Show
|
|
193
|
-
'field.showComposerToggleHint': 'Shown by default. Hiding the
|
|
197
|
+
'field.paused': 'Enable auto-continue globally',
|
|
198
|
+
'field.showComposerToggle': 'Show session mode in the composer',
|
|
199
|
+
'field.showComposerToggleHint': 'Shown by default. Hiding the control does not change session modes. Click Save to apply.',
|
|
194
200
|
'composer.label': 'Auto-continue',
|
|
195
|
-
'composer.scope': '
|
|
201
|
+
'composer.scope': 'Only affects this session. Saved immediately and synced across tabs. Off also disables loop-guard interruptions here.',
|
|
202
|
+
'composer.default': 'Follow default',
|
|
203
|
+
'composer.off': 'Off',
|
|
204
|
+
'composer.recover': 'Recovery only',
|
|
205
|
+
'composer.loop': 'Autonomous loop',
|
|
206
|
+
'composer.paused': 'Globally paused',
|
|
207
|
+
'composer.unavailable': 'Waiting for host',
|
|
196
208
|
'composer.saving': 'Saving auto-continue setting…',
|
|
197
209
|
'composer.saveFailed': 'Could not save. Try again.',
|
|
198
210
|
'field.pausedHint': 'Resume interrupted sessions. Turn off and save to pause recovery globally and cancel queued continuations. The loop guard stays active; turn it off separately to stop automatic interruptions.',
|
|
@@ -204,8 +216,8 @@ export const en: Record<SettingsCardKey, string> = {
|
|
|
204
216
|
'default.continueTextMaxTokens': LOCALIZED_TEXT_DEFAULTS.en.continueTextMaxTokens,
|
|
205
217
|
'field.resumeSilentTurns': 'Resume silent turns',
|
|
206
218
|
'field.resumeSilentTurnsHint': 'Resume observed model activity without visible output. No-op turns, images and extension blocks are not treated as silent; cooldown and retry limits still apply.',
|
|
207
|
-
'field.resumeCompletedTurns': '
|
|
208
|
-
'field.resumeCompletedTurnsHint': '
|
|
219
|
+
'field.resumeCompletedTurns': 'Default session mode',
|
|
220
|
+
'field.resumeCompletedTurnsHint': 'Applies to sessions without their own mode. Recovery only leaves normal completions alone; autonomous loop continues after them. Silent and failed turns still consume the retry budget.',
|
|
209
221
|
'field.continueTextLoop': 'Continue text (autonomous loop)',
|
|
210
222
|
'field.continueTextLoopHint': 'Text sent on each autonomous-loop continuation.',
|
|
211
223
|
'default.continueTextLoop': LOCALIZED_TEXT_DEFAULTS.en.continueTextLoop,
|