dsh-client-auto-continue 0.17.3 → 0.18.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 +36 -0
- package/README.md +37 -6
- package/README.zh.md +37 -6
- package/docs/releases/v0.17.4.md +35 -0
- package/docs/releases/v0.18.0.md +58 -0
- package/lib/client.js +53 -4
- package/lib/client.js.map +2 -2
- package/lib/index.js +540 -13
- package/lib/types/client/locales.d.ts +14 -0
- package/lib/types/client/settings-card.d.ts +7 -0
- package/lib/types/host/connectivity.d.ts +4 -0
- package/lib/types/host/engine.d.ts +50 -1
- package/lib/types/index.d.ts +56 -0
- package/lib/types/shared/core.d.ts +39 -0
- package/package.json +2 -2
- package/src/client/locales.ts +28 -0
- package/src/client/settings-card.tsx +24 -3
- package/src/host/connectivity.ts +54 -0
- package/src/host/engine.ts +574 -4
- package/src/index.ts +14 -0
- package/src/shared/core.ts +70 -1
package/src/index.ts
CHANGED
|
@@ -28,6 +28,8 @@ export const AUTO_CONTINUE_NS = 'auto-continue';
|
|
|
28
28
|
const settingsFields = {
|
|
29
29
|
/** Active browser/UI locale mirrored by the client. */
|
|
30
30
|
locale: z.string().default('en'),
|
|
31
|
+
/** Send continue messages with the plugin source instead of the legacy user source. */
|
|
32
|
+
usePluginSource: z.boolean().default(false),
|
|
31
33
|
/** Text automatically sent after an interruption. */
|
|
32
34
|
continueText: z.string().default(''),
|
|
33
35
|
/** Text sent when the output token ceiling is reached (same placeholders as `continueText`). */
|
|
@@ -98,6 +100,18 @@ const settingsFields = {
|
|
|
98
100
|
loopText: z
|
|
99
101
|
.string()
|
|
100
102
|
.default(''),
|
|
103
|
+
/** Recover child (subagent / Agent Teams) sessions a restart interrupted by waking their root session once. */
|
|
104
|
+
resumeInterruptedChildren: z.boolean().default(false),
|
|
105
|
+
/** Re-arm a goal a restart left `active` but `disarmed`, when its own session is resumed. */
|
|
106
|
+
resumeGoals: z.boolean().default(false),
|
|
107
|
+
/** Also resume goals the user explicitly paused. Off by default: pausing is a human decision. */
|
|
108
|
+
resumePausedGoals: z.boolean().default(false),
|
|
109
|
+
/** Hold network-error recoveries while the host is offline; waiting does not consume the retry budget. */
|
|
110
|
+
pauseWhenOffline: z.boolean().default(true),
|
|
111
|
+
/** How often (ms) a held recovery re-checks connectivity. */
|
|
112
|
+
offlineCheckMs: z.natural().min(1000).default(15000),
|
|
113
|
+
/** Autonomous-loop round cap per session; 0 means unlimited. */
|
|
114
|
+
loopMaxIterations: z.natural().default(0),
|
|
101
115
|
};
|
|
102
116
|
export const AutoContinueSchema = z.object(settingsFields);
|
|
103
117
|
|
package/src/shared/core.ts
CHANGED
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { SessionEvent, SessionId } from '@deepseek-ai/dsh-session/types';
|
|
8
8
|
|
|
9
|
+
export const AUTO_CONTINUE_SOURCE_KIND = 'plugin:dsh-client-auto-continue';
|
|
10
|
+
|
|
11
|
+
declare module '@deepseek-ai/dsh-llm' {
|
|
12
|
+
interface MessageSourceMap {
|
|
13
|
+
'plugin:dsh-client-auto-continue': { kind: typeof AUTO_CONTINUE_SOURCE_KIND };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
9
17
|
/** Supported UI/config locales; missing and unsupported values use English. */
|
|
10
18
|
export type AutoContinueLocale = 'en' | 'zh';
|
|
11
19
|
|
|
@@ -64,6 +72,8 @@ export const LOCALIZED_TEXT_DEFAULTS = {
|
|
|
64
72
|
export interface AutoContinueSettings {
|
|
65
73
|
/** Active browser/UI locale mirrored by the client. */
|
|
66
74
|
locale?: AutoContinueLocale;
|
|
75
|
+
/** Send continue messages with the plugin source instead of the legacy user source. */
|
|
76
|
+
usePluginSource?: boolean;
|
|
67
77
|
/** Text automatically sent after an interruption. */
|
|
68
78
|
continueText?: string;
|
|
69
79
|
/** Text sent when the output token ceiling is reached (same placeholders as `continueText`). */
|
|
@@ -128,6 +138,18 @@ export interface AutoContinueSettings {
|
|
|
128
138
|
loopRepeatText?: number;
|
|
129
139
|
/** Text sent after the loop guard cancels and restarts a turn (supports {tool}). */
|
|
130
140
|
loopText?: string;
|
|
141
|
+
/** Recover child (subagent / Agent Teams) sessions that a restart interrupted by waking their root session once. */
|
|
142
|
+
resumeInterruptedChildren?: boolean;
|
|
143
|
+
/** Re-arm a goal that a restart left `active` but `disarmed`, when its own session is resumed. */
|
|
144
|
+
resumeGoals?: boolean;
|
|
145
|
+
/** Also resume goals the user explicitly paused. Off by default: pausing is a human decision. */
|
|
146
|
+
resumePausedGoals?: boolean;
|
|
147
|
+
/** Hold network-error recoveries while the host is offline; waiting does not consume the retry budget. */
|
|
148
|
+
pauseWhenOffline?: boolean;
|
|
149
|
+
/** How often (ms) a held recovery re-checks connectivity. */
|
|
150
|
+
offlineCheckMs?: number;
|
|
151
|
+
/** Autonomous-loop round cap per session; 0 means unlimited. Resets when the user sends a message or turns the loop back on. */
|
|
152
|
+
loopMaxIterations?: number;
|
|
131
153
|
}
|
|
132
154
|
|
|
133
155
|
/** Fully resolved configuration (built-in defaults + user overrides). */
|
|
@@ -137,6 +159,7 @@ export type AutoContinueConfig = Required<AutoContinueSettings>;
|
|
|
137
159
|
export const DEFAULT_CONFIG: AutoContinueConfig = {
|
|
138
160
|
locale: 'en',
|
|
139
161
|
...LOCALIZED_TEXT_DEFAULTS.en,
|
|
162
|
+
usePluginSource: false,
|
|
140
163
|
resumeSilentTurns: true,
|
|
141
164
|
resumeCompletedTurns: false,
|
|
142
165
|
continueTextLoop: '',
|
|
@@ -162,6 +185,12 @@ export const DEFAULT_CONFIG: AutoContinueConfig = {
|
|
|
162
185
|
loopShortCount: 12,
|
|
163
186
|
loopRepeatText: 4,
|
|
164
187
|
loopToolRepeat: 5,
|
|
188
|
+
resumeInterruptedChildren: false,
|
|
189
|
+
resumeGoals: false,
|
|
190
|
+
resumePausedGoals: false,
|
|
191
|
+
pauseWhenOffline: true,
|
|
192
|
+
offlineCheckMs: 15000,
|
|
193
|
+
loopMaxIterations: 0,
|
|
165
194
|
};
|
|
166
195
|
|
|
167
196
|
function numberOr(value: unknown, fallback: number): number {
|
|
@@ -207,6 +236,7 @@ export function resolveConfig(section: AutoContinueSettings | undefined): AutoCo
|
|
|
207
236
|
: localized.guardDoneText;
|
|
208
237
|
return {
|
|
209
238
|
locale,
|
|
239
|
+
usePluginSource: booleanOr(value.usePluginSource, DEFAULT_CONFIG.usePluginSource),
|
|
210
240
|
continueText: text,
|
|
211
241
|
continueTextMaxTokens: maxTokensText,
|
|
212
242
|
resumeSilentTurns: booleanOr(value.resumeSilentTurns, DEFAULT_CONFIG.resumeSilentTurns),
|
|
@@ -246,6 +276,15 @@ export function resolveConfig(section: AutoContinueSettings | undefined): AutoCo
|
|
|
246
276
|
typeof value.loopText === 'string' && value.loopText.trim() !== ''
|
|
247
277
|
? value.loopText
|
|
248
278
|
: localized.loopText,
|
|
279
|
+
resumeInterruptedChildren: booleanOr(
|
|
280
|
+
value.resumeInterruptedChildren,
|
|
281
|
+
DEFAULT_CONFIG.resumeInterruptedChildren,
|
|
282
|
+
),
|
|
283
|
+
resumeGoals: booleanOr(value.resumeGoals, DEFAULT_CONFIG.resumeGoals),
|
|
284
|
+
resumePausedGoals: booleanOr(value.resumePausedGoals, DEFAULT_CONFIG.resumePausedGoals),
|
|
285
|
+
pauseWhenOffline: booleanOr(value.pauseWhenOffline, DEFAULT_CONFIG.pauseWhenOffline),
|
|
286
|
+
offlineCheckMs: Math.max(1000, numberOr(value.offlineCheckMs, DEFAULT_CONFIG.offlineCheckMs)),
|
|
287
|
+
loopMaxIterations: Math.floor(numberOr(value.loopMaxIterations, DEFAULT_CONFIG.loopMaxIterations)),
|
|
249
288
|
};
|
|
250
289
|
}
|
|
251
290
|
|
|
@@ -287,6 +326,8 @@ export function isTransientFailure(failure: FailureFacts, retryableErrorPatterns
|
|
|
287
326
|
if (explicitlyRetryable) return true;
|
|
288
327
|
const status = failure.status;
|
|
289
328
|
if (status !== undefined && (status === 401 || status === 403)) return false;
|
|
329
|
+
// Malformed model output can echo tool arguments that look like auth/quota errors.
|
|
330
|
+
if (failure.code === 'MALFORMED_RESPONSE') return true;
|
|
290
331
|
const permanent =
|
|
291
332
|
/auth|unauthor|forbidden|credential|api[_-]?key|permission/i.test(haystack) ||
|
|
292
333
|
/insufficient.*(balance|quota)|billing|payment|quota.*exceeded.*(?!retry)/i.test(haystack) ||
|
|
@@ -306,6 +347,16 @@ export function isTransientAgentError(message: string): boolean {
|
|
|
306
347
|
return /network|timeout|timed ?out|econn|etimedout|socket|5\d\d|\b429\b|upstream|temporar/i.test(message);
|
|
307
348
|
}
|
|
308
349
|
|
|
350
|
+
/**
|
|
351
|
+
* 失败是否属于连接层(断网/DNS/连接被拒/传输超时)。只有这类失败值得先做连通性
|
|
352
|
+
* 检测: 断网时续跑必然再失败一次, 白白消耗连续上限。5xx/429 等服务端错误不在此列。
|
|
353
|
+
*/
|
|
354
|
+
export function isNetworkFailure(failure: FailureFacts): boolean {
|
|
355
|
+
if (/^(TRANSPORT|TIMEOUT|NETWORK|E(CONN|NET|HOST|AI_|NOTFOUND|TIMEDOUT|PIPE))/i.test(failure.code)) return true;
|
|
356
|
+
return /network|fetch failed|econn|enotfound|eai_again|etimedout|enetunreach|ehostunreach|enetdown|getaddrinfo|socket hang up|offline|could not reach|connection (reset|refused|closed)|timed? ?out/i
|
|
357
|
+
.test(failure.message);
|
|
358
|
+
}
|
|
359
|
+
|
|
309
360
|
/** 通知上的一个操作按钮(action 标识 + 显示文案)。 */
|
|
310
361
|
export interface NotifyAction {
|
|
311
362
|
/** 稳定动作标识, 点击时经 onAction 回调传出。 */
|
|
@@ -918,6 +969,18 @@ export interface SessionState {
|
|
|
918
969
|
loopRetryTimer: ReturnType<typeof setTimeout> | undefined;
|
|
919
970
|
/** 冷却期恢复的延迟定时器(等到冷却结束再 schedule, 而不是丢弃这次恢复)。 */
|
|
920
971
|
cooldownRetryTimer: ReturnType<typeof setTimeout> | undefined;
|
|
972
|
+
/** 断网挂起: 进行中的连通性检测令牌(取消时置空, 迟到的检测结果据此作废)。 */
|
|
973
|
+
offlineWait: object | undefined;
|
|
974
|
+
/** 断网挂起: 下一次连通性复检的定时器。 */
|
|
975
|
+
offlineTimer: ReturnType<typeof setTimeout> | undefined;
|
|
976
|
+
/** 本次断网挂起开始的时间; 0 = 未挂起(只在挂起开始/结束时各记一次日志)。 */
|
|
977
|
+
offlineSince: number;
|
|
978
|
+
/** 自主循环已续跑的轮数(用户发消息或重新开启循环时清零)。 */
|
|
979
|
+
loopIterations: number;
|
|
980
|
+
/** 本轮循环上限提示已发出(每次触顶只提示一次)。 */
|
|
981
|
+
loopCapNotified: boolean;
|
|
982
|
+
/** 上次观察到的循环开关; 由关到开时清零轮数。 */
|
|
983
|
+
loopEnabled: boolean | undefined;
|
|
921
984
|
}
|
|
922
985
|
|
|
923
986
|
export const freshState = (): SessionState => ({
|
|
@@ -946,6 +1009,12 @@ export const freshState = (): SessionState => ({
|
|
|
946
1009
|
loopFired: false,
|
|
947
1010
|
loopRetryTimer: undefined,
|
|
948
1011
|
cooldownRetryTimer: undefined,
|
|
1012
|
+
offlineWait: undefined,
|
|
1013
|
+
offlineTimer: undefined,
|
|
1014
|
+
offlineSince: 0,
|
|
1015
|
+
loopIterations: 0,
|
|
1016
|
+
loopCapNotified: false,
|
|
1017
|
+
loopEnabled: undefined,
|
|
949
1018
|
});
|
|
950
1019
|
|
|
951
1020
|
|
|
@@ -981,7 +1050,7 @@ export function forgetPendingEcho(state: SessionState, messageId: string): void
|
|
|
981
1050
|
export function isOurEcho(state: SessionState, event: SessionEvent): boolean {
|
|
982
1051
|
if (event.type !== 'user/message') return false;
|
|
983
1052
|
const message = event.data;
|
|
984
|
-
if (message.source.kind !== 'user') return false;
|
|
1053
|
+
if (message.source.kind !== 'user' && message.source.kind !== AUTO_CONTINUE_SOURCE_KIND) return false;
|
|
985
1054
|
if (state.pendingEchoMessageIds.size === 0) return false;
|
|
986
1055
|
const now = Date.now();
|
|
987
1056
|
prunePendingEchoMessageIds(state, now);
|