/** * Shared HTTP helpers for ab-api endpoints. * * Centralizes the auth contract (X-Priv-Token + x-invoke-skill / x-invoke-agent / * x-conversation-id), business-code error handling (result.code != 0), and the * env var resolution order that every Python skill used to duplicate. * * Token resolution order (high → low), shared with the CLI auth commands via * src/auth/resolve.ts: * 1. opts.privateToken — caller override (maps to --token/--priv-token) * 2. process.env.PRIV_TOKEN — process env (CI / agent-embedded hosts) * 3. Credential_Store[apiBaseUrl] — written by `remixmate login` * (none) → throws SkillError — non-interactive failure * * Base URL resolution: * 1. opts.apiBaseUrl — caller override * 2. process.env.MM_API_BASE_URL — process env (point at local/staging here) * 3. process.env.MM_BACKEND_API_URL — ab-agent's convention (back-compat) * 4. https://api.remixmate.ai/api — production default (zero-config) */ import { type Billing } from './billing.js'; export { SkillError, EXIT } from './errors.js'; /** * Resolve the ab-api base URL the same way for authenticated and device-flow calls. * * `MM_BACKEND_API_URL` is honored because several Python skills already fall back * to it (registry_loader, render_job_client, _vod_polling). Since runner.ts now * injects the resolved base URL into those child processes, leaving it out here * would let a prod default silently override an ab-agent-injected backend. */ export declare function resolveApiBaseUrl(flag?: string): string; export interface HttpContext { apiBaseUrl: string; privateToken: string; skillName: string; agentName?: string; conversationId?: string; } export declare function resolveHttpContext(skillName: string, opts?: { apiBaseUrl?: string; privateToken?: string; /** * Token already resolved by the dispatcher's auth preflight (runner.ts). * Reusing it avoids a second credential-store read — and, more importantly, * a second device-flow attempt — per skill invocation. */ preflightToken?: string; }): Promise; export interface MmResponse { code: number; msg?: string; data?: T; /** Present only on responses that charged credits — see billing.ts. */ billing?: Billing; } /** * POST JSON to ab-api and return the parsed business payload. * Throws SkillError on HTTP errors or business code != 0. */ export declare function mmPost(ctx: HttpContext, pathOrUrl: string, body: unknown, opts?: { timeoutMs?: number; }): Promise; /** * Generic polling helper. Invokes `probe()` immediately, then every * `intervalMs`, until it returns a non-null value or `timeoutMs` elapses. * Probing first (rather than sleeping first) avoids a wasted initial interval * when the backend job is already complete. */ export declare function pollUntil(probe: () => Promise, opts?: { intervalMs?: number; timeoutMs?: number; }): Promise;