@mevdragon/vidfarm-devcli 0.20.6 → 0.20.9

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.
Files changed (157) hide show
  1. package/.agents/skills/editor-capabilities/SKILL.md +15 -1
  2. package/.agents/skills/vidfarm-director/SKILL.md +106 -0
  3. package/.agents/skills/vidfarm-director/recipes/find-and-fork-template.md +16 -0
  4. package/.agents/skills/vidfarm-director/recipes/local-edit-render-approve.md +13 -0
  5. package/.agents/skills/vidfarm-director/recipes/onboard-a-new-director.md +13 -0
  6. package/.agents/skills/vidfarm-director/recipes/retheme-template.md +17 -0
  7. package/.agents/skills/vidfarm-director/references/assets-and-sourcing.md +117 -0
  8. package/.agents/skills/vidfarm-director/references/automation-and-local-dev.md +245 -0
  9. package/.agents/skills/vidfarm-director/references/core-workflows.md +273 -0
  10. package/.agents/skills/vidfarm-director/references/editor-workflows.md +365 -0
  11. package/.agents/skills/vidfarm-director/references/onboarding.md +28 -0
  12. package/.agents/skills/vidfarm-director/references/primitives.md +308 -0
  13. package/SKILL.director.md +517 -250
  14. package/dist/src/cli.js +563 -99
  15. package/dist/src/devcli/clips.js +29 -12
  16. package/dist/src/devcli/doctor.js +2 -2
  17. package/dist/src/devcli/local-backend.js +46 -2
  18. package/dist/src/services/clip-curation/cost.js +5 -1
  19. package/dist/src/services/clip-curation/gemini.js +14 -2
  20. package/dist/src/services/clip-curation/hunt.js +56 -0
  21. package/dist/src/services/clip-curation/index.js +1 -1
  22. package/dist/src/services/clip-curation/scan.js +5 -3
  23. package/package.json +30 -10
  24. package/SKILL.platform.md +0 -432
  25. package/demo/README.md +0 -28
  26. package/demo/dist/app.css +0 -1
  27. package/demo/dist/app.js +0 -1850
  28. package/demo/dist/chunks/chunk-DXB73IDG.js +0 -1
  29. package/demo/dist/chunks/chunk-S7OWAJDS.js +0 -36
  30. package/demo/dist/chunks/chunk-VTIBZ6AN.js +0 -1
  31. package/demo/dist/chunks/dist-ADSJKBVE.js +0 -332
  32. package/demo/dist/chunks/domEditingLayers-VZMLL4AP-SGHWPND4.js +0 -1
  33. package/demo/dist/chunks/hyperframes-player-XB65TCD6.js +0 -425
  34. package/demo/dist/chunks/lib-XAQ37YOE.js +0 -1
  35. package/demo/dist/chunks/src-TJ2QYA4U.js +0 -207
  36. package/demo/dist/favicon.ico +0 -0
  37. package/demo/dist/icons/timeline/audio.svg +0 -7
  38. package/demo/dist/icons/timeline/captions.svg +0 -5
  39. package/demo/dist/icons/timeline/composition.svg +0 -12
  40. package/demo/dist/icons/timeline/image.svg +0 -18
  41. package/demo/dist/icons/timeline/music.svg +0 -10
  42. package/demo/dist/icons/timeline/text.svg +0 -3
  43. package/demo/dist/index.html +0 -15
  44. package/dist/src/account-pages-legacy.js +0 -9396
  45. package/dist/src/account-pages.js +0 -61
  46. package/dist/src/app.js +0 -21603
  47. package/dist/src/composition-runtime.js +0 -1053
  48. package/dist/src/config.js +0 -217
  49. package/dist/src/context.js +0 -447
  50. package/dist/src/dev-app-legacy.js +0 -739
  51. package/dist/src/dev-app.js +0 -6
  52. package/dist/src/devcli/migrate-local.js +0 -140
  53. package/dist/src/devcli/sync.js +0 -368
  54. package/dist/src/domain.js +0 -5
  55. package/dist/src/editor-chat-history.js +0 -82
  56. package/dist/src/editor-chat.js +0 -828
  57. package/dist/src/editor-dark-theme.js +0 -1128
  58. package/dist/src/frontend/debug.js +0 -71
  59. package/dist/src/frontend/discover-client.js +0 -130
  60. package/dist/src/frontend/discover-store.js +0 -23
  61. package/dist/src/frontend/file-directory.js +0 -1018
  62. package/dist/src/frontend/flockposter-cache-store.js +0 -124
  63. package/dist/src/frontend/homepage-client.js +0 -446
  64. package/dist/src/frontend/homepage-shared.js +0 -201
  65. package/dist/src/frontend/homepage-store.js +0 -66
  66. package/dist/src/frontend/homepage-view.js +0 -705
  67. package/dist/src/frontend/page-runtime-client.js +0 -132
  68. package/dist/src/frontend/page-runtime-store.js +0 -9
  69. package/dist/src/frontend/sentry.js +0 -42
  70. package/dist/src/frontend/template-editor-chat.js +0 -4181
  71. package/dist/src/help-page.js +0 -346
  72. package/dist/src/homepage.js +0 -1458
  73. package/dist/src/index.js +0 -16
  74. package/dist/src/instrument.js +0 -30
  75. package/dist/src/landing-page.js +0 -384
  76. package/dist/src/page-runtime.js +0 -2
  77. package/dist/src/page-shell.js +0 -1452
  78. package/dist/src/primitive-context.js +0 -416
  79. package/dist/src/primitive-registry.js +0 -3940
  80. package/dist/src/primitive-sdk.js +0 -4
  81. package/dist/src/primitives/hyperframes-media.js +0 -108
  82. package/dist/src/react-page-shell.js +0 -35
  83. package/dist/src/ready-post-schedule-component.js +0 -1540
  84. package/dist/src/registry.js +0 -296
  85. package/dist/src/reskin/agency-page.js +0 -299
  86. package/dist/src/reskin/calendar-page.js +0 -568
  87. package/dist/src/reskin/chat-page.js +0 -942
  88. package/dist/src/reskin/discover-page.js +0 -1788
  89. package/dist/src/reskin/document.js +0 -1587
  90. package/dist/src/reskin/help-page.js +0 -357
  91. package/dist/src/reskin/index-page.js +0 -62
  92. package/dist/src/reskin/inpaint-clipper-page.js +0 -890
  93. package/dist/src/reskin/inpaint-page.js +0 -2554
  94. package/dist/src/reskin/inpaint-video-page.js +0 -1339
  95. package/dist/src/reskin/job-runs-page.js +0 -477
  96. package/dist/src/reskin/library-page.js +0 -1634
  97. package/dist/src/reskin/login-page.js +0 -262
  98. package/dist/src/reskin/portfolio-page.js +0 -687
  99. package/dist/src/reskin/pricing-page.js +0 -390
  100. package/dist/src/reskin/settings-page.js +0 -732
  101. package/dist/src/reskin/theme.js +0 -711
  102. package/dist/src/runtime.js +0 -35
  103. package/dist/src/services/api-call-history.js +0 -249
  104. package/dist/src/services/auth.js +0 -152
  105. package/dist/src/services/billing-pricing.js +0 -39
  106. package/dist/src/services/billing.js +0 -241
  107. package/dist/src/services/cast.js +0 -127
  108. package/dist/src/services/chat-threads.js +0 -92
  109. package/dist/src/services/clip-records.js +0 -250
  110. package/dist/src/services/clip-search.js +0 -77
  111. package/dist/src/services/clip-vectors.js +0 -125
  112. package/dist/src/services/composition-sanitize.js +0 -124
  113. package/dist/src/services/composition-watch.js +0 -79
  114. package/dist/src/services/elevenlabs.js +0 -222
  115. package/dist/src/services/file-directory.js +0 -117
  116. package/dist/src/services/fork-access.js +0 -93
  117. package/dist/src/services/fork-manifest.js +0 -42
  118. package/dist/src/services/ghostcut.js +0 -179
  119. package/dist/src/services/hyperframes.js +0 -3654
  120. package/dist/src/services/job-capacity.js +0 -14
  121. package/dist/src/services/job-logs.js +0 -197
  122. package/dist/src/services/jobs.js +0 -136
  123. package/dist/src/services/local-dynamo.js +0 -0
  124. package/dist/src/services/media-processing.js +0 -766
  125. package/dist/src/services/primitive-media-lambda.js +0 -280
  126. package/dist/src/services/providers.js +0 -2748
  127. package/dist/src/services/rate-limits.js +0 -262
  128. package/dist/src/services/scene-annotations.js +0 -32
  129. package/dist/src/services/serverless-auth.js +0 -382
  130. package/dist/src/services/serverless-jobs.js +0 -1084
  131. package/dist/src/services/serverless-provider-keys.js +0 -409
  132. package/dist/src/services/serverless-records.js +0 -1515
  133. package/dist/src/services/serverless-template-configs.js +0 -75
  134. package/dist/src/services/storage.js +0 -461
  135. package/dist/src/services/swipe-customize.js +0 -437
  136. package/dist/src/services/template-certification.js +0 -413
  137. package/dist/src/services/template-loader.js +0 -99
  138. package/dist/src/services/template-runtime-bundles.js +0 -217
  139. package/dist/src/services/template-sources.js +0 -1017
  140. package/dist/src/services/upstream.js +0 -248
  141. package/dist/src/services/video-normalization.js +0 -2
  142. package/dist/src/services/webhooks.js +0 -62
  143. package/dist/src/template-editor-pages.js +0 -2576
  144. package/dist/src/template-editor-shell.js +0 -2893
  145. package/dist/src/template-sdk.js +0 -4
  146. package/dist/src/worker.js +0 -17
  147. package/public/assets/discover-client-app.js +0 -1
  148. package/public/assets/file-directory-app.js +0 -3
  149. package/public/assets/homepage-app.js +0 -54
  150. package/public/assets/homepage-client-app.js +0 -80
  151. package/public/assets/page-runtime-client-app.js +0 -94
  152. package/public/assets/placeholders/scene-placeholder.png +0 -0
  153. package/src/assets/SELLING_AWARENESS_STAGES.md +0 -579
  154. package/src/assets/SELLING_WITH_HOOKS.md +0 -377
  155. package/src/assets/SELLING_WITH_VSLS.md +0 -606
  156. package/src/assets/favicon.ico +0 -0
  157. package/src/assets/logo-vidfarm.png +0 -0
@@ -1,241 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { serverlessRecords } from "./serverless-records.js";
3
- import { createId } from "../lib/ids.js";
4
- import { config } from "../config.js";
5
- const BILLING_COST_EVENTS_PATH = "/v1/cost-events";
6
- const BILLING_WALLET_GRANTS_PATH = "/v1/wallet-grants";
7
- const PAID_SIGNUP_BONUS_GRANT_TYPE = "paid_signup_bonus";
8
- const PAID_SIGNUP_BONUS_USD = 5;
9
- export class BillingService {
10
- async getWalletSummary(customerId) {
11
- if (!config.VIDFARM_BILLING_URL || !config.VIDFARM_BILLING_SECRET) {
12
- throw new Error("Billing service is not configured.");
13
- }
14
- const response = await fetch(new URL(`/v1/wallets/${encodeURIComponent(customerId)}`, config.VIDFARM_BILLING_URL), {
15
- headers: {
16
- "x-vidfarm-billing-secret": config.VIDFARM_BILLING_SECRET
17
- }
18
- });
19
- if (!response.ok) {
20
- const body = await response.text().catch(() => "");
21
- throw new Error(`Billing wallet lookup failed (${response.status}): ${body || response.statusText}`);
22
- }
23
- const payload = await response.json();
24
- return {
25
- currency: typeof payload.currency === "string" ? payload.currency : "USD",
26
- balanceUsd: Number(payload.balance_usd ?? 0),
27
- balanceMicrosUsd: Number(payload.balance_micros_usd ?? 0)
28
- };
29
- }
30
- async getJobBillingSummary(input) {
31
- if (!config.VIDFARM_BILLING_URL || !config.VIDFARM_BILLING_SECRET) {
32
- return {
33
- currency: "USD",
34
- eventCount: 0,
35
- totalBaseCostUsd: 0,
36
- totalChargeUsd: 0,
37
- unavailableReason: "Billing service is not configured."
38
- };
39
- }
40
- const url = new URL(`/v1/jobs/${encodeURIComponent(input.jobId)}/billing`, config.VIDFARM_BILLING_URL);
41
- url.searchParams.set("customer_id", input.customerId);
42
- if (input.templateId) {
43
- url.searchParams.set("template_id", input.templateId);
44
- }
45
- const response = await fetch(url, {
46
- headers: {
47
- "x-vidfarm-billing-secret": config.VIDFARM_BILLING_SECRET
48
- }
49
- });
50
- if (!response.ok) {
51
- const body = await response.text().catch(() => "");
52
- throw new Error(`Billing job summary lookup failed (${response.status}): ${body || response.statusText}`);
53
- }
54
- const payload = await response.json();
55
- return {
56
- currency: typeof payload.currency === "string" ? payload.currency : "USD",
57
- eventCount: Number(payload.event_count ?? 0),
58
- totalBaseCostUsd: Number(payload.total_base_cost_usd ?? 0),
59
- totalChargeUsd: Number(payload.total_charge_usd ?? 0),
60
- unavailableReason: null
61
- };
62
- }
63
- async record(input) {
64
- const normalizedCostCenterSlug = resolveCostCenterSlug(input);
65
- const normalizedIdempotencyKey = resolveIdempotencyKey(input, normalizedCostCenterSlug);
66
- const remoteEventCostCenterSlug = normalizedCostCenterSlug ?? null;
67
- if (!remoteEventCostCenterSlug) {
68
- return;
69
- }
70
- if (!config.VIDFARM_BILLING_URL || !config.VIDFARM_BILLING_SECRET) {
71
- throw new Error(`Billing URL/secret missing for cost center ${remoteEventCostCenterSlug}.`);
72
- }
73
- const response = await fetch(new URL(BILLING_COST_EVENTS_PATH, config.VIDFARM_BILLING_URL), {
74
- method: "POST",
75
- headers: {
76
- "content-type": "application/json",
77
- "x-vidfarm-billing-secret": config.VIDFARM_BILLING_SECRET
78
- },
79
- body: JSON.stringify({
80
- idempotency_key: normalizedIdempotencyKey ?? `${remoteEventCostCenterSlug}:${input.jobId}:${input.templateId}:${input.type}`,
81
- customer_id: input.customerId,
82
- job_id: input.jobId,
83
- tracer: input.tracer,
84
- cost_center_slug: remoteEventCostCenterSlug,
85
- base_cost_usd: input.costUsd,
86
- metadata: {
87
- ...input.metadata,
88
- template_id: input.templateId,
89
- local_charge_usd: input.chargeUsd
90
- },
91
- occurred_at_ms: input.occurredAtMs ?? Date.now()
92
- })
93
- });
94
- if (!response.ok) {
95
- const body = await response.text().catch(() => "");
96
- throw new Error(`Billing service rejected cost event (${response.status}): ${body || response.statusText}`);
97
- }
98
- await response.json().catch(() => ({}));
99
- }
100
- async grantPaidSignupBonus(customerId, metadata) {
101
- const customer = await serverlessRecords.getCustomerById(customerId);
102
- if (!customer) {
103
- throw new Error("Customer not found.");
104
- }
105
- if (!customer.isPaidPlan) {
106
- return { granted: false, reason: "customer_not_paid" };
107
- }
108
- if (await serverlessRecords.hasCustomerCreditGrant(customerId, PAID_SIGNUP_BONUS_GRANT_TYPE)) {
109
- return { granted: false, reason: "already_granted" };
110
- }
111
- if (!config.VIDFARM_BILLING_URL || !config.VIDFARM_BILLING_SECRET) {
112
- throw new Error("Billing service is not configured.");
113
- }
114
- const response = await fetch(new URL(BILLING_WALLET_GRANTS_PATH, config.VIDFARM_BILLING_URL), {
115
- method: "POST",
116
- headers: {
117
- "content-type": "application/json",
118
- "x-vidfarm-billing-secret": config.VIDFARM_BILLING_SECRET
119
- },
120
- body: JSON.stringify({
121
- idempotency_key: `${PAID_SIGNUP_BONUS_GRANT_TYPE}:${customerId}`,
122
- customer_id: customerId,
123
- amount_usd: PAID_SIGNUP_BONUS_USD,
124
- grant_type: PAID_SIGNUP_BONUS_GRANT_TYPE,
125
- occurred_at_ms: Date.now(),
126
- metadata: {
127
- ...(metadata ?? {}),
128
- grant_type: PAID_SIGNUP_BONUS_GRANT_TYPE
129
- }
130
- })
131
- });
132
- if (!response.ok) {
133
- const body = await response.text().catch(() => "");
134
- throw new Error(`Billing service rejected signup wallet grant (${response.status}): ${body || response.statusText}`);
135
- }
136
- try {
137
- await serverlessRecords.insertCustomerCreditGrant({
138
- id: createId("grant"),
139
- customerId,
140
- grantType: PAID_SIGNUP_BONUS_GRANT_TYPE,
141
- amountUsd: PAID_SIGNUP_BONUS_USD,
142
- metadata: metadata ?? {}
143
- });
144
- }
145
- catch (error) {
146
- if (!isUniqueConstraintError(error)) {
147
- throw error;
148
- }
149
- }
150
- return {
151
- granted: true,
152
- reason: "granted",
153
- amountUsd: PAID_SIGNUP_BONUS_USD,
154
- grantType: PAID_SIGNUP_BONUS_GRANT_TYPE
155
- };
156
- }
157
- }
158
- function resolveCostCenterSlug(input) {
159
- if (input.costCenterSlug?.trim()) {
160
- const explicitSlug = input.costCenterSlug.trim();
161
- return explicitSlug === "hyperframes_lambda"
162
- || explicitSlug === "video_normalization"
163
- || explicitSlug === "rapidapi_video_download"
164
- || explicitSlug === "video_download_lambda"
165
- || explicitSlug === "video_ingest_lambda"
166
- || explicitSlug === "rapidapi_remove_background"
167
- // Local sharp chroma-key background removal + the 2-step media-overlay
168
- // primitive (BYOK image gen + chroma key): platform compute/convenience.
169
- || explicitSlug === "greenscreen_chroma_key"
170
- || explicitSlug === "media_overlay"
171
- // Platform ElevenLabs audio (music / TTS / STT) run on the wallet when the
172
- // caller opts into use_wallet_credits (the audio-primitive default).
173
- || explicitSlug === "elevenlabs_music"
174
- || explicitSlug === "elevenlabs_tts"
175
- || explicitSlug === "elevenlabs_stt"
176
- || explicitSlug === "primitive_media_lambda"
177
- || explicitSlug === "job_runner_lambda"
178
- || explicitSlug === "step_functions_standard"
179
- // Clip hunting (long-form → short-form): AWS compute only — the AI
180
- // tagging/embedding spend is BYOK and deliberately NOT wallet-billed.
181
- || explicitSlug === "clip_scan_lambda"
182
- ? explicitSlug
183
- : null;
184
- }
185
- return null;
186
- }
187
- function resolveIdempotencyKey(input, costCenterSlug) {
188
- if (input.idempotencyKey?.trim()) {
189
- return input.idempotencyKey.trim();
190
- }
191
- const renderId = typeof input.metadata?.render_id === "string"
192
- ? input.metadata.render_id
193
- : typeof input.metadata?.renderId === "string"
194
- ? input.metadata.renderId
195
- : null;
196
- if (costCenterSlug === "hyperframes_lambda" && renderId) {
197
- return `hyperframes_lambda:${renderId}`;
198
- }
199
- return buildBillingEventFingerprint(input, costCenterSlug);
200
- }
201
- function buildBillingEventFingerprint(input, costCenterSlug) {
202
- const fingerprintPayload = {
203
- customerId: input.customerId,
204
- jobId: input.jobId,
205
- templateId: input.templateId,
206
- tracer: input.tracer ?? null,
207
- type: input.type,
208
- costCenterSlug,
209
- costUsd: roundUsd(input.costUsd),
210
- chargeUsd: input.chargeUsd == null ? null : roundUsd(input.chargeUsd),
211
- occurredAtMs: input.occurredAtMs ?? null,
212
- metadata: sortJsonValue(input.metadata ?? {})
213
- };
214
- const digest = createHash("sha256")
215
- .update(JSON.stringify(fingerprintPayload))
216
- .digest("hex")
217
- .slice(0, 24);
218
- return `${costCenterSlug ?? input.type}:${input.jobId}:${digest}`;
219
- }
220
- function sortJsonValue(value) {
221
- if (Array.isArray(value)) {
222
- return value.map(sortJsonValue);
223
- }
224
- if (value && typeof value === "object") {
225
- return Object.entries(value)
226
- .sort(([left], [right]) => left.localeCompare(right))
227
- .reduce((acc, [key, nestedValue]) => {
228
- acc[key] = sortJsonValue(nestedValue);
229
- return acc;
230
- }, {});
231
- }
232
- return value;
233
- }
234
- function roundUsd(value) {
235
- return Number(value.toFixed(6));
236
- }
237
- function isUniqueConstraintError(error) {
238
- return Boolean(error instanceof Error && /unique constraint/i.test(error.message));
239
- }
240
- export { PAID_SIGNUP_BONUS_GRANT_TYPE, PAID_SIGNUP_BONUS_USD, resolveCostCenterSlug, resolveIdempotencyKey };
241
- //# sourceMappingURL=billing.js.map
@@ -1,127 +0,0 @@
1
- import { extractVideoFrameAsset } from "./media-processing.js";
2
- // ==========================================================================
3
- // Cast pass state — persisted per fork under
4
- // compositions/forks/{forkId}/working/cast.json
5
- // and copied on fork/clone/version so the identified cast (and its reference
6
- // stills) travel with every descendant composition. Drives the async
7
- // /cast-poll flow, mirroring the ghostcut.json state machine: /auto-decompose
8
- // seeds it "pending", and /cast-poll advances it one unit of work per call
9
- // (analyze -> per-member still -> per-member isolation -> done).
10
- //
11
- // The cast/ reference images live under the same public fork prefix, so their
12
- // URLs are directly fetchable by every user and by AI generation primitives
13
- // (as input_references / prompt_attachments) without a proxy hop.
14
- // ==========================================================================
15
- export const CAST_STATE_VERSION = 1;
16
- export function buildPendingCastState(input) {
17
- return {
18
- version: CAST_STATE_VERSION,
19
- status: "pending",
20
- stage: "analyze",
21
- savedAtMs: Date.now(),
22
- compositionId: input.compositionId,
23
- sourceUrl: input.sourceUrl,
24
- title: input.title,
25
- provider: null,
26
- model: null,
27
- durationSeconds: 0,
28
- width: 0,
29
- height: 0,
30
- members: []
31
- };
32
- }
33
- export function castMemberFromRaw(raw) {
34
- return {
35
- slug: raw.slug,
36
- name: raw.name,
37
- role: raw.role,
38
- description: raw.description,
39
- wardrobe: raw.wardrobe,
40
- appears_in: raw.appears_in,
41
- best_frame_ms: Math.max(0, Math.round(raw.best_frame_seconds * 1000)),
42
- bbox: raw.bbox,
43
- is_primary: raw.is_primary,
44
- still_url: null,
45
- reference_url: null,
46
- status: "pending"
47
- };
48
- }
49
- // The registry's default image model per provider is module-private; mirror it
50
- // here so the cast isolation edit picks a supported model without importing
51
- // the whole primitive registry.
52
- function defaultImageModelForProvider(provider) {
53
- switch (provider) {
54
- case "gemini":
55
- return "gemini-2.5-flash-image";
56
- case "openrouter":
57
- return "google/gemini-2.5-flash-image-preview";
58
- default:
59
- return "gpt-image-2";
60
- }
61
- }
62
- // Pick the customer's best available image-capable provider. Order mirrors the
63
- // vision fallback (gemini -> openai -> openrouter). perplexity has no image
64
- // capability so it's never a candidate.
65
- export function pickImageProvider(keys) {
66
- if (keys.gemini)
67
- return "gemini";
68
- if (keys.openai)
69
- return "openai";
70
- if (keys.openrouter)
71
- return "openrouter";
72
- return null;
73
- }
74
- function describeBbox(bbox) {
75
- if (!bbox)
76
- return "";
77
- const pct = (v) => `${Math.round(v * 100)}%`;
78
- const cx = bbox.x + bbox.width / 2;
79
- const horizontal = cx < 0.34 ? "on the left" : cx > 0.66 ? "on the right" : "in the center";
80
- return ` They are located ${horizontal} of the frame (roughly x=${pct(bbox.x)}, y=${pct(bbox.y)}, width=${pct(bbox.width)}, height=${pct(bbox.height)}).`;
81
- }
82
- export function buildCastIsolationInstruction(member) {
83
- const wardrobe = member.wardrobe ? ` They are wearing: ${member.wardrobe}.` : "";
84
- return [
85
- `Isolate ONLY the single person described as: ${member.description}.${wardrobe}${describeBbox(member.bbox)}`,
86
- "Cut that one person out cleanly and place them on a fully transparent background.",
87
- "Preserve their exact face, hairstyle, skin tone, body proportions, and clothing without alteration.",
88
- "Remove every other person and the entire original background. If multiple people are present, keep only the described one.",
89
- "Output a single-subject cutout suitable for reuse as a character reference."
90
- ].join(" ");
91
- }
92
- // Extracts the best-frame still for a member and stores it under the fork's
93
- // public working/cast/ prefix. Returns the public URL (or null if the key is
94
- // not in a public prefix, which shouldn't happen for fork keys).
95
- export async function extractCastStill(input) {
96
- const frame = await extractVideoFrameAsset({
97
- sourceUrl: input.sourceUrl,
98
- atMs: input.member.best_frame_ms,
99
- format: "png"
100
- });
101
- const key = input.storage.compositionForkWorkingKey(input.forkId, `cast/${input.member.slug}-still.png`);
102
- const stored = await input.storage.putBuffer(key, frame.bytes, frame.contentType);
103
- return { url: stored.url ?? input.storage.getPublicUrl(key) };
104
- }
105
- // Runs the image-edit "isolate this person on transparent background" pass over
106
- // the extracted still and stores the cutout under the fork's public prefix.
107
- // There is no true person-segmentation primitive in the platform, so this
108
- // approximates instance masking via a prompt-driven edit (bbox-guided).
109
- export async function isolateCastMember(input) {
110
- const provider = pickImageProvider(input.keys);
111
- if (!provider) {
112
- throw new Error("No image-capable provider key available for cast isolation");
113
- }
114
- const edited = await input.providers.editImage({
115
- customerId: input.customerId,
116
- jobId: input.jobId,
117
- workerId: `cast-isolate:${input.member.slug}`,
118
- provider,
119
- model: defaultImageModelForProvider(provider),
120
- sourceImageUrl: input.stillUrl,
121
- instruction: buildCastIsolationInstruction(input.member)
122
- });
123
- const key = input.storage.compositionForkWorkingKey(input.forkId, `cast/${input.member.slug}.png`);
124
- const stored = await input.storage.putBuffer(key, edited.bytes, edited.contentType ?? "image/png");
125
- return { url: stored.url ?? input.storage.getPublicUrl(key) };
126
- }
127
- //# sourceMappingURL=cast.js.map
@@ -1,92 +0,0 @@
1
- import { createId } from "../lib/ids.js";
2
- import { nowIso } from "../lib/time.js";
3
- import { serverlessRecords } from "./serverless-records.js";
4
- import { StorageService } from "./storage.js";
5
- const storage = new StorageService();
6
- function normalizeTracerList(values) {
7
- return [...new Set(values.map((value) => value.trim()).filter(Boolean))];
8
- }
9
- function buildThreadStoragePrefix(customerId, templateId, threadId) {
10
- return storage.developerScopedKey(customerId, "chat-threads", templateId, threadId);
11
- }
12
- function buildThreadChunkKey(prefix, createdAt) {
13
- const sortableTime = createdAt.replace(/[^0-9]/g, "");
14
- return `${prefix}/chunks/${sortableTime}-${createId("chunk")}.json`;
15
- }
16
- async function readChunkMessages(key) {
17
- const raw = await storage.readText(key);
18
- if (!raw) {
19
- return [];
20
- }
21
- const parsed = JSON.parse(raw);
22
- return Array.isArray(parsed.messages) ? parsed.messages : [];
23
- }
24
- export const chatThreads = {
25
- async listThreads(input) {
26
- const threads = await serverlessRecords.listChatThreadMetas(input);
27
- if (input.includeMessages === false) {
28
- return threads;
29
- }
30
- const withMessages = await Promise.all(threads.map(async (thread) => ({
31
- ...thread,
32
- messages: await this.loadThreadMessages(thread)
33
- })));
34
- return withMessages;
35
- },
36
- async getThread(input) {
37
- const thread = await serverlessRecords.getChatThreadMeta(input.customerId, input.threadId);
38
- if (!thread) {
39
- return null;
40
- }
41
- return {
42
- ...thread,
43
- messages: await this.loadThreadMessages(thread)
44
- };
45
- },
46
- async appendExchange(input) {
47
- const createdAt = nowIso();
48
- const storagePrefix = buildThreadStoragePrefix(input.customerId, input.templateId, input.threadId);
49
- const chunk = {
50
- version: 1,
51
- threadId: input.threadId,
52
- customerId: input.customerId,
53
- templateId: input.templateId,
54
- createdAt,
55
- messages: input.messages
56
- };
57
- await storage.putJson(buildThreadChunkKey(storagePrefix, createdAt), chunk);
58
- const updated = await serverlessRecords.appendChatThreadMessages({
59
- threadId: input.threadId,
60
- customerId: input.customerId,
61
- title: input.title || "New chat",
62
- templateId: input.templateId,
63
- storagePrefix,
64
- tracers: normalizeTracerList(input.tracers),
65
- messageCountDelta: input.messages.length,
66
- lastMessageAt: createdAt
67
- });
68
- return updated ? this.getThread({ customerId: input.customerId, threadId: updated.id }) : null;
69
- },
70
- async updateThread(input) {
71
- const updated = await serverlessRecords.updateChatThreadState({
72
- ...input,
73
- tracers: input.tracers ? normalizeTracerList(input.tracers) : undefined
74
- });
75
- return updated ? this.getThread({ customerId: input.customerId, threadId: updated.id }) : null;
76
- },
77
- async deleteThread(input) {
78
- const existing = await serverlessRecords.deleteChatThread(input.customerId, input.threadId);
79
- if (!existing) {
80
- return null;
81
- }
82
- const keys = await storage.listKeys(`${existing.storagePrefix}/`);
83
- await Promise.all(keys.map((key) => storage.deleteObject(key)));
84
- return existing;
85
- },
86
- async loadThreadMessages(thread) {
87
- const keys = (await storage.listKeys(`${thread.storagePrefix}/chunks/`)).sort();
88
- const messageGroups = await Promise.all(keys.map((key) => readChunkMessages(key)));
89
- return messageGroups.flat();
90
- }
91
- };
92
- //# sourceMappingURL=chat-threads.js.map