@volter/teams 0.1.65 → 0.1.66

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/teams",
3
- "version": "0.1.65",
3
+ "version": "0.1.66",
4
4
  "type": "module",
5
5
  "description": "Volter Teams, the neutral team plane: machine identity and daemon core, the local door and server link, admission from machine grants, product doors, and the Teams server's neutral routes (company RFC 0008).",
6
6
  "license": "MIT",
@@ -18,7 +18,7 @@ export function followTeamSession({ origin, teamId, sessionId, token, tail = 300
18
18
  const controller = new AbortController();
19
19
  const headers = async () => ({ Authorization: `Bearer ${await token()}` });
20
20
  const failure = (stage, status, message) => Object.assign(new Error(message), { stage, status });
21
- let reading = null, requested = false;
21
+ let reading = null, requested = false, observed = false;
22
22
  const read = () => {
23
23
  requested = true;
24
24
  return reading ??= (async () => {
@@ -30,6 +30,7 @@ export function followTeamSession({ origin, teamId, sessionId, token, tail = 300
30
30
  const body = await response.json();
31
31
  if (controller.signal.aborted) throw new DOMException('Session follow stopped', 'AbortError');
32
32
  snapshot = body.data ?? body;
33
+ observed = true;
33
34
  onSnapshot(snapshot);
34
35
  // A change during the HTTP read may be newer than the capture it
35
36
  // returned. Coalesce the callers, but do not drop that invalidation.
@@ -46,7 +47,12 @@ export function followTeamSession({ origin, teamId, sessionId, token, tail = 300
46
47
  try {
47
48
  if (!cursor) cursor = String((await read()).event_cursor ?? '') || null;
48
49
  const response = await fetchImpl(`${base}/events?${cursor ? `after=${encodeURIComponent(cursor)}` : 'tail=1'}`, { headers: await headers(), signal: AbortSignal.any([controller.signal, connection.signal]) });
49
- if (!response.ok) throw failure('follow', response.status, `following the session failed (${response.status})`);
50
+ if (!response.ok) {
51
+ // The event door uses 409 when this cursor is outside its retained
52
+ // journal (including after a server restart). Retrying it cannot help.
53
+ if (response.status === 409) cursor = null;
54
+ throw failure('follow', response.status, `following the session failed (${response.status})`);
55
+ }
50
56
  onLive(true);
51
57
  reader = response.body.getReader();
52
58
  const decoder = new TextDecoder();
@@ -65,7 +71,7 @@ export function followTeamSession({ origin, teamId, sessionId, token, tail = 300
65
71
  if (event.cursor) cursor = event.cursor;
66
72
  // The server ends a stream it can no longer resume (a slow reader, a retired cursor): start from a snapshot.
67
73
  if (event.terminal && event.type === 'resync_required') cursor = null;
68
- if (event.type === 'snapshot') onSnapshot(event.data);
74
+ if (event.type === 'snapshot') { observed = true; onSnapshot(event.data); }
69
75
  else if (event.type === 'session_changed') {
70
76
  const refresh = read();
71
77
  // One recovery handler per coalesced read, including when a
@@ -79,7 +85,7 @@ export function followTeamSession({ origin, teamId, sessionId, token, tail = 300
79
85
  // Recover even if no further message arrives.
80
86
  cursor = null;
81
87
  following?.abort();
82
- onError({ stage: error.stage ?? 'read', status: error.status ?? null, message: error.message, snapshot: true });
88
+ onError({ stage: error.stage ?? 'read', status: error.status ?? null, message: error.message, snapshot: observed });
83
89
  });
84
90
  }
85
91
  }
@@ -88,7 +94,7 @@ export function followTeamSession({ origin, teamId, sessionId, token, tail = 300
88
94
  }
89
95
  } catch (error) {
90
96
  if (controller.signal.aborted) return;
91
- if (!connection.signal.aborted) onError({ stage: error.stage ?? 'follow', status: error.status ?? null, message: error.message, snapshot: Boolean(cursor) });
97
+ if (!connection.signal.aborted) onError({ stage: error.stage ?? 'follow', status: error.status ?? null, message: error.message, snapshot: observed });
92
98
  } finally {
93
99
  if (following === connection) following = null;
94
100
  connection.abort();
@@ -164,8 +170,12 @@ export function withPeople(transcript, messages, { agentName = null, sessionId =
164
170
  if (!attributed && /^\s*\[Cross-session [a-z ]*notice\]/i.test(entry.text)) return { ...entry, role: 'notice', text: entry.text.trim().split('\n')[0] };
165
171
  const peer = attributed ? null : peerMessage(entry.text);
166
172
  if (peer) {
167
- const seed = peer.address.startsWith('sc:') ? peer.address : peer.name;
168
- return { ...entry, text: peer.body, mail: { id: peer.id || entry.id, from: peer.name, to: agentName || 'This session', direction: 'in', ...(peer.subject ? { subject: peer.subject } : {}), ...(peer.via === 'voice' ? { via: 'voice' } : {}), ...(peer.inReplyTo ? { inReplyTo: peer.inReplyTo } : {}) }, actor: { id: seed, name: peer.name, image: agent(seed), kind: 'agent' }, context: [{ id: `${entry.id}:envelope`, kind: 'envelope', label: 'Delivered by supercode', detail: entry.text }] };
173
+ // The native voice envelope deliberately omits its return address: it
174
+ // is this session's own front, not another agent with a generated id.
175
+ const ownVoice = peer.via === 'voice';
176
+ const seed = ownVoice ? sessionId : peer.address.startsWith('sc:') ? peer.address : peer.name;
177
+ const name = ownVoice && agentName ? agentName : peer.name, picture = agent(seed);
178
+ return { ...entry, text: peer.body, mail: { id: peer.id || entry.id, from: name, to: agentName || 'This session', direction: 'in', image: picture, ...(peer.subject ? { subject: peer.subject } : {}), ...(ownVoice ? { via: 'voice' } : {}), ...(peer.inReplyTo ? { inReplyTo: peer.inReplyTo } : {}) }, actor: { id: seed, name, image: picture, kind: 'agent' }, context: [{ id: `${entry.id}:envelope`, kind: 'envelope', label: 'Delivered by supercode', detail: entry.text }] };
169
179
  }
170
180
  const name = metadata.source_name || null;
171
181
  const seed = name ? (metadata.source_principal_id || name) : '';