@mosadd/mcp 3.0.0-alpha.3 → 3.0.0-alpha.4
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 +116 -116
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-HD5RLE5K.js → chunk-YDFU6S5E.js} +326 -48
- package/dist/index.d.ts +22 -1
- package/dist/index.js +1 -1
- package/package.json +6 -6
- 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 -138
- package/src/bin/mcp.ts +97 -97
- package/src/config.ts +66 -66
- package/src/crypto/mdm-session.ts +403 -378
- package/src/index.ts +17 -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 +96 -96
- package/src/server.ts +105 -103
- package/src/tools/capabilities.ts +68 -68
- package/src/tools/index.ts +43 -37
- package/src/tools/knowledge.ts +91 -0
- package/src/tools/mail.ts +89 -89
- package/src/tools/mdm.ts +392 -379
- package/src/tools/mirc-members.ts +177 -177
- package/src/tools/mirc-messages.ts +151 -0
- package/src/tools/mirc.ts +170 -170
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +189 -189
- package/src/tools/mtalk.ts +121 -0
- package/src/types.ts +85 -79
- package/src/voice/floor.ts +132 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mKB — 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
|
+
* `mKB_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 m0ssad-3 `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 mKB_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 mKB_search(
|
|
57
|
+
input: z.infer<typeof mKB_search_input>,
|
|
58
|
+
ctx: MosaddToolContext,
|
|
59
|
+
): Promise<{ answer: string; sources: RagSource[]; chunks_found: number }> {
|
|
60
|
+
readSupabaseEnv();
|
|
61
|
+
ctx.log("debug", "mKB_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
|
+
export const knowledgeTools: MosaddTool[] = [
|
|
83
|
+
{
|
|
84
|
+
name: "mKB_search",
|
|
85
|
+
requires: "network",
|
|
86
|
+
description:
|
|
87
|
+
"Search and answer questions over the USER'S OWN mosadd data (messages, emails, calls, notes) with a private 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 (mKB = knowledge base) over the user's communications, available outside the mosadd app.",
|
|
88
|
+
inputSchema: mKB_search_input,
|
|
89
|
+
handler: mKB_search as MosaddTool["handler"],
|
|
90
|
+
},
|
|
91
|
+
];
|
package/src/tools/mail.ts
CHANGED
|
@@ -1,89 +1,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 m0ssad-3 mp0st pipeline.
|
|
6
|
-
*
|
|
7
|
-
* Phase 1 alpha: wired to m0ssad-3 `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
|
-
});
|
|
35
|
-
|
|
36
|
-
const mAIL_view_input = z.object({
|
|
37
|
-
message_id: MessageId,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// ---- Handlers ----
|
|
41
|
-
|
|
42
|
-
async function mAIL_send(
|
|
43
|
-
input: z.infer<typeof mAIL_send_input>,
|
|
44
|
-
ctx: MosaddToolContext,
|
|
45
|
-
): Promise<{ message_id: string; queued_at: string }> {
|
|
46
|
-
readSupabaseEnv();
|
|
47
|
-
if (!input.body_text && !input.body_html) {
|
|
48
|
-
throw new Error("mAIL_send requires at least one of body_text or body_html.");
|
|
49
|
-
}
|
|
50
|
-
ctx.log("debug", "mAIL_send invoking mp0st-send", { to: input.to });
|
|
51
|
-
return await invokeFunction<{ message_id: string; queued_at: string }>("mp0st-send", input);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function mAIL_view(
|
|
55
|
-
input: z.infer<typeof mAIL_view_input>,
|
|
56
|
-
ctx: MosaddToolContext,
|
|
57
|
-
): Promise<{
|
|
58
|
-
message_id: string;
|
|
59
|
-
from: string;
|
|
60
|
-
to: string[];
|
|
61
|
-
subject: string;
|
|
62
|
-
body_text: string | null;
|
|
63
|
-
body_html: string | null;
|
|
64
|
-
received_at: string;
|
|
65
|
-
}> {
|
|
66
|
-
readSupabaseEnv();
|
|
67
|
-
ctx.log("debug", "mAIL_view invoking mp0st-view", { message_id: input.message_id });
|
|
68
|
-
return await invokeFunction("mp0st-view", { message_id: input.message_id });
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// ---- Registration ----
|
|
72
|
-
|
|
73
|
-
export const mailTools: MosaddTool[] = [
|
|
74
|
-
{
|
|
75
|
-
name: "mAIL_send",
|
|
76
|
-
requires: "network",
|
|
77
|
-
description:
|
|
78
|
-
"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.",
|
|
79
|
-
inputSchema: mAIL_send_input,
|
|
80
|
-
handler: mAIL_send as MosaddTool["handler"],
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
name: "mAIL_view",
|
|
84
|
-
requires: "network",
|
|
85
|
-
description: "Read the full body and metadata of an email by message_id.",
|
|
86
|
-
inputSchema: mAIL_view_input,
|
|
87
|
-
handler: mAIL_view as MosaddTool["handler"],
|
|
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 m0ssad-3 mp0st pipeline.
|
|
6
|
+
*
|
|
7
|
+
* Phase 1 alpha: wired to m0ssad-3 `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
|
+
});
|
|
35
|
+
|
|
36
|
+
const mAIL_view_input = z.object({
|
|
37
|
+
message_id: MessageId,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// ---- Handlers ----
|
|
41
|
+
|
|
42
|
+
async function mAIL_send(
|
|
43
|
+
input: z.infer<typeof mAIL_send_input>,
|
|
44
|
+
ctx: MosaddToolContext,
|
|
45
|
+
): Promise<{ message_id: string; queued_at: string }> {
|
|
46
|
+
readSupabaseEnv();
|
|
47
|
+
if (!input.body_text && !input.body_html) {
|
|
48
|
+
throw new Error("mAIL_send requires at least one of body_text or body_html.");
|
|
49
|
+
}
|
|
50
|
+
ctx.log("debug", "mAIL_send invoking mp0st-send", { to: input.to });
|
|
51
|
+
return await invokeFunction<{ message_id: string; queued_at: string }>("mp0st-send", input);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function mAIL_view(
|
|
55
|
+
input: z.infer<typeof mAIL_view_input>,
|
|
56
|
+
ctx: MosaddToolContext,
|
|
57
|
+
): Promise<{
|
|
58
|
+
message_id: string;
|
|
59
|
+
from: string;
|
|
60
|
+
to: string[];
|
|
61
|
+
subject: string;
|
|
62
|
+
body_text: string | null;
|
|
63
|
+
body_html: string | null;
|
|
64
|
+
received_at: string;
|
|
65
|
+
}> {
|
|
66
|
+
readSupabaseEnv();
|
|
67
|
+
ctx.log("debug", "mAIL_view invoking mp0st-view", { message_id: input.message_id });
|
|
68
|
+
return await invokeFunction("mp0st-view", { message_id: input.message_id });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ---- Registration ----
|
|
72
|
+
|
|
73
|
+
export const mailTools: MosaddTool[] = [
|
|
74
|
+
{
|
|
75
|
+
name: "mAIL_send",
|
|
76
|
+
requires: "network",
|
|
77
|
+
description:
|
|
78
|
+
"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.",
|
|
79
|
+
inputSchema: mAIL_send_input,
|
|
80
|
+
handler: mAIL_send as MosaddTool["handler"],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: "mAIL_view",
|
|
84
|
+
requires: "network",
|
|
85
|
+
description: "Read the full body and metadata of an email by message_id.",
|
|
86
|
+
inputSchema: mAIL_view_input,
|
|
87
|
+
handler: mAIL_view as MosaddTool["handler"],
|
|
88
|
+
},
|
|
89
|
+
];
|