@mainsoft/agent-cms 0.10.1 → 0.11.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 (87) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +98 -2
  3. package/TODO.md +6 -6
  4. package/UPGRADE-0.11.md +43 -0
  5. package/dist/agent.d.cts +1 -1
  6. package/dist/agent.d.ts +1 -1
  7. package/dist/agent.js +7 -7
  8. package/dist/bin.js +236 -23
  9. package/dist/{chunk-IU2SMWAM.js → chunk-42PW3HQ3.js} +15 -1
  10. package/dist/{chunk-6PB4ZCHH.js → chunk-CIMW73L3.js} +58 -1
  11. package/dist/{chunk-7Y6TU2UA.js → chunk-HY4ED7LT.js} +2 -2
  12. package/dist/{chunk-DSJETZT4.js → chunk-I3DF6DMI.js} +15 -10
  13. package/dist/{chunk-KAO3Z3CF.js → chunk-I5UHTAAW.js} +3 -1
  14. package/dist/{chunk-7SCYDG2G.js → chunk-J25IKU7C.js} +164 -28
  15. package/dist/{chunk-BFVBHIHV.js → chunk-J5DW3RFQ.js} +4 -1
  16. package/dist/{chunk-7WJIIJCI.js → chunk-LELPCGDX.js} +8 -5
  17. package/dist/{chunk-QMPSOLLH.js → chunk-NO6S7KOL.js} +1 -1
  18. package/dist/{chunk-ZCUJ4MPT.js → chunk-OLHLSSTD.js} +3 -3
  19. package/dist/{chunk-3OPKTBEI.js → chunk-SV3ZA6XP.js} +1 -1
  20. package/dist/{chunk-PEQY4N73.js → chunk-TKKTEGHL.js} +1 -0
  21. package/dist/{chunk-PGV2QPIL.js → chunk-WWG7XDIZ.js} +2 -0
  22. package/dist/cli.cjs +236 -23
  23. package/dist/cli.d.cts +2 -2
  24. package/dist/cli.d.ts +2 -2
  25. package/dist/cli.js +18 -16
  26. package/dist/client.cjs +4 -1
  27. package/dist/client.d.cts +14 -2
  28. package/dist/client.d.ts +14 -2
  29. package/dist/client.js +1 -1
  30. package/dist/{cms-pqJyowu1.d.ts → cms-A9tmLmTP.d.ts} +100 -5
  31. package/dist/{cms-C_vkAxYV.d.cts → cms-CaB81PPX.d.cts} +100 -5
  32. package/dist/config.d.cts +1 -1
  33. package/dist/config.d.ts +1 -1
  34. package/dist/{drizzle-repo-DWLD0rWe.d.ts → drizzle-repo-BXV-hFkE.d.ts} +1 -1
  35. package/dist/{drizzle-repo-CviH3EX7.d.cts → drizzle-repo-CblPVYnK.d.cts} +1 -1
  36. package/dist/errors.cjs +4 -0
  37. package/dist/errors.d.cts +3 -1
  38. package/dist/errors.d.ts +3 -1
  39. package/dist/errors.js +2 -2
  40. package/dist/frontmatter.d.cts +1 -1
  41. package/dist/frontmatter.d.ts +1 -1
  42. package/dist/http.cjs +32 -12
  43. package/dist/http.d.cts +18 -4
  44. package/dist/http.d.ts +18 -4
  45. package/dist/http.js +30 -20
  46. package/dist/image-sharp.cjs +104 -0
  47. package/dist/image-sharp.d.cts +47 -0
  48. package/dist/image-sharp.d.ts +47 -0
  49. package/dist/image-sharp.js +70 -0
  50. package/dist/index.cjs +244 -27
  51. package/dist/index.d.cts +3 -3
  52. package/dist/index.d.ts +3 -3
  53. package/dist/index.js +21 -21
  54. package/dist/mcp.cjs +9 -4
  55. package/dist/mcp.d.cts +1 -1
  56. package/dist/mcp.d.ts +1 -1
  57. package/dist/mcp.js +11 -11
  58. package/dist/messages/en.cjs +2 -0
  59. package/dist/messages/en.js +1 -1
  60. package/dist/messages/ko.cjs +2 -0
  61. package/dist/messages/ko.js +2 -0
  62. package/dist/registry/cms-doc-editor.json +6 -1
  63. package/dist/registry/cms-lib.json +2 -2
  64. package/dist/registry/cms-media-picker.json +2 -2
  65. package/dist/registry/cms-media.json +1 -1
  66. package/dist/registry/registry.json +4 -0
  67. package/dist/storage-vercel-blob.cjs +199 -0
  68. package/dist/storage-vercel-blob.d.cts +98 -0
  69. package/dist/storage-vercel-blob.d.ts +98 -0
  70. package/dist/storage-vercel-blob.js +165 -0
  71. package/dist/storage.cjs +63 -3
  72. package/dist/storage.d.cts +27 -2
  73. package/dist/storage.d.ts +27 -2
  74. package/dist/storage.js +9 -3
  75. package/dist/tables.cjs +15 -1
  76. package/dist/tables.d.cts +154 -1
  77. package/dist/tables.d.ts +154 -1
  78. package/dist/tables.js +2 -2
  79. package/dist/tools.cjs +8 -3
  80. package/dist/tools.d.cts +1 -1
  81. package/dist/tools.d.ts +1 -1
  82. package/dist/tools.js +9 -9
  83. package/dist/types.cjs +5 -0
  84. package/dist/types.d.cts +6 -1
  85. package/dist/types.d.ts +6 -1
  86. package/dist/types.js +3 -3
  87. package/package.json +36 -2
package/dist/index.cjs CHANGED
@@ -548,6 +548,60 @@ var DEFAULT_MAX_FILE_SIZE = 5 * 1024 ** 3;
548
548
  var PART_SIZE = 16 * 1024 * 1024;
549
549
  var THUMB_PREFIX = "_cms/thumbs/";
550
550
  var RESERVED_FOLDER = "_cms";
551
+ var DERIVED_PREFIX = "_cms/derived/";
552
+ var REPLACE_PREFIX = "_cms/replace/";
553
+ function stripJpegMetadata(b) {
554
+ if (b.length < 4 || b[0] !== 255 || b[1] !== 216) return b;
555
+ const keep = [];
556
+ let orientation = 1;
557
+ let dropped = false;
558
+ let i = 2;
559
+ while (i + 4 <= b.length && b[i] === 255) {
560
+ const m = b[i + 1];
561
+ if (m === 218 || m === 217) break;
562
+ if (m === 255) {
563
+ i++;
564
+ continue;
565
+ }
566
+ if (m >= 208 && m <= 215 || m === 1) {
567
+ keep.push([i, i + 2]);
568
+ i += 2;
569
+ continue;
570
+ }
571
+ const end = i + 2 + (b[i + 2] << 8 | b[i + 3]);
572
+ if (end < i + 4 || end > b.length) return b;
573
+ if (m === 225 || m === 237 || m === 254) {
574
+ dropped = true;
575
+ if (m === 225 && end - i >= 18 && b[i + 4] === 69 && b[i + 5] === 120 && b[i + 6] === 105 && b[i + 7] === 102) orientation = exifOrientation(b.subarray(i + 10, end)) ?? orientation;
576
+ } else keep.push([i, end]);
577
+ i = end;
578
+ }
579
+ if (!dropped) return b;
580
+ const turn = orientation >= 2 && orientation <= 8 ? Uint8Array.of(255, 225, 0, 34, 69, 120, 105, 102, 0, 0, 77, 77, 0, 42, 0, 0, 0, 8, 0, 1, 1, 18, 0, 3, 0, 0, 0, 1, 0, orientation, 0, 0, 0, 0, 0, 0) : new Uint8Array();
581
+ const out = new Uint8Array(2 + turn.length + keep.reduce((n, [a, z3]) => n + z3 - a, 0) + b.length - i);
582
+ out.set(b.subarray(0, 2));
583
+ out.set(turn, 2);
584
+ let at = 2 + turn.length;
585
+ for (const [a, z3] of keep) {
586
+ out.set(b.subarray(a, z3), at);
587
+ at += z3 - a;
588
+ }
589
+ out.set(b.subarray(i), at);
590
+ return out;
591
+ }
592
+ function exifOrientation(t) {
593
+ if (t.length < 14) return null;
594
+ const le = t[0] === 73;
595
+ const u16 = (o) => le ? t[o] | t[o + 1] << 8 : t[o] << 8 | t[o + 1];
596
+ const ifd = le ? t[4] | t[5] << 8 | t[6] << 16 | t[7] << 24 : (t[4] << 24 | t[5] << 16 | t[6] << 8 | t[7]) >>> 0;
597
+ if (ifd < 8 || ifd + 2 > t.length) return null;
598
+ const n = u16(ifd);
599
+ for (let k = 0; k < n && ifd + 2 + (k + 1) * 12 <= t.length; k++) {
600
+ const e = ifd + 2 + k * 12;
601
+ if (u16(e) === 274) return u16(e + 8);
602
+ }
603
+ return null;
604
+ }
551
605
  var extOf = (name) => {
552
606
  const m = /\.([a-z0-9]{1,10})$/i.exec(name);
553
607
  return m ? m[1].toLowerCase() : "";
@@ -696,7 +750,7 @@ var MemoryStorage = class {
696
750
  return `memory://${this.o.name ?? "store"}/`;
697
751
  }
698
752
  store(key, body, o) {
699
- this.objects.set(key, { body, mime: o.mime, disposition: o.disposition ?? null, at: (/* @__PURE__ */ new Date()).toISOString() });
753
+ this.objects.set(key, { body, mime: o.mime, disposition: o.disposition ?? null, cacheControl: o.cacheControl ?? null, at: (/* @__PURE__ */ new Date()).toISOString() });
700
754
  }
701
755
  meta(key, v) {
702
756
  return { key, size: v.body.length, mime: v.mime, etag: `"m${v.body.length}"`, lastModified: v.at };
@@ -798,6 +852,16 @@ var MemoryStorage = class {
798
852
  var SIGN_SECONDS = 3600;
799
853
  var MAX_THUMB_BYTES = 512 * 1024;
800
854
  var TAG_MAX = 30;
855
+ var IMAGE_EXT = { webp: "webp", avif: "avif", jpeg: "jpg", png: "png" };
856
+ var FOREVER = "public, max-age=31536000, immutable";
857
+ function stamp(v) {
858
+ let h = 2166136261;
859
+ for (const c of JSON.stringify(v)) h = Math.imul(h ^ c.charCodeAt(0), 16777619);
860
+ return (h >>> 0).toString(36);
861
+ }
862
+ var withRev = (url, rev) => rev > 0 ? `${url}${url.includes("?") ? "&" : "?"}v=${rev}` : url;
863
+ var focalOf = (a) => a.focalX !== null && a.focalY !== null ? { x: a.focalX, y: a.focalY } : null;
864
+ var resizable = (a) => a.kind === "image" && a.mime !== "image/svg+xml" && a.mime !== "image/gif";
801
865
  var assetId = () => import_zod.z.string().regex(ASSET_ID_RE, "not a file id");
802
866
  function humanSize(bytes) {
803
867
  const units = ["B", "KB", "MB", "GB", "TB"];
@@ -819,6 +883,7 @@ function createAssets(ctx) {
819
883
  const names2 = Object.keys(media?.stores ?? {});
820
884
  const filesUrl = (media?.filesUrl ?? "/api/cms/files").replace(/\/+$/, "");
821
885
  const ttl = media?.linkTtlSeconds ?? 300;
886
+ const transforms = media?.transforms ?? null;
822
887
  for (const n of names2) {
823
888
  const s = media.stores[n];
824
889
  const rules = s.accept ?? media.accept ?? DEFAULT_ACCEPT;
@@ -851,11 +916,12 @@ function createAssets(ctx) {
851
916
  function view(a) {
852
917
  const cfg = media?.stores[a.store];
853
918
  const href = `${filesUrl}/${a.id}/${encodeURIComponent(a.name)}`;
854
- return { ...a, visibility: cfg?.visibility ?? "private", href, publicUrl: cfg?.visibility === "public" ? cfg.adapter.publicUrl(a.key) : null, thumbHref: a.thumbKey ? `${href}?thumb=1` : null };
919
+ const direct = cfg?.visibility === "public" ? cfg.adapter.publicUrl(a.key) : null;
920
+ return { ...a, visibility: cfg?.visibility ?? "private", href, publicUrl: direct ? withRev(direct, a.rev) : null, thumbHref: a.thumbKey ? `${href}?thumb=1${a.rev ? `&v=${a.rev}` : ""}` : null };
855
921
  }
856
922
  const info = (a) => {
857
923
  const v = view(a);
858
- return { id: a.id, name: a.name, kind: a.kind, mime: a.mime, size: a.size, width: a.width, height: a.height, duration: a.duration, alt: a.alt, url: v.publicUrl ?? v.href, visibility: v.visibility };
924
+ return { id: a.id, name: a.name, kind: a.kind, mime: a.mime, size: a.size, width: a.width, height: a.height, duration: a.duration, alt: a.alt, url: v.publicUrl ?? v.href, visibility: v.visibility, focal: focalOf(a) };
859
925
  };
860
926
  async function load(id, o = {}) {
861
927
  const a = ASSET_ID_RE.test(id) ? await repo.findAsset(id) : null;
@@ -898,23 +964,25 @@ function createAssets(ctx) {
898
964
  }
899
965
  async function requestUpload(actor, input) {
900
966
  await ctx.ready();
901
- const store2 = storeOf(input.store);
967
+ const target = input.replace ? await replaceable(actor, input.replace, input) : null;
968
+ const store2 = storeOf(target ? target.store : input.store);
902
969
  need(actor, store2.name, "write");
903
- const a = admit(store2, input);
904
- const free = await freeKey(store2, a.folder, a.name);
970
+ const a = target ? admit(store2, { name: target.name, mime: target.mime, size: input.size, folder: target.folder }) : admit(store2, input);
971
+ const id = newAssetId();
972
+ const free = target ? { key: `${REPLACE_PREFIX}${target.id}/${id}${extOf(target.name) ? `.${extOf(target.name)}` : ""}`, name: target.name } : await freeKey(store2, a.folder, a.name);
905
973
  const put2 = { mime: a.mime, disposition: dispositionFor(free.name, a.mime) };
906
974
  const who = ctx.actorRef(actor);
907
975
  let upload;
908
976
  let uploadId = null;
909
- if (input.size <= PART_SIZE) {
910
- const signed = await store2.cfg.adapter.presignPut(free.key, { ...put2, expires: SIGN_SECONDS });
977
+ if (input.size <= PART_SIZE || store2.cfg.adapter.multipart === false) {
978
+ const signed = await store2.cfg.adapter.presignPut(free.key, { ...put2, expires: SIGN_SECONDS, size: input.size });
911
979
  upload = { kind: "single", url: signed.url, headers: signed.headers };
912
980
  } else {
913
981
  uploadId = await store2.cfg.adapter.createMultipart(free.key, put2);
914
982
  upload = { kind: "multipart", partSize: PART_SIZE, partCount: Math.ceil(input.size / PART_SIZE) };
915
983
  }
916
984
  const row = await repo.insertAsset({
917
- id: newAssetId(),
985
+ id,
918
986
  store: store2.name,
919
987
  key: free.key,
920
988
  folder: a.folder,
@@ -962,9 +1030,107 @@ function createAssets(ctx) {
962
1030
  });
963
1031
  if (a.thumbKey) await adapter.delete(a.thumbKey).catch(() => {
964
1032
  });
1033
+ await dropDerived(a);
965
1034
  }
966
1035
  await repo.deleteAsset(a.id);
967
1036
  }
1037
+ async function replaceable(actor, id, input) {
1038
+ const t = await load(id);
1039
+ need(actor, t.store, "delete");
1040
+ if (t.kind === "folder" || mimeOf(cleanName(input.name), input.mime) !== t.mime) throw fail("asset_replace_type", { name: input.name, mime: t.mime });
1041
+ return t;
1042
+ }
1043
+ async function replaced(actor, t, now) {
1044
+ const adapter = storeOf(t.store).cfg.adapter;
1045
+ if (t.thumbKey) await adapter.delete(t.thumbKey).catch(() => {
1046
+ });
1047
+ await dropDerived(t);
1048
+ const row = await repo.updateAsset(t.id, { ...now, thumbKey: null, rev: t.rev + 1, updatedAt: ctx.nowIso() });
1049
+ ctx.audit(actor, "asset.replace", { detail: { id: t.id, store: t.store, key: t.key, size: now.size, was: t.size } });
1050
+ return row;
1051
+ }
1052
+ async function replace(actor, id, input) {
1053
+ await ctx.ready();
1054
+ const t = await replaceable(actor, id, { name: (await load(id)).name, mime: input.mime });
1055
+ const store2 = storeOf(t.store);
1056
+ const bytes = media?.stripMetadata && t.mime === "image/jpeg" ? stripJpegMetadata(input.bytes) : input.bytes;
1057
+ admit(store2, { name: t.name, mime: t.mime, size: bytes.length, folder: t.folder });
1058
+ if (!contentMatches(t.mime, bytes.subarray(0, 4096))) throw fail("asset_type_mismatch", { name: t.name, mime: t.mime });
1059
+ await scanned(actor, { store: t.store, key: t.key, name: t.name, mime: t.mime, size: bytes.length, bytes }, null);
1060
+ await store2.cfg.adapter.put(t.key, bytes, { mime: t.mime, disposition: dispositionFor(t.name, t.mime) });
1061
+ const given = dims(input);
1062
+ const read = t.kind === "image" && !given.width ? imageSize(bytes) : null;
1063
+ return view(await serverThumb(await replaced(actor, t, { size: bytes.length, width: given.width ?? read?.width ?? null, height: given.height ?? read?.height ?? null, duration: given.duration }), bytes));
1064
+ }
1065
+ const made = /* @__PURE__ */ new Set();
1066
+ const making = /* @__PURE__ */ new Map();
1067
+ const waiting = [];
1068
+ let active = 0;
1069
+ const jobOf = (a, p) => ({ width: p.width ?? null, height: p.height ?? null, fit: p.fit ?? "inside", format: p.format ?? transforms.format, quality: p.quality ?? null, focal: focalOf(a) });
1070
+ async function sized(a, size) {
1071
+ const preset = transforms?.presets[size];
1072
+ if (!transforms || !preset) throw fail("unknown_image_size", { size });
1073
+ if (!resizable(a) || a.size > (transforms.maxInputBytes ?? 40 * 1024 * 1024)) return null;
1074
+ const job = jobOf(a, preset);
1075
+ const key = `${DERIVED_PREFIX}${a.id}/${size}-${stamp([a.rev, a.size, job])}.${IMAGE_EXT[job.format]}`;
1076
+ if (made.has(key)) return key;
1077
+ let work = making.get(key);
1078
+ if (!work) {
1079
+ work = (async () => {
1080
+ const adapter = storeOf(a.store).cfg.adapter;
1081
+ if (await adapter.head(key)) return key;
1082
+ if (active >= (transforms.concurrency ?? 4)) await new Promise((go) => waiting.push(go));
1083
+ else active++;
1084
+ try {
1085
+ const bytes = await adapter.readStart(a.key, a.size);
1086
+ if (!bytes) return null;
1087
+ const out = await transforms.make(bytes, job);
1088
+ await adapter.put(key, out.bytes, { mime: `image/${job.format}`, cacheControl: FOREVER });
1089
+ return key;
1090
+ } finally {
1091
+ const next = waiting.shift();
1092
+ if (next) next();
1093
+ else active--;
1094
+ }
1095
+ })().then((k) => (k && made.add(k), k)).catch((e) => (ctx.warn(`image-size-${a.id}-${size}`, `could not make size "${size}" of ${a.key}: ${e instanceof Error ? e.message : String(e)}`), null)).finally(() => making.delete(key));
1096
+ making.set(key, work);
1097
+ }
1098
+ let timer;
1099
+ const late = new Promise((r) => timer = setTimeout(() => r(null), transforms.timeoutMs ?? 1e4));
1100
+ try {
1101
+ return await Promise.race([work, late]);
1102
+ } finally {
1103
+ clearTimeout(timer);
1104
+ }
1105
+ }
1106
+ async function dropDerived(a) {
1107
+ const adapter = media?.stores[a.store]?.adapter;
1108
+ if (!adapter || !transforms) return;
1109
+ try {
1110
+ let cursor = null;
1111
+ do {
1112
+ const page = await adapter.list({ prefix: `${DERIVED_PREFIX}${a.id}/`, cursor, limit: 200 });
1113
+ for (const o of page.objects) {
1114
+ await adapter.delete(o.key).catch(() => {
1115
+ });
1116
+ made.delete(o.key);
1117
+ }
1118
+ cursor = page.cursor;
1119
+ } while (cursor);
1120
+ } catch {
1121
+ }
1122
+ }
1123
+ async function serverThumb(row, bytes) {
1124
+ if (!transforms || !resizable(row) || bytes.length > (transforms.maxInputBytes ?? 40 * 1024 * 1024)) return row;
1125
+ try {
1126
+ const out = await transforms.make(bytes, { width: 480, height: 480, fit: "inside", format: "webp", quality: null, focal: null });
1127
+ const key = `${THUMB_PREFIX}${row.id}.webp`;
1128
+ await storeOf(row.store).cfg.adapter.put(key, out.bytes, { mime: "image/webp", cacheControl: FOREVER });
1129
+ return await repo.updateAsset(row.id, { thumbKey: key }) ?? row;
1130
+ } catch {
1131
+ return row;
1132
+ }
1133
+ }
968
1134
  const dims = (o) => {
969
1135
  const int = (v) => typeof v === "number" && Number.isFinite(v) && v > 0 && v < 1e5 ? Math.round(v) : null;
970
1136
  return { width: int(o.width), height: int(o.height), duration: typeof o.duration === "number" && Number.isFinite(o.duration) && o.duration >= 0 ? o.duration : null };
@@ -999,6 +1165,19 @@ function createAssets(ctx) {
999
1165
  });
1000
1166
  const given = dims(meta);
1001
1167
  const read = a.kind === "image" && !given.width ? imageSize(start) : null;
1168
+ const settle = (key, name) => adapter.settle?.(key, { mime: a.mime, disposition: dispositionFor(name, a.mime) });
1169
+ if (a.key.startsWith(REPLACE_PREFIX)) {
1170
+ const t = await repo.findAsset(a.key.slice(REPLACE_PREFIX.length).split("/")[0]);
1171
+ if (!t || t.status !== "ready" || !canAsset(actor, t.store, "delete")) {
1172
+ await discard({ ...a, uploadId: null });
1173
+ throw fail("asset_not_found", { id });
1174
+ }
1175
+ await adapter.copy(a.key, t.key);
1176
+ await settle(t.key, t.name);
1177
+ await discard({ ...a, uploadId: null });
1178
+ return view(await replaced(actor, t, { size: head.size, width: given.width ?? read?.width ?? null, height: given.height ?? read?.height ?? null, duration: given.duration }));
1179
+ }
1180
+ await settle(a.key, a.name);
1002
1181
  const row = await repo.updateAsset(a.id, { status: "ready", uploadId: null, width: given.width ?? read?.width ?? null, height: given.height ?? read?.height ?? null, duration: given.duration, updatedAt: ctx.nowIso() });
1003
1182
  ctx.audit(actor, "asset.upload", { detail: { id: a.id, store: a.store, key: a.key, size: a.size } });
1004
1183
  return view(row);
@@ -1024,6 +1203,7 @@ function createAssets(ctx) {
1024
1203
  await ctx.ready();
1025
1204
  const store2 = storeOf(input.store);
1026
1205
  need(actor, store2.name, "write");
1206
+ if (media?.stripMetadata && mimeOf(cleanName(input.name), input.mime) === "image/jpeg") input = { ...input, bytes: stripJpegMetadata(input.bytes) };
1027
1207
  const a = admit(store2, { ...input, size: input.bytes.length });
1028
1208
  if (!contentMatches(a.mime, input.bytes.subarray(0, 4096))) throw fail("asset_type_mismatch", { name: a.name, mime: a.mime });
1029
1209
  const free = await freeKey(store2, a.folder, a.name);
@@ -1057,7 +1237,7 @@ function createAssets(ctx) {
1057
1237
  updatedAt: ctx.nowIso()
1058
1238
  });
1059
1239
  ctx.audit(actor, "asset.upload", { detail: { id: row.id, store: row.store, key: row.key, size: row.size } });
1060
- return view(row);
1240
+ return view(await serverThumb(row, input.bytes));
1061
1241
  }
1062
1242
  async function importFromUrl(actor, input) {
1063
1243
  const store2 = storeOf(input.store);
@@ -1168,7 +1348,10 @@ function createAssets(ctx) {
1168
1348
  async function update(actor, id, patch) {
1169
1349
  const a = await load(id);
1170
1350
  need(actor, a.store, "write");
1171
- const row = await repo.updateAsset(a.id, { ...patch.alt !== void 0 ? { alt: String(patch.alt).trim().slice(0, 500) } : {}, ...patch.tags !== void 0 ? { tags: cleanTags(patch.tags) } : {}, updatedAt: ctx.nowIso() });
1351
+ const unit = (v) => Math.round(Math.min(1, Math.max(0, Number(v) || 0)) * 1e3) / 1e3;
1352
+ const focal = patch.focal === void 0 ? {} : patch.focal === null || a.kind !== "image" ? { focalX: null, focalY: null } : { focalX: unit(patch.focal.x), focalY: unit(patch.focal.y) };
1353
+ const row = await repo.updateAsset(a.id, { ...patch.alt !== void 0 ? { alt: String(patch.alt).trim().slice(0, 500) } : {}, ...patch.tags !== void 0 ? { tags: cleanTags(patch.tags) } : {}, ...focal, updatedAt: ctx.nowIso() });
1354
+ if ("focalX" in focal && (focal.focalX !== a.focalX || focal.focalY !== a.focalY)) await dropDerived(a);
1172
1355
  return view(row);
1173
1356
  }
1174
1357
  async function move(actor, id, to) {
@@ -1238,8 +1421,9 @@ function createAssets(ctx) {
1238
1421
  const a = await load(id);
1239
1422
  const store2 = storeOf(a.store);
1240
1423
  if (store2.cfg.visibility === "private" || store2.cfg.access?.read) need(actor, a.store, "read");
1241
- const key = o.thumb && a.thumbKey ? a.thumbKey : a.key;
1242
- const direct = store2.cfg.visibility === "public" && !o.download ? store2.cfg.adapter.publicUrl(key) : null;
1424
+ const key = o.thumb && a.thumbKey ? a.thumbKey : o.size && !o.thumb ? await sized(a, o.size) ?? a.key : a.key;
1425
+ const plain = store2.cfg.visibility === "public" && !o.download ? store2.cfg.adapter.publicUrl(key) : null;
1426
+ const direct = plain && !key.startsWith(DERIVED_PREFIX) ? withRev(plain, a.rev) : plain;
1243
1427
  return { url: direct ?? await store2.cfg.adapter.presignGet(key, { expires: ttl, download: o.download ? a.name : null }), visibility: store2.cfg.visibility, ttl };
1244
1428
  }
1245
1429
  async function cleanup(o = {}) {
@@ -1319,7 +1503,9 @@ function createAssets(ctx) {
1319
1503
  return Object.fromEntries(rows.filter((a) => a.status === "ready" && media.stores[a.store]).map((a) => [a.id, info(a)]));
1320
1504
  }
1321
1505
  function imageUrl(asset, o) {
1322
- return media?.imageUrl && asset.kind === "image" && asset.mime !== "image/svg+xml" ? media.imageUrl({ url: asset.url, width: o.width, asset }) : asset.url;
1506
+ if (asset.kind !== "image" || asset.mime === "image/svg+xml") return asset.url;
1507
+ if (o.size && transforms?.presets[o.size] && asset.mime !== "image/gif") return `${filesUrl}/${asset.id}/${encodeURIComponent(asset.name)}?size=${encodeURIComponent(o.size)}`;
1508
+ return media?.imageUrl && o.width ? media.imageUrl({ url: asset.url, width: o.width, asset }) : asset.url;
1323
1509
  }
1324
1510
  async function scanned(actor, f, adapter) {
1325
1511
  if (!media?.scan) return;
@@ -1530,9 +1716,9 @@ function createAssets(ctx) {
1530
1716
  if (!media) return null;
1531
1717
  const stores = names2.filter((n) => canAsset(actor, n, "read")).map((n) => {
1532
1718
  const cfg = media.stores[n];
1533
- return { name: n, label: cfg.label ?? n, visibility: cfg.visibility, ...rulesOf(cfg), can: { write: canAsset(actor, n, "write"), delete: canAsset(actor, n, "delete"), browse: canBrowse(actor, n) } };
1719
+ return { name: n, label: cfg.label ?? n, visibility: cfg.visibility, ...rulesOf(cfg), parts: cfg.adapter.multipart !== false, can: { write: canAsset(actor, n, "write"), delete: canAsset(actor, n, "delete"), browse: canBrowse(actor, n) } };
1534
1720
  });
1535
- return stores.length ? { stores, partSize: PART_SIZE } : null;
1721
+ return stores.length ? { stores, partSize: PART_SIZE, stripMetadata: !!media.stripMetadata, sizes: Object.keys(transforms?.presets ?? {}) } : null;
1536
1722
  }
1537
1723
  return {
1538
1724
  enabled: !!media && names2.length > 0,
@@ -1546,6 +1732,7 @@ function createAssets(ctx) {
1546
1732
  abortUpload,
1547
1733
  setThumb,
1548
1734
  put,
1735
+ replace,
1549
1736
  import: importFromUrl,
1550
1737
  list,
1551
1738
  folders,
@@ -1634,6 +1821,8 @@ var en = {
1634
1821
  import_blocked: "That address cannot be fetched",
1635
1822
  import_failed: "Could not fetch the file ({reason})",
1636
1823
  asset_rejected: "This file did not pass the check",
1824
+ asset_replace_type: "A file can only be replaced by one of the same type ({mime})",
1825
+ unknown_image_size: "There is no image size named \u201C{size}\u201D",
1637
1826
  asset_missing: "The file {id} does not exist",
1638
1827
  asset_wrong_kind: "The file {id} is not a kind this field takes",
1639
1828
  asset_alt_missing: "The image on line {line} has no alt text",
@@ -1724,6 +1913,8 @@ var ERROR_CODES = {
1724
1913
  import_blocked: "invalid",
1725
1914
  import_failed: "invalid",
1726
1915
  asset_rejected: "invalid",
1916
+ asset_replace_type: "invalid",
1917
+ unknown_image_size: "not_found",
1727
1918
  asset_missing: "invalid",
1728
1919
  asset_wrong_kind: "invalid",
1729
1920
  asset_alt_missing: "invalid",
@@ -1903,6 +2094,7 @@ var AUDIT_ACTIONS = [
1903
2094
  "review.reject",
1904
2095
  "release.publish",
1905
2096
  "asset.restore",
2097
+ "asset.replace",
1906
2098
  "preview.create",
1907
2099
  "asset.upload",
1908
2100
  "asset.move",
@@ -2599,7 +2791,7 @@ function displayPrefix(raw) {
2599
2791
  }
2600
2792
 
2601
2793
  // src/schema-version.ts
2602
- var SCHEMA_VERSION = 4;
2794
+ var SCHEMA_VERSION = 5;
2603
2795
 
2604
2796
  // src/search.ts
2605
2797
  var HANGUL = /[\uac00-\ud7a3]/;
@@ -3641,17 +3833,17 @@ ${h.added.join("\n")}`).digest("hex").slice(0, 12);
3641
3833
  const t = Date.now();
3642
3834
  if (index2.built && !index2.dirty && t - index2.checkedAt > refreshMs) {
3643
3835
  index2.checkedAt = t;
3644
- const stamp = await repo.changeStamp().catch(() => index2.stamp);
3645
- if (stamp !== index2.stamp) index2.dirty = true;
3836
+ const stamp2 = await repo.changeStamp().catch(() => index2.stamp);
3837
+ if (stamp2 !== index2.stamp) index2.dirty = true;
3646
3838
  }
3647
3839
  if (index2.built && !index2.dirty) return index2.built;
3648
3840
  if (!index2.building) {
3649
3841
  index2.dirty = false;
3650
3842
  index2.building = (async () => {
3651
- const stamp = await repo.changeStamp();
3843
+ const stamp2 = await repo.changeStamp();
3652
3844
  const built = await buildIndex();
3653
3845
  index2.built = built;
3654
- index2.stamp = stamp;
3846
+ index2.stamp = stamp2;
3655
3847
  index2.checkedAt = Date.now();
3656
3848
  return built;
3657
3849
  })().catch((err) => {
@@ -4057,6 +4249,9 @@ function cmsTables(o = {}) {
4057
4249
  alt: (0, import_pg_core.text)("alt").notNull().default(""),
4058
4250
  tags: (0, import_pg_core.jsonb)("tags").$type().notNull().default([]),
4059
4251
  thumbKey: (0, import_pg_core.text)("thumb_key"),
4252
+ focalX: (0, import_pg_core.real)("focal_x"),
4253
+ focalY: (0, import_pg_core.real)("focal_y"),
4254
+ rev: (0, import_pg_core.integer)("rev").notNull().default(0),
4060
4255
  status: (0, import_pg_core.text)("status").notNull().default("pending"),
4061
4256
  uploadId: (0, import_pg_core.text)("upload_id"),
4062
4257
  createdBy: (0, import_pg_core.text)("created_by"),
@@ -4233,6 +4428,9 @@ CREATE TABLE IF NOT EXISTS ${tbl("assets")} (
4233
4428
  "alt" text NOT NULL DEFAULT '',
4234
4429
  "tags" jsonb NOT NULL DEFAULT '[]'::jsonb,
4235
4430
  "thumb_key" text,
4431
+ "focal_x" real,
4432
+ "focal_y" real,
4433
+ "rev" integer NOT NULL DEFAULT 0,
4236
4434
  "status" text NOT NULL DEFAULT 'pending',
4237
4435
  "upload_id" text,
4238
4436
  "created_by" text,
@@ -4322,6 +4520,14 @@ CREATE TABLE IF NOT EXISTS ${tbl("presence")} (
4322
4520
  PRIMARY KEY ("document_id", "actor_id")
4323
4521
  );
4324
4522
  CREATE INDEX IF NOT EXISTS ${idx("presence_seen_idx")} ON ${tbl("presence")} ("seen_at");`.trim()
4523
+ },
4524
+ {
4525
+ version: 5,
4526
+ name: "agent-cms 0.11.0: an image's focal point, replacing a file at the same address",
4527
+ sql: `
4528
+ ALTER TABLE ${tbl("assets")} ADD COLUMN IF NOT EXISTS "focal_x" real;
4529
+ ALTER TABLE ${tbl("assets")} ADD COLUMN IF NOT EXISTS "focal_y" real;
4530
+ ALTER TABLE ${tbl("assets")} ADD COLUMN IF NOT EXISTS "rev" integer NOT NULL DEFAULT 0;`.trim()
4325
4531
  }
4326
4532
  ];
4327
4533
  }
@@ -4554,6 +4760,9 @@ var DrizzleRepo = class _DrizzleRepo {
4554
4760
  alt: r.alt,
4555
4761
  tags: r.tags ?? [],
4556
4762
  thumbKey: r.thumbKey,
4763
+ focalX: r.focalX ?? null,
4764
+ focalY: r.focalY ?? null,
4765
+ rev: r.rev ?? 0,
4557
4766
  status: r.status,
4558
4767
  uploadId: r.uploadId,
4559
4768
  createdBy: r.createdBy,
@@ -5131,7 +5340,7 @@ var MemoryRepo = class {
5131
5340
  if (this.assets.has(a.id)) throw new Error("duplicate asset id");
5132
5341
  for (const o of this.assets.values()) if (o.store === a.store && o.key === a.key) throw new Error("duplicate asset key");
5133
5342
  const now = (/* @__PURE__ */ new Date()).toISOString();
5134
- const row = { deletedAt: null, deletedBy: null, ...structuredClone(a), createdAt: a.createdAt ?? now, updatedAt: a.updatedAt ?? now };
5343
+ const row = { deletedAt: null, deletedBy: null, focalX: null, focalY: null, rev: 0, ...structuredClone(a), createdAt: a.createdAt ?? now, updatedAt: a.updatedAt ?? now };
5135
5344
  this.assets.set(row.id, row);
5136
5345
  return structuredClone(row);
5137
5346
  }
@@ -5630,7 +5839,10 @@ function createRestClient(opts) {
5630
5839
  /** Address of a file by its key (files the CMS has no row for). */
5631
5840
  storeFileUrl: (store2, key, o = {}) => `${base}/stores/${enc(store2)}/files/_open?key=${enc(key)}${o.download ? "&download=1" : ""}`,
5632
5841
  /** Address of a file through the CMS route (`thumb`: its small picture). */
5633
- fileUrl: (a, o = {}) => `${base}/files/${enc(a.id)}/${enc(a.name)}${o.thumb ? "?thumb=1" : o.download ? "?download=1" : ""}`,
5842
+ fileUrl: (a, o = {}) => {
5843
+ const query = [o.thumb ? "thumb=1" : o.download ? "download=1" : o.size ? `size=${enc(o.size)}` : "", a.rev ? `v=${a.rev}` : ""].filter(Boolean).join("&");
5844
+ return `${base}/files/${enc(a.id)}/${enc(a.name)}${query ? `?${query}` : ""}`;
5845
+ },
5634
5846
  audit: (q = {}) => req("GET", "/audit", { query: q })
5635
5847
  };
5636
5848
  }
@@ -6013,9 +6225,14 @@ var CMS_TOOLS = [
6013
6225
  {
6014
6226
  name: "update_asset",
6015
6227
  media: "write",
6016
- description: "Change a file's alt text or tags. Documents that use the file without their own alt text show the new one.",
6017
- input: import_zod2.z.object({ id: assetId2, alt: import_zod2.z.string().optional(), tags: import_zod2.z.array(import_zod2.z.string()).optional() }),
6018
- run: async (cms, actor, a) => assetOut(await cms.assets.update(actor, a.id, { alt: a.alt, tags: a.tags }))
6228
+ description: "Change a file's alt text, tags or focal point. Documents that use the file without their own alt text show the new one.",
6229
+ input: import_zod2.z.object({
6230
+ id: assetId2,
6231
+ alt: import_zod2.z.string().optional(),
6232
+ tags: import_zod2.z.array(import_zod2.z.string()).optional(),
6233
+ focal: import_zod2.z.object({ x: import_zod2.z.number().min(0).max(1), y: import_zod2.z.number().min(0).max(1) }).nullable().optional().describe("Images: the point that stays in view when the picture is cropped, from the left and from the top (0..1). null clears it.")
6234
+ }),
6235
+ run: async (cms, actor, a) => assetOut(await cms.assets.update(actor, a.id, { alt: a.alt, tags: a.tags, focal: a.focal }))
6019
6236
  },
6020
6237
  {
6021
6238
  name: "move_asset",
@@ -6176,7 +6393,7 @@ function docFromMarkdown(text2, fallbackSlug) {
6176
6393
  }
6177
6394
 
6178
6395
  // src/version.ts
6179
- var VERSION = "0.10.1";
6396
+ var VERSION = "0.11.0";
6180
6397
  // Annotate the CommonJS export names for ESM import in node:
6181
6398
  0 && (module.exports = {
6182
6399
  ASSET_KINDS,
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- export { A as AgentChange, a as AnyCollection, b as AssetInfo, c as AssetListOptions, d as AssetPatch, e as AssetQuery, f as AssetUsage, g as AssetView, h as AuditQuery, B as BULK_ACTIONS, i as BulkAction, j as BulkResult, k as ChangeInfo, l as Cms, m as CmsAssets, n as CmsCore, C as CmsLike, o as CmsRepo, p as CollectionName, q as CreateCmsOptions, D as DocDiff, r as DocInput, s as DocPatch, F as FieldsOf, t as FieldsPatch, K as KeyRow, L as LIMITS, u as ListOptions, M as MediaOptions, v as MediaStoreConfig, w as MemoryRepo, N as NewAsset, x as NewAudit, y as NewDoc, z as NewVersion, P as PREVIEW_TTLS, E as PatchOp, G as PreviewLink, H as PreviewRead, I as PreviewTtl, S as SLUG_RE, J as ScanFile, O as SearchOptions, Q as SearchResult, R as SectionRange, T as StoredVersion, U as TypedDoc, V as UploadInstructions, W as UploadRequest, X as WriteOptions, Y as applyPatch, Z as assetFields, _ as assetId, $ as coreOf, a0 as createCms, a1 as createCmsCore, a2 as dayIn, a3 as defineCollection, a4 as humanSize, a5 as mergePatch, a6 as normalizeQuery, a7 as sectionRanges } from './cms-C_vkAxYV.cjs';
2
- export { D as DoctorReport, a as DrizzleRepo, b as DrizzleRepoOptions } from './drizzle-repo-CviH3EX7.cjs';
1
+ export { A as AgentChange, c as AnyCollection, d as AssetInfo, e as AssetListOptions, f as AssetPatch, g as AssetQuery, h as AssetUsage, i as AssetView, j as AuditQuery, B as BULK_ACTIONS, k as BulkAction, l as BulkResult, m as ChangeInfo, n as Cms, o as CmsAssets, p as CmsCore, C as CmsLike, q as CmsRepo, r as CollectionName, s as CreateCmsOptions, D as DocDiff, t as DocInput, u as DocPatch, F as FieldsOf, v as FieldsPatch, K as KeyRow, L as LIMITS, w as ListOptions, M as MediaOptions, x as MediaStoreConfig, y as MemoryRepo, N as NewAsset, z as NewAudit, E as NewDoc, G as NewVersion, P as PREVIEW_TTLS, H as PatchOp, J as PreviewLink, O as PreviewRead, Q as PreviewTtl, S as SLUG_RE, R as ScanFile, T as SearchOptions, U as SearchResult, V as SectionRange, W as StoredVersion, X as TypedDoc, Y as UploadInstructions, Z as UploadRequest, _ as WriteOptions, $ as applyPatch, a0 as assetFields, a1 as assetId, a2 as coreOf, a3 as createCms, a4 as createCmsCore, a5 as dayIn, a6 as defineCollection, a7 as humanSize, a8 as mergePatch, a9 as normalizeQuery, aa as sectionRanges } from './cms-CaB81PPX.cjs';
2
+ export { D as DoctorReport, a as DrizzleRepo, b as DrizzleRepoOptions } from './drizzle-repo-CblPVYnK.cjs';
3
3
  export { CmsTables, CmsTablesOptions, SCHEMA_VERSION, cmsApiKeys, cmsAssetRefs, cmsAssets, cmsAudit, cmsComments, cmsDdl, cmsDocuments, cmsHits, cmsMeta, cmsPresence, cmsReleases, cmsSavedFilters, cmsTables, cmsVersions, defaultTables, schemaVersionSql, splitSql, upgradeSteps } from './tables.cjs';
4
4
  export { AgentLink, AgentLookup, AgentSection, Citation, ENVELOPE_PREAMBLE, LookupOptions, citationId, envelope, lookupForAgent, verifyCitations } from './agent.cjs';
5
5
  export { CMS_TOOLS, CMS_TOOL_NAMES, CallToolOptions, CmsToolDef, ToolErrorResult, ToolOutcome, callTool, runTool, toolErrorResult, toolsFor } from './tools.cjs';
@@ -14,6 +14,6 @@ import './diff.cjs';
14
14
  import 'drizzle-orm/pg-core';
15
15
 
16
16
  /** Package version (kept in step with package.json by `src/parts.test.ts`). */
17
- declare const VERSION = "0.10.1";
17
+ declare const VERSION = "0.11.0";
18
18
 
19
19
  export { VERSION };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { A as AgentChange, a as AnyCollection, b as AssetInfo, c as AssetListOptions, d as AssetPatch, e as AssetQuery, f as AssetUsage, g as AssetView, h as AuditQuery, B as BULK_ACTIONS, i as BulkAction, j as BulkResult, k as ChangeInfo, l as Cms, m as CmsAssets, n as CmsCore, C as CmsLike, o as CmsRepo, p as CollectionName, q as CreateCmsOptions, D as DocDiff, r as DocInput, s as DocPatch, F as FieldsOf, t as FieldsPatch, K as KeyRow, L as LIMITS, u as ListOptions, M as MediaOptions, v as MediaStoreConfig, w as MemoryRepo, N as NewAsset, x as NewAudit, y as NewDoc, z as NewVersion, P as PREVIEW_TTLS, E as PatchOp, G as PreviewLink, H as PreviewRead, I as PreviewTtl, S as SLUG_RE, J as ScanFile, O as SearchOptions, Q as SearchResult, R as SectionRange, T as StoredVersion, U as TypedDoc, V as UploadInstructions, W as UploadRequest, X as WriteOptions, Y as applyPatch, Z as assetFields, _ as assetId, $ as coreOf, a0 as createCms, a1 as createCmsCore, a2 as dayIn, a3 as defineCollection, a4 as humanSize, a5 as mergePatch, a6 as normalizeQuery, a7 as sectionRanges } from './cms-pqJyowu1.js';
2
- export { D as DoctorReport, a as DrizzleRepo, b as DrizzleRepoOptions } from './drizzle-repo-DWLD0rWe.js';
1
+ export { A as AgentChange, c as AnyCollection, d as AssetInfo, e as AssetListOptions, f as AssetPatch, g as AssetQuery, h as AssetUsage, i as AssetView, j as AuditQuery, B as BULK_ACTIONS, k as BulkAction, l as BulkResult, m as ChangeInfo, n as Cms, o as CmsAssets, p as CmsCore, C as CmsLike, q as CmsRepo, r as CollectionName, s as CreateCmsOptions, D as DocDiff, t as DocInput, u as DocPatch, F as FieldsOf, v as FieldsPatch, K as KeyRow, L as LIMITS, w as ListOptions, M as MediaOptions, x as MediaStoreConfig, y as MemoryRepo, N as NewAsset, z as NewAudit, E as NewDoc, G as NewVersion, P as PREVIEW_TTLS, H as PatchOp, J as PreviewLink, O as PreviewRead, Q as PreviewTtl, S as SLUG_RE, R as ScanFile, T as SearchOptions, U as SearchResult, V as SectionRange, W as StoredVersion, X as TypedDoc, Y as UploadInstructions, Z as UploadRequest, _ as WriteOptions, $ as applyPatch, a0 as assetFields, a1 as assetId, a2 as coreOf, a3 as createCms, a4 as createCmsCore, a5 as dayIn, a6 as defineCollection, a7 as humanSize, a8 as mergePatch, a9 as normalizeQuery, aa as sectionRanges } from './cms-A9tmLmTP.js';
2
+ export { D as DoctorReport, a as DrizzleRepo, b as DrizzleRepoOptions } from './drizzle-repo-BXV-hFkE.js';
3
3
  export { CmsTables, CmsTablesOptions, SCHEMA_VERSION, cmsApiKeys, cmsAssetRefs, cmsAssets, cmsAudit, cmsComments, cmsDdl, cmsDocuments, cmsHits, cmsMeta, cmsPresence, cmsReleases, cmsSavedFilters, cmsTables, cmsVersions, defaultTables, schemaVersionSql, splitSql, upgradeSteps } from './tables.js';
4
4
  export { AgentLink, AgentLookup, AgentSection, Citation, ENVELOPE_PREAMBLE, LookupOptions, citationId, envelope, lookupForAgent, verifyCitations } from './agent.js';
5
5
  export { CMS_TOOLS, CMS_TOOL_NAMES, CallToolOptions, CmsToolDef, ToolErrorResult, ToolOutcome, callTool, runTool, toolErrorResult, toolsFor } from './tools.js';
@@ -14,6 +14,6 @@ import './diff.js';
14
14
  import 'drizzle-orm/pg-core';
15
15
 
16
16
  /** Package version (kept in step with package.json by `src/parts.test.ts`). */
17
- declare const VERSION = "0.10.1";
17
+ declare const VERSION = "0.11.0";
18
18
 
19
19
  export { VERSION };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DrizzleRepo
3
- } from "./chunk-7WJIIJCI.js";
3
+ } from "./chunk-LELPCGDX.js";
4
4
  import {
5
5
  docFromMarkdown,
6
6
  parseFrontmatter
@@ -24,10 +24,10 @@ import {
24
24
  schemaVersionSql,
25
25
  splitSql,
26
26
  upgradeSteps
27
- } from "./chunk-IU2SMWAM.js";
27
+ } from "./chunk-42PW3HQ3.js";
28
28
  import {
29
29
  VERSION
30
- } from "./chunk-QMPSOLLH.js";
30
+ } from "./chunk-NO6S7KOL.js";
31
31
  import {
32
32
  CMS_TOOLS,
33
33
  CMS_TOOL_NAMES,
@@ -35,20 +35,14 @@ import {
35
35
  runTool,
36
36
  toolErrorResult,
37
37
  toolsFor
38
- } from "./chunk-DSJETZT4.js";
39
- import {
40
- CmsRemoteError,
41
- createCmsClient,
42
- createRestClient,
43
- isCmsRemoteError
44
- } from "./chunk-BFVBHIHV.js";
38
+ } from "./chunk-I3DF6DMI.js";
45
39
  import {
46
40
  ENVELOPE_PREAMBLE,
47
41
  citationId,
48
42
  envelope,
49
43
  lookupForAgent,
50
44
  verifyCitations
51
- } from "./chunk-7Y6TU2UA.js";
45
+ } from "./chunk-HY4ED7LT.js";
52
46
  import {
53
47
  BULK_ACTIONS,
54
48
  LIMITS,
@@ -66,7 +60,7 @@ import {
66
60
  mergePatch,
67
61
  normalizeQuery,
68
62
  sectionRanges
69
- } from "./chunk-7SCYDG2G.js";
63
+ } from "./chunk-J25IKU7C.js";
70
64
  import "./chunk-MA6VKJ3F.js";
71
65
  import {
72
66
  ASSET_KINDS,
@@ -75,23 +69,29 @@ import {
75
69
  KEY_SCOPES,
76
70
  VIAS,
77
71
  docState
78
- } from "./chunk-PEQY4N73.js";
79
- import {
80
- SCHEMA_VERSION
81
- } from "./chunk-3OPKTBEI.js";
82
- import "./chunk-AKN7SUXU.js";
72
+ } from "./chunk-TKKTEGHL.js";
83
73
  import {
84
74
  CmsError,
85
75
  ERROR_CODES,
86
76
  ERROR_KINDS,
87
77
  formatMessage,
88
78
  isCmsError
89
- } from "./chunk-KAO3Z3CF.js";
90
- import "./chunk-PGV2QPIL.js";
79
+ } from "./chunk-I5UHTAAW.js";
80
+ import "./chunk-WWG7XDIZ.js";
81
+ import {
82
+ SCHEMA_VERSION
83
+ } from "./chunk-SV3ZA6XP.js";
84
+ import "./chunk-AKN7SUXU.js";
85
+ import {
86
+ CmsRemoteError,
87
+ createCmsClient,
88
+ createRestClient,
89
+ isCmsRemoteError
90
+ } from "./chunk-J5DW3RFQ.js";
91
91
  import {
92
92
  DEFAULT_ACCEPT,
93
93
  MemoryStorage
94
- } from "./chunk-6PB4ZCHH.js";
94
+ } from "./chunk-CIMW73L3.js";
95
95
  import "./chunk-2NTK7H4W.js";
96
96
 
97
97
  // src/repo.ts
@@ -242,7 +242,7 @@ var MemoryRepo = class {
242
242
  if (this.assets.has(a.id)) throw new Error("duplicate asset id");
243
243
  for (const o of this.assets.values()) if (o.store === a.store && o.key === a.key) throw new Error("duplicate asset key");
244
244
  const now = (/* @__PURE__ */ new Date()).toISOString();
245
- const row = { deletedAt: null, deletedBy: null, ...structuredClone(a), createdAt: a.createdAt ?? now, updatedAt: a.updatedAt ?? now };
245
+ const row = { deletedAt: null, deletedBy: null, focalX: null, focalY: null, rev: 0, ...structuredClone(a), createdAt: a.createdAt ?? now, updatedAt: a.updatedAt ?? now };
246
246
  this.assets.set(row.id, row);
247
247
  return structuredClone(row);
248
248
  }
package/dist/mcp.cjs CHANGED
@@ -634,9 +634,14 @@ var CMS_TOOLS = [
634
634
  {
635
635
  name: "update_asset",
636
636
  media: "write",
637
- description: "Change a file's alt text or tags. Documents that use the file without their own alt text show the new one.",
638
- input: import_zod.z.object({ id: assetId, alt: import_zod.z.string().optional(), tags: import_zod.z.array(import_zod.z.string()).optional() }),
639
- run: async (cms, actor, a) => assetOut(await cms.assets.update(actor, a.id, { alt: a.alt, tags: a.tags }))
637
+ description: "Change a file's alt text, tags or focal point. Documents that use the file without their own alt text show the new one.",
638
+ input: import_zod.z.object({
639
+ id: assetId,
640
+ alt: import_zod.z.string().optional(),
641
+ tags: import_zod.z.array(import_zod.z.string()).optional(),
642
+ focal: import_zod.z.object({ x: import_zod.z.number().min(0).max(1), y: import_zod.z.number().min(0).max(1) }).nullable().optional().describe("Images: the point that stays in view when the picture is cropped, from the left and from the top (0..1). null clears it.")
643
+ }),
644
+ run: async (cms, actor, a) => assetOut(await cms.assets.update(actor, a.id, { alt: a.alt, tags: a.tags, focal: a.focal }))
640
645
  },
641
646
  {
642
647
  name: "move_asset",
@@ -705,7 +710,7 @@ async function runTool(cms, actor, name, args = {}, opts = {}) {
705
710
  }
706
711
 
707
712
  // src/version.ts
708
- var VERSION = "0.10.1";
713
+ var VERSION = "0.11.0";
709
714
 
710
715
  // src/mcp.ts
711
716
  var ANONYMOUS_READ_TOOLS = ["list_collections", "search_documents", "read_for_answer", "list_documents", "get_document"];