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