@santori/station 0.9.8 → 0.9.10

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/webhooks.js CHANGED
@@ -1,30 +1,11 @@
1
- // `station webhook`: the person points their agent's seat in a room at a
2
- // URL, and the relay posts there when something in the room is for that
3
- // agent: how a Grok Bot routine or another hosted agent is woken
4
- // (docs/webhooks.md). The person runs these in their own terminal, signed
5
- // in, so the receiver's key is typed there and never passes through the
1
+ // `station webhook`: the person points one of their agents at a URL, and
2
+ // the relay posts there when something in any of its rooms is for it: how
3
+ // a Grok Bot routine or another hosted agent is woken (docs/webhooks.md).
4
+ // The person runs these in their own terminal, signed in, so the receiver's key is typed there and never passes through the
6
5
  // agent: it is asked for, not taken as a flag.
7
6
  import { createInterface } from "node:readline";
8
7
  import { call } from "./relay.js";
9
- import { roomRef } from "./rooms.js";
10
8
  import { Usage } from "./usage.js";
11
- /** Which agent: the one named (its name or seat id), else the one agent in
12
- * the room that is the person's own. */
13
- export function pickAgent(seats, wanted) {
14
- const agents = seats.filter((seat) => seat.kind === "agent");
15
- if (wanted) {
16
- const found = agents.find((seat) => seat.id === wanted) ?? agents.filter((seat) => seat.name === wanted).at(-1);
17
- if (!found)
18
- throw new Usage(`No agent called "${wanted}" in this room. Agents here: ${agents.map((a) => `"${a.name}"`).join(", ") || "none"}.`);
19
- return found;
20
- }
21
- const mine = agents.filter((seat) => seat.for?.you && !seat.left_at);
22
- if (mine.length === 1)
23
- return mine[0];
24
- if (!mine.length)
25
- throw new Usage(`None of the agents in this room is yours yet. Name one with --agent "<name>"; it has to be yours (claim it first if it was let in).`);
26
- throw new Usage(`More than one of your agents is in this room: ${mine.map((a) => `"${a.name}"`).join(", ")}. Say which with --agent "<name>".`);
27
- }
28
9
  /** Reads the header's value: from a pipe as is, or asked for in a terminal
29
10
  * without showing what is typed. */
30
11
  export async function readSecret(prompt, input = process.stdin, output = process.stderr) {
@@ -69,36 +50,43 @@ export function addResult(webhook, result) {
69
50
  const why = result.status ? `${host} answered ${result.status}.` : result.error ?? `nothing reached ${host}.`;
70
51
  return [`It did not work: ${why} Nothing was saved.`, `Fix that, then run the command again.`];
71
52
  }
72
- export function webhookLines(hooks) {
53
+ export function webhookLines(hooks, agent) {
73
54
  if (!hooks.length)
74
- return ["No webhooks in this room."];
55
+ return [`No webhooks for ${agent}.`];
75
56
  return hooks.map((h) => {
76
57
  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";
77
58
  const header = h.header ? `, header ${h.header.name}: ${h.header.value}` : "";
78
59
  const debounce = h.debounce_seconds ? `, debounce ${h.debounce_seconds}s` : "";
79
60
  const wakes = h.wakes_per_day ? `, ${h.wakes_today ?? 0} of ${h.wakes_per_day} wakes today` : "";
80
- return `${h.id} ${h.agent ?? h.participant_id} → ${h.url} on ${h.on.join(",")}${debounce}${wakes}${header}; ${last}`;
61
+ return `${h.id} ${h.agent ?? h.agent_id} → ${h.url} on ${h.on.join(",")}${debounce}${wakes}${header}${h.signed ? ", signed" : ""}; ${last}`;
81
62
  });
82
63
  }
83
- export async function webhookCommand(credentials, args, flag, out, me) {
84
- const [sub, room, id] = args;
85
- const usage = `${me} webhook add <room> --url <https url> [--agent "<name>"] [--header-name Authorization] [--on message,approval,asked] [--debounce 30] [--wakes-per-day 60]
86
- ${me} webhook list <room>
87
- ${me} webhook test <room> <webhook id>
88
- ${me} webhook remove <room> <webhook id>`;
89
- if (!sub || !room)
64
+ /** `seatAgent`: the agent of this session's seat, when there is one, for a
65
+ * command run without --agent. */
66
+ export async function webhookCommand(credentials, args, flag, out, me, seatAgent = null) {
67
+ const [sub, id] = args;
68
+ const usage = `${me} webhook add [--agent <name, kind or id>] --url <https url> [--header-name Authorization] [--sign] [--on message,approval,asked] [--debounce 30] [--wakes-per-day 60]
69
+ ${me} webhook list [--agent <name>]
70
+ ${me} webhook test [--agent <name>] <webhook id>
71
+ ${me} webhook remove [--agent <name>] <webhook id>
72
+ Without --agent: the agent of this session's seat.`;
73
+ if (!sub)
90
74
  throw new Usage(usage);
91
- const { relayUrl, roomId } = roomRef(credentials, room);
92
- if (credentials.relayUrl !== relayUrl)
93
- throw new Usage(`This computer is signed in to ${credentials.relayUrl}, not ${relayUrl}.`);
75
+ // A webhook is the agent's, for all its rooms: a room is not part of it any more.
76
+ if ((sub === "add" || sub === "list") && id)
77
+ throw new Usage(`A webhook wakes the agent for every room it is in, so it takes no room. Name the agent with --agent instead.\n${usage}`);
78
+ const named = flag("agent");
79
+ const agent = named && named !== "true" ? named : seatAgent;
80
+ if (!agent)
81
+ throw new Usage(`Say which of your agents with --agent "<its name>", codex or claude, or run this from a session with a seat.\n${usage}`);
82
+ const { relayUrl } = credentials;
94
83
  const auth = { token: credentials.token };
95
- const base = `/${roomId}/webhooks`;
84
+ const base = `/me/agents/${encodeURIComponent(agent)}/webhooks`;
85
+ const testCommand = (hook) => `${me} webhook test${named ? ` --agent ${JSON.stringify(agent)}` : ""} ${hook}`;
96
86
  if (sub === "add") {
97
87
  const url = flag("url");
98
88
  if (!url)
99
89
  throw new Usage(usage);
100
- const { participants } = await call(relayUrl, `/${roomId}`, auth);
101
- const agent = pickAgent(participants, flag("agent"));
102
90
  const headerName = flag("header-name");
103
91
  let header;
104
92
  if (headerName) {
@@ -109,9 +97,21 @@ ${me} webhook remove <room> <webhook id>`;
109
97
  }
110
98
  const debounce = flag("debounce");
111
99
  const wakes = flag("wakes-per-day");
112
- const { webhook } = await call(relayUrl, base, auth, {
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) },
100
+ const sign = flag("sign");
101
+ if (sign !== undefined && sign !== "true" && sign !== "false")
102
+ throw new Usage("Use --sign to generate a signing secret.");
103
+ const { webhook, signing_secret } = await call(relayUrl, base, auth, {
104
+ body: { url, header, sign: sign === "true" ? true : undefined, on: flag("on")?.split(","), debounce_seconds: debounce === undefined ? undefined : Number(debounce.replace(/s$/, "")), wakes_per_day: wakes === undefined ? undefined : Number(wakes) },
114
105
  });
106
+ if (sign === "true") {
107
+ if (!signing_secret) {
108
+ await call(relayUrl, `${base}/${webhook.id}`, auth, { method: "DELETE" });
109
+ throw new Error("The relay did not return a signing secret. Try again on a relay that supports signing.");
110
+ }
111
+ out(`Signing secret (shown once): ${signing_secret}`);
112
+ out(`Set this secret on the receiver, then run: ${testCommand(webhook.id)}`);
113
+ return 0;
114
+ }
115
115
  // Send the test now, so the person learns here whether the key works. A
116
116
  // webhook the receiver refuses is removed: it would only fail on every wake.
117
117
  const result = await call(relayUrl, `${base}/${webhook.id}/test`, auth, { body: {} });
@@ -123,7 +123,7 @@ ${me} webhook remove <room> <webhook id>`;
123
123
  }
124
124
  if (sub === "list") {
125
125
  const { webhooks } = await call(relayUrl, base, auth);
126
- for (const line of webhookLines(webhooks))
126
+ for (const line of webhookLines(webhooks, agent))
127
127
  out(line);
128
128
  return 0;
129
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@santori/station",
3
- "version": "0.9.8",
3
+ "version": "0.9.10",
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",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/node": "^22.20.5",
47
- "typescript": "^5.6.3",
47
+ "typescript": "^7.0.2",
48
48
  "vitest": "^2.1.9"
49
49
  }
50
50
  }