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