@zalify/cli 0.4.0 → 0.5.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/dist/cli.js +108 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -11293,7 +11293,7 @@ function updateNotifier(options) {
|
|
|
11293
11293
|
|
|
11294
11294
|
// src/cli.ts
|
|
11295
11295
|
import { createRequire as createRequire2 } from "node:module";
|
|
11296
|
-
import { dirname, join as
|
|
11296
|
+
import { dirname, join as join4 } from "node:path";
|
|
11297
11297
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
11298
11298
|
|
|
11299
11299
|
// src/auth.ts
|
|
@@ -11847,10 +11847,112 @@ async function workspaceSet(slugOrId) {
|
|
|
11847
11847
|
console.log(`✓ Active workspace: ${found[1].name} (${found[1].slug})`);
|
|
11848
11848
|
}
|
|
11849
11849
|
|
|
11850
|
+
// src/images.ts
|
|
11851
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
11852
|
+
import { readFileSync as readFileSync3, writeFileSync as writeFileSync4, existsSync as existsSync3 } from "node:fs";
|
|
11853
|
+
import { join as join3, resolve as resolve2 } from "node:path";
|
|
11854
|
+
var BATCH2 = 20;
|
|
11855
|
+
async function imagesGenerate(storeDir) {
|
|
11856
|
+
const auth = requireActive();
|
|
11857
|
+
const imagesDir = join3(resolve2(storeDir), "images");
|
|
11858
|
+
const manifestPath = join3(imagesDir, "manifest.json");
|
|
11859
|
+
if (!existsSync3(manifestPath)) {
|
|
11860
|
+
throw new Error(`No images/manifest.json in ${storeDir}`);
|
|
11861
|
+
}
|
|
11862
|
+
const manifest = JSON.parse(readFileSync3(manifestPath, "utf8"));
|
|
11863
|
+
const indexPath = join3(imagesDir, "assets.json");
|
|
11864
|
+
const index = existsSync3(indexPath) ? JSON.parse(readFileSync3(indexPath, "utf8")) : {};
|
|
11865
|
+
const missing = manifest.images.filter((e) => !existsSync3(join3(imagesDir, e.file)));
|
|
11866
|
+
if (missing.length === 0) {
|
|
11867
|
+
console.log("All manifest images already exist locally.");
|
|
11868
|
+
return;
|
|
11869
|
+
}
|
|
11870
|
+
console.log(`Generating ${missing.length} image(s) on Zalify (workspace "${auth.workspaceName}")…`);
|
|
11871
|
+
let produced = 0;
|
|
11872
|
+
let failed = 0;
|
|
11873
|
+
for (let i = 0;i < missing.length; i += BATCH2) {
|
|
11874
|
+
const batch = missing.slice(i, i + BATCH2);
|
|
11875
|
+
const res = await fetch(`${auth.appUrl}/api/assets/generate`, {
|
|
11876
|
+
method: "POST",
|
|
11877
|
+
headers: {
|
|
11878
|
+
"Content-Type": "application/json",
|
|
11879
|
+
Authorization: `Bearer ${auth.key}`
|
|
11880
|
+
},
|
|
11881
|
+
body: JSON.stringify({
|
|
11882
|
+
workspaceId: auth.workspaceId,
|
|
11883
|
+
jobs: batch.map((e) => ({
|
|
11884
|
+
prompt: `${e.type === "model" ? manifest.modelStyle ?? manifest.style : manifest.style}
|
|
11885
|
+
|
|
11886
|
+
${e.prompt}`,
|
|
11887
|
+
count: 1,
|
|
11888
|
+
size: "1024x1024"
|
|
11889
|
+
}))
|
|
11890
|
+
})
|
|
11891
|
+
});
|
|
11892
|
+
if (!res.ok || !res.body) {
|
|
11893
|
+
const json = await res.json().catch(() => ({}));
|
|
11894
|
+
if (json.code === "UPGRADE_REQUIRED") {
|
|
11895
|
+
throw new Error(`${json.error ?? "Paid plan required."}
|
|
11896
|
+
Upgrade: ${auth.appUrl}/store/${auth.workspaceSlug}/settings/billing`);
|
|
11897
|
+
}
|
|
11898
|
+
throw new Error(`generate ${res.status}: ${JSON.stringify(json)}`);
|
|
11899
|
+
}
|
|
11900
|
+
const reader = res.body.getReader();
|
|
11901
|
+
const decoder = new TextDecoder;
|
|
11902
|
+
let buffer = "";
|
|
11903
|
+
while (true) {
|
|
11904
|
+
const { done, value } = await reader.read();
|
|
11905
|
+
if (done)
|
|
11906
|
+
break;
|
|
11907
|
+
buffer += decoder.decode(value, { stream: true });
|
|
11908
|
+
const lines = buffer.split(`
|
|
11909
|
+
`);
|
|
11910
|
+
buffer = lines.pop() ?? "";
|
|
11911
|
+
for (const line of lines) {
|
|
11912
|
+
if (!line.trim())
|
|
11913
|
+
continue;
|
|
11914
|
+
let event;
|
|
11915
|
+
try {
|
|
11916
|
+
event = JSON.parse(line);
|
|
11917
|
+
} catch {
|
|
11918
|
+
continue;
|
|
11919
|
+
}
|
|
11920
|
+
if (event.type === "image") {
|
|
11921
|
+
const entry = batch[event.jobIndex];
|
|
11922
|
+
if (!entry)
|
|
11923
|
+
continue;
|
|
11924
|
+
const img = await fetch(event.asset.url);
|
|
11925
|
+
if (!img.ok) {
|
|
11926
|
+
console.error(` ✗ ${entry.file}: download ${img.status}`);
|
|
11927
|
+
failed++;
|
|
11928
|
+
continue;
|
|
11929
|
+
}
|
|
11930
|
+
const bytes = Buffer.from(await img.arrayBuffer());
|
|
11931
|
+
writeFileSync4(join3(imagesDir, entry.file), bytes);
|
|
11932
|
+
index[entry.file] = {
|
|
11933
|
+
assetId: event.asset.id,
|
|
11934
|
+
url: event.asset.url,
|
|
11935
|
+
checksum: createHash2("sha256").update(bytes).digest("hex")
|
|
11936
|
+
};
|
|
11937
|
+
writeFileSync4(indexPath, JSON.stringify(index, null, 2) + `
|
|
11938
|
+
`);
|
|
11939
|
+
produced++;
|
|
11940
|
+
console.log(` ✓ ${entry.file} (${produced + failed}/${missing.length})`);
|
|
11941
|
+
} else if (event.type === "error") {
|
|
11942
|
+
const entry = batch[event.jobIndex];
|
|
11943
|
+
failed++;
|
|
11944
|
+
console.error(` ✗ ${entry?.file ?? `job ${event.jobIndex}`}: ${event.message}`);
|
|
11945
|
+
}
|
|
11946
|
+
}
|
|
11947
|
+
}
|
|
11948
|
+
}
|
|
11949
|
+
console.log(`Done: ${produced} generated (already in the asset library), ${failed} failed${failed ? " — re-run to retry" : ""}.`);
|
|
11950
|
+
}
|
|
11951
|
+
|
|
11850
11952
|
// src/cli.ts
|
|
11851
11953
|
var __dirname4 = dirname(fileURLToPath3(import.meta.url));
|
|
11852
11954
|
var require2 = createRequire2(import.meta.url);
|
|
11853
|
-
var pkg = require2(
|
|
11955
|
+
var pkg = require2(join4(__dirname4, "..", "package.json"));
|
|
11854
11956
|
try {
|
|
11855
11957
|
updateNotifier({ pkg }).notify({
|
|
11856
11958
|
isGlobal: true,
|
|
@@ -11894,6 +11996,10 @@ workspace.command("list", { isDefault: true }).description("List authorized work
|
|
|
11894
11996
|
workspace.command("set <slug-or-id>").description("Switch the active workspace (local, no re-login)").action(async (slugOrId) => {
|
|
11895
11997
|
await workspaceSet(slugOrId);
|
|
11896
11998
|
});
|
|
11999
|
+
var images = program2.command("images").description("Generate images on Zalify infrastructure");
|
|
12000
|
+
images.command("generate <store-dir>").description("Generate missing manifest images server-side (results land in the asset library and are downloaded locally)").action(async (storeDir) => {
|
|
12001
|
+
await imagesGenerate(storeDir);
|
|
12002
|
+
});
|
|
11897
12003
|
var assets = program2.command("assets").description("Sync images with the Zalify asset library");
|
|
11898
12004
|
assets.command("push <store-dir>").description("Upload <store-dir>/images/*.png (sha256 dedup, writes assets.json)").action(async (storeDir) => {
|
|
11899
12005
|
await assetsPush(storeDir);
|