@cerebriline/llms 0.0.0-stage → 4.100.241

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 (204) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +15 -2
  3. package/dist/catalog/catalog-cline-recommended.d.ts +14 -0
  4. package/dist/catalog/catalog-cline-recommended.d.ts.map +1 -0
  5. package/dist/catalog/catalog-live.d.ts +64 -0
  6. package/dist/catalog/catalog-live.d.ts.map +1 -0
  7. package/dist/catalog/catalog.generated-access.d.ts +5 -0
  8. package/dist/catalog/catalog.generated-access.d.ts.map +1 -0
  9. package/dist/catalog/catalog.generated.d.ts +17 -0
  10. package/dist/catalog/catalog.generated.d.ts.map +1 -0
  11. package/dist/catalog/model-filters.d.ts +9 -0
  12. package/dist/catalog/model-filters.d.ts.map +1 -0
  13. package/dist/catalog/model-id-aliases.d.ts +11 -0
  14. package/dist/catalog/model-id-aliases.d.ts.map +1 -0
  15. package/dist/catalog/model-operation.d.ts +27 -0
  16. package/dist/catalog/model-operation.d.ts.map +1 -0
  17. package/dist/catalog/types.d.ts +367 -0
  18. package/dist/catalog/types.d.ts.map +1 -0
  19. package/dist/index.browser.d.ts +12 -0
  20. package/dist/index.browser.d.ts.map +1 -0
  21. package/dist/index.browser.js +16 -0
  22. package/dist/index.d.ts +30 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +272 -0
  25. package/dist/models.d.ts +10 -0
  26. package/dist/models.d.ts.map +1 -0
  27. package/dist/models.js +241 -0
  28. package/dist/providers/agent-slots.d.ts +100 -0
  29. package/dist/providers/agent-slots.d.ts.map +1 -0
  30. package/dist/providers/ai-sdk.d.ts +158 -0
  31. package/dist/providers/ai-sdk.d.ts.map +1 -0
  32. package/dist/providers/async.d.ts +2 -0
  33. package/dist/providers/async.d.ts.map +1 -0
  34. package/dist/providers/billing.d.ts +5 -0
  35. package/dist/providers/billing.d.ts.map +1 -0
  36. package/dist/providers/builtin-types.d.ts +34 -0
  37. package/dist/providers/builtin-types.d.ts.map +1 -0
  38. package/dist/providers/builtins-runtime.d.ts +3 -0
  39. package/dist/providers/builtins-runtime.d.ts.map +1 -0
  40. package/dist/providers/builtins.d.ts +30 -0
  41. package/dist/providers/builtins.d.ts.map +1 -0
  42. package/dist/providers/compat.d.ts +75 -0
  43. package/dist/providers/compat.d.ts.map +1 -0
  44. package/dist/providers/config.d.ts +521 -0
  45. package/dist/providers/config.d.ts.map +1 -0
  46. package/dist/providers/error-classification.d.ts +23 -0
  47. package/dist/providers/error-classification.d.ts.map +1 -0
  48. package/dist/providers/errors.d.ts +33 -0
  49. package/dist/providers/errors.d.ts.map +1 -0
  50. package/dist/providers/factory-registry.d.ts +92 -0
  51. package/dist/providers/factory-registry.d.ts.map +1 -0
  52. package/dist/providers/format.d.ts +2 -0
  53. package/dist/providers/format.d.ts.map +1 -0
  54. package/dist/providers/gateway.d.ts +123 -0
  55. package/dist/providers/gateway.d.ts.map +1 -0
  56. package/dist/providers/handler.d.ts +75 -0
  57. package/dist/providers/handler.d.ts.map +1 -0
  58. package/dist/providers/http.d.ts +10 -0
  59. package/dist/providers/http.d.ts.map +1 -0
  60. package/dist/providers/ids.d.ts +77 -0
  61. package/dist/providers/ids.d.ts.map +1 -0
  62. package/dist/providers/messages.d.ts +5 -0
  63. package/dist/providers/messages.d.ts.map +1 -0
  64. package/dist/providers/middleware/backoff.d.ts +11 -0
  65. package/dist/providers/middleware/backoff.d.ts.map +1 -0
  66. package/dist/providers/middleware/retry-empty-response.d.ts +74 -0
  67. package/dist/providers/middleware/retry-empty-response.d.ts.map +1 -0
  68. package/dist/providers/middleware/retry-rate-limit.d.ts +49 -0
  69. package/dist/providers/middleware/retry-rate-limit.d.ts.map +1 -0
  70. package/dist/providers/middleware/split-tool-images.d.ts +32 -0
  71. package/dist/providers/middleware/split-tool-images.d.ts.map +1 -0
  72. package/dist/providers/middleware/stream-part-classification.d.ts +33 -0
  73. package/dist/providers/middleware/stream-part-classification.d.ts.map +1 -0
  74. package/dist/providers/model-capabilities.d.ts +15 -0
  75. package/dist/providers/model-capabilities.d.ts.map +1 -0
  76. package/dist/providers/model-facts.d.ts +115 -0
  77. package/dist/providers/model-facts.d.ts.map +1 -0
  78. package/dist/providers/model-operations.d.ts +78 -0
  79. package/dist/providers/model-operations.d.ts.map +1 -0
  80. package/dist/providers/model-registry.d.ts +25 -0
  81. package/dist/providers/model-registry.d.ts.map +1 -0
  82. package/dist/providers/model-tools.d.ts +22 -0
  83. package/dist/providers/model-tools.d.ts.map +1 -0
  84. package/dist/providers/openai-codex-models.d.ts +11 -0
  85. package/dist/providers/openai-codex-models.d.ts.map +1 -0
  86. package/dist/providers/provider-ids.generated.d.ts +13 -0
  87. package/dist/providers/provider-ids.generated.d.ts.map +1 -0
  88. package/dist/providers/provider-keys.d.ts +13 -0
  89. package/dist/providers/provider-keys.d.ts.map +1 -0
  90. package/dist/providers/provider-request-capture.d.ts +10 -0
  91. package/dist/providers/provider-request-capture.d.ts.map +1 -0
  92. package/dist/providers/providers.generated.d.ts +19 -0
  93. package/dist/providers/providers.generated.d.ts.map +1 -0
  94. package/dist/providers/reasoning-history.d.ts +140 -0
  95. package/dist/providers/reasoning-history.d.ts.map +1 -0
  96. package/dist/providers/registry.d.ts +19 -0
  97. package/dist/providers/registry.d.ts.map +1 -0
  98. package/dist/providers/request-headers.d.ts +30 -0
  99. package/dist/providers/request-headers.d.ts.map +1 -0
  100. package/dist/providers/request-timings.d.ts +20 -0
  101. package/dist/providers/request-timings.d.ts.map +1 -0
  102. package/dist/providers/routing/anthropic-compatible.d.ts +35 -0
  103. package/dist/providers/routing/anthropic-compatible.d.ts.map +1 -0
  104. package/dist/providers/routing/bedrock-cache-point.d.ts +26 -0
  105. package/dist/providers/routing/bedrock-cache-point.d.ts.map +1 -0
  106. package/dist/providers/routing/generic-compatible.d.ts +10 -0
  107. package/dist/providers/routing/generic-compatible.d.ts.map +1 -0
  108. package/dist/providers/routing/glm-thinking.d.ts +16 -0
  109. package/dist/providers/routing/glm-thinking.d.ts.map +1 -0
  110. package/dist/providers/routing/minimax-thinking.d.ts +6 -0
  111. package/dist/providers/routing/minimax-thinking.d.ts.map +1 -0
  112. package/dist/providers/routing/portable-reasoning.d.ts +11 -0
  113. package/dist/providers/routing/portable-reasoning.d.ts.map +1 -0
  114. package/dist/providers/routing/provider-option-rules.d.ts +13 -0
  115. package/dist/providers/routing/provider-option-rules.d.ts.map +1 -0
  116. package/dist/providers/routing/provider-options-types.d.ts +57 -0
  117. package/dist/providers/routing/provider-options-types.d.ts.map +1 -0
  118. package/dist/providers/routing/provider-options.d.ts +27 -0
  119. package/dist/providers/routing/provider-options.d.ts.map +1 -0
  120. package/dist/providers/routing/reasoning-codecs.d.ts +4 -0
  121. package/dist/providers/routing/reasoning-codecs.d.ts.map +1 -0
  122. package/dist/providers/routing/reasoning-options.d.ts +8 -0
  123. package/dist/providers/routing/reasoning-options.d.ts.map +1 -0
  124. package/dist/providers/routing/utils.d.ts +31 -0
  125. package/dist/providers/routing/utils.d.ts.map +1 -0
  126. package/dist/providers/sdk-warnings.d.ts +14 -0
  127. package/dist/providers/sdk-warnings.d.ts.map +1 -0
  128. package/dist/providers/server-health.d.ts +66 -0
  129. package/dist/providers/server-health.d.ts.map +1 -0
  130. package/dist/providers/stream.d.ts +124 -0
  131. package/dist/providers/stream.d.ts.map +1 -0
  132. package/dist/providers/types.d.ts +10 -0
  133. package/dist/providers/types.d.ts.map +1 -0
  134. package/dist/providers/url.d.ts +3 -0
  135. package/dist/providers/url.d.ts.map +1 -0
  136. package/dist/providers/utils.d.ts +2 -0
  137. package/dist/providers/utils.d.ts.map +1 -0
  138. package/dist/providers/vendors/anthropic.d.ts +4 -0
  139. package/dist/providers/vendors/anthropic.d.ts.map +1 -0
  140. package/dist/providers/vendors/bedrock.d.ts +24 -0
  141. package/dist/providers/vendors/bedrock.d.ts.map +1 -0
  142. package/dist/providers/vendors/cline.d.ts +37 -0
  143. package/dist/providers/vendors/cline.d.ts.map +1 -0
  144. package/dist/providers/vendors/community.d.ts +8 -0
  145. package/dist/providers/vendors/community.d.ts.map +1 -0
  146. package/dist/providers/vendors/google.d.ts +12 -0
  147. package/dist/providers/vendors/google.d.ts.map +1 -0
  148. package/dist/providers/vendors/llamacpp-sampling.d.ts +130 -0
  149. package/dist/providers/vendors/llamacpp-sampling.d.ts.map +1 -0
  150. package/dist/providers/vendors/llamacpp-timings.d.ts +33 -0
  151. package/dist/providers/vendors/llamacpp-timings.d.ts.map +1 -0
  152. package/dist/providers/vendors/minimax-thinking.d.ts +5 -0
  153. package/dist/providers/vendors/minimax-thinking.d.ts.map +1 -0
  154. package/dist/providers/vendors/mistral.d.ts +4 -0
  155. package/dist/providers/vendors/mistral.d.ts.map +1 -0
  156. package/dist/providers/vendors/ollama-account.d.ts +128 -0
  157. package/dist/providers/vendors/ollama-account.d.ts.map +1 -0
  158. package/dist/providers/vendors/ollama-reachability.d.ts +42 -0
  159. package/dist/providers/vendors/ollama-reachability.d.ts.map +1 -0
  160. package/dist/providers/vendors/ollama-stall-watchdog.d.ts +86 -0
  161. package/dist/providers/vendors/ollama-stall-watchdog.d.ts.map +1 -0
  162. package/dist/providers/vendors/ollama-tool-images.d.ts +67 -0
  163. package/dist/providers/vendors/ollama-tool-images.d.ts.map +1 -0
  164. package/dist/providers/vendors/ollama.d.ts +256 -0
  165. package/dist/providers/vendors/ollama.d.ts.map +1 -0
  166. package/dist/providers/vendors/openai-compatible.d.ts +16 -0
  167. package/dist/providers/vendors/openai-compatible.d.ts.map +1 -0
  168. package/dist/providers/vendors/openai.d.ts +4 -0
  169. package/dist/providers/vendors/openai.d.ts.map +1 -0
  170. package/dist/providers/vendors/opencoti-agent-window.d.ts +44 -0
  171. package/dist/providers/vendors/opencoti-agent-window.d.ts.map +1 -0
  172. package/dist/providers/vendors/opencoti-kv-pressure.d.ts +322 -0
  173. package/dist/providers/vendors/opencoti-kv-pressure.d.ts.map +1 -0
  174. package/dist/providers/vendors/opencoti-liveness.d.ts +177 -0
  175. package/dist/providers/vendors/opencoti-liveness.d.ts.map +1 -0
  176. package/dist/providers/vendors/opencoti-window.d.ts +56 -0
  177. package/dist/providers/vendors/opencoti-window.d.ts.map +1 -0
  178. package/dist/providers/vendors/opencoti.d.ts +335 -0
  179. package/dist/providers/vendors/opencoti.d.ts.map +1 -0
  180. package/dist/providers/vendors/polykv-lead.d.ts +94 -0
  181. package/dist/providers/vendors/polykv-lead.d.ts.map +1 -0
  182. package/dist/providers/vendors/polykv-swarm.d.ts +705 -0
  183. package/dist/providers/vendors/polykv-swarm.d.ts.map +1 -0
  184. package/dist/providers/vendors/polykv.d.ts +958 -0
  185. package/dist/providers/vendors/polykv.d.ts.map +1 -0
  186. package/dist/providers/vendors/types.d.ts +176 -0
  187. package/dist/providers/vendors/types.d.ts.map +1 -0
  188. package/dist/providers/vendors/vertex.d.ts +4 -0
  189. package/dist/providers/vendors/vertex.d.ts.map +1 -0
  190. package/dist/providers/vendors/xollama-engine.d.ts +57 -0
  191. package/dist/providers/vendors/xollama-engine.d.ts.map +1 -0
  192. package/dist/providers/vendors/xollama.d.ts +188 -0
  193. package/dist/providers/vendors/xollama.d.ts.map +1 -0
  194. package/dist/providers.browser.d.ts +3 -0
  195. package/dist/providers.browser.d.ts.map +1 -0
  196. package/dist/providers.browser.js +16 -0
  197. package/dist/providers.d.ts +12 -0
  198. package/dist/providers.d.ts.map +1 -0
  199. package/dist/providers.js +272 -0
  200. package/dist/services/langfuse-telemetry.d.ts +19 -0
  201. package/dist/services/langfuse-telemetry.d.ts.map +1 -0
  202. package/dist/transcription.d.ts +53 -0
  203. package/dist/transcription.d.ts.map +1 -0
  204. package/package.json +84 -5
@@ -0,0 +1,335 @@
1
+ import { type GatewayProviderContext, type GatewayResolvedProviderConfig } from "@cerebriline/shared";
2
+ import type { PolykvOptions } from "../config";
3
+ import { type OpencotiAgentWindow } from "./opencoti-agent-window";
4
+ import { type PolykvSessionState } from "./polykv";
5
+ import { type PolykvWorkerSpec } from "./polykv-swarm";
6
+ import type { ProviderFactoryResult } from "./types";
7
+ /**
8
+ * opencoti-llamafile: llama.cpp's wire format with a KV control plane attached.
9
+ *
10
+ * The chat endpoint is OpenAI-compatible, so most of this is the compatible
11
+ * provider. What is not: two body extras, `pool_id` and `session_id`, which
12
+ * attach the request to a pinned prefix already resident on the server instead
13
+ * of re-sending it. That is the whole point of routing through this vendor
14
+ * rather than the generic one -- see `polykv.ts` for the tree those ids name.
15
+ *
16
+ * The engine also answers `429`/`503` with `Retry-After` when a pool is
17
+ * saturated. Left as a bare HTTP error that reads as a network fault, which is
18
+ * how the equivalent condition presented on the Ollama path: a stall that was
19
+ * really the server declining to admit more work.
20
+ */
21
+ export interface OpencotiRequestOptions {
22
+ /** Pool to attach this request to. Absent means an unpooled request. */
23
+ poolId?: string;
24
+ /**
25
+ * Session identity, stable across the turns of one conversation.
26
+ *
27
+ * The engine keys per-session tps, slot affinity and admission on it, and
28
+ * treats a known session as a continuation rather than a new admission --
29
+ * so a stable id is what keeps a long conversation from being gated
30
+ * mid-run.
31
+ */
32
+ sessionId?: string;
33
+ /**
34
+ * Explicit shared-prefix length. Optional by design: the server computes
35
+ * the longest hash-match itself (auto-P), which is what removed the
36
+ * mis-set-P footgun. Send it only when it is known to be right.
37
+ */
38
+ sharedPrefixTokens?: number;
39
+ /** Bypass admission for this request, explicitly and visibly. */
40
+ overcommit?: boolean;
41
+ /**
42
+ * Attach a lead conversation to the server-wide lead tree
43
+ * (`polykv-lead.ts`). Only requests whose system turn carries environment
44
+ * spans are a lead's; the rest ignore it.
45
+ */
46
+ leadPool?: boolean;
47
+ /** "Keep the prefix resident": see `prepareLeadPool`'s `pinPrefix`. */
48
+ pinPrefix?: boolean;
49
+ /**
50
+ * The context window to book, in tokens.
51
+ *
52
+ * Sent only when the user stated one. A guaranteed allocation is booked
53
+ * whole at admission and held for the session's life, so this is the number
54
+ * the conversation is sized against for as long as it lives.
55
+ *
56
+ * On a CONTINUATION -- a turn on a session the server already holds -- it is
57
+ * ignored rather than re-booked. You keep the window you were granted, and
58
+ * `X-Context-Window` reports that one, so a changed value here must be
59
+ * checked against what comes back rather than assumed to have taken.
60
+ */
61
+ numCtx?: number;
62
+ /**
63
+ * The floor below which a window is worse than no connection.
64
+ *
65
+ * The server settles this against `numCtx` in ONE admission: the largest
66
+ * window in the band, or a 429 naming `largest_admissible`. That matters
67
+ * beyond tidiness -- the client-side equivalent is to read
68
+ * `largest_admissible` off a refusal and retry at it, and another arrival
69
+ * can take those cells in the gap between the read and the retry. A single
70
+ * request has no gap to lose.
71
+ *
72
+ * On a RESUME, send it equal to `numCtx`: "the window I had, or refuse".
73
+ * A resumed conversation may never negotiate down, because its history no
74
+ * longer fits a smaller window and a silent shrink truncates mid-thread.
75
+ *
76
+ * Sent only where `/props` advertises `ctx_min_negotiation_v1`. Without it
77
+ * the fetch keeps the floor to itself and falls back to retrying ONCE at
78
+ * the refusal's `largest_admissible`, when that is at or above the floor.
79
+ */
80
+ numCtxMin?: number;
81
+ /**
82
+ * The floor the session declared, kept apart from {@link numCtxMin}: a
83
+ * resume sends its grant as `num_ctx_min`, and the floor it declared is
84
+ * then what a pressure resize may shrink it to (`kv_resize_v1`). The
85
+ * profile's `contextFloor`; an agent's is measured off the body instead.
86
+ */
87
+ windowFloor?: number;
88
+ /**
89
+ * This session has been granted a window before: every admission from here
90
+ * on is "exactly that window, or refuse". A resume never negotiates down
91
+ * and never waits -- a refusal is the "Can't resume" card at once.
92
+ */
93
+ resume?: boolean;
94
+ /**
95
+ * The longest a NEW session below its floor waits, once, before it is
96
+ * refused. The profile's `maxRetryAfterMs`, the same bound the rate-limit
97
+ * middleware honours; the server's `Retry-After` inside it.
98
+ */
99
+ maxRetryAfterMs?: number;
100
+ /**
101
+ * The output cap a worker declares when the request carries none (P2).
102
+ *
103
+ * A worker is charged to its owner's window, and the engine can refuse it
104
+ * at arrival -- before a prefill is spent -- only if it knows how much the
105
+ * reply may take. The gateway sends no cap for a model the catalog knows
106
+ * nothing about, or when its estimate leaves no room, so this is the
107
+ * fallback that makes "workers always declare" true on the wire.
108
+ */
109
+ workerMaxTokens?: number;
110
+ /**
111
+ * This request is one agent of a swarm sharing a pool tree.
112
+ *
113
+ * Replaces `poolId` and `sessionId`: the pool is the deepest layer of the
114
+ * tree its own messages match, and the session is the agent's own. A worker
115
+ * books no window of its own -- the owner's is charged -- so `numCtx` is not
116
+ * sent either. See `polykv-swarm.ts`.
117
+ */
118
+ worker?: PolykvWorkerSpec;
119
+ /**
120
+ * This request is a delegated agent's on a node with an "Agent window"
121
+ * share: the floor (`num_ctx_min`) is that share between the minimum the
122
+ * request itself needs and the node's window, and is measured off the body
123
+ * at send time. A per-agent session asks for the node's window with it; a
124
+ * swarm worker hands it to the owner it opens, and to the session it books
125
+ * when it falls back to running unpooled. See `opencoti-agent-window.ts`.
126
+ */
127
+ agentWindow?: OpencotiAgentWindow;
128
+ /**
129
+ * `numCtx` is one compaction call's exact booking, not the session's
130
+ * window: the grant that comes back is not recorded, no floor is recorded
131
+ * for a pressure resize, and a refusal is not negotiated as a resume.
132
+ */
133
+ transientBooking?: boolean;
134
+ }
135
+ /**
136
+ * What the engine reports back, on the channel it actually uses.
137
+ *
138
+ * Deliberately short, and shorter than it used to be. The previous version read
139
+ * `x-pool-id`, `x-cached-prefix-tokens` and `x-session-tps`, none of which the
140
+ * server sets -- they were specified and then deferred, because headers must be
141
+ * emitted before the body while the slot, and therefore the tps, is only
142
+ * assigned after the task is queued. With all three always absent the callback
143
+ * guarded on them never fired once, so the whole observability path was dead
144
+ * while looking implemented.
145
+ *
146
+ * Whether the pool attached is the fact worth having, and on c7 it is not on
147
+ * the response at all: read `/slots[].opencoti.n_pool_shared`. c8 puts an
148
+ * `opencoti {pool_id, n_pool_shared}` block on the response itself.
149
+ */
150
+ export interface OpencotiResponseFacts {
151
+ /**
152
+ * Sessions the pool can still admit, as the warn arm reports it.
153
+ *
154
+ * Absent means "not computable", which is not zero -- and on c7 a reported
155
+ * `0` may itself be wrong. Neither may be read as saturation.
156
+ */
157
+ sessionsRemaining?: number;
158
+ /**
159
+ * The request outlived its settling hold and was let through on the clock.
160
+ *
161
+ * Worth distinguishing: every other admit is evidence the pool had room, and
162
+ * this one is evidence only that the timer expired.
163
+ */
164
+ settleWaivedMs?: number;
165
+ /**
166
+ * The pool the turn actually ran against, as the server names it.
167
+ *
168
+ * A string, because pool `0` -- the first pool on a fresh server -- is
169
+ * falsy as a number and is dropped by every `if (poolId)` between here and
170
+ * wherever it is used.
171
+ */
172
+ poolId?: string;
173
+ /**
174
+ * Tokens the prefix actually shared with the pool.
175
+ *
176
+ * The number that says whether pooling worked. **`0` with a pool named is a
177
+ * silently degraded attach**, not an absence: the turn succeeds, the answer
178
+ * is right, and the prefix was prefilled from scratch anyway. Nothing else
179
+ * in the client can tell that from a working attach, so it is reported
180
+ * rather than treated as nothing to say. `undefined` is the different fact
181
+ * that the server did not report one.
182
+ */
183
+ poolSharedTokens?: number;
184
+ /**
185
+ * How far the prompt matched the named pool, and the pool's length
186
+ * (`pool_match_in_response_v1`). `match < length` is a pool prompt that
187
+ * diverges from the rendered request: it was built wrong, and shares only
188
+ * the part before the divergence. The server log names the token.
189
+ */
190
+ poolMatchTokens?: number;
191
+ poolLengthTokens?: number;
192
+ /**
193
+ * The named pool does not exist in the process that answered
194
+ * (`pool_unknown_in_response_v1`): the turn ran, reprocessed in full --
195
+ * never refused -- and the id this side holds is stale.
196
+ */
197
+ poolUnknown?: boolean;
198
+ /**
199
+ * The window the server granted, from `X-Context-Window`.
200
+ *
201
+ * **Absent is not "unchanged".** The header rides every admitted response
202
+ * *while the server is in guaranteed mode*, so its absence means the
203
+ * request was not guaranteed -- an `overcommit`, or a server not enforcing
204
+ * -- and the honest reading is "unknown". Treating it as unchanged is a
205
+ * silent lie about the one number the conversation is sized against.
206
+ */
207
+ contextWindow?: number;
208
+ /**
209
+ * The window this request asked for on the wire (`num_ctx`), beside the
210
+ * grant, so "asked X, got Y" is one observation rather than two numbers
211
+ * from two places. Absent when the request asked for none.
212
+ */
213
+ askedWindow?: number;
214
+ }
215
+ /**
216
+ * Add the PolyKV fields to an outgoing chat request, and read the facts back.
217
+ *
218
+ * Done in a fetch wrapper rather than through provider options because the
219
+ * fields belong on the request body root, next to `messages` -- the
220
+ * compatible provider has no route for arbitrary body extras that survives its
221
+ * own serialization.
222
+ */
223
+ export declare function createOpencotiFetch(options: {
224
+ fetch?: typeof fetch;
225
+ dispatcher?: unknown;
226
+ request?: OpencotiRequestOptions;
227
+ onFacts?: (facts: OpencotiResponseFacts) => void;
228
+ /** Server root, for the swarm's control-plane calls and session close. */
229
+ baseUrl?: string;
230
+ headers?: Record<string, string>;
231
+ /** Seam for tests: the one below-floor wait a new session is allowed. */
232
+ sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
233
+ /** Where what the fetch learns and recovers from is logged. */
234
+ log?: OpencotiLog;
235
+ }): typeof fetch;
236
+ /**
237
+ * A pool divergence, worded for the agent's row.
238
+ *
239
+ * `pool_match` is where the two token streams part, so it is also the token
240
+ * the server names in its log ("diverges from the pool prompt at token 4").
241
+ */
242
+ export declare function poolDivergenceNotice(facts: OpencotiResponseFacts): string;
243
+ /** A line for the provider's log. */
244
+ export type OpencotiLog = (message: string, severity: "info" | "warn") => void;
245
+ /**
246
+ * Where a worker's request fields go on the wire.
247
+ *
248
+ * opencoti's chat is OpenAI-compatible and takes them at the top level. An
249
+ * xOllama engine is reached through Ollama's native `/api/chat`, which takes
250
+ * the pool and the window in `placement` and the output cap in
251
+ * `options.num_predict`, and streams NDJSON with no heartbeat to supervise.
252
+ * Everything else a worker does -- the tree, the owners, the waits -- is the
253
+ * engine's business and is the same on both.
254
+ */
255
+ export interface PolykvWireDialect {
256
+ name: "openai" | "ollama";
257
+ setPool(wire: Record<string, unknown>, poolId: number): void;
258
+ poolOf(wire: Record<string, unknown>): number | undefined;
259
+ setWindow(wire: Record<string, unknown>, ask: number, floor?: number): void;
260
+ clearWindow(wire: Record<string, unknown>): void;
261
+ windowOf(wire: Record<string, unknown>): number | undefined;
262
+ declaresOutputCap(wire: Record<string, unknown>): boolean;
263
+ setOutputCap(wire: Record<string, unknown>, cap: number): void;
264
+ /** The engine's SSE heartbeat is ours to ask for and supervise. */
265
+ keepalive: boolean;
266
+ }
267
+ export declare const OPENAI_WIRE_DIALECT: PolykvWireDialect;
268
+ export declare const OLLAMA_WIRE_DIALECT: PolykvWireDialect;
269
+ /**
270
+ * A swarm worker's fetch (see {@link createWorkerFetch}), for a vendor other
271
+ * than opencoti's own: xOllama drives the same engine through its native API.
272
+ */
273
+ export declare function createPolykvWorkerFetch(options: Parameters<typeof createWorkerFetch>[0]): typeof fetch;
274
+ declare function createWorkerFetch(options: {
275
+ fetch?: typeof fetch;
276
+ dispatcher?: unknown;
277
+ worker: PolykvWorkerSpec;
278
+ /** Where the pool and window go on the wire. opencoti's by default. */
279
+ dialect?: PolykvWireDialect;
280
+ baseUrl: string;
281
+ headers?: Record<string, string>;
282
+ onFacts?: (facts: OpencotiResponseFacts) => void;
283
+ workerMaxTokens?: number;
284
+ /** See {@link OpencotiRequestOptions.agentWindow}. */
285
+ agentWindow?: OpencotiAgentWindow;
286
+ log?: OpencotiLog;
287
+ }): typeof fetch;
288
+ /**
289
+ * The PolyKV section this profile configured, if any.
290
+ *
291
+ * Read from the typed field the settings panel writes; the loose
292
+ * `polykv*`-prefixed keys below are the older route and stay readable so a
293
+ * caller that sets them directly is not silently ignored.
294
+ */
295
+ export declare function readPolykvSettings(context: GatewayProviderContext): PolykvOptions | undefined;
296
+ /** Read the per-request PolyKV options a caller put on the provider config. */
297
+ export declare function readOpencotiRequestOptions(context: GatewayProviderContext): OpencotiRequestOptions;
298
+ /** `http://host:8240` and `http://host:8240/v1` both mean the same server. */
299
+ export declare function normalizeOpencotiBaseUrl(baseUrl: string | undefined): string | undefined;
300
+ export declare function createOpencotiProviderModule(config: GatewayResolvedProviderConfig, context: GatewayProviderContext): Promise<ProviderFactoryResult>;
301
+ /**
302
+ * A request continuing its pool (`pool_continue_v1`): only the turns after
303
+ * the pool's stored stream go on the wire. The tools are dropped with the
304
+ * rest of the prefix -- the template renders them into the system turn, which
305
+ * the pool already holds -- and a rendering of them here would sit between
306
+ * the pool and the new turns.
307
+ */
308
+ export declare function continuePoolBody(body: Record<string, unknown>, tail: number): void;
309
+ /**
310
+ * Render a session's own root pool again, with the fields of the request that
311
+ * attaches it, when it was rendered without them.
312
+ *
313
+ * The root is created before any request exists (`ensurePolykvPool`), so it is
314
+ * rendered from the system prompt and tools alone. The request carries the
315
+ * reasoning fields, and on Gemma-4 `reasoning_budget_tokens` decides whether
316
+ * the system turn opens with `<|think|>`: measured on 8244 2026-09-26, the
317
+ * root matched 4 of its 141 tokens and every turn prefilled whole. The lead
318
+ * tree and the swarm already render with `templateFieldsOf`; this is the one
319
+ * root that did not.
320
+ *
321
+ * Returns the new pool id, or `undefined` when the root is already right or
322
+ * could not be rendered -- the request then goes as it was, which is slower
323
+ * and never broken.
324
+ */
325
+ export declare function renderOwnRootWithRequestFields(input: {
326
+ baseUrl: string;
327
+ fetch?: typeof fetch;
328
+ headers?: Record<string, string>;
329
+ sessionId: string;
330
+ state: PolykvSessionState;
331
+ body: Record<string, unknown>;
332
+ log?: OpencotiLog;
333
+ }): Promise<string | undefined>;
334
+ export {};
335
+ //# sourceMappingURL=opencoti.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opencoti.d.ts","sourceRoot":"","sources":["../../../src/providers/vendors/opencoti.ts"],"names":[],"mappings":"AAKA,OAAO,EAEN,KAAK,sBAAsB,EAC3B,KAAK,6BAA6B,EAClC,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAQ/C,OAAO,EAEN,KAAK,mBAAmB,EAExB,MAAM,yBAAyB,CAAC;AAajC,OAAO,EAON,KAAK,kBAAkB,EAOvB,MAAM,UAAU,CAAC;AAOlB,OAAO,EAcN,KAAK,gBA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 export interface LeadAttach {
3
+ poolId: string;
4
+ /** Tokens of the request's prefix the pool holds. */
5
+ sharedTokens: number;
6
+ /**
7
+ * The server counts `num_ctx` as the private budget
8
+ * (`polykv_private_window_v1`): the shared prefix rides above it.
9
+ */
10
+ privateWindow: boolean;
11
+ /**
12
+ * The server generation `poolId` belongs to. A request that goes out after
13
+ * the generation moved must not carry it.
14
+ */
15
+ generation: number;
16
+ }
17
+ /**
18
+ * After this long without a request, check the pools still exist.
19
+ *
20
+ * Well under the engine's idle TTL (300 s on the builds measured): a window
21
+ * that lapses takes every pool its session owned with it, and a request
22
+ * naming a released pool is not refused -- it reprocesses in full, silently.
23
+ */
24
+ export declare const POLYKV_LEAD_RECHECK_MS = 60000;
25
+ /**
26
+ * Lift the environment spans of a request's system turn into a user turn.
27
+ *
28
+ * Mutates `body`. Answers whether the request is a lead conversation's: a
29
+ * system turn carrying spans is only ever built for one.
30
+ */
31
+ export declare function hoistLeadEnvironment(body: Record<string, unknown>): boolean;
32
+ /**
33
+ * The pool this lead request attaches to, creating what it needs.
34
+ *
35
+ * Call after `hoistLeadEnvironment` answered `true`, so the request is
36
+ * `[system, environment, ...conversation]`. `undefined` means "run unpooled":
37
+ * the server has no pools, or the prefix could not be made shareable -- slower,
38
+ * never wrong.
39
+ */
40
+ export declare function prepareLeadPool(options: PrepareLeadPoolOptions): Promise<LeadAttach | undefined>;
41
+ interface PrepareLeadPoolOptions {
42
+ baseUrl: string;
43
+ fetch: typeof fetch;
44
+ headers?: Record<string, string>;
45
+ body: Record<string, unknown>;
46
+ /** The conversation's session id, as the host knows it. */
47
+ sessionId: string;
48
+ now?: number;
49
+ /**
50
+ * "Keep the prefix resident" (the PolyKV section's `pinPrefix`, on unless
51
+ * it says off): pin a shared root while this process has a conversation on
52
+ * it, so a pause past the engine's 60 s sweep does not cost the next turn
53
+ * the render and prefill of the whole static prompt again. Taken off with
54
+ * the last conversation, after which the sweep owns it as before. A process
55
+ * that dies holding it leaves it pinned (`orphaned_pin` on the engine) until
56
+ * the next process on that prompt finishes with it.
57
+ */
58
+ pinPrefix?: boolean;
59
+ }
60
+ /**
61
+ * One pool of this conversation's chain is gone while the process stayed up
62
+ * (`pool_unknown` under an unchanged boot id): its sub-pool, released with a
63
+ * window that lapsed on the idle TTL, or the root it forks from, swept.
64
+ *
65
+ * Only that chain is dropped. A lost sub-pool goes with its window (the
66
+ * resume rule re-books it on the next request, and the sub-pool follows on
67
+ * the one after -- as when a lapse is found by the recheck). A lost root
68
+ * takes the sub-pools forked from it, for every conversation on it. Nothing
69
+ * is released: the server no longer holds it. Returns whether the id was
70
+ * this conversation's.
71
+ */
72
+ export declare function forgetPolykvLeadPool(sessionId: string, poolId: string): boolean;
73
+ /**
74
+ * The conversation now holds a window: the next request may own a sub-pool.
75
+ *
76
+ * Called on a successful response to a request that asked for one.
77
+ */
78
+ export declare function markLeadWindowLive(sessionId: string): void;
79
+ /**
80
+ * End a conversation's place in the lead tree.
81
+ *
82
+ * Its sub-pool goes, and the shared root with the last conversation on it. A
83
+ * no-op for a session that never attached.
84
+ */
85
+ export declare function releasePolykvLead(sessionId: string): Promise<void>;
86
+ /** Test seam: what the lead tree holds. */
87
+ export declare function polykvLeadState(): Array<{
88
+ root: string;
89
+ sessions: string[];
90
+ }>;
91
+ /** Test seam, and process shutdown. */
92
+ export declare function releaseAllPolykvLeads(): Promise<void>;
93
+ export {};
94
+ //# sourceMappingURL=polykv-lead.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polykv-lead.d.ts","sourceRoot":"","sources":["../../../src/providers/vendors/polykv-lead.ts"],"names":[],"mappings":"AAmGA,yEAAyE;AACzE,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,aAAa,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;CACnB;AAuBD;;;;;;GAMG;AACH,eAAO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