summaryrefslogtreecommitdiffhomepage
path: root/packages/kernel/src/runtime/run-turn.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-07 16:07:35 +0900
committerAdam Malczewski <[email protected]>2026-06-07 16:07:35 +0900
commit904c6d7cc882ea6e092f03f9f487d80b75426440 (patch)
tree0b97107a859f8d347071c01a6907c778dd9cd05a /packages/kernel/src/runtime/run-turn.ts
parentefddee1edd2924725a4dd240894666ede97b67b9 (diff)
downloaddispatch-904c6d7cc882ea6e092f03f9f487d80b75426440.tar.gz
dispatch-904c6d7cc882ea6e092f03f9f487d80b75426440.zip
feat(wire,kernel,conversation-store): step grouping via stepId for batched tool calls
Expose a per-step grouping key so a client can render a model's batched/parallel tool calls (those emitted in one step) as one unit, on both the live stream and replayed history. Key = branded StepId, derived turnId#stepIndex (0-based). - [email protected]: required stepId on Turn{Tool,ToolResult}Event; optional stepId on Tool{Call,Result}Chunk (generation provenance on the chunk, not the StoredChunk envelope — StoredChunk unchanged). [email protected] (re-export bump). - kernel-runtime: mint stepId per step; stamp on tool chunks + tool events. - conversation-store: chunk-carried stepId round-trips append/load/loadSince for free; reconcile copies it onto synthesized (interrupted) results. - cli: stepId added to event test fixtures (renderer unchanged). typecheck clean; 509 vitest + 89 bun; biome 0/0. FE courier reply + reference snapshots regenerated in ../dispatch-web.
Diffstat (limited to 'packages/kernel/src/runtime/run-turn.ts')
-rw-r--r--packages/kernel/src/runtime/run-turn.ts10
1 files changed, 9 insertions, 1 deletions
diff --git a/packages/kernel/src/runtime/run-turn.ts b/packages/kernel/src/runtime/run-turn.ts
index 1e98351..b722f3f 100644
--- a/packages/kernel/src/runtime/run-turn.ts
+++ b/packages/kernel/src/runtime/run-turn.ts
@@ -1,4 +1,4 @@
-import type { ChatMessage, Chunk } from "../contracts/conversation.js";
+import type { ChatMessage, Chunk, StepId } from "../contracts/conversation.js";
import type { Logger, Span } from "../contracts/logging.js";
import type { ProviderContract, ProviderEvent, Usage } from "../contracts/provider.js";
import type { EventEmitter, RunTurnInput, RunTurnResult } from "../contracts/runtime.js";
@@ -79,6 +79,7 @@ interface StepContext {
readonly signal: AbortSignal;
readonly conversationId: string;
readonly turnId: string;
+ readonly stepId: StepId;
readonly logger: Logger;
readonly turnSpan: Span | undefined;
readonly toolSpans: Map<string, Span>;
@@ -122,11 +123,13 @@ function processEvent(
toolCallId: event.toolCallId,
toolName: event.toolName,
input: event.input,
+ stepId: ctx.stepId,
});
ctx.emit(
toolCallEvent(
ctx.conversationId,
ctx.turnId,
+ ctx.stepId,
event.toolCallId,
event.toolName,
event.input,
@@ -273,6 +276,7 @@ async function executeStep(ctx: StepContext): Promise<StepResult> {
toolResultEvent(
ctx.conversationId,
ctx.turnId,
+ ctx.stepId,
call.id,
call.name,
result.content,
@@ -288,6 +292,7 @@ async function executeStep(ctx: StepContext): Promise<StepResult> {
toolName: call.name,
content: result.content,
isError,
+ stepId: ctx.stepId,
},
],
});
@@ -357,6 +362,8 @@ export async function runTurn(input: RunTurnInput): Promise<RunTurnResult> {
break;
}
+ const stepId = `${turnId}#${step}` as StepId;
+
const stepResult = await executeStep({
provider: input.provider,
messages,
@@ -367,6 +374,7 @@ export async function runTurn(input: RunTurnInput): Promise<RunTurnResult> {
signal,
conversationId,
turnId,
+ stepId,
logger: turnSpan?.log ?? logger ?? createNoopLogger(),
turnSpan,
toolSpans,