@mevdragon/vidfarm-devcli 0.5.3 → 0.7.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.
Files changed (116) hide show
  1. package/README.md +3 -3
  2. package/SKILL.director.md +28 -7
  3. package/SKILL.platform.md +9 -5
  4. package/demo/README.md +28 -0
  5. package/demo/dist/app.css +1 -0
  6. package/demo/dist/app.js +1184 -0
  7. package/demo/dist/chunks/chunk-DXB73IDG.js +1 -0
  8. package/demo/dist/chunks/chunk-S7OWAJDS.js +36 -0
  9. package/demo/dist/chunks/chunk-VTIBZ6AN.js +1 -0
  10. package/demo/dist/chunks/dist-ADSJKBVE.js +332 -0
  11. package/demo/dist/chunks/domEditingLayers-VZMLL4AP-SGHWPND4.js +1 -0
  12. package/demo/dist/chunks/hyperframes-player-XB65TCD6.js +425 -0
  13. package/demo/dist/chunks/lib-XAQ37YOE.js +1 -0
  14. package/demo/dist/chunks/src-TJ2QYA4U.js +207 -0
  15. package/demo/dist/favicon.ico +0 -0
  16. package/demo/dist/icons/timeline/audio.svg +7 -0
  17. package/demo/dist/icons/timeline/captions.svg +5 -0
  18. package/demo/dist/icons/timeline/composition.svg +12 -0
  19. package/demo/dist/icons/timeline/image.svg +18 -0
  20. package/demo/dist/icons/timeline/music.svg +10 -0
  21. package/demo/dist/icons/timeline/text.svg +3 -0
  22. package/demo/dist/index.html +15 -0
  23. package/dist/src/account-pages-legacy.js +9396 -0
  24. package/dist/src/account-pages.js +61 -0
  25. package/dist/src/app.js +14663 -0
  26. package/dist/src/cli.js +60 -97
  27. package/dist/src/composition-runtime.js +613 -0
  28. package/dist/src/config.js +173 -0
  29. package/dist/src/context.js +447 -0
  30. package/dist/src/dev-app-legacy.js +739 -0
  31. package/dist/src/dev-app.js +6 -0
  32. package/dist/src/domain.js +2 -0
  33. package/dist/src/editor-chat-history.js +82 -0
  34. package/dist/src/editor-chat.js +449 -0
  35. package/dist/src/editor-dark-theme.js +1128 -0
  36. package/dist/src/frontend/debug.js +71 -0
  37. package/dist/src/frontend/flockposter-cache-store.js +124 -0
  38. package/dist/src/frontend/homepage-client.js +182 -0
  39. package/dist/src/frontend/homepage-shared.js +4 -0
  40. package/dist/src/frontend/homepage-store.js +28 -0
  41. package/dist/src/frontend/homepage-view.js +547 -0
  42. package/dist/src/frontend/page-runtime-client.js +132 -0
  43. package/dist/src/frontend/page-runtime-store.js +9 -0
  44. package/dist/src/frontend/sentry.js +42 -0
  45. package/dist/src/frontend/template-editor-chat.js +3960 -0
  46. package/dist/src/help-page.js +346 -0
  47. package/dist/src/homepage.js +1235 -0
  48. package/dist/src/hyperframes/composition.js +180 -0
  49. package/dist/src/index.js +16 -0
  50. package/dist/src/instrument.js +30 -0
  51. package/dist/src/lib/crypto.js +45 -0
  52. package/dist/src/lib/dev-log.js +54 -0
  53. package/dist/src/lib/display-name.js +11 -0
  54. package/dist/src/lib/ids.js +24 -0
  55. package/dist/src/lib/images.js +19 -0
  56. package/dist/src/lib/json.js +15 -0
  57. package/dist/src/lib/package-root.js +47 -0
  58. package/dist/src/lib/template-paths.js +28 -0
  59. package/dist/src/lib/time.js +7 -0
  60. package/dist/src/lib/url-clean.js +85 -0
  61. package/dist/src/page-runtime.js +2 -0
  62. package/dist/src/page-shell.js +1381 -0
  63. package/dist/src/primitive-context.js +357 -0
  64. package/dist/src/primitive-registry.js +2561 -0
  65. package/dist/src/primitive-sdk.js +4 -0
  66. package/dist/src/primitives/hyperframes-media.js +108 -0
  67. package/dist/src/react-page-shell.js +35 -0
  68. package/dist/src/ready-post-schedule-component.js +1540 -0
  69. package/dist/src/registry.js +296 -0
  70. package/dist/src/runtime.js +35 -0
  71. package/dist/src/services/api-call-history.js +249 -0
  72. package/dist/src/services/auth.js +152 -0
  73. package/dist/src/services/billing-pricing.js +39 -0
  74. package/dist/src/services/billing.js +228 -0
  75. package/dist/src/services/cast.js +127 -0
  76. package/dist/src/services/chat-threads.js +92 -0
  77. package/dist/src/services/composition-sanitize.js +124 -0
  78. package/dist/src/services/composition-watch.js +79 -0
  79. package/dist/src/services/fork-access.js +93 -0
  80. package/dist/src/services/fork-manifest.js +42 -0
  81. package/dist/src/services/ghostcut.js +179 -0
  82. package/dist/src/services/hyperframes.js +2307 -0
  83. package/dist/src/services/job-capacity.js +14 -0
  84. package/dist/src/services/job-logs.js +197 -0
  85. package/dist/src/services/jobs.js +136 -0
  86. package/dist/src/services/local-dynamo.js +0 -0
  87. package/dist/src/services/media-processing.js +766 -0
  88. package/dist/src/services/primitive-media-lambda.js +280 -0
  89. package/dist/src/services/providers.js +2926 -0
  90. package/dist/src/services/rate-limits.js +262 -0
  91. package/dist/src/services/serverless-auth.js +382 -0
  92. package/dist/src/services/serverless-jobs.js +1082 -0
  93. package/dist/src/services/serverless-provider-keys.js +409 -0
  94. package/dist/src/services/serverless-records.js +1385 -0
  95. package/dist/src/services/serverless-template-configs.js +75 -0
  96. package/dist/src/services/storage.js +383 -0
  97. package/dist/src/services/template-certification.js +413 -0
  98. package/dist/src/services/template-loader.js +99 -0
  99. package/dist/src/services/template-runtime-bundles.js +217 -0
  100. package/dist/src/services/template-sources.js +1017 -0
  101. package/dist/src/services/upstream.js +248 -0
  102. package/dist/src/services/video-normalization.js +2 -0
  103. package/dist/src/services/webhooks.js +62 -0
  104. package/dist/src/template-editor-pages.js +2576 -0
  105. package/dist/src/template-editor-shell.js +2840 -0
  106. package/dist/src/template-sdk.js +4 -0
  107. package/dist/src/worker.js +17 -0
  108. package/package.json +6 -4
  109. package/public/assets/homepage-app.js +54 -0
  110. package/public/assets/homepage-client-app.js +80 -0
  111. package/public/assets/page-runtime-client-app.js +94 -0
  112. package/src/assets/SELLING_AWARENESS_STAGES.md +579 -0
  113. package/src/assets/SELLING_WITH_HOOKS.md +377 -0
  114. package/src/assets/SELLING_WITH_VSLS.md +606 -0
  115. package/src/assets/favicon.ico +0 -0
  116. package/src/assets/logo-vidfarm.png +0 -0
@@ -0,0 +1,248 @@
1
+ import { config } from "../config.js";
2
+ import { StorageService } from "./storage.js";
3
+ import { serverlessRecords } from "./serverless-records.js";
4
+ // Cloud passthrough for `vidfarm serve`. A locally-booted box keeps the
5
+ // editor, storage, and render fully local, but mirrors the upstream (prod)
6
+ // deployment for everything catalog-shaped: /discover and /library list the
7
+ // cloud data, templates/forks seed onto local disk on demand, and a render
8
+ // can be handed off to the cloud renderer. The upstream host + API key are
9
+ // injected by the serve command (VIDFARM_UPSTREAM_HOST / _API_KEY); deployed
10
+ // environments never set them, so every helper here is a no-op in the cloud.
11
+ const UPSTREAM_TIMEOUT_MS = 15_000;
12
+ export function upstreamHost() {
13
+ const raw = (config.VIDFARM_UPSTREAM_HOST ?? "").trim().replace(/\/+$/, "");
14
+ if (!raw)
15
+ return null;
16
+ if (!/^https?:\/\//i.test(raw))
17
+ return null;
18
+ return raw;
19
+ }
20
+ // Passthrough only ever activates on a fully-local box. STORAGE_DRIVER=local
21
+ // is the serve fingerprint (same signal the editor's liveReload uses).
22
+ export function isUpstreamEnabled() {
23
+ return config.STORAGE_DRIVER === "local" && Boolean(upstreamHost());
24
+ }
25
+ export function upstreamApiKey() {
26
+ const key = (config.VIDFARM_UPSTREAM_API_KEY ?? "").trim();
27
+ return key || null;
28
+ }
29
+ export function hasUpstreamKey() {
30
+ return isUpstreamEnabled() && Boolean(upstreamApiKey());
31
+ }
32
+ export function upstreamAuthHeaders(extra) {
33
+ const headers = { accept: "application/json", ...(extra ?? {}) };
34
+ const key = upstreamApiKey();
35
+ if (key)
36
+ headers["vidfarm-api-key"] = key;
37
+ return headers;
38
+ }
39
+ // One-shot JSON fetch against the upstream host. Never throws on HTTP or
40
+ // network errors — callers treat a failed upstream as "no cloud data" and
41
+ // fall back to local-only behavior.
42
+ export async function upstreamJson(pathWithQuery, init) {
43
+ const host = upstreamHost();
44
+ if (!host)
45
+ return { ok: false, status: 0, json: null };
46
+ try {
47
+ const response = await fetch(`${host}${pathWithQuery}`, {
48
+ method: init?.method ?? "GET",
49
+ headers: upstreamAuthHeaders(init?.body !== undefined ? { "content-type": "application/json" } : undefined),
50
+ body: init?.body !== undefined ? JSON.stringify(init.body) : undefined,
51
+ signal: AbortSignal.timeout(init?.timeoutMs ?? UPSTREAM_TIMEOUT_MS)
52
+ });
53
+ const json = await response.json().catch(() => null);
54
+ return { ok: response.ok, status: response.status, json };
55
+ }
56
+ catch (error) {
57
+ console.warn(`[upstream] ${init?.method ?? "GET"} ${pathWithQuery} failed: ${error instanceof Error ? error.message : String(error)}`);
58
+ return { ok: false, status: 0, json: null };
59
+ }
60
+ }
61
+ // Forward the incoming request to the same path on the upstream host with the
62
+ // upstream API key swapped in for the local session. Used as a fallback when
63
+ // a resource id (approved post, inspiration) doesn't resolve locally — the id
64
+ // then almost certainly belongs to the cloud account this box mirrors.
65
+ // requireKey defaults to true so authed reads/mutations never proxy without
66
+ // cloud credentials; public-data GET fallbacks pass requireKey: false.
67
+ export async function proxyRequestToUpstream(c, options) {
68
+ const host = upstreamHost();
69
+ if (!host || !isUpstreamEnabled())
70
+ return null;
71
+ if ((options?.requireKey ?? true) && !hasUpstreamKey())
72
+ return null;
73
+ const incoming = new URL(c.req.url);
74
+ const target = `${host}${incoming.pathname}${incoming.search}`;
75
+ const method = c.req.method.toUpperCase();
76
+ const headers = upstreamAuthHeaders();
77
+ let body;
78
+ if (method !== "GET" && method !== "HEAD") {
79
+ body = await c.req.text().catch(() => "");
80
+ const contentType = c.req.header("content-type");
81
+ if (contentType)
82
+ headers["content-type"] = contentType;
83
+ }
84
+ try {
85
+ const response = await fetch(target, {
86
+ method,
87
+ headers,
88
+ body,
89
+ signal: AbortSignal.timeout(UPSTREAM_TIMEOUT_MS)
90
+ });
91
+ const payload = Buffer.from(await response.arrayBuffer());
92
+ return new Response(payload, {
93
+ status: response.status,
94
+ headers: {
95
+ "content-type": response.headers.get("content-type") ?? "application/json",
96
+ "x-vidfarm-upstream": host
97
+ }
98
+ });
99
+ }
100
+ catch (error) {
101
+ console.warn(`[upstream] proxy ${method} ${incoming.pathname} failed: ${error instanceof Error ? error.message : String(error)}`);
102
+ return null;
103
+ }
104
+ }
105
+ // ---------------------------------------------------------------------------
106
+ // On-demand seeding: pull a cloud fork's composition onto local disk and mint
107
+ // the matching local template + fork records so the local editor resolves it.
108
+ // Same behavior as `vidfarm serve <templateId>` boot seeding, but callable
109
+ // from the /editor route when the user clicks a proxied catalog entry.
110
+ // ---------------------------------------------------------------------------
111
+ function seedAuthHeaders(shareToken) {
112
+ const headers = { accept: "text/html,application/json" };
113
+ const key = upstreamApiKey();
114
+ if (key)
115
+ headers["vidfarm-api-key"] = key;
116
+ if (shareToken)
117
+ headers["vidfarm-share-token"] = shareToken;
118
+ return headers;
119
+ }
120
+ // /editor/<template_id> issues a 302 → /editor/<template_id>?fork=<id>
121
+ // whenever the caller (or the template's default fork) has one. Follow the
122
+ // redirect once by hand so we can read the fork id off the query string.
123
+ async function resolveUpstreamForkId(input) {
124
+ try {
125
+ const res = await fetch(`${input.host}/editor/${encodeURIComponent(input.templateId)}`, {
126
+ method: "GET",
127
+ redirect: "manual",
128
+ headers: seedAuthHeaders(input.shareToken),
129
+ signal: AbortSignal.timeout(UPSTREAM_TIMEOUT_MS)
130
+ });
131
+ if (res.status >= 300 && res.status < 400) {
132
+ const location = res.headers.get("location");
133
+ if (location) {
134
+ const target = new URL(location, input.host);
135
+ const fork = target.searchParams.get("fork");
136
+ if (fork)
137
+ return fork;
138
+ }
139
+ }
140
+ }
141
+ catch {
142
+ // fall through to null — caller starts empty
143
+ }
144
+ return null;
145
+ }
146
+ // Best-effort: returns null (and logs) instead of throwing so callers can
147
+ // fall back to their template-not-found behavior.
148
+ export async function seedFromUpstream(input) {
149
+ const host = upstreamHost();
150
+ if (!host || !isUpstreamEnabled())
151
+ return null;
152
+ const storage = new StorageService();
153
+ const headers = seedAuthHeaders(input.shareToken);
154
+ // 1. Resolve the source fork: explicit fork wins, else the template's
155
+ // default fork (grabs the shared decomposition even if another user owns it).
156
+ let cloudForkId = input.forkId ?? null;
157
+ if (!cloudForkId && input.templateId) {
158
+ cloudForkId = await resolveUpstreamForkId({ host, templateId: input.templateId, shareToken: input.shareToken });
159
+ }
160
+ if (!cloudForkId) {
161
+ console.warn(`[upstream] seed: no fork resolvable for template ${input.templateId ?? "<none>"}`);
162
+ return null;
163
+ }
164
+ // 2. Read the serialized fork for its template id + title.
165
+ const forkMeta = (await upstreamJson(`/api/v1/compositions/${encodeURIComponent(cloudForkId)}`)).json;
166
+ const templateId = input.templateId ?? (typeof forkMeta?.template_id === "string" ? forkMeta.template_id : null);
167
+ if (!templateId || !templateId.startsWith("template_")) {
168
+ console.warn(`[upstream] seed: could not determine a template id for fork ${cloudForkId}`);
169
+ return null;
170
+ }
171
+ const title = (typeof forkMeta?.title === "string" && forkMeta.title) || `Local · ${templateId}`;
172
+ // 3. Materialize the local template record (the editor 404s without it).
173
+ const existingTemplate = await serverlessRecords.getTemplate(templateId);
174
+ if (!existingTemplate) {
175
+ await serverlessRecords.createTemplate({
176
+ id: templateId,
177
+ inspirationId: `local:${templateId}`,
178
+ customerId: input.customerId,
179
+ originalUrl: typeof forkMeta?.original_url === "string" ? forkMeta.original_url : "",
180
+ sourceHost: "local",
181
+ title,
182
+ visibility: "public"
183
+ });
184
+ }
185
+ // 4. Materialize the local fork (reuse the cloud id for stable URLs — the
186
+ // shared id is also what lets a later "Render in Cloud" find its source).
187
+ const existingFork = await serverlessRecords.getCompositionFork(cloudForkId);
188
+ if (!existingFork) {
189
+ await serverlessRecords.createCompositionFork({
190
+ id: cloudForkId,
191
+ customerId: input.customerId,
192
+ templateId,
193
+ title,
194
+ visibility: "private"
195
+ });
196
+ }
197
+ // 5. Pull composition.html/json onto disk (skip if present unless refetch,
198
+ // so local edits aren't clobbered).
199
+ const htmlKey = storage.compositionForkWorkingKey(cloudForkId, "composition.html");
200
+ const jsonKey = storage.compositionForkWorkingKey(cloudForkId, "composition.json");
201
+ const hasLocalHtml = Boolean(await storage.readText(htmlKey));
202
+ if (!hasLocalHtml || input.refetch) {
203
+ try {
204
+ const htmlRes = await fetch(`${host}/api/v1/compositions/${encodeURIComponent(cloudForkId)}/composition.html`, {
205
+ headers,
206
+ signal: AbortSignal.timeout(UPSTREAM_TIMEOUT_MS)
207
+ });
208
+ if (!htmlRes.ok) {
209
+ console.warn(`[upstream] seed: could not fetch composition.html for ${cloudForkId} (${htmlRes.status})`);
210
+ return null;
211
+ }
212
+ const compositionHtml = await htmlRes.text();
213
+ await storage.putText(htmlKey, compositionHtml, "text/html; charset=utf-8");
214
+ // Backfill the local template's preview metadata from the composition
215
+ // itself (no single-template REST read exists) so the seeded copy also
216
+ // renders a card on the LOCAL /discover feed.
217
+ const sourceVideoMatch = compositionHtml.match(/data-source-video="([^"]+)"/i);
218
+ const durationMatch = compositionHtml.match(/data-duration="([^"]+)"/i);
219
+ const template = await serverlessRecords.getTemplate(templateId);
220
+ if (template && !template.videoUrl && sourceVideoMatch?.[1]) {
221
+ const durationSeconds = durationMatch ? Number.parseFloat(durationMatch[1]) : NaN;
222
+ await serverlessRecords.updateTemplate({
223
+ templateId,
224
+ patch: {
225
+ videoUrl: sourceVideoMatch[1].replace(/&amp;/g, "&"),
226
+ ...(Number.isFinite(durationSeconds) && durationSeconds > 0 ? { durationSeconds } : {})
227
+ }
228
+ }).catch(() => undefined);
229
+ }
230
+ const jsonRes = await fetch(`${host}/api/v1/compositions/${encodeURIComponent(cloudForkId)}/composition.json`, {
231
+ headers,
232
+ signal: AbortSignal.timeout(UPSTREAM_TIMEOUT_MS)
233
+ });
234
+ if (jsonRes.ok)
235
+ await storage.putBuffer(jsonKey, Buffer.from(await jsonRes.text(), "utf8"), "application/json");
236
+ console.log(`[upstream] seeded fork ${cloudForkId} from ${host}`);
237
+ }
238
+ catch (error) {
239
+ console.warn(`[upstream] seed: composition fetch failed for ${cloudForkId}: ${error instanceof Error ? error.message : String(error)}`);
240
+ return null;
241
+ }
242
+ }
243
+ // 6. Point the template's default fork at the local copy so a bare
244
+ // /editor/:templateId resolves it too.
245
+ await serverlessRecords.stampDefaultForkIfUnset({ templateId, forkId: cloudForkId });
246
+ return { templateId, forkId: cloudForkId };
247
+ }
248
+ //# sourceMappingURL=upstream.js.map
@@ -0,0 +1,2 @@
1
+ export { estimateNormalizationCostUsd, normalizeVideoAsset } from "./media-processing.js";
2
+ //# sourceMappingURL=video-normalization.js.map
@@ -0,0 +1,62 @@
1
+ import { createHmac } from "node:crypto";
2
+ import { config } from "../config.js";
3
+ import { serverlessRecords } from "./serverless-records.js";
4
+ import { createId } from "../lib/ids.js";
5
+ import { addSeconds, nowIso } from "../lib/time.js";
6
+ export class WebhookService {
7
+ async queueJobEvent(input) {
8
+ await serverlessRecords.queueWebhookDelivery({
9
+ id: createId("whd"),
10
+ jobId: input.jobId,
11
+ customerId: input.customerId,
12
+ destinationUrl: input.destinationUrl,
13
+ eventType: input.eventType,
14
+ payload: input.payload
15
+ });
16
+ }
17
+ async flushPending(limit = 20) {
18
+ const deliveries = await serverlessRecords.listPendingWebhookDeliveries(limit);
19
+ for (const delivery of deliveries) {
20
+ const payload = String(delivery.payload_json);
21
+ const signature = createHmac("sha256", config.WEBHOOK_SECRET).update(payload).digest("hex");
22
+ const attemptCount = Number(delivery.attempt_count) + 1;
23
+ try {
24
+ const response = await fetch(String(delivery.destination_url), {
25
+ method: "POST",
26
+ headers: {
27
+ "Content-Type": "application/json",
28
+ "x-vidfarm-signature": signature,
29
+ "x-vidfarm-event": String(delivery.event_type)
30
+ },
31
+ body: payload
32
+ });
33
+ if (!response.ok) {
34
+ throw new Error(`Webhook returned ${response.status}`);
35
+ }
36
+ await serverlessRecords.markWebhookDelivery({
37
+ id: String(delivery.id),
38
+ status: "delivered",
39
+ attemptCount
40
+ });
41
+ }
42
+ catch (error) {
43
+ const retriesLeft = attemptCount < 6;
44
+ await serverlessRecords.markWebhookDelivery({
45
+ id: String(delivery.id),
46
+ status: retriesLeft ? "retrying" : "failed",
47
+ attemptCount,
48
+ nextAttemptAt: retriesLeft ? addSeconds(new Date(), Math.min(300, attemptCount * 30)) : undefined,
49
+ lastError: error instanceof Error ? error.message : "Unknown webhook error"
50
+ });
51
+ }
52
+ }
53
+ }
54
+ buildJobPayload(eventType, job) {
55
+ return {
56
+ type: eventType,
57
+ emitted_at: nowIso(),
58
+ job
59
+ };
60
+ }
61
+ }
62
+ //# sourceMappingURL=webhooks.js.map