@mosadd/mcp 3.0.0-alpha.0 → 3.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -116
- package/dist/bin/login.d.ts +13 -0
- package/dist/bin/login.js +110 -0
- package/dist/bin/mcp.js +36 -1
- package/dist/chunk-6EPYADVR.js +2095 -0
- package/dist/chunk-Z7WR52GE.js +45 -0
- package/dist/index.d.ts +46 -4
- package/dist/index.js +6 -3
- package/package.json +11 -7
- package/src/__tests__/golden-path.test.ts +137 -132
- package/src/__tests__/integration.test.ts +178 -175
- package/src/__tests__/mdm-e2ee.test.ts +178 -149
- package/src/__tests__/mtalk.test.ts +122 -0
- package/src/__tests__/server.test.ts +67 -67
- package/src/bin/login.ts +138 -0
- package/src/bin/mcp.ts +97 -47
- package/src/config.ts +66 -0
- package/src/crypto/mdm-session.ts +403 -378
- package/src/index.ts +19 -17
- package/src/observability/sentry.ts +79 -79
- package/src/providers/memory-voice.ts +79 -0
- package/src/providers/supabase-dm.ts +117 -117
- package/src/providers/supabase-voice.ts +91 -0
- package/src/providers/supabase.ts +49 -9
- package/src/server.ts +105 -103
- package/src/tools/capabilities.ts +68 -68
- package/src/tools/index.ts +53 -37
- package/src/tools/knowledge.ts +191 -0
- package/src/tools/mail.ts +371 -89
- package/src/tools/mcall.ts +216 -0
- package/src/tools/mdm-voice.ts +206 -0
- package/src/tools/mdm.ts +448 -379
- package/src/tools/mirc-edge.ts +190 -0
- package/src/tools/mirc-members.ts +177 -177
- package/src/tools/mirc-messages.ts +156 -0
- package/src/tools/mirc.ts +170 -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 +141 -0
- package/src/types.ts +85 -79
- package/src/voice/floor.ts +132 -0
- package/dist/chunk-25L536JZ.js +0 -1182
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mRAG — Knowledge Base (RAG): search and reason over the user's own mosadd data.
|
|
3
|
+
*
|
|
4
|
+
* This is the developer-facing surface of the RAG pipeline that already runs
|
|
5
|
+
* inside the mosadd backend: every message/email/call is embedded into a
|
|
6
|
+
* private per-user vector index (rag_embeddings) with hybrid vector + BM25
|
|
7
|
+
* retrieval, Cohere reranking, and a freshness lane for just-sent items. The
|
|
8
|
+
* `mRAG_search` tool lets an AGENT query that index — semantic recall over
|
|
9
|
+
* the user's communications — WITHOUT the mosadd.com app. It is the dev-product
|
|
10
|
+
* form of RAG (decision C): the same engine, exposed as one MCP tool.
|
|
11
|
+
*
|
|
12
|
+
* Wired to the mosadd backend's `rag-query` Edge Function. The answer + cited sources
|
|
13
|
+
* come back grounded strictly in the user's indexed data (no fabrication).
|
|
14
|
+
*
|
|
15
|
+
* Plan note: on the hosted hub this tool is gated by plan (free = off,
|
|
16
|
+
* pro/team = on); BYOK/self-host runs it against the user's own backend. Gating
|
|
17
|
+
* is enforced at the hub, not in this tool.
|
|
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 mRAG_search_input = z.object({
|
|
25
|
+
query: z
|
|
26
|
+
.string()
|
|
27
|
+
.min(1)
|
|
28
|
+
.max(2_000)
|
|
29
|
+
.describe("Natural-language question to answer from the user's own indexed messages/emails/calls/notes."),
|
|
30
|
+
top_k: z
|
|
31
|
+
.number()
|
|
32
|
+
.int()
|
|
33
|
+
.min(1)
|
|
34
|
+
.max(25)
|
|
35
|
+
.optional()
|
|
36
|
+
.describe("Max number of source chunks to retrieve and ground the answer in. Default 8."),
|
|
37
|
+
source_types: z
|
|
38
|
+
.array(z.enum(["message", "email", "call", "note", "contact"]))
|
|
39
|
+
.optional()
|
|
40
|
+
.describe("Restrict retrieval to these source types. Omit to search everything."),
|
|
41
|
+
thread_id: z
|
|
42
|
+
.string()
|
|
43
|
+
.optional()
|
|
44
|
+
.describe("Optional: restrict retrieval to a single thread id (e.g. a dm:/chat: thread)."),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
interface RagSource {
|
|
48
|
+
source_type: string;
|
|
49
|
+
source_id: string;
|
|
50
|
+
thread_id: string | null;
|
|
51
|
+
similarity: number;
|
|
52
|
+
snippet: string;
|
|
53
|
+
created_at: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function mRAG_search(
|
|
57
|
+
input: z.infer<typeof mRAG_search_input>,
|
|
58
|
+
ctx: MosaddToolContext,
|
|
59
|
+
): Promise<{ answer: string; sources: RagSource[]; chunks_found: number }> {
|
|
60
|
+
readSupabaseEnv();
|
|
61
|
+
ctx.log("debug", "mRAG_search via rag-query", { top_k: input.top_k ?? 8 });
|
|
62
|
+
|
|
63
|
+
type RagQueryResponse = {
|
|
64
|
+
answer?: string;
|
|
65
|
+
sources?: RagSource[];
|
|
66
|
+
chunks_found?: number;
|
|
67
|
+
};
|
|
68
|
+
const data = await invokeFunction<RagQueryResponse>("rag-query", {
|
|
69
|
+
query: input.query,
|
|
70
|
+
top_k: input.top_k ?? 8,
|
|
71
|
+
source_types: input.source_types ?? null,
|
|
72
|
+
thread_id: input.thread_id ?? null,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
answer: data.answer ?? "",
|
|
77
|
+
sources: data.sources ?? [],
|
|
78
|
+
chunks_found: data.chunks_found ?? (data.sources?.length ?? 0),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const mRAG_ingest_input = z.object({
|
|
83
|
+
content_text: z
|
|
84
|
+
.string()
|
|
85
|
+
.min(1)
|
|
86
|
+
.max(200_000)
|
|
87
|
+
.describe("Text to index into the user's private knowledge base (a note, document, transcript, pasted page…). Chunked + embedded server-side."),
|
|
88
|
+
source_type: z
|
|
89
|
+
.enum(["file", "note", "message", "email", "contact", "call"])
|
|
90
|
+
.optional()
|
|
91
|
+
.describe("What kind of source this is. Default 'file' (a document/note). Use 'note' for ad-hoc text."),
|
|
92
|
+
source_id: z.string().optional().describe("Optional stable id for the source so re-ingests can be grouped."),
|
|
93
|
+
thread_id: z.string().optional().describe("Optional thread id to associate this knowledge with (e.g. a dm:/chat: thread)."),
|
|
94
|
+
title: z.string().max(300).optional().describe("Optional human title, stored in metadata."),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
async function mRAG_ingest(
|
|
98
|
+
input: z.infer<typeof mRAG_ingest_input>,
|
|
99
|
+
ctx: MosaddToolContext,
|
|
100
|
+
): Promise<{ indexed: number; chunk_count: number }> {
|
|
101
|
+
readSupabaseEnv();
|
|
102
|
+
// rag-index accepts a fixed source_type set; map "note" → "file".
|
|
103
|
+
const backendType = input.source_type === "note" ? "file" : (input.source_type ?? "file");
|
|
104
|
+
ctx.log("debug", "mRAG_ingest via rag-index", { source_type: backendType });
|
|
105
|
+
const data = await invokeFunction<{ indexed?: number; chunk_count?: number }>("rag-index", {
|
|
106
|
+
source_type: backendType,
|
|
107
|
+
source_id: input.source_id ?? null,
|
|
108
|
+
thread_id: input.thread_id ?? null,
|
|
109
|
+
content_text: input.content_text,
|
|
110
|
+
metadata: { ...(input.title ? { title: input.title } : {}), ingested_via: "mRAG_ingest" },
|
|
111
|
+
});
|
|
112
|
+
return { indexed: data.indexed ?? 0, chunk_count: data.chunk_count ?? 0 };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const mRAG_list_sources_input = z.object({});
|
|
116
|
+
|
|
117
|
+
interface RagSourceEntry {
|
|
118
|
+
source_type: string;
|
|
119
|
+
source_id: string | null;
|
|
120
|
+
thread_id: string | null;
|
|
121
|
+
title: string | null;
|
|
122
|
+
chunks: number;
|
|
123
|
+
first_indexed: string;
|
|
124
|
+
last_indexed: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function mRAG_list_sources(
|
|
128
|
+
_input: z.infer<typeof mRAG_list_sources_input>,
|
|
129
|
+
ctx: MosaddToolContext,
|
|
130
|
+
): Promise<{ sources: RagSourceEntry[]; total_sources: number; total_chunks: number }> {
|
|
131
|
+
readSupabaseEnv();
|
|
132
|
+
ctx.log("debug", "mRAG_list_sources via rag-sources");
|
|
133
|
+
return await invokeFunction("rag-sources", { action: "list" });
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const mRAG_delete_input = z
|
|
137
|
+
.object({
|
|
138
|
+
source_id: z.string().optional().describe("Delete every indexed chunk with this source_id (from mRAG_list_sources)."),
|
|
139
|
+
thread_id: z.string().optional().describe("Delete every indexed chunk associated with this thread_id."),
|
|
140
|
+
})
|
|
141
|
+
.refine((v) => v.source_id || v.thread_id, {
|
|
142
|
+
message: "Provide source_id or thread_id — mRAG_delete refuses to purge the whole index.",
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
async function mRAG_delete(
|
|
146
|
+
input: z.infer<typeof mRAG_delete_input>,
|
|
147
|
+
ctx: MosaddToolContext,
|
|
148
|
+
): Promise<{ ok: true; deleted: number; source_id: string | null; thread_id: string | null }> {
|
|
149
|
+
readSupabaseEnv();
|
|
150
|
+
ctx.log("debug", "mRAG_delete via rag-sources", { source_id: input.source_id, thread_id: input.thread_id });
|
|
151
|
+
return await invokeFunction("rag-sources", {
|
|
152
|
+
action: "delete",
|
|
153
|
+
source_id: input.source_id ?? null,
|
|
154
|
+
thread_id: input.thread_id ?? null,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export const knowledgeTools: MosaddTool[] = [
|
|
159
|
+
{
|
|
160
|
+
name: "mRAG_ingest",
|
|
161
|
+
requires: "network",
|
|
162
|
+
description:
|
|
163
|
+
"Add text to the USER'S OWN private knowledge base so mRAG_search can recall it later. Pass content_text (a note, document, transcript, pasted page); it is semantically chunked, embedded (1536-d) and stored in the per-user vector index mRAG_search reads. Returns how many chunks were indexed. NOTE: indexed content is stored server-side in plaintext — NOT covered by the zero-knowledge / E2EE guarantee. Only ingest what the user opted to make searchable.",
|
|
164
|
+
inputSchema: mRAG_ingest_input,
|
|
165
|
+
handler: mRAG_ingest as MosaddTool["handler"],
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: "mRAG_search",
|
|
169
|
+
requires: "network",
|
|
170
|
+
description:
|
|
171
|
+
"Search and answer questions over the USER'S OWN mosadd data (messages, emails, calls, notes) with a private per-user RAG index — hybrid vector + keyword retrieval, reranked, grounded in cited sources (no fabrication). Use it to recall 'what did X say about Y', summarize a thread, or pull facts the user has received. Returns an answer plus the source snippets it used. This is agent memory (mRAG = RAG over your own data) over the user's communications, available outside the mosadd app. NOTE: RAG requires content to be indexed server-side in plaintext, so anything searchable here is NOT covered by the zero-knowledge / E2EE guarantee — only data the user has explicitly opted into indexing is searchable. See docs/security/e2ee-posture.md.",
|
|
172
|
+
inputSchema: mRAG_search_input,
|
|
173
|
+
handler: mRAG_search as MosaddTool["handler"],
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: "mRAG_list_sources",
|
|
177
|
+
requires: "network",
|
|
178
|
+
description:
|
|
179
|
+
"List what is currently indexed in the user's private knowledge base, grouped by source (source_type, source_id, thread_id, title) with per-source chunk counts and first/last indexed timestamps. Use it to see what mRAG_search can recall, and to find a source_id to remove with mRAG_delete. Owner-scoped.",
|
|
180
|
+
inputSchema: mRAG_list_sources_input,
|
|
181
|
+
handler: mRAG_list_sources as MosaddTool["handler"],
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
name: "mRAG_delete",
|
|
185
|
+
requires: "network",
|
|
186
|
+
description:
|
|
187
|
+
"Remove indexed content from the user's knowledge base by source_id or thread_id (from mRAG_list_sources). Deletes every embedded chunk for that source so mRAG_search can no longer recall it. Requires source_id or thread_id (will not purge the whole index). Returns the number of chunks deleted. Owner-scoped.",
|
|
188
|
+
inputSchema: mRAG_delete_input,
|
|
189
|
+
handler: mRAG_delete as MosaddTool["handler"],
|
|
190
|
+
},
|
|
191
|
+
];
|
package/src/tools/mail.ts
CHANGED
|
@@ -1,89 +1,371 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mAIL — Email.
|
|
3
|
-
*
|
|
4
|
-
* Every mosadd user gets `<userId>@mosadd.com` for free — incoming mail lands
|
|
5
|
-
* in their app, outgoing mail flows through the
|
|
6
|
-
*
|
|
7
|
-
* Phase 1 alpha: wired to
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { z } from "zod";
|
|
11
|
-
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
12
|
-
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
13
|
-
|
|
14
|
-
// ---- Schemas ----
|
|
15
|
-
|
|
16
|
-
const EmailAddress = z
|
|
17
|
-
.string()
|
|
18
|
-
.email()
|
|
19
|
-
.max(254)
|
|
20
|
-
.describe("RFC 5321 email address.");
|
|
21
|
-
|
|
22
|
-
const MessageId = z.string().min(1).describe("Message id (UUID) from mAIL_send or inbox.");
|
|
23
|
-
|
|
24
|
-
const mAIL_send_input = z.object({
|
|
25
|
-
to: z.union([EmailAddress, z.array(EmailAddress).min(1).max(50)]).describe(
|
|
26
|
-
"Recipient(s). Single address or array of up to 50.",
|
|
27
|
-
),
|
|
28
|
-
subject: z.string().min(1).max(998).describe("Email subject line. Max 998 chars (RFC 5322)."),
|
|
29
|
-
body_text: z.string().max(1_048_576).optional().describe("Plain text body. Max 1 MB."),
|
|
30
|
-
body_html: z.string().max(1_048_576).optional().describe("HTML body. Max 1 MB."),
|
|
31
|
-
cc: z.array(EmailAddress).max(50).optional(),
|
|
32
|
-
bcc: z.array(EmailAddress).max(50).optional(),
|
|
33
|
-
reply_to: EmailAddress.optional(),
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
/**
|
|
2
|
+
* mAIL — Email.
|
|
3
|
+
*
|
|
4
|
+
* Every mosadd user gets `<userId>@mosadd.com` for free — incoming mail lands
|
|
5
|
+
* in their app, outgoing mail flows through the mosadd mp0st pipeline.
|
|
6
|
+
*
|
|
7
|
+
* Phase 1 alpha: wired to the mosadd backend's `mp0st-send` + `mp0st-view` Edge Functions.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
12
|
+
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
13
|
+
|
|
14
|
+
// ---- Schemas ----
|
|
15
|
+
|
|
16
|
+
const EmailAddress = z
|
|
17
|
+
.string()
|
|
18
|
+
.email()
|
|
19
|
+
.max(254)
|
|
20
|
+
.describe("RFC 5321 email address.");
|
|
21
|
+
|
|
22
|
+
const MessageId = z.string().min(1).describe("Message id (UUID) from mAIL_send or inbox.");
|
|
23
|
+
|
|
24
|
+
const mAIL_send_input = z.object({
|
|
25
|
+
to: z.union([EmailAddress, z.array(EmailAddress).min(1).max(50)]).describe(
|
|
26
|
+
"Recipient(s). Single address or array of up to 50.",
|
|
27
|
+
),
|
|
28
|
+
subject: z.string().min(1).max(998).describe("Email subject line. Max 998 chars (RFC 5322)."),
|
|
29
|
+
body_text: z.string().max(1_048_576).optional().describe("Plain text body. Max 1 MB."),
|
|
30
|
+
body_html: z.string().max(1_048_576).optional().describe("HTML body. Max 1 MB."),
|
|
31
|
+
cc: z.array(EmailAddress).max(50).optional(),
|
|
32
|
+
bcc: z.array(EmailAddress).max(50).optional(),
|
|
33
|
+
reply_to: EmailAddress.optional(),
|
|
34
|
+
tracking: z
|
|
35
|
+
.boolean()
|
|
36
|
+
.optional()
|
|
37
|
+
.describe("Open-pixel + link-click tracking. Default true. Set false to send with NO tracking (privacy / GDPR-friendly)."),
|
|
38
|
+
force_reader: z
|
|
39
|
+
.boolean()
|
|
40
|
+
.optional()
|
|
41
|
+
.describe("Default false. If true, the email body is a stub only and the recipient must open it in mosadd's secure reader — maximizes tracking (print/copy/time-on-read become observable). Best for confidential / legal mail."),
|
|
42
|
+
disclose_tracking: z
|
|
43
|
+
.boolean()
|
|
44
|
+
.optional()
|
|
45
|
+
.describe("Default false. If true (and tracking on), append a tracking-disclosure footer to the email — recommended for GDPR/ePrivacy compliance."),
|
|
46
|
+
watermark: z
|
|
47
|
+
.union([z.boolean(), z.string().max(120)])
|
|
48
|
+
.optional()
|
|
49
|
+
.describe("Inject a faint recipient watermark into the secure reader (shows in screenshots/prints). Pass true to watermark with the recipient address, or a custom string."),
|
|
50
|
+
auto_destruct: z
|
|
51
|
+
.enum(["1h", "24h", "7d"])
|
|
52
|
+
.optional()
|
|
53
|
+
.describe("Self-destruct timer: the secure-reader link expires after this window."),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const mAIL_view_input = z.object({
|
|
57
|
+
message_id: MessageId,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const mAIL_delete_input = z.object({
|
|
61
|
+
message_id: MessageId,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const mAIL_list_input = z.object({
|
|
65
|
+
direction: z
|
|
66
|
+
.enum(["inbound", "outbound"])
|
|
67
|
+
.optional()
|
|
68
|
+
.describe("Filter to received (inbound) or sent (outbound) mail. Omit for both."),
|
|
69
|
+
limit: z.number().int().min(1).max(200).optional().describe("Max emails to return. Default 50."),
|
|
70
|
+
before: z
|
|
71
|
+
.string()
|
|
72
|
+
.optional()
|
|
73
|
+
.describe("Pagination cursor: pass the previous response's next_cursor to get the next (older) page."),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const mAIL_stats_input = z.object({
|
|
77
|
+
message_id: MessageId,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const mAIL_events_input = z.object({
|
|
81
|
+
message_id: MessageId,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const mAIL_metrics_input = z.object({});
|
|
85
|
+
|
|
86
|
+
const mAIL_revoke_input = z.object({
|
|
87
|
+
message_id: MessageId,
|
|
88
|
+
restore: z
|
|
89
|
+
.boolean()
|
|
90
|
+
.optional()
|
|
91
|
+
.describe("Set true to UN-revoke (restore access). Default false = revoke."),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const mAIL_audit_export_input = z.object({
|
|
95
|
+
message_id: MessageId,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const mAIL_consent_input = z.object({
|
|
99
|
+
action: z
|
|
100
|
+
.enum(["list", "check", "optin"])
|
|
101
|
+
.describe("'list' = recipients who opted out of your tracking; 'check' = is one recipient opted out; 'optin' = re-enable tracking for a recipient."),
|
|
102
|
+
recipient: EmailAddress.optional().describe("Required for 'check' and 'optin'."),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const mAIL_notify_input = z.object({
|
|
106
|
+
since: z
|
|
107
|
+
.string()
|
|
108
|
+
.optional()
|
|
109
|
+
.describe("ISO-8601 cursor — return only events newer than this. Pass the previous response's `cursor` to poll for new activity."),
|
|
110
|
+
limit: z.number().int().min(1).max(200).optional().describe("Max events. Default 50."),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
interface MailListItem {
|
|
114
|
+
message_id: string;
|
|
115
|
+
direction: "inbound" | "outbound";
|
|
116
|
+
from: string;
|
|
117
|
+
to: string;
|
|
118
|
+
subject: string;
|
|
119
|
+
priority: string;
|
|
120
|
+
status: string;
|
|
121
|
+
sent_at: string;
|
|
122
|
+
snippet: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ---- Handlers ----
|
|
126
|
+
|
|
127
|
+
async function mAIL_send(
|
|
128
|
+
input: z.infer<typeof mAIL_send_input>,
|
|
129
|
+
ctx: MosaddToolContext,
|
|
130
|
+
): Promise<{ message_id: string; queued_at: string }> {
|
|
131
|
+
readSupabaseEnv();
|
|
132
|
+
if (!input.body_text && !input.body_html) {
|
|
133
|
+
throw new Error("mAIL_send requires at least one of body_text or body_html.");
|
|
134
|
+
}
|
|
135
|
+
ctx.log("debug", "mAIL_send invoking mp0st-send", { to: input.to });
|
|
136
|
+
return await invokeFunction<{ message_id: string; queued_at: string }>("mp0st-send", input);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function mAIL_view(
|
|
140
|
+
input: z.infer<typeof mAIL_view_input>,
|
|
141
|
+
ctx: MosaddToolContext,
|
|
142
|
+
): Promise<{
|
|
143
|
+
message_id: string;
|
|
144
|
+
from: string;
|
|
145
|
+
to: string[];
|
|
146
|
+
subject: string;
|
|
147
|
+
body_text: string | null;
|
|
148
|
+
body_html: string | null;
|
|
149
|
+
received_at: string;
|
|
150
|
+
}> {
|
|
151
|
+
readSupabaseEnv();
|
|
152
|
+
ctx.log("debug", "mAIL_view invoking mp0st-view", { message_id: input.message_id });
|
|
153
|
+
return await invokeFunction("mp0st-view", { message_id: input.message_id });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function mAIL_list(
|
|
157
|
+
input: z.infer<typeof mAIL_list_input>,
|
|
158
|
+
ctx: MosaddToolContext,
|
|
159
|
+
): Promise<{ emails: MailListItem[]; next_cursor: string | null }> {
|
|
160
|
+
readSupabaseEnv();
|
|
161
|
+
ctx.log("debug", "mAIL_list invoking mp0st-list", { direction: input.direction });
|
|
162
|
+
return await invokeFunction<{ emails: MailListItem[]; next_cursor: string | null }>("mp0st-list", {
|
|
163
|
+
direction: input.direction ?? null,
|
|
164
|
+
limit: input.limit ?? 50,
|
|
165
|
+
before: input.before ?? null,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function mAIL_delete(
|
|
170
|
+
input: z.infer<typeof mAIL_delete_input>,
|
|
171
|
+
ctx: MosaddToolContext,
|
|
172
|
+
): Promise<{ ok: true; message_id: string; deleted: true }> {
|
|
173
|
+
readSupabaseEnv();
|
|
174
|
+
ctx.log("debug", "mAIL_delete invoking mp0st-delete", { message_id: input.message_id });
|
|
175
|
+
return await invokeFunction<{ ok: true; message_id: string; deleted: true }>("mp0st-delete", {
|
|
176
|
+
message_id: input.message_id,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
interface MailEngagement {
|
|
181
|
+
message_id: string;
|
|
182
|
+
subject: string;
|
|
183
|
+
to: string;
|
|
184
|
+
direction: string;
|
|
185
|
+
status: string;
|
|
186
|
+
sent_at: string;
|
|
187
|
+
open_count: number;
|
|
188
|
+
unique_opens: number;
|
|
189
|
+
click_count: number;
|
|
190
|
+
forwarded: boolean;
|
|
191
|
+
first_opened_at: string | null;
|
|
192
|
+
last_opened_at: string | null;
|
|
193
|
+
events_by_type: Record<string, number>;
|
|
194
|
+
total_events: number;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function mAIL_stats(
|
|
198
|
+
input: z.infer<typeof mAIL_stats_input>,
|
|
199
|
+
ctx: MosaddToolContext,
|
|
200
|
+
): Promise<{ summary: MailEngagement }> {
|
|
201
|
+
readSupabaseEnv();
|
|
202
|
+
ctx.log("debug", "mAIL_stats invoking mp0st-stats", { message_id: input.message_id });
|
|
203
|
+
return await invokeFunction<{ summary: MailEngagement }>("mp0st-stats", {
|
|
204
|
+
message_id: input.message_id,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function mAIL_events(
|
|
209
|
+
input: z.infer<typeof mAIL_events_input>,
|
|
210
|
+
ctx: MosaddToolContext,
|
|
211
|
+
): Promise<{
|
|
212
|
+
summary: MailEngagement;
|
|
213
|
+
events: Array<{ event_type: string; at: string; device: string | null; ip_hash: string | null; link_url: string | null }>;
|
|
214
|
+
}> {
|
|
215
|
+
readSupabaseEnv();
|
|
216
|
+
ctx.log("debug", "mAIL_events invoking mp0st-stats", { message_id: input.message_id });
|
|
217
|
+
return await invokeFunction("mp0st-stats", { message_id: input.message_id, events: true });
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function mAIL_metrics(
|
|
221
|
+
_input: z.infer<typeof mAIL_metrics_input>,
|
|
222
|
+
ctx: MosaddToolContext,
|
|
223
|
+
): Promise<{
|
|
224
|
+
mailbox: {
|
|
225
|
+
total_sent: number;
|
|
226
|
+
opened_emails: number;
|
|
227
|
+
open_rate_pct: number;
|
|
228
|
+
total_opens: number;
|
|
229
|
+
total_clicks: number;
|
|
230
|
+
forwarded_emails: number;
|
|
231
|
+
};
|
|
232
|
+
}> {
|
|
233
|
+
readSupabaseEnv();
|
|
234
|
+
ctx.log("debug", "mAIL_metrics invoking mp0st-stats");
|
|
235
|
+
return await invokeFunction("mp0st-stats", {});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function mAIL_revoke(
|
|
239
|
+
input: z.infer<typeof mAIL_revoke_input>,
|
|
240
|
+
ctx: MosaddToolContext,
|
|
241
|
+
): Promise<{ ok: true; message_id: string; revoked: boolean; expires_at: string | null }> {
|
|
242
|
+
readSupabaseEnv();
|
|
243
|
+
ctx.log("debug", "mAIL_revoke invoking mp0st-revoke", { message_id: input.message_id, restore: !!input.restore });
|
|
244
|
+
return await invokeFunction("mp0st-revoke", {
|
|
245
|
+
message_id: input.message_id,
|
|
246
|
+
restore: input.restore ?? false,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async function mAIL_audit_export(
|
|
251
|
+
input: z.infer<typeof mAIL_audit_export_input>,
|
|
252
|
+
ctx: MosaddToolContext,
|
|
253
|
+
): Promise<{ audit: Record<string, unknown>; signature: string; algo: string; note: string }> {
|
|
254
|
+
readSupabaseEnv();
|
|
255
|
+
ctx.log("debug", "mAIL_audit_export invoking mp0st-audit", { message_id: input.message_id });
|
|
256
|
+
return await invokeFunction("mp0st-audit", { message_id: input.message_id });
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async function mAIL_consent(
|
|
260
|
+
input: z.infer<typeof mAIL_consent_input>,
|
|
261
|
+
ctx: MosaddToolContext,
|
|
262
|
+
): Promise<Record<string, unknown>> {
|
|
263
|
+
readSupabaseEnv();
|
|
264
|
+
ctx.log("debug", "mAIL_consent invoking mp0st-consent", { action: input.action });
|
|
265
|
+
return await invokeFunction("mp0st-consent", { action: input.action, recipient: input.recipient ?? null });
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async function mAIL_notify(
|
|
269
|
+
input: z.infer<typeof mAIL_notify_input>,
|
|
270
|
+
ctx: MosaddToolContext,
|
|
271
|
+
): Promise<{
|
|
272
|
+
events: Array<{ message_id: string; subject: string | null; to: string | null; event_type: string; device: string | null; link_url: string | null; at: string }>;
|
|
273
|
+
cursor: string | null;
|
|
274
|
+
count: number;
|
|
275
|
+
}> {
|
|
276
|
+
readSupabaseEnv();
|
|
277
|
+
ctx.log("debug", "mAIL_notify invoking mp0st-notify", { since: input.since });
|
|
278
|
+
return await invokeFunction("mp0st-notify", { action: "feed", since: input.since ?? null, limit: input.limit ?? 50 });
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ---- Registration ----
|
|
282
|
+
|
|
283
|
+
export const mailTools: MosaddTool[] = [
|
|
284
|
+
{
|
|
285
|
+
name: "mAIL_list",
|
|
286
|
+
requires: "network",
|
|
287
|
+
description:
|
|
288
|
+
"List the user's mailbox (their <userId>@mosadd.com inbox/outbox) newest-first, with sender, subject, status and a short snippet. Filter by direction ('inbound' = received, 'outbound' = sent). Use the returned next_cursor with `before` to page through older mail. Call mAIL_view to read a full message body.",
|
|
289
|
+
inputSchema: mAIL_list_input,
|
|
290
|
+
handler: mAIL_list as MosaddTool["handler"],
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
name: "mAIL_send",
|
|
294
|
+
requires: "network",
|
|
295
|
+
description:
|
|
296
|
+
"Send an email from the user's mosadd address (<userId>@mosadd.com). Pass body_text or body_html (or both). Supports cc, bcc, reply_to. Monitoring/legal options: tracking (open+click, default on; set false for no tracking), force_reader (stub email → recipient opens in mosadd's secure reader, unlocking print/copy/time-on-read tracking + revoke), watermark (recipient watermark visible in screenshots/prints), disclose_tracking (GDPR footer), auto_destruct ('1h'|'24h'|'7d').",
|
|
297
|
+
inputSchema: mAIL_send_input,
|
|
298
|
+
handler: mAIL_send as MosaddTool["handler"],
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
name: "mAIL_view",
|
|
302
|
+
requires: "network",
|
|
303
|
+
description: "Read the full body and metadata of an email by message_id.",
|
|
304
|
+
inputSchema: mAIL_view_input,
|
|
305
|
+
handler: mAIL_view as MosaddTool["handler"],
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
name: "mAIL_delete",
|
|
309
|
+
requires: "network",
|
|
310
|
+
description:
|
|
311
|
+
"Delete one of the user's emails by message_id (from mAIL_list). Soft-delete — it stops showing in mAIL_list. Owner-scoped: only your own mail.",
|
|
312
|
+
inputSchema: mAIL_delete_input,
|
|
313
|
+
handler: mAIL_delete as MosaddTool["handler"],
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
name: "mAIL_stats",
|
|
317
|
+
requires: "network",
|
|
318
|
+
description:
|
|
319
|
+
"Engagement summary for one sent email (by message_id): open_count, unique_opens, click_count, whether it was likely forwarded, first/last opened time, and a breakdown of tracked event types. Opens/clicks are real (tracking pixel + link-wrap); forward detection is best-effort (IP-subnet diversity). Owner-scoped.",
|
|
320
|
+
inputSchema: mAIL_stats_input,
|
|
321
|
+
handler: mAIL_stats as MosaddTool["handler"],
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
name: "mAIL_events",
|
|
325
|
+
requires: "network",
|
|
326
|
+
description:
|
|
327
|
+
"Raw engagement timeline for one email (by message_id): every tracked event (pixel_open, link_click, forwarded, page_view, copy/print/focus signals) with timestamp, device type and link URL. Use mAIL_stats for the rollup; use this for the per-event detail. Owner-scoped.",
|
|
328
|
+
inputSchema: mAIL_events_input,
|
|
329
|
+
handler: mAIL_events as MosaddTool["handler"],
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
name: "mAIL_metrics",
|
|
333
|
+
requires: "network",
|
|
334
|
+
description:
|
|
335
|
+
"Mailbox-wide engagement aggregate across the user's sent mail: total_sent, opened_emails, open_rate_pct, total_opens, total_clicks, forwarded_emails. Owner-scoped.",
|
|
336
|
+
inputSchema: mAIL_metrics_input,
|
|
337
|
+
handler: mAIL_metrics as MosaddTool["handler"],
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
name: "mAIL_revoke",
|
|
341
|
+
requires: "network",
|
|
342
|
+
description:
|
|
343
|
+
"Revoke (recall) a sent email's secure-reader access by message_id — the recipient can no longer open the full message via the mosadd reader link (Virtru-style recall, immediate). Pass restore:true to re-enable. HONEST LIMIT: cannot un-send or claw back content the recipient already read, copied, or screenshotted — only disables future reader access. Owner-scoped.",
|
|
344
|
+
inputSchema: mAIL_revoke_input,
|
|
345
|
+
handler: mAIL_revoke as MosaddTool["handler"],
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
name: "mAIL_audit_export",
|
|
349
|
+
requires: "network",
|
|
350
|
+
description:
|
|
351
|
+
"Export a tamper-evident engagement audit report for one sent email (RMail-style): full event trail (opens, clicks, reader print/copy/forward signals) + totals, plus an HMAC-SHA256 signature over the canonical JSON so the report can be proven unaltered. For legal/compliance use. HONEST LIMIT: proves what mosadd observed; it is not a qualified delivery receipt (ERDS). Owner-scoped.",
|
|
352
|
+
inputSchema: mAIL_audit_export_input,
|
|
353
|
+
handler: mAIL_audit_export as MosaddTool["handler"],
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
name: "mAIL_consent",
|
|
357
|
+
requires: "network",
|
|
358
|
+
description:
|
|
359
|
+
"Manage recipient tracking opt-outs (GDPR/ePrivacy). action 'list' = recipients who opted out of your tracking; 'check' {recipient} = whether one opted out; 'optin' {recipient} = re-enable. Recipients self-opt-out via the footer link in your tracked emails; mAIL_send then automatically sends them with NO pixel/link-wrap. Owner-scoped.",
|
|
360
|
+
inputSchema: mAIL_consent_input,
|
|
361
|
+
handler: mAIL_consent as MosaddTool["handler"],
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
name: "mAIL_notify",
|
|
365
|
+
requires: "network",
|
|
366
|
+
description:
|
|
367
|
+
"Recent engagement feed across ALL your sent mail — the 'who just opened/clicked my mail' notifications stream (opens, clicks, forwards, reader print/copy signals), newest first, each with the email subject + recipient. Poll: pass the returned `cursor` back as `since` to get only new activity. Owner-scoped.",
|
|
368
|
+
inputSchema: mAIL_notify_input,
|
|
369
|
+
handler: mAIL_notify as MosaddTool["handler"],
|
|
370
|
+
},
|
|
371
|
+
];
|