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

providerRuntime.ts

1,294 lines47.8 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 "./orchestration.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});
333export type ThreadTokenUsageSnapshot = typeof ThreadTokenUsageSnapshot.Type;
334​
335const ThreadTokenUsageUpdatedPayload = Schema.Struct({
336 usage: ThreadTokenUsageSnapshot,
337});
338export type ThreadTokenUsageUpdatedPayload = typeof ThreadTokenUsageUpdatedPayload.Type;
339​
340const ThreadRealtimeStartedPayload = Schema.Struct({
341 realtimeSessionId: Schema.optional(TrimmedNonEmptyStringSchema),
342});
343export type ThreadRealtimeStartedPayload = typeof ThreadRealtimeStartedPayload.Type;
344​
345const ThreadRealtimeItemAddedPayload = Schema.Struct({
346 item: Schema.Unknown,
347});
348export type ThreadRealtimeItemAddedPayload = typeof ThreadRealtimeItemAddedPayload.Type;
349​
350const ThreadRealtimeAudioDeltaPayload = Schema.Struct({
351 audio: Schema.Unknown,
352});
353export type ThreadRealtimeAudioDeltaPayload = typeof ThreadRealtimeAudioDeltaPayload.Type;
354​
355const ThreadRealtimeErrorPayload = Schema.Struct({
356 message: TrimmedNonEmptyStringSchema,
357});
358export type ThreadRealtimeErrorPayload = typeof ThreadRealtimeErrorPayload.Type;
359​
360const ThreadRealtimeClosedPayload = Schema.Struct({
361 reason: Schema.optional(TrimmedNonEmptyStringSchema),
362});
363export type ThreadRealtimeClosedPayload = typeof ThreadRealtimeClosedPayload.Type;
364​
365const TurnStartedPayload = Schema.Struct({
366 model: Schema.optional(TrimmedNonEmptyStringSchema),
367 effort: Schema.optional(TrimmedNonEmptyStringSchema),
368});
369export type TurnStartedPayload = typeof TurnStartedPayload.Type;
370​
371/**
372 * Normalized main-agent usage for one turn. Input includes cache reads and
373 * writes. Output includes reasoning, and reasoningTokens is an optional subset.
374 * Complete means the provider supplied full input and output totals. Partial
375 * means every included count is valid, but the full turn total is not known.
376 */
377const TurnTokenUsageCommonFields = {
378 usageScope: Schema.Literal("main_agent"),
379 cachedInputTokens: Schema.optional(NonNegativeInt),
380 cacheCreationTokens: Schema.optional(NonNegativeInt),
381 reasoningTokens: Schema.optional(NonNegativeInt),
382 hasSubagents: Schema.Boolean,
383};
384export const TurnTokenUsage = Schema.Union([
385 Schema.Struct({
386 ...TurnTokenUsageCommonFields,
387 usageStatus: Schema.Literal("complete"),
388 inputTokens: NonNegativeInt,
389 outputTokens: NonNegativeInt,
390 }),
391 Schema.Struct({
392 ...TurnTokenUsageCommonFields,
393 usageStatus: Schema.Literals(["partial", "unavailable"]),
394 inputTokens: Schema.optional(NonNegativeInt),
395 outputTokens: Schema.optional(NonNegativeInt),
396 }),
397]);
398export type TurnTokenUsage = typeof TurnTokenUsage.Type;
399​
400/** Why a turn failed, for clients that render classes of failure differently. */
401export const RuntimeTurnFailureReason = Schema.Literals(["usage_limit"]);
402export type RuntimeTurnFailureReason = typeof RuntimeTurnFailureReason.Type;
403​
404const TurnCompletedPayload = Schema.Struct({
405 state: RuntimeTurnState,
406 stopReason: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
407 usage: Schema.optional(Schema.Unknown),
408 modelUsage: Schema.optional(UnknownRecordSchema),
409 totalCostUsd: Schema.optional(Schema.Number),
410 errorMessage: Schema.optional(TrimmedNonEmptyStringSchema),
411 failureReason: Schema.optional(RuntimeTurnFailureReason),
412 // When the blocking window resets, epoch millis. Only meaningful with
413 // failureReason "usage_limit".
414 failureResetsAt: Schema.optional(Schema.Number),
415 tokenUsage: Schema.optional(TurnTokenUsage),
416});
417export type TurnCompletedPayload = typeof TurnCompletedPayload.Type;
418​
419const TurnAbortedPayload = Schema.Struct({
420 reason: TrimmedNonEmptyStringSchema,
421 tokenUsage: Schema.optional(TurnTokenUsage),
422});
423export type TurnAbortedPayload = typeof TurnAbortedPayload.Type;
424​
425const RuntimePlanStep = Schema.Struct({
426 step: TrimmedNonEmptyStringSchema,
427 status: RuntimePlanStepStatus,
428});
429export type RuntimePlanStep = typeof RuntimePlanStep.Type;
430​
431const TurnPlanUpdatedPayload = Schema.Struct({
432 explanation: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
433 plan: Schema.Array(RuntimePlanStep),
434});
435export type TurnPlanUpdatedPayload = typeof TurnPlanUpdatedPayload.Type;
436​
437const TurnProposedDeltaPayload = Schema.Struct({
438 delta: Schema.String,
439});
440export type TurnProposedDeltaPayload = typeof TurnProposedDeltaPayload.Type;
441​
442const TurnProposedCompletedPayload = Schema.Struct({
443 planMarkdown: TrimmedNonEmptyStringSchema,
444});
445export type TurnProposedCompletedPayload = typeof TurnProposedCompletedPayload.Type;
446​
447const TurnDiffUpdatedPayload = Schema.Struct({
448 unifiedDiff: Schema.String,
449});
450export type TurnDiffUpdatedPayload = typeof TurnDiffUpdatedPayload.Type;
451​
452export const ToolActivitySurface = Schema.Literals(["browser", "computer"]);
453export type ToolActivitySurface = typeof ToolActivitySurface.Type;
454​
455export const ToolActivityNativeAppReference = Schema.Union([
456 Schema.TaggedStruct("app-id", {
457 appId: TrimmedNonEmptyStringSchema.check(
458 Schema.isMaxLength(512),
459 Schema.isPattern(/^[A-Za-z0-9._-]+$/u),
460 ),
461 }),
462 Schema.TaggedStruct("display-name", {
463 displayName: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(160)),
464 }),
465]);
466export type ToolActivityNativeAppReference = typeof ToolActivityNativeAppReference.Type;
467​
468export const ToolActivityIcon = Schema.Union([
469 Schema.TaggedStruct("website", {
470 pageUrl: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096)),
471 faviconUrl: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096))),
472 faviconUrlDark: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096))),
473 }),
474 Schema.TaggedStruct("native-app", {
475 app: ToolActivityNativeAppReference,
476 }),
477 Schema.TaggedStruct("themed-logo", {
478 logoUrl: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096)),
479 logoUrlDark: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(4096))),
480 }),
481]);
482export type ToolActivityIcon = typeof ToolActivityIcon.Type;
483​
484export const ToolActivitySource = Schema.Struct({
485 key: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(512)),
486 name: TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(160)),
487 kind: Schema.Literals(["browser", "computer", "integration"]),
488 icon: Schema.optional(ToolActivityIcon),
489});
490export type ToolActivitySource = typeof ToolActivitySource.Type;
491​
492export const ItemLifecyclePayload = Schema.Struct({
493 itemType: CanonicalItemType,
494 status: Schema.optional(RuntimeItemStatus),
495 title: Schema.optional(TrimmedNonEmptyStringSchema),
496 detail: Schema.optional(TrimmedNonEmptyStringSchema),
497 toolSurface: Schema.optional(ToolActivitySurface),
498 toolIcon: Schema.optional(ToolActivityIcon),
499 toolSource: Schema.optional(ToolActivitySource),
500 data: Schema.optional(Schema.Unknown),
501 /**
502 * Owning agent when this item ran inside a subagent (resolved from the
503 * SDK's parent_tool_use_id). Clients re-home attributed items out of the
504 * main timeline and into the owning agent's Agents-surface row.
505 */
506 agentId: Schema.optional(TrimmedNonEmptyStringSchema),
507 parentToolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
508});
509export type ItemLifecyclePayload = typeof ItemLifecyclePayload.Type;
510​
511const ContentDeltaPayload = Schema.Struct({
512 streamKind: RuntimeContentStreamKind,
513 delta: Schema.String,
514 contentIndex: Schema.optional(Schema.Int),
515 summaryIndex: Schema.optional(Schema.Int),
516});
517export type ContentDeltaPayload = typeof ContentDeltaPayload.Type;
518​
519const RequestOpenedPayload = Schema.Struct({
520 requestType: CanonicalRequestType,
521 detail: Schema.optional(TrimmedNonEmptyStringSchema),
522 appName: Schema.optional(TrimmedNonEmptyStringSchema),
523 options: Schema.optional(Schema.Array(ProviderApprovalOption)),
524 args: Schema.optional(Schema.Unknown),
525});
526export type RequestOpenedPayload = typeof RequestOpenedPayload.Type;
527​
528const RequestResolvedPayload = Schema.Struct({
529 requestType: CanonicalRequestType,
530 decision: Schema.optional(TrimmedNonEmptyStringSchema),
531 resolution: Schema.optional(Schema.Unknown),
532});
533export type RequestResolvedPayload = typeof RequestResolvedPayload.Type;
534​
535const UserInputQuestionOption = Schema.Struct({
536 label: TrimmedNonEmptyStringSchema,
537 description: Schema.String,
538 value: Schema.optional(Schema.String),
539});
540export type UserInputQuestionOption = typeof UserInputQuestionOption.Type;
541​
542export const UserInputQuestion = Schema.Struct({
543 id: TrimmedNonEmptyStringSchema,
544 header: TrimmedNonEmptyStringSchema,
545 question: TrimmedNonEmptyStringSchema,
546 options: Schema.Array(UserInputQuestionOption),
547 allowCustomAnswer: Schema.optional(Schema.Boolean),
548 multiSelect: Schema.optional(Schema.Boolean).pipe(
549 Schema.withConstructorDefault(Effect.succeed(false)),
550 ),
551});
552export type UserInputQuestion = typeof UserInputQuestion.Type;
553​
554export const UserInputRequestedPayload = Schema.Struct({
555 questions: Schema.Array(UserInputQuestion),
556 responseMode: Schema.optional(Schema.Literal("message")),
557});
558export type UserInputRequestedPayload = typeof UserInputRequestedPayload.Type;
559​
560const UserInputResolvedPayload = Schema.Struct({
561 answers: UnknownRecordSchema,
562});
563export type UserInputResolvedPayload = typeof UserInputResolvedPayload.Type;
564​
565/**
566 * Typed per-task usage rollup. Field names match the orchestration-v2 subagent
567 * usage vocabulary (#4779) so the eventual migration is a rename, not a remap.
568 * Claude reports per-activation deltas; Codex reports cumulative totals — the
569 * merge strategy is provider-specific and lives in client-runtime.
570 */
571export const RuntimeTaskUsage = Schema.Struct({
572 totalTokens: NonNegativeInt,
573 inputTokens: Schema.optional(NonNegativeInt),
574 cachedInputTokens: Schema.optional(NonNegativeInt),
575 outputTokens: Schema.optional(NonNegativeInt),
576 reasoningOutputTokens: Schema.optional(NonNegativeInt),
577 toolUses: Schema.optional(NonNegativeInt),
578 durationMs: Schema.optional(NonNegativeInt),
579});
580export type RuntimeTaskUsage = typeof RuntimeTaskUsage.Type;
581​
582export const TaskWorkflowPhase = Schema.Struct({
583 index: NonNegativeInt,
584 title: TrimmedNonEmptyStringSchema,
585});
586export type TaskWorkflowPhase = typeof TaskWorkflowPhase.Type;
587​
588export const TaskRunHandles = Schema.Struct({
589 runId: Schema.optional(TrimmedNonEmptyStringSchema),
590 scriptPath: Schema.optional(TrimmedNonEmptyStringSchema),
591 transcriptDir: Schema.optional(TrimmedNonEmptyStringSchema),
592 /** Only http/https URLs may be stored here — sanitized at the adapter. */
593 sessionUrl: Schema.optional(TrimmedNonEmptyStringSchema),
594});
595export type TaskRunHandles = typeof TaskRunHandles.Type;
596​
597/**
598 * Watch-loop task types: Monitor-tool tasks plus background shells (a shell
599 * that outlives its turn is in practice a watch loop). Canonical single copy —
600 * the server liveness registry, ingestion's agentKind stamp, and the client
601 * fold's legacy fallback all classify with these sets.
602 */
603export const MONITOR_TASK_TYPES: ReadonlySet<string> = new Set([
604 "monitor",
605 "monitor_mcp",
606 "local_bash",
607 "shell",
608]);
609/** Task types that are neither agents nor watch loops (plan-mode bookkeeping). */
610export const INERT_TASK_TYPES: ReadonlySet<string> = new Set(["plan", "dream"]);
611​
612/**
613 * Agent-vs-background classification, stamped by ingestion as `agentKind` so
614 * persisted rows are self-describing. A deliberate denylist: the SDK's
615 * agent-flavored type names drift (subagent, local_agent, local_workflow, …)
616 * and an allowlist silently dropped real subagents when "local_agent"
617 * appeared. A task launched from inside a subagent (agentId set) is
618 * agent-internal background work UNLESS it is itself agent-flavored — a
619 * nested agent can outlive its parent and stays in the roster.
620 */
621export function classifyTaskAgentKind(input: {
622 readonly taskType?: string | undefined;
623 readonly agentId?: string | undefined;
624}): "agent" | "background" {
625 const { taskType, agentId } = input;
626 const nonAgentType =
627 taskType !== undefined && (MONITOR_TASK_TYPES.has(taskType) || INERT_TASK_TYPES.has(taskType));
628 if (agentId !== undefined && agentId.trim().length > 0) {
629 return taskType === undefined || nonAgentType ? "background" : "agent";
630 }
631 return nonAgentType ? "background" : "agent";
633​
634/**
635 * Optional agent-identity linkage carried on every task lifecycle payload.
636 * Repeated on progress and terminal rows (not just start) so client folds can
637 * reconstruct an agent even when its start row aged out of activity retention.
638 * All fields optional: old emitters and old rows decode unchanged.
639 */
640const taskAgentLinkageFields = {
641 /** SDK task_type (subagent/shell/monitor/local_workflow/…), repeated on
642 * every row so folds can classify without the start row. */
643 taskType: Schema.optional(TrimmedNonEmptyStringSchema),
644 /**
645 * Server-stamped classification (classifyTaskAgentKind at ingestion).
646 * Clients trust this stamp outright; rows without it (legacy, pre-stamp)
647 * fall back to client-side heuristics.
648 */
649 agentKind: Schema.optional(Schema.Literals(["agent", "background"])),
650 /**
651 * Owning agent when the task itself was launched from inside a subagent
652 * (e.g. a subagent's background shell). Clients treat such tasks as
653 * agent-internal and keep them out of the parent work log.
654 */
655 agentId: Schema.optional(TrimmedNonEmptyStringSchema),
656 title: Schema.optional(TrimmedNonEmptyStringSchema),
657 role: Schema.optional(TrimmedNonEmptyStringSchema),
658 model: Schema.optional(TrimmedNonEmptyStringSchema),
659 /** Reasoning effort when known (e.g. "high"). Open string: provider vocabularies differ. */
660 effort: Schema.optional(TrimmedNonEmptyStringSchema),
661 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
662 parentAgentId: Schema.optional(TrimmedNonEmptyStringSchema),
663 workflowName: Schema.optional(TrimmedNonEmptyStringSchema),
664 agentIndex: Schema.optional(NonNegativeInt),
665 phaseIndex: Schema.optional(NonNegativeInt),
666 phaseTitle: Schema.optional(TrimmedNonEmptyStringSchema),
667 phases: Schema.optional(Schema.Array(TaskWorkflowPhase)),
668 attempt: Schema.optional(NonNegativeInt),
669 runHandles: Schema.optional(TaskRunHandles),
670 outputFile: Schema.optional(TrimmedNonEmptyStringSchema),
671 /** Codex agent hierarchy path, e.g. "/root/marlow". */
672 agentPath: Schema.optional(TrimmedNonEmptyStringSchema),
673 /**
674 * Set on provider-synthesized child-agent events (Codex) whose activity
675 * belongs in the Agents surface, never the parent timeline.
676 */
677 timelineBypass: Schema.optional(Schema.Boolean),
678} as const;
679​
680export const TaskAgentLinkage = Schema.Struct(taskAgentLinkageFields);
681export type TaskAgentLinkage = typeof TaskAgentLinkage.Type;
682​
683const TaskStartedPayload = Schema.Struct({
684 taskId: RuntimeTaskId,
685 description: Schema.optional(TrimmedNonEmptyStringSchema),
686 ...taskAgentLinkageFields,
687});
688export type TaskStartedPayload = typeof TaskStartedPayload.Type;
689​
690export const RuntimeTaskStatus = Schema.Literals([
691 "pending",
692 "running",
693 "waiting",
694 "idle",
695 "completed",
696 "failed",
697 "cancelled",
698 "interrupted",
699]);
700export type RuntimeTaskStatus = typeof RuntimeTaskStatus.Type;
701​
702const TaskProgressPayload = Schema.Struct({
703 taskId: RuntimeTaskId,
704 description: TrimmedNonEmptyStringSchema,
705 summary: Schema.optional(TrimmedNonEmptyStringSchema),
706 usage: Schema.optional(Schema.Unknown),
707 typedUsage: Schema.optional(RuntimeTaskUsage),
708 lastToolName: Schema.optional(TrimmedNonEmptyStringSchema),
709 /** Present on synthesized member/child progress rows that carry state. */
710 status: Schema.optional(RuntimeTaskStatus),
711 error: Schema.optional(TrimmedNonEmptyStringSchema),
712 ...taskAgentLinkageFields,
713});
714export type TaskProgressPayload = typeof TaskProgressPayload.Type;
715​
716/**
717 * Non-terminal status patch (from the Claude SDK's task_updated, which main
718 * previously dropped). killed→cancelled and paused→idle are mapped at the
719 * adapter so the wire only carries the shared vocabulary.
720 */
721const TaskUpdatedPayload = Schema.Struct({
722 taskId: RuntimeTaskId,
723 status: Schema.optional(RuntimeTaskStatus),
724 description: Schema.optional(TrimmedNonEmptyStringSchema),
725 error: Schema.optional(TrimmedNonEmptyStringSchema),
726 endedAt: Schema.optional(IsoDateTime),
727 isBackgrounded: Schema.optional(Schema.Boolean),
728 ...taskAgentLinkageFields,
729});
730export type TaskUpdatedPayload = typeof TaskUpdatedPayload.Type;
731​
732const TaskCompletedPayload = Schema.Struct({
733 taskId: RuntimeTaskId,
734 status: Schema.Literals(["completed", "failed", "stopped"]),
735 summary: Schema.optional(TrimmedNonEmptyStringSchema),
736 usage: Schema.optional(Schema.Unknown),
737 typedUsage: Schema.optional(RuntimeTaskUsage),
738 ...taskAgentLinkageFields,
739});
740export type TaskCompletedPayload = typeof TaskCompletedPayload.Type;
741​
742const HookStartedPayload = Schema.Struct({
743 hookId: TrimmedNonEmptyStringSchema,
744 hookName: TrimmedNonEmptyStringSchema,
745 hookEvent: TrimmedNonEmptyStringSchema,
746});
747export type HookStartedPayload = typeof HookStartedPayload.Type;
748​
749const HookProgressPayload = Schema.Struct({
750 hookId: TrimmedNonEmptyStringSchema,
751 output: Schema.optional(Schema.String),
752 stdout: Schema.optional(Schema.String),
753 stderr: Schema.optional(Schema.String),
754});
755export type HookProgressPayload = typeof HookProgressPayload.Type;
756​
757const HookCompletedPayload = Schema.Struct({
758 hookId: TrimmedNonEmptyStringSchema,
759 outcome: Schema.Literals(["success", "error", "cancelled"]),
760 output: Schema.optional(Schema.String),
761 stdout: Schema.optional(Schema.String),
762 stderr: Schema.optional(Schema.String),
763 exitCode: Schema.optional(Schema.Int),
764});
765export type HookCompletedPayload = typeof HookCompletedPayload.Type;
766​
767const ToolProgressPayload = Schema.Struct({
768 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
769 toolName: Schema.optional(TrimmedNonEmptyStringSchema),
770 summary: Schema.optional(TrimmedNonEmptyStringSchema),
771 elapsedSeconds: Schema.optional(Schema.Number),
772 /** Owning task/agent when the tool ran inside a subagent. */
773 taskId: Schema.optional(RuntimeTaskId),
774 parentToolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
775});
776export type ToolProgressPayload = typeof ToolProgressPayload.Type;
777​
778const ToolSummaryPayload = Schema.Struct({
779 summary: TrimmedNonEmptyStringSchema,
780 precedingToolUseIds: Schema.optional(Schema.Array(TrimmedNonEmptyStringSchema)),
781});
782export type ToolSummaryPayload = typeof ToolSummaryPayload.Type;
783​
784const AuthStatusPayload = Schema.Struct({
785 isAuthenticating: Schema.optional(Schema.Boolean),
786 output: Schema.optional(Schema.Array(Schema.String)),
787 error: Schema.optional(TrimmedNonEmptyStringSchema),
788});
789export type AuthStatusPayload = typeof AuthStatusPayload.Type;
790​
791const AccountUpdatedPayload = Schema.Struct({
792 account: Schema.Unknown,
793});
794export type AccountUpdatedPayload = typeof AccountUpdatedPayload.Type;
795​
796/**
797 * Adapters normalise their native rate-limit payload at the boundary so the
798 * consumer that folds it into the provider snapshot never sees driver shapes.
799 */
800const AccountRateLimitsUpdatedPayload = Schema.Struct({
801 limits: ProviderUsageLimitsUpdate,
802});
803export type AccountRateLimitsUpdatedPayload = typeof AccountRateLimitsUpdatedPayload.Type;
804​
805const McpStatusUpdatedPayload = Schema.Struct({
806 status: Schema.Unknown,
807});
808export type McpStatusUpdatedPayload = typeof McpStatusUpdatedPayload.Type;
809​
810const McpOauthCompletedPayload = Schema.Struct({
811 success: Schema.Boolean,
812 name: Schema.optional(TrimmedNonEmptyStringSchema),
813 error: Schema.optional(TrimmedNonEmptyStringSchema),
814});
815export type McpOauthCompletedPayload = typeof McpOauthCompletedPayload.Type;
816​
817const ModelReroutedPayload = Schema.Struct({
818 fromModel: TrimmedNonEmptyStringSchema,
819 toModel: TrimmedNonEmptyStringSchema,
820 reason: TrimmedNonEmptyStringSchema,
821});
822export type ModelReroutedPayload = typeof ModelReroutedPayload.Type;
823​
824const ConfigWarningPayload = Schema.Struct({
825 summary: TrimmedNonEmptyStringSchema,
826 details: Schema.optional(TrimmedNonEmptyStringSchema),
827 path: Schema.optional(TrimmedNonEmptyStringSchema),
828 range: Schema.optional(Schema.Unknown),
829});
830export type ConfigWarningPayload = typeof ConfigWarningPayload.Type;
831​
832const DeprecationNoticePayload = Schema.Struct({
833 summary: TrimmedNonEmptyStringSchema,
834 details: Schema.optional(TrimmedNonEmptyStringSchema),
835});
836export type DeprecationNoticePayload = typeof DeprecationNoticePayload.Type;
837​
838const FilesPersistedPayload = Schema.Struct({
839 files: Schema.Array(
840 Schema.Struct({
841 filename: TrimmedNonEmptyStringSchema,
842 fileId: TrimmedNonEmptyStringSchema,
843 }),
844 ),
845 failed: Schema.optional(
846 Schema.Array(
847 Schema.Struct({
848 filename: TrimmedNonEmptyStringSchema,
849 error: TrimmedNonEmptyStringSchema,
850 }),
851 ),
852 ),
853});
854export type FilesPersistedPayload = typeof FilesPersistedPayload.Type;
855​
856const ToolDeniedPayload = Schema.Struct({
857 toolName: TrimmedNonEmptyStringSchema,
858 toolUseId: Schema.optional(TrimmedNonEmptyStringSchema),
859 reason: Schema.optional(TrimmedNonEmptyStringSchema),
860 agentId: Schema.optional(TrimmedNonEmptyStringSchema),
861});
862export type ToolDeniedPayload = typeof ToolDeniedPayload.Type;
863​
864const RuntimeWarningPayload = Schema.Struct({
865 message: TrimmedNonEmptyStringSchema,
866 detail: Schema.optional(Schema.Unknown),
867});
868export type RuntimeWarningPayload = typeof RuntimeWarningPayload.Type;
869​
870const RuntimeErrorPayload = Schema.Struct({
871 message: TrimmedNonEmptyStringSchema,
872 class: Schema.optional(RuntimeErrorClass),
873 detail: Schema.optional(Schema.Unknown),
874});
875export type RuntimeErrorPayload = typeof RuntimeErrorPayload.Type;
876​
877const ProviderRuntimeSessionStartedEvent = Schema.Struct({
878 ...ProviderRuntimeEventBase.fields,
879 type: SessionStartedType,
880 payload: SessionStartedPayload,
881});
882export type ProviderRuntimeSessionStartedEvent = typeof ProviderRuntimeSessionStartedEvent.Type;
883​
884const ProviderRuntimeSessionConfiguredEvent = Schema.Struct({
885 ...ProviderRuntimeEventBase.fields,
886 type: SessionConfiguredType,
887 payload: SessionConfiguredPayload,
888});
889export type ProviderRuntimeSessionConfiguredEvent =
890 typeof ProviderRuntimeSessionConfiguredEvent.Type;
891​
892const ProviderRuntimeSessionStateChangedEvent = Schema.Struct({
893 ...ProviderRuntimeEventBase.fields,
894 type: SessionStateChangedType,
895 payload: SessionStateChangedPayload,
896});
897export type ProviderRuntimeSessionStateChangedEvent =
898 typeof ProviderRuntimeSessionStateChangedEvent.Type;
899​
900const ProviderRuntimeSessionExitedEvent = Schema.Struct({
901 ...ProviderRuntimeEventBase.fields,
902 type: SessionExitedType,
903 payload: SessionExitedPayload,
904});
905export type ProviderRuntimeSessionExitedEvent = typeof ProviderRuntimeSessionExitedEvent.Type;
906​
907const ProviderRuntimeThreadStartedEvent = Schema.Struct({
908 ...ProviderRuntimeEventBase.fields,
909 type: ThreadStartedType,
910 payload: ThreadStartedPayload,
911});
912export type ProviderRuntimeThreadStartedEvent = typeof ProviderRuntimeThreadStartedEvent.Type;
913​
914const ProviderRuntimeThreadStateChangedEvent = Schema.Struct({
915 ...ProviderRuntimeEventBase.fields,
916 type: ThreadStateChangedType,
917 payload: ThreadStateChangedPayload,
918});
919export type ProviderRuntimeThreadStateChangedEvent =
920 typeof ProviderRuntimeThreadStateChangedEvent.Type;
921​
922const ProviderRuntimeThreadMetadataUpdatedEvent = Schema.Struct({
923 ...ProviderRuntimeEventBase.fields,
924 type: ThreadMetadataUpdatedType,
925 payload: ThreadMetadataUpdatedPayload,
926});
927export type ProviderRuntimeThreadMetadataUpdatedEvent =
928 typeof ProviderRuntimeThreadMetadataUpdatedEvent.Type;
929​
930const ProviderRuntimeThreadTokenUsageUpdatedEvent = Schema.Struct({
931 ...ProviderRuntimeEventBase.fields,
932 type: ThreadTokenUsageUpdatedType,
933 payload: ThreadTokenUsageUpdatedPayload,
934});
935export type ProviderRuntimeThreadTokenUsageUpdatedEvent =
936 typeof ProviderRuntimeThreadTokenUsageUpdatedEvent.Type;
937​
938const ProviderRuntimeThreadRealtimeStartedEvent = Schema.Struct({
939 ...ProviderRuntimeEventBase.fields,
940 type: ThreadRealtimeStartedType,
941 payload: ThreadRealtimeStartedPayload,
942});
943export type ProviderRuntimeThreadRealtimeStartedEvent =
944 typeof ProviderRuntimeThreadRealtimeStartedEvent.Type;
945​
946const ProviderRuntimeThreadRealtimeItemAddedEvent = Schema.Struct({
947 ...ProviderRuntimeEventBase.fields,
948 type: ThreadRealtimeItemAddedType,
949 payload: ThreadRealtimeItemAddedPayload,
950});
951export type ProviderRuntimeThreadRealtimeItemAddedEvent =
952 typeof ProviderRuntimeThreadRealtimeItemAddedEvent.Type;
953​
954const ProviderRuntimeThreadRealtimeAudioDeltaEvent = Schema.Struct({
955 ...ProviderRuntimeEventBase.fields,
956 type: ThreadRealtimeAudioDeltaType,
957 payload: ThreadRealtimeAudioDeltaPayload,
958});
959export type ProviderRuntimeThreadRealtimeAudioDeltaEvent =
960 typeof ProviderRuntimeThreadRealtimeAudioDeltaEvent.Type;
961​
962const ProviderRuntimeThreadRealtimeErrorEvent = Schema.Struct({
963 ...ProviderRuntimeEventBase.fields,
964 type: ThreadRealtimeErrorType,
965 payload: ThreadRealtimeErrorPayload,
966});
967export type ProviderRuntimeThreadRealtimeErrorEvent =
968 typeof ProviderRuntimeThreadRealtimeErrorEvent.Type;
969​
970const ProviderRuntimeThreadRealtimeClosedEvent = Schema.Struct({
971 ...ProviderRuntimeEventBase.fields,
972 type: ThreadRealtimeClosedType,
973 payload: ThreadRealtimeClosedPayload,
974});
975export type ProviderRuntimeThreadRealtimeClosedEvent =
976 typeof ProviderRuntimeThreadRealtimeClosedEvent.Type;
977​
978const ProviderRuntimeTurnStartedEvent = Schema.Struct({
979 ...ProviderRuntimeEventBase.fields,
980 type: TurnStartedType,
981 payload: TurnStartedPayload,
982});
983export type ProviderRuntimeTurnStartedEvent = typeof ProviderRuntimeTurnStartedEvent.Type;
984​
985const ProviderRuntimeTurnCompletedEvent = Schema.Struct({
986 ...ProviderRuntimeEventBase.fields,
987 type: TurnCompletedType,
988 payload: TurnCompletedPayload,
989});
990export type ProviderRuntimeTurnCompletedEvent = typeof ProviderRuntimeTurnCompletedEvent.Type;
991​
992const ProviderRuntimeTurnAbortedEvent = Schema.Struct({
993 ...ProviderRuntimeEventBase.fields,
994 type: TurnAbortedType,
995 payload: TurnAbortedPayload,
996});
997export type ProviderRuntimeTurnAbortedEvent = typeof ProviderRuntimeTurnAbortedEvent.Type;
998​
999const ProviderRuntimeTurnPlanUpdatedEvent = Schema.Struct({
1000 ...ProviderRuntimeEventBase.fields,
1001 type: TurnPlanUpdatedType,
1002 payload: TurnPlanUpdatedPayload,
1003});
1004export type ProviderRuntimeTurnPlanUpdatedEvent = typeof ProviderRuntimeTurnPlanUpdatedEvent.Type;
1005​
1006const ProviderRuntimeTurnProposedDeltaEvent = Schema.Struct({
1007 ...ProviderRuntimeEventBase.fields,
1008 type: TurnProposedDeltaType,
1009 payload: TurnProposedDeltaPayload,
1010});
1011export type ProviderRuntimeTurnProposedDeltaEvent =
1012 typeof ProviderRuntimeTurnProposedDeltaEvent.Type;
1013​
1014const ProviderRuntimeTurnProposedCompletedEvent = Schema.Struct({
1015 ...ProviderRuntimeEventBase.fields,
1016 type: TurnProposedCompletedType,
1017 payload: TurnProposedCompletedPayload,
1018});
1019export type ProviderRuntimeTurnProposedCompletedEvent =
1020 typeof ProviderRuntimeTurnProposedCompletedEvent.Type;
1021​
1022const ProviderRuntimeTurnDiffUpdatedEvent = Schema.Struct({
1023 ...ProviderRuntimeEventBase.fields,
1024 type: TurnDiffUpdatedType,
1025 payload: TurnDiffUpdatedPayload,
1026});
1027export type ProviderRuntimeTurnDiffUpdatedEvent = typeof ProviderRuntimeTurnDiffUpdatedEvent.Type;
1028​
1029const ProviderRuntimeItemStartedEvent = Schema.Struct({
1030 ...ProviderRuntimeEventBase.fields,
1031 type: ItemStartedType,
1032 payload: ItemLifecyclePayload,
1033});
1034export type ProviderRuntimeItemStartedEvent = typeof ProviderRuntimeItemStartedEvent.Type;
1035​
1036const ProviderRuntimeItemUpdatedEvent = Schema.Struct({
1037 ...ProviderRuntimeEventBase.fields,
1038 type: ItemUpdatedType,
1039 payload: ItemLifecyclePayload,
1040});
1041export type ProviderRuntimeItemUpdatedEvent = typeof ProviderRuntimeItemUpdatedEvent.Type;
1042​
1043const ProviderRuntimeItemCompletedEvent = Schema.Struct({
1044 ...ProviderRuntimeEventBase.fields,
1045 type: ItemCompletedType,
1046 payload: ItemLifecyclePayload,
1047});
1048export type ProviderRuntimeItemCompletedEvent = typeof ProviderRuntimeItemCompletedEvent.Type;
1049​
1050const ProviderRuntimeContentDeltaEvent = Schema.Struct({
1051 ...ProviderRuntimeEventBase.fields,
1052 type: ContentDeltaType,
1053 payload: ContentDeltaPayload,
1054});
1055export type ProviderRuntimeContentDeltaEvent = typeof ProviderRuntimeContentDeltaEvent.Type;
1056​
1057const ProviderRuntimeRequestOpenedEvent = Schema.Struct({
1058 ...ProviderRuntimeEventBase.fields,
1059 type: RequestOpenedType,
1060 payload: RequestOpenedPayload,
1061});
1062export type ProviderRuntimeRequestOpenedEvent = typeof ProviderRuntimeRequestOpenedEvent.Type;
1063​
1064const ProviderRuntimeRequestResolvedEvent = Schema.Struct({
1065 ...ProviderRuntimeEventBase.fields,
1066 type: RequestResolvedType,
1067 payload: RequestResolvedPayload,
1068});
1069export type ProviderRuntimeRequestResolvedEvent = typeof ProviderRuntimeRequestResolvedEvent.Type;
1070​
1071const ProviderRuntimeUserInputRequestedEvent = Schema.Struct({
1072 ...ProviderRuntimeEventBase.fields,
1073 type: UserInputRequestedType,
1074 payload: UserInputRequestedPayload,
1075});
1076export type ProviderRuntimeUserInputRequestedEvent =
1077 typeof ProviderRuntimeUserInputRequestedEvent.Type;
1078​
1079const ProviderRuntimeUserInputResolvedEvent = Schema.Struct({
1080 ...ProviderRuntimeEventBase.fields,
1081 type: UserInputResolvedType,
1082 payload: UserInputResolvedPayload,
1083});
1084export type ProviderRuntimeUserInputResolvedEvent =
1085 typeof ProviderRuntimeUserInputResolvedEvent.Type;
1086​
1087const ProviderRuntimeTaskStartedEvent = Schema.Struct({
1088 ...ProviderRuntimeEventBase.fields,
1089 type: TaskStartedType,
1090 payload: TaskStartedPayload,
1091});
1092export type ProviderRuntimeTaskStartedEvent = typeof ProviderRuntimeTaskStartedEvent.Type;
1093​
1094const ProviderRuntimeTaskProgressEvent = Schema.Struct({
1095 ...ProviderRuntimeEventBase.fields,
1096 type: TaskProgressType,
1097 payload: TaskProgressPayload,
1098});
1099export type ProviderRuntimeTaskProgressEvent = typeof ProviderRuntimeTaskProgressEvent.Type;
1100​
1101const ProviderRuntimeTaskUpdatedEvent = Schema.Struct({
1102 ...ProviderRuntimeEventBase.fields,
1103 type: TaskUpdatedType,
1104 payload: TaskUpdatedPayload,
1105});
1106export type ProviderRuntimeTaskUpdatedEvent = typeof ProviderRuntimeTaskUpdatedEvent.Type;
1107​
1108const ProviderRuntimeTaskCompletedEvent = Schema.Struct({
1109 ...ProviderRuntimeEventBase.fields,
1110 type: TaskCompletedType,
1111 payload: TaskCompletedPayload,
1112});
1113export type ProviderRuntimeTaskCompletedEvent = typeof ProviderRuntimeTaskCompletedEvent.Type;
1114​
1115const ProviderRuntimeHookStartedEvent = Schema.Struct({
1116 ...ProviderRuntimeEventBase.fields,
1117 type: HookStartedType,
1118 payload: HookStartedPayload,
1119});
1120export type ProviderRuntimeHookStartedEvent = typeof ProviderRuntimeHookStartedEvent.Type;
1121​
1122const ProviderRuntimeHookProgressEvent = Schema.Struct({
1123 ...ProviderRuntimeEventBase.fields,
1124 type: HookProgressType,
1125 payload: HookProgressPayload,
1126});
1127export type ProviderRuntimeHookProgressEvent = typeof ProviderRuntimeHookProgressEvent.Type;
1128​
1129const ProviderRuntimeHookCompletedEvent = Schema.Struct({
1130 ...ProviderRuntimeEventBase.fields,
1131 type: HookCompletedType,
1132 payload: HookCompletedPayload,
1133});
1134export type ProviderRuntimeHookCompletedEvent = typeof ProviderRuntimeHookCompletedEvent.Type;
1135​
1136const ProviderRuntimeToolProgressEvent = Schema.Struct({
1137 ...ProviderRuntimeEventBase.fields,
1138 type: ToolProgressType,
1139 payload: ToolProgressPayload,
1140});
1141export type ProviderRuntimeToolProgressEvent = typeof ProviderRuntimeToolProgressEvent.Type;
1142​
1143const ProviderRuntimeToolSummaryEvent = Schema.Struct({
1144 ...ProviderRuntimeEventBase.fields,
1145 type: ToolSummaryType,
1146 payload: ToolSummaryPayload,
1147});
1148export type ProviderRuntimeToolSummaryEvent = typeof ProviderRuntimeToolSummaryEvent.Type;
1149​
1150const ProviderRuntimeAuthStatusEvent = Schema.Struct({
1151 ...ProviderRuntimeEventBase.fields,
1152 type: AuthStatusType,
1153 payload: AuthStatusPayload,
1154});
1155export type ProviderRuntimeAuthStatusEvent = typeof ProviderRuntimeAuthStatusEvent.Type;
1156​
1157const ProviderRuntimeAccountUpdatedEvent = Schema.Struct({
1158 ...ProviderRuntimeEventBase.fields,
1159 type: AccountUpdatedType,
1160 payload: AccountUpdatedPayload,
1161});
1162export type ProviderRuntimeAccountUpdatedEvent = typeof ProviderRuntimeAccountUpdatedEvent.Type;
1163​
1164const ProviderRuntimeAccountRateLimitsUpdatedEvent = Schema.Struct({
1165 ...ProviderRuntimeEventBase.fields,
1166 type: AccountRateLimitsUpdatedType,
1167 payload: AccountRateLimitsUpdatedPayload,
1168});
1169export type ProviderRuntimeAccountRateLimitsUpdatedEvent =
1170 typeof ProviderRuntimeAccountRateLimitsUpdatedEvent.Type;
1171​
1172const ProviderRuntimeMcpStatusUpdatedEvent = Schema.Struct({
1173 ...ProviderRuntimeEventBase.fields,
1174 type: McpStatusUpdatedType,
1175 payload: McpStatusUpdatedPayload,
1176});
1177export type ProviderRuntimeMcpStatusUpdatedEvent = typeof ProviderRuntimeMcpStatusUpdatedEvent.Type;
1178​
1179const ProviderRuntimeMcpOauthCompletedEvent = Schema.Struct({
1180 ...ProviderRuntimeEventBase.fields,
1181 type: McpOauthCompletedType,
1182 payload: McpOauthCompletedPayload,
1183});
1184export type ProviderRuntimeMcpOauthCompletedEvent =
1185 typeof ProviderRuntimeMcpOauthCompletedEvent.Type;
1186​
1187const ProviderRuntimeModelReroutedEvent = Schema.Struct({
1188 ...ProviderRuntimeEventBase.fields,
1189 type: ModelReroutedType,
1190 payload: ModelReroutedPayload,
1191});
1192export type ProviderRuntimeModelReroutedEvent = typeof ProviderRuntimeModelReroutedEvent.Type;
1193​
1194const ProviderRuntimeConfigWarningEvent = Schema.Struct({
1195 ...ProviderRuntimeEventBase.fields,
1196 type: ConfigWarningType,
1197 payload: ConfigWarningPayload,
1198});
1199export type ProviderRuntimeConfigWarningEvent = typeof ProviderRuntimeConfigWarningEvent.Type;
1200​
1201const ProviderRuntimeDeprecationNoticeEvent = Schema.Struct({
1202 ...ProviderRuntimeEventBase.fields,
1203 type: DeprecationNoticeType,
1204 payload: DeprecationNoticePayload,
1205});
1206export type ProviderRuntimeDeprecationNoticeEvent =
1207 typeof ProviderRuntimeDeprecationNoticeEvent.Type;
1208​
1209const ProviderRuntimeFilesPersistedEvent = Schema.Struct({
1210 ...ProviderRuntimeEventBase.fields,
1211 type: FilesPersistedType,
1212 payload: FilesPersistedPayload,
1213});
1214export type ProviderRuntimeFilesPersistedEvent = typeof ProviderRuntimeFilesPersistedEvent.Type;
1215​
1216const ProviderRuntimeToolDeniedEvent = Schema.Struct({
1217 ...ProviderRuntimeEventBase.fields,
1218 type: ToolDeniedType,
1219 payload: ToolDeniedPayload,
1220});
1221export type ProviderRuntimeToolDeniedEvent = typeof ProviderRuntimeToolDeniedEvent.Type;
1222​
1223const ProviderRuntimeWarningEvent = Schema.Struct({
1224 ...ProviderRuntimeEventBase.fields,
1225 type: RuntimeWarningType,
1226 payload: RuntimeWarningPayload,
1227});
1228export type ProviderRuntimeWarningEvent = typeof ProviderRuntimeWarningEvent.Type;
1229​
1230const ProviderRuntimeErrorEvent = Schema.Struct({
1231 ...ProviderRuntimeEventBase.fields,
1232 type: RuntimeErrorType,
1233 payload: RuntimeErrorPayload,
1234});
1235export type ProviderRuntimeErrorEvent = typeof ProviderRuntimeErrorEvent.Type;
1236​
1237export const ProviderRuntimeEventV2 = Schema.Union([
1238 ProviderRuntimeSessionStartedEvent,
1239 ProviderRuntimeSessionConfiguredEvent,
1240 ProviderRuntimeSessionStateChangedEvent,
1241 ProviderRuntimeSessionExitedEvent,
1242 ProviderRuntimeThreadStartedEvent,
1243 ProviderRuntimeThreadStateChangedEvent,
1244 ProviderRuntimeThreadMetadataUpdatedEvent,
1245 ProviderRuntimeThreadTokenUsageUpdatedEvent,
1246 ProviderRuntimeThreadRealtimeStartedEvent,
1247 ProviderRuntimeThreadRealtimeItemAddedEvent,
1248 ProviderRuntimeThreadRealtimeAudioDeltaEvent,
1249 ProviderRuntimeThreadRealtimeErrorEvent,
1250 ProviderRuntimeThreadRealtimeClosedEvent,
1251 ProviderRuntimeTurnStartedEvent,
1252 ProviderRuntimeTurnCompletedEvent,
1253 ProviderRuntimeTurnAbortedEvent,
1254 ProviderRuntimeTurnPlanUpdatedEvent,
1255 ProviderRuntimeTurnProposedDeltaEvent,
1256 ProviderRuntimeTurnProposedCompletedEvent,
1257 ProviderRuntimeTurnDiffUpdatedEvent,
1258 ProviderRuntimeItemStartedEvent,
1259 ProviderRuntimeItemUpdatedEvent,
1260 ProviderRuntimeItemCompletedEvent,
1261 ProviderRuntimeContentDeltaEvent,
1262 ProviderRuntimeRequestOpenedEvent,
1263 ProviderRuntimeRequestResolvedEvent,
1264 ProviderRuntimeUserInputRequestedEvent,
1265 ProviderRuntimeUserInputResolvedEvent,
1266 ProviderRuntimeTaskStartedEvent,
1267 ProviderRuntimeTaskProgressEvent,
1268 ProviderRuntimeTaskUpdatedEvent,
1269 ProviderRuntimeTaskCompletedEvent,
1270 ProviderRuntimeHookStartedEvent,
1271 ProviderRuntimeHookProgressEvent,
1272 ProviderRuntimeHookCompletedEvent,
1273 ProviderRuntimeToolProgressEvent,
1274 ProviderRuntimeToolSummaryEvent,
1275 ProviderRuntimeAuthStatusEvent,
1276 ProviderRuntimeAccountUpdatedEvent,
1277 ProviderRuntimeAccountRateLimitsUpdatedEvent,
1278 ProviderRuntimeMcpStatusUpdatedEvent,
1279 ProviderRuntimeMcpOauthCompletedEvent,
1280 ProviderRuntimeModelReroutedEvent,
1281 ProviderRuntimeConfigWarningEvent,
1282 ProviderRuntimeDeprecationNoticeEvent,
1283 ProviderRuntimeFilesPersistedEvent,
1284 ProviderRuntimeToolDeniedEvent,
1285 ProviderRuntimeWarningEvent,
1286 ProviderRuntimeErrorEvent,
1287]);
1288export type ProviderRuntimeEventV2 = typeof ProviderRuntimeEventV2.Type;
1289​
1290export const ProviderRuntimeEvent = ProviderRuntimeEventV2;
1291export type ProviderRuntimeEvent = ProviderRuntimeEventV2;
1292​
1293export const ProviderRuntimeTurnStatus = RuntimeTurnState;
1294export type ProviderRuntimeTurnStatus = RuntimeTurnState;