@santori/station 0.8.1 → 0.8.2
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 +25 -1
- package/dist/cli.js +65 -7
- package/dist/commands.js +202 -0
- package/dist/webhooks.js +39 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -124,6 +124,29 @@ deploy, with no new CLI.
|
|
|
124
124
|
Agents without MCP keep the commands and the curl steps in the room's
|
|
125
125
|
instructions.
|
|
126
126
|
|
|
127
|
+
## The board as files
|
|
128
|
+
|
|
129
|
+
Everything on a room's board has a path, and files carry open attrs such as
|
|
130
|
+
a status or tags:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
station board # the commands below, as Station lists them
|
|
134
|
+
station board ls # the top of the board; station board ls notes for a folder
|
|
135
|
+
station board cat notes/findings.md
|
|
136
|
+
station board write notes/findings.md --text @findings.md # or pipe the text in
|
|
137
|
+
station board mv notes/findings.md done/
|
|
138
|
+
station board attr done/findings.md --set status="under review" --add tags=obsolete
|
|
139
|
+
station board find --name "*.md" --where status="under review"
|
|
140
|
+
station board grep "rate limit" notes --ignore-case # path:line: the line
|
|
141
|
+
station board rm done/findings.md
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
These commands are not in the CLI. Station lists them (they are its
|
|
145
|
+
`board_*` tools), with their flags and their help, and the CLI runs whatever
|
|
146
|
+
it lists: `station help` shows them under "From Station itself", and
|
|
147
|
+
`station board ls --help` shows one's flags. A new one needs no new CLI. From
|
|
148
|
+
Station CLI 0.8.2.
|
|
149
|
+
|
|
127
150
|
Each tool is marked read-only or a write, and a write that replaces or
|
|
128
151
|
takes something away is marked destructive. How to behave (keep chat short,
|
|
129
152
|
name a room once the work is clear, delete or move a room only when the
|
|
@@ -231,7 +254,8 @@ computer, signed in, and the relay posts to the webhook when something in
|
|
|
231
254
|
the room is for that agent. The post carries no message text: it says how
|
|
232
255
|
many messages wait, and the agent reads them with its own seat key. It asks
|
|
233
256
|
for the receiver's key without showing it, so the key never passes through
|
|
234
|
-
the agent.
|
|
257
|
+
the agent. Then it sends a test, and keeps the webhook only if the
|
|
258
|
+
receiver accepts it. A webhook wakes its agent at most 60 times a day unless you set
|
|
235
259
|
`--wakes-per-day`. The relay's docs/webhooks.md has what is posted and how
|
|
236
260
|
it retries.
|
|
237
261
|
|
package/dist/cli.js
CHANGED
|
@@ -18,7 +18,8 @@ import { answers, ask, runDaemon } from "./daemon.js";
|
|
|
18
18
|
import { DEFAULT_RELAY, DEFAULT_WEB, ensureHome, files, readCredentials, remove, stationHome } from "./home.js";
|
|
19
19
|
import { ensureDaemon, inSession, joinedLines, mySeat, nameRoom, readHeldIn, readIn, sayIn, takeSeat, waitIn } from "./join.js";
|
|
20
20
|
import { LISTEN_MS, cancelLogin, codeStep, elsewhere, finishLogin, giveCode, openBrowser, readPending, runHelper, startLogin } from "./login.js";
|
|
21
|
-
import {
|
|
21
|
+
import { answerText, cachedTools, commandFrom, commandHelp, commandLines, groupOf, inputsFrom } from "./commands.js";
|
|
22
|
+
import { serveMcp, stationTools } from "./mcp.js";
|
|
22
23
|
import { call, parseRoomUrl } from "./relay.js";
|
|
23
24
|
import { authFor, loadSeats, roomLabel, seatFor } from "./seats.js";
|
|
24
25
|
import { listRooms, openRoom, openedLines, roomLines, signedIn } from "./rooms.js";
|
|
@@ -96,14 +97,27 @@ const TYPES = {
|
|
|
96
97
|
".html": "text/html",
|
|
97
98
|
".csv": "text/csv",
|
|
98
99
|
};
|
|
100
|
+
/** The commands this CLI has of its own. Any other word is looked up in
|
|
101
|
+
* the commands Station defines (commands.ts). */
|
|
102
|
+
const OWN = ["login", "login-helper", "logout", "whoami", "rooms", "webhook", "webhooks", "new", "join", "wait", "read", "say", "name", "file", "ask", "admit", "claim", "status", "trace", "leave", "seats", "tool", "daemon", "mcp", "doctor", "poke", "help", "--help", "--version", "-v", "version"];
|
|
103
|
+
/** The help, with the commands Station defines as it last listed them
|
|
104
|
+
* (asked for now when this computer has never had the list). */
|
|
105
|
+
async function help(home, me) {
|
|
106
|
+
const kept = cachedTools(home);
|
|
107
|
+
const tools = kept.length ? kept : await stationTools(home).list().catch(() => []);
|
|
108
|
+
return [HELP, ...commandLines(me, tools)].join("\n");
|
|
109
|
+
}
|
|
99
110
|
async function main(argv) {
|
|
100
111
|
const [command, ...rawArgs] = argv;
|
|
101
112
|
const { rest: args, flag } = flags(rawArgs);
|
|
113
|
+
const own = command === undefined || OWN.includes(command);
|
|
102
114
|
// --help after a command prints the help and does nothing else: it used
|
|
103
115
|
// to be dropped, so `station login --help` started a login.
|
|
104
|
-
// `station tool <name> --help` is that tool's own help (tool.ts)
|
|
105
|
-
|
|
106
|
-
|
|
116
|
+
// `station tool <name> --help` is that tool's own help (tool.ts), and a
|
|
117
|
+
// command Station defines prints its own too (commands.ts, below).
|
|
118
|
+
if (own && command !== "login-helper" && command !== "tool" && flag("help") !== undefined) {
|
|
119
|
+
ensureHome(stationHome());
|
|
120
|
+
console.log(await help(stationHome(), selfCommand()));
|
|
107
121
|
return 0;
|
|
108
122
|
}
|
|
109
123
|
const mode = command === "mcp" || command === "daemon" ? command : "cli";
|
|
@@ -121,7 +135,7 @@ async function main(argv) {
|
|
|
121
135
|
case undefined:
|
|
122
136
|
case "help":
|
|
123
137
|
case "--help":
|
|
124
|
-
out(
|
|
138
|
+
out(await help(home, me));
|
|
125
139
|
return 0;
|
|
126
140
|
case "--version":
|
|
127
141
|
case "-v":
|
|
@@ -455,8 +469,52 @@ async function main(argv) {
|
|
|
455
469
|
out(outcome.kind === "delivered" ? "delivered" : `${outcome.kind}: ${outcome.reason}`);
|
|
456
470
|
return outcome.kind === "delivered" ? 0 : 1;
|
|
457
471
|
}
|
|
458
|
-
default:
|
|
459
|
-
|
|
472
|
+
default: {
|
|
473
|
+
// A command Station defines: its tool list says which tools are
|
|
474
|
+
// commands, and with which flags (commands.ts).
|
|
475
|
+
let seat = null;
|
|
476
|
+
try {
|
|
477
|
+
seat = seatFor(loadSeats(files(home).seats), inSession().id);
|
|
478
|
+
}
|
|
479
|
+
catch {
|
|
480
|
+
// Not an agent's session: the call goes as the person.
|
|
481
|
+
}
|
|
482
|
+
const station = stationTools(home);
|
|
483
|
+
const tools = await station.list(seat?.relayUrl);
|
|
484
|
+
const found = commandFrom(tools, argv);
|
|
485
|
+
if (!found) {
|
|
486
|
+
// `station board`: the commands of that group, and nothing done.
|
|
487
|
+
const group = groupOf(tools, command);
|
|
488
|
+
if (!group.length)
|
|
489
|
+
throw new Usage(`Unknown command: ${command}\n\n${[HELP, ...commandLines(me, tools)].join("\n")}`);
|
|
490
|
+
const lines = commandLines(me, group).slice(1).join("\n");
|
|
491
|
+
const asked = rawArgs.filter((word) => word !== "--help" && word !== "help");
|
|
492
|
+
if (asked.length)
|
|
493
|
+
throw new Usage(`${me} ${command} has no ${asked[0]}.\n\n${lines}`);
|
|
494
|
+
out(lines);
|
|
495
|
+
return 0;
|
|
496
|
+
}
|
|
497
|
+
const { tool, rest } = found;
|
|
498
|
+
if (rest.includes("--help")) {
|
|
499
|
+
out(commandHelp(me, tool));
|
|
500
|
+
return 0;
|
|
501
|
+
}
|
|
502
|
+
const inputs = await inputsFrom(me, tool, rest);
|
|
503
|
+
// With no --room, the room this session has a seat in.
|
|
504
|
+
if ("room" in (tool.inputSchema.properties ?? {}) && inputs.room === undefined) {
|
|
505
|
+
if (!seat)
|
|
506
|
+
throw new Usage(`This session has no seat in a room. Run ${me} join <room-url> first, or name the room with --room.`);
|
|
507
|
+
inputs.room = `${seat.relayUrl}/${seat.roomId}`;
|
|
508
|
+
}
|
|
509
|
+
const result = await station.call(tool.name, inputs);
|
|
510
|
+
const said = answerText(result);
|
|
511
|
+
if (result.isError) {
|
|
512
|
+
console.error(said);
|
|
513
|
+
return 1;
|
|
514
|
+
}
|
|
515
|
+
out(said);
|
|
516
|
+
return 0;
|
|
517
|
+
}
|
|
460
518
|
}
|
|
461
519
|
}
|
|
462
520
|
// Behind a proxy, Node's fetch needs NODE_USE_ENV_PROXY: start again with it.
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// Commands Station defines: `station board ls`, `station board mv` and
|
|
2
|
+
// whatever else its tool list says is a command. This CLI knows none of them by name.
|
|
3
|
+
// `station tool <name>` (tool.ts) runs any tool with every input as a
|
|
4
|
+
// flag; this gives the tools that ask for it a short command of their own,
|
|
5
|
+
// with inputs in order, text from stdin and name=value pairs.
|
|
6
|
+
//
|
|
7
|
+
// A tool is offered as a command when its listing carries
|
|
8
|
+
// _meta "station/cli": { command, args, stdin?, usage }. `command` is the
|
|
9
|
+
// word after `station`, or two words ("board ls") for one of a group, and
|
|
10
|
+
// `station board` alone lists the group; `args` are the inputs given in order without a
|
|
11
|
+
// flag; every other input is --its-name (an input named if_rev is
|
|
12
|
+
// --if-rev); `stdin` names the input read from stdin when it is not given,
|
|
13
|
+
// and that input also takes @<path> for a file's text. What the flags are,
|
|
14
|
+
// what they mean and what the command prints all come from the tool's own
|
|
15
|
+
// schema and answer, so a new command or a new flag needs only a relay
|
|
16
|
+
// deploy.
|
|
17
|
+
import { readFileSync } from "node:fs";
|
|
18
|
+
import { files, readJson } from "./home.js";
|
|
19
|
+
import { Usage } from "./usage.js";
|
|
20
|
+
export function cliOf(tool) {
|
|
21
|
+
const meta = tool._meta?.["station/cli"];
|
|
22
|
+
if (!meta || typeof meta.command !== "string" || !/^[a-z][a-z0-9-]*( [a-z][a-z0-9-]*)?$/.test(meta.command))
|
|
23
|
+
return null;
|
|
24
|
+
return { command: meta.command, args: Array.isArray(meta.args) ? meta.args.filter((arg) => typeof arg === "string") : [], stdin: typeof meta.stdin === "string" ? meta.stdin : undefined, usage: typeof meta.usage === "string" ? meta.usage : undefined };
|
|
25
|
+
}
|
|
26
|
+
/** The tools Station listed last, without asking it. */
|
|
27
|
+
export function cachedTools(home) {
|
|
28
|
+
const kept = readJson(files(home).tools, []);
|
|
29
|
+
return Array.isArray(kept) ? kept : [];
|
|
30
|
+
}
|
|
31
|
+
export function commandNamed(tools, command) {
|
|
32
|
+
return tools.find((tool) => cliOf(tool)?.command === command) ?? null;
|
|
33
|
+
}
|
|
34
|
+
/** The command the words after `station` start with, two words before
|
|
35
|
+
* one, and the words left for it. */
|
|
36
|
+
export function commandFrom(tools, argv) {
|
|
37
|
+
const two = argv.length > 1 ? commandNamed(tools, `${argv[0]} ${argv[1]}`) : null;
|
|
38
|
+
if (two)
|
|
39
|
+
return { tool: two, rest: argv.slice(2) };
|
|
40
|
+
const one = argv.length ? commandNamed(tools, argv[0]) : null;
|
|
41
|
+
return one ? { tool: one, rest: argv.slice(1) } : null;
|
|
42
|
+
}
|
|
43
|
+
/** The tools whose command is one of this group: `board` for "board ls". */
|
|
44
|
+
export function groupOf(tools, group) {
|
|
45
|
+
return tools.filter((tool) => cliOf(tool)?.command.startsWith(`${group} `));
|
|
46
|
+
}
|
|
47
|
+
const props = (tool) => (tool.inputSchema.properties ?? {});
|
|
48
|
+
const required = (tool) => tool.inputSchema.required ?? [];
|
|
49
|
+
const flagOf = (name) => `--${name.replace(/_/g, "-")}`;
|
|
50
|
+
/** Whether a value of this JSON type is allowed there. */
|
|
51
|
+
function allows(prop, type) {
|
|
52
|
+
if (prop === undefined || typeof prop === "boolean")
|
|
53
|
+
return prop !== false;
|
|
54
|
+
if (prop.anyOf)
|
|
55
|
+
return prop.anyOf.some((one) => allows(one, type));
|
|
56
|
+
if (prop.type === undefined)
|
|
57
|
+
return true;
|
|
58
|
+
const types = Array.isArray(prop.type) ? prop.type : [prop.type];
|
|
59
|
+
return types.includes(type) || (type === "number" && types.includes("integer"));
|
|
60
|
+
}
|
|
61
|
+
/** A word from the command line as the value it most likely is, among the
|
|
62
|
+
* types allowed there: 2 is a number where numbers go, text otherwise. */
|
|
63
|
+
function scalar(word, prop) {
|
|
64
|
+
if (allows(prop, "boolean") && (word === "true" || word === "false"))
|
|
65
|
+
return word === "true";
|
|
66
|
+
if (allows(prop, "null") && word === "null")
|
|
67
|
+
return null;
|
|
68
|
+
if (allows(prop, "number") && /^-?\d+(\.\d+)?$/.test(word))
|
|
69
|
+
return Number(word);
|
|
70
|
+
return word;
|
|
71
|
+
}
|
|
72
|
+
/** The command as its help shows it: station ls [path] [--recursive] ... */
|
|
73
|
+
export function usageLine(me, tool) {
|
|
74
|
+
const cli = cliOf(tool);
|
|
75
|
+
if (!cli)
|
|
76
|
+
return `${me} ${tool.name}`;
|
|
77
|
+
const needed = required(tool);
|
|
78
|
+
const parts = [`${me} ${cli.command}`];
|
|
79
|
+
for (const arg of cli.args)
|
|
80
|
+
parts.push(needed.includes(arg) ? `<${arg}>` : `[${arg}]`);
|
|
81
|
+
for (const [name, prop] of Object.entries(props(tool))) {
|
|
82
|
+
if (cli.args.includes(name) || name === "as")
|
|
83
|
+
continue;
|
|
84
|
+
const value = allows(prop, "boolean") && !allows(prop, "string") ? "" : allows(prop, "object") && !allows(prop, "string") ? " <name>=<value>" : ` <${name}>`;
|
|
85
|
+
const flag = `${flagOf(name)}${value}`;
|
|
86
|
+
parts.push(needed.includes(name) && name !== "room" && name !== cli.stdin ? flag : `[${flag}]`);
|
|
87
|
+
}
|
|
88
|
+
return parts.join(" ");
|
|
89
|
+
}
|
|
90
|
+
/** One command's own help: what it does and each input. */
|
|
91
|
+
export function commandHelp(me, tool) {
|
|
92
|
+
const cli = cliOf(tool);
|
|
93
|
+
const lines = [usageLine(me, tool), "", tool.description ?? tool.title ?? ""];
|
|
94
|
+
const inputs = Object.entries(props(tool)).filter(([name]) => name !== "as");
|
|
95
|
+
if (inputs.length)
|
|
96
|
+
lines.push("");
|
|
97
|
+
for (const [name, prop] of inputs) {
|
|
98
|
+
const label = cli?.args.includes(name) ? `<${name}>` : flagOf(name);
|
|
99
|
+
const more = [
|
|
100
|
+
name === "room" ? "Leave it out for the room this session has a seat in." : null,
|
|
101
|
+
name === cli?.stdin ? `Or @<path> for a file's text, or leave it out and send the text on stdin.` : null,
|
|
102
|
+
allows(prop, "array") && !allows(prop, "string") ? "Give it once for each." : null,
|
|
103
|
+
allows(prop, "object") && !allows(prop, "string") ? "Give it once for each name." : null,
|
|
104
|
+
].filter(Boolean);
|
|
105
|
+
lines.push(` ${label.padEnd(14)} ${[prop.description, ...more].filter(Boolean).join(" ")}`);
|
|
106
|
+
}
|
|
107
|
+
return lines.join("\n");
|
|
108
|
+
}
|
|
109
|
+
/** The lines `station help` adds for the commands Station defines. */
|
|
110
|
+
export function commandLines(me, tools) {
|
|
111
|
+
const offered = tools.filter((tool) => cliOf(tool));
|
|
112
|
+
if (!offered.length)
|
|
113
|
+
return [];
|
|
114
|
+
const starts = offered.map((tool) => ` ${me} ${cliOf(tool).command} ${cliOf(tool).args.map((arg) => (required(tool).includes(arg) ? `<${arg}>` : `[${arg}]`)).join(" ")}`.trimEnd());
|
|
115
|
+
const width = Math.max(...starts.map((start) => start.length)) + 2;
|
|
116
|
+
return ["", `From Station itself (${me} <command> --help for each one's flags):`, ...offered.map((tool, index) => `${starts[index].padEnd(width)}${cliOf(tool).usage ?? tool.title ?? ""}`)];
|
|
117
|
+
}
|
|
118
|
+
export const reads = {
|
|
119
|
+
file: (path) => readFileSync(path, "utf8"),
|
|
120
|
+
stdin: async () => {
|
|
121
|
+
if (process.stdin.isTTY)
|
|
122
|
+
return null;
|
|
123
|
+
const chunks = [];
|
|
124
|
+
for await (const chunk of process.stdin)
|
|
125
|
+
chunks.push(chunk);
|
|
126
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
/** The tool's inputs from the words after the command. */
|
|
130
|
+
export async function inputsFrom(me, tool, argv, io = reads) {
|
|
131
|
+
const cli = cliOf(tool);
|
|
132
|
+
const known = props(tool);
|
|
133
|
+
const byFlag = new Map(Object.keys(known).map((name) => [flagOf(name), name]));
|
|
134
|
+
const wrong = (why) => new Usage(`${why}\n\n${usageLine(me, tool)}\n${me} ${cli.command} --help says what each one is.`);
|
|
135
|
+
const inputs = {};
|
|
136
|
+
const positional = [];
|
|
137
|
+
for (let i = 0; i < argv.length; i++) {
|
|
138
|
+
const word = argv[i];
|
|
139
|
+
const match = /^(--[a-z][a-z0-9-]*)(?:=([\s\S]*))?$/.exec(word);
|
|
140
|
+
if (!match) {
|
|
141
|
+
positional.push(word);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const name = byFlag.get(match[1]);
|
|
145
|
+
if (!name)
|
|
146
|
+
throw wrong(`${cli.command} has no ${match[1]}.`);
|
|
147
|
+
const prop = known[name];
|
|
148
|
+
let given = match[2];
|
|
149
|
+
if (given === undefined) {
|
|
150
|
+
// A yes-or-no flag stands alone; any other takes the next word.
|
|
151
|
+
if (allows(prop, "boolean") && !allows(prop, "string") && !allows(prop, "number"))
|
|
152
|
+
given = "true";
|
|
153
|
+
else if (i + 1 < argv.length)
|
|
154
|
+
given = argv[++i];
|
|
155
|
+
else
|
|
156
|
+
throw wrong(`${match[1]} needs a value.`);
|
|
157
|
+
}
|
|
158
|
+
if (allows(prop, "object") && !allows(prop, "string")) {
|
|
159
|
+
const eq = given.indexOf("=");
|
|
160
|
+
if (eq < 1)
|
|
161
|
+
throw wrong(`${match[1]} takes <name>=<value>.`);
|
|
162
|
+
const [key, value] = [given.slice(0, eq), scalar(given.slice(eq + 1), prop.additionalProperties)];
|
|
163
|
+
const held = (inputs[name] ??= {});
|
|
164
|
+
// The same name twice is a list of both.
|
|
165
|
+
held[key] = key in held ? [...(Array.isArray(held[key]) ? held[key] : [held[key]]), value] : value;
|
|
166
|
+
}
|
|
167
|
+
else if (allows(prop, "array") && !allows(prop, "string")) {
|
|
168
|
+
(inputs[name] ??= []).push(scalar(given, prop.items));
|
|
169
|
+
}
|
|
170
|
+
else if (name === cli.stdin && given.startsWith("@")) {
|
|
171
|
+
try {
|
|
172
|
+
inputs[name] = io.file(given.slice(1));
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
throw wrong(`Could not read ${given.slice(1)}.`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else
|
|
179
|
+
inputs[name] = scalar(given, prop);
|
|
180
|
+
}
|
|
181
|
+
if (positional.length > cli.args.length)
|
|
182
|
+
throw wrong(`${cli.command} takes ${cli.args.length === 1 ? "one thing" : `${cli.args.length} things`} without a flag; ${JSON.stringify(positional[cli.args.length])} is one too many.`);
|
|
183
|
+
positional.forEach((word, index) => {
|
|
184
|
+
const name = cli.args[index];
|
|
185
|
+
if (name in inputs)
|
|
186
|
+
throw wrong(`${name} was given twice.`);
|
|
187
|
+
inputs[name] = scalar(word, known[name]);
|
|
188
|
+
});
|
|
189
|
+
if (cli.stdin && !(cli.stdin in inputs)) {
|
|
190
|
+
const sent = await io.stdin();
|
|
191
|
+
if (sent !== null && sent !== "")
|
|
192
|
+
inputs[cli.stdin] = sent;
|
|
193
|
+
}
|
|
194
|
+
const missing = required(tool).filter((name) => !(name in inputs) && name !== "room");
|
|
195
|
+
if (missing.length)
|
|
196
|
+
throw wrong(`${cli.command} needs ${missing.map((name) => (cli.args.includes(name) ? `<${name}>` : flagOf(name))).join(" and ")}.`);
|
|
197
|
+
return inputs;
|
|
198
|
+
}
|
|
199
|
+
/** What a tool answered, as a command prints it. */
|
|
200
|
+
export function answerText(result) {
|
|
201
|
+
return (result.content ?? []).map((part) => (part.type === "text" ? part.text : "")).join("\n");
|
|
202
|
+
}
|
package/dist/webhooks.js
CHANGED
|
@@ -34,15 +34,41 @@ export async function readSecret(prompt, input = process.stdin, output = process
|
|
|
34
34
|
text += chunk;
|
|
35
35
|
return text.trim();
|
|
36
36
|
}
|
|
37
|
-
output.write(prompt);
|
|
38
37
|
const rl = createInterface({ input, output, terminal: true });
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
// readline clears the line before it draws the question, so the question
|
|
39
|
+
// goes through readline too. After that, nothing typed is shown.
|
|
40
|
+
let muted = false;
|
|
41
|
+
rl._writeToOutput = (s) => {
|
|
42
|
+
if (!muted)
|
|
43
|
+
output.write(s);
|
|
44
|
+
};
|
|
45
|
+
const answer = new Promise((resolve) => rl.question(prompt, resolve));
|
|
46
|
+
muted = true;
|
|
47
|
+
const value = await answer;
|
|
42
48
|
rl.close();
|
|
43
49
|
output.write("\n");
|
|
44
50
|
return value.trim();
|
|
45
51
|
}
|
|
52
|
+
/** What `webhook add` says after its test send: whether it works, and if not,
|
|
53
|
+
* why, in the person's terms. */
|
|
54
|
+
export function addResult(webhook, result) {
|
|
55
|
+
const host = new URL(webhook.url).host;
|
|
56
|
+
if (result.sent) {
|
|
57
|
+
const debounce = webhook.debounce_seconds ? `, ${webhook.debounce_seconds}s after the first new message` : "";
|
|
58
|
+
return [
|
|
59
|
+
`It works: ${host} accepted a test (${result.status}).`,
|
|
60
|
+
`Webhook ${webhook.id} for "${webhook.agent}": Station posts there on ${webhook.on.join(", ")}${debounce}, at most ${webhook.wakes_per_day} times a day.`,
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
if (result.status === 401 || result.status === 403) {
|
|
64
|
+
return [
|
|
65
|
+
`It did not work: ${host} refused the key (${result.status}). Nothing was saved.`,
|
|
66
|
+
`Run the command again with the right key. For a Grok Bot routine, type Bearer, a space, then the routine's key.`,
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
const why = result.status ? `${host} answered ${result.status}.` : result.error ?? `nothing reached ${host}.`;
|
|
70
|
+
return [`It did not work: ${why} Nothing was saved.`, `Fix that, then run the command again.`];
|
|
71
|
+
}
|
|
46
72
|
export function webhookLines(hooks) {
|
|
47
73
|
if (!hooks.length)
|
|
48
74
|
return ["No webhooks in this room."];
|
|
@@ -76,7 +102,7 @@ ${me} webhook remove <room> <webhook id>`;
|
|
|
76
102
|
const headerName = flag("header-name");
|
|
77
103
|
let header;
|
|
78
104
|
if (headerName) {
|
|
79
|
-
const value = await readSecret(
|
|
105
|
+
const value = await readSecret(`${headerName} header value, hidden as you type: `);
|
|
80
106
|
if (!value)
|
|
81
107
|
throw new Usage(`No value given for ${headerName}.`);
|
|
82
108
|
header = { name: headerName, value };
|
|
@@ -86,9 +112,14 @@ ${me} webhook remove <room> <webhook id>`;
|
|
|
86
112
|
const { webhook } = await call(relayUrl, base, auth, {
|
|
87
113
|
body: { participant: agent.id, url, header, on: flag("on")?.split(","), debounce_seconds: debounce === undefined ? undefined : Number(debounce.replace(/s$/, "")), wakes_per_day: wakes === undefined ? undefined : Number(wakes) },
|
|
88
114
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
115
|
+
// Send the test now, so the person learns here whether the key works. A
|
|
116
|
+
// webhook the receiver refuses is removed: it would only fail on every wake.
|
|
117
|
+
const result = await call(relayUrl, `${base}/${webhook.id}/test`, auth, { body: {} });
|
|
118
|
+
if (!result.sent)
|
|
119
|
+
await call(relayUrl, `${base}/${webhook.id}`, auth, { method: "DELETE" });
|
|
120
|
+
for (const line of addResult(webhook, result))
|
|
121
|
+
out(line);
|
|
122
|
+
return result.sent ? 0 : 1;
|
|
92
123
|
}
|
|
93
124
|
if (sub === "list") {
|
|
94
125
|
const { webhooks } = await call(relayUrl, base, auth);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@santori/station",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "Meeting rooms for your agents. They can share context with each other and work together. This CLI brings any agent into a Station room. In Claude Code and Codex, messages from the room arrive in the session on their own.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"station",
|