Open History to see the last commit
1import { Option, Schema } from "effect";
2import {
3 EventId,
4 IsoDateTime,
5 NonNegativeInt,
6 ProviderItemId,
7 PositiveInt,
8 RuntimeItemId,
9 RuntimeRequestId,
10 RuntimeTaskId,
11 ThreadId,
12 TrimmedNonEmptyString,
13 TurnId,
14} from "./baseSchemas";
15import { ProviderKind } from "./orchestration";
16
17const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
18const UnknownRecordSchema = Schema.Record(Schema.String, Schema.Unknown);
19
20const RuntimeEventRawSource = Schema.Literals([
21 "codex.app-server.notification",
22 "codex.app-server.request",
23 "codex.eventmsg",
24 "claude.sdk.message",
25 "claude.sdk.permission",
26 "codex.sdk.thread-event",
27]);
28export type RuntimeEventRawSource = typeof RuntimeEventRawSource.Type;
29
30export const RuntimeEventRaw = Schema.Struct({
31 source: RuntimeEventRawSource,
32 method: Schema.optional(TrimmedNonEmptyStringSchema),
33 messageType: Schema.optional(TrimmedNonEmptyStringSchema),
34 payload: Schema.Unknown,
35});
36export type RuntimeEventRaw = typeof RuntimeEventRaw.Type;
37
38const ProviderRequestId = TrimmedNonEmptyStringSchema;
39export type ProviderRequestId = typeof ProviderRequestId.Type;
40
41const ProviderRefs = Schema.Struct({
42 providerTurnId: Schema.optional(TrimmedNonEmptyStringSchema),
43 providerItemId: Schema.optional(ProviderItemId),
44 providerRequestId: Schema.optional(ProviderRequestId),
45});
46export type ProviderRefs = typeof ProviderRefs.Type;
47
48const RuntimeSessionState = Schema.Literals([
49 "starting",
50 "ready",
51 "running",
52 "waiting",
53 "stopped",
54 "error",
55]);
56export type RuntimeSessionState = typeof RuntimeSessionState.Type;
57
58const RuntimeThreadState = Schema.Literals([
59 "active",
60 "idle",
61 "archived",
62 "closed",
63 "compacted",
64 "error",
65]);
66export type RuntimeThreadState = typeof RuntimeThreadState.Type;
67
68const RuntimeTurnState = Schema.Literals(["completed", "failed", "interrupted", "cancelled"]);
69export type RuntimeTurnState = typeof RuntimeTurnState.Type;
70
71const RuntimePlanStepStatus = Schema.Literals(["pending", "inProgress", "completed"]);
72export type RuntimePlanStepStatus = typeof RuntimePlanStepStatus.Type;
73
74const RuntimeItemStatus = Schema.Literals(["inProgress", "completed", "failed", "declined"]);
75export type RuntimeItemStatus = typeof RuntimeItemStatus.Type;
76
77const RuntimeContentStreamKind = Schema.Literals([
78 "assistant_text",
79 "reasoning_text",
80 "reasoning_summary_text",
81 "plan_text",
82 "command_output",
83 "file_change_output",
84 "unknown",
85]);
86export type RuntimeContentStreamKind = typeof RuntimeContentStreamKind.Type;
87
88const RuntimeSessionExitKind = Schema.Literals(["graceful", "error"]);
89export type RuntimeSessionExitKind = typeof RuntimeSessionExitKind.Type;
90
91const RuntimeErrorClass = Schema.Literals([
92 "provider_error",
93 "transport_error",
94 "permission_error",
95 "validation_error",
96 "unknown",
97]);
98export type RuntimeErrorClass = typeof RuntimeErrorClass.Type;
99
100export const TOOL_LIFECYCLE_ITEM_TYPES = [
101 "command_execution",
102 "file_change",
103 "mcp_tool_call",
104 "dynamic_tool_call",
105 "collab_agent_tool_call",
106 "web_search",
107 "image_view",
108] as const;
109
110export const ToolLifecycleItemType = Schema.Literals(TOOL_LIFECYCLE_ITEM_TYPES);
111export type ToolLifecycleItemType = typeof ToolLifecycleItemType.Type;
112
113export function isToolLifecycleItemType(value: string): value is ToolLifecycleItemType {
114 return TOOL_LIFECYCLE_ITEM_TYPES.includes(value as ToolLifecycleItemType);
115}
116
117export const CanonicalItemType = Schema.Literals([
118 "user_message",
119 "assistant_message",
120 "reasoning",
121 "plan",
122 ...TOOL_LIFECYCLE_ITEM_TYPES,
123 "review_entered",
124 "review_exited",
125 "context_compaction",
126 "error",
127 "unknown",
128]);
129export type CanonicalItemType = typeof CanonicalItemType.Type;
130
131export const CanonicalRequestType = Schema.Literals([
132 "command_execution_approval",
133 "file_read_approval",
134 "file_change_approval",
135 "apply_patch_approval",
136 "exec_command_approval",
137 "tool_user_input",
138 "dynamic_tool_call",
139 "auth_tokens_refresh",
140 "unknown",
141]);
142export type CanonicalRequestType = typeof CanonicalRequestType.Type;
143
144const ProviderRuntimeEventType = Schema.Literals([
145 "session.started",
146 "session.configured",
147 "session.state.changed",
148 "session.exited",
149 "thread.started",
150 "thread.state.changed",
151 "thread.metadata.updated",
152 "thread.token-usage.updated",
153 "thread.realtime.started",
154 "thread.realtime.item-added",
155 "thread.realtime.audio.delta",
156 "thread.realtime.error",
157 "thread.realtime.closed",
158 "turn.started",
159 "turn.completed",
160 "turn.aborted",
161 "turn.plan.updated",
162 "turn.proposed.delta",
163 "turn.proposed.completed",
164 "turn.diff.updated",
165 "item.started",
166 "item.updated",
167 "item.completed",
168 "content.delta",
169 "request.opened",
170 "request.resolved",
171 "user-input.requested",
172 "user-input.resolved",
173 "task.started",
174 "task.progress",
175 "task.completed",
176 "hook.started",
177 "hook.progress",
178 "hook.completed",
179 "tool.progress",
180 "tool.summary",
181 "auth.status",
182 "account.updated",
183 "account.rate-limits.updated",
184 "mcp.status.updated",
185 "mcp.oauth.completed",
186 "model.rerouted",
187 "config.warning",
188 "deprecation.notice",
189 "files.persisted",
190 "runtime.warning",
191 "runtime.error",
192]);
193export type ProviderRuntimeEventType = typeof ProviderRuntimeEventType.Type;
194
195const SessionStartedType = Schema.Literal("session.started");
196const SessionConfiguredType = Schema.Literal("session.configured");
197const SessionStateChangedType = Schema.Literal("session.state.changed");
198const SessionExitedType = Schema.Literal("session.exited");
199const ThreadStartedType = Schema.Literal("thread.started");
200const ThreadStateChangedType = Schema.Literal("thread.state.changed");
201const ThreadMetadataUpdatedType = Schema.Literal("thread.metadata.updated");
202const ThreadTokenUsageUpdatedType = Schema.Literal("thread.token-usage.updated");
203const ThreadRealtimeStartedType = Schema.Literal("thread.realtime.started");
204const ThreadRealtimeItemAddedType = Schema.Literal("thread.realtime.item-added");
205const ThreadRealtimeAudioDeltaType = Schema.Literal("thread.realtime.audio.delta");
206const ThreadRealtimeErrorType = Schema.Literal("thread.realtime.error");
207const ThreadRealtimeClosedType = Schema.Literal("thread.realtime.closed");
208const TurnStartedType = Schema.Literal("turn.started");
209const TurnCompletedType = Schema.Literal("turn.completed");
210const TurnAbortedType = Schema.Literal("turn.aborted");
211const TurnPlanUpdatedType = Schema.Literal("turn.plan.updated");
212const TurnProposedDeltaType = Schema.Literal("turn.proposed.delta");
213const TurnProposedCompletedType = Schema.Literal("turn.proposed.completed");
214const TurnDiffUpdatedType = Schema.Literal("turn.diff.updated");
215const ItemStartedType = Schema.Literal("item.started");
216const ItemUpdatedType = Schema.Literal("item.updated");
217const ItemCompletedType = Schema.Literal("item.completed");
218const ContentDeltaType = Schema.Literal("content.delta");
219const RequestOpenedType = Schema.Literal("request.opened");
220const RequestResolvedType = Schema.Literal("request.resolved");
221const UserInputRequestedType = Schema.Literal("user-input.requested");
222const UserInputResolvedType = Schema.Literal("user-input.resolved");
223const TaskStartedType = Schema.Literal("task.started");
224const TaskProgressType = Schema.Literal("task.progress");
225const TaskCompletedType = Schema.Literal("task.completed");
226const HookStartedType = Schema.Literal("hook.started");
227const HookProgressType = Schema.Literal("hook.progress");
228const HookCompletedType = Schema.Literal("hook.completed");
229const ToolProgressType = Schema.Literal("tool.progress");
230const ToolSummaryType = Schema.Literal("tool.summary");
231const AuthStatusType = Schema.Literal("auth.status");
232const AccountUpdatedType = Schema.Literal("account.updated");
233const AccountRateLimitsUpdatedType = Schema.Literal("account.rate-limits.updated");
234const McpStatusUpdatedType = Schema.Literal("mcp.status.updated");
235const McpOauthCompletedType = Schema.Literal("mcp.oauth.completed");
236const ModelReroutedType = Schema.Literal("model.rerouted");
237const ConfigWarningType = Schema.Literal("config.warning");
238const DeprecationNoticeType = Schema.Literal("deprecation.notice");
239const FilesPersistedType = Schema.Literal("files.persisted");
240const RuntimeWarningType = Schema.Literal("runtime.warning");
241const RuntimeErrorType = Schema.Literal("runtime.error");
242
243const ProviderRuntimeEventBase = Schema.Struct({
244 eventId: EventId,
245 provider: ProviderKind,
246 threadId: ThreadId,
247 createdAt: IsoDateTime,
248 turnId: Schema.optional(TurnId),
249 itemId: Schema.optional(RuntimeItemId),
250 requestId: Schema.optional(RuntimeRequestId),
251 providerRefs: Schema.optional(ProviderRefs),
252 raw: Schema.optional(RuntimeEventRaw),
253});
254export type ProviderRuntimeEventBase = typeof ProviderRuntimeEventBase.Type;
255
256const SessionStartedPayload = Schema.Struct({
257 message: Schema.optional(TrimmedNonEmptyStringSchema),
258 resume: Schema.optional(Schema.Unknown),
259});
260export type SessionStartedPayload = typeof SessionStartedPayload.Type;
261
262const SessionConfiguredPayload = Schema.Struct({
263 config: UnknownRecordSchema,
264});
265export type SessionConfiguredPayload = typeof SessionConfiguredPayload.Type;
266
267const SessionStateChangedPayload = Schema.Struct({
268 state: RuntimeSessionState,
269 reason: Schema.optional(TrimmedNonEmptyStringSchema),
270 detail: Schema.optional(Schema.Unknown),
271});
272export type SessionStateChangedPayload = typeof SessionStateChangedPayload.Type;
273
274const SessionExitedPayload = Schema.Struct({
275 reason: Schema.optional(TrimmedNonEmptyStringSchema),
276 recoverable: Schema.optional(Schema.Boolean),
277 exitKind: Schema.optional(RuntimeSessionExitKind),
278});
279export type SessionExitedPayload = typeof SessionExitedPayload.Type;
280
281const ThreadStartedPayload = Schema.Struct({
282 providerThreadId: Schema.optional(TrimmedNonEmptyStringSchema),
283});
284export type ThreadStartedPayload = typeof ThreadStartedPayload.Type;
285
286const ThreadStateChangedPayload = Schema.Struct({
287 state: RuntimeThreadState,
288 detail: Schema.optional(Schema.Unknown),
289});
290export type ThreadStateChangedPayload = typeof ThreadStateChangedPayload.Type;
291
292const ThreadMetadataUpdatedPayload = Schema.Struct({
293 name: Schema.optional(TrimmedNonEmptyStringSchema),
294 metadata: Schema.optional(UnknownRecordSchema),
295});
296export type ThreadMetadataUpdatedPayload = typeof ThreadMetadataUpdatedPayload.Type;
297
298export const ThreadTokenUsageSnapshot = Schema.Struct({
299 usedTokens: NonNegativeInt,
300 totalProcessedTokens: Schema.optional(NonNegativeInt),
301 maxTokens: Schema.optional(PositiveInt),
302 inputTokens: Schema.optional(NonNegativeInt),
303 cachedInputTokens: Schema.optional(NonNegativeInt),
304 outputTokens: Schema.optional(NonNegativeInt),
305 reasoningOutputTokens: Schema.optional(NonNegativeInt),
306 lastUsedTokens: Schema.optional(NonNegativeInt),
307 lastInputTokens: Schema.optional(NonNegativeInt),
308 lastCachedInputTokens: Schema.optional(NonNegativeInt),
309 lastOutputTokens: Schema.optional(NonNegativeInt),
310 lastReasoningOutputTokens: Schema.optional(NonNegativeInt),
311 toolUses: Schema.optional(NonNegativeInt),
312 durationMs: Schema.optional(NonNegativeInt),
313 compactsAutomatically: Schema.optional(Schema.Boolean),
314});
315export type ThreadTokenUsageSnapshot = typeof ThreadTokenUsageSnapshot.Type;
316
317const ThreadTokenUsageUpdatedPayload = Schema.Struct({
318 usage: ThreadTokenUsageSnapshot,
319});
320export type ThreadTokenUsageUpdatedPayload = typeof ThreadTokenUsageUpdatedPayload.Type;
321
322const ThreadRealtimeStartedPayload = Schema.Struct({
323 realtimeSessionId: Schema.optional(TrimmedNonEmptyStringSchema),
324});
325export type ThreadRealtimeStartedPayload = typeof ThreadRealtimeStartedPayload.Type;
326
327const ThreadRealtimeItemAddedPayload = Schema.Struct({
328 item: Schema.Unknown,
329});
330export type ThreadRealtimeItemAddedPayload = typeof ThreadRealtimeItemAddedPayload.Type;
331
332const ThreadRealtimeAudioDeltaPayload = Schema.Struct({
333 audio: Schema.Unknown,
334});
335export type ThreadRealtimeAudioDeltaPayload = typeof ThreadRealtimeAudioDeltaPayload.Type;
336
337const ThreadRealtimeErrorPayload = Schema.Struct({
338 message: TrimmedNonEmptyStringSchema,
339});
340export type ThreadRealtimeErrorPayload = typeof ThreadRealtimeErrorPayload.Type;
341
342const ThreadRealtimeClosedPayload = Schema.Struct({
343 reason: Schema.optional(TrimmedNonEmptyStringSchema),
344});
345export type ThreadRealtimeClosedPayload = typeof ThreadRealtimeClosedPayload.Type;
346
347const TurnStartedPayload = Schema.Struct({
348 model: Schema.optional(TrimmedNonEmptyStringSchema),
349 effort: Schema.optional(TrimmedNonEmptyStringSchema),
350});
351export type TurnStartedPayload = typeof TurnStartedPayload.Type;
352
353const TurnCompletedPayload = Schema.Struct({
354 state: RuntimeTurnState,
355 stopReason: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
356 usage: Schema.optional(Schema.Unknown),
357 modelUsage: Schema.optional(UnknownRecordSchema),
358 totalCostUsd: Schema.optional(Schema.Number),
359 errorMessage: Schema.optional(TrimmedNonEmptyStringSchema),
360});
361export type TurnCompletedPayload = typeof TurnCompletedPayload.Type;
362
363const TurnAbortedPayload = Schema.Struct({
364 reason: TrimmedNonEmptyStringSchema,
365});
366export type TurnAbortedPayload = typeof TurnAbortedPayload.Type;
367
368const RuntimePlanStep = Schema.Struct({
369 step: TrimmedNonEmptyStringSchema,
370 status: RuntimePlanStepStatus,
371});
372export type RuntimePlanStep = typeof RuntimePlanStep.Type;
373
374const TurnPlanUpdatedPayload = Schema.Struct({
375 explanation: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
376 plan: Schema.Array(RuntimePlanStep),
377});
378export type TurnPlanUpdatedPayload = typeof TurnPlanUpdatedPayload.Type;
379
380const TurnProposedDeltaPayload = Schema.Struct({
381 delta: Schema.String,
382});
383export type TurnProposedDeltaPayload = typeof TurnProposedDeltaPayload.Type;
384
385const TurnProposedCompletedPayload = Schema.Struct({
386 planMarkdown: TrimmedNonEmptyStringSchema,
387});
388export type TurnProposedCompletedPayload = typeof TurnProposedCompletedPayload.Type;
389
390const TurnDiffUpdatedPayload = Schema.Struct({
391 unifiedDiff: Schema.String,
392});
393export type TurnDiffUpdatedPayload = typeof TurnDiffUpdatedPayload.Type;
394
395export const ItemLifecyclePayload = Schema.Struct({
396 itemType: CanonicalItemType,
397 status: Schema.optional(RuntimeItemStatus),
398 title: Schema.optional(TrimmedNonEmptyStringSchema),
399 detail: Schema.optional(TrimmedNonEmptyStringSchema),
400 data: Schema.optional(Schema.Unknown),
401});
402export type ItemLifecyclePayload = typeof ItemLifecyclePayload.Type;
403
404const ContentDeltaPayload = Schema.Struct({
405 streamKind: RuntimeContentStreamKind,
406 delta: Schema.String,
407 contentIndex: Schema.optional(Schema.Int),
408 summaryIndex: Schema.optional(Schema.Int),
409});
410export type ContentDeltaPayload = typeof ContentDeltaPayload.Type;
411
412const RequestOpenedPayload = Schema.Struct({
413 requestType: CanonicalRequestType,
414 detail: Schema.optional(TrimmedNonEmptyStringSchema),
415 args: Schema.optional(Schema.Unknown),
416});
417export type RequestOpenedPayload = typeof RequestOpenedPayload.Type;
418
419const RequestResolvedPayload = Schema.Struct({
420 requestType: CanonicalRequestType,
421 decision: Schema.optional(TrimmedNonEmptyStringSchema),
422 resolution: Schema.optional(Schema.Unknown),
423});
424export type RequestResolvedPayload = typeof RequestResolvedPayload.Type;
425
426const UserInputQuestionOption = Schema.Struct({
427 label: TrimmedNonEmptyStringSchema,
428 description: TrimmedNonEmptyStringSchema,
429});
430export type UserInputQuestionOption = typeof UserInputQuestionOption.Type;
431
432export const UserInputQuestion = Schema.Struct({
433 id: TrimmedNonEmptyStringSchema,
434 header: TrimmedNonEmptyStringSchema,
435 question: TrimmedNonEmptyStringSchema,
436 options: Schema.Array(UserInputQuestionOption),
437 multiSelect: Schema.optional(Schema.Boolean).pipe(
438 Schema.withConstructorDefault(() => Option.some(false)),
439 ),
440});
441export type UserInputQuestion = typeof UserInputQuestion.Type;
442
443const UserInputRequestedPayload = Schema.Struct({
444 questions: Schema.Array(UserInputQuestion),
445});
446export type UserInputRequestedPayload = typeof UserInputRequestedPayload.Type;
447
448const UserInputResolvedPayload = Schema.Struct({
449 answers: UnknownRecordSchema,
450});
451export type UserInputResolvedPayload = typeof UserInputResolvedPayload.Type;
452
453const TaskStartedPayload = Schema.Struct({
454 taskId: RuntimeTaskId,
455 description: Schema.optional(TrimmedNonEmptyStringSchema),
456 taskType: Schema.optional(TrimmedNonEmptyStringSchema),
457});
458export type TaskStartedPayload = typeof TaskStartedPayload.Type;
459
460const TaskProgressPayload = Schema.Struct({
461 taskId: RuntimeTaskId,
462 description: TrimmedNonEmptyStringSchema,
463 summary: Schema.optional(TrimmedNonEmptyStringSchema),
464 usage: Schema.optional(Schema.Unknown),
465 lastToolName: Schema.optional(TrimmedNonEmptyStringSchema),
466});
467export type TaskProgressPayload = typeof TaskProgressPayload.Type;
468
469const TaskCompletedPayload = Schema.Struct({
470 taskId: RuntimeTaskId,
471 status: Schema.Literals(["completed", "failed", "stopped"]),
472 summary: Schema.optional(TrimmedNonEmptyStringSchema),
473 usage: Schema.optional(Schema.Unknown),
474});
475export type TaskCompletedPayload = typeof TaskCompletedPayload.Type;
476
477const HookStartedPayload = Schema.Struct({
478 hookId: TrimmedNonEmptyStringSchema,
479 hookName: TrimmedNonEmptyStringSchema,
480 hookEvent: TrimmedNonEmptyStringSchema,
481});
482export type HookStartedPayload = typeof HookStartedPayload.Type;
483
484const HookProgressPayload = Schema.Struct({
485 hookId: TrimmedNonEmptyStringSchema,
486 output: Schema.optional(Schema.String),
487 stdout: Schema.optional(Schema.String),
488 stderr: Schema.optional(Schema.String),
489});
490export type HookProgressPayload = typeof HookProgressPayload.Type;
491
492const HookCompletedPayload = Schema.Struct({
493 hookId: TrimmedNonEmptyStringSchema,
494 outcome: Schema.Literals(["success", "error", "cancelled"]),
495 output: Schema.optional(Schema.String),
496 stdout: Schema.optional(Schema.String),
497 stderr: Schema.optional(Schema.String),
498 exitCode: Schema.optional(Schema.Int),
499});
500export type HookCompletedPayload = typeof HookCompletedPayload.Type;
501
502const ToolProgressPayload = Schema.Struct({
503 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
504 toolName: Schema.optional(TrimmedNonEmptyStringSchema),
505 summary: Schema.optional(TrimmedNonEmptyStringSchema),
506 elapsedSeconds: Schema.optional(Schema.Number),
507});
508export type ToolProgressPayload = typeof ToolProgressPayload.Type;
509
510const ToolSummaryPayload = Schema.Struct({
511 summary: TrimmedNonEmptyStringSchema,
512 precedingToolUseIds: Schema.optional(Schema.Array(TrimmedNonEmptyStringSchema)),
513});
514export type ToolSummaryPayload = typeof ToolSummaryPayload.Type;
515
516const AuthStatusPayload = Schema.Struct({
517 isAuthenticating: Schema.optional(Schema.Boolean),
518 output: Schema.optional(Schema.Array(Schema.String)),
519 error: Schema.optional(TrimmedNonEmptyStringSchema),
520});
521export type AuthStatusPayload = typeof AuthStatusPayload.Type;
522
523const AccountUpdatedPayload = Schema.Struct({
524 account: Schema.Unknown,
525});
526export type AccountUpdatedPayload = typeof AccountUpdatedPayload.Type;
527
528const AccountRateLimitsUpdatedPayload = Schema.Struct({
529 rateLimits: Schema.Unknown,
530});
531export type AccountRateLimitsUpdatedPayload = typeof AccountRateLimitsUpdatedPayload.Type;
532
533const McpStatusUpdatedPayload = Schema.Struct({
534 status: Schema.Unknown,
535});
536export type McpStatusUpdatedPayload = typeof McpStatusUpdatedPayload.Type;
537
538const McpOauthCompletedPayload = Schema.Struct({
539 success: Schema.Boolean,
540 name: Schema.optional(TrimmedNonEmptyStringSchema),
541 error: Schema.optional(TrimmedNonEmptyStringSchema),
542});
543export type McpOauthCompletedPayload = typeof McpOauthCompletedPayload.Type;
544
545const ModelReroutedPayload = Schema.Struct({
546 fromModel: TrimmedNonEmptyStringSchema,
547 toModel: TrimmedNonEmptyStringSchema,
548 reason: TrimmedNonEmptyStringSchema,
549});
550export type ModelReroutedPayload = typeof ModelReroutedPayload.Type;
551
552const ConfigWarningPayload = Schema.Struct({
553 summary: TrimmedNonEmptyStringSchema,
554 details: Schema.optional(TrimmedNonEmptyStringSchema),
555 path: Schema.optional(TrimmedNonEmptyStringSchema),
556 range: Schema.optional(Schema.Unknown),
557});
558export type ConfigWarningPayload = typeof ConfigWarningPayload.Type;
559
560const DeprecationNoticePayload = Schema.Struct({
561 summary: TrimmedNonEmptyStringSchema,
562 details: Schema.optional(TrimmedNonEmptyStringSchema),
563});
564export type DeprecationNoticePayload = typeof DeprecationNoticePayload.Type;
565
566const FilesPersistedPayload = Schema.Struct({
567 files: Schema.Array(
568 Schema.Struct({
569 filename: TrimmedNonEmptyStringSchema,
570 fileId: TrimmedNonEmptyStringSchema,
571 }),
572 ),
573 failed: Schema.optional(
574 Schema.Array(
575 Schema.Struct({
576 filename: TrimmedNonEmptyStringSchema,
577 error: TrimmedNonEmptyStringSchema,
578 }),
579 ),
580 ),
581});
582export type FilesPersistedPayload = typeof FilesPersistedPayload.Type;
583
584const RuntimeWarningPayload = Schema.Struct({
585 message: TrimmedNonEmptyStringSchema,
586 detail: Schema.optional(Schema.Unknown),
587});
588export type RuntimeWarningPayload = typeof RuntimeWarningPayload.Type;
589
590const RuntimeErrorPayload = Schema.Struct({
591 message: TrimmedNonEmptyStringSchema,
592 class: Schema.optional(RuntimeErrorClass),
593 detail: Schema.optional(Schema.Unknown),
594});
595export type RuntimeErrorPayload = typeof RuntimeErrorPayload.Type;
596
597const ProviderRuntimeSessionStartedEvent = Schema.Struct({
598 ...ProviderRuntimeEventBase.fields,
599 type: SessionStartedType,
600 payload: SessionStartedPayload,
601});
602export type ProviderRuntimeSessionStartedEvent = typeof ProviderRuntimeSessionStartedEvent.Type;
603
604const ProviderRuntimeSessionConfiguredEvent = Schema.Struct({
605 ...ProviderRuntimeEventBase.fields,
606 type: SessionConfiguredType,
607 payload: SessionConfiguredPayload,
608});
609export type ProviderRuntimeSessionConfiguredEvent =
610 typeof ProviderRuntimeSessionConfiguredEvent.Type;
611
612const ProviderRuntimeSessionStateChangedEvent = Schema.Struct({
613 ...ProviderRuntimeEventBase.fields,
614 type: SessionStateChangedType,
615 payload: SessionStateChangedPayload,
616});
617export type ProviderRuntimeSessionStateChangedEvent =
618 typeof ProviderRuntimeSessionStateChangedEvent.Type;
619
620const ProviderRuntimeSessionExitedEvent = Schema.Struct({
621 ...ProviderRuntimeEventBase.fields,
622 type: SessionExitedType,
623 payload: SessionExitedPayload,
624});
625export type ProviderRuntimeSessionExitedEvent = typeof ProviderRuntimeSessionExitedEvent.Type;
626
627const ProviderRuntimeThreadStartedEvent = Schema.Struct({
628 ...ProviderRuntimeEventBase.fields,
629 type: ThreadStartedType,
630 payload: ThreadStartedPayload,
631});
632export type ProviderRuntimeThreadStartedEvent = typeof ProviderRuntimeThreadStartedEvent.Type;
633
634const ProviderRuntimeThreadStateChangedEvent = Schema.Struct({
635 ...ProviderRuntimeEventBase.fields,
636 type: ThreadStateChangedType,
637 payload: ThreadStateChangedPayload,
638});
639export type ProviderRuntimeThreadStateChangedEvent =
640 typeof ProviderRuntimeThreadStateChangedEvent.Type;
641
642const ProviderRuntimeThreadMetadataUpdatedEvent = Schema.Struct({
643 ...ProviderRuntimeEventBase.fields,
644 type: ThreadMetadataUpdatedType,
645 payload: ThreadMetadataUpdatedPayload,
646});
647export type ProviderRuntimeThreadMetadataUpdatedEvent =
648 typeof ProviderRuntimeThreadMetadataUpdatedEvent.Type;
649
650const ProviderRuntimeThreadTokenUsageUpdatedEvent = Schema.Struct({
651 ...ProviderRuntimeEventBase.fields,
652 type: ThreadTokenUsageUpdatedType,
653 payload: ThreadTokenUsageUpdatedPayload,
654});
655export type ProviderRuntimeThreadTokenUsageUpdatedEvent =
656 typeof ProviderRuntimeThreadTokenUsageUpdatedEvent.Type;
657
658const ProviderRuntimeThreadRealtimeStartedEvent = Schema.Struct({
659 ...ProviderRuntimeEventBase.fields,
660 type: ThreadRealtimeStartedType,
661 payload: ThreadRealtimeStartedPayload,
662});
663export type ProviderRuntimeThreadRealtimeStartedEvent =
664 typeof ProviderRuntimeThreadRealtimeStartedEvent.Type;
665
666const ProviderRuntimeThreadRealtimeItemAddedEvent = Schema.Struct({
667 ...ProviderRuntimeEventBase.fields,
668 type: ThreadRealtimeItemAddedType,
669 payload: ThreadRealtimeItemAddedPayload,
670});
671export type ProviderRuntimeThreadRealtimeItemAddedEvent =
672 typeof ProviderRuntimeThreadRealtimeItemAddedEvent.Type;
673
674const ProviderRuntimeThreadRealtimeAudioDeltaEvent = Schema.Struct({
675 ...ProviderRuntimeEventBase.fields,
676 type: ThreadRealtimeAudioDeltaType,
677 payload: ThreadRealtimeAudioDeltaPayload,
678});
679export type ProviderRuntimeThreadRealtimeAudioDeltaEvent =
680 typeof ProviderRuntimeThreadRealtimeAudioDeltaEvent.Type;
681
682const ProviderRuntimeThreadRealtimeErrorEvent = Schema.Struct({
683 ...ProviderRuntimeEventBase.fields,
684 type: ThreadRealtimeErrorType,
685 payload: ThreadRealtimeErrorPayload,
686});
687export type ProviderRuntimeThreadRealtimeErrorEvent =
688 typeof ProviderRuntimeThreadRealtimeErrorEvent.Type;
689
690const ProviderRuntimeThreadRealtimeClosedEvent = Schema.Struct({
691 ...ProviderRuntimeEventBase.fields,
692 type: ThreadRealtimeClosedType,
693 payload: ThreadRealtimeClosedPayload,
694});
695export type ProviderRuntimeThreadRealtimeClosedEvent =
696 typeof ProviderRuntimeThreadRealtimeClosedEvent.Type;
697
698const ProviderRuntimeTurnStartedEvent = Schema.Struct({
699 ...ProviderRuntimeEventBase.fields,
700 type: TurnStartedType,
701 payload: TurnStartedPayload,
702});
703export type ProviderRuntimeTurnStartedEvent = typeof ProviderRuntimeTurnStartedEvent.Type;
704
705const ProviderRuntimeTurnCompletedEvent = Schema.Struct({
706 ...ProviderRuntimeEventBase.fields,
707 type: TurnCompletedType,
708 payload: TurnCompletedPayload,
709});
710export type ProviderRuntimeTurnCompletedEvent = typeof ProviderRuntimeTurnCompletedEvent.Type;
711
712const ProviderRuntimeTurnAbortedEvent = Schema.Struct({
713 ...ProviderRuntimeEventBase.fields,
714 type: TurnAbortedType,
715 payload: TurnAbortedPayload,
716});
717export type ProviderRuntimeTurnAbortedEvent = typeof ProviderRuntimeTurnAbortedEvent.Type;
718
719const ProviderRuntimeTurnPlanUpdatedEvent = Schema.Struct({
720 ...ProviderRuntimeEventBase.fields,
721 type: TurnPlanUpdatedType,
722 payload: TurnPlanUpdatedPayload,
723});
724export type ProviderRuntimeTurnPlanUpdatedEvent = typeof ProviderRuntimeTurnPlanUpdatedEvent.Type;
725
726const ProviderRuntimeTurnProposedDeltaEvent = Schema.Struct({
727 ...ProviderRuntimeEventBase.fields,
728 type: TurnProposedDeltaType,
729 payload: TurnProposedDeltaPayload,
730});
731export type ProviderRuntimeTurnProposedDeltaEvent =
732 typeof ProviderRuntimeTurnProposedDeltaEvent.Type;
733
734const ProviderRuntimeTurnProposedCompletedEvent = Schema.Struct({
735 ...ProviderRuntimeEventBase.fields,
736 type: TurnProposedCompletedType,
737 payload: TurnProposedCompletedPayload,
738});
739export type ProviderRuntimeTurnProposedCompletedEvent =
740 typeof ProviderRuntimeTurnProposedCompletedEvent.Type;
741
742const ProviderRuntimeTurnDiffUpdatedEvent = Schema.Struct({
743 ...ProviderRuntimeEventBase.fields,
744 type: TurnDiffUpdatedType,
745 payload: TurnDiffUpdatedPayload,
746});
747export type ProviderRuntimeTurnDiffUpdatedEvent = typeof ProviderRuntimeTurnDiffUpdatedEvent.Type;
748
749const ProviderRuntimeItemStartedEvent = Schema.Struct({
750 ...ProviderRuntimeEventBase.fields,
751 type: ItemStartedType,
752 payload: ItemLifecyclePayload,
753});
754export type ProviderRuntimeItemStartedEvent = typeof ProviderRuntimeItemStartedEvent.Type;
755
756const ProviderRuntimeItemUpdatedEvent = Schema.Struct({
757 ...ProviderRuntimeEventBase.fields,
758 type: ItemUpdatedType,
759 payload: ItemLifecyclePayload,
760});
761export type ProviderRuntimeItemUpdatedEvent = typeof ProviderRuntimeItemUpdatedEvent.Type;
762
763const ProviderRuntimeItemCompletedEvent = Schema.Struct({
764 ...ProviderRuntimeEventBase.fields,
765 type: ItemCompletedType,
766 payload: ItemLifecyclePayload,
767});
768export type ProviderRuntimeItemCompletedEvent = typeof ProviderRuntimeItemCompletedEvent.Type;
769
770const ProviderRuntimeContentDeltaEvent = Schema.Struct({
771 ...ProviderRuntimeEventBase.fields,
772 type: ContentDeltaType,
773 payload: ContentDeltaPayload,
774});
775export type ProviderRuntimeContentDeltaEvent = typeof ProviderRuntimeContentDeltaEvent.Type;
776
777const ProviderRuntimeRequestOpenedEvent = Schema.Struct({
778 ...ProviderRuntimeEventBase.fields,
779 type: RequestOpenedType,
780 payload: RequestOpenedPayload,
781});
782export type ProviderRuntimeRequestOpenedEvent = typeof ProviderRuntimeRequestOpenedEvent.Type;
783
784const ProviderRuntimeRequestResolvedEvent = Schema.Struct({
785 ...ProviderRuntimeEventBase.fields,
786 type: RequestResolvedType,
787 payload: RequestResolvedPayload,
788});
789export type ProviderRuntimeRequestResolvedEvent = typeof ProviderRuntimeRequestResolvedEvent.Type;
790
791const ProviderRuntimeUserInputRequestedEvent = Schema.Struct({
792 ...ProviderRuntimeEventBase.fields,
793 type: UserInputRequestedType,
794 payload: UserInputRequestedPayload,
795});
796export type ProviderRuntimeUserInputRequestedEvent =
797 typeof ProviderRuntimeUserInputRequestedEvent.Type;
798
799const ProviderRuntimeUserInputResolvedEvent = Schema.Struct({
800 ...ProviderRuntimeEventBase.fields,
801 type: UserInputResolvedType,
802 payload: UserInputResolvedPayload,
803});
804export type ProviderRuntimeUserInputResolvedEvent =
805 typeof ProviderRuntimeUserInputResolvedEvent.Type;
806
807const ProviderRuntimeTaskStartedEvent = Schema.Struct({
808 ...ProviderRuntimeEventBase.fields,
809 type: TaskStartedType,
810 payload: TaskStartedPayload,
811});
812export type ProviderRuntimeTaskStartedEvent = typeof ProviderRuntimeTaskStartedEvent.Type;
813
814const ProviderRuntimeTaskProgressEvent = Schema.Struct({
815 ...ProviderRuntimeEventBase.fields,
816 type: TaskProgressType,
817 payload: TaskProgressPayload,
818});
819export type ProviderRuntimeTaskProgressEvent = typeof ProviderRuntimeTaskProgressEvent.Type;
820
821const ProviderRuntimeTaskCompletedEvent = Schema.Struct({
822 ...ProviderRuntimeEventBase.fields,
823 type: TaskCompletedType,
824 payload: TaskCompletedPayload,
825});
826export type ProviderRuntimeTaskCompletedEvent = typeof ProviderRuntimeTaskCompletedEvent.Type;
827
828const ProviderRuntimeHookStartedEvent = Schema.Struct({
829 ...ProviderRuntimeEventBase.fields,
830 type: HookStartedType,
831 payload: HookStartedPayload,
832});
833export type ProviderRuntimeHookStartedEvent = typeof ProviderRuntimeHookStartedEvent.Type;
834
835const ProviderRuntimeHookProgressEvent = Schema.Struct({
836 ...ProviderRuntimeEventBase.fields,
837 type: HookProgressType,
838 payload: HookProgressPayload,
839});
840export type ProviderRuntimeHookProgressEvent = typeof ProviderRuntimeHookProgressEvent.Type;
841
842const ProviderRuntimeHookCompletedEvent = Schema.Struct({
843 ...ProviderRuntimeEventBase.fields,
844 type: HookCompletedType,
845 payload: HookCompletedPayload,
846});
847export type ProviderRuntimeHookCompletedEvent = typeof ProviderRuntimeHookCompletedEvent.Type;
848
849const ProviderRuntimeToolProgressEvent = Schema.Struct({
850 ...ProviderRuntimeEventBase.fields,
851 type: ToolProgressType,
852 payload: ToolProgressPayload,
853});
854export type ProviderRuntimeToolProgressEvent = typeof ProviderRuntimeToolProgressEvent.Type;
855
856const ProviderRuntimeToolSummaryEvent = Schema.Struct({
857 ...ProviderRuntimeEventBase.fields,
858 type: ToolSummaryType,
859 payload: ToolSummaryPayload,
860});
861export type ProviderRuntimeToolSummaryEvent = typeof ProviderRuntimeToolSummaryEvent.Type;
862
863const ProviderRuntimeAuthStatusEvent = Schema.Struct({
864 ...ProviderRuntimeEventBase.fields,
865 type: AuthStatusType,
866 payload: AuthStatusPayload,
867});
868export type ProviderRuntimeAuthStatusEvent = typeof ProviderRuntimeAuthStatusEvent.Type;
869
870const ProviderRuntimeAccountUpdatedEvent = Schema.Struct({
871 ...ProviderRuntimeEventBase.fields,
872 type: AccountUpdatedType,
873 payload: AccountUpdatedPayload,
874});
875export type ProviderRuntimeAccountUpdatedEvent = typeof ProviderRuntimeAccountUpdatedEvent.Type;
876
877const ProviderRuntimeAccountRateLimitsUpdatedEvent = Schema.Struct({
878 ...ProviderRuntimeEventBase.fields,
879 type: AccountRateLimitsUpdatedType,
880 payload: AccountRateLimitsUpdatedPayload,
881});
882export type ProviderRuntimeAccountRateLimitsUpdatedEvent =
883 typeof ProviderRuntimeAccountRateLimitsUpdatedEvent.Type;
884
885const ProviderRuntimeMcpStatusUpdatedEvent = Schema.Struct({
886 ...ProviderRuntimeEventBase.fields,
887 type: McpStatusUpdatedType,
888 payload: McpStatusUpdatedPayload,
889});
890export type ProviderRuntimeMcpStatusUpdatedEvent = typeof ProviderRuntimeMcpStatusUpdatedEvent.Type;
891
892const ProviderRuntimeMcpOauthCompletedEvent = Schema.Struct({
893 ...ProviderRuntimeEventBase.fields,
894 type: McpOauthCompletedType,
895 payload: McpOauthCompletedPayload,
896});
897export type ProviderRuntimeMcpOauthCompletedEvent =
898 typeof ProviderRuntimeMcpOauthCompletedEvent.Type;
899
900const ProviderRuntimeModelReroutedEvent = Schema.Struct({
901 ...ProviderRuntimeEventBase.fields,
902 type: ModelReroutedType,
903 payload: ModelReroutedPayload,
904});
905export type ProviderRuntimeModelReroutedEvent = typeof ProviderRuntimeModelReroutedEvent.Type;
906
907const ProviderRuntimeConfigWarningEvent = Schema.Struct({
908 ...ProviderRuntimeEventBase.fields,
909 type: ConfigWarningType,
910 payload: ConfigWarningPayload,
911});
912export type ProviderRuntimeConfigWarningEvent = typeof ProviderRuntimeConfigWarningEvent.Type;
913
914const ProviderRuntimeDeprecationNoticeEvent = Schema.Struct({
915 ...ProviderRuntimeEventBase.fields,
916 type: DeprecationNoticeType,
917 payload: DeprecationNoticePayload,
918});
919export type ProviderRuntimeDeprecationNoticeEvent =
920 typeof ProviderRuntimeDeprecationNoticeEvent.Type;
921
922const ProviderRuntimeFilesPersistedEvent = Schema.Struct({
923 ...ProviderRuntimeEventBase.fields,
924 type: FilesPersistedType,
925 payload: FilesPersistedPayload,
926});
927export type ProviderRuntimeFilesPersistedEvent = typeof ProviderRuntimeFilesPersistedEvent.Type;
928
929const ProviderRuntimeWarningEvent = Schema.Struct({
930 ...ProviderRuntimeEventBase.fields,
931 type: RuntimeWarningType,
932 payload: RuntimeWarningPayload,
933});
934export type ProviderRuntimeWarningEvent = typeof ProviderRuntimeWarningEvent.Type;
935
936const ProviderRuntimeErrorEvent = Schema.Struct({
937 ...ProviderRuntimeEventBase.fields,
938 type: RuntimeErrorType,
939 payload: RuntimeErrorPayload,
940});
941export type ProviderRuntimeErrorEvent = typeof ProviderRuntimeErrorEvent.Type;
942
943export const ProviderRuntimeEventV2 = Schema.Union([
944 ProviderRuntimeSessionStartedEvent,
945 ProviderRuntimeSessionConfiguredEvent,
946 ProviderRuntimeSessionStateChangedEvent,
947 ProviderRuntimeSessionExitedEvent,
948 ProviderRuntimeThreadStartedEvent,
949 ProviderRuntimeThreadStateChangedEvent,
950 ProviderRuntimeThreadMetadataUpdatedEvent,
951 ProviderRuntimeThreadTokenUsageUpdatedEvent,
952 ProviderRuntimeThreadRealtimeStartedEvent,
953 ProviderRuntimeThreadRealtimeItemAddedEvent,
954 ProviderRuntimeThreadRealtimeAudioDeltaEvent,
955 ProviderRuntimeThreadRealtimeErrorEvent,
956 ProviderRuntimeThreadRealtimeClosedEvent,
957 ProviderRuntimeTurnStartedEvent,
958 ProviderRuntimeTurnCompletedEvent,
959 ProviderRuntimeTurnAbortedEvent,
960 ProviderRuntimeTurnPlanUpdatedEvent,
961 ProviderRuntimeTurnProposedDeltaEvent,
962 ProviderRuntimeTurnProposedCompletedEvent,
963 ProviderRuntimeTurnDiffUpdatedEvent,
964 ProviderRuntimeItemStartedEvent,
965 ProviderRuntimeItemUpdatedEvent,
966 ProviderRuntimeItemCompletedEvent,
967 ProviderRuntimeContentDeltaEvent,
968 ProviderRuntimeRequestOpenedEvent,
969 ProviderRuntimeRequestResolvedEvent,
970 ProviderRuntimeUserInputRequestedEvent,
971 ProviderRuntimeUserInputResolvedEvent,
972 ProviderRuntimeTaskStartedEvent,
973 ProviderRuntimeTaskProgressEvent,
974 ProviderRuntimeTaskCompletedEvent,
975 ProviderRuntimeHookStartedEvent,
976 ProviderRuntimeHookProgressEvent,
977 ProviderRuntimeHookCompletedEvent,
978 ProviderRuntimeToolProgressEvent,
979 ProviderRuntimeToolSummaryEvent,
980 ProviderRuntimeAuthStatusEvent,
981 ProviderRuntimeAccountUpdatedEvent,
982 ProviderRuntimeAccountRateLimitsUpdatedEvent,
983 ProviderRuntimeMcpStatusUpdatedEvent,
984 ProviderRuntimeMcpOauthCompletedEvent,
985 ProviderRuntimeModelReroutedEvent,
986 ProviderRuntimeConfigWarningEvent,
987 ProviderRuntimeDeprecationNoticeEvent,
988 ProviderRuntimeFilesPersistedEvent,
989 ProviderRuntimeWarningEvent,
990 ProviderRuntimeErrorEvent,
991]);
992export type ProviderRuntimeEventV2 = typeof ProviderRuntimeEventV2.Type;
993
994export const ProviderRuntimeEvent = ProviderRuntimeEventV2;
995export type ProviderRuntimeEvent = ProviderRuntimeEventV2;
996
997// Compatibility aliases for call sites still importing legacy names.
998const ProviderRuntimeMessageDeltaEvent = ProviderRuntimeContentDeltaEvent;
999export type ProviderRuntimeMessageDeltaEvent = ProviderRuntimeContentDeltaEvent;
1000const ProviderRuntimeMessageCompletedEvent = ProviderRuntimeItemCompletedEvent;
1001export type ProviderRuntimeMessageCompletedEvent = ProviderRuntimeItemCompletedEvent;
1002const ProviderRuntimeToolStartedEvent = ProviderRuntimeItemStartedEvent;
1003export type ProviderRuntimeToolStartedEvent = ProviderRuntimeItemStartedEvent;
1004const ProviderRuntimeToolCompletedEvent = ProviderRuntimeItemCompletedEvent;
1005export type ProviderRuntimeToolCompletedEvent = ProviderRuntimeItemCompletedEvent;
1006const ProviderRuntimeApprovalRequestedEvent = ProviderRuntimeRequestOpenedEvent;
1007export type ProviderRuntimeApprovalRequestedEvent = ProviderRuntimeRequestOpenedEvent;
1008const ProviderRuntimeApprovalResolvedEvent = ProviderRuntimeRequestResolvedEvent;
1009export type ProviderRuntimeApprovalResolvedEvent = ProviderRuntimeRequestResolvedEvent;
1010
1011// Legacy helper aliases retained for adapters/tests.
1012const ProviderRuntimeToolKind = Schema.Literals(["command", "file-read", "file-change", "other"]);
1013export type ProviderRuntimeToolKind = typeof ProviderRuntimeToolKind.Type;
1014
1015export const ProviderRuntimeTurnStatus = RuntimeTurnState;
1016export type ProviderRuntimeTurnStatus = RuntimeTurnState;