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

providerRuntime.ts

1,023 lines36.9 KB

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