@contractspec/bundle.library 2.9.1 → 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 +240 -214
- package/AGENTS.md +19 -12
- package/CHANGELOG.md +84 -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/components/docs/DocsIndexPage.js +1 -1
- package/dist/components/docs/architecture/ArchitectureControlPlanePage.d.ts +1 -0
- package/dist/components/docs/architecture/ArchitectureControlPlanePage.js +204 -0
- package/dist/components/docs/architecture/ArchitectureOverviewPage.js +17 -1
- package/dist/components/docs/architecture/index.d.ts +1 -0
- package/dist/components/docs/architecture/index.js +507 -289
- package/dist/components/docs/ecosystem/IntegrationsPage.js +6 -3
- package/dist/components/docs/ecosystem/PluginsPage.js +98 -98
- package/dist/components/docs/ecosystem/RegistryPage.js +39 -42
- package/dist/components/docs/ecosystem/TemplatesPage.js +26 -21
- package/dist/components/docs/ecosystem/ecosystem.docblocks.js +10 -10
- package/dist/components/docs/ecosystem/index.js +179 -174
- package/dist/components/docs/index.js +6795 -5376
- package/dist/components/docs/integrations/IntegrationsElevenLabsPage.js +2 -2
- package/dist/components/docs/integrations/IntegrationsGithubPage.d.ts +1 -0
- package/dist/components/docs/integrations/IntegrationsGithubPage.js +155 -0
- package/dist/components/docs/integrations/IntegrationsHealthRoutingPage.d.ts +1 -0
- package/dist/components/docs/integrations/IntegrationsHealthRoutingPage.js +168 -0
- package/dist/components/docs/integrations/IntegrationsMistralPage.d.ts +1 -0
- package/dist/components/docs/integrations/IntegrationsMistralPage.js +203 -0
- package/dist/components/docs/integrations/IntegrationsOpenAIPage.js +2 -2
- package/dist/components/docs/integrations/IntegrationsOverviewPage.js +136 -9
- package/dist/components/docs/integrations/IntegrationsSlackPage.d.ts +1 -0
- package/dist/components/docs/integrations/IntegrationsSlackPage.js +161 -0
- package/dist/components/docs/integrations/IntegrationsSpecModelPage.js +72 -0
- package/dist/components/docs/integrations/IntegrationsTwilioPage.js +2 -2
- package/dist/components/docs/integrations/IntegrationsWhatsappMetaPage.d.ts +1 -0
- package/dist/components/docs/integrations/IntegrationsWhatsappMetaPage.js +157 -0
- package/dist/components/docs/integrations/IntegrationsWhatsappTwilioPage.d.ts +1 -0
- package/dist/components/docs/integrations/IntegrationsWhatsappTwilioPage.js +165 -0
- package/dist/components/docs/integrations/index.d.ts +6 -0
- package/dist/components/docs/integrations/index.js +1688 -492
- package/dist/index.js +8016 -6597
- 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/dist/node/components/docs/DocsIndexPage.js +1 -1
- package/dist/node/components/docs/architecture/ArchitectureControlPlanePage.js +203 -0
- package/dist/node/components/docs/architecture/ArchitectureOverviewPage.js +17 -1
- package/dist/node/components/docs/architecture/index.js +507 -289
- package/dist/node/components/docs/ecosystem/IntegrationsPage.js +6 -3
- package/dist/node/components/docs/ecosystem/PluginsPage.js +98 -98
- package/dist/node/components/docs/ecosystem/RegistryPage.js +39 -42
- package/dist/node/components/docs/ecosystem/TemplatesPage.js +26 -21
- package/dist/node/components/docs/ecosystem/ecosystem.docblocks.js +10 -10
- package/dist/node/components/docs/ecosystem/index.js +179 -174
- package/dist/node/components/docs/index.js +6795 -5376
- package/dist/node/components/docs/integrations/IntegrationsElevenLabsPage.js +2 -2
- package/dist/node/components/docs/integrations/IntegrationsGithubPage.js +154 -0
- package/dist/node/components/docs/integrations/IntegrationsHealthRoutingPage.js +167 -0
- package/dist/node/components/docs/integrations/IntegrationsMistralPage.js +202 -0
- package/dist/node/components/docs/integrations/IntegrationsOpenAIPage.js +2 -2
- package/dist/node/components/docs/integrations/IntegrationsOverviewPage.js +136 -9
- package/dist/node/components/docs/integrations/IntegrationsSlackPage.js +160 -0
- package/dist/node/components/docs/integrations/IntegrationsSpecModelPage.js +72 -0
- package/dist/node/components/docs/integrations/IntegrationsTwilioPage.js +2 -2
- package/dist/node/components/docs/integrations/IntegrationsWhatsappMetaPage.js +156 -0
- package/dist/node/components/docs/integrations/IntegrationsWhatsappTwilioPage.js +164 -0
- package/dist/node/components/docs/integrations/index.js +1688 -492
- package/dist/node/index.js +8016 -6597
- package/package.json +195 -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/DocsIndexPage.tsx +2 -1
- package/src/components/docs/architecture/ArchitectureControlPlanePage.tsx +136 -0
- package/src/components/docs/architecture/ArchitectureOverviewPage.tsx +13 -1
- package/src/components/docs/architecture/index.ts +1 -0
- package/src/components/docs/ecosystem/IntegrationsPage.tsx +4 -3
- package/src/components/docs/ecosystem/PluginsPage.tsx +68 -87
- package/src/components/docs/ecosystem/RegistryPage.tsx +35 -43
- package/src/components/docs/ecosystem/TemplatesPage.tsx +28 -21
- package/src/components/docs/ecosystem/ecosystem.docblocks.ts +12 -10
- package/src/components/docs/generated/docs-index._common.json +1119 -1
- package/src/components/docs/generated/docs-index.health.json +98 -0
- package/src/components/docs/generated/docs-index.manifest.json +15 -5
- package/src/components/docs/generated/docs-index.metrics.json +8 -0
- package/src/components/docs/generated/docs-index.platform-integrations.json +89 -1
- package/src/components/docs/generated/docs-index.video-api-showcase.json +26 -0
- package/src/components/docs/integrations/IntegrationsElevenLabsPage.tsx +2 -2
- package/src/components/docs/integrations/IntegrationsGithubPage.tsx +90 -0
- package/src/components/docs/integrations/IntegrationsHealthRoutingPage.tsx +112 -0
- package/src/components/docs/integrations/IntegrationsMistralPage.tsx +133 -0
- package/src/components/docs/integrations/IntegrationsOpenAIPage.tsx +2 -2
- package/src/components/docs/integrations/IntegrationsOverviewPage.tsx +108 -9
- package/src/components/docs/integrations/IntegrationsSlackPage.tsx +98 -0
- package/src/components/docs/integrations/IntegrationsSpecModelPage.tsx +59 -0
- package/src/components/docs/integrations/IntegrationsTwilioPage.tsx +2 -2
- package/src/components/docs/integrations/IntegrationsWhatsappMetaPage.tsx +90 -0
- package/src/components/docs/integrations/IntegrationsWhatsappTwilioPage.tsx +92 -0
- package/src/components/docs/integrations/index.ts +6 -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
|
+
};
|
|
@@ -207,7 +207,7 @@ bun contractspec build src/contracts/mySpec.ts`
|
|
|
207
207
|
},
|
|
208
208
|
{
|
|
209
209
|
title: "Ecosystem",
|
|
210
|
-
description: "
|
|
210
|
+
description: "Cursor marketplace plugins, templates, manifest, and integrations",
|
|
211
211
|
href: "/docs/ecosystem/plugins"
|
|
212
212
|
},
|
|
213
213
|
{
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// src/components/docs/architecture/ArchitectureControlPlanePage.tsx
|
|
2
|
+
import { CodeBlock } from "@contractspec/lib.design-system";
|
|
3
|
+
import Link from "@contractspec/lib.ui-link";
|
|
4
|
+
import { ChevronRight } from "lucide-react";
|
|
5
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
6
|
+
function ArchitectureControlPlanePage() {
|
|
7
|
+
return /* @__PURE__ */ jsxDEV("div", {
|
|
8
|
+
className: "space-y-8",
|
|
9
|
+
children: [
|
|
10
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
11
|
+
className: "space-y-4",
|
|
12
|
+
children: [
|
|
13
|
+
/* @__PURE__ */ jsxDEV("h1", {
|
|
14
|
+
className: "text-4xl font-bold",
|
|
15
|
+
children: "Control Plane Runtime"
|
|
16
|
+
}, undefined, false, undefined, this),
|
|
17
|
+
/* @__PURE__ */ jsxDEV("p", {
|
|
18
|
+
className: "text-muted-foreground",
|
|
19
|
+
children: "The control plane is the governance layer for agentic execution. It turns incoming intent into deterministic plans, enforces risk policy before side effects, and records replayable traces for audits."
|
|
20
|
+
}, undefined, false, undefined, this)
|
|
21
|
+
]
|
|
22
|
+
}, undefined, true, undefined, this),
|
|
23
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
24
|
+
className: "space-y-4",
|
|
25
|
+
children: [
|
|
26
|
+
/* @__PURE__ */ jsxDEV("h2", {
|
|
27
|
+
className: "text-2xl font-bold",
|
|
28
|
+
children: "Canonical execution loop"
|
|
29
|
+
}, undefined, false, undefined, this),
|
|
30
|
+
/* @__PURE__ */ jsxDEV("ol", {
|
|
31
|
+
className: "text-muted-foreground list-inside list-decimal space-y-2",
|
|
32
|
+
children: [
|
|
33
|
+
/* @__PURE__ */ jsxDEV("li", {
|
|
34
|
+
children: "Accept intent and create execution identity + trace context."
|
|
35
|
+
}, undefined, false, undefined, this),
|
|
36
|
+
/* @__PURE__ */ jsxDEV("li", {
|
|
37
|
+
children: "Compile intent into a typed, deterministic plan DAG."
|
|
38
|
+
}, undefined, false, undefined, this),
|
|
39
|
+
/* @__PURE__ */ jsxDEV("li", {
|
|
40
|
+
children: "Verify plan against policy and risk rules."
|
|
41
|
+
}, undefined, false, undefined, this),
|
|
42
|
+
/* @__PURE__ */ jsxDEV("li", {
|
|
43
|
+
children: "Route into autonomous or assist mode based on verdict."
|
|
44
|
+
}, undefined, false, undefined, this),
|
|
45
|
+
/* @__PURE__ */ jsxDEV("li", {
|
|
46
|
+
children: "Execute steps with idempotent keys and explicit stage events."
|
|
47
|
+
}, undefined, false, undefined, this),
|
|
48
|
+
/* @__PURE__ */ jsxDEV("li", {
|
|
49
|
+
children: "Persist outcomes for replay, audits, and operator visibility."
|
|
50
|
+
}, undefined, false, undefined, this)
|
|
51
|
+
]
|
|
52
|
+
}, undefined, true, undefined, this)
|
|
53
|
+
]
|
|
54
|
+
}, undefined, true, undefined, this),
|
|
55
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
56
|
+
className: "space-y-4",
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ jsxDEV("h2", {
|
|
59
|
+
className: "text-2xl font-bold",
|
|
60
|
+
children: "Contract surfaces (v1 baseline)"
|
|
61
|
+
}, undefined, false, undefined, this),
|
|
62
|
+
/* @__PURE__ */ jsxDEV("p", {
|
|
63
|
+
className: "text-muted-foreground",
|
|
64
|
+
children: [
|
|
65
|
+
"The runtime is contract-first. Commands, queries, events, and capabilities are explicit and versioned under",
|
|
66
|
+
/* @__PURE__ */ jsxDEV("code", {
|
|
67
|
+
children: " @contractspec/lib.contracts-spec"
|
|
68
|
+
}, undefined, false, undefined, this),
|
|
69
|
+
"."
|
|
70
|
+
]
|
|
71
|
+
}, undefined, true, undefined, this),
|
|
72
|
+
/* @__PURE__ */ jsxDEV(CodeBlock, {
|
|
73
|
+
language: "text",
|
|
74
|
+
code: `Commands
|
|
75
|
+
- controlPlane.intent.submit
|
|
76
|
+
- controlPlane.plan.compile
|
|
77
|
+
- controlPlane.plan.verify
|
|
78
|
+
- controlPlane.execution.start
|
|
79
|
+
- controlPlane.execution.approve
|
|
80
|
+
- controlPlane.execution.reject
|
|
81
|
+
- controlPlane.execution.cancel
|
|
82
|
+
- controlPlane.skill.install
|
|
83
|
+
- controlPlane.skill.disable
|
|
84
|
+
|
|
85
|
+
Queries
|
|
86
|
+
- controlPlane.execution.get
|
|
87
|
+
- controlPlane.execution.list
|
|
88
|
+
- controlPlane.trace.get
|
|
89
|
+
- controlPlane.policy.explain
|
|
90
|
+
- controlPlane.skill.list
|
|
91
|
+
- controlPlane.skill.verify
|
|
92
|
+
|
|
93
|
+
Events
|
|
94
|
+
- controlPlane.intent.received
|
|
95
|
+
- controlPlane.plan.compiled
|
|
96
|
+
- controlPlane.plan.rejected
|
|
97
|
+
- controlPlane.execution.step.started
|
|
98
|
+
- controlPlane.execution.step.blocked
|
|
99
|
+
- controlPlane.execution.step.completed
|
|
100
|
+
- controlPlane.execution.completed
|
|
101
|
+
- controlPlane.execution.failed
|
|
102
|
+
- controlPlane.skill.installed
|
|
103
|
+
- controlPlane.skill.rejected
|
|
104
|
+
|
|
105
|
+
Capabilities
|
|
106
|
+
- control-plane.core
|
|
107
|
+
- control-plane.approval
|
|
108
|
+
- control-plane.audit
|
|
109
|
+
- control-plane.skill-registry
|
|
110
|
+
- control-plane.channel-runtime`
|
|
111
|
+
}, undefined, false, undefined, this)
|
|
112
|
+
]
|
|
113
|
+
}, undefined, true, undefined, this),
|
|
114
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
115
|
+
className: "space-y-4",
|
|
116
|
+
children: [
|
|
117
|
+
/* @__PURE__ */ jsxDEV("h2", {
|
|
118
|
+
className: "text-2xl font-bold",
|
|
119
|
+
children: "Policy and safety posture"
|
|
120
|
+
}, undefined, false, undefined, this),
|
|
121
|
+
/* @__PURE__ */ jsxDEV("ul", {
|
|
122
|
+
className: "text-muted-foreground list-inside list-disc space-y-2",
|
|
123
|
+
children: [
|
|
124
|
+
/* @__PURE__ */ jsxDEV("li", {
|
|
125
|
+
children: "No side-effect action executes unless it comes from a compiled plan."
|
|
126
|
+
}, undefined, false, undefined, this),
|
|
127
|
+
/* @__PURE__ */ jsxDEV("li", {
|
|
128
|
+
children: "High-risk actions are blocked from autonomous mode in v1."
|
|
129
|
+
}, undefined, false, undefined, this),
|
|
130
|
+
/* @__PURE__ */ jsxDEV("li", {
|
|
131
|
+
children: "Approval commands provide explicit human-in-the-loop transitions."
|
|
132
|
+
}, undefined, false, undefined, this),
|
|
133
|
+
/* @__PURE__ */ jsxDEV("li", {
|
|
134
|
+
children: "Skill installation is modeled as governance-controlled operations."
|
|
135
|
+
}, undefined, false, undefined, this),
|
|
136
|
+
/* @__PURE__ */ jsxDEV("li", {
|
|
137
|
+
children: "Trace queries expose policy rationale and step outcomes for replay."
|
|
138
|
+
}, undefined, false, undefined, this)
|
|
139
|
+
]
|
|
140
|
+
}, undefined, true, undefined, this)
|
|
141
|
+
]
|
|
142
|
+
}, undefined, true, undefined, this),
|
|
143
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
144
|
+
className: "space-y-4",
|
|
145
|
+
children: [
|
|
146
|
+
/* @__PURE__ */ jsxDEV("h2", {
|
|
147
|
+
className: "text-2xl font-bold",
|
|
148
|
+
children: "Implementation map"
|
|
149
|
+
}, undefined, false, undefined, this),
|
|
150
|
+
/* @__PURE__ */ jsxDEV(CodeBlock, {
|
|
151
|
+
language: "text",
|
|
152
|
+
code: `packages/libs/contracts-spec/src/control-plane/
|
|
153
|
+
commands/
|
|
154
|
+
queries/
|
|
155
|
+
events/
|
|
156
|
+
capabilities/
|
|
157
|
+
contracts.ts
|
|
158
|
+
contracts.test.ts
|
|
159
|
+
|
|
160
|
+
packages/apps/web-landing/src/app/docs/architecture/control-plane/page.tsx
|
|
161
|
+
implementation_plan_controle_plane.md`
|
|
162
|
+
}, undefined, false, undefined, this)
|
|
163
|
+
]
|
|
164
|
+
}, undefined, true, undefined, this),
|
|
165
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
166
|
+
className: "space-y-4",
|
|
167
|
+
children: [
|
|
168
|
+
/* @__PURE__ */ jsxDEV("h2", {
|
|
169
|
+
className: "text-2xl font-bold",
|
|
170
|
+
children: "What comes next"
|
|
171
|
+
}, undefined, false, undefined, this),
|
|
172
|
+
/* @__PURE__ */ jsxDEV("p", {
|
|
173
|
+
className: "text-muted-foreground",
|
|
174
|
+
children: "WS1 delivers the contract fabric. Next increments add planner/executor split, policy escalation, capability-bound authorization, signed skill compatibility checks, and full replay tooling."
|
|
175
|
+
}, undefined, false, undefined, this)
|
|
176
|
+
]
|
|
177
|
+
}, undefined, true, undefined, this),
|
|
178
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
179
|
+
className: "flex items-center gap-4 pt-4",
|
|
180
|
+
children: [
|
|
181
|
+
/* @__PURE__ */ jsxDEV(Link, {
|
|
182
|
+
href: "/docs/architecture/integration-binding",
|
|
183
|
+
className: "btn-ghost",
|
|
184
|
+
children: "Previous: Integration Binding"
|
|
185
|
+
}, undefined, false, undefined, this),
|
|
186
|
+
/* @__PURE__ */ jsxDEV(Link, {
|
|
187
|
+
href: "/docs/safety/auditing",
|
|
188
|
+
className: "btn-primary",
|
|
189
|
+
children: [
|
|
190
|
+
"Audit Logs ",
|
|
191
|
+
/* @__PURE__ */ jsxDEV(ChevronRight, {
|
|
192
|
+
size: 16
|
|
193
|
+
}, undefined, false, undefined, this)
|
|
194
|
+
]
|
|
195
|
+
}, undefined, true, undefined, this)
|
|
196
|
+
]
|
|
197
|
+
}, undefined, true, undefined, this)
|
|
198
|
+
]
|
|
199
|
+
}, undefined, true, undefined, this);
|
|
200
|
+
}
|
|
201
|
+
export {
|
|
202
|
+
ArchitectureControlPlanePage
|
|
203
|
+
};
|