import { z } from "zod"; import type { Paths } from "../paths.js"; import { CloudHttpError } from "./http.js"; /** What an organisation API key looks like; machine tokens (`shm_…`) never do. One line, so it can only ever travel as a header. */ export declare const API_KEY_RE: RegExp; export declare class CloudApiError extends Error { /** The HTTP status the cloud answered (0: it was not reached), when it answered at all. */ readonly status?: number | undefined; /** The problem's `code` (`unknown_tool`, `forbidden`, `unknown_machine`, …). */ readonly code?: string | undefined; constructor(message: string, /** The HTTP status the cloud answered (0: it was not reached), when it answered at all. */ status?: number | undefined, /** The problem's `code` (`unknown_tool`, `forbidden`, `unknown_machine`, …). */ code?: string | undefined); } /** `GET /api/v1/me`: whose key it is. */ export declare const MeSchema: z.ZodObject<{ organisation: z.ZodObject<{ id: z.ZodString; slug: z.ZodOptional>; name: z.ZodString; }, z.core.$loose>; key: z.ZodObject<{ id: z.ZodString; name: z.ZodString; scopes: z.ZodArray; }, z.core.$loose>; role: z.ZodString; }, z.core.$loose>; export type Me = z.infer; export declare const FleetMachineSchema: z.ZodObject<{ id: z.ZodString; name: z.ZodString; status: z.ZodOptional>; mode: z.ZodOptional>; skillhook_version: z.ZodOptional>; link_state: z.ZodOptional>; last_seen_at: z.ZodOptional>; }, z.core.$loose>; export type FleetMachine = z.infer; export declare const MachineListSchema: z.ZodObject<{ machines: z.ZodArray>; mode: z.ZodOptional>; skillhook_version: z.ZodOptional>; link_state: z.ZodOptional>; last_seen_at: z.ZodOptional>; }, z.core.$loose>>; }, z.core.$loose>; export declare const FleetJobSchema: z.ZodObject<{ id: z.ZodString; local_id: z.ZodOptional>; machine_id: z.ZodOptional>; skill: z.ZodString; status: z.ZodString; outcome: z.ZodOptional>; trigger: z.ZodOptional>; runner: z.ZodOptional>; model: z.ZodOptional>; created_at: z.ZodOptional>; duration_ms: z.ZodOptional>; cost_usd: z.ZodOptional>; waiting_for_human: z.ZodOptional>; question: z.ZodOptional>>; }, z.core.$loose>>>; answer: z.ZodOptional>; by: z.ZodOptional>; }, z.core.$loose>>>; progress: z.ZodOptional>; percent: z.ZodOptional>; }, z.core.$loose>>>; response: z.ZodOptional>; summary: z.ZodOptional>; }, z.core.$loose>>>; failure: z.ZodOptional>; }, z.core.$loose>>>; result: z.ZodOptional>; dashboard_url: z.ZodOptional>; }, z.core.$loose>; export type FleetJob = z.infer; export declare const JobListSchema: z.ZodObject<{ jobs: z.ZodArray>; machine_id: z.ZodOptional>; skill: z.ZodString; status: z.ZodString; outcome: z.ZodOptional>; trigger: z.ZodOptional>; runner: z.ZodOptional>; model: z.ZodOptional>; created_at: z.ZodOptional>; duration_ms: z.ZodOptional>; cost_usd: z.ZodOptional>; waiting_for_human: z.ZodOptional>; question: z.ZodOptional>>; }, z.core.$loose>>>; answer: z.ZodOptional>; by: z.ZodOptional>; }, z.core.$loose>>>; progress: z.ZodOptional>; percent: z.ZodOptional>; }, z.core.$loose>>>; response: z.ZodOptional>; summary: z.ZodOptional>; }, z.core.$loose>>>; failure: z.ZodOptional>; }, z.core.$loose>>>; result: z.ZodOptional>; dashboard_url: z.ZodOptional>; }, z.core.$loose>>; next_before: z.ZodOptional>; }, z.core.$loose>; export declare const JobDetailSchema: z.ZodObject<{ job: z.ZodObject<{ id: z.ZodString; local_id: z.ZodOptional>; machine_id: z.ZodOptional>; skill: z.ZodString; status: z.ZodString; outcome: z.ZodOptional>; trigger: z.ZodOptional>; runner: z.ZodOptional>; model: z.ZodOptional>; created_at: z.ZodOptional>; duration_ms: z.ZodOptional>; cost_usd: z.ZodOptional>; waiting_for_human: z.ZodOptional>; question: z.ZodOptional>>; }, z.core.$loose>>>; answer: z.ZodOptional>; by: z.ZodOptional>; }, z.core.$loose>>>; progress: z.ZodOptional>; percent: z.ZodOptional>; }, z.core.$loose>>>; response: z.ZodOptional>; summary: z.ZodOptional>; }, z.core.$loose>>>; failure: z.ZodOptional>; }, z.core.$loose>>>; result: z.ZodOptional>; dashboard_url: z.ZodOptional>; }, z.core.$loose>; }, z.core.$loose>; /** Which front end of skillhook calls (`skillhook cloud …` or `skillhook mcp --cloud`): the cloud attributes its checkout links to it (ref=agent-cli, agent-mcp). */ export type SkillhookClient = "cli" | "mcp"; export declare const CLIENT_HEADER = "x-skillhook-client"; export interface ApiCredentials { key: string | undefined; /** The cloud the key was checked against at login; unset for a key kept by skillhook 0.6 or given without one. */ url: string | undefined; } /** * `SKILLHOOK_CLOUD_API_KEY` and its cloud: from the environment (CI) with `SKILLHOOK_CLOUD_API_URL` there, or the cloud * login kept with the same key; else both from `.env`, where login keeps them. A key without a cloud of its own (kept by * skillhook 0.6, or set in the environment alone) goes to the machine's cloud, `SKILLHOOK_CLOUD_URL` or `cloud.url`. */ export declare function storedApiCredentials(paths: Paths, env: NodeJS.ProcessEnv): ApiCredentials; /** * Keeps a key in `.env` (mode 600) with the cloud it was checked against, as `skillhook cloud login` does (and the * `skillhook_cloud_setup` tool after a browser sign-in); it goes to that cloud and nowhere else from then on. */ export declare function keepApiKey(paths: Paths, key: string, url: string): void; export interface FleetClient { /** The cloud the requests go to. */ url: string; /** `GET /api/v1`: the parsed answer and the answer as the cloud sent it (what `--json` prints); `timeoutMs` defaults to 20 s. */ get(path: string, schema: z.ZodType, options?: { timeoutMs?: number; }): Promise<{ data: T; raw: unknown; }>; /** `POST /api/v1` with a JSON body; `timeoutMs` for calls that wait for a machine (default 20 s). */ post(path: string, body: unknown, schema: z.ZodType, options?: { timeoutMs?: number; }): Promise<{ data: T; raw: unknown; status: number; }>; } /** * A client with the key for the cloud it was checked against (`credentials.url`; `options.url` at login), else the * machine's cloud (`SKILLHOOK_CLOUD_URL`, `cloud.url`, else Skillhook Cloud's own) for a key that has none; refused under * `SKILLHOOK_NO_CLOUD`, without a well-formed key, or to a URL that is not https. A key login kept never follows a * `cloud.url` changed after it. */ /** A request the cloud refused or failed, as `skillhook feedback report --last` attaches it. */ export interface ApiFailure { at: string; url: string; method: "GET" | "POST"; path: string; status: number; code: string; message: string; request_id?: string; } export declare function fleetClient(env: NodeJS.ProcessEnv, cloud: { url?: string; }, credentials: ApiCredentials, options?: { fetchImpl?: typeof fetch; url?: string; client?: SkillhookClient; onFailure?: (failure: ApiFailure) => void; }): FleetClient; /** What a person runs to keep a key for `url`: `--url` only for a cloud other than Skillhook Cloud's own. */ export declare function loginCommand(url: string): string; /** A refused key says to log in again, a missing scope says which, an unreachable cloud where it was looked for. */ export declare function describeApiFailure(error: CloudHttpError, url: string, method?: "GET" | "POST"): string; /** Machine names by id, for tables; ids stay ids when the list cannot be read. */ export declare function machineNames(client: FleetClient): Promise>;