@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.
Files changed (121) hide show
  1. package/.turbo/turbo-build.log +130 -116
  2. package/CHANGELOG.md +80 -0
  3. package/dist/application/index.js +806 -131
  4. package/dist/application/mcp/cliMcp.js +21 -2
  5. package/dist/application/mcp/common.js +21 -2
  6. package/dist/application/mcp/common.test.d.ts +1 -0
  7. package/dist/application/mcp/contractsMcp.js +21 -2
  8. package/dist/application/mcp/docsMcp.catalog.d.ts +2 -0
  9. package/dist/application/mcp/docsMcp.catalog.js +382 -0
  10. package/dist/application/mcp/docsMcp.d.ts +5 -1
  11. package/dist/application/mcp/docsMcp.data.d.ts +85 -0
  12. package/dist/application/mcp/docsMcp.data.js +148 -0
  13. package/dist/application/mcp/docsMcp.js +776 -101
  14. package/dist/application/mcp/docsMcp.prompts.d.ts +3 -0
  15. package/dist/application/mcp/docsMcp.prompts.js +522 -0
  16. package/dist/application/mcp/docsMcp.reference.d.ts +24 -0
  17. package/dist/application/mcp/docsMcp.reference.js +236 -0
  18. package/dist/application/mcp/docsMcp.resources.d.ts +3 -0
  19. package/dist/application/mcp/docsMcp.resources.js +520 -0
  20. package/dist/application/mcp/docsMcp.test.d.ts +1 -0
  21. package/dist/application/mcp/docsMcp.tools.d.ts +3 -0
  22. package/dist/application/mcp/docsMcp.tools.js +519 -0
  23. package/dist/application/mcp/index.js +806 -131
  24. package/dist/application/mcp/internalMcp.js +21 -2
  25. package/dist/application/mcp/normalizeMcpRequest.d.ts +1 -0
  26. package/dist/application/mcp/normalizeMcpRequest.js +22 -0
  27. package/dist/application/mcp/providerRankingMcp.js +21 -2
  28. package/dist/components/docs/generated/docs-index.generated.d.ts +6 -6
  29. package/dist/components/docs/index.js +23 -24
  30. package/dist/components/docs/libraries/LibrariesAiAgentPage.js +22 -22
  31. package/dist/components/docs/libraries/LibrariesSupportBotPage.js +1 -2
  32. package/dist/components/docs/libraries/index.js +23 -24
  33. package/dist/components/templates/engine/index.d.ts +1 -1
  34. package/dist/components/templates/engine/index.js +1 -1
  35. package/dist/features/index.js +15 -15
  36. package/dist/index.js +194 -195
  37. package/dist/node/application/index.js +806 -131
  38. package/dist/node/application/mcp/cliMcp.js +21 -2
  39. package/dist/node/application/mcp/common.js +21 -2
  40. package/dist/node/application/mcp/contractsMcp.js +21 -2
  41. package/dist/node/application/mcp/docsMcp.catalog.js +381 -0
  42. package/dist/node/application/mcp/docsMcp.data.js +147 -0
  43. package/dist/node/application/mcp/docsMcp.js +776 -101
  44. package/dist/node/application/mcp/docsMcp.prompts.js +521 -0
  45. package/dist/node/application/mcp/docsMcp.reference.js +235 -0
  46. package/dist/node/application/mcp/docsMcp.resources.js +519 -0
  47. package/dist/node/application/mcp/docsMcp.tools.js +518 -0
  48. package/dist/node/application/mcp/index.js +806 -131
  49. package/dist/node/application/mcp/internalMcp.js +21 -2
  50. package/dist/node/application/mcp/normalizeMcpRequest.js +21 -0
  51. package/dist/node/application/mcp/providerRankingMcp.js +21 -2
  52. package/dist/node/components/docs/index.js +23 -24
  53. package/dist/node/components/docs/libraries/LibrariesAiAgentPage.js +22 -22
  54. package/dist/node/components/docs/libraries/LibrariesSupportBotPage.js +1 -2
  55. package/dist/node/components/docs/libraries/index.js +23 -24
  56. package/dist/node/components/templates/engine/index.js +1 -1
  57. package/dist/node/features/index.js +15 -15
  58. package/dist/node/index.js +194 -195
  59. package/dist/node/presentation/features/hooks/index.js +12 -12
  60. package/dist/node/presentation/features/hooks/useContractsRegistry.js +12 -12
  61. package/dist/node/presentation/features/index.js +12 -12
  62. package/dist/node/presentation/features/organisms/FeatureDataViewsList.js +12 -12
  63. package/dist/node/presentation/features/organisms/FeatureEventsList.js +12 -12
  64. package/dist/node/presentation/features/organisms/FeatureFormsList.js +12 -12
  65. package/dist/node/presentation/features/organisms/FeaturePresentationsList.js +12 -12
  66. package/dist/node/presentation/features/organisms/index.js +12 -12
  67. package/dist/node/presentation/features/templates/FeatureDataViewsTemplate/FeatureDataViewsTemplate.js +12 -12
  68. package/dist/node/presentation/features/templates/FeatureDataViewsTemplate/index.js +12 -12
  69. package/dist/node/presentation/features/templates/FeatureEventsTemplate/FeatureEventsTemplate.js +12 -12
  70. package/dist/node/presentation/features/templates/FeatureEventsTemplate/index.js +12 -12
  71. package/dist/node/presentation/features/templates/FeatureFormsTemplate/FeatureFormsTemplate.js +12 -12
  72. package/dist/node/presentation/features/templates/FeatureFormsTemplate/index.js +12 -12
  73. package/dist/node/presentation/features/templates/FeaturePresentationsTemplate/FeaturePresentationsTemplate.js +12 -12
  74. package/dist/node/presentation/features/templates/FeaturePresentationsTemplate/index.js +12 -12
  75. package/dist/presentation/features/hooks/index.js +12 -12
  76. package/dist/presentation/features/hooks/useContractsRegistry.js +12 -12
  77. package/dist/presentation/features/index.js +12 -12
  78. package/dist/presentation/features/organisms/FeatureDataViewsList.js +12 -12
  79. package/dist/presentation/features/organisms/FeatureEventsList.js +12 -12
  80. package/dist/presentation/features/organisms/FeatureFormsList.js +12 -12
  81. package/dist/presentation/features/organisms/FeaturePresentationsList.js +12 -12
  82. package/dist/presentation/features/organisms/index.js +12 -12
  83. package/dist/presentation/features/templates/FeatureDataViewsTemplate/FeatureDataViewsTemplate.js +12 -12
  84. package/dist/presentation/features/templates/FeatureDataViewsTemplate/index.js +12 -12
  85. package/dist/presentation/features/templates/FeatureEventsTemplate/FeatureEventsTemplate.js +12 -12
  86. package/dist/presentation/features/templates/FeatureEventsTemplate/index.js +12 -12
  87. package/dist/presentation/features/templates/FeatureFormsTemplate/FeatureFormsTemplate.js +12 -12
  88. package/dist/presentation/features/templates/FeatureFormsTemplate/index.js +12 -12
  89. package/dist/presentation/features/templates/FeaturePresentationsTemplate/FeaturePresentationsTemplate.js +12 -12
  90. package/dist/presentation/features/templates/FeaturePresentationsTemplate/index.js +12 -12
  91. package/package.json +108 -23
  92. package/src/application/mcp/common.test.ts +64 -0
  93. package/src/application/mcp/common.ts +5 -2
  94. package/src/application/mcp/docsMcp.catalog.ts +2 -0
  95. package/src/application/mcp/docsMcp.data.ts +196 -0
  96. package/src/application/mcp/docsMcp.prompts.ts +165 -0
  97. package/src/application/mcp/docsMcp.reference.ts +152 -0
  98. package/src/application/mcp/docsMcp.resources.ts +194 -0
  99. package/src/application/mcp/docsMcp.test.ts +148 -0
  100. package/src/application/mcp/docsMcp.tools.ts +183 -0
  101. package/src/application/mcp/docsMcp.ts +13 -177
  102. package/src/application/mcp/normalizeMcpRequest.ts +30 -0
  103. package/src/components/docs/generated/docs-index._common.json +1 -1
  104. package/src/components/docs/generated/docs-index.ai-chat-assistant.json +8 -0
  105. package/src/components/docs/generated/docs-index.artisan-knowledge-product.json +18 -0
  106. package/src/components/docs/generated/docs-index.artisan-payments-stripe.json +34 -0
  107. package/src/components/docs/generated/docs-index.data-grid-showcase.json +18 -0
  108. package/src/components/docs/generated/docs-index.generated.ts +6 -6
  109. package/src/components/docs/generated/docs-index.harness-lab.json +10 -0
  110. package/src/components/docs/generated/docs-index.locale-jurisdiction-gate.json +8 -0
  111. package/src/components/docs/generated/docs-index.manifest.json +50 -5
  112. package/src/components/docs/generated/docs-index.messaging-agent-actions.json +18 -0
  113. package/src/components/docs/generated/docs-index.mobile-demo-tasks.json +34 -0
  114. package/src/components/docs/generated/docs-index.opencode-cli.json +2 -2
  115. package/src/components/docs/generated/docs-index.platform-control-plane.json +250 -0
  116. package/src/components/docs/generated/docs-index.platform-harness.json +178 -0
  117. package/src/components/docs/generated/docs-index.platform-integrations.json +22 -14
  118. package/src/components/docs/generated/docs-index.visualization-showcase.json +18 -0
  119. package/src/components/docs/libraries/LibrariesAiAgentPage.tsx +20 -17
  120. package/src/components/docs/libraries/LibrariesSupportBotPage.tsx +1 -2
  121. package/src/components/templates/engine/index.ts +2 -2
@@ -26,6 +26,25 @@ var authLogger = new Logger({
26
26
  enableContext: true,
27
27
  enableColors: false
28
28
  });
29
+ // src/application/mcp/normalizeMcpRequest.ts
30
+ var REQUIRED_ACCEPT_TYPES = ["application/json", "text/event-stream"];
31
+ function canNormalizeAcceptHeader(acceptHeader) {
32
+ return !acceptHeader || acceptHeader.includes("*/*") || acceptHeader.includes("application/*") || REQUIRED_ACCEPT_TYPES.some((value) => acceptHeader.includes(value));
33
+ }
34
+ function normalizeMcpRequest(request) {
35
+ if (request.method !== "POST")
36
+ return request;
37
+ const acceptHeader = request.headers.get("accept");
38
+ if (!canNormalizeAcceptHeader(acceptHeader))
39
+ return request;
40
+ const missingTypes = REQUIRED_ACCEPT_TYPES.filter((value) => !acceptHeader?.includes(value));
41
+ if (missingTypes.length === 0)
42
+ return request;
43
+ const headers = new Headers(request.headers);
44
+ headers.set("accept", [acceptHeader, ...missingTypes].filter(Boolean).join(", "));
45
+ return new Request(request, { headers });
46
+ }
47
+
29
48
  // src/application/mcp/common.ts
30
49
  import { randomUUID } from "crypto";
31
50
  import { createMcpServer } from "@contractspec/lib.contracts-runtime-server-mcp/provider-mcp";
@@ -121,7 +140,7 @@ function createMcpElysiaHandler({
121
140
  stateful: false
122
141
  });
123
142
  try {
124
- return await state.transport.handleRequest(request);
143
+ return await state.transport.handleRequest(normalizeMcpRequest(request));
125
144
  } finally {
126
145
  await closeSessionState(state);
127
146
  }
@@ -157,7 +176,7 @@ function createMcpElysiaHandler({
157
176
  createdState = true;
158
177
  }
159
178
  try {
160
- const response = await state.transport.handleRequest(request);
179
+ const response = await state.transport.handleRequest(normalizeMcpRequest(request));
161
180
  const activeSessionId = state.transport.sessionId;
162
181
  if (activeSessionId && !sessions.has(activeSessionId)) {
163
182
  sessions.set(activeSessionId, state);
@@ -1,4 +1,23 @@
1
1
  // @bun
2
+ // src/application/mcp/normalizeMcpRequest.ts
3
+ var REQUIRED_ACCEPT_TYPES = ["application/json", "text/event-stream"];
4
+ function canNormalizeAcceptHeader(acceptHeader) {
5
+ return !acceptHeader || acceptHeader.includes("*/*") || acceptHeader.includes("application/*") || REQUIRED_ACCEPT_TYPES.some((value) => acceptHeader.includes(value));
6
+ }
7
+ function normalizeMcpRequest(request) {
8
+ if (request.method !== "POST")
9
+ return request;
10
+ const acceptHeader = request.headers.get("accept");
11
+ if (!canNormalizeAcceptHeader(acceptHeader))
12
+ return request;
13
+ const missingTypes = REQUIRED_ACCEPT_TYPES.filter((value) => !acceptHeader?.includes(value));
14
+ if (missingTypes.length === 0)
15
+ return request;
16
+ const headers = new Headers(request.headers);
17
+ headers.set("accept", [acceptHeader, ...missingTypes].filter(Boolean).join(", "));
18
+ return new Request(request, { headers });
19
+ }
20
+
2
21
  // src/application/mcp/common.ts
3
22
  import { randomUUID } from "crypto";
4
23
  import { createMcpServer } from "@contractspec/lib.contracts-runtime-server-mcp/provider-mcp";
@@ -94,7 +113,7 @@ function createMcpElysiaHandler({
94
113
  stateful: false
95
114
  });
96
115
  try {
97
- return await state.transport.handleRequest(request);
116
+ return await state.transport.handleRequest(normalizeMcpRequest(request));
98
117
  } finally {
99
118
  await closeSessionState(state);
100
119
  }
@@ -130,7 +149,7 @@ function createMcpElysiaHandler({
130
149
  createdState = true;
131
150
  }
132
151
  try {
133
- const response = await state.transport.handleRequest(request);
152
+ const response = await state.transport.handleRequest(normalizeMcpRequest(request));
134
153
  const activeSessionId = state.transport.sessionId;
135
154
  if (activeSessionId && !sessions.has(activeSessionId)) {
136
155
  sessions.set(activeSessionId, state);
@@ -0,0 +1 @@
1
+ export {};
@@ -26,6 +26,25 @@ var authLogger = new Logger({
26
26
  enableContext: true,
27
27
  enableColors: false
28
28
  });
29
+ // src/application/mcp/normalizeMcpRequest.ts
30
+ var REQUIRED_ACCEPT_TYPES = ["application/json", "text/event-stream"];
31
+ function canNormalizeAcceptHeader(acceptHeader) {
32
+ return !acceptHeader || acceptHeader.includes("*/*") || acceptHeader.includes("application/*") || REQUIRED_ACCEPT_TYPES.some((value) => acceptHeader.includes(value));
33
+ }
34
+ function normalizeMcpRequest(request) {
35
+ if (request.method !== "POST")
36
+ return request;
37
+ const acceptHeader = request.headers.get("accept");
38
+ if (!canNormalizeAcceptHeader(acceptHeader))
39
+ return request;
40
+ const missingTypes = REQUIRED_ACCEPT_TYPES.filter((value) => !acceptHeader?.includes(value));
41
+ if (missingTypes.length === 0)
42
+ return request;
43
+ const headers = new Headers(request.headers);
44
+ headers.set("accept", [acceptHeader, ...missingTypes].filter(Boolean).join(", "));
45
+ return new Request(request, { headers });
46
+ }
47
+
29
48
  // src/application/mcp/common.ts
30
49
  import { randomUUID } from "crypto";
31
50
  import { createMcpServer } from "@contractspec/lib.contracts-runtime-server-mcp/provider-mcp";
@@ -121,7 +140,7 @@ function createMcpElysiaHandler({
121
140
  stateful: false
122
141
  });
123
142
  try {
124
- return await state.transport.handleRequest(request);
143
+ return await state.transport.handleRequest(normalizeMcpRequest(request));
125
144
  } finally {
126
145
  await closeSessionState(state);
127
146
  }
@@ -157,7 +176,7 @@ function createMcpElysiaHandler({
157
176
  createdState = true;
158
177
  }
159
178
  try {
160
- const response = await state.transport.handleRequest(request);
179
+ const response = await state.transport.handleRequest(normalizeMcpRequest(request));
161
180
  const activeSessionId = state.transport.sessionId;
162
181
  if (activeSessionId && !sessions.has(activeSessionId)) {
163
182
  sessions.set(activeSessionId, state);
@@ -0,0 +1,2 @@
1
+ export * from './docsMcp.data';
2
+ export * from './docsMcp.reference';
@@ -0,0 +1,382 @@
1
+ // @bun
2
+ // src/application/mcp/docsMcp.data.ts
3
+ import { defaultDocRegistry } from "@contractspec/lib.contracts-spec/docs";
4
+ var DEFAULT_LIMIT = 20;
5
+ var MAX_LIMIT = 100;
6
+ function normalizeText(value) {
7
+ return value?.trim().toLowerCase() ?? "";
8
+ }
9
+ function normalizeRoute(route) {
10
+ const decoded = decodeURIComponent(route).trim();
11
+ if (!decoded)
12
+ return "/";
13
+ return decoded.startsWith("/") ? decoded : `/${decoded}`;
14
+ }
15
+ function normalizeTags(value) {
16
+ const tags = Array.isArray(value) ? value : value ? [value] : [];
17
+ return tags.map((tag) => normalizeText(tag)).filter(Boolean);
18
+ }
19
+ function clampLimit(limit) {
20
+ if (!limit || Number.isNaN(limit))
21
+ return DEFAULT_LIMIT;
22
+ return Math.min(Math.max(limit, 1), MAX_LIMIT);
23
+ }
24
+ function clampOffset(offset) {
25
+ if (!offset || Number.isNaN(offset))
26
+ return 0;
27
+ return Math.max(offset, 0);
28
+ }
29
+ function toDocSummary({ block, route }) {
30
+ return {
31
+ id: block.id,
32
+ title: block.title,
33
+ summary: block.summary ?? "",
34
+ route,
35
+ visibility: block.visibility ?? "public",
36
+ kind: block.kind ?? "reference",
37
+ version: block.version ?? "1.0.0",
38
+ tags: block.tags ?? []
39
+ };
40
+ }
41
+ function scoreDoc(route, query) {
42
+ if (!query)
43
+ return 1;
44
+ const tokens = query.split(/\s+/).filter(Boolean);
45
+ const title = normalizeText(route.block.title);
46
+ const id = normalizeText(route.block.id);
47
+ const summary = normalizeText(route.block.summary);
48
+ const body = normalizeText(route.block.body);
49
+ const path = normalizeText(route.route);
50
+ const tags = (route.block.tags ?? []).map((tag) => normalizeText(tag));
51
+ const haystack = [title, id, summary, body, path, ...tags].join(" ");
52
+ if (tokens.some((token) => !haystack.includes(token)))
53
+ return 0;
54
+ let score = 0;
55
+ for (const token of tokens) {
56
+ if (id.includes(token))
57
+ score += 8;
58
+ if (title.includes(token))
59
+ score += 7;
60
+ if (tags.some((tag) => tag.includes(token)))
61
+ score += 5;
62
+ if (summary.includes(token))
63
+ score += 4;
64
+ if (path.includes(token))
65
+ score += 3;
66
+ if (body.includes(token))
67
+ score += 2;
68
+ }
69
+ return score;
70
+ }
71
+ function searchDocs(routes, args) {
72
+ const query = normalizeText(typeof args.query === "string" ? args.query : undefined);
73
+ const tags = normalizeTags(args.tag);
74
+ const visibility = normalizeText(typeof args.visibility === "string" ? args.visibility : undefined);
75
+ const kind = normalizeText(typeof args.kind === "string" ? args.kind : undefined);
76
+ const limit = clampLimit(typeof args.limit === "number" ? args.limit : undefined);
77
+ const offset = clampOffset(typeof args.offset === "number" ? args.offset : undefined);
78
+ const ranked = routes.map((route) => ({
79
+ doc: toDocSummary(route),
80
+ score: scoreDoc(route, query)
81
+ })).filter(({ doc, score }) => {
82
+ const matchesQuery = query ? score > 0 : true;
83
+ const matchesTags = tags.length ? tags.every((tag) => doc.tags.some((docTag) => normalizeText(docTag).includes(tag))) : true;
84
+ const matchesVisibility = visibility ? normalizeText(doc.visibility) === visibility : true;
85
+ const matchesKind = kind ? normalizeText(doc.kind) === kind : true;
86
+ return matchesQuery && matchesTags && matchesVisibility && matchesKind;
87
+ }).sort((left, right) => {
88
+ if (right.score !== left.score)
89
+ return right.score - left.score;
90
+ return left.doc.title.localeCompare(right.doc.title);
91
+ });
92
+ const docs = ranked.slice(offset, offset + limit).map(({ doc }) => doc);
93
+ const nextOffset = offset + docs.length < ranked.length ? offset + docs.length : undefined;
94
+ return {
95
+ docs,
96
+ items: docs,
97
+ total: ranked.length,
98
+ ...nextOffset != null ? { nextOffset } : {}
99
+ };
100
+ }
101
+ function getDocById(id) {
102
+ const normalizedId = decodeURIComponent(id);
103
+ const found = defaultDocRegistry.get(normalizedId);
104
+ if (!found)
105
+ return;
106
+ return {
107
+ doc: toDocSummary(found),
108
+ content: String(found.block.body ?? "")
109
+ };
110
+ }
111
+ function getDocByRoute(routes, routePath) {
112
+ const normalizedPath = normalizeRoute(routePath);
113
+ const found = routes.find((route) => normalizeRoute(route.route) === normalizedPath);
114
+ if (!found)
115
+ return;
116
+ return {
117
+ doc: toDocSummary(found),
118
+ content: String(found.block.body ?? "")
119
+ };
120
+ }
121
+ function listDocFacets(routes) {
122
+ const tags = new Map;
123
+ const kinds = new Map;
124
+ const visibilities = new Map;
125
+ for (const route of routes) {
126
+ const kind = route.block.kind ?? "reference";
127
+ const visibility = route.block.visibility ?? "public";
128
+ kinds.set(kind, (kinds.get(kind) ?? 0) + 1);
129
+ visibilities.set(visibility, (visibilities.get(visibility) ?? 0) + 1);
130
+ for (const tag of route.block.tags ?? []) {
131
+ tags.set(tag, (tags.get(tag) ?? 0) + 1);
132
+ }
133
+ }
134
+ const toEntries = (values, key) => [...values.entries()].sort((left, right) => right[1] - left[1] || left[0].localeCompare(right[0])).map(([value, count]) => ({ [key]: value, count }));
135
+ return {
136
+ totalDocs: routes.length,
137
+ tags: toEntries(tags, "tag"),
138
+ kinds: toEntries(kinds, "kind"),
139
+ visibilities: toEntries(visibilities, "visibility")
140
+ };
141
+ }
142
+
143
+ // src/features/contracts-registry.ts
144
+ import {
145
+ EventRegistry,
146
+ OperationSpecRegistry
147
+ } from "@contractspec/lib.contracts-spec";
148
+ import {
149
+ DataViewRegistry
150
+ } from "@contractspec/lib.contracts-spec/data-views";
151
+ import {
152
+ ContractReferenceDataView,
153
+ ContractReferenceQuery,
154
+ DocsGenerateCommand,
155
+ DocsGeneratedEvent,
156
+ DocsIndexDataView,
157
+ DocsIndexQuery,
158
+ DocsLayoutPresentation,
159
+ DocsPublishCommand,
160
+ DocsPublishedEvent,
161
+ DocsReferencePagePresentation,
162
+ DocsSearchForm,
163
+ ExampleCatalogDataView
164
+ } from "@contractspec/lib.contracts-spec/docs";
165
+ import { FormRegistry } from "@contractspec/lib.contracts-spec/forms";
166
+ import {
167
+ PresentationRegistry
168
+ } from "@contractspec/lib.contracts-spec/presentations";
169
+ import {
170
+ serializeDataViewSpec,
171
+ serializeEventSpec,
172
+ serializeFormSpec,
173
+ serializeOperationSpec,
174
+ serializePresentationSpec
175
+ } from "@contractspec/lib.contracts-spec/serialization";
176
+ var operationRegistry = null;
177
+ function createContractSpecOperationRegistry() {
178
+ const registry = new OperationSpecRegistry;
179
+ registry.register(DocsIndexQuery).register(ContractReferenceQuery).register(DocsGenerateCommand).register(DocsPublishCommand);
180
+ return registry;
181
+ }
182
+ function getContractSpecOperationRegistry() {
183
+ if (!operationRegistry) {
184
+ operationRegistry = createContractSpecOperationRegistry();
185
+ }
186
+ return operationRegistry;
187
+ }
188
+ function resolveOperationSpec(key, version) {
189
+ return getContractSpecOperationRegistry().get(key, version);
190
+ }
191
+ var eventRegistry = null;
192
+ function createContractSpecEventRegistry() {
193
+ const registry = new EventRegistry;
194
+ registry.register(DocsGeneratedEvent).register(DocsPublishedEvent);
195
+ return registry;
196
+ }
197
+ function getContractSpecEventRegistry() {
198
+ if (!eventRegistry) {
199
+ eventRegistry = createContractSpecEventRegistry();
200
+ }
201
+ return eventRegistry;
202
+ }
203
+ function resolveEventSpec(key, version) {
204
+ return getContractSpecEventRegistry().get(key, version);
205
+ }
206
+ var presentationRegistry = null;
207
+ function createContractSpecPresentationRegistry() {
208
+ const registry = new PresentationRegistry;
209
+ registry.register(DocsLayoutPresentation).register(DocsReferencePagePresentation);
210
+ return registry;
211
+ }
212
+ function getContractSpecPresentationRegistry() {
213
+ if (!presentationRegistry) {
214
+ presentationRegistry = createContractSpecPresentationRegistry();
215
+ }
216
+ return presentationRegistry;
217
+ }
218
+ function resolvePresentationSpec(key, version) {
219
+ return getContractSpecPresentationRegistry().get(key, version);
220
+ }
221
+ var dataViewRegistry = null;
222
+ function createContractSpecDataViewRegistry() {
223
+ const registry = new DataViewRegistry;
224
+ registry.register(DocsIndexDataView).register(ContractReferenceDataView).register(ExampleCatalogDataView);
225
+ return registry;
226
+ }
227
+ function getContractSpecDataViewRegistry() {
228
+ if (!dataViewRegistry) {
229
+ dataViewRegistry = createContractSpecDataViewRegistry();
230
+ }
231
+ return dataViewRegistry;
232
+ }
233
+ function resolveDataViewSpec(key, version) {
234
+ return getContractSpecDataViewRegistry().get(key, version);
235
+ }
236
+ var formRegistry = null;
237
+ function createContractSpecFormRegistry() {
238
+ const registry = new FormRegistry;
239
+ registry.register(DocsSearchForm);
240
+ return registry;
241
+ }
242
+ function getContractSpecFormRegistry() {
243
+ if (!formRegistry) {
244
+ formRegistry = createContractSpecFormRegistry();
245
+ }
246
+ return formRegistry;
247
+ }
248
+ function resolveFormSpec(key, _version) {
249
+ return getContractSpecFormRegistry().get(key);
250
+ }
251
+ function resolveSerializedOperationSpec(key, version) {
252
+ const spec = resolveOperationSpec(key, version);
253
+ return serializeOperationSpec(spec) ?? undefined;
254
+ }
255
+ function resolveSerializedEventSpec(key, version) {
256
+ const spec = resolveEventSpec(key, version);
257
+ return serializeEventSpec(spec) ?? undefined;
258
+ }
259
+ function resolveSerializedPresentationSpec(key, version) {
260
+ const spec = resolvePresentationSpec(key, version);
261
+ return serializePresentationSpec(spec) ?? undefined;
262
+ }
263
+ function resolveSerializedDataViewSpec(key, version) {
264
+ const spec = resolveDataViewSpec(key, version);
265
+ return serializeDataViewSpec(spec) ?? undefined;
266
+ }
267
+ function resolveSerializedFormSpec(key, version) {
268
+ const spec = resolveFormSpec(key, version);
269
+ return serializeFormSpec(spec) ?? undefined;
270
+ }
271
+ function resetContractSpecOperationRegistry() {
272
+ operationRegistry = null;
273
+ }
274
+ function resetContractSpecEventRegistry() {
275
+ eventRegistry = null;
276
+ }
277
+ function resetContractSpecPresentationRegistry() {
278
+ presentationRegistry = null;
279
+ }
280
+ function resetContractSpecDataViewRegistry() {
281
+ dataViewRegistry = null;
282
+ }
283
+ function resetContractSpecFormRegistry() {
284
+ formRegistry = null;
285
+ }
286
+ function resetAllContractSpecRegistries() {
287
+ resetContractSpecOperationRegistry();
288
+ resetContractSpecEventRegistry();
289
+ resetContractSpecPresentationRegistry();
290
+ resetContractSpecDataViewRegistry();
291
+ resetContractSpecFormRegistry();
292
+ }
293
+
294
+ // src/application/mcp/docsMcp.reference.ts
295
+ import { defaultDocRegistry as defaultDocRegistry2 } from "@contractspec/lib.contracts-spec/docs";
296
+ function normalizeText2(value) {
297
+ return value?.trim().toLowerCase() ?? "";
298
+ }
299
+ function routeFromDocIds(docIds) {
300
+ for (const docId of docIds ?? []) {
301
+ const doc = defaultDocRegistry2.get(docId);
302
+ if (doc)
303
+ return doc.route;
304
+ }
305
+ return;
306
+ }
307
+ function toReference(spec, type, schema, policy) {
308
+ const title = spec.meta.title ?? spec.meta.key;
309
+ const route = routeFromDocIds(spec.meta.docId);
310
+ const description = spec.meta.description;
311
+ return {
312
+ key: spec.meta.key,
313
+ version: spec.meta.version,
314
+ type,
315
+ title,
316
+ description,
317
+ markdown: [
318
+ `# ${title}`,
319
+ `- Key: ${spec.meta.key}`,
320
+ `- Type: ${type}`,
321
+ `- Version: ${spec.meta.version}`,
322
+ route ? `- Docs route: ${route}` : "",
323
+ description ? `
324
+ ${description}` : ""
325
+ ].filter(Boolean).join(`
326
+ `),
327
+ ...route ? { route } : {},
328
+ ...schema ? { schema } : {},
329
+ ...policy ? { policy } : {},
330
+ tags: spec.meta.tags ?? [],
331
+ owners: spec.meta.owners ?? [],
332
+ stability: spec.meta.stability
333
+ };
334
+ }
335
+ function resolveContractReference(args) {
336
+ const includeSchema = args.includeSchema ?? false;
337
+ const requestedType = normalizeText2(args.type);
338
+ const operation = resolveOperationSpec(args.key, args.version);
339
+ if (operation && (!requestedType || requestedType === "operation" || requestedType === operation.meta.kind)) {
340
+ return {
341
+ reference: toReference(operation, operation.meta.kind, includeSchema ? resolveSerializedOperationSpec(args.key, args.version) : undefined, operation.policy)
342
+ };
343
+ }
344
+ const resolvers = [
345
+ {
346
+ type: "data-view",
347
+ spec: resolveDataViewSpec(args.key, args.version),
348
+ schema: includeSchema ? resolveSerializedDataViewSpec(args.key, args.version) : undefined
349
+ },
350
+ {
351
+ type: "form",
352
+ spec: resolveFormSpec(args.key, args.version),
353
+ schema: includeSchema ? resolveSerializedFormSpec(args.key, args.version) : undefined
354
+ },
355
+ {
356
+ type: "presentation",
357
+ spec: resolvePresentationSpec(args.key, args.version),
358
+ schema: includeSchema ? resolveSerializedPresentationSpec(args.key, args.version) : undefined
359
+ },
360
+ {
361
+ type: "event",
362
+ spec: resolveEventSpec(args.key, args.version),
363
+ schema: includeSchema ? resolveSerializedEventSpec(args.key, args.version) : undefined
364
+ }
365
+ ];
366
+ for (const candidate of resolvers) {
367
+ if (candidate.spec && (!requestedType || requestedType === candidate.type)) {
368
+ return {
369
+ reference: toReference(candidate.spec, candidate.type, candidate.schema)
370
+ };
371
+ }
372
+ }
373
+ throw new Error(`Contract reference not found: ${args.key}`);
374
+ }
375
+ export {
376
+ toDocSummary,
377
+ searchDocs,
378
+ resolveContractReference,
379
+ listDocFacets,
380
+ getDocByRoute,
381
+ getDocById
382
+ };
@@ -1,4 +1,7 @@
1
- export declare function createDocsMcpHandler(path?: string): import("elysia").default<"", {
1
+ interface DocsMcpHandlerOptions {
2
+ includePresentations?: boolean;
3
+ }
4
+ export declare function createDocsMcpHandler(path?: string, options?: DocsMcpHandlerOptions): import("elysia").default<"", {
2
5
  decorator: {};
3
6
  store: {};
4
7
  derive: {};
@@ -38,3 +41,4 @@ export declare function createDocsMcpHandler(path?: string): import("elysia").de
38
41
  standaloneSchema: {};
39
42
  response: {};
40
43
  }>;
44
+ export {};
@@ -0,0 +1,85 @@
1
+ import type { DocPresentationRoute } from '@contractspec/lib.contracts-spec/docs';
2
+ type DocsSearchArgs = {
3
+ query?: string;
4
+ tag?: string | string[];
5
+ visibility?: string;
6
+ kind?: string;
7
+ limit?: number;
8
+ offset?: number;
9
+ };
10
+ export declare function toDocSummary({ block, route }: DocPresentationRoute): {
11
+ id: string;
12
+ title: string;
13
+ summary: string;
14
+ route: string;
15
+ visibility: import("@contractspec/lib.contracts-spec").DocVisibility;
16
+ kind: import("@contractspec/lib.contracts-spec").DocKind;
17
+ version: string;
18
+ tags: string[];
19
+ };
20
+ export declare function searchDocs(routes: DocPresentationRoute[], args: DocsSearchArgs): {
21
+ nextOffset?: number | undefined;
22
+ docs: {
23
+ id: string;
24
+ title: string;
25
+ summary: string;
26
+ route: string;
27
+ visibility: import("@contractspec/lib.contracts-spec").DocVisibility;
28
+ kind: import("@contractspec/lib.contracts-spec").DocKind;
29
+ version: string;
30
+ tags: string[];
31
+ }[];
32
+ items: {
33
+ id: string;
34
+ title: string;
35
+ summary: string;
36
+ route: string;
37
+ visibility: import("@contractspec/lib.contracts-spec").DocVisibility;
38
+ kind: import("@contractspec/lib.contracts-spec").DocKind;
39
+ version: string;
40
+ tags: string[];
41
+ }[];
42
+ total: number;
43
+ };
44
+ export declare function getDocById(id: string): {
45
+ doc: {
46
+ id: string;
47
+ title: string;
48
+ summary: string;
49
+ route: string;
50
+ visibility: import("@contractspec/lib.contracts-spec").DocVisibility;
51
+ kind: import("@contractspec/lib.contracts-spec").DocKind;
52
+ version: string;
53
+ tags: string[];
54
+ };
55
+ content: string;
56
+ } | undefined;
57
+ export declare function getDocByRoute(routes: DocPresentationRoute[], routePath: string): {
58
+ doc: {
59
+ id: string;
60
+ title: string;
61
+ summary: string;
62
+ route: string;
63
+ visibility: import("@contractspec/lib.contracts-spec").DocVisibility;
64
+ kind: import("@contractspec/lib.contracts-spec").DocKind;
65
+ version: string;
66
+ tags: string[];
67
+ };
68
+ content: string;
69
+ } | undefined;
70
+ export declare function listDocFacets(routes: DocPresentationRoute[]): {
71
+ totalDocs: number;
72
+ tags: {
73
+ [x: string]: string | number;
74
+ count: number;
75
+ }[];
76
+ kinds: {
77
+ [x: string]: string | number;
78
+ count: number;
79
+ }[];
80
+ visibilities: {
81
+ [x: string]: string | number;
82
+ count: number;
83
+ }[];
84
+ };
85
+ export {};