@oalo-ai/cli 0.4.5 → 0.5.1
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/README.md +20 -0
- package/man/oalo.1 +163 -8
- package/package.json +1 -1
- package/src/args.js +64 -5
- package/src/bot-settings.json +10 -0
- package/src/channel.js +1 -1
- package/src/commands/bots.js +95 -5
- package/src/commands/call.js +16 -4
- package/src/commands/data.js +9 -1
- package/src/commands/deploy.js +6 -2
- package/src/commands/graphs.js +28 -8
- package/src/commands/link.js +68 -46
- package/src/commands/login.js +1 -1
- package/src/commands/machines.js +182 -0
- package/src/commands/mcp.js +26 -2
- package/src/commands/run.js +12 -8
- package/src/commands/serve.js +562 -0
- package/src/commands/switches.js +10 -0
- package/src/commands/tokens.js +14 -6
- package/src/commands/typegen.js +2 -1
- package/src/coord-release.json +9 -9
- package/src/events.js +9 -4
- package/src/graphfiles.js +44 -1
- package/src/help.js +86 -7
- package/src/index.js +8 -0
- package/src/mcp/describe.js +2 -1
- package/src/mcp/fit.js +3 -1
- package/src/mcp/tools.js +85 -4
- package/src/serve/command.js +145 -0
- package/src/serve/config.js +215 -0
- package/src/serve/folder.js +372 -0
- package/src/serve/install.js +107 -0
- package/src/serve/model.js +363 -0
- package/src/serve/node.js +300 -0
package/src/events.js
CHANGED
|
@@ -27,10 +27,15 @@ function format(event, payload) {
|
|
|
27
27
|
const p = payload && typeof payload === "object" ? payload : {};
|
|
28
28
|
|
|
29
29
|
if (event === "activity:event") {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
// A workflow run has no person behind it and its event carries only the
|
|
31
|
+
// run id: it printed "someone started" (2026-11-18).
|
|
32
|
+
const run = p.surface === "runs";
|
|
33
|
+
const who = p.actor?.username || p.actor?.user_id || (run ? "workflow" : "someone");
|
|
34
|
+
const object =
|
|
35
|
+
p.object_type || p.object_name
|
|
36
|
+
? [p.object_type, p.object_name && `"${p.object_name}"`]
|
|
37
|
+
: [run && p.object_id != null && `run #${p.object_id}`];
|
|
38
|
+
const what = [p.verb, ...object].filter(Boolean).join(" ");
|
|
34
39
|
return `${bold(who)} ${what || p.surface}${p.link ? dim(` ${p.link}`) : ""}`;
|
|
35
40
|
}
|
|
36
41
|
|
package/src/graphfiles.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { readFileSync, writeFileSync, mkdirSync, readdirSync, existsSync, unlinkSync, statSync } from "node:fs";
|
|
3
|
-
import { join, dirname, relative } from "node:path";
|
|
3
|
+
import { join, dirname, relative, resolve, sep } from "node:path";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Flows and loops as files in the project, for `oalo pull` / `push` / `status`.
|
|
@@ -224,6 +224,16 @@ export function standing(file, remote) {
|
|
|
224
224
|
return "clean";
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
/**
|
|
228
|
+
* A file that is exactly an older pulled version (restored from git, say) is
|
|
229
|
+
* a rollback, not someone else's edit: say how to make it live. Null when the
|
|
230
|
+
* file was edited, is new, or is not behind the server.
|
|
231
|
+
*/
|
|
232
|
+
export function rollbackHint(file, remoteVersion, relPath) {
|
|
233
|
+
if (file.version == null || locallyModified(file) || remoteVersion == null || remoteVersion === file.version) return null;
|
|
234
|
+
return `this file is v${file.version} as it was pulled, unchanged, and the server is at v${remoteVersion}. To make this earlier version live again (a rollback), run \`oalo push ${relPath} --force\`.`;
|
|
235
|
+
}
|
|
236
|
+
|
|
227
237
|
/**
|
|
228
238
|
* The smallest new file of each kind, for errors and help: a new loop or flow
|
|
229
239
|
* is often written from scratch, with no pulled file to copy.
|
|
@@ -265,6 +275,39 @@ export function removeFile(path) {
|
|
|
265
275
|
if (existsSync(path)) unlinkSync(path);
|
|
266
276
|
}
|
|
267
277
|
|
|
278
|
+
/**
|
|
279
|
+
* The file a flow push leaves stale, to remove: a pulled file under
|
|
280
|
+
* .oalo/flows whose flow is now saved at another path (it was renamed). A file
|
|
281
|
+
* pushed from anywhere else is the user's own copy and stays (demo sweep
|
|
282
|
+
* 2026-11-18: pushing a kept copy of a flow from a demos folder deleted it).
|
|
283
|
+
* Null when nothing is stale.
|
|
284
|
+
*/
|
|
285
|
+
export function staleAfterFlowPush(path, newPath, cwd = process.cwd()) {
|
|
286
|
+
const old = resolve(cwd, path);
|
|
287
|
+
if (old === resolve(cwd, newPath)) return null;
|
|
288
|
+
return old.startsWith(resolve(cwd, ROOT, "flows") + sep) ? old : null;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Where a successful push writes the server's copy back. `path` is the file
|
|
293
|
+
* pushed, `savedPath` where pull keeps that flow or loop. The pushed file is
|
|
294
|
+
* always rewritten with the new version, so it is clean, not "behind its own
|
|
295
|
+
* push". When it lives elsewhere (a copy in a demos folder), the pulled copy at
|
|
296
|
+
* `savedPath` is refreshed too, unless it holds edits of its own
|
|
297
|
+
* (`savedEdited`): then it is kept, not overwritten (demo sweep 2026-11-18:
|
|
298
|
+
* pushing a kept copy of a loop wiped an unsaved edit in .oalo/loops).
|
|
299
|
+
* Returns {write: [paths], remove: path | null, kept: path | null}.
|
|
300
|
+
*/
|
|
301
|
+
export function pushWriteBack(path, savedPath, savedEdited, cwd = process.cwd()) {
|
|
302
|
+
const pushed = resolve(cwd, path);
|
|
303
|
+
const saved = resolve(cwd, savedPath);
|
|
304
|
+
if (pushed === saved) return { write: [saved], remove: null, kept: null };
|
|
305
|
+
if (savedEdited) return { write: [pushed], remove: null, kept: saved };
|
|
306
|
+
const stale = staleAfterFlowPush(pushed, saved, cwd);
|
|
307
|
+
if (stale) return { write: [saved], remove: stale, kept: null };
|
|
308
|
+
return { write: [pushed, saved], remove: null, kept: null };
|
|
309
|
+
}
|
|
310
|
+
|
|
268
311
|
// `<name>.server.json` is the server's copy saved by a conflicted push: a merge
|
|
269
312
|
// aid, not a file to push.
|
|
270
313
|
const isGraphFile = (f) => f.endsWith(".json") && !f.endsWith(".server.json");
|
package/src/help.js
CHANGED
|
@@ -19,7 +19,7 @@ export const TOKENS = [
|
|
|
19
19
|
kind: "cli",
|
|
20
20
|
where: "`oalo login`, or dashboard -> Account -> CLI & agents",
|
|
21
21
|
plane: "control (the build surface)",
|
|
22
|
-
usedBy: ["whoami", "tail", "call", "run", "emit", "data", "tokens", "docs", "apps", "deploy", "env", "logs", "secrets", "loops", "flows", "pull", "status", "lint", "push", "qa", "rehearse", "bots", "sources", "mcp"],
|
|
22
|
+
usedBy: ["whoami", "tail", "call", "run", "emit", "data", "tokens", "docs", "apps", "deploy", "env", "logs", "secrets", "loops", "flows", "pull", "status", "lint", "push", "qa", "rehearse", "bots", "sources", "machines", "mcp"],
|
|
23
23
|
warning: "Acts as you, with exactly your permissions. No read-only mode. Treat it like a password.",
|
|
24
24
|
},
|
|
25
25
|
];
|
|
@@ -129,10 +129,11 @@ export const COMMANDS = [
|
|
|
129
129
|
name: "call",
|
|
130
130
|
summary: "Call any build-surface event directly. The escape hatch.",
|
|
131
131
|
env: "Doesn't add the project's env. An event that takes one reads only \"env\" in the params, with its own default: booking:* and metrics:query use prod, loops:run_now dev. For a draft bot's booking setup, pass \"env\": \"dev\".",
|
|
132
|
-
usage: ["oalo call <event> ['<json params>' | @file.json | -]", "oalo call --list [text] [--json]"],
|
|
132
|
+
usage: ["oalo call <event> ['<json params>' | @file.json | -] [--timeout <seconds>]", "oalo call --list [text] [--json]"],
|
|
133
133
|
flags: [
|
|
134
134
|
{ flag: "--list [text]", desc: "List the events you can call, from the workspace. With text, the matching events and the params each accepts." },
|
|
135
135
|
{ flag: "--namespaces", desc: "The events you may call, counted per namespace (what `--list` with no text shows)." },
|
|
136
|
+
{ flag: "--timeout <seconds>", desc: "How long to wait for the reply, 1 to 600. Default 30." },
|
|
136
137
|
{ flag: "--compact", desc: "Print the reply as one line of JSON." },
|
|
137
138
|
],
|
|
138
139
|
notes: [
|
|
@@ -532,20 +533,29 @@ export const COMMANDS = [
|
|
|
532
533
|
"oalo bots [--json]",
|
|
533
534
|
"oalo bots knowledge <bot> [--json]",
|
|
534
535
|
"oalo bots knowledge <bot> --add <source> [--add ...] [--remove <source>] [--json]",
|
|
536
|
+
"oalo bots knowledge <bot> --priority <document> [--no-priority <document>] [--json]",
|
|
535
537
|
"oalo bots tools <bot> [--add <tool>] [--remove <tool>] [--json]",
|
|
536
538
|
"oalo bots settings <bot> [--json]",
|
|
537
539
|
"oalo bots settings <bot> set key=value [key=value ...] [--yes] [--dry-run] [--json]",
|
|
538
540
|
"oalo bots settings --explain [<key> | <group>] [--json]",
|
|
539
|
-
"oalo bots graph <bot> [--build] [--json]",
|
|
541
|
+
"oalo bots graph <bot> [--build | --resync | --export] [--json]",
|
|
542
|
+
"oalo bots graph <bot> --search <query> [--json]",
|
|
543
|
+
"oalo bots graph <bot> --import <file.json> [--json]",
|
|
540
544
|
"oalo bots graph <bot> --reset --yes [--json]",
|
|
541
545
|
],
|
|
542
546
|
flags: [
|
|
543
547
|
{ flag: "tools --add <tool>", desc: "Let the bot call one of the workspace's tools, by name. Your server apps' own endpoints are listed once a deploy reads their .oalo/app.json (see `oalo docs app-tools`). --remove takes it away." },
|
|
544
548
|
{ flag: "--add <source>", desc: "knowledge: attach a searchable table: its handle (model:products, table:prod.faq) or just its name when that's unique. Repeat it, or comma-separate." },
|
|
545
549
|
{ flag: "--remove <source>", desc: "Detach one. The table stays searchable for other bots." },
|
|
550
|
+
{ flag: "--priority <document>", desc: "knowledge: mark one of the bot's documents priority, by its id or name as knowledge lists it. Every section of it is the last related section cut when space runs out, and comes with a longer excerpt. --no-priority unmarks it. Repeat it, or comma-separate. Sections of other documents get priority from the priority_words setting." },
|
|
551
|
+
{ flag: "--no-priority <document>", desc: "knowledge: unmark a priority document." },
|
|
546
552
|
{ flag: "set key=value", desc: "settings: change one or more. A value starting with @ is read from that file (for the frame). none, default or an empty value clears a setting where its help says so." },
|
|
547
553
|
{ flag: "--yes", desc: "settings set: apply to a published bot. Without it a published bot's change is shown and not saved. graph --reset: go ahead." },
|
|
548
554
|
{ flag: "--build", desc: "graph: build the bot's knowledge graph from its documents, in the background (a minute or two). After that, each new document keeps it current. Run it again to rebuild it whole." },
|
|
555
|
+
{ flag: "--search <query>", desc: "graph: keyword/substring search over the bot's knowledge graph nodes." },
|
|
556
|
+
{ flag: "--export", desc: "graph: print the bot's knowledge graph as import-compatible JSON ({nodes, edges})." },
|
|
557
|
+
{ flag: "--import <file>", desc: "graph: queue a bulk import from a JSON file with {nodes, edges?}." },
|
|
558
|
+
{ flag: "--resync", desc: "graph: queue a chunk resync to refresh retrieval embeddings from the current graph content." },
|
|
549
559
|
{ flag: "--reset", desc: "graph: delete the whole graph, links added by hand or imported included. Needs --yes." },
|
|
550
560
|
{ flag: "--dry-run", desc: "settings set: show what would change; save nothing." },
|
|
551
561
|
{ flag: "--explain [key]", desc: "settings: what each setting does, its values and default. A key, a group (knowledge, memory, model, replies, limits, data) or all." },
|
|
@@ -553,7 +563,7 @@ export const COMMANDS = [
|
|
|
553
563
|
],
|
|
554
564
|
notes: [
|
|
555
565
|
"<bot> is the bot's public id (bot_...), as `oalo bots` prints it.",
|
|
556
|
-
"A source is a table made searchable with `oalo data vectorize <table> --fields ...`. A bot always searches its own knowledge base (documents) too.",
|
|
566
|
+
"A source is a table made searchable with `oalo data vectorize <table> --fields ...`. A bot always searches its own knowledge base (documents) too. knowledge lists those documents, and which have priority.",
|
|
557
567
|
"The same as ticking a table in the bot's Knowledge pane in the dashboard, with the same access as there.",
|
|
558
568
|
"settings go through the dashboard's own actions, with the same checks and access. A change sets only the settings it names: the model without the provider keeps the provider, one limit keeps the others, one context.* key keeps the rest of the context config.",
|
|
559
569
|
"Every setting is described in `man oalo` (BOT SETTINGS) and by `oalo bots settings --explain`.",
|
|
@@ -561,6 +571,73 @@ export const COMMANDS = [
|
|
|
561
571
|
],
|
|
562
572
|
exits: { 0: "done", 1: "refused or failed", 2: "bad arguments or no CLI token" },
|
|
563
573
|
},
|
|
574
|
+
{
|
|
575
|
+
name: "machines",
|
|
576
|
+
summary: "The computers that answer your bots from their own data, through oalo serve: list, add, revoke, allow.",
|
|
577
|
+
usage: [
|
|
578
|
+
"oalo machines [--json]",
|
|
579
|
+
"oalo machines add <name> [--json]",
|
|
580
|
+
"oalo machines revoke <name> --yes [--json]",
|
|
581
|
+
"oalo machines allow <byo-endpoint/model> [--off] [--json]",
|
|
582
|
+
],
|
|
583
|
+
flags: [
|
|
584
|
+
{ flag: "add <name>", desc: "Make this computer a machine: lowercase letters, digits and hyphens, up to 40 (shop-pc). Saves its key to ~/.oalo/serve/<name>.json, mode 0600. The key is never printed. Admins only." },
|
|
585
|
+
{ flag: "revoke <name>", desc: "Its key stops working at once: oalo serve on it can't connect, and the bot tools it serves stop answering. Removes the key from this computer's config too, keeping its handlers." },
|
|
586
|
+
{ flag: "allow <byo-endpoint/model>", desc: "Let bots and workflows use this own model without waiting for (or passing) ModelCheck. Admins only." },
|
|
587
|
+
{ flag: "--off", desc: "allow: turn the ModelCheck override back off for this model." },
|
|
588
|
+
{ flag: "--yes", desc: "revoke: go ahead. Without it, revoke only says what it would do." },
|
|
589
|
+
{ flag: "--json", desc: "The machines, or what add, revoke, and allow did, as JSON." },
|
|
590
|
+
],
|
|
591
|
+
notes: [
|
|
592
|
+
"The list shows each machine online or offline, when it was last seen, the handlers it declared and which one is this computer. Under it, each model a model handler declared: its model check result (passed, failed, running or not checked), the window it really has, and the id a bot is set to (byo-mep_.../qwen3:14b) once it passes, or why it can't be used yet.",
|
|
593
|
+
"A machine's key (a node token, oalo_node_...) can only answer the box's requests for that machine. It can't read data or change anything in the workspace, so it is safe to leave on a shop computer. It is still a credential: the file is readable only by you.",
|
|
594
|
+
"Then add handlers and start serving: see `oalo help serve`. In the dashboard, a flow or loop's \"On your machine\" step lists each machine's handlers and whether it's online.",
|
|
595
|
+
],
|
|
596
|
+
exits: { 0: "done", 1: "refused or failed (only an admin can add or revoke)", 2: "bad arguments, revoke without --yes, or no CLI token" },
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
name: "serve",
|
|
600
|
+
summary: "Answer your bots from this computer: a folder or a script here answers the bot's tool calls, and the data never leaves it. A model server here (Ollama, vLLM) can run the bots too.",
|
|
601
|
+
usage: [
|
|
602
|
+
"oalo serve [--machine <name>]",
|
|
603
|
+
"oalo serve add folder <name> <path> --describe \"<what's in it>\"",
|
|
604
|
+
"oalo serve add command <name> --describe \"<what it answers>\" [--input 'sku:string,qty:integer?'] [--timeout <seconds>] -- <program> [args...]",
|
|
605
|
+
"oalo serve add model <name> [--base-url <url>] [--server ollama|vllm|openai] [--models <id1,id2>] [--key-env <VAR>] [--context <tokens>] [--output <tokens>] [--describe \"...\"]",
|
|
606
|
+
"oalo serve remove <name>",
|
|
607
|
+
"oalo serve list [--json]",
|
|
608
|
+
"oalo serve test <name> '<json input>'",
|
|
609
|
+
"oalo serve install [--dry-run]",
|
|
610
|
+
],
|
|
611
|
+
flags: [
|
|
612
|
+
{ flag: "--machine <name>", desc: "Which machine, when this computer has more than one (`oalo machines add` made them). Every subcommand takes it." },
|
|
613
|
+
{ flag: "--describe <text>", desc: "add: what the handler holds or answers. The bot reads it when deciding to call the tool, so be specific: \"Store policies, shipping and returns\"." },
|
|
614
|
+
{ flag: "--input <fields>", desc: "add command: the fields the bot sends, name:type, comma-separated: --input 'sku:string,qty:integer?'. Types string, integer, number, boolean; a ? makes a field optional (keep the quotes, or zsh reads the ? as a file pattern). Left out, the tool takes no input." },
|
|
615
|
+
{ flag: "--timeout <seconds>", desc: "add command: how long the program may run, 1 to 3600. Default 30 (chat tool calls are still capped at 120s on the box; workflow remote steps can run up to 1 hour). Then it's stopped (SIGTERM, then SIGKILL 2 s later) and the caller sees a timeout." },
|
|
616
|
+
{ flag: "-- <program> [args...]", desc: "add command: the program to run and its arguments, after a bare --. Run directly, never through a shell, from the folder you ran add in." },
|
|
617
|
+
{ flag: "--base-url <url>", desc: "add model: the model server's OpenAI-style API root, http or https. Default Ollama's http://127.0.0.1:11434/v1. Every model call goes to <url>/chat/completions and nowhere else. A warning if it isn't this computer or a private network address." },
|
|
618
|
+
{ flag: "--server <kind>", desc: "add model: ollama, vllm or openai (any other OpenAI-compatible server, like LM Studio). Left out: ollama on port 11434, vllm when its model list says so, else openai. It decides how thinking is turned off." },
|
|
619
|
+
{ flag: "--models <ids>", desc: "add model: which of the server's models to declare, comma-separated, up to 32 (qwen3:14b,llama3.2:3b). Left out: all its chat models." },
|
|
620
|
+
{ flag: "--key-env <name>", desc: "add model: the NAME of an environment variable holding the model server's key, sent as Authorization: Bearer. The key isn't saved, printed or sent to the workspace; set the variable where oalo serve runs." },
|
|
621
|
+
{ flag: "--context <tokens>", desc: "add model: the context window to declare for every model. Left out: Ollama's num_ctx if the model sets one, else the model's maximum; vLLM's max_model_len." },
|
|
622
|
+
{ flag: "--output <tokens>", desc: "add model: the most tokens a reply may take, for every model. Default the smaller of 8192 and a quarter of the context." },
|
|
623
|
+
{ flag: "--dry-run", desc: "install: print the service file and the command to load it; write nothing." },
|
|
624
|
+
{ flag: "--json", desc: "list: the machine's handlers as JSON." },
|
|
625
|
+
],
|
|
626
|
+
notes: [
|
|
627
|
+
"Start with `oalo machines add <name>`, which saves this computer's key (step by step: `oalo docs answer-from-your-own-data`). Handlers live in that machine's config, ~/.oalo/serve/<name>.json, never in a project. OALO_HOME moves it.",
|
|
628
|
+
"oalo serve connects out to your workspace and declares the handlers; nothing listens on this computer and no port is opened. Each handler becomes a workspace tool with the handler's name: give it to a bot with `oalo bots tools <bot> --add <handler>`. A name another tool already has is skipped, and oalo serve says so. A handler name is lowercase letters, digits and underscores, up to 48, starting with a letter.",
|
|
629
|
+
"It prints one line per request: the time, the handler, how long it took, ok or the error, and the sizes in and out. Never what was asked or answered, which can be customer data. If the connection drops it reconnects, waiting 1 s, then 2, 4, up to 30.",
|
|
630
|
+
"folder: keyword search over the folder's .md, .markdown, .txt, .csv, .tsv, .json, .html and .htm files. Hidden files and folders, node_modules, files over 2 MB and links that lead outside the folder are skipped; nothing outside it is read. Markdown is split by heading and paragraph, a CSV or TSV one row at a time with its header line. Accents don't matter: devolucion finds devolución. The bot sends {\"query\", \"limit\"} (limit 1 to 10, default 5) and gets back {\"results\": [{\"file\", \"snippet\", \"score\"}]}. Edits are picked up on the next request.",
|
|
631
|
+
"command: the program gets {\"input\": {...}, \"context\": {...}} on stdin and prints one JSON object on stdout, which is the answer. context has surface (chat, flow or loop), bot, conversation and member: the verified id of the person chatting, so a script can return only their own orders. A flow step adds the flow's name, a loop step the loop's name and the run's contact. Use it, never a name or id the person typed. A non-zero exit or output that isn't a JSON object is an error the bot sees, with the last line the program wrote to stderr. Its environment is yours minus every OALO_ variable.",
|
|
632
|
+
"An answer is at most 64 KB; a bigger one is refused as \"output too large\". The answer goes into the bot's reply, so it passes through Oalo and the bot's model for that message. The folder or the program's data stays here.",
|
|
633
|
+
"test runs a handler here, with no connection, and prints exactly what the bot would get. Try every handler with it before a bot uses it.",
|
|
634
|
+
"install writes a launchd agent (macOS, ~/Library/LaunchAgents/ai.oalo.serve.<name>.plist) or a systemd user unit (Linux, ~/.config/systemd/user/oalo-serve-<name>.service) that runs oalo serve --machine <name> at login and restarts it if it stops, then prints the one command that starts it. It never runs launchctl or systemctl itself.",
|
|
635
|
+
"model: runs your bots on a model server on this computer or your network (Ollama, vLLM, LM Studio, anything OpenAI-compatible). It isn't a tool: the workspace sends a model id and a chat request, never an address, and this computer forwards it to the --base-url in its own config and streams the reply back. add reads the server's models (and, for Ollama, each model's window and whether it sees images); run it again with the same name to update them. Ollama serves a smaller window than a model's maximum unless OLLAMA_CONTEXT_LENGTH or num_ctx is raised, so add says so, and the workspace's model check finds the real one. test sends one message the way the workspace would, thinking off, and prints the reply, the time to the first token and tokens per second: oalo serve test <name> '{\"model\": \"qwen3:14b\", \"message\": \"Say hi in five words\"}'. Each model call is one line: the time, the handler, the model, how long, the first token, tokens in and out. Never the conversation. Before a bot can use a model, the workspace checks it through the same path a member's message takes: it must call a made-up lookup tool and answer from it (6 of 6), pick the right one of three tools, refuse to run commands or read files, never reply with nothing, find facts far back in a long conversation, and return a form's fields as JSON. A model that can't call tools fails, and so does one whose server really reads fewer than 8,192 tokens (raise OLLAMA_CONTEXT_LENGTH or num_ctx, then add the model again with --context so it's checked again). The check starts by itself when oalo serve first declares a model and takes a few minutes per model; `oalo machines` shows the result. Then set the bot to the model: oalo bots settings <bot> set provider=opencode model=<the id oalo machines shows>. If this computer is off when a bot needs the model, the member gets a short apology and the workspace an incident. The whole walkthrough: `oalo docs run-your-bot-on-your-own-model`.",
|
|
636
|
+
"After add or remove, restart oalo serve so the workspace sees the change.",
|
|
637
|
+
"Flows and loops can call a handler too, with a remote_step (\"On your machine\" in the editor). The step waits for the answer without holding anything open, and a step that started while this computer was off is sent when oalo serve connects. The handler's own --timeout still limits each run.",
|
|
638
|
+
],
|
|
639
|
+
exits: { 0: "done, or stopped with Ctrl-C", 1: "a handler failed its test, the key was revoked, or a write failed", 2: "bad arguments, no machine on this computer, or no handlers" },
|
|
640
|
+
},
|
|
564
641
|
{
|
|
565
642
|
name: "tokens",
|
|
566
643
|
summary: "List, create and revoke the workspace's sync tokens, for an app's own server.",
|
|
@@ -858,7 +935,8 @@ export const COMMANDS = [
|
|
|
858
935
|
"Without files, pushes every file edited since its pull (and new ones).",
|
|
859
936
|
"Each save sends the pulled version: if someone saved in between, the push is refused as a conflict and nothing is overwritten. Pull, merge, push again.",
|
|
860
937
|
"Saves are strict: error-level lint findings block them. Fix the findings (each says how) or pass --no-strict.",
|
|
861
|
-
"After a save the file is rewritten from the server's copy with the new version.",
|
|
938
|
+
"After a save the file is rewritten from the server's copy with the new version. A flow file pushed from outside .oalo/flows is kept as it is, and the saved copy goes to .oalo/flows/<bot>/<flow>.json.",
|
|
939
|
+
"Oalo keeps no older versions of a flow or loop. Keep the .oalo/ files in git to have them: to go back, restore the earlier file and run `oalo push <file> --force` (it still carries the version it was pulled at, so without --force it counts as unchanged).",
|
|
862
940
|
"Needs a CLI token.",
|
|
863
941
|
],
|
|
864
942
|
exits: { 0: "every file saved", 1: "a file was refused, in conflict, or failed", 2: "bad arguments or no token" },
|
|
@@ -897,8 +975,8 @@ export const COMMANDS = [
|
|
|
897
975
|
usage: ["oalo rehearse [--number <phone_number_id>] [--responder <bot_...>] [--timeout <s>] [--json]", "oalo rehearse --script <file.json>"],
|
|
898
976
|
flags: [
|
|
899
977
|
{ flag: "--number <id>", desc: "The WhatsApp number (phone_number_id) the customer writes to. Default: the workspace's default number." },
|
|
900
|
-
{ flag: "--responder <bot_...>", desc: "The bot the checks expect to end up answering, by its public id (`oalo bots` lists them). It's a check, not routing: messages still go where the number and its triage send them. To rehearse a bot that isn't on the number, give a --script scenario with an open_thread on that bot. Default: the bot an enabled triage loop hands threads to, else the number's bot." },
|
|
901
|
-
{ flag: "--script <file>", desc: 'A JSON file: {"scenarios": [{"name", "messages", "known_contact", "opted_out", "open_thread": {"bot_id", "number", "hours_ago", "tags", "assigned", "deal", "messages"}, "expect": {"reply", "bot_id", "assigned"}}]}. open_thread.bot_id is a public id (bot_...) or number. An open thread starts with one earlier exchange: open_thread.messages [customer, reply] when given, else a Spanish greeting ("Hola" / "¡Hola! ¿En qué te puedo ayudar?"), which can set the language the bot answers in.' },
|
|
978
|
+
{ flag: "--responder <bot_...>", desc: "The bot the checks expect to end up answering, by its public id (`oalo bots` lists them). It's a check, not routing: messages still go where the number and its triage send them. To rehearse a bot that isn't on the number, give a --script scenario with an open_thread on that bot. Default: the bot an enabled triage loop hands threads to, counting only loops that fire for a WhatsApp message on that number (their channel and bot filters allow it), else the number's bot." },
|
|
979
|
+
{ flag: "--script <file>", desc: 'A JSON file: {"scenarios": [{"name", "messages", "known_contact", "opted_out", "open_thread": {"bot_id", "number", "hours_ago", "tags", "assigned", "deal", "messages"}, "expect": {"reply", "bot_id", "assigned"}}]}. open_thread.bot_id is a public id (bot_...) or number. open_thread.number defaults to the number the scenario writes to. An open thread starts with one earlier exchange: open_thread.messages [customer, reply] when given, else a Spanish greeting ("Hola" / "¡Hola! ¿En qué te puedo ayudar?"), which can set the language the bot answers in.' },
|
|
902
980
|
{ flag: "--timeout <s>", desc: "How long one message may take to settle. Default 120, at most 300." },
|
|
903
981
|
{ flag: "--json", desc: "Print every scenario as JSON: turns (what was sent), threads, loop runs and their steps, checks, why_silent, cost_usd." },
|
|
904
982
|
],
|
|
@@ -933,6 +1011,7 @@ export const COMMANDS = [
|
|
|
933
1011
|
usage: ["oalo mcp"],
|
|
934
1012
|
flags: [],
|
|
935
1013
|
notes: [
|
|
1014
|
+
"Add it to Claude Code from the linked project folder: `claude mcp add oalo -- oalo mcp` (or put {\"mcpServers\": {\"oalo\": {\"command\": \"oalo\", \"args\": [\"mcp\"]}}} in .mcp.json). Cursor: the same command and args in its MCP settings.",
|
|
936
1015
|
"stdout is the MCP protocol stream. Diagnostics go to stderr.",
|
|
937
1016
|
"Exposes a curated tool set plus an oalo_call passthrough; the build surface has ~442 events and mapping them all would wreck tool selection.",
|
|
938
1017
|
"oalo_describe is a short summary (apps, bots and loops by name, the tool groups, how dev and prod work, the docs index); its section argument pages through the full records. A reply longer than about 60,000 characters has its longest list cut, with a `_cut` note saying how to get the rest (oalo_call takes match and offset; oalo_node_catalog takes node_type).",
|
package/src/index.js
CHANGED
|
@@ -35,6 +35,8 @@ import { metrics, dashboards } from "./commands/metrics.js";
|
|
|
35
35
|
import { db } from "./commands/db.js";
|
|
36
36
|
import { migrate } from "./commands/migrate.js";
|
|
37
37
|
import { coordInstall, coordRun } from "./commands/coord-bin.js";
|
|
38
|
+
import { machines } from "./commands/machines.js";
|
|
39
|
+
import { serve } from "./commands/serve.js";
|
|
38
40
|
import { existsSync } from "node:fs";
|
|
39
41
|
import { overview, commandHelp, helpJson, COMMANDS } from "./help.js";
|
|
40
42
|
import { parse } from "./args.js";
|
|
@@ -158,6 +160,12 @@ async function dispatch(cmd) {
|
|
|
158
160
|
case "sources":
|
|
159
161
|
await sources(flags, rest);
|
|
160
162
|
break;
|
|
163
|
+
case "machines":
|
|
164
|
+
await machines(flags, rest);
|
|
165
|
+
break;
|
|
166
|
+
case "serve":
|
|
167
|
+
await serve(flags, rest);
|
|
168
|
+
break;
|
|
161
169
|
case "setup":
|
|
162
170
|
await setup(flags, rest);
|
|
163
171
|
break;
|
package/src/mcp/describe.js
CHANGED
|
@@ -20,7 +20,8 @@ export const TOOL_GROUPS = {
|
|
|
20
20
|
"data": ["oalo_list_models", "oalo_create_model", "oalo_read_rows", "oalo_write_rows", "oalo_promote_model", "oalo_db_query", "oalo_query_metrics", "oalo_sync_routes", "oalo_list_dashboards", "oalo_save_dashboard_widget"],
|
|
21
21
|
"code tools": ["oalo_list_functions", "oalo_generate_tool", "oalo_get_tool_source", "oalo_save_tool_source", "oalo_tool_templates", "oalo_bot_tools"],
|
|
22
22
|
"apps": ["oalo_app_logs", "oalo_releases"],
|
|
23
|
-
"channels and sales": ["oalo_widgets", "oalo_wa_templates", "oalo_rehearse_inbound", "oalo_pipelines"
|
|
23
|
+
"channels and sales": ["oalo_widgets", "oalo_wa_templates", "oalo_rehearse_inbound", "oalo_pipelines"],
|
|
24
|
+
"knowledge graph": ["oalo_knowledge_search", "oalo_knowledge_graph", "oalo_knowledge_edit"],
|
|
24
25
|
"anything else": ["oalo_call"],
|
|
25
26
|
};
|
|
26
27
|
|
package/src/mcp/fit.js
CHANGED
|
@@ -41,7 +41,9 @@ export function fitReply(result, { max = MAX_REPLY_CHARS, hint = "", offset = 0
|
|
|
41
41
|
if (lo > 0 && text.length <= max) return text;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
const note = `The whole reply is ${compact.length} characters, more than an MCP reply can hold.${hint ? ` ${hint}` : ""}`;
|
|
45
|
+
const budget = Math.max(200, max - note.length - 80);
|
|
46
|
+
return JSON.stringify({ _cut: note, total_chars: compact.length, preview: compact.slice(0, budget) });
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/**
|
package/src/mcp/tools.js
CHANGED
|
@@ -576,13 +576,87 @@ export const TOOLS = [
|
|
|
576
576
|
},
|
|
577
577
|
{
|
|
578
578
|
name: "oalo_knowledge_search",
|
|
579
|
-
description:
|
|
580
|
-
|
|
579
|
+
description:
|
|
580
|
+
"Keyword/substring (ILIKE) search over a bot's knowledge graph node titles and summaries. Pass short keywords or topic names rather than full sentences.",
|
|
581
|
+
inputSchema: S({ bot_id: { type: "string" }, query: { type: "string", description: "Short keyword or substring to match" } }, [
|
|
581
582
|
"bot_id",
|
|
582
583
|
"query",
|
|
583
584
|
]),
|
|
584
585
|
event: "kg:search",
|
|
585
586
|
},
|
|
587
|
+
{
|
|
588
|
+
name: "oalo_knowledge_graph",
|
|
589
|
+
description:
|
|
590
|
+
"Inspect or maintain a bot's knowledge graph. Actions: counts (node/edge counts and config), roots (top-level nodes), focus (inspect node_id and its neighbors), export (full import-compatible {nodes, edges} JSON), import (queue bulk import of nodes and edges), resync (rebuild retrieval chunks from graph content), rebuild (re-derive auto graph from documents).",
|
|
591
|
+
inputSchema: S(
|
|
592
|
+
{
|
|
593
|
+
action: {
|
|
594
|
+
type: "string",
|
|
595
|
+
enum: ["counts", "roots", "focus", "export", "import", "resync", "rebuild"],
|
|
596
|
+
},
|
|
597
|
+
bot_id: { type: "string", description: "Bot public id (bot_...) or numeric id. Required for all actions except focus." },
|
|
598
|
+
node_id: { type: "string", description: "Node id for action=focus" },
|
|
599
|
+
limit: { type: "number", description: "Max neighbors for action=focus (1-100, default 40)" },
|
|
600
|
+
nodes: { type: "array", items: { type: "object" }, description: "Nodes array for action=import" },
|
|
601
|
+
edges: { type: "array", items: { type: "object" }, description: "Edges array for action=import" },
|
|
602
|
+
},
|
|
603
|
+
["action"],
|
|
604
|
+
),
|
|
605
|
+
run: async (oalo, { action, bot_id, node_id, limit, nodes, edges }) => {
|
|
606
|
+
if (action === "focus") {
|
|
607
|
+
if (!node_id) throw new Error("node_id is required for action=focus");
|
|
608
|
+
return oalo.call("kg:focus", { node_id, ...(limit != null ? { limit } : {}) });
|
|
609
|
+
}
|
|
610
|
+
if (!bot_id) throw new Error(`bot_id is required for action=${action}`);
|
|
611
|
+
if (action === "counts") {
|
|
612
|
+
const [cfg, counts] = await Promise.all([oalo.call("kg:config", { bot_id }), oalo.call("kg:counts", { bot_id })]);
|
|
613
|
+
return { ...cfg, ...counts };
|
|
614
|
+
}
|
|
615
|
+
if (action === "roots") return oalo.call("kg:roots", { bot_id });
|
|
616
|
+
if (action === "export") return oalo.call("kg:export", { bot_id }, 120_000);
|
|
617
|
+
if (action === "import") {
|
|
618
|
+
if (!Array.isArray(nodes)) throw new Error("nodes array is required for action=import");
|
|
619
|
+
return oalo.call("kg:import", { bot_id, nodes, edges: Array.isArray(edges) ? edges : [] }, 120_000);
|
|
620
|
+
}
|
|
621
|
+
if (action === "resync") return oalo.call("kg:resync_chunks", { bot_id });
|
|
622
|
+
if (action === "rebuild") return oalo.call("kg:rebuild", { bot_id });
|
|
623
|
+
throw new Error(`unknown action: ${action}`);
|
|
624
|
+
},
|
|
625
|
+
mutates: true,
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
name: "oalo_knowledge_edit",
|
|
629
|
+
description:
|
|
630
|
+
"Create, update, or delete curated nodes and edges in a bot's knowledge graph. Actions: create_node, update_node, delete_node, create_edge, delete_edge.",
|
|
631
|
+
inputSchema: S(
|
|
632
|
+
{
|
|
633
|
+
action: {
|
|
634
|
+
type: "string",
|
|
635
|
+
enum: ["create_node", "update_node", "delete_node", "create_edge", "delete_edge"],
|
|
636
|
+
},
|
|
637
|
+
bot_id: { type: "string", description: "Required for create_node and create_edge" },
|
|
638
|
+
node_id: { type: "string", description: "Required for update_node and delete_node" },
|
|
639
|
+
title: { type: "string", description: "Node title" },
|
|
640
|
+
summary: { type: "string", description: "Node summary" },
|
|
641
|
+
content: { type: "string", description: "Node full content/body" },
|
|
642
|
+
kind: { type: "string", description: "Node kind (topic, section, entity, fact, ...)" },
|
|
643
|
+
from: { type: "string", description: "Source node id for create_edge / delete_edge" },
|
|
644
|
+
to: { type: "string", description: "Target node id for create_edge / delete_edge" },
|
|
645
|
+
relation: { type: "string", description: "Edge relation name for create_edge / delete_edge" },
|
|
646
|
+
weight: { type: "number", description: "Optional edge weight (default 1.0)" },
|
|
647
|
+
},
|
|
648
|
+
["action"],
|
|
649
|
+
),
|
|
650
|
+
route: ({ action, ...rest }) => {
|
|
651
|
+
if (action === "create_node") return { event: "kg:node:create", params: rest };
|
|
652
|
+
if (action === "update_node") return { event: "kg:node:update", params: rest };
|
|
653
|
+
if (action === "delete_node") return { event: "kg:node:delete", params: { node_id: rest.node_id } };
|
|
654
|
+
if (action === "create_edge") return { event: "kg:edge:create", params: rest };
|
|
655
|
+
if (action === "delete_edge") return { event: "kg:edge:delete", params: { from: rest.from, to: rest.to, relation: rest.relation } };
|
|
656
|
+
throw new Error(`unknown action: ${action}`);
|
|
657
|
+
},
|
|
658
|
+
mutates: true,
|
|
659
|
+
},
|
|
586
660
|
{
|
|
587
661
|
name: "oalo_jobs",
|
|
588
662
|
description:
|
|
@@ -799,12 +873,19 @@ export const TOOLS = [
|
|
|
799
873
|
params: { type: "object", description: "Event params" },
|
|
800
874
|
match: { type: "string", description: "Keep only the items of the reply's longest list that mention this text (any field, any case), e.g. send_email." },
|
|
801
875
|
offset: { type: "number", description: "Skip this many items of the reply's longest list (after match), to page past a cut." },
|
|
876
|
+
timeout_ms: { type: "number", description: "Optional timeout in milliseconds (1000 to 600000, default 30000) for slow events like kg:import, loops:test, or chat:bots:qa_run." },
|
|
802
877
|
},
|
|
803
878
|
["event"],
|
|
804
879
|
),
|
|
805
|
-
run: async (oalo, { event, params, match, offset }) => {
|
|
880
|
+
run: async (oalo, { event, params, match, offset, timeout_ms }) => {
|
|
806
881
|
if (!event) throw new Error("event is required");
|
|
807
|
-
|
|
882
|
+
let ms;
|
|
883
|
+
if (timeout_ms !== undefined) {
|
|
884
|
+
const n = Number(timeout_ms);
|
|
885
|
+
if (!Number.isFinite(n) || n < 1000 || n > 600_000) throw new Error("timeout_ms must be between 1000 and 600000");
|
|
886
|
+
ms = Math.round(n);
|
|
887
|
+
}
|
|
888
|
+
const reply = ms ? await oalo.call(event, params || {}, ms) : await oalo.call(event, params || {});
|
|
808
889
|
return match || offset ? narrowList(reply, { match, offset }) : reply;
|
|
809
890
|
},
|
|
810
891
|
cutHint: "Pass match=<word> to keep only the items that mention it, or offset=<n> to skip the ones shown.",
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { MAX_OUTPUT_BYTES, clampTimeout } from "./config.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The `command` handler: run a local program, never through a shell. It gets
|
|
6
|
+
* {"input": ..., "context": ...} on stdin and prints one JSON object on
|
|
7
|
+
* stdout, which is the handler's output.
|
|
8
|
+
*
|
|
9
|
+
* The child's environment is this process's minus every OALO_ variable, so a
|
|
10
|
+
* script never sees the CLI's own settings. The node token isn't in the
|
|
11
|
+
* environment at all (it lives in the machine's config file), and it is never
|
|
12
|
+
* on a child's command line.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const KILL_AFTER_MS = 2000;
|
|
16
|
+
const STDERR_KEEP = 8192;
|
|
17
|
+
|
|
18
|
+
/** process.env without OALO_* (and with nothing else changed). */
|
|
19
|
+
export function childEnv(env = process.env) {
|
|
20
|
+
const out = {};
|
|
21
|
+
for (const [k, v] of Object.entries(env)) if (!k.startsWith("OALO_")) out[k] = v;
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The last non-empty stderr line, at most 300 characters. */
|
|
26
|
+
export function lastLine(text) {
|
|
27
|
+
const lines = String(text || "").split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
28
|
+
const l = lines[lines.length - 1] || "";
|
|
29
|
+
return l.length > 300 ? l.slice(0, 297) + "..." : l;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Run one request. `timeoutMs` is the handler's timeout, already cut to the
|
|
34
|
+
* request's deadline. Resolves {ok, output} or {ok: false, error}; never
|
|
35
|
+
* rejects.
|
|
36
|
+
*/
|
|
37
|
+
export function runCommand(handler, input, context, { timeoutMs, env = process.env } = {}) {
|
|
38
|
+
const argv = handler.command?.argv;
|
|
39
|
+
if (!Array.isArray(argv) || !argv.length || !argv.every((a) => typeof a === "string")) {
|
|
40
|
+
return Promise.resolve({ ok: false, error: "this handler has no command to run" });
|
|
41
|
+
}
|
|
42
|
+
const limit = clampTimeout(timeoutMs ?? handler.timeout_ms);
|
|
43
|
+
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
let done = false;
|
|
46
|
+
let timer = null;
|
|
47
|
+
let killer = null;
|
|
48
|
+
const finish = (r) => {
|
|
49
|
+
if (done) return;
|
|
50
|
+
done = true;
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
clearTimeout(killer);
|
|
53
|
+
resolve(r);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
let child;
|
|
57
|
+
const group = process.platform !== "win32";
|
|
58
|
+
try {
|
|
59
|
+
child = spawn(argv[0], argv.slice(1), {
|
|
60
|
+
cwd: handler.command.cwd || undefined,
|
|
61
|
+
env: childEnv(env),
|
|
62
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
63
|
+
shell: false,
|
|
64
|
+
detached: group,
|
|
65
|
+
windowsHide: true,
|
|
66
|
+
});
|
|
67
|
+
} catch (e) {
|
|
68
|
+
return finish({ ok: false, error: `couldn't start ${argv[0]}: ${e.code || e.message}` });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const out = [];
|
|
72
|
+
let outBytes = 0;
|
|
73
|
+
let tooBig = false;
|
|
74
|
+
let err = "";
|
|
75
|
+
let timedOut = false;
|
|
76
|
+
|
|
77
|
+
// The child leads its own process group, so a script's own children
|
|
78
|
+
// (a shell's sleep, say) stop with it.
|
|
79
|
+
const sendSignal = (sig) => {
|
|
80
|
+
try {
|
|
81
|
+
if (group) process.kill(-child.pid, sig);
|
|
82
|
+
else child.kill(sig);
|
|
83
|
+
} catch {
|
|
84
|
+
try { child.kill(sig); } catch { /* gone */ }
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const stop = () => {
|
|
88
|
+
if (killer) return;
|
|
89
|
+
sendSignal("SIGTERM");
|
|
90
|
+
killer = setTimeout(() => sendSignal("SIGKILL"), KILL_AFTER_MS);
|
|
91
|
+
killer.unref?.();
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
timer = setTimeout(() => {
|
|
95
|
+
timedOut = true;
|
|
96
|
+
stop();
|
|
97
|
+
}, limit);
|
|
98
|
+
|
|
99
|
+
child.stdout.on("data", (b) => {
|
|
100
|
+
if (tooBig) return;
|
|
101
|
+
outBytes += b.length;
|
|
102
|
+
if (outBytes > MAX_OUTPUT_BYTES) {
|
|
103
|
+
tooBig = true;
|
|
104
|
+
stop();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
out.push(b);
|
|
108
|
+
});
|
|
109
|
+
child.stderr.on("data", (b) => {
|
|
110
|
+
err = (err + b.toString("utf8")).slice(-STDERR_KEEP);
|
|
111
|
+
});
|
|
112
|
+
// A program that exits without reading stdin closes the pipe: not an error.
|
|
113
|
+
child.stdin.on("error", () => {});
|
|
114
|
+
|
|
115
|
+
child.on("error", (e) => {
|
|
116
|
+
const why = e.code === "ENOENT" ? "not found" : e.code === "EACCES" ? "not allowed to run it" : e.code || e.message;
|
|
117
|
+
finish({ ok: false, error: `couldn't start ${argv[0]}: ${why}` });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
child.on("close", (code, signal) => {
|
|
121
|
+
const tail = lastLine(err);
|
|
122
|
+
const withTail = (msg) => (tail ? `${msg}: ${tail}` : msg);
|
|
123
|
+
if (timedOut) return finish({ ok: false, error: `timed out after ${limit >= 1000 ? `${Math.round(limit / 1000)}s` : `${limit} ms`}` });
|
|
124
|
+
if (tooBig) {
|
|
125
|
+
const maxKb = Math.round(MAX_OUTPUT_BYTES / 1024);
|
|
126
|
+
return finish({ ok: false, error: `output too large (over ${maxKb} KB, max ${maxKb} KB)` });
|
|
127
|
+
}
|
|
128
|
+
if (signal) return finish({ ok: false, error: withTail(`stopped by ${signal}`) });
|
|
129
|
+
if (code !== 0) return finish({ ok: false, error: withTail(`exited with code ${code}`) });
|
|
130
|
+
const text = Buffer.concat(out).toString("utf8").trim();
|
|
131
|
+
let output;
|
|
132
|
+
try {
|
|
133
|
+
output = JSON.parse(text);
|
|
134
|
+
} catch {
|
|
135
|
+
return finish({ ok: false, error: withTail(text ? "printed something that isn't JSON" : "printed nothing (it should print one JSON object)") });
|
|
136
|
+
}
|
|
137
|
+
if (!output || typeof output !== "object" || Array.isArray(output)) {
|
|
138
|
+
return finish({ ok: false, error: "printed JSON that isn't an object (wrap it: {\"results\": [...]})" });
|
|
139
|
+
}
|
|
140
|
+
finish({ ok: true, output });
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
child.stdin.end(JSON.stringify({ input, context }) + "\n");
|
|
144
|
+
});
|
|
145
|
+
}
|