@mosadd/mcp 3.0.0-alpha.3 → 3.0.0-alpha.4
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/README.md +116 -116
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-HD5RLE5K.js → chunk-YDFU6S5E.js} +326 -48
- package/dist/index.d.ts +22 -1
- package/dist/index.js +1 -1
- package/package.json +6 -6
- package/src/__tests__/golden-path.test.ts +137 -132
- package/src/__tests__/integration.test.ts +178 -175
- package/src/__tests__/mdm-e2ee.test.ts +178 -149
- package/src/__tests__/mtalk.test.ts +122 -0
- package/src/__tests__/server.test.ts +67 -67
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +97 -97
- package/src/config.ts +66 -66
- package/src/crypto/mdm-session.ts +403 -378
- package/src/index.ts +17 -17
- package/src/observability/sentry.ts +79 -79
- package/src/providers/memory-voice.ts +79 -0
- package/src/providers/supabase-dm.ts +117 -117
- package/src/providers/supabase-voice.ts +91 -0
- package/src/providers/supabase.ts +96 -96
- package/src/server.ts +105 -103
- package/src/tools/capabilities.ts +68 -68
- package/src/tools/index.ts +43 -37
- package/src/tools/knowledge.ts +91 -0
- package/src/tools/mail.ts +89 -89
- package/src/tools/mdm.ts +392 -379
- package/src/tools/mirc-members.ts +177 -177
- package/src/tools/mirc-messages.ts +151 -0
- package/src/tools/mirc.ts +170 -170
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +189 -189
- package/src/tools/mtalk.ts +121 -0
- package/src/types.ts +85 -79
- package/src/voice/floor.ts +132 -0
package/src/tools/mirc.ts
CHANGED
|
@@ -1,170 +1,170 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mIRC — Persistent Channels.
|
|
3
|
-
*
|
|
4
|
-
* IRC-style persistent channels (Discord/Slack semantics). Channels live forever
|
|
5
|
-
* until deleted, members come and go. Distinct from mROOM (ephemeral, no-account).
|
|
6
|
-
*
|
|
7
|
-
* Phase 1 alpha: wired to m0ssad-3 `channel-manage` Edge Function (strangler-fig).
|
|
8
|
-
* The single edge fn dispatches on `action` — we expose each action as its own
|
|
9
|
-
* MCP tool for clarity.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { z } from "zod";
|
|
13
|
-
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
14
|
-
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
15
|
-
|
|
16
|
-
// ---- Schemas ----
|
|
17
|
-
|
|
18
|
-
const ChannelId = z
|
|
19
|
-
.string()
|
|
20
|
-
.min(1)
|
|
21
|
-
.max(120)
|
|
22
|
-
.describe("Channel id (UUID). Use mIRC_list to discover available channels.");
|
|
23
|
-
|
|
24
|
-
const AccessMode = z
|
|
25
|
-
.enum(["
|
|
26
|
-
.describe("
|
|
27
|
-
|
|
28
|
-
const Capabilities = z
|
|
29
|
-
.object({
|
|
30
|
-
txt: z.boolean().default(true),
|
|
31
|
-
ptt: z.boolean().default(false),
|
|
32
|
-
live: z.boolean().default(false),
|
|
33
|
-
})
|
|
34
|
-
.describe("Which modes are enabled in this channel: txt (text), ptt (push-to-talk voice), live (live stream).")
|
|
35
|
-
.optional();
|
|
36
|
-
|
|
37
|
-
const mIRC_create_input = z.object({
|
|
38
|
-
name: z.string().min(1).max(80).describe("Channel display name."),
|
|
39
|
-
topic: z.string().max(500).optional().describe("Optional channel topic/description."),
|
|
40
|
-
access_mode: AccessMode.default("
|
|
41
|
-
password: z.string().min(6).max(120).optional().describe("Password (only for access_mode=
|
|
42
|
-
capabilities: Capabilities,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const mIRC_list_input = z.object({
|
|
46
|
-
limit: z.number().int().min(1).max(500).default(100).optional(),
|
|
47
|
-
offset: z.number().int().min(0).default(0).optional(),
|
|
48
|
-
access_mode: AccessMode.optional().describe("Filter to a single access mode."),
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const mIRC_get_input = z.object({
|
|
52
|
-
channel_id: ChannelId,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const mIRC_update_input = z.object({
|
|
56
|
-
channel_id: ChannelId,
|
|
57
|
-
name: z.string().min(1).max(80).optional(),
|
|
58
|
-
topic: z.string().max(500).optional(),
|
|
59
|
-
access_mode: AccessMode.optional(),
|
|
60
|
-
capabilities: Capabilities,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const mIRC_delete_input = z.object({
|
|
64
|
-
channel_id: ChannelId,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// ---- Handlers ----
|
|
68
|
-
|
|
69
|
-
async function mIRC_create(
|
|
70
|
-
input: z.infer<typeof mIRC_create_input>,
|
|
71
|
-
ctx: MosaddToolContext,
|
|
72
|
-
): Promise<{ channel: unknown }> {
|
|
73
|
-
readSupabaseEnv();
|
|
74
|
-
ctx.log("debug", "mIRC_create invoking channel-manage", { name: input.name });
|
|
75
|
-
return await invokeFunction<{ channel: unknown }>("channel-manage", {
|
|
76
|
-
action: "create",
|
|
77
|
-
...input,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async function mIRC_list(
|
|
82
|
-
input: z.infer<typeof mIRC_list_input>,
|
|
83
|
-
ctx: MosaddToolContext,
|
|
84
|
-
): Promise<{ channels: unknown[] }> {
|
|
85
|
-
readSupabaseEnv();
|
|
86
|
-
ctx.log("debug", "mIRC_list invoking channel-manage");
|
|
87
|
-
return await invokeFunction<{ channels: unknown[] }>("channel-manage", {
|
|
88
|
-
action: "list",
|
|
89
|
-
...input,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function mIRC_get(
|
|
94
|
-
input: z.infer<typeof mIRC_get_input>,
|
|
95
|
-
ctx: MosaddToolContext,
|
|
96
|
-
): Promise<{ channel: unknown }> {
|
|
97
|
-
readSupabaseEnv();
|
|
98
|
-
ctx.log("debug", "mIRC_get invoking channel-manage", { channel_id: input.channel_id });
|
|
99
|
-
return await invokeFunction<{ channel: unknown }>("channel-manage", {
|
|
100
|
-
action: "get",
|
|
101
|
-
channel_id: input.channel_id,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async function mIRC_update(
|
|
106
|
-
input: z.infer<typeof mIRC_update_input>,
|
|
107
|
-
ctx: MosaddToolContext,
|
|
108
|
-
): Promise<{ channel: unknown }> {
|
|
109
|
-
readSupabaseEnv();
|
|
110
|
-
ctx.log("debug", "mIRC_update invoking channel-manage", { channel_id: input.channel_id });
|
|
111
|
-
return await invokeFunction<{ channel: unknown }>("channel-manage", {
|
|
112
|
-
action: "update",
|
|
113
|
-
...input,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async function mIRC_delete(
|
|
118
|
-
input: z.infer<typeof mIRC_delete_input>,
|
|
119
|
-
ctx: MosaddToolContext,
|
|
120
|
-
): Promise<{ deleted: true }> {
|
|
121
|
-
readSupabaseEnv();
|
|
122
|
-
ctx.log("debug", "mIRC_delete invoking channel-manage", { channel_id: input.channel_id });
|
|
123
|
-
await invokeFunction<{ deleted: boolean }>("channel-manage", {
|
|
124
|
-
action: "delete",
|
|
125
|
-
channel_id: input.channel_id,
|
|
126
|
-
});
|
|
127
|
-
return { deleted: true };
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// ---- Registration ----
|
|
131
|
-
|
|
132
|
-
export const mircTools: MosaddTool[] = [
|
|
133
|
-
{
|
|
134
|
-
name: "mIRC_create",
|
|
135
|
-
requires: "network",
|
|
136
|
-
description:
|
|
137
|
-
"Create a new persistent channel (Discord/Slack-style). Set access_mode to
|
|
138
|
-
inputSchema: mIRC_create_input,
|
|
139
|
-
handler: mIRC_create as MosaddTool["handler"],
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
name: "mIRC_list",
|
|
143
|
-
requires: "network",
|
|
144
|
-
description:
|
|
145
|
-
"List channels available to the current user. Optionally filter by access_mode.",
|
|
146
|
-
inputSchema: mIRC_list_input,
|
|
147
|
-
handler: mIRC_list as MosaddTool["handler"],
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
name: "mIRC_get",
|
|
151
|
-
requires: "network",
|
|
152
|
-
description: "Get full details of a single channel by id.",
|
|
153
|
-
inputSchema: mIRC_get_input,
|
|
154
|
-
handler: mIRC_get as MosaddTool["handler"],
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
name: "mIRC_update",
|
|
158
|
-
requires: "network",
|
|
159
|
-
description: "Update channel metadata (name, topic, access_mode, capabilities). Owner only.",
|
|
160
|
-
inputSchema: mIRC_update_input,
|
|
161
|
-
handler: mIRC_update as MosaddTool["handler"],
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
name: "mIRC_delete",
|
|
165
|
-
requires: "network",
|
|
166
|
-
description: "Delete a channel and cascade-remove its members. Owner only.",
|
|
167
|
-
inputSchema: mIRC_delete_input,
|
|
168
|
-
handler: mIRC_delete as MosaddTool["handler"],
|
|
169
|
-
},
|
|
170
|
-
];
|
|
1
|
+
/**
|
|
2
|
+
* mIRC — Persistent Channels.
|
|
3
|
+
*
|
|
4
|
+
* IRC-style persistent channels (Discord/Slack semantics). Channels live forever
|
|
5
|
+
* until deleted, members come and go. Distinct from mROOM (ephemeral, no-account).
|
|
6
|
+
*
|
|
7
|
+
* Phase 1 alpha: wired to m0ssad-3 `channel-manage` Edge Function (strangler-fig).
|
|
8
|
+
* The single edge fn dispatches on `action` — we expose each action as its own
|
|
9
|
+
* MCP tool for clarity.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
14
|
+
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
15
|
+
|
|
16
|
+
// ---- Schemas ----
|
|
17
|
+
|
|
18
|
+
const ChannelId = z
|
|
19
|
+
.string()
|
|
20
|
+
.min(1)
|
|
21
|
+
.max(120)
|
|
22
|
+
.describe("Channel id (UUID). Use mIRC_list to discover available channels.");
|
|
23
|
+
|
|
24
|
+
const AccessMode = z
|
|
25
|
+
.enum(["open", "password", "private"])
|
|
26
|
+
.describe("open: anyone can join · password: join with a shared password · private: invite-only.");
|
|
27
|
+
|
|
28
|
+
const Capabilities = z
|
|
29
|
+
.object({
|
|
30
|
+
txt: z.boolean().default(true),
|
|
31
|
+
ptt: z.boolean().default(false),
|
|
32
|
+
live: z.boolean().default(false),
|
|
33
|
+
})
|
|
34
|
+
.describe("Which modes are enabled in this channel: txt (text), ptt (push-to-talk voice), live (live stream).")
|
|
35
|
+
.optional();
|
|
36
|
+
|
|
37
|
+
const mIRC_create_input = z.object({
|
|
38
|
+
name: z.string().min(1).max(80).describe("Channel display name."),
|
|
39
|
+
topic: z.string().max(500).optional().describe("Optional channel topic/description."),
|
|
40
|
+
access_mode: AccessMode.default("open"),
|
|
41
|
+
password: z.string().min(6).max(120).optional().describe("Password (only for access_mode=password)."),
|
|
42
|
+
capabilities: Capabilities,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const mIRC_list_input = z.object({
|
|
46
|
+
limit: z.number().int().min(1).max(500).default(100).optional(),
|
|
47
|
+
offset: z.number().int().min(0).default(0).optional(),
|
|
48
|
+
access_mode: AccessMode.optional().describe("Filter to a single access mode."),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const mIRC_get_input = z.object({
|
|
52
|
+
channel_id: ChannelId,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const mIRC_update_input = z.object({
|
|
56
|
+
channel_id: ChannelId,
|
|
57
|
+
name: z.string().min(1).max(80).optional(),
|
|
58
|
+
topic: z.string().max(500).optional(),
|
|
59
|
+
access_mode: AccessMode.optional(),
|
|
60
|
+
capabilities: Capabilities,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const mIRC_delete_input = z.object({
|
|
64
|
+
channel_id: ChannelId,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// ---- Handlers ----
|
|
68
|
+
|
|
69
|
+
async function mIRC_create(
|
|
70
|
+
input: z.infer<typeof mIRC_create_input>,
|
|
71
|
+
ctx: MosaddToolContext,
|
|
72
|
+
): Promise<{ channel: unknown }> {
|
|
73
|
+
readSupabaseEnv();
|
|
74
|
+
ctx.log("debug", "mIRC_create invoking channel-manage", { name: input.name });
|
|
75
|
+
return await invokeFunction<{ channel: unknown }>("channel-manage", {
|
|
76
|
+
action: "create",
|
|
77
|
+
...input,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function mIRC_list(
|
|
82
|
+
input: z.infer<typeof mIRC_list_input>,
|
|
83
|
+
ctx: MosaddToolContext,
|
|
84
|
+
): Promise<{ channels: unknown[] }> {
|
|
85
|
+
readSupabaseEnv();
|
|
86
|
+
ctx.log("debug", "mIRC_list invoking channel-manage");
|
|
87
|
+
return await invokeFunction<{ channels: unknown[] }>("channel-manage", {
|
|
88
|
+
action: "list",
|
|
89
|
+
...input,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function mIRC_get(
|
|
94
|
+
input: z.infer<typeof mIRC_get_input>,
|
|
95
|
+
ctx: MosaddToolContext,
|
|
96
|
+
): Promise<{ channel: unknown }> {
|
|
97
|
+
readSupabaseEnv();
|
|
98
|
+
ctx.log("debug", "mIRC_get invoking channel-manage", { channel_id: input.channel_id });
|
|
99
|
+
return await invokeFunction<{ channel: unknown }>("channel-manage", {
|
|
100
|
+
action: "get",
|
|
101
|
+
channel_id: input.channel_id,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function mIRC_update(
|
|
106
|
+
input: z.infer<typeof mIRC_update_input>,
|
|
107
|
+
ctx: MosaddToolContext,
|
|
108
|
+
): Promise<{ channel: unknown }> {
|
|
109
|
+
readSupabaseEnv();
|
|
110
|
+
ctx.log("debug", "mIRC_update invoking channel-manage", { channel_id: input.channel_id });
|
|
111
|
+
return await invokeFunction<{ channel: unknown }>("channel-manage", {
|
|
112
|
+
action: "update",
|
|
113
|
+
...input,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function mIRC_delete(
|
|
118
|
+
input: z.infer<typeof mIRC_delete_input>,
|
|
119
|
+
ctx: MosaddToolContext,
|
|
120
|
+
): Promise<{ deleted: true }> {
|
|
121
|
+
readSupabaseEnv();
|
|
122
|
+
ctx.log("debug", "mIRC_delete invoking channel-manage", { channel_id: input.channel_id });
|
|
123
|
+
await invokeFunction<{ deleted: boolean }>("channel-manage", {
|
|
124
|
+
action: "delete",
|
|
125
|
+
channel_id: input.channel_id,
|
|
126
|
+
});
|
|
127
|
+
return { deleted: true };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ---- Registration ----
|
|
131
|
+
|
|
132
|
+
export const mircTools: MosaddTool[] = [
|
|
133
|
+
{
|
|
134
|
+
name: "mIRC_create",
|
|
135
|
+
requires: "network",
|
|
136
|
+
description:
|
|
137
|
+
"Create a new persistent channel (Discord/Slack-style). Set access_mode to open (anyone joins), password (shared-password gated), or private (invite-only). capabilities controls modes (txt/ptt/live).",
|
|
138
|
+
inputSchema: mIRC_create_input,
|
|
139
|
+
handler: mIRC_create as MosaddTool["handler"],
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "mIRC_list",
|
|
143
|
+
requires: "network",
|
|
144
|
+
description:
|
|
145
|
+
"List channels available to the current user. Optionally filter by access_mode.",
|
|
146
|
+
inputSchema: mIRC_list_input,
|
|
147
|
+
handler: mIRC_list as MosaddTool["handler"],
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: "mIRC_get",
|
|
151
|
+
requires: "network",
|
|
152
|
+
description: "Get full details of a single channel by id.",
|
|
153
|
+
inputSchema: mIRC_get_input,
|
|
154
|
+
handler: mIRC_get as MosaddTool["handler"],
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: "mIRC_update",
|
|
158
|
+
requires: "network",
|
|
159
|
+
description: "Update channel metadata (name, topic, access_mode, capabilities). Owner only.",
|
|
160
|
+
inputSchema: mIRC_update_input,
|
|
161
|
+
handler: mIRC_update as MosaddTool["handler"],
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: "mIRC_delete",
|
|
165
|
+
requires: "network",
|
|
166
|
+
description: "Delete a channel and cascade-remove its members. Owner only.",
|
|
167
|
+
inputSchema: mIRC_delete_input,
|
|
168
|
+
handler: mIRC_delete as MosaddTool["handler"],
|
|
169
|
+
},
|
|
170
|
+
];
|
|
@@ -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
|
+
* 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
|
+
];
|