@mosadd/mcp 3.0.0-alpha.52 → 3.0.0-alpha.53

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +334 -309
  2. package/README.md +150 -150
  3. package/dist/bin/mcp.js +1 -1
  4. package/dist/{chunk-KVN7LZFW.js → chunk-AWKITPZQ.js} +384 -103
  5. package/dist/index.d.ts +11 -1
  6. package/dist/index.js +1 -1
  7. package/package.json +9 -9
  8. package/src/__tests__/golden-path.test.ts +139 -139
  9. package/src/__tests__/integration.test.ts +182 -182
  10. package/src/__tests__/knowledge-ingest.test.ts +114 -114
  11. package/src/__tests__/mdm-e2ee.test.ts +212 -212
  12. package/src/__tests__/mdm-mcp-readable.test.ts +284 -0
  13. package/src/__tests__/mirc-invite.test.ts +112 -112
  14. package/src/__tests__/mtalk.test.ts +122 -122
  15. package/src/__tests__/server.test.ts +71 -71
  16. package/src/__tests__/serverJsonVersion.test.ts +45 -45
  17. package/src/__tests__/tool-count-consistency.test.ts +199 -199
  18. package/src/bin/login.ts +138 -138
  19. package/src/bin/mcp.ts +145 -145
  20. package/src/config.ts +66 -66
  21. package/src/crypto/mdm-session.ts +798 -502
  22. package/src/index.ts +19 -19
  23. package/src/observability/sentry.ts +79 -79
  24. package/src/providers/memory-voice.ts +79 -79
  25. package/src/providers/supabase-dm.ts +174 -122
  26. package/src/providers/supabase-voice.ts +91 -91
  27. package/src/providers/supabase.ts +231 -231
  28. package/src/server.ts +186 -162
  29. package/src/tools/__tests__/ragDeleteFoldsSourceId.test.ts +67 -67
  30. package/src/tools/actions.ts +166 -166
  31. package/src/tools/attachments.ts +276 -276
  32. package/src/tools/capabilities.ts +70 -70
  33. package/src/tools/embed.ts +110 -110
  34. package/src/tools/index.ts +181 -181
  35. package/src/tools/knowledge-graph.ts +186 -186
  36. package/src/tools/knowledge.ts +344 -344
  37. package/src/tools/mail-agentbox.ts +155 -155
  38. package/src/tools/mail-aliases.ts +25 -25
  39. package/src/tools/mail-provenance.ts +137 -137
  40. package/src/tools/mail.ts +403 -403
  41. package/src/tools/mcall.ts +216 -216
  42. package/src/tools/mdm-as-agent.ts +126 -126
  43. package/src/tools/mdm-voice.ts +220 -220
  44. package/src/tools/mdm.ts +119 -17
  45. package/src/tools/mirc-edge.ts +196 -196
  46. package/src/tools/mirc-members.ts +287 -287
  47. package/src/tools/mirc.ts +308 -308
  48. package/src/tools/mroom-messages.ts +142 -142
  49. package/src/tools/mroom.ts +221 -221
  50. package/src/tools/mtalk.ts +131 -131
  51. package/src/tools/murl.ts +314 -314
  52. package/src/tools/presence.ts +442 -442
  53. package/src/tools/ptt-ingest.ts +99 -99
  54. package/src/tools/threat.ts +123 -123
  55. package/src/types.ts +121 -121
  56. package/src/version.ts +8 -8
  57. package/src/voice/floor.ts +132 -132
  58. package/LICENSE +0 -201
@@ -1,166 +1,166 @@
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
- title: "Create one-click action link",
149
- annotations: { readOnlyHint: false },
150
- requires: "network",
151
- description:
152
- "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).",
153
- inputSchema: action_create_input,
154
- handler: action_create as MosaddTool["handler"],
155
- },
156
- {
157
- name: "comms_action_frame_get",
158
- title: "View shared screen frame",
159
- annotations: { readOnlyHint: true },
160
- requires: "network",
161
- description:
162
- "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.",
163
- inputSchema: action_frame_get_input,
164
- handler: action_frame_get as MosaddTool["handler"],
165
- },
166
- ];
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
+ title: "Create one-click action link",
149
+ annotations: { readOnlyHint: false },
150
+ requires: "network",
151
+ description:
152
+ "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).",
153
+ inputSchema: action_create_input,
154
+ handler: action_create as MosaddTool["handler"],
155
+ },
156
+ {
157
+ name: "comms_action_frame_get",
158
+ title: "View shared screen frame",
159
+ annotations: { readOnlyHint: true },
160
+ requires: "network",
161
+ description:
162
+ "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.",
163
+ inputSchema: action_frame_get_input,
164
+ handler: action_frame_get as MosaddTool["handler"],
165
+ },
166
+ ];