1016 lines · 36.4 KB · TypeScript
RawDownload
import { Option, Schema } from "effect";import {  EventId,  IsoDateTime,  NonNegativeInt,  ProviderItemId,  PositiveInt,  RuntimeItemId,  RuntimeRequestId,  RuntimeTaskId,  ThreadId,  TrimmedNonEmptyString,  TurnId,} from "./baseSchemas";import { ProviderKind } from "./orchestration"; const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;const UnknownRecordSchema = Schema.Record(Schema.String, Schema.Unknown); const RuntimeEventRawSource = Schema.Literals([  "codex.app-server.notification",  "codex.app-server.request",  "codex.eventmsg",  "claude.sdk.message",  "claude.sdk.permission",  "codex.sdk.thread-event",]);export type RuntimeEventRawSource = typeof RuntimeEventRawSource.Type; export const RuntimeEventRaw = Schema.Struct({  source: RuntimeEventRawSource,  method: Schema.optional(TrimmedNonEmptyStringSchema),  messageType: Schema.optional(TrimmedNonEmptyStringSchema),  payload: Schema.Unknown,});export type RuntimeEventRaw = typeof RuntimeEventRaw.Type; const ProviderRequestId = TrimmedNonEmptyStringSchema;export type ProviderRequestId = typeof ProviderRequestId.Type; const ProviderRefs = Schema.Struct({  providerTurnId: Schema.optional(TrimmedNonEmptyStringSchema),  providerItemId: Schema.optional(ProviderItemId),  providerRequestId: Schema.optional(ProviderRequestId),});export type ProviderRefs = typeof ProviderRefs.Type; const RuntimeSessionState = Schema.Literals([  "starting",  "ready",  "running",  "waiting",  "stopped",  "error",]);export type RuntimeSessionState = typeof RuntimeSessionState.Type; const RuntimeThreadState = Schema.Literals([  "active",  "idle",  "archived",  "closed",  "compacted",  "error",]);export type RuntimeThreadState = typeof RuntimeThreadState.Type; const RuntimeTurnState = Schema.Literals(["completed", "failed", "interrupted", "cancelled"]);export type RuntimeTurnState = typeof RuntimeTurnState.Type; const RuntimePlanStepStatus = Schema.Literals(["pending", "inProgress", "completed"]);export type RuntimePlanStepStatus = typeof RuntimePlanStepStatus.Type; const RuntimeItemStatus = Schema.Literals(["inProgress", "completed", "failed", "declined"]);export type RuntimeItemStatus = typeof RuntimeItemStatus.Type; const RuntimeContentStreamKind = Schema.Literals([  "assistant_text",  "reasoning_text",  "reasoning_summary_text",  "plan_text",  "command_output",  "file_change_output",  "unknown",]);export type RuntimeContentStreamKind = typeof RuntimeContentStreamKind.Type; const RuntimeSessionExitKind = Schema.Literals(["graceful", "error"]);export type RuntimeSessionExitKind = typeof RuntimeSessionExitKind.Type; const RuntimeErrorClass = Schema.Literals([  "provider_error",  "transport_error",  "permission_error",  "validation_error",  "unknown",]);export type RuntimeErrorClass = typeof RuntimeErrorClass.Type; export const TOOL_LIFECYCLE_ITEM_TYPES = [  "command_execution",  "file_change",  "mcp_tool_call",  "dynamic_tool_call",  "collab_agent_tool_call",  "web_search",  "image_view",] as const; export const ToolLifecycleItemType = Schema.Literals(TOOL_LIFECYCLE_ITEM_TYPES);export type ToolLifecycleItemType = typeof ToolLifecycleItemType.Type; export function isToolLifecycleItemType(value: string): value is ToolLifecycleItemType {  return TOOL_LIFECYCLE_ITEM_TYPES.includes(value as ToolLifecycleItemType);} export const CanonicalItemType = Schema.Literals([  "user_message",  "assistant_message",  "reasoning",  "plan",  ...TOOL_LIFECYCLE_ITEM_TYPES,  "review_entered",  "review_exited",  "context_compaction",  "error",  "unknown",]);export type CanonicalItemType = typeof CanonicalItemType.Type; export const CanonicalRequestType = Schema.Literals([  "command_execution_approval",  "file_read_approval",  "file_change_approval",  "apply_patch_approval",  "exec_command_approval",  "tool_user_input",  "dynamic_tool_call",  "auth_tokens_refresh",  "unknown",]);export type CanonicalRequestType = typeof CanonicalRequestType.Type; const ProviderRuntimeEventType = Schema.Literals([  "session.started",  "session.configured",  "session.state.changed",  "session.exited",  "thread.started",  "thread.state.changed",  "thread.metadata.updated",  "thread.token-usage.updated",  "thread.realtime.started",  "thread.realtime.item-added",  "thread.realtime.audio.delta",  "thread.realtime.error",  "thread.realtime.closed",  "turn.started",  "turn.completed",  "turn.aborted",  "turn.plan.updated",  "turn.proposed.delta",  "turn.proposed.completed",  "turn.diff.updated",  "item.started",  "item.updated",  "item.completed",  "content.delta",  "request.opened",  "request.resolved",  "user-input.requested",  "user-input.resolved",  "task.started",  "task.progress",  "task.completed",  "hook.started",  "hook.progress",  "hook.completed",  "tool.progress",  "tool.summary",  "auth.status",  "account.updated",  "account.rate-limits.updated",  "mcp.status.updated",  "mcp.oauth.completed",  "model.rerouted",  "config.warning",  "deprecation.notice",  "files.persisted",  "runtime.warning",  "runtime.error",]);export type ProviderRuntimeEventType = typeof ProviderRuntimeEventType.Type; const SessionStartedType = Schema.Literal("session.started");const SessionConfiguredType = Schema.Literal("session.configured");const SessionStateChangedType = Schema.Literal("session.state.changed");const SessionExitedType = Schema.Literal("session.exited");const ThreadStartedType = Schema.Literal("thread.started");const ThreadStateChangedType = Schema.Literal("thread.state.changed");const ThreadMetadataUpdatedType = Schema.Literal("thread.metadata.updated");const ThreadTokenUsageUpdatedType = Schema.Literal("thread.token-usage.updated");const ThreadRealtimeStartedType = Schema.Literal("thread.realtime.started");const ThreadRealtimeItemAddedType = Schema.Literal("thread.realtime.item-added");const ThreadRealtimeAudioDeltaType = Schema.Literal("thread.realtime.audio.delta");const ThreadRealtimeErrorType = Schema.Literal("thread.realtime.error");const ThreadRealtimeClosedType = Schema.Literal("thread.realtime.closed");const TurnStartedType = Schema.Literal("turn.started");const TurnCompletedType = Schema.Literal("turn.completed");const TurnAbortedType = Schema.Literal("turn.aborted");const TurnPlanUpdatedType = Schema.Literal("turn.plan.updated");const TurnProposedDeltaType = Schema.Literal("turn.proposed.delta");const TurnProposedCompletedType = Schema.Literal("turn.proposed.completed");const TurnDiffUpdatedType = Schema.Literal("turn.diff.updated");const ItemStartedType = Schema.Literal("item.started");const ItemUpdatedType = Schema.Literal("item.updated");const ItemCompletedType = Schema.Literal("item.completed");const ContentDeltaType = Schema.Literal("content.delta");const RequestOpenedType = Schema.Literal("request.opened");const RequestResolvedType = Schema.Literal("request.resolved");const UserInputRequestedType = Schema.Literal("user-input.requested");const UserInputResolvedType = Schema.Literal("user-input.resolved");const TaskStartedType = Schema.Literal("task.started");const TaskProgressType = Schema.Literal("task.progress");const TaskCompletedType = Schema.Literal("task.completed");const HookStartedType = Schema.Literal("hook.started");const HookProgressType = Schema.Literal("hook.progress");const HookCompletedType = Schema.Literal("hook.completed");const ToolProgressType = Schema.Literal("tool.progress");const ToolSummaryType = Schema.Literal("tool.summary");const AuthStatusType = Schema.Literal("auth.status");const AccountUpdatedType = Schema.Literal("account.updated");const AccountRateLimitsUpdatedType = Schema.Literal("account.rate-limits.updated");const McpStatusUpdatedType = Schema.Literal("mcp.status.updated");const McpOauthCompletedType = Schema.Literal("mcp.oauth.completed");const ModelReroutedType = Schema.Literal("model.rerouted");const ConfigWarningType = Schema.Literal("config.warning");const DeprecationNoticeType = Schema.Literal("deprecation.notice");const FilesPersistedType = Schema.Literal("files.persisted");const RuntimeWarningType = Schema.Literal("runtime.warning");const RuntimeErrorType = Schema.Literal("runtime.error"); const ProviderRuntimeEventBase = Schema.Struct({  eventId: EventId,  provider: ProviderKind,  threadId: ThreadId,  createdAt: IsoDateTime,  turnId: Schema.optional(TurnId),  itemId: Schema.optional(RuntimeItemId),  requestId: Schema.optional(RuntimeRequestId),  providerRefs: Schema.optional(ProviderRefs),  raw: Schema.optional(RuntimeEventRaw),});export type ProviderRuntimeEventBase = typeof ProviderRuntimeEventBase.Type; const SessionStartedPayload = Schema.Struct({  message: Schema.optional(TrimmedNonEmptyStringSchema),  resume: Schema.optional(Schema.Unknown),});export type SessionStartedPayload = typeof SessionStartedPayload.Type; const SessionConfiguredPayload = Schema.Struct({  config: UnknownRecordSchema,});export type SessionConfiguredPayload = typeof SessionConfiguredPayload.Type; const SessionStateChangedPayload = Schema.Struct({  state: RuntimeSessionState,  reason: Schema.optional(TrimmedNonEmptyStringSchema),  detail: Schema.optional(Schema.Unknown),});export type SessionStateChangedPayload = typeof SessionStateChangedPayload.Type; const SessionExitedPayload = Schema.Struct({  reason: Schema.optional(TrimmedNonEmptyStringSchema),  recoverable: Schema.optional(Schema.Boolean),  exitKind: Schema.optional(RuntimeSessionExitKind),});export type SessionExitedPayload = typeof SessionExitedPayload.Type; const ThreadStartedPayload = Schema.Struct({  providerThreadId: Schema.optional(TrimmedNonEmptyStringSchema),});export type ThreadStartedPayload = typeof ThreadStartedPayload.Type; const ThreadStateChangedPayload = Schema.Struct({  state: RuntimeThreadState,  detail: Schema.optional(Schema.Unknown),});export type ThreadStateChangedPayload = typeof ThreadStateChangedPayload.Type; const ThreadMetadataUpdatedPayload = Schema.Struct({  name: Schema.optional(TrimmedNonEmptyStringSchema),  metadata: Schema.optional(UnknownRecordSchema),});export type ThreadMetadataUpdatedPayload = typeof ThreadMetadataUpdatedPayload.Type; export const ThreadTokenUsageSnapshot = Schema.Struct({  usedTokens: NonNegativeInt,  totalProcessedTokens: Schema.optional(NonNegativeInt),  maxTokens: Schema.optional(PositiveInt),  inputTokens: Schema.optional(NonNegativeInt),  cachedInputTokens: Schema.optional(NonNegativeInt),  outputTokens: Schema.optional(NonNegativeInt),  reasoningOutputTokens: Schema.optional(NonNegativeInt),  lastUsedTokens: Schema.optional(NonNegativeInt),  lastInputTokens: Schema.optional(NonNegativeInt),  lastCachedInputTokens: Schema.optional(NonNegativeInt),  lastOutputTokens: Schema.optional(NonNegativeInt),  lastReasoningOutputTokens: Schema.optional(NonNegativeInt),  toolUses: Schema.optional(NonNegativeInt),  durationMs: Schema.optional(NonNegativeInt),  compactsAutomatically: Schema.optional(Schema.Boolean),});export type ThreadTokenUsageSnapshot = typeof ThreadTokenUsageSnapshot.Type; const ThreadTokenUsageUpdatedPayload = Schema.Struct({  usage: ThreadTokenUsageSnapshot,});export type ThreadTokenUsageUpdatedPayload = typeof ThreadTokenUsageUpdatedPayload.Type; const ThreadRealtimeStartedPayload = Schema.Struct({  realtimeSessionId: Schema.optional(TrimmedNonEmptyStringSchema),});export type ThreadRealtimeStartedPayload = typeof ThreadRealtimeStartedPayload.Type; const ThreadRealtimeItemAddedPayload = Schema.Struct({  item: Schema.Unknown,});export type ThreadRealtimeItemAddedPayload = typeof ThreadRealtimeItemAddedPayload.Type; const ThreadRealtimeAudioDeltaPayload = Schema.Struct({  audio: Schema.Unknown,});export type ThreadRealtimeAudioDeltaPayload = typeof ThreadRealtimeAudioDeltaPayload.Type; const ThreadRealtimeErrorPayload = Schema.Struct({  message: TrimmedNonEmptyStringSchema,});export type ThreadRealtimeErrorPayload = typeof ThreadRealtimeErrorPayload.Type; const ThreadRealtimeClosedPayload = Schema.Struct({  reason: Schema.optional(TrimmedNonEmptyStringSchema),});export type ThreadRealtimeClosedPayload = typeof ThreadRealtimeClosedPayload.Type; const TurnStartedPayload = Schema.Struct({  model: Schema.optional(TrimmedNonEmptyStringSchema),  effort: Schema.optional(TrimmedNonEmptyStringSchema),});export type TurnStartedPayload = typeof TurnStartedPayload.Type; const TurnCompletedPayload = Schema.Struct({  state: RuntimeTurnState,  stopReason: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),  usage: Schema.optional(Schema.Unknown),  modelUsage: Schema.optional(UnknownRecordSchema),  totalCostUsd: Schema.optional(Schema.Number),  errorMessage: Schema.optional(TrimmedNonEmptyStringSchema),});export type TurnCompletedPayload = typeof TurnCompletedPayload.Type; const TurnAbortedPayload = Schema.Struct({  reason: TrimmedNonEmptyStringSchema,});export type TurnAbortedPayload = typeof TurnAbortedPayload.Type; const RuntimePlanStep = Schema.Struct({  step: TrimmedNonEmptyStringSchema,  status: RuntimePlanStepStatus,});export type RuntimePlanStep = typeof RuntimePlanStep.Type; const TurnPlanUpdatedPayload = Schema.Struct({  explanation: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),  plan: Schema.Array(RuntimePlanStep),});export type TurnPlanUpdatedPayload = typeof TurnPlanUpdatedPayload.Type; const TurnProposedDeltaPayload = Schema.Struct({  delta: Schema.String,});export type TurnProposedDeltaPayload = typeof TurnProposedDeltaPayload.Type; const TurnProposedCompletedPayload = Schema.Struct({  planMarkdown: TrimmedNonEmptyStringSchema,});export type TurnProposedCompletedPayload = typeof TurnProposedCompletedPayload.Type; const TurnDiffUpdatedPayload = Schema.Struct({  unifiedDiff: Schema.String,});export type TurnDiffUpdatedPayload = typeof TurnDiffUpdatedPayload.Type; export const ItemLifecyclePayload = Schema.Struct({  itemType: CanonicalItemType,  status: Schema.optional(RuntimeItemStatus),  title: Schema.optional(TrimmedNonEmptyStringSchema),  detail: Schema.optional(TrimmedNonEmptyStringSchema),  data: Schema.optional(Schema.Unknown),});export type ItemLifecyclePayload = typeof ItemLifecyclePayload.Type; const ContentDeltaPayload = Schema.Struct({  streamKind: RuntimeContentStreamKind,  delta: Schema.String,  contentIndex: Schema.optional(Schema.Int),  summaryIndex: Schema.optional(Schema.Int),});export type ContentDeltaPayload = typeof ContentDeltaPayload.Type; const RequestOpenedPayload = Schema.Struct({  requestType: CanonicalRequestType,  detail: Schema.optional(TrimmedNonEmptyStringSchema),  args: Schema.optional(Schema.Unknown),});export type RequestOpenedPayload = typeof RequestOpenedPayload.Type; const RequestResolvedPayload = Schema.Struct({  requestType: CanonicalRequestType,  decision: Schema.optional(TrimmedNonEmptyStringSchema),  resolution: Schema.optional(Schema.Unknown),});export type RequestResolvedPayload = typeof RequestResolvedPayload.Type; const UserInputQuestionOption = Schema.Struct({  label: TrimmedNonEmptyStringSchema,  description: TrimmedNonEmptyStringSchema,});export type UserInputQuestionOption = typeof UserInputQuestionOption.Type; export const UserInputQuestion = Schema.Struct({  id: TrimmedNonEmptyStringSchema,  header: TrimmedNonEmptyStringSchema,  question: TrimmedNonEmptyStringSchema,  options: Schema.Array(UserInputQuestionOption),  multiSelect: Schema.optional(Schema.Boolean).pipe(    Schema.withConstructorDefault(() => Option.some(false)),  ),});export type UserInputQuestion = typeof UserInputQuestion.Type; const UserInputRequestedPayload = Schema.Struct({  questions: Schema.Array(UserInputQuestion),});export type UserInputRequestedPayload = typeof UserInputRequestedPayload.Type; const UserInputResolvedPayload = Schema.Struct({  answers: UnknownRecordSchema,});export type UserInputResolvedPayload = typeof UserInputResolvedPayload.Type; const TaskStartedPayload = Schema.Struct({  taskId: RuntimeTaskId,  description: Schema.optional(TrimmedNonEmptyStringSchema),  taskType: Schema.optional(TrimmedNonEmptyStringSchema),});export type TaskStartedPayload = typeof TaskStartedPayload.Type; const TaskProgressPayload = Schema.Struct({  taskId: RuntimeTaskId,  description: TrimmedNonEmptyStringSchema,  summary: Schema.optional(TrimmedNonEmptyStringSchema),  usage: Schema.optional(Schema.Unknown),  lastToolName: Schema.optional(TrimmedNonEmptyStringSchema),});export type TaskProgressPayload = typeof TaskProgressPayload.Type; const TaskCompletedPayload = Schema.Struct({  taskId: RuntimeTaskId,  status: Schema.Literals(["completed", "failed", "stopped"]),  summary: Schema.optional(TrimmedNonEmptyStringSchema),  usage: Schema.optional(Schema.Unknown),});export type TaskCompletedPayload = typeof TaskCompletedPayload.Type; const HookStartedPayload = Schema.Struct({  hookId: TrimmedNonEmptyStringSchema,  hookName: TrimmedNonEmptyStringSchema,  hookEvent: TrimmedNonEmptyStringSchema,});export type HookStartedPayload = typeof HookStartedPayload.Type; const HookProgressPayload = Schema.Struct({  hookId: TrimmedNonEmptyStringSchema,  output: Schema.optional(Schema.String),  stdout: Schema.optional(Schema.String),  stderr: Schema.optional(Schema.String),});export type HookProgressPayload = typeof HookProgressPayload.Type; const HookCompletedPayload = Schema.Struct({  hookId: TrimmedNonEmptyStringSchema,  outcome: Schema.Literals(["success", "error", "cancelled"]),  output: Schema.optional(Schema.String),  stdout: Schema.optional(Schema.String),  stderr: Schema.optional(Schema.String),  exitCode: Schema.optional(Schema.Int),});export type HookCompletedPayload = typeof HookCompletedPayload.Type;

Lines 1–500 of 1016.