@mosadd/mcp 3.0.0-alpha.31 → 3.0.0-alpha.33
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 +74 -0
- package/README.md +11 -11
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-P4ENU5MW.js → chunk-IWLN5EO5.js} +665 -140
- package/dist/index.js +1 -1
- package/package.json +15 -15
- package/src/__tests__/golden-path.test.ts +137 -137
- package/src/__tests__/integration.test.ts +179 -179
- package/src/__tests__/knowledge-ingest.test.ts +114 -0
- package/src/__tests__/mdm-e2ee.test.ts +212 -212
- package/src/__tests__/mtalk.test.ts +122 -122
- package/src/__tests__/presence.test.ts +141 -0
- package/src/__tests__/server.test.ts +71 -71
- package/src/__tests__/tool-count-consistency.test.ts +164 -0
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -145
- package/src/config.ts +66 -66
- package/src/crypto/mdm-session.ts +502 -502
- package/src/index.ts +19 -19
- package/src/observability/sentry.ts +79 -79
- package/src/providers/blob-upload.ts +116 -116
- package/src/providers/memory-voice.ts +79 -79
- package/src/providers/supabase-dm.ts +122 -122
- package/src/providers/supabase-voice.ts +91 -91
- package/src/providers/supabase.ts +148 -148
- package/src/server.ts +1 -1
- package/src/tools/actions.ts +162 -162
- package/src/tools/attachments.ts +268 -268
- package/src/tools/capabilities.ts +68 -68
- package/src/tools/embed.ts +108 -108
- package/src/tools/index.ts +173 -104
- package/src/tools/knowledge-graph.ts +178 -0
- package/src/tools/knowledge.ts +319 -191
- package/src/tools/mail-agentbox.ts +147 -0
- package/src/tools/mail-aliases.ts +25 -25
- package/src/tools/mail-provenance.ts +135 -135
- package/src/tools/mail.ts +381 -381
- package/src/tools/mdm.ts +476 -479
- package/src/tools/mirc-edge.ts +190 -190
- package/src/tools/mirc-members.ts +5 -5
- package/src/tools/mirc-messages.ts +155 -155
- package/src/tools/mirc.ts +63 -3
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +221 -221
- package/src/tools/mtalk.ts +121 -121
- package/src/tools/murl.ts +4 -2
- package/src/tools/presence.ts +208 -0
- package/src/types.ts +94 -94
- package/src/voice/floor.ts +132 -132
- package/LICENSE +0 -201
- package/dist/bin/login.d.ts +0 -13
- package/dist/bin/mcp.d.ts +0 -1
- package/dist/index.d.ts +0 -266
|
@@ -1,148 +1,148 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Supabase provider for the alpha MCP server.
|
|
3
|
-
*
|
|
4
|
-
* Local BYOK mode: user supplies their own Supabase URL + anon key + user JWT
|
|
5
|
-
* via env vars. The MCP server creates a per-request Supabase client and
|
|
6
|
-
* invokes the mosadd Edge Functions on the user's behalf.
|
|
7
|
-
*
|
|
8
|
-
* In Phase 2 this is replaced by the hosted gateway (mcp.mosadd.com) which
|
|
9
|
-
* holds keys server-side via the BYOK broker.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
13
|
-
import { createClient, type SupabaseClient } from "@supabase/supabase-js";
|
|
14
|
-
import { loadSession, isSessionExpired } from "../config.js";
|
|
15
|
-
|
|
16
|
-
export interface SupabaseEnv {
|
|
17
|
-
url: string;
|
|
18
|
-
anonKey: string;
|
|
19
|
-
userJwt?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Per-request session context for the hosted HTTP gateway (mcp.mosadd.com).
|
|
24
|
-
*
|
|
25
|
-
* stdio runs one user per process, so credentials live in process.env. The
|
|
26
|
-
* hosted gateway serves MANY users from one process — sharing process.env would
|
|
27
|
-
* leak user A's JWT into user B's concurrent request. The gateway instead
|
|
28
|
-
* resolves the caller's session (Bearer api key → hub-key-exchange) and runs the
|
|
29
|
-
* whole request inside `runWithSupabaseEnv(env, …)`; `readSupabaseEnv()` reads
|
|
30
|
-
* this store first and falls back to process.env, so stdio is unaffected.
|
|
31
|
-
*/
|
|
32
|
-
const requestEnv = new AsyncLocalStorage<SupabaseEnv>();
|
|
33
|
-
|
|
34
|
-
/** Run `fn` (and every tool call it triggers) with a per-request Supabase session. */
|
|
35
|
-
export function runWithSupabaseEnv<T>(env: SupabaseEnv, fn: () => T): T {
|
|
36
|
-
return requestEnv.run(env, fn);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class MissingSupabaseEnvError extends Error {
|
|
40
|
-
constructor(missing: string[]) {
|
|
41
|
-
super(
|
|
42
|
-
`Missing Supabase credentials: ${missing.join(", ")}. ` +
|
|
43
|
-
`Run \`mosadd login\`, or set MOSADD_SUPABASE_URL, MOSADD_SUPABASE_ANON_KEY and MOSADD_USER_JWT.`,
|
|
44
|
-
);
|
|
45
|
-
this.name = "MissingSupabaseEnvError";
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function readSupabaseEnv(): SupabaseEnv {
|
|
50
|
-
// Hosted HTTP gateway: a per-request session set via runWithSupabaseEnv wins
|
|
51
|
-
// over any process-global env (multi-tenant safety). stdio has no store → falls
|
|
52
|
-
// through to the env/login resolution below.
|
|
53
|
-
const perRequest = requestEnv.getStore();
|
|
54
|
-
if (perRequest) return perRequest;
|
|
55
|
-
|
|
56
|
-
// Canonical env vars are MOSADD_*; the legacy M0SSAD_* names are still
|
|
57
|
-
// honored (deprecated) so anyone who set them before the brand sweep keeps
|
|
58
|
-
// working. Env vars take precedence; fall back to the session saved by
|
|
59
|
-
// `mosadd login`.
|
|
60
|
-
const env = (canonical: string, legacy: string): string | undefined =>
|
|
61
|
-
process.env[canonical] ?? process.env[legacy];
|
|
62
|
-
const userJwtEnv = env("MOSADD_USER_JWT", "M0SSAD_USER_JWT");
|
|
63
|
-
|
|
64
|
-
const session = loadSession();
|
|
65
|
-
const url = env("MOSADD_SUPABASE_URL", "M0SSAD_SUPABASE_URL") ?? session?.url;
|
|
66
|
-
const anonKey = env("MOSADD_SUPABASE_ANON_KEY", "M0SSAD_SUPABASE_ANON_KEY") ?? session?.anonKey;
|
|
67
|
-
const userJwt = userJwtEnv ?? session?.accessToken;
|
|
68
|
-
|
|
69
|
-
const missing: string[] = [];
|
|
70
|
-
if (!url) missing.push("MOSADD_SUPABASE_URL");
|
|
71
|
-
if (!anonKey) missing.push("MOSADD_SUPABASE_ANON_KEY");
|
|
72
|
-
if (missing.length) throw new MissingSupabaseEnvError(missing);
|
|
73
|
-
|
|
74
|
-
// Surface an expired `mosadd login` token early with an actionable message.
|
|
75
|
-
if (!userJwtEnv && session && isSessionExpired(session)) {
|
|
76
|
-
throw new Error("Your mosadd session has expired. Run `mosadd login` again to refresh it.");
|
|
77
|
-
}
|
|
78
|
-
return { url: url!, anonKey: anonKey!, userJwt };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function getSupabase(env: SupabaseEnv = readSupabaseEnv()): SupabaseClient {
|
|
82
|
-
return createClient(env.url, env.anonKey, {
|
|
83
|
-
auth: {
|
|
84
|
-
persistSession: false,
|
|
85
|
-
autoRefreshToken: false,
|
|
86
|
-
detectSessionInUrl: false,
|
|
87
|
-
},
|
|
88
|
-
global: env.userJwt
|
|
89
|
-
? {
|
|
90
|
-
headers: { Authorization: `Bearer ${env.userJwt}` },
|
|
91
|
-
}
|
|
92
|
-
: undefined,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Invoke a the legacy mosadd consumer-app repo Edge Function. Wraps `supabase.functions.invoke` with
|
|
98
|
-
* normalized error handling so MCP tool handlers can throw clean errors that
|
|
99
|
-
* agents can reason about.
|
|
100
|
-
*/
|
|
101
|
-
export async function invokeFunction<T = unknown>(
|
|
102
|
-
fn: string,
|
|
103
|
-
body: Record<string, unknown>,
|
|
104
|
-
): Promise<T> {
|
|
105
|
-
const client = getSupabase();
|
|
106
|
-
const { data, error } = await client.functions.invoke<T>(fn, { body });
|
|
107
|
-
if (error) {
|
|
108
|
-
// supabase-js throws FunctionsHttpError for any non-2xx, whose `.message`
|
|
109
|
-
// is the FIXED generic string "Edge Function returned a non-2xx status
|
|
110
|
-
// code" — the *real* reason (e.g. {"error":"wrapped_group_key required"},
|
|
111
|
-
// "forbidden", an RLS denial) lives in `error.context`, a Response. Read it
|
|
112
|
-
// so the agent gets an actionable message (and the HTTP status) it can
|
|
113
|
-
// reason about and self-correct on, instead of the same opaque sentence
|
|
114
|
-
// for every failure across mDM/mIRC/mp0st/mRAG/prekey/message-list.
|
|
115
|
-
let msg =
|
|
116
|
-
error instanceof Error && error.message
|
|
117
|
-
? error.message
|
|
118
|
-
: `Edge function ${fn} failed`;
|
|
119
|
-
const ctx = (error as { context?: unknown }).context;
|
|
120
|
-
if (ctx && typeof (ctx as Response).text === "function") {
|
|
121
|
-
const res = ctx as Response;
|
|
122
|
-
try {
|
|
123
|
-
const raw = await res.text();
|
|
124
|
-
if (raw) {
|
|
125
|
-
let detail = raw;
|
|
126
|
-
try {
|
|
127
|
-
const parsed = JSON.parse(raw) as { error?: unknown; message?: unknown };
|
|
128
|
-
detail =
|
|
129
|
-
(typeof parsed.error === "string" && parsed.error) ||
|
|
130
|
-
(typeof parsed.message === "string" && parsed.message) ||
|
|
131
|
-
raw;
|
|
132
|
-
} catch {
|
|
133
|
-
// non-JSON body — use the raw text as-is
|
|
134
|
-
}
|
|
135
|
-
const status = typeof res.status === "number" ? res.status : undefined;
|
|
136
|
-
msg = status ? `${fn} (${status}): ${detail}` : `${fn}: ${detail}`;
|
|
137
|
-
}
|
|
138
|
-
} catch {
|
|
139
|
-
// body already consumed or unreadable — keep the generic message
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
throw new Error(msg);
|
|
143
|
-
}
|
|
144
|
-
if (data == null) {
|
|
145
|
-
throw new Error(`Edge function ${fn} returned no data`);
|
|
146
|
-
}
|
|
147
|
-
return data;
|
|
148
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Supabase provider for the alpha MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Local BYOK mode: user supplies their own Supabase URL + anon key + user JWT
|
|
5
|
+
* via env vars. The MCP server creates a per-request Supabase client and
|
|
6
|
+
* invokes the mosadd Edge Functions on the user's behalf.
|
|
7
|
+
*
|
|
8
|
+
* In Phase 2 this is replaced by the hosted gateway (mcp.mosadd.com) which
|
|
9
|
+
* holds keys server-side via the BYOK broker.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
13
|
+
import { createClient, type SupabaseClient } from "@supabase/supabase-js";
|
|
14
|
+
import { loadSession, isSessionExpired } from "../config.js";
|
|
15
|
+
|
|
16
|
+
export interface SupabaseEnv {
|
|
17
|
+
url: string;
|
|
18
|
+
anonKey: string;
|
|
19
|
+
userJwt?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Per-request session context for the hosted HTTP gateway (mcp.mosadd.com).
|
|
24
|
+
*
|
|
25
|
+
* stdio runs one user per process, so credentials live in process.env. The
|
|
26
|
+
* hosted gateway serves MANY users from one process — sharing process.env would
|
|
27
|
+
* leak user A's JWT into user B's concurrent request. The gateway instead
|
|
28
|
+
* resolves the caller's session (Bearer api key → hub-key-exchange) and runs the
|
|
29
|
+
* whole request inside `runWithSupabaseEnv(env, …)`; `readSupabaseEnv()` reads
|
|
30
|
+
* this store first and falls back to process.env, so stdio is unaffected.
|
|
31
|
+
*/
|
|
32
|
+
const requestEnv = new AsyncLocalStorage<SupabaseEnv>();
|
|
33
|
+
|
|
34
|
+
/** Run `fn` (and every tool call it triggers) with a per-request Supabase session. */
|
|
35
|
+
export function runWithSupabaseEnv<T>(env: SupabaseEnv, fn: () => T): T {
|
|
36
|
+
return requestEnv.run(env, fn);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class MissingSupabaseEnvError extends Error {
|
|
40
|
+
constructor(missing: string[]) {
|
|
41
|
+
super(
|
|
42
|
+
`Missing Supabase credentials: ${missing.join(", ")}. ` +
|
|
43
|
+
`Run \`mosadd login\`, or set MOSADD_SUPABASE_URL, MOSADD_SUPABASE_ANON_KEY and MOSADD_USER_JWT.`,
|
|
44
|
+
);
|
|
45
|
+
this.name = "MissingSupabaseEnvError";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function readSupabaseEnv(): SupabaseEnv {
|
|
50
|
+
// Hosted HTTP gateway: a per-request session set via runWithSupabaseEnv wins
|
|
51
|
+
// over any process-global env (multi-tenant safety). stdio has no store → falls
|
|
52
|
+
// through to the env/login resolution below.
|
|
53
|
+
const perRequest = requestEnv.getStore();
|
|
54
|
+
if (perRequest) return perRequest;
|
|
55
|
+
|
|
56
|
+
// Canonical env vars are MOSADD_*; the legacy M0SSAD_* names are still
|
|
57
|
+
// honored (deprecated) so anyone who set them before the brand sweep keeps
|
|
58
|
+
// working. Env vars take precedence; fall back to the session saved by
|
|
59
|
+
// `mosadd login`.
|
|
60
|
+
const env = (canonical: string, legacy: string): string | undefined =>
|
|
61
|
+
process.env[canonical] ?? process.env[legacy];
|
|
62
|
+
const userJwtEnv = env("MOSADD_USER_JWT", "M0SSAD_USER_JWT");
|
|
63
|
+
|
|
64
|
+
const session = loadSession();
|
|
65
|
+
const url = env("MOSADD_SUPABASE_URL", "M0SSAD_SUPABASE_URL") ?? session?.url;
|
|
66
|
+
const anonKey = env("MOSADD_SUPABASE_ANON_KEY", "M0SSAD_SUPABASE_ANON_KEY") ?? session?.anonKey;
|
|
67
|
+
const userJwt = userJwtEnv ?? session?.accessToken;
|
|
68
|
+
|
|
69
|
+
const missing: string[] = [];
|
|
70
|
+
if (!url) missing.push("MOSADD_SUPABASE_URL");
|
|
71
|
+
if (!anonKey) missing.push("MOSADD_SUPABASE_ANON_KEY");
|
|
72
|
+
if (missing.length) throw new MissingSupabaseEnvError(missing);
|
|
73
|
+
|
|
74
|
+
// Surface an expired `mosadd login` token early with an actionable message.
|
|
75
|
+
if (!userJwtEnv && session && isSessionExpired(session)) {
|
|
76
|
+
throw new Error("Your mosadd session has expired. Run `mosadd login` again to refresh it.");
|
|
77
|
+
}
|
|
78
|
+
return { url: url!, anonKey: anonKey!, userJwt };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function getSupabase(env: SupabaseEnv = readSupabaseEnv()): SupabaseClient {
|
|
82
|
+
return createClient(env.url, env.anonKey, {
|
|
83
|
+
auth: {
|
|
84
|
+
persistSession: false,
|
|
85
|
+
autoRefreshToken: false,
|
|
86
|
+
detectSessionInUrl: false,
|
|
87
|
+
},
|
|
88
|
+
global: env.userJwt
|
|
89
|
+
? {
|
|
90
|
+
headers: { Authorization: `Bearer ${env.userJwt}` },
|
|
91
|
+
}
|
|
92
|
+
: undefined,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Invoke a the legacy mosadd consumer-app repo Edge Function. Wraps `supabase.functions.invoke` with
|
|
98
|
+
* normalized error handling so MCP tool handlers can throw clean errors that
|
|
99
|
+
* agents can reason about.
|
|
100
|
+
*/
|
|
101
|
+
export async function invokeFunction<T = unknown>(
|
|
102
|
+
fn: string,
|
|
103
|
+
body: Record<string, unknown>,
|
|
104
|
+
): Promise<T> {
|
|
105
|
+
const client = getSupabase();
|
|
106
|
+
const { data, error } = await client.functions.invoke<T>(fn, { body });
|
|
107
|
+
if (error) {
|
|
108
|
+
// supabase-js throws FunctionsHttpError for any non-2xx, whose `.message`
|
|
109
|
+
// is the FIXED generic string "Edge Function returned a non-2xx status
|
|
110
|
+
// code" — the *real* reason (e.g. {"error":"wrapped_group_key required"},
|
|
111
|
+
// "forbidden", an RLS denial) lives in `error.context`, a Response. Read it
|
|
112
|
+
// so the agent gets an actionable message (and the HTTP status) it can
|
|
113
|
+
// reason about and self-correct on, instead of the same opaque sentence
|
|
114
|
+
// for every failure across mDM/mIRC/mp0st/mRAG/prekey/message-list.
|
|
115
|
+
let msg =
|
|
116
|
+
error instanceof Error && error.message
|
|
117
|
+
? error.message
|
|
118
|
+
: `Edge function ${fn} failed`;
|
|
119
|
+
const ctx = (error as { context?: unknown }).context;
|
|
120
|
+
if (ctx && typeof (ctx as Response).text === "function") {
|
|
121
|
+
const res = ctx as Response;
|
|
122
|
+
try {
|
|
123
|
+
const raw = await res.text();
|
|
124
|
+
if (raw) {
|
|
125
|
+
let detail = raw;
|
|
126
|
+
try {
|
|
127
|
+
const parsed = JSON.parse(raw) as { error?: unknown; message?: unknown };
|
|
128
|
+
detail =
|
|
129
|
+
(typeof parsed.error === "string" && parsed.error) ||
|
|
130
|
+
(typeof parsed.message === "string" && parsed.message) ||
|
|
131
|
+
raw;
|
|
132
|
+
} catch {
|
|
133
|
+
// non-JSON body — use the raw text as-is
|
|
134
|
+
}
|
|
135
|
+
const status = typeof res.status === "number" ? res.status : undefined;
|
|
136
|
+
msg = status ? `${fn} (${status}): ${detail}` : `${fn}: ${detail}`;
|
|
137
|
+
}
|
|
138
|
+
} catch {
|
|
139
|
+
// body already consumed or unreadable — keep the generic message
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
throw new Error(msg);
|
|
143
|
+
}
|
|
144
|
+
if (data == null) {
|
|
145
|
+
throw new Error(`Edge function ${fn} returned no data`);
|
|
146
|
+
}
|
|
147
|
+
return data;
|
|
148
|
+
}
|
package/src/server.ts
CHANGED
package/src/tools/actions.ts
CHANGED
|
@@ -1,162 +1,162 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Action links — agent → user one-link actions (Tier 1).
|
|
3
|
-
*
|
|
4
|
-
* Mint a single-use, expiring link (`https://mosadd.com/do/<token>`) that asks a
|
|
5
|
-
* human to DO something in their browser — confirm, pick a file, fill a form, or
|
|
6
|
-
* open a vetted URL — with explicit consent. Send the returned `link` to the
|
|
7
|
-
* person via any channel (mDM/mIRC/mp0st). They open it, see what's asked, consent,
|
|
8
|
-
* and the browser performs the action IN ITS SANDBOX, then the result is recorded
|
|
9
|
-
* against the action. No install, no OS access, nothing runs without a user gesture.
|
|
10
|
-
*
|
|
11
|
-
* Backend: mosadd `action-create` Edge Function. The action is owned by the
|
|
12
|
-
* calling user (user-JWT scoped — `mosadd login` / MOSADD_USER_JWT), so only you
|
|
13
|
-
* can later read its result.
|
|
14
|
-
*
|
|
15
|
-
* Result read-back (an `action_status` tool) is a follow-up — it needs a small
|
|
16
|
-
* creator-scoped read Edge Function (`action-status`). For now, the recipient's
|
|
17
|
-
* outcome is recorded on the action row; surface it once that EF ships.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import { z } from "zod";
|
|
21
|
-
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
22
|
-
import { invokeFunction, readSupabaseEnv, getSupabase } from "../providers/supabase.js";
|
|
23
|
-
|
|
24
|
-
const formField = z.object({
|
|
25
|
-
name: z.string().min(1).max(60).describe("Field key — returned verbatim in the result."),
|
|
26
|
-
label: z.string().max(120).optional().describe("Human label shown to the recipient. Defaults to `name`."),
|
|
27
|
-
type: z.enum(["text", "email", "number", "textarea", "tel", "url"]).optional().describe("Input type. Default 'text'."),
|
|
28
|
-
required: z.boolean().optional().describe("Whether the recipient must fill this field."),
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const action_create_input = z.object({
|
|
32
|
-
action_type: z.enum(["confirm", "file_request", "form", "open_url", "screen_share"]).describe(
|
|
33
|
-
"What you want the recipient to do: 'confirm' (yes/no), 'file_request' (pick a file from their computer), 'form' (fill fields), 'open_url' (open a vetted https URL), 'screen_share' (recipient shares their screen so you can SEE it via comms_action_frame_get — view only).",
|
|
34
|
-
),
|
|
35
|
-
message: z.string().min(1).max(2000).describe("What you're asking — shown on the consent screen above the action UI."),
|
|
36
|
-
creator_label: z.string().max(80).optional().describe("How you're identified to the recipient (e.g. your agent name). Default 'Agent'."),
|
|
37
|
-
// confirm
|
|
38
|
-
yes_label: z.string().max(40).optional().describe("[confirm] Affirmative button label. Default 'Tak'."),
|
|
39
|
-
no_label: z.string().max(40).optional().describe("[confirm] Negative button label. Default 'Nie'."),
|
|
40
|
-
// file_request
|
|
41
|
-
accept: z.string().max(200).optional().describe("[file_request] Accepted file types (HTML accept attr, e.g. 'image/*,.pdf')."),
|
|
42
|
-
max_bytes: z.number().int().positive().max(5_242_880).optional().describe("[file_request] Max file size in bytes (≤ 5 MB). NOTE: the returned file is NOT yet end-to-end encrypted — do not request sensitive files until Tier 1.1 ships."),
|
|
43
|
-
// form
|
|
44
|
-
fields: z.array(formField).min(1).max(20).optional().describe("[form] Fields to collect from the recipient."),
|
|
45
|
-
// open_url
|
|
46
|
-
url: z.string().url().optional().describe("[open_url] The https URL to open. The full URL is shown to the recipient before they open it."),
|
|
47
|
-
// screen_share
|
|
48
|
-
max_width: z.number().int().positive().max(1920).optional().describe("[screen_share] Max captured frame width in px (default 1280). Frames are downscaled JPEGs."),
|
|
49
|
-
// lifecycle
|
|
50
|
-
ttl_ms: z.number().int().positive().optional().describe("Link lifetime in milliseconds. Default 24h, capped at 7d."),
|
|
51
|
-
max_uses: z.number().int().min(1).max(50).optional().describe("How many times the link can be redeemed. Default 1 (single-use)."),
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
function buildParams(input: z.infer<typeof action_create_input>): Record<string, unknown> {
|
|
55
|
-
switch (input.action_type) {
|
|
56
|
-
case "confirm":
|
|
57
|
-
return { message: input.message, yesLabel: input.yes_label, noLabel: input.no_label };
|
|
58
|
-
case "file_request":
|
|
59
|
-
return { message: input.message, accept: input.accept, maxBytes: input.max_bytes };
|
|
60
|
-
case "form":
|
|
61
|
-
if (!input.fields?.length) throw new Error("action_type 'form' requires a non-empty `fields` array.");
|
|
62
|
-
return { message: input.message, fields: input.fields };
|
|
63
|
-
case "open_url":
|
|
64
|
-
if (!input.url) throw new Error("action_type 'open_url' requires `url`.");
|
|
65
|
-
return { message: input.message, url: input.url };
|
|
66
|
-
case "screen_share":
|
|
67
|
-
return { message: input.message, maxWidth: input.max_width };
|
|
68
|
-
default:
|
|
69
|
-
return { message: input.message };
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
interface ActionCreateResult {
|
|
74
|
-
action_id: string;
|
|
75
|
-
token: string;
|
|
76
|
-
link: string;
|
|
77
|
-
action_type: string;
|
|
78
|
-
expires_at: string;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async function action_create(
|
|
82
|
-
input: z.infer<typeof action_create_input>,
|
|
83
|
-
ctx: MosaddToolContext,
|
|
84
|
-
): Promise<ActionCreateResult> {
|
|
85
|
-
readSupabaseEnv();
|
|
86
|
-
ctx.log("debug", "action_create invoking action-create", { action_type: input.action_type });
|
|
87
|
-
|
|
88
|
-
const body: Record<string, unknown> = {
|
|
89
|
-
action_type: input.action_type,
|
|
90
|
-
params: buildParams(input),
|
|
91
|
-
};
|
|
92
|
-
if (input.creator_label !== undefined) body.creator_label = input.creator_label;
|
|
93
|
-
if (input.ttl_ms !== undefined) body.ttl_ms = input.ttl_ms;
|
|
94
|
-
if (input.max_uses !== undefined) body.max_uses = input.max_uses;
|
|
95
|
-
|
|
96
|
-
const res = await invokeFunction<Partial<ActionCreateResult> & { error?: string }>("action-create", body);
|
|
97
|
-
if (res.error) throw new Error(res.error);
|
|
98
|
-
if (!res.link || !res.token) throw new Error("action-create returned a malformed response (missing link/token).");
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
action_id: res.action_id ?? "",
|
|
102
|
-
token: res.token,
|
|
103
|
-
link: res.link,
|
|
104
|
-
action_type: res.action_type ?? input.action_type,
|
|
105
|
-
expires_at: res.expires_at ?? "",
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// ── comms_action_frame_get — read the latest screen frame (Tier 1.5) ──────────
|
|
110
|
-
const action_frame_get_input = z.object({
|
|
111
|
-
action_id: z.string().min(1).describe("The action_id returned by comms_action_create for a 'screen_share' action you created."),
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
async function action_frame_get(
|
|
115
|
-
input: z.infer<typeof action_frame_get_input>,
|
|
116
|
-
ctx: MosaddToolContext,
|
|
117
|
-
): Promise<{ mcpContent: Array<Record<string, unknown>> }> {
|
|
118
|
-
readSupabaseEnv();
|
|
119
|
-
ctx.log("debug", "action_frame_get reading frame", { action_id: input.action_id });
|
|
120
|
-
// Read directly via RLS ("creators read own frames") — the agent's JWT gates it
|
|
121
|
-
// to screen_share actions it created. No edge function needed.
|
|
122
|
-
const sb = getSupabase();
|
|
123
|
-
const { data, error } = await sb
|
|
124
|
-
.from("action_screen_frames")
|
|
125
|
-
.select("image_jpeg, width, seq, updated_at")
|
|
126
|
-
.eq("action_id", input.action_id)
|
|
127
|
-
.maybeSingle();
|
|
128
|
-
if (error) throw new Error(error.message);
|
|
129
|
-
if (!data) {
|
|
130
|
-
return { mcpContent: [{ type: "text", text: "No frame yet — the recipient hasn't started sharing their screen (or you don't own this action)." }] };
|
|
131
|
-
}
|
|
132
|
-
const row = data as { image_jpeg: string; width: number | null; seq: number; updated_at: string };
|
|
133
|
-
const ageSec = Math.round((Date.now() - new Date(row.updated_at).getTime()) / 1000);
|
|
134
|
-
return {
|
|
135
|
-
mcpContent: [
|
|
136
|
-
{ type: "text", text: `Latest screen frame — seq ${row.seq}, ${row.width ?? "?"}px wide, ${ageSec}s old.` },
|
|
137
|
-
{ type: "image", data: row.image_jpeg, mimeType: "image/jpeg" },
|
|
138
|
-
],
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export const actionTools: MosaddTool[] = [
|
|
143
|
-
{
|
|
144
|
-
// RFC 0001: channel-agnostic capability (link is sent over ANY channel), so it
|
|
145
|
-
// lives in the `comms_` namespace rather than a channel `m<MODULE>_` prefix.
|
|
146
|
-
// A dedicated `mACT` module (create/get/status) is a possible RFC follow-up.
|
|
147
|
-
name: "comms_action_create",
|
|
148
|
-
requires: "network",
|
|
149
|
-
description:
|
|
150
|
-
"Mint a single-use, expiring action link (https://mosadd.com/do/<token>) that asks a human to DO something in their browser, with explicit consent. action_type: 'confirm' (yes/no) | 'file_request' (recipient picks a file from their computer) | 'form' (recipient fills fields you define) | 'open_url' (recipient opens a vetted https URL). Returns { action_id, token, link, expires_at }. Send the `link` to the person via mDM/mIRC/mp0st; they open it, consent, and the browser performs the action in its sandbox (no install, no OS access). The action is owned by you (the calling user). HONEST LIMITS: this is browser-sandbox only — it cannot click other apps, run programs, or read files the user didn't pick; and file_request payloads are not yet end-to-end encrypted (don't request sensitive files until Tier 1.1).",
|
|
151
|
-
inputSchema: action_create_input,
|
|
152
|
-
handler: action_create as MosaddTool["handler"],
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
name: "comms_action_frame_get",
|
|
156
|
-
requires: "network",
|
|
157
|
-
description:
|
|
158
|
-
"See the LATEST screen frame from a 'screen_share' action you created (pass the action_id from comms_action_create). Returns the current screenshot AS AN IMAGE you can look at, plus how old it is. The recipient must have opened the link and clicked 'share screen' first. Poll this every few seconds to watch live. VIEW ONLY — you cannot click or control their screen. Returns a 'no frame yet' note until they start sharing.",
|
|
159
|
-
inputSchema: action_frame_get_input,
|
|
160
|
-
handler: action_frame_get as MosaddTool["handler"],
|
|
161
|
-
},
|
|
162
|
-
];
|
|
1
|
+
/**
|
|
2
|
+
* Action links — agent → user one-link actions (Tier 1).
|
|
3
|
+
*
|
|
4
|
+
* Mint a single-use, expiring link (`https://mosadd.com/do/<token>`) that asks a
|
|
5
|
+
* human to DO something in their browser — confirm, pick a file, fill a form, or
|
|
6
|
+
* open a vetted URL — with explicit consent. Send the returned `link` to the
|
|
7
|
+
* person via any channel (mDM/mIRC/mp0st). They open it, see what's asked, consent,
|
|
8
|
+
* and the browser performs the action IN ITS SANDBOX, then the result is recorded
|
|
9
|
+
* against the action. No install, no OS access, nothing runs without a user gesture.
|
|
10
|
+
*
|
|
11
|
+
* Backend: mosadd `action-create` Edge Function. The action is owned by the
|
|
12
|
+
* calling user (user-JWT scoped — `mosadd login` / MOSADD_USER_JWT), so only you
|
|
13
|
+
* can later read its result.
|
|
14
|
+
*
|
|
15
|
+
* Result read-back (an `action_status` tool) is a follow-up — it needs a small
|
|
16
|
+
* creator-scoped read Edge Function (`action-status`). For now, the recipient's
|
|
17
|
+
* outcome is recorded on the action row; surface it once that EF ships.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
22
|
+
import { invokeFunction, readSupabaseEnv, getSupabase } from "../providers/supabase.js";
|
|
23
|
+
|
|
24
|
+
const formField = z.object({
|
|
25
|
+
name: z.string().min(1).max(60).describe("Field key — returned verbatim in the result."),
|
|
26
|
+
label: z.string().max(120).optional().describe("Human label shown to the recipient. Defaults to `name`."),
|
|
27
|
+
type: z.enum(["text", "email", "number", "textarea", "tel", "url"]).optional().describe("Input type. Default 'text'."),
|
|
28
|
+
required: z.boolean().optional().describe("Whether the recipient must fill this field."),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const action_create_input = z.object({
|
|
32
|
+
action_type: z.enum(["confirm", "file_request", "form", "open_url", "screen_share"]).describe(
|
|
33
|
+
"What you want the recipient to do: 'confirm' (yes/no), 'file_request' (pick a file from their computer), 'form' (fill fields), 'open_url' (open a vetted https URL), 'screen_share' (recipient shares their screen so you can SEE it via comms_action_frame_get — view only).",
|
|
34
|
+
),
|
|
35
|
+
message: z.string().min(1).max(2000).describe("What you're asking — shown on the consent screen above the action UI."),
|
|
36
|
+
creator_label: z.string().max(80).optional().describe("How you're identified to the recipient (e.g. your agent name). Default 'Agent'."),
|
|
37
|
+
// confirm
|
|
38
|
+
yes_label: z.string().max(40).optional().describe("[confirm] Affirmative button label. Default 'Tak'."),
|
|
39
|
+
no_label: z.string().max(40).optional().describe("[confirm] Negative button label. Default 'Nie'."),
|
|
40
|
+
// file_request
|
|
41
|
+
accept: z.string().max(200).optional().describe("[file_request] Accepted file types (HTML accept attr, e.g. 'image/*,.pdf')."),
|
|
42
|
+
max_bytes: z.number().int().positive().max(5_242_880).optional().describe("[file_request] Max file size in bytes (≤ 5 MB). NOTE: the returned file is NOT yet end-to-end encrypted — do not request sensitive files until Tier 1.1 ships."),
|
|
43
|
+
// form
|
|
44
|
+
fields: z.array(formField).min(1).max(20).optional().describe("[form] Fields to collect from the recipient."),
|
|
45
|
+
// open_url
|
|
46
|
+
url: z.string().url().optional().describe("[open_url] The https URL to open. The full URL is shown to the recipient before they open it."),
|
|
47
|
+
// screen_share
|
|
48
|
+
max_width: z.number().int().positive().max(1920).optional().describe("[screen_share] Max captured frame width in px (default 1280). Frames are downscaled JPEGs."),
|
|
49
|
+
// lifecycle
|
|
50
|
+
ttl_ms: z.number().int().positive().optional().describe("Link lifetime in milliseconds. Default 24h, capped at 7d."),
|
|
51
|
+
max_uses: z.number().int().min(1).max(50).optional().describe("How many times the link can be redeemed. Default 1 (single-use)."),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
function buildParams(input: z.infer<typeof action_create_input>): Record<string, unknown> {
|
|
55
|
+
switch (input.action_type) {
|
|
56
|
+
case "confirm":
|
|
57
|
+
return { message: input.message, yesLabel: input.yes_label, noLabel: input.no_label };
|
|
58
|
+
case "file_request":
|
|
59
|
+
return { message: input.message, accept: input.accept, maxBytes: input.max_bytes };
|
|
60
|
+
case "form":
|
|
61
|
+
if (!input.fields?.length) throw new Error("action_type 'form' requires a non-empty `fields` array.");
|
|
62
|
+
return { message: input.message, fields: input.fields };
|
|
63
|
+
case "open_url":
|
|
64
|
+
if (!input.url) throw new Error("action_type 'open_url' requires `url`.");
|
|
65
|
+
return { message: input.message, url: input.url };
|
|
66
|
+
case "screen_share":
|
|
67
|
+
return { message: input.message, maxWidth: input.max_width };
|
|
68
|
+
default:
|
|
69
|
+
return { message: input.message };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface ActionCreateResult {
|
|
74
|
+
action_id: string;
|
|
75
|
+
token: string;
|
|
76
|
+
link: string;
|
|
77
|
+
action_type: string;
|
|
78
|
+
expires_at: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function action_create(
|
|
82
|
+
input: z.infer<typeof action_create_input>,
|
|
83
|
+
ctx: MosaddToolContext,
|
|
84
|
+
): Promise<ActionCreateResult> {
|
|
85
|
+
readSupabaseEnv();
|
|
86
|
+
ctx.log("debug", "action_create invoking action-create", { action_type: input.action_type });
|
|
87
|
+
|
|
88
|
+
const body: Record<string, unknown> = {
|
|
89
|
+
action_type: input.action_type,
|
|
90
|
+
params: buildParams(input),
|
|
91
|
+
};
|
|
92
|
+
if (input.creator_label !== undefined) body.creator_label = input.creator_label;
|
|
93
|
+
if (input.ttl_ms !== undefined) body.ttl_ms = input.ttl_ms;
|
|
94
|
+
if (input.max_uses !== undefined) body.max_uses = input.max_uses;
|
|
95
|
+
|
|
96
|
+
const res = await invokeFunction<Partial<ActionCreateResult> & { error?: string }>("action-create", body);
|
|
97
|
+
if (res.error) throw new Error(res.error);
|
|
98
|
+
if (!res.link || !res.token) throw new Error("action-create returned a malformed response (missing link/token).");
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
action_id: res.action_id ?? "",
|
|
102
|
+
token: res.token,
|
|
103
|
+
link: res.link,
|
|
104
|
+
action_type: res.action_type ?? input.action_type,
|
|
105
|
+
expires_at: res.expires_at ?? "",
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ── comms_action_frame_get — read the latest screen frame (Tier 1.5) ──────────
|
|
110
|
+
const action_frame_get_input = z.object({
|
|
111
|
+
action_id: z.string().min(1).describe("The action_id returned by comms_action_create for a 'screen_share' action you created."),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
async function action_frame_get(
|
|
115
|
+
input: z.infer<typeof action_frame_get_input>,
|
|
116
|
+
ctx: MosaddToolContext,
|
|
117
|
+
): Promise<{ mcpContent: Array<Record<string, unknown>> }> {
|
|
118
|
+
readSupabaseEnv();
|
|
119
|
+
ctx.log("debug", "action_frame_get reading frame", { action_id: input.action_id });
|
|
120
|
+
// Read directly via RLS ("creators read own frames") — the agent's JWT gates it
|
|
121
|
+
// to screen_share actions it created. No edge function needed.
|
|
122
|
+
const sb = getSupabase();
|
|
123
|
+
const { data, error } = await sb
|
|
124
|
+
.from("action_screen_frames")
|
|
125
|
+
.select("image_jpeg, width, seq, updated_at")
|
|
126
|
+
.eq("action_id", input.action_id)
|
|
127
|
+
.maybeSingle();
|
|
128
|
+
if (error) throw new Error(error.message);
|
|
129
|
+
if (!data) {
|
|
130
|
+
return { mcpContent: [{ type: "text", text: "No frame yet — the recipient hasn't started sharing their screen (or you don't own this action)." }] };
|
|
131
|
+
}
|
|
132
|
+
const row = data as { image_jpeg: string; width: number | null; seq: number; updated_at: string };
|
|
133
|
+
const ageSec = Math.round((Date.now() - new Date(row.updated_at).getTime()) / 1000);
|
|
134
|
+
return {
|
|
135
|
+
mcpContent: [
|
|
136
|
+
{ type: "text", text: `Latest screen frame — seq ${row.seq}, ${row.width ?? "?"}px wide, ${ageSec}s old.` },
|
|
137
|
+
{ type: "image", data: row.image_jpeg, mimeType: "image/jpeg" },
|
|
138
|
+
],
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const actionTools: MosaddTool[] = [
|
|
143
|
+
{
|
|
144
|
+
// RFC 0001: channel-agnostic capability (link is sent over ANY channel), so it
|
|
145
|
+
// lives in the `comms_` namespace rather than a channel `m<MODULE>_` prefix.
|
|
146
|
+
// A dedicated `mACT` module (create/get/status) is a possible RFC follow-up.
|
|
147
|
+
name: "comms_action_create",
|
|
148
|
+
requires: "network",
|
|
149
|
+
description:
|
|
150
|
+
"Mint a single-use, expiring action link (https://mosadd.com/do/<token>) that asks a human to DO something in their browser, with explicit consent. action_type: 'confirm' (yes/no) | 'file_request' (recipient picks a file from their computer) | 'form' (recipient fills fields you define) | 'open_url' (recipient opens a vetted https URL). Returns { action_id, token, link, expires_at }. Send the `link` to the person via mDM/mIRC/mp0st; they open it, consent, and the browser performs the action in its sandbox (no install, no OS access). The action is owned by you (the calling user). HONEST LIMITS: this is browser-sandbox only — it cannot click other apps, run programs, or read files the user didn't pick; and file_request payloads are not yet end-to-end encrypted (don't request sensitive files until Tier 1.1).",
|
|
151
|
+
inputSchema: action_create_input,
|
|
152
|
+
handler: action_create as MosaddTool["handler"],
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: "comms_action_frame_get",
|
|
156
|
+
requires: "network",
|
|
157
|
+
description:
|
|
158
|
+
"See the LATEST screen frame from a 'screen_share' action you created (pass the action_id from comms_action_create). Returns the current screenshot AS AN IMAGE you can look at, plus how old it is. The recipient must have opened the link and clicked 'share screen' first. Poll this every few seconds to watch live. VIEW ONLY — you cannot click or control their screen. Returns a 'no frame yet' note until they start sharing.",
|
|
159
|
+
inputSchema: action_frame_get_input,
|
|
160
|
+
handler: action_frame_get as MosaddTool["handler"],
|
|
161
|
+
},
|
|
162
|
+
];
|