@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,217 @@
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync, mkdirSync, readdirSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { gunzipSync } from "node:zlib";
6
+ import { devLog } from "../lib/dev-log.js";
7
+ import { loadTemplateFromModule } from "./template-loader.js";
8
+ import { StorageService } from "./storage.js";
9
+ const storage = new StorageService();
10
+ const releaseCache = new Map();
11
+ const MAX_EXTRACTED_RUNTIME_RELEASES = 6;
12
+ export async function loadTemplateFromRuntimeRelease(release) {
13
+ const cacheKey = `${release.id}:${release.commitSha}:${release.runtimeArtifactSha256 ?? "local"}`;
14
+ const existing = releaseCache.get(cacheKey);
15
+ if (existing) {
16
+ return existing;
17
+ }
18
+ const loadPromise = loadRuntimeReleaseUncached(release);
19
+ releaseCache.set(cacheKey, loadPromise);
20
+ try {
21
+ return await loadPromise;
22
+ }
23
+ catch (error) {
24
+ releaseCache.delete(cacheKey);
25
+ throw error;
26
+ }
27
+ }
28
+ async function loadRuntimeReleaseUncached(release) {
29
+ if (release.runtimeArtifactKey) {
30
+ const checkoutPath = await extractRuntimeArtifact(release);
31
+ const modulePath = path.join(checkoutPath, release.runtimeModulePath ?? relativeModulePath(release));
32
+ devLog("template_runtime.release.loading", {
33
+ release_id: release.id,
34
+ template_id: release.templateId,
35
+ runtime_artifact_key: release.runtimeArtifactKey,
36
+ module_path: modulePath
37
+ });
38
+ const template = await loadTemplateFromModule(modulePath);
39
+ return {
40
+ ...template,
41
+ skillPath: path.join(checkoutPath, relativeSkillPath(release))
42
+ };
43
+ }
44
+ if (release.modulePath && existsSync(release.modulePath)) {
45
+ devLog("template_runtime.release.local_loading", {
46
+ release_id: release.id,
47
+ template_id: release.templateId,
48
+ module_path: release.modulePath
49
+ });
50
+ const template = await loadTemplateFromModule(release.modulePath);
51
+ return {
52
+ ...template,
53
+ skillPath: release.skillPath
54
+ };
55
+ }
56
+ throw new Error(`Active template release ${release.id} has no runtime artifact and no local module path.`);
57
+ }
58
+ async function extractRuntimeArtifact(release) {
59
+ const root = path.join(os.tmpdir(), "vidfarm-template-releases");
60
+ const checkoutPath = path.join(root, `${safePathSegment(release.templateId)}-${safePathSegment(release.commitSha)}`);
61
+ const markerPath = path.join(checkoutPath, ".vidfarm-runtime-ready");
62
+ if (existsSync(markerPath)) {
63
+ return checkoutPath;
64
+ }
65
+ const archive = await storage.readBuffer(String(release.runtimeArtifactKey));
66
+ if (!archive) {
67
+ throw new Error(`Runtime template artifact not found: ${release.runtimeArtifactKey}`);
68
+ }
69
+ const sha256 = createHash("sha256").update(archive).digest("hex");
70
+ if (release.runtimeArtifactSha256 && sha256 !== release.runtimeArtifactSha256) {
71
+ throw new Error(`Runtime template artifact hash mismatch for ${release.runtimeArtifactKey}.`);
72
+ }
73
+ try {
74
+ extractRuntimeArtifactToPath({ archive, root, checkoutPath, markerPath, release, sha256 });
75
+ }
76
+ catch (error) {
77
+ if (!isNoSpaceError(error)) {
78
+ throw error;
79
+ }
80
+ devLog("template_runtime.release.extract_enospc_retry", {
81
+ release_id: release.id,
82
+ template_id: release.templateId,
83
+ checkout_path: checkoutPath
84
+ });
85
+ pruneExtractedRuntimeArtifacts(root, checkoutPath, 0);
86
+ extractRuntimeArtifactToPath({ archive, root, checkoutPath, markerPath, release, sha256 });
87
+ }
88
+ return checkoutPath;
89
+ }
90
+ function extractRuntimeArtifactToPath(input) {
91
+ mkdirSync(input.root, { recursive: true });
92
+ pruneExtractedRuntimeArtifacts(input.root, input.checkoutPath, MAX_EXTRACTED_RUNTIME_RELEASES);
93
+ rmSync(input.checkoutPath, { recursive: true, force: true });
94
+ mkdirSync(input.checkoutPath, { recursive: true });
95
+ extractTarGzBuffer(input.archive, input.checkoutPath);
96
+ linkSharedNodeModules(input.checkoutPath);
97
+ writeFileSync(input.markerPath, JSON.stringify({
98
+ release_id: input.release.id,
99
+ template_id: input.release.templateId,
100
+ commit_sha: input.release.commitSha,
101
+ runtime_artifact_key: input.release.runtimeArtifactKey,
102
+ runtime_artifact_sha256: input.sha256,
103
+ extracted_at: new Date().toISOString()
104
+ }, null, 2));
105
+ devLog("template_runtime.release.extracted", {
106
+ release_id: input.release.id,
107
+ template_id: input.release.templateId,
108
+ checkout_path: input.checkoutPath,
109
+ runtime_artifact_key: input.release.runtimeArtifactKey
110
+ });
111
+ }
112
+ function pruneExtractedRuntimeArtifacts(root, keepPath, maxEntries) {
113
+ if (!existsSync(root)) {
114
+ return;
115
+ }
116
+ const keep = path.resolve(keepPath);
117
+ const entries = readdirSync(root, { withFileTypes: true })
118
+ .filter((entry) => entry.isDirectory())
119
+ .map((entry) => {
120
+ const fullPath = path.join(root, entry.name);
121
+ let mtimeMs = 0;
122
+ try {
123
+ mtimeMs = statSync(fullPath).mtimeMs;
124
+ }
125
+ catch {
126
+ return null;
127
+ }
128
+ return { fullPath, mtimeMs };
129
+ })
130
+ .filter((entry) => Boolean(entry))
131
+ .filter((entry) => path.resolve(entry.fullPath) !== keep)
132
+ .sort((a, b) => b.mtimeMs - a.mtimeMs);
133
+ const stale = maxEntries <= 0 ? entries : entries.slice(Math.max(0, maxEntries - 1));
134
+ for (const entry of stale) {
135
+ rmSync(entry.fullPath, { recursive: true, force: true });
136
+ }
137
+ }
138
+ function isNoSpaceError(error) {
139
+ return Boolean(error && typeof error === "object" && "code" in error && error.code === "ENOSPC");
140
+ }
141
+ function linkSharedNodeModules(checkoutPath) {
142
+ const target = path.resolve(process.env.LAMBDA_TASK_ROOT ?? process.cwd(), "node_modules");
143
+ const linkPath = path.join(checkoutPath, "node_modules");
144
+ if (!existsSync(target) || existsSync(linkPath)) {
145
+ return;
146
+ }
147
+ symlinkSync(target, linkPath, "dir");
148
+ }
149
+ function relativeModulePath(release) {
150
+ if (release.runtimeModulePath) {
151
+ return release.runtimeModulePath;
152
+ }
153
+ return path.relative(release.checkoutPath, release.modulePath).split(path.sep).join("/");
154
+ }
155
+ function relativeSkillPath(release) {
156
+ return path.relative(release.checkoutPath, release.skillPath).split(path.sep).join("/");
157
+ }
158
+ function safePathSegment(value) {
159
+ return value.replace(/[^a-zA-Z0-9._-]/g, "_").slice(0, 180);
160
+ }
161
+ function extractTarGzBuffer(archive, outputDir) {
162
+ const tar = gunzipSync(archive);
163
+ let offset = 0;
164
+ while (offset + 512 <= tar.length) {
165
+ const header = tar.subarray(offset, offset + 512);
166
+ offset += 512;
167
+ if (header.every((byte) => byte === 0)) {
168
+ break;
169
+ }
170
+ const name = readTarString(header, 0, 100);
171
+ const prefix = readTarString(header, 345, 155);
172
+ const fullName = [prefix, name].filter(Boolean).join("/");
173
+ const size = Number.parseInt(readTarString(header, 124, 12).trim() || "0", 8) || 0;
174
+ const typeFlag = readTarString(header, 156, 1) || "0";
175
+ const body = tar.subarray(offset, offset + size);
176
+ offset += Math.ceil(size / 512) * 512;
177
+ if (!fullName || fullName === "." || typeFlag === "x" || typeFlag === "g") {
178
+ continue;
179
+ }
180
+ const outputPath = resolveTarOutputPath(outputDir, fullName);
181
+ if (!outputPath) {
182
+ continue;
183
+ }
184
+ if (typeFlag === "5") {
185
+ mkdirSync(outputPath, { recursive: true });
186
+ continue;
187
+ }
188
+ if (typeFlag === "2") {
189
+ continue;
190
+ }
191
+ if (typeFlag !== "0" && typeFlag !== "") {
192
+ continue;
193
+ }
194
+ mkdirSync(path.dirname(outputPath), { recursive: true });
195
+ writeFileSync(outputPath, body);
196
+ }
197
+ }
198
+ function readTarString(buffer, offset, length) {
199
+ return buffer
200
+ .subarray(offset, offset + length)
201
+ .toString("utf8")
202
+ .replace(/\0.*$/s, "")
203
+ .trim();
204
+ }
205
+ function resolveTarOutputPath(outputDir, entryName) {
206
+ const normalized = entryName.replace(/^\.\/+/, "");
207
+ if (!normalized || normalized.startsWith("/") || normalized.includes("..")) {
208
+ return null;
209
+ }
210
+ const root = path.resolve(outputDir);
211
+ const outputPath = path.resolve(root, normalized);
212
+ if (outputPath !== root && !outputPath.startsWith(`${root}${path.sep}`)) {
213
+ return null;
214
+ }
215
+ return outputPath;
216
+ }
217
+ //# sourceMappingURL=template-runtime-bundles.js.map