import type { BrokerLedgerLike } from '../economy/auto-topup' /** * A listed inference service from a provider catalog (0G serving-broker * `listService()` for Direct; the public `/v1/models` list for Router). */ export interface ListedService { provider: string url?: string endpoint?: string model: string serviceType?: string inputPrice?: bigint outputPrice?: bigint verifiability?: string [k: string]: unknown } /** * Provider-specific seam for the OpenAI-compatible completion call. * * {@link OGComputeBrain} owns everything provider-agnostic: the tool loop, the * ``/dash sanitizers, compaction, channel history + persistence, and * the actual `fetch` + request-body build + response parse. A * `CompletionTransport` owns ONLY the three things that differ per provider: * * 1. endpoint + model resolution ({@link init} → {@link baseUrl}/{@link modelId}) * 2. per-request auth headers ({@link authHeaders}) * 3. HTTP-error mapping ({@link mapHttpError}) * * Direct (0G serving-broker, EIP-712 per-request vouchers) is the default impl * (`DirectTransport`) and is what every existing caller gets when no transport * is injected. The 0G Router (OpenAI-compatible gateway, `Bearer sk-`) is the * opt-in second impl (`RouterTransport`). Keeping the fetch + parse shared is * what makes the Direct path bit-identical after extraction. */ export interface CompletionTransport { /** Idempotent. Resolve {@link baseUrl} + {@link modelId} + any auth/session setup. */ init(): Promise /** Base URL for the OpenAI-compatible endpoint (no trailing slash). Valid after {@link init}. */ readonly baseUrl: string /** Model id to send in the request body. Valid after {@link init}. */ readonly modelId: string /** * Provider-specific auth headers for ONE completion POST. `lastContent` is * the last message's content; Direct binds it into the per-request EIP-712 * voucher, Router ignores it (Bearer auth is content-independent). */ authHeaders(lastContent: string): Promise> /** * Map a non-OK HTTP completion response into a typed Error, or `null` to let * the caller throw a generic `Brain HTTP ` error. */ mapHttpError(status: number, body: string): Error | null /** * Whether the brain should strip inline `...` blocks from * `content`. True for Router (MiniMax-M3 emits CoT inline); false/undefined * for Direct so the Direct path stays byte-identical (qwen routes CoT into * `reasoning_content`, not `content`). */ readonly stripInlineThink?: boolean /** * Called by the brain on an HTTP 401/403 (auth) from a completion. Re-establish * credentials (e.g. Router re-mints its sk- via SIWE) and return `true` if the * request should be retried once. Absent/`false` → no retry (Direct's * per-request voucher never expires, so it has none). */ reprovision?(): Promise /** * The prepaid-credit ledger object the auto-topup manager consumes, or * `null` when N/A. Direct returns `broker.ledger`; Router returns `null` * (it has no serving-broker ledger, the Payment Layer is funded separately). */ getLedger(): BrokerLedgerLike | null /** Live prepaid balance in 0G, or `null` on failure / when N/A. */ getLedgerBalance(): Promise /** Live model/service catalog. */ listServices(): Promise }