iagenify 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4177,6 +4177,135 @@ function createServiceTools() {
4177
4177
  };
4178
4178
  }
4179
4179
 
4180
+ // src/resources/designTools.js
4181
+ var DESIGN_TOOL_NAMES = ["design_read", "design_apply", "design_render", "design_check", "design_template"];
4182
+ var fail5 = (message) => {
4183
+ throw Object.assign(new Error(message), { code: "tool_error" });
4184
+ };
4185
+ var clip3 = (value, max = 48e3) => String(value || "").length > max ? `${String(value).slice(0, max)}
4186
+ \u2026[truncated]` : String(value || "");
4187
+ var projectId = (value) => {
4188
+ const id = String(value || "").trim();
4189
+ if (!id) fail5('"projectId" is required. Use the design project currently open in the editor.');
4190
+ return id;
4191
+ };
4192
+ var parseOperations = (value) => {
4193
+ let operations = value;
4194
+ if (typeof value === "string") {
4195
+ try {
4196
+ operations = JSON.parse(value);
4197
+ } catch (error) {
4198
+ fail5(`"operations" is not valid JSON (${error.message}).`);
4199
+ }
4200
+ }
4201
+ if (!Array.isArray(operations) || operations.length < 1 || operations.length > 100) {
4202
+ fail5('"operations" must be a JSON array with 1 to 100 document operations.');
4203
+ }
4204
+ return operations;
4205
+ };
4206
+ function createDesignTools() {
4207
+ return {
4208
+ design_read: {
4209
+ category: "read",
4210
+ description: "Read the Design document of projectId. Optional node selects one subtree; otherwise return the page/frame tree, tokens, and node ids, names, types, sizes, layout and text. Call before making changes.",
4211
+ parameters: {
4212
+ projectId: { type: "string", required: true, description: "The design project id currently open in the user's editor" },
4213
+ node: { type: "string", description: "An existing node id from this document" }
4214
+ },
4215
+ async run({ projectId: id, node: node4 }, { api }) {
4216
+ const project = await api.design.projects.get(projectId(id));
4217
+ const doc = await project.open();
4218
+ const json = doc.toJSON();
4219
+ const describe = (nodeId) => {
4220
+ const item = json.nodes[nodeId];
4221
+ if (!item) return null;
4222
+ return {
4223
+ id: nodeId,
4224
+ type: item.type,
4225
+ name: item.name,
4226
+ size: item.size,
4227
+ position: item.position,
4228
+ text: item.text,
4229
+ style: item.style,
4230
+ layout: item.layout,
4231
+ children: (item.children || []).map(describe)
4232
+ };
4233
+ };
4234
+ if (node4) {
4235
+ const item = json.nodes[node4];
4236
+ if (!item) fail5(`Unknown design node id "${node4}".`);
4237
+ return { output: clip3(JSON.stringify(describe(node4))), summary: `Read ${item.name || node4}`, meta: { projectId: project.id, node: node4 } };
4238
+ }
4239
+ const pages = json.pages.map((page) => ({ id: page.id, name: page.name, frames: page.frames.map(describe) }));
4240
+ return { output: clip3(JSON.stringify({ pages, tokens: json.tokens || {}, version: project.version?.id || null })), summary: `Read ${project.label}`, meta: { projectId: project.id, pages: pages.length } };
4241
+ }
4242
+ },
4243
+ design_apply: {
4244
+ category: "write",
4245
+ description: "Apply an atomic, undoable batch to the saved Design document. operations is JSON text containing 1\u2013100 set/insert/move/remove operations. Use ids from design_read. The project is version-checked; the editor receives the exact operations and new version.",
4246
+ parameters: {
4247
+ projectId: { type: "string", required: true, description: "The design project id currently open in the user's editor" },
4248
+ operations: { type: "string", required: true, description: "JSON array of 1\u2013100 valid document operations" }
4249
+ },
4250
+ async run({ projectId: id, operations: raw }, { api }) {
4251
+ const operations = parseOperations(raw);
4252
+ const project = await api.design.projects.get(projectId(id));
4253
+ const doc = await project.open();
4254
+ const applied = doc.apply(operations, { source: "agent" });
4255
+ const saved = await doc.save();
4256
+ return {
4257
+ output: `Applied and saved ${applied.applied} design operation${applied.applied === 1 ? "" : "s"} to ${project.label}. The open editor will receive this exact batch.`,
4258
+ summary: `Updated ${project.label}`,
4259
+ meta: { projectId: project.id, version: saved.version, operations, created: applied.created }
4260
+ };
4261
+ }
4262
+ },
4263
+ design_render: {
4264
+ category: "read",
4265
+ description: "Render one frame of a saved Design project as PNG. The PNG is attached to your context so you can inspect it visually and correct the design.",
4266
+ parameters: {
4267
+ projectId: { type: "string", required: true, description: "The design project id currently open in the user's editor" },
4268
+ frame: { type: "string", description: "Frame id from design_read; omit to render the first frame" }
4269
+ },
4270
+ async run({ projectId: id, frame }, { api }) {
4271
+ const project = await api.design.projects.get(projectId(id));
4272
+ const result = await project.render({ frame });
4273
+ if (!result?.image?.data) fail5("The design preview returned no image.");
4274
+ return {
4275
+ output: `Rendered frame ${result.image.frame || frame || "first frame"} at ${result.image.width}\xD7${result.image.height}. Inspect the attached image before changing the design again.`,
4276
+ summary: "Rendered the design for visual review",
4277
+ meta: { projectId: project.id, frame: result.image.frame, width: result.image.width, height: result.image.height },
4278
+ attachments: [{ mime: result.image.mime || "image/png", data: result.image.data }]
4279
+ };
4280
+ }
4281
+ },
4282
+ design_check: {
4283
+ category: "read",
4284
+ description: "Run deterministic design checks on a saved project and report every issue with rule, severity, node and measured details.",
4285
+ parameters: { projectId: { type: "string", required: true, description: "The design project id currently open in the user's editor" } },
4286
+ async run({ projectId: id }, { api }) {
4287
+ const project = await api.design.projects.get(projectId(id));
4288
+ const doc = await project.open();
4289
+ const result = doc.check();
4290
+ return { output: clip3(JSON.stringify(result)), summary: `${result.issues.length} design checks reported`, meta: { projectId: project.id, issues: result.issues.length } };
4291
+ }
4292
+ },
4293
+ design_template: {
4294
+ category: "read",
4295
+ description: "List available Design templates, or read one template by id including its starting document.",
4296
+ parameters: { id: { type: "string", description: "Template id; omit to list templates" } },
4297
+ async run({ id }, { api }) {
4298
+ if (!id) {
4299
+ const templates2 = await api.design.templates.list({ type: "design" });
4300
+ return { output: clip3(JSON.stringify(templates2)), summary: `${templates2.length} design templates`, meta: { count: templates2.length } };
4301
+ }
4302
+ const template = await api.design.templates.get(id);
4303
+ return { output: clip3(JSON.stringify(template)), summary: `Read template ${id}`, meta: { template: id } };
4304
+ }
4305
+ }
4306
+ };
4307
+ }
4308
+
4180
4309
  // src/resources/workspaceTools.js
4181
4310
  var MAX_OUTPUT = 6e4;
4182
4311
  var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", ".next", "dist", "build", "__pycache__", ".venv"]);
@@ -4199,12 +4328,12 @@ var MEDIA_MIME = {
4199
4328
  };
4200
4329
  var EXT_FOR = { markdown: "md", text: "txt", jpeg: "jpg", base64: "txt" };
4201
4330
  var ATTACHMENT_MAX = 15 * 1024 * 1024;
4202
- var fail5 = (message) => {
4331
+ var fail6 = (message) => {
4203
4332
  throw new IaGenifyError(400, "tool_error", message);
4204
4333
  };
4205
4334
  var short = (text2 = "", max = 80) => String(text2).length > max ? `${String(text2).slice(0, max)}\u2026` : String(text2);
4206
4335
  var filled2 = (value) => typeof value === "string" && value.trim() !== "";
4207
- var clip3 = (text2, max = MAX_OUTPUT) => text2.length > max ? `${text2.slice(0, max)}
4336
+ var clip4 = (text2, max = MAX_OUTPUT) => text2.length > max ? `${text2.slice(0, max)}
4208
4337
  \u2026[truncated ${text2.length - max} characters]` : text2;
4209
4338
  var stamp = () => (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
4210
4339
  var isTextMime = (mime) => mime.startsWith("text/") || /json|xml|yaml|javascript|typescript/.test(mime);
@@ -4278,7 +4407,7 @@ async function backup(files, path) {
4278
4407
  }
4279
4408
  async function readText(files, path) {
4280
4409
  const file = await files.read(path);
4281
- if (typeof file.content !== "string") fail5(`"${path}" is not a text file.`);
4410
+ if (typeof file.content !== "string") fail6(`"${path}" is not a text file.`);
4282
4411
  return file.content;
4283
4412
  }
4284
4413
  var countOf = (text2, needle) => needle ? text2.split(needle).length - 1 : 0;
@@ -4336,11 +4465,11 @@ function storageArgs(args = {}) {
4336
4465
  try {
4337
4466
  parsed = JSON.parse(value);
4338
4467
  } catch (err) {
4339
- fail5(`"${name}" is not valid JSON (${err.message}). Send it as JSON text, e.g. ${shape === "array" ? "[{\u2026}]" : "{\u2026}"}.`);
4468
+ fail6(`"${name}" is not valid JSON (${err.message}). Send it as JSON text, e.g. ${shape === "array" ? "[{\u2026}]" : "{\u2026}"}.`);
4340
4469
  }
4341
4470
  }
4342
4471
  const isArray = Array.isArray(parsed);
4343
- if (shape === "array" ? !isArray : isArray || parsed === null || typeof parsed !== "object") fail5(`"${name}" must be a JSON ${shape}.`);
4472
+ if (shape === "array" ? !isArray : isArray || parsed === null || typeof parsed !== "object") fail6(`"${name}" must be a JSON ${shape}.`);
4344
4473
  return parsed;
4345
4474
  };
4346
4475
  return {
@@ -4353,25 +4482,25 @@ function storageArgs(args = {}) {
4353
4482
  documents: parse("documents", "array")
4354
4483
  };
4355
4484
  }
4356
- var requireText2 = (value, name) => typeof value === "string" && value.trim() ? value.trim() : fail5(`"${name}" is required for this action.`);
4485
+ var requireText2 = (value, name) => typeof value === "string" && value.trim() ? value.trim() : fail6(`"${name}" is required for this action.`);
4357
4486
  async function pickStorage(api, name, providers) {
4358
- if (!providers) fail5("Unknown action for this tool.");
4487
+ if (!providers) fail6("Unknown action for this tool.");
4359
4488
  const connected = (await api.storage.list()).filter((s) => s.type === "database" || s.type === "object");
4360
- if (!connected.length) fail5("No database or bucket is connected. Tell the user to connect one in Cloud.");
4489
+ if (!connected.length) fail6("No database or bucket is connected. Tell the user to connect one in Cloud.");
4361
4490
  const describe = (list) => list.map((s) => `"${s.label}" (${storageKindName(s, PROVIDER_NAMES)})`).join(", ");
4362
4491
  const byName = name ? connected.find((s) => s.id === name || s.label === name) || connected.find((s) => s.label.toLowerCase() === String(name).trim().toLowerCase()) : null;
4363
- if (name && !byName) fail5(`No connected storage named "${name}". Connected: ${describe(connected)}.`);
4492
+ if (name && !byName) fail6(`No connected storage named "${name}". Connected: ${describe(connected)}.`);
4364
4493
  const able = connected.filter((s) => providers.includes(engineOf(s)));
4365
4494
  const storage = byName || (able.length === 1 ? able[0] : null);
4366
- if (!storage) fail5(able.length ? `Several storages can do this: set "storage" to one of ${describe(able)}.` : `No connected storage supports this action (it needs ${providers.map((p) => PROVIDER_NAMES[p]).join(" or ")}). Connected: ${describe(connected)}.`);
4367
- if (!providers.includes(engineOf(storage))) fail5(`"${storage.label}" is ${storageKindName(storage, PROVIDER_NAMES)}; this action needs ${providers.map((p) => PROVIDER_NAMES[p]).join(" or ")}.`);
4495
+ if (!storage) fail6(able.length ? `Several storages can do this: set "storage" to one of ${describe(able)}.` : `No connected storage supports this action (it needs ${providers.map((p) => PROVIDER_NAMES[p]).join(" or ")}). Connected: ${describe(connected)}.`);
4496
+ if (!providers.includes(engineOf(storage))) fail6(`"${storage.label}" is ${storageKindName(storage, PROVIDER_NAMES)}; this action needs ${providers.map((p) => PROVIDER_NAMES[p]).join(" or ")}.`);
4368
4497
  return storage;
4369
4498
  }
4370
4499
  function sqlStatement(input) {
4371
4500
  const sql = String(input || "").trim().replace(/;\s*$/, "");
4372
- if (!sql) fail5('"sql" is required for this action.');
4501
+ if (!sql) fail6('"sql" is required for this action.');
4373
4502
  const bare = sql.replace(/--[^\n]*/g, " ").replace(/\/\*[\s\S]*?\*\//g, " ").replace(/'(?:[^']|'')*'/g, "''").replace(/"(?:[^"]|"")*"/g, '""');
4374
- if (bare.includes(";")) fail5("Send one SQL statement per call.");
4503
+ if (bare.includes(";")) fail6("Send one SQL statement per call.");
4375
4504
  const verb = (bare.match(/^\s*([a-z]+)/i) || [])[1]?.toUpperCase() || "";
4376
4505
  const writesInside = /\b(INSERT|UPDATE|DELETE|REPLACE|CREATE|ALTER|DROP)\b/i.test(bare);
4377
4506
  const read = ["SELECT", "EXPLAIN"].includes(verb) && !writesInside || verb === "WITH" && !writesInside || verb === "PRAGMA" && !bare.includes("=");
@@ -4386,28 +4515,28 @@ async function checkStorageWrite(rawArgs = {}, { api, mode } = {}) {
4386
4515
  const emptyFilter = !args.filter || !Object.keys(args.filter).length;
4387
4516
  let statement = null;
4388
4517
  if (["insert", "update", "delete"].includes(action)) requireText2(args.collection, "collection");
4389
- if (action === "insert" && (!Array.isArray(args.documents) || !args.documents.length || args.documents.length > 500)) fail5("insert needs documents: a list of 1 to 500 objects.");
4518
+ if (action === "insert" && (!Array.isArray(args.documents) || !args.documents.length || args.documents.length > 500)) fail6("insert needs documents: a list of 1 to 500 objects.");
4390
4519
  if (action === "update") {
4391
- if (emptyFilter && args.all !== true) fail5("update with an empty filter would change every document. Add a filter, or all: true if that is really what the user wants.");
4392
- if (!args.update || !Object.keys(args.update).length || !Object.keys(args.update).every((k) => k.startsWith("$"))) fail5('update needs operators such as {"$set":{"field":"value"}}, not a whole document.');
4520
+ if (emptyFilter && args.all !== true) fail6("update with an empty filter would change every document. Add a filter, or all: true if that is really what the user wants.");
4521
+ if (!args.update || !Object.keys(args.update).length || !Object.keys(args.update).every((k) => k.startsWith("$"))) fail6('update needs operators such as {"$set":{"field":"value"}}, not a whole document.');
4393
4522
  }
4394
- if (action === "delete" && emptyFilter && args.all !== true) fail5("delete with an empty filter would remove every document. Add a filter, or all: true if that is really what the user wants.");
4523
+ if (action === "delete" && emptyFilter && args.all !== true) fail6("delete with an empty filter would remove every document. Add a filter, or all: true if that is really what the user wants.");
4395
4524
  if (action === "sql") {
4396
4525
  statement = sqlStatement(args.sql);
4397
- if (statement.read) fail5('This statement only reads: use query_storage with action "sql".');
4398
- if (!statement.write) fail5(`write_storage runs INSERT, UPDATE, DELETE, REPLACE, CREATE, ALTER or DROP \u2014 not ${statement.verb || "this statement"}.`);
4399
- if (statement.drop && mode?.() !== "full") fail5("DROP is only allowed in Full access mode. Ask the user to switch mode if they really want to drop it.");
4400
- if (statement.unbounded && args.all !== true) fail5(`${statement.verb} without WHERE would touch every row. Add a WHERE clause, or all: true if that is really what the user wants.`);
4526
+ if (statement.read) fail6('This statement only reads: use query_storage with action "sql".');
4527
+ if (!statement.write) fail6(`write_storage runs INSERT, UPDATE, DELETE, REPLACE, CREATE, ALTER or DROP \u2014 not ${statement.verb || "this statement"}.`);
4528
+ if (statement.drop && mode?.() !== "full") fail6("DROP is only allowed in Full access mode. Ask the user to switch mode if they really want to drop it.");
4529
+ if (statement.unbounded && args.all !== true) fail6(`${statement.verb} without WHERE would touch every row. Add a WHERE clause, or all: true if that is really what the user wants.`);
4401
4530
  }
4402
4531
  if (action === "put") {
4403
4532
  requireText2(args.key, "key");
4404
- if (args.content == null && !args.path) fail5("put needs content (text) or path (a workspace file).");
4533
+ if (args.content == null && !args.path) fail6("put needs content (text) or path (a workspace file).");
4405
4534
  }
4406
4535
  if (action === "remove") requireText2(args.key, "key");
4407
4536
  if (action === "create_collection") requireText2(args.collection, "collection");
4408
4537
  if (action === "drop_collection") {
4409
4538
  requireText2(args.collection, "collection");
4410
- if (mode?.() !== "full") fail5("drop_collection removes a collection and every document in it: it is only allowed in Full access mode. Ask the user to switch mode if they really want to drop it.");
4539
+ if (mode?.() !== "full") fail6("drop_collection removes a collection and every document in it: it is only allowed in Full access mode. Ask the user to switch mode if they really want to drop it.");
4411
4540
  }
4412
4541
  return { db, statement, args };
4413
4542
  }
@@ -4421,7 +4550,7 @@ function createWorkspaceTools({ client }) {
4421
4550
  if (typeof text2 !== "string" && attachMime) {
4422
4551
  if (file.size > ATTACHMENT_MAX) {
4423
4552
  const advice = /^(audio|video)\//.test(attachMime) ? ` Convert it to a lighter form first \u2014 convert { path: "${file.path}", to: "mp3" } keeps the sound and drops the weight.` : " Ask the user for a smaller version.";
4424
- fail5(`"${file.path}" is ${(file.size / 1048576).toFixed(1)} MB; files over ${ATTACHMENT_MAX / 1048576} MB cannot be attached.${advice}`);
4553
+ fail6(`"${file.path}" is ${(file.size / 1048576).toFixed(1)} MB; files over ${ATTACHMENT_MAX / 1048576} MB cannot be attached.${advice}`);
4425
4554
  }
4426
4555
  const kind = attachMime.startsWith("audio/") ? "Listen to it" : attachMime.startsWith("video/") ? "Watch it" : "Read it";
4427
4556
  return {
@@ -4435,7 +4564,7 @@ function createWorkspaceTools({ client }) {
4435
4564
  if (CONVERTIBLE[ext]) {
4436
4565
  const converted = await convert.convert({ from: ext, to: CONVERTIBLE[ext], file: file.content });
4437
4566
  text2 = String(converted.content ?? converted.markdown ?? converted.text ?? "");
4438
- if (!text2) fail5(`Could not extract text from "${path}".`);
4567
+ if (!text2) fail6(`Could not extract text from "${path}".`);
4439
4568
  } else {
4440
4569
  return { output: `"${file.path}" is a binary file (${file.mimeType}, ${file.size} bytes) and has no text to read.`, summary: `${file.path} (binary)`, meta: { path: file.path } };
4441
4570
  }
@@ -4446,7 +4575,7 @@ function createWorkspaceTools({ client }) {
4446
4575
  const numbered = slice.map((l, i) => `${start + i} ${l.length > 2e3 ? `${l.slice(0, 2e3)}\u2026` : l}`).join("\n");
4447
4576
  const more = start - 1 + slice.length < lines.length ? `
4448
4577
  \u2026[${lines.length - (start - 1 + slice.length)} more lines \u2014 use offset]` : "";
4449
- return { output: clip3(numbered + more) || "(empty file)", summary: `${file.path} \xB7 ${lines.length} lines`, meta: { path: file.path, lines: lines.length } };
4578
+ return { output: clip4(numbered + more) || "(empty file)", summary: `${file.path} \xB7 ${lines.length} lines`, meta: { path: file.path, lines: lines.length } };
4450
4579
  }
4451
4580
  const search = new SearchResource(client);
4452
4581
  const fetchPage = new FetchResource(client);
@@ -4455,6 +4584,7 @@ function createWorkspaceTools({ client }) {
4455
4584
  ...createPlatformTools(),
4456
4585
  // P54 : les services de la plateforme — hébergement, courrier, domaines, compte, documents, second modèle.
4457
4586
  ...createServiceTools(),
4587
+ ...createDesignTools(),
4458
4588
  read: {
4459
4589
  category: "read",
4460
4590
  description: "Read any file in the workspace and SEE it: text and code as numbered lines (use offset/limit for long files); PDFs (including scanned ones), images, audio and video are attached so you read, hear and watch them directly, like a person would; DOCX, PPTX and XLSX are converted to text. This is the only tool you need to understand a document, a recording or a clip \u2014 never write scripts to parse file formats, and never look for a transcription tool: read the file.",
@@ -4466,8 +4596,8 @@ function createWorkspaceTools({ client }) {
4466
4596
  },
4467
4597
  async run({ path, paths, offset = 1, limit = 2e3 }, context) {
4468
4598
  const liste = Array.isArray(paths) && paths.length ? paths.map((p) => String(p)) : [String(path ?? "")];
4469
- if (!filled2(liste[0])) fail5('Give "path" (one file) or "paths" (several).');
4470
- if (liste.length > 20) fail5(`A single call reads at most 20 files (got ${liste.length}).`);
4599
+ if (!filled2(liste[0])) fail6('Give "path" (one file) or "paths" (several).');
4600
+ if (liste.length > 20) fail6(`A single call reads at most 20 files (got ${liste.length}).`);
4471
4601
  if (liste.length === 1) return lireFichier(liste[0], { offset, limit }, context);
4472
4602
  const lus = [];
4473
4603
  const pieces2 = [];
@@ -4483,7 +4613,7 @@ Error: ${err.message}`);
4483
4613
  }
4484
4614
  }
4485
4615
  return {
4486
- output: clip3(lus.join("\n\n"), 6e4),
4616
+ output: clip4(lus.join("\n\n"), 6e4),
4487
4617
  summary: `${liste.length} files`,
4488
4618
  meta: { paths: liste, attached: pieces2.length || void 0 },
4489
4619
  ...pieces2.length ? { attachments: pieces2 } : {}
@@ -4520,7 +4650,7 @@ Error: ${err.message}`);
4520
4650
  try {
4521
4651
  re = new RegExp(pattern, ignore_case ? "i" : "");
4522
4652
  } catch (err) {
4523
- fail5(`Invalid regular expression: ${err.message}`);
4653
+ fail6(`Invalid regular expression: ${err.message}`);
4524
4654
  }
4525
4655
  const only = glob ? globToRegExp(glob) : null;
4526
4656
  const hits = [];
@@ -4554,8 +4684,8 @@ Error: ${err.message}`);
4554
4684
  async run({ path, old_string, new_string, replace_all = false }, { files }) {
4555
4685
  const before = await readText(files, path);
4556
4686
  const count = countOf(before, old_string);
4557
- if (!count) fail5(`old_string was not found in "${path}". Read the file and copy the text exactly.`);
4558
- if (count > 1 && !replace_all) fail5(`old_string appears ${count} times in "${path}". Add surrounding lines to make it unique, or set replace_all.`);
4687
+ if (!count) fail6(`old_string was not found in "${path}". Read the file and copy the text exactly.`);
4688
+ if (count > 1 && !replace_all) fail6(`old_string appears ${count} times in "${path}". Add surrounding lines to make it unique, or set replace_all.`);
4559
4689
  const after = replace_all ? before.split(old_string).join(new_string) : before.replace(old_string, () => new_string);
4560
4690
  await backup(files, path);
4561
4691
  await files.write(path, after);
@@ -4579,8 +4709,8 @@ Error: ${err.message}`);
4579
4709
  const diffs = [];
4580
4710
  edits.forEach((e, i) => {
4581
4711
  const count = countOf(text2, e.old_string);
4582
- if (!count) fail5(`Edit ${i + 1}: old_string not found in "${path}". Nothing was changed.`);
4583
- if (count > 1 && !e.replace_all) fail5(`Edit ${i + 1}: old_string appears ${count} times. Nothing was changed.`);
4712
+ if (!count) fail6(`Edit ${i + 1}: old_string not found in "${path}". Nothing was changed.`);
4713
+ if (count > 1 && !e.replace_all) fail6(`Edit ${i + 1}: old_string appears ${count} times. Nothing was changed.`);
4584
4714
  diffs.push(diffOf(text2, e.old_string, e.new_string));
4585
4715
  text2 = e.replace_all ? text2.split(e.old_string).join(e.new_string) : text2.replace(e.old_string, () => e.new_string);
4586
4716
  });
@@ -4624,17 +4754,17 @@ Error: ${err.message}`);
4624
4754
  // Refusé avant toute permission, en disant comment faire.
4625
4755
  check({ command = "", commands, background } = {}, { shell, terminals } = {}) {
4626
4756
  if (commands !== void 0) {
4627
- if (!Array.isArray(commands) || !commands.length) fail5('"commands" must be a list of shell commands, e.g. ["npm ci", "npm run build"].');
4628
- if (commands.some((c) => typeof c !== "string" || !c.trim())) fail5('Every entry of "commands" must be a non-empty command.');
4629
- if (commands.length > 20) fail5(`A single call runs at most 20 commands (got ${commands.length}).`);
4630
- if (background === true) fail5("background: true runs ONE command in a terminal. Use command, not commands \u2014 or run the sequence without background.");
4757
+ if (!Array.isArray(commands) || !commands.length) fail6('"commands" must be a list of shell commands, e.g. ["npm ci", "npm run build"].');
4758
+ if (commands.some((c) => typeof c !== "string" || !c.trim())) fail6('Every entry of "commands" must be a non-empty command.');
4759
+ if (commands.length > 20) fail6(`A single call runs at most 20 commands (got ${commands.length}).`);
4760
+ if (background === true) fail6("background: true runs ONE command in a terminal. Use command, not commands \u2014 or run the sequence without background.");
4631
4761
  } else if (!filled2(command)) {
4632
- fail5('Give "command" (one command) or "commands" (several, run in order).');
4762
+ fail6('Give "command" (one command) or "commands" (several, run in order).');
4633
4763
  }
4634
4764
  if (background === true || !terminals) return;
4635
4765
  const text2 = [command, ...Array.isArray(commands) ? commands : []].filter(Boolean).join("\n");
4636
4766
  if (DETACHED.test(text2) && RUNTIME.test(text2)) {
4637
- fail5(`Do not detach servers or dev tools (Start-Process, Start-Job, nohup, setsid, a trailing &): they would run hidden, outside the user's terminals, where nobody can see or stop them. Run the command itself with background: true \u2014 e.g. bash { command: "cd my-app; npm run dev -- --port 5173", background: true } \u2014 then read it with terminal { action: "output" } and stop it with terminal { action: "kill" }.`);
4767
+ fail6(`Do not detach servers or dev tools (Start-Process, Start-Job, nohup, setsid, a trailing &): they would run hidden, outside the user's terminals, where nobody can see or stop them. Run the command itself with background: true \u2014 e.g. bash { command: "cd my-app; npm run dev -- --port 5173", background: true } \u2014 then read it with terminal { action: "output" } and stop it with terminal { action: "kill" }.`);
4638
4768
  }
4639
4769
  },
4640
4770
  async run({ command, commands, timeout_ms = 12e4, background = false, stop_on_error = true, port = null }, { root, signal, shell, terminals }) {
@@ -4643,7 +4773,7 @@ Error: ${err.message}`);
4643
4773
  const seule = liste[0];
4644
4774
  const auto = background !== true && Boolean(terminals) && liste.length === 1 && LONG_RUNNING.test(seule);
4645
4775
  if (background === true || auto) {
4646
- if (!terminals) fail5("Background commands need a terminal environment, and there are none here. Run the command without background.");
4776
+ if (!terminals) fail6("Background commands need a terminal environment, and there are none here. Run the command without background.");
4647
4777
  const note = auto ? "This command starts a server that never exits, so it runs in a terminal instead of blocking.\n" : "";
4648
4778
  const terminal = await terminals.create({ name: short(seule, 60), command: seule, by: "agent", ...port ? { port } : {} });
4649
4779
  const first = await settle(terminal, signal);
@@ -4652,9 +4782,9 @@ Error: ${err.message}`);
4652
4782
  const exited = first.status === "exited";
4653
4783
  const output = exited ? `Terminal ${terminal.id} (${seule}) exited with code ${first.exitCode} right away.
4654
4784
  --- output ---
4655
- ${clip3(text2, 2e4)}` : `Started terminal ${terminal.id} (${seule}). It keeps running after your answer; use terminal { action: "output", id: "${terminal.id}" } to check it and terminal { action: "kill" } to stop it.
4785
+ ${clip4(text2, 2e4)}` : `Started terminal ${terminal.id} (${seule}). It keeps running after your answer; use terminal { action: "output", id: "${terminal.id}" } to check it and terminal { action: "kill" } to stop it.
4656
4786
  --- first output ---
4657
- ${clip3(text2, 2e4) || "(nothing yet)"}`;
4787
+ ${clip4(text2, 2e4) || "(nothing yet)"}`;
4658
4788
  const adresse = terminal.url ? `
4659
4789
 
4660
4790
  Open it at: ${terminal.url}
@@ -4662,7 +4792,7 @@ If it does not answer, the server is listening on localhost instead of 0.0.0.0 \
4662
4792
  return {
4663
4793
  output: note + output + adresse,
4664
4794
  summary: `${seule.slice(0, 80)} \xB7 ${exited ? `exit ${first.exitCode}` : terminal.url || `terminal ${terminal.id}`}`,
4665
- meta: { command: seule, background: true, terminalId: terminal.id, status: first.status, exitCode: first.exitCode, stdout: clip3(text2, 4e3), url: terminal.url ?? null, port: terminal.port ?? null }
4795
+ meta: { command: seule, background: true, terminalId: terminal.id, status: first.status, exitCode: first.exitCode, stdout: clip4(text2, 4e3), url: terminal.url ?? null, port: terminal.port ?? null }
4666
4796
  };
4667
4797
  }
4668
4798
  const executer = async (cmd) => {
@@ -4714,9 +4844,9 @@ If it does not answer, the server is listening on localhost instead of 0.0.0.0 \
4714
4844
  if (liste.length === 1) {
4715
4845
  const r = await executer(seule);
4716
4846
  const output = [`exit code ${etat(r)}`, r.stdout && `--- stdout ---
4717
- ${clip3(r.stdout, 3e4)}`, r.stderr && `--- stderr ---
4718
- ${clip3(r.stderr, 3e4)}`].filter(Boolean).join("\n");
4719
- return { output, summary: `${seule.slice(0, 80)} \xB7 exit ${etat(r)}`, meta: { command: seule, exitCode: r.code, timedOut: r.timedOut, stdout: clip3(r.stdout, 4e3), stderr: clip3(r.stderr, 4e3) } };
4847
+ ${clip4(r.stdout, 3e4)}`, r.stderr && `--- stderr ---
4848
+ ${clip4(r.stderr, 3e4)}`].filter(Boolean).join("\n");
4849
+ return { output, summary: `${seule.slice(0, 80)} \xB7 exit ${etat(r)}`, meta: { command: seule, exitCode: r.code, timedOut: r.timedOut, stdout: clip4(r.stdout, 4e3), stderr: clip4(r.stderr, 4e3) } };
4720
4850
  }
4721
4851
  const faits = [];
4722
4852
  for (const cmd of liste) {
@@ -4729,9 +4859,9 @@ ${clip3(r.stderr, 3e4)}`].filter(Boolean).join("\n");
4729
4859
  const bloc = faits.map((r, i) => [
4730
4860
  `[${i + 1}/${liste.length}] ${r.cmd} \u2014 exit ${etat(r)}`,
4731
4861
  r.stdout && `--- stdout ---
4732
- ${clip3(r.stdout, part)}`,
4862
+ ${clip4(r.stdout, part)}`,
4733
4863
  r.stderr && `--- stderr ---
4734
- ${clip3(r.stderr, part)}`
4864
+ ${clip4(r.stderr, part)}`
4735
4865
  ].filter(Boolean).join("\n")).join("\n\n");
4736
4866
  const dernier = faits.at(-1);
4737
4867
  const rates = faits.filter((r) => r.timedOut || r.code !== 0).length;
@@ -4747,8 +4877,8 @@ Stopped at command ${faits.length} of ${liste.length}: the rest was not run.` :
4747
4877
  exitCode: dernier ? dernier.code : null,
4748
4878
  timedOut: Boolean(dernier?.timedOut),
4749
4879
  results: faits.map((r) => ({ command: r.cmd, exitCode: r.code, timedOut: r.timedOut })),
4750
- stdout: clip3(faits.map((r) => r.stdout).filter(Boolean).join("\n"), 4e3),
4751
- stderr: clip3(faits.map((r) => r.stderr).filter(Boolean).join("\n"), 4e3)
4880
+ stdout: clip4(faits.map((r) => r.stdout).filter(Boolean).join("\n"), 4e3),
4881
+ stderr: clip4(faits.map((r) => r.stderr).filter(Boolean).join("\n"), 4e3)
4752
4882
  }
4753
4883
  };
4754
4884
  }
@@ -4765,14 +4895,14 @@ Stopped at command ${faits.length} of ${liste.length}: the rest was not run.` :
4765
4895
  since: { type: "integer", description: "output: read from this position; 0 = everything kept" }
4766
4896
  },
4767
4897
  async run({ action, id, since }, { terminals }) {
4768
- if (!terminals) fail5("There are no terminals here: they only exist on a computer.");
4898
+ if (!terminals) fail6("There are no terminals here: they only exist on a computer.");
4769
4899
  if (action === "list") {
4770
4900
  const all = await terminals.list();
4771
4901
  if (!all.length) return { output: "No terminals are open.", summary: "No terminals", meta: { terminals: [] } };
4772
4902
  const lines = all.map((t) => `${t.id} \xB7 ${t.status}${t.status === "exited" ? ` (code ${t.exitCode ?? "stopped"})` : ""} \xB7 ${t.command || t.name} \xB7 cwd ${t.cwd || "."} \xB7 by ${t.by} \xB7 started ${t.startedAt}`);
4773
4903
  return { output: lines.join("\n"), summary: `${all.filter((t) => t.status === "running").length} running \xB7 ${all.length} terminals`, meta: { terminals: all } };
4774
4904
  }
4775
- if (!id) fail5(`"id" is required for ${action}. Use terminal { action: "list" } to find it.`);
4905
+ if (!id) fail6(`"id" is required for ${action}. Use terminal { action: "list" } to find it.`);
4776
4906
  const terminal = await terminals.get(id);
4777
4907
  if (action === "output") {
4778
4908
  const from = since != null ? Number(since) : terminal.agentCursor || 0;
@@ -4782,16 +4912,16 @@ Stopped at command ${faits.length} of ${liste.length}: the rest was not run.` :
4782
4912
  return {
4783
4913
  output: `${terminal.id} \xB7 ${out.status}${out.status === "exited" ? ` (code ${out.exitCode ?? "stopped"})` : ""}${out.truncated ? " \xB7 older output was dropped" : ""}
4784
4914
  --- output ---
4785
- ${clip3(text2, 3e4) || "(no new output)"}`,
4915
+ ${clip4(text2, 3e4) || "(no new output)"}`,
4786
4916
  summary: `${terminal.name} \xB7 ${out.status}`,
4787
- meta: { terminalId: terminal.id, status: out.status, exitCode: out.exitCode, stdout: clip3(text2, 4e3) }
4917
+ meta: { terminalId: terminal.id, status: out.status, exitCode: out.exitCode, stdout: clip4(text2, 4e3) }
4788
4918
  };
4789
4919
  }
4790
4920
  if (action === "kill") {
4791
4921
  const stopped = await terminal.kill();
4792
4922
  return { output: `Stopped terminal ${stopped.id} (${stopped.command || stopped.name}).`, summary: `Stopped ${stopped.name}`, meta: { terminalId: stopped.id, status: stopped.status } };
4793
4923
  }
4794
- fail5(`Unknown action "${action}": use list, output or kill.`);
4924
+ fail6(`Unknown action "${action}": use list, output or kill.`);
4795
4925
  }
4796
4926
  },
4797
4927
  ask_user: {
@@ -4864,7 +4994,7 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
4864
4994
  const shot = r.screenshot?.base64 ? { mime: r.screenshot.mimeType || "image/jpeg", data: r.screenshot.base64 } : null;
4865
4995
  if (screenshot === true && !shot) sections.push("--- screenshot ---\n(the page could not be captured as an image)");
4866
4996
  return {
4867
- output: clip3(sections.filter(Boolean).join("\n\n"), 3e4),
4997
+ output: clip4(sections.filter(Boolean).join("\n\n"), 3e4),
4868
4998
  summary: `${r.title || url}${shot ? " \xB7 seen" : ""}`,
4869
4999
  meta: { url: r.url || url, title: r.title || "", credits: r.creditsUsed ?? 1, ...shot ? { screenshot: true } : {}, ...wants.has("console") ? { consoleErrors: (r.console || []).filter((l) => l.level === "error").length } : {} },
4870
5000
  ...shot ? { attachments: [shot] } : {}
@@ -4883,12 +5013,12 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
4883
5013
  },
4884
5014
  async run({ path, url, to, save }, { files }) {
4885
5015
  const target = String(to || "").trim().toLowerCase();
4886
- if (!target) fail5('"to" is required: the format to convert into, e.g. "pdf".');
4887
- if (!filled2(path) && !filled2(url)) fail5('Give "path" (a workspace file) or "url".');
4888
- if (filled2(path) && filled2(url)) fail5('Give "path" or "url", not both.');
5016
+ if (!target) fail6('"to" is required: the format to convert into, e.g. "pdf".');
5017
+ if (!filled2(path) && !filled2(url)) fail6('Give "path" (a workspace file) or "url".');
5018
+ if (filled2(path) && filled2(url)) fail6('Give "path" or "url", not both.');
4889
5019
  const sourceName = filled2(path) ? String(path) : new URL(String(url)).pathname.split("/").filter(Boolean).pop() || "page";
4890
5020
  const from = sourceName.includes(".") ? sourceName.split(".").pop().toLowerCase() : "";
4891
- if (!from) fail5(`Cannot tell the format of "${sourceName}": the name has no extension.`);
5021
+ if (!from) fail6(`Cannot tell the format of "${sourceName}": the name has no extension.`);
4892
5022
  let result;
4893
5023
  if (filled2(path)) {
4894
5024
  const file = await files.read(path);
@@ -4897,7 +5027,7 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
4897
5027
  } else {
4898
5028
  result = await convert.convert({ from, to: target, url: String(url) });
4899
5029
  }
4900
- if (!result?.ok) fail5(result?.message || `Conversion ${from} \u2192 ${target} failed.`);
5030
+ if (!result?.ok) fail6(result?.message || `Conversion ${from} \u2192 ${target} failed.`);
4901
5031
  const data = result.content !== void 0 ? String(result.content) : Buffer.from(result.base64 || "", "base64");
4902
5032
  const ext = EXT_FOR[target] || target;
4903
5033
  const base2 = sourceName.replace(/\.[^.]+$/, "");
@@ -4978,7 +5108,7 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
4978
5108
  const usage = await api.cloud.usage();
4979
5109
  if (!args.storage) return { output: cloudUsageReport(usage), summary: "IaGenify Cloud \xB7 usage", meta: { action, storage: null } };
4980
5110
  const target2 = await pickStorage(api, args.storage, STORAGE_READS.usage);
4981
- if (!target2.service) fail5(`"${target2.label}" is a connected storage: its space is managed by its own provider. usage only reports IaGenify Cloud storages.`);
5111
+ if (!target2.service) fail6(`"${target2.label}" is a connected storage: its space is managed by its own provider. usage only reports IaGenify Cloud storages.`);
4982
5112
  return { output: cloudUsageReport(usage, target2), summary: `${target2.label} \xB7 usage`, meta: { storage: target2.label, provider: target2.provider, action } };
4983
5113
  }
4984
5114
  const db = await pickStorage(api, args.storage, STORAGE_READS[action]);
@@ -4986,7 +5116,7 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
4986
5116
  if (action === "overview") {
4987
5117
  const seen = await db.run({ action: "overview" });
4988
5118
  return {
4989
- output: clip3(overviewReport(db, seen), 3e4),
5119
+ output: clip4(overviewReport(db, seen), 3e4),
4990
5120
  summary: `${db.label} \xB7 overview`,
4991
5121
  meta: { storage: db.label, provider: db.provider, action, returned: (seen.collections || seen.tables || seen.folders || []).length }
4992
5122
  };
@@ -5002,13 +5132,13 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
5002
5132
  });
5003
5133
  } else if (action === "count") result = await db.run({ action: "count", collection: requireText2(args.collection, "collection"), filter: args.filter || {} });
5004
5134
  else if (action === "aggregate") {
5005
- if (!Array.isArray(args.pipeline) || !args.pipeline.length) fail5('aggregate needs a pipeline: a list of stages such as [{"$group":{"_id":"$model","total":{"$sum":"$credits"}}}].');
5006
- if (/"\$(out|merge)"/.test(JSON.stringify(args.pipeline))) fail5("aggregate is read-only: $out and $merge are not allowed.");
5135
+ if (!Array.isArray(args.pipeline) || !args.pipeline.length) fail6('aggregate needs a pipeline: a list of stages such as [{"$group":{"_id":"$model","total":{"$sum":"$credits"}}}].');
5136
+ if (/"\$(out|merge)"/.test(JSON.stringify(args.pipeline))) fail6("aggregate is read-only: $out and $merge are not allowed.");
5007
5137
  result = await db.run({ action: "aggregate", collection: requireText2(args.collection, "collection"), pipeline: args.pipeline });
5008
5138
  } else if (action === "tables") result = await db.run({ action: "tables" });
5009
5139
  else if (action === "sql") {
5010
5140
  const statement = sqlStatement(args.sql);
5011
- if (!statement.read) fail5(`query_storage only runs SELECT, WITH, PRAGMA or EXPLAIN. To change data (${statement.verb || "this statement"}), use write_storage with action "sql".`);
5141
+ if (!statement.read) fail6(`query_storage only runs SELECT, WITH, PRAGMA or EXPLAIN. To change data (${statement.verb || "this statement"}), use write_storage with action "sql".`);
5012
5142
  result = await db.run({ sql: statement.sql, params: Array.isArray(args.params) ? args.params : [] });
5013
5143
  } else if (action === "objects") result = await db.run({ action: "list", prefix: String(args.prefix || "") });
5014
5144
  else if (action === "object") result = await db.run({ action: "object", key: requireText2(args.key, "key") });
@@ -5023,7 +5153,7 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
5023
5153
  };
5024
5154
  }
5025
5155
  return {
5026
- output: clip3(results.map((r, i) => `[${i + 1}] ${r.source?.name || "document"} \xB7 ${r.score}
5156
+ output: clip4(results.map((r, i) => `[${i + 1}] ${r.source?.name || "document"} \xB7 ${r.score}
5027
5157
  ${r.text}`).join("\n\n"), 3e4),
5028
5158
  summary: `${db.label} \xB7 ${results.length} extract${results.length === 1 ? "" : "s"}`,
5029
5159
  meta: { storage: db.label, provider: db.provider, action, credits: found.creditsUsed ?? 1, returned: results.length, scanned: found.scanned ?? null, sources: [...new Set(results.map((r) => r.source?.name).filter(Boolean))] }
@@ -5077,7 +5207,7 @@ ${r.text}`).join("\n\n"), 3e4),
5077
5207
  else if (action === "drop_collection") result = await db.run({ action: "dropCollection", collection: args.collection.trim() });
5078
5208
  const target = args.collection || args.key || (args.sql ? String(args.sql).trim().split(/\s+/).slice(0, 3).join(" ") : "");
5079
5209
  return {
5080
- output: clip3(JSON.stringify(result, null, 1), 3e4),
5210
+ output: clip4(JSON.stringify(result, null, 1), 3e4),
5081
5211
  summary: `${db.label} \xB7 ${action}${target ? ` ${target}` : ""}`,
5082
5212
  meta: { storage: db.label, provider: db.provider, action, collection: args.collection || null, result }
5083
5213
  };
@@ -5148,28 +5278,28 @@ var MEDIA = {
5148
5278
  // produire doit se dire tout de suite, pas revenir en erreur du fournisseur une fois payé.
5149
5279
  verify: (a, model) => {
5150
5280
  if (OMNI_MODELS.includes(model)) {
5151
- if (a.audio === true) fail5(`"${model}" has no sound option. Use veo-3.1 for sound.`);
5281
+ if (a.audio === true) fail6(`"${model}" has no sound option. Use veo-3.1 for sound.`);
5152
5282
  if (a.duration !== void 0 && a.duration !== null && a.duration !== "") {
5153
5283
  const d = Number(a.duration);
5154
5284
  if (!Number.isFinite(d) || d < OMNI_SECONDS.min || d > OMNI_SECONDS.max) {
5155
- fail5(`"${model}" makes videos of ${OMNI_SECONDS.min} to ${OMNI_SECONDS.max} seconds (the provider's limit); you asked for ${a.duration}.`);
5285
+ fail6(`"${model}" makes videos of ${OMNI_SECONDS.min} to ${OMNI_SECONDS.max} seconds (the provider's limit); you asked for ${a.duration}.`);
5156
5286
  }
5157
5287
  }
5158
5288
  const permises = VIDEO_RESOLUTIONS[model] || [];
5159
5289
  if (filled2(a.resolution) && !permises.includes(a.resolution)) {
5160
- fail5(`"${model}" has no ${a.resolution}. It does ${permises.join(", ")}.`);
5290
+ fail6(`"${model}" has no ${a.resolution}. It does ${permises.join(", ")}.`);
5161
5291
  }
5162
5292
  return;
5163
5293
  }
5164
5294
  if (a.audio === true && !VIDEO_WITH_AUDIO.includes(model)) {
5165
- fail5(`"${model}" makes no sound. Only ${VIDEO_WITH_AUDIO.join(", ")} does \u2014 pass model: "veo-3.1", or leave audio out.`);
5295
+ fail6(`"${model}" makes no sound. Only ${VIDEO_WITH_AUDIO.join(", ")} does \u2014 pass model: "veo-3.1", or leave audio out.`);
5166
5296
  }
5167
5297
  if (a.duration !== void 0 && a.duration !== null && !VIDEO_DURATIONS.includes(Number(a.duration))) {
5168
- fail5(`duration must be ${VIDEO_DURATIONS.join(", ")} seconds; you asked for ${a.duration}.`);
5298
+ fail6(`duration must be ${VIDEO_DURATIONS.join(", ")} seconds; you asked for ${a.duration}.`);
5169
5299
  }
5170
5300
  const allowed = VIDEO_RESOLUTIONS[model] || [];
5171
5301
  if (filled2(a.resolution) && !allowed.includes(a.resolution)) {
5172
- fail5(`"${model}" has no ${a.resolution}. It does ${allowed.join(", ")} \u2014 change the resolution, or pick another model.`);
5302
+ fail6(`"${model}" has no ${a.resolution}. It does ${allowed.join(", ")} \u2014 change the resolution, or pick another model.`);
5173
5303
  }
5174
5304
  },
5175
5305
  // Omni : seulement ce qui a été demandé — sans durée, le modèle fait ses 10 s par défaut, et un
@@ -5258,7 +5388,7 @@ function createMediaTools({ client, media = {} }) {
5258
5388
  const args = fusionner(spec, media[MEDIA_KINDS[name]] || {}, brut);
5259
5389
  const model = filled2(args.model) ? args.model : spec.model;
5260
5390
  if (!spec.models.includes(model)) {
5261
- fail5(`${name} has no model "${args.model}". Available: ${spec.models.join(", ")}.`);
5391
+ fail6(`${name} has no model "${args.model}". Available: ${spec.models.join(", ")}.`);
5262
5392
  }
5263
5393
  if (spec.verify) spec.verify(args, model);
5264
5394
  },
@@ -5270,15 +5400,15 @@ function createMediaTools({ client, media = {} }) {
5270
5400
  if (spec.from && filled2(image)) {
5271
5401
  const source = await files.read(String(image));
5272
5402
  const mime = /^image\//.test(source.mimeType || "") ? source.mimeType : mimeOf(String(image));
5273
- if (!mime || !mime.startsWith("image/")) fail5(`"${source.path}" is not an image (${source.mimeType || "unknown type"}).`);
5274
- if (source.size > ATTACHMENT_MAX) fail5(`"${source.path}" is ${(source.size / 1048576).toFixed(1)} MB; the starting image must be under ${ATTACHMENT_MAX / 1048576} MB.`);
5403
+ if (!mime || !mime.startsWith("image/")) fail6(`"${source.path}" is not an image (${source.mimeType || "unknown type"}).`);
5404
+ if (source.size > ATTACHMENT_MAX) fail6(`"${source.path}" is ${(source.size / 1048576).toFixed(1)} MB; the starting image must be under ${ATTACHMENT_MAX / 1048576} MB.`);
5275
5405
  inputs.push({ type: "image", content: Buffer.from(source.content).toString("base64"), mime });
5276
5406
  }
5277
5407
  const session = await models.create({ model, settings: spec.settings(args, model), memory: false });
5278
5408
  try {
5279
5409
  const result = await session.generate({ inputs, outputs: [{ type: spec.output }] });
5280
5410
  const output = result.outputs?.find((o) => o.content);
5281
- if (!output) fail5(`The ${spec.type} model returned nothing.`);
5411
+ if (!output) fail6(`The ${spec.type} model returned nothing.`);
5282
5412
  const ext = output.mime?.split("/")[1]?.split(";")[0]?.replace("mpeg", "mp3") || spec.ext;
5283
5413
  const target = path || `Agent/${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}/${Date.now()}.${ext}`;
5284
5414
  const item = await files.write(target, Buffer.from(output.content, "base64"));
@@ -5295,10 +5425,10 @@ function createMediaTools({ client, media = {} }) {
5295
5425
  }
5296
5426
  }]));
5297
5427
  }
5298
- var WORKSPACE_TOOL_NAMES = ["read", "list", "glob", "grep", "write", "edit", "multi_edit", "move", "delete", "bash", "terminal", "todo_write", "ask_user", "search", "fetch", "convert", "account", "query_storage", "write_storage", "memory", "recall", ...PLATFORM_TOOL_NAMES, ...SERVICE_TOOL_NAMES, ...Object.keys(MEDIA)];
5428
+ var WORKSPACE_TOOL_NAMES = ["read", "list", "glob", "grep", "write", "edit", "multi_edit", "move", "delete", "bash", "terminal", "todo_write", "ask_user", "search", "fetch", "convert", "account", "query_storage", "write_storage", "memory", "recall", ...PLATFORM_TOOL_NAMES, ...SERVICE_TOOL_NAMES, ...DESIGN_TOOL_NAMES, ...Object.keys(MEDIA)];
5299
5429
 
5300
5430
  // src/resources/prompt.js
5301
- var fail6 = (code, message) => new IaGenifyError(400, code, message);
5431
+ var fail7 = (code, message) => new IaGenifyError(400, code, message);
5302
5432
  var PROMPT_OPTIONS = {
5303
5433
  model: "text",
5304
5434
  mode: ["ask", "auto", "plan", "full"],
@@ -5339,26 +5469,26 @@ function parsePrompt(input, library = {}) {
5339
5469
  if (!flag) break;
5340
5470
  const key = flag[1].toLowerCase();
5341
5471
  const kind = PROMPT_OPTIONS[key];
5342
- if (!kind) throw fail6("unknown_option", `Unknown option --${key}. Options: ${Object.keys(PROMPT_OPTIONS).map((k) => `--${k}`).join(" ")}. Write \\-- to start a message with "--".`);
5472
+ if (!kind) throw fail7("unknown_option", `Unknown option --${key}. Options: ${Object.keys(PROMPT_OPTIONS).map((k) => `--${k}`).join(" ")}. Write \\-- to start a message with "--".`);
5343
5473
  rest = rest.slice(flag[0].length);
5344
5474
  if (kind === "flag") {
5345
5475
  if (key === "no-memory") options.memory = false;
5346
5476
  continue;
5347
5477
  }
5348
5478
  const found = rest.match(/^(?:=|[ \t]+)("([^"]*)"|'([^']*)'|\S+)/);
5349
- if (!found) throw fail6("option_value_required", `--${key} needs a value.`);
5479
+ if (!found) throw fail7("option_value_required", `--${key} needs a value.`);
5350
5480
  const value = found[2] ?? found[3] ?? found[1];
5351
5481
  rest = rest.slice(found[0].length);
5352
5482
  if (key === "mode") {
5353
- if (!kind.includes(value)) throw fail6("invalid_option", `--mode must be one of ${kind.join(", ")}.`);
5483
+ if (!kind.includes(value)) throw fail7("invalid_option", `--mode must be one of ${kind.join(", ")}.`);
5354
5484
  options.mode = value;
5355
5485
  } else if (key === "budget") {
5356
5486
  if (value === "none") options.budget = null;
5357
5487
  else if (Number(value) > 0) options.budget = Math.round(Number(value));
5358
- else throw fail6("invalid_option", "--budget takes a number of credits, or none.");
5488
+ else throw fail7("invalid_option", "--budget takes a number of credits, or none.");
5359
5489
  } else if (key === "context") {
5360
5490
  const tokens = parseTokenCount(value);
5361
- if (!tokens) throw fail6("invalid_option", "--context takes a number of tokens: 200k, 400k, 1M.");
5491
+ if (!tokens) throw fail7("invalid_option", "--context takes a number of tokens: 200k, 400k, 1M.");
5362
5492
  options.contextTokens = tokens;
5363
5493
  } else {
5364
5494
  options[key] = value;
@@ -5399,7 +5529,7 @@ function parsePrompt(input, library = {}) {
5399
5529
  }
5400
5530
 
5401
5531
  // src/resources/library.js
5402
- var fail7 = (status, code, message) => new IaGenifyError(status, code, message);
5532
+ var fail8 = (status, code, message) => new IaGenifyError(status, code, message);
5403
5533
  var NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
5404
5534
  var MAX_CONTENT = 1e5;
5405
5535
  var CLAUDE_TOOLS = { ls: "list", websearch: "search", webfetch: "fetch", multiedit: "multi_edit", todowrite: "todo_write" };
@@ -5481,13 +5611,13 @@ var LocalLibrary = class {
5481
5611
  }
5482
5612
  async _ready() {
5483
5613
  if (typeof process === "undefined" || !process.versions?.node) {
5484
- throw fail7(400, "local_files_require_node", "A computer's skills and subagents live on its disk: that source is only available from Node.js. The account's own are available everywhere.");
5614
+ throw fail8(400, "local_files_require_node", "A computer's skills and subagents live on its disk: that source is only available from Node.js. The account's own are available everywhere.");
5485
5615
  }
5486
5616
  if (this.storage && this.storage.type !== "filesystem") {
5487
- throw fail7(400, "storage_not_local", `\xAB ${this.storage.label} \xBB n'est pas un stockage ordinateur : ses ${this.kind} ne sont pas sur un disque.`);
5617
+ throw fail8(400, "storage_not_local", `\xAB ${this.storage.label} \xBB n'est pas un stockage ordinateur : ses ${this.kind} ne sont pas sur un disque.`);
5488
5618
  }
5489
5619
  if (this.storage?.machineId && this.storage.machineId !== await getMachineId()) {
5490
- throw fail7(409, "storage_not_on_this_machine", `\xAB ${this.storage.label} \xBB belongs to another computer: its ${this.kind} stay there.`);
5620
+ throw fail8(409, "storage_not_on_this_machine", `\xAB ${this.storage.label} \xBB belongs to another computer: its ${this.kind} stay there.`);
5491
5621
  }
5492
5622
  const { fs, path, os } = await node3();
5493
5623
  const base2 = this.root || path.join(os.homedir(), ".iagenify");
@@ -5500,7 +5630,7 @@ var LocalLibrary = class {
5500
5630
  }
5501
5631
  _checkName(name) {
5502
5632
  if (typeof name !== "string" || !NAME.test(name)) {
5503
- throw fail7(400, "invalid_name", `A ${this.spec.label} name uses lowercase letters, digits and dashes (e.g. "legal-review"), 64 characters at most.`);
5633
+ throw fail8(400, "invalid_name", `A ${this.spec.label} name uses lowercase letters, digits and dashes (e.g. "legal-review"), 64 characters at most.`);
5504
5634
  }
5505
5635
  }
5506
5636
  /** Un élément lu sur disque : { name, description, …, content, builtIn: false }. */
@@ -5544,7 +5674,7 @@ var LocalLibrary = class {
5544
5674
  try {
5545
5675
  text2 = await fs.readFile(file, "utf8");
5546
5676
  } catch (err) {
5547
- if (err.code === "ENOENT") throw fail7(404, `${this.spec.label}_not_found`, `No ${this.spec.label} named "${name}".`);
5677
+ if (err.code === "ENOENT") throw fail8(404, `${this.spec.label}_not_found`, `No ${this.spec.label} named "${name}".`);
5548
5678
  throw err;
5549
5679
  }
5550
5680
  if (this.kind !== "skills") return this._fromFile(name, text2);
@@ -5568,10 +5698,10 @@ var LocalLibrary = class {
5568
5698
  async save(item = {}) {
5569
5699
  const { name, description, content } = item;
5570
5700
  this._checkName(name);
5571
- if (this.spec.builtIns[name]) throw fail7(409, "name_reserved", `"${name}" is a built-in ${this.spec.label}; choose another name.`);
5572
- if (typeof description !== "string" || !description.trim()) throw fail7(400, "description_required", `A ${this.spec.label} needs a description: it is how the agent knows when to use it.`);
5573
- if (typeof content !== "string" || !content.trim()) throw fail7(400, "content_required", `A ${this.spec.label} needs instructions (content).`);
5574
- if (content.length > MAX_CONTENT) throw fail7(400, "content_too_long", `Instructions are limited to ${MAX_CONTENT.toLocaleString("en")} characters.`);
5701
+ if (this.spec.builtIns[name]) throw fail8(409, "name_reserved", `"${name}" is a built-in ${this.spec.label}; choose another name.`);
5702
+ if (typeof description !== "string" || !description.trim()) throw fail8(400, "description_required", `A ${this.spec.label} needs a description: it is how the agent knows when to use it.`);
5703
+ if (typeof content !== "string" || !content.trim()) throw fail8(400, "content_required", `A ${this.spec.label} needs instructions (content).`);
5704
+ if (content.length > MAX_CONTENT) throw fail8(400, "content_too_long", `Instructions are limited to ${MAX_CONTENT.toLocaleString("en")} characters.`);
5575
5705
  const data = { name, description: description.trim().replace(/\s+/g, " ") };
5576
5706
  if (this.kind === "subagents") {
5577
5707
  const tools = normalizeTools(item.tools);
@@ -5587,13 +5717,13 @@ var LocalLibrary = class {
5587
5717
  /** Met l'élément à la corbeille (~/.iagenify/.trash/<horodatage>/…), d'où on peut le récupérer. */
5588
5718
  async remove(name) {
5589
5719
  this._checkName(name);
5590
- if (this.spec.builtIns[name]) throw fail7(400, "builtin_item", `"${name}" is built in and cannot be removed.`);
5720
+ if (this.spec.builtIns[name]) throw fail8(400, "builtin_item", `"${name}" is built in and cannot be removed.`);
5591
5721
  const { fs, path, base: base2, dir } = await this._ready();
5592
5722
  const source = this.kind === "skills" ? path.join(dir, name) : this._file(path, dir, name);
5593
5723
  try {
5594
5724
  await fs.access(source);
5595
5725
  } catch {
5596
- throw fail7(404, `${this.spec.label}_not_found`, `No ${this.spec.label} named "${name}".`);
5726
+ throw fail8(404, `${this.spec.label}_not_found`, `No ${this.spec.label} named "${name}".`);
5597
5727
  }
5598
5728
  const target = path.join(base2, ".trash", (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-"), this.spec.folder, path.basename(source));
5599
5729
  await fs.mkdir(path.dirname(target), { recursive: true });
@@ -5602,15 +5732,15 @@ var LocalLibrary = class {
5602
5732
  }
5603
5733
  /** Skills seulement : un fichier du skill (modèle, référence…), en texte. */
5604
5734
  async readFile(name, file) {
5605
- if (this.kind !== "skills") throw fail7(400, "not_a_skill", "Only skills have files.");
5735
+ if (this.kind !== "skills") throw fail8(400, "not_a_skill", "Only skills have files.");
5606
5736
  const skill = await this.get(name);
5607
5737
  const { fs, path } = await node3();
5608
5738
  const full = path.resolve(skill.folder, String(file || "").replace(/\\/g, "/"));
5609
- if (!full.startsWith(skill.folder + path.sep)) throw fail7(400, "invalid_path", `"${file}" is outside the skill folder.`);
5739
+ if (!full.startsWith(skill.folder + path.sep)) throw fail8(400, "invalid_path", `"${file}" is outside the skill folder.`);
5610
5740
  try {
5611
5741
  return { name: path.basename(full), path: path.relative(skill.folder, full).split(path.sep).join("/"), content: await fs.readFile(full, "utf8") };
5612
5742
  } catch (err) {
5613
- if (err.code === "ENOENT" || err.code === "EISDIR") throw fail7(404, "path_not_found", `The skill "${name}" has no file "${file}". Files: ${skill.files.join(", ") || "none"}.`);
5743
+ if (err.code === "ENOENT" || err.code === "EISDIR") throw fail8(404, "path_not_found", `The skill "${name}" has no file "${file}". Files: ${skill.files.join(", ") || "none"}.`);
5614
5744
  throw err;
5615
5745
  }
5616
5746
  }
@@ -5685,13 +5815,13 @@ var AgentLibrary = class {
5685
5815
  if (err.status !== 404 || !this.computer) throw err;
5686
5816
  const onDisk = await this.computer.get(name).catch(() => null);
5687
5817
  if (!onDisk) throw err;
5688
- throw fail7(409, "item_on_computer", `\xAB ${name} \xBB est un fichier de cet ordinateur (~/.iagenify/${this.spec.folder}) : supprimez-le sur le disque.`);
5818
+ throw fail8(409, "item_on_computer", `\xAB ${name} \xBB est un fichier de cet ordinateur (~/.iagenify/${this.spec.folder}) : supprimez-le sur le disque.`);
5689
5819
  }
5690
5820
  }
5691
5821
  /** Skills seulement : un fichier annexe. Ceux du compte n'en ont pas — le contenu est le document. */
5692
5822
  async readFile(name, file) {
5693
- if (this.kind !== "skills") throw fail7(400, "not_a_skill", "Only skills have files.");
5694
- if (!this.computer) throw fail7(404, "path_not_found", `\xAB ${name} \xBB n'a pas de fichiers : les skills du compte sont un seul document.`);
5823
+ if (this.kind !== "skills") throw fail8(400, "not_a_skill", "Only skills have files.");
5824
+ if (!this.computer) throw fail8(404, "path_not_found", `\xAB ${name} \xBB n'a pas de fichiers : les skills du compte sont un seul document.`);
5695
5825
  return this.computer.readFile(name, file);
5696
5826
  }
5697
5827
  };
@@ -5707,11 +5837,11 @@ var MAX_OUTPUT2 = 6e4;
5707
5837
  var CALL_TIMEOUT_MS = 6e4;
5708
5838
  var LIST_TIMEOUT_MS = 3e4;
5709
5839
  var MAX_PAGES = 20;
5710
- var fail8 = (status, code, message) => new IaGenifyError(status, code, message);
5840
+ var fail9 = (status, code, message) => new IaGenifyError(status, code, message);
5711
5841
  var CODE_VERSION_NON_SUPPORTEE = -32022;
5712
5842
  var estErreurModerne = (code) => typeof code === "number" && code <= -32020 && code >= -32099;
5713
5843
  var REPLI_ANCIENNE_POIGNEE = /* @__PURE__ */ new Set(["mcp_error", "mcp_http_error", "mcp_bad_response"]);
5714
- var clip4 = (text2, max = MAX_OUTPUT2) => text2.length > max ? `${text2.slice(0, max)}
5844
+ var clip5 = (text2, max = MAX_OUTPUT2) => text2.length > max ? `${text2.slice(0, max)}
5715
5845
  \u2026[truncated ${text2.length - max} characters]` : text2;
5716
5846
  var SCHEMA_TYPES = /* @__PURE__ */ new Set(["string", "number", "integer", "boolean", "array", "object"]);
5717
5847
  var SCHEMA_KEYS = /* @__PURE__ */ new Set(["type", "description", "properties", "required", "items", "enum", "nullable"]);
@@ -5768,7 +5898,7 @@ function cleanToken(value) {
5768
5898
  token = token.replace(/^authorization\s*:\s*/i, "").replace(/^bearer\b\s*/i, "").replace(/^token\s*=\s*/i, "").trim().replace(quotes, "").trim();
5769
5899
  if (!token) return null;
5770
5900
  if (/\s/.test(token)) {
5771
- throw fail8(400, "mcp_token_malformed", "Ce jeton contient une espace : collez le jeton seul, sans \xAB Bearer \xBB, sans guillemets et sans retour \xE0 la ligne.");
5901
+ throw fail9(400, "mcp_token_malformed", "Ce jeton contient une espace : collez le jeton seul, sans \xAB Bearer \xBB, sans guillemets et sans retour \xE0 la ligne.");
5772
5902
  }
5773
5903
  return token;
5774
5904
  }
@@ -5844,7 +5974,7 @@ function mirroredParams(schema, args) {
5844
5974
  }
5845
5975
  var McpClient = class {
5846
5976
  constructor({ url, token = null, name = "mcp", fetchImpl = null } = {}) {
5847
- if (!url) throw fail8(400, "url_required", "An MCP server needs its address.");
5977
+ if (!url) throw fail9(400, "url_required", "An MCP server needs its address.");
5848
5978
  this.url = String(url);
5849
5979
  this.token = cleanToken(token);
5850
5980
  this.name = name;
@@ -5906,8 +6036,8 @@ var McpClient = class {
5906
6036
  redirect: "manual"
5907
6037
  });
5908
6038
  } catch (err) {
5909
- if (controller.signal.aborted) throw fail8(504, "mcp_timeout", `\xAB ${this.name} \xBB n'a pas r\xE9pondu en ${Math.round(timeout / 1e3)} s.`);
5910
- throw fail8(502, "mcp_unreachable", `\xAB ${this.name} \xBB est injoignable : ${err.message}`);
6039
+ if (controller.signal.aborted) throw fail9(504, "mcp_timeout", `\xAB ${this.name} \xBB n'a pas r\xE9pondu en ${Math.round(timeout / 1e3)} s.`);
6040
+ throw fail9(502, "mcp_unreachable", `\xAB ${this.name} \xBB est injoignable : ${err.message}`);
5911
6041
  } finally {
5912
6042
  clearTimeout(timer);
5913
6043
  signal?.removeEventListener?.("abort", abort);
@@ -5916,17 +6046,17 @@ var McpClient = class {
5916
6046
  const detail = this._detail(brut);
5917
6047
  if (response.status === 401 || response.status === 403) {
5918
6048
  if (!this.token) {
5919
- throw fail8(401, "mcp_token_required", `\xAB ${this.name} \xBB demande un jeton : ce serveur ne r\xE9pond pas sans authentification.${detail}`);
6049
+ throw fail9(401, "mcp_token_required", `\xAB ${this.name} \xBB demande un jeton : ce serveur ne r\xE9pond pas sans authentification.${detail}`);
5920
6050
  }
5921
- throw fail8(401, "mcp_unauthorized", `\xAB ${this.name} \xBB refuse le jeton (${response.status}). V\xE9rifiez-le, ou recr\xE9ez-en un.${detail}`);
6051
+ throw fail9(401, "mcp_unauthorized", `\xAB ${this.name} \xBB refuse le jeton (${response.status}). V\xE9rifiez-le, ou recr\xE9ez-en un.${detail}`);
5922
6052
  }
5923
6053
  if (response.status >= 300 && response.status < 400) {
5924
- throw fail8(502, "mcp_redirect", `\xAB ${this.name} \xBB redirige vers une autre adresse : reconnectez-le avec l'adresse d\xE9finitive.`);
6054
+ throw fail9(502, "mcp_redirect", `\xAB ${this.name} \xBB redirige vers une autre adresse : reconnectez-le avec l'adresse d\xE9finitive.`);
5925
6055
  }
5926
- if (!response.ok) throw this._rpcError(fail8(502, "mcp_http_error", `\xAB ${this.name} \xBB a r\xE9pondu ${response.status}.${detail}`), brut);
6056
+ if (!response.ok) throw this._rpcError(fail9(502, "mcp_http_error", `\xAB ${this.name} \xBB a r\xE9pondu ${response.status}.${detail}`), brut);
5927
6057
  const message = await this._readMessage(response, id);
5928
6058
  if (message?.error) {
5929
- const err = fail8(502, "mcp_error", `\xAB ${this.name} \xBB refuse : ${String(message.error.message || message.error.code || "erreur").slice(0, 500)}`);
6059
+ const err = fail9(502, "mcp_error", `\xAB ${this.name} \xBB refuse : ${String(message.error.message || message.error.code || "erreur").slice(0, 500)}`);
5930
6060
  err.rpc = { code: message.error.code, data: message.error.data };
5931
6061
  throw err;
5932
6062
  }
@@ -5956,12 +6086,12 @@ var McpClient = class {
5956
6086
  /** La réponse, qu'elle arrive en JSON ou en flux d'événements (`text/event-stream`). */
5957
6087
  async _readMessage(response, id) {
5958
6088
  const type = String(response.headers.get("content-type") || "");
5959
- const body = clip4(await response.text(), 2e6);
6089
+ const body = clip5(await response.text(), 2e6);
5960
6090
  if (!type.includes("text/event-stream")) {
5961
6091
  try {
5962
6092
  return JSON.parse(body);
5963
6093
  } catch {
5964
- throw fail8(502, "mcp_bad_response", `\xAB ${this.name} \xBB n'a pas r\xE9pondu en JSON.`);
6094
+ throw fail9(502, "mcp_bad_response", `\xAB ${this.name} \xBB n'a pas r\xE9pondu en JSON.`);
5965
6095
  }
5966
6096
  }
5967
6097
  let last = null;
@@ -5976,7 +6106,7 @@ var McpClient = class {
5976
6106
  }
5977
6107
  }
5978
6108
  if (last) return last;
5979
- throw fail8(502, "mcp_bad_response", `\xAB ${this.name} \xBB n'a renvoy\xE9 aucune r\xE9ponse exploitable.`);
6109
+ throw fail9(502, "mcp_bad_response", `\xAB ${this.name} \xBB n'a renvoy\xE9 aucune r\xE9ponse exploitable.`);
5980
6110
  }
5981
6111
  /**
5982
6112
  * La poignée de main, dans les deux révisions. Elle dit quelle version le serveur a acceptée.
@@ -5998,7 +6128,7 @@ var McpClient = class {
5998
6128
  const propose = err.rpc?.data?.supportedVersions || err.rpc?.data?.supported;
5999
6129
  const version = negotiateVersion(propose);
6000
6130
  if (!version) {
6001
- throw fail8(
6131
+ throw fail9(
6002
6132
  502,
6003
6133
  "mcp_protocol_unsupported",
6004
6134
  `\xAB ${this.name} \xBB ne parle aucune r\xE9vision que ce client conna\xEEt (il propose ${[].concat(propose || []).join(", ") || "rien"}).`
@@ -6029,7 +6159,7 @@ var McpClient = class {
6029
6159
  const found = await this._rpc("server/discover", {}, { signal });
6030
6160
  const version = negotiateVersion(found.supportedVersions);
6031
6161
  if (found.supportedVersions && !version) {
6032
- throw fail8(
6162
+ throw fail9(
6033
6163
  502,
6034
6164
  "mcp_protocol_unsupported",
6035
6165
  `\xAB ${this.name} \xBB ne parle aucune r\xE9vision que ce client conna\xEEt (il propose ${[].concat(found.supportedVersions).join(", ")}).`
@@ -6081,7 +6211,7 @@ var McpClient = class {
6081
6211
  return part?.text ? String(part.text) : "";
6082
6212
  }).filter(Boolean).join("\n");
6083
6213
  const output = text2 || (result.structuredContent ? JSON.stringify(result.structuredContent) : "(aucun contenu)");
6084
- return { output: clip4(output), isError: Boolean(result.isError) };
6214
+ return { output: clip5(output), isError: Boolean(result.isError) };
6085
6215
  }
6086
6216
  };
6087
6217
  var McpResource = class {
@@ -6491,6 +6621,7 @@ var TOOL_FAMILIES = [
6491
6621
  ["Storages", ["query_storage", "write_storage"]],
6492
6622
  ["The account", ["account", "cloud"]],
6493
6623
  ["Put online and communicate", ["deploy", "domain", "mail", "send_mail"]],
6624
+ ["Design", ["design_read", "design_apply", "design_render", "design_check", "design_template"]],
6494
6625
  ["The platform itself", ["iagenify_docs", "workflow", "mcp"]],
6495
6626
  ["Ask another model", ["generate"]],
6496
6627
  ["This conversation", ["todo_write", "ask_user", "memory", "recall", "skill", "task"]]
@@ -6670,9 +6801,9 @@ var SUBAGENT_MAX_STEPS = 40;
6670
6801
  var MAX_SKILL_OUTPUT = 6e4;
6671
6802
  var withoutAttachments = (messages) => messages.map(({ attachments, images, ...m }) => attachments?.length || images?.length ? { ...m, content: `${m.content || ""} [${(attachments || images).length} file(s) attached]` } : m);
6672
6803
  var estimateTokens = (messages) => Math.ceil(JSON.stringify(withoutAttachments(messages)).length / 4);
6673
- var clip5 = (text2, max) => text2.length > max ? `${text2.slice(0, max)}
6804
+ var clip6 = (text2, max) => text2.length > max ? `${text2.slice(0, max)}
6674
6805
  \u2026[truncated ${text2.length - max} characters]` : text2;
6675
- var fail9 = (message) => {
6806
+ var fail10 = (message) => {
6676
6807
  throw new IaGenifyError(400, "tool_error", message);
6677
6808
  };
6678
6809
  var KEEP_ATTACHMENTS_FOR = 6;
@@ -7023,11 +7154,11 @@ var LocalAgent = class _LocalAgent {
7023
7154
  const notes = await this.api.memory.list();
7024
7155
  return { output: notes.length ? notes.map((n) => `- ${n.name}: ${n.description || n.content.slice(0, 80)}`).join("\n") : "(no memory yet)", summary: `${notes.length} notes` };
7025
7156
  }
7026
- if (!name) fail9("memory needs a name.");
7157
+ if (!name) fail10("memory needs a name.");
7027
7158
  if (action === "read") {
7028
7159
  const notes = await this.api.memory.list();
7029
7160
  const note = notes.find((n) => n.name === name);
7030
- if (!note) fail9(`No memory called "${name}". Listed names: ${notes.map((n) => n.name).join(", ") || "none"}.`);
7161
+ if (!note) fail10(`No memory called "${name}". Listed names: ${notes.map((n) => n.name).join(", ") || "none"}.`);
7031
7162
  return { output: `# ${note.name}
7032
7163
  ${note.description}
7033
7164
 
@@ -7038,7 +7169,7 @@ ${note.content}`, summary: note.name, meta: { memory: note.name } };
7038
7169
  this.memories = this.memories.filter((n) => n.name !== name);
7039
7170
  return { output: `Memory "${name}" deleted.`, summary: name, meta: { memory: name, deleted: true } };
7040
7171
  }
7041
- if (!content.trim()) fail9("memory save needs content.");
7172
+ if (!content.trim()) fail10("memory save needs content.");
7042
7173
  const saved = await this.api.memory.save({ name, description, content, type, source: "agent", ...this.memory ? { sessionId: this.id } : {} });
7043
7174
  this.memories = [saved, ...this.memories.filter((n) => n.name !== saved.name)];
7044
7175
  return { output: `Remembered as "${saved.name}". It will be in your memory index from now on.`, summary: saved.name, meta: { memory: saved.name, saved: true } };
@@ -7072,19 +7203,19 @@ ${note.content}`, summary: note.name, meta: { memory: note.name } };
7072
7203
  file: { type: "string", description: "Optional: one of the skill's files, as listed when it is loaded" }
7073
7204
  }),
7074
7205
  run: async ({ name, file }) => {
7075
- if (!this.library.skills.some((s) => s.name === name)) fail9(`Unknown skill "${name}". Available: ${this.library.skills.map((s) => s.name).join(", ")}.`);
7206
+ if (!this.library.skills.some((s) => s.name === name)) fail10(`Unknown skill "${name}". Available: ${this.library.skills.map((s) => s.name).join(", ")}.`);
7076
7207
  const library = this._library("skills");
7077
- if (!library) fail9("No skills are available here.");
7208
+ if (!library) fail10("No skills are available here.");
7078
7209
  if (file) {
7079
7210
  const read = await library.readFile(name, file);
7080
- return { output: clip5(read.content, MAX_SKILL_OUTPUT) || "(empty file)", summary: `${name} \xB7 ${read.path}`, meta: { skill: name, file: read.path } };
7211
+ return { output: clip6(read.content, MAX_SKILL_OUTPUT) || "(empty file)", summary: `${name} \xB7 ${read.path}`, meta: { skill: name, file: read.path } };
7081
7212
  }
7082
7213
  const skill = await library.get(name);
7083
7214
  const files = skill.files?.length ? `
7084
7215
 
7085
7216
  Files in this skill (read one with skill + file): ${skill.files.join(", ")}${skill.folder ? `
7086
7217
  Folder on this computer, for commands: ${skill.folder}` : ""}` : "";
7087
- return { output: clip5(`# Skill: ${name}
7218
+ return { output: clip6(`# Skill: ${name}
7088
7219
 
7089
7220
  ${skill.content}${files}`, MAX_SKILL_OUTPUT), summary: `Loaded ${name}`, meta: { skill: name, files: skill.files?.length || 0 } };
7090
7221
  }
@@ -7103,8 +7234,8 @@ ${skill.content}${files}`, MAX_SKILL_OUTPUT), summary: `Loaded ${name}`, meta: {
7103
7234
  }
7104
7235
  /** Lance un sous-agent : même machine, même mode, mêmes permissions, budget et crédits partagés avec ce run. */
7105
7236
  async _runSubagent({ agent: name, description = "", prompt }, call) {
7106
- if (!this.library.subagents.some((a) => a.name === name)) fail9(`Unknown subagent "${name}". Available: ${this.library.subagents.map((a) => a.name).join(", ")}.`);
7107
- if (!String(prompt || "").trim()) fail9("task needs a prompt: the subagent sees nothing of this conversation.");
7237
+ if (!this.library.subagents.some((a) => a.name === name)) fail10(`Unknown subagent "${name}". Available: ${this.library.subagents.map((a) => a.name).join(", ")}.`);
7238
+ if (!String(prompt || "").trim()) fail10("task needs a prompt: the subagent sees nothing of this conversation.");
7108
7239
  const definition = await this._definition("subagents", name);
7109
7240
  const wanted = !definition.tools || definition.tools === "all" ? WORKSPACE_TOOL_NAMES : definition.tools;
7110
7241
  const tools = wanted.filter((t) => this.toolNames.includes(t) && !PARENT_ONLY_TOOLS.has(t));
@@ -7154,7 +7285,7 @@ ${skill.content}${files}`, MAX_SKILL_OUTPUT), summary: `Loaded ${name}`, meta: {
7154
7285
 
7155
7286
  [${name} subagent \xB7 ${turns} turns \xB7 ${toolCalls} tool calls \xB7 ${credits} credits${ended}]`,
7156
7287
  summary: description || name,
7157
- meta: { agent: name, description, model: child.model, turns, toolCalls, credits, stopReason: result.stopReason, report: clip5(result.text || "", 4e3) }
7288
+ meta: { agent: name, description, model: child.model, turns, toolCalls, credits, stopReason: result.stopReason, report: clip6(result.text || "", 4e3) }
7158
7289
  };
7159
7290
  } finally {
7160
7291
  this.children.delete(child);
@@ -7185,7 +7316,7 @@ Files in this skill (read one with skill + file): ${skill.files.join(", ")}` : "
7185
7316
 
7186
7317
  # Skill: ${name}
7187
7318
 
7188
- ${clip5(skill.content, MAX_SKILL_OUTPUT)}${files}
7319
+ ${clip6(skill.content, MAX_SKILL_OUTPUT)}${files}
7189
7320
 
7190
7321
  # Request
7191
7322
  ${args || "Apply this skill."}`;
@@ -7248,13 +7379,13 @@ ${args || "Apply this skill."}`;
7248
7379
  const read = await this.catalog.read.run({ path }, { files });
7249
7380
  if (read.attachments?.length) images.push(...read.attachments.map((a) => ({ mime: a.mime, data: a.data })));
7250
7381
  sections.push(`## @${read.meta?.path || path}
7251
- ${read.attachments?.length ? read.output : clip5(read.output, 3e4)}`);
7382
+ ${read.attachments?.length ? read.output : clip6(read.output, 3e4)}`);
7252
7383
  emit({ type: "mention", kind: "file", path: read.meta?.path || path });
7253
7384
  } catch {
7254
7385
  try {
7255
7386
  const list = await this.catalog.list.run({ path }, { files });
7256
7387
  sections.push(`## @${path} (folder)
7257
- ${clip5(list.output, 8e3)}`);
7388
+ ${clip6(list.output, 8e3)}`);
7258
7389
  emit({ type: "mention", kind: "folder", path });
7259
7390
  } catch {
7260
7391
  }
@@ -7265,7 +7396,7 @@ ${clip5(list.output, 8e3)}`);
7265
7396
  try {
7266
7397
  const read = await this.catalog.query_storage.run({ storage: s.name, action, ...action === "schema" ? { collection: s.collection } : {}, ...action === "objects" && s.collection ? { prefix: s.collection } : {} }, { api: this.api });
7267
7398
  sections.push(`## #${s.name}${s.collection ? ` \xB7 ${s.collection}` : ""}
7268
- ${clip5(read.output, 8e3)}`);
7399
+ ${clip6(read.output, 8e3)}`);
7269
7400
  emit({ type: "mention", kind: "storage", storage: s.name, collection: s.collection });
7270
7401
  } catch (err) {
7271
7402
  sections.push(`## #${s.name}${s.collection ? ` \xB7 ${s.collection}` : ""}
@@ -10426,8 +10557,8 @@ var StudioDocument = class {
10426
10557
  }
10427
10558
  };
10428
10559
 
10429
- // src/resources/studio.js
10430
- var base = "/api/studio";
10560
+ // src/resources/design.js
10561
+ var base = "/api/design";
10431
10562
  var projectPath = (id) => `${base}/projects/${encodeURIComponent(id)}`;
10432
10563
  var byType = (path, type) => type === void 0 ? path : `${path}?type=${encodeURIComponent(type)}`;
10433
10564
  var StudioProject = class _StudioProject {
@@ -10474,8 +10605,11 @@ var StudioProject = class _StudioProject {
10474
10605
  Object.assign(this, project);
10475
10606
  return this;
10476
10607
  }
10608
+ async render({ frame, width, height } = {}) {
10609
+ return this.#client.post(`${projectPath(this.id)}/render`, { frame, width, height }, { timeout: 0 });
10610
+ }
10477
10611
  };
10478
- var StudioResource = class {
10612
+ var DesignResource = class {
10479
10613
  constructor(client) {
10480
10614
  const wrap = (data) => new StudioProject(client, data);
10481
10615
  this.templates = {
@@ -10587,7 +10721,7 @@ var IaGenify = class {
10587
10721
  this.mail = new MailResource(this._client);
10588
10722
  this.hosts = new HostsResource(this._client);
10589
10723
  this.compute = new ComputeResource(this._client);
10590
- this.studio = new StudioResource(this._client);
10724
+ this.design = new DesignResource(this._client);
10591
10725
  }
10592
10726
  async getUser() {
10593
10727
  const res = await this._client.get("/api/auth/me");