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

providerRuntime.ts

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