@santori/station 0.9.0 → 0.9.3

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 CHANGED
@@ -113,9 +113,12 @@ passes each call on with what only this computer has:
113
113
  with the person's role, as on the website.
114
114
  - **A seat, for the one tool that takes one.** `wait` joins the room
115
115
  first when the session has no seat there, the way `station join` does, and
116
- hands the seat to the daemon. In Claude Code and Codex the room's messages
117
- then arrive in the session on their own; in any other agent, `wait`
118
- waits for them. `send` needs that seat and says so without it.
116
+ hands the seat to the daemon. Its answer says how the room's messages
117
+ reach the session: on their own where Station can put them in, else
118
+ by calling `wait` again after each reply. `send` needs that seat and says so without it.
119
+ - **Letting a seat go.** `mutate` with the action `room.leave` leaves the
120
+ room as the session's seat, and the CLI stops holding it, as
121
+ `station leave` does. From Station CLI 0.9.1.
119
122
 
120
123
  `station tool` and `station board` in a shell run the same things one tool
121
124
  at a time, each with its own flags (`station tool room_status --help`).
package/dist/cli.js CHANGED
@@ -241,7 +241,7 @@ async function main(argv) {
241
241
  if (extra !== undefined && /^stn_/.test(extra))
242
242
  out("Room tokens are gone; joining with the room's address.");
243
243
  const session = inSession();
244
- const held = seatFor(loadSeats(files(home).seats), session.id, parseRoomUrl(url).roomId);
244
+ const held = seatFor(loadSeats(files(home).seats), session.id, parseRoomUrl(url, readCredentials(home)).roomId);
245
245
  if (held && session.harness !== "shell")
246
246
  out(`This session already has a seat in ${roomLabel(held)}, as ${held.name}; this join is the same seat. ${ANOTHER_AGENT}`);
247
247
  const joined = await takeSeat(home, session, url, { name: flag("name"), invite: flag("invite"), onAsked: (line) => out(line) });
@@ -336,8 +336,10 @@ async function main(argv) {
336
336
  }
337
337
  case "file": {
338
338
  const [path] = args;
339
- if (!path || !existsSync(path))
339
+ if (!path)
340
340
  throw new Usage("station file <path>");
341
+ if (!existsSync(path))
342
+ throw new Usage(`The file does not exist: ${path}`);
341
343
  const seat = mySeat(home, inSession(), flag("room"));
342
344
  const name = flag("name") ?? basename(path);
343
345
  await call(seat.relayUrl, `/${seat.roomId}/files`, authFor(seat, readCredentials(home)), {
package/dist/join.js CHANGED
@@ -122,9 +122,9 @@ export async function takeSeat(home, session, url, options = {}) {
122
122
  // This computer's sign-in; else nothing. A public room takes nothing; a
123
123
  // private one then has the agent ask to join, and it waits here until
124
124
  // someone in the room lets it in.
125
- const { relayUrl, roomId, inviteToken } = parseRoomUrl(url);
126
- const invite = options.invite || inviteToken;
127
125
  const credentials = readCredentials(home);
126
+ const { relayUrl, roomId, inviteToken } = parseRoomUrl(url, credentials);
127
+ const invite = options.invite || inviteToken;
128
128
  let via;
129
129
  let token;
130
130
  if (credentials && credentials.relayUrl === relayUrl) {
@@ -186,7 +186,7 @@ export function chatLines(seat, room, last, me) {
186
186
  }
187
187
  /** What `station join` says once seated. `me` is the command to type again. */
188
188
  export function joinedLines(me, { seat, room }, why = null) {
189
- const lines = [`Joined ${roomLabel(seat)} as "${seat.name}".`, `People here: ${room.participants.map((p) => p.name).join(", ")}`];
189
+ const lines = [`Joined ${roomLabel(seat)} as "${seat.name}".`, `People here: ${room.participants.filter((p) => !p.left_at).map((p) => p.name).join(", ")}`];
190
190
  const recent = chatLines(seat, room, 8, me);
191
191
  if (recent.length)
192
192
  lines.push(["Recent messages:", ...recent].join("\n"));
package/dist/login.js CHANGED
@@ -171,9 +171,17 @@ export async function runHelper(home, waitMs = LISTEN_MS) {
171
171
  // Logged out, or a newer login, since this one started: save nothing.
172
172
  if (!mine())
173
173
  return;
174
- const answer = await call(pending.relayUrl, "/cli/token", null, {
175
- body: { code, verifier: pending.verifier },
176
- });
174
+ report({ trading: true });
175
+ let answer;
176
+ try {
177
+ answer = await call(pending.relayUrl, "/cli/token", null, {
178
+ body: { code, verifier: pending.verifier },
179
+ });
180
+ }
181
+ catch (error) {
182
+ report({ trading: false });
183
+ throw error;
184
+ }
177
185
  // Station's own site is not saved, so a sign-in follows DEFAULT_WEB when the domain moves.
178
186
  const site = pending.webUrl === DEFAULT_WEB ? {} : { webUrl: pending.webUrl };
179
187
  const credentials = { relayUrl: pending.relayUrl, ...site, token: answer.token, userId: answer.user_id, name: answer.name };
@@ -261,8 +269,9 @@ function spawnHelper(home) {
261
269
  * up to `waitMs` for it to end, even when an older sign-in is saved (the
262
270
  * login may be switching accounts). The sign-in on disk once no login is
263
271
  * under way, or null while one still is. A failed login is cleared and
264
- * says why. */
265
- export async function finishLogin(home, waitMs) {
272
+ * says why. With `waitForCode` false, only an exchange already under way
273
+ * gets time to finish, not a link still waiting for the person. */
274
+ export async function finishLogin(home, waitMs, waitForCode = true) {
266
275
  const deadline = Date.now() + waitMs;
267
276
  for (;;) {
268
277
  const pending = readPending(home);
@@ -279,7 +288,7 @@ export async function finishLogin(home, waitMs) {
279
288
  remove(files(home).login);
280
289
  continue;
281
290
  }
282
- if (Date.now() >= deadline)
291
+ if ((!waitForCode && !pending.trading) || Date.now() >= deadline)
283
292
  return null;
284
293
  await new Promise((resolve) => setTimeout(resolve, 250));
285
294
  }
package/dist/mcp.js CHANGED
@@ -19,6 +19,8 @@
19
19
  // Codex puts the room's messages into the session.
20
20
  // - An answer that says how far the session has read (_meta
21
21
  // "station/after") moves the seat's place, so each message reaches it once.
22
+ // - An answer that says the seat left its room (_meta "station/seat":
23
+ // "drop") lets go of the seat here too, as `station leave` does.
22
24
  //
23
25
  // The last list Station gave is kept, so a session that starts while
24
26
  // Station cannot be reached still has its tools.
@@ -72,11 +74,11 @@ function relayOf(credentials) {
72
74
  function asPerson(credentials, relayUrl) {
73
75
  return credentials && credentials.relayUrl === relayUrl ? { Authorization: `Bearer ${credentials.token}` } : {};
74
76
  }
75
- /** A login still waiting for the browser gets a moment to finish
77
+ /** A login exchanging a code gets a moment to finish
76
78
  * (login.ts), so no call goes out as nobody, or as the account it replaces. */
77
79
  async function settled(home) {
78
80
  if (readPending(home))
79
- await finishLogin(home, 15_000).catch(() => null);
81
+ await finishLogin(home, 15_000, false).catch(() => null);
80
82
  return readPending(home) ? null : readCredentials(home);
81
83
  }
82
84
  export const thisComputer = {
@@ -86,6 +88,10 @@ export const thisComputer = {
86
88
  await ensureDaemon(home);
87
89
  await ask(files(home).socket, { op: "read", sessionId: seat.sessionId, roomId: seat.roomId, after });
88
90
  },
91
+ drop: async (home, seat) => {
92
+ if (existsSync(files(home).socket))
93
+ await ask(files(home).socket, { op: "drop", sessionId: seat.sessionId, roomId: seat.roomId });
94
+ },
89
95
  };
90
96
  function cached(path) {
91
97
  if (!existsSync(path))
@@ -139,9 +145,10 @@ export function stationTools(home, post = postToAgent, computer = thisComputer,
139
145
  const credentials = await settled(home);
140
146
  let relayUrl = relayOf(credentials);
141
147
  let roomId = null;
148
+ let inviteToken;
142
149
  if (typeof args.room === "string") {
143
150
  try {
144
- ({ relayUrl, roomId } = roomRef(credentials, args.room));
151
+ ({ relayUrl, roomId, inviteToken } = roomRef(credentials, args.room));
145
152
  }
146
153
  catch {
147
154
  // Not a room this computer can read; the tool says what is wrong with it.
@@ -162,7 +169,8 @@ export function stationTools(home, post = postToAgent, computer = thisComputer,
162
169
  // Says why when this is not an agent's session that can hold a seat.
163
170
  // The seat's name, when the call gives one (room_wait's `name`), as station join --name.
164
171
  const name = typeof args.name === "string" && args.name.trim() ? args.name.trim() : null;
165
- seat = await computer.takeSeat(home, caller ?? computer.session(worker), `${relayUrl}/${roomId}`, name);
172
+ const invite = inviteToken ? `?${new URLSearchParams({ invite_token: inviteToken })}` : "";
173
+ seat = await computer.takeSeat(home, caller ?? computer.session(worker), `${relayUrl}/${roomId}${invite}`, name);
166
174
  joined = true;
167
175
  }
168
176
  const headers = ours(folded);
@@ -186,6 +194,9 @@ export function stationTools(home, post = postToAgent, computer = thisComputer,
186
194
  // The seat's place moves, so the next read starts after these.
187
195
  await computer.read(home, seat, after).catch(() => undefined);
188
196
  }
197
+ // The seat left the room: nothing here holds it any longer.
198
+ if (seat && result._meta?.["station/seat"] === "drop")
199
+ await computer.drop(home, seat).catch(() => undefined);
189
200
  return result;
190
201
  }
191
202
  catch (error) {
package/dist/relay.js CHANGED
@@ -2,6 +2,7 @@
2
2
  // describes for curl, with the seat's credential: the room's token for a
3
3
  // pasted room, or this computer's sign-in.
4
4
  import { fetchAsCaller } from "./caller.js";
5
+ import { DEFAULT_RELAY, DEFAULT_WEB } from "./home.js";
5
6
  export class RelayError extends Error {
6
7
  status;
7
8
  constructor(status, message) {
@@ -43,8 +44,8 @@ export async function call(base, path, auth, init = {}) {
43
44
  }
44
45
  return (response.status === 204 ? undefined : await response.json());
45
46
  }
46
- /** A room URL is the relay's origin and the room id. */
47
- export function parseRoomUrl(url) {
47
+ /** A relay room URL, or a room page on Station's website. */
48
+ export function parseRoomUrl(url, credentials = null) {
48
49
  // The paste is a sentence ("Come join my Station room. To get started, run
49
50
  // curl -s <url> and follow the steps there."), so an agent may copy a
50
51
  // period, or the link inside quotes or angle brackets.
@@ -56,9 +57,13 @@ export function parseRoomUrl(url) {
56
57
  catch {
57
58
  throw new Error(`Not a room URL: ${url}`);
58
59
  }
59
- const roomId = parsed.pathname.replace(/^\/+|\/+$/g, "");
60
+ const webRelay = parsed.origin === new URL(credentials?.webUrl ?? DEFAULT_WEB).origin
61
+ ? credentials?.relayUrl ?? DEFAULT_RELAY
62
+ : parsed.origin === DEFAULT_WEB ? DEFAULT_RELAY : null;
63
+ const page = webRelay ? parsed.pathname.match(/^\/b\/([0-9a-f-]{36})(?:\/.*)?$/i) : null;
64
+ const roomId = page?.[1] ?? parsed.pathname.replace(/^\/+|\/+$/g, "");
60
65
  if (!/^[0-9a-f-]{36}$/i.test(roomId))
61
66
  throw new Error(`Not a room URL: ${url}`);
62
67
  // The room's invite token, when the link carries it (?invite_token=).
63
- return { relayUrl: parsed.origin, roomId, inviteToken: parsed.searchParams.get("invite_token") || null };
68
+ return { relayUrl: page && webRelay ? webRelay : parsed.origin, roomId, inviteToken: parsed.searchParams.get("invite_token") || null };
64
69
  }
package/dist/rooms.js CHANGED
@@ -75,8 +75,8 @@ export function openedLines(opened) {
75
75
  export function roomRef(credentials, room) {
76
76
  const trimmed = room.trim();
77
77
  if (/^https?:\/\//i.test(trimmed)) {
78
- const { relayUrl, roomId } = parseRoomUrl(trimmed);
79
- return { relayUrl, roomId };
78
+ const { relayUrl, roomId, inviteToken } = parseRoomUrl(trimmed, credentials);
79
+ return { relayUrl, roomId, ...(inviteToken ? { inviteToken } : {}) };
80
80
  }
81
81
  const id = trimmed.replace(/^[<("'`]+|[>)"'`.,;:!?]+$/g, "");
82
82
  if (!/^[0-9a-f-]{36}$/i.test(id))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@santori/station",
3
- "version": "0.9.0",
3
+ "version": "0.9.3",
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",