/** * @fileoverview Core API client (isomorphic HTTP + SSE wrappers) * Simplicity first: minimal surface needed for CLI/MCP/Dashboard. */ import type { CrashReport, LogRecord } from "@ai-kod/common"; import type { SSEMessage } from "./lib/sse.js"; export interface ApiClientOptions { baseUrl: string; token?: string; fetchImpl?: typeof fetch; } export interface StreamOptions { eventTypes?: string[]; priority?: string; taskId?: string; cursor?: string; initial?: number; blockMs?: number; signal?: AbortSignal; } export interface LogsReadOptions { sources?: string[]; from?: string; to?: string; level?: string[]; taskId?: string; stepId?: string; process?: string; limit?: number; } export interface LogsTailOptions { sources?: string[]; from?: string; to?: string; level?: string[]; taskId?: string; stepId?: string; process?: string; initial?: number; timeoutMs?: number; heartbeatMs?: number; signal?: AbortSignal; } export interface ActiveTailSessionInfo { sessionId: string; connectionId: string; sources: string[]; startedAt: string; lastHeartbeatAt: string; entriesEmitted: number; clientIp?: string | null; userAgent?: string; } export interface LogsStreamsMetadata { eventStreamLength: number | null; tailLimit: number; activeTailSessions?: { count: number; example: ActiveTailSessionInfo[]; }; } export interface LogsStreamsResponse { success: boolean; sources: string[]; metadata?: LogsStreamsMetadata; timestamp?: string; } export interface LogsReadResponse { success: true; entries: LogRecord[]; pagination: { limit: number; fetched: number; }; timestamp: string; } export interface LogsTailHeartbeat { type: "heartbeat"; connectionId: string; sessionId: string; lastActivityAt: string; entriesEmitted: number; timestamp: string; } export interface LogsTailConnection { type: "connection"; connectionId: string; timestamp: string; } export interface LogsTailEnd { type: "end"; reason: string; timestamp: string; } export interface LogsTailEntry { type: "entry"; entry: T; } export interface LogsTailUnknown { type: "unknown"; raw: SSEMessage; } export type ParsedLogsTailMessage = LogsTailConnection | LogsTailHeartbeat | LogsTailEnd | LogsTailEntry | LogsTailUnknown; export interface LogsTailStream extends AsyncIterable> { close(): void; } export interface TasksListOptions { testOnly?: boolean; testSuite?: string; testSessionId?: string; } export interface TaskGlobalResponse { success: boolean; data: { taskId: string; global: Record; updated_at: string; }; correlationId?: string; } export interface TaskCrashReportListItem { reportId: string; filename: string; absolutePath: string; createdAt: string; size: number; scope: "task" | "step"; stepId?: string; } export interface TaskCrashReportsResponse { success: boolean; data: { taskId: string; reports: TaskCrashReportListItem[]; }; correlationId?: string; } export interface TaskCrashReportResponse { success: boolean; data: { taskId: string; scope: "task" | "step"; stepId?: string; report: CrashReport; }; correlationId?: string; } export interface WorkflowsListOptions { folder?: string; } export interface WorkflowInputSchemaResponse { success: boolean; data: { workflow_id: string; schema_available: boolean; schema_id?: string; schema_kind?: string; schema_version?: number; json_schema: Record; template: Record; required: string[]; definitions: Array>; files: { schema: string; template: string; }; }; } export type WorkflowItemKind = "bundle" | "package" | "prompt" | "mcp" | "skills"; export type WorkflowInstallMode = "copy" | "link"; export type WorkflowItemSource = { type: "git"; provider: string; repository: string; ref: string; commit: string; protocol?: "https" | "ssh"; } | { type: "path"; path: string; } | { type: "bundle"; bundleName: string; bundlePath: string; }; export interface WorkflowItemMetadata { id: string; kind: WorkflowItemKind; name: string; version: string; path: string; relativePath: string; installedAt: string; updatedAt: string; source: WorkflowItemSource; installMode: WorkflowInstallMode; integrity: string; providedBy?: { kind: "bundle"; name: string; }; required?: boolean; labels?: string[]; bundle?: { id: string; version: string; namespace?: string; manifestPath: string; defaultWorkflowId?: string | null; defaultWorkflowFile?: string | null; }; } export interface WorkflowInstallPayload { kind: WorkflowItemKind; repo: string; ref?: string; name?: string; provider?: string; subPath?: string; protocol?: "https" | "ssh"; depth?: number; force?: boolean; } export interface WorkflowUninstallPayload { kind: WorkflowItemKind; name: string; } export interface WorkflowListOptions { kind?: WorkflowItemKind; } export interface WorkflowListResponse { items: WorkflowItemMetadata[]; } export interface McpStatusResponse { item: WorkflowItemMetadata; manifest: unknown; manifestPath: string; requiredTools: string[]; } export declare function createClient(options: ApiClientOptions): { /** Health endpoint */ health: { get: () => Promise; }; workflow: { install: (payload: WorkflowInstallPayload) => Promise; uninstall: (payload: WorkflowUninstallPayload) => Promise<{ removed: boolean; }>; list: (options?: WorkflowListOptions) => Promise; workflows: () => Promise; packages: () => Promise; mcpStatus: (name: string) => Promise; }; /** V7 events */ events: { /** * Connect to SSE event stream (JSONL per event). * Returns an async iterator of SSEMessage, and exposes close() via controller. */ stream: (opts?: StreamOptions) => AsyncIterable & { close(): void; }; /** Stats */ stats: () => Promise; }; /** Fire WORKFLOW_STARTING via V7 events facade */ workflows: { run: (workflowId: string, payload: { inputs?: Record; prompt?: unknown; runMode?: "default" | "step_by_step"; testMetadata?: Record; engineProfile?: string | null; engineOptions?: Record; engineOverride?: { engine?: string; profile?: string | null; options?: Record; } | null; }) => Promise; runStarting: (payload: { taskId: string; workflowId: string; inputs?: Record; }) => Promise; list: (opts?: WorkflowsListOptions) => Promise; get: (workflowId: string) => Promise; getLayout: (workflowId: string) => Promise; relayout: (workflowId: string, payload?: { direction?: "DOWN" | "RIGHT"; }) => Promise; getInputSchema: (workflowId: string) => Promise; }; /** Tasks facade (MVP) */ tasks: { list: (opts?: TasksListOptions) => Promise; get: (taskId: string) => Promise; global: (taskId: string) => Promise; listCrashReports: (taskId: string) => Promise; getCrashReport: (taskId: string, reportId: string) => Promise; listSteps: (taskId: string) => Promise; getStepFiles: (taskId: string, stepId: string) => Promise; pause: (taskId: string) => Promise; resume: (taskId: string) => Promise; stop: (taskId: string) => Promise; }; steps: { getExecution: (taskId: string, stepId: string) => Promise; rerun: (taskId: string, stepId: string) => Promise; run: (taskId: string, stepId: string, mode?: "default" | "step_by_step") => Promise; streamLogs: (taskId: string, stepId: string, opts?: { signal?: AbortSignal; }) => AsyncIterable & { close(): void; }; }; workers: { list: () => Promise; get: (workerId: string) => Promise; }; logs: { /** Describe available streams (MVP: events stream only) */ streams: () => Promise; /** Read recent log entries with optional filters */ read: (opts?: LogsReadOptions) => Promise; /** Tail logs via SSE with optional filters */ tail: (opts?: LogsTailOptions) => LogsTailStream; }; system: { stats: () => Promise; versions: () => Promise; }; }; export type { SSEMessage } from "./lib/sse.js"; export declare function parseLogsTailMessage(message: SSEMessage): ParsedLogsTailMessage | undefined;