@modootoday/pmcp 0.5.1 → 0.7.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.
@@ -0,0 +1,160 @@
1
+ import {
2
+ openDatabase
3
+ } from "./chunk-ZLELYZHL.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-NI2OLZPA.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createSkillServer
3
- } from "./chunk-76UKXVUE.js";
3
+ } from "./chunk-QHFORYIN.js";
4
4
 
5
5
  // src/stdio.ts
6
6
  import { serveStdio } from "@modelcontextprotocol/server/stdio";
@@ -35,4 +35,4 @@ export {
35
35
  serve,
36
36
  main
37
37
  };
38
- //# sourceMappingURL=chunk-ICHBC5FM.js.map
38
+ //# sourceMappingURL=chunk-POJOFL4L.js.map
@@ -1129,7 +1129,7 @@ function registerSkillTools(server, tools) {
1129
1129
  return server;
1130
1130
  }
1131
1131
  function createSkillServer(options) {
1132
- const server = new McpServer({ name: SERVER_NAME, version: "0.5.1" });
1132
+ const server = new McpServer({ name: SERVER_NAME, version: "0.7.0" });
1133
1133
  const tools = createSkillTools(options);
1134
1134
  registerSkillsExtension(server, tools.skills);
1135
1135
  return registerSkillTools(server, tools);
@@ -1167,4 +1167,4 @@ export {
1167
1167
  registerSkillTools,
1168
1168
  createSkillServer
1169
1169
  };
1170
- //# sourceMappingURL=chunk-76UKXVUE.js.map
1170
+ //# sourceMappingURL=chunk-QHFORYIN.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  normaliseIntent
3
- } from "./chunk-76UKXVUE.js";
3
+ } from "./chunk-QHFORYIN.js";
4
4
 
5
5
  // src/cache.ts
6
6
  async function openDatabase(path) {
@@ -126,68 +126,9 @@ async function openIntentCache(options) {
126
126
  };
127
127
  }
128
128
 
129
- // src/config.ts
130
- import { existsSync, readFileSync } from "fs";
131
- import { dirname, join, resolve } from "path";
132
- import { parse } from "smol-toml";
133
- var CONFIG_FILE = "pmcp.toml";
134
- var ConfigError = class extends Error {
135
- constructor(path, message) {
136
- super(`${path}: ${message}`);
137
- this.name = "ConfigError";
138
- }
139
- };
140
- var PATH_KEYS = ["roots", "workspaces", "packages", "marketplaces"];
141
- var CATALOG_KEYS = /* @__PURE__ */ new Set([...PATH_KEYS, "scopes"]);
142
- function findConfig(start) {
143
- let dir = resolve(start);
144
- for (; ; ) {
145
- const candidate = join(dir, CONFIG_FILE);
146
- if (existsSync(candidate)) return candidate;
147
- const parent = dirname(dir);
148
- if (parent === dir) return null;
149
- dir = parent;
150
- }
151
- }
152
- function stringList(path, key, value) {
153
- if (!Array.isArray(value) || !value.every((v) => typeof v === "string")) {
154
- throw new ConfigError(path, `[catalog] ${key} must be a list of strings`);
155
- }
156
- return value;
157
- }
158
- function readConfig(path) {
159
- const absolute = resolve(path);
160
- const dir = dirname(absolute);
161
- let raw;
162
- try {
163
- raw = parse(readFileSync(absolute, "utf8"));
164
- } catch (error) {
165
- const reason = error instanceof Error ? error.message : "unreadable";
166
- throw new ConfigError(absolute, reason.split("\n")[0] ?? reason);
167
- }
168
- const section = raw["catalog"];
169
- if (section === void 0) return { path: absolute, dir, catalog: {}, raw };
170
- if (section === null || typeof section !== "object" || Array.isArray(section)) {
171
- throw new ConfigError(absolute, "[catalog] must be a table");
172
- }
173
- const catalog = {};
174
- for (const [key, value] of Object.entries(section)) {
175
- if (!CATALOG_KEYS.has(key)) {
176
- throw new ConfigError(absolute, `unknown key [catalog] ${key}`);
177
- }
178
- const list = stringList(absolute, key, value);
179
- catalog[key] = key === "scopes" ? list : list.map((p) => resolve(dir, p));
180
- }
181
- return { path: absolute, dir, catalog, raw };
182
- }
183
-
184
129
  export {
185
130
  openDatabase,
186
131
  DEFAULT_INTENT_CACHE_LIMIT,
187
- openIntentCache,
188
- CONFIG_FILE,
189
- ConfigError,
190
- findConfig,
191
- readConfig
132
+ openIntentCache
192
133
  };
193
- //# sourceMappingURL=chunk-XTLANVRL.js.map
134
+ //# sourceMappingURL=chunk-ZLELYZHL.js.map