@mosadd/mcp 3.0.0-alpha.31 → 3.0.0-alpha.33

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/README.md +11 -11
  3. package/dist/bin/mcp.js +1 -1
  4. package/dist/{chunk-P4ENU5MW.js → chunk-IWLN5EO5.js} +665 -140
  5. package/dist/index.js +1 -1
  6. package/package.json +15 -15
  7. package/src/__tests__/golden-path.test.ts +137 -137
  8. package/src/__tests__/integration.test.ts +179 -179
  9. package/src/__tests__/knowledge-ingest.test.ts +114 -0
  10. package/src/__tests__/mdm-e2ee.test.ts +212 -212
  11. package/src/__tests__/mtalk.test.ts +122 -122
  12. package/src/__tests__/presence.test.ts +141 -0
  13. package/src/__tests__/server.test.ts +71 -71
  14. package/src/__tests__/tool-count-consistency.test.ts +164 -0
  15. package/src/bin/login.ts +138 -138
  16. package/src/bin/mcp.ts +145 -145
  17. package/src/config.ts +66 -66
  18. package/src/crypto/mdm-session.ts +502 -502
  19. package/src/index.ts +19 -19
  20. package/src/observability/sentry.ts +79 -79
  21. package/src/providers/blob-upload.ts +116 -116
  22. package/src/providers/memory-voice.ts +79 -79
  23. package/src/providers/supabase-dm.ts +122 -122
  24. package/src/providers/supabase-voice.ts +91 -91
  25. package/src/providers/supabase.ts +148 -148
  26. package/src/server.ts +1 -1
  27. package/src/tools/actions.ts +162 -162
  28. package/src/tools/attachments.ts +268 -268
  29. package/src/tools/capabilities.ts +68 -68
  30. package/src/tools/embed.ts +108 -108
  31. package/src/tools/index.ts +173 -104
  32. package/src/tools/knowledge-graph.ts +178 -0
  33. package/src/tools/knowledge.ts +319 -191
  34. package/src/tools/mail-agentbox.ts +147 -0
  35. package/src/tools/mail-aliases.ts +25 -25
  36. package/src/tools/mail-provenance.ts +135 -135
  37. package/src/tools/mail.ts +381 -381
  38. package/src/tools/mdm.ts +476 -479
  39. package/src/tools/mirc-edge.ts +190 -190
  40. package/src/tools/mirc-members.ts +5 -5
  41. package/src/tools/mirc-messages.ts +155 -155
  42. package/src/tools/mirc.ts +63 -3
  43. package/src/tools/mroom-messages.ts +142 -142
  44. package/src/tools/mroom.ts +221 -221
  45. package/src/tools/mtalk.ts +121 -121
  46. package/src/tools/murl.ts +4 -2
  47. package/src/tools/presence.ts +208 -0
  48. package/src/types.ts +94 -94
  49. package/src/voice/floor.ts +132 -132
  50. package/LICENSE +0 -201
  51. package/dist/bin/login.d.ts +0 -13
  52. package/dist/bin/mcp.d.ts +0 -1
  53. package/dist/index.d.ts +0 -266
@@ -1,122 +1,122 @@
1
- /**
2
- * SupabaseDmProvider — the default (network) DmProvider.
3
- *
4
- * Implements the transport-agnostic `DmProvider` contract from
5
- * `@mosadd/providers` over the mosadd Supabase Edge Functions
6
- * (`message-send` / `message-list`). This is the strangler-fig network path;
7
- * a carrier-aware host injects a different DmProvider for radio.
8
- *
9
- * The provider receives OPAQUE bytes and base64-wraps them into the
10
- * `encrypted_payload` string the Edge Function expects — it does not know or
11
- * care that the bytes are (for alpha) a plaintext `mosadd.chat.v1` envelope.
12
- */
13
-
14
- import type {
15
- DmProvider,
16
- DmSendArgs,
17
- DmSendResult,
18
- DmListArgs,
19
- DmListResult,
20
- } from "@mosadd/providers";
21
- import { getSupabase, invokeFunction, readSupabaseEnv } from "./supabase.js";
22
-
23
- const PROTOCOL_VERSION = "mosadd.chat.v1";
24
-
25
- export class SupabaseDmProvider implements DmProvider {
26
- private cachedSelfId: string | null = null;
27
-
28
- async selfId(): Promise<string> {
29
- if (this.cachedSelfId) return this.cachedSelfId;
30
- readSupabaseEnv(); // fail fast with an actionable error if BYOK env missing
31
- const sb = getSupabase();
32
- const { data: u, error: ue } = await sb.auth.getUser();
33
- if (ue || !u?.user) {
34
- throw new Error(
35
- "Unable to resolve current user. Ensure MOSADD_USER_JWT is set to a valid Supabase session token.",
36
- );
37
- }
38
- const { data: identity, error } = await sb
39
- .from("identities")
40
- .select("id")
41
- .eq("user_id", u.user.id)
42
- .maybeSingle();
43
- if (error || !identity) {
44
- throw new Error("Current user has no mosadd identity row. Sign in to mosadd.com first.");
45
- }
46
- this.cachedSelfId = identity.id as string;
47
- return this.cachedSelfId;
48
- }
49
-
50
- async send(args: DmSendArgs): Promise<DmSendResult> {
51
- const encrypted_payload = Buffer.from(args.payload).toString("base64");
52
- type MessageSendResponse = { message?: { id: string; created_at: string } };
53
- const data = await invokeFunction<MessageSendResponse>("message-send", {
54
- space_id: "dm",
55
- thread_id: args.threadId,
56
- encrypted_payload,
57
- message_type: "text",
58
- protocol_version: PROTOCOL_VERSION,
59
- recipient_account_id: args.to,
60
- reply_to_id: args.replyToId ?? null,
61
- });
62
- if (!data?.message?.id) {
63
- throw new Error("message-send returned no message id");
64
- }
65
- return {
66
- id: data.message.id,
67
- deliveredAt: data.message.created_at ?? new Date().toISOString(),
68
- };
69
- }
70
-
71
- async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
72
- // Network key directory. Server-side fn (`prekey-bundle-publish`) is the
73
- // the mosadd hub's responsibility — it stores the opaque bundle keyed by the
74
- // caller's identity (resolved from the JWT). mosadd-os just ships bytes.
75
- await invokeFunction<{ ok: boolean }>("prekey-bundle-publish", {
76
- bundle: Buffer.from(bundle).toString("base64"),
77
- });
78
- }
79
-
80
- async fetchPrekeyBundle(peerId: string): Promise<Uint8Array | null> {
81
- type FetchResponse = { bundle?: string | null };
82
- const data = await invokeFunction<FetchResponse>("prekey-bundle-fetch", {
83
- peer_id: peerId,
84
- });
85
- if (!data?.bundle) return null;
86
- return new Uint8Array(Buffer.from(data.bundle, "base64"));
87
- }
88
-
89
- async list(args: DmListArgs): Promise<DmListResult> {
90
- type MessageListResponse = {
91
- messages?: Array<{
92
- id: string;
93
- sender_identity_id: string;
94
- thread_id: string;
95
- encrypted_payload: string;
96
- created_at: string;
97
- }>;
98
- cursor?: string | null;
99
- has_more?: boolean;
100
- next_before?: string | null;
101
- };
102
- // message-list paginates history via `before` (a created_at marker) and returns
103
- // the next marker as `cursor` — NOT `cursor` in / `next_cursor` out.
104
- const data = await invokeFunction<MessageListResponse>("message-list", {
105
- space_id: "dm",
106
- thread_id: args.threadId,
107
- limit: args.limit ?? 50,
108
- before: args.cursor,
109
- });
110
- return {
111
- messages: (data?.messages ?? []).map((m) => ({
112
- id: m.id,
113
- senderId: m.sender_identity_id,
114
- payload: new Uint8Array(Buffer.from(m.encrypted_payload, "base64")),
115
- timestamp: m.created_at,
116
- threadId: m.thread_id,
117
- })),
118
- // history mode (`before`) returns `next_before`; incremental (`since`) returns `cursor`+`has_more`.
119
- nextCursor: data?.next_before ?? (data?.has_more ? (data?.cursor ?? null) : null),
120
- };
121
- }
122
- }
1
+ /**
2
+ * SupabaseDmProvider — the default (network) DmProvider.
3
+ *
4
+ * Implements the transport-agnostic `DmProvider` contract from
5
+ * `@mosadd/providers` over the mosadd Supabase Edge Functions
6
+ * (`message-send` / `message-list`). This is the strangler-fig network path;
7
+ * a carrier-aware host injects a different DmProvider for radio.
8
+ *
9
+ * The provider receives OPAQUE bytes and base64-wraps them into the
10
+ * `encrypted_payload` string the Edge Function expects — it does not know or
11
+ * care that the bytes are (for alpha) a plaintext `mosadd.chat.v1` envelope.
12
+ */
13
+
14
+ import type {
15
+ DmProvider,
16
+ DmSendArgs,
17
+ DmSendResult,
18
+ DmListArgs,
19
+ DmListResult,
20
+ } from "@mosadd/providers";
21
+ import { getSupabase, invokeFunction, readSupabaseEnv } from "./supabase.js";
22
+
23
+ const PROTOCOL_VERSION = "mosadd.chat.v1";
24
+
25
+ export class SupabaseDmProvider implements DmProvider {
26
+ private cachedSelfId: string | null = null;
27
+
28
+ async selfId(): Promise<string> {
29
+ if (this.cachedSelfId) return this.cachedSelfId;
30
+ readSupabaseEnv(); // fail fast with an actionable error if BYOK env missing
31
+ const sb = getSupabase();
32
+ const { data: u, error: ue } = await sb.auth.getUser();
33
+ if (ue || !u?.user) {
34
+ throw new Error(
35
+ "Unable to resolve current user. Ensure MOSADD_USER_JWT is set to a valid Supabase session token.",
36
+ );
37
+ }
38
+ const { data: identity, error } = await sb
39
+ .from("identities")
40
+ .select("id")
41
+ .eq("user_id", u.user.id)
42
+ .maybeSingle();
43
+ if (error || !identity) {
44
+ throw new Error("Current user has no mosadd identity row. Sign in to mosadd.com first.");
45
+ }
46
+ this.cachedSelfId = identity.id as string;
47
+ return this.cachedSelfId;
48
+ }
49
+
50
+ async send(args: DmSendArgs): Promise<DmSendResult> {
51
+ const encrypted_payload = Buffer.from(args.payload).toString("base64");
52
+ type MessageSendResponse = { message?: { id: string; created_at: string } };
53
+ const data = await invokeFunction<MessageSendResponse>("message-send", {
54
+ space_id: "dm",
55
+ thread_id: args.threadId,
56
+ encrypted_payload,
57
+ message_type: "text",
58
+ protocol_version: PROTOCOL_VERSION,
59
+ recipient_account_id: args.to,
60
+ reply_to_id: args.replyToId ?? null,
61
+ });
62
+ if (!data?.message?.id) {
63
+ throw new Error("message-send returned no message id");
64
+ }
65
+ return {
66
+ id: data.message.id,
67
+ deliveredAt: data.message.created_at ?? new Date().toISOString(),
68
+ };
69
+ }
70
+
71
+ async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
72
+ // Network key directory. Server-side fn (`prekey-bundle-publish`) is the
73
+ // the mosadd hub's responsibility — it stores the opaque bundle keyed by the
74
+ // caller's identity (resolved from the JWT). mosadd-os just ships bytes.
75
+ await invokeFunction<{ ok: boolean }>("prekey-bundle-publish", {
76
+ bundle: Buffer.from(bundle).toString("base64"),
77
+ });
78
+ }
79
+
80
+ async fetchPrekeyBundle(peerId: string): Promise<Uint8Array | null> {
81
+ type FetchResponse = { bundle?: string | null };
82
+ const data = await invokeFunction<FetchResponse>("prekey-bundle-fetch", {
83
+ peer_id: peerId,
84
+ });
85
+ if (!data?.bundle) return null;
86
+ return new Uint8Array(Buffer.from(data.bundle, "base64"));
87
+ }
88
+
89
+ async list(args: DmListArgs): Promise<DmListResult> {
90
+ type MessageListResponse = {
91
+ messages?: Array<{
92
+ id: string;
93
+ sender_identity_id: string;
94
+ thread_id: string;
95
+ encrypted_payload: string;
96
+ created_at: string;
97
+ }>;
98
+ cursor?: string | null;
99
+ has_more?: boolean;
100
+ next_before?: string | null;
101
+ };
102
+ // message-list paginates history via `before` (a created_at marker) and returns
103
+ // the next marker as `cursor` — NOT `cursor` in / `next_cursor` out.
104
+ const data = await invokeFunction<MessageListResponse>("message-list", {
105
+ space_id: "dm",
106
+ thread_id: args.threadId,
107
+ limit: args.limit ?? 50,
108
+ before: args.cursor,
109
+ });
110
+ return {
111
+ messages: (data?.messages ?? []).map((m) => ({
112
+ id: m.id,
113
+ senderId: m.sender_identity_id,
114
+ payload: new Uint8Array(Buffer.from(m.encrypted_payload, "base64")),
115
+ timestamp: m.created_at,
116
+ threadId: m.thread_id,
117
+ })),
118
+ // history mode (`before`) returns `next_before`; incremental (`since`) returns `cursor`+`has_more`.
119
+ nextCursor: data?.next_before ?? (data?.has_more ? (data?.cursor ?? null) : null),
120
+ };
121
+ }
122
+ }
@@ -1,91 +1,91 @@
1
- /**
2
- * SupabaseVoiceProvider — the default (network) mTALK provider.
3
- *
4
- * Audio media: a LiveKit room, credentials minted by the existing
5
- * `livekit-token` Edge Function. Floor control: the `mtalk-floor` Edge Function
6
- * holds the AUTHORITATIVE per-room floor state (running the same reference FSM
7
- * as floor.ts) and broadcasts changes over Supabase Realtime for sub-100ms PTT
8
- * grant. mosadd-os just asks and relays the answer.
9
- */
10
-
11
- import type {
12
- VoiceProvider,
13
- FloorSnapshot,
14
- FloorRequestResult,
15
- VoiceJoinTicket,
16
- } from "@mosadd/providers";
17
- import { getSupabase, invokeFunction, readSupabaseEnv } from "./supabase.js";
18
-
19
- const ROOM_PREFIX = "mosadd-room-";
20
-
21
- export class SupabaseVoiceProvider implements VoiceProvider {
22
- private cachedSelfId: string | null = null;
23
-
24
- async selfId(): Promise<string> {
25
- if (this.cachedSelfId) return this.cachedSelfId;
26
- readSupabaseEnv();
27
- const sb = getSupabase();
28
- const { data: u, error: ue } = await sb.auth.getUser();
29
- if (ue || !u?.user) {
30
- throw new Error(
31
- "Unable to resolve current user. Ensure MOSADD_USER_JWT is set to a valid Supabase session token.",
32
- );
33
- }
34
- const { data: identity, error } = await sb
35
- .from("identities")
36
- .select("id")
37
- .eq("user_id", u.user.id)
38
- .maybeSingle();
39
- if (error || !identity) {
40
- throw new Error("Current user has no mosadd identity row. Sign in to mosadd.com first.");
41
- }
42
- this.cachedSelfId = identity.id as string;
43
- return this.cachedSelfId;
44
- }
45
-
46
- async createRoom(label?: string): Promise<{ roomId: string }> {
47
- const self = await this.selfId();
48
- const roomId = `${ROOM_PREFIX}${label ? slug(label) : self}`;
49
- // Floor row is created lazily by mtalk-floor on first request; nothing to do
50
- // here beyond returning the canonical id.
51
- return { roomId };
52
- }
53
-
54
- async joinTicket(roomId: string): Promise<VoiceJoinTicket> {
55
- const self = await this.selfId();
56
- type TokenResp = { token: string; url: string; roomName: string; identity: string };
57
- const data = await invokeFunction<TokenResp>("livekit-token", {
58
- roomName: roomId,
59
- identity: self,
60
- });
61
- return { token: data.token, url: data.url, identity: data.identity, roomId: data.roomName };
62
- }
63
-
64
- async requestFloor(roomId: string): Promise<FloorRequestResult> {
65
- return invokeFunction<FloorRequestResult>("mtalk-floor", { action: "request", room_id: roomId });
66
- }
67
-
68
- async releaseFloor(roomId: string): Promise<FloorSnapshot> {
69
- const data = await invokeFunction<{ snapshot: FloorSnapshot }>("mtalk-floor", {
70
- action: "release",
71
- room_id: roomId,
72
- });
73
- return data.snapshot;
74
- }
75
-
76
- async floorState(roomId: string): Promise<FloorSnapshot> {
77
- const data = await invokeFunction<{ snapshot: FloorSnapshot }>("mtalk-floor", {
78
- action: "state",
79
- room_id: roomId,
80
- });
81
- return data.snapshot;
82
- }
83
- }
84
-
85
- function slug(s: string): string {
86
- return s
87
- .toLowerCase()
88
- .replace(/[^a-z0-9._-]+/g, "-")
89
- .replace(/^-+|-+$/g, "")
90
- .slice(0, 200);
91
- }
1
+ /**
2
+ * SupabaseVoiceProvider — the default (network) mTALK provider.
3
+ *
4
+ * Audio media: a LiveKit room, credentials minted by the existing
5
+ * `livekit-token` Edge Function. Floor control: the `mtalk-floor` Edge Function
6
+ * holds the AUTHORITATIVE per-room floor state (running the same reference FSM
7
+ * as floor.ts) and broadcasts changes over Supabase Realtime for sub-100ms PTT
8
+ * grant. mosadd-os just asks and relays the answer.
9
+ */
10
+
11
+ import type {
12
+ VoiceProvider,
13
+ FloorSnapshot,
14
+ FloorRequestResult,
15
+ VoiceJoinTicket,
16
+ } from "@mosadd/providers";
17
+ import { getSupabase, invokeFunction, readSupabaseEnv } from "./supabase.js";
18
+
19
+ const ROOM_PREFIX = "mosadd-room-";
20
+
21
+ export class SupabaseVoiceProvider implements VoiceProvider {
22
+ private cachedSelfId: string | null = null;
23
+
24
+ async selfId(): Promise<string> {
25
+ if (this.cachedSelfId) return this.cachedSelfId;
26
+ readSupabaseEnv();
27
+ const sb = getSupabase();
28
+ const { data: u, error: ue } = await sb.auth.getUser();
29
+ if (ue || !u?.user) {
30
+ throw new Error(
31
+ "Unable to resolve current user. Ensure MOSADD_USER_JWT is set to a valid Supabase session token.",
32
+ );
33
+ }
34
+ const { data: identity, error } = await sb
35
+ .from("identities")
36
+ .select("id")
37
+ .eq("user_id", u.user.id)
38
+ .maybeSingle();
39
+ if (error || !identity) {
40
+ throw new Error("Current user has no mosadd identity row. Sign in to mosadd.com first.");
41
+ }
42
+ this.cachedSelfId = identity.id as string;
43
+ return this.cachedSelfId;
44
+ }
45
+
46
+ async createRoom(label?: string): Promise<{ roomId: string }> {
47
+ const self = await this.selfId();
48
+ const roomId = `${ROOM_PREFIX}${label ? slug(label) : self}`;
49
+ // Floor row is created lazily by mtalk-floor on first request; nothing to do
50
+ // here beyond returning the canonical id.
51
+ return { roomId };
52
+ }
53
+
54
+ async joinTicket(roomId: string): Promise<VoiceJoinTicket> {
55
+ const self = await this.selfId();
56
+ type TokenResp = { token: string; url: string; roomName: string; identity: string };
57
+ const data = await invokeFunction<TokenResp>("livekit-token", {
58
+ roomName: roomId,
59
+ identity: self,
60
+ });
61
+ return { token: data.token, url: data.url, identity: data.identity, roomId: data.roomName };
62
+ }
63
+
64
+ async requestFloor(roomId: string): Promise<FloorRequestResult> {
65
+ return invokeFunction<FloorRequestResult>("mtalk-floor", { action: "request", room_id: roomId });
66
+ }
67
+
68
+ async releaseFloor(roomId: string): Promise<FloorSnapshot> {
69
+ const data = await invokeFunction<{ snapshot: FloorSnapshot }>("mtalk-floor", {
70
+ action: "release",
71
+ room_id: roomId,
72
+ });
73
+ return data.snapshot;
74
+ }
75
+
76
+ async floorState(roomId: string): Promise<FloorSnapshot> {
77
+ const data = await invokeFunction<{ snapshot: FloorSnapshot }>("mtalk-floor", {
78
+ action: "state",
79
+ room_id: roomId,
80
+ });
81
+ return data.snapshot;
82
+ }
83
+ }
84
+
85
+ function slug(s: string): string {
86
+ return s
87
+ .toLowerCase()
88
+ .replace(/[^a-z0-9._-]+/g, "-")
89
+ .replace(/^-+|-+$/g, "")
90
+ .slice(0, 200);
91
+ }