@specverse/engines 4.1.5 → 4.1.6
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/dist/libs/instance-factories/applications/templates/generic/backend-env-generator.js +22 -0
- package/dist/libs/instance-factories/applications/templates/generic/backend-package-json-generator.js +66 -0
- package/dist/libs/instance-factories/applications/templates/generic/backend-tsconfig-generator.js +54 -0
- package/dist/libs/instance-factories/applications/templates/generic/main-generator.js +290 -0
- package/dist/libs/instance-factories/applications/templates/react/_view-components-source.js +530 -0
- package/dist/libs/instance-factories/applications/templates/react/api-client-generator.js +437 -0
- package/dist/libs/instance-factories/applications/templates/react/api-types-generator.js +146 -0
- package/dist/libs/instance-factories/applications/templates/react/app-tsx-generator.js +73 -0
- package/dist/libs/instance-factories/applications/templates/react/env-example-generator.js +18 -0
- package/dist/libs/instance-factories/applications/templates/react/field-helpers-generator.js +99 -0
- package/dist/libs/instance-factories/applications/templates/react/gitignore-generator.js +35 -0
- package/dist/libs/instance-factories/applications/templates/react/index-css-generator.js +9 -0
- package/dist/libs/instance-factories/applications/templates/react/index-html-generator.js +23 -0
- package/dist/libs/instance-factories/applications/templates/react/main-tsx-generator.js +29 -0
- package/dist/libs/instance-factories/applications/templates/react/package-json-generator.js +49 -0
- package/dist/libs/instance-factories/applications/templates/react/pattern-adapter-generator.js +156 -0
- package/dist/libs/instance-factories/applications/templates/react/react-pattern-adapter.js +935 -0
- package/dist/libs/instance-factories/applications/templates/react/relationship-field-generator.js +143 -0
- package/dist/libs/instance-factories/applications/templates/react/runtime-app-tsx-generator.js +101 -0
- package/dist/libs/instance-factories/applications/templates/react/runtime-package-json-generator.js +50 -0
- package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-generator.js +646 -0
- package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-wrapper-generator.js +65 -0
- package/dist/libs/instance-factories/applications/templates/react/tsconfig-generator.js +28 -0
- package/dist/libs/instance-factories/applications/templates/react/use-api-hooks-generator.js +132 -0
- package/dist/libs/instance-factories/applications/templates/react/view-dashboard-generator.js +143 -0
- package/dist/libs/instance-factories/applications/templates/react/view-detail-generator.js +143 -0
- package/dist/libs/instance-factories/applications/templates/react/view-form-generator.js +355 -0
- package/dist/libs/instance-factories/applications/templates/react/view-list-generator.js +91 -0
- package/dist/libs/instance-factories/applications/templates/react/view-router-generator.js +79 -0
- package/dist/libs/instance-factories/applications/templates/react/vite-config-generator.js +42 -0
- package/dist/libs/instance-factories/cli/templates/commander/cli-bin-wrapper-generator.js +11 -0
- package/dist/libs/instance-factories/cli/templates/commander/cli-entry-generator.js +111 -0
- package/dist/libs/instance-factories/cli/templates/commander/command-generator.js +928 -0
- package/dist/libs/instance-factories/communication/templates/eventemitter/bus-generator.js +83 -0
- package/dist/libs/instance-factories/communication/templates/eventemitter/publisher-generator.js +91 -0
- package/dist/libs/instance-factories/communication/templates/eventemitter/subscriber-generator.js +86 -0
- package/dist/libs/instance-factories/controllers/templates/fastify/meta-routes-generator.js +93 -0
- package/dist/libs/instance-factories/controllers/templates/fastify/routes-generator.js +280 -0
- package/dist/libs/instance-factories/controllers/templates/fastify/server-generator.js +125 -0
- package/dist/libs/instance-factories/infrastructure/templates/docker-k8s/infrastructure-generator.js +25 -0
- package/dist/libs/instance-factories/orms/templates/prisma/schema-generator.js +371 -0
- package/dist/libs/instance-factories/orms/templates/prisma/services-generator.js +266 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/env-example-generator.js +51 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/env-generator.js +61 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/gitignore-generator.js +59 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/package-json-generator.js +126 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/readme-generator.js +159 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/tsconfig-generator.js +56 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/tsconfig-react-generator.js +37 -0
- package/dist/libs/instance-factories/sdks/templates/python/sdk-generator.js +29 -0
- package/dist/libs/instance-factories/sdks/templates/typescript/sdk-generator.js +28 -0
- package/dist/libs/instance-factories/services/templates/memory/generate-interpreter.js +14 -0
- package/dist/libs/instance-factories/services/templates/memory/step-conventions-memory.js +415 -0
- package/dist/libs/instance-factories/services/templates/prisma/behavior-generator.js +177 -0
- package/dist/libs/instance-factories/services/templates/prisma/controller-generator.js +413 -0
- package/dist/libs/instance-factories/services/templates/prisma/service-generator.js +243 -0
- package/dist/libs/instance-factories/services/templates/prisma/step-conventions.js +264 -0
- package/dist/libs/instance-factories/services/templates/shared-patterns.js +24 -0
- package/dist/libs/instance-factories/shared/path-resolver.js +59 -0
- package/dist/libs/instance-factories/storage/templates/mongodb/config-generator.js +13 -0
- package/dist/libs/instance-factories/storage/templates/mongodb/docker-generator.js +16 -0
- package/dist/libs/instance-factories/storage/templates/postgresql/config-generator.js +45 -0
- package/dist/libs/instance-factories/storage/templates/postgresql/docker-generator.js +46 -0
- package/dist/libs/instance-factories/storage/templates/redis/config-generator.js +14 -0
- package/dist/libs/instance-factories/storage/templates/redis/docker-generator.js +16 -0
- package/dist/libs/instance-factories/test-generation.js +145 -0
- package/dist/libs/instance-factories/testing/templates/vitest/tests-generator.js +30 -0
- package/dist/libs/instance-factories/tools/templates/mcp/mcp-server-generator.js +149 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/controllers/MCPServerController.js +232 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/events/EventEmitter.js +49 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/index.js +18 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/interfaces/ResourceProvider.js +0 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/models/LibrarySuggestion.js +97 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/models/SpecVerseResource.js +64 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/server/mcp-server.js +182 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/CLIProxyService.js +1210 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/EmbeddedResourcesAdapter.js +172 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/EntityModuleService.js +240 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/HybridResourcesProvider.js +147 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/LibraryToolsService.js +281 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorBridge.js +409 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorToolsService.js +414 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/PromptToolsService.js +467 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/ResourcesProviderService.js +135 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/types/index.js +0 -0
- package/dist/libs/instance-factories/tools/templates/vscode/static/extension.js +965 -0
- package/dist/libs/instance-factories/tools/templates/vscode/vscode-extension-generator.js +238 -0
- package/dist/libs/instance-factories/validation/templates/zod/validation-generator.js +25 -0
- package/dist/libs/instance-factories/views/index.js +48 -0
- package/dist/libs/instance-factories/views/templates/react/adapters/antd-adapter.js +742 -0
- package/dist/libs/instance-factories/views/templates/react/adapters/mui-adapter.js +824 -0
- package/dist/libs/instance-factories/views/templates/react/adapters/shadcn-adapter.js +719 -0
- package/dist/libs/instance-factories/views/templates/react/app-generator.js +45 -0
- package/dist/libs/instance-factories/views/templates/react/components-generator.js +779 -0
- package/dist/libs/instance-factories/views/templates/react/forms-generator.js +285 -0
- package/dist/libs/instance-factories/views/templates/react/frontend-package-json-generator.js +46 -0
- package/dist/libs/instance-factories/views/templates/react/hooks-generator.js +111 -0
- package/dist/libs/instance-factories/views/templates/react/index-css-generator.js +9 -0
- package/dist/libs/instance-factories/views/templates/react/index-html-generator.js +23 -0
- package/dist/libs/instance-factories/views/templates/react/main-tsx-generator.js +21 -0
- package/dist/libs/instance-factories/views/templates/react/react-component-generator.js +299 -0
- package/dist/libs/instance-factories/views/templates/react/router-generator.js +136 -0
- package/dist/libs/instance-factories/views/templates/react/router-generic-generator.js +107 -0
- package/dist/libs/instance-factories/views/templates/react/shared-utils-generator.js +179 -0
- package/dist/libs/instance-factories/views/templates/react/spec-json-generator.js +7 -0
- package/dist/libs/instance-factories/views/templates/react/types-generator.js +56 -0
- package/dist/libs/instance-factories/views/templates/react/views-metadata-generator.js +27 -0
- package/dist/libs/instance-factories/views/templates/react/vite-config-generator.js +29 -0
- package/dist/libs/instance-factories/views/templates/runtime/runtime-view-renderer.js +261 -0
- package/dist/libs/instance-factories/views/templates/shared/adapter-types.js +34 -0
- package/dist/libs/instance-factories/views/templates/shared/atomic-components-registry.js +800 -0
- package/dist/libs/instance-factories/views/templates/shared/base-generator.js +305 -0
- package/dist/libs/instance-factories/views/templates/shared/component-metadata.js +517 -0
- package/dist/libs/instance-factories/views/templates/shared/composite-pattern-types.js +0 -0
- package/dist/libs/instance-factories/views/templates/shared/composite-patterns.js +445 -0
- package/dist/libs/instance-factories/views/templates/shared/index.js +80 -0
- package/dist/libs/instance-factories/views/templates/shared/pattern-validator.js +210 -0
- package/dist/libs/instance-factories/views/templates/shared/property-mapper.js +492 -0
- package/dist/libs/instance-factories/views/templates/shared/syntax-mapper.js +321 -0
- package/package.json +3 -2
package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/LibraryToolsService.js
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { parse } from "yaml";
|
|
2
|
+
import { LibrarySuggestionModel } from "../models/LibrarySuggestion.js";
|
|
3
|
+
class LibraryToolsService {
|
|
4
|
+
resourcesProvider;
|
|
5
|
+
libraryCatalog = null;
|
|
6
|
+
catalogCache = /* @__PURE__ */ new Map();
|
|
7
|
+
constructor(resourcesProvider) {
|
|
8
|
+
this.resourcesProvider = resourcesProvider;
|
|
9
|
+
}
|
|
10
|
+
async getLibrarySuggestions(context) {
|
|
11
|
+
try {
|
|
12
|
+
if (!this.libraryCatalog) {
|
|
13
|
+
await this.loadLibraryCatalog();
|
|
14
|
+
}
|
|
15
|
+
if (!this.libraryCatalog) {
|
|
16
|
+
throw new Error("Library catalog not available");
|
|
17
|
+
}
|
|
18
|
+
const {
|
|
19
|
+
requirements = "",
|
|
20
|
+
scale = "business"
|
|
21
|
+
} = context;
|
|
22
|
+
const analysis = this.analyzeSuggestions(requirements, scale);
|
|
23
|
+
return {
|
|
24
|
+
content: [{
|
|
25
|
+
type: "text",
|
|
26
|
+
text: JSON.stringify({
|
|
27
|
+
libraries: analysis.libraries.map((lib) => ({
|
|
28
|
+
name: lib.name,
|
|
29
|
+
path: lib.path,
|
|
30
|
+
type: lib.type,
|
|
31
|
+
description: lib.description,
|
|
32
|
+
ai_description: lib.ai_description,
|
|
33
|
+
expansion_factor: lib.expansion_factor,
|
|
34
|
+
complexity_level: lib.complexity_level,
|
|
35
|
+
best_for: lib.best_for
|
|
36
|
+
})),
|
|
37
|
+
reasoning: analysis.reasoning,
|
|
38
|
+
usage_examples: analysis.usage_examples,
|
|
39
|
+
total_suggestions: analysis.libraries.length,
|
|
40
|
+
scale_optimization: scale
|
|
41
|
+
}, null, 2)
|
|
42
|
+
}]
|
|
43
|
+
};
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return {
|
|
46
|
+
content: [{
|
|
47
|
+
type: "text",
|
|
48
|
+
text: `Error generating library suggestions: ${error instanceof Error ? error.message : String(error)}`
|
|
49
|
+
}],
|
|
50
|
+
isError: true
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
analyzeSuggestions(projectContext, scale) {
|
|
55
|
+
if (!this.libraryCatalog) {
|
|
56
|
+
return {
|
|
57
|
+
libraries: [],
|
|
58
|
+
reasoning: "Library catalog not available",
|
|
59
|
+
usage_examples: []
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const suggestions = [];
|
|
63
|
+
const reasoningParts = [];
|
|
64
|
+
const usageExamples = [];
|
|
65
|
+
const contextLower = projectContext.toLowerCase();
|
|
66
|
+
const allLibraries = this.getAllLibraries();
|
|
67
|
+
const domainAnalysis = this.analyzeDomain(contextLower, allLibraries);
|
|
68
|
+
if (domainAnalysis.library) {
|
|
69
|
+
suggestions.push(domainAnalysis.library);
|
|
70
|
+
reasoningParts.push(domainAnalysis.reasoning);
|
|
71
|
+
usageExamples.push(domainAnalysis.usage);
|
|
72
|
+
}
|
|
73
|
+
const techAnalysis = this.analyzeTechnology(contextLower, allLibraries);
|
|
74
|
+
if (techAnalysis.library && !suggestions.find((s) => s.name === techAnalysis.library.name)) {
|
|
75
|
+
suggestions.push(techAnalysis.library);
|
|
76
|
+
reasoningParts.push(techAnalysis.reasoning);
|
|
77
|
+
usageExamples.push(techAnalysis.usage);
|
|
78
|
+
}
|
|
79
|
+
const deploymentAnalysis = this.analyzeDeployment(scale, allLibraries);
|
|
80
|
+
if (deploymentAnalysis.library && !suggestions.find((s) => s.name === deploymentAnalysis.library.name)) {
|
|
81
|
+
suggestions.push(deploymentAnalysis.library);
|
|
82
|
+
reasoningParts.push(deploymentAnalysis.reasoning);
|
|
83
|
+
usageExamples.push(deploymentAnalysis.usage);
|
|
84
|
+
}
|
|
85
|
+
const authAnalysis = this.analyzeAuthentication(contextLower, allLibraries);
|
|
86
|
+
if (authAnalysis.library && !suggestions.find((s) => s.name === authAnalysis.library.name)) {
|
|
87
|
+
suggestions.push(authAnalysis.library);
|
|
88
|
+
reasoningParts.push(authAnalysis.reasoning);
|
|
89
|
+
usageExamples.push(authAnalysis.usage);
|
|
90
|
+
}
|
|
91
|
+
if (suggestions.length === 0) {
|
|
92
|
+
const defaults = allLibraries.filter((lib) => this.isGeneralPurpose(lib) || this.matchesScale(lib, scale)).slice(0, 2);
|
|
93
|
+
suggestions.push(...defaults);
|
|
94
|
+
reasoningParts.push("General-purpose libraries for common patterns");
|
|
95
|
+
usageExamples.push('import:\\n - from: "@specverse/types/examples"\\n models: [User, BaseEntity]');
|
|
96
|
+
}
|
|
97
|
+
suggestions.sort((a, b) => {
|
|
98
|
+
const aScore = a.matchesContext(projectContext, scale);
|
|
99
|
+
const bScore = b.matchesContext(projectContext, scale);
|
|
100
|
+
return bScore - aScore;
|
|
101
|
+
});
|
|
102
|
+
return {
|
|
103
|
+
libraries: suggestions.slice(0, 5),
|
|
104
|
+
// Top 5 suggestions
|
|
105
|
+
reasoning: reasoningParts.join("; "),
|
|
106
|
+
usage_examples: usageExamples
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async loadLibraryCatalog() {
|
|
110
|
+
try {
|
|
111
|
+
const catalogContent = await this.resourcesProvider.getResourceContent("specverse://libraries/catalog");
|
|
112
|
+
this.libraryCatalog = parse(catalogContent);
|
|
113
|
+
this.cacheLibraryModels();
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error("Failed to load library catalog:", error);
|
|
116
|
+
this.libraryCatalog = this.createEmptyLibraryCatalog();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
cacheLibraryModels() {
|
|
120
|
+
if (!this.libraryCatalog) return;
|
|
121
|
+
const allLibraries = [
|
|
122
|
+
...Object.values(this.libraryCatalog.deployments || {}),
|
|
123
|
+
...Object.values(this.libraryCatalog.domains || {}),
|
|
124
|
+
...Object.values(this.libraryCatalog.manifests || {}),
|
|
125
|
+
...Object.values(this.libraryCatalog.types || {})
|
|
126
|
+
];
|
|
127
|
+
for (const library of allLibraries) {
|
|
128
|
+
try {
|
|
129
|
+
const model = LibrarySuggestionModel.create(library);
|
|
130
|
+
this.catalogCache.set(library.name, model);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.warn(`Failed to cache library ${library.name}:`, error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
getAllLibraries() {
|
|
137
|
+
return Array.from(this.catalogCache.values());
|
|
138
|
+
}
|
|
139
|
+
analyzeDomain(context, libraries) {
|
|
140
|
+
if (context.includes("ecommerce") || context.includes("store") || context.includes("shop")) {
|
|
141
|
+
const ecommerce = libraries.find((lib) => lib.name.includes("ecommerce"));
|
|
142
|
+
if (ecommerce) {
|
|
143
|
+
return {
|
|
144
|
+
library: ecommerce,
|
|
145
|
+
reasoning: "E-commerce domain detected",
|
|
146
|
+
usage: 'import:\\n - from: "@specverse/domains/ecommerce"\\n models: [Product, Order, Customer]'
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (context.includes("healthcare") || context.includes("medical") || context.includes("patient")) {
|
|
151
|
+
const healthcare = libraries.find((lib) => lib.name.includes("healthcare"));
|
|
152
|
+
if (healthcare) {
|
|
153
|
+
return {
|
|
154
|
+
library: healthcare,
|
|
155
|
+
reasoning: "Healthcare domain detected",
|
|
156
|
+
usage: 'import:\\n - from: "@specverse/domains/healthcare"\\n models: [Patient, Provider, Appointment]'
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return { reasoning: "No specific domain patterns detected", usage: "" };
|
|
161
|
+
}
|
|
162
|
+
analyzeTechnology(context, libraries) {
|
|
163
|
+
if (context.includes("nextjs") || context.includes("next.js") || context.includes("react")) {
|
|
164
|
+
const nextjs = libraries.find((lib) => lib.name.includes("nextjs"));
|
|
165
|
+
if (nextjs) {
|
|
166
|
+
return {
|
|
167
|
+
library: nextjs,
|
|
168
|
+
reasoning: "Next.js framework detected",
|
|
169
|
+
usage: 'import:\\n - from: "@specverse/manifests/nextjs"\\n manifests: [nextjs-config]'
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (context.includes("postgresql") || context.includes("postgres")) {
|
|
174
|
+
const postgres = libraries.find((lib) => lib.name.includes("postgresql"));
|
|
175
|
+
if (postgres) {
|
|
176
|
+
return {
|
|
177
|
+
library: postgres,
|
|
178
|
+
reasoning: "PostgreSQL database detected",
|
|
179
|
+
usage: 'import:\\n - from: "@specverse/manifests/postgresql"\\n manifests: [postgres-config]'
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return { reasoning: "No specific technology patterns detected", usage: "" };
|
|
184
|
+
}
|
|
185
|
+
analyzeDeployment(scale, libraries) {
|
|
186
|
+
switch (scale) {
|
|
187
|
+
case "personal":
|
|
188
|
+
const personal = libraries.find((lib) => lib.name.includes("jamstack") || lib.name.includes("monolith"));
|
|
189
|
+
if (personal) {
|
|
190
|
+
return {
|
|
191
|
+
library: personal,
|
|
192
|
+
reasoning: "Personal scale: simple deployment recommended",
|
|
193
|
+
usage: `import:\\n - from: "@specverse/deployments/${personal.name}"\\n deployments: [development]`
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
break;
|
|
197
|
+
case "enterprise":
|
|
198
|
+
const enterprise = libraries.find((lib) => lib.name.includes("enterprise") || lib.name.includes("microservices"));
|
|
199
|
+
if (enterprise) {
|
|
200
|
+
return {
|
|
201
|
+
library: enterprise,
|
|
202
|
+
reasoning: "Enterprise scale: distributed architecture recommended",
|
|
203
|
+
usage: `import:\\n - from: "@specverse/deployments/${enterprise.name}"\\n deployments: [production-cluster]`
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
default:
|
|
208
|
+
const business = libraries.find((lib) => lib.name.includes("microservices") || lib.name.includes("monolith"));
|
|
209
|
+
if (business) {
|
|
210
|
+
return {
|
|
211
|
+
library: business,
|
|
212
|
+
reasoning: "Business scale: scalable deployment recommended",
|
|
213
|
+
usage: `import:\\n - from: "@specverse/deployments/${business.name}"\\n deployments: [production]`
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
return { reasoning: "No deployment pattern match found", usage: "" };
|
|
219
|
+
}
|
|
220
|
+
analyzeAuthentication(context, libraries) {
|
|
221
|
+
if (context.includes("authentication") || context.includes("auth") || context.includes("login")) {
|
|
222
|
+
const oauth = libraries.find((lib) => lib.name.includes("oauth"));
|
|
223
|
+
if (oauth) {
|
|
224
|
+
return {
|
|
225
|
+
library: oauth,
|
|
226
|
+
reasoning: "Authentication features detected",
|
|
227
|
+
usage: 'import:\\n - from: "@specverse/manifests/oauth"\\n manifests: [oauth-config]'
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return { reasoning: "No authentication patterns detected", usage: "" };
|
|
232
|
+
}
|
|
233
|
+
isGeneralPurpose(library) {
|
|
234
|
+
return library.name.includes("examples") || library.name.includes("lib") || library.type === "type";
|
|
235
|
+
}
|
|
236
|
+
matchesScale(library, scale) {
|
|
237
|
+
const scaleComplexity = this.getScaleComplexity(scale);
|
|
238
|
+
const libComplexity = this.getComplexityScore(library.complexity_level);
|
|
239
|
+
return Math.abs(libComplexity - scaleComplexity) <= 1;
|
|
240
|
+
}
|
|
241
|
+
getScaleComplexity(scale) {
|
|
242
|
+
switch (scale) {
|
|
243
|
+
case "personal":
|
|
244
|
+
return 1;
|
|
245
|
+
case "business":
|
|
246
|
+
return 2;
|
|
247
|
+
case "enterprise":
|
|
248
|
+
return 3;
|
|
249
|
+
default:
|
|
250
|
+
return 2;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
getComplexityScore(complexity) {
|
|
254
|
+
switch (complexity) {
|
|
255
|
+
case "low":
|
|
256
|
+
return 1;
|
|
257
|
+
case "medium":
|
|
258
|
+
return 2;
|
|
259
|
+
case "high":
|
|
260
|
+
return 3;
|
|
261
|
+
default:
|
|
262
|
+
return 2;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
createEmptyLibraryCatalog() {
|
|
266
|
+
return {
|
|
267
|
+
version: "3.1.0",
|
|
268
|
+
generated_at: /* @__PURE__ */ new Date(),
|
|
269
|
+
generated_from: "embedded",
|
|
270
|
+
ai_optimization: false,
|
|
271
|
+
total_libraries: 0,
|
|
272
|
+
deployments: {},
|
|
273
|
+
domains: {},
|
|
274
|
+
manifests: {},
|
|
275
|
+
types: {}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
export {
|
|
280
|
+
LibraryToolsService
|
|
281
|
+
};
|
package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorBridge.js
ADDED
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
class OrchestratorBridge {
|
|
2
|
+
config;
|
|
3
|
+
eventEmitter;
|
|
4
|
+
capabilities;
|
|
5
|
+
orchestrator = null;
|
|
6
|
+
initialized = false;
|
|
7
|
+
constructor(config, eventEmitter) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.eventEmitter = eventEmitter;
|
|
10
|
+
this.capabilities = {
|
|
11
|
+
hasFullOrchestrator: false,
|
|
12
|
+
availableOperations: [],
|
|
13
|
+
sessionSupport: false,
|
|
14
|
+
inferenceEngine: false
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Initialize orchestrator bridge with environment detection
|
|
19
|
+
*/
|
|
20
|
+
async initialize() {
|
|
21
|
+
if (this.initialized) return;
|
|
22
|
+
try {
|
|
23
|
+
if (this.config.autoDetect !== false) {
|
|
24
|
+
await this.detectOrchestrator();
|
|
25
|
+
}
|
|
26
|
+
if (this.config.enabled && this.capabilities.hasFullOrchestrator) {
|
|
27
|
+
await this.initializeFullOrchestrator();
|
|
28
|
+
} else {
|
|
29
|
+
await this.initializeFallbackMode();
|
|
30
|
+
}
|
|
31
|
+
this.initialized = true;
|
|
32
|
+
this.eventEmitter.emit("orchestrator-initialized", {
|
|
33
|
+
type: "orchestrator-initialized",
|
|
34
|
+
capabilities: this.capabilities
|
|
35
|
+
});
|
|
36
|
+
} catch (error) {
|
|
37
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
38
|
+
if (this.config.logging) {
|
|
39
|
+
console.warn(`Orchestrator initialization failed: ${errorMessage}`);
|
|
40
|
+
}
|
|
41
|
+
await this.initializeFallbackMode();
|
|
42
|
+
this.initialized = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Execute orchestrator operation
|
|
47
|
+
*/
|
|
48
|
+
async execute(context) {
|
|
49
|
+
if (!this.initialized) {
|
|
50
|
+
throw new Error("Orchestrator bridge not initialized");
|
|
51
|
+
}
|
|
52
|
+
const startTime = Date.now();
|
|
53
|
+
try {
|
|
54
|
+
let result;
|
|
55
|
+
if (this.capabilities.hasFullOrchestrator && this.orchestrator) {
|
|
56
|
+
result = await this.executeWithFullOrchestrator(context);
|
|
57
|
+
} else {
|
|
58
|
+
result = await this.executeWithFallback(context);
|
|
59
|
+
}
|
|
60
|
+
const executionTime = Date.now() - startTime;
|
|
61
|
+
result.executionTime = executionTime;
|
|
62
|
+
this.eventEmitter.emit("orchestrator-execution-completed", {
|
|
63
|
+
type: "orchestrator-execution-completed",
|
|
64
|
+
operation: context.operation,
|
|
65
|
+
executionTime,
|
|
66
|
+
success: result.success
|
|
67
|
+
});
|
|
68
|
+
return result;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
const executionTime = Date.now() - startTime;
|
|
71
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
72
|
+
this.eventEmitter.emit("orchestrator-execution-failed", {
|
|
73
|
+
type: "orchestrator-execution-failed",
|
|
74
|
+
operation: context.operation,
|
|
75
|
+
error: errorMessage,
|
|
76
|
+
executionTime
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
content: "",
|
|
81
|
+
operation: context.operation,
|
|
82
|
+
executionTime,
|
|
83
|
+
error: errorMessage
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get orchestrator capabilities
|
|
89
|
+
*/
|
|
90
|
+
getCapabilities() {
|
|
91
|
+
return { ...this.capabilities };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check if orchestrator is available
|
|
95
|
+
*/
|
|
96
|
+
isAvailable() {
|
|
97
|
+
return this.initialized && (this.capabilities.hasFullOrchestrator || true);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get supported operations
|
|
101
|
+
*/
|
|
102
|
+
getSupportedOperations() {
|
|
103
|
+
return [...this.capabilities.availableOperations];
|
|
104
|
+
}
|
|
105
|
+
// Private methods
|
|
106
|
+
/**
|
|
107
|
+
* Detect orchestrator availability in current environment
|
|
108
|
+
*/
|
|
109
|
+
async detectOrchestrator() {
|
|
110
|
+
try {
|
|
111
|
+
const orchestratorPath = this.config.orchestratorPath || "@specverse/engine-ai";
|
|
112
|
+
try {
|
|
113
|
+
const orchestratorModule = await import(orchestratorPath);
|
|
114
|
+
if (orchestratorModule.SpecVerseOrchestrator) {
|
|
115
|
+
this.capabilities.hasFullOrchestrator = true;
|
|
116
|
+
if (this.config.logging && this.config.mode !== "local") {
|
|
117
|
+
console.log("Full orchestrator detected via import");
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
} catch (importError) {
|
|
122
|
+
}
|
|
123
|
+
const { existsSync } = await import("fs");
|
|
124
|
+
const { resolve, join } = await import("path");
|
|
125
|
+
const possiblePaths = [
|
|
126
|
+
resolve(process.cwd(), "../../../src/orchestrator"),
|
|
127
|
+
resolve(process.cwd(), "../../src/orchestrator"),
|
|
128
|
+
resolve(process.cwd(), "../src/orchestrator"),
|
|
129
|
+
resolve(process.cwd(), "src/orchestrator"),
|
|
130
|
+
join(process.cwd(), "../../dist/orchestrator")
|
|
131
|
+
];
|
|
132
|
+
for (const path of possiblePaths) {
|
|
133
|
+
if (existsSync(path)) {
|
|
134
|
+
this.capabilities.hasFullOrchestrator = true;
|
|
135
|
+
this.config.orchestratorPath = path;
|
|
136
|
+
if (this.config.logging && this.config.mode !== "local") {
|
|
137
|
+
console.log(`Orchestrator detected at: ${path}`);
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
const { execSync } = await import("child_process");
|
|
144
|
+
execSync("specverse --version", { stdio: "pipe" });
|
|
145
|
+
this.capabilities.hasFullOrchestrator = true;
|
|
146
|
+
if (this.config.logging && this.config.mode !== "local") {
|
|
147
|
+
console.log("Global SpecVerse CLI detected");
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
} catch (cliError) {
|
|
151
|
+
}
|
|
152
|
+
if (this.config.logging && this.config.mode !== "local") {
|
|
153
|
+
console.log("Full orchestrator not detected, using fallback mode");
|
|
154
|
+
}
|
|
155
|
+
this.capabilities.hasFullOrchestrator = false;
|
|
156
|
+
} catch (error) {
|
|
157
|
+
if (this.config.logging) {
|
|
158
|
+
console.warn(`Orchestrator detection failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
159
|
+
}
|
|
160
|
+
this.capabilities.hasFullOrchestrator = false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Initialize full orchestrator with all capabilities
|
|
165
|
+
*/
|
|
166
|
+
async initializeFullOrchestrator() {
|
|
167
|
+
try {
|
|
168
|
+
let orchestratorModule;
|
|
169
|
+
const possiblePaths = [
|
|
170
|
+
this.config.orchestratorPath,
|
|
171
|
+
// User-specified path
|
|
172
|
+
"@specverse/engine-ai",
|
|
173
|
+
// npm package (primary)
|
|
174
|
+
"../../dist/orchestrator/index.js"
|
|
175
|
+
// local package path (fallback)
|
|
176
|
+
].filter(Boolean);
|
|
177
|
+
for (const path of possiblePaths) {
|
|
178
|
+
if (!path) continue;
|
|
179
|
+
try {
|
|
180
|
+
orchestratorModule = await import(path);
|
|
181
|
+
if (orchestratorModule.SpecVerseOrchestrator) {
|
|
182
|
+
if (this.config.logging) {
|
|
183
|
+
console.log(`Successfully loaded orchestrator from: ${path}`);
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
} catch (error) {
|
|
188
|
+
if (this.config.logging) {
|
|
189
|
+
console.debug(`Failed to load orchestrator from ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
190
|
+
}
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (!orchestratorModule) {
|
|
195
|
+
throw new Error("Could not find orchestrator module in any of the expected locations");
|
|
196
|
+
}
|
|
197
|
+
if (!orchestratorModule.SpecVerseOrchestrator) {
|
|
198
|
+
throw new Error("SpecVerseOrchestrator not found in module");
|
|
199
|
+
}
|
|
200
|
+
this.orchestrator = new orchestratorModule.SpecVerseOrchestrator();
|
|
201
|
+
await this.orchestrator.initialize();
|
|
202
|
+
this.capabilities = {
|
|
203
|
+
hasFullOrchestrator: true,
|
|
204
|
+
availableOperations: ["analyse", "create", "infer", "materialise", "realize"],
|
|
205
|
+
workingDirectory: this.config.workingDirectory || process.cwd(),
|
|
206
|
+
sessionSupport: true,
|
|
207
|
+
inferenceEngine: true
|
|
208
|
+
};
|
|
209
|
+
if (this.config.logging) {
|
|
210
|
+
if (this.config.logging && this.config.mode !== "local") {
|
|
211
|
+
console.log("Full orchestrator initialized successfully");
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (this.config.logging) {
|
|
215
|
+
if (this.config.logging && this.config.mode !== "local") {
|
|
216
|
+
console.log(`Available operations: ${this.capabilities.availableOperations.join(", ")}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
} catch (error) {
|
|
220
|
+
throw new Error(`Failed to initialize full orchestrator: ${error instanceof Error ? error.message : String(error)}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Initialize fallback mode with limited capabilities
|
|
225
|
+
*/
|
|
226
|
+
async initializeFallbackMode() {
|
|
227
|
+
this.capabilities = {
|
|
228
|
+
hasFullOrchestrator: false,
|
|
229
|
+
availableOperations: ["create", "analyse"],
|
|
230
|
+
// Basic operations available via prompts
|
|
231
|
+
workingDirectory: this.config.workingDirectory || process.cwd(),
|
|
232
|
+
sessionSupport: false,
|
|
233
|
+
inferenceEngine: false
|
|
234
|
+
};
|
|
235
|
+
if (this.config.logging) {
|
|
236
|
+
if (this.config.logging && this.config.mode !== "local") {
|
|
237
|
+
console.log("Orchestrator bridge initialized in fallback mode");
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (this.config.logging) {
|
|
241
|
+
if (this.config.logging && this.config.mode !== "local") {
|
|
242
|
+
console.log(`Limited operations: ${this.capabilities.availableOperations.join(", ")}`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Execute operation with full orchestrator
|
|
248
|
+
*/
|
|
249
|
+
async executeWithFullOrchestrator(context) {
|
|
250
|
+
try {
|
|
251
|
+
const orchestrationContext = {
|
|
252
|
+
operation: context.operation,
|
|
253
|
+
input: context.input,
|
|
254
|
+
inputPath: context.inputPath,
|
|
255
|
+
inputType: context.inputType,
|
|
256
|
+
outputPath: context.outputPath,
|
|
257
|
+
framework: context.framework,
|
|
258
|
+
scale: context.scale || "business",
|
|
259
|
+
interactive: context.interactive || false,
|
|
260
|
+
sessionId: context.sessionId
|
|
261
|
+
};
|
|
262
|
+
if (this.config.logging) {
|
|
263
|
+
if (this.config.logging && this.config.mode !== "local") {
|
|
264
|
+
console.log(`Executing ${context.operation} with full orchestrator...`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
const result = await this.orchestrator.execute(orchestrationContext);
|
|
268
|
+
return {
|
|
269
|
+
success: true,
|
|
270
|
+
content: result.content,
|
|
271
|
+
operation: context.operation,
|
|
272
|
+
provider: result.provider,
|
|
273
|
+
sessionId: result.sessionId,
|
|
274
|
+
executionTime: 0,
|
|
275
|
+
// Will be set by caller
|
|
276
|
+
metadata: result.metadata
|
|
277
|
+
};
|
|
278
|
+
} catch (error) {
|
|
279
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
280
|
+
if (this.config.logging) {
|
|
281
|
+
console.error(`Full orchestrator execution failed: ${errorMessage}`);
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
success: false,
|
|
285
|
+
content: "",
|
|
286
|
+
operation: context.operation,
|
|
287
|
+
executionTime: 0,
|
|
288
|
+
error: errorMessage
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Execute operation with fallback implementation
|
|
294
|
+
*/
|
|
295
|
+
async executeWithFallback(context) {
|
|
296
|
+
if (this.config.logging) {
|
|
297
|
+
if (this.config.logging && this.config.mode !== "local") {
|
|
298
|
+
console.log(`Executing ${context.operation} in fallback mode...`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
switch (context.operation) {
|
|
302
|
+
case "create":
|
|
303
|
+
return this.executeFallbackCreate(context);
|
|
304
|
+
case "analyse":
|
|
305
|
+
return this.executeFallbackAnalyse(context);
|
|
306
|
+
case "infer":
|
|
307
|
+
return this.executeFallbackInfer(context);
|
|
308
|
+
default:
|
|
309
|
+
return {
|
|
310
|
+
success: false,
|
|
311
|
+
content: "",
|
|
312
|
+
operation: context.operation,
|
|
313
|
+
executionTime: 0,
|
|
314
|
+
error: `Operation '${context.operation}' not supported in fallback mode. Full orchestrator required.`
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
async executeFallbackCreate(context) {
|
|
319
|
+
const content = `# SpecVerse Creation (Fallback Mode)
|
|
320
|
+
|
|
321
|
+
**Requirements**: ${context.input || "No requirements provided"}
|
|
322
|
+
**Scale**: ${context.scale || "business"}
|
|
323
|
+
**Framework**: ${context.framework || "auto-detect"}
|
|
324
|
+
|
|
325
|
+
## Next Steps
|
|
326
|
+
|
|
327
|
+
This operation requires the full SpecVerse orchestrator for AI-powered specification creation.
|
|
328
|
+
|
|
329
|
+
In fallback mode, you can:
|
|
330
|
+
1. Use the \`get_creation_prompt\` MCP tool to get an expanded prompt
|
|
331
|
+
2. Use that prompt with your AI assistant to create specifications
|
|
332
|
+
3. Use the SpecVerse CLI locally for full orchestrator capabilities
|
|
333
|
+
|
|
334
|
+
## Fallback Specification Template
|
|
335
|
+
|
|
336
|
+
\`\`\`yaml
|
|
337
|
+
components:
|
|
338
|
+
${context.framework || "Application"}Component:
|
|
339
|
+
models:
|
|
340
|
+
# Define your models here based on requirements
|
|
341
|
+
ExampleModel:
|
|
342
|
+
attributes:
|
|
343
|
+
name: String required
|
|
344
|
+
description: String optional
|
|
345
|
+
relationships:
|
|
346
|
+
# Add relationships as needed
|
|
347
|
+
\`\`\`
|
|
348
|
+
|
|
349
|
+
**Note**: For full AI-powered creation, install the complete SpecVerse toolchain locally.`;
|
|
350
|
+
return {
|
|
351
|
+
success: true,
|
|
352
|
+
content,
|
|
353
|
+
operation: context.operation,
|
|
354
|
+
executionTime: 0,
|
|
355
|
+
metadata: {
|
|
356
|
+
scale: context.scale,
|
|
357
|
+
framework: context.framework,
|
|
358
|
+
processingTime: 1
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
async executeFallbackAnalyse(context) {
|
|
363
|
+
const content = `# SpecVerse Analysis (Fallback Mode)
|
|
364
|
+
|
|
365
|
+
**Target**: ${context.inputPath || context.input || "No input provided"}
|
|
366
|
+
**Framework**: ${context.framework || "auto-detect"}
|
|
367
|
+
|
|
368
|
+
## Analysis Summary
|
|
369
|
+
|
|
370
|
+
This operation requires the full SpecVerse orchestrator for AI-powered codebase analysis.
|
|
371
|
+
|
|
372
|
+
In fallback mode, you can:
|
|
373
|
+
1. Use the \`get_analysis_prompt\` MCP tool to get an expanded analysis prompt
|
|
374
|
+
2. Use that prompt with your AI assistant to analyze codebases
|
|
375
|
+
3. Install the complete SpecVerse toolchain for full orchestrator capabilities
|
|
376
|
+
|
|
377
|
+
## Manual Analysis Steps
|
|
378
|
+
|
|
379
|
+
1. **Identify Models**: Look for data structures, entities, classes
|
|
380
|
+
2. **Map Relationships**: Identify how models relate to each other
|
|
381
|
+
3. **Find Controllers**: Locate API endpoints, request handlers
|
|
382
|
+
4. **Discover Services**: Find business logic, processing functions
|
|
383
|
+
5. **Map Events**: Identify event publishing and handling
|
|
384
|
+
|
|
385
|
+
**Note**: For full AI-powered analysis, install the complete SpecVerse toolchain locally.`;
|
|
386
|
+
return {
|
|
387
|
+
success: true,
|
|
388
|
+
content,
|
|
389
|
+
operation: context.operation,
|
|
390
|
+
executionTime: 0,
|
|
391
|
+
metadata: {
|
|
392
|
+
framework: context.framework,
|
|
393
|
+
processingTime: 1
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
async executeFallbackInfer(context) {
|
|
398
|
+
return {
|
|
399
|
+
success: false,
|
|
400
|
+
content: "",
|
|
401
|
+
operation: context.operation,
|
|
402
|
+
executionTime: 0,
|
|
403
|
+
error: "Inference operation requires the full SpecVerse orchestrator with inference engine. Please install the complete SpecVerse toolchain."
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
export {
|
|
408
|
+
OrchestratorBridge
|
|
409
|
+
};
|