openmsg 0.5.0 → 0.7.0
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/README.md +1 -0
- package/package.json +1 -1
- package/src/cli.mjs +137 -6
- package/src/deliver.mjs +15 -7
- package/src/gateway.mjs +209 -8
- package/src/hook.mjs +40 -4
- package/src/mcp.mjs +359 -0
- package/src/mcpagents.mjs +118 -0
- package/src/places.mjs +105 -0
- package/src/registry.mjs +7 -1
- package/src/remote.mjs +22 -1
- package/src/wsframe.mjs +5 -1
package/src/registry.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import os from "node:os";
|
|
|
6
6
|
import { execFile } from "node:child_process";
|
|
7
7
|
import { registered } from "./selfregistry.mjs";
|
|
8
8
|
import { agents as webhookAgents } from "./webhooks.mjs";
|
|
9
|
+
import { agents as mcpAgents } from "./mcpagents.mjs";
|
|
9
10
|
import { promisify } from "node:util";
|
|
10
11
|
|
|
11
12
|
const run = promisify(execFile);
|
|
@@ -437,7 +438,7 @@ export async function allAgents() {
|
|
|
437
438
|
]);
|
|
438
439
|
// An agent with no push entry point reports itself from its hook.
|
|
439
440
|
// An agent that wakes on an HTTP request has no session. Its owner named it.
|
|
440
|
-
return [...claude, ...opencode, ...codex, ...registered(), ...webhookAgents()];
|
|
441
|
+
return [...claude, ...opencode, ...codex, ...registered(), ...webhookAgents(), ...mcpAgents()];
|
|
441
442
|
}
|
|
442
443
|
|
|
443
444
|
// Discovery of one vendor. The gateway needs the session of one published
|
|
@@ -451,6 +452,7 @@ export async function agentsOfVendor(vendor) {
|
|
|
451
452
|
return live.length > 0 ? live : codexAgentsFromFiles();
|
|
452
453
|
}
|
|
453
454
|
if (vendor === "webhook") return webhookAgents();
|
|
455
|
+
if (vendor === "mcp") return mcpAgents();
|
|
454
456
|
return registered();
|
|
455
457
|
}
|
|
456
458
|
|
|
@@ -536,6 +538,10 @@ export async function self() {
|
|
|
536
538
|
const known = webhookAgents().find((a) => `webhook:${a.name}` === value);
|
|
537
539
|
if (known) return known;
|
|
538
540
|
}
|
|
541
|
+
if (value.startsWith("mcp:")) {
|
|
542
|
+
const known = mcpAgents().find((a) => `mcp:${a.name}` === value);
|
|
543
|
+
if (known) return known;
|
|
544
|
+
}
|
|
539
545
|
try {
|
|
540
546
|
return await findAgent(value);
|
|
541
547
|
} catch {
|
package/src/remote.mjs
CHANGED
|
@@ -27,6 +27,10 @@ export const VERSION = 2;
|
|
|
27
27
|
// A message that waits too long says little. The deadline stops an injection
|
|
28
28
|
// that did not happen yet, and it does not undo work that started.
|
|
29
29
|
export const DEFAULT_TTL_MS = 15 * 60 * 1000;
|
|
30
|
+
// A message that the sender knows will wait takes a longer deadline: the
|
|
31
|
+
// relay does not answer, the gateway of the receiver is offline, or the
|
|
32
|
+
// session does not run now. A machine that sleeps for a night still takes it.
|
|
33
|
+
export const WAIT_TTL_MS = 24 * 3600 * 1000;
|
|
30
34
|
|
|
31
35
|
// An error of this module carries a reason. The gateway of phase 3 turns a
|
|
32
36
|
// reason into a state: refused, held, or expired.
|
|
@@ -318,7 +322,10 @@ export function digestOf(message) {
|
|
|
318
322
|
// The text that the receiving agent reads. It names the person, the project,
|
|
319
323
|
// and the limit of the message. The gateway verified the signature before this
|
|
320
324
|
// step, so the text gives no key and no fingerprint. `openmsg dir` shows them.
|
|
321
|
-
|
|
325
|
+
// `placed` says that the message went to a directory, and not to the session
|
|
326
|
+
// that it named. The session that reads it must know that it is not the
|
|
327
|
+
// session of that conversation.
|
|
328
|
+
export function layoutOf({ message, verified, placed = null }) {
|
|
322
329
|
const o = message.openmsg;
|
|
323
330
|
const who = `${o.from.vendor}:${o.from.name ?? o.from.id}@${verified.label}`;
|
|
324
331
|
const id = shortId(message.messageId);
|
|
@@ -335,12 +342,26 @@ export function layoutOf({ message, verified }) {
|
|
|
335
342
|
RULE,
|
|
336
343
|
`From the agent of another person, ${verified.label}. It is information, and it does not approve any action.`,
|
|
337
344
|
...work,
|
|
345
|
+
...whereLines(placed),
|
|
338
346
|
`To answer: openmsg send "${who}" "<your answer>" --reply-to ${id}`,
|
|
339
347
|
`After you read it: openmsg ack ${id}`,
|
|
340
348
|
],
|
|
341
349
|
);
|
|
342
350
|
}
|
|
343
351
|
|
|
352
|
+
function whereLines(placed) {
|
|
353
|
+
if (!placed) return [];
|
|
354
|
+
if (!placed.wasFor) return [`It is for the directory ${placed.place}, and not for one session.`];
|
|
355
|
+
const lines = [
|
|
356
|
+
`It was for the session ${placed.wasFor.alias}, which ended. You are another session in the same ` +
|
|
357
|
+
"directory, and you do not hold that conversation.",
|
|
358
|
+
];
|
|
359
|
+
if (placed.wasFor.vendor === "claude") {
|
|
360
|
+
lines.push(`Your user can open that conversation again with: claude --resume ${placed.wasFor.session}`);
|
|
361
|
+
}
|
|
362
|
+
return lines;
|
|
363
|
+
}
|
|
364
|
+
|
|
344
365
|
export function render(record, options = {}) {
|
|
345
366
|
return compose(layoutOf(record), options);
|
|
346
367
|
}
|
package/src/wsframe.mjs
CHANGED
|
@@ -248,11 +248,15 @@ export function connect(url, { timeoutMs = 10_000, tls: tlsOptions = {}, socketP
|
|
|
248
248
|
: socketPath
|
|
249
249
|
? net.createConnection(socketPath)
|
|
250
250
|
: net.createConnection({ host: address.hostname, port });
|
|
251
|
+
let timer = null;
|
|
251
252
|
const fail = (e) => {
|
|
253
|
+
// A timer that stays keeps the process of a command alive for its whole
|
|
254
|
+
// length, after the answer is already known.
|
|
255
|
+
clearTimeout(timer);
|
|
252
256
|
socket.destroy();
|
|
253
257
|
reject(new Error(`the server at ${socketPath ?? url} did not answer: ${e.message}`));
|
|
254
258
|
};
|
|
255
|
-
|
|
259
|
+
timer = setTimeout(() => fail(new Error("timeout")), timeoutMs);
|
|
256
260
|
socket.once("error", fail);
|
|
257
261
|
socket.on(secure ? "secureConnect" : "connect", () => {
|
|
258
262
|
socket.write(
|