vidspotai-shared 1.0.131 → 1.0.133
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 +4 -0
- package/lib/globals/aiModels/enums.d.ts.map +1 -1
- package/lib/globals/aiModels/enums.js +9 -0
- package/lib/globals/aiModels/index.d.ts.map +1 -1
- package/lib/globals/aiModels/index.js +2 -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/types.d.ts +3 -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/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 +13 -4
- package/lib/services/agent/tools/animateImage.tool.js +1 -1
- package/lib/services/agent/tools/generateVideo.tool.js +3 -3
- package/lib/services/aiGen/aiGenFactory.service.d.ts.map +1 -1
- package/lib/services/aiGen/aiGenFactory.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/google.service.d.ts.map +1 -1
- package/lib/services/aiGen/providers/google/google.service.js +9 -1
- 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/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/translation.service.d.ts.map +1 -1
- package/lib/services/translation/translation.service.js +13 -2
- package/lib/utils/errors.d.ts +4 -0
- package/lib/utils/errors.d.ts.map +1 -1
- package/lib/utils/errors.js +6 -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,59 @@
|
|
|
1
|
+
import { FieldValue } from "firebase-admin/firestore";
|
|
2
|
+
import { EImageJobStatus } from "../globals/types";
|
|
3
|
+
import { VideoBgRemovalQuality } from "../globals/videoTools";
|
|
4
|
+
/** Backdrop composited behind the matted subject. Absent = keep transparency. */
|
|
5
|
+
export type VideoToolBackground = {
|
|
6
|
+
kind: "color";
|
|
7
|
+
color: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: "image";
|
|
10
|
+
imageUrl: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "blur";
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Container for the result. Transparent outputs are "webm" (VP9 + alpha —
|
|
16
|
+
* plays in Chrome/Firefox/Edge, imports into most editors) or "mov" (ProRes
|
|
17
|
+
* 4444 + alpha — Final Cut / Premiere / DaVinci). Any output with a
|
|
18
|
+
* `background` is flattened, so it is always an H.264 "mp4".
|
|
19
|
+
*/
|
|
20
|
+
export type VideoToolOutputFormat = "webm" | "mov" | "mp4";
|
|
21
|
+
/**
|
|
22
|
+
* Persistent record for an async video tool job (background removal on a
|
|
23
|
+
* clip). Created by the Cloud Function controller, finalized by the
|
|
24
|
+
* VIDEO_TOOL_JOBS worker. Status values reuse EImageJobStatus so the client
|
|
25
|
+
* normaliser is shared with image jobs.
|
|
26
|
+
*/
|
|
27
|
+
export interface IVideoToolJobModel {
|
|
28
|
+
userId: string;
|
|
29
|
+
tool: "remove-background";
|
|
30
|
+
status: EImageJobStatus;
|
|
31
|
+
inputVideoUrl: string;
|
|
32
|
+
quality: VideoBgRemovalQuality;
|
|
33
|
+
outputFormat: VideoToolOutputFormat;
|
|
34
|
+
background?: VideoToolBackground;
|
|
35
|
+
/** Client-reported duration the upfront estimate was billed on. */
|
|
36
|
+
declaredDurationSec: number;
|
|
37
|
+
sourceMeta?: {
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
durationSec: number;
|
|
41
|
+
hasAudio: boolean;
|
|
42
|
+
};
|
|
43
|
+
providerRequestId?: string;
|
|
44
|
+
/** "matting" → fal is working; "compositing" → our ffmpeg pass. */
|
|
45
|
+
stage?: "probing" | "matting" | "compositing" | "uploading";
|
|
46
|
+
outputVideoUrl?: string;
|
|
47
|
+
outputWidth?: number;
|
|
48
|
+
outputHeight?: number;
|
|
49
|
+
outputDurationSec?: number;
|
|
50
|
+
estimatedCredits?: number;
|
|
51
|
+
totalCreditsUsed?: number;
|
|
52
|
+
errorMessage?: string;
|
|
53
|
+
lastHeartbeatAt?: FieldValue;
|
|
54
|
+
creditReconciliationStatus?: "completed" | "pending";
|
|
55
|
+
creditReconciliationError?: string;
|
|
56
|
+
createdAt: FieldValue;
|
|
57
|
+
updatedAt: FieldValue;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=videoTool.model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"videoTool.model.d.ts","sourceRoot":"","sources":["../../src/models/videoTool.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,iFAAiF;AACjF,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAErB;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,mBAAmB,CAAC;IAC1B,MAAM,EAAE,eAAe,CAAC;IAGxB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,qBAAqB,CAAC;IAC/B,YAAY,EAAE,qBAAqB,CAAC;IACpC,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,mEAAmE;IACnE,mBAAmB,EAAE,MAAM,CAAC;IAG5B,UAAU,CAAC,EAAE;QACX,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,OAAO,CAAC;KACnB,CAAC;IAGF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mEAAmE;IACnE,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,aAAa,GAAG,WAAW,CAAC;IAG5D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAG3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,UAAU,CAAC;IAC7B,0BAA0B,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IACrD,yBAAyB,CAAC,EAAE,MAAM,CAAC;IAEnC,SAAS,EAAE,UAAU,CAAC;IACtB,SAAS,EAAE,UAAU,CAAC;CACvB"}
|
|
@@ -136,7 +136,7 @@ function buildStructuralRulesSection(brief) {
|
|
|
136
136
|
// The catalog above lists each model's "dur:..." constraint — match scene
|
|
137
137
|
// durations to it. Pacing target can still be honoured by varying scene COUNT
|
|
138
138
|
// (e.g. a 10s UGC at fast pacing = 2 scenes × 5s on pixverse, NOT 6 × 1.7s).
|
|
139
|
-
lines.push(" - Provider duration floor: every scene with strategy=ai-image-to-video or ai-text-to-video MUST have durationMs/1000 in its preferredModel's allowed durations (shown as `dur:` in the catalog). Hard universal floor is 2s — no provider accepts sub-2s clips. If a desired scene is shorter than the floor, MERGE it with the next scene instead of generating a too-short clip. For sub-5s scenes, pick from: bytedance-seedance-1.0-pro / -pro-fast (2-12s), runway-gen4.5 / runway-gen4-turbo (2-10s), kling-v3.0 (3-15s), google-
|
|
139
|
+
lines.push(" - Provider duration floor: every scene with strategy=ai-image-to-video or ai-text-to-video MUST have durationMs/1000 in its preferredModel's allowed durations (shown as `dur:` in the catalog). Hard universal floor is 2s — no provider accepts sub-2s clips. If a desired scene is shorter than the floor, MERGE it with the next scene instead of generating a too-short clip. For sub-5s scenes, pick from: bytedance-seedance-1.0-pro / -pro-fast (2-12s), runway-gen4.5 / runway-gen4-turbo (2-10s), kling-v3.0 (3-15s), google-gemini-omni-flash (3-10s). Picking minimax-hailuo for a <6s scene is a HARD ERROR.");
|
|
140
140
|
// AG-28: voiceover-vs-scene duration budget. Without this, the planner
|
|
141
141
|
// picks scene.durationMs based on visual pacing and the TTS that comes
|
|
142
142
|
// out is consistently 1-2s longer per scene → voice clipped mid-sentence.
|
|
@@ -190,7 +190,7 @@ function buildStructuralRulesSection(brief) {
|
|
|
190
190
|
// Only meaningful on ai-image-to-video scenes whose preferredModel is
|
|
191
191
|
// FLF-capable; the executor silently ignores it otherwise, so the rule is
|
|
192
192
|
// additive and safe to skip when no scene needs directed two-anchor motion.
|
|
193
|
-
lines.push(" - First-last-frame (FLF) interpolation: for a scene with strategy=ai-image-to-video where the motion goes between TWO distinct, specific compositions (wide establishing shot → product close-up; closed door → open door; ingredient on counter → finished plated dish; logo small → logo filling frame), set scene.lastFramePrompt to a COMPLETE image prompt describing the END frame. scene.prompt is the START frame; the model interpolates between them for reliable directed motion instead of guessing from a single image + motion words. Rules: (1) lastFramePrompt is a full visual description of the final composition, NOT a motion verb (GOOD: \"extreme close-up of the bottle label, soft studio light\"; BAD: \"zoom into the label\"). (2) Keep subject/lighting/style consistent with scene.prompt so the interpolation reads as one continuous shot — re-state shared identity descriptors verbatim. (3) ONLY set it when preferredModel is FLF-capable: google-
|
|
193
|
+
lines.push(" - First-last-frame (FLF) interpolation: for a scene with strategy=ai-image-to-video where the motion goes between TWO distinct, specific compositions (wide establishing shot → product close-up; closed door → open door; ingredient on counter → finished plated dish; logo small → logo filling frame), set scene.lastFramePrompt to a COMPLETE image prompt describing the END frame. scene.prompt is the START frame; the model interpolates between them for reliable directed motion instead of guessing from a single image + motion words. Rules: (1) lastFramePrompt is a full visual description of the final composition, NOT a motion verb (GOOD: \"extreme close-up of the bottle label, soft studio light\"; BAD: \"zoom into the label\"). (2) Keep subject/lighting/style consistent with scene.prompt so the interpolation reads as one continuous shot — re-state shared identity descriptors verbatim. (3) ONLY set it when preferredModel is FLF-capable: google-gemini-omni-flash, kling-v2.6 / -v2.5-turbo / -v3.0, alibaba-wan (NOT Runway — its models take a first frame only). On any other model it is ignored. (4) Use sparingly — only when a scene genuinely has two anchor compositions; ordinary single-image motion needs no lastFramePrompt. It costs one extra (cheap) image generation per FLF scene.");
|
|
194
194
|
// Camera move as a structured field. The executor sends it to the video
|
|
195
195
|
// model as cameraControl; applyCameraDirection writes it in the syntax that
|
|
196
196
|
// model documents (MiniMax [Pan left] commands, a camera sentence, etc.).
|
|
@@ -214,7 +214,7 @@ function checkSceneDurationCapability(plan) {
|
|
|
214
214
|
return (`AG-15 duration-capability mismatch: ${details}. ` +
|
|
215
215
|
`Fix BY EITHER: (a) merging too-short scenes into a single ≥${offending[0].allowed[0]}s clip so the cut count drops but the total duration stays the same, OR ` +
|
|
216
216
|
`(b) re-picking preferredModel from a provider whose dur: range INCLUDES the scene's duration. ` +
|
|
217
|
-
`Short-duration capable models: bytedance-seedance-1.0-pro-fast (2-12s), bytedance-seedance-1.0-pro (2-12s), runway-gen4.5 (2-10s), kling-v3.0 (3-15s), google-
|
|
217
|
+
`Short-duration capable models: bytedance-seedance-1.0-pro-fast (2-12s), bytedance-seedance-1.0-pro (2-12s), runway-gen4.5 (2-10s), kling-v3.0 (3-15s), google-gemini-omni-flash (3-10s). ` +
|
|
218
218
|
`Do NOT pick minimax-hailuo for any scene shorter than 6s.`);
|
|
219
219
|
}
|
|
220
220
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../../../../src/services/agent/providerFallback/chains.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EACf,eAAe,EACf,aAAa,EAGb,KAAK,cAAc,EACpB,MAAM,2BAA2B,CAAC;AAGnC;;;;;;;;;;;;GAYG;AAGH,eAAO,MAAM,sBAAsB,EAAE,SAAS,eAAe,
|
|
1
|
+
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../../../../src/services/agent/providerFallback/chains.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EACf,eAAe,EACf,aAAa,EAGb,KAAK,cAAc,EACpB,MAAM,2BAA2B,CAAC;AAGnC;;;;;;;;;;;;GAYG;AAGH,eAAO,MAAM,sBAAsB,EAAE,SAAS,eAAe,EAc5D,CAAC;AAKF,eAAO,MAAM,sBAAsB,EAAE,SAAS,eAAe,EAc5D,CAAC;AAQF,eAAO,MAAM,uBAAuB,EAAE,SAAS,eAAe,EAc7D,CAAC;AAKF,eAAO,MAAM,uBAAuB,EAAE,SAAS,eAAe,EAW7D,CAAC;AASF,eAAO,MAAM,kBAAkB,EAAE,SAAS,eAAe,EAIxD,CAAC;AAGF,eAAO,MAAM,WAAW,EAAE,SAAS,eAAe,EAIjD,CAAC;AAGF,eAAO,MAAM,SAAS,EAAE,SAAS,aAAa,EAE7C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,+EAA+E;IAC/E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,wCAAwC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,eAAe,EACtB,GAAG,EAAE,sBAAsB,GAC1B,OAAO,CAyCT;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CASjD;AA6DD;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,eAAe,GAAG,MAAM,GAAG,MAAM,CAI5E;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,SAAS,eAAe,EAAE,EACjC,KAAK,EAAE,eAAe,GACrB,eAAe,EAAE,CAInB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAOtE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,eAAe,EAC5B,aAAa,EAAE,SAAS,eAAe,EAAE,GACxC,eAAe,EAAE,CAMnB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,WAAW,mBAAmB;IAClC,4CAA4C;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,YAAY,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,GAAG,eAAe,EAC/B,WAAW,EAAE,MAAM,EACnB,IAAI,GAAE,mBAAwB,GAC7B,kBAAkB,GAAG,IAAI,CAyB3B"}
|
|
@@ -25,7 +25,9 @@ const helpers_1 = require("../../aiGen/helpers");
|
|
|
25
25
|
*/
|
|
26
26
|
// ── Video: text-to-video, T3 (cinematic) ──────────────────────────────
|
|
27
27
|
exports.T3_TEXT_TO_VIDEO_CHAIN = [
|
|
28
|
-
|
|
28
|
+
// REMOVED FOR v1 — kept for reference: Veo 3.1 shut down by Google 2026-10-22;
|
|
29
|
+
// the key is now a deprecated alias of Gemini Omni Flash (next entry).
|
|
30
|
+
// EVideoGenModels.GOOGLE_VEO_3_1,
|
|
29
31
|
// Gemini Omni Flash: Google's current default video model (GA), 3-10s, ~$0.10/s.
|
|
30
32
|
aiModels_1.EVideoGenModels.GOOGLE_GEMINI_OMNI_FLASH,
|
|
31
33
|
aiModels_1.EVideoGenModels.KLING_V2_6,
|
|
@@ -43,7 +45,10 @@ exports.T3_TEXT_TO_VIDEO_CHAIN = [
|
|
|
43
45
|
exports.T2_TEXT_TO_VIDEO_CHAIN = [
|
|
44
46
|
aiModels_1.EVideoGenModels.BYTEDANCE_SEEDANCE_1_0_PRO_FAST,
|
|
45
47
|
aiModels_1.EVideoGenModels.KLING_V2_5_TURBO,
|
|
46
|
-
|
|
48
|
+
// REMOVED FOR v1 — kept for reference: Veo 3.1 Fast shut down by Google
|
|
49
|
+
// 2026-10-22. Gemini Omni Flash takes its slot (same $0.10/s at 720p).
|
|
50
|
+
// EVideoGenModels.GOOGLE_VEO_3_1_FAST,
|
|
51
|
+
aiModels_1.EVideoGenModels.GOOGLE_GEMINI_OMNI_FLASH,
|
|
47
52
|
aiModels_1.EVideoGenModels.BYTEDANCE_SEEDANCE_1_5_PRO,
|
|
48
53
|
// 2.0 Mini: cheapest 2.x (native audio + refs, up to 15s). Budget tier → T2.
|
|
49
54
|
aiModels_1.EVideoGenModels.BYTEDANCE_SEEDANCE_2_0_MINI,
|
|
@@ -61,7 +66,10 @@ exports.T2_TEXT_TO_VIDEO_CHAIN = [
|
|
|
61
66
|
exports.T2_IMAGE_TO_VIDEO_CHAIN = [
|
|
62
67
|
aiModels_1.EVideoGenModels.BYTEDANCE_SEEDANCE_1_0_PRO_FAST,
|
|
63
68
|
aiModels_1.EVideoGenModels.KLING_V2_5_TURBO,
|
|
64
|
-
|
|
69
|
+
// REMOVED FOR v1 — kept for reference: Veo 3.1 Fast shut down by Google
|
|
70
|
+
// 2026-10-22. Gemini Omni Flash takes its slot (same $0.10/s at 720p).
|
|
71
|
+
// EVideoGenModels.GOOGLE_VEO_3_1_FAST,
|
|
72
|
+
aiModels_1.EVideoGenModels.GOOGLE_GEMINI_OMNI_FLASH,
|
|
65
73
|
aiModels_1.EVideoGenModels.RUNWAY_GEN4_TURBO,
|
|
66
74
|
aiModels_1.EVideoGenModels.BYTEDANCE_SEEDANCE_1_5_PRO,
|
|
67
75
|
// 2.0 Mini: cheapest 2.x I2V (native audio + refs, up to 15s). Budget tier → T2.
|
|
@@ -76,7 +84,8 @@ exports.T2_IMAGE_TO_VIDEO_CHAIN = [
|
|
|
76
84
|
exports.T3_IMAGE_TO_VIDEO_CHAIN = [
|
|
77
85
|
aiModels_1.EVideoGenModels.KLING_V2_6,
|
|
78
86
|
aiModels_1.EVideoGenModels.KLING_V3_0,
|
|
79
|
-
|
|
87
|
+
// REMOVED FOR v1 — kept for reference: Veo 3.1 shut down by Google 2026-10-22.
|
|
88
|
+
// EVideoGenModels.GOOGLE_VEO_3_1,
|
|
80
89
|
aiModels_1.EVideoGenModels.GOOGLE_GEMINI_OMNI_FLASH,
|
|
81
90
|
aiModels_1.EVideoGenModels.RUNWAY_GEN4_5,
|
|
82
91
|
aiModels_1.EVideoGenModels.BYTEDANCE_SEEDANCE_2_5,
|
|
@@ -32,7 +32,7 @@ const InputSchema = zod_1.z.object({
|
|
|
32
32
|
.describe("AG-1: end frame for first-last-frame (FLF) interpolation — animate FROM " +
|
|
33
33
|
"imageUrl (first frame) TO this image (last frame) for directed motion " +
|
|
34
34
|
"between two specific compositions. Only FLF-capable models accept it " +
|
|
35
|
-
"(kling, google-
|
|
35
|
+
"(kling, google-gemini-omni-flash, alibaba-wan); the chain skips " +
|
|
36
36
|
"and falls back on models that don't. Omit for plain single-image motion."),
|
|
37
37
|
cameraControl: videoPlan_schema_1.CameraControlSchema.optional().describe("Camera move (preset like dolly_in / pan_left / orbit_right / static, optional 0..1 intensity). " +
|
|
38
38
|
"Translated per model: MiniMax [Pan left] commands, a camera sentence in the prompt elsewhere."),
|
|
@@ -30,7 +30,7 @@ const InputSchema = zod_1.z.object({
|
|
|
30
30
|
.describe("Detailed motion + visual prompt. Describe subject, camera move, mood, lighting."),
|
|
31
31
|
modelKey: zod_1.z
|
|
32
32
|
.nativeEnum(aiModels_1.EVideoGenModels)
|
|
33
|
-
.describe("Pick by tier: T3 cinematic = google-
|
|
33
|
+
.describe("Pick by tier: T3 cinematic = google-gemini-omni-flash, runway-gen4.5; balanced = kling-v2.6, bytedance-seedance-1.5-pro; cheap fast = minimax-hailuo-2.3-fast, pixverse-v5.6."),
|
|
34
34
|
durationSec: zod_1.z
|
|
35
35
|
.number()
|
|
36
36
|
.int()
|
|
@@ -54,7 +54,7 @@ const InputSchema = zod_1.z.object({
|
|
|
54
54
|
"animates FROM inputImageUrl (first frame) TO this image (last frame), the " +
|
|
55
55
|
"cleanest way to get reliable directed motion between two specific " +
|
|
56
56
|
"compositions. REQUIRES inputImageUrl (the first frame). Only " +
|
|
57
|
-
"FLF-capable models accept it (google-
|
|
57
|
+
"FLF-capable models accept it (google-gemini-omni-flash, kling, alibaba-wan); the capability gate skips models that don't, and the chain " +
|
|
58
58
|
"falls back. Omit for normal single-image animation."),
|
|
59
59
|
audio: zod_1.z.boolean().optional().describe("Whether the model should generate audio."),
|
|
60
60
|
negativePrompt: zod_1.z.string().optional(),
|
|
@@ -65,7 +65,7 @@ const InputSchema = zod_1.z.object({
|
|
|
65
65
|
.max(9)
|
|
66
66
|
.optional()
|
|
67
67
|
.describe("Identity / style reference images (NOT the first frame) — a character or product the clip " +
|
|
68
|
-
"must show. Models that take refs natively (google-
|
|
68
|
+
"must show. Models that take refs natively (google-gemini-omni-flash ≤3, kling-video-o1 / kling-v3-omni-video ≤7) " +
|
|
69
69
|
"are tried first; a fallback without ref support drops them."),
|
|
70
70
|
seed: zod_1.z.number().int().optional(),
|
|
71
71
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiGenFactory.service.d.ts","sourceRoot":"","sources":["../../../src/services/aiGen/aiGenFactory.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EACL,iBAAiB,EAEjB,eAAe,EACf,aAAa,EACb,cAAc,EACd,qBAAqB,EAErB,qBAAqB,EAErB,eAAe,EACf,WAAW,EACZ,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"aiGenFactory.service.d.ts","sourceRoot":"","sources":["../../../src/services/aiGen/aiGenFactory.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EACL,iBAAiB,EAEjB,eAAe,EACf,aAAa,EACb,cAAc,EACd,qBAAqB,EAErB,qBAAqB,EAErB,eAAe,EACf,WAAW,EACZ,MAAM,wBAAwB,CAAC;AAkBhC,KAAK,uBAAuB,GAAG,UAAU,wBAAwB,CAAC;AASlE,eAAO,MAAM,gBAAgB,EAAE,OAAO,CACpC,MAAM,CAAC,eAAe,EAAE,uBAAuB,CAAC,CAiGjD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CACnC,iBAAiB,EACjB,uBAAuB,CA4DxB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CACnC,eAAe,EACf,uBAAuB,CAMxB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CACjC,aAAa,EACb,uBAAuB,CAGxB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,cAAc,EAAE,uBAAuB,CAsBzE,CAAC;AAEJ;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAC1C,qBAAqB,EACrB,uBAAuB,CAGxB,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAC1C,qBAAqB,EACrB,uBAAuB,CAGxB,CAAC;AA6BF,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,qBAAqB,GAC9B,wBAAwB,CAM1B;AAED,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,qBAAqB,GAC9B,wBAAwB,CAM1B;AAED,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,WAAW,GACpB,wBAAwB,CAmB1B"}
|
|
@@ -17,6 +17,7 @@ const bytedance_service_1 = require("./providers/bytedance/bytedance.service");
|
|
|
17
17
|
const elevenlabs_service_1 = require("./providers/elevenlabs/elevenlabs.service");
|
|
18
18
|
const anthropic_service_1 = require("./providers/anthropic/anthropic.service");
|
|
19
19
|
const falUpscale_service_1 = require("./providers/fal/falUpscale.service");
|
|
20
|
+
const falImageTools_service_1 = require("./providers/fal/falImageTools.service");
|
|
20
21
|
const xai_service_1 = require("./providers/xai/xai.service");
|
|
21
22
|
const cdnUrl_1 = require("../../libs/storage/cdnUrl");
|
|
22
23
|
// Partial, intentionally: hosted avatar engines (heygen-avatar, tavus-avatar)
|
|
@@ -172,6 +173,11 @@ exports.imageServicesMap = {
|
|
|
172
173
|
// --- RunwayML Gen-4 Image ---
|
|
173
174
|
[aiModels_1.EImageGenModels.RUNWAYML_GEN4_IMAGE]: runway_service_1.RunwayService,
|
|
174
175
|
[aiModels_1.EImageGenModels.RUNWAYML_GEN4_IMAGE_TURBO]: runway_service_1.RunwayService,
|
|
176
|
+
// --- fal.ai image TOOLS (matting / replace / erase / product staging) ---
|
|
177
|
+
[aiModels_1.EImageGenModels.FAL_BIREFNET_V2]: falImageTools_service_1.FalImageToolsService,
|
|
178
|
+
[aiModels_1.EImageGenModels.FAL_BRIA_BACKGROUND_REPLACE]: falImageTools_service_1.FalImageToolsService,
|
|
179
|
+
[aiModels_1.EImageGenModels.FAL_BRIA_ERASER]: falImageTools_service_1.FalImageToolsService,
|
|
180
|
+
[aiModels_1.EImageGenModels.FAL_BRIA_PRODUCT_SHOT]: falImageTools_service_1.FalImageToolsService,
|
|
175
181
|
};
|
|
176
182
|
/**
|
|
177
183
|
* Music-gen factory. Each provider service implements `generateMusic()` (sync —
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseAiGenProviderService } from "../baseAiGenProvider.service";
|
|
2
|
+
import { CreditUsageParams, ImageGenerationParams, ImageGenerationResult } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* fal.ai photo TOOLS — background removal (BiRefNet v2 alpha matting),
|
|
5
|
+
* background replace, object eraser and product staging (Bria). Registered in
|
|
6
|
+
* imageServicesMap under the `fal-*` EImageGenModels keys, so it rides the
|
|
7
|
+
* existing /v1/image/generate → IMAGE_JOBS worker path (deduct-first billing,
|
|
8
|
+
* refund-on-failure, onSnapshot delivery) instead of a parallel pipeline.
|
|
9
|
+
*
|
|
10
|
+
* Unlike the gpt-image "transparent background" edit this replaces on the
|
|
11
|
+
* /ai-background-remover page, BiRefNet is a segmentation model: it returns
|
|
12
|
+
* the ORIGINAL pixels plus an alpha matte, so the subject is never redrawn.
|
|
13
|
+
*
|
|
14
|
+
* BiRefNet runs on fal's sync route (SYNC_APPS); the Bria tools go through
|
|
15
|
+
* the queue API (submit → poll status → fetch result). Either way the output
|
|
16
|
+
* is re-hosted in our bucket via mediaStorage, so job docs never point at
|
|
17
|
+
* fal's short-lived CDN.
|
|
18
|
+
*/
|
|
19
|
+
export declare class FalImageToolsService extends BaseAiGenProviderService {
|
|
20
|
+
private readonly apiKey;
|
|
21
|
+
constructor();
|
|
22
|
+
private headers;
|
|
23
|
+
/** Map our ImageGenerationParams onto the fal endpoint's input schema. */
|
|
24
|
+
private buildInput;
|
|
25
|
+
generateImage(params: ImageGenerationParams): Promise<ImageGenerationResult>;
|
|
26
|
+
private runSync;
|
|
27
|
+
private submit;
|
|
28
|
+
private waitForResult;
|
|
29
|
+
/**
|
|
30
|
+
* `cost.fixed × outputs`, floored at the model's own `cost.creditFloor` when
|
|
31
|
+
* it declares one (sub-cent matting → MIN_CREDITS_PER_UTILITY_OP, for every
|
|
32
|
+
* plan), otherwise at the caller's floor (paid image floor / standard floor)
|
|
33
|
+
* exactly like every other image provider.
|
|
34
|
+
*/
|
|
35
|
+
getCreditUsed({ modelKey, numImages, creditFloor }: CreditUsageParams): number;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=falImageTools.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"falImageTools.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/fal/falImageTools.service.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAmD3F;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,oBAAqB,SAAQ,wBAAwB;IAChE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;;IAUhC,OAAO,CAAC,OAAO;IAMf,0EAA0E;IAC1E,OAAO,CAAC,UAAU;IA8DZ,aAAa,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAC;YAgDpE,OAAO;YAoCP,MAAM;YAgDN,aAAa;IAqC3B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,QAAQ,EAAE,SAAa,EAAE,WAAW,EAAE,EAAE,iBAAiB,GAAG,MAAM;CAUnF"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FalImageToolsService = void 0;
|
|
4
|
+
const aiModels_1 = require("../../../../globals/aiModels");
|
|
5
|
+
const enums_1 = require("../../../../globals/aiModels/enums");
|
|
6
|
+
const creditUnit_1 = require("../../../../globals/creditUnit");
|
|
7
|
+
const storage_1 = require("../../../../libs/storage");
|
|
8
|
+
const errors_1 = require("../../../../utils/errors");
|
|
9
|
+
const helpers_1 = require("../../../../utils/helpers");
|
|
10
|
+
const logger_1 = require("../../../../utils/logger");
|
|
11
|
+
const transientRetry_1 = require("../../transientRetry");
|
|
12
|
+
const baseAiGenProvider_service_1 = require("../baseAiGenProvider.service");
|
|
13
|
+
const falUpscale_service_1 = require("./falUpscale.service");
|
|
14
|
+
const QUEUE_BASE_URL = "https://queue.fal.run";
|
|
15
|
+
const SYNC_BASE_URL = "https://fal.run";
|
|
16
|
+
/**
|
|
17
|
+
* Apps called on fal's synchronous route instead of the queue. BiRefNet
|
|
18
|
+
* returns in ~1.3 s warm; the queue's submit → poll → fetch round-trips more
|
|
19
|
+
* than double that, and "a cutout in under five seconds" is a product promise.
|
|
20
|
+
*/
|
|
21
|
+
const SYNC_APPS = new Set(["fal-ai/birefnet/v2"]);
|
|
22
|
+
const SYNC_TIMEOUT_MS = 60000;
|
|
23
|
+
const POLL_INTERVAL_MS = 1000;
|
|
24
|
+
/** Matting returns in ~1–3 s and Bria in ~5–20 s; 3 min only bounds a stuck job. */
|
|
25
|
+
const POLL_TIMEOUT_MS = 3 * 60000;
|
|
26
|
+
/** BiRefNet variant + operating resolution per requested quality. */
|
|
27
|
+
const BIREFNET_BY_QUALITY = {
|
|
28
|
+
low: { model: "General Use (Light)", operating_resolution: "1024x1024" },
|
|
29
|
+
medium: { model: "General Use (Heavy)", operating_resolution: "1024x1024" },
|
|
30
|
+
high: { model: "General Use (Dynamic)", operating_resolution: "2304x2304" },
|
|
31
|
+
auto: { model: "General Use (Dynamic)", operating_resolution: "2304x2304" },
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* fal.ai photo TOOLS — background removal (BiRefNet v2 alpha matting),
|
|
35
|
+
* background replace, object eraser and product staging (Bria). Registered in
|
|
36
|
+
* imageServicesMap under the `fal-*` EImageGenModels keys, so it rides the
|
|
37
|
+
* existing /v1/image/generate → IMAGE_JOBS worker path (deduct-first billing,
|
|
38
|
+
* refund-on-failure, onSnapshot delivery) instead of a parallel pipeline.
|
|
39
|
+
*
|
|
40
|
+
* Unlike the gpt-image "transparent background" edit this replaces on the
|
|
41
|
+
* /ai-background-remover page, BiRefNet is a segmentation model: it returns
|
|
42
|
+
* the ORIGINAL pixels plus an alpha matte, so the subject is never redrawn.
|
|
43
|
+
*
|
|
44
|
+
* BiRefNet runs on fal's sync route (SYNC_APPS); the Bria tools go through
|
|
45
|
+
* the queue API (submit → poll status → fetch result). Either way the output
|
|
46
|
+
* is re-hosted in our bucket via mediaStorage, so job docs never point at
|
|
47
|
+
* fal's short-lived CDN.
|
|
48
|
+
*/
|
|
49
|
+
class FalImageToolsService extends baseAiGenProvider_service_1.BaseAiGenProviderService {
|
|
50
|
+
constructor() {
|
|
51
|
+
super();
|
|
52
|
+
if (!process.env.FAL_KEY) {
|
|
53
|
+
throw new Error("Missing FAL_KEY in environment variables");
|
|
54
|
+
}
|
|
55
|
+
this.apiKey = process.env.FAL_KEY;
|
|
56
|
+
}
|
|
57
|
+
headers(json) {
|
|
58
|
+
const h = { Authorization: `Key ${this.apiKey}` };
|
|
59
|
+
if (json)
|
|
60
|
+
h["Content-Type"] = "application/json";
|
|
61
|
+
return h;
|
|
62
|
+
}
|
|
63
|
+
/** Map our ImageGenerationParams onto the fal endpoint's input schema. */
|
|
64
|
+
buildInput(modelKey, params) {
|
|
65
|
+
const imageUrl = params.inputImageUrl ?? params.inputImageUrls?.[0];
|
|
66
|
+
if (!imageUrl) {
|
|
67
|
+
throw new errors_1.UserFacingError("An input image is required for this tool.", errors_1.USER_FACING_ERROR_CODES.CAPABILITY_MISMATCH);
|
|
68
|
+
}
|
|
69
|
+
const prompt = params.prompt?.trim();
|
|
70
|
+
const fullModel = params.quality === "high";
|
|
71
|
+
switch (modelKey) {
|
|
72
|
+
case enums_1.EImageGenModels.FAL_BIREFNET_V2: {
|
|
73
|
+
const variant = BIREFNET_BY_QUALITY[params.quality ?? "high"] ?? BIREFNET_BY_QUALITY.high;
|
|
74
|
+
return {
|
|
75
|
+
image_url: imageUrl,
|
|
76
|
+
...variant,
|
|
77
|
+
refine_foreground: true,
|
|
78
|
+
output_format: params.outputFormat === "webp" ? "webp" : "png",
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
case enums_1.EImageGenModels.FAL_BRIA_BACKGROUND_REPLACE:
|
|
82
|
+
return {
|
|
83
|
+
image_url: imageUrl,
|
|
84
|
+
prompt,
|
|
85
|
+
// A second input image is a style reference for the new background.
|
|
86
|
+
...(params.inputImageUrls?.[1] && { ref_image_url: params.inputImageUrls[1] }),
|
|
87
|
+
...(params.negativePrompt && { negative_prompt: params.negativePrompt }),
|
|
88
|
+
...(params.seed !== undefined && { seed: params.seed }),
|
|
89
|
+
num_images: Math.min(Math.max(params.numImages ?? 1, 1), 4),
|
|
90
|
+
refine_prompt: true,
|
|
91
|
+
fast: !fullModel,
|
|
92
|
+
};
|
|
93
|
+
case enums_1.EImageGenModels.FAL_BRIA_ERASER:
|
|
94
|
+
if (!params.maskImageUrl) {
|
|
95
|
+
throw new errors_1.UserFacingError("Paint over the area to erase first.", errors_1.USER_FACING_ERROR_CODES.CAPABILITY_MISMATCH);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
image_url: imageUrl,
|
|
99
|
+
mask_url: params.maskImageUrl,
|
|
100
|
+
mask_type: "manual",
|
|
101
|
+
preserve_alpha: true,
|
|
102
|
+
};
|
|
103
|
+
case enums_1.EImageGenModels.FAL_BRIA_PRODUCT_SHOT:
|
|
104
|
+
return {
|
|
105
|
+
image_url: imageUrl,
|
|
106
|
+
scene_description: prompt,
|
|
107
|
+
...(params.inputImageUrls?.[1] && { ref_image_url: params.inputImageUrls[1] }),
|
|
108
|
+
// The caller frames the product on its canvas before submitting;
|
|
109
|
+
// "original" keeps that framing instead of Bria re-placing it.
|
|
110
|
+
placement_type: "original",
|
|
111
|
+
original_quality: true,
|
|
112
|
+
num_results: Math.min(Math.max(params.numImages ?? 1, 1), 4),
|
|
113
|
+
optimize_description: true,
|
|
114
|
+
fast: !fullModel,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async generateImage(params) {
|
|
119
|
+
const modelKey = params.modelKey;
|
|
120
|
+
const appId = aiModels_1.aiModelConfigs[modelKey]?.modelId;
|
|
121
|
+
if (!appId) {
|
|
122
|
+
throw new Error(`FalImageToolsService: no model config for "${params.modelKey}"`);
|
|
123
|
+
}
|
|
124
|
+
const input = this.buildInput(modelKey, params);
|
|
125
|
+
let requestId;
|
|
126
|
+
let result;
|
|
127
|
+
if (SYNC_APPS.has(appId)) {
|
|
128
|
+
result = await this.runSync(appId, input);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
const queued = await this.submit(appId, input);
|
|
132
|
+
requestId = queued.requestId;
|
|
133
|
+
result = await this.waitForResult(appId, queued);
|
|
134
|
+
}
|
|
135
|
+
const files = result.images?.length ? result.images : result.image ? [result.image] : [];
|
|
136
|
+
const urls = [];
|
|
137
|
+
const ts = Date.now();
|
|
138
|
+
for (let i = 0; i < files.length; i++) {
|
|
139
|
+
const file = files[i];
|
|
140
|
+
if (!file?.url)
|
|
141
|
+
continue;
|
|
142
|
+
const assetResp = await fetch(file.url);
|
|
143
|
+
if (!assetResp.ok) {
|
|
144
|
+
throw new Error(`Failed to download fal ${appId} output: ${assetResp.status}`);
|
|
145
|
+
}
|
|
146
|
+
const contentType = file.content_type || assetResp.headers.get("content-type") || "image/png";
|
|
147
|
+
const ext = (contentType.split("/")[1] || "png").toLowerCase().replace("jpeg", "jpg");
|
|
148
|
+
const buffer = Buffer.from(await assetResp.arrayBuffer());
|
|
149
|
+
const path = `images/fal/${ts}-${Math.random().toString(36).slice(2, 8)}-${i}.${ext}`;
|
|
150
|
+
// mediaStorage: GCS write + best-effort R2 mirror (zero-egress delivery).
|
|
151
|
+
urls.push(await storage_1.mediaStorage.put(path, buffer, contentType));
|
|
152
|
+
}
|
|
153
|
+
if (!urls.length) {
|
|
154
|
+
throw new Error(`fal ${appId} returned no images`);
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
imageUrl: urls[0],
|
|
158
|
+
imageUrls: urls.length > 1 ? urls : undefined,
|
|
159
|
+
width: files[0]?.width,
|
|
160
|
+
height: files[0]?.height,
|
|
161
|
+
seed: result.seed,
|
|
162
|
+
providerRequestId: requestId,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
async runSync(appId, input) {
|
|
166
|
+
return (0, transientRetry_1.withTransientRetry)(`fal:${appId}:sync`, async () => {
|
|
167
|
+
const resp = await fetch(`${SYNC_BASE_URL}/${appId}`, {
|
|
168
|
+
method: "POST",
|
|
169
|
+
headers: this.headers(true),
|
|
170
|
+
body: JSON.stringify(input),
|
|
171
|
+
signal: AbortSignal.timeout(SYNC_TIMEOUT_MS),
|
|
172
|
+
});
|
|
173
|
+
if (!resp.ok) {
|
|
174
|
+
const body = await resp.text();
|
|
175
|
+
if (resp.status === 422) {
|
|
176
|
+
logger_1.logger.warn("fal image tool rejected input (422)", { appId, body: body.slice(0, 500) });
|
|
177
|
+
throw new errors_1.UserFacingError("This image couldn't be processed. Try a JPG, PNG or WebP under 22MB.", errors_1.USER_FACING_ERROR_CODES.INPUT_IMAGE_REJECTED);
|
|
178
|
+
}
|
|
179
|
+
throw (0, falUpscale_service_1.classifyFalHttpError)(resp.status, body, `${appId}:sync`);
|
|
180
|
+
}
|
|
181
|
+
return (await resp.json());
|
|
182
|
+
}, {
|
|
183
|
+
onRetry: ({ attempt, maxAttempts, backoffMs, err }) => logger_1.logger.warn("fal image tool sync transient error — retrying", {
|
|
184
|
+
appId,
|
|
185
|
+
attempt,
|
|
186
|
+
maxAttempts,
|
|
187
|
+
backoffMs,
|
|
188
|
+
message: err.message,
|
|
189
|
+
}),
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
async submit(appId, input) {
|
|
193
|
+
return (0, transientRetry_1.withTransientRetry)(`fal:${appId}:submit`, async () => {
|
|
194
|
+
const resp = await fetch(`${QUEUE_BASE_URL}/${appId}`, {
|
|
195
|
+
method: "POST",
|
|
196
|
+
headers: this.headers(true),
|
|
197
|
+
body: JSON.stringify(input),
|
|
198
|
+
});
|
|
199
|
+
if (!resp.ok) {
|
|
200
|
+
const body = await resp.text();
|
|
201
|
+
if (resp.status === 422) {
|
|
202
|
+
logger_1.logger.warn("fal image tool rejected input (422)", { appId, body: body.slice(0, 500) });
|
|
203
|
+
// fal validation failure — almost always an unreadable / unsupported
|
|
204
|
+
// input image. Deterministic, so surface it instead of retrying.
|
|
205
|
+
throw new errors_1.UserFacingError("This image couldn't be processed. Try a JPG, PNG or WebP under 22MB.", errors_1.USER_FACING_ERROR_CODES.INPUT_IMAGE_REJECTED);
|
|
206
|
+
}
|
|
207
|
+
throw (0, falUpscale_service_1.classifyFalHttpError)(resp.status, body, `${appId}:submit`);
|
|
208
|
+
}
|
|
209
|
+
const data = (await resp.json());
|
|
210
|
+
if (!data.request_id)
|
|
211
|
+
throw new Error(`fal ${appId} did not return a request_id`);
|
|
212
|
+
// Prefer the URLs fal hands back: for nested app ids
|
|
213
|
+
// (`fal-ai/bria/eraser`) the status/result routes drop the sub-path,
|
|
214
|
+
// and fal owns that rule — the fallback mirrors it.
|
|
215
|
+
const [owner, app] = appId.split("/");
|
|
216
|
+
const base = `${QUEUE_BASE_URL}/${owner}/${app}/requests/${data.request_id}`;
|
|
217
|
+
return {
|
|
218
|
+
requestId: data.request_id,
|
|
219
|
+
statusUrl: data.status_url ?? `${base}/status`,
|
|
220
|
+
responseUrl: data.response_url ?? base,
|
|
221
|
+
};
|
|
222
|
+
}, {
|
|
223
|
+
onRetry: ({ attempt, maxAttempts, backoffMs, err }) => logger_1.logger.warn("fal image tool submit transient error — retrying", {
|
|
224
|
+
appId,
|
|
225
|
+
attempt,
|
|
226
|
+
maxAttempts,
|
|
227
|
+
backoffMs,
|
|
228
|
+
message: err.message,
|
|
229
|
+
}),
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
async waitForResult(appId, queued) {
|
|
233
|
+
const deadline = Date.now() + POLL_TIMEOUT_MS;
|
|
234
|
+
while (Date.now() < deadline) {
|
|
235
|
+
const statusResp = await fetch(queued.statusUrl, { headers: this.headers(false) });
|
|
236
|
+
if (!statusResp.ok) {
|
|
237
|
+
throw (0, falUpscale_service_1.classifyFalHttpError)(statusResp.status, await statusResp.text(), `${appId}:status`);
|
|
238
|
+
}
|
|
239
|
+
const status = (await statusResp.json());
|
|
240
|
+
if ((status.status ?? "").toUpperCase() === "COMPLETED") {
|
|
241
|
+
if (status.error)
|
|
242
|
+
throw new Error(`fal ${appId} failed: ${status.error}`);
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
|
|
246
|
+
}
|
|
247
|
+
if (Date.now() >= deadline) {
|
|
248
|
+
throw new errors_1.UserFacingError("The image tool took too long to respond. Your credits were refunded — please try again.", errors_1.USER_FACING_ERROR_CODES.PROVIDER_UNAVAILABLE);
|
|
249
|
+
}
|
|
250
|
+
const resultResp = await fetch(queued.responseUrl, { headers: this.headers(false) });
|
|
251
|
+
if (!resultResp.ok) {
|
|
252
|
+
const body = await resultResp.text();
|
|
253
|
+
if (resultResp.status === 422) {
|
|
254
|
+
logger_1.logger.warn("fal image tool rejected input (422)", { appId, body: body.slice(0, 500) });
|
|
255
|
+
throw new errors_1.UserFacingError("This image couldn't be processed. Try a JPG, PNG or WebP under 22MB.", errors_1.USER_FACING_ERROR_CODES.INPUT_IMAGE_REJECTED);
|
|
256
|
+
}
|
|
257
|
+
throw (0, falUpscale_service_1.classifyFalHttpError)(resultResp.status, body, `${appId}:result`);
|
|
258
|
+
}
|
|
259
|
+
return (await resultResp.json());
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* `cost.fixed × outputs`, floored at the model's own `cost.creditFloor` when
|
|
263
|
+
* it declares one (sub-cent matting → MIN_CREDITS_PER_UTILITY_OP, for every
|
|
264
|
+
* plan), otherwise at the caller's floor (paid image floor / standard floor)
|
|
265
|
+
* exactly like every other image provider.
|
|
266
|
+
*/
|
|
267
|
+
getCreditUsed({ modelKey, numImages = 1, creditFloor }) {
|
|
268
|
+
const cost = aiModels_1.aiModelConfigs[modelKey]?.cost;
|
|
269
|
+
if (cost?.fixed === undefined) {
|
|
270
|
+
logger_1.logger.warn(`fal image tool getCreditUsed: no cost config for "${modelKey}" — fallback`, { modelKey });
|
|
271
|
+
return (0, helpers_1.getCreditsFromCost)(0.04, true, creditFloor ?? creditUnit_1.MIN_CREDITS_PER_IMAGE_OP);
|
|
272
|
+
}
|
|
273
|
+
const outputs = Math.min(Math.max(numImages, 1), 4);
|
|
274
|
+
const floor = typeof cost.creditFloor === "number" ? cost.creditFloor : creditFloor;
|
|
275
|
+
return (0, helpers_1.getCreditsFromCost)(cost.fixed * outputs, true, floor);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
exports.FalImageToolsService = FalImageToolsService;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { BaseAiGenProviderService } from "../baseAiGenProvider.service";
|
|
2
2
|
import { CreditUsageParams, UpscaleImageParams, UpscaleImageStatusResult, UpscaleStatusParams, UpscaleSubmitResult, UpscaleVideoParams, UpscaleVideoStatusResult } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Classify a fal.ai HTTP failure (non-2xx). Same shape as every other
|
|
5
|
+
* provider's classifier (see topaz.service.ts's classifyTopazHttpError) —
|
|
6
|
+
* 401/403 is a deploy/config bug (fail fast, no Slack noise per job), 5xx/429
|
|
7
|
+
* is transient and retried by withTransientRetry, everything else is a real
|
|
8
|
+
* bug worth alerting on. Error body shape per fal docs: {detail, error_type}.
|
|
9
|
+
*/
|
|
10
|
+
export declare function classifyFalHttpError(status: number, body: string, op: string): Error;
|
|
3
11
|
/**
|
|
4
12
|
* fal.ai upscale provider (image + video) — wired in behind the SAME
|
|
5
13
|
* EUpscaleImageModels/EUpscaleVideoModels model keys Topaz used
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"falUpscale.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/fal/falUpscale.service.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,EACzB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"falUpscale.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/fal/falUpscale.service.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,EACzB,MAAM,UAAU,CAAC;AAUlB;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,KAAK,CAWpF;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,iBAAkB,SAAQ,wBAAwB;IAC7D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;;IAUhC,OAAO,CAAC,OAAO;IAUT,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAkCtE,uBAAuB,CAAC,EAC5B,iBAAiB,EACjB,cAAc,EACd,cAAiC,GAClC,EAAE,mBAAmB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAmDpD,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAiCtE,uBAAuB,CAAC,EAC5B,iBAAiB,EACjB,cAAc,EACd,cAAiC,GAClC,EAAE,mBAAmB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IA+C1D;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE,QAAY,EAAE,WAAW,EAAE,EAAE,iBAAiB,GAAG,MAAM;CAiBpG"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FalUpscaleService = void 0;
|
|
4
|
+
exports.classifyFalHttpError = classifyFalHttpError;
|
|
4
5
|
const aiModels_1 = require("../../../../globals/aiModels");
|
|
5
6
|
const creditUnit_1 = require("../../../../globals/creditUnit");
|
|
6
7
|
const storage_1 = require("../../../../libs/storage");
|
|
@@ -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"}
|