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

providerRuntime.ts

1,296 lines48.0 KB

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