@demicodes/agent 0.25.12 → 0.26.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.
@@ -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-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";
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-BwS3vLGB.mjs";
2
+ import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-5UKD6Dru.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 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";
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-BwS3vLGB.mjs";
2
+ import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-5UKD6Dru.mjs";
3
3
  import { BashAuditEvent, BashEnvironment, BashEnvironmentOptions, Command, CommandMetadataRecord, CommandRegistry, Host, HostStore, ShellCommandStatus, ShellOutputChunk } from "@demicodes/shell";
4
4
  import { AgentProvider, Provider, ProviderSelection } from "@demicodes/provider";
5
5
  import { Block, Model, ModelMediaKind, ModelSelection, ProviderErrorDiagnostics, QueuedMessage, SessionPhase, UserContentBlock } from "@demicodes/core";
package/dist/index.mjs CHANGED
@@ -1122,41 +1122,17 @@ var ProviderTurnLoop = class {
1122
1122
  executed: false,
1123
1123
  stopAfterToolResult: false
1124
1124
  };
1125
- const tools = this.currentTools();
1126
- const toolsByName = new Map(tools.map((tool) => [tool.name, tool]));
1125
+ const toolsByName = new Map(this.currentTools().map((tool) => [tool.name, tool]));
1127
1126
  let stopAfterToolResult = false;
1128
1127
  const previousActivePhase = this.host.getActiveTurnPhase();
1129
1128
  this.host.setActiveTurnPhase("tool_executing");
1130
1129
  try {
1131
- for (const toolCall of pending) {
1130
+ for (const batch of toolCallBatches(pending, toolsByName)) {
1132
1131
  throwIfAborted(this.host.currentSignal());
1133
- const steerContinuationBeforeTool = this.host.steerContinuationCount;
1134
- const tool = toolsByName.get(toolCall.toolName);
1135
- if (!tool) {
1136
- this.host.transcript.completeToolCall(toolCall.toolUseId, [{
1137
- type: "text",
1138
- text: `Tool not found: ${toolCall.toolName}`
1139
- }], true);
1140
- await this.host.commitTranscript();
1141
- if (!options.deferSteerMaterialization) await this.host.materializeSteersArrivedSince(steerContinuationBeforeTool);
1142
- continue;
1143
- }
1144
- const input = parseJsonOrString(toolCall.input);
1145
- const result = await this.invokeToolAsResult(tool, toolCall.toolUseId, input);
1146
- this.host.transcript.completeToolCall(toolCall.toolUseId, filterCorruptImages(result.output), result.isError ?? false, result.view ?? null);
1147
- await this.host.runtime.lifecycle?.({
1148
- type: "after_tool_call",
1149
- agentSessionId: this.host.agentSessionId,
1150
- state: this.host.agentState,
1151
- transcript: this.host.transcript,
1152
- toolCallId: toolCall.toolUseId,
1153
- toolName: toolCall.toolName,
1154
- result,
1155
- metadata: this.host.metadata
1156
- });
1157
- await this.host.commitTranscript();
1158
- if (!options.deferSteerMaterialization) await this.host.materializeSteersArrivedSince(steerContinuationBeforeTool);
1159
- stopAfterToolResult ||= result.stopAfterToolResult === true;
1132
+ const steerContinuationBeforeBatch = this.host.steerContinuationCount;
1133
+ const results = await this.runToolCallBatch(batch, toolsByName);
1134
+ if (!options.deferSteerMaterialization) await this.host.materializeSteersArrivedSince(steerContinuationBeforeBatch);
1135
+ stopAfterToolResult ||= results.some((result) => result.stopAfterToolResult === true);
1160
1136
  }
1161
1137
  } finally {
1162
1138
  this.host.setActiveTurnPhase(previousActivePhase);
@@ -1166,6 +1142,45 @@ var ProviderTurnLoop = class {
1166
1142
  stopAfterToolResult
1167
1143
  };
1168
1144
  }
1145
+ /**
1146
+ * Starts every call of the batch at once and records each result as soon as it
1147
+ * arrives, one at a time, so transcript commits never overlap. Waits for every
1148
+ * call to settle before rethrowing an abort, so no call records after the turn ends.
1149
+ */
1150
+ async runToolCallBatch(batch, toolsByName) {
1151
+ let recording = Promise.resolve();
1152
+ const outcomes = await Promise.allSettled(batch.map(async (toolCall) => {
1153
+ const tool = toolsByName.get(toolCall.toolName);
1154
+ const result = tool ? await this.invokeToolAsResult(tool, toolCall.toolUseId, parseJsonOrString(toolCall.input)) : {
1155
+ output: [{
1156
+ type: "text",
1157
+ text: `Tool not found: ${toolCall.toolName}`
1158
+ }],
1159
+ isError: true
1160
+ };
1161
+ const recorded = recording.then(() => this.recordToolResult(toolCall, result, tool !== void 0));
1162
+ recording = recorded.catch(() => {});
1163
+ await recorded;
1164
+ return result;
1165
+ }));
1166
+ const failure = outcomes.find((outcome) => outcome.status === "rejected");
1167
+ if (failure) throw failure.reason;
1168
+ return outcomes.map((outcome) => outcome.value);
1169
+ }
1170
+ async recordToolResult(toolCall, result, isKnownTool) {
1171
+ this.host.transcript.completeToolCall(toolCall.toolUseId, filterCorruptImages(result.output), result.isError ?? false, result.view ?? null);
1172
+ if (isKnownTool) await this.host.runtime.lifecycle?.({
1173
+ type: "after_tool_call",
1174
+ agentSessionId: this.host.agentSessionId,
1175
+ state: this.host.agentState,
1176
+ transcript: this.host.transcript,
1177
+ toolCallId: toolCall.toolUseId,
1178
+ toolName: toolCall.toolName,
1179
+ result,
1180
+ metadata: this.host.metadata
1181
+ });
1182
+ await this.host.commitTranscript();
1183
+ }
1169
1184
  async invokeTool(tool, toolCallId, input) {
1170
1185
  const signal = this.host.currentSignal();
1171
1186
  return abortable(Promise.resolve(tool.invoke({
@@ -1239,6 +1254,20 @@ var ProviderTurnLoop = class {
1239
1254
  return usage.inputTokens + usage.outputTokens + usage.cacheReadTokens + usage.cacheWriteTokens >= resolveCompactionThreshold(contextWindow, this.host.thresholdRatio, this.host.thresholdTokens);
1240
1255
  }
1241
1256
  };
1257
+ /** Groups adjacent calls of concurrent tools; every other call forms a batch of its own. */
1258
+ function toolCallBatches(pending, toolsByName) {
1259
+ const batches = [];
1260
+ for (const toolCall of pending) {
1261
+ const isConcurrent = toolsByName.get(toolCall.toolName)?.concurrent === true;
1262
+ const last = batches.at(-1);
1263
+ if (isConcurrent && last?.isConcurrent) last.calls.push(toolCall);
1264
+ else batches.push({
1265
+ isConcurrent,
1266
+ calls: [toolCall]
1267
+ });
1268
+ }
1269
+ return batches.map((batch) => batch.calls);
1270
+ }
1242
1271
  function toToolDefinition(tool) {
1243
1272
  return {
1244
1273
  name: tool.name,
@@ -2328,7 +2357,8 @@ function createStandardAgentTools(options) {
2328
2357
  return [
2329
2358
  {
2330
2359
  name: "shell_exec",
2331
- description: "Start a shell script and observe it for up to timeoutMs. timeoutMs is an observation window, not a kill deadline: at timeoutMs the command keeps running and a command handle (commandId) is returned. Completed short output is returned directly. shell_exec never ends the turn or schedules a wakeup on its own. Set timeoutMs to how long the command is expected to take, such as 30000 to 120000 for queries, log or API lookups, tests and builds, so its result returns in this call; a timeoutMs shorter than the command only adds shell_status round trips. Use a short timeoutMs only for a server, watcher or long job you intend to leave running. Commands that do not depend on each other go in one response as several shell_exec calls.",
2360
+ concurrent: true,
2361
+ description: "Start a shell script and observe it for up to timeoutMs. timeoutMs is an observation window, not a kill deadline: at timeoutMs the command keeps running and a command handle (commandId) is returned. Completed short output is returned directly. shell_exec never ends the turn or schedules a wakeup on its own. Set timeoutMs to how long the command is expected to take, such as 30000 to 120000 for queries, log or API lookups, tests and builds, so its result returns in this call; a timeoutMs shorter than the command only adds shell_status round trips. Use a short timeoutMs only for a server, watcher or long job you intend to leave running. Commands that do not depend on each other go in one response as several shell_exec calls, which run at the same time.",
2332
2362
  inputSchema: {
2333
2363
  type: "object",
2334
2364
  additionalProperties: false,
@@ -2369,6 +2399,7 @@ function createStandardAgentTools(options) {
2369
2399
  },
2370
2400
  {
2371
2401
  name: "shell_status",
2402
+ concurrent: true,
2372
2403
  description: "Read a running command handle status and any new budgeted output preview. Does not wait or write stdin.",
2373
2404
  inputSchema: {
2374
2405
  type: "object",
@@ -2392,6 +2423,7 @@ function createStandardAgentTools(options) {
2392
2423
  },
2393
2424
  {
2394
2425
  name: "shell_write",
2426
+ concurrent: true,
2395
2427
  description: "Write non-empty stdin to a running foreground command and return status with new budgeted output preview. Include a newline for line-oriented prompts.",
2396
2428
  inputSchema: {
2397
2429
  type: "object",
@@ -2419,6 +2451,7 @@ function createStandardAgentTools(options) {
2419
2451
  },
2420
2452
  {
2421
2453
  name: "shell_abort",
2454
+ concurrent: true,
2422
2455
  description: "Stop a running foreground command by commandId.",
2423
2456
  inputSchema: {
2424
2457
  type: "object",
@@ -1,4 +1,4 @@
1
- import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-Qj50JTjx.mjs";
1
+ import { n as AgentServerTransport, t as AgentClientTransport } from "./transport-BwS3vLGB.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;
@@ -248,6 +248,12 @@ interface AbortResult {
248
248
  canAbortAgain: boolean;
249
249
  }
250
250
  interface AgentTool<State = unknown> extends ToolDefinition {
251
+ /**
252
+ * Calls of this tool that a response requests next to each other run at the
253
+ * same time. A tool without it runs alone, after every earlier call of the
254
+ * response has finished and before any later one starts.
255
+ */
256
+ concurrent?: boolean;
251
257
  invoke(ctx: AgentToolInvokeContext<State>, input: unknown): Promise<AgentToolInvokeResult> | AgentToolInvokeResult;
252
258
  }
253
259
  type AgentLifecycleEvent<State> = {
@@ -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-Qj50JTjx.mjs";
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-BwS3vLGB.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.12",
4
+ "version": "0.26.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.25.12",
23
- "@demicodes/provider": "^0.25.12",
24
- "@demicodes/shell": "^0.25.12",
25
- "@demicodes/utils": "^0.25.12",
22
+ "@demicodes/core": "^0.26.0",
23
+ "@demicodes/provider": "^0.26.0",
24
+ "@demicodes/shell": "^0.26.0",
25
+ "@demicodes/utils": "^0.26.0",
26
26
  "zod": "^4.0.0"
27
27
  },
28
28
  "license": "Apache-2.0",