@mosadd/mcp 3.0.0-alpha.1 → 3.0.0-alpha.10

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 (41) hide show
  1. package/README.md +127 -116
  2. package/dist/bin/login.js +4 -4
  3. package/dist/bin/mcp.js +29 -1
  4. package/dist/chunk-6EPYADVR.js +2095 -0
  5. package/dist/index.d.ts +46 -4
  6. package/dist/index.js +5 -3
  7. package/package.json +8 -5
  8. package/src/__tests__/golden-path.test.ts +137 -132
  9. package/src/__tests__/integration.test.ts +178 -175
  10. package/src/__tests__/mdm-e2ee.test.ts +178 -149
  11. package/src/__tests__/mtalk.test.ts +122 -0
  12. package/src/__tests__/server.test.ts +67 -67
  13. package/src/bin/login.ts +138 -127
  14. package/src/bin/mcp.ts +97 -55
  15. package/src/config.ts +66 -66
  16. package/src/crypto/mdm-session.ts +403 -378
  17. package/src/index.ts +19 -17
  18. package/src/observability/sentry.ts +79 -79
  19. package/src/providers/memory-voice.ts +79 -0
  20. package/src/providers/supabase-dm.ts +117 -117
  21. package/src/providers/supabase-voice.ts +91 -0
  22. package/src/providers/supabase.ts +120 -89
  23. package/src/server.ts +105 -103
  24. package/src/tools/capabilities.ts +68 -68
  25. package/src/tools/index.ts +53 -37
  26. package/src/tools/knowledge.ts +191 -0
  27. package/src/tools/mail.ts +371 -89
  28. package/src/tools/mcall.ts +216 -0
  29. package/src/tools/mdm-voice.ts +206 -0
  30. package/src/tools/mdm.ts +448 -379
  31. package/src/tools/mirc-edge.ts +190 -0
  32. package/src/tools/mirc-members.ts +177 -177
  33. package/src/tools/mirc-messages.ts +156 -0
  34. package/src/tools/mirc.ts +170 -170
  35. package/src/tools/mroom-messages.ts +142 -142
  36. package/src/tools/mroom.ts +221 -189
  37. package/src/tools/mtalk.ts +121 -0
  38. package/src/tools/murl.ts +141 -0
  39. package/src/types.ts +85 -79
  40. package/src/voice/floor.ts +132 -0
  41. package/dist/chunk-6IA4QVAJ.js +0 -1191
@@ -1,142 +1,142 @@
1
- /**
2
- * mROOM text mode — send + list messages inside a private room.
3
- *
4
- * mROOM_send_message and mROOM_list_messages route through the same
5
- * m0ssad-3 `message-send` / `message-list` Edge Functions that mDM uses,
6
- * but with `space_id: 'rooms'` and `thread_id: 'privroom:<room_id>'` so the
7
- * RLS policies apply room-membership checks rather than DM contact checks.
8
- *
9
- * Voice in rooms (PTT, audio) lands separately via mTALK_start_session
10
- * over the WebRTC daemon — see LINEAR-2145.
11
- */
12
-
13
- import { z } from "zod";
14
- import type { MosaddTool, MosaddToolContext } from "../types.js";
15
- import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
16
-
17
- const PROTOCOL_VERSION = "mosadd.chat.v1";
18
-
19
- const RoomId = z.string().min(1).describe("Private room id (UUID). From mROOM_create / mROOM_list.");
20
-
21
- const mROOM_send_message_input = z.object({
22
- room_id: RoomId,
23
- text: z.string().min(1).max(64_000).describe("Message body (UTF-8). Max 64 KB."),
24
- reply_to_id: z.string().optional().describe("Optional id of the message being replied to."),
25
- });
26
-
27
- const mROOM_list_messages_input = z.object({
28
- room_id: RoomId,
29
- limit: z.number().int().min(1).max(200).default(50).optional(),
30
- cursor: z.string().optional().describe("Opaque pagination cursor from a prior list response."),
31
- });
32
-
33
- function packPlaintextPayload(text: string, replyToId?: string): string {
34
- const envelope = {
35
- v: PROTOCOL_VERSION,
36
- type: "text",
37
- text,
38
- reply_to: replyToId ?? null,
39
- sent_at: new Date().toISOString(),
40
- };
41
- return Buffer.from(JSON.stringify(envelope), "utf8").toString("base64");
42
- }
43
-
44
- function unpackPayload(payload: string): { text: string } {
45
- try {
46
- const json = Buffer.from(payload, "base64").toString("utf8");
47
- const obj = JSON.parse(json);
48
- if (typeof obj?.text === "string") return obj;
49
- } catch {
50
- /* fall through */
51
- }
52
- return { text: "<ciphertext>" };
53
- }
54
-
55
- async function mROOM_send_message(
56
- input: z.infer<typeof mROOM_send_message_input>,
57
- ctx: MosaddToolContext,
58
- ): Promise<{ message_id: string; delivered_at: string; thread_id: string }> {
59
- readSupabaseEnv();
60
- const thread_id = `privroom:${input.room_id}`;
61
- ctx.log("debug", "mROOM_send_message", { thread_id });
62
-
63
- const data = await invokeFunction<{ message?: { id: string; created_at: string } }>(
64
- "message-send",
65
- {
66
- space_id: "rooms",
67
- thread_id,
68
- encrypted_payload: packPlaintextPayload(input.text, input.reply_to_id),
69
- message_type: "text",
70
- protocol_version: PROTOCOL_VERSION,
71
- reply_to_id: input.reply_to_id ?? null,
72
- },
73
- );
74
-
75
- if (!data?.message?.id) {
76
- throw new Error("message-send returned no message id");
77
- }
78
-
79
- return {
80
- message_id: data.message.id,
81
- delivered_at: data.message.created_at ?? new Date().toISOString(),
82
- thread_id,
83
- };
84
- }
85
-
86
- async function mROOM_list_messages(
87
- input: z.infer<typeof mROOM_list_messages_input>,
88
- ctx: MosaddToolContext,
89
- ): Promise<{
90
- messages: Array<{ id: string; sender_identity_id: string; text: string; timestamp: string }>;
91
- next_cursor: string | null;
92
- }> {
93
- readSupabaseEnv();
94
- const thread_id = `privroom:${input.room_id}`;
95
- ctx.log("debug", "mROOM_list_messages", { thread_id });
96
-
97
- type MessageListResponse = {
98
- messages?: Array<{
99
- id: string;
100
- sender_identity_id: string;
101
- encrypted_payload: string;
102
- created_at: string;
103
- }>;
104
- next_cursor?: string | null;
105
- };
106
-
107
- const data = await invokeFunction<MessageListResponse>("message-list", {
108
- space_id: "rooms",
109
- thread_id,
110
- limit: input.limit ?? 50,
111
- cursor: input.cursor,
112
- });
113
-
114
- return {
115
- messages: (data?.messages ?? []).map((m) => ({
116
- id: m.id,
117
- sender_identity_id: m.sender_identity_id,
118
- text: unpackPayload(m.encrypted_payload).text,
119
- timestamp: m.created_at,
120
- })),
121
- next_cursor: data?.next_cursor ?? null,
122
- };
123
- }
124
-
125
- export const mroomMessagesTools: MosaddTool[] = [
126
- {
127
- name: "mROOM_send_message",
128
- requires: "network",
129
- description:
130
- "Send a text message into a private room. Authorisation: must be a member (or guest with a valid token). Alpha payload is plaintext base64; v0.2 wraps with Double Ratchet.",
131
- inputSchema: mROOM_send_message_input,
132
- handler: mROOM_send_message as MosaddTool["handler"],
133
- },
134
- {
135
- name: "mROOM_list_messages",
136
- requires: "network",
137
- description:
138
- "List recent text messages in a private room. Cursor-paginated, newest first.",
139
- inputSchema: mROOM_list_messages_input,
140
- handler: mROOM_list_messages as MosaddTool["handler"],
141
- },
142
- ];
1
+ /**
2
+ * mROOM text mode — send + list messages inside a private room.
3
+ *
4
+ * mROOM_send_message and mROOM_list_messages route through the same
5
+ * the mosadd backend's `message-send` / `message-list` Edge Functions that mDM uses,
6
+ * but with `space_id: 'rooms'` and `thread_id: 'privroom:<room_id>'` so the
7
+ * RLS policies apply room-membership checks rather than DM contact checks.
8
+ *
9
+ * Voice in rooms (PTT, audio) lands separately via mTALK_start_session
10
+ * over the WebRTC daemon — see LINEAR-2145.
11
+ */
12
+
13
+ import { z } from "zod";
14
+ import type { MosaddTool, MosaddToolContext } from "../types.js";
15
+ import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
16
+
17
+ const PROTOCOL_VERSION = "mosadd.chat.v1";
18
+
19
+ const RoomId = z.string().min(1).describe("Private room id (UUID). From mROOM_create / mROOM_list.");
20
+
21
+ const mROOM_send_message_input = z.object({
22
+ room_id: RoomId,
23
+ text: z.string().min(1).max(64_000).describe("Message body (UTF-8). Max 64 KB."),
24
+ reply_to_id: z.string().optional().describe("Optional id of the message being replied to."),
25
+ });
26
+
27
+ const mROOM_list_messages_input = z.object({
28
+ room_id: RoomId,
29
+ limit: z.number().int().min(1).max(200).default(50).optional(),
30
+ cursor: z.string().optional().describe("Opaque pagination cursor from a prior list response."),
31
+ });
32
+
33
+ function packPlaintextPayload(text: string, replyToId?: string): string {
34
+ const envelope = {
35
+ v: PROTOCOL_VERSION,
36
+ type: "text",
37
+ text,
38
+ reply_to: replyToId ?? null,
39
+ sent_at: new Date().toISOString(),
40
+ };
41
+ return Buffer.from(JSON.stringify(envelope), "utf8").toString("base64");
42
+ }
43
+
44
+ function unpackPayload(payload: string): { text: string } {
45
+ try {
46
+ const json = Buffer.from(payload, "base64").toString("utf8");
47
+ const obj = JSON.parse(json);
48
+ if (typeof obj?.text === "string") return obj;
49
+ } catch {
50
+ /* fall through */
51
+ }
52
+ return { text: "<ciphertext>" };
53
+ }
54
+
55
+ async function mROOM_send_message(
56
+ input: z.infer<typeof mROOM_send_message_input>,
57
+ ctx: MosaddToolContext,
58
+ ): Promise<{ message_id: string; delivered_at: string; thread_id: string }> {
59
+ readSupabaseEnv();
60
+ const thread_id = `privroom:${input.room_id}`;
61
+ ctx.log("debug", "mROOM_send_message", { thread_id });
62
+
63
+ const data = await invokeFunction<{ message?: { id: string; created_at: string } }>(
64
+ "message-send",
65
+ {
66
+ space_id: "rooms",
67
+ thread_id,
68
+ encrypted_payload: packPlaintextPayload(input.text, input.reply_to_id),
69
+ message_type: "text",
70
+ protocol_version: PROTOCOL_VERSION,
71
+ reply_to_id: input.reply_to_id ?? null,
72
+ },
73
+ );
74
+
75
+ if (!data?.message?.id) {
76
+ throw new Error("message-send returned no message id");
77
+ }
78
+
79
+ return {
80
+ message_id: data.message.id,
81
+ delivered_at: data.message.created_at ?? new Date().toISOString(),
82
+ thread_id,
83
+ };
84
+ }
85
+
86
+ async function mROOM_list_messages(
87
+ input: z.infer<typeof mROOM_list_messages_input>,
88
+ ctx: MosaddToolContext,
89
+ ): Promise<{
90
+ messages: Array<{ id: string; sender_identity_id: string; text: string; timestamp: string }>;
91
+ next_cursor: string | null;
92
+ }> {
93
+ readSupabaseEnv();
94
+ const thread_id = `privroom:${input.room_id}`;
95
+ ctx.log("debug", "mROOM_list_messages", { thread_id });
96
+
97
+ type MessageListResponse = {
98
+ messages?: Array<{
99
+ id: string;
100
+ sender_identity_id: string;
101
+ encrypted_payload: string;
102
+ created_at: string;
103
+ }>;
104
+ next_cursor?: string | null;
105
+ };
106
+
107
+ const data = await invokeFunction<MessageListResponse>("message-list", {
108
+ space_id: "rooms",
109
+ thread_id,
110
+ limit: input.limit ?? 50,
111
+ cursor: input.cursor,
112
+ });
113
+
114
+ return {
115
+ messages: (data?.messages ?? []).map((m) => ({
116
+ id: m.id,
117
+ sender_identity_id: m.sender_identity_id,
118
+ text: unpackPayload(m.encrypted_payload).text,
119
+ timestamp: m.created_at,
120
+ })),
121
+ next_cursor: data?.next_cursor ?? null,
122
+ };
123
+ }
124
+
125
+ export const mroomMessagesTools: MosaddTool[] = [
126
+ {
127
+ name: "mROOM_send_message",
128
+ requires: "network",
129
+ description:
130
+ "Send a text message into a private room. Authorisation: must be a member (or guest with a valid token). Alpha payload is plaintext base64; v0.2 wraps with Double Ratchet.",
131
+ inputSchema: mROOM_send_message_input,
132
+ handler: mROOM_send_message as MosaddTool["handler"],
133
+ },
134
+ {
135
+ name: "mROOM_list_messages",
136
+ requires: "network",
137
+ description:
138
+ "List recent text messages in a private room. Cursor-paginated, newest first.",
139
+ inputSchema: mROOM_list_messages_input,
140
+ handler: mROOM_list_messages as MosaddTool["handler"],
141
+ },
142
+ ];