@llmnative/runner 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.js.map +1 -1
- package/dist/client.mjs.map +1 -1
- package/dist/setup-app/assets/{NetworkCanvasImpl-DIYuzg6x-Cvx1IqQZ.js → NetworkCanvasImpl-DIYuzg6x-CmSzOSsS.js} +1 -1
- package/dist/setup-app/assets/{index-Ce40a4eE.js → index-DlTuUME8.js} +3 -3
- package/dist/setup-app/assets/{index.es-9Zr7VidY.js → index.es-A5wBsXN0.js} +1 -1
- package/dist/setup-app/assets/{lucide-react-2gg5h5-W.js → lucide-react-CoEgBOt8.js} +1 -1
- package/dist/setup-app/index.html +1 -1
- package/dist/steps.js +1 -1
- package/dist/steps.mjs +2 -2
- package/dist/types/client/index.d.ts +2 -1
- package/install/coolify.yaml +2 -2
- package/install/install.sh +1 -1
- package/openapi/v1.yaml +3 -1
- package/package.json +1 -1
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":["RUNNER_KEY_PROVIDERS","RunnerError","code","status","extra","noCreditUntil","event","RunnerClient","options","scope","json","key","tenant","user","headers","response","path","body","text","data","name","project","approve","id","input","label","provider","request","tools","message","signal","callId","answer","reader","decoder","buffer","value","done","lines","line","PERSON_ROUTES","forwardToRunner","target","type","url","fetchImpl"],"sources":["../src/client/index.ts"],"sourcesContent":["// @llmnative/runner/client — the client of the API v1 of the LLMNative Runner, for the browser and for Node.\n//\n// A key never belongs in the browser of the people of a tenant: a host app talks to the runner from its backend\n// (`createRunnerProxy` forwards the requests of its signed-in people, adding the key, the tenant and the person),\n// and its pages use `RunnerClient` against that backend. The console of the runner and a personal app with a key of\n// its own use `RunnerClient` directly.\n\n/** The providers paid by use whose API key the runner keeps and opencode runs (ids of @llmnative/react). */\nexport const RUNNER_KEY_PROVIDERS = ['anthropic', 'openai', 'gemini', 'mistral', 'deepseek', 'openrouter'] as const;\nexport type RunnerKeyProvider = (typeof RUNNER_KEY_PROVIDERS)[number];\nexport type RunnerProvider = 'claude-code' | 'opencode-go' | 'opencode' | RunnerKeyProvider;\nexport type RunnerPermission = 'complete' | 'chat' | 'chat:tools' | 'accounts' | 'accounts:tenant' | 'act-as-user' | 'keys';\n\nexport type RunnerAccount = {\n provider: RunnerProvider;\n id: string;\n label?: string;\n /** When it was connected. */\n at: string;\n scope: 'user' | 'tenant';\n /** Out of credit until then (the limit of a subscription); absent when it has credit. */\n noCreditUntil?: string;\n};\n\nexport type RunnerModels = {\n /** `models`: the list a subscription serves; empty for a provider by use, which runs any model the client names. */\n providers: Array<{ id: RunnerProvider; kind: 'subscription' | 'usage'; models: string[]; accounts: number; available: number; yours: number; tenant: number }>;\n};\n\nexport type RunnerTenant = { id: string; name: string; createdAt: string; usersWithAccounts?: number };\nexport type RunnerKey = { id: string; kind: 'platform' | 'project'; tenant?: string; /** Platform keys: the project whose tenants (`<project>`, `<project>-…`) it owns. */ project?: string; name: string; permissions: RunnerPermission[]; createdAt: string; expiresAt: string | null };\n\nexport type RunnerStatus = {\n version: string;\n agentImage: string;\n url?: string;\n /** The project of the platform key asking: the tenants listed are its own only. */\n project?: string;\n load: { chats: number; answering: number; completions: number; maxChats: number };\n machine: { totalBytes: number; availableBytes: number; cpus: number };\n tenants: RunnerTenant[];\n};\n\n/** A pairing request made by a platform: `request` is its secret (keep it in the backend), `code` is shown on both sides. */\nexport type RunnerPairingRequest = { request: string; code: string; approveUrl: string; expiresAt: string; interval: number };\nexport type RunnerPairingPoll = { status: 'pending' | 'denied' | 'expired' } | { status: 'approved'; key: string; record: RunnerKey; version: string };\nexport type RunnerPairingRequestView = { code: string; name: string; project?: string; from?: string; createdAt: string; expiresAt: string };\nexport type RunnerHealth = { ok: boolean; version: string; chats: number; answering: number; completions: number; maxChats: number };\n\nexport type RunnerCompletionRequest = { provider: RunnerProvider; model: string; prompt: string; effort?: 'low' | 'medium' | 'high' | 'xhigh' | 'max' };\nexport type RunnerCompletion = { text: string; usage?: { inputTokens: number; outputTokens: number } };\n\nexport type RunnerChatTool = { name: string; description: string; inputSchema: Record<string, unknown>; endsTurn?: boolean };\nexport type RunnerChatModel = { provider: string; model: string; variant?: string; name?: string; effort?: string };\nexport type RunnerChatEvent =\n | { type: 'text'; text: string }\n | { type: 'reasoning'; text: string }\n | { type: 'step'; id: string; label: string; status: 'running' | 'done' }\n | { type: 'tool-call'; id: string; name: string; input: Record<string, unknown> }\n | { type: 'done' }\n | { type: 'error'; message: string };\n\n/** An error of the runner: its status and code (`no-credit`, `busy`…), and for `no-credit` until when. */\nexport class RunnerError extends Error {\n readonly status: number;\n readonly code: string;\n readonly until?: string;\n readonly detail?: string;\n\n constructor(status: number, code: string, extra: { until?: string; detail?: string } = {}) {\n super(code);\n this.name = 'RunnerError';\n this.status = status;\n this.code = code;\n if (extra.until) this.until = extra.until;\n if (extra.detail) this.detail = extra.detail;\n }\n}\n\n/** When a chat event says the accounts ran out of credit: until when (`no-credit:<iso>`). */\nexport const noCreditUntil = (event: RunnerChatEvent): string | undefined =>\n event.type === 'error' && event.message.startsWith('no-credit:') ? event.message.slice('no-credit:'.length) : undefined;\n\nexport type RunnerClientOptions = {\n /** The address of the runner (`https://runner.example.com`), or of the backend of the host that forwards to it. */\n url: string;\n /** A key of the runner (or the admin token in the console); none when the backend of the host adds it. */\n key?: string;\n /** With a platform key or the admin token: the tenant the requests are for. */\n tenant?: string;\n /** The person the requests are for (needs `act-as-user` with a project key). */\n user?: string;\n fetch?: typeof fetch;\n /** More headers for each request (the session of the host, for its backend). */\n headers?: () => Record<string, string> | Promise<Record<string, string>>;\n};\n\nexport class RunnerClient {\n readonly options: RunnerClientOptions;\n\n constructor(options: RunnerClientOptions) {\n this.options = { ...options, url: options.url.replace(/\\/+$/, '') };\n }\n\n /** The same runner for another tenant or person. */\n as(scope: { tenant?: string; user?: string }): RunnerClient {\n return new RunnerClient({ ...this.options, ...scope });\n }\n\n private async headers(json: boolean): Promise<Record<string, string>> {\n const { key, tenant, user, headers } = this.options;\n return {\n ...(json ? { 'content-type': 'application/json' } : {}),\n ...(key ? { authorization: `Bearer ${key}` } : {}),\n ...(tenant ? { 'x-runner-tenant': tenant } : {}),\n ...(user ? { 'x-runner-user': user } : {}),\n ...(await headers?.()),\n };\n }\n\n /** One request; its JSON, or a RunnerError. */\n async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const response = await (this.options.fetch ?? fetch)(`${this.options.url}${path}`, {\n method,\n headers: await this.headers(body !== undefined),\n ...(body !== undefined ? { body: JSON.stringify(body) } : {}),\n });\n const text = await response.text();\n let data: Record<string, unknown> = {};\n try {\n data = text ? JSON.parse(text) as Record<string, unknown> : {};\n } catch {\n // Not JSON (a proxy in between): said by its status.\n }\n if (!response.ok) {\n throw new RunnerError(response.status, typeof data.error === 'string' ? data.error : `http-${response.status}`, {\n ...(typeof data.until === 'string' ? { until: data.until } : {}),\n ...(typeof data.detail === 'string' ? { detail: data.detail } : {}),\n });\n }\n return data as T;\n }\n\n // ── Public ──────────────────────────────────────────────────────────────────────────────────────────────\n health(): Promise<RunnerHealth> {\n return this.request('GET', '/health');\n }\n\n /** A pairing code (printed by the installer) → a platform key, seen once. */\n /** `project`: the platform key owns only the tenants of that project (`<project>`, `<project>-…`). */\n pair(code: string, name?: string, project?: string): Promise<{ key: string; record: RunnerKey; version: string }> {\n return this.request('POST', '/v1/pair', { code, ...(name ? { name } : {}), ...(project ? { project } : {}) });\n }\n\n /**\n * Asks to connect (device flow): the admin of the runner approves it in the console at `approveUrl`, where the\n * same `code` is shown; meanwhile `pollPairing(request)` every `interval` seconds, until it gives the key.\n */\n requestPairing(name: string, project?: string): Promise<RunnerPairingRequest> {\n return this.request('POST', '/v1/pair/requests', { name, ...(project ? { project } : {}) });\n }\n\n pollPairing(request: string): Promise<RunnerPairingPoll> {\n return this.request('POST', '/v1/pair/requests/poll', { request });\n }\n\n info(): Promise<{ version: string; harnesses: string[]; capabilities: Record<string, boolean>; permissions: RunnerPermission[]; tenant?: string }> {\n return this.request('GET', '/v1/info');\n }\n\n // ── Admin token ─────────────────────────────────────────────────────────────────────────────────────────\n createPairing(): Promise<{ code: string; expiresAt: string }> {\n return this.request('POST', '/v1/admin/pairing');\n }\n\n async pairingRequests(): Promise<RunnerPairingRequestView[]> {\n return (await this.request<{ requests: RunnerPairingRequestView[] }>('GET', '/v1/admin/pairing/requests')).requests;\n }\n\n async answerPairing(code: string, approve: boolean): Promise<RunnerPairingRequestView> {\n return (await this.request<{ request: RunnerPairingRequestView }>('POST', `/v1/admin/pairing/requests/${encodeURIComponent(code)}/${approve ? 'approve' : 'deny'}`)).request;\n }\n\n /** The project of a platform key (null: every tenant, as keys made before 1.2). */\n async setKeyProject(id: string, project: string | null): Promise<RunnerKey> {\n return (await this.request<{ record: RunnerKey }>('PUT', `/v1/admin/keys/${encodeURIComponent(id)}/project`, { project })).record;\n }\n\n // ── Platform key ────────────────────────────────────────────────────────────────────────────────────────\n readonly platform = {\n status: (): Promise<RunnerStatus> => this.request('GET', '/v1/platform/status'),\n tenants: async (): Promise<RunnerTenant[]> => (await this.request<{ tenants: RunnerTenant[] }>('GET', '/v1/platform/tenants')).tenants,\n /** A tenant, with its first project key unless `key: false` (seen once: keep it in the backend). */\n createTenant: (id: string, options: { name?: string; key?: boolean; keyPermissions?: RunnerPermission[] } = {}): Promise<{ tenant: RunnerTenant; key?: string; keyRecord?: RunnerKey }> =>\n this.request('POST', '/v1/platform/tenants', { id, ...options }),\n removeTenant: async (id: string): Promise<boolean> => (await this.request<{ removed: boolean }>('DELETE', `/v1/platform/tenants/${encodeURIComponent(id)}`)).removed,\n keys: async (tenant: string): Promise<RunnerKey[]> => (await this.request<{ keys: RunnerKey[] }>('GET', `/v1/platform/tenants/${encodeURIComponent(tenant)}/keys`)).keys,\n createKey: (tenant: string, input: { name?: string; permissions?: RunnerPermission[]; expiresAt?: string | null } = {}): Promise<{ key: string; record: RunnerKey }> =>\n this.request('POST', `/v1/platform/tenants/${encodeURIComponent(tenant)}/keys`, input),\n revokeKey: async (tenant: string, id: string): Promise<boolean> => (await this.request<{ removed: boolean }>('DELETE', `/v1/platform/tenants/${encodeURIComponent(tenant)}/keys/${encodeURIComponent(id)}`)).removed,\n platformKeys: async (): Promise<RunnerKey[]> => (await this.request<{ keys: RunnerKey[] }>('GET', '/v1/platform/keys')).keys,\n revokePlatformKey: async (id: string): Promise<boolean> => (await this.request<{ removed: boolean }>('DELETE', `/v1/platform/keys/${encodeURIComponent(id)}`)).removed,\n };\n\n // ── Accounts of the person (or of the tenant) ───────────────────────────────────────────────────────────\n readonly accounts = {\n list: async (): Promise<{ scope: 'user' | 'tenant'; accounts: RunnerAccount[] }> => this.request('GET', '/v1/accounts'),\n /** The sign-in of a Claude subscription: open `url`, then give the code Anthropic shows to `finishClaudeLogin`. */\n startClaudeLogin: (): Promise<{ url: string }> => this.request('POST', '/v1/accounts/claude-code/login'),\n finishClaudeLogin: async (code: string, label?: string): Promise<RunnerAccount> =>\n (await this.request<{ account: RunnerAccount }>('POST', '/v1/accounts/claude-code/login/code', { code, ...(label ? { label } : {}) })).account,\n /** A token made elsewhere with `claude setup-token`. */\n addClaudeToken: async (token: string, label?: string): Promise<RunnerAccount> =>\n (await this.request<{ account: RunnerAccount }>('POST', '/v1/accounts/claude-code', { token, ...(label ? { label } : {}) })).account,\n /** A key: OpenCode Go/Zen, or the API key of a provider by use the runner keeps (opencode runs it). */\n addKey: async (provider: Exclude<RunnerProvider, 'claude-code'>, key: string, label?: string): Promise<RunnerAccount> =>\n (await this.request<{ account: RunnerAccount }>('POST', `/v1/accounts/${provider}`, { key, ...(label ? { label } : {}) })).account,\n remove: async (provider: RunnerProvider, id: string): Promise<boolean> =>\n (await this.request<{ removed: boolean }>('DELETE', `/v1/accounts/${provider}/${encodeURIComponent(id)}`)).removed,\n order: async (provider: RunnerProvider, ids: string[]): Promise<RunnerAccount[]> =>\n (await this.request<{ accounts: RunnerAccount[] }>('PUT', '/v1/accounts/order', { provider, ids })).accounts,\n };\n\n models(): Promise<RunnerModels> {\n return this.request('GET', '/v1/models');\n }\n\n complete(request: RunnerCompletionRequest): Promise<RunnerCompletion> {\n return this.request('POST', '/v1/complete', request);\n }\n\n // ── Chats ───────────────────────────────────────────────────────────────────────────────────────────────\n readonly chats = {\n /** A chat (id: 8 hex characters, chosen by the client), with the tools the harness may call. */\n start: (id: string, tools?: RunnerChatTool[]): Promise<{ id: string }> => this.request('POST', '/v1/chats', { id, ...(tools ? { tools } : {}) }),\n /** A message: its events as they come. Aborting the signal stops the harness. */\n send: (id: string, message: { text: string; model: RunnerChatModel; attachments?: Array<{ name: string; mimeType: string; base64: string }> }, signal?: AbortSignal): AsyncIterable<RunnerChatEvent> =>\n this.stream(`/v1/chats/${encodeURIComponent(id)}/messages`, message, signal),\n answerCall: async (id: string, callId: string, answer: { result?: unknown; isError?: boolean }): Promise<boolean> =>\n (await this.request<{ answered: boolean }>('POST', `/v1/chats/${encodeURIComponent(id)}/calls/${encodeURIComponent(callId)}`, answer)).answered,\n stop: async (id: string): Promise<boolean> => (await this.request<{ stopped: boolean }>('POST', `/v1/chats/${encodeURIComponent(id)}/stop`)).stopped,\n close: async (id: string): Promise<boolean> => (await this.request<{ closed: boolean }>('DELETE', `/v1/chats/${encodeURIComponent(id)}`)).closed,\n };\n\n private async *stream(path: string, body: unknown, signal?: AbortSignal): AsyncIterable<RunnerChatEvent> {\n const response = await (this.options.fetch ?? fetch)(`${this.options.url}${path}`, { method: 'POST', headers: await this.headers(true), body: JSON.stringify(body), ...(signal ? { signal } : {}) });\n if (!response.ok || !response.body) {\n let code = `http-${response.status}`;\n try {\n const data = await response.json() as { error?: string };\n if (data.error) code = data.error;\n } catch {\n // Said by its status.\n }\n throw new RunnerError(response.status, code);\n }\n const reader = response.body.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n for (;;) {\n const { done, value } = await reader.read();\n buffer += decoder.decode(value ?? new Uint8Array(), { stream: !done });\n const lines = buffer.split('\\n');\n buffer = done ? '' : lines.pop() ?? '';\n for (const line of lines) {\n if (!line.trim()) continue;\n let event: RunnerChatEvent | { type: 'ping' };\n try {\n event = JSON.parse(line) as RunnerChatEvent | { type: 'ping' };\n } catch {\n continue;\n }\n if (event.type !== 'ping') yield event;\n }\n if (done) return;\n }\n }\n}\n\n// ── For the backend of a host ───────────────────────────────────────────────────────────────────────────────\n\n/** The routes the people of a tenant may reach through the backend of the host: never the platform ones. */\nconst PERSON_ROUTES = /^\\/v1\\/(info|models|complete|accounts(\\/[A-Za-z0-9_.:-]+){0,3}|chats(\\/[a-f0-9]{8}(\\/(messages|stop|calls\\/[a-f0-9]{12}))?)?)$/;\n\nexport type RunnerProxyTarget = {\n /** The address of the runner of this tenant. */\n url: string;\n /** A project key of the tenant (with `act-as-user`), or a platform key with `tenant`. */\n key: string;\n tenant?: string;\n /** The signed-in person, verified by the host. */\n user: string;\n};\n\n/**\n * Forwards a request of a signed-in person to their runner: only the routes of a person, with the key, tenant and\n * person added by the host (whatever the browser sent for them is dropped). Streams answers (chat replies) as they\n * come. `path` is the path of the runner, e.g. `/v1/models` (the host strips its own prefix).\n */\nexport async function forwardToRunner(request: Request, path: string, target: RunnerProxyTarget, fetchImpl: typeof fetch = fetch): Promise<Response> {\n if (!PERSON_ROUTES.test(path)) return new Response(JSON.stringify({ error: 'not found' }), { status: 404, headers: { 'content-type': 'application/json' } });\n if (!['GET', 'POST', 'PUT', 'DELETE'].includes(request.method)) return new Response(JSON.stringify({ error: 'not found' }), { status: 404, headers: { 'content-type': 'application/json' } });\n const headers: Record<string, string> = {\n authorization: `Bearer ${target.key}`,\n 'x-runner-user': target.user,\n ...(target.tenant ? { 'x-runner-tenant': target.tenant } : {}),\n };\n const type = request.headers.get('content-type');\n if (type) headers['content-type'] = type;\n const body = request.method === 'GET' || request.method === 'DELETE' ? undefined : await request.arrayBuffer();\n const url = new URL(request.url);\n const answer = await fetchImpl(`${target.url.replace(/\\/+$/, '')}${path}${url.search}`, {\n method: request.method,\n headers,\n ...(body ? { body } : {}),\n signal: request.signal,\n });\n return new Response(answer.body, {\n status: answer.status,\n headers: {\n 'content-type': answer.headers.get('content-type') ?? 'application/json',\n 'cache-control': 'no-store',\n 'x-accel-buffering': 'no',\n },\n });\n}\n"],"mappings":"A,mEAQA,IAAaA,EAAuB,CAAC,YAAa,SAAU,SAAU,UAAW,WAAY,YAAY,EAuD5FC,EAAb,cAAiC,KAAM,CACnC,OACA,KACA,MACA,OAEA,YAAY,EAAgB,EAAc,EAA6C,CAAC,EAAG,CACvF,MAAMC,CAAI,EACV,KAAK,KAAO,cACZ,KAAK,OAASC,EACd,KAAK,KAAOD,EACRE,EAAM,QAAO,KAAK,MAAQA,EAAM,OAChCA,EAAM,SAAQ,KAAK,OAASA,EAAM,OAC1C,CACJ,EAGaC,EAAiB,GAC1BC,EAAM,OAAS,SAAWA,EAAM,QAAQ,WAAW,YAAY,EAAIA,EAAM,QAAQ,MAAM,EAAmB,EAAI,IAAA,GAgBrGC,EAAb,MAAaA,CAAa,CACtB,QAEA,YAAY,EAA8B,CACtC,KAAK,QAAU,CAAE,GAAGC,EAAS,IAAKA,EAAQ,IAAI,QAAQ,OAAQ,EAAE,CAAE,CACtE,CAGA,GAAG,EAAyD,CACxD,OAAO,IAAID,EAAa,CAAE,GAAG,KAAK,QAAS,GAAGE,CAAM,CAAC,CACzD,CAEA,MAAc,QAAQ,EAAgD,CAClE,GAAM,CAAE,MAAK,SAAQ,OAAM,WAAY,KAAK,QAC5C,MAAO,CACH,GAAIC,EAAO,CAAE,eAAgB,kBAAmB,EAAI,CAAC,EACrD,GAAIC,EAAM,CAAE,cAAe,UAAUA,GAAM,EAAI,CAAC,EAChD,GAAIC,EAAS,CAAE,kBAAmBA,CAAO,EAAI,CAAC,EAC9C,GAAIC,EAAO,CAAE,gBAAiBA,CAAK,EAAI,CAAC,EACxC,GAAI,MAAMC,IAAU,CACxB,CACJ,CAGA,MAAM,QAAW,EAAgB,EAAc,EAA4B,CAC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ACJ,EAKMG,EAAgB,iIAiBtB,eAAsBC,EAAgB,EAAkB,EAAc,EAA2B,EAA0B,MAA0B,CAEjJ,GADI,CAACD,EAAc,KAAKxB,CAAI,GACxB,CAAC,CAAC,MAAO,OAAQ,MAAO,QAAQ,CAAC,CAAC,SAASW,EAAQ,MAAM,EAAG,OAAO,IAAI,SAAS,KAAK,UAAU,CAAE,MAAO,WAAY,CAAC,EAAG,CAAE,OAAQ,IAAK,QAAS,CAAE,eAAgB,kBAAmB,CAAE,CAAC,EAC5L,IAAMb,EAAkC,CACpC,cAAe,UAAU4B,EAAO,MAChC,gBAAiBA,EAAO,KACxB,GAAIA,EAAO,OAAS,CAAE,kBAAmBA,EAAO,MAAO,EAAI,CAAC,CAChE,EACMC,EAAOhB,EAAQ,QAAQ,IAAI,cAAc,EAC3CgB,IAAM,EAAQ,gBAAkBA,GACpC,IAAM1B,EAAOU,EAAQ,SAAW,OAASA,EAAQ,SAAW,SAAW,IAAA,GAAY,MAAMA,EAAQ,YAAY,EACvGiB,EAAM,IAAI,IAAIjB,EAAQ,GAAG,EACzBK,EAAS,MAAMa,EAAU,GAAGH,EAAO,IAAI,QAAQ,OAAQ,EAAE,IAAI1B,IAAO4B,EAAI,SAAU,CACpF,OAAQjB,EAAQ,OAChB,UACA,GAAIV,EAAO,CAAE,MAAK,EAAI,CAAC,EACvB,OAAQU,EAAQ,MACpB,CAAC,EACD,OAAO,IAAI,SAASK,EAAO,KAAM,CAC7B,OAAQA,EAAO,OACf,QAAS,CACL,eAAgBA,EAAO,QAAQ,IAAI,cAAc,GAAK,mBACtD,gBAAiB,WACjB,oBAAqB,IACzB,CACJ,CAAC,CACL,C"}
|
|
1
|
+
{"version":3,"file":"client.js","names":["RUNNER_KEY_PROVIDERS","RunnerError","code","status","extra","noCreditUntil","event","RunnerClient","options","scope","json","key","tenant","user","headers","response","path","body","text","data","name","project","approve","id","input","label","provider","request","tools","message","signal","callId","answer","reader","decoder","buffer","value","done","lines","line","PERSON_ROUTES","forwardToRunner","target","type","url","fetchImpl"],"sources":["../src/client/index.ts"],"sourcesContent":["// @llmnative/runner/client — the client of the API v1 of the LLMNative Runner, for the browser and for Node.\n//\n// A key never belongs in the browser of the people of a tenant: a host app talks to the runner from its backend\n// (`createRunnerProxy` forwards the requests of its signed-in people, adding the key, the tenant and the person),\n// and its pages use `RunnerClient` against that backend. The console of the runner and a personal app with a key of\n// its own use `RunnerClient` directly.\n\n/** The providers paid by use whose API key the runner keeps and opencode runs (ids of @llmnative/react). */\nexport const RUNNER_KEY_PROVIDERS = ['anthropic', 'openai', 'gemini', 'mistral', 'deepseek', 'openrouter'] as const;\nexport type RunnerKeyProvider = (typeof RUNNER_KEY_PROVIDERS)[number];\nexport type RunnerProvider = 'claude-code' | 'opencode-go' | 'opencode' | RunnerKeyProvider;\nexport type RunnerPermission = 'complete' | 'chat' | 'chat:tools' | 'accounts' | 'accounts:tenant' | 'act-as-user' | 'keys' | 'modules';\n\nexport type RunnerAccount = {\n provider: RunnerProvider;\n id: string;\n label?: string;\n /** When it was connected. */\n at: string;\n scope: 'user' | 'tenant';\n /** Out of credit until then (the limit of a subscription); absent when it has credit. */\n noCreditUntil?: string;\n};\n\nexport type RunnerModels = {\n /** `models`: the list a subscription serves; empty for a provider by use, which runs any model the client names. */\n providers: Array<{ id: RunnerProvider; kind: 'subscription' | 'usage'; models: string[]; accounts: number; available: number; yours: number; tenant: number }>;\n};\n\nexport type RunnerTenant = { id: string; name: string; createdAt: string; usersWithAccounts?: number };\nexport type RunnerKey = { id: string; kind: 'platform' | 'project'; tenant?: string; /** Platform keys: the project whose tenants (`<project>`, `<project>-…`) it owns. */ project?: string; name: string; permissions: RunnerPermission[]; createdAt: string; expiresAt: string | null };\n\nexport type RunnerStatus = {\n version: string;\n agentImage: string;\n url?: string;\n /** The project of the platform key asking: the tenants listed are its own only. */\n project?: string;\n load: { chats: number; answering: number; completions: number; maxChats: number };\n machine: { totalBytes: number; availableBytes: number; cpus: number };\n tenants: RunnerTenant[];\n};\n\n/** A pairing request made by a platform: `request` is its secret (keep it in the backend), `code` is shown on both sides. */\nexport type RunnerPairingRequest = { request: string; code: string; approveUrl: string; expiresAt: string; interval: number };\nexport type RunnerPairingPoll = { status: 'pending' | 'denied' | 'expired' } | { status: 'approved'; key: string; record: RunnerKey; version: string };\nexport type RunnerPairingRequestView = { code: string; name: string; project?: string; from?: string; createdAt: string; expiresAt: string };\nexport type RunnerHealth = { ok: boolean; version: string; chats: number; answering: number; completions: number; maxChats: number };\n\nexport type RunnerCompletionRequest = { provider: RunnerProvider; model: string; prompt: string; effort?: 'low' | 'medium' | 'high' | 'xhigh' | 'max' };\nexport type RunnerCompletion = { text: string; usage?: { inputTokens: number; outputTokens: number } };\n\nexport type RunnerChatTool = { name: string; description: string; inputSchema: Record<string, unknown>; endsTurn?: boolean };\nexport type RunnerChatModel = { provider: string; model: string; variant?: string; name?: string; effort?: string };\nexport type RunnerChatEvent =\n | { type: 'text'; text: string }\n | { type: 'reasoning'; text: string }\n | { type: 'step'; id: string; label: string; status: 'running' | 'done' }\n | { type: 'tool-call'; id: string; name: string; input: Record<string, unknown> }\n | { type: 'done' }\n | { type: 'error'; message: string };\n\n/** An error of the runner: its status and code (`no-credit`, `busy`…), and for `no-credit` until when. */\nexport class RunnerError extends Error {\n readonly status: number;\n readonly code: string;\n readonly until?: string;\n readonly detail?: string;\n\n constructor(status: number, code: string, extra: { until?: string; detail?: string } = {}) {\n super(code);\n this.name = 'RunnerError';\n this.status = status;\n this.code = code;\n if (extra.until) this.until = extra.until;\n if (extra.detail) this.detail = extra.detail;\n }\n}\n\n/** When a chat event says the accounts ran out of credit: until when (`no-credit:<iso>`). */\nexport const noCreditUntil = (event: RunnerChatEvent): string | undefined =>\n event.type === 'error' && event.message.startsWith('no-credit:') ? event.message.slice('no-credit:'.length) : undefined;\n\nexport type RunnerClientOptions = {\n /** The address of the runner (`https://runner.example.com`), or of the backend of the host that forwards to it. */\n url: string;\n /** A key of the runner (or the admin token in the console); none when the backend of the host adds it. */\n key?: string;\n /** With a platform key or the admin token: the tenant the requests are for. */\n tenant?: string;\n /** The person the requests are for (needs `act-as-user` with a project key). */\n user?: string;\n fetch?: typeof fetch;\n /** More headers for each request (the session of the host, for its backend). */\n headers?: () => Record<string, string> | Promise<Record<string, string>>;\n};\n\nexport class RunnerClient {\n readonly options: RunnerClientOptions;\n\n constructor(options: RunnerClientOptions) {\n this.options = { ...options, url: options.url.replace(/\\/+$/, '') };\n }\n\n /** The same runner for another tenant or person. */\n as(scope: { tenant?: string; user?: string }): RunnerClient {\n return new RunnerClient({ ...this.options, ...scope });\n }\n\n private async headers(json: boolean): Promise<Record<string, string>> {\n const { key, tenant, user, headers } = this.options;\n return {\n ...(json ? { 'content-type': 'application/json' } : {}),\n ...(key ? { authorization: `Bearer ${key}` } : {}),\n ...(tenant ? { 'x-runner-tenant': tenant } : {}),\n ...(user ? { 'x-runner-user': user } : {}),\n ...(await headers?.()),\n };\n }\n\n /** One request; its JSON, or a RunnerError. */\n async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const response = await (this.options.fetch ?? fetch)(`${this.options.url}${path}`, {\n method,\n headers: await this.headers(body !== undefined),\n ...(body !== undefined ? { body: JSON.stringify(body) } : {}),\n });\n const text = await response.text();\n let data: Record<string, unknown> = {};\n try {\n data = text ? JSON.parse(text) as Record<string, unknown> : {};\n } catch {\n // Not JSON (a proxy in between): said by its status.\n }\n if (!response.ok) {\n throw new RunnerError(response.status, typeof data.error === 'string' ? data.error : `http-${response.status}`, {\n ...(typeof data.until === 'string' ? { until: data.until } : {}),\n ...(typeof data.detail === 'string' ? { detail: data.detail } : {}),\n });\n }\n return data as T;\n }\n\n // ── Public ──────────────────────────────────────────────────────────────────────────────────────────────\n health(): Promise<RunnerHealth> {\n return this.request('GET', '/health');\n }\n\n /** A pairing code (printed by the installer) → a platform key, seen once. */\n /** `project`: the platform key owns only the tenants of that project (`<project>`, `<project>-…`). */\n pair(code: string, name?: string, project?: string): Promise<{ key: string; record: RunnerKey; version: string }> {\n return this.request('POST', '/v1/pair', { code, ...(name ? { name } : {}), ...(project ? { project } : {}) });\n }\n\n /**\n * Asks to connect (device flow): the admin of the runner approves it in the console at `approveUrl`, where the\n * same `code` is shown; meanwhile `pollPairing(request)` every `interval` seconds, until it gives the key.\n */\n requestPairing(name: string, project?: string): Promise<RunnerPairingRequest> {\n return this.request('POST', '/v1/pair/requests', { name, ...(project ? { project } : {}) });\n }\n\n pollPairing(request: string): Promise<RunnerPairingPoll> {\n return this.request('POST', '/v1/pair/requests/poll', { request });\n }\n\n info(): Promise<{ version: string; harnesses: string[]; capabilities: Record<string, boolean>; modules?: string[]; permissions: RunnerPermission[]; tenant?: string }> {\n return this.request('GET', '/v1/info');\n }\n\n // ── Admin token ─────────────────────────────────────────────────────────────────────────────────────────\n createPairing(): Promise<{ code: string; expiresAt: string }> {\n return this.request('POST', '/v1/admin/pairing');\n }\n\n async pairingRequests(): Promise<RunnerPairingRequestView[]> {\n return (await this.request<{ requests: RunnerPairingRequestView[] }>('GET', '/v1/admin/pairing/requests')).requests;\n }\n\n async answerPairing(code: string, approve: boolean): Promise<RunnerPairingRequestView> {\n return (await this.request<{ request: RunnerPairingRequestView }>('POST', `/v1/admin/pairing/requests/${encodeURIComponent(code)}/${approve ? 'approve' : 'deny'}`)).request;\n }\n\n /** The project of a platform key (null: every tenant, as keys made before 1.2). */\n async setKeyProject(id: string, project: string | null): Promise<RunnerKey> {\n return (await this.request<{ record: RunnerKey }>('PUT', `/v1/admin/keys/${encodeURIComponent(id)}/project`, { project })).record;\n }\n\n // ── Platform key ────────────────────────────────────────────────────────────────────────────────────────\n readonly platform = {\n status: (): Promise<RunnerStatus> => this.request('GET', '/v1/platform/status'),\n tenants: async (): Promise<RunnerTenant[]> => (await this.request<{ tenants: RunnerTenant[] }>('GET', '/v1/platform/tenants')).tenants,\n /** A tenant, with its first project key unless `key: false` (seen once: keep it in the backend). */\n createTenant: (id: string, options: { name?: string; key?: boolean; keyPermissions?: RunnerPermission[] } = {}): Promise<{ tenant: RunnerTenant; key?: string; keyRecord?: RunnerKey }> =>\n this.request('POST', '/v1/platform/tenants', { id, ...options }),\n removeTenant: async (id: string): Promise<boolean> => (await this.request<{ removed: boolean }>('DELETE', `/v1/platform/tenants/${encodeURIComponent(id)}`)).removed,\n keys: async (tenant: string): Promise<RunnerKey[]> => (await this.request<{ keys: RunnerKey[] }>('GET', `/v1/platform/tenants/${encodeURIComponent(tenant)}/keys`)).keys,\n createKey: (tenant: string, input: { name?: string; permissions?: RunnerPermission[]; expiresAt?: string | null } = {}): Promise<{ key: string; record: RunnerKey }> =>\n this.request('POST', `/v1/platform/tenants/${encodeURIComponent(tenant)}/keys`, input),\n revokeKey: async (tenant: string, id: string): Promise<boolean> => (await this.request<{ removed: boolean }>('DELETE', `/v1/platform/tenants/${encodeURIComponent(tenant)}/keys/${encodeURIComponent(id)}`)).removed,\n platformKeys: async (): Promise<RunnerKey[]> => (await this.request<{ keys: RunnerKey[] }>('GET', '/v1/platform/keys')).keys,\n revokePlatformKey: async (id: string): Promise<boolean> => (await this.request<{ removed: boolean }>('DELETE', `/v1/platform/keys/${encodeURIComponent(id)}`)).removed,\n };\n\n // ── Accounts of the person (or of the tenant) ───────────────────────────────────────────────────────────\n readonly accounts = {\n list: async (): Promise<{ scope: 'user' | 'tenant'; accounts: RunnerAccount[] }> => this.request('GET', '/v1/accounts'),\n /** The sign-in of a Claude subscription: open `url`, then give the code Anthropic shows to `finishClaudeLogin`. */\n startClaudeLogin: (): Promise<{ url: string }> => this.request('POST', '/v1/accounts/claude-code/login'),\n finishClaudeLogin: async (code: string, label?: string): Promise<RunnerAccount> =>\n (await this.request<{ account: RunnerAccount }>('POST', '/v1/accounts/claude-code/login/code', { code, ...(label ? { label } : {}) })).account,\n /** A token made elsewhere with `claude setup-token`. */\n addClaudeToken: async (token: string, label?: string): Promise<RunnerAccount> =>\n (await this.request<{ account: RunnerAccount }>('POST', '/v1/accounts/claude-code', { token, ...(label ? { label } : {}) })).account,\n /** A key: OpenCode Go/Zen, or the API key of a provider by use the runner keeps (opencode runs it). */\n addKey: async (provider: Exclude<RunnerProvider, 'claude-code'>, key: string, label?: string): Promise<RunnerAccount> =>\n (await this.request<{ account: RunnerAccount }>('POST', `/v1/accounts/${provider}`, { key, ...(label ? { label } : {}) })).account,\n remove: async (provider: RunnerProvider, id: string): Promise<boolean> =>\n (await this.request<{ removed: boolean }>('DELETE', `/v1/accounts/${provider}/${encodeURIComponent(id)}`)).removed,\n order: async (provider: RunnerProvider, ids: string[]): Promise<RunnerAccount[]> =>\n (await this.request<{ accounts: RunnerAccount[] }>('PUT', '/v1/accounts/order', { provider, ids })).accounts,\n };\n\n models(): Promise<RunnerModels> {\n return this.request('GET', '/v1/models');\n }\n\n complete(request: RunnerCompletionRequest): Promise<RunnerCompletion> {\n return this.request('POST', '/v1/complete', request);\n }\n\n // ── Chats ───────────────────────────────────────────────────────────────────────────────────────────────\n readonly chats = {\n /** A chat (id: 8 hex characters, chosen by the client), with the tools the harness may call. */\n start: (id: string, tools?: RunnerChatTool[]): Promise<{ id: string }> => this.request('POST', '/v1/chats', { id, ...(tools ? { tools } : {}) }),\n /** A message: its events as they come. Aborting the signal stops the harness. */\n send: (id: string, message: { text: string; model: RunnerChatModel; attachments?: Array<{ name: string; mimeType: string; base64: string }> }, signal?: AbortSignal): AsyncIterable<RunnerChatEvent> =>\n this.stream(`/v1/chats/${encodeURIComponent(id)}/messages`, message, signal),\n answerCall: async (id: string, callId: string, answer: { result?: unknown; isError?: boolean }): Promise<boolean> =>\n (await this.request<{ answered: boolean }>('POST', `/v1/chats/${encodeURIComponent(id)}/calls/${encodeURIComponent(callId)}`, answer)).answered,\n stop: async (id: string): Promise<boolean> => (await this.request<{ stopped: boolean }>('POST', `/v1/chats/${encodeURIComponent(id)}/stop`)).stopped,\n close: async (id: string): Promise<boolean> => (await this.request<{ closed: boolean }>('DELETE', `/v1/chats/${encodeURIComponent(id)}`)).closed,\n };\n\n private async *stream(path: string, body: unknown, signal?: AbortSignal): AsyncIterable<RunnerChatEvent> {\n const response = await (this.options.fetch ?? fetch)(`${this.options.url}${path}`, { method: 'POST', headers: await this.headers(true), body: JSON.stringify(body), ...(signal ? { signal } : {}) });\n if (!response.ok || !response.body) {\n let code = `http-${response.status}`;\n try {\n const data = await response.json() as { error?: string };\n if (data.error) code = data.error;\n } catch {\n // Said by its status.\n }\n throw new RunnerError(response.status, code);\n }\n const reader = response.body.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n for (;;) {\n const { done, value } = await reader.read();\n buffer += decoder.decode(value ?? new Uint8Array(), { stream: !done });\n const lines = buffer.split('\\n');\n buffer = done ? '' : lines.pop() ?? '';\n for (const line of lines) {\n if (!line.trim()) continue;\n let event: RunnerChatEvent | { type: 'ping' };\n try {\n event = JSON.parse(line) as RunnerChatEvent | { type: 'ping' };\n } catch {\n continue;\n }\n if (event.type !== 'ping') yield event;\n }\n if (done) return;\n }\n }\n}\n\n// ── For the backend of a host ───────────────────────────────────────────────────────────────────────────────\n\n/** The routes the people of a tenant may reach through the backend of the host: never the platform ones. */\nconst PERSON_ROUTES = /^\\/v1\\/(info|models|complete|accounts(\\/[A-Za-z0-9_.:-]+){0,3}|chats(\\/[a-f0-9]{8}(\\/(messages|stop|calls\\/[a-f0-9]{12}))?)?)$/;\n\nexport type RunnerProxyTarget = {\n /** The address of the runner of this tenant. */\n url: string;\n /** A project key of the tenant (with `act-as-user`), or a platform key with `tenant`. */\n key: string;\n tenant?: string;\n /** The signed-in person, verified by the host. */\n user: string;\n};\n\n/**\n * Forwards a request of a signed-in person to their runner: only the routes of a person, with the key, tenant and\n * person added by the host (whatever the browser sent for them is dropped). Streams answers (chat replies) as they\n * come. `path` is the path of the runner, e.g. `/v1/models` (the host strips its own prefix).\n */\nexport async function forwardToRunner(request: Request, path: string, target: RunnerProxyTarget, fetchImpl: typeof fetch = fetch): Promise<Response> {\n if (!PERSON_ROUTES.test(path)) return new Response(JSON.stringify({ error: 'not found' }), { status: 404, headers: { 'content-type': 'application/json' } });\n if (!['GET', 'POST', 'PUT', 'DELETE'].includes(request.method)) return new Response(JSON.stringify({ error: 'not found' }), { status: 404, headers: { 'content-type': 'application/json' } });\n const headers: Record<string, string> = {\n authorization: `Bearer ${target.key}`,\n 'x-runner-user': target.user,\n ...(target.tenant ? { 'x-runner-tenant': target.tenant } : {}),\n };\n const type = request.headers.get('content-type');\n if (type) headers['content-type'] = type;\n const body = request.method === 'GET' || request.method === 'DELETE' ? undefined : await request.arrayBuffer();\n const url = new URL(request.url);\n const answer = await fetchImpl(`${target.url.replace(/\\/+$/, '')}${path}${url.search}`, {\n method: request.method,\n headers,\n ...(body ? { body } : {}),\n signal: request.signal,\n });\n return new Response(answer.body, {\n status: answer.status,\n headers: {\n 'content-type': answer.headers.get('content-type') ?? 'application/json',\n 'cache-control': 'no-store',\n 'x-accel-buffering': 'no',\n },\n });\n}\n"],"mappings":"A,mEAQA,IAAaA,EAAuB,CAAC,YAAa,SAAU,SAAU,UAAW,WAAY,YAAY,EAuD5FC,EAAb,cAAiC,KAAM,CACnC,OACA,KACA,MACA,OAEA,YAAY,EAAgB,EAAc,EAA6C,CAAC,EAAG,CACvF,MAAMC,CAAI,EACV,KAAK,KAAO,cACZ,KAAK,OAASC,EACd,KAAK,KAAOD,EACRE,EAAM,QAAO,KAAK,MAAQA,EAAM,OAChCA,EAAM,SAAQ,KAAK,OAASA,EAAM,OAC1C,CACJ,EAGaC,EAAiB,GAC1BC,EAAM,OAAS,SAAWA,EAAM,QAAQ,WAAW,YAAY,EAAIA,EAAM,QAAQ,MAAM,EAAmB,EAAI,IAAA,GAgBrGC,EAAb,MAAaA,CAAa,CACtB,QAEA,YAAY,EAA8B,CACtC,KAAK,QAAU,CAAE,GAAGC,EAAS,IAAKA,EAAQ,IAAI,QAAQ,OAAQ,EAAE,CAAE,CACtE,CAGA,GAAG,EAAyD,CACxD,OAAO,IAAID,EAAa,CAAE,GAAG,KAAK,QAAS,GAAGE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,EACvB,OAAQU,EAAQ,MACpB,CAAC,EACD,OAAO,IAAI,SAASK,EAAO,KAAM,CAC7B,OAAQA,EAAO,OACf,QAAS,CACL,eAAgBA,EAAO,QAAQ,IAAI,cAAc,GAAK,mBACtD,gBAAiB,WACjB,oBAAqB,IACzB,CACJ,CAAC,CACL,C"}
|
package/dist/client.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","names":["RUNNER_KEY_PROVIDERS","RunnerError","code","status","extra","noCreditUntil","event","RunnerClient","options","scope","json","key","tenant","user","headers","response","path","body","text","data","name","project","approve","id","input","label","provider","request","tools","message","signal","callId","answer","reader","decoder","buffer","value","done","lines","line","PERSON_ROUTES","forwardToRunner","target","type","url","fetchImpl"],"sources":["../src/client/index.ts"],"sourcesContent":["// @llmnative/runner/client — the client of the API v1 of the LLMNative Runner, for the browser and for Node.\n//\n// A key never belongs in the browser of the people of a tenant: a host app talks to the runner from its backend\n// (`createRunnerProxy` forwards the requests of its signed-in people, adding the key, the tenant and the person),\n// and its pages use `RunnerClient` against that backend. The console of the runner and a personal app with a key of\n// its own use `RunnerClient` directly.\n\n/** The providers paid by use whose API key the runner keeps and opencode runs (ids of @llmnative/react). */\nexport const RUNNER_KEY_PROVIDERS = ['anthropic', 'openai', 'gemini', 'mistral', 'deepseek', 'openrouter'] as const;\nexport type RunnerKeyProvider = (typeof RUNNER_KEY_PROVIDERS)[number];\nexport type RunnerProvider = 'claude-code' | 'opencode-go' | 'opencode' | RunnerKeyProvider;\nexport type RunnerPermission = 'complete' | 'chat' | 'chat:tools' | 'accounts' | 'accounts:tenant' | 'act-as-user' | 'keys';\n\nexport type RunnerAccount = {\n provider: RunnerProvider;\n id: string;\n label?: string;\n /** When it was connected. */\n at: string;\n scope: 'user' | 'tenant';\n /** Out of credit until then (the limit of a subscription); absent when it has credit. */\n noCreditUntil?: string;\n};\n\nexport type RunnerModels = {\n /** `models`: the list a subscription serves; empty for a provider by use, which runs any model the client names. */\n providers: Array<{ id: RunnerProvider; kind: 'subscription' | 'usage'; models: string[]; accounts: number; available: number; yours: number; tenant: number }>;\n};\n\nexport type RunnerTenant = { id: string; name: string; createdAt: string; usersWithAccounts?: number };\nexport type RunnerKey = { id: string; kind: 'platform' | 'project'; tenant?: string; /** Platform keys: the project whose tenants (`<project>`, `<project>-…`) it owns. */ project?: string; name: string; permissions: RunnerPermission[]; createdAt: string; expiresAt: string | null };\n\nexport type RunnerStatus = {\n version: string;\n agentImage: string;\n url?: string;\n /** The project of the platform key asking: the tenants listed are its own only. */\n project?: string;\n load: { chats: number; answering: number; completions: number; maxChats: number };\n machine: { totalBytes: number; availableBytes: number; cpus: number };\n tenants: RunnerTenant[];\n};\n\n/** A pairing request made by a platform: `request` is its secret (keep it in the backend), `code` is shown on both sides. */\nexport type RunnerPairingRequest = { request: string; code: string; approveUrl: string; expiresAt: string; interval: number };\nexport type RunnerPairingPoll = { status: 'pending' | 'denied' | 'expired' } | { status: 'approved'; key: string; record: RunnerKey; version: string };\nexport type RunnerPairingRequestView = { code: string; name: string; project?: string; from?: string; createdAt: string; expiresAt: string };\nexport type RunnerHealth = { ok: boolean; version: string; chats: number; answering: number; completions: number; maxChats: number };\n\nexport type RunnerCompletionRequest = { provider: RunnerProvider; model: string; prompt: string; effort?: 'low' | 'medium' | 'high' | 'xhigh' | 'max' };\nexport type RunnerCompletion = { text: string; usage?: { inputTokens: number; outputTokens: number } };\n\nexport type RunnerChatTool = { name: string; description: string; inputSchema: Record<string, unknown>; endsTurn?: boolean };\nexport type RunnerChatModel = { provider: string; model: string; variant?: string; name?: string; effort?: string };\nexport type RunnerChatEvent =\n | { type: 'text'; text: string }\n | { type: 'reasoning'; text: string }\n | { type: 'step'; id: string; label: string; status: 'running' | 'done' }\n | { type: 'tool-call'; id: string; name: string; input: Record<string, unknown> }\n | { type: 'done' }\n | { type: 'error'; message: string };\n\n/** An error of the runner: its status and code (`no-credit`, `busy`…), and for `no-credit` until when. */\nexport class RunnerError extends Error {\n readonly status: number;\n readonly code: string;\n readonly until?: string;\n readonly detail?: string;\n\n constructor(status: number, code: string, extra: { until?: string; detail?: string } = {}) {\n super(code);\n this.name = 'RunnerError';\n this.status = status;\n this.code = code;\n if (extra.until) this.until = extra.until;\n if (extra.detail) this.detail = extra.detail;\n }\n}\n\n/** When a chat event says the accounts ran out of credit: until when (`no-credit:<iso>`). */\nexport const noCreditUntil = (event: RunnerChatEvent): string | undefined =>\n event.type === 'error' && event.message.startsWith('no-credit:') ? event.message.slice('no-credit:'.length) : undefined;\n\nexport type RunnerClientOptions = {\n /** The address of the runner (`https://runner.example.com`), or of the backend of the host that forwards to it. */\n url: string;\n /** A key of the runner (or the admin token in the console); none when the backend of the host adds it. */\n key?: string;\n /** With a platform key or the admin token: the tenant the requests are for. */\n tenant?: string;\n /** The person the requests are for (needs `act-as-user` with a project key). */\n user?: string;\n fetch?: typeof fetch;\n /** More headers for each request (the session of the host, for its backend). */\n headers?: () => Record<string, string> | Promise<Record<string, string>>;\n};\n\nexport class RunnerClient {\n readonly options: RunnerClientOptions;\n\n constructor(options: RunnerClientOptions) {\n this.options = { ...options, url: options.url.replace(/\\/+$/, '') };\n }\n\n /** The same runner for another tenant or person. */\n as(scope: { tenant?: string; user?: string }): RunnerClient {\n return new RunnerClient({ ...this.options, ...scope });\n }\n\n private async headers(json: boolean): Promise<Record<string, string>> {\n const { key, tenant, user, headers } = this.options;\n return {\n ...(json ? { 'content-type': 'application/json' } : {}),\n ...(key ? { authorization: `Bearer ${key}` } : {}),\n ...(tenant ? { 'x-runner-tenant': tenant } : {}),\n ...(user ? { 'x-runner-user': user } : {}),\n ...(await headers?.()),\n };\n }\n\n /** One request; its JSON, or a RunnerError. */\n async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const response = await (this.options.fetch ?? fetch)(`${this.options.url}${path}`, {\n method,\n headers: await this.headers(body !== undefined),\n ...(body !== undefined ? { body: JSON.stringify(body) } : {}),\n });\n const text = await response.text();\n let data: Record<string, unknown> = {};\n try {\n data = text ? JSON.parse(text) as Record<string, unknown> : {};\n } catch {\n // Not JSON (a proxy in between): said by its status.\n }\n if (!response.ok) {\n throw new RunnerError(response.status, typeof data.error === 'string' ? data.error : `http-${response.status}`, {\n ...(typeof data.until === 'string' ? { until: data.until } : {}),\n ...(typeof data.detail === 'string' ? { detail: data.detail } : {}),\n });\n }\n return data as T;\n }\n\n // ── Public ──────────────────────────────────────────────────────────────────────────────────────────────\n health(): Promise<RunnerHealth> {\n return this.request('GET', '/health');\n }\n\n /** A pairing code (printed by the installer) → a platform key, seen once. */\n /** `project`: the platform key owns only the tenants of that project (`<project>`, `<project>-…`). */\n pair(code: string, name?: string, project?: string): Promise<{ key: string; record: RunnerKey; version: string }> {\n return this.request('POST', '/v1/pair', { code, ...(name ? { name } : {}), ...(project ? { project } : {}) });\n }\n\n /**\n * Asks to connect (device flow): the admin of the runner approves it in the console at `approveUrl`, where the\n * same `code` is shown; meanwhile `pollPairing(request)` every `interval` seconds, until it gives the key.\n */\n requestPairing(name: string, project?: string): Promise<RunnerPairingRequest> {\n return this.request('POST', '/v1/pair/requests', { name, ...(project ? { project } : {}) });\n }\n\n pollPairing(request: string): Promise<RunnerPairingPoll> {\n return this.request('POST', '/v1/pair/requests/poll', { request });\n }\n\n info(): Promise<{ version: string; harnesses: string[]; capabilities: Record<string, boolean>; permissions: RunnerPermission[]; tenant?: string }> {\n return this.request('GET', '/v1/info');\n }\n\n // ── Admin token ─────────────────────────────────────────────────────────────────────────────────────────\n createPairing(): Promise<{ code: string; expiresAt: string }> {\n return this.request('POST', '/v1/admin/pairing');\n }\n\n async pairingRequests(): Promise<RunnerPairingRequestView[]> {\n return (await this.request<{ requests: RunnerPairingRequestView[] }>('GET', '/v1/admin/pairing/requests')).requests;\n }\n\n async answerPairing(code: string, approve: boolean): Promise<RunnerPairingRequestView> {\n return (await this.request<{ request: RunnerPairingRequestView }>('POST', `/v1/admin/pairing/requests/${encodeURIComponent(code)}/${approve ? 'approve' : 'deny'}`)).request;\n }\n\n /** The project of a platform key (null: every tenant, as keys made before 1.2). */\n async setKeyProject(id: string, project: string | null): Promise<RunnerKey> {\n return (await this.request<{ record: RunnerKey }>('PUT', `/v1/admin/keys/${encodeURIComponent(id)}/project`, { project })).record;\n }\n\n // ── Platform key ────────────────────────────────────────────────────────────────────────────────────────\n readonly platform = {\n status: (): Promise<RunnerStatus> => this.request('GET', '/v1/platform/status'),\n tenants: async (): Promise<RunnerTenant[]> => (await this.request<{ tenants: RunnerTenant[] }>('GET', '/v1/platform/tenants')).tenants,\n /** A tenant, with its first project key unless `key: false` (seen once: keep it in the backend). */\n createTenant: (id: string, options: { name?: string; key?: boolean; keyPermissions?: RunnerPermission[] } = {}): Promise<{ tenant: RunnerTenant; key?: string; keyRecord?: RunnerKey }> =>\n this.request('POST', '/v1/platform/tenants', { id, ...options }),\n removeTenant: async (id: string): Promise<boolean> => (await this.request<{ removed: boolean }>('DELETE', `/v1/platform/tenants/${encodeURIComponent(id)}`)).removed,\n keys: async (tenant: string): Promise<RunnerKey[]> => (await this.request<{ keys: RunnerKey[] }>('GET', `/v1/platform/tenants/${encodeURIComponent(tenant)}/keys`)).keys,\n createKey: (tenant: string, input: { name?: string; permissions?: RunnerPermission[]; expiresAt?: string | null } = {}): Promise<{ key: string; record: RunnerKey }> =>\n this.request('POST', `/v1/platform/tenants/${encodeURIComponent(tenant)}/keys`, input),\n revokeKey: async (tenant: string, id: string): Promise<boolean> => (await this.request<{ removed: boolean }>('DELETE', `/v1/platform/tenants/${encodeURIComponent(tenant)}/keys/${encodeURIComponent(id)}`)).removed,\n platformKeys: async (): Promise<RunnerKey[]> => (await this.request<{ keys: RunnerKey[] }>('GET', '/v1/platform/keys')).keys,\n revokePlatformKey: async (id: string): Promise<boolean> => (await this.request<{ removed: boolean }>('DELETE', `/v1/platform/keys/${encodeURIComponent(id)}`)).removed,\n };\n\n // ── Accounts of the person (or of the tenant) ───────────────────────────────────────────────────────────\n readonly accounts = {\n list: async (): Promise<{ scope: 'user' | 'tenant'; accounts: RunnerAccount[] }> => this.request('GET', '/v1/accounts'),\n /** The sign-in of a Claude subscription: open `url`, then give the code Anthropic shows to `finishClaudeLogin`. */\n startClaudeLogin: (): Promise<{ url: string }> => this.request('POST', '/v1/accounts/claude-code/login'),\n finishClaudeLogin: async (code: string, label?: string): Promise<RunnerAccount> =>\n (await this.request<{ account: RunnerAccount }>('POST', '/v1/accounts/claude-code/login/code', { code, ...(label ? { label } : {}) })).account,\n /** A token made elsewhere with `claude setup-token`. */\n addClaudeToken: async (token: string, label?: string): Promise<RunnerAccount> =>\n (await this.request<{ account: RunnerAccount }>('POST', '/v1/accounts/claude-code', { token, ...(label ? { label } : {}) })).account,\n /** A key: OpenCode Go/Zen, or the API key of a provider by use the runner keeps (opencode runs it). */\n addKey: async (provider: Exclude<RunnerProvider, 'claude-code'>, key: string, label?: string): Promise<RunnerAccount> =>\n (await this.request<{ account: RunnerAccount }>('POST', `/v1/accounts/${provider}`, { key, ...(label ? { label } : {}) })).account,\n remove: async (provider: RunnerProvider, id: string): Promise<boolean> =>\n (await this.request<{ removed: boolean }>('DELETE', `/v1/accounts/${provider}/${encodeURIComponent(id)}`)).removed,\n order: async (provider: RunnerProvider, ids: string[]): Promise<RunnerAccount[]> =>\n (await this.request<{ accounts: RunnerAccount[] }>('PUT', '/v1/accounts/order', { provider, ids })).accounts,\n };\n\n models(): Promise<RunnerModels> {\n return this.request('GET', '/v1/models');\n }\n\n complete(request: RunnerCompletionRequest): Promise<RunnerCompletion> {\n return this.request('POST', '/v1/complete', request);\n }\n\n // ── Chats ───────────────────────────────────────────────────────────────────────────────────────────────\n readonly chats = {\n /** A chat (id: 8 hex characters, chosen by the client), with the tools the harness may call. */\n start: (id: string, tools?: RunnerChatTool[]): Promise<{ id: string }> => this.request('POST', '/v1/chats', { id, ...(tools ? { tools } : {}) }),\n /** A message: its events as they come. Aborting the signal stops the harness. */\n send: (id: string, message: { text: string; model: RunnerChatModel; attachments?: Array<{ name: string; mimeType: string; base64: string }> }, signal?: AbortSignal): AsyncIterable<RunnerChatEvent> =>\n this.stream(`/v1/chats/${encodeURIComponent(id)}/messages`, message, signal),\n answerCall: async (id: string, callId: string, answer: { result?: unknown; isError?: boolean }): Promise<boolean> =>\n (await this.request<{ answered: boolean }>('POST', `/v1/chats/${encodeURIComponent(id)}/calls/${encodeURIComponent(callId)}`, answer)).answered,\n stop: async (id: string): Promise<boolean> => (await this.request<{ stopped: boolean }>('POST', `/v1/chats/${encodeURIComponent(id)}/stop`)).stopped,\n close: async (id: string): Promise<boolean> => (await this.request<{ closed: boolean }>('DELETE', `/v1/chats/${encodeURIComponent(id)}`)).closed,\n };\n\n private async *stream(path: string, body: unknown, signal?: AbortSignal): AsyncIterable<RunnerChatEvent> {\n const response = await (this.options.fetch ?? fetch)(`${this.options.url}${path}`, { method: 'POST', headers: await this.headers(true), body: JSON.stringify(body), ...(signal ? { signal } : {}) });\n if (!response.ok || !response.body) {\n let code = `http-${response.status}`;\n try {\n const data = await response.json() as { error?: string };\n if (data.error) code = data.error;\n } catch {\n // Said by its status.\n }\n throw new RunnerError(response.status, code);\n }\n const reader = response.body.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n for (;;) {\n const { done, value } = await reader.read();\n buffer += decoder.decode(value ?? new Uint8Array(), { stream: !done });\n const lines = buffer.split('\\n');\n buffer = done ? '' : lines.pop() ?? '';\n for (const line of lines) {\n if (!line.trim()) continue;\n let event: RunnerChatEvent | { type: 'ping' };\n try {\n event = JSON.parse(line) as RunnerChatEvent | { type: 'ping' };\n } catch {\n continue;\n }\n if (event.type !== 'ping') yield event;\n }\n if (done) return;\n }\n }\n}\n\n// ── For the backend of a host ───────────────────────────────────────────────────────────────────────────────\n\n/** The routes the people of a tenant may reach through the backend of the host: never the platform ones. */\nconst PERSON_ROUTES = /^\\/v1\\/(info|models|complete|accounts(\\/[A-Za-z0-9_.:-]+){0,3}|chats(\\/[a-f0-9]{8}(\\/(messages|stop|calls\\/[a-f0-9]{12}))?)?)$/;\n\nexport type RunnerProxyTarget = {\n /** The address of the runner of this tenant. */\n url: string;\n /** A project key of the tenant (with `act-as-user`), or a platform key with `tenant`. */\n key: string;\n tenant?: string;\n /** The signed-in person, verified by the host. */\n user: string;\n};\n\n/**\n * Forwards a request of a signed-in person to their runner: only the routes of a person, with the key, tenant and\n * person added by the host (whatever the browser sent for them is dropped). Streams answers (chat replies) as they\n * come. `path` is the path of the runner, e.g. `/v1/models` (the host strips its own prefix).\n */\nexport async function forwardToRunner(request: Request, path: string, target: RunnerProxyTarget, fetchImpl: typeof fetch = fetch): Promise<Response> {\n if (!PERSON_ROUTES.test(path)) return new Response(JSON.stringify({ error: 'not found' }), { status: 404, headers: { 'content-type': 'application/json' } });\n if (!['GET', 'POST', 'PUT', 'DELETE'].includes(request.method)) return new Response(JSON.stringify({ error: 'not found' }), { status: 404, headers: { 'content-type': 'application/json' } });\n const headers: Record<string, string> = {\n authorization: `Bearer ${target.key}`,\n 'x-runner-user': target.user,\n ...(target.tenant ? { 'x-runner-tenant': target.tenant } : {}),\n };\n const type = request.headers.get('content-type');\n if (type) headers['content-type'] = type;\n const body = request.method === 'GET' || request.method === 'DELETE' ? undefined : await request.arrayBuffer();\n const url = new URL(request.url);\n const answer = await fetchImpl(`${target.url.replace(/\\/+$/, '')}${path}${url.search}`, {\n method: request.method,\n headers,\n ...(body ? { body } : {}),\n signal: request.signal,\n });\n return new Response(answer.body, {\n status: answer.status,\n headers: {\n 'content-type': answer.headers.get('content-type') ?? 'application/json',\n 'cache-control': 'no-store',\n 'x-accel-buffering': 'no',\n },\n });\n}\n"],"mappings":";AAQA,IAAaA,IAAuB;CAAC;CAAa;CAAU;CAAU;CAAW;CAAY;AAAY,GAuD5FC,IAAb,cAAiC,MAAM;CACnC;CACA;CACA;CACA;CAEA,YAAY,GAAgB,GAAc,IAA6C,CAAC,GAAG;EAMvF,AALA,MAAMC,CAAI,GACV,KAAK,OAAO,eACZ,KAAK,SAASC,GACd,K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AChC,iBAAiBA,EAAO;EACxB,GAAIA,EAAO,SAAS,EAAE,mBAAmBA,EAAO,OAAO,IAAI,CAAC;CAChE,GACMC,IAAOhB,EAAQ,QAAQ,IAAI,cAAc;CAC/C,AAAIgB,MAAM,EAAQ,kBAAkBA;CACpC,IAAM1B,IAAOU,EAAQ,WAAW,SAASA,EAAQ,WAAW,WAAW,KAAA,IAAY,MAAMA,EAAQ,YAAY,GACvGiB,IAAM,IAAI,IAAIjB,EAAQ,GAAG,GACzBK,IAAS,MAAMa,EAAU,GAAGH,EAAO,IAAI,QAAQ,QAAQ,EAAE,IAAI1B,IAAO4B,EAAI,UAAU;EACpF,QAAQjB,EAAQ;EAChB;EACA,GAAIV,IAAO,EAAE,QAAK,IAAI,CAAC;EACvB,QAAQU,EAAQ;CACpB,CAAC;CACD,OAAO,IAAI,SAASK,EAAO,MAAM;EAC7B,QAAQA,EAAO;EACf,SAAS;GACL,gBAAgBA,EAAO,QAAQ,IAAI,cAAc,KAAK;GACtD,iBAAiB;GACjB,qBAAqB;EACzB;CACJ,CAAC;AACL"}
|
|
1
|
+
{"version":3,"file":"client.mjs","names":["RUNNER_KEY_PROVIDERS","RunnerError","code","status","extra","noCreditUntil","event","RunnerClient","options","scope","json","key","tenant","user","headers","response","path","body","text","data","name","project","approve","id","input","label","provider","request","tools","message","signal","callId","answer","reader","decoder","buffer","value","done","lines","line","PERSON_ROUTES","forwardToRunner","target","type","url","fetchImpl"],"sources":["../src/client/index.ts"],"sourcesContent":["// @llmnative/runner/client — the client of the API v1 of the LLMNative Runner, for the browser and for Node.\n//\n// A key never belongs in the browser of the people of a tenant: a host app talks to the runner from its backend\n// (`createRunnerProxy` forwards the requests of its signed-in people, adding the key, the tenant and the person),\n// and its pages use `RunnerClient` against that backend. The console of the runner and a personal app with a key of\n// its own use `RunnerClient` directly.\n\n/** The providers paid by use whose API key the runner keeps and opencode runs (ids of @llmnative/react). */\nexport const RUNNER_KEY_PROVIDERS = ['anthropic', 'openai', 'gemini', 'mistral', 'deepseek', 'openrouter'] as const;\nexport type RunnerKeyProvider = (typeof RUNNER_KEY_PROVIDERS)[number];\nexport type RunnerProvider = 'claude-code' | 'opencode-go' | 'opencode' | RunnerKeyProvider;\nexport type RunnerPermission = 'complete' | 'chat' | 'chat:tools' | 'accounts' | 'accounts:tenant' | 'act-as-user' | 'keys' | 'modules';\n\nexport type RunnerAccount = {\n provider: RunnerProvider;\n id: string;\n label?: string;\n /** When it was connected. */\n at: string;\n scope: 'user' | 'tenant';\n /** Out of credit until then (the limit of a subscription); absent when it has credit. */\n noCreditUntil?: string;\n};\n\nexport type RunnerModels = {\n /** `models`: the list a subscription serves; empty for a provider by use, which runs any model the client names. */\n providers: Array<{ id: RunnerProvider; kind: 'subscription' | 'usage'; models: string[]; accounts: number; available: number; yours: number; tenant: number }>;\n};\n\nexport type RunnerTenant = { id: string; name: string; createdAt: string; usersWithAccounts?: number };\nexport type RunnerKey = { id: string; kind: 'platform' | 'project'; tenant?: string; /** Platform keys: the project whose tenants (`<project>`, `<project>-…`) it owns. */ project?: string; name: string; permissions: RunnerPermission[]; createdAt: string; expiresAt: string | null };\n\nexport type RunnerStatus = {\n version: string;\n agentImage: string;\n url?: string;\n /** The project of the platform key asking: the tenants listed are its own only. */\n project?: string;\n load: { chats: number; answering: number; completions: number; maxChats: number };\n machine: { totalBytes: number; availableBytes: number; cpus: number };\n tenants: RunnerTenant[];\n};\n\n/** A pairing request made by a platform: `request` is its secret (keep it in the backend), `code` is shown on both sides. */\nexport type RunnerPairingRequest = { request: string; code: string; approveUrl: string; expiresAt: string; interval: number };\nexport type RunnerPairingPoll = { status: 'pending' | 'denied' | 'expired' } | { status: 'approved'; key: string; record: RunnerKey; version: string };\nexport type RunnerPairingRequestView = { code: string; name: string; project?: string; from?: string; createdAt: string; expiresAt: string };\nexport type RunnerHealth = { ok: boolean; version: string; chats: number; answering: number; completions: number; maxChats: number };\n\nexport type RunnerCompletionRequest = { provider: RunnerProvider; model: string; prompt: string; effort?: 'low' | 'medium' | 'high' | 'xhigh' | 'max' };\nexport type RunnerCompletion = { text: string; usage?: { inputTokens: number; outputTokens: number } };\n\nexport type RunnerChatTool = { name: string; description: string; inputSchema: Record<string, unknown>; endsTurn?: boolean };\nexport type RunnerChatModel = { provider: string; model: string; variant?: string; name?: string; effort?: string };\nexport type RunnerChatEvent =\n | { type: 'text'; text: string }\n | { type: 'reasoning'; text: string }\n | { type: 'step'; id: string; label: string; status: 'running' | 'done' }\n | { type: 'tool-call'; id: string; name: string; input: Record<string, unknown> }\n | { type: 'done' }\n | { type: 'error'; message: string };\n\n/** An error of the runner: its status and code (`no-credit`, `busy`…), and for `no-credit` until when. */\nexport class RunnerError extends Error {\n readonly status: number;\n readonly code: string;\n readonly until?: string;\n readonly detail?: string;\n\n constructor(status: number, code: string, extra: { until?: string; detail?: string } = {}) {\n super(code);\n this.name = 'RunnerError';\n this.status = status;\n this.code = code;\n if (extra.until) this.until = extra.until;\n if (extra.detail) this.detail = extra.detail;\n }\n}\n\n/** When a chat event says the accounts ran out of credit: until when (`no-credit:<iso>`). */\nexport const noCreditUntil = (event: RunnerChatEvent): string | undefined =>\n event.type === 'error' && event.message.startsWith('no-credit:') ? event.message.slice('no-credit:'.length) : undefined;\n\nexport type RunnerClientOptions = {\n /** The address of the runner (`https://runner.example.com`), or of the backend of the host that forwards to it. */\n url: string;\n /** A key of the runner (or the admin token in the console); none when the backend of the host adds it. */\n key?: string;\n /** With a platform key or the admin token: the tenant the requests are for. */\n tenant?: string;\n /** The person the requests are for (needs `act-as-user` with a project key). */\n user?: string;\n fetch?: typeof fetch;\n /** More headers for each request (the session of the host, for its backend). */\n headers?: () => Record<string, string> | Promise<Record<string, string>>;\n};\n\nexport class RunnerClient {\n readonly options: RunnerClientOptions;\n\n constructor(options: RunnerClientOptions) {\n this.options = { ...options, url: options.url.replace(/\\/+$/, '') };\n }\n\n /** The same runner for another tenant or person. */\n as(scope: { tenant?: string; user?: string }): RunnerClient {\n return new RunnerClient({ ...this.options, ...scope });\n }\n\n private async headers(json: boolean): Promise<Record<string, string>> {\n const { key, tenant, user, headers } = this.options;\n return {\n ...(json ? { 'content-type': 'application/json' } : {}),\n ...(key ? { authorization: `Bearer ${key}` } : {}),\n ...(tenant ? { 'x-runner-tenant': tenant } : {}),\n ...(user ? { 'x-runner-user': user } : {}),\n ...(await headers?.()),\n };\n }\n\n /** One request; its JSON, or a RunnerError. */\n async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const response = await (this.options.fetch ?? fetch)(`${this.options.url}${path}`, {\n method,\n headers: await this.headers(body !== undefined),\n ...(body !== undefined ? { body: JSON.stringify(body) } : {}),\n });\n const text = await response.text();\n let data: Record<string, unknown> = {};\n try {\n data = text ? JSON.parse(text) as Record<string, unknown> : {};\n } catch {\n // Not JSON (a proxy in between): said by its status.\n }\n if (!response.ok) {\n throw new RunnerError(response.status, typeof data.error === 'string' ? data.error : `http-${response.status}`, {\n ...(typeof data.until === 'string' ? { until: data.until } : {}),\n ...(typeof data.detail === 'string' ? { detail: data.detail } : {}),\n });\n }\n return data as T;\n }\n\n // ── Public ──────────────────────────────────────────────────────────────────────────────────────────────\n health(): Promise<RunnerHealth> {\n return this.request('GET', '/health');\n }\n\n /** A pairing code (printed by the installer) → a platform key, seen once. */\n /** `project`: the platform key owns only the tenants of that project (`<project>`, `<project>-…`). */\n pair(code: string, name?: string, project?: string): Promise<{ key: string; record: RunnerKey; version: string }> {\n return this.request('POST', '/v1/pair', { code, ...(name ? { name } : {}), ...(project ? { project } : {}) });\n }\n\n /**\n * Asks to connect (device flow): the admin of the runner approves it in the console at `approveUrl`, where the\n * same `code` is shown; meanwhile `pollPairing(request)` every `interval` seconds, until it gives the key.\n */\n requestPairing(name: string, project?: string): Promise<RunnerPairingRequest> {\n return this.request('POST', '/v1/pair/requests', { name, ...(project ? { project } : {}) });\n }\n\n pollPairing(request: string): Promise<RunnerPairingPoll> {\n return this.request('POST', '/v1/pair/requests/poll', { request });\n }\n\n info(): Promise<{ version: string; harnesses: string[]; capabilities: Record<string, boolean>; modules?: string[]; permissions: RunnerPermission[]; tenant?: string }> {\n return this.request('GET', '/v1/info');\n }\n\n // ── Admin token ─────────────────────────────────────────────────────────────────────────────────────────\n createPairing(): Promise<{ code: string; expiresAt: string }> {\n return this.request('POST', '/v1/admin/pairing');\n }\n\n async pairingRequests(): Promise<RunnerPairingRequestView[]> {\n return (await this.request<{ requests: RunnerPairingRequestView[] }>('GET', '/v1/admin/pairing/requests')).requests;\n }\n\n async answerPairing(code: string, approve: boolean): Promise<RunnerPairingRequestView> {\n return (await this.request<{ request: RunnerPairingRequestView }>('POST', `/v1/admin/pairing/requests/${encodeURIComponent(code)}/${approve ? 'approve' : 'deny'}`)).request;\n }\n\n /** The project of a platform key (null: every tenant, as keys made before 1.2). */\n async setKeyProject(id: string, project: string | null): Promise<RunnerKey> {\n return (await this.request<{ record: RunnerKey }>('PUT', `/v1/admin/keys/${encodeURIComponent(id)}/project`, { project })).record;\n }\n\n // ── Platform key ────────────────────────────────────────────────────────────────────────────────────────\n readonly platform = {\n status: (): Promise<RunnerStatus> => this.request('GET', '/v1/platform/status'),\n tenants: async (): Promise<RunnerTenant[]> => (await this.request<{ tenants: RunnerTenant[] }>('GET', '/v1/platform/tenants')).tenants,\n /** A tenant, with its first project key unless `key: false` (seen once: keep it in the backend). */\n createTenant: (id: string, options: { name?: string; key?: boolean; keyPermissions?: RunnerPermission[] } = {}): Promise<{ tenant: RunnerTenant; key?: string; keyRecord?: RunnerKey }> =>\n this.request('POST', '/v1/platform/tenants', { id, ...options }),\n removeTenant: async (id: string): Promise<boolean> => (await this.request<{ removed: boolean }>('DELETE', `/v1/platform/tenants/${encodeURIComponent(id)}`)).removed,\n keys: async (tenant: string): Promise<RunnerKey[]> => (await this.request<{ keys: RunnerKey[] }>('GET', `/v1/platform/tenants/${encodeURIComponent(tenant)}/keys`)).keys,\n createKey: (tenant: string, input: { name?: string; permissions?: RunnerPermission[]; expiresAt?: string | null } = {}): Promise<{ key: string; record: RunnerKey }> =>\n this.request('POST', `/v1/platform/tenants/${encodeURIComponent(tenant)}/keys`, input),\n revokeKey: async (tenant: string, id: string): Promise<boolean> => (await this.request<{ removed: boolean }>('DELETE', `/v1/platform/tenants/${encodeURIComponent(tenant)}/keys/${encodeURIComponent(id)}`)).removed,\n platformKeys: async (): Promise<RunnerKey[]> => (await this.request<{ keys: RunnerKey[] }>('GET', '/v1/platform/keys')).keys,\n revokePlatformKey: async (id: string): Promise<boolean> => (await this.request<{ removed: boolean }>('DELETE', `/v1/platform/keys/${encodeURIComponent(id)}`)).removed,\n };\n\n // ── Accounts of the person (or of the tenant) ───────────────────────────────────────────────────────────\n readonly accounts = {\n list: async (): Promise<{ scope: 'user' | 'tenant'; accounts: RunnerAccount[] }> => this.request('GET', '/v1/accounts'),\n /** The sign-in of a Claude subscription: open `url`, then give the code Anthropic shows to `finishClaudeLogin`. */\n startClaudeLogin: (): Promise<{ url: string }> => this.request('POST', '/v1/accounts/claude-code/login'),\n finishClaudeLogin: async (code: string, label?: string): Promise<RunnerAccount> =>\n (await this.request<{ account: RunnerAccount }>('POST', '/v1/accounts/claude-code/login/code', { code, ...(label ? { label } : {}) })).account,\n /** A token made elsewhere with `claude setup-token`. */\n addClaudeToken: async (token: string, label?: string): Promise<RunnerAccount> =>\n (await this.request<{ account: RunnerAccount }>('POST', '/v1/accounts/claude-code', { token, ...(label ? { label } : {}) })).account,\n /** A key: OpenCode Go/Zen, or the API key of a provider by use the runner keeps (opencode runs it). */\n addKey: async (provider: Exclude<RunnerProvider, 'claude-code'>, key: string, label?: string): Promise<RunnerAccount> =>\n (await this.request<{ account: RunnerAccount }>('POST', `/v1/accounts/${provider}`, { key, ...(label ? { label } : {}) })).account,\n remove: async (provider: RunnerProvider, id: string): Promise<boolean> =>\n (await this.request<{ removed: boolean }>('DELETE', `/v1/accounts/${provider}/${encodeURIComponent(id)}`)).removed,\n order: async (provider: RunnerProvider, ids: string[]): Promise<RunnerAccount[]> =>\n (await this.request<{ accounts: RunnerAccount[] }>('PUT', '/v1/accounts/order', { provider, ids })).accounts,\n };\n\n models(): Promise<RunnerModels> {\n return this.request('GET', '/v1/models');\n }\n\n complete(request: RunnerCompletionRequest): Promise<RunnerCompletion> {\n return this.request('POST', '/v1/complete', request);\n }\n\n // ── Chats ───────────────────────────────────────────────────────────────────────────────────────────────\n readonly chats = {\n /** A chat (id: 8 hex characters, chosen by the client), with the tools the harness may call. */\n start: (id: string, tools?: RunnerChatTool[]): Promise<{ id: string }> => this.request('POST', '/v1/chats', { id, ...(tools ? { tools } : {}) }),\n /** A message: its events as they come. Aborting the signal stops the harness. */\n send: (id: string, message: { text: string; model: RunnerChatModel; attachments?: Array<{ name: string; mimeType: string; base64: string }> }, signal?: AbortSignal): AsyncIterable<RunnerChatEvent> =>\n this.stream(`/v1/chats/${encodeURIComponent(id)}/messages`, message, signal),\n answerCall: async (id: string, callId: string, answer: { result?: unknown; isError?: boolean }): Promise<boolean> =>\n (await this.request<{ answered: boolean }>('POST', `/v1/chats/${encodeURIComponent(id)}/calls/${encodeURIComponent(callId)}`, answer)).answered,\n stop: async (id: string): Promise<boolean> => (await this.request<{ stopped: boolean }>('POST', `/v1/chats/${encodeURIComponent(id)}/stop`)).stopped,\n close: async (id: string): Promise<boolean> => (await this.request<{ closed: boolean }>('DELETE', `/v1/chats/${encodeURIComponent(id)}`)).closed,\n };\n\n private async *stream(path: string, body: unknown, signal?: AbortSignal): AsyncIterable<RunnerChatEvent> {\n const response = await (this.options.fetch ?? fetch)(`${this.options.url}${path}`, { method: 'POST', headers: await this.headers(true), body: JSON.stringify(body), ...(signal ? { signal } : {}) });\n if (!response.ok || !response.body) {\n let code = `http-${response.status}`;\n try {\n const data = await response.json() as { error?: string };\n if (data.error) code = data.error;\n } catch {\n // Said by its status.\n }\n throw new RunnerError(response.status, code);\n }\n const reader = response.body.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n for (;;) {\n const { done, value } = await reader.read();\n buffer += decoder.decode(value ?? new Uint8Array(), { stream: !done });\n const lines = buffer.split('\\n');\n buffer = done ? '' : lines.pop() ?? '';\n for (const line of lines) {\n if (!line.trim()) continue;\n let event: RunnerChatEvent | { type: 'ping' };\n try {\n event = JSON.parse(line) as RunnerChatEvent | { type: 'ping' };\n } catch {\n continue;\n }\n if (event.type !== 'ping') yield event;\n }\n if (done) return;\n }\n }\n}\n\n// ── For the backend of a host ───────────────────────────────────────────────────────────────────────────────\n\n/** The routes the people of a tenant may reach through the backend of the host: never the platform ones. */\nconst PERSON_ROUTES = /^\\/v1\\/(info|models|complete|accounts(\\/[A-Za-z0-9_.:-]+){0,3}|chats(\\/[a-f0-9]{8}(\\/(messages|stop|calls\\/[a-f0-9]{12}))?)?)$/;\n\nexport type RunnerProxyTarget = {\n /** The address of the runner of this tenant. */\n url: string;\n /** A project key of the tenant (with `act-as-user`), or a platform key with `tenant`. */\n key: string;\n tenant?: string;\n /** The signed-in person, verified by the host. */\n user: string;\n};\n\n/**\n * Forwards a request of a signed-in person to their runner: only the routes of a person, with the key, tenant and\n * person added by the host (whatever the browser sent for them is dropped). Streams answers (chat replies) as they\n * come. `path` is the path of the runner, e.g. `/v1/models` (the host strips its own prefix).\n */\nexport async function forwardToRunner(request: Request, path: string, target: RunnerProxyTarget, fetchImpl: typeof fetch = fetch): Promise<Response> {\n if (!PERSON_ROUTES.test(path)) return new Response(JSON.stringify({ error: 'not found' }), { status: 404, headers: { 'content-type': 'application/json' } });\n if (!['GET', 'POST', 'PUT', 'DELETE'].includes(request.method)) return new Response(JSON.stringify({ error: 'not found' }), { status: 404, headers: { 'content-type': 'application/json' } });\n const headers: Record<string, string> = {\n authorization: `Bearer ${target.key}`,\n 'x-runner-user': target.user,\n ...(target.tenant ? { 'x-runner-tenant': target.tenant } : {}),\n };\n const type = request.headers.get('content-type');\n if (type) headers['content-type'] = type;\n const body = request.method === 'GET' || request.method === 'DELETE' ? undefined : await request.arrayBuffer();\n const url = new URL(request.url);\n const answer = await fetchImpl(`${target.url.replace(/\\/+$/, '')}${path}${url.search}`, {\n method: request.method,\n headers,\n ...(body ? { body } : {}),\n signal: request.signal,\n });\n return new Response(answer.body, {\n status: answer.status,\n headers: {\n 'content-type': answer.headers.get('content-type') ?? 'application/json',\n 'cache-control': 'no-store',\n 'x-accel-buffering': 'no',\n },\n });\n}\n"],"mappings":";AAQA,IAAaA,IAAuB;CAAC;CAAa;CAAU;CAAU;CAAW;CAAY;AAAY,GAuD5FC,IAAb,cAAiC,MAAM;CACnC;CACA;CACA;CACA;CAEA,YAAY,GAAgB,GAAc,IAA6C,CAAC,GAAG;EAMvF,AALA,MAAMC,CAAI,GACV,KAAK,OAAO,eACZ,KAAK,SAASC,GACd,KAAK,OAAOD,GACRE,EAAM,UAAO,KAAK,QAAQA,EAAM,QAChCA,EAAM,WAAQ,KAAK,SAASA,EAAM;CAC1C;AACJ,GAGaC,KAAiB,MAC1BC,EAAM,SAAS,WAAWA,EAAM,QAAQ,WAAW,YAAY,IAAIA,EAAM,QAAQ,MAAM,EAAmB,IAAI,KAAA,GAgBrGC,IAAb,MAAaA,EAAa;CACtB;CAEA,YAAY,GAA8B;EACtC,KAAK,UAAU;GAAE,GAAGC;GAAS,KAAKA,EAAQ,IAAI,QAAQ,QAAQ,EAAE;EAAE;CACtE;CAGA,GAAG,GAAyD;EACxD,OAAO,IAAID,EAAa;GAAE,GAAG,KAAK;GAAS,GAAGE;EAAM,CAAC;CACzD;CAEA,MAAc,QAAQ,GAAgD;EAClE,IAAM,EAAE,QAAK,WAAQ,SAAM,eAAY,KAAK;EAC5C,OAAO;GACH,GAAIC,IAAO,EAAE,gBAAgB,mBAAmB,IAAI,CAAC;GACrD,GAAIC,IAAM,EAAE,eAAe,UAAUA,IAAM,IAAI,CAAC;GAChD,GAAIC,IAAS,EAAE,mBAAmBA,EAAO,IAAI,CAAC;GAC9C,GAAIC,IAAO,EAAE,iBAAiBA,EAAK,IAAI,CAAC;GACxC,GAAI,MAAMC,IAAU;EACxB;CACJ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