@happyvertical/smrt-core 0.54.1 → 0.54.3
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/AGENTS.md +6 -1
- package/README.md +8 -0
- package/agents/change-feed.md +7 -12
- package/agents/generators.md +13 -0
- package/agents/object-runtime.md +8 -0
- package/agents/schema-paths.md +14 -0
- package/dist/audit-context.d.ts +4 -0
- package/dist/audit-context.d.ts.map +1 -0
- package/dist/audit-context.js +16 -0
- package/dist/audit-context.js.map +1 -0
- package/dist/audit.d.ts +34 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +63 -0
- package/dist/audit.js.map +1 -0
- package/dist/browser.d.ts +2 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +4 -3
- package/dist/cascade.d.ts +1 -1
- package/dist/cascade.d.ts.map +1 -1
- package/dist/cascade.js +10 -7
- package/dist/cascade.js.map +1 -1
- package/dist/change-feed.js +1 -1
- package/dist/collection.d.ts +9 -2
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +59 -4
- package/dist/collection.js.map +1 -1
- package/dist/embedded-write-queue.d.ts +2 -0
- package/dist/embedded-write-queue.d.ts.map +1 -1
- package/dist/embedded-write-queue.js +12 -5
- package/dist/embedded-write-queue.js.map +1 -1
- package/dist/generators/changes-route.js +1 -1
- package/dist/generators/mcp-runtime-template.d.ts +2 -0
- package/dist/generators/mcp-runtime-template.d.ts.map +1 -1
- package/dist/generators/mcp-runtime-template.js +18 -16
- package/dist/generators/mcp-runtime-template.js.map +1 -1
- package/dist/generators/mcp-tool-name.d.ts +6 -0
- package/dist/generators/mcp-tool-name.d.ts.map +1 -1
- package/dist/generators/mcp-tool-name.js.map +1 -1
- package/dist/generators/mcp.d.ts +34 -1
- package/dist/generators/mcp.d.ts.map +1 -1
- package/dist/generators/mcp.js +148 -110
- package/dist/generators/mcp.js.map +1 -1
- package/dist/generators/rest.d.ts.map +1 -1
- package/dist/generators/rest.js +16 -7
- package/dist/generators/rest.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/junction.d.ts +29 -10
- package/dist/junction.d.ts.map +1 -1
- package/dist/junction.js +31 -12
- package/dist/junction.js.map +1 -1
- package/dist/knowledge.js +1 -1
- package/dist/knowledge.js.map +1 -1
- package/dist/manifest/manifest-loader.d.ts.map +1 -1
- package/dist/manifest/manifest-loader.js +1 -1
- package/dist/manifest/manifest-loader.js.map +1 -1
- package/dist/manifest/static-manifest.d.ts.map +1 -1
- package/dist/manifest/static-manifest.js +106 -9
- package/dist/manifest/static-manifest.js.map +1 -1
- package/dist/manifest/store.d.ts +8 -0
- package/dist/manifest/store.d.ts.map +1 -1
- package/dist/manifest/store.js +12 -2
- package/dist/manifest/store.js.map +1 -1
- package/dist/manifest.json +119 -9
- package/dist/migrations/differ.d.ts +3 -3
- package/dist/migrations/differ.d.ts.map +1 -1
- package/dist/migrations/differ.js +8 -4
- package/dist/migrations/differ.js.map +1 -1
- package/dist/object.d.ts +1 -0
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +19 -7
- package/dist/object.js.map +1 -1
- package/dist/registry/class-registration.d.ts.map +1 -1
- package/dist/registry/class-registration.js +75 -10
- package/dist/registry/class-registration.js.map +1 -1
- package/dist/registry/collection-resolution.d.ts +2 -2
- package/dist/registry/collection-resolution.d.ts.map +1 -1
- package/dist/registry/collection-resolution.js +2 -1
- package/dist/registry/collection-resolution.js.map +1 -1
- package/dist/registry/collision-policy.d.ts +8 -0
- package/dist/registry/collision-policy.d.ts.map +1 -1
- package/dist/registry/collision-policy.js +2 -2
- package/dist/registry/collision-policy.js.map +1 -1
- package/dist/registry/framework-base-classes.d.ts.map +1 -1
- package/dist/registry/framework-base-classes.js +2 -1
- package/dist/registry/framework-base-classes.js.map +1 -1
- package/dist/registry/schema-builder.d.ts.map +1 -1
- package/dist/registry/schema-builder.js +33 -4
- package/dist/registry/schema-builder.js.map +1 -1
- package/dist/registry/shared-state.d.ts +6 -0
- package/dist/registry/shared-state.d.ts.map +1 -1
- package/dist/registry/shared-state.js +12 -1
- package/dist/registry/shared-state.js.map +1 -1
- package/dist/registry/types.d.ts +7 -1
- package/dist/registry/types.d.ts.map +1 -1
- package/dist/registry.d.ts +7 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +25 -3
- package/dist/registry.js.map +1 -1
- package/dist/scanner/manifest-generator.d.ts.map +1 -1
- package/dist/scanner/manifest-generator.js +5 -1
- package/dist/scanner/manifest-generator.js.map +1 -1
- package/dist/scanner/types.d.ts +8 -0
- package/dist/scanner/types.d.ts.map +1 -1
- package/dist/scanner/types.js.map +1 -1
- package/dist/schema/ddl/duckdb-strategy.d.ts.map +1 -1
- package/dist/schema/ddl/duckdb-strategy.js +1 -0
- package/dist/schema/ddl/duckdb-strategy.js.map +1 -1
- package/dist/schema/ddl/null-equal-index.d.ts.map +1 -1
- package/dist/schema/ddl/null-equal-index.js +4 -2
- package/dist/schema/ddl/null-equal-index.js.map +1 -1
- package/dist/schema/generator.d.ts +3 -0
- package/dist/schema/generator.d.ts.map +1 -1
- package/dist/schema/generator.js +38 -0
- package/dist/schema/generator.js.map +1 -1
- package/dist/smrt-knowledge.json +74 -20
- package/dist/sync/apply.d.ts +2 -0
- package/dist/sync/apply.d.ts.map +1 -1
- package/dist/sync/apply.js +7 -3
- package/dist/sync/apply.js.map +1 -1
- package/dist/utils/scanner-module.d.ts +9 -0
- package/dist/utils/scanner-module.d.ts.map +1 -1
- package/dist/vite-plugin/index.d.ts +14 -0
- package/dist/vite-plugin/index.d.ts.map +1 -1
- package/dist/vite-plugin/index.js +58 -18
- package/dist/vite-plugin/index.js.map +1 -1
- package/dist/vite-plugin/package-stamp.d.ts +41 -0
- package/dist/vite-plugin/package-stamp.d.ts.map +1 -0
- package/dist/vite-plugin/package-stamp.js +33 -0
- package/dist/vite-plugin/package-stamp.js.map +1 -0
- package/dist/vite-plugin/sveltekit-generator.js +5 -3
- package/dist/vite-plugin/sveltekit-generator.js.map +1 -1
- package/dist/vite-plugin/sync-apply-route.d.ts.map +1 -1
- package/dist/vite-plugin/sync-apply-route.js +10 -0
- package/dist/vite-plugin/sync-apply-route.js.map +1 -1
- package/dist/vite-plugin.js +2 -2
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/generators/mcp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/generators/mcp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgBH,OAAO,EAGL,KAAK,oBAAoB,EAQzB,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAC;AAiB5B,OAAO,EAOL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACL,yBAAyB,EACzB,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAqB1B;;;GAGG;AACH,KAAK,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AASxC,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE;QACN,SAAS,CAAC,EAAE,uBAAuB,CAAC;KACrC,CAAC;IACF,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAChC;AAED,eAAO,MAAM,yBAAyB,WAAa,CAAC;AAEpD,MAAM,WAAW,uBAAuB;IACtC,uFAAuF;IACvF,KAAK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p.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { buildDefaultListOrderBy, resolveListLimit, resolveListOffset } from "../query-bounds.js";
|
|
2
|
+
import { SmrtCollection } from "../collection.js";
|
|
3
|
+
import { isQualifiedName } from "../utils/qualified-names.js";
|
|
2
4
|
import { SMRT_CUSTOM_ACTION_ERROR_METADATA_KEY, buildCustomActionInvocationArgs, customActionParameterInputName, isCrudOperation, isCrudToolAction, isFrameworkLifecycleMethod, normalizeCustomActionFailure, resolveCustomActionMetadata } from "./custom-action.js";
|
|
3
5
|
import { isFrameworkBaseClass } from "../registry/framework-base-classes.js";
|
|
4
6
|
import { ObjectRegistry } from "../registry.js";
|
|
5
|
-
import { SmrtCollection } from "../collection.js";
|
|
6
7
|
import { generatedSiblingExtension, renderGeneratedSource, resolveGeneratedSourceLanguage } from "./mcp-emit.js";
|
|
7
8
|
import { generateClaudeConfig, generateMCPDocumentation, generateMCPScript, generateRuntimeBootstrap } from "./mcp-runtime-template.js";
|
|
8
9
|
import { canonicalMcpToolNames } from "./mcp-tool-name.js";
|
|
@@ -128,10 +129,12 @@ var MCPGenerator = class {
|
|
|
128
129
|
/** Return the validated source identity for a tool returned by this generator. */
|
|
129
130
|
getToolIdentity(tool) {
|
|
130
131
|
const target = this.toolTarget(tool);
|
|
132
|
+
const owner = this.toolClass(tool);
|
|
131
133
|
return {
|
|
132
134
|
objectName: target.objectName,
|
|
133
135
|
action: target.action,
|
|
134
|
-
originalName: target.originalName ?? tool.name
|
|
136
|
+
originalName: target.originalName ?? tool.name,
|
|
137
|
+
...owner ? { qualifiedName: owner.classInfo.qualifiedName ?? owner.key } : {}
|
|
135
138
|
};
|
|
136
139
|
}
|
|
137
140
|
runtimeToolTargets(tools) {
|
|
@@ -171,10 +174,15 @@ var MCPGenerator = class {
|
|
|
171
174
|
async generateTools() {
|
|
172
175
|
const tools = [];
|
|
173
176
|
const registeredClasses = ObjectRegistry.getAllClasses();
|
|
177
|
+
const scope = this.resolveClassScope(registeredClasses);
|
|
178
|
+
const generated = /* @__PURE__ */ new Set();
|
|
174
179
|
for (const [key, classInfo] of registeredClasses) {
|
|
175
180
|
const simpleName = classInfo.name || key;
|
|
181
|
+
if (generated.has(classInfo)) continue;
|
|
182
|
+
generated.add(classInfo);
|
|
183
|
+
if (scope && !scope.has(classInfo)) continue;
|
|
176
184
|
if (isFrameworkBaseClass(simpleName, classInfo.packageName)) continue;
|
|
177
|
-
const mcpConfig = ObjectRegistry.getConfig(
|
|
185
|
+
const mcpConfig = ObjectRegistry.getConfig(key).mcp;
|
|
178
186
|
if (mcpConfig === false) continue;
|
|
179
187
|
const excluded = typeof mcpConfig === "object" && mcpConfig?.exclude ? mcpConfig.exclude : [];
|
|
180
188
|
const included = typeof mcpConfig === "object" ? mcpConfig?.include : void 0;
|
|
@@ -183,7 +191,7 @@ var MCPGenerator = class {
|
|
|
183
191
|
if (excluded.includes(endpoint)) return false;
|
|
184
192
|
return true;
|
|
185
193
|
};
|
|
186
|
-
const objectTools = await this.generateObjectTools(simpleName, shouldInclude);
|
|
194
|
+
const objectTools = await this.generateObjectTools(simpleName, shouldInclude, key);
|
|
187
195
|
tools.push(...objectTools);
|
|
188
196
|
}
|
|
189
197
|
const names = canonicalMcpToolNames(tools.map((tool) => ({
|
|
@@ -196,44 +204,77 @@ var MCPGenerator = class {
|
|
|
196
204
|
return sortMCPTools(tools);
|
|
197
205
|
}
|
|
198
206
|
/**
|
|
199
|
-
*
|
|
207
|
+
* The registered classes `MCPConfig.classNames` selects, or undefined when
|
|
208
|
+
* unscoped. A qualified name selects exactly that registration; a simple
|
|
209
|
+
* name must match one class only, so the scope never picks one of several
|
|
210
|
+
* same-named classes on its own (#3490).
|
|
200
211
|
*/
|
|
201
|
-
|
|
212
|
+
resolveClassScope(classes) {
|
|
213
|
+
if (!this.config.classNames) return void 0;
|
|
214
|
+
const scope = /* @__PURE__ */ new Set();
|
|
215
|
+
for (const requested of this.config.classNames) {
|
|
216
|
+
const wanted = requested.toLowerCase();
|
|
217
|
+
const qualified = isQualifiedName(requested);
|
|
218
|
+
const matches = /* @__PURE__ */ new Set();
|
|
219
|
+
for (const [key, info] of classes) if ((qualified ? info.qualifiedName ?? key : info.name || key).toLowerCase() === wanted) matches.add(info);
|
|
220
|
+
if (matches.size > 1) {
|
|
221
|
+
const names = [...matches].map((info) => info.qualifiedName ?? info.name).sort().join(", ");
|
|
222
|
+
throw new Error(`MCP class scope '${requested}' is ambiguous: it matches ${names}. Scope it by qualified name.`);
|
|
223
|
+
}
|
|
224
|
+
for (const info of matches) scope.add(info);
|
|
225
|
+
}
|
|
226
|
+
return scope;
|
|
227
|
+
}
|
|
228
|
+
/** The registry key of the class a generated tool belongs to. */
|
|
229
|
+
toolClass(tool) {
|
|
230
|
+
const key = this.toolTargets.get(tool)?.registryKey;
|
|
231
|
+
const classInfo = key ? ObjectRegistry.getAllClasses().get(key) : void 0;
|
|
232
|
+
return key && classInfo ? {
|
|
233
|
+
key,
|
|
234
|
+
classInfo
|
|
235
|
+
} : void 0;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Generate tools for a specific object. `objectName` names the tools;
|
|
239
|
+
* `registryKey` (the class's registry key) resolves everything else.
|
|
240
|
+
*/
|
|
241
|
+
async generateObjectTools(displayName, shouldInclude, registryKey = displayName) {
|
|
242
|
+
const objectName = registryKey;
|
|
202
243
|
const tools = [];
|
|
203
244
|
const fields = ObjectRegistry.getFields(objectName);
|
|
204
|
-
const lowerName =
|
|
245
|
+
const lowerName = displayName.toLowerCase();
|
|
205
246
|
const classInfo = ObjectRegistry.getClass(objectName);
|
|
206
247
|
if (shouldInclude("list")) tools.push({
|
|
207
248
|
name: `${lowerName}_list`,
|
|
208
|
-
description: `List ${
|
|
249
|
+
description: `List ${displayName} objects with optional filtering`,
|
|
209
250
|
inputSchema: this.buildInputSchema(objectName, "list", fields),
|
|
210
251
|
outputSchema: this.buildOutputSchema(objectName, "list", fields),
|
|
211
252
|
annotations: mcpToolAnnotations("list")
|
|
212
253
|
});
|
|
213
254
|
if (shouldInclude("get")) tools.push({
|
|
214
255
|
name: `${lowerName}_get`,
|
|
215
|
-
description: `Get a specific ${
|
|
256
|
+
description: `Get a specific ${displayName} by ID or slug`,
|
|
216
257
|
inputSchema: this.buildInputSchema(objectName, "get", fields),
|
|
217
258
|
outputSchema: this.buildOutputSchema(objectName, "get", fields),
|
|
218
259
|
annotations: mcpToolAnnotations("get")
|
|
219
260
|
});
|
|
220
261
|
if (shouldInclude("create")) tools.push({
|
|
221
262
|
name: `${lowerName}_create`,
|
|
222
|
-
description: `Create a new ${
|
|
263
|
+
description: `Create a new ${displayName}`,
|
|
223
264
|
inputSchema: this.buildInputSchema(objectName, "create", fields),
|
|
224
265
|
outputSchema: this.buildOutputSchema(objectName, "create", fields),
|
|
225
266
|
annotations: mcpToolAnnotations("create")
|
|
226
267
|
});
|
|
227
268
|
if (shouldInclude("update")) tools.push({
|
|
228
269
|
name: `${lowerName}_update`,
|
|
229
|
-
description: `Update an existing ${
|
|
270
|
+
description: `Update an existing ${displayName}`,
|
|
230
271
|
inputSchema: this.buildInputSchema(objectName, "update", fields),
|
|
231
272
|
outputSchema: this.buildOutputSchema(objectName, "update", fields),
|
|
232
273
|
annotations: mcpToolAnnotations("update")
|
|
233
274
|
});
|
|
234
275
|
if (shouldInclude("delete")) tools.push({
|
|
235
276
|
name: `${lowerName}_delete`,
|
|
236
|
-
description: `Delete a ${
|
|
277
|
+
description: `Delete a ${displayName} by ID`,
|
|
237
278
|
inputSchema: this.buildInputSchema(objectName, "delete", fields),
|
|
238
279
|
outputSchema: this.buildOutputSchema(objectName, "delete", fields),
|
|
239
280
|
annotations: mcpToolAnnotations("delete")
|
|
@@ -245,7 +286,7 @@ var MCPGenerator = class {
|
|
|
245
286
|
const excludedLower = new Set(excluded.map((entry) => entry.toLowerCase()));
|
|
246
287
|
const customMethodsInInclude = included?.filter((item) => {
|
|
247
288
|
if (!isCrudToolAction(item)) return true;
|
|
248
|
-
if (!isCrudOperation(item)) console.warn(`Warning: MCP include entry '${item}' for ${
|
|
289
|
+
if (!isCrudOperation(item)) console.warn(`Warning: MCP include entry '${item}' for ${displayName} resolves to the reserved CRUD tool '${lowerName}_${item.toLowerCase()}' and was ignored; use '${item.toLowerCase()}' to expose that operation`);
|
|
249
290
|
return false;
|
|
250
291
|
}) || [];
|
|
251
292
|
const hasIncludeList = included !== void 0;
|
|
@@ -258,12 +299,12 @@ var MCPGenerator = class {
|
|
|
258
299
|
const existsInManifest = methodNames.has(methodName);
|
|
259
300
|
const existsOnClass = this.validateCustomMethod(classInfo.constructor, methodName);
|
|
260
301
|
if (!existsInManifest && !existsOnClass) {
|
|
261
|
-
console.warn(`Warning: Custom action '${methodName}' specified in MCP config for ${
|
|
302
|
+
console.warn(`Warning: Custom action '${methodName}' specified in MCP config for ${displayName}, but method ${methodName}() not found on class`);
|
|
262
303
|
continue;
|
|
263
304
|
}
|
|
264
305
|
const methodDef = methods.get(methodName);
|
|
265
306
|
if (methodDef && !methodDef.isPublic) continue;
|
|
266
|
-
const tool = this.buildCustomActionTool(
|
|
307
|
+
const tool = this.buildCustomActionTool(displayName, lowerName, methodName, methodDef, this.hasCollectionReceiver(classInfo), registryKey);
|
|
267
308
|
if (emittedToolNames.has(tool.name)) continue;
|
|
268
309
|
emittedToolNames.add(tool.name);
|
|
269
310
|
tools.push(tool);
|
|
@@ -273,26 +314,27 @@ var MCPGenerator = class {
|
|
|
273
314
|
if (isFrameworkLifecycleMethod(methodName)) continue;
|
|
274
315
|
if (!methodDef.isPublic) continue;
|
|
275
316
|
if (excludedLower.has(methodName.toLowerCase())) continue;
|
|
276
|
-
const tool = this.buildCustomActionTool(
|
|
317
|
+
const tool = this.buildCustomActionTool(displayName, lowerName, methodName, methodDef, this.hasCollectionReceiver(classInfo), registryKey);
|
|
277
318
|
if (emittedToolNames.has(tool.name)) continue;
|
|
278
319
|
emittedToolNames.add(tool.name);
|
|
279
320
|
tools.push(tool);
|
|
280
321
|
}
|
|
281
322
|
}
|
|
282
323
|
for (const tool of tools) this.toolTargets.set(tool, {
|
|
283
|
-
objectName,
|
|
324
|
+
objectName: displayName,
|
|
284
325
|
action: tool.name.slice(lowerName.length + 1),
|
|
285
|
-
originalName: tool.name
|
|
326
|
+
originalName: tool.name,
|
|
327
|
+
registryKey
|
|
286
328
|
});
|
|
287
329
|
return tools;
|
|
288
330
|
}
|
|
289
|
-
buildCustomActionTool(objectName, lowerName, methodName, methodDef, collectionReceiver = false) {
|
|
290
|
-
const metadata = this.resolveCustomActionMetadata(
|
|
331
|
+
buildCustomActionTool(objectName, lowerName, methodName, methodDef, collectionReceiver = false, registryKey = objectName) {
|
|
332
|
+
const metadata = this.resolveCustomActionMetadata(registryKey, methodName, methodDef, collectionReceiver);
|
|
291
333
|
return {
|
|
292
334
|
name: `${lowerName}_${methodName}`.toLowerCase(),
|
|
293
335
|
description: `Execute ${methodName} action on ${objectName}`,
|
|
294
|
-
inputSchema: this.buildInputSchema(
|
|
295
|
-
outputSchema: this.buildOutputSchema(
|
|
336
|
+
inputSchema: this.buildInputSchema(registryKey, methodName, ObjectRegistry.getFields(registryKey), metadata),
|
|
337
|
+
outputSchema: this.buildOutputSchema(registryKey, methodName, ObjectRegistry.getFields(registryKey)),
|
|
296
338
|
annotations: mcpToolAnnotations(methodName, metadata)
|
|
297
339
|
};
|
|
298
340
|
}
|
|
@@ -482,22 +524,31 @@ var MCPGenerator = class {
|
|
|
482
524
|
}
|
|
483
525
|
return properties;
|
|
484
526
|
}
|
|
527
|
+
/**
|
|
528
|
+
* The STI subtypes a create may select, each bound to its exact registry
|
|
529
|
+
* entry (`name` is its registry key). A subtype is the base itself or a
|
|
530
|
+
* class whose constructor descends from the base's, or — for manifest-only
|
|
531
|
+
* entries — whose inheritance chain names the base's qualified identity.
|
|
532
|
+
* Never resolved by simple name: two packages may declare same-named
|
|
533
|
+
* subtypes of one base (#3490).
|
|
534
|
+
*/
|
|
485
535
|
getStiVariants(objectName) {
|
|
486
536
|
if (ObjectRegistry.getTableStrategy(objectName) !== "sti") return [];
|
|
487
537
|
const base = ObjectRegistry.getClass(objectName);
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
base?.qualifiedName
|
|
492
|
-
].filter((name) => typeof name === "string"));
|
|
538
|
+
if (!base) return [];
|
|
539
|
+
const baseKeys = new Set([objectName, base.qualifiedName].filter((name) => typeof name === "string"));
|
|
540
|
+
const isStub = (info) => info.constructor._isManifestStub === true;
|
|
493
541
|
const variants = /* @__PURE__ */ new Map();
|
|
542
|
+
const seen = /* @__PURE__ */ new Set();
|
|
494
543
|
for (const [key, info] of ObjectRegistry.getAllClasses()) {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
544
|
+
if (seen.has(info)) continue;
|
|
545
|
+
seen.add(info);
|
|
546
|
+
if (!(info === base || !isStub(info) && !isStub(base) && info.constructor.prototype instanceof base.constructor || (isStub(info) || isStub(base)) && ObjectRegistry.getInheritanceChain(key).some((ancestor) => baseKeys.has(ancestor)))) continue;
|
|
547
|
+
const discriminator = info.qualifiedName || info.name || key;
|
|
498
548
|
variants.set(discriminator, {
|
|
499
|
-
name,
|
|
500
|
-
discriminator
|
|
549
|
+
name: key,
|
|
550
|
+
discriminator,
|
|
551
|
+
classInfo: info
|
|
501
552
|
});
|
|
502
553
|
}
|
|
503
554
|
return Array.from(variants.values()).sort((left, right) => left.discriminator.localeCompare(right.discriminator));
|
|
@@ -511,18 +562,9 @@ var MCPGenerator = class {
|
|
|
511
562
|
const tool = (await this.generateTools()).find((candidate) => candidate.name === name);
|
|
512
563
|
if (!tool) throw new Error(`Unknown tool: ${name}`);
|
|
513
564
|
const { objectName, action } = this.toolTarget(tool);
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
for (const [_key, info] of registeredClasses) {
|
|
518
|
-
const simpleName = info.name || _key;
|
|
519
|
-
if (simpleName.toLowerCase() === objectName.toLowerCase()) {
|
|
520
|
-
classInfo = info;
|
|
521
|
-
actualObjectName = simpleName;
|
|
522
|
-
break;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
if (!classInfo) throw new Error(`Object type '${objectName}' not found`);
|
|
565
|
+
const owner = this.toolClass(tool);
|
|
566
|
+
if (!owner) throw new Error(`Object type '${objectName}' not found`);
|
|
567
|
+
const { key: actualObjectName, classInfo } = owner;
|
|
526
568
|
const collection = await this.getCollection(actualObjectName, classInfo);
|
|
527
569
|
const result = await this.executeAction(collection, action, args, actualObjectName);
|
|
528
570
|
const publicResult = this.toJsonValue(result);
|
|
@@ -588,12 +630,11 @@ var MCPGenerator = class {
|
|
|
588
630
|
const tools = await this.generateTools();
|
|
589
631
|
const tool = tools.find((candidate) => candidate.name === toolName);
|
|
590
632
|
if (!tool) return null;
|
|
591
|
-
const {
|
|
633
|
+
const { action } = this.toolTarget(tool);
|
|
592
634
|
if (isCrudToolAction(action)) return null;
|
|
593
|
-
const
|
|
594
|
-
if (!
|
|
595
|
-
const
|
|
596
|
-
const objectName = classInfo.name || key;
|
|
635
|
+
const owner = this.toolClass(tool);
|
|
636
|
+
if (!owner) return null;
|
|
637
|
+
const { key: objectName, classInfo } = owner;
|
|
597
638
|
const mcpConfig = ObjectRegistry.getConfig(objectName).mcp;
|
|
598
639
|
const configuredTasks = typeof mcpConfig === "object" ? mcpConfig.tasks : void 0;
|
|
599
640
|
if (configuredTasks !== true && (!Array.isArray(configuredTasks) || !configuredTasks.some((method) => method.toLowerCase() === action.toLowerCase()))) return null;
|
|
@@ -624,6 +665,10 @@ var MCPGenerator = class {
|
|
|
624
665
|
* Get or create collection for an object
|
|
625
666
|
*/
|
|
626
667
|
async getCollection(objectName, classInfo) {
|
|
668
|
+
if (!this.collections.has(objectName) && !classInfo.collectionConstructor) this.collections.set(objectName, await ObjectRegistry.getCollection(classInfo.qualifiedName || objectName, {
|
|
669
|
+
ai: this.context.ai,
|
|
670
|
+
db: this.context.db
|
|
671
|
+
}));
|
|
627
672
|
if (!this.collections.has(objectName)) {
|
|
628
673
|
if (!classInfo.collectionConstructor || typeof classInfo.collectionConstructor !== "function") throw new Error(`No valid collection constructor found for ${objectName}`);
|
|
629
674
|
const collection = new classInfo.collectionConstructor({
|
|
@@ -720,8 +765,8 @@ var MCPGenerator = class {
|
|
|
720
765
|
if (action === "create" && objectName && typeof args._meta_type === "string") {
|
|
721
766
|
const variant = this.getStiVariants(objectName).find((candidate) => candidate.discriminator === args._meta_type);
|
|
722
767
|
if (!variant) throw new Error(`Unknown STI discriminator: ${args._meta_type}`);
|
|
723
|
-
const classInfo =
|
|
724
|
-
if (
|
|
768
|
+
const classInfo = variant.classInfo;
|
|
769
|
+
if (ObjectRegistry.getAllClasses().get(variant.name) !== classInfo) throw new Error(`STI subtype '${variant.name}' is not registered`);
|
|
725
770
|
targetCollection = await this.getCollection(variant.name, classInfo);
|
|
726
771
|
targetObjectName = variant.name;
|
|
727
772
|
}
|
|
@@ -763,12 +808,14 @@ var MCPGenerator = class {
|
|
|
763
808
|
for (const tool of tools) {
|
|
764
809
|
const { objectName } = this.toolTarget(tool);
|
|
765
810
|
if (!objectName) continue;
|
|
811
|
+
const owner = this.toolClass(tool);
|
|
812
|
+
if (owner) {
|
|
813
|
+
if (isTenantScopedClass(owner.key)) scoped.add(objectName.toLowerCase());
|
|
814
|
+
continue;
|
|
815
|
+
}
|
|
766
816
|
for (const [key, info] of ObjectRegistry.getAllClasses()) {
|
|
767
817
|
const simpleName = info.name || key;
|
|
768
|
-
if (simpleName.toLowerCase() === objectName.toLowerCase())
|
|
769
|
-
if (isTenantScopedClass(simpleName)) scoped.add(simpleName.toLowerCase());
|
|
770
|
-
break;
|
|
771
|
-
}
|
|
818
|
+
if (simpleName.toLowerCase() === objectName.toLowerCase() && isTenantScopedClass(key)) scoped.add(simpleName.toLowerCase());
|
|
772
819
|
}
|
|
773
820
|
}
|
|
774
821
|
return Array.from(scoped);
|
|
@@ -784,15 +831,14 @@ var MCPGenerator = class {
|
|
|
784
831
|
async hasTenantScopedTools(tools) {
|
|
785
832
|
if ((await this.tenantScopedObjectNames(tools)).length > 0) return true;
|
|
786
833
|
for (const tool of tools) {
|
|
834
|
+
const owner = this.toolClass(tool);
|
|
835
|
+
if (owner) {
|
|
836
|
+
if (ObjectRegistry.isTenantScoped(owner.key)) return true;
|
|
837
|
+
continue;
|
|
838
|
+
}
|
|
787
839
|
const { objectName } = this.toolTarget(tool);
|
|
788
840
|
if (!objectName) continue;
|
|
789
|
-
for (const [key, info] of ObjectRegistry.getAllClasses())
|
|
790
|
-
const simpleName = info.name || key;
|
|
791
|
-
if (simpleName.toLowerCase() === objectName.toLowerCase()) {
|
|
792
|
-
if (ObjectRegistry.isTenantScoped(simpleName)) return true;
|
|
793
|
-
break;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
841
|
+
for (const [key, info] of ObjectRegistry.getAllClasses()) if ((info.name || key).toLowerCase() === objectName.toLowerCase() && ObjectRegistry.isTenantScoped(key)) return true;
|
|
796
842
|
}
|
|
797
843
|
return false;
|
|
798
844
|
}
|
|
@@ -835,7 +881,6 @@ var MCPGenerator = class {
|
|
|
835
881
|
createData.owner_id = this.context.user.id;
|
|
836
882
|
}
|
|
837
883
|
const newItem = await collection.create(createData);
|
|
838
|
-
await newItem.save();
|
|
839
884
|
return this.toPublicData(newItem);
|
|
840
885
|
}
|
|
841
886
|
case "update": {
|
|
@@ -844,21 +889,21 @@ var MCPGenerator = class {
|
|
|
844
889
|
const existing = await collection.get(id);
|
|
845
890
|
if (!existing) throw new Error("Object not found");
|
|
846
891
|
const updateData = this.applyWritablePolicy(objectName, args);
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
892
|
+
await collection.withAuditMutation(existing, "updated", async (bound) => {
|
|
893
|
+
Object.assign(bound, updateData);
|
|
894
|
+
if (this.context.user) bound.updated_by = this.context.user.id;
|
|
895
|
+
await bound.save();
|
|
896
|
+
});
|
|
850
897
|
return this.toPublicData(existing);
|
|
851
898
|
}
|
|
852
|
-
case "delete":
|
|
899
|
+
case "delete":
|
|
853
900
|
if (!args.id) throw new Error("ID is required for delete");
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
await toDelete.delete();
|
|
901
|
+
if (!await collection.get(args.id)) throw new Error("Object not found");
|
|
902
|
+
await collection.delete(args.id);
|
|
857
903
|
return {
|
|
858
904
|
success: true,
|
|
859
905
|
message: "Object deleted successfully"
|
|
860
906
|
};
|
|
861
|
-
}
|
|
862
907
|
default: {
|
|
863
908
|
const result = await this.executeCustomAction(collection, action, args, objectName);
|
|
864
909
|
return this.toPublicData(result);
|
|
@@ -992,16 +1037,12 @@ var MCPGenerator = class {
|
|
|
992
1037
|
}
|
|
993
1038
|
async runtimeCustomActions(tools) {
|
|
994
1039
|
const metadata = {};
|
|
995
|
-
const classes = ObjectRegistry.getAllClasses();
|
|
996
1040
|
for (const tool of tools) {
|
|
997
|
-
const
|
|
998
|
-
const objectPrefix = target.objectName.toLowerCase();
|
|
999
|
-
const action = target.action;
|
|
1041
|
+
const action = this.toolTarget(tool).action;
|
|
1000
1042
|
if (isCrudToolAction(action)) continue;
|
|
1001
|
-
const
|
|
1002
|
-
if (!
|
|
1003
|
-
const
|
|
1004
|
-
const objectName = classInfo.name || key;
|
|
1043
|
+
const owner = this.toolClass(tool);
|
|
1044
|
+
if (!owner) continue;
|
|
1045
|
+
const { key: objectName, classInfo } = owner;
|
|
1005
1046
|
const [methodName, method] = resolveCustomActionMethod(await ObjectRegistry.getAllMethods(objectName), action);
|
|
1006
1047
|
const resolved = this.resolveCustomActionMetadata(objectName, methodName, method, this.hasCollectionReceiver(classInfo));
|
|
1007
1048
|
metadata[tool.name] = {
|
|
@@ -1020,17 +1061,16 @@ var MCPGenerator = class {
|
|
|
1020
1061
|
/** Emit only task-enabled item custom actions for the generated runtime. */
|
|
1021
1062
|
async runtimeTaskActions(tools) {
|
|
1022
1063
|
const actions = {};
|
|
1023
|
-
const classes = ObjectRegistry.getAllClasses();
|
|
1024
1064
|
for (const tool of tools) {
|
|
1025
1065
|
if (!await this.supportsTaskTool(tool.name)) continue;
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
const [key, classInfo] = matched;
|
|
1066
|
+
const owner = this.toolClass(tool);
|
|
1067
|
+
if (!owner) continue;
|
|
1068
|
+
const { key, classInfo } = owner;
|
|
1030
1069
|
const objectName = classInfo.name || key;
|
|
1031
1070
|
actions[tool.name] = {
|
|
1032
1071
|
objectName,
|
|
1033
|
-
objectType: classInfo.qualifiedName || objectName
|
|
1072
|
+
objectType: classInfo.qualifiedName || objectName,
|
|
1073
|
+
registryKey: key
|
|
1034
1074
|
};
|
|
1035
1075
|
}
|
|
1036
1076
|
return actions;
|
|
@@ -1065,29 +1105,26 @@ var MCPGenerator = class {
|
|
|
1065
1105
|
*/
|
|
1066
1106
|
runtimeListOrderBy(tools) {
|
|
1067
1107
|
const orderings = {};
|
|
1068
|
-
const classes = ObjectRegistry.getAllClasses();
|
|
1069
1108
|
for (const tool of tools) {
|
|
1070
1109
|
const target = this.toolTarget(tool);
|
|
1071
1110
|
if (target.action !== "list") continue;
|
|
1072
1111
|
const objectPrefix = target.objectName.toLowerCase();
|
|
1073
1112
|
if (orderings[objectPrefix]) continue;
|
|
1074
|
-
const
|
|
1075
|
-
if (!
|
|
1076
|
-
orderings[objectPrefix] = this.resolveDefaultListOrderBy(
|
|
1113
|
+
const owner = this.toolClass(tool);
|
|
1114
|
+
if (!owner) continue;
|
|
1115
|
+
orderings[objectPrefix] = this.resolveDefaultListOrderBy(owner.key);
|
|
1077
1116
|
}
|
|
1078
1117
|
return orderings;
|
|
1079
1118
|
}
|
|
1080
1119
|
runtimeStiTargets(tools) {
|
|
1081
1120
|
const targets = {};
|
|
1082
|
-
const classes = ObjectRegistry.getAllClasses();
|
|
1083
1121
|
for (const tool of tools) {
|
|
1084
1122
|
const target = this.toolTarget(tool);
|
|
1085
1123
|
if (target.action !== "create") continue;
|
|
1086
1124
|
const objectPrefix = target.objectName.toLowerCase();
|
|
1087
|
-
const
|
|
1088
|
-
if (!
|
|
1089
|
-
const
|
|
1090
|
-
const variants = this.getStiVariants(classInfo.name || key);
|
|
1125
|
+
const owner = this.toolClass(tool);
|
|
1126
|
+
if (!owner) continue;
|
|
1127
|
+
const variants = this.getStiVariants(owner.key);
|
|
1091
1128
|
if (variants.length === 0) continue;
|
|
1092
1129
|
targets[objectPrefix] = Object.fromEntries(variants.map((variant) => [variant.discriminator, variant.discriminator]));
|
|
1093
1130
|
}
|
|
@@ -1181,13 +1218,14 @@ export const tools: Array<{
|
|
|
1181
1218
|
const target = this.toolTarget(tool);
|
|
1182
1219
|
const objectName = target.objectName.toLowerCase();
|
|
1183
1220
|
const action = target.action;
|
|
1221
|
+
const lookup = target.registryKey ?? target.objectName;
|
|
1184
1222
|
switch (action) {
|
|
1185
1223
|
case "list": return `${indent}case '${tool.name}': {
|
|
1186
1224
|
${indent} const limit = args.limit ?? 50;
|
|
1187
1225
|
${indent} const offset = args.offset ?? 0;
|
|
1188
1226
|
${indent} const where = args.where ?? {};
|
|
1189
1227
|
|
|
1190
|
-
${indent} const collection = await ObjectRegistry.getCollection(${JSON.stringify(
|
|
1228
|
+
${indent} const collection = await ObjectRegistry.getCollection(${JSON.stringify(lookup)}, {
|
|
1191
1229
|
${indent} persistence: { type: process.env.DATABASE_TYPE || 'sqlite', url: process.env.DATABASE_URL || ':memory:' },
|
|
1192
1230
|
${indent} ai: aiConfig
|
|
1193
1231
|
${indent} });
|
|
@@ -1205,7 +1243,7 @@ ${indent} if (!args.id && !args.slug) {
|
|
|
1205
1243
|
${indent} throw new Error('Either id or slug is required');
|
|
1206
1244
|
${indent} }
|
|
1207
1245
|
|
|
1208
|
-
${indent} const collection = await ObjectRegistry.getCollection(${JSON.stringify(
|
|
1246
|
+
${indent} const collection = await ObjectRegistry.getCollection(${JSON.stringify(lookup)}, {
|
|
1209
1247
|
${indent} persistence: { type: process.env.DATABASE_TYPE || 'sqlite', url: process.env.DATABASE_URL || ':memory:' },
|
|
1210
1248
|
${indent} ai: aiConfig
|
|
1211
1249
|
${indent} });
|
|
@@ -1220,10 +1258,9 @@ ${indent} }
|
|
|
1220
1258
|
${indent} return successResult(item.toPublicJSON(PUBLIC_JSON_OPTIONS));
|
|
1221
1259
|
${indent}}`;
|
|
1222
1260
|
case "create": return `${indent}case '${tool.name}': {
|
|
1223
|
-
${indent} const { collection, objectName: targetObjectName } = await resolveCreateTarget(${JSON.stringify(objectName)}, args, aiConfig);
|
|
1261
|
+
${indent} const { collection, objectName: targetObjectName } = await resolveCreateTarget(${JSON.stringify(objectName)}, ${JSON.stringify(lookup)}, args, aiConfig);
|
|
1224
1262
|
|
|
1225
1263
|
${indent} const newItem = await collection.create(applyWritablePolicy(targetObjectName, args));
|
|
1226
|
-
${indent} await newItem.save();
|
|
1227
1264
|
|
|
1228
1265
|
${indent} return successResult(newItem.toPublicJSON(PUBLIC_JSON_OPTIONS));
|
|
1229
1266
|
${indent}}`;
|
|
@@ -1233,7 +1270,7 @@ ${indent} if (!id) {
|
|
|
1233
1270
|
${indent} throw new Error('ID is required for update');
|
|
1234
1271
|
${indent} }
|
|
1235
1272
|
|
|
1236
|
-
${indent} const collection = await ObjectRegistry.getCollection(${JSON.stringify(
|
|
1273
|
+
${indent} const collection = await ObjectRegistry.getCollection(${JSON.stringify(lookup)}, {
|
|
1237
1274
|
${indent} persistence: { type: process.env.DATABASE_TYPE || 'sqlite', url: process.env.DATABASE_URL || ':memory:' },
|
|
1238
1275
|
${indent} ai: aiConfig
|
|
1239
1276
|
${indent} });
|
|
@@ -1243,8 +1280,10 @@ ${indent} if (!existing) {
|
|
|
1243
1280
|
${indent} throw new Error('Object not found');
|
|
1244
1281
|
${indent} }
|
|
1245
1282
|
|
|
1246
|
-
${indent}
|
|
1247
|
-
${indent}
|
|
1283
|
+
${indent} await collection.withAuditMutation(existing, 'updated', async (bound) => {
|
|
1284
|
+
${indent} Object.assign(bound, applyWritablePolicy(${JSON.stringify(lookup)}, updateData));
|
|
1285
|
+
${indent} await bound.save();
|
|
1286
|
+
${indent} });
|
|
1248
1287
|
|
|
1249
1288
|
${indent} return successResult(existing.toPublicJSON(PUBLIC_JSON_OPTIONS));
|
|
1250
1289
|
${indent}}`;
|
|
@@ -1253,7 +1292,7 @@ ${indent} if (!args.id) {
|
|
|
1253
1292
|
${indent} throw new Error('ID is required for delete');
|
|
1254
1293
|
${indent} }
|
|
1255
1294
|
|
|
1256
|
-
${indent} const collection = await ObjectRegistry.getCollection(${JSON.stringify(
|
|
1295
|
+
${indent} const collection = await ObjectRegistry.getCollection(${JSON.stringify(lookup)}, {
|
|
1257
1296
|
${indent} persistence: { type: process.env.DATABASE_TYPE || 'sqlite', url: process.env.DATABASE_URL || ':memory:' },
|
|
1258
1297
|
${indent} ai: aiConfig
|
|
1259
1298
|
${indent} });
|
|
@@ -1263,15 +1302,14 @@ ${indent} if (!toDelete) {
|
|
|
1263
1302
|
${indent} throw new Error('Object not found');
|
|
1264
1303
|
${indent} }
|
|
1265
1304
|
|
|
1266
|
-
${indent} await
|
|
1305
|
+
${indent} await collection.delete(args.id);
|
|
1267
1306
|
|
|
1268
1307
|
${indent} return successResult({ success: true, message: 'Object deleted successfully' });
|
|
1269
1308
|
${indent}}`;
|
|
1270
1309
|
default: {
|
|
1271
|
-
const
|
|
1272
|
-
if (!
|
|
1273
|
-
const
|
|
1274
|
-
const registeredName = classInfo.name || classKey;
|
|
1310
|
+
const owner = this.toolClass(tool);
|
|
1311
|
+
if (!owner) throw new Error(`Unable to resolve custom-action target for tool '${tool.name}'`);
|
|
1312
|
+
const { key: registeredName, classInfo } = owner;
|
|
1275
1313
|
const [methodName, method] = resolveCustomActionMethod(await ObjectRegistry.getAllMethods(registeredName), action);
|
|
1276
1314
|
const metadata = this.resolveCustomActionMetadata(registeredName, methodName, method, this.hasCollectionReceiver(classInfo));
|
|
1277
1315
|
const methodArgs = !metadata.parameters ? "Object.keys(options ?? {}).length > 0 ? options : directArgs" : metadata.parameters.length === 1 && metadata.parameters[0]?.name === "options" ? "options" : `[${metadata.parameters.map((parameter) => `args[${JSON.stringify(customActionParameterInputName(metadata, parameter.name))}]`).join(", ")}]`;
|
|
@@ -1357,7 +1395,7 @@ const MCP_TENANT_ID = process.env.SMRT_MCP_TENANT_ID || undefined;
|
|
|
1357
1395
|
const MCP_ALLOW_CROSS_TENANT = process.env.SMRT_MCP_ALLOW_CROSS_TENANT === 'true';
|
|
1358
1396
|
` : ""}
|
|
1359
1397
|
|
|
1360
|
-
const TOOL_TARGETS: Record<string, { objectName: string; action: string }> = ${JSON.stringify(toolTargets)};
|
|
1398
|
+
const TOOL_TARGETS: Record<string, { objectName: string; action: string; registryKey?: string }> = ${JSON.stringify(toolTargets)};
|
|
1361
1399
|
const PUBLIC_JSON_OPTIONS = {
|
|
1362
1400
|
permissions: (process.env.SMRT_MCP_PERMISSIONS || '')
|
|
1363
1401
|
.split(',')
|
|
@@ -1400,10 +1438,10 @@ function applyWritablePolicy(objectName: string, data: any): Record<string, any>
|
|
|
1400
1438
|
}
|
|
1401
1439
|
|
|
1402
1440
|
/** Resolve an advertised STI discriminator to its registered subtype collection. */
|
|
1403
|
-
async function resolveCreateTarget(baseObjectName: string, args: Record<string, any>, aiConfig: any) {
|
|
1441
|
+
async function resolveCreateTarget(stiKey: string, baseObjectName: string, args: Record<string, any>, aiConfig: any) {
|
|
1404
1442
|
let objectName = baseObjectName;
|
|
1405
1443
|
const discriminator = args._meta_type;
|
|
1406
|
-
const targets = STI_TARGETS[
|
|
1444
|
+
const targets = STI_TARGETS[stiKey];
|
|
1407
1445
|
if (typeof discriminator === 'string' && targets) {
|
|
1408
1446
|
const target = targets[discriminator];
|
|
1409
1447
|
if (!target) throw new Error('Unknown STI discriminator: ' + discriminator);
|