@contractspec/bundle.library 3.8.2 → 3.8.5
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 +130 -116
- package/CHANGELOG.md +80 -0
- package/dist/application/index.js +806 -131
- package/dist/application/mcp/cliMcp.js +21 -2
- package/dist/application/mcp/common.js +21 -2
- package/dist/application/mcp/common.test.d.ts +1 -0
- package/dist/application/mcp/contractsMcp.js +21 -2
- package/dist/application/mcp/docsMcp.catalog.d.ts +2 -0
- package/dist/application/mcp/docsMcp.catalog.js +382 -0
- package/dist/application/mcp/docsMcp.d.ts +5 -1
- package/dist/application/mcp/docsMcp.data.d.ts +85 -0
- package/dist/application/mcp/docsMcp.data.js +148 -0
- package/dist/application/mcp/docsMcp.js +776 -101
- package/dist/application/mcp/docsMcp.prompts.d.ts +3 -0
- package/dist/application/mcp/docsMcp.prompts.js +522 -0
- package/dist/application/mcp/docsMcp.reference.d.ts +24 -0
- package/dist/application/mcp/docsMcp.reference.js +236 -0
- package/dist/application/mcp/docsMcp.resources.d.ts +3 -0
- package/dist/application/mcp/docsMcp.resources.js +520 -0
- package/dist/application/mcp/docsMcp.test.d.ts +1 -0
- package/dist/application/mcp/docsMcp.tools.d.ts +3 -0
- package/dist/application/mcp/docsMcp.tools.js +519 -0
- package/dist/application/mcp/index.js +806 -131
- package/dist/application/mcp/internalMcp.js +21 -2
- package/dist/application/mcp/normalizeMcpRequest.d.ts +1 -0
- package/dist/application/mcp/normalizeMcpRequest.js +22 -0
- package/dist/application/mcp/providerRankingMcp.js +21 -2
- package/dist/components/docs/generated/docs-index.generated.d.ts +6 -6
- package/dist/components/docs/index.js +23 -24
- package/dist/components/docs/libraries/LibrariesAiAgentPage.js +22 -22
- package/dist/components/docs/libraries/LibrariesSupportBotPage.js +1 -2
- package/dist/components/docs/libraries/index.js +23 -24
- package/dist/components/templates/engine/index.d.ts +1 -1
- package/dist/components/templates/engine/index.js +1 -1
- package/dist/features/index.js +15 -15
- package/dist/index.js +194 -195
- package/dist/node/application/index.js +806 -131
- package/dist/node/application/mcp/cliMcp.js +21 -2
- package/dist/node/application/mcp/common.js +21 -2
- package/dist/node/application/mcp/contractsMcp.js +21 -2
- package/dist/node/application/mcp/docsMcp.catalog.js +381 -0
- package/dist/node/application/mcp/docsMcp.data.js +147 -0
- package/dist/node/application/mcp/docsMcp.js +776 -101
- package/dist/node/application/mcp/docsMcp.prompts.js +521 -0
- package/dist/node/application/mcp/docsMcp.reference.js +235 -0
- package/dist/node/application/mcp/docsMcp.resources.js +519 -0
- package/dist/node/application/mcp/docsMcp.tools.js +518 -0
- package/dist/node/application/mcp/index.js +806 -131
- package/dist/node/application/mcp/internalMcp.js +21 -2
- package/dist/node/application/mcp/normalizeMcpRequest.js +21 -0
- package/dist/node/application/mcp/providerRankingMcp.js +21 -2
- package/dist/node/components/docs/index.js +23 -24
- package/dist/node/components/docs/libraries/LibrariesAiAgentPage.js +22 -22
- package/dist/node/components/docs/libraries/LibrariesSupportBotPage.js +1 -2
- package/dist/node/components/docs/libraries/index.js +23 -24
- package/dist/node/components/templates/engine/index.js +1 -1
- package/dist/node/features/index.js +15 -15
- package/dist/node/index.js +194 -195
- package/dist/node/presentation/features/hooks/index.js +12 -12
- package/dist/node/presentation/features/hooks/useContractsRegistry.js +12 -12
- package/dist/node/presentation/features/index.js +12 -12
- package/dist/node/presentation/features/organisms/FeatureDataViewsList.js +12 -12
- package/dist/node/presentation/features/organisms/FeatureEventsList.js +12 -12
- package/dist/node/presentation/features/organisms/FeatureFormsList.js +12 -12
- package/dist/node/presentation/features/organisms/FeaturePresentationsList.js +12 -12
- package/dist/node/presentation/features/organisms/index.js +12 -12
- package/dist/node/presentation/features/templates/FeatureDataViewsTemplate/FeatureDataViewsTemplate.js +12 -12
- package/dist/node/presentation/features/templates/FeatureDataViewsTemplate/index.js +12 -12
- package/dist/node/presentation/features/templates/FeatureEventsTemplate/FeatureEventsTemplate.js +12 -12
- package/dist/node/presentation/features/templates/FeatureEventsTemplate/index.js +12 -12
- package/dist/node/presentation/features/templates/FeatureFormsTemplate/FeatureFormsTemplate.js +12 -12
- package/dist/node/presentation/features/templates/FeatureFormsTemplate/index.js +12 -12
- package/dist/node/presentation/features/templates/FeaturePresentationsTemplate/FeaturePresentationsTemplate.js +12 -12
- package/dist/node/presentation/features/templates/FeaturePresentationsTemplate/index.js +12 -12
- package/dist/presentation/features/hooks/index.js +12 -12
- package/dist/presentation/features/hooks/useContractsRegistry.js +12 -12
- package/dist/presentation/features/index.js +12 -12
- package/dist/presentation/features/organisms/FeatureDataViewsList.js +12 -12
- package/dist/presentation/features/organisms/FeatureEventsList.js +12 -12
- package/dist/presentation/features/organisms/FeatureFormsList.js +12 -12
- package/dist/presentation/features/organisms/FeaturePresentationsList.js +12 -12
- package/dist/presentation/features/organisms/index.js +12 -12
- package/dist/presentation/features/templates/FeatureDataViewsTemplate/FeatureDataViewsTemplate.js +12 -12
- package/dist/presentation/features/templates/FeatureDataViewsTemplate/index.js +12 -12
- package/dist/presentation/features/templates/FeatureEventsTemplate/FeatureEventsTemplate.js +12 -12
- package/dist/presentation/features/templates/FeatureEventsTemplate/index.js +12 -12
- package/dist/presentation/features/templates/FeatureFormsTemplate/FeatureFormsTemplate.js +12 -12
- package/dist/presentation/features/templates/FeatureFormsTemplate/index.js +12 -12
- package/dist/presentation/features/templates/FeaturePresentationsTemplate/FeaturePresentationsTemplate.js +12 -12
- package/dist/presentation/features/templates/FeaturePresentationsTemplate/index.js +12 -12
- package/package.json +108 -23
- package/src/application/mcp/common.test.ts +64 -0
- package/src/application/mcp/common.ts +5 -2
- package/src/application/mcp/docsMcp.catalog.ts +2 -0
- package/src/application/mcp/docsMcp.data.ts +196 -0
- package/src/application/mcp/docsMcp.prompts.ts +165 -0
- package/src/application/mcp/docsMcp.reference.ts +152 -0
- package/src/application/mcp/docsMcp.resources.ts +194 -0
- package/src/application/mcp/docsMcp.test.ts +148 -0
- package/src/application/mcp/docsMcp.tools.ts +183 -0
- package/src/application/mcp/docsMcp.ts +13 -177
- package/src/application/mcp/normalizeMcpRequest.ts +30 -0
- package/src/components/docs/generated/docs-index._common.json +1 -1
- package/src/components/docs/generated/docs-index.ai-chat-assistant.json +8 -0
- package/src/components/docs/generated/docs-index.artisan-knowledge-product.json +18 -0
- package/src/components/docs/generated/docs-index.artisan-payments-stripe.json +34 -0
- package/src/components/docs/generated/docs-index.data-grid-showcase.json +18 -0
- package/src/components/docs/generated/docs-index.generated.ts +6 -6
- package/src/components/docs/generated/docs-index.harness-lab.json +10 -0
- package/src/components/docs/generated/docs-index.locale-jurisdiction-gate.json +8 -0
- package/src/components/docs/generated/docs-index.manifest.json +50 -5
- package/src/components/docs/generated/docs-index.messaging-agent-actions.json +18 -0
- package/src/components/docs/generated/docs-index.mobile-demo-tasks.json +34 -0
- package/src/components/docs/generated/docs-index.opencode-cli.json +2 -2
- package/src/components/docs/generated/docs-index.platform-control-plane.json +250 -0
- package/src/components/docs/generated/docs-index.platform-harness.json +178 -0
- package/src/components/docs/generated/docs-index.platform-integrations.json +22 -14
- package/src/components/docs/generated/docs-index.visualization-showcase.json +18 -0
- package/src/components/docs/libraries/LibrariesAiAgentPage.tsx +20 -17
- package/src/components/docs/libraries/LibrariesSupportBotPage.tsx +1 -2
- package/src/components/templates/engine/index.ts +2 -2
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
// src/application/mcp/docsMcp.data.ts
|
|
2
|
+
import { defaultDocRegistry } from "@contractspec/lib.contracts-spec/docs";
|
|
3
|
+
var DEFAULT_LIMIT = 20;
|
|
4
|
+
var MAX_LIMIT = 100;
|
|
5
|
+
function normalizeText(value) {
|
|
6
|
+
return value?.trim().toLowerCase() ?? "";
|
|
7
|
+
}
|
|
8
|
+
function normalizeRoute(route) {
|
|
9
|
+
const decoded = decodeURIComponent(route).trim();
|
|
10
|
+
if (!decoded)
|
|
11
|
+
return "/";
|
|
12
|
+
return decoded.startsWith("/") ? decoded : `/${decoded}`;
|
|
13
|
+
}
|
|
14
|
+
function normalizeTags(value) {
|
|
15
|
+
const tags = Array.isArray(value) ? value : value ? [value] : [];
|
|
16
|
+
return tags.map((tag) => normalizeText(tag)).filter(Boolean);
|
|
17
|
+
}
|
|
18
|
+
function clampLimit(limit) {
|
|
19
|
+
if (!limit || Number.isNaN(limit))
|
|
20
|
+
return DEFAULT_LIMIT;
|
|
21
|
+
return Math.min(Math.max(limit, 1), MAX_LIMIT);
|
|
22
|
+
}
|
|
23
|
+
function clampOffset(offset) {
|
|
24
|
+
if (!offset || Number.isNaN(offset))
|
|
25
|
+
return 0;
|
|
26
|
+
return Math.max(offset, 0);
|
|
27
|
+
}
|
|
28
|
+
function toDocSummary({ block, route }) {
|
|
29
|
+
return {
|
|
30
|
+
id: block.id,
|
|
31
|
+
title: block.title,
|
|
32
|
+
summary: block.summary ?? "",
|
|
33
|
+
route,
|
|
34
|
+
visibility: block.visibility ?? "public",
|
|
35
|
+
kind: block.kind ?? "reference",
|
|
36
|
+
version: block.version ?? "1.0.0",
|
|
37
|
+
tags: block.tags ?? []
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function scoreDoc(route, query) {
|
|
41
|
+
if (!query)
|
|
42
|
+
return 1;
|
|
43
|
+
const tokens = query.split(/\s+/).filter(Boolean);
|
|
44
|
+
const title = normalizeText(route.block.title);
|
|
45
|
+
const id = normalizeText(route.block.id);
|
|
46
|
+
const summary = normalizeText(route.block.summary);
|
|
47
|
+
const body = normalizeText(route.block.body);
|
|
48
|
+
const path = normalizeText(route.route);
|
|
49
|
+
const tags = (route.block.tags ?? []).map((tag) => normalizeText(tag));
|
|
50
|
+
const haystack = [title, id, summary, body, path, ...tags].join(" ");
|
|
51
|
+
if (tokens.some((token) => !haystack.includes(token)))
|
|
52
|
+
return 0;
|
|
53
|
+
let score = 0;
|
|
54
|
+
for (const token of tokens) {
|
|
55
|
+
if (id.includes(token))
|
|
56
|
+
score += 8;
|
|
57
|
+
if (title.includes(token))
|
|
58
|
+
score += 7;
|
|
59
|
+
if (tags.some((tag) => tag.includes(token)))
|
|
60
|
+
score += 5;
|
|
61
|
+
if (summary.includes(token))
|
|
62
|
+
score += 4;
|
|
63
|
+
if (path.includes(token))
|
|
64
|
+
score += 3;
|
|
65
|
+
if (body.includes(token))
|
|
66
|
+
score += 2;
|
|
67
|
+
}
|
|
68
|
+
return score;
|
|
69
|
+
}
|
|
70
|
+
function searchDocs(routes, args) {
|
|
71
|
+
const query = normalizeText(typeof args.query === "string" ? args.query : undefined);
|
|
72
|
+
const tags = normalizeTags(args.tag);
|
|
73
|
+
const visibility = normalizeText(typeof args.visibility === "string" ? args.visibility : undefined);
|
|
74
|
+
const kind = normalizeText(typeof args.kind === "string" ? args.kind : undefined);
|
|
75
|
+
const limit = clampLimit(typeof args.limit === "number" ? args.limit : undefined);
|
|
76
|
+
const offset = clampOffset(typeof args.offset === "number" ? args.offset : undefined);
|
|
77
|
+
const ranked = routes.map((route) => ({
|
|
78
|
+
doc: toDocSummary(route),
|
|
79
|
+
score: scoreDoc(route, query)
|
|
80
|
+
})).filter(({ doc, score }) => {
|
|
81
|
+
const matchesQuery = query ? score > 0 : true;
|
|
82
|
+
const matchesTags = tags.length ? tags.every((tag) => doc.tags.some((docTag) => normalizeText(docTag).includes(tag))) : true;
|
|
83
|
+
const matchesVisibility = visibility ? normalizeText(doc.visibility) === visibility : true;
|
|
84
|
+
const matchesKind = kind ? normalizeText(doc.kind) === kind : true;
|
|
85
|
+
return matchesQuery && matchesTags && matchesVisibility && matchesKind;
|
|
86
|
+
}).sort((left, right) => {
|
|
87
|
+
if (right.score !== left.score)
|
|
88
|
+
return right.score - left.score;
|
|
89
|
+
return left.doc.title.localeCompare(right.doc.title);
|
|
90
|
+
});
|
|
91
|
+
const docs = ranked.slice(offset, offset + limit).map(({ doc }) => doc);
|
|
92
|
+
const nextOffset = offset + docs.length < ranked.length ? offset + docs.length : undefined;
|
|
93
|
+
return {
|
|
94
|
+
docs,
|
|
95
|
+
items: docs,
|
|
96
|
+
total: ranked.length,
|
|
97
|
+
...nextOffset != null ? { nextOffset } : {}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function getDocById(id) {
|
|
101
|
+
const normalizedId = decodeURIComponent(id);
|
|
102
|
+
const found = defaultDocRegistry.get(normalizedId);
|
|
103
|
+
if (!found)
|
|
104
|
+
return;
|
|
105
|
+
return {
|
|
106
|
+
doc: toDocSummary(found),
|
|
107
|
+
content: String(found.block.body ?? "")
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function getDocByRoute(routes, routePath) {
|
|
111
|
+
const normalizedPath = normalizeRoute(routePath);
|
|
112
|
+
const found = routes.find((route) => normalizeRoute(route.route) === normalizedPath);
|
|
113
|
+
if (!found)
|
|
114
|
+
return;
|
|
115
|
+
return {
|
|
116
|
+
doc: toDocSummary(found),
|
|
117
|
+
content: String(found.block.body ?? "")
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function listDocFacets(routes) {
|
|
121
|
+
const tags = new Map;
|
|
122
|
+
const kinds = new Map;
|
|
123
|
+
const visibilities = new Map;
|
|
124
|
+
for (const route of routes) {
|
|
125
|
+
const kind = route.block.kind ?? "reference";
|
|
126
|
+
const visibility = route.block.visibility ?? "public";
|
|
127
|
+
kinds.set(kind, (kinds.get(kind) ?? 0) + 1);
|
|
128
|
+
visibilities.set(visibility, (visibilities.get(visibility) ?? 0) + 1);
|
|
129
|
+
for (const tag of route.block.tags ?? []) {
|
|
130
|
+
tags.set(tag, (tags.get(tag) ?? 0) + 1);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const toEntries = (values, key) => [...values.entries()].sort((left, right) => right[1] - left[1] || left[0].localeCompare(right[0])).map(([value, count]) => ({ [key]: value, count }));
|
|
134
|
+
return {
|
|
135
|
+
totalDocs: routes.length,
|
|
136
|
+
tags: toEntries(tags, "tag"),
|
|
137
|
+
kinds: toEntries(kinds, "kind"),
|
|
138
|
+
visibilities: toEntries(visibilities, "visibility")
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/features/contracts-registry.ts
|
|
143
|
+
import {
|
|
144
|
+
EventRegistry,
|
|
145
|
+
OperationSpecRegistry
|
|
146
|
+
} from "@contractspec/lib.contracts-spec";
|
|
147
|
+
import {
|
|
148
|
+
DataViewRegistry
|
|
149
|
+
} from "@contractspec/lib.contracts-spec/data-views";
|
|
150
|
+
import {
|
|
151
|
+
ContractReferenceDataView,
|
|
152
|
+
ContractReferenceQuery,
|
|
153
|
+
DocsGenerateCommand,
|
|
154
|
+
DocsGeneratedEvent,
|
|
155
|
+
DocsIndexDataView,
|
|
156
|
+
DocsIndexQuery,
|
|
157
|
+
DocsLayoutPresentation,
|
|
158
|
+
DocsPublishCommand,
|
|
159
|
+
DocsPublishedEvent,
|
|
160
|
+
DocsReferencePagePresentation,
|
|
161
|
+
DocsSearchForm,
|
|
162
|
+
ExampleCatalogDataView
|
|
163
|
+
} from "@contractspec/lib.contracts-spec/docs";
|
|
164
|
+
import { FormRegistry } from "@contractspec/lib.contracts-spec/forms";
|
|
165
|
+
import {
|
|
166
|
+
PresentationRegistry
|
|
167
|
+
} from "@contractspec/lib.contracts-spec/presentations";
|
|
168
|
+
import {
|
|
169
|
+
serializeDataViewSpec,
|
|
170
|
+
serializeEventSpec,
|
|
171
|
+
serializeFormSpec,
|
|
172
|
+
serializeOperationSpec,
|
|
173
|
+
serializePresentationSpec
|
|
174
|
+
} from "@contractspec/lib.contracts-spec/serialization";
|
|
175
|
+
var operationRegistry = null;
|
|
176
|
+
function createContractSpecOperationRegistry() {
|
|
177
|
+
const registry = new OperationSpecRegistry;
|
|
178
|
+
registry.register(DocsIndexQuery).register(ContractReferenceQuery).register(DocsGenerateCommand).register(DocsPublishCommand);
|
|
179
|
+
return registry;
|
|
180
|
+
}
|
|
181
|
+
function getContractSpecOperationRegistry() {
|
|
182
|
+
if (!operationRegistry) {
|
|
183
|
+
operationRegistry = createContractSpecOperationRegistry();
|
|
184
|
+
}
|
|
185
|
+
return operationRegistry;
|
|
186
|
+
}
|
|
187
|
+
function resolveOperationSpec(key, version) {
|
|
188
|
+
return getContractSpecOperationRegistry().get(key, version);
|
|
189
|
+
}
|
|
190
|
+
var eventRegistry = null;
|
|
191
|
+
function createContractSpecEventRegistry() {
|
|
192
|
+
const registry = new EventRegistry;
|
|
193
|
+
registry.register(DocsGeneratedEvent).register(DocsPublishedEvent);
|
|
194
|
+
return registry;
|
|
195
|
+
}
|
|
196
|
+
function getContractSpecEventRegistry() {
|
|
197
|
+
if (!eventRegistry) {
|
|
198
|
+
eventRegistry = createContractSpecEventRegistry();
|
|
199
|
+
}
|
|
200
|
+
return eventRegistry;
|
|
201
|
+
}
|
|
202
|
+
function resolveEventSpec(key, version) {
|
|
203
|
+
return getContractSpecEventRegistry().get(key, version);
|
|
204
|
+
}
|
|
205
|
+
var presentationRegistry = null;
|
|
206
|
+
function createContractSpecPresentationRegistry() {
|
|
207
|
+
const registry = new PresentationRegistry;
|
|
208
|
+
registry.register(DocsLayoutPresentation).register(DocsReferencePagePresentation);
|
|
209
|
+
return registry;
|
|
210
|
+
}
|
|
211
|
+
function getContractSpecPresentationRegistry() {
|
|
212
|
+
if (!presentationRegistry) {
|
|
213
|
+
presentationRegistry = createContractSpecPresentationRegistry();
|
|
214
|
+
}
|
|
215
|
+
return presentationRegistry;
|
|
216
|
+
}
|
|
217
|
+
function resolvePresentationSpec(key, version) {
|
|
218
|
+
return getContractSpecPresentationRegistry().get(key, version);
|
|
219
|
+
}
|
|
220
|
+
var dataViewRegistry = null;
|
|
221
|
+
function createContractSpecDataViewRegistry() {
|
|
222
|
+
const registry = new DataViewRegistry;
|
|
223
|
+
registry.register(DocsIndexDataView).register(ContractReferenceDataView).register(ExampleCatalogDataView);
|
|
224
|
+
return registry;
|
|
225
|
+
}
|
|
226
|
+
function getContractSpecDataViewRegistry() {
|
|
227
|
+
if (!dataViewRegistry) {
|
|
228
|
+
dataViewRegistry = createContractSpecDataViewRegistry();
|
|
229
|
+
}
|
|
230
|
+
return dataViewRegistry;
|
|
231
|
+
}
|
|
232
|
+
function resolveDataViewSpec(key, version) {
|
|
233
|
+
return getContractSpecDataViewRegistry().get(key, version);
|
|
234
|
+
}
|
|
235
|
+
var formRegistry = null;
|
|
236
|
+
function createContractSpecFormRegistry() {
|
|
237
|
+
const registry = new FormRegistry;
|
|
238
|
+
registry.register(DocsSearchForm);
|
|
239
|
+
return registry;
|
|
240
|
+
}
|
|
241
|
+
function getContractSpecFormRegistry() {
|
|
242
|
+
if (!formRegistry) {
|
|
243
|
+
formRegistry = createContractSpecFormRegistry();
|
|
244
|
+
}
|
|
245
|
+
return formRegistry;
|
|
246
|
+
}
|
|
247
|
+
function resolveFormSpec(key, _version) {
|
|
248
|
+
return getContractSpecFormRegistry().get(key);
|
|
249
|
+
}
|
|
250
|
+
function resolveSerializedOperationSpec(key, version) {
|
|
251
|
+
const spec = resolveOperationSpec(key, version);
|
|
252
|
+
return serializeOperationSpec(spec) ?? undefined;
|
|
253
|
+
}
|
|
254
|
+
function resolveSerializedEventSpec(key, version) {
|
|
255
|
+
const spec = resolveEventSpec(key, version);
|
|
256
|
+
return serializeEventSpec(spec) ?? undefined;
|
|
257
|
+
}
|
|
258
|
+
function resolveSerializedPresentationSpec(key, version) {
|
|
259
|
+
const spec = resolvePresentationSpec(key, version);
|
|
260
|
+
return serializePresentationSpec(spec) ?? undefined;
|
|
261
|
+
}
|
|
262
|
+
function resolveSerializedDataViewSpec(key, version) {
|
|
263
|
+
const spec = resolveDataViewSpec(key, version);
|
|
264
|
+
return serializeDataViewSpec(spec) ?? undefined;
|
|
265
|
+
}
|
|
266
|
+
function resolveSerializedFormSpec(key, version) {
|
|
267
|
+
const spec = resolveFormSpec(key, version);
|
|
268
|
+
return serializeFormSpec(spec) ?? undefined;
|
|
269
|
+
}
|
|
270
|
+
function resetContractSpecOperationRegistry() {
|
|
271
|
+
operationRegistry = null;
|
|
272
|
+
}
|
|
273
|
+
function resetContractSpecEventRegistry() {
|
|
274
|
+
eventRegistry = null;
|
|
275
|
+
}
|
|
276
|
+
function resetContractSpecPresentationRegistry() {
|
|
277
|
+
presentationRegistry = null;
|
|
278
|
+
}
|
|
279
|
+
function resetContractSpecDataViewRegistry() {
|
|
280
|
+
dataViewRegistry = null;
|
|
281
|
+
}
|
|
282
|
+
function resetContractSpecFormRegistry() {
|
|
283
|
+
formRegistry = null;
|
|
284
|
+
}
|
|
285
|
+
function resetAllContractSpecRegistries() {
|
|
286
|
+
resetContractSpecOperationRegistry();
|
|
287
|
+
resetContractSpecEventRegistry();
|
|
288
|
+
resetContractSpecPresentationRegistry();
|
|
289
|
+
resetContractSpecDataViewRegistry();
|
|
290
|
+
resetContractSpecFormRegistry();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/application/mcp/docsMcp.reference.ts
|
|
294
|
+
import { defaultDocRegistry as defaultDocRegistry2 } from "@contractspec/lib.contracts-spec/docs";
|
|
295
|
+
function normalizeText2(value) {
|
|
296
|
+
return value?.trim().toLowerCase() ?? "";
|
|
297
|
+
}
|
|
298
|
+
function routeFromDocIds(docIds) {
|
|
299
|
+
for (const docId of docIds ?? []) {
|
|
300
|
+
const doc = defaultDocRegistry2.get(docId);
|
|
301
|
+
if (doc)
|
|
302
|
+
return doc.route;
|
|
303
|
+
}
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
function toReference(spec, type, schema, policy) {
|
|
307
|
+
const title = spec.meta.title ?? spec.meta.key;
|
|
308
|
+
const route = routeFromDocIds(spec.meta.docId);
|
|
309
|
+
const description = spec.meta.description;
|
|
310
|
+
return {
|
|
311
|
+
key: spec.meta.key,
|
|
312
|
+
version: spec.meta.version,
|
|
313
|
+
type,
|
|
314
|
+
title,
|
|
315
|
+
description,
|
|
316
|
+
markdown: [
|
|
317
|
+
`# ${title}`,
|
|
318
|
+
`- Key: ${spec.meta.key}`,
|
|
319
|
+
`- Type: ${type}`,
|
|
320
|
+
`- Version: ${spec.meta.version}`,
|
|
321
|
+
route ? `- Docs route: ${route}` : "",
|
|
322
|
+
description ? `
|
|
323
|
+
${description}` : ""
|
|
324
|
+
].filter(Boolean).join(`
|
|
325
|
+
`),
|
|
326
|
+
...route ? { route } : {},
|
|
327
|
+
...schema ? { schema } : {},
|
|
328
|
+
...policy ? { policy } : {},
|
|
329
|
+
tags: spec.meta.tags ?? [],
|
|
330
|
+
owners: spec.meta.owners ?? [],
|
|
331
|
+
stability: spec.meta.stability
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function resolveContractReference(args) {
|
|
335
|
+
const includeSchema = args.includeSchema ?? false;
|
|
336
|
+
const requestedType = normalizeText2(args.type);
|
|
337
|
+
const operation = resolveOperationSpec(args.key, args.version);
|
|
338
|
+
if (operation && (!requestedType || requestedType === "operation" || requestedType === operation.meta.kind)) {
|
|
339
|
+
return {
|
|
340
|
+
reference: toReference(operation, operation.meta.kind, includeSchema ? resolveSerializedOperationSpec(args.key, args.version) : undefined, operation.policy)
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
const resolvers = [
|
|
344
|
+
{
|
|
345
|
+
type: "data-view",
|
|
346
|
+
spec: resolveDataViewSpec(args.key, args.version),
|
|
347
|
+
schema: includeSchema ? resolveSerializedDataViewSpec(args.key, args.version) : undefined
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
type: "form",
|
|
351
|
+
spec: resolveFormSpec(args.key, args.version),
|
|
352
|
+
schema: includeSchema ? resolveSerializedFormSpec(args.key, args.version) : undefined
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
type: "presentation",
|
|
356
|
+
spec: resolvePresentationSpec(args.key, args.version),
|
|
357
|
+
schema: includeSchema ? resolveSerializedPresentationSpec(args.key, args.version) : undefined
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
type: "event",
|
|
361
|
+
spec: resolveEventSpec(args.key, args.version),
|
|
362
|
+
schema: includeSchema ? resolveSerializedEventSpec(args.key, args.version) : undefined
|
|
363
|
+
}
|
|
364
|
+
];
|
|
365
|
+
for (const candidate of resolvers) {
|
|
366
|
+
if (candidate.spec && (!requestedType || requestedType === candidate.type)) {
|
|
367
|
+
return {
|
|
368
|
+
reference: toReference(candidate.spec, candidate.type, candidate.schema)
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
throw new Error(`Contract reference not found: ${args.key}`);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/application/mcp/docsMcp.prompts.ts
|
|
376
|
+
import { definePrompt, PromptRegistry } from "@contractspec/lib.contracts-spec";
|
|
377
|
+
import z from "zod";
|
|
378
|
+
var DOC_OWNERS = ["@contractspec"];
|
|
379
|
+
var DOC_TAGS = ["docs", "mcp"];
|
|
380
|
+
function buildDocPrompts(routes) {
|
|
381
|
+
const prompts = new PromptRegistry;
|
|
382
|
+
prompts.register(definePrompt({
|
|
383
|
+
meta: {
|
|
384
|
+
key: "docs.navigator",
|
|
385
|
+
version: "1.0.0",
|
|
386
|
+
title: "Find relevant ContractSpec docs",
|
|
387
|
+
description: "Guide agents to search, filter, and open the right ContractSpec docs.",
|
|
388
|
+
tags: DOC_TAGS,
|
|
389
|
+
stability: "beta",
|
|
390
|
+
owners: DOC_OWNERS
|
|
391
|
+
},
|
|
392
|
+
args: [
|
|
393
|
+
{
|
|
394
|
+
name: "topic",
|
|
395
|
+
description: "Goal or subject to search for.",
|
|
396
|
+
required: false,
|
|
397
|
+
schema: z.string().optional()
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
name: "kind",
|
|
401
|
+
description: "Optional doc kind filter.",
|
|
402
|
+
required: false,
|
|
403
|
+
schema: z.string().optional()
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
name: "tag",
|
|
407
|
+
description: "Optional tag filter.",
|
|
408
|
+
required: false,
|
|
409
|
+
schema: z.string().optional()
|
|
410
|
+
}
|
|
411
|
+
],
|
|
412
|
+
input: z.object({
|
|
413
|
+
topic: z.string().optional(),
|
|
414
|
+
kind: z.string().optional(),
|
|
415
|
+
tag: z.string().optional()
|
|
416
|
+
}),
|
|
417
|
+
render: async ({ topic, kind, tag }) => {
|
|
418
|
+
const matches = searchDocs(routes, {
|
|
419
|
+
query: topic,
|
|
420
|
+
kind,
|
|
421
|
+
tag,
|
|
422
|
+
limit: 3
|
|
423
|
+
});
|
|
424
|
+
const suggestedDocs = matches.docs.length ? matches.docs.map((doc) => `- ${doc.title} (${doc.id}) -> ${doc.route}`).join(`
|
|
425
|
+
`) : "- No direct pre-match. Use docs_list_facets-v1_0_0 to browse tags and kinds.";
|
|
426
|
+
return [
|
|
427
|
+
{
|
|
428
|
+
type: "text",
|
|
429
|
+
text: [
|
|
430
|
+
"Use docs_search-v1_0_0 first, then read docs://doc/{id} for the strongest matches.",
|
|
431
|
+
"Use docs_resolve_route-v1_0_0 when the user already gives you a docs URL or route.",
|
|
432
|
+
"Use docs_list_facets-v1_0_0 or docs://facets to browse the docs taxonomy before guessing.",
|
|
433
|
+
topic ? `Topic: ${topic}` : "",
|
|
434
|
+
kind ? `Kind: ${kind}` : "",
|
|
435
|
+
tag ? `Tag: ${tag}` : "",
|
|
436
|
+
"Suggested starting docs:",
|
|
437
|
+
suggestedDocs
|
|
438
|
+
].filter(Boolean).join(`
|
|
439
|
+
`)
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
type: "resource",
|
|
443
|
+
uri: "docs://index",
|
|
444
|
+
title: "DocBlocks index"
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
type: "resource",
|
|
448
|
+
uri: "docs://facets",
|
|
449
|
+
title: "Docs facets"
|
|
450
|
+
}
|
|
451
|
+
];
|
|
452
|
+
}
|
|
453
|
+
}));
|
|
454
|
+
prompts.register(definePrompt({
|
|
455
|
+
meta: {
|
|
456
|
+
key: "docs.reference.guide",
|
|
457
|
+
version: "1.0.0",
|
|
458
|
+
title: "Resolve a ContractSpec reference",
|
|
459
|
+
description: "Guide agents to fetch the canonical reference payload for a ContractSpec surface.",
|
|
460
|
+
tags: DOC_TAGS,
|
|
461
|
+
stability: "beta",
|
|
462
|
+
owners: DOC_OWNERS
|
|
463
|
+
},
|
|
464
|
+
args: [
|
|
465
|
+
{
|
|
466
|
+
name: "key",
|
|
467
|
+
description: "ContractSpec key to resolve.",
|
|
468
|
+
required: true,
|
|
469
|
+
schema: z.string()
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
name: "version",
|
|
473
|
+
description: "Optional version override.",
|
|
474
|
+
required: false,
|
|
475
|
+
schema: z.string().optional()
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
name: "type",
|
|
479
|
+
description: "Optional surface type: command, query, form, data-view, presentation, event.",
|
|
480
|
+
required: false,
|
|
481
|
+
schema: z.string().optional()
|
|
482
|
+
}
|
|
483
|
+
],
|
|
484
|
+
input: z.object({
|
|
485
|
+
key: z.string(),
|
|
486
|
+
version: z.string().optional(),
|
|
487
|
+
type: z.string().optional()
|
|
488
|
+
}),
|
|
489
|
+
render: async ({ key, version, type }) => {
|
|
490
|
+
const reference = resolveContractReference({
|
|
491
|
+
key,
|
|
492
|
+
version,
|
|
493
|
+
type,
|
|
494
|
+
includeSchema: true
|
|
495
|
+
}).reference;
|
|
496
|
+
return [
|
|
497
|
+
{
|
|
498
|
+
type: "text",
|
|
499
|
+
text: [
|
|
500
|
+
"Use docs_contract_reference-v1_0_0 when you need the canonical docs payload for a ContractSpec surface.",
|
|
501
|
+
"Use docs_get-v1_0_0 only when you already know the exact DocBlock id and need raw markdown.",
|
|
502
|
+
`Resolved key: ${reference.key}`,
|
|
503
|
+
`Resolved type: ${reference.type}`,
|
|
504
|
+
reference.route ? `Docs route: ${reference.route}` : "",
|
|
505
|
+
`Resource URI: docs://contract-reference/${encodeURIComponent(key)}`
|
|
506
|
+
].filter(Boolean).join(`
|
|
507
|
+
`)
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
type: "resource",
|
|
511
|
+
uri: `docs://contract-reference/${encodeURIComponent(key)}`,
|
|
512
|
+
title: "Contract reference"
|
|
513
|
+
}
|
|
514
|
+
];
|
|
515
|
+
}
|
|
516
|
+
}));
|
|
517
|
+
return prompts;
|
|
518
|
+
}
|
|
519
|
+
export {
|
|
520
|
+
buildDocPrompts
|
|
521
|
+
};
|