vidspotai-shared 1.0.130 → 1.0.132
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/lib/globals/aiModels/enums.d.ts +6 -0
- package/lib/globals/aiModels/enums.d.ts.map +1 -1
- package/lib/globals/aiModels/enums.js +31 -1
- package/lib/globals/aiModels/index.d.ts.map +1 -1
- package/lib/globals/aiModels/index.js +2 -0
- package/lib/globals/aiModels/providers/bytedance.d.ts.map +1 -1
- package/lib/globals/aiModels/providers/bytedance.js +4 -0
- package/lib/globals/aiModels/providers/fal.d.ts +20 -0
- package/lib/globals/aiModels/providers/fal.d.ts.map +1 -0
- package/lib/globals/aiModels/providers/fal.js +100 -0
- package/lib/globals/aiModels/providers/google.d.ts.map +1 -1
- package/lib/globals/aiModels/providers/google.js +229 -177
- package/lib/globals/aiModels/tierHelpers.d.ts +3 -1
- package/lib/globals/aiModels/tierHelpers.d.ts.map +1 -1
- package/lib/globals/aiModels/tierHelpers.js +7 -1
- package/lib/globals/aiModels/types.d.ts +10 -1
- package/lib/globals/aiModels/types.d.ts.map +1 -1
- package/lib/globals/creditUnit.d.ts +9 -0
- package/lib/globals/creditUnit.d.ts.map +1 -1
- package/lib/globals/creditUnit.js +10 -1
- package/lib/globals/index.d.ts +2 -0
- package/lib/globals/index.d.ts.map +1 -1
- package/lib/globals/index.js +2 -0
- package/lib/globals/posterExport.d.ts +34 -0
- package/lib/globals/posterExport.d.ts.map +1 -0
- package/lib/globals/posterExport.js +50 -0
- package/lib/globals/types.d.ts +9 -1
- package/lib/globals/types.d.ts.map +1 -1
- package/lib/globals/types.js +9 -0
- package/lib/globals/videoTools.d.ts +24 -0
- package/lib/globals/videoTools.d.ts.map +1 -0
- package/lib/globals/videoTools.js +31 -0
- package/lib/libs/storage/MediaStorage.d.ts.map +1 -1
- package/lib/libs/storage/MediaStorage.js +37 -10
- package/lib/libs/storage/cdnUrl.d.ts +7 -0
- package/lib/libs/storage/cdnUrl.d.ts.map +1 -1
- package/lib/libs/storage/cdnUrl.js +26 -0
- package/lib/models/index.d.ts +2 -0
- package/lib/models/index.d.ts.map +1 -1
- package/lib/models/index.js +2 -0
- package/lib/models/organization.model.d.ts +23 -0
- package/lib/models/organization.model.d.ts.map +1 -1
- package/lib/models/organization.model.js +17 -0
- package/lib/models/posterExport.model.d.ts +29 -0
- package/lib/models/posterExport.model.d.ts.map +1 -0
- package/lib/models/posterExport.model.js +2 -0
- package/lib/models/videoTool.model.d.ts +59 -0
- package/lib/models/videoTool.model.d.ts.map +1 -0
- package/lib/models/videoTool.model.js +2 -0
- package/lib/services/agent/planner/Planner.d.ts.map +1 -1
- package/lib/services/agent/planner/Planner.js +9 -0
- package/lib/services/agent/planner/structuralRules.js +2 -2
- package/lib/services/agent/planner/validators.js +1 -1
- package/lib/services/agent/providerFallback/chains.d.ts.map +1 -1
- package/lib/services/agent/providerFallback/chains.js +18 -5
- package/lib/services/agent/tools/animateImage.tool.js +1 -1
- package/lib/services/agent/tools/generateVideo.tool.js +3 -3
- package/lib/services/agent/tools/searchUserLibrary.tool.d.ts.map +1 -1
- package/lib/services/agent/tools/searchUserLibrary.tool.js +7 -1
- package/lib/services/aiGen/aiGenFactory.service.d.ts.map +1 -1
- package/lib/services/aiGen/aiGenFactory.service.js +6 -0
- package/lib/services/aiGen/helpers.d.ts.map +1 -1
- package/lib/services/aiGen/helpers.js +5 -0
- package/lib/services/aiGen/providers/alibaba/alibaba.d.ts.map +1 -1
- package/lib/services/aiGen/providers/alibaba/alibaba.js +27 -0
- package/lib/services/aiGen/providers/bytedance/bytedance.service.d.ts.map +1 -1
- package/lib/services/aiGen/providers/bytedance/bytedance.service.js +6 -0
- package/lib/services/aiGen/providers/fal/falImageTools.service.d.ts +37 -0
- package/lib/services/aiGen/providers/fal/falImageTools.service.d.ts.map +1 -0
- package/lib/services/aiGen/providers/fal/falImageTools.service.js +278 -0
- package/lib/services/aiGen/providers/fal/falUpscale.service.d.ts +8 -0
- package/lib/services/aiGen/providers/fal/falUpscale.service.d.ts.map +1 -1
- package/lib/services/aiGen/providers/fal/falUpscale.service.js +1 -0
- package/lib/services/aiGen/providers/fal/falVideoMatting.service.d.ts +36 -0
- package/lib/services/aiGen/providers/fal/falVideoMatting.service.d.ts.map +1 -0
- package/lib/services/aiGen/providers/fal/falVideoMatting.service.js +119 -0
- package/lib/services/aiGen/providers/fal/index.d.ts +2 -0
- package/lib/services/aiGen/providers/fal/index.d.ts.map +1 -1
- package/lib/services/aiGen/providers/fal/index.js +2 -0
- package/lib/services/aiGen/providers/google/googleMusic.d.ts.map +1 -1
- package/lib/services/aiGen/providers/google/googleMusic.js +14 -1
- package/lib/services/aiGen/providers/runway/runway.service.d.ts +2 -2
- package/lib/services/aiGen/providers/runway/runway.service.d.ts.map +1 -1
- package/lib/services/aiGen/providers/runway/runway.service.js +81 -3
- package/lib/services/aiGen/textFallback.d.ts +19 -0
- package/lib/services/aiGen/textFallback.d.ts.map +1 -0
- package/lib/services/aiGen/textFallback.js +76 -0
- package/lib/services/brandKit.service.d.ts +22 -0
- package/lib/services/brandKit.service.d.ts.map +1 -0
- package/lib/services/brandKit.service.js +59 -0
- package/lib/services/bullmq.service.d.ts +11 -0
- package/lib/services/bullmq.service.d.ts.map +1 -1
- package/lib/services/bullmq.service.js +79 -18
- package/lib/services/firestore.service.d.ts +7 -1
- package/lib/services/firestore.service.d.ts.map +1 -1
- package/lib/services/firestore.service.js +10 -0
- package/lib/services/index.d.ts +1 -0
- package/lib/services/index.d.ts.map +1 -1
- package/lib/services/index.js +1 -0
- package/lib/services/translation/index.d.ts +1 -1
- package/lib/services/translation/index.d.ts.map +1 -1
- package/lib/services/translation/index.js +2 -1
- package/lib/services/translation/outputLanguage.d.ts +9 -0
- package/lib/services/translation/outputLanguage.d.ts.map +1 -1
- package/lib/services/translation/outputLanguage.js +53 -1
- package/lib/services/translation/translation.service.d.ts +16 -0
- package/lib/services/translation/translation.service.d.ts.map +1 -1
- package/lib/services/translation/translation.service.js +60 -2
- package/lib/utils/errors.d.ts +11 -0
- package/lib/utils/errors.d.ts.map +1 -1
- package/lib/utils/errors.js +29 -0
- package/lib/utils/helpers.d.ts.map +1 -1
- package/lib/utils/helpers.js +7 -4
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { VideoBgRemovalQuality } from "../../../../globals/videoTools";
|
|
2
|
+
/** fal's container options for the matted clip. */
|
|
3
|
+
export type FalVideoMattingContainer = "webm" | "mov";
|
|
4
|
+
export type FalQueueStatus = "IN_QUEUE" | "IN_PROGRESS" | "COMPLETED";
|
|
5
|
+
export interface FalVideoMattingResult {
|
|
6
|
+
url: string;
|
|
7
|
+
contentType: string;
|
|
8
|
+
width?: number;
|
|
9
|
+
height?: number;
|
|
10
|
+
durationSec?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* fal BiRefNet v2 VIDEO — alpha-matte background removal on a clip. Queue-only
|
|
14
|
+
* (minutes, not seconds), so this service exposes the three queue steps and
|
|
15
|
+
* leaves the poll loop to the VIDEO_TOOL_JOBS worker, which owns heartbeats,
|
|
16
|
+
* resumption (providerRequestId is persisted) and the ffmpeg composite.
|
|
17
|
+
*/
|
|
18
|
+
export declare class FalVideoMattingService {
|
|
19
|
+
private readonly apiKey;
|
|
20
|
+
constructor();
|
|
21
|
+
private headers;
|
|
22
|
+
/**
|
|
23
|
+
* Status/result routes for a request id. fal drops the nested sub-path of an
|
|
24
|
+
* app id (`fal-ai/birefnet/v2/video` → `fal-ai/birefnet`) on these routes —
|
|
25
|
+
* rebuilt here so a resumed job only needs the persisted request id.
|
|
26
|
+
*/
|
|
27
|
+
private routes;
|
|
28
|
+
submit(params: {
|
|
29
|
+
videoUrl: string;
|
|
30
|
+
quality: VideoBgRemovalQuality;
|
|
31
|
+
container: FalVideoMattingContainer;
|
|
32
|
+
}): Promise<string>;
|
|
33
|
+
status(requestId: string): Promise<FalQueueStatus>;
|
|
34
|
+
result(requestId: string): Promise<FalVideoMattingResult>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=falVideoMatting.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"falVideoMatting.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/fal/falVideoMatting.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAQzF,mDAAmD;AACnD,MAAM,MAAM,wBAAwB,GAAG,MAAM,GAAG,KAAK,CAAC;AActD,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,aAAa,GAAG,WAAW,CAAC;AAEtE,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAUD;;;;;GAKG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;;IAShC,OAAO,CAAC,OAAO;IAMf;;;;OAIG;IACH,OAAO,CAAC,MAAM;IAMR,MAAM,CAAC,MAAM,EAAE;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,qBAAqB,CAAC;QAC/B,SAAS,EAAE,wBAAwB,CAAC;KACrC,GAAG,OAAO,CAAC,MAAM,CAAC;IA4Cb,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAYlD,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAsBhE"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FalVideoMattingService = void 0;
|
|
4
|
+
const videoTools_1 = require("../../../../globals/videoTools");
|
|
5
|
+
const errors_1 = require("../../../../utils/errors");
|
|
6
|
+
const logger_1 = require("../../../../utils/logger");
|
|
7
|
+
const transientRetry_1 = require("../../transientRetry");
|
|
8
|
+
const falUpscale_service_1 = require("./falUpscale.service");
|
|
9
|
+
const QUEUE_BASE_URL = "https://queue.fal.run";
|
|
10
|
+
const OUTPUT_TYPE = {
|
|
11
|
+
// VP9 carries alpha (alpha_mode=1) — verified with ffprobe on a real output.
|
|
12
|
+
webm: "VP9 (.webm)",
|
|
13
|
+
mov: "PRORES4444 (.mov)",
|
|
14
|
+
};
|
|
15
|
+
/** BiRefNet video variant per quality — Light is ~12.7 compute-s per video-s. */
|
|
16
|
+
const MODEL_BY_QUALITY = {
|
|
17
|
+
standard: { model: "General Use (Light)", operating_resolution: "1024x1024" },
|
|
18
|
+
high: { model: "General Use (Heavy)", operating_resolution: "1024x1024" },
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* fal BiRefNet v2 VIDEO — alpha-matte background removal on a clip. Queue-only
|
|
22
|
+
* (minutes, not seconds), so this service exposes the three queue steps and
|
|
23
|
+
* leaves the poll loop to the VIDEO_TOOL_JOBS worker, which owns heartbeats,
|
|
24
|
+
* resumption (providerRequestId is persisted) and the ffmpeg composite.
|
|
25
|
+
*/
|
|
26
|
+
class FalVideoMattingService {
|
|
27
|
+
constructor() {
|
|
28
|
+
if (!process.env.FAL_KEY) {
|
|
29
|
+
throw new Error("Missing FAL_KEY in environment variables");
|
|
30
|
+
}
|
|
31
|
+
this.apiKey = process.env.FAL_KEY;
|
|
32
|
+
}
|
|
33
|
+
headers(json) {
|
|
34
|
+
const h = { Authorization: `Key ${this.apiKey}` };
|
|
35
|
+
if (json)
|
|
36
|
+
h["Content-Type"] = "application/json";
|
|
37
|
+
return h;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Status/result routes for a request id. fal drops the nested sub-path of an
|
|
41
|
+
* app id (`fal-ai/birefnet/v2/video` → `fal-ai/birefnet`) on these routes —
|
|
42
|
+
* rebuilt here so a resumed job only needs the persisted request id.
|
|
43
|
+
*/
|
|
44
|
+
routes(requestId) {
|
|
45
|
+
const [owner, app] = videoTools_1.VIDEO_BG_REMOVAL.appId.split("/");
|
|
46
|
+
const base = `${QUEUE_BASE_URL}/${owner}/${app}/requests/${requestId}`;
|
|
47
|
+
return { statusUrl: `${base}/status`, responseUrl: base };
|
|
48
|
+
}
|
|
49
|
+
async submit(params) {
|
|
50
|
+
const input = {
|
|
51
|
+
video_url: params.videoUrl,
|
|
52
|
+
...MODEL_BY_QUALITY[params.quality],
|
|
53
|
+
video_output_type: OUTPUT_TYPE[params.container],
|
|
54
|
+
video_quality: "high",
|
|
55
|
+
video_write_mode: "balanced",
|
|
56
|
+
refine_foreground: true,
|
|
57
|
+
output_mask: false,
|
|
58
|
+
};
|
|
59
|
+
return (0, transientRetry_1.withTransientRetry)("fal:birefnet-video:submit", async () => {
|
|
60
|
+
const resp = await fetch(`${QUEUE_BASE_URL}/${videoTools_1.VIDEO_BG_REMOVAL.appId}`, {
|
|
61
|
+
method: "POST",
|
|
62
|
+
headers: this.headers(true),
|
|
63
|
+
body: JSON.stringify(input),
|
|
64
|
+
});
|
|
65
|
+
if (!resp.ok) {
|
|
66
|
+
const body = await resp.text();
|
|
67
|
+
if (resp.status === 422) {
|
|
68
|
+
throw new errors_1.UserFacingError("This video couldn't be processed. Try an MP4, MOV or WebM up to 60 seconds.", errors_1.USER_FACING_ERROR_CODES.INPUT_VIDEO_REJECTED);
|
|
69
|
+
}
|
|
70
|
+
throw (0, falUpscale_service_1.classifyFalHttpError)(resp.status, body, "birefnet-video:submit");
|
|
71
|
+
}
|
|
72
|
+
const data = (await resp.json());
|
|
73
|
+
if (!data.request_id)
|
|
74
|
+
throw new Error("fal birefnet video did not return a request_id");
|
|
75
|
+
return data.request_id;
|
|
76
|
+
}, {
|
|
77
|
+
onRetry: ({ attempt, maxAttempts, backoffMs, err }) => logger_1.logger.warn("fal video matting submit transient error — retrying", {
|
|
78
|
+
attempt,
|
|
79
|
+
maxAttempts,
|
|
80
|
+
backoffMs,
|
|
81
|
+
message: err.message,
|
|
82
|
+
}),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async status(requestId) {
|
|
86
|
+
const resp = await fetch(this.routes(requestId).statusUrl, { headers: this.headers(false) });
|
|
87
|
+
if (!resp.ok) {
|
|
88
|
+
throw (0, falUpscale_service_1.classifyFalHttpError)(resp.status, await resp.text(), "birefnet-video:status");
|
|
89
|
+
}
|
|
90
|
+
const data = (await resp.json());
|
|
91
|
+
if (data.error)
|
|
92
|
+
throw new Error(`fal birefnet video failed: ${data.error}`);
|
|
93
|
+
const status = (data.status ?? "").toUpperCase();
|
|
94
|
+
if (status === "COMPLETED" || status === "IN_PROGRESS")
|
|
95
|
+
return status;
|
|
96
|
+
return "IN_QUEUE";
|
|
97
|
+
}
|
|
98
|
+
async result(requestId) {
|
|
99
|
+
const resp = await fetch(this.routes(requestId).responseUrl, { headers: this.headers(false) });
|
|
100
|
+
if (!resp.ok) {
|
|
101
|
+
const body = await resp.text();
|
|
102
|
+
if (resp.status === 422) {
|
|
103
|
+
throw new errors_1.UserFacingError("This video couldn't be processed. Try an MP4, MOV or WebM up to 60 seconds.", errors_1.USER_FACING_ERROR_CODES.INPUT_VIDEO_REJECTED);
|
|
104
|
+
}
|
|
105
|
+
throw (0, falUpscale_service_1.classifyFalHttpError)(resp.status, body, "birefnet-video:result");
|
|
106
|
+
}
|
|
107
|
+
const data = (await resp.json());
|
|
108
|
+
if (!data.video?.url)
|
|
109
|
+
throw new Error("fal birefnet video returned no video");
|
|
110
|
+
return {
|
|
111
|
+
url: data.video.url,
|
|
112
|
+
contentType: data.video.content_type ?? "video/webm",
|
|
113
|
+
width: data.video.width,
|
|
114
|
+
height: data.video.height,
|
|
115
|
+
durationSec: data.video.duration,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.FalVideoMattingService = FalVideoMattingService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/fal/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/fal/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC"}
|
|
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./falImage.service"), exports);
|
|
18
18
|
__exportStar(require("./falUpscale.service"), exports);
|
|
19
|
+
__exportStar(require("./falImageTools.service"), exports);
|
|
20
|
+
__exportStar(require("./falVideoMatting.service"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"googleMusic.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/google/googleMusic.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC,
|
|
1
|
+
{"version":3,"file":"googleMusic.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/google/googleMusic.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC,CA6EhC"}
|
|
@@ -19,13 +19,26 @@ const storage_1 = require("../../../../libs/storage");
|
|
|
19
19
|
async function generateGoogleMusic(params) {
|
|
20
20
|
const modelConfig = aiModels_1.aiModelConfigs[params.modelKey];
|
|
21
21
|
const modelId = modelConfig?.modelId ?? "lyria-002";
|
|
22
|
-
|
|
22
|
+
// Prod never set GCP_PROJECT_ID, so every Lyria call threw before reaching
|
|
23
|
+
// Vertex. Fall back to the runtime project (Cloud Functions sets
|
|
24
|
+
// GCLOUD_PROJECT) and then the backend service account's own project.
|
|
25
|
+
const clientEmail = process.env.GOOGLE_CLIENT_EMAIL;
|
|
26
|
+
const privateKey = process.env.GOOGLE_PRIVATE_KEY;
|
|
27
|
+
const projectId = process.env.GCP_PROJECT_ID ||
|
|
28
|
+
process.env.GOOGLE_CLOUD_PROJECT ||
|
|
29
|
+
process.env.GCLOUD_PROJECT ||
|
|
30
|
+
clientEmail?.match(/@([^.]+)\.iam\.gserviceaccount\.com$/)?.[1];
|
|
23
31
|
if (!projectId) {
|
|
24
32
|
throw new Error("Missing GCP_PROJECT_ID env var (required for Vertex Lyria)");
|
|
25
33
|
}
|
|
26
34
|
const location = process.env.GCP_LOCATION ?? "us-central1";
|
|
35
|
+
// Railway has no ADC — use the backend service account from env when it's
|
|
36
|
+
// there (same creds GCPService uses); otherwise ADC (Cloud Functions SA).
|
|
27
37
|
const auth = new google_auth_library_1.GoogleAuth({
|
|
28
38
|
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
39
|
+
...(clientEmail && privateKey
|
|
40
|
+
? { credentials: { client_email: clientEmail, private_key: privateKey.replace(/\\n/g, "\n") } }
|
|
41
|
+
: {}),
|
|
29
42
|
});
|
|
30
43
|
const client = await auth.getClient();
|
|
31
44
|
const tokenRes = await client.getAccessToken();
|
|
@@ -5,7 +5,7 @@ export declare class RunwayService extends BaseAiGenProviderService {
|
|
|
5
5
|
private readonly apiKey;
|
|
6
6
|
constructor();
|
|
7
7
|
private request;
|
|
8
|
-
generateVideo(
|
|
8
|
+
generateVideo(rawParams: VideoGenerationParams): Promise<VideoGenerationResult>;
|
|
9
9
|
checkVideoStatus({ task, outputFilename, outputFilePath, }: VideoStatusParams): Promise<VideoStatusResult>;
|
|
10
10
|
getCreditUsed({ modelKey, duration, multiClip, numImages, aspectRatio, creditFloor, resolution, audio, hasInputVideo, inputVideoDurationSec, numInputImages, numInputAudios, }: CreditUsageParams): number;
|
|
11
11
|
/**
|
|
@@ -17,6 +17,6 @@ export declare class RunwayService extends BaseAiGenProviderService {
|
|
|
17
17
|
* Runway requires concrete pixel ratios (`"1920:1080"` etc.) per the
|
|
18
18
|
* Gen-4 Image spec.
|
|
19
19
|
*/
|
|
20
|
-
generateImage(
|
|
20
|
+
generateImage(rawParams: ImageGenerationParams): Promise<ImageGenerationResult>;
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=runway.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runway.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/runway/runway.service.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"runway.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/runway/runway.service.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAiFlB,qBAAa,aAAc,SAAQ,wBAAwB;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqC;IAC7D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;;YAUlB,OAAO;IA0Df,aAAa,CACjB,SAAS,EAAE,qBAAqB,GAC/B,OAAO,CAAC,qBAAqB,CAAC;IA0J3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAuDjD,aAAa,CAAC,EACZ,QAAQ,EACR,QAAY,EACZ,SAAiB,EACjB,SAAa,EACb,WAAW,EACX,WAAW,EACX,UAAU,EACV,KAAK,EACL,aAAa,EACb,qBAAqB,EACrB,cAAkB,EAClB,cAAkB,GACnB,EAAE,iBAAiB,GAAG,MAAM;IAwD7B;;;;;;;;OAQG;IACG,aAAa,CACjB,SAAS,EAAE,qBAAqB,GAC/B,OAAO,CAAC,qBAAqB,CAAC;CAgFlC"}
|
|
@@ -16,6 +16,73 @@ const types_2 = require("./types");
|
|
|
16
16
|
const errors_1 = require("../../../../utils/errors");
|
|
17
17
|
const cameraAdapter_1 = require("./cameraAdapter");
|
|
18
18
|
const hostedModels_1 = require("./hostedModels");
|
|
19
|
+
// Runway only fetches assets served with an image Content-Type. Some of our
|
|
20
|
+
// own objects are served as application/octet-stream (a missing type at
|
|
21
|
+
// upload time), and Runway 400s on them (prod 2026-10-10, grok-imagine-1.5).
|
|
22
|
+
const RUNWAY_IMAGE_TYPES = new Set(["image/jpeg", "image/png", "image/webp"]);
|
|
23
|
+
function sniffImageType(buf) {
|
|
24
|
+
if (buf.length >= 3 && buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff)
|
|
25
|
+
return "image/jpeg";
|
|
26
|
+
if (buf.length >= 8 && buf.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]))) {
|
|
27
|
+
return "image/png";
|
|
28
|
+
}
|
|
29
|
+
if (buf.length >= 12 && buf.toString("ascii", 0, 4) === "RIFF" && buf.toString("ascii", 8, 12) === "WEBP") {
|
|
30
|
+
return "image/webp";
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Return `uri` unchanged when Runway will accept it; otherwise re-host the
|
|
36
|
+
* bytes under the sniffed image type and return the new URL. Best-effort: on
|
|
37
|
+
* any probe failure the original URI is passed through, so Runway's own error
|
|
38
|
+
* (not ours) is what surfaces.
|
|
39
|
+
*/
|
|
40
|
+
async function ensureRunwayImageUri(uri) {
|
|
41
|
+
if (uri.startsWith("data:"))
|
|
42
|
+
return uri;
|
|
43
|
+
try {
|
|
44
|
+
const head = await axios_1.default.get(uri, {
|
|
45
|
+
responseType: "arraybuffer",
|
|
46
|
+
headers: { Range: "bytes=0-0" },
|
|
47
|
+
timeout: 15000,
|
|
48
|
+
validateStatus: () => true,
|
|
49
|
+
});
|
|
50
|
+
const served = String(head.headers["content-type"] ?? "").split(";")[0].trim().toLowerCase();
|
|
51
|
+
if (RUNWAY_IMAGE_TYPES.has(served))
|
|
52
|
+
return uri;
|
|
53
|
+
const full = await axios_1.default.get(uri, { responseType: "arraybuffer", timeout: 60000 });
|
|
54
|
+
const buf = Buffer.from(full.data);
|
|
55
|
+
const sniffed = sniffImageType(buf);
|
|
56
|
+
if (!sniffed) {
|
|
57
|
+
logger_1.logger.warn("Runway input image has an unsupported type; passing through", { served, uri: uri.slice(0, 160) });
|
|
58
|
+
return uri;
|
|
59
|
+
}
|
|
60
|
+
const ext = sniffed.split("/")[1];
|
|
61
|
+
const path = `images/runway-inputs/${Date.now()}-${Math.random().toString(36).slice(2, 8)}.${ext}`;
|
|
62
|
+
const rehosted = await storage_1.mediaStorage.put(path, buf, sniffed);
|
|
63
|
+
logger_1.logger.info("Runway input image re-hosted with a proper Content-Type", { served, sniffed, path });
|
|
64
|
+
return rehosted;
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
logger_1.logger.warn("Runway input image probe failed; passing through", {
|
|
68
|
+
uri: uri.slice(0, 160),
|
|
69
|
+
err: err instanceof Error ? err.message : String(err),
|
|
70
|
+
});
|
|
71
|
+
return uri;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function withRunwayImageUris(params) {
|
|
75
|
+
const out = { ...params };
|
|
76
|
+
await Promise.all([
|
|
77
|
+
out.inputImageUrl && ensureRunwayImageUri(out.inputImageUrl).then((u) => { out.inputImageUrl = u; }),
|
|
78
|
+
out.lastFrameImageUrl && ensureRunwayImageUri(out.lastFrameImageUrl).then((u) => { out.lastFrameImageUrl = u; }),
|
|
79
|
+
out.referenceImageUrls &&
|
|
80
|
+
Promise.all(out.referenceImageUrls.map(ensureRunwayImageUri)).then((u) => { out.referenceImageUrls = u; }),
|
|
81
|
+
out.inputImageUrls &&
|
|
82
|
+
Promise.all(out.inputImageUrls.map(ensureRunwayImageUri)).then((u) => { out.inputImageUrls = u; }),
|
|
83
|
+
]);
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
19
86
|
class RunwayService extends baseAiGenProvider_service_1.BaseAiGenProviderService {
|
|
20
87
|
constructor() {
|
|
21
88
|
super();
|
|
@@ -49,12 +116,22 @@ class RunwayService extends baseAiGenProvider_service_1.BaseAiGenProviderService
|
|
|
49
116
|
if (tooLong) {
|
|
50
117
|
throw new errors_1.UserFacingError(`Your prompt is too long for this model${tooLong.maximum ? ` (max ${tooLong.maximum} characters)` : ""}. Please shorten it and try again.`, errors_1.USER_FACING_ERROR_CODES.PROMPT_TOO_LONG);
|
|
51
118
|
}
|
|
119
|
+
// OUR Runway account is out of credits (prod 2026-10, 400 "You do not
|
|
120
|
+
// have enough credits to run this task."). Ops must top up — classify as
|
|
121
|
+
// ACCOUNT_QUOTA_EXCEEDED so it still pages (errorPaging excludes that
|
|
122
|
+
// code from the quiet set) but the user sees the canned "pick another
|
|
123
|
+
// model" message instead of raw provider text.
|
|
124
|
+
const errText = typeof response.data?.error === "string" ? response.data.error : "";
|
|
125
|
+
if (/not have enough credits|insufficient credits/i.test(errText)) {
|
|
126
|
+
throw new errors_1.UserFacingError("This video model is temporarily unavailable. You haven't been charged — please pick a different model or retry shortly.", errors_1.USER_FACING_ERROR_CODES.ACCOUNT_QUOTA_EXCEEDED);
|
|
127
|
+
}
|
|
52
128
|
throw new Error(`Runway API Error: ${response.status} ${response.statusText} - ${JSON.stringify(response.data)}`);
|
|
53
129
|
}
|
|
54
130
|
return response.data;
|
|
55
131
|
}
|
|
56
|
-
async generateVideo(
|
|
57
|
-
(0, helpers_2.validateParams)(
|
|
132
|
+
async generateVideo(rawParams) {
|
|
133
|
+
(0, helpers_2.validateParams)(rawParams);
|
|
134
|
+
const params = await withRunwayImageUris(rawParams);
|
|
58
135
|
const modelId = aiModels_1.aiModelConfigs[params.modelKey]?.modelId;
|
|
59
136
|
if (!modelId)
|
|
60
137
|
throw new Error(`Unknown modelKey: ${params.modelKey}`);
|
|
@@ -298,7 +375,8 @@ class RunwayService extends baseAiGenProvider_service_1.BaseAiGenProviderService
|
|
|
298
375
|
* Runway requires concrete pixel ratios (`"1920:1080"` etc.) per the
|
|
299
376
|
* Gen-4 Image spec.
|
|
300
377
|
*/
|
|
301
|
-
async generateImage(
|
|
378
|
+
async generateImage(rawParams) {
|
|
379
|
+
const params = await withRunwayImageUris(rawParams);
|
|
302
380
|
const modelConfig = aiModels_1.aiModelConfigs[params.modelKey];
|
|
303
381
|
const modelId = modelConfig?.modelId;
|
|
304
382
|
if (!modelId)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ETextGenModels } from "../../globals/aiModels";
|
|
2
|
+
import type { TextGenerationParams, TextGenerationResult } from "./providers/types";
|
|
3
|
+
/**
|
|
4
|
+
* Cross-provider fallback for one-shot text generation.
|
|
5
|
+
*
|
|
6
|
+
* 2026-10-23: the OpenAI org ran out of credits ("429 You have no credits
|
|
7
|
+
* remaining") and every caller pinned to gpt-4o-mini — prompt generation,
|
|
8
|
+
* the translation LLM fallback — failed outright for a day. A second
|
|
9
|
+
* provider on a separate account (Gemini, separate billing + key) keeps
|
|
10
|
+
* those features up while the primary account is fixed.
|
|
11
|
+
*/
|
|
12
|
+
export declare const TEXT_FALLBACK_MODEL = ETextGenModels.GOOGLE_GEMINI_3_5_FLASH;
|
|
13
|
+
/** Quota / billing / auth failures need a human (top up, rotate a key) — so
|
|
14
|
+
* they page; anything else (transient 5xx, timeouts) is recovered silently. */
|
|
15
|
+
export declare function isOperatorActionableLlmError(err: unknown): boolean;
|
|
16
|
+
/** Run `params` on its own provider; on failure, retry once on Gemini. If both
|
|
17
|
+
* fail, the PRIMARY error is rethrown (it's the one that explains the outage). */
|
|
18
|
+
export declare function generateTextWithFallback(params: TextGenerationParams, context: string): Promise<TextGenerationResult>;
|
|
19
|
+
//# sourceMappingURL=textFallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textFallback.d.ts","sourceRoot":"","sources":["../../../src/services/aiGen/textFallback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEpF;;;;;;;;GAQG;AAGH,eAAO,MAAM,mBAAmB,yCAAyC,CAAC;AAW1E;+EAC+E;AAC/E,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAUlE;AAkBD;kFACkF;AAClF,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,oBAAoB,CAAC,CAuB/B"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TEXT_FALLBACK_MODEL = void 0;
|
|
4
|
+
exports.isOperatorActionableLlmError = isOperatorActionableLlmError;
|
|
5
|
+
exports.generateTextWithFallback = generateTextWithFallback;
|
|
6
|
+
const aiModels_1 = require("../../globals/aiModels");
|
|
7
|
+
const logger_1 = require("../../utils/logger");
|
|
8
|
+
const aiGenFactory_service_1 = require("./aiGenFactory.service");
|
|
9
|
+
/**
|
|
10
|
+
* Cross-provider fallback for one-shot text generation.
|
|
11
|
+
*
|
|
12
|
+
* 2026-10-23: the OpenAI org ran out of credits ("429 You have no credits
|
|
13
|
+
* remaining") and every caller pinned to gpt-4o-mini — prompt generation,
|
|
14
|
+
* the translation LLM fallback — failed outright for a day. A second
|
|
15
|
+
* provider on a separate account (Gemini, separate billing + key) keeps
|
|
16
|
+
* those features up while the primary account is fixed.
|
|
17
|
+
*/
|
|
18
|
+
// gemini-3.5-flash, not 2.5: newer Google projects (our pool key #1) get
|
|
19
|
+
// "gemini-2.5-flash is no longer available to new users" (checked 2026-10-23).
|
|
20
|
+
exports.TEXT_FALLBACK_MODEL = aiModels_1.ETextGenModels.GOOGLE_GEMINI_3_5_FLASH;
|
|
21
|
+
/** Quota / billing / auth failures need a human (top up, rotate a key) — so
|
|
22
|
+
* they page; anything else (transient 5xx, timeouts) is recovered silently. */
|
|
23
|
+
function isOperatorActionableLlmError(err) {
|
|
24
|
+
const e = (err ?? {});
|
|
25
|
+
const status = e.status ?? e.response?.status;
|
|
26
|
+
if (status === 401 || status === 403)
|
|
27
|
+
return true;
|
|
28
|
+
const code = `${e.code ?? ""} ${e.type ?? ""} ${e.error?.code ?? ""} ${e.error?.type ?? ""}`;
|
|
29
|
+
const msg = e.message ?? "";
|
|
30
|
+
return (/insufficient_quota|billing|authentication_error|invalid_api_key/i.test(code) ||
|
|
31
|
+
/no credits remaining|exceeded your current quota|invalid x-api-key|incorrect api key/i.test(msg));
|
|
32
|
+
}
|
|
33
|
+
/** Gemini has JSON mode but no OpenAI-style strict json_schema, so the schema
|
|
34
|
+
* rides along in the system prompt; callers still Zod-validate the output. */
|
|
35
|
+
function adaptParamsForFallback(params) {
|
|
36
|
+
const schema = params.options?.responseFormat?.json_schema?.schema;
|
|
37
|
+
if (!schema || !Array.isArray(params.input)) {
|
|
38
|
+
return { ...params, modelKey: exports.TEXT_FALLBACK_MODEL };
|
|
39
|
+
}
|
|
40
|
+
const hint = `Respond with a single JSON object that matches this JSON Schema exactly:\n${JSON.stringify(schema)}`;
|
|
41
|
+
const input = params.input;
|
|
42
|
+
const hasSystem = input.some((m) => m.role === "system");
|
|
43
|
+
const adapted = hasSystem
|
|
44
|
+
? input.map((m) => (m.role === "system" && typeof m.content === "string" ? { ...m, content: `${m.content}\n\n${hint}` } : m))
|
|
45
|
+
: [{ role: "system", content: hint }, ...input];
|
|
46
|
+
return { ...params, input: adapted, modelKey: exports.TEXT_FALLBACK_MODEL };
|
|
47
|
+
}
|
|
48
|
+
/** Run `params` on its own provider; on failure, retry once on Gemini. If both
|
|
49
|
+
* fail, the PRIMARY error is rethrown (it's the one that explains the outage). */
|
|
50
|
+
async function generateTextWithFallback(params, context) {
|
|
51
|
+
try {
|
|
52
|
+
return await (0, aiGenFactory_service_1.getAiGenProviderService)(params.modelKey).generateText(params);
|
|
53
|
+
}
|
|
54
|
+
catch (primaryErr) {
|
|
55
|
+
if (params.modelKey === exports.TEXT_FALLBACK_MODEL)
|
|
56
|
+
throw primaryErr;
|
|
57
|
+
const logFn = isOperatorActionableLlmError(primaryErr) ? logger_1.logger.error.bind(logger_1.logger) : logger_1.logger.warn.bind(logger_1.logger);
|
|
58
|
+
logFn("Text LLM primary failed — retrying on fallback provider", {
|
|
59
|
+
context,
|
|
60
|
+
primaryModel: params.modelKey,
|
|
61
|
+
fallbackModel: exports.TEXT_FALLBACK_MODEL,
|
|
62
|
+
err: primaryErr?.message ?? String(primaryErr),
|
|
63
|
+
});
|
|
64
|
+
try {
|
|
65
|
+
return await (0, aiGenFactory_service_1.getAiGenProviderService)(exports.TEXT_FALLBACK_MODEL).generateText(adaptParamsForFallback(params));
|
|
66
|
+
}
|
|
67
|
+
catch (fallbackErr) {
|
|
68
|
+
logger_1.logger.warn("Text LLM fallback provider also failed", {
|
|
69
|
+
context,
|
|
70
|
+
fallbackModel: exports.TEXT_FALLBACK_MODEL,
|
|
71
|
+
err: fallbackErr?.message ?? String(fallbackErr),
|
|
72
|
+
});
|
|
73
|
+
throw primaryErr;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IBrandKitModel } from "../models/agent.model";
|
|
2
|
+
import { IOrganizationBrandKitModel } from "../models/organization.model";
|
|
3
|
+
export interface IResolvedBrandKit {
|
|
4
|
+
/** Personal kit with the active org's shared fields laid over it; null when neither exists. */
|
|
5
|
+
brandKit: IBrandKitModel | null;
|
|
6
|
+
/** The org whose team kit was applied, when one was. */
|
|
7
|
+
teamOrgId: string | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Overlay a team kit onto a personal kit. Only the shareable fields
|
|
11
|
+
* (ORG_BRAND_KIT_FIELDS) move; a field the team kit leaves unset falls back
|
|
12
|
+
* to the member's own value, and likeness fields always stay personal.
|
|
13
|
+
*/
|
|
14
|
+
export declare function mergeTeamBrandKit(userId: string, personal: IBrandKitModel | null, team: IOrganizationBrandKitModel | null): IBrandKitModel | null;
|
|
15
|
+
/**
|
|
16
|
+
* The brand kit every brand-aware surface should apply for `userId`: their
|
|
17
|
+
* personal kit, overridden by their ACTIVE org's shared team kit (if they
|
|
18
|
+
* have one and are still a member). Membership is re-checked so a removed
|
|
19
|
+
* member whose `organizationId` hasn't been cleared yet stops inheriting.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveBrandKitForUser(userId: string, organizationId?: string | null): Promise<IResolvedBrandKit>;
|
|
22
|
+
//# sourceMappingURL=brandKit.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brandKit.service.d.ts","sourceRoot":"","sources":["../../src/services/brandKit.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EACL,0BAA0B,EAG3B,MAAM,8BAA8B,CAAC;AAGtC,MAAM,WAAW,iBAAiB;IAChC,+FAA+F;IAC/F,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAC;IAChC,wDAAwD;IACxD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,cAAc,GAAG,IAAI,EAC/B,IAAI,EAAE,0BAA0B,GAAG,IAAI,GACtC,cAAc,GAAG,IAAI,CAevB;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,GAC7B,OAAO,CAAC,iBAAiB,CAAC,CAwB5B"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeTeamBrandKit = mergeTeamBrandKit;
|
|
4
|
+
exports.resolveBrandKitForUser = resolveBrandKitForUser;
|
|
5
|
+
const organization_model_1 = require("../models/organization.model");
|
|
6
|
+
const firestore_service_1 = require("./firestore.service");
|
|
7
|
+
/**
|
|
8
|
+
* Overlay a team kit onto a personal kit. Only the shareable fields
|
|
9
|
+
* (ORG_BRAND_KIT_FIELDS) move; a field the team kit leaves unset falls back
|
|
10
|
+
* to the member's own value, and likeness fields always stay personal.
|
|
11
|
+
*/
|
|
12
|
+
function mergeTeamBrandKit(userId, personal, team) {
|
|
13
|
+
if (!team)
|
|
14
|
+
return personal;
|
|
15
|
+
const base = personal ?? {
|
|
16
|
+
userId,
|
|
17
|
+
createdAt: team.createdAt,
|
|
18
|
+
updatedAt: team.updatedAt,
|
|
19
|
+
};
|
|
20
|
+
const merged = { ...base };
|
|
21
|
+
for (const field of organization_model_1.ORG_BRAND_KIT_FIELDS) {
|
|
22
|
+
const value = team[field];
|
|
23
|
+
if (value === undefined || value === null || value === "")
|
|
24
|
+
continue;
|
|
25
|
+
if (Array.isArray(value) && value.length === 0)
|
|
26
|
+
continue;
|
|
27
|
+
merged[field] = value;
|
|
28
|
+
}
|
|
29
|
+
return merged;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The brand kit every brand-aware surface should apply for `userId`: their
|
|
33
|
+
* personal kit, overridden by their ACTIVE org's shared team kit (if they
|
|
34
|
+
* have one and are still a member). Membership is re-checked so a removed
|
|
35
|
+
* member whose `organizationId` hasn't been cleared yet stops inheriting.
|
|
36
|
+
*/
|
|
37
|
+
async function resolveBrandKitForUser(userId, organizationId) {
|
|
38
|
+
const personalPromise = firestore_service_1.FirestoreService.brandKitsCol.doc(userId).get();
|
|
39
|
+
let orgId = organizationId;
|
|
40
|
+
if (orgId === undefined) {
|
|
41
|
+
const user = await firestore_service_1.FirestoreService.getDataById(firestore_service_1.FirestoreService.usersCol, userId);
|
|
42
|
+
orgId = user?.organizationId ?? null;
|
|
43
|
+
}
|
|
44
|
+
if (!orgId) {
|
|
45
|
+
const personal = (await personalPromise).data() ?? null;
|
|
46
|
+
return { brandKit: personal, teamOrgId: null };
|
|
47
|
+
}
|
|
48
|
+
const [personalSnap, memberSnap, teamSnap] = await Promise.all([
|
|
49
|
+
personalPromise,
|
|
50
|
+
firestore_service_1.FirestoreService.organizationMembersCol.doc((0, organization_model_1.organizationMemberDocId)(orgId, userId)).get(),
|
|
51
|
+
firestore_service_1.FirestoreService.organizationBrandKitsCol.doc(orgId).get(),
|
|
52
|
+
]);
|
|
53
|
+
const personal = personalSnap.data() ?? null;
|
|
54
|
+
const team = memberSnap.exists ? (teamSnap.data() ?? null) : null;
|
|
55
|
+
return {
|
|
56
|
+
brandKit: mergeTeamBrandKit(userId, personal, team),
|
|
57
|
+
teamOrgId: team ? orgId : null,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Job } from "bullmq";
|
|
2
2
|
import { RedisOptions } from "ioredis";
|
|
3
|
+
export declare class EnqueueTimeoutError extends Error {
|
|
4
|
+
constructor();
|
|
5
|
+
}
|
|
3
6
|
export type JobData = Record<string, any>;
|
|
4
7
|
interface BullMQServiceOptions {
|
|
5
8
|
redisOptions: RedisOptions;
|
|
@@ -89,6 +92,14 @@ declare class BullMQService {
|
|
|
89
92
|
count?: number;
|
|
90
93
|
};
|
|
91
94
|
}): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* After an enqueue timeout, drop the (likely half-open) shared connection so
|
|
97
|
+
* the next call dials a fresh one — and so the stalled command is rejected
|
|
98
|
+
* rather than flushed late. Only in producer-only processes: a worker host
|
|
99
|
+
* shares this connection with its Workers, so tearing it down there would
|
|
100
|
+
* kill job processing; there we just surface the timeout.
|
|
101
|
+
*/
|
|
102
|
+
private resetProducerConnection;
|
|
92
103
|
/** Get (or lazily create) the Queue handle for a name, reusing the cache. */
|
|
93
104
|
private getQueue;
|
|
94
105
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bullmq.service.d.ts","sourceRoot":"","sources":["../../src/services/bullmq.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAgB,EAAwB,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"bullmq.service.d.ts","sourceRoot":"","sources":["../../src/services/bullmq.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAgB,EAAwB,YAAY,EAAE,MAAM,SAAS,CAAC;AAOtE,qBAAa,mBAAoB,SAAQ,KAAK;;CAK7C;AAqBD,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAc1C,UAAU,oBAAoB;IAC5B,YAAY,EAAE,YAAY,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,cAAM,aAAa;IACjB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAgB;IACvC,OAAO,CAAC,MAAM,CAAiC;IAC/C,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,YAAY,CAAgB;IAIpC,OAAO,CAAC,UAAU,CAAC,CAAc;IACjC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,YAAY,CAAS;IAE7B,OAAO;WAQO,WAAW,CAAC,OAAO,EAAE,oBAAoB;IAOvD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,OAAO,CAAC,aAAa;IAOrB;;;;;OAKG;IACU,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvC,sDAAsD;IACzC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBlC;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,oBAAoB;IAQ5B,gBAAgB;IACH,MAAM,CACjB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,OAAO,EACb,IAAI,CAAC,EAAE;QACL,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,0DAA0D;QAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,mDAAmD;QACnD,OAAO,CAAC,EAAE;YAAE,IAAI,EAAE,OAAO,GAAG,aAAa,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;QAC3D;;;;WAIG;QACH,gBAAgB,CAAC,EAAE,MAAM,GAAG;YAAE,GAAG,CAAC,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC7D,YAAY,CAAC,EAAE,MAAM,GAAG;YAAE,GAAG,CAAC,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;KAC1D;IAqCH;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IAc/B,6EAA6E;IAC7E,OAAO,CAAC,QAAQ;IAQhB;;;;;OAKG;IACU,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAUtE,wEAAwE;IAC3D,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CACvD,KAAK,CAAC;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC,CACH;IAgCD,gDAAgD;IACnC,eAAe,IAAI,OAAO,CAAC;QACtC,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IAWK,YAAY,CACjB,UAAU,EAAE,MAAM,EAAE,EACpB,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,EACtC,eAAe,CAAC,EAAE,MAAM,CACtB,MAAM,EACN;QACE,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CACF;CA8JJ;AASD,eAAO,MAAM,MAAM,eAGjB,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,GAAG,CAAC"}
|