@fleox/agentphoto 0.1.0 → 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.
Files changed (37) hide show
  1. package/README.md +177 -72
  2. package/changelog.json +18 -0
  3. package/dist/agent/agentphoto.mjs +64 -17
  4. package/dist/agent/chunks/{assets-CDQo3VqD.mjs → assets-BZVUUHjg.mjs} +3 -3
  5. package/dist/agent/chunks/{context-DoLoLF9f.mjs → context-CNpRboiC.mjs} +1 -1
  6. package/dist/agent/chunks/{doc-BjY_j4Su.mjs → doc-D_v_yE07.mjs} +25 -286
  7. package/dist/agent/chunks/{export-CLmpFART.mjs → export-aNJcPNbJ.mjs} +1 -1
  8. package/dist/agent/chunks/geometry-BKIhUO9x.mjs +315 -0
  9. package/dist/agent/chunks/{models-C4i_hicr.mjs → models-CxrjmA0W.mjs} +1 -1
  10. package/dist/agent/chunks/{package-DSmAxrla.mjs → package-Cu1GyvKL.mjs} +2 -2
  11. package/dist/agent/chunks/{project-CUykGysG.mjs → project-o1DH2nOw.mjs} +12 -10
  12. package/dist/agent/chunks/{templates--YGpGuHh.mjs → templates-BJ2me4XZ.mjs} +24 -3
  13. package/dist/agent/chunks/{tools-Dnh8g6F9.mjs → tools-DKaAPEV5.mjs} +92 -27
  14. package/dist/agent/chunks/{tree-DO7N0UDV.mjs → tree-D8qZKPAb.mjs} +2 -2
  15. package/dist/engine/agentphoto-engine.js +408 -352
  16. package/dist/studio/assets/index-CmOzzoXv.css +1 -0
  17. package/dist/studio/assets/index-D3Iw5q8v.js +28 -0
  18. package/dist/studio/assets/{transformers.web-DgnCIB_X.js → transformers.web-osEqoMhg.js} +1 -1
  19. package/dist/studio/index.html +2 -2
  20. package/dist/studio/templates/index.json +1 -1
  21. package/dist/studio/templates/product-white/photo.json +2 -2
  22. package/dist/studio/templates/product-white/preview.jpg +0 -0
  23. package/dist/studio/templates/product-white/template.json +1 -1
  24. package/package.json +2 -2
  25. package/plugin/.claude-plugin/plugin.json +1 -1
  26. package/plugin/skills/agentphoto-cutout/SKILL.md +30 -25
  27. package/plugin/skills/agentphoto-design/SKILL.md +24 -24
  28. package/plugin/skills/agentphoto-publish/SKILL.md +10 -10
  29. package/plugin/skills/agentphoto-retouch/SKILL.md +26 -26
  30. package/plugin/skills/agentphoto-retouch/references/filters.md +1 -1
  31. package/plugin/skills/agentphoto-retouch/references/patch-ops.md +14 -13
  32. package/plugin/skills/agentphoto-retouch/references/recipes.md +3 -3
  33. package/templates/product-white/photo.json +2 -2
  34. package/templates/product-white/preview.jpg +0 -0
  35. package/templates/product-white/template.json +1 -1
  36. package/dist/studio/assets/index-Be8JnaFy.js +0 -28
  37. package/dist/studio/assets/index-DwPms2S5.css +0 -1
@@ -5,18 +5,19 @@ __apRequire(import.meta.url);
5
5
  const __filename = __apPath(import.meta.url);
6
6
  __apDirname(__filename);
7
7
  import { c as closest, i as validateDoc, u as listOptions } from "./validate-CXPFB-i6.mjs";
8
- import { n as KB, r as OpsError } from "./context-DoLoLF9f.mjs";
8
+ import { n as KB, r as OpsError } from "./context-CNpRboiC.mjs";
9
9
  import { c as filterDef, o as MODELS, r as DEFAULT_MODELS, s as SIZE_PRESETS, t as CATALOG } from "./catalog-DIZ5dnH5.mjs";
10
- import { a as readAssetManifest, i as missingFiles, o as removeAsset, r as listAssets, t as addAsset } from "./assets-CDQo3VqD.mjs";
10
+ import { a as readAssetManifest, i as missingFiles, o as removeAsset, r as listAssets, t as addAsset } from "./assets-BZVUUHjg.mjs";
11
11
  import { n as imageInfo } from "./imageInfo-QxAfu8R6.mjs";
12
12
  import { n as isLibraryRef, r as libraryId, t as findLibraryAsset } from "./library-C_EXiphj.mjs";
13
- import { a as patchDoc, c as layerBox, i as getDoc, n as applyDoc, o as summarizeDoc, t as PATCH_OPS } from "./doc-BjY_j4Su.mjs";
14
- import { l as walkLayers, n as findLayer, r as flattenLayers, s as referencedFiles, t as allLayerIds } from "./tree-DO7N0UDV.mjs";
15
- import { i as loadProject, r as createProject } from "./project-CUykGysG.mjs";
16
- import { n as listTemplates, t as findTemplate } from "./templates--YGpGuHh.mjs";
13
+ import { a as patchDoc, i as getDoc, n as applyDoc, o as summarizeDoc, t as PATCH_OPS } from "./doc-D_v_yE07.mjs";
14
+ import { o as layerBox, t as ANCHORS } from "./geometry-BKIhUO9x.mjs";
15
+ import { l as walkLayers, n as findLayer, r as flattenLayers, s as referencedFiles, t as allLayerIds } from "./tree-D8qZKPAb.mjs";
16
+ import { a as loadProject, i as loadManifest, r as createProject } from "./project-o1DH2nOw.mjs";
17
+ import { n as listTemplates, t as findTemplate } from "./templates-BJ2me4XZ.mjs";
17
18
  import { i as uniqueId } from "./ids-DAmiNwd9.mjs";
18
19
  import { i as isImageMask } from "./types-DOK7tAAu.mjs";
19
- import { r as planExport, t as IMAGE_FORMATS } from "./export-CLmpFART.mjs";
20
+ import { r as planExport, t as IMAGE_FORMATS } from "./export-aNJcPNbJ.mjs";
20
21
  // src/ops/check.ts
21
22
  async function checkProject(fs, opts = {}) {
22
23
  const doc = await getDoc(fs);
@@ -131,6 +132,14 @@ async function checkProject(fs, opts = {}) {
131
132
  };
132
133
  }
133
134
  // src/ai/shared.ts
135
+ function libraryReader(ctx) {
136
+ const lib = ctx.host?.library;
137
+ if (!lib) return void 0;
138
+ return async (id) => {
139
+ const a = lib.index.assets.find((x) => x.id === id);
140
+ return a?.path ? lib.read(a.path) : null;
141
+ };
142
+ }
134
143
  function str(input, key, required = true) {
135
144
  const v = input[key];
136
145
  if (typeof v === "string" && v.trim()) return v.trim();
@@ -265,13 +274,9 @@ function catalogGet(section, id) {
265
274
  };
266
275
  }
267
276
  async function patch(ctx, ops, dryRun) {
268
- const lib = ctx.host?.library;
269
277
  return mutationResult(await patchDoc(ctx.fs, ops, {
270
278
  dryRun,
271
- readLibrary: lib ? async (id) => {
272
- const a = lib.index.assets.find((x) => x.id === id);
273
- return a?.path ? lib.read(a.path) : null;
274
- } : void 0
279
+ readLibrary: libraryReader(ctx)
275
280
  }), dryRun);
276
281
  }
277
282
  async function readInputImage(ctx, input, what) {
@@ -435,7 +440,7 @@ var DOC_TOOLS = [
435
440
  },
436
441
  {
437
442
  name: "doc_patch",
438
- description: `Atomic list of edits, validated together (nothing written if any fails). Ops: ${PATCH_OPS.join(", ")}. Shapes: { op: "set", path: "layers#title.size", value: 96 } · { op: "merge", path, value } (objects merge, null deletes) · { op: "remove", path } · { op: "addLayer", layer, parent?, index?, above?, below? } · { op: "updateLayer", id, set } (deep merge, null deletes a field) · { op: "removeLayer", id } · { op: "moveLayer", id, parent?, index?, above?, below? } · { op: "duplicateLayer", id, newId?, offset? } · { op: "groupLayers", ids, id, name? } · { op: "ungroup", id } · { op: "addFilter", id, filter, index? } · { op: "updateFilter", id, index, set } · { op: "removeFilter", id, index } · { op: "setMask", id, mask | null } · { op: "crop", x, y, width, height } · { op: "resizeCanvas", width, height, anchor? } · { op: "resizeImage", width?, height?, scale? } · { op: "rotateCanvas", angle: 90|180|270 } · { op: "flipCanvas", axis: horizontal|vertical }. Paths: "canvas.background", "layers#<id>.<field>", "layers#<id>.filters[0].radius".`,
443
+ description: `Atomic list of edits, validated together (nothing written if any fails). Ops: ${PATCH_OPS.join(", ")}. Shapes: { op: "set", path: "layers#title.size", value: 96 } · { op: "merge", path, value } (objects merge, null deletes) · { op: "remove", path } · { op: "addLayer", layer, parent?, index?, above?, below? } · { op: "updateLayer", id, set } (deep merge, null deletes a field) · { op: "removeLayer", id } · { op: "moveLayer", id, parent?, index?, above?, below? } · { op: "duplicateLayer", id, newId?, offset? } · { op: "groupLayers", ids, id, name? } · { op: "ungroup", id } · { op: "addFilter", id, filter, index? } · { op: "updateFilter", id, index, set } · { op: "removeFilter", id, index } · { op: "setMask", id, mask | null } · { op: "crop", x, y, width, height } · { op: "resizeCanvas", width, height, anchor? } · { op: "resizeImage", width?, height?, scale? } · { op: "rotateCanvas", angle: 90|180|270 } · { op: "flipCanvas", axis: horizontal|vertical } · { op: "fitLayer", id, box: { x, y, width, height }, subject?, anchor? } (scale + move a layer so subject — a canvas-px region of it, e.g. remove_background's subject; default its box — fits in box, aligned on anchor: center, bottom…). Paths: "canvas.background", "layers#<id>.<field>", "layers#<id>.filters[0].radius".`,
439
444
  inputSchema: {
440
445
  type: "object",
441
446
  properties: {
@@ -726,7 +731,7 @@ var DOC_TOOLS = [
726
731
  };
727
732
  const doc = await getDoc(ctx.fs);
728
733
  const { uniqueId, slugify } = await import("./ids-DAmiNwd9.mjs").then((n) => n.t);
729
- const { allLayerIds } = await import("./tree-DO7N0UDV.mjs").then((n) => n.c);
734
+ const { allLayerIds } = await import("./tree-D8qZKPAb.mjs").then((n) => n.c);
730
735
  const id = uniqueId(optStr(input, "layerId") ?? slugify(entry.path.split("/").pop().replace(/\.[^.]+$/, ""), "image"), allLayerIds(doc));
731
736
  const W = doc.canvas.width;
732
737
  const H = doc.canvas.height;
@@ -850,7 +855,7 @@ async function writeMask(ctx, doc, id, img, opts) {
850
855
  mask
851
856
  },
852
857
  ...opts.extraOps ?? []
853
- ]).catch(async (e) => {
858
+ ], { readLibrary: libraryReader(ctx) }).catch(async (e) => {
854
859
  await removeGenerated(ctx.fs, entry.path);
855
860
  throw e;
856
861
  });
@@ -859,14 +864,15 @@ async function writeMask(ctx, doc, id, img, opts) {
859
864
  if (r.applied && prev && prev !== entry.path && prev.startsWith("assets/masks/")) {
860
865
  if (!referencedFiles(r.doc).some((f) => f.path === prev)) await removeGenerated(ctx.fs, prev);
861
866
  }
867
+ const after = r.applied ? findLayer(r.doc.layers, target)?.layer ?? layer : layer;
862
868
  return {
863
869
  mask: entry.path,
864
870
  size: `${img.width}×${img.height}`,
865
- ...img.bbox !== void 0 ? { subject: subjectBox(layer, img) } : {},
871
+ ...img.bbox !== void 0 ? { subject: subjectBox(after, img) } : {},
866
872
  ...mutationResult(r, false)
867
873
  };
868
874
  }
869
- function coverCuts(doc, job) {
875
+ function coverCuts(doc, job, measured = {}) {
870
876
  const { x, y, width, height } = job.source;
871
877
  if (x <= .5 && y <= .5 && width >= doc.canvas.width - 1 && height >= doc.canvas.height - 1) return [];
872
878
  const out = [];
@@ -875,7 +881,8 @@ function coverCuts(doc, job) {
875
881
  if (l.visible === false) continue;
876
882
  if (l.type === "group") visit(l.children ?? []);
877
883
  if (l.type !== "text" && l.type !== "shape") continue;
878
- const b = layerBox(l);
884
+ const m = measured[l.id];
885
+ const b = l.type === "text" && m ? m.ink ?? m : layerBox(l);
879
886
  if (b && (b.x < x - 1 || b.y < y - 1 || b.x + b.width > x + width + 1 || b.y + b.height > y + height + 1)) out.push(l.id);
880
887
  }
881
888
  };
@@ -898,8 +905,42 @@ function subjectBox(layer, img) {
898
905
  height: r(b.height * ky)
899
906
  };
900
907
  }
908
+ async function fitTarget(ctx, layer, fit) {
909
+ if (fit === false || fit === null) return null;
910
+ if (fit !== void 0) {
911
+ const f = fit;
912
+ if (!f || typeof f !== "object" || ![
913
+ "x",
914
+ "y",
915
+ "width",
916
+ "height"
917
+ ].every((k) => typeof f[k] === "number" && Number.isFinite(f[k])) || !(f.width >= 1 && f.height >= 1)) throw new OpsError("invalid", "fit must be { x, y, width, height, anchor? } in canvas px (or false).", "e.g. fit: { \"x\": 500, \"y\": 400, \"width\": 1000, \"height\": 850, \"anchor\": \"bottom\" }.");
918
+ const anchor = f.anchor ?? "center";
919
+ if (!ANCHORS.includes(anchor)) throw new OpsError("invalid", `Unknown anchor "${String(f.anchor)}".`, `Anchors: ${ANCHORS.join(", ")}.`);
920
+ return {
921
+ box: {
922
+ x: f.x,
923
+ y: f.y,
924
+ width: f.width,
925
+ height: f.height
926
+ },
927
+ anchor,
928
+ from: "input"
929
+ };
930
+ }
931
+ if (layer.mask && isImageMask(layer.mask)) return null;
932
+ const manifest = await loadManifest(ctx.fs).catch(() => null);
933
+ const t = manifest?.template ? ctx.host?.templates?.index.find((x) => x.id === manifest.template) : void 0;
934
+ if (!t?.subjectArea || t.slot !== layer.id) return null;
935
+ const { anchor, ...box } = t.subjectArea;
936
+ return {
937
+ box,
938
+ anchor: anchor ?? "center",
939
+ from: `template ${t.id}`
940
+ };
941
+ }
901
942
  async function removeGenerated(fs, path) {
902
- const { removeAsset } = await import("./assets-CDQo3VqD.mjs").then((n) => n.n);
943
+ const { removeAsset } = await import("./assets-BZVUUHjg.mjs").then((n) => n.n);
903
944
  await removeAsset(fs, path, { force: true }).catch(() => void 0);
904
945
  }
905
946
  var IMAGE_TOOLS = [
@@ -940,7 +981,7 @@ var IMAGE_TOOLS = [
940
981
  const maxWidth = num(input, "maxWidth") ?? 1e3;
941
982
  const zoom = input.zoom;
942
983
  if (zoom) {
943
- const { cropDoc } = await import("./doc-BjY_j4Su.mjs").then((n) => n.s);
984
+ const { cropDoc } = await import("./geometry-BKIhUO9x.mjs").then((n) => n.a);
944
985
  doc = cropDoc(doc, {
945
986
  x: zoom.x,
946
987
  y: zoom.y,
@@ -1049,6 +1090,7 @@ var IMAGE_TOOLS = [
1049
1090
  ...v
1050
1091
  })) : [base];
1051
1092
  const files = [];
1093
+ let measured;
1052
1094
  for (const req of reqs) {
1053
1095
  const job = planExport(doc, req);
1054
1096
  const img = await e.exportImage(doc, job);
@@ -1059,7 +1101,8 @@ var IMAGE_TOOLS = [
1059
1101
  note = `${job.format.toUpperCase()} encoding is not supported by this browser: written as ${img.mime}.`;
1060
1102
  }
1061
1103
  await ctx.fs.writeBytes(path, img.bytes);
1062
- const cut = coverCuts(doc, job);
1104
+ if ((job.source.x > .5 || job.source.y > .5 || job.source.width < doc.canvas.width - 1 || job.source.height < doc.canvas.height - 1) && measured === void 0) measured = await e.layerBoxes?.(doc).catch(() => void 0) ?? {};
1105
+ const cut = coverCuts(doc, job, measured);
1063
1106
  if (cut.length) note = `${note ? `${note} ` : ""}fit "cover" crops the canvas to ${Math.round(job.source.width)}×${Math.round(job.source.height)} and cuts layer${cut.length > 1 ? "s" : ""} ${cut.join(", ")}: use fit "contain", or adapt the layout (doc_patch resizeCanvas / move layers) for this size.`;
1064
1107
  if (job.scale > 1.05) note = `${note ? `${note} ` : ""}Upscaled ×${Math.round(job.scale * 100) / 100} from the ${doc.canvas.width}×${doc.canvas.height} canvas: it may look soft.`;
1065
1108
  files.push({
@@ -1125,6 +1168,11 @@ var IMAGE_TOOLS = [
1125
1168
  shadow: {
1126
1169
  type: "boolean",
1127
1170
  description: "Add a soft drop shadow under the subject."
1171
+ },
1172
+ fit: {
1173
+ type: ["object", "boolean"],
1174
+ description: "Scale and move the layer so the cut-out subject fits this canvas box: { x, y, width, height, anchor? } (anchor: center (default), bottom = standing on a floor line, top, left…). false leaves the layer where it is. Default: a template's subject area on its photo slot (first cut-out after a photo swap), otherwise nothing moves.",
1175
+ additionalProperties: true
1128
1176
  }
1129
1177
  },
1130
1178
  required: ["id"]
@@ -1136,6 +1184,7 @@ var IMAGE_TOOLS = [
1136
1184
  const doc = await getDoc(ctx.fs);
1137
1185
  const layer = layerOf(doc, id);
1138
1186
  if (layer.type !== "image") throw new OpsError("invalid", `"${id}" is a ${layer.type} layer: background removal works on image layers.`);
1187
+ const fit = await fitTarget(ctx, layer, input.fit);
1139
1188
  const model = optStr(input, "model") ?? DEFAULT_MODELS["background-removal"];
1140
1189
  const img = await engine(ctx).backgroundMask(doc, id, {
1141
1190
  model,
@@ -1143,6 +1192,14 @@ var IMAGE_TOOLS = [
1143
1192
  threshold: num(input, "threshold")
1144
1193
  });
1145
1194
  const extra = [];
1195
+ const found = subjectBox(layer, img);
1196
+ if (fit && found) extra.push({
1197
+ op: "fitLayer",
1198
+ id,
1199
+ box: fit.box,
1200
+ subject: found,
1201
+ anchor: fit.anchor
1202
+ });
1146
1203
  if (input.background !== void 0 && input.background !== null) {
1147
1204
  const bgId = uniqueId(`${id}-background`, allLayerIds(doc));
1148
1205
  extra.push({
@@ -1167,14 +1224,22 @@ var IMAGE_TOOLS = [
1167
1224
  blur: 30
1168
1225
  } } }
1169
1226
  });
1227
+ const r = await writeMask(ctx, doc, id, img, {
1228
+ label: "cutout",
1229
+ extraOps: extra,
1230
+ source: `remove_background:${model}`
1231
+ });
1232
+ const fitted = fit && found && r.applied === true ? {
1233
+ box: fit.box,
1234
+ anchor: fit.anchor,
1235
+ from: fit.from
1236
+ } : void 0;
1237
+ const place = fitted ? `The layer was scaled and moved so the subject fits ${JSON.stringify(fitted.box)} (anchor ${fitted.anchor}, from the ${fitted.from}); fit: false keeps the layer where it was.` : `To recentre / rescale it: doc_patch [{ "op": "fitLayer", "id": "${id}", "subject": <subject>, "box": { "x", "y", "width", "height" }, "anchor": "center" | "bottom" }] (or remove_background again with fit).`;
1170
1238
  return {
1171
- ...await writeMask(ctx, doc, id, img, {
1172
- label: "cutout",
1173
- extraOps: extra,
1174
- source: `remove_background:${model}`
1175
- }),
1239
+ ...r,
1176
1240
  model,
1177
- hint: "subject = the kept area in canvas px (null: nothing found). Center / scale the layer from it if needed, then render_preview (zoom on an edge: hair, fingers) to check; refine with mask_generate (points) or threshold / feather."
1241
+ ...fitted ? { fitted } : {},
1242
+ hint: `subject = the kept area in canvas px (null: nothing found). ${place} Then render_preview (zoom on an edge: hair, fingers) to check; refine with mask_generate (points) or threshold / feather.`
1178
1243
  };
1179
1244
  }
1180
1245
  },
@@ -52,7 +52,7 @@ function layerDetail(l) {
52
52
  case "text": return `${JSON.stringify(short(String(l.text ?? "")))} (${l.font ?? "inter"} ${l.size ?? 64})`;
53
53
  case "shape": return `${l.shape}${typeof l.fill === "string" ? ` ${l.fill}` : l.fill ? " gradient" : ""}`;
54
54
  case "fill": return typeof l.fill === "string" ? l.fill : `${l.fill?.type ?? "?"} gradient`;
55
- case "adjustment": return (l.filters ?? []).map((f) => f.type === "look" ? `look:${String(f.look)}` : f.type).join(", ") || "(empty)";
55
+ case "adjustment": return l.filters?.length ? "filters the layers below" : "(empty)";
56
56
  case "group": return `${l.children?.length ?? 0} layers`;
57
57
  default: return "";
58
58
  }
@@ -88,7 +88,7 @@ function flatLayer(l, parent, depth, index) {
88
88
  if (l.clip) out.clip = true;
89
89
  const mk = maskKind(l);
90
90
  if (mk) out.mask = l.mask && l.mask.enabled === false ? `${mk} (disabled)` : mk;
91
- if (l.type !== "adjustment" && l.filters?.length) out.filters = l.filters.map((f) => (f.type === "look" ? `look:${String(f.look)}` : f.type) + (f.enabled === false ? " (off)" : ""));
91
+ if (l.filters?.length) out.filters = l.filters.map((f) => (f.type === "look" ? `look:${String(f.look)}` : f.type) + (f.enabled === false ? " (off)" : ""));
92
92
  if (l.effects) {
93
93
  const fx = Object.entries(l.effects).filter(([, v]) => v).map(([k]) => k);
94
94
  if (fx.length) out.effects = fx;