@mosadd/mcp 3.0.0-alpha.47 → 3.0.0-alpha.49
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-XTQMZ6K7.js → chunk-MGF7BV3M.js} +41 -23
- package/dist/index.js +1 -1
- package/package.json +73 -73
- package/src/__tests__/knowledge-ingest.test.ts +114 -114
- package/src/__tests__/presence.test.ts +190 -190
- package/src/__tests__/serverJsonVersion.test.ts +45 -45
- package/src/providers/supabase.ts +231 -231
- package/src/server.ts +162 -162
- package/src/tools/__tests__/ragDeleteFoldsSourceId.test.ts +67 -67
- package/src/tools/knowledge-graph.ts +186 -186
- package/src/tools/mail-agentbox.ts +155 -155
- package/src/tools/mcall.ts +216 -216
- package/src/tools/mdm-as-agent.ts +126 -126
- package/src/tools/mdm-voice.ts +220 -220
- package/src/tools/mdm.ts +495 -494
- package/src/tools/mirc-messages.ts +186 -185
- package/src/tools/murl.ts +314 -314
- package/src/tools/presence.ts +442 -414
- package/src/tools/ptt-ingest.ts +99 -99
- package/src/tools/threat.ts +123 -123
- package/src/tools/voice-format.ts +28 -0
- package/src/version.ts +8 -8
- 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 -310
package/src/tools/murl.ts
CHANGED
|
@@ -1,314 +1,314 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mURL — IRC-for-URLs: real-time chat attached to any web DOMAIN, AGENT-NATIVE.
|
|
3
|
-
*
|
|
4
|
-
* Same mosadd-edge Cloudflare Worker / Durable Object backend as mIRC edge, but the
|
|
5
|
-
* channel id is the URL SLUG: host("."→"-") + path("/"→"__") (RFC-0004). A bare domain
|
|
6
|
-
* → the domain room; a full URL with a path → a per-PAGE room (the per-article ask).
|
|
7
|
-
* Auto-created on first activity (status "open"); the domain owner can verify/claim the
|
|
8
|
-
* whole domain (a domain block covers all its page rooms).
|
|
9
|
-
*
|
|
10
|
-
* THE WEDGE: every prior "chat on a web page" (Google Sidewiki, Genius, Hypothes.is,
|
|
11
|
-
* HERE.fm) died on the empty-room cold-start because they were HUMAN-ONLY — you arrive,
|
|
12
|
-
* nobody's there, you leave. mURL is agent-native: an AI agent researching a domain can
|
|
13
|
-
* READ the channel (human + agent context — "is this a scam?", "promo code here") and
|
|
14
|
-
* WRITE findings back, so the room is never empty. First per-domain chat where agents are
|
|
15
|
-
* first-class citizens.
|
|
16
|
-
*
|
|
17
|
-
* Auth: MOSADD_API_KEY (hub key) for read/post; presence is public.
|
|
18
|
-
*/
|
|
19
|
-
import { z } from "zod";
|
|
20
|
-
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
21
|
-
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
22
|
-
|
|
23
|
-
const DEFAULT_EDGE_URL = "https://mosadd-edge.mr-brics-33.workers.dev";
|
|
24
|
-
function edgeUrl(): string {
|
|
25
|
-
return process.env.MOSADD_EDGE_URL?.replace(/\/$/, "") ?? DEFAULT_EDGE_URL;
|
|
26
|
-
}
|
|
27
|
-
function hubKey(): string {
|
|
28
|
-
const key = process.env.MOSADD_API_KEY ?? process.env.MOSADD_HUB_KEY ?? "";
|
|
29
|
-
if (!key) throw new Error("MOSADD_API_KEY required for mURL tools (see `mosadd login` / hub-keys).");
|
|
30
|
-
return key;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** A domain OR full URL → { domain, slug }. mURL is keyed PER-URL (RFC-0004):
|
|
34
|
-
* slug = host("."→"-") + each path segment ("/"→"__"); scheme, query, fragment and
|
|
35
|
-
* trailing slash are stripped and segments are sanitised to [a-z0-9-]. A bare domain
|
|
36
|
-
* (no path) yields the DOMAIN room (back-compat); a URL with a path yields a PER-PAGE
|
|
37
|
-
* room. `domain` (host only) is returned for status/branding — a domain block covers
|
|
38
|
-
* every page room under it. */
|
|
39
|
-
function urlToSlug(input: string): { domain: string; slug: string } {
|
|
40
|
-
let s = String(input).trim().toLowerCase();
|
|
41
|
-
s = s.replace(/^[a-z]+:\/\//, "").replace(/[?#].*$/, ""); // strip scheme + query + fragment
|
|
42
|
-
const slash = s.indexOf("/");
|
|
43
|
-
let host = (slash >= 0 ? s.slice(0, slash) : s).replace(/:\d+$/, "");
|
|
44
|
-
if (host.startsWith("www.")) host = host.slice(4);
|
|
45
|
-
if (!host || !/^[a-z0-9-]+(\.[a-z0-9-]+)+$/.test(host)) {
|
|
46
|
-
throw new Error(`Invalid URL: "${input}" — pass a domain like "example.com" or a full URL.`);
|
|
47
|
-
}
|
|
48
|
-
const segs = (slash >= 0 ? s.slice(slash) : "")
|
|
49
|
-
.split("/")
|
|
50
|
-
.map((seg) => seg.replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, ""))
|
|
51
|
-
.filter(Boolean);
|
|
52
|
-
const base = host.replace(/\./g, "-");
|
|
53
|
-
return { domain: host, slug: segs.length ? `${base}__${segs.join("__")}` : base };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const DomainArg = z
|
|
57
|
-
.string()
|
|
58
|
-
.min(3)
|
|
59
|
-
.max(2048)
|
|
60
|
-
.describe("A domain ('example.com') or a full URL. Keyed PER-URL: a bare domain → the domain room; a URL with a path (e.g. 'site.com/articles/abc') → that page's own room.");
|
|
61
|
-
|
|
62
|
-
// ── read ──────────────────────────────────────────────────────────────────────
|
|
63
|
-
const mURL_read_channel_input = z.object({
|
|
64
|
-
domain: DomainArg,
|
|
65
|
-
limit: z.number().int().min(1).max(100).optional().describe("Recent messages to return (max 100). Default 50."),
|
|
66
|
-
});
|
|
67
|
-
async function mURL_read_channel(
|
|
68
|
-
input: z.infer<typeof mURL_read_channel_input>,
|
|
69
|
-
ctx: MosaddToolContext,
|
|
70
|
-
): Promise<{ domain: string; messages: Array<{ id: string; from: string | null; text: string; timestamp: number }> }> {
|
|
71
|
-
const { domain, slug } = urlToSlug(input.domain);
|
|
72
|
-
const limit = input.limit ?? 50;
|
|
73
|
-
ctx.log("debug", "mURL_read_channel", { domain });
|
|
74
|
-
const r = await fetch(`${edgeUrl()}/c/${slug}/history?limit=${limit}`, {
|
|
75
|
-
headers: { Authorization: `Bearer ${hubKey()}` },
|
|
76
|
-
});
|
|
77
|
-
if (!r.ok) {
|
|
78
|
-
const e = await r.text().catch(() => "");
|
|
79
|
-
throw new Error(`mosadd-edge ${r.status}: ${e.slice(0, 200)}`);
|
|
80
|
-
}
|
|
81
|
-
const data = (await r.json()) as { messages?: Array<{ id: string; ts: number; from?: string | null; text: string }> };
|
|
82
|
-
return {
|
|
83
|
-
domain,
|
|
84
|
-
messages: (data.messages ?? []).map((m) => ({ id: m.id, from: m.from ?? null, text: m.text, timestamp: m.ts })),
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// ── post ──────────────────────────────────────────────────────────────────────
|
|
89
|
-
const mURL_post_input = z.object({
|
|
90
|
-
domain: DomainArg,
|
|
91
|
-
text: z.string().min(1).max(2000).describe("Message body (max 2000 chars, up to 3 lines — Worker-enforced)."),
|
|
92
|
-
from: z.string().max(120).optional().describe("Sender hint shown to others (defaults to the hub-key owner / your agent name)."),
|
|
93
|
-
});
|
|
94
|
-
async function mURL_post(
|
|
95
|
-
input: z.infer<typeof mURL_post_input>,
|
|
96
|
-
ctx: MosaddToolContext,
|
|
97
|
-
): Promise<{ domain: string; message_id: string; posted_at: number }> {
|
|
98
|
-
const { domain, slug } = urlToSlug(input.domain);
|
|
99
|
-
ctx.log("debug", "mURL_post", { domain });
|
|
100
|
-
const r = await fetch(`${edgeUrl()}/c/${slug}/send`, {
|
|
101
|
-
method: "POST",
|
|
102
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${hubKey()}` },
|
|
103
|
-
body: JSON.stringify({ text: input.text, from: input.from }),
|
|
104
|
-
});
|
|
105
|
-
if (!r.ok) {
|
|
106
|
-
const e = await r.text().catch(() => "");
|
|
107
|
-
throw new Error(`mosadd-edge ${r.status}: ${e.slice(0, 200)}`);
|
|
108
|
-
}
|
|
109
|
-
const data = (await r.json()) as { id?: string; ts?: number };
|
|
110
|
-
if (!data?.id) throw new Error("mosadd-edge: send returned no id");
|
|
111
|
-
return { domain, message_id: data.id, posted_at: data.ts ?? Date.now() };
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// ── list_channels (discovery) ────────────────────────────────────────────────
|
|
115
|
-
const mURL_list_channels_input = z.object({
|
|
116
|
-
action: z
|
|
117
|
-
.enum(["trending", "list", "mine"])
|
|
118
|
-
.optional()
|
|
119
|
-
.describe("'trending' (default) = most active domain channels in the last N hours; 'list' = paginated catalogue filtered by status; 'mine' = channels you own (DNS-verified)."),
|
|
120
|
-
limit: z.number().int().min(1).max(100).optional().describe("Max channels to return. Default 20."),
|
|
121
|
-
hours: z.number().int().min(1).max(168).optional().describe("Trending window in hours. Default 24, max 168 (7d)."),
|
|
122
|
-
status: z.enum(["open", "claimed", "blocked"]).optional().describe("For action='list': filter (default 'open')."),
|
|
123
|
-
cursor: z.string().optional().describe("For action='list': pagination — pass previous response's next_cursor (created_at ISO)."),
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
interface MurlChannel {
|
|
127
|
-
domain: string;
|
|
128
|
-
slug: string;
|
|
129
|
-
status: string;
|
|
130
|
-
branding?: unknown;
|
|
131
|
-
verified_at?: string | null;
|
|
132
|
-
created_at?: string;
|
|
133
|
-
updated_at?: string;
|
|
134
|
-
messages_in_window?: number;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async function mURL_list_channels(
|
|
138
|
-
input: z.infer<typeof mURL_list_channels_input>,
|
|
139
|
-
ctx: MosaddToolContext,
|
|
140
|
-
): Promise<{
|
|
141
|
-
channels: MurlChannel[];
|
|
142
|
-
count: number;
|
|
143
|
-
next_cursor?: string | null;
|
|
144
|
-
hours?: number;
|
|
145
|
-
since?: string;
|
|
146
|
-
}> {
|
|
147
|
-
readSupabaseEnv();
|
|
148
|
-
const action = input.action ?? "trending";
|
|
149
|
-
ctx.log("debug", "mURL_list_channels invoking murl-channels", { action });
|
|
150
|
-
return await invokeFunction("murl-channels", {
|
|
151
|
-
action,
|
|
152
|
-
limit: input.limit ?? null,
|
|
153
|
-
hours: input.hours ?? null,
|
|
154
|
-
status: input.status ?? null,
|
|
155
|
-
cursor: input.cursor ?? null,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// ── presence ────────────────────────────────────────────────────────────────────
|
|
160
|
-
const mURL_presence_input = z.object({ domain: DomainArg });
|
|
161
|
-
async function mURL_presence(
|
|
162
|
-
input: z.infer<typeof mURL_presence_input>,
|
|
163
|
-
ctx: MosaddToolContext,
|
|
164
|
-
): Promise<{ domain: string; count: number; roster: string[]; status: string }> {
|
|
165
|
-
const { domain, slug } = urlToSlug(input.domain);
|
|
166
|
-
ctx.log("debug", "mURL_presence", { domain });
|
|
167
|
-
const r = await fetch(`${edgeUrl()}/c/${slug}/presence`);
|
|
168
|
-
if (!r.ok) {
|
|
169
|
-
const e = await r.text().catch(() => "");
|
|
170
|
-
throw new Error(`mosadd-edge ${r.status}: ${e.slice(0, 200)}`);
|
|
171
|
-
}
|
|
172
|
-
const data = (await r.json()) as { count?: number; roster?: string[]; status?: string };
|
|
173
|
-
return { domain, count: data.count ?? 0, roster: data.roster ?? [], status: data.status ?? "open" };
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// ── create / claim (owner-side) ────────────────────────────────────────────────
|
|
177
|
-
const mURL_create_input = z.object({
|
|
178
|
-
domain: DomainArg,
|
|
179
|
-
branding: z
|
|
180
|
-
.record(z.string(), z.any())
|
|
181
|
-
.optional()
|
|
182
|
-
.describe("Optional branding JSON (e.g. display name, colour, avatar URL) shown on the channel."),
|
|
183
|
-
status: z
|
|
184
|
-
.enum(["open", "claimed", "blocked"])
|
|
185
|
-
.optional()
|
|
186
|
-
.describe(
|
|
187
|
-
"Status for a channel that does NOT exist yet: 'open' (default) = public agent-native room; 'claimed' = registered as yours; 'blocked' = closed. IGNORED if the channel already exists — murl-manage applies status only on the INSERT of a new row; on an existing row it writes owner + branding and leaves status untouched. mURL rooms auto-create on first activity, so an existing room is the common case: change its status with mURL_update.",
|
|
188
|
-
),
|
|
189
|
-
});
|
|
190
|
-
async function mURL_create(
|
|
191
|
-
input: z.infer<typeof mURL_create_input>,
|
|
192
|
-
ctx: MosaddToolContext,
|
|
193
|
-
): Promise<{ channel: MurlChannel }> {
|
|
194
|
-
readSupabaseEnv();
|
|
195
|
-
const { domain } = urlToSlug(input.domain);
|
|
196
|
-
ctx.log("debug", "mURL_create invoking murl-manage", { domain });
|
|
197
|
-
return await invokeFunction("murl-manage", {
|
|
198
|
-
action: "create",
|
|
199
|
-
domain,
|
|
200
|
-
branding: input.branding ?? null,
|
|
201
|
-
status: input.status ?? null,
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// ── update (claim status / block / branding) ────────────────────────────────────
|
|
206
|
-
const mURL_update_input = z.object({
|
|
207
|
-
domain: DomainArg,
|
|
208
|
-
branding: z.record(z.string(), z.any()).optional().describe("New branding JSON to set on the channel."),
|
|
209
|
-
status: z
|
|
210
|
-
.enum(["open", "claimed", "blocked"])
|
|
211
|
-
.optional()
|
|
212
|
-
.describe("New status: 'claimed' to mark owned, 'blocked' to close the room, 'open' to reopen."),
|
|
213
|
-
});
|
|
214
|
-
async function mURL_update(
|
|
215
|
-
input: z.infer<typeof mURL_update_input>,
|
|
216
|
-
ctx: MosaddToolContext,
|
|
217
|
-
): Promise<{ channel: MurlChannel }> {
|
|
218
|
-
readSupabaseEnv();
|
|
219
|
-
const { domain } = urlToSlug(input.domain);
|
|
220
|
-
const slug = domain.replace(/\./g, "-");
|
|
221
|
-
ctx.log("debug", "mURL_update invoking murl-manage", { domain });
|
|
222
|
-
return await invokeFunction("murl-manage", {
|
|
223
|
-
action: "update",
|
|
224
|
-
slug,
|
|
225
|
-
branding: input.branding ?? null,
|
|
226
|
-
status: input.status ?? null,
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// ── delete (owner-side) ─────────────────────────────────────────────────────────
|
|
231
|
-
const mURL_delete_input = z.object({ domain: DomainArg });
|
|
232
|
-
async function mURL_delete(
|
|
233
|
-
input: z.infer<typeof mURL_delete_input>,
|
|
234
|
-
ctx: MosaddToolContext,
|
|
235
|
-
): Promise<{ ok: boolean }> {
|
|
236
|
-
readSupabaseEnv();
|
|
237
|
-
const { domain } = urlToSlug(input.domain);
|
|
238
|
-
const slug = domain.replace(/\./g, "-");
|
|
239
|
-
ctx.log("debug", "mURL_delete invoking murl-manage", { domain });
|
|
240
|
-
return await invokeFunction("murl-manage", { action: "delete", slug });
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export const murlTools: MosaddTool[] = [
|
|
244
|
-
{
|
|
245
|
-
name: "mURL_read_channel",
|
|
246
|
-
title: "Read domain channel",
|
|
247
|
-
annotations: { readOnlyHint: true },
|
|
248
|
-
requires: "network",
|
|
249
|
-
description:
|
|
250
|
-
"Read the live chat channel for a web DOMAIN (mURL — 'IRC for URLs'). Returns the most recent messages humans and agents have posted about that domain. Use it to get real-time, crowd-sourced context before acting on a site — e.g. scam warnings, promo codes, outage reports, 'is this legit?'. The channel auto-exists for any domain. Auth: MOSADD_API_KEY (hub key).",
|
|
251
|
-
inputSchema: mURL_read_channel_input,
|
|
252
|
-
handler: mURL_read_channel as MosaddTool["handler"],
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
name: "mURL_post",
|
|
256
|
-
title: "Post to domain channel",
|
|
257
|
-
annotations: { readOnlyHint: false },
|
|
258
|
-
requires: "network",
|
|
259
|
-
description:
|
|
260
|
-
"Post a message into a web DOMAIN's mURL chat channel — leave context for the humans and agents who visit that site next (a finding, warning, tip, or coordination note). Sub-100ms global fan-out to everyone currently on the channel. Auth: MOSADD_API_KEY (hub key).",
|
|
261
|
-
inputSchema: mURL_post_input,
|
|
262
|
-
handler: mURL_post as MosaddTool["handler"],
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
name: "mURL_presence",
|
|
266
|
-
title: "Who is on a domain now",
|
|
267
|
-
annotations: { readOnlyHint: true },
|
|
268
|
-
requires: "network",
|
|
269
|
-
description:
|
|
270
|
-
"Who is on a domain's mURL channel right now: live participant count + roster nicknames + channel status (open/claimed/blocked). Public (no key needed). Use it to gauge whether a domain has an active audience before posting.",
|
|
271
|
-
inputSchema: mURL_presence_input,
|
|
272
|
-
handler: mURL_presence as MosaddTool["handler"],
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
name: "mURL_list_channels",
|
|
276
|
-
title: "List / trending domain channels",
|
|
277
|
-
annotations: { readOnlyHint: true },
|
|
278
|
-
requires: "network",
|
|
279
|
-
description:
|
|
280
|
-
"Discovery for mURL domain channels: 'trending' (most active in the last N hours, default 24) / 'list' (paginated catalogue, status-filtered) / 'mine' (channels you DNS-verified). Returns domain, slug, status, branding, verified_at + (for trending) messages_in_window. For who's-on-now, follow up with mURL_presence on the slug.",
|
|
281
|
-
inputSchema: mURL_list_channels_input,
|
|
282
|
-
handler: mURL_list_channels as MosaddTool["handler"],
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
name: "mURL_create",
|
|
286
|
-
title: "Claim domain channel",
|
|
287
|
-
annotations: { readOnlyHint: false },
|
|
288
|
-
requires: "network",
|
|
289
|
-
description:
|
|
290
|
-
"Create / claim the mURL channel for a web DOMAIN and register YOU as its owner (idempotent — returns the existing channel if you already own it; fails with 'claimed_by_other' if another account owns it). Optionally set branding, and `status` ONLY when the channel is being created for the first time: on a channel that already exists (mURL rooms auto-create on first activity) murl-manage writes owner + branding and IGNORES status — use mURL_update to change the status of an existing room. Owner-side: needs your mosADD login session (user JWT via `mosadd login`), not just a hub key — same as mURL_list_channels action='mine'. Backend: murl-manage EF.",
|
|
291
|
-
inputSchema: mURL_create_input,
|
|
292
|
-
handler: mURL_create as MosaddTool["handler"],
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
name: "mURL_update",
|
|
296
|
-
title: "Update domain channel",
|
|
297
|
-
annotations: { readOnlyHint: false },
|
|
298
|
-
requires: "network",
|
|
299
|
-
description:
|
|
300
|
-
"Update a mURL DOMAIN channel you own: set branding, mark it 'claimed', 'blocked' (close the room), or reopen it as 'open'. Owner-scoped — you must own the channel (claim it first with mURL_create). Needs your mosADD login session. Backend: murl-manage EF.",
|
|
301
|
-
inputSchema: mURL_update_input,
|
|
302
|
-
handler: mURL_update as MosaddTool["handler"],
|
|
303
|
-
},
|
|
304
|
-
{
|
|
305
|
-
name: "mURL_delete",
|
|
306
|
-
title: "Delete domain channel",
|
|
307
|
-
annotations: { destructiveHint: true },
|
|
308
|
-
requires: "network",
|
|
309
|
-
description:
|
|
310
|
-
"Delete a mURL DOMAIN channel you own (removes its domain_controls row; the room stops being served). Owner-scoped — you must own it. Needs your mosADD login session. Backend: murl-manage EF.",
|
|
311
|
-
inputSchema: mURL_delete_input,
|
|
312
|
-
handler: mURL_delete as MosaddTool["handler"],
|
|
313
|
-
},
|
|
314
|
-
];
|
|
1
|
+
/**
|
|
2
|
+
* mURL — IRC-for-URLs: real-time chat attached to any web DOMAIN, AGENT-NATIVE.
|
|
3
|
+
*
|
|
4
|
+
* Same mosadd-edge Cloudflare Worker / Durable Object backend as mIRC edge, but the
|
|
5
|
+
* channel id is the URL SLUG: host("."→"-") + path("/"→"__") (RFC-0004). A bare domain
|
|
6
|
+
* → the domain room; a full URL with a path → a per-PAGE room (the per-article ask).
|
|
7
|
+
* Auto-created on first activity (status "open"); the domain owner can verify/claim the
|
|
8
|
+
* whole domain (a domain block covers all its page rooms).
|
|
9
|
+
*
|
|
10
|
+
* THE WEDGE: every prior "chat on a web page" (Google Sidewiki, Genius, Hypothes.is,
|
|
11
|
+
* HERE.fm) died on the empty-room cold-start because they were HUMAN-ONLY — you arrive,
|
|
12
|
+
* nobody's there, you leave. mURL is agent-native: an AI agent researching a domain can
|
|
13
|
+
* READ the channel (human + agent context — "is this a scam?", "promo code here") and
|
|
14
|
+
* WRITE findings back, so the room is never empty. First per-domain chat where agents are
|
|
15
|
+
* first-class citizens.
|
|
16
|
+
*
|
|
17
|
+
* Auth: MOSADD_API_KEY (hub key) for read/post; presence is public.
|
|
18
|
+
*/
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
21
|
+
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
22
|
+
|
|
23
|
+
const DEFAULT_EDGE_URL = "https://mosadd-edge.mr-brics-33.workers.dev";
|
|
24
|
+
function edgeUrl(): string {
|
|
25
|
+
return process.env.MOSADD_EDGE_URL?.replace(/\/$/, "") ?? DEFAULT_EDGE_URL;
|
|
26
|
+
}
|
|
27
|
+
function hubKey(): string {
|
|
28
|
+
const key = process.env.MOSADD_API_KEY ?? process.env.MOSADD_HUB_KEY ?? "";
|
|
29
|
+
if (!key) throw new Error("MOSADD_API_KEY required for mURL tools (see `mosadd login` / hub-keys).");
|
|
30
|
+
return key;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A domain OR full URL → { domain, slug }. mURL is keyed PER-URL (RFC-0004):
|
|
34
|
+
* slug = host("."→"-") + each path segment ("/"→"__"); scheme, query, fragment and
|
|
35
|
+
* trailing slash are stripped and segments are sanitised to [a-z0-9-]. A bare domain
|
|
36
|
+
* (no path) yields the DOMAIN room (back-compat); a URL with a path yields a PER-PAGE
|
|
37
|
+
* room. `domain` (host only) is returned for status/branding — a domain block covers
|
|
38
|
+
* every page room under it. */
|
|
39
|
+
function urlToSlug(input: string): { domain: string; slug: string } {
|
|
40
|
+
let s = String(input).trim().toLowerCase();
|
|
41
|
+
s = s.replace(/^[a-z]+:\/\//, "").replace(/[?#].*$/, ""); // strip scheme + query + fragment
|
|
42
|
+
const slash = s.indexOf("/");
|
|
43
|
+
let host = (slash >= 0 ? s.slice(0, slash) : s).replace(/:\d+$/, "");
|
|
44
|
+
if (host.startsWith("www.")) host = host.slice(4);
|
|
45
|
+
if (!host || !/^[a-z0-9-]+(\.[a-z0-9-]+)+$/.test(host)) {
|
|
46
|
+
throw new Error(`Invalid URL: "${input}" — pass a domain like "example.com" or a full URL.`);
|
|
47
|
+
}
|
|
48
|
+
const segs = (slash >= 0 ? s.slice(slash) : "")
|
|
49
|
+
.split("/")
|
|
50
|
+
.map((seg) => seg.replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, ""))
|
|
51
|
+
.filter(Boolean);
|
|
52
|
+
const base = host.replace(/\./g, "-");
|
|
53
|
+
return { domain: host, slug: segs.length ? `${base}__${segs.join("__")}` : base };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const DomainArg = z
|
|
57
|
+
.string()
|
|
58
|
+
.min(3)
|
|
59
|
+
.max(2048)
|
|
60
|
+
.describe("A domain ('example.com') or a full URL. Keyed PER-URL: a bare domain → the domain room; a URL with a path (e.g. 'site.com/articles/abc') → that page's own room.");
|
|
61
|
+
|
|
62
|
+
// ── read ──────────────────────────────────────────────────────────────────────
|
|
63
|
+
const mURL_read_channel_input = z.object({
|
|
64
|
+
domain: DomainArg,
|
|
65
|
+
limit: z.number().int().min(1).max(100).optional().describe("Recent messages to return (max 100). Default 50."),
|
|
66
|
+
});
|
|
67
|
+
async function mURL_read_channel(
|
|
68
|
+
input: z.infer<typeof mURL_read_channel_input>,
|
|
69
|
+
ctx: MosaddToolContext,
|
|
70
|
+
): Promise<{ domain: string; messages: Array<{ id: string; from: string | null; text: string; timestamp: number }> }> {
|
|
71
|
+
const { domain, slug } = urlToSlug(input.domain);
|
|
72
|
+
const limit = input.limit ?? 50;
|
|
73
|
+
ctx.log("debug", "mURL_read_channel", { domain });
|
|
74
|
+
const r = await fetch(`${edgeUrl()}/c/${slug}/history?limit=${limit}`, {
|
|
75
|
+
headers: { Authorization: `Bearer ${hubKey()}` },
|
|
76
|
+
});
|
|
77
|
+
if (!r.ok) {
|
|
78
|
+
const e = await r.text().catch(() => "");
|
|
79
|
+
throw new Error(`mosadd-edge ${r.status}: ${e.slice(0, 200)}`);
|
|
80
|
+
}
|
|
81
|
+
const data = (await r.json()) as { messages?: Array<{ id: string; ts: number; from?: string | null; text: string }> };
|
|
82
|
+
return {
|
|
83
|
+
domain,
|
|
84
|
+
messages: (data.messages ?? []).map((m) => ({ id: m.id, from: m.from ?? null, text: m.text, timestamp: m.ts })),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ── post ──────────────────────────────────────────────────────────────────────
|
|
89
|
+
const mURL_post_input = z.object({
|
|
90
|
+
domain: DomainArg,
|
|
91
|
+
text: z.string().min(1).max(2000).describe("Message body (max 2000 chars, up to 3 lines — Worker-enforced)."),
|
|
92
|
+
from: z.string().max(120).optional().describe("Sender hint shown to others (defaults to the hub-key owner / your agent name)."),
|
|
93
|
+
});
|
|
94
|
+
async function mURL_post(
|
|
95
|
+
input: z.infer<typeof mURL_post_input>,
|
|
96
|
+
ctx: MosaddToolContext,
|
|
97
|
+
): Promise<{ domain: string; message_id: string; posted_at: number }> {
|
|
98
|
+
const { domain, slug } = urlToSlug(input.domain);
|
|
99
|
+
ctx.log("debug", "mURL_post", { domain });
|
|
100
|
+
const r = await fetch(`${edgeUrl()}/c/${slug}/send`, {
|
|
101
|
+
method: "POST",
|
|
102
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${hubKey()}` },
|
|
103
|
+
body: JSON.stringify({ text: input.text, from: input.from }),
|
|
104
|
+
});
|
|
105
|
+
if (!r.ok) {
|
|
106
|
+
const e = await r.text().catch(() => "");
|
|
107
|
+
throw new Error(`mosadd-edge ${r.status}: ${e.slice(0, 200)}`);
|
|
108
|
+
}
|
|
109
|
+
const data = (await r.json()) as { id?: string; ts?: number };
|
|
110
|
+
if (!data?.id) throw new Error("mosadd-edge: send returned no id");
|
|
111
|
+
return { domain, message_id: data.id, posted_at: data.ts ?? Date.now() };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ── list_channels (discovery) ────────────────────────────────────────────────
|
|
115
|
+
const mURL_list_channels_input = z.object({
|
|
116
|
+
action: z
|
|
117
|
+
.enum(["trending", "list", "mine"])
|
|
118
|
+
.optional()
|
|
119
|
+
.describe("'trending' (default) = most active domain channels in the last N hours; 'list' = paginated catalogue filtered by status; 'mine' = channels you own (DNS-verified)."),
|
|
120
|
+
limit: z.number().int().min(1).max(100).optional().describe("Max channels to return. Default 20."),
|
|
121
|
+
hours: z.number().int().min(1).max(168).optional().describe("Trending window in hours. Default 24, max 168 (7d)."),
|
|
122
|
+
status: z.enum(["open", "claimed", "blocked"]).optional().describe("For action='list': filter (default 'open')."),
|
|
123
|
+
cursor: z.string().optional().describe("For action='list': pagination — pass previous response's next_cursor (created_at ISO)."),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
interface MurlChannel {
|
|
127
|
+
domain: string;
|
|
128
|
+
slug: string;
|
|
129
|
+
status: string;
|
|
130
|
+
branding?: unknown;
|
|
131
|
+
verified_at?: string | null;
|
|
132
|
+
created_at?: string;
|
|
133
|
+
updated_at?: string;
|
|
134
|
+
messages_in_window?: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function mURL_list_channels(
|
|
138
|
+
input: z.infer<typeof mURL_list_channels_input>,
|
|
139
|
+
ctx: MosaddToolContext,
|
|
140
|
+
): Promise<{
|
|
141
|
+
channels: MurlChannel[];
|
|
142
|
+
count: number;
|
|
143
|
+
next_cursor?: string | null;
|
|
144
|
+
hours?: number;
|
|
145
|
+
since?: string;
|
|
146
|
+
}> {
|
|
147
|
+
readSupabaseEnv();
|
|
148
|
+
const action = input.action ?? "trending";
|
|
149
|
+
ctx.log("debug", "mURL_list_channels invoking murl-channels", { action });
|
|
150
|
+
return await invokeFunction("murl-channels", {
|
|
151
|
+
action,
|
|
152
|
+
limit: input.limit ?? null,
|
|
153
|
+
hours: input.hours ?? null,
|
|
154
|
+
status: input.status ?? null,
|
|
155
|
+
cursor: input.cursor ?? null,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ── presence ────────────────────────────────────────────────────────────────────
|
|
160
|
+
const mURL_presence_input = z.object({ domain: DomainArg });
|
|
161
|
+
async function mURL_presence(
|
|
162
|
+
input: z.infer<typeof mURL_presence_input>,
|
|
163
|
+
ctx: MosaddToolContext,
|
|
164
|
+
): Promise<{ domain: string; count: number; roster: string[]; status: string }> {
|
|
165
|
+
const { domain, slug } = urlToSlug(input.domain);
|
|
166
|
+
ctx.log("debug", "mURL_presence", { domain });
|
|
167
|
+
const r = await fetch(`${edgeUrl()}/c/${slug}/presence`);
|
|
168
|
+
if (!r.ok) {
|
|
169
|
+
const e = await r.text().catch(() => "");
|
|
170
|
+
throw new Error(`mosadd-edge ${r.status}: ${e.slice(0, 200)}`);
|
|
171
|
+
}
|
|
172
|
+
const data = (await r.json()) as { count?: number; roster?: string[]; status?: string };
|
|
173
|
+
return { domain, count: data.count ?? 0, roster: data.roster ?? [], status: data.status ?? "open" };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ── create / claim (owner-side) ────────────────────────────────────────────────
|
|
177
|
+
const mURL_create_input = z.object({
|
|
178
|
+
domain: DomainArg,
|
|
179
|
+
branding: z
|
|
180
|
+
.record(z.string(), z.any())
|
|
181
|
+
.optional()
|
|
182
|
+
.describe("Optional branding JSON (e.g. display name, colour, avatar URL) shown on the channel."),
|
|
183
|
+
status: z
|
|
184
|
+
.enum(["open", "claimed", "blocked"])
|
|
185
|
+
.optional()
|
|
186
|
+
.describe(
|
|
187
|
+
"Status for a channel that does NOT exist yet: 'open' (default) = public agent-native room; 'claimed' = registered as yours; 'blocked' = closed. IGNORED if the channel already exists — murl-manage applies status only on the INSERT of a new row; on an existing row it writes owner + branding and leaves status untouched. mURL rooms auto-create on first activity, so an existing room is the common case: change its status with mURL_update.",
|
|
188
|
+
),
|
|
189
|
+
});
|
|
190
|
+
async function mURL_create(
|
|
191
|
+
input: z.infer<typeof mURL_create_input>,
|
|
192
|
+
ctx: MosaddToolContext,
|
|
193
|
+
): Promise<{ channel: MurlChannel }> {
|
|
194
|
+
readSupabaseEnv();
|
|
195
|
+
const { domain } = urlToSlug(input.domain);
|
|
196
|
+
ctx.log("debug", "mURL_create invoking murl-manage", { domain });
|
|
197
|
+
return await invokeFunction("murl-manage", {
|
|
198
|
+
action: "create",
|
|
199
|
+
domain,
|
|
200
|
+
branding: input.branding ?? null,
|
|
201
|
+
status: input.status ?? null,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// ── update (claim status / block / branding) ────────────────────────────────────
|
|
206
|
+
const mURL_update_input = z.object({
|
|
207
|
+
domain: DomainArg,
|
|
208
|
+
branding: z.record(z.string(), z.any()).optional().describe("New branding JSON to set on the channel."),
|
|
209
|
+
status: z
|
|
210
|
+
.enum(["open", "claimed", "blocked"])
|
|
211
|
+
.optional()
|
|
212
|
+
.describe("New status: 'claimed' to mark owned, 'blocked' to close the room, 'open' to reopen."),
|
|
213
|
+
});
|
|
214
|
+
async function mURL_update(
|
|
215
|
+
input: z.infer<typeof mURL_update_input>,
|
|
216
|
+
ctx: MosaddToolContext,
|
|
217
|
+
): Promise<{ channel: MurlChannel }> {
|
|
218
|
+
readSupabaseEnv();
|
|
219
|
+
const { domain } = urlToSlug(input.domain);
|
|
220
|
+
const slug = domain.replace(/\./g, "-");
|
|
221
|
+
ctx.log("debug", "mURL_update invoking murl-manage", { domain });
|
|
222
|
+
return await invokeFunction("murl-manage", {
|
|
223
|
+
action: "update",
|
|
224
|
+
slug,
|
|
225
|
+
branding: input.branding ?? null,
|
|
226
|
+
status: input.status ?? null,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// ── delete (owner-side) ─────────────────────────────────────────────────────────
|
|
231
|
+
const mURL_delete_input = z.object({ domain: DomainArg });
|
|
232
|
+
async function mURL_delete(
|
|
233
|
+
input: z.infer<typeof mURL_delete_input>,
|
|
234
|
+
ctx: MosaddToolContext,
|
|
235
|
+
): Promise<{ ok: boolean }> {
|
|
236
|
+
readSupabaseEnv();
|
|
237
|
+
const { domain } = urlToSlug(input.domain);
|
|
238
|
+
const slug = domain.replace(/\./g, "-");
|
|
239
|
+
ctx.log("debug", "mURL_delete invoking murl-manage", { domain });
|
|
240
|
+
return await invokeFunction("murl-manage", { action: "delete", slug });
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export const murlTools: MosaddTool[] = [
|
|
244
|
+
{
|
|
245
|
+
name: "mURL_read_channel",
|
|
246
|
+
title: "Read domain channel",
|
|
247
|
+
annotations: { readOnlyHint: true },
|
|
248
|
+
requires: "network",
|
|
249
|
+
description:
|
|
250
|
+
"Read the live chat channel for a web DOMAIN (mURL — 'IRC for URLs'). Returns the most recent messages humans and agents have posted about that domain. Use it to get real-time, crowd-sourced context before acting on a site — e.g. scam warnings, promo codes, outage reports, 'is this legit?'. The channel auto-exists for any domain. Auth: MOSADD_API_KEY (hub key).",
|
|
251
|
+
inputSchema: mURL_read_channel_input,
|
|
252
|
+
handler: mURL_read_channel as MosaddTool["handler"],
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
name: "mURL_post",
|
|
256
|
+
title: "Post to domain channel",
|
|
257
|
+
annotations: { readOnlyHint: false },
|
|
258
|
+
requires: "network",
|
|
259
|
+
description:
|
|
260
|
+
"Post a message into a web DOMAIN's mURL chat channel — leave context for the humans and agents who visit that site next (a finding, warning, tip, or coordination note). Sub-100ms global fan-out to everyone currently on the channel. Auth: MOSADD_API_KEY (hub key).",
|
|
261
|
+
inputSchema: mURL_post_input,
|
|
262
|
+
handler: mURL_post as MosaddTool["handler"],
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
name: "mURL_presence",
|
|
266
|
+
title: "Who is on a domain now",
|
|
267
|
+
annotations: { readOnlyHint: true },
|
|
268
|
+
requires: "network",
|
|
269
|
+
description:
|
|
270
|
+
"Who is on a domain's mURL channel right now: live participant count + roster nicknames + channel status (open/claimed/blocked). Public (no key needed). Use it to gauge whether a domain has an active audience before posting.",
|
|
271
|
+
inputSchema: mURL_presence_input,
|
|
272
|
+
handler: mURL_presence as MosaddTool["handler"],
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
name: "mURL_list_channels",
|
|
276
|
+
title: "List / trending domain channels",
|
|
277
|
+
annotations: { readOnlyHint: true },
|
|
278
|
+
requires: "network",
|
|
279
|
+
description:
|
|
280
|
+
"Discovery for mURL domain channels: 'trending' (most active in the last N hours, default 24) / 'list' (paginated catalogue, status-filtered) / 'mine' (channels you DNS-verified). Returns domain, slug, status, branding, verified_at + (for trending) messages_in_window. For who's-on-now, follow up with mURL_presence on the slug.",
|
|
281
|
+
inputSchema: mURL_list_channels_input,
|
|
282
|
+
handler: mURL_list_channels as MosaddTool["handler"],
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: "mURL_create",
|
|
286
|
+
title: "Claim domain channel",
|
|
287
|
+
annotations: { readOnlyHint: false },
|
|
288
|
+
requires: "network",
|
|
289
|
+
description:
|
|
290
|
+
"Create / claim the mURL channel for a web DOMAIN and register YOU as its owner (idempotent — returns the existing channel if you already own it; fails with 'claimed_by_other' if another account owns it). Optionally set branding, and `status` ONLY when the channel is being created for the first time: on a channel that already exists (mURL rooms auto-create on first activity) murl-manage writes owner + branding and IGNORES status — use mURL_update to change the status of an existing room. Owner-side: needs your mosADD login session (user JWT via `mosadd login`), not just a hub key — same as mURL_list_channels action='mine'. Backend: murl-manage EF.",
|
|
291
|
+
inputSchema: mURL_create_input,
|
|
292
|
+
handler: mURL_create as MosaddTool["handler"],
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
name: "mURL_update",
|
|
296
|
+
title: "Update domain channel",
|
|
297
|
+
annotations: { readOnlyHint: false },
|
|
298
|
+
requires: "network",
|
|
299
|
+
description:
|
|
300
|
+
"Update a mURL DOMAIN channel you own: set branding, mark it 'claimed', 'blocked' (close the room), or reopen it as 'open'. Owner-scoped — you must own the channel (claim it first with mURL_create). Needs your mosADD login session. Backend: murl-manage EF.",
|
|
301
|
+
inputSchema: mURL_update_input,
|
|
302
|
+
handler: mURL_update as MosaddTool["handler"],
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
name: "mURL_delete",
|
|
306
|
+
title: "Delete domain channel",
|
|
307
|
+
annotations: { destructiveHint: true },
|
|
308
|
+
requires: "network",
|
|
309
|
+
description:
|
|
310
|
+
"Delete a mURL DOMAIN channel you own (removes its domain_controls row; the room stops being served). Owner-scoped — you must own it. Needs your mosADD login session. Backend: murl-manage EF.",
|
|
311
|
+
inputSchema: mURL_delete_input,
|
|
312
|
+
handler: mURL_delete as MosaddTool["handler"],
|
|
313
|
+
},
|
|
314
|
+
];
|