Open History to see the last commit
1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3import {
4 EventId,
5 IsoDateTime,
6 NonNegativeInt,
7 ProviderItemId,
8 PositiveInt,
9 RuntimeItemId,
10 RuntimeRequestId,
11 RuntimeTaskId,
12 ThreadId,
13 TrimmedNonEmptyString,
14 TurnId,
15} from "./baseSchemas.ts";
16import { ProviderInstanceId, ProviderDriverKind } from "./providerInstance.ts";
17
18const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
19const UnknownRecordSchema = Schema.Record(Schema.String, Schema.Unknown);
20
21const RuntimeEventRawSource = Schema.Union([
22 Schema.Literal("codex.app-server.notification"),
23 Schema.Literal("codex.app-server.request"),
24 Schema.Literal("codex.eventmsg"),
25 Schema.Literal("claude.sdk.message"),
26 Schema.Literal("claude.sdk.permission"),
27 Schema.Literal("codex.sdk.thread-event"),
28 Schema.Literal("opencode.sdk.event"),
29 Schema.Literal("acp.jsonrpc"),
30 Schema.TemplateLiteral(["acp.", Schema.String, ".extension"]),
31]);
32export type RuntimeEventRawSource = typeof RuntimeEventRawSource.Type;
33
34export const RuntimeEventRaw = Schema.Struct({
35 source: RuntimeEventRawSource,
36 method: Schema.optional(TrimmedNonEmptyStringSchema),
37 messageType: Schema.optional(TrimmedNonEmptyStringSchema),
38 payload: Schema.Unknown,
39});
40export type RuntimeEventRaw = typeof RuntimeEventRaw.Type;
41
42const ProviderRequestId = TrimmedNonEmptyStringSchema;
43export type ProviderRequestId = typeof ProviderRequestId.Type;
44
45const ProviderRefs = Schema.Struct({
46 providerTurnId: Schema.optional(TrimmedNonEmptyStringSchema),
47 providerItemId: Schema.optional(ProviderItemId),
48 providerRequestId: Schema.optional(ProviderRequestId),
49});
50export type ProviderRefs = typeof ProviderRefs.Type;
51
52const RuntimeSessionState = Schema.Literals([
53 "starting",
54 "ready",
55 "running",
56 "waiting",
57 "stopped",
58 "error",
59]);
60export type RuntimeSessionState = typeof RuntimeSessionState.Type;
61
62const RuntimeThreadState = Schema.Literals([
63 "active",
64 "idle",
65 "archived",
66 "closed",
67 "compacted",
68 "error",
69]);
70export type RuntimeThreadState = typeof RuntimeThreadState.Type;
71
72const RuntimeTurnState = Schema.Literals(["completed", "failed", "interrupted", "cancelled"]);
73export type RuntimeTurnState = typeof RuntimeTurnState.Type;
74
75const RuntimePlanStepStatus = Schema.Literals(["pending", "inProgress", "completed"]);
76export type RuntimePlanStepStatus = typeof RuntimePlanStepStatus.Type;
77
78const RuntimeItemStatus = Schema.Literals(["inProgress", "completed", "failed", "declined"]);
79export type RuntimeItemStatus = typeof RuntimeItemStatus.Type;
80
81const RuntimeContentStreamKind = Schema.Literals([
82 "assistant_text",
83 "reasoning_text",
84 "reasoning_summary_text",
85 "plan_text",
86 "command_output",
87 "file_change_output",
88 "unknown",
89]);
90export type RuntimeContentStreamKind = typeof RuntimeContentStreamKind.Type;
91
92const RuntimeSessionExitKind = Schema.Literals(["graceful", "error"]);
93export type RuntimeSessionExitKind = typeof RuntimeSessionExitKind.Type;
94
95const RuntimeErrorClass = Schema.Literals([
96 "provider_error",
97 "transport_error",
98 "permission_error",
99 "validation_error",
100 "unknown",
101]);
102export type RuntimeErrorClass = typeof RuntimeErrorClass.Type;
103
104export const TOOL_LIFECYCLE_ITEM_TYPES = [
105 "command_execution",
106 "file_change",
107 "mcp_tool_call",
108 "dynamic_tool_call",
109 "collab_agent_tool_call",
110 "web_search",
111 "image_view",
112] as const;
113
114export const ToolLifecycleItemType = Schema.Literals(TOOL_LIFECYCLE_ITEM_TYPES);
115export type ToolLifecycleItemType = typeof ToolLifecycleItemType.Type;
116
117export function isToolLifecycleItemType(value: string): value is ToolLifecycleItemType {
118 return TOOL_LIFECYCLE_ITEM_TYPES.includes(value as ToolLifecycleItemType);
119}
120
121export const CanonicalItemType = Schema.Literals([
122 "user_message",
123 "assistant_message",
124 "reasoning",
125 "plan",
126 ...TOOL_LIFECYCLE_ITEM_TYPES,
127 "review_entered",
128 "review_exited",
129 "context_compaction",
130 "error",
131 "unknown",
132]);
133export type CanonicalItemType = typeof CanonicalItemType.Type;
134
135export const CanonicalRequestType = Schema.Literals([
136 "command_execution_approval",
137 "file_read_approval",
138 "file_change_approval",
139 "apply_patch_approval",
140 "exec_command_approval",
141 "tool_user_input",
142 "dynamic_tool_call",
143 "auth_tokens_refresh",
144 "unknown",
145]);
146export type CanonicalRequestType = typeof CanonicalRequestType.Type;
147
148const ProviderRuntimeEventType = Schema.Literals([
149 "session.started",
150 "session.configured",
151 "session.state.changed",
152 "session.exited",
153 "thread.started",
154 "thread.state.changed",
155 "thread.metadata.updated",
156 "thread.token-usage.updated",
157 "thread.realtime.started",
158 "thread.realtime.item-added",
159 "thread.realtime.audio.delta",
160 "thread.realtime.error",
161 "thread.realtime.closed",
162 "turn.started",
163 "turn.completed",
164 "turn.aborted",
165 "turn.plan.updated",
166 "turn.proposed.delta",
167 "turn.proposed.completed",
168 "turn.diff.updated",
169 "item.started",
170 "item.updated",
171 "item.completed",
172 "content.delta",
173 "request.opened",
174 "request.resolved",
175 "user-input.requested",
176 "user-input.resolved",
177 "task.started",
178 "task.progress",
179 "task.updated",
180 "task.completed",
181 "hook.started",
182 "hook.progress",
183 "hook.completed",
184 "tool.progress",
185 "tool.summary",
186 "auth.status",
187 "account.updated",
188 "account.rate-limits.updated",
189 "mcp.status.updated",
190 "mcp.oauth.completed",
191 "model.rerouted",
192 "config.warning",
193 "deprecation.notice",
194 "files.persisted",
195 "runtime.warning",
196 "runtime.error",
197]);
198export type ProviderRuntimeEventType = typeof ProviderRuntimeEventType.Type;
199
200const SessionStartedType = Schema.Literal("session.started");
201const SessionConfiguredType = Schema.Literal("session.configured");
202const SessionStateChangedType = Schema.Literal("session.state.changed");
203const SessionExitedType = Schema.Literal("session.exited");
204const ThreadStartedType = Schema.Literal("thread.started");
205const ThreadStateChangedType = Schema.Literal("thread.state.changed");
206const ThreadMetadataUpdatedType = Schema.Literal("thread.metadata.updated");
207const ThreadTokenUsageUpdatedType = Schema.Literal("thread.token-usage.updated");
208const ThreadRealtimeStartedType = Schema.Literal("thread.realtime.started");
209const ThreadRealtimeItemAddedType = Schema.Literal("thread.realtime.item-added");
210const ThreadRealtimeAudioDeltaType = Schema.Literal("thread.realtime.audio.delta");
211const ThreadRealtimeErrorType = Schema.Literal("thread.realtime.error");
212const ThreadRealtimeClosedType = Schema.Literal("thread.realtime.closed");
213const TurnStartedType = Schema.Literal("turn.started");
214const TurnCompletedType = Schema.Literal("turn.completed");
215const TurnAbortedType = Schema.Literal("turn.aborted");
216const TurnPlanUpdatedType = Schema.Literal("turn.plan.updated");
217const TurnProposedDeltaType = Schema.Literal("turn.proposed.delta");
218const TurnProposedCompletedType = Schema.Literal("turn.proposed.completed");
219const TurnDiffUpdatedType = Schema.Literal("turn.diff.updated");
220const ItemStartedType = Schema.Literal("item.started");
221const ItemUpdatedType = Schema.Literal("item.updated");
222const ItemCompletedType = Schema.Literal("item.completed");
223const ContentDeltaType = Schema.Literal("content.delta");
224const RequestOpenedType = Schema.Literal("request.opened");
225const RequestResolvedType = Schema.Literal("request.resolved");
226const UserInputRequestedType = Schema.Literal("user-input.requested");
227const UserInputResolvedType = Schema.Literal("user-input.resolved");
228const TaskStartedType = Schema.Literal("task.started");
229const TaskProgressType = Schema.Literal("task.progress");
230const TaskUpdatedType = Schema.Literal("task.updated");
231const TaskCompletedType = Schema.Literal("task.completed");
232const HookStartedType = Schema.Literal("hook.started");
233const HookProgressType = Schema.Literal("hook.progress");
234const HookCompletedType = Schema.Literal("hook.completed");
235const ToolProgressType = Schema.Literal("tool.progress");
236const ToolSummaryType = Schema.Literal("tool.summary");
237const AuthStatusType = Schema.Literal("auth.status");
238const AccountUpdatedType = Schema.Literal("account.updated");
239const AccountRateLimitsUpdatedType = Schema.Literal("account.rate-limits.updated");
240const McpStatusUpdatedType = Schema.Literal("mcp.status.updated");
241const McpOauthCompletedType = Schema.Literal("mcp.oauth.completed");
242const ModelReroutedType = Schema.Literal("model.rerouted");
243const ConfigWarningType = Schema.Literal("config.warning");
244const DeprecationNoticeType = Schema.Literal("deprecation.notice");
245const FilesPersistedType = Schema.Literal("files.persisted");
246const ToolDeniedType = Schema.Literal("tool.denied");
247const RuntimeWarningType = Schema.Literal("runtime.warning");
248const RuntimeErrorType = Schema.Literal("runtime.error");
249
250const ProviderRuntimeEventBase = Schema.Struct({
251 eventId: EventId,
252 provider: ProviderDriverKind,
253 // Optional during the driver/instance migration. See providerInstance.ts
254 // for the routing-key-vs-driver-id distinction. Once every emitter
255 // populates it (post-slice-4), routing flips to instance-id-only.
256 providerInstanceId: Schema.optional(ProviderInstanceId),
257 threadId: ThreadId,
258 createdAt: IsoDateTime,
259 turnId: Schema.optional(TurnId),
260 itemId: Schema.optional(RuntimeItemId),
261 requestId: Schema.optional(RuntimeRequestId),
262 providerRefs: Schema.optional(ProviderRefs),
263 raw: Schema.optional(RuntimeEventRaw),
264});
265export type ProviderRuntimeEventBase = typeof ProviderRuntimeEventBase.Type;
266
267const SessionStartedPayload = Schema.Struct({
268 message: Schema.optional(TrimmedNonEmptyStringSchema),
269 resume: Schema.optional(Schema.Unknown),
270});
271export type SessionStartedPayload = typeof SessionStartedPayload.Type;
272
273const SessionConfiguredPayload = Schema.Struct({
274 config: UnknownRecordSchema,
275});
276export type SessionConfiguredPayload = typeof SessionConfiguredPayload.Type;
277
278const SessionStateChangedPayload = Schema.Struct({
279 state: RuntimeSessionState,
280 reason: Schema.optional(TrimmedNonEmptyStringSchema),
281 detail: Schema.optional(Schema.Unknown),
282});
283export type SessionStateChangedPayload = typeof SessionStateChangedPayload.Type;
284
285const SessionExitedPayload = Schema.Struct({
286 reason: Schema.optional(TrimmedNonEmptyStringSchema),
287 recoverable: Schema.optional(Schema.Boolean),
288 exitKind: Schema.optional(RuntimeSessionExitKind),
289});
290export type SessionExitedPayload = typeof SessionExitedPayload.Type;
291
292const ThreadStartedPayload = Schema.Struct({
293 providerThreadId: Schema.optional(TrimmedNonEmptyStringSchema),
294});
295export type ThreadStartedPayload = typeof ThreadStartedPayload.Type;
296
297const ThreadStateChangedPayload = Schema.Struct({
298 state: RuntimeThreadState,
299 detail: Schema.optional(Schema.Unknown),
300});
301export type ThreadStateChangedPayload = typeof ThreadStateChangedPayload.Type;
302
303const ThreadMetadataUpdatedPayload = Schema.Struct({
304 name: Schema.optional(TrimmedNonEmptyStringSchema),
305 metadata: Schema.optional(UnknownRecordSchema),
306});
307export type ThreadMetadataUpdatedPayload = typeof ThreadMetadataUpdatedPayload.Type;
308
309export const ThreadTokenUsageSnapshot = Schema.Struct({
310 usedTokens: NonNegativeInt,
311 totalProcessedTokens: Schema.optional(NonNegativeInt),
312 maxTokens: Schema.optional(PositiveInt),
313 inputTokens: Schema.optional(NonNegativeInt),
314 cachedInputTokens: Schema.optional(NonNegativeInt),
315 outputTokens: Schema.optional(NonNegativeInt),
316 reasoningOutputTokens: Schema.optional(NonNegativeInt),
317 lastUsedTokens: Schema.optional(NonNegativeInt),
318 lastInputTokens: Schema.optional(NonNegativeInt),
319 lastCachedInputTokens: Schema.optional(NonNegativeInt),
320 lastOutputTokens: Schema.optional(NonNegativeInt),
321 lastReasoningOutputTokens: Schema.optional(NonNegativeInt),
322 toolUses: Schema.optional(NonNegativeInt),
323 durationMs: Schema.optional(NonNegativeInt),
324 compactsAutomatically: Schema.optional(Schema.Boolean),
325});
326export type ThreadTokenUsageSnapshot = typeof ThreadTokenUsageSnapshot.Type;
327
328const ThreadTokenUsageUpdatedPayload = Schema.Struct({
329 usage: ThreadTokenUsageSnapshot,
330});
331export type ThreadTokenUsageUpdatedPayload = typeof ThreadTokenUsageUpdatedPayload.Type;
332
333const ThreadRealtimeStartedPayload = Schema.Struct({
334 realtimeSessionId: Schema.optional(TrimmedNonEmptyStringSchema),
335});
336export type ThreadRealtimeStartedPayload = typeof ThreadRealtimeStartedPayload.Type;
337
338const ThreadRealtimeItemAddedPayload = Schema.Struct({
339 item: Schema.Unknown,
340});
341export type ThreadRealtimeItemAddedPayload = typeof ThreadRealtimeItemAddedPayload.Type;
342
343const ThreadRealtimeAudioDeltaPayload = Schema.Struct({
344 audio: Schema.Unknown,
345});
346export type ThreadRealtimeAudioDeltaPayload = typeof ThreadRealtimeAudioDeltaPayload.Type;
347
348const ThreadRealtimeErrorPayload = Schema.Struct({
349 message: TrimmedNonEmptyStringSchema,
350});
351export type ThreadRealtimeErrorPayload = typeof ThreadRealtimeErrorPayload.Type;
352
353const ThreadRealtimeClosedPayload = Schema.Struct({
354 reason: Schema.optional(TrimmedNonEmptyStringSchema),
355});
356export type ThreadRealtimeClosedPayload = typeof ThreadRealtimeClosedPayload.Type;
357
358const TurnStartedPayload = Schema.Struct({
359 model: Schema.optional(TrimmedNonEmptyStringSchema),
360 effort: Schema.optional(TrimmedNonEmptyStringSchema),
361});
362export type TurnStartedPayload = typeof TurnStartedPayload.Type;
363
364const TurnCompletedPayload = Schema.Struct({
365 state: RuntimeTurnState,
366 actualModel: Schema.optional(TrimmedNonEmptyStringSchema),
367 stopReason: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
368 usage: Schema.optional(Schema.Unknown),
369 modelUsage: Schema.optional(UnknownRecordSchema),
370 totalCostUsd: Schema.optional(Schema.Number),
371 errorMessage: Schema.optional(TrimmedNonEmptyStringSchema),
372});
373export type TurnCompletedPayload = typeof TurnCompletedPayload.Type;
374
375const TurnAbortedPayload = Schema.Struct({
376 reason: TrimmedNonEmptyStringSchema,
377});
378export type TurnAbortedPayload = typeof TurnAbortedPayload.Type;
379
380const RuntimePlanStep = Schema.Struct({
381 step: TrimmedNonEmptyStringSchema,
382 status: RuntimePlanStepStatus,
383});
384export type RuntimePlanStep = typeof RuntimePlanStep.Type;
385
386const TurnPlanUpdatedPayload = Schema.Struct({
387 explanation: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
388 plan: Schema.Array(RuntimePlanStep),
389});
390export type TurnPlanUpdatedPayload = typeof TurnPlanUpdatedPayload.Type;
391
392const TurnProposedDeltaPayload = Schema.Struct({
393 delta: Schema.String,
394});
395export type TurnProposedDeltaPayload = typeof TurnProposedDeltaPayload.Type;
396
397const TurnProposedCompletedPayload = Schema.Struct({
398 planMarkdown: TrimmedNonEmptyStringSchema,
399});
400export type TurnProposedCompletedPayload = typeof TurnProposedCompletedPayload.Type;
401
402const TurnDiffUpdatedPayload = Schema.Struct({
403 unifiedDiff: Schema.String,
404});
405export type TurnDiffUpdatedPayload = typeof TurnDiffUpdatedPayload.Type;
406
407export const ItemLifecyclePayload = Schema.Struct({
408 itemType: CanonicalItemType,
409 status: Schema.optional(RuntimeItemStatus),
410 title: Schema.optional(TrimmedNonEmptyStringSchema),
411 detail: Schema.optional(TrimmedNonEmptyStringSchema),
412 data: Schema.optional(Schema.Unknown),
413 /**
414 * Owning agent when this item ran inside a subagent (resolved from the
415 * SDK's parent_tool_use_id). Clients re-home attributed items out of the
416 * main timeline and into the owning agent's Agents-surface row.
417 */
418 agentId: Schema.optional(TrimmedNonEmptyStringSchema),
419 parentToolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
420});
421export type ItemLifecyclePayload = typeof ItemLifecyclePayload.Type;
422
423const ContentDeltaPayload = Schema.Struct({
424 streamKind: RuntimeContentStreamKind,
425 delta: Schema.String,
426 contentIndex: Schema.optional(Schema.Int),
427 summaryIndex: Schema.optional(Schema.Int),
428});
429export type ContentDeltaPayload = typeof ContentDeltaPayload.Type;
430
431const RequestOpenedPayload = Schema.Struct({
432 requestType: CanonicalRequestType,
433 detail: Schema.optional(TrimmedNonEmptyStringSchema),
434 args: Schema.optional(Schema.Unknown),
435});
436export type RequestOpenedPayload = typeof RequestOpenedPayload.Type;
437
438const RequestResolvedPayload = Schema.Struct({
439 requestType: CanonicalRequestType,
440 decision: Schema.optional(TrimmedNonEmptyStringSchema),
441 resolution: Schema.optional(Schema.Unknown),
442});
443export type RequestResolvedPayload = typeof RequestResolvedPayload.Type;
444
445const UserInputQuestionOption = Schema.Struct({
446 label: TrimmedNonEmptyStringSchema,
447 description: TrimmedNonEmptyStringSchema,
448});
449export type UserInputQuestionOption = typeof UserInputQuestionOption.Type;
450
451export const UserInputQuestion = Schema.Struct({
452 id: TrimmedNonEmptyStringSchema,
453 header: TrimmedNonEmptyStringSchema,
454 question: TrimmedNonEmptyStringSchema,
455 options: Schema.Array(UserInputQuestionOption),
456 multiSelect: Schema.optional(Schema.Boolean).pipe(
457 Schema.withConstructorDefault(Effect.succeed(false)),
458 ),
459});
460export type UserInputQuestion = typeof UserInputQuestion.Type;
461
462const UserInputRequestedPayload = Schema.Struct({
463 questions: Schema.Array(UserInputQuestion),
464});
465export type UserInputRequestedPayload = typeof UserInputRequestedPayload.Type;
466
467const UserInputResolvedPayload = Schema.Struct({
468 answers: UnknownRecordSchema,
469});
470export type UserInputResolvedPayload = typeof UserInputResolvedPayload.Type;
471
472/**
473 * Typed per-task usage rollup. Field names match the orchestration-v2 subagent
474 * usage vocabulary (#4779) so the eventual migration is a rename, not a remap.
475 * Claude reports per-activation deltas; Codex reports cumulative totals — the
476 * merge strategy is provider-specific and lives in client-runtime.
477 */
478export const RuntimeTaskUsage = Schema.Struct({
479 totalTokens: NonNegativeInt,
480 inputTokens: Schema.optional(NonNegativeInt),
481 cachedInputTokens: Schema.optional(NonNegativeInt),
482 outputTokens: Schema.optional(NonNegativeInt),
483 reasoningOutputTokens: Schema.optional(NonNegativeInt),
484 toolUses: Schema.optional(NonNegativeInt),
485 durationMs: Schema.optional(NonNegativeInt),
486});
487export type RuntimeTaskUsage = typeof RuntimeTaskUsage.Type;
488
489export const TaskWorkflowPhase = Schema.Struct({
490 index: NonNegativeInt,
491 title: TrimmedNonEmptyStringSchema,
492});
493export type TaskWorkflowPhase = typeof TaskWorkflowPhase.Type;
494
495export const TaskRunHandles = Schema.Struct({
496 runId: Schema.optional(TrimmedNonEmptyStringSchema),
497 scriptPath: Schema.optional(TrimmedNonEmptyStringSchema),
498 transcriptDir: Schema.optional(TrimmedNonEmptyStringSchema),
499 /** Only http/https URLs may be stored here — sanitized at the adapter. */
500 sessionUrl: Schema.optional(TrimmedNonEmptyStringSchema),
501});
502export type TaskRunHandles = typeof TaskRunHandles.Type;
503
504/**
505 * Watch-loop task types: Monitor-tool tasks plus background shells (a shell
506 * that outlives its turn is in practice a watch loop). Canonical single copy —
507 * the server liveness registry, ingestion's agentKind stamp, and the client
508 * fold's legacy fallback all classify with these sets.
509 */
510export const MONITOR_TASK_TYPES: ReadonlySet<string> = new Set([
511 "monitor",
512 "monitor_mcp",
513 "local_bash",
514 "shell",
515]);
516/** Task types that are neither agents nor watch loops (plan-mode bookkeeping). */
517export const INERT_TASK_TYPES: ReadonlySet<string> = new Set(["plan", "dream"]);
518
519/**
520 * Agent-vs-background classification, stamped by ingestion as `agentKind` so
521 * persisted rows are self-describing. A deliberate denylist: the SDK's
522 * agent-flavored type names drift (subagent, local_agent, local_workflow, …)
523 * and an allowlist silently dropped real subagents when "local_agent"
524 * appeared. A task launched from inside a subagent (agentId set) is
525 * agent-internal background work UNLESS it is itself agent-flavored — a
526 * nested agent can outlive its parent and stays in the roster.
527 */
528export function classifyTaskAgentKind(input: {
529 readonly taskType?: string | undefined;
530 readonly agentId?: string | undefined;
531}): "agent" | "background" {
532 const { taskType, agentId } = input;
533 const nonAgentType =
534 taskType !== undefined && (MONITOR_TASK_TYPES.has(taskType) || INERT_TASK_TYPES.has(taskType));
535 if (agentId !== undefined && agentId.trim().length > 0) {
536 return taskType === undefined || nonAgentType ? "background" : "agent";
537 }
538 return nonAgentType ? "background" : "agent";
539}
540
541/**
542 * Optional agent-identity linkage carried on every task lifecycle payload.
543 * Repeated on progress and terminal rows (not just start) so client folds can
544 * reconstruct an agent even when its start row aged out of activity retention.
545 * All fields optional: old emitters and old rows decode unchanged.
546 */
547const taskAgentLinkageFields = {
548 /** SDK task_type (subagent/shell/monitor/local_workflow/…), repeated on
549 * every row so folds can classify without the start row. */
550 taskType: Schema.optional(TrimmedNonEmptyStringSchema),
551 /**
552 * Server-stamped classification (classifyTaskAgentKind at ingestion).
553 * Clients trust this stamp outright; rows without it (legacy, pre-stamp)
554 * fall back to client-side heuristics.
555 */
556 agentKind: Schema.optional(Schema.Literals(["agent", "background"])),
557 /**
558 * Owning agent when the task itself was launched from inside a subagent
559 * (e.g. a subagent's background shell). Clients treat such tasks as
560 * agent-internal and keep them out of the parent work log.
561 */
562 agentId: Schema.optional(TrimmedNonEmptyStringSchema),
563 title: Schema.optional(TrimmedNonEmptyStringSchema),
564 role: Schema.optional(TrimmedNonEmptyStringSchema),
565 model: Schema.optional(TrimmedNonEmptyStringSchema),
566 /** Reasoning effort when known (e.g. "high"). Open string: provider vocabularies differ. */
567 effort: Schema.optional(TrimmedNonEmptyStringSchema),
568 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
569 parentAgentId: Schema.optional(TrimmedNonEmptyStringSchema),
570 workflowName: Schema.optional(TrimmedNonEmptyStringSchema),
571 agentIndex: Schema.optional(NonNegativeInt),
572 phaseIndex: Schema.optional(NonNegativeInt),
573 phaseTitle: Schema.optional(TrimmedNonEmptyStringSchema),
574 phases: Schema.optional(Schema.Array(TaskWorkflowPhase)),
575 attempt: Schema.optional(NonNegativeInt),
576 runHandles: Schema.optional(TaskRunHandles),
577 outputFile: Schema.optional(TrimmedNonEmptyStringSchema),
578 /** Codex agent hierarchy path, e.g. "/root/marlow". */
579 agentPath: Schema.optional(TrimmedNonEmptyStringSchema),
580 /**
581 * Set on provider-synthesized child-agent events (Codex) whose activity
582 * belongs in the Agents surface, never the parent timeline.
583 */
584 timelineBypass: Schema.optional(Schema.Boolean),
585} as const;
586
587export const TaskAgentLinkage = Schema.Struct(taskAgentLinkageFields);
588export type TaskAgentLinkage = typeof TaskAgentLinkage.Type;
589
590const TaskStartedPayload = Schema.Struct({
591 taskId: RuntimeTaskId,
592 description: Schema.optional(TrimmedNonEmptyStringSchema),
593 ...taskAgentLinkageFields,
594});
595export type TaskStartedPayload = typeof TaskStartedPayload.Type;
596
597export const RuntimeTaskStatus = Schema.Literals([
598 "pending",
599 "running",
600 "waiting",
601 "idle",
602 "completed",
603 "failed",
604 "cancelled",
605 "interrupted",
606]);
607export type RuntimeTaskStatus = typeof RuntimeTaskStatus.Type;
608
609const TaskProgressPayload = Schema.Struct({
610 taskId: RuntimeTaskId,
611 description: TrimmedNonEmptyStringSchema,
612 summary: Schema.optional(TrimmedNonEmptyStringSchema),
613 usage: Schema.optional(Schema.Unknown),
614 typedUsage: Schema.optional(RuntimeTaskUsage),
615 lastToolName: Schema.optional(TrimmedNonEmptyStringSchema),
616 /** Present on synthesized member/child progress rows that carry state. */
617 status: Schema.optional(RuntimeTaskStatus),
618 error: Schema.optional(TrimmedNonEmptyStringSchema),
619 ...taskAgentLinkageFields,
620});
621export type TaskProgressPayload = typeof TaskProgressPayload.Type;
622
623/**
624 * Non-terminal status patch (from the Claude SDK's task_updated, which main
625 * previously dropped). killed→cancelled and paused→idle are mapped at the
626 * adapter so the wire only carries the shared vocabulary.
627 */
628const TaskUpdatedPayload = Schema.Struct({
629 taskId: RuntimeTaskId,
630 status: Schema.optional(RuntimeTaskStatus),
631 description: Schema.optional(TrimmedNonEmptyStringSchema),
632 error: Schema.optional(TrimmedNonEmptyStringSchema),
633 endedAt: Schema.optional(IsoDateTime),
634 isBackgrounded: Schema.optional(Schema.Boolean),
635 ...taskAgentLinkageFields,
636});
637export type TaskUpdatedPayload = typeof TaskUpdatedPayload.Type;
638
639const TaskCompletedPayload = Schema.Struct({
640 taskId: RuntimeTaskId,
641 status: Schema.Literals(["completed", "failed", "stopped"]),
642 summary: Schema.optional(TrimmedNonEmptyStringSchema),
643 usage: Schema.optional(Schema.Unknown),
644 typedUsage: Schema.optional(RuntimeTaskUsage),
645 ...taskAgentLinkageFields,
646});
647export type TaskCompletedPayload = typeof TaskCompletedPayload.Type;
648
649const HookStartedPayload = Schema.Struct({
650 hookId: TrimmedNonEmptyStringSchema,
651 hookName: TrimmedNonEmptyStringSchema,
652 hookEvent: TrimmedNonEmptyStringSchema,
653});
654export type HookStartedPayload = typeof HookStartedPayload.Type;
655
656const HookProgressPayload = Schema.Struct({
657 hookId: TrimmedNonEmptyStringSchema,
658 output: Schema.optional(Schema.String),
659 stdout: Schema.optional(Schema.String),
660 stderr: Schema.optional(Schema.String),
661});
662export type HookProgressPayload = typeof HookProgressPayload.Type;
663
664const HookCompletedPayload = Schema.Struct({
665 hookId: TrimmedNonEmptyStringSchema,
666 outcome: Schema.Literals(["success", "error", "cancelled"]),
667 output: Schema.optional(Schema.String),
668 stdout: Schema.optional(Schema.String),
669 stderr: Schema.optional(Schema.String),
670 exitCode: Schema.optional(Schema.Int),
671});
672export type HookCompletedPayload = typeof HookCompletedPayload.Type;
673
674const ToolProgressPayload = Schema.Struct({
675 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
676 toolName: Schema.optional(TrimmedNonEmptyStringSchema),
677 summary: Schema.optional(TrimmedNonEmptyStringSchema),
678 elapsedSeconds: Schema.optional(Schema.Number),
679 /** Owning task/agent when the tool ran inside a subagent. */
680 taskId: Schema.optional(RuntimeTaskId),
681 parentToolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
682});
683export type ToolProgressPayload = typeof ToolProgressPayload.Type;
684
685const ToolSummaryPayload = Schema.Struct({
686 summary: TrimmedNonEmptyStringSchema,
687 precedingToolUseIds: Schema.optional(Schema.Array(TrimmedNonEmptyStringSchema)),
688});
689export type ToolSummaryPayload = typeof ToolSummaryPayload.Type;
690
691const AuthStatusPayload = Schema.Struct({
692 isAuthenticating: Schema.optional(Schema.Boolean),
693 output: Schema.optional(Schema.Array(Schema.String)),
694 error: Schema.optional(TrimmedNonEmptyStringSchema),
695});
696export type AuthStatusPayload = typeof AuthStatusPayload.Type;
697
698const AccountUpdatedPayload = Schema.Struct({
699 account: Schema.Unknown,
700});
701export type AccountUpdatedPayload = typeof AccountUpdatedPayload.Type;
702
703const AccountRateLimitsUpdatedPayload = Schema.Struct({
704 rateLimits: Schema.Unknown,
705});
706export type AccountRateLimitsUpdatedPayload = typeof AccountRateLimitsUpdatedPayload.Type;
707
708const McpStatusUpdatedPayload = Schema.Struct({
709 status: Schema.Unknown,
710});
711export type McpStatusUpdatedPayload = typeof McpStatusUpdatedPayload.Type;
712
713const McpOauthCompletedPayload = Schema.Struct({
714 success: Schema.Boolean,
715 name: Schema.optional(TrimmedNonEmptyStringSchema),
716 error: Schema.optional(TrimmedNonEmptyStringSchema),
717});
718export type McpOauthCompletedPayload = typeof McpOauthCompletedPayload.Type;
719
720const ModelReroutedPayload = Schema.Struct({
721 fromModel: TrimmedNonEmptyStringSchema,
722 toModel: TrimmedNonEmptyStringSchema,
723 reason: TrimmedNonEmptyStringSchema,
724});
725export type ModelReroutedPayload = typeof ModelReroutedPayload.Type;
726
727const ConfigWarningPayload = Schema.Struct({
728 summary: TrimmedNonEmptyStringSchema,
729 details: Schema.optional(TrimmedNonEmptyStringSchema),
730 path: Schema.optional(TrimmedNonEmptyStringSchema),
731 range: Schema.optional(Schema.Unknown),
732});
733export type ConfigWarningPayload = typeof ConfigWarningPayload.Type;
734
735const DeprecationNoticePayload = Schema.Struct({
736 summary: TrimmedNonEmptyStringSchema,
737 details: Schema.optional(TrimmedNonEmptyStringSchema),
738});
739export type DeprecationNoticePayload = typeof DeprecationNoticePayload.Type;
740
741const FilesPersistedPayload = Schema.Struct({
742 files: Schema.Array(
743 Schema.Struct({
744 filename: TrimmedNonEmptyStringSchema,
745 fileId: TrimmedNonEmptyStringSchema,
746 }),
747 ),
748 failed: Schema.optional(
749 Schema.Array(
750 Schema.Struct({
751 filename: TrimmedNonEmptyStringSchema,
752 error: TrimmedNonEmptyStringSchema,
753 }),
754 ),
755 ),
756});
757export type FilesPersistedPayload = typeof FilesPersistedPayload.Type;
758
759const ToolDeniedPayload = Schema.Struct({
760 toolName: TrimmedNonEmptyStringSchema,
761 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
762 reason: Schema.optional(TrimmedNonEmptyStringSchema),
763 agentId: Schema.optional(TrimmedNonEmptyStringSchema),
764});
765export type ToolDeniedPayload = typeof ToolDeniedPayload.Type;
766
767const RuntimeWarningPayload = Schema.Struct({
768 message: TrimmedNonEmptyStringSchema,
769 detail: Schema.optional(Schema.Unknown),
770});
771export type RuntimeWarningPayload = typeof RuntimeWarningPayload.Type;
772
773const RuntimeErrorPayload = Schema.Struct({
774 message: TrimmedNonEmptyStringSchema,
775 class: Schema.optional(RuntimeErrorClass),
776 detail: Schema.optional(Schema.Unknown),
777});
778export type RuntimeErrorPayload = typeof RuntimeErrorPayload.Type;
779
780const ProviderRuntimeSessionStartedEvent = Schema.Struct({
781 ...ProviderRuntimeEventBase.fields,
782 type: SessionStartedType,
783 payload: SessionStartedPayload,
784});
785export type ProviderRuntimeSessionStartedEvent = typeof ProviderRuntimeSessionStartedEvent.Type;
786
787const ProviderRuntimeSessionConfiguredEvent = Schema.Struct({
788 ...ProviderRuntimeEventBase.fields,
789 type: SessionConfiguredType,
790 payload: SessionConfiguredPayload,
791});
792export type ProviderRuntimeSessionConfiguredEvent =
793 typeof ProviderRuntimeSessionConfiguredEvent.Type;
794
795const ProviderRuntimeSessionStateChangedEvent = Schema.Struct({
796 ...ProviderRuntimeEventBase.fields,
797 type: SessionStateChangedType,
798 payload: SessionStateChangedPayload,
799});
800export type ProviderRuntimeSessionStateChangedEvent =
801 typeof ProviderRuntimeSessionStateChangedEvent.Type;
802
803const ProviderRuntimeSessionExitedEvent = Schema.Struct({
804 ...ProviderRuntimeEventBase.fields,
805 type: SessionExitedType,
806 payload: SessionExitedPayload,
807});
808export type ProviderRuntimeSessionExitedEvent = typeof ProviderRuntimeSessionExitedEvent.Type;
809
810const ProviderRuntimeThreadStartedEvent = Schema.Struct({
811 ...ProviderRuntimeEventBase.fields,
812 type: ThreadStartedType,
813 payload: ThreadStartedPayload,
814});
815export type ProviderRuntimeThreadStartedEvent = typeof ProviderRuntimeThreadStartedEvent.Type;
816
817const ProviderRuntimeThreadStateChangedEvent = Schema.Struct({
818 ...ProviderRuntimeEventBase.fields,
819 type: ThreadStateChangedType,
820 payload: ThreadStateChangedPayload,
821});
822export type ProviderRuntimeThreadStateChangedEvent =
823 typeof ProviderRuntimeThreadStateChangedEvent.Type;
824
825const ProviderRuntimeThreadMetadataUpdatedEvent = Schema.Struct({
826 ...ProviderRuntimeEventBase.fields,
827 type: ThreadMetadataUpdatedType,
828 payload: ThreadMetadataUpdatedPayload,
829});
830export type ProviderRuntimeThreadMetadataUpdatedEvent =
831 typeof ProviderRuntimeThreadMetadataUpdatedEvent.Type;
832
833const ProviderRuntimeThreadTokenUsageUpdatedEvent = Schema.Struct({
834 ...ProviderRuntimeEventBase.fields,
835 type: ThreadTokenUsageUpdatedType,
836 payload: ThreadTokenUsageUpdatedPayload,
837});
838export type ProviderRuntimeThreadTokenUsageUpdatedEvent =
839 typeof ProviderRuntimeThreadTokenUsageUpdatedEvent.Type;
840
841const ProviderRuntimeThreadRealtimeStartedEvent = Schema.Struct({
842 ...ProviderRuntimeEventBase.fields,
843 type: ThreadRealtimeStartedType,
844 payload: ThreadRealtimeStartedPayload,
845});
846export type ProviderRuntimeThreadRealtimeStartedEvent =
847 typeof ProviderRuntimeThreadRealtimeStartedEvent.Type;
848
849const ProviderRuntimeThreadRealtimeItemAddedEvent = Schema.Struct({
850 ...ProviderRuntimeEventBase.fields,
851 type: ThreadRealtimeItemAddedType,
852 payload: ThreadRealtimeItemAddedPayload,
853});
854export type ProviderRuntimeThreadRealtimeItemAddedEvent =
855 typeof ProviderRuntimeThreadRealtimeItemAddedEvent.Type;
856
857const ProviderRuntimeThreadRealtimeAudioDeltaEvent = Schema.Struct({
858 ...ProviderRuntimeEventBase.fields,
859 type: ThreadRealtimeAudioDeltaType,
860 payload: ThreadRealtimeAudioDeltaPayload,
861});
862export type ProviderRuntimeThreadRealtimeAudioDeltaEvent =
863 typeof ProviderRuntimeThreadRealtimeAudioDeltaEvent.Type;
864
865const ProviderRuntimeThreadRealtimeErrorEvent = Schema.Struct({
866 ...ProviderRuntimeEventBase.fields,
867 type: ThreadRealtimeErrorType,
868 payload: ThreadRealtimeErrorPayload,
869});
870export type ProviderRuntimeThreadRealtimeErrorEvent =
871 typeof ProviderRuntimeThreadRealtimeErrorEvent.Type;
872
873const ProviderRuntimeThreadRealtimeClosedEvent = Schema.Struct({
874 ...ProviderRuntimeEventBase.fields,
875 type: ThreadRealtimeClosedType,
876 payload: ThreadRealtimeClosedPayload,
877});
878export type ProviderRuntimeThreadRealtimeClosedEvent =
879 typeof ProviderRuntimeThreadRealtimeClosedEvent.Type;
880
881const ProviderRuntimeTurnStartedEvent = Schema.Struct({
882 ...ProviderRuntimeEventBase.fields,
883 type: TurnStartedType,
884 payload: TurnStartedPayload,
885});
886export type ProviderRuntimeTurnStartedEvent = typeof ProviderRuntimeTurnStartedEvent.Type;
887
888const ProviderRuntimeTurnCompletedEvent = Schema.Struct({
889 ...ProviderRuntimeEventBase.fields,
890 type: TurnCompletedType,
891 payload: TurnCompletedPayload,
892});
893export type ProviderRuntimeTurnCompletedEvent = typeof ProviderRuntimeTurnCompletedEvent.Type;
894
895const ProviderRuntimeTurnAbortedEvent = Schema.Struct({
896 ...ProviderRuntimeEventBase.fields,
897 type: TurnAbortedType,
898 payload: TurnAbortedPayload,
899});
900export type ProviderRuntimeTurnAbortedEvent = typeof ProviderRuntimeTurnAbortedEvent.Type;
901
902const ProviderRuntimeTurnPlanUpdatedEvent = Schema.Struct({
903 ...ProviderRuntimeEventBase.fields,
904 type: TurnPlanUpdatedType,
905 payload: TurnPlanUpdatedPayload,
906});
907export type ProviderRuntimeTurnPlanUpdatedEvent = typeof ProviderRuntimeTurnPlanUpdatedEvent.Type;
908
909const ProviderRuntimeTurnProposedDeltaEvent = Schema.Struct({
910 ...ProviderRuntimeEventBase.fields,
911 type: TurnProposedDeltaType,
912 payload: TurnProposedDeltaPayload,
913});
914export type ProviderRuntimeTurnProposedDeltaEvent =
915 typeof ProviderRuntimeTurnProposedDeltaEvent.Type;
916
917const ProviderRuntimeTurnProposedCompletedEvent = Schema.Struct({
918 ...ProviderRuntimeEventBase.fields,
919 type: TurnProposedCompletedType,
920 payload: TurnProposedCompletedPayload,
921});
922export type ProviderRuntimeTurnProposedCompletedEvent =
923 typeof ProviderRuntimeTurnProposedCompletedEvent.Type;
924
925const ProviderRuntimeTurnDiffUpdatedEvent = Schema.Struct({
926 ...ProviderRuntimeEventBase.fields,
927 type: TurnDiffUpdatedType,
928 payload: TurnDiffUpdatedPayload,
929});
930export type ProviderRuntimeTurnDiffUpdatedEvent = typeof ProviderRuntimeTurnDiffUpdatedEvent.Type;
931
932const ProviderRuntimeItemStartedEvent = Schema.Struct({
933 ...ProviderRuntimeEventBase.fields,
934 type: ItemStartedType,
935 payload: ItemLifecyclePayload,
936});
937export type ProviderRuntimeItemStartedEvent = typeof ProviderRuntimeItemStartedEvent.Type;
938
939const ProviderRuntimeItemUpdatedEvent = Schema.Struct({
940 ...ProviderRuntimeEventBase.fields,
941 type: ItemUpdatedType,
942 payload: ItemLifecyclePayload,
943});
944export type ProviderRuntimeItemUpdatedEvent = typeof ProviderRuntimeItemUpdatedEvent.Type;
945
946const ProviderRuntimeItemCompletedEvent = Schema.Struct({
947 ...ProviderRuntimeEventBase.fields,
948 type: ItemCompletedType,
949 payload: ItemLifecyclePayload,
950});
951export type ProviderRuntimeItemCompletedEvent = typeof ProviderRuntimeItemCompletedEvent.Type;
952
953const ProviderRuntimeContentDeltaEvent = Schema.Struct({
954 ...ProviderRuntimeEventBase.fields,
955 type: ContentDeltaType,
956 payload: ContentDeltaPayload,
957});
958export type ProviderRuntimeContentDeltaEvent = typeof ProviderRuntimeContentDeltaEvent.Type;
959
960const ProviderRuntimeRequestOpenedEvent = Schema.Struct({
961 ...ProviderRuntimeEventBase.fields,
962 type: RequestOpenedType,
963 payload: RequestOpenedPayload,
964});
965export type ProviderRuntimeRequestOpenedEvent = typeof ProviderRuntimeRequestOpenedEvent.Type;
966
967const ProviderRuntimeRequestResolvedEvent = Schema.Struct({
968 ...ProviderRuntimeEventBase.fields,
969 type: RequestResolvedType,
970 payload: RequestResolvedPayload,
971});
972export type ProviderRuntimeRequestResolvedEvent = typeof ProviderRuntimeRequestResolvedEvent.Type;
973
974const ProviderRuntimeUserInputRequestedEvent = Schema.Struct({
975 ...ProviderRuntimeEventBase.fields,
976 type: UserInputRequestedType,
977 payload: UserInputRequestedPayload,
978});
979export type ProviderRuntimeUserInputRequestedEvent =
980 typeof ProviderRuntimeUserInputRequestedEvent.Type;
981
982const ProviderRuntimeUserInputResolvedEvent = Schema.Struct({
983 ...ProviderRuntimeEventBase.fields,
984 type: UserInputResolvedType,
985 payload: UserInputResolvedPayload,
986});
987export type ProviderRuntimeUserInputResolvedEvent =
988 typeof ProviderRuntimeUserInputResolvedEvent.Type;
989
990const ProviderRuntimeTaskStartedEvent = Schema.Struct({
991 ...ProviderRuntimeEventBase.fields,
992 type: TaskStartedType,
993 payload: TaskStartedPayload,
994});
995export type ProviderRuntimeTaskStartedEvent = typeof ProviderRuntimeTaskStartedEvent.Type;
996
997const ProviderRuntimeTaskProgressEvent = Schema.Struct({
998 ...ProviderRuntimeEventBase.fields,
999 type: TaskProgressType,
1000 payload: TaskProgressPayload,
1001});
1002export type ProviderRuntimeTaskProgressEvent = typeof ProviderRuntimeTaskProgressEvent.Type;
1003
1004const ProviderRuntimeTaskUpdatedEvent = Schema.Struct({
1005 ...ProviderRuntimeEventBase.fields,
1006 type: TaskUpdatedType,
1007 payload: TaskUpdatedPayload,
1008});
1009export type ProviderRuntimeTaskUpdatedEvent = typeof ProviderRuntimeTaskUpdatedEvent.Type;
1010
1011const ProviderRuntimeTaskCompletedEvent = Schema.Struct({
1012 ...ProviderRuntimeEventBase.fields,
1013 type: TaskCompletedType,
1014 payload: TaskCompletedPayload,
1015});
1016export type ProviderRuntimeTaskCompletedEvent = typeof ProviderRuntimeTaskCompletedEvent.Type;
1017
1018const ProviderRuntimeHookStartedEvent = Schema.Struct({
1019 ...ProviderRuntimeEventBase.fields,
1020 type: HookStartedType,
1021 payload: HookStartedPayload,
1022});
1023export type ProviderRuntimeHookStartedEvent = typeof ProviderRuntimeHookStartedEvent.Type;
1024
1025const ProviderRuntimeHookProgressEvent = Schema.Struct({
1026 ...ProviderRuntimeEventBase.fields,
1027 type: HookProgressType,
1028 payload: HookProgressPayload,
1029});
1030export type ProviderRuntimeHookProgressEvent = typeof ProviderRuntimeHookProgressEvent.Type;
1031
1032const ProviderRuntimeHookCompletedEvent = Schema.Struct({
1033 ...ProviderRuntimeEventBase.fields,
1034 type: HookCompletedType,
1035 payload: HookCompletedPayload,
1036});
1037export type ProviderRuntimeHookCompletedEvent = typeof ProviderRuntimeHookCompletedEvent.Type;
1038
1039const ProviderRuntimeToolProgressEvent = Schema.Struct({
1040 ...ProviderRuntimeEventBase.fields,
1041 type: ToolProgressType,
1042 payload: ToolProgressPayload,
1043});
1044export type ProviderRuntimeToolProgressEvent = typeof ProviderRuntimeToolProgressEvent.Type;
1045
1046const ProviderRuntimeToolSummaryEvent = Schema.Struct({
1047 ...ProviderRuntimeEventBase.fields,
1048 type: ToolSummaryType,
1049 payload: ToolSummaryPayload,
1050});
1051export type ProviderRuntimeToolSummaryEvent = typeof ProviderRuntimeToolSummaryEvent.Type;
1052
1053const ProviderRuntimeAuthStatusEvent = Schema.Struct({
1054 ...ProviderRuntimeEventBase.fields,
1055 type: AuthStatusType,
1056 payload: AuthStatusPayload,
1057});
1058export type ProviderRuntimeAuthStatusEvent = typeof ProviderRuntimeAuthStatusEvent.Type;
1059
1060const ProviderRuntimeAccountUpdatedEvent = Schema.Struct({
1061 ...ProviderRuntimeEventBase.fields,
1062 type: AccountUpdatedType,
1063 payload: AccountUpdatedPayload,
1064});
1065export type ProviderRuntimeAccountUpdatedEvent = typeof ProviderRuntimeAccountUpdatedEvent.Type;
1066
1067const ProviderRuntimeAccountRateLimitsUpdatedEvent = Schema.Struct({
1068 ...ProviderRuntimeEventBase.fields,
1069 type: AccountRateLimitsUpdatedType,
1070 payload: AccountRateLimitsUpdatedPayload,
1071});
1072export type ProviderRuntimeAccountRateLimitsUpdatedEvent =
1073 typeof ProviderRuntimeAccountRateLimitsUpdatedEvent.Type;
1074
1075const ProviderRuntimeMcpStatusUpdatedEvent = Schema.Struct({
1076 ...ProviderRuntimeEventBase.fields,
1077 type: McpStatusUpdatedType,
1078 payload: McpStatusUpdatedPayload,
1079});
1080export type ProviderRuntimeMcpStatusUpdatedEvent = typeof ProviderRuntimeMcpStatusUpdatedEvent.Type;
1081
1082const ProviderRuntimeMcpOauthCompletedEvent = Schema.Struct({
1083 ...ProviderRuntimeEventBase.fields,
1084 type: McpOauthCompletedType,
1085 payload: McpOauthCompletedPayload,
1086});
1087export type ProviderRuntimeMcpOauthCompletedEvent =
1088 typeof ProviderRuntimeMcpOauthCompletedEvent.Type;
1089
1090const ProviderRuntimeModelReroutedEvent = Schema.Struct({
1091 ...ProviderRuntimeEventBase.fields,
1092 type: ModelReroutedType,
1093 payload: ModelReroutedPayload,
1094});
1095export type ProviderRuntimeModelReroutedEvent = typeof ProviderRuntimeModelReroutedEvent.Type;
1096
1097const ProviderRuntimeConfigWarningEvent = Schema.Struct({
1098 ...ProviderRuntimeEventBase.fields,
1099 type: ConfigWarningType,
1100 payload: ConfigWarningPayload,
1101});
1102export type ProviderRuntimeConfigWarningEvent = typeof ProviderRuntimeConfigWarningEvent.Type;
1103
1104const ProviderRuntimeDeprecationNoticeEvent = Schema.Struct({
1105 ...ProviderRuntimeEventBase.fields,
1106 type: DeprecationNoticeType,
1107 payload: DeprecationNoticePayload,
1108});
1109export type ProviderRuntimeDeprecationNoticeEvent =
1110 typeof ProviderRuntimeDeprecationNoticeEvent.Type;
1111
1112const ProviderRuntimeFilesPersistedEvent = Schema.Struct({
1113 ...ProviderRuntimeEventBase.fields,
1114 type: FilesPersistedType,
1115 payload: FilesPersistedPayload,
1116});
1117export type ProviderRuntimeFilesPersistedEvent = typeof ProviderRuntimeFilesPersistedEvent.Type;
1118
1119const ProviderRuntimeToolDeniedEvent = Schema.Struct({
1120 ...ProviderRuntimeEventBase.fields,
1121 type: ToolDeniedType,
1122 payload: ToolDeniedPayload,
1123});
1124export type ProviderRuntimeToolDeniedEvent = typeof ProviderRuntimeToolDeniedEvent.Type;
1125
1126const ProviderRuntimeWarningEvent = Schema.Struct({
1127 ...ProviderRuntimeEventBase.fields,
1128 type: RuntimeWarningType,
1129 payload: RuntimeWarningPayload,
1130});
1131export type ProviderRuntimeWarningEvent = typeof ProviderRuntimeWarningEvent.Type;
1132
1133const ProviderRuntimeErrorEvent = Schema.Struct({
1134 ...ProviderRuntimeEventBase.fields,
1135 type: RuntimeErrorType,
1136 payload: RuntimeErrorPayload,
1137});
1138export type ProviderRuntimeErrorEvent = typeof ProviderRuntimeErrorEvent.Type;
1139
1140export const ProviderRuntimeEventV2 = Schema.Union([
1141 ProviderRuntimeSessionStartedEvent,
1142 ProviderRuntimeSessionConfiguredEvent,
1143 ProviderRuntimeSessionStateChangedEvent,
1144 ProviderRuntimeSessionExitedEvent,
1145 ProviderRuntimeThreadStartedEvent,
1146 ProviderRuntimeThreadStateChangedEvent,
1147 ProviderRuntimeThreadMetadataUpdatedEvent,
1148 ProviderRuntimeThreadTokenUsageUpdatedEvent,
1149 ProviderRuntimeThreadRealtimeStartedEvent,
1150 ProviderRuntimeThreadRealtimeItemAddedEvent,
1151 ProviderRuntimeThreadRealtimeAudioDeltaEvent,
1152 ProviderRuntimeThreadRealtimeErrorEvent,
1153 ProviderRuntimeThreadRealtimeClosedEvent,
1154 ProviderRuntimeTurnStartedEvent,
1155 ProviderRuntimeTurnCompletedEvent,
1156 ProviderRuntimeTurnAbortedEvent,
1157 ProviderRuntimeTurnPlanUpdatedEvent,
1158 ProviderRuntimeTurnProposedDeltaEvent,
1159 ProviderRuntimeTurnProposedCompletedEvent,
1160 ProviderRuntimeTurnDiffUpdatedEvent,
1161 ProviderRuntimeItemStartedEvent,
1162 ProviderRuntimeItemUpdatedEvent,
1163 ProviderRuntimeItemCompletedEvent,
1164 ProviderRuntimeContentDeltaEvent,
1165 ProviderRuntimeRequestOpenedEvent,
1166 ProviderRuntimeRequestResolvedEvent,
1167 ProviderRuntimeUserInputRequestedEvent,
1168 ProviderRuntimeUserInputResolvedEvent,
1169 ProviderRuntimeTaskStartedEvent,
1170 ProviderRuntimeTaskProgressEvent,
1171 ProviderRuntimeTaskUpdatedEvent,
1172 ProviderRuntimeTaskCompletedEvent,
1173 ProviderRuntimeHookStartedEvent,
1174 ProviderRuntimeHookProgressEvent,
1175 ProviderRuntimeHookCompletedEvent,
1176 ProviderRuntimeToolProgressEvent,
1177 ProviderRuntimeToolSummaryEvent,
1178 ProviderRuntimeAuthStatusEvent,
1179 ProviderRuntimeAccountUpdatedEvent,
1180 ProviderRuntimeAccountRateLimitsUpdatedEvent,
1181 ProviderRuntimeMcpStatusUpdatedEvent,
1182 ProviderRuntimeMcpOauthCompletedEvent,
1183 ProviderRuntimeModelReroutedEvent,
1184 ProviderRuntimeConfigWarningEvent,
1185 ProviderRuntimeDeprecationNoticeEvent,
1186 ProviderRuntimeFilesPersistedEvent,
1187 ProviderRuntimeToolDeniedEvent,
1188 ProviderRuntimeWarningEvent,
1189 ProviderRuntimeErrorEvent,
1190]);
1191export type ProviderRuntimeEventV2 = typeof ProviderRuntimeEventV2.Type;
1192
1193export const ProviderRuntimeEvent = ProviderRuntimeEventV2;
1194export type ProviderRuntimeEvent = ProviderRuntimeEventV2;
1195
1196// Compatibility aliases for call sites still importing legacy names.
1197const ProviderRuntimeMessageDeltaEvent = ProviderRuntimeContentDeltaEvent;
1198export type ProviderRuntimeMessageDeltaEvent = ProviderRuntimeContentDeltaEvent;
1199const ProviderRuntimeMessageCompletedEvent = ProviderRuntimeItemCompletedEvent;
1200export type ProviderRuntimeMessageCompletedEvent = ProviderRuntimeItemCompletedEvent;
1201const ProviderRuntimeToolStartedEvent = ProviderRuntimeItemStartedEvent;
1202export type ProviderRuntimeToolStartedEvent = ProviderRuntimeItemStartedEvent;
1203const ProviderRuntimeToolCompletedEvent = ProviderRuntimeItemCompletedEvent;
1204export type ProviderRuntimeToolCompletedEvent = ProviderRuntimeItemCompletedEvent;
1205const ProviderRuntimeApprovalRequestedEvent = ProviderRuntimeRequestOpenedEvent;
1206export type ProviderRuntimeApprovalRequestedEvent = ProviderRuntimeRequestOpenedEvent;
1207const ProviderRuntimeApprovalResolvedEvent = ProviderRuntimeRequestResolvedEvent;
1208export type ProviderRuntimeApprovalResolvedEvent = ProviderRuntimeRequestResolvedEvent;
1209
1210// Legacy helper aliases retained for adapters/tests.
1211const ProviderRuntimeToolKind = Schema.Literals(["command", "file-read", "file-change", "other"]);
1212export type ProviderRuntimeToolKind = typeof ProviderRuntimeToolKind.Type;
1213
1214export const ProviderRuntimeTurnStatus = RuntimeTurnState;
1215export type ProviderRuntimeTurnStatus = RuntimeTurnState;