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