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

providerRuntime.ts

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