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 "./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);
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});
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";
572}
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 class: Schema.optional(RuntimeErrorClass),
813 detail: Schema.optional(Schema.Unknown),
814});
815export type RuntimeErrorPayload = typeof RuntimeErrorPayload.Type;
816
817const ProviderRuntimeSessionStartedEvent = Schema.Struct({
818 ...ProviderRuntimeEventBase.fields,
819 type: SessionStartedType,
820 payload: SessionStartedPayload,
821});
822export type ProviderRuntimeSessionStartedEvent = typeof ProviderRuntimeSessionStartedEvent.Type;
823
824const ProviderRuntimeSessionConfiguredEvent = Schema.Struct({
825 ...ProviderRuntimeEventBase.fields,
826 type: SessionConfiguredType,
827 payload: SessionConfiguredPayload,
828});
829export type ProviderRuntimeSessionConfiguredEvent =
830 typeof ProviderRuntimeSessionConfiguredEvent.Type;
831
832const ProviderRuntimeSessionStateChangedEvent = Schema.Struct({
833 ...ProviderRuntimeEventBase.fields,
834 type: SessionStateChangedType,
835 payload: SessionStateChangedPayload,
836});
837export type ProviderRuntimeSessionStateChangedEvent =
838 typeof ProviderRuntimeSessionStateChangedEvent.Type;
839
840const ProviderRuntimeSessionExitedEvent = Schema.Struct({
841 ...ProviderRuntimeEventBase.fields,
842 type: SessionExitedType,
843 payload: SessionExitedPayload,
844});
845export type ProviderRuntimeSessionExitedEvent = typeof ProviderRuntimeSessionExitedEvent.Type;
846
847const ProviderRuntimeThreadStartedEvent = Schema.Struct({
848 ...ProviderRuntimeEventBase.fields,
849 type: ThreadStartedType,
850 payload: ThreadStartedPayload,
851});
852export type ProviderRuntimeThreadStartedEvent = typeof ProviderRuntimeThreadStartedEvent.Type;
853
854const ProviderRuntimeThreadStateChangedEvent = Schema.Struct({
855 ...ProviderRuntimeEventBase.fields,
856 type: ThreadStateChangedType,
857 payload: ThreadStateChangedPayload,
858});
859export type ProviderRuntimeThreadStateChangedEvent =
860 typeof ProviderRuntimeThreadStateChangedEvent.Type;
861
862const ProviderRuntimeThreadMetadataUpdatedEvent = Schema.Struct({
863 ...ProviderRuntimeEventBase.fields,
864 type: ThreadMetadataUpdatedType,
865 payload: ThreadMetadataUpdatedPayload,
866});
867export type ProviderRuntimeThreadMetadataUpdatedEvent =
868 typeof ProviderRuntimeThreadMetadataUpdatedEvent.Type;
869
870const ProviderRuntimeThreadTokenUsageUpdatedEvent = Schema.Struct({
871 ...ProviderRuntimeEventBase.fields,
872 type: ThreadTokenUsageUpdatedType,
873 payload: ThreadTokenUsageUpdatedPayload,
874});
875export type ProviderRuntimeThreadTokenUsageUpdatedEvent =
876 typeof ProviderRuntimeThreadTokenUsageUpdatedEvent.Type;
877
878const ProviderRuntimeThreadRealtimeStartedEvent = Schema.Struct({
879 ...ProviderRuntimeEventBase.fields,
880 type: ThreadRealtimeStartedType,
881 payload: ThreadRealtimeStartedPayload,
882});
883export type ProviderRuntimeThreadRealtimeStartedEvent =
884 typeof ProviderRuntimeThreadRealtimeStartedEvent.Type;
885
886const ProviderRuntimeThreadRealtimeItemAddedEvent = Schema.Struct({
887 ...ProviderRuntimeEventBase.fields,
888 type: ThreadRealtimeItemAddedType,
889 payload: ThreadRealtimeItemAddedPayload,
890});
891export type ProviderRuntimeThreadRealtimeItemAddedEvent =
892 typeof ProviderRuntimeThreadRealtimeItemAddedEvent.Type;
893
894const ProviderRuntimeThreadRealtimeAudioDeltaEvent = Schema.Struct({
895 ...ProviderRuntimeEventBase.fields,
896 type: ThreadRealtimeAudioDeltaType,
897 payload: ThreadRealtimeAudioDeltaPayload,
898});
899export type ProviderRuntimeThreadRealtimeAudioDeltaEvent =
900 typeof ProviderRuntimeThreadRealtimeAudioDeltaEvent.Type;
901
902const ProviderRuntimeThreadRealtimeErrorEvent = Schema.Struct({
903 ...ProviderRuntimeEventBase.fields,
904 type: ThreadRealtimeErrorType,
905 payload: ThreadRealtimeErrorPayload,
906});
907export type ProviderRuntimeThreadRealtimeErrorEvent =
908 typeof ProviderRuntimeThreadRealtimeErrorEvent.Type;
909
910const ProviderRuntimeThreadRealtimeClosedEvent = Schema.Struct({
911 ...ProviderRuntimeEventBase.fields,
912 type: ThreadRealtimeClosedType,
913 payload: ThreadRealtimeClosedPayload,
914});
915export type ProviderRuntimeThreadRealtimeClosedEvent =
916 typeof ProviderRuntimeThreadRealtimeClosedEvent.Type;
917
918const ProviderRuntimeTurnStartedEvent = Schema.Struct({
919 ...ProviderRuntimeEventBase.fields,
920 type: TurnStartedType,
921 payload: TurnStartedPayload,
922});
923export type ProviderRuntimeTurnStartedEvent = typeof ProviderRuntimeTurnStartedEvent.Type;
924
925const ProviderRuntimeTurnCompletedEvent = Schema.Struct({
926 ...ProviderRuntimeEventBase.fields,
927 type: TurnCompletedType,
928 payload: TurnCompletedPayload,
929});
930export type ProviderRuntimeTurnCompletedEvent = typeof ProviderRuntimeTurnCompletedEvent.Type;
931
932const ProviderRuntimeTurnAbortedEvent = Schema.Struct({
933 ...ProviderRuntimeEventBase.fields,
934 type: TurnAbortedType,
935 payload: TurnAbortedPayload,
936});
937export type ProviderRuntimeTurnAbortedEvent = typeof ProviderRuntimeTurnAbortedEvent.Type;
938
939const ProviderRuntimeTurnPlanUpdatedEvent = Schema.Struct({
940 ...ProviderRuntimeEventBase.fields,
941 type: TurnPlanUpdatedType,
942 payload: TurnPlanUpdatedPayload,
943});
944export type ProviderRuntimeTurnPlanUpdatedEvent = typeof ProviderRuntimeTurnPlanUpdatedEvent.Type;
945
946const ProviderRuntimeTurnProposedDeltaEvent = Schema.Struct({
947 ...ProviderRuntimeEventBase.fields,
948 type: TurnProposedDeltaType,
949 payload: TurnProposedDeltaPayload,
950});
951export type ProviderRuntimeTurnProposedDeltaEvent =
952 typeof ProviderRuntimeTurnProposedDeltaEvent.Type;
953
954const ProviderRuntimeTurnProposedCompletedEvent = Schema.Struct({
955 ...ProviderRuntimeEventBase.fields,
956 type: TurnProposedCompletedType,
957 payload: TurnProposedCompletedPayload,
958});
959export type ProviderRuntimeTurnProposedCompletedEvent =
960 typeof ProviderRuntimeTurnProposedCompletedEvent.Type;
961
962const ProviderRuntimeTurnDiffUpdatedEvent = Schema.Struct({
963 ...ProviderRuntimeEventBase.fields,
964 type: TurnDiffUpdatedType,
965 payload: TurnDiffUpdatedPayload,
966});
967export type ProviderRuntimeTurnDiffUpdatedEvent = typeof ProviderRuntimeTurnDiffUpdatedEvent.Type;
968
969const ProviderRuntimeItemStartedEvent = Schema.Struct({
970 ...ProviderRuntimeEventBase.fields,
971 type: ItemStartedType,
972 payload: ItemLifecyclePayload,
973});
974export type ProviderRuntimeItemStartedEvent = typeof ProviderRuntimeItemStartedEvent.Type;
975
976const ProviderRuntimeItemUpdatedEvent = Schema.Struct({
977 ...ProviderRuntimeEventBase.fields,
978 type: ItemUpdatedType,
979 payload: ItemLifecyclePayload,
980});
981export type ProviderRuntimeItemUpdatedEvent = typeof ProviderRuntimeItemUpdatedEvent.Type;
982
983const ProviderRuntimeItemCompletedEvent = Schema.Struct({
984 ...ProviderRuntimeEventBase.fields,
985 type: ItemCompletedType,
986 payload: ItemLifecyclePayload,
987});
988export type ProviderRuntimeItemCompletedEvent = typeof ProviderRuntimeItemCompletedEvent.Type;
989
990const ProviderRuntimeContentDeltaEvent = Schema.Struct({
991 ...ProviderRuntimeEventBase.fields,
992 type: ContentDeltaType,
993 payload: ContentDeltaPayload,
994});
995export type ProviderRuntimeContentDeltaEvent = typeof ProviderRuntimeContentDeltaEvent.Type;
996
997const ProviderRuntimeRequestOpenedEvent = Schema.Struct({
998 ...ProviderRuntimeEventBase.fields,
999 type: RequestOpenedType,
1000 payload: RequestOpenedPayload,
1001});
1002export type ProviderRuntimeRequestOpenedEvent = typeof ProviderRuntimeRequestOpenedEvent.Type;
1003
1004const ProviderRuntimeRequestResolvedEvent = Schema.Struct({
1005 ...ProviderRuntimeEventBase.fields,
1006 type: RequestResolvedType,
1007 payload: RequestResolvedPayload,
1008});
1009export type ProviderRuntimeRequestResolvedEvent = typeof ProviderRuntimeRequestResolvedEvent.Type;
1010
1011const ProviderRuntimeUserInputRequestedEvent = Schema.Struct({
1012 ...ProviderRuntimeEventBase.fields,
1013 type: UserInputRequestedType,
1014 payload: UserInputRequestedPayload,
1015});
1016export type ProviderRuntimeUserInputRequestedEvent =
1017 typeof ProviderRuntimeUserInputRequestedEvent.Type;
1018
1019const ProviderRuntimeUserInputResolvedEvent = Schema.Struct({
1020 ...ProviderRuntimeEventBase.fields,
1021 type: UserInputResolvedType,
1022 payload: UserInputResolvedPayload,
1023});
1024export type ProviderRuntimeUserInputResolvedEvent =
1025 typeof ProviderRuntimeUserInputResolvedEvent.Type;
1026
1027const ProviderRuntimeTaskStartedEvent = Schema.Struct({
1028 ...ProviderRuntimeEventBase.fields,
1029 type: TaskStartedType,
1030 payload: TaskStartedPayload,
1031});
1032export type ProviderRuntimeTaskStartedEvent = typeof ProviderRuntimeTaskStartedEvent.Type;
1033
1034const ProviderRuntimeTaskProgressEvent = Schema.Struct({
1035 ...ProviderRuntimeEventBase.fields,
1036 type: TaskProgressType,
1037 payload: TaskProgressPayload,
1038});
1039export type ProviderRuntimeTaskProgressEvent = typeof ProviderRuntimeTaskProgressEvent.Type;
1040
1041const ProviderRuntimeTaskUpdatedEvent = Schema.Struct({
1042 ...ProviderRuntimeEventBase.fields,
1043 type: TaskUpdatedType,
1044 payload: TaskUpdatedPayload,
1045});
1046export type ProviderRuntimeTaskUpdatedEvent = typeof ProviderRuntimeTaskUpdatedEvent.Type;
1047
1048const ProviderRuntimeTaskCompletedEvent = Schema.Struct({
1049 ...ProviderRuntimeEventBase.fields,
1050 type: TaskCompletedType,
1051 payload: TaskCompletedPayload,
1052});
1053export type ProviderRuntimeTaskCompletedEvent = typeof ProviderRuntimeTaskCompletedEvent.Type;
1054
1055const ProviderRuntimeHookStartedEvent = Schema.Struct({
1056 ...ProviderRuntimeEventBase.fields,
1057 type: HookStartedType,
1058 payload: HookStartedPayload,
1059});
1060export type ProviderRuntimeHookStartedEvent = typeof ProviderRuntimeHookStartedEvent.Type;
1061
1062const ProviderRuntimeHookProgressEvent = Schema.Struct({
1063 ...ProviderRuntimeEventBase.fields,
1064 type: HookProgressType,
1065 payload: HookProgressPayload,
1066});
1067export type ProviderRuntimeHookProgressEvent = typeof ProviderRuntimeHookProgressEvent.Type;
1068
1069const ProviderRuntimeHookCompletedEvent = Schema.Struct({
1070 ...ProviderRuntimeEventBase.fields,
1071 type: HookCompletedType,
1072 payload: HookCompletedPayload,
1073});
1074export type ProviderRuntimeHookCompletedEvent = typeof ProviderRuntimeHookCompletedEvent.Type;
1075
1076const ProviderRuntimeToolProgressEvent = Schema.Struct({
1077 ...ProviderRuntimeEventBase.fields,
1078 type: ToolProgressType,
1079 payload: ToolProgressPayload,
1080});
1081export type ProviderRuntimeToolProgressEvent = typeof ProviderRuntimeToolProgressEvent.Type;
1082
1083const ProviderRuntimeToolSummaryEvent = Schema.Struct({
1084 ...ProviderRuntimeEventBase.fields,
1085 type: ToolSummaryType,
1086 payload: ToolSummaryPayload,
1087});
1088export type ProviderRuntimeToolSummaryEvent = typeof ProviderRuntimeToolSummaryEvent.Type;
1089
1090const ProviderRuntimeAuthStatusEvent = Schema.Struct({
1091 ...ProviderRuntimeEventBase.fields,
1092 type: AuthStatusType,
1093 payload: AuthStatusPayload,
1094});
1095export type ProviderRuntimeAuthStatusEvent = typeof ProviderRuntimeAuthStatusEvent.Type;
1096
1097const ProviderRuntimeAccountUpdatedEvent = Schema.Struct({
1098 ...ProviderRuntimeEventBase.fields,
1099 type: AccountUpdatedType,
1100 payload: AccountUpdatedPayload,
1101});
1102export type ProviderRuntimeAccountUpdatedEvent = typeof ProviderRuntimeAccountUpdatedEvent.Type;
1103
1104const ProviderRuntimeAccountRateLimitsUpdatedEvent = Schema.Struct({
1105 ...ProviderRuntimeEventBase.fields,
1106 type: AccountRateLimitsUpdatedType,
1107 payload: AccountRateLimitsUpdatedPayload,
1108});
1109export type ProviderRuntimeAccountRateLimitsUpdatedEvent =
1110 typeof ProviderRuntimeAccountRateLimitsUpdatedEvent.Type;
1111
1112const ProviderRuntimeMcpStatusUpdatedEvent = Schema.Struct({
1113 ...ProviderRuntimeEventBase.fields,
1114 type: McpStatusUpdatedType,
1115 payload: McpStatusUpdatedPayload,
1116});
1117export type ProviderRuntimeMcpStatusUpdatedEvent = typeof ProviderRuntimeMcpStatusUpdatedEvent.Type;
1118
1119const ProviderRuntimeMcpOauthCompletedEvent = Schema.Struct({
1120 ...ProviderRuntimeEventBase.fields,
1121 type: McpOauthCompletedType,
1122 payload: McpOauthCompletedPayload,
1123});
1124export type ProviderRuntimeMcpOauthCompletedEvent =
1125 typeof ProviderRuntimeMcpOauthCompletedEvent.Type;
1126
1127const ProviderRuntimeModelReroutedEvent = Schema.Struct({
1128 ...ProviderRuntimeEventBase.fields,
1129 type: ModelReroutedType,
1130 payload: ModelReroutedPayload,
1131});
1132export type ProviderRuntimeModelReroutedEvent = typeof ProviderRuntimeModelReroutedEvent.Type;
1133
1134const ProviderRuntimeConfigWarningEvent = Schema.Struct({
1135 ...ProviderRuntimeEventBase.fields,
1136 type: ConfigWarningType,
1137 payload: ConfigWarningPayload,
1138});
1139export type ProviderRuntimeConfigWarningEvent = typeof ProviderRuntimeConfigWarningEvent.Type;
1140
1141const ProviderRuntimeDeprecationNoticeEvent = Schema.Struct({
1142 ...ProviderRuntimeEventBase.fields,
1143 type: DeprecationNoticeType,
1144 payload: DeprecationNoticePayload,
1145});
1146export type ProviderRuntimeDeprecationNoticeEvent =
1147 typeof ProviderRuntimeDeprecationNoticeEvent.Type;
1148
1149const ProviderRuntimeFilesPersistedEvent = Schema.Struct({
1150 ...ProviderRuntimeEventBase.fields,
1151 type: FilesPersistedType,
1152 payload: FilesPersistedPayload,
1153});
1154export type ProviderRuntimeFilesPersistedEvent = typeof ProviderRuntimeFilesPersistedEvent.Type;
1155
1156const ProviderRuntimeToolDeniedEvent = Schema.Struct({
1157 ...ProviderRuntimeEventBase.fields,
1158 type: ToolDeniedType,
1159 payload: ToolDeniedPayload,
1160});
1161export type ProviderRuntimeToolDeniedEvent = typeof ProviderRuntimeToolDeniedEvent.Type;
1162
1163const ProviderRuntimeWarningEvent = Schema.Struct({
1164 ...ProviderRuntimeEventBase.fields,
1165 type: RuntimeWarningType,
1166 payload: RuntimeWarningPayload,
1167});
1168export type ProviderRuntimeWarningEvent = typeof ProviderRuntimeWarningEvent.Type;
1169
1170const ProviderRuntimeErrorEvent = Schema.Struct({
1171 ...ProviderRuntimeEventBase.fields,
1172 type: RuntimeErrorType,
1173 payload: RuntimeErrorPayload,
1174});
1175export type ProviderRuntimeErrorEvent = typeof ProviderRuntimeErrorEvent.Type;
1176
1177export const ProviderRuntimeEventV2 = Schema.Union([
1178 ProviderRuntimeSessionStartedEvent,
1179 ProviderRuntimeSessionConfiguredEvent,
1180 ProviderRuntimeSessionStateChangedEvent,
1181 ProviderRuntimeSessionExitedEvent,
1182 ProviderRuntimeThreadStartedEvent,
1183 ProviderRuntimeThreadStateChangedEvent,
1184 ProviderRuntimeThreadMetadataUpdatedEvent,
1185 ProviderRuntimeThreadTokenUsageUpdatedEvent,
1186 ProviderRuntimeThreadRealtimeStartedEvent,
1187 ProviderRuntimeThreadRealtimeItemAddedEvent,
1188 ProviderRuntimeThreadRealtimeAudioDeltaEvent,
1189 ProviderRuntimeThreadRealtimeErrorEvent,
1190 ProviderRuntimeThreadRealtimeClosedEvent,
1191 ProviderRuntimeTurnStartedEvent,
1192 ProviderRuntimeTurnCompletedEvent,
1193 ProviderRuntimeTurnAbortedEvent,
1194 ProviderRuntimeTurnPlanUpdatedEvent,
1195 ProviderRuntimeTurnProposedDeltaEvent,
1196 ProviderRuntimeTurnProposedCompletedEvent,
1197 ProviderRuntimeTurnDiffUpdatedEvent,
1198 ProviderRuntimeItemStartedEvent,
1199 ProviderRuntimeItemUpdatedEvent,
1200 ProviderRuntimeItemCompletedEvent,
1201 ProviderRuntimeContentDeltaEvent,
1202 ProviderRuntimeRequestOpenedEvent,
1203 ProviderRuntimeRequestResolvedEvent,
1204 ProviderRuntimeUserInputRequestedEvent,
1205 ProviderRuntimeUserInputResolvedEvent,
1206 ProviderRuntimeTaskStartedEvent,
1207 ProviderRuntimeTaskProgressEvent,
1208 ProviderRuntimeTaskUpdatedEvent,
1209 ProviderRuntimeTaskCompletedEvent,
1210 ProviderRuntimeHookStartedEvent,
1211 ProviderRuntimeHookProgressEvent,
1212 ProviderRuntimeHookCompletedEvent,
1213 ProviderRuntimeToolProgressEvent,
1214 ProviderRuntimeToolSummaryEvent,
1215 ProviderRuntimeAuthStatusEvent,
1216 ProviderRuntimeAccountUpdatedEvent,
1217 ProviderRuntimeAccountRateLimitsUpdatedEvent,
1218 ProviderRuntimeMcpStatusUpdatedEvent,
1219 ProviderRuntimeMcpOauthCompletedEvent,
1220 ProviderRuntimeModelReroutedEvent,
1221 ProviderRuntimeConfigWarningEvent,
1222 ProviderRuntimeDeprecationNoticeEvent,
1223 ProviderRuntimeFilesPersistedEvent,
1224 ProviderRuntimeToolDeniedEvent,
1225 ProviderRuntimeWarningEvent,
1226 ProviderRuntimeErrorEvent,
1227]);
1228export type ProviderRuntimeEventV2 = typeof ProviderRuntimeEventV2.Type;
1229
1230export const ProviderRuntimeEvent = ProviderRuntimeEventV2;
1231export type ProviderRuntimeEvent = ProviderRuntimeEventV2;
1232
1233export const ProviderRuntimeTurnStatus = RuntimeTurnState;
1234export type ProviderRuntimeTurnStatus = RuntimeTurnState;