@aparte/provider-openai-compat 0.24.0 → 0.26.0

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/README.md CHANGED
@@ -31,3 +31,44 @@ your headers), or hand it to `createAparteChatHandler` from core.
31
31
 
32
32
  > Part of the [aparté](https://github.com/apartejs/aparte) monorepo. ESM-only.
33
33
  > See the **Providers** guide in the docs for the full usage.
34
+
35
+ ## Context window
36
+
37
+ `fetchModels` fills each model's `contextWindow`, which is what the token gauge and
38
+ compaction measure against. It reads the first positive integer among `context_length`
39
+ (OpenRouter, Together), `max_model_len` (vLLM), `context_window` (Groq) and
40
+ `max_context_length` (Mistral) on the `GET /models` entry. A local server also needs to
41
+ say which one it is, because most of them do not put the window on `/models`:
42
+
43
+ ```ts
44
+ createOpenAICompatProvider({ id: 'my-box', baseURL: 'http://localhost:8080/v1', isLocal: true, server: 'llamacpp' });
45
+ ```
46
+
47
+ With `server` set, one extra request goes to the endpoint's origin (the `/v1` path
48
+ stripped) and the **effective** window wins over the trained maximum, since that is where
49
+ the server truncates:
50
+
51
+ | Preset | `server` | Reads | Notes |
52
+ | --- | --- | --- | --- |
53
+ | `LMSTUDIO` | `lmstudio` | `/api/v1/models`: a loaded model's `config.context_length` | an unloaded model gets none |
54
+ | `OLLAMA` | `ollama` | `/api/ps`: the loaded runner's `context_length` | a model that is not loaded gets none |
55
+ | `LLAMACPP` | `llamacpp` | `/props`: `default_generation_settings.n_ctx` | per slot, one value for the served model |
56
+ | `VLLM` | `vllm` | `max_model_len` on `/v1/models` | no extra request |
57
+
58
+ An unloaded model gets no window rather than its trained maximum: that number is not what
59
+ the server will run with. A probe that fails (CORS, an older server, a closed port) leaves
60
+ the models without a window and logs one warning; it never fails the model list.
61
+
62
+ A model you declare in `models` with a `contextWindow` wins over anything read from the
63
+ server.
64
+
65
+ `LLAMACPP` (`http://localhost:8080/v1`) and `VLLM` (`http://localhost:8000/v1`) are presets
66
+ like the others: local, key optional.
67
+
68
+ ## Errors and finish reason
69
+
70
+ A server that answers `200` and then streams `data: {"error": {...}}` (LM Studio on a
71
+ context overflow, OpenAI and vLLM mid-stream) ends the turn with an `error` event carrying
72
+ its message, not an empty completed reply. The last `finish_reason` of the stream travels
73
+ on the `done` event as `finishReason` (`stop`, `length`, `tool-calls`, `content-filter`,
74
+ `other`).
package/dist/index.d.ts CHANGED
@@ -42,6 +42,19 @@ export interface OpenAICompatProviderOptions {
42
42
  * `/models` fetch runs even without a key.
43
43
  */
44
44
  isLocal?: boolean;
45
+ /**
46
+ * Which local server this endpoint is, so `fetchModels` can read the context window
47
+ * the server actually serves through that server's own API: LM Studio's
48
+ * `/api/v1/models`, Ollama's `/api/ps`, llama.cpp's `/props`. Data, not code — the
49
+ * request shape is the same for everyone and only the probe differs. With it,
50
+ * `fetchModels` makes one extra request at the endpoint's origin (the `/v1` path
51
+ * stripped) and prefers the EFFECTIVE window (what the server loaded, which is where
52
+ * it truncates) over the trained maximum. A probe that fails leaves the models
53
+ * without a window; it never fails the model list. `'vllm'` needs no extra request,
54
+ * its `/v1/models` already carries `max_model_len`, and is accepted so a preset can
55
+ * say what it is.
56
+ */
57
+ server?: 'lmstudio' | 'ollama' | 'llamacpp' | 'vllm';
45
58
  /** Static model list (consumer data). Defaults to `[]` — use `fetchModels`. */
46
59
  models?: AparteAIModel[];
47
60
  /**
@@ -66,14 +79,15 @@ export interface OpenAICompatProviderOptions {
66
79
  *
67
80
  * `AparteAIProvider` declares that surface optional — correct in general, since a
68
81
  * provider may own its I/O through `chat()` instead — and `AparteFormatAdapter` keeps
69
- * `authHeaders` / `parseText` optional because some vendors authenticate by query
70
- * string or never answer non-streaming. THIS factory always supplies all of them, so
82
+ * `authHeaders` / `parseText` / `classifyError` optional because some vendors authenticate
83
+ * by query string, never answer non-streaming, or say nothing a client could classify.
84
+ * THIS factory always supplies all of them, so
71
85
  * saying so here is the difference between a caller writing
72
86
  * `provider.buildRequest(req)` and a caller sprinkling `!` or writing a check that
73
87
  * cannot fail. Useful to annotate with when you drive the adapter yourself (your own
74
88
  * `fetch`, your own `AbortSignal`) from a server or an Electron main process.
75
89
  */
76
- export type OpenAICompatProvider = AparteAIProvider & AparteFormatAdapter & Required<Pick<AparteFormatAdapter, 'authHeaders' | 'parseText'>>;
90
+ export type OpenAICompatProvider = AparteAIProvider & AparteFormatAdapter & Required<Pick<AparteFormatAdapter, 'authHeaders' | 'parseText' | 'classifyError'>>;
77
91
  /**
78
92
  * Build an `AparteAIProvider` (full format-adapter surface) for one
79
93
  * OpenAI-compatible endpoint. Register it like any provider:
@@ -97,6 +111,8 @@ export declare function createOpenAICompatProvider(opts: OpenAICompatProviderOpt
97
111
  * - `delta.content` → text event
98
112
  * - `delta.reasoning_content` → thinking event (Qwen3, DeepSeek R1, …)
99
113
  * - `delta.tool_calls` → accumulate → tool_use on finish_reason='tool_calls'
114
+ * - `finish_reason` → `finishReason` on the `done`
115
+ * - `{ error }` data line → error event, and the stream ends there (no `done`)
100
116
  * - usage-only chunk + [DONE] → done{usage}
101
117
  */
102
118
  export declare function parseOpenAICompatStream(stream: ReadableStream<Uint8Array>): ReadableStream<AparteStreamEvent>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EACR,gBAAgB,EAChB,aAAa,EACb,4BAA4B,EAM5B,iBAAiB,EAEjB,mBAAmB,EACtB,MAAM,cAAc,CAAC;AAKtB,iGAAiG;AACjG,MAAM,WAAW,2BAA2B;IACxC,6EAA6E;IAC7E,EAAE,EAAE,MAAM,CAAC;IACX,sFAAsF;IACtF,OAAO,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;I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Y,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { contentToText } from "@aparte/core";
1
+ import { AparteErrorCode, contentToText } from "@aparte/core";
2
2
  const OPENAI = {
3
3
  id: "openai",
4
4
  baseURL: "https://api.openai.com/v1",
@@ -51,6 +51,7 @@ const LMSTUDIO = {
51
51
  description: "Run LLMs locally with the LM Studio app",
52
52
  hasFreeModels: true,
53
53
  isLocal: true,
54
+ server: "lmstudio",
54
55
  helpUrl: "https://lmstudio.ai/"
55
56
  };
56
57
  const OLLAMA = {
@@ -62,9 +63,34 @@ const OLLAMA = {
62
63
  description: "Run LLMs locally — free and fully private",
63
64
  hasFreeModels: true,
64
65
  isLocal: true,
66
+ server: "ollama",
65
67
  helpUrl: "https://ollama.com/"
66
68
  };
67
- const presets = { OPENAI, MISTRAL, ZAI, OPENROUTER, LMSTUDIO, OLLAMA };
69
+ const LLAMACPP = {
70
+ id: "llamacpp",
71
+ baseURL: "http://localhost:8080/v1",
72
+ name: "llama.cpp",
73
+ icon: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="M7 9h2M7 12h6M7 15h4"/></svg>`,
74
+ color: "#64748b",
75
+ description: "Run GGUF models locally with llama-server",
76
+ hasFreeModels: true,
77
+ isLocal: true,
78
+ server: "llamacpp",
79
+ helpUrl: "https://github.com/ggml-org/llama.cpp"
80
+ };
81
+ const VLLM = {
82
+ id: "vllm",
83
+ baseURL: "http://localhost:8000/v1",
84
+ name: "vLLM",
85
+ icon: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 3l9 5-9 5-9-5 9-5z"/><path d="M3 13l9 5 9-5"/></svg>`,
86
+ color: "#6b7280",
87
+ description: "Serve open models from your own GPU with vLLM",
88
+ hasFreeModels: true,
89
+ isLocal: true,
90
+ server: "vllm",
91
+ helpUrl: "https://docs.vllm.ai/"
92
+ };
93
+ const presets = { OPENAI, MISTRAL, ZAI, OPENROUTER, LMSTUDIO, OLLAMA, LLAMACPP, VLLM };
68
94
  const ADAPTER_FIELDS = /* @__PURE__ */ new Set(["model", "messages", "temperature", "max_tokens", "stream", "stream_options", "seed", "tools", "tool_choice"]);
69
95
  function toOpenAIContent(content) {
70
96
  if (typeof content === "string") return content;
@@ -119,6 +145,101 @@ function toOpenAITools(tools) {
119
145
  function bearer(key) {
120
146
  return key.startsWith("Bearer ") ? key : `Bearer ${key}`;
121
147
  }
148
+ function toFinishReason(raw) {
149
+ switch (raw) {
150
+ case "stop":
151
+ return "stop";
152
+ case "length":
153
+ return "length";
154
+ case "tool_calls":
155
+ case "function_call":
156
+ return "tool-calls";
157
+ case "content_filter":
158
+ return "content-filter";
159
+ default:
160
+ return "other";
161
+ }
162
+ }
163
+ function errorPayloadMessage(error) {
164
+ if (typeof error === "string" && error) return error;
165
+ const message = error?.message;
166
+ return typeof message === "string" && message ? message : "The server reported an error";
167
+ }
168
+ const CONTEXT_OVERFLOW = /maximum context length|context length|context size has been exceeded|exceed_context_size_error|exceeds the available context size|prompt is too long/i;
169
+ function isContextOverflow(error) {
170
+ if (typeof error === "string") return CONTEXT_OVERFLOW.test(error);
171
+ const fields = error;
172
+ const strings = [fields?.message, fields?.type, fields?.code].filter((v) => typeof v === "string");
173
+ return strings.some((v) => v === "context_length_exceeded" || CONTEXT_OVERFLOW.test(v));
174
+ }
175
+ function errorEvent(error) {
176
+ const message = errorPayloadMessage(error);
177
+ return isContextOverflow(error) ? { type: "error", message, code: AparteErrorCode.USAGE_CONTEXT_EXCEEDED } : { type: "error", message };
178
+ }
179
+ const WINDOW_FIELDS = ["context_length", "max_model_len", "context_window", "max_context_length"];
180
+ function positiveInt(v) {
181
+ return typeof v === "number" && Number.isInteger(v) && v > 0 ? v : void 0;
182
+ }
183
+ function genericWindow(entry) {
184
+ for (const field of WINDOW_FIELDS) {
185
+ const n = positiveInt(entry[field]);
186
+ if (n !== void 0) return n;
187
+ }
188
+ return void 0;
189
+ }
190
+ function asJson(v) {
191
+ return v !== null && typeof v === "object" ? v : {};
192
+ }
193
+ function asJsonList(v) {
194
+ return Array.isArray(v) ? v.map(asJson) : [];
195
+ }
196
+ async function getJSON(url, headers) {
197
+ const response = await fetch(url, { headers });
198
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
199
+ return asJson(await response.json());
200
+ }
201
+ async function probeWindows(server, origin, headers) {
202
+ if (server === "lmstudio") {
203
+ const byId = /* @__PURE__ */ new Map();
204
+ let data;
205
+ try {
206
+ data = await getJSON(`${origin}/api/v1/models`, headers);
207
+ } catch {
208
+ const legacy = await getJSON(`${origin}/api/v0/models`, headers);
209
+ for (const m of asJsonList(legacy["data"])) {
210
+ const n = positiveInt(m["loaded_context_length"]);
211
+ if (typeof m["id"] === "string" && n !== void 0) byId.set(m["id"], n);
212
+ }
213
+ return (id) => byId.get(id);
214
+ }
215
+ for (const m of asJsonList(data["models"])) {
216
+ const instances = asJsonList(m["loaded_instances"]);
217
+ for (const instance of instances) {
218
+ const n = positiveInt(asJson(instance["config"])["context_length"]);
219
+ if (typeof instance["id"] === "string" && n !== void 0) byId.set(instance["id"], n);
220
+ }
221
+ const first = positiveInt(asJson(instances[0]?.["config"])["context_length"]);
222
+ if (typeof m["key"] === "string" && first !== void 0 && !byId.has(m["key"])) byId.set(m["key"], first);
223
+ }
224
+ return (id) => byId.get(id);
225
+ }
226
+ if (server === "ollama") {
227
+ const data = await getJSON(`${origin}/api/ps`, headers);
228
+ const byName = /* @__PURE__ */ new Map();
229
+ for (const m of asJsonList(data["models"])) {
230
+ const n = positiveInt(m["context_length"]);
231
+ if (n === void 0) continue;
232
+ for (const name of [m["name"], m["model"]]) if (typeof name === "string") byName.set(name, n);
233
+ }
234
+ return (id) => byName.get(id) ?? byName.get(id.endsWith(":latest") ? id.slice(0, -7) : `${id}:latest`);
235
+ }
236
+ if (server === "llamacpp") {
237
+ const data = await getJSON(`${origin}/props`, headers);
238
+ const n = positiveInt(asJson(data["default_generation_settings"])["n_ctx"]);
239
+ return n === void 0 ? void 0 : () => n;
240
+ }
241
+ return void 0;
242
+ }
122
243
  const DEFAULT_CONFIG_SCHEMA = (opts) => ({
123
244
  fields: opts.isLocal ? [
124
245
  { id: "endpoint", type: "url", label: "Server", defaultValue: opts.baseURL, required: true },
@@ -164,27 +285,39 @@ function createOpenAICompatProvider(opts) {
164
285
  const response = await fetch(`${endpoint}/models`, { headers });
165
286
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
166
287
  const data = await response.json();
167
- return (data.data ?? []).map((m) => ({
168
- id: m.id,
169
- name: m.name || m.id,
170
- contextWindow: m.context_length,
171
- // `function_calling` is declared because it is a property of the
172
- // WIRE FORMAT, which is what this provider is: `/chat/completions`
173
- // takes a `tools` array, and every server behind a compat endpoint
174
- // accepts one. `/models` returns `{id, object, owned_by}` and says
175
- // nothing about tools, so waiting for it to declare the capability
176
- // means never declaring it — and core gates tools on exactly this
177
- // field, so a registered tool, an approval gate and the whole
178
- // elicitation path were dead on this provider: the model was asked
179
- // to use a tool it had never been sent.
180
- //
181
- // The failure mode of over-declaring is mild and visible: a model
182
- // that cannot call tools simply does not call one. The failure mode
183
- // of under-declaring was silent and total. A server that rejects a
184
- // `tools` array outright surfaces as an error from its own endpoint,
185
- // which is the right place for that argument to happen.
186
- capabilities: ["streaming", "function_calling"]
187
- }));
288
+ let probed;
289
+ if (opts.server) {
290
+ try {
291
+ probed = await probeWindows(opts.server, new URL(endpoint).origin, headers);
292
+ } catch (error) {
293
+ console.warn(`[${displayName}] Could not read the context window from the ${opts.server} server:`, error);
294
+ }
295
+ }
296
+ const declared = new Map((opts.models ?? []).flatMap((m) => m.contextWindow ? [[m.id, m.contextWindow]] : []));
297
+ return (data.data ?? []).map((m) => {
298
+ const contextWindow = declared.get(m.id) ?? probed?.(m.id) ?? genericWindow(m);
299
+ return {
300
+ id: m.id,
301
+ name: m.name || m.id,
302
+ ...contextWindow !== void 0 ? { contextWindow } : {},
303
+ // `function_calling` is declared because it is a property of the
304
+ // WIRE FORMAT, which is what this provider is: `/chat/completions`
305
+ // takes a `tools` array, and every server behind a compat endpoint
306
+ // accepts one. `/models` returns `{id, object, owned_by}` and says
307
+ // nothing about tools, so waiting for it to declare the capability
308
+ // means never declaring it — and core gates tools on exactly this
309
+ // field, so a registered tool, an approval gate and the whole
310
+ // elicitation path were dead on this provider: the model was asked
311
+ // to use a tool it had never been sent.
312
+ //
313
+ // The failure mode of over-declaring is mild and visible: a model
314
+ // that cannot call tools simply does not call one. The failure mode
315
+ // of under-declaring was silent and total. A server that rejects a
316
+ // `tools` array outright surfaces as an error from its own endpoint,
317
+ // which is the right place for that argument to happen.
318
+ capabilities: ["streaming", "function_calling"]
319
+ };
320
+ });
188
321
  } catch (error) {
189
322
  console.error(`[${displayName}] Failed to fetch models:`, error);
190
323
  return [];
@@ -222,7 +355,21 @@ function createOpenAICompatProvider(opts) {
222
355
  parseStream(body) {
223
356
  return parseOpenAICompatStream(body);
224
357
  },
358
+ /**
359
+ * A 400 (or a 413) whose body says the prompt did not fit is an overflow, not a bad
360
+ * request: the client compacts and sends the turn again. Other statuses keep what
361
+ * the status says.
362
+ */
363
+ classifyError(status, body) {
364
+ if (status !== 400 && status !== 413) return void 0;
365
+ return isContextOverflow(body?.error) ? AparteErrorCode.USAGE_CONTEXT_EXCEEDED : void 0;
366
+ },
225
367
  parseText(json) {
368
+ const payload = json;
369
+ if (payload?.error && !payload.choices) {
370
+ const failure = new Error(errorPayloadMessage(payload.error));
371
+ throw isContextOverflow(payload.error) ? Object.assign(failure, { code: AparteErrorCode.USAGE_CONTEXT_EXCEEDED }) : failure;
372
+ }
226
373
  return json?.choices?.[0]?.message?.content || "";
227
374
  }
228
375
  };
@@ -235,6 +382,7 @@ function parseOpenAICompatStream(stream) {
235
382
  const toolCallAliases = /* @__PURE__ */ new Map();
236
383
  let mintedCallIds = 0;
237
384
  let capturedUsage;
385
+ let finishReason;
238
386
  let reader = null;
239
387
  const flushToolCalls = (controller, complete) => {
240
388
  for (const entry of toolCalls.values()) {
@@ -289,7 +437,7 @@ function parseOpenAICompatStream(stream) {
289
437
  const raw = trimmed.slice(5).trim();
290
438
  if (raw === "[DONE]") {
291
439
  flushToolCalls(controller, false);
292
- controller.enqueue({ type: "done", usage: capturedUsage });
440
+ controller.enqueue({ type: "done", usage: capturedUsage, ...finishReason ? { finishReason } : {} });
293
441
  return;
294
442
  }
295
443
  try {
@@ -302,8 +450,16 @@ function parseOpenAICompatStream(stream) {
302
450
  cacheReadTokens: json.usage.prompt_tokens_details?.cached_tokens
303
451
  };
304
452
  }
453
+ if (json.error) {
454
+ controller.enqueue(errorEvent(json.error));
455
+ reader?.cancel().catch(() => void 0);
456
+ return;
457
+ }
305
458
  const choice = json.choices?.[0];
306
459
  if (!choice) continue;
460
+ if (typeof choice.finish_reason === "string" && choice.finish_reason) {
461
+ finishReason = toFinishReason(choice.finish_reason);
462
+ }
307
463
  const delta = choice.delta;
308
464
  if (delta) {
309
465
  if (delta.reasoning_content) {
@@ -335,7 +491,7 @@ function parseOpenAICompatStream(stream) {
335
491
  }
336
492
  }
337
493
  flushToolCalls(controller, false);
338
- controller.enqueue({ type: "done", usage: capturedUsage });
494
+ controller.enqueue({ type: "done", usage: capturedUsage, ...finishReason ? { finishReason } : {} });
339
495
  } catch (err) {
340
496
  if (err?.name !== "AbortError") {
341
497
  controller.enqueue({ type: "error", message: err?.message ?? "Stream error" });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/presets.ts","../src/index.ts"],"sourcesContent":["/**\n * presets.ts — vendor DATA for well-known OpenAI-compatible endpoints.\n *\n * A preset is nothing but an `OpenAICompatProviderOptions` literal: base URL +\n * branding (icon/color/helpUrl) carried over from the retired per-vendor\n * packages. No code varies per vendor — that is the whole point.\n *\n * ```ts\n * aparteGlobalConfig.registerAIProvider(createOpenAICompatProvider(presets.MISTRAL));\n * ```\n *\n * Local servers (LM Studio, Ollama) are served through their OpenAI-compat\n * `/v1` endpoints — same format, `isLocal` just relaxes the key requirement.\n */\n\nimport type { OpenAICompatProviderOptions } from './index.js';\n\nconst OPENAI: OpenAICompatProviderOptions = {\n id: 'openai',\n baseURL: 'https://api.openai.com/v1',\n name: 'OpenAI',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2zm0 18a8 8 0 1 1 8-8 8 8 0 0 1-8 8z\"/><path d=\"M12 6v6l4 2\"/></svg>`,\n color: '#10a37f',\n description: 'GPT-4o, GPT-4 Turbo, and the O1 reasoning models',\n helpUrl: 'https://platform.openai.com/api-keys',\n};\n\nconst MISTRAL: OpenAICompatProviderOptions = {\n id: 'mistral',\n baseURL: 'https://api.mistral.ai/v1',\n name: 'Mistral AI',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M12 2l4 22-4-8-4 8 4-22z\"/></svg>`,\n color: '#fd7e14',\n description: 'European AI: Mistral Large, Mixtral, Codestral',\n helpUrl: 'https://console.mistral.ai/api-keys/',\n};\n\nconst ZAI: OpenAICompatProviderOptions = {\n id: 'zai',\n baseURL: 'https://open.bigmodel.cn/api/paas/v4',\n name: 'Z.ai (Zhipu)',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M13 2L3 14h9l-1 8 10-12h-9l1-8z\"/></svg>`,\n color: '#6366f1',\n description: \"Access Zhipu AI's free GLM models\",\n hasFreeModels: true,\n helpUrl: 'https://open.bigmodel.cn',\n};\n\nconst OPENROUTER: OpenAICompatProviderOptions = {\n id: 'openrouter',\n baseURL: 'https://openrouter.ai/api/v1',\n name: 'OpenRouter',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20\"/><path d=\"M2 12h20\"/></svg>`,\n color: '#000000',\n description: 'Access 100+ AI models through a single API',\n hasFreeModels: true,\n helpUrl: 'https://openrouter.ai/keys',\n // OpenRouter attribution headers (sent on chat + model fetch).\n extraHeaders: {\n 'HTTP-Referer': typeof window !== 'undefined' ? window.location.origin : '',\n 'X-Title': 'aparté',\n },\n};\n\nconst LMSTUDIO: OpenAICompatProviderOptions = {\n id: 'lmstudio',\n baseURL: 'http://localhost:1234/v1',\n name: 'LM Studio',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"2\"/><path d=\"M9 9h6v6H9z\"/><path d=\"M9 1h1v3h-1zM14 1h1v3h-1zM9 20h1v3h-1zM14 20h1v3h-1zM20 9h3v1h-3zM20 14h3v1h-3zM1 9h3v1H1zM1 14h3v1H1z\"/></svg>`,\n color: '#444444',\n description: 'Run LLMs locally with the LM Studio app',\n hasFreeModels: true,\n isLocal: true,\n helpUrl: 'https://lmstudio.ai/',\n};\n\n// Ollama through its OpenAI-compat endpoint (`/v1`), NOT its native `/api/chat`.\n// Same chat-completions format as everyone else; the native-protocol niceties\n// (inline base64 images, Ollama-shaped tool calls, keep_alive) don't apply —\n// see the README's Ollama section for the behavioural delta.\nconst OLLAMA: OpenAICompatProviderOptions = {\n id: 'ollama',\n baseURL: 'http://localhost:11434/v1',\n name: 'Ollama',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M12 2a10 10 0 0 1 10 10 10 10 0 0 1-10 10 10 10 0 0 1-10-10 10 10 0 0 1 10-10zM12 11l4 2-4 2-4-2 4-2zM12 6v5M12 15v3\"/></svg>`,\n color: '#57534e',\n description: 'Run LLMs locally — free and fully private',\n hasFreeModels: true,\n isLocal: true,\n helpUrl: 'https://ollama.com/',\n};\n\n/** Vendor presets for {@link createOpenAICompatProvider}. Pure data. */\nexport const presets = { OPENAI, MISTRAL, ZAI, OPENROUTER, LMSTUDIO, OLLAMA } as const;\n","/**\n * @aparte/provider-openai-compat — ONE adapter for every OpenAI-compatible\n * chat-completions endpoint.\n *\n * The OpenAI `/chat/completions` wire format is the de-facto industry standard:\n * OpenAI, Mistral, OpenRouter, Z.ai, Groq, Together, LM Studio, Ollama (`/v1`)\n * and many more all speak it. This package is the single, zero-dependency\n * format adapter for that family — vendors differ only by DATA (base URL, auth\n * header, branding), which you pass as config (or pick from `presets`).\n *\n * It replaces the per-vendor `@aparte/provider-{openai,mistral,zai,openrouter,\n * lmstudio,ollama}` packages, whose adapter bodies were byte-identical copies\n * (drift even produced real bugs: LM Studio dropped `max_tokens`, Z.ai dropped\n * `seed` — both fixed here by construction, there is only one body now).\n *\n * Model lists are CONSUMER data: pass `models` statically, or rely on the\n * generic `GET {baseURL}/models` fetcher (part of the compat standard). For\n * vendors outside this family (Anthropic, Gemini, …) use the AI-SDK bridge\n * provider instead — this package deliberately covers ONE format.\n */\n\nimport type {\n AparteAIProvider,\n AparteAIModel,\n AparteAIProviderConfigSchema,\n AparteChatRequest,\n AparteChatMessage,\n AparteTool,\n AparteToolCall,\n AparteContentPart,\n AparteStreamEvent,\n AparteUsage,\n AparteFormatAdapter,\n} from '@aparte/core';\nimport { contentToText } from '@aparte/core';\n\n// ─── Options ─────────────────────────────────────────────────────────────────\n\n/** Config for one OpenAI-compatible endpoint. Everything but `id`/`baseURL` is branding/data. */\nexport interface OpenAICompatProviderOptions {\n /** Provider id used across aparté (key resolution, model picker, events). */\n id: string;\n /** Endpoint base, e.g. `https://api.openai.com/v1` or `http://localhost:11434/v1`. */\n baseURL: string;\n /** Display name (defaults to `id`). */\n name?: string;\n /** Brand icon (SVG string / data URI / icon-provider key). */\n icon?: string;\n /** Brand color. */\n color?: string;\n /** Short tag line. */\n description?: string;\n /** Where the user gets a key. */\n helpUrl?: string;\n /** Whether the vendor offers free models. */\n hasFreeModels?: boolean;\n /**\n * Local server (LM Studio, Ollama…): key optional, and the generic\n * `/models` fetch runs even without a key.\n */\n isLocal?: boolean;\n /** Static model list (consumer data). Defaults to `[]` — use `fetchModels`. */\n models?: AparteAIModel[];\n /**\n * Extra headers sent on every request (chat + model fetch), e.g.\n * OpenRouter's attribution headers `HTTP-Referer` / `X-Title`.\n */\n extraHeaders?: Record<string, string>;\n /**\n * Fields added to every chat request body, for a vendor switch outside the OpenAI\n * schema, e.g. Zhipu's `thinking: { type: 'disabled' }` on GLM. The body's\n * counterpart of `extraHeaders`. The fields this adapter writes stay its own\n * (`model`, `messages`, `stream`, `tools`… see `ADAPTER_FIELDS`): an\n * `extraBody` key of the same name is ignored.\n */\n extraBody?: Record<string, unknown>;\n /** Override the default apiKey+endpoint settings schema. */\n configSchema?: AparteAIProviderConfigSchema;\n}\n\n/** The body fields `buildRequest` writes itself: `extraBody` cannot replace them. */\nconst ADAPTER_FIELDS = new Set(['model', 'messages', 'temperature', 'max_tokens', 'stream', 'stream_options', 'seed', 'tools', 'tool_choice']);\n\n// ─── Message / tool shaping (the format half) ────────────────────────────────\n\n/** Content → OpenAI multipart array when images are present. */\nfunction toOpenAIContent(content: string | AparteContentPart[]): unknown {\n if (typeof content === 'string') return content;\n // Two arms, exhaustive: a part is text or an image. A third used to answer the\n // removed `AparteFilePart` with an empty text part — a branch nothing could reach,\n // standing in for inline-file support this format does not have.\n return content.map(p => (p.type === 'text'\n ? { type: 'text', text: p.text }\n : { type: 'image_url', image_url: { url: p.image } }));\n}\n\n/**\n * The two roles a tool turn used to wear. `AparteChatMessage` no longer allows either, so\n * the comparison is on the role as a string: a message carrying one comes from code built\n * against an older aparté, which no type here can catch. Warned once per role, then\n * skipped — passing it on would put an unknown role on the wire and 400 the whole request.\n */\nconst LEGACY_TOOL_ROLES = new Set(['tool_call', 'tool_result']);\nconst warnedLegacyRoles = new Set<string>();\nfunction warnLegacyToolRole(role: string): void {\n if (warnedLegacyRoles.has(role)) return;\n warnedLegacyRoles.add(role);\n console.warn(\n `[@aparte/provider-openai-compat] Skipping a message with the removed role \"${role}\".`\n + \" A tool turn is now an assistant message carrying its calls — { role: 'assistant',\"\n + \" content: <what it said>, toolCalls } — followed by one { role: 'tool', content:\"\n + ' <result>, toolCallId, toolName } per call. This warning is removed in 0.18.',\n );\n}\n\n// The other half of that legacy shape, and it is deliberately NOT warned: an assistant\n// message built by hand with both `toolCalls` and image parts loses the images here.\n// Chat Completions does not carry them — an assistant message's content parts are `text`\n// and `refusal`, never `image_url` — so the mapping that used to emit them was a 400\n// waiting to happen, and the loop cannot mint the shape (`stream-run.ts` builds an\n// assistant's content from a string). Images on a USER turn are carried, unchanged.\n\n/** AparteChatMessage[] → OpenAI messages (incl. an assistant turn's calls and the `tool` answers). */\nfunction toOpenAIMessages(messages: AparteChatMessage[]): unknown[] {\n const out: unknown[] = [];\n for (const msg of messages) {\n const role: string = msg.role;\n if (LEGACY_TOOL_ROLES.has(role)) {\n warnLegacyToolRole(role);\n continue;\n }\n if (msg.role === 'tool') {\n out.push({ role: 'tool', tool_call_id: msg.toolCallId, content: contentToText(msg.content) });\n continue;\n }\n if (msg.role === 'assistant' && msg.toolCalls?.length) {\n out.push({\n role: 'assistant',\n // `||`, not `??`: this API takes null (or nothing) beside `tool_calls`, and\n // an assistant that said nothing before its calls now carries '' — which\n // some endpoints reject and the rest read as an empty reply.\n content: contentToText(msg.content) || null,\n tool_calls: msg.toolCalls.map(tc => ({\n id: tc.id,\n type: 'function',\n function: { name: tc.name, arguments: JSON.stringify(tc.input) },\n })),\n });\n continue;\n }\n out.push({ role: msg.role, content: toOpenAIContent(msg.content) });\n }\n return out;\n}\n\n/** AparteTool[] → OpenAI function-tool declarations. */\nfunction toOpenAITools(tools: AparteTool[]): unknown[] {\n return tools.map(t => ({\n type: 'function',\n function: { name: t.name, description: t.description, parameters: t.inputSchema },\n }));\n}\n\n/** Accept both raw keys and user-pasted `Bearer xxx` values (local servers). */\nfunction bearer(key: string): string {\n return key.startsWith('Bearer ') ? key : `Bearer ${key}`;\n}\n\nconst DEFAULT_CONFIG_SCHEMA = (opts: OpenAICompatProviderOptions): AparteAIProviderConfigSchema => ({\n fields: opts.isLocal\n ? [\n { id: 'endpoint', type: 'url', label: 'Server', defaultValue: opts.baseURL, required: true },\n { id: 'apiKey', type: 'password', label: 'API Key / Token (optional)', placeholder: 'Bearer ...', isAdvanced: true },\n ]\n : [\n { id: 'apiKey', type: 'password', label: 'API Key', placeholder: 'sk-...', required: true },\n { id: 'endpoint', type: 'url', label: 'Custom endpoint', placeholder: opts.baseURL, isAdvanced: true },\n ],\n});\n\n// ─── The factory ─────────────────────────────────────────────────────────────\n\n/**\n * What {@link createOpenAICompatProvider} hands back: a provider whose whole\n * format-adapter surface is guaranteed present.\n *\n * `AparteAIProvider` declares that surface optional — correct in general, since a\n * provider may own its I/O through `chat()` instead — and `AparteFormatAdapter` keeps\n * `authHeaders` / `parseText` optional because some vendors authenticate by query\n * string or never answer non-streaming. THIS factory always supplies all of them, so\n * saying so here is the difference between a caller writing\n * `provider.buildRequest(req)` and a caller sprinkling `!` or writing a check that\n * cannot fail. Useful to annotate with when you drive the adapter yourself (your own\n * `fetch`, your own `AbortSignal`) from a server or an Electron main process.\n */\nexport type OpenAICompatProvider =\n AparteAIProvider\n & AparteFormatAdapter\n & Required<Pick<AparteFormatAdapter, 'authHeaders' | 'parseText'>>;\n\n/**\n * Build an `AparteAIProvider` (full format-adapter surface) for one\n * OpenAI-compatible endpoint. Register it like any provider:\n *\n * ```ts\n * import { createOpenAICompatProvider, presets } from '@aparte/provider-openai-compat';\n * aparteGlobalConfig.registerAIProvider(createOpenAICompatProvider(presets.OPENROUTER));\n * // or any compat endpoint, no preset needed:\n * aparteGlobalConfig.registerAIProvider(createOpenAICompatProvider({ id: 'groq', baseURL: 'https://api.groq.com/openai/v1' }));\n * ```\n *\n * Returns {@link OpenAICompatProvider}: the full format-adapter surface, non-optional.\n */\nexport function createOpenAICompatProvider(opts: OpenAICompatProviderOptions): OpenAICompatProvider {\n const displayName = opts.name ?? opts.id;\n\n return {\n id: opts.id,\n\n getMetadata() {\n return {\n id: opts.id,\n name: displayName,\n icon: opts.icon,\n color: opts.color,\n description: opts.description,\n helpUrl: opts.helpUrl,\n hasFreeModels: opts.hasFreeModels,\n isLocal: opts.isLocal,\n configSchema: opts.configSchema ?? DEFAULT_CONFIG_SCHEMA(opts),\n };\n },\n\n getModels(): AparteAIModel[] {\n return opts.models ?? [];\n },\n\n /**\n * Generic `GET {baseURL}/models` — part of the compat standard. Cloud\n * endpoints need a key (returns `[]` without one); local servers fetch\n * keyless. Vendor-specific niceties (pricing, name prettifying) are\n * consumer concerns: pass `models` yourself for anything fancier.\n */\n async fetchModels(config?: string | Record<string, string>): Promise<AparteAIModel[]> {\n const apiKey = typeof config === 'string' ? config : config?.['apiKey'];\n const endpoint = (typeof config === 'object' ? config?.['endpoint'] : null) || opts.baseURL;\n if (!apiKey && !opts.isLocal) return [];\n\n try {\n const headers: Record<string, string> = { ...opts.extraHeaders };\n if (apiKey) headers['Authorization'] = bearer(apiKey);\n const response = await fetch(`${endpoint}/models`, { headers });\n if (!response.ok) throw new Error(`HTTP ${response.status}`);\n const data = await response.json() as { data?: Array<{ id: string; name?: string; context_length?: number }> };\n return (data.data ?? []).map(m => ({\n id: m.id,\n name: m.name || m.id,\n contextWindow: m.context_length,\n // `function_calling` is declared because it is a property of the\n // WIRE FORMAT, which is what this provider is: `/chat/completions`\n // takes a `tools` array, and every server behind a compat endpoint\n // accepts one. `/models` returns `{id, object, owned_by}` and says\n // nothing about tools, so waiting for it to declare the capability\n // means never declaring it — and core gates tools on exactly this\n // field, so a registered tool, an approval gate and the whole\n // elicitation path were dead on this provider: the model was asked\n // to use a tool it had never been sent.\n //\n // The failure mode of over-declaring is mild and visible: a model\n // that cannot call tools simply does not call one. The failure mode\n // of under-declaring was silent and total. A server that rejects a\n // `tools` array outright surfaces as an error from its own endpoint,\n // which is the right place for that argument to happen.\n capabilities: ['streaming', 'function_calling'],\n }));\n } catch (error) {\n console.error(`[${displayName}] Failed to fetch models:`, error);\n return [];\n }\n },\n\n // ── Format-adapter surface (transport ⊥ format) ──────────────────────\n // The vendor concern only: request shape + stream parsing. Auth and\n // network are the transport's job (AparteDirectTransport / AparteBackendTransport).\n defaultEndpoint: opts.baseURL,\n\n buildRequest(request: AparteChatRequest) {\n const body: Record<string, unknown> = {\n ...Object.fromEntries(Object.entries(opts.extraBody ?? {}).filter(([key]) => !ADAPTER_FIELDS.has(key))),\n model: request.modelId,\n messages: toOpenAIMessages(request.messages),\n temperature: request.temperature,\n max_tokens: request.maxTokens,\n stream: request.stream ?? true,\n ...((request.stream ?? true) ? { stream_options: { include_usage: true } } : {}),\n ...(request.seed !== undefined ? { seed: request.seed } : {}),\n };\n if (request.tools?.length) {\n body['tools'] = toOpenAITools(request.tools);\n /*\n * A forced tool travels; `'auto'` is only the DEFAULT. It used to be\n * written unconditionally, so `toolChoice: { name }` — a shape the loop\n * passes straight through, since it intercepts only `{ name, input }`\n * (the synthetic call it runs itself) — was silently downgraded to\n * \"the model decides\", while the ai-sdk bridge honoured the same field.\n * `'none'` never reaches here: core strips the tools upstream.\n */\n const forced = typeof request.toolChoice === 'object' ? request.toolChoice.name : undefined;\n body['tool_choice'] = forced ? { type: 'function', function: { name: forced } } : 'auto';\n }\n return {\n path: '/chat/completions',\n body,\n ...(opts.extraHeaders ? { headers: opts.extraHeaders } : {}),\n };\n },\n\n authHeaders(key: string) {\n return { Authorization: bearer(key) };\n },\n\n parseStream(body: ReadableStream<Uint8Array>) {\n return parseOpenAICompatStream(body);\n },\n\n parseText(json: unknown): string {\n return (json as { choices?: Array<{ message?: { content?: string } }> })?.choices?.[0]?.message?.content || '';\n },\n };\n}\n\n// ─── SSE stream parser (ported from @aparte/core parseOpenAIStream) ──────────\n\n/**\n * OpenAI-compatible SSE stream parser — this package's own copy of core's\n * `parseOpenAIStream` (the parser follows the format adapter; core keeps only\n * the aparté-native NDJSON parser).\n *\n * Handles:\n * - `delta.content` → text event\n * - `delta.reasoning_content` → thinking event (Qwen3, DeepSeek R1, …)\n * - `delta.tool_calls` → accumulate → tool_use on finish_reason='tool_calls'\n * - usage-only chunk + [DONE] → done{usage}\n */\nexport function parseOpenAICompatStream(\n stream: ReadableStream<Uint8Array>,\n): ReadableStream<AparteStreamEvent> {\n const decoder = new TextDecoder();\n let buffer = '';\n\n /*\n * Tool call accumulation state, in wire order, keyed by `toolCallKey` below.\n * A Map, not an object: the key comes off the wire, and on a plain `{}` a chunk\n * whose `index` is `\"__proto__\"` writes into Object.prototype for the whole page.\n */\n const toolCalls = new Map<string, { id: string; name: string; args: string }>();\n /** The call the last delta touched — what a bare argument fragment continues. */\n let lastToolKey: string | null = null;\n /**\n * Every key a delta has addressed a call by → that call's slot in `toolCalls`.\n * One call can be addressed both ways in one turn (by `index` in a chunk, by `id`\n * in the next), so the identity is the alias, not the key of the moment.\n */\n const toolCallAliases = new Map<string, string>();\n /** Ids minted for a vendor that sends none. Per stream, i.e. per turn. */\n let mintedCallIds = 0;\n let capturedUsage: AparteUsage | undefined;\n let reader: ReadableStreamDefaultReader<Uint8Array> | null = null;\n\n /*\n * Emit the accumulated calls and clear the map.\n *\n * Called at EVERY graceful end of a turn, not only on `finish_reason: 'tool_calls'`:\n * the accumulation spans the whole stream, and a vendor that ends with `stop`,\n * `length` or a bare `[DONE]` after streaming tool-call deltas used to drop them —\n * the model had asked for a tool and the loop never heard. `complete` says the\n * model declared the calls finished: a parse failure there is malformed JSON (a\n * real small-model failure) and the tool still runs, on `{}`. Elsewhere it is\n * truncation, and running a tool on `{}` for a call the model never finished would\n * be worse than dropping it — so those are dropped, with a breadcrumb.\n */\n const flushToolCalls = (controller: ReadableStreamDefaultController<AparteStreamEvent>, complete: boolean): void => {\n for (const entry of toolCalls.values()) {\n let input: Record<string, unknown> = {};\n try {\n input = entry.args.trim() ? JSON.parse(entry.args) : {};\n } catch {\n if (!complete) {\n console.warn(`[openai-compat] Tool \"${entry.name}\" was cut mid-arguments (the turn ended without finish_reason 'tool_calls'); the call is dropped. Raw:`, entry.args);\n continue;\n }\n console.warn(\n `[openai-compat] Tool \"${entry.name}\" returned malformed arguments JSON; ` +\n `passing empty input. Raw:`, entry.args,\n );\n }\n const toolCall: AparteToolCall = { id: entry.id, name: entry.name, input };\n controller.enqueue({ type: 'tool_use', ...toolCall });\n }\n toolCalls.clear();\n toolCallAliases.clear();\n lastToolKey = null;\n };\n\n /*\n * Which accumulated call a `delta.tool_calls` entry belongs to.\n *\n * Both `index` and `id` address a call, and a vendor may use one in a chunk and\n * the other in the next — so neither can BE the identity: a delta's keys are\n * ALIASES that all resolve to the same slot. A key already resolved names the\n * call, and every key a delta carries is recorded against the slot it lands on.\n * Picking one key instead (`index` first, `id` next) split such a call in two,\n * the second half nameless, and the turn ran the tool on `{}`.\n *\n * When no key of the delta is known yet, the function NAME decides — it appears\n * only on a call's FIRST delta, so a nameless delta continues the call before it\n * and a named one opens its own. That single rule covers the vendor whose deltas\n * never carry both addresses at once (open by `id`, continue by `index`, or the\n * reverse) and the vendor that carries neither: `index` is a streaming\n * convenience, not part of the function-call payload, and keying on it alone\n * (`Number(tc.index ?? 0)`) put every call of a server that omits it on slot 0.\n *\n * `null` means \"skip this entry\": an `index` the vendor sent that is not a\n * non-negative integer is not a slot number, it is malformed (or hostile —\n * `\"__proto__\"` was the shape that made this a Map).\n */\n const toolCallKey = (tc: { index?: unknown; id?: string; function?: { name?: string } }): string | null => {\n let indexKey: string | undefined;\n if (tc.index !== undefined && tc.index !== null) {\n // Made a number, not annotated as one: `index` is whatever the vendor's JSON put there.\n const idx = Number(tc.index);\n if (!Number.isInteger(idx) || idx < 0) return null;\n indexKey = `i${idx}`;\n }\n const idKey = tc.id ? `d${tc.id}` : undefined;\n const known = (idKey ? toolCallAliases.get(idKey) : undefined) ?? (indexKey ? toolCallAliases.get(indexKey) : undefined);\n // No key of this delta is known yet. A nameless delta never OPENS a call, so it\n // continues the call before it — which is what keeps ONE call together when the\n // vendor opens it with one address and continues it with the other, neither\n // delta carrying both. A named delta still opens its own slot.\n const key = known ?? ((!tc.function?.name && lastToolKey !== null) ? lastToolKey : (idKey ?? indexKey));\n if (key === undefined) return `p${toolCalls.size}`;\n if (idKey) toolCallAliases.set(idKey, key);\n if (indexKey) toolCallAliases.set(indexKey, key);\n return key;\n };\n\n return new ReadableStream<AparteStreamEvent>({\n async start(controller) {\n reader = stream.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed.startsWith('data:')) continue;\n const raw = trimmed.slice(5).trim();\n if (raw === '[DONE]') {\n // A turn that streamed tool-call deltas and ended on `stop`,\n // `length` or a bare [DONE]: the calls are still the model's.\n flushToolCalls(controller, false);\n controller.enqueue({ type: 'done', usage: capturedUsage });\n return;\n }\n try {\n const json = JSON.parse(raw);\n\n // Capture usage from the usage-only chunk (choices: [])\n if (json.usage) {\n capturedUsage = {\n inputTokens: json.usage.prompt_tokens ?? 0,\n outputTokens: json.usage.completion_tokens ?? 0,\n totalTokens: json.usage.total_tokens,\n cacheReadTokens: json.usage.prompt_tokens_details?.cached_tokens,\n };\n }\n\n const choice = json.choices?.[0];\n if (!choice) continue;\n\n const delta = choice.delta;\n if (delta) {\n if (delta.reasoning_content) {\n controller.enqueue({ type: 'thinking', delta: delta.reasoning_content });\n }\n if (delta.content) {\n controller.enqueue({ type: 'text', delta: delta.content });\n }\n if (delta.tool_calls) {\n for (const tc of delta.tool_calls) {\n const key = toolCallKey(tc);\n if (key === null) continue;\n let entry = toolCalls.get(key);\n if (!entry) {\n /*\n * An id is MINTED when the vendor sends none. `id: ''`\n * used to travel: the transcript keys a row on\n * `tool-${id}` and the history a result on\n * `toolCallId`, so two id-less calls in one turn shared\n * one row (the second call's result landed on the first\n * call's line) and one history slot an OpenAI-shaped\n * endpoint rejects on the next turn. A real id arriving\n * in a later chunk still wins, below. The mint is\n * namespaced because `call_1` is what an OpenAI-shaped\n * server calls its own first call: a turn mixing an\n * id-less call with a real `call_1` minted a duplicate.\n */\n entry = { id: tc.id ?? `aparte-call-${++mintedCallIds}`, name: tc.function?.name ?? '', args: '' };\n toolCalls.set(key, entry);\n }\n lastToolKey = key;\n if (tc.id) entry.id = tc.id;\n if (tc.function?.name) entry.name = tc.function.name;\n if (tc.function?.arguments) entry.args += tc.function.arguments;\n }\n }\n }\n\n // The model declared the calls complete: emit them now (and clear\n // the map, so a server that repeats the finish chunk cannot\n // re-emit them). Do NOT emit `done` or return here: under\n // `include_usage` (which buildRequest requests) the usage-only\n // chunk arrives AFTER this finish chunk, so stopping now dropped\n // usage on every tool-call turn — i.e. most turns of an agent.\n // Keep reading; the single `done` comes from `[DONE]` below, or\n // from the end-of-stream fallback if the socket just closes.\n if (choice.finish_reason === 'tool_calls') flushToolCalls(controller, true);\n } catch {\n // Every line here is a complete, newline-terminated SSE\n // line (see buffer split above), so a parse failure is an\n // unexpected/malformed server payload, not partial JSON —\n // log a breadcrumb instead of dropping it silently.\n console.warn('[openai-compat] Skipped an unparseable SSE data line:', raw);\n }\n }\n }\n // The socket closed without [DONE]: same rule, the calls are flushed first.\n flushToolCalls(controller, false);\n controller.enqueue({ type: 'done', usage: capturedUsage });\n } catch (err: unknown) {\n // AbortError surfaces here when the caller's signal fires mid-stream:\n // the consumer (agent loop) cancelled on purpose — end quietly, the\n // same way the ai-sdk provider does. Reporting it as an `error` event\n // makes a deliberate Stop indistinguishable from a network failure,\n // and the loop's error branch then replaces the streamed answer with\n // an error bubble.\n if ((err as { name?: string } | undefined)?.name !== 'AbortError') {\n controller.enqueue({ type: 'error', message: (err as Error | undefined)?.message ?? 'Stream error' });\n }\n } finally {\n reader?.releaseLock();\n reader = null;\n controller.close();\n }\n },\n // Consumer cancelled (e.g. user hit \"stop\"): cancel the underlying reader so\n // the vendor response body stops being drained to its natural end instead of\n // silently finishing the whole SSE stream in the background.\n cancel(reason) {\n const r = reader;\n reader = null;\n return r?.cancel(reason);\n },\n });\n}\n\nexport * from './presets.js';\nexport type { AparteAIProvider, AparteAIModel } from '@aparte/core';\n"],"names":[],"mappings":";AAiBA,MAAM,SAAsC;AAAA,EACxC,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS;AACb;AAEA,MAAM,UAAuC;AAAA,EACzC,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS;AACb;AAEA,MAAM,MAAmC;AAAA,EACrC,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,eAAe;AAAA,EACf,SAAS;AACb;AAEA,MAAM,aAA0C;AAAA,EAC5C,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,eAAe;AAAA,EACf,SAAS;AAAA;AAAA,EAET,cAAc;AAAA,IACV,gBAAgB,OAAO,WAAW,cAAc,OAAO,SAAS,SAAS;AAAA,IACzE,WAAW;AAAA,EAAA;AAEnB;AAEA,MAAM,WAAwC;AAAA,EAC1C,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,eAAe;AAAA,EACf,SAAS;AAAA,EACT,SAAS;AACb;AAMA,MAAM,SAAsC;AAAA,EACxC,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,E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IAAI,GAAG;AAC7B,wBAAI,CAAC,OAAO;AAcR,8BAAQ,EAAE,IAAI,GAAG,MAAM,eAAe,EAAE,aAAa,IAAI,MAAM,GAAG,UAAU,QAAQ,IAAI,MAAM,GAAA;AAC9F,gCAAU,IAAI,KAAK,KAAK;AAAA,oBAC5B;AACA,kCAAc;AACd,wBAAI,GAAG,GAAI,OAAM,KAAK,GAAG;AACzB,wBAAI,GAAG,UAAU,KAAM,OAAM,OAAO,GAAG,SAAS;AAChD,wBAAI,GAAG,UAAU,UAAW,OAAM,QAAQ,GAAG,SAAS;AAAA,kBAC1D;AAAA,gBACJ;AAAA,cACJ;AAUA,kBAAI,OAAO,kBAAkB,aAAc,gBAAe,YAAY,IAAI;AAAA,YAC9E,QAAQ;AAKJ,sBAAQ,KAAK,yDAAyD,GAAG;AAAA,YAC7E;AAAA,UACJ;AAAA,QACJ;AAEA,uBAAe,YAAY,KAAK;AAChC,mBAAW,QAAQ,EAAE,MAAM,QAAQ,OAAO,eAAe;AAAA,MAC7D,SAAS,KAAc;AAOnB,YAAK,KAAuC,SAAS,cAAc;AAC/D,qBAAW,QAAQ,EAAE,MAAM,SAAS,SAAU,KAA2B,WAAW,gBAAgB;AAAA,QACxG;AAAA,MACJ,UAAA;AACI,gBAAQ,YAAA;AACR,iBAAS;AACT,mBAAW,MAAA;AAAA,MACf;AAAA,IACJ;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,QAAQ;AACX,YAAM,IAAI;AACV,eAAS;AACT,aAAO,GAAG,OAAO,MAAM;AAAA,IAC3B;AAAA,EAAA,CACH;AACL;"}
1
+ {"version":3,"file":"index.js","sources":["../src/presets.ts","../src/index.ts"],"sourcesContent":["/**\n * presets.ts — vendor DATA for well-known OpenAI-compatible endpoints.\n *\n * A preset is nothing but an `OpenAICompatProviderOptions` literal: base URL +\n * branding (icon/color/helpUrl) carried over from the retired per-vendor\n * packages. No code varies per vendor — that is the whole point.\n *\n * ```ts\n * aparteGlobalConfig.registerAIProvider(createOpenAICompatProvider(presets.MISTRAL));\n * ```\n *\n * Local servers (LM Studio, Ollama) are served through their OpenAI-compat\n * `/v1` endpoints — same format, `isLocal` just relaxes the key requirement.\n */\n\nimport type { OpenAICompatProviderOptions } from './index.js';\n\nconst OPENAI: OpenAICompatProviderOptions = {\n id: 'openai',\n baseURL: 'https://api.openai.com/v1',\n name: 'OpenAI',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2zm0 18a8 8 0 1 1 8-8 8 8 0 0 1-8 8z\"/><path d=\"M12 6v6l4 2\"/></svg>`,\n color: '#10a37f',\n description: 'GPT-4o, GPT-4 Turbo, and the O1 reasoning models',\n helpUrl: 'https://platform.openai.com/api-keys',\n};\n\nconst MISTRAL: OpenAICompatProviderOptions = {\n id: 'mistral',\n baseURL: 'https://api.mistral.ai/v1',\n name: 'Mistral AI',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M12 2l4 22-4-8-4 8 4-22z\"/></svg>`,\n color: '#fd7e14',\n description: 'European AI: Mistral Large, Mixtral, Codestral',\n helpUrl: 'https://console.mistral.ai/api-keys/',\n};\n\nconst ZAI: OpenAICompatProviderOptions = {\n id: 'zai',\n baseURL: 'https://open.bigmodel.cn/api/paas/v4',\n name: 'Z.ai (Zhipu)',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M13 2L3 14h9l-1 8 10-12h-9l1-8z\"/></svg>`,\n color: '#6366f1',\n description: \"Access Zhipu AI's free GLM models\",\n hasFreeModels: true,\n helpUrl: 'https://open.bigmodel.cn',\n};\n\nconst OPENROUTER: OpenAICompatProviderOptions = {\n id: 'openrouter',\n baseURL: 'https://openrouter.ai/api/v1',\n name: 'OpenRouter',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20\"/><path d=\"M2 12h20\"/></svg>`,\n color: '#000000',\n description: 'Access 100+ AI models through a single API',\n hasFreeModels: true,\n helpUrl: 'https://openrouter.ai/keys',\n // OpenRouter attribution headers (sent on chat + model fetch).\n extraHeaders: {\n 'HTTP-Referer': typeof window !== 'undefined' ? window.location.origin : '',\n 'X-Title': 'aparté',\n },\n};\n\nconst LMSTUDIO: OpenAICompatProviderOptions = {\n id: 'lmstudio',\n baseURL: 'http://localhost:1234/v1',\n name: 'LM Studio',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"2\"/><path d=\"M9 9h6v6H9z\"/><path d=\"M9 1h1v3h-1zM14 1h1v3h-1zM9 20h1v3h-1zM14 20h1v3h-1zM20 9h3v1h-3zM20 14h3v1h-3zM1 9h3v1H1zM1 14h3v1H1z\"/></svg>`,\n color: '#444444',\n description: 'Run LLMs locally with the LM Studio app',\n hasFreeModels: true,\n isLocal: true,\n server: 'lmstudio',\n helpUrl: 'https://lmstudio.ai/',\n};\n\n// Ollama through its OpenAI-compat endpoint (`/v1`), NOT its native `/api/chat`.\n// Same chat-completions format as everyone else; the native-protocol niceties\n// (inline base64 images, Ollama-shaped tool calls, keep_alive) don't apply —\n// see the README's Ollama section for the behavioural delta.\nconst OLLAMA: OpenAICompatProviderOptions = {\n id: 'ollama',\n baseURL: 'http://localhost:11434/v1',\n name: 'Ollama',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M12 2a10 10 0 0 1 10 10 10 10 0 0 1-10 10 10 10 0 0 1-10-10 10 10 0 0 1 10-10zM12 11l4 2-4 2-4-2 4-2zM12 6v5M12 15v3\"/></svg>`,\n color: '#57534e',\n description: 'Run LLMs locally — free and fully private',\n hasFreeModels: true,\n isLocal: true,\n server: 'ollama',\n helpUrl: 'https://ollama.com/',\n};\n\n// llama.cpp's `llama-server` and vLLM both serve `/v1/chat/completions` on their own\n// port. The icons are generic line art (a chip, a stack of layers), not either project's mark.\nconst LLAMACPP: OpenAICompatProviderOptions = {\n id: 'llamacpp',\n baseURL: 'http://localhost:8080/v1',\n name: 'llama.cpp',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><rect x=\"3\" y=\"5\" width=\"18\" height=\"14\" rx=\"2\"/><path d=\"M7 9h2M7 12h6M7 15h4\"/></svg>`,\n color: '#64748b',\n description: 'Run GGUF models locally with llama-server',\n hasFreeModels: true,\n isLocal: true,\n server: 'llamacpp',\n helpUrl: 'https://github.com/ggml-org/llama.cpp',\n};\n\nconst VLLM: OpenAICompatProviderOptions = {\n id: 'vllm',\n baseURL: 'http://localhost:8000/v1',\n name: 'vLLM',\n icon: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M12 3l9 5-9 5-9-5 9-5z\"/><path d=\"M3 13l9 5 9-5\"/></svg>`,\n color: '#6b7280',\n description: 'Serve open models from your own GPU with vLLM',\n hasFreeModels: true,\n isLocal: true,\n server: 'vllm',\n helpUrl: 'https://docs.vllm.ai/',\n};\n\n/** Vendor presets for {@link createOpenAICompatProvider}. Pure data. */\nexport const presets = { OPENAI, MISTRAL, ZAI, OPENROUTER, LMSTUDIO, OLLAMA, LLAMACPP, VLLM } as const;\n","/**\n * @aparte/provider-openai-compat — ONE adapter for every OpenAI-compatible\n * chat-completions endpoint.\n *\n * The OpenAI `/chat/completions` wire format is the de-facto industry standard:\n * OpenAI, Mistral, OpenRouter, Z.ai, Groq, Together, LM Studio, Ollama (`/v1`)\n * and many more all speak it. This package is the single, zero-dependency\n * format adapter for that family — vendors differ only by DATA (base URL, auth\n * header, branding), which you pass as config (or pick from `presets`).\n *\n * It replaces the per-vendor `@aparte/provider-{openai,mistral,zai,openrouter,\n * lmstudio,ollama}` packages, whose adapter bodies were byte-identical copies\n * (drift even produced real bugs: LM Studio dropped `max_tokens`, Z.ai dropped\n * `seed` — both fixed here by construction, there is only one body now).\n *\n * Model lists are CONSUMER data: pass `models` statically, or rely on the\n * generic `GET {baseURL}/models` fetcher (part of the compat standard). For\n * vendors outside this family (Anthropic, Gemini, …) use the AI-SDK bridge\n * provider instead — this package deliberately covers ONE format.\n */\n\nimport type {\n AparteAIProvider,\n AparteAIModel,\n AparteAIProviderConfigSchema,\n AparteChatRequest,\n AparteChatMessage,\n AparteTool,\n AparteToolCall,\n AparteContentPart,\n AparteStreamEvent,\n AparteUsage,\n AparteFinishReason,\n AparteFormatAdapter,\n} from '@aparte/core';\nimport { AparteErrorCode, contentToText } from '@aparte/core';\n\n// ─── Options ─────────────────────────────────────────────────────────────────\n\n/** Config for one OpenAI-compatible endpoint. Everything but `id`/`baseURL` is branding/data. */\nexport interface OpenAICompatProviderOptions {\n /** Provider id used across aparté (key resolution, model picker, events). */\n id: string;\n /** Endpoint base, e.g. `https://api.openai.com/v1` or `http://localhost:11434/v1`. */\n baseURL: string;\n /** Display name (defaults to `id`). */\n name?: string;\n /** Brand icon (SVG string / data URI / icon-provider key). */\n icon?: string;\n /** Brand color. */\n color?: string;\n /** Short tag line. */\n description?: string;\n /** Where the user gets a key. */\n helpUrl?: string;\n /** Whether the vendor offers free models. */\n hasFreeModels?: boolean;\n /**\n * Local server (LM Studio, Ollama…): key optional, and the generic\n * `/models` fetch runs even without a key.\n */\n isLocal?: boolean;\n /**\n * Which local server this endpoint is, so `fetchModels` can read the context window\n * the server actually serves through that server's own API: LM Studio's\n * `/api/v1/models`, Ollama's `/api/ps`, llama.cpp's `/props`. Data, not code — the\n * request shape is the same for everyone and only the probe differs. With it,\n * `fetchModels` makes one extra request at the endpoint's origin (the `/v1` path\n * stripped) and prefers the EFFECTIVE window (what the server loaded, which is where\n * it truncates) over the trained maximum. A probe that fails leaves the models\n * without a window; it never fails the model list. `'vllm'` needs no extra request,\n * its `/v1/models` already carries `max_model_len`, and is accepted so a preset can\n * say what it is.\n */\n server?: 'lmstudio' | 'ollama' | 'llamacpp' | 'vllm';\n /** Static model list (consumer data). Defaults to `[]` — use `fetchModels`. */\n models?: AparteAIModel[];\n /**\n * Extra headers sent on every request (chat + model fetch), e.g.\n * OpenRouter's attribution headers `HTTP-Referer` / `X-Title`.\n */\n extraHeaders?: Record<string, string>;\n /**\n * Fields added to every chat request body, for a vendor switch outside the OpenAI\n * schema, e.g. Zhipu's `thinking: { type: 'disabled' }` on GLM. The body's\n * counterpart of `extraHeaders`. The fields this adapter writes stay its own\n * (`model`, `messages`, `stream`, `tools`… see `ADAPTER_FIELDS`): an\n * `extraBody` key of the same name is ignored.\n */\n extraBody?: Record<string, unknown>;\n /** Override the default apiKey+endpoint settings schema. */\n configSchema?: AparteAIProviderConfigSchema;\n}\n\n/** The body fields `buildRequest` writes itself: `extraBody` cannot replace them. */\nconst ADAPTER_FIELDS = new Set(['model', 'messages', 'temperature', 'max_tokens', 'stream', 'stream_options', 'seed', 'tools', 'tool_choice']);\n\n// ─── Message / tool shaping (the format half) ────────────────────────────────\n\n/** Content → OpenAI multipart array when images are present. */\nfunction toOpenAIContent(content: string | AparteContentPart[]): unknown {\n if (typeof content === 'string') return content;\n // Two arms, exhaustive: a part is text or an image. A third used to answer the\n // removed `AparteFilePart` with an empty text part — a branch nothing could reach,\n // standing in for inline-file support this format does not have.\n return content.map(p => (p.type === 'text'\n ? { type: 'text', text: p.text }\n : { type: 'image_url', image_url: { url: p.image } }));\n}\n\n/**\n * The two roles a tool turn used to wear. `AparteChatMessage` no longer allows either, so\n * the comparison is on the role as a string: a message carrying one comes from code built\n * against an older aparté, which no type here can catch. Warned once per role, then\n * skipped — passing it on would put an unknown role on the wire and 400 the whole request.\n */\nconst LEGACY_TOOL_ROLES = new Set(['tool_call', 'tool_result']);\nconst warnedLegacyRoles = new Set<string>();\nfunction warnLegacyToolRole(role: string): void {\n if (warnedLegacyRoles.has(role)) return;\n warnedLegacyRoles.add(role);\n console.warn(\n `[@aparte/provider-openai-compat] Skipping a message with the removed role \"${role}\".`\n + \" A tool turn is now an assistant message carrying its calls — { role: 'assistant',\"\n + \" content: <what it said>, toolCalls } — followed by one { role: 'tool', content:\"\n + ' <result>, toolCallId, toolName } per call. This warning is removed in 0.18.',\n );\n}\n\n// The other half of that legacy shape, and it is deliberately NOT warned: an assistant\n// message built by hand with both `toolCalls` and image parts loses the images here.\n// Chat Completions does not carry them — an assistant message's content parts are `text`\n// and `refusal`, never `image_url` — so the mapping that used to emit them was a 400\n// waiting to happen, and the loop cannot mint the shape (`stream-run.ts` builds an\n// assistant's content from a string). Images on a USER turn are carried, unchanged.\n\n/** AparteChatMessage[] → OpenAI messages (incl. an assistant turn's calls and the `tool` answers). */\nfunction toOpenAIMessages(messages: AparteChatMessage[]): unknown[] {\n const out: unknown[] = [];\n for (const msg of messages) {\n const role: string = msg.role;\n if (LEGACY_TOOL_ROLES.has(role)) {\n warnLegacyToolRole(role);\n continue;\n }\n if (msg.role === 'tool') {\n out.push({ role: 'tool', tool_call_id: msg.toolCallId, content: contentToText(msg.content) });\n continue;\n }\n if (msg.role === 'assistant' && msg.toolCalls?.length) {\n out.push({\n role: 'assistant',\n // `||`, not `??`: this API takes null (or nothing) beside `tool_calls`, and\n // an assistant that said nothing before its calls now carries '' — which\n // some endpoints reject and the rest read as an empty reply.\n content: contentToText(msg.content) || null,\n tool_calls: msg.toolCalls.map(tc => ({\n id: tc.id,\n type: 'function',\n function: { name: tc.name, arguments: JSON.stringify(tc.input) },\n })),\n });\n continue;\n }\n out.push({ role: msg.role, content: toOpenAIContent(msg.content) });\n }\n return out;\n}\n\n/** AparteTool[] → OpenAI function-tool declarations. */\nfunction toOpenAITools(tools: AparteTool[]): unknown[] {\n return tools.map(t => ({\n type: 'function',\n function: { name: t.name, description: t.description, parameters: t.inputSchema },\n }));\n}\n\n/** Accept both raw keys and user-pasted `Bearer xxx` values (local servers). */\nfunction bearer(key: string): string {\n return key.startsWith('Bearer ') ? key : `Bearer ${key}`;\n}\n\n/** Map the server's `finish_reason` onto aparté's closed union. */\nfunction toFinishReason(raw: string): AparteFinishReason {\n switch (raw) {\n case 'stop': return 'stop';\n case 'length': return 'length';\n case 'tool_calls':\n case 'function_call': return 'tool-calls';\n case 'content_filter': return 'content-filter';\n default: return 'other';\n }\n}\n\n/** The message of a `{ \"error\": … }` payload: `error.message`, or the error itself when it is a string. */\nfunction errorPayloadMessage(error: unknown): string {\n if (typeof error === 'string' && error) return error;\n const message = (error as { message?: unknown } | null)?.message;\n return typeof message === 'string' && message ? message : 'The server reported an error';\n}\n\n/**\n * What servers write when the prompt is longer than the model's window: OpenAI's\n * \"maximum context length\", the generic \"context length\", LM Studio's \"Context size has\n * been exceeded\", llama.cpp's `exceed_context_size_error` (\"the request exceeds the\n * available context size\"), Anthropic-compatible gateways' \"prompt is too long\". Matched\n * against the message, the type and the code of the payload, because each server puts the\n * telltale in a different one.\n */\nconst CONTEXT_OVERFLOW = /maximum context length|context length|context size has been exceeded|exceed_context_size_error|exceeds the available context size|prompt is too long/i;\n\n/** Is this `{ \"error\": … }` payload a prompt that did not fit? OpenAI's own `context_length_exceeded` code says so outright. */\nfunction isContextOverflow(error: unknown): boolean {\n if (typeof error === 'string') return CONTEXT_OVERFLOW.test(error);\n const fields = error as { message?: unknown; type?: unknown; code?: unknown } | null;\n const strings = [fields?.message, fields?.type, fields?.code].filter((v): v is string => typeof v === 'string');\n return strings.some((v) => v === 'context_length_exceeded' || CONTEXT_OVERFLOW.test(v));\n}\n\n/**\n * The error event for a payload the server streamed after its 200. An overflow carries\n * its code, so the client can compact and resend instead of showing the prose.\n */\nfunction errorEvent(error: unknown): AparteStreamEvent {\n const message = errorPayloadMessage(error);\n return isContextOverflow(error)\n ? { type: 'error', message, code: AparteErrorCode.USAGE_CONTEXT_EXCEEDED }\n : { type: 'error', message };\n}\n\n// ─── Context window ──────────────────────────────────────────────────────────\n\n/**\n * The fields a `GET /models` entry may carry its window in, by vendor: OpenRouter and\n * Together (`context_length`), vLLM (`max_model_len`), Groq (`context_window`), Mistral\n * and LM Studio (`max_context_length`). Read in this order; the first positive integer wins.\n */\nconst WINDOW_FIELDS = ['context_length', 'max_model_len', 'context_window', 'max_context_length'] as const;\n\nfunction positiveInt(v: unknown): number | undefined {\n return typeof v === 'number' && Number.isInteger(v) && v > 0 ? v : undefined;\n}\n\nfunction genericWindow(entry: Record<string, unknown>): number | undefined {\n for (const field of WINDOW_FIELDS) {\n const n = positiveInt(entry[field]);\n if (n !== undefined) return n;\n }\n return undefined;\n}\n\ntype WindowOf = (modelId: string) => number | undefined;\n\ntype Json = Record<string, unknown>;\n\n/** A server's JSON is whatever it sent: narrow to an object, or to nothing. */\nfunction asJson(v: unknown): Json {\n return v !== null && typeof v === 'object' ? v as Json : {};\n}\n\nfunction asJsonList(v: unknown): Json[] {\n return Array.isArray(v) ? v.map(asJson) : [];\n}\n\nasync function getJSON(url: string, headers: Record<string, string>): Promise<Json> {\n const response = await fetch(url, { headers });\n if (!response.ok) throw new Error(`HTTP ${response.status}`);\n return asJson(await response.json());\n}\n\n/**\n * Ask a local server for the window it serves, through its own API. Returns a lookup by\n * model id. Throws on a failed probe; the caller turns that into \"no window\".\n *\n * What each one reads, and what it deliberately does NOT:\n * - LM Studio: a LOADED model's `loaded_instances[].config.context_length`. An unloaded\n * model has only `max_context_length`, the trained maximum, which is not what a JIT\n * load will run with — reading it would draw a gauge against a ceiling the server\n * never enforces, so an unloaded model is left without a window.\n * - Ollama: `/api/ps`, a loaded runner's `context_length`. Ollama also truncates the\n * prompt silently, and `/api/show` only has `num_ctx` when a Modelfile bakes one in,\n * so the trained maximum there is never used either.\n * - llama.cpp: `default_generation_settings.n_ctx` of `/props`, the per-slot window,\n * one value for the one model the process serves.\n */\nasync function probeWindows(\n server: NonNullable<OpenAICompatProviderOptions['server']>,\n origin: string,\n headers: Record<string, string>,\n): Promise<WindowOf | undefined> {\n if (server === 'lmstudio') {\n const byId = new Map<string, number>();\n let data: Json | undefined;\n try {\n data = await getJSON(`${origin}/api/v1/models`, headers);\n } catch {\n // Before the v1 REST API (and still beside it), `/api/v0/models` lists each\n // model with the window it was loaded at: `loaded_context_length` on a\n // `state: \"loaded\"` entry, read live on LM Studio 0.4.26.\n const legacy = await getJSON(`${origin}/api/v0/models`, headers);\n for (const m of asJsonList(legacy['data'])) {\n const n = positiveInt(m['loaded_context_length']);\n if (typeof m['id'] === 'string' && n !== undefined) byId.set(m['id'], n);\n }\n return id => byId.get(id);\n }\n for (const m of asJsonList(data['models'])) {\n const instances = asJsonList(m['loaded_instances']);\n // A model loaded under an identifier of its own (`lms load … --identifier`) is\n // listed by `/v1/models` under that identifier, which is the instance's id —\n // so each instance answers for its own id, and the model's key for its first.\n for (const instance of instances) {\n const n = positiveInt(asJson(instance['config'])['context_length']);\n if (typeof instance['id'] === 'string' && n !== undefined) byId.set(instance['id'], n);\n }\n const first = positiveInt(asJson(instances[0]?.['config'])['context_length']);\n if (typeof m['key'] === 'string' && first !== undefined && !byId.has(m['key'])) byId.set(m['key'], first);\n }\n return id => byId.get(id);\n }\n if (server === 'ollama') {\n const data = await getJSON(`${origin}/api/ps`, headers);\n const byName = new Map<string, number>();\n for (const m of asJsonList(data['models'])) {\n const n = positiveInt(m['context_length']);\n if (n === undefined) continue;\n for (const name of [m['name'], m['model']]) if (typeof name === 'string') byName.set(name, n);\n }\n // `/v1/models` lists `llama3.2:latest`; a bare `llama3.2` is the same model.\n return id => byName.get(id) ?? byName.get(id.endsWith(':latest') ? id.slice(0, -7) : `${id}:latest`);\n }\n if (server === 'llamacpp') {\n const data = await getJSON(`${origin}/props`, headers);\n const n = positiveInt(asJson(data['default_generation_settings'])['n_ctx']);\n return n === undefined ? undefined : () => n;\n }\n return undefined;\n}\n\nconst DEFAULT_CONFIG_SCHEMA = (opts: OpenAICompatProviderOptions): AparteAIProviderConfigSchema => ({\n fields: opts.isLocal\n ? [\n { id: 'endpoint', type: 'url', label: 'Server', defaultValue: opts.baseURL, required: true },\n { id: 'apiKey', type: 'password', label: 'API Key / Token (optional)', placeholder: 'Bearer ...', isAdvanced: true },\n ]\n : [\n { id: 'apiKey', type: 'password', label: 'API Key', placeholder: 'sk-...', required: true },\n { id: 'endpoint', type: 'url', label: 'Custom endpoint', placeholder: opts.baseURL, isAdvanced: true },\n ],\n});\n\n// ─── The factory ─────────────────────────────────────────────────────────────\n\n/**\n * What {@link createOpenAICompatProvider} hands back: a provider whose whole\n * format-adapter surface is guaranteed present.\n *\n * `AparteAIProvider` declares that surface optional — correct in general, since a\n * provider may own its I/O through `chat()` instead — and `AparteFormatAdapter` keeps\n * `authHeaders` / `parseText` / `classifyError` optional because some vendors authenticate\n * by query string, never answer non-streaming, or say nothing a client could classify.\n * THIS factory always supplies all of them, so\n * saying so here is the difference between a caller writing\n * `provider.buildRequest(req)` and a caller sprinkling `!` or writing a check that\n * cannot fail. Useful to annotate with when you drive the adapter yourself (your own\n * `fetch`, your own `AbortSignal`) from a server or an Electron main process.\n */\nexport type OpenAICompatProvider =\n AparteAIProvider\n & AparteFormatAdapter\n & Required<Pick<AparteFormatAdapter, 'authHeaders' | 'parseText' | 'classifyError'>>;\n\n/**\n * Build an `AparteAIProvider` (full format-adapter surface) for one\n * OpenAI-compatible endpoint. Register it like any provider:\n *\n * ```ts\n * import { createOpenAICompatProvider, presets } from '@aparte/provider-openai-compat';\n * aparteGlobalConfig.registerAIProvider(createOpenAICompatProvider(presets.OPENROUTER));\n * // or any compat endpoint, no preset needed:\n * aparteGlobalConfig.registerAIProvider(createOpenAICompatProvider({ id: 'groq', baseURL: 'https://api.groq.com/openai/v1' }));\n * ```\n *\n * Returns {@link OpenAICompatProvider}: the full format-adapter surface, non-optional.\n */\nexport function createOpenAICompatProvider(opts: OpenAICompatProviderOptions): OpenAICompatProvider {\n const displayName = opts.name ?? opts.id;\n\n return {\n id: opts.id,\n\n getMetadata() {\n return {\n id: opts.id,\n name: displayName,\n icon: opts.icon,\n color: opts.color,\n description: opts.description,\n helpUrl: opts.helpUrl,\n hasFreeModels: opts.hasFreeModels,\n isLocal: opts.isLocal,\n configSchema: opts.configSchema ?? DEFAULT_CONFIG_SCHEMA(opts),\n };\n },\n\n getModels(): AparteAIModel[] {\n return opts.models ?? [];\n },\n\n /**\n * Generic `GET {baseURL}/models` — part of the compat standard. Cloud\n * endpoints need a key (returns `[]` without one); local servers fetch\n * keyless. Vendor-specific niceties (pricing, name prettifying) are\n * consumer concerns: pass `models` yourself for anything fancier.\n */\n async fetchModels(config?: string | Record<string, string>): Promise<AparteAIModel[]> {\n const apiKey = typeof config === 'string' ? config : config?.['apiKey'];\n const endpoint = (typeof config === 'object' ? config?.['endpoint'] : null) || opts.baseURL;\n if (!apiKey && !opts.isLocal) return [];\n\n try {\n const headers: Record<string, string> = { ...opts.extraHeaders };\n if (apiKey) headers['Authorization'] = bearer(apiKey);\n const response = await fetch(`${endpoint}/models`, { headers });\n if (!response.ok) throw new Error(`HTTP ${response.status}`);\n const data = await response.json() as { data?: Array<Record<string, unknown> & { id: string; name?: string }> };\n\n // The server's own view of the window, when this endpoint says which\n // server it is. Quiet on failure: the list is still good without it.\n let probed: WindowOf | undefined;\n if (opts.server) {\n try {\n probed = await probeWindows(opts.server, new URL(endpoint).origin, headers);\n } catch (error) {\n console.warn(`[${displayName}] Could not read the context window from the ${opts.server} server:`, error);\n }\n }\n // A window the consumer declared on a static model beats anything read.\n const declared = new Map((opts.models ?? []).flatMap(m => (m.contextWindow ? [[m.id, m.contextWindow] as const] : [])));\n\n return (data.data ?? []).map(m => {\n const contextWindow = declared.get(m.id) ?? probed?.(m.id) ?? genericWindow(m);\n return {\n id: m.id,\n name: m.name || m.id,\n ...(contextWindow !== undefined ? { contextWindow } : {}),\n // `function_calling` is declared because it is a property of the\n // WIRE FORMAT, which is what this provider is: `/chat/completions`\n // takes a `tools` array, and every server behind a compat endpoint\n // accepts one. `/models` returns `{id, object, owned_by}` and says\n // nothing about tools, so waiting for it to declare the capability\n // means never declaring it — and core gates tools on exactly this\n // field, so a registered tool, an approval gate and the whole\n // elicitation path were dead on this provider: the model was asked\n // to use a tool it had never been sent.\n //\n // The failure mode of over-declaring is mild and visible: a model\n // that cannot call tools simply does not call one. The failure mode\n // of under-declaring was silent and total. A server that rejects a\n // `tools` array outright surfaces as an error from its own endpoint,\n // which is the right place for that argument to happen.\n capabilities: ['streaming', 'function_calling'],\n };\n });\n } catch (error) {\n console.error(`[${displayName}] Failed to fetch models:`, error);\n return [];\n }\n },\n\n // ── Format-adapter surface (transport ⊥ format) ──────────────────────\n // The vendor concern only: request shape + stream parsing. Auth and\n // network are the transport's job (AparteDirectTransport / AparteBackendTransport).\n defaultEndpoint: opts.baseURL,\n\n buildRequest(request: AparteChatRequest) {\n const body: Record<string, unknown> = {\n ...Object.fromEntries(Object.entries(opts.extraBody ?? {}).filter(([key]) => !ADAPTER_FIELDS.has(key))),\n model: request.modelId,\n messages: toOpenAIMessages(request.messages),\n temperature: request.temperature,\n max_tokens: request.maxTokens,\n stream: request.stream ?? true,\n ...((request.stream ?? true) ? { stream_options: { include_usage: true } } : {}),\n ...(request.seed !== undefined ? { seed: request.seed } : {}),\n };\n if (request.tools?.length) {\n body['tools'] = toOpenAITools(request.tools);\n /*\n * A forced tool travels; `'auto'` is only the DEFAULT. It used to be\n * written unconditionally, so `toolChoice: { name }` — a shape the loop\n * passes straight through, since it intercepts only `{ name, input }`\n * (the synthetic call it runs itself) — was silently downgraded to\n * \"the model decides\", while the ai-sdk bridge honoured the same field.\n * `'none'` never reaches here: core strips the tools upstream.\n */\n const forced = typeof request.toolChoice === 'object' ? request.toolChoice.name : undefined;\n body['tool_choice'] = forced ? { type: 'function', function: { name: forced } } : 'auto';\n }\n return {\n path: '/chat/completions',\n body,\n ...(opts.extraHeaders ? { headers: opts.extraHeaders } : {}),\n };\n },\n\n authHeaders(key: string) {\n return { Authorization: bearer(key) };\n },\n\n parseStream(body: ReadableStream<Uint8Array>) {\n return parseOpenAICompatStream(body);\n },\n\n /**\n * A 400 (or a 413) whose body says the prompt did not fit is an overflow, not a bad\n * request: the client compacts and sends the turn again. Other statuses keep what\n * the status says.\n */\n classifyError(status: number, body: unknown): AparteErrorCode | undefined {\n if (status !== 400 && status !== 413) return undefined;\n return isContextOverflow((body as { error?: unknown } | null | undefined)?.error)\n ? AparteErrorCode.USAGE_CONTEXT_EXCEEDED\n : undefined;\n },\n\n parseText(json: unknown): string {\n // A 200 that carries `error` and no `choices` is a failure, not an empty\n // reply: LM Studio answers a context overflow this way. The direct\n // transport propagates the throw as the turn's error.\n const payload = json as { error?: unknown; choices?: unknown } | null;\n if (payload?.error && !payload.choices) {\n const failure = new Error(errorPayloadMessage(payload.error));\n throw isContextOverflow(payload.error)\n ? Object.assign(failure, { code: AparteErrorCode.USAGE_CONTEXT_EXCEEDED })\n : failure;\n }\n return (json as { choices?: Array<{ message?: { content?: string } }> })?.choices?.[0]?.message?.content || '';\n },\n };\n}\n\n// ─── SSE stream parser (ported from @aparte/core parseOpenAIStream) ──────────\n\n/**\n * OpenAI-compatible SSE stream parser — this package's own copy of core's\n * `parseOpenAIStream` (the parser follows the format adapter; core keeps only\n * the aparté-native NDJSON parser).\n *\n * Handles:\n * - `delta.content` → text event\n * - `delta.reasoning_content` → thinking event (Qwen3, DeepSeek R1, …)\n * - `delta.tool_calls` → accumulate → tool_use on finish_reason='tool_calls'\n * - `finish_reason` → `finishReason` on the `done`\n * - `{ error }` data line → error event, and the stream ends there (no `done`)\n * - usage-only chunk + [DONE] → done{usage}\n */\nexport function parseOpenAICompatStream(\n stream: ReadableStream<Uint8Array>,\n): ReadableStream<AparteStreamEvent> {\n const decoder = new TextDecoder();\n let buffer = '';\n\n /*\n * Tool call accumulation state, in wire order, keyed by `toolCallKey` below.\n * A Map, not an object: the key comes off the wire, and on a plain `{}` a chunk\n * whose `index` is `\"__proto__\"` writes into Object.prototype for the whole page.\n */\n const toolCalls = new Map<string, { id: string; name: string; args: string }>();\n /** The call the last delta touched — what a bare argument fragment continues. */\n let lastToolKey: string | null = null;\n /**\n * Every key a delta has addressed a call by → that call's slot in `toolCalls`.\n * One call can be addressed both ways in one turn (by `index` in a chunk, by `id`\n * in the next), so the identity is the alias, not the key of the moment.\n */\n const toolCallAliases = new Map<string, string>();\n /** Ids minted for a vendor that sends none. Per stream, i.e. per turn. */\n let mintedCallIds = 0;\n let capturedUsage: AparteUsage | undefined;\n /** The last non-null `finish_reason` seen, mapped; every `done` carries it. */\n let finishReason: AparteFinishReason | undefined;\n let reader: ReadableStreamDefaultReader<Uint8Array> | null = null;\n\n /*\n * Emit the accumulated calls and clear the map.\n *\n * Called at EVERY graceful end of a turn, not only on `finish_reason: 'tool_calls'`:\n * the accumulation spans the whole stream, and a vendor that ends with `stop`,\n * `length` or a bare `[DONE]` after streaming tool-call deltas used to drop them —\n * the model had asked for a tool and the loop never heard. `complete` says the\n * model declared the calls finished: a parse failure there is malformed JSON (a\n * real small-model failure) and the tool still runs, on `{}`. Elsewhere it is\n * truncation, and running a tool on `{}` for a call the model never finished would\n * be worse than dropping it — so those are dropped, with a breadcrumb.\n */\n const flushToolCalls = (controller: ReadableStreamDefaultController<AparteStreamEvent>, complete: boolean): void => {\n for (const entry of toolCalls.values()) {\n let input: Record<string, unknown> = {};\n try {\n input = entry.args.trim() ? JSON.parse(entry.args) : {};\n } catch {\n if (!complete) {\n console.warn(`[openai-compat] Tool \"${entry.name}\" was cut mid-arguments (the turn ended without finish_reason 'tool_calls'); the call is dropped. Raw:`, entry.args);\n continue;\n }\n console.warn(\n `[openai-compat] Tool \"${entry.name}\" returned malformed arguments JSON; ` +\n `passing empty input. Raw:`, entry.args,\n );\n }\n const toolCall: AparteToolCall = { id: entry.id, name: entry.name, input };\n controller.enqueue({ type: 'tool_use', ...toolCall });\n }\n toolCalls.clear();\n toolCallAliases.clear();\n lastToolKey = null;\n };\n\n /*\n * Which accumulated call a `delta.tool_calls` entry belongs to.\n *\n * Both `index` and `id` address a call, and a vendor may use one in a chunk and\n * the other in the next — so neither can BE the identity: a delta's keys are\n * ALIASES that all resolve to the same slot. A key already resolved names the\n * call, and every key a delta carries is recorded against the slot it lands on.\n * Picking one key instead (`index` first, `id` next) split such a call in two,\n * the second half nameless, and the turn ran the tool on `{}`.\n *\n * When no key of the delta is known yet, the function NAME decides — it appears\n * only on a call's FIRST delta, so a nameless delta continues the call before it\n * and a named one opens its own. That single rule covers the vendor whose deltas\n * never carry both addresses at once (open by `id`, continue by `index`, or the\n * reverse) and the vendor that carries neither: `index` is a streaming\n * convenience, not part of the function-call payload, and keying on it alone\n * (`Number(tc.index ?? 0)`) put every call of a server that omits it on slot 0.\n *\n * `null` means \"skip this entry\": an `index` the vendor sent that is not a\n * non-negative integer is not a slot number, it is malformed (or hostile —\n * `\"__proto__\"` was the shape that made this a Map).\n */\n const toolCallKey = (tc: { index?: unknown; id?: string; function?: { name?: string } }): string | null => {\n let indexKey: string | undefined;\n if (tc.index !== undefined && tc.index !== null) {\n // Made a number, not annotated as one: `index` is whatever the vendor's JSON put there.\n const idx = Number(tc.index);\n if (!Number.isInteger(idx) || idx < 0) return null;\n indexKey = `i${idx}`;\n }\n const idKey = tc.id ? `d${tc.id}` : undefined;\n const known = (idKey ? toolCallAliases.get(idKey) : undefined) ?? (indexKey ? toolCallAliases.get(indexKey) : undefined);\n // No key of this delta is known yet. A nameless delta never OPENS a call, so it\n // continues the call before it — which is what keeps ONE call together when the\n // vendor opens it with one address and continues it with the other, neither\n // delta carrying both. A named delta still opens its own slot.\n const key = known ?? ((!tc.function?.name && lastToolKey !== null) ? lastToolKey : (idKey ?? indexKey));\n if (key === undefined) return `p${toolCalls.size}`;\n if (idKey) toolCallAliases.set(idKey, key);\n if (indexKey) toolCallAliases.set(indexKey, key);\n return key;\n };\n\n return new ReadableStream<AparteStreamEvent>({\n async start(controller) {\n reader = stream.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed.startsWith('data:')) continue;\n const raw = trimmed.slice(5).trim();\n if (raw === '[DONE]') {\n // A turn that streamed tool-call deltas and ended on `stop`,\n // `length` or a bare [DONE]: the calls are still the model's.\n flushToolCalls(controller, false);\n controller.enqueue({ type: 'done', usage: capturedUsage, ...(finishReason ? { finishReason } : {}) });\n return;\n }\n try {\n const json = JSON.parse(raw);\n\n // Capture usage from the usage-only chunk (choices: [])\n if (json.usage) {\n capturedUsage = {\n inputTokens: json.usage.prompt_tokens ?? 0,\n outputTokens: json.usage.completion_tokens ?? 0,\n totalTokens: json.usage.total_tokens,\n cacheReadTokens: json.usage.prompt_tokens_details?.cached_tokens,\n };\n }\n\n // An error the server streamed AFTER a 200 (LM Studio on a context\n // overflow, OpenAI and vLLM mid-stream). Without this the line was\n // skipped as \"no choices\" and the turn ended on an empty `done`:\n // an empty reply marked completed. An `event: error` line before it\n // is ignored like every non-`data:` line; this data line is the payload.\n if (json.error) {\n controller.enqueue(errorEvent(json.error));\n reader?.cancel().catch(() => undefined);\n return;\n }\n\n const choice = json.choices?.[0];\n if (!choice) continue;\n if (typeof choice.finish_reason === 'string' && choice.finish_reason) {\n finishReason = toFinishReason(choice.finish_reason);\n }\n\n const delta = choice.delta;\n if (delta) {\n if (delta.reasoning_content) {\n controller.enqueue({ type: 'thinking', delta: delta.reasoning_content });\n }\n if (delta.content) {\n controller.enqueue({ type: 'text', delta: delta.content });\n }\n if (delta.tool_calls) {\n for (const tc of delta.tool_calls) {\n const key = toolCallKey(tc);\n if (key === null) continue;\n let entry = toolCalls.get(key);\n if (!entry) {\n /*\n * An id is MINTED when the vendor sends none. `id: ''`\n * used to travel: the transcript keys a row on\n * `tool-${id}` and the history a result on\n * `toolCallId`, so two id-less calls in one turn shared\n * one row (the second call's result landed on the first\n * call's line) and one history slot an OpenAI-shaped\n * endpoint rejects on the next turn. A real id arriving\n * in a later chunk still wins, below. The mint is\n * namespaced because `call_1` is what an OpenAI-shaped\n * server calls its own first call: a turn mixing an\n * id-less call with a real `call_1` minted a duplicate.\n */\n entry = { id: tc.id ?? `aparte-call-${++mintedCallIds}`, name: tc.function?.name ?? '', args: '' };\n toolCalls.set(key, entry);\n }\n lastToolKey = key;\n if (tc.id) entry.id = tc.id;\n if (tc.function?.name) entry.name = tc.function.name;\n if (tc.function?.arguments) entry.args += tc.function.arguments;\n }\n }\n }\n\n // The model declared the calls complete: emit them now (and clear\n // the map, so a server that repeats the finish chunk cannot\n // re-emit them). Do NOT emit `done` or return here: under\n // `include_usage` (which buildRequest requests) the usage-only\n // chunk arrives AFTER this finish chunk, so stopping now dropped\n // usage on every tool-call turn — i.e. most turns of an agent.\n // Keep reading; the single `done` comes from `[DONE]` below, or\n // from the end-of-stream fallback if the socket just closes.\n if (choice.finish_reason === 'tool_calls') flushToolCalls(controller, true);\n } catch {\n // Every line here is a complete, newline-terminated SSE\n // line (see buffer split above), so a parse failure is an\n // unexpected/malformed server payload, not partial JSON —\n // log a breadcrumb instead of dropping it silently.\n console.warn('[openai-compat] Skipped an unparseable SSE data line:', raw);\n }\n }\n }\n // The socket closed without [DONE]: same rule, the calls are flushed first.\n flushToolCalls(controller, false);\n controller.enqueue({ type: 'done', usage: capturedUsage, ...(finishReason ? { finishReason } : {}) });\n } catch (err: unknown) {\n // AbortError surfaces here when the caller's signal fires mid-stream:\n // the consumer (agent loop) cancelled on purpose — end quietly, the\n // same way the ai-sdk provider does. Reporting it as an `error` event\n // makes a deliberate Stop indistinguishable from a network failure,\n // and the loop's error branch then replaces the streamed answer with\n // an error bubble.\n if ((err as { name?: string } | undefined)?.name !== 'AbortError') {\n controller.enqueue({ type: 'error', message: (err as Error | undefined)?.message ?? 'Stream error' });\n }\n } finally {\n reader?.releaseLock();\n reader = null;\n controller.close();\n }\n },\n // Consumer cancelled (e.g. user hit \"stop\"): cancel the underlying reader so\n // the vendor response body stops being drained to its natural end instead of\n // silently finishing the whole SSE stream in the background.\n cancel(reason) {\n const r = reader;\n reader = null;\n return r?.cancel(reason);\n },\n });\n}\n\nexport * from './presets.js';\nexport type { AparteAIProvider, AparteAIModel } from '@aparte/core';\n"],"names":[],"mappings":";AAiBA,MAAM,SAAsC;AAAA,EACxC,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS;AACb;AAEA,MAAM,UAAuC;AAAA,EACzC,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS;AACb;AAEA,MAAM,MAAmC;AAAA,EACrC,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,eAAe;AAAA,EACf,SAAS;AACb;AAEA,MAAM,aAA0C;AAAA,EAC5C,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,eAAe;AAAA,EACf,SAAS;AAAA;AAAA,EAET,cAAc;AAAA,IACV,gBAAgB,OAAO,WAAW,cAAc,OAAO,SAAS,SAAS;AAAA,IACzE,WAAW;AAAA,EAAA;AAEnB;AAEA,MAAM,WAAwC;AAAA,EAC1C,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,eAAe;AAAA,EACf,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AACb;AAMA,MAAM,SAAsC;AAAA,EACxC,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,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23
23
  readonly OLLAMA: OpenAICompatProviderOptions;
24
+ readonly LLAMACPP: OpenAICompatProviderOptions;
25
+ readonly VLLM: OpenAICompatProviderOptions;
24
26
  };
25
27
  //# sourceMappingURL=presets.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AA6E9D,wEAAwE;AACxE,eAAO,MAAM,OAAO;;;;;;;CAAkE,CAAC"}
1
+ {"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AA2G9D,wEAAwE;AACxE,eAAO,MAAM,OAAO;;;;;;;;;CAAkF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aparte/provider-openai-compat",
3
- "version": "0.24.0",
3
+ "version": "0.26.0",
4
4
  "homepage": "https://apartejs.dev/providers/ai/openai-compat/",
5
5
  "description": "One OpenAI-compatible chat-completions adapter for any /v1 endpoint — OpenAI, Mistral, OpenRouter, Z.ai, Groq, LM Studio, Ollama and friends, via presets or plain config.",
6
6
  "type": "module",
@@ -25,13 +25,13 @@
25
25
  "node": ">=18"
26
26
  },
27
27
  "peerDependencies": {
28
- "@aparte/core": ">=0.24.0 <1.0.0"
28
+ "@aparte/core": ">=0.26.0 <1.0.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^22.0.0",
32
32
  "typescript": "^5.4.0",
33
33
  "vite": "^6.0.0",
34
- "@aparte/core": "0.24.0"
34
+ "@aparte/core": "0.26.0"
35
35
  },
36
36
  "keywords": [
37
37
  "ai",