@volter/teams 0.1.61 → 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 +1 -1
- package/session-follow.d.ts +2 -2
- package/session-follow.mjs +23 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/teams",
|
|
3
|
-
"version": "0.1.
|
|
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",
|
package/session-follow.d.ts
CHANGED
|
@@ -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' } }>;
|
|
@@ -45,7 +45,7 @@ export function agentImage(seed: string): string;
|
|
|
45
45
|
* Who wrote each entry of a projected transcript (supercode-ui's `TranscriptEntryModel`s), from the messages' own
|
|
46
46
|
* annotations. Each actor carries `id` (a principal id, a session address or seed) for a host that draws its own faces.
|
|
47
47
|
*/
|
|
48
|
-
export function withPeople<Entry extends { role: string; text: string; ts: number | null; id: string }>(
|
|
48
|
+
export function withPeople<Entry extends { role: string; text: string; ts: number | null; id: string; messageIndex?: number }>(
|
|
49
49
|
transcript: Entry[],
|
|
50
50
|
messages: Array<{ role?: string; metadata?: Record<string, unknown> }>,
|
|
51
51
|
options?: { agentName?: string | null; sessionId?: string; personImage?(seed: string): string; agentImage?(seed: string): string; locale?: string | string[] },
|
package/session-follow.mjs
CHANGED
|
@@ -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
|
-
|
|
83
|
+
// Match the producer's escaping, exactly once. An original literal <
|
|
84
|
+
// arrives as &lt; and must remain <, 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. */
|
|
@@ -104,24 +109,32 @@ export function withPeople(transcript, messages, { agentName = null, sessionId =
|
|
|
104
109
|
for (const message of messages) {
|
|
105
110
|
if (message?.role !== 'user') continue;
|
|
106
111
|
const at = Date.parse(message.metadata?.timestamp ?? '');
|
|
107
|
-
|
|
112
|
+
// A timestamp alone is not an identity: a native batch may record several
|
|
113
|
+
// turns at the same instant. Keep this fallback only when it is unambiguous.
|
|
114
|
+
if (Number.isFinite(at)) byTime.set(at, byTime.has(at) ? null : message.metadata);
|
|
108
115
|
}
|
|
109
116
|
const people = transcript.map((entry) => {
|
|
110
117
|
if (entry.role === 'assistant') return { ...entry, actor: { id: sessionId, ...(agentName ? { name: agentName } : {}), image: agent(sessionId), kind: 'agent' } };
|
|
111
118
|
if (entry.role !== 'user') return entry;
|
|
119
|
+
// The projection carries its one-based position in this exact capture.
|
|
120
|
+
// Resolve it before looking at the words: a person's pasted envelope or
|
|
121
|
+
// wake notice remains that person's message when the native source says so.
|
|
122
|
+
const indexed = Number.isSafeInteger(entry.messageIndex) && entry.messageIndex > 0;
|
|
123
|
+
const native = indexed ? messages[entry.messageIndex - 1] : null;
|
|
124
|
+
const metadata = indexed ? native?.role === 'user' ? native.metadata ?? {} : {} : byTime.get(entry.ts) ?? {};
|
|
125
|
+
const attributed = Boolean(metadata.source_principal_id || metadata.source_name || metadata.source_via);
|
|
112
126
|
const automated = /^\s*<(hook_prompt|supercode-notice)\b[^>]*>([\s\S]*)<\/\1>\s*$/.exec(entry.text);
|
|
113
127
|
// This exact legacy wake string is emitted by mail_route::CODEX_WAKE. Do
|
|
114
128
|
// not infer automation from general wording in a person's own message.
|
|
115
129
|
const legacyWake = entry.text.trim() === 'You have unread supercode messages. Read them with: supercode message inbox';
|
|
116
|
-
if (automated || legacyWake) return { ...entry, role: 'notice', code: 'automation', text: `${automated?.[1] === 'hook_prompt' ? 'Hook' : 'Mailbox'} notification: ${automated ? automated[2].trim() : entry.text.trim()}` };
|
|
130
|
+
if (!attributed && (automated || legacyWake)) return { ...entry, role: 'notice', code: 'automation', text: `${automated?.[1] === 'hook_prompt' ? 'Hook' : 'Mailbox'} notification: ${automated ? automated[2].trim() : entry.text.trim()}` };
|
|
117
131
|
// A harness's delivery notice about a message is a compact system line, not a person's turn.
|
|
118
|
-
if (/^\s*\[Cross-session [a-z ]*notice\]/i.test(entry.text)) return { ...entry, role: 'notice', text: entry.text.trim().split('\n')[0] };
|
|
119
|
-
const peer = peerMessage(entry.text);
|
|
132
|
+
if (!attributed && /^\s*\[Cross-session [a-z ]*notice\]/i.test(entry.text)) return { ...entry, role: 'notice', text: entry.text.trim().split('\n')[0] };
|
|
133
|
+
const peer = attributed ? null : peerMessage(entry.text);
|
|
120
134
|
if (peer) {
|
|
121
135
|
const seed = peer.address.startsWith('sc:') ? peer.address : peer.name;
|
|
122
|
-
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 }] };
|
|
123
137
|
}
|
|
124
|
-
const metadata = byTime.get(entry.ts) ?? {};
|
|
125
138
|
const name = metadata.source_name || null;
|
|
126
139
|
const seed = name ? (metadata.source_principal_id || name) : '';
|
|
127
140
|
const via = typeof metadata.source_via === 'string' ? metadata.source_via.trim() : '';
|