@mosadd/mcp 3.0.0-alpha.55 → 3.0.0-alpha.56

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 +5 -11
  2. package/LICENSE +21 -0
  3. package/README.md +151 -150
  4. package/dist/bin/mcp.js +1 -1
  5. package/dist/{chunk-IWUGKLDX.js → chunk-T3KDVUAT.js} +14 -10
  6. package/dist/index.js +1 -1
  7. package/package.json +10 -10
  8. package/src/__tests__/blob-upload.test.ts +93 -93
  9. package/src/__tests__/channel-e2ee.test.ts +62 -62
  10. package/src/__tests__/flota-jawnie.test.ts +2 -2
  11. package/src/__tests__/golden-path.test.ts +139 -139
  12. package/src/__tests__/integration.test.ts +209 -182
  13. package/src/__tests__/mdm-e2ee.test.ts +212 -212
  14. package/src/__tests__/mdm-mcp-readable.test.ts +390 -390
  15. package/src/__tests__/mirc-invite.test.ts +112 -112
  16. package/src/__tests__/mtalk.test.ts +122 -122
  17. package/src/__tests__/presence.test.ts +199 -199
  18. package/src/__tests__/server.test.ts +71 -71
  19. package/src/__tests__/tool-count-consistency.test.ts +255 -199
  20. package/src/bin/login.ts +138 -138
  21. package/src/bin/mcp.ts +145 -145
  22. package/src/config.ts +66 -66
  23. package/src/crypto/channel-e2ee.ts +288 -288
  24. package/src/crypto/mdm-session.ts +842 -842
  25. package/src/index.ts +19 -19
  26. package/src/observability/sentry.ts +79 -79
  27. package/src/providers/blob-upload.ts +162 -162
  28. package/src/providers/memory-voice.ts +79 -79
  29. package/src/providers/supabase-dm.ts +202 -202
  30. package/src/providers/supabase-voice.ts +91 -91
  31. package/src/server.ts +195 -195
  32. package/src/tools/actions.ts +166 -166
  33. package/src/tools/attachments.ts +276 -276
  34. package/src/tools/capabilities.ts +70 -70
  35. package/src/tools/channel-payload.ts +2 -2
  36. package/src/tools/embed.ts +110 -110
  37. package/src/tools/index.ts +181 -181
  38. package/src/tools/knowledge.ts +344 -344
  39. package/src/tools/mail-aliases.ts +25 -25
  40. package/src/tools/mail-provenance.ts +137 -137
  41. package/src/tools/mail.ts +403 -403
  42. package/src/tools/mdm-as-agent.ts +138 -126
  43. package/src/tools/mdm.ts +3 -3
  44. package/src/tools/mirc-edge.ts +196 -196
  45. package/src/tools/mirc-members.ts +287 -287
  46. package/src/tools/mirc-messages.ts +1 -1
  47. package/src/tools/mirc.ts +308 -308
  48. package/src/tools/mroom.ts +221 -221
  49. package/src/tools/mtalk.ts +131 -131
  50. package/src/tools/presence.ts +442 -442
  51. package/src/tools/voice-format.ts +28 -28
  52. package/src/types.ts +121 -121
  53. package/src/voice/floor.ts +132 -132
@@ -1,276 +1,276 @@
1
- /**
2
- * Symmetric voice + file attachments across channels (mDM, mIRC).
3
- *
4
- * GOAL (Lane C): an AGENT must be able to participate in every channel the same
5
- * way a human does — including sending VOICE notes and FILES, not just text.
6
- * Today only mDM has a half-measure (`mDM_voice_note`, which takes a pre-uploaded
7
- * URL and posts a control envelope, NOT a first-class `voice` message via the
8
- * `message-send` attachments contract). mIRC has no voice/file send at all
9
- * from the toolkit.
10
- *
11
- * These tools accept the blob as base64 (MCP is JSON-only), upload it to Storage
12
- * via the shared `uploadBlob` helper, then call `message-send` with
13
- * `message_type: 'voice' | 'file'` and the `attachments[]` descriptor.
14
- *
15
- * STATUS: scaffold against the Lane A contract. Compiles and uploads, but the
16
- * `message-send` call is the not-yet-final shape — see TODO(Lane A) markers.
17
- * mDM voice additionally needs client-side E2EE sealing before upload (TODO).
18
- */
19
-
20
- import { z } from "zod";
21
- import type { MosaddTool, MosaddToolContext } from "../types.js";
22
- import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
23
- import { uploadBlob, decodeBase64Body, type AttachmentDescriptor } from "../providers/blob-upload.js";
24
-
25
- const PROTOCOL_VERSION = "mosadd.chat.v1";
26
-
27
- // ---- Shared schema fragments ----
28
-
29
- const Base64Body = z
30
- .string()
31
- .min(1)
32
- .max(20_000_000)
33
- .describe("Attachment bytes as base64 (or a data: URL). MCP is JSON-only, so binary is base64-encoded. Max ~15 MB decoded.");
34
-
35
- const Mime = z.string().min(1).max(120).describe("MIME type, e.g. audio/ogg, application/pdf, image/png.");
36
- const DurationMs = z.number().int().positive().optional().describe("Audio clip length in ms (voice only), if known.");
37
- const Filename = z.string().min(1).max(255).optional().describe("Original filename (file only).");
38
- const ReplyTo = z.string().optional().describe("Optional id of the message being replied to.");
39
-
40
- const ContactRef = z.string().min(1).describe("Recipient identity id (UUID). Use mDM_list_contacts to find it.");
41
- const RoomId = z.string().min(1).describe("Room/channel id (UUID).");
42
-
43
- const ThreadLabel = z
44
- .string()
45
- .max(120)
46
- .regex(/^[a-zA-Z0-9._-]+$/)
47
- .optional()
48
- .describe("Optional thread label within the conversation (mDM USP: multiple threads per contact).");
49
-
50
- // ---- Helpers ----
51
-
52
- /** Deterministic DM thread id (sorted pair) — must match mdm.ts dmThreadId. */
53
- function dmThreadId(selfId: string, otherId: string, label?: string): string {
54
- const [a, b] = [selfId, otherId].sort();
55
- return label ? `dm:${a}:${b}:${label}` : `dm:${a}:${b}`;
56
- }
57
-
58
- /**
59
- * Post an attachment message through `message-send`.
60
- *
61
- * TODO(Lane A): lock the exact body shape. Current best-guess from the contract:
62
- * { space_id, thread_id, message_type: 'voice'|'file', attachments: [desc],
63
- * encrypted_payload: <caption envelope>, protocol_version, reply_to_id }
64
- * Open questions for Lane A:
65
- * - is `attachments` a top-level field on message-send, or nested under the
66
- * payload? (assumed top-level here)
67
- * - does voice/file still require a (possibly empty) encrypted_payload caption?
68
- * - mDM: who seals the blob + mints key_ref — this tool, or the EF?
69
- */
70
- async function sendAttachmentMessage(
71
- ctx: MosaddToolContext,
72
- args: {
73
- space_id: string;
74
- thread_id: string;
75
- message_type: "voice" | "file";
76
- attachment: AttachmentDescriptor;
77
- caption?: string;
78
- reply_to_id?: string;
79
- recipient_account_id?: string;
80
- },
81
- ): Promise<{ message_id: string; delivered_at: string; thread_id: string }> {
82
- readSupabaseEnv();
83
- const captionEnvelope = {
84
- v: PROTOCOL_VERSION,
85
- type: args.message_type,
86
- text: args.caption ?? "",
87
- sent_at: new Date().toISOString(),
88
- };
89
- const encrypted_payload = Buffer.from(JSON.stringify(captionEnvelope), "utf8").toString("base64");
90
-
91
- ctx.log("debug", "sendAttachmentMessage", {
92
- thread_id: args.thread_id,
93
- message_type: args.message_type,
94
- bucket: args.attachment.bucket,
95
- });
96
-
97
- const data = await invokeFunction<{ message?: { id: string; created_at: string } }>("message-send", {
98
- space_id: args.space_id,
99
- thread_id: args.thread_id,
100
- message_type: args.message_type,
101
- attachments: [args.attachment], // TODO(Lane A): confirm field placement
102
- encrypted_payload,
103
- protocol_version: PROTOCOL_VERSION,
104
- recipient_account_id: args.recipient_account_id ?? null,
105
- reply_to_id: args.reply_to_id ?? null,
106
- });
107
-
108
- if (!data?.message?.id) throw new Error("message-send returned no message id (attachment)");
109
- return {
110
- message_id: data.message.id,
111
- delivered_at: data.message.created_at ?? new Date().toISOString(),
112
- thread_id: args.thread_id,
113
- };
114
- }
115
-
116
- /** Resolve a channel's backing space id — mirrors mirc-messages.ts. */
117
- async function resolveLinkedSpaceId(channelId: string): Promise<string> {
118
- type GetResponse = { channel?: { metadata?: { linked_space_id?: string } | null }; linked_space_id?: string };
119
- const data = await invokeFunction<GetResponse>("channel-manage", { action: "get", channel_id: channelId });
120
- const spaceId = data?.linked_space_id ?? data?.channel?.metadata?.linked_space_id;
121
- if (!spaceId) throw new Error(`Channel ${channelId} has no linked space yet — run mIRC_join/mIRC_list first or pass space_id.`);
122
- return spaceId;
123
- }
124
-
125
- // ====================================================================
126
- // mDM voice/file
127
- // ====================================================================
128
-
129
- const mDM_send_voice_input = z.object({
130
- to: ContactRef,
131
- audio_base64: Base64Body,
132
- mime: Mime.default("audio/ogg"),
133
- duration_ms: DurationMs,
134
- caption: z.string().max(2_000).optional(),
135
- thread_label: ThreadLabel,
136
- reply_to_id: ReplyTo,
137
- });
138
-
139
- const mDM_send_file_input = z.object({
140
- to: ContactRef,
141
- file_base64: Base64Body,
142
- filename: Filename,
143
- mime: Mime,
144
- caption: z.string().max(2_000).optional(),
145
- thread_label: ThreadLabel,
146
- reply_to_id: ReplyTo,
147
- });
148
-
149
- async function mDM_send_voice(input: z.infer<typeof mDM_send_voice_input>, ctx: MosaddToolContext) {
150
- const dm = ctx.providers.dm;
151
- const selfId = await dm.selfId();
152
- const thread_id = dmThreadId(selfId, input.to, input.thread_label);
153
- // TODO(Lane A/E2EE): mDM is client-encrypted — seal these bytes per-recipient
154
- // via @mosadd/crypto and pass the wrapped content key as key_ref BEFORE upload.
155
- // Uploading plaintext here is a scaffold-only shortcut.
156
- const attachment = await uploadBlob({
157
- kind: "voice",
158
- bytes: decodeBase64Body(input.audio_base64),
159
- mime: input.mime,
160
- prefix: thread_id,
161
- duration_ms: input.duration_ms,
162
- });
163
- return sendAttachmentMessage(ctx, {
164
- space_id: "dm",
165
- thread_id,
166
- message_type: "voice",
167
- attachment,
168
- caption: input.caption,
169
- reply_to_id: input.reply_to_id,
170
- recipient_account_id: input.to,
171
- });
172
- }
173
-
174
- async function mDM_send_file(input: z.infer<typeof mDM_send_file_input>, ctx: MosaddToolContext) {
175
- const dm = ctx.providers.dm;
176
- const selfId = await dm.selfId();
177
- const thread_id = dmThreadId(selfId, input.to, input.thread_label);
178
- // TODO(Lane A/E2EE): seal as above for mDM.
179
- const attachment = await uploadBlob({
180
- kind: "file",
181
- bytes: decodeBase64Body(input.file_base64),
182
- mime: input.mime,
183
- prefix: thread_id,
184
- filename: input.filename,
185
- });
186
- return sendAttachmentMessage(ctx, {
187
- space_id: "dm",
188
- thread_id,
189
- message_type: "file",
190
- attachment,
191
- caption: input.caption,
192
- reply_to_id: input.reply_to_id,
193
- recipient_account_id: input.to,
194
- });
195
- }
196
-
197
- // ====================================================================
198
- // mIRC voice/file
199
- // ====================================================================
200
-
201
- const mIRC_send_voice_input = z.object({
202
- channel_id: RoomId,
203
- audio_base64: Base64Body,
204
- mime: Mime.default("audio/ogg"),
205
- duration_ms: DurationMs,
206
- caption: z.string().max(2_000).optional(),
207
- reply_to_id: ReplyTo,
208
- space_id: z.string().optional().describe("Backing space id. Resolved automatically if omitted."),
209
- });
210
-
211
- const mIRC_send_file_input = z.object({
212
- channel_id: RoomId,
213
- file_base64: Base64Body,
214
- filename: Filename,
215
- mime: Mime,
216
- caption: z.string().max(2_000).optional(),
217
- reply_to_id: ReplyTo,
218
- space_id: z.string().optional(),
219
- });
220
-
221
- async function mIRC_send_voice(input: z.infer<typeof mIRC_send_voice_input>, ctx: MosaddToolContext) {
222
- const space_id = input.space_id ?? (await resolveLinkedSpaceId(input.channel_id));
223
- const thread_id = `chat:${input.channel_id}`;
224
- const attachment = await uploadBlob({ kind: "voice", bytes: decodeBase64Body(input.audio_base64), mime: input.mime, prefix: thread_id, duration_ms: input.duration_ms });
225
- return sendAttachmentMessage(ctx, { space_id, thread_id, message_type: "voice", attachment, caption: input.caption, reply_to_id: input.reply_to_id });
226
- }
227
-
228
- async function mIRC_send_file(input: z.infer<typeof mIRC_send_file_input>, ctx: MosaddToolContext) {
229
- const space_id = input.space_id ?? (await resolveLinkedSpaceId(input.channel_id));
230
- const thread_id = `chat:${input.channel_id}`;
231
- const attachment = await uploadBlob({ kind: "file", bytes: decodeBase64Body(input.file_base64), mime: input.mime, prefix: thread_id, filename: input.filename });
232
- return sendAttachmentMessage(ctx, { space_id, thread_id, message_type: "file", attachment, caption: input.caption, reply_to_id: input.reply_to_id });
233
- }
234
-
235
- // ---- Registration ----
236
-
237
- export const attachmentTools: MosaddTool[] = [
238
- {
239
- name: "mDM_send_voice",
240
- title: "Send a voice message",
241
- annotations: { readOnlyHint: false },
242
- requires: "network",
243
- description:
244
- "Send a VOICE note to a contact as a first-class mDM `voice` message (not a URL stub). Pass audio bytes as base64; the tool uploads to Storage and posts via message-send with the voice attachment descriptor. SCAFFOLD: mDM is client-encrypted — until the seal step ships, bytes are uploaded unsealed (TODO Lane A).",
245
- inputSchema: mDM_send_voice_input,
246
- handler: mDM_send_voice as MosaddTool["handler"],
247
- },
248
- {
249
- name: "mDM_send_file",
250
- title: "Send a file in DM",
251
- annotations: { readOnlyHint: false },
252
- requires: "network",
253
- description:
254
- "Send a FILE to a contact as a first-class mDM `file` message. Base64 bytes → Storage → message-send file attachment. SCAFFOLD: mDM E2EE seal is TODO (Lane A).",
255
- inputSchema: mDM_send_file_input,
256
- handler: mDM_send_file as MosaddTool["handler"],
257
- },
258
- {
259
- name: "mIRC_send_voice",
260
- title: "Send voice note to channel",
261
- annotations: { readOnlyHint: false },
262
- requires: "network",
263
- description: "Send a VOICE note into a persistent channel as a first-class `voice` message. Base64 audio → Storage → message-send (backing space resolved automatically).",
264
- inputSchema: mIRC_send_voice_input,
265
- handler: mIRC_send_voice as MosaddTool["handler"],
266
- },
267
- {
268
- name: "mIRC_send_file",
269
- title: "Send file to channel",
270
- annotations: { readOnlyHint: false },
271
- requires: "network",
272
- description: "Send a FILE into a persistent channel as a first-class `file` message. Base64 bytes → Storage → message-send.",
273
- inputSchema: mIRC_send_file_input,
274
- handler: mIRC_send_file as MosaddTool["handler"],
275
- },
276
- ];
1
+ /**
2
+ * Symmetric voice + file attachments across channels (mDM, mIRC).
3
+ *
4
+ * GOAL (Lane C): an AGENT must be able to participate in every channel the same
5
+ * way a human does — including sending VOICE notes and FILES, not just text.
6
+ * Today only mDM has a half-measure (`mDM_voice_note`, which takes a pre-uploaded
7
+ * URL and posts a control envelope, NOT a first-class `voice` message via the
8
+ * `message-send` attachments contract). mIRC has no voice/file send at all
9
+ * from the toolkit.
10
+ *
11
+ * These tools accept the blob as base64 (MCP is JSON-only), upload it to Storage
12
+ * via the shared `uploadBlob` helper, then call `message-send` with
13
+ * `message_type: 'voice' | 'file'` and the `attachments[]` descriptor.
14
+ *
15
+ * STATUS: scaffold against the Lane A contract. Compiles and uploads, but the
16
+ * `message-send` call is the not-yet-final shape — see TODO(Lane A) markers.
17
+ * mDM voice additionally needs client-side E2EE sealing before upload (TODO).
18
+ */
19
+
20
+ import { z } from "zod";
21
+ import type { MosaddTool, MosaddToolContext } from "../types.js";
22
+ import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
23
+ import { uploadBlob, decodeBase64Body, type AttachmentDescriptor } from "../providers/blob-upload.js";
24
+
25
+ const PROTOCOL_VERSION = "mosadd.chat.v1";
26
+
27
+ // ---- Shared schema fragments ----
28
+
29
+ const Base64Body = z
30
+ .string()
31
+ .min(1)
32
+ .max(20_000_000)
33
+ .describe("Attachment bytes as base64 (or a data: URL). MCP is JSON-only, so binary is base64-encoded. Max ~15 MB decoded.");
34
+
35
+ const Mime = z.string().min(1).max(120).describe("MIME type, e.g. audio/ogg, application/pdf, image/png.");
36
+ const DurationMs = z.number().int().positive().optional().describe("Audio clip length in ms (voice only), if known.");
37
+ const Filename = z.string().min(1).max(255).optional().describe("Original filename (file only).");
38
+ const ReplyTo = z.string().optional().describe("Optional id of the message being replied to.");
39
+
40
+ const ContactRef = z.string().min(1).describe("Recipient identity id (UUID). Use mDM_list_contacts to find it.");
41
+ const RoomId = z.string().min(1).describe("Room/channel id (UUID).");
42
+
43
+ const ThreadLabel = z
44
+ .string()
45
+ .max(120)
46
+ .regex(/^[a-zA-Z0-9._-]+$/)
47
+ .optional()
48
+ .describe("Optional thread label within the conversation (mDM USP: multiple threads per contact).");
49
+
50
+ // ---- Helpers ----
51
+
52
+ /** Deterministic DM thread id (sorted pair) — must match mdm.ts dmThreadId. */
53
+ function dmThreadId(selfId: string, otherId: string, label?: string): string {
54
+ const [a, b] = [selfId, otherId].sort();
55
+ return label ? `dm:${a}:${b}:${label}` : `dm:${a}:${b}`;
56
+ }
57
+
58
+ /**
59
+ * Post an attachment message through `message-send`.
60
+ *
61
+ * TODO(Lane A): lock the exact body shape. Current best-guess from the contract:
62
+ * { space_id, thread_id, message_type: 'voice'|'file', attachments: [desc],
63
+ * encrypted_payload: <caption envelope>, protocol_version, reply_to_id }
64
+ * Open questions for Lane A:
65
+ * - is `attachments` a top-level field on message-send, or nested under the
66
+ * payload? (assumed top-level here)
67
+ * - does voice/file still require a (possibly empty) encrypted_payload caption?
68
+ * - mDM: who seals the blob + mints key_ref — this tool, or the EF?
69
+ */
70
+ async function sendAttachmentMessage(
71
+ ctx: MosaddToolContext,
72
+ args: {
73
+ space_id: string;
74
+ thread_id: string;
75
+ message_type: "voice" | "file";
76
+ attachment: AttachmentDescriptor;
77
+ caption?: string;
78
+ reply_to_id?: string;
79
+ recipient_account_id?: string;
80
+ },
81
+ ): Promise<{ message_id: string; delivered_at: string; thread_id: string }> {
82
+ readSupabaseEnv();
83
+ const captionEnvelope = {
84
+ v: PROTOCOL_VERSION,
85
+ type: args.message_type,
86
+ text: args.caption ?? "",
87
+ sent_at: new Date().toISOString(),
88
+ };
89
+ const encrypted_payload = Buffer.from(JSON.stringify(captionEnvelope), "utf8").toString("base64");
90
+
91
+ ctx.log("debug", "sendAttachmentMessage", {
92
+ thread_id: args.thread_id,
93
+ message_type: args.message_type,
94
+ bucket: args.attachment.bucket,
95
+ });
96
+
97
+ const data = await invokeFunction<{ message?: { id: string; created_at: string } }>("message-send", {
98
+ space_id: args.space_id,
99
+ thread_id: args.thread_id,
100
+ message_type: args.message_type,
101
+ attachments: [args.attachment], // TODO(Lane A): confirm field placement
102
+ encrypted_payload,
103
+ protocol_version: PROTOCOL_VERSION,
104
+ recipient_account_id: args.recipient_account_id ?? null,
105
+ reply_to_id: args.reply_to_id ?? null,
106
+ });
107
+
108
+ if (!data?.message?.id) throw new Error("message-send returned no message id (attachment)");
109
+ return {
110
+ message_id: data.message.id,
111
+ delivered_at: data.message.created_at ?? new Date().toISOString(),
112
+ thread_id: args.thread_id,
113
+ };
114
+ }
115
+
116
+ /** Resolve a channel's backing space id — mirrors mirc-messages.ts. */
117
+ async function resolveLinkedSpaceId(channelId: string): Promise<string> {
118
+ type GetResponse = { channel?: { metadata?: { linked_space_id?: string } | null }; linked_space_id?: string };
119
+ const data = await invokeFunction<GetResponse>("channel-manage", { action: "get", channel_id: channelId });
120
+ const spaceId = data?.linked_space_id ?? data?.channel?.metadata?.linked_space_id;
121
+ if (!spaceId) throw new Error(`Channel ${channelId} has no linked space yet — run mIRC_join/mIRC_list first or pass space_id.`);
122
+ return spaceId;
123
+ }
124
+
125
+ // ====================================================================
126
+ // mDM voice/file
127
+ // ====================================================================
128
+
129
+ const mDM_send_voice_input = z.object({
130
+ to: ContactRef,
131
+ audio_base64: Base64Body,
132
+ mime: Mime.default("audio/ogg"),
133
+ duration_ms: DurationMs,
134
+ caption: z.string().max(2_000).optional(),
135
+ thread_label: ThreadLabel,
136
+ reply_to_id: ReplyTo,
137
+ });
138
+
139
+ const mDM_send_file_input = z.object({
140
+ to: ContactRef,
141
+ file_base64: Base64Body,
142
+ filename: Filename,
143
+ mime: Mime,
144
+ caption: z.string().max(2_000).optional(),
145
+ thread_label: ThreadLabel,
146
+ reply_to_id: ReplyTo,
147
+ });
148
+
149
+ async function mDM_send_voice(input: z.infer<typeof mDM_send_voice_input>, ctx: MosaddToolContext) {
150
+ const dm = ctx.providers.dm;
151
+ const selfId = await dm.selfId();
152
+ const thread_id = dmThreadId(selfId, input.to, input.thread_label);
153
+ // TODO(Lane A/E2EE): mDM is client-encrypted — seal these bytes per-recipient
154
+ // via @mosadd/crypto and pass the wrapped content key as key_ref BEFORE upload.
155
+ // Uploading plaintext here is a scaffold-only shortcut.
156
+ const attachment = await uploadBlob({
157
+ kind: "voice",
158
+ bytes: decodeBase64Body(input.audio_base64),
159
+ mime: input.mime,
160
+ prefix: thread_id,
161
+ duration_ms: input.duration_ms,
162
+ });
163
+ return sendAttachmentMessage(ctx, {
164
+ space_id: "dm",
165
+ thread_id,
166
+ message_type: "voice",
167
+ attachment,
168
+ caption: input.caption,
169
+ reply_to_id: input.reply_to_id,
170
+ recipient_account_id: input.to,
171
+ });
172
+ }
173
+
174
+ async function mDM_send_file(input: z.infer<typeof mDM_send_file_input>, ctx: MosaddToolContext) {
175
+ const dm = ctx.providers.dm;
176
+ const selfId = await dm.selfId();
177
+ const thread_id = dmThreadId(selfId, input.to, input.thread_label);
178
+ // TODO(Lane A/E2EE): seal as above for mDM.
179
+ const attachment = await uploadBlob({
180
+ kind: "file",
181
+ bytes: decodeBase64Body(input.file_base64),
182
+ mime: input.mime,
183
+ prefix: thread_id,
184
+ filename: input.filename,
185
+ });
186
+ return sendAttachmentMessage(ctx, {
187
+ space_id: "dm",
188
+ thread_id,
189
+ message_type: "file",
190
+ attachment,
191
+ caption: input.caption,
192
+ reply_to_id: input.reply_to_id,
193
+ recipient_account_id: input.to,
194
+ });
195
+ }
196
+
197
+ // ====================================================================
198
+ // mIRC voice/file
199
+ // ====================================================================
200
+
201
+ const mIRC_send_voice_input = z.object({
202
+ channel_id: RoomId,
203
+ audio_base64: Base64Body,
204
+ mime: Mime.default("audio/ogg"),
205
+ duration_ms: DurationMs,
206
+ caption: z.string().max(2_000).optional(),
207
+ reply_to_id: ReplyTo,
208
+ space_id: z.string().optional().describe("Backing space id. Resolved automatically if omitted."),
209
+ });
210
+
211
+ const mIRC_send_file_input = z.object({
212
+ channel_id: RoomId,
213
+ file_base64: Base64Body,
214
+ filename: Filename,
215
+ mime: Mime,
216
+ caption: z.string().max(2_000).optional(),
217
+ reply_to_id: ReplyTo,
218
+ space_id: z.string().optional(),
219
+ });
220
+
221
+ async function mIRC_send_voice(input: z.infer<typeof mIRC_send_voice_input>, ctx: MosaddToolContext) {
222
+ const space_id = input.space_id ?? (await resolveLinkedSpaceId(input.channel_id));
223
+ const thread_id = `chat:${input.channel_id}`;
224
+ const attachment = await uploadBlob({ kind: "voice", bytes: decodeBase64Body(input.audio_base64), mime: input.mime, prefix: thread_id, duration_ms: input.duration_ms });
225
+ return sendAttachmentMessage(ctx, { space_id, thread_id, message_type: "voice", attachment, caption: input.caption, reply_to_id: input.reply_to_id });
226
+ }
227
+
228
+ async function mIRC_send_file(input: z.infer<typeof mIRC_send_file_input>, ctx: MosaddToolContext) {
229
+ const space_id = input.space_id ?? (await resolveLinkedSpaceId(input.channel_id));
230
+ const thread_id = `chat:${input.channel_id}`;
231
+ const attachment = await uploadBlob({ kind: "file", bytes: decodeBase64Body(input.file_base64), mime: input.mime, prefix: thread_id, filename: input.filename });
232
+ return sendAttachmentMessage(ctx, { space_id, thread_id, message_type: "file", attachment, caption: input.caption, reply_to_id: input.reply_to_id });
233
+ }
234
+
235
+ // ---- Registration ----
236
+
237
+ export const attachmentTools: MosaddTool[] = [
238
+ {
239
+ name: "mDM_send_voice",
240
+ title: "Send a voice message",
241
+ annotations: { readOnlyHint: false },
242
+ requires: "network",
243
+ description:
244
+ "Send a VOICE note to a contact as a first-class mDM `voice` message (not a URL stub). Pass audio bytes as base64; the tool uploads to Storage and posts via message-send with the voice attachment descriptor. SCAFFOLD: mDM is client-encrypted — until the seal step ships, bytes are uploaded unsealed (TODO Lane A).",
245
+ inputSchema: mDM_send_voice_input,
246
+ handler: mDM_send_voice as MosaddTool["handler"],
247
+ },
248
+ {
249
+ name: "mDM_send_file",
250
+ title: "Send a file in DM",
251
+ annotations: { readOnlyHint: false },
252
+ requires: "network",
253
+ description:
254
+ "Send a FILE to a contact as a first-class mDM `file` message. Base64 bytes → Storage → message-send file attachment. SCAFFOLD: mDM E2EE seal is TODO (Lane A).",
255
+ inputSchema: mDM_send_file_input,
256
+ handler: mDM_send_file as MosaddTool["handler"],
257
+ },
258
+ {
259
+ name: "mIRC_send_voice",
260
+ title: "Send voice note to channel",
261
+ annotations: { readOnlyHint: false },
262
+ requires: "network",
263
+ description: "Send a VOICE note into a persistent channel as a first-class `voice` message. Base64 audio → Storage → message-send (backing space resolved automatically).",
264
+ inputSchema: mIRC_send_voice_input,
265
+ handler: mIRC_send_voice as MosaddTool["handler"],
266
+ },
267
+ {
268
+ name: "mIRC_send_file",
269
+ title: "Send file to channel",
270
+ annotations: { readOnlyHint: false },
271
+ requires: "network",
272
+ description: "Send a FILE into a persistent channel as a first-class `file` message. Base64 bytes → Storage → message-send.",
273
+ inputSchema: mIRC_send_file_input,
274
+ handler: mIRC_send_file as MosaddTool["handler"],
275
+ },
276
+ ];