@volter/teams 0.2.30 → 0.2.32
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/board-owner.mjs +18 -6
- package/machine-core.mjs +10 -3
- package/package.json +1 -1
package/board-owner.mjs
CHANGED
|
@@ -46,6 +46,14 @@ export const BOARD_OPERATION_VERBS = new Set(['serve', 'daemon', 'dispatch', 'in
|
|
|
46
46
|
export const CALLER_FACTS = ['SUPERCODE_AGENT_ID', 'SUPERCODE_AUTOMATION', 'SUPERCODE_CONTEXT', 'HERMES_PROFILE', 'USER', 'SUPERCODE_CALLER', 'SUPERCODE_RUN_LAUNCH'];
|
|
47
47
|
export const callerFacts = (env = process.env) => Object.fromEntries(CALLER_FACTS.filter((key) => env[key]).map((key) => [key, env[key]]));
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* What a caller says of an answer marked `unanswered` (the owner took the request and the call ended with no answer):
|
|
51
|
+
* the outcome is unknown, and the card is read before the verb is run again. `what` names the verb or tool.
|
|
52
|
+
*/
|
|
53
|
+
export function unansweredText(answer, what) {
|
|
54
|
+
return `${String(answer.stderr ?? '').trim() || 'the board owner gave no answer'}; whether ${what} ran is unknown: read the card with \`supercode workflow show <id>\` before running it again\n`;
|
|
55
|
+
}
|
|
56
|
+
|
|
49
57
|
/**
|
|
50
58
|
* Send one verb to the owner of the home at `root`: answers `{ code, stdout, stderr }`. A home whose owner is not
|
|
51
59
|
* running answers that, with what starts it; nothing else runs the verb.
|
|
@@ -56,25 +64,29 @@ export function askBoardOwner(root, request) {
|
|
|
56
64
|
return new Promise((done) => {
|
|
57
65
|
let answer = '';
|
|
58
66
|
let settled = false;
|
|
67
|
+
// once the request is written the owner may have run the verb: a failure after that is `unanswered` (whether it
|
|
68
|
+
// ran is unknown), never a plain failure a caller would take as "nothing happened" and run again
|
|
69
|
+
let sent = false;
|
|
59
70
|
const finish = (value) => { if (!settled) { settled = true; done(value); } };
|
|
71
|
+
const lost = (stderr) => finish({ code: 1, stdout: '', stderr, ...(sent ? { unanswered: true } : {}) });
|
|
60
72
|
const socket = connect(path);
|
|
61
73
|
socket.setEncoding('utf8');
|
|
62
74
|
// The request is one line, and the connection stays open both ways until the answer's line has come: an answer that
|
|
63
75
|
// takes its time (a Teams lookup, a reread home) is never lost to a closed side.
|
|
64
|
-
socket.on('connect', () => socket.write(`${JSON.stringify({ v: 1, ...request })}\n`));
|
|
76
|
+
socket.on('connect', () => { sent = true; socket.write(`${JSON.stringify({ v: 1, ...request })}\n`); });
|
|
65
77
|
socket.on('data', (chunk) => {
|
|
66
78
|
answer += chunk;
|
|
67
79
|
const end = answer.indexOf('\n');
|
|
68
80
|
if (end < 0) return;
|
|
69
81
|
socket.end();
|
|
70
|
-
try { finish(JSON.parse(answer.slice(0, end))); } catch {
|
|
82
|
+
try { finish(JSON.parse(answer.slice(0, end))); } catch { lost(`the board owner of ${root} answered nothing readable\n`); }
|
|
71
83
|
});
|
|
72
|
-
socket.on('close', () =>
|
|
84
|
+
socket.on('close', () => lost(`the board owner of ${root} closed the call before answering\n`));
|
|
73
85
|
socket.on('error', (error) => {
|
|
74
|
-
const down = ['ENOENT', 'ECONNREFUSED'].includes(error.code);
|
|
75
|
-
|
|
86
|
+
const down = !sent && ['ENOENT', 'ECONNREFUSED'].includes(error.code);
|
|
87
|
+
lost(down
|
|
76
88
|
? `the boards of ${root} have no running owner: \`supercode workflow serve --root ${root}\` is it (an install's keeper runs it)\n`
|
|
77
|
-
: `the board owner of ${root} could not be reached: ${error.message}\n`
|
|
89
|
+
: sent ? `the board owner of ${root} dropped the call after it was sent: ${error.message}\n` : `the board owner of ${root} could not be reached: ${error.message}\n`);
|
|
78
90
|
});
|
|
79
91
|
});
|
|
80
92
|
}
|
package/machine-core.mjs
CHANGED
|
@@ -257,7 +257,13 @@ export class MachineCore extends EventEmitter {
|
|
|
257
257
|
// ---- connections ---------------------------------------------------------
|
|
258
258
|
|
|
259
259
|
/** The local door: whoever opened the owner-only socket is this OS user. */
|
|
260
|
-
|
|
260
|
+
#accept(socket) { return this.acceptLocal(socket); }
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* A local connection: one the socket accepted, or one made inside this daemon (`facts` mark it: the app door's
|
|
264
|
+
* relayed pages are `{ appDoor: true }`, which no client can claim, as it never reaches this through the socket).
|
|
265
|
+
*/
|
|
266
|
+
async acceptLocal(socket, facts = {}) {
|
|
261
267
|
let channel;
|
|
262
268
|
try {
|
|
263
269
|
channel = await Channel.accept(socket, { floor: this.floor });
|
|
@@ -266,8 +272,9 @@ export class MachineCore extends EventEmitter {
|
|
|
266
272
|
return;
|
|
267
273
|
}
|
|
268
274
|
const index = this.nextConnection++;
|
|
269
|
-
//
|
|
270
|
-
|
|
275
|
+
// Who is on its other end is what the client says (its claim), held to the daemon's live-session map; the socket is
|
|
276
|
+
// this user's alone (docs/architecture/overview.md, "Who is calling").
|
|
277
|
+
const entry = { ...facts, channel, admitted: LOCAL_OPERATOR, principal: 'local', socket };
|
|
271
278
|
this.connections.set(index, entry);
|
|
272
279
|
channel.on('stream', (stream, accept, refuse) => this.#routeStream(index, entry, stream, accept, refuse));
|
|
273
280
|
channel.on('close', () => { this.connections.delete(index); this.connectionClosed(index); });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/teams",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.32",
|
|
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",
|