@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,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
- * 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
- ];
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
+ ];