@mevdragon/vidfarm-devcli 0.9.0 → 0.10.0
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/README.md +19 -1
- package/SKILL.director.md +57 -0
- package/SKILL.platform.md +13 -1
- package/dist/src/account-pages-legacy.js +15 -10
- package/dist/src/app.js +531 -183
- package/dist/src/cli.js +10 -4
- package/dist/src/config.js +5 -0
- package/dist/src/devcli/clips.js +312 -49
- package/dist/src/editor-chat.js +1 -1
- package/dist/src/frontend/homepage-view.js +0 -5
- package/dist/src/page-shell.js +47 -0
- package/dist/src/primitive-registry.js +7 -0
- package/dist/src/services/billing.js +3 -0
- package/dist/src/services/clip-curation/ffmpeg.js +59 -17
- package/dist/src/services/clip-curation/gemini.js +72 -23
- package/dist/src/services/clip-curation/hunt.js +332 -0
- package/dist/src/services/clip-curation/index.js +3 -1
- package/dist/src/services/clip-curation/local-agent.js +247 -0
- package/dist/src/services/clip-curation/refine.js +7 -29
- package/dist/src/services/clip-curation/scan.js +37 -10
- package/dist/src/services/serverless-records.js +9 -2
- package/dist/src/services/storage.js +16 -1
- package/package.json +1 -1
- package/public/assets/homepage-client-app.js +17 -17
package/dist/src/app.js
CHANGED
|
@@ -45,10 +45,10 @@ import { ServerlessProviderKeyService } from "./services/serverless-provider-key
|
|
|
45
45
|
import { ServerlessTemplateConfigService } from "./services/serverless-template-configs.js";
|
|
46
46
|
import { parseHTML } from "linkedom";
|
|
47
47
|
import { joinStorageKey, StorageService } from "./services/storage.js";
|
|
48
|
-
import { SFNClient, StartExecutionCommand } from "@aws-sdk/client-sfn";
|
|
48
|
+
import { DescribeExecutionCommand, SFNClient, StartExecutionCommand } from "@aws-sdk/client-sfn";
|
|
49
49
|
import { clipRecords, makeUserPreset } from "./services/clip-records.js";
|
|
50
50
|
import { matchScenesToClips, searchUserClips } from "./services/clip-search.js";
|
|
51
|
-
import { BUILTIN_PRESETS, ClipModelClient, estimateScanCostFromDuration } from "./services/clip-curation/index.js";
|
|
51
|
+
import { BUILTIN_PRESETS, ClipModelClient, effectiveHuntDurationSec, estimateScanCostFromDuration, normalizeHuntSpec, parseClipHuntPrompt, resolveDurationBand } from "./services/clip-curation/index.js";
|
|
52
52
|
import { analyzeCastMembers, annotateScenesFromSource, buildSmartDecomposedHtml, HyperframesService, smartDecomposeVideo, stampCompositionIdentity } from "./services/hyperframes.js";
|
|
53
53
|
import { buildPendingSceneAnnotationsState } from "./services/scene-annotations.js";
|
|
54
54
|
import { createPrimitiveJobContext } from "./primitive-context.js";
|
|
@@ -59,7 +59,8 @@ import { hasUpstreamKey, isUpstreamEnabled, proxyRequestToUpstream, seedFromUpst
|
|
|
59
59
|
import { TemplateSourceService } from "./services/template-sources.js";
|
|
60
60
|
import { TemplateSourceAlreadyRegisteredError } from "./services/template-sources.js";
|
|
61
61
|
import { renderCustomInpaintPage } from "./template-editor-pages.js";
|
|
62
|
-
import {
|
|
62
|
+
import { TEMPLATE_EDITOR_SHELL_STYLES } from "./template-editor-shell.js";
|
|
63
|
+
import { escapeAttribute, escapeHtml, escapeJsonForHtml, renderBrandLockup, renderPageShell, renderPrimaryNav } from "./page-shell.js";
|
|
63
64
|
import { renderReadyPostScheduleData, renderReadyPostScheduleModal, renderReadyPostScheduleScript, renderReadyPostScheduleStyles } from "./ready-post-schedule-component.js";
|
|
64
65
|
const auth = new AuthService();
|
|
65
66
|
const billing = new BillingService();
|
|
@@ -81,6 +82,11 @@ const INSPIRATIONS_PREFIX = `${API_PREFIX}/inspirations`;
|
|
|
81
82
|
const VIDEOS_PREFIX = `${API_PREFIX}/videos`;
|
|
82
83
|
const PRIMITIVES_PREFIX = `${API_PREFIX}/primitives`;
|
|
83
84
|
const CLIPS_PREFIX = "/clips";
|
|
85
|
+
// Temp folder ("My Files → temporary") hard-TTL. Keep in sync with the
|
|
86
|
+
// tag-scoped S3 lifecycle rule (30 days) in the CDK stacks and the clip-scan
|
|
87
|
+
// Lambda's TEMP_SOURCE_TTL_DAYS — records, sweeps, and object lifecycle must
|
|
88
|
+
// agree or users see phantom files (record without object) or orphans.
|
|
89
|
+
const TEMP_FILE_TTL_DAYS = 30;
|
|
84
90
|
const APPROVED_POSTS_PREFIX = `${API_PREFIX}/approved/posts`;
|
|
85
91
|
const APPROVED_POSTS_PUBLIC_PREFIX = "/approved/posts";
|
|
86
92
|
const ACCOUNT_FRONTEND_PREFIX = "/u/:userId";
|
|
@@ -3174,6 +3180,40 @@ async function buildChatBrainstormEditorChatBoot(input) {
|
|
|
3174
3180
|
}
|
|
3175
3181
|
};
|
|
3176
3182
|
}
|
|
3183
|
+
async function buildClipsEditorChatBoot(input) {
|
|
3184
|
+
const directorSkill = readRootSkillFile("SKILL.director.md", "SKILL.user.md") || null;
|
|
3185
|
+
const availableProviders = (await normalizeEditorChatProviderRows(input.customer.id)).map((entry) => entry.provider);
|
|
3186
|
+
const docsRoutes = [
|
|
3187
|
+
{ method: "GET", path: `${CLIPS_PREFIX}/feed`, summary: "List the caller's reusable clip library (optional ?q, ?source, ?limit)." },
|
|
3188
|
+
{ method: "POST", path: `${CLIPS_PREFIX}/search`, summary: "Hybrid structured + semantic clip search. Body is { query } (natural language) or { criteria } (structured filter)." },
|
|
3189
|
+
{ method: "POST", path: `${CLIPS_PREFIX}/scan`, summary: "Import a source video and mine it into clips. Body accepts source_url (a public/durable video URL), raw_s3_uri, or s3_key, plus an optional prompt describing which scenes to keep (e.g. 'people with food, no on-screen text, vertical, 5-10s')." },
|
|
3190
|
+
{ method: "GET", path: `${CLIPS_PREFIX}/scan/:scanId`, summary: "Poll clip-scan status for an in-progress import." },
|
|
3191
|
+
{ method: "GET", path: `${CLIPS_PREFIX}/presets`, summary: "List the caller's saved clip-search presets." }
|
|
3192
|
+
];
|
|
3193
|
+
return {
|
|
3194
|
+
apiUrl: resolveEditorChatApiUrl(),
|
|
3195
|
+
threadsUrl: `${API_PREFIX}/editor-chat/threads`,
|
|
3196
|
+
vidfarmApiKey: await getVisibleApiKey(input.customer.id),
|
|
3197
|
+
cachedContext: {
|
|
3198
|
+
directorSkill,
|
|
3199
|
+
templateSkill: null,
|
|
3200
|
+
availableProviders,
|
|
3201
|
+
currentTemplateConfig: null
|
|
3202
|
+
},
|
|
3203
|
+
template: {
|
|
3204
|
+
page: "docs",
|
|
3205
|
+
tracerId: null,
|
|
3206
|
+
tracers: [],
|
|
3207
|
+
defaultRequestTracer: null,
|
|
3208
|
+
activeTracer: null,
|
|
3209
|
+
templateId: "chat-brainstorm",
|
|
3210
|
+
templateSlug: "clip-curator",
|
|
3211
|
+
templateTitle: "Clip curator",
|
|
3212
|
+
templateDescription: "Search your reusable clip library and import new source videos to mine into clips.",
|
|
3213
|
+
docsRoutes
|
|
3214
|
+
}
|
|
3215
|
+
};
|
|
3216
|
+
}
|
|
3177
3217
|
function resolveEditorChatApiUrl() {
|
|
3178
3218
|
return config.PUBLIC_EDITOR_CHAT_URL?.trim() || `${API_PREFIX}/editor-chat`;
|
|
3179
3219
|
}
|
|
@@ -3504,7 +3544,15 @@ function normalizeEditorChatPath(input) {
|
|
|
3504
3544
|
// advances the job so the copilot must be explicit about wanting it, but it
|
|
3505
3545
|
// lives under the same prefix and is protected by its own auth guard, which
|
|
3506
3546
|
// is fine.
|
|
3507
|
-
COMPOSITIONS_PREFIX
|
|
3547
|
+
COMPOSITIONS_PREFIX,
|
|
3548
|
+
// Clip hunting (long-form → short-form): search/feed the caller's clip
|
|
3549
|
+
// library, start a scan (POST /clips/scan with source_url|s3_key|
|
|
3550
|
+
// temp_file_id + prompt/ranges/duration/aspect), and poll its status. The
|
|
3551
|
+
// scan route is wallet-gated + billed for AWS compute only (BYOK AI keys),
|
|
3552
|
+
// and NEVER runs GhostCut on the long-form source — "no text" is a
|
|
3553
|
+
// scene-selection filter; caption removal stays a per-finished-clip
|
|
3554
|
+
// primitive (/api/v1/primitives/videos/remove-captions).
|
|
3555
|
+
CLIPS_PREFIX
|
|
3508
3556
|
];
|
|
3509
3557
|
const parsed = trimmed.startsWith("http://") || trimmed.startsWith("https://")
|
|
3510
3558
|
? new URL(trimmed)
|
|
@@ -3634,7 +3682,7 @@ function normalizeOperationRequestTracer(tracer) {
|
|
|
3634
3682
|
}
|
|
3635
3683
|
function createTemplateHttpTool(input) {
|
|
3636
3684
|
return tool({
|
|
3637
|
-
description: "Call exactly one Vidfarm REST API route and inspect the response before deciding the next call. Use template routes for metadata, skill, config, operations, jobs, logs, and cancel routes. Use primitive routes under /api/v1/primitives for reusable image generation, image editing, inpainting, still rendering, social/media video download, AI video generation, video slide rendering, burned-in caption removal, video trim/extract/probe/mute/concat operations, audio trim/probe/concat/normalize operations, brainstorm strategy routes, and primitive job inspection; these primitive routes are allowed directly from editor chat even when they are not specific to the current template. Primitive POST bodies must use { tracer, payload: { ...primitive fields... }, webhook_url? }; do not put prompt, source_image_url, instruction, slides, html, or other primitive fields at the top level. Never say primitive image generation, image edit, inpaint, HTML render, video download, AI video generation, caption removal, trim, probe, extract-audio, concat, mute, video render, or brainstorm routes are unavailable here when the route exists. If the user asks to generate a new image similar to an attachment, call POST /api/v1/primitives/images/generate with body { tracer, payload: { prompt, prompt_attachments: [exact attachment URL] } }. If the user asks to revise the attached image itself, call POST /api/v1/primitives/images/edit with body { tracer, payload: { source_image_url, instruction } }. If the user asks to download a social/media post into a durable MP4, call POST /api/v1/primitives/videos/download with body { tracer, payload: { source_url|video_url|url, quality?: \"best\"|\"hd\"|\"full_hd\" } }. If the user asks to generate a new AI video, call POST /api/v1/primitives/videos/generate with body { tracer, payload: { prompt, provider?: \"openai\"|\"gemini\"|\"openrouter\", duration?: seconds, input_references?: [direct image asset URL], frame_images?: [{ image_url, frame_type }] } }; never send webpage or social post URLs in input_references. duration is seconds, not milliseconds, and duration_ms belongs only to /videos/render-slides slides. Default video models are openai/sora-2, gemini/veo-3.0-generate-001, and openrouter/bytedance/seedance-2.0. Use POST /api/v1/primitives/videos/render-slides only to assemble existing media URLs into an MP4 slideshow. Use POST /api/v1/primitives/media/dedupe to apply subtle dedupe transforms (zoom/tilt/rotate/saturation/speed/horizontal_flip/contrast/brightness/hue_rotate/blur/tint) to any image or video URL, with body { tracer, payload: { source_media_url, media_type?, effects?, tint_color?, tint_opacity?, width?, height?, duration_ms?, object_fit?, background_color?, output_format? }, webhook_url? }. Use POST /api/v1/primitives/videos/trim for clipping, /videos/extract-audio for demuxing, /videos/probe or /audio/probe for metadata-only JSON outputs, /videos/extract-frame for stills, /videos/mute to remove audio, /videos/replace-audio to swap tracks, /videos/concat for sequential muted MP4 joins, /audio/trim for clipped audio, /audio/concat for stitched audio, and /audio/normalize for leveled/re-encoded audio. If the user asks to remove burned-in captions, subtitles, or on-screen text from a video, call POST /api/v1/primitives/videos/remove-captions with body { tracer, payload: { source_video_url } } — an async job that returns a durable caption-free MP4 and bills about $0.10 per 30 seconds of source video. If the user explicitly asks for hooks, angles, awareness-stage advice, or a cold-start strategy questionnaire, call the matching brainstorm route immediately instead of brainstorming in chat from memory. Use POST /api/v1/primitives/brainstorm/coldstart when the customer is starting from zero, /brainstorm/awareness_stages when they do not know what ad types to make, /brainstorm/angles when they want persuasive angles, and /brainstorm/hooks when they want many openings. Product placement is a first-class brainstorm primitive like angles and hooks: when the user wants to identify product-placement opportunities in a video or repurpose a video into a native ad for their product, call POST /api/v1/primitives/brainstorm/product_placement with body { tracer, payload: { source_video_url, offer_description }, webhook_url? } — it watches the video and returns timestamped native placement opportunities and prefers a Gemini key. You may also analyze an attached video directly to answer product-placement questions conversationally instead of the primitive when the user just wants a quick take. For brainstorm routes, do not send count by default; only include count when the user explicitly asks for a specific number of hooks, angles, questions, or opportunities. When brainstorm jobs finish and the response includes a JSON artifact, tell the user to open and review that JSON in the chat UI because it contains the structured output. When the user asks for content ideas or says they do not know where to start, prefer the sequence coldstart -> awareness_stages -> angles -> hooks, then use the output to choose templates. For template operation POST bodies, use top-level template_preview_media=\"auto\" by default, \"include\" when the user wants the template to use catalog preview media as references where supported, and \"exclude\" when the user asks not to use preview media as references. Templates decide which generation steps honor that policy. If a POST returns a queued job, do not poll it in this same response; continue with any remaining requested POST calls, then summarize the queued job ids and tracers. If you know a job_id but not the template or primitive, use GET /api/v1/user/me/jobs/:jobId or its /logs and /artifacts subroutes instead of paging through job lists. Use GET /api/v1/compositions/:forkId/remove-video-captions to look up both the original source video URL and the subtitle-removed mirrored URL for the current fork before feeding a video URL into a primitive route; this is a read-only, non-billing status check — never confuse it with POST /remove-video-captions-poll (which advances the fork's decompose-time subtitle-removal job and can bill). Use POST /api/v1/approved/posts with title, caption, pinned_comment, media URLs, and tracer to approve a finished output into a preview/share page. Use POST /api/v1/approved/posts/:postId/schedules with destination_type, destination_id, scheduled_at, timezone, and optional settings/additional_notes to schedule an approved post. When a rendered video was built from slideshow frame images, include both versions in one media array: final MP4 first with kind=\"video\" and role=\"primary\", then every finished captioned slide frame image in order with kind=\"image\" and role=\"slide\". Prefer create-slideshow result.renderVideoInput.slides[].imageUrl or result.slides[].frameImageUrl for carousel media; do not use backgroundImageUrl, manifests, thumbnails, or a partial files array as the full slide set. If the user supplies exact media file URLs for approval, use those URLs as the backup source of truth, preserve their order, infer kind when needed, and assign primary/video and slide/image roles correctly. If the user asks for N distinct generated outputs, make N sequential POST calls rather than one combined POST and do not stop after the first queued job.",
|
|
3685
|
+
description: "Call exactly one Vidfarm REST API route and inspect the response before deciding the next call. Use template routes for metadata, skill, config, operations, jobs, logs, and cancel routes. Use primitive routes under /api/v1/primitives for reusable image generation, image editing, inpainting, still rendering, social/media video download, AI video generation, video slide rendering, burned-in caption removal, video trim/extract/probe/mute/concat operations, audio trim/probe/concat/normalize operations, brainstorm strategy routes, and primitive job inspection; these primitive routes are allowed directly from editor chat even when they are not specific to the current template. Primitive POST bodies must use { tracer, payload: { ...primitive fields... }, webhook_url? }; do not put prompt, source_image_url, instruction, slides, html, or other primitive fields at the top level. Never say primitive image generation, image edit, inpaint, HTML render, video download, AI video generation, caption removal, trim, probe, extract-audio, concat, mute, video render, or brainstorm routes are unavailable here when the route exists. If the user asks to generate a new image similar to an attachment, call POST /api/v1/primitives/images/generate with body { tracer, payload: { prompt, prompt_attachments: [exact attachment URL] } }. If the user asks to revise the attached image itself, call POST /api/v1/primitives/images/edit with body { tracer, payload: { source_image_url, instruction } }. If the user asks to download a social/media post into a durable MP4, call POST /api/v1/primitives/videos/download with body { tracer, payload: { source_url|video_url|url, quality?: \"best\"|\"hd\"|\"full_hd\" } }. If the user asks to generate a new AI video, call POST /api/v1/primitives/videos/generate with body { tracer, payload: { prompt, provider?: \"openai\"|\"gemini\"|\"openrouter\", duration?: seconds, input_references?: [direct image asset URL], frame_images?: [{ image_url, frame_type }] } }; never send webpage or social post URLs in input_references. duration is seconds, not milliseconds, and duration_ms belongs only to /videos/render-slides slides. Default video models are openai/sora-2, gemini/veo-3.0-generate-001, and openrouter/bytedance/seedance-2.0. Use POST /api/v1/primitives/videos/render-slides only to assemble existing media URLs into an MP4 slideshow. Use POST /api/v1/primitives/media/dedupe to apply subtle dedupe transforms (zoom/tilt/rotate/saturation/speed/horizontal_flip/contrast/brightness/hue_rotate/blur/tint) to any image or video URL, with body { tracer, payload: { source_media_url, media_type?, effects?, tint_color?, tint_opacity?, width?, height?, duration_ms?, object_fit?, background_color?, output_format? }, webhook_url? }. Use POST /api/v1/primitives/videos/trim for clipping, /videos/extract-audio for demuxing, /videos/probe or /audio/probe for metadata-only JSON outputs, /videos/extract-frame for stills, /videos/mute to remove audio, /videos/replace-audio to swap tracks, /videos/concat for sequential muted MP4 joins, /audio/trim for clipped audio, /audio/concat for stitched audio, and /audio/normalize for leveled/re-encoded audio. If the user asks to remove burned-in captions, subtitles, or on-screen text from a video, call POST /api/v1/primitives/videos/remove-captions with body { tracer, payload: { source_video_url } } — an async job that returns a durable caption-free MP4 and bills about $0.10 per 30 seconds of source video. Caption removal is capped at ~15 minutes of source and must NEVER be used on long-form video: when the user wants short clips out of a long video (a podcast, stream VOD, webinar, or any YouTube/TikTok/IG/X URL), call POST /clips/scan instead with body { source_url | temp_file_id | s3_key, prompt, ranges?: [\"MM:SS-MM:SS\"], target_duration_sec?, aspect?: \"9:16\"|\"16:9\"|\"4:3\"|\"1:1\", avoid_text?, tracer? } — target_duration_sec is a SOFT range (30 → 20-40s), ranges restrict the hunt to those source windows (big cost saver on long videos), aspect crops every clip, and avoid_text prefers scenes WITHOUT on-screen text via scene SELECTION (never caption removal on the source). The hunt is async: it returns scan_id immediately; poll GET /clips/scan/:scanId, then browse results via GET /clips/feed?source=<source_video_id> or POST /clips/search. Hunts bill AWS compute only — the AI tagging runs on the user's own saved provider keys. To remove captions from a finished HUNTED clip, pass that clip's short mp4 to /videos/remove-captions afterwards. If the user explicitly asks for hooks, angles, awareness-stage advice, or a cold-start strategy questionnaire, call the matching brainstorm route immediately instead of brainstorming in chat from memory. Use POST /api/v1/primitives/brainstorm/coldstart when the customer is starting from zero, /brainstorm/awareness_stages when they do not know what ad types to make, /brainstorm/angles when they want persuasive angles, and /brainstorm/hooks when they want many openings. Product placement is a first-class brainstorm primitive like angles and hooks: when the user wants to identify product-placement opportunities in a video or repurpose a video into a native ad for their product, call POST /api/v1/primitives/brainstorm/product_placement with body { tracer, payload: { source_video_url, offer_description }, webhook_url? } — it watches the video and returns timestamped native placement opportunities and prefers a Gemini key. You may also analyze an attached video directly to answer product-placement questions conversationally instead of the primitive when the user just wants a quick take. For brainstorm routes, do not send count by default; only include count when the user explicitly asks for a specific number of hooks, angles, questions, or opportunities. When brainstorm jobs finish and the response includes a JSON artifact, tell the user to open and review that JSON in the chat UI because it contains the structured output. When the user asks for content ideas or says they do not know where to start, prefer the sequence coldstart -> awareness_stages -> angles -> hooks, then use the output to choose templates. For template operation POST bodies, use top-level template_preview_media=\"auto\" by default, \"include\" when the user wants the template to use catalog preview media as references where supported, and \"exclude\" when the user asks not to use preview media as references. Templates decide which generation steps honor that policy. If a POST returns a queued job, do not poll it in this same response; continue with any remaining requested POST calls, then summarize the queued job ids and tracers. If you know a job_id but not the template or primitive, use GET /api/v1/user/me/jobs/:jobId or its /logs and /artifacts subroutes instead of paging through job lists. Use GET /api/v1/compositions/:forkId/remove-video-captions to look up both the original source video URL and the subtitle-removed mirrored URL for the current fork before feeding a video URL into a primitive route; this is a read-only, non-billing status check — never confuse it with POST /remove-video-captions-poll (which advances the fork's decompose-time subtitle-removal job and can bill). Use POST /api/v1/approved/posts with title, caption, pinned_comment, media URLs, and tracer to approve a finished output into a preview/share page. Use POST /api/v1/approved/posts/:postId/schedules with destination_type, destination_id, scheduled_at, timezone, and optional settings/additional_notes to schedule an approved post. When a rendered video was built from slideshow frame images, include both versions in one media array: final MP4 first with kind=\"video\" and role=\"primary\", then every finished captioned slide frame image in order with kind=\"image\" and role=\"slide\". Prefer create-slideshow result.renderVideoInput.slides[].imageUrl or result.slides[].frameImageUrl for carousel media; do not use backgroundImageUrl, manifests, thumbnails, or a partial files array as the full slide set. If the user supplies exact media file URLs for approval, use those URLs as the backup source of truth, preserve their order, infer kind when needed, and assign primary/video and slide/image roles correctly. If the user asks for N distinct generated outputs, make N sequential POST calls rather than one combined POST and do not stop after the first queued job.",
|
|
3638
3686
|
inputSchema: z.object({
|
|
3639
3687
|
method: z.enum(["GET", "POST"]).describe("HTTP method to use."),
|
|
3640
3688
|
path: z.string().min(1).describe("Absolute path or same-origin URL for an allowed Vidfarm REST route."),
|
|
@@ -4777,6 +4825,7 @@ app.get(`${ACCOUNT_FRONTEND_PREFIX}/discover`, (c) => redirectToPublicPath(c, "/
|
|
|
4777
4825
|
app.get(`${ACCOUNT_FRONTEND_PREFIX}/help`, (c) => redirectToPublicPath(c, "/help"));
|
|
4778
4826
|
app.get(`${ACCOUNT_FRONTEND_PREFIX}/chat`, (c) => dispatchScopedGetToLegacyRoute(c, "/chat"));
|
|
4779
4827
|
app.get(`${ACCOUNT_FRONTEND_PREFIX}/library`, (c) => dispatchScopedGetToLegacyRoute(c, "/library"));
|
|
4828
|
+
app.get(`${ACCOUNT_FRONTEND_PREFIX}/clips`, (c) => dispatchScopedGetToLegacyRoute(c, "/clips"));
|
|
4780
4829
|
app.get(`${ACCOUNT_FRONTEND_PREFIX}/inpaint`, (c) => dispatchScopedGetToLegacyRoute(c, "/inpaint"));
|
|
4781
4830
|
app.get(`${ACCOUNT_FRONTEND_PREFIX}/calendar`, (c) => dispatchScopedGetToLegacyRoute(c, "/calendar"));
|
|
4782
4831
|
app.get(`${ACCOUNT_FRONTEND_PREFIX}/settings`, (c) => dispatchScopedGetToLegacyRoute(c, "/settings"));
|
|
@@ -14676,7 +14725,9 @@ app.get(`${USER_PREFIX}/me/temporary-files`, async (c) => {
|
|
|
14676
14725
|
return c.json({
|
|
14677
14726
|
files,
|
|
14678
14727
|
folders: Array.from(new Set(folders)).sort(),
|
|
14679
|
-
|
|
14728
|
+
// Temp folder hard-TTLs at 30 days: DynamoDB record TTL + tag-scoped S3
|
|
14729
|
+
// lifecycle + this route's sweep all converge on the same deadline.
|
|
14730
|
+
ttl_days: TEMP_FILE_TTL_DAYS,
|
|
14680
14731
|
max_size_bytes: 100 * 1024 * 1024
|
|
14681
14732
|
});
|
|
14682
14733
|
});
|
|
@@ -14756,6 +14807,10 @@ app.post(`${USER_PREFIX}/me/temporary-files/upload`, async (c) => {
|
|
|
14756
14807
|
const fileId = randomUUID();
|
|
14757
14808
|
const storageKey = storage.userTemporaryFileKey(customer.id, fileId, fileName, folderPath);
|
|
14758
14809
|
await storage.putBuffer(storageKey, buffer, contentType);
|
|
14810
|
+
// The tag drives the bucket's 30-day lifecycle deletion of the original.
|
|
14811
|
+
await storage.putObjectTags(storageKey, { "vidfarm-temp": "1" }).catch((error) => {
|
|
14812
|
+
console.error(`[vidfarm] putObjectTags failed for temporary file key ${storageKey}:`, error);
|
|
14813
|
+
});
|
|
14759
14814
|
await serverlessRecords.createUserTemporaryFile({
|
|
14760
14815
|
id: fileId,
|
|
14761
14816
|
customerId: customer.id,
|
|
@@ -14764,7 +14819,7 @@ app.post(`${USER_PREFIX}/me/temporary-files/upload`, async (c) => {
|
|
|
14764
14819
|
sizeBytes: buffer.byteLength,
|
|
14765
14820
|
storageKey,
|
|
14766
14821
|
folderPath,
|
|
14767
|
-
expiresAt: addSeconds(new Date(),
|
|
14822
|
+
expiresAt: addSeconds(new Date(), TEMP_FILE_TTL_DAYS * 24 * 60 * 60)
|
|
14768
14823
|
});
|
|
14769
14824
|
const saved = await serverlessRecords.getUserTemporaryFile(customer.id, fileId);
|
|
14770
14825
|
if (!saved) {
|
|
@@ -14790,6 +14845,11 @@ app.post(`${USER_PREFIX}/me/temporary-files`, async (c) => {
|
|
|
14790
14845
|
if (!isAllowedAttachment(fileName, contentType)) {
|
|
14791
14846
|
return c.json({ error: `Unsupported temporary file type: ${fileName}` }, 400);
|
|
14792
14847
|
}
|
|
14848
|
+
// Presigned transport: the bytes went straight to S3, so tag server-side at
|
|
14849
|
+
// finalize — the tag drives the bucket's 30-day lifecycle deletion.
|
|
14850
|
+
await storage.putObjectTags(expectedStorageKey, { "vidfarm-temp": "1" }).catch((error) => {
|
|
14851
|
+
console.error(`[vidfarm] putObjectTags failed for temporary file key ${expectedStorageKey}:`, error);
|
|
14852
|
+
});
|
|
14793
14853
|
await serverlessRecords.createUserTemporaryFile({
|
|
14794
14854
|
id: body.file_id,
|
|
14795
14855
|
customerId: customer.id,
|
|
@@ -14798,7 +14858,7 @@ app.post(`${USER_PREFIX}/me/temporary-files`, async (c) => {
|
|
|
14798
14858
|
sizeBytes: body.size_bytes,
|
|
14799
14859
|
storageKey: expectedStorageKey,
|
|
14800
14860
|
folderPath,
|
|
14801
|
-
expiresAt: addSeconds(new Date(),
|
|
14861
|
+
expiresAt: addSeconds(new Date(), TEMP_FILE_TTL_DAYS * 24 * 60 * 60)
|
|
14802
14862
|
});
|
|
14803
14863
|
const saved = await serverlessRecords.getUserTemporaryFile(customer.id, body.file_id);
|
|
14804
14864
|
if (!saved) {
|
|
@@ -15082,179 +15142,347 @@ app.post(`${USER_PREFIX}/me/provider-keys`, async (c) => {
|
|
|
15082
15142
|
// and natural-language→criteria use the caller's saved gemini provider key.
|
|
15083
15143
|
const clipScanSfn = new SFNClient({});
|
|
15084
15144
|
const BUILTIN_CLIP_PRESET_IDS = new Set(BUILTIN_PRESETS.map((p) => p.preset_id));
|
|
15145
|
+
// Pre-scan estimate of the AWS compute the wallet will be billed for a hunt
|
|
15146
|
+
// (Lambda GB-seconds + Step Functions transitions — mirrors the post-hoc
|
|
15147
|
+
// billing in infra/lambda/clip-scan.ts). The BYOK AI spend is estimated
|
|
15148
|
+
// separately (estimateScanCostFromDuration) and is NOT wallet-billed.
|
|
15149
|
+
function estimateClipScanComputeUsd(effectiveDurationSec, targetSceneSec) {
|
|
15150
|
+
const LAMBDA_X86_GB_SECOND_USD = 0.0000166667;
|
|
15151
|
+
const LAMBDA_REQUEST_USD = 0.20 / 1_000_000;
|
|
15152
|
+
const STEP_FUNCTIONS_STANDARD_TRANSITION_USD = 0.000025;
|
|
15153
|
+
const CLIP_SCAN_MEMORY_GB = 3;
|
|
15154
|
+
const avgSceneSec = Math.max(2, targetSceneSec ?? 4);
|
|
15155
|
+
const scenes = Math.max(1, Math.ceil(effectiveDurationSec / avgSceneSec));
|
|
15156
|
+
// probe decodes the windowed footage once; each scene worker extracts +
|
|
15157
|
+
// uploads a clip (dominated by a fixed overhead + a share of re-encode time).
|
|
15158
|
+
const probeSeconds = 15 + effectiveDurationSec * 0.08;
|
|
15159
|
+
const perSceneSeconds = 8 + avgSceneSec * 0.6;
|
|
15160
|
+
const finalizeSeconds = 3;
|
|
15161
|
+
const lambdaSeconds = probeSeconds + scenes * perSceneSeconds + finalizeSeconds;
|
|
15162
|
+
const gbSeconds = lambdaSeconds * CLIP_SCAN_MEMORY_GB;
|
|
15163
|
+
const lambdaUsd = gbSeconds * LAMBDA_X86_GB_SECOND_USD + (scenes + 2) * LAMBDA_REQUEST_USD;
|
|
15164
|
+
const stepFunctionsUsd = (3 + scenes) * STEP_FUNCTIONS_STANDARD_TRANSITION_USD;
|
|
15165
|
+
const baseUsd = Number((lambdaUsd + stepFunctionsUsd).toFixed(6));
|
|
15166
|
+
return {
|
|
15167
|
+
estimated_scenes: scenes,
|
|
15168
|
+
lambda_gb_seconds: Number(gbSeconds.toFixed(1)),
|
|
15169
|
+
aws_compute_usd: baseUsd,
|
|
15170
|
+
// What actually lands on the wallet (platform markup included).
|
|
15171
|
+
estimated_charge_usd: Number(applyMarkupUsd(baseUsd).toFixed(6))
|
|
15172
|
+
};
|
|
15173
|
+
}
|
|
15085
15174
|
// First-class Clips gallery page (served at /clips). Self-contained HTML; the
|
|
15086
15175
|
// client fetches /clips/feed, /clips/presets and /clips/search with the session
|
|
15087
15176
|
// cookie. Standalone browse/search — no video generation required.
|
|
15088
|
-
function renderClipsPage() {
|
|
15089
|
-
|
|
15090
|
-
|
|
15091
|
-
|
|
15092
|
-
|
|
15093
|
-
|
|
15094
|
-
|
|
15095
|
-
|
|
15096
|
-
|
|
15097
|
-
|
|
15098
|
-
|
|
15099
|
-
|
|
15100
|
-
|
|
15101
|
-
|
|
15102
|
-
header.top nav { display:flex; gap:6px; }
|
|
15103
|
-
header.top nav a { padding:6px 12px; border-radius:8px; color:var(--dim); font-weight:600; }
|
|
15104
|
-
header.top nav a.active, header.top nav a:hover { color:var(--text); background:var(--panel2); }
|
|
15105
|
-
.wrap { max-width:1200px; margin:0 auto; padding:28px 24px 80px; }
|
|
15106
|
-
.hero h1 { font-size:26px; margin:0 0 4px; }
|
|
15107
|
-
.hero p { color:var(--dim); margin:0 0 20px; }
|
|
15108
|
-
.searchbar { display:flex; gap:10px; margin-bottom:14px; }
|
|
15109
|
-
.searchbar input { flex:1; background:var(--panel); border:1px solid var(--line); color:var(--text); border-radius:10px; padding:12px 14px; font-size:15px; outline:none; }
|
|
15110
|
-
.searchbar input:focus { border-color:var(--accent); }
|
|
15111
|
-
.searchbar button { background:var(--accent); color:#fff; border:0; border-radius:10px; padding:0 18px; font-weight:700; cursor:pointer; }
|
|
15112
|
-
.presets { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:22px; }
|
|
15113
|
-
.chip { background:var(--panel); border:1px solid var(--line); color:var(--dim); border-radius:999px; padding:6px 13px; font-size:13px; font-weight:600; cursor:pointer; }
|
|
15114
|
-
.chip:hover, .chip.active { color:var(--text); border-color:var(--accent); }
|
|
15115
|
-
.status { color:var(--dim); font-size:14px; margin-bottom:16px; min-height:20px; }
|
|
15116
|
-
.grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(230px,1fr)); gap:18px; }
|
|
15117
|
-
.card { background:var(--panel); border:1px solid var(--line); border-radius:14px; overflow:hidden; display:flex; flex-direction:column; }
|
|
15118
|
-
.card .thumb { position:relative; aspect-ratio:9/16; background:#000; overflow:hidden; }
|
|
15119
|
-
.card .thumb img, .card .thumb video { width:100%; height:100%; object-fit:cover; display:block; }
|
|
15120
|
-
.card .thumb .range { position:absolute; left:8px; bottom:8px; background:rgba(0,0,0,.7); border-radius:6px; padding:2px 7px; font-size:12px; font-variant-numeric:tabular-nums; }
|
|
15121
|
-
.card .thumb .score { position:absolute; right:8px; top:8px; background:rgba(58,214,160,.15); color:var(--accent2); border:1px solid rgba(58,214,160,.4); border-radius:6px; padding:1px 6px; font-size:11px; font-weight:700; }
|
|
15122
|
-
.card .body { padding:11px 12px 12px; display:flex; flex-direction:column; gap:8px; flex:1; }
|
|
15123
|
-
.card .desc { font-size:13px; color:var(--text); display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
|
|
15124
|
-
.card .tags { display:flex; flex-wrap:wrap; gap:5px; }
|
|
15125
|
-
.card .tag { font-size:11px; color:var(--dim); background:var(--panel2); border-radius:5px; padding:1px 6px; }
|
|
15126
|
-
.card .row { display:flex; align-items:center; justify-content:space-between; margin-top:auto; }
|
|
15127
|
-
.card .src { font-size:11px; color:var(--dim); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:60%; }
|
|
15128
|
-
.card a.dl { font-size:12px; font-weight:700; color:var(--accent); }
|
|
15129
|
-
.empty { text-align:center; color:var(--dim); padding:60px 20px; }
|
|
15130
|
-
.empty code { background:var(--panel2); padding:2px 8px; border-radius:6px; color:var(--accent2); }
|
|
15131
|
-
</style>
|
|
15132
|
-
</head>
|
|
15133
|
-
<body>
|
|
15134
|
-
<header class="top">
|
|
15135
|
-
<div class="brand">Vidfarm</div>
|
|
15136
|
-
<nav>
|
|
15137
|
-
<a href="/discover">Discover</a>
|
|
15138
|
-
<a href="/library">Library</a>
|
|
15139
|
-
<a href="/clips" class="active">Clips</a>
|
|
15140
|
-
</nav>
|
|
15141
|
-
</header>
|
|
15142
|
-
<div class="wrap">
|
|
15143
|
-
<div class="hero">
|
|
15144
|
-
<h1>Clips</h1>
|
|
15145
|
-
<p>Your reusable clip library — mined from long-form video, searchable by tag or natural language.</p>
|
|
15146
|
-
</div>
|
|
15147
|
-
<form class="searchbar" id="searchForm">
|
|
15148
|
-
<input id="q" type="search" placeholder="Search clips — e.g. "someone looks confused after reading a message"" autocomplete="off" />
|
|
15149
|
-
<button type="submit">Search</button>
|
|
15150
|
-
</form>
|
|
15151
|
-
<div class="presets" id="presets"></div>
|
|
15152
|
-
<div class="status" id="status">Loading your clips…</div>
|
|
15153
|
-
<div class="grid" id="grid"></div>
|
|
15154
|
-
</div>
|
|
15155
|
-
<script>
|
|
15156
|
-
(function(){
|
|
15157
|
-
var grid = document.getElementById('grid');
|
|
15158
|
-
var statusEl = document.getElementById('status');
|
|
15159
|
-
var presetsEl = document.getElementById('presets');
|
|
15160
|
-
var form = document.getElementById('searchForm');
|
|
15161
|
-
var input = document.getElementById('q');
|
|
15177
|
+
function renderClipsPage(input) {
|
|
15178
|
+
const libraryHref = withAccountQuery("/library", input.currentAccountId);
|
|
15179
|
+
const clipsHref = withAccountQuery("/clips", input.currentAccountId);
|
|
15180
|
+
return renderPageShell({
|
|
15181
|
+
title: "Clips — VidFarm",
|
|
15182
|
+
mainClass: "is-wide",
|
|
15183
|
+
runtimeBoot: {
|
|
15184
|
+
pageKind: "legacy",
|
|
15185
|
+
title: "Clips",
|
|
15186
|
+
userId: input.userId,
|
|
15187
|
+
editorChat: input.editorChat ?? null
|
|
15188
|
+
},
|
|
15189
|
+
style: `
|
|
15190
|
+
${TEMPLATE_EDITOR_SHELL_STYLES}
|
|
15162
15191
|
|
|
15163
|
-
|
|
15164
|
-
|
|
15192
|
+
.clips-frame { padding-left: 432px; }
|
|
15193
|
+
.clips-shell { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 16px; min-height: 0; }
|
|
15194
|
+
.clips-toolbar { display: grid; gap: 12px; }
|
|
15195
|
+
.clips-toolbar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
|
|
15196
|
+
.clips-search { display: flex; gap: 10px; flex: 1 1 320px; min-width: 240px; margin: 0; }
|
|
15197
|
+
.clips-search input { flex: 1; }
|
|
15198
|
+
.clips-search button { flex: 0 0 auto; }
|
|
15199
|
+
.clips-status { min-height: 20px; color: var(--muted); font-size: 0.94rem; }
|
|
15200
|
+
.clips-scroll { min-height: 0; overflow: auto; padding-right: 6px; }
|
|
15201
|
+
.clips-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(216px, 1fr)); gap: 16px; padding-bottom: 24px; }
|
|
15202
|
+
.clip-card {
|
|
15203
|
+
display: flex;
|
|
15204
|
+
flex-direction: column;
|
|
15205
|
+
overflow: hidden;
|
|
15206
|
+
border: 1px solid rgba(255, 255, 255, 0.72);
|
|
15207
|
+
border-radius: var(--radius-sm);
|
|
15208
|
+
background: rgba(255, 252, 247, 0.82);
|
|
15209
|
+
box-shadow: var(--shadow-soft);
|
|
15210
|
+
}
|
|
15211
|
+
.clip-thumb { position: relative; aspect-ratio: 9 / 16; overflow: hidden; background: #12161f; }
|
|
15212
|
+
.clip-thumb img, .clip-thumb video { display: block; width: 100%; height: 100%; object-fit: cover; }
|
|
15213
|
+
.clip-thumb .clip-noimg { display: flex; align-items: center; justify-content: center; height: 100%; color: rgba(255, 255, 255, 0.5); font-size: 0.82rem; }
|
|
15214
|
+
.clip-range {
|
|
15215
|
+
position: absolute; left: 8px; bottom: 8px;
|
|
15216
|
+
padding: 2px 8px; border-radius: 8px;
|
|
15217
|
+
background: rgba(20, 22, 30, 0.72); color: #f4efe6;
|
|
15218
|
+
font-size: 12px; font-variant-numeric: tabular-nums;
|
|
15219
|
+
}
|
|
15220
|
+
.clip-score {
|
|
15221
|
+
position: absolute; right: 8px; top: 8px;
|
|
15222
|
+
padding: 1px 7px; border-radius: 8px;
|
|
15223
|
+
background: rgba(36, 48, 65, 0.92); color: #f3e8cd;
|
|
15224
|
+
font-size: 11px; font-weight: 800;
|
|
15225
|
+
}
|
|
15226
|
+
.clip-body { display: flex; flex-direction: column; gap: 8px; flex: 1; padding: 12px; }
|
|
15227
|
+
.clip-desc { color: var(--ink); font-size: 0.9rem; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
|
|
15228
|
+
.clip-tags { display: flex; flex-wrap: wrap; gap: 5px; }
|
|
15229
|
+
.clip-tag { padding: 2px 7px; border-radius: 6px; background: rgba(244, 236, 223, 0.86); color: #6f7d95; font-size: 11px; }
|
|
15230
|
+
.clip-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
|
|
15231
|
+
.clip-src { max-width: 58%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }
|
|
15232
|
+
.clip-dl { color: #b4823a; font-size: 12px; font-weight: 800; text-decoration: none; }
|
|
15233
|
+
.clip-dl:hover { text-decoration: underline; }
|
|
15234
|
+
.clips-empty { grid-column: 1 / -1; display: grid; place-items: center; min-height: 320px; padding: 48px 20px; text-align: center; color: var(--muted); font-size: 1.05rem; line-height: 1.7; }
|
|
15165
15235
|
|
|
15166
|
-
|
|
15167
|
-
|
|
15168
|
-
|
|
15169
|
-
|
|
15170
|
-
|
|
15171
|
-
|
|
15172
|
-
|
|
15236
|
+
.clips-import-dialog {
|
|
15237
|
+
width: min(30rem, calc(100vw - 1.5rem));
|
|
15238
|
+
padding: 0;
|
|
15239
|
+
border: 1px solid rgba(191, 164, 109, 0.4);
|
|
15240
|
+
border-radius: 26px;
|
|
15241
|
+
background: rgba(255, 252, 247, 0.99);
|
|
15242
|
+
box-shadow: 0 28px 72px rgba(37, 45, 61, 0.22);
|
|
15243
|
+
}
|
|
15244
|
+
.clips-import-dialog::backdrop { background: rgba(31, 38, 53, 0.32); backdrop-filter: blur(6px); }
|
|
15245
|
+
.clips-import-form { display: grid; gap: 14px; margin: 0; padding: 22px 22px 20px; }
|
|
15246
|
+
.clips-import-head { display: grid; gap: 6px; }
|
|
15247
|
+
.clips-import-head h3 { font-size: 1.5rem; letter-spacing: -0.03em; }
|
|
15248
|
+
.clips-import-head p { font-size: 0.9rem; }
|
|
15249
|
+
.clips-import-field { display: grid; gap: 6px; }
|
|
15250
|
+
.clips-import-field textarea { min-height: 96px; border-radius: 18px; }
|
|
15251
|
+
.clips-import-note { min-height: 18px; font-size: 0.85rem; color: var(--muted); }
|
|
15252
|
+
.clips-import-note[data-tone="error"] { color: #9f3d3d; }
|
|
15253
|
+
.clips-import-note[data-tone="success"] { color: #3f7d55; }
|
|
15254
|
+
.clips-import-actions { display: flex; justify-content: flex-end; gap: 10px; }
|
|
15173
15255
|
|
|
15174
|
-
|
|
15175
|
-
|
|
15176
|
-
|
|
15177
|
-
|
|
15178
|
-
|
|
15179
|
-
:
|
|
15180
|
-
|
|
15181
|
-
|
|
15182
|
-
|
|
15183
|
-
|
|
15184
|
-
|
|
15185
|
-
|
|
15186
|
-
|
|
15187
|
-
|
|
15188
|
-
|
|
15189
|
-
|
|
15190
|
-
|
|
15256
|
+
@media (max-width: 1180px) {
|
|
15257
|
+
.clips-frame { padding-left: 0; }
|
|
15258
|
+
.editor-right-rail { position: relative; inset: auto; width: 100%; height: 540px; margin-top: 14px; border-radius: 24px; overflow: hidden; }
|
|
15259
|
+
.editor-chat-panel { border-right: 0; border-radius: 24px; }
|
|
15260
|
+
}
|
|
15261
|
+
@media (min-width: 1025px) and (max-width: 1180px) {
|
|
15262
|
+
html, body { height: auto; min-height: 100%; overflow: auto; overflow-x: hidden; }
|
|
15263
|
+
.app-shell { height: auto; min-height: 100svh; }
|
|
15264
|
+
.page-stack, .frame { height: auto; min-height: 0; overflow: visible; }
|
|
15265
|
+
.clips-scroll { overflow: visible; padding-right: 0; }
|
|
15266
|
+
}
|
|
15267
|
+
@media (max-width: 1024px) {
|
|
15268
|
+
.clips-shell { grid-template-rows: auto auto; }
|
|
15269
|
+
.clips-scroll { overflow: visible; padding-right: 0; }
|
|
15270
|
+
}
|
|
15271
|
+
`,
|
|
15272
|
+
body: `
|
|
15273
|
+
<section class="frame clips-frame">
|
|
15274
|
+
<header class="topbar">
|
|
15275
|
+
${renderBrandLockup({ displayName: input.name, email: input.email, accountId: input.currentAccountId })}
|
|
15276
|
+
<div class="topbar-actions">
|
|
15277
|
+
${renderPrimaryNav({ loggedIn: true, current: "library", accountId: input.currentAccountId })}
|
|
15278
|
+
</div>
|
|
15279
|
+
</header>
|
|
15280
|
+
<div class="frame-body">
|
|
15281
|
+
<section class="clips-shell">
|
|
15282
|
+
<div class="clips-toolbar">
|
|
15283
|
+
<div class="clips-toolbar-row">
|
|
15284
|
+
<div class="view-toggle" role="tablist" aria-label="Library view">
|
|
15285
|
+
<a class="view-toggle-tab" role="tab" href="${escapeAttribute(libraryHref)}">Finished</a>
|
|
15286
|
+
<a class="view-toggle-tab is-active" role="tab" aria-current="page" href="${escapeAttribute(clipsHref)}">Clips</a>
|
|
15287
|
+
</div>
|
|
15288
|
+
<form class="clips-search" id="searchForm">
|
|
15289
|
+
<input id="q" type="search" placeholder="Search clips — e.g. "someone looks confused after reading a message"" autocomplete="off" />
|
|
15290
|
+
<button type="submit">Search</button>
|
|
15291
|
+
</form>
|
|
15292
|
+
<button type="button" class="secondary" id="importSourceBtn">Import Source</button>
|
|
15293
|
+
</div>
|
|
15294
|
+
<div class="clips-status" id="status">Loading your clips…</div>
|
|
15295
|
+
</div>
|
|
15296
|
+
<div class="clips-scroll">
|
|
15297
|
+
<div class="clips-grid" id="grid"></div>
|
|
15298
|
+
</div>
|
|
15299
|
+
</section>
|
|
15300
|
+
</div>
|
|
15301
|
+
</section>
|
|
15302
|
+
<aside class="editor-right-rail" aria-label="Clip curator chat"><div class="editor-chat-panel" data-template-editor-chat-root></div></aside>
|
|
15303
|
+
<dialog class="clips-import-dialog" id="importDialog">
|
|
15304
|
+
<form class="clips-import-form" id="importForm" method="dialog">
|
|
15305
|
+
<div class="clips-import-head">
|
|
15306
|
+
<div class="label">Import source</div>
|
|
15307
|
+
<h3>Mine a video into clips</h3>
|
|
15308
|
+
<p>Paste a video URL — TikTok, YouTube, Instagram, X, or a direct link. We'll scan it and add the matching moments to your clip library.</p>
|
|
15309
|
+
</div>
|
|
15310
|
+
<div class="clips-import-field">
|
|
15311
|
+
<label for="importUrl">Video URL</label>
|
|
15312
|
+
<input id="importUrl" name="url" type="url" placeholder="https://youtube.com/watch?v=… or https://…/video.mp4" autocomplete="off" required />
|
|
15313
|
+
</div>
|
|
15314
|
+
<div class="clips-import-field">
|
|
15315
|
+
<label for="importPrompt">What to clip for</label>
|
|
15316
|
+
<textarea id="importPrompt" name="prompt" placeholder="Clip scenes of people with food, no text on screen, vertical, between 5-10 secs long"></textarea>
|
|
15317
|
+
</div>
|
|
15318
|
+
<div class="clips-import-note" id="importNote"></div>
|
|
15319
|
+
<div class="clips-import-actions">
|
|
15320
|
+
<button type="button" class="secondary" id="importCancel">Cancel</button>
|
|
15321
|
+
<button type="submit" id="importSubmit">Start scan</button>
|
|
15322
|
+
</div>
|
|
15323
|
+
</form>
|
|
15324
|
+
</dialog>
|
|
15325
|
+
<script>
|
|
15326
|
+
(function(){
|
|
15327
|
+
var grid = document.getElementById('grid');
|
|
15328
|
+
var statusEl = document.getElementById('status');
|
|
15329
|
+
var form = document.getElementById('searchForm');
|
|
15330
|
+
var input = document.getElementById('q');
|
|
15191
15331
|
|
|
15192
|
-
|
|
15193
|
-
|
|
15194
|
-
|
|
15195
|
-
|
|
15196
|
-
|
|
15197
|
-
|
|
15198
|
-
|
|
15199
|
-
|
|
15200
|
-
|
|
15201
|
-
|
|
15332
|
+
function fmtClock(sec){ var m=Math.floor(sec/60), s=Math.floor(sec%60); return (m<10?'0':'')+m+':'+(s<10?'0':'')+s; }
|
|
15333
|
+
function esc(t){ var d=document.createElement('div'); d.textContent=(t==null?'':String(t)); return d.innerHTML; }
|
|
15334
|
+
|
|
15335
|
+
function topTags(tags){
|
|
15336
|
+
if(!tags) return [];
|
|
15337
|
+
var out=[];
|
|
15338
|
+
['subject','action','emotion','composition'].forEach(function(k){ (tags[k]||[]).slice(0,1).forEach(function(v){ out.push(v); }); });
|
|
15339
|
+
if(tags.energy) out.push('energy:'+tags.energy);
|
|
15340
|
+
return out.slice(0,4);
|
|
15341
|
+
}
|
|
15202
15342
|
|
|
15203
|
-
|
|
15204
|
-
|
|
15205
|
-
|
|
15206
|
-
|
|
15207
|
-
|
|
15208
|
-
|
|
15209
|
-
|
|
15210
|
-
|
|
15343
|
+
function card(clip){
|
|
15344
|
+
var range = fmtClock(clip.start_time_sec)+'–'+fmtClock(clip.end_time_sec);
|
|
15345
|
+
var score = (clip.score!=null) ? '<div class="clip-score">'+ (clip.score*100).toFixed(0) +'</div>' : '';
|
|
15346
|
+
var media = clip.thumbnail_url
|
|
15347
|
+
? '<img loading="lazy" src="'+esc(clip.thumbnail_url)+'" onmouseover="var v=this.parentNode.querySelector("video"); if(v){v.style.display="block";v.play();}" />'
|
|
15348
|
+
: '<div class="clip-noimg">no thumb</div>';
|
|
15349
|
+
var vid = clip.view_url ? '<video muted loop playsinline preload="none" style="display:none;position:absolute;inset:0" src="'+esc(clip.view_url)+'"></video>' : '';
|
|
15350
|
+
var tags = topTags(clip.tags).map(function(t){ return '<span class="clip-tag">'+esc(t)+'</span>'; }).join('');
|
|
15351
|
+
return '<div class="clip-card">'
|
|
15352
|
+
+ '<div class="clip-thumb" onmouseleave="var v=this.querySelector("video"); if(v){v.pause();v.style.display="none";}">'+media+vid+'<div class="clip-range">'+range+' · '+clip.duration_sec.toFixed(1)+'s</div>'+score+'</div>'
|
|
15353
|
+
+ '<div class="clip-body">'
|
|
15354
|
+
+ '<div class="clip-desc">'+esc(clip.description||clip.tags&&clip.tags.transcript||'(untagged clip)')+'</div>'
|
|
15355
|
+
+ '<div class="clip-tags">'+tags+'</div>'
|
|
15356
|
+
+ '<div class="clip-row"><span class="clip-src" title="'+esc(clip.source_filename)+'">'+esc(clip.source_filename)+'</span>'
|
|
15357
|
+
+ '<a class="clip-dl" href="/clips/'+encodeURIComponent(clip.clip_id)+'/download">Download</a></div>'
|
|
15358
|
+
+ '</div></div>';
|
|
15359
|
+
}
|
|
15211
15360
|
|
|
15212
|
-
|
|
15213
|
-
|
|
15214
|
-
|
|
15215
|
-
|
|
15216
|
-
|
|
15361
|
+
function render(clips, label){
|
|
15362
|
+
if(!clips || clips.length===0){
|
|
15363
|
+
statusEl.innerHTML = label || '';
|
|
15364
|
+
grid.innerHTML = '<div class="clips-empty">No Clips Yet. Click "Import Source" to begin</div>';
|
|
15365
|
+
return;
|
|
15366
|
+
}
|
|
15367
|
+
statusEl.textContent = (label||'') + clips.length + ' clip' + (clips.length===1?'':'s');
|
|
15368
|
+
grid.innerHTML = clips.map(card).join('');
|
|
15369
|
+
}
|
|
15217
15370
|
|
|
15218
|
-
|
|
15219
|
-
|
|
15220
|
-
|
|
15221
|
-
|
|
15222
|
-
|
|
15223
|
-
|
|
15224
|
-
|
|
15225
|
-
|
|
15371
|
+
function handleAuth(res){
|
|
15372
|
+
if(res.status===401||res.status===403){
|
|
15373
|
+
grid.innerHTML='';
|
|
15374
|
+
statusEl.innerHTML='Sign in to VidFarm to see your clips. Then build a library with <code>vidfarm clips scan</code>.';
|
|
15375
|
+
throw new Error('unauthorized');
|
|
15376
|
+
}
|
|
15377
|
+
return res.json();
|
|
15378
|
+
}
|
|
15226
15379
|
|
|
15227
|
-
|
|
15228
|
-
|
|
15229
|
-
|
|
15230
|
-
|
|
15231
|
-
|
|
15232
|
-
|
|
15233
|
-
|
|
15234
|
-
|
|
15235
|
-
|
|
15236
|
-
|
|
15237
|
-
|
|
15238
|
-
|
|
15239
|
-
|
|
15380
|
+
function loadFeed(){
|
|
15381
|
+
statusEl.textContent='Loading your clips…';
|
|
15382
|
+
fetch('/clips/feed?limit=120', {credentials:'same-origin', headers:{Accept:'application/json'}})
|
|
15383
|
+
.then(handleAuth).then(function(d){ render(d.clips, ''); }).catch(function(){});
|
|
15384
|
+
}
|
|
15385
|
+
|
|
15386
|
+
function search(query, criteria){
|
|
15387
|
+
statusEl.textContent='Searching…';
|
|
15388
|
+
fetch('/clips/search', {method:'POST', credentials:'same-origin', headers:{'Content-Type':'application/json', Accept:'application/json'}, body: JSON.stringify(criteria?{criteria:criteria, limit:60}:{query:query, limit:60})})
|
|
15389
|
+
.then(handleAuth).then(function(d){
|
|
15390
|
+
var label = (d.semantic?'semantic ':'') + 'results for "' + (query||'preset') + '" — ';
|
|
15391
|
+
render(d.results, label);
|
|
15392
|
+
}).catch(function(){});
|
|
15393
|
+
}
|
|
15394
|
+
|
|
15395
|
+
form.addEventListener('submit', function(e){
|
|
15396
|
+
e.preventDefault();
|
|
15397
|
+
var q = input.value.trim();
|
|
15398
|
+
if(q) search(q, null); else loadFeed();
|
|
15240
15399
|
});
|
|
15241
|
-
});
|
|
15242
|
-
}).catch(function(){});
|
|
15243
|
-
}
|
|
15244
15400
|
|
|
15245
|
-
|
|
15246
|
-
|
|
15247
|
-
|
|
15248
|
-
|
|
15249
|
-
|
|
15250
|
-
|
|
15401
|
+
// ── Import Source modal ────────────────────────────────────────
|
|
15402
|
+
var importBtn = document.getElementById('importSourceBtn');
|
|
15403
|
+
var importDialog = document.getElementById('importDialog');
|
|
15404
|
+
var importForm = document.getElementById('importForm');
|
|
15405
|
+
var importUrl = document.getElementById('importUrl');
|
|
15406
|
+
var importPrompt = document.getElementById('importPrompt');
|
|
15407
|
+
var importNote = document.getElementById('importNote');
|
|
15408
|
+
var importCancel = document.getElementById('importCancel');
|
|
15409
|
+
var importSubmit = document.getElementById('importSubmit');
|
|
15410
|
+
var scanPoll = null;
|
|
15251
15411
|
|
|
15252
|
-
|
|
15253
|
-
|
|
15254
|
-
|
|
15255
|
-
|
|
15256
|
-
|
|
15257
|
-
|
|
15412
|
+
function setNote(msg, tone){
|
|
15413
|
+
if(!importNote) return;
|
|
15414
|
+
importNote.textContent = msg || '';
|
|
15415
|
+
if(tone) importNote.setAttribute('data-tone', tone); else importNote.removeAttribute('data-tone');
|
|
15416
|
+
}
|
|
15417
|
+
function openImport(){
|
|
15418
|
+
setNote('');
|
|
15419
|
+
if(importDialog && typeof importDialog.showModal === 'function' && !importDialog.open) importDialog.showModal();
|
|
15420
|
+
if(importUrl) importUrl.focus();
|
|
15421
|
+
}
|
|
15422
|
+
function closeImport(){
|
|
15423
|
+
if(importDialog && importDialog.open) importDialog.close();
|
|
15424
|
+
}
|
|
15425
|
+
function pollScan(scanId){
|
|
15426
|
+
if(scanPoll) clearInterval(scanPoll);
|
|
15427
|
+
var tries = 0;
|
|
15428
|
+
scanPoll = setInterval(function(){
|
|
15429
|
+
tries++;
|
|
15430
|
+
if(tries > 200){ clearInterval(scanPoll); scanPoll=null; statusEl.textContent='Still scanning in the background — check back shortly.'; return; }
|
|
15431
|
+
fetch('/clips/scan/'+encodeURIComponent(scanId), {credentials:'same-origin', headers:{Accept:'application/json'}})
|
|
15432
|
+
.then(function(r){ return r.ok ? r.json() : null; })
|
|
15433
|
+
.then(function(d){
|
|
15434
|
+
if(!d) return;
|
|
15435
|
+
var src = d.source || {};
|
|
15436
|
+
var status = src.status || (d.scan && d.scan.status) || 'running';
|
|
15437
|
+
if(status==='complete'){
|
|
15438
|
+
clearInterval(scanPoll); scanPoll=null;
|
|
15439
|
+
statusEl.textContent='Import complete — refreshing your clips…';
|
|
15440
|
+
loadFeed();
|
|
15441
|
+
} else if(status==='failed'||status==='error'){
|
|
15442
|
+
clearInterval(scanPoll); scanPoll=null;
|
|
15443
|
+
statusEl.textContent='Import failed: '+(src.error||(d.scan&&d.scan.error)||'the source could not be scanned.');
|
|
15444
|
+
} else {
|
|
15445
|
+
statusEl.textContent='Scanning source… ('+status+')';
|
|
15446
|
+
}
|
|
15447
|
+
}).catch(function(){});
|
|
15448
|
+
}, 4000);
|
|
15449
|
+
}
|
|
15450
|
+
|
|
15451
|
+
if(importBtn) importBtn.addEventListener('click', openImport);
|
|
15452
|
+
if(importCancel) importCancel.addEventListener('click', closeImport);
|
|
15453
|
+
if(importDialog) importDialog.addEventListener('click', function(e){
|
|
15454
|
+
var rect = importDialog.getBoundingClientRect();
|
|
15455
|
+
if(e.clientX<rect.left||e.clientX>rect.right||e.clientY<rect.top||e.clientY>rect.bottom) closeImport();
|
|
15456
|
+
});
|
|
15457
|
+
if(importForm) importForm.addEventListener('submit', function(e){
|
|
15458
|
+
e.preventDefault();
|
|
15459
|
+
var url = (importUrl && importUrl.value || '').trim();
|
|
15460
|
+
var prompt = (importPrompt && importPrompt.value || '').trim();
|
|
15461
|
+
if(!url){ setNote('Enter a video URL.', 'error'); return; }
|
|
15462
|
+
setNote('Starting scan…');
|
|
15463
|
+
if(importSubmit) importSubmit.disabled = true;
|
|
15464
|
+
fetch('/clips/scan', {method:'POST', credentials:'same-origin', headers:{'Content-Type':'application/json', Accept:'application/json'}, body: JSON.stringify({source_url:url, prompt:prompt})})
|
|
15465
|
+
.then(function(r){ return r.json().then(function(d){ return {ok:r.ok, status:r.status, data:d}; }); })
|
|
15466
|
+
.then(function(res){
|
|
15467
|
+
if(importSubmit) importSubmit.disabled = false;
|
|
15468
|
+
if(!res.ok){ setNote((res.data && res.data.error) || 'Could not start the scan.', 'error'); return; }
|
|
15469
|
+
setNote('Scan started — this can take a few minutes.', 'success');
|
|
15470
|
+
statusEl.textContent='Scanning source…';
|
|
15471
|
+
closeImport();
|
|
15472
|
+
if(importForm.reset) importForm.reset();
|
|
15473
|
+
if(res.data && res.data.scan_id) pollScan(res.data.scan_id);
|
|
15474
|
+
})
|
|
15475
|
+
.catch(function(){
|
|
15476
|
+
if(importSubmit) importSubmit.disabled = false;
|
|
15477
|
+
setNote('Network error — please try again.', 'error');
|
|
15478
|
+
});
|
|
15479
|
+
});
|
|
15480
|
+
|
|
15481
|
+
loadFeed();
|
|
15482
|
+
})();
|
|
15483
|
+
</script>
|
|
15484
|
+
`
|
|
15485
|
+
});
|
|
15258
15486
|
}
|
|
15259
15487
|
async function resolveCustomerProviderKey(customerId, provider) {
|
|
15260
15488
|
const rows = (await listProviderKeysWithSecretsForCustomer(customerId));
|
|
@@ -15350,9 +15578,22 @@ function clipKeywordMatch(clip, q) {
|
|
|
15350
15578
|
.filter(Boolean)
|
|
15351
15579
|
.every((term) => hay.includes(term));
|
|
15352
15580
|
}
|
|
15353
|
-
// GET /clips — the
|
|
15354
|
-
//
|
|
15355
|
-
|
|
15581
|
+
// GET /clips — the Clips gallery, rendered in the same shell as the rest of the
|
|
15582
|
+
// frontend and reached via the Library page's "Finished / Clips" toggle. The
|
|
15583
|
+
// client fetches /clips/feed with the session cookie (mirrors /discover vs /feed).
|
|
15584
|
+
app.get(CLIPS_PREFIX, async (c) => {
|
|
15585
|
+
const customer = await getPreferredBrowserCustomer(c);
|
|
15586
|
+
if (!customer) {
|
|
15587
|
+
return redirect(c, "/login");
|
|
15588
|
+
}
|
|
15589
|
+
return c.html(renderClipsPage({
|
|
15590
|
+
userId: customer.id,
|
|
15591
|
+
currentAccountId: customer.id,
|
|
15592
|
+
name: customer.name,
|
|
15593
|
+
email: customer.email,
|
|
15594
|
+
editorChat: await buildClipsEditorChatBoot({ customer })
|
|
15595
|
+
}));
|
|
15596
|
+
});
|
|
15356
15597
|
// GET /clips/feed — the caller's clip library as JSON (optional ?source, ?q, ?limit).
|
|
15357
15598
|
app.get(`${CLIPS_PREFIX}/feed`, async (c) => {
|
|
15358
15599
|
const customer = requireCustomer(c);
|
|
@@ -15472,14 +15713,79 @@ app.post(`${CLIPS_PREFIX}/match-scenes`, async (c) => {
|
|
|
15472
15713
|
}
|
|
15473
15714
|
});
|
|
15474
15715
|
// POST /clips/scan — kick off a cloud scan of an uploaded/staged source video.
|
|
15716
|
+
// Inherently ASYNC: returns 202 + scan_id immediately; the Step Functions
|
|
15717
|
+
// pipeline runs the hunt and GET /clips/scan/:scanId polls it. Billing is AWS
|
|
15718
|
+
// compute only (clip_scan_lambda + step_functions_standard) — the AI spend is
|
|
15719
|
+
// the caller's own provider key (BYOK) and is never wallet-billed.
|
|
15475
15720
|
app.post(`${CLIPS_PREFIX}/scan`, async (c) => {
|
|
15476
15721
|
const customer = requireCustomer(c);
|
|
15477
15722
|
try {
|
|
15478
15723
|
const body = (await c.req.json());
|
|
15724
|
+
const guidancePrompt = body.prompt?.trim() || "";
|
|
15725
|
+
// Build the hunt spec: explicit structured fields win, the free "what to
|
|
15726
|
+
// clip for" prompt fills the gaps (duration band, vertical/aspect, no-text).
|
|
15727
|
+
// A pasted "Import Source" URL rides in hunt_spec.source_url — the clip-scan
|
|
15728
|
+
// Lambda ingests it (RapidAPI, incl. TikTok/YouTube/IG/X) into the user's
|
|
15729
|
+
// 30-day temp folder before scanning.
|
|
15730
|
+
const sourceUrl = readNonEmptyString(body.source_url) ?? readNonEmptyString(body.video_url) ?? readNonEmptyString(body.url);
|
|
15731
|
+
if (sourceUrl && !/^https?:\/\//i.test(sourceUrl)) {
|
|
15732
|
+
return c.json({ error: "That doesn't look like a valid video URL." }, 400);
|
|
15733
|
+
}
|
|
15734
|
+
const huntSpec = normalizeHuntSpec({
|
|
15735
|
+
...(body.hunt_spec && typeof body.hunt_spec === "object" ? body.hunt_spec : {}),
|
|
15736
|
+
...(body.ranges != null ? { ranges: body.ranges } : {}),
|
|
15737
|
+
...(body.target_duration_sec != null ? { target_duration_sec: body.target_duration_sec } : {}),
|
|
15738
|
+
...(body.aspect != null ? { aspect: body.aspect } : {}),
|
|
15739
|
+
...(body.crop_focus != null ? { crop_focus: body.crop_focus } : {}),
|
|
15740
|
+
...(body.avoid_text != null ? { avoid_text: body.avoid_text } : {}),
|
|
15741
|
+
...(body.no_text != null ? { no_text: body.no_text } : {})
|
|
15742
|
+
});
|
|
15743
|
+
const parsedPrompt = parseClipHuntPrompt(guidancePrompt);
|
|
15744
|
+
if (!huntSpec.windows?.length && parsedPrompt.windows.length)
|
|
15745
|
+
huntSpec.windows = parsedPrompt.windows;
|
|
15746
|
+
if (!huntSpec.duration_band && parsedPrompt.target_duration_sec != null) {
|
|
15747
|
+
const band = resolveDurationBand(parsedPrompt.target_duration_sec);
|
|
15748
|
+
if (band)
|
|
15749
|
+
huntSpec.duration_band = band;
|
|
15750
|
+
}
|
|
15751
|
+
if (!huntSpec.aspect && parsedPrompt.aspect)
|
|
15752
|
+
huntSpec.aspect = parsedPrompt.aspect;
|
|
15753
|
+
if (!huntSpec.avoid_text && parsedPrompt.avoid_text)
|
|
15754
|
+
huntSpec.avoid_text = true;
|
|
15755
|
+
if (!huntSpec.source_url && sourceUrl)
|
|
15756
|
+
huntSpec.source_url = sourceUrl;
|
|
15757
|
+
// Uploaded-source hunts: resolve a temp-folder file (the canonical home for
|
|
15758
|
+
// hunt originals — 30-day TTL) or a My Files attachment to its S3 key.
|
|
15759
|
+
let resolvedS3Key = readNonEmptyString(body.s3_key) ?? undefined;
|
|
15760
|
+
const tempFileId = readNonEmptyString(body.temp_file_id);
|
|
15761
|
+
const attachmentId = readNonEmptyString(body.attachment_id);
|
|
15762
|
+
if (!body.raw_s3_uri && !resolvedS3Key && tempFileId) {
|
|
15763
|
+
const file = await serverlessRecords.getUserTemporaryFile(customer.id, tempFileId);
|
|
15764
|
+
if (!file)
|
|
15765
|
+
return c.json({ error: "Temporary file not found — upload it first via /api/v1/user/me/temporary-files." }, 404);
|
|
15766
|
+
resolvedS3Key = file.storageKey;
|
|
15767
|
+
}
|
|
15768
|
+
else if (!body.raw_s3_uri && !resolvedS3Key && attachmentId) {
|
|
15769
|
+
const attachment = await serverlessRecords.getUserAttachment(customer.id, attachmentId);
|
|
15770
|
+
if (!attachment)
|
|
15771
|
+
return c.json({ error: "Attachment not found in My Files." }, 404);
|
|
15772
|
+
resolvedS3Key = attachment.storageKey;
|
|
15773
|
+
}
|
|
15479
15774
|
const rawS3Uri = body.raw_s3_uri ??
|
|
15480
|
-
(
|
|
15481
|
-
if (!rawS3Uri) {
|
|
15482
|
-
return c.json({ error: "Provide raw_s3_uri (s3://…) or s3_key of the
|
|
15775
|
+
(resolvedS3Key && config.AWS_S3_BUCKET ? `s3://${config.AWS_S3_BUCKET}/${resolvedS3Key}` : undefined);
|
|
15776
|
+
if (!rawS3Uri && !huntSpec.source_url) {
|
|
15777
|
+
return c.json({ error: "Provide source_url (a video URL), temp_file_id/attachment_id of an upload, raw_s3_uri (s3://…), or s3_key of the staged source video." }, 400);
|
|
15778
|
+
}
|
|
15779
|
+
// Hunts bill AWS compute post-hoc, so submission is the spend gate (same
|
|
15780
|
+
// policy as job submission).
|
|
15781
|
+
try {
|
|
15782
|
+
await assertWalletCanQueueJobs(customer.id);
|
|
15783
|
+
}
|
|
15784
|
+
catch (error) {
|
|
15785
|
+
if (error instanceof InsufficientWalletFundsError) {
|
|
15786
|
+
return insufficientFundsResponse(c, error);
|
|
15787
|
+
}
|
|
15788
|
+
throw error;
|
|
15483
15789
|
}
|
|
15484
15790
|
const provider = normalizeClipProvider(body.provider);
|
|
15485
15791
|
const built = await buildCustomerClipClient(customer.id, provider);
|
|
@@ -15489,26 +15795,39 @@ app.post(`${CLIPS_PREFIX}/scan`, async (c) => {
|
|
|
15489
15795
|
const tier = normalizeScanTier(body.tier);
|
|
15490
15796
|
const framesPerScene = Math.max(1, Math.min(3, Number(body.frames_per_scene) || 2));
|
|
15491
15797
|
const includeAudio = body.include_audio !== false && provider === "gemini";
|
|
15492
|
-
const
|
|
15798
|
+
const tracer = readNonEmptyString(body.tracer) ?? `clips_import:${customer.id}`;
|
|
15493
15799
|
const now = nowIso();
|
|
15494
15800
|
const scanId = createIdV7("clipscan");
|
|
15495
15801
|
const sourceVideoId = createIdV7("srcvid");
|
|
15496
|
-
|
|
15497
|
-
const
|
|
15498
|
-
|
|
15802
|
+
// The URL ingest is deferred to the Lambda, so raw_s3_uri may be empty here.
|
|
15803
|
+
const sourcePointer = rawS3Uri ?? huntSpec.source_url ?? "";
|
|
15804
|
+
const filename = body.filename || (sourcePointer.split("/").pop() || "source.mp4").split("?")[0] || "source.mp4";
|
|
15805
|
+
// Time-range hunts only pay for the windows: both estimates use the
|
|
15806
|
+
// EFFECTIVE (windowed) duration, and the duration band drives the expected
|
|
15807
|
+
// scene size. The BYOK estimate is the user's own provider spend; the
|
|
15808
|
+
// compute estimate is what the wallet will be billed (AWS only, marked up).
|
|
15809
|
+
const effectiveDurationSec = body.duration_sec && body.duration_sec > 0
|
|
15810
|
+
? effectiveHuntDurationSec(body.duration_sec, huntSpec.windows)
|
|
15811
|
+
: null;
|
|
15812
|
+
const estimate = effectiveDurationSec
|
|
15813
|
+
? estimateScanCostFromDuration(effectiveDurationSec, {
|
|
15499
15814
|
tier,
|
|
15500
15815
|
provider,
|
|
15501
15816
|
tagModelId: client.tagModelId,
|
|
15502
15817
|
embedModelId: client.embeddingModelId,
|
|
15503
15818
|
framesPerScene,
|
|
15504
|
-
includeAudio
|
|
15819
|
+
includeAudio,
|
|
15820
|
+
avgSceneSec: huntSpec.duration_band?.target_sec
|
|
15505
15821
|
})
|
|
15506
15822
|
: null;
|
|
15823
|
+
const computeEstimate = effectiveDurationSec
|
|
15824
|
+
? estimateClipScanComputeUsd(effectiveDurationSec, huntSpec.duration_band?.target_sec)
|
|
15825
|
+
: null;
|
|
15507
15826
|
const source = {
|
|
15508
15827
|
source_video_id: sourceVideoId,
|
|
15509
15828
|
owner_id: customer.id,
|
|
15510
15829
|
filename,
|
|
15511
|
-
raw_s3_uri:
|
|
15830
|
+
raw_s3_uri: sourcePointer,
|
|
15512
15831
|
duration_sec: body.duration_sec,
|
|
15513
15832
|
clip_count: 0,
|
|
15514
15833
|
tier,
|
|
@@ -15528,7 +15847,7 @@ app.post(`${CLIPS_PREFIX}/scan`, async (c) => {
|
|
|
15528
15847
|
owner_id: customer.id,
|
|
15529
15848
|
source_video_id: sourceVideoId,
|
|
15530
15849
|
source_filename: filename,
|
|
15531
|
-
raw_s3_uri: rawS3Uri,
|
|
15850
|
+
raw_s3_uri: rawS3Uri ?? "",
|
|
15532
15851
|
tier,
|
|
15533
15852
|
provider,
|
|
15534
15853
|
tag_api_key: tagApiKey,
|
|
@@ -15536,7 +15855,9 @@ app.post(`${CLIPS_PREFIX}/scan`, async (c) => {
|
|
|
15536
15855
|
embedding_api_key: embeddingKey ?? "",
|
|
15537
15856
|
guidance_prompt: guidancePrompt,
|
|
15538
15857
|
frames_per_scene: framesPerScene,
|
|
15539
|
-
include_audio: includeAudio
|
|
15858
|
+
include_audio: includeAudio,
|
|
15859
|
+
hunt_spec: huntSpec,
|
|
15860
|
+
tracer
|
|
15540
15861
|
})
|
|
15541
15862
|
}));
|
|
15542
15863
|
executionArn = res.executionArn;
|
|
@@ -15547,8 +15868,9 @@ app.post(`${CLIPS_PREFIX}/scan`, async (c) => {
|
|
|
15547
15868
|
source_video_id: sourceVideoId,
|
|
15548
15869
|
status: executionArn ? "running" : "queued",
|
|
15549
15870
|
tier,
|
|
15550
|
-
raw_s3_uri:
|
|
15871
|
+
raw_s3_uri: sourcePointer,
|
|
15551
15872
|
execution_arn: executionArn,
|
|
15873
|
+
tracer,
|
|
15552
15874
|
created_at: now,
|
|
15553
15875
|
updated_at: now
|
|
15554
15876
|
};
|
|
@@ -15558,7 +15880,10 @@ app.post(`${CLIPS_PREFIX}/scan`, async (c) => {
|
|
|
15558
15880
|
source_video_id: sourceVideoId,
|
|
15559
15881
|
status: scan.status,
|
|
15560
15882
|
execution_arn: executionArn ?? null,
|
|
15883
|
+
tracer,
|
|
15884
|
+
hunt_spec: huntSpec,
|
|
15561
15885
|
estimate,
|
|
15886
|
+
compute_estimate: computeEstimate,
|
|
15562
15887
|
pipeline_deployed: Boolean(config.VIDFARM_CLIP_SCAN_STATE_MACHINE_ARN)
|
|
15563
15888
|
}, 202);
|
|
15564
15889
|
}
|
|
@@ -15569,9 +15894,32 @@ app.post(`${CLIPS_PREFIX}/scan`, async (c) => {
|
|
|
15569
15894
|
// GET /clips/scan/:scanId — poll scan status.
|
|
15570
15895
|
app.get(`${CLIPS_PREFIX}/scan/:scanId`, async (c) => {
|
|
15571
15896
|
const customer = requireCustomer(c);
|
|
15572
|
-
|
|
15897
|
+
let scan = await clipRecords.getScan(customer.id, c.req.param("scanId"));
|
|
15573
15898
|
if (!scan)
|
|
15574
15899
|
return c.json({ error: "Scan not found" }, 404);
|
|
15900
|
+
// Lazily reconcile with the Step Functions execution: the pipeline has no
|
|
15901
|
+
// failure hook back into the scan record, so a crashed execution would
|
|
15902
|
+
// otherwise leave "running" forever and pollers spin.
|
|
15903
|
+
if ((scan.status === "running" || scan.status === "queued") && scan.execution_arn) {
|
|
15904
|
+
try {
|
|
15905
|
+
const desc = await clipScanSfn.send(new DescribeExecutionCommand({ executionArn: scan.execution_arn }));
|
|
15906
|
+
if (desc.status === "FAILED" || desc.status === "TIMED_OUT" || desc.status === "ABORTED") {
|
|
15907
|
+
scan = { ...scan, status: "failed", error: `Scan pipeline ${desc.status.toLowerCase().replace("_", " ")}.`, updated_at: nowIso() };
|
|
15908
|
+
await clipRecords.putScan(scan);
|
|
15909
|
+
const failedSource = await clipRecords.getSource(customer.id, scan.source_video_id);
|
|
15910
|
+
if (failedSource && failedSource.status !== "complete") {
|
|
15911
|
+
await clipRecords.putSource({ ...failedSource, status: "failed", updated_at: nowIso() });
|
|
15912
|
+
}
|
|
15913
|
+
}
|
|
15914
|
+
else if (desc.status === "SUCCEEDED") {
|
|
15915
|
+
scan = { ...scan, status: "complete", updated_at: nowIso() };
|
|
15916
|
+
await clipRecords.putScan(scan);
|
|
15917
|
+
}
|
|
15918
|
+
}
|
|
15919
|
+
catch (error) {
|
|
15920
|
+
devLog("clip_scan.reconcile_failed", { scan_id: scan.scan_id, ...devErrorFields(error) }, "warn");
|
|
15921
|
+
}
|
|
15922
|
+
}
|
|
15575
15923
|
const source = await clipRecords.getSource(customer.id, scan.source_video_id);
|
|
15576
15924
|
return c.json({ scan, source });
|
|
15577
15925
|
});
|