@demicodes/agent 0.10.3 → 0.12.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/README.md +2 -0
- package/dist/client-entry.d.mts +3 -3
- package/dist/client-entry.mjs +1 -1
- package/dist/index.d.mts +154 -28
- package/dist/index.mjs +643 -329
- package/dist/stdio-transport.d.mts +1 -2
- package/dist/{transport-Bhf0h9FY.d.mts → transport-Diegnou1.d.mts} +87 -37
- package/dist/{websocket-transport-Bod0puog.mjs → websocket-transport-BjSj3U0I.mjs} +62 -19
- package/dist/{websocket-transport-D_Awo7zN.d.mts → websocket-transport-c4hu2c0X.d.mts} +22 -9
- package/package.json +5 -5
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-
|
|
1
|
+
import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-Diegnou1.mjs";
|
|
2
2
|
import { Readable, Writable } from "node:stream";
|
|
3
|
-
|
|
4
3
|
//#region src/stdio-transport.d.ts
|
|
5
4
|
declare function createStdioClientTransport(readable: Readable, writable: Writable): AgentClientTransport;
|
|
6
5
|
declare function createStdioServerTransport(readable: Readable, writable: Writable): AgentServerTransport;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PortableJsonValue } from "@demicodes/utils";
|
|
2
|
+
import { BashAuditEvent, Command, Host, ShellCommandStatus } from "@demicodes/shell";
|
|
2
3
|
import { AgentProvider, InferenceItem, ProviderEvent, ProviderSelection, ToolDefinition } from "@demicodes/provider";
|
|
3
|
-
import { Block, ModelSelection, QueuedMessage, SessionPhase, ToolResultContentBlock, Transcript, UserContentBlock } from "@demicodes/core";
|
|
4
|
-
|
|
4
|
+
import { Block, ModelSelection, ProviderErrorDiagnostics, QueuedMessage, SessionPhase, ToolResultContentBlock, Transcript, UserContentBlock } from "@demicodes/core";
|
|
5
5
|
//#region src/retry-policy.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Retry policy for provider requests, applied by the agent runtime (turn loop
|
|
@@ -49,7 +49,7 @@ interface DrainedTranscriptPatches {
|
|
|
49
49
|
revision: number;
|
|
50
50
|
patches: TranscriptPatch[];
|
|
51
51
|
}
|
|
52
|
-
declare class
|
|
52
|
+
declare class TranscriptLog implements Transcript {
|
|
53
53
|
readonly blocks: Block[];
|
|
54
54
|
private readonly idFactory;
|
|
55
55
|
private readonly now;
|
|
@@ -58,7 +58,7 @@ declare class Transcript$1 implements Transcript {
|
|
|
58
58
|
private readonly replayHeadChars;
|
|
59
59
|
private readonly replayTailChars;
|
|
60
60
|
constructor(blocks?: Block[], options?: TranscriptOptions);
|
|
61
|
-
|
|
61
|
+
toJSON(): Transcript;
|
|
62
62
|
/** Monotonic revision, advanced once per drained patch batch. */
|
|
63
63
|
get revision(): number;
|
|
64
64
|
/**
|
|
@@ -83,8 +83,13 @@ declare class Transcript$1 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
|
-
completeToolCall(toolUseId: string, output: ToolResultContentBlock[], isError?: boolean,
|
|
92
|
+
completeToolCall(toolUseId: string, output: ToolResultContentBlock[], isError?: boolean, view?: unknown | null): Block | null;
|
|
88
93
|
findPendingToolUseId(): string | null;
|
|
89
94
|
pendingToolCalls(): Extract<Block, {
|
|
90
95
|
type: 'tool_call';
|
|
@@ -107,8 +112,13 @@ declare class Transcript$1 implements Transcript {
|
|
|
107
112
|
* history), it anchors the estimate and only blocks streamed after it are
|
|
108
113
|
* char-estimated; otherwise the whole replay window is estimated at ~4
|
|
109
114
|
* chars/token with fixed weights for images and documents.
|
|
115
|
+
*
|
|
116
|
+
* When `contextWindow` is given, an anchor larger than the window is
|
|
117
|
+
* discarded: a single request's usage physically cannot exceed the window,
|
|
118
|
+
* so such a value is a provider violation of the response-usage contract
|
|
119
|
+
* (e.g. a turn-cumulative total) and would poison the estimate.
|
|
110
120
|
*/
|
|
111
|
-
estimateContextTokens(): number;
|
|
121
|
+
estimateContextTokens(contextWindow?: number): number;
|
|
112
122
|
/**
|
|
113
123
|
* The latest response block's usage, valid only when no compaction happened
|
|
114
124
|
* after it (compaction shrinks the history the usage was measured against).
|
|
@@ -123,16 +133,19 @@ declare class Transcript$1 implements Transcript {
|
|
|
123
133
|
declare function estimateTranscriptBlockTokens(block: Block): number;
|
|
124
134
|
//#endregion
|
|
125
135
|
//#region src/types.d.ts
|
|
136
|
+
/** Caller-defined data carried with one agent action. Demi transports it without interpreting it. */
|
|
137
|
+
type AgentMetadata = Readonly<Record<string, PortableJsonValue>>;
|
|
126
138
|
interface AgentPromptContext<State> {
|
|
127
139
|
agentSessionId: string;
|
|
128
140
|
state: State;
|
|
129
141
|
cwd: string;
|
|
130
|
-
transcript:
|
|
142
|
+
transcript: TranscriptLog;
|
|
143
|
+
metadata: AgentMetadata | null;
|
|
131
144
|
}
|
|
132
145
|
interface AgentSystemPromptContext<State> extends AgentPromptContext<State> {
|
|
133
146
|
/**
|
|
134
147
|
* Rendered help for every registered command (summary, subcommands, parameters,
|
|
135
|
-
* stdin fields
|
|
148
|
+
* stdin fields), produced by the server from the session's actual
|
|
136
149
|
* CommandRegistry. Harnesses embed it wherever their system prompt wants the
|
|
137
150
|
* command reference; empty string when no commands are registered.
|
|
138
151
|
*/
|
|
@@ -142,28 +155,36 @@ interface AgentToolContext<State> {
|
|
|
142
155
|
agentSessionId: string;
|
|
143
156
|
state: State;
|
|
144
157
|
cwd: string;
|
|
158
|
+
metadata: AgentMetadata | null;
|
|
145
159
|
}
|
|
146
160
|
interface AgentDisposeContext<State> {
|
|
147
161
|
agentSessionId: string;
|
|
148
162
|
state: State;
|
|
149
163
|
cwd: string;
|
|
150
|
-
transcript:
|
|
164
|
+
transcript: TranscriptLog;
|
|
151
165
|
}
|
|
152
166
|
interface AgentReferenceResolveContext<State> {
|
|
153
167
|
agentSessionId: string;
|
|
154
168
|
state: State;
|
|
155
169
|
cwd: string;
|
|
156
|
-
transcript:
|
|
170
|
+
transcript: TranscriptLog;
|
|
157
171
|
signal: AbortSignal;
|
|
172
|
+
metadata: AgentMetadata | null;
|
|
158
173
|
}
|
|
159
174
|
interface AgentHarnessContext<State> {
|
|
160
175
|
state: State;
|
|
161
176
|
cwd: string;
|
|
162
177
|
}
|
|
178
|
+
/** Context used when a shell operation resolves its action-specific Host. */
|
|
179
|
+
interface AgentHostContext<State> extends AgentHarnessContext<State> {
|
|
180
|
+
agentSessionId: string;
|
|
181
|
+
metadata: AgentMetadata | null;
|
|
182
|
+
}
|
|
163
183
|
interface AgentHarness<State = unknown> {
|
|
164
184
|
name: string;
|
|
165
185
|
initialState(): State;
|
|
166
|
-
|
|
186
|
+
/** Return the same Host object for calls that target the same execution environment. */
|
|
187
|
+
host(ctx: AgentHarnessContext<State> | AgentHostContext<State>): Host | Promise<Host>;
|
|
167
188
|
commands?(ctx: AgentHarnessContext<State>): Command[];
|
|
168
189
|
systemPrompt(ctx: AgentSystemPromptContext<State>): string;
|
|
169
190
|
preamble?(ctx: AgentPromptContext<State>): string | null;
|
|
@@ -178,21 +199,16 @@ interface AgentToolInvokeContext<State> {
|
|
|
178
199
|
model: ModelSelection;
|
|
179
200
|
toolCallId: string;
|
|
180
201
|
signal: AbortSignal;
|
|
202
|
+
metadata: AgentMetadata | null;
|
|
181
203
|
emitProgress(progress: unknown): void;
|
|
182
204
|
}
|
|
183
205
|
interface AgentToolInvokeResult {
|
|
184
206
|
output: ToolResultContentBlock[];
|
|
185
207
|
isError?: boolean;
|
|
186
|
-
|
|
187
|
-
|
|
208
|
+
/** Bounded UI-facing view data stored on the tool_call block; see the core Block contract. */
|
|
209
|
+
view?: unknown | null;
|
|
188
210
|
stopAfterToolResult?: boolean;
|
|
189
211
|
}
|
|
190
|
-
interface ToolContinuation {
|
|
191
|
-
toolCallId: string;
|
|
192
|
-
shellId: string;
|
|
193
|
-
commandId: string;
|
|
194
|
-
status: 'running';
|
|
195
|
-
}
|
|
196
212
|
type AbortTarget = 'active_provider_stream' | 'active_tool' | 'active_compaction' | 'active_turn' | 'queued_action' | 'queued_message' | 'pending_yield_wakeup';
|
|
197
213
|
interface AbortResult {
|
|
198
214
|
aborted: boolean;
|
|
@@ -206,22 +222,25 @@ type AgentLifecycleEvent<State> = {
|
|
|
206
222
|
type: 'before_round_start';
|
|
207
223
|
agentSessionId: string;
|
|
208
224
|
state: State;
|
|
209
|
-
transcript:
|
|
225
|
+
transcript: TranscriptLog;
|
|
210
226
|
content: UserContentBlock[];
|
|
227
|
+
metadata: AgentMetadata | null;
|
|
211
228
|
} | {
|
|
212
229
|
type: 'after_tool_call';
|
|
213
230
|
agentSessionId: string;
|
|
214
231
|
state: State;
|
|
215
|
-
transcript:
|
|
232
|
+
transcript: TranscriptLog;
|
|
216
233
|
toolCallId: string;
|
|
217
234
|
toolName: string;
|
|
218
235
|
result: AgentToolInvokeResult;
|
|
236
|
+
metadata: AgentMetadata | null;
|
|
219
237
|
} | {
|
|
220
238
|
type: 'after_transcript_rewrite';
|
|
221
239
|
agentSessionId: string;
|
|
222
240
|
state: State;
|
|
223
|
-
transcript:
|
|
241
|
+
transcript: TranscriptLog;
|
|
224
242
|
reason: 'retry';
|
|
243
|
+
metadata: AgentMetadata | null;
|
|
225
244
|
};
|
|
226
245
|
interface AgentHarnessRuntime<State> {
|
|
227
246
|
harnessName: string;
|
|
@@ -238,10 +257,31 @@ interface AgentSessionParams<State> {
|
|
|
238
257
|
model: ModelSelection;
|
|
239
258
|
cwd: string;
|
|
240
259
|
runtime: AgentHarnessRuntime<State>;
|
|
241
|
-
transcript?: Transcript |
|
|
260
|
+
transcript?: Transcript | TranscriptLog;
|
|
261
|
+
state?: State;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Overrides for `AgentSession.clone()`.
|
|
265
|
+
*
|
|
266
|
+
* Omitted fields keep the clone defaults: an independent `provider.clone()`,
|
|
267
|
+
* structured copies of model/transcript/state, and the same cwd/runtime.
|
|
268
|
+
*/
|
|
269
|
+
interface AgentSessionCloneParams<State = unknown> {
|
|
270
|
+
transcript?: Transcript;
|
|
271
|
+
/** Use this runtime instead of `this.provider.clone()`. */
|
|
272
|
+
provider?: AgentProvider;
|
|
273
|
+
model?: ModelSelection;
|
|
274
|
+
cwd?: string;
|
|
275
|
+
runtime?: AgentHarnessRuntime<State>;
|
|
276
|
+
/**
|
|
277
|
+
* Replace state. When omitted, state is `structuredClone`d for isolation.
|
|
278
|
+
* When provided, ownership transfers by reference (same as the constructor).
|
|
279
|
+
*/
|
|
242
280
|
state?: State;
|
|
281
|
+
/** Options for the clone. Parent store is never inherited. */
|
|
282
|
+
options?: AgentSessionOptions<State>;
|
|
243
283
|
}
|
|
244
|
-
interface
|
|
284
|
+
interface AgentSessionCheckpoint<State> {
|
|
245
285
|
transcript: Transcript;
|
|
246
286
|
state: State;
|
|
247
287
|
phase: SessionPhase;
|
|
@@ -251,14 +291,14 @@ interface AgentSessionSnapshot<State> {
|
|
|
251
291
|
harnessName: string;
|
|
252
292
|
}
|
|
253
293
|
interface AgentSessionStore<State = unknown> {
|
|
254
|
-
|
|
255
|
-
/** Load a previously saved
|
|
256
|
-
|
|
294
|
+
saveCheckpoint(checkpoint: AgentSessionCheckpoint<State>): Promise<void> | void;
|
|
295
|
+
/** Load a previously saved checkpoint for this session, or null if none exists. */
|
|
296
|
+
loadCheckpoint(): Promise<AgentSessionCheckpoint<State> | null>;
|
|
257
297
|
}
|
|
258
298
|
interface AgentSessionRestoreParams<State> {
|
|
259
299
|
provider: AgentProvider;
|
|
260
300
|
runtime: AgentHarnessRuntime<State>;
|
|
261
|
-
|
|
301
|
+
checkpoint: AgentSessionCheckpoint<State>;
|
|
262
302
|
}
|
|
263
303
|
interface AgentSessionOptions<State = unknown> {
|
|
264
304
|
agentSessionId?: string;
|
|
@@ -270,7 +310,7 @@ interface AgentSessionOptions<State = unknown> {
|
|
|
270
310
|
preflightThresholdRatio?: number;
|
|
271
311
|
};
|
|
272
312
|
/**
|
|
273
|
-
* Maximum interval between
|
|
313
|
+
* Maximum interval between checkpoint writes while a turn is streaming. Writes
|
|
274
314
|
* always flush at action boundaries (turn end, abort, dispose); this only
|
|
275
315
|
* bounds staleness during streaming. Default 1000ms.
|
|
276
316
|
*/
|
|
@@ -298,6 +338,7 @@ type SessionEvent = {
|
|
|
298
338
|
attempt: number;
|
|
299
339
|
delayMs: number;
|
|
300
340
|
code: string | null;
|
|
341
|
+
diagnostics?: ProviderErrorDiagnostics;
|
|
301
342
|
} | {
|
|
302
343
|
type: 'error';
|
|
303
344
|
error: Error;
|
|
@@ -324,6 +365,7 @@ type ClientFrame = {
|
|
|
324
365
|
type: 'send';
|
|
325
366
|
messageId: string;
|
|
326
367
|
content: UserContentBlock[];
|
|
368
|
+
metadata?: AgentMetadata;
|
|
327
369
|
} | {
|
|
328
370
|
type: 'dequeue_message';
|
|
329
371
|
messageId: string;
|
|
@@ -350,14 +392,18 @@ type ClientFrame = {
|
|
|
350
392
|
type: 'abort';
|
|
351
393
|
} | {
|
|
352
394
|
type: 'retry';
|
|
395
|
+
metadata?: AgentMetadata;
|
|
353
396
|
} | {
|
|
354
397
|
type: 'resume';
|
|
398
|
+
metadata?: AgentMetadata;
|
|
355
399
|
} | {
|
|
356
400
|
type: 'compact';
|
|
401
|
+
metadata?: AgentMetadata;
|
|
357
402
|
} | {
|
|
358
403
|
type: 'shell_write';
|
|
359
404
|
commandId: string;
|
|
360
405
|
stdin: string;
|
|
406
|
+
metadata?: AgentMetadata;
|
|
361
407
|
} | {
|
|
362
408
|
type: 'list_conversations';
|
|
363
409
|
cwd: string;
|
|
@@ -373,7 +419,7 @@ type ServerFrame = {
|
|
|
373
419
|
command: string;
|
|
374
420
|
reason: string;
|
|
375
421
|
} | {
|
|
376
|
-
type: '
|
|
422
|
+
type: 'transcript_reset';
|
|
377
423
|
blocks: Block[];
|
|
378
424
|
revision: number;
|
|
379
425
|
} | {
|
|
@@ -406,7 +452,7 @@ type ServerFrame = {
|
|
|
406
452
|
type: 'shell_output';
|
|
407
453
|
shellId: string;
|
|
408
454
|
commandId: string;
|
|
409
|
-
|
|
455
|
+
status: ShellCommandStatusLike;
|
|
410
456
|
} | {
|
|
411
457
|
type: 'shell_write_result';
|
|
412
458
|
commandId: string;
|
|
@@ -422,15 +468,17 @@ type ServerFrame = {
|
|
|
422
468
|
attempt: number;
|
|
423
469
|
delayMs: number;
|
|
424
470
|
code: string | null;
|
|
471
|
+
diagnostics?: ProviderErrorDiagnostics;
|
|
425
472
|
} | {
|
|
426
473
|
type: 'error';
|
|
427
474
|
message: string;
|
|
428
475
|
code?: string;
|
|
476
|
+
diagnostics?: ProviderErrorDiagnostics;
|
|
429
477
|
} | {
|
|
430
478
|
type: 'closed';
|
|
431
479
|
};
|
|
432
480
|
/**
|
|
433
|
-
* Wire patches for transcript replication. Produced directly by the
|
|
481
|
+
* Wire patches for transcript replication. Produced directly by the TranscriptLog's
|
|
434
482
|
* mutation journal (never diff-derived). `append_text` carries streaming deltas
|
|
435
483
|
* for the `text` field of the block at the index (text/thinking blocks), keeping
|
|
436
484
|
* per-delta cost O(delta) instead of O(block) or O(transcript).
|
|
@@ -455,9 +503,9 @@ type TranscriptPatch = {
|
|
|
455
503
|
path: ['blocks'];
|
|
456
504
|
value: Block[];
|
|
457
505
|
};
|
|
458
|
-
type
|
|
506
|
+
type ShellCommandStatusLike = ShellCommandStatus;
|
|
459
507
|
type ClientSessionEvent = {
|
|
460
|
-
type: '
|
|
508
|
+
type: 'transcript_reset';
|
|
461
509
|
blocks: Block[];
|
|
462
510
|
} | {
|
|
463
511
|
type: 'transcript_patch';
|
|
@@ -489,7 +537,7 @@ type ClientSessionEvent = {
|
|
|
489
537
|
type: 'shell_output';
|
|
490
538
|
shellId: string;
|
|
491
539
|
commandId: string;
|
|
492
|
-
|
|
540
|
+
status: ShellCommandStatusLike;
|
|
493
541
|
} | {
|
|
494
542
|
type: 'shell_write_result';
|
|
495
543
|
commandId: string;
|
|
@@ -502,6 +550,7 @@ type ClientSessionEvent = {
|
|
|
502
550
|
attempt: number;
|
|
503
551
|
delayMs: number;
|
|
504
552
|
code: string | null;
|
|
553
|
+
diagnostics?: ProviderErrorDiagnostics;
|
|
505
554
|
} | {
|
|
506
555
|
type: 'rejected';
|
|
507
556
|
command: string;
|
|
@@ -510,6 +559,7 @@ type ClientSessionEvent = {
|
|
|
510
559
|
type: 'error';
|
|
511
560
|
message: string;
|
|
512
561
|
code?: string;
|
|
562
|
+
diagnostics?: ProviderErrorDiagnostics;
|
|
513
563
|
} | {
|
|
514
564
|
type: 'opened';
|
|
515
565
|
} | {
|
|
@@ -530,4 +580,4 @@ interface InProcessTransportPair {
|
|
|
530
580
|
}
|
|
531
581
|
declare function createInProcessTransportPair(): InProcessTransportPair;
|
|
532
582
|
//#endregion
|
|
533
|
-
export {
|
|
583
|
+
export { AgentTool as A, TranscriptOptions as B, AgentSessionCheckpoint as C, AgentSessionRestoreParams as D, AgentSessionParams as E, SessionEvent as F, resolveRetryPolicy as G, DEFAULT_TURN_RETRY_POLICY as H, SessionEventListener as I, retryDelayMs as K, CompactionWindow as L, AgentToolInvokeContext as M, AgentToolInvokeResult as N, AgentSessionStore as O, ExternalMutationReservation as P, DrainedTranscriptPatches as R, AgentReferenceResolveContext as S, AgentSessionOptions as T, TurnRetryPolicy as U, estimateTranscriptBlockTokens as V, isRetryableCode as W, AgentHarnessRuntime as _, createInProcessTransportPair as a, AgentMetadata as b, ConversationSummary as c, TranscriptPatch as d, AbortResult as f, AgentHarnessContext as g, AgentHarness as h, InProcessTransportPair as i, AgentToolContext as j, AgentSystemPromptContext as k, ServerFrame as l, AgentDisposeContext as m, AgentServerTransport as n, ClientFrame as o, AbortTarget as p, AgentTransport as r, ClientSessionEvent as s, AgentClientTransport as t, ShellCommandStatusLike as u, AgentHostContext as v, AgentSessionCloneParams as w, AgentPromptContext as x, AgentLifecycleEvent as y, TranscriptLog as z };
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { parsePortableJson, stringifyPortableJson } from "@demicodes/utils";
|
|
2
|
+
//#region src/provider-stream-error.ts
|
|
3
|
+
/** Error carrying a provider stream's normalized code and bounded diagnostics. */
|
|
4
|
+
var ProviderStreamError = class extends Error {
|
|
5
|
+
code;
|
|
6
|
+
diagnostics;
|
|
7
|
+
constructor(message, code, diagnostics) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "ProviderStreamError";
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.diagnostics = diagnostics;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/** Whether an error is a provider stream error reporting the context window was exceeded. */
|
|
15
|
+
function isContextLengthExceeded(error) {
|
|
16
|
+
return error instanceof ProviderStreamError && error.code === "context_length_exceeded";
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
2
19
|
//#region src/patch.ts
|
|
3
20
|
/**
|
|
4
21
|
* Applies journal-produced transcript patches to a block list, returning a new
|
|
@@ -73,18 +90,19 @@ var AgentClient = class {
|
|
|
73
90
|
});
|
|
74
91
|
});
|
|
75
92
|
}
|
|
76
|
-
sendMessage(content) {
|
|
93
|
+
sendMessage(content, options = {}) {
|
|
77
94
|
const messageId = globalThis.crypto.randomUUID();
|
|
78
95
|
const wait = this.waitForAction("send", messageId);
|
|
79
96
|
this.sendFrame({
|
|
80
97
|
type: "send",
|
|
81
98
|
messageId,
|
|
82
|
-
content
|
|
99
|
+
content,
|
|
100
|
+
metadata: options.metadata
|
|
83
101
|
});
|
|
84
102
|
return wait;
|
|
85
103
|
}
|
|
86
|
-
send(content) {
|
|
87
|
-
return this.sendMessage(content);
|
|
104
|
+
send(content, options = {}) {
|
|
105
|
+
return this.sendMessage(content, options);
|
|
88
106
|
}
|
|
89
107
|
dequeueMessage(messageId) {
|
|
90
108
|
this.sendFrame({
|
|
@@ -147,19 +165,39 @@ var AgentClient = class {
|
|
|
147
165
|
provider
|
|
148
166
|
});
|
|
149
167
|
}
|
|
150
|
-
|
|
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
|
+
*/
|
|
174
|
+
retry(options = {}) {
|
|
151
175
|
const wait = this.waitForAction("retry");
|
|
152
|
-
this.sendFrame({
|
|
176
|
+
this.sendFrame({
|
|
177
|
+
type: "retry",
|
|
178
|
+
metadata: options.metadata
|
|
179
|
+
});
|
|
153
180
|
return wait;
|
|
154
181
|
}
|
|
155
|
-
|
|
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
|
+
*/
|
|
187
|
+
resume(options = {}) {
|
|
156
188
|
const wait = this.waitForAction("resume");
|
|
157
|
-
this.sendFrame({
|
|
189
|
+
this.sendFrame({
|
|
190
|
+
type: "resume",
|
|
191
|
+
metadata: options.metadata
|
|
192
|
+
});
|
|
158
193
|
return wait;
|
|
159
194
|
}
|
|
160
|
-
compact() {
|
|
195
|
+
compact(options = {}) {
|
|
161
196
|
const wait = this.waitForAction("compact");
|
|
162
|
-
this.sendFrame({
|
|
197
|
+
this.sendFrame({
|
|
198
|
+
type: "compact",
|
|
199
|
+
metadata: options.metadata
|
|
200
|
+
});
|
|
163
201
|
return wait;
|
|
164
202
|
}
|
|
165
203
|
abort() {
|
|
@@ -167,12 +205,13 @@ var AgentClient = class {
|
|
|
167
205
|
this.sendFrame({ type: "abort" });
|
|
168
206
|
return wait;
|
|
169
207
|
}
|
|
170
|
-
shellWrite(commandId, stdin) {
|
|
208
|
+
shellWrite(commandId, stdin, options = {}) {
|
|
171
209
|
const wait = this.waitForShellWrite(commandId);
|
|
172
210
|
this.sendFrame({
|
|
173
211
|
type: "shell_write",
|
|
174
212
|
commandId,
|
|
175
|
-
stdin
|
|
213
|
+
stdin,
|
|
214
|
+
metadata: options.metadata
|
|
176
215
|
});
|
|
177
216
|
return wait;
|
|
178
217
|
}
|
|
@@ -198,12 +237,12 @@ var AgentClient = class {
|
|
|
198
237
|
}
|
|
199
238
|
handleServerFrame(frame) {
|
|
200
239
|
switch (frame.type) {
|
|
201
|
-
case "
|
|
240
|
+
case "transcript_reset":
|
|
202
241
|
this.blocks = [...frame.blocks];
|
|
203
242
|
this.revision = frame.revision;
|
|
204
243
|
this.awaitingResync = false;
|
|
205
244
|
this.emit({
|
|
206
|
-
type: "
|
|
245
|
+
type: "transcript_reset",
|
|
207
246
|
blocks: this.blocks
|
|
208
247
|
});
|
|
209
248
|
return;
|
|
@@ -273,9 +312,12 @@ var AgentClient = class {
|
|
|
273
312
|
return;
|
|
274
313
|
case "error":
|
|
275
314
|
this.emit(frame);
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
315
|
+
{
|
|
316
|
+
const error = frame.code ? new ProviderStreamError(frame.message, frame.code, frame.diagnostics) : new Error(frame.message);
|
|
317
|
+
this.rejectErroredAction(error);
|
|
318
|
+
this.rejectAllSteerWaiters(error);
|
|
319
|
+
this.rejectAllAbortWaiters(error);
|
|
320
|
+
}
|
|
279
321
|
return;
|
|
280
322
|
}
|
|
281
323
|
}
|
|
@@ -447,7 +489,8 @@ var WebSocketJsonTransport = class {
|
|
|
447
489
|
socket;
|
|
448
490
|
handlers = /* @__PURE__ */ new Set();
|
|
449
491
|
onMessage = (event) => {
|
|
450
|
-
const
|
|
492
|
+
const text = typeof event.data === "string" ? event.data : String(event.data);
|
|
493
|
+
const frame = parsePortableJson(text);
|
|
451
494
|
for (const handler of this.handlers) handler(frame);
|
|
452
495
|
};
|
|
453
496
|
constructor(socket) {
|
|
@@ -470,4 +513,4 @@ var WebSocketJsonTransport = class {
|
|
|
470
513
|
}
|
|
471
514
|
};
|
|
472
515
|
//#endregion
|
|
473
|
-
export { cloneBlocks as a, applyTranscriptPatches as i, createWebSocketServerTransport as n, AgentClient as r, createWebSocketClientTransport as t };
|
|
516
|
+
export { cloneBlocks as a, applyTranscriptPatches as i, createWebSocketServerTransport as n, ProviderStreamError as o, AgentClient as r, isContextLengthExceeded as s, createWebSocketClientTransport as t };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { 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-Diegnou1.mjs";
|
|
2
2
|
import { ProviderSelection } from "@demicodes/provider";
|
|
3
3
|
import { Block, UserContentBlock } from "@demicodes/core";
|
|
4
|
-
|
|
5
4
|
//#region src/client.d.ts
|
|
6
5
|
type AgentClientListener = (event: ClientSessionEvent) => void;
|
|
6
|
+
interface AgentActionOptions {
|
|
7
|
+
metadata?: AgentMetadata;
|
|
8
|
+
}
|
|
7
9
|
declare class AgentClient {
|
|
8
10
|
private readonly transport;
|
|
9
11
|
private readonly listeners;
|
|
@@ -20,8 +22,8 @@ declare class AgentClient {
|
|
|
20
22
|
constructor(transport: AgentClientTransport);
|
|
21
23
|
open(provider: ProviderSelection, cwd: string, sessionId: string): Promise<void>;
|
|
22
24
|
listConversations(cwd: string): Promise<ConversationSummary[]>;
|
|
23
|
-
sendMessage(content: UserContentBlock[]): Promise<void>;
|
|
24
|
-
send(content: UserContentBlock[]): Promise<void>;
|
|
25
|
+
sendMessage(content: UserContentBlock[], options?: AgentActionOptions): Promise<void>;
|
|
26
|
+
send(content: UserContentBlock[], options?: AgentActionOptions): Promise<void>;
|
|
25
27
|
dequeueMessage(messageId: string): void;
|
|
26
28
|
sendQueuedMessage(messageId: string): void;
|
|
27
29
|
steerQueuedMessage(messageId: string, options?: {
|
|
@@ -37,11 +39,22 @@ declare class AgentClient {
|
|
|
37
39
|
* turn (the server applies it at a turn boundary), so this is fire-and-forget.
|
|
38
40
|
*/
|
|
39
41
|
setProvider(provider: ProviderSelection): void;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
*/
|
|
48
|
+
retry(options?: AgentActionOptions): Promise<void>;
|
|
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
|
+
*/
|
|
54
|
+
resume(options?: AgentActionOptions): Promise<void>;
|
|
55
|
+
compact(options?: AgentActionOptions): Promise<void>;
|
|
43
56
|
abort(): Promise<AbortResult>;
|
|
44
|
-
shellWrite(commandId: string, stdin: string): Promise<void>;
|
|
57
|
+
shellWrite(commandId: string, stdin: string, options?: AgentActionOptions): Promise<void>;
|
|
45
58
|
close(): Promise<void>;
|
|
46
59
|
subscribe(listener: AgentClientListener): () => void;
|
|
47
60
|
transcript(): {
|
|
@@ -85,4 +98,4 @@ interface JsonWebSocket {
|
|
|
85
98
|
declare function createWebSocketClientTransport(socket: JsonWebSocket): AgentClientTransport;
|
|
86
99
|
declare function createWebSocketServerTransport(socket: JsonWebSocket): AgentServerTransport;
|
|
87
100
|
//#endregion
|
|
88
|
-
export {
|
|
101
|
+
export { AgentClient as a, AgentActionOptions as i, createWebSocketClientTransport as n, AgentClientListener as o, createWebSocketServerTransport as r, JsonWebSocket as t };
|
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.12.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.12.0",
|
|
23
|
+
"@demicodes/provider": "^0.12.0",
|
|
24
|
+
"@demicodes/shell": "^0.12.0",
|
|
25
|
+
"@demicodes/utils": "^0.12.0"
|
|
26
26
|
},
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"main": "./dist/index.mjs",
|