@mosadd/mcp 3.0.0-alpha.7 → 3.0.1
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 +415 -0
- package/LICENSE +21 -201
- package/README.md +79 -40
- package/dist/bin/mcp.js +132 -8
- package/dist/chunk-J2S44U5R.js +4258 -0
- package/dist/index.d.ts +112 -8
- package/dist/index.js +3 -1
- package/package.json +19 -16
- package/src/__tests__/blob-upload.test.ts +93 -0
- package/src/__tests__/channel-e2ee.test.ts +62 -0
- package/src/__tests__/cli.test.ts +47 -0
- package/src/__tests__/fleet-plaintext.test.ts +243 -0
- package/src/__tests__/golden-path.test.ts +4 -2
- package/src/__tests__/integration.test.ts +50 -11
- package/src/__tests__/knowledge-ingest.test.ts +114 -0
- package/src/__tests__/label-room-owner.test.ts +22 -0
- package/src/__tests__/mdm-e2ee.test.ts +36 -2
- package/src/__tests__/mdm-mcp-readable.test.ts +390 -0
- package/src/__tests__/mirc-invite.test.ts +112 -0
- package/src/__tests__/mirc-voice.test.ts +82 -0
- package/src/__tests__/mrag-search-answer.test.ts +42 -0
- package/src/__tests__/mrag-search-diagnostics.test.ts +78 -0
- package/src/__tests__/no-dead-host.test.ts +37 -0
- package/src/__tests__/presence.test.ts +199 -0
- package/src/__tests__/server.test.ts +11 -7
- package/src/__tests__/serverJsonVersion.test.ts +45 -0
- package/src/__tests__/tool-count-consistency.test.ts +259 -0
- package/src/__tests__/voice-fields.test.ts +24 -0
- package/src/bin/mcp.ts +71 -6
- package/src/cli.ts +100 -0
- package/src/crypto/channel-e2ee.ts +288 -0
- package/src/crypto/mdm-session.ts +479 -40
- package/src/index.ts +2 -2
- package/src/providers/blob-upload.ts +162 -0
- package/src/providers/supabase-dm.ts +102 -7
- package/src/providers/supabase-voice.ts +13 -1
- package/src/providers/supabase.ts +121 -10
- package/src/server.ts +102 -12
- package/src/tools/__tests__/ragDeleteFoldsSourceId.test.ts +67 -0
- package/src/tools/actions.ts +166 -0
- package/src/tools/attachments.ts +276 -0
- package/src/tools/capabilities.ts +2 -0
- package/src/tools/channel-payload.ts +69 -0
- package/src/tools/embed.ts +110 -0
- package/src/tools/index.ts +136 -6
- package/src/tools/knowledge-graph.ts +186 -0
- package/src/tools/knowledge.ts +205 -12
- 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 +214 -60
- package/src/tools/mdm-as-agent.ts +137 -0
- package/src/tools/mdm-voice.ts +17 -3
- package/src/tools/mdm.ts +306 -58
- package/src/tools/mirc-edge.ts +12 -6
- package/src/tools/mirc-members.ts +130 -20
- package/src/tools/mirc-messages.ts +109 -40
- package/src/tools/mirc.ts +149 -11
- package/src/tools/mroom-messages.ts +5 -13
- package/src/tools/mtalk.ts +11 -1
- package/src/tools/murl.ts +314 -0
- package/src/tools/presence.ts +442 -0
- package/src/tools/ptt-ingest.ts +99 -0
- package/src/tools/threat.ts +123 -0
- package/src/tools/voice-format.ts +66 -0
- package/src/types.ts +36 -0
- package/src/version.ts +8 -0
- package/dist/chunk-EFTB743G.js +0 -1924
package/src/tools/knowledge.ts
CHANGED
|
@@ -17,10 +17,40 @@
|
|
|
17
17
|
* is enforced at the hub, not in this tool.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
import { createHash } from "node:crypto";
|
|
20
21
|
import { z } from "zod";
|
|
21
22
|
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
22
23
|
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
23
24
|
|
|
25
|
+
// ── source_id: free-form for the caller, a UUID on the wire ──────────────────
|
|
26
|
+
// `user_embeddings.source_id` is a **uuid** column (measured on prod 2026-08-14). This tool has
|
|
27
|
+
// always advertised source_id as "an optional stable id so re-ingests can be grouped" and typed it
|
|
28
|
+
// as a plain string — so the natural thing to pass (a file path, a case number, a docket id) made
|
|
29
|
+
// the INSERT blow up and the whole call came back as an opaque `rag-index (500): Internal error`.
|
|
30
|
+
// Bisected that day: every other field succeeded, `source_id: "bisect-1"` alone failed. It would
|
|
31
|
+
// have hit the legal-corpus ingest on document #1, with an error message pointing nowhere.
|
|
32
|
+
//
|
|
33
|
+
// Rather than push the problem onto every caller ("bring your own UUID"), a non-UUID id is folded
|
|
34
|
+
// into a DETERMINISTIC UUIDv5. Same input → same uuid, for ever, so grouping and mRAG_delete keep
|
|
35
|
+
// working on natural keys; a caller that already passes a real UUID is untouched. The original
|
|
36
|
+
// string is preserved as `metadata.source_ref` so it comes back with search hits and nothing is
|
|
37
|
+
// silently renamed behind the user's back.
|
|
38
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
39
|
+
|
|
40
|
+
/** Fixed namespace for mosadd mRAG source ids. Changing it would orphan every previously grouped source. */
|
|
41
|
+
const SOURCE_ID_NAMESPACE = "1f0b6c2e-6a4d-4f7a-9c1e-0b2d3a4f5e6b";
|
|
42
|
+
|
|
43
|
+
/** RFC 4122 v5 (SHA-1, namespaced). Small enough to keep here rather than add a dependency. */
|
|
44
|
+
function uuidV5(name: string, namespace: string): string {
|
|
45
|
+
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
46
|
+
const digest = createHash("sha1").update(Buffer.concat([ns, Buffer.from(name, "utf8")])).digest();
|
|
47
|
+
const b = Buffer.from(digest.subarray(0, 16));
|
|
48
|
+
b[6] = (b[6] & 0x0f) | 0x50; // version 5
|
|
49
|
+
b[8] = (b[8] & 0x3f) | 0x80; // RFC 4122 variant
|
|
50
|
+
const h = b.toString("hex");
|
|
51
|
+
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
24
54
|
const mRAG_search_input = z.object({
|
|
25
55
|
query: z
|
|
26
56
|
.string()
|
|
@@ -35,13 +65,29 @@ const mRAG_search_input = z.object({
|
|
|
35
65
|
.optional()
|
|
36
66
|
.describe("Max number of source chunks to retrieve and ground the answer in. Default 8."),
|
|
37
67
|
source_types: z
|
|
38
|
-
|
|
68
|
+
// ⚠ MUST stay a superset of everything that can REACH the index, or a filter
|
|
69
|
+
// silently hides data the user owns. Until 2026-08-11 this enum was missing
|
|
70
|
+
// "file" and "ptt" while the index held both — `file` is what mRAG_ingest itself
|
|
71
|
+
// writes (it is the DEFAULT source_type, and "note" is mapped onto it), and `ptt`
|
|
72
|
+
// is what mTALK_ingest_ptt writes once a push-to-talk transcript lands. Measured
|
|
73
|
+
// on prod that day: email 4098 · call 233 · note 187 · message 86 · file 49 · ptt 14
|
|
74
|
+
// — i.e. 63 rows were unreachable by any source_types filter. Add a value HERE
|
|
75
|
+
// whenever a new writer starts stamping a new source_type.
|
|
76
|
+
.array(z.enum(["message", "email", "call", "note", "contact", "file", "ptt"]))
|
|
39
77
|
.optional()
|
|
40
|
-
.describe(
|
|
78
|
+
.describe(
|
|
79
|
+
"Restrict retrieval to these source types. Omit to search everything. 'file' covers anything added with mRAG_ingest (its default, and where 'note' ingests land); 'ptt' covers push-to-talk transcripts ingested by mTALK_ingest_ptt.",
|
|
80
|
+
),
|
|
41
81
|
thread_id: z
|
|
42
82
|
.string()
|
|
43
83
|
.optional()
|
|
44
84
|
.describe("Optional: restrict retrieval to a single thread id (e.g. a dm:/chat: thread)."),
|
|
85
|
+
answer: z
|
|
86
|
+
.boolean()
|
|
87
|
+
.optional()
|
|
88
|
+
.describe(
|
|
89
|
+
"Set true to also get a generated answer (answer field) grounded in the returned sources. Default false: ranked sources only, answer is empty.",
|
|
90
|
+
),
|
|
45
91
|
});
|
|
46
92
|
|
|
47
93
|
interface RagSource {
|
|
@@ -53,10 +99,42 @@ interface RagSource {
|
|
|
53
99
|
created_at: string;
|
|
54
100
|
}
|
|
55
101
|
|
|
102
|
+
/**
|
|
103
|
+
* What rag-query says about HOW it found the sources. Until now the handler kept only answer/sources/chunks_found, so an agent
|
|
104
|
+
* could not tell a complete hybrid result from a keyword-only fallback after the vector stage ran out of time (rag-query ≥ 2026-11-22),
|
|
105
|
+
* nor see which stage was slow. All fields are optional and copied only when the backend sent them — an older backend yields the same
|
|
106
|
+
* three-field result as before.
|
|
107
|
+
*/
|
|
108
|
+
export interface RagSearchDiagnostics {
|
|
109
|
+
/** true when the vector stage did not deliver and the sources come from the keyword fallback (or are empty because both stages failed). */
|
|
110
|
+
partial?: boolean;
|
|
111
|
+
/** search_timeout | embed_failed | search_error */
|
|
112
|
+
partial_reason?: string;
|
|
113
|
+
/** "hybrid" (vector + keyword) or "keyword" (fallback). */
|
|
114
|
+
search_mode?: string;
|
|
115
|
+
/** Set when a model answer was requested but not produced (e.g. "ai_unavailable", "budget"); sources are still returned. */
|
|
116
|
+
degraded?: string;
|
|
117
|
+
/** Per-stage milliseconds measured by rag-query (auth, embed, vector, keyword, rerank, model, total). */
|
|
118
|
+
timing?: Record<string, number | string>;
|
|
119
|
+
/** Normalised stage summary: embed_ms, wektor_ms, slowa_ms, rerank_ms, synteza_ms, total_ms and per-stage status (ok | limit | blad | pominiety | niedostepny). */
|
|
120
|
+
stages?: Record<string, unknown>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const DIAGNOSTIC_KEYS = ["partial", "partial_reason", "search_mode", "degraded", "timing", "stages"] as const;
|
|
124
|
+
|
|
125
|
+
function ragDiagnostics(data: RagSearchDiagnostics): RagSearchDiagnostics {
|
|
126
|
+
const out: Record<string, unknown> = {};
|
|
127
|
+
for (const key of DIAGNOSTIC_KEYS) {
|
|
128
|
+
const value = data[key];
|
|
129
|
+
if (value !== undefined && value !== null) out[key] = value;
|
|
130
|
+
}
|
|
131
|
+
return out as RagSearchDiagnostics;
|
|
132
|
+
}
|
|
133
|
+
|
|
56
134
|
async function mRAG_search(
|
|
57
135
|
input: z.infer<typeof mRAG_search_input>,
|
|
58
136
|
ctx: MosaddToolContext,
|
|
59
|
-
): Promise<{ answer: string; sources: RagSource[]; chunks_found: number }> {
|
|
137
|
+
): Promise<{ answer: string; sources: RagSource[]; chunks_found: number } & RagSearchDiagnostics> {
|
|
60
138
|
readSupabaseEnv();
|
|
61
139
|
ctx.log("debug", "mRAG_search via rag-query", { top_k: input.top_k ?? 8 });
|
|
62
140
|
|
|
@@ -64,21 +142,42 @@ async function mRAG_search(
|
|
|
64
142
|
answer?: string;
|
|
65
143
|
sources?: RagSource[];
|
|
66
144
|
chunks_found?: number;
|
|
67
|
-
};
|
|
145
|
+
} & RagSearchDiagnostics;
|
|
68
146
|
const data = await invokeFunction<RagQueryResponse>("rag-query", {
|
|
69
147
|
query: input.query,
|
|
70
148
|
top_k: input.top_k ?? 8,
|
|
71
149
|
source_types: input.source_types ?? null,
|
|
72
150
|
thread_id: input.thread_id ?? null,
|
|
151
|
+
answer: input.answer ?? false,
|
|
73
152
|
});
|
|
74
153
|
|
|
75
154
|
return {
|
|
76
155
|
answer: data.answer ?? "",
|
|
77
156
|
sources: data.sources ?? [],
|
|
78
157
|
chunks_found: data.chunks_found ?? (data.sources?.length ?? 0),
|
|
158
|
+
...ragDiagnostics(data),
|
|
79
159
|
};
|
|
80
160
|
}
|
|
81
161
|
|
|
162
|
+
/**
|
|
163
|
+
* A person / company / address a document involves.
|
|
164
|
+
*
|
|
165
|
+
* Polymorphic on purpose: mail carries an address, mDM carries an identity UUID, a court filing
|
|
166
|
+
* carries a party name — all three flow through the SAME `{ kind, ref, label }` shape so one
|
|
167
|
+
* filter matches any of them. Mirrors `Party` in the backend's _shared/enrichRagMetadata.ts.
|
|
168
|
+
*/
|
|
169
|
+
const PartyArg = z.object({
|
|
170
|
+
kind: z
|
|
171
|
+
.enum(["identity", "account", "email", "phone", "url", "unknown"])
|
|
172
|
+
.describe("How to read `ref`: a mosadd identity UUID, an account id, an email address, a phone number, a URL, or a plain name ('unknown')."),
|
|
173
|
+
ref: z
|
|
174
|
+
.string()
|
|
175
|
+
.min(1)
|
|
176
|
+
.max(400)
|
|
177
|
+
.describe("The stable key this party is recognised by — identity UUID, email address, phone number, or the party's canonical name. Use the SAME ref for the same party across documents; that is what merges them into one node in the knowledge graph."),
|
|
178
|
+
label: z.string().max(300).nullish().describe("Human name to display for this party."),
|
|
179
|
+
});
|
|
180
|
+
|
|
82
181
|
const mRAG_ingest_input = z.object({
|
|
83
182
|
content_text: z
|
|
84
183
|
.string()
|
|
@@ -89,9 +188,51 @@ const mRAG_ingest_input = z.object({
|
|
|
89
188
|
.enum(["file", "note", "message", "email", "contact", "call"])
|
|
90
189
|
.optional()
|
|
91
190
|
.describe("What kind of source this is. Default 'file' (a document/note). Use 'note' for ad-hoc text."),
|
|
92
|
-
source_id: z
|
|
191
|
+
source_id: z
|
|
192
|
+
.string()
|
|
193
|
+
.max(500)
|
|
194
|
+
.optional()
|
|
195
|
+
.describe(
|
|
196
|
+
"Optional stable id for the source so re-ingests of the SAME document group together (and can be removed later with mRAG_delete). Any string works — a file path, a case number, a checksum: a non-UUID is folded into a stable id derived from it, deterministically, and the original is kept as metadata.source_ref.",
|
|
197
|
+
),
|
|
93
198
|
thread_id: z.string().optional().describe("Optional thread id to associate this knowledge with (e.g. a dm:/chat: thread)."),
|
|
94
199
|
title: z.string().max(300).optional().describe("Optional human title, stored in metadata."),
|
|
200
|
+
// ── Graph + file-manager fields ────────────────────────────────────────────
|
|
201
|
+
// Added 2026-08-14. The backend (rag-index → enrichRagMetadata) has accepted all of these
|
|
202
|
+
// since 2026-07-19; THIS tool was the only ingest path that dropped them, so everything
|
|
203
|
+
// pushed through MCP landed with no parties and no event date — and therefore contributed
|
|
204
|
+
// NOTHING to mRAG_graph_*, which builds its nodes from exactly these fields. A corpus could
|
|
205
|
+
// be fully indexed and its graph still come back empty. See the note on the tool below.
|
|
206
|
+
sender: PartyArg.optional().describe(
|
|
207
|
+
"Who the document is FROM (author, filing party, sender). Becomes a node in the knowledge graph — without it this document adds no party to mRAG_graph_overview.",
|
|
208
|
+
),
|
|
209
|
+
recipient: PartyArg.optional().describe(
|
|
210
|
+
"Who the document is TO (addressee, court, counterparty). Becomes a node in the knowledge graph, connected to `sender`.",
|
|
211
|
+
),
|
|
212
|
+
occurred_at: z
|
|
213
|
+
.string()
|
|
214
|
+
.optional()
|
|
215
|
+
.describe("ISO-8601 timestamp of WHEN the document happened (letter date, filing date, email Date header) — not when you indexed it. Drives mRAG_graph_timeline; defaults to now if omitted, which makes a 2019 filing look like it happened today."),
|
|
216
|
+
direction: z
|
|
217
|
+
.enum(["in", "out", "self"])
|
|
218
|
+
.optional()
|
|
219
|
+
.describe("Direction relative to the account owner: received, sent, or the owner's own note."),
|
|
220
|
+
labels: z
|
|
221
|
+
.array(z.string().max(120))
|
|
222
|
+
.max(50)
|
|
223
|
+
.optional()
|
|
224
|
+
.describe("Free-text tags to attach (e.g. a case id, a jurisdiction) for later filtering."),
|
|
225
|
+
name: z
|
|
226
|
+
.string()
|
|
227
|
+
.max(400)
|
|
228
|
+
.optional()
|
|
229
|
+
.describe("Original filename, if this came from a file (e.g. 'pozew-2019-03-11.pdf'). Its extension is what classifies the row as a document/image/audio in the file view. Distinct from `title`, which is free prose."),
|
|
230
|
+
mime: z.string().max(200).optional().describe("MIME type of the original file, if known."),
|
|
231
|
+
size: z.number().int().nonnegative().optional().describe("Size of the original file in bytes, if known."),
|
|
232
|
+
metadata: z
|
|
233
|
+
.record(z.string(), z.unknown())
|
|
234
|
+
.optional()
|
|
235
|
+
.describe("Any extra fields to store alongside the row (case id, docket number, jurisdiction, file path, checksum, sensitivity flag…). Stored verbatim and returned with search hits. NOTE: this is stored server-side in plaintext like the content itself."),
|
|
95
236
|
});
|
|
96
237
|
|
|
97
238
|
async function mRAG_ingest(
|
|
@@ -101,13 +242,40 @@ async function mRAG_ingest(
|
|
|
101
242
|
readSupabaseEnv();
|
|
102
243
|
// rag-index accepts a fixed source_type set; map "note" → "file".
|
|
103
244
|
const backendType = input.source_type === "note" ? "file" : (input.source_type ?? "file");
|
|
104
|
-
ctx.log("debug", "mRAG_ingest via rag-index", {
|
|
245
|
+
ctx.log("debug", "mRAG_ingest via rag-index", {
|
|
246
|
+
source_type: backendType,
|
|
247
|
+
has_parties: Boolean(input.sender || input.recipient),
|
|
248
|
+
has_occurred_at: Boolean(input.occurred_at),
|
|
249
|
+
});
|
|
250
|
+
// The enrichment fields are TOP-LEVEL on the rag-index request, not inside `metadata` — the
|
|
251
|
+
// function destructures them by name and hands them to enrichRagMetadata, which is what stamps
|
|
252
|
+
// metadata.sender / .recipient / .occurred_at in the canonical shape kg_refresh_me reads.
|
|
253
|
+
// Passing them inside `metadata` would land them via `passthrough` and happen to work today,
|
|
254
|
+
// but it would bypass the canonical stamping (and its `sender.ref` validation) — so send them
|
|
255
|
+
// where the contract says they go. Undefined keys are omitted rather than sent as null, so a
|
|
256
|
+
// caller that passes none produces byte-identical requests to before this change.
|
|
257
|
+
const rawSourceId = input.source_id?.trim() || null;
|
|
258
|
+
const sourceId = rawSourceId && !UUID_RE.test(rawSourceId) ? uuidV5(rawSourceId, SOURCE_ID_NAMESPACE) : rawSourceId;
|
|
105
259
|
const data = await invokeFunction<{ indexed?: number; chunk_count?: number }>("rag-index", {
|
|
106
260
|
source_type: backendType,
|
|
107
|
-
source_id:
|
|
261
|
+
source_id: sourceId,
|
|
108
262
|
thread_id: input.thread_id ?? null,
|
|
109
263
|
content_text: input.content_text,
|
|
110
|
-
|
|
264
|
+
...(input.sender ? { sender: input.sender } : {}),
|
|
265
|
+
...(input.recipient ? { recipient: input.recipient } : {}),
|
|
266
|
+
...(input.occurred_at ? { occurred_at: input.occurred_at } : {}),
|
|
267
|
+
...(input.direction ? { direction: input.direction } : {}),
|
|
268
|
+
...(input.labels?.length ? { labels: input.labels } : {}),
|
|
269
|
+
...(input.name ? { name: input.name } : {}),
|
|
270
|
+
...(input.mime ? { mime: input.mime } : {}),
|
|
271
|
+
...(typeof input.size === "number" ? { size: input.size } : {}),
|
|
272
|
+
metadata: {
|
|
273
|
+
...(input.metadata ?? {}),
|
|
274
|
+
...(input.title ? { title: input.title } : {}),
|
|
275
|
+
// Only when we actually rewrote it — a caller that passed a real UUID sees no extra key.
|
|
276
|
+
...(rawSourceId && rawSourceId !== sourceId ? { source_ref: rawSourceId } : {}),
|
|
277
|
+
ingested_via: "mRAG_ingest",
|
|
278
|
+
},
|
|
111
279
|
});
|
|
112
280
|
return { indexed: data.indexed ?? 0, chunk_count: data.chunk_count ?? 0 };
|
|
113
281
|
}
|
|
@@ -147,10 +315,27 @@ async function mRAG_delete(
|
|
|
147
315
|
ctx: MosaddToolContext,
|
|
148
316
|
): Promise<{ ok: true; deleted: number; source_id: string | null; thread_id: string | null }> {
|
|
149
317
|
readSupabaseEnv();
|
|
150
|
-
|
|
318
|
+
// ⛔ TĘ SAMĄ FUNKCJĘ MUSI PRZEJŚĆ KASOWANIE, CO INDEKSOWANIE (2026-08-28).
|
|
319
|
+
//
|
|
320
|
+
// `mRAG_ingest` foldował nie-UUID przez `uuidV5`, a `mRAG_delete` wysyłał SUROWY napis prosto do
|
|
321
|
+
// kolumny UUID — więc `rag-sources` odpowiadał `500: invalid input syntax for type uuid`.
|
|
322
|
+
// Skutek: dokument zaindeksowany pod naturalnym kluczem (numer sprawy, ścieżka pliku, threadId
|
|
323
|
+
// Gmaila) dawało się dodać, ale **NIGDY nie dawało się go usunąć tym samym identyfikatorem**.
|
|
324
|
+
// Dwie połowy tej samej rury nie zgadzały się ze sobą.
|
|
325
|
+
//
|
|
326
|
+
// I nie jest to niedopatrzenie w cieniu: komentarz przy foldowaniu (linie 30-37) obiecuje wprost
|
|
327
|
+
// „so grouping and mRAG_delete keep working on natural keys", a opis narzędzia mówi userowi
|
|
328
|
+
// „can later be removed with mRAG_delete". Obietnica była w dwóch miejscach, implementacja
|
|
329
|
+
// w jednym. Zmierzone na żywo: ingest `DIAG-…-a1b2c3` → indexed 1; delete tego samego id → 500.
|
|
330
|
+
//
|
|
331
|
+
// Boli to najbardziej przy korpusie, bo tam naturalne klucze są jedynym sposobem na dedup przy
|
|
332
|
+
// ponownym wczytaniu — a Dyspozytor mieli akta właśnie tak.
|
|
333
|
+
const rawId = input.source_id?.trim() || null;
|
|
334
|
+
const sourceId = rawId && !UUID_RE.test(rawId) ? uuidV5(rawId, SOURCE_ID_NAMESPACE) : rawId;
|
|
335
|
+
ctx.log("debug", "mRAG_delete via rag-sources", { source_id: sourceId, source_ref: rawId, thread_id: input.thread_id });
|
|
151
336
|
return await invokeFunction("rag-sources", {
|
|
152
337
|
action: "delete",
|
|
153
|
-
source_id:
|
|
338
|
+
source_id: sourceId,
|
|
154
339
|
thread_id: input.thread_id ?? null,
|
|
155
340
|
});
|
|
156
341
|
}
|
|
@@ -158,22 +343,28 @@ async function mRAG_delete(
|
|
|
158
343
|
export const knowledgeTools: MosaddTool[] = [
|
|
159
344
|
{
|
|
160
345
|
name: "mRAG_ingest",
|
|
346
|
+
title: "Ingest into memory",
|
|
347
|
+
annotations: { readOnlyHint: false },
|
|
161
348
|
requires: "network",
|
|
162
349
|
description:
|
|
163
|
-
"Add text to the USER'S OWN private knowledge base so mRAG_search can recall it later. Pass content_text (a note, document, transcript, pasted page); it is semantically chunked, embedded (1536-d) and stored in the per-user vector index mRAG_search reads. Returns how many chunks were indexed. NOTE: indexed content
|
|
350
|
+
"Add text to the USER'S OWN private knowledge base so mRAG_search can recall it later. Pass content_text (a note, document, transcript, pasted page); it is semantically chunked, embedded (1536-d) and stored in the per-user vector index mRAG_search reads. Returns how many chunks were indexed. ⚠ IF YOU ARE INDEXING A CORPUS you want to TRAVERSE (who is connected to whom, when), also pass sender / recipient / occurred_at: the knowledge graph builds its nodes from those fields alone, so documents ingested without them are searchable but contribute NOTHING to mRAG_graph_overview / _neighbors / _timeline — the graph comes back empty however many documents you loaded. Reuse the same party `ref` across documents to merge them into one node. NOTE: indexed content and metadata are stored server-side in plaintext — NOT covered by the zero-knowledge / E2EE guarantee. Only ingest what the user opted to make searchable.",
|
|
164
351
|
inputSchema: mRAG_ingest_input,
|
|
165
352
|
handler: mRAG_ingest as MosaddTool["handler"],
|
|
166
353
|
},
|
|
167
354
|
{
|
|
168
355
|
name: "mRAG_search",
|
|
356
|
+
title: "Search memory",
|
|
357
|
+
annotations: { readOnlyHint: true },
|
|
169
358
|
requires: "network",
|
|
170
359
|
description:
|
|
171
|
-
"Search and answer questions over the USER'S OWN mosadd data (messages, emails, calls, notes) with a private per-user RAG index — hybrid vector + keyword retrieval, reranked, grounded in cited sources (no fabrication). Use it to recall 'what did X say about Y', summarize a thread, or pull facts the user has received.
|
|
360
|
+
"Search and answer questions over the USER'S OWN mosadd data (messages, emails, calls, notes) with a private per-user RAG index — hybrid vector + keyword retrieval, reranked, grounded in cited sources (no fabrication). Use it to recall 'what did X say about Y', summarize a thread, or pull facts the user has received. By DEFAULT (via MCP) it returns the ranked source snippets only (answer_mode retrieve_only): fast, no model call; `answer` is empty or a short status note starting with '[mRAG' that names the stages and their times. Pass answer:true to also get a generated answer grounded in those sources (slower, uses the model budget). If the vector stage runs out of time the call still succeeds: the sources come from a keyword fallback and the result carries partial:true, partial_reason and search_mode:'keyword' (never a silent empty list); `timing` and `stages` give the milliseconds of every stage. This is agent memory (mRAG = RAG over your own data) over the user's communications, available outside the mosadd app. NOTE: RAG requires content to be indexed server-side in plaintext, so anything searchable here is NOT covered b",
|
|
172
361
|
inputSchema: mRAG_search_input,
|
|
173
362
|
handler: mRAG_search as MosaddTool["handler"],
|
|
174
363
|
},
|
|
175
364
|
{
|
|
176
365
|
name: "mRAG_list_sources",
|
|
366
|
+
title: "List memory sources",
|
|
367
|
+
annotations: { readOnlyHint: true },
|
|
177
368
|
requires: "network",
|
|
178
369
|
description:
|
|
179
370
|
"List what is currently indexed in the user's private knowledge base, grouped by source (source_type, source_id, thread_id, title) with per-source chunk counts and first/last indexed timestamps. Use it to see what mRAG_search can recall, and to find a source_id to remove with mRAG_delete. Owner-scoped.",
|
|
@@ -182,6 +373,8 @@ export const knowledgeTools: MosaddTool[] = [
|
|
|
182
373
|
},
|
|
183
374
|
{
|
|
184
375
|
name: "mRAG_delete",
|
|
376
|
+
title: "Delete memory source",
|
|
377
|
+
annotations: { destructiveHint: true },
|
|
185
378
|
requires: "network",
|
|
186
379
|
description:
|
|
187
380
|
"Remove indexed content from the user's knowledge base by source_id or thread_id (from mRAG_list_sources). Deletes every embedded chunk for that source so mRAG_search can no longer recall it. Requires source_id or thread_id (will not purge the whole index). Returns the number of chunks deleted. Owner-scoped.",
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mAYL agent inboxes — disposable, two-way mailboxes an agent can mint for itself.
|
|
3
|
+
*
|
|
4
|
+
* Backed by the mosADD `mayl-agentbox` Edge Function (owner-scoped CRUD over
|
|
5
|
+
* public.mayl_agent_boxes) + the mp0st-inbound-webhook receive path. A box is a REAL
|
|
6
|
+
* address `agent-<hex>@mosadd.com` that can both SEND (via mAYL_send's from-selector)
|
|
7
|
+
* and — since 2026-08-06 — RECEIVE (inbound mail resolves the box → the owner account).
|
|
8
|
+
*
|
|
9
|
+
* This is the mosADD answer to AgentMail's `create_inbox`: the agent gets its own real
|
|
10
|
+
* inbox on demand, but inside an E2EE messenger where the agent is already a first-class
|
|
11
|
+
* contact and every send carries cryptographic provenance — not a bare third-party API.
|
|
12
|
+
*
|
|
13
|
+
* Auth is identical to every other mAYL tool: invokeFunction sends the caller's
|
|
14
|
+
* `Authorization: Bearer <userJwt>`, which mayl-agentbox validates via requireUser
|
|
15
|
+
* (auth.uid() owner-scoping). No new auth surface.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
20
|
+
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
21
|
+
|
|
22
|
+
// ---- Schemas ----
|
|
23
|
+
|
|
24
|
+
const BoxId = z.string().min(1).describe("Agent-box id (UUID) from mAYL_agentbox_provision or mAYL_agentbox_list.");
|
|
25
|
+
|
|
26
|
+
const agentbox_provision_input = z.object({
|
|
27
|
+
display_name: z
|
|
28
|
+
.string()
|
|
29
|
+
.max(120)
|
|
30
|
+
.optional()
|
|
31
|
+
.describe("Optional human label for the box (e.g. 'signup catcher'). Max 120 chars."),
|
|
32
|
+
agent_id: z
|
|
33
|
+
.string()
|
|
34
|
+
.optional()
|
|
35
|
+
.describe("Optional identity id to attribute the box to — must be an agent identity you own."),
|
|
36
|
+
kind: z
|
|
37
|
+
.enum(["ephemeral", "persistent"])
|
|
38
|
+
.optional()
|
|
39
|
+
.describe("'ephemeral' (default) auto-expires + is reaped; 'persistent' never expires."),
|
|
40
|
+
ttl_seconds: z
|
|
41
|
+
.number()
|
|
42
|
+
.int()
|
|
43
|
+
.positive()
|
|
44
|
+
.max(86_400)
|
|
45
|
+
.optional()
|
|
46
|
+
.describe("Lifetime for an ephemeral box, in seconds. Default 600 (10 min). Max 86400 (24 h). Ignored for persistent."),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const agentbox_list_input = z.object({});
|
|
50
|
+
|
|
51
|
+
const agentbox_release_input = z.object({ id: BoxId });
|
|
52
|
+
|
|
53
|
+
const agentbox_extend_input = z.object({
|
|
54
|
+
id: BoxId,
|
|
55
|
+
ttl_seconds: z
|
|
56
|
+
.number()
|
|
57
|
+
.int()
|
|
58
|
+
.positive()
|
|
59
|
+
.max(86_400)
|
|
60
|
+
.optional()
|
|
61
|
+
.describe("New lifetime from NOW, in seconds. Default 600 (10 min). Max 86400 (24 h). Ephemeral boxes only."),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// ---- Handlers ----
|
|
65
|
+
|
|
66
|
+
async function agentbox_provision(
|
|
67
|
+
input: z.infer<typeof agentbox_provision_input>,
|
|
68
|
+
ctx: MosaddToolContext,
|
|
69
|
+
): Promise<Record<string, unknown>> {
|
|
70
|
+
readSupabaseEnv();
|
|
71
|
+
ctx.log("debug", "mAYL_agentbox_provision invoking mayl-agentbox", { kind: input.kind ?? "ephemeral" });
|
|
72
|
+
return await invokeFunction("mayl-agentbox", {
|
|
73
|
+
action: "create",
|
|
74
|
+
display_name: input.display_name ?? null,
|
|
75
|
+
agent_id: input.agent_id ?? null,
|
|
76
|
+
kind: input.kind ?? "ephemeral",
|
|
77
|
+
ttl_seconds: input.ttl_seconds ?? null,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function agentbox_list(
|
|
82
|
+
_input: z.infer<typeof agentbox_list_input>,
|
|
83
|
+
ctx: MosaddToolContext,
|
|
84
|
+
): Promise<Record<string, unknown>> {
|
|
85
|
+
readSupabaseEnv();
|
|
86
|
+
ctx.log("debug", "mAYL_agentbox_list invoking mayl-agentbox", {});
|
|
87
|
+
return await invokeFunction("mayl-agentbox", { action: "list" });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function agentbox_release(
|
|
91
|
+
input: z.infer<typeof agentbox_release_input>,
|
|
92
|
+
ctx: MosaddToolContext,
|
|
93
|
+
): Promise<Record<string, unknown>> {
|
|
94
|
+
readSupabaseEnv();
|
|
95
|
+
ctx.log("debug", "mAYL_agentbox_release invoking mayl-agentbox", { id: input.id });
|
|
96
|
+
return await invokeFunction("mayl-agentbox", { action: "release", id: input.id });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function agentbox_extend(
|
|
100
|
+
input: z.infer<typeof agentbox_extend_input>,
|
|
101
|
+
ctx: MosaddToolContext,
|
|
102
|
+
): Promise<Record<string, unknown>> {
|
|
103
|
+
readSupabaseEnv();
|
|
104
|
+
ctx.log("debug", "mAYL_agentbox_extend invoking mayl-agentbox", { id: input.id });
|
|
105
|
+
return await invokeFunction("mayl-agentbox", {
|
|
106
|
+
action: "extend",
|
|
107
|
+
id: input.id,
|
|
108
|
+
ttl_seconds: input.ttl_seconds ?? null,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ---- Registration ----
|
|
113
|
+
|
|
114
|
+
export const mailAgentboxTools: MosaddTool[] = [
|
|
115
|
+
{
|
|
116
|
+
name: "mAYL_agentbox_provision",
|
|
117
|
+
title: "Provision disposable inbox",
|
|
118
|
+
annotations: { readOnlyHint: false },
|
|
119
|
+
requires: "network",
|
|
120
|
+
description:
|
|
121
|
+
"Mint the agent its OWN real, disposable email inbox at agent-<hex>@mosadd.com that can SEND and RECEIVE. Default ephemeral with a 10-minute TTL (auto-expires + is reaped); pass kind:'persistent' for a permanent box, or ttl_seconds (max 86400) for a custom lifetime. Optional display_name + agent_id. Returns the box {id, address, expires_at}. Use the address to catch signup/verification codes or replies, then mAYL_list (filter by the box address) + mAYL_view to read what arrived. Owner-scoped; max 25 active boxes per account.",
|
|
122
|
+
inputSchema: agentbox_provision_input,
|
|
123
|
+
handler: agentbox_provision as MosaddTool["handler"],
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: "mAYL_agentbox_list",
|
|
127
|
+
title: "List disposable inboxes",
|
|
128
|
+
annotations: { readOnlyHint: true },
|
|
129
|
+
requires: "network",
|
|
130
|
+
description:
|
|
131
|
+
"List your active agent inboxes (address, display_name, kind, agent_id, expires_at), newest first. Owner-scoped.",
|
|
132
|
+
inputSchema: agentbox_list_input,
|
|
133
|
+
handler: agentbox_list as MosaddTool["handler"],
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: "mAYL_agentbox_release",
|
|
137
|
+
title: "Release disposable inbox",
|
|
138
|
+
annotations: { destructiveHint: true },
|
|
139
|
+
requires: "network",
|
|
140
|
+
description:
|
|
141
|
+
"Release (delete) one of your agent inboxes by id — frees the address immediately so it stops receiving. Owner-scoped.",
|
|
142
|
+
inputSchema: agentbox_release_input,
|
|
143
|
+
handler: agentbox_release as MosaddTool["handler"],
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: "mAYL_agentbox_extend",
|
|
147
|
+
title: "Extend disposable inbox",
|
|
148
|
+
annotations: { readOnlyHint: false },
|
|
149
|
+
requires: "network",
|
|
150
|
+
description:
|
|
151
|
+
"Extend an EPHEMERAL agent inbox's lifetime by id (ttl_seconds counted from NOW, max 24 h). Persistent boxes never expire and cannot be extended. Owner-scoped.",
|
|
152
|
+
inputSchema: agentbox_extend_input,
|
|
153
|
+
handler: agentbox_extend as MosaddTool["handler"],
|
|
154
|
+
},
|
|
155
|
+
];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// mail-aliases.ts — back-compat mp0st_* aliases for mAYL_* tools
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// The mosADD re-arch (2026-06-27) renamed the email module from `mp0st` to
|
|
5
|
+
// `mAYL`. The canonical tool names are mAYL_* — see
|
|
6
|
+
// `tools/mail.ts`. THIS module exposes back-compat aliases so any agent already
|
|
7
|
+
// wired to mp0st_send / mp0st_view / etc. KEEPS WORKING in this release.
|
|
8
|
+
//
|
|
9
|
+
// Rule: never drop an alias in the release that adds its replacement — live
|
|
10
|
+
// agents would 404. mp0st_* aliases stay through alpha.25 and the next minor;
|
|
11
|
+
// flag for removal goes into the a later release's notes.
|
|
12
|
+
// =============================================================================
|
|
13
|
+
|
|
14
|
+
import type { MosaddTool } from "../types.js";
|
|
15
|
+
import { mailTools } from "./mail.js";
|
|
16
|
+
|
|
17
|
+
/** Same handlers/schemas as `mailTools`, but registered under the legacy mp0st_* names. */
|
|
18
|
+
export const mailAliasTools: MosaddTool[] = mailTools.map((tool) => ({
|
|
19
|
+
...tool,
|
|
20
|
+
name: tool.name.replace(/^mAYL_/, "mp0st_"),
|
|
21
|
+
description:
|
|
22
|
+
`[DEPRECATED — use ${tool.name} instead. mp0st_* aliases stay through alpha.25 ` +
|
|
23
|
+
`for back-compat; will be removed in a later alpha.] ` +
|
|
24
|
+
tool.description,
|
|
25
|
+
}));
|
|
@@ -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://api.mosadd.com";
|
|
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).
|
|
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
|
+
];
|