dsh-client-auto-continue 0.16.0 → 0.17.1-rc.1
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 +38 -0
- package/README.md +14 -11
- package/README.zh.md +10 -10
- package/docs/releases/v0.17.0.md +62 -0
- package/docs/releases/v0.17.1-rc.1.md +55 -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/lib/client.js +381 -118
- package/lib/client.js.map +4 -4
- package/lib/index.js +25 -10
- package/lib/types/client/auto-continue-icon.d.ts +1 -0
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/client/locales.d.ts +5 -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 +1 -1
- package/lib/types/shared/core.d.ts +2 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +5 -3
- package/src/client/auto-continue-icon.tsx +35 -0
- package/src/client/composer-toggle.tsx +58 -14
- package/src/client/index.ts +1 -1
- package/src/client/locales.ts +12 -18
- package/src/client/mode-menu.tsx +110 -0
- package/src/client/native-toast.tsx +44 -0
- package/src/client/settings-card.tsx +130 -24
- package/src/client/styles.ts +61 -40
- package/src/host/engine.ts +29 -6
- package/src/shared/core.ts +4 -1
package/lib/index.js
CHANGED
|
@@ -1236,7 +1236,7 @@ function isTransientFailure(failure, retryableErrorPatterns = "") {
|
|
|
1236
1236
|
if (explicitlyRetryable) return true;
|
|
1237
1237
|
const status = failure.status;
|
|
1238
1238
|
if (status !== void 0 && (status === 401 || status === 403)) return false;
|
|
1239
|
-
const permanent = /auth|unauthor|forbidden|credential|api[_-]?key|permission/i.test(haystack) || /insufficient.*(balance|quota)|billing|payment|quota.*exceeded.*(?!retry)/i.test(haystack) || /model.*not[_-]?found|unknown[_-]?model|model[_-]?not[_-]?found|not.*support.*model/i.test(haystack) || /context.*(length|limit|overflow|exceed)|token.*limit|max.*context/i.test(haystack) || /invalid[_-]?request|bad[_-]?request/i.test(haystack);
|
|
1239
|
+
const permanent = /auth|unauthor|forbidden|credential|api[_-]?key|permission/i.test(haystack) || /insufficient.*(balance|quota)|billing|payment|quota.*exceeded.*(?!retry)/i.test(haystack) || /model.*not[_-]?found|unknown[_-]?model|model[_-]?not[_-]?found|not.*support.*model/i.test(haystack) || /context.*(length|limit|overflow|exceed)|token.*limit|max.*context/i.test(haystack) || /invalid[_-]?request|bad[_-]?request/i.test(haystack) || /prompt variable "\{\{[^"\r\n]+\}\}" has no value for this assembly/i.test(haystack);
|
|
1240
1240
|
return !permanent;
|
|
1241
1241
|
}
|
|
1242
1242
|
function formatElapsed(ms) {
|
|
@@ -1689,6 +1689,16 @@ function validateSessionEvents(events) {
|
|
|
1689
1689
|
}
|
|
1690
1690
|
return events;
|
|
1691
1691
|
}
|
|
1692
|
+
function latestTurnStart(events) {
|
|
1693
|
+
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
1694
|
+
const event = events[i];
|
|
1695
|
+
if (event?.type === "turn/start") return event;
|
|
1696
|
+
}
|
|
1697
|
+
return void 0;
|
|
1698
|
+
}
|
|
1699
|
+
function isMaintenanceTurnStart(event) {
|
|
1700
|
+
return event?.data?.reason === "message-ops";
|
|
1701
|
+
}
|
|
1692
1702
|
function parseFailureFacts(value) {
|
|
1693
1703
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
1694
1704
|
const failure = value;
|
|
@@ -1905,6 +1915,7 @@ var AutoContinueRunner = class {
|
|
|
1905
1915
|
return;
|
|
1906
1916
|
}
|
|
1907
1917
|
if (sessionState?.subagent) return;
|
|
1918
|
+
if (sessionState?.maintenanceTurn !== void 0 && sessionState.maintenanceTurn === event.data.turn && event.type !== "turn/start" && event.type !== "turn/end") return;
|
|
1908
1919
|
if ((event.type === "user/message" || event.type === "assistant/message") && typeof event.surfaceOp === "object" && event.surfaceOp !== null) {
|
|
1909
1920
|
this.state(sessionId).tools.recordSurfaceReplacement(event.seq);
|
|
1910
1921
|
return;
|
|
@@ -2134,6 +2145,8 @@ var AutoContinueRunner = class {
|
|
|
2134
2145
|
switch (event.type) {
|
|
2135
2146
|
case "turn/start":
|
|
2136
2147
|
state.running = true;
|
|
2148
|
+
state.maintenanceTurn = isMaintenanceTurnStart(event) ? event.data.turn : void 0;
|
|
2149
|
+
if (state.maintenanceTurn !== void 0) state.pendingRecoveryAt = 0;
|
|
2137
2150
|
state.tools.startTurn(event.seq);
|
|
2138
2151
|
state.shortRun = 0;
|
|
2139
2152
|
state.lastShortAt = 0;
|
|
@@ -2160,6 +2173,12 @@ var AutoContinueRunner = class {
|
|
|
2160
2173
|
const turnOutput = state.outputTurn === event.data.turn ? state.turnOutput : "unknown";
|
|
2161
2174
|
state.turnOutput = "unknown";
|
|
2162
2175
|
state.outputTurn = void 0;
|
|
2176
|
+
const maintenance = state.maintenanceTurn !== void 0 && state.maintenanceTurn === event.data.turn;
|
|
2177
|
+
state.maintenanceTurn = void 0;
|
|
2178
|
+
if (maintenance) {
|
|
2179
|
+
this.log(`跳过维护回合 ${sessionId}(message-ops): 不触发自动继续`);
|
|
2180
|
+
break;
|
|
2181
|
+
}
|
|
2163
2182
|
const reason = event.data.reason;
|
|
2164
2183
|
const reasonKind = readReasonKind(reason);
|
|
2165
2184
|
if (reasonKind === void 0) {
|
|
@@ -2636,11 +2655,13 @@ var AutoContinueRunner = class {
|
|
|
2636
2655
|
}
|
|
2637
2656
|
}
|
|
2638
2657
|
const reasonKind = readReasonKind(lastEnd?.data.reason);
|
|
2658
|
+
const lastStart = latestTurnStart(events);
|
|
2659
|
+
const maintenance = lastStart?.data.turn === lastEnd?.data.turn && isMaintenanceTurnStart(lastStart);
|
|
2639
2660
|
const silent = reasonKind === "no-visible-output" && config.resumeSilentTurns;
|
|
2640
2661
|
const superseded = lastEnd !== void 0 && events.some(
|
|
2641
2662
|
(event) => event.seq > lastEnd.seq && (event.type === "turn/start" || event.type === "user/message" && event.data.source.kind === "user")
|
|
2642
2663
|
);
|
|
2643
|
-
if (lastEnd === void 0 || reasonKind === void 0 || !isNonHumanReason(reasonKind) && !silent || lastEnd.time < now - config.freshMs || superseded) {
|
|
2664
|
+
if (lastEnd === void 0 || maintenance || reasonKind === void 0 || !isNonHumanReason(reasonKind) && !silent || lastEnd.time < now - config.freshMs || superseded) {
|
|
2644
2665
|
this.bootScannedSessions.add(session);
|
|
2645
2666
|
continue;
|
|
2646
2667
|
}
|
|
@@ -2783,15 +2804,9 @@ var AutoContinueRunner = class {
|
|
|
2783
2804
|
break;
|
|
2784
2805
|
}
|
|
2785
2806
|
}
|
|
2786
|
-
|
|
2787
|
-
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
2788
|
-
const event = events[i];
|
|
2789
|
-
if (event?.type === "turn/start") {
|
|
2790
|
-
lastStart = event;
|
|
2791
|
-
break;
|
|
2792
|
-
}
|
|
2793
|
-
}
|
|
2807
|
+
const lastStart = latestTurnStart(events);
|
|
2794
2808
|
const openTurn = lastStart !== void 0 && (lastEnd === void 0 || lastStart.seq > lastEnd.seq);
|
|
2809
|
+
if (isMaintenanceTurnStart(lastStart) && (openTurn || lastStart?.data.turn === lastEnd?.data.turn)) continue;
|
|
2795
2810
|
let reasonKind;
|
|
2796
2811
|
let freshAt;
|
|
2797
2812
|
if (openTurn) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function AutoContinueIcon(): import("react").JSX.Element;
|
|
@@ -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 per-session composer mode
|
|
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,6 +28,7 @@ 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;
|
|
37
33
|
'composer.default': string;
|
|
38
34
|
'composer.off': string;
|
|
@@ -141,6 +137,7 @@ export declare const zh: {
|
|
|
141
137
|
'chrome.expand': string;
|
|
142
138
|
'chrome.unsaved': string;
|
|
143
139
|
'chrome.readOnly': string;
|
|
140
|
+
'chrome.unavailable': string;
|
|
144
141
|
'chrome.saveFailed': string;
|
|
145
142
|
'chrome.discard': string;
|
|
146
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;
|
|
@@ -83,5 +83,5 @@ export declare class AutoContinueSettingsCardController {
|
|
|
83
83
|
export type AutoContinueSettingsCardProps = PropsLocale<'auto-continue'> & InjectFace<AutoContinueSettingsCardFace>;
|
|
84
84
|
/** The bundle page supplies no list container, unlike the legacy settings slot. */
|
|
85
85
|
export declare function AutoContinueSettingsPage(props: AutoContinueSettingsCardProps): import("react").JSX.Element;
|
|
86
|
-
/** Native category layout
|
|
86
|
+
/** Native category layout; the plugin manager above already owns the title, version and status. */
|
|
87
87
|
export declare function AutoContinueSettingsCard(props: AutoContinueSettingsCardProps): import("react").JSX.Element | null;
|
|
@@ -330,6 +330,8 @@ export interface SessionState {
|
|
|
330
330
|
turnOutput: 'unknown' | 'empty' | 'silent' | 'visible';
|
|
331
331
|
outputTurn: number | undefined;
|
|
332
332
|
outputStartSeq: number;
|
|
333
|
+
/** message-ops maintenance window, which must not enter model recovery or loop accounting. */
|
|
334
|
+
maintenanceTurn?: number;
|
|
333
335
|
/** 当前连续短句数(loop guard 信号 1: 空转)。 */
|
|
334
336
|
shortRun: number;
|
|
335
337
|
/** 最后一条短句的时间(时间窗判定用)。 */
|
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.1-rc.1",
|
|
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",
|
|
@@ -48,7 +50,7 @@
|
|
|
48
50
|
"watch": "node build.mjs --watch",
|
|
49
51
|
"typecheck": "tsc --noEmit",
|
|
50
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",
|
|
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",
|
|
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/settings-card-native.mjs && node tests/composer-toggle.mjs && node tests/settings-notifications.mjs && node tests/prepare-github-package.mjs && node tests/maintenance-turns.mjs && node tests/publish-prerelease.mjs",
|
|
52
54
|
"prepack": "npm run build"
|
|
53
55
|
},
|
|
54
56
|
"keywords": [
|
|
@@ -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
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
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';
|
|
3
|
-
import {
|
|
4
|
+
import { sessionMode, type SessionMode, type SessionPolicy } from '../shared/core.ts';
|
|
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;
|
|
@@ -10,6 +15,26 @@ export interface ComposerToggleState {
|
|
|
10
15
|
failed: ReadonlySet<string>;
|
|
11
16
|
}
|
|
12
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)} />;
|
|
36
|
+
}
|
|
37
|
+
|
|
13
38
|
export interface ComposerToggleFace {
|
|
14
39
|
hooks: { autoContinueComposer: SnapshotStore<ComposerToggleState> };
|
|
15
40
|
sessionId: string;
|
|
@@ -19,24 +44,43 @@ export interface ComposerToggleFace {
|
|
|
19
44
|
export function AutoContinueComposerToggle(props: PropsLocale<'auto-continue'> & InjectFace<ComposerToggleFace>) {
|
|
20
45
|
const state = props.useAutoContinueComposer((snapshot) => snapshot);
|
|
21
46
|
if (!state.visible || !props.sessionId) return null;
|
|
47
|
+
const failed = state.failed.has(props.sessionId);
|
|
22
48
|
const saving = state.saving.has(props.sessionId);
|
|
23
49
|
const policy = state.policy;
|
|
50
|
+
const mode = sessionMode(policy?.modes ?? {}, props.sessionId);
|
|
51
|
+
const disabled = !policy || !state.writable || saving;
|
|
24
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
|
+
];
|
|
25
65
|
return (
|
|
26
|
-
<div className="dshAcComposer" title={title}>
|
|
27
|
-
<span className="
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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} />
|
|
39
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>}
|
|
40
84
|
</div>
|
|
41
85
|
);
|
|
42
86
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -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 per-session composer mode
|
|
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,
|
package/src/client/locales.ts
CHANGED
|
@@ -7,14 +7,6 @@ import { LOCALIZED_TEXT_DEFAULTS } from '../shared/core.ts';
|
|
|
7
7
|
|
|
8
8
|
/** 简体中文词典(键集的事实来源)。 */
|
|
9
9
|
export const zh = {
|
|
10
|
-
'card.title': '自动继续',
|
|
11
|
-
'card.description': '恢复意外中断的会话,按你的节奏继续。',
|
|
12
|
-
'repo.star': '觉得好用的话,点个 Star 吧',
|
|
13
|
-
'repo.note': 'HsiangNianian 的开源插件,也欢迎反馈和 PR。',
|
|
14
|
-
'repo.link': 'GitHub 仓库',
|
|
15
|
-
'repo.aria': '在新标签页打开 HsiangNianian/dsh-auto-continue 的 GitHub 仓库',
|
|
16
|
-
'chrome.enabled': '已启用',
|
|
17
|
-
'chrome.paused': '已暂停',
|
|
18
10
|
'chrome.saved': '所有更改已保存',
|
|
19
11
|
'notification.title': '自动继续设置',
|
|
20
12
|
'notification.enabled': '设置已保存,浏览器通知已开启。',
|
|
@@ -24,6 +16,9 @@ export const zh = {
|
|
|
24
16
|
'notification.unsupported': '设置已保存,当前浏览器不支持通知。',
|
|
25
17
|
'notification.failed': '设置已保存,但浏览器通知未能发出。请检查网站和系统的通知权限。',
|
|
26
18
|
'chrome.categories': '设置类别',
|
|
19
|
+
'repo.star': '觉得好用的话,点个 Star 吧',
|
|
20
|
+
'repo.link': 'GitHub 仓库',
|
|
21
|
+
'repo.aria': '在新标签页打开 HsiangNianian/dsh-auto-continue 的 GitHub 仓库',
|
|
27
22
|
'category.general.title': '常规',
|
|
28
23
|
'category.general.description': '控制自动继续的启停、显示和通知。',
|
|
29
24
|
'category.recovery.title': '重试策略',
|
|
@@ -37,9 +32,10 @@ export const zh = {
|
|
|
37
32
|
'category.status.title': '状态与日志',
|
|
38
33
|
'category.status.description': '查看活动记录与暂停的会话。',
|
|
39
34
|
'field.paused': '全局启用自动继续',
|
|
40
|
-
'field.showComposerToggle': '
|
|
35
|
+
'field.showComposerToggle': '在会话区显示自动继续开关',
|
|
41
36
|
'field.showComposerToggleHint': '默认显示。隐藏控件不会改变会话模式;点击保存后生效。',
|
|
42
37
|
'composer.label': '自动继续',
|
|
38
|
+
'composer.mode': '自动继续模式',
|
|
43
39
|
'composer.scope': '只控制当前会话,立即保存并同步到其他标签页。关闭后也不再自动打断循环。',
|
|
44
40
|
'composer.default': '跟随默认',
|
|
45
41
|
'composer.off': '关闭',
|
|
@@ -148,6 +144,7 @@ export const zh = {
|
|
|
148
144
|
'chrome.expand': '展开设置',
|
|
149
145
|
'chrome.unsaved': '未保存',
|
|
150
146
|
'chrome.readOnly': '当前部署的设置只读。',
|
|
147
|
+
'chrome.unavailable': '设置暂不可用。',
|
|
151
148
|
'chrome.saveFailed': '部署未接受这些值, 已保留供你修改。',
|
|
152
149
|
'chrome.discard': '放弃',
|
|
153
150
|
'chrome.saving': '保存中…',
|
|
@@ -165,14 +162,6 @@ export type SettingsCardKey = keyof typeof zh;
|
|
|
165
162
|
|
|
166
163
|
/** English dictionary, checked complete against the zh key set. */
|
|
167
164
|
export const en: Record<SettingsCardKey, string> = {
|
|
168
|
-
'card.title': 'Auto continue',
|
|
169
|
-
'card.description': 'Resume interrupted sessions, at your pace.',
|
|
170
|
-
'repo.star': 'Finding it useful? Leave a Star',
|
|
171
|
-
'repo.note': 'By HsiangNianian. Feedback and PRs welcome.',
|
|
172
|
-
'repo.link': 'GitHub repo',
|
|
173
|
-
'repo.aria': 'Open HsiangNianian/dsh-auto-continue on GitHub in a new tab',
|
|
174
|
-
'chrome.enabled': 'Enabled',
|
|
175
|
-
'chrome.paused': 'Paused',
|
|
176
165
|
'chrome.saved': 'All changes saved',
|
|
177
166
|
'notification.title': 'Auto-continue settings',
|
|
178
167
|
'notification.enabled': 'Settings saved. Browser notifications are on.',
|
|
@@ -182,6 +171,9 @@ export const en: Record<SettingsCardKey, string> = {
|
|
|
182
171
|
'notification.unsupported': 'Settings saved. This browser does not support notifications.',
|
|
183
172
|
'notification.failed': 'Settings saved, but the notification could not be sent. Check notification permissions for this site and your system.',
|
|
184
173
|
'chrome.categories': 'Settings categories',
|
|
174
|
+
'repo.star': 'Finding it useful? Leave a Star',
|
|
175
|
+
'repo.link': 'GitHub repo',
|
|
176
|
+
'repo.aria': 'Open HsiangNianian/dsh-auto-continue on GitHub in a new tab',
|
|
185
177
|
'category.general.title': 'General',
|
|
186
178
|
'category.general.description': 'Control automatic recovery, visibility, and notifications.',
|
|
187
179
|
'category.recovery.title': 'Retry strategy',
|
|
@@ -195,9 +187,10 @@ export const en: Record<SettingsCardKey, string> = {
|
|
|
195
187
|
'category.status.title': 'Status and logs',
|
|
196
188
|
'category.status.description': 'View activity and paused sessions.',
|
|
197
189
|
'field.paused': 'Enable auto-continue globally',
|
|
198
|
-
'field.showComposerToggle': 'Show
|
|
190
|
+
'field.showComposerToggle': 'Show auto-continue switch in the composer',
|
|
199
191
|
'field.showComposerToggleHint': 'Shown by default. Hiding the control does not change session modes. Click Save to apply.',
|
|
200
192
|
'composer.label': 'Auto-continue',
|
|
193
|
+
'composer.mode': 'Auto-continue mode',
|
|
201
194
|
'composer.scope': 'Only affects this session. Saved immediately and synced across tabs. Off also disables loop-guard interruptions here.',
|
|
202
195
|
'composer.default': 'Follow default',
|
|
203
196
|
'composer.off': 'Off',
|
|
@@ -306,6 +299,7 @@ export const en: Record<SettingsCardKey, string> = {
|
|
|
306
299
|
'chrome.expand': 'Show settings',
|
|
307
300
|
'chrome.unsaved': 'Unsaved',
|
|
308
301
|
'chrome.readOnly': 'This deployment stores settings read-only.',
|
|
302
|
+
'chrome.unavailable': 'Settings are unavailable.',
|
|
309
303
|
'chrome.saveFailed': 'The deployment did not accept these values; they were left for you to correct.',
|
|
310
304
|
'chrome.discard': 'Discard',
|
|
311
305
|
'chrome.saving': 'Saving…',
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composer mode menu.
|
|
3
|
+
*
|
|
4
|
+
* Uses the host's own `Menu` and chevron primitives whenever the running DSH
|
|
5
|
+
* exposes them, so the control looks and behaves like the composer's other
|
|
6
|
+
* dropdowns (workspace permission, model picker). Legacy hosts, and the unit
|
|
7
|
+
* tests' minimal module fixture, fall back to a native `<select>` over the
|
|
8
|
+
* same compact label.
|
|
9
|
+
*/
|
|
10
|
+
import { useEffect, useState, type ComponentType, type ReactNode } from 'react';
|
|
11
|
+
import { isSessionMode, type SessionMode } from '../shared/core.ts';
|
|
12
|
+
|
|
13
|
+
export interface ModeMenuOption {
|
|
14
|
+
id: SessionMode;
|
|
15
|
+
label: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface MenuProps {
|
|
19
|
+
open: boolean;
|
|
20
|
+
anchor: ReactNode;
|
|
21
|
+
items: readonly ModeMenuOption[];
|
|
22
|
+
selectedId?: string;
|
|
23
|
+
onSelect?: (id: string) => void;
|
|
24
|
+
onClose?: () => void;
|
|
25
|
+
side?: 'top' | 'bottom';
|
|
26
|
+
portal?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ChevronProps {
|
|
30
|
+
className?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const primitives = (() => {
|
|
34
|
+
try {
|
|
35
|
+
return require('@deepseek-ai/dsh-client-ui-primitives') as {
|
|
36
|
+
Menu?: ComponentType<MenuProps>;
|
|
37
|
+
IconChevronDownOutlineRegular?: ComponentType<ChevronProps>;
|
|
38
|
+
};
|
|
39
|
+
} catch {
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
})();
|
|
43
|
+
|
|
44
|
+
const HostMenu = primitives.Menu;
|
|
45
|
+
const HostChevron = primitives.IconChevronDownOutlineRegular;
|
|
46
|
+
|
|
47
|
+
function ChevronDown() {
|
|
48
|
+
if (HostChevron) return <HostChevron />;
|
|
49
|
+
return (
|
|
50
|
+
<svg className="dshAcModeChevronFallback" viewBox="0 0 16 16" aria-hidden="true">
|
|
51
|
+
<path d="m4.5 6.25 3.5 3.5 3.5-3.5" />
|
|
52
|
+
</svg>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ModeMenuProps {
|
|
57
|
+
mode: SessionMode;
|
|
58
|
+
options: readonly ModeMenuOption[];
|
|
59
|
+
/** Short label shown on the trigger, e.g. 跟随默认. */
|
|
60
|
+
label: string;
|
|
61
|
+
/** Accessible name including the resolved mode, e.g. 自动继续模式: 跟随默认 (仅故障恢复). */
|
|
62
|
+
ariaLabel: string;
|
|
63
|
+
/** Plain menu name used by the legacy select fallback. */
|
|
64
|
+
selectLabel: string;
|
|
65
|
+
title: string;
|
|
66
|
+
disabled: boolean;
|
|
67
|
+
onChange: (mode: SessionMode) => void;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function ModeMenu(props: ModeMenuProps) {
|
|
71
|
+
const [open, setOpen] = useState(false);
|
|
72
|
+
const expanded = open && !props.disabled;
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (props.disabled) setOpen(false);
|
|
76
|
+
}, [props.disabled]);
|
|
77
|
+
|
|
78
|
+
const choose = (id: string) => {
|
|
79
|
+
setOpen(false);
|
|
80
|
+
if (isSessionMode(id) && id !== props.mode) props.onChange(id);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
if (HostMenu) {
|
|
84
|
+
return (
|
|
85
|
+
<HostMenu open={expanded} side="top" portal
|
|
86
|
+
items={props.options} selectedId={props.mode}
|
|
87
|
+
onSelect={choose} onClose={() => setOpen(false)}
|
|
88
|
+
anchor={
|
|
89
|
+
<button type="button" className="dshAcModeTrigger" disabled={props.disabled}
|
|
90
|
+
aria-label={props.ariaLabel} aria-haspopup="menu" aria-expanded={expanded}
|
|
91
|
+
title={props.title} onClick={() => setOpen(value => !value)}>
|
|
92
|
+
<span className="dshAcModeTriggerLabel">{props.label}</span>
|
|
93
|
+
<span className="dshAcModeChevron" data-open={expanded} aria-hidden="true"><ChevronDown /></span>
|
|
94
|
+
</button>
|
|
95
|
+
} />
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<span className="dshAcModeMenu" data-disabled={props.disabled} title={props.title}>
|
|
101
|
+
<span className="dshAcModeTriggerLabel">{props.label}</span>
|
|
102
|
+
<span className="dshAcModeChevron" aria-hidden="true"><ChevronDown /></span>
|
|
103
|
+
<select className="dshAcComposerSelect" aria-label={props.selectLabel} disabled={props.disabled}
|
|
104
|
+
value={props.mode}
|
|
105
|
+
onChange={event => { if (isSessionMode(event.target.value)) props.onChange(event.target.value); }}>
|
|
106
|
+
{props.options.map(option => <option key={option.id} value={option.id}>{option.label}</option>)}
|
|
107
|
+
</select>
|
|
108
|
+
</span>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
|
|
10
|
+
export interface ToastProps {
|
|
11
|
+
text: string;
|
|
12
|
+
icon?: ReactNode;
|
|
13
|
+
tone?: 'success';
|
|
14
|
+
onDone?: () => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface IconProps {
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const primitives = (() => {
|
|
22
|
+
try {
|
|
23
|
+
return require('@deepseek-ai/dsh-client-ui-primitives') as {
|
|
24
|
+
Toast?: ComponentType<ToastProps>;
|
|
25
|
+
IconWarningOutlineRegular?: ComponentType<IconProps>;
|
|
26
|
+
};
|
|
27
|
+
} catch {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
})();
|
|
31
|
+
|
|
32
|
+
export const NativeToast = primitives.Toast;
|
|
33
|
+
export const hasNativeToast = typeof NativeToast === 'function';
|
|
34
|
+
|
|
35
|
+
export function WarningIcon() {
|
|
36
|
+
const Icon = primitives.IconWarningOutlineRegular;
|
|
37
|
+
if (Icon) return <Icon />;
|
|
38
|
+
return (
|
|
39
|
+
<svg className="dshAcToastIcon" viewBox="0 0 16 16" aria-hidden="true">
|
|
40
|
+
<path d="M8 2.3 14.3 13H1.7L8 2.3Z" />
|
|
41
|
+
<path d="M8 6.2v3.1M8 11.8v.1" />
|
|
42
|
+
</svg>
|
|
43
|
+
);
|
|
44
|
+
}
|