@mountaya/client 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +104 -0
- package/LICENCE.fr.txt +280 -0
- package/LICENSE.txt +262 -0
- package/README.md +1260 -2
- package/dist/admin/index.cjs +3521 -0
- package/dist/admin/index.cjs.map +1 -0
- package/dist/admin/index.d.cts +1070 -0
- package/dist/admin/index.d.ts +1070 -0
- package/dist/admin/index.js +301 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/browser.cjs +8073 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +106 -0
- package/dist/browser.d.ts +106 -0
- package/dist/browser.js +53 -0
- package/dist/browser.js.map +1 -0
- package/dist/chunk-BM526BHG.js +342 -0
- package/dist/chunk-BM526BHG.js.map +1 -0
- package/dist/chunk-D2YEVTG7.js +327 -0
- package/dist/chunk-D2YEVTG7.js.map +1 -0
- package/dist/chunk-OHKVUREN.js +3500 -0
- package/dist/chunk-OHKVUREN.js.map +1 -0
- package/dist/chunk-TDTK2L5H.js +3842 -0
- package/dist/chunk-TDTK2L5H.js.map +1 -0
- package/dist/coreOperations.gen-BMYPoBbz.d.ts +1760 -0
- package/dist/coreOperations.gen-BxX5xRxw.d.cts +1760 -0
- package/dist/errors-B-GqAtQv.d.cts +75960 -0
- package/dist/errors-B-GqAtQv.d.ts +75960 -0
- package/dist/events/index.cjs +1972 -0
- package/dist/events/index.cjs.map +1 -0
- package/dist/events/index.d.cts +781 -0
- package/dist/events/index.d.ts +781 -0
- package/dist/events/index.js +826 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index.cjs +8072 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/operations.gen-CvTyzKNF.d.cts +3993 -0
- package/dist/operations.gen-DUD406TV.d.ts +3993 -0
- package/package.json +127 -4
- package/src/admin/index.ts +47 -0
- package/src/admin/rules/mountayaAdmin.ts +102 -0
- package/src/browser.ts +232 -0
- package/src/core/engines/sessionToken.ts +870 -0
- package/src/core/rules/auth.ts +1017 -0
- package/src/core/rules/clientHeader.ts +28 -0
- package/src/core/rules/dates.ts +200 -0
- package/src/core/rules/decode.ts +154 -0
- package/src/core/rules/envelope.ts +41 -0
- package/src/core/rules/errors.ts +1486 -0
- package/src/core/rules/graphql.ts +576 -0
- package/src/core/rules/headerValue.ts +42 -0
- package/src/core/rules/idempotencyKey.ts +64 -0
- package/src/core/rules/nullMask.ts +127 -0
- package/src/core/rules/nullMasks.gen.ts +416 -0
- package/src/core/rules/paginate.ts +316 -0
- package/src/core/rules/rateLimit.ts +507 -0
- package/src/core/rules/redaction.ts +219 -0
- package/src/core/rules/resourceRef.ts +110 -0
- package/src/core/rules/responseBody.ts +492 -0
- package/src/core/rules/retry.ts +386 -0
- package/src/core/rules/selection.ts +416 -0
- package/src/core/rules/sessionAnswer.ts +90 -0
- package/src/core/rules/sessionSchedule.ts +131 -0
- package/src/core/rules/sessionWait.ts +112 -0
- package/src/core/rules/transport.ts +2386 -0
- package/src/core/rules/version.gen.ts +16 -0
- package/src/core/rules/webAddress.ts +165 -0
- package/src/core/rules/webAddresses.gen.ts +30 -0
- package/src/data/operations.gen.ts +603 -0
- package/src/data/schema.gen.ts +8078 -0
- package/src/data/selection.gen.ts +472 -0
- package/src/events/index.ts +67 -0
- package/src/events/rules/agent.ts +439 -0
- package/src/events/rules/collab.ts +554 -0
- package/src/events/rules/collabNulls.gen.ts +17 -0
- package/src/events/rules/eventStream.ts +94 -0
- package/src/events/rules/openSseStream.ts +594 -0
- package/src/events/rules/sse.ts +349 -0
- package/src/index.ts +231 -0
- package/src/rest/adminOperations.gen.ts +70 -0
- package/src/rest/adminResources.gen.ts +136 -0
- package/src/rest/coreOperations.gen.ts +74 -0
- package/src/rest/coreResources.gen.ts +244 -0
- package/src/rest/dates.gen.ts +217 -0
- package/src/rest/operations.gen.ts +4341 -0
- package/src/rest/resources.gen.ts +369 -0
- package/src/rest/schema.gen.ts +56840 -0
- package/src/tiles/operations.gen.ts +206 -0
- package/src/tiles/schema.gen.ts +8408 -0
- package/src/webhooks/rules/constructWebhookEvent.ts +482 -0
- package/src/webhooks/rules/webhookEvent.ts +38 -0
- package/src/webhooks/rules/webhookEvents.gen.ts +732 -0
|
@@ -0,0 +1,826 @@
|
|
|
1
|
+
import { isHeaderValue, readFailure, MAX_TIMER_DELAY_MS } from '../chunk-D2YEVTG7.js';
|
|
2
|
+
import { MountayaError, refuseOption, postAgentRun, MountayaApiError, postAgentRunInput, parseJsonWithDates, collabStreamEventDatesByType, withAbsentNulls, postItineraryCollab, postZoneCollab, isMountayaApiError, MountayaConfigurationError, isMountayaError, MountayaConnectionError } from '../chunk-TDTK2L5H.js';
|
|
3
|
+
|
|
4
|
+
// src/events/rules/sse.ts
|
|
5
|
+
var BYTE_ORDER_MARK = "\uFEFF";
|
|
6
|
+
var MAX_SSE_BUFFER_CHARS = 8 * 1024 * 1024;
|
|
7
|
+
var SseBufferOverflowError = class extends MountayaError {
|
|
8
|
+
// The family's spelling, and not `this.name = …` in the constructor: every class here
|
|
9
|
+
// declares its name as a string LITERAL on the class, because an identifier is what a
|
|
10
|
+
// consumer's minifier renames and data is what survives it. `errors.test.ts` derives that
|
|
11
|
+
// rule from the barrel, and this class is on it.
|
|
12
|
+
name = "SseBufferOverflowError";
|
|
13
|
+
/** The cap the parser enforced, in UTF-16 code units. */
|
|
14
|
+
limit;
|
|
15
|
+
/**
|
|
16
|
+
* Builds the error a parser throws once its unterminated record passes the cap.
|
|
17
|
+
*
|
|
18
|
+
* @param limit - the cap the parser enforced, in UTF-16 code units.
|
|
19
|
+
* @param operationId - the operation whose stream overflowed, where the thrower knows it: the
|
|
20
|
+
* message then opens with it and ends with what a reopen would meet.
|
|
21
|
+
* @param options - the standard error options, for the `cause` an opener hands on.
|
|
22
|
+
*/
|
|
23
|
+
constructor(limit, operationId, options) {
|
|
24
|
+
const overflow = `sse frame parser: unterminated frame exceeded ${limit} characters`;
|
|
25
|
+
super(
|
|
26
|
+
operationId === void 0 ? overflow : `${operationId}: ${overflow}. The producer never ended the record, and a reopen meets it again.`,
|
|
27
|
+
options
|
|
28
|
+
);
|
|
29
|
+
this.limit = limit;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var SseFrameParser = class {
|
|
33
|
+
// The unterminated line, in the pieces the pushes delivered it in, and how long they are
|
|
34
|
+
// together. Joined once, when the line ends, so a long line is never copied per push.
|
|
35
|
+
lineParts = [];
|
|
36
|
+
lineLength = 0;
|
|
37
|
+
// What the current record holds: its data lines, its event name, and its own `id:`, which is
|
|
38
|
+
// undefined until it names one.
|
|
39
|
+
dataLines = [];
|
|
40
|
+
event = "";
|
|
41
|
+
recordId;
|
|
42
|
+
// The characters of the current record's completed lines, line endings included. With the
|
|
43
|
+
// unterminated line, it is what the cap bounds.
|
|
44
|
+
recordLength = 0;
|
|
45
|
+
// The stream's last event ID, moved when a record naming an `id:` ends, and undefined until one
|
|
46
|
+
// does.
|
|
47
|
+
lastId;
|
|
48
|
+
// No character has arrived yet, so a byte-order mark opening the next one is still dropped.
|
|
49
|
+
atStart = true;
|
|
50
|
+
// Whether the last character read is a CR that ended a line, so an LF arriving next completes
|
|
51
|
+
// a CRLF.
|
|
52
|
+
afterCarriageReturn = false;
|
|
53
|
+
// Set past the cap, for good.
|
|
54
|
+
overflowed = false;
|
|
55
|
+
// The cap on the unterminated record, checked at construction.
|
|
56
|
+
maxBufferChars;
|
|
57
|
+
/**
|
|
58
|
+
* Builds a parser that holds at most `maxBufferChars` of a record it has not seen the end of.
|
|
59
|
+
*
|
|
60
|
+
* @param maxBufferChars - bounds the unterminated record this parser holds, in UTF-16 code
|
|
61
|
+
* units: a whole number of 1 or more. A consumer whose frames are known small may tighten
|
|
62
|
+
* it; the shared readers take the default. A cap that is not a number of characters would
|
|
63
|
+
* bound nothing (`NaN` and `Infinity` are exceeded by no length) or refuse every push (zero
|
|
64
|
+
* and below), so it is refused here.
|
|
65
|
+
* @default MAX_SSE_BUFFER_CHARS
|
|
66
|
+
* @throws `MountayaConfigurationError` for a cap that is not a whole number of 1 or more.
|
|
67
|
+
*/
|
|
68
|
+
constructor(maxBufferChars = MAX_SSE_BUFFER_CHARS) {
|
|
69
|
+
const given = maxBufferChars;
|
|
70
|
+
if (typeof given !== "number" || !Number.isInteger(given) || given < 1) {
|
|
71
|
+
throw refuseOption(
|
|
72
|
+
"maxBufferChars",
|
|
73
|
+
given,
|
|
74
|
+
`pass a whole number of characters of 1 or more, or leave it out for the default of ${MAX_SSE_BUFFER_CHARS}.`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
this.maxBufferChars = given;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* lastEventId is the stream's last event ID, as the HTML standard defines it: the value of the
|
|
81
|
+
* latest `id:` in a record the parser has seen the end of, whatever else that record carried.
|
|
82
|
+
*
|
|
83
|
+
* It is the position a reconnect resumes from, sent as `Last-Event-ID`. It carries over a
|
|
84
|
+
* record that names no `id:`, an empty `id:` clears it to the empty string, and an `id:` holding
|
|
85
|
+
* U+0000 is ignored. An `id:` in a record still unterminated has not moved it: a reconnect
|
|
86
|
+
* discards that record, so resuming past it would skip it.
|
|
87
|
+
*
|
|
88
|
+
* It is `undefined` until the stream names a position, where the standard starts from the empty
|
|
89
|
+
* string, so a stream that names none reads apart from one that clears it. A caller resuming
|
|
90
|
+
* from a position an earlier connection named keeps that position through the first and drops
|
|
91
|
+
* it at the second.
|
|
92
|
+
*/
|
|
93
|
+
get lastEventId() {
|
|
94
|
+
return this.lastId;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* push feeds the next decoded text chunk and returns every frame the records it completes
|
|
98
|
+
* dispatch, in stream order. What it leaves unterminated stays held for the next push, unless it
|
|
99
|
+
* passes the cap: then push throws {@link SseBufferOverflowError} instead of returning, dropping
|
|
100
|
+
* the frames the same chunk completed. The stream is being torn down with them, and a caller
|
|
101
|
+
* that resumes re-reads from the position it last recorded.
|
|
102
|
+
*/
|
|
103
|
+
push(chunk) {
|
|
104
|
+
if (this.overflowed) {
|
|
105
|
+
throw new SseBufferOverflowError(this.maxBufferChars);
|
|
106
|
+
}
|
|
107
|
+
const frames = [];
|
|
108
|
+
let start = 0;
|
|
109
|
+
if (chunk.length > 0) {
|
|
110
|
+
if (this.atStart) {
|
|
111
|
+
this.atStart = false;
|
|
112
|
+
if (chunk.startsWith(BYTE_ORDER_MARK)) {
|
|
113
|
+
start = BYTE_ORDER_MARK.length;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (this.afterCarriageReturn) {
|
|
117
|
+
this.afterCarriageReturn = false;
|
|
118
|
+
if (chunk.startsWith("\n", start)) {
|
|
119
|
+
start += 1;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
let carriageReturn = chunk.indexOf("\r", start);
|
|
124
|
+
let lineFeed = chunk.indexOf("\n", start);
|
|
125
|
+
while (carriageReturn !== -1 || lineFeed !== -1) {
|
|
126
|
+
const end = carriageReturn === -1 || lineFeed !== -1 && lineFeed < carriageReturn ? lineFeed : carriageReturn;
|
|
127
|
+
let next = end + 1;
|
|
128
|
+
if (end === carriageReturn) {
|
|
129
|
+
if (next === chunk.length) {
|
|
130
|
+
this.afterCarriageReturn = true;
|
|
131
|
+
} else if (chunk.startsWith("\n", next)) {
|
|
132
|
+
next += 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const line = this.completeLine(chunk.slice(start, end));
|
|
136
|
+
this.recordLength += line.length + (next - end);
|
|
137
|
+
const frame = this.readLine(line);
|
|
138
|
+
if (frame !== null) {
|
|
139
|
+
frames.push(frame);
|
|
140
|
+
}
|
|
141
|
+
start = next;
|
|
142
|
+
if (carriageReturn !== -1 && carriageReturn < start) {
|
|
143
|
+
carriageReturn = chunk.indexOf("\r", start);
|
|
144
|
+
}
|
|
145
|
+
if (lineFeed !== -1 && lineFeed < start) {
|
|
146
|
+
lineFeed = chunk.indexOf("\n", start);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (start < chunk.length) {
|
|
150
|
+
this.lineParts.push(chunk.slice(start));
|
|
151
|
+
this.lineLength += chunk.length - start;
|
|
152
|
+
}
|
|
153
|
+
if (this.recordLength + this.lineLength > this.maxBufferChars) {
|
|
154
|
+
this.lineParts = [];
|
|
155
|
+
this.lineLength = 0;
|
|
156
|
+
this.startRecord();
|
|
157
|
+
this.overflowed = true;
|
|
158
|
+
throw new SseBufferOverflowError(this.maxBufferChars);
|
|
159
|
+
}
|
|
160
|
+
return frames;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* completeLine joins the line held from earlier pushes with its last piece, `tail`, and starts
|
|
164
|
+
* the next line empty.
|
|
165
|
+
*/
|
|
166
|
+
completeLine(tail) {
|
|
167
|
+
if (this.lineParts.length === 0) {
|
|
168
|
+
return tail;
|
|
169
|
+
}
|
|
170
|
+
this.lineParts.push(tail);
|
|
171
|
+
const line = this.lineParts.join("");
|
|
172
|
+
this.lineParts = [];
|
|
173
|
+
this.lineLength = 0;
|
|
174
|
+
return line;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* readLine applies one complete line to the current record, and returns the frame the record
|
|
178
|
+
* dispatches when the line is the empty one that ends it.
|
|
179
|
+
*
|
|
180
|
+
* A field line is split at its first colon, and one space after the colon is dropped: only the
|
|
181
|
+
* first space is the standard's separator, and a second one is part of the value. A line with no
|
|
182
|
+
* colon is its whole self as the field name, with an empty value.
|
|
183
|
+
*/
|
|
184
|
+
readLine(line) {
|
|
185
|
+
if (line === "") {
|
|
186
|
+
return this.endRecord();
|
|
187
|
+
}
|
|
188
|
+
if (line.startsWith(":")) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
const colon = line.indexOf(":");
|
|
192
|
+
const field = colon === -1 ? line : line.slice(0, colon);
|
|
193
|
+
const raw = colon === -1 ? "" : line.slice(colon + 1);
|
|
194
|
+
const value = raw.startsWith(" ") ? raw.slice(1) : raw;
|
|
195
|
+
if (field === "data") {
|
|
196
|
+
this.dataLines.push(value);
|
|
197
|
+
} else if (field === "event") {
|
|
198
|
+
this.event = value;
|
|
199
|
+
} else if (field === "id" && !value.includes("\0")) {
|
|
200
|
+
this.recordId = value;
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* endRecord closes the current record: an `id:` it named becomes the stream's last event ID,
|
|
206
|
+
* and it returns the frame the record dispatches, or null for a record with no data.
|
|
207
|
+
*/
|
|
208
|
+
endRecord() {
|
|
209
|
+
const { dataLines, event, recordId } = this;
|
|
210
|
+
this.startRecord();
|
|
211
|
+
if (recordId !== void 0) {
|
|
212
|
+
this.lastId = recordId;
|
|
213
|
+
}
|
|
214
|
+
if (dataLines.length === 0) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
return { data: dataLines.join("\n"), event, id: recordId ?? "" };
|
|
218
|
+
}
|
|
219
|
+
/** startRecord empties the record being read, so the next line begins the next one. */
|
|
220
|
+
startRecord() {
|
|
221
|
+
this.dataLines = [];
|
|
222
|
+
this.event = "";
|
|
223
|
+
this.recordId = void 0;
|
|
224
|
+
this.recordLength = 0;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// src/events/rules/eventStream.ts
|
|
229
|
+
var readEventStream = async (body, onFrame, onLastEventId) => {
|
|
230
|
+
const reader = body.getReader();
|
|
231
|
+
const decoder = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
232
|
+
const parser = new SseFrameParser();
|
|
233
|
+
let known;
|
|
234
|
+
try {
|
|
235
|
+
while (true) {
|
|
236
|
+
const { done, value } = await reader.read();
|
|
237
|
+
if (done) {
|
|
238
|
+
return "ended";
|
|
239
|
+
}
|
|
240
|
+
for (const frame of parser.push(decoder.decode(value, { stream: true }))) {
|
|
241
|
+
if (frame.id !== "") {
|
|
242
|
+
known = frame.id;
|
|
243
|
+
}
|
|
244
|
+
const stop = await onFrame(frame);
|
|
245
|
+
if (stop) {
|
|
246
|
+
return "stopped";
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const position = parser.lastEventId;
|
|
250
|
+
if (position !== void 0 && position !== known) {
|
|
251
|
+
known = position;
|
|
252
|
+
onLastEventId?.(position);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} finally {
|
|
256
|
+
reader.releaseLock();
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// src/events/rules/openSseStream.ts
|
|
261
|
+
var STALL_WINDOW_MS = 45e3;
|
|
262
|
+
var SILENCE = /* @__PURE__ */ Symbol("silence");
|
|
263
|
+
var LET_GO = /* @__PURE__ */ Symbol("let go");
|
|
264
|
+
var boundSilence = (body, operationId, signal) => {
|
|
265
|
+
const reader = body.getReader();
|
|
266
|
+
const letGo = () => {
|
|
267
|
+
try {
|
|
268
|
+
reader.releaseLock();
|
|
269
|
+
} catch {
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
let endWait;
|
|
273
|
+
if (signal.aborted) {
|
|
274
|
+
letGo();
|
|
275
|
+
} else {
|
|
276
|
+
signal.addEventListener(
|
|
277
|
+
"abort",
|
|
278
|
+
() => {
|
|
279
|
+
endWait?.(LET_GO);
|
|
280
|
+
letGo();
|
|
281
|
+
},
|
|
282
|
+
{ once: true }
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
return new ReadableStream(
|
|
286
|
+
{
|
|
287
|
+
cancel: (reason) => reader.cancel(reason),
|
|
288
|
+
pull: async (controller) => {
|
|
289
|
+
if (signal.aborted) {
|
|
290
|
+
controller.close();
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
let timer;
|
|
294
|
+
const ended = new Promise((resolve) => {
|
|
295
|
+
endWait = resolve;
|
|
296
|
+
timer = setTimeout(() => resolve(SILENCE), STALL_WINDOW_MS);
|
|
297
|
+
});
|
|
298
|
+
try {
|
|
299
|
+
const next = await Promise.race([reader.read(), ended]);
|
|
300
|
+
if (next === LET_GO) {
|
|
301
|
+
controller.close();
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (next === SILENCE) {
|
|
305
|
+
throw new MountayaConnectionError(
|
|
306
|
+
`${operationId}: the stream went silent for ${STALL_WINDOW_MS} ms, past the heartbeat every live stream carries. Reopen it from the last position it named, and check the network path to the API if it keeps going silent.`
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
if (next.done) {
|
|
310
|
+
controller.close();
|
|
311
|
+
} else {
|
|
312
|
+
controller.enqueue(next.value);
|
|
313
|
+
}
|
|
314
|
+
} finally {
|
|
315
|
+
endWait = void 0;
|
|
316
|
+
clearTimeout(timer);
|
|
317
|
+
if (signal.aborted) {
|
|
318
|
+
letGo();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
// A read-ahead queue of none: the next chunk is asked for only when the reader asks.
|
|
324
|
+
{ highWaterMark: 0 }
|
|
325
|
+
);
|
|
326
|
+
};
|
|
327
|
+
var openTimeoutOf = (timeoutMs, operationId) => {
|
|
328
|
+
if (timeoutMs === void 0) {
|
|
329
|
+
return STALL_WINDOW_MS;
|
|
330
|
+
}
|
|
331
|
+
if (Number.isInteger(timeoutMs) && timeoutMs >= 1 && timeoutMs <= MAX_TIMER_DELAY_MS) {
|
|
332
|
+
return timeoutMs;
|
|
333
|
+
}
|
|
334
|
+
throw refuseOption(
|
|
335
|
+
"timeoutMs",
|
|
336
|
+
timeoutMs,
|
|
337
|
+
`pass a whole number of milliseconds from 1 to ${MAX_TIMER_DELAY_MS}, or leave it out to wait at most ${STALL_WINDOW_MS}.`,
|
|
338
|
+
operationId
|
|
339
|
+
);
|
|
340
|
+
};
|
|
341
|
+
var requestStream = async (options, state, declaration) => {
|
|
342
|
+
const { operationId } = options;
|
|
343
|
+
const openTimeout = openTimeoutOf(options.timeoutMs, operationId);
|
|
344
|
+
const headers = new Headers({ Accept: "text/event-stream" });
|
|
345
|
+
if (options.lastEventId) {
|
|
346
|
+
const position = String(options.lastEventId);
|
|
347
|
+
if (!isHeaderValue(position)) {
|
|
348
|
+
throw new MountayaConfigurationError(
|
|
349
|
+
`${operationId}: lastEventId holds a character no request header carries, so the stream cannot be resumed from it. Pass the position the stream named, as it named it, or leave it out to read from the start.`
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
headers.set("Last-Event-ID", position);
|
|
353
|
+
}
|
|
354
|
+
const waiting = options.waitForSession?.(state.controller.signal);
|
|
355
|
+
if (waiting !== void 0) {
|
|
356
|
+
await waiting;
|
|
357
|
+
}
|
|
358
|
+
const url = typeof options.url === "function" ? options.url() : options.url;
|
|
359
|
+
const init = options.applyAuth({ headers, signal: state.controller.signal }, "GET");
|
|
360
|
+
let timedOut = false;
|
|
361
|
+
const deadline = setTimeout(() => {
|
|
362
|
+
timedOut = true;
|
|
363
|
+
state.controller.abort();
|
|
364
|
+
}, openTimeout);
|
|
365
|
+
let response;
|
|
366
|
+
try {
|
|
367
|
+
response = await options.doFetch(url, init);
|
|
368
|
+
} catch (cause) {
|
|
369
|
+
if (state.closedByCaller) {
|
|
370
|
+
throw cause;
|
|
371
|
+
}
|
|
372
|
+
if (timedOut) {
|
|
373
|
+
throw new MountayaConnectionError(
|
|
374
|
+
options.timeoutMs === void 0 ? `${operationId}: no response within ${openTimeout} ms. Check the network path to the API.` : `${operationId}: no response within ${openTimeout} ms. Raise timeoutMs for a stream that is slow to answer, or check the network path to the API.`
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
if (isMountayaError(cause)) {
|
|
378
|
+
throw cause;
|
|
379
|
+
}
|
|
380
|
+
throw new MountayaConnectionError(
|
|
381
|
+
`${operationId}: the stream failed before a response arrived. Check the network, and that the stream's URL names a host that answers.`,
|
|
382
|
+
cause
|
|
383
|
+
);
|
|
384
|
+
} finally {
|
|
385
|
+
clearTimeout(deadline);
|
|
386
|
+
}
|
|
387
|
+
options.onResponse?.(response);
|
|
388
|
+
if (!response.ok) {
|
|
389
|
+
throw await readFailure(response, {
|
|
390
|
+
...declaration,
|
|
391
|
+
operationId,
|
|
392
|
+
signal: state.controller.signal
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
const body = response.body;
|
|
396
|
+
if (body === void 0) {
|
|
397
|
+
throw new MountayaConfigurationError(
|
|
398
|
+
`${operationId}: this runtime's fetch exposes no response body to read the stream from. Pass a fetch that streams response bodies.`
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
if (body === null) {
|
|
402
|
+
throw new MountayaConnectionError(
|
|
403
|
+
`${operationId}: the ${response.status} answer carries no body, so something on the network path answered in the API's place. Check the network path to the API.`
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
return body;
|
|
407
|
+
};
|
|
408
|
+
var openDeclaredSseStream = (options, declaration) => {
|
|
409
|
+
const { operationId, signal } = options;
|
|
410
|
+
const state = { closedByCaller: false, controller: new AbortController() };
|
|
411
|
+
const close = () => {
|
|
412
|
+
state.closedByCaller = true;
|
|
413
|
+
state.controller.abort();
|
|
414
|
+
};
|
|
415
|
+
if (signal?.aborted) {
|
|
416
|
+
close();
|
|
417
|
+
} else {
|
|
418
|
+
signal?.addEventListener("abort", close, { once: true });
|
|
419
|
+
}
|
|
420
|
+
let callerFault = false;
|
|
421
|
+
const handle = async (frame) => {
|
|
422
|
+
if (state.closedByCaller) {
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
try {
|
|
426
|
+
const event = options.decode(frame);
|
|
427
|
+
if (event === null) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
return await options.onFrame(event, frame.id || void 0);
|
|
431
|
+
} catch (error) {
|
|
432
|
+
callerFault = true;
|
|
433
|
+
throw error;
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
const report = (lastEventId) => {
|
|
437
|
+
if (state.closedByCaller) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
try {
|
|
441
|
+
options.onLastEventId?.(lastEventId || void 0);
|
|
442
|
+
} catch (error) {
|
|
443
|
+
callerFault = true;
|
|
444
|
+
throw error;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
const read = async () => {
|
|
448
|
+
const body = await requestStream(options, state, declaration);
|
|
449
|
+
try {
|
|
450
|
+
return await readEventStream(
|
|
451
|
+
boundSilence(body, operationId, state.controller.signal),
|
|
452
|
+
handle,
|
|
453
|
+
report
|
|
454
|
+
);
|
|
455
|
+
} catch (cause) {
|
|
456
|
+
if (state.closedByCaller || callerFault) {
|
|
457
|
+
throw cause;
|
|
458
|
+
}
|
|
459
|
+
if (cause instanceof SseBufferOverflowError) {
|
|
460
|
+
throw new SseBufferOverflowError(cause.limit, operationId, { cause });
|
|
461
|
+
}
|
|
462
|
+
if (isMountayaError(cause)) {
|
|
463
|
+
throw cause;
|
|
464
|
+
}
|
|
465
|
+
throw new MountayaConnectionError(
|
|
466
|
+
`${operationId}: the stream broke off before it ended. Reopen it from the last position it named, and check the network path to the API if it keeps breaking off.`,
|
|
467
|
+
cause
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
void (async () => {
|
|
472
|
+
if (state.closedByCaller) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
let settled;
|
|
476
|
+
try {
|
|
477
|
+
settled = { outcome: await read() };
|
|
478
|
+
} catch (error) {
|
|
479
|
+
settled = { error };
|
|
480
|
+
}
|
|
481
|
+
signal?.removeEventListener("abort", close);
|
|
482
|
+
state.controller.abort();
|
|
483
|
+
if (state.closedByCaller) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
if ("outcome" in settled) {
|
|
487
|
+
options.onClose?.(settled.outcome);
|
|
488
|
+
} else {
|
|
489
|
+
options.onError?.(settled.error);
|
|
490
|
+
}
|
|
491
|
+
})();
|
|
492
|
+
return close;
|
|
493
|
+
};
|
|
494
|
+
var openSseStream = (options) => openDeclaredSseStream(options, void 0);
|
|
495
|
+
|
|
496
|
+
// src/events/rules/agent.ts
|
|
497
|
+
var agentRunEventTypes = {
|
|
498
|
+
"awaiting-input": "awaiting-input",
|
|
499
|
+
"budget-exhausted": "budget-exhausted",
|
|
500
|
+
"checks-unmet": "checks-unmet",
|
|
501
|
+
"confirm-required": "confirm-required",
|
|
502
|
+
done: "done",
|
|
503
|
+
error: "error",
|
|
504
|
+
message: "message",
|
|
505
|
+
"message-delta": "message-delta",
|
|
506
|
+
reconnect: "reconnect",
|
|
507
|
+
"tool-abandoned": "tool-abandoned",
|
|
508
|
+
"tool-call": "tool-call",
|
|
509
|
+
"tool-result": "tool-result"
|
|
510
|
+
};
|
|
511
|
+
var agentTerminalEventTypes = /* @__PURE__ */ new Set([
|
|
512
|
+
agentRunEventTypes.done
|
|
513
|
+
]);
|
|
514
|
+
var runIdFrom = (body) => {
|
|
515
|
+
const id = body?.data?.id;
|
|
516
|
+
return typeof id === "string" && id !== "" ? id : void 0;
|
|
517
|
+
};
|
|
518
|
+
var decodeAgentFrame = (frame) => {
|
|
519
|
+
if (!Object.hasOwn(agentRunEventTypes, frame.event)) {
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
let payload;
|
|
523
|
+
try {
|
|
524
|
+
payload = frame.data ? JSON.parse(frame.data) : {};
|
|
525
|
+
} catch {
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
if (typeof payload !== "object" || payload === null) {
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
return { ...payload, type: frame.event };
|
|
532
|
+
};
|
|
533
|
+
var AGENT_EVENTS_OPERATION_ID = "getAgentRunEvents";
|
|
534
|
+
var refuseServerToolsUnderKey = (transport, operationId, serverTools) => {
|
|
535
|
+
if (serverTools === void 0 || serverTools.length === 0) {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
if (transport.mapCredential.publishableKey === void 0) {
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
throw new MountayaConfigurationError(
|
|
542
|
+
`${operationId}: a run under a publishable key calls no server tool, so server_tools must be empty. Turn routesServerTools off.`
|
|
543
|
+
);
|
|
544
|
+
};
|
|
545
|
+
var isReconnect = (event) => event.type === agentRunEventTypes.reconnect;
|
|
546
|
+
var createAgentTransport = (transport) => ({
|
|
547
|
+
sendInput: async (runId, input, options) => {
|
|
548
|
+
if (input.type === "manifest-update") {
|
|
549
|
+
refuseServerToolsUnderKey(transport, "postAgentRunInput", input.server_tools);
|
|
550
|
+
}
|
|
551
|
+
await postAgentRunInput(transport, {
|
|
552
|
+
body: input,
|
|
553
|
+
idempotencyKey: options?.idempotencyKey,
|
|
554
|
+
run_id: runId
|
|
555
|
+
});
|
|
556
|
+
},
|
|
557
|
+
startRun: async (params, options) => {
|
|
558
|
+
refuseServerToolsUnderKey(transport, "postAgentRun", params.server_tools);
|
|
559
|
+
const body = await postAgentRun(transport, {
|
|
560
|
+
body: params,
|
|
561
|
+
idempotencyKey: options?.idempotencyKey
|
|
562
|
+
});
|
|
563
|
+
const runId = runIdFrom(body);
|
|
564
|
+
if (runId === void 0) {
|
|
565
|
+
throw new MountayaApiError("postAgentRun: 202 named no run", 202, []);
|
|
566
|
+
}
|
|
567
|
+
return { runId };
|
|
568
|
+
},
|
|
569
|
+
subscribe: (runId, handlers, options) => {
|
|
570
|
+
const seam = transport.streamSeam;
|
|
571
|
+
let expiresAt;
|
|
572
|
+
let reconnected = false;
|
|
573
|
+
return openDeclaredSseStream(
|
|
574
|
+
{
|
|
575
|
+
// What `getAgentRunEvents` declares, stated as its generated operation states it: its
|
|
576
|
+
// only security requirement pairs the key with a session token, and the stream acts as
|
|
577
|
+
// the member that token names. Stating both here is what refuses a credential carrying no
|
|
578
|
+
// session token, or one a source reports as minted without `user_id`, before the open;
|
|
579
|
+
// the refusal reaches onError like any other failed open. No share token reaches it, which
|
|
580
|
+
// the absence of `acceptsShareToken` says.
|
|
581
|
+
applyAuth: (init, method) => {
|
|
582
|
+
const applied = seam.applyAuth(init, method, {
|
|
583
|
+
actsAsMember: true,
|
|
584
|
+
operationId: AGENT_EVENTS_OPERATION_ID,
|
|
585
|
+
requiresSession: true
|
|
586
|
+
});
|
|
587
|
+
expiresAt = seam.sessionExpiresAt();
|
|
588
|
+
return applied;
|
|
589
|
+
},
|
|
590
|
+
// A frame skipped is still one the stream delivered, which the subscriber is told of as it
|
|
591
|
+
// is read, in order with the frames handed over.
|
|
592
|
+
decode: (frame) => {
|
|
593
|
+
const event = decodeAgentFrame(frame);
|
|
594
|
+
if (event === null) {
|
|
595
|
+
handlers.onSkippedFrame?.();
|
|
596
|
+
}
|
|
597
|
+
return event;
|
|
598
|
+
},
|
|
599
|
+
doFetch: seam.doFetch,
|
|
600
|
+
lastEventId: options?.lastEventId,
|
|
601
|
+
onClose: (outcome) => {
|
|
602
|
+
if (outcome === "stopped") {
|
|
603
|
+
handlers.onClose(reconnected ? "reconnect" : "terminal");
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
const expired = expiresAt !== void 0 && Date.now() >= expiresAt.getTime();
|
|
607
|
+
handlers.onClose(expired ? "reconnect" : "ended");
|
|
608
|
+
},
|
|
609
|
+
onError: (error) => handlers.onError(error),
|
|
610
|
+
onFrame: async (event, id) => {
|
|
611
|
+
if (isReconnect(event)) {
|
|
612
|
+
reconnected = true;
|
|
613
|
+
return true;
|
|
614
|
+
}
|
|
615
|
+
await handlers.onFrame({ event, id });
|
|
616
|
+
return agentTerminalEventTypes.has(event.type);
|
|
617
|
+
},
|
|
618
|
+
onLastEventId: (lastEventId) => handlers.onLastEventId?.(lastEventId),
|
|
619
|
+
onResponse: (response) => {
|
|
620
|
+
seam.report(response, AGENT_EVENTS_OPERATION_ID);
|
|
621
|
+
},
|
|
622
|
+
operationId: AGENT_EVENTS_OPERATION_ID,
|
|
623
|
+
signal: options?.signal,
|
|
624
|
+
// The wait for the stream's response is the client's own per-attempt budget.
|
|
625
|
+
timeoutMs: seam.timeoutMs,
|
|
626
|
+
// Resolved when the open is made, so a run id the path cannot carry (an empty one, or a
|
|
627
|
+
// dot segment) is refused through onError like any other failed open.
|
|
628
|
+
url: () => seam.url(`/v1/agent/runs/${encodeURIComponent(runId)}/events`, AGENT_EVENTS_OPERATION_ID),
|
|
629
|
+
waitForSession: (signal) => seam.waitForSession(AGENT_EVENTS_OPERATION_ID, signal)
|
|
630
|
+
},
|
|
631
|
+
// The same declaration the credential is stamped by, so a refused open names the step a
|
|
632
|
+
// member reading their own run takes.
|
|
633
|
+
{ actsAsMember: true }
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
// src/events/rules/collabNulls.gen.ts
|
|
639
|
+
var collabCursorEventNulls = { position: true };
|
|
640
|
+
var collabSelectionEventNulls = { selection: true };
|
|
641
|
+
var collabStreamEventNulls = ["type", { cursor: collabCursorEventNulls, selection: collabSelectionEventNulls }];
|
|
642
|
+
|
|
643
|
+
// src/events/rules/collab.ts
|
|
644
|
+
var collabStreamEventTypes = {
|
|
645
|
+
"collection.changed": "collection.changed",
|
|
646
|
+
cursor: "cursor",
|
|
647
|
+
"draft.clear": "draft.clear",
|
|
648
|
+
"draft.update": "draft.update",
|
|
649
|
+
"itinerary.changed": "itinerary.changed",
|
|
650
|
+
"lock.acquired": "lock.acquired",
|
|
651
|
+
"lock.released": "lock.released",
|
|
652
|
+
"lock.snapshot": "lock.snapshot",
|
|
653
|
+
"presence.join": "presence.join",
|
|
654
|
+
"presence.leave": "presence.leave",
|
|
655
|
+
"presence.snapshot": "presence.snapshot",
|
|
656
|
+
reconnect: "reconnect",
|
|
657
|
+
"segment.changed": "segment.changed",
|
|
658
|
+
selection: "selection",
|
|
659
|
+
"waypoint.changed": "waypoint.changed",
|
|
660
|
+
"zone.changed": "zone.changed"
|
|
661
|
+
};
|
|
662
|
+
var collabEventDates = collabStreamEventDatesByType;
|
|
663
|
+
var NIL_UUID = "00000000-0000-0000-0000-000000000000";
|
|
664
|
+
var isTerminalStatus = (status) => status >= 400 && status < 500 && status !== 429;
|
|
665
|
+
var REOPEN_REPEATS_ERROR_NAMES = [
|
|
666
|
+
"MountayaConfigurationError",
|
|
667
|
+
"SseBufferOverflowError"
|
|
668
|
+
];
|
|
669
|
+
var holderIdOf = (metadata) => {
|
|
670
|
+
const holder = metadata?.holder;
|
|
671
|
+
if (typeof holder !== "object" || holder === null || !("id" in holder)) {
|
|
672
|
+
return void 0;
|
|
673
|
+
}
|
|
674
|
+
const { id } = holder;
|
|
675
|
+
return typeof id === "string" && id !== "" && id !== NIL_UUID ? id : void 0;
|
|
676
|
+
};
|
|
677
|
+
var decodeCollabFrame = (frame) => {
|
|
678
|
+
if (!Object.hasOwn(collabStreamEventTypes, frame.event)) {
|
|
679
|
+
return null;
|
|
680
|
+
}
|
|
681
|
+
let payload;
|
|
682
|
+
try {
|
|
683
|
+
payload = frame.data ? parseJsonWithDates(frame.data, collabEventDates[frame.event]) : {};
|
|
684
|
+
} catch {
|
|
685
|
+
return null;
|
|
686
|
+
}
|
|
687
|
+
if (typeof payload !== "object" || payload === null) {
|
|
688
|
+
return null;
|
|
689
|
+
}
|
|
690
|
+
return withAbsentNulls({ ...payload, type: frame.event }, collabStreamEventNulls);
|
|
691
|
+
};
|
|
692
|
+
var createCollabTransport = (transport) => {
|
|
693
|
+
const subscribeStream = (operationId, path, handlers, options) => {
|
|
694
|
+
const seam = transport.streamSeam;
|
|
695
|
+
let subscriberFault;
|
|
696
|
+
const asSubscriber = (call) => {
|
|
697
|
+
try {
|
|
698
|
+
call();
|
|
699
|
+
} catch (thrown) {
|
|
700
|
+
subscriberFault = { thrown };
|
|
701
|
+
throw thrown;
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
let expiresAt;
|
|
705
|
+
let userId;
|
|
706
|
+
let reconnected = false;
|
|
707
|
+
return openDeclaredSseStream(
|
|
708
|
+
{
|
|
709
|
+
// What each collaboration stream declares, stated as its generated operation states it:
|
|
710
|
+
// its only security requirement pairs the key with a session token, and it acts as the
|
|
711
|
+
// member that token names. Stating both here is what refuses a credential carrying no
|
|
712
|
+
// session token, or one a source reports as minted without `user_id`, before the open,
|
|
713
|
+
// and a share token, which no stream accepts; the refusal reaches onError below.
|
|
714
|
+
applyAuth: (init, method) => {
|
|
715
|
+
const applied = seam.applyAuth(init, method, {
|
|
716
|
+
actsAsMember: true,
|
|
717
|
+
operationId,
|
|
718
|
+
requiresSession: true
|
|
719
|
+
});
|
|
720
|
+
expiresAt = seam.sessionExpiresAt();
|
|
721
|
+
userId = seam.sessionUserId() ?? void 0;
|
|
722
|
+
return applied;
|
|
723
|
+
},
|
|
724
|
+
// A frame skipped is still one the stream delivered, which the subscriber is told of as it
|
|
725
|
+
// is read, in order with the frames handed over.
|
|
726
|
+
decode: (frame) => {
|
|
727
|
+
const event = decodeCollabFrame(frame);
|
|
728
|
+
if (event === null) {
|
|
729
|
+
asSubscriber(() => handlers.onSkippedFrame?.());
|
|
730
|
+
}
|
|
731
|
+
return event;
|
|
732
|
+
},
|
|
733
|
+
doFetch: seam.doFetch,
|
|
734
|
+
lastEventId: options?.lastEventId,
|
|
735
|
+
// The last record before a close can be lost on its way, so a close once the token has
|
|
736
|
+
// expired is read as the `reconnect` the API would have written.
|
|
737
|
+
onClose: () => {
|
|
738
|
+
const expired = expiresAt !== void 0 && Date.now() >= expiresAt.getTime();
|
|
739
|
+
handlers.onClose(reconnected || expired ? "reconnect" : "ended");
|
|
740
|
+
},
|
|
741
|
+
// Classify the failure so a session stops its loop instead of reconnecting forever.
|
|
742
|
+
// The unrecoverable faults arrive by different routes: a credential the seam refuses
|
|
743
|
+
// before the open, which a reopen refuses again; a runtime whose fetch streams no body,
|
|
744
|
+
// which every reopen meets again; a terminal status on the open, a 401 on the reopen
|
|
745
|
+
// after a `reconnect` among them; a producer that never terminates a frame, whose read
|
|
746
|
+
// the parser fails at its buffer cap, where reopening only re-buffers to the same cap
|
|
747
|
+
// against the same producer; and a fault the subscriber's own `onFrame` or
|
|
748
|
+
// `onLastEventId` threw, whatever it threw, since a reopen resumes from the subscriber's
|
|
749
|
+
// cursor and hands the same durable frame to the same callback. Every other mid-stream
|
|
750
|
+
// fault is the stream's, which a reconnect does fix.
|
|
751
|
+
//
|
|
752
|
+
// Read by the name each class declares rather than by constructor, so a failure a second
|
|
753
|
+
// copy of this package threw is classified the same way.
|
|
754
|
+
onError: (error) => {
|
|
755
|
+
const terminal = subscriberFault !== void 0 && subscriberFault.thrown === error || isMountayaError(error) && REOPEN_REPEATS_ERROR_NAMES.includes(error.name) || isMountayaApiError(error) && isTerminalStatus(error.status);
|
|
756
|
+
handlers.onError(error, { terminal });
|
|
757
|
+
},
|
|
758
|
+
onFrame: (event, id) => {
|
|
759
|
+
if (event.type === collabStreamEventTypes.reconnect) {
|
|
760
|
+
reconnected = true;
|
|
761
|
+
return true;
|
|
762
|
+
}
|
|
763
|
+
asSubscriber(() => handlers.onFrame({ event, id }));
|
|
764
|
+
return false;
|
|
765
|
+
},
|
|
766
|
+
onLastEventId: (lastEventId) => {
|
|
767
|
+
asSubscriber(() => handlers.onLastEventId?.(lastEventId));
|
|
768
|
+
},
|
|
769
|
+
onResponse: (response) => {
|
|
770
|
+
seam.report(response, operationId);
|
|
771
|
+
if (response.ok) {
|
|
772
|
+
asSubscriber(() => handlers.onOpen?.({ userId }));
|
|
773
|
+
}
|
|
774
|
+
},
|
|
775
|
+
operationId,
|
|
776
|
+
signal: options?.signal,
|
|
777
|
+
// The wait for the stream's response is the client's own per-attempt budget.
|
|
778
|
+
timeoutMs: seam.timeoutMs,
|
|
779
|
+
// Resolved when the open is made, so an id the path cannot carry (an empty one, or a dot
|
|
780
|
+
// segment) is refused through onError like any other failed open.
|
|
781
|
+
url: () => seam.url(path, operationId),
|
|
782
|
+
waitForSession: (signal) => seam.waitForSession(operationId, signal)
|
|
783
|
+
},
|
|
784
|
+
// The same declaration the credential is stamped by, so a refused open names the step a
|
|
785
|
+
// member following the resource takes.
|
|
786
|
+
{ actsAsMember: true }
|
|
787
|
+
);
|
|
788
|
+
};
|
|
789
|
+
return {
|
|
790
|
+
sendSignal: async (resource, signal) => {
|
|
791
|
+
try {
|
|
792
|
+
if (resource.kind === "itineraries") {
|
|
793
|
+
await postItineraryCollab(transport, { body: signal, itinerary_id: resource.id });
|
|
794
|
+
} else {
|
|
795
|
+
await postZoneCollab(transport, { body: signal, zone_id: resource.id });
|
|
796
|
+
}
|
|
797
|
+
} catch (error) {
|
|
798
|
+
if (isMountayaApiError(error) && error.status === 409) {
|
|
799
|
+
return { holderId: holderIdOf(error.metadata), ok: false };
|
|
800
|
+
}
|
|
801
|
+
throw error;
|
|
802
|
+
}
|
|
803
|
+
return { ok: true };
|
|
804
|
+
},
|
|
805
|
+
subscribeEditor: (resource, handlers, options) => (
|
|
806
|
+
// resource.kind is a fixed collection literal, so it rides the path as-is; only the id
|
|
807
|
+
// is percent-encoded.
|
|
808
|
+
subscribeStream(
|
|
809
|
+
resource.kind === "itineraries" ? "getItineraryEvents" : "getZoneEvents",
|
|
810
|
+
`/v1/${resource.kind}/${encodeURIComponent(resource.id)}/events`,
|
|
811
|
+
handlers,
|
|
812
|
+
options
|
|
813
|
+
)
|
|
814
|
+
),
|
|
815
|
+
subscribeList: (organizationId, handlers, options) => subscribeStream(
|
|
816
|
+
"getOrganizationEvents",
|
|
817
|
+
`/v1/organizations/${encodeURIComponent(organizationId)}/events`,
|
|
818
|
+
handlers,
|
|
819
|
+
options
|
|
820
|
+
)
|
|
821
|
+
};
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
export { MAX_SSE_BUFFER_CHARS, SseBufferOverflowError, SseFrameParser, agentTerminalEventTypes, createAgentTransport, createCollabTransport, decodeAgentFrame, decodeCollabFrame, openSseStream, readEventStream };
|
|
825
|
+
//# sourceMappingURL=index.js.map
|
|
826
|
+
//# sourceMappingURL=index.js.map
|