@demicodes/agent 0.10.2 → 0.10.3
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 +0 -2
- package/dist/client-entry.d.mts +3 -3
- package/dist/client-entry.mjs +1 -1
- package/dist/index.d.mts +28 -145
- package/dist/index.mjs +205 -577
- package/dist/stdio-transport.d.mts +2 -1
- package/dist/{transport-BZwi2YZL.d.mts → transport-Bhf0h9FY.d.mts} +36 -65
- package/dist/{websocket-transport-os0mfcLi.mjs → websocket-transport-Bod0puog.mjs} +18 -60
- package/dist/{websocket-transport-CZpGt4Py.d.mts → websocket-transport-D_Awo7zN.d.mts} +9 -22
- package/package.json +5 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-
|
|
1
|
+
import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-Bhf0h9FY.mjs";
|
|
2
2
|
import { Readable, Writable } from "node:stream";
|
|
3
|
+
|
|
3
4
|
//#region src/stdio-transport.d.ts
|
|
4
5
|
declare function createStdioClientTransport(readable: Readable, writable: Writable): AgentClientTransport;
|
|
5
6
|
declare function createStdioServerTransport(readable: Readable, writable: Writable): AgentServerTransport;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BashAuditEvent, Command, Host, ShellCommandStatus } from "@demicodes/shell";
|
|
1
|
+
import { BashAuditEvent, Command, Host, ShellCommandSnapshot } from "@demicodes/shell";
|
|
3
2
|
import { AgentProvider, InferenceItem, ProviderEvent, ProviderSelection, ToolDefinition } from "@demicodes/provider";
|
|
4
|
-
import { Block, ModelSelection,
|
|
3
|
+
import { Block, ModelSelection, QueuedMessage, SessionPhase, ToolResultContentBlock, Transcript, UserContentBlock } from "@demicodes/core";
|
|
4
|
+
|
|
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 Transcript$1 implements Transcript {
|
|
53
53
|
readonly blocks: Block[];
|
|
54
54
|
private readonly idFactory;
|
|
55
55
|
private readonly now;
|
|
@@ -58,7 +58,7 @@ declare class TranscriptLog implements Transcript {
|
|
|
58
58
|
private readonly replayHeadChars;
|
|
59
59
|
private readonly replayTailChars;
|
|
60
60
|
constructor(blocks?: Block[], options?: TranscriptOptions);
|
|
61
|
-
|
|
61
|
+
snapshot(): Transcript;
|
|
62
62
|
/** Monotonic revision, advanced once per drained patch batch. */
|
|
63
63
|
get revision(): number;
|
|
64
64
|
/**
|
|
@@ -83,13 +83,8 @@ 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;
|
|
91
86
|
applyProviderEvent(model: ModelSelection, event: ProviderEvent): Block | null;
|
|
92
|
-
completeToolCall(toolUseId: string, output: ToolResultContentBlock[], isError?: boolean,
|
|
87
|
+
completeToolCall(toolUseId: string, output: ToolResultContentBlock[], isError?: boolean, metadata?: unknown | null): Block | null;
|
|
93
88
|
findPendingToolUseId(): string | null;
|
|
94
89
|
pendingToolCalls(): Extract<Block, {
|
|
95
90
|
type: 'tool_call';
|
|
@@ -112,13 +107,8 @@ declare class TranscriptLog implements Transcript {
|
|
|
112
107
|
* history), it anchors the estimate and only blocks streamed after it are
|
|
113
108
|
* char-estimated; otherwise the whole replay window is estimated at ~4
|
|
114
109
|
* 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.
|
|
120
110
|
*/
|
|
121
|
-
estimateContextTokens(
|
|
111
|
+
estimateContextTokens(): number;
|
|
122
112
|
/**
|
|
123
113
|
* The latest response block's usage, valid only when no compaction happened
|
|
124
114
|
* after it (compaction shrinks the history the usage was measured against).
|
|
@@ -133,14 +123,11 @@ declare class TranscriptLog implements Transcript {
|
|
|
133
123
|
declare function estimateTranscriptBlockTokens(block: Block): number;
|
|
134
124
|
//#endregion
|
|
135
125
|
//#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>>;
|
|
138
126
|
interface AgentPromptContext<State> {
|
|
139
127
|
agentSessionId: string;
|
|
140
128
|
state: State;
|
|
141
129
|
cwd: string;
|
|
142
|
-
transcript:
|
|
143
|
-
metadata: AgentMetadata | null;
|
|
130
|
+
transcript: Transcript$1;
|
|
144
131
|
}
|
|
145
132
|
interface AgentSystemPromptContext<State> extends AgentPromptContext<State> {
|
|
146
133
|
/**
|
|
@@ -155,36 +142,28 @@ interface AgentToolContext<State> {
|
|
|
155
142
|
agentSessionId: string;
|
|
156
143
|
state: State;
|
|
157
144
|
cwd: string;
|
|
158
|
-
metadata: AgentMetadata | null;
|
|
159
145
|
}
|
|
160
146
|
interface AgentDisposeContext<State> {
|
|
161
147
|
agentSessionId: string;
|
|
162
148
|
state: State;
|
|
163
149
|
cwd: string;
|
|
164
|
-
transcript:
|
|
150
|
+
transcript: Transcript$1;
|
|
165
151
|
}
|
|
166
152
|
interface AgentReferenceResolveContext<State> {
|
|
167
153
|
agentSessionId: string;
|
|
168
154
|
state: State;
|
|
169
155
|
cwd: string;
|
|
170
|
-
transcript:
|
|
156
|
+
transcript: Transcript$1;
|
|
171
157
|
signal: AbortSignal;
|
|
172
|
-
metadata: AgentMetadata | null;
|
|
173
158
|
}
|
|
174
159
|
interface AgentHarnessContext<State> {
|
|
175
160
|
state: State;
|
|
176
161
|
cwd: string;
|
|
177
162
|
}
|
|
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
|
-
}
|
|
183
163
|
interface AgentHarness<State = unknown> {
|
|
184
164
|
name: string;
|
|
185
165
|
initialState(): State;
|
|
186
|
-
|
|
187
|
-
host(ctx: AgentHarnessContext<State> | AgentHostContext<State>): Host | Promise<Host>;
|
|
166
|
+
host(ctx: AgentHarnessContext<State>): Host;
|
|
188
167
|
commands?(ctx: AgentHarnessContext<State>): Command[];
|
|
189
168
|
systemPrompt(ctx: AgentSystemPromptContext<State>): string;
|
|
190
169
|
preamble?(ctx: AgentPromptContext<State>): string | null;
|
|
@@ -199,16 +178,21 @@ interface AgentToolInvokeContext<State> {
|
|
|
199
178
|
model: ModelSelection;
|
|
200
179
|
toolCallId: string;
|
|
201
180
|
signal: AbortSignal;
|
|
202
|
-
metadata: AgentMetadata | null;
|
|
203
181
|
emitProgress(progress: unknown): void;
|
|
204
182
|
}
|
|
205
183
|
interface AgentToolInvokeResult {
|
|
206
184
|
output: ToolResultContentBlock[];
|
|
207
185
|
isError?: boolean;
|
|
208
|
-
|
|
209
|
-
|
|
186
|
+
metadata?: unknown | null;
|
|
187
|
+
continuation?: ToolContinuation;
|
|
210
188
|
stopAfterToolResult?: boolean;
|
|
211
189
|
}
|
|
190
|
+
interface ToolContinuation {
|
|
191
|
+
toolCallId: string;
|
|
192
|
+
shellId: string;
|
|
193
|
+
commandId: string;
|
|
194
|
+
status: 'running';
|
|
195
|
+
}
|
|
212
196
|
type AbortTarget = 'active_provider_stream' | 'active_tool' | 'active_compaction' | 'active_turn' | 'queued_action' | 'queued_message' | 'pending_yield_wakeup';
|
|
213
197
|
interface AbortResult {
|
|
214
198
|
aborted: boolean;
|
|
@@ -222,25 +206,22 @@ type AgentLifecycleEvent<State> = {
|
|
|
222
206
|
type: 'before_round_start';
|
|
223
207
|
agentSessionId: string;
|
|
224
208
|
state: State;
|
|
225
|
-
transcript:
|
|
209
|
+
transcript: Transcript$1;
|
|
226
210
|
content: UserContentBlock[];
|
|
227
|
-
metadata: AgentMetadata | null;
|
|
228
211
|
} | {
|
|
229
212
|
type: 'after_tool_call';
|
|
230
213
|
agentSessionId: string;
|
|
231
214
|
state: State;
|
|
232
|
-
transcript:
|
|
215
|
+
transcript: Transcript$1;
|
|
233
216
|
toolCallId: string;
|
|
234
217
|
toolName: string;
|
|
235
218
|
result: AgentToolInvokeResult;
|
|
236
|
-
metadata: AgentMetadata | null;
|
|
237
219
|
} | {
|
|
238
220
|
type: 'after_transcript_rewrite';
|
|
239
221
|
agentSessionId: string;
|
|
240
222
|
state: State;
|
|
241
|
-
transcript:
|
|
223
|
+
transcript: Transcript$1;
|
|
242
224
|
reason: 'retry';
|
|
243
|
-
metadata: AgentMetadata | null;
|
|
244
225
|
};
|
|
245
226
|
interface AgentHarnessRuntime<State> {
|
|
246
227
|
harnessName: string;
|
|
@@ -257,10 +238,10 @@ interface AgentSessionParams<State> {
|
|
|
257
238
|
model: ModelSelection;
|
|
258
239
|
cwd: string;
|
|
259
240
|
runtime: AgentHarnessRuntime<State>;
|
|
260
|
-
transcript?: Transcript |
|
|
241
|
+
transcript?: Transcript | Transcript$1;
|
|
261
242
|
state?: State;
|
|
262
243
|
}
|
|
263
|
-
interface
|
|
244
|
+
interface AgentSessionSnapshot<State> {
|
|
264
245
|
transcript: Transcript;
|
|
265
246
|
state: State;
|
|
266
247
|
phase: SessionPhase;
|
|
@@ -270,14 +251,14 @@ interface AgentSessionCheckpoint<State> {
|
|
|
270
251
|
harnessName: string;
|
|
271
252
|
}
|
|
272
253
|
interface AgentSessionStore<State = unknown> {
|
|
273
|
-
|
|
274
|
-
/** Load a previously saved
|
|
275
|
-
|
|
254
|
+
saveSnapshot(snapshot: AgentSessionSnapshot<State>): Promise<void> | void;
|
|
255
|
+
/** Load a previously saved snapshot for this session, or null if none exists. */
|
|
256
|
+
loadSnapshot(): Promise<AgentSessionSnapshot<State> | null>;
|
|
276
257
|
}
|
|
277
258
|
interface AgentSessionRestoreParams<State> {
|
|
278
259
|
provider: AgentProvider;
|
|
279
260
|
runtime: AgentHarnessRuntime<State>;
|
|
280
|
-
|
|
261
|
+
snapshot: AgentSessionSnapshot<State>;
|
|
281
262
|
}
|
|
282
263
|
interface AgentSessionOptions<State = unknown> {
|
|
283
264
|
agentSessionId?: string;
|
|
@@ -289,7 +270,7 @@ interface AgentSessionOptions<State = unknown> {
|
|
|
289
270
|
preflightThresholdRatio?: number;
|
|
290
271
|
};
|
|
291
272
|
/**
|
|
292
|
-
* Maximum interval between
|
|
273
|
+
* Maximum interval between snapshot writes while a turn is streaming. Writes
|
|
293
274
|
* always flush at action boundaries (turn end, abort, dispose); this only
|
|
294
275
|
* bounds staleness during streaming. Default 1000ms.
|
|
295
276
|
*/
|
|
@@ -317,7 +298,6 @@ type SessionEvent = {
|
|
|
317
298
|
attempt: number;
|
|
318
299
|
delayMs: number;
|
|
319
300
|
code: string | null;
|
|
320
|
-
diagnostics?: ProviderErrorDiagnostics;
|
|
321
301
|
} | {
|
|
322
302
|
type: 'error';
|
|
323
303
|
error: Error;
|
|
@@ -344,7 +324,6 @@ type ClientFrame = {
|
|
|
344
324
|
type: 'send';
|
|
345
325
|
messageId: string;
|
|
346
326
|
content: UserContentBlock[];
|
|
347
|
-
metadata?: AgentMetadata;
|
|
348
327
|
} | {
|
|
349
328
|
type: 'dequeue_message';
|
|
350
329
|
messageId: string;
|
|
@@ -371,18 +350,14 @@ type ClientFrame = {
|
|
|
371
350
|
type: 'abort';
|
|
372
351
|
} | {
|
|
373
352
|
type: 'retry';
|
|
374
|
-
metadata?: AgentMetadata;
|
|
375
353
|
} | {
|
|
376
354
|
type: 'resume';
|
|
377
|
-
metadata?: AgentMetadata;
|
|
378
355
|
} | {
|
|
379
356
|
type: 'compact';
|
|
380
|
-
metadata?: AgentMetadata;
|
|
381
357
|
} | {
|
|
382
358
|
type: 'shell_write';
|
|
383
359
|
commandId: string;
|
|
384
360
|
stdin: string;
|
|
385
|
-
metadata?: AgentMetadata;
|
|
386
361
|
} | {
|
|
387
362
|
type: 'list_conversations';
|
|
388
363
|
cwd: string;
|
|
@@ -398,7 +373,7 @@ type ServerFrame = {
|
|
|
398
373
|
command: string;
|
|
399
374
|
reason: string;
|
|
400
375
|
} | {
|
|
401
|
-
type: '
|
|
376
|
+
type: 'transcript_snapshot';
|
|
402
377
|
blocks: Block[];
|
|
403
378
|
revision: number;
|
|
404
379
|
} | {
|
|
@@ -431,7 +406,7 @@ type ServerFrame = {
|
|
|
431
406
|
type: 'shell_output';
|
|
432
407
|
shellId: string;
|
|
433
408
|
commandId: string;
|
|
434
|
-
|
|
409
|
+
snapshot: ShellCommandSnapshotLike;
|
|
435
410
|
} | {
|
|
436
411
|
type: 'shell_write_result';
|
|
437
412
|
commandId: string;
|
|
@@ -447,17 +422,15 @@ type ServerFrame = {
|
|
|
447
422
|
attempt: number;
|
|
448
423
|
delayMs: number;
|
|
449
424
|
code: string | null;
|
|
450
|
-
diagnostics?: ProviderErrorDiagnostics;
|
|
451
425
|
} | {
|
|
452
426
|
type: 'error';
|
|
453
427
|
message: string;
|
|
454
428
|
code?: string;
|
|
455
|
-
diagnostics?: ProviderErrorDiagnostics;
|
|
456
429
|
} | {
|
|
457
430
|
type: 'closed';
|
|
458
431
|
};
|
|
459
432
|
/**
|
|
460
|
-
* Wire patches for transcript replication. Produced directly by the
|
|
433
|
+
* Wire patches for transcript replication. Produced directly by the Transcript's
|
|
461
434
|
* mutation journal (never diff-derived). `append_text` carries streaming deltas
|
|
462
435
|
* for the `text` field of the block at the index (text/thinking blocks), keeping
|
|
463
436
|
* per-delta cost O(delta) instead of O(block) or O(transcript).
|
|
@@ -482,9 +455,9 @@ type TranscriptPatch = {
|
|
|
482
455
|
path: ['blocks'];
|
|
483
456
|
value: Block[];
|
|
484
457
|
};
|
|
485
|
-
type
|
|
458
|
+
type ShellCommandSnapshotLike = ShellCommandSnapshot;
|
|
486
459
|
type ClientSessionEvent = {
|
|
487
|
-
type: '
|
|
460
|
+
type: 'transcript_snapshot';
|
|
488
461
|
blocks: Block[];
|
|
489
462
|
} | {
|
|
490
463
|
type: 'transcript_patch';
|
|
@@ -516,7 +489,7 @@ type ClientSessionEvent = {
|
|
|
516
489
|
type: 'shell_output';
|
|
517
490
|
shellId: string;
|
|
518
491
|
commandId: string;
|
|
519
|
-
|
|
492
|
+
snapshot: ShellCommandSnapshotLike;
|
|
520
493
|
} | {
|
|
521
494
|
type: 'shell_write_result';
|
|
522
495
|
commandId: string;
|
|
@@ -529,7 +502,6 @@ type ClientSessionEvent = {
|
|
|
529
502
|
attempt: number;
|
|
530
503
|
delayMs: number;
|
|
531
504
|
code: string | null;
|
|
532
|
-
diagnostics?: ProviderErrorDiagnostics;
|
|
533
505
|
} | {
|
|
534
506
|
type: 'rejected';
|
|
535
507
|
command: string;
|
|
@@ -538,7 +510,6 @@ type ClientSessionEvent = {
|
|
|
538
510
|
type: 'error';
|
|
539
511
|
message: string;
|
|
540
512
|
code?: string;
|
|
541
|
-
diagnostics?: ProviderErrorDiagnostics;
|
|
542
513
|
} | {
|
|
543
514
|
type: 'opened';
|
|
544
515
|
} | {
|
|
@@ -559,4 +530,4 @@ interface InProcessTransportPair {
|
|
|
559
530
|
}
|
|
560
531
|
declare function createInProcessTransportPair(): InProcessTransportPair;
|
|
561
532
|
//#endregion
|
|
562
|
-
export {
|
|
533
|
+
export { AgentToolInvokeResult as A, DEFAULT_TURN_RETRY_POLICY as B, AgentSessionRestoreParams as C, AgentTool as D, AgentSystemPromptContext as E, CompactionWindow as F, isRetryableCode as H, DrainedTranscriptPatches as I, Transcript$1 as L, SessionEvent as M, SessionEventListener as N, AgentToolContext as O, ToolContinuation as P, TranscriptOptions as R, AgentSessionParams as S, AgentSessionStore as T, resolveRetryPolicy as U, TurnRetryPolicy as V, retryDelayMs as W, AgentHarnessRuntime as _, createInProcessTransportPair as a, AgentReferenceResolveContext as b, ConversationSummary as c, TranscriptPatch as d, AbortResult as f, AgentHarnessContext as g, AgentHarness as h, InProcessTransportPair as i, ExternalMutationReservation as j, AgentToolInvokeContext 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, ShellCommandSnapshotLike as u, AgentLifecycleEvent as v, AgentSessionSnapshot as w, AgentSessionOptions as x, AgentPromptContext as y, estimateTranscriptBlockTokens as z };
|
|
@@ -1,21 +1,4 @@
|
|
|
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
|
|
19
2
|
//#region src/patch.ts
|
|
20
3
|
/**
|
|
21
4
|
* Applies journal-produced transcript patches to a block list, returning a new
|
|
@@ -90,19 +73,18 @@ var AgentClient = class {
|
|
|
90
73
|
});
|
|
91
74
|
});
|
|
92
75
|
}
|
|
93
|
-
sendMessage(content
|
|
76
|
+
sendMessage(content) {
|
|
94
77
|
const messageId = globalThis.crypto.randomUUID();
|
|
95
78
|
const wait = this.waitForAction("send", messageId);
|
|
96
79
|
this.sendFrame({
|
|
97
80
|
type: "send",
|
|
98
81
|
messageId,
|
|
99
|
-
content
|
|
100
|
-
metadata: options.metadata
|
|
82
|
+
content
|
|
101
83
|
});
|
|
102
84
|
return wait;
|
|
103
85
|
}
|
|
104
|
-
send(content
|
|
105
|
-
return this.sendMessage(content
|
|
86
|
+
send(content) {
|
|
87
|
+
return this.sendMessage(content);
|
|
106
88
|
}
|
|
107
89
|
dequeueMessage(messageId) {
|
|
108
90
|
this.sendFrame({
|
|
@@ -165,39 +147,19 @@ var AgentClient = class {
|
|
|
165
147
|
provider
|
|
166
148
|
});
|
|
167
149
|
}
|
|
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 = {}) {
|
|
150
|
+
retry() {
|
|
175
151
|
const wait = this.waitForAction("retry");
|
|
176
|
-
this.sendFrame({
|
|
177
|
-
type: "retry",
|
|
178
|
-
metadata: options.metadata
|
|
179
|
-
});
|
|
152
|
+
this.sendFrame({ type: "retry" });
|
|
180
153
|
return wait;
|
|
181
154
|
}
|
|
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 = {}) {
|
|
155
|
+
resume() {
|
|
188
156
|
const wait = this.waitForAction("resume");
|
|
189
|
-
this.sendFrame({
|
|
190
|
-
type: "resume",
|
|
191
|
-
metadata: options.metadata
|
|
192
|
-
});
|
|
157
|
+
this.sendFrame({ type: "resume" });
|
|
193
158
|
return wait;
|
|
194
159
|
}
|
|
195
|
-
compact(
|
|
160
|
+
compact() {
|
|
196
161
|
const wait = this.waitForAction("compact");
|
|
197
|
-
this.sendFrame({
|
|
198
|
-
type: "compact",
|
|
199
|
-
metadata: options.metadata
|
|
200
|
-
});
|
|
162
|
+
this.sendFrame({ type: "compact" });
|
|
201
163
|
return wait;
|
|
202
164
|
}
|
|
203
165
|
abort() {
|
|
@@ -205,13 +167,12 @@ var AgentClient = class {
|
|
|
205
167
|
this.sendFrame({ type: "abort" });
|
|
206
168
|
return wait;
|
|
207
169
|
}
|
|
208
|
-
shellWrite(commandId, stdin
|
|
170
|
+
shellWrite(commandId, stdin) {
|
|
209
171
|
const wait = this.waitForShellWrite(commandId);
|
|
210
172
|
this.sendFrame({
|
|
211
173
|
type: "shell_write",
|
|
212
174
|
commandId,
|
|
213
|
-
stdin
|
|
214
|
-
metadata: options.metadata
|
|
175
|
+
stdin
|
|
215
176
|
});
|
|
216
177
|
return wait;
|
|
217
178
|
}
|
|
@@ -237,12 +198,12 @@ var AgentClient = class {
|
|
|
237
198
|
}
|
|
238
199
|
handleServerFrame(frame) {
|
|
239
200
|
switch (frame.type) {
|
|
240
|
-
case "
|
|
201
|
+
case "transcript_snapshot":
|
|
241
202
|
this.blocks = [...frame.blocks];
|
|
242
203
|
this.revision = frame.revision;
|
|
243
204
|
this.awaitingResync = false;
|
|
244
205
|
this.emit({
|
|
245
|
-
type: "
|
|
206
|
+
type: "transcript_snapshot",
|
|
246
207
|
blocks: this.blocks
|
|
247
208
|
});
|
|
248
209
|
return;
|
|
@@ -312,12 +273,9 @@ var AgentClient = class {
|
|
|
312
273
|
return;
|
|
313
274
|
case "error":
|
|
314
275
|
this.emit(frame);
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
this.rejectAllSteerWaiters(error);
|
|
319
|
-
this.rejectAllAbortWaiters(error);
|
|
320
|
-
}
|
|
276
|
+
this.rejectErroredAction(new Error(frame.message));
|
|
277
|
+
this.rejectAllSteerWaiters(new Error(frame.message));
|
|
278
|
+
this.rejectAllAbortWaiters(new Error(frame.message));
|
|
321
279
|
return;
|
|
322
280
|
}
|
|
323
281
|
}
|
|
@@ -512,4 +470,4 @@ var WebSocketJsonTransport = class {
|
|
|
512
470
|
}
|
|
513
471
|
};
|
|
514
472
|
//#endregion
|
|
515
|
-
export { cloneBlocks as a, applyTranscriptPatches as i, createWebSocketServerTransport as n,
|
|
473
|
+
export { cloneBlocks as a, applyTranscriptPatches as i, createWebSocketServerTransport as n, AgentClient as r, createWebSocketClientTransport as t };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as ConversationSummary, f as AbortResult, n as AgentServerTransport, s as ClientSessionEvent, t as AgentClientTransport } from "./transport-Bhf0h9FY.mjs";
|
|
2
2
|
import { ProviderSelection } from "@demicodes/provider";
|
|
3
3
|
import { Block, UserContentBlock } from "@demicodes/core";
|
|
4
|
+
|
|
4
5
|
//#region src/client.d.ts
|
|
5
6
|
type AgentClientListener = (event: ClientSessionEvent) => void;
|
|
6
|
-
interface AgentActionOptions {
|
|
7
|
-
metadata?: AgentMetadata;
|
|
8
|
-
}
|
|
9
7
|
declare class AgentClient {
|
|
10
8
|
private readonly transport;
|
|
11
9
|
private readonly listeners;
|
|
@@ -22,8 +20,8 @@ declare class AgentClient {
|
|
|
22
20
|
constructor(transport: AgentClientTransport);
|
|
23
21
|
open(provider: ProviderSelection, cwd: string, sessionId: string): Promise<void>;
|
|
24
22
|
listConversations(cwd: string): Promise<ConversationSummary[]>;
|
|
25
|
-
sendMessage(content: UserContentBlock[]
|
|
26
|
-
send(content: UserContentBlock[]
|
|
23
|
+
sendMessage(content: UserContentBlock[]): Promise<void>;
|
|
24
|
+
send(content: UserContentBlock[]): Promise<void>;
|
|
27
25
|
dequeueMessage(messageId: string): void;
|
|
28
26
|
sendQueuedMessage(messageId: string): void;
|
|
29
27
|
steerQueuedMessage(messageId: string, options?: {
|
|
@@ -39,22 +37,11 @@ declare class AgentClient {
|
|
|
39
37
|
* turn (the server applies it at a turn boundary), so this is fire-and-forget.
|
|
40
38
|
*/
|
|
41
39
|
setProvider(provider: ProviderSelection): void;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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>;
|
|
40
|
+
retry(): Promise<void>;
|
|
41
|
+
resume(): Promise<void>;
|
|
42
|
+
compact(): Promise<void>;
|
|
56
43
|
abort(): Promise<AbortResult>;
|
|
57
|
-
shellWrite(commandId: string, stdin: string
|
|
44
|
+
shellWrite(commandId: string, stdin: string): Promise<void>;
|
|
58
45
|
close(): Promise<void>;
|
|
59
46
|
subscribe(listener: AgentClientListener): () => void;
|
|
60
47
|
transcript(): {
|
|
@@ -98,4 +85,4 @@ interface JsonWebSocket {
|
|
|
98
85
|
declare function createWebSocketClientTransport(socket: JsonWebSocket): AgentClientTransport;
|
|
99
86
|
declare function createWebSocketServerTransport(socket: JsonWebSocket): AgentServerTransport;
|
|
100
87
|
//#endregion
|
|
101
|
-
export {
|
|
88
|
+
export { AgentClientListener as a, AgentClient as i, createWebSocketClientTransport as n, 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.10.
|
|
4
|
+
"version": "0.10.3",
|
|
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.10.
|
|
23
|
-
"@demicodes/provider": "^0.10.
|
|
24
|
-
"@demicodes/shell": "^0.10.
|
|
25
|
-
"@demicodes/utils": "^0.10.
|
|
22
|
+
"@demicodes/core": "^0.10.3",
|
|
23
|
+
"@demicodes/provider": "^0.10.3",
|
|
24
|
+
"@demicodes/shell": "^0.10.3",
|
|
25
|
+
"@demicodes/utils": "^0.10.3"
|
|
26
26
|
},
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"main": "./dist/index.mjs",
|