@volter/supercode-teams 0.2.160 → 0.2.161
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 +29 -4
- package/package.json +1 -1
package/mail-history.mjs
CHANGED
|
@@ -22,10 +22,11 @@ function sessionDirectory(binary, env, signal) {
|
|
|
22
22
|
|
|
23
23
|
/** Resolve from supercode's existing session directory and explicit voice
|
|
24
24
|
* backing, never by interpreting an operator mailbox's generated name. */
|
|
25
|
-
function mailActors(rows, sessions, self) {
|
|
25
|
+
function mailActors(rows, sessions, self, answered = []) {
|
|
26
26
|
const directory = new Map(sessions.map(session => [session.address, session]));
|
|
27
|
-
const
|
|
28
|
-
const
|
|
27
|
+
const identities = [...answered, ...rows];
|
|
28
|
+
const voices = new Map(identities.filter(row => row.envelope.voice_for).map(row => [row.envelope.from, row.envelope.voice_for]));
|
|
29
|
+
const names = new Map(identities.map(row => [row.envelope.from, row.envelope.from_name]));
|
|
29
30
|
const actor = (address) => {
|
|
30
31
|
const backing = voices.get(address) || address;
|
|
31
32
|
const native = /^sc:([^:]+):([^:]+):(.+)$/.exec(backing);
|
|
@@ -45,6 +46,29 @@ function mailActors(rows, sessions, self) {
|
|
|
45
46
|
}));
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
async function answeredMail(rows, binary, env, signal) {
|
|
50
|
+
const known = new Set(rows.filter(row => row.envelope.voice_for).map(row => row.envelope.from));
|
|
51
|
+
const replies = rows.filter(row => row.direction === 'out' && row.envelope.in_reply_to && !known.has(row.session) && /^sc:[^:]+:operator:/.test(row.session));
|
|
52
|
+
const ids = [...new Set(replies.map(row => row.envelope.in_reply_to))];
|
|
53
|
+
if (!ids.length) return [];
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
const child = spawn(binary, ['message', 'show', ...ids, '--json'], {
|
|
56
|
+
env, stdio: ['ignore', 'pipe', 'pipe'], signal: AbortSignal.any([...(signal ? [signal] : []), AbortSignal.timeout(20_000)]),
|
|
57
|
+
});
|
|
58
|
+
let output = '', detail = '';
|
|
59
|
+
child.stdout.on('data', chunk => { output += chunk; if (output.length > 8_000_000) child.kill(); });
|
|
60
|
+
child.stderr.on('data', chunk => { detail = (detail + chunk).slice(-1000); });
|
|
61
|
+
child.on('error', reject);
|
|
62
|
+
child.on('close', code => {
|
|
63
|
+
try {
|
|
64
|
+
if (code !== 0 && code !== 3) throw new Error(detail || 'Answered messages could not be read');
|
|
65
|
+
const parents = JSON.parse(output).filter(row => row.found === true).map(row => row.message);
|
|
66
|
+
resolve(parents.filter(parent => parent.envelope?.voice_for && replies.some(reply => reply.envelope.in_reply_to === parent.envelope.id && reply.session === parent.envelope.from && reply.envelope.from === parent.session)));
|
|
67
|
+
} catch (error) { reject(error); }
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
48
72
|
// Match the CLI's local_machine_name: the native mailbox belongs to its
|
|
49
73
|
// enrolled context, which can differ from a viewer connector's --home.
|
|
50
74
|
function machineName(env) {
|
|
@@ -81,7 +105,8 @@ export function readMailHistory({ binary, env, harness, session, signal }) {
|
|
|
81
105
|
if (code !== 0) return reject(new Error(error || 'Mailbox could not be read'));
|
|
82
106
|
try {
|
|
83
107
|
const rows = JSON.parse(out).filter(row => ['peer', 'channel'].includes(row.envelope?.kind));
|
|
84
|
-
|
|
108
|
+
const [sessions, answered] = await Promise.all([sessionDirectory(binary, env, signal), answeredMail(rows, binary, env, signal)]);
|
|
109
|
+
resolve(mailActors(rows, sessions, address, answered));
|
|
85
110
|
} catch (error) { reject(error); }
|
|
86
111
|
});
|
|
87
112
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/supercode-teams",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.161",
|
|
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",
|