@mosadd/mcp 3.0.0-alpha.38 → 3.0.0-alpha.39
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 +1 -1
- package/dist/{chunk-L63CG22X.js → chunk-DMQVYA7W.js} +304 -55
- package/dist/index.d.ts +26 -0
- package/dist/index.js +1 -1
- package/package.json +14 -14
- package/src/__tests__/presence.test.ts +38 -1
- package/src/server.ts +39 -7
- package/src/tools/actions.ts +4 -0
- package/src/tools/attachments.ts +8 -0
- package/src/tools/capabilities.ts +2 -0
- package/src/tools/embed.ts +2 -0
- package/src/tools/knowledge-graph.ts +8 -0
- package/src/tools/knowledge.ts +8 -0
- package/src/tools/mail-agentbox.ts +8 -0
- package/src/tools/mail-provenance.ts +2 -0
- package/src/tools/mail.ts +22 -0
- package/src/tools/mdm-as-agent.ts +4 -0
- package/src/tools/mdm-voice.ts +8 -0
- package/src/tools/mdm.ts +16 -0
- package/src/tools/mirc-edge.ts +6 -0
- package/src/tools/mirc-members.ts +20 -0
- package/src/tools/mirc-messages.ts +4 -0
- package/src/tools/mirc.ts +14 -0
- package/src/tools/mtalk.ts +10 -0
- package/src/tools/murl.ts +14 -0
- package/src/tools/presence.ts +165 -40
- package/src/tools/ptt-ingest.ts +2 -0
- package/src/tools/threat.ts +4 -0
- package/src/types.ts +27 -0
- package/LICENSE +0 -201
package/src/tools/mirc-edge.ts
CHANGED
|
@@ -165,6 +165,8 @@ async function mIRC_mint_channel_token(
|
|
|
165
165
|
export const mircEdgeTools: MosaddTool[] = [
|
|
166
166
|
{
|
|
167
167
|
name: "mIRC_mint_channel_token",
|
|
168
|
+
title: "Mint channel token",
|
|
169
|
+
annotations: { readOnlyHint: false },
|
|
168
170
|
requires: "network",
|
|
169
171
|
description:
|
|
170
172
|
"Exchange the hub key (MOSADD_API_KEY) for a short-lived (5min), channel-scoped JWT. Returns { token, expires_in, channel_id, scope }. The token is safe to hand to a browser to open a WS via `Sec-WebSocket-Protocol: mosadd.v1, bearer.<token>`. The hub key NEVER leaves the server. Use this from any server-side route (Next.js /api/chat-token, Express, etc.) before showing chat in a browser. Required by LINEAR-2675/E6 to avoid leaking the hub key into CDN access logs.",
|
|
@@ -173,6 +175,8 @@ export const mircEdgeTools: MosaddTool[] = [
|
|
|
173
175
|
},
|
|
174
176
|
{
|
|
175
177
|
name: "mIRC_send_edge",
|
|
178
|
+
title: "Send message (low-latency edge)",
|
|
179
|
+
annotations: { readOnlyHint: false },
|
|
176
180
|
requires: "network",
|
|
177
181
|
description:
|
|
178
182
|
"Send a text message into a persistent channel via the mosadd-edge Cloudflare Worker (Durable Object backend). Sub-100ms global fan-out to all WebSocket subscribers of the channel + async flush to Supabase as system-of-record (idempotent). Use this when you want native realtime push without polling. Parallel to mIRC_post_message (Supabase path); pick one per channel. Auth: MOSADD_API_KEY env (hub key).",
|
|
@@ -181,6 +185,8 @@ export const mircEdgeTools: MosaddTool[] = [
|
|
|
181
185
|
},
|
|
182
186
|
{
|
|
183
187
|
name: "mIRC_history_edge",
|
|
188
|
+
title: "Read channel history (edge)",
|
|
189
|
+
annotations: { readOnlyHint: true },
|
|
184
190
|
requires: "network",
|
|
185
191
|
description:
|
|
186
192
|
"Read the last N (max 100) messages held in the channel's Durable Object ring buffer at the edge. Hot path is the DO, not Supabase — same data lands in messages_meta via async flush, so cold reads / pagination beyond 100 should use mIRC_list_messages.",
|
|
@@ -120,6 +120,8 @@ async function invokeChannelMembers(
|
|
|
120
120
|
export const mircMembersTools: MosaddTool[] = [
|
|
121
121
|
{
|
|
122
122
|
name: "mIRC_join",
|
|
123
|
+
title: "Join channel",
|
|
124
|
+
annotations: { readOnlyHint: false },
|
|
123
125
|
requires: "network",
|
|
124
126
|
description:
|
|
125
127
|
"Join a channel as the current user. Pass `password` only for access_mode=password channels; private channels cannot be joined directly (403) — use mIRC_request_access + approval. Idempotent: an existing active member gets their membership row back (200, no 409).",
|
|
@@ -128,6 +130,8 @@ export const mircMembersTools: MosaddTool[] = [
|
|
|
128
130
|
},
|
|
129
131
|
{
|
|
130
132
|
name: "mIRC_request_access",
|
|
133
|
+
title: "Request channel access",
|
|
134
|
+
annotations: { readOnlyHint: false },
|
|
131
135
|
requires: "network",
|
|
132
136
|
description:
|
|
133
137
|
"Request access to a password/private channel (your membership goes to state=requested for an admin to approve).",
|
|
@@ -136,6 +140,8 @@ export const mircMembersTools: MosaddTool[] = [
|
|
|
136
140
|
},
|
|
137
141
|
{
|
|
138
142
|
name: "mIRC_leave",
|
|
143
|
+
title: "Leave channel",
|
|
144
|
+
annotations: { readOnlyHint: false },
|
|
139
145
|
requires: "network",
|
|
140
146
|
description: "Leave a channel as the current user. Owner cannot leave without transferring ownership first.",
|
|
141
147
|
inputSchema: mIRC_leave_input,
|
|
@@ -143,6 +149,8 @@ export const mircMembersTools: MosaddTool[] = [
|
|
|
143
149
|
},
|
|
144
150
|
{
|
|
145
151
|
name: "mIRC_approve_request",
|
|
152
|
+
title: "Approve access request",
|
|
153
|
+
annotations: { readOnlyHint: false },
|
|
146
154
|
requires: "network",
|
|
147
155
|
description:
|
|
148
156
|
"Approve a pending access request (state=requested → active). Admins / moderators / owner only. Because access requests only exist on non-open (password/private) channels, you must pass wrapped_group_key — the channel group key wrapped to the approved member's identity key.",
|
|
@@ -151,6 +159,8 @@ export const mircMembersTools: MosaddTool[] = [
|
|
|
151
159
|
},
|
|
152
160
|
{
|
|
153
161
|
name: "mIRC_reject_request",
|
|
162
|
+
title: "Reject access request",
|
|
163
|
+
annotations: { readOnlyHint: false },
|
|
154
164
|
requires: "network",
|
|
155
165
|
description: "Reject a pending access request. Admins / moderators / owner only.",
|
|
156
166
|
inputSchema: mIRC_reject_request_input,
|
|
@@ -158,6 +168,8 @@ export const mircMembersTools: MosaddTool[] = [
|
|
|
158
168
|
},
|
|
159
169
|
{
|
|
160
170
|
name: "mIRC_kick",
|
|
171
|
+
title: "Kick a member",
|
|
172
|
+
annotations: { destructiveHint: true },
|
|
161
173
|
requires: "network",
|
|
162
174
|
description:
|
|
163
175
|
"Remove a member from the channel. They can rejoin if not banned. Requires moderator+.",
|
|
@@ -166,6 +178,8 @@ export const mircMembersTools: MosaddTool[] = [
|
|
|
166
178
|
},
|
|
167
179
|
{
|
|
168
180
|
name: "mIRC_ban",
|
|
181
|
+
title: "Ban a member",
|
|
182
|
+
annotations: { destructiveHint: true },
|
|
169
183
|
requires: "network",
|
|
170
184
|
description:
|
|
171
185
|
"Ban a member from the channel. The ban is permanent until you call mIRC_unban. Requires admin+.",
|
|
@@ -174,6 +188,8 @@ export const mircMembersTools: MosaddTool[] = [
|
|
|
174
188
|
},
|
|
175
189
|
{
|
|
176
190
|
name: "mIRC_unban",
|
|
191
|
+
title: "Lift a ban",
|
|
192
|
+
annotations: { readOnlyHint: false },
|
|
177
193
|
requires: "network",
|
|
178
194
|
description: "Lift a ban. Requires admin+.",
|
|
179
195
|
inputSchema: mIRC_unban_input,
|
|
@@ -181,6 +197,8 @@ export const mircMembersTools: MosaddTool[] = [
|
|
|
181
197
|
},
|
|
182
198
|
{
|
|
183
199
|
name: "mIRC_set_role",
|
|
200
|
+
title: "Set member role",
|
|
201
|
+
annotations: { readOnlyHint: false },
|
|
184
202
|
requires: "network",
|
|
185
203
|
description:
|
|
186
204
|
"Promote / demote a member. Roles: owner(100) > superadmin(90) > admin(80) > moderator(70) > member(10). No 'guest'. An actor may assign any role below their own tier — so a superadmin (not only the owner) can promote to admin.",
|
|
@@ -189,6 +207,8 @@ export const mircMembersTools: MosaddTool[] = [
|
|
|
189
207
|
},
|
|
190
208
|
{
|
|
191
209
|
name: "mIRC_set_ptt",
|
|
210
|
+
title: "Set push-to-talk permission",
|
|
211
|
+
annotations: { readOnlyHint: false },
|
|
192
212
|
requires: "network",
|
|
193
213
|
description:
|
|
194
214
|
"Grant or revoke PTT floor permission for a member in voice-capable channels (capabilities.ptt=true). Requires moderator+.",
|
|
@@ -164,6 +164,8 @@ async function mIRC_list_messages(
|
|
|
164
164
|
export const mircMessagesTools: MosaddTool[] = [
|
|
165
165
|
{
|
|
166
166
|
name: "mIRC_post_message",
|
|
167
|
+
title: "Post channel message",
|
|
168
|
+
annotations: { readOnlyHint: false },
|
|
167
169
|
requires: "network",
|
|
168
170
|
description:
|
|
169
171
|
"Post a text message into a persistent channel (mIRC). Pass channel_id from mIRC_create / mIRC_list; the backing space is resolved automatically. This is how an agent actually talks in a channel — the other mIRC_* tools only manage it. ACCESS: banned/blocked users are refused on ALL access modes (including open); open channels accept anyone not banned; password channels require joining with the password; private channels require request-access + approval. ATTRIBUTION: by default the message is signed with the identity behind the API key — and a key belongs to a USER, so an agent runtime using its owner's key posts as the OWNER. Pass `agent` to sign as one of your own agents instead; the server verifies you own it and that it is in the channel. ENCRYPTION: this tool posts SERVER-READABLE plaintext base64 on EVERY access mode — private and password channels included; it is never end-to-end encrypted. Open channels: app clients CAN read toolkit-posted messages. Password/private channels: the mosadd.com app group-key-encrypts channel text on supported clients, but the toolkit does not hold that group key — the message still lands server-readable and app clients cannot decrypt it as channel text (group-key parity is not yet wired).",
|
|
@@ -172,6 +174,8 @@ export const mircMessagesTools: MosaddTool[] = [
|
|
|
172
174
|
},
|
|
173
175
|
{
|
|
174
176
|
name: "mIRC_list_messages",
|
|
177
|
+
title: "Read channel messages",
|
|
178
|
+
annotations: { readOnlyHint: true },
|
|
175
179
|
requires: "network",
|
|
176
180
|
description:
|
|
177
181
|
"List recent text messages in a persistent channel (mIRC), newest first, cursor-paginated. Pass channel_id; the backing space is resolved automatically.",
|
package/src/tools/mirc.ts
CHANGED
|
@@ -196,6 +196,8 @@ async function mIRC_report(
|
|
|
196
196
|
export const mircTools: MosaddTool[] = [
|
|
197
197
|
{
|
|
198
198
|
name: "mIRC_create",
|
|
199
|
+
title: "Create channel",
|
|
200
|
+
annotations: { readOnlyHint: false },
|
|
199
201
|
requires: "network",
|
|
200
202
|
description:
|
|
201
203
|
"Create a new persistent channel (Discord/Slack-style). Set access_mode to open (anyone joins), password (shared-password gated), or private (invite-only). capabilities controls modes (txt/voice/files/ptt/live; voice/ptt/live are server-relayed via LiveKit, NOT E2EE). Set discoverable:true (open channels only) to list it in the public directory. NOTE: password/private channels are provisioned for group-key TEXT encryption — supply wrapped_group_key (the group key wrapped to your identity key); open channels do not need it. The mosadd.com app encrypts/decrypts channel text with that key on supported clients; the toolkit's own mIRC_post_message posts server-readable text today (group-key parity is the next milestone). Channel voice is never E2EE.",
|
|
@@ -204,6 +206,8 @@ export const mircTools: MosaddTool[] = [
|
|
|
204
206
|
},
|
|
205
207
|
{
|
|
206
208
|
name: "mIRC_list",
|
|
209
|
+
title: "List your channels",
|
|
210
|
+
annotations: { readOnlyHint: true },
|
|
207
211
|
requires: "network",
|
|
208
212
|
description:
|
|
209
213
|
"List channels available to the current user.",
|
|
@@ -212,6 +216,8 @@ export const mircTools: MosaddTool[] = [
|
|
|
212
216
|
},
|
|
213
217
|
{
|
|
214
218
|
name: "mIRC_get",
|
|
219
|
+
title: "Get channel details",
|
|
220
|
+
annotations: { readOnlyHint: true },
|
|
215
221
|
requires: "network",
|
|
216
222
|
description: "Get full details of a single channel by id.",
|
|
217
223
|
inputSchema: mIRC_get_input,
|
|
@@ -219,6 +225,8 @@ export const mircTools: MosaddTool[] = [
|
|
|
219
225
|
},
|
|
220
226
|
{
|
|
221
227
|
name: "mIRC_update",
|
|
228
|
+
title: "Update channel settings",
|
|
229
|
+
annotations: { readOnlyHint: false },
|
|
222
230
|
requires: "network",
|
|
223
231
|
description: "Update channel metadata (name, topic, capabilities). Owner only. Access mode is fixed at creation — recreate the channel to change it.",
|
|
224
232
|
inputSchema: mIRC_update_input,
|
|
@@ -226,6 +234,8 @@ export const mircTools: MosaddTool[] = [
|
|
|
226
234
|
},
|
|
227
235
|
{
|
|
228
236
|
name: "mIRC_delete",
|
|
237
|
+
title: "Delete channel",
|
|
238
|
+
annotations: { destructiveHint: true },
|
|
229
239
|
requires: "network",
|
|
230
240
|
description: "Delete a channel and cascade-remove its members. Owner only.",
|
|
231
241
|
inputSchema: mIRC_delete_input,
|
|
@@ -233,6 +243,8 @@ export const mircTools: MosaddTool[] = [
|
|
|
233
243
|
},
|
|
234
244
|
{
|
|
235
245
|
name: "mIRC_discover",
|
|
246
|
+
title: "Discover public channels",
|
|
247
|
+
annotations: { readOnlyHint: true },
|
|
236
248
|
requires: "network",
|
|
237
249
|
description:
|
|
238
250
|
"Browse the PUBLIC channel DIRECTORY — open channels whose owners opted in (discoverable=true). Returns {id, channel_key, name, description, capabilities, member_count, is_member}. Filter by name with q; paginated. Join a result with mIRC_join (open = one-click). Private/password/partner channels never appear.",
|
|
@@ -241,6 +253,8 @@ export const mircTools: MosaddTool[] = [
|
|
|
241
253
|
},
|
|
242
254
|
{
|
|
243
255
|
name: "mIRC_report",
|
|
256
|
+
title: "Report abuse",
|
|
257
|
+
annotations: { readOnlyHint: false },
|
|
244
258
|
requires: "network",
|
|
245
259
|
description:
|
|
246
260
|
"Report a channel for abuse (spam/harassment/illegal/etc). Metadata + reason only — never message content. The reported party is the channel owner (server-derived). Use for public-directory moderation.",
|
package/src/tools/mtalk.ts
CHANGED
|
@@ -80,6 +80,8 @@ async function mTALK_state(
|
|
|
80
80
|
export const mtalkTools: MosaddTool[] = [
|
|
81
81
|
{
|
|
82
82
|
name: "mTALK_open",
|
|
83
|
+
title: "Open push-to-talk room",
|
|
84
|
+
annotations: { readOnlyHint: false },
|
|
83
85
|
requires: "any",
|
|
84
86
|
description:
|
|
85
87
|
"Open (or get) a push-to-talk room. Returns a stable room_id. Pass an optional label to share a named room (e.g. 'ops'); omit it for a personal room. Works over network (LiveKit) or off-grid radio depending on the host.",
|
|
@@ -88,6 +90,8 @@ export const mtalkTools: MosaddTool[] = [
|
|
|
88
90
|
},
|
|
89
91
|
{
|
|
90
92
|
name: "mTALK_join",
|
|
93
|
+
title: "Get PTT join credentials",
|
|
94
|
+
annotations: { readOnlyHint: false },
|
|
91
95
|
requires: "network",
|
|
92
96
|
description:
|
|
93
97
|
"Get credentials (token + media URL) to join a PTT room's audio transport. Hand these to a human or bot client to connect. The agent itself drives the floor with mTALK_press / mTALK_release.",
|
|
@@ -96,6 +100,8 @@ export const mtalkTools: MosaddTool[] = [
|
|
|
96
100
|
},
|
|
97
101
|
{
|
|
98
102
|
name: "mTALK_press",
|
|
103
|
+
title: "Press to talk (request floor)",
|
|
104
|
+
annotations: { readOnlyHint: false },
|
|
99
105
|
requires: "any",
|
|
100
106
|
description:
|
|
101
107
|
"Press push-to-talk: request the floor in a room. Half-duplex — if no one is transmitting you are GRANTED the floor (granted=true) and may speak; otherwise you are queued FIFO and `position` tells you where you are. Call mTALK_release when done. A holder who never releases is auto-bumped after the anti-hog timeout.",
|
|
@@ -104,6 +110,8 @@ export const mtalkTools: MosaddTool[] = [
|
|
|
104
110
|
},
|
|
105
111
|
{
|
|
106
112
|
name: "mTALK_release",
|
|
113
|
+
title: "Release the floor",
|
|
114
|
+
annotations: { readOnlyHint: false },
|
|
107
115
|
requires: "any",
|
|
108
116
|
description:
|
|
109
117
|
"Release push-to-talk: give up the floor (or cancel your queued request). If you held the floor, the next participant in the queue is promoted automatically. Returns the new holder and queue.",
|
|
@@ -112,6 +120,8 @@ export const mtalkTools: MosaddTool[] = [
|
|
|
112
120
|
},
|
|
113
121
|
{
|
|
114
122
|
name: "mTALK_state",
|
|
123
|
+
title: "Read PTT floor state",
|
|
124
|
+
annotations: { readOnlyHint: true },
|
|
115
125
|
requires: "any",
|
|
116
126
|
description:
|
|
117
127
|
"Read a PTT room's floor state without changing it: who is currently transmitting (holder), since when, and the waiting queue.",
|
package/src/tools/murl.ts
CHANGED
|
@@ -243,6 +243,8 @@ async function mURL_delete(
|
|
|
243
243
|
export const murlTools: MosaddTool[] = [
|
|
244
244
|
{
|
|
245
245
|
name: "mURL_read_channel",
|
|
246
|
+
title: "Read domain channel",
|
|
247
|
+
annotations: { readOnlyHint: true },
|
|
246
248
|
requires: "network",
|
|
247
249
|
description:
|
|
248
250
|
"Read the live chat channel for a web DOMAIN (mURL — 'IRC for URLs'). Returns the most recent messages humans and agents have posted about that domain. Use it to get real-time, crowd-sourced context before acting on a site — e.g. scam warnings, promo codes, outage reports, 'is this legit?'. The channel auto-exists for any domain. Auth: MOSADD_API_KEY (hub key).",
|
|
@@ -251,6 +253,8 @@ export const murlTools: MosaddTool[] = [
|
|
|
251
253
|
},
|
|
252
254
|
{
|
|
253
255
|
name: "mURL_post",
|
|
256
|
+
title: "Post to domain channel",
|
|
257
|
+
annotations: { readOnlyHint: false },
|
|
254
258
|
requires: "network",
|
|
255
259
|
description:
|
|
256
260
|
"Post a message into a web DOMAIN's mURL chat channel — leave context for the humans and agents who visit that site next (a finding, warning, tip, or coordination note). Sub-100ms global fan-out to everyone currently on the channel. Auth: MOSADD_API_KEY (hub key).",
|
|
@@ -259,6 +263,8 @@ export const murlTools: MosaddTool[] = [
|
|
|
259
263
|
},
|
|
260
264
|
{
|
|
261
265
|
name: "mURL_presence",
|
|
266
|
+
title: "Who is on a domain now",
|
|
267
|
+
annotations: { readOnlyHint: true },
|
|
262
268
|
requires: "network",
|
|
263
269
|
description:
|
|
264
270
|
"Who is on a domain's mURL channel right now: live participant count + roster nicknames + channel status (open/claimed/blocked). Public (no key needed). Use it to gauge whether a domain has an active audience before posting.",
|
|
@@ -267,6 +273,8 @@ export const murlTools: MosaddTool[] = [
|
|
|
267
273
|
},
|
|
268
274
|
{
|
|
269
275
|
name: "mURL_list_channels",
|
|
276
|
+
title: "List / trending domain channels",
|
|
277
|
+
annotations: { readOnlyHint: true },
|
|
270
278
|
requires: "network",
|
|
271
279
|
description:
|
|
272
280
|
"Discovery for mURL domain channels: 'trending' (most active in the last N hours, default 24) / 'list' (paginated catalogue, status-filtered) / 'mine' (channels you DNS-verified). Returns domain, slug, status, branding, verified_at + (for trending) messages_in_window. For who's-on-now, follow up with mURL_presence on the slug.",
|
|
@@ -275,6 +283,8 @@ export const murlTools: MosaddTool[] = [
|
|
|
275
283
|
},
|
|
276
284
|
{
|
|
277
285
|
name: "mURL_create",
|
|
286
|
+
title: "Claim domain channel",
|
|
287
|
+
annotations: { readOnlyHint: false },
|
|
278
288
|
requires: "network",
|
|
279
289
|
description:
|
|
280
290
|
"Create / claim the mURL channel for a web DOMAIN and register YOU as its owner (idempotent — returns the existing channel if you already own it; fails with 'claimed_by_other' if another account owns it). Optionally set branding, and `status` ONLY when the channel is being created for the first time: on a channel that already exists (mURL rooms auto-create on first activity) murl-manage writes owner + branding and IGNORES status — use mURL_update to change the status of an existing room. Owner-side: needs your mosADD login session (user JWT via `mosadd login`), not just a hub key — same as mURL_list_channels action='mine'. Backend: murl-manage EF.",
|
|
@@ -283,6 +293,8 @@ export const murlTools: MosaddTool[] = [
|
|
|
283
293
|
},
|
|
284
294
|
{
|
|
285
295
|
name: "mURL_update",
|
|
296
|
+
title: "Update domain channel",
|
|
297
|
+
annotations: { readOnlyHint: false },
|
|
286
298
|
requires: "network",
|
|
287
299
|
description:
|
|
288
300
|
"Update a mURL DOMAIN channel you own: set branding, mark it 'claimed', 'blocked' (close the room), or reopen it as 'open'. Owner-scoped — you must own the channel (claim it first with mURL_create). Needs your mosADD login session. Backend: murl-manage EF.",
|
|
@@ -291,6 +303,8 @@ export const murlTools: MosaddTool[] = [
|
|
|
291
303
|
},
|
|
292
304
|
{
|
|
293
305
|
name: "mURL_delete",
|
|
306
|
+
title: "Delete domain channel",
|
|
307
|
+
annotations: { destructiveHint: true },
|
|
294
308
|
requires: "network",
|
|
295
309
|
description:
|
|
296
310
|
"Delete a mURL DOMAIN channel you own (removes its domain_controls row; the room stops being served). Owner-scoped — you must own it. Needs your mosADD login session. Backend: murl-manage EF.",
|
package/src/tools/presence.ts
CHANGED
|
@@ -17,6 +17,21 @@
|
|
|
17
17
|
* VPS, the legal dispatcher, a cloud runner — attaches with one call and the stand-in defers to it
|
|
18
18
|
* for as long as that session's process lives.
|
|
19
19
|
*
|
|
20
|
+
* ⭐ AS_AGENT (2026-08-26, founder order: "wpinanie agentów ma działać co sesję i w różnych
|
|
21
|
+
* kontach Claude"). Fleet sessions usually hold the OWNER's key (identity kind=human), so a bare
|
|
22
|
+
* attach claims the OWNER's lane — and every channel post they made either landed in the owner's
|
|
23
|
+
* bubble (identity theft) or, after the v146 guard, got a 403 unless the model remembered a
|
|
24
|
+
* per-post `agent` field. `as_agent` fixes this at the ROOT: the session declares ONCE whose line
|
|
25
|
+
* it speaks for. That does two things server-side:
|
|
26
|
+
* 1. upserts `mosadd_gateway_agent_binding` — message-send then signs the session's channel
|
|
27
|
+
* posts as that agent automatically (explicit `agent` field still wins; ownership is
|
|
28
|
+
* re-validated server-side on every post);
|
|
29
|
+
* 2. beats the AGENT line's heartbeat (RLS additionally allows the owner to claim lines of
|
|
30
|
+
* agents they own — migration 20260826210000), so the agent's cloud stand-in defers to
|
|
31
|
+
* this session, exactly as if the agent's own key were plugged in.
|
|
32
|
+
* Binding is per OWNER (one row) — the last attach wins, which is visible and recoverable,
|
|
33
|
+
* unlike a silent mis-signed post.
|
|
34
|
+
*
|
|
20
35
|
* ⭐ THE BEAT IS NOT THE MODEL'S JOB. The heartbeat window is minutes wide, and a model cannot be
|
|
21
36
|
* relied on to call a tool on a timer — it answers prompts, it does not hold a clock. So attaching
|
|
22
37
|
* starts an internal keep-alive interval inside THIS process. The signal is therefore "the session
|
|
@@ -30,9 +45,10 @@
|
|
|
30
45
|
* tenant's env or throw. The env is captured at attach time and passed explicitly to
|
|
31
46
|
* `getSupabase(env)` on every beat, and attachments are tracked per identity, not per process.
|
|
32
47
|
*
|
|
33
|
-
* Security: the write is plain RLS, no privileged path.
|
|
34
|
-
*
|
|
35
|
-
*
|
|
48
|
+
* Security: the write is plain RLS, no privileged path. agent_bridge_heartbeat allows a session
|
|
49
|
+
* to claim the account whose key it holds OR a line of an agent that account OWNS (kind='agent',
|
|
50
|
+
* retired IS NULL); mosadd_gateway_agent_binding enforces the same ownership in its CHECK. A key
|
|
51
|
+
* can never claim or speak for a stranger's line.
|
|
36
52
|
*/
|
|
37
53
|
|
|
38
54
|
import { hostname } from "node:os";
|
|
@@ -52,6 +68,8 @@ const BEAT_MS = 60_000;
|
|
|
52
68
|
/** Advertised to the caller so it knows how long an attachment survives without this process. */
|
|
53
69
|
const HOLD_SECONDS = 300;
|
|
54
70
|
|
|
71
|
+
const UUID_RE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
72
|
+
|
|
55
73
|
interface Attachment {
|
|
56
74
|
timer: ReturnType<typeof setInterval>;
|
|
57
75
|
env: SupabaseEnv;
|
|
@@ -60,6 +78,13 @@ interface Attachment {
|
|
|
60
78
|
/** identity_id → its keep-alive. Keyed per identity so one gateway process can hold many. */
|
|
61
79
|
const attachments = new Map<string, Attachment>();
|
|
62
80
|
|
|
81
|
+
/**
|
|
82
|
+
* owner user_id → agent identity this PROCESS bound via as_agent. Needed so a plain
|
|
83
|
+
* `release:true` from the same session also hands back the agent line it took, without
|
|
84
|
+
* a releasing session ever touching a binding some OTHER process created.
|
|
85
|
+
*/
|
|
86
|
+
const processBindings = new Map<string, string>();
|
|
87
|
+
|
|
63
88
|
/** One upsert of the liveness row. Best-effort by design: a missed beat must never throw into a timer. */
|
|
64
89
|
async function beat(env: SupabaseEnv, identityId: string, host: string, mode: string): Promise<void> {
|
|
65
90
|
await getSupabase(env)
|
|
@@ -77,7 +102,9 @@ async function beat(env: SupabaseEnv, identityId: string, host: string, mode: st
|
|
|
77
102
|
* that one is private to mDM and this file must not reach into another module's internals.
|
|
78
103
|
* The identity id is NOT the auth user id; the heartbeat table is keyed on the identity.
|
|
79
104
|
*/
|
|
80
|
-
async function resolveSelf(
|
|
105
|
+
async function resolveSelf(
|
|
106
|
+
env: SupabaseEnv,
|
|
107
|
+
): Promise<{ id: string; display_name: string | null; user_id: string }> {
|
|
81
108
|
const sb = getSupabase(env);
|
|
82
109
|
const { data: u, error: ue } = await sb.auth.getUser();
|
|
83
110
|
if (ue || !u?.user) {
|
|
@@ -93,7 +120,56 @@ async function resolveSelf(env: SupabaseEnv): Promise<{ id: string; display_name
|
|
|
93
120
|
if (error || !data) {
|
|
94
121
|
throw new Error("This account has no mosadd identity row yet — sign in to mosadd.com once to create it.");
|
|
95
122
|
}
|
|
96
|
-
return { id: data.id as string, display_name: (data.display_name as string | null) ?? null };
|
|
123
|
+
return { id: data.id as string, display_name: (data.display_name as string | null) ?? null, user_id: u.user.id };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Resolve ONE agent OWNED by the caller from what they typed: identity uuid, mosADD address
|
|
128
|
+
* (dispatcher@mosadd.com) or display name. Mirrors the server-side ownership rule
|
|
129
|
+
* (m0ssad-3 `_shared/ownedAgent.ts`): kind='agent' AND owner_user_id = caller AND not retired.
|
|
130
|
+
* Ownership is part of the QUERY — a stranger's agent resolves to nothing, never to a row we
|
|
131
|
+
* would then have to remember to reject.
|
|
132
|
+
*/
|
|
133
|
+
async function resolveOwnedAgentLine(
|
|
134
|
+
env: SupabaseEnv,
|
|
135
|
+
ownerUserId: string,
|
|
136
|
+
ref: string,
|
|
137
|
+
): Promise<{ id: string; m0ssad_email: string | null; display_name: string | null } | null> {
|
|
138
|
+
const value = ref.trim();
|
|
139
|
+
if (!value || /[(),]/.test(value)) return null;
|
|
140
|
+
let q = getSupabase(env)
|
|
141
|
+
.from("identities")
|
|
142
|
+
.select("id, m0ssad_email, display_name")
|
|
143
|
+
.eq("kind", "agent")
|
|
144
|
+
.eq("owner_user_id", ownerUserId)
|
|
145
|
+
.is("retired_at", null);
|
|
146
|
+
q = UUID_RE.test(value)
|
|
147
|
+
? q.or(`id.eq.${value},m0ssad_email.eq.${value}`)
|
|
148
|
+
: q.or(`m0ssad_email.eq.${value},display_name.eq.${value}`);
|
|
149
|
+
const { data, error } = await q.limit(2);
|
|
150
|
+
if (error || !data || data.length !== 1) return null;
|
|
151
|
+
return data[0] as { id: string; m0ssad_email: string | null; display_name: string | null };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function stopAttachment(identityId: string): void {
|
|
155
|
+
const existing = attachments.get(identityId);
|
|
156
|
+
if (existing) {
|
|
157
|
+
clearInterval(existing.timer);
|
|
158
|
+
attachments.delete(identityId);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function startAttachment(env: SupabaseEnv, identityId: string, host: string, mode: string, ctx: MosaddToolContext): void {
|
|
163
|
+
const timer = setInterval(() => {
|
|
164
|
+
void beat(env, identityId, host, mode).catch((e) => {
|
|
165
|
+
// A single missed beat is survivable (3 min of cover remain) and must not kill the interval:
|
|
166
|
+
// a transient network blip would otherwise silently un-attach the session for good.
|
|
167
|
+
ctx.log("warn", "comms_session_attach: beat failed", { identity_id: identityId, error: String(e) });
|
|
168
|
+
});
|
|
169
|
+
}, BEAT_MS);
|
|
170
|
+
// Never hold the process open on account of the beat — when the session ends, it ends.
|
|
171
|
+
timer.unref?.();
|
|
172
|
+
attachments.set(identityId, { timer, env });
|
|
97
173
|
}
|
|
98
174
|
|
|
99
175
|
const comms_session_attach_input = z.object({
|
|
@@ -104,11 +180,18 @@ const comms_session_attach_input = z.object({
|
|
|
104
180
|
.describe(
|
|
105
181
|
"Short name for THIS session, shown to the owner as who is holding the line (e.g. 'CTO — Claude Code', 'dispatcher — Cowork'). Defaults to the machine name.",
|
|
106
182
|
),
|
|
183
|
+
as_agent: z
|
|
184
|
+
.string()
|
|
185
|
+
.max(200)
|
|
186
|
+
.optional()
|
|
187
|
+
.describe(
|
|
188
|
+
"Speak as ONE OF THE OWNER'S AGENT LINES while holding the owner's key — its mosADD address (dispatcher@mosadd.com), identity id, or display name. Declares ONCE per session whose line this session speaks for: the gateway then signs your CHANNEL posts as that agent automatically (no per-post `agent` field needed), and that agent's cloud stand-in defers to you. The server verifies you OWN the agent; a stranger's agent is refused. Omit to claim the key's own line, exactly as before.",
|
|
189
|
+
),
|
|
107
190
|
release: z
|
|
108
191
|
.boolean()
|
|
109
192
|
.optional()
|
|
110
193
|
.describe(
|
|
111
|
-
"Hand the line back immediately instead of claiming it: stops this session's keep-alive
|
|
194
|
+
"Hand the line back immediately instead of claiming it: stops this session's keep-alive, clears the liveness row (and any as_agent declaration this session made), so the 24/7 cloud stand-in resumes answering at once rather than after the hold expires. Call this when the session is finishing.",
|
|
112
195
|
),
|
|
113
196
|
});
|
|
114
197
|
|
|
@@ -116,6 +199,8 @@ interface AttachResult {
|
|
|
116
199
|
attached: boolean;
|
|
117
200
|
identity_id: string;
|
|
118
201
|
display_name: string | null;
|
|
202
|
+
/** Set when as_agent bound this session to an agent line — whose voice channel posts use. */
|
|
203
|
+
speaking_as?: { identity_id: string; address: string | null; display_name: string | null };
|
|
119
204
|
/** Where the beat says it is coming from — the owner sees this. */
|
|
120
205
|
host?: string;
|
|
121
206
|
/** Seconds a beat stays trusted if this process stops beating. */
|
|
@@ -131,71 +216,110 @@ async function comms_session_attach(
|
|
|
131
216
|
// note in the file header. Everything after this (including timer callbacks) uses this value.
|
|
132
217
|
const env = readSupabaseEnv();
|
|
133
218
|
const self = await resolveSelf(env);
|
|
134
|
-
|
|
135
|
-
// Whether attaching or releasing, any previous keep-alive for this identity is stale: a second
|
|
136
|
-
// attach replaces the first rather than doubling the beat rate.
|
|
137
|
-
const existing = attachments.get(self.id);
|
|
138
|
-
if (existing) {
|
|
139
|
-
clearInterval(existing.timer);
|
|
140
|
-
attachments.delete(self.id);
|
|
141
|
-
}
|
|
219
|
+
const sb = getSupabase(env);
|
|
142
220
|
|
|
143
221
|
if (input.release) {
|
|
144
|
-
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
222
|
+
// Hand back everything THIS process (or this call, via as_agent) holds for the account:
|
|
223
|
+
// the key's own line, plus the agent line it declared with as_agent, plus that binding row.
|
|
224
|
+
// DELETE, not a backdated timestamp. "No row" is the truthful representation of "nobody is
|
|
225
|
+
// on this line"; writing a fake past `last_seen_at` would put a lie in a table other code reads.
|
|
226
|
+
const toRelease = new Set<string>([self.id]);
|
|
227
|
+
const bound = processBindings.get(self.user_id);
|
|
228
|
+
if (bound) toRelease.add(bound);
|
|
229
|
+
if (input.as_agent) {
|
|
230
|
+
const agent = await resolveOwnedAgentLine(env, self.user_id, input.as_agent);
|
|
231
|
+
if (agent) toRelease.add(agent.id);
|
|
232
|
+
}
|
|
233
|
+
for (const id of toRelease) {
|
|
234
|
+
stopAttachment(id);
|
|
235
|
+
const { error } = await sb.from("agent_bridge_heartbeat").delete().eq("identity_id", id);
|
|
236
|
+
if (error) throw new Error(`Could not release the line: ${error.message}`);
|
|
237
|
+
}
|
|
238
|
+
await sb.from("mosadd_gateway_agent_binding").delete().eq("user_id", self.user_id);
|
|
239
|
+
processBindings.delete(self.user_id);
|
|
240
|
+
ctx.log("info", "comms_session_attach: released", { identity_ids: [...toRelease] });
|
|
149
241
|
return {
|
|
150
242
|
attached: false,
|
|
151
243
|
identity_id: self.id,
|
|
152
244
|
display_name: self.display_name,
|
|
153
|
-
note: "Line released. The 24/7 cloud stand-in answers
|
|
245
|
+
note: "Line released (agent declaration cleared too). The 24/7 cloud stand-in answers from now on.",
|
|
154
246
|
};
|
|
155
247
|
}
|
|
156
248
|
|
|
157
249
|
const host = input.label?.trim() || `mcp:${hostname()}`;
|
|
158
250
|
const mode = "mcp-session";
|
|
159
251
|
|
|
252
|
+
// Which line does this session claim? Without as_agent: the key's own line — bit-for-bit the
|
|
253
|
+
// old behaviour. With as_agent: the OWNED agent's line + the gateway signing declaration.
|
|
254
|
+
let lineId = self.id;
|
|
255
|
+
let speakingAs: AttachResult["speaking_as"];
|
|
256
|
+
if (input.as_agent) {
|
|
257
|
+
const agent = await resolveOwnedAgentLine(env, self.user_id, input.as_agent);
|
|
258
|
+
if (!agent) {
|
|
259
|
+
throw new Error(
|
|
260
|
+
`No LIVE agent of yours matches "${input.as_agent}". You may only speak as an agent you OWN ` +
|
|
261
|
+
"(its mosADD address, identity id, or display name) — never as someone else's agent or another human.",
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
lineId = agent.id;
|
|
265
|
+
speakingAs = { identity_id: agent.id, address: agent.m0ssad_email, display_name: agent.display_name };
|
|
266
|
+
|
|
267
|
+
// The signing declaration message-send reads (migration 20260826210000). RLS re-checks
|
|
268
|
+
// ownership in its WITH CHECK; message-send re-validates AGAIN per post (defence in depth).
|
|
269
|
+
const { error: bindError } = await sb.from("mosadd_gateway_agent_binding").upsert(
|
|
270
|
+
{
|
|
271
|
+
user_id: self.user_id,
|
|
272
|
+
agent_identity_id: agent.id,
|
|
273
|
+
agent_address: agent.m0ssad_email,
|
|
274
|
+
bound_at: new Date().toISOString(),
|
|
275
|
+
bound_by_host: host,
|
|
276
|
+
},
|
|
277
|
+
{ onConflict: "user_id" },
|
|
278
|
+
);
|
|
279
|
+
if (bindError) throw new Error(`Could not declare the agent line: ${bindError.message}`);
|
|
280
|
+
processBindings.set(self.user_id, agent.id);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Whether attaching or re-attaching, any previous keep-alive for this line is stale: a second
|
|
284
|
+
// attach replaces the first rather than doubling the beat rate.
|
|
285
|
+
stopAttachment(lineId);
|
|
286
|
+
|
|
160
287
|
// First beat is awaited so the caller learns immediately if RLS refuses (wrong account / no
|
|
161
288
|
// identity) instead of failing silently in a timer nobody watches.
|
|
162
289
|
try {
|
|
163
|
-
await beat(env,
|
|
290
|
+
await beat(env, lineId, host, mode);
|
|
164
291
|
} catch (e) {
|
|
165
292
|
throw new Error(`Could not claim the line: ${e instanceof Error ? e.message : String(e)}`);
|
|
166
293
|
}
|
|
294
|
+
startAttachment(env, lineId, host, mode, ctx);
|
|
167
295
|
|
|
168
|
-
|
|
169
|
-
void beat(env, self.id, host, mode).catch((e) => {
|
|
170
|
-
// A single missed beat is survivable (3 min of cover remain) and must not kill the interval:
|
|
171
|
-
// a transient network blip would otherwise silently un-attach the session for good.
|
|
172
|
-
ctx.log("warn", "comms_session_attach: beat failed", { identity_id: self.id, error: String(e) });
|
|
173
|
-
});
|
|
174
|
-
}, BEAT_MS);
|
|
175
|
-
// Never hold the process open on account of the beat — when the session ends, it ends.
|
|
176
|
-
timer.unref?.();
|
|
177
|
-
attachments.set(self.id, { timer, env });
|
|
178
|
-
|
|
179
|
-
ctx.log("info", "comms_session_attach: line claimed", { identity_id: self.id, host });
|
|
296
|
+
ctx.log("info", "comms_session_attach: line claimed", { identity_id: lineId, host, as_agent: speakingAs?.address });
|
|
180
297
|
return {
|
|
181
298
|
attached: true,
|
|
182
|
-
identity_id:
|
|
183
|
-
display_name: self.display_name,
|
|
299
|
+
identity_id: lineId,
|
|
300
|
+
display_name: speakingAs ? speakingAs.display_name : self.display_name,
|
|
301
|
+
...(speakingAs ? { speaking_as: speakingAs } : {}),
|
|
184
302
|
host,
|
|
185
303
|
holds_for_seconds: HOLD_SECONDS,
|
|
186
|
-
note:
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
304
|
+
note: speakingAs
|
|
305
|
+
? `This session now speaks for ${speakingAs.address ?? speakingAs.identity_id}: channel posts sent ` +
|
|
306
|
+
"through this gateway are signed as that agent automatically (an explicit `agent` field still wins), " +
|
|
307
|
+
"and the agent's cloud stand-in defers to you while the session runs. " +
|
|
308
|
+
"Call again with release:true to hand it back."
|
|
309
|
+
: "This session now owns the account's reply lane; the cloud stand-in will not answer while it is held. " +
|
|
310
|
+
"The hold renews itself for as long as this process runs and lapses on its own if the session dies. " +
|
|
311
|
+
"Call again with release:true to hand it back immediately.",
|
|
190
312
|
};
|
|
191
313
|
}
|
|
192
314
|
|
|
193
315
|
export const presenceTools: MosaddTool[] = [
|
|
194
316
|
{
|
|
195
317
|
name: "comms_session_attach",
|
|
318
|
+
title: "Attach session to a line",
|
|
319
|
+
annotations: { destructiveHint: false, idempotentHint: true },
|
|
196
320
|
requires: "network",
|
|
197
321
|
description:
|
|
198
|
-
"Claim
|
|
322
|
+
"Claim a mosADD reply lane for the CURRENT agent session, so the 24/7 cloud stand-in stops answering in its place and the owner talks to you instead. Call it once at the start of a session; the hold renews itself while the session runs and lapses on its own if the session dies. Holding the OWNER's key while working as one of their agent lines? Pass as_agent:'<address of YOUR line>' (e.g. dispatcher@mosadd.com) — the gateway then signs your channel posts as that agent automatically for the whole session and silences that agent's stand-in; ownership is verified server-side. Pass release:true when finishing to hand everything back immediately. Owner-scoped: a session can only claim the account whose key it holds, or a line of an agent that account owns.",
|
|
199
323
|
inputSchema: comms_session_attach_input,
|
|
200
324
|
handler: comms_session_attach as MosaddTool["handler"],
|
|
201
325
|
},
|
|
@@ -205,4 +329,5 @@ export const presenceTools: MosaddTool[] = [
|
|
|
205
329
|
export function __clearAttachmentsForTest(): void {
|
|
206
330
|
for (const a of attachments.values()) clearInterval(a.timer);
|
|
207
331
|
attachments.clear();
|
|
332
|
+
processBindings.clear();
|
|
208
333
|
}
|
package/src/tools/ptt-ingest.ts
CHANGED
|
@@ -88,6 +88,8 @@ async function mTALK_ingest_ptt(
|
|
|
88
88
|
export const pttIngestTools: MosaddTool[] = [
|
|
89
89
|
{
|
|
90
90
|
name: "mTALK_ingest_ptt",
|
|
91
|
+
title: "Transcribe PTT audio into memory",
|
|
92
|
+
annotations: { readOnlyHint: false },
|
|
91
93
|
requires: "network",
|
|
92
94
|
description:
|
|
93
95
|
"Submit a finished PTT 'over' (push-to-talk audio segment) for transcription into the caller's RAG index — so 'what did X say on PTT?' is searchable later. The PERSISTENCE of the voice message itself (the message_meta row + fan-out) is handled by mDM_send_voice / mIRC_send_voice; this tool is the transcription bridge only. Honors per-user RAG opt-in: opted-out callers get status='skipped_optout' (no transcript stored). Auth: Supabase session JWT.",
|
package/src/tools/threat.ts
CHANGED
|
@@ -102,6 +102,8 @@ async function threat_classify(
|
|
|
102
102
|
export const threatTools: MosaddTool[] = [
|
|
103
103
|
{
|
|
104
104
|
name: "threat_catalog",
|
|
105
|
+
title: "Threat taxonomy catalog",
|
|
106
|
+
annotations: { readOnlyHint: true },
|
|
105
107
|
requires: "any",
|
|
106
108
|
description:
|
|
107
109
|
"List the canonical mosadd threat-event taxonomy (the full radar catalog: id, category, default severity, auto-actions, per-platform availability). Filter by category or platform. Pure/offline — returns { count, total, events }. Use to discover what the defensive engine recognises.",
|
|
@@ -110,6 +112,8 @@ export const threatTools: MosaddTool[] = [
|
|
|
110
112
|
},
|
|
111
113
|
{
|
|
112
114
|
name: "threat_classify",
|
|
115
|
+
title: "Classify threat event",
|
|
116
|
+
annotations: { readOnlyHint: true },
|
|
113
117
|
requires: "any",
|
|
114
118
|
description:
|
|
115
119
|
"Classify a single telemetry event against the mosadd threat taxonomy + DECK engine. For a known event type (e.g. PROCESS_INJECTION, STINGRAY_DETECT, IMSI_CATCHER_SCAN, MEMORY_INJECTION) it returns that event's real severity (info|warning|elevated|critical|killswitch) with action=\"monitor\" — Pegasus-class events surface as critical immediately, but the engine NEVER auto-acts (it tells you, it never disconnects/locks). Unknown strings fall back to the pure DECK decision (log_only|revoke_sessions|lock_account|suspend_did). Returns { action, severity, reason, known_event, category, label }. Deterministic, offline, no backend.",
|