@modootoday/pmcp 0.10.0 → 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,88 +0,0 @@
1
- import {
2
- createSkillServer
3
- } from "./chunk-VRZFM2M5.js";
4
- import {
5
- attachMailbox
6
- } from "./chunk-HNAVQG6R.js";
7
-
8
- // src/stdio.ts
9
- import { serveStdio } from "@modelcontextprotocol/server/stdio";
10
- function resolveRoots(argv, cwd) {
11
- const given = argv.filter((arg) => !arg.startsWith("-"));
12
- return given.length > 0 ? given : [`${cwd}/node_modules`];
13
- }
14
- function serve(catalog, serving = {}) {
15
- const options = {
16
- ...catalog,
17
- ...serving,
18
- onReject: ({ path, reason }) => process.stderr.write(`pmcp: skipped ${path}: ${reason}
19
- `),
20
- onWarning: ({ path, reason }) => process.stderr.write(`pmcp: warning ${path}: ${reason}
21
- `)
22
- };
23
- return serveStdio(() => createSkillServer(options), {
24
- // stdout is the protocol. A diagnostic written there corrupts the stream,
25
- // so out-of-band errors go to stderr and nowhere else.
26
- onerror: (error) => process.stderr.write(`pmcp: ${error.message}
27
- `)
28
- });
29
- }
30
- async function serveWithMailbox(catalog, mailbox, serving = {}) {
31
- let stop;
32
- const attachment = await attachMailbox({
33
- ...mailbox,
34
- onExpired: () => {
35
- process.stderr.write("pmcp: mailbox attachment expired or superseded\n");
36
- void stop?.().catch(() => {
37
- process.exitCode = 1;
38
- });
39
- }
40
- });
41
- let handle;
42
- try {
43
- handle = serve(catalog, { ...serving, mailbox: attachment.service });
44
- } catch (error) {
45
- await attachment.close();
46
- throw error;
47
- }
48
- let shutdown;
49
- const onExit = () => {
50
- void stop().catch(() => {
51
- process.exitCode = 1;
52
- });
53
- };
54
- stop = () => {
55
- if (shutdown) return shutdown;
56
- process.removeListener("SIGINT", onExit);
57
- process.removeListener("SIGTERM", onExit);
58
- process.stdin.removeListener("end", onExit);
59
- shutdown = (async () => {
60
- try {
61
- await handle.close();
62
- } finally {
63
- await attachment.close();
64
- }
65
- })();
66
- return shutdown;
67
- };
68
- process.once("SIGINT", onExit);
69
- process.once("SIGTERM", onExit);
70
- process.stdin.once("end", onExit);
71
- return stop;
72
- }
73
- function main(argv = process.argv.slice(2)) {
74
- const scopeArg = argv.find((arg) => arg.startsWith("--scope="));
75
- const scopes = scopeArg ? scopeArg.slice("--scope=".length).split(",") : [];
76
- serve({
77
- roots: resolveRoots(argv, process.cwd()),
78
- ...scopes.length > 0 ? { scopes } : {}
79
- });
80
- }
81
-
82
- export {
83
- resolveRoots,
84
- serve,
85
- serveWithMailbox,
86
- main
87
- };
88
- //# sourceMappingURL=chunk-JRSR4JBR.js.map
@@ -1,147 +0,0 @@
1
- import {
2
- resolveEncoder
3
- } from "./chunk-XOH2CW6P.js";
4
-
5
- // src/config.ts
6
- import { existsSync, readFileSync } from "fs";
7
- import { dirname, join, resolve } from "path";
8
- import { parse } from "smol-toml";
9
- var CONFIG_FILE = "pmcp.toml";
10
- function embeddingSection(path, dir, value) {
11
- if (value === void 0) return void 0;
12
- if (value === null || typeof value !== "object" || Array.isArray(value))
13
- throw new ConfigError(path, "[embedding] must be a table");
14
- const section = value;
15
- const allowed = /* @__PURE__ */ new Set([
16
- "enabled",
17
- "model",
18
- "dtype",
19
- "dimensions",
20
- "revision",
21
- "model_path",
22
- "cache_dir",
23
- "encoder"
24
- ]);
25
- for (const key of Object.keys(section)) {
26
- if (!allowed.has(key))
27
- throw new ConfigError(path, `unknown key [embedding] ${key}`);
28
- }
29
- if (section.enabled !== void 0 && typeof section.enabled !== "boolean")
30
- throw new ConfigError(path, "[embedding] enabled must be a boolean");
31
- const string = (key) => {
32
- const item = section[key];
33
- if (item === void 0) return void 0;
34
- if (typeof item !== "string" || !item.trim())
35
- throw new ConfigError(
36
- path,
37
- `[embedding] ${key} must be a non-empty string`
38
- );
39
- return item;
40
- };
41
- let encoder;
42
- if (section.encoder !== void 0) {
43
- if (section.encoder === null || typeof section.encoder !== "object" || Array.isArray(section.encoder))
44
- throw new ConfigError(path, "[embedding.encoder] must be a table");
45
- const source = section.encoder;
46
- const keys = /* @__PURE__ */ new Set([
47
- "query_prefix",
48
- "passage_prefix",
49
- "pooling",
50
- "projected"
51
- ]);
52
- for (const key of Object.keys(source)) {
53
- if (!keys.has(key))
54
- throw new ConfigError(path, `unknown key [embedding.encoder] ${key}`);
55
- }
56
- encoder = {};
57
- if (source.query_prefix !== void 0)
58
- encoder = { ...encoder, queryPrefix: source.query_prefix };
59
- if (source.passage_prefix !== void 0)
60
- encoder = { ...encoder, passagePrefix: source.passage_prefix };
61
- if (source.pooling !== void 0)
62
- encoder = { ...encoder, pooling: source.pooling };
63
- if (source.projected !== void 0)
64
- encoder = { ...encoder, projected: source.projected };
65
- }
66
- const modelPath = string("model_path");
67
- const cacheDir = string("cache_dir");
68
- const result = {
69
- modelId: string("model"),
70
- dtype: string("dtype"),
71
- dimensions: section.dimensions,
72
- revision: string("revision"),
73
- encoder,
74
- enabled: section.enabled,
75
- modelPath: modelPath === void 0 ? void 0 : resolve(dir, modelPath),
76
- cacheDir: cacheDir === void 0 ? void 0 : resolve(dir, cacheDir)
77
- };
78
- try {
79
- resolveEncoder(result.modelId, result);
80
- } catch (error) {
81
- throw new ConfigError(
82
- path,
83
- error instanceof Error ? error.message : "Invalid embedding configuration"
84
- );
85
- }
86
- return result;
87
- }
88
- var ConfigError = class extends Error {
89
- constructor(path, message) {
90
- super(`${path}: ${message}`);
91
- this.name = "ConfigError";
92
- }
93
- };
94
- var PATH_KEYS = ["roots", "workspaces", "packages", "marketplaces"];
95
- var CATALOG_KEYS = /* @__PURE__ */ new Set([...PATH_KEYS, "scopes"]);
96
- function findConfig(start) {
97
- let dir = resolve(start);
98
- for (; ; ) {
99
- const candidate = join(dir, CONFIG_FILE);
100
- if (existsSync(candidate)) return candidate;
101
- const parent = dirname(dir);
102
- if (parent === dir) return null;
103
- dir = parent;
104
- }
105
- }
106
- function stringList(path, key, value) {
107
- if (!Array.isArray(value) || !value.every((v) => typeof v === "string")) {
108
- throw new ConfigError(path, `[catalog] ${key} must be a list of strings`);
109
- }
110
- return value;
111
- }
112
- function readConfig(path) {
113
- const absolute = resolve(path);
114
- const dir = dirname(absolute);
115
- let raw;
116
- try {
117
- raw = parse(readFileSync(absolute, "utf8"));
118
- } catch (error) {
119
- const reason = error instanceof Error ? error.message : "unreadable";
120
- throw new ConfigError(absolute, reason.split("\n")[0] ?? reason);
121
- }
122
- const section = raw["catalog"];
123
- const embedding = embeddingSection(absolute, dir, raw.embedding);
124
- const configured = embedding === void 0 ? {} : { embedding };
125
- if (section === void 0)
126
- return { path: absolute, dir, catalog: {}, raw, ...configured };
127
- if (section === null || typeof section !== "object" || Array.isArray(section)) {
128
- throw new ConfigError(absolute, "[catalog] must be a table");
129
- }
130
- const catalog = {};
131
- for (const [key, value] of Object.entries(section)) {
132
- if (!CATALOG_KEYS.has(key)) {
133
- throw new ConfigError(absolute, `unknown key [catalog] ${key}`);
134
- }
135
- const list = stringList(absolute, key, value);
136
- catalog[key] = key === "scopes" ? list : list.map((p) => resolve(dir, p));
137
- }
138
- return { path: absolute, dir, catalog, raw, ...configured };
139
- }
140
-
141
- export {
142
- CONFIG_FILE,
143
- ConfigError,
144
- findConfig,
145
- readConfig
146
- };
147
- //# sourceMappingURL=chunk-MSTKY33C.js.map