@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,322 @@
1
+ /**
2
+ * Global KV pressure, and the resize that answers it (`kv_pressure_v1`,
3
+ * `kv_resize_v1`, opencoti b108, mail #296).
4
+ *
5
+ * Until these, a booking was sized once and held for its life (§10.1 of the
6
+ * integration guide): a session that compacted from 200k to 20k still held
7
+ * 200k, while the server refused new agents for want of cells it was not
8
+ * using. The engine now says two things it did not:
9
+ *
10
+ * - **Whether it is refusing.** `GET /kv` carries a `pressure` block -- the
11
+ * refusals of the last `window_s` seconds -- and every admission 429 carries
12
+ * the same block as `error.pressure`.
13
+ * - **That a booking can move.** `POST /kv/sessions/{id}/resize {num_ctx}`
14
+ * shrinks or grows a live booking between requests; the session's next
15
+ * request runs in the new window.
16
+ *
17
+ * This module is the wire half: the types, the parsers, a per-server record of
18
+ * the last pressure seen, and the resize call. What a running agent does with
19
+ * them -- compact, shrink, grow back -- is policy, and lives with the
20
+ * compaction trigger in `@cerebriline/core` (`kv-pressure.ts`).
21
+ *
22
+ * Nothing here throws. A block that is not there is `undefined`, and a resize
23
+ * that fails in any way comes back as a typed refusal: agents retry and never
24
+ * fail on infrastructure, so there is nothing a caller could usefully catch.
25
+ */
26
+ import { type OpencotiAllocation } from "./polykv";
27
+ /**
28
+ * The server's refusals over its trailing window, as `GET /kv` states them.
29
+ *
30
+ * `refusedMinNeededMin60s` is the number a running session shrinks toward: the
31
+ * smallest floor that would have satisfied one of the refused requests, so
32
+ * freeing that many cells lets at least one of them in.
33
+ */
34
+ export interface OpencotiKvPressure {
35
+ /** The trailing window the `*_60s` counters cover, in seconds (60). */
36
+ windowS: number;
37
+ /** Admission refusals inside the window. */
38
+ refused60s: number;
39
+ /** The largest peak among them, in cells. */
40
+ refusedPeakMax60s?: number;
41
+ /** The most any one of them needed. */
42
+ refusedNeededMax60s?: number;
43
+ /** The least any one of them needed: free this much and one fits. */
44
+ refusedMinNeededMin60s?: number;
45
+ /** Epoch seconds of the last refusal, on the server's clock. */
46
+ lastRefusalAt?: number;
47
+ /** Seconds since the last refusal, when the block was written. */
48
+ lastRefusalAgeS?: number;
49
+ /** Refusals since boot. */
50
+ refusalsTotal?: number;
51
+ /**
52
+ * Cells physically held by IDLE slots minus their pool share
53
+ * (`kv_observable_v1`, bug-3657): released workers' "ghosts", charged to
54
+ * no booking. Reclaimed one slot per failed `find_slot`, or when the slot
55
+ * is reused -- until then, room the admission gate counts as free and the
56
+ * cache does not have. Server-wide: the engine does not say whose.
57
+ */
58
+ idleResident?: number;
59
+ }
60
+ /**
61
+ * Read a `pressure` block, from `/kv` or from a 429's `error`.
62
+ *
63
+ * `undefined` for anything that is not an object carrying at least the refusal
64
+ * count: a block that does not say how many were refused says nothing a
65
+ * policy could act on.
66
+ */
67
+ export declare function parseOpencotiKvPressure(raw: unknown): OpencotiKvPressure | undefined;
68
+ /** The `error.pressure` of a refusal body, given as text or parsed. */
69
+ export declare function parseOpencotiRefusalPressure(body: unknown): OpencotiKvPressure | undefined;
70
+ /** The last pressure a server stated, and when this process read it. */
71
+ export interface OpencotiPressureReading {
72
+ pressure: OpencotiKvPressure;
73
+ /** `Date.now()` when it was read -- not the server's clock. */
74
+ at: number;
75
+ }
76
+ /**
77
+ * Remember what a server said about its refusals.
78
+ *
79
+ * Kept per server rather than per session: pressure is the server's, and a
80
+ * refusal one agent's request ran into is news for every other agent there.
81
+ * The newest reading wins, whichever route it came by.
82
+ */
83
+ export declare function noteOpencotiPressure(baseUrl: string, pressure: OpencotiKvPressure, at?: number): void;
84
+ /** Record the `error.pressure` a refusal carried, if it carried one. */
85
+ export declare function noteOpencotiRefusalPressure(baseUrl: string, body: unknown): OpencotiKvPressure | undefined;
86
+ /** The newest pressure reading for a server, if any. */
87
+ export declare function latestOpencotiPressure(baseUrl: string | undefined): OpencotiPressureReading | undefined;
88
+ /** Test seam. */
89
+ export declare function resetOpencotiPressure(): void;
90
+ /** The KV cells a server stated on its last `GET /kv`, as this process read it. */
91
+ export interface OpencotiKvCellsReading {
92
+ /** `Date.now()` when it was read. */
93
+ at: number;
94
+ /** Cells booked: the sum of every live session's window. */
95
+ booked: number;
96
+ /** Sessions holding a window. */
97
+ sessions: number;
98
+ cellsTotal?: number;
99
+ cellsFree?: number;
100
+ /**
101
+ * Each session's own row, by engine session id: what the lead's status
102
+ * shows per agent, so it can tell which agents hold the cells.
103
+ */
104
+ bySession?: Record<string, {
105
+ used: number;
106
+ window: number;
107
+ pressure: number;
108
+ }>;
109
+ }
110
+ /** The newest `/kv` cells reading for a server, if any was made. */
111
+ export declare function latestOpencotiKv(baseUrl: string | undefined): OpencotiKvCellsReading | undefined;
112
+ /**
113
+ * How long a "no refusals" reading may be trusted to say the pressure has
114
+ * cleared. Growing back takes cells, so it waits for a reading this recent;
115
+ * the per-turn `/kv` read is bounded at five seconds, well inside it.
116
+ */
117
+ export declare const OPENCOTI_PRESSURE_CLEAR_MAX_AGE_MS = 15000;
118
+ /**
119
+ * Whether the refusals in a pressure block were for want of cells on the
120
+ * SERVER -- the only refusals running agents answer by giving cells back.
121
+ *
122
+ * `refused_needed_max_60s` is the most base-pool cells any refusal in the
123
+ * window asked for (opencoti `oc_refusal_record`: the admission's
124
+ * `want[OC_POOL_BASE]`). A worker refused because its OWNER is full asks the
125
+ * base pool for nothing -- its cells are priced against the owner's window --
126
+ * so a window of only those reads 0: the server had the room, one booking
127
+ * was short. Live on 8244 (b108, 2026-09-25): four such refusals with 786k
128
+ * base cells free; answering them by compacting and shrinking every running
129
+ * agent would have been exactly wrong. The answer to those is growing the
130
+ * owner (`growPolykvOwnerForWorker`). A block without the field (an older
131
+ * engine) reads as global, as before.
132
+ */
133
+ export declare function opencotiRefusalsAreGlobal(pressure: OpencotiKvPressure): boolean;
134
+ /**
135
+ * Whether the server is refusing now: `active`, `clear`, or `unknown`.
136
+ *
137
+ * Active while the last refusal is inside the window, counted forward from
138
+ * when the block was read -- the server's own `last_refusal_age_s` plus the
139
+ * time since -- so a reading does not have to be fresh to still be true, and
140
+ * the server's clock is never compared with ours. A block with refusals and
141
+ * no age is active for one window from the read.
142
+ *
143
+ * Clear only on a recent reading: an old "nothing refused" says nothing about
144
+ * now, and growing on it would take cells someone was just refused.
145
+ *
146
+ * Only refusals for want of server cells count ({@link
147
+ * opencotiRefusalsAreGlobal}): a window of nothing but session-full
148
+ * refusals is a server with room, and reads as one.
149
+ */
150
+ export declare function opencotiPressureState(reading: OpencotiPressureReading | undefined, now?: number): "active" | "clear" | "unknown";
151
+ /** What one `GET /kv` read gives the pressure policy. */
152
+ export interface OpencotiKvSnapshot {
153
+ allocations: OpencotiAllocation[];
154
+ /** Present only where the server advertises `kv_pressure_v1`. */
155
+ pressure?: OpencotiKvPressure;
156
+ /**
157
+ * Present only where the server advertises `kv_observable_v1`: what the
158
+ * cache physically holds beyond the bookings, and the room the admission
159
+ * gate still counts as free.
160
+ */
161
+ resident?: OpencotiKvResident;
162
+ }
163
+ /** The part of the cache no booking accounts for (`kv_observable_v1`). */
164
+ export interface OpencotiKvResident {
165
+ /** `pressure.idle_resident`: see {@link OpencotiKvPressure.idleResident}. */
166
+ idleResident: number;
167
+ /** `cells_free`: unallocated base cells, what admission will hand out. */
168
+ cellsFree?: number;
169
+ /** `cells_total`: the base pool. */
170
+ cellsTotal?: number;
171
+ /**
172
+ * `/kv` → `swa`: the sliding-window half, on a model with one (null
173
+ * otherwise). Bookings and `largest_admissible` count BASE cells only,
174
+ * and every resident sequence keeps its last SWA window -- idle sessions
175
+ * and pools included -- so this half can be full while the base is nearly
176
+ * empty: the b116 evictions were "SWA half could not fit the batch (2048
177
+ * tokens): swa 66044 used of 66048 cells" with the base holding 163k of
178
+ * 1M (opencoti mail #322).
179
+ */
180
+ swa?: OpencotiKvSwa;
181
+ }
182
+ /**
183
+ * The SWA half as `/kv` states it. `cellsUsed` is the engine's ACCOUNTING
184
+ * (`oc_kv_pools_state`): the eventual demand of processing slots and pools,
185
+ * with idle slots deliberately uncharged (bug-3535). It is not the physical
186
+ * occupancy the engine's find_slot failure logs, which includes the idle
187
+ * slots' windows -- so it reads low exactly when ghosts hold the half.
188
+ */
189
+ export interface OpencotiKvSwa {
190
+ cellsUsed: number;
191
+ cellsTotal: number;
192
+ cellsFree?: number;
193
+ cellsReserved?: number;
194
+ /** The model's sliding window, per sequence. */
195
+ window?: number;
196
+ /**
197
+ * Under `kv_recyclable_v1` (b122, mail #326): the cells a batch can take
198
+ * now -- empty ones plus those find_slot recycles (a sequence's own cells
199
+ * behind its window). The half's real room; `cellsUsed` is accounting.
200
+ */
201
+ cellsPhysFree?: number;
202
+ /** The physical size of the half, beside {@link cellsPhysFree}. */
203
+ cellsPhysTotal?: number;
204
+ }
205
+ /**
206
+ * `GET /kv`: the allocations, and -- under `kv_pressure_v1` -- the pressure.
207
+ *
208
+ * One read for both, so the compaction trigger's per-turn row read carries
209
+ * the pressure with it rather than asking a second time. The pressure is also
210
+ * recorded for the server (see {@link noteOpencotiPressure}). `undefined`
211
+ * where the server does not offer `/kv` (`kv_status_v1`) or did not answer.
212
+ */
213
+ export declare function readOpencotiKv(baseUrl: string | undefined, fetchImpl?: typeof fetch): Promise<OpencotiKvSnapshot | undefined>;
214
+ /**
215
+ * The route a resize goes to.
216
+ *
217
+ * `POST /kv/sessions/{id}/resize` for an id the path can carry; `POST
218
+ * /sessions/resize {session_id, num_ctx}` for anything else. The path segment
219
+ * cannot hold a `/` -- encoded, the route does not match (the close route's
220
+ * lesson, `engineSessionId`) -- and our own ids carry `~` (`~teammate-…`,
221
+ * `~agent-…`, `~polykv-owner-…`), which the body form takes without asking how
222
+ * the router reads it.
223
+ */
224
+ export declare function opencotiResizeRequest(sessionId: string, numCtx: number): {
225
+ path: string;
226
+ body: Record<string, unknown>;
227
+ };
228
+ /** The window a resize queued on this session will apply, if one is. */
229
+ export declare function opencotiPendingResize(baseUrl: string, sessionId: string): number | undefined;
230
+ /** Test seam. */
231
+ export declare function resetOpencotiPendingResizes(): void;
232
+ /**
233
+ * Whether this server resizes a busy session while its requests run: it
234
+ * says so in `/props` features, or a resize here already answered `live`
235
+ * (0422 answers a busy resize 200 `live: true`, and a shrink that does not
236
+ * fit yet 409 with `smallest_window_now`).
237
+ */
238
+ export declare function opencotiResizesLive(baseUrl: string, features?: readonly string[]): boolean;
239
+ /** A resize the engine took. `cellsDelta` is negative for cells given back. */
240
+ export interface OpencotiResizeDone {
241
+ ok: true;
242
+ window?: number;
243
+ windowNew: number;
244
+ cells?: number;
245
+ cellsNew?: number;
246
+ cellsDelta?: number;
247
+ used?: number;
248
+ sequences?: number;
249
+ /**
250
+ * `idle_resident` at the resize (`kv_observable_v1`): the cells beyond
251
+ * `used` the cache still holds. Shrink against `used + idleResident`.
252
+ */
253
+ idleResident?: number;
254
+ }
255
+ /**
256
+ * A resize the engine did not take, by kind:
257
+ *
258
+ * - `session_not_found` (404), `session_closing` (409): the booking is gone
259
+ * or going; nothing to resize.
260
+ * - `invalid_num_ctx`, `above_session_ctx_max` (400).
261
+ * - `per_request_session` (409): the session holds nothing between
262
+ * requests, so there is nothing to resize -- and stating a smaller
263
+ * `num_ctx` on its next request would make it a HELD booking (mail #301).
264
+ * - `session_busy` (409): a task is active or pending; try between requests.
265
+ * - `used_exceeds_window` (409): the tree holds more than the asked window;
266
+ * `used` is the floor.
267
+ * - `exhausted` (429): a grow the free cells cannot cover;
268
+ * `largestAdmissible` is the most it could grow to.
269
+ * - `deferred` (202): not a refusal -- queued for the session's idle
270
+ * moment (`deferred: true` asked, `kv_resize_deferred_v1`); `pending` is
271
+ * the window it will apply. Not applied yet, so nothing may read it as
272
+ * the new window.
273
+ * - `transport`: no answer at all.
274
+ * - anything else the engine names, verbatim.
275
+ */
276
+ export interface OpencotiResizeRefused {
277
+ ok: false;
278
+ status: number;
279
+ kind: string;
280
+ message?: string;
281
+ used?: number;
282
+ window?: number;
283
+ cells?: number;
284
+ largestAdmissible?: number;
285
+ pressure?: OpencotiKvPressure;
286
+ /** `deferred`: the window queued for the idle moment. */
287
+ pending?: number;
288
+ /** As on {@link OpencotiResizeDone}, where the engine states it. */
289
+ idleResident?: number;
290
+ }
291
+ export type OpencotiResizeResult = OpencotiResizeDone | OpencotiResizeRefused;
292
+ /**
293
+ * Resize a live booking (`kv_resize_v1`). Never throws.
294
+ *
295
+ * `sessionId` is the id the wire carried (`engineSessionId(...)`). Only valid
296
+ * between the session's requests: the engine answers `session_busy` while a
297
+ * task is active or pending, and the caller tries again at its next turn
298
+ * boundary. The caller checks the feature; this only makes the call.
299
+ */
300
+ export declare function resizeOpencotiSession(options: {
301
+ baseUrl: string;
302
+ sessionId: string;
303
+ numCtx: number;
304
+ /**
305
+ * Queue it for the session's idle moment if the session is busy
306
+ * (`kv_resize_deferred_v1` -- the caller checks the feature). An idle
307
+ * session takes it at once, as without the flag; asking for the current
308
+ * window cancels what is queued.
309
+ */
310
+ deferred?: boolean;
311
+ fetch?: typeof fetch;
312
+ headers?: Record<string, string>;
313
+ }): Promise<OpencotiResizeResult>;
314
+ export declare function recordOpencotiWindowFloor(sessionId: string, floor: number | undefined): void;
315
+ export declare function getOpencotiWindowFloor(sessionId: string | undefined): number | undefined;
316
+ /** Test seam. */
317
+ export declare function resetOpencotiWindowFloors(): void;
318
+ export declare function recordOpencotiWindowCeiling(sessionId: string, ceiling: number | undefined): void;
319
+ export declare function getOpencotiWindowCeiling(sessionId: string | undefined): number | undefined;
320
+ /** Test seam. */
321
+ export declare function resetOpencotiWindowCeilings(): void;
322
+ //# sourceMappingURL=opencoti-kv-pressure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opencoti-kv-pressure.d.ts","sourceRoot":"","sources":["../../../src/providers/vendors/opencoti-kv-pressure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAGN,KAAK,kBAAkB,EAIvB,MAAM,UAAU,CAAC;AAElB;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IAClC,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,uCAAuC;IACvC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,qEAAqE;IACrE,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,gEAAgE;IAChE,aAAa,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AAI,IAAI,CAElD"}
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Server liveness on the opencoti stream (`stream_keepalive_v1`, patch 0388).
3
+ *
4
+ * Cerebriline runs its local streams with every timeout off, because a 40k
5
+ * prefill behind a busy server can legitimately take minutes of silence. That
6
+ * made a dead server, a half-open connection and a slow turn look the same:
7
+ * nothing on the wire, for as long as anyone cared to wait.
8
+ *
9
+ * With `stream_options.keepalive: true` the server opens the SSE stream at once
10
+ * and sends one comment line per silent `sse_ping_interval`, naming the phase:
11
+ *
12
+ * : keepalive queued
13
+ * : keepalive prefill 20481/41533
14
+ * : keepalive generating 17
15
+ *
16
+ * Three silent periods is dead. Two things come with it:
17
+ *
18
+ * - **The first-result error moves into the stream.** Without the option an
19
+ * admission refusal, an overlong prompt or a window refusal of the slot is a
20
+ * plain HTTP error; with it, the stream is already open, so it arrives as a
21
+ * `data: {"error": {...}}` event under a 200. Every refusal path on this side
22
+ * reads the status, so {@link superviseKeepaliveStream} puts the status back.
23
+ * - **A silence that outlasts three periods is a transport fault**, raised as
24
+ * one ({@link OpencotiServerSilentError}) so the turn-fault recovery waits
25
+ * for `/health` and runs the turn again.
26
+ *
27
+ * Refusals the server makes BEFORE it opens the stream (the enforced admission
28
+ * gate's 429 + Retry-After, its settling hold) are untouched by the option:
29
+ * they are still plain HTTP responses, and a hold is still silence before the
30
+ * headers. The watchdog therefore starts at the headers, never before them.
31
+ */
32
+ /**
33
+ * The ping interval this client asks for, in seconds.
34
+ *
35
+ * `/props` does not advertise the server's `--sse-ping-interval` (checked
36
+ * against patch 0388: it is in neither `features` nor
37
+ * `default_generation_settings`), and a server launched with upstream's 30 s
38
+ * would have every healthy stream killed by a watchdog sized for 10 s. So the
39
+ * interval is not guessed: `sse_ping_interval` is a per-request field of the
40
+ * completion schema, and the request states it. 10 s is the patch's own
41
+ * default, so on a stock-configured server this changes nothing.
42
+ */
43
+ export declare const OPENCOTI_KEEPALIVE_PING_SECONDS = 10;
44
+ /** Silent periods after which the server is presumed dead (the contract's three). */
45
+ export declare const OPENCOTI_KEEPALIVE_DEAD_PERIODS = 3;
46
+ /**
47
+ * Slack on top of the three periods: the server's ping timer starts when its
48
+ * last write ended, and a busy event loop or a slow link adds to that. Enough
49
+ * to absorb both, small next to a period.
50
+ */
51
+ export declare const OPENCOTI_KEEPALIVE_MARGIN_MS = 5000;
52
+ /** How long a keepalive stream may go without a single byte: 35 s at the default. */
53
+ export declare function opencotiKeepaliveDeadMs(pingSeconds: number): number;
54
+ /**
55
+ * The longest a stream may stay silent while the server still answers.
56
+ *
57
+ * A silent stream on a server that answers is one of two things: the server is
58
+ * busy and not pinging, or this connection is dead and the server is fine. The
59
+ * first is waited out -- an abort there throws away a turn that is queued and
60
+ * will run. The second cannot be told from the first by asking the server, so
61
+ * it is bounded by time: ten minutes, the engine's own backstop for a
62
+ * reservation nothing released.
63
+ */
64
+ export declare const OPENCOTI_SILENT_ALIVE_MAX_MS = 600000;
65
+ /**
66
+ * The server went silent past three keepalive periods.
67
+ *
68
+ * Carries `code: "ETIMEDOUT"` and says so in its message, because both are
69
+ * what the turn-fault classifier reads as transport -- the kind waited out by
70
+ * asking `/health` and then running the turn again -- whether it is handed
71
+ * the error object or only its flattened text.
72
+ */
73
+ export declare class OpencotiServerSilentError extends Error {
74
+ readonly silentMs: number;
75
+ readonly code = "ETIMEDOUT";
76
+ constructor(silentMs: number);
77
+ }
78
+ /** What a keepalive comment says the request is doing. */
79
+ export type OpencotiStreamPhase = {
80
+ kind: "queued";
81
+ } | {
82
+ kind: "prefill";
83
+ processed: number;
84
+ total: number;
85
+ } | {
86
+ kind: "generating";
87
+ decoded: number;
88
+ };
89
+ /**
90
+ * Read one SSE comment line. A bare `:` (upstream's ping) and anything that is
91
+ * not a keepalive line say nothing about the phase.
92
+ */
93
+ export declare function parseKeepaliveComment(line: string): OpencotiStreamPhase | undefined;
94
+ /** A phase, worded for an agent's row. */
95
+ export declare function describeOpencotiStreamPhase(phase: OpencotiStreamPhase): string;
96
+ /** What a request that asked for the heartbeat asked for. */
97
+ export interface KeepaliveRequest {
98
+ /**
99
+ * The ping interval it carries, in seconds; absent when the caller turned
100
+ * the pings off (`sse_ping_interval <= 0`). The stream still opens early
101
+ * then, so a first-result error is still in-stream -- but a silence proves
102
+ * nothing, and there is no watchdog.
103
+ */
104
+ pingSeconds?: number;
105
+ }
106
+ /**
107
+ * Ask for the heartbeat on a streaming request body, in place.
108
+ *
109
+ * `stream_options` is merged, never replaced: the compatible provider puts
110
+ * `include_usage` there, and the usage row is read from it. Returns what was
111
+ * asked for, or `undefined` for a request that does not stream -- a buffered
112
+ * response has nowhere to put a comment.
113
+ */
114
+ export declare function requestStreamKeepalive(body: Record<string, unknown>): KeepaliveRequest | undefined;
115
+ /**
116
+ * The status an in-stream error would have had as a plain HTTP error.
117
+ *
118
+ * The server's non-streaming path sets the status from the error's own `code`
119
+ * (`res->error`: `status = json_value(error, "code", 500)`), so that is read
120
+ * first; the type table is the fallback, and 500 the default, as there.
121
+ */
122
+ export declare function statusOfStreamError(error: Record<string, unknown>): number;
123
+ export interface KeepaliveSupervision {
124
+ /**
125
+ * The ping interval the request asked for, in seconds. Absent: pings off,
126
+ * so no watchdog.
127
+ */
128
+ pingSeconds?: number;
129
+ /** Told once, when the silence has outlasted three periods. */
130
+ onDead?: (error: OpencotiServerSilentError) => void;
131
+ /**
132
+ * Asked when the silence has outlasted three periods, before the stream is
133
+ * given up: does the server answer at all? `true` keeps the stream open for
134
+ * another three periods, up to {@link OPENCOTI_SILENT_ALIVE_MAX_MS} of
135
+ * silence. Absent, the silence alone decides, as it did.
136
+ *
137
+ * bs2:8244, 2026-10-03: the server stopped pinging every open stream at
138
+ * once and went on answering `/health`. Ten queued turns were aborted in
139
+ * three seconds and sent again, thirty times in one round, and each abort
140
+ * left a reservation on the engine for 600 s. The pool the turns were
141
+ * queued on filled with them.
142
+ */
143
+ stillAlive?: () => Promise<boolean>;
144
+ /**
145
+ * Told the phase each keepalive comment names, and `undefined` once the
146
+ * stream produces again (or ends). Per comment; the receiver throttles.
147
+ */
148
+ onPhase?: (phase: OpencotiStreamPhase | undefined) => void;
149
+ /** Test seams. */
150
+ setTimer?: (fn: () => void, ms: number) => unknown;
151
+ clearTimer?: (handle: unknown) => void;
152
+ }
153
+ /** The header patch 0388 puts on every completion response. */
154
+ export declare const OPENCOTI_BOOT_ID_HEADER = "x-opencoti-boot-id";
155
+ /**
156
+ * Supervise a response to a request that asked for the heartbeat.
157
+ *
158
+ * - A response that is not a 200 event stream is returned as it is: a refusal
159
+ * the server made before opening the stream is already the HTTP error it
160
+ * always was.
161
+ * - Otherwise the stream is read up to its first data or error event --
162
+ * comments do not count. An error first becomes the plain HTTP response it
163
+ * would have been without the option, so every status-reading path (the 429
164
+ * window negotiation, the worker's window-full wait, the 5xx server-fault
165
+ * wait, the error classifier) sees what it always saw. Anything else is
166
+ * handed on as a stream that replays what was read and then continues.
167
+ * - Throughout, before and after that first event, a silence longer than three
168
+ * ping periods plus a margin cancels the body and fails the read with
169
+ * {@link OpencotiServerSilentError}: thrown from here while the first event
170
+ * is awaited, as a stream error after it. Armed only when the pings are on
171
+ * AND the response carries `X-OpenCoti-Boot-Id` -- the proof that the
172
+ * process that answered is one that sends the heartbeat. `/props` was read
173
+ * once per root; a restart onto an older build would leave long prefills
174
+ * silent, and a watchdog on those would kill healthy turns.
175
+ */
176
+ export declare function superviseKeepaliveStream(response: Response, options?: KeepaliveSupervision): Promise<Response>;
177
+ //# sourceMappingURL=opencoti-liveness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opencoti-liveness.d.ts","sourceRoot":"","sources":["../../../src/providers/vendors/opencoti-liveness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAElD,qFAAqF;AACrF,eAAO,MAAM,+BAA+B,IAAI,CAAC;AAEjD;;;;GAIG;AACH,eAA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C,KAAK,EAAE,yBAAyB,KAAK,IAAI,CAAC;IACpD;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,GAAG,SAAS,KAAK,IAAI,CAAC;IAC3D,kBAAkB;IAClB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;IACnD,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CACvC;AAED,+DAA+D;AAC/D,eAAO,MAAM,uBAAuB,uBAAuB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,wBAAwB,CAC7C,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,oBAAyB,GAChC,OAAO,CAAC,QAAQ,CAAC,CAiOnB"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The refusal a conversation gets when opencoti cannot give it a window it can
3
+ * use (PLANS §9c).
4
+ *
5
+ * Two shapes, one class:
6
+ *
7
+ * - **A resume** asked for exactly the window it was opened with -- its history
8
+ * no longer fits a smaller one -- and the server has less free. It is never
9
+ * retried and never negotiated down: the user is told, and chooses.
10
+ * - **A new session** asked for its configured window, bounded below by the
11
+ * floor, and even the floor did not fit after the one wait it is allowed.
12
+ *
13
+ * It is thrown out of the provider's fetch rather than returned as a 429, so
14
+ * that nothing between here and the user waits it out: the rate-limit
15
+ * middleware retries every 429, and this one has already had its wait.
16
+ *
17
+ * **The message is the carrier.** By the time a failed turn reaches a host the
18
+ * error object is gone and only its text is left, so the numbers ride in a
19
+ * machine-readable tail that {@link parseOpencotiWindowUnavailable} reads back.
20
+ * The prose avoids every phrase the overflow classifier keys on -- a refusal
21
+ * read as "context window exceeded" would start a compaction, which cannot help
22
+ * a server that is short of cells.
23
+ */
24
+ export declare const OPENCOTI_WINDOW_UNAVAILABLE_CODE = "opencoti_window_unavailable";
25
+ export interface OpencotiWindowUnavailableDetails {
26
+ /** The window this request asked for (`num_ctx`). */
27
+ asked: number;
28
+ /** The smallest window it would have accepted (`num_ctx_min`, or the ask). */
29
+ floor: number;
30
+ /** What the server said it could grant right now, when it said. */
31
+ largestAdmissible?: number;
32
+ /** A resumed conversation: it needed exactly `asked`, and never waits. */
33
+ resume: boolean;
34
+ }
35
+ /** `262144` -> `256k`. Rounded, because the card is prose, not a ledger. */
36
+ export declare function formatWindowK(tokens: number): string;
37
+ export declare class OpencotiWindowUnavailableError extends Error {
38
+ readonly name = "OpencotiWindowUnavailableError";
39
+ readonly asked: number;
40
+ readonly floor: number;
41
+ readonly largestAdmissible: number | undefined;
42
+ readonly resume: boolean;
43
+ constructor(details: OpencotiWindowUnavailableDetails);
44
+ get details(): OpencotiWindowUnavailableDetails;
45
+ }
46
+ /**
47
+ * Read the refusal back out of an error message, wherever it ended up.
48
+ *
49
+ * `undefined` for any message that is not one: a host branches on this to
50
+ * render the card, so a false positive would put a "Can't resume" card on an
51
+ * unrelated failure.
52
+ */
53
+ export declare function parseOpencotiWindowUnavailable(message: string | undefined): OpencotiWindowUnavailableDetails | undefined;
54
+ /** Whether an error, or anything in its cause chain, is this refusal. */
55
+ export declare function isOpencotiWindowUnavailableError(error: unknown): boolean;
56
+ //# sourceMappingURL=opencoti-window.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opencoti-window.d.ts","sourceRoot":"","sources":["../../../src/providers/vendors/opencoti-window.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,eAAO,MAAM,gCAAgC,gCAAgC,CAAC;AAE9E,MAAM,WAAW,gCAAgC;IAChD,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,0EAA0E;IAC1E,MAAM,EAAE,OAAO,CAAC;CAChB;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpD;AAqBD,qBAAa,8BAA+B,SAAQ,KAAK;IACxD,SAAkB,IAAI,oCAAoC;IAC1D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;gBAEb,OAAO,EAAE,gCAAgC;IAQrD,IAAI,OAAO,IAAI,gCAAgC,CAS9C;CACD;AAID;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC7C,OAAO,EAAE,MAAM,GAAG,SAAS,GACzB,gCAAgC,GAAG,SAAS,CAkC9C;AAED,yEAAyE;AACzE,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAexE"}