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