@mosadd/mcp 3.0.0-alpha.20 → 3.0.0-alpha.22
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/CHANGELOG.md +22 -0
- package/README.md +12 -12
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-FZNAGICW.js → chunk-TNWL6GPV.js} +189 -243
- package/dist/index.d.ts +8 -3
- package/dist/index.js +1 -1
- package/package.json +9 -8
- package/src/__tests__/mdm-e2ee.test.ts +1 -1
- package/src/crypto/mdm-session.ts +136 -37
- package/src/providers/blob-upload.ts +1 -1
- package/src/tools/attachments.ts +2 -2
- package/src/tools/index.ts +8 -4
- package/src/tools/mirc-messages.ts +2 -6
- package/src/tools/mirc.ts +3 -1
- package/src/tools/ptt-ingest.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,28 @@ gateway (Phase 2) ships.
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [3.0.0-alpha.22] — 2026-06-26
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
- **alpha.21 was broken on a fresh install** — it crashed on startup with
|
|
15
|
+
`SyntaxError: The requested module '@mosadd/crypto' does not provide an export named
|
|
16
|
+
'initRatchetInitiator'`. The workspace dependency packages (`@mosadd/crypto`, `protocol`,
|
|
17
|
+
`providers`, `threat-engine`) had drifted: their *source* gained new exports (the mDM
|
|
18
|
+
Double-Ratchet work) but their version was never bumped, so npm still served the stale
|
|
19
|
+
alpha.4/alpha.5 builds while `@mosadd/mcp` was built against the newer API. Bumped the whole
|
|
20
|
+
alpha-line in lockstep to alpha.22 and republished so every published package matches current
|
|
21
|
+
source and `workspace:*` cross-deps resolve. Verified: a clean `npm i @mosadd/mcp@alpha`
|
|
22
|
+
now boots and lists 62 tools. (The previous alpha.20 was broken-on-install the same way.)
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
- **Unregistered 2 scaffold tools that failed on every call.** `mp0st_send_as_agent`
|
|
26
|
+
(POSTed to a non-existent `hub-claim-mint` endpoint → 404, and sent provenance body
|
|
27
|
+
fields the deployed `mp0st-send` EF never reads) and `mTALK_ingest_ptt` (request body
|
|
28
|
+
didn't match the deployed `ptt-ingest` EF → 400). Both are now commented out in
|
|
29
|
+
`tools/index.ts` like the other not-registered modules, so an agent only ever discovers
|
|
30
|
+
tools that actually work. Registered tool count **64 → 62** (mp0st 12→11, mTALK 6→5).
|
|
31
|
+
Source is kept; both re-register once their backend contracts are wired + tested.
|
|
32
|
+
|
|
11
33
|
### Fixed
|
|
12
34
|
- **mIRC `reject_request` / `approve_request` field (LINEAR-3522):** the tools sent
|
|
13
35
|
`request_id` but `channel-members-manage` reads `target_identity_id` → 400 every
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# @mosadd/mcp
|
|
2
2
|
|
|
3
|
-
MCP server for [
|
|
3
|
+
MCP server for [mosADD](https://mosadd.com) — exposes the OS modules (m\*) as Model Context Protocol tools so any agent runtime can talk to mosadd: Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom.
|
|
4
4
|
|
|
5
|
-
> **3.0.0-alpha.
|
|
5
|
+
> **3.0.0-alpha.20** — **62 live tools across 5 live modules** (mDM incl. voice + files, mIRC, mp0st, mTALK, mRAG) + agent→user action links + the `comms_capabilities` discovery tool + the defensive `threat_*` engine, wired to the mosADD backend (BYOK) as a strangler-fig step. Phase 2 routes through the hosted gateway at `mcp.mosadd.com` with the 166-event radar in front.
|
|
6
6
|
|
|
7
7
|
## Connect your agent
|
|
8
8
|
|
|
9
|
-
Three ways to authenticate, friendliest first — all three end with the same ~
|
|
9
|
+
Three ways to authenticate, friendliest first — all three end with the same ~62 tools.
|
|
10
10
|
|
|
11
11
|
### 1. `mosadd login` — recommended (one command, stays logged in)
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ Sign in once; the session is saved to `~/.mosadd/session.json` and **refreshed a
|
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
npx -y @mosadd/mcp@alpha login
|
|
17
|
-
# prompts for your Supabase URL + anon key (both public) and your
|
|
17
|
+
# prompts for your Supabase URL + anon key (both public) and your mosADD email + password
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
Then register the server with **no env block**:
|
|
@@ -51,7 +51,7 @@ A `mosadd_sk_live_…` hub key does not expire; the server exchanges it for a fr
|
|
|
51
51
|
}
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
Mint a key
|
|
54
|
+
Mint a key at **[mosadd.com/keys](https://mosadd.com/keys)** — the hub shows it once, in the `mosadd_sk_live_…` format above. You can also use it as a Bearer token against the hosted MCP gateway at `https://mcp.mosadd.com/mcp`.
|
|
55
55
|
|
|
56
56
|
### 3. BYOK + `MOSADD_USER_JWT` — advanced / debugging
|
|
57
57
|
|
|
@@ -65,19 +65,19 @@ In Phase 2 the hosted gateway at `mcp.mosadd.com` removes even this — add a UR
|
|
|
65
65
|
|
|
66
66
|
## Tools shipped in alpha
|
|
67
67
|
|
|
68
|
-
**
|
|
68
|
+
**62 live tools across 5 live modules** (mDM, mIRC, mp0st, mTALK, mRAG) + agent→user action links + the `comms_capabilities` discovery tool + the defensive `threat_*` engine. Highlights per module:
|
|
69
69
|
|
|
70
70
|
| Module | Tools | What it does |
|
|
71
71
|
|---|---|---|
|
|
72
|
-
| **mDM** (14) | `mDM_list_contacts`, `mDM_send`, `mDM_send_unencrypted`, `mDM_edit`, `mDM_delete`, `mDM_list`, `mDM_publish_keys`, `mDM_respond_request`, `mDM_call_start/answer/end`, `mDM_voice_note`, `mDM_send_voice`, `mDM_send_file` | 1:1 text, voice notes, calls + file/voice attachments. Multi-thread per contact
|
|
72
|
+
| **mDM** (14) | `mDM_list_contacts`, `mDM_send`, `mDM_send_unencrypted`, `mDM_edit`, `mDM_delete`, `mDM_list`, `mDM_publish_keys`, `mDM_respond_request`, `mDM_call_start/answer/end`, `mDM_voice_note`, `mDM_send_voice`, `mDM_send_file` | 1:1 text, voice notes, calls + file/voice attachments. Multi-thread per contact. `mDM_send` is end-to-end encrypted by default (X3DH / Double Ratchet, `mosadd.e2ee.v2`); the operator cannot read message content |
|
|
73
73
|
| **mIRC** (22) | `mIRC_create/list/get/update/delete`, member RBAC (`mIRC_join/leave/kick/ban/unban/set_role/set_ptt/approve_request/reject_request/request_access`), `mIRC_post_message`, `mIRC_list_messages`, edge (`mIRC_mint_channel_token`, `mIRC_send_edge`, `mIRC_history_edge`), `mIRC_send_voice/file` | Persistent Discord/Slack-style channels + the agent-coordination edge transport |
|
|
74
|
-
| **mp0st** (
|
|
75
|
-
| **mTALK** (
|
|
74
|
+
| **mp0st** (11) | `mp0st_send`, `mp0st_view`, `mp0st_list`, `mp0st_delete`, `mp0st_stats`, `mp0st_events`, `mp0st_metrics`, `mp0st_revoke`, `mp0st_audit_export`, `mp0st_consent`, `mp0st_notify` | Mail; every user gets `<id>@mosadd.com`. `mp0st_revoke` recalls secure-reader access; `mp0st_audit_export` emits an HMAC-SHA256-signed engagement audit; `mp0st_consent` manages recipient tracking opt-outs (GDPR); `mp0st_notify` pulls the inbound-mail feed |
|
|
75
|
+
| **mTALK** (5) | `mTALK_open`, `mTALK_join`, `mTALK_press`, `mTALK_release`, `mTALK_state` | Half-duplex push-to-talk: one speaker, FIFO queue, anti-hog auto-release |
|
|
76
76
|
| **mRAG** (4) | `mRAG_ingest`, `mRAG_search`, `mRAG_list_sources`, `mRAG_delete` | RAG recall over the user's own data (hybrid vector + BM25) |
|
|
77
77
|
| **comms_** (4) | `comms_action_create`, `comms_action_frame_get`, `comms_capabilities`, `comms_embed_create` | `comms_action_create` mints an agent→user one-link browser action (Tier 1); `comms_action_frame_get` fetches a framed action; `comms_capabilities` is one-call discovery of every tool's transport `requires` flag; `comms_embed_create` builds an embeddable surface |
|
|
78
78
|
| **threat_** (2) | `threat_catalog`, `threat_classify` | Pure defensive threat-event classification engine — enumerate the catalog and classify an operation against it |
|
|
79
79
|
|
|
80
|
-
Counts by module prefix sum to **
|
|
80
|
+
Counts by module prefix sum to **56 channel tools**; the 4 `comms_*` tools and 2 `threat_*` tools make **62 callable** in total. `mCALL` (telephony), `mROOM`, `mURL` — and the `mp0st_send_as_agent` provenance + `mTALK_ingest_ptt` scaffolds (backend contract not yet wired) — exist in the source but are **not registered**, so agents only ever see tools that actually work.
|
|
81
81
|
|
|
82
82
|
All tool names follow [RFC 0001](https://github.com/Hei33enberg/mosadd-os/blob/main/docs/rfcs/0001-module-naming.md) — `m<MODULE>_<operation>` snake_case.
|
|
83
83
|
|
|
@@ -91,7 +91,7 @@ Claude calls `mDM_list_contacts` → you see your contact list.
|
|
|
91
91
|
|
|
92
92
|
> Send "hello from Claude" to <id> with thread label `notes`.
|
|
93
93
|
|
|
94
|
-
Claude calls `mDM_send({ to, text, thread_label: "notes" })` → message appears in your
|
|
94
|
+
Claude calls `mDM_send({ to, text, thread_label: "notes" })` → message appears in your mosADD app under a `notes` thread.
|
|
95
95
|
|
|
96
96
|
## Architecture
|
|
97
97
|
|
|
@@ -105,7 +105,7 @@ Agent (Claude / Cursor / ...)
|
|
|
105
105
|
│ supabase.functions.invoke('message-send', ...)
|
|
106
106
|
│ + Authorization: Bearer <MOSADD_USER_JWT>
|
|
107
107
|
▼
|
|
108
|
-
|
|
108
|
+
mosADD backend Edge Function
|
|
109
109
|
│
|
|
110
110
|
│ RLS-checked insert
|
|
111
111
|
▼
|
package/dist/bin/mcp.js
CHANGED
|
@@ -78,10 +78,15 @@ import {
|
|
|
78
78
|
signEd25519,
|
|
79
79
|
verifyEd25519,
|
|
80
80
|
toBase64,
|
|
81
|
-
fromBase64
|
|
81
|
+
fromBase64,
|
|
82
|
+
initRatchetInitiator,
|
|
83
|
+
initRatchetResponder,
|
|
84
|
+
ratchetEncrypt,
|
|
85
|
+
ratchetDecrypt
|
|
82
86
|
} from "@mosadd/crypto";
|
|
83
87
|
var PREKEY_BUNDLE_VERSION = "mosadd.prekeys.v1";
|
|
84
88
|
var E2EE_ENVELOPE_VERSION = "mosadd.e2ee.v1";
|
|
89
|
+
var E2EE_ENVELOPE_VERSION_V2 = "mosadd.e2ee.v2";
|
|
85
90
|
var DEFAULT_ONE_TIME_PREKEYS = 8;
|
|
86
91
|
var InMemoryMdmKeyStore = class {
|
|
87
92
|
material = null;
|
|
@@ -175,11 +180,21 @@ function verifyPublicBundle(bundle) {
|
|
|
175
180
|
function isE2eeEnvelope(bytes) {
|
|
176
181
|
try {
|
|
177
182
|
const obj = JSON.parse(Buffer.from(bytes).toString("utf8"));
|
|
178
|
-
|
|
183
|
+
if (!obj?.ct) return false;
|
|
184
|
+
if (obj.v === E2EE_ENVELOPE_VERSION) return typeof obj.i === "number";
|
|
185
|
+
if (obj.v === E2EE_ENVELOPE_VERSION_V2) return typeof obj.dh === "string" && typeof obj.n === "number";
|
|
186
|
+
return false;
|
|
179
187
|
} catch {
|
|
180
188
|
return false;
|
|
181
189
|
}
|
|
182
190
|
}
|
|
191
|
+
function peekEnvelopeVersion(bytes) {
|
|
192
|
+
try {
|
|
193
|
+
return JSON.parse(Buffer.from(bytes).toString("utf8"))?.v;
|
|
194
|
+
} catch {
|
|
195
|
+
return void 0;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
183
198
|
function serializeEnvelope(env) {
|
|
184
199
|
return new Uint8Array(Buffer.from(JSON.stringify(env), "utf8"));
|
|
185
200
|
}
|
|
@@ -188,6 +203,11 @@ function parseEnvelope(bytes) {
|
|
|
188
203
|
if (obj?.v !== E2EE_ENVELOPE_VERSION) throw new Error(`Unsupported mDM envelope version: ${obj?.v}`);
|
|
189
204
|
return obj;
|
|
190
205
|
}
|
|
206
|
+
function parseEnvelopeV2(bytes) {
|
|
207
|
+
const obj = JSON.parse(Buffer.from(bytes).toString("utf8"));
|
|
208
|
+
if (obj?.v !== E2EE_ENVELOPE_VERSION_V2) throw new Error(`Unsupported mDM envelope version: ${obj?.v}`);
|
|
209
|
+
return obj;
|
|
210
|
+
}
|
|
191
211
|
async function publishOwnPrekeys(keystore, dm) {
|
|
192
212
|
const material = await keystore.getOwnMaterial();
|
|
193
213
|
await dm.publishPrekeyBundle(serializePublicBundle(material));
|
|
@@ -216,13 +236,33 @@ async function encryptForPeer(keystore, dm, peerId, plaintext) {
|
|
|
216
236
|
signedPreKeyPublicKey: peer.signedPrekey.publicKey,
|
|
217
237
|
oneTimePreKeyPublicKey: opk?.publicKey
|
|
218
238
|
});
|
|
219
|
-
const
|
|
239
|
+
const ratchet2 = await initRatchetInitiator(rootKey, peer.signedPrekey.publicKey);
|
|
220
240
|
session = {
|
|
221
|
-
|
|
241
|
+
ratchet2,
|
|
222
242
|
role: "initiator",
|
|
223
243
|
pendingHandshake: { ik: own.identity.publicKey, ek: ephemeral.publicKey, opkId: opk?.id }
|
|
224
244
|
};
|
|
225
245
|
}
|
|
246
|
+
if (session.ratchet2) {
|
|
247
|
+
const { header, ct: ct2 } = await ratchetEncrypt(session.ratchet2, plaintext);
|
|
248
|
+
const env2 = {
|
|
249
|
+
v: E2EE_ENVELOPE_VERSION_V2,
|
|
250
|
+
dh: toBase64(header.dh),
|
|
251
|
+
pn: header.pn,
|
|
252
|
+
n: header.n,
|
|
253
|
+
ct: ct2
|
|
254
|
+
};
|
|
255
|
+
if (session.pendingHandshake) {
|
|
256
|
+
env2.hdr = {
|
|
257
|
+
ik: toBase64(session.pendingHandshake.ik),
|
|
258
|
+
ek: toBase64(session.pendingHandshake.ek),
|
|
259
|
+
opk: session.pendingHandshake.opkId
|
|
260
|
+
};
|
|
261
|
+
session.pendingHandshake = void 0;
|
|
262
|
+
}
|
|
263
|
+
await keystore.putSession(peerId, session);
|
|
264
|
+
return serializeEnvelope(env2);
|
|
265
|
+
}
|
|
226
266
|
const step = await ratchetSend(session.ratchet);
|
|
227
267
|
const ct = await encryptBytes(step.messageKey, plaintext);
|
|
228
268
|
const env = { v: E2EE_ENVELOPE_VERSION, i: step.messageIndex, ct };
|
|
@@ -237,40 +277,69 @@ async function encryptForPeer(keystore, dm, peerId, plaintext) {
|
|
|
237
277
|
await keystore.putSession(peerId, session);
|
|
238
278
|
return serializeEnvelope(env);
|
|
239
279
|
}
|
|
280
|
+
async function responderRootKey(keystore, hdr) {
|
|
281
|
+
const own = await keystore.getOwnMaterial();
|
|
282
|
+
let oneTimePreKeyPrivateKey;
|
|
283
|
+
if (hdr.opk !== void 0) {
|
|
284
|
+
oneTimePreKeyPrivateKey = await keystore.takeOneTimePrekey(hdr.opk);
|
|
285
|
+
if (!oneTimePreKeyPrivateKey) {
|
|
286
|
+
throw new Error(`Handshake references one-time prekey ${hdr.opk} which is unknown or already consumed.`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const { rootKey } = await performX3dhResponder(
|
|
290
|
+
{
|
|
291
|
+
identityPrivateKey: own.identity.privateKey,
|
|
292
|
+
signedPreKeyPrivateKey: own.signedPrekey.pair.privateKey,
|
|
293
|
+
oneTimePreKeyPrivateKey
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
initiatorIdentityPublicKey: fromBase64(hdr.ik),
|
|
297
|
+
initiatorEphemeralPublicKey: fromBase64(hdr.ek),
|
|
298
|
+
usedOneTimePreKeyId: hdr.opk
|
|
299
|
+
}
|
|
300
|
+
);
|
|
301
|
+
return rootKey;
|
|
302
|
+
}
|
|
240
303
|
async function decryptFromPeer(keystore, peerId, envelopeBytes) {
|
|
304
|
+
if (peekEnvelopeVersion(envelopeBytes) === E2EE_ENVELOPE_VERSION_V2) {
|
|
305
|
+
const env2 = parseEnvelopeV2(envelopeBytes);
|
|
306
|
+
let session2 = await keystore.getSession(peerId);
|
|
307
|
+
if (!session2) {
|
|
308
|
+
if (!env2.hdr) {
|
|
309
|
+
throw new Error(`No session with "${peerId}" and the message carries no handshake header \u2014 cannot decrypt.`);
|
|
310
|
+
}
|
|
311
|
+
const rootKey = await responderRootKey(keystore, env2.hdr);
|
|
312
|
+
const own = await keystore.getOwnMaterial();
|
|
313
|
+
const ratchet2 = await initRatchetResponder(rootKey, {
|
|
314
|
+
publicKey: own.signedPrekey.pair.publicKey,
|
|
315
|
+
privateKey: own.signedPrekey.pair.privateKey
|
|
316
|
+
});
|
|
317
|
+
session2 = { ratchet2, role: "responder" };
|
|
318
|
+
}
|
|
319
|
+
if (!session2.ratchet2) {
|
|
320
|
+
throw new Error(`Received a v2 mDM envelope but the session with "${peerId}" is v1 \u2014 refusing to mix ratchets.`);
|
|
321
|
+
}
|
|
322
|
+
const plaintext2 = await ratchetDecrypt(
|
|
323
|
+
session2.ratchet2,
|
|
324
|
+
{ dh: fromBase64(env2.dh), pn: env2.pn, n: env2.n },
|
|
325
|
+
env2.ct
|
|
326
|
+
);
|
|
327
|
+
await keystore.putSession(peerId, session2);
|
|
328
|
+
return plaintext2;
|
|
329
|
+
}
|
|
241
330
|
const env = parseEnvelope(envelopeBytes);
|
|
242
331
|
let session = await keystore.getSession(peerId);
|
|
243
332
|
if (!session) {
|
|
244
333
|
if (!env.hdr) {
|
|
245
|
-
throw new Error(
|
|
246
|
-
`No session with "${peerId}" and the message carries no handshake header \u2014 cannot decrypt.`
|
|
247
|
-
);
|
|
334
|
+
throw new Error(`No session with "${peerId}" and the message carries no handshake header \u2014 cannot decrypt.`);
|
|
248
335
|
}
|
|
249
|
-
const
|
|
250
|
-
let oneTimePreKeyPrivateKey;
|
|
251
|
-
if (env.hdr.opk !== void 0) {
|
|
252
|
-
oneTimePreKeyPrivateKey = await keystore.takeOneTimePrekey(env.hdr.opk);
|
|
253
|
-
if (!oneTimePreKeyPrivateKey) {
|
|
254
|
-
throw new Error(
|
|
255
|
-
`Handshake references one-time prekey ${env.hdr.opk} which is unknown or already consumed.`
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
const { rootKey } = await performX3dhResponder(
|
|
260
|
-
{
|
|
261
|
-
identityPrivateKey: own.identity.privateKey,
|
|
262
|
-
signedPreKeyPrivateKey: own.signedPrekey.pair.privateKey,
|
|
263
|
-
oneTimePreKeyPrivateKey
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
initiatorIdentityPublicKey: fromBase64(env.hdr.ik),
|
|
267
|
-
initiatorEphemeralPublicKey: fromBase64(env.hdr.ek),
|
|
268
|
-
usedOneTimePreKeyId: env.hdr.opk
|
|
269
|
-
}
|
|
270
|
-
);
|
|
336
|
+
const rootKey = await responderRootKey(keystore, env.hdr);
|
|
271
337
|
const ratchet = await initializeRatchet(rootKey, "responder");
|
|
272
338
|
session = { ratchet, role: "responder" };
|
|
273
339
|
}
|
|
340
|
+
if (!session.ratchet) {
|
|
341
|
+
throw new Error(`Received a v1 mDM envelope but the session with "${peerId}" is v2 \u2014 refusing to mix ratchets.`);
|
|
342
|
+
}
|
|
274
343
|
const step = await ratchetReceive(session.ratchet);
|
|
275
344
|
if (step.messageIndex !== env.i) {
|
|
276
345
|
throw new Error(
|
|
@@ -1343,97 +1412,17 @@ var mailTools = [
|
|
|
1343
1412
|
}
|
|
1344
1413
|
];
|
|
1345
1414
|
|
|
1346
|
-
// src/tools/mail-provenance.ts
|
|
1347
|
-
import { z as z8 } from "zod";
|
|
1348
|
-
var DEFAULT_SUPABASE_URL2 = "https://rooffhgbxafyjcwmwpsy.supabase.co";
|
|
1349
|
-
function supabaseUrl2() {
|
|
1350
|
-
return process.env.MOSADD_SUPABASE_URL?.replace(/\/$/, "") ?? process.env.SUPABASE_URL?.replace(/\/$/, "") ?? DEFAULT_SUPABASE_URL2;
|
|
1351
|
-
}
|
|
1352
|
-
function hubKey2() {
|
|
1353
|
-
return process.env.MOSADD_API_KEY ?? process.env.MOSADD_HUB_KEY ?? null;
|
|
1354
|
-
}
|
|
1355
|
-
var EmailAddress2 = z8.string().email().max(254);
|
|
1356
|
-
var mp0st_send_as_agent_input = z8.object({
|
|
1357
|
-
to: z8.union([EmailAddress2, z8.array(EmailAddress2).min(1).max(50)]),
|
|
1358
|
-
subject: z8.string().min(1).max(998),
|
|
1359
|
-
body_text: z8.string().max(1048576).optional(),
|
|
1360
|
-
body_html: z8.string().max(1048576).optional(),
|
|
1361
|
-
cc: z8.array(EmailAddress2).max(50).optional(),
|
|
1362
|
-
bcc: z8.array(EmailAddress2).max(50).optional(),
|
|
1363
|
-
reply_to: EmailAddress2.optional(),
|
|
1364
|
-
tracking: z8.boolean().optional(),
|
|
1365
|
-
agent_id: z8.string().min(1).max(120).describe("Stable id of the agent doing the send. Stamped as sent_by_agent_id for provenance."),
|
|
1366
|
-
task_id: z8.string().min(1).max(120).optional().describe("Optional id of the task/run this send belongs to. Stamped as sent_by_task_id.")
|
|
1367
|
-
});
|
|
1368
|
-
async function mintHubClaim(agentId, taskId) {
|
|
1369
|
-
const key = hubKey2();
|
|
1370
|
-
if (!key) {
|
|
1371
|
-
throw new Error("mp0st_send_as_agent needs MOSADD_API_KEY (hub key) to mint a provenance claim.");
|
|
1372
|
-
}
|
|
1373
|
-
const r = await fetch(`${supabaseUrl2()}/functions/v1/hub-claim-mint`, {
|
|
1374
|
-
method: "POST",
|
|
1375
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
|
|
1376
|
-
body: JSON.stringify({ scope: "mail:send", agent_id: agentId, task_id: taskId ?? null })
|
|
1377
|
-
});
|
|
1378
|
-
if (!r.ok) {
|
|
1379
|
-
const b = await r.text().catch(() => "");
|
|
1380
|
-
throw new Error(`hub-claim-mint ${r.status}: ${b.slice(0, 200)}`);
|
|
1381
|
-
}
|
|
1382
|
-
const data = await r.json();
|
|
1383
|
-
if (!data?.token) throw new Error("hub-claim-mint: no token in response");
|
|
1384
|
-
return data.token;
|
|
1385
|
-
}
|
|
1386
|
-
async function mp0st_send_as_agent(input, ctx) {
|
|
1387
|
-
if (!input.body_text && !input.body_html) {
|
|
1388
|
-
throw new Error("mp0st_send_as_agent requires at least one of body_text or body_html.");
|
|
1389
|
-
}
|
|
1390
|
-
const claim = await mintHubClaim(input.agent_id, input.task_id);
|
|
1391
|
-
ctx.log("debug", "mp0st_send_as_agent invoking mp0st-send with hub-claim", { agent_id: input.agent_id });
|
|
1392
|
-
const { agent_id, task_id, ...mailFields } = input;
|
|
1393
|
-
const r = await fetch(`${supabaseUrl2()}/functions/v1/mp0st-send`, {
|
|
1394
|
-
method: "POST",
|
|
1395
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${claim}` },
|
|
1396
|
-
body: JSON.stringify({
|
|
1397
|
-
...mailFields,
|
|
1398
|
-
sent_by: "agent",
|
|
1399
|
-
sent_by_agent_id: agent_id,
|
|
1400
|
-
sent_by_task_id: task_id ?? null
|
|
1401
|
-
})
|
|
1402
|
-
});
|
|
1403
|
-
if (!r.ok) {
|
|
1404
|
-
const b = await r.text().catch(() => "");
|
|
1405
|
-
throw new Error(`mp0st-send ${r.status}: ${b.slice(0, 200)}`);
|
|
1406
|
-
}
|
|
1407
|
-
const res = await r.json();
|
|
1408
|
-
if (res.error) throw new Error(res.error);
|
|
1409
|
-
return {
|
|
1410
|
-
message_id: res.email_id ?? "",
|
|
1411
|
-
status: res.status ?? "sent",
|
|
1412
|
-
is_internal: res.is_internal ?? false,
|
|
1413
|
-
sent_by: "agent"
|
|
1414
|
-
};
|
|
1415
|
-
}
|
|
1416
|
-
var mailProvenanceTools = [
|
|
1417
|
-
{
|
|
1418
|
-
name: "mp0st_send_as_agent",
|
|
1419
|
-
requires: "network",
|
|
1420
|
-
description: "Send an email ATTRIBUTED TO THE AGENT (provenance-stamped). Unlike mp0st_send (sends as the user), this stamps sent_by='agent' plus your agent_id and optional task_id onto the email record and audit trail \u2014 so recipients and compliance can see the mail was agent-originated. Auth: presents a hub-claim JWT (needs MOSADD_API_KEY). SCAFFOLD: depends on mp0st-send honoring the hub-claim + provenance fields (TODO Lane A).",
|
|
1421
|
-
inputSchema: mp0st_send_as_agent_input,
|
|
1422
|
-
handler: mp0st_send_as_agent
|
|
1423
|
-
}
|
|
1424
|
-
];
|
|
1425
|
-
|
|
1426
1415
|
// src/tools/mtalk.ts
|
|
1427
|
-
import { z as
|
|
1428
|
-
var RoomLabel =
|
|
1429
|
-
var RoomId2 =
|
|
1430
|
-
var mTALK_open_input =
|
|
1416
|
+
import { z as z8 } from "zod";
|
|
1417
|
+
var RoomLabel = z8.string().min(1).max(120).regex(/^[a-zA-Z0-9._-]+$/).describe("Human-readable room label (e.g. 'ops', 'field-team'). Used to derive a stable room id.");
|
|
1418
|
+
var RoomId2 = z8.string().min(1).describe("Room id returned by mTALK_open.");
|
|
1419
|
+
var mTALK_open_input = z8.object({
|
|
1431
1420
|
label: RoomLabel.optional().describe("Optional label; defaults to a personal room.")
|
|
1432
1421
|
});
|
|
1433
|
-
var mTALK_join_input =
|
|
1434
|
-
var mTALK_press_input =
|
|
1435
|
-
var mTALK_release_input =
|
|
1436
|
-
var mTALK_state_input =
|
|
1422
|
+
var mTALK_join_input = z8.object({ room_id: RoomId2 });
|
|
1423
|
+
var mTALK_press_input = z8.object({ room_id: RoomId2 });
|
|
1424
|
+
var mTALK_release_input = z8.object({ room_id: RoomId2 });
|
|
1425
|
+
var mTALK_state_input = z8.object({ room_id: RoomId2 });
|
|
1437
1426
|
async function mTALK_open(input, ctx) {
|
|
1438
1427
|
const { roomId } = await ctx.providers.voice.createRoom(input.label);
|
|
1439
1428
|
ctx.log("debug", "mTALK_open", { room_id: roomId });
|
|
@@ -1497,7 +1486,7 @@ var mtalkTools = [
|
|
|
1497
1486
|
];
|
|
1498
1487
|
|
|
1499
1488
|
// src/tools/attachments.ts
|
|
1500
|
-
import { z as
|
|
1489
|
+
import { z as z9 } from "zod";
|
|
1501
1490
|
|
|
1502
1491
|
// src/providers/blob-upload.ts
|
|
1503
1492
|
function defaultBucket(kind) {
|
|
@@ -1547,14 +1536,14 @@ function decodeBase64Body(b64) {
|
|
|
1547
1536
|
|
|
1548
1537
|
// src/tools/attachments.ts
|
|
1549
1538
|
var PROTOCOL_VERSION4 = "mosadd.chat.v1";
|
|
1550
|
-
var Base64Body =
|
|
1551
|
-
var Mime =
|
|
1552
|
-
var DurationMs =
|
|
1553
|
-
var Filename =
|
|
1554
|
-
var ReplyTo =
|
|
1555
|
-
var ContactRef3 =
|
|
1556
|
-
var RoomId3 =
|
|
1557
|
-
var ThreadLabel =
|
|
1539
|
+
var Base64Body = z9.string().min(1).max(2e7).describe("Attachment bytes as base64 (or a data: URL). MCP is JSON-only, so binary is base64-encoded. Max ~15 MB decoded.");
|
|
1540
|
+
var Mime = z9.string().min(1).max(120).describe("MIME type, e.g. audio/ogg, application/pdf, image/png.");
|
|
1541
|
+
var DurationMs = z9.number().int().positive().optional().describe("Audio clip length in ms (voice only), if known.");
|
|
1542
|
+
var Filename = z9.string().min(1).max(255).optional().describe("Original filename (file only).");
|
|
1543
|
+
var ReplyTo = z9.string().optional().describe("Optional id of the message being replied to.");
|
|
1544
|
+
var ContactRef3 = z9.string().min(1).describe("Recipient identity id (UUID). Use mDM_list_contacts to find it.");
|
|
1545
|
+
var RoomId3 = z9.string().min(1).describe("Room/channel id (UUID).");
|
|
1546
|
+
var ThreadLabel = z9.string().max(120).regex(/^[a-zA-Z0-9._-]+$/).optional().describe("Optional thread label within the conversation (mDM USP: multiple threads per contact).");
|
|
1558
1547
|
function dmThreadId3(selfId, otherId, label) {
|
|
1559
1548
|
const [a, b] = [selfId, otherId].sort();
|
|
1560
1549
|
return label ? `dm:${a}:${b}:${label}` : `dm:${a}:${b}`;
|
|
@@ -1597,21 +1586,21 @@ async function resolveLinkedSpaceId2(channelId) {
|
|
|
1597
1586
|
if (!spaceId) throw new Error(`Channel ${channelId} has no linked space yet \u2014 run mIRC_join/mIRC_list first or pass space_id.`);
|
|
1598
1587
|
return spaceId;
|
|
1599
1588
|
}
|
|
1600
|
-
var mDM_send_voice_input =
|
|
1589
|
+
var mDM_send_voice_input = z9.object({
|
|
1601
1590
|
to: ContactRef3,
|
|
1602
1591
|
audio_base64: Base64Body,
|
|
1603
1592
|
mime: Mime.default("audio/ogg"),
|
|
1604
1593
|
duration_ms: DurationMs,
|
|
1605
|
-
caption:
|
|
1594
|
+
caption: z9.string().max(2e3).optional(),
|
|
1606
1595
|
thread_label: ThreadLabel,
|
|
1607
1596
|
reply_to_id: ReplyTo
|
|
1608
1597
|
});
|
|
1609
|
-
var mDM_send_file_input =
|
|
1598
|
+
var mDM_send_file_input = z9.object({
|
|
1610
1599
|
to: ContactRef3,
|
|
1611
1600
|
file_base64: Base64Body,
|
|
1612
1601
|
filename: Filename,
|
|
1613
1602
|
mime: Mime,
|
|
1614
|
-
caption:
|
|
1603
|
+
caption: z9.string().max(2e3).optional(),
|
|
1615
1604
|
thread_label: ThreadLabel,
|
|
1616
1605
|
reply_to_id: ReplyTo
|
|
1617
1606
|
});
|
|
@@ -1657,23 +1646,23 @@ async function mDM_send_file(input, ctx) {
|
|
|
1657
1646
|
recipient_account_id: input.to
|
|
1658
1647
|
});
|
|
1659
1648
|
}
|
|
1660
|
-
var mIRC_send_voice_input =
|
|
1649
|
+
var mIRC_send_voice_input = z9.object({
|
|
1661
1650
|
channel_id: RoomId3,
|
|
1662
1651
|
audio_base64: Base64Body,
|
|
1663
1652
|
mime: Mime.default("audio/ogg"),
|
|
1664
1653
|
duration_ms: DurationMs,
|
|
1665
|
-
caption:
|
|
1654
|
+
caption: z9.string().max(2e3).optional(),
|
|
1666
1655
|
reply_to_id: ReplyTo,
|
|
1667
|
-
space_id:
|
|
1656
|
+
space_id: z9.string().optional().describe("Backing space id. Resolved automatically if omitted.")
|
|
1668
1657
|
});
|
|
1669
|
-
var mIRC_send_file_input =
|
|
1658
|
+
var mIRC_send_file_input = z9.object({
|
|
1670
1659
|
channel_id: RoomId3,
|
|
1671
1660
|
file_base64: Base64Body,
|
|
1672
1661
|
filename: Filename,
|
|
1673
1662
|
mime: Mime,
|
|
1674
|
-
caption:
|
|
1663
|
+
caption: z9.string().max(2e3).optional(),
|
|
1675
1664
|
reply_to_id: ReplyTo,
|
|
1676
|
-
space_id:
|
|
1665
|
+
space_id: z9.string().optional()
|
|
1677
1666
|
});
|
|
1678
1667
|
async function mIRC_send_voice(input, ctx) {
|
|
1679
1668
|
const space_id = input.space_id ?? await resolveLinkedSpaceId2(input.channel_id);
|
|
@@ -1718,60 +1707,13 @@ var attachmentTools = [
|
|
|
1718
1707
|
}
|
|
1719
1708
|
];
|
|
1720
1709
|
|
|
1721
|
-
// src/tools/ptt-ingest.ts
|
|
1722
|
-
import { z as z11 } from "zod";
|
|
1723
|
-
var mTALK_ingest_ptt_input = z11.object({
|
|
1724
|
-
audio_base64: z11.string().min(1).max(2e7).describe("Recorded PTT 'over' as base64 (or data: URL)."),
|
|
1725
|
-
mime: z11.string().min(1).max(120).default("audio/ogg"),
|
|
1726
|
-
duration_ms: z11.number().int().positive().optional(),
|
|
1727
|
-
// Routing: exactly one of room_id / channel_id identifies where the over lands.
|
|
1728
|
-
channel_id: z11.string().optional().describe("mIRC channel id \u2014 route the queued PTT into a persistent channel's PTT log."),
|
|
1729
|
-
room_id: z11.string().optional().describe("mROOM/mTALK room id \u2014 route into an ephemeral room's PTT log."),
|
|
1730
|
-
transcribe: z11.boolean().optional().describe("Request RAG transcription. Honored only if the user has opted in to rag ingest; ignored otherwise. Default true.")
|
|
1731
|
-
});
|
|
1732
|
-
async function mTALK_ingest_ptt(input, ctx) {
|
|
1733
|
-
readSupabaseEnv();
|
|
1734
|
-
if (!input.channel_id && !input.room_id) {
|
|
1735
|
-
throw new Error("mTALK_ingest_ptt requires one of channel_id or room_id to route the queued PTT.");
|
|
1736
|
-
}
|
|
1737
|
-
const prefix = input.channel_id ? `chat:${input.channel_id}` : `room:${input.room_id}`;
|
|
1738
|
-
const attachment = await uploadBlob({
|
|
1739
|
-
kind: "ptt",
|
|
1740
|
-
bytes: decodeBase64Body(input.audio_base64),
|
|
1741
|
-
mime: input.mime,
|
|
1742
|
-
prefix,
|
|
1743
|
-
duration_ms: input.duration_ms
|
|
1744
|
-
});
|
|
1745
|
-
ctx.log("debug", "mTALK_ingest_ptt invoking ptt-ingest", { prefix, transcribe: input.transcribe ?? true });
|
|
1746
|
-
const res = await invokeFunction("ptt-ingest", {
|
|
1747
|
-
attachment,
|
|
1748
|
-
channel_id: input.channel_id ?? null,
|
|
1749
|
-
room_id: input.room_id ?? null,
|
|
1750
|
-
transcribe: input.transcribe ?? true
|
|
1751
|
-
});
|
|
1752
|
-
return {
|
|
1753
|
-
ptt_id: res.ptt_id ?? "",
|
|
1754
|
-
queued: true,
|
|
1755
|
-
transcription: res.transcription ?? "queued"
|
|
1756
|
-
};
|
|
1757
|
-
}
|
|
1758
|
-
var pttIngestTools = [
|
|
1759
|
-
{
|
|
1760
|
-
name: "mTALK_ingest_ptt",
|
|
1761
|
-
requires: "network",
|
|
1762
|
-
description: "Capture a finished PTT transmission (an 'over') as a durable, QUEUED PTT message in a channel (mIRC) or room (mROOM), and \u2014 if the user has opted in to RAG \u2014 transcribe it into searchable knowledge. Pass the clip as base64 + a route (channel_id OR room_id). Complements mTALK_press/release (which only manage the live floor). SCAFFOLD: depends on the not-yet-deployed `ptt-ingest` Edge Function.",
|
|
1763
|
-
inputSchema: mTALK_ingest_ptt_input,
|
|
1764
|
-
handler: mTALK_ingest_ptt
|
|
1765
|
-
}
|
|
1766
|
-
];
|
|
1767
|
-
|
|
1768
1710
|
// src/tools/knowledge.ts
|
|
1769
|
-
import { z as
|
|
1770
|
-
var mRAG_search_input =
|
|
1771
|
-
query:
|
|
1772
|
-
top_k:
|
|
1773
|
-
source_types:
|
|
1774
|
-
thread_id:
|
|
1711
|
+
import { z as z10 } from "zod";
|
|
1712
|
+
var mRAG_search_input = z10.object({
|
|
1713
|
+
query: z10.string().min(1).max(2e3).describe("Natural-language question to answer from the user's own indexed messages/emails/calls/notes."),
|
|
1714
|
+
top_k: z10.number().int().min(1).max(25).optional().describe("Max number of source chunks to retrieve and ground the answer in. Default 8."),
|
|
1715
|
+
source_types: z10.array(z10.enum(["message", "email", "call", "note", "contact"])).optional().describe("Restrict retrieval to these source types. Omit to search everything."),
|
|
1716
|
+
thread_id: z10.string().optional().describe("Optional: restrict retrieval to a single thread id (e.g. a dm:/chat: thread).")
|
|
1775
1717
|
});
|
|
1776
1718
|
async function mRAG_search(input, ctx) {
|
|
1777
1719
|
readSupabaseEnv();
|
|
@@ -1788,12 +1730,12 @@ async function mRAG_search(input, ctx) {
|
|
|
1788
1730
|
chunks_found: data.chunks_found ?? (data.sources?.length ?? 0)
|
|
1789
1731
|
};
|
|
1790
1732
|
}
|
|
1791
|
-
var mRAG_ingest_input =
|
|
1792
|
-
content_text:
|
|
1793
|
-
source_type:
|
|
1794
|
-
source_id:
|
|
1795
|
-
thread_id:
|
|
1796
|
-
title:
|
|
1733
|
+
var mRAG_ingest_input = z10.object({
|
|
1734
|
+
content_text: z10.string().min(1).max(2e5).describe("Text to index into the user's private knowledge base (a note, document, transcript, pasted page\u2026). Chunked + embedded server-side."),
|
|
1735
|
+
source_type: z10.enum(["file", "note", "message", "email", "contact", "call"]).optional().describe("What kind of source this is. Default 'file' (a document/note). Use 'note' for ad-hoc text."),
|
|
1736
|
+
source_id: z10.string().optional().describe("Optional stable id for the source so re-ingests can be grouped."),
|
|
1737
|
+
thread_id: z10.string().optional().describe("Optional thread id to associate this knowledge with (e.g. a dm:/chat: thread)."),
|
|
1738
|
+
title: z10.string().max(300).optional().describe("Optional human title, stored in metadata.")
|
|
1797
1739
|
});
|
|
1798
1740
|
async function mRAG_ingest(input, ctx) {
|
|
1799
1741
|
readSupabaseEnv();
|
|
@@ -1808,15 +1750,15 @@ async function mRAG_ingest(input, ctx) {
|
|
|
1808
1750
|
});
|
|
1809
1751
|
return { indexed: data.indexed ?? 0, chunk_count: data.chunk_count ?? 0 };
|
|
1810
1752
|
}
|
|
1811
|
-
var mRAG_list_sources_input =
|
|
1753
|
+
var mRAG_list_sources_input = z10.object({});
|
|
1812
1754
|
async function mRAG_list_sources(_input, ctx) {
|
|
1813
1755
|
readSupabaseEnv();
|
|
1814
1756
|
ctx.log("debug", "mRAG_list_sources via rag-sources");
|
|
1815
1757
|
return await invokeFunction("rag-sources", { action: "list" });
|
|
1816
1758
|
}
|
|
1817
|
-
var mRAG_delete_input =
|
|
1818
|
-
source_id:
|
|
1819
|
-
thread_id:
|
|
1759
|
+
var mRAG_delete_input = z10.object({
|
|
1760
|
+
source_id: z10.string().optional().describe("Delete every indexed chunk with this source_id (from mRAG_list_sources)."),
|
|
1761
|
+
thread_id: z10.string().optional().describe("Delete every indexed chunk associated with this thread_id.")
|
|
1820
1762
|
}).refine((v) => v.source_id || v.thread_id, {
|
|
1821
1763
|
message: "Provide source_id or thread_id \u2014 mRAG_delete refuses to purge the whole index."
|
|
1822
1764
|
});
|
|
@@ -1861,34 +1803,34 @@ var knowledgeTools = [
|
|
|
1861
1803
|
];
|
|
1862
1804
|
|
|
1863
1805
|
// src/tools/actions.ts
|
|
1864
|
-
import { z as
|
|
1865
|
-
var formField =
|
|
1866
|
-
name:
|
|
1867
|
-
label:
|
|
1868
|
-
type:
|
|
1869
|
-
required:
|
|
1806
|
+
import { z as z11 } from "zod";
|
|
1807
|
+
var formField = z11.object({
|
|
1808
|
+
name: z11.string().min(1).max(60).describe("Field key \u2014 returned verbatim in the result."),
|
|
1809
|
+
label: z11.string().max(120).optional().describe("Human label shown to the recipient. Defaults to `name`."),
|
|
1810
|
+
type: z11.enum(["text", "email", "number", "textarea", "tel", "url"]).optional().describe("Input type. Default 'text'."),
|
|
1811
|
+
required: z11.boolean().optional().describe("Whether the recipient must fill this field.")
|
|
1870
1812
|
});
|
|
1871
|
-
var action_create_input =
|
|
1872
|
-
action_type:
|
|
1813
|
+
var action_create_input = z11.object({
|
|
1814
|
+
action_type: z11.enum(["confirm", "file_request", "form", "open_url", "screen_share"]).describe(
|
|
1873
1815
|
"What you want the recipient to do: 'confirm' (yes/no), 'file_request' (pick a file from their computer), 'form' (fill fields), 'open_url' (open a vetted https URL), 'screen_share' (recipient shares their screen so you can SEE it via comms_action_frame_get \u2014 view only)."
|
|
1874
1816
|
),
|
|
1875
|
-
message:
|
|
1876
|
-
creator_label:
|
|
1817
|
+
message: z11.string().min(1).max(2e3).describe("What you're asking \u2014 shown on the consent screen above the action UI."),
|
|
1818
|
+
creator_label: z11.string().max(80).optional().describe("How you're identified to the recipient (e.g. your agent name). Default 'Agent'."),
|
|
1877
1819
|
// confirm
|
|
1878
|
-
yes_label:
|
|
1879
|
-
no_label:
|
|
1820
|
+
yes_label: z11.string().max(40).optional().describe("[confirm] Affirmative button label. Default 'Tak'."),
|
|
1821
|
+
no_label: z11.string().max(40).optional().describe("[confirm] Negative button label. Default 'Nie'."),
|
|
1880
1822
|
// file_request
|
|
1881
|
-
accept:
|
|
1882
|
-
max_bytes:
|
|
1823
|
+
accept: z11.string().max(200).optional().describe("[file_request] Accepted file types (HTML accept attr, e.g. 'image/*,.pdf')."),
|
|
1824
|
+
max_bytes: z11.number().int().positive().max(5242880).optional().describe("[file_request] Max file size in bytes (\u2264 5 MB). NOTE: the returned file is NOT yet end-to-end encrypted \u2014 do not request sensitive files until Tier 1.1 ships."),
|
|
1883
1825
|
// form
|
|
1884
|
-
fields:
|
|
1826
|
+
fields: z11.array(formField).min(1).max(20).optional().describe("[form] Fields to collect from the recipient."),
|
|
1885
1827
|
// open_url
|
|
1886
|
-
url:
|
|
1828
|
+
url: z11.string().url().optional().describe("[open_url] The https URL to open. The full URL is shown to the recipient before they open it."),
|
|
1887
1829
|
// screen_share
|
|
1888
|
-
max_width:
|
|
1830
|
+
max_width: z11.number().int().positive().max(1920).optional().describe("[screen_share] Max captured frame width in px (default 1280). Frames are downscaled JPEGs."),
|
|
1889
1831
|
// lifecycle
|
|
1890
|
-
ttl_ms:
|
|
1891
|
-
max_uses:
|
|
1832
|
+
ttl_ms: z11.number().int().positive().optional().describe("Link lifetime in milliseconds. Default 24h, capped at 7d."),
|
|
1833
|
+
max_uses: z11.number().int().min(1).max(50).optional().describe("How many times the link can be redeemed. Default 1 (single-use).")
|
|
1892
1834
|
});
|
|
1893
1835
|
function buildParams(input) {
|
|
1894
1836
|
switch (input.action_type) {
|
|
@@ -1929,8 +1871,8 @@ async function action_create(input, ctx) {
|
|
|
1929
1871
|
expires_at: res.expires_at ?? ""
|
|
1930
1872
|
};
|
|
1931
1873
|
}
|
|
1932
|
-
var action_frame_get_input =
|
|
1933
|
-
action_id:
|
|
1874
|
+
var action_frame_get_input = z11.object({
|
|
1875
|
+
action_id: z11.string().min(1).describe("The action_id returned by comms_action_create for a 'screen_share' action you created.")
|
|
1934
1876
|
});
|
|
1935
1877
|
async function action_frame_get(input, ctx) {
|
|
1936
1878
|
readSupabaseEnv();
|
|
@@ -1971,20 +1913,20 @@ var actionTools = [
|
|
|
1971
1913
|
];
|
|
1972
1914
|
|
|
1973
1915
|
// src/tools/embed.ts
|
|
1974
|
-
import { z as
|
|
1916
|
+
import { z as z12 } from "zod";
|
|
1975
1917
|
var EMBED_CDN = (process.env.MOSADD_EMBED_CDN ?? "https://embed.mosadd.com").replace(/\/+$/, "");
|
|
1976
1918
|
var POSITIONS = ["inline", "sidebar-left", "sidebar-right", "floating-bl", "floating-br", "fullscreen"];
|
|
1977
1919
|
var SKINS = ["default", "retro-irc-1990", "terminal", "minimal-dark", "minimal-light"];
|
|
1978
|
-
var embed_create_input =
|
|
1979
|
-
channel:
|
|
1980
|
-
allowed_origins:
|
|
1981
|
-
name:
|
|
1982
|
-
position:
|
|
1983
|
-
skin:
|
|
1984
|
-
title:
|
|
1985
|
-
anon:
|
|
1986
|
-
locale:
|
|
1987
|
-
mode:
|
|
1920
|
+
var embed_create_input = z12.object({
|
|
1921
|
+
channel: z12.string().min(1).max(128).regex(/^[A-Za-z0-9_-]+$/).describe("The mIRC channel id everyone on the embed shares (e.g. 'acme-support'). Auto-created on first message if new."),
|
|
1922
|
+
allowed_origins: z12.array(z12.string().min(1)).min(1).max(10).describe("REQUIRED. Domain(s) where the widget will be served \u2014 the key only works from these origins. Use the host(s) of the app you're building, e.g. ['app.acme.com','*.acme.com']. For local testing use mode:'test' and e.g. 'localhost:3000'."),
|
|
1923
|
+
name: z12.string().max(64).optional().describe("Label for the key in the owner's dashboard. Default 'embed: <channel>'."),
|
|
1924
|
+
position: z12.enum(POSITIONS).optional().describe("Where the widget renders. Default 'inline'."),
|
|
1925
|
+
skin: z12.enum(SKINS).optional().describe("Visual skin. Default 'default' (mosadd-branded retro mIRC)."),
|
|
1926
|
+
title: z12.string().max(60).optional().describe("Header title shown in the widget. Default 'mIRC'."),
|
|
1927
|
+
anon: z12.boolean().optional().describe("Allow visitors to join with just a nick (no mosadd account). Default true."),
|
|
1928
|
+
locale: z12.enum(["en", "pl"]).optional().describe("Widget UI language. Default 'en'."),
|
|
1929
|
+
mode: z12.enum(["live", "test"]).optional().describe("Key mode \u2014 'test' for local/dev origins, 'live' for production. Default 'live'.")
|
|
1988
1930
|
});
|
|
1989
1931
|
var attrSafe = (s) => s.replace(/["'<>]/g, "");
|
|
1990
1932
|
function buildSnippet(input, key) {
|
|
@@ -2025,15 +1967,15 @@ var embedTools = [
|
|
|
2025
1967
|
];
|
|
2026
1968
|
|
|
2027
1969
|
// src/tools/threat.ts
|
|
2028
|
-
import { z as
|
|
1970
|
+
import { z as z13 } from "zod";
|
|
2029
1971
|
import {
|
|
2030
1972
|
THREAT_EVENTS,
|
|
2031
1973
|
THREAT_EVENT_COUNT,
|
|
2032
1974
|
evaluateEvent
|
|
2033
1975
|
} from "@mosadd/threat-engine";
|
|
2034
|
-
var threat_catalog_input =
|
|
2035
|
-
category:
|
|
2036
|
-
platform:
|
|
1976
|
+
var threat_catalog_input = z13.object({
|
|
1977
|
+
category: z13.enum(["COMINT", "ELINT", "MASINT", "CYBER", "BEHAVIORAL", "PRIVACY", "SIGINT", "OSINT", "MPOST"]).optional().describe("Filter the catalog to one intelligence-discipline category. Omit for the full catalog."),
|
|
1978
|
+
platform: z13.enum(["apk", "ios", "pwa", "harmony"]).optional().describe("Filter to events detectable on this platform. Omit for all platforms.")
|
|
2037
1979
|
});
|
|
2038
1980
|
async function threat_catalog(input, _ctx) {
|
|
2039
1981
|
let events = THREAT_EVENTS;
|
|
@@ -2041,10 +1983,10 @@ async function threat_catalog(input, _ctx) {
|
|
|
2041
1983
|
if (input.platform) events = events.filter((e) => e.platforms.includes(input.platform));
|
|
2042
1984
|
return { count: events.length, total: THREAT_EVENT_COUNT, events };
|
|
2043
1985
|
}
|
|
2044
|
-
var threat_classify_input =
|
|
2045
|
-
event_type:
|
|
2046
|
-
severity:
|
|
2047
|
-
details:
|
|
1986
|
+
var threat_classify_input = z13.object({
|
|
1987
|
+
event_type: z13.string().min(1).max(120).describe('Event type to classify, e.g. "SIM_SWAP", "AUTH_BRUTEFORCE", "TOLL_FRAUD". Case-insensitive.'),
|
|
1988
|
+
severity: z13.string().optional().describe('Optional producer severity hint. "killswitch" \u2192 lock_account; "critical" \u2192 revoke_sessions; anything else is informational.'),
|
|
1989
|
+
details: z13.string().max(2e3).optional().describe("Optional free-text context (informational only).")
|
|
2048
1990
|
});
|
|
2049
1991
|
async function threat_classify(input, _ctx) {
|
|
2050
1992
|
return evaluateEvent({ eventType: input.event_type, severity: input.severity, details: input.details });
|
|
@@ -2067,7 +2009,7 @@ var threatTools = [
|
|
|
2067
2009
|
];
|
|
2068
2010
|
|
|
2069
2011
|
// src/tools/capabilities.ts
|
|
2070
|
-
import { z as
|
|
2012
|
+
import { z as z14 } from "zod";
|
|
2071
2013
|
var CONTRACT_VERSION = "1.0.0";
|
|
2072
2014
|
var ALL_REQUIREMENTS = ["any", "radio", "network"];
|
|
2073
2015
|
function buildCapabilityManifest(tools) {
|
|
@@ -2090,7 +2032,7 @@ function makeCapabilitiesTool(channelTools2) {
|
|
|
2090
2032
|
name: "comms_capabilities",
|
|
2091
2033
|
requires: "any",
|
|
2092
2034
|
description: "Discover which mosadd tools are available and what transport each requires (any | radio | network). Carrier-aware hosts (e.g. off-grid radio devices) call this once to gate the tool list to what the current carrier supports. Returns a manifest with per-tool requirements grouped by transport.",
|
|
2093
|
-
inputSchema:
|
|
2035
|
+
inputSchema: z14.object({}),
|
|
2094
2036
|
handler: async () => buildCapabilityManifest([...channelTools2, tool])
|
|
2095
2037
|
};
|
|
2096
2038
|
return tool;
|
|
@@ -2107,10 +2049,14 @@ var channelTools = [
|
|
|
2107
2049
|
// ...mroomTools, // mROOM: killed (LINEAR-3414) — channel re-cut into ephemeral private mIRC
|
|
2108
2050
|
// ...mroomMessagesTools, // mROOM: killed (LINEAR-3414)
|
|
2109
2051
|
...mailTools,
|
|
2110
|
-
...mailProvenanceTools,
|
|
2052
|
+
// ...mailProvenanceTools, // mp0st_send_as_agent: SCAFFOLD — calls a non-existent hub-claim-mint
|
|
2053
|
+
// endpoint (404s every call) + sends provenance body fields the EF never reads. Unregister until
|
|
2054
|
+
// rewired onto hub-key-exchange (agent_id/task_id + mosadd_hub JWT claim). See consistency ticket.
|
|
2111
2055
|
...mtalkTools,
|
|
2112
2056
|
...attachmentTools,
|
|
2113
|
-
...pttIngestTools,
|
|
2057
|
+
// ...pttIngestTools, // mTALK_ingest_ptt: SCAFFOLD — request body doesn't match the deployed
|
|
2058
|
+
// ptt-ingest EF (needs {direction, audio_base64, mime_type, message_id|thread_id} → 400s every
|
|
2059
|
+
// call) and the PTT→RAG path needs rework. Unregister until both are fixed. See consistency ticket.
|
|
2114
2060
|
...knowledgeTools,
|
|
2115
2061
|
...actionTools,
|
|
2116
2062
|
// Action links (Tier 1): agent → user one-link browser action via action-create EF
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { DmProvider, VoiceProvider } from '@mosadd/providers';
|
|
4
|
-
import { RatchetState, SessionRole } from '@mosadd/crypto';
|
|
4
|
+
import { RatchetState, DhRatchetState, SessionRole } from '@mosadd/crypto';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* mDM end-to-end encryption — session layer (LINEAR-2357).
|
|
@@ -53,9 +53,14 @@ interface OwnPrekeyMaterial {
|
|
|
53
53
|
pair: X25519Pair;
|
|
54
54
|
}>;
|
|
55
55
|
}
|
|
56
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Persisted per-peer ratchet session. Plain data → trivially serializable.
|
|
58
|
+
* A session is either v1 (`ratchet`, symmetric) or v2 (`ratchet2`, DH ratchet /
|
|
59
|
+
* PCS). New sessions are v2; an existing v1 session keeps running v1.
|
|
60
|
+
*/
|
|
57
61
|
interface MdmSessionRecord {
|
|
58
|
-
ratchet
|
|
62
|
+
ratchet?: RatchetState;
|
|
63
|
+
ratchet2?: DhRatchetState;
|
|
59
64
|
role: SessionRole;
|
|
60
65
|
/** Handshake header still owed to the peer (initiator only, until first send). */
|
|
61
66
|
pendingHandshake?: {
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mosadd/mcp",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "3.0.0-alpha.22",
|
|
4
|
+
"mcpName": "io.github.hei33enberg/mosadd-mcp",
|
|
5
|
+
"description": "Model Context Protocol server for mosadd. Exposes the 5 live m* modules (mDM, mIRC, mTALK, mp0st, mRAG) plus comms + threat tools — 62 tools — to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
|
|
6
|
+
"homepage": "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/Hei33enberg/
|
|
9
|
+
"url": "https://github.com/Hei33enberg/mosADD-OS.git",
|
|
9
10
|
"directory": "packages/mcp"
|
|
10
11
|
},
|
|
11
12
|
"license": "Apache-2.0",
|
|
@@ -37,10 +38,10 @@
|
|
|
37
38
|
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
38
39
|
"@supabase/supabase-js": "^2.48.0",
|
|
39
40
|
"zod": "^4.3.6",
|
|
40
|
-
"@mosadd/
|
|
41
|
-
"@mosadd/
|
|
42
|
-
"@mosadd/providers": "3.0.0-alpha.
|
|
43
|
-
"@mosadd/threat-engine": "3.0.0-alpha.
|
|
41
|
+
"@mosadd/crypto": "3.0.0-alpha.22",
|
|
42
|
+
"@mosadd/protocol": "3.0.0-alpha.22",
|
|
43
|
+
"@mosadd/providers": "3.0.0-alpha.22",
|
|
44
|
+
"@mosadd/threat-engine": "3.0.0-alpha.22"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"tsup": "^8.3.5",
|
|
@@ -105,7 +105,7 @@ describe("mDM E2EE golden path — X3DH handshake + ratchet, both directions", (
|
|
|
105
105
|
const wire = backend.messages[0]!.payload;
|
|
106
106
|
const wireStr = Buffer.from(wire).toString("utf8");
|
|
107
107
|
expect(wireStr).not.toContain("first contact");
|
|
108
|
-
expect(wireStr).toContain("mosadd.e2ee.
|
|
108
|
+
expect(wireStr).toContain("mosadd.e2ee.v2"); // DH-ratchet sealed envelope (PCS — LINEAR-3409)
|
|
109
109
|
|
|
110
110
|
// 4. Bob lists the thread and decrypts Alice's message.
|
|
111
111
|
const bobView = (await tool("mDM_list")({ contact_id: "alice" }, bob)) as {
|
|
@@ -36,14 +36,22 @@ import {
|
|
|
36
36
|
verifyEd25519,
|
|
37
37
|
toBase64,
|
|
38
38
|
fromBase64,
|
|
39
|
+
initRatchetInitiator,
|
|
40
|
+
initRatchetResponder,
|
|
41
|
+
ratchetEncrypt,
|
|
42
|
+
ratchetDecrypt,
|
|
39
43
|
type EncryptedPayload,
|
|
40
44
|
type RatchetState,
|
|
45
|
+
type DhRatchetState,
|
|
41
46
|
type SessionRole,
|
|
42
47
|
} from "@mosadd/crypto";
|
|
43
48
|
import type { DmProvider } from "@mosadd/providers";
|
|
44
49
|
|
|
45
50
|
export const PREKEY_BUNDLE_VERSION = "mosadd.prekeys.v1" as const;
|
|
51
|
+
/** Legacy symmetric-ratchet envelope (no PCS). Still DECODED for back-compat. */
|
|
46
52
|
export const E2EE_ENVELOPE_VERSION = "mosadd.e2ee.v1" as const;
|
|
53
|
+
/** Double-Ratchet-with-DH envelope — post-compromise security (LINEAR-3409). New sends use this. */
|
|
54
|
+
export const E2EE_ENVELOPE_VERSION_V2 = "mosadd.e2ee.v2" as const;
|
|
47
55
|
|
|
48
56
|
const DEFAULT_ONE_TIME_PREKEYS = 8;
|
|
49
57
|
|
|
@@ -79,9 +87,14 @@ export interface PublicPrekeyBundle {
|
|
|
79
87
|
signature: Uint8Array;
|
|
80
88
|
}
|
|
81
89
|
|
|
82
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Persisted per-peer ratchet session. Plain data → trivially serializable.
|
|
92
|
+
* A session is either v1 (`ratchet`, symmetric) or v2 (`ratchet2`, DH ratchet /
|
|
93
|
+
* PCS). New sessions are v2; an existing v1 session keeps running v1.
|
|
94
|
+
*/
|
|
83
95
|
export interface MdmSessionRecord {
|
|
84
|
-
ratchet
|
|
96
|
+
ratchet?: RatchetState; // v1 (legacy symmetric)
|
|
97
|
+
ratchet2?: DhRatchetState; // v2 (DH ratchet, PCS — LINEAR-3409)
|
|
85
98
|
role: SessionRole;
|
|
86
99
|
/** Handshake header still owed to the peer (initiator only, until first send). */
|
|
87
100
|
pendingHandshake?: { ik: Uint8Array; ek: Uint8Array; opkId?: number };
|
|
@@ -246,17 +259,39 @@ interface E2eeEnvelope {
|
|
|
246
259
|
ct: EncryptedPayload;
|
|
247
260
|
}
|
|
248
261
|
|
|
249
|
-
/**
|
|
262
|
+
/** v2 envelope: carries the DH ratchet header (dh/pn/n) instead of a flat index. */
|
|
263
|
+
interface E2eeEnvelopeV2 {
|
|
264
|
+
v: typeof E2EE_ENVELOPE_VERSION_V2;
|
|
265
|
+
hdr?: { ik: string; ek: string; opk?: number };
|
|
266
|
+
dh: string; // base64 ratchet public key
|
|
267
|
+
pn: number;
|
|
268
|
+
n: number;
|
|
269
|
+
ct: EncryptedPayload;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Quick check whether on-wire bytes are an mDM E2EE envelope (v1 or v2). */
|
|
250
273
|
export function isE2eeEnvelope(bytes: Uint8Array): boolean {
|
|
251
274
|
try {
|
|
252
275
|
const obj = JSON.parse(Buffer.from(bytes).toString("utf8"));
|
|
253
|
-
|
|
276
|
+
if (!obj?.ct) return false;
|
|
277
|
+
if (obj.v === E2EE_ENVELOPE_VERSION) return typeof obj.i === "number";
|
|
278
|
+
if (obj.v === E2EE_ENVELOPE_VERSION_V2) return typeof obj.dh === "string" && typeof obj.n === "number";
|
|
279
|
+
return false;
|
|
254
280
|
} catch {
|
|
255
281
|
return false;
|
|
256
282
|
}
|
|
257
283
|
}
|
|
258
284
|
|
|
259
|
-
|
|
285
|
+
/** Read the envelope version without validating the rest. */
|
|
286
|
+
function peekEnvelopeVersion(bytes: Uint8Array): string | undefined {
|
|
287
|
+
try {
|
|
288
|
+
return JSON.parse(Buffer.from(bytes).toString("utf8"))?.v;
|
|
289
|
+
} catch {
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function serializeEnvelope(env: E2eeEnvelope | E2eeEnvelopeV2): Uint8Array {
|
|
260
295
|
return new Uint8Array(Buffer.from(JSON.stringify(env), "utf8"));
|
|
261
296
|
}
|
|
262
297
|
|
|
@@ -266,6 +301,12 @@ function parseEnvelope(bytes: Uint8Array): E2eeEnvelope {
|
|
|
266
301
|
return obj as E2eeEnvelope;
|
|
267
302
|
}
|
|
268
303
|
|
|
304
|
+
function parseEnvelopeV2(bytes: Uint8Array): E2eeEnvelopeV2 {
|
|
305
|
+
const obj = JSON.parse(Buffer.from(bytes).toString("utf8"));
|
|
306
|
+
if (obj?.v !== E2EE_ENVELOPE_VERSION_V2) throw new Error(`Unsupported mDM envelope version: ${obj?.v}`);
|
|
307
|
+
return obj as E2eeEnvelopeV2;
|
|
308
|
+
}
|
|
309
|
+
|
|
269
310
|
// ---- Publish ----
|
|
270
311
|
|
|
271
312
|
/** Serialize the local bundle and hand it to the provider's key directory. */
|
|
@@ -319,18 +360,42 @@ export async function encryptForPeer(
|
|
|
319
360
|
signedPreKeyPublicKey: peer.signedPrekey.publicKey,
|
|
320
361
|
oneTimePreKeyPublicKey: opk?.publicKey,
|
|
321
362
|
});
|
|
322
|
-
|
|
363
|
+
// New sessions use the DH ratchet (v2 / PCS). The initial remote ratchet key
|
|
364
|
+
// is the peer's signed prekey (the X3DH→DR handoff). LINEAR-3409.
|
|
365
|
+
const ratchet2 = await initRatchetInitiator(rootKey, peer.signedPrekey.publicKey);
|
|
323
366
|
session = {
|
|
324
|
-
|
|
367
|
+
ratchet2,
|
|
325
368
|
role: "initiator",
|
|
326
369
|
pendingHandshake: { ik: own.identity.publicKey, ek: ephemeral.publicKey, opkId: opk?.id },
|
|
327
370
|
};
|
|
328
371
|
}
|
|
329
372
|
|
|
330
|
-
|
|
373
|
+
// v2 (DH ratchet) path for new + v2 sessions.
|
|
374
|
+
if (session.ratchet2) {
|
|
375
|
+
const { header, ct } = await ratchetEncrypt(session.ratchet2, plaintext);
|
|
376
|
+
const env: E2eeEnvelopeV2 = {
|
|
377
|
+
v: E2EE_ENVELOPE_VERSION_V2,
|
|
378
|
+
dh: toBase64(header.dh),
|
|
379
|
+
pn: header.pn,
|
|
380
|
+
n: header.n,
|
|
381
|
+
ct,
|
|
382
|
+
};
|
|
383
|
+
if (session.pendingHandshake) {
|
|
384
|
+
env.hdr = {
|
|
385
|
+
ik: toBase64(session.pendingHandshake.ik),
|
|
386
|
+
ek: toBase64(session.pendingHandshake.ek),
|
|
387
|
+
opk: session.pendingHandshake.opkId,
|
|
388
|
+
};
|
|
389
|
+
session.pendingHandshake = undefined;
|
|
390
|
+
}
|
|
391
|
+
await keystore.putSession(peerId, session);
|
|
392
|
+
return serializeEnvelope(env);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// v1 (legacy symmetric) path — only for a session already established as v1.
|
|
396
|
+
const step = await ratchetSend(session.ratchet!);
|
|
331
397
|
const ct = await encryptBytes(step.messageKey, plaintext);
|
|
332
398
|
const env: E2eeEnvelope = { v: E2EE_ENVELOPE_VERSION, i: step.messageIndex, ct };
|
|
333
|
-
|
|
334
399
|
if (session.pendingHandshake && step.messageIndex === 0) {
|
|
335
400
|
env.hdr = {
|
|
336
401
|
ik: toBase64(session.pendingHandshake.ik),
|
|
@@ -338,7 +403,6 @@ export async function encryptForPeer(
|
|
|
338
403
|
opk: session.pendingHandshake.opkId,
|
|
339
404
|
};
|
|
340
405
|
}
|
|
341
|
-
// Header owed only on the first message; clear it after.
|
|
342
406
|
session.pendingHandshake = undefined;
|
|
343
407
|
await keystore.putSession(peerId, session);
|
|
344
408
|
return serializeEnvelope(env);
|
|
@@ -350,46 +414,81 @@ export async function encryptForPeer(
|
|
|
350
414
|
* Open an envelope from `peerId`, running X3DH (responder) on the first message
|
|
351
415
|
* to derive the shared root key. Returns the inner plaintext bytes.
|
|
352
416
|
*/
|
|
417
|
+
/** Run X3DH (responder side) from a first-contact handshake header → shared root key. */
|
|
418
|
+
async function responderRootKey(
|
|
419
|
+
keystore: MdmKeyStore,
|
|
420
|
+
hdr: { ik: string; ek: string; opk?: number },
|
|
421
|
+
): Promise<Uint8Array> {
|
|
422
|
+
const own = await keystore.getOwnMaterial();
|
|
423
|
+
let oneTimePreKeyPrivateKey: Uint8Array | undefined;
|
|
424
|
+
if (hdr.opk !== undefined) {
|
|
425
|
+
oneTimePreKeyPrivateKey = await keystore.takeOneTimePrekey(hdr.opk);
|
|
426
|
+
if (!oneTimePreKeyPrivateKey) {
|
|
427
|
+
throw new Error(`Handshake references one-time prekey ${hdr.opk} which is unknown or already consumed.`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
const { rootKey } = await performX3dhResponder(
|
|
431
|
+
{
|
|
432
|
+
identityPrivateKey: own.identity.privateKey,
|
|
433
|
+
signedPreKeyPrivateKey: own.signedPrekey.pair.privateKey,
|
|
434
|
+
oneTimePreKeyPrivateKey,
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
initiatorIdentityPublicKey: fromBase64(hdr.ik),
|
|
438
|
+
initiatorEphemeralPublicKey: fromBase64(hdr.ek),
|
|
439
|
+
usedOneTimePreKeyId: hdr.opk,
|
|
440
|
+
},
|
|
441
|
+
);
|
|
442
|
+
return rootKey;
|
|
443
|
+
}
|
|
444
|
+
|
|
353
445
|
export async function decryptFromPeer(
|
|
354
446
|
keystore: MdmKeyStore,
|
|
355
447
|
peerId: string,
|
|
356
448
|
envelopeBytes: Uint8Array,
|
|
357
449
|
): Promise<Uint8Array> {
|
|
450
|
+
// v2 (DH ratchet / PCS) — LINEAR-3409.
|
|
451
|
+
if (peekEnvelopeVersion(envelopeBytes) === E2EE_ENVELOPE_VERSION_V2) {
|
|
452
|
+
const env = parseEnvelopeV2(envelopeBytes);
|
|
453
|
+
let session = await keystore.getSession(peerId);
|
|
454
|
+
if (!session) {
|
|
455
|
+
if (!env.hdr) {
|
|
456
|
+
throw new Error(`No session with "${peerId}" and the message carries no handshake header — cannot decrypt.`);
|
|
457
|
+
}
|
|
458
|
+
const rootKey = await responderRootKey(keystore, env.hdr);
|
|
459
|
+
const own = await keystore.getOwnMaterial();
|
|
460
|
+
const ratchet2 = await initRatchetResponder(rootKey, {
|
|
461
|
+
publicKey: own.signedPrekey.pair.publicKey,
|
|
462
|
+
privateKey: own.signedPrekey.pair.privateKey,
|
|
463
|
+
});
|
|
464
|
+
session = { ratchet2, role: "responder" };
|
|
465
|
+
}
|
|
466
|
+
if (!session.ratchet2) {
|
|
467
|
+
throw new Error(`Received a v2 mDM envelope but the session with "${peerId}" is v1 — refusing to mix ratchets.`);
|
|
468
|
+
}
|
|
469
|
+
const plaintext = await ratchetDecrypt(
|
|
470
|
+
session.ratchet2,
|
|
471
|
+
{ dh: fromBase64(env.dh), pn: env.pn, n: env.n },
|
|
472
|
+
env.ct,
|
|
473
|
+
);
|
|
474
|
+
await keystore.putSession(peerId, session);
|
|
475
|
+
return plaintext;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// v1 (legacy symmetric) — back-compat decode.
|
|
358
479
|
const env = parseEnvelope(envelopeBytes);
|
|
359
480
|
let session = await keystore.getSession(peerId);
|
|
360
|
-
|
|
361
481
|
if (!session) {
|
|
362
482
|
if (!env.hdr) {
|
|
363
|
-
throw new Error(
|
|
364
|
-
`No session with "${peerId}" and the message carries no handshake header — cannot decrypt.`,
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
const own = await keystore.getOwnMaterial();
|
|
368
|
-
let oneTimePreKeyPrivateKey: Uint8Array | undefined;
|
|
369
|
-
if (env.hdr.opk !== undefined) {
|
|
370
|
-
oneTimePreKeyPrivateKey = await keystore.takeOneTimePrekey(env.hdr.opk);
|
|
371
|
-
if (!oneTimePreKeyPrivateKey) {
|
|
372
|
-
throw new Error(
|
|
373
|
-
`Handshake references one-time prekey ${env.hdr.opk} which is unknown or already consumed.`,
|
|
374
|
-
);
|
|
375
|
-
}
|
|
483
|
+
throw new Error(`No session with "${peerId}" and the message carries no handshake header — cannot decrypt.`);
|
|
376
484
|
}
|
|
377
|
-
const
|
|
378
|
-
{
|
|
379
|
-
identityPrivateKey: own.identity.privateKey,
|
|
380
|
-
signedPreKeyPrivateKey: own.signedPrekey.pair.privateKey,
|
|
381
|
-
oneTimePreKeyPrivateKey,
|
|
382
|
-
},
|
|
383
|
-
{
|
|
384
|
-
initiatorIdentityPublicKey: fromBase64(env.hdr.ik),
|
|
385
|
-
initiatorEphemeralPublicKey: fromBase64(env.hdr.ek),
|
|
386
|
-
usedOneTimePreKeyId: env.hdr.opk,
|
|
387
|
-
},
|
|
388
|
-
);
|
|
485
|
+
const rootKey = await responderRootKey(keystore, env.hdr);
|
|
389
486
|
const ratchet = await initializeRatchet(rootKey, "responder");
|
|
390
487
|
session = { ratchet, role: "responder" };
|
|
391
488
|
}
|
|
392
|
-
|
|
489
|
+
if (!session.ratchet) {
|
|
490
|
+
throw new Error(`Received a v1 mDM envelope but the session with "${peerId}" is v2 — refusing to mix ratchets.`);
|
|
491
|
+
}
|
|
393
492
|
const step = await ratchetReceive(session.ratchet);
|
|
394
493
|
if (step.messageIndex !== env.i) {
|
|
395
494
|
throw new Error(
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* message row only references them by `{ bucket, path }`.
|
|
8
8
|
*
|
|
9
9
|
* This module centralises that upload so every channel's voice/file/ptt tool
|
|
10
|
-
* (mDM,
|
|
10
|
+
* (mDM, mIRC) produces an identical attachment descriptor.
|
|
11
11
|
*
|
|
12
12
|
* STATUS: scaffold. The Storage upload path below is real (supabase-js
|
|
13
13
|
* `storage.from(bucket).upload`), but two things are TODO and gated on the
|
package/src/tools/attachments.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* way a human does — including sending VOICE notes and FILES, not just text.
|
|
6
6
|
* Today only mDM has a half-measure (`mDM_voice_note`, which takes a pre-uploaded
|
|
7
7
|
* URL and posts a control envelope, NOT a first-class `voice` message via the
|
|
8
|
-
* `message-send` attachments contract).
|
|
9
|
-
*
|
|
8
|
+
* `message-send` attachments contract). mIRC has no voice/file send at all
|
|
9
|
+
* from the toolkit.
|
|
10
10
|
*
|
|
11
11
|
* These tools accept the blob as base64 (MCP is JSON-only), upload it to Storage
|
|
12
12
|
* via the shared `uploadBlob` helper, then call `message-send` with
|
package/src/tools/index.ts
CHANGED
|
@@ -24,10 +24,10 @@ import { mircEdgeTools } from "./mirc-edge.js";
|
|
|
24
24
|
// import { mroomTools } from "./mroom.js"; // mROOM: killed (LINEAR-3414) — not registered
|
|
25
25
|
// import { mroomMessagesTools } from "./mroom-messages.js"; // mROOM: killed (LINEAR-3414) — not registered
|
|
26
26
|
import { mailTools } from "./mail.js";
|
|
27
|
-
import { mailProvenanceTools } from "./mail-provenance.js";
|
|
27
|
+
// import { mailProvenanceTools } from "./mail-provenance.js"; // scaffold (mp0st_send_as_agent) — not registered, see below
|
|
28
28
|
import { mtalkTools } from "./mtalk.js";
|
|
29
29
|
import { attachmentTools } from "./attachments.js";
|
|
30
|
-
import { pttIngestTools } from "./ptt-ingest.js";
|
|
30
|
+
// import { pttIngestTools } from "./ptt-ingest.js"; // scaffold (mTALK_ingest_ptt) — not registered, see below
|
|
31
31
|
// import { mcallTools } from "./mcall.js"; // mCALL: carrier-pending — not registered (see header note)
|
|
32
32
|
import { knowledgeTools } from "./knowledge.js";
|
|
33
33
|
import { actionTools } from "./actions.js";
|
|
@@ -47,10 +47,14 @@ const channelTools: MosaddTool[] = [
|
|
|
47
47
|
// ...mroomTools, // mROOM: killed (LINEAR-3414) — channel re-cut into ephemeral private mIRC
|
|
48
48
|
// ...mroomMessagesTools, // mROOM: killed (LINEAR-3414)
|
|
49
49
|
...mailTools,
|
|
50
|
-
...mailProvenanceTools,
|
|
50
|
+
// ...mailProvenanceTools, // mp0st_send_as_agent: SCAFFOLD — calls a non-existent hub-claim-mint
|
|
51
|
+
// endpoint (404s every call) + sends provenance body fields the EF never reads. Unregister until
|
|
52
|
+
// rewired onto hub-key-exchange (agent_id/task_id + mosadd_hub JWT claim). See consistency ticket.
|
|
51
53
|
...mtalkTools,
|
|
52
54
|
...attachmentTools,
|
|
53
|
-
...pttIngestTools,
|
|
55
|
+
// ...pttIngestTools, // mTALK_ingest_ptt: SCAFFOLD — request body doesn't match the deployed
|
|
56
|
+
// ptt-ingest EF (needs {direction, audio_base64, mime_type, message_id|thread_id} → 400s every
|
|
57
|
+
// call) and the PTT→RAG path needs rework. Unregister until both are fixed. See consistency ticket.
|
|
54
58
|
...knowledgeTools,
|
|
55
59
|
...actionTools, // Action links (Tier 1): agent → user one-link browser action via action-create EF
|
|
56
60
|
...embedTools, // comms_embed_create: agent embeds a live channel into the app it builds (embed-keys EF + embed.mosadd.com widget)
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* mIRC text mode — post + list messages inside a
|
|
2
|
+
* mIRC text mode — post + list messages inside a channel.
|
|
3
3
|
*
|
|
4
4
|
* Channel messages route through the same the mosadd backend's `message-send` / `message-list`
|
|
5
|
-
* Edge Functions as DMs
|
|
5
|
+
* Edge Functions as DMs, but with `thread_id: 'chat:<channelId>'` so the
|
|
6
6
|
* RLS / access checks apply channel-membership rules. Each channel is linked to a
|
|
7
7
|
* backing space (`metadata.linked_space_id`); message-send needs that space id, so
|
|
8
8
|
* these tools resolve it from the channel automatically (or accept an override).
|
|
9
|
-
*
|
|
10
|
-
* Until now mIRC exposed only channel *management* (create/join/moderate) — there
|
|
11
|
-
* was no way to actually post or read a channel's messages from MCP. These two
|
|
12
|
-
* tools close that gap (the mROOM channels had it; mIRC did not).
|
|
13
9
|
*/
|
|
14
10
|
|
|
15
11
|
import { z } from "zod";
|
package/src/tools/mirc.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* mIRC — Persistent Channels.
|
|
3
3
|
*
|
|
4
4
|
* IRC-style persistent channels (Discord/Slack semantics). Channels live forever
|
|
5
|
-
* until deleted, members come and go.
|
|
5
|
+
* until deleted, members come and go. Ephemeral / no-account / single-action
|
|
6
|
+
* channels are PRESETS of mIRC (planned: LINEAR-3523 — TTL `expires_at` +
|
|
7
|
+
* guest-link + voice), not a separate module. The killed mROOM is absorbed here.
|
|
6
8
|
*
|
|
7
9
|
* Phase 1 alpha: wired to the mosadd backend's `channel-manage` Edge Function (strangler-fig).
|
|
8
10
|
* The single edge fn dispatches on `action` — we expose each action as its own
|
package/src/tools/ptt-ingest.ts
CHANGED
|
@@ -32,8 +32,9 @@ const mTALK_ingest_ptt_input = z.object({
|
|
|
32
32
|
mime: z.string().min(1).max(120).default("audio/ogg"),
|
|
33
33
|
duration_ms: z.number().int().positive().optional(),
|
|
34
34
|
// Routing: exactly one of room_id / channel_id identifies where the over lands.
|
|
35
|
-
channel_id: z.string().optional().describe("mIRC channel id — route the queued PTT into
|
|
36
|
-
room_id
|
|
35
|
+
channel_id: z.string().optional().describe("mIRC channel id — route the queued PTT into the channel's PTT log."),
|
|
36
|
+
// room_id retained for the rare mTALK-only PTT room (no mIRC channel backing). mROOM is gone — do NOT pass an mROOM id (will 404). Prefer channel_id.
|
|
37
|
+
room_id: z.string().optional().describe("Optional mTALK-only PTT room id (no mIRC channel backing). For mIRC channels use channel_id."),
|
|
37
38
|
transcribe: z
|
|
38
39
|
.boolean()
|
|
39
40
|
.optional()
|
|
@@ -84,7 +85,7 @@ export const pttIngestTools: MosaddTool[] = [
|
|
|
84
85
|
name: "mTALK_ingest_ptt",
|
|
85
86
|
requires: "network",
|
|
86
87
|
description:
|
|
87
|
-
"Capture a finished PTT transmission (an 'over') as a durable, QUEUED PTT message in
|
|
88
|
+
"Capture a finished PTT transmission (an 'over') as a durable, QUEUED PTT message in an mIRC channel, and — if the user has opted in to RAG — transcribe it into searchable knowledge. Pass the clip as base64 + a route (channel_id; or room_id for an mTALK-only PTT room without a channel backing). Complements mTALK_press/release (which only manage the live floor).",
|
|
88
89
|
inputSchema: mTALK_ingest_ptt_input,
|
|
89
90
|
handler: mTALK_ingest_ptt as MosaddTool["handler"],
|
|
90
91
|
},
|