omni-notify-mcp 1.3.472 → 1.3.476
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/gateway/mcpDoor.js +5 -5
- package/dist/gateway/restDoor.js +2 -2
- package/dist/gateway/terminalDoor.js +1 -1
- package/dist/gatewayInstall.cjs +59 -59
- package/dist/notify.js +35 -7
- package/dist/shared/agentSession.js +38 -6
- package/dist/shared/conversation/conversations.js +46 -12
- package/dist/shared/conversation/providerProof.js +75 -0
- package/dist/shared/webhost/autoSwitch.cjs +10 -3
- package/package.json +1 -1
- package/scripts/shared/ownerGuard.cs +665 -0
- package/scripts/shared/ownerGuard.ps1 +31 -0
package/dist/gateway/mcpDoor.js
CHANGED
|
@@ -232,8 +232,8 @@ function buildServer(caller, base, offer) {
|
|
|
232
232
|
const target = conversation !== undefined ? seen(conversation) : (routes ? routeAsk(caller, text)?.id : undefined);
|
|
233
233
|
// NULL-OK: field target is OPTIONAL and therefore it is ok to check for NULL
|
|
234
234
|
const sent = target === undefined
|
|
235
|
-
? { id: (await createdOn(project, provider, () => caller, (on) => startConversation({ platform: "mcp", technical: true, chat: caller, ...on, text, receivedMs: Math.round(performance.now() - arrived), arrival }), model)).made.id, turn: 1 }
|
|
236
|
-
: { id: seen(target), turn: sendToConversation(target, text, Math.round(performance.now() - arrived), arrival).n };
|
|
235
|
+
? { id: (await createdOn(project, provider, () => caller, (on) => startConversation({ platform: "mcp", technical: true, chat: caller, ...on, text, receivedMs: Math.round(performance.now() - arrived), arrival }), model, viewerNow()?.folder)).made.id, turn: 1 }
|
|
236
|
+
: { id: seen(target), turn: sendToConversation(target, text, Math.round(performance.now() - arrived), arrival, viewerNow()?.folder).n };
|
|
237
237
|
const { events, ended, turn } = await waitForTurn(sent.id, sent.turn, MAX_WAIT_SECONDS);
|
|
238
238
|
const meta = readConversation(sent.id);
|
|
239
239
|
const reply = events.filter((e) => e.turn === turn && REPLY_FIELD[e.kind] !== undefined).at(-1);
|
|
@@ -263,16 +263,16 @@ function buildServer(caller, base, offer) {
|
|
|
263
263
|
server.tool("agent_start", `Creates a new conversation AND submits text as its first task (turn 1) in one call, and returns {id, state} at once without waiting for the agent. The way to run a long or autonomous task: read its progress and answer with agent_wait {id, after:1, wait:${MAX_WAIT_SECONDS}}, again with the after each reply returned, until an event of kind answer or failed with turn 1, or of kind stopped, arrives. The task is already submitted, so do not also agent_send the same text, and do not call agent_start again for it — each call starts another agent on the task. agent_prompt sends and waits in one blocking call instead.`, { project: projectField(offer).optional().describe(`The workspace this conversation runs in: exactly one of ${offer.either}, resolved under ${offer.under}; no path is accepted. Leave it out and the conversation runs at the workspace root (${offer.under}) with every project's rules, which route the request to its project; it is never resolved from the text`), text: z.string().min(1).describe("The first task, submitted by this call itself"), provider: z.string().min(1).optional().describe(`The agent CLI this conversation runs: exactly one of ${PROVIDER_NAMES.join(", ")}. Use auto or omit it for the shared subscription-first choice. A permitted funded key is considered once eligible subscriptions are exhausted`), model: z.string().min(1).optional() }, ({ project, text, provider, model }) => act(async () => {
|
|
264
264
|
const arrived = performance.now();
|
|
265
265
|
const arrival = arrivalOf(requestIdOf(), randomUUID().slice(0, 8));
|
|
266
|
-
const meta = (await createdOn(project, provider, () => caller, (on) => startConversation({ platform: "mcp", technical: true, chat: caller, ...on, text, receivedMs: Math.round(performance.now() - arrived), arrival }), model)).made;
|
|
266
|
+
const meta = (await createdOn(project, provider, () => caller, (on) => startConversation({ platform: "mcp", technical: true, chat: caller, ...on, text, receivedMs: Math.round(performance.now() - arrived), arrival }), model, viewerNow()?.folder)).made;
|
|
267
267
|
return { id: meta.id, state: meta.state };
|
|
268
268
|
}));
|
|
269
269
|
server.tool("agent_open", `Opens a new conversation with no message and starts no agent: no text, no process started and nothing spent. It returns {id, state} at once. It names the workspace and the agent CLI the conversation opens on — project and provider are both optional: a conversation with no project runs at the workspace root, whose rules route each request to its project, and one with no provider runs on the agent CLI whose subscription has room. Ask it with agent_send and read it with agent_wait; the folder can be switched afterwards with agent_project, and the conversation keeps its id and its whole transcript.`, { project: projectField(offer).optional().describe(`Exactly one of ${offer.either}, resolved under ${offer.under}; no path is accepted. Leave it out for the workspace root (${offer.under}), where the rules of every project route the request; it is never resolved from anything else`), provider: z.string().min(1).optional().describe(`The agent CLI the conversation runs: exactly one of ${PROVIDER_NAMES.join(", ")}. Use auto or omit it for the shared subscription-first choice. A permitted funded key is considered once eligible subscriptions are exhausted`), model: z.string().min(1).optional() }, ({ project, provider, model }) => act(async () => {
|
|
270
|
-
const meta = (await createdOn(project, provider, () => caller, (on) => openConversation({ platform: "mcp", technical: true, chat: caller, ...on }), model)).made;
|
|
270
|
+
const meta = (await createdOn(project, provider, () => caller, (on) => openConversation({ platform: "mcp", technical: true, chat: caller, ...on }), model, viewerNow()?.folder)).made;
|
|
271
271
|
return { id: meta.id, state: meta.state };
|
|
272
272
|
}));
|
|
273
273
|
server.tool("agent_send", `Sends a message to a conversation that already exists (agent_start or agent_prompt made it) and returns {n} at once without waiting for the agent. n is the message's position in the log and the number of the turn it starts: read its answer with agent_wait {id, after:n, wait:${MAX_WAIT_SECONDS}}. A message sent while a turn runs is queued behind that turn, not an interrupt — also while a conversation's agent waits on a question on its own CLI screen, which the user answers there by opening the conversation in BN, never by a message to it. A stopped or archived conversation resumes. Each call submits its text once more, so do not repeat a send that returned.`, { id: z.string().min(1).describe("The conversation id agent_start returned, or the 'conversation' agent_prompt returned"), text: z.string().min(1).describe("The follow-up message; the first task belongs in agent_start") }, ({ id, text }) => act(() => {
|
|
274
274
|
const arrived = performance.now();
|
|
275
|
-
return { n: sendToConversation(seen(id), text, Math.round(performance.now() - arrived), arrivalOf(requestIdOf(), randomUUID().slice(0, 8))).n };
|
|
275
|
+
return { n: sendToConversation(seen(id), text, Math.round(performance.now() - arrived), arrivalOf(requestIdOf(), randomUUID().slice(0, 8)), viewerNow()?.folder).n };
|
|
276
276
|
}));
|
|
277
277
|
server.tool("agent_wait", `Reads a conversation's events past position 'after' — a long-poll read the caller repeats, not a notification BN pushes. With wait=0 (the default) it returns at once with whatever is there; with wait above 0 it holds the call until a new event arrives or the wait (at most ${MAX_WAIT_SECONDS} seconds) runs out, and an empty events list means nothing new yet. Repeat the call with the reply's after value (the position it leaves you at, a line it wrote itself included) until the turn you wait on ends: an event of kind answer or failed whose turn is that turn's number (1 after agent_start, the n agent_send returned), or an event of kind stopped. A question the agent asks does not end the turn: a status event says it waits on its own CLI screen, and the turn goes on once the user answers there. after=0 reads the log from the start, earlier turns' answers included. The state is not the end of the turn, because a conversation stays running until its idle process is freed. Reading sends nothing, so it is always safe to call again. Each answer or failed event carries its timing, in which a reply's time is three separate figures rather than one number: bnMs, the end-to-end elapsed time from the request arriving at BN's door to the answer being stored; queuedMs (beside queued, whether it stood in line at all — false is the store's own statement that it never stood in line, absent is unmeasured), the part of it the message waited for a free slot or the turn ahead; and agentMs, the part the agent itself worked. totalMs is BN's own total from the message being stored to the answer being stored, never the agent's time, and rows carries the turn layer by layer.`, { id: z.string().min(1), after: z.number().int().min(0).default(0).describe("The last event position n already read; events past it are returned. 1 right after agent_start, the n agent_send returned after a send"), wait: z.number().min(0).default(0).describe(`Seconds to hold the call for a new event, capped at ${MAX_WAIT_SECONDS}; 0 returns at once`) }, ({ id, after, wait }) => {
|
|
278
278
|
const arrived = performance.now();
|
package/dist/gateway/restDoor.js
CHANGED
|
@@ -175,7 +175,7 @@ async function route(req, url, arrivedAt) {
|
|
|
175
175
|
receivedMs = monotonicMs() - arrivedAt;
|
|
176
176
|
const chat = creatorOf(viewer, on.project);
|
|
177
177
|
return text === undefined ? openConversation({ platform: "rest", chat, ...on }) : startConversation({ platform: "rest", chat, ...on, text, receivedMs });
|
|
178
|
-
}, model);
|
|
178
|
+
}, model, viewer?.folder);
|
|
179
179
|
return { status: 201, body: { id: meta.id, state: meta.state, receivedMs } };
|
|
180
180
|
}
|
|
181
181
|
}
|
|
@@ -201,7 +201,7 @@ async function route(req, url, arrivedAt) {
|
|
|
201
201
|
else if (sub === "messages" && method === "POST") {
|
|
202
202
|
const text = requiredText(await readJson(req), "text");
|
|
203
203
|
const receivedMs = monotonicMs() - arrivedAt;
|
|
204
|
-
const event = sendToConversation(id, text, receivedMs);
|
|
204
|
+
const event = sendToConversation(id, text, receivedMs, undefined, viewer?.folder);
|
|
205
205
|
return { status: 202, body: { n: event.n, receivedMs } };
|
|
206
206
|
}
|
|
207
207
|
else if (sub === "events" && method === "GET") {
|
|
@@ -183,7 +183,7 @@ async function newAgent(body, viewer) {
|
|
|
183
183
|
const model = typeof body.model === "string" && body.model.trim() ? body.model.trim() : undefined;
|
|
184
184
|
if (model !== undefined && !/^[a-zA-Z0-9._:/-]+$/.test(model))
|
|
185
185
|
throw new GatewayError(400, "Model must be its CLI name, without spaces or shell characters.");
|
|
186
|
-
return (await createdOn(body.project, body.provider, (folder) => creatorOf(viewer, folder), (on) => openConversation({ platform: "rest", chat: creatorOf(viewer, on.project), ...on }), model)).made.id;
|
|
186
|
+
return (await createdOn(body.project, body.provider, (folder) => creatorOf(viewer, folder), (on) => openConversation({ platform: "rest", chat: creatorOf(viewer, on.project), ...on }), model, viewer?.folder)).made.id;
|
|
187
187
|
}
|
|
188
188
|
/** The conversation's own CLI, opened by the session driver — never a second one — once it is running, or the reason this machine could not start it. */
|
|
189
189
|
async function opened(id) {
|
package/dist/gatewayInstall.cjs
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const { spawn } = require("child_process");
|
|
6
|
-
|
|
7
|
-
const DOMAIN = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/i;
|
|
8
|
-
|
|
9
|
-
function deployArgs({ deploy, domain, preview, projectRoot, home, doorsDir }) {
|
|
10
|
-
return [
|
|
11
|
-
deploy,
|
|
12
|
-
"--domain", domain,
|
|
13
|
-
...(preview ? ["--new-install", "--dry-run"] : ["--new-install"]),
|
|
14
|
-
// NULL-OK: field projectRoot is OPTIONAL and therefore it is ok to check for NULL
|
|
15
|
-
"--project-root", projectRoot ?? home,
|
|
16
|
-
"--security-dir", path.join(home, ".notify-mcp", "gateway", "security"),
|
|
17
|
-
"--notify-dir", doorsDir,
|
|
18
|
-
];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function runDeploy({ node, args, cwd, env, onOutput }) {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
const child = spawn(node, args, { windowsHide: true, cwd, env });
|
|
24
|
-
child.stdout.on("data", (chunk) => onOutput(String(chunk)));
|
|
25
|
-
child.stderr.on("data", (chunk) => onOutput(String(chunk)));
|
|
26
|
-
child.on("error", reject);
|
|
27
|
-
child.on("exit", (exitCode, signal) => resolve({ exitCode, signal }));
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const PROMPT_ON_THE_PC = "The elevated helper is not running as this build's copy, so installing would raise one Windows administrator prompt on the PC itself, which only a person at the PC can accept. Run Set up public access from VS Code on the PC (or accept the prompt there); with the helper running, this button installs without a prompt. Preview needs no administrator.";
|
|
32
|
-
|
|
33
|
-
function writeRecord(file, record) {
|
|
34
|
-
const staged = `${file}.${process.pid}.tmp`;
|
|
35
|
-
fs.writeFileSync(staged, JSON.stringify(record, null, 2));
|
|
36
|
-
try {
|
|
37
|
-
fs.renameSync(staged, file);
|
|
38
|
-
} catch (err) {
|
|
39
|
-
fs.rmSync(staged, { force: true });
|
|
40
|
-
throw err;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function runRecorded(recordFile, recordText) {
|
|
45
|
-
const record = { ...JSON.parse(recordText), pid: process.pid };
|
|
46
|
-
const log = recordFile.replace(/\.json$/, ".log");
|
|
47
|
-
const write = (fields) => writeRecord(recordFile, { ...record, ...fields });
|
|
48
|
-
try {
|
|
49
|
-
const ended = await runDeploy({ node: process.execPath, args: record.args, cwd: record.cwd, onOutput: (text) => fs.appendFileSync(log, text) });
|
|
50
|
-
write({ endedAt: new Date().toISOString(), ...ended });
|
|
51
|
-
} catch (err) {
|
|
52
|
-
// OWNER: the detached run's trigger root — a deploy that could not be launched is written into the run's record, which the page and the MCP tool read back.
|
|
53
|
-
write({ endedAt: new Date().toISOString(), exitCode: null, failure: `the deploy could not be launched: ${err.message}` });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (require.main === module) void runRecorded(process.argv[2], process.argv[3]);
|
|
58
|
-
|
|
59
|
-
module.exports = { DOMAIN, deployArgs, runDeploy, runRecorded, writeRecord, PROMPT_ON_THE_PC };
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { spawn } = require("child_process");
|
|
6
|
+
|
|
7
|
+
const DOMAIN = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/i;
|
|
8
|
+
|
|
9
|
+
function deployArgs({ deploy, domain, preview, projectRoot, home, doorsDir }) {
|
|
10
|
+
return [
|
|
11
|
+
deploy,
|
|
12
|
+
"--domain", domain,
|
|
13
|
+
...(preview ? ["--new-install", "--dry-run"] : ["--new-install"]),
|
|
14
|
+
// NULL-OK: field projectRoot is OPTIONAL and therefore it is ok to check for NULL
|
|
15
|
+
"--project-root", projectRoot ?? home,
|
|
16
|
+
"--security-dir", path.join(home, ".notify-mcp", "gateway", "security"),
|
|
17
|
+
"--notify-dir", doorsDir,
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function runDeploy({ node, args, cwd, env, onOutput }) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const child = spawn(node, args, { windowsHide: true, cwd, env });
|
|
24
|
+
child.stdout.on("data", (chunk) => onOutput(String(chunk)));
|
|
25
|
+
child.stderr.on("data", (chunk) => onOutput(String(chunk)));
|
|
26
|
+
child.on("error", reject);
|
|
27
|
+
child.on("exit", (exitCode, signal) => resolve({ exitCode, signal }));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const PROMPT_ON_THE_PC = "The elevated helper is not running as this build's copy, so installing would raise one Windows administrator prompt on the PC itself, which only a person at the PC can accept. Run Set up public access from VS Code on the PC (or accept the prompt there); with the helper running, this button installs without a prompt. Preview needs no administrator.";
|
|
32
|
+
|
|
33
|
+
function writeRecord(file, record) {
|
|
34
|
+
const staged = `${file}.${process.pid}.tmp`;
|
|
35
|
+
fs.writeFileSync(staged, JSON.stringify(record, null, 2));
|
|
36
|
+
try {
|
|
37
|
+
fs.renameSync(staged, file);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
fs.rmSync(staged, { force: true });
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function runRecorded(recordFile, recordText) {
|
|
45
|
+
const record = { ...JSON.parse(recordText), pid: process.pid };
|
|
46
|
+
const log = recordFile.replace(/\.json$/, ".log");
|
|
47
|
+
const write = (fields) => writeRecord(recordFile, { ...record, ...fields });
|
|
48
|
+
try {
|
|
49
|
+
const ended = await runDeploy({ node: process.execPath, args: record.args, cwd: record.cwd, onOutput: (text) => fs.appendFileSync(log, text) });
|
|
50
|
+
write({ endedAt: new Date().toISOString(), ...ended });
|
|
51
|
+
} catch (err) {
|
|
52
|
+
// OWNER: the detached run's trigger root — a deploy that could not be launched is written into the run's record, which the page and the MCP tool read back.
|
|
53
|
+
write({ endedAt: new Date().toISOString(), exitCode: null, failure: `the deploy could not be launched: ${err.message}` });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (require.main === module) void runRecorded(process.argv[2], process.argv[3]);
|
|
58
|
+
|
|
59
|
+
module.exports = { DOMAIN, deployArgs, runDeploy, runRecorded, writeRecord, PROMPT_ON_THE_PC };
|
package/dist/notify.js
CHANGED
|
@@ -2195,7 +2195,8 @@ async function pollSlackOnce(token, channel) {
|
|
|
2195
2195
|
.filter(m => !m.subtype && !m.bot_id && !m.app_id && m.user && String(m.text ?? "").trim())
|
|
2196
2196
|
.sort((a, b) => Number(a.ts) - Number(b.ts));
|
|
2197
2197
|
const isAsk = (m) => String(m.text ?? "").replace(/<@[A-Za-z0-9]+>/g, "").toLowerCase().trim().startsWith(AGENT_PREFIX);
|
|
2198
|
-
|
|
2198
|
+
// Every message meant for the agent — his own words and a '!'-prefixed ask — not bus commands or a message addressed to a connected client.
|
|
2199
|
+
const forAgent = human.filter((m) => !isSlackBusTraffic(m));
|
|
2199
2200
|
// Meni is found before anything is taken off the channel, so a users.list that fails for a moment throws here and every message is read again; a poll with no human message and no open agent thread never asks.
|
|
2200
2201
|
let owner;
|
|
2201
2202
|
try {
|
|
@@ -2206,9 +2207,11 @@ async function pollSlackOnce(token, channel) {
|
|
|
2206
2207
|
catch (err) {
|
|
2207
2208
|
if (!(err instanceof SlackOwnerUnknown) && !(err instanceof SlackRefused && err.error === "missing_scope"))
|
|
2208
2209
|
throw err;
|
|
2209
|
-
// OWNER: the agent answers only Meni, and Slack will not name him until the app holds users:read — no
|
|
2210
|
-
if (err.message !== slackOwnerRefusal)
|
|
2211
|
-
log("·", "agent:slack", `${
|
|
2210
|
+
// OWNER: the agent answers only Meni, and Slack will not name him until the app holds users:read — no message of his is answered, the reason is said once in the channel and logged once, and the bus goes on.
|
|
2211
|
+
if (err.message !== slackOwnerRefusal) {
|
|
2212
|
+
log("·", "agent:slack", `${forAgent.length} message(s) in ${channel} not answered: ${err.message}`);
|
|
2213
|
+
await reply(`⚠️ Nothing you post in this channel reaches an agent — ${err.message}. Tap Reinstall in BN once that is fixed.`);
|
|
2214
|
+
}
|
|
2212
2215
|
slackOwnerRefusal = err.message;
|
|
2213
2216
|
}
|
|
2214
2217
|
for (const m of human) {
|
|
@@ -2216,12 +2219,16 @@ async function pollSlackOnce(token, channel) {
|
|
|
2216
2219
|
try {
|
|
2217
2220
|
// NULL-OK: field owner is OPTIONAL and therefore it is ok to check for NULL
|
|
2218
2221
|
if (isAsk(m)) {
|
|
2222
|
+
// NULL-OK: field owner is OPTIONAL and therefore it is ok to check for NULL
|
|
2219
2223
|
if (owner !== undefined)
|
|
2220
2224
|
await answerSlackAgentMessage(token, channel, m, owner);
|
|
2221
2225
|
}
|
|
2222
2226
|
// NULL-OK: field owner is OPTIONAL and therefore it is ok to check for NULL
|
|
2223
2227
|
else if (owner !== undefined && m.user === owner && !isSlackBusTraffic(m))
|
|
2224
2228
|
takeSlackDmMessage(slackChannelChat(token, channel), owner, m);
|
|
2229
|
+
// The owner is unknown, so his words cannot be told apart from anyone else's and are answered by nobody — the channel already says why; never the misleading "No agents connected" reply.
|
|
2230
|
+
else if (owner === undefined && !isSlackBusTraffic(m))
|
|
2231
|
+
continue;
|
|
2225
2232
|
else
|
|
2226
2233
|
await routeSlackInbox(m, reply);
|
|
2227
2234
|
}
|
|
@@ -2283,14 +2290,35 @@ const slackThreadCursor = (channel, threadTs) => POLL_CURSORS.cursor(`${SLACK_TH
|
|
|
2283
2290
|
const slackDms = new Map();
|
|
2284
2291
|
/** Why the direct message cannot be read with this bot token; it is not tried again until the token changes or BN restarts. */
|
|
2285
2292
|
let slackDmOff;
|
|
2286
|
-
/**
|
|
2293
|
+
/** The direct-message channel of the workspace owner: Slack's conversations.open once the app holds im:write, else opened by a post to his user id (chat:write alone) that is deleted at once, so his chat is left exactly as it was — no greeting, and the DM still works on a workspace that never granted im:write. */
|
|
2294
|
+
async function openSlackDm(token, owner) {
|
|
2295
|
+
try {
|
|
2296
|
+
return String((await slackCall(SLACK_API_BASE, token, "conversations.open", { users: owner })).channel.id);
|
|
2297
|
+
}
|
|
2298
|
+
catch (err) {
|
|
2299
|
+
if (!(err instanceof SlackRefused) || err.error !== "missing_scope")
|
|
2300
|
+
throw err;
|
|
2301
|
+
}
|
|
2302
|
+
const opened = await slackCall(SLACK_API_BASE, token, "chat.postMessage", { channel: owner, text: "." });
|
|
2303
|
+
const channel = String(opened.channel);
|
|
2304
|
+
try {
|
|
2305
|
+
await slackCall(SLACK_API_BASE, token, "chat.delete", { channel, ts: String(opened.ts) });
|
|
2306
|
+
}
|
|
2307
|
+
catch (err) {
|
|
2308
|
+
// OWNER: a Slack documented refusal or an unreachable Slack when deleting the opener must not cost him the whole direct message — the failure is logged and the DM is opened with the opener line left in place.
|
|
2309
|
+
if (!(err instanceof SlackRefused) && !(err instanceof SlackUnreachable) && !(err instanceof SlackUnknown))
|
|
2310
|
+
throw err;
|
|
2311
|
+
log("·", "slack:error", `the Slack direct message was opened by a post that could not be deleted: ${err.message}`);
|
|
2312
|
+
}
|
|
2313
|
+
return channel;
|
|
2314
|
+
}
|
|
2315
|
+
/** Meni's direct-message chat with the bot: the workspace owner's, opened once per token, its conversation keyed by the channel id. */
|
|
2287
2316
|
async function slackDmOf(token, owner) {
|
|
2288
2317
|
const known = slackDms.get(token);
|
|
2289
2318
|
// NULL-OK: field known is OPTIONAL and therefore it is ok to check for NULL
|
|
2290
2319
|
if (known !== undefined)
|
|
2291
2320
|
return known;
|
|
2292
|
-
const
|
|
2293
|
-
const dm = new SlackMessenger(SLACK_API_BASE, token, String(opened.channel.id), slackSwitchedOn, undefined, undefined, (line) => log("→", "agent:slack", line), slackTappable);
|
|
2321
|
+
const dm = new SlackMessenger(SLACK_API_BASE, token, await openSlackDm(token, owner), slackSwitchedOn, undefined, undefined, (line) => log("→", "agent:slack", line), slackTappable);
|
|
2294
2322
|
slackDms.set(token, dm);
|
|
2295
2323
|
// The thread views post with the token they were made with: a new bot token starts them afresh.
|
|
2296
2324
|
slackThreadViews.clear();
|
|
@@ -4194,6 +4194,41 @@ function movedWords(moved) {
|
|
|
4194
4194
|
/** 🔴 #4123 — a parked worker's idle process is stopped at once, and a stop that did not take is tried again only after its wait. */
|
|
4195
4195
|
// NULL-OK: field stoppedAt is OPTIONAL and therefore it is ok to check for NULL
|
|
4196
4196
|
const stopDue = (worker, now) => worker.stoppedAt === undefined || now >= worker.stoppedAt + wakeDelayMs(worker.wakes ?? 0);
|
|
4197
|
+
/**
|
|
4198
|
+
* 🔴 #4559/#4587 — THE RUNNING LANE A CUT OF PRIORITY `cutPri` PAUSES, or undefined when none can be: the lowest priority first and never one above the
|
|
4199
|
+
* cut's own ({@link PRI_ORDER}), then the least progress — the lane's living number, tool steps a minute — then the newest start; and only a worker whose
|
|
4200
|
+
* stop is asked at its next tool call, never one already pausing, parked, on another box, or ended by ⛔ Kill, so nothing is ever killed and the cut is never
|
|
4201
|
+
* itself. ONE chooser, so a ⚡ Force start and a BN chat's request that reaches the queue from outside it pick the same lane.
|
|
4202
|
+
*/
|
|
4203
|
+
export function yieldLaneFor(entries, cutStoryId, cutPri, progress) {
|
|
4204
|
+
const rank = (x) => rankIn(PRI_ORDER, x.pri);
|
|
4205
|
+
const cut = rankIn(PRI_ORDER, cutPri);
|
|
4206
|
+
const pausable = (x) => x.storyId !== cutStoryId && x.state === "running" && x.handStop === undefined && x.worker !== undefined && x.worker.parkedAt === undefined && x.worker.box === undefined && stopRouteOf(x.worker).stop === "asked" && rank(x) >= cut;
|
|
4207
|
+
return entries.filter(pausable).sort((a, b) => rank(b) - rank(a) || progress(a.storyId) - progress(b.storyId) || b.worker.startedAt - a.worker.startedAt)[0];
|
|
4208
|
+
}
|
|
4209
|
+
/**
|
|
4210
|
+
* 🔴 #4587 items 8–11 — A REQUEST THAT REACHES THE QUEUE FROM OUTSIDE IT TAKES ITS SLOT, THE WORKING LANE IS PUT BACK INTACT. A BN chat's lane works a story
|
|
4211
|
+
* of this board directly (outside the queue), so FleetView injects it as a first-class queue row ({@link gateStoryHolders}) and, once that lane takes the
|
|
4212
|
+
* workspace past its lane limit, pauses the lane this request outranks that has made the least progress — the SAME pause a ⚡ Force start makes
|
|
4213
|
+
* ({@link yieldLaneFor}), never a second preemption. The paused lane keeps its story, its worktree, its branch and its worker's own session, goes back in line
|
|
4214
|
+
* with exactly the progress it had, and is woken in its own session when a lane frees. Answers what it did, in words naming both lanes.
|
|
4215
|
+
*/
|
|
4216
|
+
export async function yieldLaneForRequest(board, storyId, pri, progress, now, by) {
|
|
4217
|
+
return withQueueLock(board, now, async () => {
|
|
4218
|
+
const store = readQueueStore(board);
|
|
4219
|
+
const lane = yieldLaneFor(store.entries, storyId, pri, progress);
|
|
4220
|
+
// NULL-OK: field lane is OPTIONAL and therefore it is ok to check for NULL
|
|
4221
|
+
if (lane === undefined)
|
|
4222
|
+
return `#${storyId} (${pri}) takes a lane from no running lane — none on this board is of its priority or lower with a stop asked at its next step`;
|
|
4223
|
+
lane.handStop = { at: now, by, yieldFor: storyId };
|
|
4224
|
+
delete lane.pauseCancelled;
|
|
4225
|
+
const known = progress(lane.storyId);
|
|
4226
|
+
lane.why = `${stopNamed(lane.handStop)}: #${storyId} (${pri}) outranks it and takes its lane, and it is the ${lane.pri} lane with the least progress (${Number.isFinite(known) ? `${known.toFixed(1)} tool steps a minute` : "no transcript reading"}) — its worker ${lane.worker.jobId} is asked to finish its step, write its progress and end its turn, then it keeps its worktree, its branch and its session, goes back in line and is woken in its own session`;
|
|
4227
|
+
step(lane, now, "stop-asked", lane.why);
|
|
4228
|
+
writeStore(board, store);
|
|
4229
|
+
return `#${storyId} (${pri}) takes the lane of #${lane.storyId}, the ${lane.pri} lane with the least progress — its worker ${lane.worker.jobId} is paused at its next step and put back in the queue with its worktree, branch and progress kept`;
|
|
4230
|
+
});
|
|
4231
|
+
}
|
|
4197
4232
|
/**
|
|
4198
4233
|
* 🔴 ONE PASS OF FLEETVIEW'S STORY QUEUE ON ONE BOARD, under its lock: every request derived from the board's startable read is applied,
|
|
4199
4234
|
* every worker is checked (a story shipped closes its entry; a worker that ended with the story still open is started
|
|
@@ -5043,12 +5078,9 @@ async function passHeld(board, world, now) {
|
|
|
5043
5078
|
// NULL-OK: field short is OPTIONAL and therefore it is ok to check for NULL
|
|
5044
5079
|
if (!overLimit && short === undefined)
|
|
5045
5080
|
return;
|
|
5046
|
-
const rank = (x) => rankIn(PRI_ORDER, x.pri);
|
|
5047
5081
|
// NULL-OK: field progressOf is OPTIONAL and therefore it is ok to check for NULL
|
|
5048
|
-
const progress = (
|
|
5049
|
-
|
|
5050
|
-
const pausable = (x) => x !== cut && x.state === "running" && x.handStop === undefined && x.worker !== undefined && x.worker.parkedAt === undefined && x.worker.box === undefined && stopRouteOf(x.worker).stop === "asked" && rank(x) >= rank(cut);
|
|
5051
|
-
const lane = store.entries.filter(pausable).sort((a, b) => rank(b) - rank(a) || progress(a) - progress(b) || b.worker.startedAt - a.worker.startedAt)[0];
|
|
5082
|
+
const progress = (storyId) => world.progressOf?.(storyId) ?? Number.POSITIVE_INFINITY;
|
|
5083
|
+
const lane = yieldLaneFor(store.entries, cut.storyId, cut.pri, progress);
|
|
5052
5084
|
const over = overLimit ? `${running} lanes run past this workspace's limit of ${lanes.limit}` : short.why;
|
|
5053
5085
|
// NULL-OK: field lane is OPTIONAL and therefore it is ok to check for NULL
|
|
5054
5086
|
if (lane === undefined) {
|
|
@@ -5057,7 +5089,7 @@ async function passHeld(board, world, now) {
|
|
|
5057
5089
|
}
|
|
5058
5090
|
lane.handStop = { at: now, by: `${by} ⚡ Force start of #${cut.storyId}`, yieldFor: cut.storyId };
|
|
5059
5091
|
delete lane.pauseCancelled;
|
|
5060
|
-
const known = progress(lane);
|
|
5092
|
+
const known = progress(lane.storyId);
|
|
5061
5093
|
lane.why = `${stopNamed(lane.handStop)}: ${over}, and it is the ${lane.pri} lane with the least progress (${Number.isFinite(known) ? `${known.toFixed(1)} tool steps a minute` : "no transcript reading"}) — its worker ${lane.worker.jobId} is asked to finish its step, write its progress and end its turn, then it waits in line and is woken in its own session`;
|
|
5062
5094
|
step(lane, now, "stop-asked", lane.why);
|
|
5063
5095
|
step(cut, now, "started", `its ⚡ Force start runs past the limit (${over}), so #${lane.storyId}, the ${lane.pri} lane with the least progress, is paused at its next step for it`);
|
|
@@ -15,7 +15,8 @@ import { EventEmitter } from "events";
|
|
|
15
15
|
import { homedir } from "os";
|
|
16
16
|
import { basename, dirname, join, resolve } from "path";
|
|
17
17
|
import autoSwitch from "../webhost/autoSwitch.cjs";
|
|
18
|
-
import {
|
|
18
|
+
import { proveStartProviders } from "./providerProof.js";
|
|
19
|
+
import { sameRoot, workspacesFile, workspacesHere } from "../webhost/workspaceList.js";
|
|
19
20
|
import { CLUSTER_OWNER, OwnershipUnreadable, startOwnerOf } from "../providerOwnership.js";
|
|
20
21
|
/** Thrown for a request the caller got wrong; the door turns it into the status code. */
|
|
21
22
|
export class GatewayError extends Error {
|
|
@@ -682,6 +683,18 @@ export function createConversationStore(host, registry) {
|
|
|
682
683
|
const boards = listed.filter((p) => hasBoard(p.folder)).map((p) => p.name);
|
|
683
684
|
return projectFolder(projectNamedIn(text, boards) ?? homeProject(listed.map((p) => p.name), boards));
|
|
684
685
|
}
|
|
686
|
+
/**
|
|
687
|
+
* 🔴 #4587 — THE WORKSPACE A CONVERSATION BELONGS TO, from the folder its CLI runs in and the workspace its caller named as its own scope. The folder wins when it IS a listed
|
|
688
|
+
* workspace (the caller named a project, so its work is that project's); otherwise the caller's scope is it (a scoped caller that named no project runs at the workspace root,
|
|
689
|
+
* ABOVE every project); otherwise NONE — a machine-wide conversation belonging to no single workspace is said honestly, never written as the bare workspace root, which carries
|
|
690
|
+
* no board. This is the ONE value a conversation's lane is placed on, so every door shares it and no reader has to guess a board from a folder that has none.
|
|
691
|
+
*
|
|
692
|
+
* The listed workspaces come from `projectsHere()`, never `workspacesHere()` directly: a workspace list that is missing or unreadable is refused as `GatewayError(503)` — the SAME refusal
|
|
693
|
+
* every other create and turn path gives — rather than thrown raw as a `SyntaxError` the caller has no words for, and a test's own `NOTIFY_AGENT_PROJECTS` stands here exactly as it does there.
|
|
694
|
+
*/
|
|
695
|
+
function conversationWorkspace(project, scope) {
|
|
696
|
+
return projectsHere().map((p) => p.folder).find((folder) => sameRoot(folder, project)) ?? scope;
|
|
697
|
+
}
|
|
685
698
|
/**
|
|
686
699
|
* The workspace a session is CREATED in, from the name its creation supplied (#3640): exactly one of the allowed project
|
|
687
700
|
* names, resolved to its folder. A creation that names none runs at the workspace root (#4157), where the root's rules
|
|
@@ -722,12 +735,21 @@ export function createConversationStore(host, registry) {
|
|
|
722
735
|
* The agent CLI a session is CREATED on (#3640): the one its creation named, or — named none (#4157) — the shared
|
|
723
736
|
* subscription-first pick (`autoProvider`, the one FleetView's AUTO runs) over every CLI this gateway runs — at the
|
|
724
737
|
* workspace root only those that load every project's rules there — weighed by DeepAgent's `provider_room` read for the folder.
|
|
738
|
+
*
|
|
739
|
+
* #4621 — AND PINGED FIRST, BY CONSTRUCTION. A provider that reads roomy is not a provider that ANSWERS. The ping rides
|
|
740
|
+
* the ONE reading every picker already takes (`readProviderRooms` asks DeepAgent's door with `prove: true`, and the shared
|
|
741
|
+
* reading treats a provider whose route did not answer as `out`), so this pick — and FleetView's queue and any other app's
|
|
742
|
+
* picker over the same reading — skip a route that does not answer with no second check here. A provider he NAMED by hand
|
|
743
|
+
* takes no room read, so it is proved directly and a refusal is said plainly, never silently swapped for another CLI.
|
|
725
744
|
*/
|
|
726
745
|
async function pickedCli(provider, folder, model) {
|
|
727
746
|
if (provider !== undefined && provider !== "auto" && !(typeof provider === "string" && provider.trim() === "")) {
|
|
728
747
|
const named = namedProvider(provider);
|
|
729
748
|
if (heldElsewhere(host.startOwner, named))
|
|
730
749
|
throw heldBy(host.startOwner, named);
|
|
750
|
+
const [proof] = await proveStartProviders(folder, [named], deepagentDoor());
|
|
751
|
+
if (proof !== undefined && proof.state === "failed")
|
|
752
|
+
throw new GatewayError(503, `${named} does not answer now — ${proof.line}. Your choice was not replaced with another CLI: pick a different provider, or repair this one in DeepAgent, and start again.`);
|
|
731
753
|
return { provider: named };
|
|
732
754
|
}
|
|
733
755
|
const startable = (isRootFolder(folder) ? registry().names.filter((name) => registry().get(name).routesAtRoot === true) : registry().names).filter((name) => !heldElsewhere(host.startOwner, name));
|
|
@@ -749,11 +771,13 @@ export function createConversationStore(host, registry) {
|
|
|
749
771
|
home: homedir(),
|
|
750
772
|
usesKey: (name) => registry().get(name)?.usesKey?.(folder, model) ?? false,
|
|
751
773
|
});
|
|
774
|
+
// #4621 — a provider whose route the ping refused reads `out` on its own reading, so the pick has already moved past it; name every refusal so a start that lands nowhere says why.
|
|
775
|
+
const refused = Object.entries(rooms).flatMap(([id, r]) => (r?.proof?.state === "failed" ? [`${id} does not answer now — ${r.proof.line}`] : []));
|
|
752
776
|
if (picked === undefined)
|
|
753
|
-
throw new GatewayError(503, "Auto has no subscription with room and no permitted, funded key for the eligible CLIs.");
|
|
777
|
+
throw new GatewayError(503, refused.length > 0 ? `no agent CLI answers now: ${refused.join("; ")}` : "Auto has no subscription with room and no permitted, funded key for the eligible CLIs.");
|
|
754
778
|
const unread = [...new Set(Object.values(rooms).flatMap((r) => (r?.state === "unread" ? [r.reason] : [])))];
|
|
755
779
|
const words = Object.entries(rooms).map(([id, r]) => `${id} ${r?.state}`).join(", ") + (unread.length === 0 ? "" : ` — unread: ${unread.join("; ")}`);
|
|
756
|
-
process.stderr.write(`[agent-gateway] no provider named for ${folder}: ${picked} of ${startable.join("/")}, the subscription-first pick over ${words}\n`);
|
|
780
|
+
process.stderr.write(`[agent-gateway] no provider named for ${folder}: ${picked} of ${startable.join("/")}, the subscription-first pick over ${words}${refused.length === 0 ? "" : ` — refused by the ping: ${refused.join("; ")}`}\n`);
|
|
757
781
|
return { provider: picked, ...(unreadBecause === undefined ? {} : { unreadBecause }) };
|
|
758
782
|
}
|
|
759
783
|
/** #4157 — the creations still waiting on their CLI pick, by the chat they are made for: an ask from that chat routes only once they exist, so it is never doubled beside one nor sent past it. */
|
|
@@ -775,9 +799,9 @@ export function createConversationStore(host, registry) {
|
|
|
775
799
|
* moment it is called, so an ask from that chat waits for it. A room DeepAgent could not read is written onto the session it makes, and that
|
|
776
800
|
* notice is handed back so a chat that started it hears it too.
|
|
777
801
|
*/
|
|
778
|
-
function createdIn(folder, provider, chatOf, make, model) {
|
|
802
|
+
function createdIn(folder, provider, chatOf, make, model, scope) {
|
|
779
803
|
const creation = pickedCli(provider, folder, model).then((pick) => {
|
|
780
|
-
const made = make({ project: folder, provider: pick.provider, model });
|
|
804
|
+
const made = make({ project: folder, provider: pick.provider, model, scope });
|
|
781
805
|
// NULL-OK: field unreadBecause is OPTIONAL and therefore it is ok to check for NULL
|
|
782
806
|
if (pick.unreadBecause === undefined)
|
|
783
807
|
return { made };
|
|
@@ -801,8 +825,8 @@ export function createConversationStore(host, registry) {
|
|
|
801
825
|
});
|
|
802
826
|
}
|
|
803
827
|
/** A session CREATED on the folder and the agent CLI its creation named or left out (#3640, #4157): see `createdIn`. */
|
|
804
|
-
function createdOn(project, provider, chatOf, make, model) {
|
|
805
|
-
return createdIn(namedProject(project), provider, chatOf, make, model);
|
|
828
|
+
function createdOn(project, provider, chatOf, make, model, scope) {
|
|
829
|
+
return createdIn(namedProject(project), provider, chatOf, make, model, scope);
|
|
806
830
|
}
|
|
807
831
|
/**
|
|
808
832
|
* Refuses, in words, a conversation with no CLI of its own to open or stream (#3845, #3916): its record names an agent this gateway does not run.
|
|
@@ -830,7 +854,7 @@ export function createConversationStore(host, registry) {
|
|
|
830
854
|
// NULL-OK: field chat is OPTIONAL and therefore it is ok to check for NULL
|
|
831
855
|
const beside = input.chat === undefined ? undefined : openConversationOf(input.chat)?.id;
|
|
832
856
|
const meta = {
|
|
833
|
-
id: randomUUID(), platform: input.platform, technical: input.technical, chat: input.chat, slack: input.slack, email: input.email, project: input.project, provider: input.provider, model: input.model,
|
|
857
|
+
id: randomUUID(), platform: input.platform, technical: input.technical, chat: input.chat, slack: input.slack, email: input.email, project: input.project, workspace: input.workspace, provider: input.provider, model: input.model,
|
|
834
858
|
state: input.state, createdAt: now, updatedAt: now, lastMessageAt: now, sessionId: randomUUID(), started: false, consumed: 0, beside, forkOf: input.forkOf,
|
|
835
859
|
};
|
|
836
860
|
writeMeta(meta);
|
|
@@ -841,7 +865,8 @@ export function createConversationStore(host, registry) {
|
|
|
841
865
|
requireConversationEnabled();
|
|
842
866
|
const project = createdFolder(input.project);
|
|
843
867
|
const provider = namedProvider(input.provider);
|
|
844
|
-
const
|
|
868
|
+
const workspace = conversationWorkspace(project, input.scope);
|
|
869
|
+
const meta = newConversation({ platform: input.platform, technical: input.technical, chat: input.chat, slack: input.slack, email: input.email, project, workspace, provider, model: input.model, forkOf: input.forkOf, state: "queued" });
|
|
845
870
|
appendEvent(meta.id, { role: "user", text: input.text, receivedMs: input.receivedMs, ...input.arrival });
|
|
846
871
|
return meta;
|
|
847
872
|
}
|
|
@@ -855,7 +880,8 @@ export function createConversationStore(host, registry) {
|
|
|
855
880
|
requireConversationEnabled();
|
|
856
881
|
const project = createdFolder(input.project);
|
|
857
882
|
const provider = namedProvider(input.provider);
|
|
858
|
-
|
|
883
|
+
const workspace = conversationWorkspace(project, input.scope);
|
|
884
|
+
return newConversation({ platform: input.platform, technical: input.technical, chat: input.chat, project, workspace, provider, model: input.model, state: "idle" });
|
|
859
885
|
}
|
|
860
886
|
/**
|
|
861
887
|
* Sets or switches the folder the conversation's agent works in (#2723), reached by every door that offers it: the Web
|
|
@@ -882,14 +908,22 @@ export function createConversationStore(host, registry) {
|
|
|
882
908
|
if (meta.project !== undefined && sameFolder(meta.project, folder))
|
|
883
909
|
return meta;
|
|
884
910
|
// The record is written first: the folder the next turn runs in comes from it, so a transcript line may never claim a switch the record does not hold. `providerArchived` is cleared because a later finish must confirm the provider's archive again rather than trust a handshake from before this work.
|
|
885
|
-
const switched = updateConversation(id, { project: folder, providerArchived: undefined });
|
|
911
|
+
const switched = updateConversation(id, { project: folder, workspace: conversationWorkspace(folder, meta.workspace), providerArchived: undefined });
|
|
886
912
|
appendEvent(id, { role: "system", kind: "status", text: `📁 Project set to ${basename(folder)} — the next turn carries this same agent on in that folder.` });
|
|
887
913
|
return switched;
|
|
888
914
|
}
|
|
889
915
|
/** Appends the message; a stopped conversation is resumed first, so its next turn picks the agent's own session up where it stopped. A message stored while a turn runs gets its place in line at once, so nobody waits behind it in silence. `receivedMs` is the door's own measured wait, as in `startConversation`. */
|
|
890
|
-
function sendToConversation(id, text, receivedMs, arrival) {
|
|
916
|
+
function sendToConversation(id, text, receivedMs, arrival, scope) {
|
|
891
917
|
requireConversationEnabled();
|
|
892
918
|
resumeConversation(id);
|
|
919
|
+
// 🔴 #4587 — the conversation's workspace is refreshed from the scope its caller names, on every call that names one, so a conversation created before its workspace was recorded (or carried on from a door that names a scope) heals on its next message rather than staying on the bare workspace root for ever.
|
|
920
|
+
if (scope !== undefined) {
|
|
921
|
+
const held = readConversation(id);
|
|
922
|
+
// NULL-OK: field project is OPTIONAL and therefore it is ok to check for NULL
|
|
923
|
+
const workspace = conversationWorkspace(held.project ?? rootFolder(), scope);
|
|
924
|
+
if (workspace !== held.workspace)
|
|
925
|
+
updateConversation(id, { workspace });
|
|
926
|
+
}
|
|
893
927
|
// Read again right here, so a turn that ended while this call was arriving is not named as still running.
|
|
894
928
|
const current = readEvents(id);
|
|
895
929
|
const behind = turnInFlight(current, readConversation(id));
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4621 — THE PING GATE BEFORE AN AGENT IS CREATED.
|
|
3
|
+
*
|
|
4
|
+
* Meni: *"flawless transition between agentic provider/sub/key at all time"*. A provider's room reading
|
|
5
|
+
* (`provider_room`) says an account has room LEFT; it never says the route ANSWERS — a funded key the provider
|
|
6
|
+
* gates, a revoked login, or a provider whose tool enum refuses the client all read as room with no call ever
|
|
7
|
+
* made. So the start door pings each candidate BEFORE it creates the agent: DeepAgent runs one real model call
|
|
8
|
+
* per provider on the very combination (provider, subscription or key, model) a new agent there would run on,
|
|
9
|
+
* and this returns one row per provider saying whether it answered.
|
|
10
|
+
*
|
|
11
|
+
* A provider the call refused is dropped and the pick moves on; one DeepAgent cannot call right now (its own
|
|
12
|
+
* door gave no answer) is `untestable`, never a failure — an untaken reading is not the same as one that failed.
|
|
13
|
+
*
|
|
14
|
+
* The call goes over DeepAgent's MCP door, the same door `autoSwitch.readProviderRooms` reads room from. The
|
|
15
|
+
* address is mirrored here rather than shared because that module was held by another lane when this landed.
|
|
16
|
+
*/
|
|
17
|
+
const DEEPAGENT_MCP_URL = "http://127.0.0.1:7473/mcp";
|
|
18
|
+
// GATE: how long one `provider_prove` read may take before every row reads untestable — DeepAgent pings its
|
|
19
|
+
// providers in parallel, each bounded at its own 30s, so 45s clears the slowest single pass and no more.
|
|
20
|
+
const PROVE_READ_TIMEOUT_MS = 45_000;
|
|
21
|
+
/**
|
|
22
|
+
* Pings the named providers over DeepAgent's `provider_prove` door and returns one row each. A door that gives
|
|
23
|
+
* no answer, a non-200, or a body that is no reading makes every row `untestable` with the reason — a reading
|
|
24
|
+
* this gate could not take never silently passes a provider as working, and never blocks a start either.
|
|
25
|
+
*/
|
|
26
|
+
export async function proveStartProviders(project, providers, url) {
|
|
27
|
+
const door = url ?? DEEPAGENT_MCP_URL;
|
|
28
|
+
const everyUntestable = (why) => providers.map((provider) => ({ provider, state: "untestable", line: why }));
|
|
29
|
+
let res;
|
|
30
|
+
try {
|
|
31
|
+
res = await fetch(door, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: { "content-type": "application/json", accept: "application/json, text/event-stream", "x-deepagent-project": project },
|
|
34
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "provider_prove", arguments: { providers: [...providers] } } }),
|
|
35
|
+
signal: AbortSignal.timeout(PROVE_READ_TIMEOUT_MS),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
if (!(err instanceof TypeError) && !(err instanceof Error && err.name === "TimeoutError"))
|
|
40
|
+
throw err;
|
|
41
|
+
const cause = err instanceof Error && err.cause instanceof Error ? ` (${err.cause.message})` : "";
|
|
42
|
+
return everyUntestable(`DeepAgent's ping door at ${door} gave no answer: ${err instanceof Error ? err.message : String(err)}${cause}`);
|
|
43
|
+
}
|
|
44
|
+
if (res.status !== 200)
|
|
45
|
+
return everyUntestable(`provider_prove answered HTTP ${res.status}`);
|
|
46
|
+
let reply;
|
|
47
|
+
try {
|
|
48
|
+
reply = JSON.parse(await res.text());
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
if (!(err instanceof SyntaxError))
|
|
52
|
+
throw err;
|
|
53
|
+
return everyUntestable("provider_prove's reply is not JSON");
|
|
54
|
+
}
|
|
55
|
+
const body = reply.result?.content?.[0]?.text;
|
|
56
|
+
if (reply.result === undefined || reply.result.isError === true || typeof body !== "string") {
|
|
57
|
+
return everyUntestable(`provider_prove gave no reading: ${String(body ?? reply.error?.message ?? "").slice(0, 200)}`);
|
|
58
|
+
}
|
|
59
|
+
let reading;
|
|
60
|
+
try {
|
|
61
|
+
reading = JSON.parse(body);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
if (!(err instanceof SyntaxError))
|
|
65
|
+
throw err;
|
|
66
|
+
return everyUntestable("provider_prove's reading is not JSON");
|
|
67
|
+
}
|
|
68
|
+
const rows = Array.isArray(reading.proofs) ? reading.proofs : [];
|
|
69
|
+
return providers.map((provider) => {
|
|
70
|
+
const found = rows.find((row) => row?.provider === provider);
|
|
71
|
+
return found !== undefined && typeof found.state === "string" && typeof found.line === "string"
|
|
72
|
+
? { provider, state: found.state, line: found.line }
|
|
73
|
+
: { provider, state: "untestable", line: "provider_prove did not answer for this provider" };
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -551,7 +551,7 @@ class RoomReadError extends Error {
|
|
|
551
551
|
/**
|
|
552
552
|
* @typedef {{ label: string, roomPct: number | undefined, resetsAt: number | undefined, refused: boolean, unread?: string }} AccountRoom
|
|
553
553
|
* @typedef {{ label: string, funds: string }} KeyRoom
|
|
554
|
-
* @typedef {{ live?: string, accounts?: AccountRoom[], keys?: KeyRoom[] }} RoomDetail
|
|
554
|
+
* @typedef {{ live?: string, accounts?: AccountRoom[], keys?: KeyRoom[], proof?: { state: string, line: string } }} RoomDetail
|
|
555
555
|
* @typedef {({ state: "room" } | { state: "out", resetsAtMs: number | undefined } | { state: "unread", reason: string }) & RoomDetail} RoomReading
|
|
556
556
|
* @typedef {Partial<Record<string, RoomReading>>} ProviderRooms
|
|
557
557
|
*/
|
|
@@ -569,7 +569,9 @@ function roomDetailOf(provider, keys, id) {
|
|
|
569
569
|
}));
|
|
570
570
|
// NULL-OK: field keys is OPTIONAL and therefore it is ok to check for NULL
|
|
571
571
|
const runs = keys === undefined ? {} : { keys: keys.filter((k) => Array.isArray(k.agents) && k.agents.includes(id)).map((k) => ({ label: String(k.label ?? k.id), funds: String(k.funds) })) };
|
|
572
|
-
|
|
572
|
+
// #4621 — the one real call that proved this provider's live route, carried onto the reading so a picker that lands elsewhere can say WHY.
|
|
573
|
+
const proof = provider.proof && typeof provider.proof.state === "string" ? { proof: { state: String(provider.proof.state), line: String(provider.proof.line ?? "") } } : {};
|
|
574
|
+
return { ...(typeof provider.live === "string" ? { live: provider.live } : {}), accounts, ...runs, ...proof };
|
|
573
575
|
}
|
|
574
576
|
/** @param {string} provider */
|
|
575
577
|
function runsOnKeys(provider) {
|
|
@@ -635,6 +637,11 @@ function roomReadingOf(provider, now, keys, id) {
|
|
|
635
637
|
}
|
|
636
638
|
const accounts = provider.accounts;
|
|
637
639
|
const detail = roomDetailOf(provider, keys, id);
|
|
640
|
+
// #4621 — A PROVIDER THAT DID NOT ANSWER IS NOT ROOM, whatever its room says: the ping gate, folded into the ONE
|
|
641
|
+
// reading every picker already takes, so a route that refuses a real call is never picked — by construction, with
|
|
642
|
+
// no second check in any door. `state: "out"` is what every picker already treats as "not this one".
|
|
643
|
+
if (provider.proof && provider.proof.state === "failed")
|
|
644
|
+
return { state: "out", resetsAtMs: undefined, ...detail };
|
|
638
645
|
if (accounts.some((a) => a.state === "read" && a.refused !== true && (a.unlimited === true || (typeof a.roomPct === "number" && a.roomPct > 0))))
|
|
639
646
|
return { state: "room", ...detail };
|
|
640
647
|
if (accounts.length === 0 || !accounts.every((a) => a.state === "read" && typeof a.roomPct === "number"))
|
|
@@ -698,7 +705,7 @@ async function roomDoorAnswer(url, project) {
|
|
|
698
705
|
const res = await fetch(url, {
|
|
699
706
|
method: "POST",
|
|
700
707
|
headers: { "content-type": "application/json", accept: "application/json, text/event-stream", "x-deepagent-project": project },
|
|
701
|
-
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "provider_room", arguments: {} } }),
|
|
708
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "provider_room", arguments: { prove: true } } }),
|
|
702
709
|
signal: AbortSignal.timeout(ROOM_READ_TIMEOUT_MS),
|
|
703
710
|
});
|
|
704
711
|
return { status: res.status, body: await res.text() };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omni-notify-mcp",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.476",
|
|
4
4
|
"homepage": "https://www.npmjs.com/package/omni-notify-mcp",
|
|
5
5
|
"description": "Reach your AI agents from anywhere — and let them reach you. One resident process on 127.0.0.1:7475 serves the whole tool surface to Claude Code, GitHub Copilot Chat and Codex: desktop, Telegram, Slack, ntfy, Discord, Teams and SMS are configured in one file, and agents notify you when long work finishes or a decision is needed, ask you a question and wait for your answer, and receive and reply to the messages you send them — with Do Not Disturb and idle detection deciding what actually gets through.",
|
|
6
6
|
"main": "dist/daemon.js",
|