@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,268 +1,268 @@
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
- requires: "network",
241
- description:
242
- "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).",
243
- inputSchema: mDM_send_voice_input,
244
- handler: mDM_send_voice as MosaddTool["handler"],
245
- },
246
- {
247
- name: "mDM_send_file",
248
- requires: "network",
249
- description:
250
- "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).",
251
- inputSchema: mDM_send_file_input,
252
- handler: mDM_send_file as MosaddTool["handler"],
253
- },
254
- {
255
- name: "mIRC_send_voice",
256
- requires: "network",
257
- description: "Send a VOICE note into a persistent channel as a first-class `voice` message. Base64 audio → Storage → message-send (backing space resolved automatically).",
258
- inputSchema: mIRC_send_voice_input,
259
- handler: mIRC_send_voice as MosaddTool["handler"],
260
- },
261
- {
262
- name: "mIRC_send_file",
263
- requires: "network",
264
- description: "Send a FILE into a persistent channel as a first-class `file` message. Base64 bytes → Storage → message-send.",
265
- inputSchema: mIRC_send_file_input,
266
- handler: mIRC_send_file as MosaddTool["handler"],
267
- },
268
- ];
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
+ requires: "network",
241
+ description:
242
+ "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).",
243
+ inputSchema: mDM_send_voice_input,
244
+ handler: mDM_send_voice as MosaddTool["handler"],
245
+ },
246
+ {
247
+ name: "mDM_send_file",
248
+ requires: "network",
249
+ description:
250
+ "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).",
251
+ inputSchema: mDM_send_file_input,
252
+ handler: mDM_send_file as MosaddTool["handler"],
253
+ },
254
+ {
255
+ name: "mIRC_send_voice",
256
+ requires: "network",
257
+ description: "Send a VOICE note into a persistent channel as a first-class `voice` message. Base64 audio → Storage → message-send (backing space resolved automatically).",
258
+ inputSchema: mIRC_send_voice_input,
259
+ handler: mIRC_send_voice as MosaddTool["handler"],
260
+ },
261
+ {
262
+ name: "mIRC_send_file",
263
+ requires: "network",
264
+ description: "Send a FILE into a persistent channel as a first-class `file` message. Base64 bytes → Storage → message-send.",
265
+ inputSchema: mIRC_send_file_input,
266
+ handler: mIRC_send_file as MosaddTool["handler"],
267
+ },
268
+ ];