@mosadd/mcp 3.0.0-alpha.52 → 3.0.0-alpha.54
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 +363 -309
- package/README.md +150 -150
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-KVN7LZFW.js → chunk-3PUOM4R5.js} +470 -112
- package/dist/index.d.ts +11 -1
- package/dist/index.js +1 -1
- package/package.json +9 -9
- package/src/__tests__/golden-path.test.ts +139 -139
- package/src/__tests__/integration.test.ts +182 -182
- package/src/__tests__/knowledge-ingest.test.ts +114 -114
- package/src/__tests__/mdm-e2ee.test.ts +212 -212
- package/src/__tests__/mdm-mcp-readable.test.ts +386 -0
- package/src/__tests__/mirc-invite.test.ts +112 -112
- package/src/__tests__/mtalk.test.ts +122 -122
- package/src/__tests__/server.test.ts +71 -71
- package/src/__tests__/serverJsonVersion.test.ts +45 -45
- package/src/__tests__/tool-count-consistency.test.ts +199 -199
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -145
- package/src/config.ts +66 -66
- package/src/crypto/mdm-session.ts +842 -502
- package/src/index.ts +19 -19
- package/src/observability/sentry.ts +79 -79
- package/src/providers/memory-voice.ts +79 -79
- package/src/providers/supabase-dm.ts +202 -122
- package/src/providers/supabase-voice.ts +91 -91
- package/src/providers/supabase.ts +231 -231
- package/src/server.ts +195 -162
- package/src/tools/__tests__/ragDeleteFoldsSourceId.test.ts +67 -67
- package/src/tools/actions.ts +166 -166
- package/src/tools/attachments.ts +276 -276
- package/src/tools/capabilities.ts +70 -70
- package/src/tools/embed.ts +110 -110
- package/src/tools/index.ts +181 -181
- package/src/tools/knowledge-graph.ts +186 -186
- package/src/tools/knowledge.ts +344 -344
- package/src/tools/mail-agentbox.ts +155 -155
- package/src/tools/mail-aliases.ts +25 -25
- package/src/tools/mail-provenance.ts +137 -137
- package/src/tools/mail.ts +403 -403
- package/src/tools/mcall.ts +216 -216
- package/src/tools/mdm-as-agent.ts +126 -126
- package/src/tools/mdm-voice.ts +220 -220
- package/src/tools/mdm.ts +211 -29
- package/src/tools/mirc-edge.ts +196 -196
- package/src/tools/mirc-members.ts +287 -287
- package/src/tools/mirc.ts +308 -308
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +221 -221
- package/src/tools/mtalk.ts +131 -131
- package/src/tools/murl.ts +314 -314
- package/src/tools/presence.ts +442 -442
- package/src/tools/ptt-ingest.ts +99 -99
- package/src/tools/threat.ts +123 -123
- package/src/types.ts +121 -121
- package/src/version.ts +8 -8
- package/src/voice/floor.ts +132 -132
- package/LICENSE +0 -201
|
@@ -148,6 +148,8 @@ function formatVoiceIfAny(text) {
|
|
|
148
148
|
// src/crypto/mdm-session.ts
|
|
149
149
|
import {
|
|
150
150
|
decryptBytes,
|
|
151
|
+
deriveHkdfKey,
|
|
152
|
+
deriveSharedSecret,
|
|
151
153
|
encryptBytes,
|
|
152
154
|
generateEd25519KeyPair,
|
|
153
155
|
generateX25519KeyPair,
|
|
@@ -211,6 +213,207 @@ var InMemoryMdmKeyStore = class {
|
|
|
211
213
|
function randomId() {
|
|
212
214
|
return crypto.getRandomValues(new Uint32Array(1))[0];
|
|
213
215
|
}
|
|
216
|
+
var X25519_BASE_POINT = (() => {
|
|
217
|
+
const b = new Uint8Array(32);
|
|
218
|
+
b[0] = 9;
|
|
219
|
+
return b;
|
|
220
|
+
})();
|
|
221
|
+
async function x25519PairFromSeed(seed) {
|
|
222
|
+
const privateKey = seed.length === 32 ? seed : seed.slice(0, 32);
|
|
223
|
+
const publicKey = await deriveSharedSecret(privateKey, X25519_BASE_POINT);
|
|
224
|
+
return { privateKey, publicKey };
|
|
225
|
+
}
|
|
226
|
+
var utf8 = new TextEncoder();
|
|
227
|
+
async function subSeed(seed, label) {
|
|
228
|
+
return deriveHkdfKey(seed, { info: utf8.encode(label), length: 32 });
|
|
229
|
+
}
|
|
230
|
+
async function deriveOwnMaterialFromSeed(seed) {
|
|
231
|
+
const [idSeed, signSeed, spkSeed] = await Promise.all([
|
|
232
|
+
subSeed(seed, "mosadd-mdm-identity-x25519"),
|
|
233
|
+
subSeed(seed, "mosadd-mdm-signing-ed25519"),
|
|
234
|
+
subSeed(seed, "mosadd-mdm-signed-prekey-x25519")
|
|
235
|
+
]);
|
|
236
|
+
return {
|
|
237
|
+
identity: await x25519PairFromSeed(idSeed),
|
|
238
|
+
signingIdentity: await generateEd25519KeyPair(signSeed),
|
|
239
|
+
signedPrekey: { id: 1, pair: await x25519PairFromSeed(spkSeed) },
|
|
240
|
+
oneTimePrekeys: []
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
async function deriveMdmSeedFromSecret(secret) {
|
|
244
|
+
return deriveHkdfKey(utf8.encode(secret), {
|
|
245
|
+
salt: utf8.encode("mosadd-mcp-api-key"),
|
|
246
|
+
info: utf8.encode("mosadd-mdm-identity-seed"),
|
|
247
|
+
length: 32
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
var SeededMdmKeyStore = class _SeededMdmKeyStore {
|
|
251
|
+
constructor(seed) {
|
|
252
|
+
this.seed = seed;
|
|
253
|
+
if (!seed || seed.length < 32) throw new Error("SeededMdmKeyStore needs a 32-byte seed");
|
|
254
|
+
}
|
|
255
|
+
seed;
|
|
256
|
+
material = null;
|
|
257
|
+
sessions = /* @__PURE__ */ new Map();
|
|
258
|
+
sentMessages = /* @__PURE__ */ new Map();
|
|
259
|
+
static async fromSecret(secret) {
|
|
260
|
+
return new _SeededMdmKeyStore(await deriveMdmSeedFromSecret(secret));
|
|
261
|
+
}
|
|
262
|
+
getOwnMaterial() {
|
|
263
|
+
if (!this.material) this.material = deriveOwnMaterialFromSeed(this.seed);
|
|
264
|
+
return this.material;
|
|
265
|
+
}
|
|
266
|
+
async takeOneTimePrekey(_id) {
|
|
267
|
+
return void 0;
|
|
268
|
+
}
|
|
269
|
+
async getSession(peerId) {
|
|
270
|
+
return this.sessions.get(peerId);
|
|
271
|
+
}
|
|
272
|
+
async putSession(peerId, record) {
|
|
273
|
+
this.sessions.set(peerId, record);
|
|
274
|
+
}
|
|
275
|
+
async putSentMessage(messageId, plaintext) {
|
|
276
|
+
this.sentMessages.set(messageId, plaintext);
|
|
277
|
+
}
|
|
278
|
+
async getSentMessage(messageId) {
|
|
279
|
+
return this.sentMessages.get(messageId);
|
|
280
|
+
}
|
|
281
|
+
/** Same label as the web's getSelfKeyBytes ("mosadd-mdm-self-read"). */
|
|
282
|
+
async getSelfKeyBytes() {
|
|
283
|
+
return deriveHkdfKey(this.seed, { info: utf8.encode("mosadd-mdm-self-read"), length: 32 });
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
var SecretMdmKeyStore = class {
|
|
287
|
+
constructor(secret) {
|
|
288
|
+
this.secret = secret;
|
|
289
|
+
}
|
|
290
|
+
secret;
|
|
291
|
+
inner = null;
|
|
292
|
+
store() {
|
|
293
|
+
if (!this.inner) this.inner = SeededMdmKeyStore.fromSecret(this.secret);
|
|
294
|
+
return this.inner;
|
|
295
|
+
}
|
|
296
|
+
async getOwnMaterial() {
|
|
297
|
+
return (await this.store()).getOwnMaterial();
|
|
298
|
+
}
|
|
299
|
+
async takeOneTimePrekey(id) {
|
|
300
|
+
return (await this.store()).takeOneTimePrekey(id);
|
|
301
|
+
}
|
|
302
|
+
async getSession(peerId) {
|
|
303
|
+
return (await this.store()).getSession(peerId);
|
|
304
|
+
}
|
|
305
|
+
async putSession(peerId, record) {
|
|
306
|
+
return (await this.store()).putSession(peerId, record);
|
|
307
|
+
}
|
|
308
|
+
async putSentMessage(messageId, plaintext) {
|
|
309
|
+
return (await this.store()).putSentMessage(messageId, plaintext);
|
|
310
|
+
}
|
|
311
|
+
async getSentMessage(messageId) {
|
|
312
|
+
return (await this.store()).getSentMessage(messageId);
|
|
313
|
+
}
|
|
314
|
+
async getSelfKeyBytes() {
|
|
315
|
+
return (await this.store()).getSelfKeyBytes();
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
var SELF_TAG = "s1.";
|
|
319
|
+
var PEER_RECOVERABLE_TAG = "r1.";
|
|
320
|
+
var PEER_RECOVERABLE_INFO = "mosadd.mdm.recipient-recoverable.v1";
|
|
321
|
+
async function aesGcmSeal(tag, keyBytes, plaintext) {
|
|
322
|
+
const key = await crypto.subtle.importKey("raw", keyBytes, { name: "AES-GCM" }, false, ["encrypt"]);
|
|
323
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
324
|
+
const ct = new Uint8Array(await crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, plaintext));
|
|
325
|
+
const packed = new Uint8Array(iv.length + ct.length);
|
|
326
|
+
packed.set(iv, 0);
|
|
327
|
+
packed.set(ct, iv.length);
|
|
328
|
+
return tag + toBase64(packed);
|
|
329
|
+
}
|
|
330
|
+
async function aesGcmOpen(tag, keyBytes, sealed) {
|
|
331
|
+
if (!sealed.startsWith(tag)) return null;
|
|
332
|
+
const packed = fromBase64(sealed.slice(tag.length));
|
|
333
|
+
if (packed.length <= 12) return null;
|
|
334
|
+
const key = await crypto.subtle.importKey("raw", keyBytes, { name: "AES-GCM" }, false, ["decrypt"]);
|
|
335
|
+
const pt = await crypto.subtle.decrypt({ name: "AES-GCM", iv: packed.slice(0, 12) }, key, packed.slice(12));
|
|
336
|
+
return new Uint8Array(pt);
|
|
337
|
+
}
|
|
338
|
+
async function sealForSelf(keystore, plaintext) {
|
|
339
|
+
try {
|
|
340
|
+
const keyBytes = await keystore.getSelfKeyBytes?.() ?? null;
|
|
341
|
+
if (!keyBytes) return null;
|
|
342
|
+
return await aesGcmSeal(SELF_TAG, keyBytes, plaintext);
|
|
343
|
+
} catch {
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
async function openSelfSealed(keystore, sealed) {
|
|
348
|
+
try {
|
|
349
|
+
if (!sealed) return null;
|
|
350
|
+
const keyBytes = await keystore.getSelfKeyBytes?.() ?? null;
|
|
351
|
+
if (!keyBytes) return null;
|
|
352
|
+
return await aesGcmOpen(SELF_TAG, keyBytes, sealed);
|
|
353
|
+
} catch {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
async function pairKey(keystore, otherIdentityPublicKey) {
|
|
358
|
+
const own = await keystore.getOwnMaterial();
|
|
359
|
+
const secret = await deriveSharedSecret(own.identity.privateKey, otherIdentityPublicKey);
|
|
360
|
+
return deriveHkdfKey(secret, { info: utf8.encode(PEER_RECOVERABLE_INFO), length: 32 });
|
|
361
|
+
}
|
|
362
|
+
async function sealForPeerRecoverable(keystore, peer, plaintext) {
|
|
363
|
+
try {
|
|
364
|
+
return await aesGcmSeal(PEER_RECOVERABLE_TAG, await pairKey(keystore, peer.identityPublicKey), plaintext);
|
|
365
|
+
} catch {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
async function openPeerRecoverable(keystore, sender, sealed) {
|
|
370
|
+
try {
|
|
371
|
+
if (!sealed) return null;
|
|
372
|
+
return await aesGcmOpen(PEER_RECOVERABLE_TAG, await pairKey(keystore, sender.identityPublicKey), sealed);
|
|
373
|
+
} catch {
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
async function fetchVerifiedBundle(dm, peerId) {
|
|
378
|
+
const raw = await dm.fetchPrekeyBundle(peerId);
|
|
379
|
+
if (!raw) return null;
|
|
380
|
+
const parsed = parsePublicBundle(raw);
|
|
381
|
+
return verifyPublicBundle(parsed) ? parsed : null;
|
|
382
|
+
}
|
|
383
|
+
function sameBytes(a, b) {
|
|
384
|
+
if (a.length !== b.length) return false;
|
|
385
|
+
for (let i = 0; i < a.length; i += 1) if (a[i] !== b[i]) return false;
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
function bundlePolicyForKind(kind, opts) {
|
|
389
|
+
if (kind === "agent") {
|
|
390
|
+
return opts.explicit ? { mayPublishWhenEmpty: true, mayReplaceForeign: true } : { mayPublishWhenEmpty: false, mayReplaceForeign: false };
|
|
391
|
+
}
|
|
392
|
+
if (kind === "human") {
|
|
393
|
+
return { mayPublishWhenEmpty: opts.explicit, mayReplaceForeign: false };
|
|
394
|
+
}
|
|
395
|
+
return { mayPublishWhenEmpty: true, mayReplaceForeign: opts.explicit };
|
|
396
|
+
}
|
|
397
|
+
async function ensureOwnBundlePublished(keystore, dm, selfId, policy) {
|
|
398
|
+
const own = await keystore.getOwnMaterial();
|
|
399
|
+
const raw = await dm.fetchPrekeyBundle(selfId);
|
|
400
|
+
if (raw) {
|
|
401
|
+
let published = null;
|
|
402
|
+
try {
|
|
403
|
+
published = parsePublicBundle(raw);
|
|
404
|
+
} catch {
|
|
405
|
+
published = null;
|
|
406
|
+
}
|
|
407
|
+
if (published && sameBytes(published.identityPublicKey, own.identity.publicKey) && sameBytes(published.signingIdentityPublicKey, own.signingIdentity.publicKey) && sameBytes(published.signedPrekey.publicKey, own.signedPrekey.pair.publicKey)) {
|
|
408
|
+
return "consistent";
|
|
409
|
+
}
|
|
410
|
+
if (!policy.mayReplaceForeign) return "foreign";
|
|
411
|
+
} else if (!policy.mayPublishWhenEmpty) {
|
|
412
|
+
return "absent";
|
|
413
|
+
}
|
|
414
|
+
await dm.publishPrekeyBundle(serializePublicBundle(own));
|
|
415
|
+
return "published";
|
|
416
|
+
}
|
|
214
417
|
function bundleSigningMessage(dhIdentityPub, signedPrekeyPub) {
|
|
215
418
|
const msg = new Uint8Array(dhIdentityPub.length + signedPrekeyPub.length);
|
|
216
419
|
msg.set(dhIdentityPub, 0);
|
|
@@ -289,11 +492,6 @@ function parseEnvelopeV2(bytes) {
|
|
|
289
492
|
if (obj?.v !== E2EE_ENVELOPE_VERSION_V2) throw new Error(`Unsupported mDM envelope version: ${obj?.v}`);
|
|
290
493
|
return obj;
|
|
291
494
|
}
|
|
292
|
-
async function publishOwnPrekeys(keystore, dm) {
|
|
293
|
-
const material = await keystore.getOwnMaterial();
|
|
294
|
-
await dm.publishPrekeyBundle(serializePublicBundle(material));
|
|
295
|
-
return { oneTimePrekeyCount: material.oneTimePrekeys.length };
|
|
296
|
-
}
|
|
297
495
|
async function encryptForPeer(keystore, dm, peerId, plaintext) {
|
|
298
496
|
let session = await keystore.getSession(peerId);
|
|
299
497
|
if (!session) {
|
|
@@ -432,8 +630,116 @@ async function decryptFromPeer(keystore, peerId, envelopeBytes) {
|
|
|
432
630
|
return plaintext;
|
|
433
631
|
}
|
|
434
632
|
|
|
435
|
-
// src/
|
|
633
|
+
// src/providers/supabase-dm.ts
|
|
436
634
|
var PROTOCOL_VERSION = "mosadd.chat.v1";
|
|
635
|
+
var MDM_TEXT_MESSAGE_TYPE = "txt";
|
|
636
|
+
var MDM_MCP_SEALED_MESSAGE_TYPE = "text";
|
|
637
|
+
var SupabaseDmProvider = class {
|
|
638
|
+
cachedSelfId = null;
|
|
639
|
+
cachedSelfKind = null;
|
|
640
|
+
/**
|
|
641
|
+
* `identities.kind` of the caller ("human" | "agent" | …). An agent LINE owns its mDM
|
|
642
|
+
* identity outright (its key is its only runtime); a human's identity is anchored in the app.
|
|
643
|
+
* ensureOwnBundlePublished uses this to decide whether a stale bundle may be replaced.
|
|
644
|
+
*/
|
|
645
|
+
async selfKind() {
|
|
646
|
+
await this.selfId();
|
|
647
|
+
return this.cachedSelfKind;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* `identities.kind` of a PEER, or null when it cannot be read (RLS can_see_identity scopes rows
|
|
651
|
+
* to contacts / thread co-members; a miss is not an error). mDM_send uses it exactly like the
|
|
652
|
+
* app's ChatPanel `peerIsAgent` (theirIdent.kind === 'agent' || iAmAgent): a DM to an agent
|
|
653
|
+
* line is sent in the clear, because the line must read it (rozkaz Króla 20.09).
|
|
654
|
+
*/
|
|
655
|
+
async peerKind(peerId) {
|
|
656
|
+
try {
|
|
657
|
+
const sb = getSupabase();
|
|
658
|
+
const { data, error } = await sb.from("identities").select("kind").eq("id", peerId).limit(1).maybeSingle();
|
|
659
|
+
if (error || !data) return null;
|
|
660
|
+
return typeof data.kind === "string" ? data.kind : null;
|
|
661
|
+
} catch {
|
|
662
|
+
return null;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
async selfId() {
|
|
666
|
+
if (this.cachedSelfId) return this.cachedSelfId;
|
|
667
|
+
readSupabaseEnv();
|
|
668
|
+
const sb = getSupabase();
|
|
669
|
+
const { data: u, error: ue } = await sb.auth.getUser();
|
|
670
|
+
if (ue || !u?.user) {
|
|
671
|
+
throw new Error(
|
|
672
|
+
"Unable to resolve current user. Ensure MOSADD_USER_JWT is set to a valid Supabase session token."
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
const { data: identity, error } = await sb.from("identities").select("id, kind").eq("user_id", u.user.id).maybeSingle();
|
|
676
|
+
if (error || !identity) {
|
|
677
|
+
throw new Error("Current user has no mosadd identity row. Sign in to mosadd.com first.");
|
|
678
|
+
}
|
|
679
|
+
this.cachedSelfId = identity.id;
|
|
680
|
+
this.cachedSelfKind = typeof identity.kind === "string" ? identity.kind : null;
|
|
681
|
+
return this.cachedSelfId;
|
|
682
|
+
}
|
|
683
|
+
async send(args) {
|
|
684
|
+
const encrypted_payload = Buffer.from(args.payload).toString("base64");
|
|
685
|
+
const data = await invokeFunction("message-send", {
|
|
686
|
+
space_id: "dm",
|
|
687
|
+
thread_id: args.threadId,
|
|
688
|
+
encrypted_payload,
|
|
689
|
+
message_type: args.messageType ?? MDM_TEXT_MESSAGE_TYPE,
|
|
690
|
+
protocol_version: PROTOCOL_VERSION,
|
|
691
|
+
recipient_account_id: args.to,
|
|
692
|
+
reply_to_id: args.replyToId ?? null,
|
|
693
|
+
// Same optional columns the app writes (ircApi.sendThreadMessage); omitted when absent.
|
|
694
|
+
...args.selfPayload ? { self_payload: args.selfPayload } : {},
|
|
695
|
+
...args.recipientSelfPayload ? { recipient_self_payload: args.recipientSelfPayload } : {}
|
|
696
|
+
});
|
|
697
|
+
if (!data?.message?.id) {
|
|
698
|
+
throw new Error("message-send returned no message id");
|
|
699
|
+
}
|
|
700
|
+
return {
|
|
701
|
+
id: data.message.id,
|
|
702
|
+
deliveredAt: data.message.created_at ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
async publishPrekeyBundle(bundle) {
|
|
706
|
+
await invokeFunction("prekey-bundle-publish", {
|
|
707
|
+
bundle: Buffer.from(bundle).toString("base64")
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
async fetchPrekeyBundle(peerId) {
|
|
711
|
+
const data = await invokeFunction("prekey-bundle-fetch", {
|
|
712
|
+
peer_id: peerId
|
|
713
|
+
});
|
|
714
|
+
if (!data?.bundle) return null;
|
|
715
|
+
return new Uint8Array(Buffer.from(data.bundle, "base64"));
|
|
716
|
+
}
|
|
717
|
+
async list(args) {
|
|
718
|
+
const data = await invokeFunction("message-list", {
|
|
719
|
+
space_id: "dm",
|
|
720
|
+
thread_id: args.threadId,
|
|
721
|
+
limit: args.limit ?? 50,
|
|
722
|
+
before: args.cursor
|
|
723
|
+
});
|
|
724
|
+
return {
|
|
725
|
+
messages: (data?.messages ?? []).map((m) => ({
|
|
726
|
+
id: m.id,
|
|
727
|
+
senderId: m.sender_identity_id,
|
|
728
|
+
payload: new Uint8Array(Buffer.from(m.encrypted_payload, "base64")),
|
|
729
|
+
timestamp: m.created_at,
|
|
730
|
+
threadId: m.thread_id,
|
|
731
|
+
messageType: m.message_type ?? void 0,
|
|
732
|
+
selfPayload: m.self_payload ?? null,
|
|
733
|
+
recipientSelfPayload: m.recipient_self_payload ?? null
|
|
734
|
+
})),
|
|
735
|
+
// history mode (`before`) returns `next_before`; incremental (`since`) returns `cursor`+`has_more`.
|
|
736
|
+
nextCursor: data?.next_before ?? (data?.has_more ? data?.cursor ?? null : null)
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
// src/tools/mdm.ts
|
|
742
|
+
var PROTOCOL_VERSION2 = "mosadd.chat.v1";
|
|
437
743
|
var ContactRef = z.string().min(1).describe(
|
|
438
744
|
"Recipient identity id (UUID). Use mDM_list_contacts first to find the right id. Future versions will accept handle/email/phone directly."
|
|
439
745
|
);
|
|
@@ -496,27 +802,100 @@ function unpackPayload(payload) {
|
|
|
496
802
|
}
|
|
497
803
|
return { text: "<ciphertext>" };
|
|
498
804
|
}
|
|
805
|
+
async function selfKindOf(dm) {
|
|
806
|
+
const f = dm.selfKind;
|
|
807
|
+
return typeof f === "function" ? await f.call(dm) : null;
|
|
808
|
+
}
|
|
809
|
+
async function peerKindOf(dm, peerId) {
|
|
810
|
+
const f = dm.peerKind;
|
|
811
|
+
if (typeof f !== "function") return null;
|
|
812
|
+
try {
|
|
813
|
+
return await f.call(dm, peerId);
|
|
814
|
+
} catch {
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
499
818
|
async function mDM_send(input, ctx) {
|
|
500
819
|
const dm = ctx.providers.dm;
|
|
501
820
|
const selfId = await dm.selfId();
|
|
502
821
|
const threadId = dmThreadId(selfId, input.to, input.thread_label);
|
|
822
|
+
const keys = ctx.providers.keys;
|
|
823
|
+
const selfKind = await selfKindOf(dm);
|
|
824
|
+
const peerKind = selfKind === "agent" || input.to === selfId ? selfKind : await peerKindOf(dm, input.to);
|
|
825
|
+
if (selfKind === "agent" || peerKind === "agent") {
|
|
826
|
+
const payload = packPlaintextPayload(input.text);
|
|
827
|
+
ctx.log("debug", "mDM_send plaintext agent lane (rozkaz Krola 20.09)", {
|
|
828
|
+
thread_id: threadId,
|
|
829
|
+
self_kind: selfKind,
|
|
830
|
+
peer_kind: peerKind
|
|
831
|
+
});
|
|
832
|
+
const plainArgs = {
|
|
833
|
+
to: input.to,
|
|
834
|
+
threadId,
|
|
835
|
+
payload,
|
|
836
|
+
replyToId: input.reply_to_id,
|
|
837
|
+
messageType: MDM_TEXT_MESSAGE_TYPE
|
|
838
|
+
};
|
|
839
|
+
const result2 = await dm.send(plainArgs);
|
|
840
|
+
return {
|
|
841
|
+
message_id: result2.id,
|
|
842
|
+
delivered_at: result2.deliveredAt,
|
|
843
|
+
thread_id: threadId,
|
|
844
|
+
encrypted: false,
|
|
845
|
+
mode: "plaintext_agent_lane",
|
|
846
|
+
sender_copy: true,
|
|
847
|
+
recipient_copy: true,
|
|
848
|
+
identity: "untouched"
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
let identity = "foreign";
|
|
852
|
+
try {
|
|
853
|
+
identity = await ensureOwnBundlePublished(keys, dm, selfId, bundlePolicyForKind(selfKind, { explicit: false }));
|
|
854
|
+
} catch (err) {
|
|
855
|
+
ctx.log("warn", "mDM_send could not reconcile own prekey bundle", { error: String(err) });
|
|
856
|
+
}
|
|
857
|
+
const ourIdentityIsPublished = identity === "consistent" || identity === "published";
|
|
503
858
|
const inner = packPlaintextPayload(input.text);
|
|
504
|
-
const sealed = await encryptForPeer(
|
|
505
|
-
|
|
506
|
-
|
|
859
|
+
const sealed = await encryptForPeer(keys, dm, input.to, inner);
|
|
860
|
+
const selfPayload = selfKind !== "human" && ourIdentityIsPublished ? await sealForSelf(keys, inner) : null;
|
|
861
|
+
let recipientSelfPayload = null;
|
|
862
|
+
if (ourIdentityIsPublished && input.to !== selfId) {
|
|
863
|
+
try {
|
|
864
|
+
const peer = await fetchVerifiedBundle(dm, input.to);
|
|
865
|
+
if (peer) recipientSelfPayload = await sealForPeerRecoverable(keys, peer, inner);
|
|
866
|
+
} catch (err) {
|
|
867
|
+
ctx.log("warn", "mDM_send skipped the recipient copy", { error: String(err) });
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
ctx.log("debug", "mDM_send E2EE via DmProvider", {
|
|
871
|
+
thread_id: threadId,
|
|
872
|
+
bytes: sealed.byteLength,
|
|
873
|
+
identity,
|
|
874
|
+
sender_copy: !!selfPayload,
|
|
875
|
+
recipient_copy: !!recipientSelfPayload
|
|
876
|
+
});
|
|
877
|
+
const sendArgs = {
|
|
507
878
|
to: input.to,
|
|
508
879
|
threadId,
|
|
509
880
|
payload: sealed,
|
|
510
|
-
replyToId: input.reply_to_id
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
881
|
+
replyToId: input.reply_to_id,
|
|
882
|
+
messageType: MDM_MCP_SEALED_MESSAGE_TYPE,
|
|
883
|
+
selfPayload,
|
|
884
|
+
recipientSelfPayload
|
|
885
|
+
};
|
|
886
|
+
const result = await dm.send(sendArgs);
|
|
887
|
+
if (keys.putSentMessage) {
|
|
888
|
+
await keys.putSentMessage(result.id, inner);
|
|
514
889
|
}
|
|
515
890
|
return {
|
|
516
891
|
message_id: result.id,
|
|
517
892
|
delivered_at: result.deliveredAt,
|
|
518
893
|
thread_id: threadId,
|
|
519
|
-
encrypted: true
|
|
894
|
+
encrypted: true,
|
|
895
|
+
mode: "e2ee",
|
|
896
|
+
sender_copy: !!selfPayload,
|
|
897
|
+
recipient_copy: !!recipientSelfPayload,
|
|
898
|
+
identity
|
|
520
899
|
};
|
|
521
900
|
}
|
|
522
901
|
async function mDM_send_unencrypted(input, ctx) {
|
|
@@ -528,12 +907,14 @@ async function mDM_send_unencrypted(input, ctx) {
|
|
|
528
907
|
thread_id: threadId,
|
|
529
908
|
bytes: payload.byteLength
|
|
530
909
|
});
|
|
531
|
-
const
|
|
910
|
+
const plainArgs = {
|
|
532
911
|
to: input.to,
|
|
533
912
|
threadId,
|
|
534
913
|
payload,
|
|
535
|
-
replyToId: input.reply_to_id
|
|
536
|
-
|
|
914
|
+
replyToId: input.reply_to_id,
|
|
915
|
+
messageType: MDM_TEXT_MESSAGE_TYPE
|
|
916
|
+
};
|
|
917
|
+
const result = await dm.send(plainArgs);
|
|
537
918
|
return {
|
|
538
919
|
message_id: result.id,
|
|
539
920
|
delivered_at: result.deliveredAt,
|
|
@@ -542,9 +923,26 @@ async function mDM_send_unencrypted(input, ctx) {
|
|
|
542
923
|
};
|
|
543
924
|
}
|
|
544
925
|
async function mDM_publish_keys(_input, ctx) {
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
|
|
926
|
+
const dm = ctx.providers.dm;
|
|
927
|
+
const keys = ctx.providers.keys;
|
|
928
|
+
const selfId = await dm.selfId();
|
|
929
|
+
const identity = await ensureOwnBundlePublished(
|
|
930
|
+
keys,
|
|
931
|
+
dm,
|
|
932
|
+
selfId,
|
|
933
|
+
bundlePolicyForKind(await selfKindOf(dm), { explicit: true })
|
|
934
|
+
);
|
|
935
|
+
const { oneTimePrekeys } = await keys.getOwnMaterial();
|
|
936
|
+
ctx.log("debug", "mDM_publish_keys", { identity, one_time_prekeys: oneTimePrekeys.length });
|
|
937
|
+
if (identity === "foreign") {
|
|
938
|
+
return {
|
|
939
|
+
published: false,
|
|
940
|
+
identity,
|
|
941
|
+
one_time_prekeys: 0,
|
|
942
|
+
note: "This identity already has keys published by the mosADD app. They were left untouched: replacing them from an API key would make every conversation with you unreadable in the app."
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
return { published: identity === "published", identity, one_time_prekeys: oneTimePrekeys.length };
|
|
548
946
|
}
|
|
549
947
|
async function mDM_list(input, ctx) {
|
|
550
948
|
const dm = ctx.providers.dm;
|
|
@@ -552,8 +950,19 @@ async function mDM_list(input, ctx) {
|
|
|
552
950
|
const threadId = dmThreadId(selfId, input.contact_id, input.thread_label);
|
|
553
951
|
ctx.log("debug", "mDM_list via DmProvider", { thread_id: threadId });
|
|
554
952
|
const result = await dm.list({ threadId, limit: input.limit ?? 50, cursor: input.cursor });
|
|
953
|
+
const keys = ctx.providers.keys;
|
|
954
|
+
const bundleBySender = /* @__PURE__ */ new Map();
|
|
955
|
+
const senderBundle = (id) => {
|
|
956
|
+
let p = bundleBySender.get(id);
|
|
957
|
+
if (!p) {
|
|
958
|
+
p = fetchVerifiedBundle(dm, id).catch(() => null);
|
|
959
|
+
bundleBySender.set(id, p);
|
|
960
|
+
}
|
|
961
|
+
return p;
|
|
962
|
+
};
|
|
555
963
|
const messages = await Promise.all(
|
|
556
|
-
result.messages.map(async (
|
|
964
|
+
result.messages.map(async (raw) => {
|
|
965
|
+
const m = raw;
|
|
557
966
|
const base = {
|
|
558
967
|
id: m.id,
|
|
559
968
|
sender_identity_id: m.senderId,
|
|
@@ -564,12 +973,26 @@ async function mDM_list(input, ctx) {
|
|
|
564
973
|
return { ...base, text: formatVoiceIfAny(unpackPayload(m.payload).text), encrypted: false };
|
|
565
974
|
}
|
|
566
975
|
if (m.senderId === selfId) {
|
|
567
|
-
const
|
|
568
|
-
if (
|
|
569
|
-
return { ...base, text: formatVoiceIfAny(unpackPayload(
|
|
976
|
+
const own = await openSelfSealed(keys, m.selfPayload) ?? await keys.getSentMessage?.(m.id);
|
|
977
|
+
if (own) {
|
|
978
|
+
return { ...base, text: formatVoiceIfAny(unpackPayload(own).text), encrypted: true };
|
|
979
|
+
}
|
|
980
|
+
if (input.contact_id === selfId) {
|
|
981
|
+
try {
|
|
982
|
+
const inner = await decryptFromPeer(keys, selfId, m.payload);
|
|
983
|
+
return { ...base, text: formatVoiceIfAny(unpackPayload(inner).text), encrypted: true };
|
|
984
|
+
} catch {
|
|
985
|
+
}
|
|
570
986
|
}
|
|
571
987
|
return { ...base, text: "<encrypted \xB7 sent by you>", encrypted: true };
|
|
572
988
|
}
|
|
989
|
+
if (m.recipientSelfPayload) {
|
|
990
|
+
const bundle = await senderBundle(m.senderId);
|
|
991
|
+
const copy = (bundle ? await openPeerRecoverable(keys, bundle, m.recipientSelfPayload) : null) ?? await openSelfSealed(keys, m.recipientSelfPayload);
|
|
992
|
+
if (copy) {
|
|
993
|
+
return { ...base, text: formatVoiceIfAny(unpackPayload(copy).text), encrypted: true };
|
|
994
|
+
}
|
|
995
|
+
}
|
|
573
996
|
try {
|
|
574
997
|
const inner = await decryptFromPeer(ctx.providers.keys, m.senderId, m.payload);
|
|
575
998
|
return { ...base, text: formatVoiceIfAny(unpackPayload(inner).text), encrypted: true };
|
|
@@ -642,7 +1065,7 @@ async function mDM_edit(input, ctx) {
|
|
|
642
1065
|
);
|
|
643
1066
|
}
|
|
644
1067
|
const envelope = {
|
|
645
|
-
v:
|
|
1068
|
+
v: PROTOCOL_VERSION2,
|
|
646
1069
|
type: "text",
|
|
647
1070
|
text: input.new_text,
|
|
648
1071
|
edited: true,
|
|
@@ -683,7 +1106,7 @@ var mdmTools = [
|
|
|
683
1106
|
title: "Send encrypted DM",
|
|
684
1107
|
annotations: { readOnlyHint: false },
|
|
685
1108
|
requires: "any",
|
|
686
|
-
description: "Send
|
|
1109
|
+
description: "Send a direct message via mosadd mDM. Between two PEOPLE it is END-TO-END-ENCRYPTED; when either side is an agent line it goes in the clear (mosadd rule: agents must read their DMs), exactly like the mosadd app. Pass `to` as the recipient's mosadd identity_id (look it up with mDM_list_contacts). Establishes an X3DH + Double Ratchet session on first contact (the recipient must have run mDM_publish_keys). Optional thread_label puts the message in a named thread \u2014 mosadd USP: multiple threads per contact, unlike WhatsApp/Telegram. If the recipient has no published keys yet, use mDM_send_unencrypted.",
|
|
687
1110
|
inputSchema: mDM_send_input,
|
|
688
1111
|
handler: mDM_send
|
|
689
1112
|
},
|
|
@@ -783,7 +1206,7 @@ var mdmAsAgentTools = [
|
|
|
783
1206
|
|
|
784
1207
|
// src/tools/mdm-voice.ts
|
|
785
1208
|
import { z as z3 } from "zod";
|
|
786
|
-
var
|
|
1209
|
+
var PROTOCOL_VERSION3 = "mosadd.chat.v1";
|
|
787
1210
|
var ContactRef2 = z3.string().min(1).describe("Recipient identity id (UUID). Use mDM_list_contacts to find it.");
|
|
788
1211
|
var RoomId = z3.string().min(1).describe("Voice room id (from mDM_call_start's call_invite).");
|
|
789
1212
|
var mDM_call_start_input = z3.object({
|
|
@@ -809,7 +1232,7 @@ function dmThreadId2(selfId, otherId, label) {
|
|
|
809
1232
|
return label ? `dm:${a}:${b}:${label}` : `dm:${a}:${b}`;
|
|
810
1233
|
}
|
|
811
1234
|
function packEnvelope(obj) {
|
|
812
|
-
const envelope = { v:
|
|
1235
|
+
const envelope = { v: PROTOCOL_VERSION3, sent_at: (/* @__PURE__ */ new Date()).toISOString(), ...obj };
|
|
813
1236
|
return new Uint8Array(Buffer.from(JSON.stringify(envelope), "utf8"));
|
|
814
1237
|
}
|
|
815
1238
|
async function signalDm(ctx, to, threadLabel, envelope) {
|
|
@@ -1468,7 +1891,7 @@ async function decryptChannelPayload(channelId, payloadB64) {
|
|
|
1468
1891
|
}
|
|
1469
1892
|
|
|
1470
1893
|
// src/tools/mirc-messages.ts
|
|
1471
|
-
var
|
|
1894
|
+
var PROTOCOL_VERSION4 = "mosadd.chat.v1";
|
|
1472
1895
|
var ChannelId3 = z6.string().min(1).max(120).describe("Channel id (UUID). From mIRC_create / mIRC_list.");
|
|
1473
1896
|
var mIRC_post_message_input = z6.object({
|
|
1474
1897
|
channel_id: ChannelId3,
|
|
@@ -1487,7 +1910,7 @@ var mIRC_list_messages_input = z6.object({
|
|
|
1487
1910
|
});
|
|
1488
1911
|
function buildPlaintextEnvelope(text, replyToId) {
|
|
1489
1912
|
const envelope = {
|
|
1490
|
-
v:
|
|
1913
|
+
v: PROTOCOL_VERSION4,
|
|
1491
1914
|
type: "text",
|
|
1492
1915
|
text,
|
|
1493
1916
|
reply_to: replyToId ?? null,
|
|
@@ -1531,7 +1954,7 @@ async function mIRC_post_message(input, ctx) {
|
|
|
1531
1954
|
thread_id,
|
|
1532
1955
|
encrypted_payload: payload,
|
|
1533
1956
|
message_type: "txt",
|
|
1534
|
-
protocol_version:
|
|
1957
|
+
protocol_version: PROTOCOL_VERSION4,
|
|
1535
1958
|
reply_to_id: input.reply_to_id ?? null,
|
|
1536
1959
|
// Attribution is decided SERVER-SIDE (message-send → _shared/ownedAgent.ts): you may sign only
|
|
1537
1960
|
// as an agent you own. Sent only when asked for, so the wire shape is unchanged for every
|
|
@@ -2254,7 +2677,7 @@ function decodeBase64Body(b64) {
|
|
|
2254
2677
|
}
|
|
2255
2678
|
|
|
2256
2679
|
// src/tools/attachments.ts
|
|
2257
|
-
var
|
|
2680
|
+
var PROTOCOL_VERSION5 = "mosadd.chat.v1";
|
|
2258
2681
|
var Base64Body = z12.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.");
|
|
2259
2682
|
var Mime = z12.string().min(1).max(120).describe("MIME type, e.g. audio/ogg, application/pdf, image/png.");
|
|
2260
2683
|
var DurationMs = z12.number().int().positive().optional().describe("Audio clip length in ms (voice only), if known.");
|
|
@@ -2270,7 +2693,7 @@ function dmThreadId3(selfId, otherId, label) {
|
|
|
2270
2693
|
async function sendAttachmentMessage(ctx, args) {
|
|
2271
2694
|
readSupabaseEnv();
|
|
2272
2695
|
const captionEnvelope = {
|
|
2273
|
-
v:
|
|
2696
|
+
v: PROTOCOL_VERSION5,
|
|
2274
2697
|
type: args.message_type,
|
|
2275
2698
|
text: args.caption ?? "",
|
|
2276
2699
|
sent_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -2288,7 +2711,7 @@ async function sendAttachmentMessage(ctx, args) {
|
|
|
2288
2711
|
attachments: [args.attachment],
|
|
2289
2712
|
// TODO(Lane A): confirm field placement
|
|
2290
2713
|
encrypted_payload,
|
|
2291
|
-
protocol_version:
|
|
2714
|
+
protocol_version: PROTOCOL_VERSION5,
|
|
2292
2715
|
recipient_account_id: args.recipient_account_id ?? null,
|
|
2293
2716
|
reply_to_id: args.reply_to_id ?? null
|
|
2294
2717
|
});
|
|
@@ -3503,7 +3926,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
3503
3926
|
// package.json
|
|
3504
3927
|
var package_default = {
|
|
3505
3928
|
name: "@mosadd/mcp",
|
|
3506
|
-
version: "3.0.0-alpha.
|
|
3929
|
+
version: "3.0.0-alpha.54",
|
|
3507
3930
|
mcpName: "io.github.hei33enberg/mosadd-mcp",
|
|
3508
3931
|
description: "Model Context Protocol server for mosadd. Exposes 4 modules (mDM, mIRC, mURL, mAYL) and capabilities (mTALK, mRAG) plus comms agent-actions \u2014 85 tools \u2014 to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
|
|
3509
3932
|
homepage: "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
|
|
@@ -3578,79 +4001,6 @@ var package_default = {
|
|
|
3578
4001
|
// src/version.ts
|
|
3579
4002
|
var PKG_VERSION = package_default.version;
|
|
3580
4003
|
|
|
3581
|
-
// src/providers/supabase-dm.ts
|
|
3582
|
-
var PROTOCOL_VERSION5 = "mosadd.chat.v1";
|
|
3583
|
-
var SupabaseDmProvider = class {
|
|
3584
|
-
cachedSelfId = null;
|
|
3585
|
-
async selfId() {
|
|
3586
|
-
if (this.cachedSelfId) return this.cachedSelfId;
|
|
3587
|
-
readSupabaseEnv();
|
|
3588
|
-
const sb = getSupabase();
|
|
3589
|
-
const { data: u, error: ue } = await sb.auth.getUser();
|
|
3590
|
-
if (ue || !u?.user) {
|
|
3591
|
-
throw new Error(
|
|
3592
|
-
"Unable to resolve current user. Ensure MOSADD_USER_JWT is set to a valid Supabase session token."
|
|
3593
|
-
);
|
|
3594
|
-
}
|
|
3595
|
-
const { data: identity, error } = await sb.from("identities").select("id").eq("user_id", u.user.id).maybeSingle();
|
|
3596
|
-
if (error || !identity) {
|
|
3597
|
-
throw new Error("Current user has no mosadd identity row. Sign in to mosadd.com first.");
|
|
3598
|
-
}
|
|
3599
|
-
this.cachedSelfId = identity.id;
|
|
3600
|
-
return this.cachedSelfId;
|
|
3601
|
-
}
|
|
3602
|
-
async send(args) {
|
|
3603
|
-
const encrypted_payload = Buffer.from(args.payload).toString("base64");
|
|
3604
|
-
const data = await invokeFunction("message-send", {
|
|
3605
|
-
space_id: "dm",
|
|
3606
|
-
thread_id: args.threadId,
|
|
3607
|
-
encrypted_payload,
|
|
3608
|
-
message_type: "text",
|
|
3609
|
-
protocol_version: PROTOCOL_VERSION5,
|
|
3610
|
-
recipient_account_id: args.to,
|
|
3611
|
-
reply_to_id: args.replyToId ?? null
|
|
3612
|
-
});
|
|
3613
|
-
if (!data?.message?.id) {
|
|
3614
|
-
throw new Error("message-send returned no message id");
|
|
3615
|
-
}
|
|
3616
|
-
return {
|
|
3617
|
-
id: data.message.id,
|
|
3618
|
-
deliveredAt: data.message.created_at ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
3619
|
-
};
|
|
3620
|
-
}
|
|
3621
|
-
async publishPrekeyBundle(bundle) {
|
|
3622
|
-
await invokeFunction("prekey-bundle-publish", {
|
|
3623
|
-
bundle: Buffer.from(bundle).toString("base64")
|
|
3624
|
-
});
|
|
3625
|
-
}
|
|
3626
|
-
async fetchPrekeyBundle(peerId) {
|
|
3627
|
-
const data = await invokeFunction("prekey-bundle-fetch", {
|
|
3628
|
-
peer_id: peerId
|
|
3629
|
-
});
|
|
3630
|
-
if (!data?.bundle) return null;
|
|
3631
|
-
return new Uint8Array(Buffer.from(data.bundle, "base64"));
|
|
3632
|
-
}
|
|
3633
|
-
async list(args) {
|
|
3634
|
-
const data = await invokeFunction("message-list", {
|
|
3635
|
-
space_id: "dm",
|
|
3636
|
-
thread_id: args.threadId,
|
|
3637
|
-
limit: args.limit ?? 50,
|
|
3638
|
-
before: args.cursor
|
|
3639
|
-
});
|
|
3640
|
-
return {
|
|
3641
|
-
messages: (data?.messages ?? []).map((m) => ({
|
|
3642
|
-
id: m.id,
|
|
3643
|
-
senderId: m.sender_identity_id,
|
|
3644
|
-
payload: new Uint8Array(Buffer.from(m.encrypted_payload, "base64")),
|
|
3645
|
-
timestamp: m.created_at,
|
|
3646
|
-
threadId: m.thread_id
|
|
3647
|
-
})),
|
|
3648
|
-
// history mode (`before`) returns `next_before`; incremental (`since`) returns `cursor`+`has_more`.
|
|
3649
|
-
nextCursor: data?.next_before ?? (data?.has_more ? data?.cursor ?? null : null)
|
|
3650
|
-
};
|
|
3651
|
-
}
|
|
3652
|
-
};
|
|
3653
|
-
|
|
3654
4004
|
// src/providers/supabase-voice.ts
|
|
3655
4005
|
var ROOM_PREFIX = "mosadd-room-";
|
|
3656
4006
|
var SupabaseVoiceProvider = class {
|
|
@@ -3708,18 +4058,22 @@ function slug(s) {
|
|
|
3708
4058
|
}
|
|
3709
4059
|
|
|
3710
4060
|
// src/server.ts
|
|
3711
|
-
function defaultProviders(injected) {
|
|
4061
|
+
function defaultProviders(injected, opts = {}) {
|
|
3712
4062
|
return {
|
|
3713
4063
|
dm: injected?.dm ?? new SupabaseDmProvider(),
|
|
3714
|
-
keys: injected?.keys ??
|
|
4064
|
+
keys: injected?.keys ?? defaultKeyStore(opts.mdmSecret),
|
|
3715
4065
|
voice: injected?.voice ?? new SupabaseVoiceProvider()
|
|
3716
4066
|
};
|
|
3717
4067
|
}
|
|
4068
|
+
function defaultKeyStore(secret) {
|
|
4069
|
+
const s = (secret ?? "").trim();
|
|
4070
|
+
return s ? new SecretMdmKeyStore(s) : new InMemoryMdmKeyStore();
|
|
4071
|
+
}
|
|
3718
4072
|
function createMosaddServer(options = {}) {
|
|
3719
4073
|
const mode = options.mode ?? (options.apiKey ? "cloud" : "local");
|
|
3720
4074
|
const hubUrl = options.hubUrl ?? "https://mcp.mosadd.com";
|
|
3721
4075
|
const logLevel = options.logLevel ?? "info";
|
|
3722
|
-
const providers = defaultProviders(options.providers);
|
|
4076
|
+
const providers = defaultProviders(options.providers, { mdmSecret: options.apiKey });
|
|
3723
4077
|
const ctx = {
|
|
3724
4078
|
options: { ...options, mode, hubUrl },
|
|
3725
4079
|
providers,
|
|
@@ -3732,7 +4086,11 @@ function createMosaddServer(options = {}) {
|
|
|
3732
4086
|
}
|
|
3733
4087
|
};
|
|
3734
4088
|
if (options.autoPublishKeys) {
|
|
3735
|
-
void
|
|
4089
|
+
void (async () => {
|
|
4090
|
+
const selfId = await providers.dm.selfId();
|
|
4091
|
+
const kind = await providers.dm.selfKind?.();
|
|
4092
|
+
return ensureOwnBundlePublished(providers.keys, providers.dm, selfId, bundlePolicyForKind(kind, { explicit: false }));
|
|
4093
|
+
})().then((state) => ctx.log("debug", "auto-ensure mDM prekeys", { state })).catch((err) => ctx.log("debug", "auto-publish mDM prekeys skipped", { error: String(err) }));
|
|
3736
4094
|
}
|
|
3737
4095
|
const server = new McpServer(
|
|
3738
4096
|
{
|