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

providerRuntime.ts

1,254 lines46.2 KB

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