@genex-ai/embed-sdk 0.30.1 → 0.32.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.
@@ -0,0 +1,534 @@
1
+ // ../embed-protocol/src/constants.ts
2
+ var NATIVE_CHANNEL = "genex-native";
3
+ var NATIVE_PROTOCOL_VERSION = 1;
4
+ var NATIVE_MARKER_PARAM = "genex_native";
5
+ var NATIVE_MARKER_VALUE = "1";
6
+ var NATIVE_PROTOCOL_PARAM = "genex_protocol";
7
+ var NATIVE_ATTEMPT_PARAM = "genex_attempt";
8
+ var NATIVE_NONCE_PARAM = "genex_nonce";
9
+ var NATIVE_CAPS_PARAM = "genex_caps";
10
+ var RESERVED_QUERY_PREFIX = "genex_";
11
+ var DASHBOARD_RESERVED_KEYS = ["ref", "s", "from", "remix", "embed", "slug"];
12
+ var RETURN_MARKER_PARAM = "genex_r";
13
+ var AUTHORIZE_ENTRY_REF_PARAM = "entryRef";
14
+ var ENTRY_HASH_KEY = "genex_hash";
15
+ var ENTRY_REFERRER_KEY = "genex_referrer";
16
+ var EMBED_REFERRER_PARAM = "genex_ref";
17
+ var MAX_ENTRY_QUERY_LENGTH = 1024;
18
+ var MAX_ENTRY_HASH_LENGTH = 4096;
19
+ var MAX_ENTRY_REFERRER_LENGTH = 255;
20
+ var MAX_RETURN_TO_LENGTH = 2048;
21
+ var NATIVE_RECEIVER = "__genexNative";
22
+ var MAX_BRIDGE_MESSAGE_BYTES = 4096;
23
+ var BRIDGE_ID_LENGTH = 32;
24
+ var BRIDGE_ID_RE = /^[0-9a-f]{32}$/;
25
+ var SLUG_RE = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
26
+ function isBridgeId(value) {
27
+ return typeof value === "string" && BRIDGE_ID_RE.test(value);
28
+ }
29
+ function isBridgeSlug(value) {
30
+ return typeof value === "string" && SLUG_RE.test(value);
31
+ }
32
+
33
+ // ../embed-protocol/src/base64url.ts
34
+ var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
35
+ var LOOKUP = (() => {
36
+ const table = new Array(128).fill(-1);
37
+ for (let i = 0; i < ALPHABET.length; i++) table[ALPHABET.charCodeAt(i)] = i;
38
+ return table;
39
+ })();
40
+ function utf8Bytes(text) {
41
+ const out = [];
42
+ for (let i = 0; i < text.length; i++) {
43
+ let code = text.charCodeAt(i);
44
+ if (code >= 55296 && code <= 56319) {
45
+ const next = i + 1 < text.length ? text.charCodeAt(i + 1) : 0;
46
+ if (next >= 56320 && next <= 57343) {
47
+ code = 65536 + (code - 55296 << 10) + (next - 56320);
48
+ i++;
49
+ } else {
50
+ code = 65533;
51
+ }
52
+ } else if (code >= 56320 && code <= 57343) {
53
+ code = 65533;
54
+ }
55
+ if (code < 128) out.push(code);
56
+ else if (code < 2048) out.push(192 | code >> 6, 128 | code & 63);
57
+ else if (code < 65536) {
58
+ out.push(224 | code >> 12, 128 | code >> 6 & 63, 128 | code & 63);
59
+ } else {
60
+ out.push(
61
+ 240 | code >> 18,
62
+ 128 | code >> 12 & 63,
63
+ 128 | code >> 6 & 63,
64
+ 128 | code & 63
65
+ );
66
+ }
67
+ }
68
+ return out;
69
+ }
70
+ function utf8Text(bytes) {
71
+ let out = "";
72
+ for (let i = 0; i < bytes.length; ) {
73
+ const b0 = bytes[i];
74
+ let code;
75
+ let size;
76
+ if (b0 < 128) {
77
+ code = b0;
78
+ size = 1;
79
+ } else if ((b0 & 224) === 192) {
80
+ code = b0 & 31;
81
+ size = 2;
82
+ } else if ((b0 & 240) === 224) {
83
+ code = b0 & 15;
84
+ size = 3;
85
+ } else if ((b0 & 248) === 240) {
86
+ code = b0 & 7;
87
+ size = 4;
88
+ } else return null;
89
+ if (i + size > bytes.length) return null;
90
+ for (let k = 1; k < size; k++) {
91
+ const b = bytes[i + k];
92
+ if ((b & 192) !== 128) return null;
93
+ code = code << 6 | b & 63;
94
+ }
95
+ if (size === 2 && code < 128) return null;
96
+ if (size === 3 && (code < 2048 || code >= 55296 && code <= 57343)) return null;
97
+ if (size === 4 && (code < 65536 || code > 1114111)) return null;
98
+ if (code > 65535) {
99
+ const v = code - 65536;
100
+ out += String.fromCharCode(55296 + (v >> 10), 56320 + (v & 1023));
101
+ } else {
102
+ out += String.fromCharCode(code);
103
+ }
104
+ i += size;
105
+ }
106
+ return out;
107
+ }
108
+ function utf8ByteLength(text) {
109
+ return utf8Bytes(text).length;
110
+ }
111
+ function encodeBase64UrlJson(value) {
112
+ const bytes = utf8Bytes(JSON.stringify(value));
113
+ let out = "";
114
+ for (let i = 0; i < bytes.length; i += 3) {
115
+ const b0 = bytes[i];
116
+ const b1 = bytes[i + 1];
117
+ const b2 = bytes[i + 2];
118
+ out += ALPHABET[b0 >> 2];
119
+ out += ALPHABET[(b0 & 3) << 4 | (b1 ?? 0) >> 4];
120
+ if (b1 === void 0) break;
121
+ out += ALPHABET[(b1 & 15) << 2 | (b2 ?? 0) >> 6];
122
+ if (b2 === void 0) break;
123
+ out += ALPHABET[b2 & 63];
124
+ }
125
+ return out;
126
+ }
127
+ function decodeBase64UrlJson(encoded) {
128
+ if (encoded.length % 4 === 1) return void 0;
129
+ const bytes = [];
130
+ let buffer = 0;
131
+ let bits = 0;
132
+ for (let i = 0; i < encoded.length; i++) {
133
+ const code = encoded.charCodeAt(i);
134
+ const value = code < 128 ? LOOKUP[code] : -1;
135
+ if (value < 0) return void 0;
136
+ buffer = buffer << 6 | value;
137
+ bits += 6;
138
+ if (bits >= 8) {
139
+ bits -= 8;
140
+ bytes.push(buffer >> bits & 255);
141
+ }
142
+ }
143
+ if (bits > 0 && (buffer & (1 << bits) - 1) !== 0) return void 0;
144
+ const text = utf8Text(bytes);
145
+ if (text === null) return void 0;
146
+ try {
147
+ return JSON.parse(text);
148
+ } catch {
149
+ return void 0;
150
+ }
151
+ }
152
+
153
+ // ../embed-protocol/src/messages.ts
154
+ var MAX_TICKET_LENGTH = 2048;
155
+ var MAX_EXPIRES_AT_LENGTH = 32;
156
+ var ISO_INSTANT_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$/;
157
+ function isRecord(value) {
158
+ return typeof value === "object" && value !== null && !Array.isArray(value);
159
+ }
160
+ function hasExactKeys(value, keys) {
161
+ const own = Object.keys(value);
162
+ if (own.length !== keys.length) return false;
163
+ for (const key of keys) {
164
+ if (!Object.prototype.hasOwnProperty.call(value, key)) return false;
165
+ }
166
+ return true;
167
+ }
168
+ var BASE_KEYS = ["channel", "v", "type", "slug", "attemptId", "nonce"];
169
+ function envelopeBaseIsValid(value) {
170
+ return value.channel === NATIVE_CHANNEL && value.v === NATIVE_PROTOCOL_VERSION && isBridgeSlug(value.slug) && isBridgeId(value.attemptId) && isBridgeId(value.nonce);
171
+ }
172
+ function parseBridgeNativeCommand(value) {
173
+ if (!isRecord(value) || !envelopeBaseIsValid(value)) return void 0;
174
+ switch (value.type) {
175
+ case "ticket":
176
+ if (!hasExactKeys(value, [...BASE_KEYS, "ticket", "expiresAt"])) return void 0;
177
+ if (typeof value.ticket !== "string" || value.ticket.length === 0 || value.ticket.length > MAX_TICKET_LENGTH) {
178
+ return void 0;
179
+ }
180
+ if (typeof value.expiresAt !== "string" || value.expiresAt.length > MAX_EXPIRES_AT_LENGTH || !ISO_INSTANT_RE.test(value.expiresAt)) {
181
+ return void 0;
182
+ }
183
+ return value;
184
+ case "guest":
185
+ case "cancel":
186
+ if (!hasExactKeys(value, BASE_KEYS)) return void 0;
187
+ return value;
188
+ case "foreground":
189
+ if (!hasExactKeys(value, [...BASE_KEYS, "active"])) return void 0;
190
+ if (typeof value.active !== "boolean") return void 0;
191
+ return value;
192
+ case "network":
193
+ if (!hasExactKeys(value, [...BASE_KEYS, "online"])) return void 0;
194
+ if (typeof value.online !== "boolean") return void 0;
195
+ return value;
196
+ default:
197
+ return void 0;
198
+ }
199
+ }
200
+
201
+ // ../embed-protocol/src/transport.ts
202
+ function read(raw, parse) {
203
+ if (typeof raw !== "string" || raw.length === 0) return { ok: false, reason: "undecodable" };
204
+ if (utf8ByteLength(raw) > MAX_BRIDGE_MESSAGE_BYTES) return { ok: false, reason: "too-large" };
205
+ const decoded = decodeBase64UrlJson(raw);
206
+ if (decoded === void 0) return { ok: false, reason: "undecodable" };
207
+ const message = parse(decoded);
208
+ if (message === void 0) return { ok: false, reason: "invalid" };
209
+ return { ok: true, message };
210
+ }
211
+ function readBridgeNativeCommand(raw) {
212
+ return read(raw, parseBridgeNativeCommand);
213
+ }
214
+ function encodeBridgeMessage(message) {
215
+ const encoded = encodeBase64UrlJson(message);
216
+ if (encoded.length > MAX_BRIDGE_MESSAGE_BYTES) return void 0;
217
+ return encoded;
218
+ }
219
+
220
+ // ../embed-protocol/src/entry-url.ts
221
+ function readParam(search, key) {
222
+ const query = search.charAt(0) === "?" ? search.slice(1) : search;
223
+ if (query.length === 0) return null;
224
+ for (const pair of query.split("&")) {
225
+ const eq = pair.indexOf("=");
226
+ if (eq === -1) continue;
227
+ if (pair.slice(0, eq) === key) return pair.slice(eq + 1);
228
+ }
229
+ return null;
230
+ }
231
+ function hasNativeMarker(search) {
232
+ return readParam(search, NATIVE_MARKER_PARAM) === NATIVE_MARKER_VALUE;
233
+ }
234
+ function readNativeEntry(search) {
235
+ if (!hasNativeMarker(search)) return null;
236
+ const attemptId = readParam(search, NATIVE_ATTEMPT_PARAM);
237
+ const nonce = readParam(search, NATIVE_NONCE_PARAM);
238
+ const protocol = Number(readParam(search, NATIVE_PROTOCOL_PARAM));
239
+ if (!isBridgeId(attemptId) || !isBridgeId(nonce)) return null;
240
+ if (protocol !== NATIVE_PROTOCOL_VERSION) return null;
241
+ return { attemptId, nonce, protocol };
242
+ }
243
+ function decodeAsciiEscapes(text) {
244
+ if (text.indexOf("%") === -1) return text;
245
+ return text.replace(/%([0-9A-Fa-f]{2})/g, (escape, hex) => {
246
+ const code = parseInt(hex, 16);
247
+ return code < 128 ? String.fromCharCode(code) : escape;
248
+ });
249
+ }
250
+ function pairKey(pair) {
251
+ const eq = pair.indexOf("=");
252
+ const raw = eq === -1 ? pair : pair.slice(0, eq);
253
+ return decodeAsciiEscapes(raw.indexOf("+") === -1 ? raw : raw.split("+").join(" "));
254
+ }
255
+ function stripReturnMarker(search) {
256
+ return stripPairs(search, [RETURN_MARKER_PARAM]);
257
+ }
258
+ var NATIVE_ENTRY_PARAMS = [
259
+ NATIVE_MARKER_PARAM,
260
+ NATIVE_PROTOCOL_PARAM,
261
+ NATIVE_ATTEMPT_PARAM,
262
+ NATIVE_NONCE_PARAM,
263
+ NATIVE_CAPS_PARAM
264
+ ];
265
+ function stripNativeEntry(search) {
266
+ return stripPairs(search, NATIVE_ENTRY_PARAMS);
267
+ }
268
+ function stripPairs(search, keys) {
269
+ const query = search.charAt(0) === "?" ? search.slice(1) : search;
270
+ if (query.length === 0) return "";
271
+ const pairs = query.split("&");
272
+ const kept = pairs.filter((pair) => !keys.includes(pairKey(pair)));
273
+ if (kept.length === pairs.length) return `?${query}`;
274
+ const rest = kept.join("&");
275
+ return rest.length === 0 ? "" : `?${rest}`;
276
+ }
277
+ var QUERY_VERBATIM_RE = /^[!$-&(-;=?-~]+$/;
278
+ function sanitizePassthroughQuery(search, reservedKeys) {
279
+ if (typeof search !== "string") return "";
280
+ let query = search.charAt(0) === "?" ? search.slice(1) : search;
281
+ const fragmentAt = query.indexOf("#");
282
+ if (fragmentAt !== -1) query = query.slice(0, fragmentAt);
283
+ if (query.length === 0 || !QUERY_VERBATIM_RE.test(query)) return "";
284
+ const kept = query.split("&").filter((pair) => {
285
+ if (pair.length === 0) return false;
286
+ const key = pairKey(pair);
287
+ return !key.startsWith(RESERVED_QUERY_PREFIX) && !reservedKeys.includes(key);
288
+ });
289
+ const passthrough = kept.join("&");
290
+ return passthrough.length > MAX_ENTRY_QUERY_LENGTH ? "" : passthrough;
291
+ }
292
+ var HASH_VERBATIM_RE = /^#[!#-;=?-_a-~]+$/;
293
+ function sanitizeEntryHash(hash) {
294
+ if (typeof hash !== "string") return "";
295
+ if (hash.length < 2 || hash.length > MAX_ENTRY_HASH_LENGTH) return "";
296
+ if (!HASH_VERBATIM_RE.test(hash)) return "";
297
+ if (decodeAsciiEscapes(hash).includes(RESERVED_QUERY_PREFIX)) return "";
298
+ return hash;
299
+ }
300
+ var HOST_NAME_RE = /^[a-z0-9._-]+$/;
301
+ var HOST_IPV6_RE = /^\[[0-9a-f:.]+\]$/;
302
+ function isHost(host) {
303
+ return HOST_NAME_RE.test(host) && /[a-z0-9]/.test(host) || HOST_IPV6_RE.test(host);
304
+ }
305
+ function httpOrigin(value) {
306
+ const head = value.slice(0, 8).toLowerCase();
307
+ const scheme = head === "https://" ? "https" : head.slice(0, 7) === "http://" ? "http" : null;
308
+ if (scheme === null) return null;
309
+ const start = scheme.length + 3;
310
+ let end = value.length;
311
+ for (let i = start; i < value.length; i++) {
312
+ const c = value.charAt(i);
313
+ if (c === "/" || c === "?" || c === "#" || c === "\\") {
314
+ end = i;
315
+ break;
316
+ }
317
+ }
318
+ if (end - start > 255) return null;
319
+ const authority = value.slice(start, end).toLowerCase();
320
+ if (authority.length === 0 || authority.indexOf("@") !== -1) return null;
321
+ let host = authority;
322
+ let port = "";
323
+ const colon = authority.lastIndexOf(":");
324
+ if (colon !== -1 && authority.charAt(authority.length - 1) !== "]") {
325
+ host = authority.slice(0, colon);
326
+ port = authority.slice(colon + 1);
327
+ }
328
+ if (!isHost(host)) return null;
329
+ if (port.length > 0) {
330
+ if (!/^[0-9]{1,5}$/.test(port)) return null;
331
+ const number = Number(port);
332
+ if (number > 65535) return null;
333
+ port = number === (scheme === "https" ? 443 : 80) ? "" : `:${number}`;
334
+ }
335
+ return `${scheme}://${host}${port}`;
336
+ }
337
+ function sanitizeEntryReferrer(value, ownOrigin) {
338
+ if (typeof value !== "string" || value.length === 0) return null;
339
+ const origin = httpOrigin(value);
340
+ if (origin === null || origin.length > MAX_ENTRY_REFERRER_LENGTH) return null;
341
+ if (typeof ownOrigin === "string" && httpOrigin(ownOrigin) === origin) return null;
342
+ return origin;
343
+ }
344
+
345
+ // ../embed-protocol/src/platform.ts
346
+ var PLATFORM_REQUEST_TYPE = "genex:platform:request";
347
+ var PLATFORM_RESULT_TYPE = "genex:platform:result";
348
+ var PLATFORM_PROTOCOL_VERSION = 1;
349
+ var PLATFORM_CAPS = ["open", "save", "fullscreen"];
350
+ var PLATFORM_ERRORS = [
351
+ "unsupported",
352
+ "needs_gesture",
353
+ "dismissed",
354
+ "busy",
355
+ "rate_limited",
356
+ "invalid_request",
357
+ "too_large",
358
+ "timeout"
359
+ ];
360
+ var MAX_PLATFORM_URL_LENGTH = 2048;
361
+ var MAX_SAVE_NAME_LENGTH = 128;
362
+ var SAVE_MIME_ALLOWLIST = [
363
+ "image/png",
364
+ "image/jpeg",
365
+ "image/webp",
366
+ "video/webm",
367
+ "video/mp4",
368
+ "application/json",
369
+ "text/plain"
370
+ ];
371
+ var SAVE_MAX_BYTES = 50 * 1024 * 1024;
372
+ var MAX_ADVERTISED_CAPS = 16;
373
+ var MAX_MIME_LENGTH = 255;
374
+ function isRecord2(value) {
375
+ return typeof value === "object" && value !== null && !Array.isArray(value);
376
+ }
377
+ function hasExactKeys2(value, keys) {
378
+ const own = Object.keys(value);
379
+ if (own.length !== keys.length) return false;
380
+ for (const key of keys) {
381
+ if (!Object.prototype.hasOwnProperty.call(value, key)) return false;
382
+ }
383
+ return true;
384
+ }
385
+ function isPlatformCap(value) {
386
+ return typeof value === "string" && PLATFORM_CAPS.includes(value);
387
+ }
388
+ function isPlatformError(value) {
389
+ return typeof value === "string" && PLATFORM_ERRORS.includes(value);
390
+ }
391
+ function readPlatformCaps(value) {
392
+ if (!Array.isArray(value)) return [];
393
+ const caps = [];
394
+ const count = Math.min(value.length, MAX_ADVERTISED_CAPS);
395
+ for (let i = 0; i < count; i++) {
396
+ const cap = value[i];
397
+ if (isPlatformCap(cap) && !caps.includes(cap)) caps.push(cap);
398
+ }
399
+ return caps;
400
+ }
401
+ var VISIBLE_ASCII_RE = /^[!-~]+$/;
402
+ function isPlatformUrl(value) {
403
+ if (typeof value !== "string" || value.length > MAX_PLATFORM_URL_LENGTH) return false;
404
+ if (value.slice(0, 8) !== "https://" || !VISIBLE_ASCII_RE.test(value)) return false;
405
+ return httpOrigin(value) !== null;
406
+ }
407
+ var SAVE_NAME_REFUSED_RE = /[\u0000-\u001f\u007f-\u009f\u061c\u200e\u200f\u2028-\u202e\u2066-\u2069\/\\]/;
408
+ function isSaveName(value) {
409
+ return typeof value === "string" && value.length >= 1 && value.length <= MAX_SAVE_NAME_LENGTH && !SAVE_NAME_REFUSED_RE.test(value);
410
+ }
411
+ function savableMime(type) {
412
+ if (typeof type !== "string" || type.length > MAX_MIME_LENGTH) return null;
413
+ const semicolon = type.indexOf(";");
414
+ const essence = (semicolon === -1 ? type : type.slice(0, semicolon)).trim().toLowerCase();
415
+ for (const mime of SAVE_MIME_ALLOWLIST) {
416
+ if (mime === essence) return mime;
417
+ }
418
+ return null;
419
+ }
420
+ function isSavableFile(value) {
421
+ if (typeof value !== "object" || value === null) return false;
422
+ const tag = Object.prototype.toString.call(value);
423
+ if (tag !== "[object Blob]" && tag !== "[object File]") return false;
424
+ const file = value;
425
+ return typeof file.size === "number" && Number.isInteger(file.size) && file.size >= 0 && file.size <= SAVE_MAX_BYTES && savableMime(file.type) !== null;
426
+ }
427
+ var OPEN_KEYS = ["type", "v", "id", "cap", "url"];
428
+ var SAVE_KEYS = ["type", "v", "id", "cap", "name", "file"];
429
+ var FULLSCREEN_KEYS = ["type", "v", "id", "cap", "on"];
430
+ function parsePlatformRequest(value) {
431
+ if (!isRecord2(value)) return void 0;
432
+ if (value.type !== PLATFORM_REQUEST_TYPE || value.v !== PLATFORM_PROTOCOL_VERSION) return void 0;
433
+ if (!isBridgeId(value.id)) return void 0;
434
+ const base = { type: PLATFORM_REQUEST_TYPE, v: PLATFORM_PROTOCOL_VERSION, id: value.id };
435
+ switch (value.cap) {
436
+ case "open":
437
+ if (!hasExactKeys2(value, OPEN_KEYS) || !isPlatformUrl(value.url)) return void 0;
438
+ return { ...base, cap: "open", url: value.url };
439
+ case "save":
440
+ if (!hasExactKeys2(value, SAVE_KEYS)) return void 0;
441
+ if (!isSaveName(value.name) || !isSavableFile(value.file)) return void 0;
442
+ return { ...base, cap: "save", name: value.name, file: value.file };
443
+ case "fullscreen":
444
+ if (!hasExactKeys2(value, FULLSCREEN_KEYS) || typeof value.on !== "boolean") return void 0;
445
+ return { ...base, cap: "fullscreen", on: value.on };
446
+ default:
447
+ return void 0;
448
+ }
449
+ }
450
+ var RESULT_OK_KEYS = ["type", "v", "id", "ok"];
451
+ var RESULT_FAILED_KEYS = ["type", "v", "id", "ok", "code"];
452
+ function parsePlatformResult(value) {
453
+ if (!isRecord2(value)) return void 0;
454
+ if (value.type !== PLATFORM_RESULT_TYPE || value.v !== PLATFORM_PROTOCOL_VERSION) return void 0;
455
+ if (!isBridgeId(value.id)) return void 0;
456
+ const base = { type: PLATFORM_RESULT_TYPE, v: PLATFORM_PROTOCOL_VERSION, id: value.id };
457
+ if (value.ok === true) {
458
+ return hasExactKeys2(value, RESULT_OK_KEYS) ? { ...base, ok: true } : void 0;
459
+ }
460
+ if (value.ok === false) {
461
+ if (!hasExactKeys2(value, RESULT_FAILED_KEYS) || !isPlatformError(value.code)) return void 0;
462
+ return { ...base, ok: false, code: value.code };
463
+ }
464
+ return void 0;
465
+ }
466
+
467
+ // ../embed-protocol/src/runtime-generation.ts
468
+ function isGenerationId(value) {
469
+ return typeof value === "string" && /^[A-Za-z0-9_-]{1,128}$/.test(value);
470
+ }
471
+ function parseGenerationStreamEvent(event, data) {
472
+ let value;
473
+ try {
474
+ value = JSON.parse(data);
475
+ } catch {
476
+ return void 0;
477
+ }
478
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
479
+ const fields = value;
480
+ if (event === "start") return isGenerationId(fields.generationId) ? { event, data: { generationId: fields.generationId } } : void 0;
481
+ if (event === "delta") return typeof fields.text === "string" ? { event, data: { text: fields.text } } : void 0;
482
+ if (event === "done") return isGenerationId(fields.id) && typeof fields.status === "string" ? { event, data: value } : void 0;
483
+ return void 0;
484
+ }
485
+ function isGenerationTerminal(status) {
486
+ return ["succeeded", "failed", "unknown", "canceled", "expired"].includes(status);
487
+ }
488
+
489
+ // ../embed-protocol/src/ids.ts
490
+ var HEX = "0123456789abcdef";
491
+ function createBridgeId(random = Math.random) {
492
+ let out = "";
493
+ for (let i = 0; i < BRIDGE_ID_LENGTH; i++) {
494
+ const index = Math.min(15, Math.max(0, random() * 16 | 0));
495
+ out += HEX[index];
496
+ }
497
+ return out;
498
+ }
499
+
500
+ export {
501
+ NATIVE_CHANNEL,
502
+ NATIVE_PROTOCOL_VERSION,
503
+ RESERVED_QUERY_PREFIX,
504
+ DASHBOARD_RESERVED_KEYS,
505
+ AUTHORIZE_ENTRY_REF_PARAM,
506
+ ENTRY_HASH_KEY,
507
+ ENTRY_REFERRER_KEY,
508
+ EMBED_REFERRER_PARAM,
509
+ MAX_ENTRY_QUERY_LENGTH,
510
+ MAX_RETURN_TO_LENGTH,
511
+ NATIVE_RECEIVER,
512
+ createBridgeId,
513
+ readBridgeNativeCommand,
514
+ encodeBridgeMessage,
515
+ hasNativeMarker,
516
+ readNativeEntry,
517
+ stripReturnMarker,
518
+ stripNativeEntry,
519
+ sanitizePassthroughQuery,
520
+ sanitizeEntryHash,
521
+ sanitizeEntryReferrer,
522
+ PLATFORM_REQUEST_TYPE,
523
+ PLATFORM_PROTOCOL_VERSION,
524
+ SAVE_MAX_BYTES,
525
+ readPlatformCaps,
526
+ isPlatformUrl,
527
+ isSaveName,
528
+ savableMime,
529
+ parsePlatformRequest,
530
+ parsePlatformResult,
531
+ isGenerationId,
532
+ parseGenerationStreamEvent,
533
+ isGenerationTerminal
534
+ };
@@ -1,4 +1,4 @@
1
- import { R as RuntimeJudgeQuestion, a as RuntimeWorkflowInput, b as RuntimeGenerationView } from './runtime-generation-sXuSFc3c.js';
1
+ import { R as RuntimeJudgeQuestion, a as RuntimeWorkflowInput, b as RuntimeGenerationView } from './runtime-generation-B3oFDmCp.js';
2
2
 
3
3
  /**
4
4
  * Server-only benchmarks spend the authenticated creator's OWN CREDITS
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isGenerationId,
3
3
  isGenerationTerminal
4
- } from "./chunk-MJPLBT3T.js";
4
+ } from "./chunk-QBCWKMVQ.js";
5
5
 
6
6
  // src/development.ts
7
7
  var DEVELOPMENT_WAIT_MS = 12e5;