@tangle-network/agent-app 0.63.30 → 0.63.32
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/dist/{DesignCanvas-3DGZQOD7.js → DesignCanvas-VKZ7Y3JU.js} +2 -3
- package/dist/{DesignCanvasEditor-OG4QY5WJ.js → DesignCanvasEditor-3V53YLLZ.js} +2 -3
- package/dist/agent-profiles/d1.js +4 -3
- package/dist/agent-profiles/d1.js.map +1 -1
- package/dist/agent-profiles/index.js +4 -3
- package/dist/alerting/github.d.ts +33 -0
- package/dist/alerting/index.d.ts +1 -0
- package/dist/alerting/index.js +47 -0
- package/dist/alerting/index.js.map +1 -1
- package/dist/app-auth/index.js +1 -2
- package/dist/app-auth/index.js.map +1 -1
- package/dist/assistant/index.js +4 -4
- package/dist/billing/index.d.ts +15 -0
- package/dist/billing/index.js +5 -3
- package/dist/chat-routes/index.js +15 -14
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-store/index.js +34 -4
- package/dist/chat-store/index.js.map +1 -1
- package/dist/chat-store/schema.d.ts +286 -0
- package/dist/{chunk-6JEDSKFH.js → chunk-2SDX3OC4.js} +32 -24
- package/dist/{chunk-6JEDSKFH.js.map → chunk-2SDX3OC4.js.map} +1 -1
- package/dist/{chunk-QLZ6A73E.js → chunk-4CEIZZTH.js} +9 -9
- package/dist/{chunk-WL7PZK7Q.js → chunk-4PIN6QYQ.js} +43 -1
- package/dist/chunk-4PIN6QYQ.js.map +1 -0
- package/dist/{chunk-6UMIOEDR.js → chunk-AZRPDSRQ.js} +3 -3
- package/dist/{chunk-6LMM3OVX.js → chunk-BMCC2BUP.js} +3 -3
- package/dist/{chunk-36HSG7HU.js → chunk-CRZXEKCX.js} +2 -2
- package/dist/chunk-F4XBNR5L.js +16 -0
- package/dist/chunk-F4XBNR5L.js.map +1 -0
- package/dist/chunk-GY4IPYG4.js +40 -0
- package/dist/chunk-GY4IPYG4.js.map +1 -0
- package/dist/{chunk-6OG4244Y.js → chunk-MTKD2FN5.js} +2 -251
- package/dist/chunk-MTKD2FN5.js.map +1 -0
- package/dist/{chunk-5AUZR655.js → chunk-NDXQFEZQ.js} +51 -48
- package/dist/chunk-NDXQFEZQ.js.map +1 -0
- package/dist/chunk-NSWLZTJX.js +645 -0
- package/dist/chunk-NSWLZTJX.js.map +1 -0
- package/dist/chunk-PU6AWIRE.js +252 -0
- package/dist/chunk-PU6AWIRE.js.map +1 -0
- package/dist/{chunk-JKECSYDB.js → chunk-PV3GSLUY.js} +3 -3
- package/dist/{chunk-7Y7U7U7X.js → chunk-Q7RSHLEV.js} +5 -3
- package/dist/{chunk-7Y7U7U7X.js.map → chunk-Q7RSHLEV.js.map} +1 -1
- package/dist/{chunk-HRBF4B5L.js → chunk-TUJ4277Q.js} +1 -14
- package/dist/chunk-TUJ4277Q.js.map +1 -0
- package/dist/{chunk-57XPEL7X.js → chunk-V42C72V5.js} +25 -2
- package/dist/chunk-V42C72V5.js.map +1 -0
- package/dist/{chunk-FCYHDENJ.js → chunk-VOIVDEAV.js} +2 -2
- package/dist/{chunk-ACB7KOQ6.js → chunk-WSQSKYXP.js} +4 -4
- package/dist/{chunk-F6J5J4H6.js → chunk-WYQTPFPI.js} +26 -2
- package/dist/chunk-WYQTPFPI.js.map +1 -0
- package/dist/{chunk-PFTOGTHH.js → chunk-Z3IJ7XEW.js} +3 -3
- package/dist/{chunk-ZD2AUFIT.js → chunk-ZGGEYYEQ.js} +3 -3
- package/dist/{chunk-O5AUJQIA.js → chunk-ZNWJJRHP.js} +2 -2
- package/dist/design-canvas/index.js +1 -2
- package/dist/design-canvas/index.js.map +1 -1
- package/dist/design-canvas-react/engine.js +1 -2
- package/dist/design-canvas-react/index.js +2 -3
- package/dist/design-canvas-react/index.js.map +1 -1
- package/dist/design-canvas-react/lazy.js +1 -1
- package/dist/media/generate-request.d.ts +27 -1
- package/dist/media/index.js +36 -426
- package/dist/media/index.js.map +1 -1
- package/dist/media/router-generation.d.ts +7 -0
- package/dist/operator/gateway-keys.d.ts +44 -0
- package/dist/operator/index.d.ts +1 -0
- package/dist/operator/index.js +55 -1
- package/dist/operator/index.js.map +1 -1
- package/dist/plans/decision.d.ts +31 -0
- package/dist/plans/drizzle.js +1 -1
- package/dist/plans/index.js +5 -1
- package/dist/platform/billing.d.ts +3 -2
- package/dist/platform/deployment.d.ts +21 -0
- package/dist/platform/index.d.ts +1 -0
- package/dist/platform/index.js +30 -10
- package/dist/platform/index.js.map +1 -1
- package/dist/preset-cloudflare/index.js +9 -8
- package/dist/preset-cloudflare/index.js.map +1 -1
- package/dist/public-consultation/index.d.ts +1 -1
- package/dist/public-consultation/index.js +13 -12
- package/dist/public-consultation/index.js.map +1 -1
- package/dist/sandbox/computer-receipts.d.ts +1 -1
- package/dist/sandbox/index.d.ts +1 -0
- package/dist/sandbox/index.js +15 -8
- package/dist/sandbox/router-model-policy.d.ts +31 -0
- package/dist/sequences/index.js +1 -2
- package/dist/sequences/index.js.map +1 -1
- package/dist/spend/drizzle.d.ts +195 -0
- package/dist/spend/drizzle.js +22 -0
- package/dist/spend/drizzle.js.map +1 -1
- package/dist/stream/index.js +2 -2
- package/dist/studio/generated-media/flows.d.ts +240 -0
- package/dist/studio/generated-media/index.d.ts +3 -1
- package/dist/studio/generated-media/index.js +357 -138
- package/dist/studio/generated-media/index.js.map +1 -1
- package/dist/studio/index.js +18 -16
- package/dist/studio-react/index.js +28 -26
- package/dist/studio-react/index.js.map +1 -1
- package/dist/teams/index.d.ts +1 -0
- package/dist/teams/index.js +16 -0
- package/dist/teams/index.js.map +1 -1
- package/dist/teams/invitations-api.js +1 -1
- package/dist/teams/members-api.d.ts +5 -3
- package/dist/teams/members-api.js +1 -1
- package/dist/teams/thread-access.d.ts +22 -0
- package/dist/tools/index.js +5 -4
- package/dist/web/index.js +4 -6
- package/dist/web-react/index.js +4 -4
- package/dist/work-product/index.js +3 -2
- package/dist/work-product/index.js.map +1 -1
- package/dist/workspace-export/d1.d.ts +1 -1
- package/dist/workspace-export/index.js +9 -2
- package/dist/workspace-export/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-57XPEL7X.js.map +0 -1
- package/dist/chunk-5AUZR655.js.map +0 -1
- package/dist/chunk-6OG4244Y.js.map +0 -1
- package/dist/chunk-6Z7TZVKZ.js +0 -26
- package/dist/chunk-6Z7TZVKZ.js.map +0 -1
- package/dist/chunk-F6J5J4H6.js.map +0 -1
- package/dist/chunk-HRBF4B5L.js.map +0 -1
- package/dist/chunk-WL7PZK7Q.js.map +0 -1
- /package/dist/{DesignCanvas-3DGZQOD7.js.map → DesignCanvas-VKZ7Y3JU.js.map} +0 -0
- /package/dist/{DesignCanvasEditor-OG4QY5WJ.js.map → DesignCanvasEditor-3V53YLLZ.js.map} +0 -0
- /package/dist/{chunk-QLZ6A73E.js.map → chunk-4CEIZZTH.js.map} +0 -0
- /package/dist/{chunk-6UMIOEDR.js.map → chunk-AZRPDSRQ.js.map} +0 -0
- /package/dist/{chunk-6LMM3OVX.js.map → chunk-BMCC2BUP.js.map} +0 -0
- /package/dist/{chunk-36HSG7HU.js.map → chunk-CRZXEKCX.js.map} +0 -0
- /package/dist/{chunk-JKECSYDB.js.map → chunk-PV3GSLUY.js.map} +0 -0
- /package/dist/{chunk-FCYHDENJ.js.map → chunk-VOIVDEAV.js.map} +0 -0
- /package/dist/{chunk-ACB7KOQ6.js.map → chunk-WSQSKYXP.js.map} +0 -0
- /package/dist/{chunk-PFTOGTHH.js.map → chunk-Z3IJ7XEW.js.map} +0 -0
- /package/dist/{chunk-ZD2AUFIT.js.map → chunk-ZGGEYYEQ.js.map} +0 -0
- /package/dist/{chunk-O5AUJQIA.js.map → chunk-ZNWJJRHP.js.map} +0 -0
|
@@ -1,145 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ToolInputError
|
|
3
|
+
} from "../../chunk-F4XBNR5L.js";
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_GENERATED_OUTPUT_PATHS,
|
|
6
|
+
GENERATED_OUTPUT_CONFIG,
|
|
7
|
+
browserUsableSourceUrl,
|
|
8
|
+
extensionForGeneratedMimeType,
|
|
9
|
+
fetchBoundedAudio,
|
|
10
|
+
generatedExtensionFromUrl,
|
|
11
|
+
generatedMediaLabel,
|
|
12
|
+
generatedMimeTypeFromUrl,
|
|
13
|
+
isGeneratedMediaType,
|
|
14
|
+
metadataResultUrl,
|
|
15
|
+
normalizeGeneratedOutputPath,
|
|
16
|
+
normalizeProviderJobStatus,
|
|
17
|
+
providerImageBytes,
|
|
18
|
+
requiredText,
|
|
19
|
+
resolveGeneratedVaultPath,
|
|
20
|
+
validateGeneratedMediaSourceUrl
|
|
21
|
+
} from "../../chunk-NSWLZTJX.js";
|
|
22
|
+
import "../../chunk-MTKD2FN5.js";
|
|
23
|
+
import {
|
|
24
|
+
withTimeout
|
|
25
|
+
} from "../../chunk-V42C72V5.js";
|
|
1
26
|
import {
|
|
2
27
|
validateVaultFilePath
|
|
3
28
|
} from "../../chunk-FRAICFTZ.js";
|
|
4
29
|
import "../../chunk-TXD5HXLE.js";
|
|
5
|
-
import {
|
|
6
|
-
isBlockedFetchHostname
|
|
7
|
-
} from "../../chunk-57XPEL7X.js";
|
|
8
|
-
|
|
9
|
-
// src/studio/generated-media/output.ts
|
|
10
|
-
var DEFAULT_GENERATED_OUTPUT_PATHS = {
|
|
11
|
-
image: "generated/images",
|
|
12
|
-
video: "generated/videos",
|
|
13
|
-
avatar: "generated/avatars",
|
|
14
|
-
speech: "generated/audio",
|
|
15
|
-
transcription: "generated/transcripts"
|
|
16
|
-
};
|
|
17
|
-
var GENERATED_OUTPUT_CONFIG = {
|
|
18
|
-
image: {
|
|
19
|
-
defaultPath: DEFAULT_GENERATED_OUTPUT_PATHS.image,
|
|
20
|
-
extensions: /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp", ".gif", ".avif"]),
|
|
21
|
-
defaultExtension: ".png",
|
|
22
|
-
defaultMimeType: "image/png",
|
|
23
|
-
frontmatterType: "generated-image",
|
|
24
|
-
title: "Studio generated image"
|
|
25
|
-
},
|
|
26
|
-
video: {
|
|
27
|
-
defaultPath: DEFAULT_GENERATED_OUTPUT_PATHS.video,
|
|
28
|
-
extensions: /* @__PURE__ */ new Set([".mp4", ".mov", ".m4v", ".webm"]),
|
|
29
|
-
defaultExtension: ".mp4",
|
|
30
|
-
defaultMimeType: "video/mp4",
|
|
31
|
-
frontmatterType: "generated-video",
|
|
32
|
-
title: "Studio generated video"
|
|
33
|
-
},
|
|
34
|
-
avatar: {
|
|
35
|
-
defaultPath: DEFAULT_GENERATED_OUTPUT_PATHS.avatar,
|
|
36
|
-
extensions: /* @__PURE__ */ new Set([".mp4", ".mov", ".m4v", ".webm"]),
|
|
37
|
-
defaultExtension: ".mp4",
|
|
38
|
-
defaultMimeType: "video/mp4",
|
|
39
|
-
frontmatterType: "generated-avatar",
|
|
40
|
-
title: "Studio generated avatar"
|
|
41
|
-
},
|
|
42
|
-
speech: {
|
|
43
|
-
defaultPath: DEFAULT_GENERATED_OUTPUT_PATHS.speech,
|
|
44
|
-
extensions: /* @__PURE__ */ new Set([".mp3", ".wav", ".m4a", ".ogg", ".webm", ".aac"]),
|
|
45
|
-
defaultExtension: ".mp3",
|
|
46
|
-
defaultMimeType: "audio/mpeg",
|
|
47
|
-
frontmatterType: "generated-audio",
|
|
48
|
-
title: "Studio generated audio"
|
|
49
|
-
},
|
|
50
|
-
transcription: {
|
|
51
|
-
defaultPath: DEFAULT_GENERATED_OUTPUT_PATHS.transcription,
|
|
52
|
-
extensions: /* @__PURE__ */ new Set([".md"]),
|
|
53
|
-
defaultExtension: ".md",
|
|
54
|
-
defaultMimeType: "text/markdown",
|
|
55
|
-
frontmatterType: "generated-transcript",
|
|
56
|
-
title: "Studio generated transcript"
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
function normalizeGeneratedOutputPath(type, input) {
|
|
60
|
-
const trimmed = (input ?? "").trim().replace(/^\/+|\/+$/g, "");
|
|
61
|
-
const normalized = trimmed.replace(/^vault\/+/i, "") || GENERATED_OUTPUT_CONFIG[type].defaultPath;
|
|
62
|
-
validateVaultFilePath(normalized);
|
|
63
|
-
return normalized;
|
|
64
|
-
}
|
|
65
|
-
function resolveGeneratedVaultPath(input) {
|
|
66
|
-
const config = GENERATED_OUTPUT_CONFIG[input.type];
|
|
67
|
-
const outputPath = normalizeGeneratedOutputPath(input.type, input.outputPath);
|
|
68
|
-
const fileName = input.fileName.trim();
|
|
69
|
-
validateVaultFilePath(fileName);
|
|
70
|
-
const vaultPath = hasConfiguredExtension(outputPath, config.extensions) ? outputPath : `${outputPath}/${fileName}`;
|
|
71
|
-
validateVaultFilePath(vaultPath);
|
|
72
|
-
return vaultPath;
|
|
73
|
-
}
|
|
74
|
-
function extensionForGeneratedMimeType(type, mimeType) {
|
|
75
|
-
const clean = mimeType.toLowerCase().split(";")[0]?.trim();
|
|
76
|
-
if (clean === "image/jpeg") return ".jpg";
|
|
77
|
-
if (clean === "image/webp") return ".webp";
|
|
78
|
-
if (clean === "image/gif") return ".gif";
|
|
79
|
-
if (clean === "image/avif") return ".avif";
|
|
80
|
-
if (clean === "video/webm") return ".webm";
|
|
81
|
-
if (clean === "video/quicktime") return ".mov";
|
|
82
|
-
if (clean === "audio/wav" || clean === "audio/x-wav") return ".wav";
|
|
83
|
-
if (clean === "audio/mp4" || clean === "audio/x-m4a") return ".m4a";
|
|
84
|
-
if (clean === "audio/ogg" || clean === "application/ogg") return ".ogg";
|
|
85
|
-
if (clean === "audio/webm") return ".webm";
|
|
86
|
-
if (clean === "audio/aac") return ".aac";
|
|
87
|
-
return GENERATED_OUTPUT_CONFIG[type].defaultExtension;
|
|
88
|
-
}
|
|
89
|
-
function validateGeneratedMediaSourceUrl(value, type) {
|
|
90
|
-
let url;
|
|
91
|
-
try {
|
|
92
|
-
url = new URL(value);
|
|
93
|
-
} catch {
|
|
94
|
-
throw new Error(`Generated ${generatedMediaLabel(type)} provider returned an invalid URL`);
|
|
95
|
-
}
|
|
96
|
-
if (url.protocol !== "https:") {
|
|
97
|
-
throw new Error(`Generated ${generatedMediaLabel(type)} provider returned a non-https URL`);
|
|
98
|
-
}
|
|
99
|
-
if (isBlockedFetchHostname(url.hostname)) {
|
|
100
|
-
throw new Error(`Generated ${generatedMediaLabel(type)} provider returned a private network URL`);
|
|
101
|
-
}
|
|
102
|
-
return url.toString();
|
|
103
|
-
}
|
|
104
|
-
function generatedExtensionFromUrl(value, type) {
|
|
105
|
-
const ext = fileExtension(new URL(value).pathname);
|
|
106
|
-
if (ext && GENERATED_OUTPUT_CONFIG[type].extensions.has(ext)) return ext;
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
function generatedMimeTypeFromUrl(value, type) {
|
|
110
|
-
const ext = generatedExtensionFromUrl(value, type);
|
|
111
|
-
if (ext === ".jpg" || ext === ".jpeg") return "image/jpeg";
|
|
112
|
-
if (ext === ".webp") return "image/webp";
|
|
113
|
-
if (ext === ".gif") return "image/gif";
|
|
114
|
-
if (ext === ".avif") return "image/avif";
|
|
115
|
-
if (ext === ".webm" && type !== "speech") return "video/webm";
|
|
116
|
-
if (ext === ".mov") return "video/quicktime";
|
|
117
|
-
if (ext === ".wav") return "audio/wav";
|
|
118
|
-
if (ext === ".m4a") return "audio/mp4";
|
|
119
|
-
if (ext === ".ogg") return "audio/ogg";
|
|
120
|
-
if (ext === ".webm") return "audio/webm";
|
|
121
|
-
if (ext === ".aac") return "audio/aac";
|
|
122
|
-
if (ext === ".mp3") return "audio/mpeg";
|
|
123
|
-
if (ext === ".mp4") return "video/mp4";
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
function hasConfiguredExtension(path, extensions) {
|
|
127
|
-
const ext = fileExtension(path);
|
|
128
|
-
return Boolean(ext && extensions.has(ext));
|
|
129
|
-
}
|
|
130
|
-
function fileExtension(path) {
|
|
131
|
-
const name = path.split("/").pop() ?? path;
|
|
132
|
-
const dotIndex = name.lastIndexOf(".");
|
|
133
|
-
if (dotIndex === -1) return null;
|
|
134
|
-
return name.slice(dotIndex).toLowerCase();
|
|
135
|
-
}
|
|
136
|
-
function generatedMediaLabel(type) {
|
|
137
|
-
if (type === "speech") return "audio";
|
|
138
|
-
return type;
|
|
139
|
-
}
|
|
140
|
-
function isGeneratedMediaType(value) {
|
|
141
|
-
return value === "image" || value === "video" || value === "avatar" || value === "speech";
|
|
142
|
-
}
|
|
143
30
|
|
|
144
31
|
// src/studio/generated-media/store.ts
|
|
145
32
|
import { and, desc, eq, inArray, sql } from "drizzle-orm";
|
|
@@ -573,10 +460,342 @@ function persistedGeneratedMediaFromRow(workspaceId, row) {
|
|
|
573
460
|
sizeBytes
|
|
574
461
|
};
|
|
575
462
|
}
|
|
463
|
+
|
|
464
|
+
// src/studio/generated-media/flows.ts
|
|
465
|
+
var GENERATED_MEDIA_INGEST_TIMEOUT_MS = 3e4;
|
|
466
|
+
var STALE_PENDING_GENERATION_MS = 5 * 60 * 1e3;
|
|
467
|
+
var AVATAR_TIMEOUT_MS = 3e4;
|
|
468
|
+
var SPEECH_TIMEOUT_MS = 45e3;
|
|
469
|
+
var TRANSCRIPTION_TIMEOUT_MS = 45e3;
|
|
470
|
+
var TRANSCRIPTION_AUDIO_TIMEOUT_MS = 15e3;
|
|
471
|
+
function createGeneratedMediaFlows(config) {
|
|
472
|
+
return {
|
|
473
|
+
mediaFields: (media) => mediaFields(config, media),
|
|
474
|
+
ingestFromUrl: (input) => ingestFromUrl(config, input),
|
|
475
|
+
settleProviderJob: (response, providerJobId, input) => settleProviderJob(config, response, providerJobId, input),
|
|
476
|
+
generateAvatar: (input) => generateAvatar(config, input),
|
|
477
|
+
generateSpeech: (input) => generateSpeech(config, input),
|
|
478
|
+
transcribe: (input) => transcribe(config, input),
|
|
479
|
+
persistProviderImage: (input) => persistProviderImage(config, input),
|
|
480
|
+
cleanupPersistedImages: (context, images) => cleanupPersistedImages(config, context, images),
|
|
481
|
+
refreshProviderJob: (row, input) => refreshProviderJob(config, row, input)
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function defaultSanitize(message) {
|
|
485
|
+
return message.slice(0, 500);
|
|
486
|
+
}
|
|
487
|
+
function mediaFields(config, media) {
|
|
488
|
+
return {
|
|
489
|
+
assetId: media?.assetId,
|
|
490
|
+
assetVersionId: media?.assetVersionId,
|
|
491
|
+
vaultPath: media?.vaultPath,
|
|
492
|
+
...config.recordVaultSave && media?.assetVersionId ? { savedToVaultAt: null } : {},
|
|
493
|
+
r2Key: media?.r2Key,
|
|
494
|
+
mimeType: media?.mimeType,
|
|
495
|
+
sizeBytes: media?.sizeBytes
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
async function ingestFromUrl(config, input) {
|
|
499
|
+
try {
|
|
500
|
+
const media = await withTimeout(
|
|
501
|
+
(signal) => config.store.persistGeneratedMediaFromUrl({ ...input, signal }),
|
|
502
|
+
GENERATED_MEDIA_INGEST_TIMEOUT_MS,
|
|
503
|
+
`Generated ${input.generationType} ingestion timed out after ${GENERATED_MEDIA_INGEST_TIMEOUT_MS / 1e3}s`
|
|
504
|
+
);
|
|
505
|
+
return { media, storageStatus: "saved" };
|
|
506
|
+
} catch (err) {
|
|
507
|
+
if (err instanceof ToolInputError && config.failOnRejectedResultUrl !== false) throw err;
|
|
508
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
509
|
+
console.error(`Generated ${input.generationType} storage failed:`, message);
|
|
510
|
+
return {
|
|
511
|
+
media: null,
|
|
512
|
+
storageStatus: "failed",
|
|
513
|
+
storageError: `Generated ${input.generationType} was created, but could not be saved to Vault.`
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
async function settleProviderJob(config, response, providerJobId, input) {
|
|
518
|
+
const providerStatus = requiredText(response.status) ?? (providerJobId ? "pending" : "submitted");
|
|
519
|
+
const providerResultUrl = requiredText(response.video_url) ?? requiredText(response.url);
|
|
520
|
+
if (!providerResultUrl && !providerJobId) {
|
|
521
|
+
throw new Error(`${input.generationType === "video" ? "Video" : "Avatar"} provider returned neither a video URL nor a job id`);
|
|
522
|
+
}
|
|
523
|
+
await input.recheck?.();
|
|
524
|
+
const source = providerResultUrl ? config.router.resolveRouterMediaSource(providerResultUrl, input.apiKey) : null;
|
|
525
|
+
const ingestion = source ? await ingestFromUrl(config, {
|
|
526
|
+
context: input.context,
|
|
527
|
+
workspaceId: input.workspaceId,
|
|
528
|
+
userId: input.userId,
|
|
529
|
+
generationType: input.generationType,
|
|
530
|
+
prompt: input.prompt,
|
|
531
|
+
model: input.model,
|
|
532
|
+
outputPath: input.outputPath,
|
|
533
|
+
sourceUrl: source.url,
|
|
534
|
+
sourceAuthorization: source.authorization,
|
|
535
|
+
metadata: { providerJobId: providerJobId ?? void 0, providerStatus, ...input.sourceMetadata },
|
|
536
|
+
recheck: input.recheck
|
|
537
|
+
}) : null;
|
|
538
|
+
const media = ingestion?.media ?? null;
|
|
539
|
+
const result = media?.url ?? browserUsableSourceUrl(source);
|
|
540
|
+
return {
|
|
541
|
+
result,
|
|
542
|
+
media,
|
|
543
|
+
fields: {
|
|
544
|
+
status: result ? "succeeded" : "running",
|
|
545
|
+
provider: input.generationType,
|
|
546
|
+
providerJobId: providerJobId ?? void 0,
|
|
547
|
+
providerStatus,
|
|
548
|
+
resultUrl: result ?? void 0,
|
|
549
|
+
providerResultUrl: source?.url,
|
|
550
|
+
pollingUrl: response.polling_url,
|
|
551
|
+
storageStatus: ingestion?.storageStatus,
|
|
552
|
+
storageError: ingestion?.storageError,
|
|
553
|
+
...mediaFields(config, media)
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
async function generateAvatar(config, input) {
|
|
558
|
+
const audioUrl = requiredText(input.inputs.audioUrl);
|
|
559
|
+
if (!audioUrl) throw new Error("audioUrl is required");
|
|
560
|
+
const response = await withTimeout(
|
|
561
|
+
(signal) => config.generation.generateAvatarViaRouter(
|
|
562
|
+
{
|
|
563
|
+
model: input.model,
|
|
564
|
+
prompt: input.effectivePrompt,
|
|
565
|
+
audio_url: audioUrl,
|
|
566
|
+
image_url: input.inputs.imageUrl,
|
|
567
|
+
avatar_id: input.inputs.avatarId,
|
|
568
|
+
callback_url: input.callbackUrl
|
|
569
|
+
},
|
|
570
|
+
signal,
|
|
571
|
+
input.apiKey
|
|
572
|
+
),
|
|
573
|
+
AVATAR_TIMEOUT_MS,
|
|
574
|
+
`Avatar generation did not return a provider job within ${AVATAR_TIMEOUT_MS / 1e3}s`
|
|
575
|
+
);
|
|
576
|
+
return settleProviderJob(config, response, requiredText(response.job_id) ?? requiredText(response.id), {
|
|
577
|
+
...input,
|
|
578
|
+
generationType: "avatar",
|
|
579
|
+
sourceMetadata: { audioUrl, imageUrl: input.inputs.imageUrl, avatarId: input.inputs.avatarId }
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
async function generateSpeech(config, input) {
|
|
583
|
+
const speechInput = await input.resolveSpeechInput(input.prompt, input.apiKey);
|
|
584
|
+
const audio = await withTimeout(
|
|
585
|
+
() => input.speak({ input: speechInput.input, model: input.model, voice: input.voice }),
|
|
586
|
+
SPEECH_TIMEOUT_MS,
|
|
587
|
+
`Speech generation timed out after ${SPEECH_TIMEOUT_MS / 1e3}s for model ${input.model}`
|
|
588
|
+
);
|
|
589
|
+
const bytes = new Uint8Array(audio);
|
|
590
|
+
if (bytes.length === 0) throw new Error(`Speech provider returned empty audio for model ${input.model}`);
|
|
591
|
+
const media = await config.store.persistGeneratedMediaAsset({
|
|
592
|
+
context: input.context,
|
|
593
|
+
workspaceId: input.workspaceId,
|
|
594
|
+
userId: input.userId,
|
|
595
|
+
generationType: "speech",
|
|
596
|
+
prompt: input.prompt,
|
|
597
|
+
model: input.model,
|
|
598
|
+
outputPath: input.outputPath,
|
|
599
|
+
bytes,
|
|
600
|
+
mimeType: "audio/mpeg",
|
|
601
|
+
metadata: { voice: input.voice },
|
|
602
|
+
recheck: input.recheck
|
|
603
|
+
});
|
|
604
|
+
return {
|
|
605
|
+
media,
|
|
606
|
+
speechInput,
|
|
607
|
+
fields: {
|
|
608
|
+
status: "succeeded",
|
|
609
|
+
provider: "speech",
|
|
610
|
+
inputs: {
|
|
611
|
+
...input.inputs,
|
|
612
|
+
speechInputMode: speechInput.mode,
|
|
613
|
+
speechInput: speechInput.input,
|
|
614
|
+
scriptCostUsd: speechInput.scriptCostUsd
|
|
615
|
+
},
|
|
616
|
+
resultUrl: metadataResultUrl(media.url),
|
|
617
|
+
...mediaFields(config, media)
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
async function transcribe(config, input) {
|
|
622
|
+
const { inputs, model } = input;
|
|
623
|
+
const audioUrl = requiredText(inputs.audioUrl);
|
|
624
|
+
if (!audioUrl) throw new Error("audioUrl is required");
|
|
625
|
+
const audioBlob = await withTimeout(
|
|
626
|
+
(signal) => fetchBoundedAudio(audioUrl, { signal }),
|
|
627
|
+
TRANSCRIPTION_AUDIO_TIMEOUT_MS,
|
|
628
|
+
`Timed out fetching transcription audio from ${audioUrl}`
|
|
629
|
+
);
|
|
630
|
+
const response = await withTimeout(
|
|
631
|
+
(signal) => config.generation.transcribeViaRouter({
|
|
632
|
+
audioBlob,
|
|
633
|
+
audioUrl,
|
|
634
|
+
model,
|
|
635
|
+
language: inputs.language,
|
|
636
|
+
prompt: input.prompt || void 0,
|
|
637
|
+
responseFormat: inputs.responseFormat,
|
|
638
|
+
temperature: inputs.temperature,
|
|
639
|
+
signal,
|
|
640
|
+
apiKey: input.apiKey
|
|
641
|
+
}),
|
|
642
|
+
TRANSCRIPTION_TIMEOUT_MS,
|
|
643
|
+
`Transcription timed out after ${TRANSCRIPTION_TIMEOUT_MS / 1e3}s for model ${model}`
|
|
644
|
+
);
|
|
645
|
+
const text = response.text ?? null;
|
|
646
|
+
if (!text) throw new Error(`Transcription provider returned no text for model ${model}`);
|
|
647
|
+
const file = await config.store.writeGeneratedTranscriptVaultFile({
|
|
648
|
+
workspaceId: input.workspaceId,
|
|
649
|
+
generationId: input.generationId,
|
|
650
|
+
prompt: input.prompt || audioUrl,
|
|
651
|
+
model,
|
|
652
|
+
outputPath: input.outputPath,
|
|
653
|
+
transcript: text,
|
|
654
|
+
sourceAudioUrl: audioUrl,
|
|
655
|
+
language: typeof inputs.language === "string" ? inputs.language : void 0,
|
|
656
|
+
responseFormat: typeof inputs.responseFormat === "string" ? inputs.responseFormat : void 0,
|
|
657
|
+
createdAt: input.createdAt,
|
|
658
|
+
status: "succeeded"
|
|
659
|
+
});
|
|
660
|
+
return { text, fields: { status: "succeeded", provider: "transcription", vaultPath: file.vaultPath } };
|
|
661
|
+
}
|
|
662
|
+
async function persistProviderImage(config, input) {
|
|
663
|
+
const base = {
|
|
664
|
+
context: input.context,
|
|
665
|
+
workspaceId: input.workspaceId,
|
|
666
|
+
userId: input.userId,
|
|
667
|
+
generationType: "image",
|
|
668
|
+
prompt: input.prompt,
|
|
669
|
+
model: input.model,
|
|
670
|
+
outputPath: input.outputPath,
|
|
671
|
+
metadata: { size: input.size, quality: input.quality },
|
|
672
|
+
recheck: input.recheck
|
|
673
|
+
};
|
|
674
|
+
const url = requiredText(input.url);
|
|
675
|
+
if (url && !url.startsWith("data:")) {
|
|
676
|
+
if (input.remoteUrl === "link") return { url };
|
|
677
|
+
return config.store.persistGeneratedMediaFromUrl({ ...base, sourceUrl: url });
|
|
678
|
+
}
|
|
679
|
+
const image = providerImageBytes(url, input.b64Json);
|
|
680
|
+
if (!image) throw new Error(`Image provider returned no image for model ${input.model}`);
|
|
681
|
+
return config.store.persistGeneratedMediaAsset({
|
|
682
|
+
...base,
|
|
683
|
+
bytes: image.bytes,
|
|
684
|
+
mimeType: image.mimeType,
|
|
685
|
+
extension: extensionForGeneratedMimeType("image", image.mimeType)
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
async function cleanupPersistedImages(config, context, images) {
|
|
689
|
+
await Promise.all(images.map(async (image) => {
|
|
690
|
+
if (!image.assetId || !image.assetVersionId || !image.r2Key) return;
|
|
691
|
+
await config.store.cleanupGeneratedMediaAsset(context, {
|
|
692
|
+
assetId: image.assetId,
|
|
693
|
+
assetVersionId: image.assetVersionId,
|
|
694
|
+
r2Key: image.r2Key
|
|
695
|
+
});
|
|
696
|
+
}));
|
|
697
|
+
}
|
|
698
|
+
async function refreshProviderJob(config, row, input) {
|
|
699
|
+
const metadata = metadataRecord2(row.metadata);
|
|
700
|
+
const status = stringValue2(metadata.generationStatus);
|
|
701
|
+
if (status !== "running" && status !== "pending") return { kind: "unchanged" };
|
|
702
|
+
const providerJobId = stringValue2(metadata.providerJobId);
|
|
703
|
+
const provider = stringValue2(metadata.provider);
|
|
704
|
+
if (!providerJobId) {
|
|
705
|
+
if (status === "pending" && Date.now() - row.createdAt.getTime() > STALE_PENDING_GENERATION_MS) {
|
|
706
|
+
return {
|
|
707
|
+
kind: "stale",
|
|
708
|
+
metadata: {
|
|
709
|
+
...metadata,
|
|
710
|
+
generationStatus: "failed",
|
|
711
|
+
providerError: "Generation did not receive a provider job id before the polling deadline."
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
return { kind: "unchanged" };
|
|
716
|
+
}
|
|
717
|
+
if (provider !== "video" && provider !== "avatar") return { kind: "unchanged" };
|
|
718
|
+
try {
|
|
719
|
+
const normalized = normalizeProviderJobStatus(await config.router.routerMediaStatus(providerJobId, void 0, input.apiKey));
|
|
720
|
+
const existingAssetVersionId = stringValue2(metadata.assetVersionId);
|
|
721
|
+
const source = normalized.resultUrl ? config.router.resolveRouterMediaSource(normalized.resultUrl, input.apiKey) : null;
|
|
722
|
+
const providerResultUrl = source?.url;
|
|
723
|
+
let resultUrl = source && !source.authorization ? source.url : void 0;
|
|
724
|
+
let mediaMetadata = {};
|
|
725
|
+
if (normalized.status === "succeeded" && source && existingAssetVersionId) {
|
|
726
|
+
resultUrl = stringValue2(metadata.resultUrl) ?? row.result ?? resultUrl;
|
|
727
|
+
}
|
|
728
|
+
if (normalized.status === "succeeded" && source && !existingAssetVersionId) {
|
|
729
|
+
try {
|
|
730
|
+
const media = await withTimeout(
|
|
731
|
+
(signal) => config.store.persistGeneratedMediaFromUrl({
|
|
732
|
+
context: input.context,
|
|
733
|
+
workspaceId: row.workspaceId,
|
|
734
|
+
userId: input.userId,
|
|
735
|
+
generationType: provider,
|
|
736
|
+
prompt: row.prompt,
|
|
737
|
+
model: row.model,
|
|
738
|
+
outputPath: stringValue2(metadata.outputPath),
|
|
739
|
+
sourceUrl: source.url,
|
|
740
|
+
sourceAuthorization: source.authorization,
|
|
741
|
+
signal,
|
|
742
|
+
metadata: { providerJobId, providerStatus: normalized.providerStatus }
|
|
743
|
+
}),
|
|
744
|
+
GENERATED_MEDIA_INGEST_TIMEOUT_MS,
|
|
745
|
+
`Generated ${provider} ingestion timed out after ${GENERATED_MEDIA_INGEST_TIMEOUT_MS / 1e3}s`
|
|
746
|
+
);
|
|
747
|
+
resultUrl = media.url;
|
|
748
|
+
mediaMetadata = { providerResultUrl, ...mediaFields(config, media), storageStatus: "saved" };
|
|
749
|
+
} catch (err) {
|
|
750
|
+
if (source.authorization) throw err;
|
|
751
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
752
|
+
console.error(`Generated ${provider} storage failed during polling:`, message);
|
|
753
|
+
mediaMetadata = {
|
|
754
|
+
providerResultUrl,
|
|
755
|
+
storageStatus: "failed",
|
|
756
|
+
storageError: `Generated ${provider} was created, but could not be saved to Vault.`
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
const unchanged = normalized.status === status && (!resultUrl || resultUrl === stringValue2(metadata.resultUrl)) && !normalized.error;
|
|
761
|
+
if (unchanged) return { kind: "unchanged" };
|
|
762
|
+
return {
|
|
763
|
+
kind: "update",
|
|
764
|
+
status: normalized.status,
|
|
765
|
+
resultUrl,
|
|
766
|
+
result: resultUrl ?? row.result,
|
|
767
|
+
metadata: {
|
|
768
|
+
...metadata,
|
|
769
|
+
generationStatus: normalized.status,
|
|
770
|
+
providerStatus: normalized.providerStatus,
|
|
771
|
+
providerError: normalized.error ? (config.sanitizeProviderError ?? defaultSanitize)(normalized.error) : void 0,
|
|
772
|
+
lastPollError: void 0,
|
|
773
|
+
lastPollErrorAt: void 0,
|
|
774
|
+
resultUrl: resultUrl ?? metadata.resultUrl,
|
|
775
|
+
...mediaMetadata
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
} catch (err) {
|
|
779
|
+
const message = err instanceof Error ? err.message : "Failed to refresh provider job";
|
|
780
|
+
return {
|
|
781
|
+
kind: "poll-failed",
|
|
782
|
+
metadata: { ...metadata, lastPollError: (config.sanitizeProviderError ?? defaultSanitize)(message), lastPollErrorAt: (/* @__PURE__ */ new Date()).toISOString() }
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
function metadataRecord2(value) {
|
|
787
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
788
|
+
}
|
|
789
|
+
function stringValue2(value) {
|
|
790
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
791
|
+
}
|
|
576
792
|
export {
|
|
577
793
|
DEFAULT_GENERATED_OUTPUT_PATHS,
|
|
794
|
+
GENERATED_MEDIA_INGEST_TIMEOUT_MS,
|
|
578
795
|
GENERATED_MEDIA_MISSING_FILE_METADATA,
|
|
579
796
|
GENERATED_OUTPUT_CONFIG,
|
|
797
|
+
STALE_PENDING_GENERATION_MS,
|
|
798
|
+
createGeneratedMediaFlows,
|
|
580
799
|
createGeneratedMediaStore,
|
|
581
800
|
extensionForGeneratedMimeType,
|
|
582
801
|
generatedExtensionFromUrl,
|