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

providerRuntime.ts

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