/** * API Client for Genspark Tool CLI */ import type { DeveloperProject, DeveloperPreflight } from './developer-contract.js'; import type { GlobalOptions, ApiResponse, ToolListResponse, UserInfo, FileUploadUrlRequest, FileUploadUrlResponse, FileDownloadRequest, FileDownloadResponse, GensparkCodeSkillsResponse } from './types.js'; /** * Make an unauthenticated request to the backend. * Used for device-flow auth endpoints that don't require an API key. */ export declare function unauthenticatedRequest(baseUrl: string, endpoint: string, method?: 'GET' | 'POST', body?: unknown): Promise; /** Hard ceiling on one automatic rate-limit wait (ms). */ export declare const MAX_RATE_LIMIT_WAIT_MS = 65000; export interface RateLimitDenial { /** Seconds the server told us to wait. */ retryAfter: number; message: string; instructionForAgent?: string; } /** * Read a 429 denial out of a response, or return null if it isn't one. * * The server sends both a standard `Retry-After` header and a `retry_after` * field in the NDJSON envelope; the header wins because a proxy may answer * without our body at all, and the body is the fallback for the reverse. * Both are ignored unless they parse to a positive finite number — a `0` * or a garbled value would otherwise license the immediate retry this * exists to stop (#61436). */ export declare function parseRateLimitDenial(status: number, headers: Headers, bodyText: string): RateLimitDenial | null; /** Milliseconds to sleep for a denial, capped and jittered. */ export declare function rateLimitWaitMs(denial: RateLimitDenial): number; /** * Error carrying the HTTP status behind a failed API call, so callers can * branch on auth failures (401/403) without parsing message strings. */ export declare class ApiHttpError extends Error { readonly httpStatus?: number; /** * Parsed `{detail: {code, message}}` from a structured developer error, when * the body carried one (e.g. `project_kind_mismatch`). Lets callers branch on * the server's own code instead of scraping the message string. */ readonly serverDetail?: { code?: string; message?: string; }; constructor(message: string, httpStatus?: number, serverDetail?: { code?: string; message?: string; }); } /** * One line for a non-2xx binary-route answer. The body is the router's * NDJSON error envelope (`{"status":"error","message":…}`), FastAPI's * `{"detail": "…"}` / `{"detail": {"code", "message"}}`, or plain text — * the message is lifted out so the agent reads WHY, not a JSON blob. */ export declare function describeHttpFailure(status: number, body: string): string; /** * Parse a developer API error body. The backend returns structured * `{"detail": {"code", "message"}}` for application errors (missing project, * kind mismatch, ...); a route that does not exist on this server answers with * a plain `{"detail": "Not Found"}` instead. `structured` is what tells the two * apart, so a real 404 like `project_not_found` is never reported as an * unsupported server. */ export declare function parseDeveloperErrorDetail(body: string): { structured: boolean; code?: string; message?: string; }; /** True when the error is an HTTP-level auth rejection (401/403). */ export declare function isAuthError(err: unknown): boolean; export declare class ApiClient { private baseUrl; private apiKey; private timeout; private debugMode; private projectId?; private invokedAs?; private options; constructor(options: GlobalOptions); getOptions(): GlobalOptions; /** * Record which CLI command form triggered the next request(s) — sent as * X-GSK-Invoked-As so the server can tell canonical from deprecated-legacy * invocations (the only signal deprecation-removal decisions can use; * tool names alone are identical across both forms). */ setInvokedAs(invokedAs: string): void; /** * Common headers for every authenticated request path (buffered AND * streaming — a header added in only one of them silently drops from * tool executions, which all go through the streaming path). */ private baseHeaders; /** Make one bounded request; creation and source writes must never be retried. */ private developerRequest; /** Explicitly create a project once, using the existing token identity. */ createDeveloperProject(kind: string, name: string): Promise; /** Fetch a project through the server's owner-only developer route. */ getDeveloperProject(id: string): Promise; /** Read advisory account checks without creating a project or sandbox. */ developerPreflight(kind: string, operation: string): Promise; /** Stream a ZIP to the selected project and return its unmodified source receipt. */ uploadHostedSource(filename: string, size: number): Promise>; private request; /** * Simple JSON request (non-streaming) for endpoints that return plain JSON. */ private requestJson; /** * List available tools with full schemas */ listTools(): Promise; /** * Execute any tool by name with arguments. * * Streams the NDJSON response so heartbeat lines reach the caller in * real time. Long-running tools (e.g. create_task) emit a heartbeat * every 5s; surfacing them via onProgress keeps bash wrappers that * track inactivity (Claude Code Bash tool, 2-min default) from * killing the process before the task completes (issue #30305). */ executeTool(toolName: string, args: Record, onProgress?: (msg: { [key: string]: unknown; }) => void): Promise; /** * Attach to a durable run's SSE stream. Only terminal ``meta`` is returned; * generated artifacts stay on the project referenced by result_summary. */ attachGskTaskRun(streamUrl: string, onEvent?: (eventType: string, data: Record) => void): Promise>; /** * Send a message to a task agent (streaming). * Calls the /agent_ask endpoint for multi-turn agent conversation. * Pass projectId=null for the first call to create a new project. * onMessage is called for each intermediate message (heartbeat, delta, tool_call) during processing. */ agentAsk(projectId: string | null, message: string, taskType: string, onMessage?: (msg: { [key: string]: unknown; }) => void, signal?: AbortSignal, useModel?: string): Promise; /** * Reconnect to an in-progress agent's event stream (streaming). * Returns the agent's response if still running, or {message: "no_running_agent"} if done. */ agentAskEvents(projectId: string, taskType: string, onMessage?: (msg: { [key: string]: unknown; }) => void, signal?: AbortSignal): Promise; /** * Export a task agent's artifact to a downloadable file (docx, pptx, xlsx). */ exportArtifact(projectId: string, taskType: string, format?: string): Promise; /** * Get a pre-signed URL for uploading a file */ getUploadUrl(params: FileUploadUrlRequest): Promise>; /** * Get a downloadable URL for a file wrapper URL */ getDownloadUrl(params: FileDownloadRequest): Promise>; /** * Authenticated GET of a binary tool-CLI route. Returns the raw Response so * the caller can stream the body to disk; no client-side timeout because * the body may be a GiB-scale attachment. A non-2xx answer is raised as an * ApiHttpError carrying the server's own message. */ fetchBinary(endpoint: string): Promise; /** * Get current user info (email, name, plan) */ getMe(): Promise; /** * Get OpenCode configuration JSON */ getOpencodeConfig(model?: string): Promise>; /** * Get the genspark-code (code sandbox) skill bundle */ getGensparkCodeSkills(): Promise; /** * Get Pi (pi.dev) config bundle: `{ models, settings, genspark }`. */ getPiConfig(model?: string): Promise>; /** * Streaming NDJSON request that processes lines as they arrive. * Calls onMessage for each intermediate message (heartbeat, delta, tool_call) * and returns the final result (identified by having a "status" field). */ requestStreaming(endpoint: string, body: unknown, onMessage: (msg: { [key: string]: unknown; }) => void, externalSignal?: AbortSignal): Promise>; } //# sourceMappingURL=client.d.ts.map