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

providerRuntime.ts

1,292 lines47.5 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";
17import { ProviderUsageLimitsUpdate } from "./providerUsageLimits.ts";
18import { ProviderApprovalOption } from "./providerPolicy.ts";
19​
20const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
21const UnknownRecordSchema = Schema.Record(Schema.String, Schema.Unknown);
22​
23const RuntimeEventRawSource = Schema.Union([
24 Schema.Literal("codex.app-server.notification"),
25 Schema.Literal("codex.app-server.request"),
26 Schema.Literal("codex.eventmsg"),
27 Schema.Literal("claude.sdk.message"),
28 Schema.Literal("claude.sdk.permission"),
29 Schema.Literal("codex.sdk.thread-event"),
30 Schema.Literal("opencode.sdk.event"),
31 Schema.Literal("acp.jsonrpc"),
32 Schema.TemplateLiteral(["acp.", Schema.String, ".extension"]),
33]);
34export type RuntimeEventRawSource = typeof RuntimeEventRawSource.Type;
35​
36export const RuntimeEventRaw = Schema.Struct({
37 source: RuntimeEventRawSource,
38 method: Schema.optional(TrimmedNonEmptyStringSchema),
39 messageType: Schema.optional(TrimmedNonEmptyStringSchema),
40 payload: Schema.Unknown,
41});
42export type RuntimeEventRaw = typeof RuntimeEventRaw.Type;
43​
44const ProviderRequestId = TrimmedNonEmptyStringSchema;
45export type ProviderRequestId = typeof ProviderRequestId.Type;
46​
47const ProviderRefs = Schema.Struct({
48 providerTurnId: Schema.optional(TrimmedNonEmptyStringSchema),
49 providerItemId: Schema.optional(ProviderItemId),
50 providerRequestId: Schema.optional(ProviderRequestId),
51});
52export type ProviderRefs = typeof ProviderRefs.Type;
53​
54const RuntimeSessionState = Schema.Literals([
55 "starting",
56 "ready",
57 "running",
58 "waiting",
59 "stopped",
60 "error",
61]);
62export type RuntimeSessionState = typeof RuntimeSessionState.Type;
63​
64const RuntimeThreadState = Schema.Literals([
65 "active",
66 "idle",
67 "archived",
68 "closed",
69 "compacted",
70 "error",
71]);
72export type RuntimeThreadState = typeof RuntimeThreadState.Type;
73​
74const RuntimeTurnState = Schema.Literals(["completed", "failed", "interrupted", "cancelled"]);
75export type RuntimeTurnState = typeof RuntimeTurnState.Type;
76​
77const RuntimePlanStepStatus = Schema.Literals(["pending", "inProgress", "completed"]);
78export type RuntimePlanStepStatus = typeof RuntimePlanStepStatus.Type;
79​
80const RuntimeItemStatus = Schema.Literals(["inProgress", "completed", "failed", "declined"]);
81export type RuntimeItemStatus = typeof RuntimeItemStatus.Type;
82​
83const RuntimeContentStreamKind = Schema.Literals([
84 "assistant_text",
85 "reasoning_text",
86 "reasoning_summary_text",
87 "plan_text",
88 "command_output",
89 "file_change_output",
90 "unknown",
91]);
92export type RuntimeContentStreamKind = typeof RuntimeContentStreamKind.Type;
93​
94const RuntimeSessionExitKind = Schema.Literals(["graceful", "error"]);
95export type RuntimeSessionExitKind = typeof RuntimeSessionExitKind.Type;
96​
97const RuntimeErrorClass = Schema.Literals([
98 "provider_error",
99 "transport_error",
100 "permission_error",
101 "validation_error",
102 "unknown",
103]);
104export type RuntimeErrorClass = typeof RuntimeErrorClass.Type;
105​
106const TOOL_LIFECYCLE_ITEM_TYPES = [
107 "command_execution",
108 "file_change",
109 "mcp_tool_call",
110 "dynamic_tool_call",
111 "collab_agent_tool_call",
112 "web_search",
113 "image_view",
114] as const;
115​
116export const ToolLifecycleItemType = Schema.Literals(TOOL_LIFECYCLE_ITEM_TYPES);
117export type ToolLifecycleItemType = typeof ToolLifecycleItemType.Type;
118​
119export function isToolLifecycleItemType(value: string): value is ToolLifecycleItemType {
120 return TOOL_LIFECYCLE_ITEM_TYPES.includes(value as ToolLifecycleItemType);
122​
123export const CanonicalItemType = Schema.Literals([
124 "user_message",
125 "assistant_message",
126 "reasoning",
127 "plan",
128 ...TOOL_LIFECYCLE_ITEM_TYPES,
129 "review_entered",
130 "review_exited",
131 "context_compaction",
132 "error",
133 "unknown",
134]);
135export type CanonicalItemType = typeof CanonicalItemType.Type;
136​
137export const CanonicalRequestType = Schema.Literals([
138 "command_execution_approval",
139 "file_read_approval",
140 "file_change_approval",
141 "apply_patch_approval",
142 "exec_command_approval",
143 "mcp_elicitation_approval",
144 "tool_user_input",
145 "dynamic_tool_call",
146 "auth_tokens_refresh",
147 "unknown",
148]);
149export type CanonicalRequestType = typeof CanonicalRequestType.Type;
150​
151const ProviderRuntimeEventType = Schema.Literals([
152 "session.started",
153 "session.configured",
154 "session.state.changed",
155 "session.exited",
156 "thread.started",
157 "thread.state.changed",
158 "thread.metadata.updated",
159 "thread.token-usage.updated",
160 "thread.realtime.started",
161 "thread.realtime.item-added",
162 "thread.realtime.audio.delta",
163 "thread.realtime.error",
164 "thread.realtime.closed",
165 "turn.started",
166 "turn.completed",
167 "turn.aborted",
168 "turn.plan.updated",
169 "turn.proposed.delta",
170 "turn.proposed.completed",
171 "turn.diff.updated",
172 "item.started",
173 "item.updated",
174 "item.completed",
175 "content.delta",
176 "request.opened",
177 "request.resolved",
178 "user-input.requested",
179 "user-input.resolved",
180 "task.started",
181 "task.progress",
182 "task.updated",
183 "task.completed",
184 "hook.started",
185 "hook.progress",
186 "hook.completed",
187 "tool.progress",
188 "tool.summary",
189 "tool.denied",
190 "auth.status",
191 "account.updated",
192 "account.rate-limits.updated",
193 "mcp.status.updated",
194 "mcp.oauth.completed",
195 "model.rerouted",
196 "config.warning",
197 "deprecation.notice",
198 "files.persisted",
199 "runtime.warning",
200 "runtime.error",
201]);
202export type ProviderRuntimeEventType = typeof ProviderRuntimeEventType.Type;
203​
204const SessionStartedType = Schema.Literal("session.started");
205const SessionConfiguredType = Schema.Literal("session.configured");
206const SessionStateChangedType = Schema.Literal("session.state.changed");
207const SessionExitedType = Schema.Literal("session.exited");
208const ThreadStartedType = Schema.Literal("thread.started");
209const ThreadStateChangedType = Schema.Literal("thread.state.changed");
210const ThreadMetadataUpdatedType = Schema.Literal("thread.metadata.updated");
211const ThreadTokenUsageUpdatedType = Schema.Literal("thread.token-usage.updated");
212const ThreadRealtimeStartedType = Schema.Literal("thread.realtime.started");
213const ThreadRealtimeItemAddedType = Schema.Literal("thread.realtime.item-added");
214const ThreadRealtimeAudioDeltaType = Schema.Literal("thread.realtime.audio.delta");
215const ThreadRealtimeErrorType = Schema.Literal("thread.realtime.error");
216const ThreadRealtimeClosedType = Schema.Literal("thread.realtime.closed");
217const TurnStartedType = Schema.Literal("turn.started");
218const TurnCompletedType = Schema.Literal("turn.completed");
219const TurnAbortedType = Schema.Literal("turn.aborted");
220const TurnPlanUpdatedType = Schema.Literal("turn.plan.updated");
221const TurnProposedDeltaType = Schema.Literal("turn.proposed.delta");
222const TurnProposedCompletedType = Schema.Literal("turn.proposed.completed");
223const TurnDiffUpdatedType = Schema.Literal("turn.diff.updated");
224const ItemStartedType = Schema.Literal("item.started");
225const ItemUpdatedType = Schema.Literal("item.updated");
226const ItemCompletedType = Schema.Literal("item.completed");
227const ContentDeltaType = Schema.Literal("content.delta");
228const RequestOpenedType = Schema.Literal("request.opened");
229const RequestResolvedType = Schema.Literal("request.resolved");
230const UserInputRequestedType = Schema.Literal("user-input.requested");
231const UserInputResolvedType = Schema.Literal("user-input.resolved");
232const TaskStartedType = Schema.Literal("task.started");
233const TaskProgressType = Schema.Literal("task.progress");
234const TaskUpdatedType = Schema.Literal("task.updated");
235const TaskCompletedType = Schema.Literal("task.completed");
236const HookStartedType = Schema.Literal("hook.started");
237const HookProgressType = Schema.Literal("hook.progress");
238const HookCompletedType = Schema.Literal("hook.completed");
239const ToolProgressType = Schema.Literal("tool.progress");
240const ToolSummaryType = Schema.Literal("tool.summary");
241const AuthStatusType = Schema.Literal("auth.status");
242const AccountUpdatedType = Schema.Literal("account.updated");
243const AccountRateLimitsUpdatedType = Schema.Literal("account.rate-limits.updated");
244const McpStatusUpdatedType = Schema.Literal("mcp.status.updated");
245const McpOauthCompletedType = Schema.Literal("mcp.oauth.completed");
246const ModelReroutedType = Schema.Literal("model.rerouted");
247const ConfigWarningType = Schema.Literal("config.warning");
248const DeprecationNoticeType = Schema.Literal("deprecation.notice");
249const FilesPersistedType = Schema.Literal("files.persisted");
250const ToolDeniedType = Schema.Literal("tool.denied");
251const RuntimeWarningType = Schema.Literal("runtime.warning");
252const RuntimeErrorType = Schema.Literal("runtime.error");
253​
254const ProviderRuntimeEventBase = Schema.Struct({
255 eventId: EventId,
256 provider: ProviderDriverKind,
257 // Optional during the driver/instance migration. See providerInstance.ts
258 // for the routing-key-vs-driver-id distinction. Once every emitter
259 // populates it (post-slice-4), routing flips to instance-id-only.
260 providerInstanceId: Schema.optional(ProviderInstanceId),
261 threadId: ThreadId,
262 createdAt: IsoDateTime,
263 turnId: Schema.optional(TurnId),
264 itemId: Schema.optional(RuntimeItemId),
265 requestId: Schema.optional(RuntimeRequestId),
266 providerRefs: Schema.optional(ProviderRefs),
267 raw: Schema.optional(RuntimeEventRaw),
268});
269export type ProviderRuntimeEventBase = typeof ProviderRuntimeEventBase.Type;
270​
271const SessionStartedPayload = Schema.Struct({
272 message: Schema.optional(TrimmedNonEmptyStringSchema),
273 resume: Schema.optional(Schema.Unknown),
274});
275export type SessionStartedPayload = typeof SessionStartedPayload.Type;
276​
277const SessionConfiguredPayload = Schema.Struct({
278 config: UnknownRecordSchema,
279});
280export type SessionConfiguredPayload = typeof SessionConfiguredPayload.Type;
281​
282const SessionStateChangedPayload = Schema.Struct({
283 state: RuntimeSessionState,
284 reason: Schema.optional(TrimmedNonEmptyStringSchema),
285 detail: Schema.optional(Schema.Unknown),
286});
287export type SessionStateChangedPayload = typeof SessionStateChangedPayload.Type;
288​
289const SessionExitedPayload = Schema.Struct({
290 reason: Schema.optional(TrimmedNonEmptyStringSchema),
291 recoverable: Schema.optional(Schema.Boolean),
292 exitKind: Schema.optional(RuntimeSessionExitKind),
293});
294export type SessionExitedPayload = typeof SessionExitedPayload.Type;
295​
296const ThreadStartedPayload = Schema.Struct({
297 providerThreadId: Schema.optional(TrimmedNonEmptyStringSchema),
298});
299export type ThreadStartedPayload = typeof ThreadStartedPayload.Type;
300​
301const ThreadStateChangedPayload = Schema.Struct({
302 state: RuntimeThreadState,
303 beforeTokens: Schema.optional(NonNegativeInt),
304 afterTokens: Schema.optional(NonNegativeInt),
305 detail: Schema.optional(Schema.Unknown),
306});
307export type ThreadStateChangedPayload = typeof ThreadStateChangedPayload.Type;
308​
309const ThreadMetadataUpdatedPayload = Schema.Struct({
310 name: Schema.optional(TrimmedNonEmptyStringSchema),
311 metadata: Schema.optional(UnknownRecordSchema),
312});
313export type ThreadMetadataUpdatedPayload = typeof ThreadMetadataUpdatedPayload.Type;
314​
315export const ThreadTokenUsageSnapshot = Schema.Struct({
316 usedTokens: NonNegativeInt,
317 totalProcessedTokens: Schema.optional(NonNegativeInt),
318 maxTokens: Schema.optional(PositiveInt),
319 inputTokens: Schema.optional(NonNegativeInt),
320 cachedInputTokens: Schema.optional(NonNegativeInt),
321 outputTokens: Schema.optional(NonNegativeInt),
322 reasoningOutputTokens: Schema.optional(NonNegativeInt),
323 lastUsedTokens: Schema.optional(NonNegativeInt),
324 lastInputTokens: Schema.optional(NonNegativeInt),
325 lastCachedInputTokens: Schema.optional(NonNegativeInt),
326 lastOutputTokens: Schema.optional(NonNegativeInt),
327 lastReasoningOutputTokens: Schema.optional(NonNegativeInt),
328 toolUses: Schema.optional(NonNegativeInt),
329 durationMs: Schema.optional(NonNegativeInt),
330 compactsAutomatically: Schema.optional(Schema.Boolean),
331 autoCompactThreshold: Schema.optional(PositiveInt),
332 cost: Schema.optional(
333 Schema.Struct({
334 amount: Schema.Number.check(Schema.isFinite()),
335 currency: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(32)),
336 }),
337 ),
338});
339export type ThreadTokenUsageSnapshot = typeof ThreadTokenUsageSnapshot.Type;
340​
341const ThreadTokenUsageUpdatedPayload = Schema.Struct({
342 usage: ThreadTokenUsageSnapshot,
343});
344export type ThreadTokenUsageUpdatedPayload = typeof ThreadTokenUsageUpdatedPayload.Type;
345​
346const ThreadRealtimeStartedPayload = Schema.Struct({
347 realtimeSessionId: Schema.optional(TrimmedNonEmptyStringSchema),
348});
349export type ThreadRealtimeStartedPayload = typeof ThreadRealtimeStartedPayload.Type;
350​
351const ThreadRealtimeItemAddedPayload = Schema.Struct({
352 item: Schema.Unknown,
353});
354export type ThreadRealtimeItemAddedPayload = typeof ThreadRealtimeItemAddedPayload.Type;
355​
356const ThreadRealtimeAudioDeltaPayload = Schema.Struct({
357 audio: Schema.Unknown,
358});
359export type ThreadRealtimeAudioDeltaPayload = typeof ThreadRealtimeAudioDeltaPayload.Type;
360​
361const ThreadRealtimeErrorPayload = Schema.Struct({
362 message: TrimmedNonEmptyStringSchema,
363});
364export type ThreadRealtimeErrorPayload = typeof ThreadRealtimeErrorPayload.Type;
365​
366const ThreadRealtimeClosedPayload = Schema.Struct({
367 reason: Schema.optional(TrimmedNonEmptyStringSchema),
368});
369export type ThreadRealtimeClosedPayload = typeof ThreadRealtimeClosedPayload.Type;
370​
371const TurnStartedPayload = Schema.Struct({
372 model: Schema.optional(TrimmedNonEmptyStringSchema),
373 effort: Schema.optional(TrimmedNonEmptyStringSchema),
374});
375export type TurnStartedPayload = typeof TurnStartedPayload.Type;
376​
377/**
378 * Normalized main-agent usage for one turn. Input includes cache reads and
379 * writes. Output includes reasoning, and reasoningTokens is an optional subset.
380 * Complete means the provider supplied full input and output totals. Partial
381 * means every included count is valid, but the full turn total is not known.
382 */
383const TurnTokenUsageCommonFields = {
384 usageScope: Schema.Literal("main_agent"),
385 cachedInputTokens: Schema.optional(NonNegativeInt),
386 cacheCreationTokens: Schema.optional(NonNegativeInt),
387 reasoningTokens: Schema.optional(NonNegativeInt),
388 hasSubagents: Schema.Boolean,
389};
390export const TurnTokenUsage = Schema.Union([
391 Schema.Struct({
392 ...TurnTokenUsageCommonFields,
393 usageStatus: Schema.Literal("complete"),
394 inputTokens: NonNegativeInt,
395 outputTokens: NonNegativeInt,
396 }),
397 Schema.Struct({
398 ...TurnTokenUsageCommonFields,
399 usageStatus: Schema.Literals(["partial", "unavailable"]),
400 inputTokens: Schema.optional(NonNegativeInt),
401 outputTokens: Schema.optional(NonNegativeInt),
402 }),
403]);
404export type TurnTokenUsage = typeof TurnTokenUsage.Type;
405​
406const TurnCompletedPayload = Schema.Struct({
407 state: RuntimeTurnState,
408 stopReason: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
409 usage: Schema.optional(Schema.Unknown),
410 modelUsage: Schema.optional(UnknownRecordSchema),
411 totalCostUsd: Schema.optional(Schema.Number),
412 errorMessage: Schema.optional(TrimmedNonEmptyStringSchema),
413 tokenUsage: Schema.optional(TurnTokenUsage),
414});
415export type TurnCompletedPayload = typeof TurnCompletedPayload.Type;
416​
417const TurnAbortedPayload = Schema.Struct({
418 reason: TrimmedNonEmptyStringSchema,
419 tokenUsage: Schema.optional(TurnTokenUsage),
420});
421export type TurnAbortedPayload = typeof TurnAbortedPayload.Type;
422​
423const RuntimePlanStep = Schema.Struct({
424 step: TrimmedNonEmptyStringSchema,
425 status: RuntimePlanStepStatus,
426});
427export type RuntimePlanStep = typeof RuntimePlanStep.Type;
428​
429const TurnPlanUpdatedPayload = Schema.Struct({
430 explanation: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
431 plan: Schema.Array(RuntimePlanStep),
432});
433export type TurnPlanUpdatedPayload = typeof TurnPlanUpdatedPayload.Type;
434​
435const TurnProposedDeltaPayload = Schema.Struct({
436 delta: Schema.String,
437});
438export type TurnProposedDeltaPayload = typeof TurnProposedDeltaPayload.Type;
439​
440const TurnProposedCompletedPayload = Schema.Struct({
441 planMarkdown: TrimmedNonEmptyStringSchema,
442});
443export type TurnProposedCompletedPayload = typeof TurnProposedCompletedPayload.Type;
444​
445const TurnDiffUpdatedPayload = Schema.Struct({
446 unifiedDiff: Schema.String,
447});
448export type TurnDiffUpdatedPayload = typeof TurnDiffUpdatedPayload.Type;
449​
450export const ToolActivitySurface = Schema.Literals(["browser", "computer"]);
451export type ToolActivitySurface = typeof ToolActivitySurface.Type;
452​
453export const ToolActivityNativeAppReference = Schema.Union([
454 Schema.TaggedStruct("app-id", {
455 appId: TrimmedNonEmptyStringSchema.check(
456 Schema.isMaxLength(512),
457 Schema.isPattern(/^[A-Za-z0-9._-]+$/u),
458 ),
459 }),
460 Schema.TaggedStruct("display-name", {
461 displayName: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(160)),
462 }),
463]);
464export type ToolActivityNativeAppReference = typeof ToolActivityNativeAppReference.Type;
465​
466export const ToolActivityIcon = Schema.Union([
467 Schema.TaggedStruct("website", {
468 pageUrl: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096)),
469 faviconUrl: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096))),
470 faviconUrlDark: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096))),
471 }),
472 Schema.TaggedStruct("native-app", {
473 app: ToolActivityNativeAppReference,
474 }),
475 Schema.TaggedStruct("themed-logo", {
476 logoUrl: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096)),
477 logoUrlDark: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096))),
478 }),
479]);
480export type ToolActivityIcon = typeof ToolActivityIcon.Type;
481​
482export const ToolActivitySource = Schema.Struct({
483 key: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(512)),
484 name: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(160)),
485 kind: Schema.Literals(["browser", "computer", "integration"]),
486 icon: Schema.optional(ToolActivityIcon),
487});
488export type ToolActivitySource = typeof ToolActivitySource.Type;
489​
490export const ItemLifecyclePayload = Schema.Struct({
491 itemType: CanonicalItemType,
492 status: Schema.optional(RuntimeItemStatus),
493 title: Schema.optional(TrimmedNonEmptyStringSchema),
494 detail: Schema.optional(TrimmedNonEmptyStringSchema),
495 toolSurface: Schema.optional(ToolActivitySurface),
496 toolIcon: Schema.optional(ToolActivityIcon),
497 toolSource: Schema.optional(ToolActivitySource),
498 data: Schema.optional(Schema.Unknown),
499 /**
500 * Owning agent when this item ran inside a subagent (resolved from the
501 * SDK's parent_tool_use_id). Clients re-home attributed items out of the
502 * main timeline and into the owning agent's Agents-surface row.
503 */
504 agentId: Schema.optional(TrimmedNonEmptyStringSchema),
505 parentToolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
506});
507export type ItemLifecyclePayload = typeof ItemLifecyclePayload.Type;
508​
509const ContentDeltaPayload = Schema.Struct({
510 streamKind: RuntimeContentStreamKind,
511 delta: Schema.String,
512 contentIndex: Schema.optional(Schema.Int),
513 summaryIndex: Schema.optional(Schema.Int),
514});
515export type ContentDeltaPayload = typeof ContentDeltaPayload.Type;
516​
517const RequestOpenedPayload = Schema.Struct({
518 requestType: CanonicalRequestType,
519 detail: Schema.optional(TrimmedNonEmptyStringSchema),
520 appName: Schema.optional(TrimmedNonEmptyStringSchema),
521 options: Schema.optional(Schema.Array(ProviderApprovalOption)),
522 args: Schema.optional(Schema.Unknown),
523});
524export type RequestOpenedPayload = typeof RequestOpenedPayload.Type;
525​
526const RequestResolvedPayload = Schema.Struct({
527 requestType: CanonicalRequestType,
528 decision: Schema.optional(TrimmedNonEmptyStringSchema),
529 resolution: Schema.optional(Schema.Unknown),
530});
531export type RequestResolvedPayload = typeof RequestResolvedPayload.Type;
532​
533const UserInputQuestionOption = Schema.Struct({
534 label: TrimmedNonEmptyStringSchema,
535 description: Schema.String,
536 value: Schema.optional(Schema.String),
537});
538export type UserInputQuestionOption = typeof UserInputQuestionOption.Type;
539​
540export const UserInputQuestion = Schema.Struct({
541 id: TrimmedNonEmptyStringSchema,
542 header: TrimmedNonEmptyStringSchema,
543 question: TrimmedNonEmptyStringSchema,
544 options: Schema.Array(UserInputQuestionOption),
545 allowCustomAnswer: Schema.optional(Schema.Boolean),
546 multiSelect: Schema.optional(Schema.Boolean).pipe(
547 Schema.withConstructorDefault(Effect.succeed(false)),
548 ),
549});
550export type UserInputQuestion = typeof UserInputQuestion.Type;
551​
552export const UserInputRequestedPayload = Schema.Struct({
553 questions: Schema.Array(UserInputQuestion),
554 responseMode: Schema.optional(Schema.Literal("message")),
555});
556export type UserInputRequestedPayload = typeof UserInputRequestedPayload.Type;
557​
558const UserInputResolvedPayload = Schema.Struct({
559 answers: UnknownRecordSchema,
560});
561export type UserInputResolvedPayload = typeof UserInputResolvedPayload.Type;
562​
563/**
564 * Typed per-task usage rollup. Field names match the orchestration-v2 subagent
565 * usage vocabulary (#4779) so the eventual migration is a rename, not a remap.
566 * Claude reports per-activation deltas; Codex reports cumulative totals — the
567 * merge strategy is provider-specific and lives in client-runtime.
568 */
569export const RuntimeTaskUsage = Schema.Struct({
570 totalTokens: NonNegativeInt,
571 inputTokens: Schema.optional(NonNegativeInt),
572 cachedInputTokens: Schema.optional(NonNegativeInt),
573 outputTokens: Schema.optional(NonNegativeInt),
574 reasoningOutputTokens: Schema.optional(NonNegativeInt),
575 toolUses: Schema.optional(NonNegativeInt),
576 durationMs: Schema.optional(NonNegativeInt),
577});
578export type RuntimeTaskUsage = typeof RuntimeTaskUsage.Type;
579​
580export const TaskWorkflowPhase = Schema.Struct({
581 index: NonNegativeInt,
582 title: TrimmedNonEmptyStringSchema,
583});
584export type TaskWorkflowPhase = typeof TaskWorkflowPhase.Type;
585​
586export const TaskRunHandles = Schema.Struct({
587 runId: Schema.optional(TrimmedNonEmptyStringSchema),
588 scriptPath: Schema.optional(TrimmedNonEmptyStringSchema),
589 transcriptDir: Schema.optional(TrimmedNonEmptyStringSchema),
590 /** Only http/https URLs may be stored here — sanitized at the adapter. */
591 sessionUrl: Schema.optional(TrimmedNonEmptyStringSchema),
592});
593export type TaskRunHandles = typeof TaskRunHandles.Type;
594​
595/**
596 * Watch-loop task types: Monitor-tool tasks plus background shells (a shell
597 * that outlives its turn is in practice a watch loop). Canonical single copy —
598 * the server liveness registry, ingestion's agentKind stamp, and the client
599 * fold's legacy fallback all classify with these sets.
600 */
601export const MONITOR_TASK_TYPES: ReadonlySet<string> = new Set([
602 "monitor",
603 "monitor_mcp",
604 "local_bash",
605 "shell",
606]);
607/** Task types that are neither agents nor watch loops (plan-mode bookkeeping). */
608export const INERT_TASK_TYPES: ReadonlySet<string> = new Set(["plan", "dream"]);
609​
610/**
611 * Agent-vs-background classification, stamped by ingestion as `agentKind` so
612 * persisted rows are self-describing. A deliberate denylist: the SDK's
613 * agent-flavored type names drift (subagent, local_agent, local_workflow, …)
614 * and an allowlist silently dropped real subagents when "local_agent"
615 * appeared. A task launched from inside a subagent (agentId set) is
616 * agent-internal background work UNLESS it is itself agent-flavored — a
617 * nested agent can outlive its parent and stays in the roster.
618 */
619export function classifyTaskAgentKind(input: {
620 readonly taskType?: string | undefined;
621 readonly agentId?: string | undefined;
622}): "agent" | "background" {
623 const { taskType, agentId } = input;
624 const nonAgentType =
625 taskType !== undefined && (MONITOR_TASK_TYPES.has(taskType) || INERT_TASK_TYPES.has(taskType));
626 if (agentId !== undefined && agentId.trim().length > 0) {
627 return taskType === undefined || nonAgentType ? "background" : "agent";
628 }
629 return nonAgentType ? "background" : "agent";
631​
632/**
633 * Optional agent-identity linkage carried on every task lifecycle payload.
634 * Repeated on progress and terminal rows (not just start) so client folds can
635 * reconstruct an agent even when its start row aged out of activity retention.
636 * All fields optional: old emitters and old rows decode unchanged.
637 */
638const taskAgentLinkageFields = {
639 /** SDK task_type (subagent/shell/monitor/local_workflow/…), repeated on
640 * every row so folds can classify without the start row. */
641 taskType: Schema.optional(TrimmedNonEmptyStringSchema),
642 /**
643 * Server-stamped classification (classifyTaskAgentKind at ingestion).
644 * Clients trust this stamp outright; rows without it (legacy, pre-stamp)
645 * fall back to client-side heuristics.
646 */
647 agentKind: Schema.optional(Schema.Literals(["agent", "background"])),
648 /**
649 * Owning agent when the task itself was launched from inside a subagent
650 * (e.g. a subagent's background shell). Clients treat such tasks as
651 * agent-internal and keep them out of the parent work log.
652 */
653 agentId: Schema.optional(TrimmedNonEmptyStringSchema),
654 title: Schema.optional(TrimmedNonEmptyStringSchema),
655 role: Schema.optional(TrimmedNonEmptyStringSchema),
656 model: Schema.optional(TrimmedNonEmptyStringSchema),
657 /** Reasoning effort when known (e.g. "high"). Open string: provider vocabularies differ. */
658 effort: Schema.optional(TrimmedNonEmptyStringSchema),
659 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
660 parentAgentId: Schema.optional(TrimmedNonEmptyStringSchema),
661 workflowName: Schema.optional(TrimmedNonEmptyStringSchema),
662 agentIndex: Schema.optional(NonNegativeInt),
663 phaseIndex: Schema.optional(NonNegativeInt),
664 phaseTitle: Schema.optional(TrimmedNonEmptyStringSchema),
665 phases: Schema.optional(Schema.Array(TaskWorkflowPhase)),
666 attempt: Schema.optional(NonNegativeInt),
667 runHandles: Schema.optional(TaskRunHandles),
668 outputFile: Schema.optional(TrimmedNonEmptyStringSchema),
669 /** Codex agent hierarchy path, e.g. "/root/marlow". */
670 agentPath: Schema.optional(TrimmedNonEmptyStringSchema),
671 /**
672 * Set on provider-synthesized child-agent events (Codex) whose activity
673 * belongs in the Agents surface, never the parent timeline.
674 */
675 timelineBypass: Schema.optional(Schema.Boolean),
676} as const;
677​
678export const TaskAgentLinkage = Schema.Struct(taskAgentLinkageFields);
679export type TaskAgentLinkage = typeof TaskAgentLinkage.Type;
680​
681const TaskStartedPayload = Schema.Struct({
682 taskId: RuntimeTaskId,
683 description: Schema.optional(TrimmedNonEmptyStringSchema),
684 ...taskAgentLinkageFields,
685});
686export type TaskStartedPayload = typeof TaskStartedPayload.Type;
687​
688export const RuntimeTaskStatus = Schema.Literals([
689 "pending",
690 "running",
691 "waiting",
692 "idle",
693 "completed",
694 "failed",
695 "cancelled",
696 "interrupted",
697]);
698export type RuntimeTaskStatus = typeof RuntimeTaskStatus.Type;
699​
700const TaskProgressPayload = Schema.Struct({
701 taskId: RuntimeTaskId,
702 description: TrimmedNonEmptyStringSchema,
703 summary: Schema.optional(TrimmedNonEmptyStringSchema),
704 usage: Schema.optional(Schema.Unknown),
705 typedUsage: Schema.optional(RuntimeTaskUsage),
706 lastToolName: Schema.optional(TrimmedNonEmptyStringSchema),
707 /** Present on synthesized member/child progress rows that carry state. */
708 status: Schema.optional(RuntimeTaskStatus),
709 error: Schema.optional(TrimmedNonEmptyStringSchema),
710 ...taskAgentLinkageFields,
711});
712export type TaskProgressPayload = typeof TaskProgressPayload.Type;
713​
714/**
715 * Non-terminal status patch (from the Claude SDK's task_updated, which main
716 * previously dropped). killed→cancelled and paused→idle are mapped at the
717 * adapter so the wire only carries the shared vocabulary.
718 */
719const TaskUpdatedPayload = Schema.Struct({
720 taskId: RuntimeTaskId,
721 status: Schema.optional(RuntimeTaskStatus),
722 description: Schema.optional(TrimmedNonEmptyStringSchema),
723 error: Schema.optional(TrimmedNonEmptyStringSchema),
724 endedAt: Schema.optional(IsoDateTime),
725 isBackgrounded: Schema.optional(Schema.Boolean),
726 ...taskAgentLinkageFields,
727});
728export type TaskUpdatedPayload = typeof TaskUpdatedPayload.Type;
729​
730const TaskCompletedPayload = Schema.Struct({
731 taskId: RuntimeTaskId,
732 status: Schema.Literals(["completed", "failed", "stopped"]),
733 summary: Schema.optional(TrimmedNonEmptyStringSchema),
734 usage: Schema.optional(Schema.Unknown),
735 typedUsage: Schema.optional(RuntimeTaskUsage),
736 ...taskAgentLinkageFields,
737});
738export type TaskCompletedPayload = typeof TaskCompletedPayload.Type;
739​
740const HookStartedPayload = Schema.Struct({
741 hookId: TrimmedNonEmptyStringSchema,
742 hookName: TrimmedNonEmptyStringSchema,
743 hookEvent: TrimmedNonEmptyStringSchema,
744});
745export type HookStartedPayload = typeof HookStartedPayload.Type;
746​
747const HookProgressPayload = Schema.Struct({
748 hookId: TrimmedNonEmptyStringSchema,
749 output: Schema.optional(Schema.String),
750 stdout: Schema.optional(Schema.String),
751 stderr: Schema.optional(Schema.String),
752});
753export type HookProgressPayload = typeof HookProgressPayload.Type;
754​
755const HookCompletedPayload = Schema.Struct({
756 hookId: TrimmedNonEmptyStringSchema,
757 outcome: Schema.Literals(["success", "error", "cancelled"]),
758 output: Schema.optional(Schema.String),
759 stdout: Schema.optional(Schema.String),
760 stderr: Schema.optional(Schema.String),
761 exitCode: Schema.optional(Schema.Int),
762});
763export type HookCompletedPayload = typeof HookCompletedPayload.Type;
764​
765const ToolProgressPayload = Schema.Struct({
766 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
767 toolName: Schema.optional(TrimmedNonEmptyStringSchema),
768 summary: Schema.optional(TrimmedNonEmptyStringSchema),
769 elapsedSeconds: Schema.optional(Schema.Number),
770 /** Owning task/agent when the tool ran inside a subagent. */
771 taskId: Schema.optional(RuntimeTaskId),
772 parentToolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
773});
774export type ToolProgressPayload = typeof ToolProgressPayload.Type;
775​
776const ToolSummaryPayload = Schema.Struct({
777 summary: TrimmedNonEmptyStringSchema,
778 precedingToolUseIds: Schema.optional(Schema.Array(TrimmedNonEmptyStringSchema)),
779});
780export type ToolSummaryPayload = typeof ToolSummaryPayload.Type;
781​
782const AuthStatusPayload = Schema.Struct({
783 isAuthenticating: Schema.optional(Schema.Boolean),
784 output: Schema.optional(Schema.Array(Schema.String)),
785 error: Schema.optional(TrimmedNonEmptyStringSchema),
786});
787export type AuthStatusPayload = typeof AuthStatusPayload.Type;
788​
789const AccountUpdatedPayload = Schema.Struct({
790 account: Schema.Unknown,
791});
792export type AccountUpdatedPayload = typeof AccountUpdatedPayload.Type;
793​
794/**
795 * Adapters normalise their native rate-limit payload at the boundary so the
796 * consumer that folds it into the provider snapshot never sees driver shapes.
797 */
798const AccountRateLimitsUpdatedPayload = Schema.Struct({
799 limits: ProviderUsageLimitsUpdate,
800});
801export type AccountRateLimitsUpdatedPayload = typeof AccountRateLimitsUpdatedPayload.Type;
802​
803const McpStatusUpdatedPayload = Schema.Struct({
804 status: Schema.Unknown,
805});
806export type McpStatusUpdatedPayload = typeof McpStatusUpdatedPayload.Type;
807​
808const McpOauthCompletedPayload = Schema.Struct({
809 success: Schema.Boolean,
810 name: Schema.optional(TrimmedNonEmptyStringSchema),
811 error: Schema.optional(TrimmedNonEmptyStringSchema),
812});
813export type McpOauthCompletedPayload = typeof McpOauthCompletedPayload.Type;
814​
815const ModelReroutedPayload = Schema.Struct({
816 fromModel: TrimmedNonEmptyStringSchema,
817 toModel: TrimmedNonEmptyStringSchema,
818 reason: TrimmedNonEmptyStringSchema,
819});
820export type ModelReroutedPayload = typeof ModelReroutedPayload.Type;
821​
822const ConfigWarningPayload = Schema.Struct({
823 summary: TrimmedNonEmptyStringSchema,
824 details: Schema.optional(TrimmedNonEmptyStringSchema),
825 path: Schema.optional(TrimmedNonEmptyStringSchema),
826 range: Schema.optional(Schema.Unknown),
827});
828export type ConfigWarningPayload = typeof ConfigWarningPayload.Type;
829​
830const DeprecationNoticePayload = Schema.Struct({
831 summary: TrimmedNonEmptyStringSchema,
832 details: Schema.optional(TrimmedNonEmptyStringSchema),
833});
834export type DeprecationNoticePayload = typeof DeprecationNoticePayload.Type;
835​
836const FilesPersistedPayload = Schema.Struct({
837 files: Schema.Array(
838 Schema.Struct({
839 filename: TrimmedNonEmptyStringSchema,
840 fileId: TrimmedNonEmptyStringSchema,
841 }),
842 ),
843 failed: Schema.optional(
844 Schema.Array(
845 Schema.Struct({
846 filename: TrimmedNonEmptyStringSchema,
847 error: TrimmedNonEmptyStringSchema,
848 }),
849 ),
850 ),
851});
852export type FilesPersistedPayload = typeof FilesPersistedPayload.Type;
853​
854const ToolDeniedPayload = Schema.Struct({
855 toolName: TrimmedNonEmptyStringSchema,
856 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
857 reason: Schema.optional(TrimmedNonEmptyStringSchema),
858 agentId: Schema.optional(TrimmedNonEmptyStringSchema),
859});
860export type ToolDeniedPayload = typeof ToolDeniedPayload.Type;
861​
862const RuntimeWarningPayload = Schema.Struct({
863 message: TrimmedNonEmptyStringSchema,
864 detail: Schema.optional(Schema.Unknown),
865});
866export type RuntimeWarningPayload = typeof RuntimeWarningPayload.Type;
867​
868const RuntimeErrorPayload = Schema.Struct({
869 message: TrimmedNonEmptyStringSchema,
870 class: Schema.optional(RuntimeErrorClass),
871 detail: Schema.optional(Schema.Unknown),
872});
873export type RuntimeErrorPayload = typeof RuntimeErrorPayload.Type;
874​
875const ProviderRuntimeSessionStartedEvent = Schema.Struct({
876 ...ProviderRuntimeEventBase.fields,
877 type: SessionStartedType,
878 payload: SessionStartedPayload,
879});
880export type ProviderRuntimeSessionStartedEvent = typeof ProviderRuntimeSessionStartedEvent.Type;
881​
882const ProviderRuntimeSessionConfiguredEvent = Schema.Struct({
883 ...ProviderRuntimeEventBase.fields,
884 type: SessionConfiguredType,
885 payload: SessionConfiguredPayload,
886});
887export type ProviderRuntimeSessionConfiguredEvent =
888 typeof ProviderRuntimeSessionConfiguredEvent.Type;
889​
890const ProviderRuntimeSessionStateChangedEvent = Schema.Struct({
891 ...ProviderRuntimeEventBase.fields,
892 type: SessionStateChangedType,
893 payload: SessionStateChangedPayload,
894});
895export type ProviderRuntimeSessionStateChangedEvent =
896 typeof ProviderRuntimeSessionStateChangedEvent.Type;
897​
898const ProviderRuntimeSessionExitedEvent = Schema.Struct({
899 ...ProviderRuntimeEventBase.fields,
900 type: SessionExitedType,
901 payload: SessionExitedPayload,
902});
903export type ProviderRuntimeSessionExitedEvent = typeof ProviderRuntimeSessionExitedEvent.Type;
904​
905const ProviderRuntimeThreadStartedEvent = Schema.Struct({
906 ...ProviderRuntimeEventBase.fields,
907 type: ThreadStartedType,
908 payload: ThreadStartedPayload,
909});
910export type ProviderRuntimeThreadStartedEvent = typeof ProviderRuntimeThreadStartedEvent.Type;
911​
912const ProviderRuntimeThreadStateChangedEvent = Schema.Struct({
913 ...ProviderRuntimeEventBase.fields,
914 type: ThreadStateChangedType,
915 payload: ThreadStateChangedPayload,
916});
917export type ProviderRuntimeThreadStateChangedEvent =
918 typeof ProviderRuntimeThreadStateChangedEvent.Type;
919​
920const ProviderRuntimeThreadMetadataUpdatedEvent = Schema.Struct({
921 ...ProviderRuntimeEventBase.fields,
922 type: ThreadMetadataUpdatedType,
923 payload: ThreadMetadataUpdatedPayload,
924});
925export type ProviderRuntimeThreadMetadataUpdatedEvent =
926 typeof ProviderRuntimeThreadMetadataUpdatedEvent.Type;
927​
928const ProviderRuntimeThreadTokenUsageUpdatedEvent = Schema.Struct({
929 ...ProviderRuntimeEventBase.fields,
930 type: ThreadTokenUsageUpdatedType,
931 payload: ThreadTokenUsageUpdatedPayload,
932});
933export type ProviderRuntimeThreadTokenUsageUpdatedEvent =
934 typeof ProviderRuntimeThreadTokenUsageUpdatedEvent.Type;
935​
936const ProviderRuntimeThreadRealtimeStartedEvent = Schema.Struct({
937 ...ProviderRuntimeEventBase.fields,
938 type: ThreadRealtimeStartedType,
939 payload: ThreadRealtimeStartedPayload,
940});
941export type ProviderRuntimeThreadRealtimeStartedEvent =
942 typeof ProviderRuntimeThreadRealtimeStartedEvent.Type;
943​
944const ProviderRuntimeThreadRealtimeItemAddedEvent = Schema.Struct({
945 ...ProviderRuntimeEventBase.fields,
946 type: ThreadRealtimeItemAddedType,
947 payload: ThreadRealtimeItemAddedPayload,
948});
949export type ProviderRuntimeThreadRealtimeItemAddedEvent =
950 typeof ProviderRuntimeThreadRealtimeItemAddedEvent.Type;
951​
952const ProviderRuntimeThreadRealtimeAudioDeltaEvent = Schema.Struct({
953 ...ProviderRuntimeEventBase.fields,
954 type: ThreadRealtimeAudioDeltaType,
955 payload: ThreadRealtimeAudioDeltaPayload,
956});
957export type ProviderRuntimeThreadRealtimeAudioDeltaEvent =
958 typeof ProviderRuntimeThreadRealtimeAudioDeltaEvent.Type;
959​
960const ProviderRuntimeThreadRealtimeErrorEvent = Schema.Struct({
961 ...ProviderRuntimeEventBase.fields,
962 type: ThreadRealtimeErrorType,
963 payload: ThreadRealtimeErrorPayload,
964});
965export type ProviderRuntimeThreadRealtimeErrorEvent =
966 typeof ProviderRuntimeThreadRealtimeErrorEvent.Type;
967​
968const ProviderRuntimeThreadRealtimeClosedEvent = Schema.Struct({
969 ...ProviderRuntimeEventBase.fields,
970 type: ThreadRealtimeClosedType,
971 payload: ThreadRealtimeClosedPayload,
972});
973export type ProviderRuntimeThreadRealtimeClosedEvent =
974 typeof ProviderRuntimeThreadRealtimeClosedEvent.Type;
975​
976const ProviderRuntimeTurnStartedEvent = Schema.Struct({
977 ...ProviderRuntimeEventBase.fields,
978 type: TurnStartedType,
979 payload: TurnStartedPayload,
980});
981export type ProviderRuntimeTurnStartedEvent = typeof ProviderRuntimeTurnStartedEvent.Type;
982​
983const ProviderRuntimeTurnCompletedEvent = Schema.Struct({
984 ...ProviderRuntimeEventBase.fields,
985 type: TurnCompletedType,
986 payload: TurnCompletedPayload,
987});
988export type ProviderRuntimeTurnCompletedEvent = typeof ProviderRuntimeTurnCompletedEvent.Type;
989​
990const ProviderRuntimeTurnAbortedEvent = Schema.Struct({
991 ...ProviderRuntimeEventBase.fields,
992 type: TurnAbortedType,
993 payload: TurnAbortedPayload,
994});
995export type ProviderRuntimeTurnAbortedEvent = typeof ProviderRuntimeTurnAbortedEvent.Type;
996​
997const ProviderRuntimeTurnPlanUpdatedEvent = Schema.Struct({
998 ...ProviderRuntimeEventBase.fields,
999 type: TurnPlanUpdatedType,
1000 payload: TurnPlanUpdatedPayload,
1001});
1002export type ProviderRuntimeTurnPlanUpdatedEvent = typeof ProviderRuntimeTurnPlanUpdatedEvent.Type;
1003​
1004const ProviderRuntimeTurnProposedDeltaEvent = Schema.Struct({
1005 ...ProviderRuntimeEventBase.fields,
1006 type: TurnProposedDeltaType,
1007 payload: TurnProposedDeltaPayload,
1008});
1009export type ProviderRuntimeTurnProposedDeltaEvent =
1010 typeof ProviderRuntimeTurnProposedDeltaEvent.Type;
1011​
1012const ProviderRuntimeTurnProposedCompletedEvent = Schema.Struct({
1013 ...ProviderRuntimeEventBase.fields,
1014 type: TurnProposedCompletedType,
1015 payload: TurnProposedCompletedPayload,
1016});
1017export type ProviderRuntimeTurnProposedCompletedEvent =
1018 typeof ProviderRuntimeTurnProposedCompletedEvent.Type;
1019​
1020const ProviderRuntimeTurnDiffUpdatedEvent = Schema.Struct({
1021 ...ProviderRuntimeEventBase.fields,
1022 type: TurnDiffUpdatedType,
1023 payload: TurnDiffUpdatedPayload,
1024});
1025export type ProviderRuntimeTurnDiffUpdatedEvent = typeof ProviderRuntimeTurnDiffUpdatedEvent.Type;
1026​
1027const ProviderRuntimeItemStartedEvent = Schema.Struct({
1028 ...ProviderRuntimeEventBase.fields,
1029 type: ItemStartedType,
1030 payload: ItemLifecyclePayload,
1031});
1032export type ProviderRuntimeItemStartedEvent = typeof ProviderRuntimeItemStartedEvent.Type;
1033​
1034const ProviderRuntimeItemUpdatedEvent = Schema.Struct({
1035 ...ProviderRuntimeEventBase.fields,
1036 type: ItemUpdatedType,
1037 payload: ItemLifecyclePayload,
1038});
1039export type ProviderRuntimeItemUpdatedEvent = typeof ProviderRuntimeItemUpdatedEvent.Type;
1040​
1041const ProviderRuntimeItemCompletedEvent = Schema.Struct({
1042 ...ProviderRuntimeEventBase.fields,
1043 type: ItemCompletedType,
1044 payload: ItemLifecyclePayload,
1045});
1046export type ProviderRuntimeItemCompletedEvent = typeof ProviderRuntimeItemCompletedEvent.Type;
1047​
1048const ProviderRuntimeContentDeltaEvent = Schema.Struct({
1049 ...ProviderRuntimeEventBase.fields,
1050 type: ContentDeltaType,
1051 payload: ContentDeltaPayload,
1052});
1053export type ProviderRuntimeContentDeltaEvent = typeof ProviderRuntimeContentDeltaEvent.Type;
1054​
1055const ProviderRuntimeRequestOpenedEvent = Schema.Struct({
1056 ...ProviderRuntimeEventBase.fields,
1057 type: RequestOpenedType,
1058 payload: RequestOpenedPayload,
1059});
1060export type ProviderRuntimeRequestOpenedEvent = typeof ProviderRuntimeRequestOpenedEvent.Type;
1061​
1062const ProviderRuntimeRequestResolvedEvent = Schema.Struct({
1063 ...ProviderRuntimeEventBase.fields,
1064 type: RequestResolvedType,
1065 payload: RequestResolvedPayload,
1066});
1067export type ProviderRuntimeRequestResolvedEvent = typeof ProviderRuntimeRequestResolvedEvent.Type;
1068​
1069const ProviderRuntimeUserInputRequestedEvent = Schema.Struct({
1070 ...ProviderRuntimeEventBase.fields,
1071 type: UserInputRequestedType,
1072 payload: UserInputRequestedPayload,
1073});
1074export type ProviderRuntimeUserInputRequestedEvent =
1075 typeof ProviderRuntimeUserInputRequestedEvent.Type;
1076​
1077const ProviderRuntimeUserInputResolvedEvent = Schema.Struct({
1078 ...ProviderRuntimeEventBase.fields,
1079 type: UserInputResolvedType,
1080 payload: UserInputResolvedPayload,
1081});
1082export type ProviderRuntimeUserInputResolvedEvent =
1083 typeof ProviderRuntimeUserInputResolvedEvent.Type;
1084​
1085const ProviderRuntimeTaskStartedEvent = Schema.Struct({
1086 ...ProviderRuntimeEventBase.fields,
1087 type: TaskStartedType,
1088 payload: TaskStartedPayload,
1089});
1090export type ProviderRuntimeTaskStartedEvent = typeof ProviderRuntimeTaskStartedEvent.Type;
1091​
1092const ProviderRuntimeTaskProgressEvent = Schema.Struct({
1093 ...ProviderRuntimeEventBase.fields,
1094 type: TaskProgressType,
1095 payload: TaskProgressPayload,
1096});
1097export type ProviderRuntimeTaskProgressEvent = typeof ProviderRuntimeTaskProgressEvent.Type;
1098​
1099const ProviderRuntimeTaskUpdatedEvent = Schema.Struct({
1100 ...ProviderRuntimeEventBase.fields,
1101 type: TaskUpdatedType,
1102 payload: TaskUpdatedPayload,
1103});
1104export type ProviderRuntimeTaskUpdatedEvent = typeof ProviderRuntimeTaskUpdatedEvent.Type;
1105​
1106const ProviderRuntimeTaskCompletedEvent = Schema.Struct({
1107 ...ProviderRuntimeEventBase.fields,
1108 type: TaskCompletedType,
1109 payload: TaskCompletedPayload,
1110});
1111export type ProviderRuntimeTaskCompletedEvent = typeof ProviderRuntimeTaskCompletedEvent.Type;
1112​
1113const ProviderRuntimeHookStartedEvent = Schema.Struct({
1114 ...ProviderRuntimeEventBase.fields,
1115 type: HookStartedType,
1116 payload: HookStartedPayload,
1117});
1118export type ProviderRuntimeHookStartedEvent = typeof ProviderRuntimeHookStartedEvent.Type;
1119​
1120const ProviderRuntimeHookProgressEvent = Schema.Struct({
1121 ...ProviderRuntimeEventBase.fields,
1122 type: HookProgressType,
1123 payload: HookProgressPayload,
1124});
1125export type ProviderRuntimeHookProgressEvent = typeof ProviderRuntimeHookProgressEvent.Type;
1126​
1127const ProviderRuntimeHookCompletedEvent = Schema.Struct({
1128 ...ProviderRuntimeEventBase.fields,
1129 type: HookCompletedType,
1130 payload: HookCompletedPayload,
1131});
1132export type ProviderRuntimeHookCompletedEvent = typeof ProviderRuntimeHookCompletedEvent.Type;
1133​
1134const ProviderRuntimeToolProgressEvent = Schema.Struct({
1135 ...ProviderRuntimeEventBase.fields,
1136 type: ToolProgressType,
1137 payload: ToolProgressPayload,
1138});
1139export type ProviderRuntimeToolProgressEvent = typeof ProviderRuntimeToolProgressEvent.Type;
1140​
1141const ProviderRuntimeToolSummaryEvent = Schema.Struct({
1142 ...ProviderRuntimeEventBase.fields,
1143 type: ToolSummaryType,
1144 payload: ToolSummaryPayload,
1145});
1146export type ProviderRuntimeToolSummaryEvent = typeof ProviderRuntimeToolSummaryEvent.Type;
1147​
1148const ProviderRuntimeAuthStatusEvent = Schema.Struct({
1149 ...ProviderRuntimeEventBase.fields,
1150 type: AuthStatusType,
1151 payload: AuthStatusPayload,
1152});
1153export type ProviderRuntimeAuthStatusEvent = typeof ProviderRuntimeAuthStatusEvent.Type;
1154​
1155const ProviderRuntimeAccountUpdatedEvent = Schema.Struct({
1156 ...ProviderRuntimeEventBase.fields,
1157 type: AccountUpdatedType,
1158 payload: AccountUpdatedPayload,
1159});
1160export type ProviderRuntimeAccountUpdatedEvent = typeof ProviderRuntimeAccountUpdatedEvent.Type;
1161​
1162const ProviderRuntimeAccountRateLimitsUpdatedEvent = Schema.Struct({
1163 ...ProviderRuntimeEventBase.fields,
1164 type: AccountRateLimitsUpdatedType,
1165 payload: AccountRateLimitsUpdatedPayload,
1166});
1167export type ProviderRuntimeAccountRateLimitsUpdatedEvent =
1168 typeof ProviderRuntimeAccountRateLimitsUpdatedEvent.Type;
1169​
1170const ProviderRuntimeMcpStatusUpdatedEvent = Schema.Struct({
1171 ...ProviderRuntimeEventBase.fields,
1172 type: McpStatusUpdatedType,
1173 payload: McpStatusUpdatedPayload,
1174});
1175export type ProviderRuntimeMcpStatusUpdatedEvent = typeof ProviderRuntimeMcpStatusUpdatedEvent.Type;
1176​
1177const ProviderRuntimeMcpOauthCompletedEvent = Schema.Struct({
1178 ...ProviderRuntimeEventBase.fields,
1179 type: McpOauthCompletedType,
1180 payload: McpOauthCompletedPayload,
1181});
1182export type ProviderRuntimeMcpOauthCompletedEvent =
1183 typeof ProviderRuntimeMcpOauthCompletedEvent.Type;
1184​
1185const ProviderRuntimeModelReroutedEvent = Schema.Struct({
1186 ...ProviderRuntimeEventBase.fields,
1187 type: ModelReroutedType,
1188 payload: ModelReroutedPayload,
1189});
1190export type ProviderRuntimeModelReroutedEvent = typeof ProviderRuntimeModelReroutedEvent.Type;
1191​
1192const ProviderRuntimeConfigWarningEvent = Schema.Struct({
1193 ...ProviderRuntimeEventBase.fields,
1194 type: ConfigWarningType,
1195 payload: ConfigWarningPayload,
1196});
1197export type ProviderRuntimeConfigWarningEvent = typeof ProviderRuntimeConfigWarningEvent.Type;
1198​
1199const ProviderRuntimeDeprecationNoticeEvent = Schema.Struct({
1200 ...ProviderRuntimeEventBase.fields,
1201 type: DeprecationNoticeType,
1202 payload: DeprecationNoticePayload,
1203});
1204export type ProviderRuntimeDeprecationNoticeEvent =
1205 typeof ProviderRuntimeDeprecationNoticeEvent.Type;
1206​
1207const ProviderRuntimeFilesPersistedEvent = Schema.Struct({
1208 ...ProviderRuntimeEventBase.fields,
1209 type: FilesPersistedType,
1210 payload: FilesPersistedPayload,
1211});
1212export type ProviderRuntimeFilesPersistedEvent = typeof ProviderRuntimeFilesPersistedEvent.Type;
1213​
1214const ProviderRuntimeToolDeniedEvent = Schema.Struct({
1215 ...ProviderRuntimeEventBase.fields,
1216 type: ToolDeniedType,
1217 payload: ToolDeniedPayload,
1218});
1219export type ProviderRuntimeToolDeniedEvent = typeof ProviderRuntimeToolDeniedEvent.Type;
1220​
1221const ProviderRuntimeWarningEvent = Schema.Struct({
1222 ...ProviderRuntimeEventBase.fields,
1223 type: RuntimeWarningType,
1224 payload: RuntimeWarningPayload,
1225});
1226export type ProviderRuntimeWarningEvent = typeof ProviderRuntimeWarningEvent.Type;
1227​
1228const ProviderRuntimeErrorEvent = Schema.Struct({
1229 ...ProviderRuntimeEventBase.fields,
1230 type: RuntimeErrorType,
1231 payload: RuntimeErrorPayload,
1232});
1233export type ProviderRuntimeErrorEvent = typeof ProviderRuntimeErrorEvent.Type;
1234​
1235export const ProviderRuntimeEventV2 = Schema.Union([
1236 ProviderRuntimeSessionStartedEvent,
1237 ProviderRuntimeSessionConfiguredEvent,
1238 ProviderRuntimeSessionStateChangedEvent,
1239 ProviderRuntimeSessionExitedEvent,
1240 ProviderRuntimeThreadStartedEvent,
1241 ProviderRuntimeThreadStateChangedEvent,
1242 ProviderRuntimeThreadMetadataUpdatedEvent,
1243 ProviderRuntimeThreadTokenUsageUpdatedEvent,
1244 ProviderRuntimeThreadRealtimeStartedEvent,
1245 ProviderRuntimeThreadRealtimeItemAddedEvent,
1246 ProviderRuntimeThreadRealtimeAudioDeltaEvent,
1247 ProviderRuntimeThreadRealtimeErrorEvent,
1248 ProviderRuntimeThreadRealtimeClosedEvent,
1249 ProviderRuntimeTurnStartedEvent,
1250 ProviderRuntimeTurnCompletedEvent,
1251 ProviderRuntimeTurnAbortedEvent,
1252 ProviderRuntimeTurnPlanUpdatedEvent,
1253 ProviderRuntimeTurnProposedDeltaEvent,
1254 ProviderRuntimeTurnProposedCompletedEvent,
1255 ProviderRuntimeTurnDiffUpdatedEvent,
1256 ProviderRuntimeItemStartedEvent,
1257 ProviderRuntimeItemUpdatedEvent,
1258 ProviderRuntimeItemCompletedEvent,
1259 ProviderRuntimeContentDeltaEvent,
1260 ProviderRuntimeRequestOpenedEvent,
1261 ProviderRuntimeRequestResolvedEvent,
1262 ProviderRuntimeUserInputRequestedEvent,
1263 ProviderRuntimeUserInputResolvedEvent,
1264 ProviderRuntimeTaskStartedEvent,
1265 ProviderRuntimeTaskProgressEvent,
1266 ProviderRuntimeTaskUpdatedEvent,
1267 ProviderRuntimeTaskCompletedEvent,
1268 ProviderRuntimeHookStartedEvent,
1269 ProviderRuntimeHookProgressEvent,
1270 ProviderRuntimeHookCompletedEvent,
1271 ProviderRuntimeToolProgressEvent,
1272 ProviderRuntimeToolSummaryEvent,
1273 ProviderRuntimeAuthStatusEvent,
1274 ProviderRuntimeAccountUpdatedEvent,
1275 ProviderRuntimeAccountRateLimitsUpdatedEvent,
1276 ProviderRuntimeMcpStatusUpdatedEvent,
1277 ProviderRuntimeMcpOauthCompletedEvent,
1278 ProviderRuntimeModelReroutedEvent,
1279 ProviderRuntimeConfigWarningEvent,
1280 ProviderRuntimeDeprecationNoticeEvent,
1281 ProviderRuntimeFilesPersistedEvent,
1282 ProviderRuntimeToolDeniedEvent,
1283 ProviderRuntimeWarningEvent,
1284 ProviderRuntimeErrorEvent,
1285]);
1286export type ProviderRuntimeEventV2 = typeof ProviderRuntimeEventV2.Type;
1287​
1288export const ProviderRuntimeEvent = ProviderRuntimeEventV2;
1289export type ProviderRuntimeEvent = ProviderRuntimeEventV2;
1290​
1291export const ProviderRuntimeTurnStatus = RuntimeTurnState;
1292export type ProviderRuntimeTurnStatus = RuntimeTurnState;