@prompt-optimizer/mcp-server 0.1.0 → 0.1.1

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.
Files changed (67) hide show
  1. package/README.md +9 -7
  2. package/dist/browser.js +10 -4200
  3. package/dist/chunk-2AOVKKBT.js +7 -0
  4. package/dist/chunk-5QROM7SH.js +3 -0
  5. package/dist/chunk-7FYOSVIN.js +3 -0
  6. package/dist/chunk-AKXNS3YY.js +4 -0
  7. package/dist/chunk-BBXFEEUH.js +43 -0
  8. package/dist/chunk-CHINCAF5.js +33 -0
  9. package/dist/chunk-EJ2IIPFF.js +3 -0
  10. package/dist/chunk-FLQML3XF.js +64 -0
  11. package/dist/chunk-GA7S5A7R.js +3 -0
  12. package/dist/chunk-IABPRAPS.js +3 -0
  13. package/dist/chunk-JE2EBI2C.js +3 -0
  14. package/dist/chunk-JL6XIA4S.js +4 -0
  15. package/dist/chunk-JXWLV6TC.js +12 -0
  16. package/dist/chunk-MUXGFCOV.js +7012 -0
  17. package/dist/chunk-NT2DBZVA.js +3 -0
  18. package/dist/chunk-NVZFDKDX.js +3 -0
  19. package/dist/chunk-PKJ2PK6J.js +106 -0
  20. package/dist/chunk-SDHFVY4F.js +6 -0
  21. package/dist/chunk-TWLLFRFQ.js +6 -0
  22. package/dist/desktop-business.js +4 -1225
  23. package/dist/desktop-comparison-UIIN3WK4.js +3 -0
  24. package/dist/desktop-storage-KJWV2A3P.js +3 -0
  25. package/dist/desktop.js +1 -24
  26. package/dist/dist-OM6QMJNC.js +10 -0
  27. package/dist/dist-YR425RV6.js +3 -0
  28. package/dist/index.js +1 -10
  29. package/dist/legacy.js +97 -26634
  30. package/dist/multipart-parser-XGXMMB2Z.js +4 -0
  31. package/dist/node-2SMUH4FH.js +3 -0
  32. package/dist/node-NX6BPYD5.js +3 -0
  33. package/dist/node-U7LDATXE.js +17 -0
  34. package/dist/registry-H5F4DGAM-2GPEVJMD.js +3 -0
  35. package/dist/src-3F22P42W.js +5 -0
  36. package/dist/start.js +2 -13
  37. package/package.json +10 -1
  38. package/preload-env.cjs +3 -352
  39. package/dist/chunk-3FYJ3FRD.js +0 -57
  40. package/dist/chunk-E7Z4Y3F4.js +0 -36402
  41. package/dist/chunk-GBDJTSRW.js +0 -298
  42. package/dist/chunk-HLCN3DLS.js +0 -19745
  43. package/dist/chunk-HYVN7FZZ.js +0 -4787
  44. package/dist/chunk-MEUCFQGU.js +0 -537
  45. package/dist/chunk-N6AUTPPS.js +0 -10647
  46. package/dist/chunk-Q52SACHI.js +0 -304
  47. package/dist/chunk-Q5B3KFB3.js +0 -31
  48. package/dist/chunk-QSPNNVX3.js +0 -49017
  49. package/dist/chunk-SO4YJHYW.js +0 -13450
  50. package/dist/chunk-SV2GETJH.js +0 -65
  51. package/dist/chunk-TFH2LO2H.js +0 -58
  52. package/dist/chunk-TFJEYQ3G.js +0 -786
  53. package/dist/chunk-TLOFCHZI.js +0 -70
  54. package/dist/chunk-TQGHULC7.js +0 -188
  55. package/dist/chunk-UTOMPKTK.js +0 -2209
  56. package/dist/chunk-XXALDAL7.js +0 -1838
  57. package/dist/chunk-YT3U6B54.js +0 -21
  58. package/dist/desktop-comparison-HDIQ6K45.js +0 -22
  59. package/dist/desktop-storage-YRABQCLF.js +0 -14
  60. package/dist/dist-O5VNBF5I.js +0 -622
  61. package/dist/dist-UMX52UME.js +0 -481
  62. package/dist/multipart-parser-XE6WGDAU.js +0 -373
  63. package/dist/node-2RBNZOSK.js +0 -2225
  64. package/dist/node-4Z3USCHW.js +0 -21
  65. package/dist/node-QHGLD5ST.js +0 -25
  66. package/dist/registry-H5F4DGAM-UHR4F6LL.js +0 -13
  67. package/dist/src-7PBMYCGI.js +0 -1398
@@ -1,298 +0,0 @@
1
- import { createRequire as __mcpCreateRequire } from "node:module";
2
- const require = __mcpCreateRequire(import.meta.url);
3
- import {
4
- AssetReadError,
5
- createReadonlyAssetReader
6
- } from "./chunk-UTOMPKTK.js";
7
-
8
- // src/desktop-router.ts
9
- import { randomUUID } from "node:crypto";
10
- import { isAbsolute, normalize } from "node:path";
11
- var DesktopSourceError = class extends Error {
12
- constructor(code) {
13
- super(`Desktop source request failed (${code}).`);
14
- this.code = code;
15
- this.name = "DesktopSourceError";
16
- }
17
- code;
18
- };
19
- var DesktopComparisonRequestError = class extends Error {
20
- constructor(code) {
21
- super(`Desktop comparison request failed (${code}).`);
22
- this.code = code;
23
- this.name = "DesktopComparisonRequestError";
24
- }
25
- code;
26
- };
27
- var identity = { scope: "mcp-process", sourceEpoch: "open-lease", inPlaceReplacementDetection: false, stableAcrossRestart: false };
28
- var noOpener = async () => {
29
- throw new DesktopSourceError("DESKTOP_OPENER_UNAVAILABLE");
30
- };
31
- function createDesktopRouter(profiles, accessMode, opener) {
32
- if (!profiles.length || profiles.length > 8) throw new DesktopSourceError("INVALID_INPUT");
33
- const paths = /* @__PURE__ */ new Set();
34
- const sources = profiles.map((profile) => {
35
- if (typeof profile.label !== "string" || !profile.label.trim() || !isAbsolute(profile.userDataPath)) {
36
- throw new DesktopSourceError("INVALID_INPUT");
37
- }
38
- const path = normalize(profile.userDataPath);
39
- const pathKey = process.platform === "win32" ? path.toLowerCase() : path;
40
- if (paths.has(pathKey)) throw new DesktopSourceError("INVALID_INPUT");
41
- paths.add(pathKey);
42
- return { id: randomUUID(), profile: { label: profile.label, userDataPath: path } };
43
- });
44
- const connections = /* @__PURE__ */ new Map();
45
- const leases = /* @__PURE__ */ new Set();
46
- let disposed = false;
47
- let disposal;
48
- function sourceDescription(source) {
49
- const connection = source.connection;
50
- return {
51
- sourceId: source.id,
52
- kind: "desktop",
53
- label: source.profile.label,
54
- sourceEpoch: connection?.executionSource.sourceEpoch ?? "unobserved",
55
- connectionGeneration: connection?.executionSource.connectionGeneration ?? "unconnected",
56
- productVersion: "unknown",
57
- contractVersion: "po-capabilities/0.2",
58
- storageVersion: connection ? "legacy-json-migration/1" : "unknown",
59
- availability: connection?.active ? "connected" : "disconnected",
60
- readiness: connection?.active ? "ready" : "not-ready",
61
- ...source.failure ? { unavailableReason: source.failure } : {}
62
- };
63
- }
64
- function assertOwner() {
65
- if (disposed) throw new DesktopSourceError("OWNER_CLOSED");
66
- }
67
- function assertActive(connection) {
68
- if (!connection?.active || disposed) throw new DesktopSourceError("CONNECTION_CLOSED");
69
- }
70
- function requireConnection(id) {
71
- assertOwner();
72
- const connection = connections.get(id);
73
- assertActive(connection);
74
- return connection;
75
- }
76
- async function releaseLease(lease, pending = /* @__PURE__ */ new Set()) {
77
- try {
78
- await lease.comparison?.runner.dispose();
79
- } finally {
80
- await Promise.allSettled([...pending]);
81
- await lease.provider.close();
82
- }
83
- }
84
- function closeConnection(connection) {
85
- if (connection.closePromise) return connection.closePromise;
86
- connection.active = false;
87
- connections.delete(connection.id);
88
- const source = sources.find((source2) => source2.connection === connection);
89
- connection.closePromise = (async () => {
90
- try {
91
- await releaseLease(connection.lease, connection.pending);
92
- } catch {
93
- if (source) source.failure = "SOURCE_CLOSE_FAILED";
94
- throw new DesktopSourceError("SOURCE_CLOSE_FAILED");
95
- } finally {
96
- leases.delete(connection);
97
- if (source) source.connection = void 0;
98
- }
99
- })();
100
- return connection.closePromise;
101
- }
102
- async function openSource(source) {
103
- let lease;
104
- try {
105
- const executionSource = {
106
- kind: "desktop",
107
- sourceId: source.id,
108
- label: source.profile.label,
109
- sourceEpoch: `lease:${randomUUID()}`,
110
- connectionGeneration: randomUUID()
111
- };
112
- lease = await opener(source.profile.userDataPath, executionSource);
113
- if (lease.migration.version !== 1) throw new DesktopSourceError("SCHEMA_UNSUPPORTED");
114
- if (accessMode === "compare" !== Boolean(lease.comparison)) throw new DesktopSourceError("SOURCE_NOT_READY");
115
- assertOwner();
116
- const connection = {
117
- id: randomUUID(),
118
- executionSource,
119
- active: true,
120
- lease,
121
- pending: /* @__PURE__ */ new Set(),
122
- reader: lease.comparison?.runner.reader ?? createReadonlyAssetReader(lease.provider, executionSource)
123
- };
124
- source.connection = connection;
125
- source.failure = void 0;
126
- connections.set(connection.id, connection);
127
- leases.add(connection);
128
- return connection;
129
- } catch (error) {
130
- if (lease) {
131
- try {
132
- await releaseLease(lease);
133
- } catch {
134
- source.failure = "SOURCE_CLOSE_FAILED";
135
- throw new DesktopSourceError("SOURCE_CLOSE_FAILED");
136
- }
137
- }
138
- const safe = error instanceof DesktopSourceError ? error : new DesktopSourceError("SOURCE_OPEN_FAILED");
139
- source.failure = safe.code;
140
- throw safe;
141
- }
142
- }
143
- async function useConnection(id, action) {
144
- const connection = requireConnection(id);
145
- let writeStarted = false;
146
- const beginWrite = () => {
147
- assertActive(connection);
148
- writeStarted = true;
149
- };
150
- const work = Promise.resolve().then(() => {
151
- assertActive(connection);
152
- return action(connection, beginWrite);
153
- });
154
- connection.pending.add(work);
155
- try {
156
- const result = await work;
157
- assertActive(connection);
158
- return result;
159
- } catch (error) {
160
- if (!connection.active || disposed) {
161
- throw new DesktopSourceError(writeStarted ? "WRITE_OUTCOME_UNKNOWN" : "CONNECTION_CLOSED");
162
- }
163
- const code = connection.lease.comparison?.errorCode(error);
164
- if (code && /^[A-Z][A-Z0-9_]{0,63}$/.test(code)) throw new DesktopComparisonRequestError(code);
165
- throw error;
166
- } finally {
167
- connection.pending.delete(work);
168
- }
169
- }
170
- function withComparison(id, action) {
171
- return useConnection(id, (connection, beginWrite) => {
172
- const session = connection.lease.comparison;
173
- if (!session) throw new DesktopSourceError("COMPARISON_ACCESS_REQUIRED");
174
- return action(session, connection, beginWrite);
175
- });
176
- }
177
- return {
178
- getSourceProfile(sourceId) {
179
- assertOwner();
180
- return sources.find((source) => source.id === sourceId)?.profile;
181
- },
182
- listSources() {
183
- assertOwner();
184
- return { sources: sources.map(sourceDescription), identity };
185
- },
186
- async open(sourceId, access) {
187
- assertOwner();
188
- if (access !== accessMode) throw new DesktopSourceError("INVALID_INPUT");
189
- const source = sources.find((source2) => source2.id === sourceId);
190
- if (!source) throw new DesktopSourceError("SOURCE_NOT_FOUND");
191
- if (source.failure === "SOURCE_CLOSE_FAILED") throw new DesktopSourceError("SOURCE_CLOSE_FAILED");
192
- if (source.connection?.closePromise) await source.connection.closePromise;
193
- assertOwner();
194
- if (!source.connection) {
195
- source.opening ??= openSource(source);
196
- try {
197
- await source.opening;
198
- } finally {
199
- source.opening = void 0;
200
- }
201
- }
202
- const connection = source.connection;
203
- assertActive(connection);
204
- return {
205
- connectionId: connection.id,
206
- source: sourceDescription(source),
207
- schemaVersion: "prompt-model/v1",
208
- identity,
209
- capabilities: { read: true, execute: accessMode === "compare", save: accessMode === "compare" }
210
- };
211
- },
212
- async close(connectionId) {
213
- await closeConnection(requireConnection(connectionId));
214
- return { closed: true };
215
- },
216
- listModels(id, options) {
217
- return useConnection(id, async ({ reader, lease }) => lease.comparison ? lease.comparison.runner.listModels(options) : reader.listModels(options));
218
- },
219
- listAssets(id, options) {
220
- return useConnection(id, ({ reader }) => reader.listAssets(options));
221
- },
222
- listAssetVersions(id, selection, options) {
223
- return useConnection(id, ({ reader }) => reader.listAssetVersions(selection, options));
224
- },
225
- getAssetVersion(id, selection) {
226
- return useConnection(id, ({ reader }) => reader.getAssetVersion(selection));
227
- },
228
- prepare(id, input) {
229
- return withComparison(id, ({ runner }) => runner.prepare(input));
230
- },
231
- execute(id, preparedId, previewRevision) {
232
- return withComparison(id, ({ runner }) => runner.execute(preparedId, previewRevision));
233
- },
234
- getTest(id, preparedId) {
235
- return withComparison(id, ({ runner }) => runner.get(preparedId));
236
- },
237
- cancel(id, preparedId, runId) {
238
- return withComparison(id, ({ runner }) => runner.cancel(preparedId, runId));
239
- },
240
- saveComparison(id, preparedId, saveKey) {
241
- return withComparison(id, async ({ runner, repository }, connection, beginWrite) => {
242
- const comparison = await runner.completed(preparedId);
243
- beginWrite();
244
- const saved = await repository.save(comparison, saveKey);
245
- const comparisonId = saved.comparison.id;
246
- return {
247
- saved: true,
248
- comparisonId,
249
- revision: saved.revision,
250
- viewTarget: { kind: "saved-comparison", sourceId: connection.executionSource.sourceId, comparisonId },
251
- visibility: "reload-required"
252
- };
253
- });
254
- },
255
- listComparisons(id, options) {
256
- return withComparison(id, ({ repository }) => repository.list(options));
257
- },
258
- getComparison(id, comparisonId) {
259
- return withComparison(id, ({ repository }) => repository.get(comparisonId));
260
- },
261
- deleteComparison(id, comparisonId, expectedRevision) {
262
- return withComparison(id, ({ repository }, _connection, beginWrite) => {
263
- beginWrite();
264
- return repository.delete(comparisonId, expectedRevision);
265
- });
266
- },
267
- dispose() {
268
- if (disposal) return disposal;
269
- disposed = true;
270
- disposal = (async () => {
271
- const active = Promise.allSettled([...leases].map(closeConnection));
272
- const [, results] = await Promise.all([Promise.allSettled(sources.map((source) => source.opening)), active]);
273
- if (results.some((result) => result.status === "rejected") || sources.some((source) => source.failure === "SOURCE_CLOSE_FAILED")) {
274
- throw new DesktopSourceError("SOURCE_CLOSE_FAILED");
275
- }
276
- })();
277
- return disposal;
278
- }
279
- };
280
- }
281
- function createDesktopReadonlyRouter(profiles, opener = noOpener) {
282
- return createDesktopRouter(profiles, "read", (path) => opener(path));
283
- }
284
- function createDesktopComparisonRouter(profiles, opener) {
285
- return createDesktopRouter(profiles, "compare", opener);
286
- }
287
- function publicDesktopError(error, access = "read") {
288
- const code = error instanceof DesktopSourceError || error instanceof AssetReadError || error instanceof DesktopComparisonRequestError ? error.code : access === "compare" ? "COMPARISON_REQUEST_FAILED" : "SOURCE_READ_FAILED";
289
- const scope = access === "compare" ? "comparison" : "readonly";
290
- return { code, message: `Desktop ${scope} request failed (${code}).` };
291
- }
292
-
293
- export {
294
- DesktopSourceError,
295
- createDesktopReadonlyRouter,
296
- createDesktopComparisonRouter,
297
- publicDesktopError
298
- };