Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

providerRuntime.ts

978 lines34.8 KB

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