omni-notify-mcp 1.3.490 → 1.3.491
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/agentGateway.js +5 -4
- package/dist/daemon.js +37 -1
- package/dist/gateway/restDoor.js +36 -13
- package/dist/messaging/messenger.js +21 -1
- package/package.json +1 -1
package/dist/agentGateway.js
CHANGED
|
@@ -385,6 +385,8 @@ class TranscriptTail {
|
|
|
385
385
|
file;
|
|
386
386
|
offset = 0;
|
|
387
387
|
rest = "";
|
|
388
|
+
/** When the turn began: a transcript found only after it began — a resumed or forked session's file is written whole, history first — is read from its start, so only an entry stamped from this time on is this turn's (#4927). */
|
|
389
|
+
since = Date.now();
|
|
388
390
|
timer;
|
|
389
391
|
/** Why the transcript could not be read on the last tick, named once until a read succeeds again. */
|
|
390
392
|
unread;
|
|
@@ -470,7 +472,7 @@ class TranscriptTail {
|
|
|
470
472
|
this.log(`transcript ${this.sessionId}: a line is not JSON (${err.message}) — it is left out of the chat's preview`);
|
|
471
473
|
return;
|
|
472
474
|
}
|
|
473
|
-
if (!Array.isArray(entry.message?.content))
|
|
475
|
+
if (!Array.isArray(entry.message?.content) || typeof entry.timestamp !== "string" || Date.parse(entry.timestamp) < this.since)
|
|
474
476
|
return;
|
|
475
477
|
for (const block of entry.message.content) {
|
|
476
478
|
if (entry.type === "assistant" && block.type === "text" && typeof block.text === "string")
|
|
@@ -498,8 +500,7 @@ export function streamedChat(messenger, log) {
|
|
|
498
500
|
return {
|
|
499
501
|
say: async (text) => { await messenger.send(text); },
|
|
500
502
|
turn(turn) {
|
|
501
|
-
const
|
|
502
|
-
const reply = new StreamedReply(chat, log);
|
|
503
|
+
const reply = new StreamedReply(messenger, log);
|
|
503
504
|
let tail;
|
|
504
505
|
const ended = () => {
|
|
505
506
|
// NULL-OK: field tail is OPTIONAL and therefore it is ok to check for NULL
|
|
@@ -555,7 +556,7 @@ export function streamedChat(messenger, log) {
|
|
|
555
556
|
case "restored":
|
|
556
557
|
return;
|
|
557
558
|
default:
|
|
558
|
-
await
|
|
559
|
+
await messenger.send(event.text);
|
|
559
560
|
return;
|
|
560
561
|
}
|
|
561
562
|
},
|
package/dist/daemon.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* inbox files under the config dir: nothing is held only in its memory, so a restart of this process loses no message.
|
|
10
10
|
*/
|
|
11
11
|
import { spawn } from "child_process";
|
|
12
|
-
import { existsSync, readFileSync, mkdirSync } from "fs";
|
|
12
|
+
import { createWriteStream, existsSync, readFileSync, mkdirSync, renameSync } from "fs";
|
|
13
13
|
import { join } from "path";
|
|
14
14
|
import { fileURLToPath } from "url";
|
|
15
15
|
import { DAEMON_BEAT_PATH, CONFIG_DIR, DAEMON_TAG, PACKAGE_VERSION, startNotifyServer, takePendingInbox, writeRecordFile, yieldGateway } from "./notify.js";
|
|
@@ -84,10 +84,46 @@ if (stoppedByHand()) {
|
|
|
84
84
|
console.log("[BOOT] BullseyeNotify daemon — a Stop was pressed on this machine; nothing started, and nothing beats until Start is pressed in the panel or the machine reboots.");
|
|
85
85
|
process.exit(0);
|
|
86
86
|
}
|
|
87
|
+
/** Where this daemon's console goes as well as to its own (#4927): every owner starts it with no console kept, so its output is otherwise lost. Each run begins the file and moves the run before it to the previous file, which that run, a build handing over, goes on writing — so the hand-over and the crash before a start both read whole. */
|
|
88
|
+
const LOG_FILE = join(CONFIG_DIR, "bn-daemon.log");
|
|
89
|
+
const PREVIOUS_LOG_FILE = join(CONFIG_DIR, "bn-daemon.previous.log");
|
|
90
|
+
function keepConsole() {
|
|
91
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
92
|
+
try {
|
|
93
|
+
if (existsSync(LOG_FILE))
|
|
94
|
+
renameSync(LOG_FILE, PREVIOUS_LOG_FILE);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
if (!(err instanceof Error) || !("code" in err))
|
|
98
|
+
throw err;
|
|
99
|
+
// OWNER: the console copy is for reading afterwards — a previous file the disk will not move (locked, denied) leaves the daemon without a copy this run, named once, and it serves on.
|
|
100
|
+
process.stderr.write(`[BOOT] no console copy this run: ${LOG_FILE} could not be moved aside — ${err.message}
|
|
101
|
+
`);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const file = createWriteStream(LOG_FILE, { flags: "w" });
|
|
105
|
+
let kept = true;
|
|
106
|
+
// OWNER: the daemon's console is a copy for reading afterwards — a file the disk refuses (full, locked, denied) ends the copy, named once on the console itself, and the daemon serves on.
|
|
107
|
+
file.on("error", (err) => {
|
|
108
|
+
kept = false;
|
|
109
|
+
process.stderr.write(`[BOOT] the console copy in ${LOG_FILE} stopped — ${err.message}
|
|
110
|
+
`);
|
|
111
|
+
});
|
|
112
|
+
for (const stream of [process.stdout, process.stderr]) {
|
|
113
|
+
const write = stream.write.bind(stream);
|
|
114
|
+
stream.write = ((chunk, ...rest) => {
|
|
115
|
+
if (kept)
|
|
116
|
+
file.write(chunk);
|
|
117
|
+
return write(chunk, ...rest);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
console.log(`[BOOT] BullseyeNotify daemon pid ${process.pid} v${PACKAGE_VERSION} at ${new Date().toISOString()} — console kept in ${LOG_FILE}`);
|
|
121
|
+
}
|
|
87
122
|
// The shared hand-over (src/shared/webhost/originHandover.js ensureResidentDoor) puts a later release on the chat door: the new build is started with --takeover over an IPC channel, says it waits, and binds once this build lets the door go.
|
|
88
123
|
const takeover = process.argv.includes("--takeover");
|
|
89
124
|
/** Whether this process writes the heartbeat: the next release only from the moment it holds the chat door, so a takeover that never lands leaves the serving build's beat alone; and a build that let the door go no longer, so the release that took it is the one beat. */
|
|
90
125
|
let beating = !takeover;
|
|
126
|
+
keepConsole();
|
|
91
127
|
// The server's own timers are unref'd, so this beat and the door hold the process until it is stopped.
|
|
92
128
|
if (beating)
|
|
93
129
|
beat();
|
package/dist/gateway/restDoor.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { spawn } from "child_process";
|
|
15
15
|
import { createHash } from "crypto";
|
|
16
|
-
import { existsSync } from "fs";
|
|
16
|
+
import { existsSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
17
17
|
import { createRequire } from "module";
|
|
18
18
|
import { isAbsolute, join, relative } from "path";
|
|
19
19
|
import { createServer, request as httpRequest } from "http";
|
|
@@ -39,7 +39,7 @@ const CLUSTER_ROUTE = /^\/v1\/(?:(?:conversations|terminals)(?:\/.*)?|projects|p
|
|
|
39
39
|
/** The header a caller names its workspace in (#4120). */
|
|
40
40
|
const SCOPE_HEADER = "x-bullseye-project";
|
|
41
41
|
/** The caller's headers AB is handed as they came (#4231 wire); the credential is replaced by the gateway bearer. */
|
|
42
|
-
const PASSED_HEADERS = [SCOPE_HEADER, "x-request-id", "content-type", "content-length", "accept", "mcp-protocol-version"];
|
|
42
|
+
const PASSED_HEADERS = [SCOPE_HEADER, "x-bn-opened-by", "x-request-id", "content-type", "content-length", "accept", "mcp-protocol-version"];
|
|
43
43
|
/** The headers of one hop, which this door's own connection sets for itself. */
|
|
44
44
|
const HOP_HEADERS = new Set(["connection", "keep-alive", "transfer-encoding"]);
|
|
45
45
|
const PLATFORMS = new Set(["telegram", "slack", "discord", "teams", "ntfy", "sms", "email"]);
|
|
@@ -178,24 +178,47 @@ function stagedLifecycle() {
|
|
|
178
178
|
throw new GatewayError(503, `BN's lifecycle is not staged at ${file} — the extension stages it at activation, so a build that never activated has none`);
|
|
179
179
|
return file;
|
|
180
180
|
}
|
|
181
|
-
/**
|
|
182
|
-
const
|
|
181
|
+
/** Where the last Start, Stop or Restart press writes what became of it (#4927): pressed, then its outcome in the row's own words, so act=state answers a press that did nothing with its reason. */
|
|
182
|
+
const LIFECYCLE_PRESS_FILE = join(CONFIG_DIR, "lifecycle-press.json");
|
|
183
|
+
/** The press itself, run in a process of its own: the row's own act, its outcome — done, refused or failed, with the row's words — written to the press file for act=state to read. */
|
|
184
|
+
const LIFECYCLE_ACTOR = `const fs = require("fs"); const [file, press, record, pressedAt] = process.argv.slice(1);
|
|
185
|
+
const write = (outcome) => { fs.writeFileSync(record + ".tmp", JSON.stringify({ press, pressedAt: Number(pressedAt), endedAt: Date.now(), ...outcome })); fs.renameSync(record + ".tmp", record); };
|
|
186
|
+
require(file).row().act(press).then((o) => write({ ok: o.ok, said: o.text }), (e) => write({ ok: false, said: String((e && e.message) || e) })).then(() => process.exit(0), () => process.exit(1));`;
|
|
183
187
|
/** A launcher that starts the actor detached and exits at once, so no live parent links the actor to this daemon: the Stop inside a Restart ends this daemon's whole process tree, and an actor still in it would die before it started BN again. */
|
|
184
188
|
const LIFECYCLE_LAUNCHER = `require("child_process").spawn(process.execPath, ["-e", ${JSON.stringify(LIFECYCLE_ACTOR)}, ...process.argv.slice(1)], { detached: true, stdio: "ignore", windowsHide: true }).unref()`;
|
|
185
189
|
/** Start, Stop and Restart end or replace the process answering this very call, so they run in a process that outlives it; the outcome is read afterwards with act=state. */
|
|
186
190
|
function pressLifecycle(file, press) {
|
|
187
191
|
return new Promise((resolve, reject) => {
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
192
|
+
const pressedAt = Date.now();
|
|
193
|
+
writePress({ press, pressedAt });
|
|
194
|
+
const unlaunched = (said) => {
|
|
195
|
+
writePress({ press, pressedAt, endedAt: Date.now(), ok: false, said });
|
|
196
|
+
reject(new GatewayError(500, said));
|
|
197
|
+
};
|
|
198
|
+
const launcher = spawn(process.execPath, ["-e", LIFECYCLE_LAUNCHER, file, press, LIFECYCLE_PRESS_FILE, String(pressedAt)], { stdio: "ignore", windowsHide: true });
|
|
199
|
+
launcher.once("error", (err) => unlaunched(`the ${press} could not be launched — ${err.message}`));
|
|
200
|
+
launcher.once("exit", (code) => (code === 0 ? resolve({ pressed: press, running: true, next: "read the outcome with bn_lifecycle act=state: its lastPress says done, or not done with the reason" }) : unlaunched(`the ${press} could not be launched — its launcher exited ${code}`)));
|
|
191
201
|
});
|
|
192
202
|
}
|
|
193
|
-
/**
|
|
203
|
+
/** The press file written whole: staged beside it and renamed over it, so act=state never reads half of it. */
|
|
204
|
+
function writePress(press) {
|
|
205
|
+
writeFileSync(`${LIFECYCLE_PRESS_FILE}.tmp`, JSON.stringify(press));
|
|
206
|
+
renameSync(`${LIFECYCLE_PRESS_FILE}.tmp`, LIFECYCLE_PRESS_FILE);
|
|
207
|
+
}
|
|
208
|
+
/** The last press and what became of it, from the press file: still running while it holds no outcome; none before the first press on this machine. */
|
|
209
|
+
function lastPress() {
|
|
210
|
+
// NULL-OK: field lifecycle-press.json is OPTIONAL and therefore it is ok to check for NULL
|
|
211
|
+
if (!existsSync(LIFECYCLE_PRESS_FILE))
|
|
212
|
+
return undefined;
|
|
213
|
+
const press = JSON.parse(readFileSync(LIFECYCLE_PRESS_FILE, "utf8"));
|
|
214
|
+
return { ...press, outcome: press.ok === undefined ? "running" : press.ok ? "done" : "not done" };
|
|
215
|
+
}
|
|
216
|
+
/** `POST /v1/lifecycle {act}`, what AB's bn_lifecycle tool runs: act=state reads the measured state with the last press and its outcome; start, stop and restart are pressed in a process that outlives this call. */
|
|
194
217
|
async function lifecycle(act) {
|
|
195
218
|
if (typeof act !== "string" || !LIFECYCLE_PRESSES.has(act))
|
|
196
219
|
throw new GatewayError(400, "act must be state, start, stop or restart");
|
|
197
220
|
const file = stagedLifecycle();
|
|
198
|
-
return act === "state" ? createRequire(file)(file).row().state() : pressLifecycle(file, act);
|
|
221
|
+
return act === "state" ? { ...(await createRequire(file)(file).row().state()), lastPress: lastPress() } : pressLifecycle(file, act);
|
|
199
222
|
}
|
|
200
223
|
/** `POST /v1/chat/reply`: one part of a chat turn AB carries back, sent on to its thread — `{replyId, platform, conversation, part, final}` — or AB's release of a settled turn's held reply, `{replyId, release: true}`. */
|
|
201
224
|
async function chatReply(body) {
|
|
@@ -219,13 +242,13 @@ async function chatReply(body) {
|
|
|
219
242
|
await AgentGateway.instance().carry(replyId, platform, conversation, part, final);
|
|
220
243
|
return {};
|
|
221
244
|
}
|
|
222
|
-
/** The relayed turn as the wire names it, `{id, n, queued,
|
|
245
|
+
/** The relayed turn as the wire names it, `{id, n, queued, provider, sessionId}`; anything else is AB's request gone wrong, refused 400. */
|
|
223
246
|
function streamedTurnOf(turn) {
|
|
224
247
|
const t = turn;
|
|
225
|
-
if (t === null || typeof t !== "object" || typeof t.id !== "string" || !Number.isInteger(t.n) || typeof t.queued !== "boolean" ||
|
|
226
|
-
throw new GatewayError(400, "turn must be {id, n, queued,
|
|
248
|
+
if (t === null || typeof t !== "object" || typeof t.id !== "string" || !Number.isInteger(t.n) || typeof t.queued !== "boolean" || typeof t.provider !== "string" || typeof t.sessionId !== "string") {
|
|
249
|
+
throw new GatewayError(400, "turn must be {id, n, queued, provider, sessionId}: the conversation, its user event, whether it waits behind another, and its CLI and session");
|
|
227
250
|
}
|
|
228
|
-
return { id: t.id, n: t.n, queued: t.queued,
|
|
251
|
+
return { id: t.id, n: t.n, queued: t.queued, provider: t.provider, sessionId: t.sessionId };
|
|
229
252
|
}
|
|
230
253
|
/** `POST /v1/chat/relay {replyId, turn, event?, close?}` (#4453): one event of a streamed turn AB relays whole to the chat its message is held with, or that turn's close. */
|
|
231
254
|
async function chatRelay(body) {
|
|
@@ -218,6 +218,12 @@ function headersOf(headers) {
|
|
|
218
218
|
headers.forEach((value, name) => { all.push(`${name}: ${value}`); });
|
|
219
219
|
return all.join("; ");
|
|
220
220
|
}
|
|
221
|
+
/** A send that went unanswered within its time-out: Telegram may have shown it, so it is never sent a second time (#4927). */
|
|
222
|
+
export class TelegramSendUnconfirmed extends Error {
|
|
223
|
+
constructor(method, timeoutMs) {
|
|
224
|
+
super(`Telegram did not answer ${method} within ${timeoutMs} ms — it may have been shown, so it is not sent again`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
221
227
|
/** An answer the Bot API documents no meaning for: carried whole so it can be read, never retried. */
|
|
222
228
|
export class TelegramUnknown extends Error {
|
|
223
229
|
constructor(method, status, body, headers) {
|
|
@@ -228,7 +234,7 @@ const DOCUMENTED_REFUSALS = new Set([400, 401, 403, 404, 409]);
|
|
|
228
234
|
// GATE: tries of one Bot API call before a network failure, a 5xx or a 429 is given up as unreachable — each wait doubles from 1 s, a 429 waits the retry_after Telegram names.
|
|
229
235
|
const TELEGRAM_TRIES = 4;
|
|
230
236
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
231
|
-
/** One Bot API call — a JSON POST, or a GET of `url` as it is when there is no body: retried on a network failure, a 5xx or a 429 (after its retry_after), refused on a documented 4xx, thrown whole on anything else. */
|
|
237
|
+
/** One Bot API call — a JSON POST, or a GET of `url` as it is when there is no body: retried on a network failure, a 5xx or a 429 (after its retry_after), refused on a documented 4xx, thrown whole on anything else. A send that timed out is never sent again: Telegram may already have shown it, and a second copy is the repeated reply (#4927), so it throws TelegramSendUnconfirmed for the sender to name once and take as sent. */
|
|
232
238
|
export async function telegramCall(url, method, body, tries = TELEGRAM_TRIES, timeoutMs = 15_000) {
|
|
233
239
|
for (let attempt = 1;; attempt++) {
|
|
234
240
|
const last = attempt >= tries;
|
|
@@ -240,6 +246,8 @@ export async function telegramCall(url, method, body, tries = TELEGRAM_TRIES, ti
|
|
|
240
246
|
catch (err) {
|
|
241
247
|
if (!(err instanceof TypeError) && !(err instanceof DOMException))
|
|
242
248
|
throw err;
|
|
249
|
+
if (body !== undefined && method.startsWith("send") && err.name === "TimeoutError")
|
|
250
|
+
throw new TelegramSendUnconfirmed(method, timeoutMs);
|
|
243
251
|
if (last)
|
|
244
252
|
throw new TelegramUnreachable(`Telegram could not be reached for ${method} after ${attempt} tries: ${err.message}`);
|
|
245
253
|
await sleep(1000 * 2 ** (attempt - 1));
|
|
@@ -341,6 +349,18 @@ export class TelegramMessenger {
|
|
|
341
349
|
}
|
|
342
350
|
/** Sends `text` in the chosen formatting; a formatting Telegram cannot parse is sent again once as plain text, and said. */
|
|
343
351
|
async formatted(method, payload, text) {
|
|
352
|
+
try {
|
|
353
|
+
return await this.formattedOnce(method, payload, text);
|
|
354
|
+
}
|
|
355
|
+
catch (err) {
|
|
356
|
+
if (!(err instanceof TelegramSendUnconfirmed))
|
|
357
|
+
throw err;
|
|
358
|
+
// OWNER: a send Telegram may already have shown is never sent twice — the repeated reply (#4927) — so it is named once on the daemon's console with its chat and taken as sent.
|
|
359
|
+
this.log(`${method} to ${this.chatId} UNCONFIRMED — ${err.message}`);
|
|
360
|
+
return undefined;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
async formattedOnce(method, payload, text) {
|
|
344
364
|
if (!this.switchedOn())
|
|
345
365
|
throw new ChannelOff("Telegram");
|
|
346
366
|
const mode = this.mode();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omni-notify-mcp",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.491",
|
|
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",
|