Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

providerRuntime.ts

1,218 lines45.1 KB

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 "./orchestration.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);
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});
328export type ThreadTokenUsageSnapshot = typeof ThreadTokenUsageSnapshot.Type;
329​
330const ThreadTokenUsageUpdatedPayload = Schema.Struct({
331 usage: ThreadTokenUsageSnapshot,
332});
333export type ThreadTokenUsageUpdatedPayload = typeof ThreadTokenUsageUpdatedPayload.Type;
334​
335const ThreadRealtimeStartedPayload = Schema.Struct({
336 realtimeSessionId: Schema.optional(TrimmedNonEmptyStringSchema),
337});
338export type ThreadRealtimeStartedPayload = typeof ThreadRealtimeStartedPayload.Type;
339​
340const ThreadRealtimeItemAddedPayload = Schema.Struct({
341 item: Schema.Unknown,
342});
343export type ThreadRealtimeItemAddedPayload = typeof ThreadRealtimeItemAddedPayload.Type;
344​
345const ThreadRealtimeAudioDeltaPayload = Schema.Struct({
346 audio: Schema.Unknown,
347});
348export type ThreadRealtimeAudioDeltaPayload = typeof ThreadRealtimeAudioDeltaPayload.Type;
349​
350const ThreadRealtimeErrorPayload = Schema.Struct({
351 message: TrimmedNonEmptyStringSchema,
352});
353export type ThreadRealtimeErrorPayload = typeof ThreadRealtimeErrorPayload.Type;
354​
355const ThreadRealtimeClosedPayload = Schema.Struct({
356 reason: Schema.optional(TrimmedNonEmptyStringSchema),
357});
358export type ThreadRealtimeClosedPayload = typeof ThreadRealtimeClosedPayload.Type;
359​
360const TurnStartedPayload = Schema.Struct({
361 model: Schema.optional(TrimmedNonEmptyStringSchema),
362 effort: Schema.optional(TrimmedNonEmptyStringSchema),
363});
364export type TurnStartedPayload = typeof TurnStartedPayload.Type;
365​
366const TurnCompletedPayload = Schema.Struct({
367 state: RuntimeTurnState,
368 stopReason: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
369 usage: Schema.optional(Schema.Unknown),
370 modelUsage: Schema.optional(UnknownRecordSchema),
371 totalCostUsd: Schema.optional(Schema.Number),
372 errorMessage: Schema.optional(TrimmedNonEmptyStringSchema),
373});
374export type TurnCompletedPayload = typeof TurnCompletedPayload.Type;
375​
376const TurnAbortedPayload = Schema.Struct({
377 reason: TrimmedNonEmptyStringSchema,
378});
379export type TurnAbortedPayload = typeof TurnAbortedPayload.Type;
380​
381const RuntimePlanStep = Schema.Struct({
382 step: TrimmedNonEmptyStringSchema,
383 status: RuntimePlanStepStatus,
384});
385export type RuntimePlanStep = typeof RuntimePlanStep.Type;
386​
387const TurnPlanUpdatedPayload = Schema.Struct({
388 explanation: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
389 plan: Schema.Array(RuntimePlanStep),
390});
391export type TurnPlanUpdatedPayload = typeof TurnPlanUpdatedPayload.Type;
392​
393const TurnProposedDeltaPayload = Schema.Struct({
394 delta: Schema.String,
395});
396export type TurnProposedDeltaPayload = typeof TurnProposedDeltaPayload.Type;
397​
398const TurnProposedCompletedPayload = Schema.Struct({
399 planMarkdown: TrimmedNonEmptyStringSchema,
400});
401export type TurnProposedCompletedPayload = typeof TurnProposedCompletedPayload.Type;
402​
403const TurnDiffUpdatedPayload = Schema.Struct({
404 unifiedDiff: Schema.String,
405});
406export type TurnDiffUpdatedPayload = typeof TurnDiffUpdatedPayload.Type;
407​
408export const ItemLifecyclePayload = Schema.Struct({
409 itemType: CanonicalItemType,
410 status: Schema.optional(RuntimeItemStatus),
411 title: Schema.optional(TrimmedNonEmptyStringSchema),
412 detail: Schema.optional(TrimmedNonEmptyStringSchema),
413 data: Schema.optional(Schema.Unknown),
414 /**
415 * Owning agent when this item ran inside a subagent (resolved from the
416 * SDK's parent_tool_use_id). Clients re-home attributed items out of the
417 * main timeline and into the owning agent's Agents-surface row.
418 */
419 agentId: Schema.optional(TrimmedNonEmptyStringSchema),
420 parentToolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
421});
422export type ItemLifecyclePayload = typeof ItemLifecyclePayload.Type;
423​
424const ContentDeltaPayload = Schema.Struct({
425 streamKind: RuntimeContentStreamKind,
426 delta: Schema.String,
427 contentIndex: Schema.optional(Schema.Int),
428 summaryIndex: Schema.optional(Schema.Int),
429});
430export type ContentDeltaPayload = typeof ContentDeltaPayload.Type;
431​
432const RequestOpenedPayload = Schema.Struct({
433 requestType: CanonicalRequestType,
434 detail: Schema.optional(TrimmedNonEmptyStringSchema),
435 appName: Schema.optional(TrimmedNonEmptyStringSchema),
436 options: Schema.optional(Schema.Array(ProviderApprovalOption)),
437 args: Schema.optional(Schema.Unknown),
438});
439export type RequestOpenedPayload = typeof RequestOpenedPayload.Type;
440​
441const RequestResolvedPayload = Schema.Struct({
442 requestType: CanonicalRequestType,
443 decision: Schema.optional(TrimmedNonEmptyStringSchema),
444 resolution: Schema.optional(Schema.Unknown),
445});
446export type RequestResolvedPayload = typeof RequestResolvedPayload.Type;
447​
448const UserInputQuestionOption = Schema.Struct({
449 label: TrimmedNonEmptyStringSchema,
450 description: TrimmedNonEmptyStringSchema,
451});
452export type UserInputQuestionOption = typeof UserInputQuestionOption.Type;
453​
454export const UserInputQuestion = Schema.Struct({
455 id: TrimmedNonEmptyStringSchema,
456 header: TrimmedNonEmptyStringSchema,
457 question: TrimmedNonEmptyStringSchema,
458 options: Schema.Array(UserInputQuestionOption),
459 multiSelect: Schema.optional(Schema.Boolean).pipe(
460 Schema.withConstructorDefault(Effect.succeed(false)),
461 ),
462});
463export type UserInputQuestion = typeof UserInputQuestion.Type;
464​
465const UserInputRequestedPayload = Schema.Struct({
466 questions: Schema.Array(UserInputQuestion),
467});
468export type UserInputRequestedPayload = typeof UserInputRequestedPayload.Type;
469​
470const UserInputResolvedPayload = Schema.Struct({
471 answers: UnknownRecordSchema,
472});
473export type UserInputResolvedPayload = typeof UserInputResolvedPayload.Type;
474​
475/**
476 * Typed per-task usage rollup. Field names match the orchestration-v2 subagent
477 * usage vocabulary (#4779) so the eventual migration is a rename, not a remap.
478 * Claude reports per-activation deltas; Codex reports cumulative totals — the
479 * merge strategy is provider-specific and lives in client-runtime.
480 */
481export const RuntimeTaskUsage = Schema.Struct({
482 totalTokens: NonNegativeInt,
483 inputTokens: Schema.optional(NonNegativeInt),
484 cachedInputTokens: Schema.optional(NonNegativeInt),
485 outputTokens: Schema.optional(NonNegativeInt),
486 reasoningOutputTokens: Schema.optional(NonNegativeInt),
487 toolUses: Schema.optional(NonNegativeInt),
488 durationMs: Schema.optional(NonNegativeInt),
489});
490export type RuntimeTaskUsage = typeof RuntimeTaskUsage.Type;
491​
492export const TaskWorkflowPhase = Schema.Struct({
493 index: NonNegativeInt,
494 title: TrimmedNonEmptyStringSchema,
495});
496export type TaskWorkflowPhase = typeof TaskWorkflowPhase.Type;
497​
498export const TaskRunHandles = Schema.Struct({
499 runId: Schema.optional(TrimmedNonEmptyStringSchema),
500 scriptPath: Schema.optional(TrimmedNonEmptyStringSchema),
501 transcriptDir: Schema.optional(TrimmedNonEmptyStringSchema),
502 /** Only http/https URLs may be stored here — sanitized at the adapter. */
503 sessionUrl: Schema.optional(TrimmedNonEmptyStringSchema),
504});
505export type TaskRunHandles = typeof TaskRunHandles.Type;
506​
507/**
508 * Watch-loop task types: Monitor-tool tasks plus background shells (a shell
509 * that outlives its turn is in practice a watch loop). Canonical single copy —
510 * the server liveness registry, ingestion's agentKind stamp, and the client
511 * fold's legacy fallback all classify with these sets.
512 */
513export const MONITOR_TASK_TYPES: ReadonlySet<string> = new Set([
514 "monitor",
515 "monitor_mcp",
516 "local_bash",
517 "shell",
518]);
519/** Task types that are neither agents nor watch loops (plan-mode bookkeeping). */
520export const INERT_TASK_TYPES: ReadonlySet<string> = new Set(["plan", "dream"]);
521​
522/**
523 * Agent-vs-background classification, stamped by ingestion as `agentKind` so
524 * persisted rows are self-describing. A deliberate denylist: the SDK's
525 * agent-flavored type names drift (subagent, local_agent, local_workflow, …)
526 * and an allowlist silently dropped real subagents when "local_agent"
527 * appeared. A task launched from inside a subagent (agentId set) is
528 * agent-internal background work UNLESS it is itself agent-flavored — a
529 * nested agent can outlive its parent and stays in the roster.
530 */
531export function classifyTaskAgentKind(input: {
532 readonly taskType?: string | undefined;
533 readonly agentId?: string | undefined;
534}): "agent" | "background" {
535 const { taskType, agentId } = input;
536 const nonAgentType =
537 taskType !== undefined && (MONITOR_TASK_TYPES.has(taskType) || INERT_TASK_TYPES.has(taskType));
538 if (agentId !== undefined && agentId.trim().length > 0) {
539 return taskType === undefined || nonAgentType ? "background" : "agent";
540 }
541 return nonAgentType ? "background" : "agent";
543​
544/**
545 * Optional agent-identity linkage carried on every task lifecycle payload.
546 * Repeated on progress and terminal rows (not just start) so client folds can
547 * reconstruct an agent even when its start row aged out of activity retention.
548 * All fields optional: old emitters and old rows decode unchanged.
549 */
550const taskAgentLinkageFields = {
551 /** SDK task_type (subagent/shell/monitor/local_workflow/…), repeated on
552 * every row so folds can classify without the start row. */
553 taskType: Schema.optional(TrimmedNonEmptyStringSchema),
554 /**
555 * Server-stamped classification (classifyTaskAgentKind at ingestion).
556 * Clients trust this stamp outright; rows without it (legacy, pre-stamp)
557 * fall back to client-side heuristics.
558 */
559 agentKind: Schema.optional(Schema.Literals(["agent", "background"])),
560 /**
561 * Owning agent when the task itself was launched from inside a subagent
562 * (e.g. a subagent's background shell). Clients treat such tasks as
563 * agent-internal and keep them out of the parent work log.
564 */
565 agentId: Schema.optional(TrimmedNonEmptyStringSchema),
566 title: Schema.optional(TrimmedNonEmptyStringSchema),
567 role: Schema.optional(TrimmedNonEmptyStringSchema),
568 model: Schema.optional(TrimmedNonEmptyStringSchema),
569 /** Reasoning effort when known (e.g. "high"). Open string: provider vocabularies differ. */
570 effort: Schema.optional(TrimmedNonEmptyStringSchema),
571 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
572 parentAgentId: Schema.optional(TrimmedNonEmptyStringSchema),
573 workflowName: Schema.optional(TrimmedNonEmptyStringSchema),
574 agentIndex: Schema.optional(NonNegativeInt),
575 phaseIndex: Schema.optional(NonNegativeInt),
576 phaseTitle: Schema.optional(TrimmedNonEmptyStringSchema),
577 phases: Schema.optional(Schema.Array(TaskWorkflowPhase)),
578 attempt: Schema.optional(NonNegativeInt),
579 runHandles: Schema.optional(TaskRunHandles),
580 outputFile: Schema.optional(TrimmedNonEmptyStringSchema),
581 /** Codex agent hierarchy path, e.g. "/root/marlow". */
582 agentPath: Schema.optional(TrimmedNonEmptyStringSchema),
583 /**
584 * Set on provider-synthesized child-agent events (Codex) whose activity
585 * belongs in the Agents surface, never the parent timeline.
586 */
587 timelineBypass: Schema.optional(Schema.Boolean),
588} as const;
589​
590export const TaskAgentLinkage = Schema.Struct(taskAgentLinkageFields);
591export type TaskAgentLinkage = typeof TaskAgentLinkage.Type;
592​
593const TaskStartedPayload = Schema.Struct({
594 taskId: RuntimeTaskId,
595 description: Schema.optional(TrimmedNonEmptyStringSchema),
596 ...taskAgentLinkageFields,
597});
598export type TaskStartedPayload = typeof TaskStartedPayload.Type;
599​
600export const RuntimeTaskStatus = Schema.Literals([
601 "pending",
602 "running",
603 "waiting",
604 "idle",
605 "completed",
606 "failed",
607 "cancelled",
608 "interrupted",
609]);
610export type RuntimeTaskStatus = typeof RuntimeTaskStatus.Type;
611​
612const TaskProgressPayload = Schema.Struct({
613 taskId: RuntimeTaskId,
614 description: TrimmedNonEmptyStringSchema,
615 summary: Schema.optional(TrimmedNonEmptyStringSchema),
616 usage: Schema.optional(Schema.Unknown),
617 typedUsage: Schema.optional(RuntimeTaskUsage),
618 lastToolName: Schema.optional(TrimmedNonEmptyStringSchema),
619 /** Present on synthesized member/child progress rows that carry state. */
620 status: Schema.optional(RuntimeTaskStatus),
621 error: Schema.optional(TrimmedNonEmptyStringSchema),
622 ...taskAgentLinkageFields,
623});
624export type TaskProgressPayload = typeof TaskProgressPayload.Type;
625​
626/**
627 * Non-terminal status patch (from the Claude SDK's task_updated, which main
628 * previously dropped). killed→cancelled and paused→idle are mapped at the
629 * adapter so the wire only carries the shared vocabulary.
630 */
631const TaskUpdatedPayload = Schema.Struct({
632 taskId: RuntimeTaskId,
633 status: Schema.optional(RuntimeTaskStatus),
634 description: Schema.optional(TrimmedNonEmptyStringSchema),
635 error: Schema.optional(TrimmedNonEmptyStringSchema),
636 endedAt: Schema.optional(IsoDateTime),
637 isBackgrounded: Schema.optional(Schema.Boolean),
638 ...taskAgentLinkageFields,
639});
640export type TaskUpdatedPayload = typeof TaskUpdatedPayload.Type;
641​
642const TaskCompletedPayload = Schema.Struct({
643 taskId: RuntimeTaskId,
644 status: Schema.Literals(["completed", "failed", "stopped"]),
645 summary: Schema.optional(TrimmedNonEmptyStringSchema),
646 usage: Schema.optional(Schema.Unknown),
647 typedUsage: Schema.optional(RuntimeTaskUsage),
648 ...taskAgentLinkageFields,
649});
650export type TaskCompletedPayload = typeof TaskCompletedPayload.Type;
651​
652const HookStartedPayload = Schema.Struct({
653 hookId: TrimmedNonEmptyStringSchema,
654 hookName: TrimmedNonEmptyStringSchema,
655 hookEvent: TrimmedNonEmptyStringSchema,
656});
657export type HookStartedPayload = typeof HookStartedPayload.Type;
658​
659const HookProgressPayload = Schema.Struct({
660 hookId: TrimmedNonEmptyStringSchema,
661 output: Schema.optional(Schema.String),
662 stdout: Schema.optional(Schema.String),
663 stderr: Schema.optional(Schema.String),
664});
665export type HookProgressPayload = typeof HookProgressPayload.Type;
666​
667const HookCompletedPayload = Schema.Struct({
668 hookId: TrimmedNonEmptyStringSchema,
669 outcome: Schema.Literals(["success", "error", "cancelled"]),
670 output: Schema.optional(Schema.String),
671 stdout: Schema.optional(Schema.String),
672 stderr: Schema.optional(Schema.String),
673 exitCode: Schema.optional(Schema.Int),
674});
675export type HookCompletedPayload = typeof HookCompletedPayload.Type;
676​
677const ToolProgressPayload = Schema.Struct({
678 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
679 toolName: Schema.optional(TrimmedNonEmptyStringSchema),
680 summary: Schema.optional(TrimmedNonEmptyStringSchema),
681 elapsedSeconds: Schema.optional(Schema.Number),
682 /** Owning task/agent when the tool ran inside a subagent. */
683 taskId: Schema.optional(RuntimeTaskId),
684 parentToolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
685});
686export type ToolProgressPayload = typeof ToolProgressPayload.Type;
687​
688const ToolSummaryPayload = Schema.Struct({
689 summary: TrimmedNonEmptyStringSchema,
690 precedingToolUseIds: Schema.optional(Schema.Array(TrimmedNonEmptyStringSchema)),
691});
692export type ToolSummaryPayload = typeof ToolSummaryPayload.Type;
693​
694const AuthStatusPayload = Schema.Struct({
695 isAuthenticating: Schema.optional(Schema.Boolean),
696 output: Schema.optional(Schema.Array(Schema.String)),
697 error: Schema.optional(TrimmedNonEmptyStringSchema),
698});
699export type AuthStatusPayload = typeof AuthStatusPayload.Type;
700​
701const AccountUpdatedPayload = Schema.Struct({
702 account: Schema.Unknown,
703});
704export type AccountUpdatedPayload = typeof AccountUpdatedPayload.Type;
705​
706const AccountRateLimitsUpdatedPayload = Schema.Struct({
707 rateLimits: Schema.Unknown,
708});
709export type AccountRateLimitsUpdatedPayload = typeof AccountRateLimitsUpdatedPayload.Type;
710​
711const McpStatusUpdatedPayload = Schema.Struct({
712 status: Schema.Unknown,
713});
714export type McpStatusUpdatedPayload = typeof McpStatusUpdatedPayload.Type;
715​
716const McpOauthCompletedPayload = Schema.Struct({
717 success: Schema.Boolean,
718 name: Schema.optional(TrimmedNonEmptyStringSchema),
719 error: Schema.optional(TrimmedNonEmptyStringSchema),
720});
721export type McpOauthCompletedPayload = typeof McpOauthCompletedPayload.Type;
722​
723const ModelReroutedPayload = Schema.Struct({
724 fromModel: TrimmedNonEmptyStringSchema,
725 toModel: TrimmedNonEmptyStringSchema,
726 reason: TrimmedNonEmptyStringSchema,
727});
728export type ModelReroutedPayload = typeof ModelReroutedPayload.Type;
729​
730const ConfigWarningPayload = Schema.Struct({
731 summary: TrimmedNonEmptyStringSchema,
732 details: Schema.optional(TrimmedNonEmptyStringSchema),
733 path: Schema.optional(TrimmedNonEmptyStringSchema),
734 range: Schema.optional(Schema.Unknown),
735});
736export type ConfigWarningPayload = typeof ConfigWarningPayload.Type;
737​
738const DeprecationNoticePayload = Schema.Struct({
739 summary: TrimmedNonEmptyStringSchema,
740 details: Schema.optional(TrimmedNonEmptyStringSchema),
741});
742export type DeprecationNoticePayload = typeof DeprecationNoticePayload.Type;
743​
744const FilesPersistedPayload = Schema.Struct({
745 files: Schema.Array(
746 Schema.Struct({
747 filename: TrimmedNonEmptyStringSchema,
748 fileId: TrimmedNonEmptyStringSchema,
749 }),
750 ),
751 failed: Schema.optional(
752 Schema.Array(
753 Schema.Struct({
754 filename: TrimmedNonEmptyStringSchema,
755 error: TrimmedNonEmptyStringSchema,
756 }),
757 ),
758 ),
759});
760export type FilesPersistedPayload = typeof FilesPersistedPayload.Type;
761​
762const ToolDeniedPayload = Schema.Struct({
763 toolName: TrimmedNonEmptyStringSchema,
764 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
765 reason: Schema.optional(TrimmedNonEmptyStringSchema),
766 agentId: Schema.optional(TrimmedNonEmptyStringSchema),
767});
768export type ToolDeniedPayload = typeof ToolDeniedPayload.Type;
769​
770const RuntimeWarningPayload = Schema.Struct({
771 message: TrimmedNonEmptyStringSchema,
772 detail: Schema.optional(Schema.Unknown),
773});
774export type RuntimeWarningPayload = typeof RuntimeWarningPayload.Type;
775​
776const RuntimeErrorPayload = Schema.Struct({
777 message: TrimmedNonEmptyStringSchema,
778 class: Schema.optional(RuntimeErrorClass),
779 detail: Schema.optional(Schema.Unknown),
780});
781export type RuntimeErrorPayload = typeof RuntimeErrorPayload.Type;
782​
783const ProviderRuntimeSessionStartedEvent = Schema.Struct({
784 ...ProviderRuntimeEventBase.fields,
785 type: SessionStartedType,
786 payload: SessionStartedPayload,
787});
788export type ProviderRuntimeSessionStartedEvent = typeof ProviderRuntimeSessionStartedEvent.Type;
789​
790const ProviderRuntimeSessionConfiguredEvent = Schema.Struct({
791 ...ProviderRuntimeEventBase.fields,
792 type: SessionConfiguredType,
793 payload: SessionConfiguredPayload,
794});
795export type ProviderRuntimeSessionConfiguredEvent =
796 typeof ProviderRuntimeSessionConfiguredEvent.Type;
797​
798const ProviderRuntimeSessionStateChangedEvent = Schema.Struct({
799 ...ProviderRuntimeEventBase.fields,
800 type: SessionStateChangedType,
801 payload: SessionStateChangedPayload,
802});
803export type ProviderRuntimeSessionStateChangedEvent =
804 typeof ProviderRuntimeSessionStateChangedEvent.Type;
805​
806const ProviderRuntimeSessionExitedEvent = Schema.Struct({
807 ...ProviderRuntimeEventBase.fields,
808 type: SessionExitedType,
809 payload: SessionExitedPayload,
810});
811export type ProviderRuntimeSessionExitedEvent = typeof ProviderRuntimeSessionExitedEvent.Type;
812​
813const ProviderRuntimeThreadStartedEvent = Schema.Struct({
814 ...ProviderRuntimeEventBase.fields,
815 type: ThreadStartedType,
816 payload: ThreadStartedPayload,
817});
818export type ProviderRuntimeThreadStartedEvent = typeof ProviderRuntimeThreadStartedEvent.Type;
819​
820const ProviderRuntimeThreadStateChangedEvent = Schema.Struct({
821 ...ProviderRuntimeEventBase.fields,
822 type: ThreadStateChangedType,
823 payload: ThreadStateChangedPayload,
824});
825export type ProviderRuntimeThreadStateChangedEvent =
826 typeof ProviderRuntimeThreadStateChangedEvent.Type;
827​
828const ProviderRuntimeThreadMetadataUpdatedEvent = Schema.Struct({
829 ...ProviderRuntimeEventBase.fields,
830 type: ThreadMetadataUpdatedType,
831 payload: ThreadMetadataUpdatedPayload,
832});
833export type ProviderRuntimeThreadMetadataUpdatedEvent =
834 typeof ProviderRuntimeThreadMetadataUpdatedEvent.Type;
835​
836const ProviderRuntimeThreadTokenUsageUpdatedEvent = Schema.Struct({
837 ...ProviderRuntimeEventBase.fields,
838 type: ThreadTokenUsageUpdatedType,
839 payload: ThreadTokenUsageUpdatedPayload,
840});
841export type ProviderRuntimeThreadTokenUsageUpdatedEvent =
842 typeof ProviderRuntimeThreadTokenUsageUpdatedEvent.Type;
843​
844const ProviderRuntimeThreadRealtimeStartedEvent = Schema.Struct({
845 ...ProviderRuntimeEventBase.fields,
846 type: ThreadRealtimeStartedType,
847 payload: ThreadRealtimeStartedPayload,
848});
849export type ProviderRuntimeThreadRealtimeStartedEvent =
850 typeof ProviderRuntimeThreadRealtimeStartedEvent.Type;
851​
852const ProviderRuntimeThreadRealtimeItemAddedEvent = Schema.Struct({
853 ...ProviderRuntimeEventBase.fields,
854 type: ThreadRealtimeItemAddedType,
855 payload: ThreadRealtimeItemAddedPayload,
856});
857export type ProviderRuntimeThreadRealtimeItemAddedEvent =
858 typeof ProviderRuntimeThreadRealtimeItemAddedEvent.Type;
859​
860const ProviderRuntimeThreadRealtimeAudioDeltaEvent = Schema.Struct({
861 ...ProviderRuntimeEventBase.fields,
862 type: ThreadRealtimeAudioDeltaType,
863 payload: ThreadRealtimeAudioDeltaPayload,
864});
865export type ProviderRuntimeThreadRealtimeAudioDeltaEvent =
866 typeof ProviderRuntimeThreadRealtimeAudioDeltaEvent.Type;
867​
868const ProviderRuntimeThreadRealtimeErrorEvent = Schema.Struct({
869 ...ProviderRuntimeEventBase.fields,
870 type: ThreadRealtimeErrorType,
871 payload: ThreadRealtimeErrorPayload,
872});
873export type ProviderRuntimeThreadRealtimeErrorEvent =
874 typeof ProviderRuntimeThreadRealtimeErrorEvent.Type;
875​
876const ProviderRuntimeThreadRealtimeClosedEvent = Schema.Struct({
877 ...ProviderRuntimeEventBase.fields,
878 type: ThreadRealtimeClosedType,
879 payload: ThreadRealtimeClosedPayload,
880});
881export type ProviderRuntimeThreadRealtimeClosedEvent =
882 typeof ProviderRuntimeThreadRealtimeClosedEvent.Type;
883​
884const ProviderRuntimeTurnStartedEvent = Schema.Struct({
885 ...ProviderRuntimeEventBase.fields,
886 type: TurnStartedType,
887 payload: TurnStartedPayload,
888});
889export type ProviderRuntimeTurnStartedEvent = typeof ProviderRuntimeTurnStartedEvent.Type;
890​
891const ProviderRuntimeTurnCompletedEvent = Schema.Struct({
892 ...ProviderRuntimeEventBase.fields,
893 type: TurnCompletedType,
894 payload: TurnCompletedPayload,
895});
896export type ProviderRuntimeTurnCompletedEvent = typeof ProviderRuntimeTurnCompletedEvent.Type;
897​
898const ProviderRuntimeTurnAbortedEvent = Schema.Struct({
899 ...ProviderRuntimeEventBase.fields,
900 type: TurnAbortedType,
901 payload: TurnAbortedPayload,
902});
903export type ProviderRuntimeTurnAbortedEvent = typeof ProviderRuntimeTurnAbortedEvent.Type;
904​
905const ProviderRuntimeTurnPlanUpdatedEvent = Schema.Struct({
906 ...ProviderRuntimeEventBase.fields,
907 type: TurnPlanUpdatedType,
908 payload: TurnPlanUpdatedPayload,
909});
910export type ProviderRuntimeTurnPlanUpdatedEvent = typeof ProviderRuntimeTurnPlanUpdatedEvent.Type;
911​
912const ProviderRuntimeTurnProposedDeltaEvent = Schema.Struct({
913 ...ProviderRuntimeEventBase.fields,
914 type: TurnProposedDeltaType,
915 payload: TurnProposedDeltaPayload,
916});
917export type ProviderRuntimeTurnProposedDeltaEvent =
918 typeof ProviderRuntimeTurnProposedDeltaEvent.Type;
919​
920const ProviderRuntimeTurnProposedCompletedEvent = Schema.Struct({
921 ...ProviderRuntimeEventBase.fields,
922 type: TurnProposedCompletedType,
923 payload: TurnProposedCompletedPayload,
924});
925export type ProviderRuntimeTurnProposedCompletedEvent =
926 typeof ProviderRuntimeTurnProposedCompletedEvent.Type;
927​
928const ProviderRuntimeTurnDiffUpdatedEvent = Schema.Struct({
929 ...ProviderRuntimeEventBase.fields,
930 type: TurnDiffUpdatedType,
931 payload: TurnDiffUpdatedPayload,
932});
933export type ProviderRuntimeTurnDiffUpdatedEvent = typeof ProviderRuntimeTurnDiffUpdatedEvent.Type;
934​
935const ProviderRuntimeItemStartedEvent = Schema.Struct({
936 ...ProviderRuntimeEventBase.fields,
937 type: ItemStartedType,
938 payload: ItemLifecyclePayload,
939});
940export type ProviderRuntimeItemStartedEvent = typeof ProviderRuntimeItemStartedEvent.Type;
941​
942const ProviderRuntimeItemUpdatedEvent = Schema.Struct({
943 ...ProviderRuntimeEventBase.fields,
944 type: ItemUpdatedType,
945 payload: ItemLifecyclePayload,
946});
947export type ProviderRuntimeItemUpdatedEvent = typeof ProviderRuntimeItemUpdatedEvent.Type;
948​
949const ProviderRuntimeItemCompletedEvent = Schema.Struct({
950 ...ProviderRuntimeEventBase.fields,
951 type: ItemCompletedType,
952 payload: ItemLifecyclePayload,
953});
954export type ProviderRuntimeItemCompletedEvent = typeof ProviderRuntimeItemCompletedEvent.Type;
955​
956const ProviderRuntimeContentDeltaEvent = Schema.Struct({
957 ...ProviderRuntimeEventBase.fields,
958 type: ContentDeltaType,
959 payload: ContentDeltaPayload,
960});
961export type ProviderRuntimeContentDeltaEvent = typeof ProviderRuntimeContentDeltaEvent.Type;
962​
963const ProviderRuntimeRequestOpenedEvent = Schema.Struct({
964 ...ProviderRuntimeEventBase.fields,
965 type: RequestOpenedType,
966 payload: RequestOpenedPayload,
967});
968export type ProviderRuntimeRequestOpenedEvent = typeof ProviderRuntimeRequestOpenedEvent.Type;
969​
970const ProviderRuntimeRequestResolvedEvent = Schema.Struct({
971 ...ProviderRuntimeEventBase.fields,
972 type: RequestResolvedType,
973 payload: RequestResolvedPayload,
974});
975export type ProviderRuntimeRequestResolvedEvent = typeof ProviderRuntimeRequestResolvedEvent.Type;
976​
977const ProviderRuntimeUserInputRequestedEvent = Schema.Struct({
978 ...ProviderRuntimeEventBase.fields,
979 type: UserInputRequestedType,
980 payload: UserInputRequestedPayload,
981});
982export type ProviderRuntimeUserInputRequestedEvent =
983 typeof ProviderRuntimeUserInputRequestedEvent.Type;
984​
985const ProviderRuntimeUserInputResolvedEvent = Schema.Struct({
986 ...ProviderRuntimeEventBase.fields,
987 type: UserInputResolvedType,
988 payload: UserInputResolvedPayload,
989});
990export type ProviderRuntimeUserInputResolvedEvent =
991 typeof ProviderRuntimeUserInputResolvedEvent.Type;
992​
993const ProviderRuntimeTaskStartedEvent = Schema.Struct({
994 ...ProviderRuntimeEventBase.fields,
995 type: TaskStartedType,
996 payload: TaskStartedPayload,
997});
998export type ProviderRuntimeTaskStartedEvent = typeof ProviderRuntimeTaskStartedEvent.Type;
999​
1000const ProviderRuntimeTaskProgressEvent = Schema.Struct({
1001 ...ProviderRuntimeEventBase.fields,
1002 type: TaskProgressType,
1003 payload: TaskProgressPayload,
1004});
1005export type ProviderRuntimeTaskProgressEvent = typeof ProviderRuntimeTaskProgressEvent.Type;
1006​
1007const ProviderRuntimeTaskUpdatedEvent = Schema.Struct({
1008 ...ProviderRuntimeEventBase.fields,
1009 type: TaskUpdatedType,
1010 payload: TaskUpdatedPayload,
1011});
1012export type ProviderRuntimeTaskUpdatedEvent = typeof ProviderRuntimeTaskUpdatedEvent.Type;
1013​
1014const ProviderRuntimeTaskCompletedEvent = Schema.Struct({
1015 ...ProviderRuntimeEventBase.fields,
1016 type: TaskCompletedType,
1017 payload: TaskCompletedPayload,
1018});
1019export type ProviderRuntimeTaskCompletedEvent = typeof ProviderRuntimeTaskCompletedEvent.Type;
1020​
1021const ProviderRuntimeHookStartedEvent = Schema.Struct({
1022 ...ProviderRuntimeEventBase.fields,
1023 type: HookStartedType,
1024 payload: HookStartedPayload,
1025});
1026export type ProviderRuntimeHookStartedEvent = typeof ProviderRuntimeHookStartedEvent.Type;
1027​
1028const ProviderRuntimeHookProgressEvent = Schema.Struct({
1029 ...ProviderRuntimeEventBase.fields,
1030 type: HookProgressType,
1031 payload: HookProgressPayload,
1032});
1033export type ProviderRuntimeHookProgressEvent = typeof ProviderRuntimeHookProgressEvent.Type;
1034​
1035const ProviderRuntimeHookCompletedEvent = Schema.Struct({
1036 ...ProviderRuntimeEventBase.fields,
1037 type: HookCompletedType,
1038 payload: HookCompletedPayload,
1039});
1040export type ProviderRuntimeHookCompletedEvent = typeof ProviderRuntimeHookCompletedEvent.Type;
1041​
1042const ProviderRuntimeToolProgressEvent = Schema.Struct({
1043 ...ProviderRuntimeEventBase.fields,
1044 type: ToolProgressType,
1045 payload: ToolProgressPayload,
1046});
1047export type ProviderRuntimeToolProgressEvent = typeof ProviderRuntimeToolProgressEvent.Type;
1048​
1049const ProviderRuntimeToolSummaryEvent = Schema.Struct({
1050 ...ProviderRuntimeEventBase.fields,
1051 type: ToolSummaryType,
1052 payload: ToolSummaryPayload,
1053});
1054export type ProviderRuntimeToolSummaryEvent = typeof ProviderRuntimeToolSummaryEvent.Type;
1055​
1056const ProviderRuntimeAuthStatusEvent = Schema.Struct({
1057 ...ProviderRuntimeEventBase.fields,
1058 type: AuthStatusType,
1059 payload: AuthStatusPayload,
1060});
1061export type ProviderRuntimeAuthStatusEvent = typeof ProviderRuntimeAuthStatusEvent.Type;
1062​
1063const ProviderRuntimeAccountUpdatedEvent = Schema.Struct({
1064 ...ProviderRuntimeEventBase.fields,
1065 type: AccountUpdatedType,
1066 payload: AccountUpdatedPayload,
1067});
1068export type ProviderRuntimeAccountUpdatedEvent = typeof ProviderRuntimeAccountUpdatedEvent.Type;
1069​
1070const ProviderRuntimeAccountRateLimitsUpdatedEvent = Schema.Struct({
1071 ...ProviderRuntimeEventBase.fields,
1072 type: AccountRateLimitsUpdatedType,
1073 payload: AccountRateLimitsUpdatedPayload,
1074});
1075export type ProviderRuntimeAccountRateLimitsUpdatedEvent =
1076 typeof ProviderRuntimeAccountRateLimitsUpdatedEvent.Type;
1077​
1078const ProviderRuntimeMcpStatusUpdatedEvent = Schema.Struct({
1079 ...ProviderRuntimeEventBase.fields,
1080 type: McpStatusUpdatedType,
1081 payload: McpStatusUpdatedPayload,
1082});
1083export type ProviderRuntimeMcpStatusUpdatedEvent = typeof ProviderRuntimeMcpStatusUpdatedEvent.Type;
1084​
1085const ProviderRuntimeMcpOauthCompletedEvent = Schema.Struct({
1086 ...ProviderRuntimeEventBase.fields,
1087 type: McpOauthCompletedType,
1088 payload: McpOauthCompletedPayload,
1089});
1090export type ProviderRuntimeMcpOauthCompletedEvent =
1091 typeof ProviderRuntimeMcpOauthCompletedEvent.Type;
1092​
1093const ProviderRuntimeModelReroutedEvent = Schema.Struct({
1094 ...ProviderRuntimeEventBase.fields,
1095 type: ModelReroutedType,
1096 payload: ModelReroutedPayload,
1097});
1098export type ProviderRuntimeModelReroutedEvent = typeof ProviderRuntimeModelReroutedEvent.Type;
1099​
1100const ProviderRuntimeConfigWarningEvent = Schema.Struct({
1101 ...ProviderRuntimeEventBase.fields,
1102 type: ConfigWarningType,
1103 payload: ConfigWarningPayload,
1104});
1105export type ProviderRuntimeConfigWarningEvent = typeof ProviderRuntimeConfigWarningEvent.Type;
1106​
1107const ProviderRuntimeDeprecationNoticeEvent = Schema.Struct({
1108 ...ProviderRuntimeEventBase.fields,
1109 type: DeprecationNoticeType,
1110 payload: DeprecationNoticePayload,
1111});
1112export type ProviderRuntimeDeprecationNoticeEvent =
1113 typeof ProviderRuntimeDeprecationNoticeEvent.Type;
1114​
1115const ProviderRuntimeFilesPersistedEvent = Schema.Struct({
1116 ...ProviderRuntimeEventBase.fields,
1117 type: FilesPersistedType,
1118 payload: FilesPersistedPayload,
1119});
1120export type ProviderRuntimeFilesPersistedEvent = typeof ProviderRuntimeFilesPersistedEvent.Type;
1121​
1122const ProviderRuntimeToolDeniedEvent = Schema.Struct({
1123 ...ProviderRuntimeEventBase.fields,
1124 type: ToolDeniedType,
1125 payload: ToolDeniedPayload,
1126});
1127export type ProviderRuntimeToolDeniedEvent = typeof ProviderRuntimeToolDeniedEvent.Type;
1128​
1129const ProviderRuntimeWarningEvent = Schema.Struct({
1130 ...ProviderRuntimeEventBase.fields,
1131 type: RuntimeWarningType,
1132 payload: RuntimeWarningPayload,
1133});
1134export type ProviderRuntimeWarningEvent = typeof ProviderRuntimeWarningEvent.Type;
1135​
1136const ProviderRuntimeErrorEvent = Schema.Struct({
1137 ...ProviderRuntimeEventBase.fields,
1138 type: RuntimeErrorType,
1139 payload: RuntimeErrorPayload,
1140});
1141export type ProviderRuntimeErrorEvent = typeof ProviderRuntimeErrorEvent.Type;
1142​
1143export const ProviderRuntimeEventV2 = Schema.Union([
1144 ProviderRuntimeSessionStartedEvent,
1145 ProviderRuntimeSessionConfiguredEvent,
1146 ProviderRuntimeSessionStateChangedEvent,
1147 ProviderRuntimeSessionExitedEvent,
1148 ProviderRuntimeThreadStartedEvent,
1149 ProviderRuntimeThreadStateChangedEvent,
1150 ProviderRuntimeThreadMetadataUpdatedEvent,
1151 ProviderRuntimeThreadTokenUsageUpdatedEvent,
1152 ProviderRuntimeThreadRealtimeStartedEvent,
1153 ProviderRuntimeThreadRealtimeItemAddedEvent,
1154 ProviderRuntimeThreadRealtimeAudioDeltaEvent,
1155 ProviderRuntimeThreadRealtimeErrorEvent,
1156 ProviderRuntimeThreadRealtimeClosedEvent,
1157 ProviderRuntimeTurnStartedEvent,
1158 ProviderRuntimeTurnCompletedEvent,
1159 ProviderRuntimeTurnAbortedEvent,
1160 ProviderRuntimeTurnPlanUpdatedEvent,
1161 ProviderRuntimeTurnProposedDeltaEvent,
1162 ProviderRuntimeTurnProposedCompletedEvent,
1163 ProviderRuntimeTurnDiffUpdatedEvent,
1164 ProviderRuntimeItemStartedEvent,
1165 ProviderRuntimeItemUpdatedEvent,
1166 ProviderRuntimeItemCompletedEvent,
1167 ProviderRuntimeContentDeltaEvent,
1168 ProviderRuntimeRequestOpenedEvent,
1169 ProviderRuntimeRequestResolvedEvent,
1170 ProviderRuntimeUserInputRequestedEvent,
1171 ProviderRuntimeUserInputResolvedEvent,
1172 ProviderRuntimeTaskStartedEvent,
1173 ProviderRuntimeTaskProgressEvent,
1174 ProviderRuntimeTaskUpdatedEvent,
1175 ProviderRuntimeTaskCompletedEvent,
1176 ProviderRuntimeHookStartedEvent,
1177 ProviderRuntimeHookProgressEvent,
1178 ProviderRuntimeHookCompletedEvent,
1179 ProviderRuntimeToolProgressEvent,
1180 ProviderRuntimeToolSummaryEvent,
1181 ProviderRuntimeAuthStatusEvent,
1182 ProviderRuntimeAccountUpdatedEvent,
1183 ProviderRuntimeAccountRateLimitsUpdatedEvent,
1184 ProviderRuntimeMcpStatusUpdatedEvent,
1185 ProviderRuntimeMcpOauthCompletedEvent,
1186 ProviderRuntimeModelReroutedEvent,
1187 ProviderRuntimeConfigWarningEvent,
1188 ProviderRuntimeDeprecationNoticeEvent,
1189 ProviderRuntimeFilesPersistedEvent,
1190 ProviderRuntimeToolDeniedEvent,
1191 ProviderRuntimeWarningEvent,
1192 ProviderRuntimeErrorEvent,
1193]);
1194export type ProviderRuntimeEventV2 = typeof ProviderRuntimeEventV2.Type;
1195​
1196export const ProviderRuntimeEvent = ProviderRuntimeEventV2;
1197export type ProviderRuntimeEvent = ProviderRuntimeEventV2;
1198​
1199// Compatibility aliases for call sites still importing legacy names.
1200const ProviderRuntimeMessageDeltaEvent = ProviderRuntimeContentDeltaEvent;
1201export type ProviderRuntimeMessageDeltaEvent = ProviderRuntimeContentDeltaEvent;
1202const ProviderRuntimeMessageCompletedEvent = ProviderRuntimeItemCompletedEvent;
1203export type ProviderRuntimeMessageCompletedEvent = ProviderRuntimeItemCompletedEvent;
1204const ProviderRuntimeToolStartedEvent = ProviderRuntimeItemStartedEvent;
1205export type ProviderRuntimeToolStartedEvent = ProviderRuntimeItemStartedEvent;
1206const ProviderRuntimeToolCompletedEvent = ProviderRuntimeItemCompletedEvent;
1207export type ProviderRuntimeToolCompletedEvent = ProviderRuntimeItemCompletedEvent;
1208const ProviderRuntimeApprovalRequestedEvent = ProviderRuntimeRequestOpenedEvent;
1209export type ProviderRuntimeApprovalRequestedEvent = ProviderRuntimeRequestOpenedEvent;
1210const ProviderRuntimeApprovalResolvedEvent = ProviderRuntimeRequestResolvedEvent;
1211export type ProviderRuntimeApprovalResolvedEvent = ProviderRuntimeRequestResolvedEvent;
1212​
1213// Legacy helper aliases retained for adapters/tests.
1214const ProviderRuntimeToolKind = Schema.Literals(["command", "file-read", "file-change", "other"]);
1215export type ProviderRuntimeToolKind = typeof ProviderRuntimeToolKind.Type;
1216​
1217export const ProviderRuntimeTurnStatus = RuntimeTurnState;
1218export type ProviderRuntimeTurnStatus = RuntimeTurnState;