skillar 0.0.0 → 0.2.0
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/LICENSE +22 -0
- package/README.md +193 -1
- package/dist/analysis/finding.js +190 -0
- package/dist/analysis/tree.js +157 -0
- package/dist/analysis/usage.js +394 -0
- package/dist/api/flows.js +285 -0
- package/dist/api/routes.js +192 -0
- package/dist/api/security.js +86 -0
- package/dist/api/sse.js +55 -0
- package/dist/api/static.js +33 -0
- package/dist/catalog/fields.js +159 -0
- package/dist/catalog/index.js +133 -0
- package/dist/catalog/scanner.js +204 -0
- package/dist/catalog/uri.js +43 -0
- package/dist/catalog/watcher.js +59 -0
- package/dist/cli/config-writer.js +255 -0
- package/dist/cli/doctor.js +268 -0
- package/dist/cli/eval.js +64 -0
- package/dist/cli/export-import.js +68 -0
- package/dist/cli/init.js +272 -0
- package/dist/cli/main.js +165 -0
- package/dist/cli/open.js +24 -0
- package/dist/cli/serve.js +147 -0
- package/dist/config.js +92 -0
- package/dist/dashboard/assets/app.js +354 -0
- package/dist/dashboard/assets/chunk-5DFWNJC2.js +1 -0
- package/dist/dashboard/assets/chunk-S6B2HJQA.js +17 -0
- package/dist/dashboard/assets/styles.css +542 -0
- package/dist/dashboard/index.html +15 -0
- package/dist/fs-watchdog.js +35 -0
- package/dist/herdr/client.js +205 -0
- package/dist/herdr/sync.js +342 -0
- package/dist/ingest/attribution.js +80 -0
- package/dist/ingest/hooks.js +168 -0
- package/dist/ingest/identity.js +4 -0
- package/dist/ingest/mcp-recorder.js +41 -0
- package/dist/ingest/otlp-traces.js +106 -0
- package/dist/ingest/otlp.js +314 -0
- package/dist/ingest/pipeline.js +119 -0
- package/dist/ingest/redact.js +36 -0
- package/dist/ingest/runtimes.js +25 -0
- package/dist/mcp/dispatch.js +54 -0
- package/dist/mcp/http.js +112 -0
- package/dist/mcp/legacy.js +61 -0
- package/dist/mcp/pagination.js +17 -0
- package/dist/mcp/protocol.js +121 -0
- package/dist/mcp/skills-extension.js +77 -0
- package/dist/mcp/stdio-proxy.js +108 -0
- package/dist/mcp/tools.js +59 -0
- package/dist/packs/claude-code.js +176 -0
- package/dist/packs/codex.js +207 -0
- package/dist/packs/cursor.js +97 -0
- package/dist/packs/gajae.js +7 -0
- package/dist/packs/gemini.js +90 -0
- package/dist/packs/json-config.js +55 -0
- package/dist/packs/omo.js +154 -0
- package/dist/packs/openclaw.js +132 -0
- package/dist/packs/registry.js +13 -0
- package/dist/search/fts.js +61 -0
- package/dist/search/fusion.js +50 -0
- package/dist/search/guidance.js +7 -0
- package/dist/search/index.js +74 -0
- package/dist/search/lexical.js +69 -0
- package/dist/server.js +267 -0
- package/dist/store/automation.js +18 -0
- package/dist/store/db.js +134 -0
- package/dist/store/execution.js +157 -0
- package/dist/store/export.js +269 -0
- package/dist/store/index.js +14 -0
- package/dist/store/migrations/002_tracing.sql +94 -0
- package/dist/store/migrations/003_tracing_indexes.sql +11 -0
- package/dist/store/migrations/004_load_reconciliation.sql +50 -0
- package/dist/store/migrations/005_execution_boundaries.sql +6 -0
- package/dist/store/migrations/006_recording_order.sql +72 -0
- package/dist/store/queries.js +643 -0
- package/dist/store/schema.sql +96 -0
- package/dist/store/workflow.js +250 -0
- package/dist/store/writes.js +315 -0
- package/dist/types.js +1 -0
- package/dist/version.js +19 -0
- package/dist/workflow/compare.js +68 -0
- package/dist/workflow/routes.js +100 -0
- package/dist/workflow/spec.js +40 -0
- package/docs/execution-ownership.md +98 -0
- package/docs/mcp-conformance.md +156 -0
- package/docs/skill-tracing.md +294 -0
- package/package.json +46 -3
- package/packs/claude-code/README.md +5 -0
- package/packs/claude-code/settings.template.json +34 -0
- package/packs/codex/README.md +8 -0
- package/packs/codex/config.template.toml +12 -0
- package/packs/cursor/hooks.example.json +8 -0
- package/packs/cursor/mcp.example.json +8 -0
- package/packs/gajae/extension/discovery.md +5 -0
- package/packs/gajae/extension/index.js +52 -0
- package/packs/gemini/settings.example.json +16 -0
- package/packs/hook-post.mjs +37 -0
- package/packs/omo/extension/discovery.md +5 -0
- package/packs/omo/extension/index.js +52 -0
- package/packs/openclaw/.codex-plugin/plugin.json +11 -0
- package/packs/openclaw/.mcp.json +12 -0
- package/packs/openclaw/hooks/skillar-discovery/HOOK.md +8 -0
- package/packs/openclaw/hooks/skillar-discovery/handler.js +30 -0
- package/packs/openclaw/index.mjs +55 -0
- package/packs/openclaw/openclaw.plugin.json +22 -0
- package/packs/openclaw/package.json +11 -0
- package/packs/openclaw/skillar.json +1 -0
- package/src/store/migrations/002_tracing.sql +94 -0
- package/src/store/migrations/003_tracing_indexes.sql +11 -0
- package/src/store/migrations/004_load_reconciliation.sql +50 -0
- package/src/store/migrations/005_execution_boundaries.sql +6 -0
- package/src/store/migrations/006_recording_order.sql +72 -0
- package/src/store/schema.sql +96 -0
- package/src/store/task-types.json +15 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { attribute, createAttributionState, remember, WINDOW_MS } from "./attribution.js";
|
|
2
|
+
import { normalizeHook } from "./hooks.js";
|
|
3
|
+
import { parseOtlpLogs } from "./otlp.js";
|
|
4
|
+
import { applyCapture } from "./redact.js";
|
|
5
|
+
export function createIngestDeps(store, opts = {}) {
|
|
6
|
+
return { store, captureLevel: opts.captureLevel ?? "full", state: opts.state ?? createAttributionState(), publish: opts.publish,
|
|
7
|
+
sessionChanged: opts.sessionChanged, log: opts.log, now: opts.now };
|
|
8
|
+
}
|
|
9
|
+
function nowOf(deps) {
|
|
10
|
+
return deps.now ? deps.now() : Date.now();
|
|
11
|
+
}
|
|
12
|
+
function logError(deps, message, error) {
|
|
13
|
+
if (deps.log)
|
|
14
|
+
deps.log(message, error);
|
|
15
|
+
else
|
|
16
|
+
console.error(`[skillar ingest] ${message}`, error);
|
|
17
|
+
}
|
|
18
|
+
function count(deps, kind, code) {
|
|
19
|
+
try {
|
|
20
|
+
deps.store.countIngest(kind, code);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
logError(deps, `countIngest(${kind}) failed`, error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function capture(event, level) {
|
|
27
|
+
if (event.text === undefined)
|
|
28
|
+
return event;
|
|
29
|
+
const captured = applyCapture(level, event.text);
|
|
30
|
+
const { text: _dropped, ...rest } = event;
|
|
31
|
+
const next = { ...rest, textDigest: captured.textDigest, textLength: captured.textLength };
|
|
32
|
+
if (captured.text !== undefined)
|
|
33
|
+
next.text = captured.text;
|
|
34
|
+
if (event.kind === "search" && typeof event.data.query === "string")
|
|
35
|
+
next.data = { ...event.data, query: captured.text ?? "" };
|
|
36
|
+
return next;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* capture -> attribute -> store.append -> publish, fully synchronous. Errors are logged, counted as
|
|
40
|
+
* rejected `ingest_error`, and swallowed so one bad event never breaks a batch or blocks an agent.
|
|
41
|
+
* Returns undefined for an event the store already had (a replayed record), which is counted nowhere and published nowhere.
|
|
42
|
+
*/
|
|
43
|
+
export function ingest(event, deps) {
|
|
44
|
+
try {
|
|
45
|
+
// A replay has to be dropped here: attribute() upserts the session and the load map is written before append could reject it.
|
|
46
|
+
if (event.sourceKey !== undefined && deps.store.hasSourceKey(event.sourceKey))
|
|
47
|
+
return undefined;
|
|
48
|
+
const level = typeof deps.captureLevel === "function" ? deps.captureLevel() : deps.captureLevel;
|
|
49
|
+
const captured = capture(event, level);
|
|
50
|
+
const now = nowOf(deps);
|
|
51
|
+
const attribution = attribute(captured, deps.store, now, deps.state);
|
|
52
|
+
if (captured.kind === "load" && attribution.reason === "ambiguous") {
|
|
53
|
+
captured.data = { ...captured.data, attributionCandidates: deps.store.openSessions(captured.ref.runtime, 0)
|
|
54
|
+
.filter((session) => session.ref.runtime === captured.ref.runtime && now - session.lastActivityAt <= WINDOW_MS)
|
|
55
|
+
.map((session) => session.id) };
|
|
56
|
+
}
|
|
57
|
+
// Attribution can upsert a session even when append later rejects a replay.
|
|
58
|
+
if (attribution.sessionId !== "unattributed")
|
|
59
|
+
deps.sessionChanged?.(attribution.sessionId);
|
|
60
|
+
const inserted = deps.store.append(captured, attribution);
|
|
61
|
+
if (captured.loadId && attribution.sessionId !== "unattributed")
|
|
62
|
+
remember(deps.state.loadSessions, captured.loadId, attribution.sessionId);
|
|
63
|
+
if (!inserted)
|
|
64
|
+
return undefined;
|
|
65
|
+
if (captured.kind === "load" || (captured.kind === "tool_call" && captured.source === "otel"))
|
|
66
|
+
deps.store.reconcileLoads({ eventId: captured.id });
|
|
67
|
+
count(deps, "accepted");
|
|
68
|
+
if (deps.publish && attribution.sessionId !== "unattributed")
|
|
69
|
+
deps.publish({ sessionId: attribution.sessionId, attribution, event: captured });
|
|
70
|
+
return attribution;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
logError(deps, `failed to ingest ${event.kind} event ${event.id}`, error);
|
|
74
|
+
count(deps, "rejected", "ingest_error");
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Binds Claude tool_use_ids to sessions in either arrival order and ingests the hook's events. */
|
|
79
|
+
export function ingestHook(runtime, payload, deps) {
|
|
80
|
+
const now = nowOf(deps);
|
|
81
|
+
const { events, bindings } = normalizeHook(runtime, payload, now);
|
|
82
|
+
for (const binding of bindings) {
|
|
83
|
+
try {
|
|
84
|
+
const sessionId = deps.store.upsertSession(binding.ref, now);
|
|
85
|
+
deps.sessionChanged?.(sessionId);
|
|
86
|
+
remember(deps.state.toolUseSessions, binding.toolUseId, sessionId);
|
|
87
|
+
const eventId = deps.store.findEventByToolUseId(binding.toolUseId);
|
|
88
|
+
if (eventId) {
|
|
89
|
+
deps.store.reattribute(eventId, sessionId, "vendor_meta");
|
|
90
|
+
deps.publish?.({ sessionId, attribution: { sessionId, method: "vendor_meta" } });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
logError(deps, `failed to bind tool_use_id ${binding.toolUseId}`, error);
|
|
95
|
+
count(deps, "rejected", "ingest_error");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (events.length === 0 && bindings.length === 0) {
|
|
99
|
+
count(deps, "dropped", "unknown_event");
|
|
100
|
+
return { accepted: 0, dropped: 1 };
|
|
101
|
+
}
|
|
102
|
+
let accepted = 0;
|
|
103
|
+
for (const event of events)
|
|
104
|
+
if (ingest(event, deps))
|
|
105
|
+
accepted += 1;
|
|
106
|
+
return { accepted, dropped: 0 };
|
|
107
|
+
}
|
|
108
|
+
export function ingestOtlp(body, deps) {
|
|
109
|
+
const parsed = parseOtlpLogs(body, nowOf(deps));
|
|
110
|
+
if (!parsed.ok) {
|
|
111
|
+
count(deps, "rejected", parsed.error.code);
|
|
112
|
+
return { status: 400, body: parsed.error };
|
|
113
|
+
}
|
|
114
|
+
for (let i = 0; i < parsed.unknown; i += 1)
|
|
115
|
+
count(deps, "dropped", "unknown_event");
|
|
116
|
+
for (const event of parsed.events)
|
|
117
|
+
ingest(event, deps);
|
|
118
|
+
return { status: 200, body: parsed.response };
|
|
119
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
export const REDACTED_MAX_CHARS = 2048;
|
|
3
|
+
export const MASK = "[REDACTED]";
|
|
4
|
+
export const SECRET_PATTERNS = [
|
|
5
|
+
/sk-[A-Za-z0-9]{20,}/g,
|
|
6
|
+
/ghp_[A-Za-z0-9]{30,}/g,
|
|
7
|
+
/AKIA[0-9A-Z]{16}/g,
|
|
8
|
+
/xox[baprs]-[A-Za-z0-9-]+/g,
|
|
9
|
+
/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g,
|
|
10
|
+
/Bearer [A-Za-z0-9._-]{20,}/g,
|
|
11
|
+
];
|
|
12
|
+
export function sha256Hex(text) {
|
|
13
|
+
return createHash("sha256").update(text, "utf8").digest("hex");
|
|
14
|
+
}
|
|
15
|
+
export function maskSecrets(text) {
|
|
16
|
+
let out = text;
|
|
17
|
+
for (const pattern of SECRET_PATTERNS)
|
|
18
|
+
out = out.replace(pattern, MASK);
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* full -> text unchanged; redacted -> secrets masked then truncated to 2048 chars;
|
|
23
|
+
* metadata -> text dropped. Digest and length always describe the original text.
|
|
24
|
+
*/
|
|
25
|
+
export function applyCapture(level, text) {
|
|
26
|
+
const textDigest = sha256Hex(text);
|
|
27
|
+
const textLength = text.length;
|
|
28
|
+
switch (level) {
|
|
29
|
+
case "full":
|
|
30
|
+
return { text, textDigest, textLength };
|
|
31
|
+
case "redacted":
|
|
32
|
+
return { text: maskSecrets(text).slice(0, REDACTED_MAX_CHARS), textDigest, textLength };
|
|
33
|
+
case "metadata":
|
|
34
|
+
return { textDigest, textLength };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const EXACT = {
|
|
2
|
+
"claude-code": "claude-code",
|
|
3
|
+
"codex-mcp-client": "codex",
|
|
4
|
+
"gemini-cli-mcp-client": "gemini",
|
|
5
|
+
"senpi-mcp-client": "omo", // verified OmO 5 client name
|
|
6
|
+
opencode: "omo",
|
|
7
|
+
"gjc-coding-agent": "gajae",
|
|
8
|
+
};
|
|
9
|
+
export function runtimeFromClientName(name) {
|
|
10
|
+
if (!name)
|
|
11
|
+
return "unknown";
|
|
12
|
+
const exact = EXACT[name];
|
|
13
|
+
if (exact)
|
|
14
|
+
return exact;
|
|
15
|
+
const lower = name.toLowerCase();
|
|
16
|
+
if (lower.startsWith("cursor"))
|
|
17
|
+
return "cursor";
|
|
18
|
+
if (lower.includes("openclaw"))
|
|
19
|
+
return "openclaw";
|
|
20
|
+
return "unknown";
|
|
21
|
+
}
|
|
22
|
+
export const RUNTIME_IDS = ["claude-code", "codex", "gemini", "cursor", "omo", "gajae", "openclaw", "unknown"];
|
|
23
|
+
export function isRuntimeId(value) {
|
|
24
|
+
return RUNTIME_IDS.includes(value);
|
|
25
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CACHE, CLIENT_INFO_KEY, PROTOCOL_VERSION, RpcError } from "./protocol.js";
|
|
3
|
+
import { paginate } from "./pagination.js";
|
|
4
|
+
import { getSkill, listResources, listSkills, readResource, SKILLS_EXTENSION_ID } from "./skills-extension.js";
|
|
5
|
+
import { createSearchTool, packageVersion, SEARCH_TOOL, SERVER_INSTRUCTIONS } from "./tools.js";
|
|
6
|
+
const listParams = z.object({ cursor: z.string().optional() }).passthrough();
|
|
7
|
+
const uriParams = z.object({ uri: z.string().min(1) }).passthrough();
|
|
8
|
+
const toolParams = z.object({ name: z.string(), arguments: z.record(z.string(), z.unknown()).optional() }).passthrough();
|
|
9
|
+
export function createDispatcher(deps) {
|
|
10
|
+
const search = createSearchTool(deps);
|
|
11
|
+
const serverInfo = { name: "skillar", version: packageVersion() };
|
|
12
|
+
return async (request, params) => {
|
|
13
|
+
const clientInfo = params._meta[CLIENT_INFO_KEY];
|
|
14
|
+
const ctx = { ...(clientInfo ? { clientName: clientInfo.name } : {}), meta: params._meta };
|
|
15
|
+
let result;
|
|
16
|
+
switch (request.method) {
|
|
17
|
+
case "server/discover":
|
|
18
|
+
result = {
|
|
19
|
+
supportedVersions: [PROTOCOL_VERSION],
|
|
20
|
+
capabilities: { tools: {}, resources: {}, extensions: { [SKILLS_EXTENSION_ID]: {} } },
|
|
21
|
+
instructions: SERVER_INSTRUCTIONS, ...CACHE,
|
|
22
|
+
};
|
|
23
|
+
break;
|
|
24
|
+
case "tools/list": {
|
|
25
|
+
const { cursor } = listParams.parse(params);
|
|
26
|
+
const { page, ...next } = paginate("tools/list", [SEARCH_TOOL], { cursor, key: (tool) => tool.name });
|
|
27
|
+
result = { tools: page, ...next, ...CACHE };
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case "tools/call": {
|
|
31
|
+
const { name, arguments: args } = toolParams.parse(params);
|
|
32
|
+
if (name !== SEARCH_TOOL.name)
|
|
33
|
+
throw new RpcError(-32602, `Unknown tool: ${name}`);
|
|
34
|
+
result = search(args, ctx);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case "skills/list":
|
|
38
|
+
result = listSkills(deps.catalog, listParams.parse(params).cursor);
|
|
39
|
+
break;
|
|
40
|
+
case "skills/get":
|
|
41
|
+
result = getSkill(deps.catalog, uriParams.parse(params).uri);
|
|
42
|
+
break;
|
|
43
|
+
case "resources/list":
|
|
44
|
+
result = listResources(deps.catalog, listParams.parse(params).cursor);
|
|
45
|
+
break;
|
|
46
|
+
case "resources/read":
|
|
47
|
+
result = await readResource(deps, uriParams.parse(params).uri, ctx);
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
throw new RpcError(-32601, `Unknown method: ${request.method}`);
|
|
51
|
+
}
|
|
52
|
+
return { resultType: "complete", ...result, _meta: { "io.modelcontextprotocol/serverInfo": serverInfo } };
|
|
53
|
+
};
|
|
54
|
+
}
|
package/dist/mcp/http.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import express from "express";
|
|
3
|
+
import { bearerOf, safeEqual } from "../api/security.js";
|
|
4
|
+
import { createDispatcher } from "./dispatch.js";
|
|
5
|
+
import { initializeResult, initializeSchema, isLegacyRequest, legacyLocalResult, negotiateVersion, toLegacyResult, toModernMessage } from "./legacy.js";
|
|
6
|
+
import { checkHeaders, checkVersion, errorResponse, messageId, messageSchema, parseParams, RpcError, rpcFailure } from "./protocol.js";
|
|
7
|
+
const MAX_LEGACY_SESSIONS = 1024;
|
|
8
|
+
/**
|
|
9
|
+
* Dual-era MCP. Modern POSTs are self-contained. An `initialize` opens a legacy session whose only state is
|
|
10
|
+
* the client identity used for attribution; unknown session IDs are served anonymously rather than rejected,
|
|
11
|
+
* so a daemon restart never strands a legacy client. No GET stream or DELETE in either era.
|
|
12
|
+
*/
|
|
13
|
+
export function registerMcp(app, deps) {
|
|
14
|
+
const dispatch = createDispatcher(deps);
|
|
15
|
+
const sessions = new Map();
|
|
16
|
+
const legacy = async (message, req, res) => {
|
|
17
|
+
try {
|
|
18
|
+
let result;
|
|
19
|
+
if (message.method === "initialize") {
|
|
20
|
+
const init = initializeSchema.safeParse(message.params);
|
|
21
|
+
if (!init.success)
|
|
22
|
+
throw new RpcError(-32602, "Invalid initialize params", init.error.issues);
|
|
23
|
+
const clientInfo = { name: init.data.clientInfo.name, version: init.data.clientInfo.version };
|
|
24
|
+
const discover = toModernMessage({ jsonrpc: "2.0", id: message.id, method: "server/discover" }, clientInfo);
|
|
25
|
+
result = initializeResult(negotiateVersion(init.data.protocolVersion), await dispatch(discover, parseParams(discover)));
|
|
26
|
+
const sessionId = randomUUID();
|
|
27
|
+
if (sessions.size >= MAX_LEGACY_SESSIONS)
|
|
28
|
+
sessions.delete(sessions.keys().next().value);
|
|
29
|
+
sessions.set(sessionId, clientInfo);
|
|
30
|
+
res.set("Mcp-Session-Id", sessionId);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const local = legacyLocalResult(message.method);
|
|
34
|
+
const sessionId = req.header("Mcp-Session-Id");
|
|
35
|
+
const modern = toModernMessage(message, sessionId ? sessions.get(sessionId) : undefined);
|
|
36
|
+
result = local ?? toLegacyResult(await dispatch(modern, parseParams(modern)));
|
|
37
|
+
}
|
|
38
|
+
if (!res.destroyed)
|
|
39
|
+
res.json({ jsonrpc: "2.0", id: message.id, result });
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
// Legacy clients surface JSON-RPC errors only from 200 responses.
|
|
43
|
+
if (!res.destroyed)
|
|
44
|
+
res.json(errorResponse(message.id, rpcFailure(error)));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const auth = (req, res, next) => {
|
|
48
|
+
if (!safeEqual(bearerOf(req), deps.token)) {
|
|
49
|
+
res.status(401).json({ error: "unauthorized" });
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
next();
|
|
53
|
+
};
|
|
54
|
+
app.post("/mcp", auth, express.json({ limit: "1mb", strict: false }), async (req, res) => {
|
|
55
|
+
const parsed = messageSchema.safeParse(req.body);
|
|
56
|
+
if (!parsed.success) {
|
|
57
|
+
res.status(400).json(errorResponse(messageId(req.body), new RpcError(-32600, "Expected one JSON-RPC request or notification")));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const message = parsed.data;
|
|
61
|
+
if (message.id === undefined) {
|
|
62
|
+
// No client notification is acted upon over HTTP in this revision.
|
|
63
|
+
res.status(202).end();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const version = req.header("MCP-Protocol-Version");
|
|
67
|
+
if (isLegacyRequest(message, version)) {
|
|
68
|
+
if (req.header("accept") && !req.accepts("application/json")) {
|
|
69
|
+
res.status(406).json(errorResponse(message.id, new RpcError(-32600, "Accept must include application/json")));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
await legacy({ ...message, id: message.id }, req, res);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
checkHeaders(message, (name) => req.header(name));
|
|
77
|
+
const params = parseParams(message);
|
|
78
|
+
checkVersion(params._meta);
|
|
79
|
+
if (!req.header("accept") || !req.accepts("application/json") || !req.accepts("text/event-stream")) {
|
|
80
|
+
res.status(406).json(errorResponse(message.id, new RpcError(-32600, "Accept must include application/json and text/event-stream")));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const result = await dispatch(message, params);
|
|
84
|
+
if (!res.destroyed)
|
|
85
|
+
res.json({ jsonrpc: "2.0", id: message.id, result });
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
const failure = rpcFailure(error);
|
|
89
|
+
const status = failure.code === -32601 ? 404 : failure.code === -32603 ? 500 : 400;
|
|
90
|
+
if (!res.destroyed)
|
|
91
|
+
res.status(status).json(errorResponse(message.id, failure));
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
app.all("/mcp", auth, (_req, res) => { res.set("Allow", "POST").status(405).end(); });
|
|
95
|
+
app.use("/mcp", (error, _req, res, next) => {
|
|
96
|
+
const parsed = bodyErrorStatus(error);
|
|
97
|
+
if (parsed === undefined) {
|
|
98
|
+
next(error);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
res.status(parsed).json(errorResponse(undefined, new RpcError(parsed === 413 ? -32600 : -32700, parsed === 413 ? "Request body exceeds 1 MiB" : "Invalid JSON")));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function bodyErrorStatus(error) {
|
|
105
|
+
if (error instanceof Error && "type" in error) {
|
|
106
|
+
if (error.type === "entity.too.large")
|
|
107
|
+
return 413;
|
|
108
|
+
if (error.type === "entity.parse.failed")
|
|
109
|
+
return 400;
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CLIENT_CAPABILITIES_KEY, CLIENT_INFO_KEY, PROTOCOL_VERSION, VERSION_KEY } from "./protocol.js";
|
|
3
|
+
/**
|
|
4
|
+
* Dual-era support: initialization-based revisions are served by translating each request into a
|
|
5
|
+
* modern request with synthesized `_meta`, then stripping modern-only result fields.
|
|
6
|
+
*/
|
|
7
|
+
export const LEGACY_VERSIONS = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
|
|
8
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9
|
+
export const initializeSchema = z.object({
|
|
10
|
+
protocolVersion: z.string(),
|
|
11
|
+
capabilities: z.record(z.string(), z.unknown()),
|
|
12
|
+
clientInfo: z.object({ name: z.string(), version: z.string() }).passthrough(),
|
|
13
|
+
}).passthrough();
|
|
14
|
+
/**
|
|
15
|
+
* A request without modern `_meta` and without a modern HTTP version header opens or continues the legacy era.
|
|
16
|
+
* Clients before 2025-06-18 send no MCP-Protocol-Version header at all.
|
|
17
|
+
*/
|
|
18
|
+
export function isLegacyRequest(message, versionHeader) {
|
|
19
|
+
const meta = isObject(message.params) && isObject(message.params._meta) ? message.params._meta : {};
|
|
20
|
+
if (VERSION_KEY in meta || CLIENT_CAPABILITIES_KEY in meta)
|
|
21
|
+
return false;
|
|
22
|
+
return versionHeader === undefined || LEGACY_VERSIONS.includes(versionHeader);
|
|
23
|
+
}
|
|
24
|
+
export function negotiateVersion(requested) {
|
|
25
|
+
return LEGACY_VERSIONS.includes(requested) ? requested : LEGACY_VERSIONS[0];
|
|
26
|
+
}
|
|
27
|
+
/** Legacy requests carry identity only on initialize; the session supplies it afterwards. */
|
|
28
|
+
export function toModernMessage(message, clientInfo) {
|
|
29
|
+
const params = isObject(message.params) ? message.params : {};
|
|
30
|
+
const meta = isObject(params._meta) ? params._meta : {};
|
|
31
|
+
return {
|
|
32
|
+
...message,
|
|
33
|
+
params: {
|
|
34
|
+
...params,
|
|
35
|
+
_meta: { ...meta, [VERSION_KEY]: PROTOCOL_VERSION, [CLIENT_CAPABILITIES_KEY]: {}, ...(clientInfo ? { [CLIENT_INFO_KEY]: { name: clientInfo.name, version: clientInfo.version } } : {}) },
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function legacyLocalResult(method) {
|
|
40
|
+
if (method === "ping")
|
|
41
|
+
return {};
|
|
42
|
+
if (method === "resources/templates/list")
|
|
43
|
+
return { resourceTemplates: [] };
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
export function toLegacyResult(result) {
|
|
47
|
+
const { resultType: _type, ttlMs: _ttl, cacheScope: _scope, _meta, ...rest } = result;
|
|
48
|
+
if (!isObject(_meta))
|
|
49
|
+
return rest;
|
|
50
|
+
const { "io.modelcontextprotocol/serverInfo": _server, ...meta } = _meta;
|
|
51
|
+
return Object.keys(meta).length ? { ...rest, _meta: meta } : rest;
|
|
52
|
+
}
|
|
53
|
+
export function initializeResult(version, discover) {
|
|
54
|
+
const meta = isObject(discover._meta) ? discover._meta : {};
|
|
55
|
+
return {
|
|
56
|
+
protocolVersion: version,
|
|
57
|
+
capabilities: discover.capabilities,
|
|
58
|
+
serverInfo: meta["io.modelcontextprotocol/serverInfo"],
|
|
59
|
+
...(typeof discover.instructions === "string" ? { instructions: discover.instructions } : {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RpcError } from "./protocol.js";
|
|
2
|
+
export const PAGE_SIZE = 50;
|
|
3
|
+
/** A stable keyset cursor, bound to the method. No per-connection cursor state. */
|
|
4
|
+
export function paginate(method, entries, opts) {
|
|
5
|
+
const sorted = [...entries].sort((a, b) => opts.key(a) < opts.key(b) ? -1 : opts.key(a) > opts.key(b) ? 1 : 0);
|
|
6
|
+
const token = (item) => Buffer.from(JSON.stringify([method, opts.key(item)])).toString("base64url");
|
|
7
|
+
let start = 0;
|
|
8
|
+
if (opts.cursor !== undefined) {
|
|
9
|
+
const at = sorted.findIndex((item) => token(item) === opts.cursor);
|
|
10
|
+
if (at === -1)
|
|
11
|
+
throw new RpcError(-32602, `Invalid or expired cursor for ${method}; restart listing`);
|
|
12
|
+
start = at + 1;
|
|
13
|
+
}
|
|
14
|
+
const page = sorted.slice(start, start + PAGE_SIZE);
|
|
15
|
+
const last = page.at(-1);
|
|
16
|
+
return { page, ...(last !== undefined && start + page.length < sorted.length ? { nextCursor: token(last) } : {}) };
|
|
17
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const PROTOCOL_VERSION = "2026-07-28";
|
|
3
|
+
export const VERSION_KEY = "io.modelcontextprotocol/protocolVersion";
|
|
4
|
+
export const CLIENT_INFO_KEY = "io.modelcontextprotocol/clientInfo";
|
|
5
|
+
export const CLIENT_CAPABILITIES_KEY = "io.modelcontextprotocol/clientCapabilities";
|
|
6
|
+
export const TRACE_KEY = "app.skillar/traceId";
|
|
7
|
+
export const CACHE = { ttlMs: 60_000, cacheScope: "private" };
|
|
8
|
+
export class RpcError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
data;
|
|
11
|
+
constructor(code, message, data) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.data = data;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const idSchema = z.union([z.string(), z.number().int()]);
|
|
18
|
+
export const responseSchema = z.union([
|
|
19
|
+
z.object({ jsonrpc: z.literal("2.0"), id: idSchema, result: z.object({ resultType: z.literal("complete") }).passthrough() }).strict(),
|
|
20
|
+
z.object({ jsonrpc: z.literal("2.0"), id: idSchema.optional(), error: z.object({ code: z.number().int(), message: z.string(), data: z.unknown().optional() }) }).strict(),
|
|
21
|
+
]);
|
|
22
|
+
export function messageId(value) {
|
|
23
|
+
if (typeof value !== "object" || value === null || !("id" in value))
|
|
24
|
+
return undefined;
|
|
25
|
+
const id = idSchema.safeParse(value.id);
|
|
26
|
+
return id.success ? id.data : undefined;
|
|
27
|
+
}
|
|
28
|
+
export const messageSchema = z.object({
|
|
29
|
+
jsonrpc: z.literal("2.0"),
|
|
30
|
+
id: idSchema.optional(),
|
|
31
|
+
method: z.string(),
|
|
32
|
+
params: z.unknown().optional(),
|
|
33
|
+
}).strict();
|
|
34
|
+
const object = z.record(z.string(), z.unknown());
|
|
35
|
+
const metaKey = /^(?:[A-Za-z](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\.[A-Za-z](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*\/)?(?:[A-Za-z0-9](?:[A-Za-z0-9_.-]*[A-Za-z0-9])?)?$/;
|
|
36
|
+
export const metaSchema = z.object({
|
|
37
|
+
[VERSION_KEY]: z.string(),
|
|
38
|
+
[CLIENT_CAPABILITIES_KEY]: z.object({
|
|
39
|
+
elicitation: z.object({ form: object.optional(), url: object.optional() }).passthrough().optional(),
|
|
40
|
+
sampling: z.object({ tools: object.optional(), context: object.optional() }).passthrough().optional(),
|
|
41
|
+
roots: object.optional(),
|
|
42
|
+
extensions: z.record(z.string().regex(metaKey).refine((s) => s.includes("/")), object).optional(),
|
|
43
|
+
}).passthrough(),
|
|
44
|
+
[CLIENT_INFO_KEY]: z.object({ name: z.string(), version: z.string() }).passthrough().optional(),
|
|
45
|
+
[TRACE_KEY]: z.string().max(128).optional(),
|
|
46
|
+
"app.gisool/traceId": z.string().max(128).optional(),
|
|
47
|
+
"io.modelcontextprotocol/logLevel": z.enum(["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]).optional(),
|
|
48
|
+
progressToken: idSchema.optional(),
|
|
49
|
+
}).catchall(z.unknown()).refine((meta) => Object.keys(meta).every((key) => metaKey.test(key)), "Invalid _meta key");
|
|
50
|
+
export const paramsSchema = z.object({ _meta: metaSchema }).passthrough();
|
|
51
|
+
export function parseParams(message) {
|
|
52
|
+
const parsed = paramsSchema.safeParse(message.params);
|
|
53
|
+
if (!parsed.success)
|
|
54
|
+
throw new RpcError(-32602, `Invalid params: required request _meta must describe MCP ${PROTOCOL_VERSION}`, parsed.error.issues);
|
|
55
|
+
return parsed.data;
|
|
56
|
+
}
|
|
57
|
+
export function checkVersion(meta) {
|
|
58
|
+
const requested = meta[VERSION_KEY];
|
|
59
|
+
if (requested !== PROTOCOL_VERSION) {
|
|
60
|
+
throw new RpcError(-32022, `Unsupported protocol version; skillar supports only ${PROTOCOL_VERSION}`, { supported: [PROTOCOL_VERSION], requested });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function errorResponse(id, error) {
|
|
64
|
+
return { jsonrpc: "2.0", ...(id === undefined ? {} : { id }), error: { code: error.code, message: error.message, ...(error.data === undefined ? {} : { data: error.data }) } };
|
|
65
|
+
}
|
|
66
|
+
export function rpcFailure(error) {
|
|
67
|
+
if (error instanceof RpcError)
|
|
68
|
+
return error;
|
|
69
|
+
if (error instanceof z.ZodError)
|
|
70
|
+
return new RpcError(-32602, "Invalid request parameters", error.issues);
|
|
71
|
+
return new RpcError(-32603, "Internal error");
|
|
72
|
+
}
|
|
73
|
+
/** HTTP field values use the spec's sentinel encoding, not URL encoding. */
|
|
74
|
+
export function encodeHeader(value) {
|
|
75
|
+
return /^[\x20-\x7e\t]*$/.test(value) && value.trim() === value && !(value.startsWith("=?base64?") && value.endsWith("?="))
|
|
76
|
+
? value : `=?base64?${Buffer.from(value, "utf8").toString("base64")}?=`;
|
|
77
|
+
}
|
|
78
|
+
function decodeHeader(value) {
|
|
79
|
+
if (!/^[\x20-\x7e\t]*$/.test(value) || value.trim() !== value)
|
|
80
|
+
throw new RpcError(-32020, "Malformed MCP header");
|
|
81
|
+
if (!value.startsWith("=?base64?") || !value.endsWith("?="))
|
|
82
|
+
return value;
|
|
83
|
+
const encoded = value.slice(9, -2);
|
|
84
|
+
const bytes = Buffer.from(encoded, "base64");
|
|
85
|
+
if (bytes.toString("base64") !== encoded)
|
|
86
|
+
throw new RpcError(-32020, "Malformed Base64 MCP header");
|
|
87
|
+
try {
|
|
88
|
+
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
throw new RpcError(-32020, "MCP header is not UTF-8");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export function checkHeaders(message, header) {
|
|
95
|
+
const raw = object.safeParse(message.params);
|
|
96
|
+
const meta = object.safeParse(raw.success ? raw.data._meta : undefined);
|
|
97
|
+
const version = header("MCP-Protocol-Version");
|
|
98
|
+
const method = header("Mcp-Method");
|
|
99
|
+
if (!version || !method)
|
|
100
|
+
throw new RpcError(-32020, "Missing required MCP headers");
|
|
101
|
+
if (method !== message.method || (meta.success && typeof meta.data[VERSION_KEY] === "string" && version !== meta.data[VERSION_KEY])) {
|
|
102
|
+
throw new RpcError(-32020, "MCP header does not match request body");
|
|
103
|
+
}
|
|
104
|
+
const name = header("Mcp-Name");
|
|
105
|
+
const nameRequired = ["tools/call", "resources/read", "prompts/get"].includes(message.method);
|
|
106
|
+
if (nameRequired || name !== undefined) {
|
|
107
|
+
const expected = raw.success ? (message.method === "resources/read" ? raw.data.uri : raw.data.name) : undefined;
|
|
108
|
+
if (name === undefined || decodeHeader(name) !== expected)
|
|
109
|
+
throw new RpcError(-32020, "Mcp-Name does not match request body");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export function requestHeaders(message, params) {
|
|
113
|
+
const headers = {
|
|
114
|
+
"Content-Type": "application/json", Accept: "application/json, text/event-stream",
|
|
115
|
+
"MCP-Protocol-Version": params._meta[VERSION_KEY], "Mcp-Method": message.method,
|
|
116
|
+
};
|
|
117
|
+
const name = message.method === "resources/read" ? params.uri : params.name;
|
|
118
|
+
if (["tools/call", "resources/read", "prompts/get"].includes(message.method) && typeof name === "string")
|
|
119
|
+
headers["Mcp-Name"] = encodeHeader(name);
|
|
120
|
+
return headers;
|
|
121
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { CatalogError } from "../catalog/index.js";
|
|
3
|
+
import { errorEvent, loadEvent, readFileEvent } from "../ingest/mcp-recorder.js";
|
|
4
|
+
import { ingest } from "../ingest/pipeline.js";
|
|
5
|
+
import { CACHE, RpcError, TRACE_KEY } from "./protocol.js";
|
|
6
|
+
import { paginate } from "./pagination.js";
|
|
7
|
+
export const SKILLS_EXTENSION_ID = "io.modelcontextprotocol/skills";
|
|
8
|
+
const TEXT_EXTENSIONS = new Set(["md", "markdown", "txt", "json", "yaml", "yml", "toml", "csv", "html", "css", "xml", "svg", "py", "sh", "bash", "zsh", "js", "mjs", "cjs", "ts", "tsx", "jsx", "rb", "go", "rs", "java", "sql", "ini", "cfg", "env"]);
|
|
9
|
+
const MIME = { md: "text/markdown", markdown: "text/markdown", json: "application/json", yaml: "application/yaml", yml: "application/yaml", html: "text/html", css: "text/css", svg: "image/svg+xml", csv: "text/csv", xml: "application/xml", js: "text/javascript", mjs: "text/javascript", png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp", pdf: "application/pdf" };
|
|
10
|
+
function extensionOf(uri) {
|
|
11
|
+
const file = uri.slice(uri.lastIndexOf("/") + 1);
|
|
12
|
+
return file.includes(".") ? file.slice(file.lastIndexOf(".") + 1).toLowerCase() : "";
|
|
13
|
+
}
|
|
14
|
+
function mimeOf(uri) {
|
|
15
|
+
const ext = extensionOf(uri);
|
|
16
|
+
return MIME[ext] ?? (TEXT_EXTENSIONS.has(ext) ? "text/plain" : "application/octet-stream");
|
|
17
|
+
}
|
|
18
|
+
function toWire(entry) {
|
|
19
|
+
if (!entry.frontmatter)
|
|
20
|
+
throw new RpcError(-32603, "Catalog entry has no frontmatter");
|
|
21
|
+
return { uri: entry.uri, frontmatter: entry.frontmatter, resources: entry.resources.map(({ uri, digest, size }) => ({ uri, digest, size })) };
|
|
22
|
+
}
|
|
23
|
+
export function listSkills(catalog, cursor) {
|
|
24
|
+
const { page, ...next } = paginate("skills/list", catalog.list(), { cursor, key: (entry) => entry.uri });
|
|
25
|
+
return { skills: page.map(toWire), ...next, ...CACHE };
|
|
26
|
+
}
|
|
27
|
+
export function getSkill(catalog, uri) {
|
|
28
|
+
const entry = catalog.get(uri);
|
|
29
|
+
if (!entry)
|
|
30
|
+
throw new RpcError(-32602, `Not a skill served by this server: ${uri}`);
|
|
31
|
+
return { skill: toWire(entry), ...CACHE };
|
|
32
|
+
}
|
|
33
|
+
export function listResources(catalog, cursor) {
|
|
34
|
+
const resources = new Map(catalog.list().flatMap((entry) => entry.resources.map((file) => {
|
|
35
|
+
const skill = catalog.get(file.uri);
|
|
36
|
+
return [file.uri, {
|
|
37
|
+
uri: file.uri, size: file.size, mimeType: mimeOf(file.uri),
|
|
38
|
+
name: skill?.name ?? decodeURIComponent(file.uri.slice(file.uri.lastIndexOf("/") + 1)),
|
|
39
|
+
...(skill ? { description: skill.description } : {}),
|
|
40
|
+
}];
|
|
41
|
+
})));
|
|
42
|
+
const { page, ...next } = paginate("resources/list", [...resources.values()], { cursor, key: (file) => file.uri });
|
|
43
|
+
return { resources: page, ...next, ...CACHE };
|
|
44
|
+
}
|
|
45
|
+
/** Reads are observations only: no approval state or load prerequisite is created. */
|
|
46
|
+
export async function readResource(deps, uri, ctx) {
|
|
47
|
+
const now = () => deps.ingest.now?.() ?? Date.now();
|
|
48
|
+
const trace = ctx.meta?.[TRACE_KEY] ?? ctx.meta?.["app.gisool/traceId"];
|
|
49
|
+
const ids = typeof trace === "string" ? { traceId: trace } : {};
|
|
50
|
+
let file;
|
|
51
|
+
try {
|
|
52
|
+
file = await deps.catalog.readResource(uri);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const code = error instanceof CatalogError && error.code !== "digest_mismatch" ? -32602 : -32603;
|
|
56
|
+
const reason = error instanceof CatalogError ? error.code : "internal_error";
|
|
57
|
+
const message = code === -32602 ? `Resource not found or invalid: ${uri}` : `Resource unavailable; refresh skills/get before retrying: ${uri}`;
|
|
58
|
+
ingest(errorEvent(ctx, { code: reason, message, tool: "resources/read", ...ids }, now()), deps.ingest);
|
|
59
|
+
throw new RpcError(code, message, { reason });
|
|
60
|
+
}
|
|
61
|
+
const entry = deps.catalog.get(uri);
|
|
62
|
+
if (entry) {
|
|
63
|
+
// IDs identify observations, not content or connections. Two callers never share a load handle.
|
|
64
|
+
const loadId = randomUUID();
|
|
65
|
+
deps.store.putLoad({ loadId, uri, manifestDigest: entry.manifestDigest, resources: entry.resources, ...ids });
|
|
66
|
+
ingest(loadEvent(ctx, { uri, loadId, manifestDigest: entry.manifestDigest, ...ids }, now()), deps.ingest);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const owner = deps.catalog.list().filter((skill) => skill.resources.some((r) => r.uri === uri)).sort((a, b) => b.uri.length - a.uri.length)[0];
|
|
70
|
+
if (owner)
|
|
71
|
+
ingest(readFileEvent(ctx, { skillUri: owner.uri, uri, bytes: file.size, ...ids }, now()), deps.ingest);
|
|
72
|
+
}
|
|
73
|
+
const bytes = Buffer.from(file.bytes);
|
|
74
|
+
const text = TEXT_EXTENSIONS.has(extensionOf(uri)) && Buffer.from(file.text, "utf8").equals(bytes);
|
|
75
|
+
const content = text ? { uri, mimeType: mimeOf(uri), text: file.text } : { uri, mimeType: mimeOf(uri), blob: bytes.toString("base64") };
|
|
76
|
+
return { contents: [content], ...CACHE };
|
|
77
|
+
}
|