@mosadd/mcp 3.0.0-alpha.15 → 3.0.0-alpha.16
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/dist/bin/mcp.js +1 -1
- package/dist/{chunk-ZT7IBWW7.js → chunk-KZ3HIZ74.js} +515 -31
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/providers/blob-upload.ts +116 -0
- package/src/tools/actions.ts +117 -0
- package/src/tools/attachments.ts +328 -0
- package/src/tools/index.ts +9 -0
- package/src/tools/mail-provenance.ts +137 -0
- package/src/tools/mail.ts +5 -2
- package/src/tools/ptt-ingest.ts +91 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mAIL provenance — agent-attributed email send.
|
|
3
|
+
*
|
|
4
|
+
* The plain `mAIL_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 mAIL):
|
|
13
|
+
* - mAIL_send uses the user's Supabase session JWT (via invokeFunction).
|
|
14
|
+
* - mAIL_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 mAIL_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 a hub-claim JWT that authorizes agent-attributed
|
|
66
|
+
* actions. TODO(Lane A): confirm endpoint + response. Mirrors the
|
|
67
|
+
* hub-mint-channel-token pattern in mirc-edge.ts.
|
|
68
|
+
*/
|
|
69
|
+
async function mintHubClaim(agentId: string, taskId?: string): Promise<string> {
|
|
70
|
+
const key = hubKey();
|
|
71
|
+
if (!key) {
|
|
72
|
+
throw new Error("mAIL_send_as_agent needs MOSADD_API_KEY (hub key) to mint a provenance claim.");
|
|
73
|
+
}
|
|
74
|
+
const r = await fetch(`${supabaseUrl()}/functions/v1/hub-claim-mint`, {
|
|
75
|
+
method: "POST",
|
|
76
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
|
|
77
|
+
body: JSON.stringify({ scope: "mail:send", agent_id: agentId, task_id: taskId ?? null }),
|
|
78
|
+
});
|
|
79
|
+
if (!r.ok) {
|
|
80
|
+
const b = await r.text().catch(() => "");
|
|
81
|
+
throw new Error(`hub-claim-mint ${r.status}: ${b.slice(0, 200)}`);
|
|
82
|
+
}
|
|
83
|
+
const data = (await r.json()) as { token?: string };
|
|
84
|
+
if (!data?.token) throw new Error("hub-claim-mint: no token in response");
|
|
85
|
+
return data.token;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function mAIL_send_as_agent(
|
|
89
|
+
input: z.infer<typeof mAIL_send_as_agent_input>,
|
|
90
|
+
ctx: MosaddToolContext,
|
|
91
|
+
): Promise<{ message_id: string; status: string; is_internal: boolean; sent_by: "agent" }> {
|
|
92
|
+
if (!input.body_text && !input.body_html) {
|
|
93
|
+
throw new Error("mAIL_send_as_agent requires at least one of body_text or body_html.");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Present the hub-claim JWT directly to mp0st-send (NOT the user session client)
|
|
97
|
+
// so the EF attributes the row to the agent. TODO(Lane A): confirm mp0st-send
|
|
98
|
+
// accepts a Bearer hub-claim and reads sent_by_agent_id / sent_by_task_id.
|
|
99
|
+
const claim = await mintHubClaim(input.agent_id, input.task_id);
|
|
100
|
+
ctx.log("debug", "mAIL_send_as_agent invoking mp0st-send with hub-claim", { agent_id: input.agent_id });
|
|
101
|
+
|
|
102
|
+
const { agent_id, task_id, ...mailFields } = input;
|
|
103
|
+
const r = await fetch(`${supabaseUrl()}/functions/v1/mp0st-send`, {
|
|
104
|
+
method: "POST",
|
|
105
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${claim}` },
|
|
106
|
+
body: JSON.stringify({
|
|
107
|
+
...mailFields,
|
|
108
|
+
sent_by: "agent",
|
|
109
|
+
sent_by_agent_id: agent_id,
|
|
110
|
+
sent_by_task_id: task_id ?? null,
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
if (!r.ok) {
|
|
114
|
+
const b = await r.text().catch(() => "");
|
|
115
|
+
throw new Error(`mp0st-send ${r.status}: ${b.slice(0, 200)}`);
|
|
116
|
+
}
|
|
117
|
+
const res = (await r.json()) as { email_id?: string; status?: string; is_internal?: boolean; error?: string };
|
|
118
|
+
if (res.error) throw new Error(res.error);
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
message_id: res.email_id ?? "",
|
|
122
|
+
status: res.status ?? "sent",
|
|
123
|
+
is_internal: res.is_internal ?? false,
|
|
124
|
+
sent_by: "agent",
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export const mailProvenanceTools: MosaddTool[] = [
|
|
129
|
+
{
|
|
130
|
+
name: "mAIL_send_as_agent",
|
|
131
|
+
requires: "network",
|
|
132
|
+
description:
|
|
133
|
+
"Send an email ATTRIBUTED TO THE AGENT (provenance-stamped). Unlike mAIL_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). SCAFFOLD: depends on mp0st-send honoring the hub-claim + provenance fields (TODO Lane A).",
|
|
134
|
+
inputSchema: mAIL_send_as_agent_input,
|
|
135
|
+
handler: mAIL_send_as_agent as MosaddTool["handler"],
|
|
136
|
+
},
|
|
137
|
+
];
|
package/src/tools/mail.ts
CHANGED
|
@@ -153,8 +153,11 @@ async function mAIL_view(
|
|
|
153
153
|
received_at: string;
|
|
154
154
|
}> {
|
|
155
155
|
readSupabaseEnv();
|
|
156
|
-
|
|
157
|
-
|
|
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", "mAIL_view invoking mp0st-get", { message_id: input.message_id });
|
|
160
|
+
return await invokeFunction("mp0st-get", { message_id: input.message_id });
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
async function mAIL_list(
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PTT capture → ingest → RAG transcription.
|
|
3
|
+
*
|
|
4
|
+
* mTALK (mtalk.ts) drives the live half-duplex FLOOR (who may transmit). What it
|
|
5
|
+
* does NOT do is capture a finished PTT transmission as a durable, queued message
|
|
6
|
+
* — i.e. a recorded "over" that lands in a channel's queued-PTT log AND (opt-in)
|
|
7
|
+
* gets transcribed into RAG. That's this module.
|
|
8
|
+
*
|
|
9
|
+
* Flow (per the Lane A contract):
|
|
10
|
+
* 1. agent records/has a PTT clip → base64 → uploadBlob(kind:'ptt') to
|
|
11
|
+
* 'voice-blobs'.
|
|
12
|
+
* 2. call `ptt-ingest` EF with the attachment descriptor + routing (which
|
|
13
|
+
* channel/room the "over" belongs to). The EF persists a queued-PTT message.
|
|
14
|
+
* 3. if the user has opted in to RAG, `rag-transcribe` runs and the transcript
|
|
15
|
+
* lands in user_embeddings(source_type='ptt').
|
|
16
|
+
*
|
|
17
|
+
* STATUS: scaffold — `ptt-ingest` is not yet deployed. Upload is real; the EF
|
|
18
|
+
* call shape is best-guess (TODO Lane A).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { z } from "zod";
|
|
22
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
23
|
+
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
24
|
+
import { uploadBlob, decodeBase64Body } from "../providers/blob-upload.js";
|
|
25
|
+
|
|
26
|
+
const mTALK_ingest_ptt_input = z.object({
|
|
27
|
+
audio_base64: z
|
|
28
|
+
.string()
|
|
29
|
+
.min(1)
|
|
30
|
+
.max(20_000_000)
|
|
31
|
+
.describe("Recorded PTT 'over' as base64 (or data: URL)."),
|
|
32
|
+
mime: z.string().min(1).max(120).default("audio/ogg"),
|
|
33
|
+
duration_ms: z.number().int().positive().optional(),
|
|
34
|
+
// Routing: exactly one of room_id / channel_id identifies where the over lands.
|
|
35
|
+
channel_id: z.string().optional().describe("mIRC channel id — route the queued PTT into a persistent channel's PTT log."),
|
|
36
|
+
room_id: z.string().optional().describe("mROOM/mTALK room id — route into an ephemeral room's PTT log."),
|
|
37
|
+
transcribe: z
|
|
38
|
+
.boolean()
|
|
39
|
+
.optional()
|
|
40
|
+
.describe("Request RAG transcription. Honored only if the user has opted in to rag ingest; ignored otherwise. Default true."),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
async function mTALK_ingest_ptt(
|
|
44
|
+
input: z.infer<typeof mTALK_ingest_ptt_input>,
|
|
45
|
+
ctx: MosaddToolContext,
|
|
46
|
+
): Promise<{ ptt_id: string; queued: true; transcription: "queued" | "skipped" | "opted_out" }> {
|
|
47
|
+
readSupabaseEnv();
|
|
48
|
+
if (!input.channel_id && !input.room_id) {
|
|
49
|
+
throw new Error("mTALK_ingest_ptt requires one of channel_id or room_id to route the queued PTT.");
|
|
50
|
+
}
|
|
51
|
+
const prefix = input.channel_id ? `chat:${input.channel_id}` : `room:${input.room_id}`;
|
|
52
|
+
const attachment = await uploadBlob({
|
|
53
|
+
kind: "ptt",
|
|
54
|
+
bytes: decodeBase64Body(input.audio_base64),
|
|
55
|
+
mime: input.mime,
|
|
56
|
+
prefix,
|
|
57
|
+
duration_ms: input.duration_ms,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
ctx.log("debug", "mTALK_ingest_ptt invoking ptt-ingest", { prefix, transcribe: input.transcribe ?? true });
|
|
61
|
+
|
|
62
|
+
// TODO(Lane A): `ptt-ingest` EF not yet deployed. Confirm request/response shape.
|
|
63
|
+
// Expected: persists a queued-PTT message_meta row (message_type:'ptt') with the
|
|
64
|
+
// attachment, then (if rag opt-in) enqueues rag-transcribe → user_embeddings(source_type='ptt').
|
|
65
|
+
const res = await invokeFunction<{
|
|
66
|
+
ptt_id?: string;
|
|
67
|
+
transcription?: "queued" | "skipped" | "opted_out";
|
|
68
|
+
}>("ptt-ingest", {
|
|
69
|
+
attachment,
|
|
70
|
+
channel_id: input.channel_id ?? null,
|
|
71
|
+
room_id: input.room_id ?? null,
|
|
72
|
+
transcribe: input.transcribe ?? true,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
ptt_id: res.ptt_id ?? "",
|
|
77
|
+
queued: true,
|
|
78
|
+
transcription: res.transcription ?? "queued",
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const pttIngestTools: MosaddTool[] = [
|
|
83
|
+
{
|
|
84
|
+
name: "mTALK_ingest_ptt",
|
|
85
|
+
requires: "network",
|
|
86
|
+
description:
|
|
87
|
+
"Capture a finished PTT transmission (an 'over') as a durable, QUEUED PTT message in a channel (mIRC) or room (mROOM), and — if the user has opted in to RAG — transcribe it into searchable knowledge. Pass the clip as base64 + a route (channel_id OR room_id). Complements mTALK_press/release (which only manage the live floor). SCAFFOLD: depends on the not-yet-deployed `ptt-ingest` Edge Function.",
|
|
88
|
+
inputSchema: mTALK_ingest_ptt_input,
|
|
89
|
+
handler: mTALK_ingest_ptt as MosaddTool["handler"],
|
|
90
|
+
},
|
|
91
|
+
];
|