@contractspec/bundle.library 3.8.4 → 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 (90) hide show
  1. package/.turbo/turbo-build.log +126 -112
  2. package/CHANGELOG.md +6 -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/features/index.js +15 -15
  29. package/dist/index.js +171 -171
  30. package/dist/node/application/index.js +806 -131
  31. package/dist/node/application/mcp/cliMcp.js +21 -2
  32. package/dist/node/application/mcp/common.js +21 -2
  33. package/dist/node/application/mcp/contractsMcp.js +21 -2
  34. package/dist/node/application/mcp/docsMcp.catalog.js +381 -0
  35. package/dist/node/application/mcp/docsMcp.data.js +147 -0
  36. package/dist/node/application/mcp/docsMcp.js +776 -101
  37. package/dist/node/application/mcp/docsMcp.prompts.js +521 -0
  38. package/dist/node/application/mcp/docsMcp.reference.js +235 -0
  39. package/dist/node/application/mcp/docsMcp.resources.js +519 -0
  40. package/dist/node/application/mcp/docsMcp.tools.js +518 -0
  41. package/dist/node/application/mcp/index.js +806 -131
  42. package/dist/node/application/mcp/internalMcp.js +21 -2
  43. package/dist/node/application/mcp/normalizeMcpRequest.js +21 -0
  44. package/dist/node/application/mcp/providerRankingMcp.js +21 -2
  45. package/dist/node/features/index.js +15 -15
  46. package/dist/node/index.js +171 -171
  47. package/dist/node/presentation/features/hooks/index.js +12 -12
  48. package/dist/node/presentation/features/hooks/useContractsRegistry.js +12 -12
  49. package/dist/node/presentation/features/index.js +12 -12
  50. package/dist/node/presentation/features/organisms/FeatureDataViewsList.js +12 -12
  51. package/dist/node/presentation/features/organisms/FeatureEventsList.js +12 -12
  52. package/dist/node/presentation/features/organisms/FeatureFormsList.js +12 -12
  53. package/dist/node/presentation/features/organisms/FeaturePresentationsList.js +12 -12
  54. package/dist/node/presentation/features/organisms/index.js +12 -12
  55. package/dist/node/presentation/features/templates/FeatureDataViewsTemplate/FeatureDataViewsTemplate.js +12 -12
  56. package/dist/node/presentation/features/templates/FeatureDataViewsTemplate/index.js +12 -12
  57. package/dist/node/presentation/features/templates/FeatureEventsTemplate/FeatureEventsTemplate.js +12 -12
  58. package/dist/node/presentation/features/templates/FeatureEventsTemplate/index.js +12 -12
  59. package/dist/node/presentation/features/templates/FeatureFormsTemplate/FeatureFormsTemplate.js +12 -12
  60. package/dist/node/presentation/features/templates/FeatureFormsTemplate/index.js +12 -12
  61. package/dist/node/presentation/features/templates/FeaturePresentationsTemplate/FeaturePresentationsTemplate.js +12 -12
  62. package/dist/node/presentation/features/templates/FeaturePresentationsTemplate/index.js +12 -12
  63. package/dist/presentation/features/hooks/index.js +12 -12
  64. package/dist/presentation/features/hooks/useContractsRegistry.js +12 -12
  65. package/dist/presentation/features/index.js +12 -12
  66. package/dist/presentation/features/organisms/FeatureDataViewsList.js +12 -12
  67. package/dist/presentation/features/organisms/FeatureEventsList.js +12 -12
  68. package/dist/presentation/features/organisms/FeatureFormsList.js +12 -12
  69. package/dist/presentation/features/organisms/FeaturePresentationsList.js +12 -12
  70. package/dist/presentation/features/organisms/index.js +12 -12
  71. package/dist/presentation/features/templates/FeatureDataViewsTemplate/FeatureDataViewsTemplate.js +12 -12
  72. package/dist/presentation/features/templates/FeatureDataViewsTemplate/index.js +12 -12
  73. package/dist/presentation/features/templates/FeatureEventsTemplate/FeatureEventsTemplate.js +12 -12
  74. package/dist/presentation/features/templates/FeatureEventsTemplate/index.js +12 -12
  75. package/dist/presentation/features/templates/FeatureFormsTemplate/FeatureFormsTemplate.js +12 -12
  76. package/dist/presentation/features/templates/FeatureFormsTemplate/index.js +12 -12
  77. package/dist/presentation/features/templates/FeaturePresentationsTemplate/FeaturePresentationsTemplate.js +12 -12
  78. package/dist/presentation/features/templates/FeaturePresentationsTemplate/index.js +12 -12
  79. package/package.json +85 -1
  80. package/src/application/mcp/common.test.ts +64 -0
  81. package/src/application/mcp/common.ts +5 -2
  82. package/src/application/mcp/docsMcp.catalog.ts +2 -0
  83. package/src/application/mcp/docsMcp.data.ts +196 -0
  84. package/src/application/mcp/docsMcp.prompts.ts +165 -0
  85. package/src/application/mcp/docsMcp.reference.ts +152 -0
  86. package/src/application/mcp/docsMcp.resources.ts +194 -0
  87. package/src/application/mcp/docsMcp.test.ts +148 -0
  88. package/src/application/mcp/docsMcp.tools.ts +183 -0
  89. package/src/application/mcp/docsMcp.ts +13 -177
  90. package/src/application/mcp/normalizeMcpRequest.ts +30 -0
@@ -0,0 +1,148 @@
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
+ export {
143
+ toDocSummary,
144
+ searchDocs,
145
+ listDocFacets,
146
+ getDocByRoute,
147
+ getDocById
148
+ };