@demicodes/agent 0.25.0 → 0.25.1
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/index.d.mts +5 -4
- package/dist/index.mjs +31 -15
- package/dist/stdio-transport.d.mts +1 -1
- package/dist/{transport-vzA9vMxT.d.mts → transport-Qj50JTjx.d.mts} +3 -2
- package/dist/{websocket-transport-CyoM_NS1.d.mts → websocket-transport-Ax8tieib.d.mts} +1 -1
- package/package.json +5 -5
package/dist/client-entry.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as TranscriptPatch, l as ServerFrame, n as AgentServerTransport, o as ClientFrame, r as AgentTransport, s as ClientSessionEvent, t as AgentClientTransport, u as ShellCommandStatusLike, x as AgentMetadata } 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 { f as TranscriptPatch, l as ServerFrame, n as AgentServerTransport, o as ClientFrame, r as AgentTransport, s as ClientSessionEvent, t as AgentClientTransport, u as ShellCommandStatusLike, x as AgentMetadata } from "./transport-Qj50JTjx.mjs";
|
|
2
|
+
import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-Ax8tieib.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/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as AgentSystemPromptContext, B as CompactionWindow, C as AgentReferenceResolveContext, D as AgentSessionParams, E as AgentSessionOptions, F as ExternalMutationReservation, G as DEFAULT_TURN_RETRY_POLICY, H as TranscriptLog, I as ModelSwitchApply, J as resolveRetryPolicy, K as TurnRetryPolicy, L as SessionEvent, M as AgentToolContext, N as AgentToolInvokeContext, O as AgentSessionRestoreParams, P as AgentToolInvokeResult, R as SessionEventListener, S as AgentPromptContext, T as AgentSessionCloneParams, U as TranscriptOptions, V as DrainedTranscriptPatches, W as estimateTranscriptBlockTokens, Y as retryDelayMs, _ as AgentHarnessContext, a as createInProcessTransportPair, b as AgentLifecycleEvent, c as ConversationSummary, d as SubagentJob, f as TranscriptPatch, g as AgentHarness, h as AgentDisposeContext, i as InProcessTransportPair, j as AgentTool, k as AgentSessionStore, l as ServerFrame, m as AbortTarget, n as AgentServerTransport, o as ClientFrame, p as AbortResult, q as isRetryableCode, r as AgentTransport, s as ClientSessionEvent, t as AgentClientTransport, u as ShellCommandStatusLike, v as AgentHarnessRuntime, w as AgentSessionCheckpoint, x as AgentMetadata, y as AgentHostContext, z as SubagentProfile } 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 AgentSystemPromptContext, B as CompactionWindow, C as AgentReferenceResolveContext, D as AgentSessionParams, E as AgentSessionOptions, F as ExternalMutationReservation, G as DEFAULT_TURN_RETRY_POLICY, H as TranscriptLog, I as ModelSwitchApply, J as resolveRetryPolicy, K as TurnRetryPolicy, L as SessionEvent, M as AgentToolContext, N as AgentToolInvokeContext, O as AgentSessionRestoreParams, P as AgentToolInvokeResult, R as SessionEventListener, S as AgentPromptContext, T as AgentSessionCloneParams, U as TranscriptOptions, V as DrainedTranscriptPatches, W as estimateTranscriptBlockTokens, Y as retryDelayMs, _ as AgentHarnessContext, a as createInProcessTransportPair, b as AgentLifecycleEvent, c as ConversationSummary, d as SubagentJob, f as TranscriptPatch, g as AgentHarness, h as AgentDisposeContext, i as InProcessTransportPair, j as AgentTool, k as AgentSessionStore, l as ServerFrame, m as AbortTarget, n as AgentServerTransport, o as ClientFrame, p as AbortResult, q as isRetryableCode, r as AgentTransport, s as ClientSessionEvent, t as AgentClientTransport, u as ShellCommandStatusLike, v as AgentHarnessRuntime, w as AgentSessionCheckpoint, x as AgentMetadata, y as AgentHostContext, z as SubagentProfile } from "./transport-Qj50JTjx.mjs";
|
|
2
|
+
import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-Ax8tieib.mjs";
|
|
3
3
|
import { BashAuditEvent, BashEnvironment, BashEnvironmentOptions, Command, CommandMetadataRecord, CommandRegistry, Host, HostStore, ShellCommandStatus, ShellOutputChunk } from "@demicodes/shell";
|
|
4
|
-
import { AgentProvider, Provider } from "@demicodes/provider";
|
|
4
|
+
import { AgentProvider, Provider, ProviderSelection } from "@demicodes/provider";
|
|
5
5
|
import { Block, Model, ModelMediaKind, ModelSelection, ProviderErrorDiagnostics, QueuedMessage, SessionPhase, UserContentBlock } from "@demicodes/core";
|
|
6
6
|
//#region src/recovery.d.ts
|
|
7
7
|
/**
|
|
@@ -521,6 +521,7 @@ interface ChildSupervisorOptions<State> {
|
|
|
521
521
|
shellOptions: Omit<BashEnvironmentOptions, 'host' | 'commands'>;
|
|
522
522
|
prepareShell: PrepareShell | null;
|
|
523
523
|
sessionOptions: AgentServerSessionOptions;
|
|
524
|
+
createRuntime(selection: ProviderSelection): Promise<AgentProvider>;
|
|
524
525
|
/** When false, a child closing never wakes an idle parent; the host app orchestrates the wakeup from the `subagent closed` frame. */
|
|
525
526
|
notifyParentOnIdle: boolean;
|
|
526
527
|
/** Backing store for child checkpoints and job metadata. */
|
|
@@ -621,6 +622,7 @@ declare class ChildSupervisor<State = unknown> {
|
|
|
621
622
|
/** Aborts every live child (each with its subtree); the archive is untouched. */
|
|
622
623
|
abortAll(): Promise<void>;
|
|
623
624
|
private spawn;
|
|
625
|
+
private createChildProvider;
|
|
624
626
|
/**
|
|
625
627
|
* Everything spawn and restore share: the command tree (identical to the
|
|
626
628
|
* owner's — children spawn, message, and observe exactly like any session),
|
|
@@ -631,7 +633,6 @@ declare class ChildSupervisor<State = unknown> {
|
|
|
631
633
|
private attachSession;
|
|
632
634
|
private childStoreKey;
|
|
633
635
|
private childSessionStore;
|
|
634
|
-
private deletePersistedJob;
|
|
635
636
|
/** Shared spawn/resume foreground behaviour: announce the id, wire abort and stdin steers, wait for close, report the outcome. */
|
|
636
637
|
private attendChild;
|
|
637
638
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -3080,8 +3080,11 @@ var ChildSupervisor = class ChildSupervisor {
|
|
|
3080
3080
|
if (this.jobs.has(id)) continue;
|
|
3081
3081
|
try {
|
|
3082
3082
|
await this.restoreJob(id);
|
|
3083
|
-
} catch {
|
|
3084
|
-
|
|
3083
|
+
} catch (error) {
|
|
3084
|
+
this.options.emit({
|
|
3085
|
+
type: "error",
|
|
3086
|
+
message: `Failed to restore subagent "${id}": ${errorMessage(error)}`
|
|
3087
|
+
});
|
|
3085
3088
|
}
|
|
3086
3089
|
}
|
|
3087
3090
|
}
|
|
@@ -3091,15 +3094,15 @@ var ChildSupervisor = class ChildSupervisor {
|
|
|
3091
3094
|
if (meta?.closedPhase) return;
|
|
3092
3095
|
const checkpoint = await this.childSessionStore(id).loadCheckpoint();
|
|
3093
3096
|
if (!meta || !checkpoint) throw new Error("incomplete persisted subagent");
|
|
3094
|
-
const
|
|
3097
|
+
const provider = await this.createChildProvider(checkpoint.model);
|
|
3098
|
+
const job = this.reassembleJob(id, meta, checkpoint, provider);
|
|
3095
3099
|
this.trackTurn(job, job.session.resume(meta.metadata ? { metadata: meta.metadata } : {}));
|
|
3096
3100
|
this.settleJob(job);
|
|
3097
3101
|
await job.ownSupervisor.restore();
|
|
3098
3102
|
}
|
|
3099
3103
|
/** Shared by restore and resume: rebuild a persisted child's job and session from its checkpoint. */
|
|
3100
|
-
reassembleJob(id, meta, checkpoint) {
|
|
3101
|
-
|
|
3102
|
-
if (!parent) throw new Error("subagent supervisor has no owner session");
|
|
3104
|
+
reassembleJob(id, meta, checkpoint, provider) {
|
|
3105
|
+
if (!this.parentSession) throw new Error("subagent supervisor has no owner session");
|
|
3103
3106
|
const profile = this.resolveProfile(meta.profileName ?? void 0);
|
|
3104
3107
|
const { job, runtime } = this.assembleJob({
|
|
3105
3108
|
id,
|
|
@@ -3111,7 +3114,7 @@ var ChildSupervisor = class ChildSupervisor {
|
|
|
3111
3114
|
canSpawnSubagents: meta.canSpawnSubagents !== false
|
|
3112
3115
|
});
|
|
3113
3116
|
const session = AgentSession.fromCheckpoint({
|
|
3114
|
-
provider
|
|
3117
|
+
provider,
|
|
3115
3118
|
runtime,
|
|
3116
3119
|
checkpoint
|
|
3117
3120
|
}, {
|
|
@@ -3146,8 +3149,9 @@ var ChildSupervisor = class ChildSupervisor {
|
|
|
3146
3149
|
spawnedAt: Date.now(),
|
|
3147
3150
|
...meta.canSpawnSubagents === false ? { canSpawnSubagents: false } : {}
|
|
3148
3151
|
};
|
|
3152
|
+
const provider = await this.createChildProvider(checkpoint.model);
|
|
3149
3153
|
await this.options.store.writeJson(this.childStoreKey(id, "job.json"), liveMeta);
|
|
3150
|
-
const job = this.reassembleJob(id, liveMeta, checkpoint);
|
|
3154
|
+
const job = this.reassembleJob(id, liveMeta, checkpoint, provider);
|
|
3151
3155
|
this.trackTurn(job, job.session.send([{
|
|
3152
3156
|
type: "text",
|
|
3153
3157
|
text: message
|
|
@@ -3188,8 +3192,10 @@ var ChildSupervisor = class ChildSupervisor {
|
|
|
3188
3192
|
if (this.isDisposed) throw new Error("owner session is closing");
|
|
3189
3193
|
if (this.jobs.size >= this.options.maxLiveSubagents) throw new Error(`at most ${this.options.maxLiveSubagents} running subagents per session; abort one or wait for a result`);
|
|
3190
3194
|
const profile = this.resolveProfile(input.profileName);
|
|
3191
|
-
const
|
|
3195
|
+
const model = structuredClone(profile.model ?? parent.modelSelection);
|
|
3192
3196
|
const metadata = parent.actionMetadata();
|
|
3197
|
+
const provider = await this.createChildProvider(model);
|
|
3198
|
+
const id = createId();
|
|
3193
3199
|
const profileName = input.profileName ?? null;
|
|
3194
3200
|
const spawnedAt = Date.now();
|
|
3195
3201
|
const canSpawnSubagents = !input.isSpawnForbidden && profile.canSpawnSubagents !== false;
|
|
@@ -3210,8 +3216,8 @@ var ChildSupervisor = class ChildSupervisor {
|
|
|
3210
3216
|
...canSpawnSubagents ? {} : { canSpawnSubagents }
|
|
3211
3217
|
});
|
|
3212
3218
|
const session = new AgentSession({
|
|
3213
|
-
provider
|
|
3214
|
-
model
|
|
3219
|
+
provider,
|
|
3220
|
+
model,
|
|
3215
3221
|
cwd: this.options.cwd,
|
|
3216
3222
|
runtime,
|
|
3217
3223
|
state: this.options.agent.initialState()
|
|
@@ -3228,6 +3234,19 @@ var ChildSupervisor = class ChildSupervisor {
|
|
|
3228
3234
|
this.settleJob(job);
|
|
3229
3235
|
return job;
|
|
3230
3236
|
}
|
|
3237
|
+
async createChildProvider(model) {
|
|
3238
|
+
const parent = this.parentSession;
|
|
3239
|
+
if (!parent || this.isDisposed) throw new Error("owner session is closing");
|
|
3240
|
+
const provider = model.providerId === parent.modelSelection.providerId ? parent.cloneProviderRuntime() : await this.options.createRuntime({
|
|
3241
|
+
providerId: model.providerId,
|
|
3242
|
+
model
|
|
3243
|
+
});
|
|
3244
|
+
if (this.isDisposed) {
|
|
3245
|
+
await provider.dispose?.();
|
|
3246
|
+
throw new Error("owner session is closing");
|
|
3247
|
+
}
|
|
3248
|
+
return provider;
|
|
3249
|
+
}
|
|
3231
3250
|
/**
|
|
3232
3251
|
* Everything spawn and restore share: the command tree (identical to the
|
|
3233
3252
|
* owner's — children spawn, message, and observe exactly like any session),
|
|
@@ -3343,10 +3362,6 @@ var ChildSupervisor = class ChildSupervisor {
|
|
|
3343
3362
|
loadCheckpoint: () => this.options.store.readJson(this.childStoreKey(childId, "checkpoint.json"))
|
|
3344
3363
|
};
|
|
3345
3364
|
}
|
|
3346
|
-
async deletePersistedJob(id) {
|
|
3347
|
-
await this.options.store.delete(this.childStoreKey(id, "checkpoint.json")).catch(noop);
|
|
3348
|
-
await this.options.store.delete(this.childStoreKey(id, "job.json")).catch(noop);
|
|
3349
|
-
}
|
|
3350
3365
|
/** Shared spawn/resume foreground behaviour: announce the id, wire abort and stdin steers, wait for close, report the outcome. */
|
|
3351
3366
|
async attendChild(job, ctx) {
|
|
3352
3367
|
const { io, isJson, signal, stdinStream } = ctx;
|
|
@@ -4257,6 +4272,7 @@ var AgentTransportBindingImpl = class {
|
|
|
4257
4272
|
shellOptions: this.shellOptions,
|
|
4258
4273
|
prepareShell: this.prepareShell,
|
|
4259
4274
|
sessionOptions: this.sessionOptions,
|
|
4275
|
+
createRuntime: (selection) => this.createRuntime(selection),
|
|
4260
4276
|
notifyParentOnIdle: this.notifyParentOnIdle,
|
|
4261
4277
|
store: provisionalHost.store,
|
|
4262
4278
|
storePrefix: `agent-sessions/${agentSessionId}`,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-
|
|
1
|
+
import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-Qj50JTjx.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;
|
|
@@ -196,6 +196,7 @@ interface SubagentProfile<State = unknown> {
|
|
|
196
196
|
readonly?: boolean;
|
|
197
197
|
/** When false, the child cannot spawn subagents of its own (communication and reads remain). */
|
|
198
198
|
canSpawnSubagents?: boolean;
|
|
199
|
+
/** Selects a model from any provider registered on AgentServer; omitted inherits the parent. */
|
|
199
200
|
model?: ModelSelection;
|
|
200
201
|
}
|
|
201
202
|
interface AgentHarness<State = unknown> {
|
|
@@ -205,8 +206,8 @@ interface AgentHarness<State = unknown> {
|
|
|
205
206
|
host(ctx: AgentHarnessContext<State> | AgentHostContext<State>): Host | Promise<Host>;
|
|
206
207
|
commands?(ctx: AgentHarnessContext<State>): Promise<Command[]> | Command[];
|
|
207
208
|
/**
|
|
208
|
-
* Named subagent profiles for `demi agent`.
|
|
209
|
-
*
|
|
209
|
+
* Named subagent profiles for `demi agent`. Omitting --profile always
|
|
210
|
+
* inherits the parent, independently of this list.
|
|
210
211
|
*/
|
|
211
212
|
agents?(ctx: AgentHarnessContext<State>): Promise<SubagentProfile<State>[]> | SubagentProfile<State>[];
|
|
212
213
|
systemPrompt(ctx: AgentSystemPromptContext<State>): Promise<string> | string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as ModelSwitchApply, c as ConversationSummary, n as AgentServerTransport, p as AbortResult, s as ClientSessionEvent, t as AgentClientTransport, x as AgentMetadata } from "./transport-
|
|
1
|
+
import { I as ModelSwitchApply, c as ConversationSummary, n as AgentServerTransport, p as AbortResult, s as ClientSessionEvent, t as AgentClientTransport, x as AgentMetadata } from "./transport-Qj50JTjx.mjs";
|
|
2
2
|
import { ProviderSelection } from "@demicodes/provider";
|
|
3
3
|
import { Block, UserContentBlock } from "@demicodes/core";
|
|
4
4
|
//#region src/client.d.ts
|
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.25.
|
|
4
|
+
"version": "0.25.1",
|
|
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.25.
|
|
23
|
-
"@demicodes/provider": "^0.25.
|
|
24
|
-
"@demicodes/shell": "^0.25.
|
|
25
|
-
"@demicodes/utils": "^0.25.
|
|
22
|
+
"@demicodes/core": "^0.25.1",
|
|
23
|
+
"@demicodes/provider": "^0.25.1",
|
|
24
|
+
"@demicodes/shell": "^0.25.1",
|
|
25
|
+
"@demicodes/utils": "^0.25.1",
|
|
26
26
|
"zod": "^4.0.0"
|
|
27
27
|
},
|
|
28
28
|
"license": "Apache-2.0",
|