@proposit/proposit-core 1.6.0 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extensions/ollama/errors.d.ts +3 -0
- package/dist/extensions/ollama/errors.d.ts.map +1 -1
- package/dist/extensions/ollama/errors.js +19 -1
- package/dist/extensions/ollama/errors.js.map +1 -1
- package/dist/extensions/ollama/provider.d.ts +3 -0
- package/dist/extensions/ollama/provider.d.ts.map +1 -1
- package/dist/extensions/ollama/provider.js +136 -4
- package/dist/extensions/ollama/provider.js.map +1 -1
- package/dist/extensions/ollama/timeout-fetch.d.ts +24 -0
- package/dist/extensions/ollama/timeout-fetch.d.ts.map +1 -0
- package/dist/extensions/ollama/timeout-fetch.js +76 -0
- package/dist/extensions/ollama/timeout-fetch.js.map +1 -0
- package/dist/extensions/ollama/types.d.ts +121 -3
- package/dist/extensions/ollama/types.d.ts.map +1 -1
- package/dist/extensions/openai/provider.d.ts +26 -0
- package/dist/extensions/openai/provider.d.ts.map +1 -1
- package/dist/extensions/openai/provider.js +334 -9
- package/dist/extensions/openai/provider.js.map +1 -1
- package/dist/extensions/openai/types.d.ts +3 -0
- package/dist/extensions/openai/types.d.ts.map +1 -1
- package/dist/lib/index.d.ts +3 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js.map +1 -1
- package/package.json +7 -2
|
@@ -62,6 +62,9 @@ export declare class ToolLoopExhaustedError extends Error {
|
|
|
62
62
|
* - context-overflow/eval err → NonRetryable (deterministic; never
|
|
63
63
|
* SchemaValidationLlmError).
|
|
64
64
|
* - `ECONNRESET` / socket drop→ Transient.
|
|
65
|
+
* - undici timeout cause-codes→ Transient (`UND_ERR_HEADERS_TIMEOUT` /
|
|
66
|
+
* `UND_ERR_BODY_TIMEOUT` / `UND_ERR_CONNECT_TIMEOUT`; a long local
|
|
67
|
+
* thinking-model generation outran the timeout — retryable).
|
|
65
68
|
* - cold-load / generic 5xx → Transient.
|
|
66
69
|
* - 429 → RateLimit (remote/proxy setups).
|
|
67
70
|
* - anything else → NonRetryable (safe fail-fast default).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/extensions/ollama/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/extensions/ollama/errors.ts"],"names":[],"mappings":"AA0CA,qBAAa,iBAAkB,SAAQ,KAAK;IACxC,SAAgB,WAAW,EAAG,WAAW,CAAS;IAClD,SAAgB,IAAI,wBAAsB;IAC1C,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAA;gBAEnB,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;CAKzD;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IACxC,SAAgB,WAAW,EAAG,YAAY,CAAS;IACnD,SAAgB,IAAI,qBAAmB;IACvC,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAA;gBAEnB,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;CAKzD;AAED;;;;;;;;;GASG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IAC/C,SAAgB,WAAW,EAAG,WAAW,CAAS;IAClD,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAA;gBAEnB,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;CAKzD;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IAC3C,SAAgB,IAAI,4BAA0B;IAC9C,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAA;gBAEnB,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;CAKzD;AAED,qBAAa,sBAAuB,SAAQ,KAAK;IAC7C,SAAgB,MAAM,EAAE,MAAM,CAAA;gBAElB,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;CAKxD;AAkDD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CA6EvD"}
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
//
|
|
15
15
|
// * `TransientLlmError` — `retryReason: "transient"`. Genuinely
|
|
16
16
|
// transient local hiccups: mid-stream `ECONNRESET`/socket drop,
|
|
17
|
+
// undici timeout cause-codes (`UND_ERR_HEADERS_TIMEOUT` /
|
|
18
|
+
// `UND_ERR_BODY_TIMEOUT` / `UND_ERR_CONNECT_TIMEOUT` — a long local
|
|
19
|
+
// thinking-model generation that outran the dispatcher timeout),
|
|
17
20
|
// cold-model-load 5xx (model pulled but still loading into VRAM),
|
|
18
21
|
// generic 5xx. Retried by the default policy.
|
|
19
22
|
// * `RateLimitLlmError` — `retryReason: "rate_limit"`. A local
|
|
@@ -146,6 +149,9 @@ const MODEL_NOT_FOUND_PATTERN = /model .* not found|not found, try pulling|no su
|
|
|
146
149
|
* - context-overflow/eval err → NonRetryable (deterministic; never
|
|
147
150
|
* SchemaValidationLlmError).
|
|
148
151
|
* - `ECONNRESET` / socket drop→ Transient.
|
|
152
|
+
* - undici timeout cause-codes→ Transient (`UND_ERR_HEADERS_TIMEOUT` /
|
|
153
|
+
* `UND_ERR_BODY_TIMEOUT` / `UND_ERR_CONNECT_TIMEOUT`; a long local
|
|
154
|
+
* thinking-model generation outran the timeout — retryable).
|
|
149
155
|
* - cold-load / generic 5xx → Transient.
|
|
150
156
|
* - 429 → RateLimit (remote/proxy setups).
|
|
151
157
|
* - anything else → NonRetryable (safe fail-fast default).
|
|
@@ -163,7 +169,19 @@ export function classifyOllamaError(err) {
|
|
|
163
169
|
});
|
|
164
170
|
}
|
|
165
171
|
// Mid-stream socket drop / transient connection loss — retryable.
|
|
166
|
-
|
|
172
|
+
// Includes undici's timeout cause-codes: a long local thinking-model
|
|
173
|
+
// generation that outruns the dispatcher's headers/body timeout (or a
|
|
174
|
+
// connect timeout) is transient against a still-working daemon, NOT a
|
|
175
|
+
// deterministic failure. The framework's default `retryOn: ["transient"]`
|
|
176
|
+
// then retries instead of dying `LLM_NON_RETRYABLE_ERROR`. undici wraps
|
|
177
|
+
// these as a `TypeError: fetch failed` whose `.cause.code` is the
|
|
178
|
+
// `UND_ERR_*` value — `nodeCodeOf` already probes one level of `.cause`.
|
|
179
|
+
if (code === "ECONNRESET" ||
|
|
180
|
+
code === "ETIMEDOUT" ||
|
|
181
|
+
code === "EPIPE" ||
|
|
182
|
+
code === "UND_ERR_HEADERS_TIMEOUT" ||
|
|
183
|
+
code === "UND_ERR_BODY_TIMEOUT" ||
|
|
184
|
+
code === "UND_ERR_CONNECT_TIMEOUT") {
|
|
167
185
|
return new TransientLlmError({
|
|
168
186
|
message: `Transient connection error talking to the Ollama daemon (${code}): ${message}`,
|
|
169
187
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/extensions/ollama/errors.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,EAAE;AACF,qEAAqE;AACrE,8DAA8D;AAC9D,sEAAsE;AACtE,qDAAqD;AACrD,sEAAsE;AACtE,uEAAuE;AACvE,uEAAuE;AACvE,yDAAyD;AACzD,EAAE;AACF,mDAAmD;AACnD,mDAAmD;AACnD,EAAE;AACF,kEAAkE;AAClE,oEAAoE;AACpE,sEAAsE;AACtE,kDAAkD;AAClD,iEAAiE;AACjE,uEAAuE;AACvE,iEAAiE;AACjE,wDAAwD;AACxD,uEAAuE;AACvE,8DAA8D;AAC9D,sEAAsE;AACtE,4DAA4D;AAC5D,6DAA6D;AAC7D,iEAAiE;AACjE,gEAAgE;AAChE,uEAAuE;AACvE,sEAAsE;AACtE,yDAAyD;AAEz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Q;QAAE,OAAO,CAAC,CAAC,MAAM,CAAA;IACjD,IAAI,OAAO,CAAC,CAAC,WAAW,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC,WAAW,CAAA;IAC3D,wDAAwD;IACxD,OAAO,SAAS,CAAA;AACpB,CAAC;AAED,SAAS,SAAS,CAAC,GAAY;IAC3B,IAAI,GAAG,YAAY,KAAK;QAAE,OAAO,GAAG,CAAC,OAAO,CAAA;IAC5C,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAA;IACvC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;AACtB,CAAC;AAED,MAAM,wBAAwB,GAC1B,8GAA8G,CAAA;AAElH,MAAM,uBAAuB,GACzB,0EAA0E,CAAA;AAE9E
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/extensions/ollama/errors.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,EAAE;AACF,qEAAqE;AACrE,8DAA8D;AAC9D,sEAAsE;AACtE,qDAAqD;AACrD,sEAAsE;AACtE,uEAAuE;AACvE,uEAAuE;AACvE,yDAAyD;AACzD,EAAE;AACF,mDAAmD;AACnD,mDAAmD;AACnD,EAAE;AACF,kEAAkE;AAClE,oEAAoE;AACpE,8DAA8D;AAC9D,wEAAwE;AACxE,qEAAqE;AACrE,sEAAsE;AACtE,kDAAkD;AAClD,iEAAiE;AACjE,uEAAuE;AACvE,iEAAiE;AACjE,wDAAwD;AACxD,uEAAuE;AACvE,8DAA8D;AAC9D,sEAAsE;AACtE,4DAA4D;AAC5D,6DAA6D;AAC7D,iEAAiE;AACjE,gEAAgE;AAChE,uEAAuE;AACvE,sEAAsE;AACtE,yDAAyD;AAEzD,OAAO,EACH,uBAAuB,EACvB,gBAAgB,EAChB,mBAAmB,GACtB,MAAM,sCAAsC,CAAA;AAE7C,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACxB,WAAW,GAAG,WAAoB,CAAA;IAClC,IAAI,GAA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,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1D,OAAO,IAAI,oBAAoB,CAAC;YAC5B,OAAO,EAAE,6FAA6F,OAAO,EAAE;YAC/G,MAAM;SACT,CAAC,CAAA;IACN,CAAC;IAED,mEAAmE;IACnE,oEAAoE;IACpE,iEAAiE;IACjE,6BAA6B;IAC7B,IAAI,wBAAwB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACzC,OAAO,IAAI,oBAAoB,CAAC;YAC5B,OAAO,EAAE,uKAAuK,OAAO,EAAE;YACzL,MAAM;SACT,CAAC,CAAA;IACN,CAAC;IAED,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACjB,OAAO,IAAI,iBAAiB,CAAC;YACzB,OAAO,EAAE,2EAA2E,OAAO,EAAE;YAC7F,MAAM;SACT,CAAC,CAAA;IACN,CAAC;IAED,iEAAiE;IACjE,kEAAkE;IAClE,8BAA8B;IAC9B,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QACxC,OAAO,IAAI,iBAAiB,CAAC;YACzB,OAAO,EAAE,mBAAmB,MAAM,CAAC,QAAQ,EAAE,4CAA4C,OAAO,EAAE;YAClG,MAAM;SACT,CAAC,CAAA;IACN,CAAC;IAED,mEAAmE;IACnE,OAAO,IAAI,oBAAoB,CAAC;QAC5B,OAAO,EAAE,8BAA8B,OAAO,EAAE;QAChD,MAAM;KACT,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -5,6 +5,9 @@ export declare class OllamaProvider implements TLlmProvider {
|
|
|
5
5
|
private clientPromise;
|
|
6
6
|
private readonly maxToolRounds;
|
|
7
7
|
private readonly numCtx;
|
|
8
|
+
private readonly requestTimeoutMs;
|
|
9
|
+
private readonly stream;
|
|
10
|
+
private readonly think?;
|
|
8
11
|
constructor(config?: TOllamaProviderConfig);
|
|
9
12
|
respond<T>(req: TLlmRequest<T>): Promise<TLlmResponse<T>>;
|
|
10
13
|
private runChatLoop;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/extensions/ollama/provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/extensions/ollama/provider.ts"],"names":[],"mappings":"AA6CA,OAAO,KAAK,EACR,YAAY,EACZ,WAAW,EACX,YAAY,EAGf,MAAM,wBAAwB,CAAA;AAc/B,OAAO,KAAK,EAOR,qBAAqB,EAExB,MAAM,YAAY,CAAA;AAkBnB,qBAAa,cAAe,YAAW,YAAY;IAC/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,aAAa,CAAsC;IAC3D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAQ;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAQ;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAS;gBAEpB,MAAM,CAAC,EAAE,qBAAqB;IAcpC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAmCjD,WAAW;IAyKzB;;;;OAIG;IACH,OAAO,CAAC,SAAS;YAQH,wBAAwB;CAiCzC"}
|
|
@@ -16,6 +16,24 @@
|
|
|
16
16
|
// * `reasoningEffort` is ignored (no Ollama analogue);
|
|
17
17
|
// `maxOutputTokens` maps to `options.num_predict` (positive values
|
|
18
18
|
// only — never 0; -1/-2 are Ollama sentinels we never emit).
|
|
19
|
+
// * Thinking follows the model default (qwen3: ON) unless the consumer
|
|
20
|
+
// sets `TOllamaProviderConfig.think`; the `think` field is sent only
|
|
21
|
+
// when configured (a pure opt-in knob). There is NO safe global
|
|
22
|
+
// default: on qwen3.6 the thinking toggle's effect on structured-
|
|
23
|
+
// output fidelity cuts both ways by stage (verified empirically).
|
|
24
|
+
// With think ON, some stages emit their whole answer in the thinking
|
|
25
|
+
// channel and return an empty `content`; with think OFF, other stages
|
|
26
|
+
// (e.g. segmentation) drop the required object wrapper → a bare
|
|
27
|
+
// array. Ollama's `format` does NOT hard-enforce the envelope on this
|
|
28
|
+
// model. So consumers pick `think` per their stages, or run a non-
|
|
29
|
+
// thinking model for the whole pipeline. When think is ON and the
|
|
30
|
+
// model returns empty `content` alongside a thinking trace, the
|
|
31
|
+
// provider raises a deterministic `NonRetryableLlmError` (not the
|
|
32
|
+
// old retry-burning transient error).
|
|
33
|
+
// * A generous per-request timeout (`requestTimeoutMs`, default 20 min)
|
|
34
|
+
// is applied via a PER-PROVIDER undici `Agent` passed as the SDK
|
|
35
|
+
// client's `fetch` — never `setGlobalDispatcher`; a library must not
|
|
36
|
+
// mutate global state. See `./timeout-fetch.ts`.
|
|
19
37
|
// * Errors are classified by `./errors.ts` #classifyOllamaError, which
|
|
20
38
|
// carries the same `retryReason` tags + lib failure-codes as the
|
|
21
39
|
// OpenAI provider. No `ollama → openai` dependency, no lib change.
|
|
@@ -26,6 +44,7 @@
|
|
|
26
44
|
// so `llmStage`'s mid-flight-abort detector marks the stage `skipped`.
|
|
27
45
|
import { debugLlmFailure, debugLlmRequest, debugLlmResponse, } from "../../lib/pipelines/debug-log.js";
|
|
28
46
|
import { typeboxToJsonSchema } from "./structured-output.js";
|
|
47
|
+
import { buildTimeoutFetch } from "./timeout-fetch.js";
|
|
29
48
|
import { NonRetryableLlmError, SchemaValidationLlmError, ToolLoopExhaustedError, classifyOllamaError, } from "./errors.js";
|
|
30
49
|
const STAGE_ID_MARKER = /<!--\s*stage-id:\s*([^\s>]+)\s*-->/;
|
|
31
50
|
const DEFAULT_BASE_URL = "http://localhost:11434";
|
|
@@ -35,16 +54,32 @@ const DEFAULT_MAX_TOOL_ROUNDS = 6;
|
|
|
35
54
|
// from a truncated prompt), and its per-model default is often ~4096,
|
|
36
55
|
// well under a real multi-KB ingestion prompt. See `TOllamaProviderConfig.numCtx`.
|
|
37
56
|
const DEFAULT_NUM_CTX = 32768;
|
|
57
|
+
// Generous per-request timeout for local thinking models. undici's 300s
|
|
58
|
+
// default aborts long structured-extraction generations with
|
|
59
|
+
// UND_ERR_HEADERS_TIMEOUT; 20 min gives qwen3.6-with-thinking room. The
|
|
60
|
+
// timeout is applied via a PER-PROVIDER undici Agent (never global state)
|
|
61
|
+
// — see ./timeout-fetch.ts and TOllamaProviderConfig.requestTimeoutMs.
|
|
62
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 1_200_000;
|
|
38
63
|
export class OllamaProvider {
|
|
39
64
|
config;
|
|
40
65
|
clientPromise = null;
|
|
41
66
|
maxToolRounds;
|
|
42
67
|
numCtx;
|
|
68
|
+
requestTimeoutMs;
|
|
69
|
+
stream;
|
|
70
|
+
think;
|
|
43
71
|
constructor(config) {
|
|
44
72
|
this.config = config ?? {};
|
|
45
73
|
this.maxToolRounds =
|
|
46
74
|
this.config.maxToolCallRounds ?? DEFAULT_MAX_TOOL_ROUNDS;
|
|
47
75
|
this.numCtx = this.config.numCtx ?? DEFAULT_NUM_CTX;
|
|
76
|
+
this.requestTimeoutMs =
|
|
77
|
+
this.config.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
78
|
+
this.stream = this.config.stream ?? true;
|
|
79
|
+
// Pure opt-in: undefined means "leave it to the model default"
|
|
80
|
+
// (no `think` field on the wire). No safe global default exists —
|
|
81
|
+
// see TOllamaProviderConfig.think.
|
|
82
|
+
this.think = this.config.think;
|
|
48
83
|
}
|
|
49
84
|
async respond(req) {
|
|
50
85
|
// Already-aborted short-circuit — don't even construct the
|
|
@@ -93,11 +128,19 @@ export class OllamaProvider {
|
|
|
93
128
|
// Build `format` from the single converted object so the
|
|
94
129
|
// schema can't drift from any prompt-grounding copy.
|
|
95
130
|
format: convertedSchema,
|
|
96
|
-
stream:
|
|
131
|
+
stream: this.stream,
|
|
97
132
|
};
|
|
98
133
|
if (tools) {
|
|
99
134
|
chatRequest.tools = tools;
|
|
100
135
|
}
|
|
136
|
+
// Thinking is a pure opt-in knob: send `think` ONLY when the
|
|
137
|
+
// consumer configured it, otherwise leave it to the model
|
|
138
|
+
// default. There is no safe global default — on qwen3.6 the
|
|
139
|
+
// thinking toggle's effect on structured-output fidelity cuts
|
|
140
|
+
// both ways by stage (see TOllamaProviderConfig.think).
|
|
141
|
+
if (this.think !== undefined) {
|
|
142
|
+
chatRequest.think = this.think;
|
|
143
|
+
}
|
|
101
144
|
// `temperature: 0` for deterministic structured output;
|
|
102
145
|
// `num_ctx` set generously so Ollama doesn't silently
|
|
103
146
|
// truncate a real multi-KB ingestion prompt (its per-model
|
|
@@ -124,7 +167,8 @@ export class OllamaProvider {
|
|
|
124
167
|
});
|
|
125
168
|
let response;
|
|
126
169
|
try {
|
|
127
|
-
|
|
170
|
+
const raw = await client.chat(chatRequest);
|
|
171
|
+
response = isAsyncIterable(raw) ? await collectStream(raw) : raw;
|
|
128
172
|
}
|
|
129
173
|
catch (err) {
|
|
130
174
|
// Mid-flight abort: the SDK rejects with an AbortError
|
|
@@ -175,6 +219,21 @@ export class OllamaProvider {
|
|
|
175
219
|
}
|
|
176
220
|
const text = response.message.content;
|
|
177
221
|
if (text === undefined || text === "") {
|
|
222
|
+
const thinking = response.message.thinking;
|
|
223
|
+
if (thinking !== undefined && thinking !== "") {
|
|
224
|
+
// The model emitted its whole answer in the thinking
|
|
225
|
+
// channel and left `content` empty — DETERMINISTIC for
|
|
226
|
+
// this prompt/model. Surfacing it as the transient
|
|
227
|
+
// SchemaValidationLlmError would burn a guaranteed-
|
|
228
|
+
// failing retry on the same request, so fail fast with
|
|
229
|
+
// actionable guidance and a thinking excerpt.
|
|
230
|
+
throw new NonRetryableLlmError({
|
|
231
|
+
message: `Ollama returned an empty assistant \`content\` alongside a ${thinking.length.toString()}-char ` +
|
|
232
|
+
"thinking trace — the model emitted its answer in the thinking channel, which cannot be " +
|
|
233
|
+
"consumed as structured output. Set `think: false` on the OllamaProvider config for this " +
|
|
234
|
+
`stage (configurable via TOllamaProviderConfig.think). Thinking excerpt: ${thinking.slice(0, 200)}`,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
178
237
|
throw new SchemaValidationLlmError({
|
|
179
238
|
message: "Ollama chat response carried no assistant text content.",
|
|
180
239
|
});
|
|
@@ -213,9 +272,11 @@ export class OllamaProvider {
|
|
|
213
272
|
}
|
|
214
273
|
async importAndConstructClient() {
|
|
215
274
|
const baseUrl = this.config.baseUrl ?? DEFAULT_BASE_URL;
|
|
275
|
+
const importOllama = this.config.importOllama ??
|
|
276
|
+
(() => import("ollama"));
|
|
216
277
|
let mod;
|
|
217
278
|
try {
|
|
218
|
-
mod =
|
|
279
|
+
mod = await importOllama();
|
|
219
280
|
}
|
|
220
281
|
catch (err) {
|
|
221
282
|
throw new Error("OllamaProvider: the optional `ollama` package is not installed. " +
|
|
@@ -223,7 +284,17 @@ export class OllamaProvider {
|
|
|
223
284
|
"or pass a pre-built `client` via the provider config. " +
|
|
224
285
|
`Original import error: ${err instanceof Error ? err.message : String(err)}`);
|
|
225
286
|
}
|
|
226
|
-
|
|
287
|
+
// Per-provider raised-timeout fetch (no global mutation). Falls
|
|
288
|
+
// back to the SDK default fetch when undici is unavailable or the
|
|
289
|
+
// caller set requestTimeoutMs to 0.
|
|
290
|
+
const timeoutFetch = await buildTimeoutFetch(this.requestTimeoutMs, this.config.importUndici);
|
|
291
|
+
const sdkConfig = {
|
|
292
|
+
host: baseUrl,
|
|
293
|
+
};
|
|
294
|
+
if (timeoutFetch) {
|
|
295
|
+
sdkConfig.fetch = timeoutFetch;
|
|
296
|
+
}
|
|
297
|
+
return new mod.Ollama(sdkConfig);
|
|
227
298
|
}
|
|
228
299
|
}
|
|
229
300
|
// -- helpers --------------------------------------------------------------
|
|
@@ -247,6 +318,67 @@ function safeParseJson(raw) {
|
|
|
247
318
|
});
|
|
248
319
|
}
|
|
249
320
|
}
|
|
321
|
+
function isAsyncIterable(value) {
|
|
322
|
+
return (typeof value === "object" &&
|
|
323
|
+
value !== null &&
|
|
324
|
+
Symbol.asyncIterator in value);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Consume a streamed `chat()` generation and synthesize a single
|
|
328
|
+
* `TOllamaChatResponse`: concatenated `message.content`, tool_calls
|
|
329
|
+
* captured from any chunk that carries them, and the eval counts from
|
|
330
|
+
* the final (`done: true`) chunk. The synthesized response feeds the
|
|
331
|
+
* existing one-shot processing path unchanged, so `respond()`'s
|
|
332
|
+
* contract is preserved.
|
|
333
|
+
*/
|
|
334
|
+
async function collectStream(iterable) {
|
|
335
|
+
let content = "";
|
|
336
|
+
let thinking = "";
|
|
337
|
+
let role = "assistant";
|
|
338
|
+
let toolCalls;
|
|
339
|
+
let promptEvalCount = 0;
|
|
340
|
+
let evalCount = 0;
|
|
341
|
+
for await (const chunk of iterable) {
|
|
342
|
+
const msg = chunk.message;
|
|
343
|
+
if (msg) {
|
|
344
|
+
content += msg.content ?? "";
|
|
345
|
+
// Accumulate the thinking channel too, so an empty `content`
|
|
346
|
+
// accompanied by a thinking trace is surfaced as a
|
|
347
|
+
// deterministic failure rather than the generic "no content"
|
|
348
|
+
// transient error. See runChatLoop's empty-content branch.
|
|
349
|
+
thinking += msg.thinking ?? "";
|
|
350
|
+
if (msg.role)
|
|
351
|
+
role = msg.role;
|
|
352
|
+
// Ollama emits tool_calls complete within a single chunk
|
|
353
|
+
// (not OpenAI-style per-index deltas), so take the latest
|
|
354
|
+
// chunk that carries them — concatenating would DUPLICATE
|
|
355
|
+
// calls. Ingestion is tool-free; only tool-using callers
|
|
356
|
+
// exercise this path.
|
|
357
|
+
if (msg.tool_calls && msg.tool_calls.length > 0) {
|
|
358
|
+
toolCalls = msg.tool_calls;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
// Last-wins: the synthesized response carries the FINAL chunk's
|
|
362
|
+
// single-round eval counts, NOT a cumulative sum across chunks.
|
|
363
|
+
// The terminal chunk reports this round's complete terminal
|
|
364
|
+
// counts, so taking the last value is the correct per-round
|
|
365
|
+
// figure. `runChatLoop`'s `mergeUsage` then SUMS these per-round
|
|
366
|
+
// terminal counts across tool-call rounds — summing the chunk
|
|
367
|
+
// values here instead would double-count within a round.
|
|
368
|
+
if (chunk.prompt_eval_count !== undefined) {
|
|
369
|
+
promptEvalCount = chunk.prompt_eval_count;
|
|
370
|
+
}
|
|
371
|
+
if (chunk.eval_count !== undefined) {
|
|
372
|
+
evalCount = chunk.eval_count;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return {
|
|
376
|
+
message: { role, content, thinking, tool_calls: toolCalls },
|
|
377
|
+
done: true,
|
|
378
|
+
prompt_eval_count: promptEvalCount,
|
|
379
|
+
eval_count: evalCount,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
250
382
|
function mergeUsage(accumulated, next) {
|
|
251
383
|
return {
|
|
252
384
|
input: accumulated.input + next.input,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/extensions/ollama/provider.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,6BAA6B;AAC7B,EAAE;AACF,uEAAuE;AACvE,gEAAgE;AAChE,2DAA2D;AAC3D,yCAAyC;AACzC,EAAE;AACF,2DAA2D;AAC3D,wEAAwE;AACxE,oEAAoE;AACpE,mDAAmD;AACnD,+DAA+D;AAC/D,qEAAqE;AACrE,wCAAwC;AACxC,yDAAyD;AACzD,uEAAuE;AACvE,iEAAiE;AACjE,yEAAyE;AACzE,qEAAqE;AACrE,uEAAuE;AACvE,EAAE;AACF,uEAAuE;AACvE,iEAAiE;AACjE,uEAAuE;AACvE,uEAAuE;AASvE,OAAO,EACH,eAAe,EACf,eAAe,EACf,gBAAgB,GACnB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA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aped function backed by a per-instance undici `Agent`
|
|
5
|
+
* whose `headersTimeout` and `bodyTimeout` are raised to `requestTimeoutMs`.
|
|
6
|
+
*
|
|
7
|
+
* The returned wrapper delegates to **the imported undici module's own
|
|
8
|
+
* `fetch`** (`mod.fetch`), passing the `Agent` as its `dispatcher`. The base
|
|
9
|
+
* fetch and the dispatcher MUST come from the same undici instance — handing
|
|
10
|
+
* this Agent to Node's bundled-undici global `fetch` is rejected with
|
|
11
|
+
* `UND_ERR_INVALID_ARG`. See the file header.
|
|
12
|
+
*
|
|
13
|
+
* Returns `undefined` when `requestTimeoutMs <= 0` (caller opted out) or
|
|
14
|
+
* when the optional `undici` peer cannot be imported (graceful fallback to
|
|
15
|
+
* the SDK's default fetch — Node's global fetch with no dispatcher, which
|
|
16
|
+
* works; the raised timeout is simply lost and `classifyOllamaError` maps
|
|
17
|
+
* any resulting timeout to a retryable transient error).
|
|
18
|
+
*
|
|
19
|
+
* @param requestTimeoutMs raised headers/body timeout in milliseconds
|
|
20
|
+
* @param importUndici injectable importer (test seam); defaults to `import("undici")`
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildTimeoutFetch(requestTimeoutMs: number, importUndici?: TUndiciImporter): Promise<typeof fetch | undefined>;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=timeout-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout-fetch.d.ts","sourceRoot":"","sources":["../../../src/extensions/ollama/timeout-fetch.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,KAAK,eAAe,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,CAAA;AAKnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,iBAAiB,CACnC,gBAAgB,EAAE,MAAM,EACxB,YAAY,GAAE,eAAuC,GACtD,OAAO,CAAC,OAAO,KAAK,GAAG,SAAS,CAAC,CAqCnC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Per-provider request-timeout fetch for the Ollama provider.
|
|
2
|
+
//
|
|
3
|
+
// Local thinking models (e.g. qwen3.6 with thinking on) legitimately take
|
|
4
|
+
// many minutes per structured-extraction stage; undici's 300s default
|
|
5
|
+
// `headersTimeout`/`bodyTimeout` aborts them mid-generation with a
|
|
6
|
+
// `TypeError: fetch failed` whose `.cause.code` is `UND_ERR_HEADERS_TIMEOUT`.
|
|
7
|
+
//
|
|
8
|
+
// This builds a custom `fetch` that routes through a **per-instance** undici
|
|
9
|
+
// `Agent` with raised timeouts, passed to the `ollama` SDK client as its
|
|
10
|
+
// `fetch`. It deliberately does NOT call `setGlobalDispatcher` — a library
|
|
11
|
+
// must not mutate global state. `undici` is an optional peer (same posture
|
|
12
|
+
// as `ollama`); when it is unavailable, this returns `undefined` and the
|
|
13
|
+
// provider falls back to the SDK's default fetch (the `classifyOllamaError`
|
|
14
|
+
// transient-timeout mapping then makes the resulting 300s timeout retryable
|
|
15
|
+
// rather than fatal).
|
|
16
|
+
//
|
|
17
|
+
// CRITICAL — pair the Agent with its OWN fetch. The raised-timeout `Agent`
|
|
18
|
+
// is constructed from the separately-installed `undici` package, so the
|
|
19
|
+
// `dispatcher` must be handed to *that same module's* `fetch` (`mod.fetch`),
|
|
20
|
+
// NOT to Node's bundled-undici global `fetch`. Node's global `fetch` rejects
|
|
21
|
+
// a foreign-undici `Agent` dispatcher with `UND_ERR_INVALID_ARG`
|
|
22
|
+
// (`TypeError: fetch failed`), which would make every Ollama request fail
|
|
23
|
+
// instantly when `undici` is installed. Never mix the two undici instances.
|
|
24
|
+
//
|
|
25
|
+
// Scoped to `src/extensions/ollama/` — `src/lib/` never imports `undici`.
|
|
26
|
+
const defaultUndiciImporter = () => import("undici");
|
|
27
|
+
/**
|
|
28
|
+
* Build a `fetch`-shaped function backed by a per-instance undici `Agent`
|
|
29
|
+
* whose `headersTimeout` and `bodyTimeout` are raised to `requestTimeoutMs`.
|
|
30
|
+
*
|
|
31
|
+
* The returned wrapper delegates to **the imported undici module's own
|
|
32
|
+
* `fetch`** (`mod.fetch`), passing the `Agent` as its `dispatcher`. The base
|
|
33
|
+
* fetch and the dispatcher MUST come from the same undici instance — handing
|
|
34
|
+
* this Agent to Node's bundled-undici global `fetch` is rejected with
|
|
35
|
+
* `UND_ERR_INVALID_ARG`. See the file header.
|
|
36
|
+
*
|
|
37
|
+
* Returns `undefined` when `requestTimeoutMs <= 0` (caller opted out) or
|
|
38
|
+
* when the optional `undici` peer cannot be imported (graceful fallback to
|
|
39
|
+
* the SDK's default fetch — Node's global fetch with no dispatcher, which
|
|
40
|
+
* works; the raised timeout is simply lost and `classifyOllamaError` maps
|
|
41
|
+
* any resulting timeout to a retryable transient error).
|
|
42
|
+
*
|
|
43
|
+
* @param requestTimeoutMs raised headers/body timeout in milliseconds
|
|
44
|
+
* @param importUndici injectable importer (test seam); defaults to `import("undici")`
|
|
45
|
+
*/
|
|
46
|
+
export async function buildTimeoutFetch(requestTimeoutMs, importUndici = defaultUndiciImporter) {
|
|
47
|
+
if (!Number.isFinite(requestTimeoutMs) || requestTimeoutMs <= 0) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
let mod;
|
|
51
|
+
try {
|
|
52
|
+
mod = await importUndici();
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// undici not installed — degrade to the SDK default fetch. The
|
|
56
|
+
// classify-timeout mapping keeps the resulting timeout retryable.
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const agent = new mod.Agent({
|
|
60
|
+
headersTimeout: requestTimeoutMs,
|
|
61
|
+
bodyTimeout: requestTimeoutMs,
|
|
62
|
+
connectTimeout: requestTimeoutMs,
|
|
63
|
+
});
|
|
64
|
+
// Pair the Agent with undici's OWN fetch — never Node's global fetch,
|
|
65
|
+
// which rejects a foreign-undici Agent dispatcher.
|
|
66
|
+
const undiciFetch = mod.fetch;
|
|
67
|
+
const timeoutFetch = ((input, init) => undiciFetch(input, {
|
|
68
|
+
...init,
|
|
69
|
+
// `dispatcher` is an undici-specific RequestInit extension that
|
|
70
|
+
// undici's fetch honors; it is not in the lib.dom RequestInit
|
|
71
|
+
// type, hence the structural widening.
|
|
72
|
+
...{ dispatcher: agent },
|
|
73
|
+
}));
|
|
74
|
+
return timeoutFetch;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=timeout-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout-fetch.js","sourceRoot":"","sources":["../../../src/extensions/ollama/timeout-fetch.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,0EAA0E;AAC1E,sEAAsE;AACtE,mEAAmE;AACnE,8EAA8E;AAC9E,EAAE;AACF,6EAA6E;AAC7E,yEAAyE;AACzE,2EAA2E;AAC3E,2EAA2E;AAC3E,yEAAyE;AACzE,4EAA4E;AAC5E,4EAA4E;AAC5E,sBAAsB;AACtB,EAAE;AACF,2EAA2E;AAC3E,wEAAwE;AACxE,6EAA6E;AAC7E,6EAA6E;AAC7E,iEAAiE;AACjE,0EAA0E;AAC1E,4EAA4E;AAC5E,EAAE;AACF,0EAA0E;AAM1E,MAAM,qBAAqB,GAAoB,GAAG,EAAE,CAChD,MAAM,CAAC,QAAQ,CAAsC,CAAA;AAEzD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACnC,gBAAwB,EACxB,eAAgC,qBAAqB;IAErD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,gBAAgB,IAAI,CAAC,EAAE,CAAC;QAC9D,OAAO,SAAS,CAAA;IACpB,CAAC;IAED,IAAI,GAAkB,CAAA;IACtB,IAAI,CAAC;QACD,GAAG,GAAG,MAAM,YAAY,EAAE,CAAA;IAC9B,CAAC;IAAC,MAAM,CAAC;QACL,+DAA+D;QAC/D,kEAAkE;QAClE,OAAO,SAAS,CAAA;IACpB,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC;QACxB,cAAc,EAAE,gBAAgB;QAChC,WAAW,EAAE,gBAAgB;QAC7B,cAAc,EAAE,gBAAgB;KACnC,CAAC,CAAA;IAEF,sEAAsE;IACtE,mDAAmD;IACnD,MAAM,WAAW,GAAG,GAAG,CAAC,KAAK,CAAA;IAE7B,MAAM,YAAY,GAAG,CAAC,CAClB,KAAkC,EAClC,IAAkC,EACpC,EAAE,CACA,WAAW,CAAC,KAAK,EAAE;QACf,GAAG,IAAI;QACP,gEAAgE;QAChE,8DAA8D;QAC9D,uCAAuC;QACvC,GAAI,EAAE,UAAU,EAAE,KAAK,EAAa;KACvC,CAAC,CAAiB,CAAA;IAEvB,OAAO,YAAY,CAAA;AACvB,CAAC"}
|
|
@@ -14,10 +14,19 @@ export type TOllamaChatToolCall = {
|
|
|
14
14
|
export type TOllamaChatMessage = {
|
|
15
15
|
role: string;
|
|
16
16
|
content: string;
|
|
17
|
+
/**
|
|
18
|
+
* Thinking-model reasoning trace, present when `think` is enabled.
|
|
19
|
+
* A wire field on the Ollama chat message; read so an empty
|
|
20
|
+
* `content` accompanied by a thinking trace can be surfaced as a
|
|
21
|
+
* deterministic, actionable failure instead of a silently-discarded
|
|
22
|
+
* answer. See `OllamaProvider`'s empty-content handling.
|
|
23
|
+
*/
|
|
24
|
+
thinking?: string;
|
|
17
25
|
tool_calls?: TOllamaChatToolCall[];
|
|
18
26
|
};
|
|
19
27
|
export type TOllamaChatResponse = {
|
|
20
28
|
message: TOllamaChatMessage;
|
|
29
|
+
done?: boolean;
|
|
21
30
|
prompt_eval_count?: number;
|
|
22
31
|
eval_count?: number;
|
|
23
32
|
};
|
|
@@ -35,8 +44,14 @@ export type TOllamaChatRequest = {
|
|
|
35
44
|
model: string;
|
|
36
45
|
messages: TOllamaChatMessage[];
|
|
37
46
|
format?: string | object;
|
|
47
|
+
/**
|
|
48
|
+
* Toggle the model's thinking trace. Omitted → model default (ON for
|
|
49
|
+
* reasoning models like qwen3). The provider sends this only when the
|
|
50
|
+
* consumer configures `TOllamaProviderConfig.think`.
|
|
51
|
+
*/
|
|
52
|
+
think?: boolean;
|
|
38
53
|
tools?: TOllamaToolWire[];
|
|
39
|
-
stream?:
|
|
54
|
+
stream?: boolean;
|
|
40
55
|
options?: {
|
|
41
56
|
temperature?: number;
|
|
42
57
|
num_predict?: number;
|
|
@@ -51,19 +66,50 @@ export type TOllamaChatRequest = {
|
|
|
51
66
|
* injection seam.
|
|
52
67
|
*/
|
|
53
68
|
export type TOllamaClient = {
|
|
54
|
-
chat(request: TOllamaChatRequest): Promise<TOllamaChatResponse
|
|
69
|
+
chat(request: TOllamaChatRequest): Promise<TOllamaChatResponse | AsyncIterable<TOllamaChatResponse>>;
|
|
55
70
|
abort(): void;
|
|
56
71
|
};
|
|
57
72
|
/**
|
|
58
73
|
* The shape of the dynamically-imported `ollama` module. `Ollama` is
|
|
59
74
|
* the SDK's exported class-constructor name (an external symbol), so it
|
|
60
|
-
* is exempt from the in-repo camelCase property-naming rule.
|
|
75
|
+
* is exempt from the in-repo camelCase property-naming rule. The SDK's
|
|
76
|
+
* `Config` accepts an optional `fetch` override (used by the
|
|
77
|
+
* per-provider raised-timeout dispatcher — see `./timeout-fetch.ts`).
|
|
61
78
|
*/
|
|
62
79
|
export type TOllamaModule = {
|
|
63
80
|
Ollama: new (config: {
|
|
64
81
|
host: string;
|
|
82
|
+
fetch?: typeof fetch;
|
|
65
83
|
}) => TOllamaClient;
|
|
66
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* Structural slice of the `undici` module the timeout-fetch helper uses.
|
|
87
|
+
* Modeled (not imported) so the optional `undici` peer stays out of the
|
|
88
|
+
* type graph — same pattern as {@link TOllamaModule} for the `ollama`
|
|
89
|
+
* peer. The undici `Agent` constructor accepts millisecond timeout
|
|
90
|
+
* options; we raise `headersTimeout` + `bodyTimeout` (and `connectTimeout`)
|
|
91
|
+
* so a long local thinking-model generation isn't aborted at undici's
|
|
92
|
+
* 300s default. `Agent` is undici's exported class-constructor name (an
|
|
93
|
+
* external symbol), exempt from the camelCase rule.
|
|
94
|
+
*/
|
|
95
|
+
export type TUndiciAgentOptions = {
|
|
96
|
+
headersTimeout?: number;
|
|
97
|
+
bodyTimeout?: number;
|
|
98
|
+
connectTimeout?: number;
|
|
99
|
+
};
|
|
100
|
+
export type TUndiciDispatcher = object;
|
|
101
|
+
export type TUndiciModule = {
|
|
102
|
+
Agent: new (options: TUndiciAgentOptions) => TUndiciDispatcher;
|
|
103
|
+
/**
|
|
104
|
+
* undici's own `fetch`. The raised-timeout `Agent` MUST be passed as
|
|
105
|
+
* a `dispatcher` to *this* fetch — the one from the same undici
|
|
106
|
+
* module the `Agent` was constructed from. Node's bundled-undici
|
|
107
|
+
* global `fetch` rejects a foreign-undici `Agent` dispatcher with
|
|
108
|
+
* `UND_ERR_INVALID_ARG`, so the base fetch and the dispatcher must
|
|
109
|
+
* come from the same undici instance. See `./timeout-fetch.ts`.
|
|
110
|
+
*/
|
|
111
|
+
fetch: typeof fetch;
|
|
112
|
+
};
|
|
67
113
|
export type TOllamaProviderConfig = {
|
|
68
114
|
/** Daemon base URL. Defaults to `http://localhost:11434`. */
|
|
69
115
|
baseUrl?: string;
|
|
@@ -74,6 +120,41 @@ export type TOllamaProviderConfig = {
|
|
|
74
120
|
* surfaces as an actionable error at construction time.
|
|
75
121
|
*/
|
|
76
122
|
client?: TOllamaClient;
|
|
123
|
+
/**
|
|
124
|
+
* Injectable `ollama`-module importer. Test seam — defaults to
|
|
125
|
+
* `import("ollama")`. Lets tests assert the SDK client is constructed
|
|
126
|
+
* with the per-provider timeout-fetch without touching the real
|
|
127
|
+
* package. Ignored when `client` is provided.
|
|
128
|
+
*
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
importOllama?: () => Promise<TOllamaModule>;
|
|
132
|
+
/**
|
|
133
|
+
* Injectable `undici`-module importer. Test seam — defaults to
|
|
134
|
+
* `import("undici")`. See {@link requestTimeoutMs}.
|
|
135
|
+
*
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
importUndici?: () => Promise<TUndiciModule>;
|
|
139
|
+
/**
|
|
140
|
+
* Per-request HTTP timeout in milliseconds, applied via a
|
|
141
|
+
* **per-provider** undici `Agent` (raised `headersTimeout` +
|
|
142
|
+
* `bodyTimeout`) passed as the `ollama` SDK client's `fetch`
|
|
143
|
+
* dispatcher. Defaults to **1_200_000 (20 min)** — local thinking
|
|
144
|
+
* models legitimately take many minutes per structured-extraction
|
|
145
|
+
* stage, and undici's 300s default aborts them mid-generation with a
|
|
146
|
+
* `UND_ERR_HEADERS_TIMEOUT` `fetch failed`.
|
|
147
|
+
*
|
|
148
|
+
* **No global state is mutated** — the raised timeout is scoped to
|
|
149
|
+
* this provider's client only (never `setGlobalDispatcher`). Requires
|
|
150
|
+
* the optional `undici` peer; if it is not installed the provider
|
|
151
|
+
* falls back to the SDK's default fetch (300s) and relies on
|
|
152
|
+
* `classifyOllamaError` retrying the resulting timeout as transient.
|
|
153
|
+
*
|
|
154
|
+
* Set `0` to disable the custom dispatcher entirely (use the SDK
|
|
155
|
+
* default). A finite positive value is recommended.
|
|
156
|
+
*/
|
|
157
|
+
requestTimeoutMs?: number;
|
|
77
158
|
/**
|
|
78
159
|
* Context-window size sent as Ollama's `options.num_ctx`. Defaults
|
|
79
160
|
* to a generous **32768**.
|
|
@@ -91,6 +172,43 @@ export type TOllamaProviderConfig = {
|
|
|
91
172
|
* and inputs are known to be small.
|
|
92
173
|
*/
|
|
93
174
|
numCtx?: number;
|
|
175
|
+
/**
|
|
176
|
+
* Stream the `chat()` generation and accumulate the chunks inside
|
|
177
|
+
* the provider, returning a single synthesized response. Defaults
|
|
178
|
+
* to **`true`** — streaming is the primary fix for the hardcoded
|
|
179
|
+
* ~300s non-streaming Ollama timeout (ollama/ollama#5081): headers
|
|
180
|
+
* and the first chunk arrive immediately and undici's `bodyTimeout`
|
|
181
|
+
* resets per chunk, so a long local thinking-model generation is no
|
|
182
|
+
* longer aborted mid-flight. Set `false` to restore the legacy
|
|
183
|
+
* single one-shot (`stream: false`) request.
|
|
184
|
+
*/
|
|
185
|
+
stream?: boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Toggle Ollama's thinking trace (`think` on the chat request).
|
|
188
|
+
*
|
|
189
|
+
* **Opt-in.** When unset (the default) the provider sends no `think`
|
|
190
|
+
* field and the model's own default applies (ON for reasoning models
|
|
191
|
+
* like `qwen3.6:latest`, off for non-thinking models like `gemma2`).
|
|
192
|
+
*
|
|
193
|
+
* **There is no safe global default**, because on `qwen3.6:latest`
|
|
194
|
+
* the thinking toggle's effect on structured-output fidelity is
|
|
195
|
+
* stage-dependent and cuts both ways (verified empirically):
|
|
196
|
+
*
|
|
197
|
+
* - With `think: true`, some stages (e.g. claim-mention-extraction)
|
|
198
|
+
* emit their entire answer in the thinking channel and return an
|
|
199
|
+
* **empty `content`** — which the provider surfaces as a
|
|
200
|
+
* deterministic {@link NonRetryableLlmError} (not a retry-burning
|
|
201
|
+
* transient error) advising `think: false`.
|
|
202
|
+
* - With `think: false`, other stages (e.g. segmentation) drop the
|
|
203
|
+
* required object wrapper and return a **bare array**, failing the
|
|
204
|
+
* downstream schema check. Ollama's `format` does NOT hard-enforce
|
|
205
|
+
* the object envelope on this model.
|
|
206
|
+
*
|
|
207
|
+
* So set `think` per the stages a given provider instance serves, or
|
|
208
|
+
* — simplest — run a non-thinking model (e.g. `gemma2:9b`) for the
|
|
209
|
+
* whole ingestion pipeline, which sidesteps the toggle entirely.
|
|
210
|
+
*/
|
|
211
|
+
think?: boolean;
|
|
94
212
|
/**
|
|
95
213
|
* Cap on function-tool agent-loop round-trips before throwing
|
|
96
214
|
* `ToolLoopExhaustedError`. Defaults to 6, mirroring the OpenAI
|