@volter/teams 0.1.62 → 0.1.63

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.62",
3
+ "version": "0.1.63",
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",
@@ -33,7 +33,7 @@ export interface FollowTeamSessionOptions {
33
33
  export function followTeamSession(options: FollowTeamSessionOptions): { stop(): void; read(): Promise<TeamSessionSnapshot> };
34
34
 
35
35
  /** A message another session sent this one, from its envelope: its sender and body, or null for an ordinary turn. */
36
- export function peerMessage(text: string): { name: string; address: string; body: string } | null;
36
+ export function peerMessage(text: string): { id: string | null; name: string; address: string; body: string; subject: string | null; via: string | null; inReplyTo: string | null } | null;
37
37
 
38
38
  /** Overlay actual envelopes, deduplicating copies already delivered into the native transcript. */
39
39
  export function withMail<Entry extends { id: string; ts: number | null; mail?: { id: string } }>(transcript: Entry[], rows: import('./browser-channel.js').MailHistoryEntry[], options?: { agentName?: string; agentId?: string; agentImage?(seed: string): string }): Array<Entry | { id: string; role: 'notice'; text: string; ts: number; truncated: boolean; mail: { id: string; from: string; to: string; direction: 'in' | 'out'; inReplyTo?: string | null; image?: string; via?: 'voice' } }>;
@@ -72,7 +72,7 @@ export function followTeamSession({ origin, teamId, sessionId, token, tail = 300
72
72
  /**
73
73
  * A message another session sent this one, as its harness delivers it: an envelope naming the sender (a
74
74
  * `cross-session-message` tag, the innermost one when the harness wraps it in its own) around the body. Returns
75
- * { name, address, body }, or null for an ordinary turn.
75
+ * { id, name, address, body, subject, via, inReplyTo }, or null for an ordinary turn.
76
76
  */
77
77
  export function peerMessage(text) {
78
78
  const close = text.search(/<\\?\/cross-session-message>/);
@@ -80,10 +80,15 @@ export function peerMessage(text) {
80
80
  const opens = [...text.slice(0, close).matchAll(/<\\?cross-session-message\b([^>]*)>/g)];
81
81
  if (!opens.length) return null;
82
82
  const inner = opens[opens.length - 1];
83
- const attributes = (tag) => Object.fromEntries([...tag.matchAll(/([\w-]+)="([^"]*)"/g)].map((m) => [m[1], m[2]]));
83
+ // Match the producer's escaping, exactly once. An original literal &lt;
84
+ // arrives as &amp;lt; and must remain &lt;, rather than becoming a tag.
85
+ const entities = { amp: '&', lt: '<', gt: '>', quot: '"' };
86
+ const decodeAttribute = value => value.replace(/&(amp|lt|gt|quot);/g, (_, name) => entities[name]);
87
+ const attributes = (tag) => Object.fromEntries([...tag.matchAll(/([\w-]+)="([^"]*)"/g)].map((m) => [m[1], decodeAttribute(m[2])]));
84
88
  const own = attributes(inner[1]), outer = attributes(opens[0][1]);
85
- const body = text.slice(inner.index + inner[0].length, close).trim();
86
- return { id: own.id || outer.id || null, name: own['from-name'] || outer['from-name'] || own.from || outer.from || 'Another session', address: own.from || outer.from || '', body };
89
+ const body = text.slice(inner.index + inner[0].length, close).trim().replace(/&(amp|lt);/g, (_, name) => entities[name]);
90
+ return { id: own.id || outer.id || null, name: own['from-name'] || outer['from-name'] || own.from || outer.from || 'Another session', address: own.from || outer.from || '', body,
91
+ subject: own.subject || outer.subject || null, via: own.via || outer.via || null, inReplyTo: own['in-reply-to'] || outer['in-reply-to'] || null };
87
92
  }
88
93
 
89
94
  /** A known person's picture; an unnamed sender gets the neutral brand user icon. */
@@ -128,7 +133,7 @@ export function withPeople(transcript, messages, { agentName = null, sessionId =
128
133
  const peer = attributed ? null : peerMessage(entry.text);
129
134
  if (peer) {
130
135
  const seed = peer.address.startsWith('sc:') ? peer.address : peer.name;
131
- return { ...entry, text: peer.body, mail: { id: peer.id || entry.id, from: peer.name, to: agentName || 'This session', direction: 'in' }, 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 }] };
136
+ 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 }] };
132
137
  }
133
138
  const name = metadata.source_name || null;
134
139
  const seed = name ? (metadata.source_principal_id || name) : '';