@mosadd/mcp 3.0.0-alpha.2 → 3.0.0-alpha.20
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 +120 -0
- package/README.md +141 -116
- package/dist/bin/mcp.js +70 -3
- package/dist/chunk-FZNAGICW.js +2353 -0
- package/dist/index.d.ts +62 -4
- package/dist/index.js +5 -3
- package/package.json +10 -5
- package/src/__tests__/golden-path.test.ts +137 -132
- package/src/__tests__/integration.test.ts +178 -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 -55
- package/src/config.ts +66 -66
- package/src/crypto/mdm-session.ts +403 -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 +120 -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 +72 -37
- package/src/tools/knowledge.ts +191 -0
- package/src/tools/mail-provenance.ts +137 -0
- package/src/tools/mail.ts +378 -89
- package/src/tools/mcall.ts +216 -0
- package/src/tools/mdm-voice.ts +206 -0
- package/src/tools/mdm.ts +451 -379
- package/src/tools/mirc-edge.ts +190 -0
- package/src/tools/mirc-members.ts +188 -177
- package/src/tools/mirc-messages.ts +159 -0
- package/src/tools/mirc.ts +174 -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 +195 -0
- package/src/tools/ptt-ingest.ts +91 -0
- package/src/tools/threat.ts +92 -0
- package/src/types.ts +94 -79
- package/src/voice/floor.ts +132 -0
- package/dist/chunk-HD5RLE5K.js +0 -1193
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mTALK floor control — the half-duplex push-to-talk state machine.
|
|
3
|
+
*
|
|
4
|
+
* This is the kill-feature logic: a walkie-talkie discipline over a real-time
|
|
5
|
+
* room. At most ONE participant transmits at a time (holds "the floor"); others
|
|
6
|
+
* who press PTT are queued FIFO and promoted when the holder releases. An
|
|
7
|
+
* anti-hog timeout auto-releases a holder who never lets go, so one participant
|
|
8
|
+
* can't lock everyone else out.
|
|
9
|
+
*
|
|
10
|
+
* It is a PURE, deterministic reducer over plain data — no I/O, no clock of its
|
|
11
|
+
* own (the caller passes `now`). That makes it:
|
|
12
|
+
* - the reference implementation the authoritative server (mtalk-floor edge
|
|
13
|
+
* function) runs per room, and
|
|
14
|
+
* - trivially unit-testable, and
|
|
15
|
+
* - reusable by an in-memory provider for local/off-grid and for tests.
|
|
16
|
+
*
|
|
17
|
+
* A radio host does NOT use this — there the floor is the physical RF channel
|
|
18
|
+
* (carrier sense + the hardware PTT button). This models the NETWORK floor.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type { FloorSnapshot } from "@mosadd/providers";
|
|
22
|
+
|
|
23
|
+
/** Serializable floor state for one room. `since` is epoch ms (number) here; the snapshot exposes ISO. */
|
|
24
|
+
export interface FloorState {
|
|
25
|
+
roomId: string;
|
|
26
|
+
holder: string | null;
|
|
27
|
+
/** Epoch ms when the holder acquired the floor; null when idle. */
|
|
28
|
+
sinceMs: number | null;
|
|
29
|
+
queue: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Max ms a holder may keep the floor before auto-release (anti-hog). 0/undefined
|
|
32
|
+
* disables the timeout. Default applied by `createFloorState`.
|
|
33
|
+
*/
|
|
34
|
+
maxHoldMs: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Default anti-hog ceiling: 30s of continuous transmission, like a real PTT radio. */
|
|
38
|
+
export const DEFAULT_MAX_HOLD_MS = 30_000;
|
|
39
|
+
|
|
40
|
+
export function createFloorState(roomId: string, maxHoldMs: number = DEFAULT_MAX_HOLD_MS): FloorState {
|
|
41
|
+
return { roomId, holder: null, sinceMs: null, queue: [], maxHoldMs };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function toSnapshot(state: FloorState): FloorSnapshot {
|
|
45
|
+
return {
|
|
46
|
+
roomId: state.roomId,
|
|
47
|
+
holder: state.holder,
|
|
48
|
+
since: state.sinceMs === null ? null : new Date(state.sinceMs).toISOString(),
|
|
49
|
+
queue: [...state.queue],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Auto-release the holder if they've exceeded the anti-hog ceiling, promoting
|
|
55
|
+
* the next queued participant. Idempotent; call before any decision so a stale
|
|
56
|
+
* holder never blocks a fresh request. Mutates and returns `state`.
|
|
57
|
+
*/
|
|
58
|
+
export function expireStale(state: FloorState, now: number): FloorState {
|
|
59
|
+
if (
|
|
60
|
+
state.holder !== null &&
|
|
61
|
+
state.maxHoldMs > 0 &&
|
|
62
|
+
state.sinceMs !== null &&
|
|
63
|
+
now - state.sinceMs >= state.maxHoldMs
|
|
64
|
+
) {
|
|
65
|
+
promoteNext(state, now);
|
|
66
|
+
}
|
|
67
|
+
return state;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Internal: clear the holder and promote the head of the queue (if any). */
|
|
71
|
+
function promoteNext(state: FloorState, now: number): void {
|
|
72
|
+
const next = state.queue.shift();
|
|
73
|
+
if (next !== undefined) {
|
|
74
|
+
state.holder = next;
|
|
75
|
+
state.sinceMs = now;
|
|
76
|
+
} else {
|
|
77
|
+
state.holder = null;
|
|
78
|
+
state.sinceMs = null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface RequestOutcome {
|
|
83
|
+
granted: boolean;
|
|
84
|
+
/** 1-based queue position when not granted; 0 when granted. */
|
|
85
|
+
position: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Press PTT. Grants the floor if idle (or refreshes if the caller already holds
|
|
90
|
+
* it); otherwise enqueues FIFO and reports the caller's position. Mutates state.
|
|
91
|
+
*/
|
|
92
|
+
export function requestFloor(state: FloorState, participant: string, now: number): RequestOutcome {
|
|
93
|
+
expireStale(state, now);
|
|
94
|
+
|
|
95
|
+
if (state.holder === null) {
|
|
96
|
+
state.holder = participant;
|
|
97
|
+
state.sinceMs = now;
|
|
98
|
+
// Acquiring clears any prior queued entry for this participant.
|
|
99
|
+
state.queue = state.queue.filter((p) => p !== participant);
|
|
100
|
+
return { granted: true, position: 0 };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (state.holder === participant) {
|
|
104
|
+
// Holding PTT down — refresh the hold so a long legitimate transmission
|
|
105
|
+
// isn't cut by the anti-hog timer mid-sentence.
|
|
106
|
+
state.sinceMs = now;
|
|
107
|
+
return { granted: true, position: 0 };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Someone else holds the floor → queue (idempotent: no duplicate entries).
|
|
111
|
+
const existing = state.queue.indexOf(participant);
|
|
112
|
+
if (existing !== -1) return { granted: false, position: existing + 1 };
|
|
113
|
+
state.queue.push(participant);
|
|
114
|
+
return { granted: false, position: state.queue.length };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Release PTT. If the caller holds the floor, it's freed and the next queued
|
|
119
|
+
* participant is promoted. If the caller is only queued, their request is
|
|
120
|
+
* cancelled. No-op otherwise. Mutates state.
|
|
121
|
+
*/
|
|
122
|
+
export function releaseFloor(state: FloorState, participant: string, now: number): FloorState {
|
|
123
|
+
expireStale(state, now);
|
|
124
|
+
|
|
125
|
+
if (state.holder === participant) {
|
|
126
|
+
promoteNext(state, now);
|
|
127
|
+
return state;
|
|
128
|
+
}
|
|
129
|
+
// Not holding — cancel a pending queued request if present.
|
|
130
|
+
state.queue = state.queue.filter((p) => p !== participant);
|
|
131
|
+
return state;
|
|
132
|
+
}
|