dsh-client-auto-continue 0.11.2 → 0.11.4
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/lib/client.js.map +2 -2
- package/lib/index.js +457 -119
- package/lib/types/host/engine.d.ts +3 -3
- package/lib/types/shared/core.d.ts +83 -27
- package/package.json +1 -1
- package/src/host/engine.ts +189 -119
- package/src/shared/core.ts +436 -45
|
@@ -21,7 +21,7 @@ export interface HostNotice {
|
|
|
21
21
|
title: string;
|
|
22
22
|
body: string;
|
|
23
23
|
/** 会话 id(通知按钮「立即续跑 / 暂停该会话」作用于它)。 */
|
|
24
|
-
sessionId
|
|
24
|
+
sessionId: SessionId;
|
|
25
25
|
actions: NotifyAction[];
|
|
26
26
|
/** 产生时间。 */
|
|
27
27
|
at: number;
|
|
@@ -74,8 +74,8 @@ export declare class AutoContinueRunner {
|
|
|
74
74
|
private checkLoop;
|
|
75
75
|
/**
|
|
76
76
|
* 打断运行中的回合: cancel(带来源标记)+ 进冷却。
|
|
77
|
-
*
|
|
78
|
-
*
|
|
77
|
+
* 只有随后持久化的 turn/end 精确携带专属 hook cause 时,
|
|
78
|
+
* 才会用 loopText 重启回合——DSH 的 first-cause 语义保证用户 Stop 优先。
|
|
79
79
|
*/
|
|
80
80
|
private interruptLoop;
|
|
81
81
|
private onSessionEvent;
|
|
@@ -152,21 +152,92 @@ export interface ToolResultFacts {
|
|
|
152
152
|
ok: boolean;
|
|
153
153
|
/** 工具输出的文本摘要(截断)。 */
|
|
154
154
|
excerpt: string;
|
|
155
|
+
/** 完整模型可见内容 + 错误状态的定长稳定指纹(loop guard 比较用)。 */
|
|
156
|
+
identity: string;
|
|
155
157
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
+
interface ToolResultData {
|
|
159
|
+
turn?: unknown;
|
|
160
|
+
step?: unknown;
|
|
158
161
|
error?: {
|
|
159
162
|
name?: string;
|
|
160
163
|
code?: string;
|
|
161
164
|
};
|
|
162
165
|
message?: {
|
|
166
|
+
source?: {
|
|
167
|
+
kind?: string;
|
|
168
|
+
callId?: unknown;
|
|
169
|
+
};
|
|
163
170
|
content?: Array<{
|
|
164
171
|
type?: string;
|
|
172
|
+
toolCallId?: unknown;
|
|
165
173
|
content?: unknown;
|
|
166
174
|
isError?: boolean;
|
|
167
175
|
}>;
|
|
168
176
|
};
|
|
169
|
-
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* 取工具结果的关联 id。新版 DSH 的权威位置是 message.source.callId,
|
|
180
|
+
* 同时接受模型可见 block 上的 toolCallId;两者冲突时宁可忽略,不猜测配对。
|
|
181
|
+
*/
|
|
182
|
+
export declare function toolResultCallId(data: ToolResultData): string | undefined;
|
|
183
|
+
/** 从 tool/result 事件载荷提取成功与否与文本摘要。 */
|
|
184
|
+
export declare function toolResultFacts(data: ToolResultData): ToolResultFacts;
|
|
185
|
+
/** loop guard 在后续 step 边界确认的连续重复信号。 */
|
|
186
|
+
export interface ToolRepeatSignal {
|
|
187
|
+
tool: string;
|
|
188
|
+
count: number;
|
|
189
|
+
}
|
|
190
|
+
export type ToolGuardState = {
|
|
191
|
+
kind: 'none';
|
|
192
|
+
} | {
|
|
193
|
+
kind: 'pending';
|
|
194
|
+
tool: string;
|
|
195
|
+
} | {
|
|
196
|
+
kind: 'done';
|
|
197
|
+
tool: string;
|
|
198
|
+
result: string;
|
|
199
|
+
} | {
|
|
200
|
+
kind: 'failed';
|
|
201
|
+
tool: string;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* 每个会话的工具调用关联器。
|
|
205
|
+
*
|
|
206
|
+
* 集中封装事件关联、step 边界确认、护栏读取与重置。内部按 callId 配对,
|
|
207
|
+
* 乱序结果先缓存、再按调用顺序推进 loop 计数。队列和去重 id 都有硬上限;
|
|
208
|
+
* 超限或载荷无法关联时会打断重复计数,宁可漏报也不误杀健康回合。
|
|
209
|
+
*/
|
|
210
|
+
export declare class ToolInvocationTracker {
|
|
211
|
+
private readonly pendingById;
|
|
212
|
+
private readonly pendingInOrder;
|
|
213
|
+
private readonly seenCalls;
|
|
214
|
+
private readonly seenInOrder;
|
|
215
|
+
private latest;
|
|
216
|
+
private run;
|
|
217
|
+
private repeatSignal;
|
|
218
|
+
private lastEventSeq;
|
|
219
|
+
reset(): void;
|
|
220
|
+
/** 新回合边界:清空工具态,同时把重放水位推进到 turn/start。 */
|
|
221
|
+
startTurn(seq: number): void;
|
|
222
|
+
/** 回合已结束:保留最后一次调用的护栏,丢弃不再可用的 loop 关联态。 */
|
|
223
|
+
resetRepeat(): void;
|
|
224
|
+
recordCall(event: SessionEvent<'tool/call'>): boolean;
|
|
225
|
+
recordResult(event: SessionEvent<'tool/result'>): ToolRepeatSignal | undefined;
|
|
226
|
+
guard(): ToolGuardState;
|
|
227
|
+
lastTool(): string | undefined;
|
|
228
|
+
/** 下一模型 step 是稳定边界;此前 replacement/新调用会先清除候选。 */
|
|
229
|
+
confirmRepeatAtStep(seq: number): ToolRepeatSignal | undefined;
|
|
230
|
+
/** 非工具 surface range replacement(如 compaction summary)同样终止旧工具证据。 */
|
|
231
|
+
recordSurfaceReplacement(seq: number): void;
|
|
232
|
+
restore(events: readonly SessionEvent[], untilSeq: number): void;
|
|
233
|
+
private acceptEventSeq;
|
|
234
|
+
private breakCorrelation;
|
|
235
|
+
private invalidateRunHistory;
|
|
236
|
+
private trim;
|
|
237
|
+
private drainCompleted;
|
|
238
|
+
private advanceRun;
|
|
239
|
+
private refreshRepeatSignal;
|
|
240
|
+
}
|
|
170
241
|
/** 自适应退避: 同一会话连续失败时的有效冷却间隔。 */
|
|
171
242
|
export declare function effectiveCooldown(consecutive: number, base: number, factor: number, max: number): number;
|
|
172
243
|
export declare function sleep(ms: number): Promise<void>;
|
|
@@ -196,12 +267,10 @@ export declare function emptyDayStats(): DayStats;
|
|
|
196
267
|
export interface SessionState {
|
|
197
268
|
/** 连续自动「继续」次数; 成功回合或用户手动介入后归零。 */
|
|
198
269
|
consecutive: number;
|
|
199
|
-
/** 上次自动「继续」时间戳。 */
|
|
200
|
-
lastAutoAt: number;
|
|
201
270
|
/** 上次自动「继续」尝试(成功或失败)时间戳; 防止失败场景下的快速重试循环。 */
|
|
202
271
|
lastAttemptAt: number;
|
|
203
|
-
/**
|
|
204
|
-
|
|
272
|
+
/** 尚未回显到会话事件流的自动发送消息 ID。 */
|
|
273
|
+
pendingEchoMessageIds: Map<string, number>;
|
|
205
274
|
/** 宽限期定时器(进行中的待发送)。 */
|
|
206
275
|
pendingTimer: ReturnType<typeof setTimeout> | undefined;
|
|
207
276
|
/** 宿主权威 running 位(来自 host/session-status 与回合事件)。 */
|
|
@@ -214,10 +283,8 @@ export interface SessionState {
|
|
|
214
283
|
lastFailure: FailureFacts | undefined;
|
|
215
284
|
/** 最近一次失败的发生时间(模板 {elapsed} 与恢复统计用)。 */
|
|
216
285
|
lastFailureAt: number;
|
|
217
|
-
/**
|
|
218
|
-
|
|
219
|
-
/** 上一步工具调用的结果状态: 'pending' = 已发起未见结果(可能已部分执行)。 */
|
|
220
|
-
lastToolResult: 'pending' | ToolResultFacts | undefined;
|
|
286
|
+
/** callId 精确配对的工具调用、幂等护栏与 loop 重复态。 */
|
|
287
|
+
tools: ToolInvocationTracker;
|
|
221
288
|
/** 失败回合的编号(模板 {turn})。 */
|
|
222
289
|
lastTurn: number | undefined;
|
|
223
290
|
/** 我们最近一次自动发送的时间戳; 0 = 没有待确认的恢复。 */
|
|
@@ -230,29 +297,18 @@ export interface SessionState {
|
|
|
230
297
|
lastAssistantText: string;
|
|
231
298
|
/** 连续相同文本消息数(最强空转信号, 不限长度)。 */
|
|
232
299
|
sameTextRun: number;
|
|
233
|
-
/**
|
|
234
|
-
* 工具重复信号(loop guard 信号 2: 死循环)。
|
|
235
|
-
* 只有「同工具 + 同参数 + 同结果」的连续调用才累计; 参数或结果有变化视为有进展, 计数重置。
|
|
236
|
-
*/
|
|
237
|
-
toolRun: {
|
|
238
|
-
/** 工具名 + 参数(用于判定是否同一调用)。 */
|
|
239
|
-
key: string;
|
|
240
|
-
/** 连续相同调用数(结果确认后更新)。 */
|
|
241
|
-
count: number;
|
|
242
|
-
/** 上次该调用的结果摘要(比较用)。 */
|
|
243
|
-
lastResult: string | undefined;
|
|
244
|
-
/** 本次调用等待结果确认。 */
|
|
245
|
-
waiting: boolean;
|
|
246
|
-
} | undefined;
|
|
247
300
|
/** 本回合已触发过 loop guard(防重复打断)。 */
|
|
248
301
|
loopFired: boolean;
|
|
249
302
|
/** loop 重启的延迟定时器(冷却结束后再 schedule)。 */
|
|
250
303
|
loopRetryTimer: ReturnType<typeof setTimeout> | undefined;
|
|
251
|
-
/** 我们主动 cancel 过本回合(区分用户停止)。 */
|
|
252
|
-
loopCancelled: boolean;
|
|
253
304
|
}
|
|
254
305
|
export declare const freshState: () => SessionState;
|
|
255
306
|
export declare const RECOVERY_WINDOW_MS: number;
|
|
256
307
|
export declare const ECHO_WINDOW_MS: number;
|
|
308
|
+
/** Track an identified plugin message before handing it to the host queue. */
|
|
309
|
+
export declare function trackPendingEcho(state: SessionState, messageId: string): void;
|
|
310
|
+
/** Roll back tracking when the host rejects a queued message. */
|
|
311
|
+
export declare function forgetPendingEcho(state: SessionState, messageId: string): void;
|
|
312
|
+
/** Match and consume one plugin-owned `user/message` event by stable message ID. */
|
|
257
313
|
export declare function isOurEcho(state: SessionState, event: SessionEvent): boolean;
|
|
258
314
|
export {};
|
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.11.
|
|
4
|
+
"version": "0.11.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/types/index.d.ts",
|