@mosadd/mcp 3.0.0-alpha.5 → 3.0.0-alpha.51
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 +309 -0
- package/LICENSE +201 -201
- package/README.md +150 -126
- package/dist/bin/mcp.js +42 -3
- package/dist/chunk-BTAIZKYT.js +3800 -0
- package/dist/index.d.ts +118 -5
- package/dist/index.js +7 -3
- package/package.json +10 -7
- package/src/__tests__/channel-e2ee.test.ts +62 -0
- package/src/__tests__/golden-path.test.ts +139 -137
- package/src/__tests__/integration.test.ts +182 -178
- package/src/__tests__/knowledge-ingest.test.ts +114 -0
- package/src/__tests__/mdm-e2ee.test.ts +212 -178
- package/src/__tests__/mirc-invite.test.ts +112 -0
- package/src/__tests__/mtalk.test.ts +122 -122
- package/src/__tests__/presence.test.ts +199 -0
- package/src/__tests__/server.test.ts +71 -67
- package/src/__tests__/serverJsonVersion.test.ts +45 -0
- package/src/__tests__/tool-count-consistency.test.ts +199 -0
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -97
- package/src/config.ts +66 -66
- package/src/crypto/channel-e2ee.ts +288 -0
- package/src/crypto/mdm-session.ts +502 -403
- package/src/index.ts +19 -17
- package/src/observability/sentry.ts +79 -79
- package/src/providers/blob-upload.ts +116 -0
- package/src/providers/memory-voice.ts +79 -79
- package/src/providers/supabase-dm.ts +122 -117
- package/src/providers/supabase-voice.ts +91 -91
- package/src/providers/supabase.ts +231 -96
- package/src/server.ts +162 -105
- 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 +70 -68
- package/src/tools/embed.ts +110 -0
- package/src/tools/index.ts +181 -51
- package/src/tools/knowledge-graph.ts +186 -0
- package/src/tools/knowledge.ts +344 -132
- 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 +403 -157
- package/src/tools/mcall.ts +216 -216
- package/src/tools/mdm-as-agent.ts +126 -0
- package/src/tools/mdm-voice.ts +220 -206
- package/src/tools/mdm.ts +73 -26
- package/src/tools/mirc-edge.ts +196 -190
- package/src/tools/mirc-members.ts +287 -177
- package/src/tools/mirc-messages.ts +76 -27
- package/src/tools/mirc.ts +308 -170
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +221 -221
- package/src/tools/mtalk.ts +131 -121
- 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 +28 -0
- package/src/types.ts +121 -85
- package/src/version.ts +8 -0
- package/src/voice/floor.ts +132 -132
- package/dist/chunk-4C36JDTJ.js +0 -1836
package/src/tools/mtalk.ts
CHANGED
|
@@ -1,121 +1,131 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mTALK — Push-to-Talk (the kill feature).
|
|
3
|
-
*
|
|
4
|
-
* Half-duplex voice over a real-time room, with a walkie-talkie floor
|
|
5
|
-
* discipline: one transmitter at a time, others queue, and an anti-hog timeout
|
|
6
|
-
* keeps the floor moving. An AGENT uses these tools to: spin up a PTT room, get
|
|
7
|
-
* join credentials for a human/bot client, and drive the floor (press/release
|
|
8
|
-
* PTT, see who's transmitting). The audio itself flows over the media transport
|
|
9
|
-
* the VoiceProvider points at (LiveKit by default); these tools coordinate WHO
|
|
10
|
-
* may transmit, which is the part that makes a PTT channel work.
|
|
11
|
-
*
|
|
12
|
-
* Transport-agnostic: the same tools drive an off-grid radio host, where the
|
|
13
|
-
* floor is the physical RF channel (the host injects its own VoiceProvider).
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { z } from "zod";
|
|
17
|
-
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
18
|
-
|
|
19
|
-
const RoomLabel = z
|
|
20
|
-
.string()
|
|
21
|
-
.min(1)
|
|
22
|
-
.max(120)
|
|
23
|
-
.regex(/^[a-zA-Z0-9._-]+$/)
|
|
24
|
-
.describe("Human-readable room label (e.g. 'ops', 'field-team'). Used to derive a stable room id.");
|
|
25
|
-
|
|
26
|
-
const RoomId = z.string().min(1).describe("Room id returned by mTALK_open.");
|
|
27
|
-
|
|
28
|
-
const mTALK_open_input = z.object({
|
|
29
|
-
label: RoomLabel.optional().describe("Optional label; defaults to a personal room."),
|
|
30
|
-
});
|
|
31
|
-
const mTALK_join_input = z.object({ room_id: RoomId });
|
|
32
|
-
const mTALK_press_input = z.object({ room_id: RoomId });
|
|
33
|
-
const mTALK_release_input = z.object({ room_id: RoomId });
|
|
34
|
-
const mTALK_state_input = z.object({ room_id: RoomId });
|
|
35
|
-
|
|
36
|
-
async function mTALK_open(
|
|
37
|
-
input: z.infer<typeof mTALK_open_input>,
|
|
38
|
-
ctx: MosaddToolContext,
|
|
39
|
-
): Promise<{ room_id: string }> {
|
|
40
|
-
const { roomId } = await ctx.providers.voice.createRoom(input.label);
|
|
41
|
-
ctx.log("debug", "mTALK_open", { room_id: roomId });
|
|
42
|
-
return { room_id: roomId };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function mTALK_join(
|
|
46
|
-
input: z.infer<typeof mTALK_join_input>,
|
|
47
|
-
ctx: MosaddToolContext,
|
|
48
|
-
): Promise<{ room_id: string; token: string; url: string; identity: string }> {
|
|
49
|
-
const ticket = await ctx.providers.voice.joinTicket(input.room_id);
|
|
50
|
-
ctx.log("debug", "mTALK_join", { room_id: ticket.roomId, identity: ticket.identity });
|
|
51
|
-
return { room_id: ticket.roomId, token: ticket.token, url: ticket.url, identity: ticket.identity };
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function mTALK_press(
|
|
55
|
-
input: z.infer<typeof mTALK_press_input>,
|
|
56
|
-
ctx: MosaddToolContext,
|
|
57
|
-
): Promise<{ granted: boolean; position: number; holder: string | null; queue: string[] }> {
|
|
58
|
-
const res = await ctx.providers.voice.requestFloor(input.room_id);
|
|
59
|
-
ctx.log("debug", "mTALK_press", { room_id: input.room_id, granted: res.granted, position: res.position });
|
|
60
|
-
return { granted: res.granted, position: res.position, holder: res.snapshot.holder, queue: res.snapshot.queue };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async function mTALK_release(
|
|
64
|
-
input: z.infer<typeof mTALK_release_input>,
|
|
65
|
-
ctx: MosaddToolContext,
|
|
66
|
-
): Promise<{ holder: string | null; queue: string[] }> {
|
|
67
|
-
const snap = await ctx.providers.voice.releaseFloor(input.room_id);
|
|
68
|
-
ctx.log("debug", "mTALK_release", { room_id: input.room_id, holder: snap.holder });
|
|
69
|
-
return { holder: snap.holder, queue: snap.queue };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function mTALK_state(
|
|
73
|
-
input: z.infer<typeof mTALK_state_input>,
|
|
74
|
-
ctx: MosaddToolContext,
|
|
75
|
-
): Promise<{ holder: string | null; since: string | null; queue: string[] }> {
|
|
76
|
-
const snap = await ctx.providers.voice.floorState(input.room_id);
|
|
77
|
-
return { holder: snap.holder, since: snap.since, queue: snap.queue };
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export const mtalkTools: MosaddTool[] = [
|
|
81
|
-
{
|
|
82
|
-
name: "mTALK_open",
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
requires: "any",
|
|
116
|
-
description:
|
|
117
|
-
"
|
|
118
|
-
inputSchema:
|
|
119
|
-
handler:
|
|
120
|
-
},
|
|
121
|
-
|
|
1
|
+
/**
|
|
2
|
+
* mTALK — Push-to-Talk (the kill feature).
|
|
3
|
+
*
|
|
4
|
+
* Half-duplex voice over a real-time room, with a walkie-talkie floor
|
|
5
|
+
* discipline: one transmitter at a time, others queue, and an anti-hog timeout
|
|
6
|
+
* keeps the floor moving. An AGENT uses these tools to: spin up a PTT room, get
|
|
7
|
+
* join credentials for a human/bot client, and drive the floor (press/release
|
|
8
|
+
* PTT, see who's transmitting). The audio itself flows over the media transport
|
|
9
|
+
* the VoiceProvider points at (LiveKit by default); these tools coordinate WHO
|
|
10
|
+
* may transmit, which is the part that makes a PTT channel work.
|
|
11
|
+
*
|
|
12
|
+
* Transport-agnostic: the same tools drive an off-grid radio host, where the
|
|
13
|
+
* floor is the physical RF channel (the host injects its own VoiceProvider).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
18
|
+
|
|
19
|
+
const RoomLabel = z
|
|
20
|
+
.string()
|
|
21
|
+
.min(1)
|
|
22
|
+
.max(120)
|
|
23
|
+
.regex(/^[a-zA-Z0-9._-]+$/)
|
|
24
|
+
.describe("Human-readable room label (e.g. 'ops', 'field-team'). Used to derive a stable room id.");
|
|
25
|
+
|
|
26
|
+
const RoomId = z.string().min(1).describe("Room id returned by mTALK_open.");
|
|
27
|
+
|
|
28
|
+
const mTALK_open_input = z.object({
|
|
29
|
+
label: RoomLabel.optional().describe("Optional label; defaults to a personal room."),
|
|
30
|
+
});
|
|
31
|
+
const mTALK_join_input = z.object({ room_id: RoomId });
|
|
32
|
+
const mTALK_press_input = z.object({ room_id: RoomId });
|
|
33
|
+
const mTALK_release_input = z.object({ room_id: RoomId });
|
|
34
|
+
const mTALK_state_input = z.object({ room_id: RoomId });
|
|
35
|
+
|
|
36
|
+
async function mTALK_open(
|
|
37
|
+
input: z.infer<typeof mTALK_open_input>,
|
|
38
|
+
ctx: MosaddToolContext,
|
|
39
|
+
): Promise<{ room_id: string }> {
|
|
40
|
+
const { roomId } = await ctx.providers.voice.createRoom(input.label);
|
|
41
|
+
ctx.log("debug", "mTALK_open", { room_id: roomId });
|
|
42
|
+
return { room_id: roomId };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function mTALK_join(
|
|
46
|
+
input: z.infer<typeof mTALK_join_input>,
|
|
47
|
+
ctx: MosaddToolContext,
|
|
48
|
+
): Promise<{ room_id: string; token: string; url: string; identity: string }> {
|
|
49
|
+
const ticket = await ctx.providers.voice.joinTicket(input.room_id);
|
|
50
|
+
ctx.log("debug", "mTALK_join", { room_id: ticket.roomId, identity: ticket.identity });
|
|
51
|
+
return { room_id: ticket.roomId, token: ticket.token, url: ticket.url, identity: ticket.identity };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function mTALK_press(
|
|
55
|
+
input: z.infer<typeof mTALK_press_input>,
|
|
56
|
+
ctx: MosaddToolContext,
|
|
57
|
+
): Promise<{ granted: boolean; position: number; holder: string | null; queue: string[] }> {
|
|
58
|
+
const res = await ctx.providers.voice.requestFloor(input.room_id);
|
|
59
|
+
ctx.log("debug", "mTALK_press", { room_id: input.room_id, granted: res.granted, position: res.position });
|
|
60
|
+
return { granted: res.granted, position: res.position, holder: res.snapshot.holder, queue: res.snapshot.queue };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function mTALK_release(
|
|
64
|
+
input: z.infer<typeof mTALK_release_input>,
|
|
65
|
+
ctx: MosaddToolContext,
|
|
66
|
+
): Promise<{ holder: string | null; queue: string[] }> {
|
|
67
|
+
const snap = await ctx.providers.voice.releaseFloor(input.room_id);
|
|
68
|
+
ctx.log("debug", "mTALK_release", { room_id: input.room_id, holder: snap.holder });
|
|
69
|
+
return { holder: snap.holder, queue: snap.queue };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function mTALK_state(
|
|
73
|
+
input: z.infer<typeof mTALK_state_input>,
|
|
74
|
+
ctx: MosaddToolContext,
|
|
75
|
+
): Promise<{ holder: string | null; since: string | null; queue: string[] }> {
|
|
76
|
+
const snap = await ctx.providers.voice.floorState(input.room_id);
|
|
77
|
+
return { holder: snap.holder, since: snap.since, queue: snap.queue };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const mtalkTools: MosaddTool[] = [
|
|
81
|
+
{
|
|
82
|
+
name: "mTALK_open",
|
|
83
|
+
title: "Open push-to-talk room",
|
|
84
|
+
annotations: { readOnlyHint: false },
|
|
85
|
+
requires: "any",
|
|
86
|
+
description:
|
|
87
|
+
"Open (or get) a push-to-talk room. Returns a stable room_id. Pass an optional label to share a named room (e.g. 'ops'); omit it for a personal room. Works over network (LiveKit) or off-grid radio depending on the host.",
|
|
88
|
+
inputSchema: mTALK_open_input,
|
|
89
|
+
handler: mTALK_open as MosaddTool["handler"],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "mTALK_join",
|
|
93
|
+
title: "Get PTT join credentials",
|
|
94
|
+
annotations: { readOnlyHint: false },
|
|
95
|
+
requires: "network",
|
|
96
|
+
description:
|
|
97
|
+
"Get credentials (token + media URL) to join a PTT room's audio transport. Hand these to a human or bot client to connect. The agent itself drives the floor with mTALK_press / mTALK_release.",
|
|
98
|
+
inputSchema: mTALK_join_input,
|
|
99
|
+
handler: mTALK_join as MosaddTool["handler"],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "mTALK_press",
|
|
103
|
+
title: "Press to talk (request floor)",
|
|
104
|
+
annotations: { readOnlyHint: false },
|
|
105
|
+
requires: "any",
|
|
106
|
+
description:
|
|
107
|
+
"Press push-to-talk: request the floor in a room. Half-duplex — if no one is transmitting you are GRANTED the floor (granted=true) and may speak; otherwise you are queued FIFO and `position` tells you where you are. Call mTALK_release when done. A holder who never releases is auto-bumped after the anti-hog timeout.",
|
|
108
|
+
inputSchema: mTALK_press_input,
|
|
109
|
+
handler: mTALK_press as MosaddTool["handler"],
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "mTALK_release",
|
|
113
|
+
title: "Release the floor",
|
|
114
|
+
annotations: { readOnlyHint: false },
|
|
115
|
+
requires: "any",
|
|
116
|
+
description:
|
|
117
|
+
"Release push-to-talk: give up the floor (or cancel your queued request). If you held the floor, the next participant in the queue is promoted automatically. Returns the new holder and queue.",
|
|
118
|
+
inputSchema: mTALK_release_input,
|
|
119
|
+
handler: mTALK_release as MosaddTool["handler"],
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: "mTALK_state",
|
|
123
|
+
title: "Read PTT floor state",
|
|
124
|
+
annotations: { readOnlyHint: true },
|
|
125
|
+
requires: "any",
|
|
126
|
+
description:
|
|
127
|
+
"Read a PTT room's floor state without changing it: who is currently transmitting (holder), since when, and the waiting queue.",
|
|
128
|
+
inputSchema: mTALK_state_input,
|
|
129
|
+
handler: mTALK_state as MosaddTool["handler"],
|
|
130
|
+
},
|
|
131
|
+
];
|
|
@@ -0,0 +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
|
+
];
|