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