@happyvertical/smrt-core 0.40.60 → 0.40.61
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/generated-client-runtime.d.ts +6 -5
- package/dist/generated-client-runtime.d.ts.map +1 -1
- package/dist/generated-client-runtime.js +49 -14
- package/dist/generated-client-runtime.js.map +1 -1
- package/dist/generators/index.d.ts +3 -2
- package/dist/generators/index.d.ts.map +1 -1
- package/dist/generators/index.js +3 -2
- package/dist/generators/mcp-runtime-template.d.ts +5 -0
- package/dist/generators/mcp-runtime-template.d.ts.map +1 -1
- package/dist/generators/mcp-runtime-template.js +9 -2
- package/dist/generators/mcp-runtime-template.js.map +1 -1
- package/dist/generators/mcp.d.ts +47 -0
- package/dist/generators/mcp.d.ts.map +1 -1
- package/dist/generators/mcp.js +64 -11
- package/dist/generators/mcp.js.map +1 -1
- package/dist/generators/rest.d.ts.map +1 -1
- package/dist/generators/rest.js +3 -0
- package/dist/generators/rest.js.map +1 -1
- package/dist/generators/typed-http-error.d.ts +16 -0
- package/dist/generators/typed-http-error.d.ts.map +1 -0
- package/dist/generators/typed-http-error.js +17 -0
- package/dist/generators/typed-http-error.js.map +1 -0
- package/dist/generators.js +3 -2
- package/dist/index.js +3 -2
- package/dist/manifest/static-manifest.js +1 -1
- package/dist/manifest/static-manifest.js.map +1 -1
- package/dist/manifest/store.js +1 -1
- package/dist/manifest.json +1 -1
- package/dist/prebuild/index.d.ts.map +1 -1
- package/dist/prebuild/index.js +13 -1
- package/dist/prebuild/index.js.map +1 -1
- package/dist/registry/types.d.ts +15 -0
- package/dist/registry/types.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +3 -3
- package/dist/vite-plugin/index.d.ts +2 -0
- package/dist/vite-plugin/index.d.ts.map +1 -1
- package/dist/vite-plugin/index.js +24 -11
- package/dist/vite-plugin/index.js.map +1 -1
- package/dist/vite-plugin/sveltekit-generator.d.ts.map +1 -1
- package/dist/vite-plugin/sveltekit-generator.js +94 -26
- package/dist/vite-plugin/sveltekit-generator.js.map +1 -1
- package/dist/vite-plugin/web-collections.d.ts +1 -0
- package/dist/vite-plugin/web-collections.d.ts.map +1 -1
- package/dist/vite-plugin/web-collections.js +17 -2
- package/dist/vite-plugin/web-collections.js.map +1 -1
- package/package.json +5 -5
- package/dist/manifest/test-manifest-loader.d.ts +0 -3
- package/dist/manifest/test-manifest-loader.d.ts.map +0 -1
- package/dist/manifest/test-manifest-stub.d.ts +0 -4
- package/dist/manifest/test-manifest-stub.d.ts.map +0 -1
- package/dist/manifest/test-manifest-stub.js +0 -77056
- package/dist/manifest/test-manifest-stub.js.map +0 -1
package/dist/generators/mcp.js
CHANGED
|
@@ -12,6 +12,27 @@ import { mkdir, writeFile } from "node:fs/promises";
|
|
|
12
12
|
*
|
|
13
13
|
* Exposes smrt objects as AI tools for Claude, GPT, and other AI models
|
|
14
14
|
*/
|
|
15
|
+
var MCP_STABLE_CATALOG_TTL_MS = 864e5;
|
|
16
|
+
/**
|
|
17
|
+
* Resolve the generated tools/list cache policy at generation time.
|
|
18
|
+
*
|
|
19
|
+
* A shared cache may otherwise serve one tenant's tool catalog to another, so
|
|
20
|
+
* public caching is deliberately double opt-in and unavailable when a
|
|
21
|
+
* generated server exposes any tenant-scoped object.
|
|
22
|
+
*/
|
|
23
|
+
function resolveMCPToolListCacheHint(options, hasTenantScopedTools) {
|
|
24
|
+
const ttlMs = options?.ttlMs ?? 864e5;
|
|
25
|
+
if (!Number.isSafeInteger(ttlMs) || ttlMs < 0) throw new RangeError("MCP tools/list cache ttlMs must be a non-negative safe integer.");
|
|
26
|
+
if (options?.cacheScope !== void 0 && options.cacheScope !== "private" && options.cacheScope !== "public") throw new RangeError("MCP tools/list cacheScope must be 'private' or 'public'.");
|
|
27
|
+
return {
|
|
28
|
+
ttlMs,
|
|
29
|
+
cacheScope: !hasTenantScopedTools && options?.cacheScope === "public" && options.publicCatalog === true ? "public" : "private"
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Return a copied, canonical tool sequence for byte-stable tools/list output. */
|
|
33
|
+
function sortMCPTools(tools) {
|
|
34
|
+
return [...tools].sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
35
|
+
}
|
|
15
36
|
var CustomActionFailureError = class extends Error {
|
|
16
37
|
failure;
|
|
17
38
|
constructor(failure) {
|
|
@@ -84,7 +105,7 @@ var MCPGenerator = class {
|
|
|
84
105
|
const objectTools = await this.generateObjectTools(simpleName, shouldInclude);
|
|
85
106
|
tools.push(...objectTools);
|
|
86
107
|
}
|
|
87
|
-
return tools;
|
|
108
|
+
return sortMCPTools(tools);
|
|
88
109
|
}
|
|
89
110
|
/**
|
|
90
111
|
* Generate tools for a specific object
|
|
@@ -609,6 +630,29 @@ var MCPGenerator = class {
|
|
|
609
630
|
return Array.from(scoped);
|
|
610
631
|
}
|
|
611
632
|
/**
|
|
633
|
+
* Whether a catalog contains a tenant-scoped class for cache isolation.
|
|
634
|
+
*
|
|
635
|
+
* Unlike the emitted runtime tenant gate, cache visibility must also fail
|
|
636
|
+
* closed for core-declared `@smrt({ tenantScoped })` models when the optional
|
|
637
|
+
* tenancy package is not installed. The registry covers that form, while
|
|
638
|
+
* `tenantScopedObjectNames()` covers the tenancy-owned decorator form.
|
|
639
|
+
*/
|
|
640
|
+
async hasTenantScopedTools(tools) {
|
|
641
|
+
if ((await this.tenantScopedObjectNames(tools)).length > 0) return true;
|
|
642
|
+
for (const tool of tools) {
|
|
643
|
+
const [objectName] = tool.name.split("_");
|
|
644
|
+
if (!objectName) continue;
|
|
645
|
+
for (const [key, info] of ObjectRegistry.getAllClasses()) {
|
|
646
|
+
const simpleName = info.name || key;
|
|
647
|
+
if (simpleName.toLowerCase() === objectName.toLowerCase()) {
|
|
648
|
+
if (ObjectRegistry.isTenantScoped(simpleName)) return true;
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
612
656
|
* Execute a resolved MCP action (CRUD or custom) against a collection. Always
|
|
613
657
|
* invoked inside the tenant gate established by {@link executeAction}.
|
|
614
658
|
*/
|
|
@@ -765,6 +809,8 @@ var MCPGenerator = class {
|
|
|
765
809
|
if (modular) await this.generateModularServer(outputDir, serverName, serverVersion, debug);
|
|
766
810
|
else {
|
|
767
811
|
const tools = await this.generateTools();
|
|
812
|
+
const tenantScopedObjects = await this.tenantScopedObjectNames(tools);
|
|
813
|
+
const hasTenantScopedTools = tenantScopedObjects.length > 0 || await this.hasTenantScopedTools(tools);
|
|
768
814
|
await writeFile(resolvedPath, generateRuntimeBootstrap({
|
|
769
815
|
name: serverName,
|
|
770
816
|
version: serverVersion,
|
|
@@ -774,8 +820,9 @@ var MCPGenerator = class {
|
|
|
774
820
|
debug,
|
|
775
821
|
tools,
|
|
776
822
|
customActions: await this.runtimeCustomActions(tools),
|
|
777
|
-
tenantScopedObjects
|
|
778
|
-
stiTargets: this.runtimeStiTargets(tools)
|
|
823
|
+
tenantScopedObjects,
|
|
824
|
+
stiTargets: this.runtimeStiTargets(tools),
|
|
825
|
+
toolListCacheHint: resolveMCPToolListCacheHint(this.config.cache?.toolsList, hasTenantScopedTools)
|
|
779
826
|
}), "utf-8");
|
|
780
827
|
console.log(`✅ Generated MCP server: ${resolvedPath}`);
|
|
781
828
|
}
|
|
@@ -871,15 +918,17 @@ var MCPGenerator = class {
|
|
|
871
918
|
const configPath = resolve(outputDir, "config.ts");
|
|
872
919
|
await writeFile(configPath, this.generateConfigFile(serverName, serverVersion, debug), "utf-8");
|
|
873
920
|
console.log(`✅ Generated config: ${configPath}`);
|
|
921
|
+
const generatedTools = await this.generateTools();
|
|
874
922
|
const toolsPath = resolve(toolsDir, "index.ts");
|
|
875
|
-
await writeFile(toolsPath,
|
|
923
|
+
await writeFile(toolsPath, this.generateToolsFile(generatedTools), "utf-8");
|
|
876
924
|
console.log(`✅ Generated tools: ${toolsPath}`);
|
|
877
925
|
const handlersPath = resolve(handlersDir, "index.ts");
|
|
878
|
-
const tenantScopedObjects = await this.tenantScopedObjectNames(
|
|
926
|
+
const tenantScopedObjects = await this.tenantScopedObjectNames(generatedTools);
|
|
927
|
+
const hasTenantScopedTools = tenantScopedObjects.length > 0 || await this.hasTenantScopedTools(generatedTools);
|
|
879
928
|
await writeFile(handlersPath, await this.generateHandlersFile(tenantScopedObjects), "utf-8");
|
|
880
929
|
console.log(`✅ Generated handlers: ${handlersPath}`);
|
|
881
930
|
const indexPath = resolve(outputDir, "index.js");
|
|
882
|
-
await writeFile(indexPath, this.generateModularIndex(), "utf-8");
|
|
931
|
+
await writeFile(indexPath, this.generateModularIndex(resolveMCPToolListCacheHint(this.config.cache?.toolsList, hasTenantScopedTools)), "utf-8");
|
|
883
932
|
console.log(`✅ Generated MCP server: ${indexPath}`);
|
|
884
933
|
}
|
|
885
934
|
/**
|
|
@@ -900,8 +949,7 @@ export const DEBUG = ${debug};
|
|
|
900
949
|
/**
|
|
901
950
|
* Generate tools definitions file for modular server
|
|
902
951
|
*/
|
|
903
|
-
|
|
904
|
-
const tools = await this.generateTools();
|
|
952
|
+
generateToolsFile(tools) {
|
|
905
953
|
return `/**
|
|
906
954
|
* MCP Tools Definitions
|
|
907
955
|
* Auto-generated from SMRT objects
|
|
@@ -1243,7 +1291,7 @@ ${hasTenantScoped ? `
|
|
|
1243
1291
|
/**
|
|
1244
1292
|
* Generate modular index file (main entry point)
|
|
1245
1293
|
*/
|
|
1246
|
-
generateModularIndex() {
|
|
1294
|
+
generateModularIndex(toolListCacheHint) {
|
|
1247
1295
|
return `#!/usr/bin/env node
|
|
1248
1296
|
/**
|
|
1249
1297
|
* Auto-generated MCP Server
|
|
@@ -1266,6 +1314,8 @@ import { SERVER_NAME, SERVER_VERSION, DEBUG } from './config.js';
|
|
|
1266
1314
|
import { tools } from './tools/index.js';
|
|
1267
1315
|
import { handleToolCall } from './handlers/index.js';
|
|
1268
1316
|
|
|
1317
|
+
const TOOL_LIST_CACHE_HINT = ${JSON.stringify(toolListCacheHint)};
|
|
1318
|
+
|
|
1269
1319
|
/**
|
|
1270
1320
|
* Main server startup function
|
|
1271
1321
|
*/
|
|
@@ -1300,6 +1350,9 @@ export async function createServer() {
|
|
|
1300
1350
|
capabilities: {
|
|
1301
1351
|
tools: {},
|
|
1302
1352
|
},
|
|
1353
|
+
cacheHints: {
|
|
1354
|
+
'tools/list': TOOL_LIST_CACHE_HINT,
|
|
1355
|
+
},
|
|
1303
1356
|
}
|
|
1304
1357
|
);
|
|
1305
1358
|
|
|
@@ -1310,7 +1363,7 @@ export async function createServer() {
|
|
|
1310
1363
|
}
|
|
1311
1364
|
|
|
1312
1365
|
return {
|
|
1313
|
-
tools: tools.map(tool => ({
|
|
1366
|
+
tools: [...tools].sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0).map(tool => ({
|
|
1314
1367
|
name: tool.name,
|
|
1315
1368
|
description: tool.description,
|
|
1316
1369
|
inputSchema: tool.inputSchema,
|
|
@@ -1362,6 +1415,6 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
|
|
1362
1415
|
}
|
|
1363
1416
|
};
|
|
1364
1417
|
//#endregion
|
|
1365
|
-
export { MCPGenerator };
|
|
1418
|
+
export { MCPGenerator, MCP_STABLE_CATALOG_TTL_MS, resolveMCPToolListCacheHint, sortMCPTools };
|
|
1366
1419
|
|
|
1367
1420
|
//# sourceMappingURL=mcp.js.map
|