@cotal-ai/connector-core 0.169.0 → 0.171.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/dist/agent-commands.d.ts +49 -0
- package/dist/agent-commands.d.ts.map +1 -0
- package/dist/agent-commands.js +144 -0
- package/dist/agent-commands.js.map +1 -0
- package/dist/agent-endpoint.d.ts +37 -0
- package/dist/agent-endpoint.d.ts.map +1 -0
- package/dist/agent-endpoint.js +70 -0
- package/dist/agent-endpoint.js.map +1 -0
- package/dist/agent-inbox-model.d.ts +185 -0
- package/dist/agent-inbox-model.d.ts.map +1 -0
- package/dist/agent-inbox-model.js +71 -0
- package/dist/agent-inbox-model.js.map +1 -0
- package/dist/agent-inbox.d.ts +9 -80
- package/dist/agent-inbox.d.ts.map +1 -1
- package/dist/agent-inbox.js +22 -70
- package/dist/agent-inbox.js.map +1 -1
- package/dist/agent.d.ts +15 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +43 -1
- package/dist/agent.js.map +1 -1
- package/dist/docs-bundle.bin +0 -0
- package/dist/docs-bundle.generated.d.ts +1 -1
- package/dist/docs-bundle.generated.js +7 -7
- package/dist/docs-bundle.generated.js.map +1 -1
- package/dist/docs-index.bin +0 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/prompt-desk.d.ts +10 -18
- package/dist/prompt-desk.d.ts.map +1 -1
- package/dist/prompt-desk.js +19 -74
- package/dist/prompt-desk.js.map +1 -1
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type CommandEntry, type CommandTarget, type EpPrincipalCommandDef } from "@cotal-ai/core";
|
|
2
|
+
/** A `commands` reply waits at most this long for the harness's list. */
|
|
3
|
+
export declare const COMMAND_LIST_MS = 10000;
|
|
4
|
+
/** How many commands may be queued at once. */
|
|
5
|
+
export declare const MAX_QUEUED_COMMANDS = 8;
|
|
6
|
+
/** How many ended commands the agent remembers. An older id is `not-found`. */
|
|
7
|
+
export declare const ENDED_COMMANDS_KEPT = 32;
|
|
8
|
+
/** One command a caller asked this agent to run. `args` is empty when the caller sent none. */
|
|
9
|
+
export interface AgentCommand {
|
|
10
|
+
readonly target: CommandTarget;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly args: string;
|
|
13
|
+
}
|
|
14
|
+
/** Lists and starts commands on a connector's harness. */
|
|
15
|
+
export interface CommandDispatcher {
|
|
16
|
+
readonly targets: ReadonlySet<CommandTarget>;
|
|
17
|
+
/** Every command and skill the harness runs now, each named as {@link dispatch} names it. A
|
|
18
|
+
* rejection is the caller's error reply. */
|
|
19
|
+
list(): Promise<CommandEntry[]>;
|
|
20
|
+
/** Start the command, resolving once the harness accepted it. A command that runs the model runs as
|
|
21
|
+
* a turn of its own, and some, such as OpenCode's `goal clear`, run no turn. Throw
|
|
22
|
+
* {@link CommandRefused} when the harness refused it and nothing started; any other throw leaves
|
|
23
|
+
* the outcome unknown. */
|
|
24
|
+
dispatch(command: AgentCommand): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/** The harness refused a command, and nothing started. */
|
|
27
|
+
export declare class CommandRefused extends Error {
|
|
28
|
+
readonly code: "not-found" | "failed-precondition";
|
|
29
|
+
constructor(code: "not-found" | "failed-precondition", message: string);
|
|
30
|
+
}
|
|
31
|
+
/** What {@link CommandQueue.dispatchNext} did: nothing was queued, the harness accepted the command,
|
|
32
|
+
* or it did not. */
|
|
33
|
+
export type CommandDispatch = "empty" | "dispatched" | "failed";
|
|
34
|
+
/** The connector's side of the queue. */
|
|
35
|
+
export interface CommandQueue {
|
|
36
|
+
/** How many commands are queued. */
|
|
37
|
+
readonly queued: number;
|
|
38
|
+
/** Take the oldest queued command and hand it to the dispatcher. It is taken before the dispatch is
|
|
39
|
+
* awaited, so two calls never take one command. */
|
|
40
|
+
dispatchNext(): Promise<CommandDispatch>;
|
|
41
|
+
}
|
|
42
|
+
export interface CommandLane extends CommandQueue {
|
|
43
|
+
readonly handlers: EpPrincipalCommandDef[];
|
|
44
|
+
/** Refuse every queued command as `unavailable`, and refuse every later `command`. A taken command
|
|
45
|
+
* stays taken, and its dispatch still ends it. */
|
|
46
|
+
close(): void;
|
|
47
|
+
}
|
|
48
|
+
export declare function createCommandLane(dispatcher: CommandDispatcher | undefined, onQueued: () => void): CommandLane;
|
|
49
|
+
//# sourceMappingURL=agent-commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-commands.d.ts","sourceRoot":"","sources":["../src/agent-commands.ts"],"names":[],"mappings":"AASA,OAAO,EAGL,KAAK,YAAY,EAA0G,KAAK,aAAa,EACtG,KAAK,qBAAqB,EAClE,MAAM,gBAAgB,CAAC;AAExB,yEAAyE;AACzE,eAAO,MAAM,eAAe,QAAS,CAAC;AACtC,+CAA+C;AAC/C,eAAO,MAAM,mBAAmB,IAAI,CAAC;AACrC,+EAA+E;AAC/E,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,+FAA+F;AAC/F,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,0DAA0D;AAC1D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;IAC7C;iDAC6C;IAC7C,IAAI,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAChC;;;+BAG2B;IAC3B,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;AAED,0DAA0D;AAC1D,qBAAa,cAAe,SAAQ,KAAK;IAC3B,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,qBAAqB;gBAAzC,IAAI,EAAE,WAAW,GAAG,qBAAqB,EAAE,OAAO,EAAE,MAAM;CAIhF;AAED;qBACqB;AACrB,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,YAAY,GAAG,QAAQ,CAAC;AAEhE,yCAAyC;AACzC,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;wDACoD;IACpD,YAAY,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,WAAY,SAAQ,YAAY;IAC/C,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,EAAE,CAAC;IAC3C;uDACmD;IACnD,KAAK,IAAI,IAAI,CAAC;CACf;AA2BD,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,iBAAiB,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,WAAW,CA4F9G"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An agent's own harness commands and skills on its `agent` endpoint (SPEC 13.22): the `commands`,
|
|
3
|
+
* `command`, `command-cancel` and `command-state` handlers, and the queue between a `command` request
|
|
4
|
+
* and the connector's next idle turn.
|
|
5
|
+
*
|
|
6
|
+
* A command starts only while no turn runs, which only the connector can see, so the connector takes
|
|
7
|
+
* each queued command with {@link CommandQueue.dispatchNext}.
|
|
8
|
+
*/
|
|
9
|
+
import { randomBytes } from "node:crypto";
|
|
10
|
+
import { AGENT_COMMAND_DESCRIPTION_MAX, AGENT_COMMAND_INPUT_HINT_MAX, AGENT_COMMAND_LIST_MAX, AGENT_COMMAND_MESSAGE_MAX, AGENT_COMMAND_STATE_DETAIL, AGENT_CONTRACTS, EpEnvelopeError, isAgentCommandName, } from "@cotal-ai/core";
|
|
11
|
+
/** A `commands` reply waits at most this long for the harness's list. */
|
|
12
|
+
export const COMMAND_LIST_MS = 10_000;
|
|
13
|
+
/** How many commands may be queued at once. */
|
|
14
|
+
export const MAX_QUEUED_COMMANDS = 8;
|
|
15
|
+
/** How many ended commands the agent remembers. An older id is `not-found`. */
|
|
16
|
+
export const ENDED_COMMANDS_KEPT = 32;
|
|
17
|
+
/** The harness refused a command, and nothing started. */
|
|
18
|
+
export class CommandRefused extends Error {
|
|
19
|
+
code;
|
|
20
|
+
constructor(code, message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.name = "CommandRefused";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const B32 = "abcdefghijklmnopqrstuvwxyz234567";
|
|
27
|
+
const refused = (code, message) => new EpEnvelopeError(code, message, undefined, "not-executed");
|
|
28
|
+
const what = (c) => `the ${c.target} "${c.name}"`;
|
|
29
|
+
function cut(text, max) {
|
|
30
|
+
const chars = [...text];
|
|
31
|
+
return chars.length <= max ? text : `${chars.slice(0, max - 1).join("")}…`;
|
|
32
|
+
}
|
|
33
|
+
function fitText(text, max) {
|
|
34
|
+
return typeof text === "string" && text !== "" ? cut(text, max) : undefined;
|
|
35
|
+
}
|
|
36
|
+
function within(work, ms) {
|
|
37
|
+
let timer;
|
|
38
|
+
const late = new Promise((_, reject) => { timer = setTimeout(() => reject(new Error(`no answer within ${ms / 1000} s`)), ms); });
|
|
39
|
+
return Promise.race([Promise.resolve().then(work), late]).finally(() => clearTimeout(timer));
|
|
40
|
+
}
|
|
41
|
+
export function createCommandLane(dispatcher, onQueued) {
|
|
42
|
+
// Every command not yet forgotten, in the order it was queued, so the first queued entry is the oldest.
|
|
43
|
+
const entries = new Map();
|
|
44
|
+
const ended = [];
|
|
45
|
+
let closed = false;
|
|
46
|
+
const queued = () => [...entries.values()].filter((e) => e.state.kind === "queued");
|
|
47
|
+
const known = (id) => {
|
|
48
|
+
const e = entries.get(id);
|
|
49
|
+
if (!e)
|
|
50
|
+
throw refused("not-found", `command ${id} is not known to this agent`);
|
|
51
|
+
return e;
|
|
52
|
+
};
|
|
53
|
+
function end(e, state) {
|
|
54
|
+
e.state = state;
|
|
55
|
+
ended.push(e.id);
|
|
56
|
+
while (ended.length > ENDED_COMMANDS_KEPT)
|
|
57
|
+
entries.delete(ended.shift());
|
|
58
|
+
}
|
|
59
|
+
async function list() {
|
|
60
|
+
if (!dispatcher)
|
|
61
|
+
return { supported: false };
|
|
62
|
+
let listed;
|
|
63
|
+
try {
|
|
64
|
+
listed = await within(() => dispatcher.list(), COMMAND_LIST_MS);
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
throw refused("unavailable", `the harness did not list its commands: ${e.message}`);
|
|
68
|
+
}
|
|
69
|
+
if (!Array.isArray(listed))
|
|
70
|
+
throw refused("internal", "the connector's list is not an array");
|
|
71
|
+
const commands = [];
|
|
72
|
+
for (const e of listed) {
|
|
73
|
+
if (!isAgentCommandName(e?.name))
|
|
74
|
+
continue;
|
|
75
|
+
if (!dispatcher.targets.has(e.target))
|
|
76
|
+
throw refused("internal", `the connector listed the ${String(e.target)} "${e.name}" but runs no ${String(e.target)}s`);
|
|
77
|
+
const description = fitText(e.description, AGENT_COMMAND_DESCRIPTION_MAX), inputHint = fitText(e.inputHint, AGENT_COMMAND_INPUT_HINT_MAX);
|
|
78
|
+
commands.push({ name: e.name, target: e.target, ...(description ? { description } : {}), ...(inputHint ? { inputHint } : {}) });
|
|
79
|
+
}
|
|
80
|
+
if (commands.length > AGENT_COMMAND_LIST_MAX)
|
|
81
|
+
throw refused("resource-exhausted", `the harness lists ${commands.length} commands and skills, over the ${AGENT_COMMAND_LIST_MAX} a reply carries`);
|
|
82
|
+
return { supported: true, commands };
|
|
83
|
+
}
|
|
84
|
+
function run(input) {
|
|
85
|
+
if (!dispatcher)
|
|
86
|
+
throw refused("unimplemented", "this agent's connector runs no commands or skills");
|
|
87
|
+
if (!dispatcher.targets.has(input.target))
|
|
88
|
+
throw refused("unimplemented", `this agent's connector runs no ${input.target}s`);
|
|
89
|
+
if (closed)
|
|
90
|
+
throw refused("unavailable", "this agent is stopping");
|
|
91
|
+
if (queued().length >= MAX_QUEUED_COMMANDS)
|
|
92
|
+
throw refused("resource-exhausted", `${MAX_QUEUED_COMMANDS} commands are already queued`);
|
|
93
|
+
let id;
|
|
94
|
+
do
|
|
95
|
+
id = Array.from(randomBytes(26), (b) => B32[b & 31]).join("");
|
|
96
|
+
while (entries.has(id));
|
|
97
|
+
entries.set(id, { id, command: { target: input.target, name: input.name, args: input.args ?? "" }, state: { kind: "queued" } });
|
|
98
|
+
onQueued();
|
|
99
|
+
return { id };
|
|
100
|
+
}
|
|
101
|
+
function cancel({ id }) {
|
|
102
|
+
const e = known(id);
|
|
103
|
+
if (e.state.kind === "queued")
|
|
104
|
+
end(e, { kind: "cancelled" });
|
|
105
|
+
else if (e.state.kind !== "cancelled")
|
|
106
|
+
throw new EpEnvelopeError("conflict", `command ${id} is ${e.state.kind}, so it can no longer be cancelled`, [{ kind: AGENT_COMMAND_STATE_DETAIL, state: e.state }], "not-executed");
|
|
107
|
+
return { state: e.state };
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
handlers: [
|
|
111
|
+
{ command: "commands", contract: AGENT_CONTRACTS.commands, handler: () => list() },
|
|
112
|
+
{ command: "command", contract: AGENT_CONTRACTS.command, handler: (ctx) => run(ctx.request.args) },
|
|
113
|
+
{ command: "command-cancel", contract: AGENT_CONTRACTS["command-cancel"], handler: (ctx) => cancel(ctx.request.args) },
|
|
114
|
+
{ command: "command-state", contract: AGENT_CONTRACTS["command-state"], handler: (ctx) => ({ state: known(ctx.request.args.id).state }) },
|
|
115
|
+
],
|
|
116
|
+
get queued() {
|
|
117
|
+
return queued().length;
|
|
118
|
+
},
|
|
119
|
+
async dispatchNext() {
|
|
120
|
+
const e = queued()[0];
|
|
121
|
+
if (!e)
|
|
122
|
+
return "empty";
|
|
123
|
+
e.state = { kind: "taken" };
|
|
124
|
+
try {
|
|
125
|
+
await dispatcher.dispatch(e.command);
|
|
126
|
+
end(e, { kind: "started" });
|
|
127
|
+
return "dispatched";
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
const message = String(err?.message ?? err);
|
|
131
|
+
end(e, err instanceof CommandRefused
|
|
132
|
+
? { kind: "refused", code: err.code, message: cut(message, AGENT_COMMAND_MESSAGE_MAX) }
|
|
133
|
+
: { kind: "unknown", code: "internal", message: cut(`the harness failed, so ${what(e.command)} may have started: ${message}`, AGENT_COMMAND_MESSAGE_MAX) });
|
|
134
|
+
return "failed";
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
close() {
|
|
138
|
+
closed = true;
|
|
139
|
+
for (const e of queued())
|
|
140
|
+
end(e, { kind: "refused", code: "unavailable", message: `the agent stopped before ${what(e.command)} started` });
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=agent-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-commands.js","sourceRoot":"","sources":["../src/agent-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EACL,6BAA6B,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,0BAA0B,EAC1I,eAAe,EAAE,eAAe,EAAE,kBAAkB,GAGrD,MAAM,gBAAgB,CAAC;AAExB,yEAAyE;AACzE,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AACtC,+CAA+C;AAC/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AACrC,+EAA+E;AAC/E,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAsBtC,0DAA0D;AAC1D,MAAM,OAAO,cAAe,SAAQ,KAAK;IAClB;IAArB,YAAqB,IAAyC,EAAE,OAAe;QAC7E,KAAK,CAAC,OAAO,CAAC,CAAC;QADI,SAAI,GAAJ,IAAI,CAAqC;QAE5D,IAAI,CAAC,IAAI,GAAG,gBAAg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AAO,EAAE,4BAA4B,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QAC7I,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent's own `agent` endpoint (SPEC 13.22), served once on the principal route (SPEC 13.21). A
|
|
3
|
+
* process serves an endpoint once for its lifecycle, and the served table is exactly the cluster's
|
|
4
|
+
* commands, so this module is the one owner of that serve.
|
|
5
|
+
*/
|
|
6
|
+
import type { CotalEndpoint } from "@cotal-ai/core";
|
|
7
|
+
import { type CommandDispatcher, type CommandQueue } from "./agent-commands.js";
|
|
8
|
+
import { type PromptDesk } from "./prompt-desk.js";
|
|
9
|
+
export interface AgentEndpoint {
|
|
10
|
+
/** The prompt desk, where an adapter opens its harness's dialogs. */
|
|
11
|
+
readonly prompts: PromptDesk;
|
|
12
|
+
/** The commands waiting for an idle turn, which the connector runs one per turn. */
|
|
13
|
+
readonly commands: CommandQueue;
|
|
14
|
+
/** Close every prompt and reply to every caller still waiting, refuse every queued command, then
|
|
15
|
+
* stop serving and wait for the handlers in flight. Does not wait for a `deliver` call that has
|
|
16
|
+
* not ended. */
|
|
17
|
+
close(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Serve this process's `agent` endpoint on `ep` and show the `prompts` presence field. Resolves once
|
|
21
|
+
* the broker accepted the subscription. `dispatcher` runs the agent's harness commands, and
|
|
22
|
+
* `onQueued` is told each time a command waits for a turn. Without a dispatcher, `commands` answers
|
|
23
|
+
* `supported: false` and `command` is refused.
|
|
24
|
+
*
|
|
25
|
+
* Rejects on an open mesh, under a static credential and without a lifecycle UID, when the broker
|
|
26
|
+
* refuses the subscription (a credential minted before the rows existed), and when the connection's
|
|
27
|
+
* `max_payload` is under {@link PROMPT_DESK_MIN_MAX_PAYLOAD}, which the largest prompt replies need.
|
|
28
|
+
* Then nothing is served and presence shows no `prompts` field. The same checks run on every replaced
|
|
29
|
+
* connection, and a failure there closes the endpoint and warns. Stopping `ep` ends the serve and not
|
|
30
|
+
* the prompts, so call `close()` first: it ends every prompt and gives each open dialog back.
|
|
31
|
+
*/
|
|
32
|
+
export declare function openAgentEndpoint(ep: CotalEndpoint, opts: {
|
|
33
|
+
warn(msg: string): void;
|
|
34
|
+
dispatcher?: CommandDispatcher;
|
|
35
|
+
onQueued?(): void;
|
|
36
|
+
}): Promise<AgentEndpoint>;
|
|
37
|
+
//# sourceMappingURL=agent-endpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-endpoint.d.ts","sourceRoot":"","sources":["../src/agent-endpoint.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAqB,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAiD,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAElG,MAAM,WAAW,aAAa;IAC5B,qEAAqE;IACrE,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,oFAAoF;IACpF,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC;;qBAEiB;IACjB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CACrC,EAAE,EAAE,aAAa,EACjB,IAAI,EAAE;IAAE,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAAC,QAAQ,CAAC,IAAI,IAAI,CAAA;CAAE,GACnF,OAAO,CAAC,aAAa,CAAC,CA+CxB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createCommandLane } from "./agent-commands.js";
|
|
2
|
+
import { PROMPT_DESK_MIN_MAX_PAYLOAD, createPromptDesk } from "./prompt-desk.js";
|
|
3
|
+
/**
|
|
4
|
+
* Serve this process's `agent` endpoint on `ep` and show the `prompts` presence field. Resolves once
|
|
5
|
+
* the broker accepted the subscription. `dispatcher` runs the agent's harness commands, and
|
|
6
|
+
* `onQueued` is told each time a command waits for a turn. Without a dispatcher, `commands` answers
|
|
7
|
+
* `supported: false` and `command` is refused.
|
|
8
|
+
*
|
|
9
|
+
* Rejects on an open mesh, under a static credential and without a lifecycle UID, when the broker
|
|
10
|
+
* refuses the subscription (a credential minted before the rows existed), and when the connection's
|
|
11
|
+
* `max_payload` is under {@link PROMPT_DESK_MIN_MAX_PAYLOAD}, which the largest prompt replies need.
|
|
12
|
+
* Then nothing is served and presence shows no `prompts` field. The same checks run on every replaced
|
|
13
|
+
* connection, and a failure there closes the endpoint and warns. Stopping `ep` ends the serve and not
|
|
14
|
+
* the prompts, so call `close()` first: it ends every prompt and gives each open dialog back.
|
|
15
|
+
*/
|
|
16
|
+
export async function openAgentEndpoint(ep, opts) {
|
|
17
|
+
if (typeof opts?.warn !== "function")
|
|
18
|
+
throw new TypeError("openAgentEndpoint needs opts.warn");
|
|
19
|
+
const max = ep.maxPayload;
|
|
20
|
+
if (max < PROMPT_DESK_MIN_MAX_PAYLOAD)
|
|
21
|
+
throw new Error(`the agent endpoint needs a connection whose max_payload is at least ${PROMPT_DESK_MIN_MAX_PAYLOAD} bytes, and this one is ${max}`);
|
|
22
|
+
const warn = (msg) => {
|
|
23
|
+
try {
|
|
24
|
+
opts.warn(msg);
|
|
25
|
+
}
|
|
26
|
+
catch { /* a logger that throws stops nothing */ }
|
|
27
|
+
};
|
|
28
|
+
const desk = createPromptDesk(ep, warn);
|
|
29
|
+
const lane = createCommandLane(opts.dispatcher, opts.onQueued ?? (() => { }));
|
|
30
|
+
const serve = ep.servePrincipal({ handlers: [...desk.handlers(), ...lane.handlers] });
|
|
31
|
+
desk.served(serve.ready);
|
|
32
|
+
let closing;
|
|
33
|
+
const close = () => (closing ??= (() => {
|
|
34
|
+
ep.off("transport", onTransport);
|
|
35
|
+
desk.close();
|
|
36
|
+
lane.close();
|
|
37
|
+
return serve.stop();
|
|
38
|
+
})());
|
|
39
|
+
const onTransport = (t) => {
|
|
40
|
+
if (!t.connected || closing)
|
|
41
|
+
return;
|
|
42
|
+
let now;
|
|
43
|
+
try {
|
|
44
|
+
now = ep.maxPayload;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return; // not live after all; the next connection runs the check
|
|
48
|
+
}
|
|
49
|
+
if (now >= PROMPT_DESK_MIN_MAX_PAYLOAD)
|
|
50
|
+
return;
|
|
51
|
+
warn(`the agent endpoint closed: the connection's max_payload is ${now} bytes, under the ${PROMPT_DESK_MIN_MAX_PAYLOAD} its largest replies need`);
|
|
52
|
+
void close();
|
|
53
|
+
};
|
|
54
|
+
ep.on("transport", onTransport);
|
|
55
|
+
void serve.failed.then((err) => {
|
|
56
|
+
if (closing)
|
|
57
|
+
return;
|
|
58
|
+
warn(`the agent endpoint closed: ${err.message}`);
|
|
59
|
+
void close();
|
|
60
|
+
});
|
|
61
|
+
try {
|
|
62
|
+
await serve.ready;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
void close();
|
|
66
|
+
throw e;
|
|
67
|
+
}
|
|
68
|
+
return { prompts: desk, commands: lane, close };
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=agent-endpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-endpoint.js","sourceRoot":"","sources":["../src/agent-endpoint.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAA6C,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAE,2BAA2B,EAAE,gBAAgB,EAAmB,MAAM,kBAAkB,CAAC;AAalG;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,EAAiB,EACjB,IAAoF;IAEpF,IAAI,OAAO,IA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AAC,CAAC,CAAC,SAAS,IAAI,OAAO;YAAE,OAAO;QACpC,IAAI,GAAW,CAAC;QAChB,IAAI,CAAC;YACH,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC;QACtB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,yDAAyD;QACnE,CAAC;QACD,IAAI,GAAG,IAAI,2BAA2B;YAAE,OAAO;QAC/C,IAAI,CAAC,8DAA8D,GAAG,qBAAqB,2BAA2B,2BAA2B,CAAC,CAAC;QACnJ,KAAK,KAAK,EAAE,CAAC;IACf,CAAC,CAAC;IACF,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAChC,KAAK,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;QAC7B,IAAI,OAAO;YAAE,OAAO;QACpB,IAAI,CAAC,8BAA8B,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAClD,KAAK,KAAK,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;IACH,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,KAAK,CAAC;IACpB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,KAAK,KAAK,EAAE,CAAC;QACb,MAAM,CAAC,CAAC;IACV,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { type CotalEndpoint, type CotalMessage, type Delivery } from "@cotal-ai/core";
|
|
2
|
+
import type { AgentConfig } from "./config.js";
|
|
3
|
+
/** A short reconnect or modest sender-clock skew must not turn a current request into history. */
|
|
4
|
+
export declare const CHANNEL_CATCHUP_AGE_MS: number;
|
|
5
|
+
/** The endpoint and host operations the inbox reads when each call runs. */
|
|
6
|
+
export interface AgentInboxDeps {
|
|
7
|
+
endpoint: () => CotalEndpoint;
|
|
8
|
+
config: () => AgentConfig;
|
|
9
|
+
transportConnected: () => boolean;
|
|
10
|
+
emit: (event: "incoming" | "mention-wake", item: InboxItem) => void;
|
|
11
|
+
warning: (error: Error) => void;
|
|
12
|
+
noteDirected: (item: InboxItem) => void;
|
|
13
|
+
inOrder: (write: () => Promise<void>) => Promise<void>;
|
|
14
|
+
requireConnected: () => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/** A message that has arrived for us, normalized for the agent to read. */
|
|
17
|
+
export interface InboxItem {
|
|
18
|
+
id: string;
|
|
19
|
+
/** Opaque per-delivery RECEIVE key (#624): the address a host uses to drain/ack THIS buffered
|
|
20
|
+
* delivery. It is the wire `id` for every message that carries one; a message whose `id` is the
|
|
21
|
+
* empty string gets a minted key, because an empty id is never a dedup key and never a
|
|
22
|
+
* selectable one. It is NOT wire identity and NOT dedup authority: nothing coalesces on it, so
|
|
23
|
+
* a redelivered copy of an id-less message mints its own key and surfaces again (at-least-once,
|
|
24
|
+
* the disclosed cost). It exists so the exact-id drains and in-flight protection can select the
|
|
25
|
+
* DELIVERY rather than an id value that two distinct messages share. */
|
|
26
|
+
recvKey: string;
|
|
27
|
+
ts: number;
|
|
28
|
+
fromId: string;
|
|
29
|
+
fromName: string;
|
|
30
|
+
fromRole?: string;
|
|
31
|
+
kind: "channel" | "dm" | "anycast";
|
|
32
|
+
/** Set when kind === "channel". */
|
|
33
|
+
channel?: string;
|
|
34
|
+
/** Set when kind === "anycast" (the role addressed). */
|
|
35
|
+
service?: string;
|
|
36
|
+
/** Lowercased names called out on a channel message (priority hint). */
|
|
37
|
+
mentions?: string[];
|
|
38
|
+
/** True iff this message mentions us by name — computed once, here. Drives high-priority wake. */
|
|
39
|
+
mentionsMe: boolean;
|
|
40
|
+
/** True iff this is backfilled history (a "catching up" block on join), not a live message. */
|
|
41
|
+
historical: boolean;
|
|
42
|
+
text: string;
|
|
43
|
+
replyTo?: string;
|
|
44
|
+
contextId?: string;
|
|
45
|
+
/** How many times the broker has delivered this copy, 1 on the first; absent on a live copy.
|
|
46
|
+
* Broker-derived, never read from the payload: above 1, an earlier delivery of this message went
|
|
47
|
+
* unacked past its ack wait and may have run, here or on another reader. */
|
|
48
|
+
deliveryCount?: number;
|
|
49
|
+
/** Set on a DM from the space's delivery daemon about one of this session's own role requests
|
|
50
|
+
* (`anycast`, SPEC §8.1) or about a channel post whose mention the daemon could not deliver
|
|
51
|
+
* (`mention`, SPEC §8): its sender was checked against the delivery lease holder. A notice asks
|
|
52
|
+
* for no reply and answers no question. */
|
|
53
|
+
notice?: DeliveryNotice;
|
|
54
|
+
}
|
|
55
|
+
/** A bounded, non-consuming view of the currently buffered inbox for presentation-only surfaces. */
|
|
56
|
+
export interface InboxSnapshot {
|
|
57
|
+
/** Total buffered deliveries, including rows beyond {@link items}. */
|
|
58
|
+
unread: number;
|
|
59
|
+
/** Oldest buffered rows, copied without receive/ack handles. */
|
|
60
|
+
items: InboxItem[];
|
|
61
|
+
}
|
|
62
|
+
/** An inbox entry: the normalized message plus its JetStream ack handle. */
|
|
63
|
+
export interface Pending {
|
|
64
|
+
item: InboxItem;
|
|
65
|
+
/** Ack the backing stream message — called only once the item is actually surfaced. */
|
|
66
|
+
ack: () => void;
|
|
67
|
+
/** The current copy's redelivery state, and the time until which this reader can vouch it still
|
|
68
|
+
* holds that copy. Both absent on a live copy. */
|
|
69
|
+
redelivery?: Delivery["redelivery"];
|
|
70
|
+
ownedUntil?: number;
|
|
71
|
+
/** Delivery class, set at receive time. Quiet ambient stays pull-only even if the mode later
|
|
72
|
+
* changes, and an automatic entry becomes pull-only when its channel is quieted, muted or left. */
|
|
73
|
+
pullOnly: boolean;
|
|
74
|
+
/** Local receive time. Distinct from `item.ts`, which is the sender's stamp. */
|
|
75
|
+
receivedAt: number;
|
|
76
|
+
/** Its place in this session's arrival order. A held role request keeps it while held and once
|
|
77
|
+
* taken, so it is offered and shown where it arrived. */
|
|
78
|
+
arrival: number;
|
|
79
|
+
/** #662: the focus tally a buffered id-less channel message is counted in, its digest there, and
|
|
80
|
+
* the copy it is counted as. Evicting it un-counts that copy only, so recall can hand its stream
|
|
81
|
+
* copy back while an identical copy with another disposition stays counted. */
|
|
82
|
+
idless?: {
|
|
83
|
+
tally: Map<string, IdlessTally>;
|
|
84
|
+
digest: string;
|
|
85
|
+
copy: IdlessCopy;
|
|
86
|
+
};
|
|
87
|
+
/** A role request on an auth mesh (SPEC §8.1): the take of the current copy, the take in flight,
|
|
88
|
+
* and the delivery count a recorded take is for. Such an entry is shown only once its take of
|
|
89
|
+
* the copy it holds is recorded. */
|
|
90
|
+
take?: Delivery["take"];
|
|
91
|
+
taking?: Promise<void>;
|
|
92
|
+
/** The link drops counted when {@link taking} began. A take that began before the latest drop is
|
|
93
|
+
* the old link's, so a read asks again instead of waiting on it. */
|
|
94
|
+
takingDrops?: number;
|
|
95
|
+
takenCount?: number;
|
|
96
|
+
/** A take was recorded for it once, so a host may have shown it. Only such an entry is acked from
|
|
97
|
+
* the held set by an exact drain. */
|
|
98
|
+
takenOnce?: boolean;
|
|
99
|
+
/** How many reads are waiting on its take in {@link AgentInbox.takeChosen}. Such a read shows the
|
|
100
|
+
* request itself, so its admission is announced as an arrival only when no read waits. */
|
|
101
|
+
awaited?: number;
|
|
102
|
+
}
|
|
103
|
+
/** #662: the copies of one id-less channel message (by content) a focus episode has settled
|
|
104
|
+
* locally. A live copy carries no stream sequence, so recall binds each settled copy to one
|
|
105
|
+
* retained stream copy at or below its frontier the first time a read can see it, and two
|
|
106
|
+
* identical copies never share a sequence. A tally with nothing left in it is deleted. */
|
|
107
|
+
export interface IdlessTally {
|
|
108
|
+
channel: string;
|
|
109
|
+
/** Settled copies no read has bound yet. */
|
|
110
|
+
unbound: IdlessCopy[];
|
|
111
|
+
/** Stream sequences of the copies settled here or handed back. */
|
|
112
|
+
bound: Set<number>;
|
|
113
|
+
}
|
|
114
|
+
/** #662: one settled id-less copy. Its stream copy is at or below the chat stream's last sequence
|
|
115
|
+
* read after it arrived. While the connection stays up, every stream copy at or below that read
|
|
116
|
+
* reached this session before the read answered, so the read bounds no copy sent in a reconnect
|
|
117
|
+
* gap. A read that answers only after the connection dropped bounds nothing. */
|
|
118
|
+
export interface IdlessCopy {
|
|
119
|
+
/** The recall epoch it was settled in. */
|
|
120
|
+
epoch: number;
|
|
121
|
+
/** The chat stream's last sequence read after it arrived, once that read answers on the same
|
|
122
|
+
* connection. */
|
|
123
|
+
frontier?: number;
|
|
124
|
+
/** Settles when that read answers or fails. Never rejects. */
|
|
125
|
+
ready: Promise<void>;
|
|
126
|
+
/** The stream sequence a read bound it to. */
|
|
127
|
+
seq?: number;
|
|
128
|
+
/** The inbox evicted it before a read bound it. It keeps its place in arrival order, and the
|
|
129
|
+
* stream copy a read binds it to is left for recall to hand back. */
|
|
130
|
+
evicted?: boolean;
|
|
131
|
+
}
|
|
132
|
+
/** Where a session's focus-mode recall has been read to: a timestamp plus the id that breaks its ties. */
|
|
133
|
+
export interface RecallMark {
|
|
134
|
+
ts: number;
|
|
135
|
+
id: string;
|
|
136
|
+
}
|
|
137
|
+
/** Total order on {@link RecallMark}: by time, then by id, so items sharing a millisecond still queue. */
|
|
138
|
+
export declare function afterRecallMark(a: RecallMark, b: RecallMark): boolean;
|
|
139
|
+
/** How many pending messages one session buffers before the overflow valve in
|
|
140
|
+
* {@link AgentInbox.buffer} evicts. Exported so the overflow smokes read the bound they exercise. */
|
|
141
|
+
export declare const MAX_INBOX = 200;
|
|
142
|
+
/** How long {@link AgentInbox.takeChosen} waits for the delivery daemon before it lets a caller show
|
|
143
|
+
* what is already taken. A take not decided by then stays held for a later read. */
|
|
144
|
+
export declare const TAKE_WAIT_MS = 2000;
|
|
145
|
+
/** How long a role request whose take could not be decided waits before it is asked about again. */
|
|
146
|
+
export declare const TAKE_RETRY_MS = 10000;
|
|
147
|
+
/** How many receive keys {@link AgentInbox.holdInFlight} protects at once. The overflow valve never
|
|
148
|
+
* evicts a held entry, so this ceiling also bounds the inbox while holds are open, which is why it
|
|
149
|
+
* is derived from {@link MAX_INBOX}. It sits above the inbox because a frame keeps its holds until
|
|
150
|
+
* its own verdict, even on entries an overlapping frame has already committed. */
|
|
151
|
+
export declare const MAX_IN_FLIGHT: number;
|
|
152
|
+
/** How many future-stamped recall ids one session will remember having handed over. See
|
|
153
|
+
* {@link AgentInbox.recallAheadRoom}. */
|
|
154
|
+
export declare const MAX_AHEAD = 256;
|
|
155
|
+
/** How many overflow-evicted ambient messages {@link AgentInbox.evictedClassifications} remembers
|
|
156
|
+
* the class of. */
|
|
157
|
+
export declare const CLASSIFICATION_CAP = 4096;
|
|
158
|
+
/** How many ids one focus episode keeps out of recall in {@link AgentInbox.focusExcludedIds}, and,
|
|
159
|
+
* bounded separately, how many id-less copies it counts in {@link AgentInbox.focusIdlessEntries}. */
|
|
160
|
+
export declare const FOCUS_EXCLUSION_CAP = 4096;
|
|
161
|
+
/** #662: history reads one channel's recall makes while an id-less copy keeps arriving mid-read. */
|
|
162
|
+
export declare const IDLESS_READS = 3;
|
|
163
|
+
/** How many ids each of {@link AgentInbox.protectedPullOnlyIds} and
|
|
164
|
+
* {@link AgentInbox.protectedDropIds} holds. */
|
|
165
|
+
export declare const PROTECTED_DISPOSITION_CAP = 4096;
|
|
166
|
+
export type InboxScope = "all" | "automatic" | "pull-only";
|
|
167
|
+
export interface ExactDrainResult {
|
|
168
|
+
items: InboxItem[];
|
|
169
|
+
missingKeys: string[];
|
|
170
|
+
}
|
|
171
|
+
/** What a delivery daemon's notice is about. */
|
|
172
|
+
export type DeliveryNotice = "anycast" | "mention";
|
|
173
|
+
/** Which delivery daemon notice part a DM carries, anycast (SPEC §8.1) or mention (SPEC §8), if any.
|
|
174
|
+
* Its sender is still to be checked against the delivery lease. */
|
|
175
|
+
export declare function deliveryNoticeOf(m: CotalMessage): DeliveryNotice | undefined;
|
|
176
|
+
/** #662: what an id-less channel delivery shares with its stream copy. Both are the same published
|
|
177
|
+
* bytes, read through the same authentication, so their content is all that links them. */
|
|
178
|
+
export declare function idlessDigest(m: CotalMessage): string;
|
|
179
|
+
/** The dedup key a received message id contributes to ingest's coalescing, or undefined when the id
|
|
180
|
+
* is EMPTY: an empty id is never a dedup key (#624). Undefined means "no identity to coalesce on",
|
|
181
|
+
* so every id-keyed lookup in {@link AgentInbox.ingest} is skipped for such a message and it flows to
|
|
182
|
+
* the buffer on its own merits. Real ids are returned unchanged: their coalescing (live/durable
|
|
183
|
+
* copies of one message, and redelivery after handle) is untouched. */
|
|
184
|
+
export declare function ingestDedupKey(id: string): string | undefined;
|
|
185
|
+
//# sourceMappingURL=agent-inbox-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-inbox-model.d.ts","sourceRoot":"","sources":["../src/agent-inbox-model.ts"],"names":[],"mappings":"AAGA,OAAO,EAA0C,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC9H,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,kGAAkG;AAClG,eAAO,MAAM,sBAAsB,QAAa,CAAC;AAGjD,4EAA4E;AAC5E,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,aAAa,CAAC;IAC9B,MAAM,EAAE,MAAM,WAAW,CAAC;IAC1B,kBAAkB,EAAE,MAAM,OAAO,CAAC;IAClC,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,GAAG,cAAc,EAAE,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACpE,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAChC,YAAY,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAGD,2EAA2E;AAC3E,M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,MAAM,CAAC;AAC7B;qFACqF;AACrF,eAAO,MAAM,YAAY,OAAQ,CAAC;AAClC,oGAAoG;AACpG,eAAO,MAAM,aAAa,QAAS,CAAC;AACpC;;;mFAGmF;AACnF,eAAO,MAAM,aAAa,QAAgB,CAAC;AAC3C;0CAC0C;AAC1C,eAAO,MAAM,SAAS,MAAM,CAAC;AAC7B;oBACoB;AACpB,eAAO,MAAM,kBAAkB,OAAO,CAAC;AACvC;sGACsG;AACtG,eAAO,MAAM,mBAAmB,OAAO,CAAC;AACxC,oGAAoG;AACpG,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B;iDACiD;AACjD,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAE9C,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,WAAW,GAAG,WAAW,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,gDAAgD;AAChD,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,CAAC;AAEnD;oEACoE;AACpE,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,YAAY,GAAG,cAAc,GAAG,SAAS,CAO5E;AAED;4FAC4F;AAC5F,wBAAgB,YAAY,CAAC,CAAC,EAAE,YAAY,GAAG,MAAM,CAEpD;AAED;;;;wEAIwE;AACxE,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE7D"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// The inbox item shapes, limits and small pure helpers the AgentInbox class works with, moved verbatim
|
|
2
|
+
// from agent-inbox.ts. agent-inbox.ts re-exports the ones other modules import, so their paths are unchanged.
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { ANYCAST_NOTICE_KEY, MENTION_NOTICE_KEY } from "@cotal-ai/core";
|
|
5
|
+
/** A short reconnect or modest sender-clock skew must not turn a current request into history. */
|
|
6
|
+
export const CHANNEL_CATCHUP_AGE_MS = 5 * 60_000;
|
|
7
|
+
/** Total order on {@link RecallMark}: by time, then by id, so items sharing a millisecond still queue. */
|
|
8
|
+
export function afterRecallMark(a, b) {
|
|
9
|
+
// #624: recall marks and items are addressed by RECEIVE key (never the wire id), and a minted
|
|
10
|
+
// key is never the empty string, so the tie-break comparator never sees an empty id on either
|
|
11
|
+
// side: the only empty id in a RecallMark is the initial cursor {ts: 0, id: ""}, whose ts
|
|
12
|
+
// differs from every real item and so never reaches the id comparison. (The empty-id guard this
|
|
13
|
+
// comparator once carried was removed after a root chase showed it unreachable: with the wire id
|
|
14
|
+
// out of the marks, no real path can put two empty ids, or an empty id against a real one, into
|
|
15
|
+
// the comparison.)
|
|
16
|
+
return a.ts !== b.ts ? a.ts > b.ts : a.id > b.id;
|
|
17
|
+
}
|
|
18
|
+
/** How many pending messages one session buffers before the overflow valve in
|
|
19
|
+
* {@link AgentInbox.buffer} evicts. Exported so the overflow smokes read the bound they exercise. */
|
|
20
|
+
export const MAX_INBOX = 200;
|
|
21
|
+
/** How long {@link AgentInbox.takeChosen} waits for the delivery daemon before it lets a caller show
|
|
22
|
+
* what is already taken. A take not decided by then stays held for a later read. */
|
|
23
|
+
export const TAKE_WAIT_MS = 2_000;
|
|
24
|
+
/** How long a role request whose take could not be decided waits before it is asked about again. */
|
|
25
|
+
export const TAKE_RETRY_MS = 10_000;
|
|
26
|
+
/** How many receive keys {@link AgentInbox.holdInFlight} protects at once. The overflow valve never
|
|
27
|
+
* evicts a held entry, so this ceiling also bounds the inbox while holds are open, which is why it
|
|
28
|
+
* is derived from {@link MAX_INBOX}. It sits above the inbox because a frame keeps its holds until
|
|
29
|
+
* its own verdict, even on entries an overlapping frame has already committed. */
|
|
30
|
+
export const MAX_IN_FLIGHT = MAX_INBOX * 2;
|
|
31
|
+
/** How many future-stamped recall ids one session will remember having handed over. See
|
|
32
|
+
* {@link AgentInbox.recallAheadRoom}. */
|
|
33
|
+
export const MAX_AHEAD = 256;
|
|
34
|
+
/** How many overflow-evicted ambient messages {@link AgentInbox.evictedClassifications} remembers
|
|
35
|
+
* the class of. */
|
|
36
|
+
export const CLASSIFICATION_CAP = 4096;
|
|
37
|
+
/** How many ids one focus episode keeps out of recall in {@link AgentInbox.focusExcludedIds}, and,
|
|
38
|
+
* bounded separately, how many id-less copies it counts in {@link AgentInbox.focusIdlessEntries}. */
|
|
39
|
+
export const FOCUS_EXCLUSION_CAP = 4096;
|
|
40
|
+
/** #662: history reads one channel's recall makes while an id-less copy keeps arriving mid-read. */
|
|
41
|
+
export const IDLESS_READS = 3;
|
|
42
|
+
/** How many ids each of {@link AgentInbox.protectedPullOnlyIds} and
|
|
43
|
+
* {@link AgentInbox.protectedDropIds} holds. */
|
|
44
|
+
export const PROTECTED_DISPOSITION_CAP = 4096;
|
|
45
|
+
/** Which delivery daemon notice part a DM carries, anycast (SPEC §8.1) or mention (SPEC §8), if any.
|
|
46
|
+
* Its sender is still to be checked against the delivery lease. */
|
|
47
|
+
export function deliveryNoticeOf(m) {
|
|
48
|
+
for (const p of m.parts) {
|
|
49
|
+
if (p.kind !== "data" || typeof p.data !== "object" || p.data === null || Array.isArray(p.data))
|
|
50
|
+
continue;
|
|
51
|
+
if (ANYCAST_NOTICE_KEY in p.data)
|
|
52
|
+
return "anycast";
|
|
53
|
+
if (MENTION_NOTICE_KEY in p.data)
|
|
54
|
+
return "mention";
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
/** #662: what an id-less channel delivery shares with its stream copy. Both are the same published
|
|
59
|
+
* bytes, read through the same authentication, so their content is all that links them. */
|
|
60
|
+
export function idlessDigest(m) {
|
|
61
|
+
return createHash("sha256").update(JSON.stringify(m)).digest("base64url");
|
|
62
|
+
}
|
|
63
|
+
/** The dedup key a received message id contributes to ingest's coalescing, or undefined when the id
|
|
64
|
+
* is EMPTY: an empty id is never a dedup key (#624). Undefined means "no identity to coalesce on",
|
|
65
|
+
* so every id-keyed lookup in {@link AgentInbox.ingest} is skipped for such a message and it flows to
|
|
66
|
+
* the buffer on its own merits. Real ids are returned unchanged: their coalescing (live/durable
|
|
67
|
+
* copies of one message, and redelivery after handle) is untouched. */
|
|
68
|
+
export function ingestDedupKey(id) {
|
|
69
|
+
return id === "" ? undefined : id;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=agent-inbox-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-inbox-model.js","sourceRoot":"","sources":["../src/agent-inbox-model.ts"],"names":[],"mappings":"AAAA,uGAAuG;AACvG,8GAA8G;AAC9G,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAwD,MAAM,gBAAgB,CAAC;AAG9H,kGAAkG;AAClG,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAG,MAAM,CAAC;AA2IjD,0GAA0G;AAC1G,MAAM,UAAU,eAAe,CAAC,CAAa,EAAE,CAAa;IAC1D,8FAA8F;IAC9F,8FAA8F;IAC9F,0FAA0F;IAC1F,gGAAgG;IAChG,iGAAiG;IACjG,gGAAgG;IAChG,mBAAmB;IACnB,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;AACnD,CAAC;AAED;sGACsG;AACtG,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAC;AAC7B;qFACqF;AACrF,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;AAClC,oGAAoG;AACpG,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AACpC;;;mFAGmF;AACnF,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,GAAG,CAAC,CAAC;AAC3C;0CAC0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