iagenify 0.4.2 → 0.4.4

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.js CHANGED
@@ -4119,6 +4119,135 @@ function createServiceTools() {
4119
4119
  };
4120
4120
  }
4121
4121
 
4122
+ // src/resources/designTools.js
4123
+ var DESIGN_TOOL_NAMES = ["design_read", "design_apply", "design_render", "design_check", "design_template"];
4124
+ var fail5 = (message) => {
4125
+ throw Object.assign(new Error(message), { code: "tool_error" });
4126
+ };
4127
+ var clip3 = (value, max = 48e3) => String(value || "").length > max ? `${String(value).slice(0, max)}
4128
+ \u2026[truncated]` : String(value || "");
4129
+ var projectId = (value) => {
4130
+ const id = String(value || "").trim();
4131
+ if (!id) fail5('"projectId" is required. Use the design project currently open in the editor.');
4132
+ return id;
4133
+ };
4134
+ var parseOperations = (value) => {
4135
+ let operations = value;
4136
+ if (typeof value === "string") {
4137
+ try {
4138
+ operations = JSON.parse(value);
4139
+ } catch (error) {
4140
+ fail5(`"operations" is not valid JSON (${error.message}).`);
4141
+ }
4142
+ }
4143
+ if (!Array.isArray(operations) || operations.length < 1 || operations.length > 100) {
4144
+ fail5('"operations" must be a JSON array with 1 to 100 document operations.');
4145
+ }
4146
+ return operations;
4147
+ };
4148
+ function createDesignTools() {
4149
+ return {
4150
+ design_read: {
4151
+ category: "read",
4152
+ 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.",
4153
+ parameters: {
4154
+ projectId: { type: "string", required: true, description: "The design project id currently open in the user's editor" },
4155
+ node: { type: "string", description: "An existing node id from this document" }
4156
+ },
4157
+ async run({ projectId: id, node: node4 }, { api }) {
4158
+ const project = await api.design.projects.get(projectId(id));
4159
+ const doc = await project.open();
4160
+ const json = doc.toJSON();
4161
+ const describe = (nodeId) => {
4162
+ const item = json.nodes[nodeId];
4163
+ if (!item) return null;
4164
+ return {
4165
+ id: nodeId,
4166
+ type: item.type,
4167
+ name: item.name,
4168
+ size: item.size,
4169
+ position: item.position,
4170
+ text: item.text,
4171
+ style: item.style,
4172
+ layout: item.layout,
4173
+ children: (item.children || []).map(describe)
4174
+ };
4175
+ };
4176
+ if (node4) {
4177
+ const item = json.nodes[node4];
4178
+ if (!item) fail5(`Unknown design node id "${node4}".`);
4179
+ return { output: clip3(JSON.stringify(describe(node4))), summary: `Read ${item.name || node4}`, meta: { projectId: project.id, node: node4 } };
4180
+ }
4181
+ const pages = json.pages.map((page) => ({ id: page.id, name: page.name, frames: page.frames.map(describe) }));
4182
+ 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 } };
4183
+ }
4184
+ },
4185
+ design_apply: {
4186
+ category: "write",
4187
+ 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.",
4188
+ parameters: {
4189
+ projectId: { type: "string", required: true, description: "The design project id currently open in the user's editor" },
4190
+ operations: { type: "string", required: true, description: "JSON array of 1\u2013100 valid document operations" }
4191
+ },
4192
+ async run({ projectId: id, operations: raw }, { api }) {
4193
+ const operations = parseOperations(raw);
4194
+ const project = await api.design.projects.get(projectId(id));
4195
+ const doc = await project.open();
4196
+ const applied = doc.apply(operations, { source: "agent" });
4197
+ const saved = await doc.save();
4198
+ return {
4199
+ output: `Applied and saved ${applied.applied} design operation${applied.applied === 1 ? "" : "s"} to ${project.label}. The open editor will receive this exact batch.`,
4200
+ summary: `Updated ${project.label}`,
4201
+ meta: { projectId: project.id, version: saved.version, operations, created: applied.created }
4202
+ };
4203
+ }
4204
+ },
4205
+ design_render: {
4206
+ category: "read",
4207
+ 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.",
4208
+ parameters: {
4209
+ projectId: { type: "string", required: true, description: "The design project id currently open in the user's editor" },
4210
+ frame: { type: "string", description: "Frame id from design_read; omit to render the first frame" }
4211
+ },
4212
+ async run({ projectId: id, frame }, { api }) {
4213
+ const project = await api.design.projects.get(projectId(id));
4214
+ const result = await project.render({ frame });
4215
+ if (!result?.image?.data) fail5("The design preview returned no image.");
4216
+ return {
4217
+ 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.`,
4218
+ summary: "Rendered the design for visual review",
4219
+ meta: { projectId: project.id, frame: result.image.frame, width: result.image.width, height: result.image.height },
4220
+ attachments: [{ mime: result.image.mime || "image/png", data: result.image.data }]
4221
+ };
4222
+ }
4223
+ },
4224
+ design_check: {
4225
+ category: "read",
4226
+ description: "Run deterministic design checks on a saved project and report every issue with rule, severity, node and measured details.",
4227
+ parameters: { projectId: { type: "string", required: true, description: "The design project id currently open in the user's editor" } },
4228
+ async run({ projectId: id }, { api }) {
4229
+ const project = await api.design.projects.get(projectId(id));
4230
+ const doc = await project.open();
4231
+ const result = doc.check();
4232
+ return { output: clip3(JSON.stringify(result)), summary: `${result.issues.length} design checks reported`, meta: { projectId: project.id, issues: result.issues.length } };
4233
+ }
4234
+ },
4235
+ design_template: {
4236
+ category: "read",
4237
+ description: "List available Design templates, or read one template by id including its starting document.",
4238
+ parameters: { id: { type: "string", description: "Template id; omit to list templates" } },
4239
+ async run({ id }, { api }) {
4240
+ if (!id) {
4241
+ const templates2 = await api.design.templates.list({ type: "design" });
4242
+ return { output: clip3(JSON.stringify(templates2)), summary: `${templates2.length} design templates`, meta: { count: templates2.length } };
4243
+ }
4244
+ const template = await api.design.templates.get(id);
4245
+ return { output: clip3(JSON.stringify(template)), summary: `Read template ${id}`, meta: { template: id } };
4246
+ }
4247
+ }
4248
+ };
4249
+ }
4250
+
4122
4251
  // src/resources/workspaceTools.js
4123
4252
  var MAX_OUTPUT = 6e4;
4124
4253
  var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", ".next", "dist", "build", "__pycache__", ".venv"]);
@@ -4141,12 +4270,12 @@ var MEDIA_MIME = {
4141
4270
  };
4142
4271
  var EXT_FOR = { markdown: "md", text: "txt", jpeg: "jpg", base64: "txt" };
4143
4272
  var ATTACHMENT_MAX = 15 * 1024 * 1024;
4144
- var fail5 = (message) => {
4273
+ var fail6 = (message) => {
4145
4274
  throw new IaGenifyError(400, "tool_error", message);
4146
4275
  };
4147
4276
  var short = (text2 = "", max = 80) => String(text2).length > max ? `${String(text2).slice(0, max)}\u2026` : String(text2);
4148
4277
  var filled2 = (value) => typeof value === "string" && value.trim() !== "";
4149
- var clip3 = (text2, max = MAX_OUTPUT) => text2.length > max ? `${text2.slice(0, max)}
4278
+ var clip4 = (text2, max = MAX_OUTPUT) => text2.length > max ? `${text2.slice(0, max)}
4150
4279
  \u2026[truncated ${text2.length - max} characters]` : text2;
4151
4280
  var stamp = () => (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
4152
4281
  var isTextMime = (mime) => mime.startsWith("text/") || /json|xml|yaml|javascript|typescript/.test(mime);
@@ -4220,7 +4349,7 @@ async function backup(files, path) {
4220
4349
  }
4221
4350
  async function readText(files, path) {
4222
4351
  const file = await files.read(path);
4223
- if (typeof file.content !== "string") fail5(`"${path}" is not a text file.`);
4352
+ if (typeof file.content !== "string") fail6(`"${path}" is not a text file.`);
4224
4353
  return file.content;
4225
4354
  }
4226
4355
  var countOf = (text2, needle) => needle ? text2.split(needle).length - 1 : 0;
@@ -4278,11 +4407,11 @@ function storageArgs(args = {}) {
4278
4407
  try {
4279
4408
  parsed = JSON.parse(value);
4280
4409
  } catch (err) {
4281
- fail5(`"${name}" is not valid JSON (${err.message}). Send it as JSON text, e.g. ${shape === "array" ? "[{\u2026}]" : "{\u2026}"}.`);
4410
+ fail6(`"${name}" is not valid JSON (${err.message}). Send it as JSON text, e.g. ${shape === "array" ? "[{\u2026}]" : "{\u2026}"}.`);
4282
4411
  }
4283
4412
  }
4284
4413
  const isArray = Array.isArray(parsed);
4285
- if (shape === "array" ? !isArray : isArray || parsed === null || typeof parsed !== "object") fail5(`"${name}" must be a JSON ${shape}.`);
4414
+ if (shape === "array" ? !isArray : isArray || parsed === null || typeof parsed !== "object") fail6(`"${name}" must be a JSON ${shape}.`);
4286
4415
  return parsed;
4287
4416
  };
4288
4417
  return {
@@ -4295,25 +4424,25 @@ function storageArgs(args = {}) {
4295
4424
  documents: parse("documents", "array")
4296
4425
  };
4297
4426
  }
4298
- var requireText2 = (value, name) => typeof value === "string" && value.trim() ? value.trim() : fail5(`"${name}" is required for this action.`);
4427
+ var requireText2 = (value, name) => typeof value === "string" && value.trim() ? value.trim() : fail6(`"${name}" is required for this action.`);
4299
4428
  async function pickStorage(api, name, providers) {
4300
- if (!providers) fail5("Unknown action for this tool.");
4429
+ if (!providers) fail6("Unknown action for this tool.");
4301
4430
  const connected = (await api.storage.list()).filter((s) => s.type === "database" || s.type === "object");
4302
- if (!connected.length) fail5("No database or bucket is connected. Tell the user to connect one in Cloud.");
4431
+ if (!connected.length) fail6("No database or bucket is connected. Tell the user to connect one in Cloud.");
4303
4432
  const describe = (list) => list.map((s) => `"${s.label}" (${storageKindName(s, PROVIDER_NAMES)})`).join(", ");
4304
4433
  const byName = name ? connected.find((s) => s.id === name || s.label === name) || connected.find((s) => s.label.toLowerCase() === String(name).trim().toLowerCase()) : null;
4305
- if (name && !byName) fail5(`No connected storage named "${name}". Connected: ${describe(connected)}.`);
4434
+ if (name && !byName) fail6(`No connected storage named "${name}". Connected: ${describe(connected)}.`);
4306
4435
  const able = connected.filter((s) => providers.includes(engineOf(s)));
4307
4436
  const storage = byName || (able.length === 1 ? able[0] : null);
4308
- 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)}.`);
4309
- if (!providers.includes(engineOf(storage))) fail5(`"${storage.label}" is ${storageKindName(storage, PROVIDER_NAMES)}; this action needs ${providers.map((p) => PROVIDER_NAMES[p]).join(" or ")}.`);
4437
+ 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)}.`);
4438
+ if (!providers.includes(engineOf(storage))) fail6(`"${storage.label}" is ${storageKindName(storage, PROVIDER_NAMES)}; this action needs ${providers.map((p) => PROVIDER_NAMES[p]).join(" or ")}.`);
4310
4439
  return storage;
4311
4440
  }
4312
4441
  function sqlStatement(input) {
4313
4442
  const sql = String(input || "").trim().replace(/;\s*$/, "");
4314
- if (!sql) fail5('"sql" is required for this action.');
4443
+ if (!sql) fail6('"sql" is required for this action.');
4315
4444
  const bare = sql.replace(/--[^\n]*/g, " ").replace(/\/\*[\s\S]*?\*\//g, " ").replace(/'(?:[^']|'')*'/g, "''").replace(/"(?:[^"]|"")*"/g, '""');
4316
- if (bare.includes(";")) fail5("Send one SQL statement per call.");
4445
+ if (bare.includes(";")) fail6("Send one SQL statement per call.");
4317
4446
  const verb = (bare.match(/^\s*([a-z]+)/i) || [])[1]?.toUpperCase() || "";
4318
4447
  const writesInside = /\b(INSERT|UPDATE|DELETE|REPLACE|CREATE|ALTER|DROP)\b/i.test(bare);
4319
4448
  const read = ["SELECT", "EXPLAIN"].includes(verb) && !writesInside || verb === "WITH" && !writesInside || verb === "PRAGMA" && !bare.includes("=");
@@ -4328,28 +4457,28 @@ async function checkStorageWrite(rawArgs = {}, { api, mode } = {}) {
4328
4457
  const emptyFilter = !args.filter || !Object.keys(args.filter).length;
4329
4458
  let statement = null;
4330
4459
  if (["insert", "update", "delete"].includes(action)) requireText2(args.collection, "collection");
4331
- 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.");
4460
+ 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.");
4332
4461
  if (action === "update") {
4333
- 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.");
4334
- 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.');
4462
+ 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.");
4463
+ 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.');
4335
4464
  }
4336
- 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.");
4465
+ 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.");
4337
4466
  if (action === "sql") {
4338
4467
  statement = sqlStatement(args.sql);
4339
- if (statement.read) fail5('This statement only reads: use query_storage with action "sql".');
4340
- if (!statement.write) fail5(`write_storage runs INSERT, UPDATE, DELETE, REPLACE, CREATE, ALTER or DROP \u2014 not ${statement.verb || "this statement"}.`);
4341
- 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.");
4342
- 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.`);
4468
+ if (statement.read) fail6('This statement only reads: use query_storage with action "sql".');
4469
+ if (!statement.write) fail6(`write_storage runs INSERT, UPDATE, DELETE, REPLACE, CREATE, ALTER or DROP \u2014 not ${statement.verb || "this statement"}.`);
4470
+ 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.");
4471
+ 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.`);
4343
4472
  }
4344
4473
  if (action === "put") {
4345
4474
  requireText2(args.key, "key");
4346
- if (args.content == null && !args.path) fail5("put needs content (text) or path (a workspace file).");
4475
+ if (args.content == null && !args.path) fail6("put needs content (text) or path (a workspace file).");
4347
4476
  }
4348
4477
  if (action === "remove") requireText2(args.key, "key");
4349
4478
  if (action === "create_collection") requireText2(args.collection, "collection");
4350
4479
  if (action === "drop_collection") {
4351
4480
  requireText2(args.collection, "collection");
4352
- 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.");
4481
+ 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.");
4353
4482
  }
4354
4483
  return { db, statement, args };
4355
4484
  }
@@ -4363,7 +4492,7 @@ function createWorkspaceTools({ client }) {
4363
4492
  if (typeof text2 !== "string" && attachMime) {
4364
4493
  if (file.size > ATTACHMENT_MAX) {
4365
4494
  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.";
4366
- fail5(`"${file.path}" is ${(file.size / 1048576).toFixed(1)} MB; files over ${ATTACHMENT_MAX / 1048576} MB cannot be attached.${advice}`);
4495
+ fail6(`"${file.path}" is ${(file.size / 1048576).toFixed(1)} MB; files over ${ATTACHMENT_MAX / 1048576} MB cannot be attached.${advice}`);
4367
4496
  }
4368
4497
  const kind = attachMime.startsWith("audio/") ? "Listen to it" : attachMime.startsWith("video/") ? "Watch it" : "Read it";
4369
4498
  return {
@@ -4377,7 +4506,7 @@ function createWorkspaceTools({ client }) {
4377
4506
  if (CONVERTIBLE[ext]) {
4378
4507
  const converted = await convert.convert({ from: ext, to: CONVERTIBLE[ext], file: file.content });
4379
4508
  text2 = String(converted.content ?? converted.markdown ?? converted.text ?? "");
4380
- if (!text2) fail5(`Could not extract text from "${path}".`);
4509
+ if (!text2) fail6(`Could not extract text from "${path}".`);
4381
4510
  } else {
4382
4511
  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 } };
4383
4512
  }
@@ -4388,7 +4517,7 @@ function createWorkspaceTools({ client }) {
4388
4517
  const numbered = slice.map((l, i) => `${start + i} ${l.length > 2e3 ? `${l.slice(0, 2e3)}\u2026` : l}`).join("\n");
4389
4518
  const more = start - 1 + slice.length < lines.length ? `
4390
4519
  \u2026[${lines.length - (start - 1 + slice.length)} more lines \u2014 use offset]` : "";
4391
- return { output: clip3(numbered + more) || "(empty file)", summary: `${file.path} \xB7 ${lines.length} lines`, meta: { path: file.path, lines: lines.length } };
4520
+ return { output: clip4(numbered + more) || "(empty file)", summary: `${file.path} \xB7 ${lines.length} lines`, meta: { path: file.path, lines: lines.length } };
4392
4521
  }
4393
4522
  const search = new SearchResource(client);
4394
4523
  const fetchPage = new FetchResource(client);
@@ -4397,6 +4526,7 @@ function createWorkspaceTools({ client }) {
4397
4526
  ...createPlatformTools(),
4398
4527
  // P54 : les services de la plateforme — hébergement, courrier, domaines, compte, documents, second modèle.
4399
4528
  ...createServiceTools(),
4529
+ ...createDesignTools(),
4400
4530
  read: {
4401
4531
  category: "read",
4402
4532
  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.",
@@ -4408,8 +4538,8 @@ function createWorkspaceTools({ client }) {
4408
4538
  },
4409
4539
  async run({ path, paths, offset = 1, limit = 2e3 }, context) {
4410
4540
  const liste = Array.isArray(paths) && paths.length ? paths.map((p) => String(p)) : [String(path ?? "")];
4411
- if (!filled2(liste[0])) fail5('Give "path" (one file) or "paths" (several).');
4412
- if (liste.length > 20) fail5(`A single call reads at most 20 files (got ${liste.length}).`);
4541
+ if (!filled2(liste[0])) fail6('Give "path" (one file) or "paths" (several).');
4542
+ if (liste.length > 20) fail6(`A single call reads at most 20 files (got ${liste.length}).`);
4413
4543
  if (liste.length === 1) return lireFichier(liste[0], { offset, limit }, context);
4414
4544
  const lus = [];
4415
4545
  const pieces2 = [];
@@ -4425,7 +4555,7 @@ Error: ${err.message}`);
4425
4555
  }
4426
4556
  }
4427
4557
  return {
4428
- output: clip3(lus.join("\n\n"), 6e4),
4558
+ output: clip4(lus.join("\n\n"), 6e4),
4429
4559
  summary: `${liste.length} files`,
4430
4560
  meta: { paths: liste, attached: pieces2.length || void 0 },
4431
4561
  ...pieces2.length ? { attachments: pieces2 } : {}
@@ -4462,7 +4592,7 @@ Error: ${err.message}`);
4462
4592
  try {
4463
4593
  re = new RegExp(pattern, ignore_case ? "i" : "");
4464
4594
  } catch (err) {
4465
- fail5(`Invalid regular expression: ${err.message}`);
4595
+ fail6(`Invalid regular expression: ${err.message}`);
4466
4596
  }
4467
4597
  const only = glob ? globToRegExp(glob) : null;
4468
4598
  const hits = [];
@@ -4496,8 +4626,8 @@ Error: ${err.message}`);
4496
4626
  async run({ path, old_string, new_string, replace_all = false }, { files }) {
4497
4627
  const before = await readText(files, path);
4498
4628
  const count = countOf(before, old_string);
4499
- if (!count) fail5(`old_string was not found in "${path}". Read the file and copy the text exactly.`);
4500
- if (count > 1 && !replace_all) fail5(`old_string appears ${count} times in "${path}". Add surrounding lines to make it unique, or set replace_all.`);
4629
+ if (!count) fail6(`old_string was not found in "${path}". Read the file and copy the text exactly.`);
4630
+ if (count > 1 && !replace_all) fail6(`old_string appears ${count} times in "${path}". Add surrounding lines to make it unique, or set replace_all.`);
4501
4631
  const after = replace_all ? before.split(old_string).join(new_string) : before.replace(old_string, () => new_string);
4502
4632
  await backup(files, path);
4503
4633
  await files.write(path, after);
@@ -4521,8 +4651,8 @@ Error: ${err.message}`);
4521
4651
  const diffs = [];
4522
4652
  edits.forEach((e, i) => {
4523
4653
  const count = countOf(text2, e.old_string);
4524
- if (!count) fail5(`Edit ${i + 1}: old_string not found in "${path}". Nothing was changed.`);
4525
- if (count > 1 && !e.replace_all) fail5(`Edit ${i + 1}: old_string appears ${count} times. Nothing was changed.`);
4654
+ if (!count) fail6(`Edit ${i + 1}: old_string not found in "${path}". Nothing was changed.`);
4655
+ if (count > 1 && !e.replace_all) fail6(`Edit ${i + 1}: old_string appears ${count} times. Nothing was changed.`);
4526
4656
  diffs.push(diffOf(text2, e.old_string, e.new_string));
4527
4657
  text2 = e.replace_all ? text2.split(e.old_string).join(e.new_string) : text2.replace(e.old_string, () => e.new_string);
4528
4658
  });
@@ -4566,17 +4696,17 @@ Error: ${err.message}`);
4566
4696
  // Refusé avant toute permission, en disant comment faire.
4567
4697
  check({ command = "", commands, background } = {}, { shell, terminals } = {}) {
4568
4698
  if (commands !== void 0) {
4569
- if (!Array.isArray(commands) || !commands.length) fail5('"commands" must be a list of shell commands, e.g. ["npm ci", "npm run build"].');
4570
- if (commands.some((c) => typeof c !== "string" || !c.trim())) fail5('Every entry of "commands" must be a non-empty command.');
4571
- if (commands.length > 20) fail5(`A single call runs at most 20 commands (got ${commands.length}).`);
4572
- if (background === true) fail5("background: true runs ONE command in a terminal. Use command, not commands \u2014 or run the sequence without background.");
4699
+ if (!Array.isArray(commands) || !commands.length) fail6('"commands" must be a list of shell commands, e.g. ["npm ci", "npm run build"].');
4700
+ if (commands.some((c) => typeof c !== "string" || !c.trim())) fail6('Every entry of "commands" must be a non-empty command.');
4701
+ if (commands.length > 20) fail6(`A single call runs at most 20 commands (got ${commands.length}).`);
4702
+ if (background === true) fail6("background: true runs ONE command in a terminal. Use command, not commands \u2014 or run the sequence without background.");
4573
4703
  } else if (!filled2(command)) {
4574
- fail5('Give "command" (one command) or "commands" (several, run in order).');
4704
+ fail6('Give "command" (one command) or "commands" (several, run in order).');
4575
4705
  }
4576
4706
  if (background === true || !terminals) return;
4577
4707
  const text2 = [command, ...Array.isArray(commands) ? commands : []].filter(Boolean).join("\n");
4578
4708
  if (DETACHED.test(text2) && RUNTIME.test(text2)) {
4579
- 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" }.`);
4709
+ 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" }.`);
4580
4710
  }
4581
4711
  },
4582
4712
  async run({ command, commands, timeout_ms = 12e4, background = false, stop_on_error = true, port = null }, { root, signal, shell, terminals }) {
@@ -4585,7 +4715,7 @@ Error: ${err.message}`);
4585
4715
  const seule = liste[0];
4586
4716
  const auto = background !== true && Boolean(terminals) && liste.length === 1 && LONG_RUNNING.test(seule);
4587
4717
  if (background === true || auto) {
4588
- if (!terminals) fail5("Background commands need a terminal environment, and there are none here. Run the command without background.");
4718
+ if (!terminals) fail6("Background commands need a terminal environment, and there are none here. Run the command without background.");
4589
4719
  const note = auto ? "This command starts a server that never exits, so it runs in a terminal instead of blocking.\n" : "";
4590
4720
  const terminal = await terminals.create({ name: short(seule, 60), command: seule, by: "agent", ...port ? { port } : {} });
4591
4721
  const first = await settle(terminal, signal);
@@ -4594,9 +4724,9 @@ Error: ${err.message}`);
4594
4724
  const exited = first.status === "exited";
4595
4725
  const output = exited ? `Terminal ${terminal.id} (${seule}) exited with code ${first.exitCode} right away.
4596
4726
  --- output ---
4597
- ${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.
4727
+ ${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.
4598
4728
  --- first output ---
4599
- ${clip3(text2, 2e4) || "(nothing yet)"}`;
4729
+ ${clip4(text2, 2e4) || "(nothing yet)"}`;
4600
4730
  const adresse = terminal.url ? `
4601
4731
 
4602
4732
  Open it at: ${terminal.url}
@@ -4604,7 +4734,7 @@ If it does not answer, the server is listening on localhost instead of 0.0.0.0 \
4604
4734
  return {
4605
4735
  output: note + output + adresse,
4606
4736
  summary: `${seule.slice(0, 80)} \xB7 ${exited ? `exit ${first.exitCode}` : terminal.url || `terminal ${terminal.id}`}`,
4607
- 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 }
4737
+ 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 }
4608
4738
  };
4609
4739
  }
4610
4740
  const executer = async (cmd) => {
@@ -4656,9 +4786,9 @@ If it does not answer, the server is listening on localhost instead of 0.0.0.0 \
4656
4786
  if (liste.length === 1) {
4657
4787
  const r = await executer(seule);
4658
4788
  const output = [`exit code ${etat(r)}`, r.stdout && `--- stdout ---
4659
- ${clip3(r.stdout, 3e4)}`, r.stderr && `--- stderr ---
4660
- ${clip3(r.stderr, 3e4)}`].filter(Boolean).join("\n");
4661
- 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) } };
4789
+ ${clip4(r.stdout, 3e4)}`, r.stderr && `--- stderr ---
4790
+ ${clip4(r.stderr, 3e4)}`].filter(Boolean).join("\n");
4791
+ 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) } };
4662
4792
  }
4663
4793
  const faits = [];
4664
4794
  for (const cmd of liste) {
@@ -4671,9 +4801,9 @@ ${clip3(r.stderr, 3e4)}`].filter(Boolean).join("\n");
4671
4801
  const bloc = faits.map((r, i) => [
4672
4802
  `[${i + 1}/${liste.length}] ${r.cmd} \u2014 exit ${etat(r)}`,
4673
4803
  r.stdout && `--- stdout ---
4674
- ${clip3(r.stdout, part)}`,
4804
+ ${clip4(r.stdout, part)}`,
4675
4805
  r.stderr && `--- stderr ---
4676
- ${clip3(r.stderr, part)}`
4806
+ ${clip4(r.stderr, part)}`
4677
4807
  ].filter(Boolean).join("\n")).join("\n\n");
4678
4808
  const dernier = faits.at(-1);
4679
4809
  const rates = faits.filter((r) => r.timedOut || r.code !== 0).length;
@@ -4689,8 +4819,8 @@ Stopped at command ${faits.length} of ${liste.length}: the rest was not run.` :
4689
4819
  exitCode: dernier ? dernier.code : null,
4690
4820
  timedOut: Boolean(dernier?.timedOut),
4691
4821
  results: faits.map((r) => ({ command: r.cmd, exitCode: r.code, timedOut: r.timedOut })),
4692
- stdout: clip3(faits.map((r) => r.stdout).filter(Boolean).join("\n"), 4e3),
4693
- stderr: clip3(faits.map((r) => r.stderr).filter(Boolean).join("\n"), 4e3)
4822
+ stdout: clip4(faits.map((r) => r.stdout).filter(Boolean).join("\n"), 4e3),
4823
+ stderr: clip4(faits.map((r) => r.stderr).filter(Boolean).join("\n"), 4e3)
4694
4824
  }
4695
4825
  };
4696
4826
  }
@@ -4707,14 +4837,14 @@ Stopped at command ${faits.length} of ${liste.length}: the rest was not run.` :
4707
4837
  since: { type: "integer", description: "output: read from this position; 0 = everything kept" }
4708
4838
  },
4709
4839
  async run({ action, id, since }, { terminals }) {
4710
- if (!terminals) fail5("There are no terminals here: they only exist on a computer.");
4840
+ if (!terminals) fail6("There are no terminals here: they only exist on a computer.");
4711
4841
  if (action === "list") {
4712
4842
  const all = await terminals.list();
4713
4843
  if (!all.length) return { output: "No terminals are open.", summary: "No terminals", meta: { terminals: [] } };
4714
4844
  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}`);
4715
4845
  return { output: lines.join("\n"), summary: `${all.filter((t) => t.status === "running").length} running \xB7 ${all.length} terminals`, meta: { terminals: all } };
4716
4846
  }
4717
- if (!id) fail5(`"id" is required for ${action}. Use terminal { action: "list" } to find it.`);
4847
+ if (!id) fail6(`"id" is required for ${action}. Use terminal { action: "list" } to find it.`);
4718
4848
  const terminal = await terminals.get(id);
4719
4849
  if (action === "output") {
4720
4850
  const from = since != null ? Number(since) : terminal.agentCursor || 0;
@@ -4724,16 +4854,16 @@ Stopped at command ${faits.length} of ${liste.length}: the rest was not run.` :
4724
4854
  return {
4725
4855
  output: `${terminal.id} \xB7 ${out.status}${out.status === "exited" ? ` (code ${out.exitCode ?? "stopped"})` : ""}${out.truncated ? " \xB7 older output was dropped" : ""}
4726
4856
  --- output ---
4727
- ${clip3(text2, 3e4) || "(no new output)"}`,
4857
+ ${clip4(text2, 3e4) || "(no new output)"}`,
4728
4858
  summary: `${terminal.name} \xB7 ${out.status}`,
4729
- meta: { terminalId: terminal.id, status: out.status, exitCode: out.exitCode, stdout: clip3(text2, 4e3) }
4859
+ meta: { terminalId: terminal.id, status: out.status, exitCode: out.exitCode, stdout: clip4(text2, 4e3) }
4730
4860
  };
4731
4861
  }
4732
4862
  if (action === "kill") {
4733
4863
  const stopped = await terminal.kill();
4734
4864
  return { output: `Stopped terminal ${stopped.id} (${stopped.command || stopped.name}).`, summary: `Stopped ${stopped.name}`, meta: { terminalId: stopped.id, status: stopped.status } };
4735
4865
  }
4736
- fail5(`Unknown action "${action}": use list, output or kill.`);
4866
+ fail6(`Unknown action "${action}": use list, output or kill.`);
4737
4867
  }
4738
4868
  },
4739
4869
  ask_user: {
@@ -4806,7 +4936,7 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
4806
4936
  const shot = r.screenshot?.base64 ? { mime: r.screenshot.mimeType || "image/jpeg", data: r.screenshot.base64 } : null;
4807
4937
  if (screenshot === true && !shot) sections.push("--- screenshot ---\n(the page could not be captured as an image)");
4808
4938
  return {
4809
- output: clip3(sections.filter(Boolean).join("\n\n"), 3e4),
4939
+ output: clip4(sections.filter(Boolean).join("\n\n"), 3e4),
4810
4940
  summary: `${r.title || url}${shot ? " \xB7 seen" : ""}`,
4811
4941
  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 } : {} },
4812
4942
  ...shot ? { attachments: [shot] } : {}
@@ -4825,12 +4955,12 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
4825
4955
  },
4826
4956
  async run({ path, url, to, save }, { files }) {
4827
4957
  const target = String(to || "").trim().toLowerCase();
4828
- if (!target) fail5('"to" is required: the format to convert into, e.g. "pdf".');
4829
- if (!filled2(path) && !filled2(url)) fail5('Give "path" (a workspace file) or "url".');
4830
- if (filled2(path) && filled2(url)) fail5('Give "path" or "url", not both.');
4958
+ if (!target) fail6('"to" is required: the format to convert into, e.g. "pdf".');
4959
+ if (!filled2(path) && !filled2(url)) fail6('Give "path" (a workspace file) or "url".');
4960
+ if (filled2(path) && filled2(url)) fail6('Give "path" or "url", not both.');
4831
4961
  const sourceName = filled2(path) ? String(path) : new URL(String(url)).pathname.split("/").filter(Boolean).pop() || "page";
4832
4962
  const from = sourceName.includes(".") ? sourceName.split(".").pop().toLowerCase() : "";
4833
- if (!from) fail5(`Cannot tell the format of "${sourceName}": the name has no extension.`);
4963
+ if (!from) fail6(`Cannot tell the format of "${sourceName}": the name has no extension.`);
4834
4964
  let result;
4835
4965
  if (filled2(path)) {
4836
4966
  const file = await files.read(path);
@@ -4839,7 +4969,7 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
4839
4969
  } else {
4840
4970
  result = await convert.convert({ from, to: target, url: String(url) });
4841
4971
  }
4842
- if (!result?.ok) fail5(result?.message || `Conversion ${from} \u2192 ${target} failed.`);
4972
+ if (!result?.ok) fail6(result?.message || `Conversion ${from} \u2192 ${target} failed.`);
4843
4973
  const data = result.content !== void 0 ? String(result.content) : Buffer.from(result.base64 || "", "base64");
4844
4974
  const ext = EXT_FOR[target] || target;
4845
4975
  const base2 = sourceName.replace(/\.[^.]+$/, "");
@@ -4920,7 +5050,7 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
4920
5050
  const usage = await api.cloud.usage();
4921
5051
  if (!args.storage) return { output: cloudUsageReport(usage), summary: "IaGenify Cloud \xB7 usage", meta: { action, storage: null } };
4922
5052
  const target2 = await pickStorage(api, args.storage, STORAGE_READS.usage);
4923
- if (!target2.service) fail5(`"${target2.label}" is a connected storage: its space is managed by its own provider. usage only reports IaGenify Cloud storages.`);
5053
+ if (!target2.service) fail6(`"${target2.label}" is a connected storage: its space is managed by its own provider. usage only reports IaGenify Cloud storages.`);
4924
5054
  return { output: cloudUsageReport(usage, target2), summary: `${target2.label} \xB7 usage`, meta: { storage: target2.label, provider: target2.provider, action } };
4925
5055
  }
4926
5056
  const db = await pickStorage(api, args.storage, STORAGE_READS[action]);
@@ -4928,7 +5058,7 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
4928
5058
  if (action === "overview") {
4929
5059
  const seen = await db.run({ action: "overview" });
4930
5060
  return {
4931
- output: clip3(overviewReport(db, seen), 3e4),
5061
+ output: clip4(overviewReport(db, seen), 3e4),
4932
5062
  summary: `${db.label} \xB7 overview`,
4933
5063
  meta: { storage: db.label, provider: db.provider, action, returned: (seen.collections || seen.tables || seen.folders || []).length }
4934
5064
  };
@@ -4944,13 +5074,13 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
4944
5074
  });
4945
5075
  } else if (action === "count") result = await db.run({ action: "count", collection: requireText2(args.collection, "collection"), filter: args.filter || {} });
4946
5076
  else if (action === "aggregate") {
4947
- 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"}}}].');
4948
- if (/"\$(out|merge)"/.test(JSON.stringify(args.pipeline))) fail5("aggregate is read-only: $out and $merge are not allowed.");
5077
+ 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"}}}].');
5078
+ if (/"\$(out|merge)"/.test(JSON.stringify(args.pipeline))) fail6("aggregate is read-only: $out and $merge are not allowed.");
4949
5079
  result = await db.run({ action: "aggregate", collection: requireText2(args.collection, "collection"), pipeline: args.pipeline });
4950
5080
  } else if (action === "tables") result = await db.run({ action: "tables" });
4951
5081
  else if (action === "sql") {
4952
5082
  const statement = sqlStatement(args.sql);
4953
- 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".`);
5083
+ 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".`);
4954
5084
  result = await db.run({ sql: statement.sql, params: Array.isArray(args.params) ? args.params : [] });
4955
5085
  } else if (action === "objects") result = await db.run({ action: "list", prefix: String(args.prefix || "") });
4956
5086
  else if (action === "object") result = await db.run({ action: "object", key: requireText2(args.key, "key") });
@@ -4965,7 +5095,7 @@ ${(res.slowest || []).map((x) => `${Math.round(x.duration)} ms ${short(x.url, 12
4965
5095
  };
4966
5096
  }
4967
5097
  return {
4968
- output: clip3(results.map((r, i) => `[${i + 1}] ${r.source?.name || "document"} \xB7 ${r.score}
5098
+ output: clip4(results.map((r, i) => `[${i + 1}] ${r.source?.name || "document"} \xB7 ${r.score}
4969
5099
  ${r.text}`).join("\n\n"), 3e4),
4970
5100
  summary: `${db.label} \xB7 ${results.length} extract${results.length === 1 ? "" : "s"}`,
4971
5101
  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))] }
@@ -5019,7 +5149,7 @@ ${r.text}`).join("\n\n"), 3e4),
5019
5149
  else if (action === "drop_collection") result = await db.run({ action: "dropCollection", collection: args.collection.trim() });
5020
5150
  const target = args.collection || args.key || (args.sql ? String(args.sql).trim().split(/\s+/).slice(0, 3).join(" ") : "");
5021
5151
  return {
5022
- output: clip3(JSON.stringify(result, null, 1), 3e4),
5152
+ output: clip4(JSON.stringify(result, null, 1), 3e4),
5023
5153
  summary: `${db.label} \xB7 ${action}${target ? ` ${target}` : ""}`,
5024
5154
  meta: { storage: db.label, provider: db.provider, action, collection: args.collection || null, result }
5025
5155
  };
@@ -5090,28 +5220,28 @@ var MEDIA = {
5090
5220
  // produire doit se dire tout de suite, pas revenir en erreur du fournisseur une fois payé.
5091
5221
  verify: (a, model) => {
5092
5222
  if (OMNI_MODELS.includes(model)) {
5093
- if (a.audio === true) fail5(`"${model}" has no sound option. Use veo-3.1 for sound.`);
5223
+ if (a.audio === true) fail6(`"${model}" has no sound option. Use veo-3.1 for sound.`);
5094
5224
  if (a.duration !== void 0 && a.duration !== null && a.duration !== "") {
5095
5225
  const d = Number(a.duration);
5096
5226
  if (!Number.isFinite(d) || d < OMNI_SECONDS.min || d > OMNI_SECONDS.max) {
5097
- fail5(`"${model}" makes videos of ${OMNI_SECONDS.min} to ${OMNI_SECONDS.max} seconds (the provider's limit); you asked for ${a.duration}.`);
5227
+ fail6(`"${model}" makes videos of ${OMNI_SECONDS.min} to ${OMNI_SECONDS.max} seconds (the provider's limit); you asked for ${a.duration}.`);
5098
5228
  }
5099
5229
  }
5100
5230
  const permises = VIDEO_RESOLUTIONS[model] || [];
5101
5231
  if (filled2(a.resolution) && !permises.includes(a.resolution)) {
5102
- fail5(`"${model}" has no ${a.resolution}. It does ${permises.join(", ")}.`);
5232
+ fail6(`"${model}" has no ${a.resolution}. It does ${permises.join(", ")}.`);
5103
5233
  }
5104
5234
  return;
5105
5235
  }
5106
5236
  if (a.audio === true && !VIDEO_WITH_AUDIO.includes(model)) {
5107
- fail5(`"${model}" makes no sound. Only ${VIDEO_WITH_AUDIO.join(", ")} does \u2014 pass model: "veo-3.1", or leave audio out.`);
5237
+ fail6(`"${model}" makes no sound. Only ${VIDEO_WITH_AUDIO.join(", ")} does \u2014 pass model: "veo-3.1", or leave audio out.`);
5108
5238
  }
5109
5239
  if (a.duration !== void 0 && a.duration !== null && !VIDEO_DURATIONS.includes(Number(a.duration))) {
5110
- fail5(`duration must be ${VIDEO_DURATIONS.join(", ")} seconds; you asked for ${a.duration}.`);
5240
+ fail6(`duration must be ${VIDEO_DURATIONS.join(", ")} seconds; you asked for ${a.duration}.`);
5111
5241
  }
5112
5242
  const allowed = VIDEO_RESOLUTIONS[model] || [];
5113
5243
  if (filled2(a.resolution) && !allowed.includes(a.resolution)) {
5114
- fail5(`"${model}" has no ${a.resolution}. It does ${allowed.join(", ")} \u2014 change the resolution, or pick another model.`);
5244
+ fail6(`"${model}" has no ${a.resolution}. It does ${allowed.join(", ")} \u2014 change the resolution, or pick another model.`);
5115
5245
  }
5116
5246
  },
5117
5247
  // Omni : seulement ce qui a été demandé — sans durée, le modèle fait ses 10 s par défaut, et un
@@ -5200,7 +5330,7 @@ function createMediaTools({ client, media = {} }) {
5200
5330
  const args = fusionner(spec, media[MEDIA_KINDS[name]] || {}, brut);
5201
5331
  const model = filled2(args.model) ? args.model : spec.model;
5202
5332
  if (!spec.models.includes(model)) {
5203
- fail5(`${name} has no model "${args.model}". Available: ${spec.models.join(", ")}.`);
5333
+ fail6(`${name} has no model "${args.model}". Available: ${spec.models.join(", ")}.`);
5204
5334
  }
5205
5335
  if (spec.verify) spec.verify(args, model);
5206
5336
  },
@@ -5212,15 +5342,15 @@ function createMediaTools({ client, media = {} }) {
5212
5342
  if (spec.from && filled2(image)) {
5213
5343
  const source = await files.read(String(image));
5214
5344
  const mime = /^image\//.test(source.mimeType || "") ? source.mimeType : mimeOf(String(image));
5215
- if (!mime || !mime.startsWith("image/")) fail5(`"${source.path}" is not an image (${source.mimeType || "unknown type"}).`);
5216
- 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.`);
5345
+ if (!mime || !mime.startsWith("image/")) fail6(`"${source.path}" is not an image (${source.mimeType || "unknown type"}).`);
5346
+ 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.`);
5217
5347
  inputs.push({ type: "image", content: Buffer.from(source.content).toString("base64"), mime });
5218
5348
  }
5219
5349
  const session = await models.create({ model, settings: spec.settings(args, model), memory: false });
5220
5350
  try {
5221
5351
  const result = await session.generate({ inputs, outputs: [{ type: spec.output }] });
5222
5352
  const output = result.outputs?.find((o) => o.content);
5223
- if (!output) fail5(`The ${spec.type} model returned nothing.`);
5353
+ if (!output) fail6(`The ${spec.type} model returned nothing.`);
5224
5354
  const ext = output.mime?.split("/")[1]?.split(";")[0]?.replace("mpeg", "mp3") || spec.ext;
5225
5355
  const target = path || `Agent/${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}/${Date.now()}.${ext}`;
5226
5356
  const item = await files.write(target, Buffer.from(output.content, "base64"));
@@ -5237,10 +5367,10 @@ function createMediaTools({ client, media = {} }) {
5237
5367
  }
5238
5368
  }]));
5239
5369
  }
5240
- 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)];
5370
+ 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)];
5241
5371
 
5242
5372
  // src/resources/prompt.js
5243
- var fail6 = (code, message) => new IaGenifyError(400, code, message);
5373
+ var fail7 = (code, message) => new IaGenifyError(400, code, message);
5244
5374
  var PROMPT_OPTIONS = {
5245
5375
  model: "text",
5246
5376
  mode: ["ask", "auto", "plan", "full"],
@@ -5281,26 +5411,26 @@ function parsePrompt(input, library = {}) {
5281
5411
  if (!flag) break;
5282
5412
  const key = flag[1].toLowerCase();
5283
5413
  const kind = PROMPT_OPTIONS[key];
5284
- if (!kind) throw fail6("unknown_option", `Unknown option --${key}. Options: ${Object.keys(PROMPT_OPTIONS).map((k) => `--${k}`).join(" ")}. Write \\-- to start a message with "--".`);
5414
+ if (!kind) throw fail7("unknown_option", `Unknown option --${key}. Options: ${Object.keys(PROMPT_OPTIONS).map((k) => `--${k}`).join(" ")}. Write \\-- to start a message with "--".`);
5285
5415
  rest = rest.slice(flag[0].length);
5286
5416
  if (kind === "flag") {
5287
5417
  if (key === "no-memory") options.memory = false;
5288
5418
  continue;
5289
5419
  }
5290
5420
  const found = rest.match(/^(?:=|[ \t]+)("([^"]*)"|'([^']*)'|\S+)/);
5291
- if (!found) throw fail6("option_value_required", `--${key} needs a value.`);
5421
+ if (!found) throw fail7("option_value_required", `--${key} needs a value.`);
5292
5422
  const value = found[2] ?? found[3] ?? found[1];
5293
5423
  rest = rest.slice(found[0].length);
5294
5424
  if (key === "mode") {
5295
- if (!kind.includes(value)) throw fail6("invalid_option", `--mode must be one of ${kind.join(", ")}.`);
5425
+ if (!kind.includes(value)) throw fail7("invalid_option", `--mode must be one of ${kind.join(", ")}.`);
5296
5426
  options.mode = value;
5297
5427
  } else if (key === "budget") {
5298
5428
  if (value === "none") options.budget = null;
5299
5429
  else if (Number(value) > 0) options.budget = Math.round(Number(value));
5300
- else throw fail6("invalid_option", "--budget takes a number of credits, or none.");
5430
+ else throw fail7("invalid_option", "--budget takes a number of credits, or none.");
5301
5431
  } else if (key === "context") {
5302
5432
  const tokens = parseTokenCount(value);
5303
- if (!tokens) throw fail6("invalid_option", "--context takes a number of tokens: 200k, 400k, 1M.");
5433
+ if (!tokens) throw fail7("invalid_option", "--context takes a number of tokens: 200k, 400k, 1M.");
5304
5434
  options.contextTokens = tokens;
5305
5435
  } else {
5306
5436
  options[key] = value;
@@ -5341,7 +5471,7 @@ function parsePrompt(input, library = {}) {
5341
5471
  }
5342
5472
 
5343
5473
  // src/resources/library.js
5344
- var fail7 = (status, code, message) => new IaGenifyError(status, code, message);
5474
+ var fail8 = (status, code, message) => new IaGenifyError(status, code, message);
5345
5475
  var NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
5346
5476
  var MAX_CONTENT = 1e5;
5347
5477
  var CLAUDE_TOOLS = { ls: "list", websearch: "search", webfetch: "fetch", multiedit: "multi_edit", todowrite: "todo_write" };
@@ -5423,13 +5553,13 @@ var LocalLibrary = class {
5423
5553
  }
5424
5554
  async _ready() {
5425
5555
  if (typeof process === "undefined" || !process.versions?.node) {
5426
- 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.");
5556
+ 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.");
5427
5557
  }
5428
5558
  if (this.storage && this.storage.type !== "filesystem") {
5429
- 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.`);
5559
+ 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.`);
5430
5560
  }
5431
5561
  if (this.storage?.machineId && this.storage.machineId !== await getMachineId()) {
5432
- throw fail7(409, "storage_not_on_this_machine", `\xAB ${this.storage.label} \xBB belongs to another computer: its ${this.kind} stay there.`);
5562
+ throw fail8(409, "storage_not_on_this_machine", `\xAB ${this.storage.label} \xBB belongs to another computer: its ${this.kind} stay there.`);
5433
5563
  }
5434
5564
  const { fs, path, os } = await node3();
5435
5565
  const base2 = this.root || path.join(os.homedir(), ".iagenify");
@@ -5442,7 +5572,7 @@ var LocalLibrary = class {
5442
5572
  }
5443
5573
  _checkName(name) {
5444
5574
  if (typeof name !== "string" || !NAME.test(name)) {
5445
- throw fail7(400, "invalid_name", `A ${this.spec.label} name uses lowercase letters, digits and dashes (e.g. "legal-review"), 64 characters at most.`);
5575
+ throw fail8(400, "invalid_name", `A ${this.spec.label} name uses lowercase letters, digits and dashes (e.g. "legal-review"), 64 characters at most.`);
5446
5576
  }
5447
5577
  }
5448
5578
  /** Un élément lu sur disque : { name, description, …, content, builtIn: false }. */
@@ -5486,7 +5616,7 @@ var LocalLibrary = class {
5486
5616
  try {
5487
5617
  text2 = await fs.readFile(file, "utf8");
5488
5618
  } catch (err) {
5489
- if (err.code === "ENOENT") throw fail7(404, `${this.spec.label}_not_found`, `No ${this.spec.label} named "${name}".`);
5619
+ if (err.code === "ENOENT") throw fail8(404, `${this.spec.label}_not_found`, `No ${this.spec.label} named "${name}".`);
5490
5620
  throw err;
5491
5621
  }
5492
5622
  if (this.kind !== "skills") return this._fromFile(name, text2);
@@ -5510,10 +5640,10 @@ var LocalLibrary = class {
5510
5640
  async save(item = {}) {
5511
5641
  const { name, description, content } = item;
5512
5642
  this._checkName(name);
5513
- if (this.spec.builtIns[name]) throw fail7(409, "name_reserved", `"${name}" is a built-in ${this.spec.label}; choose another name.`);
5514
- 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.`);
5515
- if (typeof content !== "string" || !content.trim()) throw fail7(400, "content_required", `A ${this.spec.label} needs instructions (content).`);
5516
- if (content.length > MAX_CONTENT) throw fail7(400, "content_too_long", `Instructions are limited to ${MAX_CONTENT.toLocaleString("en")} characters.`);
5643
+ if (this.spec.builtIns[name]) throw fail8(409, "name_reserved", `"${name}" is a built-in ${this.spec.label}; choose another name.`);
5644
+ 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.`);
5645
+ if (typeof content !== "string" || !content.trim()) throw fail8(400, "content_required", `A ${this.spec.label} needs instructions (content).`);
5646
+ if (content.length > MAX_CONTENT) throw fail8(400, "content_too_long", `Instructions are limited to ${MAX_CONTENT.toLocaleString("en")} characters.`);
5517
5647
  const data = { name, description: description.trim().replace(/\s+/g, " ") };
5518
5648
  if (this.kind === "subagents") {
5519
5649
  const tools = normalizeTools(item.tools);
@@ -5529,13 +5659,13 @@ var LocalLibrary = class {
5529
5659
  /** Met l'élément à la corbeille (~/.iagenify/.trash/<horodatage>/…), d'où on peut le récupérer. */
5530
5660
  async remove(name) {
5531
5661
  this._checkName(name);
5532
- if (this.spec.builtIns[name]) throw fail7(400, "builtin_item", `"${name}" is built in and cannot be removed.`);
5662
+ if (this.spec.builtIns[name]) throw fail8(400, "builtin_item", `"${name}" is built in and cannot be removed.`);
5533
5663
  const { fs, path, base: base2, dir } = await this._ready();
5534
5664
  const source = this.kind === "skills" ? path.join(dir, name) : this._file(path, dir, name);
5535
5665
  try {
5536
5666
  await fs.access(source);
5537
5667
  } catch {
5538
- throw fail7(404, `${this.spec.label}_not_found`, `No ${this.spec.label} named "${name}".`);
5668
+ throw fail8(404, `${this.spec.label}_not_found`, `No ${this.spec.label} named "${name}".`);
5539
5669
  }
5540
5670
  const target = path.join(base2, ".trash", (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-"), this.spec.folder, path.basename(source));
5541
5671
  await fs.mkdir(path.dirname(target), { recursive: true });
@@ -5544,15 +5674,15 @@ var LocalLibrary = class {
5544
5674
  }
5545
5675
  /** Skills seulement : un fichier du skill (modèle, référence…), en texte. */
5546
5676
  async readFile(name, file) {
5547
- if (this.kind !== "skills") throw fail7(400, "not_a_skill", "Only skills have files.");
5677
+ if (this.kind !== "skills") throw fail8(400, "not_a_skill", "Only skills have files.");
5548
5678
  const skill = await this.get(name);
5549
5679
  const { fs, path } = await node3();
5550
5680
  const full = path.resolve(skill.folder, String(file || "").replace(/\\/g, "/"));
5551
- if (!full.startsWith(skill.folder + path.sep)) throw fail7(400, "invalid_path", `"${file}" is outside the skill folder.`);
5681
+ if (!full.startsWith(skill.folder + path.sep)) throw fail8(400, "invalid_path", `"${file}" is outside the skill folder.`);
5552
5682
  try {
5553
5683
  return { name: path.basename(full), path: path.relative(skill.folder, full).split(path.sep).join("/"), content: await fs.readFile(full, "utf8") };
5554
5684
  } catch (err) {
5555
- 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"}.`);
5685
+ 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"}.`);
5556
5686
  throw err;
5557
5687
  }
5558
5688
  }
@@ -5627,13 +5757,13 @@ var AgentLibrary = class {
5627
5757
  if (err.status !== 404 || !this.computer) throw err;
5628
5758
  const onDisk = await this.computer.get(name).catch(() => null);
5629
5759
  if (!onDisk) throw err;
5630
- throw fail7(409, "item_on_computer", `\xAB ${name} \xBB est un fichier de cet ordinateur (~/.iagenify/${this.spec.folder}) : supprimez-le sur le disque.`);
5760
+ throw fail8(409, "item_on_computer", `\xAB ${name} \xBB est un fichier de cet ordinateur (~/.iagenify/${this.spec.folder}) : supprimez-le sur le disque.`);
5631
5761
  }
5632
5762
  }
5633
5763
  /** Skills seulement : un fichier annexe. Ceux du compte n'en ont pas — le contenu est le document. */
5634
5764
  async readFile(name, file) {
5635
- if (this.kind !== "skills") throw fail7(400, "not_a_skill", "Only skills have files.");
5636
- 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.`);
5765
+ if (this.kind !== "skills") throw fail8(400, "not_a_skill", "Only skills have files.");
5766
+ 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.`);
5637
5767
  return this.computer.readFile(name, file);
5638
5768
  }
5639
5769
  };
@@ -5649,11 +5779,11 @@ var MAX_OUTPUT2 = 6e4;
5649
5779
  var CALL_TIMEOUT_MS = 6e4;
5650
5780
  var LIST_TIMEOUT_MS = 3e4;
5651
5781
  var MAX_PAGES = 20;
5652
- var fail8 = (status, code, message) => new IaGenifyError(status, code, message);
5782
+ var fail9 = (status, code, message) => new IaGenifyError(status, code, message);
5653
5783
  var CODE_VERSION_NON_SUPPORTEE = -32022;
5654
5784
  var estErreurModerne = (code) => typeof code === "number" && code <= -32020 && code >= -32099;
5655
5785
  var REPLI_ANCIENNE_POIGNEE = /* @__PURE__ */ new Set(["mcp_error", "mcp_http_error", "mcp_bad_response"]);
5656
- var clip4 = (text2, max = MAX_OUTPUT2) => text2.length > max ? `${text2.slice(0, max)}
5786
+ var clip5 = (text2, max = MAX_OUTPUT2) => text2.length > max ? `${text2.slice(0, max)}
5657
5787
  \u2026[truncated ${text2.length - max} characters]` : text2;
5658
5788
  var SCHEMA_TYPES = /* @__PURE__ */ new Set(["string", "number", "integer", "boolean", "array", "object"]);
5659
5789
  var SCHEMA_KEYS = /* @__PURE__ */ new Set(["type", "description", "properties", "required", "items", "enum", "nullable"]);
@@ -5710,7 +5840,7 @@ function cleanToken(value) {
5710
5840
  token = token.replace(/^authorization\s*:\s*/i, "").replace(/^bearer\b\s*/i, "").replace(/^token\s*=\s*/i, "").trim().replace(quotes, "").trim();
5711
5841
  if (!token) return null;
5712
5842
  if (/\s/.test(token)) {
5713
- 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.");
5843
+ 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.");
5714
5844
  }
5715
5845
  return token;
5716
5846
  }
@@ -5786,7 +5916,7 @@ function mirroredParams(schema, args) {
5786
5916
  }
5787
5917
  var McpClient = class {
5788
5918
  constructor({ url, token = null, name = "mcp", fetchImpl = null } = {}) {
5789
- if (!url) throw fail8(400, "url_required", "An MCP server needs its address.");
5919
+ if (!url) throw fail9(400, "url_required", "An MCP server needs its address.");
5790
5920
  this.url = String(url);
5791
5921
  this.token = cleanToken(token);
5792
5922
  this.name = name;
@@ -5848,8 +5978,8 @@ var McpClient = class {
5848
5978
  redirect: "manual"
5849
5979
  });
5850
5980
  } catch (err) {
5851
- if (controller.signal.aborted) throw fail8(504, "mcp_timeout", `\xAB ${this.name} \xBB n'a pas r\xE9pondu en ${Math.round(timeout / 1e3)} s.`);
5852
- throw fail8(502, "mcp_unreachable", `\xAB ${this.name} \xBB est injoignable : ${err.message}`);
5981
+ if (controller.signal.aborted) throw fail9(504, "mcp_timeout", `\xAB ${this.name} \xBB n'a pas r\xE9pondu en ${Math.round(timeout / 1e3)} s.`);
5982
+ throw fail9(502, "mcp_unreachable", `\xAB ${this.name} \xBB est injoignable : ${err.message}`);
5853
5983
  } finally {
5854
5984
  clearTimeout(timer);
5855
5985
  signal?.removeEventListener?.("abort", abort);
@@ -5858,17 +5988,17 @@ var McpClient = class {
5858
5988
  const detail = this._detail(brut);
5859
5989
  if (response.status === 401 || response.status === 403) {
5860
5990
  if (!this.token) {
5861
- throw fail8(401, "mcp_token_required", `\xAB ${this.name} \xBB demande un jeton : ce serveur ne r\xE9pond pas sans authentification.${detail}`);
5991
+ throw fail9(401, "mcp_token_required", `\xAB ${this.name} \xBB demande un jeton : ce serveur ne r\xE9pond pas sans authentification.${detail}`);
5862
5992
  }
5863
- throw fail8(401, "mcp_unauthorized", `\xAB ${this.name} \xBB refuse le jeton (${response.status}). V\xE9rifiez-le, ou recr\xE9ez-en un.${detail}`);
5993
+ throw fail9(401, "mcp_unauthorized", `\xAB ${this.name} \xBB refuse le jeton (${response.status}). V\xE9rifiez-le, ou recr\xE9ez-en un.${detail}`);
5864
5994
  }
5865
5995
  if (response.status >= 300 && response.status < 400) {
5866
- throw fail8(502, "mcp_redirect", `\xAB ${this.name} \xBB redirige vers une autre adresse : reconnectez-le avec l'adresse d\xE9finitive.`);
5996
+ throw fail9(502, "mcp_redirect", `\xAB ${this.name} \xBB redirige vers une autre adresse : reconnectez-le avec l'adresse d\xE9finitive.`);
5867
5997
  }
5868
- if (!response.ok) throw this._rpcError(fail8(502, "mcp_http_error", `\xAB ${this.name} \xBB a r\xE9pondu ${response.status}.${detail}`), brut);
5998
+ if (!response.ok) throw this._rpcError(fail9(502, "mcp_http_error", `\xAB ${this.name} \xBB a r\xE9pondu ${response.status}.${detail}`), brut);
5869
5999
  const message = await this._readMessage(response, id);
5870
6000
  if (message?.error) {
5871
- const err = fail8(502, "mcp_error", `\xAB ${this.name} \xBB refuse : ${String(message.error.message || message.error.code || "erreur").slice(0, 500)}`);
6001
+ const err = fail9(502, "mcp_error", `\xAB ${this.name} \xBB refuse : ${String(message.error.message || message.error.code || "erreur").slice(0, 500)}`);
5872
6002
  err.rpc = { code: message.error.code, data: message.error.data };
5873
6003
  throw err;
5874
6004
  }
@@ -5898,12 +6028,12 @@ var McpClient = class {
5898
6028
  /** La réponse, qu'elle arrive en JSON ou en flux d'événements (`text/event-stream`). */
5899
6029
  async _readMessage(response, id) {
5900
6030
  const type = String(response.headers.get("content-type") || "");
5901
- const body = clip4(await response.text(), 2e6);
6031
+ const body = clip5(await response.text(), 2e6);
5902
6032
  if (!type.includes("text/event-stream")) {
5903
6033
  try {
5904
6034
  return JSON.parse(body);
5905
6035
  } catch {
5906
- throw fail8(502, "mcp_bad_response", `\xAB ${this.name} \xBB n'a pas r\xE9pondu en JSON.`);
6036
+ throw fail9(502, "mcp_bad_response", `\xAB ${this.name} \xBB n'a pas r\xE9pondu en JSON.`);
5907
6037
  }
5908
6038
  }
5909
6039
  let last = null;
@@ -5918,7 +6048,7 @@ var McpClient = class {
5918
6048
  }
5919
6049
  }
5920
6050
  if (last) return last;
5921
- throw fail8(502, "mcp_bad_response", `\xAB ${this.name} \xBB n'a renvoy\xE9 aucune r\xE9ponse exploitable.`);
6051
+ throw fail9(502, "mcp_bad_response", `\xAB ${this.name} \xBB n'a renvoy\xE9 aucune r\xE9ponse exploitable.`);
5922
6052
  }
5923
6053
  /**
5924
6054
  * La poignée de main, dans les deux révisions. Elle dit quelle version le serveur a acceptée.
@@ -5940,7 +6070,7 @@ var McpClient = class {
5940
6070
  const propose = err.rpc?.data?.supportedVersions || err.rpc?.data?.supported;
5941
6071
  const version = negotiateVersion(propose);
5942
6072
  if (!version) {
5943
- throw fail8(
6073
+ throw fail9(
5944
6074
  502,
5945
6075
  "mcp_protocol_unsupported",
5946
6076
  `\xAB ${this.name} \xBB ne parle aucune r\xE9vision que ce client conna\xEEt (il propose ${[].concat(propose || []).join(", ") || "rien"}).`
@@ -5971,7 +6101,7 @@ var McpClient = class {
5971
6101
  const found = await this._rpc("server/discover", {}, { signal });
5972
6102
  const version = negotiateVersion(found.supportedVersions);
5973
6103
  if (found.supportedVersions && !version) {
5974
- throw fail8(
6104
+ throw fail9(
5975
6105
  502,
5976
6106
  "mcp_protocol_unsupported",
5977
6107
  `\xAB ${this.name} \xBB ne parle aucune r\xE9vision que ce client conna\xEEt (il propose ${[].concat(found.supportedVersions).join(", ")}).`
@@ -6023,7 +6153,7 @@ var McpClient = class {
6023
6153
  return part?.text ? String(part.text) : "";
6024
6154
  }).filter(Boolean).join("\n");
6025
6155
  const output = text2 || (result.structuredContent ? JSON.stringify(result.structuredContent) : "(aucun contenu)");
6026
- return { output: clip4(output), isError: Boolean(result.isError) };
6156
+ return { output: clip5(output), isError: Boolean(result.isError) };
6027
6157
  }
6028
6158
  };
6029
6159
  var McpResource = class {
@@ -6433,6 +6563,7 @@ var TOOL_FAMILIES = [
6433
6563
  ["Storages", ["query_storage", "write_storage"]],
6434
6564
  ["The account", ["account", "cloud"]],
6435
6565
  ["Put online and communicate", ["deploy", "domain", "mail", "send_mail"]],
6566
+ ["Design", ["design_read", "design_apply", "design_render", "design_check", "design_template"]],
6436
6567
  ["The platform itself", ["iagenify_docs", "workflow", "mcp"]],
6437
6568
  ["Ask another model", ["generate"]],
6438
6569
  ["This conversation", ["todo_write", "ask_user", "memory", "recall", "skill", "task"]]
@@ -6612,9 +6743,9 @@ var SUBAGENT_MAX_STEPS = 40;
6612
6743
  var MAX_SKILL_OUTPUT = 6e4;
6613
6744
  var withoutAttachments = (messages) => messages.map(({ attachments, images, ...m }) => attachments?.length || images?.length ? { ...m, content: `${m.content || ""} [${(attachments || images).length} file(s) attached]` } : m);
6614
6745
  var estimateTokens = (messages) => Math.ceil(JSON.stringify(withoutAttachments(messages)).length / 4);
6615
- var clip5 = (text2, max) => text2.length > max ? `${text2.slice(0, max)}
6746
+ var clip6 = (text2, max) => text2.length > max ? `${text2.slice(0, max)}
6616
6747
  \u2026[truncated ${text2.length - max} characters]` : text2;
6617
- var fail9 = (message) => {
6748
+ var fail10 = (message) => {
6618
6749
  throw new IaGenifyError(400, "tool_error", message);
6619
6750
  };
6620
6751
  var KEEP_ATTACHMENTS_FOR = 6;
@@ -6965,11 +7096,11 @@ var LocalAgent = class _LocalAgent {
6965
7096
  const notes = await this.api.memory.list();
6966
7097
  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` };
6967
7098
  }
6968
- if (!name) fail9("memory needs a name.");
7099
+ if (!name) fail10("memory needs a name.");
6969
7100
  if (action === "read") {
6970
7101
  const notes = await this.api.memory.list();
6971
7102
  const note = notes.find((n) => n.name === name);
6972
- if (!note) fail9(`No memory called "${name}". Listed names: ${notes.map((n) => n.name).join(", ") || "none"}.`);
7103
+ if (!note) fail10(`No memory called "${name}". Listed names: ${notes.map((n) => n.name).join(", ") || "none"}.`);
6973
7104
  return { output: `# ${note.name}
6974
7105
  ${note.description}
6975
7106
 
@@ -6980,7 +7111,7 @@ ${note.content}`, summary: note.name, meta: { memory: note.name } };
6980
7111
  this.memories = this.memories.filter((n) => n.name !== name);
6981
7112
  return { output: `Memory "${name}" deleted.`, summary: name, meta: { memory: name, deleted: true } };
6982
7113
  }
6983
- if (!content.trim()) fail9("memory save needs content.");
7114
+ if (!content.trim()) fail10("memory save needs content.");
6984
7115
  const saved = await this.api.memory.save({ name, description, content, type, source: "agent", ...this.memory ? { sessionId: this.id } : {} });
6985
7116
  this.memories = [saved, ...this.memories.filter((n) => n.name !== saved.name)];
6986
7117
  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 } };
@@ -7014,19 +7145,19 @@ ${note.content}`, summary: note.name, meta: { memory: note.name } };
7014
7145
  file: { type: "string", description: "Optional: one of the skill's files, as listed when it is loaded" }
7015
7146
  }),
7016
7147
  run: async ({ name, file }) => {
7017
- if (!this.library.skills.some((s) => s.name === name)) fail9(`Unknown skill "${name}". Available: ${this.library.skills.map((s) => s.name).join(", ")}.`);
7148
+ if (!this.library.skills.some((s) => s.name === name)) fail10(`Unknown skill "${name}". Available: ${this.library.skills.map((s) => s.name).join(", ")}.`);
7018
7149
  const library = this._library("skills");
7019
- if (!library) fail9("No skills are available here.");
7150
+ if (!library) fail10("No skills are available here.");
7020
7151
  if (file) {
7021
7152
  const read = await library.readFile(name, file);
7022
- return { output: clip5(read.content, MAX_SKILL_OUTPUT) || "(empty file)", summary: `${name} \xB7 ${read.path}`, meta: { skill: name, file: read.path } };
7153
+ return { output: clip6(read.content, MAX_SKILL_OUTPUT) || "(empty file)", summary: `${name} \xB7 ${read.path}`, meta: { skill: name, file: read.path } };
7023
7154
  }
7024
7155
  const skill = await library.get(name);
7025
7156
  const files = skill.files?.length ? `
7026
7157
 
7027
7158
  Files in this skill (read one with skill + file): ${skill.files.join(", ")}${skill.folder ? `
7028
7159
  Folder on this computer, for commands: ${skill.folder}` : ""}` : "";
7029
- return { output: clip5(`# Skill: ${name}
7160
+ return { output: clip6(`# Skill: ${name}
7030
7161
 
7031
7162
  ${skill.content}${files}`, MAX_SKILL_OUTPUT), summary: `Loaded ${name}`, meta: { skill: name, files: skill.files?.length || 0 } };
7032
7163
  }
@@ -7045,8 +7176,8 @@ ${skill.content}${files}`, MAX_SKILL_OUTPUT), summary: `Loaded ${name}`, meta: {
7045
7176
  }
7046
7177
  /** Lance un sous-agent : même machine, même mode, mêmes permissions, budget et crédits partagés avec ce run. */
7047
7178
  async _runSubagent({ agent: name, description = "", prompt }, call) {
7048
- if (!this.library.subagents.some((a) => a.name === name)) fail9(`Unknown subagent "${name}". Available: ${this.library.subagents.map((a) => a.name).join(", ")}.`);
7049
- if (!String(prompt || "").trim()) fail9("task needs a prompt: the subagent sees nothing of this conversation.");
7179
+ if (!this.library.subagents.some((a) => a.name === name)) fail10(`Unknown subagent "${name}". Available: ${this.library.subagents.map((a) => a.name).join(", ")}.`);
7180
+ if (!String(prompt || "").trim()) fail10("task needs a prompt: the subagent sees nothing of this conversation.");
7050
7181
  const definition = await this._definition("subagents", name);
7051
7182
  const wanted = !definition.tools || definition.tools === "all" ? WORKSPACE_TOOL_NAMES : definition.tools;
7052
7183
  const tools = wanted.filter((t) => this.toolNames.includes(t) && !PARENT_ONLY_TOOLS.has(t));
@@ -7096,7 +7227,7 @@ ${skill.content}${files}`, MAX_SKILL_OUTPUT), summary: `Loaded ${name}`, meta: {
7096
7227
 
7097
7228
  [${name} subagent \xB7 ${turns} turns \xB7 ${toolCalls} tool calls \xB7 ${credits} credits${ended}]`,
7098
7229
  summary: description || name,
7099
- meta: { agent: name, description, model: child.model, turns, toolCalls, credits, stopReason: result.stopReason, report: clip5(result.text || "", 4e3) }
7230
+ meta: { agent: name, description, model: child.model, turns, toolCalls, credits, stopReason: result.stopReason, report: clip6(result.text || "", 4e3) }
7100
7231
  };
7101
7232
  } finally {
7102
7233
  this.children.delete(child);
@@ -7127,7 +7258,7 @@ Files in this skill (read one with skill + file): ${skill.files.join(", ")}` : "
7127
7258
 
7128
7259
  # Skill: ${name}
7129
7260
 
7130
- ${clip5(skill.content, MAX_SKILL_OUTPUT)}${files}
7261
+ ${clip6(skill.content, MAX_SKILL_OUTPUT)}${files}
7131
7262
 
7132
7263
  # Request
7133
7264
  ${args || "Apply this skill."}`;
@@ -7190,13 +7321,13 @@ ${args || "Apply this skill."}`;
7190
7321
  const read = await this.catalog.read.run({ path }, { files });
7191
7322
  if (read.attachments?.length) images.push(...read.attachments.map((a) => ({ mime: a.mime, data: a.data })));
7192
7323
  sections.push(`## @${read.meta?.path || path}
7193
- ${read.attachments?.length ? read.output : clip5(read.output, 3e4)}`);
7324
+ ${read.attachments?.length ? read.output : clip6(read.output, 3e4)}`);
7194
7325
  emit({ type: "mention", kind: "file", path: read.meta?.path || path });
7195
7326
  } catch {
7196
7327
  try {
7197
7328
  const list = await this.catalog.list.run({ path }, { files });
7198
7329
  sections.push(`## @${path} (folder)
7199
- ${clip5(list.output, 8e3)}`);
7330
+ ${clip6(list.output, 8e3)}`);
7200
7331
  emit({ type: "mention", kind: "folder", path });
7201
7332
  } catch {
7202
7333
  }
@@ -7207,7 +7338,7 @@ ${clip5(list.output, 8e3)}`);
7207
7338
  try {
7208
7339
  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 });
7209
7340
  sections.push(`## #${s.name}${s.collection ? ` \xB7 ${s.collection}` : ""}
7210
- ${clip5(read.output, 8e3)}`);
7341
+ ${clip6(read.output, 8e3)}`);
7211
7342
  emit({ type: "mention", kind: "storage", storage: s.name, collection: s.collection });
7212
7343
  } catch (err) {
7213
7344
  sections.push(`## #${s.name}${s.collection ? ` \xB7 ${s.collection}` : ""}
@@ -10368,8 +10499,8 @@ var StudioDocument = class {
10368
10499
  }
10369
10500
  };
10370
10501
 
10371
- // src/resources/studio.js
10372
- var base = "/api/studio";
10502
+ // src/resources/design.js
10503
+ var base = "/api/design";
10373
10504
  var projectPath = (id) => `${base}/projects/${encodeURIComponent(id)}`;
10374
10505
  var byType = (path, type) => type === void 0 ? path : `${path}?type=${encodeURIComponent(type)}`;
10375
10506
  var StudioProject = class _StudioProject {
@@ -10416,8 +10547,11 @@ var StudioProject = class _StudioProject {
10416
10547
  Object.assign(this, project);
10417
10548
  return this;
10418
10549
  }
10550
+ async render({ frame, width, height } = {}) {
10551
+ return this.#client.post(`${projectPath(this.id)}/render`, { frame, width, height }, { timeout: 0 });
10552
+ }
10419
10553
  };
10420
- var StudioResource = class {
10554
+ var DesignResource = class {
10421
10555
  constructor(client) {
10422
10556
  const wrap = (data) => new StudioProject(client, data);
10423
10557
  this.templates = {
@@ -10529,7 +10663,7 @@ var IaGenify = class {
10529
10663
  this.mail = new MailResource(this._client);
10530
10664
  this.hosts = new HostsResource(this._client);
10531
10665
  this.compute = new ComputeResource(this._client);
10532
- this.studio = new StudioResource(this._client);
10666
+ this.design = new DesignResource(this._client);
10533
10667
  }
10534
10668
  async getUser() {
10535
10669
  const res = await this._client.get("/api/auth/me");