Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

client.ts

48 lines1.5 KB

1/**
2 * Configuration for the Ollaya HTTP client used by the adapters in this
3 * package. Requests are made with plain `fetch` — no SDK dependency.
4 *
5 * Ollaya is a local decision server, so there is no required API key. Pass
6 * `apiKey` when the server has `OLLAYA_API_KEY` set, or when a proxy
7 * requires a bearer token.
8 */
9export interface OllayaClientConfig {
10 /** Bearer token for `OLLAYA_API_KEY`, or for an auth proxy. */
11 apiKey?: string
12​
13 /**
14 * Base URL for every request (defaults to `http://127.0.0.1:11435`). Same
15 * option name as the other adapters, so a gateway config can be spread into
16 * any of them. A non-blank value wins over `baseUrl`.
17 */
18 baseURL?: string
19​
20 /** Alias of `baseURL`. */
21 baseUrl?: string
22​
23 /**
24 * Headers sent with every request. Same option name as the other adapters.
25 * Wins over `headers` when both are set.
26 */
27 defaultHeaders?: Record<string, string>
28​
29 /** Alias of `defaultHeaders`. */
30 headers?: Record<string, string>
31​
32 /** Override `fetch`. Defaults to global `fetch`. */
33 fetch?: typeof fetch
35​
36export const OLLAYA_DEFAULT_BASE_URL = 'http://127.0.0.1:11435'
37​
38/** Resolve the effective base URL (no trailing slash) and headers. */
39export function resolveOllayaTransport(config: OllayaClientConfig) {
40 return {
41 baseUrl: (
42 config.baseURL?.trim() ||
43 config.baseUrl?.trim() ||
44 OLLAYA_DEFAULT_BASE_URL
45 ).replace(/\/+$/, ''),
46 headers: config.defaultHeaders ?? config.headers ?? {},
47 }