@contractspec/bundle.library 3.0.0 → 3.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.
- package/.turbo/turbo-build.log +178 -166
- package/AGENTS.md +19 -12
- package/CHANGELOG.md +46 -0
- package/dist/application/context-storage/index.d.ts +18 -0
- package/dist/application/context-storage/index.js +29 -0
- package/dist/application/index.d.ts +1 -0
- package/dist/application/index.js +662 -2
- package/dist/application/mcp/cliMcp.js +12 -2
- package/dist/application/mcp/common.d.ts +11 -1
- package/dist/application/mcp/common.js +12 -2
- package/dist/application/mcp/contractsMcp.d.ts +51 -0
- package/dist/application/mcp/contractsMcp.js +531 -0
- package/dist/application/mcp/contractsMcpResources.d.ts +7 -0
- package/dist/application/mcp/contractsMcpResources.js +124 -0
- package/dist/application/mcp/contractsMcpTools.d.ts +9 -0
- package/dist/application/mcp/contractsMcpTools.js +200 -0
- package/dist/application/mcp/contractsMcpTypes.d.ts +50 -0
- package/dist/application/mcp/contractsMcpTypes.js +1 -0
- package/dist/application/mcp/docsMcp.js +12 -2
- package/dist/application/mcp/index.d.ts +2 -0
- package/dist/application/mcp/index.js +635 -2
- package/dist/application/mcp/internalMcp.js +12 -2
- package/dist/application/mcp/providerRankingMcp.d.ts +46 -0
- package/dist/application/mcp/providerRankingMcp.js +494 -0
- package/dist/node/application/context-storage/index.js +28 -0
- package/dist/node/application/index.js +662 -2
- package/dist/node/application/mcp/cliMcp.js +12 -2
- package/dist/node/application/mcp/common.js +12 -2
- package/dist/node/application/mcp/contractsMcp.js +530 -0
- package/dist/node/application/mcp/contractsMcpResources.js +123 -0
- package/dist/node/application/mcp/contractsMcpTools.js +199 -0
- package/dist/node/application/mcp/contractsMcpTypes.js +0 -0
- package/dist/node/application/mcp/docsMcp.js +12 -2
- package/dist/node/application/mcp/index.js +635 -2
- package/dist/node/application/mcp/internalMcp.js +12 -2
- package/dist/node/application/mcp/providerRankingMcp.js +493 -0
- package/package.json +111 -25
- package/src/application/context-storage/index.ts +58 -0
- package/src/application/index.ts +1 -0
- package/src/application/mcp/common.ts +28 -1
- package/src/application/mcp/contractsMcp.ts +34 -0
- package/src/application/mcp/contractsMcpResources.ts +142 -0
- package/src/application/mcp/contractsMcpTools.ts +246 -0
- package/src/application/mcp/contractsMcpTypes.ts +47 -0
- package/src/application/mcp/index.ts +2 -0
- package/src/application/mcp/providerRankingMcp.ts +380 -0
- package/src/components/docs/generated/docs-index._common.json +879 -1
- package/src/components/docs/generated/docs-index.manifest.json +5 -5
- package/src/components/docs/generated/docs-index.metrics.json +8 -0
- package/src/components/docs/generated/docs-index.platform-integrations.json +8 -0
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
// src/application/mcp/common.ts
|
|
2
|
+
import { PresentationRegistry } from "@contractspec/lib.contracts-spec/presentations";
|
|
3
|
+
import { createMcpServer } from "@contractspec/lib.contracts-runtime-server-mcp/provider-mcp";
|
|
4
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
|
+
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
6
|
+
import { Elysia } from "elysia";
|
|
7
|
+
import { randomUUID } from "node:crypto";
|
|
8
|
+
var baseCtx = {
|
|
9
|
+
actor: "anonymous",
|
|
10
|
+
decide: async () => ({ effect: "allow" })
|
|
11
|
+
};
|
|
12
|
+
function createJsonRpcErrorResponse(status, code, message, data) {
|
|
13
|
+
return new Response(JSON.stringify({
|
|
14
|
+
jsonrpc: "2.0",
|
|
15
|
+
error: {
|
|
16
|
+
code,
|
|
17
|
+
message,
|
|
18
|
+
...data ? { data } : {}
|
|
19
|
+
},
|
|
20
|
+
id: null
|
|
21
|
+
}), {
|
|
22
|
+
status,
|
|
23
|
+
headers: {
|
|
24
|
+
"content-type": "application/json"
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function createSessionState({
|
|
29
|
+
logger,
|
|
30
|
+
serverName,
|
|
31
|
+
ops,
|
|
32
|
+
resources,
|
|
33
|
+
prompts,
|
|
34
|
+
presentations,
|
|
35
|
+
stateful
|
|
36
|
+
}) {
|
|
37
|
+
const server = new McpServer({
|
|
38
|
+
name: serverName,
|
|
39
|
+
version: "1.0.0"
|
|
40
|
+
}, {
|
|
41
|
+
capabilities: {
|
|
42
|
+
tools: {},
|
|
43
|
+
resources: {},
|
|
44
|
+
prompts: {},
|
|
45
|
+
logging: {}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
logger.info("Setting up MCP server...");
|
|
49
|
+
createMcpServer(server, ops, resources, prompts, {
|
|
50
|
+
logger,
|
|
51
|
+
toolCtx: () => baseCtx,
|
|
52
|
+
promptCtx: () => ({ locale: "en" }),
|
|
53
|
+
resourceCtx: () => ({ locale: "en" }),
|
|
54
|
+
presentations: new PresentationRegistry(presentations)
|
|
55
|
+
});
|
|
56
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
57
|
+
sessionIdGenerator: stateful ? () => randomUUID() : undefined,
|
|
58
|
+
enableJsonResponse: true
|
|
59
|
+
});
|
|
60
|
+
return server.connect(transport).then(() => ({ server, transport }));
|
|
61
|
+
}
|
|
62
|
+
async function closeSessionState(state) {
|
|
63
|
+
await Promise.allSettled([state.transport.close(), state.server.close()]);
|
|
64
|
+
}
|
|
65
|
+
function toErrorMessage(error) {
|
|
66
|
+
return error instanceof Error ? error.stack ?? error.message : String(error);
|
|
67
|
+
}
|
|
68
|
+
function createMcpElysiaHandler({
|
|
69
|
+
logger,
|
|
70
|
+
path,
|
|
71
|
+
serverName,
|
|
72
|
+
ops,
|
|
73
|
+
resources,
|
|
74
|
+
prompts,
|
|
75
|
+
presentations,
|
|
76
|
+
validateAuth,
|
|
77
|
+
requiredAuthMethods
|
|
78
|
+
}) {
|
|
79
|
+
logger.info("Setting up MCP handler...", {
|
|
80
|
+
requiredAuthMethods: requiredAuthMethods ?? []
|
|
81
|
+
});
|
|
82
|
+
const isStateful = process.env.CONTRACTSPEC_MCP_STATEFUL === "1";
|
|
83
|
+
const sessions = new Map;
|
|
84
|
+
async function handleStateless(request) {
|
|
85
|
+
const state = await createSessionState({
|
|
86
|
+
logger,
|
|
87
|
+
path,
|
|
88
|
+
serverName,
|
|
89
|
+
ops,
|
|
90
|
+
resources,
|
|
91
|
+
prompts,
|
|
92
|
+
presentations,
|
|
93
|
+
stateful: false
|
|
94
|
+
});
|
|
95
|
+
try {
|
|
96
|
+
return await state.transport.handleRequest(request);
|
|
97
|
+
} finally {
|
|
98
|
+
await closeSessionState(state);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async function closeSession(sessionId) {
|
|
102
|
+
const state = sessions.get(sessionId);
|
|
103
|
+
if (!state)
|
|
104
|
+
return;
|
|
105
|
+
sessions.delete(sessionId);
|
|
106
|
+
await closeSessionState(state);
|
|
107
|
+
}
|
|
108
|
+
async function handleStateful(request) {
|
|
109
|
+
const requestedSessionId = request.headers.get("mcp-session-id");
|
|
110
|
+
let state;
|
|
111
|
+
let createdState = false;
|
|
112
|
+
if (requestedSessionId) {
|
|
113
|
+
const existing = sessions.get(requestedSessionId);
|
|
114
|
+
if (!existing) {
|
|
115
|
+
return createJsonRpcErrorResponse(404, -32001, "Session not found");
|
|
116
|
+
}
|
|
117
|
+
state = existing;
|
|
118
|
+
} else {
|
|
119
|
+
state = await createSessionState({
|
|
120
|
+
logger,
|
|
121
|
+
path,
|
|
122
|
+
serverName,
|
|
123
|
+
ops,
|
|
124
|
+
resources,
|
|
125
|
+
prompts,
|
|
126
|
+
presentations,
|
|
127
|
+
stateful: true
|
|
128
|
+
});
|
|
129
|
+
createdState = true;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const response = await state.transport.handleRequest(request);
|
|
133
|
+
const activeSessionId = state.transport.sessionId;
|
|
134
|
+
if (activeSessionId && !sessions.has(activeSessionId)) {
|
|
135
|
+
sessions.set(activeSessionId, state);
|
|
136
|
+
}
|
|
137
|
+
if (request.method === "DELETE" && activeSessionId) {
|
|
138
|
+
await closeSession(activeSessionId);
|
|
139
|
+
} else if (!activeSessionId && createdState) {
|
|
140
|
+
await closeSessionState(state);
|
|
141
|
+
}
|
|
142
|
+
return response;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
if (createdState) {
|
|
145
|
+
await closeSessionState(state);
|
|
146
|
+
}
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return new Elysia({ name: `mcp-${serverName}` }).all(path, async ({ request }) => {
|
|
151
|
+
try {
|
|
152
|
+
if (validateAuth) {
|
|
153
|
+
const authResult = await validateAuth(request);
|
|
154
|
+
if (!authResult.valid) {
|
|
155
|
+
return createJsonRpcErrorResponse(401, -32002, "Authentication failed", authResult.reason);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (isStateful) {
|
|
159
|
+
return await handleStateful(request);
|
|
160
|
+
}
|
|
161
|
+
return await handleStateless(request);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
logger.error("Error handling MCP request", {
|
|
164
|
+
path,
|
|
165
|
+
method: request.method,
|
|
166
|
+
error: toErrorMessage(error)
|
|
167
|
+
});
|
|
168
|
+
return createJsonRpcErrorResponse(500, -32000, "Internal error");
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/infrastructure/elysia/logger.ts
|
|
174
|
+
import { Logger, LogLevel } from "@contractspec/lib.logger";
|
|
175
|
+
var createAppLogger = () => new Logger({
|
|
176
|
+
level: LogLevel.DEBUG,
|
|
177
|
+
environment: "development",
|
|
178
|
+
enableTracing: true,
|
|
179
|
+
enableTiming: true,
|
|
180
|
+
enableContext: true,
|
|
181
|
+
enableColors: true
|
|
182
|
+
});
|
|
183
|
+
var appLogger = createAppLogger();
|
|
184
|
+
var dbLogger = new Logger({
|
|
185
|
+
level: LogLevel.DEBUG,
|
|
186
|
+
environment: "development",
|
|
187
|
+
enableTracing: true,
|
|
188
|
+
enableTiming: true,
|
|
189
|
+
enableContext: true,
|
|
190
|
+
enableColors: true
|
|
191
|
+
});
|
|
192
|
+
var authLogger = new Logger({
|
|
193
|
+
level: LogLevel.INFO,
|
|
194
|
+
environment: "development",
|
|
195
|
+
enableTracing: true,
|
|
196
|
+
enableTiming: true,
|
|
197
|
+
enableContext: true,
|
|
198
|
+
enableColors: true
|
|
199
|
+
});
|
|
200
|
+
// src/application/mcp/providerRankingMcp.ts
|
|
201
|
+
import {
|
|
202
|
+
definePrompt,
|
|
203
|
+
defineResourceTemplate,
|
|
204
|
+
installOp,
|
|
205
|
+
OperationSpecRegistry,
|
|
206
|
+
PromptRegistry,
|
|
207
|
+
ResourceRegistry
|
|
208
|
+
} from "@contractspec/lib.contracts-spec";
|
|
209
|
+
import {
|
|
210
|
+
BenchmarkIngestCommand,
|
|
211
|
+
BenchmarkRunCustomCommand,
|
|
212
|
+
RankingRefreshCommand
|
|
213
|
+
} from "@contractspec/lib.contracts-spec/provider-ranking";
|
|
214
|
+
import z from "zod";
|
|
215
|
+
import { InMemoryProviderRankingStore } from "@contractspec/lib.provider-ranking/in-memory-store";
|
|
216
|
+
import { createDefaultIngesterRegistry } from "@contractspec/lib.provider-ranking/ingesters";
|
|
217
|
+
import { computeModelRankings } from "@contractspec/lib.provider-ranking/scoring";
|
|
218
|
+
import { normalizeBenchmarkResults } from "@contractspec/lib.provider-ranking/scoring";
|
|
219
|
+
var TransportFilterSchema = z.enum(["rest", "mcp", "webhook", "sdk"]).optional();
|
|
220
|
+
var AuthFilterSchema = z.enum([
|
|
221
|
+
"api-key",
|
|
222
|
+
"oauth2",
|
|
223
|
+
"bearer",
|
|
224
|
+
"header",
|
|
225
|
+
"basic",
|
|
226
|
+
"webhook-signing",
|
|
227
|
+
"service-account"
|
|
228
|
+
]).optional();
|
|
229
|
+
var RANKING_TAGS = ["ranking", "mcp", "ai"];
|
|
230
|
+
var RANKING_OWNERS = ["platform.ai"];
|
|
231
|
+
var sharedStore = null;
|
|
232
|
+
function getStore() {
|
|
233
|
+
if (!sharedStore) {
|
|
234
|
+
sharedStore = new InMemoryProviderRankingStore;
|
|
235
|
+
}
|
|
236
|
+
return sharedStore;
|
|
237
|
+
}
|
|
238
|
+
function buildRankingResources() {
|
|
239
|
+
const resources = new ResourceRegistry;
|
|
240
|
+
resources.register(defineResourceTemplate({
|
|
241
|
+
meta: {
|
|
242
|
+
uriTemplate: "ranking://leaderboard",
|
|
243
|
+
title: "AI Model Leaderboard",
|
|
244
|
+
description: "Current ranked list of AI models by composite score. Supports optional transport and authMethod query filters.",
|
|
245
|
+
mimeType: "application/json",
|
|
246
|
+
tags: RANKING_TAGS
|
|
247
|
+
},
|
|
248
|
+
input: z.object({
|
|
249
|
+
transport: TransportFilterSchema,
|
|
250
|
+
authMethod: AuthFilterSchema
|
|
251
|
+
}),
|
|
252
|
+
resolve: async ({ transport, authMethod }) => {
|
|
253
|
+
const store = getStore();
|
|
254
|
+
const result = await store.listModelRankings({
|
|
255
|
+
limit: 100,
|
|
256
|
+
requiredTransport: transport,
|
|
257
|
+
requiredAuthMethod: authMethod
|
|
258
|
+
});
|
|
259
|
+
return {
|
|
260
|
+
uri: "ranking://leaderboard",
|
|
261
|
+
mimeType: "application/json",
|
|
262
|
+
data: JSON.stringify(result, null, 2)
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}));
|
|
266
|
+
resources.register(defineResourceTemplate({
|
|
267
|
+
meta: {
|
|
268
|
+
uriTemplate: "ranking://leaderboard/{dimension}",
|
|
269
|
+
title: "AI Model Leaderboard by Dimension",
|
|
270
|
+
description: "Ranked list of AI models filtered by a specific dimension. Supports optional transport and authMethod query filters.",
|
|
271
|
+
mimeType: "application/json",
|
|
272
|
+
tags: RANKING_TAGS
|
|
273
|
+
},
|
|
274
|
+
input: z.object({
|
|
275
|
+
dimension: z.string(),
|
|
276
|
+
transport: TransportFilterSchema,
|
|
277
|
+
authMethod: AuthFilterSchema
|
|
278
|
+
}),
|
|
279
|
+
resolve: async ({ dimension, transport, authMethod }) => {
|
|
280
|
+
const store = getStore();
|
|
281
|
+
const result = await store.listModelRankings({
|
|
282
|
+
dimension,
|
|
283
|
+
limit: 100,
|
|
284
|
+
requiredTransport: transport,
|
|
285
|
+
requiredAuthMethod: authMethod
|
|
286
|
+
});
|
|
287
|
+
return {
|
|
288
|
+
uri: `ranking://leaderboard/${encodeURIComponent(dimension)}`,
|
|
289
|
+
mimeType: "application/json",
|
|
290
|
+
data: JSON.stringify(result, null, 2)
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}));
|
|
294
|
+
resources.register(defineResourceTemplate({
|
|
295
|
+
meta: {
|
|
296
|
+
uriTemplate: "ranking://model/{modelId}",
|
|
297
|
+
title: "AI Model Profile",
|
|
298
|
+
description: "Detailed profile for a specific AI model including scores and benchmarks.",
|
|
299
|
+
mimeType: "application/json",
|
|
300
|
+
tags: RANKING_TAGS
|
|
301
|
+
},
|
|
302
|
+
input: z.object({ modelId: z.string() }),
|
|
303
|
+
resolve: async ({ modelId }) => {
|
|
304
|
+
const store = getStore();
|
|
305
|
+
const profile = await store.getModelProfile(modelId);
|
|
306
|
+
if (!profile) {
|
|
307
|
+
return {
|
|
308
|
+
uri: `ranking://model/${encodeURIComponent(modelId)}`,
|
|
309
|
+
mimeType: "application/json",
|
|
310
|
+
data: JSON.stringify({ error: "not_found", modelId })
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
uri: `ranking://model/${encodeURIComponent(modelId)}`,
|
|
315
|
+
mimeType: "application/json",
|
|
316
|
+
data: JSON.stringify(profile, null, 2)
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
}));
|
|
320
|
+
resources.register(defineResourceTemplate({
|
|
321
|
+
meta: {
|
|
322
|
+
uriTemplate: "ranking://results",
|
|
323
|
+
title: "Benchmark Results",
|
|
324
|
+
description: "List of raw benchmark results from all ingested sources.",
|
|
325
|
+
mimeType: "application/json",
|
|
326
|
+
tags: RANKING_TAGS
|
|
327
|
+
},
|
|
328
|
+
input: z.object({}),
|
|
329
|
+
resolve: async () => {
|
|
330
|
+
const store = getStore();
|
|
331
|
+
const result = await store.listBenchmarkResults({ limit: 200 });
|
|
332
|
+
return {
|
|
333
|
+
uri: "ranking://results",
|
|
334
|
+
mimeType: "application/json",
|
|
335
|
+
data: JSON.stringify(result, null, 2)
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
}));
|
|
339
|
+
return resources;
|
|
340
|
+
}
|
|
341
|
+
function buildRankingPrompts() {
|
|
342
|
+
const prompts = new PromptRegistry;
|
|
343
|
+
prompts.register(definePrompt({
|
|
344
|
+
meta: {
|
|
345
|
+
key: "ranking.advisor",
|
|
346
|
+
version: "1.0.0",
|
|
347
|
+
title: "AI Model Advisor",
|
|
348
|
+
description: "Which AI model is best for a given task? Uses the leaderboard to recommend.",
|
|
349
|
+
tags: RANKING_TAGS,
|
|
350
|
+
stability: "beta",
|
|
351
|
+
owners: RANKING_OWNERS
|
|
352
|
+
},
|
|
353
|
+
args: [
|
|
354
|
+
{
|
|
355
|
+
name: "task",
|
|
356
|
+
description: "The task or use case to recommend a model for.",
|
|
357
|
+
required: true,
|
|
358
|
+
schema: z.string()
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
name: "priority",
|
|
362
|
+
description: "Priority dimension (coding, reasoning, cost, latency, etc.).",
|
|
363
|
+
required: false,
|
|
364
|
+
schema: z.string().optional()
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
name: "transport",
|
|
368
|
+
description: "Required transport type (rest, mcp, webhook, sdk).",
|
|
369
|
+
required: false,
|
|
370
|
+
schema: TransportFilterSchema
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
name: "authMethod",
|
|
374
|
+
description: "Required auth method (api-key, oauth2, bearer, etc.).",
|
|
375
|
+
required: false,
|
|
376
|
+
schema: AuthFilterSchema
|
|
377
|
+
}
|
|
378
|
+
],
|
|
379
|
+
input: z.object({
|
|
380
|
+
task: z.string(),
|
|
381
|
+
priority: z.string().optional(),
|
|
382
|
+
transport: TransportFilterSchema,
|
|
383
|
+
authMethod: AuthFilterSchema
|
|
384
|
+
}),
|
|
385
|
+
render: async ({ task, priority, transport, authMethod }) => {
|
|
386
|
+
const constraints = [];
|
|
387
|
+
if (priority)
|
|
388
|
+
constraints.push(`Prioritize: ${priority}.`);
|
|
389
|
+
if (transport)
|
|
390
|
+
constraints.push(`Required transport: ${transport}.`);
|
|
391
|
+
if (authMethod)
|
|
392
|
+
constraints.push(`Required auth: ${authMethod}.`);
|
|
393
|
+
return [
|
|
394
|
+
{
|
|
395
|
+
type: "text",
|
|
396
|
+
text: `Recommend the best AI model for: "${task}".${constraints.length ? ` ${constraints.join(" ")}` : ""} Use the leaderboard data to justify your recommendation.`
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
type: "resource",
|
|
400
|
+
uri: priority ? `ranking://leaderboard/${priority}` : "ranking://leaderboard",
|
|
401
|
+
title: "Leaderboard"
|
|
402
|
+
}
|
|
403
|
+
];
|
|
404
|
+
}
|
|
405
|
+
}));
|
|
406
|
+
return prompts;
|
|
407
|
+
}
|
|
408
|
+
function buildRankingOps() {
|
|
409
|
+
const registry = new OperationSpecRegistry;
|
|
410
|
+
const ingesterRegistry = createDefaultIngesterRegistry();
|
|
411
|
+
installOp(registry, BenchmarkIngestCommand, async (args) => {
|
|
412
|
+
const store = getStore();
|
|
413
|
+
const source = args.source;
|
|
414
|
+
const ingester = ingesterRegistry.get(source);
|
|
415
|
+
if (!ingester) {
|
|
416
|
+
throw new Error(`No ingester registered for source: ${source}`);
|
|
417
|
+
}
|
|
418
|
+
const rawResults = await ingester.ingest({
|
|
419
|
+
sourceUrl: args.sourceUrl,
|
|
420
|
+
dimensions: args.dimensions
|
|
421
|
+
});
|
|
422
|
+
const normalized = normalizeBenchmarkResults(rawResults);
|
|
423
|
+
for (const result of normalized) {
|
|
424
|
+
await store.upsertBenchmarkResult(result);
|
|
425
|
+
}
|
|
426
|
+
return {
|
|
427
|
+
ingestionId: `ingest-${source}-${Date.now()}`,
|
|
428
|
+
source,
|
|
429
|
+
resultsCount: normalized.length,
|
|
430
|
+
status: "completed",
|
|
431
|
+
ingestedAt: new Date
|
|
432
|
+
};
|
|
433
|
+
});
|
|
434
|
+
installOp(registry, BenchmarkRunCustomCommand, async (args) => {
|
|
435
|
+
return {
|
|
436
|
+
runId: `custom-${Date.now()}`,
|
|
437
|
+
evalSuiteKey: args.evalSuiteKey,
|
|
438
|
+
modelId: args.modelId,
|
|
439
|
+
status: "started",
|
|
440
|
+
startedAt: new Date
|
|
441
|
+
};
|
|
442
|
+
});
|
|
443
|
+
installOp(registry, RankingRefreshCommand, async (args) => {
|
|
444
|
+
const store = getStore();
|
|
445
|
+
const allResults = [];
|
|
446
|
+
let offset = 0;
|
|
447
|
+
const pageSize = 500;
|
|
448
|
+
while (true) {
|
|
449
|
+
const page = await store.listBenchmarkResults({
|
|
450
|
+
limit: pageSize,
|
|
451
|
+
offset
|
|
452
|
+
});
|
|
453
|
+
allResults.push(...page.results);
|
|
454
|
+
if (allResults.length >= page.total || page.results.length < pageSize)
|
|
455
|
+
break;
|
|
456
|
+
offset += pageSize;
|
|
457
|
+
}
|
|
458
|
+
const existingRankings = new Map((await store.listModelRankings({ limit: 1e4 })).rankings.map((r) => [
|
|
459
|
+
r.modelId,
|
|
460
|
+
r
|
|
461
|
+
]));
|
|
462
|
+
const weightOverrides = args.weightOverrides ? Array.isArray(args.weightOverrides) ? args.weightOverrides : [args.weightOverrides] : undefined;
|
|
463
|
+
const newRankings = computeModelRankings(allResults, weightOverrides ? {
|
|
464
|
+
weightOverrides
|
|
465
|
+
} : undefined, existingRankings);
|
|
466
|
+
for (const ranking of newRankings) {
|
|
467
|
+
await store.upsertModelRanking(ranking);
|
|
468
|
+
}
|
|
469
|
+
return {
|
|
470
|
+
modelsRanked: newRankings.length,
|
|
471
|
+
updatedAt: new Date,
|
|
472
|
+
status: "completed"
|
|
473
|
+
};
|
|
474
|
+
});
|
|
475
|
+
return registry;
|
|
476
|
+
}
|
|
477
|
+
function createProviderRankingMcpHandler(path = "/api/mcp/ranking") {
|
|
478
|
+
return createMcpElysiaHandler({
|
|
479
|
+
logger: appLogger,
|
|
480
|
+
path,
|
|
481
|
+
serverName: "contractspec-ranking-mcp",
|
|
482
|
+
ops: buildRankingOps(),
|
|
483
|
+
resources: buildRankingResources(),
|
|
484
|
+
prompts: buildRankingPrompts()
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
function setProviderRankingStore(store) {
|
|
488
|
+
sharedStore = store;
|
|
489
|
+
}
|
|
490
|
+
export {
|
|
491
|
+
setProviderRankingStore,
|
|
492
|
+
createProviderRankingMcpHandler
|
|
493
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/bundle.library",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rm -rf dist",
|
|
@@ -30,6 +30,18 @@
|
|
|
30
30
|
"node": "./dist/node/application/index.js",
|
|
31
31
|
"default": "./dist/application/index.js"
|
|
32
32
|
},
|
|
33
|
+
"./application/context-storage": {
|
|
34
|
+
"types": "./dist/application/context-storage/index.d.ts",
|
|
35
|
+
"bun": "./dist/application/context-storage/index.js",
|
|
36
|
+
"node": "./dist/node/application/context-storage/index.js",
|
|
37
|
+
"default": "./dist/application/context-storage/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./application/context-storage/index": {
|
|
40
|
+
"types": "./dist/application/context-storage/index.d.ts",
|
|
41
|
+
"bun": "./dist/application/context-storage/index.js",
|
|
42
|
+
"node": "./dist/node/application/context-storage/index.js",
|
|
43
|
+
"default": "./dist/application/context-storage/index.js"
|
|
44
|
+
},
|
|
33
45
|
"./application/index": {
|
|
34
46
|
"types": "./dist/application/index.d.ts",
|
|
35
47
|
"bun": "./dist/application/index.js",
|
|
@@ -54,6 +66,30 @@
|
|
|
54
66
|
"node": "./dist/node/application/mcp/common.js",
|
|
55
67
|
"default": "./dist/application/mcp/common.js"
|
|
56
68
|
},
|
|
69
|
+
"./application/mcp/contractsMcp": {
|
|
70
|
+
"types": "./dist/application/mcp/contractsMcp.d.ts",
|
|
71
|
+
"bun": "./dist/application/mcp/contractsMcp.js",
|
|
72
|
+
"node": "./dist/node/application/mcp/contractsMcp.js",
|
|
73
|
+
"default": "./dist/application/mcp/contractsMcp.js"
|
|
74
|
+
},
|
|
75
|
+
"./application/mcp/contractsMcpResources": {
|
|
76
|
+
"types": "./dist/application/mcp/contractsMcpResources.d.ts",
|
|
77
|
+
"bun": "./dist/application/mcp/contractsMcpResources.js",
|
|
78
|
+
"node": "./dist/node/application/mcp/contractsMcpResources.js",
|
|
79
|
+
"default": "./dist/application/mcp/contractsMcpResources.js"
|
|
80
|
+
},
|
|
81
|
+
"./application/mcp/contractsMcpTools": {
|
|
82
|
+
"types": "./dist/application/mcp/contractsMcpTools.d.ts",
|
|
83
|
+
"bun": "./dist/application/mcp/contractsMcpTools.js",
|
|
84
|
+
"node": "./dist/node/application/mcp/contractsMcpTools.js",
|
|
85
|
+
"default": "./dist/application/mcp/contractsMcpTools.js"
|
|
86
|
+
},
|
|
87
|
+
"./application/mcp/contractsMcpTypes": {
|
|
88
|
+
"types": "./dist/application/mcp/contractsMcpTypes.d.ts",
|
|
89
|
+
"bun": "./dist/application/mcp/contractsMcpTypes.js",
|
|
90
|
+
"node": "./dist/node/application/mcp/contractsMcpTypes.js",
|
|
91
|
+
"default": "./dist/application/mcp/contractsMcpTypes.js"
|
|
92
|
+
},
|
|
57
93
|
"./application/mcp/docsMcp": {
|
|
58
94
|
"types": "./dist/application/mcp/docsMcp.d.ts",
|
|
59
95
|
"bun": "./dist/application/mcp/docsMcp.js",
|
|
@@ -72,6 +108,12 @@
|
|
|
72
108
|
"node": "./dist/node/application/mcp/internalMcp.js",
|
|
73
109
|
"default": "./dist/application/mcp/internalMcp.js"
|
|
74
110
|
},
|
|
111
|
+
"./application/mcp/providerRankingMcp": {
|
|
112
|
+
"types": "./dist/application/mcp/providerRankingMcp.d.ts",
|
|
113
|
+
"bun": "./dist/application/mcp/providerRankingMcp.js",
|
|
114
|
+
"node": "./dist/node/application/mcp/providerRankingMcp.js",
|
|
115
|
+
"default": "./dist/application/mcp/providerRankingMcp.js"
|
|
116
|
+
},
|
|
75
117
|
"./components/docs": {
|
|
76
118
|
"types": "./dist/components/docs/index.d.ts",
|
|
77
119
|
"bun": "./dist/components/docs/index.js",
|
|
@@ -2095,41 +2137,43 @@
|
|
|
2095
2137
|
},
|
|
2096
2138
|
"dependencies": {
|
|
2097
2139
|
"@apollo/client": "^4.1.6",
|
|
2098
|
-
"@contractspec/lib.contracts-spec": "3.
|
|
2099
|
-
"@contractspec/lib.contracts-library": "3.
|
|
2100
|
-
"@contractspec/lib.contracts-runtime-server-mcp": "3.
|
|
2101
|
-
"@contractspec/lib.design-system": "3.
|
|
2102
|
-
"@contractspec/lib.example-shared-ui": "3.
|
|
2103
|
-
"@contractspec/lib.
|
|
2104
|
-
"@contractspec/lib.
|
|
2105
|
-
"@contractspec/lib.
|
|
2106
|
-
"@contractspec/lib.
|
|
2107
|
-
"@contractspec/lib.ui-
|
|
2108
|
-
"@contractspec/
|
|
2140
|
+
"@contractspec/lib.contracts-spec": "3.1.1",
|
|
2141
|
+
"@contractspec/lib.contracts-library": "3.1.1",
|
|
2142
|
+
"@contractspec/lib.contracts-runtime-server-mcp": "3.1.1",
|
|
2143
|
+
"@contractspec/lib.design-system": "3.1.1",
|
|
2144
|
+
"@contractspec/lib.example-shared-ui": "3.1.1",
|
|
2145
|
+
"@contractspec/lib.knowledge": "3.1.1",
|
|
2146
|
+
"@contractspec/lib.logger": "3.1.0",
|
|
2147
|
+
"@contractspec/lib.runtime-sandbox": "2.1.0",
|
|
2148
|
+
"@contractspec/lib.schema": "3.1.0",
|
|
2149
|
+
"@contractspec/lib.ui-kit-web": "3.1.0",
|
|
2150
|
+
"@contractspec/lib.ui-link": "3.1.0",
|
|
2151
|
+
"@contractspec/module.context-storage": "0.1.2",
|
|
2152
|
+
"@contractspec/module.examples": "3.1.1",
|
|
2109
2153
|
"@dnd-kit/core": "^6.1.0",
|
|
2110
2154
|
"@dnd-kit/sortable": "^10.0.0",
|
|
2111
2155
|
"@dnd-kit/utilities": "^3.2.2",
|
|
2112
2156
|
"@electric-sql/pglite": "^0.3.14",
|
|
2113
|
-
"@scaleway/sdk": "^3.
|
|
2114
|
-
"@scaleway/sdk-client": "^2.1
|
|
2157
|
+
"@scaleway/sdk": "^3.3.1",
|
|
2158
|
+
"@scaleway/sdk-client": "^2.2.1",
|
|
2115
2159
|
"drizzle-orm": "^0.45.1",
|
|
2116
|
-
"framer-motion": "^12.
|
|
2117
|
-
"lucide-react": "^0.
|
|
2118
|
-
"posthog-js": "^1.
|
|
2119
|
-
"posthog-node": "^5.
|
|
2120
|
-
"posthog-react-native": "^4.
|
|
2160
|
+
"framer-motion": "^12.35.0",
|
|
2161
|
+
"lucide-react": "^0.577.0",
|
|
2162
|
+
"posthog-js": "^1.359.1",
|
|
2163
|
+
"posthog-node": "^5.28.0",
|
|
2164
|
+
"posthog-react-native": "^4.37.1",
|
|
2121
2165
|
"react-hook-form": "^7.71.2",
|
|
2122
2166
|
"zod": "^4.3.5",
|
|
2123
|
-
"@contractspec/lib.contracts-integrations": "3.
|
|
2124
|
-
"@contractspec/lib.contracts-runtime-server-rest": "3.
|
|
2125
|
-
"@contractspec/lib.contracts-runtime-server-graphql": "3.
|
|
2167
|
+
"@contractspec/lib.contracts-integrations": "3.1.1",
|
|
2168
|
+
"@contractspec/lib.contracts-runtime-server-rest": "3.1.1",
|
|
2169
|
+
"@contractspec/lib.contracts-runtime-server-graphql": "3.1.1"
|
|
2126
2170
|
},
|
|
2127
2171
|
"devDependencies": {
|
|
2128
2172
|
"@types/react": "~19.2.14",
|
|
2129
|
-
"@contractspec/tool.typescript": "3.
|
|
2173
|
+
"@contractspec/tool.typescript": "3.1.0",
|
|
2130
2174
|
"typescript": "^5.9.3",
|
|
2131
|
-
"@types/bun": "~1.3.
|
|
2132
|
-
"@contractspec/tool.bun": "3.
|
|
2175
|
+
"@types/bun": "~1.3.10",
|
|
2176
|
+
"@contractspec/tool.bun": "3.1.0"
|
|
2133
2177
|
},
|
|
2134
2178
|
"publishConfig": {
|
|
2135
2179
|
"access": "public",
|
|
@@ -2147,6 +2191,18 @@
|
|
|
2147
2191
|
"node": "./dist/node/application/index.js",
|
|
2148
2192
|
"default": "./dist/application/index.js"
|
|
2149
2193
|
},
|
|
2194
|
+
"./application/context-storage": {
|
|
2195
|
+
"types": "./dist/application/context-storage/index.d.ts",
|
|
2196
|
+
"bun": "./dist/application/context-storage/index.js",
|
|
2197
|
+
"node": "./dist/node/application/context-storage/index.js",
|
|
2198
|
+
"default": "./dist/application/context-storage/index.js"
|
|
2199
|
+
},
|
|
2200
|
+
"./application/context-storage/index": {
|
|
2201
|
+
"types": "./dist/application/context-storage/index.d.ts",
|
|
2202
|
+
"bun": "./dist/application/context-storage/index.js",
|
|
2203
|
+
"node": "./dist/node/application/context-storage/index.js",
|
|
2204
|
+
"default": "./dist/application/context-storage/index.js"
|
|
2205
|
+
},
|
|
2150
2206
|
"./application/index": {
|
|
2151
2207
|
"types": "./dist/application/index.d.ts",
|
|
2152
2208
|
"bun": "./dist/application/index.js",
|
|
@@ -2171,6 +2227,30 @@
|
|
|
2171
2227
|
"node": "./dist/node/application/mcp/common.js",
|
|
2172
2228
|
"default": "./dist/application/mcp/common.js"
|
|
2173
2229
|
},
|
|
2230
|
+
"./application/mcp/contractsMcp": {
|
|
2231
|
+
"types": "./dist/application/mcp/contractsMcp.d.ts",
|
|
2232
|
+
"bun": "./dist/application/mcp/contractsMcp.js",
|
|
2233
|
+
"node": "./dist/node/application/mcp/contractsMcp.js",
|
|
2234
|
+
"default": "./dist/application/mcp/contractsMcp.js"
|
|
2235
|
+
},
|
|
2236
|
+
"./application/mcp/contractsMcpResources": {
|
|
2237
|
+
"types": "./dist/application/mcp/contractsMcpResources.d.ts",
|
|
2238
|
+
"bun": "./dist/application/mcp/contractsMcpResources.js",
|
|
2239
|
+
"node": "./dist/node/application/mcp/contractsMcpResources.js",
|
|
2240
|
+
"default": "./dist/application/mcp/contractsMcpResources.js"
|
|
2241
|
+
},
|
|
2242
|
+
"./application/mcp/contractsMcpTools": {
|
|
2243
|
+
"types": "./dist/application/mcp/contractsMcpTools.d.ts",
|
|
2244
|
+
"bun": "./dist/application/mcp/contractsMcpTools.js",
|
|
2245
|
+
"node": "./dist/node/application/mcp/contractsMcpTools.js",
|
|
2246
|
+
"default": "./dist/application/mcp/contractsMcpTools.js"
|
|
2247
|
+
},
|
|
2248
|
+
"./application/mcp/contractsMcpTypes": {
|
|
2249
|
+
"types": "./dist/application/mcp/contractsMcpTypes.d.ts",
|
|
2250
|
+
"bun": "./dist/application/mcp/contractsMcpTypes.js",
|
|
2251
|
+
"node": "./dist/node/application/mcp/contractsMcpTypes.js",
|
|
2252
|
+
"default": "./dist/application/mcp/contractsMcpTypes.js"
|
|
2253
|
+
},
|
|
2174
2254
|
"./application/mcp/docsMcp": {
|
|
2175
2255
|
"types": "./dist/application/mcp/docsMcp.d.ts",
|
|
2176
2256
|
"bun": "./dist/application/mcp/docsMcp.js",
|
|
@@ -2189,6 +2269,12 @@
|
|
|
2189
2269
|
"node": "./dist/node/application/mcp/internalMcp.js",
|
|
2190
2270
|
"default": "./dist/application/mcp/internalMcp.js"
|
|
2191
2271
|
},
|
|
2272
|
+
"./application/mcp/providerRankingMcp": {
|
|
2273
|
+
"types": "./dist/application/mcp/providerRankingMcp.d.ts",
|
|
2274
|
+
"bun": "./dist/application/mcp/providerRankingMcp.js",
|
|
2275
|
+
"node": "./dist/node/application/mcp/providerRankingMcp.js",
|
|
2276
|
+
"default": "./dist/application/mcp/providerRankingMcp.js"
|
|
2277
|
+
},
|
|
2192
2278
|
"./components/docs": {
|
|
2193
2279
|
"types": "./dist/components/docs/index.d.ts",
|
|
2194
2280
|
"bun": "./dist/components/docs/index.js",
|