@demicodes/agent 0.9.1 → 0.10.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/dist/client-entry.d.mts +2 -2
- package/dist/client-entry.mjs +1 -1
- package/dist/index.d.mts +47 -4
- package/dist/index.mjs +111 -14
- package/dist/stdio-transport.d.mts +1 -1
- package/dist/{transport-CD53ZgRO.d.mts → transport-BZwi2YZL.d.mts} +5 -0
- package/dist/{websocket-transport-DrsdY12Z.d.mts → websocket-transport-CZpGt4Py.d.mts} +12 -2
- package/dist/{websocket-transport-D8o_MJP4.mjs → websocket-transport-os0mfcLi.mjs} +11 -1
- package/package.json +5 -5
package/dist/client-entry.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as AgentMetadata, d as TranscriptPatch, l as ServerFrame, n as AgentServerTransport, o as ClientFrame, r as AgentTransport, s as ClientSessionEvent, t as AgentClientTransport, u as ShellCommandStatusLike } from "./transport-
|
|
2
|
-
import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-
|
|
1
|
+
import { b as AgentMetadata, d as TranscriptPatch, l as ServerFrame, n as AgentServerTransport, o as ClientFrame, r as AgentTransport, s as ClientSessionEvent, t as AgentClientTransport, u as ShellCommandStatusLike } from "./transport-BZwi2YZL.mjs";
|
|
2
|
+
import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-CZpGt4Py.mjs";
|
|
3
3
|
import { ProviderSelection } from "@demicodes/provider";
|
|
4
4
|
export { type AgentActionOptions, AgentClient, type AgentClientListener, type AgentClientTransport, type AgentMetadata, type AgentServerTransport, type AgentTransport, type ClientFrame, type ClientSessionEvent, type JsonWebSocket, type ProviderSelection, type ServerFrame, type ShellCommandStatusLike, type TranscriptPatch, createWebSocketClientTransport, createWebSocketServerTransport };
|
package/dist/client-entry.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createWebSocketServerTransport, r as AgentClient, t as createWebSocketClientTransport } from "./websocket-transport-
|
|
1
|
+
import { n as createWebSocketServerTransport, r as AgentClient, t as createWebSocketClientTransport } from "./websocket-transport-os0mfcLi.mjs";
|
|
2
2
|
export { AgentClient, createWebSocketClientTransport, createWebSocketServerTransport };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
|
-
import { A as AgentToolContext, B as estimateTranscriptBlockTokens, C as AgentSessionCheckpoint, D as AgentSessionStore, E as AgentSessionRestoreParams, F as SessionEventListener, G as retryDelayMs, H as TurnRetryPolicy, I as CompactionWindow, L as DrainedTranscriptPatches, M as AgentToolInvokeResult, N as ExternalMutationReservation, O as AgentSystemPromptContext, P as SessionEvent, R as TranscriptLog, S as AgentReferenceResolveContext, T as AgentSessionParams, U as isRetryableCode, V as DEFAULT_TURN_RETRY_POLICY, W as resolveRetryPolicy, _ as AgentHarnessRuntime, a as createInProcessTransportPair, b as AgentMetadata, c as ConversationSummary, d as TranscriptPatch, f as AbortResult, g as AgentHarnessContext, h as AgentHarness, i as InProcessTransportPair, j as AgentToolInvokeContext, k as AgentTool, l as ServerFrame, m as AgentDisposeContext, n as AgentServerTransport, o as ClientFrame, p as AbortTarget, r as AgentTransport, s as ClientSessionEvent, t as AgentClientTransport, u as ShellCommandStatusLike, v as AgentHostContext, w as AgentSessionOptions, x as AgentPromptContext, y as AgentLifecycleEvent, z as TranscriptOptions } from "./transport-
|
|
2
|
-
import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-
|
|
1
|
+
import { A as AgentToolContext, B as estimateTranscriptBlockTokens, C as AgentSessionCheckpoint, D as AgentSessionStore, E as AgentSessionRestoreParams, F as SessionEventListener, G as retryDelayMs, H as TurnRetryPolicy, I as CompactionWindow, L as DrainedTranscriptPatches, M as AgentToolInvokeResult, N as ExternalMutationReservation, O as AgentSystemPromptContext, P as SessionEvent, R as TranscriptLog, S as AgentReferenceResolveContext, T as AgentSessionParams, U as isRetryableCode, V as DEFAULT_TURN_RETRY_POLICY, W as resolveRetryPolicy, _ as AgentHarnessRuntime, a as createInProcessTransportPair, b as AgentMetadata, c as ConversationSummary, d as TranscriptPatch, f as AbortResult, g as AgentHarnessContext, h as AgentHarness, i as InProcessTransportPair, j as AgentToolInvokeContext, k as AgentTool, l as ServerFrame, m as AgentDisposeContext, n as AgentServerTransport, o as ClientFrame, p as AbortTarget, r as AgentTransport, s as ClientSessionEvent, t as AgentClientTransport, u as ShellCommandStatusLike, v as AgentHostContext, w as AgentSessionOptions, x as AgentPromptContext, y as AgentLifecycleEvent, z as TranscriptOptions } from "./transport-BZwi2YZL.mjs";
|
|
2
|
+
import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-CZpGt4Py.mjs";
|
|
3
3
|
import { BashAuditEvent, BashEnvironment, BashEnvironmentOptions, CommandMetadataRecord, Host, ShellCommandStatus, ShellOutputChunk } from "@demicodes/shell";
|
|
4
4
|
import { AgentProvider, Provider } from "@demicodes/provider";
|
|
5
5
|
import { Block, Model, ModelMediaKind, ModelSelection, ProviderErrorDiagnostics, QueuedMessage, SessionPhase, UserContentBlock } from "@demicodes/core";
|
|
6
|
+
//#region src/recovery.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Where re-inference must restart after a turn failed to finish.
|
|
9
|
+
*
|
|
10
|
+
* `cut` is the index from which blocks are discardable; `isFullRerun` is true when
|
|
11
|
+
* that reaches all the way back to the user turn, meaning the turn produced nothing
|
|
12
|
+
* and can simply be run again.
|
|
13
|
+
*/
|
|
14
|
+
interface ResumePoint {
|
|
15
|
+
cut: number;
|
|
16
|
+
isFullRerun: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Finds how far back an unfinished turn can be unwound before re-inferring.
|
|
20
|
+
*
|
|
21
|
+
* This is the single decision behind both recovery paths. A transient provider
|
|
22
|
+
* failure and a human asking to continue a dead round ask the same question — how
|
|
23
|
+
* do we finish this turn — and the answer depends only on what has already left
|
|
24
|
+
* the process, never on which of the two asked or on how the turn died.
|
|
25
|
+
*/
|
|
26
|
+
declare function findResumePoint(blocks: readonly Block[]): ResumePoint;
|
|
27
|
+
//#endregion
|
|
6
28
|
//#region src/provider-stream-error.d.ts
|
|
7
29
|
/** Error carrying a provider stream's normalized code and bounded diagnostics. */
|
|
8
30
|
declare class ProviderStreamError extends Error {
|
|
@@ -62,10 +84,24 @@ declare class AgentSession<State> {
|
|
|
62
84
|
id?: string;
|
|
63
85
|
metadata?: AgentMetadata;
|
|
64
86
|
}): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Discards the whole latest turn and runs it again from the user's input.
|
|
89
|
+
*
|
|
90
|
+
* This is "regenerate": it is only meaningful when the caller wants a different
|
|
91
|
+
* answer to the same question and knows the turn's effects can be repeated. It is
|
|
92
|
+
* NOT the way to recover a failed turn — use `resume`, which unwinds only as far
|
|
93
|
+
* as is safe.
|
|
94
|
+
*/
|
|
65
95
|
retry(options?: {
|
|
66
96
|
metadata?: AgentMetadata;
|
|
67
97
|
}): Promise<void>;
|
|
68
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Finishes a turn that did not finish, after an abort or a terminal provider
|
|
100
|
+
* error. Unwinds to the turn's resume point — dropping the failed attempt's
|
|
101
|
+
* leftovers, keeping everything that already left the process — and re-infers
|
|
102
|
+
* from there. Callers do not choose the granularity and do not need to know how
|
|
103
|
+
* the turn died.
|
|
104
|
+
*/
|
|
69
105
|
resume(options?: {
|
|
70
106
|
metadata?: AgentMetadata;
|
|
71
107
|
}): Promise<void>;
|
|
@@ -135,6 +171,13 @@ declare class AgentSession<State> {
|
|
|
135
171
|
private executeSend;
|
|
136
172
|
private resolveReferences;
|
|
137
173
|
private executeRetry;
|
|
174
|
+
/**
|
|
175
|
+
* Finishes an unfinished turn. Unwinds to its resume point — dropping the failed
|
|
176
|
+
* attempt's leftovers, keeping everything that already left the process — and
|
|
177
|
+
* re-infers from there. When the whole turn turns out to be discardable this is
|
|
178
|
+
* a plain rerun, which spares the model a continuation boundary attached to a
|
|
179
|
+
* stub of its own aborted output.
|
|
180
|
+
*/
|
|
138
181
|
private executeResume;
|
|
139
182
|
private providerEvents;
|
|
140
183
|
private promptContext;
|
|
@@ -322,4 +365,4 @@ interface ShellToolView {
|
|
|
322
365
|
declare function finishShellToolResult<State>(environment: BashEnvironment, result: ShellCommandStatus, ctx: AgentToolInvokeContext<State>): Promise<AgentToolInvokeResult>;
|
|
323
366
|
declare function shellCommandHandleRequired(result: ShellCommandStatus, budgetTokens: number): boolean;
|
|
324
367
|
//#endregion
|
|
325
|
-
export { AbortResult, AbortTarget, ActiveTurnPhase, AgentActionOptions, AgentClient, AgentClientListener, AgentClientTransport, AgentDisposeContext, AgentHarness, AgentHarnessContext, AgentHarnessRuntime, AgentHostContext, AgentLifecycleEvent, AgentMetadata, AgentPromptContext, AgentReferenceResolveContext, AgentServer, AgentServerOptions, AgentServerSessionOptions, AgentServerTransport, AgentSession, AgentSessionCheckpoint, AgentSessionOptions, AgentSessionParams, AgentSessionRestoreParams, AgentSessionStore, AgentSystemPromptContext, AgentTool, AgentToolContext, AgentToolInvokeContext, AgentToolInvokeResult, AgentTransport, AgentTransportBinding, ClientFrame, ClientSessionEvent, CompactionWindow, ConversationSummary, DEFAULT_MAX_MEDIA_BYTES, DEFAULT_TURN_RETRY_POLICY, DrainedTranscriptPatches, ExternalMutationReservation, InProcessTransportPair, JsonWebSocket, PrepareShell, PrepareShellContext, ProviderStreamError, RunCommandLineCommandNotRegisteredError, RunCommandLineOptions, RunCommandLineResult, RunCommandLineShellNotFoundError, RunCommandLineTimeoutError, SHELL_VIEW_MAX_CHARS, ServerFrame, SessionEvent, SessionEventListener, ShellCommandStatusLike, ShellToolResultOptions, ShellToolView, StandardAgentToolOptions, TranscriptLog, TranscriptOptions, TranscriptPatch, TurnRetryPolicy, applyTranscriptPatches, cloneBlocks, createInProcessTransportPair, createStandardAgentTools, createWebSocketClientTransport, createWebSocketServerTransport, estimateTranscriptBlockTokens, finishShellToolResult, isContextLengthExceeded, isRetryableCode, resolveRetryPolicy, retryDelayMs, shellCommandHandleRequired, shellPreviewBudgetTokens, toShellToolResult };
|
|
368
|
+
export { AbortResult, AbortTarget, ActiveTurnPhase, AgentActionOptions, AgentClient, AgentClientListener, AgentClientTransport, AgentDisposeContext, AgentHarness, AgentHarnessContext, AgentHarnessRuntime, AgentHostContext, AgentLifecycleEvent, AgentMetadata, AgentPromptContext, AgentReferenceResolveContext, AgentServer, AgentServerOptions, AgentServerSessionOptions, AgentServerTransport, AgentSession, AgentSessionCheckpoint, AgentSessionOptions, AgentSessionParams, AgentSessionRestoreParams, AgentSessionStore, AgentSystemPromptContext, AgentTool, AgentToolContext, AgentToolInvokeContext, AgentToolInvokeResult, AgentTransport, AgentTransportBinding, ClientFrame, ClientSessionEvent, CompactionWindow, ConversationSummary, DEFAULT_MAX_MEDIA_BYTES, DEFAULT_TURN_RETRY_POLICY, DrainedTranscriptPatches, ExternalMutationReservation, InProcessTransportPair, JsonWebSocket, PrepareShell, PrepareShellContext, ProviderStreamError, ResumePoint, RunCommandLineCommandNotRegisteredError, RunCommandLineOptions, RunCommandLineResult, RunCommandLineShellNotFoundError, RunCommandLineTimeoutError, SHELL_VIEW_MAX_CHARS, ServerFrame, SessionEvent, SessionEventListener, ShellCommandStatusLike, ShellToolResultOptions, ShellToolView, StandardAgentToolOptions, TranscriptLog, TranscriptOptions, TranscriptPatch, TurnRetryPolicy, applyTranscriptPatches, cloneBlocks, createInProcessTransportPair, createStandardAgentTools, createWebSocketClientTransport, createWebSocketServerTransport, estimateTranscriptBlockTokens, findResumePoint, finishShellToolResult, isContextLengthExceeded, isRetryableCode, resolveRetryPolicy, retryDelayMs, shellCommandHandleRequired, shellPreviewBudgetTokens, toShellToolResult };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as cloneBlocks, i as applyTranscriptPatches, n as createWebSocketServerTransport, o as ProviderStreamError, r as AgentClient, s as isContextLengthExceeded, t as createWebSocketClientTransport } from "./websocket-transport-
|
|
1
|
+
import { a as cloneBlocks, i as applyTranscriptPatches, n as createWebSocketServerTransport, o as ProviderStreamError, r as AgentClient, s as isContextLengthExceeded, t as createWebSocketClientTransport } from "./websocket-transport-os0mfcLi.mjs";
|
|
2
2
|
import { AbortError, abortable, asError, asRecord, asString, bytesToBase64, createId, delay, isAbortError, isRecord, noop, parseJsonOrString, safeJsonStringify, throwIfAborted, truncate } from "@demicodes/utils";
|
|
3
3
|
import { BashEnvironment, CommandRegistry, MAX_TIMEOUT_MS, heredocDelimiter, shellQuote } from "@demicodes/shell";
|
|
4
4
|
import { providerRuntime } from "@demicodes/provider";
|
|
@@ -149,6 +149,22 @@ var TranscriptLog = class {
|
|
|
149
149
|
}
|
|
150
150
|
return null;
|
|
151
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Drops the blocks from `index` onward, returning true when anything went.
|
|
154
|
+
* Used to unwind a turn to its resume point before re-inferring.
|
|
155
|
+
*/
|
|
156
|
+
truncateFrom(index) {
|
|
157
|
+
let changed = false;
|
|
158
|
+
for (let i = this.blocks.length - 1; i >= index; i -= 1) {
|
|
159
|
+
this.blocks.splice(i, 1);
|
|
160
|
+
this.record({
|
|
161
|
+
op: "remove",
|
|
162
|
+
path: ["blocks", i]
|
|
163
|
+
});
|
|
164
|
+
changed = true;
|
|
165
|
+
}
|
|
166
|
+
return changed;
|
|
167
|
+
}
|
|
152
168
|
applyProviderEvent(model, event) {
|
|
153
169
|
switch (event.type) {
|
|
154
170
|
case "thinking_start": return this.appendThinking(model, "");
|
|
@@ -604,6 +620,57 @@ function retryDelayMs(policy, attempt, retryAfterMs) {
|
|
|
604
620
|
return Math.floor(Math.random() * ceiling);
|
|
605
621
|
}
|
|
606
622
|
//#endregion
|
|
623
|
+
//#region src/recovery.ts
|
|
624
|
+
/**
|
|
625
|
+
* Whether a block is a leftover of the failed attempt that nobody can have acted on.
|
|
626
|
+
*
|
|
627
|
+
* Everything else has to be assumed acted on. Transcript blocks stream outward as
|
|
628
|
+
* they are produced and products turn them into effects that cannot be recalled —
|
|
629
|
+
* rendering them, posting them to a chat, executing the tool they describe. A tool
|
|
630
|
+
* call counts whatever its status: one still marked executing outlived the process
|
|
631
|
+
* that was running it, so whether its effect landed is unknown, and unknown has to
|
|
632
|
+
* be treated as landed. An abort block is history the user created, not a leftover.
|
|
633
|
+
*
|
|
634
|
+
* Thinking is the interesting case: products display it, but nothing keys off it and
|
|
635
|
+
* a rerun simply reasons again, so it is discardable. A `response` is not — it
|
|
636
|
+
* records a provider request that did complete, and its usage anchors the context
|
|
637
|
+
* estimate for everything after it.
|
|
638
|
+
*/
|
|
639
|
+
function isDiscardableLeftover(block) {
|
|
640
|
+
switch (block.type) {
|
|
641
|
+
case "thinking":
|
|
642
|
+
case "redacted_thinking":
|
|
643
|
+
case "error": return true;
|
|
644
|
+
case "text": return block.text.trim().length === 0;
|
|
645
|
+
default: return false;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Finds how far back an unfinished turn can be unwound before re-inferring.
|
|
650
|
+
*
|
|
651
|
+
* This is the single decision behind both recovery paths. A transient provider
|
|
652
|
+
* failure and a human asking to continue a dead round ask the same question — how
|
|
653
|
+
* do we finish this turn — and the answer depends only on what has already left
|
|
654
|
+
* the process, never on which of the two asked or on how the turn died.
|
|
655
|
+
*/
|
|
656
|
+
function findResumePoint(blocks) {
|
|
657
|
+
for (let i = blocks.length - 1; i >= 0; i -= 1) {
|
|
658
|
+
const block = blocks[i];
|
|
659
|
+
if (block.type === "user") return {
|
|
660
|
+
cut: i + 1,
|
|
661
|
+
isFullRerun: true
|
|
662
|
+
};
|
|
663
|
+
if (!isDiscardableLeftover(block)) return {
|
|
664
|
+
cut: i + 1,
|
|
665
|
+
isFullRerun: false
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
return {
|
|
669
|
+
cut: blocks.length,
|
|
670
|
+
isFullRerun: false
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
//#endregion
|
|
607
674
|
//#region src/yield-scheduler.ts
|
|
608
675
|
/**
|
|
609
676
|
* Tracks scheduled `yield` wakeups and their timers. This class owns only the
|
|
@@ -944,8 +1011,9 @@ var ProviderTurnLoop = class {
|
|
|
944
1011
|
}
|
|
945
1012
|
/**
|
|
946
1013
|
* Streams one provider response, silently retrying transient failures
|
|
947
|
-
* (rate_limit/overloaded) with backoff
|
|
948
|
-
*
|
|
1014
|
+
* (rate_limit/overloaded) with backoff. A retry is taken only when everything
|
|
1015
|
+
* the failed attempt put in the transcript can be unwound — the same question
|
|
1016
|
+
* `resume` asks, so an automatic recovery and a human-driven one never disagree.
|
|
949
1017
|
* The turn stays in provider_streaming across backoff waits so steers keep
|
|
950
1018
|
* queueing instead of being rejected.
|
|
951
1019
|
*/
|
|
@@ -971,9 +1039,9 @@ var ProviderTurnLoop = class {
|
|
|
971
1039
|
}
|
|
972
1040
|
async streamAttempt(attempt, policy) {
|
|
973
1041
|
const request = this.buildInferenceRequest();
|
|
1042
|
+
const attemptStart = this.host.transcript.blocks.length;
|
|
974
1043
|
const run = this.host.provider.run(request);
|
|
975
1044
|
let shouldAutoRecover = false;
|
|
976
|
-
let produced = false;
|
|
977
1045
|
let hasPendingThinkingStart = false;
|
|
978
1046
|
this.host.setActiveProviderRun(run);
|
|
979
1047
|
try {
|
|
@@ -994,13 +1062,16 @@ var ProviderTurnLoop = class {
|
|
|
994
1062
|
...event,
|
|
995
1063
|
diagnostics
|
|
996
1064
|
};
|
|
997
|
-
if (
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1065
|
+
if (findResumePoint(this.host.transcript.blocks).cut <= attemptStart && attempt < policy.maxAttempts && isRetryableCode(policy, errorEvent.code)) {
|
|
1066
|
+
if (this.host.transcript.truncateFrom(attemptStart)) await this.host.commitTranscript();
|
|
1067
|
+
return {
|
|
1068
|
+
type: "retry",
|
|
1069
|
+
attempt,
|
|
1070
|
+
delayMs: retryDelayMs(policy, attempt, errorEvent.retryAfterMs ?? null),
|
|
1071
|
+
code: errorEvent.code,
|
|
1072
|
+
diagnostics: errorEvent.diagnostics
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1004
1075
|
await this.applyProviderEvent(errorEvent);
|
|
1005
1076
|
throw new ProviderStreamError(errorEvent.message, errorEvent.code, errorEvent.diagnostics);
|
|
1006
1077
|
}
|
|
@@ -1009,7 +1080,6 @@ var ProviderTurnLoop = class {
|
|
|
1009
1080
|
hasPendingThinkingStart = false;
|
|
1010
1081
|
}
|
|
1011
1082
|
await this.applyProviderEvent(event);
|
|
1012
|
-
produced = true;
|
|
1013
1083
|
if (event.type === "response" && this.isUsageNearLimit(event.usage)) shouldAutoRecover = true;
|
|
1014
1084
|
}
|
|
1015
1085
|
} finally {
|
|
@@ -1337,6 +1407,14 @@ var AgentSession = class AgentSession {
|
|
|
1337
1407
|
reject: noop
|
|
1338
1408
|
});
|
|
1339
1409
|
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Discards the whole latest turn and runs it again from the user's input.
|
|
1412
|
+
*
|
|
1413
|
+
* This is "regenerate": it is only meaningful when the caller wants a different
|
|
1414
|
+
* answer to the same question and knows the turn's effects can be repeated. It is
|
|
1415
|
+
* NOT the way to recover a failed turn — use `resume`, which unwinds only as far
|
|
1416
|
+
* as is safe.
|
|
1417
|
+
*/
|
|
1340
1418
|
retry(options = {}) {
|
|
1341
1419
|
return this.enqueue({
|
|
1342
1420
|
type: "retry",
|
|
@@ -1345,7 +1423,13 @@ var AgentSession = class AgentSession {
|
|
|
1345
1423
|
reject: noop
|
|
1346
1424
|
});
|
|
1347
1425
|
}
|
|
1348
|
-
/**
|
|
1426
|
+
/**
|
|
1427
|
+
* Finishes a turn that did not finish, after an abort or a terminal provider
|
|
1428
|
+
* error. Unwinds to the turn's resume point — dropping the failed attempt's
|
|
1429
|
+
* leftovers, keeping everything that already left the process — and re-infers
|
|
1430
|
+
* from there. Callers do not choose the granularity and do not need to know how
|
|
1431
|
+
* the turn died.
|
|
1432
|
+
*/
|
|
1349
1433
|
resume(options = {}) {
|
|
1350
1434
|
return this.enqueue({
|
|
1351
1435
|
type: "resume",
|
|
@@ -1878,8 +1962,21 @@ var AgentSession = class AgentSession {
|
|
|
1878
1962
|
await this.compaction.preflight();
|
|
1879
1963
|
await this.turnLoop.run();
|
|
1880
1964
|
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Finishes an unfinished turn. Unwinds to its resume point — dropping the failed
|
|
1967
|
+
* attempt's leftovers, keeping everything that already left the process — and
|
|
1968
|
+
* re-infers from there. When the whole turn turns out to be discardable this is
|
|
1969
|
+
* a plain rerun, which spares the model a continuation boundary attached to a
|
|
1970
|
+
* stub of its own aborted output.
|
|
1971
|
+
*/
|
|
1881
1972
|
async executeResume() {
|
|
1973
|
+
const { cut, isFullRerun } = findResumePoint(this.transcriptLog.blocks);
|
|
1974
|
+
if (isFullRerun) {
|
|
1975
|
+
await this.executeRetry();
|
|
1976
|
+
return;
|
|
1977
|
+
}
|
|
1882
1978
|
await this.applyPendingModelSwitch();
|
|
1979
|
+
this.transcriptLog.truncateFrom(cut);
|
|
1883
1980
|
this.transcriptLog.markLatestAbortResumed();
|
|
1884
1981
|
this.transcriptLog.pushResumeTurn(this.currentTurnId(), this.model);
|
|
1885
1982
|
await this.commitTranscript();
|
|
@@ -3339,4 +3436,4 @@ function createProviderMap(providers) {
|
|
|
3339
3436
|
return map;
|
|
3340
3437
|
}
|
|
3341
3438
|
//#endregion
|
|
3342
|
-
export { AgentClient, AgentServer, AgentSession, DEFAULT_MAX_MEDIA_BYTES, DEFAULT_TURN_RETRY_POLICY, ProviderStreamError, RunCommandLineCommandNotRegisteredError, RunCommandLineShellNotFoundError, RunCommandLineTimeoutError, SHELL_VIEW_MAX_CHARS, TranscriptLog, applyTranscriptPatches, cloneBlocks, createInProcessTransportPair, createStandardAgentTools, createWebSocketClientTransport, createWebSocketServerTransport, estimateTranscriptBlockTokens, finishShellToolResult, isContextLengthExceeded, isRetryableCode, resolveRetryPolicy, retryDelayMs, shellCommandHandleRequired, shellPreviewBudgetTokens, toShellToolResult };
|
|
3439
|
+
export { AgentClient, AgentServer, AgentSession, DEFAULT_MAX_MEDIA_BYTES, DEFAULT_TURN_RETRY_POLICY, ProviderStreamError, RunCommandLineCommandNotRegisteredError, RunCommandLineShellNotFoundError, RunCommandLineTimeoutError, SHELL_VIEW_MAX_CHARS, TranscriptLog, applyTranscriptPatches, cloneBlocks, createInProcessTransportPair, createStandardAgentTools, createWebSocketClientTransport, createWebSocketServerTransport, estimateTranscriptBlockTokens, findResumePoint, finishShellToolResult, isContextLengthExceeded, isRetryableCode, resolveRetryPolicy, retryDelayMs, shellCommandHandleRequired, shellPreviewBudgetTokens, toShellToolResult };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-
|
|
1
|
+
import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-BZwi2YZL.mjs";
|
|
2
2
|
import { Readable, Writable } from "node:stream";
|
|
3
3
|
//#region src/stdio-transport.d.ts
|
|
4
4
|
declare function createStdioClientTransport(readable: Readable, writable: Writable): AgentClientTransport;
|
|
@@ -83,6 +83,11 @@ declare class TranscriptLog implements Transcript {
|
|
|
83
83
|
rewindToLastUserTurn(): Extract<Block, {
|
|
84
84
|
type: 'user';
|
|
85
85
|
}> | null;
|
|
86
|
+
/**
|
|
87
|
+
* Drops the blocks from `index` onward, returning true when anything went.
|
|
88
|
+
* Used to unwind a turn to its resume point before re-inferring.
|
|
89
|
+
*/
|
|
90
|
+
truncateFrom(index: number): boolean;
|
|
86
91
|
applyProviderEvent(model: ModelSelection, event: ProviderEvent): Block | null;
|
|
87
92
|
completeToolCall(toolUseId: string, output: ToolResultContentBlock[], isError?: boolean, view?: unknown | null): Block | null;
|
|
88
93
|
findPendingToolUseId(): string | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as AgentMetadata, c as ConversationSummary, f as AbortResult, n as AgentServerTransport, s as ClientSessionEvent, t as AgentClientTransport } from "./transport-
|
|
1
|
+
import { b as AgentMetadata, c as ConversationSummary, f as AbortResult, n as AgentServerTransport, s as ClientSessionEvent, t as AgentClientTransport } from "./transport-BZwi2YZL.mjs";
|
|
2
2
|
import { ProviderSelection } from "@demicodes/provider";
|
|
3
3
|
import { Block, UserContentBlock } from "@demicodes/core";
|
|
4
4
|
//#region src/client.d.ts
|
|
@@ -39,8 +39,18 @@ declare class AgentClient {
|
|
|
39
39
|
* turn (the server applies it at a turn boundary), so this is fire-and-forget.
|
|
40
40
|
*/
|
|
41
41
|
setProvider(provider: ProviderSelection): void;
|
|
42
|
+
/**
|
|
43
|
+
* Discards the whole latest turn and runs it again from the user's input —
|
|
44
|
+
* "regenerate". NOT a recovery path: it drops text the turn already emitted and
|
|
45
|
+
* tool calls it already ran while their effects remain. Use `resume` to finish a
|
|
46
|
+
* turn that failed.
|
|
47
|
+
*/
|
|
42
48
|
retry(options?: AgentActionOptions): Promise<void>;
|
|
43
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Finishes a turn that did not finish, after an abort or a terminal provider
|
|
51
|
+
* error. Unwinds only as far as is safe and re-infers from there; the caller
|
|
52
|
+
* does not choose the granularity.
|
|
53
|
+
*/
|
|
44
54
|
resume(options?: AgentActionOptions): Promise<void>;
|
|
45
55
|
compact(options?: AgentActionOptions): Promise<void>;
|
|
46
56
|
abort(): Promise<AbortResult>;
|
|
@@ -165,6 +165,12 @@ var AgentClient = class {
|
|
|
165
165
|
provider
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Discards the whole latest turn and runs it again from the user's input —
|
|
170
|
+
* "regenerate". NOT a recovery path: it drops text the turn already emitted and
|
|
171
|
+
* tool calls it already ran while their effects remain. Use `resume` to finish a
|
|
172
|
+
* turn that failed.
|
|
173
|
+
*/
|
|
168
174
|
retry(options = {}) {
|
|
169
175
|
const wait = this.waitForAction("retry");
|
|
170
176
|
this.sendFrame({
|
|
@@ -173,7 +179,11 @@ var AgentClient = class {
|
|
|
173
179
|
});
|
|
174
180
|
return wait;
|
|
175
181
|
}
|
|
176
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* Finishes a turn that did not finish, after an abort or a terminal provider
|
|
184
|
+
* error. Unwinds only as far as is safe and re-infers from there; the caller
|
|
185
|
+
* does not choose the granularity.
|
|
186
|
+
*/
|
|
177
187
|
resume(options = {}) {
|
|
178
188
|
const wait = this.waitForAction("resume");
|
|
179
189
|
this.sendFrame({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@demicodes/agent",
|
|
3
3
|
"description": "Session runtime and transport-neutral client and server protocol for Demi.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@demicodes/core": "^0.
|
|
23
|
-
"@demicodes/provider": "^0.
|
|
24
|
-
"@demicodes/shell": "^0.
|
|
25
|
-
"@demicodes/utils": "^0.
|
|
22
|
+
"@demicodes/core": "^0.10.0",
|
|
23
|
+
"@demicodes/provider": "^0.10.0",
|
|
24
|
+
"@demicodes/shell": "^0.10.0",
|
|
25
|
+
"@demicodes/utils": "^0.10.0"
|
|
26
26
|
},
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"main": "./dist/index.mjs",
|