@mosadd/mcp 3.0.0-alpha.14 → 3.0.0-alpha.16
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/dist/bin/mcp.js +1 -1
- package/dist/{chunk-I6MAQUMM.js → chunk-KZ3HIZ74.js} +519 -34
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/providers/blob-upload.ts +116 -0
- package/src/providers/supabase-dm.ts +6 -3
- package/src/tools/actions.ts +117 -0
- package/src/tools/attachments.ts +328 -0
- package/src/tools/index.ts +9 -0
- package/src/tools/mail-provenance.ts +137 -0
- package/src/tools/mail.ts +5 -2
- package/src/tools/mdm.ts +4 -1
- package/src/tools/ptt-ingest.ts +91 -0
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mosadd/mcp",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.16",
|
|
4
4
|
"description": "Model Context Protocol server for mosadd. Exposes the 6 live m* modules (mDM, mIRC, mROOM, mTALK, mAIL, mRAG) — 61 tools — to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
|
|
5
5
|
"homepage": "https://github.com/Hei33enberg/mosadd-os/tree/main/packages/mcp",
|
|
6
6
|
"repository": {
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"@supabase/supabase-js": "^2.48.0",
|
|
38
38
|
"zod": "^4.3.6",
|
|
39
39
|
"@mosadd/crypto": "3.0.0-alpha.4",
|
|
40
|
-
"@mosadd/
|
|
41
|
-
"@mosadd/
|
|
40
|
+
"@mosadd/protocol": "3.0.0-alpha.4",
|
|
41
|
+
"@mosadd/providers": "3.0.0-alpha.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"tsup": "^8.3.5",
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voice/file blob upload helper.
|
|
3
|
+
*
|
|
4
|
+
* The `message-send` contract carries voice/ptt/file bodies via an
|
|
5
|
+
* `attachments[]` array of `{ kind, bucket, path, mime, duration_ms, key_ref }`
|
|
6
|
+
* descriptors. The actual bytes must be uploaded to Supabase Storage FIRST; the
|
|
7
|
+
* message row only references them by `{ bucket, path }`.
|
|
8
|
+
*
|
|
9
|
+
* This module centralises that upload so every channel's voice/file/ptt tool
|
|
10
|
+
* (mDM, mROOM, mIRC) produces an identical attachment descriptor.
|
|
11
|
+
*
|
|
12
|
+
* STATUS: scaffold. The Storage upload path below is real (supabase-js
|
|
13
|
+
* `storage.from(bucket).upload`), but two things are TODO and gated on the
|
|
14
|
+
* Lane A / CTO backend contract:
|
|
15
|
+
* - TODO(Lane A): confirm bucket names (`voice-blobs` for voice/ptt) and the
|
|
16
|
+
* RLS/policy that lets an agent JWT or hub-claim JWT write to them.
|
|
17
|
+
* - TODO(Lane A): mDM voice is CLIENT-ENCRYPTED — the bytes must be sealed
|
|
18
|
+
* (per-recipient, via @mosadd/crypto) before upload and `key_ref` must point
|
|
19
|
+
* at the wrapped content key. Today this helper uploads the bytes as-is and
|
|
20
|
+
* sets key_ref:null. Do NOT use for mDM voice until the seal step lands.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { getSupabase, readSupabaseEnv } from "./supabase.js";
|
|
24
|
+
|
|
25
|
+
export type AttachmentKind = "voice" | "file" | "ptt";
|
|
26
|
+
|
|
27
|
+
/** The descriptor shape `message-send` expects inside `attachments[]`. */
|
|
28
|
+
export interface AttachmentDescriptor {
|
|
29
|
+
kind: AttachmentKind;
|
|
30
|
+
bucket: string;
|
|
31
|
+
path: string;
|
|
32
|
+
mime: string;
|
|
33
|
+
duration_ms?: number | null;
|
|
34
|
+
/** Reference to the wrapped content-encryption key (E2EE channels only). */
|
|
35
|
+
key_ref?: string | null;
|
|
36
|
+
/** Original filename, for `kind:'file'`. */
|
|
37
|
+
filename?: string | null;
|
|
38
|
+
size_bytes?: number | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface UploadBlobArgs {
|
|
42
|
+
kind: AttachmentKind;
|
|
43
|
+
/** Raw bytes to upload. Caller is responsible for any E2EE sealing first. */
|
|
44
|
+
bytes: Uint8Array;
|
|
45
|
+
mime: string;
|
|
46
|
+
/** Storage bucket. Defaults: voice/ptt → 'voice-blobs', file → 'file-blobs'. */
|
|
47
|
+
bucket?: string;
|
|
48
|
+
/** Sub-path prefix inside the bucket (e.g. the thread id). */
|
|
49
|
+
prefix?: string;
|
|
50
|
+
duration_ms?: number | null;
|
|
51
|
+
filename?: string | null;
|
|
52
|
+
/** Reference to the wrapped content key, when the caller pre-sealed the bytes. */
|
|
53
|
+
key_ref?: string | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function defaultBucket(kind: AttachmentKind): string {
|
|
57
|
+
// TODO(Lane A): confirm canonical bucket names + write policy for agent JWTs.
|
|
58
|
+
return kind === "file" ? "file-blobs" : "voice-blobs";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function randomId(): string {
|
|
62
|
+
// crypto.randomUUID is available on Node >=18 (package engines floor).
|
|
63
|
+
return globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Upload bytes to Supabase Storage and return the attachment descriptor to embed
|
|
68
|
+
* in `message-send`'s `attachments[]`.
|
|
69
|
+
*/
|
|
70
|
+
export async function uploadBlob(args: UploadBlobArgs): Promise<AttachmentDescriptor> {
|
|
71
|
+
readSupabaseEnv();
|
|
72
|
+
const sb = getSupabase();
|
|
73
|
+
const bucket = args.bucket ?? defaultBucket(args.kind);
|
|
74
|
+
const ext = args.filename?.split(".").pop() ?? mimeExt(args.mime);
|
|
75
|
+
const path = `${args.prefix ? args.prefix.replace(/[^a-zA-Z0-9._/-]/g, "-") + "/" : ""}${randomId()}${ext ? "." + ext : ""}`;
|
|
76
|
+
|
|
77
|
+
const { error } = await sb.storage.from(bucket).upload(path, args.bytes, {
|
|
78
|
+
contentType: args.mime,
|
|
79
|
+
upsert: false,
|
|
80
|
+
});
|
|
81
|
+
if (error) {
|
|
82
|
+
throw new Error(`blob upload to ${bucket}/${path} failed: ${error.message}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
kind: args.kind,
|
|
87
|
+
bucket,
|
|
88
|
+
path,
|
|
89
|
+
mime: args.mime,
|
|
90
|
+
duration_ms: args.duration_ms ?? null,
|
|
91
|
+
key_ref: args.key_ref ?? null,
|
|
92
|
+
filename: args.filename ?? null,
|
|
93
|
+
size_bytes: args.bytes.byteLength,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function mimeExt(mime: string): string {
|
|
98
|
+
const map: Record<string, string> = {
|
|
99
|
+
"audio/ogg": "ogg",
|
|
100
|
+
"audio/mpeg": "mp3",
|
|
101
|
+
"audio/mp4": "m4a",
|
|
102
|
+
"audio/wav": "wav",
|
|
103
|
+
"audio/webm": "webm",
|
|
104
|
+
};
|
|
105
|
+
return map[mime] ?? "";
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Decode a base64 / data-URL string into bytes. Agents hand us audio/file
|
|
110
|
+
* content as base64 (MCP is JSON-only — no binary channel), so every voice/file
|
|
111
|
+
* tool funnels through this.
|
|
112
|
+
*/
|
|
113
|
+
export function decodeBase64Body(b64: string): Uint8Array {
|
|
114
|
+
const cleaned = b64.includes(",") && b64.startsWith("data:") ? b64.slice(b64.indexOf(",") + 1) : b64;
|
|
115
|
+
return new Uint8Array(Buffer.from(cleaned, "base64"));
|
|
116
|
+
}
|
|
@@ -95,13 +95,16 @@ export class SupabaseDmProvider implements DmProvider {
|
|
|
95
95
|
encrypted_payload: string;
|
|
96
96
|
created_at: string;
|
|
97
97
|
}>;
|
|
98
|
-
|
|
98
|
+
cursor?: string | null;
|
|
99
|
+
has_more?: boolean;
|
|
99
100
|
};
|
|
101
|
+
// message-list paginates history via `before` (a created_at marker) and returns
|
|
102
|
+
// the next marker as `cursor` — NOT `cursor` in / `next_cursor` out.
|
|
100
103
|
const data = await invokeFunction<MessageListResponse>("message-list", {
|
|
101
104
|
space_id: "dm",
|
|
102
105
|
thread_id: args.threadId,
|
|
103
106
|
limit: args.limit ?? 50,
|
|
104
|
-
|
|
107
|
+
before: args.cursor,
|
|
105
108
|
});
|
|
106
109
|
return {
|
|
107
110
|
messages: (data?.messages ?? []).map((m) => ({
|
|
@@ -111,7 +114,7 @@ export class SupabaseDmProvider implements DmProvider {
|
|
|
111
114
|
timestamp: m.created_at,
|
|
112
115
|
threadId: m.thread_id,
|
|
113
116
|
})),
|
|
114
|
-
nextCursor: data?.
|
|
117
|
+
nextCursor: data?.has_more ? (data?.cursor ?? null) : null,
|
|
115
118
|
};
|
|
116
119
|
}
|
|
117
120
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action links — agent → user one-link actions (Tier 1).
|
|
3
|
+
*
|
|
4
|
+
* Mint a single-use, expiring link (`https://mosadd.com/do/<token>`) that asks a
|
|
5
|
+
* human to DO something in their browser — confirm, pick a file, fill a form, or
|
|
6
|
+
* open a vetted URL — with explicit consent. Send the returned `link` to the
|
|
7
|
+
* person via any channel (mDM/mIRC/mAIL). They open it, see what's asked, consent,
|
|
8
|
+
* and the browser performs the action IN ITS SANDBOX, then the result is recorded
|
|
9
|
+
* against the action. No install, no OS access, nothing runs without a user gesture.
|
|
10
|
+
*
|
|
11
|
+
* Backend: mosadd `action-create` Edge Function. The action is owned by the
|
|
12
|
+
* calling user (user-JWT scoped — `mosadd login` / MOSADD_USER_JWT), so only you
|
|
13
|
+
* can later read its result.
|
|
14
|
+
*
|
|
15
|
+
* Result read-back (an `action_status` tool) is a follow-up — it needs a small
|
|
16
|
+
* creator-scoped read Edge Function (`action-status`). For now, the recipient's
|
|
17
|
+
* outcome is recorded on the action row; surface it once that EF ships.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
22
|
+
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
23
|
+
|
|
24
|
+
const formField = z.object({
|
|
25
|
+
name: z.string().min(1).max(60).describe("Field key — returned verbatim in the result."),
|
|
26
|
+
label: z.string().max(120).optional().describe("Human label shown to the recipient. Defaults to `name`."),
|
|
27
|
+
type: z.enum(["text", "email", "number", "textarea", "tel", "url"]).optional().describe("Input type. Default 'text'."),
|
|
28
|
+
required: z.boolean().optional().describe("Whether the recipient must fill this field."),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const action_create_input = z.object({
|
|
32
|
+
action_type: z.enum(["confirm", "file_request", "form", "open_url"]).describe(
|
|
33
|
+
"What you want the recipient to do: 'confirm' (yes/no), 'file_request' (pick a file from their computer), 'form' (fill fields), 'open_url' (open a vetted https URL).",
|
|
34
|
+
),
|
|
35
|
+
message: z.string().min(1).max(2000).describe("What you're asking — shown on the consent screen above the action UI."),
|
|
36
|
+
creator_label: z.string().max(80).optional().describe("How you're identified to the recipient (e.g. your agent name). Default 'Agent'."),
|
|
37
|
+
// confirm
|
|
38
|
+
yes_label: z.string().max(40).optional().describe("[confirm] Affirmative button label. Default 'Tak'."),
|
|
39
|
+
no_label: z.string().max(40).optional().describe("[confirm] Negative button label. Default 'Nie'."),
|
|
40
|
+
// file_request
|
|
41
|
+
accept: z.string().max(200).optional().describe("[file_request] Accepted file types (HTML accept attr, e.g. 'image/*,.pdf')."),
|
|
42
|
+
max_bytes: z.number().int().positive().max(5_242_880).optional().describe("[file_request] Max file size in bytes (≤ 5 MB). NOTE: the returned file is NOT yet end-to-end encrypted — do not request sensitive files until Tier 1.1 ships."),
|
|
43
|
+
// form
|
|
44
|
+
fields: z.array(formField).min(1).max(20).optional().describe("[form] Fields to collect from the recipient."),
|
|
45
|
+
// open_url
|
|
46
|
+
url: z.string().url().optional().describe("[open_url] The https URL to open. The full URL is shown to the recipient before they open it."),
|
|
47
|
+
// lifecycle
|
|
48
|
+
ttl_ms: z.number().int().positive().optional().describe("Link lifetime in milliseconds. Default 24h, capped at 7d."),
|
|
49
|
+
max_uses: z.number().int().min(1).max(50).optional().describe("How many times the link can be redeemed. Default 1 (single-use)."),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function buildParams(input: z.infer<typeof action_create_input>): Record<string, unknown> {
|
|
53
|
+
switch (input.action_type) {
|
|
54
|
+
case "confirm":
|
|
55
|
+
return { message: input.message, yesLabel: input.yes_label, noLabel: input.no_label };
|
|
56
|
+
case "file_request":
|
|
57
|
+
return { message: input.message, accept: input.accept, maxBytes: input.max_bytes };
|
|
58
|
+
case "form":
|
|
59
|
+
if (!input.fields?.length) throw new Error("action_type 'form' requires a non-empty `fields` array.");
|
|
60
|
+
return { message: input.message, fields: input.fields };
|
|
61
|
+
case "open_url":
|
|
62
|
+
if (!input.url) throw new Error("action_type 'open_url' requires `url`.");
|
|
63
|
+
return { message: input.message, url: input.url };
|
|
64
|
+
default:
|
|
65
|
+
return { message: input.message };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface ActionCreateResult {
|
|
70
|
+
action_id: string;
|
|
71
|
+
token: string;
|
|
72
|
+
link: string;
|
|
73
|
+
action_type: string;
|
|
74
|
+
expires_at: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function action_create(
|
|
78
|
+
input: z.infer<typeof action_create_input>,
|
|
79
|
+
ctx: MosaddToolContext,
|
|
80
|
+
): Promise<ActionCreateResult> {
|
|
81
|
+
readSupabaseEnv();
|
|
82
|
+
ctx.log("debug", "action_create invoking action-create", { action_type: input.action_type });
|
|
83
|
+
|
|
84
|
+
const body: Record<string, unknown> = {
|
|
85
|
+
action_type: input.action_type,
|
|
86
|
+
params: buildParams(input),
|
|
87
|
+
};
|
|
88
|
+
if (input.creator_label !== undefined) body.creator_label = input.creator_label;
|
|
89
|
+
if (input.ttl_ms !== undefined) body.ttl_ms = input.ttl_ms;
|
|
90
|
+
if (input.max_uses !== undefined) body.max_uses = input.max_uses;
|
|
91
|
+
|
|
92
|
+
const res = await invokeFunction<Partial<ActionCreateResult> & { error?: string }>("action-create", body);
|
|
93
|
+
if (res.error) throw new Error(res.error);
|
|
94
|
+
if (!res.link || !res.token) throw new Error("action-create returned a malformed response (missing link/token).");
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
action_id: res.action_id ?? "",
|
|
98
|
+
token: res.token,
|
|
99
|
+
link: res.link,
|
|
100
|
+
action_type: res.action_type ?? input.action_type,
|
|
101
|
+
expires_at: res.expires_at ?? "",
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const actionTools: MosaddTool[] = [
|
|
106
|
+
{
|
|
107
|
+
// RFC 0001: channel-agnostic capability (link is sent over ANY channel), so it
|
|
108
|
+
// lives in the `comms_` namespace rather than a channel `m<MODULE>_` prefix.
|
|
109
|
+
// A dedicated `mACT` module (create/get/status) is a possible RFC follow-up.
|
|
110
|
+
name: "comms_action_create",
|
|
111
|
+
requires: "network",
|
|
112
|
+
description:
|
|
113
|
+
"Mint a single-use, expiring action link (https://mosadd.com/do/<token>) that asks a human to DO something in their browser, with explicit consent. action_type: 'confirm' (yes/no) | 'file_request' (recipient picks a file from their computer) | 'form' (recipient fills fields you define) | 'open_url' (recipient opens a vetted https URL). Returns { action_id, token, link, expires_at }. Send the `link` to the person via mDM/mIRC/mAIL; they open it, consent, and the browser performs the action in its sandbox (no install, no OS access). The action is owned by you (the calling user). HONEST LIMITS: this is browser-sandbox only — it cannot click other apps, run programs, or read files the user didn't pick; and file_request payloads are not yet end-to-end encrypted (don't request sensitive files until Tier 1.1).",
|
|
114
|
+
inputSchema: action_create_input,
|
|
115
|
+
handler: action_create as MosaddTool["handler"],
|
|
116
|
+
},
|
|
117
|
+
];
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symmetric voice + file attachments across channels (mDM, mROOM, 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). mROOM and mIRC have no voice/file send
|
|
9
|
+
* at all 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
|
+
// mROOM voice/file
|
|
199
|
+
// ====================================================================
|
|
200
|
+
|
|
201
|
+
const mROOM_send_voice_input = z.object({
|
|
202
|
+
room_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
|
+
});
|
|
209
|
+
|
|
210
|
+
const mROOM_send_file_input = z.object({
|
|
211
|
+
room_id: RoomId,
|
|
212
|
+
file_base64: Base64Body,
|
|
213
|
+
filename: Filename,
|
|
214
|
+
mime: Mime,
|
|
215
|
+
caption: z.string().max(2_000).optional(),
|
|
216
|
+
reply_to_id: ReplyTo,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
async function mROOM_send_voice(input: z.infer<typeof mROOM_send_voice_input>, ctx: MosaddToolContext) {
|
|
220
|
+
const thread_id = `privroom:${input.room_id}`;
|
|
221
|
+
const attachment = await uploadBlob({
|
|
222
|
+
kind: "voice",
|
|
223
|
+
bytes: decodeBase64Body(input.audio_base64),
|
|
224
|
+
mime: input.mime,
|
|
225
|
+
prefix: thread_id,
|
|
226
|
+
duration_ms: input.duration_ms,
|
|
227
|
+
});
|
|
228
|
+
return sendAttachmentMessage(ctx, { space_id: "rooms", thread_id, message_type: "voice", attachment, caption: input.caption, reply_to_id: input.reply_to_id });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function mROOM_send_file(input: z.infer<typeof mROOM_send_file_input>, ctx: MosaddToolContext) {
|
|
232
|
+
const thread_id = `privroom:${input.room_id}`;
|
|
233
|
+
const attachment = await uploadBlob({
|
|
234
|
+
kind: "file",
|
|
235
|
+
bytes: decodeBase64Body(input.file_base64),
|
|
236
|
+
mime: input.mime,
|
|
237
|
+
prefix: thread_id,
|
|
238
|
+
filename: input.filename,
|
|
239
|
+
});
|
|
240
|
+
return sendAttachmentMessage(ctx, { space_id: "rooms", thread_id, message_type: "file", attachment, caption: input.caption, reply_to_id: input.reply_to_id });
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ====================================================================
|
|
244
|
+
// mIRC voice/file
|
|
245
|
+
// ====================================================================
|
|
246
|
+
|
|
247
|
+
const mIRC_send_voice_input = z.object({
|
|
248
|
+
channel_id: RoomId,
|
|
249
|
+
audio_base64: Base64Body,
|
|
250
|
+
mime: Mime.default("audio/ogg"),
|
|
251
|
+
duration_ms: DurationMs,
|
|
252
|
+
caption: z.string().max(2_000).optional(),
|
|
253
|
+
reply_to_id: ReplyTo,
|
|
254
|
+
space_id: z.string().optional().describe("Backing space id. Resolved automatically if omitted."),
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const mIRC_send_file_input = z.object({
|
|
258
|
+
channel_id: RoomId,
|
|
259
|
+
file_base64: Base64Body,
|
|
260
|
+
filename: Filename,
|
|
261
|
+
mime: Mime,
|
|
262
|
+
caption: z.string().max(2_000).optional(),
|
|
263
|
+
reply_to_id: ReplyTo,
|
|
264
|
+
space_id: z.string().optional(),
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
async function mIRC_send_voice(input: z.infer<typeof mIRC_send_voice_input>, ctx: MosaddToolContext) {
|
|
268
|
+
const space_id = input.space_id ?? (await resolveLinkedSpaceId(input.channel_id));
|
|
269
|
+
const thread_id = `chat:${input.channel_id}`;
|
|
270
|
+
const attachment = await uploadBlob({ kind: "voice", bytes: decodeBase64Body(input.audio_base64), mime: input.mime, prefix: thread_id, duration_ms: input.duration_ms });
|
|
271
|
+
return sendAttachmentMessage(ctx, { space_id, thread_id, message_type: "voice", attachment, caption: input.caption, reply_to_id: input.reply_to_id });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async function mIRC_send_file(input: z.infer<typeof mIRC_send_file_input>, ctx: MosaddToolContext) {
|
|
275
|
+
const space_id = input.space_id ?? (await resolveLinkedSpaceId(input.channel_id));
|
|
276
|
+
const thread_id = `chat:${input.channel_id}`;
|
|
277
|
+
const attachment = await uploadBlob({ kind: "file", bytes: decodeBase64Body(input.file_base64), mime: input.mime, prefix: thread_id, filename: input.filename });
|
|
278
|
+
return sendAttachmentMessage(ctx, { space_id, thread_id, message_type: "file", attachment, caption: input.caption, reply_to_id: input.reply_to_id });
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ---- Registration ----
|
|
282
|
+
|
|
283
|
+
export const attachmentTools: MosaddTool[] = [
|
|
284
|
+
{
|
|
285
|
+
name: "mDM_send_voice",
|
|
286
|
+
requires: "network",
|
|
287
|
+
description:
|
|
288
|
+
"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).",
|
|
289
|
+
inputSchema: mDM_send_voice_input,
|
|
290
|
+
handler: mDM_send_voice as MosaddTool["handler"],
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
name: "mDM_send_file",
|
|
294
|
+
requires: "network",
|
|
295
|
+
description:
|
|
296
|
+
"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).",
|
|
297
|
+
inputSchema: mDM_send_file_input,
|
|
298
|
+
handler: mDM_send_file as MosaddTool["handler"],
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
name: "mROOM_send_voice",
|
|
302
|
+
requires: "network",
|
|
303
|
+
description: "Send a VOICE note into a room as a first-class `voice` message. Base64 audio → Storage → message-send. Be a room member first (mROOM_join).",
|
|
304
|
+
inputSchema: mROOM_send_voice_input,
|
|
305
|
+
handler: mROOM_send_voice as MosaddTool["handler"],
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
name: "mROOM_send_file",
|
|
309
|
+
requires: "network",
|
|
310
|
+
description: "Send a FILE into a room as a first-class `file` message. Base64 bytes → Storage → message-send.",
|
|
311
|
+
inputSchema: mROOM_send_file_input,
|
|
312
|
+
handler: mROOM_send_file as MosaddTool["handler"],
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
name: "mIRC_send_voice",
|
|
316
|
+
requires: "network",
|
|
317
|
+
description: "Send a VOICE note into a persistent channel as a first-class `voice` message. Base64 audio → Storage → message-send (backing space resolved automatically).",
|
|
318
|
+
inputSchema: mIRC_send_voice_input,
|
|
319
|
+
handler: mIRC_send_voice as MosaddTool["handler"],
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
name: "mIRC_send_file",
|
|
323
|
+
requires: "network",
|
|
324
|
+
description: "Send a FILE into a persistent channel as a first-class `file` message. Base64 bytes → Storage → message-send.",
|
|
325
|
+
inputSchema: mIRC_send_file_input,
|
|
326
|
+
handler: mIRC_send_file as MosaddTool["handler"],
|
|
327
|
+
},
|
|
328
|
+
];
|
package/src/tools/index.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Tool registry. Each m* module contributes a set of tools.
|
|
3
3
|
*
|
|
4
4
|
* Live modules (6): mDM, mIRC, mROOM, mTALK, mAIL, mRAG — 61 tools + comms_capabilities.
|
|
5
|
+
* Plus action links (Tier 1): comms_action_create — agent → user one-link browser action.
|
|
5
6
|
* mURL is a consumer/brand surface (murl.mosadd.com), NOT a dev product — its tools
|
|
6
7
|
* live in tools/murl.ts but are NOT registered here (founder decision 2026-06-10).
|
|
7
8
|
* mCALL is carrier-pending (no telephony carrier live yet): its tools live in
|
|
@@ -19,9 +20,13 @@ import { mircEdgeTools } from "./mirc-edge.js";
|
|
|
19
20
|
import { mroomTools } from "./mroom.js";
|
|
20
21
|
import { mroomMessagesTools } from "./mroom-messages.js";
|
|
21
22
|
import { mailTools } from "./mail.js";
|
|
23
|
+
import { mailProvenanceTools } from "./mail-provenance.js";
|
|
22
24
|
import { mtalkTools } from "./mtalk.js";
|
|
25
|
+
import { attachmentTools } from "./attachments.js";
|
|
26
|
+
import { pttIngestTools } from "./ptt-ingest.js";
|
|
23
27
|
// import { mcallTools } from "./mcall.js"; // mCALL: carrier-pending — not registered (see header note)
|
|
24
28
|
import { knowledgeTools } from "./knowledge.js";
|
|
29
|
+
import { actionTools } from "./actions.js";
|
|
25
30
|
// import { murlTools } from "./murl.js"; // mURL: brand/consumer surface, not a dev product — not registered
|
|
26
31
|
import { makeCapabilitiesTool } from "./capabilities.js";
|
|
27
32
|
|
|
@@ -36,8 +41,12 @@ const channelTools: MosaddTool[] = [
|
|
|
36
41
|
...mroomTools,
|
|
37
42
|
...mroomMessagesTools,
|
|
38
43
|
...mailTools,
|
|
44
|
+
...mailProvenanceTools,
|
|
39
45
|
...mtalkTools,
|
|
46
|
+
...attachmentTools,
|
|
47
|
+
...pttIngestTools,
|
|
40
48
|
...knowledgeTools,
|
|
49
|
+
...actionTools, // Action links (Tier 1): agent → user one-link browser action via action-create EF
|
|
41
50
|
// ...murlTools, // mURL: brand/consumer surface (murl.mosadd.com), not a dev product
|
|
42
51
|
// ...mcallTools, // mCALL: carrier-pending (no telephony carrier live) — re-register when a carrier is configured
|
|
43
52
|
// mirlTools,
|