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

providerRuntime.ts

1,041 lines37.6 KB

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);
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 ToolDeniedType = Schema.Literal("tool.denied");
245const RuntimeWarningType = Schema.Literal("runtime.warning");
246const RuntimeErrorType = Schema.Literal("runtime.error");
247​
248const ProviderRuntimeEventBase = Schema.Struct({
249 eventId: EventId,
250 provider: ProviderDriverKind,
251 // Optional during the driver/instance migration. See providerInstance.ts
252 // for the routing-key-vs-driver-id distinction. Once every emitter
253 // populates it (post-slice-4), routing flips to instance-id-only.
254 providerInstanceId: Schema.optional(ProviderInstanceId),
255 threadId: ThreadId,
256 createdAt: IsoDateTime,
257 turnId: Schema.optional(TurnId),
258 itemId: Schema.optional(RuntimeItemId),
259 requestId: Schema.optional(RuntimeRequestId),
260 providerRefs: Schema.optional(ProviderRefs),
261 raw: Schema.optional(RuntimeEventRaw),
262});
263export type ProviderRuntimeEventBase = typeof ProviderRuntimeEventBase.Type;
264​
265const SessionStartedPayload = Schema.Struct({
266 message: Schema.optional(TrimmedNonEmptyStringSchema),
267 resume: Schema.optional(Schema.Unknown),
268});
269export type SessionStartedPayload = typeof SessionStartedPayload.Type;
270​
271const SessionConfiguredPayload = Schema.Struct({
272 config: UnknownRecordSchema,
273});
274export type SessionConfiguredPayload = typeof SessionConfiguredPayload.Type;
275​
276const SessionStateChangedPayload = Schema.Struct({
277 state: RuntimeSessionState,
278 reason: Schema.optional(TrimmedNonEmptyStringSchema),
279 detail: Schema.optional(Schema.Unknown),
280});
281export type SessionStateChangedPayload = typeof SessionStateChangedPayload.Type;
282​
283const SessionExitedPayload = Schema.Struct({
284 reason: Schema.optional(TrimmedNonEmptyStringSchema),
285 recoverable: Schema.optional(Schema.Boolean),
286 exitKind: Schema.optional(RuntimeSessionExitKind),
287});
288export type SessionExitedPayload = typeof SessionExitedPayload.Type;
289​
290const ThreadStartedPayload = Schema.Struct({
291 providerThreadId: Schema.optional(TrimmedNonEmptyStringSchema),
292});
293export type ThreadStartedPayload = typeof ThreadStartedPayload.Type;
294​
295const ThreadStateChangedPayload = Schema.Struct({
296 state: RuntimeThreadState,
297 detail: Schema.optional(Schema.Unknown),
298});
299export type ThreadStateChangedPayload = typeof ThreadStateChangedPayload.Type;
300​
301const ThreadMetadataUpdatedPayload = Schema.Struct({
302 name: Schema.optional(TrimmedNonEmptyStringSchema),
303 metadata: Schema.optional(UnknownRecordSchema),
304});
305export type ThreadMetadataUpdatedPayload = typeof ThreadMetadataUpdatedPayload.Type;
306​
307export const ThreadTokenUsageSnapshot = Schema.Struct({
308 usedTokens: NonNegativeInt,
309 totalProcessedTokens: Schema.optional(NonNegativeInt),
310 maxTokens: Schema.optional(PositiveInt),
311 inputTokens: Schema.optional(NonNegativeInt),
312 cachedInputTokens: Schema.optional(NonNegativeInt),
313 outputTokens: Schema.optional(NonNegativeInt),
314 reasoningOutputTokens: Schema.optional(NonNegativeInt),
315 lastUsedTokens: Schema.optional(NonNegativeInt),
316 lastInputTokens: Schema.optional(NonNegativeInt),
317 lastCachedInputTokens: Schema.optional(NonNegativeInt),
318 lastOutputTokens: Schema.optional(NonNegativeInt),
319 lastReasoningOutputTokens: Schema.optional(NonNegativeInt),
320 toolUses: Schema.optional(NonNegativeInt),
321 durationMs: Schema.optional(NonNegativeInt),
322 compactsAutomatically: Schema.optional(Schema.Boolean),
323});
324export type ThreadTokenUsageSnapshot = typeof ThreadTokenUsageSnapshot.Type;
325​
326const ThreadTokenUsageUpdatedPayload = Schema.Struct({
327 usage: ThreadTokenUsageSnapshot,
328});
329export type ThreadTokenUsageUpdatedPayload = typeof ThreadTokenUsageUpdatedPayload.Type;
330​
331const ThreadRealtimeStartedPayload = Schema.Struct({
332 realtimeSessionId: Schema.optional(TrimmedNonEmptyStringSchema),
333});
334export type ThreadRealtimeStartedPayload = typeof ThreadRealtimeStartedPayload.Type;
335​
336const ThreadRealtimeItemAddedPayload = Schema.Struct({
337 item: Schema.Unknown,
338});
339export type ThreadRealtimeItemAddedPayload = typeof ThreadRealtimeItemAddedPayload.Type;
340​
341const ThreadRealtimeAudioDeltaPayload = Schema.Struct({
342 audio: Schema.Unknown,
343});
344export type ThreadRealtimeAudioDeltaPayload = typeof ThreadRealtimeAudioDeltaPayload.Type;
345​
346const ThreadRealtimeErrorPayload = Schema.Struct({
347 message: TrimmedNonEmptyStringSchema,
348});
349export type ThreadRealtimeErrorPayload = typeof ThreadRealtimeErrorPayload.Type;
350​
351const ThreadRealtimeClosedPayload = Schema.Struct({
352 reason: Schema.optional(TrimmedNonEmptyStringSchema),
353});
354export type ThreadRealtimeClosedPayload = typeof ThreadRealtimeClosedPayload.Type;
355​
356const TurnStartedPayload = Schema.Struct({
357 model: Schema.optional(TrimmedNonEmptyStringSchema),
358 effort: Schema.optional(TrimmedNonEmptyStringSchema),
359});
360export type TurnStartedPayload = typeof TurnStartedPayload.Type;
361​
362const TurnCompletedPayload = Schema.Struct({
363 state: RuntimeTurnState,
364 stopReason: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
365 usage: Schema.optional(Schema.Unknown),
366 modelUsage: Schema.optional(UnknownRecordSchema),
367 totalCostUsd: Schema.optional(Schema.Number),
368 errorMessage: Schema.optional(TrimmedNonEmptyStringSchema),
369});
370export type TurnCompletedPayload = typeof TurnCompletedPayload.Type;
371​
372const TurnAbortedPayload = Schema.Struct({
373 reason: TrimmedNonEmptyStringSchema,
374});
375export type TurnAbortedPayload = typeof TurnAbortedPayload.Type;
376​
377const RuntimePlanStep = Schema.Struct({
378 step: TrimmedNonEmptyStringSchema,
379 status: RuntimePlanStepStatus,
380});
381export type RuntimePlanStep = typeof RuntimePlanStep.Type;
382​
383const TurnPlanUpdatedPayload = Schema.Struct({
384 explanation: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
385 plan: Schema.Array(RuntimePlanStep),
386});
387export type TurnPlanUpdatedPayload = typeof TurnPlanUpdatedPayload.Type;
388​
389const TurnProposedDeltaPayload = Schema.Struct({
390 delta: Schema.String,
391});
392export type TurnProposedDeltaPayload = typeof TurnProposedDeltaPayload.Type;
393​
394const TurnProposedCompletedPayload = Schema.Struct({
395 planMarkdown: TrimmedNonEmptyStringSchema,
396});
397export type TurnProposedCompletedPayload = typeof TurnProposedCompletedPayload.Type;
398​
399const TurnDiffUpdatedPayload = Schema.Struct({
400 unifiedDiff: Schema.String,
401});
402export type TurnDiffUpdatedPayload = typeof TurnDiffUpdatedPayload.Type;
403​
404export const ItemLifecyclePayload = Schema.Struct({
405 itemType: CanonicalItemType,
406 status: Schema.optional(RuntimeItemStatus),
407 title: Schema.optional(TrimmedNonEmptyStringSchema),
408 detail: Schema.optional(TrimmedNonEmptyStringSchema),
409 data: Schema.optional(Schema.Unknown),
410});
411export type ItemLifecyclePayload = typeof ItemLifecyclePayload.Type;
412​
413const ContentDeltaPayload = Schema.Struct({
414 streamKind: RuntimeContentStreamKind,
415 delta: Schema.String,
416 contentIndex: Schema.optional(Schema.Int),
417 summaryIndex: Schema.optional(Schema.Int),
418});
419export type ContentDeltaPayload = typeof ContentDeltaPayload.Type;
420​
421const RequestOpenedPayload = Schema.Struct({
422 requestType: CanonicalRequestType,
423 detail: Schema.optional(TrimmedNonEmptyStringSchema),
424 args: Schema.optional(Schema.Unknown),
425});
426export type RequestOpenedPayload = typeof RequestOpenedPayload.Type;
427​
428const RequestResolvedPayload = Schema.Struct({
429 requestType: CanonicalRequestType,
430 decision: Schema.optional(TrimmedNonEmptyStringSchema),
431 resolution: Schema.optional(Schema.Unknown),
432});
433export type RequestResolvedPayload = typeof RequestResolvedPayload.Type;
434​
435const UserInputQuestionOption = Schema.Struct({
436 label: TrimmedNonEmptyStringSchema,
437 description: TrimmedNonEmptyStringSchema,
438});
439export type UserInputQuestionOption = typeof UserInputQuestionOption.Type;
440​
441export const UserInputQuestion = Schema.Struct({
442 id: TrimmedNonEmptyStringSchema,
443 header: TrimmedNonEmptyStringSchema,
444 question: TrimmedNonEmptyStringSchema,
445 options: Schema.Array(UserInputQuestionOption),
446 multiSelect: Schema.optional(Schema.Boolean).pipe(
447 Schema.withConstructorDefault(Effect.succeed(false)),
448 ),
449});
450export type UserInputQuestion = typeof UserInputQuestion.Type;
451​
452const UserInputRequestedPayload = Schema.Struct({
453 questions: Schema.Array(UserInputQuestion),
454});
455export type UserInputRequestedPayload = typeof UserInputRequestedPayload.Type;
456​
457const UserInputResolvedPayload = Schema.Struct({
458 answers: UnknownRecordSchema,
459});
460export type UserInputResolvedPayload = typeof UserInputResolvedPayload.Type;
461​
462const TaskStartedPayload = Schema.Struct({
463 taskId: RuntimeTaskId,
464 description: Schema.optional(TrimmedNonEmptyStringSchema),
465 taskType: Schema.optional(TrimmedNonEmptyStringSchema),
466});
467export type TaskStartedPayload = typeof TaskStartedPayload.Type;
468​
469const TaskProgressPayload = Schema.Struct({
470 taskId: RuntimeTaskId,
471 description: TrimmedNonEmptyStringSchema,
472 summary: Schema.optional(TrimmedNonEmptyStringSchema),
473 usage: Schema.optional(Schema.Unknown),
474 lastToolName: Schema.optional(TrimmedNonEmptyStringSchema),
475});
476export type TaskProgressPayload = typeof TaskProgressPayload.Type;
477​
478const TaskCompletedPayload = Schema.Struct({
479 taskId: RuntimeTaskId,
480 status: Schema.Literals(["completed", "failed", "stopped"]),
481 summary: Schema.optional(TrimmedNonEmptyStringSchema),
482 usage: Schema.optional(Schema.Unknown),
483});
484export type TaskCompletedPayload = typeof TaskCompletedPayload.Type;
485​
486const HookStartedPayload = Schema.Struct({
487 hookId: TrimmedNonEmptyStringSchema,
488 hookName: TrimmedNonEmptyStringSchema,
489 hookEvent: TrimmedNonEmptyStringSchema,
490});
491export type HookStartedPayload = typeof HookStartedPayload.Type;
492​
493const HookProgressPayload = Schema.Struct({
494 hookId: TrimmedNonEmptyStringSchema,
495 output: Schema.optional(Schema.String),
496 stdout: Schema.optional(Schema.String),
497 stderr: Schema.optional(Schema.String),
498});
499export type HookProgressPayload = typeof HookProgressPayload.Type;
500​
501const HookCompletedPayload = Schema.Struct({
502 hookId: TrimmedNonEmptyStringSchema,
503 outcome: Schema.Literals(["success", "error", "cancelled"]),
504 output: Schema.optional(Schema.String),
505 stdout: Schema.optional(Schema.String),
506 stderr: Schema.optional(Schema.String),
507 exitCode: Schema.optional(Schema.Int),
508});
509export type HookCompletedPayload = typeof HookCompletedPayload.Type;
510​
511const ToolProgressPayload = Schema.Struct({
512 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
513 toolName: Schema.optional(TrimmedNonEmptyStringSchema),
514 summary: Schema.optional(TrimmedNonEmptyStringSchema),
515 elapsedSeconds: Schema.optional(Schema.Number),
516});
517export type ToolProgressPayload = typeof ToolProgressPayload.Type;
518​
519const ToolSummaryPayload = Schema.Struct({
520 summary: TrimmedNonEmptyStringSchema,
521 precedingToolUseIds: Schema.optional(Schema.Array(TrimmedNonEmptyStringSchema)),
522});
523export type ToolSummaryPayload = typeof ToolSummaryPayload.Type;
524​
525const AuthStatusPayload = Schema.Struct({
526 isAuthenticating: Schema.optional(Schema.Boolean),
527 output: Schema.optional(Schema.Array(Schema.String)),
528 error: Schema.optional(TrimmedNonEmptyStringSchema),
529});
530export type AuthStatusPayload = typeof AuthStatusPayload.Type;
531​
532const AccountUpdatedPayload = Schema.Struct({
533 account: Schema.Unknown,
534});
535export type AccountUpdatedPayload = typeof AccountUpdatedPayload.Type;
536​
537const AccountRateLimitsUpdatedPayload = Schema.Struct({
538 rateLimits: Schema.Unknown,
539});
540export type AccountRateLimitsUpdatedPayload = typeof AccountRateLimitsUpdatedPayload.Type;
541​
542const McpStatusUpdatedPayload = Schema.Struct({
543 status: Schema.Unknown,
544});
545export type McpStatusUpdatedPayload = typeof McpStatusUpdatedPayload.Type;
546​
547const McpOauthCompletedPayload = Schema.Struct({
548 success: Schema.Boolean,
549 name: Schema.optional(TrimmedNonEmptyStringSchema),
550 error: Schema.optional(TrimmedNonEmptyStringSchema),
551});
552export type McpOauthCompletedPayload = typeof McpOauthCompletedPayload.Type;
553​
554const ModelReroutedPayload = Schema.Struct({
555 fromModel: TrimmedNonEmptyStringSchema,
556 toModel: TrimmedNonEmptyStringSchema,
557 reason: TrimmedNonEmptyStringSchema,
558});
559export type ModelReroutedPayload = typeof ModelReroutedPayload.Type;
560​
561const ConfigWarningPayload = Schema.Struct({
562 summary: TrimmedNonEmptyStringSchema,
563 details: Schema.optional(TrimmedNonEmptyStringSchema),
564 path: Schema.optional(TrimmedNonEmptyStringSchema),
565 range: Schema.optional(Schema.Unknown),
566});
567export type ConfigWarningPayload = typeof ConfigWarningPayload.Type;
568​
569const DeprecationNoticePayload = Schema.Struct({
570 summary: TrimmedNonEmptyStringSchema,
571 details: Schema.optional(TrimmedNonEmptyStringSchema),
572});
573export type DeprecationNoticePayload = typeof DeprecationNoticePayload.Type;
574​
575const FilesPersistedPayload = Schema.Struct({
576 files: Schema.Array(
577 Schema.Struct({
578 filename: TrimmedNonEmptyStringSchema,
579 fileId: TrimmedNonEmptyStringSchema,
580 }),
581 ),
582 failed: Schema.optional(
583 Schema.Array(
584 Schema.Struct({
585 filename: TrimmedNonEmptyStringSchema,
586 error: TrimmedNonEmptyStringSchema,
587 }),
588 ),
589 ),
590});
591export type FilesPersistedPayload = typeof FilesPersistedPayload.Type;
592​
593const ToolDeniedPayload = Schema.Struct({
594 toolName: TrimmedNonEmptyStringSchema,
595 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
596 reason: Schema.optional(TrimmedNonEmptyStringSchema),
597 agentId: Schema.optional(TrimmedNonEmptyStringSchema),
598});
599export type ToolDeniedPayload = typeof ToolDeniedPayload.Type;
600​
601const RuntimeWarningPayload = Schema.Struct({
602 message: TrimmedNonEmptyStringSchema,
603 detail: Schema.optional(Schema.Unknown),
604});
605export type RuntimeWarningPayload = typeof RuntimeWarningPayload.Type;
606​
607const RuntimeErrorPayload = Schema.Struct({
608 message: TrimmedNonEmptyStringSchema,
609 class: Schema.optional(RuntimeErrorClass),
610 detail: Schema.optional(Schema.Unknown),
611});
612export type RuntimeErrorPayload = typeof RuntimeErrorPayload.Type;
613​
614const ProviderRuntimeSessionStartedEvent = Schema.Struct({
615 ...ProviderRuntimeEventBase.fields,
616 type: SessionStartedType,
617 payload: SessionStartedPayload,
618});
619export type ProviderRuntimeSessionStartedEvent = typeof ProviderRuntimeSessionStartedEvent.Type;
620​
621const ProviderRuntimeSessionConfiguredEvent = Schema.Struct({
622 ...ProviderRuntimeEventBase.fields,
623 type: SessionConfiguredType,
624 payload: SessionConfiguredPayload,
625});
626export type ProviderRuntimeSessionConfiguredEvent =
627 typeof ProviderRuntimeSessionConfiguredEvent.Type;
628​
629const ProviderRuntimeSessionStateChangedEvent = Schema.Struct({
630 ...ProviderRuntimeEventBase.fields,
631 type: SessionStateChangedType,
632 payload: SessionStateChangedPayload,
633});
634export type ProviderRuntimeSessionStateChangedEvent =
635 typeof ProviderRuntimeSessionStateChangedEvent.Type;
636​
637const ProviderRuntimeSessionExitedEvent = Schema.Struct({
638 ...ProviderRuntimeEventBase.fields,
639 type: SessionExitedType,
640 payload: SessionExitedPayload,
641});
642export type ProviderRuntimeSessionExitedEvent = typeof ProviderRuntimeSessionExitedEvent.Type;
643​
644const ProviderRuntimeThreadStartedEvent = Schema.Struct({
645 ...ProviderRuntimeEventBase.fields,
646 type: ThreadStartedType,
647 payload: ThreadStartedPayload,
648});
649export type ProviderRuntimeThreadStartedEvent = typeof ProviderRuntimeThreadStartedEvent.Type;
650​
651const ProviderRuntimeThreadStateChangedEvent = Schema.Struct({
652 ...ProviderRuntimeEventBase.fields,
653 type: ThreadStateChangedType,
654 payload: ThreadStateChangedPayload,
655});
656export type ProviderRuntimeThreadStateChangedEvent =
657 typeof ProviderRuntimeThreadStateChangedEvent.Type;
658​
659const ProviderRuntimeThreadMetadataUpdatedEvent = Schema.Struct({
660 ...ProviderRuntimeEventBase.fields,
661 type: ThreadMetadataUpdatedType,
662 payload: ThreadMetadataUpdatedPayload,
663});
664export type ProviderRuntimeThreadMetadataUpdatedEvent =
665 typeof ProviderRuntimeThreadMetadataUpdatedEvent.Type;
666​
667const ProviderRuntimeThreadTokenUsageUpdatedEvent = Schema.Struct({
668 ...ProviderRuntimeEventBase.fields,
669 type: ThreadTokenUsageUpdatedType,
670 payload: ThreadTokenUsageUpdatedPayload,
671});
672export type ProviderRuntimeThreadTokenUsageUpdatedEvent =
673 typeof ProviderRuntimeThreadTokenUsageUpdatedEvent.Type;
674​
675const ProviderRuntimeThreadRealtimeStartedEvent = Schema.Struct({
676 ...ProviderRuntimeEventBase.fields,
677 type: ThreadRealtimeStartedType,
678 payload: ThreadRealtimeStartedPayload,
679});
680export type ProviderRuntimeThreadRealtimeStartedEvent =
681 typeof ProviderRuntimeThreadRealtimeStartedEvent.Type;
682​
683const ProviderRuntimeThreadRealtimeItemAddedEvent = Schema.Struct({
684 ...ProviderRuntimeEventBase.fields,
685 type: ThreadRealtimeItemAddedType,
686 payload: ThreadRealtimeItemAddedPayload,
687});
688export type ProviderRuntimeThreadRealtimeItemAddedEvent =
689 typeof ProviderRuntimeThreadRealtimeItemAddedEvent.Type;
690​
691const ProviderRuntimeThreadRealtimeAudioDeltaEvent = Schema.Struct({
692 ...ProviderRuntimeEventBase.fields,
693 type: ThreadRealtimeAudioDeltaType,
694 payload: ThreadRealtimeAudioDeltaPayload,
695});
696export type ProviderRuntimeThreadRealtimeAudioDeltaEvent =
697 typeof ProviderRuntimeThreadRealtimeAudioDeltaEvent.Type;
698​
699const ProviderRuntimeThreadRealtimeErrorEvent = Schema.Struct({
700 ...ProviderRuntimeEventBase.fields,
701 type: ThreadRealtimeErrorType,
702 payload: ThreadRealtimeErrorPayload,
703});
704export type ProviderRuntimeThreadRealtimeErrorEvent =
705 typeof ProviderRuntimeThreadRealtimeErrorEvent.Type;
706​
707const ProviderRuntimeThreadRealtimeClosedEvent = Schema.Struct({
708 ...ProviderRuntimeEventBase.fields,
709 type: ThreadRealtimeClosedType,
710 payload: ThreadRealtimeClosedPayload,
711});
712export type ProviderRuntimeThreadRealtimeClosedEvent =
713 typeof ProviderRuntimeThreadRealtimeClosedEvent.Type;
714​
715const ProviderRuntimeTurnStartedEvent = Schema.Struct({
716 ...ProviderRuntimeEventBase.fields,
717 type: TurnStartedType,
718 payload: TurnStartedPayload,
719});
720export type ProviderRuntimeTurnStartedEvent = typeof ProviderRuntimeTurnStartedEvent.Type;
721​
722const ProviderRuntimeTurnCompletedEvent = Schema.Struct({
723 ...ProviderRuntimeEventBase.fields,
724 type: TurnCompletedType,
725 payload: TurnCompletedPayload,
726});
727export type ProviderRuntimeTurnCompletedEvent = typeof ProviderRuntimeTurnCompletedEvent.Type;
728​
729const ProviderRuntimeTurnAbortedEvent = Schema.Struct({
730 ...ProviderRuntimeEventBase.fields,
731 type: TurnAbortedType,
732 payload: TurnAbortedPayload,
733});
734export type ProviderRuntimeTurnAbortedEvent = typeof ProviderRuntimeTurnAbortedEvent.Type;
735​
736const ProviderRuntimeTurnPlanUpdatedEvent = Schema.Struct({
737 ...ProviderRuntimeEventBase.fields,
738 type: TurnPlanUpdatedType,
739 payload: TurnPlanUpdatedPayload,
740});
741export type ProviderRuntimeTurnPlanUpdatedEvent = typeof ProviderRuntimeTurnPlanUpdatedEvent.Type;
742​
743const ProviderRuntimeTurnProposedDeltaEvent = Schema.Struct({
744 ...ProviderRuntimeEventBase.fields,
745 type: TurnProposedDeltaType,
746 payload: TurnProposedDeltaPayload,
747});
748export type ProviderRuntimeTurnProposedDeltaEvent =
749 typeof ProviderRuntimeTurnProposedDeltaEvent.Type;
750​
751const ProviderRuntimeTurnProposedCompletedEvent = Schema.Struct({
752 ...ProviderRuntimeEventBase.fields,
753 type: TurnProposedCompletedType,
754 payload: TurnProposedCompletedPayload,
755});
756export type ProviderRuntimeTurnProposedCompletedEvent =
757 typeof ProviderRuntimeTurnProposedCompletedEvent.Type;
758​
759const ProviderRuntimeTurnDiffUpdatedEvent = Schema.Struct({
760 ...ProviderRuntimeEventBase.fields,
761 type: TurnDiffUpdatedType,
762 payload: TurnDiffUpdatedPayload,
763});
764export type ProviderRuntimeTurnDiffUpdatedEvent = typeof ProviderRuntimeTurnDiffUpdatedEvent.Type;
765​
766const ProviderRuntimeItemStartedEvent = Schema.Struct({
767 ...ProviderRuntimeEventBase.fields,
768 type: ItemStartedType,
769 payload: ItemLifecyclePayload,
770});
771export type ProviderRuntimeItemStartedEvent = typeof ProviderRuntimeItemStartedEvent.Type;
772​
773const ProviderRuntimeItemUpdatedEvent = Schema.Struct({
774 ...ProviderRuntimeEventBase.fields,
775 type: ItemUpdatedType,
776 payload: ItemLifecyclePayload,
777});
778export type ProviderRuntimeItemUpdatedEvent = typeof ProviderRuntimeItemUpdatedEvent.Type;
779​
780const ProviderRuntimeItemCompletedEvent = Schema.Struct({
781 ...ProviderRuntimeEventBase.fields,
782 type: ItemCompletedType,
783 payload: ItemLifecyclePayload,
784});
785export type ProviderRuntimeItemCompletedEvent = typeof ProviderRuntimeItemCompletedEvent.Type;
786​
787const ProviderRuntimeContentDeltaEvent = Schema.Struct({
788 ...ProviderRuntimeEventBase.fields,
789 type: ContentDeltaType,
790 payload: ContentDeltaPayload,
791});
792export type ProviderRuntimeContentDeltaEvent = typeof ProviderRuntimeContentDeltaEvent.Type;
793​
794const ProviderRuntimeRequestOpenedEvent = Schema.Struct({
795 ...ProviderRuntimeEventBase.fields,
796 type: RequestOpenedType,
797 payload: RequestOpenedPayload,
798});
799export type ProviderRuntimeRequestOpenedEvent = typeof ProviderRuntimeRequestOpenedEvent.Type;
800​
801const ProviderRuntimeRequestResolvedEvent = Schema.Struct({
802 ...ProviderRuntimeEventBase.fields,
803 type: RequestResolvedType,
804 payload: RequestResolvedPayload,
805});
806export type ProviderRuntimeRequestResolvedEvent = typeof ProviderRuntimeRequestResolvedEvent.Type;
807​
808const ProviderRuntimeUserInputRequestedEvent = Schema.Struct({
809 ...ProviderRuntimeEventBase.fields,
810 type: UserInputRequestedType,
811 payload: UserInputRequestedPayload,
812});
813export type ProviderRuntimeUserInputRequestedEvent =
814 typeof ProviderRuntimeUserInputRequestedEvent.Type;
815​
816const ProviderRuntimeUserInputResolvedEvent = Schema.Struct({
817 ...ProviderRuntimeEventBase.fields,
818 type: UserInputResolvedType,
819 payload: UserInputResolvedPayload,
820});
821export type ProviderRuntimeUserInputResolvedEvent =
822 typeof ProviderRuntimeUserInputResolvedEvent.Type;
823​
824const ProviderRuntimeTaskStartedEvent = Schema.Struct({
825 ...ProviderRuntimeEventBase.fields,
826 type: TaskStartedType,
827 payload: TaskStartedPayload,
828});
829export type ProviderRuntimeTaskStartedEvent = typeof ProviderRuntimeTaskStartedEvent.Type;
830​
831const ProviderRuntimeTaskProgressEvent = Schema.Struct({
832 ...ProviderRuntimeEventBase.fields,
833 type: TaskProgressType,
834 payload: TaskProgressPayload,
835});
836export type ProviderRuntimeTaskProgressEvent = typeof ProviderRuntimeTaskProgressEvent.Type;
837​
838const ProviderRuntimeTaskCompletedEvent = Schema.Struct({
839 ...ProviderRuntimeEventBase.fields,
840 type: TaskCompletedType,
841 payload: TaskCompletedPayload,
842});
843export type ProviderRuntimeTaskCompletedEvent = typeof ProviderRuntimeTaskCompletedEvent.Type;
844​
845const ProviderRuntimeHookStartedEvent = Schema.Struct({
846 ...ProviderRuntimeEventBase.fields,
847 type: HookStartedType,
848 payload: HookStartedPayload,
849});
850export type ProviderRuntimeHookStartedEvent = typeof ProviderRuntimeHookStartedEvent.Type;
851​
852const ProviderRuntimeHookProgressEvent = Schema.Struct({
853 ...ProviderRuntimeEventBase.fields,
854 type: HookProgressType,
855 payload: HookProgressPayload,
856});
857export type ProviderRuntimeHookProgressEvent = typeof ProviderRuntimeHookProgressEvent.Type;
858​
859const ProviderRuntimeHookCompletedEvent = Schema.Struct({
860 ...ProviderRuntimeEventBase.fields,
861 type: HookCompletedType,
862 payload: HookCompletedPayload,
863});
864export type ProviderRuntimeHookCompletedEvent = typeof ProviderRuntimeHookCompletedEvent.Type;
865​
866const ProviderRuntimeToolProgressEvent = Schema.Struct({
867 ...ProviderRuntimeEventBase.fields,
868 type: ToolProgressType,
869 payload: ToolProgressPayload,
870});
871export type ProviderRuntimeToolProgressEvent = typeof ProviderRuntimeToolProgressEvent.Type;
872​
873const ProviderRuntimeToolSummaryEvent = Schema.Struct({
874 ...ProviderRuntimeEventBase.fields,
875 type: ToolSummaryType,
876 payload: ToolSummaryPayload,
877});
878export type ProviderRuntimeToolSummaryEvent = typeof ProviderRuntimeToolSummaryEvent.Type;
879​
880const ProviderRuntimeAuthStatusEvent = Schema.Struct({
881 ...ProviderRuntimeEventBase.fields,
882 type: AuthStatusType,
883 payload: AuthStatusPayload,
884});
885export type ProviderRuntimeAuthStatusEvent = typeof ProviderRuntimeAuthStatusEvent.Type;
886​
887const ProviderRuntimeAccountUpdatedEvent = Schema.Struct({
888 ...ProviderRuntimeEventBase.fields,
889 type: AccountUpdatedType,
890 payload: AccountUpdatedPayload,
891});
892export type ProviderRuntimeAccountUpdatedEvent = typeof ProviderRuntimeAccountUpdatedEvent.Type;
893​
894const ProviderRuntimeAccountRateLimitsUpdatedEvent = Schema.Struct({
895 ...ProviderRuntimeEventBase.fields,
896 type: AccountRateLimitsUpdatedType,
897 payload: AccountRateLimitsUpdatedPayload,
898});
899export type ProviderRuntimeAccountRateLimitsUpdatedEvent =
900 typeof ProviderRuntimeAccountRateLimitsUpdatedEvent.Type;
901​
902const ProviderRuntimeMcpStatusUpdatedEvent = Schema.Struct({
903 ...ProviderRuntimeEventBase.fields,
904 type: McpStatusUpdatedType,
905 payload: McpStatusUpdatedPayload,
906});
907export type ProviderRuntimeMcpStatusUpdatedEvent = typeof ProviderRuntimeMcpStatusUpdatedEvent.Type;
908​
909const ProviderRuntimeMcpOauthCompletedEvent = Schema.Struct({
910 ...ProviderRuntimeEventBase.fields,
911 type: McpOauthCompletedType,
912 payload: McpOauthCompletedPayload,
913});
914export type ProviderRuntimeMcpOauthCompletedEvent =
915 typeof ProviderRuntimeMcpOauthCompletedEvent.Type;
916​
917const ProviderRuntimeModelReroutedEvent = Schema.Struct({
918 ...ProviderRuntimeEventBase.fields,
919 type: ModelReroutedType,
920 payload: ModelReroutedPayload,
921});
922export type ProviderRuntimeModelReroutedEvent = typeof ProviderRuntimeModelReroutedEvent.Type;
923​
924const ProviderRuntimeConfigWarningEvent = Schema.Struct({
925 ...ProviderRuntimeEventBase.fields,
926 type: ConfigWarningType,
927 payload: ConfigWarningPayload,
928});
929export type ProviderRuntimeConfigWarningEvent = typeof ProviderRuntimeConfigWarningEvent.Type;
930​
931const ProviderRuntimeDeprecationNoticeEvent = Schema.Struct({
932 ...ProviderRuntimeEventBase.fields,
933 type: DeprecationNoticeType,
934 payload: DeprecationNoticePayload,
935});
936export type ProviderRuntimeDeprecationNoticeEvent =
937 typeof ProviderRuntimeDeprecationNoticeEvent.Type;
938​
939const ProviderRuntimeFilesPersistedEvent = Schema.Struct({
940 ...ProviderRuntimeEventBase.fields,
941 type: FilesPersistedType,
942 payload: FilesPersistedPayload,
943});
944export type ProviderRuntimeFilesPersistedEvent = typeof ProviderRuntimeFilesPersistedEvent.Type;
945​
946const ProviderRuntimeToolDeniedEvent = Schema.Struct({
947 ...ProviderRuntimeEventBase.fields,
948 type: ToolDeniedType,
949 payload: ToolDeniedPayload,
950});
951export type ProviderRuntimeToolDeniedEvent = typeof ProviderRuntimeToolDeniedEvent.Type;
952​
953const ProviderRuntimeWarningEvent = Schema.Struct({
954 ...ProviderRuntimeEventBase.fields,
955 type: RuntimeWarningType,
956 payload: RuntimeWarningPayload,
957});
958export type ProviderRuntimeWarningEvent = typeof ProviderRuntimeWarningEvent.Type;
959​
960const ProviderRuntimeErrorEvent = Schema.Struct({
961 ...ProviderRuntimeEventBase.fields,
962 type: RuntimeErrorType,
963 payload: RuntimeErrorPayload,
964});
965export type ProviderRuntimeErrorEvent = typeof ProviderRuntimeErrorEvent.Type;
966​
967export const ProviderRuntimeEventV2 = Schema.Union([
968 ProviderRuntimeSessionStartedEvent,
969 ProviderRuntimeSessionConfiguredEvent,
970 ProviderRuntimeSessionStateChangedEvent,
971 ProviderRuntimeSessionExitedEvent,
972 ProviderRuntimeThreadStartedEvent,
973 ProviderRuntimeThreadStateChangedEvent,
974 ProviderRuntimeThreadMetadataUpdatedEvent,
975 ProviderRuntimeThreadTokenUsageUpdatedEvent,
976 ProviderRuntimeThreadRealtimeStartedEvent,
977 ProviderRuntimeThreadRealtimeItemAddedEvent,
978 ProviderRuntimeThreadRealtimeAudioDeltaEvent,
979 ProviderRuntimeThreadRealtimeErrorEvent,
980 ProviderRuntimeThreadRealtimeClosedEvent,
981 ProviderRuntimeTurnStartedEvent,
982 ProviderRuntimeTurnCompletedEvent,
983 ProviderRuntimeTurnAbortedEvent,
984 ProviderRuntimeTurnPlanUpdatedEvent,
985 ProviderRuntimeTurnProposedDeltaEvent,
986 ProviderRuntimeTurnProposedCompletedEvent,
987 ProviderRuntimeTurnDiffUpdatedEvent,
988 ProviderRuntimeItemStartedEvent,
989 ProviderRuntimeItemUpdatedEvent,
990 ProviderRuntimeItemCompletedEvent,
991 ProviderRuntimeContentDeltaEvent,
992 ProviderRuntimeRequestOpenedEvent,
993 ProviderRuntimeRequestResolvedEvent,
994 ProviderRuntimeUserInputRequestedEvent,
995 ProviderRuntimeUserInputResolvedEvent,
996 ProviderRuntimeTaskStartedEvent,
997 ProviderRuntimeTaskProgressEvent,
998 ProviderRuntimeTaskCompletedEvent,
999 ProviderRuntimeHookStartedEvent,
1000 ProviderRuntimeHookProgressEvent,
1001 ProviderRuntimeHookCompletedEvent,
1002 ProviderRuntimeToolProgressEvent,
1003 ProviderRuntimeToolSummaryEvent,
1004 ProviderRuntimeAuthStatusEvent,
1005 ProviderRuntimeAccountUpdatedEvent,
1006 ProviderRuntimeAccountRateLimitsUpdatedEvent,
1007 ProviderRuntimeMcpStatusUpdatedEvent,
1008 ProviderRuntimeMcpOauthCompletedEvent,
1009 ProviderRuntimeModelReroutedEvent,
1010 ProviderRuntimeConfigWarningEvent,
1011 ProviderRuntimeDeprecationNoticeEvent,
1012 ProviderRuntimeFilesPersistedEvent,
1013 ProviderRuntimeToolDeniedEvent,
1014 ProviderRuntimeWarningEvent,
1015 ProviderRuntimeErrorEvent,
1016]);
1017export type ProviderRuntimeEventV2 = typeof ProviderRuntimeEventV2.Type;
1018​
1019export const ProviderRuntimeEvent = ProviderRuntimeEventV2;
1020export type ProviderRuntimeEvent = ProviderRuntimeEventV2;
1021​
1022// Compatibility aliases for call sites still importing legacy names.
1023const ProviderRuntimeMessageDeltaEvent = ProviderRuntimeContentDeltaEvent;
1024export type ProviderRuntimeMessageDeltaEvent = ProviderRuntimeContentDeltaEvent;
1025const ProviderRuntimeMessageCompletedEvent = ProviderRuntimeItemCompletedEvent;
1026export type ProviderRuntimeMessageCompletedEvent = ProviderRuntimeItemCompletedEvent;
1027const ProviderRuntimeToolStartedEvent = ProviderRuntimeItemStartedEvent;
1028export type ProviderRuntimeToolStartedEvent = ProviderRuntimeItemStartedEvent;
1029const ProviderRuntimeToolCompletedEvent = ProviderRuntimeItemCompletedEvent;
1030export type ProviderRuntimeToolCompletedEvent = ProviderRuntimeItemCompletedEvent;
1031const ProviderRuntimeApprovalRequestedEvent = ProviderRuntimeRequestOpenedEvent;
1032export type ProviderRuntimeApprovalRequestedEvent = ProviderRuntimeRequestOpenedEvent;
1033const ProviderRuntimeApprovalResolvedEvent = ProviderRuntimeRequestResolvedEvent;
1034export type ProviderRuntimeApprovalResolvedEvent = ProviderRuntimeRequestResolvedEvent;
1035​
1036// Legacy helper aliases retained for adapters/tests.
1037const ProviderRuntimeToolKind = Schema.Literals(["command", "file-read", "file-change", "other"]);
1038export type ProviderRuntimeToolKind = typeof ProviderRuntimeToolKind.Type;
1039​
1040export const ProviderRuntimeTurnStatus = RuntimeTurnState;
1041export type ProviderRuntimeTurnStatus = RuntimeTurnState;