nitrostack 1.0.0
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/CHANGELOG.md +227 -0
- package/CONTRIBUTING.md +182 -0
- package/LICENSE +201 -0
- package/LICENSE_URLS_UPDATE_COMPLETE.md +388 -0
- package/NOTICE +153 -0
- package/README.md +571 -0
- package/dist/auth/api-key.d.ts +118 -0
- package/dist/auth/api-key.d.ts.map +1 -0
- package/dist/auth/api-key.js +168 -0
- package/dist/auth/api-key.js.map +1 -0
- package/dist/auth/client.d.ts +151 -0
- package/dist/auth/client.d.ts.map +1 -0
- package/dist/auth/client.js +330 -0
- package/dist/auth/client.js.map +1 -0
- package/dist/auth/index.d.ts +30 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +43 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/middleware.d.ts +95 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +260 -0
- package/dist/auth/middleware.js.map +1 -0
- package/dist/auth/pkce.d.ts +53 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +105 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/quick-setup.d.ts +94 -0
- package/dist/auth/quick-setup.d.ts.map +1 -0
- package/dist/auth/quick-setup.js +210 -0
- package/dist/auth/quick-setup.js.map +1 -0
- package/dist/auth/server-integration.d.ts +97 -0
- package/dist/auth/server-integration.d.ts.map +1 -0
- package/dist/auth/server-integration.js +182 -0
- package/dist/auth/server-integration.js.map +1 -0
- package/dist/auth/server-metadata.d.ts +51 -0
- package/dist/auth/server-metadata.d.ts.map +1 -0
- package/dist/auth/server-metadata.js +106 -0
- package/dist/auth/server-metadata.js.map +1 -0
- package/dist/auth/simple-jwt.d.ts +88 -0
- package/dist/auth/simple-jwt.d.ts.map +1 -0
- package/dist/auth/simple-jwt.js +152 -0
- package/dist/auth/simple-jwt.js.map +1 -0
- package/dist/auth/token-store.d.ts +104 -0
- package/dist/auth/token-store.d.ts.map +1 -0
- package/dist/auth/token-store.js +205 -0
- package/dist/auth/token-store.js.map +1 -0
- package/dist/auth/token-validation.d.ts +47 -0
- package/dist/auth/token-validation.d.ts.map +1 -0
- package/dist/auth/token-validation.js +237 -0
- package/dist/auth/token-validation.js.map +1 -0
- package/dist/auth/types.d.ts +215 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +6 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/cli/commands/build.d.ts +6 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/build.js +104 -0
- package/dist/cli/commands/build.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +7 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +312 -0
- package/dist/cli/commands/dev.js.map +1 -0
- package/dist/cli/commands/generate-types.d.ts +8 -0
- package/dist/cli/commands/generate-types.d.ts.map +1 -0
- package/dist/cli/commands/generate-types.js +220 -0
- package/dist/cli/commands/generate-types.js.map +1 -0
- package/dist/cli/commands/generate.d.ts +5 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +365 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/init.d.ts +7 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +365 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/start.d.ts +6 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +61 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +47 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/mcp-dev-wrapper.d.ts +3 -0
- package/dist/cli/mcp-dev-wrapper.d.ts.map +1 -0
- package/dist/cli/mcp-dev-wrapper.js +116 -0
- package/dist/cli/mcp-dev-wrapper.js.map +1 -0
- package/dist/core/apikey-module.d.ts +69 -0
- package/dist/core/apikey-module.d.ts.map +1 -0
- package/dist/core/apikey-module.js +114 -0
- package/dist/core/apikey-module.js.map +1 -0
- package/dist/core/app-decorator.d.ts +58 -0
- package/dist/core/app-decorator.d.ts.map +1 -0
- package/dist/core/app-decorator.js +261 -0
- package/dist/core/app-decorator.js.map +1 -0
- package/dist/core/builders.d.ts +38 -0
- package/dist/core/builders.d.ts.map +1 -0
- package/dist/core/builders.js +129 -0
- package/dist/core/builders.js.map +1 -0
- package/dist/core/component.d.ts +105 -0
- package/dist/core/component.d.ts.map +1 -0
- package/dist/core/component.js +182 -0
- package/dist/core/component.js.map +1 -0
- package/dist/core/config-module.d.ts +55 -0
- package/dist/core/config-module.d.ts.map +1 -0
- package/dist/core/config-module.js +94 -0
- package/dist/core/config-module.js.map +1 -0
- package/dist/core/decorators/cache.decorator.d.ts +61 -0
- package/dist/core/decorators/cache.decorator.d.ts.map +1 -0
- package/dist/core/decorators/cache.decorator.js +115 -0
- package/dist/core/decorators/cache.decorator.js.map +1 -0
- package/dist/core/decorators/health-check.decorator.d.ts +80 -0
- package/dist/core/decorators/health-check.decorator.d.ts.map +1 -0
- package/dist/core/decorators/health-check.decorator.js +153 -0
- package/dist/core/decorators/health-check.decorator.js.map +1 -0
- package/dist/core/decorators/rate-limit.decorator.d.ts +62 -0
- package/dist/core/decorators/rate-limit.decorator.d.ts.map +1 -0
- package/dist/core/decorators/rate-limit.decorator.js +129 -0
- package/dist/core/decorators/rate-limit.decorator.js.map +1 -0
- package/dist/core/decorators.d.ts +151 -0
- package/dist/core/decorators.d.ts.map +1 -0
- package/dist/core/decorators.js +142 -0
- package/dist/core/decorators.js.map +1 -0
- package/dist/core/di/container.d.ts +42 -0
- package/dist/core/di/container.d.ts.map +1 -0
- package/dist/core/di/container.js +76 -0
- package/dist/core/di/container.js.map +1 -0
- package/dist/core/di/injectable.decorator.d.ts +35 -0
- package/dist/core/di/injectable.decorator.d.ts.map +1 -0
- package/dist/core/di/injectable.decorator.js +57 -0
- package/dist/core/di/injectable.decorator.js.map +1 -0
- package/dist/core/errors.d.ts +54 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +87 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/events/event-emitter.d.ts +50 -0
- package/dist/core/events/event-emitter.d.ts.map +1 -0
- package/dist/core/events/event-emitter.js +94 -0
- package/dist/core/events/event-emitter.js.map +1 -0
- package/dist/core/events/event.decorator.d.ts +48 -0
- package/dist/core/events/event.decorator.d.ts.map +1 -0
- package/dist/core/events/event.decorator.js +68 -0
- package/dist/core/events/event.decorator.js.map +1 -0
- package/dist/core/filters/exception-filter.decorator.d.ts +40 -0
- package/dist/core/filters/exception-filter.decorator.d.ts.map +1 -0
- package/dist/core/filters/exception-filter.decorator.js +54 -0
- package/dist/core/filters/exception-filter.decorator.js.map +1 -0
- package/dist/core/filters/exception-filter.interface.d.ts +30 -0
- package/dist/core/filters/exception-filter.interface.d.ts.map +1 -0
- package/dist/core/filters/exception-filter.interface.js +2 -0
- package/dist/core/filters/exception-filter.interface.js.map +1 -0
- package/dist/core/guards/apikey.guard.d.ts +22 -0
- package/dist/core/guards/apikey.guard.d.ts.map +1 -0
- package/dist/core/guards/apikey.guard.js +11 -0
- package/dist/core/guards/apikey.guard.js.map +1 -0
- package/dist/core/guards/guard.interface.d.ts +18 -0
- package/dist/core/guards/guard.interface.d.ts.map +1 -0
- package/dist/core/guards/guard.interface.js +2 -0
- package/dist/core/guards/guard.interface.js.map +1 -0
- package/dist/core/guards/jwt.guard.d.ts +18 -0
- package/dist/core/guards/jwt.guard.d.ts.map +1 -0
- package/dist/core/guards/jwt.guard.js +2 -0
- package/dist/core/guards/jwt.guard.js.map +1 -0
- package/dist/core/guards/oauth.guard.d.ts +35 -0
- package/dist/core/guards/oauth.guard.d.ts.map +1 -0
- package/dist/core/guards/oauth.guard.js +2 -0
- package/dist/core/guards/oauth.guard.js.map +1 -0
- package/dist/core/guards/use-guards.decorator.d.ts +25 -0
- package/dist/core/guards/use-guards.decorator.d.ts.map +1 -0
- package/dist/core/guards/use-guards.decorator.js +32 -0
- package/dist/core/guards/use-guards.decorator.js.map +1 -0
- package/dist/core/health/health-checks.resource.d.ts +14 -0
- package/dist/core/health/health-checks.resource.d.ts.map +1 -0
- package/dist/core/health/health-checks.resource.js +29 -0
- package/dist/core/health/health-checks.resource.js.map +1 -0
- package/dist/core/index.d.ts +55 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +57 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/interceptors/interceptor.decorator.d.ts +37 -0
- package/dist/core/interceptors/interceptor.decorator.d.ts.map +1 -0
- package/dist/core/interceptors/interceptor.decorator.js +51 -0
- package/dist/core/interceptors/interceptor.decorator.js.map +1 -0
- package/dist/core/interceptors/interceptor.interface.d.ts +31 -0
- package/dist/core/interceptors/interceptor.interface.d.ts.map +1 -0
- package/dist/core/interceptors/interceptor.interface.js +2 -0
- package/dist/core/interceptors/interceptor.interface.js.map +1 -0
- package/dist/core/jwt-module.d.ts +51 -0
- package/dist/core/jwt-module.d.ts.map +1 -0
- package/dist/core/jwt-module.js +52 -0
- package/dist/core/jwt-module.js.map +1 -0
- package/dist/core/logger.d.ts +18 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +51 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/middleware/middleware.decorator.d.ts +39 -0
- package/dist/core/middleware/middleware.decorator.d.ts.map +1 -0
- package/dist/core/middleware/middleware.decorator.js +53 -0
- package/dist/core/middleware/middleware.decorator.js.map +1 -0
- package/dist/core/middleware/middleware.interface.d.ts +29 -0
- package/dist/core/middleware/middleware.interface.d.ts.map +1 -0
- package/dist/core/middleware/middleware.interface.js +2 -0
- package/dist/core/middleware/middleware.interface.js.map +1 -0
- package/dist/core/module.d.ts +74 -0
- package/dist/core/module.d.ts.map +1 -0
- package/dist/core/module.js +82 -0
- package/dist/core/module.js.map +1 -0
- package/dist/core/oauth-module.d.ts +144 -0
- package/dist/core/oauth-module.d.ts.map +1 -0
- package/dist/core/oauth-module.js +190 -0
- package/dist/core/oauth-module.js.map +1 -0
- package/dist/core/pipes/pipe.decorator.d.ts +55 -0
- package/dist/core/pipes/pipe.decorator.d.ts.map +1 -0
- package/dist/core/pipes/pipe.decorator.js +85 -0
- package/dist/core/pipes/pipe.decorator.js.map +1 -0
- package/dist/core/pipes/pipe.interface.d.ts +36 -0
- package/dist/core/pipes/pipe.interface.d.ts.map +1 -0
- package/dist/core/pipes/pipe.interface.js +2 -0
- package/dist/core/pipes/pipe.interface.js.map +1 -0
- package/dist/core/prompt.d.ts +37 -0
- package/dist/core/prompt.d.ts.map +1 -0
- package/dist/core/prompt.js +76 -0
- package/dist/core/prompt.js.map +1 -0
- package/dist/core/resource.d.ts +42 -0
- package/dist/core/resource.d.ts.map +1 -0
- package/dist/core/resource.js +90 -0
- package/dist/core/resource.js.map +1 -0
- package/dist/core/server.d.ts +72 -0
- package/dist/core/server.d.ts.map +1 -0
- package/dist/core/server.js +406 -0
- package/dist/core/server.js.map +1 -0
- package/dist/core/tool.d.ts +78 -0
- package/dist/core/tool.d.ts.map +1 -0
- package/dist/core/tool.js +190 -0
- package/dist/core/tool.js.map +1 -0
- package/dist/core/transports/http-server.d.ts +102 -0
- package/dist/core/transports/http-server.d.ts.map +1 -0
- package/dist/core/transports/http-server.js +265 -0
- package/dist/core/transports/http-server.js.map +1 -0
- package/dist/core/types.d.ts +123 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/widgets/widget-examples.resource.d.ts +17 -0
- package/dist/core/widgets/widget-examples.resource.d.ts.map +1 -0
- package/dist/core/widgets/widget-examples.resource.js +28 -0
- package/dist/core/widgets/widget-examples.resource.js.map +1 -0
- package/dist/core/widgets/widget-registry.d.ts +56 -0
- package/dist/core/widgets/widget-registry.d.ts.map +1 -0
- package/dist/core/widgets/widget-registry.js +75 -0
- package/dist/core/widgets/widget-registry.js.map +1 -0
- package/dist/testing/index.d.ts +82 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +164 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/ui-next/index.d.ts +31 -0
- package/dist/ui-next/index.d.ts.map +1 -0
- package/dist/ui-next/index.js +687 -0
- package/dist/ui-next/index.js.map +1 -0
- package/dist/widgets/index.d.ts +9 -0
- package/dist/widgets/index.d.ts.map +1 -0
- package/dist/widgets/index.js +9 -0
- package/dist/widgets/index.js.map +1 -0
- package/dist/widgets/metadata.d.ts +53 -0
- package/dist/widgets/metadata.d.ts.map +1 -0
- package/dist/widgets/metadata.js +29 -0
- package/dist/widgets/metadata.js.map +1 -0
- package/dist/widgets/withToolData.d.ts +19 -0
- package/dist/widgets/withToolData.d.ts.map +1 -0
- package/dist/widgets/withToolData.js +240 -0
- package/dist/widgets/withToolData.js.map +1 -0
- package/jest.config.js +21 -0
- package/package.json +108 -0
- package/templates/typescript-auth/AI_AGENT_CLI_REFERENCE.md +702 -0
- package/templates/typescript-auth/AI_AGENT_SDK_REFERENCE.md +1260 -0
- package/templates/typescript-auth/README.md +400 -0
- package/templates/typescript-auth/package.json +44 -0
- package/templates/typescript-auth-api-key/AI_AGENT_CLI_REFERENCE.md +701 -0
- package/templates/typescript-auth-api-key/AI_AGENT_SDK_REFERENCE.md +1260 -0
- package/templates/typescript-auth-api-key/README.md +483 -0
- package/templates/typescript-auth-api-key/package-lock.json +124 -0
- package/templates/typescript-auth-api-key/package.json +29 -0
- package/templates/typescript-oauth/AI_AGENT_CLI_REFERENCE.md +701 -0
- package/templates/typescript-oauth/AI_AGENT_SDK_REFERENCE.md +1260 -0
- package/templates/typescript-oauth/OAUTH_SETUP.md +406 -0
- package/templates/typescript-oauth/README.md +350 -0
- package/templates/typescript-oauth/package.json +30 -0
- package/templates/typescript-starter/AI_AGENT_CLI_REFERENCE.md +701 -0
- package/templates/typescript-starter/AI_AGENT_SDK_REFERENCE.md +1260 -0
- package/templates/typescript-starter/README.md +312 -0
- package/templates/typescript-starter/package.json +32 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Tool } from './tool.js';
|
|
2
|
+
import { createResource } from './resource.js';
|
|
3
|
+
import { createPrompt } from './prompt.js';
|
|
4
|
+
import { createComponentFromNextRoute } from '../ui-next/index.js';
|
|
5
|
+
import { extractTools, extractResources, extractPrompts, getWidgetMetadata } from './decorators.js';
|
|
6
|
+
import { getGuardsMetadata } from './guards/use-guards.decorator.js';
|
|
7
|
+
import { getMiddlewareMetadata } from './middleware/middleware.decorator.js';
|
|
8
|
+
import { getInterceptorMetadata } from './interceptors/interceptor.decorator.js';
|
|
9
|
+
import { getPipeMetadata } from './pipes/pipe.decorator.js';
|
|
10
|
+
import { getExceptionFilterMetadata } from './filters/exception-filter.decorator.js';
|
|
11
|
+
import { DIContainer } from './di/container.js';
|
|
12
|
+
import { isInjectable } from './di/injectable.decorator.js';
|
|
13
|
+
/**
|
|
14
|
+
* Build a Tool instance from a decorated method
|
|
15
|
+
*/
|
|
16
|
+
export function buildTool(controllerInstance, methodName, options, widgetRoute) {
|
|
17
|
+
const prototype = Object.getPrototypeOf(controllerInstance);
|
|
18
|
+
// Get the original method
|
|
19
|
+
const originalMethod = controllerInstance[methodName].bind(controllerInstance);
|
|
20
|
+
// Extract all decorator metadata
|
|
21
|
+
const guards = getGuardsMetadata(prototype, methodName);
|
|
22
|
+
const middlewares = getMiddlewareMetadata(prototype, methodName);
|
|
23
|
+
const interceptors = getInterceptorMetadata(prototype, methodName);
|
|
24
|
+
const pipes = getPipeMetadata(prototype, methodName);
|
|
25
|
+
const filters = getExceptionFilterMetadata(prototype, methodName);
|
|
26
|
+
// Create tool with all metadata
|
|
27
|
+
const tool = new Tool({
|
|
28
|
+
name: options.name,
|
|
29
|
+
description: options.description,
|
|
30
|
+
inputSchema: options.inputSchema,
|
|
31
|
+
handler: originalMethod,
|
|
32
|
+
guards,
|
|
33
|
+
middlewares,
|
|
34
|
+
interceptors,
|
|
35
|
+
pipes,
|
|
36
|
+
filters,
|
|
37
|
+
examples: options.examples,
|
|
38
|
+
widget: widgetRoute ? { route: widgetRoute } : undefined,
|
|
39
|
+
outputTemplate: widgetRoute,
|
|
40
|
+
});
|
|
41
|
+
// Create and attach component if widget route is specified
|
|
42
|
+
if (widgetRoute) {
|
|
43
|
+
const component = createComponentFromNextRoute(widgetRoute);
|
|
44
|
+
tool.setComponent(component);
|
|
45
|
+
}
|
|
46
|
+
return tool;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build all tools from a controller
|
|
50
|
+
*/
|
|
51
|
+
export function buildTools(controllerInstance) {
|
|
52
|
+
const toolMetadata = extractTools(Object.getPrototypeOf(controllerInstance).constructor);
|
|
53
|
+
return toolMetadata.map(({ methodName, options }) => {
|
|
54
|
+
// Check if this method has a widget
|
|
55
|
+
const widgetRoute = getWidgetMetadata(Object.getPrototypeOf(controllerInstance), methodName);
|
|
56
|
+
return buildTool(controllerInstance, methodName, options, widgetRoute);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build a Resource instance from a decorated method
|
|
61
|
+
*/
|
|
62
|
+
export function buildResource(controllerInstance, methodName, options) {
|
|
63
|
+
const originalMethod = controllerInstance[methodName].bind(controllerInstance);
|
|
64
|
+
const resourceDefinition = {
|
|
65
|
+
uri: options.uri,
|
|
66
|
+
name: options.name,
|
|
67
|
+
description: options.description,
|
|
68
|
+
mimeType: options.mimeType,
|
|
69
|
+
handler: async (context) => {
|
|
70
|
+
return await originalMethod(context);
|
|
71
|
+
},
|
|
72
|
+
metadata: options.metadata,
|
|
73
|
+
};
|
|
74
|
+
return createResource(resourceDefinition);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build all resources from a controller
|
|
78
|
+
*/
|
|
79
|
+
export function buildResources(controllerInstance) {
|
|
80
|
+
const resourceMetadata = extractResources(Object.getPrototypeOf(controllerInstance).constructor);
|
|
81
|
+
return resourceMetadata.map(({ methodName, options }) => {
|
|
82
|
+
return buildResource(controllerInstance, methodName, options);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Build a Prompt instance from a decorated method
|
|
87
|
+
*/
|
|
88
|
+
export function buildPrompt(controllerInstance, methodName, options) {
|
|
89
|
+
const originalMethod = controllerInstance[methodName].bind(controllerInstance);
|
|
90
|
+
const promptDefinition = {
|
|
91
|
+
name: options.name,
|
|
92
|
+
description: options.description,
|
|
93
|
+
arguments: options.arguments,
|
|
94
|
+
handler: async (args, context) => {
|
|
95
|
+
return await originalMethod(args, context);
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
return createPrompt(promptDefinition);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Build all prompts from a controller
|
|
102
|
+
*/
|
|
103
|
+
export function buildPrompts(controllerInstance) {
|
|
104
|
+
const promptMetadata = extractPrompts(Object.getPrototypeOf(controllerInstance).constructor);
|
|
105
|
+
return promptMetadata.map(({ methodName, options }) => {
|
|
106
|
+
return buildPrompt(controllerInstance, methodName, options);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Build all tools, resources, and prompts from a controller
|
|
111
|
+
* Supports dependency injection
|
|
112
|
+
*/
|
|
113
|
+
export function buildController(controller) {
|
|
114
|
+
const container = DIContainer.getInstance();
|
|
115
|
+
// Create controller instance (with DI if available)
|
|
116
|
+
let instance;
|
|
117
|
+
if (isInjectable(controller) && container.has(controller)) {
|
|
118
|
+
instance = container.resolve(controller);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
instance = new controller();
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
tools: buildTools(instance),
|
|
125
|
+
resources: buildResources(instance),
|
|
126
|
+
prompts: buildPrompts(instance),
|
|
127
|
+
};
|
|
128
|
+
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interface ComponentMetadata {
|
|
6
|
+
/** Unique identifier for the component */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Human-readable name */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Description of what the component displays */
|
|
11
|
+
description?: string;
|
|
12
|
+
/** HTML content or path to HTML file */
|
|
13
|
+
html: string;
|
|
14
|
+
/** CSS content or path to CSS file */
|
|
15
|
+
css?: string;
|
|
16
|
+
/** JavaScript content or path to JS file */
|
|
17
|
+
js?: string;
|
|
18
|
+
/** Whether component can initiate tool calls */
|
|
19
|
+
canInvokeTools?: boolean;
|
|
20
|
+
/** Content Security Policy domains */
|
|
21
|
+
csp?: {
|
|
22
|
+
connectDomains?: string[];
|
|
23
|
+
resourceDomains?: string[];
|
|
24
|
+
};
|
|
25
|
+
/** Custom subdomain for component rendering */
|
|
26
|
+
subdomain?: string;
|
|
27
|
+
/** Whether to show border around component */
|
|
28
|
+
prefersBorder?: boolean;
|
|
29
|
+
/** Provider-specific metadata */
|
|
30
|
+
providerMetadata?: Record<string, any>;
|
|
31
|
+
/** Internal metadata (not exposed to MCP) */
|
|
32
|
+
_meta?: Record<string, any>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Component definition
|
|
36
|
+
*/
|
|
37
|
+
export interface ComponentDefinition extends ComponentMetadata {
|
|
38
|
+
/** Data transformation function */
|
|
39
|
+
transformer?: (data: any, context: ExecutionContext) => any;
|
|
40
|
+
/** Component initialization logic */
|
|
41
|
+
onInit?: (context: ExecutionContext) => void | Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Component class for defining UI components
|
|
45
|
+
*/
|
|
46
|
+
export declare class Component {
|
|
47
|
+
private definition;
|
|
48
|
+
private compiled;
|
|
49
|
+
private bundle;
|
|
50
|
+
constructor(definition: ComponentDefinition);
|
|
51
|
+
private validateDefinition;
|
|
52
|
+
/**
|
|
53
|
+
* Get component ID
|
|
54
|
+
*/
|
|
55
|
+
get id(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Get component name
|
|
58
|
+
*/
|
|
59
|
+
get name(): string;
|
|
60
|
+
/**
|
|
61
|
+
* Get component description
|
|
62
|
+
*/
|
|
63
|
+
get description(): string | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Compile component bundle
|
|
66
|
+
*/
|
|
67
|
+
compile(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Get compiled bundle as HTML document
|
|
70
|
+
*/
|
|
71
|
+
getBundle(): string;
|
|
72
|
+
/**
|
|
73
|
+
* Get component URI for resource registration
|
|
74
|
+
*/
|
|
75
|
+
getResourceUri(): string;
|
|
76
|
+
/**
|
|
77
|
+
* Check if component is in dev mode
|
|
78
|
+
*/
|
|
79
|
+
isDevMode(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Get dev URL if in dev mode
|
|
82
|
+
*/
|
|
83
|
+
getDevUrl(): string | null;
|
|
84
|
+
/**
|
|
85
|
+
* Transform data for component
|
|
86
|
+
*/
|
|
87
|
+
transformData(data: any, context: ExecutionContext): Promise<any>;
|
|
88
|
+
/**
|
|
89
|
+
* Get provider-specific metadata
|
|
90
|
+
*/
|
|
91
|
+
getProviderMetadata(provider: 'openai' | 'anthropic' | 'generic'): Record<string, any>;
|
|
92
|
+
/**
|
|
93
|
+
* Get resource metadata for MCP
|
|
94
|
+
*/
|
|
95
|
+
getResourceMetadata(): any;
|
|
96
|
+
/**
|
|
97
|
+
* Initialize component
|
|
98
|
+
*/
|
|
99
|
+
initialize(context: ExecutionContext): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Helper function to create a component
|
|
103
|
+
*/
|
|
104
|
+
export declare function createComponent(definition: ComponentDefinition): Component;
|
|
105
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/core/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,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E,mBAAmB;IAK3C,OAAO,CAAC,kBAAkB;IAY1B;;OAEG;IACH,IAAI,EAAE,IAAI,MAAM,CAEf;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAEpC;IAED;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAa9B;;OAEG;IACH,SAAS,IAAI,MAAM;IAoBnB;;OAEG;IACH,cAAc,IAAI,MAAM;IAQxB;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACH,SAAS,IAAI,MAAM,GAAG,IAAI;IAI1B;;OAEG;IACG,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC;IAOvE;;OAEG;IACH,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAiDtF;;OAEG;IACH,mBAAmB,IAAI,GAAG;IAoB1B;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;CAK3D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,mBAAmB,GAAG,SAAS,CAE1E"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component class for defining UI components
|
|
3
|
+
*/
|
|
4
|
+
export class Component {
|
|
5
|
+
definition;
|
|
6
|
+
compiled = false;
|
|
7
|
+
bundle = { html: '' };
|
|
8
|
+
constructor(definition) {
|
|
9
|
+
this.definition = definition;
|
|
10
|
+
this.validateDefinition();
|
|
11
|
+
}
|
|
12
|
+
validateDefinition() {
|
|
13
|
+
if (!this.definition.id) {
|
|
14
|
+
throw new Error('Component ID is required');
|
|
15
|
+
}
|
|
16
|
+
if (!this.definition.name) {
|
|
17
|
+
throw new Error('Component name is required');
|
|
18
|
+
}
|
|
19
|
+
if (!this.definition.html) {
|
|
20
|
+
throw new Error('Component HTML is required');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get component ID
|
|
25
|
+
*/
|
|
26
|
+
get id() {
|
|
27
|
+
return this.definition.id;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get component name
|
|
31
|
+
*/
|
|
32
|
+
get name() {
|
|
33
|
+
return this.definition.name;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get component description
|
|
37
|
+
*/
|
|
38
|
+
get description() {
|
|
39
|
+
return this.definition.description;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Compile component bundle
|
|
43
|
+
*/
|
|
44
|
+
async compile() {
|
|
45
|
+
if (this.compiled)
|
|
46
|
+
return;
|
|
47
|
+
// Simple compilation - in production, use a proper bundler
|
|
48
|
+
this.bundle = {
|
|
49
|
+
html: this.definition.html,
|
|
50
|
+
css: this.definition.css,
|
|
51
|
+
js: this.definition.js,
|
|
52
|
+
};
|
|
53
|
+
this.compiled = true;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get compiled bundle as HTML document
|
|
57
|
+
*/
|
|
58
|
+
getBundle() {
|
|
59
|
+
if (!this.compiled) {
|
|
60
|
+
throw new Error('Component not compiled. Call compile() first.');
|
|
61
|
+
}
|
|
62
|
+
const cssTag = this.bundle.css
|
|
63
|
+
? `<style>${this.bundle.css}</style>`
|
|
64
|
+
: '';
|
|
65
|
+
const jsTag = this.bundle.js
|
|
66
|
+
? `<script type="module">${this.bundle.js}</script>`
|
|
67
|
+
: '';
|
|
68
|
+
return `
|
|
69
|
+
${this.bundle.html}
|
|
70
|
+
${cssTag}
|
|
71
|
+
${jsTag}
|
|
72
|
+
`.trim();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get component URI for resource registration
|
|
76
|
+
*/
|
|
77
|
+
getResourceUri() {
|
|
78
|
+
// In dev mode, return the dev URL if available
|
|
79
|
+
if (this.definition._meta?.devMode && this.definition._meta?.devUrl) {
|
|
80
|
+
return this.definition._meta.devUrl;
|
|
81
|
+
}
|
|
82
|
+
return `ui://widget/${this.definition.id}.html`;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Check if component is in dev mode
|
|
86
|
+
*/
|
|
87
|
+
isDevMode() {
|
|
88
|
+
return this.definition._meta?.devMode === true;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get dev URL if in dev mode
|
|
92
|
+
*/
|
|
93
|
+
getDevUrl() {
|
|
94
|
+
return this.definition._meta?.devUrl || null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Transform data for component
|
|
98
|
+
*/
|
|
99
|
+
async transformData(data, context) {
|
|
100
|
+
if (this.definition.transformer) {
|
|
101
|
+
return await this.definition.transformer(data, context);
|
|
102
|
+
}
|
|
103
|
+
return data;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get provider-specific metadata
|
|
107
|
+
*/
|
|
108
|
+
getProviderMetadata(provider) {
|
|
109
|
+
const metadata = {};
|
|
110
|
+
switch (provider) {
|
|
111
|
+
case 'openai':
|
|
112
|
+
metadata['openai/outputTemplate'] = this.getResourceUri();
|
|
113
|
+
metadata['openai/widgetAccessible'] = this.definition.canInvokeTools || false;
|
|
114
|
+
if (this.definition.description) {
|
|
115
|
+
metadata['openai/widgetDescription'] = this.definition.description;
|
|
116
|
+
}
|
|
117
|
+
if (this.definition.prefersBorder) {
|
|
118
|
+
metadata['openai/widgetPrefersBorder'] = true;
|
|
119
|
+
}
|
|
120
|
+
if (this.definition.subdomain) {
|
|
121
|
+
metadata['openai/widgetDomain'] = this.definition.subdomain;
|
|
122
|
+
}
|
|
123
|
+
if (this.definition.csp) {
|
|
124
|
+
metadata['openai/widgetCSP'] = {
|
|
125
|
+
connect_domains: this.definition.csp.connectDomains || [],
|
|
126
|
+
resource_domains: this.definition.csp.resourceDomains || [],
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
case 'anthropic':
|
|
131
|
+
// Future: Anthropic-specific metadata
|
|
132
|
+
metadata['anthropic/ui'] = this.getResourceUri();
|
|
133
|
+
break;
|
|
134
|
+
case 'generic':
|
|
135
|
+
default:
|
|
136
|
+
// Generic provider metadata
|
|
137
|
+
metadata['ui/template'] = this.getResourceUri();
|
|
138
|
+
metadata['ui/interactive'] = this.definition.canInvokeTools || false;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
// Merge with custom provider metadata
|
|
142
|
+
if (this.definition.providerMetadata) {
|
|
143
|
+
Object.assign(metadata, this.definition.providerMetadata);
|
|
144
|
+
}
|
|
145
|
+
return metadata;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get resource metadata for MCP
|
|
149
|
+
*/
|
|
150
|
+
getResourceMetadata() {
|
|
151
|
+
const metadata = {
|
|
152
|
+
mimeType: 'text/html',
|
|
153
|
+
};
|
|
154
|
+
// Add OpenAI-specific metadata
|
|
155
|
+
const openaiMeta = this.getProviderMetadata('openai');
|
|
156
|
+
if (openaiMeta['openai/widgetCSP']) {
|
|
157
|
+
metadata['openai/widgetCSP'] = openaiMeta['openai/widgetCSP'];
|
|
158
|
+
}
|
|
159
|
+
if (openaiMeta['openai/widgetDescription']) {
|
|
160
|
+
metadata['openai/widgetDescription'] = openaiMeta['openai/widgetDescription'];
|
|
161
|
+
}
|
|
162
|
+
if (openaiMeta['openai/widgetPrefersBorder']) {
|
|
163
|
+
metadata['openai/widgetPrefersBorder'] = openaiMeta['openai/widgetPrefersBorder'];
|
|
164
|
+
}
|
|
165
|
+
return metadata;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Initialize component
|
|
169
|
+
*/
|
|
170
|
+
async initialize(context) {
|
|
171
|
+
if (this.definition.onInit) {
|
|
172
|
+
await this.definition.onInit(context);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Helper function to create a component
|
|
178
|
+
*/
|
|
179
|
+
export function createComponent(definition) {
|
|
180
|
+
return new Component(definition);
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/core/component.ts"],"names":[],"mappings":"AAyDA;;GAEG;AACH,MAAM,OAAO,SAAS;IACZ,UAAU,CAAsB;IAChC,QAAQ,GAAY,KAAK,CAAC;IAC1B,MAAM,GAIV,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAEjB,YAAY,UAA+B;QACzC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC5B,CAAC;IAEO,kBAAkB;QACxB,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,KAAK,CA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,CAAC;QACpF,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,OAAyB;QACxC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YAC3B,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,UAA+B;IAC7D,OAAO,IAAI,SAAS,CAAC,UAAU,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration Module Options
|
|
4
|
+
*/
|
|
5
|
+
export interface ConfigModuleOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Path to .env file (relative to project root)
|
|
8
|
+
*/
|
|
9
|
+
envFilePath?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Whether to ignore .env file if it doesn't exist
|
|
12
|
+
*/
|
|
13
|
+
ignoreEnvFile?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to validate environment variables
|
|
16
|
+
*/
|
|
17
|
+
validate?: (config: Record<string, any>) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Default values for environment variables
|
|
20
|
+
*/
|
|
21
|
+
defaults?: Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Configuration Service
|
|
25
|
+
* Provides type-safe access to environment variables
|
|
26
|
+
*/
|
|
27
|
+
export declare class ConfigService {
|
|
28
|
+
private config;
|
|
29
|
+
constructor(options?: ConfigModuleOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Get a configuration value
|
|
32
|
+
*/
|
|
33
|
+
get<T = string>(key: string): T | undefined;
|
|
34
|
+
get<T = string>(key: string, defaultValue: T): T;
|
|
35
|
+
/**
|
|
36
|
+
* Get a required configuration value
|
|
37
|
+
* Throws if not found
|
|
38
|
+
*/
|
|
39
|
+
getOrThrow<T = string>(key: string): T;
|
|
40
|
+
/**
|
|
41
|
+
* Get all configuration
|
|
42
|
+
*/
|
|
43
|
+
getAll(): Record<string, string>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Configuration Module
|
|
47
|
+
* NestJS-style configuration management
|
|
48
|
+
*/
|
|
49
|
+
export declare class ConfigModule {
|
|
50
|
+
static forRoot(options?: ConfigModuleOptions): {
|
|
51
|
+
providers: any[];
|
|
52
|
+
exports: any[];
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=config-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-module.d.ts","sourceRoot":"","sources":["../../src/core/config-module.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAI1B;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAC;IAEpD;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAyCD;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAyB;gBAE3B,OAAO,GAAE,mBAAwB;IAqB7C;;OAEG;IACH,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAC3C,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC;IAShD;;;OAGG;IACH,UAAU,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC;IAQtC;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAGjC;AAED;;;GAGG;AACH,qBAAa,YAAY;IACvB,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,mBAAwB,GAAG;QACjD,SAAS,EAAE,GAAG,EAAE,CAAC;QACjB,OAAO,EAAE,GAAG,EAAE,CAAC;KAChB;CAQF"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
/**
|
|
5
|
+
* Parse .env file manually to avoid stdout pollution
|
|
6
|
+
* (dotenv.config() can write to stdout which breaks MCP stdio protocol)
|
|
7
|
+
*/
|
|
8
|
+
function parseEnvFile(filePath) {
|
|
9
|
+
const envVars = {};
|
|
10
|
+
if (!fs.existsSync(filePath)) {
|
|
11
|
+
return envVars;
|
|
12
|
+
}
|
|
13
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
14
|
+
content.split('\n').forEach(line => {
|
|
15
|
+
line = line.trim();
|
|
16
|
+
// Skip empty lines and comments
|
|
17
|
+
if (!line || line.startsWith('#')) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
// Parse KEY=VALUE
|
|
21
|
+
const [key, ...valueParts] = line.split('=');
|
|
22
|
+
if (key && valueParts.length > 0) {
|
|
23
|
+
let value = valueParts.join('=').trim();
|
|
24
|
+
// Remove quotes if present
|
|
25
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
26
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
27
|
+
value = value.slice(1, -1);
|
|
28
|
+
}
|
|
29
|
+
envVars[key.trim()] = value;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return envVars;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Configuration Service
|
|
36
|
+
* Provides type-safe access to environment variables
|
|
37
|
+
*/
|
|
38
|
+
export class ConfigService {
|
|
39
|
+
config;
|
|
40
|
+
constructor(options = {}) {
|
|
41
|
+
this.config = { ...options.defaults };
|
|
42
|
+
// Load environment variables from .env file
|
|
43
|
+
if (!options.ignoreEnvFile) {
|
|
44
|
+
const envPath = options.envFilePath || '.env';
|
|
45
|
+
const fullPath = path.resolve(process.cwd(), envPath);
|
|
46
|
+
const parsed = parseEnvFile(fullPath);
|
|
47
|
+
this.config = { ...this.config, ...parsed };
|
|
48
|
+
}
|
|
49
|
+
// Merge with process.env (already loaded by Studio)
|
|
50
|
+
this.config = { ...this.config, ...process.env };
|
|
51
|
+
// Validate if validator provided
|
|
52
|
+
if (options.validate && !options.validate(this.config)) {
|
|
53
|
+
throw new Error('Environment variable validation failed');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
get(key, defaultValue) {
|
|
57
|
+
const value = this.config[key];
|
|
58
|
+
if (value === undefined) {
|
|
59
|
+
return defaultValue;
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get a required configuration value
|
|
65
|
+
* Throws if not found
|
|
66
|
+
*/
|
|
67
|
+
getOrThrow(key) {
|
|
68
|
+
const value = this.get(key);
|
|
69
|
+
if (value === undefined) {
|
|
70
|
+
throw new Error(`Configuration key "${key}" is required but not found`);
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get all configuration
|
|
76
|
+
*/
|
|
77
|
+
getAll() {
|
|
78
|
+
return { ...this.config };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Configuration Module
|
|
83
|
+
* NestJS-style configuration management
|
|
84
|
+
*/
|
|
85
|
+
export class ConfigModule {
|
|
86
|
+
static forRoot(options = {}) {
|
|
87
|
+
const configService = new ConfigService(options);
|
|
88
|
+
return {
|
|
89
|
+
providers: [configService],
|
|
90
|
+
exports: [ConfigService],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=config-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-module.js","sourceRoot":"","sources":["../../src/core/config-module.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AA2B7B;;;GAGG;AACH,SAAS,YAAY,CAAC,QAAgB;IACpC,MAAM,OAAO,GAA2B,EAAE,CAAC;IAE3C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEnD,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACjC,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEnB,gCAAgC;QAChC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAClC,OAAO;QACT,CAAC;QAED,kBAAkB;QAClB,MAAM,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7C,IAAI,GAAG,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACjC,IAAI,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;YAExC,2BAA2B;YAC3B,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBAC9C,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CA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C;QAC/B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,YAAY,CAAC;QACtB,CAAC;QACD,OAAO,KAAU,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,UAAU,CAAa,GAAW;QAChC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAI,GAAG,CAAC,CAAC;QAC/B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,6BAA6B,CAAC,CAAC;QAC1E,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,OAAO,CAAC,UAA+B,EAAE;QAI9C,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;QAEjD,OAAO;YACL,SAAS,EAAE,CAAC,aAAa,CAAC;YAC1B,OAAO,EAAE,CAAC,aAAa,CAAC;SACzB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
/**
|
|
3
|
+
* Cache options
|
|
4
|
+
*/
|
|
5
|
+
export interface CacheOptions {
|
|
6
|
+
/** Time to live in seconds */
|
|
7
|
+
ttl: number;
|
|
8
|
+
/** Custom cache key generator */
|
|
9
|
+
key?: (input: any, context: any) => string;
|
|
10
|
+
/** Cache storage (default: in-memory) */
|
|
11
|
+
storage?: CacheStorage;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Cache storage interface
|
|
15
|
+
*/
|
|
16
|
+
export interface CacheStorage {
|
|
17
|
+
get(key: string): Promise<any> | any;
|
|
18
|
+
set(key: string, value: any, ttl: number): Promise<void> | void;
|
|
19
|
+
delete(key: string): Promise<void> | void;
|
|
20
|
+
clear(): Promise<void> | void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Default in-memory cache storage
|
|
24
|
+
*/
|
|
25
|
+
export declare class InMemoryCacheStorage implements CacheStorage {
|
|
26
|
+
private cache;
|
|
27
|
+
get(key: string): any;
|
|
28
|
+
set(key: string, value: any, ttl: number): void;
|
|
29
|
+
delete(key: string): void;
|
|
30
|
+
clear(): void;
|
|
31
|
+
private cleanup;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Cache decorator - caches tool results for a specified duration
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* @Tool({ name: 'get_products', ... })
|
|
39
|
+
* @Cache({ ttl: 300 }) // Cache for 5 minutes
|
|
40
|
+
* async getProducts(input: any) {
|
|
41
|
+
* return await this.database.query('SELECT * FROM products');
|
|
42
|
+
* }
|
|
43
|
+
*
|
|
44
|
+
* // With custom cache key
|
|
45
|
+
* @Cache({
|
|
46
|
+
* ttl: 300,
|
|
47
|
+
* key: (input) => `products:${input.category}`
|
|
48
|
+
* })
|
|
49
|
+
* async getProducts(input: any) { }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function Cache(options: CacheOptions): MethodDecorator;
|
|
53
|
+
/**
|
|
54
|
+
* Get cache options from metadata
|
|
55
|
+
*/
|
|
56
|
+
export declare function getCacheMetadata(target: any, propertyKey: string | symbol): CacheOptions | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Clear cache for a specific key or all keys
|
|
59
|
+
*/
|
|
60
|
+
export declare function clearCache(key?: string): Promise<void>;
|
|
61
|
+
//# sourceMappingURL=cache.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/cache.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAI1B;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B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