| 1 | export type FleetRunId = string; |
| 2 | export type FleetRunStatus = |
| 3 | | "pending" |
| 4 | | "queued" |
| 5 | | "running" |
| 6 | | "paused" |
| 7 | | "completed" |
| 8 | | "failed" |
| 9 | | "cancelled"; |
| 10 | |
| 11 | export type FleetRuntimeTarget = "this_computer" | "another_computer" | "cloud"; |
| 12 | export type FleetWorkflowKind = "parallel"; |
| 13 | |
| 14 | export interface FleetWorkflowDescriptor { |
| 15 | id: string; |
| 16 | kind: FleetWorkflowKind; |
| 17 | } |
| 18 | |
| 19 | export type FleetWorkerStatus = |
| 20 | | "unknown" |
| 21 | | "online" |
| 22 | | "busy" |
| 23 | | "offline" |
| 24 | | "unhealthy" |
| 25 | | "draining" |
| 26 | | "retired"; |
| 27 | |
| 28 | export type FleetArtifactKind = |
| 29 | | "log" |
| 30 | | "patch" |
| 31 | | "test_result" |
| 32 | | "report" |
| 33 | | "checkpoint" |
| 34 | | "receipt" |
| 35 | | string; |
| 36 | |
| 37 | export interface FleetStatusSummary { |
| 38 | runs: number; |
| 39 | queued: number; |
| 40 | running: number; |
| 41 | completed: number; |
| 42 | partial: number; |
| 43 | failed: number; |
| 44 | restarted: number; |
| 45 | escalated: number; |
| 46 | transport_failed: number; |
| 47 | task_failed: number; |
| 48 | verifier_failed: number; |
| 49 | cancelled: number; |
| 50 | stale: number; |
| 51 | workers: Record<string, FleetWorkerStatus>; |
| 52 | } |
| 53 | |
| 54 | export interface FleetTaskStatusSummary { |
| 55 | task_id: string; |
| 56 | status: "enqueued" | "leased" | "completed" | "failed" | "cancelled"; |
| 57 | leased_to?: string | null; |
| 58 | attempts: number; |
| 59 | } |
| 60 | |
| 61 | export interface FleetRunSummary { |
| 62 | id: string; |
| 63 | name: string; |
| 64 | lifecycle_status: FleetRunStatus; |
| 65 | status: FleetStatusSummary; |
| 66 | target?: FleetRuntimeTarget | null; |
| 67 | workflow?: FleetWorkflowDescriptor | null; |
| 68 | roles: string[]; |
| 69 | task_count: number; |
| 70 | worker_count: number; |
| 71 | tasks: FleetTaskStatusSummary[]; |
| 72 | labels: Record<string, string>; |
| 73 | created_at: string; |
| 74 | updated_at?: string | null; |
| 75 | completed_at?: string | null; |
| 76 | } |
| 77 | |
| 78 | export interface FleetRunDetail extends FleetRunSummary { |
| 79 | task_specs: FleetTaskSpec[]; |
| 80 | worker_specs: FleetWorkerSpec[]; |
| 81 | } |
| 82 | |
| 83 | export interface FleetRunsResponse { |
| 84 | status: FleetStatusSummary; |
| 85 | runs: FleetRunSummary[]; |
| 86 | } |
| 87 | |
| 88 | export interface FleetTaskSpec { |
| 89 | id: string; |
| 90 | name: string; |
| 91 | description?: string | null; |
| 92 | objective?: string | null; |
| 93 | instructions: string; |
| 94 | worker?: FleetTaskWorkerProfile | null; |
| 95 | workspace?: FleetWorkspaceRequirements | null; |
| 96 | input_files?: string[]; |
| 97 | context?: string[]; |
| 98 | budget?: FleetTaskBudget | null; |
| 99 | tags?: string[]; |
| 100 | expected_artifacts?: FleetArtifactKind[]; |
| 101 | scorer?: Record<string, unknown> | null; |
| 102 | retry_policy?: Record<string, unknown> | null; |
| 103 | alert_policy?: FleetAlertPolicy | null; |
| 104 | timeout_seconds?: number | null; |
| 105 | metadata?: Record<string, unknown>; |
| 106 | } |
| 107 | |
| 108 | export interface FleetTaskWorkerProfile { |
| 109 | agent_profile?: string | null; |
| 110 | role?: string | null; |
| 111 | loadout?: string | null; |
| 112 | model_class?: string | null; |
| 113 | model?: string | null; |
| 114 | tool_profile?: string | null; |
| 115 | tools?: string[]; |
| 116 | capabilities?: string[]; |
| 117 | } |
| 118 | |
| 119 | export interface FleetWorkspaceRequirements { |
| 120 | root?: string | null; |
| 121 | required_files?: string[]; |
| 122 | writable_paths?: string[]; |
| 123 | environment?: FleetEnvironmentRequirements | null; |
| 124 | } |
| 125 | |
| 126 | export interface FleetEnvironmentRequirements { |
| 127 | required?: string[]; |
| 128 | allowlist?: string[]; |
| 129 | } |
| 130 | |
| 131 | export interface FleetTaskBudget { |
| 132 | max_tokens?: number | null; |
| 133 | max_tool_calls?: number | null; |
| 134 | max_seconds?: number | null; |
| 135 | } |
| 136 | |
| 137 | export interface FleetAlertPolicy { |
| 138 | events?: string[]; |
| 139 | channels?: Array<Record<string, unknown>>; |
| 140 | after_attempts?: number | null; |
| 141 | after_minutes_stale?: number | null; |
| 142 | } |
| 143 | |
| 144 | export interface FleetWorkerSpec { |
| 145 | id: string; |
| 146 | name: string; |
| 147 | host: Record<string, unknown>; |
| 148 | labels?: Record<string, string>; |
| 149 | capabilities?: string[]; |
| 150 | max_concurrent_tasks?: number | null; |
| 151 | } |
| 152 | |
| 153 | export interface FleetArtifactRef { |
| 154 | kind: FleetArtifactKind; |
| 155 | path: string; |
| 156 | checksum?: string | null; |
| 157 | mime_type?: string | null; |
| 158 | size_bytes?: number | null; |
| 159 | } |
| 160 | |
| 161 | export type FleetWorkerEventPayload = |
| 162 | | { state: "queued" } |
| 163 | | { state: "leased"; lease_expires_at?: string | null } |
| 164 | | { state: "starting" } |
| 165 | | { state: "running" } |
| 166 | | { state: "model_wait"; model?: string | null } |
| 167 | | { state: "running_tool"; tool: string; call_id?: string | null } |
| 168 | | { state: "heartbeat"; cpu_percent?: number | null; memory_mb?: number | null } |
| 169 | | ({ state: "artifact" } & FleetArtifactRef) |
| 170 | | { state: "completed"; exit_code?: number | null; summary?: string | null } |
| 171 | | { state: "failed"; reason: string; recoverable?: boolean } |
| 172 | | { state: "cancelled"; cancelled_by?: string | null } |
| 173 | | { state: "interrupted"; signal?: string | null } |
| 174 | | { state: "stale"; last_heartbeat_at?: string | null } |
| 175 | | { state: "restarted"; restart_count?: number } |
| 176 | | { state: "escalated"; channel: string; alert_id?: string | null }; |
| 177 | |
| 178 | export interface FleetWorkerEvent { |
| 179 | seq: number; |
| 180 | run_id: string; |
| 181 | worker_id: string; |
| 182 | task_id: string; |
| 183 | timestamp: string; |
| 184 | label?: string; |
| 185 | payload: FleetWorkerEventPayload; |
| 186 | extra?: Record<string, unknown>; |
| 187 | } |
| 188 | |
| 189 | export interface FleetWorkerInspection { |
| 190 | worker_id: string; |
| 191 | status: FleetWorkerStatus; |
| 192 | run_id?: string | null; |
| 193 | task_id?: string | null; |
| 194 | objective?: string | null; |
| 195 | role?: string | null; |
| 196 | host?: Record<string, unknown> | null; |
| 197 | latest_heartbeat_at?: string | null; |
| 198 | latest_event?: FleetWorkerEvent | null; |
| 199 | artifacts: FleetArtifactRef[]; |
| 200 | last_error?: string | null; |
| 201 | alert_state?: Record<string, unknown> | null; |
| 202 | } |
| 203 | |
| 204 | export interface FleetWorkersResponse { |
| 205 | run_id: string; |
| 206 | workers: FleetWorkerInspection[]; |
| 207 | } |
| 208 | |
| 209 | export interface FleetWorkerActionResponse { |
| 210 | action: "interrupt" | "restart" | "stop"; |
| 211 | worker: FleetWorkerInspection; |
| 212 | } |
| 213 | |
| 214 | export interface StopFleetRunResponse { |
| 215 | action: "stop"; |
| 216 | run_id: string; |
| 217 | stopped: number; |
| 218 | status: FleetStatusSummary; |
| 219 | } |
| 220 | |
| 221 | export interface ManagedFleetRole { |
| 222 | name: string; |
| 223 | agent_profile?: string | null; |
| 224 | } |
| 225 | |
| 226 | export interface ManagedFleetWorkflow extends FleetWorkflowDescriptor { |
| 227 | tasks: FleetTaskSpec[]; |
| 228 | } |
| 229 | |
| 230 | export interface FleetRunCreateSpec { |
| 231 | name?: string; |
| 232 | target: FleetRuntimeTarget; |
| 233 | roles: ManagedFleetRole[]; |
| 234 | workflow: ManagedFleetWorkflow; |
| 235 | labels?: Record<string, string>; |
| 236 | max_workers?: number; |
| 237 | } |
| 238 | |
| 239 | export interface CreateFleetRunResponse { |
| 240 | execution: "awaiting_start"; |
| 241 | run: FleetRunDetail; |
| 242 | warnings: string[]; |
| 243 | } |
| 244 | |
| 245 | export interface StartFleetRunResponse { |
| 246 | action: "start"; |
| 247 | execution: "scheduled"; |
| 248 | run_id: string; |
| 249 | target: "this_computer"; |
| 250 | /** Leasing begins only after the scheduled driver owns the run. */ |
| 251 | leased: 0; |
| 252 | queued: number; |
| 253 | worker_ids: string[]; |
| 254 | } |
| 255 | |
| 256 | export interface FleetRuntimeEvent { |
| 257 | cursor: string; |
| 258 | event: string; |
| 259 | run_id: string; |
| 260 | worker_id?: string | null; |
| 261 | task_id?: string | null; |
| 262 | timestamp?: string | null; |
| 263 | worker_seq?: number | null; |
| 264 | payload: Record<string, unknown>; |
| 265 | } |
| 266 | |
| 267 | export interface FleetStreamControlEvent { |
| 268 | event: |
| 269 | | "fleet.replay.truncated" |
| 270 | | "fleet.replay.cursor_unavailable" |
| 271 | | "fleet.stream.error"; |
| 272 | run_id?: string; |
| 273 | cursor?: never; |
| 274 | reload_projection?: boolean; |
| 275 | retryable?: boolean; |
| 276 | } |
| 277 | |
| 278 | export type FleetStreamEvent = FleetRuntimeEvent | FleetStreamControlEvent; |
| 279 | |
| 280 | export interface FleetEventReplay { |
| 281 | run_id: string; |
| 282 | events: FleetRuntimeEvent[]; |
| 283 | has_more: boolean; |
| 284 | history_truncated: boolean; |
| 285 | next_cursor?: string | null; |
| 286 | } |
| 287 | |
| 288 | export interface FleetEventOptions { |
| 289 | after?: string; |
| 290 | limit?: number; |
| 291 | } |
| 292 | |
| 293 | export interface RuntimeClientOptions { |
| 294 | baseUrl?: string; |
| 295 | token?: string; |
| 296 | fetch?: typeof fetch; |
| 297 | } |
| 298 | |
| 299 | export class RuntimeApiError extends Error { |
| 300 | status?: number; |
| 301 | method?: string; |
| 302 | path?: string; |
| 303 | body?: string; |
| 304 | } |
| 305 | |
| 306 | export class RuntimeCapabilityError extends RuntimeApiError { |
| 307 | capability: string; |
| 308 | } |
| 309 | |
| 310 | export class CodeWhaleRuntimeClient { |
| 311 | constructor(options?: RuntimeClientOptions); |
| 312 | createFleetRun(spec: FleetRunCreateSpec): Promise<CreateFleetRunResponse>; |
| 313 | startFleetRun(runId: FleetRunId): Promise<StartFleetRunResponse>; |
| 314 | replayFleetEvents(runId: FleetRunId, options?: FleetEventOptions): Promise<FleetEventReplay>; |
| 315 | listFleetRuns(): Promise<FleetRunsResponse>; |
| 316 | getFleetRun(runId: FleetRunId): Promise<FleetRunDetail>; |
| 317 | listFleetWorkers(runId: FleetRunId): Promise<FleetWorkersResponse>; |
| 318 | getFleetWorker(workerId: string): Promise<FleetWorkerInspection>; |
| 319 | interruptWorker(workerId: string): Promise<FleetWorkerActionResponse>; |
| 320 | stopWorker(workerId: string): Promise<FleetWorkerActionResponse>; |
| 321 | restartWorker(workerId: string): Promise<FleetWorkerActionResponse>; |
| 322 | stopFleetRun(runId: FleetRunId): Promise<StopFleetRunResponse>; |
| 323 | fleetEvents( |
| 324 | runId: FleetRunId, |
| 325 | options?: FleetEventOptions & { path?: string }, |
| 326 | ): AsyncIterable<FleetStreamEvent>; |
| 327 | } |
| 328 | |
| 329 | export function createRuntimeClient(options?: RuntimeClientOptions): CodeWhaleRuntimeClient; |
| 330 |