@nitrostack/core 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/LICENSE +201 -0
- package/README.md +80 -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 +31 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +46 -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/secure-secret.d.ts +136 -0
- package/dist/auth/secure-secret.d.ts.map +1 -0
- package/dist/auth/secure-secret.js +182 -0
- package/dist/auth/secure-secret.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 +174 -0
- package/dist/auth/simple-jwt.d.ts.map +1 -0
- package/dist/auth/simple-jwt.js +162 -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 +59 -0
- package/dist/auth/token-validation.d.ts.map +1 -0
- package/dist/auth/token-validation.js +241 -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/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 +59 -0
- package/dist/core/app-decorator.d.ts.map +1 -0
- package/dist/core/app-decorator.js +322 -0
- package/dist/core/app-decorator.js.map +1 -0
- package/dist/core/builders.d.ts +50 -0
- package/dist/core/builders.d.ts.map +1 -0
- package/dist/core/builders.js +139 -0
- package/dist/core/builders.js.map +1 -0
- package/dist/core/component.d.ts +111 -0
- package/dist/core/component.d.ts.map +1 -0
- package/dist/core/component.js +228 -0
- package/dist/core/component.js.map +1 -0
- package/dist/core/config-module.d.ts +62 -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 +63 -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 +190 -0
- package/dist/core/decorators.d.ts.map +1 -0
- package/dist/core/decorators.js +170 -0
- package/dist/core/decorators.js.map +1 -0
- package/dist/core/di/container.d.ts +64 -0
- package/dist/core/di/container.d.ts.map +1 -0
- package/dist/core/di/container.js +105 -0
- package/dist/core/di/container.js.map +1 -0
- package/dist/core/di/injectable.decorator.d.ts +62 -0
- package/dist/core/di/injectable.decorator.d.ts.map +1 -0
- package/dist/core/di/injectable.decorator.js +66 -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 +72 -0
- package/dist/core/events/event.decorator.js.map +1 -0
- package/dist/core/events/log-emitter.d.ts +14 -0
- package/dist/core/events/log-emitter.d.ts.map +1 -0
- package/dist/core/events/log-emitter.js +20 -0
- package/dist/core/events/log-emitter.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 +39 -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 +57 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +59 -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 +53 -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 +93 -0
- package/dist/core/module.d.ts.map +1 -0
- package/dist/core/module.js +87 -0
- package/dist/core/module.js.map +1 -0
- package/dist/core/oauth-module.d.ts +123 -0
- package/dist/core/oauth-module.d.ts.map +1 -0
- package/dist/core/oauth-module.js +324 -0
- package/dist/core/oauth-module.js.map +1 -0
- package/dist/core/pipes/pipe.decorator.d.ts +64 -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 +41 -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 +46 -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 +47 -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 +129 -0
- package/dist/core/server.d.ts.map +1 -0
- package/dist/core/server.js +617 -0
- package/dist/core/server.js.map +1 -0
- package/dist/core/tool.d.ts +108 -0
- package/dist/core/tool.d.ts.map +1 -0
- package/dist/core/tool.js +241 -0
- package/dist/core/tool.js.map +1 -0
- package/dist/core/transports/discovery-http-server.d.ts +19 -0
- package/dist/core/transports/discovery-http-server.d.ts.map +1 -0
- package/dist/core/transports/discovery-http-server.js +54 -0
- package/dist/core/transports/discovery-http-server.js.map +1 -0
- package/dist/core/transports/http-server.d.ts +108 -0
- package/dist/core/transports/http-server.d.ts.map +1 -0
- package/dist/core/transports/http-server.js +293 -0
- package/dist/core/transports/http-server.js.map +1 -0
- package/dist/core/transports/streamable-http.d.ts +177 -0
- package/dist/core/transports/streamable-http.d.ts.map +1 -0
- package/dist/core/transports/streamable-http.js +1287 -0
- package/dist/core/transports/streamable-http.js.map +1 -0
- package/dist/core/types.d.ts +195 -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 +103 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +161 -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/package.json +89 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ExecutionContext } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Component metadata for UI rendering
|
|
4
|
+
*/
|
|
5
|
+
export 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, unknown>;
|
|
31
|
+
/** Internal metadata (not exposed to MCP) */
|
|
32
|
+
_meta?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Component definition
|
|
36
|
+
*/
|
|
37
|
+
export interface ComponentDefinition extends ComponentMetadata {
|
|
38
|
+
/** Data transformation function for structuredContent */
|
|
39
|
+
transformer?: (data: unknown, context: ExecutionContext) => unknown;
|
|
40
|
+
/** Data transformation function for _meta (widget state) */
|
|
41
|
+
metaTransformer?: (data: unknown, context: ExecutionContext) => unknown;
|
|
42
|
+
/** Component initialization logic */
|
|
43
|
+
onInit?: (context: ExecutionContext) => void | Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Component class for defining UI components
|
|
47
|
+
*/
|
|
48
|
+
export declare class Component {
|
|
49
|
+
private definition;
|
|
50
|
+
private compiled;
|
|
51
|
+
private bundle;
|
|
52
|
+
constructor(definition: ComponentDefinition);
|
|
53
|
+
private validateDefinition;
|
|
54
|
+
/**
|
|
55
|
+
* Get component ID
|
|
56
|
+
*/
|
|
57
|
+
get id(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Get component name
|
|
60
|
+
*/
|
|
61
|
+
get name(): string;
|
|
62
|
+
/**
|
|
63
|
+
* Get component description
|
|
64
|
+
*/
|
|
65
|
+
get description(): string | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Compile component bundle
|
|
68
|
+
*/
|
|
69
|
+
compile(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Get compiled bundle as HTML document
|
|
72
|
+
*/
|
|
73
|
+
getBundle(): string;
|
|
74
|
+
/**
|
|
75
|
+
* Get component URI for resource registration
|
|
76
|
+
*/
|
|
77
|
+
getResourceUri(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Check if component is in dev mode
|
|
80
|
+
*/
|
|
81
|
+
isDevMode(): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Get dev URL if in dev mode
|
|
84
|
+
*/
|
|
85
|
+
getDevUrl(): string | null;
|
|
86
|
+
/**
|
|
87
|
+
* Transform data for component
|
|
88
|
+
*/
|
|
89
|
+
transformData(data: unknown, context: ExecutionContext): Promise<unknown>;
|
|
90
|
+
/**
|
|
91
|
+
* Get widget metadata (state)
|
|
92
|
+
*/
|
|
93
|
+
getWidgetMeta(data: unknown, context: ExecutionContext): Promise<unknown>;
|
|
94
|
+
/**
|
|
95
|
+
* Get provider-specific metadata
|
|
96
|
+
*/
|
|
97
|
+
getProviderMetadata(provider: 'openai' | 'anthropic' | 'generic'): Record<string, unknown>;
|
|
98
|
+
/**
|
|
99
|
+
* Get resource metadata for MCP
|
|
100
|
+
*/
|
|
101
|
+
getResourceMetadata(): Record<string, unknown>;
|
|
102
|
+
/**
|
|
103
|
+
* Initialize component
|
|
104
|
+
*/
|
|
105
|
+
initialize(context: ExecutionContext): Promise<void>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Helper function to create a component
|
|
109
|
+
*/
|
|
110
|
+
export declare function createComponent(definition: ComponentDefinition): Component;
|
|
111
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @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@@
|
|
|
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
|
+
// HTML is required unless we are in dev mode or using static exports
|
|
20
|
+
if (!this.definition.html && !this.definition._meta?.devMode) {
|
|
21
|
+
// We'll check for static files during compile
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get component ID
|
|
26
|
+
*/
|
|
27
|
+
get id() {
|
|
28
|
+
return this.definition.id;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get component name
|
|
32
|
+
*/
|
|
33
|
+
get name() {
|
|
34
|
+
return this.definition.name;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get component description
|
|
38
|
+
*/
|
|
39
|
+
get description() {
|
|
40
|
+
return this.definition.description;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Compile component bundle
|
|
44
|
+
*/
|
|
45
|
+
async compile() {
|
|
46
|
+
if (this.compiled)
|
|
47
|
+
return;
|
|
48
|
+
// Check if we should load from static export (esbuild output)
|
|
49
|
+
// We assume the widgets are built to src/widgets/out
|
|
50
|
+
// and the file name corresponds to the component ID (e.g. id="weather" -> weather.html)
|
|
51
|
+
const fs = await import('fs');
|
|
52
|
+
const path = await import('path');
|
|
53
|
+
const widgetsOutDir = path.resolve(process.cwd(), 'src/widgets/out');
|
|
54
|
+
// Try exact ID first
|
|
55
|
+
let componentHtmlPath = path.join(widgetsOutDir, `${this.id}.html`);
|
|
56
|
+
// If not found and ID starts with 'next-', try without the prefix
|
|
57
|
+
// This handles the case where createComponentFromNextRoute adds 'next-' prefix
|
|
58
|
+
// but the actual file is named without it (e.g., calculator-result.html)
|
|
59
|
+
if (!fs.existsSync(componentHtmlPath) && this.id.startsWith('next-')) {
|
|
60
|
+
const idWithoutPrefix = this.id.substring(5); // Remove 'next-' prefix
|
|
61
|
+
componentHtmlPath = path.join(widgetsOutDir, `${idWithoutPrefix}.html`);
|
|
62
|
+
}
|
|
63
|
+
if (fs.existsSync(componentHtmlPath)) {
|
|
64
|
+
try {
|
|
65
|
+
// The esbuild bundler already creates self-contained HTML files
|
|
66
|
+
// with all JavaScript and CSS inlined, so we just read the file
|
|
67
|
+
const htmlContent = fs.readFileSync(componentHtmlPath, 'utf-8');
|
|
68
|
+
this.bundle = {
|
|
69
|
+
html: htmlContent
|
|
70
|
+
};
|
|
71
|
+
this.compiled = true;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
console.warn(`Failed to read widget file for ${this.id}:`, err);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Fallback to inline definition
|
|
79
|
+
this.bundle = {
|
|
80
|
+
html: this.definition.html || '',
|
|
81
|
+
css: this.definition.css,
|
|
82
|
+
js: this.definition.js,
|
|
83
|
+
};
|
|
84
|
+
if (!this.bundle.html && !this.definition._meta?.devMode) {
|
|
85
|
+
console.warn(`Warning: Component ${this.id} has no HTML content and no static file found at ${componentHtmlPath}`);
|
|
86
|
+
}
|
|
87
|
+
this.compiled = true;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get compiled bundle as HTML document
|
|
91
|
+
*/
|
|
92
|
+
getBundle() {
|
|
93
|
+
if (!this.compiled) {
|
|
94
|
+
throw new Error('Component not compiled. Call compile() first.');
|
|
95
|
+
}
|
|
96
|
+
const cssTag = this.bundle.css
|
|
97
|
+
? `<style>${this.bundle.css}</style>`
|
|
98
|
+
: '';
|
|
99
|
+
const jsTag = this.bundle.js
|
|
100
|
+
? `<script type="module">${this.bundle.js}</script>`
|
|
101
|
+
: '';
|
|
102
|
+
return `
|
|
103
|
+
${this.bundle.html}
|
|
104
|
+
${cssTag}
|
|
105
|
+
${jsTag}
|
|
106
|
+
`.trim();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get component URI for resource registration
|
|
110
|
+
*/
|
|
111
|
+
getResourceUri() {
|
|
112
|
+
// In dev mode, return the dev URL if available
|
|
113
|
+
if (this.definition._meta?.devMode && this.definition._meta?.devUrl) {
|
|
114
|
+
return String(this.definition._meta.devUrl);
|
|
115
|
+
}
|
|
116
|
+
return `ui://widget/${this.definition.id}.html`;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Check if component is in dev mode
|
|
120
|
+
*/
|
|
121
|
+
isDevMode() {
|
|
122
|
+
return this.definition._meta?.devMode === true;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get dev URL if in dev mode
|
|
126
|
+
*/
|
|
127
|
+
getDevUrl() {
|
|
128
|
+
const devUrl = this.definition._meta?.devUrl;
|
|
129
|
+
return devUrl ? String(devUrl) : null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Transform data for component
|
|
133
|
+
*/
|
|
134
|
+
async transformData(data, context) {
|
|
135
|
+
if (this.definition.transformer) {
|
|
136
|
+
return await this.definition.transformer(data, context);
|
|
137
|
+
}
|
|
138
|
+
return data;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get widget metadata (state)
|
|
142
|
+
*/
|
|
143
|
+
async getWidgetMeta(data, context) {
|
|
144
|
+
if (this.definition.metaTransformer) {
|
|
145
|
+
return await this.definition.metaTransformer(data, context);
|
|
146
|
+
}
|
|
147
|
+
// Default: return empty object or maybe the data itself if appropriate?
|
|
148
|
+
// For now, let's return null so the server knows there's no specific meta
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get provider-specific metadata
|
|
153
|
+
*/
|
|
154
|
+
getProviderMetadata(provider) {
|
|
155
|
+
const metadata = {};
|
|
156
|
+
switch (provider) {
|
|
157
|
+
case 'openai':
|
|
158
|
+
metadata['openai/outputTemplate'] = this.getResourceUri();
|
|
159
|
+
metadata['openai/widgetAccessible'] = this.definition.canInvokeTools || false;
|
|
160
|
+
if (this.definition.description) {
|
|
161
|
+
metadata['openai/widgetDescription'] = this.definition.description;
|
|
162
|
+
}
|
|
163
|
+
if (this.definition.prefersBorder) {
|
|
164
|
+
metadata['openai/widgetPrefersBorder'] = true;
|
|
165
|
+
}
|
|
166
|
+
if (this.definition.subdomain) {
|
|
167
|
+
metadata['openai/widgetDomain'] = this.definition.subdomain;
|
|
168
|
+
}
|
|
169
|
+
if (this.definition.csp) {
|
|
170
|
+
metadata['openai/widgetCSP'] = {
|
|
171
|
+
connect_domains: this.definition.csp.connectDomains || [],
|
|
172
|
+
resource_domains: this.definition.csp.resourceDomains || [],
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
case 'anthropic':
|
|
177
|
+
// Future: Anthropic-specific metadata
|
|
178
|
+
metadata['anthropic/ui'] = this.getResourceUri();
|
|
179
|
+
break;
|
|
180
|
+
case 'generic':
|
|
181
|
+
default:
|
|
182
|
+
// Generic provider metadata
|
|
183
|
+
metadata['ui/template'] = this.getResourceUri();
|
|
184
|
+
metadata['ui/interactive'] = this.definition.canInvokeTools || false;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
// Merge with custom provider metadata
|
|
188
|
+
if (this.definition.providerMetadata) {
|
|
189
|
+
Object.assign(metadata, this.definition.providerMetadata);
|
|
190
|
+
}
|
|
191
|
+
return metadata;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get resource metadata for MCP
|
|
195
|
+
*/
|
|
196
|
+
getResourceMetadata() {
|
|
197
|
+
const metadata = {
|
|
198
|
+
mimeType: 'text/html',
|
|
199
|
+
};
|
|
200
|
+
// Add OpenAI-specific metadata
|
|
201
|
+
const openaiMeta = this.getProviderMetadata('openai');
|
|
202
|
+
if (openaiMeta['openai/widgetCSP']) {
|
|
203
|
+
metadata['openai/widgetCSP'] = openaiMeta['openai/widgetCSP'];
|
|
204
|
+
}
|
|
205
|
+
if (openaiMeta['openai/widgetDescription']) {
|
|
206
|
+
metadata['openai/widgetDescription'] = openaiMeta['openai/widgetDescription'];
|
|
207
|
+
}
|
|
208
|
+
if (openaiMeta['openai/widgetPrefersBorder']) {
|
|
209
|
+
metadata['openai/widgetPrefersBorder'] = openaiMeta['openai/widgetPrefersBorder'];
|
|
210
|
+
}
|
|
211
|
+
return metadata;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Initialize component
|
|
215
|
+
*/
|
|
216
|
+
async initialize(context) {
|
|
217
|
+
if (this.definition.onInit) {
|
|
218
|
+
await this.definition.onInit(context);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Helper function to create a component
|
|
224
|
+
*/
|
|
225
|
+
export function createComponent(definition) {
|
|
226
|
+
return new Component(definition);
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/core/component.ts"],"names":[],"mappings":"AA4DA;;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,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C,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,62 @@
|
|
|
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
|
+
* Dynamic module result type
|
|
47
|
+
*/
|
|
48
|
+
export interface DynamicModuleResult {
|
|
49
|
+
providers: Array<{
|
|
50
|
+
provide: any;
|
|
51
|
+
useValue: unknown;
|
|
52
|
+
}>;
|
|
53
|
+
exports: any[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Configuration Module
|
|
57
|
+
* NestJS-style configuration management
|
|
58
|
+
*/
|
|
59
|
+
export declare class ConfigModule {
|
|
60
|
+
static forRoot(options?: ConfigModuleOptions): DynamicModuleResult;
|
|
61
|
+
}
|
|
62
|
+
//# 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;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAElC,SAAS,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,GAAG,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAEtD,OAAO,EAAE,GAAG,EAAE,CAAC;CAChB;AAED;;;GAGG;AACH,qBAAa,YAAY;IACvB,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,mBAAwB,GAAG,mBAAmB;CAQvE"}
|
|
@@ -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: [{ provide: ConfigService, useValue: 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,M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
7
|
+
ttl: number;
|
|
8
|
+
/** Custom cache key generator */
|
|
9
|
+
key?: (input: unknown, context: unknown) => 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<unknown> | unknown;
|
|
18
|
+
set(key: string, value: unknown, 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): unknown;
|
|
28
|
+
set(key: string, value: unknown, 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: unknown) {
|
|
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 as {category: string}).category}`
|
|
48
|
+
* })
|
|
49
|
+
* async getProducts(input: unknown) { }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function Cache(options: CacheOptions): MethodDecorator;
|
|
53
|
+
/**
|
|
54
|
+
* Get cache options from metadata
|
|
55
|
+
*/
|
|
56
|
+
export declare function getCacheMetadata(target: object, 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,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IAEZ,iCAAiC;IACjC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC;IAEnD,yCAAyC;IACzC,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAC7C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACpE,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC/B;AAED;;GAEG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACvD,OAAO,CAAC,KAAK,CAA0D;IAEvE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAYzB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAOnD,MAAM,CAAC,GA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