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