@mosadd/mcp 3.0.0-alpha.4 → 3.0.0-alpha.40
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 +298 -0
- package/README.md +70 -36
- package/dist/bin/mcp.js +42 -3
- package/dist/chunk-7ZAAJ52G.js +3475 -0
- package/dist/index.d.ts +115 -6
- package/dist/index.js +7 -3
- package/package.json +8 -5
- package/src/__tests__/golden-path.test.ts +139 -137
- package/src/__tests__/integration.test.ts +179 -178
- package/src/__tests__/knowledge-ingest.test.ts +114 -0
- package/src/__tests__/mdm-e2ee.test.ts +212 -178
- package/src/__tests__/mtalk.test.ts +122 -122
- package/src/__tests__/presence.test.ts +178 -0
- package/src/__tests__/server.test.ts +71 -67
- package/src/__tests__/tool-count-consistency.test.ts +164 -0
- 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 -403
- 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 -79
- package/src/providers/supabase-dm.ts +122 -117
- package/src/providers/supabase-voice.ts +91 -91
- package/src/providers/supabase.ts +155 -96
- package/src/server.ts +60 -9
- package/src/tools/actions.ts +166 -0
- package/src/tools/attachments.ts +276 -0
- package/src/tools/capabilities.ts +70 -68
- package/src/tools/embed.ts +110 -0
- package/src/tools/index.ts +177 -43
- package/src/tools/knowledge-graph.ts +186 -0
- package/src/tools/knowledge.ts +327 -91
- package/src/tools/mail-agentbox.ts +155 -0
- package/src/tools/mail-aliases.ts +25 -0
- package/src/tools/mail-provenance.ts +137 -0
- package/src/tools/mail.ts +403 -89
- package/src/tools/mcall.ts +216 -0
- package/src/tools/mdm-as-agent.ts +126 -0
- package/src/tools/mdm-voice.ts +220 -0
- package/src/tools/mdm.ts +494 -392
- package/src/tools/mirc-edge.ts +196 -0
- package/src/tools/mirc-members.ts +61 -20
- package/src/tools/mirc-messages.ts +185 -151
- package/src/tools/mirc.ts +104 -10
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +221 -189
- package/src/tools/mtalk.ts +131 -121
- package/src/tools/murl.ts +314 -0
- package/src/tools/presence.ts +333 -0
- package/src/tools/ptt-ingest.ts +99 -0
- package/src/tools/threat.ts +123 -0
- package/src/types.ts +121 -85
- package/src/version.ts +8 -0
- package/src/voice/floor.ts +132 -132
- package/dist/chunk-YDFU6S5E.js +0 -1471
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mp0st provenance — agent-attributed email send.
|
|
3
|
+
*
|
|
4
|
+
* The plain `mp0st_send` (mail.ts) sends as the USER. When an AGENT sends mail on
|
|
5
|
+
* the user's behalf, the recipient (and the audit trail) should be able to tell
|
|
6
|
+
* it was agent-originated. Per the Lane A contract, `mp0st-send`, when called
|
|
7
|
+
* with a HUB-CLAIM JWT, stamps the row with:
|
|
8
|
+
* sent_by = 'agent', sent_by_agent_id, sent_by_task_id
|
|
9
|
+
*
|
|
10
|
+
* This tool mints/forwards that hub-claim JWT and sets the provenance fields.
|
|
11
|
+
*
|
|
12
|
+
* AUTH MODEL (differs from the rest of mp0st):
|
|
13
|
+
* - mp0st_send uses the user's Supabase session JWT (via invokeFunction).
|
|
14
|
+
* - mp0st_send_as_agent presents a HUB-CLAIM JWT (hub key → claim exchange) so
|
|
15
|
+
* mp0st-send can attribute the send to the agent/task.
|
|
16
|
+
*
|
|
17
|
+
* STATUS: scaffold. The hub-claim exchange endpoint is assumed (TODO Lane A —
|
|
18
|
+
* confirm the exact route + claim shape). Falls back to the user session JWT if
|
|
19
|
+
* no hub key is configured, with provenance fields passed through for the EF to
|
|
20
|
+
* honor once deployed.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { z } from "zod";
|
|
24
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
25
|
+
|
|
26
|
+
const DEFAULT_SUPABASE_URL = "https://rooffhgbxafyjcwmwpsy.supabase.co";
|
|
27
|
+
|
|
28
|
+
function supabaseUrl(): string {
|
|
29
|
+
return (
|
|
30
|
+
process.env.MOSADD_SUPABASE_URL?.replace(/\/$/, "") ??
|
|
31
|
+
process.env.SUPABASE_URL?.replace(/\/$/, "") ??
|
|
32
|
+
DEFAULT_SUPABASE_URL
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function hubKey(): string | null {
|
|
37
|
+
return process.env.MOSADD_API_KEY ?? process.env.MOSADD_HUB_KEY ?? null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const EmailAddress = z.string().email().max(254);
|
|
41
|
+
|
|
42
|
+
const mp0st_send_as_agent_input = z.object({
|
|
43
|
+
to: z.union([EmailAddress, z.array(EmailAddress).min(1).max(50)]),
|
|
44
|
+
subject: z.string().min(1).max(998),
|
|
45
|
+
body_text: z.string().max(1_048_576).optional(),
|
|
46
|
+
body_html: z.string().max(1_048_576).optional(),
|
|
47
|
+
cc: z.array(EmailAddress).max(50).optional(),
|
|
48
|
+
bcc: z.array(EmailAddress).max(50).optional(),
|
|
49
|
+
reply_to: EmailAddress.optional(),
|
|
50
|
+
tracking: z.boolean().optional(),
|
|
51
|
+
agent_id: z
|
|
52
|
+
.string()
|
|
53
|
+
.min(1)
|
|
54
|
+
.max(120)
|
|
55
|
+
.describe("Stable id of the agent doing the send. Stamped as sent_by_agent_id for provenance."),
|
|
56
|
+
task_id: z
|
|
57
|
+
.string()
|
|
58
|
+
.min(1)
|
|
59
|
+
.max(120)
|
|
60
|
+
.optional()
|
|
61
|
+
.describe("Optional id of the task/run this send belongs to. Stamped as sent_by_task_id."),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Exchange the hub key for an HS256 hub-claim JWT that authorizes agent-attributed
|
|
66
|
+
* mail sends. The `mp0st-send` EF verifies this token with HUB_JWT_SECRET and reads
|
|
67
|
+
* `agent_id` + `task_id` from its claims authoritatively (body fields are NOT trusted
|
|
68
|
+
* for provenance). LINEAR-3991.
|
|
69
|
+
*/
|
|
70
|
+
async function mintHubClaim(agentId: string, taskId?: string): Promise<string> {
|
|
71
|
+
const key = hubKey();
|
|
72
|
+
if (!key) {
|
|
73
|
+
throw new Error("mAYL_send_as_agent needs MOSADD_API_KEY (hub key) to mint a provenance claim.");
|
|
74
|
+
}
|
|
75
|
+
const r = await fetch(`${supabaseUrl()}/functions/v1/hub-claim-mint`, {
|
|
76
|
+
method: "POST",
|
|
77
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
|
|
78
|
+
body: JSON.stringify({ agent_id: agentId, task_id: taskId ?? null }),
|
|
79
|
+
});
|
|
80
|
+
if (!r.ok) {
|
|
81
|
+
const b = await r.text().catch(() => "");
|
|
82
|
+
throw new Error(`hub-claim-mint ${r.status}: ${b.slice(0, 200)}`);
|
|
83
|
+
}
|
|
84
|
+
const data = (await r.json()) as { access_token?: string };
|
|
85
|
+
if (!data?.access_token) throw new Error("hub-claim-mint: no access_token in response");
|
|
86
|
+
return data.access_token;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function mAYL_send_as_agent(
|
|
90
|
+
input: z.infer<typeof mp0st_send_as_agent_input>,
|
|
91
|
+
ctx: MosaddToolContext,
|
|
92
|
+
): Promise<{ message_id: string; status: string; is_internal: boolean; sent_by: "agent" }> {
|
|
93
|
+
if (!input.body_text && !input.body_html) {
|
|
94
|
+
throw new Error("mAYL_send_as_agent requires at least one of body_text or body_html.");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Mint the hub-claim JWT and present it directly to mp0st-send (NOT the user
|
|
98
|
+
// session client) so the EF attributes the row to the agent. mp0st-send verifies
|
|
99
|
+
// the HS256 signature with HUB_JWT_SECRET and stamps sent_by_agent_id /
|
|
100
|
+
// sent_by_task_id from the verified claims — body fields are NOT trusted for
|
|
101
|
+
// provenance.
|
|
102
|
+
const claim = await mintHubClaim(input.agent_id, input.task_id);
|
|
103
|
+
ctx.log("debug", "mAYL_send_as_agent invoking mp0st-send with hub-claim", { agent_id: input.agent_id });
|
|
104
|
+
|
|
105
|
+
const { agent_id: _ai, task_id: _ti, ...mailFields } = input;
|
|
106
|
+
const r = await fetch(`${supabaseUrl()}/functions/v1/mp0st-send`, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${claim}` },
|
|
109
|
+
body: JSON.stringify(mailFields),
|
|
110
|
+
});
|
|
111
|
+
if (!r.ok) {
|
|
112
|
+
const b = await r.text().catch(() => "");
|
|
113
|
+
throw new Error(`mp0st-send ${r.status}: ${b.slice(0, 200)}`);
|
|
114
|
+
}
|
|
115
|
+
const res = (await r.json()) as { email_id?: string; status?: string; is_internal?: boolean; error?: string };
|
|
116
|
+
if (res.error) throw new Error(res.error);
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
message_id: res.email_id ?? "",
|
|
120
|
+
status: res.status ?? "sent",
|
|
121
|
+
is_internal: res.is_internal ?? false,
|
|
122
|
+
sent_by: "agent",
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const mailProvenanceTools: MosaddTool[] = [
|
|
127
|
+
{
|
|
128
|
+
name: "mAYL_send_as_agent",
|
|
129
|
+
title: "Send email as your agent",
|
|
130
|
+
annotations: { readOnlyHint: false },
|
|
131
|
+
requires: "network",
|
|
132
|
+
description:
|
|
133
|
+
"Send an email ATTRIBUTED TO THE AGENT (provenance-stamped). Unlike mAYL_send (sends as the user), this stamps sent_by='agent' plus your agent_id and optional task_id onto the email record and audit trail — so recipients and compliance can see the mail was agent-originated. Auth: presents a hub-claim JWT (needs MOSADD_API_KEY). The mp0st-send EF verifies the claim with HUB_JWT_SECRET; body trust is never granted for provenance.",
|
|
134
|
+
inputSchema: mp0st_send_as_agent_input,
|
|
135
|
+
handler: mAYL_send_as_agent as MosaddTool["handler"],
|
|
136
|
+
},
|
|
137
|
+
];
|
package/src/tools/mail.ts
CHANGED
|
@@ -1,89 +1,403 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
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
|
|
23
|
-
|
|
24
|
-
const
|
|
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
|
+
* mp0st — 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 mAYL_send or inbox.");
|
|
23
|
+
|
|
24
|
+
const mp0st_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 mp0st_view_input = z.object({
|
|
57
|
+
message_id: MessageId,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const mp0st_delete_input = z.object({
|
|
61
|
+
message_id: MessageId,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const mp0st_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 mp0st_stats_input = z.object({
|
|
77
|
+
message_id: MessageId,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const mp0st_events_input = z.object({
|
|
81
|
+
message_id: MessageId,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const mp0st_metrics_input = z.object({});
|
|
85
|
+
|
|
86
|
+
const mp0st_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 mp0st_audit_export_input = z.object({
|
|
95
|
+
message_id: MessageId,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const mp0st_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 mp0st_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 mp0st_send(
|
|
128
|
+
input: z.infer<typeof mp0st_send_input>,
|
|
129
|
+
ctx: MosaddToolContext,
|
|
130
|
+
): Promise<{ message_id: string; status: string; is_internal: boolean }> {
|
|
131
|
+
readSupabaseEnv();
|
|
132
|
+
if (!input.body_text && !input.body_html) {
|
|
133
|
+
throw new Error("mp0st_send requires at least one of body_text or body_html.");
|
|
134
|
+
}
|
|
135
|
+
ctx.log("debug", "mp0st_send invoking mp0st-send", { to: input.to });
|
|
136
|
+
// mp0st-send returns { ok, email_id, status, is_internal } — remap email_id to the
|
|
137
|
+
// tool's message_id contract (email_id IS the message id). Surface backend errors.
|
|
138
|
+
const res = await invokeFunction<{ ok?: boolean; email_id?: string; status?: string; is_internal?: boolean; error?: string }>("mp0st-send", input);
|
|
139
|
+
if (res.error) throw new Error(res.error);
|
|
140
|
+
return { message_id: res.email_id ?? "", status: res.status ?? "sent", is_internal: res.is_internal ?? false };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function mp0st_view(
|
|
144
|
+
input: z.infer<typeof mp0st_view_input>,
|
|
145
|
+
ctx: MosaddToolContext,
|
|
146
|
+
): Promise<{
|
|
147
|
+
message_id: string;
|
|
148
|
+
from: string;
|
|
149
|
+
to: string[];
|
|
150
|
+
subject: string;
|
|
151
|
+
body_text: string | null;
|
|
152
|
+
body_html: string | null;
|
|
153
|
+
sent_at: string;
|
|
154
|
+
}> {
|
|
155
|
+
readSupabaseEnv();
|
|
156
|
+
// mp0st-get (NOT mp0st-view): mp0st-view is the open-tracking pixel endpoint
|
|
157
|
+
// keyed on ?t=<trackingId> and always 400s "Missing tracking ID" on a JSON POST.
|
|
158
|
+
// mp0st-get reads the owner-scoped email by id and returns the full body.
|
|
159
|
+
ctx.log("debug", "mp0st_view invoking mp0st-get", { message_id: input.message_id });
|
|
160
|
+
return await invokeFunction("mp0st-get", { message_id: input.message_id });
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function mp0st_list(
|
|
164
|
+
input: z.infer<typeof mp0st_list_input>,
|
|
165
|
+
ctx: MosaddToolContext,
|
|
166
|
+
): Promise<{ emails: MailListItem[]; next_cursor: string | null }> {
|
|
167
|
+
readSupabaseEnv();
|
|
168
|
+
ctx.log("debug", "mp0st_list invoking mp0st-list", { direction: input.direction });
|
|
169
|
+
return await invokeFunction<{ emails: MailListItem[]; next_cursor: string | null }>("mp0st-list", {
|
|
170
|
+
direction: input.direction ?? null,
|
|
171
|
+
limit: input.limit ?? 50,
|
|
172
|
+
before: input.before ?? null,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function mp0st_delete(
|
|
177
|
+
input: z.infer<typeof mp0st_delete_input>,
|
|
178
|
+
ctx: MosaddToolContext,
|
|
179
|
+
): Promise<{ ok: true; message_id: string; deleted: true }> {
|
|
180
|
+
readSupabaseEnv();
|
|
181
|
+
ctx.log("debug", "mp0st_delete invoking mp0st-delete", { message_id: input.message_id });
|
|
182
|
+
return await invokeFunction<{ ok: true; message_id: string; deleted: true }>("mp0st-delete", {
|
|
183
|
+
message_id: input.message_id,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
interface MailEngagement {
|
|
188
|
+
message_id: string;
|
|
189
|
+
subject: string;
|
|
190
|
+
to: string;
|
|
191
|
+
direction: string;
|
|
192
|
+
status: string;
|
|
193
|
+
sent_at: string;
|
|
194
|
+
open_count: number;
|
|
195
|
+
unique_opens: number;
|
|
196
|
+
click_count: number;
|
|
197
|
+
forwarded: boolean;
|
|
198
|
+
first_opened_at: string | null;
|
|
199
|
+
last_opened_at: string | null;
|
|
200
|
+
events_by_type: Record<string, number>;
|
|
201
|
+
total_events: number;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async function mp0st_stats(
|
|
205
|
+
input: z.infer<typeof mp0st_stats_input>,
|
|
206
|
+
ctx: MosaddToolContext,
|
|
207
|
+
): Promise<{ summary: MailEngagement }> {
|
|
208
|
+
readSupabaseEnv();
|
|
209
|
+
ctx.log("debug", "mp0st_stats invoking mp0st-stats", { message_id: input.message_id });
|
|
210
|
+
return await invokeFunction<{ summary: MailEngagement }>("mp0st-stats", {
|
|
211
|
+
message_id: input.message_id,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function mp0st_events(
|
|
216
|
+
input: z.infer<typeof mp0st_events_input>,
|
|
217
|
+
ctx: MosaddToolContext,
|
|
218
|
+
): Promise<{
|
|
219
|
+
summary: MailEngagement;
|
|
220
|
+
events: Array<{ event_type: string; at: string; device: string | null; ip_hash: string | null; link_url: string | null }>;
|
|
221
|
+
}> {
|
|
222
|
+
readSupabaseEnv();
|
|
223
|
+
ctx.log("debug", "mp0st_events invoking mp0st-stats", { message_id: input.message_id });
|
|
224
|
+
return await invokeFunction("mp0st-stats", { message_id: input.message_id, events: true });
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function mp0st_metrics(
|
|
228
|
+
_input: z.infer<typeof mp0st_metrics_input>,
|
|
229
|
+
ctx: MosaddToolContext,
|
|
230
|
+
): Promise<{
|
|
231
|
+
mailbox: {
|
|
232
|
+
total_sent: number;
|
|
233
|
+
opened_emails: number;
|
|
234
|
+
open_rate_pct: number;
|
|
235
|
+
total_opens: number;
|
|
236
|
+
total_clicks: number;
|
|
237
|
+
forwarded_emails: number;
|
|
238
|
+
};
|
|
239
|
+
}> {
|
|
240
|
+
readSupabaseEnv();
|
|
241
|
+
ctx.log("debug", "mp0st_metrics invoking mp0st-stats");
|
|
242
|
+
return await invokeFunction("mp0st-stats", {});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function mp0st_revoke(
|
|
246
|
+
input: z.infer<typeof mp0st_revoke_input>,
|
|
247
|
+
ctx: MosaddToolContext,
|
|
248
|
+
): Promise<{ ok: true; message_id: string; revoked: boolean; expires_at: string | null }> {
|
|
249
|
+
readSupabaseEnv();
|
|
250
|
+
ctx.log("debug", "mp0st_revoke invoking mp0st-revoke", { message_id: input.message_id, restore: !!input.restore });
|
|
251
|
+
return await invokeFunction("mp0st-revoke", {
|
|
252
|
+
message_id: input.message_id,
|
|
253
|
+
restore: input.restore ?? false,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function mp0st_audit_export(
|
|
258
|
+
input: z.infer<typeof mp0st_audit_export_input>,
|
|
259
|
+
ctx: MosaddToolContext,
|
|
260
|
+
): Promise<{ audit: Record<string, unknown>; signature: string; algo: string; note: string }> {
|
|
261
|
+
readSupabaseEnv();
|
|
262
|
+
ctx.log("debug", "mp0st_audit_export invoking mp0st-audit", { message_id: input.message_id });
|
|
263
|
+
return await invokeFunction("mp0st-audit", { message_id: input.message_id });
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async function mp0st_consent(
|
|
267
|
+
input: z.infer<typeof mp0st_consent_input>,
|
|
268
|
+
ctx: MosaddToolContext,
|
|
269
|
+
): Promise<Record<string, unknown>> {
|
|
270
|
+
readSupabaseEnv();
|
|
271
|
+
if ((input.action === "check" || input.action === "optin") && !input.recipient) {
|
|
272
|
+
throw new Error(`mp0st_consent action '${input.action}' requires a 'recipient' email address.`);
|
|
273
|
+
}
|
|
274
|
+
ctx.log("debug", "mp0st_consent invoking mp0st-consent", { action: input.action });
|
|
275
|
+
return await invokeFunction("mp0st-consent", { action: input.action, recipient: input.recipient ?? null });
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
async function mp0st_notify(
|
|
279
|
+
input: z.infer<typeof mp0st_notify_input>,
|
|
280
|
+
ctx: MosaddToolContext,
|
|
281
|
+
): Promise<{
|
|
282
|
+
events: Array<{ message_id: string; subject: string | null; to: string | null; event_type: string; device: string | null; link_url: string | null; at: string }>;
|
|
283
|
+
cursor: string | null;
|
|
284
|
+
count: number;
|
|
285
|
+
}> {
|
|
286
|
+
readSupabaseEnv();
|
|
287
|
+
ctx.log("debug", "mp0st_notify invoking mp0st-notify", { since: input.since });
|
|
288
|
+
return await invokeFunction("mp0st-notify", { action: "feed", since: input.since ?? null, limit: input.limit ?? 50 });
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ---- Registration ----
|
|
292
|
+
|
|
293
|
+
export const mailTools: MosaddTool[] = [
|
|
294
|
+
{
|
|
295
|
+
name: "mAYL_list",
|
|
296
|
+
title: "List emails",
|
|
297
|
+
annotations: { readOnlyHint: true },
|
|
298
|
+
requires: "network",
|
|
299
|
+
description:
|
|
300
|
+
"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 mAYL_view to read a full message body.",
|
|
301
|
+
inputSchema: mp0st_list_input,
|
|
302
|
+
handler: mp0st_list as MosaddTool["handler"],
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
name: "mAYL_send",
|
|
306
|
+
title: "Send email",
|
|
307
|
+
annotations: { readOnlyHint: false },
|
|
308
|
+
requires: "network",
|
|
309
|
+
description:
|
|
310
|
+
"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').",
|
|
311
|
+
inputSchema: mp0st_send_input,
|
|
312
|
+
handler: mp0st_send as MosaddTool["handler"],
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
name: "mAYL_view",
|
|
316
|
+
title: "Read an email",
|
|
317
|
+
annotations: { readOnlyHint: true },
|
|
318
|
+
requires: "network",
|
|
319
|
+
description: "Read the full body and metadata of an email by message_id.",
|
|
320
|
+
inputSchema: mp0st_view_input,
|
|
321
|
+
handler: mp0st_view as MosaddTool["handler"],
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
name: "mAYL_delete",
|
|
325
|
+
title: "Delete email",
|
|
326
|
+
annotations: { destructiveHint: true },
|
|
327
|
+
requires: "network",
|
|
328
|
+
description:
|
|
329
|
+
"Delete one of the user's emails by message_id (from mAYL_list). Soft-delete — it stops showing in mAYL_list. Owner-scoped: only your own mail.",
|
|
330
|
+
inputSchema: mp0st_delete_input,
|
|
331
|
+
handler: mp0st_delete as MosaddTool["handler"],
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
name: "mAYL_stats",
|
|
335
|
+
title: "Email delivery stats",
|
|
336
|
+
annotations: { readOnlyHint: true },
|
|
337
|
+
requires: "network",
|
|
338
|
+
description:
|
|
339
|
+
"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.",
|
|
340
|
+
inputSchema: mp0st_stats_input,
|
|
341
|
+
handler: mp0st_stats as MosaddTool["handler"],
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
name: "mAYL_events",
|
|
345
|
+
title: "Email event trail",
|
|
346
|
+
annotations: { readOnlyHint: true },
|
|
347
|
+
requires: "network",
|
|
348
|
+
description:
|
|
349
|
+
"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 mAYL_stats for the rollup; use this for the per-event detail. Owner-scoped.",
|
|
350
|
+
inputSchema: mp0st_events_input,
|
|
351
|
+
handler: mp0st_events as MosaddTool["handler"],
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
name: "mAYL_metrics",
|
|
355
|
+
title: "Email engagement metrics",
|
|
356
|
+
annotations: { readOnlyHint: true },
|
|
357
|
+
requires: "network",
|
|
358
|
+
description:
|
|
359
|
+
"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.",
|
|
360
|
+
inputSchema: mp0st_metrics_input,
|
|
361
|
+
handler: mp0st_metrics as MosaddTool["handler"],
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
name: "mAYL_revoke",
|
|
365
|
+
title: "Revoke a sent email",
|
|
366
|
+
annotations: { destructiveHint: true },
|
|
367
|
+
requires: "network",
|
|
368
|
+
description:
|
|
369
|
+
"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.",
|
|
370
|
+
inputSchema: mp0st_revoke_input,
|
|
371
|
+
handler: mp0st_revoke as MosaddTool["handler"],
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
name: "mAYL_audit_export",
|
|
375
|
+
title: "Export signed audit report",
|
|
376
|
+
annotations: { readOnlyHint: true },
|
|
377
|
+
requires: "network",
|
|
378
|
+
description:
|
|
379
|
+
"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.",
|
|
380
|
+
inputSchema: mp0st_audit_export_input,
|
|
381
|
+
handler: mp0st_audit_export as MosaddTool["handler"],
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
name: "mAYL_consent",
|
|
385
|
+
title: "Manage tracking opt-outs",
|
|
386
|
+
annotations: { readOnlyHint: false },
|
|
387
|
+
requires: "network",
|
|
388
|
+
description:
|
|
389
|
+
"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; mAYL_send then automatically sends them with NO pixel/link-wrap. Owner-scoped.",
|
|
390
|
+
inputSchema: mp0st_consent_input,
|
|
391
|
+
handler: mp0st_consent as MosaddTool["handler"],
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
name: "mAYL_notify",
|
|
395
|
+
title: "Engagement notifications feed",
|
|
396
|
+
annotations: { readOnlyHint: true },
|
|
397
|
+
requires: "network",
|
|
398
|
+
description:
|
|
399
|
+
"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.",
|
|
400
|
+
inputSchema: mp0st_notify_input,
|
|
401
|
+
handler: mp0st_notify as MosaddTool["handler"],
|
|
402
|
+
},
|
|
403
|
+
];
|