@fleox/agentphoto 0.0.0-stage → 0.1.1
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/LICENSE +143 -0
- package/README.md +334 -2
- package/changelog.json +35 -0
- package/dist/agent/agentphoto.mjs +3354 -0
- package/dist/agent/chunks/assets-BZVUUHjg.mjs +151 -0
- package/dist/agent/chunks/catalog-DIZ5dnH5.mjs +953 -0
- package/dist/agent/chunks/context-CNpRboiC.mjs +75 -0
- package/dist/agent/chunks/doc-D_v_yE07.mjs +512 -0
- package/dist/agent/chunks/export-aNJcPNbJ.mjs +140 -0
- package/dist/agent/chunks/geometry-BKIhUO9x.mjs +315 -0
- package/dist/agent/chunks/ids-DAmiNwd9.mjs +28 -0
- package/dist/agent/chunks/imageInfo-QxAfu8R6.mjs +173 -0
- package/dist/agent/chunks/jsonPath-B7vAPXsi.mjs +155 -0
- package/dist/agent/chunks/library-C_EXiphj.mjs +16 -0
- package/dist/agent/chunks/models-CxrjmA0W.mjs +387 -0
- package/dist/agent/chunks/output-3F12IR9O.mjs +130 -0
- package/dist/agent/chunks/package-Cu1GyvKL.mjs +71 -0
- package/dist/agent/chunks/project-o1DH2nOw.mjs +200 -0
- package/dist/agent/chunks/rolldown-runtime-CMQPkI6i.mjs +18 -0
- package/dist/agent/chunks/server-I0trf5tM.mjs +241 -0
- package/dist/agent/chunks/templates-BJ2me4XZ.mjs +61 -0
- package/dist/agent/chunks/tools-DKaAPEV5.mjs +1419 -0
- package/dist/agent/chunks/tree-D8qZKPAb.mjs +127 -0
- package/dist/agent/chunks/types-DOK7tAAu.mjs +30 -0
- package/dist/agent/chunks/validate-CXPFB-i6.mjs +936 -0
- package/dist/engine/agentphoto-engine.js +2833 -0
- package/dist/engine/chunks/transformers.web-D5Vsg6-A.js +18494 -0
- package/dist/engine/ort/ort-wasm-simd-threaded.asyncify.mjs +124 -0
- package/dist/engine/ort/ort-wasm-simd-threaded.asyncify.wasm +0 -0
- package/dist/studio/assets/index-CmOzzoXv.css +1 -0
- package/dist/studio/assets/index-D3Iw5q8v.js +28 -0
- package/dist/studio/assets/transformers.web-osEqoMhg.js +38 -0
- package/dist/studio/index.html +15 -0
- package/dist/studio/library/LICENSES.md +57 -0
- package/dist/studio/library/fonts/OFL.txt +90 -0
- package/dist/studio/library/fonts/anton/anton-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/anton/anton-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/archivo-black/archivo-black-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/archivo-black/archivo-black-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/bebas-neue/bebas-neue-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/bebas-neue/bebas-neue-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/caveat/caveat-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/caveat/caveat-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/caveat/caveat-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/caveat/caveat-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/dm-serif/dm-serif-display-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/dm-serif/dm-serif-display-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-800-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
- package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/lobster/lobster-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/lobster/lobster-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-800-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-ext-800-normal.woff2 +0 -0
- package/dist/studio/library/fonts/oswald/oswald-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/oswald/oswald-latin-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/oswald/oswald-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/oswald/oswald-latin-ext-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/pacifico/pacifico-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/pacifico/pacifico-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-400-italic.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-ext-400-italic.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-ext-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/roboto-slab/LICENSE.txt +202 -0
- package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-500-normal.woff2 +0 -0
- package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-ext-500-normal.woff2 +0 -0
- package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/images/city.jpg +0 -0
- package/dist/studio/library/images/food.jpg +0 -0
- package/dist/studio/library/images/landscape.jpg +0 -0
- package/dist/studio/library/images/pet.jpg +0 -0
- package/dist/studio/library/images/portrait.jpg +0 -0
- package/dist/studio/library/images/product.jpg +0 -0
- package/dist/studio/library/index.json +752 -0
- package/dist/studio/templates/avatar-pro/assets/masks/photo-cutout.png +0 -0
- package/dist/studio/templates/avatar-pro/photo.json +13 -0
- package/dist/studio/templates/avatar-pro/preview.jpg +0 -0
- package/dist/studio/templates/avatar-pro/template.json +1 -0
- package/dist/studio/templates/index.json +1 -0
- package/dist/studio/templates/og-article/photo.json +13 -0
- package/dist/studio/templates/og-article/preview.jpg +0 -0
- package/dist/studio/templates/og-article/template.json +1 -0
- package/dist/studio/templates/polaroid/photo.json +13 -0
- package/dist/studio/templates/polaroid/preview.jpg +0 -0
- package/dist/studio/templates/polaroid/template.json +1 -0
- package/dist/studio/templates/product-white/assets/masks/photo-cutout.png +0 -0
- package/dist/studio/templates/product-white/photo.json +72 -0
- package/dist/studio/templates/product-white/preview.jpg +0 -0
- package/dist/studio/templates/product-white/template.json +1 -0
- package/dist/studio/templates/sale-banner/photo.json +125 -0
- package/dist/studio/templates/sale-banner/preview.jpg +0 -0
- package/dist/studio/templates/sale-banner/template.json +1 -0
- package/dist/studio/templates/social-quote/photo.json +13 -0
- package/dist/studio/templates/social-quote/preview.jpg +0 -0
- package/dist/studio/templates/social-quote/template.json +1 -0
- package/dist/studio/templates/story-promo/photo.json +13 -0
- package/dist/studio/templates/story-promo/preview.jpg +0 -0
- package/dist/studio/templates/story-promo/template.json +1 -0
- package/dist/studio/templates/youtube-thumbnail/photo.json +12 -0
- package/dist/studio/templates/youtube-thumbnail/preview.jpg +0 -0
- package/dist/studio/templates/youtube-thumbnail/template.json +1 -0
- package/library/LICENSES.md +57 -0
- package/library/fonts/OFL.txt +90 -0
- package/library/fonts/anton/anton-latin-400-normal.woff2 +0 -0
- package/library/fonts/anton/anton-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/archivo-black/archivo-black-latin-400-normal.woff2 +0 -0
- package/library/fonts/archivo-black/archivo-black-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/bebas-neue/bebas-neue-latin-400-normal.woff2 +0 -0
- package/library/fonts/bebas-neue/bebas-neue-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/caveat/caveat-latin-400-normal.woff2 +0 -0
- package/library/fonts/caveat/caveat-latin-700-normal.woff2 +0 -0
- package/library/fonts/caveat/caveat-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/caveat/caveat-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/dm-serif/dm-serif-display-latin-400-normal.woff2 +0 -0
- package/library/fonts/dm-serif/dm-serif-display-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-400-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-600-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-700-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-800-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
- package/library/fonts/jetbrains-mono/jetbrains-mono-latin-400-normal.woff2 +0 -0
- package/library/fonts/jetbrains-mono/jetbrains-mono-latin-700-normal.woff2 +0 -0
- package/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/lobster/lobster-latin-400-normal.woff2 +0 -0
- package/library/fonts/lobster/lobster-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-400-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-700-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-800-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-ext-800-normal.woff2 +0 -0
- package/library/fonts/oswald/oswald-latin-400-normal.woff2 +0 -0
- package/library/fonts/oswald/oswald-latin-600-normal.woff2 +0 -0
- package/library/fonts/oswald/oswald-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/oswald/oswald-latin-ext-600-normal.woff2 +0 -0
- package/library/fonts/pacifico/pacifico-latin-400-normal.woff2 +0 -0
- package/library/fonts/pacifico/pacifico-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-400-italic.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-400-normal.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-700-normal.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-ext-400-italic.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-400-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-600-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-700-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-ext-600-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/roboto-slab/LICENSE.txt +202 -0
- package/library/fonts/roboto-slab/roboto-slab-latin-400-normal.woff2 +0 -0
- package/library/fonts/roboto-slab/roboto-slab-latin-700-normal.woff2 +0 -0
- package/library/fonts/roboto-slab/roboto-slab-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/roboto-slab/roboto-slab-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/space-grotesk/space-grotesk-latin-500-normal.woff2 +0 -0
- package/library/fonts/space-grotesk/space-grotesk-latin-700-normal.woff2 +0 -0
- package/library/fonts/space-grotesk/space-grotesk-latin-ext-500-normal.woff2 +0 -0
- package/library/fonts/space-grotesk/space-grotesk-latin-ext-700-normal.woff2 +0 -0
- package/library/images/city.jpg +0 -0
- package/library/images/food.jpg +0 -0
- package/library/images/landscape.jpg +0 -0
- package/library/images/pet.jpg +0 -0
- package/library/images/portrait.jpg +0 -0
- package/library/images/product.jpg +0 -0
- package/library/index.json +752 -0
- package/package.json +65 -4
- package/plugin/.claude-plugin/plugin.json +19 -0
- package/plugin/skills/agentphoto-cutout/SKILL.md +137 -0
- package/plugin/skills/agentphoto-design/SKILL.md +104 -0
- package/plugin/skills/agentphoto-design/references/layouts.md +60 -0
- package/plugin/skills/agentphoto-publish/SKILL.md +79 -0
- package/plugin/skills/agentphoto-retouch/SKILL.md +144 -0
- package/plugin/skills/agentphoto-retouch/references/filters.md +51 -0
- package/plugin/skills/agentphoto-retouch/references/patch-ops.md +67 -0
- package/plugin/skills/agentphoto-retouch/references/recipes.md +129 -0
- package/templates/avatar-pro/assets/masks/photo-cutout.png +0 -0
- package/templates/avatar-pro/photo.json +13 -0
- package/templates/avatar-pro/preview.jpg +0 -0
- package/templates/avatar-pro/template.json +1 -0
- package/templates/og-article/photo.json +13 -0
- package/templates/og-article/preview.jpg +0 -0
- package/templates/og-article/template.json +1 -0
- package/templates/polaroid/photo.json +13 -0
- package/templates/polaroid/preview.jpg +0 -0
- package/templates/polaroid/template.json +1 -0
- package/templates/product-white/assets/masks/photo-cutout.png +0 -0
- package/templates/product-white/photo.json +72 -0
- package/templates/product-white/preview.jpg +0 -0
- package/templates/product-white/template.json +1 -0
- package/templates/sale-banner/photo.json +125 -0
- package/templates/sale-banner/preview.jpg +0 -0
- package/templates/sale-banner/template.json +1 -0
- package/templates/social-quote/photo.json +13 -0
- package/templates/social-quote/preview.jpg +0 -0
- package/templates/social-quote/template.json +1 -0
- package/templates/story-promo/photo.json +13 -0
- package/templates/story-promo/preview.jpg +0 -0
- package/templates/story-promo/template.json +1 -0
- package/templates/youtube-thumbnail/photo.json +12 -0
- package/templates/youtube-thumbnail/preview.jpg +0 -0
- package/templates/youtube-thumbnail/template.json +1 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { createRequire as __apRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath as __apPath } from "node:url";
|
|
3
|
+
import { dirname as __apDirname } from "node:path";
|
|
4
|
+
__apRequire(import.meta.url);
|
|
5
|
+
const __filename = __apPath(import.meta.url);
|
|
6
|
+
__apDirname(__filename);
|
|
7
|
+
import { t as __exportAll } from "./rolldown-runtime-CMQPkI6i.mjs";
|
|
8
|
+
// src/core/jsonPath.ts
|
|
9
|
+
var jsonPath_exports = /* @__PURE__ */ __exportAll({ getAt: () => getAt });
|
|
10
|
+
var PathError = class extends Error {
|
|
11
|
+
hint;
|
|
12
|
+
name = "PathError";
|
|
13
|
+
constructor(message, hint) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.hint = hint;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var SEGMENT_RE = /^([^#[\]]*)(?:#([^[\]]+))?((?:\[\d+\])*)$/;
|
|
19
|
+
function parsePath(path) {
|
|
20
|
+
if (typeof path !== "string" || !path.trim()) throw new PathError("Empty path.", "Use a path like \"canvas.width\" or \"layers#title.color\".");
|
|
21
|
+
const tokens = [];
|
|
22
|
+
for (const seg of splitSegments(path.trim())) {
|
|
23
|
+
const m = SEGMENT_RE.exec(seg);
|
|
24
|
+
if (!m) throw new PathError(`Invalid path segment "${seg}" in "${path}".`, "Segments are keys, \"[index]\" or \"key#id\", e.g. \"layers#group.children[0].x\".");
|
|
25
|
+
const [, key, ref, idx] = m;
|
|
26
|
+
if (key) tokens.push({ key });
|
|
27
|
+
else if (!ref && !idx) throw new PathError(`Empty segment in "${path}".`);
|
|
28
|
+
if (ref) tokens.push({
|
|
29
|
+
ref,
|
|
30
|
+
tree: key === "layers" || key === "children"
|
|
31
|
+
});
|
|
32
|
+
for (const im of idx.matchAll(/\[(\d+)\]/g)) tokens.push({ index: Number(im[1]) });
|
|
33
|
+
}
|
|
34
|
+
return tokens;
|
|
35
|
+
}
|
|
36
|
+
function splitSegments(path) {
|
|
37
|
+
return path.split(".");
|
|
38
|
+
}
|
|
39
|
+
function formatPath(tokens) {
|
|
40
|
+
let out = "";
|
|
41
|
+
for (const t of tokens) if ("key" in t) out += out ? `.${t.key}` : t.key;
|
|
42
|
+
else if ("index" in t) out += `[${t.index}]`;
|
|
43
|
+
else out += `#${t.ref}`;
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
var isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
47
|
+
function findById(arr, id, tree) {
|
|
48
|
+
for (let i = 0; i < arr.length; i++) {
|
|
49
|
+
const el = arr[i];
|
|
50
|
+
if (isObj(el) && el.id === id) return {
|
|
51
|
+
container: arr,
|
|
52
|
+
index: i
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (tree) {
|
|
56
|
+
for (const el of arr) if (isObj(el) && Array.isArray(el.children)) {
|
|
57
|
+
const found = findById(el.children, id, true);
|
|
58
|
+
if (found) return found;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
function locate(root, tokens, create, fullPath) {
|
|
64
|
+
if (!tokens.length) throw new PathError("Empty path.");
|
|
65
|
+
let cur = root;
|
|
66
|
+
const steps = tokens.map((tok, i) => ({
|
|
67
|
+
tok,
|
|
68
|
+
next: tokens[i + 1]
|
|
69
|
+
}));
|
|
70
|
+
let parent = null;
|
|
71
|
+
for (let i = 0; i < steps.length; i++) {
|
|
72
|
+
const { tok, next } = steps[i];
|
|
73
|
+
const here = formatPath(tokens.slice(0, i + 1));
|
|
74
|
+
if ("ref" in tok) {
|
|
75
|
+
if (!Array.isArray(cur)) throw new PathError(`"${formatPath(tokens.slice(0, i))}" is not an array, cannot look up "#${tok.ref}" in "${fullPath}".`);
|
|
76
|
+
const found = findById(cur, tok.ref, tok.tree);
|
|
77
|
+
if (!found) throw new PathError(`No element with id "${tok.ref}" (path "${fullPath}").`, tok.tree ? "List the layer ids with doc_summary / layer_list." : void 0);
|
|
78
|
+
parent = {
|
|
79
|
+
parent: found.container,
|
|
80
|
+
key: found.index
|
|
81
|
+
};
|
|
82
|
+
} else if ("index" in tok) {
|
|
83
|
+
if (!Array.isArray(cur)) throw new PathError(`"${formatPath(tokens.slice(0, i))}" is not an array (path "${fullPath}").`);
|
|
84
|
+
if (tok.index > cur.length || tok.index === cur.length && (i < steps.length - 1 || !create)) throw new PathError(`Index ${tok.index} out of range at "${here}" (length ${cur.length}).`);
|
|
85
|
+
parent = {
|
|
86
|
+
parent: cur,
|
|
87
|
+
key: tok.index
|
|
88
|
+
};
|
|
89
|
+
} else {
|
|
90
|
+
if (!isObj(cur)) throw new PathError(`"${formatPath(tokens.slice(0, i)) || "<root>"}" is not an object, cannot read "${tok.key}" (path "${fullPath}").`);
|
|
91
|
+
parent = {
|
|
92
|
+
parent: cur,
|
|
93
|
+
key: tok.key
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (i === steps.length - 1) return parent;
|
|
97
|
+
let child = parent.parent[parent.key];
|
|
98
|
+
if (child === void 0 || child === null) {
|
|
99
|
+
if (!create) throw new PathError(`Nothing at "${here}" (path "${fullPath}").`);
|
|
100
|
+
child = next && ("index" in next || "ref" in next) ? [] : {};
|
|
101
|
+
parent.parent[parent.key] = child;
|
|
102
|
+
}
|
|
103
|
+
cur = child;
|
|
104
|
+
}
|
|
105
|
+
throw new PathError("Unreachable");
|
|
106
|
+
}
|
|
107
|
+
function getAt(root, path) {
|
|
108
|
+
const tokens = typeof path === "string" ? parsePath(path) : path;
|
|
109
|
+
const loc = locate(root, tokens, false, typeof path === "string" ? path : formatPath(tokens));
|
|
110
|
+
return loc.parent[loc.key];
|
|
111
|
+
}
|
|
112
|
+
function setAt(root, path, value) {
|
|
113
|
+
const tokens = typeof path === "string" ? parsePath(path) : path;
|
|
114
|
+
const loc = locate(root, tokens, true, typeof path === "string" ? path : formatPath(tokens));
|
|
115
|
+
loc.parent[loc.key] = value;
|
|
116
|
+
}
|
|
117
|
+
function removeAt(root, path) {
|
|
118
|
+
const tokens = typeof path === "string" ? parsePath(path) : path;
|
|
119
|
+
const loc = locate(root, tokens, false, typeof path === "string" ? path : formatPath(tokens));
|
|
120
|
+
if (Array.isArray(loc.parent)) {
|
|
121
|
+
const idx = loc.key;
|
|
122
|
+
if (idx >= loc.parent.length) return false;
|
|
123
|
+
loc.parent.splice(idx, 1);
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
if (!(String(loc.key) in loc.parent)) return false;
|
|
127
|
+
delete loc.parent[String(loc.key)];
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
function mergePatch(target, patch) {
|
|
131
|
+
if (!isObj(patch)) return clone(patch);
|
|
132
|
+
const out = isObj(target) ? { ...target } : {};
|
|
133
|
+
for (const [k, v] of Object.entries(patch)) if (v === null) delete out[k];
|
|
134
|
+
else out[k] = mergePatch(out[k], v);
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
function clone(v) {
|
|
138
|
+
return v === void 0 ? v : JSON.parse(JSON.stringify(v));
|
|
139
|
+
}
|
|
140
|
+
function stableStringify(v) {
|
|
141
|
+
return JSON.stringify(sortKeys(v));
|
|
142
|
+
}
|
|
143
|
+
function sortKeys(v) {
|
|
144
|
+
if (Array.isArray(v)) return v.map(sortKeys);
|
|
145
|
+
if (isObj(v)) {
|
|
146
|
+
const out = {};
|
|
147
|
+
for (const k of Object.keys(v).sort()) if (v[k] !== void 0) out[k] = sortKeys(v[k]);
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
return v;
|
|
151
|
+
}
|
|
152
|
+
function deepEqual(a, b) {
|
|
153
|
+
return stableStringify(a) === stableStringify(b);
|
|
154
|
+
}
|
|
155
|
+
export { jsonPath_exports as a, setAt as c, getAt as i, clone as n, mergePatch as o, deepEqual as r, removeAt as s, PathError as t };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createRequire as __apRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath as __apPath } from "node:url";
|
|
3
|
+
import { dirname as __apDirname } from "node:path";
|
|
4
|
+
__apRequire(import.meta.url);
|
|
5
|
+
const __filename = __apPath(import.meta.url);
|
|
6
|
+
__apDirname(__filename);
|
|
7
|
+
function isLibraryRef(path) {
|
|
8
|
+
return typeof path === "string" && path.startsWith("library:");
|
|
9
|
+
}
|
|
10
|
+
function libraryId(ref) {
|
|
11
|
+
return ref.slice(8);
|
|
12
|
+
}
|
|
13
|
+
function findLibraryAsset(index, id) {
|
|
14
|
+
return index?.assets.find((a) => a.id === id);
|
|
15
|
+
}
|
|
16
|
+
export { isLibraryRef as n, libraryId as r, findLibraryAsset as t };
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { createRequire as __apRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath as __apPath, fileURLToPath } from "node:url";
|
|
3
|
+
import { dirname as __apDirname, dirname, extname, join, resolve, sep } from "node:path";
|
|
4
|
+
__apRequire(import.meta.url);
|
|
5
|
+
const __filename = __apPath(import.meta.url);
|
|
6
|
+
__apDirname(__filename);
|
|
7
|
+
import { t as __exportAll } from "./rolldown-runtime-CMQPkI6i.mjs";
|
|
8
|
+
import { o as MODELS } from "./catalog-DIZ5dnH5.mjs";
|
|
9
|
+
import { t as package_default } from "./package-Cu1GyvKL.mjs";
|
|
10
|
+
import { createReadStream, createWriteStream, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync } from "node:fs";
|
|
11
|
+
import { homedir } from "node:os";
|
|
12
|
+
import { createServer } from "node:http";
|
|
13
|
+
// agent/paths.ts
|
|
14
|
+
function isBundled() {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
function packageRoot() {
|
|
18
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
if (isBundled()) return here.endsWith("chunks") ? resolve(here, "..", "..", "..") : resolve(here, "..", "..");
|
|
20
|
+
return resolve(here, "..");
|
|
21
|
+
}
|
|
22
|
+
function distRoot() {
|
|
23
|
+
if (process.env.AGENTPHOTO_DIST) return resolve(process.env.AGENTPHOTO_DIST);
|
|
24
|
+
return join(packageRoot(), "dist");
|
|
25
|
+
}
|
|
26
|
+
var engineDir = () => join(distRoot(), "engine");
|
|
27
|
+
var studioDir = () => join(distRoot(), "studio");
|
|
28
|
+
var libraryDir = () => process.env.AGENTPHOTO_LIBRARY ? resolve(process.env.AGENTPHOTO_LIBRARY) : join(packageRoot(), "library");
|
|
29
|
+
var templatesDir = () => process.env.AGENTPHOTO_TEMPLATES ? resolve(process.env.AGENTPHOTO_TEMPLATES) : join(packageRoot(), "templates");
|
|
30
|
+
var modelsDir = () => process.env.AGENTPHOTO_MODELS ? resolve(process.env.AGENTPHOTO_MODELS) : join(homedir(), ".cache", "agentphoto", "models");
|
|
31
|
+
var ENGINE_ENTRY = "agentphoto-engine.js";
|
|
32
|
+
function engineBuilt() {
|
|
33
|
+
return existsSync(join(engineDir(), ENGINE_ENTRY));
|
|
34
|
+
}
|
|
35
|
+
function readVersionInfo() {
|
|
36
|
+
const file = join(distRoot(), "version.json");
|
|
37
|
+
if (existsSync(file)) try {
|
|
38
|
+
const v = JSON.parse(readFileSync(file, "utf8"));
|
|
39
|
+
if (v.version) return {
|
|
40
|
+
name: v.name ?? package_default.name,
|
|
41
|
+
version: v.version
|
|
42
|
+
};
|
|
43
|
+
} catch {}
|
|
44
|
+
return {
|
|
45
|
+
name: package_default.name,
|
|
46
|
+
version: package_default.version
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
package_default.name;
|
|
50
|
+
// agent/render/server.ts
|
|
51
|
+
var MIME = {
|
|
52
|
+
".html": "text/html; charset=utf-8",
|
|
53
|
+
".js": "text/javascript; charset=utf-8",
|
|
54
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
55
|
+
".css": "text/css; charset=utf-8",
|
|
56
|
+
".json": "application/json; charset=utf-8",
|
|
57
|
+
".map": "application/json; charset=utf-8",
|
|
58
|
+
".svg": "image/svg+xml",
|
|
59
|
+
".png": "image/png",
|
|
60
|
+
".jpg": "image/jpeg",
|
|
61
|
+
".jpeg": "image/jpeg",
|
|
62
|
+
".webp": "image/webp",
|
|
63
|
+
".gif": "image/gif",
|
|
64
|
+
".avif": "image/avif",
|
|
65
|
+
".ico": "image/x-icon",
|
|
66
|
+
".hdr": "application/octet-stream",
|
|
67
|
+
".exr": "application/octet-stream",
|
|
68
|
+
".ktx2": "image/ktx2",
|
|
69
|
+
".glb": "model/gltf-binary",
|
|
70
|
+
".gltf": "model/gltf+json",
|
|
71
|
+
".bin": "application/octet-stream",
|
|
72
|
+
".woff": "font/woff",
|
|
73
|
+
".woff2": "font/woff2",
|
|
74
|
+
".ttf": "font/ttf",
|
|
75
|
+
".otf": "font/otf",
|
|
76
|
+
".mp3": "audio/mpeg",
|
|
77
|
+
".ogg": "audio/ogg",
|
|
78
|
+
".wav": "audio/wav",
|
|
79
|
+
".m4a": "audio/mp4",
|
|
80
|
+
".webm": "video/webm",
|
|
81
|
+
".mp4": "video/mp4",
|
|
82
|
+
".txt": "text/plain; charset=utf-8",
|
|
83
|
+
".wasm": "application/wasm"
|
|
84
|
+
};
|
|
85
|
+
function mimeOf(path) {
|
|
86
|
+
return MIME[extname(path).toLowerCase()] ?? "application/octet-stream";
|
|
87
|
+
}
|
|
88
|
+
function resolveUnder(root, rel) {
|
|
89
|
+
let decoded;
|
|
90
|
+
try {
|
|
91
|
+
decoded = decodeURIComponent(rel);
|
|
92
|
+
} catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
if (decoded.includes("\0")) return null;
|
|
96
|
+
const parts = decoded.replace(/\\/g, "/").split("/").filter((p) => p && p !== ".");
|
|
97
|
+
if (parts.includes("..")) return null;
|
|
98
|
+
const absRoot = resolve(root);
|
|
99
|
+
const file = resolve(absRoot, ...parts);
|
|
100
|
+
if (file !== absRoot && !file.startsWith(absRoot + sep)) return null;
|
|
101
|
+
if (existsSync(file)) try {
|
|
102
|
+
const realRoot = realpathSync(absRoot);
|
|
103
|
+
const real = realpathSync(file);
|
|
104
|
+
if (real !== realRoot && !real.startsWith(realRoot + sep)) return null;
|
|
105
|
+
} catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
return file;
|
|
109
|
+
}
|
|
110
|
+
function isFile(file) {
|
|
111
|
+
try {
|
|
112
|
+
return statSync(file).isFile();
|
|
113
|
+
} catch {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function sendFile(req, res, file) {
|
|
118
|
+
if (!file || !isFile(file)) {
|
|
119
|
+
res.writeHead(404, { "content-type": "text/plain; charset=utf-8" }).end("Not found");
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
res.writeHead(200, {
|
|
123
|
+
"content-type": mimeOf(file),
|
|
124
|
+
"cache-control": "no-store",
|
|
125
|
+
"x-content-type-options": "nosniff"
|
|
126
|
+
});
|
|
127
|
+
if (req.method === "HEAD") res.end();
|
|
128
|
+
else createReadStream(file).on("error", () => res.destroy()).pipe(res);
|
|
129
|
+
}
|
|
130
|
+
function sendText(res, status, body, type = "text/plain; charset=utf-8") {
|
|
131
|
+
res.writeHead(status, {
|
|
132
|
+
"content-type": type,
|
|
133
|
+
"cache-control": "no-store",
|
|
134
|
+
"x-content-type-options": "nosniff"
|
|
135
|
+
}).end(body);
|
|
136
|
+
}
|
|
137
|
+
function sendJson(res, status, body) {
|
|
138
|
+
sendText(res, status, JSON.stringify(body), "application/json; charset=utf-8");
|
|
139
|
+
}
|
|
140
|
+
function startLocalServer(opts) {
|
|
141
|
+
const host = opts.host ?? "127.0.0.1";
|
|
142
|
+
const mounts = Object.entries(opts.mounts).sort((a, b) => b[0].length - a[0].length);
|
|
143
|
+
const server = createServer((req, res) => {
|
|
144
|
+
(async () => {
|
|
145
|
+
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
146
|
+
if (url.pathname === "/" && opts.index) url.pathname = opts.index;
|
|
147
|
+
if (url.pathname === "/favicon.ico" && !opts.fallbackRoot) return void res.writeHead(204).end();
|
|
148
|
+
for (const route of opts.routes ?? []) if (await route(req, res, url)) return;
|
|
149
|
+
if (req.method !== "GET" && req.method !== "HEAD") return sendText(res, 405, "Method not allowed");
|
|
150
|
+
const raw = (req.url ?? "/").split("?")[0].split("#")[0];
|
|
151
|
+
const rawPath = raw === "/" && opts.index ? opts.index : raw;
|
|
152
|
+
for (const [prefix, root] of mounts) if (rawPath.startsWith(prefix)) return sendFile(req, res, resolveUnder(root, rawPath.slice(prefix.length)));
|
|
153
|
+
if (opts.fallbackRoot) {
|
|
154
|
+
const file = resolveUnder(opts.fallbackRoot, rawPath.replace(/^\//, "") || "index.html");
|
|
155
|
+
if (file && isFile(file)) return sendFile(req, res, file);
|
|
156
|
+
if (!extname(rawPath)) return sendFile(req, res, resolveUnder(opts.fallbackRoot, "index.html"));
|
|
157
|
+
}
|
|
158
|
+
sendText(res, 404, "Not found");
|
|
159
|
+
})().catch((err) => {
|
|
160
|
+
if (!res.headersSent) sendText(res, 500, err.message);
|
|
161
|
+
else res.destroy();
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
server.on("clientError", (_err, socket) => socket.destroy());
|
|
165
|
+
return new Promise((resolvePromise, reject) => {
|
|
166
|
+
server.once("error", reject);
|
|
167
|
+
server.listen(opts.port ?? 0, host, () => {
|
|
168
|
+
server.off("error", reject);
|
|
169
|
+
const port = server.address().port;
|
|
170
|
+
resolvePromise({
|
|
171
|
+
server,
|
|
172
|
+
port,
|
|
173
|
+
url: `http://${host}:${port}`,
|
|
174
|
+
close: () => new Promise((r) => {
|
|
175
|
+
server.closeAllConnections?.();
|
|
176
|
+
server.close(() => r());
|
|
177
|
+
})
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
function readBody(req, limit = 52428800) {
|
|
183
|
+
return new Promise((resolvePromise, reject) => {
|
|
184
|
+
const chunks = [];
|
|
185
|
+
let size = 0;
|
|
186
|
+
req.on("data", (c) => {
|
|
187
|
+
size += c.length;
|
|
188
|
+
if (size > limit) {
|
|
189
|
+
reject(/* @__PURE__ */ new Error("Request body too large"));
|
|
190
|
+
req.destroy();
|
|
191
|
+
} else chunks.push(c);
|
|
192
|
+
});
|
|
193
|
+
req.on("end", () => resolvePromise(Buffer.concat(chunks)));
|
|
194
|
+
req.on("error", reject);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
// agent/render/models.ts
|
|
198
|
+
var models_exports = /* @__PURE__ */ __exportAll({ listCachedModels: () => listCachedModels });
|
|
199
|
+
var SEGMENT = /^[\w@=+,-][\w.@=+,-]*$/;
|
|
200
|
+
function parseModelPath(rawPath) {
|
|
201
|
+
if (!rawPath.startsWith("/__models/")) return null;
|
|
202
|
+
let segs;
|
|
203
|
+
try {
|
|
204
|
+
segs = rawPath.slice(10).split("/").map((s) => decodeURIComponent(s));
|
|
205
|
+
} catch {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
if (segs.some((s) => !SEGMENT.test(s) || s === "." || s === "..")) return null;
|
|
209
|
+
const i = segs.indexOf("resolve");
|
|
210
|
+
if (i < 1 || i > 3 || segs.length < i + 3) return null;
|
|
211
|
+
return {
|
|
212
|
+
repo: segs.slice(0, i).join("/"),
|
|
213
|
+
rev: segs[i + 1],
|
|
214
|
+
file: segs.slice(i + 2).join("/")
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function cacheFileOf(root, ref) {
|
|
218
|
+
return join(root, ...ref.repo.split("/"), ref.rev, ...ref.file.split("/"));
|
|
219
|
+
}
|
|
220
|
+
var CONTENT_TYPE = {
|
|
221
|
+
json: "application/json; charset=utf-8",
|
|
222
|
+
txt: "text/plain; charset=utf-8",
|
|
223
|
+
onnx: "application/octet-stream"
|
|
224
|
+
};
|
|
225
|
+
var typeOf = (file) => CONTENT_TYPE[file.split(".").pop() ?? ""] ?? "application/octet-stream";
|
|
226
|
+
function serveCached(req, res, file, name) {
|
|
227
|
+
const size = statSync(file).size;
|
|
228
|
+
res.writeHead(200, {
|
|
229
|
+
"content-type": typeOf(name),
|
|
230
|
+
"content-length": String(size),
|
|
231
|
+
"cache-control": "no-store",
|
|
232
|
+
"x-content-type-options": "nosniff"
|
|
233
|
+
});
|
|
234
|
+
if (req.method === "HEAD") return void res.end();
|
|
235
|
+
createReadStream(file).on("error", () => res.destroy()).pipe(res);
|
|
236
|
+
}
|
|
237
|
+
var write = (stream, chunk) => new Promise((resolve, reject) => {
|
|
238
|
+
if (stream.write(chunk, (err) => err ? reject(err) : void 0)) resolve();
|
|
239
|
+
else stream.once("drain", () => resolve());
|
|
240
|
+
});
|
|
241
|
+
var close = (ws) => new Promise((resolve, reject) => ws.end((err) => err ? reject(err) : resolve()));
|
|
242
|
+
function modelsRoute(opts = {}) {
|
|
243
|
+
const root = opts.root ?? modelsDir;
|
|
244
|
+
const fetchImpl = opts.fetchImpl ?? ((url, init) => fetch(url, init));
|
|
245
|
+
const upstream = opts.upstream ?? "https://huggingface.co/";
|
|
246
|
+
const log = opts.log ?? (() => void 0);
|
|
247
|
+
const inflight = /* @__PURE__ */ new Map();
|
|
248
|
+
return async (req, res, url) => {
|
|
249
|
+
if (!url.pathname.startsWith("/__models/")) return false;
|
|
250
|
+
const ref = parseModelPath((req.url ?? "").split("?")[0]);
|
|
251
|
+
if (!ref) return sendText(res, 404, "Not a model file path"), true;
|
|
252
|
+
if (req.method !== "GET" && req.method !== "HEAD") return sendText(res, 405, "Method not allowed"), true;
|
|
253
|
+
const file = cacheFileOf(root(), ref);
|
|
254
|
+
const pending = inflight.get(file);
|
|
255
|
+
if (pending) await pending.catch(() => void 0);
|
|
256
|
+
if (existsSync(file)) return serveCached(req, res, file, ref.file), true;
|
|
257
|
+
const remote = `${upstream.replace(/\/?$/, "/")}${ref.repo}/resolve/${encodeURIComponent(ref.rev)}/${ref.file.split("/").map(encodeURIComponent).join("/")}`;
|
|
258
|
+
if (req.method === "HEAD") {
|
|
259
|
+
const r = await fetchImpl(remote, {
|
|
260
|
+
method: "HEAD",
|
|
261
|
+
redirect: "follow"
|
|
262
|
+
}).catch(() => null);
|
|
263
|
+
res.writeHead(r?.status ?? 502, {
|
|
264
|
+
"content-type": typeOf(ref.file),
|
|
265
|
+
...r?.headers.get("content-length") ? { "content-length": r.headers.get("content-length") } : {}
|
|
266
|
+
}).end();
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
let done;
|
|
270
|
+
let failed;
|
|
271
|
+
const job = new Promise((a, b) => (done = a, failed = b));
|
|
272
|
+
job.catch(() => void 0);
|
|
273
|
+
inflight.set(file, job);
|
|
274
|
+
const tmp = `${file}.${process.pid}.${Date.now().toString(36)}.part`;
|
|
275
|
+
let ws = null;
|
|
276
|
+
try {
|
|
277
|
+
let up;
|
|
278
|
+
try {
|
|
279
|
+
up = await fetchImpl(remote, { redirect: "follow" });
|
|
280
|
+
} catch (e) {
|
|
281
|
+
log(`[models] ${ref.repo}/${ref.file}: download failed (${e.message}). Check the network (the model is downloaded once from huggingface.co).`);
|
|
282
|
+
sendText(res, 502, `Model download failed: ${e.message}`);
|
|
283
|
+
failed(e);
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
if (!up.ok || !up.body) {
|
|
287
|
+
sendText(res, up.status === 200 ? 502 : up.status, up.status === 404 ? "Not found" : `Upstream HTTP ${up.status}`);
|
|
288
|
+
await up.body?.cancel().catch(() => void 0);
|
|
289
|
+
done();
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
const total = Number(up.headers.get("content-length")) || 0;
|
|
293
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
294
|
+
ws = createWriteStream(tmp);
|
|
295
|
+
res.writeHead(200, {
|
|
296
|
+
"content-type": typeOf(ref.file),
|
|
297
|
+
...total ? { "content-length": String(total) } : {},
|
|
298
|
+
"cache-control": "no-store",
|
|
299
|
+
"x-content-type-options": "nosniff"
|
|
300
|
+
});
|
|
301
|
+
const big = total > 2097152;
|
|
302
|
+
if (big) log(`Downloading ${ref.repo} ${ref.file} (${Math.round(total / 1048576)} MB, once — cached in ${root()})`);
|
|
303
|
+
let received = 0;
|
|
304
|
+
let lastPct = 0;
|
|
305
|
+
let lastAt = Date.now();
|
|
306
|
+
const reader = up.body.getReader();
|
|
307
|
+
for (;;) {
|
|
308
|
+
const { value, done: end } = await reader.read();
|
|
309
|
+
if (end) break;
|
|
310
|
+
received += value.byteLength;
|
|
311
|
+
await write(ws, value);
|
|
312
|
+
if (!res.destroyed) await write(res, value).catch(() => void 0);
|
|
313
|
+
if (big) {
|
|
314
|
+
const pct = Math.floor(received / total * 100);
|
|
315
|
+
if (pct >= lastPct + 10 || Date.now() - lastAt > 3e3 && pct > lastPct) {
|
|
316
|
+
lastPct = pct;
|
|
317
|
+
lastAt = Date.now();
|
|
318
|
+
log(`Downloading ${ref.repo} ${ref.file} (${pct} %)`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
await close(ws);
|
|
323
|
+
ws = null;
|
|
324
|
+
if (total && received !== total) throw new Error(`incomplete download (${received} of ${total} bytes)`);
|
|
325
|
+
renameSync(tmp, file);
|
|
326
|
+
res.end();
|
|
327
|
+
done();
|
|
328
|
+
} catch (e) {
|
|
329
|
+
if (ws) ws.destroy();
|
|
330
|
+
rmSync(tmp, { force: true });
|
|
331
|
+
log(`[models] ${ref.repo}/${ref.file}: ${e.message}`);
|
|
332
|
+
if (!res.headersSent) sendText(res, 502, e.message);
|
|
333
|
+
else res.destroy();
|
|
334
|
+
failed(e);
|
|
335
|
+
} finally {
|
|
336
|
+
inflight.delete(file);
|
|
337
|
+
}
|
|
338
|
+
return true;
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function modelCacheDir(def, root = modelsDir()) {
|
|
342
|
+
return join(root, ...def.repo.split("/"));
|
|
343
|
+
}
|
|
344
|
+
function dirSize(dir) {
|
|
345
|
+
let bytes = 0;
|
|
346
|
+
let files = 0;
|
|
347
|
+
const walk = (d) => {
|
|
348
|
+
let entries;
|
|
349
|
+
try {
|
|
350
|
+
entries = readdirSync(d, { withFileTypes: true });
|
|
351
|
+
} catch {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
for (const e of entries) {
|
|
355
|
+
const p = join(d, e.name);
|
|
356
|
+
if (e.isDirectory()) walk(p);
|
|
357
|
+
else if (e.isFile() && !e.name.endsWith(".part")) {
|
|
358
|
+
bytes += statSync(p).size;
|
|
359
|
+
files++;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
walk(dir);
|
|
364
|
+
return {
|
|
365
|
+
bytes,
|
|
366
|
+
files
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function listCachedModels(root = modelsDir()) {
|
|
370
|
+
return MODELS.map((m) => {
|
|
371
|
+
const dir = modelCacheDir(m, root);
|
|
372
|
+
const s = dirSize(dir);
|
|
373
|
+
return {
|
|
374
|
+
id: m.id,
|
|
375
|
+
task: m.task,
|
|
376
|
+
repo: m.repo,
|
|
377
|
+
sizeMb: m.sizeMb,
|
|
378
|
+
license: m.license,
|
|
379
|
+
description: m.description,
|
|
380
|
+
cached: s.files > 0 && existsSync(dir),
|
|
381
|
+
cachedMb: Math.round(s.bytes / 1048576 * 10) / 10,
|
|
382
|
+
files: s.files,
|
|
383
|
+
dir
|
|
384
|
+
};
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
export { packageRoot as _, mimeOf as a, templatesDir as b, sendJson as c, distRoot as d, engineBuilt as f, modelsDir as g, libraryDir as h, models_exports as i, sendText as l, isBundled as m, modelCacheDir as n, readBody as o, engineDir as p, modelsRoute as r, resolveUnder as s, listCachedModels as t, startLocalServer as u, readVersionInfo as v, studioDir as y };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createRequire as __apRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath as __apPath } from "node:url";
|
|
3
|
+
import { dirname as __apDirname } from "node:path";
|
|
4
|
+
__apRequire(import.meta.url);
|
|
5
|
+
const __filename = __apPath(import.meta.url);
|
|
6
|
+
__apDirname(__filename);
|
|
7
|
+
import { format } from "node:util";
|
|
8
|
+
// agent/output.ts
|
|
9
|
+
var CliError = class extends Error {
|
|
10
|
+
code;
|
|
11
|
+
hint;
|
|
12
|
+
exitCode;
|
|
13
|
+
details;
|
|
14
|
+
constructor(code, message, hint, exitCode = 1, details) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.hint = hint;
|
|
18
|
+
this.exitCode = exitCode;
|
|
19
|
+
this.details = details;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
function routeConsoleToStderr(target = console, write = (t) => void process.stderr.write(t)) {
|
|
23
|
+
const toStderr = (...args) => write(`${format(...args)}\n`);
|
|
24
|
+
target.log = toStderr;
|
|
25
|
+
target.info = toStderr;
|
|
26
|
+
target.debug = toStderr;
|
|
27
|
+
}
|
|
28
|
+
function createIo(json) {
|
|
29
|
+
return {
|
|
30
|
+
json,
|
|
31
|
+
out: (text) => process.stdout.write(text.endsWith("\n") ? text : text + "\n"),
|
|
32
|
+
err: (text) => process.stderr.write(text.endsWith("\n") ? text : text + "\n")
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
var TOOL_COMMANDS = {
|
|
36
|
+
project_info: "agentphoto info",
|
|
37
|
+
project_create: "agentphoto new <dir>",
|
|
38
|
+
doc_get: "agentphoto doc get",
|
|
39
|
+
doc_summary: "agentphoto doc summary",
|
|
40
|
+
doc_apply: "agentphoto doc apply",
|
|
41
|
+
doc_patch: "agentphoto doc patch",
|
|
42
|
+
doc_validate: "agentphoto doc validate",
|
|
43
|
+
layer_list: "agentphoto layer list",
|
|
44
|
+
layer_add: "agentphoto layer add",
|
|
45
|
+
layer_update: "agentphoto layer update",
|
|
46
|
+
layer_remove: "agentphoto layer remove",
|
|
47
|
+
layer_move: "agentphoto layer move",
|
|
48
|
+
filter_add: "agentphoto filter add",
|
|
49
|
+
mask_set: "agentphoto mask set",
|
|
50
|
+
remove_background: "agentphoto remove-bg",
|
|
51
|
+
mask_generate: "agentphoto mask generate",
|
|
52
|
+
image_analyze: "agentphoto analyze",
|
|
53
|
+
render_preview: "agentphoto render",
|
|
54
|
+
catalog_get: "agentphoto catalog",
|
|
55
|
+
templates_list: "agentphoto templates list",
|
|
56
|
+
library_list: "agentphoto assets library",
|
|
57
|
+
assets_list: "agentphoto assets list",
|
|
58
|
+
assets_add: "agentphoto assets add",
|
|
59
|
+
assets_remove: "agentphoto assets remove"
|
|
60
|
+
};
|
|
61
|
+
var TOOL_NAMES = Object.keys(TOOL_COMMANDS).join("|");
|
|
62
|
+
var TOOL_RE = new RegExp(`\\b(${TOOL_NAMES})\\b`, "g");
|
|
63
|
+
var TOOLS_THEN_CLI = new RegExp(`\\b(?:${TOOL_NAMES})(?:\\s*[/+,]\\s*(?:${TOOL_NAMES}))*\\s*(?:\\(CLI:\\s*([^)]*)\\)|,\\s*CLI:\\s*([^)]*)|/\\s*(\`agentphoto[^\`]*\`))`, "g");
|
|
64
|
+
function cliHint(text) {
|
|
65
|
+
if (!TOOL_RE.test(text)) return text;
|
|
66
|
+
TOOL_RE.lastIndex = 0;
|
|
67
|
+
return text.replace(TOOLS_THEN_CLI, (_m, a, b, c) => {
|
|
68
|
+
const cli = (a ?? b ?? c ?? "").trim();
|
|
69
|
+
return cli.startsWith("`") ? cli : `\`${cli}\``;
|
|
70
|
+
}).replace(TOOL_RE, (name) => `\`${TOOL_COMMANDS[name]}\``).replace(/``+/g, "`");
|
|
71
|
+
}
|
|
72
|
+
function withCliHints(data) {
|
|
73
|
+
if (Array.isArray(data)) return data.map((v) => withCliHints(v));
|
|
74
|
+
if (!data || typeof data !== "object") return data;
|
|
75
|
+
const out = {};
|
|
76
|
+
for (const [k, v] of Object.entries(data)) out[k] = k === "hint" && typeof v === "string" ? cliHint(v) : withCliHints(v);
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
function printResult(io, data, human, opts = {}) {
|
|
80
|
+
const shown = opts.raw ? data : withCliHints(data);
|
|
81
|
+
if (io.json) io.out(JSON.stringify({
|
|
82
|
+
ok: true,
|
|
83
|
+
data: shown
|
|
84
|
+
}));
|
|
85
|
+
else io.out(human());
|
|
86
|
+
}
|
|
87
|
+
var OPS_HINTS = {
|
|
88
|
+
notFound: "Check the id or path (`agentphoto layer list`, `agentphoto doc summary`, `agentphoto assets list` print them).",
|
|
89
|
+
validation: "Fix the document and retry: `agentphoto doc validate` lists every issue with its JSON path and a hint; `agentphoto catalog <section> <id>` documents the parameters.",
|
|
90
|
+
conflict: "Something with the same id already exists — list it first (`agentphoto layer list`), then update instead of adding, or pick another id.",
|
|
91
|
+
invalid: "Check the arguments with `agentphoto help <command>`.",
|
|
92
|
+
unavailable: "This needs the image engine: install Google Chrome (or `npx playwright install chromium`) and run `agentphoto doctor`.",
|
|
93
|
+
io: "A file could not be read or written: check the path and permissions of the project folder (--project <dir>)."
|
|
94
|
+
};
|
|
95
|
+
function knownError(error) {
|
|
96
|
+
if (!(error instanceof Error)) return null;
|
|
97
|
+
if (error.name === "OpsError") {
|
|
98
|
+
const e = error;
|
|
99
|
+
const code = e.code ?? "invalid";
|
|
100
|
+
return new CliError(code, error.message, e.hint || OPS_HINTS[code] || OPS_HINTS.invalid, code === "validation" || code === "invalid" ? 2 : 1, e.details);
|
|
101
|
+
}
|
|
102
|
+
if (error.name === "PathError") return new CliError("invalid-path", error.message, error.hint || "Paths look like \"canvas.background\", \"layers#title.size\" or \"layers#photo.filters[0].amount\" (`agentphoto doc summary` lists the ids).", 2);
|
|
103
|
+
if (error.name === "FsError") {
|
|
104
|
+
const code = error.code;
|
|
105
|
+
if (code === "notFound") return new CliError("notFound", error.message, "Is --project pointing at an AgentPhoto project folder (agentphoto.json + photo.json)? Create one with `agentphoto new <dir>`.");
|
|
106
|
+
if (code === "invalidPath") return new CliError("invalid-path", error.message, "Project paths are relative to the project folder and never contain \"..\" or an absolute prefix.", 2);
|
|
107
|
+
return new CliError("io", error.message, OPS_HINTS.io);
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
function toCliError(error) {
|
|
112
|
+
return error instanceof CliError ? error : knownError(error) ?? new CliError("internal", error instanceof Error ? error.message : String(error), "Unexpected error. Retry once; if it persists, report it with the command and this output (`agentphoto doctor` checks the setup).");
|
|
113
|
+
}
|
|
114
|
+
function printError(io, error) {
|
|
115
|
+
const e = toCliError(error);
|
|
116
|
+
const hint = e.hint ? cliHint(e.hint) : void 0;
|
|
117
|
+
const details = e.details !== void 0 ? { details: withCliHints(e.details) } : {};
|
|
118
|
+
if (io.json) io.out(JSON.stringify({
|
|
119
|
+
ok: false,
|
|
120
|
+
error: {
|
|
121
|
+
code: e.code,
|
|
122
|
+
message: e.message,
|
|
123
|
+
...hint ? { hint } : {},
|
|
124
|
+
...details
|
|
125
|
+
}
|
|
126
|
+
}));
|
|
127
|
+
else io.err(`Error: ${e.message}${hint ? `\nHint: ${hint}` : ""}`);
|
|
128
|
+
return e.exitCode;
|
|
129
|
+
}
|
|
130
|
+
export { routeConsoleToStderr as a, printResult as i, createIo as n, toCliError as o, printError as r, CliError as t };
|