summaryrefslogtreecommitdiffhomepage
path: root/packages/kernel/src/runtime/events.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-26 22:03:19 +0900
committerAdam Malczewski <[email protected]>2026-06-26 22:23:39 +0900
commit727c98c9dae516a2070eb950410314380a20c974 (patch)
tree52aa1022c54f11770be7e4e2a324f0a8b8b8deec /packages/kernel/src/runtime/events.ts
parente59dc11f63b1df51142259bb2c406af8c9c8c2bb (diff)
downloaddispatch-727c98c9dae516a2070eb950410314380a20c974.tar.gz
dispatch-727c98c9dae516a2070eb950410314380a20c974.zip
style: switch from tabs to 2-space indentation
Diffstat (limited to 'packages/kernel/src/runtime/events.ts')
-rw-r--r--packages/kernel/src/runtime/events.ts270
1 files changed, 135 insertions, 135 deletions
diff --git a/packages/kernel/src/runtime/events.ts b/packages/kernel/src/runtime/events.ts
index 5805e28..353b6ca 100644
--- a/packages/kernel/src/runtime/events.ts
+++ b/packages/kernel/src/runtime/events.ts
@@ -3,178 +3,178 @@ import type { AgentEvent } from "../contracts/events.js";
import type { Usage } from "../contracts/provider.js";
export function textDeltaEvent(conversationId: string, turnId: string, delta: string): AgentEvent {
- return { type: "text-delta", conversationId, turnId, delta };
+ return { type: "text-delta", conversationId, turnId, delta };
}
export function reasoningDeltaEvent(
- conversationId: string,
- turnId: string,
- delta: string,
+ conversationId: string,
+ turnId: string,
+ delta: string,
): AgentEvent {
- return { type: "reasoning-delta", conversationId, turnId, delta };
+ return { type: "reasoning-delta", conversationId, turnId, delta };
}
export function toolCallEvent(
- conversationId: string,
- turnId: string,
- stepId: StepId,
- toolCallId: string,
- toolName: string,
- input: unknown,
+ conversationId: string,
+ turnId: string,
+ stepId: StepId,
+ toolCallId: string,
+ toolName: string,
+ input: unknown,
): AgentEvent {
- return { type: "tool-call", conversationId, turnId, stepId, toolCallId, toolName, input };
+ return { type: "tool-call", conversationId, turnId, stepId, toolCallId, toolName, input };
}
export function toolResultEvent(
- conversationId: string,
- turnId: string,
- stepId: StepId,
- toolCallId: string,
- toolName: string,
- content: string,
- isError: boolean,
- durationMs?: number,
+ conversationId: string,
+ turnId: string,
+ stepId: StepId,
+ toolCallId: string,
+ toolName: string,
+ content: string,
+ isError: boolean,
+ durationMs?: number,
): AgentEvent {
- const base = {
- type: "tool-result" as const,
- conversationId,
- turnId,
- stepId,
- toolCallId,
- toolName,
- content,
- isError,
- };
- if (durationMs !== undefined) {
- return { ...base, durationMs };
- }
- return base;
+ const base = {
+ type: "tool-result" as const,
+ conversationId,
+ turnId,
+ stepId,
+ toolCallId,
+ toolName,
+ content,
+ isError,
+ };
+ if (durationMs !== undefined) {
+ return { ...base, durationMs };
+ }
+ return base;
}
export function toolOutputEvent(
- conversationId: string,
- turnId: string,
- toolCallId: string,
- data: string,
- stream: "stdout" | "stderr",
+ conversationId: string,
+ turnId: string,
+ toolCallId: string,
+ data: string,
+ stream: "stdout" | "stderr",
): AgentEvent {
- return { type: "tool-output", conversationId, turnId, toolCallId, data, stream };
+ return { type: "tool-output", conversationId, turnId, toolCallId, data, stream };
}
export function usageEvent(
- conversationId: string,
- turnId: string,
- usage: Usage,
- stepId?: StepId,
+ conversationId: string,
+ turnId: string,
+ usage: Usage,
+ stepId?: StepId,
): AgentEvent {
- if (stepId !== undefined) {
- return { type: "usage", conversationId, turnId, usage, stepId };
- }
- return { type: "usage", conversationId, turnId, usage };
+ if (stepId !== undefined) {
+ return { type: "usage", conversationId, turnId, usage, stepId };
+ }
+ return { type: "usage", conversationId, turnId, usage };
}
export function turnStartEvent(conversationId: string, turnId: string): AgentEvent {
- return { type: "turn-start", conversationId, turnId };
+ return { type: "turn-start", conversationId, turnId };
}
export function stepCompleteEvent(
- conversationId: string,
- turnId: string,
- stepId: StepId,
- timing?: { ttftMs?: number; decodeMs?: number; genTotalMs?: number },
+ conversationId: string,
+ turnId: string,
+ stepId: StepId,
+ timing?: { ttftMs?: number; decodeMs?: number; genTotalMs?: number },
): AgentEvent {
- if (timing !== undefined) {
- if (timing.ttftMs !== undefined) {
- if (timing.decodeMs !== undefined && timing.genTotalMs !== undefined) {
- return {
- type: "step-complete",
- conversationId,
- turnId,
- stepId,
- ttftMs: timing.ttftMs,
- decodeMs: timing.decodeMs,
- genTotalMs: timing.genTotalMs,
- };
- }
- if (timing.genTotalMs !== undefined) {
- return {
- type: "step-complete",
- conversationId,
- turnId,
- stepId,
- ttftMs: timing.ttftMs,
- genTotalMs: timing.genTotalMs,
- };
- }
- return { type: "step-complete", conversationId, turnId, stepId, ttftMs: timing.ttftMs };
- }
- if (timing.genTotalMs !== undefined) {
- return {
- type: "step-complete",
- conversationId,
- turnId,
- stepId,
- genTotalMs: timing.genTotalMs,
- };
- }
- }
- return { type: "step-complete", conversationId, turnId, stepId };
+ if (timing !== undefined) {
+ if (timing.ttftMs !== undefined) {
+ if (timing.decodeMs !== undefined && timing.genTotalMs !== undefined) {
+ return {
+ type: "step-complete",
+ conversationId,
+ turnId,
+ stepId,
+ ttftMs: timing.ttftMs,
+ decodeMs: timing.decodeMs,
+ genTotalMs: timing.genTotalMs,
+ };
+ }
+ if (timing.genTotalMs !== undefined) {
+ return {
+ type: "step-complete",
+ conversationId,
+ turnId,
+ stepId,
+ ttftMs: timing.ttftMs,
+ genTotalMs: timing.genTotalMs,
+ };
+ }
+ return { type: "step-complete", conversationId, turnId, stepId, ttftMs: timing.ttftMs };
+ }
+ if (timing.genTotalMs !== undefined) {
+ return {
+ type: "step-complete",
+ conversationId,
+ turnId,
+ stepId,
+ genTotalMs: timing.genTotalMs,
+ };
+ }
+ }
+ return { type: "step-complete", conversationId, turnId, stepId };
}
export function doneEvent(
- conversationId: string,
- turnId: string,
- reason: string,
- durationMs?: number,
- usage?: Usage,
- contextSize?: number,
+ conversationId: string,
+ turnId: string,
+ reason: string,
+ durationMs?: number,
+ usage?: Usage,
+ contextSize?: number,
): AgentEvent {
- if (durationMs !== undefined && usage !== undefined && contextSize !== undefined) {
- return { type: "done", conversationId, turnId, reason, durationMs, usage, contextSize };
- }
- if (durationMs !== undefined && usage !== undefined) {
- return { type: "done", conversationId, turnId, reason, durationMs, usage };
- }
- if (durationMs !== undefined && contextSize !== undefined) {
- return { type: "done", conversationId, turnId, reason, durationMs, contextSize };
- }
- if (usage !== undefined && contextSize !== undefined) {
- return { type: "done", conversationId, turnId, reason, usage, contextSize };
- }
- if (durationMs !== undefined) {
- return { type: "done", conversationId, turnId, reason, durationMs };
- }
- if (usage !== undefined) {
- return { type: "done", conversationId, turnId, reason, usage };
- }
- if (contextSize !== undefined) {
- return { type: "done", conversationId, turnId, reason, contextSize };
- }
- return { type: "done", conversationId, turnId, reason };
+ if (durationMs !== undefined && usage !== undefined && contextSize !== undefined) {
+ return { type: "done", conversationId, turnId, reason, durationMs, usage, contextSize };
+ }
+ if (durationMs !== undefined && usage !== undefined) {
+ return { type: "done", conversationId, turnId, reason, durationMs, usage };
+ }
+ if (durationMs !== undefined && contextSize !== undefined) {
+ return { type: "done", conversationId, turnId, reason, durationMs, contextSize };
+ }
+ if (usage !== undefined && contextSize !== undefined) {
+ return { type: "done", conversationId, turnId, reason, usage, contextSize };
+ }
+ if (durationMs !== undefined) {
+ return { type: "done", conversationId, turnId, reason, durationMs };
+ }
+ if (usage !== undefined) {
+ return { type: "done", conversationId, turnId, reason, usage };
+ }
+ if (contextSize !== undefined) {
+ return { type: "done", conversationId, turnId, reason, contextSize };
+ }
+ return { type: "done", conversationId, turnId, reason };
}
export function errorEvent(
- conversationId: string,
- turnId: string,
- message: string,
- code?: string,
+ conversationId: string,
+ turnId: string,
+ message: string,
+ code?: string,
): AgentEvent {
- if (code !== undefined) {
- return { type: "error", conversationId, turnId, message, code };
- }
- return { type: "error", conversationId, turnId, message };
+ if (code !== undefined) {
+ return { type: "error", conversationId, turnId, message, code };
+ }
+ return { type: "error", conversationId, turnId, message };
}
export function providerRetryEvent(
- conversationId: string,
- turnId: string,
- attempt: number,
- delayMs: number,
- message: string,
- code?: string,
+ conversationId: string,
+ turnId: string,
+ attempt: number,
+ delayMs: number,
+ message: string,
+ code?: string,
): AgentEvent {
- if (code !== undefined) {
- return { type: "provider-retry", conversationId, turnId, attempt, delayMs, message, code };
- }
- return { type: "provider-retry", conversationId, turnId, attempt, delayMs, message };
+ if (code !== undefined) {
+ return { type: "provider-retry", conversationId, turnId, attempt, delayMs, message, code };
+ }
+ return { type: "provider-retry", conversationId, turnId, attempt, delayMs, message };
}