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

providerRuntime.ts

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