@santori/station 0.7.2 → 0.8.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 +32 -5
- package/dist/cli.js +53 -16
- package/dist/daemon.js +125 -81
- package/dist/frame.js +21 -36
- package/dist/guard.js +41 -13
- package/dist/handover.js +71 -0
- package/dist/join.js +58 -14
- package/dist/login.js +129 -31
- package/dist/mark.js +90 -0
- package/dist/mcp.js +15 -11
- package/dist/rooms.js +4 -2
- package/dist/seats.js +3 -3
- package/dist/tool.js +131 -0
- package/dist/webhooks.js +7 -5
- package/package.json +1 -1
package/dist/rooms.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// agent calls through `station mcp`, so `station rooms` and rooms_list
|
|
5
5
|
// never disagree.
|
|
6
6
|
import { DEFAULT_RELAY, DEFAULT_WEB, readCredentials } from "./home.js";
|
|
7
|
-
import { waitingAt } from "./login.js";
|
|
7
|
+
import { codeStep, waitingAt, waitingForCode } from "./login.js";
|
|
8
8
|
import { call, parseRoomUrl } from "./relay.js";
|
|
9
9
|
import { connectTo, useTool } from "./station.js";
|
|
10
10
|
import { NOT_SIGNED_IN, Usage } from "./usage.js";
|
|
@@ -13,8 +13,10 @@ export function signedIn(home) {
|
|
|
13
13
|
const credentials = readCredentials(home);
|
|
14
14
|
// A login under way may be switching accounts: no acting as the old one meanwhile.
|
|
15
15
|
const url = waitingAt(home);
|
|
16
|
+
if (url && waitingForCode(home))
|
|
17
|
+
throw new Usage(`Not signed in yet: the person has not finished at ${url}. ${codeStep("station", true)}`);
|
|
16
18
|
if (url)
|
|
17
|
-
throw new Usage(`Not signed in yet: the person has not finished at ${url}. Run this again once they have clicked Connect
|
|
19
|
+
throw new Usage(`Not signed in yet: the person has not finished at ${url}. Run this again once they have clicked Connect. ${codeStep("station", false)}`);
|
|
18
20
|
if (!credentials)
|
|
19
21
|
throw new Usage(NOT_SIGNED_IN);
|
|
20
22
|
return credentials;
|
package/dist/seats.js
CHANGED
|
@@ -20,10 +20,10 @@ export function seatFor(seats, sessionId, room) {
|
|
|
20
20
|
return mine.sort((a, b) => b.joinedAt.localeCompare(a.joinedAt))[0] ?? null;
|
|
21
21
|
}
|
|
22
22
|
/** The seat with its owner learned from the room, when it did not know
|
|
23
|
-
* them yet: the person entered the room after their agent
|
|
24
|
-
*
|
|
23
|
+
* them yet: the person entered the room after their agent, or claimed a
|
|
24
|
+
* seat that came in without a sign-in. */
|
|
25
25
|
export function withOwner(seat, owner) {
|
|
26
|
-
return
|
|
26
|
+
return !seat.ownerSeat && owner ? { ...seat, ownerSeat: owner } : seat;
|
|
27
27
|
}
|
|
28
28
|
export function roomLabel(seat) {
|
|
29
29
|
return seat.roomTitle?.trim() || `room ${seat.roomId.slice(0, 8)}`;
|
package/dist/tool.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { files } from "./home.js";
|
|
2
|
+
import { inSession } from "./join.js";
|
|
3
|
+
import { stationTools } from "./mcp.js";
|
|
4
|
+
import { loadSeats, seatFor } from "./seats.js";
|
|
5
|
+
import { Usage } from "./usage.js";
|
|
6
|
+
const inputsOf = (tool) => (tool.inputSchema.properties ?? {});
|
|
7
|
+
const requiredOf = (tool) => (tool.inputSchema.required ?? []);
|
|
8
|
+
/** An input as a flag: `is_public` is `--is-public`. */
|
|
9
|
+
const flagOf = (input) => `--${input.replace(/_/g, "-")}`;
|
|
10
|
+
const typeOf = (input) => (Array.isArray(input.type) ? (input.type.find((one) => one !== "null") ?? "string") : (input.type ?? "string"));
|
|
11
|
+
/** `--name value`, `--name=value`, or a bare `--name` (true). Unlike the
|
|
12
|
+
* commands' own flags, a name may hold digits and underscores, and a value
|
|
13
|
+
* may start with a dash when it is given with `=`. */
|
|
14
|
+
export function toolFlags(args) {
|
|
15
|
+
const given = new Map();
|
|
16
|
+
const rest = [];
|
|
17
|
+
for (let i = 0; i < args.length; i++) {
|
|
18
|
+
const match = /^--([A-Za-z0-9_-]+)(?:=([\s\S]*))?$/.exec(args[i]);
|
|
19
|
+
if (!match)
|
|
20
|
+
rest.push(args[i]);
|
|
21
|
+
else if (match[2] !== undefined)
|
|
22
|
+
given.set(match[1], match[2]);
|
|
23
|
+
else if (i + 1 < args.length && !args[i + 1].startsWith("--"))
|
|
24
|
+
given.set(match[1], args[++i]);
|
|
25
|
+
else
|
|
26
|
+
given.set(match[1], true);
|
|
27
|
+
}
|
|
28
|
+
return { given, rest };
|
|
29
|
+
}
|
|
30
|
+
/** A flag's text as the tool's input wants it. */
|
|
31
|
+
function valueFor(flag, input, raw) {
|
|
32
|
+
const type = typeOf(input);
|
|
33
|
+
if (type === "boolean") {
|
|
34
|
+
if (raw === true || raw === "true")
|
|
35
|
+
return true;
|
|
36
|
+
if (raw === "false")
|
|
37
|
+
return false;
|
|
38
|
+
throw new Usage(`${flag} is true or false.`);
|
|
39
|
+
}
|
|
40
|
+
if (raw === true)
|
|
41
|
+
throw new Usage(`${flag} needs a value.`);
|
|
42
|
+
if (type === "number" || type === "integer") {
|
|
43
|
+
const number = Number(raw);
|
|
44
|
+
if (raw.trim() === "" || Number.isNaN(number))
|
|
45
|
+
throw new Usage(`${flag} is a number.`);
|
|
46
|
+
return number;
|
|
47
|
+
}
|
|
48
|
+
if (type === "array" || type === "object") {
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(raw);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
throw new Usage(`${flag} is JSON, such as ${type === "array" ? '\'["a","b"]\'' : "'{\"key\":\"value\"}'"}.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return raw;
|
|
57
|
+
}
|
|
58
|
+
function oneLine(text, max = 200) {
|
|
59
|
+
const line = (text ?? "").replace(/\s+/g, " ").trim();
|
|
60
|
+
return line.length > max ? `${line.slice(0, max - 1)}…` : line;
|
|
61
|
+
}
|
|
62
|
+
/** One tool's flags, as its help. */
|
|
63
|
+
export function toolHelp(me, tool) {
|
|
64
|
+
const required = requiredOf(tool);
|
|
65
|
+
const lines = [`${me} tool ${tool.name}${Object.keys(inputsOf(tool)).length ? " [flags]" : ""}`, "", (tool.description ?? "").trim(), ""];
|
|
66
|
+
for (const [name, input] of Object.entries(inputsOf(tool))) {
|
|
67
|
+
const choices = input.enum?.length ? ` One of: ${input.enum.join(", ")}.` : "";
|
|
68
|
+
const need = name === "room" ? " (this session's room when left out)" : required.includes(name) ? " (required)" : "";
|
|
69
|
+
lines.push(` ${flagOf(name)} <${typeOf(input)}>${need}`, ` ${oneLine(input.description)}${choices}`);
|
|
70
|
+
}
|
|
71
|
+
return lines;
|
|
72
|
+
}
|
|
73
|
+
function sessionSeat(home) {
|
|
74
|
+
try {
|
|
75
|
+
return seatFor(loadSeats(files(home).seats), inSession().id) ?? null;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Not an agent's session: the call goes as the person.
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function textOf(result) {
|
|
83
|
+
return (result.content ?? []).map((part) => (part.type === "text" ? part.text : "")).join("\n");
|
|
84
|
+
}
|
|
85
|
+
/** Runs `station tool ...`: 0 when the tool answered, 1 when it refused. */
|
|
86
|
+
export async function toolCommand({ home, args, out, me, tools = stationTools(home), seat = () => sessionSeat(home) }) {
|
|
87
|
+
const { given, rest } = toolFlags(args);
|
|
88
|
+
const [name, ...extra] = rest;
|
|
89
|
+
const mine = seat();
|
|
90
|
+
const listed = await tools.list(mine?.relayUrl);
|
|
91
|
+
if (!listed.length)
|
|
92
|
+
throw new Error("Station did not answer, and this computer has no list of its tools yet. Try again in a moment.");
|
|
93
|
+
if (!name) {
|
|
94
|
+
out(`Station's tools. For one tool's flags: ${me} tool <name> --help`);
|
|
95
|
+
out("");
|
|
96
|
+
for (const tool of listed)
|
|
97
|
+
out(` ${tool.name.padEnd(18)} ${oneLine(tool.title ?? tool.description, 90)}`);
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
const tool = listed.find((one) => one.name === name);
|
|
101
|
+
if (!tool)
|
|
102
|
+
throw new Usage(`Station has no tool called ${name}. It has: ${listed.map((one) => one.name).join(", ")}.`);
|
|
103
|
+
if (given.has("help")) {
|
|
104
|
+
for (const line of toolHelp(me, tool))
|
|
105
|
+
out(line);
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
if (extra.length)
|
|
109
|
+
throw new Usage(`${me} tool takes each input as a flag, such as --text "hello". Not understood: ${extra.join(" ")}\n\n${toolHelp(me, tool).join("\n")}`);
|
|
110
|
+
const inputs = inputsOf(tool);
|
|
111
|
+
const byFlag = new Map(Object.keys(inputs).flatMap((input) => [[input, input], [input.replace(/_/g, "-"), input]]));
|
|
112
|
+
const call = {};
|
|
113
|
+
for (const [flag, raw] of given) {
|
|
114
|
+
const input = byFlag.get(flag);
|
|
115
|
+
if (!input)
|
|
116
|
+
throw new Usage(`${tool.name} has no --${flag}.\n\n${toolHelp(me, tool).join("\n")}`);
|
|
117
|
+
call[input] = valueFor(`--${flag}`, inputs[input], raw);
|
|
118
|
+
}
|
|
119
|
+
// The room this session sits in, when the tool takes one and none was given.
|
|
120
|
+
if ("room" in inputs && call.room === undefined && mine)
|
|
121
|
+
call.room = `${mine.relayUrl}/${mine.roomId}`;
|
|
122
|
+
const missing = requiredOf(tool).filter((input) => call[input] === undefined);
|
|
123
|
+
if (missing.length)
|
|
124
|
+
throw new Usage(`${tool.name} needs ${missing.map(flagOf).join(", ")}.\n\n${toolHelp(me, tool).join("\n")}`);
|
|
125
|
+
const result = await tools.call(tool.name, call);
|
|
126
|
+
const text = textOf(result);
|
|
127
|
+
if (result.isError)
|
|
128
|
+
throw new Error(text || `Station refused ${tool.name}.`);
|
|
129
|
+
out(text);
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
package/dist/webhooks.js
CHANGED
|
@@ -47,15 +47,16 @@ export function webhookLines(hooks) {
|
|
|
47
47
|
if (!hooks.length)
|
|
48
48
|
return ["No webhooks in this room."];
|
|
49
49
|
return hooks.map((h) => {
|
|
50
|
-
const last = h.last_error ? `last try failed: ${h.last_error}` : h.last_sent_at ? `last sent ${h.last_sent_at} (${h.last_status})` : "nothing sent yet";
|
|
50
|
+
const last = h.last_error ? (h.last_error.startsWith("Not woken") ? h.last_error : `last try failed: ${h.last_error}`) : h.last_sent_at ? `last sent ${h.last_sent_at} (${h.last_status})` : "nothing sent yet";
|
|
51
51
|
const header = h.header ? `, header ${h.header.name}: ${h.header.value}` : "";
|
|
52
52
|
const debounce = h.debounce_seconds ? `, debounce ${h.debounce_seconds}s` : "";
|
|
53
|
-
|
|
53
|
+
const wakes = h.wakes_per_day ? `, ${h.wakes_today ?? 0} of ${h.wakes_per_day} wakes today` : "";
|
|
54
|
+
return `${h.id} ${h.agent ?? h.participant_id} → ${h.url} on ${h.on.join(",")}${debounce}${wakes}${header}; ${last}`;
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
export async function webhookCommand(credentials, args, flag, out, me) {
|
|
57
58
|
const [sub, room, id] = args;
|
|
58
|
-
const usage = `${me} webhook add <room> --url <https url> [--agent "<name>"] [--header-name Authorization] [--on message,approval,asked] [--debounce 30]
|
|
59
|
+
const usage = `${me} webhook add <room> --url <https url> [--agent "<name>"] [--header-name Authorization] [--on message,approval,asked] [--debounce 30] [--wakes-per-day 60]
|
|
59
60
|
${me} webhook list <room>
|
|
60
61
|
${me} webhook test <room> <webhook id>
|
|
61
62
|
${me} webhook remove <room> <webhook id>`;
|
|
@@ -81,10 +82,11 @@ ${me} webhook remove <room> <webhook id>`;
|
|
|
81
82
|
header = { name: headerName, value };
|
|
82
83
|
}
|
|
83
84
|
const debounce = flag("debounce");
|
|
85
|
+
const wakes = flag("wakes-per-day");
|
|
84
86
|
const { webhook } = await call(relayUrl, base, auth, {
|
|
85
|
-
body: { participant: agent.id, url, header, on: flag("on")?.split(","), debounce_seconds: debounce === undefined ? undefined : Number(debounce.replace(/s$/, "")) },
|
|
87
|
+
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) },
|
|
86
88
|
});
|
|
87
|
-
out(`Webhook ${webhook.id} for "${webhook.agent}": Station posts to ${webhook.url} on ${webhook.on.join(", ")}${webhook.debounce_seconds ? `, ${webhook.debounce_seconds}s after the first new message` : ""}.`);
|
|
89
|
+
out(`Webhook ${webhook.id} for "${webhook.agent}": Station posts to ${webhook.url} on ${webhook.on.join(", ")}${webhook.debounce_seconds ? `, ${webhook.debounce_seconds}s after the first new message` : ""}, at most ${webhook.wakes_per_day} times a day.`);
|
|
88
90
|
out(`Try it: ${me} webhook test ${roomId} ${webhook.id}`);
|
|
89
91
|
return 0;
|
|
90
92
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@santori/station",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
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",
|