@mountaya/client 0.1.0 → 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 (67) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +2 -2
  3. package/dist/admin/index.cjs +2876 -3502
  4. package/dist/admin/index.cjs.map +1 -1
  5. package/dist/admin/index.d.cts +731 -912
  6. package/dist/admin/index.d.ts +731 -912
  7. package/dist/admin/index.js +188 -285
  8. package/dist/admin/index.js.map +1 -1
  9. package/dist/browser.cjs +5913 -7993
  10. package/dist/browser.cjs.map +1 -1
  11. package/dist/browser.d.cts +42 -78
  12. package/dist/browser.d.ts +42 -78
  13. package/dist/browser.js +18 -49
  14. package/dist/browser.js.map +1 -1
  15. package/dist/chunk-CeEX7ayk.d.cts +75531 -0
  16. package/dist/chunk-CeEX7ayk.d.ts +75531 -0
  17. package/dist/chunk-Cg7Dtcb4.js +2987 -0
  18. package/dist/chunk-Cg7Dtcb4.js.map +1 -0
  19. package/dist/chunk-DJqUsgsy.d.ts +1463 -0
  20. package/dist/chunk-DNc8T5K1.js +241 -0
  21. package/dist/chunk-DNc8T5K1.js.map +1 -0
  22. package/dist/chunk-DTxzw3hu.d.cts +1463 -0
  23. package/dist/chunk-DmxQID5X.js +2289 -0
  24. package/dist/chunk-DmxQID5X.js.map +1 -0
  25. package/dist/chunk-DoZt_oIV.d.ts +3991 -0
  26. package/dist/chunk-DpJrqANO.js +11 -0
  27. package/dist/chunk-Dx8mPAdC.d.cts +3991 -0
  28. package/dist/chunk-X2ukY3ho.js +419 -0
  29. package/dist/chunk-X2ukY3ho.js.map +1 -0
  30. package/dist/events/index.cjs +1338 -1874
  31. package/dist/events/index.cjs.map +1 -1
  32. package/dist/events/index.d.cts +373 -382
  33. package/dist/events/index.d.ts +373 -382
  34. package/dist/events/index.js +523 -806
  35. package/dist/events/index.js.map +1 -1
  36. package/dist/index.cjs +5908 -7988
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.cts +37 -69
  39. package/dist/index.d.ts +37 -69
  40. package/dist/index.js +17 -48
  41. package/dist/index.js.map +1 -1
  42. package/package.json +7 -8
  43. package/src/browser.ts +1 -0
  44. package/src/core/rules/clientHeader.ts +1 -1
  45. package/src/core/rules/errors.ts +1 -1
  46. package/src/core/rules/nullMasks.gen.ts +14 -2
  47. package/src/core/rules/version.gen.ts +1 -1
  48. package/src/events/index.ts +1 -5
  49. package/src/rest/adminResources.gen.ts +2 -0
  50. package/src/rest/dates.gen.ts +1 -1
  51. package/src/rest/resources.gen.ts +2 -0
  52. package/src/rest/schema.gen.ts +247 -60
  53. package/src/tiles/schema.gen.ts +1 -3
  54. package/dist/chunk-BM526BHG.js +0 -342
  55. package/dist/chunk-BM526BHG.js.map +0 -1
  56. package/dist/chunk-D2YEVTG7.js +0 -327
  57. package/dist/chunk-D2YEVTG7.js.map +0 -1
  58. package/dist/chunk-OHKVUREN.js +0 -3500
  59. package/dist/chunk-OHKVUREN.js.map +0 -1
  60. package/dist/chunk-TDTK2L5H.js +0 -3842
  61. package/dist/chunk-TDTK2L5H.js.map +0 -1
  62. package/dist/coreOperations.gen-BMYPoBbz.d.ts +0 -1760
  63. package/dist/coreOperations.gen-BxX5xRxw.d.cts +0 -1760
  64. package/dist/errors-B-GqAtQv.d.cts +0 -75960
  65. package/dist/errors-B-GqAtQv.d.ts +0 -75960
  66. package/dist/operations.gen-CvTyzKNF.d.cts +0 -3993
  67. package/dist/operations.gen-DUD406TV.d.ts +0 -3993
@@ -1,7 +1,4 @@
1
- import { MountayaError, AgentRunEvent, AgentRunInputParams, AgentRunCreateParams, CollabStreamEvent, CollabChangeAction, CollabSignalParams } from '../browser.cjs';
2
- import { MountayaTransport } from '../index.cjs';
3
- import 'geojson';
4
-
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";
5
2
  /**
6
3
  * SseFrame is one Server-Sent Events record that carried data: its `id`, its `event` name, and
7
4
  * the raw `data` text, still a string the caller parses and validates.
@@ -12,12 +9,12 @@ import 'geojson';
12
9
  * heartbeat comment, an `id:` alone) dispatches no frame.
13
10
  */
14
11
  interface SseFrame {
15
- /** The record's `data:` lines, joined with newlines, unparsed. */
16
- data: string;
17
- /** The record's last `event:` name, or the empty string where it names none. */
18
- event: string;
19
- /** The record's own `id:`, or the empty string where it names none. */
20
- id: string;
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;
21
18
  }
22
19
  /**
23
20
  * MAX_SSE_BUFFER_CHARS caps the text of one record a parser has not seen the end of: every
@@ -32,7 +29,7 @@ interface SseFrame {
32
29
  * it threatens the tab. The unit is UTF-16 code units, a JavaScript string's own `length`, so a
33
30
  * record at the cap costs at most twice this many bytes of heap.
34
31
  */
35
- declare const MAX_SSE_BUFFER_CHARS: number;
32
+ export declare const MAX_SSE_BUFFER_CHARS: number;
36
33
  /**
37
34
  * SseBufferOverflowError is thrown by a parser whose unterminated record has passed its cap. It
38
35
  * carries the `limit` it enforced, so a consumer can tell a broken producer apart from a network
@@ -48,19 +45,19 @@ declare const MAX_SSE_BUFFER_CHARS: number;
48
45
  * covers it. A stream torn down by a malformed producer is a platform failure, and an error outside
49
46
  * the family would read as the application's own crash.
50
47
  */
51
- declare class SseBufferOverflowError extends MountayaError {
52
- readonly name = "SseBufferOverflowError";
53
- /** The cap the parser enforced, in UTF-16 code units. */
54
- readonly limit: number;
55
- /**
56
- * Builds the error a parser throws once its unterminated record passes the cap.
57
- *
58
- * @param limit - the cap the parser enforced, in UTF-16 code units.
59
- * @param operationId - the operation whose stream overflowed, where the thrower knows it: the
60
- * message then opens with it and ends with what a reopen would meet.
61
- * @param options - the standard error options, for the `cause` an opener hands on.
62
- */
63
- constructor(limit: number, operationId?: string, options?: ErrorOptions);
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);
64
61
  }
65
62
  /**
66
63
  * SseFrameParser frames the text of a `text/event-stream` body into records, by the HTML
@@ -91,76 +88,75 @@ declare class SseBufferOverflowError extends MountayaError {
91
88
  * was holding and refuses every later push, so a caller that swallowed the throw can never resume
92
89
  * mid-record and frame the tail of a refused record as a record of its own.
93
90
  */
94
- declare class SseFrameParser {
95
- private lineParts;
96
- private lineLength;
97
- private dataLines;
98
- private event;
99
- private recordId;
100
- private recordLength;
101
- private lastId;
102
- private atStart;
103
- private afterCarriageReturn;
104
- private overflowed;
105
- private readonly maxBufferChars;
106
- /**
107
- * Builds a parser that holds at most `maxBufferChars` of a record it has not seen the end of.
108
- *
109
- * @param maxBufferChars - bounds the unterminated record this parser holds, in UTF-16 code
110
- * units: a whole number of 1 or more. A consumer whose frames are known small may tighten
111
- * it; the shared readers take the default. A cap that is not a number of characters would
112
- * bound nothing (`NaN` and `Infinity` are exceeded by no length) or refuse every push (zero
113
- * and below), so it is refused here.
114
- * @default MAX_SSE_BUFFER_CHARS
115
- * @throws `MountayaConfigurationError` for a cap that is not a whole number of 1 or more.
116
- */
117
- constructor(maxBufferChars?: number);
118
- /**
119
- * lastEventId is the stream's last event ID, as the HTML standard defines it: the value of the
120
- * latest `id:` in a record the parser has seen the end of, whatever else that record carried.
121
- *
122
- * It is the position a reconnect resumes from, sent as `Last-Event-ID`. It carries over a
123
- * record that names no `id:`, an empty `id:` clears it to the empty string, and an `id:` holding
124
- * U+0000 is ignored. An `id:` in a record still unterminated has not moved it: a reconnect
125
- * discards that record, so resuming past it would skip it.
126
- *
127
- * It is `undefined` until the stream names a position, where the standard starts from the empty
128
- * string, so a stream that names none reads apart from one that clears it. A caller resuming
129
- * from a position an earlier connection named keeps that position through the first and drops
130
- * it at the second.
131
- */
132
- get lastEventId(): string | undefined;
133
- /**
134
- * push feeds the next decoded text chunk and returns every frame the records it completes
135
- * dispatch, in stream order. What it leaves unterminated stays held for the next push, unless it
136
- * passes the cap: then push throws {@link SseBufferOverflowError} instead of returning, dropping
137
- * the frames the same chunk completed. The stream is being torn down with them, and a caller
138
- * that resumes re-reads from the position it last recorded.
139
- */
140
- push(chunk: string): SseFrame[];
141
- /**
142
- * completeLine joins the line held from earlier pushes with its last piece, `tail`, and starts
143
- * the next line empty.
144
- */
145
- private completeLine;
146
- /**
147
- * readLine applies one complete line to the current record, and returns the frame the record
148
- * dispatches when the line is the empty one that ends it.
149
- *
150
- * A field line is split at its first colon, and one space after the colon is dropped: only the
151
- * first space is the standard's separator, and a second one is part of the value. A line with no
152
- * colon is its whole self as the field name, with an empty value.
153
- */
154
- private readLine;
155
- /**
156
- * endRecord closes the current record: an `id:` it named becomes the stream's last event ID,
157
- * and it returns the frame the record dispatches, or null for a record with no data.
158
- */
159
- private endRecord;
160
- /** startRecord empties the record being read, so the next line begins the next one. */
161
- private startRecord;
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;
162
159
  }
163
-
164
160
  /** AgentEvent is one decoded frame off a run's event stream. */
165
161
  type AgentEvent = AgentRunEvent;
166
162
  /** AgentInput is one input signal sent into a running run. */
@@ -170,7 +166,7 @@ type AgentInput = AgentRunInputParams;
170
166
  * stream is finished and the read stops rather than waiting on the server to hang up.
171
167
  * `done` is the sole terminal: an ended run always finishes with one.
172
168
  */
173
- declare const agentTerminalEventTypes: ReadonlySet<AgentEvent["type"]>;
169
+ export declare const agentTerminalEventTypes: ReadonlySet<AgentEvent["type"]>;
174
170
  /**
175
171
  * AgentStreamFrame is one decoded frame paired with its stream position id. A reader
176
172
  * records the id of the last frame it consumed, so a reconnect passes it back as
@@ -180,10 +176,10 @@ declare const agentTerminalEventTypes: ReadonlySet<AgentEvent["type"]>;
180
176
  * resumes as a full replay.
181
177
  */
182
178
  interface AgentStreamFrame {
183
- /** The decoded event, discriminated on `type`. */
184
- event: AgentEvent;
185
- /** The record's own `id:`, the position a resume passes back; absent where it names none. */
186
- id?: string | undefined;
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;
187
183
  }
188
184
  /**
189
185
  * AgentStreamCloseReason distinguishes how a run's stream finished without an error:
@@ -206,54 +202,54 @@ type AgentStreamCloseReason = "terminal" | "reconnect" | "ended";
206
202
  * teardown and fires neither.
207
203
  */
208
204
  interface AgentStreamHandlers {
209
- /** onClose is told once the stream finished with no error, and why. */
210
- onClose: (reason: AgentStreamCloseReason) => void;
211
- /**
212
- * onError receives the failure once. It is an error of the client's family, except a fault the
213
- * subscriber's own `onFrame`, `onSkippedFrame` or `onLastEventId` threw, which arrives as it was
214
- * thrown: an open the API refused raises the class a request answered the same way raises, and
215
- * a connection that failed or broke off raises a `MountayaConnectionError` naming
216
- * `getAgentRunEvents`.
217
- */
218
- onError: (error: unknown) => void;
219
- /**
220
- * onFrame receives one decoded frame. It is awaited, so returning a promise backpressures
221
- * the read: the next frame is pulled only once the current one is handled, which throttles
222
- * the stream to tool dispatch rather than letting frames pile up ahead of their effects.
223
- */
224
- onFrame: (frame: AgentStreamFrame) => void | Promise<void>;
225
- /**
226
- * onLastEventId receives the run's stream position when it moves to one no frame carries: a
227
- * record that names an `id:` and no event, or an empty `id:`, which clears the position and
228
- * arrives as `undefined`. A subscriber keeping a resume cursor records it as it records a
229
- * frame's id, so a reopen resumes from the last position the stream named.
230
- *
231
- * A frame {@link decodeAgentFrame} skips (a kind this build does not know, or a payload that is
232
- * not an object) is neither handed to onFrame nor reported here, whatever id it carries, so its
233
- * position reaches a cursor only once a later frame or record names one. A reopen before then
234
- * replays it, and it is skipped again.
235
- */
236
- onLastEventId?: ((lastEventId: string | undefined) => void) | undefined;
237
- /**
238
- * onSkippedFrame is told of each frame the stream delivers that {@link decodeAgentFrame} skips:
239
- * one naming an event this build does not know, or carrying data it cannot read. Nothing of it
240
- * is handed over, and it moves no position, but it is a frame the stream delivered, so a reader
241
- * counting what an open delivered, as a reconnect policy does to tell an open that made progress
242
- * from one that did not, counts it. A `reconnect`, which is the transport's own, is not one.
243
- */
244
- onSkippedFrame?: (() => void) | undefined;
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;
245
241
  }
246
242
  /**
247
243
  * AgentWriteOptions tune one write into a run: starting it, or delivering input into it.
248
244
  */
249
245
  interface AgentWriteOptions {
250
- /**
251
- * The `Idempotency-Key` the write sends on every attempt. Left out, the client draws one for
252
- * the call. A caller that asks again itself after a failure passes the key it drew for the first
253
- * ask, so a start whose answer was lost is answered with the run it started rather than a second
254
- * run.
255
- */
256
- readonly idempotencyKey?: string | undefined;
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;
257
253
  }
258
254
  /**
259
255
  * AgentSubscribeOptions tune one open. `lastEventId` resumes the durable history after a
@@ -261,10 +257,10 @@ interface AgentWriteOptions {
261
257
  * open stream down from outside, exactly as the returned unsubscribe does.
262
258
  */
263
259
  interface AgentSubscribeOptions {
264
- /** The position to resume after, sent as `Last-Event-ID`; left out, the run replays whole. */
265
- lastEventId?: string | undefined;
266
- /** Closes the stream once it aborts, as the unsubscribe `subscribe` returns does. */
267
- signal?: AbortSignal | undefined;
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;
268
264
  }
269
265
  /**
270
266
  * AgentTransport is the seam an agent session drives: start a run, deliver input into it,
@@ -277,31 +273,31 @@ interface AgentSubscribeOptions {
277
273
  * reports `onClose("terminal")` only after it has handed over a `done`.
278
274
  */
279
275
  interface AgentTransport {
280
- /**
281
- * sendInput delivers one input signal into a running run, resolving once the API took it.
282
- *
283
- * @throws the `MountayaApiError` class the API's refusal maps to, or a
284
- * `MountayaConnectionError` when no answer arrived; in the live transport, a
285
- * `MountayaConfigurationError` before anything is sent for a routing update naming a server
286
- * tool under a publishable key.
287
- */
288
- sendInput: (runId: string, input: AgentInput, options?: AgentWriteOptions) => Promise<void>;
289
- /**
290
- * startRun starts a run and answers its id, which `sendInput` and `subscribe` take.
291
- *
292
- * @throws the `MountayaApiError` class the API's refusal maps to, including a 202 that names no
293
- * run, or a `MountayaConnectionError` when no answer arrived; in the live transport, a
294
- * `MountayaConfigurationError` before anything is sent for a start naming a server tool under
295
- * a publishable key.
296
- */
297
- startRun: (params: AgentRunCreateParams, options?: AgentWriteOptions) => Promise<{
298
- runId: string;
299
- }>;
300
- /**
301
- * subscribe opens a run's event stream and returns the function that closes it. Every failure
302
- * reaches `handlers.onError`; the call itself never throws.
303
- */
304
- subscribe: (runId: string, handlers: AgentStreamHandlers, options?: AgentSubscribeOptions) => () => void;
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;
305
301
  }
306
302
  /**
307
303
  * decodeAgentFrame turns one raw SSE frame into a typed event, or null to skip it.
@@ -322,7 +318,7 @@ interface AgentTransport {
322
318
  * discriminant, which arrives on its own line, and nothing below it. A `tool-call`'s input
323
319
  * is `unknown` either way and is validated by the tool bus against the tool's own schema.
324
320
  */
325
- declare const decodeAgentFrame: (frame: SseFrame) => AgentEvent | null;
321
+ export declare const decodeAgentFrame: (frame: SseFrame) => AgentEvent | null;
326
322
  /**
327
323
  * createAgentTransport binds an agent run's endpoints to one client's transport.
328
324
  *
@@ -343,8 +339,7 @@ declare const decodeAgentFrame: (frame: SseFrame) => AgentEvent | null;
343
339
  * carried, where the credential's source reports one. A frame it skips is told to
344
340
  * `onSkippedFrame`.
345
341
  */
346
- declare const createAgentTransport: (transport: MountayaTransport) => AgentTransport;
347
-
342
+ export declare const createAgentTransport: (transport: MountayaTransport) => AgentTransport;
348
343
  /**
349
344
  * CollabEvent is one decoded frame off a collaboration stream: the contract's union,
350
345
  * re-exported under the name the reading code uses.
@@ -367,7 +362,7 @@ type CollabSignal = CollabSignalParams;
367
362
  * carrying one rather than by being listed.
368
363
  */
369
364
  type CollabDurableChange = Extract<CollabEvent, {
370
- action: CollabChangeAction;
365
+ action: CollabChangeAction;
371
366
  }>;
372
367
  /**
373
368
  * CollabStreamResource is the resource whose editor stream is being read: the collection
@@ -379,10 +374,10 @@ type CollabDurableChange = Extract<CollabEvent, {
379
374
  * is structurally identical and assignable to it, and a twin test pins the two.
380
375
  */
381
376
  interface CollabStreamResource {
382
- /** The resource's id, as its path carries it. */
383
- readonly id: string;
384
- /** The collection segment of the resource's path. */
385
- readonly kind: "itineraries" | "zones";
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";
386
381
  }
387
382
  /**
388
383
  * CollabStreamFrame is one decoded frame paired with its stream position id. A reader
@@ -391,24 +386,24 @@ interface CollabStreamResource {
391
386
  * numbers its frames, in which case a resume falls back to a full replay.
392
387
  */
393
388
  interface CollabStreamFrame {
394
- /** The decoded frame, discriminated on `type`. */
395
- event: CollabEvent;
396
- /** The record's own `id:`, the position a resume passes back; absent where it names none. */
397
- id?: string | undefined;
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;
398
393
  }
399
394
  /**
400
395
  * CollabStreamErrorOptions classify a stream failure for the reader that has to decide
401
396
  * whether to reconnect.
402
397
  */
403
398
  interface CollabStreamErrorOptions {
404
- /**
405
- * Whether reopening cannot help: a credential refused before the open, a runtime whose fetch
406
- * streams no body, a 4xx other than 429 on the open, a producer that never ends a frame, and a
407
- * fault the subscriber's own `onFrame` or `onLastEventId` threw, which a reopen would hand the
408
- * same frame again. `false` for a failure a reopen can get past: a dropped connection, a
409
- * stream gone silent, a 429 and a 5xx.
410
- */
411
- terminal?: boolean | undefined;
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;
412
407
  }
413
408
  /**
414
409
  * CollabStreamCloseReason says how a collaboration stream finished without an error:
@@ -430,48 +425,48 @@ type CollabStreamCloseReason = "reconnect" | "ended";
430
425
  * after it.
431
426
  */
432
427
  interface CollabStreamHandlers {
433
- /** onClose is told once the stream's body finished with no error, and why. */
434
- onClose: (reason: CollabStreamCloseReason) => void;
435
- /**
436
- * onError receives the failure once, classified. It is an error of the client's family, except
437
- * a fault the subscriber's own `onOpen`, `onFrame`, `onSkippedFrame` or `onLastEventId` threw,
438
- * which arrives as it was thrown and classified terminal: an open the API refused raises the
439
- * class a request answered the same way raises, and a connection that failed or broke off raises
440
- * a `MountayaConnectionError` naming the stream's operation.
441
- */
442
- onError: (error: unknown, options?: CollabStreamErrorOptions) => void;
443
- /** onFrame receives each decoded frame, in the order the stream wrote them. */
444
- onFrame: (frame: CollabStreamFrame) => void;
445
- /**
446
- * onLastEventId receives the stream position when it moves to one no frame carries: a record
447
- * that names an `id:` and no event, or an empty `id:`, which clears the position and arrives as
448
- * `undefined`. A subscriber keeping a resume cursor records it, so a reopen resumes from the
449
- * last position the stream named rather than replaying what it has read.
450
- *
451
- * A frame {@link decodeCollabFrame} skips (a kind this build does not know, or a payload that is
452
- * not an object) is neither handed to onFrame nor reported here, whatever id it carries, so its
453
- * position reaches a cursor only once a later frame or record names one. A reopen before then
454
- * replays it, and it is skipped again.
455
- */
456
- onLastEventId?: ((lastEventId: string | undefined) => void) | undefined;
457
- /**
458
- * onOpen is told once the API has answered the open, before any frame of it, with the user the
459
- * stream is read as: the user the session token it was opened with names, `userId`, undefined
460
- * where the credential's source does not say or the token is held as a string or a function,
461
- * whose user the client is not told. A reader judging its own member's `presence.join` reads
462
- * that user first, and a user it is told otherwise only where it is undefined.
463
- */
464
- onOpen?: ((open: {
465
- readonly userId: string | undefined;
466
- }) => void) | undefined;
467
- /**
468
- * onSkippedFrame is told of each frame the stream delivers that {@link decodeCollabFrame} skips:
469
- * one naming a kind this build does not know, or carrying data it cannot read. Nothing of it is
470
- * handed over, and it moves no position, but it is a frame the stream delivered, so a reader
471
- * telling an open that made progress from one that did not counts it as one past those every
472
- * open begins with. A `reconnect`, which is the transport's own, is not one.
473
- */
474
- onSkippedFrame?: (() => void) | undefined;
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;
475
470
  }
476
471
  /**
477
472
  * CollabSubscribeOptions tune one open. `lastEventId` resumes the durable history after a
@@ -479,10 +474,10 @@ interface CollabStreamHandlers {
479
474
  * unsubscribe does.
480
475
  */
481
476
  interface CollabSubscribeOptions {
482
- /** The position to resume after, sent as `Last-Event-ID`; left out, the stream replays whole. */
483
- lastEventId?: string | undefined;
484
- /** Closes the stream once it aborts, as the unsubscribe a subscribe returns does. */
485
- signal?: AbortSignal | undefined;
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;
486
481
  }
487
482
  /**
488
483
  * CollabSignalResult is how a published signal settled. A lock contention is a RESULT
@@ -495,10 +490,10 @@ interface CollabSubscribeOptions {
495
490
  * answered in the API's place.
496
491
  */
497
492
  type CollabSignalResult = {
498
- ok: true;
493
+ ok: true;
499
494
  } | {
500
- holderId?: string | undefined;
501
- ok: false;
495
+ holderId?: string | undefined;
496
+ ok: false;
502
497
  };
503
498
  /**
504
499
  * CollabTransport is the seam a collaboration session drives: publish one signal, and open
@@ -510,23 +505,23 @@ type CollabSignalResult = {
510
505
  * your own bounds both waits the same way: the engine waits as long as a stream says nothing.
511
506
  */
512
507
  interface CollabTransport {
513
- /**
514
- * sendSignal publishes one signal for a resource, and answers how it settled: a lock another
515
- * member holds is a result naming them, never a throw.
516
- *
517
- * @throws the client's own error family for every other refusal: see {@link CollabSignalResult}.
518
- */
519
- sendSignal: (resource: CollabStreamResource, signal: CollabSignal) => Promise<CollabSignalResult>;
520
- /**
521
- * subscribeEditor opens the editor stream of one resource and returns the function that closes
522
- * it. Every failure reaches `handlers.onError`, classified; the call itself never throws.
523
- */
524
- subscribeEditor: (resource: CollabStreamResource, handlers: CollabStreamHandlers, options?: CollabSubscribeOptions) => () => void;
525
- /**
526
- * subscribeList opens an organization's event stream, the changes to its itineraries, zones and
527
- * collections, and returns the function that closes it. Every failure reaches `handlers.onError`, classified; the call itself never throws.
528
- */
529
- subscribeList: (organizationId: string, handlers: CollabStreamHandlers, options?: CollabSubscribeOptions) => () => void;
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;
530
525
  }
531
526
  /**
532
527
  * decodeCollabFrame turns one raw SSE frame into a typed event, or null to skip it.
@@ -551,7 +546,7 @@ interface CollabTransport {
551
546
  * What is checked at runtime is the one field the wire and the type disagree about (the
552
547
  * discriminant, which arrives on a separate line) and nothing below it.
553
548
  */
554
- declare const decodeCollabFrame: (frame: SseFrame) => CollabEvent | null;
549
+ export declare const decodeCollabFrame: (frame: SseFrame) => CollabEvent | null;
555
550
  /**
556
551
  * createCollabTransport binds the collaboration streams to one client's transport.
557
552
  *
@@ -569,8 +564,7 @@ declare const decodeCollabFrame: (frame: SseFrame) => CollabEvent | null;
569
564
  * answers tells `onOpen` the user that token names, and a frame it skips is told to
570
565
  * `onSkippedFrame`.
571
566
  */
572
- declare const createCollabTransport: (transport: MountayaTransport) => CollabTransport;
573
-
567
+ export declare const createCollabTransport: (transport: MountayaTransport) => CollabTransport;
574
568
  /**
575
569
  * FrameHandler receives one framed record as readEventStream decodes it. It is
576
570
  * awaited, so returning a promise backpressures the read: the next chunk is
@@ -616,8 +610,7 @@ type EventStreamOutcome = "stopped" | "ended";
616
610
  * `stopped` or a throw, the connection behind it stays open until the caller, whose body it is,
617
611
  * cancels it or aborts the request that opened it.
618
612
  */
619
- declare const readEventStream: (body: ReadableStream<Uint8Array>, onFrame: FrameHandler, onLastEventId?: (lastEventId: string) => void) => Promise<EventStreamOutcome>;
620
-
613
+ export declare const readEventStream: (body: ReadableStream<Uint8Array>, onFrame: FrameHandler, onLastEventId?: (lastEventId: string) => void) => Promise<EventStreamOutcome>;
621
614
  /**
622
615
  * OpenSseStreamOptions configure one open of a resumable Server-Sent Events read
623
616
  * over fetch. The caller supplies the network seam (doFetch + applyAuth), the URL and
@@ -627,123 +620,123 @@ declare const readEventStream: (body: ReadableStream<Uint8Array>, onFrame: Frame
627
620
  * type), so this reader knows no feature's schema.
628
621
  */
629
622
  interface OpenSseStreamOptions<TEvent> {
630
- /**
631
- * applyAuth folds the host's credential into the request's RequestInit.
632
- *
633
- * `method` reaches it because the published seam takes one, for the wording of a refusal.
634
- *
635
- * What the stream's operation declares does not reach it, because this reader knows the
636
- * operation by name alone. An opener states it in the closure it passes, as the collaboration
637
- * and agent transports do over `MountayaTransport.streamSeam`: the session token every stream
638
- * requires, that it acts as the member that token names, and, by saying nothing, that no
639
- * stream accepts a share token. The seam refuses a credential that cannot meet them locally,
640
- * which for a share token is the only place the rule is named: the server answers one sent where
641
- * it is not accepted with a 401, as if no credential had been sent. A refusal thrown here
642
- * surfaces through onError like any other failed open.
643
- */
644
- applyAuth: (init: RequestInit, method: string) => RequestInit;
645
- /** decode turns one raw SSE frame into a typed event, or null to skip it. */
646
- decode: (frame: SseFrame) => TEvent | null;
647
- /** doFetch is the fetch implementation: the real one, or a test double. */
648
- doFetch: typeof fetch;
649
- /** lastEventId resumes the stream after a position via the Last-Event-ID header. */
650
- lastEventId?: string | undefined;
651
- /** onClose runs once when the body finishes, told why the read returned. */
652
- onClose?: ((outcome: EventStreamOutcome) => void) | undefined;
653
- /**
654
- * onResponse is told of the open's answer once it arrives, a refusal's as well as a stream's,
655
- * before the stream is read or the refusal classified. The openers of this entry point pass
656
- * `MountayaTransport.streamSeam`'s `report`, so the client's own `onResponse` hears of every
657
- * open. A fault it throws fails the open, as a fault of `applyAuth` does.
658
- */
659
- onResponse?: ((response: Response) => void) | undefined;
660
- /**
661
- * onError runs once on a failure that is not the caller's own abort (an abort is a silent
662
- * teardown and fires neither onClose nor onError).
663
- *
664
- * What it receives is an error of this package's family, except a fault the caller's own
665
- * `applyAuth`, `decode`, `onFrame` or `onLastEventId` threw, which arrives as it was thrown:
666
- * - an open the API refused raises what a request the API answered the same way raises (the
667
- * class its status and first entry decide, carrying the entries, the `code` and the metadata),
668
- * so a `402` is a `MountayaBillingError` and a `409` naming a held lock a `MountayaConflictError`. Its body
669
- * is read under a bound on time and one on size, and past either the status alone decides the
670
- * class;
671
- * - a request that failed before a response arrived and a body that broke off mid-read raise a
672
- * `MountayaConnectionError` carrying the runtime's failure as its `cause`, and an ok answer
673
- * with no body raises one with no `cause`, since no runtime failure lies behind it;
674
- * - an open with no response within {@link OpenSseStreamOptions.timeoutMs}, and a stream that
675
- * delivered nothing for the stall window, raise a `MountayaConnectionError` that says which
676
- * wait ran out, with no `cause`: the request is aborted and its body let go first;
677
- * - a `timeoutMs` out of range raises a `MountayaConfigurationError` naming it, and nothing is
678
- * opened;
679
- * - a runtime whose fetch exposes no response body to stream raises a
680
- * `MountayaConfigurationError`, since every reopen meets the same runtime;
681
- * - a producer past the frame parser's cap raises a `SseBufferOverflowError` naming the
682
- * operation, with the parser's own error as its `cause`;
683
- * - a credential the transports' stream seam refuses in applyAuth, and a failure the fetch raised
684
- * from inside the family, are already of the family and arrive as they were thrown.
685
- */
686
- onError?: ((error: unknown) => void) | undefined;
687
- /**
688
- * onFrame receives each decoded event with its stream position id and returns
689
- * whether to stop the read (a terminal event). Returning a promise backpressures
690
- * the read: the next frame is pulled only once it settles.
691
- */
692
- onFrame: (event: TEvent, id: string | undefined) => boolean | Promise<boolean>;
693
- /**
694
- * onLastEventId receives the stream's position when it moves to one no frame handed to
695
- * onFrame carries: a record that names an `id:` and no `data:`, which dispatches no frame, or
696
- * an empty `id:`, even one before the stream names any other position, which clears the
697
- * position and arrives as `undefined`. A caller keeping a resume cursor records it as it records
698
- * a frame's id, so a reopen from the cursor resumes from the last position the stream named. It
699
- * runs only once the frames before it are handled (see `readEventStream`).
700
- *
701
- * A frame decode skips is neither handed to onFrame nor reported, whatever id it carries, so its
702
- * position reaches a cursor only once a later frame or record names one. A reopen before then
703
- * replays it, and decode skips it again.
704
- */
705
- onLastEventId?: ((lastEventId: string | undefined) => void) | undefined;
706
- /**
707
- * operationId names the operation the stream opens, and every failure this open builds names it
708
- * too: a refusal, a connection failure, and an answer with no body to read
709
- * (`getAgentRunEvents: 403 FORBIDDEN …`), and so does the frame parser's overflow, which is
710
- * handed on as a `SseBufferOverflowError` naming it. A failure handed on as it was thrown keeps
711
- * its own message.
712
- */
713
- operationId: string;
714
- /** signal is an external abort that tears the open stream down like the returned close. */
715
- signal?: AbortSignal | undefined;
716
- /**
717
- * timeoutMs bounds the open's wait for its response, in milliseconds: past it the request is
718
- * aborted and onError receives a `MountayaConnectionError` naming the wait. A whole number from
719
- * 1 to 2,147,483,647; anything else fails the open with a `MountayaConfigurationError` before a
720
- * request is made. The agent and collaboration transports pass the client's own per-attempt
721
- * `timeoutMs`, which `MountayaTransport.streamSeam` carries, so their opens wait what a request
722
- * of the same client waits.
723
- *
724
- * Once the response arrives the wait that follows is the stream's silence, which is bounded on
725
- * its own: a stream that delivers nothing, not even the heartbeat comment the API writes to
726
- * every live stream, for the stall window is given up the same way.
727
- *
728
- * @default the stall window, 45,000 ms, so no wait on the network is unbounded.
729
- */
730
- timeoutMs?: number | undefined;
731
- /**
732
- * waitForSession is called before each open's credential is applied, with the open's own
733
- * signal, and the promise it answers is awaited, so a session token on its way is the one the
734
- * open carries; `undefined` is nothing to wait for, and the open is made at once. The openers of
735
- * this entry point pass `MountayaTransport.streamSeam`'s, which waits for a token the
736
- * credential's source reports on its way, as a request does. What it rejects with reaches
737
- * onError like any other failed open, and a close during the wait ends it silently.
738
- */
739
- waitForSession?: ((signal: AbortSignal) => Promise<void> | undefined) | undefined;
740
- /**
741
- * url is the fully-qualified stream endpoint, or a function answering it. A function is called
742
- * once, when the open is made, and what it throws reaches onError as a failed open: an opener
743
- * whose resolver refuses a path (`StreamSeam.url` does, for one that leaves the API) passes the
744
- * call rather than its answer.
745
- */
746
- url: string | (() => string);
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);
747
740
  }
748
741
  /**
749
742
  * openSseStream opens one resumable `text/event-stream` read over fetch and returns
@@ -775,7 +768,5 @@ interface OpenSseStreamOptions<TEvent> {
775
768
  * the failure a caller reopens on, rather than as a read that never settles. The time a frame
776
769
  * handler holds the read is the caller's, and never counts as the stream's silence.
777
770
  */
778
- declare const openSseStream: <TEvent>(options: OpenSseStreamOptions<TEvent>) => (() => void);
779
-
780
- export { MAX_SSE_BUFFER_CHARS, SseBufferOverflowError, SseFrameParser, agentTerminalEventTypes, createAgentTransport, createCollabTransport, decodeAgentFrame, decodeCollabFrame, openSseStream, readEventStream };
781
- 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 };
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 };