@monoclaw/machine 1.0.19 → 1.0.21
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 +544 -143
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -1
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
|
|
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
|
-
|
|
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() });
|
|
@@ -1193,7 +1210,8 @@ var RouterFrame = z4.discriminatedUnion("t", [
|
|
|
1193
1210
|
/** Remove a module and its connections (and their keys). */
|
|
1194
1211
|
z4.object({ t: z4.literal("module.remove"), reqId: z4.string(), module: ModuleId }),
|
|
1195
1212
|
/** The options a module offers for one use (`agent` for an agent's engine, `tts` a voice, `stt` transcription, `image` a tool). */
|
|
1196
|
-
|
|
1213
|
+
/** `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. */
|
|
1214
|
+
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
1215
|
/**
|
|
1198
1216
|
* Do one piece of work with a module and a connection, with the owner's options. Answered with `job.result`. A
|
|
1199
1217
|
* text-to-speech job is one chapter; the server sends a message's chapters one after another.
|
|
@@ -1372,10 +1390,88 @@ var IMAGE_VIEW = {
|
|
|
1372
1390
|
example: { image: "attachment:att_01HZY4K2M7Q8R9S0T1U2V3W4X5" }
|
|
1373
1391
|
};
|
|
1374
1392
|
|
|
1393
|
+
// ../../packages/protocol/src/manifest.ts
|
|
1394
|
+
import { z as z9 } from "zod";
|
|
1395
|
+
var MODULE_ID_PATTERN = /^[a-z][a-z0-9-]{1,40}$/;
|
|
1396
|
+
var TOOL_NAME_PATTERN = /^[a-z][a-z0-9_]{2,63}$/;
|
|
1397
|
+
var ModuleUse = z9.string().regex(/^(agent|speech|transcription|tool:[a-z][a-z0-9_]{2,63})$/);
|
|
1398
|
+
function useFromCapability(capability, imageTool) {
|
|
1399
|
+
if (capability === "agent") return "agent";
|
|
1400
|
+
if (capability === "tts") return "speech";
|
|
1401
|
+
if (capability === "stt") return "transcription";
|
|
1402
|
+
return `tool:${imageTool ?? "image"}`;
|
|
1403
|
+
}
|
|
1404
|
+
var JsonSchema = z9.record(z9.string(), z9.unknown());
|
|
1405
|
+
var ToolDeclaration = z9.object({
|
|
1406
|
+
name: z9.string().regex(TOOL_NAME_PATTERN),
|
|
1407
|
+
title: z9.string().min(1).max(60),
|
|
1408
|
+
description: z9.string().min(1),
|
|
1409
|
+
/** A JSON Schema object with flat properties (`jsonSchemaToZod` says what is allowed). */
|
|
1410
|
+
input: JsonSchema,
|
|
1411
|
+
/** Input fields that name a file: a path the agent's machine uploads, or `attachment:<id>`. */
|
|
1412
|
+
files: z9.array(z9.object({ field: z9.string(), accept: z9.array(z9.string()).min(1), maxMb: z9.number().positive() })).default([]),
|
|
1413
|
+
/** Whether the use `tool:<name>` has settings (§ 5); agent-settable ones are merged into the input. */
|
|
1414
|
+
settings: z9.boolean().default(false),
|
|
1415
|
+
example: z9.record(z9.string(), z9.unknown()),
|
|
1416
|
+
risk: z9.object({ costs: z9.boolean(), writes: z9.boolean(), sends: z9.boolean(), ask: z9.enum(["never", "always"]) }),
|
|
1417
|
+
labels: z9.object({ running: z9.string().min(1).max(40), done: z9.string().min(1).max(40) }),
|
|
1418
|
+
result: z9.object({ views: z9.array(z9.string()).min(1) }),
|
|
1419
|
+
timeoutMs: z9.number().int().positive().max(9e5)
|
|
1420
|
+
});
|
|
1421
|
+
var ModuleManifest = z9.object({
|
|
1422
|
+
manifestVersion: z9.literal(1),
|
|
1423
|
+
id: z9.string().regex(MODULE_ID_PATTERN),
|
|
1424
|
+
version: z9.string().regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/),
|
|
1425
|
+
name: z9.string().min(1).max(60),
|
|
1426
|
+
summary: z9.string().min(1).max(200),
|
|
1427
|
+
description: z9.string().optional(),
|
|
1428
|
+
/** Unknown values show under Other. */
|
|
1429
|
+
category: z9.string().default("other"),
|
|
1430
|
+
publisher: z9.object({ name: z9.string(), tier: z9.enum(["monoclaw", "verified", "custom"]) }).optional(),
|
|
1431
|
+
/** A local model on the machine, or a service on the internet. */
|
|
1432
|
+
runs: z9.enum(["local", "service"]),
|
|
1433
|
+
needs: z9.object({
|
|
1434
|
+
downloadMb: z9.number().nonnegative().optional(),
|
|
1435
|
+
diskMb: z9.number().nonnegative().optional(),
|
|
1436
|
+
memoryMb: z9.number().nonnegative().optional(),
|
|
1437
|
+
gpu: z9.boolean().optional(),
|
|
1438
|
+
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()
|
|
1439
|
+
}).optional(),
|
|
1440
|
+
/**
|
|
1441
|
+
* The credential a module needs: none; an API key (one field, pasted, sealed to the machine); or a login the machine's
|
|
1442
|
+
* own sign-in provides (no field is asked). `several`: more than one key may be added.
|
|
1443
|
+
*/
|
|
1444
|
+
key: z9.object({
|
|
1445
|
+
kind: z9.enum(["api_key", "login"]),
|
|
1446
|
+
label: z9.string(),
|
|
1447
|
+
placeholder: z9.string().optional(),
|
|
1448
|
+
pageUrl: z9.string().optional(),
|
|
1449
|
+
pattern: z9.string().optional(),
|
|
1450
|
+
patternHelp: z9.string().optional(),
|
|
1451
|
+
several: z9.boolean()
|
|
1452
|
+
}).nullable().default(null),
|
|
1453
|
+
cost: z9.object({ unit: z9.enum(["usd", "characters"]), suggestedMonthlyCap: z9.number().positive(), note: z9.string() }).nullable().default(null),
|
|
1454
|
+
provides: z9.object({
|
|
1455
|
+
agent: z9.object({ providerId: z9.string() }).optional(),
|
|
1456
|
+
jobs: z9.array(z9.enum(["speech", "transcription"])).default([]),
|
|
1457
|
+
tools: z9.array(ToolDeclaration).default([])
|
|
1458
|
+
}),
|
|
1459
|
+
/** "Install manually", as today: the module writes its own steps for the machine. */
|
|
1460
|
+
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([])
|
|
1461
|
+
});
|
|
1462
|
+
|
|
1375
1463
|
// src/modules/index.ts
|
|
1376
1464
|
import path11 from "node:path";
|
|
1377
1465
|
|
|
1378
1466
|
// src/modules/types.ts
|
|
1467
|
+
var connectionTypeOf = (m) => m.manifest.key ? m.manifest.key.kind === "login" ? "subscription" : "api_key" : "local";
|
|
1468
|
+
var multipleConnectionsOf = (m) => !!m.manifest.key?.several;
|
|
1469
|
+
var legacyKindOf = (m) => m.manifest.runs === "service" ? "api" : "local";
|
|
1470
|
+
var needsSecretOf = (m) => m.manifest.key?.kind === "api_key";
|
|
1471
|
+
var moduleNameOf = (m) => m.manifest.name;
|
|
1472
|
+
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 });
|
|
1473
|
+
var toolOf = (m, name) => m.manifest.provides.tools.find((t) => t.name === name) ?? null;
|
|
1474
|
+
var imageToolOf = (m) => m.manifest.provides.tools.find((t) => t.result.views.includes("images"))?.name;
|
|
1379
1475
|
function resolveOptions(fields, options, args2 = {}) {
|
|
1380
1476
|
const out = {};
|
|
1381
1477
|
for (const f of fields) if (f.default !== void 0) out[f.key] = f.default;
|
|
@@ -1431,9 +1527,19 @@ function claudeSubscriptionModule(probe) {
|
|
|
1431
1527
|
return {
|
|
1432
1528
|
id: "claude-subscription",
|
|
1433
1529
|
version: "1.0.0",
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1530
|
+
manifest: {
|
|
1531
|
+
manifestVersion: 1,
|
|
1532
|
+
id: "claude-subscription",
|
|
1533
|
+
name: "Claude (subscription)",
|
|
1534
|
+
summary: "Your agents run on Claude Code with this machine's own Claude login, on your Claude subscription.",
|
|
1535
|
+
category: "agents",
|
|
1536
|
+
publisher: { name: "MonoClaw", tier: "monoclaw" },
|
|
1537
|
+
runs: "local",
|
|
1538
|
+
key: { kind: "login", label: "Claude login", several: false },
|
|
1539
|
+
cost: null,
|
|
1540
|
+
provides: { agent: { providerId: "claude" }, jobs: [], tools: [] }
|
|
1541
|
+
},
|
|
1542
|
+
legacyCapabilities: ["agent"],
|
|
1437
1543
|
providerId: "claude",
|
|
1438
1544
|
defaultConnection: { id: "claude", name: "Claude Code" },
|
|
1439
1545
|
status: () => ({ state: "ready", progress: null, summary: "" }),
|
|
@@ -1446,9 +1552,19 @@ function claudeApiModule(probe) {
|
|
|
1446
1552
|
return {
|
|
1447
1553
|
id: "claude-api",
|
|
1448
1554
|
version: "1.0.0",
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1555
|
+
manifest: {
|
|
1556
|
+
manifestVersion: 1,
|
|
1557
|
+
id: "claude-api",
|
|
1558
|
+
name: "Claude (API key)",
|
|
1559
|
+
summary: "Your agents run on Claude Code with an Anthropic API key, billed to that key. Add one key per team or budget.",
|
|
1560
|
+
category: "agents",
|
|
1561
|
+
publisher: { name: "MonoClaw", tier: "monoclaw" },
|
|
1562
|
+
runs: "service",
|
|
1563
|
+
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 },
|
|
1564
|
+
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." },
|
|
1565
|
+
provides: { agent: { providerId: "claude" }, jobs: [], tools: [] }
|
|
1566
|
+
},
|
|
1567
|
+
legacyCapabilities: ["agent"],
|
|
1452
1568
|
providerId: "claude",
|
|
1453
1569
|
status: () => ({ state: "ready", progress: null, summary: "" }),
|
|
1454
1570
|
checkKey: (key) => ANTHROPIC_KEY_RE.test(key) ? null : "That does not look like an Anthropic API key; it starts with sk-ant-.",
|
|
@@ -1462,6 +1578,51 @@ function claudeApiModule(probe) {
|
|
|
1462
1578
|
};
|
|
1463
1579
|
}
|
|
1464
1580
|
|
|
1581
|
+
// src/modules/declare.ts
|
|
1582
|
+
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" } };
|
|
1583
|
+
var SPEAK_MAX_CHARS = 9e3;
|
|
1584
|
+
function speakTool(name, service2, costs) {
|
|
1585
|
+
return {
|
|
1586
|
+
name,
|
|
1587
|
+
title: "Make audio",
|
|
1588
|
+
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.`,
|
|
1589
|
+
input: { type: "object", properties: { text: { type: "string", description: "The text to speak", minLength: 1, maxLength: SPEAK_MAX_CHARS } }, required: ["text"], additionalProperties: false },
|
|
1590
|
+
files: [],
|
|
1591
|
+
settings: true,
|
|
1592
|
+
example: { text: "Good morning. Here is today's summary." },
|
|
1593
|
+
risk: { costs, writes: false, sends: false, ask: "never" },
|
|
1594
|
+
labels: { running: "Making audio", done: "Made audio" },
|
|
1595
|
+
result: { views: ["audio", "text"] },
|
|
1596
|
+
timeoutMs: 3e5
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
function transcribeTool(name, service2, costs) {
|
|
1600
|
+
return {
|
|
1601
|
+
name,
|
|
1602
|
+
title: "Transcribe a recording",
|
|
1603
|
+
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.`,
|
|
1604
|
+
input: { type: "object", properties: { file: { type: "string", description: "The audio or video file: a path, or attachment:<id>", minLength: 1 } }, required: ["file"], additionalProperties: false },
|
|
1605
|
+
files: [{ field: "file", accept: ["audio/*", "video/*"], maxMb: 20 }],
|
|
1606
|
+
settings: true,
|
|
1607
|
+
example: { file: "recordings/interview.m4a" },
|
|
1608
|
+
risk: { costs, writes: false, sends: false, ask: "never" },
|
|
1609
|
+
labels: { running: "Transcribing", done: "Transcribed a recording" },
|
|
1610
|
+
result: { views: ["text"] },
|
|
1611
|
+
timeoutMs: 6e5
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
function settableArgs(fields, input) {
|
|
1615
|
+
const out = {};
|
|
1616
|
+
for (const f of fields) {
|
|
1617
|
+
const v = input[f.key];
|
|
1618
|
+
if (f.agentSettable && (typeof v === "string" || typeof v === "number" || typeof v === "boolean")) out[f.key] = v;
|
|
1619
|
+
}
|
|
1620
|
+
return out;
|
|
1621
|
+
}
|
|
1622
|
+
function unknownTool(moduleName, name, tools) {
|
|
1623
|
+
return new Error(`${moduleName} has no tool "${name}". Its tools: ${tools.map((t) => t.name).join(", ") || "none"}.`);
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1465
1626
|
// src/modules/echo.ts
|
|
1466
1627
|
var PIXEL = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==", "base64");
|
|
1467
1628
|
function silentWav(durationMs, voice) {
|
|
@@ -1497,17 +1658,81 @@ var IMAGE_FIELDS = [
|
|
|
1497
1658
|
var echoModule = {
|
|
1498
1659
|
id: "echo",
|
|
1499
1660
|
version: "1.0.0",
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1661
|
+
manifest: {
|
|
1662
|
+
manifestVersion: 1,
|
|
1663
|
+
id: "echo",
|
|
1664
|
+
name: "Echo (test)",
|
|
1665
|
+
summary: "Repeats what you say, and fakes voices, transcripts and images. For testing without a model.",
|
|
1666
|
+
category: "other",
|
|
1667
|
+
publisher: { name: "MonoClaw", tier: "monoclaw" },
|
|
1668
|
+
runs: "local",
|
|
1669
|
+
key: null,
|
|
1670
|
+
cost: null,
|
|
1671
|
+
provides: {
|
|
1672
|
+
agent: { providerId: "echo" },
|
|
1673
|
+
jobs: ["speech", "transcription"],
|
|
1674
|
+
tools: [
|
|
1675
|
+
{
|
|
1676
|
+
name: "echo_image",
|
|
1677
|
+
title: "Make a test image",
|
|
1678
|
+
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.",
|
|
1679
|
+
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 },
|
|
1680
|
+
files: [{ field: "reference_image", accept: ["image/*"], maxMb: 8 }],
|
|
1681
|
+
settings: true,
|
|
1682
|
+
example: { prompt: "a red fox" },
|
|
1683
|
+
risk: { costs: false, writes: false, sends: false, ask: "never" },
|
|
1684
|
+
labels: { running: "Making an image", done: "Made an image" },
|
|
1685
|
+
result: { views: ["images", "text"] },
|
|
1686
|
+
timeoutMs: 3e4
|
|
1687
|
+
},
|
|
1688
|
+
speakTool("echo_speak", "the echo module (silence of the right length)", false),
|
|
1689
|
+
transcribeTool("echo_transcribe", "the echo module (it reports the bytes it heard)", false),
|
|
1690
|
+
{
|
|
1691
|
+
name: "echo_lookup",
|
|
1692
|
+
title: "Look something up",
|
|
1693
|
+
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.",
|
|
1694
|
+
input: { type: "object", properties: { query: { type: "string", description: "What to look up", minLength: 1 } }, required: ["query"], additionalProperties: false },
|
|
1695
|
+
files: [],
|
|
1696
|
+
settings: false,
|
|
1697
|
+
example: { query: "harbour" },
|
|
1698
|
+
risk: { costs: false, writes: false, sends: false, ask: "never" },
|
|
1699
|
+
labels: { running: "Looking it up", done: "Looked it up" },
|
|
1700
|
+
result: { views: ["text", "files"] },
|
|
1701
|
+
timeoutMs: 3e4
|
|
1702
|
+
}
|
|
1703
|
+
]
|
|
1704
|
+
}
|
|
1705
|
+
},
|
|
1706
|
+
legacyCapabilities: ["agent", "tts", "stt", "image"],
|
|
1503
1707
|
providerId: "echo",
|
|
1504
1708
|
defaultConnection: { id: "echo", name: "Echo (test)" },
|
|
1505
1709
|
status: () => ({ state: "ready", progress: null, summary: "Ready" }),
|
|
1506
1710
|
readiness: async () => ({ ready: true, summary: "Ready", details: {} }),
|
|
1507
|
-
async options(
|
|
1508
|
-
return
|
|
1711
|
+
async options(use) {
|
|
1712
|
+
return use === "speech" || use === "tool:echo_speak" ? TTS_FIELDS : use === "transcription" || use === "tool:echo_transcribe" ? STT_FIELDS : use === "tool:echo_image" ? IMAGE_FIELDS : [];
|
|
1509
1713
|
},
|
|
1510
1714
|
estimate: (job) => job.capability === "tts" ? { characters: job.text.length } : {},
|
|
1715
|
+
async runTool(name, input, files, options, conn, secret) {
|
|
1716
|
+
if (name === "echo_speak") return this.run({ capability: "tts", text: String(input.text ?? ""), options: resolveOptions(TTS_FIELDS, options, settableArgs(TTS_FIELDS, input)) }, conn, secret);
|
|
1717
|
+
if (name === "echo_transcribe") {
|
|
1718
|
+
const file = files.find((f) => f.field === "file");
|
|
1719
|
+
if (!file) throw new Error("echo_transcribe needs the file to transcribe.");
|
|
1720
|
+
return this.run({ capability: "stt", audio: file.bytes, mime: file.mime, options: resolveOptions(STT_FIELDS, options, settableArgs(STT_FIELDS, input)) }, conn, secret);
|
|
1721
|
+
}
|
|
1722
|
+
if (name === "echo_image") {
|
|
1723
|
+
const ref = files.find((f) => f.field === "reference_image");
|
|
1724
|
+
return this.run({ capability: "image", prompt: String(input.prompt ?? ""), args: settableArgs(IMAGE_FIELDS, input), options, ...ref ? { reference: { bytes: ref.bytes, mime: ref.mime } } : {} }, conn, secret);
|
|
1725
|
+
}
|
|
1726
|
+
if (name === "echo_lookup") {
|
|
1727
|
+
const q = String(input.query ?? "").trim();
|
|
1728
|
+
const csv = `query,answer
|
|
1729
|
+
${JSON.stringify(q)},${JSON.stringify(`echo found ${q}`)}
|
|
1730
|
+
${JSON.stringify(q)},${JSON.stringify(`echo found ${q} again`)}
|
|
1731
|
+
`;
|
|
1732
|
+
return { files: [{ bytes: Buffer.from(csv, "utf8"), mime: "text/csv", name: "lookup.csv" }], text: `Looked up "${q}": 2 rows, in lookup.csv.` };
|
|
1733
|
+
}
|
|
1734
|
+
throw unknownTool("Echo (test)", name, this.manifest.provides.tools);
|
|
1735
|
+
},
|
|
1511
1736
|
async run(job) {
|
|
1512
1737
|
if (job.capability === "tts") {
|
|
1513
1738
|
const o2 = resolveOptions(TTS_FIELDS, job.options);
|
|
@@ -1516,6 +1741,7 @@ var echoModule = {
|
|
|
1516
1741
|
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
1742
|
}
|
|
1518
1743
|
if (job.capability === "stt") return { files: [], text: `echo heard ${job.audio.length} bytes of ${job.mime}`, language: "en", usage: { amount: 1, unit: "seconds" } };
|
|
1744
|
+
if (job.capability === "tool") throw new Error("echo runs its tools through runTool.");
|
|
1519
1745
|
const o = resolveOptions(IMAGE_FIELDS, job.options, job.args);
|
|
1520
1746
|
const n = Math.max(1, Math.min(4, Math.round(num(o.num_images, 1))));
|
|
1521
1747
|
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 +1899,19 @@ function elevenlabsModule(deps = {}) {
|
|
|
1673
1899
|
return {
|
|
1674
1900
|
id: "elevenlabs",
|
|
1675
1901
|
version: "1.0.0",
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1902
|
+
manifest: {
|
|
1903
|
+
manifestVersion: 1,
|
|
1904
|
+
id: "elevenlabs",
|
|
1905
|
+
name: "ElevenLabs",
|
|
1906
|
+
summary: "Your agents speak with your ElevenLabs voices, your own clones included, and voice messages are transcribed with Scribe, on your ElevenLabs key.",
|
|
1907
|
+
category: "voice",
|
|
1908
|
+
publisher: { name: "MonoClaw", tier: "monoclaw" },
|
|
1909
|
+
runs: "service",
|
|
1910
|
+
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 },
|
|
1911
|
+
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." },
|
|
1912
|
+
provides: { jobs: ["speech", "transcription"], tools: [speakTool("elevenlabs_speak", "ElevenLabs", true), transcribeTool("elevenlabs_transcribe", "ElevenLabs", true)] }
|
|
1913
|
+
},
|
|
1914
|
+
legacyCapabilities: ["tts", "stt"],
|
|
1679
1915
|
status: () => ({ state: "ready", progress: null, summary: "" }),
|
|
1680
1916
|
checkKey: (key) => key.trim().length >= 20 && !/\s/.test(key.trim()) ? null : "That does not look like an ElevenLabs API key.",
|
|
1681
1917
|
async readiness(_conn, secret) {
|
|
@@ -1689,9 +1925,9 @@ function elevenlabsModule(deps = {}) {
|
|
|
1689
1925
|
return notReady(e.message, e instanceof ServiceError && e.status === 401 ? "Enter the key again." : void 0);
|
|
1690
1926
|
}
|
|
1691
1927
|
},
|
|
1692
|
-
async options(
|
|
1693
|
-
if (
|
|
1694
|
-
if (
|
|
1928
|
+
async options(use, _conn, secret) {
|
|
1929
|
+
if (use === "transcription" || use === "tool:elevenlabs_transcribe") return ELEVENLABS_STT_FIELDS;
|
|
1930
|
+
if (use !== "speech" && use !== "tool:elevenlabs_speak") throw new Error("ElevenLabs makes speech and transcripts, not images.");
|
|
1695
1931
|
const key = needKey(secret);
|
|
1696
1932
|
const [v, m] = await Promise.all([voices(key), models(key)]);
|
|
1697
1933
|
return [
|
|
@@ -1699,7 +1935,18 @@ function elevenlabsModule(deps = {}) {
|
|
|
1699
1935
|
{ 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
1936
|
];
|
|
1701
1937
|
},
|
|
1702
|
-
estimate: (job) => job.capability === "tts" ? { characters: job.text.length } : {},
|
|
1938
|
+
estimate: (job) => job.capability === "tts" ? { characters: job.text.length } : job.capability === "tool" && job.tool === "elevenlabs_speak" ? { characters: String(job.input.text ?? "").length } : {},
|
|
1939
|
+
async runTool(name, input, files, options, conn, secret) {
|
|
1940
|
+
if (name === "elevenlabs_speak") {
|
|
1941
|
+
return this.run({ capability: "tts", text: String(input.text ?? ""), options: { ...options, ...settableArgs(await this.options("speech", conn, secret), input) } }, conn, secret);
|
|
1942
|
+
}
|
|
1943
|
+
if (name === "elevenlabs_transcribe") {
|
|
1944
|
+
const file = files.find((f2) => f2.field === "file");
|
|
1945
|
+
if (!file) throw new Error("elevenlabs_transcribe needs the file to transcribe.");
|
|
1946
|
+
return this.run({ capability: "stt", audio: file.bytes, mime: file.mime, options: resolveOptions(ELEVENLABS_STT_FIELDS, options, settableArgs(ELEVENLABS_STT_FIELDS, input)) }, conn, secret);
|
|
1947
|
+
}
|
|
1948
|
+
throw unknownTool("ElevenLabs", name, this.manifest.provides.tools);
|
|
1949
|
+
},
|
|
1703
1950
|
async run(job, conn, secret) {
|
|
1704
1951
|
const key = needKey(secret);
|
|
1705
1952
|
if (job.capability === "tts") {
|
|
@@ -1757,6 +2004,24 @@ var FAL_FIELDS = [
|
|
|
1757
2004
|
{ key: "output_format", label: "Format", type: "select", choices: [{ value: "jpeg", label: "JPEG" }, { value: "png", label: "PNG" }], default: "jpeg", required: false, agentSettable: true },
|
|
1758
2005
|
{ key: "enable_safety_checker", label: "Safety checker", type: "boolean", default: true, required: false, agentSettable: true }
|
|
1759
2006
|
];
|
|
2007
|
+
var FAL_IMAGE_TOOL = {
|
|
2008
|
+
name: "fal_image",
|
|
2009
|
+
title: "Make an image",
|
|
2010
|
+
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.",
|
|
2011
|
+
input: {
|
|
2012
|
+
type: "object",
|
|
2013
|
+
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>" } },
|
|
2014
|
+
required: ["prompt"],
|
|
2015
|
+
additionalProperties: false
|
|
2016
|
+
},
|
|
2017
|
+
files: [{ field: "reference_image", accept: ["image/png", "image/jpeg", "image/webp"], maxMb: MAX_REFERENCE / 1024 / 1024 }],
|
|
2018
|
+
settings: true,
|
|
2019
|
+
example: { prompt: "A red kite flying over a harbour at dusk, watercolour" },
|
|
2020
|
+
risk: { costs: true, writes: false, sends: false, ask: "never" },
|
|
2021
|
+
labels: { running: "Making an image", done: "Made an image" },
|
|
2022
|
+
result: { views: ["images", "text"] },
|
|
2023
|
+
timeoutMs: 18e4
|
|
2024
|
+
};
|
|
1760
2025
|
function falInput(model, prompt, o) {
|
|
1761
2026
|
const size = str(o.image_size, "landscape_4_3");
|
|
1762
2027
|
const preset = IMAGE_SIZES[size] ?? IMAGE_SIZES.landscape_4_3;
|
|
@@ -1810,9 +2075,19 @@ function falModule(deps = {}) {
|
|
|
1810
2075
|
return {
|
|
1811
2076
|
id: "fal",
|
|
1812
2077
|
version: "1.0.0",
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
2078
|
+
manifest: {
|
|
2079
|
+
manifestVersion: 1,
|
|
2080
|
+
id: "fal",
|
|
2081
|
+
name: "fal.ai",
|
|
2082
|
+
summary: "Your agents make images with FLUX and other models on fal.ai, on your fal key.",
|
|
2083
|
+
category: "images",
|
|
2084
|
+
publisher: { name: "MonoClaw", tier: "monoclaw" },
|
|
2085
|
+
runs: "service",
|
|
2086
|
+
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 },
|
|
2087
|
+
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." },
|
|
2088
|
+
provides: { jobs: [], tools: [FAL_IMAGE_TOOL] }
|
|
2089
|
+
},
|
|
2090
|
+
legacyCapabilities: ["image"],
|
|
1816
2091
|
status: () => ({ state: "ready", progress: null, summary: "" }),
|
|
1817
2092
|
checkKey: (key) => /^[\w-]+:[\w-]+$/.test(key.trim()) ? null : "That does not look like a fal key (<key id>:<secret>).",
|
|
1818
2093
|
async readiness(_conn, secret) {
|
|
@@ -1832,15 +2107,20 @@ function falModule(deps = {}) {
|
|
|
1832
2107
|
if (res.status === 403 && err.code !== "rejected_key") return { ready: true, summary: "Ready (this key can't see the balance)", details: {} };
|
|
1833
2108
|
return notReady(err.message, "Enter the key again.");
|
|
1834
2109
|
},
|
|
1835
|
-
async options(
|
|
1836
|
-
if (
|
|
2110
|
+
async options(use) {
|
|
2111
|
+
if (use !== "tool:fal_image") throw new Error("fal makes images.");
|
|
1837
2112
|
return FAL_FIELDS;
|
|
1838
2113
|
},
|
|
1839
2114
|
estimate(job) {
|
|
2115
|
+
if (job.capability === "tool") return job.tool === "fal_image" ? this.estimate(asImageJob(job)) : {};
|
|
1840
2116
|
if (job.capability !== "image") return {};
|
|
1841
2117
|
const o = resolved(job);
|
|
1842
2118
|
return { usd: falEstimateUsd(modelOf(o), o) };
|
|
1843
2119
|
},
|
|
2120
|
+
async runTool(name, input, files, options, conn, secret) {
|
|
2121
|
+
if (name !== "fal_image") throw unknownTool(this.manifest.name, name, this.manifest.provides.tools);
|
|
2122
|
+
return this.run(asImageJob({ capability: "tool", tool: name, input, files, options }), conn, secret);
|
|
2123
|
+
},
|
|
1844
2124
|
async run(job, _conn, secret) {
|
|
1845
2125
|
if (job.capability !== "image") throw new Error("fal makes images.");
|
|
1846
2126
|
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 +2170,10 @@ function falModule(deps = {}) {
|
|
|
1890
2170
|
}
|
|
1891
2171
|
};
|
|
1892
2172
|
}
|
|
2173
|
+
function asImageJob(job) {
|
|
2174
|
+
const ref = job.files.find((f) => f.field === "reference_image");
|
|
2175
|
+
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 } } : {} };
|
|
2176
|
+
}
|
|
1893
2177
|
function isFalCdn(u) {
|
|
1894
2178
|
const h = u.hostname.toLowerCase();
|
|
1895
2179
|
if (h === "fal.media" || h.endsWith(".fal.media") || h === "fal.ai" || h.endsWith(".fal.ai") || h.endsWith(".fal.run")) return true;
|
|
@@ -2718,36 +3002,36 @@ var ENGINE_VERSION = "1.0.0";
|
|
|
2718
3002
|
var MODEL_VERSION = "kokoro-v1.0+parakeet-tdt-0.6b-v2";
|
|
2719
3003
|
|
|
2720
3004
|
// ../../packages/voice-recipe/src/recipe.ts
|
|
2721
|
-
import { z as
|
|
3005
|
+
import { z as z10 } from "zod";
|
|
2722
3006
|
var RECIPE_VERSION = 1;
|
|
2723
3007
|
var TONES = ["natural", "warm", "bright", "radio", "phone"];
|
|
2724
3008
|
var REVERBS = ["off", "room", "hall"];
|
|
2725
3009
|
var LEVEL_MODES = ["loudness", "peak"];
|
|
2726
3010
|
var CONTENT_TYPES = { ogg: "audio/ogg", mp3: "audio/mpeg", wav: "audio/wav", m4a: "audio/mp4" };
|
|
2727
|
-
var blendPartSchema =
|
|
2728
|
-
var voiceRecipeSchema =
|
|
2729
|
-
version:
|
|
3011
|
+
var blendPartSchema = z10.object({ voice: z10.string().min(1).max(64), weight: z10.number().min(0).max(1) });
|
|
3012
|
+
var voiceRecipeSchema = z10.object({
|
|
3013
|
+
version: z10.literal(RECIPE_VERSION).default(RECIPE_VERSION),
|
|
2730
3014
|
/** TTS model id the base voice belongs to. */
|
|
2731
|
-
model:
|
|
3015
|
+
model: z10.string().min(1).max(64).default("kokoro-v1.0"),
|
|
2732
3016
|
/** Base voice id, e.g. `bf_emma`. */
|
|
2733
|
-
voice:
|
|
3017
|
+
voice: z10.string().min(1).max(64),
|
|
2734
3018
|
/**
|
|
2735
3019
|
* Up to two voices with weights. Reserved for engines that can mix style vectors; engine 1.x renders the heaviest
|
|
2736
3020
|
* voice (or `voice` when the list is empty) and reports `blend: false` in its capabilities.
|
|
2737
3021
|
*/
|
|
2738
|
-
blend:
|
|
2739
|
-
speed:
|
|
2740
|
-
pitchSemitones:
|
|
2741
|
-
tone:
|
|
2742
|
-
reverb:
|
|
2743
|
-
normalize:
|
|
2744
|
-
levelMode:
|
|
3022
|
+
blend: z10.array(blendPartSchema).max(2).default([]),
|
|
3023
|
+
speed: z10.number().min(0.5).max(2).default(1),
|
|
3024
|
+
pitchSemitones: z10.number().min(-12).max(12).default(0),
|
|
3025
|
+
tone: z10.enum(TONES).default("natural"),
|
|
3026
|
+
reverb: z10.enum(REVERBS).default("off"),
|
|
3027
|
+
normalize: z10.boolean().default(true),
|
|
3028
|
+
levelMode: z10.enum(LEVEL_MODES).default("loudness"),
|
|
2745
3029
|
/** Mono speech target; −19 LUFS mono is the −16 LUFS stereo guidance. */
|
|
2746
|
-
targetLufs:
|
|
2747
|
-
truePeakDb:
|
|
2748
|
-
gainDb:
|
|
3030
|
+
targetLufs: z10.number().min(-30).max(-10).default(-19),
|
|
3031
|
+
truePeakDb: z10.number().min(-6).max(0).default(-1),
|
|
3032
|
+
gainDb: z10.number().min(-20).max(20).default(0),
|
|
2749
3033
|
/** Pause length between sentences, as the synthesiser's silence scale. */
|
|
2750
|
-
silenceScale:
|
|
3034
|
+
silenceScale: z10.number().min(0).max(2).default(0.2)
|
|
2751
3035
|
});
|
|
2752
3036
|
var round3 = (n) => Math.round(n * 1e3) / 1e3;
|
|
2753
3037
|
function normaliseRecipe(input) {
|
|
@@ -3285,9 +3569,20 @@ function kokoroModule(voice) {
|
|
|
3285
3569
|
return {
|
|
3286
3570
|
id: "kokoro",
|
|
3287
3571
|
version: "1.0.0",
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3572
|
+
manifest: {
|
|
3573
|
+
manifestVersion: 1,
|
|
3574
|
+
id: "kokoro",
|
|
3575
|
+
name: "Kokoro",
|
|
3576
|
+
summary: "A voice for your agents, made on this machine. 54 voices in nine languages, free and private.",
|
|
3577
|
+
category: "voice",
|
|
3578
|
+
publisher: { name: "MonoClaw", tier: "monoclaw" },
|
|
3579
|
+
runs: "local",
|
|
3580
|
+
needs: { downloadMb: 385, programs: [FFMPEG] },
|
|
3581
|
+
key: null,
|
|
3582
|
+
cost: null,
|
|
3583
|
+
provides: { jobs: ["speech"], tools: [speakTool("kokoro_speak", "Kokoro, on this machine", false)] }
|
|
3584
|
+
},
|
|
3585
|
+
legacyCapabilities: ["tts"],
|
|
3291
3586
|
defaultConnection: { id: "kokoro", name: "This machine" },
|
|
3292
3587
|
status: () => install.status(),
|
|
3293
3588
|
install: (onProgress) => install.run(onProgress),
|
|
@@ -3299,7 +3594,11 @@ function kokoroModule(voice) {
|
|
|
3299
3594
|
async options() {
|
|
3300
3595
|
return KOKORO_FIELDS;
|
|
3301
3596
|
},
|
|
3302
|
-
estimate: (job) => job.capability === "tts" ? { characters: job.text.length } : {},
|
|
3597
|
+
estimate: (job) => job.capability === "tts" ? { characters: job.text.length } : job.capability === "tool" ? { characters: String(job.input.text ?? "").length } : {},
|
|
3598
|
+
async runTool(name, input, _files, options, conn, secret) {
|
|
3599
|
+
if (name !== "kokoro_speak") throw unknownTool("Kokoro", name, this.manifest.provides.tools);
|
|
3600
|
+
return this.run({ capability: "tts", text: String(input.text ?? ""), options: resolveOptions(KOKORO_FIELDS, options, settableArgs(KOKORO_FIELDS, input)) }, conn, secret);
|
|
3601
|
+
},
|
|
3303
3602
|
async run(job) {
|
|
3304
3603
|
if (job.capability !== "tts") throw new Error("Kokoro only makes speech.");
|
|
3305
3604
|
const s = install.status();
|
|
@@ -3365,9 +3664,20 @@ function parakeetModule(voice) {
|
|
|
3365
3664
|
return {
|
|
3366
3665
|
id: "parakeet",
|
|
3367
3666
|
version: "1.0.0",
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3667
|
+
manifest: {
|
|
3668
|
+
manifestVersion: 1,
|
|
3669
|
+
id: "parakeet",
|
|
3670
|
+
name: "Parakeet",
|
|
3671
|
+
summary: "Turns voice messages into text on this machine. English, or 25 European languages, free and private.",
|
|
3672
|
+
category: "voice",
|
|
3673
|
+
publisher: { name: "MonoClaw", tier: "monoclaw" },
|
|
3674
|
+
runs: "local",
|
|
3675
|
+
needs: { downloadMb: 520, programs: [FFMPEG] },
|
|
3676
|
+
key: null,
|
|
3677
|
+
cost: null,
|
|
3678
|
+
provides: { jobs: ["transcription"], tools: [transcribeTool("parakeet_transcribe", "Parakeet, on this machine", false)] }
|
|
3679
|
+
},
|
|
3680
|
+
legacyCapabilities: ["stt"],
|
|
3371
3681
|
defaultConnection: { id: "parakeet", name: "This machine" },
|
|
3372
3682
|
status() {
|
|
3373
3683
|
const s = install.status();
|
|
@@ -3383,6 +3693,12 @@ function parakeetModule(voice) {
|
|
|
3383
3693
|
async options() {
|
|
3384
3694
|
return PARAKEET_FIELDS;
|
|
3385
3695
|
},
|
|
3696
|
+
async runTool(name, input, files, options, conn, secret) {
|
|
3697
|
+
if (name !== "parakeet_transcribe") throw unknownTool("Parakeet", name, this.manifest.provides.tools);
|
|
3698
|
+
const file = files.find((f) => f.field === "file");
|
|
3699
|
+
if (!file) throw new Error("parakeet_transcribe needs the file to transcribe.");
|
|
3700
|
+
return this.run({ capability: "stt", audio: file.bytes, mime: file.mime, options: resolveOptions(PARAKEET_FIELDS, options, settableArgs(PARAKEET_FIELDS, input)) }, conn, secret);
|
|
3701
|
+
},
|
|
3386
3702
|
async run(job) {
|
|
3387
3703
|
if (job.capability !== "stt") throw new Error("Parakeet only transcribes.");
|
|
3388
3704
|
const s = install.status();
|
|
@@ -3458,35 +3774,30 @@ function toWav(input, ffmpeg = "ffmpeg") {
|
|
|
3458
3774
|
}
|
|
3459
3775
|
|
|
3460
3776
|
// 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
3777
|
function moduleSetup(m, platform = process.platform) {
|
|
3472
3778
|
const steps = [];
|
|
3473
|
-
const name = m.
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3779
|
+
const name = m.manifest.name;
|
|
3780
|
+
const key = m.manifest.key;
|
|
3781
|
+
const needs = m.manifest.needs;
|
|
3782
|
+
for (const p of needs?.programs ?? []) {
|
|
3783
|
+
const command = p.install[platform === "darwin" ? "darwin" : platform === "win32" ? "win32" : "linux"] ?? p.install.linux ?? p.install.darwin ?? p.install.win32;
|
|
3784
|
+
steps.push({ title: `Install ${p.name}`, ...command ? { command } : {}, detail: `${name} ${p.why}` });
|
|
3785
|
+
}
|
|
3786
|
+
if (m.manifest.provides.agent?.providerId === "claude") {
|
|
3478
3787
|
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
3788
|
}
|
|
3480
|
-
|
|
3481
|
-
|
|
3789
|
+
const downloadMb = needs?.downloadMb ?? null;
|
|
3790
|
+
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 });
|
|
3791
|
+
if (key?.kind === "login") {
|
|
3482
3792
|
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
3793
|
}
|
|
3484
|
-
if (
|
|
3485
|
-
const page =
|
|
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.${
|
|
3487
|
-
|
|
3794
|
+
if (key?.kind === "api_key") {
|
|
3795
|
+
const page = key.pageUrl ? { label: new URL(key.pageUrl).hostname, url: key.pageUrl } : void 0;
|
|
3796
|
+
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 } : {} });
|
|
3797
|
+
const cost = m.manifest.cost;
|
|
3798
|
+
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
3799
|
}
|
|
3489
|
-
steps.push({ title: "Check it", command: "monoclaw modules list", detail:
|
|
3800
|
+
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
3801
|
return steps.map((st) => st.command ? { ...st, command: withProfile(st.command) } : st);
|
|
3491
3802
|
}
|
|
3492
3803
|
function withProfile(command, profile = currentProfile()) {
|
|
@@ -3597,10 +3908,12 @@ var ModuleRegistry = class {
|
|
|
3597
3908
|
this.deps = deps;
|
|
3598
3909
|
this.voice = deps.voice ?? new LocalVoice(sharedDir());
|
|
3599
3910
|
this.voice.changed = () => this.changed();
|
|
3600
|
-
this.all = { ...defaultModules({ providers: deps.providers, voice: this.voice, fetch: deps.fetch })
|
|
3911
|
+
this.all = { ...defaultModules({ providers: deps.providers, voice: this.voice, fetch: deps.fetch }) };
|
|
3912
|
+
for (const [id, m] of Object.entries(deps.modules ?? {})) if (m) this.all[id] = m;
|
|
3601
3913
|
this.ledger = deps.ledger ?? new UsageLedger(path11.join(configDir(), "usage.json"));
|
|
3602
3914
|
}
|
|
3603
3915
|
deps;
|
|
3916
|
+
/** Every module this program carries, by id (a module is no longer one of a fixed list: docs/spec/modules.md § 3). */
|
|
3604
3917
|
all;
|
|
3605
3918
|
ledger;
|
|
3606
3919
|
voice;
|
|
@@ -3619,17 +3932,21 @@ var ModuleRegistry = class {
|
|
|
3619
3932
|
return this.deps.echo ?? echoFromEnv();
|
|
3620
3933
|
}
|
|
3621
3934
|
module(id) {
|
|
3622
|
-
return
|
|
3935
|
+
return this.all[id] ?? null;
|
|
3623
3936
|
}
|
|
3624
3937
|
/** What this machine can install, each with its version and its setup steps for this platform. */
|
|
3625
3938
|
catalogue() {
|
|
3626
|
-
return
|
|
3939
|
+
return Object.keys(this.all).filter((id) => id !== "echo" || this.echoAllowed()).map((id) => {
|
|
3627
3940
|
const m = this.all[id];
|
|
3628
|
-
return { ...m
|
|
3941
|
+
return { ...legacyCatalogueOf(m), version: m.version, setup: moduleSetup(m), manifest: this.manifestOf(m) };
|
|
3629
3942
|
});
|
|
3630
3943
|
}
|
|
3944
|
+
/** 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). */
|
|
3945
|
+
manifestOf(m) {
|
|
3946
|
+
return { ...m.manifest, version: m.version, setup: moduleSetup(m) };
|
|
3947
|
+
}
|
|
3631
3948
|
installedIds() {
|
|
3632
|
-
const ids = this.deps.config.get().modules.map((m) => m.id).filter((id) =>
|
|
3949
|
+
const ids = this.deps.config.get().modules.map((m) => m.id).filter((id) => id in this.all);
|
|
3633
3950
|
if (this.echoAllowed() && !ids.includes("echo")) ids.push("echo");
|
|
3634
3951
|
return [...new Set(ids)];
|
|
3635
3952
|
}
|
|
@@ -3668,11 +3985,11 @@ var ModuleRegistry = class {
|
|
|
3668
3985
|
const c = this.connection(connectionId);
|
|
3669
3986
|
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
3987
|
const m = this.all[c.module];
|
|
3671
|
-
if (!m?.providerId) return `${c.name} is a ${m
|
|
3988
|
+
if (!m?.providerId) return `${c.name} is a ${m ? moduleNameOf(m) : c.module} connection, not an agent engine.`;
|
|
3672
3989
|
if (m.providerId !== providerId) return `${c.name} runs ${m.providerId}, not ${providerId}.`;
|
|
3673
3990
|
return null;
|
|
3674
3991
|
}
|
|
3675
|
-
const logins = this.installedIds().filter((id) => this.all[id].providerId === providerId && this.all[id]
|
|
3992
|
+
const logins = this.installedIds().filter((id) => this.all[id].providerId === providerId && connectionTypeOf(this.all[id]) !== "api_key");
|
|
3676
3993
|
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
3994
|
return null;
|
|
3678
3995
|
}
|
|
@@ -3682,7 +3999,7 @@ var ModuleRegistry = class {
|
|
|
3682
3999
|
if (!m) throw new Error(`There is no module "${id}". See \`monoclaw modules list --all\`.`);
|
|
3683
4000
|
if (id === "echo" && !this.echoAllowed()) throw new Error("echo is a test module: start the host with MONOCLAW_PROVIDERS=echo to use it.");
|
|
3684
4001
|
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
|
|
4002
|
+
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
4003
|
log("info", `module ${id} added`);
|
|
3687
4004
|
const install = this.startInstall(m);
|
|
3688
4005
|
this.changed();
|
|
@@ -3728,7 +4045,8 @@ var ModuleRegistry = class {
|
|
|
3728
4045
|
async readiness(connectionId) {
|
|
3729
4046
|
const c = this.connection(connectionId);
|
|
3730
4047
|
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.
|
|
4048
|
+
const m = this.module(c.module);
|
|
4049
|
+
if (!m) return { ready: false, summary: `This machine has no module "${c.module}" for that connection.`, details: {} };
|
|
3732
4050
|
let r;
|
|
3733
4051
|
try {
|
|
3734
4052
|
r = await m.readiness(c, c.type === "api_key" ? await this.deps.accounts.secretOf(c.id) : null);
|
|
@@ -3751,7 +4069,7 @@ var ModuleRegistry = class {
|
|
|
3751
4069
|
const rs = conns.map((c2) => this.readinessCache.get(c2.id));
|
|
3752
4070
|
if (!conns.length) {
|
|
3753
4071
|
state = "needs_setup";
|
|
3754
|
-
summary = m
|
|
4072
|
+
summary = connectionTypeOf(m) === "api_key" ? `Add an API key (monoclaw modules connect ${id})` : "No connection";
|
|
3755
4073
|
} else if (rs.some((r) => r?.ready)) {
|
|
3756
4074
|
const n = rs.filter((r) => r?.ready).length;
|
|
3757
4075
|
summary = conns.length === 1 ? rs[0].summary : `${n} of ${conns.length} connections ready`;
|
|
@@ -3761,8 +4079,8 @@ var ModuleRegistry = class {
|
|
|
3761
4079
|
summary = `${conns.length === 1 ? "" : `${conns.find((c2) => this.readinessCache.get(c2.id) === r).name}: `}${r.summary}${r.action ? `. ${r.action}` : ""}`;
|
|
3762
4080
|
} else summary = st.summary || "Checking\u2026";
|
|
3763
4081
|
}
|
|
3764
|
-
const c = m
|
|
3765
|
-
return { id, name: c.name, version: m.version, description: c.description, capabilities: c.capabilities, kind: c.kind, needsSecret: c.needsSecret, multipleConnections: m.
|
|
4082
|
+
const c = legacyCatalogueOf(m);
|
|
4083
|
+
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
4084
|
}
|
|
3767
4085
|
reports() {
|
|
3768
4086
|
return this.installedIds().map((id) => this.report(id));
|
|
@@ -3770,31 +4088,43 @@ var ModuleRegistry = class {
|
|
|
3770
4088
|
connectionReports() {
|
|
3771
4089
|
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 }));
|
|
3772
4090
|
}
|
|
3773
|
-
/**
|
|
3774
|
-
|
|
4091
|
+
/**
|
|
4092
|
+
* The fields a module offers for one use, choices filled in (live where the module fetches them). `use` is the word
|
|
4093
|
+
* of the spec (`agent`, `speech`, `transcription`, `tool:<name>`); a caller from before gives the old `capability`, which
|
|
4094
|
+
* maps onto it (an `image` is the module's one image tool).
|
|
4095
|
+
*/
|
|
4096
|
+
async options(moduleId, capability, connectionId, use) {
|
|
3775
4097
|
const m = this.installed(moduleId);
|
|
3776
|
-
|
|
4098
|
+
const name = moduleNameOf(m);
|
|
4099
|
+
const u = use ?? useFromCapability(capability, imageToolOf(m));
|
|
4100
|
+
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));
|
|
4101
|
+
if (!has2) throw new Error(`${name} has no ${use ?? capability} options.`);
|
|
3777
4102
|
if (!m.options) return [];
|
|
3778
4103
|
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 ${
|
|
3780
|
-
return m.options(
|
|
4104
|
+
if (connectionId && (!conn || conn.module !== moduleId)) throw new Error(`This machine has no ${name} connection ${connectionId}.`);
|
|
4105
|
+
return m.options(u, conn, conn?.type === "api_key" ? await this.deps.accounts.secretOf(conn.id) : null);
|
|
3781
4106
|
}
|
|
3782
4107
|
/** One job with a module and a connection: caps checked first, usage recorded after. */
|
|
3783
4108
|
async runJob(moduleId, connectionId, job) {
|
|
3784
4109
|
const m = this.installed(moduleId);
|
|
3785
|
-
|
|
4110
|
+
const name = moduleNameOf(m);
|
|
4111
|
+
if (job.capability === "tool") {
|
|
4112
|
+
if (!toolOf(m, job.tool)) throw unknownTool(name, job.tool, m.manifest.provides.tools);
|
|
4113
|
+
if (!m.runTool) throw new Error(`${name} does not run tools on this machine program.`);
|
|
4114
|
+
} 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
4115
|
const conn = this.connection(connectionId);
|
|
3787
|
-
if (!conn || conn.module !== moduleId) throw new Error(`This machine has no ${
|
|
4116
|
+
if (!conn || conn.module !== moduleId) throw new Error(`This machine has no ${name} connection ${connectionId}.`);
|
|
3788
4117
|
const over = this.ledger.check(conn, m.estimate?.(job));
|
|
3789
4118
|
if (over) throw new Error(over);
|
|
3790
|
-
const
|
|
4119
|
+
const secret = conn.type === "api_key" ? await this.deps.accounts.secretOf(conn.id) : null;
|
|
4120
|
+
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
4121
|
this.ledger.add(conn.id, out.usage);
|
|
3792
4122
|
return out;
|
|
3793
4123
|
}
|
|
3794
4124
|
installed(moduleId) {
|
|
3795
4125
|
const m = this.module(moduleId);
|
|
3796
4126
|
if (!m) throw new Error(`There is no module "${moduleId}".`);
|
|
3797
|
-
if (!this.isInstalled(moduleId)) throw new Error(`${m
|
|
4127
|
+
if (!this.isInstalled(moduleId)) throw new Error(`${moduleNameOf(m)} isn't on this machine any more.`);
|
|
3798
4128
|
return m;
|
|
3799
4129
|
}
|
|
3800
4130
|
};
|
|
@@ -3846,9 +4176,22 @@ function formatUseResult(name, r, cwd) {
|
|
|
3846
4176
|
if (r.error) return { content: [{ type: "text", text: r.error }], isError: true };
|
|
3847
4177
|
return formatToolResult({ name }, r, cwd);
|
|
3848
4178
|
}
|
|
4179
|
+
var READ_ONLY_TOOLS = /* @__PURE__ */ new Set(["find_tools", "list_agents", "image_view", "agents_options", "agents_read_profile"]);
|
|
4180
|
+
var RESTART_PLAIN = "The service restarted while this ran; call it again.";
|
|
4181
|
+
function restartMessage(call) {
|
|
4182
|
+
switch (call.kind) {
|
|
4183
|
+
case "find":
|
|
4184
|
+
case "list":
|
|
4185
|
+
return RESTART_PLAIN;
|
|
4186
|
+
case "use":
|
|
4187
|
+
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.`;
|
|
4188
|
+
case "send":
|
|
4189
|
+
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.`;
|
|
4190
|
+
}
|
|
4191
|
+
}
|
|
3849
4192
|
var ToolWaits = class {
|
|
3850
4193
|
waits = /* @__PURE__ */ new Map();
|
|
3851
|
-
wait(id, timeoutMs = TOOL_TIMEOUT_MS) {
|
|
4194
|
+
wait(id, timeoutMs = TOOL_TIMEOUT_MS, lost = RESTART_PLAIN) {
|
|
3852
4195
|
return new Promise((resolve) => {
|
|
3853
4196
|
const timer = setTimeout(() => finish({ error: `No result within ${Math.round(timeoutMs / 1e3)} seconds.`, files: [] }), timeoutMs);
|
|
3854
4197
|
const finish = (r) => {
|
|
@@ -3856,14 +4199,18 @@ var ToolWaits = class {
|
|
|
3856
4199
|
this.waits.delete(id);
|
|
3857
4200
|
resolve(r);
|
|
3858
4201
|
};
|
|
3859
|
-
this.waits.set(id, finish);
|
|
4202
|
+
this.waits.set(id, { finish, lost });
|
|
3860
4203
|
});
|
|
3861
4204
|
}
|
|
3862
4205
|
resolve(id, r) {
|
|
3863
|
-
this.waits.get(id)?.(r);
|
|
4206
|
+
this.waits.get(id)?.finish(r);
|
|
3864
4207
|
}
|
|
3865
4208
|
closeAll(reason = "Session closed.") {
|
|
3866
|
-
for (const
|
|
4209
|
+
for (const w of [...this.waits.values()]) w.finish({ error: reason, files: [] });
|
|
4210
|
+
}
|
|
4211
|
+
/** The connection to the service closed: every waiting call ends now with its own message. */
|
|
4212
|
+
failWaiting() {
|
|
4213
|
+
for (const w of [...this.waits.values()]) w.finish({ error: w.lost, files: [] });
|
|
3867
4214
|
}
|
|
3868
4215
|
};
|
|
3869
4216
|
var SessionToolRunner = class {
|
|
@@ -3889,7 +4236,7 @@ var SessionToolRunner = class {
|
|
|
3889
4236
|
if (!ok) return formatToolResult(t, { error: "The user declined this tool call.", files: [] });
|
|
3890
4237
|
}
|
|
3891
4238
|
const id = newId();
|
|
3892
|
-
const wait = this.waits.wait(id, t.capability === "tts" && this.timeoutMs === TOOL_TIMEOUT_MS ? TTS_TOOL_TIMEOUT_MS : this.timeoutMs);
|
|
4239
|
+
const wait = this.waits.wait(id, t.capability === "tts" && this.timeoutMs === TOOL_TIMEOUT_MS ? TTS_TOOL_TIMEOUT_MS : this.timeoutMs, restartMessage({ kind: "use", name: t.name }));
|
|
3893
4240
|
this.push({ kind: "tool.call", id, toolId: t.id, prompt, args: callArgs });
|
|
3894
4241
|
return formatToolResult(t, await wait, this.cwd);
|
|
3895
4242
|
}
|
|
@@ -3901,7 +4248,7 @@ var SessionToolRunner = class {
|
|
|
3901
4248
|
const callArgs2 = toolCallArgs(t, args2);
|
|
3902
4249
|
if (t.askBeforeUse && !await this.approve(toolMcpName(t), { file: given, ...callArgs2 }, `${t.name}: ${given}`)) return formatToolResult(t, { error: "The user declined this tool call.", files: [] });
|
|
3903
4250
|
const id2 = newId();
|
|
3904
|
-
const wait2 = this.waits.wait(id2, this.timeoutMs === TOOL_TIMEOUT_MS ? STT_TOOL_TIMEOUT_MS : this.timeoutMs);
|
|
4251
|
+
const wait2 = this.waits.wait(id2, this.timeoutMs === TOOL_TIMEOUT_MS ? STT_TOOL_TIMEOUT_MS : this.timeoutMs, restartMessage({ kind: "use", name: t.name }));
|
|
3905
4252
|
this.push({ kind: "tool.call", id: id2, toolId: t.id, prompt: "", args: callArgs2, attachmentId: attachment });
|
|
3906
4253
|
return formatToolResult(t, await wait2, this.cwd);
|
|
3907
4254
|
}
|
|
@@ -3913,14 +4260,14 @@ var SessionToolRunner = class {
|
|
|
3913
4260
|
if (!ok) return formatToolResult(t, { error: "The user declined this tool call.", files: [] });
|
|
3914
4261
|
}
|
|
3915
4262
|
const id = newId();
|
|
3916
|
-
const wait = this.waits.wait(id, this.timeoutMs === TOOL_TIMEOUT_MS ? STT_TOOL_TIMEOUT_MS : this.timeoutMs);
|
|
4263
|
+
const wait = this.waits.wait(id, this.timeoutMs === TOOL_TIMEOUT_MS ? STT_TOOL_TIMEOUT_MS : this.timeoutMs, restartMessage({ kind: "use", name: t.name }));
|
|
3917
4264
|
this.push({ kind: "tool.call", id, toolId: t.id, prompt: "", args: callArgs, file: file.path });
|
|
3918
4265
|
return formatToolResult(t, await wait, this.cwd);
|
|
3919
4266
|
}
|
|
3920
4267
|
/** `find_tools`: the server's list, as the JSON text it sent. */
|
|
3921
4268
|
async find(args2) {
|
|
3922
4269
|
const id = newId();
|
|
3923
|
-
const wait = this.waits.wait(id, this.timeoutMs === TOOL_TIMEOUT_MS ? FIND_TOOLS_TIMEOUT_MS : this.timeoutMs);
|
|
4270
|
+
const wait = this.waits.wait(id, this.timeoutMs === TOOL_TIMEOUT_MS ? FIND_TOOLS_TIMEOUT_MS : this.timeoutMs, restartMessage({ kind: "find" }));
|
|
3924
4271
|
this.push({ kind: "tools.find", id, ...args2.query?.trim() ? { query: args2.query.trim() } : {}, ...typeof args2.limit === "number" ? { limit: args2.limit } : {} });
|
|
3925
4272
|
const r = await wait;
|
|
3926
4273
|
return r.error ? { content: [{ type: "text", text: r.error }], isError: true } : { content: [{ type: "text", text: r.text ?? "" }] };
|
|
@@ -3944,7 +4291,7 @@ var SessionToolRunner = class {
|
|
|
3944
4291
|
let file;
|
|
3945
4292
|
for (let round2 = 0; round2 < 3; round2++) {
|
|
3946
4293
|
const id = newId();
|
|
3947
|
-
const wait = this.waits.wait(id, this.timeoutMs === TOOL_TIMEOUT_MS ? USE_TOOL_TIMEOUT_MS : this.timeoutMs);
|
|
4294
|
+
const wait = this.waits.wait(id, this.timeoutMs === TOOL_TIMEOUT_MS ? USE_TOOL_TIMEOUT_MS : this.timeoutMs, restartMessage({ kind: "use", name }));
|
|
3948
4295
|
this.push({ kind: "tool.use", id, name, input, ...approved ? { approved } : {}, ...file ? { file } : {} });
|
|
3949
4296
|
const r = await wait;
|
|
3950
4297
|
if (!r.next) return formatUseResult(name, r, this.cwd);
|
|
@@ -3964,6 +4311,10 @@ var SessionToolRunner = class {
|
|
|
3964
4311
|
result(id, r) {
|
|
3965
4312
|
this.waits.resolve(id, r);
|
|
3966
4313
|
}
|
|
4314
|
+
/** The connection to the service closed: every waiting call ends now (bug: a tool call lost in a server restart). */
|
|
4315
|
+
failWaiting() {
|
|
4316
|
+
this.waits.failWaiting();
|
|
4317
|
+
}
|
|
3967
4318
|
close() {
|
|
3968
4319
|
this.waits.closeAll();
|
|
3969
4320
|
}
|
|
@@ -4324,6 +4675,10 @@ var SessionManager = class {
|
|
|
4324
4675
|
this.emit(groupId, { kind: "error", message: e.message, fatal: false });
|
|
4325
4676
|
}
|
|
4326
4677
|
}
|
|
4678
|
+
/** The connection to the service closed: every session's waiting calls end now (bug: a tool call lost in a server restart). */
|
|
4679
|
+
connectionLost() {
|
|
4680
|
+
for (const l of this.live.values()) l.session.connectionLost?.();
|
|
4681
|
+
}
|
|
4327
4682
|
/** The server's answer to an `agent.send` or `agents.list` event. */
|
|
4328
4683
|
agentResult(groupId, id, result) {
|
|
4329
4684
|
this.live.get(groupId)?.session.agentResult?.(id, result);
|
|
@@ -4665,7 +5020,7 @@ function guessMime(name) {
|
|
|
4665
5020
|
}
|
|
4666
5021
|
|
|
4667
5022
|
// src/version.ts
|
|
4668
|
-
var APP_VERSION = true ? "1.0.
|
|
5023
|
+
var APP_VERSION = true ? "1.0.21" : fromPackage();
|
|
4669
5024
|
|
|
4670
5025
|
// src/diag.ts
|
|
4671
5026
|
var MAX_HELD = 200;
|
|
@@ -4939,6 +5294,7 @@ var HostClient = class {
|
|
|
4939
5294
|
ws.on("close", (code, reason) => {
|
|
4940
5295
|
if (this.ws !== ws) return;
|
|
4941
5296
|
this.onState("offline");
|
|
5297
|
+
this.sessions.connectionLost();
|
|
4942
5298
|
if (this.heartbeat) clearInterval(this.heartbeat);
|
|
4943
5299
|
this.clearTimers();
|
|
4944
5300
|
if (code === 4001) {
|
|
@@ -5092,7 +5448,7 @@ var HostClient = class {
|
|
|
5092
5448
|
return;
|
|
5093
5449
|
case "module.options":
|
|
5094
5450
|
try {
|
|
5095
|
-
this.send({ t: "module.options.result", reqId: frame.reqId, fields: await this.registry.options(frame.module, frame.capability, frame.connectionId) });
|
|
5451
|
+
this.send({ t: "module.options.result", reqId: frame.reqId, fields: await this.registry.options(frame.module, frame.capability, frame.connectionId, frame.use) });
|
|
5096
5452
|
} catch (e) {
|
|
5097
5453
|
this.send({ t: "module.options.result", reqId: frame.reqId, fields: [], error: e.message.slice(0, 300) });
|
|
5098
5454
|
}
|
|
@@ -5103,15 +5459,16 @@ var HostClient = class {
|
|
|
5103
5459
|
case "provider_account.expect": {
|
|
5104
5460
|
const m = this.registry.module(frame.module);
|
|
5105
5461
|
if (!m || !this.registry.isInstalled(frame.module)) {
|
|
5106
|
-
this.send({ t: "provider_account.readiness", id: frame.id, readiness: { ready: false, summary: `${m
|
|
5462
|
+
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." } });
|
|
5107
5463
|
return;
|
|
5108
5464
|
}
|
|
5109
|
-
|
|
5110
|
-
|
|
5465
|
+
const connectionType = connectionTypeOf(m);
|
|
5466
|
+
if (frame.type !== connectionType) {
|
|
5467
|
+
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: {} } });
|
|
5111
5468
|
return;
|
|
5112
5469
|
}
|
|
5113
|
-
if (!m
|
|
5114
|
-
this.send({ t: "provider_account.readiness", id: frame.id, readiness: { ready: false, summary: `${m
|
|
5470
|
+
if (!multipleConnectionsOf(m) && this.registry.connectionsOf(frame.module).some((c) => c.id !== frame.id)) {
|
|
5471
|
+
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: {} } });
|
|
5115
5472
|
return;
|
|
5116
5473
|
}
|
|
5117
5474
|
this.accounts.upsert({ id: frame.id, name: frame.name, type: frame.type, module: frame.module, provider: m.providerId ?? frame.module, allowedFolders: frame.allowedFolders ?? [] });
|
|
@@ -5216,6 +5573,7 @@ var HostClient = class {
|
|
|
5216
5573
|
const origin = routerOrigin(this.cfg.routerUrl);
|
|
5217
5574
|
const credential = this.cfg.credential ?? "";
|
|
5218
5575
|
let audioFile = "";
|
|
5576
|
+
const jobFiles = [];
|
|
5219
5577
|
log("info", `job ${frame.jobId.slice(0, 10)} ${frame.module} ${frame.input.capability}: received`);
|
|
5220
5578
|
const facts = { module: frame.module, capability: frame.input.capability, jobId: frame.jobId.slice(0, 10) };
|
|
5221
5579
|
const hung = setTimeout(() => {
|
|
@@ -5229,7 +5587,23 @@ var HostClient = class {
|
|
|
5229
5587
|
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);
|
|
5230
5588
|
job = { capability: "stt", audio: fs16.readFileSync(audioFile), mime: frame.input.mime, options: frame.options };
|
|
5231
5589
|
} else if (frame.input.capability === "tts") job = { capability: "tts", text: frame.input.text, options: frame.options };
|
|
5232
|
-
else {
|
|
5590
|
+
else if (frame.input.capability === "tool") {
|
|
5591
|
+
const m = this.registry.module(frame.module);
|
|
5592
|
+
const declared = m ? toolOf(m, frame.input.tool) : null;
|
|
5593
|
+
if (!m || !declared) throw unknownTool(m ? moduleNameOf(m) : frame.module, frame.input.tool, m?.manifest.provides.tools ?? []);
|
|
5594
|
+
const files = [];
|
|
5595
|
+
for (const f of frame.input.files) {
|
|
5596
|
+
const rule = declared.files.find((d) => d.field === f.field);
|
|
5597
|
+
if (!rule) throw new Error(`${declared.name} takes no file in "${f.field}".`);
|
|
5598
|
+
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(", ")}.`);
|
|
5599
|
+
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);
|
|
5600
|
+
jobFiles.push(saved);
|
|
5601
|
+
const bytes = fs16.readFileSync(saved);
|
|
5602
|
+
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.`);
|
|
5603
|
+
files.push({ field: f.field, bytes, mime: f.mime, name: f.name });
|
|
5604
|
+
}
|
|
5605
|
+
job = { capability: "tool", tool: frame.input.tool, input: frame.input.input, files, options: frame.options };
|
|
5606
|
+
} else {
|
|
5233
5607
|
job = { capability: "image", prompt: frame.input.prompt, args: frame.input.args, options: frame.options };
|
|
5234
5608
|
if (frame.input.reference) {
|
|
5235
5609
|
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);
|
|
@@ -5254,6 +5628,7 @@ var HostClient = class {
|
|
|
5254
5628
|
} finally {
|
|
5255
5629
|
clearTimeout(hung);
|
|
5256
5630
|
if (audioFile) fs16.rmSync(audioFile, { force: true });
|
|
5631
|
+
for (const f of jobFiles) fs16.rmSync(f, { force: true });
|
|
5257
5632
|
}
|
|
5258
5633
|
this.scheduleModules();
|
|
5259
5634
|
}
|
|
@@ -5261,6 +5636,11 @@ var HostClient = class {
|
|
|
5261
5636
|
function describeMachine() {
|
|
5262
5637
|
return { name: os5.hostname(), platform: process.platform, arch: process.arch, appVersion: APP_VERSION, nodeVersion: process.version };
|
|
5263
5638
|
}
|
|
5639
|
+
function mimeMatches(pattern2, mime) {
|
|
5640
|
+
const m = mime.split(";")[0].trim().toLowerCase();
|
|
5641
|
+
const p = pattern2.toLowerCase();
|
|
5642
|
+
return p === "*/*" || p === m || p.endsWith("/*") && m.startsWith(p.slice(0, -1));
|
|
5643
|
+
}
|
|
5264
5644
|
|
|
5265
5645
|
// src/modules/commands.ts
|
|
5266
5646
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
@@ -5285,6 +5665,8 @@ async function listModules(reg, io2, opts = {}) {
|
|
|
5285
5665
|
io2.out("Modules on this machine:");
|
|
5286
5666
|
for (const r of reg.reports()) {
|
|
5287
5667
|
io2.out(`${mark(r.state === "ready", r.state === "installing")} ${r.id.padEnd(20)} ${r.state === "ready" ? "" : `${r.state.replace("_", " ")}: `}${r.summary}`);
|
|
5668
|
+
const m = reg.module(r.id);
|
|
5669
|
+
if (m) io2.out(` ${providesLine(m)}`);
|
|
5288
5670
|
for (const c of reg.connectionsOf(r.id)) {
|
|
5289
5671
|
const rd = reg.cachedReadiness(c.id);
|
|
5290
5672
|
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(", ");
|
|
@@ -5315,28 +5697,28 @@ async function addModules(reg, ids, io2, opts = {}) {
|
|
|
5315
5697
|
}
|
|
5316
5698
|
await reg.refreshReadiness(reg.connectionsOf(id).map((c) => c.id));
|
|
5317
5699
|
const r = reg.report(id);
|
|
5318
|
-
io2.out(`${mark(r.state === "ready", r.state === "needs_setup")} ${m
|
|
5319
|
-
if (m
|
|
5700
|
+
io2.out(`${mark(r.state === "ready", r.state === "needs_setup")} ${moduleNameOf(m)}${already ? " (already added)" : " added"}: ${r.summary}`);
|
|
5701
|
+
if (connectionTypeOf(m) === "api_key" && !reg.connectionsOf(id).length) io2.out(` Next: monoclaw modules connect ${id} --name "<a name>" (asks for the key)`);
|
|
5320
5702
|
}
|
|
5321
5703
|
io2.out(RUNNING_HOST);
|
|
5322
5704
|
}
|
|
5323
5705
|
async function removeModule(reg, id, io2) {
|
|
5324
5706
|
const m = reg.module(id) ?? fail(`There is no module "${id}".`);
|
|
5325
|
-
if (!reg.isInstalled(id)) fail(`${m
|
|
5707
|
+
if (!reg.isInstalled(id)) fail(`${moduleNameOf(m)} isn't on this machine.`);
|
|
5326
5708
|
const n = reg.connectionsOf(id).length;
|
|
5327
5709
|
await reg.remove(id);
|
|
5328
|
-
io2.out(`Removed ${m
|
|
5710
|
+
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}`);
|
|
5329
5711
|
}
|
|
5330
5712
|
async function connectModule(reg, accounts, moduleId, io2, opts = {}) {
|
|
5331
5713
|
const m = reg.module(moduleId) ?? fail(`There is no module "${moduleId}". See \`monoclaw modules list --all\`.`);
|
|
5332
|
-
if (m
|
|
5714
|
+
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.`);
|
|
5333
5715
|
if (!reg.isInstalled(moduleId)) await reg.add(moduleId).install;
|
|
5334
|
-
const key = (await io2.readSecret(`${m
|
|
5716
|
+
const key = (await io2.readSecret(`${moduleNameOf(m)} API key (not echoed): `)).trim();
|
|
5335
5717
|
if (!key) fail("No key given.");
|
|
5336
5718
|
const bad = m.checkKey?.(key);
|
|
5337
5719
|
if (bad) fail(bad);
|
|
5338
5720
|
const id = opts.id ?? newConnectionId();
|
|
5339
|
-
const name = opts.name?.trim() || `${m
|
|
5721
|
+
const name = opts.name?.trim() || `${moduleNameOf(m)} key`;
|
|
5340
5722
|
accounts.upsert({ id, name, type: "api_key", module: moduleId, provider: m.providerId ?? moduleId });
|
|
5341
5723
|
await accounts.setSecret(id, key);
|
|
5342
5724
|
const r = await reg.readiness(id);
|
|
@@ -5348,7 +5730,7 @@ async function setKey(reg, accounts, connectionId, io2) {
|
|
|
5348
5730
|
const c = accounts.get(connectionId) ?? fail(`There is no connection ${connectionId}. See \`monoclaw modules list\`.`);
|
|
5349
5731
|
if (c.type !== "api_key") fail(`${c.name} is not an API key connection; it has no key.`);
|
|
5350
5732
|
const m = reg.module(c.module);
|
|
5351
|
-
const key = (await io2.readSecret(`${m
|
|
5733
|
+
const key = (await io2.readSecret(`${(m ? moduleNameOf(m) : void 0) ?? c.module} API key for ${c.name} (not echoed): `)).trim();
|
|
5352
5734
|
if (!key) fail("No key given.");
|
|
5353
5735
|
const bad = m?.checkKey?.(key);
|
|
5354
5736
|
if (bad) fail(bad);
|
|
@@ -5380,16 +5762,25 @@ function setCap(reg, accounts, connectionId, opts, io2) {
|
|
|
5380
5762
|
function fail(message) {
|
|
5381
5763
|
throw new Error(message);
|
|
5382
5764
|
}
|
|
5765
|
+
function providesLine(m) {
|
|
5766
|
+
const p = m.manifest.provides;
|
|
5767
|
+
const parts = [];
|
|
5768
|
+
if (p.agent) parts.push("Runs agents");
|
|
5769
|
+
if (p.jobs.includes("speech")) parts.push("Speaks replies");
|
|
5770
|
+
if (p.jobs.includes("transcription")) parts.push("Transcribes voice messages");
|
|
5771
|
+
if (p.tools.length) parts.push(`${p.tools.length} tool${p.tools.length === 1 ? "" : "s"}: ${p.tools.map((t) => t.name).join(", ")}`);
|
|
5772
|
+
return parts.join(" \xB7 ") || "Provides nothing yet";
|
|
5773
|
+
}
|
|
5383
5774
|
|
|
5384
5775
|
// src/enrol.ts
|
|
5385
|
-
import { z as
|
|
5386
|
-
var EnrolResponse =
|
|
5387
|
-
var EnrolPreview =
|
|
5388
|
-
space:
|
|
5776
|
+
import { z as z11 } from "zod";
|
|
5777
|
+
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() });
|
|
5778
|
+
var EnrolPreview = z11.object({
|
|
5779
|
+
space: z11.object({ id: z11.string(), handle: z11.string(), name: z11.string() }),
|
|
5389
5780
|
/** The token re-enrols an existing machine (after a reset) rather than making a new one. */
|
|
5390
|
-
reenrol:
|
|
5781
|
+
reenrol: z11.boolean(),
|
|
5391
5782
|
/** Of the host ids we sent, the ones already enrolled in the token's space. */
|
|
5392
|
-
sameSpaceHostIds:
|
|
5783
|
+
sameSpaceHostIds: z11.array(z11.string())
|
|
5393
5784
|
});
|
|
5394
5785
|
async function previewToken(routerUrl, token, hostIds, insecure) {
|
|
5395
5786
|
const base = routerUrl.replace(/\/+$/, "");
|
|
@@ -5477,7 +5868,7 @@ import { promisify as promisify5 } from "node:util";
|
|
|
5477
5868
|
import { spawn as spawn3 } from "node:child_process";
|
|
5478
5869
|
import fs17 from "node:fs";
|
|
5479
5870
|
import path17 from "node:path";
|
|
5480
|
-
import { z as
|
|
5871
|
+
import { z as z12 } from "zod";
|
|
5481
5872
|
var PACKAGE = "@monoclaw/machine";
|
|
5482
5873
|
function nodeInstallHint(platform) {
|
|
5483
5874
|
if (platform === "darwin") return "Install Node 22 or newer: `brew install node`, or the LTS installer from https://nodejs.org";
|
|
@@ -5496,7 +5887,7 @@ function updateWait(busy2, background, since, now) {
|
|
|
5496
5887
|
return now - from < BACKGROUND_WAIT_MS ? { wait: true, why: "background", since: from } : { wait: false, why: null, since: null };
|
|
5497
5888
|
}
|
|
5498
5889
|
var INSTALL_TIMEOUT_MS = 5 * 6e4;
|
|
5499
|
-
var VersionPolicy =
|
|
5890
|
+
var VersionPolicy = z12.object({ package: z12.string(), latest: z12.string().nullable(), minimum: z12.string().nullable() });
|
|
5500
5891
|
function detectInstallMode(entry = process.argv[1] ?? "") {
|
|
5501
5892
|
let real = entry;
|
|
5502
5893
|
try {
|
|
@@ -5942,7 +6333,7 @@ var EchoSession = class {
|
|
|
5942
6333
|
const id = newId();
|
|
5943
6334
|
const r = await new Promise((res) => {
|
|
5944
6335
|
const t = setTimeout(() => res({ error: "no answer from the router" }), 5e3);
|
|
5945
|
-
this.agentWaits.set(id, (x) => (clearTimeout(t), res(x)));
|
|
6336
|
+
this.agentWaits.set(id, { finish: (x) => (clearTimeout(t), res(x)), lost: restartMessage({ kind: "send", to: to.trim() }) });
|
|
5946
6337
|
this.q.push({ kind: "agent.send", id, to: to.trim(), text: rest.join(":").trim() });
|
|
5947
6338
|
});
|
|
5948
6339
|
this.agentWaits.delete(id);
|
|
@@ -5954,7 +6345,7 @@ var EchoSession = class {
|
|
|
5954
6345
|
const id = newId();
|
|
5955
6346
|
const r = await new Promise((res) => {
|
|
5956
6347
|
const t = setTimeout(() => res({ error: "no answer from the router" }), 5e3);
|
|
5957
|
-
this.agentWaits.set(id, (x) => (clearTimeout(t), res(x)));
|
|
6348
|
+
this.agentWaits.set(id, { finish: (x) => (clearTimeout(t), res(x)), lost: restartMessage({ kind: "list" }) });
|
|
5958
6349
|
this.q.push({ kind: "agents.list", id });
|
|
5959
6350
|
});
|
|
5960
6351
|
this.agentWaits.delete(id);
|
|
@@ -6054,11 +6445,15 @@ ${r.text}`, final: true });
|
|
|
6054
6445
|
this.pending.delete(id);
|
|
6055
6446
|
}
|
|
6056
6447
|
agentResult(id, result) {
|
|
6057
|
-
this.agentWaits.get(id)?.(result);
|
|
6448
|
+
this.agentWaits.get(id)?.finish(result);
|
|
6058
6449
|
}
|
|
6059
6450
|
toolResult(id, result) {
|
|
6060
6451
|
this.tools.result(id, result);
|
|
6061
6452
|
}
|
|
6453
|
+
connectionLost() {
|
|
6454
|
+
for (const w of [...this.agentWaits.values()]) w.finish({ error: w.lost });
|
|
6455
|
+
this.tools.failWaiting();
|
|
6456
|
+
}
|
|
6062
6457
|
async interrupt() {
|
|
6063
6458
|
this.abort?.abort();
|
|
6064
6459
|
}
|
|
@@ -6117,7 +6512,7 @@ import fs20 from "node:fs";
|
|
|
6117
6512
|
import os7 from "node:os";
|
|
6118
6513
|
import path20 from "node:path";
|
|
6119
6514
|
import { promisify as promisify7 } from "node:util";
|
|
6120
|
-
import { z as
|
|
6515
|
+
import { z as z13 } from "zod";
|
|
6121
6516
|
import { createSdkMcpServer, listSessions, query, tool } from "@anthropic-ai/claude-agent-sdk";
|
|
6122
6517
|
|
|
6123
6518
|
// src/providers/claude/cli.ts
|
|
@@ -6409,6 +6804,7 @@ var ClaudeSession = class {
|
|
|
6409
6804
|
/** tool_use id → tool name, so a result can be named. */
|
|
6410
6805
|
toolNames = /* @__PURE__ */ new Map();
|
|
6411
6806
|
/** `send` and `list_agents` calls waiting for the server's `agent.send.result`. */
|
|
6807
|
+
/** `send` and `list_agents` calls waiting for the service, each with what to say if the connection is lost meanwhile. */
|
|
6412
6808
|
agentWaits = /* @__PURE__ */ new Map();
|
|
6413
6809
|
/** The agent's tools: calls waiting for the server's `tool.result`. */
|
|
6414
6810
|
tools;
|
|
@@ -6457,7 +6853,7 @@ var ClaudeSession = class {
|
|
|
6457
6853
|
tool(
|
|
6458
6854
|
"send_file",
|
|
6459
6855
|
"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.",
|
|
6460
|
-
{ path:
|
|
6856
|
+
{ 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") },
|
|
6461
6857
|
async (args2) => {
|
|
6462
6858
|
const full = sendablePath(this.opts.cwd, args2.path);
|
|
6463
6859
|
if (!full) return { content: [{ type: "text", text: `Only files inside the working folder (${this.opts.cwd}), outside dot-folders, can be sent.` }], isError: true };
|
|
@@ -6482,7 +6878,7 @@ var ClaudeSession = class {
|
|
|
6482
6878
|
this.agentWaits.delete(id);
|
|
6483
6879
|
resolve(r2);
|
|
6484
6880
|
};
|
|
6485
|
-
this.agentWaits.set(id, finish);
|
|
6881
|
+
this.agentWaits.set(id, { finish, lost: restartMessage({ kind: "list" }) });
|
|
6486
6882
|
});
|
|
6487
6883
|
this.q.push({ kind: "agents.list", id });
|
|
6488
6884
|
const r = await result;
|
|
@@ -6493,7 +6889,7 @@ var ClaudeSession = class {
|
|
|
6493
6889
|
tool(
|
|
6494
6890
|
"send",
|
|
6495
6891
|
SEND_TOOL_DESCRIPTION,
|
|
6496
|
-
{ to:
|
|
6892
|
+
{ to: z13.string().min(1).describe("One agent's name from list_agents"), text: z13.string().describe("The message") },
|
|
6497
6893
|
async (args2) => {
|
|
6498
6894
|
const id = newId();
|
|
6499
6895
|
const result = new Promise((resolve) => {
|
|
@@ -6503,7 +6899,7 @@ var ClaudeSession = class {
|
|
|
6503
6899
|
this.agentWaits.delete(id);
|
|
6504
6900
|
resolve(r);
|
|
6505
6901
|
};
|
|
6506
|
-
this.agentWaits.set(id, finish);
|
|
6902
|
+
this.agentWaits.set(id, { finish, lost: restartMessage({ kind: "send", to: args2.to }) });
|
|
6507
6903
|
});
|
|
6508
6904
|
this.q.push({ kind: "agent.send", id, to: args2.to, text: args2.text });
|
|
6509
6905
|
return sendToolResult(args2, await result);
|
|
@@ -6513,11 +6909,11 @@ var ClaudeSession = class {
|
|
|
6513
6909
|
}
|
|
6514
6910
|
if (s.toolDoors)
|
|
6515
6911
|
tools.push(
|
|
6516
|
-
tool(FIND_TOOLS, FIND_TOOLS_DESCRIPTION, { query:
|
|
6912
|
+
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 }),
|
|
6517
6913
|
tool(
|
|
6518
6914
|
USE_TOOL,
|
|
6519
6915
|
USE_TOOL_DESCRIPTION,
|
|
6520
|
-
{ name:
|
|
6916
|
+
{ 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") },
|
|
6521
6917
|
async (args2) => this.tools.use(args2),
|
|
6522
6918
|
{ alwaysLoad: true }
|
|
6523
6919
|
)
|
|
@@ -6721,11 +7117,16 @@ ${files.map((a) => `- ${a.localPath} (${a.mime}, ${a.size} bytes)${a.note ? `: $
|
|
|
6721
7117
|
f(allow ? { behavior: "allow", updatedInput } : { behavior: "deny", message: "The user declined this action in the chat." });
|
|
6722
7118
|
}
|
|
6723
7119
|
agentResult(id, result) {
|
|
6724
|
-
this.agentWaits.get(id)?.(result);
|
|
7120
|
+
this.agentWaits.get(id)?.finish(result);
|
|
6725
7121
|
}
|
|
6726
7122
|
toolResult(id, result) {
|
|
6727
7123
|
this.tools.result(id, result);
|
|
6728
7124
|
}
|
|
7125
|
+
/** The machine's connection to the service closed: what was waiting for it ends now, each call with its own words. */
|
|
7126
|
+
connectionLost() {
|
|
7127
|
+
for (const w of [...this.agentWaits.values()]) w.finish({ error: w.lost });
|
|
7128
|
+
this.tools.failWaiting();
|
|
7129
|
+
}
|
|
6729
7130
|
/**
|
|
6730
7131
|
* When we last asked the run to stop. The result that follows within a minute is a stop, whatever it calls itself
|
|
6731
7132
|
* (a stop asked for while nothing ran must not hide a later run's real error, hence the limit).
|
|
@@ -6760,7 +7161,7 @@ ${files.map((a) => `- ${a.localPath} (${a.mime}, ${a.size} bytes)${a.note ? `: $
|
|
|
6760
7161
|
this.closed = true;
|
|
6761
7162
|
liveBackground.delete(this.opts.groupId);
|
|
6762
7163
|
for (const f of this.pending.values()) f({ behavior: "deny", message: "Session closed." });
|
|
6763
|
-
for (const
|
|
7164
|
+
for (const w of this.agentWaits.values()) w.finish({ error: "Session closed." });
|
|
6764
7165
|
this.tools.close();
|
|
6765
7166
|
this.prompts.close();
|
|
6766
7167
|
await this.query?.interrupt().catch(() => {
|
|
@@ -7382,7 +7783,7 @@ async function readSecret(prompt) {
|
|
|
7382
7783
|
});
|
|
7383
7784
|
}
|
|
7384
7785
|
var modules = program.command("modules").description("What this machine can do: agent engines, voices, transcription, images (keys stay on this machine)");
|
|
7385
|
-
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) => {
|
|
7786
|
+
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) => {
|
|
7386
7787
|
const { registry } = await makeContext(requireConfig());
|
|
7387
7788
|
await listModules(registry, io, opts);
|
|
7388
7789
|
});
|