dsh-client-auto-continue 0.15.0 → 0.17.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 +56 -0
- package/README.md +37 -21
- package/README.zh.md +34 -21
- package/docs/releases/v0.16.0.md +75 -0
- package/docs/releases/v0.17.0.md +62 -0
- 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 +8 -8
- package/docs/third-party-notices.md +19 -0
- package/lib/client.js +474 -133
- package/lib/client.js.map +4 -4
- package/lib/index.js +7560 -117
- package/lib/types/client/auto-continue-icon.d.ts +1 -0
- 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 +11 -8
- package/lib/types/client/mode-menu.d.ts +19 -0
- package/lib/types/client/native-toast.d.ts +17 -0
- package/lib/types/client/settings-card.d.ts +6 -5
- 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/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +24 -14
- package/src/client/auto-continue-icon.tsx +35 -0
- package/src/client/bridge.ts +35 -4
- package/src/client/composer-toggle.tsx +66 -14
- package/src/client/index.ts +4 -2
- package/src/client/locales.ts +32 -26
- package/src/client/mode-menu.tsx +110 -0
- package/src/client/native-toast.tsx +44 -0
- package/src/client/settings-card.tsx +156 -41
- package/src/client/styles.ts +61 -37
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function AutoContinueIcon(): import("react").JSX.Element;
|
|
@@ -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 switch and mode menu 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,
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
/** 简体中文词典(键集的事实来源)。 */
|
|
2
2
|
export declare const zh: {
|
|
3
|
-
'card.title': string;
|
|
4
|
-
'card.description': string;
|
|
5
|
-
'repo.star': string;
|
|
6
|
-
'repo.note': string;
|
|
7
|
-
'repo.link': string;
|
|
8
|
-
'repo.aria': string;
|
|
9
|
-
'chrome.enabled': string;
|
|
10
|
-
'chrome.paused': string;
|
|
11
3
|
'chrome.saved': string;
|
|
12
4
|
'notification.title': string;
|
|
13
5
|
'notification.enabled': string;
|
|
@@ -17,6 +9,9 @@ export declare const zh: {
|
|
|
17
9
|
'notification.unsupported': string;
|
|
18
10
|
'notification.failed': string;
|
|
19
11
|
'chrome.categories': string;
|
|
12
|
+
'repo.star': string;
|
|
13
|
+
'repo.link': string;
|
|
14
|
+
'repo.aria': string;
|
|
20
15
|
'category.general.title': string;
|
|
21
16
|
'category.general.description': string;
|
|
22
17
|
'category.recovery.title': string;
|
|
@@ -33,7 +28,14 @@ export declare const zh: {
|
|
|
33
28
|
'field.showComposerToggle': string;
|
|
34
29
|
'field.showComposerToggleHint': string;
|
|
35
30
|
'composer.label': string;
|
|
31
|
+
'composer.mode': string;
|
|
36
32
|
'composer.scope': string;
|
|
33
|
+
'composer.default': string;
|
|
34
|
+
'composer.off': string;
|
|
35
|
+
'composer.recover': string;
|
|
36
|
+
'composer.loop': string;
|
|
37
|
+
'composer.paused': string;
|
|
38
|
+
'composer.unavailable': string;
|
|
37
39
|
'composer.saving': string;
|
|
38
40
|
'composer.saveFailed': string;
|
|
39
41
|
'field.pausedHint': string;
|
|
@@ -135,6 +137,7 @@ export declare const zh: {
|
|
|
135
137
|
'chrome.expand': string;
|
|
136
138
|
'chrome.unsaved': string;
|
|
137
139
|
'chrome.readOnly': string;
|
|
140
|
+
'chrome.unavailable': string;
|
|
138
141
|
'chrome.saveFailed': string;
|
|
139
142
|
'chrome.discard': string;
|
|
140
143
|
'chrome.saving': string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type SessionMode } from '../shared/core.ts';
|
|
2
|
+
export interface ModeMenuOption {
|
|
3
|
+
id: SessionMode;
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ModeMenuProps {
|
|
7
|
+
mode: SessionMode;
|
|
8
|
+
options: readonly ModeMenuOption[];
|
|
9
|
+
/** Short label shown on the trigger, e.g. 跟随默认. */
|
|
10
|
+
label: string;
|
|
11
|
+
/** Accessible name including the resolved mode, e.g. 自动继续模式: 跟随默认 (仅故障恢复). */
|
|
12
|
+
ariaLabel: string;
|
|
13
|
+
/** Plain menu name used by the legacy select fallback. */
|
|
14
|
+
selectLabel: string;
|
|
15
|
+
title: string;
|
|
16
|
+
disabled: boolean;
|
|
17
|
+
onChange: (mode: SessionMode) => void;
|
|
18
|
+
}
|
|
19
|
+
export declare function ModeMenu(props: ModeMenuProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSH toast bridge.
|
|
3
|
+
*
|
|
4
|
+
* The composer reports a failed session-mode save with the host's own toast
|
|
5
|
+
* instead of inline red text that shifts the input row. Hosts without the
|
|
6
|
+
* primitive (older DSH, or the unit-test fixture) keep the inline fallback.
|
|
7
|
+
*/
|
|
8
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
9
|
+
export interface ToastProps {
|
|
10
|
+
text: string;
|
|
11
|
+
icon?: ReactNode;
|
|
12
|
+
tone?: 'success';
|
|
13
|
+
onDone?: () => void;
|
|
14
|
+
}
|
|
15
|
+
export declare const NativeToast: ComponentType<ToastProps> | undefined;
|
|
16
|
+
export declare const hasNativeToast: boolean;
|
|
17
|
+
export declare function WarningIcon(): import("react").JSX.Element;
|
|
@@ -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
|
}
|
|
@@ -82,5 +83,5 @@ export declare class AutoContinueSettingsCardController {
|
|
|
82
83
|
export type AutoContinueSettingsCardProps = PropsLocale<'auto-continue'> & InjectFace<AutoContinueSettingsCardFace>;
|
|
83
84
|
/** The bundle page supplies no list container, unlike the legacy settings slot. */
|
|
84
85
|
export declare function AutoContinueSettingsPage(props: AutoContinueSettingsCardProps): import("react").JSX.Element;
|
|
85
|
-
/** Native category layout
|
|
86
|
+
/** Native category layout; the plugin manager above already owns the title, version and status. */
|
|
86
87
|
export declare function AutoContinueSettingsCard(props: AutoContinueSettingsCardProps): import("react").JSX.Element | null;
|
|
@@ -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/locale/en.json
ADDED
package/locale/zh.json
ADDED
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.17.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/types/index.d.ts",
|
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
"types": "./lib/types/client/index.d.ts",
|
|
15
15
|
"default": "./lib/client.js"
|
|
16
16
|
},
|
|
17
|
-
"./package.json": "./package.json"
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
"./locale/*.json": "./locale/*.json"
|
|
18
19
|
},
|
|
19
20
|
"files": [
|
|
20
21
|
"lib",
|
|
21
22
|
"src",
|
|
23
|
+
"locale",
|
|
22
24
|
"cordis.patch.yml",
|
|
23
25
|
"scripts",
|
|
24
26
|
"docs",
|
|
@@ -26,6 +28,7 @@
|
|
|
26
28
|
"tsconfig.build.json",
|
|
27
29
|
"README.md",
|
|
28
30
|
"README.zh.md",
|
|
31
|
+
"CHANGELOG.md",
|
|
29
32
|
"LICENSE"
|
|
30
33
|
],
|
|
31
34
|
"dsh": {
|
|
@@ -46,8 +49,8 @@
|
|
|
46
49
|
"build": "node build.mjs && tsc -p tsconfig.build.json",
|
|
47
50
|
"watch": "node build.mjs --watch",
|
|
48
51
|
"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",
|
|
52
|
+
"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",
|
|
53
|
+
"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
54
|
"prepack": "npm run build"
|
|
52
55
|
},
|
|
53
56
|
"keywords": [
|
|
@@ -67,16 +70,23 @@
|
|
|
67
70
|
"esbuild": "^0.25.0",
|
|
68
71
|
"typescript": "~5.8.0",
|
|
69
72
|
"@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"
|
|
73
|
+
"@deepseek-ai/cordis": "4.0.2",
|
|
74
|
+
"@deepseek-ai/dsh-client-connection": "0.1.2-rc.1",
|
|
75
|
+
"@deepseek-ai/dsh-client-locale": "0.1.2-rc.1",
|
|
76
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.1.2-rc.1",
|
|
77
|
+
"@deepseek-ai/dsh-client-ui-settings-plugins": "0.1.2-rc.1",
|
|
78
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.1.2-rc.1",
|
|
79
|
+
"@deepseek-ai/dsh-session": "0.1.2-rc.1",
|
|
80
|
+
"@deepseek-ai/dsh-settings": "0.1.2-rc.1",
|
|
81
|
+
"@deepseek-ai/schemastery": "3.18.2",
|
|
82
|
+
"@types/node": "^22.0.0",
|
|
83
|
+
"yaml": "2.9.1",
|
|
84
|
+
"@deepseek-ai/dsh-agent": "0.1.2-rc.1",
|
|
85
|
+
"@deepseek-ai/dsh-client-store": "0.1.2-rc.1",
|
|
86
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.1.2-rc.1",
|
|
87
|
+
"@deepseek-ai/dsh-host-webserver": "0.1.2-rc.1",
|
|
88
|
+
"@deepseek-ai/dsh-llm": "0.1.2-rc.1",
|
|
89
|
+
"react-dom": "^18.2.0"
|
|
80
90
|
},
|
|
81
91
|
"license": "MIT",
|
|
82
92
|
"peerDependencies": {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-continue glyph.
|
|
3
|
+
*
|
|
4
|
+
* Prefers the host's own icon so the composer label matches the surrounding
|
|
5
|
+
* DSH chrome; older hosts without the primitives module get an equivalent
|
|
6
|
+
* inline stroke icon. The icon stays visible when the label text is hidden at
|
|
7
|
+
* narrow widths.
|
|
8
|
+
*/
|
|
9
|
+
import type { ComponentType } from 'react';
|
|
10
|
+
|
|
11
|
+
interface IconProps {
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const primitives = (() => {
|
|
16
|
+
try {
|
|
17
|
+
return require('@deepseek-ai/dsh-client-ui-primitives') as {
|
|
18
|
+
IconRefreshOutlineRegular?: ComponentType<IconProps>;
|
|
19
|
+
};
|
|
20
|
+
} catch {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
})();
|
|
24
|
+
|
|
25
|
+
const HostRefresh = primitives.IconRefreshOutlineRegular;
|
|
26
|
+
|
|
27
|
+
export function AutoContinueIcon() {
|
|
28
|
+
if (HostRefresh) return <HostRefresh />;
|
|
29
|
+
return (
|
|
30
|
+
<svg className="dshAcComposerIconFallback" viewBox="0 0 16 16" aria-hidden="true">
|
|
31
|
+
<path d="M13.25 8a5.25 5.25 0 1 1-1.54-3.71" />
|
|
32
|
+
<path d="M13.25 3.1v3.3h-3.3" />
|
|
33
|
+
</svg>
|
|
34
|
+
);
|
|
35
|
+
}
|
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,34 +1,86 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
1
2
|
import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
3
|
import type { SnapshotStore } from './dsh-store-compat.ts';
|
|
4
|
+
import { sessionMode, type SessionMode, type SessionPolicy } from '../shared/core.ts';
|
|
3
5
|
import { NativeSwitch } from './native-switch.tsx';
|
|
6
|
+
import { ModeMenu, type ModeMenuOption } from './mode-menu.tsx';
|
|
7
|
+
import { AutoContinueIcon } from './auto-continue-icon.tsx';
|
|
8
|
+
import { NativeToast, WarningIcon, hasNativeToast } from './native-toast.tsx';
|
|
4
9
|
|
|
5
10
|
export interface ComposerToggleState {
|
|
6
11
|
visible: boolean;
|
|
7
|
-
|
|
12
|
+
policy: SessionPolicy | undefined;
|
|
8
13
|
writable: boolean;
|
|
9
|
-
saving:
|
|
10
|
-
failed:
|
|
14
|
+
saving: ReadonlySet<string>;
|
|
15
|
+
failed: ReadonlySet<string>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const HOST_UNAVAILABLE_DELAY_MS = 3000;
|
|
19
|
+
|
|
20
|
+
function HostUnavailableToast({ text }: { text: string }) {
|
|
21
|
+
const [visible, setVisible] = useState(false);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const timer = setTimeout(() => setVisible(true), HOST_UNAVAILABLE_DELAY_MS);
|
|
24
|
+
return () => clearTimeout(timer);
|
|
25
|
+
}, []);
|
|
26
|
+
if (!hasNativeToast || !visible) return null;
|
|
27
|
+
const Toast = NativeToast!;
|
|
28
|
+
return <Toast text={text} icon={<WarningIcon />} onDone={() => setVisible(false)} />;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function SaveFailureToast({ text }: { text: string }) {
|
|
32
|
+
const [visible, setVisible] = useState(true);
|
|
33
|
+
if (!hasNativeToast || !visible) return null;
|
|
34
|
+
const Toast = NativeToast!;
|
|
35
|
+
return <Toast text={text} icon={<WarningIcon />} onDone={() => setVisible(false)} />;
|
|
11
36
|
}
|
|
12
37
|
|
|
13
38
|
export interface ComposerToggleFace {
|
|
14
39
|
hooks: { autoContinueComposer: SnapshotStore<ComposerToggleState> };
|
|
15
|
-
|
|
40
|
+
sessionId: string;
|
|
41
|
+
setMode: (mode: SessionMode) => void;
|
|
16
42
|
}
|
|
17
43
|
|
|
18
44
|
export function AutoContinueComposerToggle(props: PropsLocale<'auto-continue'> & InjectFace<ComposerToggleFace>) {
|
|
19
45
|
const state = props.useAutoContinueComposer((snapshot) => snapshot);
|
|
20
|
-
if (!state.visible) return null;
|
|
21
|
-
const
|
|
46
|
+
if (!state.visible || !props.sessionId) return null;
|
|
47
|
+
const failed = state.failed.has(props.sessionId);
|
|
48
|
+
const saving = state.saving.has(props.sessionId);
|
|
49
|
+
const policy = state.policy;
|
|
50
|
+
const mode = sessionMode(policy?.modes ?? {}, props.sessionId);
|
|
51
|
+
const disabled = !policy || !state.writable || saving;
|
|
52
|
+
const title = props.t(!policy ? 'composer.unavailable' : !state.writable ? 'chrome.readOnly' : saving ? 'composer.saving' : 'composer.scope');
|
|
53
|
+
const modeName = props.t(`composer.${mode}`);
|
|
54
|
+
const defaultName = policy
|
|
55
|
+
? `${props.t('composer.default')} (${props.t(`composer.${policy.defaultMode}`)})`
|
|
56
|
+
: props.t('composer.default');
|
|
57
|
+
const fullModeLabel = mode === 'default' ? defaultName : modeName;
|
|
58
|
+
const modeTitle = `${props.t('composer.mode')}: ${fullModeLabel}`;
|
|
59
|
+
const options: readonly ModeMenuOption[] = [
|
|
60
|
+
{ id: 'default', label: defaultName },
|
|
61
|
+
{ id: 'off', label: props.t('composer.off') },
|
|
62
|
+
{ id: 'recover', label: props.t('composer.recover') },
|
|
63
|
+
{ id: 'loop', label: props.t('composer.loop') },
|
|
64
|
+
];
|
|
22
65
|
return (
|
|
23
|
-
<div className="dshAcComposer" title={title}>
|
|
24
|
-
<span className="
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
66
|
+
<div className="dshAcComposer" title={title} aria-busy={saving || undefined}>
|
|
67
|
+
<span className="dshAcComposerCore">
|
|
68
|
+
<span className="dshAcComposerLabel">
|
|
69
|
+
<span className="dshAcComposerIcon" aria-hidden="true"><AutoContinueIcon /></span>
|
|
70
|
+
<span className="dshAcComposerText">{props.t('composer.label')}</span>
|
|
71
|
+
</span>
|
|
72
|
+
<span className="dshAcSwitchTarget">
|
|
73
|
+
<NativeSwitch checked={!!policy && mode !== 'off'} onChange={enabled => props.setMode(enabled ? 'default' : 'off')}
|
|
74
|
+
disabled={disabled} label={props.t('composer.label')} title={title} />
|
|
75
|
+
</span>
|
|
76
|
+
<ModeMenu mode={mode} options={options} label={modeName}
|
|
77
|
+
ariaLabel={modeTitle} selectLabel={props.t('composer.mode')} title={modeTitle}
|
|
78
|
+
disabled={disabled} onChange={props.setMode} />
|
|
31
79
|
</span>
|
|
80
|
+
{policy?.paused && <span className="dshAcComposerLabel">{props.t('composer.paused')}</span>}
|
|
81
|
+
{!policy && hasNativeToast && <HostUnavailableToast text={props.t('composer.unavailable')} />}
|
|
82
|
+
{failed && hasNativeToast && <SaveFailureToast text={props.t('composer.saveFailed')} />}
|
|
83
|
+
{failed && !hasNativeToast && <span className="dshAcComposerError" role="status">{props.t('composer.saveFailed')}</span>}
|
|
32
84
|
</div>
|
|
33
85
|
);
|
|
34
86
|
}
|