@orkestrel/ollama 0.0.14 → 0.0.16

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.
@@ -1,629 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- let _orkestrel_contract = require("@orkestrel/contract");
3
- let _orkestrel_agent = require("@orkestrel/agent");
4
- let _orkestrel_ndjson = require("@orkestrel/ndjson");
5
- let _orkestrel_timeout = require("@orkestrel/timeout");
6
- //#region src/server/constants.ts
7
- /** Names the local Ollama daemon base URL assumed when `OllamaOptions.url` is omitted. */
8
- var DEFAULT_OLLAMA_URL = "http://localhost:11434";
9
- /**
10
- * Names how long the model stays resident after a call when `OllamaOptions.keepAlive` is
11
- * omitted — Ollama's own `keep_alive` default, expressed as a duration string.
12
- *
13
- * @remarks
14
- * The name mirrors the Ollama `/api/chat` `keep_alive` field this value is sent as, so
15
- * the constant, the `OllamaOptions.keepAlive` key, and the wire member read as one term.
16
- */
17
- var DEFAULT_KEEP_ALIVE = "5m";
18
- /**
19
- * Names the per-call deadline in milliseconds when `OllamaOptions.timeout` is omitted —
20
- * generous enough that a cold model load does not trip it.
21
- */
22
- var DEFAULT_PROVIDER_TIMEOUT = 12e4;
23
- /**
24
- * Names the cap, in characters, on how much of a non-OK response body is
25
- * incorporated into a thrown {@link OllamaHTTPError}'s message.
26
- *
27
- * @remarks
28
- * Bounds the excerpt so a defensive proxy or a misbehaving daemon handing
29
- * back an unbounded response body cannot inflate the thrown error's message
30
- * without limit. `2048` characters is generous enough to carry a
31
- * useful diagnostic snippet while staying well short of any practical size
32
- * concern.
33
- */
34
- var MAX_ERROR_BODY_LENGTH = 2048;
35
- //#endregion
36
- //#region src/server/errors.ts
37
- /**
38
- * Represents an error thrown when the Ollama `/api/chat` HTTP transport fails.
39
- *
40
- * @remarks
41
- * Carries the machine-readable `code` `'HTTP'` and the response `status` (0 when no
42
- * HTTP response was received at all, for example a `null` body). Thrown by
43
- * {@link OllamaProvider} at its HTTP failure sites — the non-OK status branch and the
44
- * null-body branch — so a caller can branch on `error.code` and read `error.status`
45
- * for the HTTP number instead of parsing the message. Narrow a caught value with
46
- * {@link isOllamaHTTPError}.
47
- *
48
- * @example
49
- * ```ts
50
- * try {
51
- * await provider.generate(messages, signal)
52
- * } catch (error) {
53
- * if (isOllamaHTTPError(error) && error.status === 404) {
54
- * // the configured model isn't pulled
55
- * }
56
- * }
57
- * ```
58
- */
59
- var OllamaHTTPError = class extends Error {
60
- /**
61
- * Names the machine-readable condition this error reports — `'HTTP'`: an `/api/chat`
62
- * transport, status, or body failure.
63
- */
64
- code = "HTTP";
65
- status;
66
- constructor(message, status, options) {
67
- super(message, options);
68
- this.name = "OllamaHTTPError";
69
- this.status = status;
70
- }
71
- };
72
- /**
73
- * Checks whether a value is an {@link OllamaHTTPError}.
74
- *
75
- * @param value - The value to test
76
- * @returns True if `value` is an `OllamaHTTPError`; false otherwise
77
- */
78
- function isOllamaHTTPError(value) {
79
- return value instanceof OllamaHTTPError;
80
- }
81
- //#endregion
82
- //#region src/server/helpers.ts
83
- /**
84
- * Maps conversation turns onto the `/api/chat` wire's minimal message shape.
85
- *
86
- * @remarks
87
- * `tool_calls` is emitted only on a turn that replays them and `images` only on a
88
- * multimodal turn, so an empty optional never reaches the wire.
89
- *
90
- * @param messages - The conversation turns to send
91
- * @returns The wire `messages` array, one entry per turn, in order
92
- *
93
- * @example
94
- * ```ts
95
- * mapMessages([{ id: '1', role: 'user', content: 'Say hello.' }])
96
- * // [{ role: 'user', content: 'Say hello.' }]
97
- * ```
98
- */
99
- function mapMessages(messages) {
100
- return messages.map((message) => ({
101
- role: message.role,
102
- content: message.content,
103
- ...message.calls !== void 0 && message.calls.length > 0 ? { tool_calls: message.calls.map((call) => ({ function: {
104
- name: call.name,
105
- arguments: call.arguments
106
- } })) } : {},
107
- ...message.images !== void 0 && message.images.length > 0 ? { images: [...message.images] } : {}
108
- }));
109
- }
110
- /**
111
- * Builds a provider result from a turn's content, reasoning, tool calls, and usage.
112
- *
113
- * @remarks
114
- * Only the present optionals are set: no empty `thinking`, no empty `tools`, and no
115
- * `usage` unless the wire reported one.
116
- *
117
- * @param content - The clean assistant content the splitter accumulated
118
- * @param thinking - The joined reasoning, empty when the turn produced none
119
- * @param tools - The tool calls collected across the turn
120
- * @param usage - The token usage, or `undefined` when the wire reported none
121
- * @returns The result carrying only its populated fields
122
- *
123
- * @example
124
- * ```ts
125
- * buildResult('ok', '', [], undefined) // { content: 'ok' }
126
- * ```
127
- */
128
- function buildResult(content, thinking, tools, usage) {
129
- const result = { content };
130
- if (thinking.length > 0) result.thinking = thinking;
131
- if (tools.length > 0) result.tools = tools;
132
- if (usage !== void 0) result.usage = usage;
133
- return result;
134
- }
135
- /**
136
- * Extracts the assistant text of one wire record.
137
- *
138
- * @param record - One parsed `/api/chat` record — a non-stream body or an NDJSON line
139
- * @returns The record's `message.content` when it is a string, else `''`
140
- *
141
- * @example
142
- * ```ts
143
- * extractContent({ message: { content: 'ok' } }) // 'ok'
144
- * ```
145
- */
146
- function extractContent(record) {
147
- const message = Reflect.get(record, "message");
148
- if (!(0, _orkestrel_contract.isRecord)(message)) return "";
149
- const content = Reflect.get(message, "content");
150
- return (0, _orkestrel_contract.isString)(content) ? content : "";
151
- }
152
- /**
153
- * Extracts the daemon-side reasoning of one wire record.
154
- *
155
- * @remarks
156
- * `message.thinking` is the `think: true` wire shape. It is read whatever the configured
157
- * flag says, because a daemon may separate reasoning on its own.
158
- *
159
- * @param record - One parsed `/api/chat` record — a non-stream body or an NDJSON line
160
- * @returns The record's `message.thinking` when it is a string, else `''`
161
- *
162
- * @example
163
- * ```ts
164
- * extractThinking({ message: { thinking: 'weighing it' } }) // 'weighing it'
165
- * ```
166
- */
167
- function extractThinking(record) {
168
- const message = Reflect.get(record, "message");
169
- if (!(0, _orkestrel_contract.isRecord)(message)) return "";
170
- const thinking = Reflect.get(message, "thinking");
171
- return (0, _orkestrel_contract.isString)(thinking) ? thinking : "";
172
- }
173
- /**
174
- * Joins a call's two reasoning carriers into the result's `thinking`.
175
- *
176
- * @param splitter - The per-call splitter holding the separated in-content spans
177
- * @param wired - The accumulated wire-side `message.thinking` text
178
- * @returns The two carriers separated by a blank line, or whichever one is non-empty
179
- *
180
- * @example
181
- * ```ts
182
- * joinThinking(createThinkSplitter(), 'from the wire') // 'from the wire'
183
- * ```
184
- */
185
- function joinThinking(splitter, wired) {
186
- if (splitter.thinking.length === 0) return wired;
187
- if (wired.length === 0) return splitter.thinking;
188
- return `${splitter.thinking}\n\n${wired}`;
189
- }
190
- /**
191
- * Extracts the token usage of one wire record.
192
- *
193
- * @remarks
194
- * Both counts must be numbers, which is true of the non-stream body and the stream's
195
- * `done: true` line. A delta line carries neither, so it yields `undefined`.
196
- *
197
- * @param record - One parsed `/api/chat` record — a non-stream body or an NDJSON line
198
- * @returns The `TokenUsage` shape, or `undefined` when either count is absent
199
- *
200
- * @example
201
- * ```ts
202
- * extractUsage({ prompt_eval_count: 3, eval_count: 4 })
203
- * // { prompt: 3, completion: 4, total: 7 }
204
- * ```
205
- */
206
- function extractUsage(record) {
207
- const prompt = Reflect.get(record, "prompt_eval_count");
208
- const completion = Reflect.get(record, "eval_count");
209
- if (!(0, _orkestrel_contract.isNumber)(prompt) || !(0, _orkestrel_contract.isNumber)(completion)) return void 0;
210
- return {
211
- prompt,
212
- completion,
213
- total: prompt + completion
214
- };
215
- }
216
- /**
217
- * Extracts the tool calls of one wire record's `message.tool_calls`.
218
- *
219
- * @remarks
220
- * Each entry narrows to `{ id, name, arguments }`: the entry and its `function` must be
221
- * records and `name` a string, else the entry is dropped. An id is minted when the wire
222
- * omits one.
223
- *
224
- * @param record - One parsed `/api/chat` record — a non-stream body or an NDJSON line
225
- * @returns The narrowed tool calls, empty when the record carries none
226
- *
227
- * @example
228
- * ```ts
229
- * extractTools({ message: { tool_calls: [{ function: { name: 'weather' } }] } })
230
- * // [{ id: '…', name: 'weather', arguments: {} }]
231
- * ```
232
- */
233
- function extractTools(record) {
234
- const message = Reflect.get(record, "message");
235
- if (!(0, _orkestrel_contract.isRecord)(message)) return [];
236
- const calls = Reflect.get(message, "tool_calls");
237
- if (!Array.isArray(calls)) return [];
238
- const out = [];
239
- for (const entry of calls) {
240
- if (!(0, _orkestrel_contract.isRecord)(entry)) continue;
241
- const callable = Reflect.get(entry, "function");
242
- if (!(0, _orkestrel_contract.isRecord)(callable)) continue;
243
- const name = Reflect.get(callable, "name");
244
- if (!(0, _orkestrel_contract.isString)(name)) continue;
245
- const id = Reflect.get(entry, "id");
246
- out.push({
247
- id: (0, _orkestrel_contract.isString)(id) ? id : crypto.randomUUID(),
248
- name,
249
- arguments: extractArguments(Reflect.get(callable, "arguments"))
250
- });
251
- }
252
- return out;
253
- }
254
- /**
255
- * Extracts a wire `arguments` value as a record.
256
- *
257
- * @remarks
258
- * Total: an object passes through, a JSON string is parsed when it yields a record, and
259
- * a malformed string yields `{}` rather than throwing.
260
- *
261
- * @param value - The wire's `function.arguments` value, of unknown shape
262
- * @returns The argument record, or `{}` when the value carries none
263
- *
264
- * @example
265
- * ```ts
266
- * extractArguments('{"city":"Oslo"}') // { city: 'Oslo' }
267
- * ```
268
- */
269
- function extractArguments(value) {
270
- if ((0, _orkestrel_contract.isRecord)(value)) return value;
271
- if ((0, _orkestrel_contract.isString)(value)) return (0, _orkestrel_contract.parseJSONAs)(value, _orkestrel_contract.isRecord) ?? {};
272
- return {};
273
- }
274
- //#endregion
275
- //#region src/server/parsers.ts
276
- /**
277
- * Parses a non-stream `/api/chat` response body into a wire record.
278
- *
279
- * @remarks
280
- * Total by construction: an empty body, a body that is not JSON, and a body whose JSON is
281
- * not an object all yield `undefined`, so a malformed daemon response never escapes as a
282
- * `SyntaxError`. The call site supplies the empty-record default that reads as empty
283
- * content and no usage.
284
- *
285
- * @param response - The 200-OK `/api/chat` response whose body is read as text
286
- * @returns The parsed record, or `undefined` when the body is empty or malformed
287
- *
288
- * @example
289
- * ```ts
290
- * await parseBody(new Response('{"message":{"content":"ok"}}'))
291
- * // { message: { content: 'ok' } }
292
- * ```
293
- */
294
- async function parseBody(response) {
295
- return (0, _orkestrel_contract.parseJSONAs)(await response.text(), _orkestrel_contract.isRecord);
296
- }
297
- //#endregion
298
- //#region src/server/OllamaProvider.ts
299
- /**
300
- * Implements the local Ollama inference boundary — a {@link ProviderInterface} over Ollama's
301
- * `POST /api/chat`, both non-streaming (`generate`) and streaming NDJSON (`stream`).
302
- *
303
- * @remarks
304
- * - **Wire protocol.** Posts `{ model, messages, stream, keep_alive, think }` plus
305
- * passthrough sampling `options` and mapped function `tools`. The `think` flag is
306
- * CONFIGURABLE through {@link OllamaOptions.think} (default `false`). Non-stream parses
307
- * one JSON body; stream consumes NDJSON (one JSON object per `\n`-terminated line) —
308
- * deltas carry `message.content`, the final `done: true` line carries the token usage.
309
- * - **Think separation.** The wire `think` flag is configurable
310
- * ({@link OllamaOptions.think}, default `false`). With `think: true` a thinking model's
311
- * daemon separates reasoning NATIVELY — returning it on the distinct `message.thinking`
312
- * channel (read here through `extractThinking`) instead of inline in `message.content`. EITHER
313
- * way the per-call {@link ThinkSplitterInterface} is the defensive guarantee: a daemon
314
- * may ignore `think: false` for a thinking model and inline `<think>` tags, so every
315
- * content delta routes through the splitter, only CLEAN content is yielded / assembled,
316
- * and the separated reasoning (plus any daemon-side `message.thinking` deltas) lands on
317
- * `ProviderResult.thinking`, never in the conversation.
318
- * - **Boundary narrowing.** Every wire value arrives as `unknown` and is
319
- * narrowed through guards (`isRecord` / `isString` / `isNumber`) — never `as`. A
320
- * missing / malformed field degrades to a sensible default (empty content, no
321
- * usage, `{}` arguments), never a throw.
322
- * - **Bounded.** Each call arms a {@link Timeout} for `OllamaOptions.timeout` and
323
- * passes `AbortSignal.any([timeout.signal, signal])` to `fetch`, so the caller's
324
- * signal AND the deadline both cancel the request. The timeout is always cleared —
325
- * in `#fetch` if the request fails/aborts, otherwise in the consuming call's `finally`.
326
- * - **Abort recovers partial.** A `stream` cancelled mid-flight throws a
327
- * `ProviderAbortError` carrying the partial result assembled so far; pairing the
328
- * `TextDecoder({ stream: true })` with the {@link NDJSONParser} parser keeps multi-byte
329
- * UTF-8 splits and partial lines honest.
330
- * - **Event-free.** A pure functional boundary — no Emitter, no events.
331
- * - **Transport seam.** {@link OllamaOptions.fetch} swaps the transport (default
332
- * `globalThis.fetch`) and {@link OllamaOptions.headers} is a per-request, possibly
333
- * async header injector merged over the base `Content-Type` — so a browser runtime
334
- * can route through the developer's own server with an obfuscated bearer token,
335
- * without this library ever handling a real API key. Both omitted ⇒ the global `fetch`
336
- * and only a JSON content type.
337
- * Orthogonal to the deadline: the hook is awaited inside `#fetch`'s try, so a hook
338
- * rejection clears the armed timer like any other request failure.
339
- *
340
- * @example
341
- * ```ts
342
- * const provider = new OllamaProvider({ model: 'qwen3.5:2b-q4_K_M' })
343
- * const result = await provider.generate(messages, abort.signal)
344
- * ```
345
- */
346
- var OllamaProvider = class {
347
- name = "ollama";
348
- #id;
349
- #model;
350
- #url;
351
- #keepAlive;
352
- #timeout;
353
- #think;
354
- #options;
355
- #transport;
356
- #headers;
357
- #format;
358
- constructor(options) {
359
- this.#id = crypto.randomUUID();
360
- this.#model = options.model;
361
- this.#url = options.url ?? "http://localhost:11434";
362
- this.#keepAlive = options.keepAlive ?? "5m";
363
- this.#timeout = options.timeout ?? 12e4;
364
- this.#think = options.think ?? false;
365
- this.#options = options.options;
366
- this.#transport = options.fetch ?? globalThis.fetch.bind(globalThis);
367
- this.#headers = options.headers;
368
- this.#format = options.format;
369
- }
370
- /**
371
- * Exposes this instance's identity — a fresh `crypto.randomUUID()` minted at
372
- * construction, satisfying the {@link ProviderInterface.id} contract member. A second
373
- * provider built from identical options carries a distinct id.
374
- *
375
- * @returns The instance's minted identifier
376
- */
377
- get id() {
378
- return this.#id;
379
- }
380
- /**
381
- * Exposes the provider's context-framing default — the PROVIDER-DEFAULT level of
382
- * {@link import('@orkestrel/agent').AgentContextInterface.build}'s format cascade (it BEATS
383
- * the managers' built-in framing, is BEATEN by a manager-options or per-item override).
384
- * Satisfies the OPTIONAL {@link ProviderInterface.format} contract member: `undefined`
385
- * when {@link OllamaOptions.format} was omitted (the framing-agnostic default ⇒ core's
386
- * built-in framing applies unchanged), else the exact configured framing the Agent
387
- * threads into `build()`.
388
- *
389
- * @remarks
390
- * EXPOSE-ONLY — read by the Agent loop and consumed by core's cascade; it is NEVER sent
391
- * on the `/api/chat` wire (it is absent from `#body` / the request). This is NOT Ollama's
392
- * structured-output `format` wire parameter — that one IS sent in `#body`, but only when
393
- * a per-call `ProviderStreamOptions.schema` is supplied; only the word collides.
394
- *
395
- * @returns The configured {@link ContextFormat}, or `undefined` when none
396
- */
397
- get format() {
398
- return this.#format;
399
- }
400
- async generate(messages, signal, tools, options) {
401
- const { response, timeout } = await this.#fetch(messages, false, signal, tools, options);
402
- try {
403
- const record = await parseBody(response) ?? {};
404
- const splitter = (0, _orkestrel_agent.createThinkSplitter)();
405
- splitter.split(extractContent(record));
406
- splitter.flush();
407
- const thinking = joinThinking(splitter, extractThinking(record));
408
- return buildResult(splitter.content, thinking, extractTools(record), extractUsage(record));
409
- } finally {
410
- timeout.clear();
411
- }
412
- }
413
- async *stream(messages, signal, tools, options) {
414
- const { response, timeout, combined } = await this.#fetch(messages, true, signal, tools, options);
415
- const body = response.body;
416
- if (body === null) {
417
- timeout.clear();
418
- throw new OllamaHTTPError("Ollama API error: no response body", 0);
419
- }
420
- const reader = body.getReader();
421
- const decoder = new TextDecoder();
422
- const parser = (0, _orkestrel_ndjson.createNDJSONParser)();
423
- const splitter = (0, _orkestrel_agent.createThinkSplitter)();
424
- let wired = "";
425
- const calls = [];
426
- let usage;
427
- try {
428
- for (;;) {
429
- const { value, done } = await reader.read();
430
- if (done) break;
431
- for (const record of parser.parse(decoder.decode(value, { stream: true }))) {
432
- const increment = yield* this.#deltas(record, splitter, usage);
433
- wired += increment.thinking;
434
- calls.push(...increment.calls);
435
- usage = increment.usage;
436
- }
437
- }
438
- const decoderTail = decoder.decode();
439
- for (const record of parser.parse(decoderTail.length > 0 ? `${decoderTail}\n` : "\n")) {
440
- const increment = yield* this.#deltas(record, splitter, usage);
441
- wired += increment.thinking;
442
- calls.push(...increment.calls);
443
- usage = increment.usage;
444
- }
445
- const tail = splitter.flush();
446
- if (tail.length > 0) yield {
447
- channel: "content",
448
- text: tail
449
- };
450
- } catch (error) {
451
- if (combined.aborted) {
452
- splitter.flush();
453
- throw new _orkestrel_agent.ProviderAbortError(buildResult(splitter.content, joinThinking(splitter, wired), calls, usage));
454
- }
455
- throw error;
456
- } finally {
457
- try {
458
- await reader.cancel();
459
- } catch {}
460
- parser.clear();
461
- timeout.clear();
462
- }
463
- return buildResult(splitter.content, joinThinking(splitter, wired), calls, usage);
464
- }
465
- *#deltas(record, splitter, usage) {
466
- const delta = splitter.split(extractContent(record));
467
- if (delta.length > 0) yield {
468
- channel: "content",
469
- text: delta
470
- };
471
- const thinking = extractThinking(record);
472
- if (thinking.length > 0) yield {
473
- channel: "thinking",
474
- text: thinking
475
- };
476
- return {
477
- thinking,
478
- calls: extractTools(record),
479
- usage: Reflect.get(record, "done") === true ? extractUsage(record) : usage
480
- };
481
- }
482
- async #fetch(messages, stream, signal, tools, options) {
483
- const timeout = new _orkestrel_timeout.Timeout({ ms: this.#timeout });
484
- timeout.start();
485
- const combined = AbortSignal.any([timeout.signal, signal]);
486
- try {
487
- const response = await this.#transport(`${this.#url}/api/chat`, {
488
- method: "POST",
489
- headers: await this.#requestHeaders(),
490
- body: JSON.stringify(this.#body(messages, stream, tools, options)),
491
- signal: combined
492
- });
493
- if (!response.ok) {
494
- let detail;
495
- try {
496
- const text = await response.text();
497
- detail = text.length > 2048 ? text.slice(0, MAX_ERROR_BODY_LENGTH) : text;
498
- } catch (cause) {
499
- throw new OllamaHTTPError(`Ollama API error: ${response.status} - (error body unavailable)`, response.status, { cause });
500
- }
501
- throw new OllamaHTTPError(`Ollama API error: ${response.status} - ${detail}`, response.status);
502
- }
503
- return {
504
- response,
505
- timeout,
506
- combined
507
- };
508
- } catch (error) {
509
- timeout.clear();
510
- throw error;
511
- }
512
- }
513
- async #requestHeaders() {
514
- const headers = { "Content-Type": "application/json" };
515
- if (this.#headers !== void 0) for (const [key, value] of Object.entries(await this.#headers())) headers[key] = value;
516
- return headers;
517
- }
518
- #body(messages, stream, tools, options) {
519
- return {
520
- model: this.#model,
521
- messages: mapMessages(messages),
522
- stream,
523
- keep_alive: this.#keepAlive,
524
- think: options?.think ?? this.#think,
525
- ...this.#options !== void 0 ? { options: this.#options } : {},
526
- ...options?.schema !== void 0 ? { format: options.schema } : {},
527
- ...tools !== void 0 && tools.length > 0 ? { tools: tools.map((tool) => ({
528
- type: "function",
529
- function: {
530
- name: tool.name,
531
- ...tool.description === void 0 ? {} : { description: tool.description },
532
- ...tool.parameters === void 0 ? {} : { parameters: tool.parameters }
533
- }
534
- })) } : {}
535
- };
536
- }
537
- };
538
- //#endregion
539
- //#region src/server/factories.ts
540
- /**
541
- * Creates a local Ollama inference provider — a {@link ProviderInterface} over the
542
- * daemon's `POST /api/chat`, supporting non-streaming `generate` and streaming
543
- * `stream`.
544
- *
545
- * @remarks
546
- * Only `model` is required; `url` defaults to the local daemon, `keepAlive` to `'5m'`,
547
- * `timeout` to `120_000`ms, and `options` is forwarded verbatim as sampling
548
- * parameters (`temperature`, `seed`, and `num_predict`). Both calls take an
549
- * `AbortSignal` to bound the request; a `stream` cancelled mid-flight throws a
550
- * `ProviderAbortError` carrying the partial result.
551
- *
552
- * The optional `fetch` + `headers` form a transport seam (see {@link OllamaOptions}):
553
- * point `url` at your own server, inject a custom `fetch`, and have `headers` attach a
554
- * generated/obfuscated bearer token your server validates — so a browser runtime
555
- * reaches the LLM through your middleware WITHOUT this library ever handling the real API
556
- * key. Both omitted ⇒ the global `fetch` and only a JSON content type.
557
- *
558
- * The optional `format` is the provider's context-framing default — the PROVIDER-DEFAULT
559
- * level of `AgentContext`'s format cascade (beaten by a manager-options or per-item
560
- * override, beating the managers' built-in framing), declaring how this
561
- * provider's models prefer context sections framed (for example XML group wrappers vs. Markdown
562
- * headers). It is EXPOSED on the provider for the Agent's `build()` and is NOT Ollama's
563
- * `/api/chat` `format` wire parameter (structured output) — the two are unrelated despite
564
- * the shared word. Omitted ⇒ the provider is framing-agnostic (core's built-in defaults).
565
- *
566
- * @param options - `model` (required), and optional `url` / `keepAlive` / `timeout` /
567
- * `options` / `fetch` / `headers` / `format` (see {@link OllamaOptions})
568
- * @returns A working {@link ProviderInterface} backed by Ollama
569
- *
570
- * @example
571
- * ```ts
572
- * import { createAbort } from '@orkestrel/abort'
573
- * import { createOllama } from '@orkestrel/ollama'
574
- *
575
- * const provider = createOllama({ model: 'qwen3.5:2b-q4_K_M' })
576
- * const abort = createAbort()
577
- * const result = await provider.generate(messages, abort.signal)
578
- * ```
579
- *
580
- * @example
581
- * Route through your own server with an obfuscated token:
582
- * ```ts
583
- * const provider = createOllama({
584
- * model: 'qwen3.5:2b-q4_K_M',
585
- * url: 'https://my-app.example.com/llm', // your server, not the daemon
586
- * fetch: myFetch, // optional custom transport
587
- * headers: () => ({ authorization: `Bearer ${myToken}` }), // your server validates this
588
- * })
589
- * ```
590
- *
591
- * @example
592
- * Declare a context-framing default — wrap the instructions section in an XML group (the
593
- * provider-default level of `AgentContext`'s cascade; NOT the wire `format`):
594
- * ```ts
595
- * const provider = createOllama({
596
- * model: 'qwen3.5:2b-q4_K_M',
597
- * format: {
598
- * instructions: {
599
- * open: '<instructions>',
600
- * render: (i) => `<instruction>${i.content}</instruction>`,
601
- * close: '</instructions>',
602
- * },
603
- * },
604
- * })
605
- * ```
606
- */
607
- function createOllama(options) {
608
- return new OllamaProvider(options);
609
- }
610
- //#endregion
611
- exports.DEFAULT_KEEP_ALIVE = DEFAULT_KEEP_ALIVE;
612
- exports.DEFAULT_OLLAMA_URL = DEFAULT_OLLAMA_URL;
613
- exports.DEFAULT_PROVIDER_TIMEOUT = DEFAULT_PROVIDER_TIMEOUT;
614
- exports.MAX_ERROR_BODY_LENGTH = MAX_ERROR_BODY_LENGTH;
615
- exports.OllamaHTTPError = OllamaHTTPError;
616
- exports.OllamaProvider = OllamaProvider;
617
- exports.buildResult = buildResult;
618
- exports.createOllama = createOllama;
619
- exports.extractArguments = extractArguments;
620
- exports.extractContent = extractContent;
621
- exports.extractThinking = extractThinking;
622
- exports.extractTools = extractTools;
623
- exports.extractUsage = extractUsage;
624
- exports.isOllamaHTTPError = isOllamaHTTPError;
625
- exports.joinThinking = joinThinking;
626
- exports.mapMessages = mapMessages;
627
- exports.parseBody = parseBody;
628
-
629
- //# sourceMappingURL=index.cjs.map