@volter/supercode-teams 0.2.115 → 0.2.116
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/mail-history.mjs +44 -7
- package/package.json +1 -1
package/mail-history.mjs
CHANGED
|
@@ -4,6 +4,47 @@ import { hostname } from 'node:os';
|
|
|
4
4
|
import { spawn } from 'node:child_process';
|
|
5
5
|
import { teamsHome } from '@volter/teams/home';
|
|
6
6
|
|
|
7
|
+
const directories = new Map();
|
|
8
|
+
function sessionDirectory(binary, env, signal) {
|
|
9
|
+
const key = `${binary}:${teamsHome(env)}`;
|
|
10
|
+
const cached = directories.get(key);
|
|
11
|
+
if (cached && cached.until > Date.now()) return cached.value;
|
|
12
|
+
const value = new Promise((resolve, reject) => {
|
|
13
|
+
const child = spawn(binary, ['message', 'list', '--json'], { env, signal: AbortSignal.any([...(signal ? [signal] : []), AbortSignal.timeout(15_000)]), stdio: ['ignore', 'pipe', 'ignore'] });
|
|
14
|
+
let out = '';
|
|
15
|
+
child.stdout.on('data', chunk => { out += chunk; if (out.length > 4_000_000) child.kill(); });
|
|
16
|
+
child.on('error', reject);
|
|
17
|
+
child.on('close', code => { try { if (code !== 0) throw new Error('Session directory unavailable'); resolve(JSON.parse(out)); } catch (error) { reject(error); } });
|
|
18
|
+
}).catch(() => []);
|
|
19
|
+
directories.set(key, { until: Date.now() + 60_000, value });
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Resolve from supercode's existing session directory and explicit voice
|
|
24
|
+
* backing, never by interpreting an operator mailbox's generated name. */
|
|
25
|
+
function mailActors(rows, sessions, self) {
|
|
26
|
+
const directory = new Map(sessions.map(session => [session.address, session]));
|
|
27
|
+
const voices = new Map(rows.filter(row => row.envelope.voice_for).map(row => [row.envelope.from, row.envelope.voice_for]));
|
|
28
|
+
const names = new Map(rows.map(row => [row.envelope.from, row.envelope.from_name]));
|
|
29
|
+
const actor = (address) => {
|
|
30
|
+
const backing = voices.get(address) || address;
|
|
31
|
+
const native = /^sc:([^:]+):([^:]+):(.+)$/.exec(backing);
|
|
32
|
+
const session = directory.get(backing);
|
|
33
|
+
const kind = native && !['operator', 'board', 'pane'].includes(native[2]) ? 'agent' : 'automation';
|
|
34
|
+
let name = session?.name || names.get(backing) || (native?.[2] === 'board' ? 'Board' : kind === 'agent' ? native[2] : 'Automation');
|
|
35
|
+
if (native && name.endsWith(`@${native[1]}`)) name = name.slice(0, -native[1].length - 1);
|
|
36
|
+
// An unnamed session gets its harness label, not its address as a name.
|
|
37
|
+
if (/^(?:codex|claude-code|claude|gemini|pi|goose|grok|opencode)-[0-9a-f]{8,}$/i.test(name)) name = native[2] === 'codex' ? 'Codex' : native[2];
|
|
38
|
+
return { id: backing, name, kind, self: backing === self, ...(native ? { session: { machine: native[1], harness: native[2], id: native[3] } } : {}), ...(voices.has(address) ? { via: 'voice' } : {}) };
|
|
39
|
+
};
|
|
40
|
+
return rows.map(({ envelope, session: to, direction, delivery }) => ({
|
|
41
|
+
id: envelope.id, from: envelope.from, fromName: envelope.from_name, to,
|
|
42
|
+
fromActor: actor(envelope.from), toActor: actor(to),
|
|
43
|
+
text: envelope.body, at: envelope.created_at_ms, direction,
|
|
44
|
+
inReplyTo: envelope.in_reply_to ?? null, delivery: delivery?.state ?? 'unknown',
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
|
|
7
48
|
// Match the CLI's local_machine_name: the native mailbox belongs to its
|
|
8
49
|
// enrolled context, which can differ from a viewer connector's --home.
|
|
9
50
|
function machineName(env) {
|
|
@@ -30,21 +71,17 @@ export function readMailHistory({ binary, env, harness, session, signal }) {
|
|
|
30
71
|
const address = `sc:${machineName(env)}:${harness}:${session}`;
|
|
31
72
|
return new Promise((resolve, reject) => {
|
|
32
73
|
const child = spawn(binary, ['message', 'inbox', '--session', address, '--json', '--recent', '100'], {
|
|
33
|
-
env, stdio: ['ignore', 'pipe', 'pipe'], signal: AbortSignal.any([signal, AbortSignal.timeout(20_000)]),
|
|
74
|
+
env, stdio: ['ignore', 'pipe', 'pipe'], signal: AbortSignal.any([...(signal ? [signal] : []), AbortSignal.timeout(20_000)]),
|
|
34
75
|
});
|
|
35
76
|
let out = '', error = '';
|
|
36
77
|
child.stdout.on('data', chunk => { out += chunk; if (out.length > 8_000_000) child.kill(); });
|
|
37
78
|
child.stderr.on('data', chunk => { error = (error + chunk).slice(-1000); });
|
|
38
79
|
child.on('error', reject);
|
|
39
|
-
child.on('close', code => {
|
|
80
|
+
child.on('close', async code => {
|
|
40
81
|
if (code !== 0) return reject(new Error(error || 'Mailbox could not be read'));
|
|
41
82
|
try {
|
|
42
83
|
const rows = JSON.parse(out).filter(row => ['peer', 'channel'].includes(row.envelope?.kind));
|
|
43
|
-
resolve(rows
|
|
44
|
-
id: envelope.id, from: envelope.from, fromName: envelope.from_name, to,
|
|
45
|
-
text: envelope.body, at: envelope.created_at_ms, direction,
|
|
46
|
-
inReplyTo: envelope.in_reply_to ?? null, delivery: delivery?.state ?? 'unknown',
|
|
47
|
-
})));
|
|
84
|
+
resolve(mailActors(rows, await sessionDirectory(binary, env, signal), address));
|
|
48
85
|
} catch (error) { reject(error); }
|
|
49
86
|
});
|
|
50
87
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/supercode-teams",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.116",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A machine daemon serving this machine's doors, and a local or remote Teams server for shared session discovery, OpenTelemetry ingestion and access to enrolled machines.",
|
|
6
6
|
"license": "MIT",
|