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