operon-agents-peers 0.1.0-alpha.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/LICENSE +55 -0
- package/README.md +191 -0
- package/dist/define-tool.d.ts +16 -0
- package/dist/define-tool.js +17 -0
- package/dist/directory.d.ts +148 -0
- package/dist/directory.js +148 -0
- package/dist/file-repo.d.ts +3 -0
- package/dist/file-repo.js +119 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +33 -0
- package/dist/mailbox.d.ts +64 -0
- package/dist/mailbox.js +32 -0
- package/dist/member-tool.d.ts +4 -0
- package/dist/member-tool.js +97 -0
- package/dist/network.d.ts +320 -0
- package/dist/network.js +526 -0
- package/dist/repo.d.ts +30 -0
- package/dist/repo.js +27 -0
- package/dist/stats.d.ts +80 -0
- package/dist/stats.js +80 -0
- package/dist/team-tool.d.ts +4 -0
- package/dist/team-tool.js +139 -0
- package/package.json +41 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local-first durable repo: two JSON files in a directory the host owns.
|
|
3
|
+
*
|
|
4
|
+
* - `mailbox.json` — messages in flight (the crash window `reconcile()` walks)
|
|
5
|
+
* - `cards.json` — team labels + type/description cards (what makes parked teammates wakeable)
|
|
6
|
+
* - stats stay in memory on purpose — see `MemoryPeerStatsStore` for why
|
|
7
|
+
*
|
|
8
|
+
* Atomicity is per PROCESS: every mutation runs on a per-file promise chain (load → apply →
|
|
9
|
+
* write tmp → rename), so concurrent calls inside one process serialize and a crash mid-write
|
|
10
|
+
* leaves the previous file intact. It is NOT safe for two processes to share the directory —
|
|
11
|
+
* a multi-process deployment implements `PeerRepo` on a store with real cross-process atomicity
|
|
12
|
+
* (PG, Redis) instead.
|
|
13
|
+
*/
|
|
14
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { MemoryPeerStatsStore } from "./stats.js";
|
|
17
|
+
/** One JSON file holding a `Record<string, T>`, all access serialized on a promise chain. */
|
|
18
|
+
class JsonBook {
|
|
19
|
+
chain = Promise.resolve();
|
|
20
|
+
book;
|
|
21
|
+
path;
|
|
22
|
+
constructor(path) {
|
|
23
|
+
this.path = path;
|
|
24
|
+
}
|
|
25
|
+
async load() {
|
|
26
|
+
if (this.book !== undefined)
|
|
27
|
+
return this.book;
|
|
28
|
+
try {
|
|
29
|
+
const parsed = JSON.parse(await readFile(this.path, "utf8"));
|
|
30
|
+
this.book = parsed !== null && typeof parsed === "object" ? parsed : {};
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
this.book = {};
|
|
34
|
+
}
|
|
35
|
+
return this.book;
|
|
36
|
+
}
|
|
37
|
+
/** Read-only access still goes through the chain, so it never observes a half-applied mutation. */
|
|
38
|
+
read(fn) {
|
|
39
|
+
return this.run(async () => fn(await this.load()));
|
|
40
|
+
}
|
|
41
|
+
mutate(fn) {
|
|
42
|
+
return this.run(async () => {
|
|
43
|
+
const book = await this.load();
|
|
44
|
+
const result = fn(book);
|
|
45
|
+
await mkdir(join(this.path, ".."), { recursive: true });
|
|
46
|
+
const tmp = `${this.path}.tmp`;
|
|
47
|
+
await writeFile(tmp, JSON.stringify(book, null, 2), "utf8");
|
|
48
|
+
await rename(tmp, this.path);
|
|
49
|
+
return result;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
run(fn) {
|
|
53
|
+
const next = this.chain.then(fn);
|
|
54
|
+
// Keep the chain alive even when one operation rejects.
|
|
55
|
+
this.chain = next.catch(() => undefined);
|
|
56
|
+
return next;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class FilePeerMailbox {
|
|
60
|
+
file;
|
|
61
|
+
constructor(path) {
|
|
62
|
+
this.file = new JsonBook(path);
|
|
63
|
+
}
|
|
64
|
+
enqueue(message, opts) {
|
|
65
|
+
return this.file.mutate((book) => {
|
|
66
|
+
const queue = book[message.to] ?? [];
|
|
67
|
+
if (opts?.capacity !== undefined && queue.length >= opts.capacity)
|
|
68
|
+
return { accepted: false };
|
|
69
|
+
queue.push(message);
|
|
70
|
+
book[message.to] = queue;
|
|
71
|
+
return { accepted: true };
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
pending(agentId) {
|
|
75
|
+
return this.file.read((book) => [...(book[agentId] ?? [])]);
|
|
76
|
+
}
|
|
77
|
+
settle(agentId, messageId) {
|
|
78
|
+
return this.file.mutate((book) => {
|
|
79
|
+
const queue = book[agentId];
|
|
80
|
+
if (queue === undefined)
|
|
81
|
+
return;
|
|
82
|
+
const next = queue.filter((message) => message.messageId !== messageId);
|
|
83
|
+
if (next.length === 0)
|
|
84
|
+
delete book[agentId];
|
|
85
|
+
else
|
|
86
|
+
book[agentId] = next;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
pendingRecipients() {
|
|
90
|
+
return this.file.read((book) => Object.keys(book));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
class FilePeerCardStore {
|
|
94
|
+
file;
|
|
95
|
+
constructor(path) {
|
|
96
|
+
this.file = new JsonBook(path);
|
|
97
|
+
}
|
|
98
|
+
put(agentId, card) {
|
|
99
|
+
return this.file.mutate((book) => {
|
|
100
|
+
book[agentId] = card;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
remove(agentId) {
|
|
104
|
+
return this.file.mutate((book) => {
|
|
105
|
+
delete book[agentId];
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
list() {
|
|
109
|
+
return this.file.read((book) => Object.entries(book).map(([agentId, card]) => ({ agentId, card })));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export function createFilePeerRepo(dir) {
|
|
113
|
+
return {
|
|
114
|
+
mailbox: new FilePeerMailbox(join(dir, "mailbox.json")),
|
|
115
|
+
cards: new FilePeerCardStore(join(dir, "cards.json")),
|
|
116
|
+
stats: new MemoryPeerStatsStore(),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=file-repo.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Peer discovery and messaging between agents — built entirely on public seams, with nothing in
|
|
3
|
+
* the engine. See this package's README.
|
|
4
|
+
*
|
|
5
|
+
* One definition, two channels. `peers(config)` is an ordinary `ExtensionDefinition` (with a
|
|
6
|
+
* `create` half): the server passes it by value, a desktop loads the same thing from a bundle.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const harness = createHarness({
|
|
10
|
+
* extensions: [peers({
|
|
11
|
+
* visibility: sharedLabelVisibility,
|
|
12
|
+
* teammates: { coder: { title: "coder" } }, // what a `coder` teammate is born as
|
|
13
|
+
* })],
|
|
14
|
+
* });
|
|
15
|
+
* const lead = await harness.createSession();
|
|
16
|
+
* // The lead's agent can `Team create` + `Team spawn`; teammates talk over `Hub`.
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* There is no team object: membership is a label on the roster, and a teammate is a session the
|
|
20
|
+
* extension's `create` half spawned. Capability follows birth — an ordinary session holds `Team`
|
|
21
|
+
* (form and run its own team), a spawned teammate holds only `Hub` (general peer messaging), and
|
|
22
|
+
* never `Team`: it is a member, not a team-former. `setup` reaches the network only through the
|
|
23
|
+
* shared handle, which is what lets a reload swap the network under live sessions.
|
|
24
|
+
*/
|
|
25
|
+
export { PeerNetwork, createPeerNetwork, peers, mountTeam, mountHub, PEER_SOURCE, PEERS_SERVICE } from "./network.ts";
|
|
26
|
+
export type { PeerNetworkHandle } from "./network.ts";
|
|
27
|
+
export type { PeerExtensionOptions, PeerMemberOptions, PeerNetworkOptions, PeerOptions, PeerParams, PeerReceipt, TeamCaller, TeammateFactory, TeammateSessionOptions, TeammateSpawnRequest, } from "./network.ts";
|
|
28
|
+
export { MemoryPeerStatsStore, UsageDiff, budgetExceeded } from "./stats.ts";
|
|
29
|
+
export type { PeerAgentStats, PeerBudget, PeerCounters, PeerFleetStats, PeerStatsStore } from "./stats.ts";
|
|
30
|
+
export { MemoryAgentDirectory, MemoryPeerCardStore, anyOf, sameSessionVisibility, sharedLabelVisibility } from "./directory.ts";
|
|
31
|
+
export type { AgentDirectory, AgentListFilter, AgentRef, AgentRefKind, AgentRefStatus, PeerCard, PeerCardStore, Visibility } from "./directory.ts";
|
|
32
|
+
export { MemoryPeerMailbox } from "./mailbox.ts";
|
|
33
|
+
export type { PeerLimits, PeerMailbox, PeerMessage } from "./mailbox.ts";
|
|
34
|
+
export { createMemoryPeerRepo } from "./repo.ts";
|
|
35
|
+
export type { PeerRepo } from "./repo.ts";
|
|
36
|
+
export { createFilePeerRepo } from "./file-repo.ts";
|
|
37
|
+
export { buildTeamTool } from "./team-tool.ts";
|
|
38
|
+
export { buildMemberTool } from "./member-tool.ts";
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Peer discovery and messaging between agents — built entirely on public seams, with nothing in
|
|
3
|
+
* the engine. See this package's README.
|
|
4
|
+
*
|
|
5
|
+
* One definition, two channels. `peers(config)` is an ordinary `ExtensionDefinition` (with a
|
|
6
|
+
* `create` half): the server passes it by value, a desktop loads the same thing from a bundle.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const harness = createHarness({
|
|
10
|
+
* extensions: [peers({
|
|
11
|
+
* visibility: sharedLabelVisibility,
|
|
12
|
+
* teammates: { coder: { title: "coder" } }, // what a `coder` teammate is born as
|
|
13
|
+
* })],
|
|
14
|
+
* });
|
|
15
|
+
* const lead = await harness.createSession();
|
|
16
|
+
* // The lead's agent can `Team create` + `Team spawn`; teammates talk over `Hub`.
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* There is no team object: membership is a label on the roster, and a teammate is a session the
|
|
20
|
+
* extension's `create` half spawned. Capability follows birth — an ordinary session holds `Team`
|
|
21
|
+
* (form and run its own team), a spawned teammate holds only `Hub` (general peer messaging), and
|
|
22
|
+
* never `Team`: it is a member, not a team-former. `setup` reaches the network only through the
|
|
23
|
+
* shared handle, which is what lets a reload swap the network under live sessions.
|
|
24
|
+
*/
|
|
25
|
+
export { PeerNetwork, createPeerNetwork, peers, mountTeam, mountHub, PEER_SOURCE, PEERS_SERVICE } from "./network.js";
|
|
26
|
+
export { MemoryPeerStatsStore, UsageDiff, budgetExceeded } from "./stats.js";
|
|
27
|
+
export { MemoryAgentDirectory, MemoryPeerCardStore, anyOf, sameSessionVisibility, sharedLabelVisibility } from "./directory.js";
|
|
28
|
+
export { MemoryPeerMailbox } from "./mailbox.js";
|
|
29
|
+
export { createMemoryPeerRepo } from "./repo.js";
|
|
30
|
+
export { createFilePeerRepo } from "./file-repo.js";
|
|
31
|
+
export { buildTeamTool } from "./team-tool.js";
|
|
32
|
+
export { buildMemberTool } from "./member-tool.js";
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write-ahead ledger for messages in flight.
|
|
3
|
+
*
|
|
4
|
+
* A message is recorded here BEFORE it is handed to the recipient, because delivery goes through
|
|
5
|
+
* an in-memory queue: a crash between enqueue and the recipient consuming it would otherwise lose
|
|
6
|
+
* the message with no trace of it ever existing.
|
|
7
|
+
*
|
|
8
|
+
* The durable anchor on the other side is the recipient's own journal — a delivered peer message
|
|
9
|
+
* is recorded with `origin.deliveryId`, so a restart can tell "already delivered" from "never
|
|
10
|
+
* arrived" by looking there. This ledger therefore never tracks delivery itself; `settle` only
|
|
11
|
+
* reclaims space.
|
|
12
|
+
*/
|
|
13
|
+
export interface PeerMessage {
|
|
14
|
+
readonly messageId: string;
|
|
15
|
+
readonly from: string;
|
|
16
|
+
readonly to: string;
|
|
17
|
+
readonly content: string;
|
|
18
|
+
readonly replyTo?: string;
|
|
19
|
+
readonly queuedAt: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* CONCURRENCY CONTRACT (holds for every `PeerRepo` facet): each method is atomic in the backend;
|
|
23
|
+
* no caller ever does a cross-call read-modify-write. That is what lets one repo be shared without
|
|
24
|
+
* conflicts — capacity, in particular, is checked INSIDE `enqueue`, in the same atomic step as the
|
|
25
|
+
* insert, so `mailboxCapacity` is a hard limit rather than a check-then-act race.
|
|
26
|
+
*/
|
|
27
|
+
export interface PeerMailbox {
|
|
28
|
+
/** Record one message in flight. With `capacity` set, a full mailbox refuses atomically —
|
|
29
|
+
* `accepted: false` and nothing written. */
|
|
30
|
+
enqueue(message: PeerMessage, opts?: {
|
|
31
|
+
readonly capacity?: number;
|
|
32
|
+
}): Promise<{
|
|
33
|
+
readonly accepted: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
pending(agentId: string): Promise<readonly PeerMessage[]>;
|
|
36
|
+
settle(agentId: string, messageId: string): Promise<void>;
|
|
37
|
+
/** Everyone with undelivered entries. What `PeerNetwork.reconcile()` walks on startup. */
|
|
38
|
+
pendingRecipients(): Promise<readonly string[]>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Non-durable default: enough to route in one process, NOT enough to survive a restart.
|
|
42
|
+
* A deployment that cares about the crash window supplies a durable `PeerRepo` (file, PG, …).
|
|
43
|
+
*/
|
|
44
|
+
export declare class MemoryPeerMailbox implements PeerMailbox {
|
|
45
|
+
private readonly queues;
|
|
46
|
+
enqueue(message: PeerMessage, opts?: {
|
|
47
|
+
readonly capacity?: number;
|
|
48
|
+
}): Promise<{
|
|
49
|
+
readonly accepted: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
pending(agentId: string): Promise<readonly PeerMessage[]>;
|
|
52
|
+
settle(agentId: string, messageId: string): Promise<void>;
|
|
53
|
+
pendingRecipients(): Promise<readonly string[]>;
|
|
54
|
+
}
|
|
55
|
+
export interface PeerLimits {
|
|
56
|
+
/** Cap on outbound messages within one turn. Guards a runaway send loop inside a single turn;
|
|
57
|
+
* deliberately orthogonal to conversation length — a long peer discussion is normal
|
|
58
|
+
* collaboration, and the real cost ceiling is the existing turn budget. */
|
|
59
|
+
readonly maxOutboundPerTurn?: number;
|
|
60
|
+
/** Mailbox depth. Full means REJECT with a failed receipt — never silently drop the oldest,
|
|
61
|
+
* which would leave the sender believing delivery happened. */
|
|
62
|
+
readonly mailboxCapacity?: number;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=mailbox.d.ts.map
|
package/dist/mailbox.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-durable default: enough to route in one process, NOT enough to survive a restart.
|
|
3
|
+
* A deployment that cares about the crash window supplies a durable `PeerRepo` (file, PG, …).
|
|
4
|
+
*/
|
|
5
|
+
export class MemoryPeerMailbox {
|
|
6
|
+
queues = new Map();
|
|
7
|
+
async enqueue(message, opts) {
|
|
8
|
+
const queue = this.queues.get(message.to) ?? [];
|
|
9
|
+
if (opts?.capacity !== undefined && queue.length >= opts.capacity)
|
|
10
|
+
return { accepted: false };
|
|
11
|
+
queue.push(message);
|
|
12
|
+
this.queues.set(message.to, queue);
|
|
13
|
+
return { accepted: true };
|
|
14
|
+
}
|
|
15
|
+
async pending(agentId) {
|
|
16
|
+
return [...(this.queues.get(agentId) ?? [])];
|
|
17
|
+
}
|
|
18
|
+
async settle(agentId, messageId) {
|
|
19
|
+
const queue = this.queues.get(agentId);
|
|
20
|
+
if (queue === undefined)
|
|
21
|
+
return;
|
|
22
|
+
const next = queue.filter((message) => message.messageId !== messageId);
|
|
23
|
+
if (next.length === 0)
|
|
24
|
+
this.queues.delete(agentId);
|
|
25
|
+
else
|
|
26
|
+
this.queues.set(agentId, next);
|
|
27
|
+
}
|
|
28
|
+
async pendingRecipients() {
|
|
29
|
+
return [...this.queues.keys()];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=mailbox.js.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The member `Hub` tool — the surface a TEAMMATE is born with. General peer messaging, gated by
|
|
3
|
+
* the network's visibility policy. Only sessions whose `params.peers` names a `member` carry it
|
|
4
|
+
* (what the spawn factory sets); ordinary sessions get the `Team` tool instead, whose reach is
|
|
5
|
+
* their own members only.
|
|
6
|
+
*
|
|
7
|
+
* `wait` is deliberately absent: a teammate answers by being woken, and a blocking op would only
|
|
8
|
+
* add the one thing this design has none of — a way for two agents to deadlock.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { defineTool } from "./define-tool.js";
|
|
12
|
+
const hubInput = z.discriminatedUnion("op", [
|
|
13
|
+
z.object({ op: z.literal("list").describe("List the peers you can address.") }),
|
|
14
|
+
z.object({
|
|
15
|
+
op: z.literal("send").describe("Send a message to a peer. Returns immediately; never waits for a reply."),
|
|
16
|
+
to: z.string().describe("Exact agent name from the roster."),
|
|
17
|
+
message: z.string().describe("Plain prose. Share paths and ids, not pasted blobs."),
|
|
18
|
+
replyTo: z.string().optional().describe("messageId you are answering, when this is a reply."),
|
|
19
|
+
interrupt: z.boolean().optional().describe("Cut into the peer's current work instead of waiting for its turn boundary. Reserve for 'stop, you're going the wrong way'."),
|
|
20
|
+
}),
|
|
21
|
+
z.object({ op: z.literal("inbox").describe("Read messages routed to you that never reached your conversation.") }),
|
|
22
|
+
]);
|
|
23
|
+
function rosterRow(ref) {
|
|
24
|
+
return {
|
|
25
|
+
name: ref.agentId,
|
|
26
|
+
type: ref.type,
|
|
27
|
+
status: ref.status,
|
|
28
|
+
...(ref.description !== undefined ? { description: ref.description } : {}),
|
|
29
|
+
...(ref.labels !== undefined && ref.labels.length > 0 ? { teams: ref.labels } : {}),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function text(body, details, isError) {
|
|
33
|
+
return { content: [{ type: "text", text: body }], ...(details !== undefined ? { details } : {}), ...(isError === true ? { isError: true } : {}) };
|
|
34
|
+
}
|
|
35
|
+
export function buildMemberTool(network, selfName) {
|
|
36
|
+
const description = [
|
|
37
|
+
"Coordinate with your peers: the teammates working alongside you, and whoever created your team.",
|
|
38
|
+
"",
|
|
39
|
+
"- `list` shows who you can address, with their name and status.",
|
|
40
|
+
"- `send` hands a message to one peer and returns immediately — it does NOT wait for a reply.",
|
|
41
|
+
" The peer sees it at its next turn boundary and answers in its own turn.",
|
|
42
|
+
"- `inbox` drains messages routed to you that never reached your conversation.",
|
|
43
|
+
"",
|
|
44
|
+
"Rules:",
|
|
45
|
+
"- Address a peer by its exact name from the roster. NEVER invent a name.",
|
|
46
|
+
"- A `failed` receipt is final for that reason — do not retry the same send.",
|
|
47
|
+
"- A `parked` peer is asleep, not gone: messaging one wakes it.",
|
|
48
|
+
"- Plain prose only. Share paths and ids rather than pasting large blobs.",
|
|
49
|
+
"- Do not use a peer for something a tool can answer yourself.",
|
|
50
|
+
].join("\n");
|
|
51
|
+
return defineTool({
|
|
52
|
+
name: "Hub",
|
|
53
|
+
description,
|
|
54
|
+
params: hubInput,
|
|
55
|
+
resolve: (args) => ({
|
|
56
|
+
// Read-only ops are auto-approved by the host's policy; `send` is not — it wakes a peer and
|
|
57
|
+
// spends its budget.
|
|
58
|
+
approvalRule: `hub.${args.op}`,
|
|
59
|
+
display: {
|
|
60
|
+
title: "Hub",
|
|
61
|
+
detail: args.op === "send" ? `${args.op} → ${args.to}` : args.op,
|
|
62
|
+
},
|
|
63
|
+
run: async (ctx) => {
|
|
64
|
+
// The member's identity is its birth name — and it belongs to the ROOT frame only.
|
|
65
|
+
// A delegation the member spawns is an ordinary delegation, not a peer.
|
|
66
|
+
if (ctx.address !== undefined && ctx.address !== "main") {
|
|
67
|
+
return text("Peer messaging belongs to this session's root agent; a delegation reports to its spawner instead.", { op: args.op }, true);
|
|
68
|
+
}
|
|
69
|
+
if (args.op === "list") {
|
|
70
|
+
const roster = await network.visiblePeers(selfName);
|
|
71
|
+
return text(roster.length === 0 ? "No peers are visible to you." : JSON.stringify({ you: selfName, peers: roster.map(rosterRow) }, null, 2), { op: args.op, count: roster.length });
|
|
72
|
+
}
|
|
73
|
+
if (args.op === "inbox") {
|
|
74
|
+
const pending = await network.drainInbox(selfName);
|
|
75
|
+
return text(pending.length === 0
|
|
76
|
+
? "No undelivered peer messages."
|
|
77
|
+
: JSON.stringify(pending.map((m) => ({ from: m.from, messageId: m.messageId, content: m.content, queuedAt: m.queuedAt })), null, 2), { op: args.op, count: pending.length });
|
|
78
|
+
}
|
|
79
|
+
const self = await network.getAgent(selfName);
|
|
80
|
+
if (self === undefined)
|
|
81
|
+
return text("You are not on the peer roster.", { op: args.op }, true);
|
|
82
|
+
if (network.overBudget(selfName, ctx.turnId)) {
|
|
83
|
+
return text("Outbound peer-message budget for this turn is exhausted. Continue your work; send again in a later turn.", { op: args.op, reason: "quota_exceeded" }, true);
|
|
84
|
+
}
|
|
85
|
+
const receipt = await network.route(self, args.to, args.message, {
|
|
86
|
+
...(args.replyTo !== undefined ? { replyTo: args.replyTo } : {}),
|
|
87
|
+
...(args.interrupt !== undefined ? { interrupt: args.interrupt } : {}),
|
|
88
|
+
});
|
|
89
|
+
const body = receipt.status === "failed"
|
|
90
|
+
? `send failed (${receipt.reason}): ${receipt.detail ?? ""}`.trim()
|
|
91
|
+
: `Message ${receipt.messageId} delivered to ${receipt.to}. It will answer in its own turn — do not wait for it.`;
|
|
92
|
+
return text(body, { op: args.op, ...receipt }, receipt.status === "failed");
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=member-tool.js.map
|