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

providerRuntime.ts

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