@tangle-network/agent-app 0.63.30 → 0.63.31

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 (133) hide show
  1. package/dist/{DesignCanvas-3DGZQOD7.js → DesignCanvas-VKZ7Y3JU.js} +2 -3
  2. package/dist/{DesignCanvasEditor-OG4QY5WJ.js → DesignCanvasEditor-3V53YLLZ.js} +2 -3
  3. package/dist/agent-profiles/d1.js +4 -3
  4. package/dist/agent-profiles/d1.js.map +1 -1
  5. package/dist/agent-profiles/index.js +4 -3
  6. package/dist/alerting/github.d.ts +33 -0
  7. package/dist/alerting/index.d.ts +1 -0
  8. package/dist/alerting/index.js +47 -0
  9. package/dist/alerting/index.js.map +1 -1
  10. package/dist/app-auth/index.js +1 -2
  11. package/dist/app-auth/index.js.map +1 -1
  12. package/dist/assistant/index.js +4 -4
  13. package/dist/billing/index.d.ts +15 -0
  14. package/dist/billing/index.js +5 -3
  15. package/dist/chat-routes/index.js +15 -14
  16. package/dist/chat-routes/index.js.map +1 -1
  17. package/dist/chat-store/index.js +34 -4
  18. package/dist/chat-store/index.js.map +1 -1
  19. package/dist/chat-store/schema.d.ts +286 -0
  20. package/dist/{chunk-6JEDSKFH.js → chunk-2SDX3OC4.js} +32 -24
  21. package/dist/{chunk-6JEDSKFH.js.map → chunk-2SDX3OC4.js.map} +1 -1
  22. package/dist/{chunk-QLZ6A73E.js → chunk-4CEIZZTH.js} +9 -9
  23. package/dist/{chunk-WL7PZK7Q.js → chunk-4PIN6QYQ.js} +43 -1
  24. package/dist/chunk-4PIN6QYQ.js.map +1 -0
  25. package/dist/{chunk-6UMIOEDR.js → chunk-AZRPDSRQ.js} +3 -3
  26. package/dist/{chunk-6LMM3OVX.js → chunk-BMCC2BUP.js} +3 -3
  27. package/dist/{chunk-36HSG7HU.js → chunk-CRZXEKCX.js} +2 -2
  28. package/dist/chunk-F4XBNR5L.js +16 -0
  29. package/dist/chunk-F4XBNR5L.js.map +1 -0
  30. package/dist/chunk-GY4IPYG4.js +40 -0
  31. package/dist/chunk-GY4IPYG4.js.map +1 -0
  32. package/dist/{chunk-6OG4244Y.js → chunk-MTKD2FN5.js} +2 -251
  33. package/dist/chunk-MTKD2FN5.js.map +1 -0
  34. package/dist/{chunk-5AUZR655.js → chunk-NDXQFEZQ.js} +51 -48
  35. package/dist/chunk-NDXQFEZQ.js.map +1 -0
  36. package/dist/chunk-NSWLZTJX.js +645 -0
  37. package/dist/chunk-NSWLZTJX.js.map +1 -0
  38. package/dist/chunk-PU6AWIRE.js +252 -0
  39. package/dist/chunk-PU6AWIRE.js.map +1 -0
  40. package/dist/{chunk-JKECSYDB.js → chunk-PV3GSLUY.js} +3 -3
  41. package/dist/{chunk-7Y7U7U7X.js → chunk-Q7RSHLEV.js} +5 -3
  42. package/dist/{chunk-7Y7U7U7X.js.map → chunk-Q7RSHLEV.js.map} +1 -1
  43. package/dist/{chunk-HRBF4B5L.js → chunk-TUJ4277Q.js} +1 -14
  44. package/dist/chunk-TUJ4277Q.js.map +1 -0
  45. package/dist/{chunk-57XPEL7X.js → chunk-V42C72V5.js} +25 -2
  46. package/dist/chunk-V42C72V5.js.map +1 -0
  47. package/dist/{chunk-FCYHDENJ.js → chunk-VOIVDEAV.js} +2 -2
  48. package/dist/{chunk-ACB7KOQ6.js → chunk-WSQSKYXP.js} +4 -4
  49. package/dist/{chunk-F6J5J4H6.js → chunk-WYQTPFPI.js} +26 -2
  50. package/dist/chunk-WYQTPFPI.js.map +1 -0
  51. package/dist/{chunk-PFTOGTHH.js → chunk-Z3IJ7XEW.js} +3 -3
  52. package/dist/{chunk-ZD2AUFIT.js → chunk-ZGGEYYEQ.js} +3 -3
  53. package/dist/{chunk-O5AUJQIA.js → chunk-ZNWJJRHP.js} +2 -2
  54. package/dist/design-canvas/index.js +1 -2
  55. package/dist/design-canvas/index.js.map +1 -1
  56. package/dist/design-canvas-react/engine.js +1 -2
  57. package/dist/design-canvas-react/index.js +2 -3
  58. package/dist/design-canvas-react/index.js.map +1 -1
  59. package/dist/design-canvas-react/lazy.js +1 -1
  60. package/dist/media/generate-request.d.ts +27 -1
  61. package/dist/media/index.js +36 -426
  62. package/dist/media/index.js.map +1 -1
  63. package/dist/media/router-generation.d.ts +7 -0
  64. package/dist/operator/gateway-keys.d.ts +44 -0
  65. package/dist/operator/index.d.ts +1 -0
  66. package/dist/operator/index.js +55 -1
  67. package/dist/operator/index.js.map +1 -1
  68. package/dist/plans/decision.d.ts +31 -0
  69. package/dist/plans/drizzle.js +1 -1
  70. package/dist/plans/index.js +5 -1
  71. package/dist/platform/billing.d.ts +3 -2
  72. package/dist/platform/deployment.d.ts +21 -0
  73. package/dist/platform/index.d.ts +1 -0
  74. package/dist/platform/index.js +30 -10
  75. package/dist/platform/index.js.map +1 -1
  76. package/dist/preset-cloudflare/index.js +9 -8
  77. package/dist/preset-cloudflare/index.js.map +1 -1
  78. package/dist/public-consultation/index.d.ts +1 -1
  79. package/dist/public-consultation/index.js +13 -12
  80. package/dist/public-consultation/index.js.map +1 -1
  81. package/dist/sandbox/computer-receipts.d.ts +1 -1
  82. package/dist/sandbox/index.d.ts +1 -0
  83. package/dist/sandbox/index.js +15 -8
  84. package/dist/sandbox/router-model-policy.d.ts +31 -0
  85. package/dist/sequences/index.js +1 -2
  86. package/dist/sequences/index.js.map +1 -1
  87. package/dist/spend/drizzle.d.ts +195 -0
  88. package/dist/spend/drizzle.js +22 -0
  89. package/dist/spend/drizzle.js.map +1 -1
  90. package/dist/stream/index.js +2 -2
  91. package/dist/studio/generated-media/flows.d.ts +240 -0
  92. package/dist/studio/generated-media/index.d.ts +3 -1
  93. package/dist/studio/generated-media/index.js +357 -138
  94. package/dist/studio/generated-media/index.js.map +1 -1
  95. package/dist/studio/index.js +18 -16
  96. package/dist/studio-react/index.js +28 -26
  97. package/dist/studio-react/index.js.map +1 -1
  98. package/dist/teams/index.d.ts +1 -0
  99. package/dist/teams/index.js +16 -0
  100. package/dist/teams/index.js.map +1 -1
  101. package/dist/teams/invitations-api.js +1 -1
  102. package/dist/teams/members-api.d.ts +5 -3
  103. package/dist/teams/members-api.js +1 -1
  104. package/dist/teams/thread-access.d.ts +22 -0
  105. package/dist/tools/index.js +5 -4
  106. package/dist/web/index.js +4 -6
  107. package/dist/web-react/index.js +4 -4
  108. package/dist/work-product/index.js +3 -2
  109. package/dist/work-product/index.js.map +1 -1
  110. package/dist/workspace-export/d1.d.ts +1 -1
  111. package/dist/workspace-export/index.js +9 -2
  112. package/dist/workspace-export/index.js.map +1 -1
  113. package/package.json +1 -1
  114. package/dist/chunk-57XPEL7X.js.map +0 -1
  115. package/dist/chunk-5AUZR655.js.map +0 -1
  116. package/dist/chunk-6OG4244Y.js.map +0 -1
  117. package/dist/chunk-6Z7TZVKZ.js +0 -26
  118. package/dist/chunk-6Z7TZVKZ.js.map +0 -1
  119. package/dist/chunk-F6J5J4H6.js.map +0 -1
  120. package/dist/chunk-HRBF4B5L.js.map +0 -1
  121. package/dist/chunk-WL7PZK7Q.js.map +0 -1
  122. /package/dist/{DesignCanvas-3DGZQOD7.js.map → DesignCanvas-VKZ7Y3JU.js.map} +0 -0
  123. /package/dist/{DesignCanvasEditor-OG4QY5WJ.js.map → DesignCanvasEditor-3V53YLLZ.js.map} +0 -0
  124. /package/dist/{chunk-QLZ6A73E.js.map → chunk-4CEIZZTH.js.map} +0 -0
  125. /package/dist/{chunk-6UMIOEDR.js.map → chunk-AZRPDSRQ.js.map} +0 -0
  126. /package/dist/{chunk-6LMM3OVX.js.map → chunk-BMCC2BUP.js.map} +0 -0
  127. /package/dist/{chunk-36HSG7HU.js.map → chunk-CRZXEKCX.js.map} +0 -0
  128. /package/dist/{chunk-JKECSYDB.js.map → chunk-PV3GSLUY.js.map} +0 -0
  129. /package/dist/{chunk-FCYHDENJ.js.map → chunk-VOIVDEAV.js.map} +0 -0
  130. /package/dist/{chunk-ACB7KOQ6.js.map → chunk-WSQSKYXP.js.map} +0 -0
  131. /package/dist/{chunk-PFTOGTHH.js.map → chunk-Z3IJ7XEW.js.map} +0 -0
  132. /package/dist/{chunk-ZD2AUFIT.js.map → chunk-ZGGEYYEQ.js.map} +0 -0
  133. /package/dist/{chunk-O5AUJQIA.js.map → chunk-ZNWJJRHP.js.map} +0 -0
@@ -1,346 +1,31 @@
1
1
  import {
2
- withTimeout
3
- } from "../chunk-6Z7TZVKZ.js";
2
+ RouterHttpError,
3
+ browserUsableSourceUrl,
4
+ checkGenerateRequest,
5
+ createRouterGeneration,
6
+ createRouterMediaClient,
7
+ fetchBoundedAudio,
8
+ generationMetadata,
9
+ imageCountForRequest,
10
+ metadataResultUrl,
11
+ modelForRequest,
12
+ normalizeProviderJobStatus,
13
+ optionalHttpsUrl,
14
+ providerImageBytes,
15
+ requiredText,
16
+ routerResponseErrorMessage,
17
+ routerV1Url,
18
+ tcloudWebhookCallbackUrl,
19
+ validProviderImages,
20
+ validateGenerateRequest,
21
+ validatePublicHttpUrl
22
+ } from "../chunk-NSWLZTJX.js";
23
+ import "../chunk-MTKD2FN5.js";
4
24
  import {
5
- isBlockedFetchHostname
6
- } from "../chunk-57XPEL7X.js";
7
-
8
- // src/media/router-client.ts
9
- var RouterHttpError = class extends Error {
10
- status;
11
- code;
12
- constructor(status, message, code) {
13
- super(message);
14
- this.name = "RouterHttpError";
15
- this.status = status;
16
- this.code = code;
17
- }
18
- };
19
- var NOT_CONFIGURED = "Media generation is not configured for this deployment.";
20
- function routerV1Url(value) {
21
- return `${routerRootUrl(value)}/v1`;
22
- }
23
- async function routerResponseError(response) {
24
- const text3 = await response.text();
25
- if (!text3) return { message: response.statusText };
26
- try {
27
- const json = JSON.parse(text3);
28
- if (typeof json.error === "string") return { message: json.error };
29
- const code = typeof json.error?.code === "string" ? json.error.code : void 0;
30
- if (typeof json.error?.message === "string") return { message: json.error.message, code };
31
- if (typeof json.message === "string") return { message: json.message, code };
32
- } catch {
33
- return { message: text3.slice(0, 500) };
34
- }
35
- return { message: text3.slice(0, 500) };
36
- }
37
- async function routerResponseErrorMessage(response) {
38
- return (await routerResponseError(response)).message;
39
- }
40
- function createRouterMediaClient(config) {
41
- const wrap = (headers) => config.headers?.(headers) ?? headers;
42
- function requiredRouterApiKey(value) {
43
- const apiKey = text(value ?? config.defaultApiKey?.());
44
- if (!apiKey) throw new Error(NOT_CONFIGURED);
45
- return apiKey;
46
- }
47
- function routerMediaUrl(path) {
48
- return `${routerV1Url(config.baseUrl())}${path}`;
49
- }
50
- function routerHeaders(apiKey, extra = {}) {
51
- return wrap({ Authorization: `Bearer ${requiredRouterApiKey(apiKey)}`, ...extra });
52
- }
53
- async function routerJson(path, body, signal, apiKey) {
54
- const response = await fetch(routerMediaUrl(path), {
55
- method: "POST",
56
- headers: routerHeaders(apiKey, { "Content-Type": "application/json" }),
57
- body: JSON.stringify(pruneUndefined(body)),
58
- signal
59
- });
60
- if (!response.ok) {
61
- const { message, code } = await routerResponseError(response);
62
- throw new RouterHttpError(response.status, `Router media request failed: ${response.status} ${message}`, code);
63
- }
64
- return await response.json();
65
- }
66
- async function routerMediaStatus(id, signal, apiKey) {
67
- const response = await fetch(routerMediaUrl(`/videos/${encodeURIComponent(id)}`), {
68
- headers: routerHeaders(apiKey),
69
- signal
70
- });
71
- if (!response.ok) {
72
- throw new Error(`Router media poll failed: ${response.status} ${await routerResponseErrorMessage(response)}`);
73
- }
74
- return await response.json();
75
- }
76
- function resolveRouterMediaSource(value, apiKey) {
77
- if (!value.startsWith("/") || value.startsWith("//")) return { url: value };
78
- return {
79
- url: `${routerRootUrl(config.baseUrl())}${value}`,
80
- authorization: `Bearer ${requiredRouterApiKey(apiKey)}`
81
- };
82
- }
83
- function validateRouterMediaSourceUrl(value) {
84
- const expected = new URL(routerRootUrl(config.baseUrl())).origin;
85
- const url = new URL(value);
86
- if (url.origin !== expected) {
87
- throw new Error(`Authorized media fetch must target the router origin ${expected}`);
88
- }
89
- return url.toString();
90
- }
91
- return {
92
- requiredRouterApiKey,
93
- routerMediaUrl,
94
- routerHeaders,
95
- routerJson,
96
- routerMediaStatus,
97
- resolveRouterMediaSource,
98
- validateRouterMediaSourceUrl
99
- };
100
- }
101
- function routerRootUrl(value) {
102
- return value.replace(/\/+$/, "").replace(/\/v1$/, "");
103
- }
104
- function pruneUndefined(value) {
105
- return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0));
106
- }
107
- function text(value) {
108
- return typeof value === "string" && value.trim() ? value.trim() : void 0;
109
- }
110
-
111
- // src/media/router-generation.ts
112
- var MAX_TRANSCRIPTION_BYTES = 25 * 1024 * 1024;
113
- var SUPPORTED_TRANSCRIPTION_FORMATS = /* @__PURE__ */ new Set(["wav", "mp3", "flac", "m4a", "ogg", "webm", "aac"]);
114
- function validatePublicHttpUrl(value, field) {
115
- let url;
116
- try {
117
- url = new URL(value);
118
- } catch {
119
- throw new Error(`${field} must be a valid public URL`);
120
- }
121
- if (url.protocol !== "https:" && url.protocol !== "http:") {
122
- throw new Error(`${field} must use http or https`);
123
- }
124
- if (isBlockedFetchHostname(url.hostname)) {
125
- throw new Error(`${field} must be a public URL`);
126
- }
127
- return url.toString();
128
- }
129
- async function fetchBoundedAudio(url, options = {}) {
130
- const safeUrl = validatePublicHttpUrl(url, "audioUrl");
131
- const response = await fetch(safeUrl, { signal: options.signal, redirect: "manual" });
132
- if (response.status >= 300 && response.status < 400) {
133
- throw new Error("Audio URL redirects are not allowed");
134
- }
135
- if (!response.ok) {
136
- throw new Error(`Audio fetch failed with ${response.status}`);
137
- }
138
- const contentLength = Number(response.headers.get("content-length") ?? "0");
139
- if (contentLength > MAX_TRANSCRIPTION_BYTES) {
140
- throw new Error("Audio file is too large");
141
- }
142
- const contentType = response.headers.get("content-type") ?? "application/octet-stream";
143
- if (!contentType.startsWith("audio/") && contentType !== "application/octet-stream") {
144
- throw new Error("Transcription URL must return audio");
145
- }
146
- const blob = await response.blob();
147
- if (blob.size === 0) throw new Error("Transcription audio URL returned an empty file");
148
- if (blob.size > MAX_TRANSCRIPTION_BYTES) {
149
- throw new Error("Audio file is too large");
150
- }
151
- return blob;
152
- }
153
- function createRouterGeneration(client) {
154
- async function generateVideoViaRouter({ model, prompt, duration, resolution, aspectRatio, referenceImageUrl, callbackUrl }, signal, apiKey) {
155
- return await client.routerJson(
156
- "/videos/generate",
157
- {
158
- model,
159
- prompt,
160
- duration,
161
- resolution,
162
- aspect_ratio: aspectRatio,
163
- image_url: referenceImageUrl,
164
- callback_url: callbackUrl
165
- },
166
- signal,
167
- apiKey
168
- );
169
- }
170
- async function generateAvatarViaRouter(body, signal, apiKey) {
171
- return await client.routerJson("/videos/avatar", { ...body }, signal, apiKey);
172
- }
173
- async function transcribeViaRouter({
174
- audioBlob,
175
- audioUrl,
176
- model,
177
- language,
178
- prompt,
179
- responseFormat,
180
- temperature,
181
- signal,
182
- apiKey
183
- }) {
184
- const format = transcriptionAudioFormat(audioUrl, audioBlob.type);
185
- const responseFormatText = typeof responseFormat === "string" && responseFormat.trim() ? responseFormat.trim() : null;
186
- const audioData = bytesToBase64(new Uint8Array(await audioBlob.arrayBuffer()));
187
- const response = await fetch(client.routerMediaUrl("/audio/transcriptions"), {
188
- method: "POST",
189
- headers: client.routerHeaders(apiKey, { "Content-Type": "application/json" }),
190
- body: JSON.stringify({
191
- model,
192
- input_audio: { data: audioData, format },
193
- language,
194
- prompt,
195
- response_format: responseFormat,
196
- temperature
197
- }),
198
- signal
199
- });
200
- if (!response.ok) {
201
- throw new Error(`Transcription provider failed: ${response.status} ${await routerResponseErrorMessage(response)}`);
202
- }
203
- if (isRawTranscriptionResponseFormat(responseFormatText)) {
204
- return { text: await response.text() };
205
- }
206
- return await response.json();
207
- }
208
- return { generateVideoViaRouter, generateAvatarViaRouter, transcribeViaRouter };
209
- }
210
- function isRawTranscriptionResponseFormat(value) {
211
- const format = value?.toLowerCase();
212
- return format === "text" || format === "srt" || format === "vtt";
213
- }
214
- function transcriptionAudioFormat(audioUrl, contentType) {
215
- const fromType = contentTypeToAudioFormat(contentType);
216
- if (fromType) return fromType;
217
- const ext = new URL(audioUrl).pathname.split(".").pop()?.toLowerCase();
218
- if (ext && SUPPORTED_TRANSCRIPTION_FORMATS.has(ext)) return ext;
219
- throw new Error("Transcription audio must be wav, mp3, flac, m4a, ogg, webm, or aac");
220
- }
221
- function contentTypeToAudioFormat(contentType) {
222
- const type = contentType.toLowerCase().split(";")[0]?.trim();
223
- if (type === "audio/wav" || type === "audio/x-wav") return "wav";
224
- if (type === "audio/mpeg" || type === "audio/mp3") return "mp3";
225
- if (type === "audio/flac") return "flac";
226
- if (type === "audio/mp4" || type === "audio/x-m4a") return "m4a";
227
- if (type === "audio/ogg" || type === "application/ogg") return "ogg";
228
- if (type === "audio/webm" || type === "video/webm") return "webm";
229
- if (type === "audio/aac") return "aac";
230
- return null;
231
- }
232
- function bytesToBase64(bytes) {
233
- let binary = "";
234
- for (let i = 0; i < bytes.length; i += 8192) {
235
- binary += String.fromCharCode(...bytes.subarray(i, i + 8192));
236
- }
237
- return btoa(binary);
238
- }
239
-
240
- // src/media/generate-request.ts
241
- var MIN_IMAGE_COUNT = 1;
242
- var MAX_IMAGE_COUNT = 4;
243
- function requiredText(value) {
244
- return typeof value === "string" && value.trim() ? value.trim() : null;
245
- }
246
- function validateGenerateRequest(type, body, prompt) {
247
- if (type !== "transcription" && type !== "avatar" && !prompt) {
248
- return { succeeded: false, error: "prompt is required" };
249
- }
250
- if (type === "avatar") {
251
- const audioUrl = requiredHttpsUrl(body.audioUrl, "audioUrl");
252
- if (!audioUrl.succeeded) return audioUrl;
253
- const imageUrl = optionalHttpsUrl(body.imageUrl, "imageUrl");
254
- if (!imageUrl.succeeded) return imageUrl;
255
- return {
256
- succeeded: true,
257
- value: {
258
- promptLabel: prompt || audioUrl.value,
259
- audioUrl: audioUrl.value,
260
- imageUrl: imageUrl.value,
261
- avatarId: body.avatarId?.trim() || void 0
262
- }
263
- };
264
- }
265
- if (type === "transcription") {
266
- const audioUrl = requiredHttpsUrl(body.audioUrl, "audioUrl");
267
- if (!audioUrl.succeeded) return audioUrl;
268
- return {
269
- succeeded: true,
270
- value: {
271
- promptLabel: prompt || audioUrl.value,
272
- audioUrl: audioUrl.value,
273
- language: body.language?.trim() || void 0,
274
- responseFormat: body.responseFormat?.trim() || void 0,
275
- temperature: numberValue(body.temperature)
276
- }
277
- };
278
- }
279
- if (type === "video") {
280
- const referenceImageUrl = optionalHttpsUrl(body.referenceImageUrl, "referenceImageUrl");
281
- if (!referenceImageUrl.succeeded) return referenceImageUrl;
282
- return {
283
- succeeded: true,
284
- value: {
285
- promptLabel: prompt,
286
- duration: body.duration,
287
- resolution: body.resolution,
288
- aspectRatio: body.aspectRatio?.trim() || void 0,
289
- referenceImageUrl: referenceImageUrl.value
290
- }
291
- };
292
- }
293
- return {
294
- succeeded: true,
295
- value: {
296
- promptLabel: prompt,
297
- size: body.size,
298
- quality: body.quality,
299
- n: body.n,
300
- duration: body.duration,
301
- resolution: body.resolution,
302
- voice: body.voice
303
- }
304
- };
305
- }
306
- function imageCountForRequest(value) {
307
- if (value == null) return { succeeded: true, value: 1 };
308
- const count = typeof value === "number" ? value : Number.NaN;
309
- if (!Number.isInteger(count) || count < MIN_IMAGE_COUNT || count > MAX_IMAGE_COUNT) {
310
- return { succeeded: false, error: `Images must be an integer between ${MIN_IMAGE_COUNT} and ${MAX_IMAGE_COUNT}` };
311
- }
312
- return { succeeded: true, value: count };
313
- }
314
- function modelForRequest(type, body, defaults) {
315
- return body.model?.trim() || defaults[type];
316
- }
317
- function requiredHttpsUrl(value, field) {
318
- const text3 = requiredText(value);
319
- if (!text3) return { succeeded: false, error: `${field} is required` };
320
- return validateExternalHttpsUrl(text3, field);
321
- }
322
- function optionalHttpsUrl(value, field) {
323
- const text3 = requiredText(value);
324
- if (!text3) return { succeeded: true, value: void 0 };
325
- return validateExternalHttpsUrl(text3, field);
326
- }
327
- function validateExternalHttpsUrl(value, field) {
328
- try {
329
- const url = new URL(value);
330
- if (url.protocol !== "https:") {
331
- return { succeeded: false, error: `${field} must be an https URL` };
332
- }
333
- if (isBlockedFetchHostname(url.hostname)) {
334
- return { succeeded: false, error: `${field} must not point to localhost or a private network address` };
335
- }
336
- return { succeeded: true, value };
337
- } catch {
338
- return { succeeded: false, error: `${field} must be a valid URL` };
339
- }
340
- }
341
- function numberValue(value) {
342
- return typeof value === "number" && Number.isFinite(value) ? value : void 0;
343
- }
25
+ withTimeout
26
+ } from "../chunk-V42C72V5.js";
27
+ import "../chunk-FRAICFTZ.js";
28
+ import "../chunk-TXD5HXLE.js";
344
29
 
345
30
  // src/media/speech-script.ts
346
31
  var DEFAULT_TIMEOUT_MS = 2e4;
@@ -391,18 +76,18 @@ function exactSpeechInput(prompt) {
391
76
  ];
392
77
  for (const pattern of patterns) {
393
78
  const match = prompt.match(pattern);
394
- const text3 = normalizeSpeechScript(match?.[1] ?? "");
395
- if (text3) return text3;
79
+ const text = normalizeSpeechScript(match?.[1] ?? "");
80
+ if (text) return text;
396
81
  }
397
82
  return null;
398
83
  }
399
84
  function normalizeSpeechScript(value) {
400
- let text3 = value.trim();
401
- text3 = text3.replace(/^```(?:text)?\s*/i, "").replace(/\s*```$/i, "").trim();
402
- text3 = text3.replace(/^(?:script|voiceover|spoken words)\s*:\s*/i, "").trim();
403
- const quoted = text3.match(/^["'“”‘’]([\s\S]+)["'“”‘’]$/);
404
- if (quoted?.[1]) text3 = quoted[1].trim();
405
- return text3;
85
+ let text = value.trim();
86
+ text = text.replace(/^```(?:text)?\s*/i, "").replace(/\s*```$/i, "").trim();
87
+ text = text.replace(/^(?:script|voiceover|spoken words)\s*:\s*/i, "").trim();
88
+ const quoted = text.match(/^["'“”‘’]([\s\S]+)["'“”‘’]$/);
89
+ if (quoted?.[1]) text = quoted[1].trim();
90
+ return text;
406
91
  }
407
92
  function estimateTextTokens(value) {
408
93
  return Math.ceil(value.trim().length / 4);
@@ -411,83 +96,6 @@ function roundUsd(value) {
411
96
  return Math.round(value * 1e6) / 1e6;
412
97
  }
413
98
 
414
- // src/media/generation-record.ts
415
- function metadataResultUrl(value) {
416
- if (!value || value.startsWith("data:")) return void 0;
417
- return value;
418
- }
419
- function generationMetadata({
420
- status,
421
- provider,
422
- negativePrompt,
423
- publishPackage,
424
- resultUrl,
425
- providerResultUrl,
426
- ...fields
427
- }) {
428
- return {
429
- generationStatus: status,
430
- provider,
431
- negativePrompt: negativePrompt || void 0,
432
- ...publishPackage ? { publishPackage } : {},
433
- ...fields,
434
- resultUrl: metadataResultUrl(resultUrl),
435
- providerResultUrl: metadataResultUrl(providerResultUrl)
436
- };
437
- }
438
- function browserUsableSourceUrl(source) {
439
- if (!source || source.authorization) return null;
440
- return source.url;
441
- }
442
- function normalizeProviderJobStatus(value) {
443
- const record = recordValue(value);
444
- const rawStatus = text2(record.status) ?? "running";
445
- const resultUrl = [record, recordValue(record.result), recordValue(record.output)].map((source) => text2(source.video_url) ?? text2(source.url) ?? text2(source.result_url) ?? text2(source.output_url)).find(Boolean);
446
- const error = text2(record.error) ?? text2(record.message);
447
- const lower = rawStatus.toLowerCase();
448
- if (lower === "failed" || lower === "error" || lower === "cancelled") {
449
- return { status: "failed", providerStatus: rawStatus, error: error ?? `Provider job ${rawStatus}` };
450
- }
451
- if (lower === "completed" || lower === "complete" || lower === "succeeded" || lower === "success") {
452
- if (!resultUrl) {
453
- return { status: "failed", providerStatus: rawStatus, error: "Provider job completed without a result URL" };
454
- }
455
- return { status: "succeeded", providerStatus: rawStatus, resultUrl };
456
- }
457
- if (resultUrl) return { status: "succeeded", providerStatus: rawStatus, resultUrl };
458
- return { status: "running", providerStatus: rawStatus };
459
- }
460
- function validProviderImages(value) {
461
- if (!Array.isArray(value)) return [];
462
- return value.filter((image) => Boolean(requiredText(image.url) || requiredText(image.b64_json)));
463
- }
464
- function providerImageBytes(url, b64Json) {
465
- const cleanUrl = requiredText(url);
466
- return cleanUrl?.startsWith("data:") ? imageBytesFromDataUri(cleanUrl) : imageBytesFromBase64(requiredText(b64Json));
467
- }
468
- function imageBytesFromDataUri(value) {
469
- const match = /^data:([^;,]+);base64,(.+)$/s.exec(value);
470
- if (!match) throw new Error("Image provider returned an unsupported data URI");
471
- return imageBytesFromBase64(match[2] ?? null, match[1]);
472
- }
473
- function imageBytesFromBase64(value, mimeType = "image/png") {
474
- if (!value) return null;
475
- try {
476
- const binary = atob(value);
477
- const bytes = new Uint8Array(binary.length);
478
- for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
479
- return { bytes, mimeType };
480
- } catch {
481
- throw new Error("Image provider returned invalid image bytes");
482
- }
483
- }
484
- function recordValue(value) {
485
- return value && typeof value === "object" && !Array.isArray(value) ? value : {};
486
- }
487
- function text2(value) {
488
- return typeof value === "string" && value.trim() ? value.trim() : void 0;
489
- }
490
-
491
99
  // src/media/model-catalog.ts
492
100
  var DEFAULT_CACHE_TTL_MS = 3e5;
493
101
  var ENDPOINT_BY_TYPE = {
@@ -630,6 +238,7 @@ function stringValue(value) {
630
238
  export {
631
239
  RouterHttpError,
632
240
  browserUsableSourceUrl,
241
+ checkGenerateRequest,
633
242
  checkMediaModelSelection,
634
243
  createMediaModelCatalog,
635
244
  createRouterGeneration,
@@ -646,6 +255,7 @@ export {
646
255
  requiredText,
647
256
  routerResponseErrorMessage,
648
257
  routerV1Url,
258
+ tcloudWebhookCallbackUrl,
649
259
  validProviderImages,
650
260
  validateGenerateRequest,
651
261
  validatePublicHttpUrl