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