@mosadd/mcp 3.0.0-alpha.3 → 3.0.0-alpha.31
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/CHANGELOG.md +224 -0
- package/README.md +150 -116
- package/dist/bin/mcp.js +42 -3
- package/dist/chunk-P4ENU5MW.js +2556 -0
- package/dist/index.d.ts +99 -7
- package/dist/index.js +7 -3
- package/package.json +10 -7
- package/src/__tests__/golden-path.test.ts +137 -132
- package/src/__tests__/integration.test.ts +179 -175
- package/src/__tests__/mdm-e2ee.test.ts +212 -149
- package/src/__tests__/mtalk.test.ts +122 -0
- package/src/__tests__/server.test.ts +71 -67
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -97
- package/src/config.ts +66 -66
- package/src/crypto/mdm-session.ts +502 -378
- package/src/index.ts +19 -17
- package/src/observability/sentry.ts +79 -79
- package/src/providers/blob-upload.ts +116 -0
- package/src/providers/memory-voice.ts +79 -0
- package/src/providers/supabase-dm.ts +122 -117
- package/src/providers/supabase-voice.ts +91 -0
- package/src/providers/supabase.ts +148 -96
- package/src/server.ts +123 -103
- package/src/tools/actions.ts +162 -0
- package/src/tools/attachments.ts +268 -0
- package/src/tools/capabilities.ts +68 -68
- package/src/tools/embed.ts +108 -0
- package/src/tools/index.ts +104 -37
- package/src/tools/knowledge.ts +191 -0
- package/src/tools/mail-aliases.ts +25 -0
- package/src/tools/mail-provenance.ts +135 -0
- package/src/tools/mail.ts +381 -89
- package/src/tools/mcall.ts +216 -0
- package/src/tools/mdm-voice.ts +212 -0
- package/src/tools/mdm.ts +479 -379
- package/src/tools/mirc-edge.ts +190 -0
- package/src/tools/mirc-members.ts +198 -177
- package/src/tools/mirc-messages.ts +155 -0
- package/src/tools/mirc.ts +190 -170
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +221 -189
- package/src/tools/mtalk.ts +121 -0
- package/src/tools/murl.ts +298 -0
- package/src/tools/ptt-ingest.ts +97 -0
- package/src/tools/threat.ts +119 -0
- package/src/types.ts +94 -79
- package/src/voice/floor.ts +132 -0
- package/dist/chunk-HD5RLE5K.js +0 -1193
|
@@ -0,0 +1,162 @@
|
|
|
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/mp0st). 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, getSupabase } 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", "screen_share"]).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), 'screen_share' (recipient shares their screen so you can SEE it via comms_action_frame_get — view only).",
|
|
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
|
+
// screen_share
|
|
48
|
+
max_width: z.number().int().positive().max(1920).optional().describe("[screen_share] Max captured frame width in px (default 1280). Frames are downscaled JPEGs."),
|
|
49
|
+
// lifecycle
|
|
50
|
+
ttl_ms: z.number().int().positive().optional().describe("Link lifetime in milliseconds. Default 24h, capped at 7d."),
|
|
51
|
+
max_uses: z.number().int().min(1).max(50).optional().describe("How many times the link can be redeemed. Default 1 (single-use)."),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
function buildParams(input: z.infer<typeof action_create_input>): Record<string, unknown> {
|
|
55
|
+
switch (input.action_type) {
|
|
56
|
+
case "confirm":
|
|
57
|
+
return { message: input.message, yesLabel: input.yes_label, noLabel: input.no_label };
|
|
58
|
+
case "file_request":
|
|
59
|
+
return { message: input.message, accept: input.accept, maxBytes: input.max_bytes };
|
|
60
|
+
case "form":
|
|
61
|
+
if (!input.fields?.length) throw new Error("action_type 'form' requires a non-empty `fields` array.");
|
|
62
|
+
return { message: input.message, fields: input.fields };
|
|
63
|
+
case "open_url":
|
|
64
|
+
if (!input.url) throw new Error("action_type 'open_url' requires `url`.");
|
|
65
|
+
return { message: input.message, url: input.url };
|
|
66
|
+
case "screen_share":
|
|
67
|
+
return { message: input.message, maxWidth: input.max_width };
|
|
68
|
+
default:
|
|
69
|
+
return { message: input.message };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface ActionCreateResult {
|
|
74
|
+
action_id: string;
|
|
75
|
+
token: string;
|
|
76
|
+
link: string;
|
|
77
|
+
action_type: string;
|
|
78
|
+
expires_at: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function action_create(
|
|
82
|
+
input: z.infer<typeof action_create_input>,
|
|
83
|
+
ctx: MosaddToolContext,
|
|
84
|
+
): Promise<ActionCreateResult> {
|
|
85
|
+
readSupabaseEnv();
|
|
86
|
+
ctx.log("debug", "action_create invoking action-create", { action_type: input.action_type });
|
|
87
|
+
|
|
88
|
+
const body: Record<string, unknown> = {
|
|
89
|
+
action_type: input.action_type,
|
|
90
|
+
params: buildParams(input),
|
|
91
|
+
};
|
|
92
|
+
if (input.creator_label !== undefined) body.creator_label = input.creator_label;
|
|
93
|
+
if (input.ttl_ms !== undefined) body.ttl_ms = input.ttl_ms;
|
|
94
|
+
if (input.max_uses !== undefined) body.max_uses = input.max_uses;
|
|
95
|
+
|
|
96
|
+
const res = await invokeFunction<Partial<ActionCreateResult> & { error?: string }>("action-create", body);
|
|
97
|
+
if (res.error) throw new Error(res.error);
|
|
98
|
+
if (!res.link || !res.token) throw new Error("action-create returned a malformed response (missing link/token).");
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
action_id: res.action_id ?? "",
|
|
102
|
+
token: res.token,
|
|
103
|
+
link: res.link,
|
|
104
|
+
action_type: res.action_type ?? input.action_type,
|
|
105
|
+
expires_at: res.expires_at ?? "",
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ── comms_action_frame_get — read the latest screen frame (Tier 1.5) ──────────
|
|
110
|
+
const action_frame_get_input = z.object({
|
|
111
|
+
action_id: z.string().min(1).describe("The action_id returned by comms_action_create for a 'screen_share' action you created."),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
async function action_frame_get(
|
|
115
|
+
input: z.infer<typeof action_frame_get_input>,
|
|
116
|
+
ctx: MosaddToolContext,
|
|
117
|
+
): Promise<{ mcpContent: Array<Record<string, unknown>> }> {
|
|
118
|
+
readSupabaseEnv();
|
|
119
|
+
ctx.log("debug", "action_frame_get reading frame", { action_id: input.action_id });
|
|
120
|
+
// Read directly via RLS ("creators read own frames") — the agent's JWT gates it
|
|
121
|
+
// to screen_share actions it created. No edge function needed.
|
|
122
|
+
const sb = getSupabase();
|
|
123
|
+
const { data, error } = await sb
|
|
124
|
+
.from("action_screen_frames")
|
|
125
|
+
.select("image_jpeg, width, seq, updated_at")
|
|
126
|
+
.eq("action_id", input.action_id)
|
|
127
|
+
.maybeSingle();
|
|
128
|
+
if (error) throw new Error(error.message);
|
|
129
|
+
if (!data) {
|
|
130
|
+
return { mcpContent: [{ type: "text", text: "No frame yet — the recipient hasn't started sharing their screen (or you don't own this action)." }] };
|
|
131
|
+
}
|
|
132
|
+
const row = data as { image_jpeg: string; width: number | null; seq: number; updated_at: string };
|
|
133
|
+
const ageSec = Math.round((Date.now() - new Date(row.updated_at).getTime()) / 1000);
|
|
134
|
+
return {
|
|
135
|
+
mcpContent: [
|
|
136
|
+
{ type: "text", text: `Latest screen frame — seq ${row.seq}, ${row.width ?? "?"}px wide, ${ageSec}s old.` },
|
|
137
|
+
{ type: "image", data: row.image_jpeg, mimeType: "image/jpeg" },
|
|
138
|
+
],
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const actionTools: MosaddTool[] = [
|
|
143
|
+
{
|
|
144
|
+
// RFC 0001: channel-agnostic capability (link is sent over ANY channel), so it
|
|
145
|
+
// lives in the `comms_` namespace rather than a channel `m<MODULE>_` prefix.
|
|
146
|
+
// A dedicated `mACT` module (create/get/status) is a possible RFC follow-up.
|
|
147
|
+
name: "comms_action_create",
|
|
148
|
+
requires: "network",
|
|
149
|
+
description:
|
|
150
|
+
"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/mp0st; 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).",
|
|
151
|
+
inputSchema: action_create_input,
|
|
152
|
+
handler: action_create as MosaddTool["handler"],
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: "comms_action_frame_get",
|
|
156
|
+
requires: "network",
|
|
157
|
+
description:
|
|
158
|
+
"See the LATEST screen frame from a 'screen_share' action you created (pass the action_id from comms_action_create). Returns the current screenshot AS AN IMAGE you can look at, plus how old it is. The recipient must have opened the link and clicked 'share screen' first. Poll this every few seconds to watch live. VIEW ONLY — you cannot click or control their screen. Returns a 'no frame yet' note until they start sharing.",
|
|
159
|
+
inputSchema: action_frame_get_input,
|
|
160
|
+
handler: action_frame_get as MosaddTool["handler"],
|
|
161
|
+
},
|
|
162
|
+
];
|
|
@@ -0,0 +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,68 +1,68 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* comms_capabilities — capability discovery for consuming hosts.
|
|
3
|
-
*
|
|
4
|
-
* THE contract surface between mosadd-os and carrier-aware hosts (e.g.
|
|
5
|
-
* cymru-os, which filters tools by available transports — see cymru-os RFC
|
|
6
|
-
* 0002 D-Bus "Capability-flag bridge"). A host spawns `@mosadd/mcp` over stdio
|
|
7
|
-
* and calls `comms_capabilities` once to learn which tools are usable on which
|
|
8
|
-
* carrier, then gates the tool list accordingly (e.g. off-grid radio →
|
|
9
|
-
* only `requires: "any" | "radio"` tools are offered).
|
|
10
|
-
*
|
|
11
|
-
* `requires: "any"` here too — discovery must work on any transport, including
|
|
12
|
-
* off-grid radio, otherwise a host couldn't learn what it's allowed to call.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { z } from "zod";
|
|
16
|
-
import type { CapabilityRequirement, MosaddTool } from "../types.js";
|
|
17
|
-
|
|
18
|
-
export interface CapabilityEntry {
|
|
19
|
-
name: string;
|
|
20
|
-
requires: CapabilityRequirement;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface CapabilityManifest {
|
|
24
|
-
/** Stable contract version. Bump on any enum/shape change (requires:cymru-input). */
|
|
25
|
-
contract_version: string;
|
|
26
|
-
/** The finalized capability enum, echoed so hosts can validate against it. */
|
|
27
|
-
requirements: CapabilityRequirement[];
|
|
28
|
-
/** Flat list of every tool and its transport requirement. */
|
|
29
|
-
tools: CapabilityEntry[];
|
|
30
|
-
/** Pre-grouped by requirement for cheap host-side filtering. */
|
|
31
|
-
by_requirement: Record<CapabilityRequirement, string[]>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const CONTRACT_VERSION = "1.0.0";
|
|
35
|
-
const ALL_REQUIREMENTS: CapabilityRequirement[] = ["any", "radio", "network"];
|
|
36
|
-
|
|
37
|
-
/** Build the capability manifest from a tool list. Pure, host-agnostic. */
|
|
38
|
-
export function buildCapabilityManifest(tools: MosaddTool[]): CapabilityManifest {
|
|
39
|
-
const entries: CapabilityEntry[] = tools.map((t) => ({ name: t.name, requires: t.requires }));
|
|
40
|
-
const by_requirement: Record<CapabilityRequirement, string[]> = {
|
|
41
|
-
any: [],
|
|
42
|
-
radio: [],
|
|
43
|
-
network: [],
|
|
44
|
-
};
|
|
45
|
-
for (const e of entries) by_requirement[e.requires].push(e.name);
|
|
46
|
-
return {
|
|
47
|
-
contract_version: CONTRACT_VERSION,
|
|
48
|
-
requirements: ALL_REQUIREMENTS,
|
|
49
|
-
tools: entries,
|
|
50
|
-
by_requirement,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Factory: build the comms_capabilities tool over a given tool set. The tool
|
|
56
|
-
* itself is appended to that set, so it self-reports too (requires: "any").
|
|
57
|
-
*/
|
|
58
|
-
export function makeCapabilitiesTool(channelTools: MosaddTool[]): MosaddTool {
|
|
59
|
-
const tool: MosaddTool = {
|
|
60
|
-
name: "comms_capabilities",
|
|
61
|
-
requires: "any",
|
|
62
|
-
description:
|
|
63
|
-
"Discover which mosadd tools are available and what transport each requires (any | radio | network). Carrier-aware hosts (e.g. off-grid radio devices) call this once to gate the tool list to what the current carrier supports. Returns a manifest with per-tool requirements grouped by transport.",
|
|
64
|
-
inputSchema: z.object({}),
|
|
65
|
-
handler: async () => buildCapabilityManifest([...channelTools, tool]),
|
|
66
|
-
};
|
|
67
|
-
return tool;
|
|
68
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* comms_capabilities — capability discovery for consuming hosts.
|
|
3
|
+
*
|
|
4
|
+
* THE contract surface between mosadd-os and carrier-aware hosts (e.g.
|
|
5
|
+
* cymru-os, which filters tools by available transports — see cymru-os RFC
|
|
6
|
+
* 0002 D-Bus "Capability-flag bridge"). A host spawns `@mosadd/mcp` over stdio
|
|
7
|
+
* and calls `comms_capabilities` once to learn which tools are usable on which
|
|
8
|
+
* carrier, then gates the tool list accordingly (e.g. off-grid radio →
|
|
9
|
+
* only `requires: "any" | "radio"` tools are offered).
|
|
10
|
+
*
|
|
11
|
+
* `requires: "any"` here too — discovery must work on any transport, including
|
|
12
|
+
* off-grid radio, otherwise a host couldn't learn what it's allowed to call.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
import type { CapabilityRequirement, MosaddTool } from "../types.js";
|
|
17
|
+
|
|
18
|
+
export interface CapabilityEntry {
|
|
19
|
+
name: string;
|
|
20
|
+
requires: CapabilityRequirement;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CapabilityManifest {
|
|
24
|
+
/** Stable contract version. Bump on any enum/shape change (requires:cymru-input). */
|
|
25
|
+
contract_version: string;
|
|
26
|
+
/** The finalized capability enum, echoed so hosts can validate against it. */
|
|
27
|
+
requirements: CapabilityRequirement[];
|
|
28
|
+
/** Flat list of every tool and its transport requirement. */
|
|
29
|
+
tools: CapabilityEntry[];
|
|
30
|
+
/** Pre-grouped by requirement for cheap host-side filtering. */
|
|
31
|
+
by_requirement: Record<CapabilityRequirement, string[]>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const CONTRACT_VERSION = "1.0.0";
|
|
35
|
+
const ALL_REQUIREMENTS: CapabilityRequirement[] = ["any", "radio", "network"];
|
|
36
|
+
|
|
37
|
+
/** Build the capability manifest from a tool list. Pure, host-agnostic. */
|
|
38
|
+
export function buildCapabilityManifest(tools: MosaddTool[]): CapabilityManifest {
|
|
39
|
+
const entries: CapabilityEntry[] = tools.map((t) => ({ name: t.name, requires: t.requires }));
|
|
40
|
+
const by_requirement: Record<CapabilityRequirement, string[]> = {
|
|
41
|
+
any: [],
|
|
42
|
+
radio: [],
|
|
43
|
+
network: [],
|
|
44
|
+
};
|
|
45
|
+
for (const e of entries) by_requirement[e.requires].push(e.name);
|
|
46
|
+
return {
|
|
47
|
+
contract_version: CONTRACT_VERSION,
|
|
48
|
+
requirements: ALL_REQUIREMENTS,
|
|
49
|
+
tools: entries,
|
|
50
|
+
by_requirement,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Factory: build the comms_capabilities tool over a given tool set. The tool
|
|
56
|
+
* itself is appended to that set, so it self-reports too (requires: "any").
|
|
57
|
+
*/
|
|
58
|
+
export function makeCapabilitiesTool(channelTools: MosaddTool[]): MosaddTool {
|
|
59
|
+
const tool: MosaddTool = {
|
|
60
|
+
name: "comms_capabilities",
|
|
61
|
+
requires: "any",
|
|
62
|
+
description:
|
|
63
|
+
"Discover which mosadd tools are available and what transport each requires (any | radio | network). Carrier-aware hosts (e.g. off-grid radio devices) call this once to gate the tool list to what the current carrier supports. Returns a manifest with per-tool requirements grouped by transport.",
|
|
64
|
+
inputSchema: z.object({}),
|
|
65
|
+
handler: async () => buildCapabilityManifest([...channelTools, tool]),
|
|
66
|
+
};
|
|
67
|
+
return tool;
|
|
68
|
+
}
|