@mosadd/mcp 3.0.0-alpha.40 → 3.0.0-alpha.42
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/bin/mcp.js
CHANGED
|
@@ -2574,11 +2574,16 @@ async function resolveSelf(env) {
|
|
|
2574
2574
|
"Unable to resolve the current account. Set MOSADD_API_KEY (hub key) or MOSADD_USER_JWT, or run `mosadd login`."
|
|
2575
2575
|
);
|
|
2576
2576
|
}
|
|
2577
|
-
const { data, error } = await sb.from("identities").select("id, display_name").eq("user_id", u.user.id).maybeSingle();
|
|
2577
|
+
const { data, error } = await sb.from("identities").select("id, display_name, kind").eq("user_id", u.user.id).maybeSingle();
|
|
2578
2578
|
if (error || !data) {
|
|
2579
2579
|
throw new Error("This account has no mosadd identity row yet \u2014 sign in to mosadd.com once to create it.");
|
|
2580
2580
|
}
|
|
2581
|
-
return {
|
|
2581
|
+
return {
|
|
2582
|
+
id: data.id,
|
|
2583
|
+
display_name: data.display_name ?? null,
|
|
2584
|
+
user_id: u.user.id,
|
|
2585
|
+
kind: data.kind ?? null
|
|
2586
|
+
};
|
|
2582
2587
|
}
|
|
2583
2588
|
async function resolveOwnedAgentLine(env, ownerUserId, ref) {
|
|
2584
2589
|
const value = ref.trim();
|
|
@@ -2698,6 +2703,38 @@ var presenceTools = [
|
|
|
2698
2703
|
handler: comms_session_attach
|
|
2699
2704
|
}
|
|
2700
2705
|
];
|
|
2706
|
+
var lastAutoBeat = /* @__PURE__ */ new Map();
|
|
2707
|
+
var lastBindingCheck = /* @__PURE__ */ new Map();
|
|
2708
|
+
async function autoBeatFromActivity(ctx) {
|
|
2709
|
+
try {
|
|
2710
|
+
const env = readSupabaseEnv();
|
|
2711
|
+
const self = await resolveSelf(env);
|
|
2712
|
+
let lineId = null;
|
|
2713
|
+
if (self.kind === "agent") {
|
|
2714
|
+
lineId = self.id;
|
|
2715
|
+
} else if (processBindings.has(self.user_id)) {
|
|
2716
|
+
lineId = processBindings.get(self.user_id);
|
|
2717
|
+
} else {
|
|
2718
|
+
const now2 = Date.now();
|
|
2719
|
+
if (now2 - (lastBindingCheck.get(self.user_id) ?? 0) >= BEAT_MS) {
|
|
2720
|
+
lastBindingCheck.set(self.user_id, now2);
|
|
2721
|
+
const { data } = await getSupabase(env).from("mosadd_gateway_agent_binding").select("agent_identity_id, bound_at").eq("user_id", self.user_id).maybeSingle();
|
|
2722
|
+
if (data && Date.now() - new Date(data.bound_at).getTime() <= 24 * 60 * 60 * 1e3) {
|
|
2723
|
+
lineId = data.agent_identity_id;
|
|
2724
|
+
processBindings.set(self.user_id, lineId);
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
if (!lineId) return;
|
|
2729
|
+
const now = Date.now();
|
|
2730
|
+
const last = lastAutoBeat.get(lineId) ?? 0;
|
|
2731
|
+
if (now - last < BEAT_MS) return;
|
|
2732
|
+
lastAutoBeat.set(lineId, now);
|
|
2733
|
+
await beat(env, lineId, `mcp:auto (${hostname()})`, "mcp-activity");
|
|
2734
|
+
} catch (e) {
|
|
2735
|
+
ctx.log("debug", "autoBeatFromActivity skipped", { error: String(e) });
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2701
2738
|
|
|
2702
2739
|
// src/tools/embed.ts
|
|
2703
2740
|
import { z as z18 } from "zod";
|
|
@@ -3159,7 +3196,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
3159
3196
|
// package.json
|
|
3160
3197
|
var package_default = {
|
|
3161
3198
|
name: "@mosadd/mcp",
|
|
3162
|
-
version: "3.0.0-alpha.
|
|
3199
|
+
version: "3.0.0-alpha.41",
|
|
3163
3200
|
mcpName: "io.github.hei33enberg/mosadd-mcp",
|
|
3164
3201
|
description: "Model Context Protocol server for mosadd. Exposes 4 modules (mDM, mIRC, mURL, mAYL) and capabilities (mTALK, mRAG) plus comms agent-actions \u2014 84 tools \u2014 to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
|
|
3165
3202
|
homepage: "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
|
|
@@ -3419,6 +3456,7 @@ function createMosaddServer(options = {}) {
|
|
|
3419
3456
|
const parsed = tool.inputSchema.parse(input);
|
|
3420
3457
|
try {
|
|
3421
3458
|
const result = await tool.handler(parsed, ctx);
|
|
3459
|
+
void autoBeatFromActivity(ctx);
|
|
3422
3460
|
const rich = result;
|
|
3423
3461
|
if (rich && Array.isArray(rich.mcpContent)) {
|
|
3424
3462
|
return { content: rich.mcpContent };
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mosadd/mcp",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.42",
|
|
4
4
|
"mcpName": "io.github.hei33enberg/mosadd-mcp",
|
|
5
5
|
"description": "Model Context Protocol server for mosadd. Exposes 4 modules (mDM, mIRC, mURL, mAYL) and capabilities (mTALK, mRAG) plus comms agent-actions — 84 tools — to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
|
|
6
6
|
"homepage": "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"zod": "^4.3.6",
|
|
41
41
|
"@mosadd/providers": "3.0.0-alpha.27",
|
|
42
42
|
"@mosadd/crypto": "3.0.0-alpha.27",
|
|
43
|
-
"@mosadd/
|
|
44
|
-
"@mosadd/
|
|
43
|
+
"@mosadd/threat-engine": "3.0.0-alpha.28",
|
|
44
|
+
"@mosadd/protocol": "3.0.0-alpha.28"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"tsup": "^8.3.5",
|
|
@@ -17,6 +17,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
|
17
17
|
|
|
18
18
|
const IDENTITY_ID = "b228b6ae-dda6-4823-9882-40ea91ed1530";
|
|
19
19
|
const USER_ID = "b1b6c60a-f5c5-47bd-8772-9e4e387994ad";
|
|
20
|
+
const TEST_SESSION = "test-host:11111111-2222-3333-4444-555555555555";
|
|
20
21
|
const AGENT_ID = "0489d4c6-8727-442f-bf83-68747a469492";
|
|
21
22
|
|
|
22
23
|
/** Calls recorded by the fake Supabase client, so assertions read like the wire traffic. */
|
|
@@ -45,10 +46,16 @@ function makeBuilder(table: string) {
|
|
|
45
46
|
pendingDelete = true;
|
|
46
47
|
return builder;
|
|
47
48
|
},
|
|
49
|
+
// ⛔ KASOWANIE MA TERAZ DWA WARUNKI: (konto, sesja). Atrapa musi dać się złożyć w łańcuch
|
|
50
|
+
// `.delete().eq(user).eq(session)`, więc zwracany obiekt jest JEDNOCZEŚNIE budowniczym i
|
|
51
|
+
// obietnicą — inaczej test przechodziłby tylko dlatego, że atrapa nie umie tego, co produkcja.
|
|
48
52
|
eq: (_col: string, val: string) => {
|
|
49
53
|
if (pendingDelete) {
|
|
50
54
|
calls.deletes.push(val);
|
|
51
|
-
return
|
|
55
|
+
return Object.assign(
|
|
56
|
+
{ eq: (_c2: string, v2: string) => { calls.deletes.push(v2); return Promise.resolve({ error: null }); } },
|
|
57
|
+
{ then: (res: (v: { error: null }) => unknown) => Promise.resolve({ error: null }).then(res) },
|
|
58
|
+
);
|
|
52
59
|
}
|
|
53
60
|
return builder;
|
|
54
61
|
},
|
|
@@ -65,6 +72,9 @@ function makeBuilder(table: string) {
|
|
|
65
72
|
|
|
66
73
|
vi.mock("../providers/supabase.js", () => ({
|
|
67
74
|
readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
|
|
75
|
+
// Stała tożsamość sesji — deklaracja linii jest odtąd kluczowana po (konto, sesja), żeby
|
|
76
|
+
// generałowie wpięci tym samym kluczem nie odbierali sobie linii nawzajem.
|
|
77
|
+
sessionId: () => TEST_SESSION,
|
|
68
78
|
getSupabase: () => ({
|
|
69
79
|
auth: { getUser: () => Promise.resolve({ data: { user: { id: USER_ID } }, error: null }) },
|
|
70
80
|
from: (table: string) => makeBuilder(table),
|
|
@@ -145,7 +155,9 @@ describe("comms_session_attach", () => {
|
|
|
145
155
|
// Two deletes since 2026-08-26: the heartbeat row (by identity) AND the as_agent
|
|
146
156
|
// declaration in mosadd_gateway_agent_binding (by user) — a finishing session hands
|
|
147
157
|
// back EVERYTHING it could hold, so no stale declaration keeps signing later posts.
|
|
148
|
-
|
|
158
|
+
// Zwolnienie kasuje: puls linii + deklarację TEJ sesji (konto ORAZ sesja). Trzeci element to
|
|
159
|
+
// dowód, że nie kasujemy po samym koncie — bo to zabierało linię wszystkim innym generałom.
|
|
160
|
+
expect(calls.deletes).toEqual([IDENTITY_ID, USER_ID, TEST_SESSION]);
|
|
149
161
|
calls.upserts = [];
|
|
150
162
|
await vi.advanceTimersByTimeAsync(180_000);
|
|
151
163
|
expect(calls.upserts).toHaveLength(0);
|
|
@@ -10,9 +10,28 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
13
|
+
import { randomUUID } from "node:crypto";
|
|
14
|
+
import { hostname } from "node:os";
|
|
13
15
|
import { createClient, type SupabaseClient } from "@supabase/supabase-js";
|
|
14
16
|
import { loadSession, isSessionExpired } from "../config.js";
|
|
15
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Tożsamość TEGO procesu — stała przez całe życie sesji, nowa przy każdym starcie.
|
|
20
|
+
*
|
|
21
|
+
* ⛔ NIE MOŻE być pochodną konta ani hosta. Dwie sesje generałów potrafią stać na tej samej
|
|
22
|
+
* maszynie i pod tym samym kontem (box floty), więc identyfikator z hosta zlepiłby je z powrotem
|
|
23
|
+
* w jedną — czyli odtworzył dokładnie ten błąd, który to naprawia. Nazwa hosta zostaje tylko jako
|
|
24
|
+
* czytelny przedrostek do diagnostyki; o rozróżnieniu decyduje losowy ogon.
|
|
25
|
+
*/
|
|
26
|
+
let cachedSessionId: string | null = null;
|
|
27
|
+
export function sessionId(): string {
|
|
28
|
+
if (cachedSessionId) return cachedSessionId;
|
|
29
|
+
let host = "mcp";
|
|
30
|
+
try { host = (hostname() || "mcp").slice(0, 24); } catch { /* bez nazwy hosta też działa */ }
|
|
31
|
+
cachedSessionId = `${host}:${randomUUID()}`;
|
|
32
|
+
return cachedSessionId;
|
|
33
|
+
}
|
|
34
|
+
|
|
16
35
|
export interface SupabaseEnv {
|
|
17
36
|
url: string;
|
|
18
37
|
anonKey: string;
|
|
@@ -95,6 +114,13 @@ export function getSupabase(env: SupabaseEnv = readSupabaseEnv()): SupabaseClien
|
|
|
95
114
|
headers: {
|
|
96
115
|
...(env.userJwt ? { Authorization: `Bearer ${env.userJwt}` } : {}),
|
|
97
116
|
"x-mosadd-origin": "hub-gateway",
|
|
117
|
+
// ⛔ KTÓRA TO SESJA (2026-08-27, „każdy generał co chwilę gubi mózg"). Wszyscy generałowie
|
|
118
|
+
// wpinają się kluczem hub TEGO SAMEGO właściciela, więc dla serwera ich wywołania były
|
|
119
|
+
// nieodróżnialne — a deklaracja linii (`comms_session_attach as_agent`) trzymała JEDEN
|
|
120
|
+
// wiersz na konto. Skutek: kto wpiął się ostatni, odbierał linię wszystkim pozostałym, a
|
|
121
|
+
// ich posty na kanałach zaczynały wracać z 403. Ten nagłówek daje każdemu PROCESOWI własną
|
|
122
|
+
// tożsamość sesji, dzięki czemu dziewięć linii na jednym koncie nie depcze sobie po piętach.
|
|
123
|
+
"x-mosadd-session": sessionId(),
|
|
98
124
|
},
|
|
99
125
|
},
|
|
100
126
|
});
|
package/src/server.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
6
|
import { allTools } from "./tools/index.js";
|
|
7
|
+
import { autoBeatFromActivity } from "./tools/presence.js";
|
|
7
8
|
import { PKG_VERSION } from "./version.js";
|
|
8
9
|
import { SupabaseDmProvider } from "./providers/supabase-dm.js";
|
|
9
10
|
import { SupabaseVoiceProvider } from "./providers/supabase-voice.js";
|
|
@@ -103,6 +104,11 @@ export function createMosaddServer(options: MosaddServerOptions = {}) {
|
|
|
103
104
|
const parsed = tool.inputSchema.parse(input);
|
|
104
105
|
try {
|
|
105
106
|
const result = await tool.handler(parsed as never, ctx);
|
|
107
|
+
// AUTO-PAROWANIE (08-26): a LIVE session that is actually WORKING holds its line —
|
|
108
|
+
// the founder spent a week talking to cloud stand-ins because models never
|
|
109
|
+
// remembered the attach handshake. Fire-and-forget, throttled inside, never blocks
|
|
110
|
+
// the tool's own response; see autoBeatFromActivity for which line gets the beat.
|
|
111
|
+
void autoBeatFromActivity(ctx);
|
|
106
112
|
// A tool may return rich MCP content (e.g. an image frame from
|
|
107
113
|
// comms_action_frame_get) via `mcpContent`; pass it through verbatim.
|
|
108
114
|
const rich = result as { mcpContent?: unknown[] } | null;
|
package/src/tools/presence.ts
CHANGED
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
import { hostname } from "node:os";
|
|
55
55
|
import { z } from "zod";
|
|
56
56
|
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
57
|
-
import { getSupabase, readSupabaseEnv, type SupabaseEnv } from "../providers/supabase.js";
|
|
57
|
+
import { getSupabase, readSupabaseEnv, sessionId, type SupabaseEnv } from "../providers/supabase.js";
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* How often we re-stamp the row. The consumer (`agent-dm-responder`, BRIDGE_FRESH_MS) trusts a beat
|
|
@@ -104,7 +104,7 @@ async function beat(env: SupabaseEnv, identityId: string, host: string, mode: st
|
|
|
104
104
|
*/
|
|
105
105
|
async function resolveSelf(
|
|
106
106
|
env: SupabaseEnv,
|
|
107
|
-
): Promise<{ id: string; display_name: string | null; user_id: string }> {
|
|
107
|
+
): Promise<{ id: string; display_name: string | null; user_id: string; kind: string | null }> {
|
|
108
108
|
const sb = getSupabase(env);
|
|
109
109
|
const { data: u, error: ue } = await sb.auth.getUser();
|
|
110
110
|
if (ue || !u?.user) {
|
|
@@ -114,13 +114,18 @@ async function resolveSelf(
|
|
|
114
114
|
}
|
|
115
115
|
const { data, error } = await sb
|
|
116
116
|
.from("identities")
|
|
117
|
-
.select("id, display_name")
|
|
117
|
+
.select("id, display_name, kind")
|
|
118
118
|
.eq("user_id", u.user.id)
|
|
119
119
|
.maybeSingle();
|
|
120
120
|
if (error || !data) {
|
|
121
121
|
throw new Error("This account has no mosadd identity row yet — sign in to mosadd.com once to create it.");
|
|
122
122
|
}
|
|
123
|
-
return {
|
|
123
|
+
return {
|
|
124
|
+
id: data.id as string,
|
|
125
|
+
display_name: (data.display_name as string | null) ?? null,
|
|
126
|
+
user_id: u.user.id,
|
|
127
|
+
kind: (data.kind as string | null) ?? null,
|
|
128
|
+
};
|
|
124
129
|
}
|
|
125
130
|
|
|
126
131
|
/**
|
|
@@ -235,7 +240,10 @@ async function comms_session_attach(
|
|
|
235
240
|
const { error } = await sb.from("agent_bridge_heartbeat").delete().eq("identity_id", id);
|
|
236
241
|
if (error) throw new Error(`Could not release the line: ${error.message}`);
|
|
237
242
|
}
|
|
238
|
-
|
|
243
|
+
// Zwalniamy WYŁĄCZNIE deklarację TEJ sesji — kasowanie po samym koncie zabierało linię
|
|
244
|
+
// wszystkim pozostałym generałom wpiętym tym samym kluczem.
|
|
245
|
+
await sb.from("mosadd_gateway_agent_binding").delete()
|
|
246
|
+
.eq("user_id", self.user_id).eq("session_id", sessionId());
|
|
239
247
|
processBindings.delete(self.user_id);
|
|
240
248
|
ctx.log("info", "comms_session_attach: released", { identity_ids: [...toRelease] });
|
|
241
249
|
return {
|
|
@@ -269,12 +277,17 @@ async function comms_session_attach(
|
|
|
269
277
|
const { error: bindError } = await sb.from("mosadd_gateway_agent_binding").upsert(
|
|
270
278
|
{
|
|
271
279
|
user_id: self.user_id,
|
|
280
|
+
// ⛔ DEKLARACJA NALEŻY DO SESJI, NIE DO KONTA (2026-08-27). Wszyscy generałowie wpinają się
|
|
281
|
+
// kluczem tego samego właściciela, więc klucz na samym `user_id` znaczył „kto ostatni, ten
|
|
282
|
+
// zabiera linię wszystkim" — i realnie zabierał: Dyspozytor tracił prawo głosu na kanałach
|
|
283
|
+
// w chwili, gdy wpinał się kolejny generał, a jego posty wracały z 403.
|
|
284
|
+
session_id: sessionId(),
|
|
272
285
|
agent_identity_id: agent.id,
|
|
273
286
|
agent_address: agent.m0ssad_email,
|
|
274
287
|
bound_at: new Date().toISOString(),
|
|
275
288
|
bound_by_host: host,
|
|
276
289
|
},
|
|
277
|
-
{ onConflict: "user_id" },
|
|
290
|
+
{ onConflict: "user_id,session_id" },
|
|
278
291
|
);
|
|
279
292
|
if (bindError) throw new Error(`Could not declare the agent line: ${bindError.message}`);
|
|
280
293
|
processBindings.set(self.user_id, agent.id);
|
|
@@ -325,9 +338,75 @@ export const presenceTools: MosaddTool[] = [
|
|
|
325
338
|
},
|
|
326
339
|
];
|
|
327
340
|
|
|
341
|
+
/**
|
|
342
|
+
* AUTO-PAROWANIE (2026-08-26, rozkaz Króla po tygodniu „żywa sesja Dyspozytora nie jest
|
|
343
|
+
* podpięta"): the founder kept talking to cloud stand-ins because LIVE sessions never
|
|
344
|
+
* remembered to call comms_session_attach. A model cannot be relied on to remember a
|
|
345
|
+
* handshake — so the handshake stops being the model's job: the server calls THIS after
|
|
346
|
+
* every successful tool call. Any session that is actually DOING something on an agent
|
|
347
|
+
* line thereby holds that line, and the stand-in defers, with zero cooperation from the
|
|
348
|
+
* model.
|
|
349
|
+
*
|
|
350
|
+
* Which line gets the beat:
|
|
351
|
+
* · key's identity kind='agent' → its own line (the dispatcher's own key working = paired);
|
|
352
|
+
* · kind='human' WITH an as_agent declaration (processBindings, i.e. made by THIS
|
|
353
|
+
* process) → the declared agent's line;
|
|
354
|
+
* · kind='human' without a declaration → NOTHING. Guessing which of the owner's nine
|
|
355
|
+
* lines a session speaks for would be a new identity bug, and auto-claiming the
|
|
356
|
+
* OWNER's line would silence his own stand-in every time any tool runs.
|
|
357
|
+
*
|
|
358
|
+
* Throttled to one DB write per identity per BEAT_MS; failures are swallowed — presence
|
|
359
|
+
* is best-effort and must never break the tool call it rides on. Fire-and-forget by the
|
|
360
|
+
* caller (void), so it adds zero latency to the tool's own response.
|
|
361
|
+
*/
|
|
362
|
+
const lastAutoBeat = new Map<string, number>();
|
|
363
|
+
const lastBindingCheck = new Map<string, number>();
|
|
364
|
+
export async function autoBeatFromActivity(ctx: MosaddToolContext): Promise<void> {
|
|
365
|
+
try {
|
|
366
|
+
const env = readSupabaseEnv();
|
|
367
|
+
const self = await resolveSelf(env);
|
|
368
|
+
let lineId: string | null = null;
|
|
369
|
+
if (self.kind === "agent") {
|
|
370
|
+
lineId = self.id;
|
|
371
|
+
} else if (processBindings.has(self.user_id)) {
|
|
372
|
+
lineId = processBindings.get(self.user_id)!;
|
|
373
|
+
} else {
|
|
374
|
+
// Hosted gateway is serverless: a declaration made in ANOTHER invocation lives only in
|
|
375
|
+
// the DB. One throttled read per user per BEAT_MS keeps the cost of that honest.
|
|
376
|
+
const now = Date.now();
|
|
377
|
+
if (now - (lastBindingCheck.get(self.user_id) ?? 0) >= BEAT_MS) {
|
|
378
|
+
lastBindingCheck.set(self.user_id, now);
|
|
379
|
+
// ⛔ ZAWĘŻONE DO TEJ SESJI. Po 2026-08-27 na jedno konto przypada tyle wierszy, ilu
|
|
380
|
+
// generałów jest wpiętych — zapytanie o sam `user_id` z `maybeSingle()` nie tylko
|
|
381
|
+
// zwróciłoby BŁĄD przy dwóch sesjach, ale przy jednej trafiłoby w CUDZĄ deklarację i
|
|
382
|
+
// biło pulsem w nie swoją linię.
|
|
383
|
+
const { data } = await getSupabase(env)
|
|
384
|
+
.from("mosadd_gateway_agent_binding")
|
|
385
|
+
.select("agent_identity_id, bound_at")
|
|
386
|
+
.eq("user_id", self.user_id)
|
|
387
|
+
.eq("session_id", sessionId())
|
|
388
|
+
.maybeSingle();
|
|
389
|
+
if (data && Date.now() - new Date(data.bound_at as string).getTime() <= 24 * 60 * 60 * 1000) {
|
|
390
|
+
lineId = data.agent_identity_id as string;
|
|
391
|
+
processBindings.set(self.user_id, lineId);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (!lineId) return;
|
|
396
|
+
const now = Date.now();
|
|
397
|
+
const last = lastAutoBeat.get(lineId) ?? 0;
|
|
398
|
+
if (now - last < BEAT_MS) return;
|
|
399
|
+
lastAutoBeat.set(lineId, now);
|
|
400
|
+
await beat(env, lineId, `mcp:auto (${hostname()})`, "mcp-activity");
|
|
401
|
+
} catch (e) {
|
|
402
|
+
ctx.log("debug", "autoBeatFromActivity skipped", { error: String(e) });
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
328
406
|
/** Test-only: stop every keep-alive so a suite does not leak timers between cases. */
|
|
329
407
|
export function __clearAttachmentsForTest(): void {
|
|
330
408
|
for (const a of attachments.values()) clearInterval(a.timer);
|
|
331
409
|
attachments.clear();
|
|
332
410
|
processBindings.clear();
|
|
411
|
+
lastAutoBeat.clear();
|
|
333
412
|
}
|