@volter/teams 0.1.74 → 0.1.76

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.
@@ -54,7 +54,8 @@ export declare class TurnDeliveryUnconfirmedError extends Error {
54
54
  /**
55
55
  * One line typed into the channel's session as its user's own turn; rejects when the machine refuses the stream.
56
56
  * `turnKey`: one per typed line, reused on retry, so the machine types the line once.
57
- * Receipt waits time out after thirty seconds. Cancellation stops waiting; it
57
+ * Receipt waits time out after thirty seconds and retain at most 256 KB of UTF-8 text.
58
+ * Cancellation stops waiting; it
58
59
  * does not undo delivery. After acceptance, a lost, invalid or cancelled receipt
59
60
  * rejects with TurnDeliveryUnconfirmedError. Reuse the same key when retrying it.
60
61
  */
@@ -185,7 +185,7 @@ export async function sendBrowserTurn(channel, text, { turnKey, signal } = {}) {
185
185
  signal?.throwIfAborted();
186
186
  const stream = await channel.open('mail', { request: { op: 'turn', text, ...(turnKey ? { turn_key: String(turnKey) } : {}) } });
187
187
  return new Promise((resolve, reject) => {
188
- let answer = '', settled = false;
188
+ let answer = '', bytes = 0, settled = false;
189
189
  const cleanup = () => { clearTimeout(timer); stream.off('data', data); stream.off('close', closed); signal?.removeEventListener('abort', cancelled); };
190
190
  const fail = error => {
191
191
  if (settled) return;
@@ -196,7 +196,13 @@ export async function sendBrowserTurn(channel, text, { turnKey, signal } = {}) {
196
196
  };
197
197
  const cancelled = () => fail(new TurnDeliveryUnconfirmedError('Turn delivery wait cancelled'));
198
198
  const timer = setTimeout(() => fail(new TurnDeliveryUnconfirmedError('Turn delivery acknowledgement timed out')), 30_000);
199
- const data = chunk => { answer += chunk; if (answer.length > 256_000) fail(new TurnDeliveryUnconfirmedError('Turn delivery receipt too large')); };
199
+ const data = chunk => {
200
+ if (typeof chunk !== 'string') { fail(new TurnDeliveryUnconfirmedError('Invalid turn delivery receipt frame')); return; }
201
+ if (chunk.length > 256_000 - bytes) { fail(new TurnDeliveryUnconfirmedError('Turn delivery receipt too large')); return; }
202
+ bytes += encoder.encode(chunk).byteLength;
203
+ if (bytes > 256_000) { fail(new TurnDeliveryUnconfirmedError('Turn delivery receipt too large')); return; }
204
+ answer += chunk;
205
+ };
200
206
  const closed = reason => {
201
207
  if (settled) return;
202
208
  settled = true; cleanup();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/teams",
3
- "version": "0.1.74",
3
+ "version": "0.1.76",
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",
@@ -142,6 +142,19 @@ export const personImage = (seed = '') => seed ? `https://brand.volter.ai/runner
142
142
  /** An agent's picture (this session's own, a peer session's): the brand's agent mark, a rounded square, never a face. */
143
143
  export const agentImage = (seed) => `https://brand.volter.ai/agent/svg?seed=${encodeURIComponent(seed)}&size=36&radius=7`;
144
144
 
145
+ // Older history lacks actor metadata but still carries its envelope name.
146
+ // Use native addressing only for a harness label, never as display text or as
147
+ // evidence that a generated operator mailbox is the voice of this session.
148
+ function mailIdentity(address, suppliedName) {
149
+ const native = /^sc:([^:]+):([^:]+):(.+)$/.exec(address || '');
150
+ const label = ({ 'claude-code': 'Claude Code', codex: 'Codex', gemini: 'Gemini', goose: 'Goose', grok: 'Grok', opencode: 'OpenCode', pi: 'Pi', operator: 'Automation', board: 'Board', pane: 'Terminal' })[native?.[2]] || 'Another session';
151
+ let name = typeof suppliedName === 'string' ? suppliedName.trim() : '';
152
+ if (native && name.endsWith(`@${native[1]}`)) name = name.slice(0, -native[1].length - 1);
153
+ if (!name || name === address || name.startsWith('sc:') || /^(?:(?:codex|claude-code|claude|gemini|pi|goose|grok|opencode|supercode-voice)-)?[0-9a-f]{8,}(?:-[0-9a-f]+)*$/i.test(name)) name = label;
154
+ return { name, kind: native && !['operator', 'board', 'pane'].includes(native[2]) ? 'agent' : 'automation' };
155
+ }
156
+ const automationImage = seed => `https://brand.volter.ai/bot/svg?seed=${encodeURIComponent(seed || 'mail')}&size=24&radius=4`;
157
+
145
158
  /**
146
159
  * Who wrote each entry of a projected transcript (supercode-ui's entries), from the messages' own annotations:
147
160
  * this session's turns are its agent's (`agentName`); a peer session's message is that session's, its envelope kept
@@ -182,10 +195,10 @@ export function withPeople(transcript, messages, { agentName = null, sessionId =
182
195
  // is this session's own front, not another agent with a generated id.
183
196
  const ownVoice = peer.via === 'voice';
184
197
  const seed = ownVoice ? sessionId : peer.address.startsWith('sc:') ? peer.address : peer.name;
185
- const native = /^sc:[^:]+:([^:]+):.+$/.exec(peer.address);
186
- const harnessName = ({ 'claude-code': 'Claude Code', codex: 'Codex', gemini: 'Gemini', goose: 'Goose', grok: 'Grok', opencode: 'OpenCode', pi: 'Pi', operator: 'Automation', board: 'Board', pane: 'Terminal' })[native?.[1]] || 'Another session';
187
- const name = ownVoice && agentName ? agentName : peer.name === peer.address ? harnessName : peer.name, picture = agent(seed);
188
- 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 }] };
198
+ const identity = mailIdentity(peer.address, peer.name);
199
+ const name = ownVoice && agentName ? agentName : identity.name;
200
+ const picture = ownVoice || identity.kind === 'agent' ? agent(seed) : automationImage(seed);
201
+ 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, ...(ownVoice || identity.kind === 'agent' ? { kind: 'agent' } : {}) }, context: [{ id: `${entry.id}:envelope`, kind: 'envelope', label: 'Delivered by supercode', detail: entry.text }] };
189
202
  }
190
203
  const name = metadata.source_name || null;
191
204
  const seed = name ? (metadata.source_principal_id || name) : '';
@@ -213,11 +226,16 @@ export function withMail(transcript, rows, { agentName = 'This session', agentId
213
226
  let earliest = Infinity;
214
227
  for (const entry of transcript) if (Number.isFinite(entry.ts)) earliest = Math.min(earliest, entry.ts);
215
228
  if (earliest !== Infinity) rows = rows.filter(row => row.at >= earliest);
216
- const nameOf = actor => actor?.self ? agentName : actor?.name || 'Unknown sender';
217
- const mail = rows.map(row => ({ id: `mail:${row.id}`, role: 'notice', text: row.text, ts: row.at, truncated: false,
218
- mail: { id: row.id, from: nameOf(row.fromActor), to: row.toActor ? nameOf(row.toActor) : row.direction === 'in' ? agentName : 'Another session',
219
- image: row.fromActor?.kind === 'agent' ? picture(row.fromActor.self ? agentId : row.fromActor.id) : `https://brand.volter.ai/bot/svg?seed=${encodeURIComponent(row.fromActor?.id || row.from)}&size=24&radius=4`,
220
- subject: row.subject || undefined, via: row.fromActor?.via, direction: row.direction, inReplyTo: row.inReplyTo } }));
229
+ const nameOf = (actor, address, suppliedName, self = false) => actor?.self || self ? agentName : mailIdentity(actor?.id || address, actor?.name || suppliedName).name;
230
+ const mail = rows.map(row => {
231
+ const own = row.fromActor ? row.fromActor.self : row.direction === 'out';
232
+ const kind = row.fromActor?.kind || (own ? 'agent' : mailIdentity(row.from, row.fromName).kind);
233
+ const seed = own ? agentId : row.fromActor?.id || row.from;
234
+ return { id: `mail:${row.id}`, role: 'notice', text: row.text, ts: row.at, truncated: false,
235
+ mail: { id: row.id, from: nameOf(row.fromActor, row.from, row.fromName, own), to: nameOf(row.toActor, row.to, '', !row.toActor && row.direction === 'in'),
236
+ image: kind === 'agent' ? picture(seed) : kind === 'person' ? personImage(seed) : automationImage(seed),
237
+ subject: row.subject || undefined, via: row.fromActor?.via, direction: row.direction, inReplyTo: row.inReplyTo } };
238
+ });
221
239
  // Some native envelopes use a shortened ID. It identifies a copy only if
222
240
  // there is exactly one matching full ID; ambiguity must not erase native mail.
223
241
  const fullIds = new Set(rows.map(row => row.id));