@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,705 @@
1
+ import type { OpencotiStreamPhase } from "./opencoti-liveness";
2
+ import { type PolykvAdmissionPolicy, type PolykvClient } from "./polykv";
3
+ /**
4
+ * Agents that share a prefix, deduplicated on the engine that holds the cells.
5
+ *
6
+ * A swarm of sub-agents on one opencoti server repeats the same context in
7
+ * every agent: the system prompt and tool schemas, then whatever knowledge they
8
+ * were all handed, then the instructions of their role. Measured on 8240 with a
9
+ * 15k-character file as the knowledge: each agent's prompt was 6,133 tokens and
10
+ * 6,099 of them were identical across every agent of a role. Sent as ordinary
11
+ * sessions they are prefilled and held once per agent; attached to a pool tree
12
+ * they are prefilled and held once.
13
+ *
14
+ * The tree mirrors how the agent's first request is laid out, one layer per
15
+ * turn:
16
+ *
17
+ * P0 system prompt + tools -- every agent
18
+ * P1 P0 + the knowledge turn -- every agent given that knowledge
19
+ * P2 P1 + the instructions turn -- every agent of that role
20
+ * worker: P2 + its own task, attached with `pool_id`
21
+ *
22
+ * Every pool is owned by one **owner session**, whose guaranteed window the
23
+ * whole tree lives in. A worker attached to an owned pool books nothing of its
24
+ * own: the engine charges its private suffix to the owner, so fifty agents fit
25
+ * where one agent's window would otherwise be booked fifty times.
26
+ *
27
+ * Three rules this module exists to keep:
28
+ *
29
+ * - **The prefix is the server's rendering, never ours.** Each layer is the
30
+ * request's own messages rendered through `/apply-template` and cut at a
31
+ * sentinel turn, then checked to be a byte-prefix of the rendering of the
32
+ * request it is for. A prefix that is not is never attached: attaching it
33
+ * costs a pool and shares nothing.
34
+ * - **Each layer ends after the next turn's opener.** A worker's prompt always
35
+ * continues with the opener of its task turn. A pool that stops before it is
36
+ * beaten by any warm slot that last served an agent of the same role -- the
37
+ * slot's cache matches those extra tokens, the engine prefers it, and the
38
+ * worker then runs on a private copy charged to the owner in full. Measured:
39
+ * 9 of 40 agents attached with the opener outside the pool.
40
+ * - **Nothing outlives its agents.** Each agent's own session is closed when
41
+ * the agent ends, and the owner -- with every pool it owns -- when its last
42
+ * agent does. The engine's idle TTL is the crash net: admission is decided
43
+ * against held windows, and a window held for five minutes after its work is
44
+ * done is five minutes of refusals for everyone queued behind it.
45
+ */
46
+ /** How one agent's requests attach to the shared tree. */
47
+ export interface PolykvWorkerSpec {
48
+ /**
49
+ * Agents that share owners. The lead conversation's session id: a swarm's
50
+ * agents dedupe against each other, never against another conversation's.
51
+ */
52
+ group: string;
53
+ /** This agent's own engine session -- slot affinity for its private suffix. */
54
+ sessionId: string;
55
+ /**
56
+ * How many turns after the system turn are shared layers.
57
+ *
58
+ * The agent's first request is `[system, ...layers, task]`; each layer turn
59
+ * becomes a pool. `0` shares the system prompt and tools only.
60
+ */
61
+ layers: number;
62
+ /**
63
+ * Attach to the tree this agent already has, and build nothing.
64
+ *
65
+ * For requests of the agent's that are not its conversation -- the
66
+ * compaction summarizer. Their prompt shares little with the tree, but
67
+ * attached to an owned pool they are charged to the owner as a worker
68
+ * instead of booking a window of their own.
69
+ */
70
+ attachOnly?: boolean;
71
+ /**
72
+ * The admission policy for every pool this agent's tree creates.
73
+ *
74
+ * Posted as each pool is made, because the engine's gate reads the policy
75
+ * of the pool a new session names, and that is the pool the worker
76
+ * attaches to -- a policy on the root alone gates nobody.
77
+ */
78
+ admission?: PolykvAdmissionPolicy;
79
+ /**
80
+ * Priority 0 (PLANS §9g): the pools live in THIS session's window -- the
81
+ * lead conversation's own -- instead of an owner opened for the swarm.
82
+ *
83
+ * The lead's session id as the host knows it (the engine spelling is made
84
+ * here). Such an owner is borrowed, never ours: it is not opened, never
85
+ * closed, and never swapped for a fresh one. What the swarm puts in it goes
86
+ * back when its last agent ends -- the pools are released one by one, the
87
+ * session stays. And a full window is the lead's, so a worker that has not
88
+ * started yet is not held on it: see `createWorkerFetch`, which hands such
89
+ * a refusal straight back so the agent overflows to a node.
90
+ */
91
+ owner?: string;
92
+ /**
93
+ * The window this agent's node states, and the least of it the agent
94
+ * accepts -- its "Agent window" share (see `opencoti-agent-window.ts`).
95
+ * An owner this agent opens is sized from it: it asks for the node's
96
+ * window (never more than the engine's per-session maximum) rather than
97
+ * the maximum itself, and floors at the agent's floor rather than at
98
+ * {@link POLYKV_OWNER_MIN_WINDOW} -- an owner granted less than one of its
99
+ * agents needs is an owner that agent can never run in.
100
+ */
101
+ window?: {
102
+ ask: number;
103
+ floor: number;
104
+ };
105
+ }
106
+ /**
107
+ * How many agents may run as sub-pools of the lead's own session (§9g).
108
+ *
109
+ * The engine's per-session sub-pool limit (`polykv_subpools_v1`): the unit
110
+ * of priority 0's capacity, and ruled as its cap.
111
+ */
112
+ export declare const POLYKV_LEAD_SUBPOOL_CAP = 8;
113
+ /**
114
+ * Pools the lead-owned swarm tree may hold: one fewer than the session's
115
+ * limit, so the conversation's own sub-pool (`polykv-lead.ts`'s `Ls`, re-made
116
+ * after each compaction) always has a place. A chain that reaches the limit
117
+ * stops there and the worker attaches to its parent -- sharing less.
118
+ */
119
+ export declare const POLYKV_LEAD_WORKER_POOL_MAX: number;
120
+ /**
121
+ * Cells of the lead's window a priority-0 agent must leave free to start.
122
+ *
123
+ * The hazard this guards is measured (991ce2466): agents charged to the
124
+ * lead's window filled it at about 21 and 49 of 51 failed. A new agent is
125
+ * therefore admitted to priority 0 only while a quarter of the window -- and
126
+ * never less than a worker's minimum useful room -- is still free for the
127
+ * conversation's own next turn. Below it the agent is refused before it
128
+ * starts and overflows to the Agent Nodes.
129
+ */
130
+ export declare function polykvLeadReserveCells(window: number): number;
131
+ /** The lead's allocation on the engine, from `GET /kv`. */
132
+ export interface PolykvLeadRoom {
133
+ window: number;
134
+ free: number;
135
+ /** Cells the lead keeps; a priority-0 agent starts only above this. */
136
+ reserve: number;
137
+ }
138
+ /**
139
+ * How much of the lead's booked window is free right now.
140
+ *
141
+ * `undefined` when it cannot be said -- `/kv` unreadable, or the lead holds
142
+ * no allocation (no `dynamicContextSize`: then a pool it "owns" is unowned,
143
+ * nothing is charged to it, and there is nothing of its to protect). The
144
+ * engine's own refusal is the backstop either way.
145
+ */
146
+ export declare function readPolykvLeadRoom(options: {
147
+ baseUrl: string;
148
+ fetch: typeof fetch;
149
+ headers?: Record<string, string>;
150
+ owner: string;
151
+ }): Promise<PolykvLeadRoom | undefined>;
152
+ export declare function markPolykvWorkerStarted(sessionId: string): void;
153
+ export declare function polykvWorkerStarted(sessionId: string): boolean;
154
+ /**
155
+ * The owner session whose `/kv` row this agent's usage lands in, or
156
+ * `undefined` when its last turn was unpooled (its own row is then the one).
157
+ *
158
+ * A worker attached to an owned pool books nothing: the engine charges its
159
+ * private suffix to the owner, so the owner's row is the booking the agent
160
+ * lives in -- and the one its compaction trigger has to read. Without it the
161
+ * trigger read no row at all for any delegated agent on a PolyKV node.
162
+ */
163
+ export declare function polykvWorkerChargedTo(sessionId: string): string | undefined;
164
+ export interface PolykvWorkerAttach {
165
+ poolId?: string;
166
+ sessionId: string;
167
+ /**
168
+ * The server generation `poolId` belongs to (see
169
+ * {@link polykvRootGeneration}). A pool id is a number the server issued
170
+ * in one boot; the caller re-prepares rather than send it once the
171
+ * generation has moved on.
172
+ */
173
+ generation?: number;
174
+ /**
175
+ * Why the request goes out with no pool, or with a shallower one than its
176
+ * layers asked for. Logged at warn by the worker's fetch: 257 dispatches
177
+ * of 2026-09-25 went out unpooled and the only line about it was a debug
178
+ * `pool=none`.
179
+ */
180
+ reason?: string;
181
+ /**
182
+ * The owner session (engine id) whose window this attach is charged to:
183
+ * set exactly when `poolId` is. See {@link polykvWorkerChargedTo}.
184
+ */
185
+ ownerSessionId?: string;
186
+ }
187
+ /** What the server said a pool was when it made it, to know it again. */
188
+ interface PoolRecord {
189
+ parent?: string;
190
+ prefixLen?: number;
191
+ }
192
+ /**
193
+ * A worker turn goes out: until the returned call, `sessionId` is using the
194
+ * owner it was sent on. The end is idempotent; ending the agent's last
195
+ * running turn closes any abandoned owner no other running turn holds.
196
+ */
197
+ export declare function beginPolykvWorkerTurn(sessionId: string): () => void;
198
+ /**
199
+ * Whether `state` differs from the last one noted for this agent (and note
200
+ * it). The worker's fetch logs only what changed.
201
+ */
202
+ export declare function notePolykvWorkerAttach(sessionId: string, state: string): boolean;
203
+ export declare function rememberOpencotiSession(sessionId: string, baseUrl: string, fetchFn: typeof fetch, headers?: Record<string, string>): void;
204
+ /** Owner windows start here and the engine grants what fits above it. */
205
+ export declare const POLYKV_OWNER_MIN_WINDOW = 32768;
206
+ /**
207
+ * Longest wait between two tries on a full window.
208
+ *
209
+ * There is no overall deadline: a full window is a queue, not a fault -- it
210
+ * drains as the other agents finish -- and an agent is meant to finish its
211
+ * job (ruled after 1tmrl). This is the one guard against a tight loop: the
212
+ * first {@link POLYKV_ROOM_WAITS_AT_NAMED} waits are what the engine names,
213
+ * and after that the wait doubles on each refusal in a row, up to this.
214
+ */
215
+ export declare const POLYKV_ROOM_BACKOFF_MAX_MS = 30000;
216
+ /** Waits in a row taken at the engine's own `Retry-After` before backing off. */
217
+ export declare const POLYKV_ROOM_WAITS_AT_NAMED = 4;
218
+ /** The wait before the `waits`th retry on a full window (1-based). */
219
+ export declare function polykvRoomBackoffMs(waits: number, namedMs: number): number;
220
+ export declare function hashString(text: string): string;
221
+ /**
222
+ * A session id the engine can close.
223
+ *
224
+ * The close route is `/sessions/:session_id/close`, and its parameter cannot
225
+ * hold a `/` -- encoded as `%2F` the route does not match and the close 404s,
226
+ * leaving the window held until the idle TTL. Measured on 8240: an owner named
227
+ * `lead/polykv-owner-1` could be opened, filled and used, and never closed.
228
+ */
229
+ export declare function engineSessionId(id: string): string;
230
+ /**
231
+ * How often an agent's reattach asks the server whether it is the one its
232
+ * pools were made on, when nothing has suggested otherwise. Shared by every
233
+ * agent on the root, so a swarm asks once per interval, not once per agent.
234
+ */
235
+ export declare const POLYKV_VERIFY_INTERVAL_MS = 2000;
236
+ /** The server generation pool ids on this root currently belong to. */
237
+ export declare function polykvRootGeneration(baseUrl: string): number;
238
+ /**
239
+ * Something suggested the server at `baseUrl` restarted: a transport fault,
240
+ * or a pooled turn that came back without `X-Context-Window`. The next attach
241
+ * on that root asks the server before it resolves any pool.
242
+ */
243
+ export declare function notePolykvServerFault(baseUrl: string): void;
244
+ /**
245
+ * The identity a `/props` body (and, when given, a `/health` body) states,
246
+ * or undefined when it states none. `boot_id` / `started_at` are preferred
247
+ * whenever either is present; see {@link BOOT_IDENTITY_FIELDS}.
248
+ */
249
+ export declare function polykvServerIdentity(props: Record<string, unknown> | undefined, health?: Record<string, unknown>): string | undefined;
250
+ /**
251
+ * The server restarted: every pool and owner this process knew on `baseUrl`
252
+ * is gone. Bumps the root's generation and drops its groups' owners, pools
253
+ * and assignments -- nothing is closed, there is nothing left to close -- so
254
+ * each agent's next turn resolves its layer key to a pool built anew, under
255
+ * a new owner, and the prefix is shared again.
256
+ */
257
+ export declare function invalidatePolykvRoot(baseUrl: string, reason: string, options?: {
258
+ /**
259
+ * The agents' notice. `warn` by default; `info` where the loss was
260
+ * found and recovered in the same breath -- the rebuild is the whole
261
+ * of what follows, and nothing is left to watch.
262
+ */
263
+ severity?: PolykvNotice["severity"];
264
+ /** The notice's text, when "restarted" is not what happened. */
265
+ text?: string;
266
+ }): string[];
267
+ /**
268
+ * How often an owner with agents is kept from lapsing.
269
+ *
270
+ * The engine releases an allocation idle past its TTL (`--elastic-alloc-ttl`,
271
+ * five minutes on bs2), and only a finished request of the owner's resets
272
+ * that clock. An owner whose agents are all being refused -- the pool floor,
273
+ * no room -- or are in long tool calls has none, and on bs2 8244 2026-09-26
274
+ * every one of 26 lapses came exactly five minutes after the owner's last
275
+ * finished request, with its agents still retrying. Losing the owner costs
276
+ * them their pools and a new window they then wait for, so an owner is not
277
+ * let go while it has agents.
278
+ */
279
+ export declare const POLYKV_OWNER_KEEPALIVE_MS = 60000;
280
+ /**
281
+ * Reset the idle clock of every owner on `root` that has agents: a resize to
282
+ * the window the engine holds for it now (`/kv`), which the engine takes as a
283
+ * use and which changes nothing else. Never a grow -- the window is read, not
284
+ * remembered, so a pressure shrink stands. An owner busy with a request is
285
+ * refused the resize and needs none. Returns how many were reset.
286
+ */
287
+ export declare function keepPolykvOwnersAlive(baseUrl: string, fetchFn: typeof fetch, headers?: Record<string, string>): Promise<number>;
288
+ /**
289
+ * The boot id this root's pools belong to, when the server has stated one.
290
+ * `undefined` on a server without `boot_id_v1`: nothing to compare against.
291
+ */
292
+ export declare function polykvRootBootId(baseUrl: string): string | undefined;
293
+ /**
294
+ * One pool of this agent's chain is gone while the process stayed up
295
+ * (`pool_unknown` under an unchanged boot id): its owner lapsed or was
296
+ * closed, or the engine released it. Forget that pool and every pool forked
297
+ * from it -- in the shard that holds it, and nowhere else -- so the agent's
298
+ * next turn rebuilds its chain from the first layer still standing. Other
299
+ * agents, on this shard or another, keep their pools; if theirs went too,
300
+ * their own next answer says so.
301
+ *
302
+ * Layers whose build failed are retried too: a fork from the pool that just
303
+ * vanished is the likeliest reason one did.
304
+ *
305
+ * Returns whether any pool was forgotten.
306
+ */
307
+ export declare function forgetPolykvWorkerPool(baseUrl: string, sessionId: string, poolId: string): boolean;
308
+ /**
309
+ * Read the `X-OpenCoti-Boot-Id` of a completion response (`boot_id_v1`).
310
+ *
311
+ * Pool ids restart from 0 with the process, so a pool id held across a
312
+ * restart names nothing -- silently reprocessed in full -- or a pool someone
313
+ * built since. The header is on every completion, so a restart is known from
314
+ * the first answer of the new process, not from the next `/props` check up to
315
+ * {@link POLYKV_VERIFY_INTERVAL_MS} later (and only on a turn that attaches).
316
+ *
317
+ * The generation's boot id is the first one stated for the root -- by
318
+ * `/props` when a chain is verified, or by this header -- and it is carried
319
+ * across a generation that ended for another reason (a lapsed pool, a
320
+ * listing that lost one): that is still the same process. So once the server
321
+ * has stated any boot id, one is always recorded, and a header that differs
322
+ * from it is the one signal: it starts a new generation at once. The swarm's
323
+ * owners and pools are dropped and every agent -- and the lead, whose tree
324
+ * follows the generation -- rebuilds on its next turn. The notice is `info`:
325
+ * the restart is over, and the rebuild is its whole consequence.
326
+ *
327
+ * Returns whether the root was invalidated. An absent header (an older build)
328
+ * says nothing.
329
+ */
330
+ export declare function notePolykvBootId(baseUrl: string, bootId: string | null | undefined): boolean;
331
+ /** What the server said of a pool when it was made, for the listing check. */
332
+ export type PolykvPoolRecord = PoolRecord;
333
+ /** Pools on `root` held outside the swarm's groups, current generation only. */
334
+ export type PolykvPoolHolder = (root: string) => Array<[string, PoolRecord]>;
335
+ /**
336
+ * Register pools held outside the swarm -- the lead tree's -- so a restart
337
+ * check can see them too.
338
+ *
339
+ * Read only when a fault made the root suspect: the lead's pools can go for
340
+ * reasons that are not a restart (a lapsed window takes its sub-pool, the
341
+ * engine sweeps an idle shared root), and on a quiet root that must not cost
342
+ * every agent its pools. After a fault, a missing pool is read as the restart
343
+ * it most likely is -- a rebuilt pool costs a prefill, a stale id can attach
344
+ * a turn to someone else's. Returns the unregister.
345
+ */
346
+ export declare function registerPolykvPoolHolder(holder: PolykvPoolHolder): () => void;
347
+ /**
348
+ * Ask the server whether it is still the one this process's pools on `root`
349
+ * were made on, and start a new generation if it is not.
350
+ *
351
+ * Two signals, whichever the build gives: its identity in `/props` (see
352
+ * {@link polykvServerIdentity}) changing, or `/polykv/pools` no longer holding
353
+ * a pool we made as we made it. Asked at most every
354
+ * {@link POLYKV_VERIFY_INTERVAL_MS} per root, and at once when a fault made
355
+ * the root suspect. A suspect root that cannot be asked is rebuilt: a rebuilt
356
+ * pool costs a prefill, a stale id can attach an agent to someone else's.
357
+ */
358
+ export declare function verifyPolykvRoot(root: string, fetchFn: typeof fetch, headers?: Record<string, string>): Promise<void>;
359
+ /**
360
+ * The bounds of an owner this process opened, by its engine session id.
361
+ *
362
+ * The floor is every agent on it at its own floor -- one agent's floor times
363
+ * the agents it carries now (never less than the floor it opened at, never
364
+ * above the ceiling): a pressure shrink that left four agents one agent's
365
+ * floor would starve three of them.
366
+ */
367
+ export declare function polykvOwnerWindowBounds(ownerSessionId: string): {
368
+ floor: number;
369
+ ceiling: number;
370
+ } | undefined;
371
+ /**
372
+ * The engine resized an owner (a pressure shrink or grow-back): the agents it
373
+ * carries follow the window it holds now.
374
+ */
375
+ export declare function notePolykvOwnerWindow(ownerSessionId: string, window: number): void;
376
+ /**
377
+ * What an owner asks the engine for: every agent it can carry at the node's
378
+ * window, capped at the engine's per-session maximum.
379
+ *
380
+ * The engine charges each pooled worker's private cells to its owner
381
+ * (`oc_alloc_tree_used`: a slot's tokens minus what it shares from a pool),
382
+ * so an owner booked at one agent's window has to hold every one of its
383
+ * workers in it. Live on 8244 (b108, 2026-09-25): 64k owners refused their
384
+ * second and third worker ("session allocation full (worker of ...)") with
385
+ * 786k base cells free. The node window is the budget PER AGENT; an owner
386
+ * carries `agents` of them. The floor is one agent's: an owner granted less
387
+ * carries the agent that opened it, and the capacity check below keeps the
388
+ * others off it.
389
+ */
390
+ export declare function polykvOwnerBooking(perAgent: {
391
+ ask: number;
392
+ floor: number;
393
+ }, maximum: number,
394
+ /**
395
+ * The agents waiting to be placed on it, where the engine resizes a busy
396
+ * owner live: it is booked for them alone and grown as more arrive.
397
+ * Absent: every agent the maximum can carry, which it cannot grow into
398
+ * later while busy.
399
+ */
400
+ waiting?: number): {
401
+ window: number;
402
+ windowMin: number;
403
+ agents: number;
404
+ };
405
+ /**
406
+ * How many agents an owner of `window` cells carries at `ask` each.
407
+ *
408
+ * `sharedPrefix` is the prefix every agent on it shares from its pools: the
409
+ * engine charges it once, to the pool, and each worker only for what is past
410
+ * it. Never less than one: an owner is never opened for nobody, and the agent
411
+ * that opened it keeps it whatever it was granted.
412
+ */
413
+ export declare function polykvOwnerAgentCapacity(window: number, ask: number, sharedPrefix?: number): number;
414
+ /**
415
+ * How old a `/kv` reading may be and still place agents by what the owner
416
+ * measurably holds. Older, the reservation count decides, as before.
417
+ */
418
+ export declare const POLYKV_MEASURED_PLACEMENT_MAX_AGE_MS = 30000;
419
+ /**
420
+ * The cells an agent's first turn takes on its owner: its prompt and its
421
+ * reply cap, never more than the node's window for one agent.
422
+ */
423
+ export declare function polykvFirstTurnCells(body: Record<string, unknown>, perAgentAsk?: number): number;
424
+ /**
425
+ * The longest placement waits for the agents already seated to start before
426
+ * it opens another owner anyway. An agent that cannot start -- refused, or
427
+ * queued behind the engine's slots -- must not hold every other agent of the
428
+ * burst back for good.
429
+ */
430
+ export declare const POLYKV_SEED_WAIT_MAX_MS = 120000;
431
+ /** How often placement looks whether the seated agents have started. */
432
+ export declare const POLYKV_SEED_POLL_MS = 100;
433
+ /**
434
+ * The owner parsed from a worker's session-full refusal, and by how much it
435
+ * is short: `session allocation full (worker of '<owner>': <free> of <cells>
436
+ * cells free, needs <need>)`.
437
+ */
438
+ export declare function parseWorkerWindowFull(text: string): {
439
+ owner: string;
440
+ free: number;
441
+ cells: number;
442
+ needs: number;
443
+ } | undefined;
444
+ /**
445
+ * A worker was refused because its owner's window is full -- not because the
446
+ * server is: grow that owner by the shortfall so the worker fits.
447
+ *
448
+ * The engine prices a worker at its private cells (its prompt and declared
449
+ * reply past the pool it attaches to) against the owner's free cells, and
450
+ * such a refusal asks nothing of the base pool (`refused_needed_max_60s` 0):
451
+ * the cells are there, the owner's booking is what is short. The answer is
452
+ * a bigger owner, never compacting everyone. Bounded by the engine's
453
+ * per-session maximum; the resize itself is bounded by the free base cells
454
+ * (a 429 there means the server really is full, and the worker waits).
455
+ * `true` when the owner grew and the worker should be sent again.
456
+ */
457
+ export declare function growPolykvOwnerForWorker(sessionId: string, refusalText: string): Promise<boolean>;
458
+ /**
459
+ * How recent a landed grow must be for a refusal to count as answered by it:
460
+ * a request refused just before another worker's grow landed is sent again
461
+ * rather than grown twice.
462
+ */
463
+ export declare const POLYKV_GROWN_MEANWHILE_MS = 5000;
464
+ /**
465
+ * The fields of `body` a pool's rendering must be given, so that it renders
466
+ * the prompt the way the server will render this request.
467
+ *
468
+ * Everything but the conversation and this request's own session, rather than
469
+ * a list of the fields known to matter: the server parses `/apply-template`
470
+ * with the chat request's own parser, and a field left out is one more way for
471
+ * the two to disagree. The one that did, on 8240 2026-09-24:
472
+ * `reasoning_budget_tokens: 0` renders Gemma-4's system turn without
473
+ * `<|think|>`, and the pool, rendered without it, had the flag. Every worker
474
+ * request diverged from its pool at token 4 -- 20 attaches of 20 -- and
475
+ * prefilled its whole ~5.6k-token prompt on every turn.
476
+ */
477
+ export declare function templateFieldsOf(body: Readonly<Record<string, unknown>>): Record<string, unknown>;
478
+ /**
479
+ * What in `fields` can change a rendering, for keying pools by it.
480
+ *
481
+ * Not the fields themselves: a request's budget is a share of its output cap,
482
+ * so it moves turn by turn, and a pool keyed on the number would be rebuilt
483
+ * whenever it did. What renders differently is whether there is one -- `0`
484
+ * drops the thinking flag, any other count keeps it (measured on 8240).
485
+ */
486
+ export declare function templateSignature(fields: Readonly<Record<string, unknown>>): string;
487
+ /**
488
+ * The layer's prefix: the conversation so far, rendered by the server, up to
489
+ * and including the opener of the turn that follows it.
490
+ *
491
+ * `fields` are the request's own (`templateFieldsOf`): a layer rendered
492
+ * without them is a different prompt from the one the request renders to.
493
+ */
494
+ export declare function renderLayer(client: PolykvClient, messages: readonly unknown[], tools: readonly unknown[] | undefined, fields?: Readonly<Record<string, unknown>>): Promise<string | undefined>;
495
+ /**
496
+ * How long a layer the engine refused is left alone before it is asked again.
497
+ *
498
+ * A refusal is a state of the owner -- its sub-pools, its window -- that
499
+ * changes as agents end, so it is never remembered for good; this is only
500
+ * the guard against every turn of every agent asking in a tight loop.
501
+ */
502
+ export declare const POLYKV_LAYER_RETRY_MS = 5000;
503
+ /**
504
+ * Whether the engine refused a pool create for want of room: in its owner (the
505
+ * sub-pool limit, a full allocation), or in the KV cache for the prefill --
506
+ * b137 (patch 0412) answers that `503` "no room in the KV cache for the pool
507
+ * prefill" where b133 answered `500`. Each is met the same way: release what
508
+ * the owner holds for nobody, and create again.
509
+ */
510
+ export declare function isPolykvNoRoomRefusal(error: unknown): boolean;
511
+ /**
512
+ * Where this agent's request attaches, creating what it needs.
513
+ *
514
+ * `undefined` pool means "run unpooled": no owner could be opened, or the
515
+ * request is not shaped `[system, ...layers, task]`. The request then goes out
516
+ * as an ordinary session of its own, which is slower, never wrong.
517
+ */
518
+ export declare function preparePolykvWorker(options: {
519
+ spec: PolykvWorkerSpec;
520
+ baseUrl: string;
521
+ fetch: typeof fetch;
522
+ headers?: Record<string, string>;
523
+ body: Record<string, unknown>;
524
+ signal?: AbortSignal | null;
525
+ /** Start on a fresh owner: the current one refused this agent. */
526
+ fresh?: boolean;
527
+ }): Promise<PolykvWorkerAttach>;
528
+ /**
529
+ * A worker refused because its owner's window is full, as the engine words it.
530
+ *
531
+ * Distinct from every other 429 on purpose: this one is a queue on a window
532
+ * other agents are draining, and it may also be answered by opening another
533
+ * owner.
534
+ */
535
+ export declare function isWorkerWindowFull(status: number, text: string): boolean;
536
+ /**
537
+ * Below this many free cells an owner is not worth moving to: a worker's
538
+ * next request charges its whole prompt, and a sliver of room refuses it again.
539
+ */
540
+ export declare const POLYKV_MOVE_MIN_FREE_CELLS = 16384;
541
+ /**
542
+ * Move a refused worker to the open owner with the most room, if one has more
543
+ * than its own.
544
+ *
545
+ * An agent stays on the owner it started on so its private suffix stays warm
546
+ * -- but that rule, alone, stalled a 75-agent swarm on 2026-09-24: the engine's
547
+ * whole KV was booked by four owners, one of them 77% full and refusing its
548
+ * workers, the other three at 3-8%. The refused agents waited on their own
549
+ * owner for up to fifteen minutes while three quarters of the cells sat idle,
550
+ * and a fresh owner could not open because there were no cells left to book.
551
+ * One full reprocess on a roomier owner is cheaper than that queue.
552
+ *
553
+ * Moving the last agent off an owner closes it, as a release would: its window
554
+ * is then free for an owner that has work.
555
+ */
556
+ export declare function movePolykvWorker(sessionId: string): Promise<boolean>;
557
+ /**
558
+ * The agent is done: close its session, and its owner if it was the last.
559
+ *
560
+ * Never throws and never waits on anything but the close calls themselves --
561
+ * this runs on every agent's way out, including the ones being cancelled.
562
+ */
563
+ export interface PolykvReleaseResult {
564
+ /** Engine session ids closed: the engine held them and let them go. */
565
+ closed: string[];
566
+ /** Engine session ids whose close failed, with why. */
567
+ failed: Array<{
568
+ sessionId: string;
569
+ error: string;
570
+ }>;
571
+ /**
572
+ * Closes the engine answered `found: false` for: it held no session under
573
+ * the id. For an agent that sent requests, ours and the engine's have
574
+ * diverged -- a restart, the idle TTL, or an id the wire never carried.
575
+ */
576
+ notFound: string[];
577
+ /**
578
+ * The agent's own session, not closed: the server does not advertise
579
+ * `session_close_v1`, so the route is not there to ask.
580
+ */
581
+ unsupported: string[];
582
+ }
583
+ export declare function releasePolykvAgent(sessionId: string): Promise<PolykvReleaseResult>;
584
+ /**
585
+ * Hold a lead's session close until its last priority-0 agent ends.
586
+ *
587
+ * `true` when the close was deferred -- the caller must not close now -- and
588
+ * `false` when nothing of the swarm is running in that session, so the caller
589
+ * closes as it always did. A second deferral for one lead replaces the first.
590
+ */
591
+ export declare function deferPolykvLeadClose(owner: string, close: () => Promise<unknown>): boolean;
592
+ /** Whether priority-0 agents are running in this lead's session now. */
593
+ export declare function polykvLeadLent(owner: string): boolean;
594
+ /**
595
+ * Whether the lead conversation `group` has agents on the engine at
596
+ * `baseUrl` now: placed on one of its swarm's owners, lent its own window, or
597
+ * waiting for an owner to open. Only then does the lead's own context compete
598
+ * with its own agents for that engine's cells.
599
+ */
600
+ export declare function polykvLeadHasAgentsOn(group: string, baseUrl: string): boolean;
601
+ /**
602
+ * The lead conversation `group` ended: release every owner its swarm opened.
603
+ *
604
+ * Its agents are being stopped with it, and each one's own release lands when
605
+ * its abort does -- or never, on a path that throws before it gets there. So
606
+ * the owners go back with the lead rather than at the engine's idle TTL. The
607
+ * agents' registrations on them are dropped; an agent's own release landing
608
+ * after this still closes its own session. A borrowed owner -- the lead's own
609
+ * session -- gives back the pools the swarm put in it, and a lead close that
610
+ * was deferred on them runs.
611
+ *
612
+ * @returns how many owners were released.
613
+ */
614
+ export declare function releasePolykvSwarmsOf(group: string): Promise<number>;
615
+ /** Close every owner this process holds. For shutdown and for tests. */
616
+ export declare function releaseAllPolykvSwarms(): Promise<void>;
617
+ /** Where an agent's request is while it waits on the engine for room. */
618
+ /** Something about an agent's requests that its row should say. */
619
+ export interface PolykvNotice {
620
+ /** `warn` is a fault the turn survived: it ran, but not as it should have. */
621
+ severity: "info" | "warn";
622
+ /** Worded for the agent's row. */
623
+ text: string;
624
+ }
625
+ /**
626
+ * Be told what the vendor learns about an agent's requests from the engine.
627
+ *
628
+ * The same reach problem as the room wait: the response is read inside this
629
+ * vendor's fetch, where nothing of the agent's UI can be reached. A worker's
630
+ * pool shared 4 tokens of 5,627 on every turn of 2026-09-24 and it reached the
631
+ * server log only. Keyed by the agent's own session id. Returns the
632
+ * unsubscribe.
633
+ */
634
+ export declare function onPolykvNotice(sessionId: string, listener: (notice: PolykvNotice) => void): () => void;
635
+ /**
636
+ * Report a notice for an agent. A repeat of the last one is dropped: a
637
+ * divergence found on every turn is one line on the row, not one per turn.
638
+ */
639
+ export declare function reportPolykvNotice(sessionId: string, notice: PolykvNotice): void;
640
+ /**
641
+ * Hear how much of a request's prompt came from its pool, per response.
642
+ *
643
+ * The engine reports it on the response (`opencoti.n_pool_shared`): the pool
644
+ * prefix a worker attached to and never prefilled. It is part of what the
645
+ * server counts as cached, and the only figure that says how much of the
646
+ * cache was the shared pool and how much the agent's own earlier turns.
647
+ */
648
+ export declare function onPolykvPoolShare(sessionId: string, listener: (tokens: number) => void): () => void;
649
+ /** One response's pool share, for whoever is counting that session's. */
650
+ export declare function reportPolykvPoolShare(sessionId: string, tokens: number): void;
651
+ export interface PolykvRoomWait {
652
+ /** `true` while the request is held client-side, `false` once it is sent. */
653
+ waiting: boolean;
654
+ /** What it is waiting for, worded for the agent's row. */
655
+ reason?: string;
656
+ }
657
+ /**
658
+ * Be told when an agent's requests are held waiting for room on the engine.
659
+ *
660
+ * The wait happens inside this vendor's fetch, where nothing of the agent's UI
661
+ * can be reached, so the agent's row went on saying "running" for as long as
662
+ * it waited -- 75 rows running on 2026-09-24 while the server was processing
663
+ * 27. Keyed by the agent's own session id, as the worker spec carries it.
664
+ * Returns the unsubscribe.
665
+ */
666
+ export declare function onPolykvRoomWait(sessionId: string, listener: (state: PolykvRoomWait) => void): () => void;
667
+ /**
668
+ * Report an agent waiting, or no longer waiting. Only changes are passed on,
669
+ * so a wait of forty refusals is one "waiting" and one "sent".
670
+ */
671
+ export declare function reportPolykvRoomWait(sessionId: string, state: PolykvRoomWait): void;
672
+ /**
673
+ * The least time between two row updates of the same phase kind. A new kind
674
+ * (queued -> prefill) and the end of the phase always go through at once.
675
+ */
676
+ export declare const POLYKV_PHASE_REPORT_MS = 3000;
677
+ /**
678
+ * Be told what an agent's request is doing on the server while its stream is
679
+ * silent: queued, prefilling `n` of `N`, generating with nothing to show
680
+ * (`stream_keepalive_v1`), and `undefined` once it produces again.
681
+ *
682
+ * The same reach problem as the room wait: the heartbeat is read inside this
683
+ * vendor's fetch. Without it a 40k prefill behind a busy server was a row
684
+ * that said nothing for minutes. Keyed by the agent's own session id.
685
+ * Returns the unsubscribe.
686
+ */
687
+ export declare function onPolykvStreamPhase(sessionId: string, listener: (phase: OpencotiStreamPhase | undefined) => void): () => void;
688
+ /**
689
+ * Report an agent's stream phase. Throttled here, once for every listener:
690
+ * a repeat of the same kind within {@link POLYKV_PHASE_REPORT_MS} is dropped,
691
+ * so the row is updated in place every few seconds at most.
692
+ */
693
+ export declare function reportPolykvStreamPhase(sessionId: string, phase: OpencotiStreamPhase | undefined, now?: number): void;
694
+ /** Test seam. */
695
+ export declare function polykvSwarmState(): Array<{
696
+ group: string;
697
+ owners: Array<{
698
+ sessionId: string;
699
+ borrowed?: boolean;
700
+ agents: string[];
701
+ pools: number;
702
+ }>;
703
+ }>;
704
+ export {};
705
+ //# sourceMappingURL=polykv-swarm.d.ts.map