@kybernesis/buzz 0.4.2 → 0.4.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.
Files changed (2) hide show
  1. package/dist/bridge.js +21 -4
  2. package/package.json +1 -1
package/dist/bridge.js CHANGED
@@ -24,7 +24,22 @@ export function buzzBridge(options) {
24
24
  const key = loadKey(options.keyFile);
25
25
  const identity = channelIdentity({ issuer: options.issuer, credential: options.credential });
26
26
  const log = options.onLog ?? ((message) => console.log(new Date().toISOString().slice(11, 19), message));
27
- /** One conversation per channel, which is how a channel already behaves. */
27
+ /**
28
+ * One conversation per channel — the SESSION ID, not a handle to it.
29
+ *
30
+ * @remarks
31
+ * This distinction is the difference between multiplayer working and quietly
32
+ * not. A session handle carries the client that made it, and that client
33
+ * carries one person's bearer token. Cache the handle and every later turn in
34
+ * the channel runs as whoever spoke first: a second person asks about their
35
+ * own mail and is shown the first person's, with nothing anywhere reporting
36
+ * an error.
37
+ *
38
+ * So the id is shared and the credentials are not. Each turn attaches to the
39
+ * same conversation through a client built for the person sending it, which
40
+ * is what the runtime reads to decide whose memory and whose connections the
41
+ * turn may touch.
42
+ */
28
43
  const sessions = new Map();
29
44
  /** Who has already been sent a link, so a room full of strangers is not a room full of spam. */
30
45
  const invited = new Map();
@@ -37,10 +52,13 @@ export function buzzBridge(options) {
37
52
  headers: bundle ? { "x-kybernesis-bundle": bundle } : {},
38
53
  });
39
54
  async function ask(channel, text, token, bundle) {
55
+ // Built per turn, for the person whose turn it is.
56
+ const client = clientFor(token, bundle);
40
57
  const existing = sessions.get(channel);
41
58
  if (existing) {
42
59
  try {
43
- const response = await existing.send(text);
60
+ const session = client.sessions.attach(existing);
61
+ const response = await session.send(text);
44
62
  return (await response.result()).message ?? "";
45
63
  }
46
64
  catch (error) {
@@ -50,9 +68,8 @@ export function buzzBridge(options) {
50
68
  sessions.delete(channel);
51
69
  }
52
70
  }
53
- const client = clientFor(token, bundle);
54
71
  const created = await client.sessions.create({ message: text });
55
- sessions.set(channel, created.session);
72
+ sessions.set(channel, created.session.state.sessionId);
56
73
  return (await created.response.result()).message ?? "";
57
74
  }
58
75
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kybernesis/buzz",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Put an eve agent in a Buzz workspace as a member: per-speaker verified identity resolved through the control plane, self-service identity linking, presence, typing and seen signals.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",