@monoclaw/machine 1.0.20 → 1.0.22

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/cli.js CHANGED
@@ -749,13 +749,16 @@ import { z as z3 } from "zod";
749
749
  // ../../packages/protocol/src/modules.ts
750
750
  import { z as z2 } from "zod";
751
751
  var ModuleCapability = z2.enum(["agent", "tts", "stt", "image"]);
752
- var MODULE_IDS = ["claude-subscription", "claude-api", "parakeet", "kokoro", "elevenlabs", "fal", "echo"];
753
- var ModuleId = z2.enum(MODULE_IDS);
752
+ var ModuleId = z2.string().regex(/^[a-z][a-z0-9-]{1,40}$/);
754
753
  var OptionChoice = z2.object({ value: z2.string(), label: z2.string(), group: z2.string().optional(), description: z2.string().optional() });
755
754
  var OptionField = z2.object({
756
755
  key: z2.string().regex(/^[a-z][a-z0-9_]{0,40}$/),
757
756
  label: z2.string(),
758
- type: z2.enum(["select", "number", "boolean", "text"]),
757
+ /**
758
+ * One of `OPTION_FIELD_TYPES`, open on the wire: a newer module's new type must not fail the frame it travels in on
759
+ * an older server or app (docs/spec/modules.md § 5), which draw a type they do not know as a text field.
760
+ */
761
+ type: z2.string(),
759
762
  choices: z2.array(OptionChoice).optional(),
760
763
  min: z2.number().optional(),
761
764
  max: z2.number().optional(),
@@ -764,7 +767,11 @@ var OptionField = z2.object({
764
767
  help: z2.string().optional(),
765
768
  required: z2.boolean().default(false),
766
769
  /** For an `image` tool: whether the agent may set this per call (the rest are fixed by the owner). */
767
- agentSettable: z2.boolean().optional()
770
+ agentSettable: z2.boolean().optional(),
771
+ /** A heading the field is drawn under (docs/spec/modules.md § 5). */
772
+ section: z2.string().optional(),
773
+ /** Drawn only while another field has a value. */
774
+ showWhen: z2.object({ key: z2.string(), equals: z2.union([z2.string(), z2.number(), z2.boolean()]) }).optional()
768
775
  });
769
776
  var ModuleState = z2.enum(["installing", "ready", "needs_setup", "error"]);
770
777
  var ModuleReport = z2.object({
@@ -781,7 +788,13 @@ var ModuleReport = z2.object({
781
788
  /** 0–1 while installing (a model download), else null. */
782
789
  progress: z2.number().min(0).max(1).nullable().default(null),
783
790
  /** One plain line: "Ready", "Downloading models (42%)", "Add an API key". */
784
- summary: z2.string().default("")
791
+ summary: z2.string().default(""),
792
+ /**
793
+ * What the module declares about itself (machine programs from 1.0.21; docs/spec/modules.md § 3), as the module wrote
794
+ * it: `unknown` on the wire, so one manifest that cannot be read never fails the frame it travels in. The server lints
795
+ * each one on its own (`lintManifest`) and keeps a bad one out, reported (§ 11.15); the machine's own tests lint its own.
796
+ */
797
+ manifest: z2.unknown().optional()
785
798
  });
786
799
  var ModuleSetupStep = z2.object({
787
800
  title: z2.string(),
@@ -801,7 +814,9 @@ var CatalogueEntry = z2.object({
801
814
  /** Approximate download on install (models, native libraries), MB. */
802
815
  downloadMb: z2.number().nullable(),
803
816
  /** How to install and configure it by hand on this machine (the web's Install manually). */
804
- setup: z2.array(ModuleSetupStep).default([])
817
+ setup: z2.array(ModuleSetupStep).default([]),
818
+ /** The module's manifest (machine programs from 1.0.21), `unknown` on the wire as on `ModuleReport`. */
819
+ manifest: z2.unknown().optional()
805
820
  });
806
821
  var JobUsage = z2.object({ amount: z2.number().nonnegative(), unit: z2.enum(["characters", "seconds", "images", "tokens"]), costUsd: z2.number().nonnegative().optional() });
807
822
  var JobInput = z2.discriminatedUnion("capability", [
@@ -809,6 +824,8 @@ var JobInput = z2.discriminatedUnion("capability", [
809
824
  /** The host downloads the audio from the signed URL. */
810
825
  z2.object({ capability: z2.literal("stt"), url: z2.string(), mime: z2.string() }),
811
826
  /** `reference` (hosts from 1.0.15): one image to make the new one from or in the style of; the host downloads it from the signed URL. */
827
+ /** A module tool through the one door (machine programs from 1.0.21; docs/spec/modules.md § 9): the declared input, and the files it names, each at a signed URL the machine downloads. */
828
+ z2.object({ capability: z2.literal("tool"), tool: z2.string(), input: z2.record(z2.string(), z2.unknown()), files: z2.array(z2.object({ field: z2.string(), url: z2.string(), mime: z2.string(), name: z2.string() })).default([]) }),
812
829
  z2.object({ capability: z2.literal("image"), prompt: z2.string().min(1).max(1e4), args: z2.record(z2.string(), z2.union([z2.string(), z2.number(), z2.boolean()])).default({}), reference: z2.object({ url: z2.string(), mime: z2.string() }).optional() })
813
830
  ]);
814
831
  var JobOutput = z2.object({ uploadId: z2.string(), mime: z2.string(), name: z2.string().optional(), durationMs: z2.number().int().nonnegative().optional(), width: z2.number().int().positive().optional(), height: z2.number().int().positive().optional() });
@@ -866,7 +883,9 @@ var ProviderAccountReport = z3.object({
866
883
  /** The module this connection belongs to. */
867
884
  module: ModuleId,
868
885
  type: ProviderAccountType,
869
- readiness: ProviderReadiness
886
+ readiness: ProviderReadiness,
887
+ /** The connection's monthly cap, as set on the machine or by the server (machine programs from 1.0.22). */
888
+ settings: z3.object({ monthlyCapUsd: z3.number().optional(), monthlyCapCharacters: z3.number().optional() }).optional()
870
889
  });
871
890
  var ModelInfo = z3.object({ id: z3.string(), name: z3.string(), description: z3.string().default("") });
872
891
  var CommandInfo = z3.object({ name: z3.string(), description: z3.string().default(""), argumentHint: z3.string().default("") });
@@ -1193,7 +1212,8 @@ var RouterFrame = z4.discriminatedUnion("t", [
1193
1212
  /** Remove a module and its connections (and their keys). */
1194
1213
  z4.object({ t: z4.literal("module.remove"), reqId: z4.string(), module: ModuleId }),
1195
1214
  /** The options a module offers for one use (`agent` for an agent's engine, `tts` a voice, `stt` transcription, `image` a tool). */
1196
- z4.object({ t: z4.literal("module.options"), reqId: z4.string(), module: ModuleId, connectionId: z4.string().optional(), capability: z4.enum(["agent", "tts", "stt", "image"]) }),
1215
+ /** `use` (servers from contract 3.35+, machines from 1.0.21): `agent`, `speech`, `transcription` or `tool:<name>`; `capability` is the old word, still sent and still understood. */
1216
+ z4.object({ t: z4.literal("module.options"), reqId: z4.string(), module: ModuleId, connectionId: z4.string().optional(), capability: z4.enum(["agent", "tts", "stt", "image"]), use: z4.string().optional() }),
1197
1217
  /**
1198
1218
  * Do one piece of work with a module and a connection, with the owner's options. Answered with `job.result`. A
1199
1219
  * text-to-speech job is one chapter; the server sends a message's chapters one after another.
@@ -1203,6 +1223,11 @@ var RouterFrame = z4.discriminatedUnion("t", [
1203
1223
  * The answer to a `tool.call`, a `tool.use` or a `tools.find`: the tool's text for the agent, and the files it made, which the agent's host saves in
1204
1224
  * the agent's folder (under `images/`).
1205
1225
  */
1226
+ /**
1227
+ * The server received a `tool.use` and is running it (machine programs from 1.0.22). `readOnly`: the tool only reads, so
1228
+ * if the connection is lost before the result the call is safe to repeat; otherwise the agent is told it may have run.
1229
+ */
1230
+ z4.object({ t: z4.literal("tool.started"), groupId: z4.string(), id: z4.string(), readOnly: z4.boolean() }),
1206
1231
  z4.object({
1207
1232
  t: z4.literal("tool.result"),
1208
1233
  groupId: z4.string(),
@@ -1229,7 +1254,15 @@ var RouterFrame = z4.discriminatedUnion("t", [
1229
1254
  /** A client's one-shot envelope with the account's secret, sealed to the host's public key; relayed once, never stored. */
1230
1255
  z4.object({ t: z4.literal("provider_account.secret"), id: z4.string(), envelope: z4.string() }),
1231
1256
  /** Rename an account or change its allowed folders (the host keeps its own copy and enforces the folders). */
1232
- z4.object({ t: z4.literal("provider_account.update"), id: z4.string(), name: z4.string().optional(), allowedFolders: z4.array(z4.string()).optional() }),
1257
+ z4.object({
1258
+ t: z4.literal("provider_account.update"),
1259
+ id: z4.string(),
1260
+ name: z4.string().optional(),
1261
+ allowedFolders: z4.array(z4.string()).optional(),
1262
+ /** A monthly cap on the key (machine programs from 1.0.22; docs/spec/modules.md § 6): a number sets it, null clears it, absent leaves it. */
1263
+ monthlyCapUsd: z4.number().positive().nullable().optional(),
1264
+ monthlyCapCharacters: z4.number().int().positive().nullable().optional()
1265
+ }),
1233
1266
  /** Forget an account and its secret. */
1234
1267
  z4.object({ t: z4.literal("provider_account.remove"), id: z4.string() }),
1235
1268
  /** Re-check an account's readiness now; answered with `provider_account.readiness`. */
@@ -1372,10 +1405,88 @@ var IMAGE_VIEW = {
1372
1405
  example: { image: "attachment:att_01HZY4K2M7Q8R9S0T1U2V3W4X5" }
1373
1406
  };
1374
1407
 
1408
+ // ../../packages/protocol/src/manifest.ts
1409
+ import { z as z9 } from "zod";
1410
+ var MODULE_ID_PATTERN = /^[a-z][a-z0-9-]{1,40}$/;
1411
+ var TOOL_NAME_PATTERN = /^[a-z][a-z0-9_]{2,63}$/;
1412
+ var ModuleUse = z9.string().regex(/^(agent|speech|transcription|tool:[a-z][a-z0-9_]{2,63})$/);
1413
+ function useFromCapability(capability, imageTool) {
1414
+ if (capability === "agent") return "agent";
1415
+ if (capability === "tts") return "speech";
1416
+ if (capability === "stt") return "transcription";
1417
+ return `tool:${imageTool ?? "image"}`;
1418
+ }
1419
+ var JsonSchema = z9.record(z9.string(), z9.unknown());
1420
+ var ToolDeclaration = z9.object({
1421
+ name: z9.string().regex(TOOL_NAME_PATTERN),
1422
+ title: z9.string().min(1).max(60),
1423
+ description: z9.string().min(1),
1424
+ /** A JSON Schema object with flat properties (`jsonSchemaToZod` says what is allowed). */
1425
+ input: JsonSchema,
1426
+ /** Input fields that name a file: a path the agent's machine uploads, or `attachment:<id>`. */
1427
+ files: z9.array(z9.object({ field: z9.string(), accept: z9.array(z9.string()).min(1), maxMb: z9.number().positive() })).default([]),
1428
+ /** Whether the use `tool:<name>` has settings (§ 5); agent-settable ones are merged into the input. */
1429
+ settings: z9.boolean().default(false),
1430
+ example: z9.record(z9.string(), z9.unknown()),
1431
+ risk: z9.object({ costs: z9.boolean(), writes: z9.boolean(), sends: z9.boolean(), ask: z9.enum(["never", "always"]) }),
1432
+ labels: z9.object({ running: z9.string().min(1).max(40), done: z9.string().min(1).max(40) }),
1433
+ result: z9.object({ views: z9.array(z9.string()).min(1) }),
1434
+ timeoutMs: z9.number().int().positive().max(9e5)
1435
+ });
1436
+ var ModuleManifest = z9.object({
1437
+ manifestVersion: z9.literal(1),
1438
+ id: z9.string().regex(MODULE_ID_PATTERN),
1439
+ version: z9.string().regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/),
1440
+ name: z9.string().min(1).max(60),
1441
+ summary: z9.string().min(1).max(200),
1442
+ description: z9.string().optional(),
1443
+ /** Unknown values show under Other. */
1444
+ category: z9.string().default("other"),
1445
+ publisher: z9.object({ name: z9.string(), tier: z9.enum(["monoclaw", "verified", "custom"]) }).optional(),
1446
+ /** A local model on the machine, or a service on the internet. */
1447
+ runs: z9.enum(["local", "service"]),
1448
+ needs: z9.object({
1449
+ downloadMb: z9.number().nonnegative().optional(),
1450
+ diskMb: z9.number().nonnegative().optional(),
1451
+ memoryMb: z9.number().nonnegative().optional(),
1452
+ gpu: z9.boolean().optional(),
1453
+ programs: z9.array(z9.object({ name: z9.string(), why: z9.string(), install: z9.object({ darwin: z9.string().optional(), linux: z9.string().optional(), win32: z9.string().optional() }) })).optional()
1454
+ }).optional(),
1455
+ /**
1456
+ * The credential a module needs: none; an API key (one field, pasted, sealed to the machine); or a login the machine's
1457
+ * own sign-in provides (no field is asked). `several`: more than one key may be added.
1458
+ */
1459
+ key: z9.object({
1460
+ kind: z9.enum(["api_key", "login"]),
1461
+ label: z9.string(),
1462
+ placeholder: z9.string().optional(),
1463
+ pageUrl: z9.string().optional(),
1464
+ pattern: z9.string().optional(),
1465
+ patternHelp: z9.string().optional(),
1466
+ several: z9.boolean()
1467
+ }).nullable().default(null),
1468
+ cost: z9.object({ unit: z9.enum(["usd", "characters"]), suggestedMonthlyCap: z9.number().positive(), note: z9.string() }).nullable().default(null),
1469
+ provides: z9.object({
1470
+ agent: z9.object({ providerId: z9.string() }).optional(),
1471
+ jobs: z9.array(z9.enum(["speech", "transcription"])).default([]),
1472
+ tools: z9.array(ToolDeclaration).default([])
1473
+ }),
1474
+ /** "Install manually", as today: the module writes its own steps for the machine. */
1475
+ setup: z9.array(z9.object({ title: z9.string(), command: z9.string().optional(), detail: z9.string().optional(), link: z9.object({ label: z9.string(), url: z9.string() }).optional() })).default([])
1476
+ });
1477
+
1375
1478
  // src/modules/index.ts
1376
1479
  import path11 from "node:path";
1377
1480
 
1378
1481
  // src/modules/types.ts
1482
+ var connectionTypeOf = (m) => m.manifest.key ? m.manifest.key.kind === "login" ? "subscription" : "api_key" : "local";
1483
+ var multipleConnectionsOf = (m) => !!m.manifest.key?.several;
1484
+ var legacyKindOf = (m) => m.manifest.runs === "service" ? "api" : "local";
1485
+ var needsSecretOf = (m) => m.manifest.key?.kind === "api_key";
1486
+ var moduleNameOf = (m) => m.manifest.name;
1487
+ var legacyCatalogueOf = (m) => ({ id: m.id, name: m.manifest.name, description: m.manifest.summary, capabilities: m.legacyCapabilities, kind: legacyKindOf(m), needsSecret: needsSecretOf(m), downloadMb: m.manifest.needs?.downloadMb ?? null });
1488
+ var toolOf = (m, name) => m.manifest.provides.tools.find((t) => t.name === name) ?? null;
1489
+ var imageToolOf = (m) => m.manifest.provides.tools.find((t) => t.result.views.includes("images"))?.name;
1379
1490
  function resolveOptions(fields, options, args2 = {}) {
1380
1491
  const out = {};
1381
1492
  for (const f of fields) if (f.default !== void 0) out[f.key] = f.default;
@@ -1431,9 +1542,19 @@ function claudeSubscriptionModule(probe) {
1431
1542
  return {
1432
1543
  id: "claude-subscription",
1433
1544
  version: "1.0.0",
1434
- catalogue: { id: "claude-subscription", name: "Claude (subscription)", description: "Agents run Claude Code with this machine's own Claude login, on your Claude subscription.", capabilities: ["agent"], kind: "local", needsSecret: false, downloadMb: null },
1435
- multipleConnections: false,
1436
- connectionType: "subscription",
1545
+ manifest: {
1546
+ manifestVersion: 1,
1547
+ id: "claude-subscription",
1548
+ name: "Claude (subscription)",
1549
+ summary: "Your agents run on Claude Code with this machine's own Claude login, on your Claude subscription.",
1550
+ category: "agents",
1551
+ publisher: { name: "MonoClaw", tier: "monoclaw" },
1552
+ runs: "local",
1553
+ key: { kind: "login", label: "Claude login", several: false },
1554
+ cost: null,
1555
+ provides: { agent: { providerId: "claude" }, jobs: [], tools: [] }
1556
+ },
1557
+ legacyCapabilities: ["agent"],
1437
1558
  providerId: "claude",
1438
1559
  defaultConnection: { id: "claude", name: "Claude Code" },
1439
1560
  status: () => ({ state: "ready", progress: null, summary: "" }),
@@ -1446,9 +1567,19 @@ function claudeApiModule(probe) {
1446
1567
  return {
1447
1568
  id: "claude-api",
1448
1569
  version: "1.0.0",
1449
- catalogue: { id: "claude-api", name: "Claude (API key)", description: "Agents run Claude Code with an Anthropic API key, billed to that key. Add one key per team or budget.", capabilities: ["agent"], kind: "api", needsSecret: true, downloadMb: null },
1450
- multipleConnections: true,
1451
- connectionType: "api_key",
1570
+ manifest: {
1571
+ manifestVersion: 1,
1572
+ id: "claude-api",
1573
+ name: "Claude (API key)",
1574
+ summary: "Your agents run on Claude Code with an Anthropic API key, billed to that key. Add one key per team or budget.",
1575
+ category: "agents",
1576
+ publisher: { name: "MonoClaw", tier: "monoclaw" },
1577
+ runs: "service",
1578
+ key: { kind: "api_key", label: "Anthropic API key", placeholder: "sk-ant-api03-\u2026", pageUrl: "https://console.anthropic.com/settings/keys", pattern: "^sk-ant-", patternHelp: "An Anthropic API key starts with sk-ant-.", several: true },
1579
+ cost: { unit: "usd", suggestedMonthlyCap: 20, note: "Billed to the key by Anthropic, by tokens used; the cap stops this machine's agents at the amount you set." },
1580
+ provides: { agent: { providerId: "claude" }, jobs: [], tools: [] }
1581
+ },
1582
+ legacyCapabilities: ["agent"],
1452
1583
  providerId: "claude",
1453
1584
  status: () => ({ state: "ready", progress: null, summary: "" }),
1454
1585
  checkKey: (key) => ANTHROPIC_KEY_RE.test(key) ? null : "That does not look like an Anthropic API key; it starts with sk-ant-.",
@@ -1462,6 +1593,70 @@ function claudeApiModule(probe) {
1462
1593
  };
1463
1594
  }
1464
1595
 
1596
+ // src/modules/declare.ts
1597
+ var FFMPEG = { name: "ffmpeg", why: "uses ffmpeg to read and write audio. Check with `ffmpeg -version`.", install: { darwin: "brew install ffmpeg", linux: "sudo apt install -y ffmpeg # or your distribution's package manager", win32: "winget install --id Gyan.FFmpeg -e" } };
1598
+ var SPEAK_MAX_CHARS = 9e3;
1599
+ function speakTool(name, service2, costs) {
1600
+ return {
1601
+ name,
1602
+ title: "Make audio",
1603
+ description: `Makes spoken audio from text with ${service2}, in the voice set for it.${costs ? ` Each call costs money on the ${service2} key, by the characters spoken.` : ""} Use it when a person asks for something read aloud, a voice note, a narration or a spoken summary. Do not use it to answer in the chat: your replies are spoken for you when the agent has a voice. One call takes up to ${SPEAK_MAX_CHARS.toLocaleString("en-GB")} characters, about ten minutes of speech; make a longer piece in parts. Returns the audio as an attachment id (and as a file under audio/ in your folder when you have full access); people can play it from your steps.`,
1604
+ input: { type: "object", properties: { text: { type: "string", description: "The text to speak", minLength: 1, maxLength: SPEAK_MAX_CHARS } }, required: ["text"], additionalProperties: false },
1605
+ files: [],
1606
+ settings: true,
1607
+ example: { text: "Good morning. Here is today's summary." },
1608
+ risk: { costs, writes: false, sends: false, ask: "never" },
1609
+ labels: { running: "Making audio", done: "Made audio" },
1610
+ result: { views: ["audio", "text"] },
1611
+ timeoutMs: 3e5
1612
+ };
1613
+ }
1614
+ function transcribeTool(name, service2, costs) {
1615
+ return {
1616
+ name,
1617
+ title: "Transcribe a recording",
1618
+ description: `Transcribes an audio or video file with ${service2} and returns the transcript as text.${costs ? ` Each call costs money on the ${service2} key, by the minutes transcribed.` : ""} Use it when a person gives you a recording to write up, or when you need the words of an audio file in the conversation (name it as attachment:<id>). Do not use it on a voice message that already shows its transcript. The file can be at most 20 MB; a path is a file on your machine, which is uploaded first.`,
1619
+ input: { type: "object", properties: { file: { type: "string", description: "The audio or video file: a path, or attachment:<id>", minLength: 1 } }, required: ["file"], additionalProperties: false },
1620
+ files: [{ field: "file", accept: ["audio/*", "video/*"], maxMb: 20 }],
1621
+ settings: true,
1622
+ example: { file: "recordings/interview.m4a" },
1623
+ risk: { costs, writes: false, sends: false, ask: "never" },
1624
+ labels: { running: "Transcribing", done: "Transcribed a recording" },
1625
+ result: { views: ["text"] },
1626
+ timeoutMs: 6e5
1627
+ };
1628
+ }
1629
+ function settableArgs(fields, input) {
1630
+ const out = {};
1631
+ for (const f of fields) {
1632
+ const v = input[f.key];
1633
+ if (f.agentSettable && (typeof v === "string" || typeof v === "number" || typeof v === "boolean")) out[f.key] = v;
1634
+ }
1635
+ return out;
1636
+ }
1637
+ function unknownTool(moduleName, name, tools) {
1638
+ return new Error(`${moduleName} has no tool "${name}". Its tools: ${tools.map((t) => t.name).join(", ") || "none"}.`);
1639
+ }
1640
+ var mmss = (ms) => {
1641
+ const s = Math.round(ms / 1e3);
1642
+ return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
1643
+ };
1644
+ function audioWords(out) {
1645
+ const ms = out.files.reduce((n, f) => n + (f.durationMs ?? 0), 0);
1646
+ return ms > 0 ? `Made ${mmss(ms)} of audio.` : "Made audio.";
1647
+ }
1648
+ function transcriptWords(out, fileName, moduleName) {
1649
+ const text2 = (out.text ?? "").trim();
1650
+ if (!text2) return `${fileName} has no speech that ${moduleName} could hear.`;
1651
+ return `Transcript of ${fileName}${out.language ? ` (${out.language})` : ""}:
1652
+
1653
+ ${text2}`;
1654
+ }
1655
+ function imageWords(out) {
1656
+ const n = out.files.length;
1657
+ return n === 0 ? "Made no image." : `Made ${n} image${n === 1 ? "" : "s"}.`;
1658
+ }
1659
+
1465
1660
  // src/modules/echo.ts
1466
1661
  var PIXEL = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==", "base64");
1467
1662
  function silentWav(durationMs, voice) {
@@ -1497,17 +1692,86 @@ var IMAGE_FIELDS = [
1497
1692
  var echoModule = {
1498
1693
  id: "echo",
1499
1694
  version: "1.0.0",
1500
- catalogue: { id: "echo", name: "Echo (test)", description: "Repeats what you say, and fakes voices, transcripts and images. For testing without a model.", capabilities: ["agent", "tts", "stt", "image"], kind: "local", needsSecret: false, downloadMb: null },
1501
- multipleConnections: false,
1502
- connectionType: "local",
1695
+ manifest: {
1696
+ manifestVersion: 1,
1697
+ id: "echo",
1698
+ name: "Echo (test)",
1699
+ summary: "Repeats what you say, and fakes voices, transcripts and images. For testing without a model.",
1700
+ category: "other",
1701
+ publisher: { name: "MonoClaw", tier: "monoclaw" },
1702
+ runs: "local",
1703
+ key: null,
1704
+ cost: null,
1705
+ provides: {
1706
+ agent: { providerId: "echo" },
1707
+ jobs: ["speech", "transcription"],
1708
+ tools: [
1709
+ {
1710
+ name: "echo_image",
1711
+ title: "Make a test image",
1712
+ description: "Makes one or more tiny test images from a description, with no model behind it. Use it in tests when an image tool's path is to be exercised end to end. Do not use it for a real picture: it is a single pixel. Returns each image as an attachment id; people see the images in your steps.",
1713
+ input: { type: "object", properties: { prompt: { type: "string", description: "What to make", minLength: 1 }, reference_image: { type: "string", description: "A path, or attachment:<id>" } }, required: ["prompt"], additionalProperties: false },
1714
+ files: [{ field: "reference_image", accept: ["image/*"], maxMb: 8 }],
1715
+ settings: true,
1716
+ example: { prompt: "a red fox" },
1717
+ risk: { costs: false, writes: false, sends: false, ask: "never" },
1718
+ labels: { running: "Making an image", done: "Made an image" },
1719
+ result: { views: ["images", "text"] },
1720
+ timeoutMs: 3e4
1721
+ },
1722
+ speakTool("echo_speak", "the echo module (silence of the right length)", false),
1723
+ transcribeTool("echo_transcribe", "the echo module (it reports the bytes it heard)", false),
1724
+ {
1725
+ name: "echo_lookup",
1726
+ title: "Look something up",
1727
+ description: "Looks a query up in the echo module's table and returns what it found as text and as a CSV file. Use it in tests when a tool of a kind no app has ever heard of is needed: text plus a file. Do not expect real data; it makes two rows from the query. The file is returned as an attachment id.",
1728
+ input: { type: "object", properties: { query: { type: "string", description: "What to look up", minLength: 1 } }, required: ["query"], additionalProperties: false },
1729
+ files: [],
1730
+ settings: false,
1731
+ example: { query: "harbour" },
1732
+ risk: { costs: false, writes: false, sends: false, ask: "never" },
1733
+ labels: { running: "Looking it up", done: "Looked it up" },
1734
+ result: { views: ["text", "files"] },
1735
+ timeoutMs: 3e4
1736
+ }
1737
+ ]
1738
+ }
1739
+ },
1740
+ legacyCapabilities: ["agent", "tts", "stt", "image"],
1503
1741
  providerId: "echo",
1504
1742
  defaultConnection: { id: "echo", name: "Echo (test)" },
1505
1743
  status: () => ({ state: "ready", progress: null, summary: "Ready" }),
1506
1744
  readiness: async () => ({ ready: true, summary: "Ready", details: {} }),
1507
- async options(capability) {
1508
- return capability === "tts" ? TTS_FIELDS : capability === "stt" ? STT_FIELDS : IMAGE_FIELDS;
1745
+ async options(use) {
1746
+ return use === "speech" || use === "tool:echo_speak" ? TTS_FIELDS : use === "transcription" || use === "tool:echo_transcribe" ? STT_FIELDS : use === "tool:echo_image" ? IMAGE_FIELDS : [];
1509
1747
  },
1510
1748
  estimate: (job) => job.capability === "tts" ? { characters: job.text.length } : {},
1749
+ async runTool(name, input, files, options, conn, secret) {
1750
+ if (name === "echo_speak") {
1751
+ const out = await this.run({ capability: "tts", text: String(input.text ?? ""), options: resolveOptions(TTS_FIELDS, options, settableArgs(TTS_FIELDS, input)) }, conn, secret);
1752
+ return { ...out, text: audioWords(out) };
1753
+ }
1754
+ if (name === "echo_transcribe") {
1755
+ const file = files.find((f) => f.field === "file");
1756
+ if (!file) throw new Error("echo_transcribe needs the file to transcribe.");
1757
+ const out = await this.run({ capability: "stt", audio: file.bytes, mime: file.mime, options: resolveOptions(STT_FIELDS, options, settableArgs(STT_FIELDS, input)) }, conn, secret);
1758
+ return { ...out, text: transcriptWords(out, file.name, "Echo") };
1759
+ }
1760
+ if (name === "echo_image") {
1761
+ const ref = files.find((f) => f.field === "reference_image");
1762
+ const out = await this.run({ capability: "image", prompt: String(input.prompt ?? ""), args: settableArgs(IMAGE_FIELDS, input), options, ...ref ? { reference: { bytes: ref.bytes, mime: ref.mime } } : {} }, conn, secret);
1763
+ return { ...out, text: imageWords(out) };
1764
+ }
1765
+ if (name === "echo_lookup") {
1766
+ const q = String(input.query ?? "").trim();
1767
+ const csv = `query,answer
1768
+ ${JSON.stringify(q)},${JSON.stringify(`echo found ${q}`)}
1769
+ ${JSON.stringify(q)},${JSON.stringify(`echo found ${q} again`)}
1770
+ `;
1771
+ return { files: [{ bytes: Buffer.from(csv, "utf8"), mime: "text/csv", name: "lookup.csv" }], text: `Looked up "${q}": 2 rows, in lookup.csv.` };
1772
+ }
1773
+ throw unknownTool("Echo (test)", name, this.manifest.provides.tools);
1774
+ },
1511
1775
  async run(job) {
1512
1776
  if (job.capability === "tts") {
1513
1777
  const o2 = resolveOptions(TTS_FIELDS, job.options);
@@ -1516,6 +1780,7 @@ var echoModule = {
1516
1780
  return { files: [{ bytes: silentWav(durationMs, str(o2.voice, "echo-a")), mime: "audio/wav", name: "speech.wav", durationMs }], usage: { amount: job.text.length, unit: "characters" } };
1517
1781
  }
1518
1782
  if (job.capability === "stt") return { files: [], text: `echo heard ${job.audio.length} bytes of ${job.mime}`, language: "en", usage: { amount: 1, unit: "seconds" } };
1783
+ if (job.capability === "tool") throw new Error("echo runs its tools through runTool.");
1519
1784
  const o = resolveOptions(IMAGE_FIELDS, job.options, job.args);
1520
1785
  const n = Math.max(1, Math.min(4, Math.round(num(o.num_images, 1))));
1521
1786
  return { files: Array.from({ length: n }, (_, i) => ({ bytes: PIXEL, mime: "image/png", name: `echo-${str(o.image_size, "square")}${job.reference ? `-from-${job.reference.bytes.length}b` : ""}-${i + 1}.png`, width: 1, height: 1 })), usage: { amount: n, unit: "images", costUsd: 0 } };
@@ -1673,9 +1938,19 @@ function elevenlabsModule(deps = {}) {
1673
1938
  return {
1674
1939
  id: "elevenlabs",
1675
1940
  version: "1.0.0",
1676
- catalogue: { id: "elevenlabs", name: "ElevenLabs", description: "Text to speech with your ElevenLabs voices (including your own clones), and speech to text with Scribe. Uses your ElevenLabs key.", capabilities: ["tts", "stt"], kind: "api", needsSecret: true, downloadMb: null },
1677
- multipleConnections: true,
1678
- connectionType: "api_key",
1941
+ manifest: {
1942
+ manifestVersion: 1,
1943
+ id: "elevenlabs",
1944
+ name: "ElevenLabs",
1945
+ summary: "Your agents speak with your ElevenLabs voices, your own clones included, and voice messages are transcribed with Scribe, on your ElevenLabs key.",
1946
+ category: "voice",
1947
+ publisher: { name: "MonoClaw", tier: "monoclaw" },
1948
+ runs: "service",
1949
+ key: { kind: "api_key", label: "ElevenLabs API key", placeholder: "sk_0123456789abcdef0123456789abcdef", pageUrl: "https://elevenlabs.io/app/settings/api-keys", pattern: "^\\S{20,}$", patternHelp: "An ElevenLabs API key is at least 20 characters, with no spaces.", several: true },
1950
+ cost: { unit: "characters", suggestedMonthlyCap: 1e5, note: "Billed by ElevenLabs by characters spoken, on your plan; the cap stops this key at the amount you set." },
1951
+ provides: { jobs: ["speech", "transcription"], tools: [speakTool("elevenlabs_speak", "ElevenLabs", true), transcribeTool("elevenlabs_transcribe", "ElevenLabs", true)] }
1952
+ },
1953
+ legacyCapabilities: ["tts", "stt"],
1679
1954
  status: () => ({ state: "ready", progress: null, summary: "" }),
1680
1955
  checkKey: (key) => key.trim().length >= 20 && !/\s/.test(key.trim()) ? null : "That does not look like an ElevenLabs API key.",
1681
1956
  async readiness(_conn, secret) {
@@ -1689,9 +1964,9 @@ function elevenlabsModule(deps = {}) {
1689
1964
  return notReady(e.message, e instanceof ServiceError && e.status === 401 ? "Enter the key again." : void 0);
1690
1965
  }
1691
1966
  },
1692
- async options(capability, _conn, secret) {
1693
- if (capability === "stt") return ELEVENLABS_STT_FIELDS;
1694
- if (capability !== "tts") throw new Error("ElevenLabs makes speech and transcripts, not images.");
1967
+ async options(use, _conn, secret) {
1968
+ if (use === "transcription" || use === "tool:elevenlabs_transcribe") return ELEVENLABS_STT_FIELDS;
1969
+ if (use !== "speech" && use !== "tool:elevenlabs_speak") throw new Error("ElevenLabs makes speech and transcripts, not images.");
1695
1970
  const key = needKey(secret);
1696
1971
  const [v, m] = await Promise.all([voices(key), models(key)]);
1697
1972
  return [
@@ -1699,7 +1974,20 @@ function elevenlabsModule(deps = {}) {
1699
1974
  { key: "model", label: "Model", type: "select", choices: m.length ? m : [{ value: DEFAULT_TTS_MODEL, label: "Eleven Multilingual v2" }], default: m.some((x) => x.value === DEFAULT_TTS_MODEL) || !m.length ? DEFAULT_TTS_MODEL : m[0].value, required: true }
1700
1975
  ];
1701
1976
  },
1702
- estimate: (job) => job.capability === "tts" ? { characters: job.text.length } : {},
1977
+ estimate: (job) => job.capability === "tts" ? { characters: job.text.length } : job.capability === "tool" && job.tool === "elevenlabs_speak" ? { characters: String(job.input.text ?? "").length } : {},
1978
+ async runTool(name, input, files, options, conn, secret) {
1979
+ if (name === "elevenlabs_speak") {
1980
+ const spoken = await this.run({ capability: "tts", text: String(input.text ?? ""), options: { ...options, ...settableArgs(await this.options("speech", conn, secret), input) } }, conn, secret);
1981
+ return { ...spoken, text: audioWords(spoken) };
1982
+ }
1983
+ if (name === "elevenlabs_transcribe") {
1984
+ const file = files.find((f2) => f2.field === "file");
1985
+ if (!file) throw new Error("elevenlabs_transcribe needs the file to transcribe.");
1986
+ const heard = await this.run({ capability: "stt", audio: file.bytes, mime: file.mime, options: resolveOptions(ELEVENLABS_STT_FIELDS, options, settableArgs(ELEVENLABS_STT_FIELDS, input)) }, conn, secret);
1987
+ return { ...heard, text: transcriptWords(heard, file.name, "ElevenLabs") };
1988
+ }
1989
+ throw unknownTool("ElevenLabs", name, this.manifest.provides.tools);
1990
+ },
1703
1991
  async run(job, conn, secret) {
1704
1992
  const key = needKey(secret);
1705
1993
  if (job.capability === "tts") {
@@ -1757,6 +2045,24 @@ var FAL_FIELDS = [
1757
2045
  { key: "output_format", label: "Format", type: "select", choices: [{ value: "jpeg", label: "JPEG" }, { value: "png", label: "PNG" }], default: "jpeg", required: false, agentSettable: true },
1758
2046
  { key: "enable_safety_checker", label: "Safety checker", type: "boolean", default: true, required: false, agentSettable: true }
1759
2047
  ];
2048
+ var FAL_IMAGE_TOOL = {
2049
+ name: "fal_image",
2050
+ title: "Make an image",
2051
+ description: "Makes images from a description with fal, on the model set for it. Use it when a person asks for a picture, an illustration, a poster or a visual draft. Do not use it to look at an image that already exists: look at that with image_view, or hand it here as a reference_image to make a new picture in its style or of the same subject (FLUX.2 models take one; another model says so). Each call costs money on the fal key. Returns each image as an attachment id (and as a file under images/ in your folder when you have full access); people see the images in your steps.",
2052
+ input: {
2053
+ type: "object",
2054
+ properties: { prompt: { type: "string", description: "What to make, described in detail", minLength: 1, maxLength: 1e4 }, reference_image: { type: "string", description: "One image to work from or in the style of: a path in your folder, or attachment:<id>" } },
2055
+ required: ["prompt"],
2056
+ additionalProperties: false
2057
+ },
2058
+ files: [{ field: "reference_image", accept: ["image/png", "image/jpeg", "image/webp"], maxMb: MAX_REFERENCE / 1024 / 1024 }],
2059
+ settings: true,
2060
+ example: { prompt: "A red kite flying over a harbour at dusk, watercolour" },
2061
+ risk: { costs: true, writes: false, sends: false, ask: "never" },
2062
+ labels: { running: "Making an image", done: "Made an image" },
2063
+ result: { views: ["images", "text"] },
2064
+ timeoutMs: 18e4
2065
+ };
1760
2066
  function falInput(model, prompt, o) {
1761
2067
  const size = str(o.image_size, "landscape_4_3");
1762
2068
  const preset = IMAGE_SIZES[size] ?? IMAGE_SIZES.landscape_4_3;
@@ -1810,9 +2116,19 @@ function falModule(deps = {}) {
1810
2116
  return {
1811
2117
  id: "fal",
1812
2118
  version: "1.0.0",
1813
- catalogue: { id: "fal", name: "fal.ai", description: "Images with FLUX and other models on fal.ai, for agents' image tools. Uses your fal key.", capabilities: ["image"], kind: "api", needsSecret: true, downloadMb: null },
1814
- multipleConnections: true,
1815
- connectionType: "api_key",
2119
+ manifest: {
2120
+ manifestVersion: 1,
2121
+ id: "fal",
2122
+ name: "fal.ai",
2123
+ summary: "Your agents make images with FLUX and other models on fal.ai, on your fal key.",
2124
+ category: "images",
2125
+ publisher: { name: "MonoClaw", tier: "monoclaw" },
2126
+ runs: "service",
2127
+ key: { kind: "api_key", label: "fal key", placeholder: "<key id>:<secret>", pageUrl: "https://fal.ai/dashboard/keys", pattern: "^[\\w-]+:[\\w-]+$", patternHelp: "A fal key is <key id>:<secret>, as the fal dashboard shows it.", several: true },
2128
+ cost: { unit: "usd", suggestedMonthlyCap: 20, note: "Each call costs; the model decides how much, from fractions of a cent to a few cents an image, billed to your fal key." },
2129
+ provides: { jobs: [], tools: [FAL_IMAGE_TOOL] }
2130
+ },
2131
+ legacyCapabilities: ["image"],
1816
2132
  status: () => ({ state: "ready", progress: null, summary: "" }),
1817
2133
  checkKey: (key) => /^[\w-]+:[\w-]+$/.test(key.trim()) ? null : "That does not look like a fal key (<key id>:<secret>).",
1818
2134
  async readiness(_conn, secret) {
@@ -1832,15 +2148,21 @@ function falModule(deps = {}) {
1832
2148
  if (res.status === 403 && err.code !== "rejected_key") return { ready: true, summary: "Ready (this key can't see the balance)", details: {} };
1833
2149
  return notReady(err.message, "Enter the key again.");
1834
2150
  },
1835
- async options(capability) {
1836
- if (capability !== "image") throw new Error("fal makes images.");
2151
+ async options(use) {
2152
+ if (use !== "tool:fal_image") throw new Error("fal makes images.");
1837
2153
  return FAL_FIELDS;
1838
2154
  },
1839
2155
  estimate(job) {
2156
+ if (job.capability === "tool") return job.tool === "fal_image" ? this.estimate(asImageJob(job)) : {};
1840
2157
  if (job.capability !== "image") return {};
1841
2158
  const o = resolved(job);
1842
2159
  return { usd: falEstimateUsd(modelOf(o), o) };
1843
2160
  },
2161
+ async runTool(name, input, files, options, conn, secret) {
2162
+ if (name !== "fal_image") throw unknownTool(this.manifest.name, name, this.manifest.provides.tools);
2163
+ const out = await this.run(asImageJob({ capability: "tool", tool: name, input, files, options }), conn, secret);
2164
+ return { ...out, text: imageWords(out) };
2165
+ },
1844
2166
  async run(job, _conn, secret) {
1845
2167
  if (job.capability !== "image") throw new Error("fal makes images.");
1846
2168
  if (!secret) throw new Error("This connection has no key yet. Enter it on the machine (`monoclaw modules key <id>`) or from the app.");
@@ -1890,6 +2212,10 @@ function falModule(deps = {}) {
1890
2212
  }
1891
2213
  };
1892
2214
  }
2215
+ function asImageJob(job) {
2216
+ const ref = job.files.find((f) => f.field === "reference_image");
2217
+ return { capability: "image", prompt: String(job.input.prompt ?? ""), args: settableArgs(FAL_FIELDS, job.input), options: job.options, ...ref ? { reference: { bytes: ref.bytes, mime: ref.mime } } : {} };
2218
+ }
1893
2219
  function isFalCdn(u) {
1894
2220
  const h = u.hostname.toLowerCase();
1895
2221
  if (h === "fal.media" || h.endsWith(".fal.media") || h === "fal.ai" || h.endsWith(".fal.ai") || h.endsWith(".fal.run")) return true;
@@ -2718,36 +3044,36 @@ var ENGINE_VERSION = "1.0.0";
2718
3044
  var MODEL_VERSION = "kokoro-v1.0+parakeet-tdt-0.6b-v2";
2719
3045
 
2720
3046
  // ../../packages/voice-recipe/src/recipe.ts
2721
- import { z as z9 } from "zod";
3047
+ import { z as z10 } from "zod";
2722
3048
  var RECIPE_VERSION = 1;
2723
3049
  var TONES = ["natural", "warm", "bright", "radio", "phone"];
2724
3050
  var REVERBS = ["off", "room", "hall"];
2725
3051
  var LEVEL_MODES = ["loudness", "peak"];
2726
3052
  var CONTENT_TYPES = { ogg: "audio/ogg", mp3: "audio/mpeg", wav: "audio/wav", m4a: "audio/mp4" };
2727
- var blendPartSchema = z9.object({ voice: z9.string().min(1).max(64), weight: z9.number().min(0).max(1) });
2728
- var voiceRecipeSchema = z9.object({
2729
- version: z9.literal(RECIPE_VERSION).default(RECIPE_VERSION),
3053
+ var blendPartSchema = z10.object({ voice: z10.string().min(1).max(64), weight: z10.number().min(0).max(1) });
3054
+ var voiceRecipeSchema = z10.object({
3055
+ version: z10.literal(RECIPE_VERSION).default(RECIPE_VERSION),
2730
3056
  /** TTS model id the base voice belongs to. */
2731
- model: z9.string().min(1).max(64).default("kokoro-v1.0"),
3057
+ model: z10.string().min(1).max(64).default("kokoro-v1.0"),
2732
3058
  /** Base voice id, e.g. `bf_emma`. */
2733
- voice: z9.string().min(1).max(64),
3059
+ voice: z10.string().min(1).max(64),
2734
3060
  /**
2735
3061
  * Up to two voices with weights. Reserved for engines that can mix style vectors; engine 1.x renders the heaviest
2736
3062
  * voice (or `voice` when the list is empty) and reports `blend: false` in its capabilities.
2737
3063
  */
2738
- blend: z9.array(blendPartSchema).max(2).default([]),
2739
- speed: z9.number().min(0.5).max(2).default(1),
2740
- pitchSemitones: z9.number().min(-12).max(12).default(0),
2741
- tone: z9.enum(TONES).default("natural"),
2742
- reverb: z9.enum(REVERBS).default("off"),
2743
- normalize: z9.boolean().default(true),
2744
- levelMode: z9.enum(LEVEL_MODES).default("loudness"),
3064
+ blend: z10.array(blendPartSchema).max(2).default([]),
3065
+ speed: z10.number().min(0.5).max(2).default(1),
3066
+ pitchSemitones: z10.number().min(-12).max(12).default(0),
3067
+ tone: z10.enum(TONES).default("natural"),
3068
+ reverb: z10.enum(REVERBS).default("off"),
3069
+ normalize: z10.boolean().default(true),
3070
+ levelMode: z10.enum(LEVEL_MODES).default("loudness"),
2745
3071
  /** Mono speech target; −19 LUFS mono is the −16 LUFS stereo guidance. */
2746
- targetLufs: z9.number().min(-30).max(-10).default(-19),
2747
- truePeakDb: z9.number().min(-6).max(0).default(-1),
2748
- gainDb: z9.number().min(-20).max(20).default(0),
3072
+ targetLufs: z10.number().min(-30).max(-10).default(-19),
3073
+ truePeakDb: z10.number().min(-6).max(0).default(-1),
3074
+ gainDb: z10.number().min(-20).max(20).default(0),
2749
3075
  /** Pause length between sentences, as the synthesiser's silence scale. */
2750
- silenceScale: z9.number().min(0).max(2).default(0.2)
3076
+ silenceScale: z10.number().min(0).max(2).default(0.2)
2751
3077
  });
2752
3078
  var round3 = (n) => Math.round(n * 1e3) / 1e3;
2753
3079
  function normaliseRecipe(input) {
@@ -3285,9 +3611,20 @@ function kokoroModule(voice) {
3285
3611
  return {
3286
3612
  id: "kokoro",
3287
3613
  version: "1.0.0",
3288
- catalogue: { id: "kokoro", name: "Kokoro", description: "Text to speech on this machine: 54 voices in nine languages, free and private. Needs ffmpeg.", capabilities: ["tts"], kind: "local", needsSecret: false, downloadMb: 385 },
3289
- multipleConnections: false,
3290
- connectionType: "local",
3614
+ manifest: {
3615
+ manifestVersion: 1,
3616
+ id: "kokoro",
3617
+ name: "Kokoro",
3618
+ summary: "A voice for your agents, made on this machine. 54 voices in nine languages, free and private.",
3619
+ category: "voice",
3620
+ publisher: { name: "MonoClaw", tier: "monoclaw" },
3621
+ runs: "local",
3622
+ needs: { downloadMb: 385, programs: [FFMPEG] },
3623
+ key: null,
3624
+ cost: null,
3625
+ provides: { jobs: ["speech"], tools: [speakTool("kokoro_speak", "Kokoro, on this machine", false)] }
3626
+ },
3627
+ legacyCapabilities: ["tts"],
3291
3628
  defaultConnection: { id: "kokoro", name: "This machine" },
3292
3629
  status: () => install.status(),
3293
3630
  install: (onProgress) => install.run(onProgress),
@@ -3299,7 +3636,12 @@ function kokoroModule(voice) {
3299
3636
  async options() {
3300
3637
  return KOKORO_FIELDS;
3301
3638
  },
3302
- estimate: (job) => job.capability === "tts" ? { characters: job.text.length } : {},
3639
+ estimate: (job) => job.capability === "tts" ? { characters: job.text.length } : job.capability === "tool" ? { characters: String(job.input.text ?? "").length } : {},
3640
+ async runTool(name, input, _files, options, conn, secret) {
3641
+ if (name !== "kokoro_speak") throw unknownTool("Kokoro", name, this.manifest.provides.tools);
3642
+ const out = await this.run({ capability: "tts", text: String(input.text ?? ""), options: resolveOptions(KOKORO_FIELDS, options, settableArgs(KOKORO_FIELDS, input)) }, conn, secret);
3643
+ return { ...out, text: audioWords(out) };
3644
+ },
3303
3645
  async run(job) {
3304
3646
  if (job.capability !== "tts") throw new Error("Kokoro only makes speech.");
3305
3647
  const s = install.status();
@@ -3365,9 +3707,20 @@ function parakeetModule(voice) {
3365
3707
  return {
3366
3708
  id: "parakeet",
3367
3709
  version: "1.0.0",
3368
- catalogue: { id: "parakeet", name: "Parakeet", description: "Speech to text on this machine: English, or 25 European languages, free and private. Needs ffmpeg.", capabilities: ["stt"], kind: "local", needsSecret: false, downloadMb: 520 },
3369
- multipleConnections: false,
3370
- connectionType: "local",
3710
+ manifest: {
3711
+ manifestVersion: 1,
3712
+ id: "parakeet",
3713
+ name: "Parakeet",
3714
+ summary: "Turns voice messages into text on this machine. English, or 25 European languages, free and private.",
3715
+ category: "voice",
3716
+ publisher: { name: "MonoClaw", tier: "monoclaw" },
3717
+ runs: "local",
3718
+ needs: { downloadMb: 520, programs: [FFMPEG] },
3719
+ key: null,
3720
+ cost: null,
3721
+ provides: { jobs: ["transcription"], tools: [transcribeTool("parakeet_transcribe", "Parakeet, on this machine", false)] }
3722
+ },
3723
+ legacyCapabilities: ["stt"],
3371
3724
  defaultConnection: { id: "parakeet", name: "This machine" },
3372
3725
  status() {
3373
3726
  const s = install.status();
@@ -3383,6 +3736,13 @@ function parakeetModule(voice) {
3383
3736
  async options() {
3384
3737
  return PARAKEET_FIELDS;
3385
3738
  },
3739
+ async runTool(name, input, files, options, conn, secret) {
3740
+ if (name !== "parakeet_transcribe") throw unknownTool("Parakeet", name, this.manifest.provides.tools);
3741
+ const file = files.find((f) => f.field === "file");
3742
+ if (!file) throw new Error("parakeet_transcribe needs the file to transcribe.");
3743
+ const out = await this.run({ capability: "stt", audio: file.bytes, mime: file.mime, options: resolveOptions(PARAKEET_FIELDS, options, settableArgs(PARAKEET_FIELDS, input)) }, conn, secret);
3744
+ return { ...out, text: transcriptWords(out, file.name, "Parakeet") };
3745
+ },
3386
3746
  async run(job) {
3387
3747
  if (job.capability !== "stt") throw new Error("Parakeet only transcribes.");
3388
3748
  const s = install.status();
@@ -3458,35 +3818,30 @@ function toWav(input, ffmpeg = "ffmpeg") {
3458
3818
  }
3459
3819
 
3460
3820
  // src/modules/setup.ts
3461
- function ffmpegInstall(platform) {
3462
- if (platform === "darwin") return "brew install ffmpeg";
3463
- if (platform === "win32") return "winget install --id Gyan.FFmpeg -e";
3464
- return "sudo apt install -y ffmpeg # or your distribution's package manager";
3465
- }
3466
- var KEY_PAGES = {
3467
- "claude-api": { label: "Anthropic Console \u2192 API keys", url: "https://console.anthropic.com/settings/keys" },
3468
- elevenlabs: { label: "ElevenLabs \u2192 API keys", url: "https://elevenlabs.io/app/settings/api-keys" },
3469
- fal: { label: "fal \u2192 Keys", url: "https://fal.ai/dashboard/keys" }
3470
- };
3471
3821
  function moduleSetup(m, platform = process.platform) {
3472
3822
  const steps = [];
3473
- const name = m.catalogue.name;
3474
- if (m.id === "kokoro" || m.id === "parakeet") {
3475
- steps.push({ title: "Install ffmpeg", command: ffmpegInstall(platform), detail: `${name} uses ffmpeg to read and write audio. Check with \`ffmpeg -version\`.` });
3476
- }
3477
- if (m.id === "claude-subscription" || m.id === "claude-api") {
3823
+ const name = m.manifest.name;
3824
+ const key = m.manifest.key;
3825
+ const needs = m.manifest.needs;
3826
+ for (const p of needs?.programs ?? []) {
3827
+ const command = p.install[platform === "darwin" ? "darwin" : platform === "win32" ? "win32" : "linux"] ?? p.install.linux ?? p.install.darwin ?? p.install.win32;
3828
+ steps.push({ title: `Install ${p.name}`, ...command ? { command } : {}, detail: `${name} ${p.why}` });
3829
+ }
3830
+ if (m.manifest.provides.agent?.providerId === "claude") {
3478
3831
  steps.push({ title: "Check Claude Code", command: "monoclaw doctor", detail: "The host brings its own copy of Claude Code; doctor says if anything is missing." });
3479
3832
  }
3480
- steps.push({ title: `Add ${name}`, command: `monoclaw modules add ${m.id}`, detail: m.catalogue.downloadMb ? `Downloads about ${m.catalogue.downloadMb} MB (models and a speech library) the first time.` : void 0 });
3481
- if (m.id === "claude-subscription") {
3833
+ const downloadMb = needs?.downloadMb ?? null;
3834
+ steps.push({ title: `Add ${name}`, command: `monoclaw modules add ${m.id}`, detail: downloadMb ? `Downloads about ${downloadMb} MB (models and a speech library) the first time.` : void 0 });
3835
+ if (key?.kind === "login") {
3482
3836
  steps.push({ title: "Sign in to Claude on this machine", command: "monoclaw claude auth login", detail: "Agents use this login (a Pro, Max, Team or Enterprise plan). Skip it if `monoclaw doctor` already shows you signed in." });
3483
3837
  }
3484
- if (m.connectionType === "api_key") {
3485
- const page = KEY_PAGES[m.id];
3486
- steps.push({ title: "Add a key", command: `monoclaw modules connect ${m.id} --name "${name} key"`, detail: `Paste the key when asked (it isn't shown). It's kept on this machine only.${m.multipleConnections ? " Add more keys the same way, one per budget or team." : ""}`, ...page ? { link: page } : {} });
3487
- steps.push({ title: "Set a monthly limit (optional)", command: m.id === "elevenlabs" ? "monoclaw modules cap <connection id> --characters 100000" : "monoclaw modules cap <connection id> --usd 20", detail: "The connection id (pac_\u2026) is in `monoclaw modules list`. The machine stops using the key when the limit is reached." });
3838
+ if (key?.kind === "api_key") {
3839
+ const page = key.pageUrl ? { label: new URL(key.pageUrl).hostname, url: key.pageUrl } : void 0;
3840
+ steps.push({ title: "Add a key", command: `monoclaw modules connect ${m.id} --name "${name} key"`, detail: `Paste the key when asked (it isn't shown). It's kept on this machine only.${key.several ? " Add more keys the same way, one per budget or team." : ""}`, ...page ? { link: page } : {} });
3841
+ const cost = m.manifest.cost;
3842
+ if (cost) steps.push({ title: "Set a monthly limit (optional)", command: cost.unit === "characters" ? `monoclaw modules cap <connection id> --characters ${cost.suggestedMonthlyCap}` : `monoclaw modules cap <connection id> --usd ${cost.suggestedMonthlyCap}`, detail: "The connection id (pac_\u2026) is in `monoclaw modules list`. The machine stops using the key when the limit is reached." });
3488
3843
  }
3489
- steps.push({ title: "Check it", command: "monoclaw modules list", detail: m.catalogue.downloadMb ? "It says Ready once the download is done; the machine's page in the app shows the same." : "It says Ready when it can be used; the machine's page in the app shows the same." });
3844
+ steps.push({ title: "Check it", command: "monoclaw modules list", detail: downloadMb ? "It says Ready once the download is done; the machine's page in the app shows the same." : "It says Ready when it can be used; the machine's page in the app shows the same." });
3490
3845
  return steps.map((st) => st.command ? { ...st, command: withProfile(st.command) } : st);
3491
3846
  }
3492
3847
  function withProfile(command, profile = currentProfile()) {
@@ -3597,10 +3952,12 @@ var ModuleRegistry = class {
3597
3952
  this.deps = deps;
3598
3953
  this.voice = deps.voice ?? new LocalVoice(sharedDir());
3599
3954
  this.voice.changed = () => this.changed();
3600
- this.all = { ...defaultModules({ providers: deps.providers, voice: this.voice, fetch: deps.fetch }), ...deps.modules };
3955
+ this.all = { ...defaultModules({ providers: deps.providers, voice: this.voice, fetch: deps.fetch }) };
3956
+ for (const [id, m] of Object.entries(deps.modules ?? {})) if (m) this.all[id] = m;
3601
3957
  this.ledger = deps.ledger ?? new UsageLedger(path11.join(configDir(), "usage.json"));
3602
3958
  }
3603
3959
  deps;
3960
+ /** Every module this program carries, by id (a module is no longer one of a fixed list: docs/spec/modules.md § 3). */
3604
3961
  all;
3605
3962
  ledger;
3606
3963
  voice;
@@ -3619,17 +3976,21 @@ var ModuleRegistry = class {
3619
3976
  return this.deps.echo ?? echoFromEnv();
3620
3977
  }
3621
3978
  module(id) {
3622
- return MODULE_IDS.includes(id) ? this.all[id] : null;
3979
+ return this.all[id] ?? null;
3623
3980
  }
3624
3981
  /** What this machine can install, each with its version and its setup steps for this platform. */
3625
3982
  catalogue() {
3626
- return MODULE_IDS.filter((id) => id !== "echo" || this.echoAllowed()).map((id) => {
3983
+ return Object.keys(this.all).filter((id) => id !== "echo" || this.echoAllowed()).map((id) => {
3627
3984
  const m = this.all[id];
3628
- return { ...m.catalogue, version: m.version, setup: moduleSetup(m) };
3985
+ return { ...legacyCatalogueOf(m), version: m.version, setup: moduleSetup(m), manifest: this.manifestOf(m) };
3629
3986
  });
3630
3987
  }
3988
+ /** The module's manifest as it travels: what the module declares, with its version and this machine's set-up steps (docs/spec/modules.md § 3). */
3989
+ manifestOf(m) {
3990
+ return { ...m.manifest, version: m.version, setup: moduleSetup(m) };
3991
+ }
3631
3992
  installedIds() {
3632
- const ids = this.deps.config.get().modules.map((m) => m.id).filter((id) => MODULE_IDS.includes(id));
3993
+ const ids = this.deps.config.get().modules.map((m) => m.id).filter((id) => id in this.all);
3633
3994
  if (this.echoAllowed() && !ids.includes("echo")) ids.push("echo");
3634
3995
  return [...new Set(ids)];
3635
3996
  }
@@ -3668,11 +4029,11 @@ var ModuleRegistry = class {
3668
4029
  const c = this.connection(connectionId);
3669
4030
  if (!c) return `The connection ${connectionId} isn't on this machine any more (its module may have been removed). Choose another for this agent.`;
3670
4031
  const m = this.all[c.module];
3671
- if (!m?.providerId) return `${c.name} is a ${m?.catalogue.name ?? c.module} connection, not an agent engine.`;
4032
+ if (!m?.providerId) return `${c.name} is a ${m ? moduleNameOf(m) : c.module} connection, not an agent engine.`;
3672
4033
  if (m.providerId !== providerId) return `${c.name} runs ${m.providerId}, not ${providerId}.`;
3673
4034
  return null;
3674
4035
  }
3675
- const logins = this.installedIds().filter((id) => this.all[id].providerId === providerId && this.all[id].connectionType !== "api_key");
4036
+ const logins = this.installedIds().filter((id) => this.all[id].providerId === providerId && connectionTypeOf(this.all[id]) !== "api_key");
3676
4037
  if (!logins.length) return `This machine has no ${providerId} login module; choose an API key connection for this agent, or run \`monoclaw modules add claude-subscription\` on the machine.`;
3677
4038
  return null;
3678
4039
  }
@@ -3682,7 +4043,7 @@ var ModuleRegistry = class {
3682
4043
  if (!m) throw new Error(`There is no module "${id}". See \`monoclaw modules list --all\`.`);
3683
4044
  if (id === "echo" && !this.echoAllowed()) throw new Error("echo is a test module: start the host with MONOCLAW_PROVIDERS=echo to use it.");
3684
4045
  if (!this.deps.config.get().modules.some((x) => x.id === id)) this.deps.config.update((c) => ({ ...c, modules: [...c.modules, { id, addedAt: (/* @__PURE__ */ new Date()).toISOString(), settings: {} }] }));
3685
- if (m.defaultConnection && !this.deps.accounts.get(m.defaultConnection.id)) this.deps.accounts.upsert({ id: m.defaultConnection.id, name: m.defaultConnection.name, type: m.connectionType, module: m.id, provider: m.providerId ?? m.id });
4046
+ if (m.defaultConnection && !this.deps.accounts.get(m.defaultConnection.id)) this.deps.accounts.upsert({ id: m.defaultConnection.id, name: m.defaultConnection.name, type: connectionTypeOf(m), module: m.id, provider: m.providerId ?? m.id });
3686
4047
  log("info", `module ${id} added`);
3687
4048
  const install = this.startInstall(m);
3688
4049
  this.changed();
@@ -3728,7 +4089,8 @@ var ModuleRegistry = class {
3728
4089
  async readiness(connectionId) {
3729
4090
  const c = this.connection(connectionId);
3730
4091
  if (!c) return { ready: false, summary: "This machine does not know that connection.", details: {}, action: "Add it again from the machine page." };
3731
- const m = this.all[c.module];
4092
+ const m = this.module(c.module);
4093
+ if (!m) return { ready: false, summary: `This machine has no module "${c.module}" for that connection.`, details: {} };
3732
4094
  let r;
3733
4095
  try {
3734
4096
  r = await m.readiness(c, c.type === "api_key" ? await this.deps.accounts.secretOf(c.id) : null);
@@ -3751,7 +4113,7 @@ var ModuleRegistry = class {
3751
4113
  const rs = conns.map((c2) => this.readinessCache.get(c2.id));
3752
4114
  if (!conns.length) {
3753
4115
  state = "needs_setup";
3754
- summary = m.connectionType === "api_key" ? `Add an API key (monoclaw modules connect ${id})` : "No connection";
4116
+ summary = connectionTypeOf(m) === "api_key" ? `Add an API key (monoclaw modules connect ${id})` : "No connection";
3755
4117
  } else if (rs.some((r) => r?.ready)) {
3756
4118
  const n = rs.filter((r) => r?.ready).length;
3757
4119
  summary = conns.length === 1 ? rs[0].summary : `${n} of ${conns.length} connections ready`;
@@ -3761,40 +4123,52 @@ var ModuleRegistry = class {
3761
4123
  summary = `${conns.length === 1 ? "" : `${conns.find((c2) => this.readinessCache.get(c2.id) === r).name}: `}${r.summary}${r.action ? `. ${r.action}` : ""}`;
3762
4124
  } else summary = st.summary || "Checking\u2026";
3763
4125
  }
3764
- const c = m.catalogue;
3765
- return { id, name: c.name, version: m.version, description: c.description, capabilities: c.capabilities, kind: c.kind, needsSecret: c.needsSecret, multipleConnections: m.multipleConnections, state, progress: state === "installing" ? st.progress ?? 0 : null, summary: summary.slice(0, 300) };
4126
+ const c = legacyCatalogueOf(m);
4127
+ return { id, name: c.name, version: m.version, description: c.description, capabilities: c.capabilities, kind: c.kind, needsSecret: c.needsSecret, multipleConnections: multipleConnectionsOf(m), manifest: this.manifestOf(m), state, progress: state === "installing" ? st.progress ?? 0 : null, summary: summary.slice(0, 300) };
3766
4128
  }
3767
4129
  reports() {
3768
4130
  return this.installedIds().map((id) => this.report(id));
3769
4131
  }
3770
4132
  connectionReports() {
3771
- return this.connections().map((c) => ({ id: c.id, name: c.name, provider: c.provider, module: c.module, type: c.type, readiness: this.readinessCache.get(c.id) ?? CHECKING }));
4133
+ return this.connections().map((c) => ({ id: c.id, name: c.name, provider: c.provider, module: c.module, type: c.type, readiness: this.readinessCache.get(c.id) ?? CHECKING, ...c.settings && Object.keys(c.settings).length ? { settings: c.settings } : {} }));
3772
4134
  }
3773
- /** The fields a module offers for one use, choices filled in (live where the module fetches them). */
3774
- async options(moduleId, capability, connectionId) {
4135
+ /**
4136
+ * The fields a module offers for one use, choices filled in (live where the module fetches them). `use` is the word
4137
+ * of the spec (`agent`, `speech`, `transcription`, `tool:<name>`); a caller from before gives the old `capability`, which
4138
+ * maps onto it (an `image` is the module's one image tool).
4139
+ */
4140
+ async options(moduleId, capability, connectionId, use) {
3775
4141
  const m = this.installed(moduleId);
3776
- if (!m.catalogue.capabilities.includes(capability)) throw new Error(`${m.catalogue.name} has no ${capability} options.`);
4142
+ const name = moduleNameOf(m);
4143
+ const u = use ?? useFromCapability(capability, imageToolOf(m));
4144
+ const has2 = u === "agent" ? !!m.manifest.provides.agent : u === "speech" ? m.manifest.provides.jobs.includes("speech") : u === "transcription" ? m.manifest.provides.jobs.includes("transcription") : !!toolOf(m, u.slice("tool:".length));
4145
+ if (!has2) throw new Error(`${name} has no ${use ?? capability} options.`);
3777
4146
  if (!m.options) return [];
3778
4147
  const conn = connectionId ? this.connection(connectionId) : this.connectionsOf(moduleId)[0] ?? null;
3779
- if (connectionId && (!conn || conn.module !== moduleId)) throw new Error(`This machine has no ${m.catalogue.name} connection ${connectionId}.`);
3780
- return m.options(capability, conn, conn?.type === "api_key" ? await this.deps.accounts.secretOf(conn.id) : null);
4148
+ if (connectionId && (!conn || conn.module !== moduleId)) throw new Error(`This machine has no ${name} connection ${connectionId}.`);
4149
+ return m.options(u, conn, conn?.type === "api_key" ? await this.deps.accounts.secretOf(conn.id) : null);
3781
4150
  }
3782
4151
  /** One job with a module and a connection: caps checked first, usage recorded after. */
3783
4152
  async runJob(moduleId, connectionId, job) {
3784
4153
  const m = this.installed(moduleId);
3785
- if (!m.run || !m.catalogue.capabilities.includes(job.capability)) throw new Error(`${m.catalogue.name} can't do ${job.capability === "tts" ? "text to speech" : job.capability === "stt" ? "speech to text" : "images"}.`);
4154
+ const name = moduleNameOf(m);
4155
+ if (job.capability === "tool") {
4156
+ if (!toolOf(m, job.tool)) throw unknownTool(name, job.tool, m.manifest.provides.tools);
4157
+ if (!m.runTool) throw new Error(`${name} does not run tools on this machine program.`);
4158
+ } else if (!m.run || !m.legacyCapabilities.includes(job.capability)) throw new Error(`${name} can't do ${job.capability === "tts" ? "text to speech" : job.capability === "stt" ? "speech to text" : "images"}.`);
3786
4159
  const conn = this.connection(connectionId);
3787
- if (!conn || conn.module !== moduleId) throw new Error(`This machine has no ${m.catalogue.name} connection ${connectionId}.`);
4160
+ if (!conn || conn.module !== moduleId) throw new Error(`This machine has no ${name} connection ${connectionId}.`);
3788
4161
  const over = this.ledger.check(conn, m.estimate?.(job));
3789
4162
  if (over) throw new Error(over);
3790
- const out = await m.run(job, conn, conn.type === "api_key" ? await this.deps.accounts.secretOf(conn.id) : null);
4163
+ const secret = conn.type === "api_key" ? await this.deps.accounts.secretOf(conn.id) : null;
4164
+ const out = job.capability === "tool" ? await m.runTool(job.tool, job.input, job.files, job.options, conn, secret) : await m.run(job, conn, secret);
3791
4165
  this.ledger.add(conn.id, out.usage);
3792
4166
  return out;
3793
4167
  }
3794
4168
  installed(moduleId) {
3795
4169
  const m = this.module(moduleId);
3796
4170
  if (!m) throw new Error(`There is no module "${moduleId}".`);
3797
- if (!this.isInstalled(moduleId)) throw new Error(`${m.catalogue.name} isn't on this machine any more.`);
4171
+ if (!this.isInstalled(moduleId)) throw new Error(`${moduleNameOf(m)} isn't on this machine any more.`);
3798
4172
  return m;
3799
4173
  }
3800
4174
  };
@@ -3846,7 +4220,6 @@ function formatUseResult(name, r, cwd) {
3846
4220
  if (r.error) return { content: [{ type: "text", text: r.error }], isError: true };
3847
4221
  return formatToolResult({ name }, r, cwd);
3848
4222
  }
3849
- var READ_ONLY_TOOLS = /* @__PURE__ */ new Set(["find_tools", "list_agents", "image_view", "agents_options", "agents_read_profile"]);
3850
4223
  var RESTART_PLAIN = "The service restarted while this ran; call it again.";
3851
4224
  function restartMessage(call) {
3852
4225
  switch (call.kind) {
@@ -3854,7 +4227,7 @@ function restartMessage(call) {
3854
4227
  case "list":
3855
4228
  return RESTART_PLAIN;
3856
4229
  case "use":
3857
- return READ_ONLY_TOOLS.has(call.name) ? RESTART_PLAIN : `The service restarted while ${call.name} ran. It may have run anyway: anything it made would be in your steps for the people in the project, and it may have cost money. Ask the person before calling it again.`;
4230
+ return `The service restarted while ${call.name} ran. It may have run anyway: anything it made would be in your steps for the people in the project, and it may have cost money. Ask the person before calling it again.`;
3858
4231
  case "send":
3859
4232
  return `The service restarted while this message was being sent to ${call.to}. It may have arrived. If it matters, ask ${call.to} whether it did before sending it again.`;
3860
4233
  }
@@ -3875,6 +4248,11 @@ var ToolWaits = class {
3875
4248
  resolve(id, r) {
3876
4249
  this.waits.get(id)?.finish(r);
3877
4250
  }
4251
+ /** The service is running the call and says whether it only reads: a read is safe to repeat if the connection is lost meanwhile. */
4252
+ started(id, readOnly) {
4253
+ const w = this.waits.get(id);
4254
+ if (w && readOnly) w.lost = RESTART_PLAIN;
4255
+ }
3878
4256
  closeAll(reason = "Session closed.") {
3879
4257
  for (const w of [...this.waits.values()]) w.finish({ error: reason, files: [] });
3880
4258
  }
@@ -3981,6 +4359,9 @@ var SessionToolRunner = class {
3981
4359
  result(id, r) {
3982
4360
  this.waits.resolve(id, r);
3983
4361
  }
4362
+ started(id, readOnly) {
4363
+ this.waits.started(id, readOnly);
4364
+ }
3984
4365
  /** The connection to the service closed: every waiting call ends now (bug: a tool call lost in a server restart). */
3985
4366
  failWaiting() {
3986
4367
  this.waits.failWaiting();
@@ -4387,6 +4768,10 @@ var SessionManager = class {
4387
4768
  }
4388
4769
  live.session.toolResult?.(id, { text: r.text, error: r.error, files, ...r.next ? { next: r.next } : {} });
4389
4770
  }
4771
+ /** The service is running a call (`tool.started`, 1.0.22): a read-only one is safe to repeat if the connection is lost. */
4772
+ toolStarted(groupId, id, readOnly) {
4773
+ this.live.get(groupId)?.session?.toolStarted?.(id, readOnly);
4774
+ }
4390
4775
  answerApproval(groupId, id, allow, updatedInput) {
4391
4776
  const live = this.live.get(groupId);
4392
4777
  if (!live) return;
@@ -4690,7 +5075,7 @@ function guessMime(name) {
4690
5075
  }
4691
5076
 
4692
5077
  // src/version.ts
4693
- var APP_VERSION = true ? "1.0.20" : fromPackage();
5078
+ var APP_VERSION = true ? "1.0.22" : fromPackage();
4694
5079
 
4695
5080
  // src/diag.ts
4696
5081
  var MAX_HELD = 200;
@@ -5097,6 +5482,9 @@ var HostClient = class {
5097
5482
  case "tool.result":
5098
5483
  await this.sessions.toolResult(frame.groupId, frame.id, { text: frame.text, error: frame.error, files: frame.files, next: frame.next });
5099
5484
  return;
5485
+ case "tool.started":
5486
+ this.sessions.toolStarted(frame.groupId, frame.id, frame.readOnly);
5487
+ return;
5100
5488
  case "module.add":
5101
5489
  try {
5102
5490
  const { install } = this.registry.add(frame.module);
@@ -5118,7 +5506,7 @@ var HostClient = class {
5118
5506
  return;
5119
5507
  case "module.options":
5120
5508
  try {
5121
- this.send({ t: "module.options.result", reqId: frame.reqId, fields: await this.registry.options(frame.module, frame.capability, frame.connectionId) });
5509
+ this.send({ t: "module.options.result", reqId: frame.reqId, fields: await this.registry.options(frame.module, frame.capability, frame.connectionId, frame.use) });
5122
5510
  } catch (e) {
5123
5511
  this.send({ t: "module.options.result", reqId: frame.reqId, fields: [], error: e.message.slice(0, 300) });
5124
5512
  }
@@ -5129,15 +5517,16 @@ var HostClient = class {
5129
5517
  case "provider_account.expect": {
5130
5518
  const m = this.registry.module(frame.module);
5131
5519
  if (!m || !this.registry.isInstalled(frame.module)) {
5132
- this.send({ t: "provider_account.readiness", id: frame.id, readiness: { ready: false, summary: `${m?.catalogue.name ?? frame.module} isn't installed on this machine.`, details: {}, action: "Add the module to the machine first." } });
5520
+ this.send({ t: "provider_account.readiness", id: frame.id, readiness: { ready: false, summary: `${m ? moduleNameOf(m) : frame.module} isn't installed on this machine.`, details: {}, action: "Add the module to the machine first." } });
5133
5521
  return;
5134
5522
  }
5135
- if (frame.type !== m.connectionType) {
5136
- this.send({ t: "provider_account.readiness", id: frame.id, readiness: { ready: false, summary: `${m.catalogue.name} connections are ${m.connectionType === "api_key" ? "API keys" : m.connectionType === "local" ? "this machine" : "logins"}, not ${frame.type}.`, details: {} } });
5523
+ const connectionType = connectionTypeOf(m);
5524
+ if (frame.type !== connectionType) {
5525
+ this.send({ t: "provider_account.readiness", id: frame.id, readiness: { ready: false, summary: `${moduleNameOf(m)} connections are ${connectionType === "api_key" ? "API keys" : connectionType === "local" ? "this machine" : "logins"}, not ${frame.type}.`, details: {} } });
5137
5526
  return;
5138
5527
  }
5139
- if (!m.multipleConnections && this.registry.connectionsOf(frame.module).some((c) => c.id !== frame.id)) {
5140
- this.send({ t: "provider_account.readiness", id: frame.id, readiness: { ready: false, summary: `${m.catalogue.name} has one connection on a machine, and this one has it.`, details: {} } });
5528
+ if (!multipleConnectionsOf(m) && this.registry.connectionsOf(frame.module).some((c) => c.id !== frame.id)) {
5529
+ this.send({ t: "provider_account.readiness", id: frame.id, readiness: { ready: false, summary: `${moduleNameOf(m)} has one connection on a machine, and this one has it.`, details: {} } });
5141
5530
  return;
5142
5531
  }
5143
5532
  this.accounts.upsert({ id: frame.id, name: frame.name, type: frame.type, module: frame.module, provider: m.providerId ?? frame.module, allowedFolders: frame.allowedFolders ?? [] });
@@ -5164,7 +5553,18 @@ var HostClient = class {
5164
5553
  }
5165
5554
  case "provider_account.update": {
5166
5555
  const a = this.accounts.get(frame.id);
5167
- if (a) this.accounts.upsert({ id: a.id, name: frame.name ?? a.name, type: a.type, module: a.module, provider: a.provider, allowedFolders: frame.allowedFolders ?? a.allowedFolders });
5556
+ if (a) {
5557
+ this.accounts.upsert({ id: a.id, name: frame.name ?? a.name, type: a.type, module: a.module, provider: a.provider, allowedFolders: frame.allowedFolders ?? a.allowedFolders });
5558
+ if (frame.monthlyCapUsd !== void 0 || frame.monthlyCapCharacters !== void 0) {
5559
+ const settings = { ...a.settings ?? {} };
5560
+ if (frame.monthlyCapUsd === null) delete settings.monthlyCapUsd;
5561
+ else if (frame.monthlyCapUsd !== void 0) settings.monthlyCapUsd = frame.monthlyCapUsd;
5562
+ if (frame.monthlyCapCharacters === null) delete settings.monthlyCapCharacters;
5563
+ else if (frame.monthlyCapCharacters !== void 0) settings.monthlyCapCharacters = frame.monthlyCapCharacters;
5564
+ this.accounts.setSettings(a.id, settings);
5565
+ log("info", `connection ${a.id.slice(0, 12)}: monthly cap ${settings.monthlyCapUsd !== void 0 ? `$${settings.monthlyCapUsd}` : settings.monthlyCapCharacters !== void 0 ? `${settings.monthlyCapCharacters} characters` : "cleared"}`);
5566
+ }
5567
+ }
5168
5568
  await this.reportAccount(frame.id);
5169
5569
  return;
5170
5570
  }
@@ -5242,6 +5642,7 @@ var HostClient = class {
5242
5642
  const origin = routerOrigin(this.cfg.routerUrl);
5243
5643
  const credential = this.cfg.credential ?? "";
5244
5644
  let audioFile = "";
5645
+ const jobFiles = [];
5245
5646
  log("info", `job ${frame.jobId.slice(0, 10)} ${frame.module} ${frame.input.capability}: received`);
5246
5647
  const facts = { module: frame.module, capability: frame.input.capability, jobId: frame.jobId.slice(0, 10) };
5247
5648
  const hung = setTimeout(() => {
@@ -5255,7 +5656,23 @@ var HostClient = class {
5255
5656
  audioFile = await downloadAttachment({ id: frame.jobId, name: `${frame.jobId}.audio`, mime: frame.input.mime, size: 0, url: frame.input.url, kind: "voice" }, path16.join(configDir(), "jobs"), credential, origin);
5256
5657
  job = { capability: "stt", audio: fs16.readFileSync(audioFile), mime: frame.input.mime, options: frame.options };
5257
5658
  } else if (frame.input.capability === "tts") job = { capability: "tts", text: frame.input.text, options: frame.options };
5258
- else {
5659
+ else if (frame.input.capability === "tool") {
5660
+ const m = this.registry.module(frame.module);
5661
+ const declared = m ? toolOf(m, frame.input.tool) : null;
5662
+ if (!m || !declared) throw unknownTool(m ? moduleNameOf(m) : frame.module, frame.input.tool, m?.manifest.provides.tools ?? []);
5663
+ const files = [];
5664
+ for (const f of frame.input.files) {
5665
+ const rule = declared.files.find((d) => d.field === f.field);
5666
+ if (!rule) throw new Error(`${declared.name} takes no file in "${f.field}".`);
5667
+ if (!rule.accept.some((a) => mimeMatches(a, f.mime))) throw new Error(`${f.name || f.field} is ${f.mime}; ${declared.name} takes ${rule.accept.join(", ")}.`);
5668
+ const saved = await downloadAttachment({ id: `${frame.jobId}-${f.field}`, name: `${frame.jobId}.${f.field}`, mime: f.mime, size: 0, url: f.url, kind: "image" }, path16.join(configDir(), "jobs"), credential, origin);
5669
+ jobFiles.push(saved);
5670
+ const bytes = fs16.readFileSync(saved);
5671
+ if (bytes.length > rule.maxMb * 1024 * 1024) throw new Error(`${f.name || f.field} is ${(bytes.length / 1024 / 1024).toFixed(1)} MB; ${declared.name} takes up to ${rule.maxMb} MB.`);
5672
+ files.push({ field: f.field, bytes, mime: f.mime, name: f.name });
5673
+ }
5674
+ job = { capability: "tool", tool: frame.input.tool, input: frame.input.input, files, options: frame.options };
5675
+ } else {
5259
5676
  job = { capability: "image", prompt: frame.input.prompt, args: frame.input.args, options: frame.options };
5260
5677
  if (frame.input.reference) {
5261
5678
  audioFile = await downloadAttachment({ id: frame.jobId, name: `${frame.jobId}.image`, mime: frame.input.reference.mime, size: 0, url: frame.input.reference.url, kind: "image" }, path16.join(configDir(), "jobs"), credential, origin);
@@ -5280,6 +5697,7 @@ var HostClient = class {
5280
5697
  } finally {
5281
5698
  clearTimeout(hung);
5282
5699
  if (audioFile) fs16.rmSync(audioFile, { force: true });
5700
+ for (const f of jobFiles) fs16.rmSync(f, { force: true });
5283
5701
  }
5284
5702
  this.scheduleModules();
5285
5703
  }
@@ -5287,6 +5705,11 @@ var HostClient = class {
5287
5705
  function describeMachine() {
5288
5706
  return { name: os5.hostname(), platform: process.platform, arch: process.arch, appVersion: APP_VERSION, nodeVersion: process.version };
5289
5707
  }
5708
+ function mimeMatches(pattern2, mime) {
5709
+ const m = mime.split(";")[0].trim().toLowerCase();
5710
+ const p = pattern2.toLowerCase();
5711
+ return p === "*/*" || p === m || p.endsWith("/*") && m.startsWith(p.slice(0, -1));
5712
+ }
5290
5713
 
5291
5714
  // src/modules/commands.ts
5292
5715
  import { randomUUID as randomUUID3 } from "node:crypto";
@@ -5311,6 +5734,8 @@ async function listModules(reg, io2, opts = {}) {
5311
5734
  io2.out("Modules on this machine:");
5312
5735
  for (const r of reg.reports()) {
5313
5736
  io2.out(`${mark(r.state === "ready", r.state === "installing")} ${r.id.padEnd(20)} ${r.state === "ready" ? "" : `${r.state.replace("_", " ")}: `}${r.summary}`);
5737
+ const m = reg.module(r.id);
5738
+ if (m) io2.out(` ${providesLine(m)}`);
5314
5739
  for (const c of reg.connectionsOf(r.id)) {
5315
5740
  const rd = reg.cachedReadiness(c.id);
5316
5741
  const caps = [c.settings?.monthlyCapUsd !== void 0 ? `cap $${c.settings.monthlyCapUsd}/month` : "", c.settings?.monthlyCapCharacters !== void 0 ? `cap ${c.settings.monthlyCapCharacters.toLocaleString("en")} characters/month` : ""].filter(Boolean).join(", ");
@@ -5341,28 +5766,28 @@ async function addModules(reg, ids, io2, opts = {}) {
5341
5766
  }
5342
5767
  await reg.refreshReadiness(reg.connectionsOf(id).map((c) => c.id));
5343
5768
  const r = reg.report(id);
5344
- io2.out(`${mark(r.state === "ready", r.state === "needs_setup")} ${m.catalogue.name}${already ? " (already added)" : " added"}: ${r.summary}`);
5345
- if (m.connectionType === "api_key" && !reg.connectionsOf(id).length) io2.out(` Next: monoclaw modules connect ${id} --name "<a name>" (asks for the key)`);
5769
+ io2.out(`${mark(r.state === "ready", r.state === "needs_setup")} ${moduleNameOf(m)}${already ? " (already added)" : " added"}: ${r.summary}`);
5770
+ if (connectionTypeOf(m) === "api_key" && !reg.connectionsOf(id).length) io2.out(` Next: monoclaw modules connect ${id} --name "<a name>" (asks for the key)`);
5346
5771
  }
5347
5772
  io2.out(RUNNING_HOST);
5348
5773
  }
5349
5774
  async function removeModule(reg, id, io2) {
5350
5775
  const m = reg.module(id) ?? fail(`There is no module "${id}".`);
5351
- if (!reg.isInstalled(id)) fail(`${m.catalogue.name} isn't on this machine.`);
5776
+ if (!reg.isInstalled(id)) fail(`${moduleNameOf(m)} isn't on this machine.`);
5352
5777
  const n = reg.connectionsOf(id).length;
5353
5778
  await reg.remove(id);
5354
- io2.out(`Removed ${m.catalogue.name}${n ? ` and its ${n === 1 ? "connection" : `${n} connections`} (keys deleted)` : ""}. Downloaded files stay, so adding it again is quick. ${RUNNING_HOST}`);
5779
+ io2.out(`Removed ${moduleNameOf(m)}${n ? ` and its ${n === 1 ? "connection" : `${n} connections`} (keys deleted)` : ""}. Downloaded files stay, so adding it again is quick. ${RUNNING_HOST}`);
5355
5780
  }
5356
5781
  async function connectModule(reg, accounts, moduleId, io2, opts = {}) {
5357
5782
  const m = reg.module(moduleId) ?? fail(`There is no module "${moduleId}". See \`monoclaw modules list --all\`.`);
5358
- if (m.connectionType !== "api_key") fail(`${m.catalogue.name} has one connection, ${m.connectionType === "local" ? "this machine" : "this machine's login"}; there is no key to add.`);
5783
+ if (connectionTypeOf(m) !== "api_key") fail(`${moduleNameOf(m)} has one connection, ${connectionTypeOf(m) === "local" ? "this machine" : "this machine's login"}; there is no key to add.`);
5359
5784
  if (!reg.isInstalled(moduleId)) await reg.add(moduleId).install;
5360
- const key = (await io2.readSecret(`${m.catalogue.name} API key (not echoed): `)).trim();
5785
+ const key = (await io2.readSecret(`${moduleNameOf(m)} API key (not echoed): `)).trim();
5361
5786
  if (!key) fail("No key given.");
5362
5787
  const bad = m.checkKey?.(key);
5363
5788
  if (bad) fail(bad);
5364
5789
  const id = opts.id ?? newConnectionId();
5365
- const name = opts.name?.trim() || `${m.catalogue.name} key`;
5790
+ const name = opts.name?.trim() || `${moduleNameOf(m)} key`;
5366
5791
  accounts.upsert({ id, name, type: "api_key", module: moduleId, provider: m.providerId ?? moduleId });
5367
5792
  await accounts.setSecret(id, key);
5368
5793
  const r = await reg.readiness(id);
@@ -5374,7 +5799,7 @@ async function setKey(reg, accounts, connectionId, io2) {
5374
5799
  const c = accounts.get(connectionId) ?? fail(`There is no connection ${connectionId}. See \`monoclaw modules list\`.`);
5375
5800
  if (c.type !== "api_key") fail(`${c.name} is not an API key connection; it has no key.`);
5376
5801
  const m = reg.module(c.module);
5377
- const key = (await io2.readSecret(`${m?.catalogue.name ?? c.module} API key for ${c.name} (not echoed): `)).trim();
5802
+ const key = (await io2.readSecret(`${(m ? moduleNameOf(m) : void 0) ?? c.module} API key for ${c.name} (not echoed): `)).trim();
5378
5803
  if (!key) fail("No key given.");
5379
5804
  const bad = m?.checkKey?.(key);
5380
5805
  if (bad) fail(bad);
@@ -5406,16 +5831,25 @@ function setCap(reg, accounts, connectionId, opts, io2) {
5406
5831
  function fail(message) {
5407
5832
  throw new Error(message);
5408
5833
  }
5834
+ function providesLine(m) {
5835
+ const p = m.manifest.provides;
5836
+ const parts = [];
5837
+ if (p.agent) parts.push("Runs agents");
5838
+ if (p.jobs.includes("speech")) parts.push("Speaks replies");
5839
+ if (p.jobs.includes("transcription")) parts.push("Transcribes voice messages");
5840
+ if (p.tools.length) parts.push(`${p.tools.length} tool${p.tools.length === 1 ? "" : "s"}: ${p.tools.map((t) => t.name).join(", ")}`);
5841
+ return parts.join(" \xB7 ") || "Provides nothing yet";
5842
+ }
5409
5843
 
5410
5844
  // src/enrol.ts
5411
- import { z as z10 } from "zod";
5412
- var EnrolResponse = z10.object({ hostId: z10.string(), credential: z10.string(), hostName: z10.string(), routerUrl: z10.string().optional(), spaceId: z10.string().optional(), spaceHandle: z10.string().optional(), spaceName: z10.string().optional() });
5413
- var EnrolPreview = z10.object({
5414
- space: z10.object({ id: z10.string(), handle: z10.string(), name: z10.string() }),
5845
+ import { z as z11 } from "zod";
5846
+ var EnrolResponse = z11.object({ hostId: z11.string(), credential: z11.string(), hostName: z11.string(), routerUrl: z11.string().optional(), spaceId: z11.string().optional(), spaceHandle: z11.string().optional(), spaceName: z11.string().optional() });
5847
+ var EnrolPreview = z11.object({
5848
+ space: z11.object({ id: z11.string(), handle: z11.string(), name: z11.string() }),
5415
5849
  /** The token re-enrols an existing machine (after a reset) rather than making a new one. */
5416
- reenrol: z10.boolean(),
5850
+ reenrol: z11.boolean(),
5417
5851
  /** Of the host ids we sent, the ones already enrolled in the token's space. */
5418
- sameSpaceHostIds: z10.array(z10.string())
5852
+ sameSpaceHostIds: z11.array(z11.string())
5419
5853
  });
5420
5854
  async function previewToken(routerUrl, token, hostIds, insecure) {
5421
5855
  const base = routerUrl.replace(/\/+$/, "");
@@ -5503,7 +5937,7 @@ import { promisify as promisify5 } from "node:util";
5503
5937
  import { spawn as spawn3 } from "node:child_process";
5504
5938
  import fs17 from "node:fs";
5505
5939
  import path17 from "node:path";
5506
- import { z as z11 } from "zod";
5940
+ import { z as z12 } from "zod";
5507
5941
  var PACKAGE = "@monoclaw/machine";
5508
5942
  function nodeInstallHint(platform) {
5509
5943
  if (platform === "darwin") return "Install Node 22 or newer: `brew install node`, or the LTS installer from https://nodejs.org";
@@ -5522,7 +5956,7 @@ function updateWait(busy2, background, since, now) {
5522
5956
  return now - from < BACKGROUND_WAIT_MS ? { wait: true, why: "background", since: from } : { wait: false, why: null, since: null };
5523
5957
  }
5524
5958
  var INSTALL_TIMEOUT_MS = 5 * 6e4;
5525
- var VersionPolicy = z11.object({ package: z11.string(), latest: z11.string().nullable(), minimum: z11.string().nullable() });
5959
+ var VersionPolicy = z12.object({ package: z12.string(), latest: z12.string().nullable(), minimum: z12.string().nullable() });
5526
5960
  function detectInstallMode(entry = process.argv[1] ?? "") {
5527
5961
  let real = entry;
5528
5962
  try {
@@ -6085,6 +6519,9 @@ ${r.text}`, final: true });
6085
6519
  toolResult(id, result) {
6086
6520
  this.tools.result(id, result);
6087
6521
  }
6522
+ toolStarted(id, readOnly) {
6523
+ this.tools.started(id, readOnly);
6524
+ }
6088
6525
  connectionLost() {
6089
6526
  for (const w of [...this.agentWaits.values()]) w.finish({ error: w.lost });
6090
6527
  this.tools.failWaiting();
@@ -6147,7 +6584,7 @@ import fs20 from "node:fs";
6147
6584
  import os7 from "node:os";
6148
6585
  import path20 from "node:path";
6149
6586
  import { promisify as promisify7 } from "node:util";
6150
- import { z as z12 } from "zod";
6587
+ import { z as z13 } from "zod";
6151
6588
  import { createSdkMcpServer, listSessions, query, tool } from "@anthropic-ai/claude-agent-sdk";
6152
6589
 
6153
6590
  // src/providers/claude/cli.ts
@@ -6488,7 +6925,7 @@ var ClaudeSession = class {
6488
6925
  tool(
6489
6926
  "send_file",
6490
6927
  "Send a file from the working folder to the user in the chat. Use for screenshots, exports, documents, audio. Paths are relative to the working folder; files outside it, or inside dot-folders, cannot be sent.",
6491
- { path: z12.string().describe("Path of the file to send, inside the working folder"), caption: z12.string().optional().describe("Short caption shown with the file") },
6928
+ { path: z13.string().describe("Path of the file to send, inside the working folder"), caption: z13.string().optional().describe("Short caption shown with the file") },
6492
6929
  async (args2) => {
6493
6930
  const full = sendablePath(this.opts.cwd, args2.path);
6494
6931
  if (!full) return { content: [{ type: "text", text: `Only files inside the working folder (${this.opts.cwd}), outside dot-folders, can be sent.` }], isError: true };
@@ -6524,7 +6961,7 @@ var ClaudeSession = class {
6524
6961
  tool(
6525
6962
  "send",
6526
6963
  SEND_TOOL_DESCRIPTION,
6527
- { to: z12.string().min(1).describe("One agent's name from list_agents"), text: z12.string().describe("The message") },
6964
+ { to: z13.string().min(1).describe("One agent's name from list_agents"), text: z13.string().describe("The message") },
6528
6965
  async (args2) => {
6529
6966
  const id = newId();
6530
6967
  const result = new Promise((resolve) => {
@@ -6544,11 +6981,11 @@ var ClaudeSession = class {
6544
6981
  }
6545
6982
  if (s.toolDoors)
6546
6983
  tools.push(
6547
- tool(FIND_TOOLS, FIND_TOOLS_DESCRIPTION, { query: z12.string().max(500).optional().describe("Keywords to search names and descriptions, or `select:name1,name2` for exact names. Leave out to list every tool."), limit: z12.number().int().min(1).max(50).optional().describe("The most matches to return for a keyword query (default 5).") }, async (args2) => this.tools.find(args2), { alwaysLoad: true }),
6984
+ tool(FIND_TOOLS, FIND_TOOLS_DESCRIPTION, { query: z13.string().max(500).optional().describe("Keywords to search names and descriptions, or `select:name1,name2` for exact names. Leave out to list every tool."), limit: z13.number().int().min(1).max(50).optional().describe("The most matches to return for a keyword query (default 5).") }, async (args2) => this.tools.find(args2), { alwaysLoad: true }),
6548
6985
  tool(
6549
6986
  USE_TOOL,
6550
6987
  USE_TOOL_DESCRIPTION,
6551
- { name: z12.string().min(1).max(64).describe("The tool's name, exactly as find_tools gave it"), input: z12.record(z12.string(), z12.unknown()).describe("The tool's input: an object matching the tool's input_schema from find_tools") },
6988
+ { name: z13.string().min(1).max(64).describe("The tool's name, exactly as find_tools gave it"), input: z13.record(z13.string(), z13.unknown()).describe("The tool's input: an object matching the tool's input_schema from find_tools") },
6552
6989
  async (args2) => this.tools.use(args2),
6553
6990
  { alwaysLoad: true }
6554
6991
  )
@@ -6757,6 +7194,9 @@ ${files.map((a) => `- ${a.localPath} (${a.mime}, ${a.size} bytes)${a.note ? `: $
6757
7194
  toolResult(id, result) {
6758
7195
  this.tools.result(id, result);
6759
7196
  }
7197
+ toolStarted(id, readOnly) {
7198
+ this.tools.started(id, readOnly);
7199
+ }
6760
7200
  /** The machine's connection to the service closed: what was waiting for it ends now, each call with its own words. */
6761
7201
  connectionLost() {
6762
7202
  for (const w of [...this.agentWaits.values()]) w.finish({ error: w.lost });
@@ -7418,7 +7858,7 @@ async function readSecret(prompt) {
7418
7858
  });
7419
7859
  }
7420
7860
  var modules = program.command("modules").description("What this machine can do: agent engines, voices, transcription, images (keys stay on this machine)");
7421
- modules.command("list").description("The modules on this machine and their connections; --all shows what you can add").option("--all", "Also list every module you can add").action(async (opts) => {
7861
+ modules.command("list").description("The modules on this machine, what each provides (agents, a voice, transcription, tools) and their connections; --all shows what you can add").option("--all", "Also list every module you can add").action(async (opts) => {
7422
7862
  const { registry } = await makeContext(requireConfig());
7423
7863
  await listModules(registry, io, opts);
7424
7864
  });
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@monoclaw/machine",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@monoclaw/machine",
9
- "version": "1.0.20",
9
+ "version": "1.0.22",
10
10
  "license": "UNLICENSED",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/claude-agent-sdk": "0.3.302",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monoclaw/machine",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "Monoclaw host app: runs agents on your machine and connects them to your Monoclaw account (command.monoclaw.ai).",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -56,6 +56,7 @@
56
56
  "lint": "eslint src tests",
57
57
  "test": "vitest run --exclude tests/claude.e2e.test.ts",
58
58
  "test:claude": "vitest run tests/claude.e2e.test.ts",
59
- "shrinkwrap": "node scripts/shrinkwrap.mjs"
59
+ "shrinkwrap": "node scripts/shrinkwrap.mjs",
60
+ "manifests": "tsx scripts/emit-manifests.ts"
60
61
  }
61
62
  }