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