@tangle-network/agent-app 0.60.250 → 0.60.251
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-L6J72JQ2.js +15 -0
- package/dist/DesignCanvasEditor-QFQD63MR.js +18 -0
- package/dist/agent-enrollment/drizzle.js +3 -3
- package/dist/agent-enrollment/index.js +3 -3
- package/dist/app-auth/drizzle.d.ts +561 -0
- package/dist/app-auth/drizzle.js +72 -0
- package/dist/app-auth/drizzle.js.map +1 -0
- package/dist/app-auth/index.js +5 -3
- package/dist/app-auth/index.js.map +1 -1
- package/dist/app-oauth/drizzle.d.ts +2080 -0
- package/dist/app-oauth/drizzle.js +161 -0
- package/dist/app-oauth/drizzle.js.map +1 -0
- package/dist/app-oauth/index.d.ts +4 -0
- package/dist/app-oauth/index.js +8 -222
- package/dist/app-oauth/index.js.map +1 -1
- package/dist/app-oauth/issuer.d.ts +133 -0
- package/dist/app-oauth/issuer.js +247 -0
- package/dist/app-oauth/issuer.js.map +1 -0
- package/dist/assistant/index.js +13 -13
- package/dist/chat-react/index.js +4 -4
- package/dist/chat-routes/index.js +37 -67
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/promote-file-part.d.ts +2 -3
- package/dist/chat-store/index.js +4 -4
- package/dist/{chunk-MY3EJJ6Y.js → chunk-4FEH6266.js} +2 -2
- package/dist/{chunk-5Y7Z5G3Y.js → chunk-4GCPADYG.js} +20 -336
- package/dist/chunk-4GCPADYG.js.map +1 -0
- package/dist/{chunk-X556WVBG.js → chunk-4ZSLX3LY.js} +2 -2
- package/dist/chunk-57XPEL7X.js +26 -0
- package/dist/chunk-57XPEL7X.js.map +1 -0
- package/dist/chunk-6Z7TZVKZ.js +26 -0
- package/dist/chunk-6Z7TZVKZ.js.map +1 -0
- package/dist/{chunk-7KKOFMLD.js → chunk-AWIQQEFP.js} +1 -1
- package/dist/chunk-AWIQQEFP.js.map +1 -0
- package/dist/{chunk-VBKP2NLI.js → chunk-BTKI4XMM.js} +2 -2
- package/dist/{chunk-63QAQP7I.js → chunk-CNBVWPQC.js} +7 -7
- package/dist/{chunk-FENBDSIW.js → chunk-CQGEGPY7.js} +75 -3
- package/dist/chunk-CQGEGPY7.js.map +1 -0
- package/dist/chunk-CTREXL3O.js +335 -0
- package/dist/chunk-CTREXL3O.js.map +1 -0
- package/dist/chunk-DLWO3J7D.js +238 -0
- package/dist/chunk-DLWO3J7D.js.map +1 -0
- package/dist/{chunk-LWSJK546.js → chunk-DSMGS4IV.js} +5 -5
- package/dist/{chunk-LWSJK546.js.map → chunk-DSMGS4IV.js.map} +1 -1
- package/dist/{chunk-A3KPDLSF.js → chunk-EFPIHR6F.js} +18 -18
- package/dist/chunk-FRAICFTZ.js +191 -0
- package/dist/chunk-FRAICFTZ.js.map +1 -0
- package/dist/chunk-GS7VWV26.js +61 -0
- package/dist/chunk-GS7VWV26.js.map +1 -0
- package/dist/{chunk-NMSAZFRL.js → chunk-H5GQMLHA.js} +2 -2
- package/dist/{chunk-OQE6WMDP.js → chunk-HN6MZ2XL.js} +5 -5
- package/dist/chunk-HY57QRRW.js +11 -0
- package/dist/chunk-HY57QRRW.js.map +1 -0
- package/dist/{chunk-TCGZFSN5.js → chunk-KH4QSBNI.js} +2 -2
- package/dist/{chunk-JH3CKHF4.js → chunk-KJODHPWM.js} +8 -8
- package/dist/chunk-LSBI5MWS.js +66 -0
- package/dist/chunk-LSBI5MWS.js.map +1 -0
- package/dist/chunk-MDRH3SDA.js +106 -0
- package/dist/chunk-MDRH3SDA.js.map +1 -0
- package/dist/{chunk-VBWYH7UZ.js → chunk-NHYRIM4I.js} +3 -3
- package/dist/{chunk-BYP54FMI.js → chunk-O2RCDK5D.js} +30 -15
- package/dist/{chunk-BYP54FMI.js.map → chunk-O2RCDK5D.js.map} +1 -1
- package/dist/{chunk-EWOJATDS.js → chunk-PDD5A43Y.js} +3 -3
- package/dist/{chunk-23JUSUUB.js → chunk-RZLCBWGG.js} +2 -2
- package/dist/chunk-SFZELD6V.js +52 -0
- package/dist/chunk-SFZELD6V.js.map +1 -0
- package/dist/{chunk-Y4W6GK5X.js → chunk-UGFCLD32.js} +2 -2
- package/dist/{chunk-ZGUXI5SI.js → chunk-VUBJZEZB.js} +2 -2
- package/dist/{chunk-LQYIBL3G.js → chunk-WL7PZK7Q.js} +71 -1
- package/dist/chunk-WL7PZK7Q.js.map +1 -0
- package/dist/{chunk-7HZCFG2A.js → chunk-WP2GYFZ4.js} +38 -1
- package/dist/chunk-WP2GYFZ4.js.map +1 -0
- package/dist/{chunk-JK7R7BZQ.js → chunk-ZWJ3SZ2G.js} +2 -2
- package/dist/crypto/digest.d.ts +2 -0
- package/dist/crypto/index.d.ts +1 -0
- package/dist/crypto/index.js +6 -2
- package/dist/design-canvas/index.js +5 -3
- package/dist/design-canvas/index.js.map +1 -1
- package/dist/design-canvas-react/engine.js +7 -5
- package/dist/design-canvas-react/index.js +14 -12
- package/dist/design-canvas-react/index.js.map +1 -1
- package/dist/design-canvas-react/lazy.js +1 -1
- package/dist/eval/index.d.ts +4 -0
- package/dist/eval/index.js +125 -0
- package/dist/eval/index.js.map +1 -1
- package/dist/eval/persona-driver.d.ts +37 -0
- package/dist/eval/research-plan.d.ts +25 -0
- package/dist/eval/research-plan.js +55 -0
- package/dist/eval/research-plan.js.map +1 -0
- package/dist/eval/scorecard.d.ts +38 -0
- package/dist/forms/blank.d.ts +2 -2
- package/dist/forms/index.js +4 -5
- package/dist/forms/index.js.map +1 -1
- package/dist/hosted-agent/application.js +2 -2
- package/dist/interactions/index.js +3 -3
- package/dist/knowledge/prelaunch-audit.d.ts +17 -0
- package/dist/knowledge/prelaunch-audit.js +67 -0
- package/dist/knowledge/prelaunch-audit.js.map +1 -0
- package/dist/media/drizzle.d.ts +207 -0
- package/dist/media/drizzle.js +26 -0
- package/dist/media/drizzle.js.map +1 -0
- package/dist/media/generate-request.d.ts +53 -0
- package/dist/media/generation-record.d.ts +68 -0
- package/dist/media/index.d.ts +13 -0
- package/dist/media/index.js +653 -0
- package/dist/media/index.js.map +1 -0
- package/dist/media/model-catalog.d.ts +109 -0
- package/dist/media/router-client.d.ts +40 -0
- package/dist/media/router-generation.d.ts +44 -0
- package/dist/media/speech-script.d.ts +20 -0
- package/dist/openui/index.js +1 -1
- package/dist/operator/index.js +4 -5
- package/dist/operator/index.js.map +1 -1
- package/dist/plans/decision.d.ts +48 -0
- package/dist/plans/drizzle.d.ts +25 -0
- package/dist/plans/drizzle.js +97 -0
- package/dist/plans/drizzle.js.map +1 -0
- package/dist/plans/index.d.ts +1 -1
- package/dist/plans/index.js +11 -3
- package/dist/platform/billing-config.d.ts +22 -0
- package/dist/platform/billing-config.js +36 -0
- package/dist/platform/billing-config.js.map +1 -0
- package/dist/platform/index.js +13 -11
- package/dist/platform/index.js.map +1 -1
- package/dist/preset-cloudflare/index.js +2 -1
- package/dist/preset-cloudflare/index.js.map +1 -1
- package/dist/profile/index.js +4 -5
- package/dist/profile/index.js.map +1 -1
- package/dist/public-consultation/index.d.ts +1 -1
- package/dist/public-consultation/index.js +13 -11
- package/dist/public-consultation/index.js.map +1 -1
- package/dist/runtime/telemetry-cap.d.ts +24 -0
- package/dist/runtime/telemetry-cap.js +36 -0
- package/dist/runtime/telemetry-cap.js.map +1 -0
- package/dist/sandbox/index.js +12 -9
- package/dist/sequences/index.js +4 -2
- package/dist/sequences/index.js.map +1 -1
- package/dist/skills-placement/box.d.ts +50 -0
- package/dist/skills-placement/box.js +204 -0
- package/dist/skills-placement/box.js.map +1 -0
- package/dist/skills-placement/index.js +8 -96
- package/dist/skills-placement/index.js.map +1 -1
- package/dist/spend/budget.d.ts +13 -0
- package/dist/spend/drizzle.d.ts +55 -0
- package/dist/spend/drizzle.js +131 -0
- package/dist/spend/drizzle.js.map +1 -0
- package/dist/spend/index.d.ts +2 -1
- package/dist/spend/index.js +77 -58
- package/dist/spend/index.js.map +1 -1
- package/dist/spend/platform-settlements.d.ts +46 -0
- package/dist/stream/index.js +19 -19
- package/dist/studio/generated-media/index.d.ts +6 -0
- package/dist/studio/generated-media/index.js +590 -0
- package/dist/studio/generated-media/index.js.map +1 -0
- package/dist/studio/generated-media/output.d.ts +27 -0
- package/dist/studio/generated-media/store.d.ts +175 -0
- package/dist/studio-react/download-generations.d.ts +7 -0
- package/dist/studio-react/index.d.ts +1 -0
- package/dist/studio-react/index.js +85 -0
- package/dist/studio-react/index.js.map +1 -1
- package/dist/studio-react/use-studio-route.d.ts +44 -0
- package/dist/teams/invitations-api.d.ts +4 -0
- package/dist/teams/invitations-api.js +44 -32
- package/dist/teams/invitations-api.js.map +1 -1
- package/dist/theme/dom.d.ts +22 -0
- package/dist/theme/dom.js +18 -0
- package/dist/theme/dom.js.map +1 -0
- package/dist/vault/collaboration.d.ts +83 -0
- package/dist/vault/collaboration.js +215 -0
- package/dist/vault/collaboration.js.map +1 -0
- package/dist/vault/server.js +6 -53
- package/dist/vault/server.js.map +1 -1
- package/dist/vault/store/coordinator.d.ts +64 -0
- package/dist/vault/store/index.d.ts +12 -0
- package/dist/vault/store/index.js +1202 -0
- package/dist/vault/store/index.js.map +1 -0
- package/dist/vault/store/paths.d.ts +65 -0
- package/dist/vault/store/revisions.d.ts +211 -0
- package/dist/vault/store/sandbox-sync.d.ts +74 -0
- package/dist/vault/store/store.d.ts +161 -0
- package/dist/vault/store/tree.d.ts +11 -0
- package/dist/web/entry-server.d.ts +7 -0
- package/dist/web/entry-server.js +29 -0
- package/dist/web/entry-server.js.map +1 -0
- package/dist/web/fetch-guard.d.ts +6 -0
- package/dist/web/index.d.ts +3 -0
- package/dist/web/index.js +20 -4
- package/dist/web/mime.d.ts +16 -0
- package/dist/web/rate-limit.d.ts +25 -0
- package/dist/web/timeout.d.ts +9 -0
- package/dist/web-react/agent-profile-editor.js +3 -3
- package/dist/web-react/api-access-panel.d.ts +4 -2
- package/dist/web-react/document.d.ts +41 -0
- package/dist/web-react/document.js +103 -0
- package/dist/web-react/document.js.map +1 -0
- package/dist/web-react/index.js +31 -31
- package/dist/workspace-react/index.js +5 -5
- package/package.json +95 -4
- package/dist/DesignCanvas-OW3W2QXW.js +0 -13
- package/dist/DesignCanvasEditor-TCHZF25W.js +0 -16
- package/dist/chunk-5Y7Z5G3Y.js.map +0 -1
- package/dist/chunk-7HZCFG2A.js.map +0 -1
- package/dist/chunk-7KKOFMLD.js.map +0 -1
- package/dist/chunk-FENBDSIW.js.map +0 -1
- package/dist/chunk-LQYIBL3G.js.map +0 -1
- /package/dist/{DesignCanvas-OW3W2QXW.js.map → DesignCanvas-L6J72JQ2.js.map} +0 -0
- /package/dist/{DesignCanvasEditor-TCHZF25W.js.map → DesignCanvasEditor-QFQD63MR.js.map} +0 -0
- /package/dist/{chunk-MY3EJJ6Y.js.map → chunk-4FEH6266.js.map} +0 -0
- /package/dist/{chunk-X556WVBG.js.map → chunk-4ZSLX3LY.js.map} +0 -0
- /package/dist/{chunk-VBKP2NLI.js.map → chunk-BTKI4XMM.js.map} +0 -0
- /package/dist/{chunk-63QAQP7I.js.map → chunk-CNBVWPQC.js.map} +0 -0
- /package/dist/{chunk-A3KPDLSF.js.map → chunk-EFPIHR6F.js.map} +0 -0
- /package/dist/{chunk-NMSAZFRL.js.map → chunk-H5GQMLHA.js.map} +0 -0
- /package/dist/{chunk-OQE6WMDP.js.map → chunk-HN6MZ2XL.js.map} +0 -0
- /package/dist/{chunk-TCGZFSN5.js.map → chunk-KH4QSBNI.js.map} +0 -0
- /package/dist/{chunk-JH3CKHF4.js.map → chunk-KJODHPWM.js.map} +0 -0
- /package/dist/{chunk-VBWYH7UZ.js.map → chunk-NHYRIM4I.js.map} +0 -0
- /package/dist/{chunk-EWOJATDS.js.map → chunk-PDD5A43Y.js.map} +0 -0
- /package/dist/{chunk-23JUSUUB.js.map → chunk-RZLCBWGG.js.map} +0 -0
- /package/dist/{chunk-Y4W6GK5X.js.map → chunk-UGFCLD32.js.map} +0 -0
- /package/dist/{chunk-ZGUXI5SI.js.map → chunk-VUBJZEZB.js.map} +0 -0
- /package/dist/{chunk-JK7R7BZQ.js.map → chunk-ZWJ3SZ2G.js.map} +0 -0
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
import {
|
|
2
|
+
validateVaultFilePath
|
|
3
|
+
} from "../../chunk-FRAICFTZ.js";
|
|
4
|
+
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
|
+
|
|
144
|
+
// src/studio/generated-media/store.ts
|
|
145
|
+
import { and, desc, eq, inArray, sql } from "drizzle-orm";
|
|
146
|
+
var GENERATED_MEDIA_MISSING_FILE_METADATA = "Existing generated media asset is missing persisted file metadata";
|
|
147
|
+
var ASSET_VERSION_QUERY_BATCH_SIZE = 200;
|
|
148
|
+
function metadataRecord(value) {
|
|
149
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
150
|
+
}
|
|
151
|
+
function stringValue(value) {
|
|
152
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
153
|
+
}
|
|
154
|
+
function numberValue(value) {
|
|
155
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
156
|
+
}
|
|
157
|
+
async function inIdChunks(ids, query) {
|
|
158
|
+
const rows = [];
|
|
159
|
+
for (let index = 0; index < ids.length; index += ASSET_VERSION_QUERY_BATCH_SIZE) {
|
|
160
|
+
rows.push(...await query(ids.slice(index, index + ASSET_VERSION_QUERY_BATCH_SIZE)));
|
|
161
|
+
}
|
|
162
|
+
return rows;
|
|
163
|
+
}
|
|
164
|
+
function createGeneratedMediaQueries(config) {
|
|
165
|
+
const { db } = config;
|
|
166
|
+
const { assets, assetVersions, generations } = config.tables;
|
|
167
|
+
async function cleanupGeneratedAssetRecords(assetId, assetVersionId) {
|
|
168
|
+
if (assetVersionId) {
|
|
169
|
+
await db.delete(assetVersions).where(eq(assetVersions.id, assetVersionId));
|
|
170
|
+
}
|
|
171
|
+
await db.delete(assets).where(eq(assets.id, assetId));
|
|
172
|
+
}
|
|
173
|
+
async function walkGeneratedMediaVaultEntries(workspaceId) {
|
|
174
|
+
const generationRows = await db.select().from(generations).where(and(
|
|
175
|
+
eq(generations.workspaceId, workspaceId),
|
|
176
|
+
inArray(generations.type, ["image", "video", "avatar", "speech"])
|
|
177
|
+
)).orderBy(desc(generations.createdAt));
|
|
178
|
+
const assetVersionIds = generationRows.map((generation) => stringValue(metadataRecord(generation.metadata).assetVersionId)).filter((id) => Boolean(id));
|
|
179
|
+
const uniqueAssetVersionIds = [...new Set(assetVersionIds)];
|
|
180
|
+
if (uniqueAssetVersionIds.length === 0) return [];
|
|
181
|
+
const versionRows = await listGeneratedAssetVersionRows(workspaceId, uniqueAssetVersionIds, { visibleOnly: true });
|
|
182
|
+
const versionById = new Map(versionRows.map((row) => [row.version.id, row]));
|
|
183
|
+
const entries = [];
|
|
184
|
+
for (const generation of generationRows) {
|
|
185
|
+
const assetVersionId = stringValue(metadataRecord(generation.metadata).assetVersionId);
|
|
186
|
+
if (!assetVersionId) continue;
|
|
187
|
+
const row = versionById.get(assetVersionId);
|
|
188
|
+
if (!row) continue;
|
|
189
|
+
const entry = buildGeneratedMediaVaultEntry(workspaceId, generation, row);
|
|
190
|
+
if (entry) entries.push(entry);
|
|
191
|
+
}
|
|
192
|
+
return entries;
|
|
193
|
+
}
|
|
194
|
+
async function listGeneratedAssetVersionRows(workspaceId, assetVersionIds, opts) {
|
|
195
|
+
return inIdChunks(assetVersionIds, (batch) => db.select({ version: assetVersions, asset: assets }).from(assetVersions).innerJoin(assets, eq(assets.id, assetVersions.assetId)).where(and(
|
|
196
|
+
eq(assetVersions.workspaceId, workspaceId),
|
|
197
|
+
inArray(assetVersions.id, batch),
|
|
198
|
+
...opts.visibleOnly ? [config.vaultVisibility.condition(assets)] : []
|
|
199
|
+
)));
|
|
200
|
+
}
|
|
201
|
+
async function readGeneratedMediaVaultEntryByPath(workspaceId, path, opts) {
|
|
202
|
+
const [row] = await db.select({ version: assetVersions, asset: assets }).from(assetVersions).innerJoin(assets, eq(assets.id, assetVersions.assetId)).where(and(
|
|
203
|
+
eq(assetVersions.workspaceId, workspaceId),
|
|
204
|
+
eq(assets.workspaceId, workspaceId),
|
|
205
|
+
eq(assets.type, "generated"),
|
|
206
|
+
eq(assets.vaultPath, path),
|
|
207
|
+
...opts.visibleOnly ? [config.vaultVisibility.condition(assets)] : []
|
|
208
|
+
)).orderBy(desc(assetVersions.createdAt)).limit(1);
|
|
209
|
+
if (!row) return null;
|
|
210
|
+
const versionMetadata = metadataRecord(row.version.metadata);
|
|
211
|
+
const assetMetadata = metadataRecord(row.asset.metadata);
|
|
212
|
+
const generationType = stringValue(versionMetadata.generationType) ?? stringValue(assetMetadata.generationType);
|
|
213
|
+
if (!isGeneratedMediaType(generationType)) return null;
|
|
214
|
+
const [generation] = await db.select().from(generations).where(and(
|
|
215
|
+
eq(generations.workspaceId, workspaceId),
|
|
216
|
+
eq(generations.type, generationType),
|
|
217
|
+
sql`json_extract(${generations.metadata}, '$.assetVersionId') = ${row.version.id}`
|
|
218
|
+
)).orderBy(desc(generations.createdAt)).limit(1);
|
|
219
|
+
if (!generation) return null;
|
|
220
|
+
const entry = buildGeneratedMediaVaultEntry(workspaceId, generation, row);
|
|
221
|
+
return entry?.path === path ? entry : null;
|
|
222
|
+
}
|
|
223
|
+
async function findPersistedGeneratedMediaByProviderJob(input) {
|
|
224
|
+
const [row] = await db.select({ version: assetVersions, asset: assets }).from(assetVersions).innerJoin(assets, eq(assets.id, assetVersions.assetId)).where(and(
|
|
225
|
+
eq(assetVersions.workspaceId, input.workspaceId),
|
|
226
|
+
eq(assets.workspaceId, input.workspaceId),
|
|
227
|
+
eq(assets.type, "generated"),
|
|
228
|
+
sql`json_extract(${assetVersions.metadata}, '$.generationType') = ${input.generationType}`,
|
|
229
|
+
sql`json_extract(${assetVersions.metadata}, '$.providerJobId') = ${input.providerJobId}`
|
|
230
|
+
)).orderBy(desc(assetVersions.createdAt)).limit(1);
|
|
231
|
+
if (!row) return null;
|
|
232
|
+
return persistedGeneratedMediaFromRow(input.workspaceId, row);
|
|
233
|
+
}
|
|
234
|
+
async function listGeneratedMediaVaultPaths(workspaceId) {
|
|
235
|
+
const entries = await walkGeneratedMediaVaultEntries(workspaceId);
|
|
236
|
+
return entries.map((entry) => entry.path);
|
|
237
|
+
}
|
|
238
|
+
async function listGeneratedMediaVaultEntries(workspaceId) {
|
|
239
|
+
const entries = await walkGeneratedMediaVaultEntries(workspaceId);
|
|
240
|
+
return entries.map((entry) => ({
|
|
241
|
+
path: entry.path,
|
|
242
|
+
sizeBytes: entry.file.metadata.sizeBytes ?? null,
|
|
243
|
+
mimeType: entry.file.mimeType
|
|
244
|
+
}));
|
|
245
|
+
}
|
|
246
|
+
async function readGeneratedMediaVaultFile(workspaceId, path) {
|
|
247
|
+
validateVaultFilePath(path);
|
|
248
|
+
const entry = await readGeneratedMediaVaultEntryByPath(workspaceId, path, { visibleOnly: config.vaultVisibility.pathReads });
|
|
249
|
+
return entry?.file ?? null;
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
cleanupGeneratedAssetRecords,
|
|
253
|
+
listGeneratedAssetVersionRows,
|
|
254
|
+
readGeneratedMediaVaultEntryByPath,
|
|
255
|
+
findPersistedGeneratedMediaByProviderJob,
|
|
256
|
+
listGeneratedMediaVaultPaths,
|
|
257
|
+
listGeneratedMediaVaultEntries,
|
|
258
|
+
readGeneratedMediaVaultFile
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function createGeneratedMediaWrites(config, queries) {
|
|
262
|
+
const { db } = config;
|
|
263
|
+
const { assets, assetVersions } = config.tables;
|
|
264
|
+
const { cleanupGeneratedAssetRecords, findPersistedGeneratedMediaByProviderJob } = queries;
|
|
265
|
+
async function persistGeneratedMediaAsset(input) {
|
|
266
|
+
if (input.bytes.byteLength === 0) throw new Error(`Generated ${generatedMediaLabel(input.generationType)} returned an empty file`);
|
|
267
|
+
const bucket = config.bucket(input.context);
|
|
268
|
+
if (!bucket) throw new Error(`Generated ${generatedMediaLabel(input.generationType)} storage is not configured for this deployment.`);
|
|
269
|
+
const id = crypto.randomUUID();
|
|
270
|
+
const extension = input.extension ?? extensionForGeneratedMimeType(input.generationType, input.mimeType);
|
|
271
|
+
const fileName = `studio-${id}${extension}`;
|
|
272
|
+
const vaultPath = resolveGeneratedVaultPath({
|
|
273
|
+
type: input.generationType,
|
|
274
|
+
outputPath: input.outputPath,
|
|
275
|
+
fileName
|
|
276
|
+
});
|
|
277
|
+
const r2Key = `workspace/${input.workspaceId}/generated-media/${id}${extension}`;
|
|
278
|
+
const outputConfig = GENERATED_OUTPUT_CONFIG[input.generationType];
|
|
279
|
+
const sizeBytes = input.bytes.byteLength;
|
|
280
|
+
const assetMetadata = {
|
|
281
|
+
source: "studio-generate",
|
|
282
|
+
generationType: input.generationType,
|
|
283
|
+
model: input.model,
|
|
284
|
+
mimeType: input.mimeType,
|
|
285
|
+
sizeBytes,
|
|
286
|
+
vaultPath,
|
|
287
|
+
...input.metadata
|
|
288
|
+
};
|
|
289
|
+
await input.recheck?.();
|
|
290
|
+
const [asset] = await db.insert(assets).values({
|
|
291
|
+
workspaceId: input.workspaceId,
|
|
292
|
+
title: input.prompt.slice(0, 120) || outputConfig.title,
|
|
293
|
+
type: "generated",
|
|
294
|
+
status: "draft",
|
|
295
|
+
vaultPath,
|
|
296
|
+
metadata: assetMetadata,
|
|
297
|
+
createdBy: input.userId
|
|
298
|
+
}).returning();
|
|
299
|
+
if (!asset) throw new Error(`Generated ${generatedMediaLabel(input.generationType)} asset was not created`);
|
|
300
|
+
let version;
|
|
301
|
+
try {
|
|
302
|
+
await input.recheck?.();
|
|
303
|
+
[version] = await db.insert(assetVersions).values({
|
|
304
|
+
assetId: asset.id,
|
|
305
|
+
workspaceId: input.workspaceId,
|
|
306
|
+
version: 1,
|
|
307
|
+
r2Key,
|
|
308
|
+
metadata: {
|
|
309
|
+
...assetMetadata,
|
|
310
|
+
fileName
|
|
311
|
+
},
|
|
312
|
+
createdBy: input.userId
|
|
313
|
+
}).returning();
|
|
314
|
+
await input.recheck?.();
|
|
315
|
+
await bucket.put(r2Key, input.bytes, {
|
|
316
|
+
httpMetadata: { contentType: input.mimeType },
|
|
317
|
+
customMetadata: {
|
|
318
|
+
workspaceId: input.workspaceId,
|
|
319
|
+
source: "studio-generate",
|
|
320
|
+
generationType: input.generationType,
|
|
321
|
+
model: input.model ?? ""
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
} catch (err) {
|
|
325
|
+
await cleanupGeneratedAssetRecords(asset.id, version?.id);
|
|
326
|
+
throw err;
|
|
327
|
+
}
|
|
328
|
+
if (!version) throw new Error(`Generated ${generatedMediaLabel(input.generationType)} asset version was not created`);
|
|
329
|
+
return {
|
|
330
|
+
url: `/api/workspaces/${input.workspaceId}/asset-versions/${version.id}/file`,
|
|
331
|
+
assetId: asset.id,
|
|
332
|
+
assetVersionId: version.id,
|
|
333
|
+
vaultPath,
|
|
334
|
+
r2Key,
|
|
335
|
+
mimeType: input.mimeType,
|
|
336
|
+
sizeBytes
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
async function persistGeneratedMediaFromUrl(input) {
|
|
340
|
+
const url = input.sourceAuthorization ? config.validateRouterSourceUrl(input.sourceUrl) : validateGeneratedMediaSourceUrl(input.sourceUrl, input.generationType);
|
|
341
|
+
const providerJobId = stringValue(input.metadata?.providerJobId);
|
|
342
|
+
if (providerJobId) {
|
|
343
|
+
const existing = await findPersistedGeneratedMediaByProviderJob({
|
|
344
|
+
workspaceId: input.workspaceId,
|
|
345
|
+
generationType: input.generationType,
|
|
346
|
+
providerJobId
|
|
347
|
+
});
|
|
348
|
+
if (existing) return existing;
|
|
349
|
+
}
|
|
350
|
+
await input.recheck?.();
|
|
351
|
+
const response = await fetch(url, {
|
|
352
|
+
signal: input.signal,
|
|
353
|
+
...input.sourceAuthorization ? { headers: config.routerSourceHeaders?.(input.sourceAuthorization) ?? { Authorization: input.sourceAuthorization } } : {}
|
|
354
|
+
});
|
|
355
|
+
if (!response.ok) {
|
|
356
|
+
throw new Error(`Could not fetch generated ${generatedMediaLabel(input.generationType)}: ${response.status} ${response.statusText}`);
|
|
357
|
+
}
|
|
358
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
359
|
+
await input.recheck?.();
|
|
360
|
+
const mimeType = response.headers.get("Content-Type")?.split(";")[0]?.trim() || generatedMimeTypeFromUrl(url, input.generationType) || GENERATED_OUTPUT_CONFIG[input.generationType].defaultMimeType;
|
|
361
|
+
return persistGeneratedMediaAsset({
|
|
362
|
+
context: input.context,
|
|
363
|
+
workspaceId: input.workspaceId,
|
|
364
|
+
userId: input.userId,
|
|
365
|
+
generationType: input.generationType,
|
|
366
|
+
prompt: input.prompt,
|
|
367
|
+
model: input.model,
|
|
368
|
+
outputPath: input.outputPath,
|
|
369
|
+
bytes,
|
|
370
|
+
mimeType,
|
|
371
|
+
extension: generatedExtensionFromUrl(url, input.generationType) ?? extensionForGeneratedMimeType(input.generationType, mimeType),
|
|
372
|
+
metadata: {
|
|
373
|
+
providerResultUrl: url,
|
|
374
|
+
...input.metadata
|
|
375
|
+
},
|
|
376
|
+
recheck: input.recheck
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
async function cleanupGeneratedMediaAsset(context, media) {
|
|
380
|
+
const bucket = config.bucket(context);
|
|
381
|
+
if (bucket) {
|
|
382
|
+
await bucket.delete(media.r2Key).catch((err) => {
|
|
383
|
+
console.error("Generated media file cleanup failed:", err instanceof Error ? err.message : String(err));
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
await cleanupGeneratedAssetRecords(media.assetId, media.assetVersionId).catch((err) => {
|
|
387
|
+
console.error("Generated media record cleanup failed:", err instanceof Error ? err.message : String(err));
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
async function writeGeneratedTranscriptVaultFile(input) {
|
|
391
|
+
const id = crypto.randomUUID();
|
|
392
|
+
const fileName = `studio-${id}.md`;
|
|
393
|
+
const vaultPath = resolveGeneratedVaultPath({
|
|
394
|
+
type: "transcription",
|
|
395
|
+
outputPath: input.outputPath,
|
|
396
|
+
fileName
|
|
397
|
+
});
|
|
398
|
+
await config.writeVaultFile(input.workspaceId, vaultPath, {
|
|
399
|
+
frontmatter: {
|
|
400
|
+
type: GENERATED_OUTPUT_CONFIG.transcription.frontmatterType,
|
|
401
|
+
generationId: input.generationId,
|
|
402
|
+
sourceAudioUrl: input.sourceAudioUrl,
|
|
403
|
+
prompt: input.prompt,
|
|
404
|
+
model: input.model ?? "",
|
|
405
|
+
language: input.language ?? "",
|
|
406
|
+
responseFormat: input.responseFormat ?? "",
|
|
407
|
+
status: input.status,
|
|
408
|
+
created: input.createdAt.toISOString()
|
|
409
|
+
},
|
|
410
|
+
body: input.transcript
|
|
411
|
+
});
|
|
412
|
+
return { vaultPath };
|
|
413
|
+
}
|
|
414
|
+
return { persistGeneratedMediaAsset, persistGeneratedMediaFromUrl, cleanupGeneratedMediaAsset, writeGeneratedTranscriptVaultFile };
|
|
415
|
+
}
|
|
416
|
+
function createGeneratedMediaDeletes(config, queries) {
|
|
417
|
+
const { db } = config;
|
|
418
|
+
const { assets, assetVersions, generations } = config.tables;
|
|
419
|
+
const { listGeneratedAssetVersionRows, readGeneratedMediaVaultEntryByPath } = queries;
|
|
420
|
+
async function deleteGeneratedMediaAsset(input) {
|
|
421
|
+
validateVaultFilePath(input.path);
|
|
422
|
+
const entry = await readGeneratedMediaVaultEntryByPath(input.workspaceId, input.path, { visibleOnly: false });
|
|
423
|
+
if (!entry) return { ok: false, reason: "not_found" };
|
|
424
|
+
if (entry.file.revision !== input.expectedRevision) return { ok: false, reason: "revision_mismatch" };
|
|
425
|
+
await deleteGeneratedAssetRows({
|
|
426
|
+
bucket: input.bucket,
|
|
427
|
+
workspaceId: input.workspaceId,
|
|
428
|
+
assetIds: [entry.file.metadata.assetId],
|
|
429
|
+
generationIds: []
|
|
430
|
+
});
|
|
431
|
+
return { ok: true };
|
|
432
|
+
}
|
|
433
|
+
async function deleteGeneratedMediaByGenerationIds(input) {
|
|
434
|
+
const rows = await inIdChunks(input.ids, (batch) => db.select({ id: generations.id, metadata: generations.metadata }).from(generations).where(and(
|
|
435
|
+
eq(generations.workspaceId, input.workspaceId),
|
|
436
|
+
inArray(generations.id, batch)
|
|
437
|
+
)));
|
|
438
|
+
if (rows.length === 0) return { deleted: 0 };
|
|
439
|
+
const assetVersionIds = [...new Set(rows.map((row) => stringValue(metadataRecord(row.metadata).assetVersionId)).filter((id) => Boolean(id)))];
|
|
440
|
+
const versionRows = assetVersionIds.length === 0 ? [] : await listGeneratedAssetVersionRows(input.workspaceId, assetVersionIds, { visibleOnly: false });
|
|
441
|
+
const assetIds = [...new Set(versionRows.filter((row) => row.asset.type === "generated").map((row) => row.asset.id))];
|
|
442
|
+
await deleteGeneratedAssetRows({
|
|
443
|
+
bucket: input.bucket,
|
|
444
|
+
workspaceId: input.workspaceId,
|
|
445
|
+
assetIds,
|
|
446
|
+
generationIds: rows.map((row) => row.id)
|
|
447
|
+
});
|
|
448
|
+
return { deleted: rows.length };
|
|
449
|
+
}
|
|
450
|
+
async function deleteGeneratedAssetRows(input) {
|
|
451
|
+
const versionRows = input.assetIds.length === 0 ? [] : await inIdChunks(input.assetIds, (batch) => db.select({ id: assetVersions.id, r2Key: assetVersions.r2Key }).from(assetVersions).where(and(
|
|
452
|
+
eq(assetVersions.workspaceId, input.workspaceId),
|
|
453
|
+
inArray(assetVersions.assetId, batch)
|
|
454
|
+
)));
|
|
455
|
+
const linkedGenerations = versionRows.length === 0 ? [] : await inIdChunks(versionRows.map((row) => row.id), (batch) => db.select({ id: generations.id }).from(generations).where(and(
|
|
456
|
+
eq(generations.workspaceId, input.workspaceId),
|
|
457
|
+
inArray(sql`json_extract(${generations.metadata}, '$.assetVersionId')`, batch)
|
|
458
|
+
)));
|
|
459
|
+
const generationIds = [.../* @__PURE__ */ new Set([...input.generationIds, ...linkedGenerations.map((row) => row.id)])];
|
|
460
|
+
if (generationIds.length === 0 && input.assetIds.length === 0) return;
|
|
461
|
+
const deleteGenerations = db.delete(generations).where(and(
|
|
462
|
+
eq(generations.workspaceId, input.workspaceId),
|
|
463
|
+
inArray(generations.id, generationIds)
|
|
464
|
+
));
|
|
465
|
+
if (input.assetIds.length === 0) {
|
|
466
|
+
await db.batch([deleteGenerations]);
|
|
467
|
+
} else {
|
|
468
|
+
await db.batch([
|
|
469
|
+
db.delete(assetVersions).where(and(
|
|
470
|
+
eq(assetVersions.workspaceId, input.workspaceId),
|
|
471
|
+
inArray(assetVersions.assetId, input.assetIds)
|
|
472
|
+
)),
|
|
473
|
+
db.delete(assets).where(and(
|
|
474
|
+
eq(assets.workspaceId, input.workspaceId),
|
|
475
|
+
inArray(assets.id, input.assetIds)
|
|
476
|
+
)),
|
|
477
|
+
deleteGenerations
|
|
478
|
+
]);
|
|
479
|
+
}
|
|
480
|
+
if (!input.bucket) return;
|
|
481
|
+
for (const row of versionRows) {
|
|
482
|
+
if (!row.r2Key) continue;
|
|
483
|
+
const r2Key = row.r2Key;
|
|
484
|
+
await input.bucket.delete(r2Key).catch((err) => {
|
|
485
|
+
console.error("Generated media R2 object cleanup failed:", r2Key, err instanceof Error ? err.message : String(err));
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return { deleteGeneratedMediaAsset, deleteGeneratedMediaByGenerationIds };
|
|
490
|
+
}
|
|
491
|
+
function createGeneratedMediaStore(config) {
|
|
492
|
+
const queries = createGeneratedMediaQueries(config);
|
|
493
|
+
const { listGeneratedMediaVaultPaths, listGeneratedMediaVaultEntries, readGeneratedMediaVaultFile } = queries;
|
|
494
|
+
return {
|
|
495
|
+
tables: config.tables,
|
|
496
|
+
...createGeneratedMediaWrites(config, queries),
|
|
497
|
+
...createGeneratedMediaDeletes(config, queries),
|
|
498
|
+
listGeneratedMediaVaultPaths,
|
|
499
|
+
listGeneratedMediaVaultEntries,
|
|
500
|
+
readGeneratedMediaVaultFile
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
function buildGeneratedMediaVaultEntry(workspaceId, generation, row) {
|
|
504
|
+
const generationMetadata = metadataRecord(generation.metadata);
|
|
505
|
+
const assetVersionId = stringValue(generationMetadata.assetVersionId) ?? row.version.id;
|
|
506
|
+
const assetMetadata = metadataRecord(row.asset.metadata);
|
|
507
|
+
const versionMetadata = metadataRecord(row.version.metadata);
|
|
508
|
+
const generationType = stringValue(versionMetadata.generationType) ?? stringValue(assetMetadata.generationType);
|
|
509
|
+
if (!isGeneratedMediaType(generationType) || generationType !== generation.type) return null;
|
|
510
|
+
const fileName = stringValue(versionMetadata.fileName);
|
|
511
|
+
if (!fileName) return null;
|
|
512
|
+
const blobUrl = stringValue(generation.result) ?? `/api/workspaces/${workspaceId}/asset-versions/${assetVersionId}/file`;
|
|
513
|
+
const mimeType = stringValue(versionMetadata.mimeType) ?? stringValue(assetMetadata.mimeType) ?? GENERATED_OUTPUT_CONFIG[generationType].defaultMimeType;
|
|
514
|
+
const path = stringValue(row.asset.vaultPath) ?? stringValue(generationMetadata.vaultPath) ?? resolveGeneratedVaultPath({
|
|
515
|
+
type: generationType,
|
|
516
|
+
outputPath: stringValue(generationMetadata.outputPath),
|
|
517
|
+
fileName
|
|
518
|
+
});
|
|
519
|
+
validateVaultFilePath(path);
|
|
520
|
+
return {
|
|
521
|
+
path,
|
|
522
|
+
file: {
|
|
523
|
+
kind: "media",
|
|
524
|
+
path,
|
|
525
|
+
content: "",
|
|
526
|
+
frontmatter: {
|
|
527
|
+
type: GENERATED_OUTPUT_CONFIG[generationType].frontmatterType,
|
|
528
|
+
prompt: generation.prompt,
|
|
529
|
+
model: generation.model ?? "",
|
|
530
|
+
status: stringValue(generationMetadata.generationStatus) ?? "unknown",
|
|
531
|
+
providerStatus: stringValue(generationMetadata.providerStatus) ?? "",
|
|
532
|
+
providerJobId: stringValue(generationMetadata.providerJobId) ?? "",
|
|
533
|
+
assetId: row.asset.id,
|
|
534
|
+
assetVersionId,
|
|
535
|
+
created: generation.createdAt.toISOString()
|
|
536
|
+
},
|
|
537
|
+
body: "",
|
|
538
|
+
blobUrl,
|
|
539
|
+
mimeType,
|
|
540
|
+
revision: row.version.id,
|
|
541
|
+
metadata: {
|
|
542
|
+
prompt: generation.prompt,
|
|
543
|
+
model: generation.model,
|
|
544
|
+
createdAt: generation.createdAt,
|
|
545
|
+
generationStatus: stringValue(generationMetadata.generationStatus) ?? "unknown",
|
|
546
|
+
providerStatus: stringValue(generationMetadata.providerStatus),
|
|
547
|
+
providerJobId: stringValue(generationMetadata.providerJobId),
|
|
548
|
+
assetId: row.asset.id,
|
|
549
|
+
assetVersionId,
|
|
550
|
+
fileName,
|
|
551
|
+
sizeBytes: numberValue(versionMetadata.sizeBytes) ?? numberValue(assetMetadata.sizeBytes)
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
function persistedGeneratedMediaFromRow(workspaceId, row) {
|
|
557
|
+
const versionMetadata = metadataRecord(row.version.metadata);
|
|
558
|
+
const r2Key = stringValue(row.version.r2Key);
|
|
559
|
+
const vaultPath = stringValue(row.asset.vaultPath);
|
|
560
|
+
const mimeType = stringValue(versionMetadata.mimeType);
|
|
561
|
+
const sizeBytes = numberValue(versionMetadata.sizeBytes);
|
|
562
|
+
if (!r2Key || !vaultPath || !mimeType || sizeBytes == null) {
|
|
563
|
+
throw new Error(GENERATED_MEDIA_MISSING_FILE_METADATA);
|
|
564
|
+
}
|
|
565
|
+
validateVaultFilePath(vaultPath);
|
|
566
|
+
return {
|
|
567
|
+
url: `/api/workspaces/${workspaceId}/asset-versions/${row.version.id}/file`,
|
|
568
|
+
assetId: row.asset.id,
|
|
569
|
+
assetVersionId: row.version.id,
|
|
570
|
+
vaultPath,
|
|
571
|
+
r2Key,
|
|
572
|
+
mimeType,
|
|
573
|
+
sizeBytes
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
export {
|
|
577
|
+
DEFAULT_GENERATED_OUTPUT_PATHS,
|
|
578
|
+
GENERATED_MEDIA_MISSING_FILE_METADATA,
|
|
579
|
+
GENERATED_OUTPUT_CONFIG,
|
|
580
|
+
createGeneratedMediaStore,
|
|
581
|
+
extensionForGeneratedMimeType,
|
|
582
|
+
generatedExtensionFromUrl,
|
|
583
|
+
generatedMediaLabel,
|
|
584
|
+
generatedMimeTypeFromUrl,
|
|
585
|
+
isGeneratedMediaType,
|
|
586
|
+
normalizeGeneratedOutputPath,
|
|
587
|
+
resolveGeneratedVaultPath,
|
|
588
|
+
validateGeneratedMediaSourceUrl
|
|
589
|
+
};
|
|
590
|
+
//# sourceMappingURL=index.js.map
|