@proposit/proposit-core 2.0.0 → 2.2.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.
Files changed (230) hide show
  1. package/dist/cli/commands/parse.d.ts.map +1 -1
  2. package/dist/cli/commands/parse.js +27 -29
  3. package/dist/cli/commands/parse.js.map +1 -1
  4. package/dist/extensions/chat-completions/errors.d.ts +66 -0
  5. package/dist/extensions/chat-completions/errors.d.ts.map +1 -0
  6. package/dist/extensions/chat-completions/errors.js +139 -0
  7. package/dist/extensions/chat-completions/errors.js.map +1 -0
  8. package/dist/extensions/chat-completions/http.d.ts +10 -0
  9. package/dist/extensions/chat-completions/http.d.ts.map +1 -0
  10. package/dist/extensions/chat-completions/http.js +80 -0
  11. package/dist/extensions/chat-completions/http.js.map +1 -0
  12. package/dist/extensions/chat-completions/index.d.ts +7 -0
  13. package/dist/extensions/chat-completions/index.d.ts.map +1 -0
  14. package/dist/extensions/chat-completions/index.js +18 -0
  15. package/dist/extensions/chat-completions/index.js.map +1 -0
  16. package/dist/extensions/chat-completions/provider.d.ts +5 -0
  17. package/dist/extensions/chat-completions/provider.d.ts.map +1 -0
  18. package/dist/extensions/chat-completions/provider.js +192 -0
  19. package/dist/extensions/chat-completions/provider.js.map +1 -0
  20. package/dist/extensions/chat-completions/structured-output.d.ts +18 -0
  21. package/dist/extensions/chat-completions/structured-output.d.ts.map +1 -0
  22. package/dist/extensions/{ollama → chat-completions}/structured-output.js +14 -10
  23. package/dist/extensions/chat-completions/structured-output.js.map +1 -0
  24. package/dist/extensions/chat-completions/types.d.ts +65 -0
  25. package/dist/extensions/chat-completions/types.d.ts.map +1 -0
  26. package/dist/extensions/chat-completions/types.js +19 -0
  27. package/dist/extensions/chat-completions/types.js.map +1 -0
  28. package/dist/extensions/openai/errors.js +1 -1
  29. package/dist/extensions/openai/errors.js.map +1 -1
  30. package/dist/extensions/openai/provider.d.ts +2 -2
  31. package/dist/extensions/{argument-ingestion/shared → pipelines/base}/basics-extension.d.ts +1 -1
  32. package/dist/extensions/pipelines/base/basics-extension.d.ts.map +1 -0
  33. package/dist/extensions/{argument-ingestion/shared → pipelines/base}/basics-extension.js +5 -4
  34. package/dist/extensions/pipelines/base/basics-extension.js.map +1 -0
  35. package/dist/extensions/pipelines/base/finalize-response-v2.d.ts.map +1 -0
  36. package/dist/extensions/{argument-ingestion/shared → pipelines/base}/finalize-response-v2.js +1 -1
  37. package/dist/extensions/pipelines/base/finalize-response-v2.js.map +1 -0
  38. package/dist/extensions/pipelines/base/index.d.ts +9 -0
  39. package/dist/extensions/pipelines/base/index.d.ts.map +1 -0
  40. package/dist/extensions/pipelines/base/index.js +17 -0
  41. package/dist/extensions/pipelines/base/index.js.map +1 -0
  42. package/dist/extensions/pipelines/base/resolve-llm-stage-options.d.ts.map +1 -0
  43. package/dist/extensions/{argument-ingestion/shared → pipelines/base}/resolve-llm-stage-options.js +2 -2
  44. package/dist/extensions/pipelines/base/resolve-llm-stage-options.js.map +1 -0
  45. package/dist/extensions/pipelines/base/role-derivation.d.ts.map +1 -0
  46. package/dist/extensions/pipelines/base/role-derivation.js.map +1 -0
  47. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/axiom-indicator-detection.d.ts +2 -2
  48. package/dist/extensions/pipelines/base/stages/axiom-indicator-detection.d.ts.map +1 -0
  49. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/axiom-indicator-detection.js +1 -1
  50. package/dist/extensions/pipelines/base/stages/axiom-indicator-detection.js.map +1 -0
  51. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/citation-source-detection.d.ts +2 -2
  52. package/dist/extensions/pipelines/base/stages/citation-source-detection.d.ts.map +1 -0
  53. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/citation-source-detection.js +1 -1
  54. package/dist/extensions/pipelines/base/stages/citation-source-detection.js.map +1 -0
  55. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/claim-canonicalization.d.ts +20 -3
  56. package/dist/extensions/pipelines/base/stages/claim-canonicalization.d.ts.map +1 -0
  57. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/claim-canonicalization.js +20 -6
  58. package/dist/extensions/pipelines/base/stages/claim-canonicalization.js.map +1 -0
  59. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/claim-mention-extraction.d.ts +2 -2
  60. package/dist/extensions/pipelines/base/stages/claim-mention-extraction.d.ts.map +1 -0
  61. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/claim-mention-extraction.js +1 -1
  62. package/dist/extensions/pipelines/base/stages/claim-mention-extraction.js.map +1 -0
  63. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/claim-reference-validation.d.ts +1 -1
  64. package/dist/extensions/pipelines/base/stages/claim-reference-validation.d.ts.map +1 -0
  65. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/claim-reference-validation.js +1 -1
  66. package/dist/extensions/pipelines/base/stages/claim-reference-validation.js.map +1 -0
  67. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/claim-type-classification.d.ts +2 -2
  68. package/dist/extensions/pipelines/base/stages/claim-type-classification.d.ts.map +1 -0
  69. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/claim-type-classification.js +2 -2
  70. package/dist/extensions/pipelines/base/stages/claim-type-classification.js.map +1 -0
  71. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/conclusion-selection.d.ts +21 -3
  72. package/dist/extensions/pipelines/base/stages/conclusion-selection.d.ts.map +1 -0
  73. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/conclusion-selection.js +8 -2
  74. package/dist/extensions/pipelines/base/stages/conclusion-selection.js.map +1 -0
  75. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/formula-compilation.d.ts +1 -1
  76. package/dist/extensions/pipelines/base/stages/formula-compilation.d.ts.map +1 -0
  77. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/formula-compilation.js +1 -1
  78. package/dist/extensions/pipelines/base/stages/formula-compilation.js.map +1 -0
  79. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/formula-validation.d.ts +1 -1
  80. package/dist/extensions/pipelines/base/stages/formula-validation.d.ts.map +1 -0
  81. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/formula-validation.js +2 -2
  82. package/dist/extensions/pipelines/base/stages/formula-validation.js.map +1 -0
  83. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/index.d.ts +2 -2
  84. package/dist/extensions/pipelines/base/stages/index.d.ts.map +1 -0
  85. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/index.js +5 -3
  86. package/dist/extensions/pipelines/base/stages/index.js.map +1 -0
  87. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/relation-extraction.d.ts +2 -2
  88. package/dist/extensions/pipelines/base/stages/relation-extraction.d.ts.map +1 -0
  89. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/relation-extraction.js +1 -1
  90. package/dist/extensions/pipelines/base/stages/relation-extraction.js.map +1 -0
  91. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/schemas.d.ts +2 -0
  92. package/dist/extensions/pipelines/base/stages/schemas.d.ts.map +1 -0
  93. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/schemas.js +8 -0
  94. package/dist/extensions/pipelines/base/stages/schemas.js.map +1 -0
  95. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/segmentation.d.ts +2 -2
  96. package/dist/extensions/pipelines/base/stages/segmentation.d.ts.map +1 -0
  97. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/segmentation.js +2 -2
  98. package/dist/extensions/pipelines/base/stages/segmentation.js.map +1 -0
  99. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/variable-assignment.d.ts +1 -1
  100. package/dist/extensions/pipelines/base/stages/variable-assignment.d.ts.map +1 -0
  101. package/dist/extensions/{argument-ingestion → pipelines/base}/stages/variable-assignment.js +1 -1
  102. package/dist/extensions/pipelines/base/stages/variable-assignment.js.map +1 -0
  103. package/dist/extensions/{argument-ingestion/shared → pipelines/base}/types.d.ts +6 -5
  104. package/dist/extensions/pipelines/base/types.d.ts.map +1 -0
  105. package/dist/extensions/pipelines/base/types.js +15 -0
  106. package/dist/extensions/pipelines/base/types.js.map +1 -0
  107. package/dist/extensions/pipelines/ingestion/index.d.ts +5 -0
  108. package/dist/extensions/pipelines/ingestion/index.d.ts.map +1 -0
  109. package/dist/extensions/pipelines/ingestion/index.js +5 -0
  110. package/dist/extensions/pipelines/ingestion/index.js.map +1 -0
  111. package/dist/extensions/pipelines/ingestion/scholar/index.d.ts +3 -0
  112. package/dist/extensions/pipelines/ingestion/scholar/index.d.ts.map +1 -0
  113. package/dist/extensions/pipelines/ingestion/scholar/index.js +3 -0
  114. package/dist/extensions/pipelines/ingestion/scholar/index.js.map +1 -0
  115. package/dist/extensions/pipelines/ingestion/scholar/scholar.d.ts +48 -0
  116. package/dist/extensions/pipelines/ingestion/scholar/scholar.d.ts.map +1 -0
  117. package/dist/extensions/{argument-ingestion/v2-multi-stage.js → pipelines/ingestion/scholar/scholar.js} +25 -18
  118. package/dist/extensions/pipelines/ingestion/scholar/scholar.js.map +1 -0
  119. package/dist/extensions/pipelines/ingestion/scribe/extract-stage.d.ts +33 -0
  120. package/dist/extensions/pipelines/ingestion/scribe/extract-stage.d.ts.map +1 -0
  121. package/dist/extensions/pipelines/ingestion/scribe/extract-stage.js +103 -0
  122. package/dist/extensions/pipelines/ingestion/scribe/extract-stage.js.map +1 -0
  123. package/dist/extensions/pipelines/ingestion/scribe/index.d.ts +3 -0
  124. package/dist/extensions/pipelines/ingestion/scribe/index.d.ts.map +1 -0
  125. package/dist/extensions/pipelines/ingestion/scribe/index.js +3 -0
  126. package/dist/extensions/pipelines/ingestion/scribe/index.js.map +1 -0
  127. package/dist/extensions/pipelines/ingestion/scribe/schemas.d.ts +17 -0
  128. package/dist/extensions/pipelines/ingestion/scribe/schemas.d.ts.map +1 -0
  129. package/dist/extensions/pipelines/ingestion/scribe/schemas.js +26 -0
  130. package/dist/extensions/pipelines/ingestion/scribe/schemas.js.map +1 -0
  131. package/dist/extensions/pipelines/ingestion/scribe/scribe.d.ts +20 -0
  132. package/dist/extensions/pipelines/ingestion/scribe/scribe.d.ts.map +1 -0
  133. package/dist/extensions/pipelines/ingestion/scribe/scribe.js +81 -0
  134. package/dist/extensions/pipelines/ingestion/scribe/scribe.js.map +1 -0
  135. package/dist/extensions/pipelines/ingestion/scribe/structure-stage.d.ts +30 -0
  136. package/dist/extensions/pipelines/ingestion/scribe/structure-stage.d.ts.map +1 -0
  137. package/dist/extensions/pipelines/ingestion/scribe/structure-stage.js +142 -0
  138. package/dist/extensions/pipelines/ingestion/scribe/structure-stage.js.map +1 -0
  139. package/dist/lib/index.d.ts +0 -2
  140. package/dist/lib/index.d.ts.map +1 -1
  141. package/dist/lib/index.js +7 -5
  142. package/dist/lib/index.js.map +1 -1
  143. package/dist/lib/pipelines/debug-log.js +1 -1
  144. package/dist/lib/pipelines/debug-log.js.map +1 -1
  145. package/dist/lib/pipelines/stage-helpers.d.ts.map +1 -1
  146. package/dist/lib/pipelines/stage-helpers.js +37 -1
  147. package/dist/lib/pipelines/stage-helpers.js.map +1 -1
  148. package/dist/lib/pipelines/types.d.ts +2 -2
  149. package/package.json +16 -16
  150. package/dist/extensions/argument-ingestion/index.d.ts +0 -15
  151. package/dist/extensions/argument-ingestion/index.d.ts.map +0 -1
  152. package/dist/extensions/argument-ingestion/index.js +0 -17
  153. package/dist/extensions/argument-ingestion/index.js.map +0 -1
  154. package/dist/extensions/argument-ingestion/shared/basics-extension.d.ts.map +0 -1
  155. package/dist/extensions/argument-ingestion/shared/basics-extension.js.map +0 -1
  156. package/dist/extensions/argument-ingestion/shared/finalize-response-v2.d.ts.map +0 -1
  157. package/dist/extensions/argument-ingestion/shared/finalize-response-v2.js.map +0 -1
  158. package/dist/extensions/argument-ingestion/shared/finalize-response.d.ts +0 -21
  159. package/dist/extensions/argument-ingestion/shared/finalize-response.d.ts.map +0 -1
  160. package/dist/extensions/argument-ingestion/shared/finalize-response.js +0 -33
  161. package/dist/extensions/argument-ingestion/shared/finalize-response.js.map +0 -1
  162. package/dist/extensions/argument-ingestion/shared/resolve-llm-stage-options.d.ts.map +0 -1
  163. package/dist/extensions/argument-ingestion/shared/resolve-llm-stage-options.js.map +0 -1
  164. package/dist/extensions/argument-ingestion/shared/role-derivation.d.ts.map +0 -1
  165. package/dist/extensions/argument-ingestion/shared/role-derivation.js.map +0 -1
  166. package/dist/extensions/argument-ingestion/shared/types.d.ts.map +0 -1
  167. package/dist/extensions/argument-ingestion/shared/types.js +0 -16
  168. package/dist/extensions/argument-ingestion/shared/types.js.map +0 -1
  169. package/dist/extensions/argument-ingestion/stages/axiom-indicator-detection.d.ts.map +0 -1
  170. package/dist/extensions/argument-ingestion/stages/axiom-indicator-detection.js.map +0 -1
  171. package/dist/extensions/argument-ingestion/stages/citation-source-detection.d.ts.map +0 -1
  172. package/dist/extensions/argument-ingestion/stages/citation-source-detection.js.map +0 -1
  173. package/dist/extensions/argument-ingestion/stages/claim-canonicalization.d.ts.map +0 -1
  174. package/dist/extensions/argument-ingestion/stages/claim-canonicalization.js.map +0 -1
  175. package/dist/extensions/argument-ingestion/stages/claim-mention-extraction.d.ts.map +0 -1
  176. package/dist/extensions/argument-ingestion/stages/claim-mention-extraction.js.map +0 -1
  177. package/dist/extensions/argument-ingestion/stages/claim-reference-validation.d.ts.map +0 -1
  178. package/dist/extensions/argument-ingestion/stages/claim-reference-validation.js.map +0 -1
  179. package/dist/extensions/argument-ingestion/stages/claim-type-classification.d.ts.map +0 -1
  180. package/dist/extensions/argument-ingestion/stages/claim-type-classification.js.map +0 -1
  181. package/dist/extensions/argument-ingestion/stages/conclusion-selection.d.ts.map +0 -1
  182. package/dist/extensions/argument-ingestion/stages/conclusion-selection.js.map +0 -1
  183. package/dist/extensions/argument-ingestion/stages/formula-compilation.d.ts.map +0 -1
  184. package/dist/extensions/argument-ingestion/stages/formula-compilation.js.map +0 -1
  185. package/dist/extensions/argument-ingestion/stages/formula-validation.d.ts.map +0 -1
  186. package/dist/extensions/argument-ingestion/stages/formula-validation.js.map +0 -1
  187. package/dist/extensions/argument-ingestion/stages/index.d.ts.map +0 -1
  188. package/dist/extensions/argument-ingestion/stages/index.js.map +0 -1
  189. package/dist/extensions/argument-ingestion/stages/relation-extraction.d.ts.map +0 -1
  190. package/dist/extensions/argument-ingestion/stages/relation-extraction.js.map +0 -1
  191. package/dist/extensions/argument-ingestion/stages/schemas.d.ts.map +0 -1
  192. package/dist/extensions/argument-ingestion/stages/schemas.js.map +0 -1
  193. package/dist/extensions/argument-ingestion/stages/segmentation.d.ts.map +0 -1
  194. package/dist/extensions/argument-ingestion/stages/segmentation.js.map +0 -1
  195. package/dist/extensions/argument-ingestion/stages/variable-assignment.d.ts.map +0 -1
  196. package/dist/extensions/argument-ingestion/stages/variable-assignment.js.map +0 -1
  197. package/dist/extensions/argument-ingestion/v1-single-shot.d.ts +0 -26
  198. package/dist/extensions/argument-ingestion/v1-single-shot.d.ts.map +0 -1
  199. package/dist/extensions/argument-ingestion/v1-single-shot.js +0 -113
  200. package/dist/extensions/argument-ingestion/v1-single-shot.js.map +0 -1
  201. package/dist/extensions/argument-ingestion/v2-multi-stage.d.ts +0 -38
  202. package/dist/extensions/argument-ingestion/v2-multi-stage.d.ts.map +0 -1
  203. package/dist/extensions/argument-ingestion/v2-multi-stage.js.map +0 -1
  204. package/dist/extensions/ollama/errors.d.ts +0 -73
  205. package/dist/extensions/ollama/errors.d.ts.map +0 -1
  206. package/dist/extensions/ollama/errors.js +0 -228
  207. package/dist/extensions/ollama/errors.js.map +0 -1
  208. package/dist/extensions/ollama/index.d.ts +0 -6
  209. package/dist/extensions/ollama/index.d.ts.map +0 -1
  210. package/dist/extensions/ollama/index.js +0 -17
  211. package/dist/extensions/ollama/index.js.map +0 -1
  212. package/dist/extensions/ollama/provider.d.ts +0 -22
  213. package/dist/extensions/ollama/provider.d.ts.map +0 -1
  214. package/dist/extensions/ollama/provider.js +0 -417
  215. package/dist/extensions/ollama/provider.js.map +0 -1
  216. package/dist/extensions/ollama/structured-output.d.ts +0 -18
  217. package/dist/extensions/ollama/structured-output.d.ts.map +0 -1
  218. package/dist/extensions/ollama/structured-output.js.map +0 -1
  219. package/dist/extensions/ollama/timeout-fetch.d.ts +0 -24
  220. package/dist/extensions/ollama/timeout-fetch.d.ts.map +0 -1
  221. package/dist/extensions/ollama/timeout-fetch.js +0 -76
  222. package/dist/extensions/ollama/timeout-fetch.js.map +0 -1
  223. package/dist/extensions/ollama/types.d.ts +0 -219
  224. package/dist/extensions/ollama/types.d.ts.map +0 -1
  225. package/dist/extensions/ollama/types.js +0 -7
  226. package/dist/extensions/ollama/types.js.map +0 -1
  227. /package/dist/extensions/{argument-ingestion/shared → pipelines/base}/finalize-response-v2.d.ts +0 -0
  228. /package/dist/extensions/{argument-ingestion/shared → pipelines/base}/resolve-llm-stage-options.d.ts +0 -0
  229. /package/dist/extensions/{argument-ingestion/shared → pipelines/base}/role-derivation.d.ts +0 -0
  230. /package/dist/extensions/{argument-ingestion/shared → pipelines/base}/role-derivation.js +0 -0
@@ -1,417 +0,0 @@
1
- // Concrete `TLlmProvider` backed by a local Ollama daemon via the
2
- // official `ollama` npm SDK.
3
- //
4
- // Dev/test only — production stays on OpenAI. The provider exists so a
5
- // developer can run the entire LLM-backed stack (notably the v2
6
- // argument-ingestion pipeline) against a self-hosted model
7
- // (`qwen3.6:latest`) with zero API cost.
8
- //
9
- // Deliberate divergences from the in-repo OpenAI provider:
10
- // * Uses the official `ollama` SDK (an optional peer) rather than raw
11
- // `fetch`. A missing package surfaces as an actionable error at
12
- // construction time (dynamic-import-or-throw).
13
- // * Structured output goes through the Ollama provider's own
14
- // standard-JSON-schema converter (`./structured-output.ts`), not
15
- // the OpenAI strict-mode converter.
16
- // * `reasoningEffort` is ignored (no Ollama analogue);
17
- // `maxOutputTokens` maps to `options.num_predict` (positive values
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`.
37
- // * Errors are classified by `./errors.ts` #classifyOllamaError, which
38
- // carries the same `retryReason` tags + lib failure-codes as the
39
- // OpenAI provider. No `ollama → openai` dependency, no lib change.
40
- //
41
- // `AbortSignal` is honored by registering an abort listener that calls
42
- // the SDK client's `abort()`; the SDK then rejects the in-flight
43
- // `chat()` with an `AbortError`, which the provider re-throws verbatim
44
- // so `llmStage`'s mid-flight-abort detector marks the stage `skipped`.
45
- import { debugLlmFailure, debugLlmRequest, debugLlmResponse, } from "../../lib/pipelines/debug-log.js";
46
- import { typeboxToJsonSchema } from "./structured-output.js";
47
- import { buildTimeoutFetch } from "./timeout-fetch.js";
48
- import { NonRetryableLlmError, SchemaValidationLlmError, ToolLoopExhaustedError, classifyOllamaError, } from "./errors.js";
49
- const STAGE_ID_MARKER = /<!--\s*stage-id:\s*([^\s>]+)\s*-->/;
50
- const DEFAULT_BASE_URL = "http://localhost:11434";
51
- const DEFAULT_MAX_TOOL_ROUNDS = 6;
52
- // Generous default context window. Ollama silently truncates prompts
53
- // longer than `num_ctx` (no error — the model emits schema-valid JSON
54
- // from a truncated prompt), and its per-model default is often ~4096,
55
- // well under a real multi-KB ingestion prompt. See `TOllamaProviderConfig.numCtx`.
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;
63
- export class OllamaProvider {
64
- config;
65
- clientPromise = null;
66
- maxToolRounds;
67
- numCtx;
68
- requestTimeoutMs;
69
- stream;
70
- think;
71
- constructor(config) {
72
- this.config = config ?? {};
73
- this.maxToolRounds =
74
- this.config.maxToolCallRounds ?? DEFAULT_MAX_TOOL_ROUNDS;
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;
83
- }
84
- async respond(req) {
85
- // Already-aborted short-circuit — don't even construct the
86
- // client or call the daemon.
87
- if (req.signal?.aborted) {
88
- throw abortError();
89
- }
90
- const client = await this.getClient();
91
- const convertedSchema = typeboxToJsonSchema(req.outputSchema);
92
- const tools = req.tools ? translateTools(req.tools) : undefined;
93
- const stageIdMatch = STAGE_ID_MARKER.exec(req.systemPrompt);
94
- const debugStageId = stageIdMatch ? stageIdMatch[1] : null;
95
- // Wire the AbortSignal to the SDK client's abort(). The SDK
96
- // rejects the in-flight chat() with an AbortError when this
97
- // fires.
98
- const onAbort = () => {
99
- client.abort();
100
- };
101
- req.signal?.addEventListener("abort", onAbort, { once: true });
102
- try {
103
- return await this.runChatLoop({
104
- client,
105
- req,
106
- convertedSchema,
107
- tools,
108
- debugStageId,
109
- });
110
- }
111
- finally {
112
- req.signal?.removeEventListener("abort", onAbort);
113
- }
114
- }
115
- async runChatLoop(args) {
116
- const { client, req, convertedSchema, tools, debugStageId } = args;
117
- // Running message array. Tool-call rounds append the model's
118
- // tool_calls echo + the tool result before re-calling.
119
- const messages = [
120
- { role: "system", content: req.systemPrompt },
121
- { role: "user", content: req.userMessage },
122
- ];
123
- let lastUsage = { input: 0, output: 0 };
124
- for (let round = 0; round < this.maxToolRounds; round += 1) {
125
- const chatRequest = {
126
- model: req.model,
127
- messages,
128
- // Build `format` from the single converted object so the
129
- // schema can't drift from any prompt-grounding copy.
130
- format: convertedSchema,
131
- stream: this.stream,
132
- };
133
- if (tools) {
134
- chatRequest.tools = tools;
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
- }
144
- // `temperature: 0` for deterministic structured output;
145
- // `num_ctx` set generously so Ollama doesn't silently
146
- // truncate a real multi-KB ingestion prompt (its per-model
147
- // default is often ~4096). `maxOutputTokens` → num_predict,
148
- // positive only: 0 means "generate nothing"; -1/-2 are Ollama
149
- // sentinels we never emit.
150
- const options = {
151
- temperature: 0,
152
- num_ctx: this.numCtx,
153
- };
154
- if (req.maxOutputTokens !== undefined && req.maxOutputTokens > 0) {
155
- options.num_predict = req.maxOutputTokens;
156
- }
157
- chatRequest.options = options;
158
- debugLlmRequest({
159
- stageId: debugStageId,
160
- model: req.model,
161
- maxOutputTokens: req.maxOutputTokens,
162
- reasoningEffort: req.reasoningEffort,
163
- systemPromptLen: req.systemPrompt.length,
164
- userMessageLen: req.userMessage.length,
165
- systemPromptHead: req.systemPrompt,
166
- userMessageHead: req.userMessage,
167
- });
168
- let response;
169
- try {
170
- const raw = await client.chat(chatRequest);
171
- response = isAsyncIterable(raw) ? await collectStream(raw) : raw;
172
- }
173
- catch (err) {
174
- // Mid-flight abort: the SDK rejects with an AbortError
175
- // when our signal listener called client.abort().
176
- // Re-throw verbatim so llmStage marks the stage skipped.
177
- if (isAbortError(err) || req.signal?.aborted) {
178
- throw abortError();
179
- }
180
- const classified = classifyOllamaError(err);
181
- debugLlmFailure({
182
- stageId: debugStageId,
183
- model: req.model,
184
- errorName: classified.name,
185
- errorMessage: classified.message,
186
- tokenUsage: lastUsage,
187
- });
188
- throw classified;
189
- }
190
- lastUsage = mergeUsage(lastUsage, {
191
- input: response.prompt_eval_count ?? 0,
192
- output: response.eval_count ?? 0,
193
- });
194
- const toolCalls = response.message.tool_calls ?? [];
195
- if (toolCalls.length > 0) {
196
- // Echo the assistant tool-call message, then append one
197
- // tool-result message per call before looping.
198
- messages.push({
199
- role: "assistant",
200
- content: response.message.content,
201
- tool_calls: toolCalls,
202
- });
203
- for (const call of toolCalls) {
204
- const handler = findFunctionHandler(req.tools, call.function.name);
205
- if (!handler) {
206
- throw new NonRetryableLlmError({
207
- message: `Ollama requested unknown function tool "${call.function.name}".`,
208
- });
209
- }
210
- const handlerResult = await handler.handler(call.function.arguments);
211
- messages.push({
212
- role: "tool",
213
- content: typeof handlerResult === "string"
214
- ? handlerResult
215
- : JSON.stringify(handlerResult),
216
- });
217
- }
218
- continue;
219
- }
220
- const text = response.message.content;
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
- }
237
- throw new SchemaValidationLlmError({
238
- message: "Ollama chat response carried no assistant text content.",
239
- });
240
- }
241
- const parsed = safeParseJson(text);
242
- debugLlmResponse({
243
- stageId: debugStageId,
244
- outputTextLen: text.length,
245
- tokenUsage: lastUsage,
246
- });
247
- return {
248
- output: parsed,
249
- tokenUsage: lastUsage,
250
- // The Ollama chat response is not request-id-bearing;
251
- // `rawResponseId` is optional, so leaving it undefined is
252
- // contract-legal. Do not fabricate one.
253
- rawResponseId: undefined,
254
- };
255
- }
256
- throw new ToolLoopExhaustedError({
257
- message: `Function-tool agent loop exceeded ${this.maxToolRounds.toString()} rounds without a final response.`,
258
- rounds: this.maxToolRounds,
259
- });
260
- }
261
- /**
262
- * Resolve the SDK client: the injected one, or a freshly imported
263
- * `Ollama` instance. Memoized so the dynamic import + construction
264
- * runs at most once.
265
- */
266
- getClient() {
267
- if (this.config.client) {
268
- return Promise.resolve(this.config.client);
269
- }
270
- this.clientPromise ??= this.importAndConstructClient();
271
- return this.clientPromise;
272
- }
273
- async importAndConstructClient() {
274
- const baseUrl = this.config.baseUrl ?? DEFAULT_BASE_URL;
275
- const importOllama = this.config.importOllama ??
276
- (() => import("ollama"));
277
- let mod;
278
- try {
279
- mod = await importOllama();
280
- }
281
- catch (err) {
282
- throw new Error("OllamaProvider: the optional `ollama` package is not installed. " +
283
- "Run `pnpm add ollama` (it is declared as an optional peerDependency) " +
284
- "or pass a pre-built `client` via the provider config. " +
285
- `Original import error: ${err instanceof Error ? err.message : String(err)}`);
286
- }
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);
298
- }
299
- }
300
- // -- helpers --------------------------------------------------------------
301
- function abortError() {
302
- const e = new Error("The Ollama request was aborted.");
303
- e.name = "AbortError";
304
- return e;
305
- }
306
- function isAbortError(err) {
307
- return (typeof err === "object" &&
308
- err !== null &&
309
- err.name === "AbortError");
310
- }
311
- function safeParseJson(raw) {
312
- try {
313
- return JSON.parse(raw);
314
- }
315
- catch (err) {
316
- throw new SchemaValidationLlmError({
317
- message: `Ollama returned malformed JSON in structured-output content: ${err instanceof Error ? err.message : String(err)}`,
318
- });
319
- }
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
- }
382
- function mergeUsage(accumulated, next) {
383
- return {
384
- input: accumulated.input + next.input,
385
- output: accumulated.output + next.output,
386
- };
387
- }
388
- function translateTools(tools) {
389
- return tools.map((tool) => {
390
- if (tool.kind === "function") {
391
- return {
392
- type: "function",
393
- function: {
394
- name: tool.name,
395
- description: tool.description,
396
- parameters: typeboxToJsonSchema(tool.parameters),
397
- },
398
- };
399
- }
400
- // Hosted-tool kinds (web_search / file_search / mcp) have no
401
- // local Ollama equivalent. Fail fast and legibly.
402
- throw new NonRetryableLlmError({
403
- message: `Tool kind "${tool.kind}" is not supported by the Ollama provider. Only kind "function" (local handler) is supported.`,
404
- });
405
- });
406
- }
407
- function findFunctionHandler(tools, name) {
408
- if (!tools)
409
- return undefined;
410
- for (const tool of tools) {
411
- if (tool.kind === "function" && tool.name === name) {
412
- return tool;
413
- }
414
- }
415
- return undefined;
416
- }
417
- //# sourceMappingURL=provider.js.map
@@ -1 +0,0 @@
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;A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ally typed as a plain object literal
4
- * (not a full JSON-Schema TS type). Ollama's `format` accepts this
5
- * shape and we round-trip it through the SDK request body. Keeping the
6
- * return type loose avoids dragging a JSON-Schema dependency into the
7
- * converter.
8
- */
9
- export type TOllamaJsonSchema = Record<string, unknown>;
10
- /**
11
- * Convert a TypeBox schema into a standard JSON Schema document
12
- * suitable for Ollama's `format` parameter.
13
- *
14
- * Throws `UnsupportedSchemaError` when the source schema contains a
15
- * TypeBox primitive outside the supported subset.
16
- */
17
- export declare function typeboxToJsonSchema(schema: TSchema): TOllamaJsonSchema;
18
- //# sourceMappingURL=structured-output.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"structured-output.d.ts","sourceRoot":"","sources":["../../../src/extensions/ollama/structured-output.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AA6BvD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,iBAAiB,CA0BtE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"structured-output.js","sourceRoot":"","sources":["../../../src/extensions/ollama/structured-output.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,EAAE;AACF,oEAAoE;AACpE,wEAAwE;AACxE,iEAAiE;AACjE,sEAAsE;AACtE,EAAE;AACF,0DAA0D;AAC1D,qEAAqE;AACrE,yDAAyD;AACzD,iEAAiE;AACjE,EAAE;AACF,wEAAwE;AACxE,oEAAoE;AACpE,yDAAyD;AACzD,EAAE;AACF,iEAAiE;AACjE,qEAAqE;AACrE,iEAAiE;AACjE,kEAAkE;AAClE,qDAAqD;AACrD,+CAA+C;AAC/C,EAAE;AACF,uEAAuE;AACvE,yDAAyD;AAazD,MAAM,sBAAuB,SAAQ,KAAK;IACtC,YAAY,IAAY;QACpB,KAAK,CACD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aAAa,CAAC,MAAe;IAClC,MAAM,MAAM,GAAG,MAEd,CAAA;IACD,8CAA8C;IAC9C,gEAAgE;IAChE,+CAA+C;IAC/C,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAA;IACxD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACX,2EAA2E,CAC9E,CAAA;IACL,CAAC;IACD,MAAM,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC/B,OAAO;QACH,IAAI,EAAE,QAAQ;QACd,oBAAoB,EAAE,mBAAmB,CAAC,WAAW,CAAC;KACzD,CAAA;AACL,CAAC"}
@@ -1,24 +0,0 @@
1
- import type { TUndiciModule } from "./types.js";
2
- type TUndiciImporter = () => Promise<TUndiciModule>;
3
- /**
4
- * Build a `fetch`-shaped 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
@@ -1 +0,0 @@
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"}
@@ -1,76 +0,0 @@
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
@@ -1 +0,0 @@
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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