@mosadd/mcp 3.0.0-alpha.52 → 3.0.0-alpha.54
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 +363 -309
- package/README.md +150 -150
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-KVN7LZFW.js → chunk-3PUOM4R5.js} +470 -112
- package/dist/index.d.ts +11 -1
- package/dist/index.js +1 -1
- package/package.json +9 -9
- package/src/__tests__/golden-path.test.ts +139 -139
- package/src/__tests__/integration.test.ts +182 -182
- package/src/__tests__/knowledge-ingest.test.ts +114 -114
- package/src/__tests__/mdm-e2ee.test.ts +212 -212
- package/src/__tests__/mdm-mcp-readable.test.ts +386 -0
- package/src/__tests__/mirc-invite.test.ts +112 -112
- package/src/__tests__/mtalk.test.ts +122 -122
- package/src/__tests__/server.test.ts +71 -71
- package/src/__tests__/serverJsonVersion.test.ts +45 -45
- package/src/__tests__/tool-count-consistency.test.ts +199 -199
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -145
- package/src/config.ts +66 -66
- package/src/crypto/mdm-session.ts +842 -502
- package/src/index.ts +19 -19
- package/src/observability/sentry.ts +79 -79
- package/src/providers/memory-voice.ts +79 -79
- package/src/providers/supabase-dm.ts +202 -122
- package/src/providers/supabase-voice.ts +91 -91
- package/src/providers/supabase.ts +231 -231
- package/src/server.ts +195 -162
- package/src/tools/__tests__/ragDeleteFoldsSourceId.test.ts +67 -67
- package/src/tools/actions.ts +166 -166
- package/src/tools/attachments.ts +276 -276
- package/src/tools/capabilities.ts +70 -70
- package/src/tools/embed.ts +110 -110
- package/src/tools/index.ts +181 -181
- package/src/tools/knowledge-graph.ts +186 -186
- package/src/tools/knowledge.ts +344 -344
- package/src/tools/mail-agentbox.ts +155 -155
- package/src/tools/mail-aliases.ts +25 -25
- package/src/tools/mail-provenance.ts +137 -137
- package/src/tools/mail.ts +403 -403
- 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 +211 -29
- package/src/tools/mirc-edge.ts +196 -196
- package/src/tools/mirc-members.ts +287 -287
- package/src/tools/mirc.ts +308 -308
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +221 -221
- package/src/tools/mtalk.ts +131 -131
- package/src/tools/murl.ts +314 -314
- package/src/tools/presence.ts +442 -442
- package/src/tools/ptt-ingest.ts +99 -99
- package/src/tools/threat.ts +123 -123
- package/src/types.ts +121 -121
- package/src/version.ts +8 -8
- package/src/voice/floor.ts +132 -132
- package/LICENSE +0 -201
package/src/server.ts
CHANGED
|
@@ -1,162 +1,195 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Build a McpServer instance with all mosadd tools registered.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
-
import { allTools } from "./tools/index.js";
|
|
7
|
-
import { autoBeatFromActivity } from "./tools/presence.js";
|
|
8
|
-
import { PKG_VERSION } from "./version.js";
|
|
9
|
-
import { SupabaseDmProvider } from "./providers/supabase-dm.js";
|
|
10
|
-
import { SupabaseVoiceProvider } from "./providers/supabase-voice.js";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Build a McpServer instance with all mosadd tools registered.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
+
import { allTools } from "./tools/index.js";
|
|
7
|
+
import { autoBeatFromActivity } from "./tools/presence.js";
|
|
8
|
+
import { PKG_VERSION } from "./version.js";
|
|
9
|
+
import { SupabaseDmProvider } from "./providers/supabase-dm.js";
|
|
10
|
+
import { SupabaseVoiceProvider } from "./providers/supabase-voice.js";
|
|
11
|
+
import {
|
|
12
|
+
InMemoryMdmKeyStore,
|
|
13
|
+
SecretMdmKeyStore,
|
|
14
|
+
bundlePolicyForKind,
|
|
15
|
+
ensureOwnBundlePublished,
|
|
16
|
+
} from "./crypto/mdm-session.js";
|
|
17
|
+
import type { MosaddServerOptions, MosaddToolContext, ProviderRegistry } from "./types.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the channel ProviderRegistry: default network adapters merged with
|
|
21
|
+
* anything the host injects. A carrier-aware host (cymru-os) passes its own
|
|
22
|
+
* radio DmProvider via `injected.dm`. This is the single place the default
|
|
23
|
+
* adapters are named — both `createMosaddServer` and the `@mosadd/ai` adapters
|
|
24
|
+
* build their context through it so they stay in lockstep.
|
|
25
|
+
*/
|
|
26
|
+
export function defaultProviders(
|
|
27
|
+
injected?: Partial<ProviderRegistry>,
|
|
28
|
+
opts: { mdmSecret?: string } = {},
|
|
29
|
+
): ProviderRegistry {
|
|
30
|
+
return {
|
|
31
|
+
dm: injected?.dm ?? new SupabaseDmProvider(),
|
|
32
|
+
keys: injected?.keys ?? defaultKeyStore(opts.mdmSecret),
|
|
33
|
+
voice: injected?.voice ?? new SupabaseVoiceProvider(),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* ⛔ ONE IDENTITY PER LOGIN SECRET, NOT ONE PER CALL (27.09.2026). With an API key the mDM
|
|
39
|
+
* identity is derived from it (SecretMdmKeyStore → SeededMdmKeyStore): the hosted gateway builds
|
|
40
|
+
* a new server per HTTP request, and with a random in-memory keystore every mDM_send was sealed
|
|
41
|
+
* by an identity that lived for one request. Without any secret (BYOK JWT only) there is nothing
|
|
42
|
+
* stable to derive from, so the old per-process random keystore remains.
|
|
43
|
+
*
|
|
44
|
+
* ⛔ STABLE PER KEY, NOT PER IDENTITY. One identity holds many keys (each OAuth connector mints
|
|
45
|
+
* its own), so this seed never publishes on its own authority: agent lines send in the clear and
|
|
46
|
+
* people keep the app's bundle (bundlePolicyForKind in crypto/mdm-session.ts).
|
|
47
|
+
*/
|
|
48
|
+
function defaultKeyStore(secret?: string) {
|
|
49
|
+
const s = (secret ?? "").trim();
|
|
50
|
+
return s ? new SecretMdmKeyStore(s) : new InMemoryMdmKeyStore();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function createMosaddServer(options: MosaddServerOptions = {}) {
|
|
54
|
+
const mode = options.mode ?? (options.apiKey ? "cloud" : "local");
|
|
55
|
+
const hubUrl = options.hubUrl ?? "https://mcp.mosadd.com";
|
|
56
|
+
const logLevel = options.logLevel ?? "info";
|
|
57
|
+
|
|
58
|
+
// DI seam: default network adapters, overridden by anything the host injects.
|
|
59
|
+
const providers = defaultProviders(options.providers, { mdmSecret: options.apiKey });
|
|
60
|
+
|
|
61
|
+
const ctx: MosaddToolContext = {
|
|
62
|
+
options: { ...options, mode, hubUrl },
|
|
63
|
+
providers,
|
|
64
|
+
log: (level, msg, extra) => {
|
|
65
|
+
if (shouldLog(level, logLevel)) {
|
|
66
|
+
// MCP servers must write logs to stderr (stdout is the protocol channel).
|
|
67
|
+
process.stderr.write(
|
|
68
|
+
JSON.stringify({ level, msg, extra, ts: new Date().toISOString() }) + "\n",
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Cold-start fix: make this identity reachable for inbound E2EE DMs the moment
|
|
75
|
+
// the server is up, so mDM_send works without every recipient first running
|
|
76
|
+
// mDM_publish_keys. Best-effort and non-fatal — it needs an authenticated
|
|
77
|
+
// session, so it silently skips when there is none (BYOK without a JWT, offline,
|
|
78
|
+
// etc.) and never blocks startup. Uses the SAME keystore the tools use, so the
|
|
79
|
+
// published identity matches what mDM_send/encryptForPeer will use this process.
|
|
80
|
+
//
|
|
81
|
+
// ⛔ ENSURE, NOT BLIND PUBLISH (27.09.2026, poprawka po weryfikacji): the policy is
|
|
82
|
+
// bundlePolicyForKind — the SAME one mDM_send uses. Agent line: writes NOTHING (it sends in the
|
|
83
|
+
// clear, rozkaz Krola 20.09; a per-key bundle from each of its keys only made the directory flap).
|
|
84
|
+
// Human: writes NOTHING (the app owns that bundle). Unknown kind (e.g. radio): empty -> publish.
|
|
85
|
+
if (options.autoPublishKeys) {
|
|
86
|
+
void (async () => {
|
|
87
|
+
const selfId = await providers.dm.selfId();
|
|
88
|
+
const kind = await (providers.dm as { selfKind?: () => Promise<string | null> }).selfKind?.();
|
|
89
|
+
return ensureOwnBundlePublished(providers.keys, providers.dm, selfId, bundlePolicyForKind(kind, { explicit: false }));
|
|
90
|
+
})()
|
|
91
|
+
.then((state) => ctx.log("debug", "auto-ensure mDM prekeys", { state }))
|
|
92
|
+
.catch((err) => ctx.log("debug", "auto-publish mDM prekeys skipped", { error: String(err) }));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const server = new McpServer(
|
|
96
|
+
{
|
|
97
|
+
name: "mosadd",
|
|
98
|
+
// Human-facing identity of the server itself (initialize result). The icon URLs
|
|
99
|
+
// point at the LIVE gateway origin on purpose: clients that honour serverInfo.icons
|
|
100
|
+
// get the brand mark without scraping the favicon, and the files ship with
|
|
101
|
+
// apps/mcp-http/public (canon 08-26 — generated by m0ssad-3 scripts/
|
|
102
|
+
// generate-brand-icons.py, never hand-edited).
|
|
103
|
+
title: "mosADD — omnichannel messenger for agents",
|
|
104
|
+
websiteUrl: "https://mosadd.com",
|
|
105
|
+
icons: [
|
|
106
|
+
{ src: "https://mcp.mosadd.com/favicon.svg", mimeType: "image/svg+xml", sizes: ["any"] },
|
|
107
|
+
{ src: "https://mcp.mosadd.com/pwa-192.png", mimeType: "image/png", sizes: ["192x192"] },
|
|
108
|
+
],
|
|
109
|
+
version: PKG_VERSION,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
capabilities: {
|
|
113
|
+
tools: {},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
for (const tool of allTools) {
|
|
119
|
+
// MCP SDK v1.x expects the field-level Zod shape (`{ to: z.string(), text: z.string() }`),
|
|
120
|
+
// not the wrapping `z.object({...})`. Tool inputs are declared as ZodObject schemas
|
|
121
|
+
// so we can `.parse()` them in the handler; surface the inner `.shape` to the SDK here.
|
|
122
|
+
const shape =
|
|
123
|
+
tool.inputSchema && typeof tool.inputSchema === "object" && "shape" in tool.inputSchema
|
|
124
|
+
? (tool.inputSchema as { shape: Record<string, unknown> }).shape
|
|
125
|
+
: (tool.inputSchema as unknown as Record<string, unknown>);
|
|
126
|
+
|
|
127
|
+
// Tool annotations ride the 5-arg overload (SDK ≥1.12 serialises them into
|
|
128
|
+
// tools/list verbatim). Without them EVERY tool lands in the connector UI's flat
|
|
129
|
+
// "Other tools" bucket — the exact founder complaint this fixes. `title` is spec'd
|
|
130
|
+
// inside ToolAnnotations, so it travels in the same object.
|
|
131
|
+
const annotations =
|
|
132
|
+
tool.title || tool.annotations
|
|
133
|
+
? { ...(tool.title ? { title: tool.title } : {}), ...(tool.annotations ?? {}) }
|
|
134
|
+
: undefined;
|
|
135
|
+
|
|
136
|
+
const toolCallback = async (input: unknown) => {
|
|
137
|
+
const parsed = tool.inputSchema.parse(input);
|
|
138
|
+
try {
|
|
139
|
+
const result = await tool.handler(parsed as never, ctx);
|
|
140
|
+
// AUTO-PAROWANIE (08-26): a LIVE session that is actually WORKING holds its line —
|
|
141
|
+
// the founder spent a week talking to cloud stand-ins because models never
|
|
142
|
+
// remembered the attach handshake. Fire-and-forget, throttled inside, never blocks
|
|
143
|
+
// the tool's own response; see autoBeatFromActivity for which line gets the beat.
|
|
144
|
+
void autoBeatFromActivity(ctx);
|
|
145
|
+
// A tool may return rich MCP content (e.g. an image frame from
|
|
146
|
+
// comms_action_frame_get) via `mcpContent`; pass it through verbatim.
|
|
147
|
+
const rich = result as { mcpContent?: unknown[] } | null;
|
|
148
|
+
if (rich && Array.isArray(rich.mcpContent)) {
|
|
149
|
+
return { content: rich.mcpContent as never[] };
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }],
|
|
153
|
+
};
|
|
154
|
+
} catch (err) {
|
|
155
|
+
ctx.log("error", `tool ${tool.name} failed`, { error: String(err) });
|
|
156
|
+
return {
|
|
157
|
+
isError: true,
|
|
158
|
+
content: [
|
|
159
|
+
{
|
|
160
|
+
type: "text" as const,
|
|
161
|
+
text: JSON.stringify({
|
|
162
|
+
error: err instanceof Error ? err.message : String(err),
|
|
163
|
+
tool: tool.name,
|
|
164
|
+
}),
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
if (annotations) {
|
|
172
|
+
server.tool(
|
|
173
|
+
tool.name,
|
|
174
|
+
tool.description,
|
|
175
|
+
shape as Parameters<typeof server.tool>[2],
|
|
176
|
+
annotations,
|
|
177
|
+
toolCallback,
|
|
178
|
+
);
|
|
179
|
+
} else {
|
|
180
|
+
server.tool(
|
|
181
|
+
tool.name,
|
|
182
|
+
tool.description,
|
|
183
|
+
shape as Parameters<typeof server.tool>[2],
|
|
184
|
+
toolCallback,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return server;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function shouldLog(level: string, threshold: string): boolean {
|
|
193
|
+
const order = { debug: 0, info: 1, warn: 2, error: 3 } as const;
|
|
194
|
+
return (order[level as keyof typeof order] ?? 1) >= (order[threshold as keyof typeof order] ?? 1);
|
|
195
|
+
}
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mRAG_delete MUSI foldować source_id dokładnie tak, jak robi to mRAG_ingest.
|
|
3
|
-
*
|
|
4
|
-
* ⛔ ZMIERZONA AWARIA (2026-08-28). `mRAG_ingest` przepuszczał nie-UUID przez `uuidV5`, a
|
|
5
|
-
* `mRAG_delete` wysyłał SUROWY napis prosto do kolumny UUID. Efekt na żywo:
|
|
6
|
-
*
|
|
7
|
-
* mRAG_ingest { source_id: "DIAG-GENERAL-2026-08-28-a1b2c3" } → { indexed: 1 } ✅
|
|
8
|
-
* mRAG_delete { source_id: "DIAG-GENERAL-2026-08-28-a1b2c3" } → 500
|
|
9
|
-
* "invalid input syntax for type uuid" ❌
|
|
10
|
-
*
|
|
11
|
-
* Czyli: dokument zaindeksowany pod NATURALNYM kluczem (numer sprawy, ścieżka pliku, threadId
|
|
12
|
-
* Gmaila) dawało się dodać, ale **nigdy nie dawało się go usunąć tym samym identyfikatorem**.
|
|
13
|
-
* Dwie połowy tej samej rury nie zgadzały się ze sobą.
|
|
14
|
-
*
|
|
15
|
-
* I to nie było niedopatrzenie w cieniu — obietnica stała w DWÓCH miejscach, a implementacja
|
|
16
|
-
* w jednym: komentarz przy foldowaniu mówi „so grouping and mRAG_delete keep working on natural
|
|
17
|
-
* keys", a opis narzędzia obiecuje userowi „can later be removed with mRAG_delete".
|
|
18
|
-
*
|
|
19
|
-
* Boli najbardziej przy korpusie, bo tam naturalne klucze są jedynym sposobem na dedup przy
|
|
20
|
-
* ponownym wczytaniu — a właśnie tak mielone są akta.
|
|
21
|
-
*
|
|
22
|
-
* Ten test pilnuje INWARIANTU, nie implementacji: cokolwiek robi ingest ze swoim `source_id`,
|
|
23
|
-
* delete ma zrobić to samo. Gdyby ktoś kiedyś zmienił namespace albo wersję UUID, obie strony
|
|
24
|
-
* muszą pojechać razem — i to złapie każdy rozjazd.
|
|
25
|
-
*/
|
|
26
|
-
import { describe, it, expect } from "vitest";
|
|
27
|
-
import { readFileSync } from "node:fs";
|
|
28
|
-
import { dirname, join } from "node:path";
|
|
29
|
-
import { fileURLToPath } from "node:url";
|
|
30
|
-
|
|
31
|
-
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
32
|
-
const SRC = readFileSync(join(HERE, "..", "knowledge.ts"), "utf8");
|
|
33
|
-
|
|
34
|
-
/** Ciało funkcji o danej nazwie — od jej deklaracji do następnej deklaracji `async function`. */
|
|
35
|
-
function bodyOf(name: string): string {
|
|
36
|
-
const start = SRC.indexOf(`async function ${name}(`);
|
|
37
|
-
expect(start, `nie znaleziono funkcji ${name} w knowledge.ts`).toBeGreaterThan(-1);
|
|
38
|
-
const next = SRC.indexOf("\nasync function ", start + 1);
|
|
39
|
-
return SRC.slice(start, next === -1 ? SRC.length : next);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe("mRAG_delete — zgodność foldowania z mRAG_ingest", () => {
|
|
43
|
-
it("delete folduje source_id przez uuidV5, tak samo jak ingest", () => {
|
|
44
|
-
const del = bodyOf("mRAG_delete");
|
|
45
|
-
expect(del, "mRAG_delete musi wołać uuidV5 — inaczej naturalny klucz da 500 na kolumnie uuid")
|
|
46
|
-
.toContain("uuidV5(");
|
|
47
|
-
expect(del, "mRAG_delete musi używać TEGO SAMEGO namespace co ingest")
|
|
48
|
-
.toContain("SOURCE_ID_NAMESPACE");
|
|
49
|
-
expect(del, "mRAG_delete musi rozpoznawać gotowy UUID i go NIE przerabiać")
|
|
50
|
-
.toContain("UUID_RE");
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("delete NIE wysyła surowego input.source_id do rag-sources", () => {
|
|
54
|
-
const del = bodyOf("mRAG_delete");
|
|
55
|
-
expect(
|
|
56
|
-
/source_id:\s*input\.source_id\s*\?\?\s*null/.test(del),
|
|
57
|
-
"regresja: surowy input.source_id znowu leci do rag-sources — to jest dokładnie ten błąd 500",
|
|
58
|
-
).toBe(false);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("obie strony dzielą jedną definicję namespace i jedną funkcję uuidV5", () => {
|
|
62
|
-
// Po jednej definicji każdej — dwie kopie to dwie prawdy, a na tym już się przejechaliśmy
|
|
63
|
-
// przy trasach modeli (FALLBACK_ROUTES vs ai_routes).
|
|
64
|
-
expect(SRC.match(/const SOURCE_ID_NAMESPACE\s*=/g)?.length ?? 0).toBe(1);
|
|
65
|
-
expect(SRC.match(/function uuidV5\(/g)?.length ?? 0).toBe(1);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* mRAG_delete MUSI foldować source_id dokładnie tak, jak robi to mRAG_ingest.
|
|
3
|
+
*
|
|
4
|
+
* ⛔ ZMIERZONA AWARIA (2026-08-28). `mRAG_ingest` przepuszczał nie-UUID przez `uuidV5`, a
|
|
5
|
+
* `mRAG_delete` wysyłał SUROWY napis prosto do kolumny UUID. Efekt na żywo:
|
|
6
|
+
*
|
|
7
|
+
* mRAG_ingest { source_id: "DIAG-GENERAL-2026-08-28-a1b2c3" } → { indexed: 1 } ✅
|
|
8
|
+
* mRAG_delete { source_id: "DIAG-GENERAL-2026-08-28-a1b2c3" } → 500
|
|
9
|
+
* "invalid input syntax for type uuid" ❌
|
|
10
|
+
*
|
|
11
|
+
* Czyli: dokument zaindeksowany pod NATURALNYM kluczem (numer sprawy, ścieżka pliku, threadId
|
|
12
|
+
* Gmaila) dawało się dodać, ale **nigdy nie dawało się go usunąć tym samym identyfikatorem**.
|
|
13
|
+
* Dwie połowy tej samej rury nie zgadzały się ze sobą.
|
|
14
|
+
*
|
|
15
|
+
* I to nie było niedopatrzenie w cieniu — obietnica stała w DWÓCH miejscach, a implementacja
|
|
16
|
+
* w jednym: komentarz przy foldowaniu mówi „so grouping and mRAG_delete keep working on natural
|
|
17
|
+
* keys", a opis narzędzia obiecuje userowi „can later be removed with mRAG_delete".
|
|
18
|
+
*
|
|
19
|
+
* Boli najbardziej przy korpusie, bo tam naturalne klucze są jedynym sposobem na dedup przy
|
|
20
|
+
* ponownym wczytaniu — a właśnie tak mielone są akta.
|
|
21
|
+
*
|
|
22
|
+
* Ten test pilnuje INWARIANTU, nie implementacji: cokolwiek robi ingest ze swoim `source_id`,
|
|
23
|
+
* delete ma zrobić to samo. Gdyby ktoś kiedyś zmienił namespace albo wersję UUID, obie strony
|
|
24
|
+
* muszą pojechać razem — i to złapie każdy rozjazd.
|
|
25
|
+
*/
|
|
26
|
+
import { describe, it, expect } from "vitest";
|
|
27
|
+
import { readFileSync } from "node:fs";
|
|
28
|
+
import { dirname, join } from "node:path";
|
|
29
|
+
import { fileURLToPath } from "node:url";
|
|
30
|
+
|
|
31
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
32
|
+
const SRC = readFileSync(join(HERE, "..", "knowledge.ts"), "utf8");
|
|
33
|
+
|
|
34
|
+
/** Ciało funkcji o danej nazwie — od jej deklaracji do następnej deklaracji `async function`. */
|
|
35
|
+
function bodyOf(name: string): string {
|
|
36
|
+
const start = SRC.indexOf(`async function ${name}(`);
|
|
37
|
+
expect(start, `nie znaleziono funkcji ${name} w knowledge.ts`).toBeGreaterThan(-1);
|
|
38
|
+
const next = SRC.indexOf("\nasync function ", start + 1);
|
|
39
|
+
return SRC.slice(start, next === -1 ? SRC.length : next);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe("mRAG_delete — zgodność foldowania z mRAG_ingest", () => {
|
|
43
|
+
it("delete folduje source_id przez uuidV5, tak samo jak ingest", () => {
|
|
44
|
+
const del = bodyOf("mRAG_delete");
|
|
45
|
+
expect(del, "mRAG_delete musi wołać uuidV5 — inaczej naturalny klucz da 500 na kolumnie uuid")
|
|
46
|
+
.toContain("uuidV5(");
|
|
47
|
+
expect(del, "mRAG_delete musi używać TEGO SAMEGO namespace co ingest")
|
|
48
|
+
.toContain("SOURCE_ID_NAMESPACE");
|
|
49
|
+
expect(del, "mRAG_delete musi rozpoznawać gotowy UUID i go NIE przerabiać")
|
|
50
|
+
.toContain("UUID_RE");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("delete NIE wysyła surowego input.source_id do rag-sources", () => {
|
|
54
|
+
const del = bodyOf("mRAG_delete");
|
|
55
|
+
expect(
|
|
56
|
+
/source_id:\s*input\.source_id\s*\?\?\s*null/.test(del),
|
|
57
|
+
"regresja: surowy input.source_id znowu leci do rag-sources — to jest dokładnie ten błąd 500",
|
|
58
|
+
).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("obie strony dzielą jedną definicję namespace i jedną funkcję uuidV5", () => {
|
|
62
|
+
// Po jednej definicji każdej — dwie kopie to dwie prawdy, a na tym już się przejechaliśmy
|
|
63
|
+
// przy trasach modeli (FALLBACK_ROUTES vs ai_routes).
|
|
64
|
+
expect(SRC.match(/const SOURCE_ID_NAMESPACE\s*=/g)?.length ?? 0).toBe(1);
|
|
65
|
+
expect(SRC.match(/function uuidV5\(/g)?.length ?? 0).toBe(1);
|
|
66
|
+
});
|
|
67
|
+
});
|