@mountaya/client 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/CHANGELOG.md +149 -0
  2. package/LICENCE.fr.txt +280 -0
  3. package/LICENSE.txt +262 -0
  4. package/README.md +1260 -2
  5. package/dist/admin/index.cjs +2895 -0
  6. package/dist/admin/index.cjs.map +1 -0
  7. package/dist/admin/index.d.cts +889 -0
  8. package/dist/admin/index.d.ts +889 -0
  9. package/dist/admin/index.js +204 -0
  10. package/dist/admin/index.js.map +1 -0
  11. package/dist/browser.cjs +5993 -0
  12. package/dist/browser.cjs.map +1 -0
  13. package/dist/browser.d.cts +70 -0
  14. package/dist/browser.d.ts +70 -0
  15. package/dist/browser.js +22 -0
  16. package/dist/browser.js.map +1 -0
  17. package/dist/chunk-CeEX7ayk.d.cts +75531 -0
  18. package/dist/chunk-CeEX7ayk.d.ts +75531 -0
  19. package/dist/chunk-Cg7Dtcb4.js +2987 -0
  20. package/dist/chunk-Cg7Dtcb4.js.map +1 -0
  21. package/dist/chunk-DJqUsgsy.d.ts +1463 -0
  22. package/dist/chunk-DNc8T5K1.js +241 -0
  23. package/dist/chunk-DNc8T5K1.js.map +1 -0
  24. package/dist/chunk-DTxzw3hu.d.cts +1463 -0
  25. package/dist/chunk-DmxQID5X.js +2289 -0
  26. package/dist/chunk-DmxQID5X.js.map +1 -0
  27. package/dist/chunk-DoZt_oIV.d.ts +3991 -0
  28. package/dist/chunk-DpJrqANO.js +11 -0
  29. package/dist/chunk-Dx8mPAdC.d.cts +3991 -0
  30. package/dist/chunk-X2ukY3ho.js +419 -0
  31. package/dist/chunk-X2ukY3ho.js.map +1 -0
  32. package/dist/events/index.cjs +1436 -0
  33. package/dist/events/index.cjs.map +1 -0
  34. package/dist/events/index.d.cts +772 -0
  35. package/dist/events/index.d.ts +772 -0
  36. package/dist/events/index.js +543 -0
  37. package/dist/events/index.js.map +1 -0
  38. package/dist/index.cjs +5992 -0
  39. package/dist/index.cjs.map +1 -0
  40. package/dist/index.d.cts +44 -0
  41. package/dist/index.d.ts +44 -0
  42. package/dist/index.js +21 -0
  43. package/dist/index.js.map +1 -0
  44. package/package.json +126 -4
  45. package/src/admin/index.ts +47 -0
  46. package/src/admin/rules/mountayaAdmin.ts +102 -0
  47. package/src/browser.ts +233 -0
  48. package/src/core/engines/sessionToken.ts +870 -0
  49. package/src/core/rules/auth.ts +1017 -0
  50. package/src/core/rules/clientHeader.ts +28 -0
  51. package/src/core/rules/dates.ts +200 -0
  52. package/src/core/rules/decode.ts +154 -0
  53. package/src/core/rules/envelope.ts +41 -0
  54. package/src/core/rules/errors.ts +1486 -0
  55. package/src/core/rules/graphql.ts +576 -0
  56. package/src/core/rules/headerValue.ts +42 -0
  57. package/src/core/rules/idempotencyKey.ts +64 -0
  58. package/src/core/rules/nullMask.ts +127 -0
  59. package/src/core/rules/nullMasks.gen.ts +428 -0
  60. package/src/core/rules/paginate.ts +316 -0
  61. package/src/core/rules/rateLimit.ts +507 -0
  62. package/src/core/rules/redaction.ts +219 -0
  63. package/src/core/rules/resourceRef.ts +110 -0
  64. package/src/core/rules/responseBody.ts +492 -0
  65. package/src/core/rules/retry.ts +386 -0
  66. package/src/core/rules/selection.ts +416 -0
  67. package/src/core/rules/sessionAnswer.ts +90 -0
  68. package/src/core/rules/sessionSchedule.ts +131 -0
  69. package/src/core/rules/sessionWait.ts +112 -0
  70. package/src/core/rules/transport.ts +2386 -0
  71. package/src/core/rules/version.gen.ts +16 -0
  72. package/src/core/rules/webAddress.ts +165 -0
  73. package/src/core/rules/webAddresses.gen.ts +30 -0
  74. package/src/data/operations.gen.ts +603 -0
  75. package/src/data/schema.gen.ts +8078 -0
  76. package/src/data/selection.gen.ts +472 -0
  77. package/src/events/index.ts +63 -0
  78. package/src/events/rules/agent.ts +439 -0
  79. package/src/events/rules/collab.ts +554 -0
  80. package/src/events/rules/collabNulls.gen.ts +17 -0
  81. package/src/events/rules/eventStream.ts +94 -0
  82. package/src/events/rules/openSseStream.ts +594 -0
  83. package/src/events/rules/sse.ts +349 -0
  84. package/src/index.ts +231 -0
  85. package/src/rest/adminOperations.gen.ts +70 -0
  86. package/src/rest/adminResources.gen.ts +138 -0
  87. package/src/rest/coreOperations.gen.ts +74 -0
  88. package/src/rest/coreResources.gen.ts +244 -0
  89. package/src/rest/dates.gen.ts +217 -0
  90. package/src/rest/operations.gen.ts +4341 -0
  91. package/src/rest/resources.gen.ts +371 -0
  92. package/src/rest/schema.gen.ts +57027 -0
  93. package/src/tiles/operations.gen.ts +206 -0
  94. package/src/tiles/schema.gen.ts +8406 -0
  95. package/src/webhooks/rules/constructWebhookEvent.ts +482 -0
  96. package/src/webhooks/rules/webhookEvent.ts +38 -0
  97. package/src/webhooks/rules/webhookEvents.gen.ts +732 -0
@@ -0,0 +1,772 @@
1
+ import { $t as AgentRunEvent, Ln as CollabChangeAction, Qt as AgentRunCreateParams, fr as CollabSignalParams, lt as MountayaTransport, m as MountayaError, mr as CollabStreamEvent, rn as AgentRunInputParams } from "../chunk-CeEX7ayk.cjs";
2
+ /**
3
+ * SseFrame is one Server-Sent Events record that carried data: its `id`, its `event` name, and
4
+ * the raw `data` text, still a string the caller parses and validates.
5
+ *
6
+ * `id` is the record's own `id:` field, and the empty string where the record named none. It is
7
+ * the record's, not the stream's: the position a reconnect resumes from carries over from record
8
+ * to record, and {@link SseFrameParser.lastEventId} holds it. A record that carries no `data:` (a
9
+ * heartbeat comment, an `id:` alone) dispatches no frame.
10
+ */
11
+ interface SseFrame {
12
+ /** The record's `data:` lines, joined with newlines, unparsed. */
13
+ data: string;
14
+ /** The record's last `event:` name, or the empty string where it names none. */
15
+ event: string;
16
+ /** The record's own `id:`, or the empty string where it names none. */
17
+ id: string;
18
+ }
19
+ /**
20
+ * MAX_SSE_BUFFER_CHARS caps the text of one record a parser has not seen the end of: every
21
+ * character read since the record began, its line endings and comment lines included. A record
22
+ * ends only at an empty line, so a producer (or a proxy, or a hostile endpoint) that opens a
23
+ * `text/event-stream` and never sends one would grow the parser for as long as the connection
24
+ * lives. The bound turns that resource exhaustion into a fault the caller can act on.
25
+ *
26
+ * 8 MiB is measured against the largest legitimate record rather than the typical one: a
27
+ * collaboration frame is kilobytes (a presence or lock roster, one durable change), so even a
28
+ * megabyte-scale record keeps eightfold headroom while a runaway producer is stopped long before
29
+ * it threatens the tab. The unit is UTF-16 code units, a JavaScript string's own `length`, so a
30
+ * record at the cap costs at most twice this many bytes of heap.
31
+ */
32
+ export declare const MAX_SSE_BUFFER_CHARS: number;
33
+ /**
34
+ * SseBufferOverflowError is thrown by a parser whose unterminated record has passed its cap. It
35
+ * carries the `limit` it enforced, so a consumer can tell a broken producer apart from a network
36
+ * fault when it classifies the failure. It is a fault, not an outcome: the read it surfaces
37
+ * through is torn down rather than reported as a stream that stopped or ended.
38
+ *
39
+ * A parser knows no operation, so what it throws names none. `openSseStream` hands the overflow
40
+ * on as an error of this class that names the stream's operation, keeps the `limit`, and carries
41
+ * the parser's own error as its `cause`.
42
+ *
43
+ * It extends {@link MountayaError}, so the one catch clause this package documents for telling a
44
+ * platform failure from a bug in the calling program, `if (error instanceof MountayaError)`,
45
+ * covers it. A stream torn down by a malformed producer is a platform failure, and an error outside
46
+ * the family would read as the application's own crash.
47
+ */
48
+ export declare class SseBufferOverflowError extends MountayaError {
49
+ readonly name = "SseBufferOverflowError";
50
+ /** The cap the parser enforced, in UTF-16 code units. */
51
+ readonly limit: number;
52
+ /**
53
+ * Builds the error a parser throws once its unterminated record passes the cap.
54
+ *
55
+ * @param limit - the cap the parser enforced, in UTF-16 code units.
56
+ * @param operationId - the operation whose stream overflowed, where the thrower knows it: the
57
+ * message then opens with it and ends with what a reopen would meet.
58
+ * @param options - the standard error options, for the `cause` an opener hands on.
59
+ */
60
+ constructor(limit: number, operationId?: string, options?: ErrorOptions);
61
+ }
62
+ /**
63
+ * SseFrameParser frames the text of a `text/event-stream` body into records, by the HTML
64
+ * standard's event-stream rules:
65
+ *
66
+ * - A line ends at CRLF, LF or a lone CR. A CR ends its line at once, and an LF that follows it,
67
+ * in the same push or at the start of the next, completes that CRLF rather than ending a
68
+ * second, empty line.
69
+ * - A record ends at an empty line. Its `data:` lines join with newlines, its last `event:` names
70
+ * it, and a comment line (a leading `:`, such as a heartbeat) or a field the frame has no slot
71
+ * for (`retry:`) is read past.
72
+ * - One byte-order mark at the start of the stream is dropped.
73
+ * - A record that carries no `data:` dispatches no frame. Its `id:` still moves
74
+ * {@link SseFrameParser.lastEventId}, so a record naming a position and nothing else moves the
75
+ * position a reconnect resumes from.
76
+ * - Every record that carries data dispatches a frame, whatever the data says. No data is an end
77
+ * marker to the parser: what ends a stream is the caller's vocabulary to name.
78
+ *
79
+ * A push may end anywhere, inside a line or inside a record, so the parser holds what is
80
+ * unterminated for the next push. It searches a character for a line ending in the push that
81
+ * delivers it and never again, so framing a long record costs its length however many pushes it
82
+ * arrives in. A character split between two reads of the body arrives whole only if the bytes
83
+ * are decoded across reads, which `readEventStream` does.
84
+ *
85
+ * What it holds is bounded (see {@link MAX_SSE_BUFFER_CHARS}), and only the unterminated record
86
+ * counts: a push carrying many complete records is legitimate however large. Past the cap the
87
+ * parser throws {@link SseBufferOverflowError} and is definitively failed: it releases the text it
88
+ * was holding and refuses every later push, so a caller that swallowed the throw can never resume
89
+ * mid-record and frame the tail of a refused record as a record of its own.
90
+ */
91
+ export declare class SseFrameParser {
92
+ private lineParts;
93
+ private lineLength;
94
+ private dataLines;
95
+ private event;
96
+ private recordId;
97
+ private recordLength;
98
+ private lastId;
99
+ private atStart;
100
+ private afterCarriageReturn;
101
+ private overflowed;
102
+ private readonly maxBufferChars;
103
+ /**
104
+ * Builds a parser that holds at most `maxBufferChars` of a record it has not seen the end of.
105
+ *
106
+ * @param maxBufferChars - bounds the unterminated record this parser holds, in UTF-16 code
107
+ * units: a whole number of 1 or more. A consumer whose frames are known small may tighten
108
+ * it; the shared readers take the default. A cap that is not a number of characters would
109
+ * bound nothing (`NaN` and `Infinity` are exceeded by no length) or refuse every push (zero
110
+ * and below), so it is refused here.
111
+ * @default MAX_SSE_BUFFER_CHARS
112
+ * @throws `MountayaConfigurationError` for a cap that is not a whole number of 1 or more.
113
+ */
114
+ constructor(maxBufferChars?: number);
115
+ /**
116
+ * lastEventId is the stream's last event ID, as the HTML standard defines it: the value of the
117
+ * latest `id:` in a record the parser has seen the end of, whatever else that record carried.
118
+ *
119
+ * It is the position a reconnect resumes from, sent as `Last-Event-ID`. It carries over a
120
+ * record that names no `id:`, an empty `id:` clears it to the empty string, and an `id:` holding
121
+ * U+0000 is ignored. An `id:` in a record still unterminated has not moved it: a reconnect
122
+ * discards that record, so resuming past it would skip it.
123
+ *
124
+ * It is `undefined` until the stream names a position, where the standard starts from the empty
125
+ * string, so a stream that names none reads apart from one that clears it. A caller resuming
126
+ * from a position an earlier connection named keeps that position through the first and drops
127
+ * it at the second.
128
+ */
129
+ get lastEventId(): string | undefined;
130
+ /**
131
+ * push feeds the next decoded text chunk and returns every frame the records it completes
132
+ * dispatch, in stream order. What it leaves unterminated stays held for the next push, unless it
133
+ * passes the cap: then push throws {@link SseBufferOverflowError} instead of returning, dropping
134
+ * the frames the same chunk completed. The stream is being torn down with them, and a caller
135
+ * that resumes re-reads from the position it last recorded.
136
+ */
137
+ push(chunk: string): SseFrame[];
138
+ /**
139
+ * completeLine joins the line held from earlier pushes with its last piece, `tail`, and starts
140
+ * the next line empty.
141
+ */
142
+ private completeLine;
143
+ /**
144
+ * readLine applies one complete line to the current record, and returns the frame the record
145
+ * dispatches when the line is the empty one that ends it.
146
+ *
147
+ * A field line is split at its first colon, and one space after the colon is dropped: only the
148
+ * first space is the standard's separator, and a second one is part of the value. A line with no
149
+ * colon is its whole self as the field name, with an empty value.
150
+ */
151
+ private readLine;
152
+ /**
153
+ * endRecord closes the current record: an `id:` it named becomes the stream's last event ID,
154
+ * and it returns the frame the record dispatches, or null for a record with no data.
155
+ */
156
+ private endRecord;
157
+ /** startRecord empties the record being read, so the next line begins the next one. */
158
+ private startRecord;
159
+ }
160
+ /** AgentEvent is one decoded frame off a run's event stream. */
161
+ type AgentEvent = AgentRunEvent;
162
+ /** AgentInput is one input signal sent into a running run. */
163
+ type AgentInput = AgentRunInputParams;
164
+ /**
165
+ * agentTerminalEventTypes are the event types that end a run: once one is seen the
166
+ * stream is finished and the read stops rather than waiting on the server to hang up.
167
+ * `done` is the sole terminal: an ended run always finishes with one.
168
+ */
169
+ export declare const agentTerminalEventTypes: ReadonlySet<AgentEvent["type"]>;
170
+ /**
171
+ * AgentStreamFrame is one decoded frame paired with its stream position id. A reader
172
+ * records the id of the last frame it consumed, so a reconnect passes it back as
173
+ * `Last-Event-ID` and resumes after it. `id` is the record's own `id:` field, and absent where
174
+ * the record names none: on the API's stream a `message-delta` carries none, since a delta
175
+ * is live and never replayed, and every other frame is numbered. A reader that holds no id
176
+ * resumes as a full replay.
177
+ */
178
+ interface AgentStreamFrame {
179
+ /** The decoded event, discriminated on `type`. */
180
+ event: AgentEvent;
181
+ /** The record's own `id:`, the position a resume passes back; absent where it names none. */
182
+ id?: string | undefined;
183
+ }
184
+ /**
185
+ * AgentStreamCloseReason distinguishes how a run's stream finished without an error:
186
+ * `terminal` means a terminal event was seen, so the run is over; `reconnect` means the API ended
187
+ * the stream and asks for a reopen at once. It says so with a `reconnect` event, when the
188
+ * credential the stream was opened with ends (the session token expires or the key is revoked)
189
+ * and when it cannot keep delivering the stream (`interrupted`: the reader fell behind or the
190
+ * subscription was lost), and a close at or after the token's expiry says the same. None is a
191
+ * failure: the reopen goes at once with the token the client holds then, a new one where the
192
+ * credential ended and the one already held where the stream was interrupted, and the last event
193
+ * id. `ended` means the body closed with no terminal, which mid-run is the server hanging up
194
+ * between turns: a candidate for a resume rather than the end of the run.
195
+ */
196
+ type AgentStreamCloseReason = "terminal" | "reconnect" | "ended";
197
+ /**
198
+ * AgentStreamHandlers are the callbacks a subscriber wires into a run's event stream. The
199
+ * transport drives them as it reads: `onFrame` per decoded frame, `onSkippedFrame` per frame it
200
+ * skips, `onLastEventId` when the run's position moves without a frame to carry it, then exactly
201
+ * one of `onClose` (finished cleanly) or `onError` (it failed). An abort is the subscriber's own
202
+ * teardown and fires neither.
203
+ */
204
+ interface AgentStreamHandlers {
205
+ /** onClose is told once the stream finished with no error, and why. */
206
+ onClose: (reason: AgentStreamCloseReason) => void;
207
+ /**
208
+ * onError receives the failure once. It is an error of the client's family, except a fault the
209
+ * subscriber's own `onFrame`, `onSkippedFrame` or `onLastEventId` threw, which arrives as it was
210
+ * thrown: an open the API refused raises the class a request answered the same way raises, and
211
+ * a connection that failed or broke off raises a `MountayaConnectionError` naming
212
+ * `getAgentRunEvents`.
213
+ */
214
+ onError: (error: unknown) => void;
215
+ /**
216
+ * onFrame receives one decoded frame. It is awaited, so returning a promise backpressures
217
+ * the read: the next frame is pulled only once the current one is handled, which throttles
218
+ * the stream to tool dispatch rather than letting frames pile up ahead of their effects.
219
+ */
220
+ onFrame: (frame: AgentStreamFrame) => void | Promise<void>;
221
+ /**
222
+ * onLastEventId receives the run's stream position when it moves to one no frame carries: a
223
+ * record that names an `id:` and no event, or an empty `id:`, which clears the position and
224
+ * arrives as `undefined`. A subscriber keeping a resume cursor records it as it records a
225
+ * frame's id, so a reopen resumes from the last position the stream named.
226
+ *
227
+ * A frame {@link decodeAgentFrame} skips (a kind this build does not know, or a payload that is
228
+ * not an object) is neither handed to onFrame nor reported here, whatever id it carries, so its
229
+ * position reaches a cursor only once a later frame or record names one. A reopen before then
230
+ * replays it, and it is skipped again.
231
+ */
232
+ onLastEventId?: ((lastEventId: string | undefined) => void) | undefined;
233
+ /**
234
+ * onSkippedFrame is told of each frame the stream delivers that {@link decodeAgentFrame} skips:
235
+ * one naming an event this build does not know, or carrying data it cannot read. Nothing of it
236
+ * is handed over, and it moves no position, but it is a frame the stream delivered, so a reader
237
+ * counting what an open delivered, as a reconnect policy does to tell an open that made progress
238
+ * from one that did not, counts it. A `reconnect`, which is the transport's own, is not one.
239
+ */
240
+ onSkippedFrame?: (() => void) | undefined;
241
+ }
242
+ /**
243
+ * AgentWriteOptions tune one write into a run: starting it, or delivering input into it.
244
+ */
245
+ interface AgentWriteOptions {
246
+ /**
247
+ * The `Idempotency-Key` the write sends on every attempt. Left out, the client draws one for
248
+ * the call. A caller that asks again itself after a failure passes the key it drew for the first
249
+ * ask, so a start whose answer was lost is answered with the run it started rather than a second
250
+ * run.
251
+ */
252
+ readonly idempotencyKey?: string | undefined;
253
+ }
254
+ /**
255
+ * AgentSubscribeOptions tune one open. `lastEventId` resumes the durable history after a
256
+ * position (the server replays past it before resuming the live feed); `signal` tears the
257
+ * open stream down from outside, exactly as the returned unsubscribe does.
258
+ */
259
+ interface AgentSubscribeOptions {
260
+ /** The position to resume after, sent as `Last-Event-ID`; left out, the run replays whole. */
261
+ lastEventId?: string | undefined;
262
+ /** Closes the stream once it aborts, as the unsubscribe `subscribe` returns does. */
263
+ signal?: AbortSignal | undefined;
264
+ }
265
+ /**
266
+ * AgentTransport is the seam an agent session drives: start a run, deliver input into it,
267
+ * and read its events frame by frame.
268
+ *
269
+ * A session takes this interface rather than a client, so an offline or scripted
270
+ * implementation is a plain object. {@link createAgentTransport} is the live one, which gives up
271
+ * an open that never answers and a stream gone silent as connection errors. A transport of your
272
+ * own bounds both waits the same way: the engine waits as long as `subscribe` says nothing. It
273
+ * reports `onClose("terminal")` only after it has handed over a `done`.
274
+ */
275
+ interface AgentTransport {
276
+ /**
277
+ * sendInput delivers one input signal into a running run, resolving once the API took it.
278
+ *
279
+ * @throws the `MountayaApiError` class the API's refusal maps to, or a
280
+ * `MountayaConnectionError` when no answer arrived; in the live transport, a
281
+ * `MountayaConfigurationError` before anything is sent for a routing update naming a server
282
+ * tool under a publishable key.
283
+ */
284
+ sendInput: (runId: string, input: AgentInput, options?: AgentWriteOptions) => Promise<void>;
285
+ /**
286
+ * startRun starts a run and answers its id, which `sendInput` and `subscribe` take.
287
+ *
288
+ * @throws the `MountayaApiError` class the API's refusal maps to, including a 202 that names no
289
+ * run, or a `MountayaConnectionError` when no answer arrived; in the live transport, a
290
+ * `MountayaConfigurationError` before anything is sent for a start naming a server tool under
291
+ * a publishable key.
292
+ */
293
+ startRun: (params: AgentRunCreateParams, options?: AgentWriteOptions) => Promise<{
294
+ runId: string;
295
+ }>;
296
+ /**
297
+ * subscribe opens a run's event stream and returns the function that closes it. Every failure
298
+ * reaches `handlers.onError`; the call itself never throws.
299
+ */
300
+ subscribe: (runId: string, handlers: AgentStreamHandlers, options?: AgentSubscribeOptions) => () => void;
301
+ }
302
+ /**
303
+ * decodeAgentFrame turns one raw SSE frame into a typed event, or null to skip it.
304
+ *
305
+ * The `event:` line is the discriminant and the `data:` line is the payload without it, so
306
+ * the two are combined and the event line wins over any stray `type` in the body. A frame
307
+ * naming a type this build does not know is skipped rather than fatal, which is what makes
308
+ * a newer server emitting a new event a compatible change. The type is looked up among the
309
+ * table's own keys, so a name every object inherits (`constructor`, `toString`) is one this
310
+ * build does not know.
311
+ *
312
+ * No date mask here: nothing in this union carries a timestamp, so the contract generates no
313
+ * event masks for it, unlike the collaboration stream's.
314
+ *
315
+ * The cast is the decision this module is built on: the contract generates the union, so a
316
+ * frame is TYPED by it rather than re-validated against a hand-written transcription. What
317
+ * is checked at runtime is the one field the wire and the type disagree about, the
318
+ * discriminant, which arrives on its own line, and nothing below it. A `tool-call`'s input
319
+ * is `unknown` either way and is validated by the tool bus against the tool's own schema.
320
+ */
321
+ export declare const decodeAgentFrame: (frame: SseFrame) => AgentEvent | null;
322
+ /**
323
+ * createAgentTransport binds an agent run's endpoints to one client's transport.
324
+ *
325
+ * The two writes go through the generated operations, so the path, the method and the
326
+ * error taxonomy are the contract's. The read cannot: a run's event stream is open for as
327
+ * long as the run lasts, and every generated reader either buffers the whole body or arms a
328
+ * per-request timeout across it (see `MountayaTransport.streamSeam` for why). It uses `fetch`
329
+ * rather than `EventSource` because the stream must carry the transport's credential and set
330
+ * `Last-Event-ID` on a reconnect, and `EventSource` supports neither. An open the API refuses
331
+ * raises the class a request answered the same way raises, read off the refusal's body.
332
+ *
333
+ * A start or a routing update whose `server_tools` names anything is refused before it is sent
334
+ * under a publishable key, under which a run calls no server tool. An open waits for a session
335
+ * token the credential's source reports on its way, as a request does. The `reconnect` event the
336
+ * API ends a stream with, when its credential ends or when it cannot keep delivering it
337
+ * (`interrupted`), is never handed to `onFrame`: it ends the read and closes it as `reconnect`,
338
+ * whatever reason it names, and so does a close at or after the expiry of the token the open
339
+ * carried, where the credential's source reports one. A frame it skips is told to
340
+ * `onSkippedFrame`.
341
+ */
342
+ export declare const createAgentTransport: (transport: MountayaTransport) => AgentTransport;
343
+ /**
344
+ * CollabEvent is one decoded frame off a collaboration stream: the contract's union,
345
+ * re-exported under the name the reading code uses.
346
+ */
347
+ type CollabEvent = CollabStreamEvent;
348
+ /**
349
+ * CollabSignal is one signal a member publishes upstream: a selection, a cursor move, a
350
+ * lock acquire or release, a draft update or clear.
351
+ *
352
+ * The inbound and outbound vocabularies are deliberately NOT one type. The server stamps
353
+ * `user_id` on every frame it republishes, and the lock pair disagrees on the discriminant
354
+ * itself (`lock.acquire` goes up, `lock.acquired` comes back), so a shared schema would
355
+ * have to be wrong about one of them.
356
+ */
357
+ type CollabSignal = CollabSignalParams;
358
+ /**
359
+ * CollabDurableChange is the subset of frames reporting a COMMITTED change to a resource,
360
+ * as opposed to the live-only presence, cursor, lock and draft traffic. Its members are the
361
+ * frames carrying an `action`, which is what selects them here: a new change family joins by
362
+ * carrying one rather than by being listed.
363
+ */
364
+ type CollabDurableChange = Extract<CollabEvent, {
365
+ action: CollabChangeAction;
366
+ }>;
367
+ /**
368
+ * CollabStreamResource is the resource whose editor stream is being read: the collection
369
+ * segment of its path and its id.
370
+ *
371
+ * It is the wire's own spelling rather than a domain handle (`itineraries` and `zones` are
372
+ * path segments here, not model names), which is why this package declares it instead of
373
+ * naming one from a package it must not depend on. `@mountaya/elements`' `CollabResource`
374
+ * is structurally identical and assignable to it, and a twin test pins the two.
375
+ */
376
+ interface CollabStreamResource {
377
+ /** The resource's id, as its path carries it. */
378
+ readonly id: string;
379
+ /** The collection segment of the resource's path. */
380
+ readonly kind: "itineraries" | "zones";
381
+ }
382
+ /**
383
+ * CollabStreamFrame is one decoded frame paired with its stream position id. A reader
384
+ * records the id of the last frame it consumed so a reconnect passes it back as
385
+ * `Last-Event-ID` and resumes after it. The id is optional because not every producer
386
+ * numbers its frames, in which case a resume falls back to a full replay.
387
+ */
388
+ interface CollabStreamFrame {
389
+ /** The decoded frame, discriminated on `type`. */
390
+ event: CollabEvent;
391
+ /** The record's own `id:`, the position a resume passes back; absent where it names none. */
392
+ id?: string | undefined;
393
+ }
394
+ /**
395
+ * CollabStreamErrorOptions classify a stream failure for the reader that has to decide
396
+ * whether to reconnect.
397
+ */
398
+ interface CollabStreamErrorOptions {
399
+ /**
400
+ * Whether reopening cannot help: a credential refused before the open, a runtime whose fetch
401
+ * streams no body, a 4xx other than 429 on the open, a producer that never ends a frame, and a
402
+ * fault the subscriber's own `onFrame` or `onLastEventId` threw, which a reopen would hand the
403
+ * same frame again. `false` for a failure a reopen can get past: a dropped connection, a
404
+ * stream gone silent, a 429 and a 5xx.
405
+ */
406
+ terminal?: boolean | undefined;
407
+ }
408
+ /**
409
+ * CollabStreamCloseReason says how a collaboration stream finished without an error:
410
+ * `reconnect` means the API ended it and asks for a reopen at once. It says so with a `reconnect`
411
+ * event, when the credential the stream was opened with ends (the session token expires or the
412
+ * key is revoked) and when it cannot keep delivering the stream (`interrupted`: the reader fell
413
+ * behind or the subscription was lost), and a close at or after the token's expiry says the same.
414
+ * None is a failure: the reopen goes at once with the token the client holds then, a new one
415
+ * where the credential ended and the one already held where the stream was interrupted, and the
416
+ * last event id. `ended` means the body closed on its own, a drop like any other.
417
+ */
418
+ type CollabStreamCloseReason = "reconnect" | "ended";
419
+ /**
420
+ * CollabStreamHandlers are the callbacks a subscriber wires into a collaboration stream.
421
+ * The transport drives them as it reads: `onOpen` once the API has answered the open, `onFrame`
422
+ * per decoded frame, `onSkippedFrame` per frame it skips, `onLastEventId` when the stream's
423
+ * position moves without a frame to carry it, then exactly one of `onClose` (the body finished)
424
+ * or `onError` (it failed). An abort is the subscriber's own teardown and fires none of them
425
+ * after it.
426
+ */
427
+ interface CollabStreamHandlers {
428
+ /** onClose is told once the stream's body finished with no error, and why. */
429
+ onClose: (reason: CollabStreamCloseReason) => void;
430
+ /**
431
+ * onError receives the failure once, classified. It is an error of the client's family, except
432
+ * a fault the subscriber's own `onOpen`, `onFrame`, `onSkippedFrame` or `onLastEventId` threw,
433
+ * which arrives as it was thrown and classified terminal: an open the API refused raises the
434
+ * class a request answered the same way raises, and a connection that failed or broke off raises
435
+ * a `MountayaConnectionError` naming the stream's operation.
436
+ */
437
+ onError: (error: unknown, options?: CollabStreamErrorOptions) => void;
438
+ /** onFrame receives each decoded frame, in the order the stream wrote them. */
439
+ onFrame: (frame: CollabStreamFrame) => void;
440
+ /**
441
+ * onLastEventId receives the stream position when it moves to one no frame carries: a record
442
+ * that names an `id:` and no event, or an empty `id:`, which clears the position and arrives as
443
+ * `undefined`. A subscriber keeping a resume cursor records it, so a reopen resumes from the
444
+ * last position the stream named rather than replaying what it has read.
445
+ *
446
+ * A frame {@link decodeCollabFrame} skips (a kind this build does not know, or a payload that is
447
+ * not an object) is neither handed to onFrame nor reported here, whatever id it carries, so its
448
+ * position reaches a cursor only once a later frame or record names one. A reopen before then
449
+ * replays it, and it is skipped again.
450
+ */
451
+ onLastEventId?: ((lastEventId: string | undefined) => void) | undefined;
452
+ /**
453
+ * onOpen is told once the API has answered the open, before any frame of it, with the user the
454
+ * stream is read as: the user the session token it was opened with names, `userId`, undefined
455
+ * where the credential's source does not say or the token is held as a string or a function,
456
+ * whose user the client is not told. A reader judging its own member's `presence.join` reads
457
+ * that user first, and a user it is told otherwise only where it is undefined.
458
+ */
459
+ onOpen?: ((open: {
460
+ readonly userId: string | undefined;
461
+ }) => void) | undefined;
462
+ /**
463
+ * onSkippedFrame is told of each frame the stream delivers that {@link decodeCollabFrame} skips:
464
+ * one naming a kind this build does not know, or carrying data it cannot read. Nothing of it is
465
+ * handed over, and it moves no position, but it is a frame the stream delivered, so a reader
466
+ * telling an open that made progress from one that did not counts it as one past those every
467
+ * open begins with. A `reconnect`, which is the transport's own, is not one.
468
+ */
469
+ onSkippedFrame?: (() => void) | undefined;
470
+ }
471
+ /**
472
+ * CollabSubscribeOptions tune one open. `lastEventId` resumes the durable history after a
473
+ * position; `signal` tears the open stream down from outside, exactly as the returned
474
+ * unsubscribe does.
475
+ */
476
+ interface CollabSubscribeOptions {
477
+ /** The position to resume after, sent as `Last-Event-ID`; left out, the stream replays whole. */
478
+ lastEventId?: string | undefined;
479
+ /** Closes the stream once it aborts, as the unsubscribe a subscribe returns does. */
480
+ signal?: AbortSignal | undefined;
481
+ }
482
+ /**
483
+ * CollabSignalResult is how a published signal settled. A lock contention is a RESULT
484
+ * rather than a throw: the caller asked whether it may edit an entity and the answer is
485
+ * "no, that member is", which is an outcome of the question rather than a failure to ask
486
+ * it. Every other non-ok status throws from the client's own error family, as the generated
487
+ * operation raises it. A success throws a `MountayaConnectionError` when its body breaks off
488
+ * before it is complete, where the signal was answered and the answer lost, and the base
489
+ * `MountayaApiError` when its body is not JSON, where something on the network path may have
490
+ * answered in the API's place.
491
+ */
492
+ type CollabSignalResult = {
493
+ ok: true;
494
+ } | {
495
+ holderId?: string | undefined;
496
+ ok: false;
497
+ };
498
+ /**
499
+ * CollabTransport is the seam a collaboration session drives: publish one signal, and open
500
+ * either the editor stream for one resource or the organization's event stream.
501
+ *
502
+ * A session takes this interface rather than a client, so an offline or scripted
503
+ * implementation is a plain object. {@link createCollabTransport} is the live one, which gives
504
+ * up an open that never answers and a stream gone silent as connection errors. A transport of
505
+ * your own bounds both waits the same way: the engine waits as long as a stream says nothing.
506
+ */
507
+ interface CollabTransport {
508
+ /**
509
+ * sendSignal publishes one signal for a resource, and answers how it settled: a lock another
510
+ * member holds is a result naming them, never a throw.
511
+ *
512
+ * @throws the client's own error family for every other refusal: see {@link CollabSignalResult}.
513
+ */
514
+ sendSignal: (resource: CollabStreamResource, signal: CollabSignal) => Promise<CollabSignalResult>;
515
+ /**
516
+ * subscribeEditor opens the editor stream of one resource and returns the function that closes
517
+ * it. Every failure reaches `handlers.onError`, classified; the call itself never throws.
518
+ */
519
+ subscribeEditor: (resource: CollabStreamResource, handlers: CollabStreamHandlers, options?: CollabSubscribeOptions) => () => void;
520
+ /**
521
+ * subscribeList opens an organization's event stream, the changes to its itineraries, zones and
522
+ * collections, and returns the function that closes it. Every failure reaches `handlers.onError`, classified; the call itself never throws.
523
+ */
524
+ subscribeList: (organizationId: string, handlers: CollabStreamHandlers, options?: CollabSubscribeOptions) => () => void;
525
+ }
526
+ /**
527
+ * decodeCollabFrame turns one raw SSE frame into a typed event, or null to skip it.
528
+ *
529
+ * The `event:` line is the discriminant and the `data:` line is the payload without it, so
530
+ * the two are combined and the event line wins over any stray `type` in the body. A frame
531
+ * naming a kind this build does not know is skipped rather than fatal: that is what makes
532
+ * a newer API release adding a frame a compatible change rather than a broken stream. The kind
533
+ * is looked up among the table's own keys, so a name every object inherits (`constructor`,
534
+ * `toString`) is one this build does not know.
535
+ *
536
+ * The payload decodes the instants its own event declares, by the mask the contract generates
537
+ * for that event, as every response decodes its operation's. Without it `connected_at` and
538
+ * `occurred_at` would be ISO strings behind a generated type that says `Date`, which is a
539
+ * `getTime is not a function` waiting for the first reader. A member its event types required and
540
+ * nullable, a cursor's `position` or a selection's `selection`, reads null where the frame leaves
541
+ * it out, as it does in an answer. Nothing else is decoded: a draft is an open object a peer is
542
+ * typing, so a timestamp in it stays the string the peer wrote.
543
+ *
544
+ * The cast is the decision this module is built on: the contract generates the union, so a
545
+ * frame is TYPED by it rather than re-validated against a hand-written transcription of it.
546
+ * What is checked at runtime is the one field the wire and the type disagree about (the
547
+ * discriminant, which arrives on a separate line) and nothing below it.
548
+ */
549
+ export declare const decodeCollabFrame: (frame: SseFrame) => CollabEvent | null;
550
+ /**
551
+ * createCollabTransport binds the collaboration streams to one client's transport.
552
+ *
553
+ * It reads the three feeds over `fetch` rather than `EventSource` because they must ride
554
+ * the transport's credential (a cookie session, a publishable key with a session token)
555
+ * and set `Last-Event-ID` on a reconnect, and `EventSource` supports neither. A
556
+ * collaboration stream has no terminal event, so a read finishes only when the body closes,
557
+ * a fault occurs, or the returned unsubscribe aborts it.
558
+ *
559
+ * An open waits for a session token the credential's source reports on its way, as a request
560
+ * does. The `reconnect` event the API ends a stream with, when its credential ends or when it
561
+ * cannot keep delivering it (`interrupted`), is never handed to `onFrame`: it ends the read and
562
+ * closes it as `reconnect`, whatever reason it names, and so does a close at or after the expiry
563
+ * of the token the open carried, where the credential's source reports one. An open the API
564
+ * answers tells `onOpen` the user that token names, and a frame it skips is told to
565
+ * `onSkippedFrame`.
566
+ */
567
+ export declare const createCollabTransport: (transport: MountayaTransport) => CollabTransport;
568
+ /**
569
+ * FrameHandler receives one framed record as readEventStream decodes it. It is
570
+ * awaited, so returning a promise backpressures the read: the next chunk is
571
+ * pulled only once the current frame is handled. Returning (or resolving to)
572
+ * `true` asks the reader to stop early: the caller has seen its own end-of-stream
573
+ * marker and need not wait for the body to close.
574
+ */
575
+ type FrameHandler = (frame: SseFrame) => boolean | void | Promise<boolean> | Promise<void>;
576
+ /**
577
+ * EventStreamOutcome reports why readEventStream returned: `stopped` when a frame
578
+ * handler asked to stop early (it recognized the caller's terminator), `ended`
579
+ * when the body closed on its own with no such request.
580
+ */
581
+ type EventStreamOutcome = "stopped" | "ended";
582
+ /**
583
+ * readEventStream reads a `text/event-stream` body to its end. It pulls each chunk from the body's
584
+ * reader, decodes it as UTF-8 across reads (so a character two reads split arrives whole), frames
585
+ * it with {@link SseFrameParser}, and hands every frame to `onFrame`. It knows nothing of the
586
+ * payload's shape or vocabulary: the caller decodes and validates each frame's data. Awaiting
587
+ * `onFrame` lets a slow handler backpressure the read, and a handler that returns `true` stops
588
+ * the read at once rather than waiting on the producer to hang up. It returns `stopped` when a
589
+ * handler stopped the read and `ended` when the body closed first.
590
+ *
591
+ * `onLastEventId`, where the caller passes one, receives the stream's last event ID (see
592
+ * {@link SseFrameParser.lastEventId}) whenever it moves to a value the frames handed to `onFrame`
593
+ * do not carry: after a record that names an `id:` and carries no `data:`, which dispatches no
594
+ * frame, and after an empty `id:`, which clears the position to the empty string while the frame's
595
+ * own id reads empty either way. An empty `id:` is reported even before the stream names any other
596
+ * position, so a cursor carried over from an earlier connection is dropped, while a stream that
597
+ * names no `id:` at all reports nothing and leaves it where it was. A frame carries its record's
598
+ * id itself, so a caller keeping a resume cursor records both, and its cursor is the position a
599
+ * reconnect resumes from. The callback runs once the frames a read completed are handled, so the
600
+ * position it reports never passes a frame `onFrame` has not seen, and a read that stops or fails
601
+ * before then reports none.
602
+ *
603
+ * A producer that never terminates a record is the one fault the reader raises on its own: past
604
+ * the parser's cap the read throws `SseBufferOverflowError` rather than buffer without bound.
605
+ * That is deliberately not an outcome: `stopped` and `ended` both describe a stream that framed
606
+ * what it was sent, and a caller reconnecting on a clean close must not mistake a broken producer
607
+ * for one.
608
+ *
609
+ * The reader's lock is released however the read finishes, and the body is left as it is: after
610
+ * `stopped` or a throw, the connection behind it stays open until the caller, whose body it is,
611
+ * cancels it or aborts the request that opened it.
612
+ */
613
+ export declare const readEventStream: (body: ReadableStream<Uint8Array>, onFrame: FrameHandler, onLastEventId?: (lastEventId: string) => void) => Promise<EventStreamOutcome>;
614
+ /**
615
+ * OpenSseStreamOptions configure one open of a resumable Server-Sent Events read
616
+ * over fetch. The caller supplies the network seam (doFetch + applyAuth), the URL and
617
+ * the operation it opens, an optional resume position and external abort, and the
618
+ * feature-specific policy: how to decode a raw frame and what to do with each decoded
619
+ * event. The vocabulary stays with the caller (decode returns the caller's own event
620
+ * type), so this reader knows no feature's schema.
621
+ */
622
+ interface OpenSseStreamOptions<TEvent> {
623
+ /**
624
+ * applyAuth folds the host's credential into the request's RequestInit.
625
+ *
626
+ * `method` reaches it because the published seam takes one, for the wording of a refusal.
627
+ *
628
+ * What the stream's operation declares does not reach it, because this reader knows the
629
+ * operation by name alone. An opener states it in the closure it passes, as the collaboration
630
+ * and agent transports do over `MountayaTransport.streamSeam`: the session token every stream
631
+ * requires, that it acts as the member that token names, and, by saying nothing, that no
632
+ * stream accepts a share token. The seam refuses a credential that cannot meet them locally,
633
+ * which for a share token is the only place the rule is named: the server answers one sent where
634
+ * it is not accepted with a 401, as if no credential had been sent. A refusal thrown here
635
+ * surfaces through onError like any other failed open.
636
+ */
637
+ applyAuth: (init: RequestInit, method: string) => RequestInit;
638
+ /** decode turns one raw SSE frame into a typed event, or null to skip it. */
639
+ decode: (frame: SseFrame) => TEvent | null;
640
+ /** doFetch is the fetch implementation: the real one, or a test double. */
641
+ doFetch: typeof fetch;
642
+ /** lastEventId resumes the stream after a position via the Last-Event-ID header. */
643
+ lastEventId?: string | undefined;
644
+ /** onClose runs once when the body finishes, told why the read returned. */
645
+ onClose?: ((outcome: EventStreamOutcome) => void) | undefined;
646
+ /**
647
+ * onResponse is told of the open's answer once it arrives, a refusal's as well as a stream's,
648
+ * before the stream is read or the refusal classified. The openers of this entry point pass
649
+ * `MountayaTransport.streamSeam`'s `report`, so the client's own `onResponse` hears of every
650
+ * open. A fault it throws fails the open, as a fault of `applyAuth` does.
651
+ */
652
+ onResponse?: ((response: Response) => void) | undefined;
653
+ /**
654
+ * onError runs once on a failure that is not the caller's own abort (an abort is a silent
655
+ * teardown and fires neither onClose nor onError).
656
+ *
657
+ * What it receives is an error of this package's family, except a fault the caller's own
658
+ * `applyAuth`, `decode`, `onFrame` or `onLastEventId` threw, which arrives as it was thrown:
659
+ * - an open the API refused raises what a request the API answered the same way raises (the
660
+ * class its status and first entry decide, carrying the entries, the `code` and the metadata),
661
+ * so a `402` is a `MountayaBillingError` and a `409` naming a held lock a `MountayaConflictError`. Its body
662
+ * is read under a bound on time and one on size, and past either the status alone decides the
663
+ * class;
664
+ * - a request that failed before a response arrived and a body that broke off mid-read raise a
665
+ * `MountayaConnectionError` carrying the runtime's failure as its `cause`, and an ok answer
666
+ * with no body raises one with no `cause`, since no runtime failure lies behind it;
667
+ * - an open with no response within {@link OpenSseStreamOptions.timeoutMs}, and a stream that
668
+ * delivered nothing for the stall window, raise a `MountayaConnectionError` that says which
669
+ * wait ran out, with no `cause`: the request is aborted and its body let go first;
670
+ * - a `timeoutMs` out of range raises a `MountayaConfigurationError` naming it, and nothing is
671
+ * opened;
672
+ * - a runtime whose fetch exposes no response body to stream raises a
673
+ * `MountayaConfigurationError`, since every reopen meets the same runtime;
674
+ * - a producer past the frame parser's cap raises a `SseBufferOverflowError` naming the
675
+ * operation, with the parser's own error as its `cause`;
676
+ * - a credential the transports' stream seam refuses in applyAuth, and a failure the fetch raised
677
+ * from inside the family, are already of the family and arrive as they were thrown.
678
+ */
679
+ onError?: ((error: unknown) => void) | undefined;
680
+ /**
681
+ * onFrame receives each decoded event with its stream position id and returns
682
+ * whether to stop the read (a terminal event). Returning a promise backpressures
683
+ * the read: the next frame is pulled only once it settles.
684
+ */
685
+ onFrame: (event: TEvent, id: string | undefined) => boolean | Promise<boolean>;
686
+ /**
687
+ * onLastEventId receives the stream's position when it moves to one no frame handed to
688
+ * onFrame carries: a record that names an `id:` and no `data:`, which dispatches no frame, or
689
+ * an empty `id:`, even one before the stream names any other position, which clears the
690
+ * position and arrives as `undefined`. A caller keeping a resume cursor records it as it records
691
+ * a frame's id, so a reopen from the cursor resumes from the last position the stream named. It
692
+ * runs only once the frames before it are handled (see `readEventStream`).
693
+ *
694
+ * A frame decode skips is neither handed to onFrame nor reported, whatever id it carries, so its
695
+ * position reaches a cursor only once a later frame or record names one. A reopen before then
696
+ * replays it, and decode skips it again.
697
+ */
698
+ onLastEventId?: ((lastEventId: string | undefined) => void) | undefined;
699
+ /**
700
+ * operationId names the operation the stream opens, and every failure this open builds names it
701
+ * too: a refusal, a connection failure, and an answer with no body to read
702
+ * (`getAgentRunEvents: 403 FORBIDDEN …`), and so does the frame parser's overflow, which is
703
+ * handed on as a `SseBufferOverflowError` naming it. A failure handed on as it was thrown keeps
704
+ * its own message.
705
+ */
706
+ operationId: string;
707
+ /** signal is an external abort that tears the open stream down like the returned close. */
708
+ signal?: AbortSignal | undefined;
709
+ /**
710
+ * timeoutMs bounds the open's wait for its response, in milliseconds: past it the request is
711
+ * aborted and onError receives a `MountayaConnectionError` naming the wait. A whole number from
712
+ * 1 to 2,147,483,647; anything else fails the open with a `MountayaConfigurationError` before a
713
+ * request is made. The agent and collaboration transports pass the client's own per-attempt
714
+ * `timeoutMs`, which `MountayaTransport.streamSeam` carries, so their opens wait what a request
715
+ * of the same client waits.
716
+ *
717
+ * Once the response arrives the wait that follows is the stream's silence, which is bounded on
718
+ * its own: a stream that delivers nothing, not even the heartbeat comment the API writes to
719
+ * every live stream, for the stall window is given up the same way.
720
+ *
721
+ * @default the stall window, 45,000 ms, so no wait on the network is unbounded.
722
+ */
723
+ timeoutMs?: number | undefined;
724
+ /**
725
+ * waitForSession is called before each open's credential is applied, with the open's own
726
+ * signal, and the promise it answers is awaited, so a session token on its way is the one the
727
+ * open carries; `undefined` is nothing to wait for, and the open is made at once. The openers of
728
+ * this entry point pass `MountayaTransport.streamSeam`'s, which waits for a token the
729
+ * credential's source reports on its way, as a request does. What it rejects with reaches
730
+ * onError like any other failed open, and a close during the wait ends it silently.
731
+ */
732
+ waitForSession?: ((signal: AbortSignal) => Promise<void> | undefined) | undefined;
733
+ /**
734
+ * url is the fully-qualified stream endpoint, or a function answering it. A function is called
735
+ * once, when the open is made, and what it throws reaches onError as a failed open: an opener
736
+ * whose resolver refuses a path (`StreamSeam.url` does, for one that leaves the API) passes the
737
+ * call rather than its answer.
738
+ */
739
+ url: string | (() => string);
740
+ }
741
+ /**
742
+ * openSseStream opens one resumable `text/event-stream` read over fetch and returns
743
+ * a close function that aborts it. It is the scaffolding every SSE consumer repeats:
744
+ * it forwards an external abort into its own controller, sets Accept and an optional
745
+ * Last-Event-ID, makes the request, decodes each frame through the caller's decode,
746
+ * hands each decoded event to onFrame (whose return stops the read on a terminal), and
747
+ * settles through onClose or, on a failure, onError. The reader stays vocabulary-free:
748
+ * every feature keeps its own decode and schema and shares only this transport shell.
749
+ *
750
+ * The call itself never throws and always returns the close. Whatever fails, a `timeoutMs` out
751
+ * of range, a `lastEventId` no request header carries, a credential or a path its seam refuses,
752
+ * reaches onError. `onFrame`, `onLastEventId`, `onClose` and `onError` run after the close has
753
+ * been returned; `url`, where it is a function, `applyAuth` and `doFetch` are each called once
754
+ * inside the call. An open under a `signal` that has already aborted reads no credential and
755
+ * makes no request.
756
+ *
757
+ * The connection lives exactly as long as the read. Once the read ends for any reason (a
758
+ * terminal frame, the body closing, a failure) the request is aborted and its body let go, so a
759
+ * stopped read leaves no socket open behind it, and then onClose or onError runs, once. A caller's
760
+ * abort, through the returned close or `signal`, is the caller's own teardown: it fires neither,
761
+ * and no frame is handed over after it. The returned close is inert once the stream has settled,
762
+ * and the listener on `signal` is removed then, so a signal that outlives many streams holds none
763
+ * of them.
764
+ *
765
+ * No wait on the network is unbounded. The wait for the response ends at `timeoutMs`, and each
766
+ * wait for the next chunk of the body ends once the stream has delivered nothing, not even a
767
+ * heartbeat comment, for the stall window. Either ends the read as a `MountayaConnectionError`,
768
+ * the failure a caller reopens on, rather than as a read that never settles. The time a frame
769
+ * handler holds the read is the caller's, and never counts as the stream's silence.
770
+ */
771
+ export declare const openSseStream: <TEvent>(options: OpenSseStreamOptions<TEvent>) => (() => void);
772
+ export type { AgentEvent, AgentInput, AgentStreamCloseReason, AgentStreamFrame, AgentStreamHandlers, AgentSubscribeOptions, AgentTransport, AgentWriteOptions, CollabDurableChange, CollabEvent, CollabSignal, CollabSignalResult, CollabStreamCloseReason, CollabStreamErrorOptions, CollabStreamFrame, CollabStreamHandlers, CollabStreamResource, CollabSubscribeOptions, CollabTransport, EventStreamOutcome, FrameHandler, OpenSseStreamOptions, SseFrame };