@modootoday/pmcp 0.9.2 → 0.11.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.
@@ -1,41 +0,0 @@
1
- import {
2
- createSkillServer
3
- } from "./chunk-A5NOHVHN.js";
4
-
5
- // src/stdio.ts
6
- import { serveStdio } from "@modelcontextprotocol/server/stdio";
7
- function resolveRoots(argv, cwd) {
8
- const given = argv.filter((arg) => !arg.startsWith("-"));
9
- return given.length > 0 ? given : [`${cwd}/node_modules`];
10
- }
11
- function serve(catalog, serving = {}) {
12
- const options = {
13
- ...catalog,
14
- ...serving,
15
- onReject: ({ path, reason }) => process.stderr.write(`pmcp: skipped ${path}: ${reason}
16
- `),
17
- onWarning: ({ path, reason }) => process.stderr.write(`pmcp: warning ${path}: ${reason}
18
- `)
19
- };
20
- serveStdio(() => createSkillServer(options), {
21
- // stdout is the protocol. A diagnostic written there corrupts the stream,
22
- // so out-of-band errors go to stderr and nowhere else.
23
- onerror: (error) => process.stderr.write(`pmcp: ${error.message}
24
- `)
25
- });
26
- }
27
- function main(argv = process.argv.slice(2)) {
28
- const scopeArg = argv.find((arg) => arg.startsWith("--scope="));
29
- const scopes = scopeArg ? scopeArg.slice("--scope=".length).split(",") : [];
30
- serve({
31
- roots: resolveRoots(argv, process.cwd()),
32
- ...scopes.length > 0 ? { scopes } : {}
33
- });
34
- }
35
-
36
- export {
37
- resolveRoots,
38
- serve,
39
- main
40
- };
41
- //# sourceMappingURL=chunk-EIHMCKY5.js.map
@@ -1,160 +0,0 @@
1
- import {
2
- openDatabase
3
- } from "./chunk-CMZ7OTQD.js";
4
-
5
- // src/embed.ts
6
- var DEFAULT_MODEL_ID = "Xenova/multilingual-e5-small";
7
- var PLAIN = {
8
- queryPrefix: "",
9
- passagePrefix: "",
10
- pooling: "mean"
11
- };
12
- var E5 = {
13
- queryPrefix: "query: ",
14
- passagePrefix: "passage: ",
15
- pooling: "mean"
16
- };
17
- var KNOWN_ENCODERS = {
18
- "Xenova/multilingual-e5-small": E5,
19
- "Xenova/multilingual-e5-base": E5,
20
- "Xenova/multilingual-e5-large": E5,
21
- "Xenova/bge-m3": { ...PLAIN, pooling: "cls" }
22
- };
23
- function encoderSpec(modelId) {
24
- return KNOWN_ENCODERS[modelId] ?? PLAIN;
25
- }
26
- var ENTRY_SCHEMA = `
27
- CREATE TABLE IF NOT EXISTS entry_vector (
28
- name TEXT NOT NULL,
29
- model_id TEXT NOT NULL,
30
- dims INTEGER NOT NULL,
31
- description_hash TEXT NOT NULL,
32
- vector BLOB NOT NULL,
33
- PRIMARY KEY (name, model_id)
34
- );
35
- `;
36
- var TRANSFORMERS = "@huggingface/transformers";
37
- async function loadEmbedder(modelId = DEFAULT_MODEL_ID, options = {}) {
38
- let module;
39
- try {
40
- module = options.module ?? await import(TRANSFORMERS);
41
- } catch {
42
- return null;
43
- }
44
- const factory = module.pipeline;
45
- if (typeof factory !== "function") return null;
46
- if (module.env) {
47
- if (options.cacheDir !== void 0)
48
- module.env["cacheDir"] = options.cacheDir;
49
- if (options.localOnly) module.env["allowRemoteModels"] = false;
50
- }
51
- const encode = await factory("feature-extraction", modelId, {
52
- dtype: options.dtype ?? "q8"
53
- });
54
- const spec = encoderSpec(modelId);
55
- let dims = 0;
56
- const run = async (text) => {
57
- const output = await encode(text, {
58
- pooling: spec.pooling,
59
- normalize: true
60
- });
61
- const vector = Float32Array.from(output.data);
62
- dims = vector.length;
63
- return vector;
64
- };
65
- return {
66
- modelId,
67
- get dims() {
68
- return dims;
69
- },
70
- embed: (text) => run(spec.queryPrefix + text),
71
- embedPassage: (text) => run(spec.passagePrefix + text)
72
- };
73
- }
74
- async function encodeEntries(embedder, entries, previous = /* @__PURE__ */ new Map()) {
75
- const out = /* @__PURE__ */ new Map();
76
- const passage = (text) => embedder.embedPassage ? embedder.embedPassage(text) : embedder.embed(text);
77
- for (const entry of entries) {
78
- const hash = describeHash(entry.description);
79
- const kept = previous.get(entry.name);
80
- if (kept && kept.hash === hash) {
81
- out.set(entry.name, kept);
82
- continue;
83
- }
84
- out.set(entry.name, { hash, vector: await passage(entry.description) });
85
- }
86
- return out;
87
- }
88
- function describeHash(description) {
89
- let hash = 2166136261;
90
- for (let i = 0; i < description.length; i++) {
91
- hash ^= description.charCodeAt(i);
92
- hash = Math.imul(hash, 16777619) >>> 0;
93
- }
94
- return hash.toString(16).padStart(8, "0");
95
- }
96
- async function openEntryVectors(path) {
97
- const opened = await openDatabase(path);
98
- if (opened === null) return null;
99
- const db = opened.db;
100
- db.exec(ENTRY_SCHEMA);
101
- return {
102
- read(modelId) {
103
- const out = /* @__PURE__ */ new Map();
104
- const rows = db.prepare(
105
- "SELECT name, dims, vector FROM entry_vector WHERE model_id = ?"
106
- ).all(modelId);
107
- for (const row of rows) {
108
- const bytes = row.vector;
109
- const vector = new Float32Array(
110
- bytes.buffer.slice(
111
- bytes.byteOffset,
112
- bytes.byteOffset + bytes.byteLength
113
- )
114
- );
115
- if (vector.length === row.dims) out.set(row.name, vector);
116
- }
117
- return out;
118
- },
119
- stale(modelId, entries) {
120
- const rows = db.prepare(
121
- "SELECT name, description_hash FROM entry_vector WHERE model_id = ?"
122
- ).all(modelId);
123
- const stored = new Map(
124
- rows.map((row) => [row.name, row.description_hash])
125
- );
126
- const out = [];
127
- for (const [name, description] of entries) {
128
- if (stored.get(name) !== describeHash(description)) out.push(name);
129
- }
130
- return out;
131
- },
132
- write(modelId, name, description, vector) {
133
- db.prepare(
134
- `INSERT INTO entry_vector (name, model_id, dims, description_hash, vector)
135
- VALUES (?, ?, ?, ?, ?)
136
- ON CONFLICT(name, model_id) DO UPDATE SET
137
- dims = excluded.dims,
138
- description_hash = excluded.description_hash,
139
- vector = excluded.vector`
140
- ).run(
141
- name,
142
- modelId,
143
- vector.length,
144
- describeHash(description),
145
- new Uint8Array(vector.buffer, vector.byteOffset, vector.byteLength)
146
- );
147
- },
148
- close() {
149
- db.close();
150
- }
151
- };
152
- }
153
-
154
- export {
155
- DEFAULT_MODEL_ID,
156
- loadEmbedder,
157
- encodeEntries,
158
- openEntryVectors
159
- };
160
- //# sourceMappingURL=chunk-KYW3VP3L.js.map