@demicodes/agent 0.12.0 → 0.14.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 CHANGED
@@ -2,21 +2,30 @@
2
2
 
3
3
  The session runtime and transport-neutral client/server protocol for Demi. It
4
4
  owns a turn's lifecycle — queueing, provider streaming, tool execution, steering,
5
- compaction, abort, and yield wakeups — and exposes it through an `AgentClient`
6
- that the REPL and web UI both consume.
5
+ compaction, abort, resume recovery, and yield wakeups — and exposes it through an
6
+ `AgentClient` that the REPL and web UI both consume.
7
7
 
8
8
  - `AgentServer` — owns sessions; `server.client()` returns an in-process client.
9
- - `AgentClient` — `open` / `send` / `steer` / `abort` / `close` / `subscribe`.
10
- - Transports: in-process, stdio (`@demicodes/agent/stdio`), or WebSocket.
9
+ - `AgentClient` — `open` / `send` / `steer` / `resume` / `abort` / `close` /
10
+ `subscribe` / `listConversations`.
11
+ - `AgentSession.clone()` — isolated point-in-time session copies (compaction and
12
+ forks); see [docs/provider-session-clone.md](../../docs/provider-session-clone.md).
13
+ - Transports: in-process, stdio (`@demicodes/agent/stdio`), or WebSocket
14
+ (`createWebSocketClientTransport` from the root entry).
11
15
  - Actions accept caller-defined `metadata` that is available to harness and
12
- tool contexts without becoming transcript or provider content.
16
+ tool contexts without becoming transcript or provider content
17
+ ([docs/action-metadata.md](../../docs/action-metadata.md)).
13
18
 
14
19
  ```ts
15
20
  import { AgentServer } from '@demicodes/agent'
16
21
 
17
22
  const server = new AgentServer({ agent, providers })
18
23
  const client = server.client()
24
+ await client.open(selection, cwd, sessionId)
19
25
  ```
20
26
 
27
+ `sessionId` is caller-owned and required so a conversation is never silently
28
+ un-resumable.
29
+
21
30
  See [Embed the UI](../../docs/guides/embed-the-ui.md). Part of
22
31
  [Demi](../../README.md). Apache-2.0.
@@ -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-Diegnou1.mjs";
2
- import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-c4hu2c0X.mjs";
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-gkyOzXn-.mjs";
2
+ import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-C6bu3Ufc.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,5 +1,5 @@
1
- import { A as AgentTool, B as TranscriptOptions, C as AgentSessionCheckpoint, D as AgentSessionRestoreParams, E as AgentSessionParams, F as SessionEvent, G as resolveRetryPolicy, H as DEFAULT_TURN_RETRY_POLICY, I as SessionEventListener, K as retryDelayMs, L as CompactionWindow, M as AgentToolInvokeContext, N as AgentToolInvokeResult, O as AgentSessionStore, P as ExternalMutationReservation, R as DrainedTranscriptPatches, S as AgentReferenceResolveContext, T as AgentSessionOptions, U as TurnRetryPolicy, V as estimateTranscriptBlockTokens, W as isRetryableCode, _ 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 AgentToolContext, k as AgentSystemPromptContext, 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 AgentSessionCloneParams, x as AgentPromptContext, y as AgentLifecycleEvent, z as TranscriptLog } from "./transport-Diegnou1.mjs";
2
- import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-c4hu2c0X.mjs";
1
+ import { A as AgentTool, B as TranscriptOptions, C as AgentSessionCheckpoint, D as AgentSessionRestoreParams, E as AgentSessionParams, F as SessionEvent, G as resolveRetryPolicy, H as DEFAULT_TURN_RETRY_POLICY, I as SessionEventListener, K as retryDelayMs, L as CompactionWindow, M as AgentToolInvokeContext, N as AgentToolInvokeResult, O as AgentSessionStore, P as ExternalMutationReservation, R as DrainedTranscriptPatches, S as AgentReferenceResolveContext, T as AgentSessionOptions, U as TurnRetryPolicy, V as estimateTranscriptBlockTokens, W as isRetryableCode, _ 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 AgentToolContext, k as AgentSystemPromptContext, 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 AgentSessionCloneParams, x as AgentPromptContext, y as AgentLifecycleEvent, z as TranscriptLog } from "./transport-gkyOzXn-.mjs";
2
+ import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-C6bu3Ufc.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";
package/dist/index.mjs CHANGED
@@ -972,7 +972,7 @@ var ProviderTurnLoop = class {
972
972
  }
973
973
  }
974
974
  async streamAttempt(attempt, policy) {
975
- const request = this.buildInferenceRequest();
975
+ const request = await this.buildInferenceRequest();
976
976
  const attemptStart = this.host.transcript.blocks.length;
977
977
  const run = this.host.provider.run(request);
978
978
  let shouldAutoRecover = false;
@@ -1121,14 +1121,15 @@ var ProviderTurnLoop = class {
1121
1121
  metadata: this.host.metadata
1122
1122
  });
1123
1123
  }
1124
- buildInferenceRequest() {
1124
+ async buildInferenceRequest() {
1125
1125
  const tools = this.currentTools().map(toToolDefinition);
1126
+ const systemPrompt = await this.host.runtime.systemPrompt(this.host.promptContext());
1126
1127
  return {
1127
1128
  sessionId: this.host.agentSessionId,
1128
1129
  turnId: this.host.currentTurnId(),
1129
1130
  requestId: this.host.nextRequestId(),
1130
1131
  modelId: this.host.model.model.id,
1131
- systemPrompt: this.host.runtime.systemPrompt(this.host.promptContext()),
1132
+ systemPrompt,
1132
1133
  cwd: this.host.cwd,
1133
1134
  items: this.host.transcript.collectInferenceItems(),
1134
1135
  tools,
@@ -1873,7 +1874,7 @@ var AgentSession = class AgentSession {
1873
1874
  });
1874
1875
  const resolvedContent = await this.resolveReferences(content);
1875
1876
  await this.applyPendingModelSwitch();
1876
- const preamble = hidden ? null : this.runtime.preamble?.(this.promptContext()) ?? null;
1877
+ const preamble = hidden ? null : await this.runtime.preamble?.(this.promptContext()) ?? null;
1877
1878
  this.transcriptLog.pushUserTurn(this.currentTurnId(), this.model, resolvedContent, preamble, hidden);
1878
1879
  await this.commitTranscript();
1879
1880
  await this.compaction.preflight();
@@ -2909,7 +2910,7 @@ var AgentTransportBindingImpl = class {
2909
2910
  state,
2910
2911
  cwd: frame.cwd
2911
2912
  };
2912
- const commands = agent.commands?.(harnessContext) ?? [];
2913
+ const commands = await agent.commands?.(harnessContext) ?? [];
2913
2914
  const commandRegistry = new CommandRegistry();
2914
2915
  for (const command of commands) commandRegistry.register(command);
2915
2916
  const commandNames = commandRegistry.list().map((command) => command.name);
@@ -1,4 +1,4 @@
1
- import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-Diegnou1.mjs";
1
+ import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-gkyOzXn-.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;
@@ -185,9 +185,9 @@ interface AgentHarness<State = unknown> {
185
185
  initialState(): State;
186
186
  /** Return the same Host object for calls that target the same execution environment. */
187
187
  host(ctx: AgentHarnessContext<State> | AgentHostContext<State>): Host | Promise<Host>;
188
- commands?(ctx: AgentHarnessContext<State>): Command[];
189
- systemPrompt(ctx: AgentSystemPromptContext<State>): string;
190
- preamble?(ctx: AgentPromptContext<State>): string | null;
188
+ commands?(ctx: AgentHarnessContext<State>): Promise<Command[]> | Command[];
189
+ systemPrompt(ctx: AgentSystemPromptContext<State>): Promise<string> | string;
190
+ preamble?(ctx: AgentPromptContext<State>): Promise<string | null> | string | null;
191
191
  resolveReferences?(ctx: AgentReferenceResolveContext<State>, content: UserContentBlock[]): Promise<UserContentBlock[]> | UserContentBlock[];
192
192
  lifecycle?(event: AgentLifecycleEvent<State>): Promise<void> | void;
193
193
  dispose?(ctx: AgentDisposeContext<State>): Promise<void> | void;
@@ -245,8 +245,8 @@ type AgentLifecycleEvent<State> = {
245
245
  interface AgentHarnessRuntime<State> {
246
246
  harnessName: string;
247
247
  initialState(): State;
248
- systemPrompt(ctx: AgentPromptContext<State>): string;
249
- preamble?(ctx: AgentPromptContext<State>): string | null;
248
+ systemPrompt(ctx: AgentPromptContext<State>): Promise<string> | string;
249
+ preamble?(ctx: AgentPromptContext<State>): Promise<string | null> | string | null;
250
250
  resolveReferences?(ctx: AgentReferenceResolveContext<State>, content: UserContentBlock[]): Promise<UserContentBlock[]> | UserContentBlock[];
251
251
  tools(ctx: AgentToolContext<State>): AgentTool<State>[];
252
252
  lifecycle?(event: AgentLifecycleEvent<State>): Promise<void> | void;
@@ -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-Diegnou1.mjs";
1
+ import { b as AgentMetadata, c as ConversationSummary, f as AbortResult, n as AgentServerTransport, s as ClientSessionEvent, t as AgentClientTransport } from "./transport-gkyOzXn-.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.12.0",
4
+ "version": "0.14.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.12.0",
23
- "@demicodes/provider": "^0.12.0",
24
- "@demicodes/shell": "^0.12.0",
25
- "@demicodes/utils": "^0.12.0"
22
+ "@demicodes/core": "^0.14.0",
23
+ "@demicodes/provider": "^0.14.0",
24
+ "@demicodes/shell": "^0.14.0",
25
+ "@demicodes/utils": "^0.14.0"
26
26
  },
27
27
  "license": "Apache-2.0",
28
28
  "main": "./dist/index.mjs",