@mosadd/mcp 3.0.0-alpha.3 → 3.0.0-alpha.30
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 +212 -0
- package/README.md +150 -116
- package/dist/bin/mcp.js +42 -3
- package/dist/chunk-6PGDNIKR.js +2556 -0
- package/dist/index.d.ts +99 -7
- package/dist/index.js +7 -3
- package/package.json +10 -7
- package/src/__tests__/golden-path.test.ts +137 -132
- package/src/__tests__/integration.test.ts +179 -175
- package/src/__tests__/mdm-e2ee.test.ts +212 -149
- package/src/__tests__/mtalk.test.ts +122 -0
- package/src/__tests__/server.test.ts +71 -67
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -97
- package/src/config.ts +66 -66
- package/src/crypto/mdm-session.ts +502 -378
- 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 -0
- package/src/providers/supabase-dm.ts +122 -117
- package/src/providers/supabase-voice.ts +91 -0
- package/src/providers/supabase.ts +148 -96
- package/src/server.ts +123 -103
- package/src/tools/actions.ts +162 -0
- package/src/tools/attachments.ts +268 -0
- package/src/tools/capabilities.ts +68 -68
- package/src/tools/embed.ts +108 -0
- package/src/tools/index.ts +104 -37
- package/src/tools/knowledge.ts +191 -0
- package/src/tools/mail-aliases.ts +25 -0
- package/src/tools/mail-provenance.ts +135 -0
- package/src/tools/mail.ts +381 -89
- package/src/tools/mcall.ts +216 -0
- package/src/tools/mdm-voice.ts +212 -0
- package/src/tools/mdm.ts +479 -379
- package/src/tools/mirc-edge.ts +190 -0
- package/src/tools/mirc-members.ts +198 -177
- package/src/tools/mirc-messages.ts +155 -0
- package/src/tools/mirc.ts +190 -170
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +221 -189
- package/src/tools/mtalk.ts +121 -0
- package/src/tools/murl.ts +298 -0
- package/src/tools/ptt-ingest.ts +97 -0
- package/src/tools/threat.ts +119 -0
- package/src/types.ts +94 -79
- package/src/voice/floor.ts +132 -0
- package/dist/chunk-HD5RLE5K.js +0 -1193
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mCALL — Outbound PSTN calls.
|
|
3
|
+
*
|
|
4
|
+
* Place a real phone call (E.164) from an agent. Control plane is MCP; audio
|
|
5
|
+
* never flows through the tool call — it is bridged over LiveKit SIP (primary)
|
|
6
|
+
* or a Telnyx fallback to the carrier, with an optional voice vocoder.
|
|
7
|
+
*
|
|
8
|
+
* Wired to the m0ssad-3 `call-start-pstn` / `call-end-pstn` Edge Functions
|
|
9
|
+
* (deployed). A carrier must be wired server-side (LIVEKIT_SIP_TRUNK_ID, or
|
|
10
|
+
* TELNYX_API_KEY + TELNYX_CONNECTION_ID + TELNYX_FROM_NUMBER); until then the
|
|
11
|
+
* call session is created and metered but no audio leg is bridged.
|
|
12
|
+
*
|
|
13
|
+
* NOTE: mCALL is the telephone (PSTN). For 1:1 in-app voice use mDM; for
|
|
14
|
+
* walkie-talkie / floor-controlled voice use mTALK.
|
|
15
|
+
*
|
|
16
|
+
* Burner numbers: mCALL_acquire_number leases an ephemeral DID (~10 min) that
|
|
17
|
+
* becomes your outbound caller-ID and can receive inbound calls. Inbound rings
|
|
18
|
+
* are delivered out-of-band (Supabase Realtime broadcast on
|
|
19
|
+
* `mcall-inbound-<identity_id>`, or an integrator webhook) carrying a room_name;
|
|
20
|
+
* mCALL_answer mints the LiveKit token to join and bridge that call. Pair with
|
|
21
|
+
* the `vocoder` flag / a published vocoder track to mask the caller's voice.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { z } from "zod";
|
|
25
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
26
|
+
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
27
|
+
|
|
28
|
+
// ---- Schemas ----
|
|
29
|
+
|
|
30
|
+
const E164 = z
|
|
31
|
+
.string()
|
|
32
|
+
.regex(/^\+\d{7,15}$/)
|
|
33
|
+
.describe("Destination phone number in E.164 format, e.g. +14155550123.");
|
|
34
|
+
|
|
35
|
+
const mCALL_start_pstn_input = z.object({
|
|
36
|
+
to: E164,
|
|
37
|
+
vocoder: z
|
|
38
|
+
.boolean()
|
|
39
|
+
.optional()
|
|
40
|
+
.describe("Disguise the caller's voice with a vocoder (anonymous calling). Default false."),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const mCALL_end_pstn_input = z.object({
|
|
44
|
+
session_id: z.string().min(1).describe("Session id returned by mCALL_start_pstn."),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// ---- Burner (ephemeral number) schemas ----
|
|
48
|
+
|
|
49
|
+
const mCALL_acquire_number_input = z.object({}).describe(
|
|
50
|
+
"No parameters. Leases the next available number for ~10 minutes (idempotent: returns your live lease if you already hold one).",
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const mCALL_my_numbers_input = z.object({}).describe("No parameters.");
|
|
54
|
+
|
|
55
|
+
const mCALL_extend_number_input = z.object({
|
|
56
|
+
number_id: z
|
|
57
|
+
.string()
|
|
58
|
+
.optional()
|
|
59
|
+
.describe("Pool id of the number to extend. Omit to extend your current lease."),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const mCALL_release_number_input = z.object({
|
|
63
|
+
number_id: z
|
|
64
|
+
.string()
|
|
65
|
+
.optional()
|
|
66
|
+
.describe("Pool id of the number to release. Omit to release all numbers you hold."),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const mCALL_answer_input = z.object({
|
|
70
|
+
room_name: z
|
|
71
|
+
.string()
|
|
72
|
+
.min(1)
|
|
73
|
+
.describe("room_name from an inbound_call event (Realtime broadcast / integrator webhook)."),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// ---- Handlers ----
|
|
77
|
+
|
|
78
|
+
async function mCALL_start_pstn(
|
|
79
|
+
input: z.infer<typeof mCALL_start_pstn_input>,
|
|
80
|
+
ctx: MosaddToolContext,
|
|
81
|
+
): Promise<{
|
|
82
|
+
session_id: string;
|
|
83
|
+
room_name: string;
|
|
84
|
+
destination_number: string;
|
|
85
|
+
vocoder_enabled: boolean;
|
|
86
|
+
minutes_remaining: number;
|
|
87
|
+
zone: string;
|
|
88
|
+
zone_label: string;
|
|
89
|
+
}> {
|
|
90
|
+
readSupabaseEnv();
|
|
91
|
+
ctx.log("debug", "mCALL_start_pstn invoking call-start-pstn", { to: input.to });
|
|
92
|
+
return await invokeFunction("call-start-pstn", {
|
|
93
|
+
destination_number: input.to,
|
|
94
|
+
vocoder_enabled: input.vocoder ?? false,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function mCALL_end_pstn(
|
|
99
|
+
input: z.infer<typeof mCALL_end_pstn_input>,
|
|
100
|
+
ctx: MosaddToolContext,
|
|
101
|
+
): Promise<{ duration_ms: number; cost_credits: number }> {
|
|
102
|
+
readSupabaseEnv();
|
|
103
|
+
ctx.log("debug", "mCALL_end_pstn invoking call-end-pstn", { session_id: input.session_id });
|
|
104
|
+
return await invokeFunction("call-end-pstn", { session_id: input.session_id });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ---- Burner (ephemeral number) handlers ----
|
|
108
|
+
|
|
109
|
+
interface AcquiredNumber {
|
|
110
|
+
did: { id: string; phone_number: string; hold_until: string | null };
|
|
111
|
+
reused: boolean;
|
|
112
|
+
hold_until: string;
|
|
113
|
+
seconds_remaining: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function mCALL_acquire_number(
|
|
117
|
+
_input: z.infer<typeof mCALL_acquire_number_input>,
|
|
118
|
+
ctx: MosaddToolContext,
|
|
119
|
+
): Promise<AcquiredNumber> {
|
|
120
|
+
readSupabaseEnv();
|
|
121
|
+
ctx.log("debug", "mCALL_acquire_number invoking call-did-pool acquire");
|
|
122
|
+
return await invokeFunction("call-did-pool", { action: "acquire" });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function mCALL_my_numbers(
|
|
126
|
+
_input: z.infer<typeof mCALL_my_numbers_input>,
|
|
127
|
+
ctx: MosaddToolContext,
|
|
128
|
+
): Promise<{ numbers: Array<{ id: string; phone_number: string; seconds_remaining: number | null }> }> {
|
|
129
|
+
readSupabaseEnv();
|
|
130
|
+
ctx.log("debug", "mCALL_my_numbers invoking call-did-pool mine");
|
|
131
|
+
return await invokeFunction("call-did-pool", { action: "mine" });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function mCALL_extend_number(
|
|
135
|
+
input: z.infer<typeof mCALL_extend_number_input>,
|
|
136
|
+
ctx: MosaddToolContext,
|
|
137
|
+
): Promise<{ did: unknown; hold_until: string; seconds_remaining: number }> {
|
|
138
|
+
readSupabaseEnv();
|
|
139
|
+
ctx.log("debug", "mCALL_extend_number invoking call-did-pool extend", { number_id: input.number_id });
|
|
140
|
+
return await invokeFunction("call-did-pool", { action: "extend", did_id: input.number_id });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function mCALL_release_number(
|
|
144
|
+
input: z.infer<typeof mCALL_release_number_input>,
|
|
145
|
+
ctx: MosaddToolContext,
|
|
146
|
+
): Promise<{ released: number; dids: unknown[] }> {
|
|
147
|
+
readSupabaseEnv();
|
|
148
|
+
ctx.log("debug", "mCALL_release_number invoking call-did-pool release_mine", { number_id: input.number_id });
|
|
149
|
+
return await invokeFunction("call-did-pool", { action: "release_mine", did_id: input.number_id });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function mCALL_answer(
|
|
153
|
+
input: z.infer<typeof mCALL_answer_input>,
|
|
154
|
+
ctx: MosaddToolContext,
|
|
155
|
+
): Promise<{ token: string; url: string; roomName: string; identity: string }> {
|
|
156
|
+
readSupabaseEnv();
|
|
157
|
+
ctx.log("debug", "mCALL_answer minting livekit token", { room_name: input.room_name });
|
|
158
|
+
return await invokeFunction("livekit-token", { roomName: input.room_name });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ---- Registration ----
|
|
162
|
+
|
|
163
|
+
export const mcallTools: MosaddTool[] = [
|
|
164
|
+
{
|
|
165
|
+
name: "mCALL_start_pstn",
|
|
166
|
+
requires: "network",
|
|
167
|
+
description:
|
|
168
|
+
"Place an outbound PSTN phone call to an E.164 number. Bridges audio over an encrypted SIP relay (LiveKit SIP / Telnyx); optional voice vocoder for anonymous calling. Returns session_id, room_name, zone + per-minute cost, and minutes_remaining. Requires PSTN minutes in the wallet.",
|
|
169
|
+
inputSchema: mCALL_start_pstn_input,
|
|
170
|
+
handler: mCALL_start_pstn as MosaddTool["handler"],
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: "mCALL_end_pstn",
|
|
174
|
+
requires: "network",
|
|
175
|
+
description: "End an active PSTN call by session_id. Returns call duration and credits spent.",
|
|
176
|
+
inputSchema: mCALL_end_pstn_input,
|
|
177
|
+
handler: mCALL_end_pstn as MosaddTool["handler"],
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: "mCALL_acquire_number",
|
|
181
|
+
requires: "network",
|
|
182
|
+
description:
|
|
183
|
+
"Lease an ephemeral 'burner' phone number for ~10 minutes. While held, it is presented as your caller-ID on mCALL_start_pstn and can receive inbound calls; it auto-recycles when the lease lapses (unless on a live call). Idempotent — returns your existing lease if you already hold one. Returns the number, hold_until and seconds_remaining.",
|
|
184
|
+
inputSchema: mCALL_acquire_number_input,
|
|
185
|
+
handler: mCALL_acquire_number as MosaddTool["handler"],
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: "mCALL_my_numbers",
|
|
189
|
+
requires: "network",
|
|
190
|
+
description: "List the ephemeral numbers currently leased to you, each with its seconds_remaining.",
|
|
191
|
+
inputSchema: mCALL_my_numbers_input,
|
|
192
|
+
handler: mCALL_my_numbers as MosaddTool["handler"],
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: "mCALL_extend_number",
|
|
196
|
+
requires: "network",
|
|
197
|
+
description: "Extend the lease on a held ephemeral number by another ~10 minutes (by number_id, or your current lease).",
|
|
198
|
+
inputSchema: mCALL_extend_number_input,
|
|
199
|
+
handler: mCALL_extend_number as MosaddTool["handler"],
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
name: "mCALL_release_number",
|
|
203
|
+
requires: "network",
|
|
204
|
+
description: "Release an ephemeral number back to the pool before its lease expires (by number_id, or all you hold).",
|
|
205
|
+
inputSchema: mCALL_release_number_input,
|
|
206
|
+
handler: mCALL_release_number as MosaddTool["handler"],
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: "mCALL_answer",
|
|
210
|
+
requires: "network",
|
|
211
|
+
description:
|
|
212
|
+
"Answer an inbound call to your burner number. Pass the room_name from the inbound_call event; returns a LiveKit token + url so your client joins the room and bridges audio (publish a vocoder track to mask your voice on answer).",
|
|
213
|
+
inputSchema: mCALL_answer_input,
|
|
214
|
+
handler: mCALL_answer as MosaddTool["handler"],
|
|
215
|
+
},
|
|
216
|
+
];
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mDM — 1:1 voice (full-duplex call + voice note).
|
|
3
|
+
*
|
|
4
|
+
* mDM is the PRIVATE channel: 1:1 / threaded text (mdm.ts) PLUS real-time 1:1
|
|
5
|
+
* voice here. This is the ordinary phone-style call between two people — NOT
|
|
6
|
+
* walkie-talkie (that's mTALK, half-duplex floor control) and NOT the telephone
|
|
7
|
+
* network (that's mCALL / PSTN). Audio rides the same media transport the
|
|
8
|
+
* VoiceProvider points at (LiveKit by default); these tools coordinate the room
|
|
9
|
+
* and the call invite/hangup signalling over the DM channel.
|
|
10
|
+
*
|
|
11
|
+
* Flow:
|
|
12
|
+
* caller: mDM_call_start({ to }) → creates a room, returns join creds, AND
|
|
13
|
+
* drops a `call_invite` control message in the DM thread.
|
|
14
|
+
* callee: sees the invite (mDM_list), then mDM_call_answer({ room_id }) → creds.
|
|
15
|
+
* either: mDM_call_end({ room_id, to }) → drops a `call_end` control message.
|
|
16
|
+
*
|
|
17
|
+
* No new backend: rooms + tokens come from ctx.providers.voice (same minting
|
|
18
|
+
* path mTALK uses); signalling reuses ctx.providers.dm.send.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { z } from "zod";
|
|
22
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
23
|
+
|
|
24
|
+
const PROTOCOL_VERSION = "mosadd.chat.v1";
|
|
25
|
+
|
|
26
|
+
const ContactRef = z
|
|
27
|
+
.string()
|
|
28
|
+
.min(1)
|
|
29
|
+
.describe("Recipient identity id (UUID). Use mDM_list_contacts to find it.");
|
|
30
|
+
|
|
31
|
+
const RoomId = z.string().min(1).describe("Voice room id (from mDM_call_start's call_invite).");
|
|
32
|
+
|
|
33
|
+
const mDM_call_start_input = z.object({
|
|
34
|
+
to: ContactRef,
|
|
35
|
+
video: z.boolean().optional().describe("Request a video call instead of audio-only. Default false."),
|
|
36
|
+
thread_label: z
|
|
37
|
+
.string()
|
|
38
|
+
.max(120)
|
|
39
|
+
.regex(/^[a-zA-Z0-9._-]+$/)
|
|
40
|
+
.optional()
|
|
41
|
+
.describe("Optional thread label to place the call invite in. Defaults to the contact's main thread."),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const mDM_call_answer_input = z.object({ room_id: RoomId });
|
|
45
|
+
|
|
46
|
+
const mDM_call_end_input = z.object({
|
|
47
|
+
room_id: RoomId,
|
|
48
|
+
to: ContactRef.optional().describe("If set, also drop a call_end control message in this contact's DM thread."),
|
|
49
|
+
thread_label: z.string().max(120).regex(/^[a-zA-Z0-9._-]+$/).optional(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const mDM_voice_note_input = z.object({
|
|
53
|
+
to: ContactRef,
|
|
54
|
+
audio_url: z.string().url().describe("URL of the recorded audio clip (already uploaded by the client)."),
|
|
55
|
+
duration_ms: z.number().int().positive().optional().describe("Clip length in milliseconds, if known."),
|
|
56
|
+
mime: z.string().max(120).optional().describe("Audio MIME type, e.g. audio/ogg, audio/mpeg. Default audio/ogg."),
|
|
57
|
+
thread_label: z.string().max(120).regex(/^[a-zA-Z0-9._-]+$/).optional(),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// ---- Helpers ----
|
|
61
|
+
|
|
62
|
+
/** Deterministic DM thread id (sorted pair) — must match mdm.ts dmThreadId. */
|
|
63
|
+
function dmThreadId(selfId: string, otherId: string, label?: string): string {
|
|
64
|
+
const [a, b] = [selfId, otherId].sort();
|
|
65
|
+
return label ? `dm:${a}:${b}:${label}` : `dm:${a}:${b}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Pack a mosadd.chat.v1 control/voice envelope into the opaque payload bytes. */
|
|
69
|
+
function packEnvelope(obj: Record<string, unknown>): Uint8Array {
|
|
70
|
+
const envelope = { v: PROTOCOL_VERSION, sent_at: new Date().toISOString(), ...obj };
|
|
71
|
+
return new Uint8Array(Buffer.from(JSON.stringify(envelope), "utf8"));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function signalDm(
|
|
75
|
+
ctx: MosaddToolContext,
|
|
76
|
+
to: string,
|
|
77
|
+
threadLabel: string | undefined,
|
|
78
|
+
envelope: Record<string, unknown>,
|
|
79
|
+
): Promise<{ message_id?: string; thread_id: string }> {
|
|
80
|
+
const dm = ctx.providers.dm;
|
|
81
|
+
const selfId = await dm.selfId();
|
|
82
|
+
const threadId = dmThreadId(selfId, to, threadLabel);
|
|
83
|
+
// DmProvider.send returns DmSendResult { id, deliveredAt } — read `id` (the old
|
|
84
|
+
// `message_id` lookup was always undefined, so the echoed id never populated).
|
|
85
|
+
const res = await dm.send({ to, threadId, payload: packEnvelope(envelope) });
|
|
86
|
+
return { message_id: (res as { id?: string })?.id, thread_id: threadId };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ---- Handlers ----
|
|
90
|
+
|
|
91
|
+
async function mDM_call_start(
|
|
92
|
+
input: z.infer<typeof mDM_call_start_input>,
|
|
93
|
+
ctx: MosaddToolContext,
|
|
94
|
+
): Promise<{
|
|
95
|
+
room_id: string;
|
|
96
|
+
token: string;
|
|
97
|
+
url: string;
|
|
98
|
+
identity: string;
|
|
99
|
+
mode: "audio" | "video";
|
|
100
|
+
invited: boolean;
|
|
101
|
+
thread_id: string;
|
|
102
|
+
}> {
|
|
103
|
+
const dm = ctx.providers.dm;
|
|
104
|
+
const selfId = await dm.selfId();
|
|
105
|
+
const mode = input.video ? "video" : "audio";
|
|
106
|
+
|
|
107
|
+
// Stable room label tied to the DM PAIR (no thread_label) so re-dials reuse one
|
|
108
|
+
// room AND the name stays short enough that both participants' full identity ids
|
|
109
|
+
// are always present — the livekit-token gate authorizes by full-id inclusion, so
|
|
110
|
+
// truncating an id would lock a real participant out. (thread_label still routes
|
|
111
|
+
// the call_invite message below, just not the room id.)
|
|
112
|
+
const label = `dmcall-${dmThreadId(selfId, input.to).replace(/[^a-zA-Z0-9._-]/g, "-")}`.slice(0, 120);
|
|
113
|
+
const { roomId } = await ctx.providers.voice.createRoom(label);
|
|
114
|
+
const ticket = await ctx.providers.voice.joinTicket(roomId);
|
|
115
|
+
|
|
116
|
+
let invited = false;
|
|
117
|
+
let thread_id = dmThreadId(selfId, input.to, input.thread_label);
|
|
118
|
+
try {
|
|
119
|
+
const sig = await signalDm(ctx, input.to, input.thread_label, {
|
|
120
|
+
type: "call_invite",
|
|
121
|
+
room_id: roomId,
|
|
122
|
+
mode,
|
|
123
|
+
from: selfId,
|
|
124
|
+
});
|
|
125
|
+
thread_id = sig.thread_id;
|
|
126
|
+
invited = true;
|
|
127
|
+
} catch (e) {
|
|
128
|
+
ctx.log("warn", "mDM_call_start: invite signal failed (room still usable)", {
|
|
129
|
+
error: (e as Error).message,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
ctx.log("debug", "mDM_call_start", { room_id: roomId, mode, invited });
|
|
134
|
+
return { room_id: roomId, token: ticket.token, url: ticket.url, identity: ticket.identity, mode, invited, thread_id };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function mDM_call_answer(
|
|
138
|
+
input: z.infer<typeof mDM_call_answer_input>,
|
|
139
|
+
ctx: MosaddToolContext,
|
|
140
|
+
): Promise<{ room_id: string; token: string; url: string; identity: string }> {
|
|
141
|
+
const ticket = await ctx.providers.voice.joinTicket(input.room_id);
|
|
142
|
+
ctx.log("debug", "mDM_call_answer", { room_id: ticket.roomId, identity: ticket.identity });
|
|
143
|
+
return { room_id: ticket.roomId, token: ticket.token, url: ticket.url, identity: ticket.identity };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function mDM_call_end(
|
|
147
|
+
input: z.infer<typeof mDM_call_end_input>,
|
|
148
|
+
ctx: MosaddToolContext,
|
|
149
|
+
): Promise<{ room_id: string; signalled: boolean }> {
|
|
150
|
+
let signalled = false;
|
|
151
|
+
if (input.to) {
|
|
152
|
+
try {
|
|
153
|
+
await signalDm(ctx, input.to, input.thread_label, { type: "call_end", room_id: input.room_id });
|
|
154
|
+
signalled = true;
|
|
155
|
+
} catch (e) {
|
|
156
|
+
ctx.log("warn", "mDM_call_end: hangup signal failed", { error: (e as Error).message });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
ctx.log("debug", "mDM_call_end", { room_id: input.room_id, signalled });
|
|
160
|
+
return { room_id: input.room_id, signalled };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function mDM_voice_note(
|
|
164
|
+
input: z.infer<typeof mDM_voice_note_input>,
|
|
165
|
+
ctx: MosaddToolContext,
|
|
166
|
+
): Promise<{ message_id?: string; thread_id: string }> {
|
|
167
|
+
const sig = await signalDm(ctx, input.to, input.thread_label, {
|
|
168
|
+
type: "voice_note",
|
|
169
|
+
audio_url: input.audio_url,
|
|
170
|
+
duration_ms: input.duration_ms ?? null,
|
|
171
|
+
mime: input.mime ?? "audio/ogg",
|
|
172
|
+
});
|
|
173
|
+
ctx.log("debug", "mDM_voice_note", { thread_id: sig.thread_id });
|
|
174
|
+
return sig;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ---- Registration ----
|
|
178
|
+
|
|
179
|
+
export const mdmVoiceTools: MosaddTool[] = [
|
|
180
|
+
{
|
|
181
|
+
name: "mDM_call_start",
|
|
182
|
+
requires: "network",
|
|
183
|
+
description:
|
|
184
|
+
"Start a 1:1 real-time voice (or video) call with a contact — the ordinary full-duplex phone-style call (NOT walkie-talkie mTALK, NOT PSTN mCALL). Creates a room, returns join credentials (token + media url), and drops a `call_invite` control message in the DM thread so the contact can answer. Set video:true for video.",
|
|
185
|
+
inputSchema: mDM_call_start_input,
|
|
186
|
+
handler: mDM_call_start as MosaddTool["handler"],
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: "mDM_call_answer",
|
|
190
|
+
requires: "network",
|
|
191
|
+
description:
|
|
192
|
+
"Answer an incoming 1:1 call by its room_id (from the call_invite seen via mDM_list). Returns join credentials (token + media url) for the same room.",
|
|
193
|
+
inputSchema: mDM_call_answer_input,
|
|
194
|
+
handler: mDM_call_answer as MosaddTool["handler"],
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: "mDM_call_end",
|
|
198
|
+
requires: "network",
|
|
199
|
+
description:
|
|
200
|
+
"End a 1:1 call. The audio leg ends when clients disconnect; pass `to` to also drop a `call_end` (hangup) control message in the contact's DM thread.",
|
|
201
|
+
inputSchema: mDM_call_end_input,
|
|
202
|
+
handler: mDM_call_end as MosaddTool["handler"],
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: "mDM_voice_note",
|
|
206
|
+
requires: "network",
|
|
207
|
+
description:
|
|
208
|
+
"Send an asynchronous voice note to a contact: references an already-uploaded audio clip (audio_url) and posts it as a `voice_note` message in the DM thread. Use for fire-and-forget voice instead of a live call.",
|
|
209
|
+
inputSchema: mDM_voice_note_input,
|
|
210
|
+
handler: mDM_voice_note as MosaddTool["handler"],
|
|
211
|
+
},
|
|
212
|
+
];
|