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

providerRuntime.ts

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