@axiom-lattice/core 4.4.0 → 5.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/dist/index.d.mts +1 -21
- package/dist/index.d.ts +1 -21
- package/dist/index.js +261 -1807
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +244 -1788
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1811,7 +1811,6 @@ __export(index_exports, {
|
|
|
1811
1811
|
createSandboxProvider: () => createSandboxProvider,
|
|
1812
1812
|
createSandboxResolver: () => createSandboxResolver,
|
|
1813
1813
|
createSchedulerMiddleware: () => createSchedulerMiddleware,
|
|
1814
|
-
createSemanticMetricsMiddleware: () => createSemanticMetricsMiddleware,
|
|
1815
1814
|
createSharePayload: () => createSharePayload,
|
|
1816
1815
|
createTaskExecutionService: () => createTaskExecutionService,
|
|
1817
1816
|
createTaskLifecycleService: () => createTaskLifecycleService,
|
|
@@ -1970,7 +1969,6 @@ __export(index_exports, {
|
|
|
1970
1969
|
sandboxLatticeManager: () => sandboxLatticeManager,
|
|
1971
1970
|
sanitizeToolCallId: () => sanitizeToolCallId,
|
|
1972
1971
|
scheduleLatticeManager: () => scheduleLatticeManager,
|
|
1973
|
-
semanticMetricsPlugin: () => semanticMetricsPlugin,
|
|
1974
1972
|
serializePluginMeta: () => serializePluginMeta,
|
|
1975
1973
|
serializeTaskMutationSuccess: () => serializeTaskMutationSuccess,
|
|
1976
1974
|
serializeTaskNormalizationFallback: () => serializeTaskNormalizationFallback,
|
|
@@ -2424,11 +2422,11 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
|
|
|
2424
2422
|
* @param key Lattice键名
|
|
2425
2423
|
* @param tool 已有的StructuredTool实例
|
|
2426
2424
|
*/
|
|
2427
|
-
registerExistingTool(key5,
|
|
2425
|
+
registerExistingTool(key5, tool68) {
|
|
2428
2426
|
const config = {
|
|
2429
|
-
name:
|
|
2430
|
-
description:
|
|
2431
|
-
schema:
|
|
2427
|
+
name: tool68.name,
|
|
2428
|
+
description: tool68.description,
|
|
2429
|
+
schema: tool68.schema,
|
|
2432
2430
|
// StructuredTool的schema已经是Zod兼容的
|
|
2433
2431
|
needUserApprove: false
|
|
2434
2432
|
// MCP工具默认不需要用户批准
|
|
@@ -2436,7 +2434,7 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
|
|
|
2436
2434
|
const toolLattice = {
|
|
2437
2435
|
key: key5,
|
|
2438
2436
|
config,
|
|
2439
|
-
client:
|
|
2437
|
+
client: tool68
|
|
2440
2438
|
};
|
|
2441
2439
|
this.register(key5, toolLattice);
|
|
2442
2440
|
}
|
|
@@ -2447,14 +2445,14 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
|
|
|
2447
2445
|
* @param key - tool lattice key (no tenant prefix)
|
|
2448
2446
|
* @param tool - the StructuredTool client
|
|
2449
2447
|
*/
|
|
2450
|
-
registerExistingToolWithTenant(tenantId2, key5,
|
|
2448
|
+
registerExistingToolWithTenant(tenantId2, key5, tool68) {
|
|
2451
2449
|
const config = {
|
|
2452
|
-
name:
|
|
2453
|
-
description:
|
|
2454
|
-
schema:
|
|
2450
|
+
name: tool68.name,
|
|
2451
|
+
description: tool68.description,
|
|
2452
|
+
schema: tool68.schema,
|
|
2455
2453
|
needUserApprove: false
|
|
2456
2454
|
};
|
|
2457
|
-
const toolLattice = { key: key5, config, client:
|
|
2455
|
+
const toolLattice = { key: key5, config, client: tool68 };
|
|
2458
2456
|
this.registerWithTenant(tenantId2, key5, toolLattice);
|
|
2459
2457
|
}
|
|
2460
2458
|
/**
|
|
@@ -2504,8 +2502,8 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
|
|
|
2504
2502
|
};
|
|
2505
2503
|
var toolLatticeManager = ToolLatticeManager.getInstance();
|
|
2506
2504
|
var registerToolLattice = (key5, config, executor) => toolLatticeManager.registerLattice(key5, config, executor);
|
|
2507
|
-
var registerExistingTool = (key5,
|
|
2508
|
-
var registerExistingToolWithTenant = (tenantId2, key5,
|
|
2505
|
+
var registerExistingTool = (key5, tool68) => toolLatticeManager.registerExistingTool(key5, tool68);
|
|
2506
|
+
var registerExistingToolWithTenant = (tenantId2, key5, tool68) => toolLatticeManager.registerExistingToolWithTenant(tenantId2, key5, tool68);
|
|
2509
2507
|
var getToolLattice = (key5) => toolLatticeManager.getToolLattice(key5);
|
|
2510
2508
|
var getToolClientWithTenant = (tenantId2, key5) => toolLatticeManager.getToolClientWithTenant(tenantId2, key5);
|
|
2511
2509
|
var getToolDefinition = (key5) => toolLatticeManager.getToolDefinition(key5);
|
|
@@ -3345,15 +3343,15 @@ ${body}` : `${frontmatter}
|
|
|
3345
3343
|
const resourcesDir = path.join(skillDir, "resources");
|
|
3346
3344
|
try {
|
|
3347
3345
|
const entries = await fs.readdir(resourcesDir, { withFileTypes: true, recursive: true });
|
|
3348
|
-
const
|
|
3346
|
+
const resources2 = [];
|
|
3349
3347
|
for (const entry of entries) {
|
|
3350
3348
|
if (!entry.isDirectory()) {
|
|
3351
3349
|
const fullPath = path.join(entry.path, entry.name);
|
|
3352
3350
|
const relativePath = path.relative(resourcesDir, fullPath);
|
|
3353
|
-
|
|
3351
|
+
resources2.push(relativePath.replace(/\\/g, "/"));
|
|
3354
3352
|
}
|
|
3355
3353
|
}
|
|
3356
|
-
return
|
|
3354
|
+
return resources2.sort();
|
|
3357
3355
|
} catch (error) {
|
|
3358
3356
|
if (error.code === "ENOENT") {
|
|
3359
3357
|
return [];
|
|
@@ -13632,11 +13630,11 @@ var PluginRegistry = class {
|
|
|
13632
13630
|
if (!isRecord2(rawDefinition) || typeof rawDefinition.version !== "string" || rawDefinition.version.trim().length === 0 || typeof rawDefinition.content !== "string") {
|
|
13633
13631
|
throw new Error(`Plugin "${key5}": skill "${name}" version and content must be a string`);
|
|
13634
13632
|
}
|
|
13635
|
-
const
|
|
13636
|
-
if (
|
|
13633
|
+
const resources2 = rawDefinition.resources;
|
|
13634
|
+
if (resources2 !== void 0 && !isRecord2(resources2)) {
|
|
13637
13635
|
throw new Error(`Plugin "${key5}": skill "${name}" resources must be an object`);
|
|
13638
13636
|
}
|
|
13639
|
-
for (const [path8, resource] of Object.entries(
|
|
13637
|
+
for (const [path8, resource] of Object.entries(resources2 ?? {})) {
|
|
13640
13638
|
try {
|
|
13641
13639
|
validateRelativePath(path8, "resource");
|
|
13642
13640
|
} catch {
|
|
@@ -14789,7 +14787,7 @@ function isSafeUiPath(path8) {
|
|
|
14789
14787
|
}
|
|
14790
14788
|
function validateSandboxPluginManifest(args) {
|
|
14791
14789
|
const diagnostics = [];
|
|
14792
|
-
const error = (code, message, pluginType,
|
|
14790
|
+
const error = (code, message, pluginType, tool68) => diagnostics.push({ level: "error", code, message, pluginType, tool: tool68 });
|
|
14793
14791
|
const raw = args.raw;
|
|
14794
14792
|
if (!isRecord5(raw)) {
|
|
14795
14793
|
error("MANIFEST_NOT_OBJECT", "manifest must be a JSON object", args.dirName);
|
|
@@ -15797,9 +15795,9 @@ function freezeMetadata(metadata) {
|
|
|
15797
15795
|
...resourceSelector ? { resourceSelector } : {}
|
|
15798
15796
|
});
|
|
15799
15797
|
}
|
|
15800
|
-
function toolName(
|
|
15801
|
-
if (typeof
|
|
15802
|
-
return typeof
|
|
15798
|
+
function toolName(tool68) {
|
|
15799
|
+
if (typeof tool68 !== "object" || tool68 === null || !("name" in tool68)) return void 0;
|
|
15800
|
+
return typeof tool68.name === "string" ? tool68.name : void 0;
|
|
15803
15801
|
}
|
|
15804
15802
|
function schemaHasConnectionKey(schema6) {
|
|
15805
15803
|
const definition = isRecord7(schema6._def) ? schema6._def : void 0;
|
|
@@ -15807,10 +15805,10 @@ function schemaHasConnectionKey(schema6) {
|
|
|
15807
15805
|
const fields = typeof shape === "function" ? shape() : shape;
|
|
15808
15806
|
return isRecord7(fields) && Object.prototype.hasOwnProperty.call(fields, "connectionKey");
|
|
15809
15807
|
}
|
|
15810
|
-
function hasConnectionKeySchema(
|
|
15811
|
-
if (!isRecord7(
|
|
15812
|
-
if (schemaHasConnectionKey(
|
|
15813
|
-
const definition = isRecord7(
|
|
15808
|
+
function hasConnectionKeySchema(tool68) {
|
|
15809
|
+
if (!isRecord7(tool68) || !isRecord7(tool68.schema)) return false;
|
|
15810
|
+
if (schemaHasConnectionKey(tool68.schema)) return true;
|
|
15811
|
+
const definition = isRecord7(tool68.schema._def) ? tool68.schema._def : void 0;
|
|
15814
15812
|
if (Array.isArray(definition?.options) && definition.options.length > 0) {
|
|
15815
15813
|
return definition.options.every(
|
|
15816
15814
|
(option) => isRecord7(option) && schemaHasConnectionKey(option)
|
|
@@ -15865,8 +15863,8 @@ var CapabilityToolRegistry = class {
|
|
|
15865
15863
|
* @remarks Standard connection authorization is captured only for tools whose
|
|
15866
15864
|
* schema declares `connectionKey`; legacy selectors remain explicit metadata.
|
|
15867
15865
|
*/
|
|
15868
|
-
register(name, metadata,
|
|
15869
|
-
this.registerInternal(name, metadata, hasConnectionKeySchema(
|
|
15866
|
+
register(name, metadata, tool68) {
|
|
15867
|
+
this.registerInternal(name, metadata, hasConnectionKeySchema(tool68));
|
|
15870
15868
|
}
|
|
15871
15869
|
/**
|
|
15872
15870
|
* Registers all tools actually exposed by a middleware instance.
|
|
@@ -15877,13 +15875,13 @@ var CapabilityToolRegistry = class {
|
|
|
15877
15875
|
* @returns Nothing.
|
|
15878
15876
|
*/
|
|
15879
15877
|
registerMiddleware(capabilityType, middleware, resourceSelectors = {}) {
|
|
15880
|
-
for (const
|
|
15881
|
-
const name = toolName(
|
|
15878
|
+
for (const tool68 of middleware.tools ?? []) {
|
|
15879
|
+
const name = toolName(tool68);
|
|
15882
15880
|
if (name) {
|
|
15883
15881
|
this.registerInternal(name, {
|
|
15884
15882
|
capabilityType,
|
|
15885
15883
|
resourceSelector: resourceSelectors[name]
|
|
15886
|
-
}, hasConnectionKeySchema(
|
|
15884
|
+
}, hasConnectionKeySchema(tool68));
|
|
15887
15885
|
}
|
|
15888
15886
|
}
|
|
15889
15887
|
}
|
|
@@ -16575,9 +16573,9 @@ var ReActAgentGraphBuilder = class {
|
|
|
16575
16573
|
*/
|
|
16576
16574
|
async build(agentLattice, params) {
|
|
16577
16575
|
const tools = params.tools.map((t) => {
|
|
16578
|
-
const
|
|
16579
|
-
return
|
|
16580
|
-
}).filter((
|
|
16576
|
+
const tool68 = getToolClientWithTenant(params.tenantId ?? "default", t.key);
|
|
16577
|
+
return tool68;
|
|
16578
|
+
}).filter((tool68) => tool68 !== void 0);
|
|
16581
16579
|
const stateSchema2 = createReactAgentSchema(params.stateSchema);
|
|
16582
16580
|
const middlewareConfigs = params.middleware || [];
|
|
16583
16581
|
const filesystemBackend = createFilesystemBackendFactory(middlewareConfigs);
|
|
@@ -17734,8 +17732,8 @@ function validateCapability(value, index) {
|
|
|
17734
17732
|
fieldPath: `/capabilities/${index}/allowedTools`
|
|
17735
17733
|
});
|
|
17736
17734
|
}
|
|
17737
|
-
for (const [toolIndex,
|
|
17738
|
-
if (typeof
|
|
17735
|
+
for (const [toolIndex, tool68] of capability.allowedTools.entries()) {
|
|
17736
|
+
if (typeof tool68 !== "string") {
|
|
17739
17737
|
throw new CapabilityBundleValidationError(
|
|
17740
17738
|
"CAPABILITY_BUNDLE_INVALID_CAPABILITY",
|
|
17741
17739
|
"allowedTools entries must be strings",
|
|
@@ -17749,10 +17747,10 @@ function validateCapability(value, index) {
|
|
|
17749
17747
|
fieldPath: `/capabilities/${index}/allowedTools`
|
|
17750
17748
|
});
|
|
17751
17749
|
}
|
|
17752
|
-
const toolNames = new Set(plugin.meta.tools.map((
|
|
17753
|
-
for (const [toolIndex,
|
|
17754
|
-
if (typeof
|
|
17755
|
-
throw new CapabilityBundleValidationError("CAPABILITY_BUNDLE_UNKNOWN_TOOL", `Unknown tool '${String(
|
|
17750
|
+
const toolNames = new Set(plugin.meta.tools.map((tool68) => tool68.name));
|
|
17751
|
+
for (const [toolIndex, tool68] of capability.allowedTools.entries()) {
|
|
17752
|
+
if (typeof tool68 !== "string" || !toolNames.has(tool68)) {
|
|
17753
|
+
throw new CapabilityBundleValidationError("CAPABILITY_BUNDLE_UNKNOWN_TOOL", `Unknown tool '${String(tool68)}'`, {
|
|
17756
17754
|
capabilityType,
|
|
17757
17755
|
fieldPath: `/capabilities/${index}/allowedTools/${toolIndex}`
|
|
17758
17756
|
});
|
|
@@ -18235,7 +18233,7 @@ function applyStaticCeiling(capabilities, staticMiddleware) {
|
|
|
18235
18233
|
const projectTools = capability.allowedTools;
|
|
18236
18234
|
const staticTools = ceiling.allowedTools;
|
|
18237
18235
|
const effectiveStaticTools = staticTools?.length === 0 ? void 0 : staticTools;
|
|
18238
|
-
const allowedTools = projectTools === void 0 ? effectiveStaticTools : effectiveStaticTools === void 0 ? projectTools : projectTools.filter((
|
|
18236
|
+
const allowedTools = projectTools === void 0 ? effectiveStaticTools : effectiveStaticTools === void 0 ? projectTools : projectTools.filter((tool68) => effectiveStaticTools.includes(tool68));
|
|
18239
18237
|
runtime[capability.type] = structuredClone({
|
|
18240
18238
|
...capability,
|
|
18241
18239
|
config: applyStaticResourceCeiling(capability, ceiling),
|
|
@@ -23990,7 +23988,7 @@ var DeepAgentGraphBuilder = class {
|
|
|
23990
23988
|
const tools = params.tools.map((t) => {
|
|
23991
23989
|
const toolClient = getToolClientWithTenant(params.tenantId ?? "default", t.key);
|
|
23992
23990
|
return toolClient;
|
|
23993
|
-
}).filter((
|
|
23991
|
+
}).filter((tool68) => tool68 !== void 0);
|
|
23994
23992
|
const subagents = await Promise.all(params.subAgents.map(async (sa) => {
|
|
23995
23993
|
if (sa.client) {
|
|
23996
23994
|
return {
|
|
@@ -25642,7 +25640,7 @@ var TeamAgentGraphBuilder = class {
|
|
|
25642
25640
|
const tools = params.tools.map((t) => {
|
|
25643
25641
|
const toolClient = getToolClientWithTenant(params.tenantId ?? "default", t.key);
|
|
25644
25642
|
return toolClient;
|
|
25645
|
-
}).filter((
|
|
25643
|
+
}).filter((tool68) => tool68 !== void 0);
|
|
25646
25644
|
const teammates = params.subAgents.map((sa) => {
|
|
25647
25645
|
const baseConfig = sa.config;
|
|
25648
25646
|
return {
|
|
@@ -30039,7 +30037,7 @@ function requireSkillDeclaration(skillLoaded) {
|
|
|
30039
30037
|
return void 0;
|
|
30040
30038
|
}
|
|
30041
30039
|
async function validateAgentReferences(input, tenantId2) {
|
|
30042
|
-
const availableTools = getAvailableTools(tenantId2).map((
|
|
30040
|
+
const availableTools = getAvailableTools(tenantId2).map((tool68) => tool68.key);
|
|
30043
30041
|
const availableMiddlewareTypes = getAvailableMiddlewareTypes();
|
|
30044
30042
|
const availableCustomMiddlewareKeys = CustomMiddlewareRegistry.list().filter(
|
|
30045
30043
|
(key5) => CustomMiddlewareRegistry.get(key5) !== void 0
|
|
@@ -33029,15 +33027,15 @@ var McpLatticeManager = class _McpLatticeManager extends BaseLatticeManager {
|
|
|
33029
33027
|
const metaByName = new Map(metaList.map((m) => [m.name, m.meta]));
|
|
33030
33028
|
this.unregisterServerTools(tenantId2, serverKey);
|
|
33031
33029
|
const keys = [];
|
|
33032
|
-
for (const
|
|
33033
|
-
if (rt.selectedTools && !rt.selectedTools.includes(
|
|
33034
|
-
const meta = metaByName.get(
|
|
33030
|
+
for (const tool68 of tools) {
|
|
33031
|
+
if (rt.selectedTools && !rt.selectedTools.includes(tool68.name)) continue;
|
|
33032
|
+
const meta = metaByName.get(tool68.name);
|
|
33035
33033
|
const rawVisibility = meta?.ui?.visibility;
|
|
33036
33034
|
const visibility = Array.isArray(rawVisibility) ? rawVisibility : typeof rawVisibility === "string" ? [rawVisibility] : void 0;
|
|
33037
33035
|
if (visibility && !visibility.includes("model")) continue;
|
|
33038
33036
|
const ref = extractAppsRef(meta, serverKey);
|
|
33039
|
-
const registered = ref ? wrapMcpToolWithUi(
|
|
33040
|
-
const toolKey = _McpLatticeManager.buildToolKey(serverKey,
|
|
33037
|
+
const registered = ref ? wrapMcpToolWithUi(tool68, ref) : tool68;
|
|
33038
|
+
const toolKey = _McpLatticeManager.buildToolKey(serverKey, tool68.name);
|
|
33041
33039
|
try {
|
|
33042
33040
|
toolLatticeManager.registerExistingToolWithTenant(tenantId2, toolKey, registered);
|
|
33043
33041
|
keys.push(toolKey);
|
|
@@ -40826,10 +40824,10 @@ var createLoadSkillContentTool = (pluginSkills, pluginSkillOwnersOrStaticSelecti
|
|
|
40826
40824
|
lockIdentity
|
|
40827
40825
|
);
|
|
40828
40826
|
let result2 = pluginSkill.definition.content;
|
|
40829
|
-
const
|
|
40830
|
-
if (
|
|
40827
|
+
const resources2 = Object.entries(pluginSkill.definition.resources ?? {});
|
|
40828
|
+
if (resources2.length > 0) {
|
|
40831
40829
|
result2 += "\n\n---\n\n**Resources** (synced to the sandbox; use `read_file` to access):\n";
|
|
40832
|
-
for (const [resourcePath, resource] of
|
|
40830
|
+
for (const [resourcePath, resource] of resources2) {
|
|
40833
40831
|
result2 += `- ${resourcePath} (mime type: ${resource.mimeType ?? "not specified"})
|
|
40834
40832
|
`;
|
|
40835
40833
|
}
|
|
@@ -40856,10 +40854,10 @@ var createLoadSkillContentTool = (pluginSkills, pluginSkillOwnersOrStaticSelecti
|
|
|
40856
40854
|
`/root/.agents/skills/${input.skill_name}/resources`,
|
|
40857
40855
|
{ recursive: false }
|
|
40858
40856
|
);
|
|
40859
|
-
const
|
|
40860
|
-
if (
|
|
40857
|
+
const resources2 = resourcesResult.files.map((f) => f.path.split("/").pop()).filter(Boolean);
|
|
40858
|
+
if (resources2.length > 0) {
|
|
40861
40859
|
result += "\n\n---\n\n**Resources** (use `read_file` tool to access):\n";
|
|
40862
|
-
|
|
40860
|
+
resources2.forEach((r) => {
|
|
40863
40861
|
result += `- ${r}
|
|
40864
40862
|
`;
|
|
40865
40863
|
});
|
|
@@ -41181,1553 +41179,12 @@ var skillPlugin = {
|
|
|
41181
41179
|
})
|
|
41182
41180
|
};
|
|
41183
41181
|
|
|
41184
|
-
// src/middlewares/semanticMetricsMiddleware.ts
|
|
41185
|
-
var import_langchain70 = require("langchain");
|
|
41186
|
-
|
|
41187
|
-
// src/tool_lattice/semantic_metrics/metrics_datasource_tool.ts
|
|
41188
|
-
var import_zod55 = __toESM(require("zod"));
|
|
41189
|
-
var import_langchain67 = require("langchain");
|
|
41190
|
-
|
|
41191
|
-
// src/tool_lattice/semantic_metrics/types.ts
|
|
41192
|
-
function readToolRunConfig(exeConfig) {
|
|
41193
|
-
return exeConfig?.configurable?.runConfig;
|
|
41194
|
-
}
|
|
41195
|
-
function resolveDatasourceId(input, exeConfig) {
|
|
41196
|
-
const id = input.datasourceId ?? readToolRunConfig(exeConfig)?.metricsDataSource?.datasourceId;
|
|
41197
|
-
if (id === void 0 || id === null || id === "") {
|
|
41198
|
-
throw new Error("datasourceId is required (provide it or set runConfig.metricsDataSource.datasourceId)");
|
|
41199
|
-
}
|
|
41200
|
-
return Number(id);
|
|
41201
|
-
}
|
|
41202
|
-
function assertDatasourceSelected(scope, datasourceId) {
|
|
41203
|
-
if (scope.unrestricted) return;
|
|
41204
|
-
if (!scope.ids.includes(datasourceId)) {
|
|
41205
|
-
throw new Error(
|
|
41206
|
-
`DATASOURCE_NOT_SELECTED: datasource ${datasourceId} is not in the effective scope [${scope.ids.join(", ")}]`
|
|
41207
|
-
);
|
|
41208
|
-
}
|
|
41209
|
-
}
|
|
41210
|
-
function effectiveDatasourceScope(connectionScope) {
|
|
41211
|
-
return connectionScope.length > 0 ? { unrestricted: false, ids: [...connectionScope] } : { unrestricted: true, ids: [] };
|
|
41212
|
-
}
|
|
41213
|
-
var DDL_DML_KEYWORDS = [
|
|
41214
|
-
"insert",
|
|
41215
|
-
"update",
|
|
41216
|
-
"delete",
|
|
41217
|
-
"drop",
|
|
41218
|
-
"alter",
|
|
41219
|
-
"create",
|
|
41220
|
-
"truncate",
|
|
41221
|
-
"grant",
|
|
41222
|
-
"revoke",
|
|
41223
|
-
"merge",
|
|
41224
|
-
"replace",
|
|
41225
|
-
"upsert"
|
|
41226
|
-
];
|
|
41227
|
-
var DDL_DML_RE = new RegExp(`\\b(?:${DDL_DML_KEYWORDS.join("|")})\\b`, "i");
|
|
41228
|
-
var SELECT_INTO_RE = /\bselect\b[\s\S]*?\binto\b/i;
|
|
41229
|
-
function validateSql(sql) {
|
|
41230
|
-
const trimmed = sql.trim();
|
|
41231
|
-
if (!trimmed) {
|
|
41232
|
-
return { ok: false, reason: "SQL is empty" };
|
|
41233
|
-
}
|
|
41234
|
-
const withoutComments = trimmed.replace(/--[^\n]*/g, " ").replace(/\/\*[\s\S]*?\*\//g, " ");
|
|
41235
|
-
const statements = withoutComments.split(";").map((s) => s.trim()).filter(Boolean);
|
|
41236
|
-
if (statements.length > 1) {
|
|
41237
|
-
return { ok: false, reason: "Multiple statements are not allowed" };
|
|
41238
|
-
}
|
|
41239
|
-
const firstKeyword = withoutComments.trim().split(/\s+/)[0].toLowerCase();
|
|
41240
|
-
if (firstKeyword !== "select" && firstKeyword !== "with") {
|
|
41241
|
-
return { ok: false, reason: `Only SELECT or WITH queries are allowed (got "${firstKeyword}")` };
|
|
41242
|
-
}
|
|
41243
|
-
if (SELECT_INTO_RE.test(withoutComments)) {
|
|
41244
|
-
return { ok: false, reason: "SELECT INTO is not allowed (creates a table)" };
|
|
41245
|
-
}
|
|
41246
|
-
if (DDL_DML_RE.test(withoutComments)) {
|
|
41247
|
-
return { ok: false, reason: "Only read-only queries are allowed (DML/DDL detected)" };
|
|
41248
|
-
}
|
|
41249
|
-
return { ok: true };
|
|
41250
|
-
}
|
|
41251
|
-
|
|
41252
|
-
// src/tool_lattice/semantic_metrics/SemanticMetricsV2Client.ts
|
|
41253
|
-
var NO_CONNECTION_HINT = "No semantic-metrics connection is configured for this tenant. Add a connection of type 'semantic-metrics' for the tenant, then select it (connections) or enable connectAll in the agent's middleware config.";
|
|
41254
|
-
async function resolveMetricsClientFromSelector(selector, scope, connectionKey) {
|
|
41255
|
-
let resolved;
|
|
41256
|
-
try {
|
|
41257
|
-
resolved = await resolvePluginConnections(selector.connectionType, selector, scope);
|
|
41258
|
-
} catch (error) {
|
|
41259
|
-
if (error instanceof Error && error.message === "ConnectionStore not configured") {
|
|
41260
|
-
throw new Error(NO_CONNECTION_HINT);
|
|
41261
|
-
}
|
|
41262
|
-
throw error;
|
|
41263
|
-
}
|
|
41264
|
-
const available = resolved.map((c) => c.key).join(", ");
|
|
41265
|
-
if (resolved.length === 0) {
|
|
41266
|
-
throw new Error(NO_CONNECTION_HINT);
|
|
41267
|
-
}
|
|
41268
|
-
const key5 = connectionKey?.trim() || (resolved.length === 1 ? resolved[0].key : "");
|
|
41269
|
-
if (!key5) {
|
|
41270
|
-
throw new Error(
|
|
41271
|
-
`connectionKey is required. Available connections: ${available}`
|
|
41272
|
-
);
|
|
41273
|
-
}
|
|
41274
|
-
const entry = resolved.find((c) => c.key === key5);
|
|
41275
|
-
if (!entry) {
|
|
41276
|
-
throw new Error(`Connection "${key5}" not found. Available connections: ${available}`);
|
|
41277
|
-
}
|
|
41278
|
-
const config = entry.config;
|
|
41279
|
-
return new SemanticMetricsV2Client(config);
|
|
41280
|
-
}
|
|
41281
|
-
var SemanticMetricsV2Client = class {
|
|
41282
|
-
/**
|
|
41283
|
-
* @param config - Connection configuration (server URL, optional API key and headers).
|
|
41284
|
-
*/
|
|
41285
|
-
constructor(config) {
|
|
41286
|
-
this.config = config;
|
|
41287
|
-
this.baseUrl = config.serverUrl.replace(/\/$/, "");
|
|
41288
|
-
}
|
|
41289
|
-
/**
|
|
41290
|
-
* Build default request headers: `Accept: application/json`, custom headers,
|
|
41291
|
-
* and a Bearer `Authorization` header when an API key is configured.
|
|
41292
|
-
*
|
|
41293
|
-
* @returns Merged headers.
|
|
41294
|
-
*/
|
|
41295
|
-
getHeaders() {
|
|
41296
|
-
const headers = {
|
|
41297
|
-
Accept: "application/json",
|
|
41298
|
-
...this.config.headers ?? {}
|
|
41299
|
-
};
|
|
41300
|
-
if (this.config.apiKey) {
|
|
41301
|
-
headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
41302
|
-
}
|
|
41303
|
-
return headers;
|
|
41304
|
-
}
|
|
41305
|
-
/**
|
|
41306
|
-
* Numeric selected resource ids of this connection (normalized).
|
|
41307
|
-
*
|
|
41308
|
-
* Reads `selectedEntities` — the standard connection resource-selection
|
|
41309
|
-
* field written by the connection UI (`connection.discover` + selection).
|
|
41310
|
-
*
|
|
41311
|
-
* @returns The selected resource ids; empty when unrestricted.
|
|
41312
|
-
*/
|
|
41313
|
-
getSelectedEntities() {
|
|
41314
|
-
const raw = this.config.selectedEntities;
|
|
41315
|
-
if (!Array.isArray(raw)) return [];
|
|
41316
|
-
return raw.map((v) => Number(v)).filter((n) => Number.isFinite(n));
|
|
41317
|
-
}
|
|
41318
|
-
/**
|
|
41319
|
-
* Perform a JSON request against the base URL.
|
|
41320
|
-
*
|
|
41321
|
-
* The Metrics Server wraps every response as `{ code, message, data }`. A
|
|
41322
|
-
* `code` of 200 resolves to `data`; any other `code` throws a business error
|
|
41323
|
-
* carrying the server message (regardless of HTTP status). Non-envelope
|
|
41324
|
-
* bodies are returned as-is.
|
|
41325
|
-
*
|
|
41326
|
-
* @param path - Path appended to the base URL (must start with `/`).
|
|
41327
|
-
* @param init - Optional `fetch` init overrides (method, body, per-call headers).
|
|
41328
|
-
* @returns The unwrapped `data` payload of the response envelope.
|
|
41329
|
-
* @throws When the server returns a non-200 `code`, or the HTTP response is not OK.
|
|
41330
|
-
*/
|
|
41331
|
-
async request(path8, init = {}) {
|
|
41332
|
-
const response = await fetch(`${this.baseUrl}${path8}`, {
|
|
41333
|
-
...init,
|
|
41334
|
-
method: init.method ?? "GET",
|
|
41335
|
-
headers: { ...this.getHeaders(), ...init.headers ?? {} }
|
|
41336
|
-
});
|
|
41337
|
-
const text = await response.text().catch(() => "");
|
|
41338
|
-
const parsed = this.parseBody(text);
|
|
41339
|
-
if (parsed?.envelope === true) {
|
|
41340
|
-
if (parsed.code !== 200) {
|
|
41341
|
-
throw new Error(`API ${parsed.code}: ${parsed.message || "Unknown error"}`);
|
|
41342
|
-
}
|
|
41343
|
-
return parsed.data;
|
|
41344
|
-
}
|
|
41345
|
-
if (!response.ok) {
|
|
41346
|
-
throw new Error(`HTTP ${response.status}: ${text || response.statusText}`);
|
|
41347
|
-
}
|
|
41348
|
-
return parsed?.value ?? void 0;
|
|
41349
|
-
}
|
|
41350
|
-
/**
|
|
41351
|
-
* Parse a response body text. Detects the server envelope `{ code, message, data }`.
|
|
41352
|
-
*
|
|
41353
|
-
* @param text - Raw response body text.
|
|
41354
|
-
* @returns `{ envelope: true, code, message, data }` for an envelope body,
|
|
41355
|
-
* `{ envelope: false, value }` for anything else (or `{ envelope: false }` when empty/invalid).
|
|
41356
|
-
*/
|
|
41357
|
-
parseBody(text) {
|
|
41358
|
-
if (!text.trim()) return { envelope: false };
|
|
41359
|
-
try {
|
|
41360
|
-
const value = JSON.parse(text);
|
|
41361
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
41362
|
-
const record = value;
|
|
41363
|
-
if (typeof record.code === "number") {
|
|
41364
|
-
return {
|
|
41365
|
-
envelope: true,
|
|
41366
|
-
code: record.code,
|
|
41367
|
-
message: typeof record.message === "string" ? record.message : void 0,
|
|
41368
|
-
data: record.data
|
|
41369
|
-
};
|
|
41370
|
-
}
|
|
41371
|
-
}
|
|
41372
|
-
return { envelope: false, value };
|
|
41373
|
-
} catch {
|
|
41374
|
-
return { envelope: false, value: text };
|
|
41375
|
-
}
|
|
41376
|
-
}
|
|
41377
|
-
/**
|
|
41378
|
-
* POST a JSON body to a path.
|
|
41379
|
-
*
|
|
41380
|
-
* @param path - Path appended to the base URL.
|
|
41381
|
-
* @param body - Payload serialized as JSON.
|
|
41382
|
-
* @returns Parsed JSON response body.
|
|
41383
|
-
*/
|
|
41384
|
-
post(path8, body) {
|
|
41385
|
-
return this.request(path8, {
|
|
41386
|
-
method: "POST",
|
|
41387
|
-
headers: { "Content-Type": "application/json" },
|
|
41388
|
-
body: JSON.stringify(body)
|
|
41389
|
-
});
|
|
41390
|
-
}
|
|
41391
|
-
/**
|
|
41392
|
-
* PUT a JSON body to a path.
|
|
41393
|
-
*
|
|
41394
|
-
* @param path - Path appended to the base URL.
|
|
41395
|
-
* @param body - Payload serialized as JSON.
|
|
41396
|
-
* @returns Parsed JSON response body.
|
|
41397
|
-
*/
|
|
41398
|
-
put(path8, body) {
|
|
41399
|
-
return this.request(path8, {
|
|
41400
|
-
method: "PUT",
|
|
41401
|
-
headers: { "Content-Type": "application/json" },
|
|
41402
|
-
body: JSON.stringify(body)
|
|
41403
|
-
});
|
|
41404
|
-
}
|
|
41405
|
-
/**
|
|
41406
|
-
* List all datasources.
|
|
41407
|
-
*
|
|
41408
|
-
* @returns Parsed JSON response body.
|
|
41409
|
-
*/
|
|
41410
|
-
listDatasources() {
|
|
41411
|
-
return this.request("/datasources");
|
|
41412
|
-
}
|
|
41413
|
-
/**
|
|
41414
|
-
* Get table grants for a datasource.
|
|
41415
|
-
*
|
|
41416
|
-
* @param datasourceId - Datasource identifier.
|
|
41417
|
-
* @returns Parsed JSON response body.
|
|
41418
|
-
*/
|
|
41419
|
-
getTableGrants(datasourceId) {
|
|
41420
|
-
return this.request(`/datasources/${encodeURIComponent(datasourceId)}/table-grants`);
|
|
41421
|
-
}
|
|
41422
|
-
/**
|
|
41423
|
-
* Run a read-only SQL query against a datasource.
|
|
41424
|
-
*
|
|
41425
|
-
* @param datasourceId - Datasource identifier.
|
|
41426
|
-
* @param input - Query input: `sql` (SELECT/WITH only), optional `params`, `maxRows`, `debug`.
|
|
41427
|
-
* @returns Parsed JSON response body.
|
|
41428
|
-
* @throws When `sql` fails read-only validation (rejected before any fetch).
|
|
41429
|
-
*/
|
|
41430
|
-
async queryDatasource(datasourceId, input) {
|
|
41431
|
-
const validation = validateSql(input.sql);
|
|
41432
|
-
if (!validation.ok) throw new Error(`SQL_NOT_ALLOWED: ${validation.reason}`);
|
|
41433
|
-
return this.post(`/datasources/${encodeURIComponent(datasourceId)}/query`, input);
|
|
41434
|
-
}
|
|
41435
|
-
/**
|
|
41436
|
-
* Test a datasource connection.
|
|
41437
|
-
*
|
|
41438
|
-
* @param datasourceId - Datasource identifier.
|
|
41439
|
-
* @returns Parsed JSON response body.
|
|
41440
|
-
*/
|
|
41441
|
-
testDatasource(datasourceId) {
|
|
41442
|
-
return this.post(`/datasources/${encodeURIComponent(datasourceId)}/test`, {});
|
|
41443
|
-
}
|
|
41444
|
-
/**
|
|
41445
|
-
* Get connection-pool status for a datasource.
|
|
41446
|
-
*
|
|
41447
|
-
* @param datasourceId - Datasource identifier.
|
|
41448
|
-
* @returns Parsed JSON response body.
|
|
41449
|
-
*/
|
|
41450
|
-
getPoolStatus(datasourceId) {
|
|
41451
|
-
return this.request(`/datasources/${encodeURIComponent(datasourceId)}/pool`);
|
|
41452
|
-
}
|
|
41453
|
-
/**
|
|
41454
|
-
* List table metadata for a datasource, auto-paginating.
|
|
41455
|
-
*
|
|
41456
|
-
* The server pages this collection (`page`/`pageSize`, default page size 20),
|
|
41457
|
-
* so requests aggregate every page into one `{ items, total }` result.
|
|
41458
|
-
*
|
|
41459
|
-
* @param datasourceId - Datasource identifier.
|
|
41460
|
-
* @returns `{ items: [...], total }` covering all pages.
|
|
41461
|
-
*/
|
|
41462
|
-
async listTables(datasourceId) {
|
|
41463
|
-
return this.listMetaPage(`/datasources/${encodeURIComponent(datasourceId)}/meta/tables`);
|
|
41464
|
-
}
|
|
41465
|
-
/**
|
|
41466
|
-
* Shared pagination walk for the paged meta collections (`{items,total,page,pageSize}`).
|
|
41467
|
-
*
|
|
41468
|
-
* @param basePath - Collection path (tables or metrics).
|
|
41469
|
-
* @returns `{ items, total }` aggregated across all pages.
|
|
41470
|
-
*/
|
|
41471
|
-
async listMetaPage(basePath) {
|
|
41472
|
-
const pageSize = 100;
|
|
41473
|
-
const items = [];
|
|
41474
|
-
let total = Number.POSITIVE_INFINITY;
|
|
41475
|
-
for (let page = 1; items.length < total; page += 1) {
|
|
41476
|
-
const body = await this.request(`${basePath}?page=${page}&pageSize=${pageSize}`);
|
|
41477
|
-
const record = body !== null && typeof body === "object" ? body : {};
|
|
41478
|
-
const batch = Array.isArray(record.items) ? record.items : [];
|
|
41479
|
-
items.push(...batch);
|
|
41480
|
-
total = typeof record.total === "number" ? record.total : items.length;
|
|
41481
|
-
if (batch.length === 0) break;
|
|
41482
|
-
}
|
|
41483
|
-
return { items, total: items.length };
|
|
41484
|
-
}
|
|
41485
|
-
/**
|
|
41486
|
-
* Get metadata for a single table.
|
|
41487
|
-
*
|
|
41488
|
-
* @param datasourceId - Datasource identifier.
|
|
41489
|
-
* @param tableKey - Table key.
|
|
41490
|
-
* @returns Parsed JSON response body.
|
|
41491
|
-
*/
|
|
41492
|
-
getTable(datasourceId, tableKey) {
|
|
41493
|
-
return this.request(
|
|
41494
|
-
`/datasources/${encodeURIComponent(datasourceId)}/meta/tables/${encodeURIComponent(tableKey)}`
|
|
41495
|
-
);
|
|
41496
|
-
}
|
|
41497
|
-
/**
|
|
41498
|
-
* Create a table definition for a datasource.
|
|
41499
|
-
*
|
|
41500
|
-
* @param datasourceId - Datasource identifier.
|
|
41501
|
-
* @param payload - Table definition payload.
|
|
41502
|
-
* @returns Parsed JSON response body.
|
|
41503
|
-
*/
|
|
41504
|
-
createTable(datasourceId, payload) {
|
|
41505
|
-
return this.post(`/datasources/${encodeURIComponent(datasourceId)}/meta/tables`, payload);
|
|
41506
|
-
}
|
|
41507
|
-
/**
|
|
41508
|
-
* Update a table definition for a datasource.
|
|
41509
|
-
*
|
|
41510
|
-
* @param datasourceId - Datasource identifier.
|
|
41511
|
-
* @param tableKey - Table key.
|
|
41512
|
-
* @param payload - Table definition payload.
|
|
41513
|
-
* @returns Parsed JSON response body.
|
|
41514
|
-
*/
|
|
41515
|
-
/**
|
|
41516
|
-
* Update a published table meta via read-modify-write.
|
|
41517
|
-
*
|
|
41518
|
-
* The server's PUT replaces the whole payload, so the current payload is
|
|
41519
|
-
* fetched first and the incoming fields are merged on top; fields not
|
|
41520
|
-
* mentioned are preserved.
|
|
41521
|
-
*/
|
|
41522
|
-
async updateTable(datasourceId, tableKey, payload) {
|
|
41523
|
-
const existing = await this.readMetaPayload(`${this.baseUrl}/datasources/${encodeURIComponent(datasourceId)}/meta/tables/${encodeURIComponent(tableKey)}`);
|
|
41524
|
-
return this.put(
|
|
41525
|
-
`/datasources/${encodeURIComponent(datasourceId)}/meta/tables/${encodeURIComponent(tableKey)}`,
|
|
41526
|
-
{ payload: { ...existing, ...payload } }
|
|
41527
|
-
);
|
|
41528
|
-
}
|
|
41529
|
-
/**
|
|
41530
|
-
* List metric definitions for a datasource.
|
|
41531
|
-
*
|
|
41532
|
-
* @param datasourceId - Datasource identifier.
|
|
41533
|
-
* @returns Parsed JSON response body.
|
|
41534
|
-
*/
|
|
41535
|
-
/**
|
|
41536
|
-
* List metric metadata for a datasource, auto-paginating.
|
|
41537
|
-
*
|
|
41538
|
-
* The server pages this collection (`page`/`pageSize`, default page size 20),
|
|
41539
|
-
* so requests aggregate every page into one `{ items, total }` result.
|
|
41540
|
-
*
|
|
41541
|
-
* @param datasourceId - Datasource identifier.
|
|
41542
|
-
* @returns `{ items: [...], total }` covering all pages.
|
|
41543
|
-
*/
|
|
41544
|
-
async listMetrics(datasourceId) {
|
|
41545
|
-
return this.listMetaPage(`/datasources/${encodeURIComponent(datasourceId)}/meta/metrics`);
|
|
41546
|
-
}
|
|
41547
|
-
/**
|
|
41548
|
-
* Get a single metric definition.
|
|
41549
|
-
*
|
|
41550
|
-
* @param datasourceId - Datasource identifier.
|
|
41551
|
-
* @param metricKey - Metric key.
|
|
41552
|
-
* @returns Parsed JSON response body.
|
|
41553
|
-
*/
|
|
41554
|
-
getMetric(datasourceId, metricKey) {
|
|
41555
|
-
return this.request(
|
|
41556
|
-
`/datasources/${encodeURIComponent(datasourceId)}/meta/metrics/${encodeURIComponent(metricKey)}`
|
|
41557
|
-
);
|
|
41558
|
-
}
|
|
41559
|
-
/**
|
|
41560
|
-
* Create a metric definition for a datasource.
|
|
41561
|
-
*
|
|
41562
|
-
* @param datasourceId - Datasource identifier.
|
|
41563
|
-
* @param payload - Metric definition payload.
|
|
41564
|
-
* @returns Parsed JSON response body.
|
|
41565
|
-
*/
|
|
41566
|
-
createMetric(datasourceId, payload) {
|
|
41567
|
-
return this.post(`/datasources/${encodeURIComponent(datasourceId)}/meta/metrics`, payload);
|
|
41568
|
-
}
|
|
41569
|
-
/**
|
|
41570
|
-
* Update a metric definition for a datasource.
|
|
41571
|
-
*
|
|
41572
|
-
* @param datasourceId - Datasource identifier.
|
|
41573
|
-
* @param metricKey - Metric key.
|
|
41574
|
-
* @param payload - Metric definition payload.
|
|
41575
|
-
* @returns Parsed JSON response body.
|
|
41576
|
-
*/
|
|
41577
|
-
/**
|
|
41578
|
-
* Update a published metric meta via read-modify-write.
|
|
41579
|
-
*
|
|
41580
|
-
* The server's PUT replaces the whole payload, so the current payload is
|
|
41581
|
-
* fetched first and the incoming fields are merged on top; fields not
|
|
41582
|
-
* mentioned are preserved.
|
|
41583
|
-
*/
|
|
41584
|
-
async updateMetric(datasourceId, metricKey, payload) {
|
|
41585
|
-
const existing = await this.readMetaPayload(`${this.baseUrl}/datasources/${encodeURIComponent(datasourceId)}/meta/metrics/${encodeURIComponent(metricKey)}`);
|
|
41586
|
-
return this.put(
|
|
41587
|
-
`/datasources/${encodeURIComponent(datasourceId)}/meta/metrics/${encodeURIComponent(metricKey)}`,
|
|
41588
|
-
{ payload: { ...existing, ...payload } }
|
|
41589
|
-
);
|
|
41590
|
-
}
|
|
41591
|
-
/**
|
|
41592
|
-
* Fetch the current `payload` object of a published meta entry.
|
|
41593
|
-
*
|
|
41594
|
-
* The single-entry read returns `{ code, data: [entry] }` (already unwrapped
|
|
41595
|
-
* to the array by {@link request}); the payload lives on the first entry.
|
|
41596
|
-
*
|
|
41597
|
-
* @param absoluteUrl - Full URL of the single-entry meta read.
|
|
41598
|
-
* @returns The stored payload object (empty when none exists).
|
|
41599
|
-
*/
|
|
41600
|
-
async readMetaPayload(absoluteUrl) {
|
|
41601
|
-
const response = await fetch(absoluteUrl, { headers: this.getHeaders() });
|
|
41602
|
-
const text = await response.text().catch(() => "");
|
|
41603
|
-
if (!response.ok) {
|
|
41604
|
-
throw new Error(`HTTP ${response.status}: ${text || response.statusText}`);
|
|
41605
|
-
}
|
|
41606
|
-
const parsed = this.parseBody(text);
|
|
41607
|
-
const data = parsed?.envelope === true ? parsed.data : parsed?.value;
|
|
41608
|
-
const entry = Array.isArray(data) ? data[0] : data;
|
|
41609
|
-
const payload = entry?.payload;
|
|
41610
|
-
return payload !== null && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
41611
|
-
}
|
|
41612
|
-
/**
|
|
41613
|
-
* Get runtime metadata for a datasource.
|
|
41614
|
-
*
|
|
41615
|
-
* @param datasourceId - Datasource identifier.
|
|
41616
|
-
* @returns Parsed JSON response body.
|
|
41617
|
-
*/
|
|
41618
|
-
getRuntimeMeta(datasourceId) {
|
|
41619
|
-
return this.request(`/datasources/${encodeURIComponent(datasourceId)}/meta`);
|
|
41620
|
-
}
|
|
41621
|
-
/**
|
|
41622
|
-
* Run a metrics query.
|
|
41623
|
-
*
|
|
41624
|
-
* @param request - Metrics query request payload.
|
|
41625
|
-
* @returns Parsed JSON response body.
|
|
41626
|
-
*/
|
|
41627
|
-
queryMetrics(request) {
|
|
41628
|
-
return this.post("/metrics/query", request);
|
|
41629
|
-
}
|
|
41630
|
-
/**
|
|
41631
|
-
* Run an ad-hoc custom SQL query, validated as read-only before sending.
|
|
41632
|
-
*
|
|
41633
|
-
* @param request - Request with `datasourceId`, `customSql` (SELECT/WITH only),
|
|
41634
|
-
* and optional `limit` / `debug`.
|
|
41635
|
-
* @returns Parsed JSON response body.
|
|
41636
|
-
* @throws When `customSql` fails read-only validation (rejected before any fetch).
|
|
41637
|
-
*/
|
|
41638
|
-
async customSql(request) {
|
|
41639
|
-
const validation = validateSql(request.customSql);
|
|
41640
|
-
if (!validation.ok) throw new Error(`SQL_NOT_ALLOWED: ${validation.reason}`);
|
|
41641
|
-
return this.post("/metrics/query", request);
|
|
41642
|
-
}
|
|
41643
|
-
};
|
|
41644
|
-
|
|
41645
|
-
// src/tool_lattice/semantic_metrics/metrics_datasource_tool.ts
|
|
41646
|
-
var DESCRIPTION = `PHYSICAL LAYER EXPLORATION \u2014 the only tool for probing raw datasource structure (Builder/Admin only; business agents do not need it).
|
|
41647
|
-
|
|
41648
|
-
OWNS: discovering datasources, reading table-grants (the exploration boundary for this tenant), and running read-only SQL (SELECT/WITH only) to inspect physical tables, columns, sample rows, and value distributions. Also: per-datasource connection test and pool status.
|
|
41649
|
-
|
|
41650
|
-
DOES NOT OWN:
|
|
41651
|
-
- Published semantic assets (table meta / metric meta) \u2192 use metrics_meta_tool.
|
|
41652
|
-
- Runtime meta and business metric queries \u2192 use metrics_runtime_tool.
|
|
41653
|
-
|
|
41654
|
-
USE WHEN: starting a modeling task \u2014 \`list_datasources\` is always the FIRST step: it returns the datasource ids that every other action and tool requires (get_grants, query_sql here; read_semantic_catalog, query_metrics in metrics_runtime_tool; the meta actions in metrics_meta_tool). Read grants next, then probe tables, columns, samples, and distributions within the grant. If a field's business meaning is unclear, probe sample values and distributions here before publishing anything.
|
|
41655
|
-
|
|
41656
|
-
COMMON MISTAKES (do not):
|
|
41657
|
-
- Do not answer business metric questions here (e.g. "monthly sales by region") \u2014 that is metrics_runtime_tool \`query\` against published metrics, NOT this tool's \`query_sql\` (physical-table SQL).
|
|
41658
|
-
- Do not read or publish semantic meta through this tool \u2014 metrics_meta_tool owns the semantic layer.
|
|
41659
|
-
- Do not probe tables outside the tenant's table-grants; un-granted probes are rejected and break the exploration boundary.
|
|
41660
|
-
- Do not attempt writes \u2014 SQL is validated read-only and rejected before sending.`;
|
|
41661
|
-
function createMetricsDatasourceTool(params) {
|
|
41662
|
-
const { connectionType, connections, connectAll } = params;
|
|
41663
|
-
return (0, import_langchain67.tool)(
|
|
41664
|
-
async (input, exeConfig) => {
|
|
41665
|
-
try {
|
|
41666
|
-
const client = await resolveMetricsClientFromSelector(
|
|
41667
|
-
{ connectionType, connections, connectAll },
|
|
41668
|
-
readToolRunConfig(exeConfig) ?? {},
|
|
41669
|
-
input.connectionKey
|
|
41670
|
-
);
|
|
41671
|
-
const scope = effectiveDatasourceScope(client.getSelectedEntities());
|
|
41672
|
-
switch (input.action) {
|
|
41673
|
-
case "list_datasources": {
|
|
41674
|
-
const result = await client.listDatasources();
|
|
41675
|
-
const filtered = scope.unrestricted ? result : result.filter((d) => scope.ids.includes(Number(d.id)));
|
|
41676
|
-
const safe = filtered.map((d) => ({
|
|
41677
|
-
id: d.id,
|
|
41678
|
-
name: d.name,
|
|
41679
|
-
sourceType: d.sourceType,
|
|
41680
|
-
description: d.description,
|
|
41681
|
-
statusLabel: d.statusLabel
|
|
41682
|
-
}));
|
|
41683
|
-
return JSON.stringify(safe, null, 2);
|
|
41684
|
-
}
|
|
41685
|
-
case "get_grants": {
|
|
41686
|
-
const ds = resolveDatasourceId(input, exeConfig);
|
|
41687
|
-
assertDatasourceSelected(scope, ds);
|
|
41688
|
-
const result = await client.getTableGrants(ds);
|
|
41689
|
-
return JSON.stringify(result, null, 2);
|
|
41690
|
-
}
|
|
41691
|
-
case "query_sql": {
|
|
41692
|
-
const ds = resolveDatasourceId(input, exeConfig);
|
|
41693
|
-
assertDatasourceSelected(scope, ds);
|
|
41694
|
-
if (!input.sql) throw new Error("sql is required for the 'query_sql' action");
|
|
41695
|
-
const result = await client.queryDatasource(ds, {
|
|
41696
|
-
sql: input.sql,
|
|
41697
|
-
params: input.params,
|
|
41698
|
-
maxRows: input.maxRows
|
|
41699
|
-
});
|
|
41700
|
-
return JSON.stringify(result, null, 2);
|
|
41701
|
-
}
|
|
41702
|
-
case "test_connection": {
|
|
41703
|
-
const ds = resolveDatasourceId(input, exeConfig);
|
|
41704
|
-
assertDatasourceSelected(scope, ds);
|
|
41705
|
-
const result = await client.testDatasource(ds);
|
|
41706
|
-
return JSON.stringify(result, null, 2);
|
|
41707
|
-
}
|
|
41708
|
-
case "pool_status": {
|
|
41709
|
-
const ds = resolveDatasourceId(input, exeConfig);
|
|
41710
|
-
assertDatasourceSelected(scope, ds);
|
|
41711
|
-
const result = await client.getPoolStatus(ds);
|
|
41712
|
-
return JSON.stringify(result, null, 2);
|
|
41713
|
-
}
|
|
41714
|
-
}
|
|
41715
|
-
} catch (error) {
|
|
41716
|
-
return `Error: ${error instanceof Error ? error.message : String(error)}`;
|
|
41717
|
-
}
|
|
41718
|
-
},
|
|
41719
|
-
{
|
|
41720
|
-
name: "metrics_datasource_tool",
|
|
41721
|
-
description: DESCRIPTION,
|
|
41722
|
-
schema: import_zod55.default.object({
|
|
41723
|
-
action: import_zod55.default.enum(["list_datasources", "get_grants", "query_sql", "test_connection", "pool_status"]).describe(
|
|
41724
|
-
"list_datasources: list datasources \u2014 ALWAYS call this first to obtain the datasource id used by every other action and tool; get_grants: read table-grants; query_sql: run read-only SQL against PHYSICAL tables (note: this is query_sql, NOT the semantic 'query' action of metrics_runtime_tool); test_connection: test the datasource; pool_status: connection-pool status"
|
|
41725
|
-
),
|
|
41726
|
-
connectionKey: import_zod55.default.string().optional().describe("Connection key. Omit when only one semantic-metrics connection exists"),
|
|
41727
|
-
datasourceId: import_zod55.default.coerce.number().optional().describe("Numeric datasource id, e.g. 15 (required for all actions except list_datasources; optional if set in runConfig.metricsDataSource)"),
|
|
41728
|
-
sql: import_zod55.default.string().optional().describe("Read-only SQL (SELECT/WITH only). Required for the query action. Metadata templates \u2014 PostgreSQL/SQL Server columns: select column_name, data_type from information_schema.columns where table_schema = :schemaName and table_name = :tableName order by ordinal_position; HANA columns: select column_name, data_type_name from table_columns where schema_name = :schemaName and table_name = :tableName order by position; distributions: select <dim>, count(*) as row_count from <table> group by <dim> order by row_count desc limit :maxRows"),
|
|
41729
|
-
params: import_zod55.default.record(import_zod55.default.union([import_zod55.default.string(), import_zod55.default.number(), import_zod55.default.boolean()])).optional().describe("Named :param values for the SQL"),
|
|
41730
|
-
maxRows: import_zod55.default.number().optional().describe("Max rows to return")
|
|
41731
|
-
})
|
|
41732
|
-
}
|
|
41733
|
-
);
|
|
41734
|
-
}
|
|
41735
|
-
|
|
41736
|
-
// src/tool_lattice/semantic_metrics/metrics_meta_tool.ts
|
|
41737
|
-
var import_zod56 = __toESM(require("zod"));
|
|
41738
|
-
var import_langchain68 = require("langchain");
|
|
41739
|
-
var DESCRIPTION2 = `SEMANTIC ASSET REGISTRY (Builder/Admin only) \u2014 the only tool for reading and publishing the runtime's semantic layer: table meta (meta/tables) and metric meta (meta/metrics).
|
|
41740
|
-
|
|
41741
|
-
OWNS: listing published tables and metrics, reading one by objectKey, publishing a semantic table (create_table: columns tagged with role dimension|measure), publishing a metric (create_metric: a metric_index payload then a metric_detail payload using the SQL-free calculation DSL), and correcting published assets (update_table / update_metric).
|
|
41742
|
-
|
|
41743
|
-
DOES NOT OWN:
|
|
41744
|
-
- Running queries or reading the aggregated runtime view \u2192 metrics_runtime_tool (get_meta / query / custom_sql).
|
|
41745
|
-
- Probing physical tables, columns, grants, or samples \u2192 metrics_datasource_tool.
|
|
41746
|
-
|
|
41747
|
-
USE WHEN: physical exploration is done and the model has been proposed and confirmed by the user \u2014 to publish the semantic table and metrics, or to correct published assets afterwards.
|
|
41748
|
-
|
|
41749
|
-
COMMON MISTAKES (do not):
|
|
41750
|
-
- Do not call get_meta here \u2014 that action belongs to metrics_runtime_tool, not this tool.
|
|
41751
|
-
- Do not try to "query numbers" through this tool \u2014 list/read actions return definitions only; use metrics_runtime_tool query for data.
|
|
41752
|
-
- Do not publish a metric whose sourceTable has no published table meta, or whose dimensions are not published columns with role dimension \u2014 the server will reject it.
|
|
41753
|
-
- The builder assistant must load the semantic-metrics-modeling skill and pass modelingSkillLoaded: true on write actions; no removal actions are exposed on purpose.`;
|
|
41754
|
-
var MODELING_SKILL_NAME = "semantic-metrics-modeling";
|
|
41755
|
-
var BUILDER_ASSISTANT_ID = "semantic-metrics-builder";
|
|
41756
|
-
function requireModelingSkillLoaded(action, input, exeConfig) {
|
|
41757
|
-
const isWriteAction = action === "create_table" || action === "update_table" || action === "create_metric" || action === "update_metric";
|
|
41758
|
-
if (!isWriteAction) return void 0;
|
|
41759
|
-
const runConfig = readToolRunConfig(exeConfig);
|
|
41760
|
-
const assistantId = runConfig?.assistant_id;
|
|
41761
|
-
if (assistantId === BUILDER_ASSISTANT_ID && input.modelingSkillLoaded !== true) {
|
|
41762
|
-
return JSON.stringify({
|
|
41763
|
-
success: false,
|
|
41764
|
-
error: `Load the '${MODELING_SKILL_NAME}' skill before publishing meta.`
|
|
41765
|
-
});
|
|
41766
|
-
}
|
|
41767
|
-
return void 0;
|
|
41768
|
-
}
|
|
41769
|
-
function actionRequiresPayload(action) {
|
|
41770
|
-
return action === "create_table" || action === "update_table" || action === "create_metric" || action === "update_metric";
|
|
41771
|
-
}
|
|
41772
|
-
function createMetricsMetaTool(params) {
|
|
41773
|
-
const { connectionType, connections, connectAll } = params;
|
|
41774
|
-
return (0, import_langchain68.tool)(
|
|
41775
|
-
async (input, exeConfig) => {
|
|
41776
|
-
try {
|
|
41777
|
-
const guardError = requireModelingSkillLoaded(input.action, input, exeConfig);
|
|
41778
|
-
if (guardError !== void 0) return guardError;
|
|
41779
|
-
const client = await resolveMetricsClientFromSelector(
|
|
41780
|
-
{ connectionType, connections, connectAll },
|
|
41781
|
-
readToolRunConfig(exeConfig) ?? {},
|
|
41782
|
-
input.connectionKey
|
|
41783
|
-
);
|
|
41784
|
-
const ds = resolveDatasourceId(input, exeConfig);
|
|
41785
|
-
assertDatasourceSelected(effectiveDatasourceScope(client.getSelectedEntities()), ds);
|
|
41786
|
-
if (actionRequiresPayload(input.action) && input.payload === void 0) {
|
|
41787
|
-
throw new Error(`payload is required for ${input.action}`);
|
|
41788
|
-
}
|
|
41789
|
-
const payload = input.payload ?? {};
|
|
41790
|
-
switch (input.action) {
|
|
41791
|
-
case "list_tables": {
|
|
41792
|
-
return JSON.stringify(await client.listTables(ds), null, 2);
|
|
41793
|
-
}
|
|
41794
|
-
case "read_table_meta": {
|
|
41795
|
-
if (!input.objectKey) throw new Error("objectKey is required for read_table_meta");
|
|
41796
|
-
return JSON.stringify(await client.getTable(ds, input.objectKey), null, 2);
|
|
41797
|
-
}
|
|
41798
|
-
case "create_table": {
|
|
41799
|
-
return JSON.stringify(await client.createTable(ds, payload), null, 2);
|
|
41800
|
-
}
|
|
41801
|
-
case "update_table": {
|
|
41802
|
-
if (!input.objectKey) throw new Error("objectKey is required for update_table");
|
|
41803
|
-
return JSON.stringify(await client.updateTable(ds, input.objectKey, payload), null, 2);
|
|
41804
|
-
}
|
|
41805
|
-
case "list_metrics": {
|
|
41806
|
-
return JSON.stringify(await client.listMetrics(ds), null, 2);
|
|
41807
|
-
}
|
|
41808
|
-
case "read_metric_meta": {
|
|
41809
|
-
if (!input.objectKey) throw new Error("objectKey is required for read_metric_meta");
|
|
41810
|
-
return JSON.stringify(await client.getMetric(ds, input.objectKey), null, 2);
|
|
41811
|
-
}
|
|
41812
|
-
case "create_metric": {
|
|
41813
|
-
return JSON.stringify(await client.createMetric(ds, payload), null, 2);
|
|
41814
|
-
}
|
|
41815
|
-
case "update_metric": {
|
|
41816
|
-
if (!input.objectKey) throw new Error("objectKey is required for update_metric");
|
|
41817
|
-
return JSON.stringify(await client.updateMetric(ds, input.objectKey, payload), null, 2);
|
|
41818
|
-
}
|
|
41819
|
-
}
|
|
41820
|
-
} catch (error) {
|
|
41821
|
-
return `Error: ${error instanceof Error ? error.message : String(error)}`;
|
|
41822
|
-
}
|
|
41823
|
-
},
|
|
41824
|
-
{
|
|
41825
|
-
name: "metrics_meta_tool",
|
|
41826
|
-
description: DESCRIPTION2,
|
|
41827
|
-
schema: import_zod56.default.object({
|
|
41828
|
-
action: import_zod56.default.enum([
|
|
41829
|
-
"list_tables",
|
|
41830
|
-
"read_table_meta",
|
|
41831
|
-
"create_table",
|
|
41832
|
-
"update_table",
|
|
41833
|
-
"list_metrics",
|
|
41834
|
-
"read_metric_meta",
|
|
41835
|
-
"create_metric",
|
|
41836
|
-
"update_metric"
|
|
41837
|
-
]).describe(
|
|
41838
|
-
"Actions ONLY in this meta tool (runtime query actions like get_meta/query belong to metrics_runtime_tool): list_tables/list_metrics (browse published assets), read_table_meta/read_metric_meta (details by objectKey), create_table/create_metric (publish), update_table/update_metric (correct)"
|
|
41839
|
-
),
|
|
41840
|
-
connectionKey: import_zod56.default.string().optional().describe("Connection key. Omit when only one semantic-metrics connection exists"),
|
|
41841
|
-
datasourceId: import_zod56.default.coerce.number().optional().describe("Numeric datasource id, e.g. 15 (optional if set in runConfig.metricsDataSource)"),
|
|
41842
|
-
objectKey: import_zod56.default.string().optional().describe("Semantic table/metric key (required for read_table_meta/update_table/read_metric_meta/update_metric)"),
|
|
41843
|
-
payload: import_zod56.default.record(import_zod56.default.unknown()).optional().describe("Meta payload (required for create/update actions; objectType/objectKey/status/payload/accessGrant)"),
|
|
41844
|
-
modelingSkillLoaded: import_zod56.default.literal(true).optional().describe("Set true after loading the semantic-metrics-modeling skill (required for the builder assistant on write actions)")
|
|
41845
|
-
})
|
|
41846
|
-
}
|
|
41847
|
-
);
|
|
41848
|
-
}
|
|
41849
|
-
|
|
41850
|
-
// src/tool_lattice/semantic_metrics/metrics_runtime_tool.ts
|
|
41851
|
-
var import_zod57 = __toESM(require("zod"));
|
|
41852
|
-
var import_langchain69 = require("langchain");
|
|
41853
|
-
var DESCRIPTION3 = `RUNTIME QUERY SURFACE \u2014 read what is published and answer business questions with numbers. Business agents use ONLY this tool; Builder agents also use it to verify freshly published metrics.
|
|
41854
|
-
|
|
41855
|
-
OWNS: list_datasources (self-contained datasource discovery \u2014 redacted output, the first step before anything else), read_semantic_catalog (the published semantic model for a datasource: tables, metrics, dimensions, filters) and query_metrics (the semantic metric query: metrics / groupBy / filters / orderBy / limit \u2014 the server generates the SQL, so there is no free-form SQL here).
|
|
41856
|
-
|
|
41857
|
-
DOES NOT OWN:
|
|
41858
|
-
- Publishing or correcting semantic tables/metrics \u2192 metrics_meta_tool (create_table/update_table/create_metric/update_metric/list_tables/read_table_meta/list_metrics/read_metric_meta).
|
|
41859
|
-
- Physical exploration of raw tables, grants, or samples \u2192 metrics_datasource_tool (query_sql).
|
|
41860
|
-
- Free-form custom SQL \u2014 intentionally not provided; use query against published metrics.
|
|
41861
|
-
|
|
41862
|
-
USE WHEN: read_semantic_catalog to see what is published before asking numbers; query_metrics to answer a business question from already-published metrics (Business) or to verify a just-published metric against its acceptance evidence (Builder).
|
|
41863
|
-
|
|
41864
|
-
COMMON MISTAKES (do not):
|
|
41865
|
-
- Do not call meta-tool actions here (create_table / update_table / create_metric / update_metric / list_tables / read_table_meta / list_metrics / read_metric_meta) \u2014 they live in metrics_meta_tool and will fail schema validation here.
|
|
41866
|
-
- Do not look for a custom-SQL action \u2014 there is none; explore physical data with metrics_datasource_tool query_sql, and query business numbers with the semantic query action.
|
|
41867
|
-
- Metrics and dimensions in query_metrics must already be published; querying an unpublished metric fails with "not found in catalog".`;
|
|
41868
|
-
function createMetricsRuntimeTool(params) {
|
|
41869
|
-
const { connectionType, connections, connectAll } = params;
|
|
41870
|
-
return (0, import_langchain69.tool)(
|
|
41871
|
-
async (input, exeConfig) => {
|
|
41872
|
-
try {
|
|
41873
|
-
const client = await resolveMetricsClientFromSelector(
|
|
41874
|
-
{ connectionType, connections, connectAll },
|
|
41875
|
-
readToolRunConfig(exeConfig) ?? {},
|
|
41876
|
-
input.connectionKey
|
|
41877
|
-
);
|
|
41878
|
-
const scope = effectiveDatasourceScope(client.getSelectedEntities());
|
|
41879
|
-
switch (input.action) {
|
|
41880
|
-
case "list_datasources": {
|
|
41881
|
-
const result = await client.listDatasources();
|
|
41882
|
-
const filtered = scope.unrestricted ? result : result.filter((d) => scope.ids.includes(Number(d.id)));
|
|
41883
|
-
const safe = filtered.map((d) => ({
|
|
41884
|
-
id: d.id,
|
|
41885
|
-
name: d.name,
|
|
41886
|
-
sourceType: d.sourceType,
|
|
41887
|
-
description: d.description,
|
|
41888
|
-
statusLabel: d.statusLabel
|
|
41889
|
-
}));
|
|
41890
|
-
return JSON.stringify(safe, null, 2);
|
|
41891
|
-
}
|
|
41892
|
-
case "read_semantic_catalog": {
|
|
41893
|
-
const ds = resolveDatasourceId(input, exeConfig);
|
|
41894
|
-
assertDatasourceSelected(scope, ds);
|
|
41895
|
-
return JSON.stringify(await client.getRuntimeMeta(ds), null, 2);
|
|
41896
|
-
}
|
|
41897
|
-
case "query_metrics": {
|
|
41898
|
-
if (!input.query) throw new Error("query is required for the 'query_metrics' action");
|
|
41899
|
-
const bodyDatasourceId = input.query.datasourceId;
|
|
41900
|
-
if (bodyDatasourceId !== void 0) {
|
|
41901
|
-
assertDatasourceSelected(scope, Number(bodyDatasourceId));
|
|
41902
|
-
}
|
|
41903
|
-
return JSON.stringify(await client.queryMetrics(input.query), null, 2);
|
|
41904
|
-
}
|
|
41905
|
-
}
|
|
41906
|
-
} catch (error) {
|
|
41907
|
-
return `Error: ${error instanceof Error ? error.message : String(error)}`;
|
|
41908
|
-
}
|
|
41909
|
-
},
|
|
41910
|
-
{
|
|
41911
|
-
name: "metrics_runtime_tool",
|
|
41912
|
-
description: DESCRIPTION3,
|
|
41913
|
-
schema: import_zod57.default.object({
|
|
41914
|
-
action: import_zod57.default.enum(["list_datasources", "read_semantic_catalog", "query_metrics"]).describe(
|
|
41915
|
-
"Actions ONLY in this runtime tool: list_datasources (list available datasources \u2014 ALWAYS call this first to obtain the datasourceId; output is redacted to non-sensitive fields), read_semantic_catalog (read the published semantic model: tables, metrics, dimensions), query_metrics (run a semantic metric query \u2014 the only way to get business numbers). Do NOT put meta-tool actions (list_tables/read_table_meta/create_table/update_table/list_metrics/read_metric_meta/create_metric/update_metric) here"
|
|
41916
|
-
),
|
|
41917
|
-
connectionKey: import_zod57.default.string().optional().describe("Connection key. Omit when only one semantic-metrics connection exists"),
|
|
41918
|
-
datasourceId: import_zod57.default.coerce.number().optional().describe("Numeric datasource id, e.g. 15 (required for read_semantic_catalog; optional if set in runConfig.metricsDataSource)"),
|
|
41919
|
-
query: import_zod57.default.record(import_zod57.default.unknown()).optional().describe('Semantic metric query request. Required for the query_metrics action, e.g. { datasourceId: 15, metrics: ["sell_in_nes"], groupBy: ["sales_team"], filters: [{ dimension: "posting_year", operator: "GTE", values: [2024] }], limit: 10 }')
|
|
41920
|
-
})
|
|
41921
|
-
}
|
|
41922
|
-
);
|
|
41923
|
-
}
|
|
41924
|
-
|
|
41925
|
-
// src/middlewares/semanticMetricsModelingSkill.ts
|
|
41926
|
-
var CONTENT = `---
|
|
41927
|
-
name: semantic-metrics-modeling
|
|
41928
|
-
description: Builder policy for turning a granted datasource into published semantic tables and metrics. Defines the orchestrator/worker contract \u2014 the orchestrator agrees goals, proposes the model, plans persistent tasks, and delegates execution to general-purpose workers with self-contained briefs; workers execute one bound brief each. Governs goal agreement, delegation, FEP verification, belief-state reconciliation, and continuous refinement until acceptance evidence is met.
|
|
41929
|
-
---
|
|
41930
|
-
|
|
41931
|
-
# Semantic Metrics Modeling
|
|
41932
|
-
|
|
41933
|
-
You are the Semantic Metrics Builder. You turn physical datasource tables into reusable
|
|
41934
|
-
**semantic tables** and **business metrics** on a Metrics Server (\`/api/v1\`). Work is
|
|
41935
|
-
governed, observable, and continuously refined \u2014 never a one-shot guess.
|
|
41936
|
-
|
|
41937
|
-
You always operate in exactly ONE of two roles:
|
|
41938
|
-
|
|
41939
|
-
- **Orchestrator** (default; no \`## Bound Task\` section in your context): you face the
|
|
41940
|
-
user. You agree the Goal Model, propose the model, plan persistent tasks, dispatch
|
|
41941
|
-
execution to workers, reconcile belief, and own every user interaction.
|
|
41942
|
-
- **Worker** (your context contains a \`## Bound Task\` section naming you executor of one
|
|
41943
|
-
task): you execute that task's brief only. See **Worker mode** \u2014 its rules override the
|
|
41944
|
-
orchestrator policy.
|
|
41945
|
-
|
|
41946
|
-
## Goal Model
|
|
41947
|
-
|
|
41948
|
-
Before any exploration or publishing, agree with the user on:
|
|
41949
|
-
- **Real goal**: the business outcome (which metrics, for what decision), not just "make a table".
|
|
41950
|
-
- **Consumer**: who reads the result and how.
|
|
41951
|
-
- **Usable state**: observable conditions that make the published meta useful.
|
|
41952
|
-
- **Scope**: which datasource/tables, and what is explicitly out of scope.
|
|
41953
|
-
- **Acceptance evidence**: objective criteria (e.g. "metric \`sell_in_nes\` returns sane monthly
|
|
41954
|
-
totals for 2024") used to decide success. Verbatim acceptance evidence is required later by
|
|
41955
|
-
the Verify dispatch \u2014 record it exactly.
|
|
41956
|
-
Do not guess material goals, consumers, or acceptance evidence.
|
|
41957
|
-
|
|
41958
|
-
**Vague requests** (e.g. "build the metric layer") \u2014 do not act and do not ask blind questions.
|
|
41959
|
-
First run cheap read-only observations (\`list_datasources\`, \`get_grants\`, \`list_metrics\`) to
|
|
41960
|
-
see what is authorized and already published, then ask focused questions that carry that
|
|
41961
|
-
context and offer concrete options (which datasource/tables, which business questions, extend
|
|
41962
|
-
existing metrics or build new). Every clarification question must include enough context and
|
|
41963
|
-
options for the user to answer in one step. Only after the user picks a direction does the
|
|
41964
|
-
Goal Model become confirmable \u2014 record it, create the task, and proceed to the workflow.
|
|
41965
|
-
|
|
41966
|
-
## Target model and quality bar
|
|
41967
|
-
|
|
41968
|
-
Your goal is a specific, verifiable artifact, not "some tables and metrics".
|
|
41969
|
-
|
|
41970
|
-
**Target shape** \u2014 one delivery is:
|
|
41971
|
-
- a published \`table_view_detail\` meta per logical table, with every column tagged
|
|
41972
|
-
\`role\` (dimension | measure) and a business-readable \`label\`;
|
|
41973
|
-
- a \`metric_index\` + \`metric_detail\` pair per metric, using the SQL-free \`calculation\` DSL;
|
|
41974
|
-
- the set, taken together, answers the user's concrete business question.
|
|
41975
|
-
|
|
41976
|
-
**Publish gate (self-check every metric before create)** \u2014 if any fails, do **not** publish; go
|
|
41977
|
-
explore or ask the user:
|
|
41978
|
-
1. measure: an aggregation is chosen **and** its business meaning is confirmed (net/gross, currency, dedupe or not);
|
|
41979
|
-
2. dimension: has a business meaning and a grain (day/month/year/\u2026);
|
|
41980
|
-
3. \`displayName\`/\`label\` are business-readable;
|
|
41981
|
-
4. the metric answers one concrete question from the user's stated goal;
|
|
41982
|
-
5. a runtime \`query\` returns numbers consistent with the confirmed meaning.
|
|
41983
|
-
|
|
41984
|
-
**Intent gaps first** \u2014 before diving into exploration, list the inputs you still need to meet the
|
|
41985
|
-
quality bar (business meaning, grain, target metric list, table scope, consumer) and ask for them
|
|
41986
|
-
explicitly. Exploration and user questions are both driven by this target shape and quality bar:
|
|
41987
|
-
missing business meaning \u2192 ask; unclear field semantics \u2192 probe or ask; right shape but it does not
|
|
41988
|
-
answer the business question \u2192 do not publish.
|
|
41989
|
-
|
|
41990
|
-
## FEP Loop
|
|
41991
|
-
|
|
41992
|
-
Apply this loop to every step (explore, publish table, publish metric, verify):
|
|
41993
|
-
**OBSERVE \u2192 HYPOTHESIZE \u2192 ACT \u2192 VERIFY \u2192 DECIDE \u2192 RECONCILE**
|
|
41994
|
-
|
|
41995
|
-
- **Observe**: current state, grants, published meta, and decision-relevant uncertainty.
|
|
41996
|
-
- **Hypothesize**: what evidence should appear if your model is right, and how each outcome changes the decision.
|
|
41997
|
-
- **Act**: one proportional action \u2014 no more than necessary.
|
|
41998
|
-
- **Verify**: compare the observed result (e.g. a runtime \`query\`) against the prediction.
|
|
41999
|
-
- **Decide**: classify as **RETAIN** (confirmed), **REVERT** (rejected), or **INCONCLUSIVE**.
|
|
42000
|
-
- **Reconcile**: update the belief state and plan, then repeat while decision-relevant action remains.
|
|
42001
|
-
|
|
42002
|
-
The orchestrator applies the loop **between dispatches** (each observation updates the plan
|
|
42003
|
-
before the next brief is written). A worker applies it **inside its brief**.
|
|
42004
|
-
|
|
42005
|
-
Renew user approval when a foundational assumption or the goal changes.
|
|
42006
|
-
|
|
42007
|
-
## Orchestrator: Task Policy
|
|
42008
|
-
|
|
42009
|
-
You are an orchestrator, not the hands. Exactly five duties:
|
|
42010
|
-
|
|
42011
|
-
1. **Goal Model agreement** \u2014 including cheap read-only observation for vague requests
|
|
42012
|
-
(\`list_datasources\`, \`get_grants\`, \`list_metrics\`). This is your ONLY inline datasource
|
|
42013
|
-
access; do not use \`write_todos\`.
|
|
42014
|
-
2. **Propose the model** and get user approval.
|
|
42015
|
-
3. **Task tree** \u2014 parent task = contract + \`## Belief State\`; child tasks = independently
|
|
42016
|
-
verifiable outcomes (explore / publish-table / publish-metric / verify), one per dispatch.
|
|
42017
|
-
See the \`task-definition\` skill for \`manage_task\` operation details.
|
|
42018
|
-
4. **Dispatch and collect** \u2014 \`task { taskId, agentId: "general-purpose" }\`; read the
|
|
42019
|
-
observation; record the \`executionResultId\` on the child task with \`manage_task update\` or
|
|
42020
|
-
\`add_activity\`; reconcile \`## Belief State\`.
|
|
42021
|
-
5. **HITL** \u2014 every \`ask_user_to_clarify\` is yours. Workers never ask the user.
|
|
42022
|
-
|
|
42023
|
-
Hard rules:
|
|
42024
|
-
- Never run exploration SQL inline. Never build or publish payloads inline (sole exception:
|
|
42025
|
-
the Publish/Verify inline fallback below).
|
|
42026
|
-
- **Belief State: you are the sole writer.** Workers return findings in their results; you
|
|
42027
|
-
update \`## Belief State\` via \`manage_task update\` on the parent task. Workers never touch it.
|
|
42028
|
-
- **Dispatch serially** \u2014 one worker at a time; reconcile belief before writing the next brief.
|
|
42029
|
-
- **Distinguish dispatch failure from worker outcome**: a dispatch failure is a tool-level
|
|
42030
|
-
error where the worker never ran. A worker returning INCONCLUSIVE or failed is a normal FEP
|
|
42031
|
-
input \u2014 reconcile it, never treat it as a dispatch failure.
|
|
42032
|
-
|
|
42033
|
-
Dispatch failure handling (worker never ran, tool error):
|
|
42034
|
-
1. Retry the dispatch once (recreate the child task if the store reports it unusable).
|
|
42035
|
-
2. **Explore: never execute inline.** If the retry fails, stop and ask the user via
|
|
42036
|
-
\`ask_user_to_clarify\` (report what is blocked and why).
|
|
42037
|
-
3. **Publish/Verify: after a failed retry you MAY execute inline** to preserve delivery \u2014
|
|
42038
|
-
the payload decisions are already in your context. Follow the same gate self-check as a
|
|
42039
|
-
worker would.
|
|
42040
|
-
|
|
42041
|
-
## Delegation Protocol
|
|
42042
|
-
|
|
42043
|
-
Mechanics every brief must be designed around:
|
|
42044
|
-
|
|
42045
|
-
- A worker sees ONLY: its task title + description, the parent task's description, and the
|
|
42046
|
-
results of completed dependency tasks. It does NOT see this conversation.
|
|
42047
|
-
- Therefore **every brief is self-contained**: all decisions, boundaries, and evidence travel
|
|
42048
|
-
inside the task description.
|
|
42049
|
-
- Dispatch is synchronous: \`task { taskId, agentId: "general-purpose" }\` returns an
|
|
42050
|
-
observation (the worker's final message, truncated at ~8k chars) and an
|
|
42051
|
-
\`executionResultId\`. Record the id on the child task (\`manage_task update\`/\`add_activity\`).
|
|
42052
|
-
- The worker settles its own task (\`set_status\` with \`result\`/\`failureReason\`). Read both the
|
|
42053
|
-
observation and the task result before reconciling.
|
|
42054
|
-
|
|
42055
|
-
Write briefs as field checklists adapted to the situation \u2014 decisions and evidence, not prose.
|
|
42056
|
-
The worker assembles payloads from the reference sections of this skill; the brief carries the
|
|
42057
|
-
approved decisions, never full payload JSON.
|
|
42058
|
-
|
|
42059
|
-
### Explore brief (\`Explore <schema>.<table> for <goal>\`)
|
|
42060
|
-
|
|
42061
|
-
Required fields:
|
|
42062
|
-
1. Datasource: serverKey/connectionKey + datasourceId (and \`runConfig.metricsDataSource\` preset if present).
|
|
42063
|
-
2. Grant boundary: the allowed schema + table pattern from \`get_grants\`, verbatim; never probe outside it.
|
|
42064
|
-
3. Target table(s): schema-qualified names; one brief per table.
|
|
42065
|
-
4. Question list: per column (or column group) \u2014 business meaning candidates, expected role
|
|
42066
|
-
(dimension | measure | time), net/gross, grain.
|
|
42067
|
-
5. Method: read-only SELECT/WITH only; use the \`references/metadata-sql.md\` templates
|
|
42068
|
-
(columns, sample rows, value distribution); cap sample size (e.g. \u22641000 rows, \u226450 groups).
|
|
42069
|
-
Prefer targeted queries over bulk catalog dumps. A large single read (e.g. full
|
|
42070
|
-
\`read_semantic_catalog\` detail) is allowed \u2014 your isolation protects the orchestrator's
|
|
42071
|
-
context \u2014 but findings must be compressed to conclusion level.
|
|
42072
|
-
6. Output contract: structured findings \u2014 per column: observed type, sample values,
|
|
42073
|
-
distribution highlights, role candidate + evidence, \`INCONCLUSIVE\` marking for unresolved
|
|
42074
|
-
semantics.
|
|
42075
|
-
7. Invariants: read-only only; grant boundary absolute; never guess \u2014 \`INCONCLUSIVE\` instead.
|
|
42076
|
-
8. Closing: settle the task (\`set_status completed\`, result = findings summary); final message
|
|
42077
|
-
= the structured findings (it becomes the observation).
|
|
42078
|
-
|
|
42079
|
-
### Publish-table brief (\`Publish table meta <objectKey>\`)
|
|
42080
|
-
|
|
42081
|
-
Required fields:
|
|
42082
|
-
1. Approved decisions: full column list (name/type/role/label/description), grain,
|
|
42083
|
-
displayName/docType/shortDesc/sourceSystem/sourceTables.
|
|
42084
|
-
2. Identity: \`objectKey\` (stable, unique per datasource) + \`schemaName.tableName\`.
|
|
42085
|
-
3. Assembly instruction: full \`table_view_detail\` payload per **Publish table meta** below,
|
|
42086
|
-
plus the identity twin (\`table_catalog\`, same \`objectKey\`), plus an EXACT \`accessGrant\`
|
|
42087
|
-
matching the tenant grant.
|
|
42088
|
-
4. Gate self-check: publish gate items 1\u20133 \u2014 do not publish if any fails.
|
|
42089
|
-
5. Publish via \`metrics_meta_tool\` \`create_table\`; then \`get_meta\` to confirm visibility.
|
|
42090
|
-
6. Mistakes: fix with \`update_table\`; never leave a partial publish.
|
|
42091
|
-
7. Invariants: EXACT patternType; every column tagged and labeled.
|
|
42092
|
-
8. Closing: settle the task; final message = receipts (objectKeys + get_meta confirmation).
|
|
42093
|
-
|
|
42094
|
-
### Publish-metric brief (\`Publish metric <objectKey>\`)
|
|
42095
|
-
|
|
42096
|
-
Required fields (per metric):
|
|
42097
|
-
1. Identity: \`objectKey\` = \`metric_name\`, display_name, domain, description, data_type, format.
|
|
42098
|
-
2. Source: schema-qualified \`source.table_view\` (must match the published table meta).
|
|
42099
|
-
3. Calculation: aggregate (\`aggregation\` + \`measure\`, with the confirmed business meaning) or
|
|
42100
|
-
derived (ratio references / formula) \u2014 exactly as approved in Propose the model.
|
|
42101
|
-
4. \`supported_dimensions\`: array of objects \`{dim_id, field_name, label, data_type}\`,
|
|
42102
|
-
including the time dimension.
|
|
42103
|
-
5. \`default_time_context\`: time_dimension + granularity + supported_grains (+ window if requested).
|
|
42104
|
-
6. \`ai_agent_context\`: polarity, synonyms, human_readable_explanation.
|
|
42105
|
-
7. Assembly instruction: \`metric_index\` then \`metric_detail\` in the FULL runtime style per
|
|
42106
|
-
**Publish metric meta** below; publish via \`metrics_meta_tool\` \`create_metric\`.
|
|
42107
|
-
8. Gate self-check + smoke \`query\` (one grouping by the default time grain) + \`get_meta\`
|
|
42108
|
-
receipts; closing = settle the task, final message = receipts.
|
|
42109
|
-
|
|
42110
|
-
### Verify brief (\`Verify <metric> against acceptance evidence\`)
|
|
42111
|
-
|
|
42112
|
-
Required fields:
|
|
42113
|
-
1. Acceptance evidence verbatim (from the Goal Model).
|
|
42114
|
-
2. Queries to run (semantic \`query\` via \`metrics_runtime_tool\`) and the expected shape/values.
|
|
42115
|
-
3. Report contract: PASS/FAIL verdict + actual vs expected; on FAIL include the differences
|
|
42116
|
-
and a suspicion list \u2014 do NOT modify meta (fixes are new Publish tasks).
|
|
42117
|
-
4. Invariants: read-only only.
|
|
42118
|
-
5. Closing: settle the task; final message = the verdict summary.
|
|
42119
|
-
|
|
42120
|
-
### Brief closing (all types)
|
|
42121
|
-
|
|
42122
|
-
- Invariants line: grant boundary + read-only SQL + publish gate before any create.
|
|
42123
|
-
- Result structure: the structured summary the orchestrator expects back.
|
|
42124
|
-
- Finish by settling the task (\`set_status completed\` with result, or \`failed\` with
|
|
42125
|
-
failureReason) and making the final message that structured summary.
|
|
42126
|
-
|
|
42127
|
-
## Worker mode
|
|
42128
|
-
|
|
42129
|
-
Trigger: your context contains \`## Bound Task\`. You are a worker; these rules override the
|
|
42130
|
-
orchestrator policy (Safety and the reference sections still apply):
|
|
42131
|
-
|
|
42132
|
-
- Execute the bound task's brief only. Read the contract with \`manage_task get\`; the task
|
|
42133
|
-
description is authoritative. Load this skill if the bootstrap asks \u2014 you need its payload
|
|
42134
|
-
reference sections.
|
|
42135
|
-
- Do NOT: re-agree the Goal Model, create sibling or child tasks, dispatch \`task\`, call
|
|
42136
|
-
\`ask_user_to_clarify\`, or update the parent task's \`## Belief State\`.
|
|
42137
|
-
- Apply the FEP loop inside the brief; obey the grant boundary and read-only SQL; run the
|
|
42138
|
-
publish gate before any create.
|
|
42139
|
-
- Unclear semantics: mark \`INCONCLUSIVE\` with candidates + evidence in your findings. Never
|
|
42140
|
-
guess, never publish on a guess.
|
|
42141
|
-
- Finish: \`set_status completed\` with a structured result (or \`failed\` with failureReason),
|
|
42142
|
-
and make your final message the structured summary \u2014 it is the observation your
|
|
42143
|
-
orchestrator reads.
|
|
42144
|
-
|
|
42145
|
-
## Belief State (orchestrator-owned)
|
|
42146
|
-
|
|
42147
|
-
The parent task's description carries a \`## Belief State\` section as a Markdown table:
|
|
42148
|
-
|
|
42149
|
-
\`\`\`
|
|
42150
|
-
| Belief Key | Probability | Target | Basis |
|
|
42151
|
-
|---|---|---|---|
|
|
42152
|
-
| sell-in-nes-source-table | 70% | 100% | column \`nes\` probed as numeric measure in grant |
|
|
42153
|
-
\`\`\`
|
|
42154
|
-
|
|
42155
|
-
Rules: belief keys are lowercase kebab-case; probability/target are percentages 0\u2013100% that
|
|
42156
|
-
represent evidence support, not calibrated probability. Only the orchestrator writes this
|
|
42157
|
-
section \u2014 after each dispatch it folds the worker's findings into the table so the parent
|
|
42158
|
-
task always reflects the current evidence.
|
|
42159
|
-
|
|
42160
|
-
## Workflow
|
|
42161
|
-
|
|
42162
|
-
1. **Pick the datasource + cheap observation.** \`metrics_datasource_tool\` action
|
|
42163
|
-
\`list_datasources\`, or the preset \`runConfig.metricsDataSource\` (\`serverKey\`\u2192connectionKey,
|
|
42164
|
-
\`datasourceId\`). Inline, read-only.
|
|
42165
|
-
2. **Agree the Goal Model.** (HITL)
|
|
42166
|
-
3. **Create the parent task** \u2014 contract + \`## Belief State\` (seeded from the Goal Model).
|
|
42167
|
-
4. **Explore by dispatch** \u2014 one Explore brief per table, serial; collect findings; reconcile
|
|
42168
|
-
\`## Belief State\`; collect \`INCONCLUSIVE\` columns.
|
|
42169
|
-
5. **Propose the model** (HITL) \u2014 present table columns (with \`role: dimension | measure\`)
|
|
42170
|
-
and the metrics (aggregate/derived) for approval; include clarify questions for
|
|
42171
|
-
\`INCONCLUSIVE\` columns in the same ask.
|
|
42172
|
-
6. **Publish tables by dispatch** \u2014 one Publish-table brief per table; check receipts.
|
|
42173
|
-
7. **Publish metrics by dispatch** \u2014 one Publish-metric brief per metric; receipts + smoke query.
|
|
42174
|
-
8. **Verify by dispatch** \u2014 Verify brief against acceptance evidence. FAIL \u2192 reconcile
|
|
42175
|
-
belief \u2192 fix decisions \u2192 new Publish task (\`update_table\`/\`update_metric\`) \u2192 re-Verify.
|
|
42176
|
-
PASS \u2192 complete the parent task (result = acceptance evidence met).
|
|
42177
|
-
|
|
42178
|
-
## Explore (reference)
|
|
42179
|
-
|
|
42180
|
-
Read \`table-grants\`, then probe with \`query\`. SQL is validated read-only by the client and the
|
|
42181
|
-
server enforces the grant; un-granted tables return \`TABLE_NOT_GRANTED\`. Prefer the
|
|
42182
|
-
\`references/metadata-sql.md\` templates because dialect varies (PostgreSQL / SQL Server / HANA).
|
|
42183
|
-
If the user provides a data dictionary or sample data file, read it with filesystem and
|
|
42184
|
-
reconcile it against the probed columns.
|
|
42185
|
-
|
|
42186
|
-
## Unclear field semantics
|
|
42187
|
-
|
|
42188
|
-
A probed column name may not reveal its business meaning (e.g. whether \`nes\` is a net amount to
|
|
42189
|
-
sum, a rate to average, or an enum to filter). Publishing meta on a misunderstood field pollutes
|
|
42190
|
-
the runtime and every downstream metric that depends on it, and delete is not available. Treat this
|
|
42191
|
-
as FEP **INCONCLUSIVE** \u2014 never guess, and never publish on an unverified guess.
|
|
42192
|
-
|
|
42193
|
-
Resolve in order of increasing cost (inside the Explore brief):
|
|
42194
|
-
1. **Probe sample values and distribution** (\`query\`, templates in \`references/metadata-sql.md\`):
|
|
42195
|
-
- numbers in (0,1) or clustered near 100 \u2192 likely a ratio/percentage \u2192 dimension or \`avg\`, rarely \`sum\`;
|
|
42196
|
-
- large additive amounts (currency, counts) \u2192 measure with \`sum\`;
|
|
42197
|
-
- small enumerations (year 2023/2024, 0/1 flags, codes) \u2192 dimension.
|
|
42198
|
-
The share of zeros/negatives and the value scale usually disambiguate semantics.
|
|
42199
|
-
2. **Read user-provided docs**: if the user supplied a data dictionary or sample file, read it via
|
|
42200
|
-
filesystem and reconcile it against the probed columns.
|
|
42201
|
-
3. **Cross-field correlation**: compare the unclear field with fields whose semantics are confirmed.
|
|
42202
|
-
|
|
42203
|
-
If evidence is still INCONCLUSIVE:
|
|
42204
|
-
- Do **not** publish meta that depends on the unclear field.
|
|
42205
|
-
- The worker marks the column \`INCONCLUSIVE\` (candidates + evidence) in its findings; the
|
|
42206
|
-
**orchestrator** lists it with candidate interpretations in the **Propose the model** step
|
|
42207
|
-
and asks the user to confirm its semantics (role, value meaning, net/gross) via
|
|
42208
|
-
\`ask_user_to_clarify\`. The user does not need to see the table \u2014 probed schema, samples, and
|
|
42209
|
-
candidates are enough.
|
|
42210
|
-
- The orchestrator records a low-probability belief entry (e.g.
|
|
42211
|
-
\`| sales-nes-semantics | 40% | 100% | user must confirm role / net amount |\`) so verify/refine
|
|
42212
|
-
can revisit it later instead of assuming it is settled.
|
|
42213
|
-
|
|
42214
|
-
## Publish table meta (\`create_table\`)
|
|
42215
|
-
|
|
42216
|
-
Publish the authoritative shape below (objectType \`table_view_detail\`, with an EXACT accessGrant):
|
|
42217
|
-
|
|
42218
|
-
\`\`\`json
|
|
42219
|
-
{
|
|
42220
|
-
"objectType": "table_view_detail",
|
|
42221
|
-
"objectKey": "hankel_view_sales_summary",
|
|
42222
|
-
"status": 1,
|
|
42223
|
-
"payload": {
|
|
42224
|
-
"schemaName": "public",
|
|
42225
|
-
"tableName": "hankel_view_sales_summary",
|
|
42226
|
-
"displayName": "Hankel Sales Summary",
|
|
42227
|
-
"docType": "Sales Summary",
|
|
42228
|
-
"docTypeEn": "Sales Summary",
|
|
42229
|
-
"shortDesc": "Sales-level progress summary.",
|
|
42230
|
-
"grain": "canonical_sales_name",
|
|
42231
|
-
"sourceSystem": "Hankel Run for Gold",
|
|
42232
|
-
"sourceTables": ["hankel_project_opportunity_lines", "hankel_new_order_lines"],
|
|
42233
|
-
"columns": [
|
|
42234
|
-
{ "name": "canonical_sales_name", "label": "Canonical Sales Name", "type": "string", "role": "dimension", "description": "Standardized sales name used for grouping." },
|
|
42235
|
-
{ "name": "nes", "label": "NES", "type": "number", "role": "measure", "description": "Net external sales amount." },
|
|
42236
|
-
{ "name": "report_cutoff_date", "label": "Report Cutoff Date", "type": "date", "role": "time", "description": "Cutoff date of the report snapshot." }
|
|
42237
|
-
]
|
|
42238
|
-
},
|
|
42239
|
-
"accessGrant": {
|
|
42240
|
-
"schemaName": "public",
|
|
42241
|
-
"tablePattern": "hankel_view_sales_summary",
|
|
42242
|
-
"patternType": "EXACT",
|
|
42243
|
-
"caseSensitive": false,
|
|
42244
|
-
"status": 1
|
|
42245
|
-
}
|
|
42246
|
-
}
|
|
42247
|
-
\`\`\`
|
|
42248
|
-
|
|
42249
|
-
Design rules:
|
|
42250
|
-
- \`objectKey\` is stable and unique per datasource (the view/table key).
|
|
42251
|
-
- \`columns[].role\` has THREE values: \`dimension\` (grouping/filtering), \`measure\` (aggregated numbers), \`time\` (the report cutoff/snapshot date used by default_time_context).
|
|
42252
|
-
- Give every column a business \`description\`.
|
|
42253
|
-
- Lineage fields (\`docType\`, \`shortDesc\`, \`grain\`, \`sourceSystem\`, \`sourceTables\`) make the asset findable and trustworthy \u2014 fill them from exploration evidence.
|
|
42254
|
-
- Runtime table publication uses \`patternType: "EXACT"\` (\`PREFIX\` is only for datasource-level exploration scopes).
|
|
42255
|
-
- For each semantic table also publish the identity twin: the same body with \`objectType: "table_catalog"\` and the same \`objectKey\` (same or richer payload).
|
|
42256
|
-
|
|
42257
|
-
## Publish metric meta (\`create_metric\`)
|
|
42258
|
-
|
|
42259
|
-
Two steps for the same \`objectKey\`.
|
|
42260
|
-
|
|
42261
|
-
### 3a. Metric index (for lists/search)
|
|
42262
|
-
|
|
42263
|
-
\`\`\`json
|
|
42264
|
-
{
|
|
42265
|
-
"objectType": "metric_index",
|
|
42266
|
-
"objectKey": "sell_in_nes",
|
|
42267
|
-
"status": 1,
|
|
42268
|
-
"payload": {
|
|
42269
|
-
"metric_name": "sell_in_nes",
|
|
42270
|
-
"display_name": "Sell-in NES",
|
|
42271
|
-
"domain": "sales",
|
|
42272
|
-
"short_desc": "Net external sales amount from distributor sell-in rows.",
|
|
42273
|
-
"search_keywords": ["sell in", "nes", "net external sales"],
|
|
42274
|
-
"source_type": "cdp_postgres",
|
|
42275
|
-
"source": { "table_view": "public.hankel_distr_sell_in" }
|
|
42276
|
-
}
|
|
42277
|
-
}
|
|
42278
|
-
\`\`\`
|
|
42279
|
-
|
|
42280
|
-
\`search_keywords\` drive metric retrieval for natural-language questions \u2014 include business synonyms.
|
|
42281
|
-
|
|
42282
|
-
### 3b. Metric detail (the calculation)
|
|
42283
|
-
|
|
42284
|
-
IMPORTANT \u2014 runtime schema requirement: the Metrics Server query runtime only recognizes metrics
|
|
42285
|
-
published in the FULL runtime style below (the same shape as existing working metrics, with
|
|
42286
|
-
snake_case fields like \`metric_name\`, \`source.table_view\`, \`supported_dimensions\` objects, and
|
|
42287
|
-
\`default_time_context\`). A minimal \`{name, sourceTable, calculation, dimensions}\` payload is
|
|
42288
|
-
accepted by the publish API but is NOT queryable \u2014 querying it returns 403 "not authorized".
|
|
42289
|
-
|
|
42290
|
-
Aggregate metric (full runtime style):
|
|
42291
|
-
|
|
42292
|
-
\`\`\`json
|
|
42293
|
-
{
|
|
42294
|
-
"objectType": "metric_detail",
|
|
42295
|
-
"objectKey": "sell_in_nes",
|
|
42296
|
-
"status": 1,
|
|
42297
|
-
"payload": {
|
|
42298
|
-
"metric_name": "sell_in_nes",
|
|
42299
|
-
"display_name": "Sell-in NES",
|
|
42300
|
-
"domain": "sales",
|
|
42301
|
-
"description": "Net external sales amount from distributor sell-in rows.",
|
|
42302
|
-
"data_type": "numeric",
|
|
42303
|
-
"format": "currency",
|
|
42304
|
-
"source_type": "cdp_postgres",
|
|
42305
|
-
"source": { "table_view": "public.hankel_distr_sell_in", "base_filters": [] },
|
|
42306
|
-
"calculation": { "type": "aggregate", "aggregation": "sum", "measure": "nes" },
|
|
42307
|
-
"supported_dimensions": [
|
|
42308
|
-
{ "dim_id": "posting_year", "field_name": "posting_year", "label": "Posting Year", "data_type": "number" },
|
|
42309
|
-
{ "dim_id": "sales_team", "field_name": "sales_team", "label": "Sales Team", "data_type": "string" }
|
|
42310
|
-
],
|
|
42311
|
-
"default_time_context": {
|
|
42312
|
-
"time_dimension": "posting_date",
|
|
42313
|
-
"label": "Posting date",
|
|
42314
|
-
"granularity": "month",
|
|
42315
|
-
"window": "YTD",
|
|
42316
|
-
"supported_grains": ["month", "year"]
|
|
42317
|
-
},
|
|
42318
|
-
"ai_agent_context": {
|
|
42319
|
-
"polarity": "positive",
|
|
42320
|
-
"synonyms": ["sell in", "nes", "net external sales"],
|
|
42321
|
-
"human_readable_explanation": "Higher sell-in NES means more goods purchased from the distributor."
|
|
42322
|
-
}
|
|
42323
|
-
}
|
|
42324
|
-
}
|
|
42325
|
-
\`\`\`
|
|
42326
|
-
|
|
42327
|
-
Derived ratio metric (references two aggregate metrics):
|
|
42328
|
-
|
|
42329
|
-
\`\`\`json
|
|
42330
|
-
{
|
|
42331
|
-
"objectType": "metric_detail",
|
|
42332
|
-
"objectKey": "gross_margin_rate",
|
|
42333
|
-
"status": 1,
|
|
42334
|
-
"payload": {
|
|
42335
|
-
"metric_name": "gross_margin_rate",
|
|
42336
|
-
"display_name": "Gross Margin Rate",
|
|
42337
|
-
"description": "Gross margin divided by sell-in NES.",
|
|
42338
|
-
"domain": "sales",
|
|
42339
|
-
"data_type": "numeric",
|
|
42340
|
-
"format": "percent",
|
|
42341
|
-
"source_type": "cdp_postgres",
|
|
42342
|
-
"source": { "table_view": "public.hankel_distr_sell_in", "base_filters": [] },
|
|
42343
|
-
"calculation": { "type": "derived", "operator": "ratio", "numerator": "gross_margin", "denominator": "sell_in_nes" },
|
|
42344
|
-
"supported_dimensions": [
|
|
42345
|
-
{ "dim_id": "posting_year", "field_name": "posting_year", "label": "Posting Year", "data_type": "number" }
|
|
42346
|
-
],
|
|
42347
|
-
"default_time_context": { "time_dimension": "posting_date", "granularity": "month", "supported_grains": ["month", "year"] }
|
|
42348
|
-
}
|
|
42349
|
-
}
|
|
42350
|
-
\`\`\`
|
|
42351
|
-
|
|
42352
|
-
Design rules:
|
|
42353
|
-
- \`objectKey\` unique per datasource (index and detail share it).
|
|
42354
|
-
- \`payload.metric_name\` must equal \`objectKey\`.
|
|
42355
|
-
- \`source.table_view\` must be schema-qualified and match the published table meta's physical table.
|
|
42356
|
-
- \`supported_dimensions\` is an array of OBJECTS ({dim_id, field_name, label, data_type}); include the time dimension too; each must be a published column of that table meta.
|
|
42357
|
-
- \`calculation.type: "aggregate"\` = one measure + aggregation (sum/avg/count/min/max/count_distinct).
|
|
42358
|
-
- \`calculation.type: "derived"\` operator \`ratio\` references existing metric objectKeys (numerator/denominator); a \`formula\` variant takes an expression of metric names, numbers, parentheses, and + - * / \u2014 referenced metrics must share the same source.table_view.
|
|
42359
|
-
- \`default_time_context\` (\`time_dimension\` + \`granularity\` + \`supported_grains\`, optionally \`window\`) is required by the query runtime; its \`time_dimension\` must appear in supported_dimensions.
|
|
42360
|
-
- \`ai_agent_context\` (\`polarity\`, \`synonyms\`, \`human_readable_explanation\`) improves natural-language metric retrieval \u2014 always provide it.
|
|
42361
|
-
- One semantic query can only combine metrics sharing the same source.table_view; groupBy values must be dim_ids or time-grain expressions like \`posting_date__month\`.
|
|
42362
|
-
- Do not inline raw SQL for new DB-backed metrics (complex logic belongs in a view).
|
|
42363
|
-
- Use \`update_metric\` / \`update_table\` to correct mistakes; no removal actions are exposed.
|
|
42364
|
-
|
|
42365
|
-
## Verify and refine
|
|
42366
|
-
|
|
42367
|
-
- Verify is **dispatched** (Verify brief). The worker runs \`get_meta\` \u2192 confirms the table and
|
|
42368
|
-
metric are visible, then \`query\`es the metric against acceptance evidence.
|
|
42369
|
-
- On FAIL the worker reports differences; the **orchestrator** applies the FEP reconcile:
|
|
42370
|
-
update \`## Belief State\`, fix the decisions, and dispatch a new Publish task
|
|
42371
|
-
(\`update_table\`/\`update_metric\`) \u2014 then re-Verify \u2014 until acceptance evidence is met.
|
|
42372
|
-
|
|
42373
|
-
## Troubleshooting
|
|
42374
|
-
|
|
42375
|
-
| Symptom | Cause / fix |
|
|
42376
|
-
|---|---|
|
|
42377
|
-
| \`TABLE_NOT_GRANTED\` | SQL referenced a table outside the tenant grant; pick an in-grant table |
|
|
42378
|
-
| metric create fails: sourceTable missing | publish the table meta first |
|
|
42379
|
-
| metric create fails: unknown dimension | publish the dimension column with \`role: dimension\` |
|
|
42380
|
-
| derived metric create fails | numerator/denominator metrics don't exist yet \u2014 publish them first |
|
|
42381
|
-
| datasource \`query\` rejected | SQL was not read-only (SELECT/WITH only) or multi-statement |
|
|
42382
|
-
| \`403 Metric is not authorized\` on query_metrics | the metric meta is not in the queryable runtime schema (e.g. missing \`source.table_view\` / \`supported_dimensions\` / \`default_time_context\`) or genuinely unauthorized \u2014 re-publish with the full runtime payload and verify; never retry blindly |
|
|
42383
|
-
| worker observation truncated | findings exceeded ~8k chars; worker must keep the final message a compact structured summary |
|
|
42384
|
-
| dispatch failed (tool error) | retry once; Explore never goes inline \u2014 ask the user; Publish/Verify may go inline after the failed retry |
|
|
42385
|
-
|
|
42386
|
-
## Safety
|
|
42387
|
-
|
|
42388
|
-
- Only query tables that match the tenant's \`table-grants\`.
|
|
42389
|
-
- Never return a full physical-table inventory or reveal whether an un-granted table exists.
|
|
42390
|
-
- SQL is validated read-only; let the server reject anything outside that.
|
|
42391
|
-
`;
|
|
42392
|
-
var resources = {
|
|
42393
|
-
"references/metadata-sql.md": {
|
|
42394
|
-
content: `# Datasource exploration SQL templates (read-only)
|
|
42395
|
-
|
|
42396
|
-
Pick the block matching the server's database. These run through the datasource \`query\` action;
|
|
42397
|
-
the SQL is validated read-only.
|
|
42398
|
-
|
|
42399
|
-
## PostgreSQL
|
|
42400
|
-
- Tables: \`select table_schema, table_name from information_schema.tables where table_schema not in ('pg_catalog','information_schema') order by table_schema, table_name\`
|
|
42401
|
-
- Columns: \`select column_name, data_type from information_schema.columns where table_schema = :schemaName and table_name = :tableName order by ordinal_position\`
|
|
42402
|
-
- Sample: \`select * from :schemaName.:tableName limit :maxRows\` \u2014 pass a concrete table, not a bound param, if the server does not support binding identifiers.
|
|
42403
|
-
|
|
42404
|
-
## SQL Server
|
|
42405
|
-
- Tables: \`select table_schema, table_name from information_schema.tables order by table_schema, table_name\`
|
|
42406
|
-
- Columns: \`select column_name, data_type from information_schema.columns where table_schema = :schemaName and table_name = :tableName order by ordinal_position\`
|
|
42407
|
-
|
|
42408
|
-
## HANA
|
|
42409
|
-
- Tables: \`select schema_name, table_name from sys.tables where schema_name = :schemaName order by table_name\`
|
|
42410
|
-
- Columns: \`select column_name, data_type_name from table_columns where schema_name = :schemaName and table_name = :tableName order by position\`
|
|
42411
|
-
|
|
42412
|
-
## Value distribution (any dialect)
|
|
42413
|
-
\`select <dim>, count(*) as row_count from <table> group by <dim> order by row_count desc limit :maxRows\`
|
|
42414
|
-
`
|
|
42415
|
-
},
|
|
42416
|
-
"examples/table-meta.json": {
|
|
42417
|
-
content: `{
|
|
42418
|
-
"objectType": "table_view_detail",
|
|
42419
|
-
"objectKey": "hankel_distr_sell_in",
|
|
42420
|
-
"status": 1,
|
|
42421
|
-
"payload": {
|
|
42422
|
-
"schemaName": "public",
|
|
42423
|
-
"tableName": "hankel_distr_sell_in",
|
|
42424
|
-
"displayName": "Hankel Distributor Sell In",
|
|
42425
|
-
"description": "Distributor sell-in transaction rows for the Hankel tenant.",
|
|
42426
|
-
"columns": [
|
|
42427
|
-
{ "name": "posting_year", "label": "Posting Year", "type": "number", "role": "dimension" },
|
|
42428
|
-
{ "name": "posting_month", "label": "Posting Month", "type": "number", "role": "dimension" },
|
|
42429
|
-
{ "name": "sales_team", "label": "Sales Team", "type": "string", "role": "dimension" },
|
|
42430
|
-
{ "name": "region", "label": "Region", "type": "string", "role": "dimension" },
|
|
42431
|
-
{ "name": "nes", "label": "Net External Sales", "type": "number", "role": "measure" },
|
|
42432
|
-
{ "name": "gross_margin", "label": "Gross Margin", "type": "number", "role": "measure" }
|
|
42433
|
-
]
|
|
42434
|
-
}
|
|
42435
|
-
}
|
|
42436
|
-
`
|
|
42437
|
-
},
|
|
42438
|
-
"examples/metric-aggregate.json": {
|
|
42439
|
-
content: `{
|
|
42440
|
-
"objectType": "metric_detail",
|
|
42441
|
-
"objectKey": "sell_in_nes",
|
|
42442
|
-
"status": 1,
|
|
42443
|
-
"payload": {
|
|
42444
|
-
"metric_name": "sell_in_nes",
|
|
42445
|
-
"display_name": "Sell-in NES",
|
|
42446
|
-
"domain": "sales",
|
|
42447
|
-
"description": "Net external sales amount from distributor sell-in rows.",
|
|
42448
|
-
"data_type": "numeric",
|
|
42449
|
-
"format": "currency",
|
|
42450
|
-
"source_type": "cdp_postgres",
|
|
42451
|
-
"source": { "table_view": "public.hankel_distr_sell_in", "base_filters": [] },
|
|
42452
|
-
"calculation": { "type": "aggregate", "aggregation": "sum", "measure": "nes" },
|
|
42453
|
-
"supported_dimensions": [
|
|
42454
|
-
{ "dim_id": "posting_year", "field_name": "posting_year", "label": "Posting Year", "data_type": "number" },
|
|
42455
|
-
{ "dim_id": "sales_team", "field_name": "sales_team", "label": "Sales Team", "data_type": "string" },
|
|
42456
|
-
{ "dim_id": "posting_date", "field_name": "posting_date", "label": "Posting Date", "data_type": "string" }
|
|
42457
|
-
],
|
|
42458
|
-
"default_time_context": {
|
|
42459
|
-
"time_dimension": "posting_date",
|
|
42460
|
-
"label": "Posting date",
|
|
42461
|
-
"granularity": "month",
|
|
42462
|
-
"window": "YTD",
|
|
42463
|
-
"supported_grains": ["month", "year"]
|
|
42464
|
-
},
|
|
42465
|
-
"ai_agent_context": {
|
|
42466
|
-
"polarity": "positive",
|
|
42467
|
-
"synonyms": ["sell in", "nes", "net external sales"],
|
|
42468
|
-
"human_readable_explanation": "Higher sell-in NES means more goods purchased from the distributor."
|
|
42469
|
-
}
|
|
42470
|
-
}
|
|
42471
|
-
}
|
|
42472
|
-
`
|
|
42473
|
-
},
|
|
42474
|
-
"examples/metric-derived.json": {
|
|
42475
|
-
content: `{
|
|
42476
|
-
"objectType": "metric_detail",
|
|
42477
|
-
"objectKey": "gross_margin_rate",
|
|
42478
|
-
"status": 1,
|
|
42479
|
-
"payload": {
|
|
42480
|
-
"metric_name": "gross_margin_rate",
|
|
42481
|
-
"display_name": "Gross Margin Rate",
|
|
42482
|
-
"domain": "sales",
|
|
42483
|
-
"description": "Gross margin divided by sell-in NES.",
|
|
42484
|
-
"data_type": "numeric",
|
|
42485
|
-
"format": "percent",
|
|
42486
|
-
"source_type": "cdp_postgres",
|
|
42487
|
-
"source": { "table_view": "public.hankel_distr_sell_in", "base_filters": [] },
|
|
42488
|
-
"calculation": { "type": "derived", "operator": "ratio", "numerator": "gross_margin", "denominator": "sell_in_nes" },
|
|
42489
|
-
"supported_dimensions": [
|
|
42490
|
-
{ "dim_id": "posting_year", "field_name": "posting_year", "label": "Posting Year", "data_type": "number" },
|
|
42491
|
-
{ "dim_id": "posting_date", "field_name": "posting_date", "label": "Posting Date", "data_type": "string" }
|
|
42492
|
-
],
|
|
42493
|
-
"default_time_context": {
|
|
42494
|
-
"time_dimension": "posting_date",
|
|
42495
|
-
"label": "Posting date",
|
|
42496
|
-
"granularity": "month",
|
|
42497
|
-
"supported_grains": ["month", "year"]
|
|
42498
|
-
},
|
|
42499
|
-
"ai_agent_context": {
|
|
42500
|
-
"polarity": "positive",
|
|
42501
|
-
"synonyms": ["gross margin rate", "margin rate"],
|
|
42502
|
-
"human_readable_explanation": "Gross margin rate divides gross margin by sell-in NES; higher means more margin retained on sold-in goods."
|
|
42503
|
-
}
|
|
42504
|
-
}
|
|
42505
|
-
}
|
|
42506
|
-
`
|
|
42507
|
-
}
|
|
42508
|
-
};
|
|
42509
|
-
var SEMANTIC_METRICS_MODELING_SKILL = {
|
|
42510
|
-
version: "1.1.2",
|
|
42511
|
-
content: CONTENT,
|
|
42512
|
-
resources
|
|
42513
|
-
};
|
|
42514
|
-
|
|
42515
|
-
// src/middlewares/semanticMetricsBuilderPrompt.ts
|
|
42516
|
-
var SEMANTIC_METRICS_BUILDER_PROMPT = `You are the Semantic Metrics Builder.
|
|
42517
|
-
|
|
42518
|
-
CRITICAL FIRST ACTION: Before any response or other action, call the \`skill\`
|
|
42519
|
-
tool with skill_name: "semantic-metrics-modeling" to load semantic-metrics-modeling and follow it.
|
|
42520
|
-
Never announce the skill load. If it fails, retry once, then stop and explicitly
|
|
42521
|
-
report that the required Semantic Metrics Builder skill could not be loaded.`;
|
|
42522
|
-
|
|
42523
|
-
// src/middlewares/semanticMetricsMiddleware.ts
|
|
42524
|
-
var import_protocols33 = require("@axiom-lattice/protocols");
|
|
42525
|
-
function createSemanticMetricsMiddleware(config) {
|
|
42526
|
-
const connections = config.connections ?? [];
|
|
42527
|
-
const connectAll = config.connectAll === true;
|
|
42528
|
-
const selector = { connectionType: "semantic-metrics", connections, connectAll };
|
|
42529
|
-
return (0, import_langchain70.createMiddleware)({
|
|
42530
|
-
name: "SemanticMetrics",
|
|
42531
|
-
contextSchema,
|
|
42532
|
-
tools: [
|
|
42533
|
-
createMetricsDatasourceTool(selector),
|
|
42534
|
-
createMetricsMetaTool(selector),
|
|
42535
|
-
createMetricsRuntimeTool(selector)
|
|
42536
|
-
]
|
|
42537
|
-
});
|
|
42538
|
-
}
|
|
42539
|
-
function buildConnectionHeaders(config) {
|
|
42540
|
-
const headers = {
|
|
42541
|
-
Accept: "application/json",
|
|
42542
|
-
...config.headers !== void 0 && config.headers !== null ? config.headers : {}
|
|
42543
|
-
};
|
|
42544
|
-
if (config.apiKey) headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
42545
|
-
return headers;
|
|
42546
|
-
}
|
|
42547
|
-
function resolveBaseUrl(config) {
|
|
42548
|
-
const serverUrl = config.serverUrl;
|
|
42549
|
-
if (!serverUrl) {
|
|
42550
|
-
throw new Error("serverUrl is required");
|
|
42551
|
-
}
|
|
42552
|
-
return serverUrl.replace(/\/$/, "");
|
|
42553
|
-
}
|
|
42554
|
-
var semanticMetricsPlugin = {
|
|
42555
|
-
meta: {
|
|
42556
|
-
type: "semantic-metrics",
|
|
42557
|
-
category: "data",
|
|
42558
|
-
capabilityBundleEligible: true,
|
|
42559
|
-
openExpose: [
|
|
42560
|
-
// Query-only surface: no writes reach either tool (SQL is read-only).
|
|
42561
|
-
{ name: "metrics_datasource_tool", readOnly: true },
|
|
42562
|
-
{ name: "metrics_runtime_tool", readOnly: true }
|
|
42563
|
-
],
|
|
42564
|
-
name: "Semantic Metrics",
|
|
42565
|
-
description: "Semantic metrics datasource exploration, meta publishing, and runtime querying. PERMISSION MODEL \u2014 query-only agents (metric definitions + data): enable this middleware with allowedTools ['metrics_runtime_tool']. Metric designers (Builder): keep all three tools (metrics_datasource_tool, metrics_meta_tool, metrics_runtime_tool) for exploration, publishing, and verification, or use the built-in 'semantic-metrics-builder' agent.",
|
|
42566
|
-
version: "1.0.0",
|
|
42567
|
-
tools: [
|
|
42568
|
-
{ name: "metrics_datasource_tool", description: "Explore datasource structure within the tenant's granted scope" },
|
|
42569
|
-
{ name: "metrics_meta_tool", description: "Publish and maintain runtime semantic tables and metrics" },
|
|
42570
|
-
{ name: "metrics_runtime_tool", description: "Read runtime meta and execute semantic metric queries" }
|
|
42571
|
-
],
|
|
42572
|
-
configSchema: {
|
|
42573
|
-
type: "object",
|
|
42574
|
-
title: "Semantic Metrics Configuration",
|
|
42575
|
-
description: "First select connections (connections or connectAll). Then scope tools by role via allowedTools: QUERY-ONLY agents (metric definitions + data) set allowedTools to ['metrics_runtime_tool'] \u2014 it is self-contained (list_datasources, read_semantic_catalog, query_metrics); metric DESIGNERS keep all three tools (datasource exploration, meta publishing, runtime verification).",
|
|
42576
|
-
properties: {
|
|
42577
|
-
connections: {
|
|
42578
|
-
type: "array",
|
|
42579
|
-
title: "Connections",
|
|
42580
|
-
items: { type: "string" },
|
|
42581
|
-
widget: "connectionSelect"
|
|
42582
|
-
},
|
|
42583
|
-
connectAll: {
|
|
42584
|
-
type: "boolean",
|
|
42585
|
-
title: "Connect All",
|
|
42586
|
-
default: false,
|
|
42587
|
-
widget: "switch"
|
|
42588
|
-
}
|
|
42589
|
-
}
|
|
42590
|
-
},
|
|
42591
|
-
defaultConfig: { connections: [], connectAll: false }
|
|
42592
|
-
},
|
|
42593
|
-
connection: {
|
|
42594
|
-
// PluginConnectionFieldSchema.type supports only string/number/boolean/password,
|
|
42595
|
-
// so headers is NOT a form field; the V2 client still reads config.headers at runtime.
|
|
42596
|
-
fields: [
|
|
42597
|
-
{ key: "serverUrl", type: "string", title: "Metrics Server Base URL (include /api/v1)", required: true },
|
|
42598
|
-
{ key: "apiKey", type: "password", title: "API Key (optional)" }
|
|
42599
|
-
],
|
|
42600
|
-
test: async (config) => {
|
|
42601
|
-
try {
|
|
42602
|
-
const baseUrl = resolveBaseUrl(config);
|
|
42603
|
-
const res = await fetch(`${baseUrl}/datasources`, {
|
|
42604
|
-
headers: buildConnectionHeaders(config)
|
|
42605
|
-
});
|
|
42606
|
-
const text = await res.text().catch(() => "");
|
|
42607
|
-
let ok = res.ok;
|
|
42608
|
-
let detail = "";
|
|
42609
|
-
try {
|
|
42610
|
-
const parsed = JSON.parse(text);
|
|
42611
|
-
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
42612
|
-
const code = parsed.code;
|
|
42613
|
-
if (typeof code === "number") {
|
|
42614
|
-
ok = res.ok && code === 200;
|
|
42615
|
-
if (!ok) detail = ` (${parsed.message ?? code})`;
|
|
42616
|
-
}
|
|
42617
|
-
}
|
|
42618
|
-
} catch {
|
|
42619
|
-
}
|
|
42620
|
-
return {
|
|
42621
|
-
ok,
|
|
42622
|
-
message: ok ? `Reachable at ${baseUrl}` : `HTTP ${res.status}${detail}`
|
|
42623
|
-
};
|
|
42624
|
-
} catch (err) {
|
|
42625
|
-
return {
|
|
42626
|
-
ok: false,
|
|
42627
|
-
message: `Cannot connect: ${err instanceof Error ? err.message : String(err)}`
|
|
42628
|
-
};
|
|
42629
|
-
}
|
|
42630
|
-
},
|
|
42631
|
-
discover: async (config) => {
|
|
42632
|
-
try {
|
|
42633
|
-
const baseUrl = resolveBaseUrl(config);
|
|
42634
|
-
const res = await fetch(`${baseUrl}/datasources`, {
|
|
42635
|
-
headers: buildConnectionHeaders(config)
|
|
42636
|
-
});
|
|
42637
|
-
const text = await res.text();
|
|
42638
|
-
if (!res.ok) {
|
|
42639
|
-
throw new Error(`HTTP ${res.status}${text ? `: ${text.slice(0, 200)}` : ""}`);
|
|
42640
|
-
}
|
|
42641
|
-
const parsed = JSON.parse(text);
|
|
42642
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
42643
|
-
throw new Error("Metrics server returned an unexpected payload (expected a JSON envelope)");
|
|
42644
|
-
}
|
|
42645
|
-
const envelope = parsed;
|
|
42646
|
-
if (typeof envelope.code === "number" && envelope.code !== 200) {
|
|
42647
|
-
throw new Error(envelope.message || `API ${envelope.code}`);
|
|
42648
|
-
}
|
|
42649
|
-
const data = envelope.data;
|
|
42650
|
-
if (!Array.isArray(data)) {
|
|
42651
|
-
throw new Error("Metrics server returned an unexpected payload (expected a datasource array)");
|
|
42652
|
-
}
|
|
42653
|
-
return data.filter((d) => {
|
|
42654
|
-
if (d === null || typeof d !== "object") return false;
|
|
42655
|
-
const id = d.id;
|
|
42656
|
-
return id !== void 0 && id !== null && id !== "";
|
|
42657
|
-
}).map((item) => ({
|
|
42658
|
-
id: String(item.id),
|
|
42659
|
-
name: item.name ?? String(item.id)
|
|
42660
|
-
}));
|
|
42661
|
-
} catch (err) {
|
|
42662
|
-
throw new Error(
|
|
42663
|
-
`Cannot discover datasources: ${err instanceof Error ? err.message : String(err)}`
|
|
42664
|
-
);
|
|
42665
|
-
}
|
|
42666
|
-
}
|
|
42667
|
-
},
|
|
42668
|
-
skills: {
|
|
42669
|
-
"semantic-metrics-modeling": SEMANTIC_METRICS_MODELING_SKILL
|
|
42670
|
-
},
|
|
42671
|
-
agents: {
|
|
42672
|
-
"semantic-metrics-builder": {
|
|
42673
|
-
key: "semantic-metrics-builder",
|
|
42674
|
-
name: "Semantic Metrics Builder",
|
|
42675
|
-
description: "Explore a granted datasource and build semantic tables and metrics interactively, tracking the work as persistent tasks with belief state and verifying each step.",
|
|
42676
|
-
type: import_protocols33.AgentType.DEEP_AGENT,
|
|
42677
|
-
prompt: SEMANTIC_METRICS_BUILDER_PROMPT,
|
|
42678
|
-
middleware: [
|
|
42679
|
-
{
|
|
42680
|
-
id: "semantic-metrics",
|
|
42681
|
-
type: "semantic-metrics",
|
|
42682
|
-
name: "Semantic Metrics",
|
|
42683
|
-
description: "Explore datasources, publish table/meta metrics, query runtime",
|
|
42684
|
-
enabled: true,
|
|
42685
|
-
config: { connections: [], connectAll: true }
|
|
42686
|
-
},
|
|
42687
|
-
{
|
|
42688
|
-
id: "skill",
|
|
42689
|
-
type: "skill",
|
|
42690
|
-
name: "Skill",
|
|
42691
|
-
description: "Load the semantic-metrics-modeling policy and task-definition reference",
|
|
42692
|
-
enabled: true,
|
|
42693
|
-
config: { readAll: false, skills: ["semantic-metrics-modeling", "task-definition"] }
|
|
42694
|
-
},
|
|
42695
|
-
{
|
|
42696
|
-
id: "task",
|
|
42697
|
-
type: "task",
|
|
42698
|
-
name: "Task",
|
|
42699
|
-
description: "Persistent TaskItems as the planning surface; update Belief State in task descriptions",
|
|
42700
|
-
enabled: true,
|
|
42701
|
-
config: {}
|
|
42702
|
-
},
|
|
42703
|
-
{
|
|
42704
|
-
id: "ask_user_to_clarify",
|
|
42705
|
-
type: "ask_user_to_clarify",
|
|
42706
|
-
name: "Ask User",
|
|
42707
|
-
description: "Wait for user input at modeling approval gates",
|
|
42708
|
-
enabled: true,
|
|
42709
|
-
config: {}
|
|
42710
|
-
},
|
|
42711
|
-
{
|
|
42712
|
-
id: "filesystem",
|
|
42713
|
-
type: "filesystem",
|
|
42714
|
-
name: "Filesystem",
|
|
42715
|
-
description: "Read user-provided schema docs, data dictionaries, or sample data files",
|
|
42716
|
-
enabled: true,
|
|
42717
|
-
config: {}
|
|
42718
|
-
}
|
|
42719
|
-
]
|
|
42720
|
-
}
|
|
42721
|
-
},
|
|
42722
|
-
middleware: (config) => createSemanticMetricsMiddleware(config)
|
|
42723
|
-
};
|
|
42724
|
-
|
|
42725
41182
|
// src/middlewares/collectionMiddleware.ts
|
|
42726
|
-
var
|
|
41183
|
+
var import_langchain77 = require("langchain");
|
|
42727
41184
|
|
|
42728
41185
|
// src/tool_lattice/collection/list_collections.ts
|
|
42729
|
-
var
|
|
42730
|
-
var
|
|
41186
|
+
var import_zod55 = __toESM(require("zod"));
|
|
41187
|
+
var import_langchain67 = require("langchain");
|
|
42731
41188
|
|
|
42732
41189
|
// src/tool_lattice/collection/utils.ts
|
|
42733
41190
|
function getEffectiveCollectionScope(exeConfig, staticScope) {
|
|
@@ -42750,7 +41207,7 @@ var createListCollectionsTool = ({
|
|
|
42750
41207
|
collectionKeys,
|
|
42751
41208
|
connectAll
|
|
42752
41209
|
}) => {
|
|
42753
|
-
return (0,
|
|
41210
|
+
return (0, import_langchain67.tool)(
|
|
42754
41211
|
async (_input, _exeConfig) => {
|
|
42755
41212
|
try {
|
|
42756
41213
|
const tenantId2 = _exeConfig?.configurable?.runConfig?.tenantId || "default";
|
|
@@ -42785,23 +41242,23 @@ var createListCollectionsTool = ({
|
|
|
42785
41242
|
{
|
|
42786
41243
|
name: "list_collections",
|
|
42787
41244
|
description: LIST_COLLECTIONS_DESCRIPTION,
|
|
42788
|
-
schema:
|
|
41245
|
+
schema: import_zod55.default.object({})
|
|
42789
41246
|
}
|
|
42790
41247
|
);
|
|
42791
41248
|
};
|
|
42792
41249
|
|
|
42793
41250
|
// src/tool_lattice/collection/search_collection.ts
|
|
42794
|
-
var
|
|
42795
|
-
var
|
|
41251
|
+
var import_zod56 = __toESM(require("zod"));
|
|
41252
|
+
var import_langchain68 = require("langchain");
|
|
42796
41253
|
var SEARCH_COLLECTION_DESCRIPTION = `Search for content within a specific collection using semantic (vector) similarity. Use the 'filter' parameter to narrow results by metadata fields (e.g., {"category": "cardiovascular"}). Returns the most relevant content entries with similarity scores.`;
|
|
42797
|
-
var searchSchema =
|
|
42798
|
-
collection:
|
|
42799
|
-
query:
|
|
42800
|
-
filter:
|
|
42801
|
-
top_k:
|
|
41254
|
+
var searchSchema = import_zod56.default.object({
|
|
41255
|
+
collection: import_zod56.default.string().describe("The collection name to search in"),
|
|
41256
|
+
query: import_zod56.default.string().describe("The search query text"),
|
|
41257
|
+
filter: import_zod56.default.record(import_zod56.default.unknown()).optional().describe("Metadata filter conditions"),
|
|
41258
|
+
top_k: import_zod56.default.number().optional().default(5).describe("Number of results to return")
|
|
42802
41259
|
});
|
|
42803
41260
|
var createSearchCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => {
|
|
42804
|
-
return (0,
|
|
41261
|
+
return (0, import_langchain68.tool)(
|
|
42805
41262
|
async (input, _exeConfig) => {
|
|
42806
41263
|
try {
|
|
42807
41264
|
const { collection, query, filter: filter2, top_k } = input;
|
|
@@ -42867,10 +41324,10 @@ var createSearchCollectionTool = (scope = { collectionKeys: [], connectAll: true
|
|
|
42867
41324
|
};
|
|
42868
41325
|
|
|
42869
41326
|
// src/tool_lattice/collection/get_collection.ts
|
|
42870
|
-
var
|
|
42871
|
-
var
|
|
41327
|
+
var import_zod57 = __toESM(require("zod"));
|
|
41328
|
+
var import_langchain69 = require("langchain");
|
|
42872
41329
|
var GET_COLLECTION_DESCRIPTION = `Get a collection's full definition including its custom fields schema. Use this to discover what metadata fields are available before adding entries.`;
|
|
42873
|
-
var createGetCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => (0,
|
|
41330
|
+
var createGetCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => (0, import_langchain69.tool)(
|
|
42874
41331
|
async (input, _exeConfig) => {
|
|
42875
41332
|
try {
|
|
42876
41333
|
const scopeError = validateCollectionScope(input.name, _exeConfig, scope);
|
|
@@ -42895,24 +41352,24 @@ Embedding: ${c.embeddingKey}${fieldsDesc}`;
|
|
|
42895
41352
|
return `Error: ${error.message}`;
|
|
42896
41353
|
}
|
|
42897
41354
|
},
|
|
42898
|
-
{ name: "get_collection", description: GET_COLLECTION_DESCRIPTION, schema:
|
|
41355
|
+
{ name: "get_collection", description: GET_COLLECTION_DESCRIPTION, schema: import_zod57.default.object({ name: import_zod57.default.string().describe("Collection name") }) }
|
|
42899
41356
|
);
|
|
42900
41357
|
|
|
42901
41358
|
// src/tool_lattice/collection/create_collection.ts
|
|
42902
|
-
var
|
|
42903
|
-
var
|
|
42904
|
-
var createSchema =
|
|
42905
|
-
name:
|
|
42906
|
-
label:
|
|
42907
|
-
embeddingKey:
|
|
42908
|
-
fields:
|
|
42909
|
-
key:
|
|
42910
|
-
type:
|
|
42911
|
-
enumValues:
|
|
42912
|
-
required:
|
|
41359
|
+
var import_zod58 = __toESM(require("zod"));
|
|
41360
|
+
var import_langchain70 = require("langchain");
|
|
41361
|
+
var createSchema = import_zod58.default.object({
|
|
41362
|
+
name: import_zod58.default.string().describe("Collection name (lowercase, underscores only)"),
|
|
41363
|
+
label: import_zod58.default.string().describe("Display name"),
|
|
41364
|
+
embeddingKey: import_zod58.default.string().describe("Embedding model key"),
|
|
41365
|
+
fields: import_zod58.default.array(import_zod58.default.object({
|
|
41366
|
+
key: import_zod58.default.string().describe("Field key name"),
|
|
41367
|
+
type: import_zod58.default.enum(["string", "number", "enum"]).describe("Field data type"),
|
|
41368
|
+
enumValues: import_zod58.default.array(import_zod58.default.string()).optional().describe("Valid values for enum type"),
|
|
41369
|
+
required: import_zod58.default.boolean().optional().default(false).describe("Whether field is required")
|
|
42913
41370
|
})).optional().describe("Custom field definitions for entries in this collection")
|
|
42914
41371
|
});
|
|
42915
|
-
var createCreateCollectionTool = (scope = {}) => (0,
|
|
41372
|
+
var createCreateCollectionTool = (scope = {}) => (0, import_langchain70.tool)(
|
|
42916
41373
|
async (input, _exeConfig) => {
|
|
42917
41374
|
try {
|
|
42918
41375
|
const tenantId2 = _exeConfig?.configurable?.runConfig?.tenantId || "default";
|
|
@@ -42938,20 +41395,20 @@ var createCreateCollectionTool = (scope = {}) => (0, import_langchain74.tool)(
|
|
|
42938
41395
|
);
|
|
42939
41396
|
|
|
42940
41397
|
// src/tool_lattice/collection/update_collection.ts
|
|
42941
|
-
var
|
|
42942
|
-
var
|
|
42943
|
-
var schema =
|
|
42944
|
-
name:
|
|
42945
|
-
label:
|
|
42946
|
-
embeddingKey:
|
|
42947
|
-
fields:
|
|
42948
|
-
key:
|
|
42949
|
-
type:
|
|
42950
|
-
enumValues:
|
|
42951
|
-
required:
|
|
41398
|
+
var import_zod59 = __toESM(require("zod"));
|
|
41399
|
+
var import_langchain71 = require("langchain");
|
|
41400
|
+
var schema = import_zod59.default.object({
|
|
41401
|
+
name: import_zod59.default.string().describe("Collection name"),
|
|
41402
|
+
label: import_zod59.default.string().optional().describe("New display name"),
|
|
41403
|
+
embeddingKey: import_zod59.default.string().optional().describe("New embedding model key"),
|
|
41404
|
+
fields: import_zod59.default.array(import_zod59.default.object({
|
|
41405
|
+
key: import_zod59.default.string().describe("Field key name"),
|
|
41406
|
+
type: import_zod59.default.enum(["string", "number", "enum"]).describe("Field data type"),
|
|
41407
|
+
enumValues: import_zod59.default.array(import_zod59.default.string()).optional().describe("Valid values for enum type"),
|
|
41408
|
+
required: import_zod59.default.boolean().optional().default(false).describe("Whether field is required")
|
|
42952
41409
|
})).optional().describe("Custom field definitions for entries (replaces existing schema)")
|
|
42953
41410
|
});
|
|
42954
|
-
var createUpdateCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => (0,
|
|
41411
|
+
var createUpdateCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => (0, import_langchain71.tool)(
|
|
42955
41412
|
async (input, _exeConfig) => {
|
|
42956
41413
|
try {
|
|
42957
41414
|
const scopeError = validateCollectionScope(input.name, _exeConfig, scope);
|
|
@@ -42972,9 +41429,9 @@ var createUpdateCollectionTool = (scope = { collectionKeys: [], connectAll: true
|
|
|
42972
41429
|
);
|
|
42973
41430
|
|
|
42974
41431
|
// src/tool_lattice/collection/delete_collection.ts
|
|
42975
|
-
var
|
|
42976
|
-
var
|
|
42977
|
-
var createDeleteCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => (0,
|
|
41432
|
+
var import_zod60 = __toESM(require("zod"));
|
|
41433
|
+
var import_langchain72 = require("langchain");
|
|
41434
|
+
var createDeleteCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => (0, import_langchain72.tool)(
|
|
42978
41435
|
async (input, _exeConfig) => {
|
|
42979
41436
|
try {
|
|
42980
41437
|
const scopeError = validateCollectionScope(input.name, _exeConfig, scope);
|
|
@@ -42986,19 +41443,19 @@ var createDeleteCollectionTool = (scope = { collectionKeys: [], connectAll: true
|
|
|
42986
41443
|
return `Error: ${e.message}`;
|
|
42987
41444
|
}
|
|
42988
41445
|
},
|
|
42989
|
-
{ name: "delete_collection", description: `Delete a collection and all its entries. This cannot be undone.`, schema:
|
|
41446
|
+
{ name: "delete_collection", description: `Delete a collection and all its entries. This cannot be undone.`, schema: import_zod60.default.object({ name: import_zod60.default.string().describe("Collection name") }) }
|
|
42990
41447
|
);
|
|
42991
41448
|
|
|
42992
41449
|
// src/tool_lattice/collection/list_entries.ts
|
|
42993
|
-
var
|
|
42994
|
-
var
|
|
42995
|
-
var schema2 =
|
|
42996
|
-
collection:
|
|
41450
|
+
var import_zod61 = __toESM(require("zod"));
|
|
41451
|
+
var import_langchain73 = require("langchain");
|
|
41452
|
+
var schema2 = import_zod61.default.object({
|
|
41453
|
+
collection: import_zod61.default.string().describe("Collection name")
|
|
42997
41454
|
});
|
|
42998
41455
|
function buildKey2(tenantId2, name) {
|
|
42999
41456
|
return `${tenantId2}:${name}`;
|
|
43000
41457
|
}
|
|
43001
|
-
var createListEntriesTool = (scope = { collectionKeys: [], connectAll: true }) => (0,
|
|
41458
|
+
var createListEntriesTool = (scope = { collectionKeys: [], connectAll: true }) => (0, import_langchain73.tool)(
|
|
43002
41459
|
async (input, _exeConfig) => {
|
|
43003
41460
|
try {
|
|
43004
41461
|
const scopeError = validateCollectionScope(input.collection, _exeConfig, scope);
|
|
@@ -43027,19 +41484,19 @@ var createListEntriesTool = (scope = { collectionKeys: [], connectAll: true }) =
|
|
|
43027
41484
|
);
|
|
43028
41485
|
|
|
43029
41486
|
// src/tool_lattice/collection/add_entry.ts
|
|
43030
|
-
var
|
|
43031
|
-
var
|
|
41487
|
+
var import_zod62 = __toESM(require("zod"));
|
|
41488
|
+
var import_langchain74 = require("langchain");
|
|
43032
41489
|
var import_documents = require("@langchain/core/documents");
|
|
43033
41490
|
var import_uuid12 = require("uuid");
|
|
43034
|
-
var schema3 =
|
|
43035
|
-
collection:
|
|
43036
|
-
content:
|
|
43037
|
-
metadata:
|
|
41491
|
+
var schema3 = import_zod62.default.object({
|
|
41492
|
+
collection: import_zod62.default.string().describe("Collection name"),
|
|
41493
|
+
content: import_zod62.default.string().describe("Entry content text"),
|
|
41494
|
+
metadata: import_zod62.default.record(import_zod62.default.unknown()).optional().describe("Metadata fields matching the collection schema")
|
|
43038
41495
|
});
|
|
43039
41496
|
function key2(t, n) {
|
|
43040
41497
|
return `${t}:${n}`;
|
|
43041
41498
|
}
|
|
43042
|
-
var createAddEntryTool = (scope = { collectionKeys: [], connectAll: true }) => (0,
|
|
41499
|
+
var createAddEntryTool = (scope = { collectionKeys: [], connectAll: true }) => (0, import_langchain74.tool)(
|
|
43043
41500
|
async (input, _exeConfig) => {
|
|
43044
41501
|
try {
|
|
43045
41502
|
const scopeError = validateCollectionScope(input.collection, _exeConfig, scope);
|
|
@@ -43071,18 +41528,18 @@ var createAddEntryTool = (scope = { collectionKeys: [], connectAll: true }) => (
|
|
|
43071
41528
|
);
|
|
43072
41529
|
|
|
43073
41530
|
// src/tool_lattice/collection/update_entry.ts
|
|
43074
|
-
var
|
|
43075
|
-
var
|
|
43076
|
-
var schema4 =
|
|
43077
|
-
collection:
|
|
43078
|
-
entryId:
|
|
43079
|
-
content:
|
|
43080
|
-
metadata:
|
|
41531
|
+
var import_zod63 = __toESM(require("zod"));
|
|
41532
|
+
var import_langchain75 = require("langchain");
|
|
41533
|
+
var schema4 = import_zod63.default.object({
|
|
41534
|
+
collection: import_zod63.default.string().describe("Collection name"),
|
|
41535
|
+
entryId: import_zod63.default.string().describe("Entry ID to update"),
|
|
41536
|
+
content: import_zod63.default.string().optional().describe("New content"),
|
|
41537
|
+
metadata: import_zod63.default.record(import_zod63.default.unknown()).optional().describe("New metadata")
|
|
43081
41538
|
});
|
|
43082
41539
|
function key3(t, n) {
|
|
43083
41540
|
return `${t}:${n}`;
|
|
43084
41541
|
}
|
|
43085
|
-
var createUpdateEntryTool = (scope = { collectionKeys: [], connectAll: true }) => (0,
|
|
41542
|
+
var createUpdateEntryTool = (scope = { collectionKeys: [], connectAll: true }) => (0, import_langchain75.tool)(
|
|
43086
41543
|
async (input, _exeConfig) => {
|
|
43087
41544
|
try {
|
|
43088
41545
|
const scopeError = validateCollectionScope(input.collection, _exeConfig, scope);
|
|
@@ -43103,16 +41560,16 @@ var createUpdateEntryTool = (scope = { collectionKeys: [], connectAll: true }) =
|
|
|
43103
41560
|
);
|
|
43104
41561
|
|
|
43105
41562
|
// src/tool_lattice/collection/delete_entry.ts
|
|
43106
|
-
var
|
|
43107
|
-
var
|
|
43108
|
-
var schema5 =
|
|
43109
|
-
collection:
|
|
43110
|
-
entryId:
|
|
41563
|
+
var import_zod64 = __toESM(require("zod"));
|
|
41564
|
+
var import_langchain76 = require("langchain");
|
|
41565
|
+
var schema5 = import_zod64.default.object({
|
|
41566
|
+
collection: import_zod64.default.string().describe("Collection name"),
|
|
41567
|
+
entryId: import_zod64.default.string().describe("Entry ID to delete")
|
|
43111
41568
|
});
|
|
43112
41569
|
function key4(t, n) {
|
|
43113
41570
|
return `${t}:${n}`;
|
|
43114
41571
|
}
|
|
43115
|
-
var createDeleteEntryTool = (scope = { collectionKeys: [], connectAll: true }) => (0,
|
|
41572
|
+
var createDeleteEntryTool = (scope = { collectionKeys: [], connectAll: true }) => (0, import_langchain76.tool)(
|
|
43116
41573
|
async (input, _exeConfig) => {
|
|
43117
41574
|
try {
|
|
43118
41575
|
const scopeError = validateCollectionScope(input.collection, _exeConfig, scope);
|
|
@@ -43132,7 +41589,7 @@ var createDeleteEntryTool = (scope = { collectionKeys: [], connectAll: true }) =
|
|
|
43132
41589
|
function createCollectionMiddleware(params) {
|
|
43133
41590
|
const { collectionKeys, connectAll, compileStableCandidateTools = false } = params;
|
|
43134
41591
|
if (!compileStableCandidateTools && !connectAll && (!collectionKeys || collectionKeys.length === 0)) {
|
|
43135
|
-
return (0,
|
|
41592
|
+
return (0, import_langchain77.createMiddleware)({
|
|
43136
41593
|
name: "collectionMiddleware",
|
|
43137
41594
|
contextSchema,
|
|
43138
41595
|
tools: [
|
|
@@ -43142,7 +41599,7 @@ function createCollectionMiddleware(params) {
|
|
|
43142
41599
|
});
|
|
43143
41600
|
}
|
|
43144
41601
|
const toolParams = { collectionKeys, connectAll };
|
|
43145
|
-
return (0,
|
|
41602
|
+
return (0, import_langchain77.createMiddleware)({
|
|
43146
41603
|
name: "collectionMiddleware",
|
|
43147
41604
|
contextSchema,
|
|
43148
41605
|
tools: [
|
|
@@ -43205,24 +41662,24 @@ var collectionPlugin = {
|
|
|
43205
41662
|
};
|
|
43206
41663
|
|
|
43207
41664
|
// src/middlewares/askUserClarifyMiddleware.ts
|
|
43208
|
-
var
|
|
41665
|
+
var import_langchain79 = require("langchain");
|
|
43209
41666
|
var import_langgraph15 = require("@langchain/langgraph");
|
|
43210
41667
|
|
|
43211
41668
|
// src/tool_lattice/ask_user_to_clarify/index.ts
|
|
43212
|
-
var
|
|
43213
|
-
var
|
|
43214
|
-
var questionSchema =
|
|
43215
|
-
question:
|
|
43216
|
-
options:
|
|
43217
|
-
type:
|
|
43218
|
-
required:
|
|
43219
|
-
allowOther:
|
|
41669
|
+
var import_langchain78 = require("langchain");
|
|
41670
|
+
var import_zod65 = __toESM(require("zod"));
|
|
41671
|
+
var questionSchema = import_zod65.default.object({
|
|
41672
|
+
question: import_zod65.default.string().describe("The question text to ask the user. MUST include the specific context, options, or details being clarified \u2014 never use a bare generic label. Good: 'Confirm the plan: use Redis cache + PostgreSQL primary, split microservices as needed?' Bad: 'Confirm the plan?'"),
|
|
41673
|
+
options: import_zod65.default.array(import_zod65.default.string()).optional().default([]).describe("List of EXACT, selectable values. Maximum 3 options allowed. DO NOT include placeholder values like 'Other' or 'Enter manually'. For free-text with predefined choices, use allowOther=true (works with 'single' and 'multiple'). For pure free-text without choices, use type='input' instead. For file_upload and input, pass an empty array."),
|
|
41674
|
+
type: import_zod65.default.enum(["single", "multiple", "file_upload", "input"]).describe("The question format. 'single' = pick one from options (default, see tool description for guidance). 'multiple' = pick several from options. 'input' = free-text field (only when options cannot express the answer). 'file_upload' = file picker."),
|
|
41675
|
+
required: import_zod65.default.boolean().optional().default(false).describe("Whether this question must be answered"),
|
|
41676
|
+
allowOther: import_zod65.default.boolean().optional().default(true).describe("Set to true to append an 'Other' checkbox with a free-text input field. Works with 'single' and 'multiple' types. Use for open-ended answers or when the options cannot cover all possibilities. Not applicable for 'input' or 'file_upload' types.")
|
|
43220
41677
|
});
|
|
43221
|
-
var inputSchema =
|
|
43222
|
-
questions:
|
|
41678
|
+
var inputSchema = import_zod65.default.object({
|
|
41679
|
+
questions: import_zod65.default.array(questionSchema).min(1, "At least one question is required").describe("A structured sequence of clarification questions. Use these to gather missing parameters or disambiguate user intent before proceeding.")
|
|
43223
41680
|
});
|
|
43224
41681
|
function createAskUserToClarifyTool() {
|
|
43225
|
-
return (0,
|
|
41682
|
+
return (0, import_langchain78.tool)(
|
|
43226
41683
|
async (input) => {
|
|
43227
41684
|
return JSON.stringify(input);
|
|
43228
41685
|
},
|
|
@@ -43247,7 +41704,7 @@ function isProjectRoomRun(request) {
|
|
|
43247
41704
|
return isRecord9(runConfig?.projectRoom);
|
|
43248
41705
|
}
|
|
43249
41706
|
function createAskUserClarifyMiddleware() {
|
|
43250
|
-
return (0,
|
|
41707
|
+
return (0, import_langchain79.createMiddleware)({
|
|
43251
41708
|
name: "AskUserClarifyMiddleware",
|
|
43252
41709
|
tools: [createAskUserToClarifyTool()],
|
|
43253
41710
|
wrapToolCall: async (request, handler) => {
|
|
@@ -43257,7 +41714,7 @@ function createAskUserClarifyMiddleware() {
|
|
|
43257
41714
|
return handler(request);
|
|
43258
41715
|
}
|
|
43259
41716
|
if (isProjectRoomRun(request)) {
|
|
43260
|
-
return new
|
|
41717
|
+
return new import_langchain79.ToolMessage({
|
|
43261
41718
|
content: "You are replying inside a project room, which has no interactive clarification UI. Ask your clarifying questions directly in your reply text and stop; the user's next room message will continue the conversation.",
|
|
43262
41719
|
tool_call_id: toolCall?.id,
|
|
43263
41720
|
name: toolName2
|
|
@@ -43265,7 +41722,7 @@ function createAskUserClarifyMiddleware() {
|
|
|
43265
41722
|
}
|
|
43266
41723
|
const parsed = inputSchema.safeParse(toolCall?.args);
|
|
43267
41724
|
if (!parsed.success) {
|
|
43268
|
-
return new
|
|
41725
|
+
return new import_langchain79.ToolMessage({
|
|
43269
41726
|
content: `Invalid clarify tool arguments: ${parsed.error.message}`,
|
|
43270
41727
|
tool_call_id: toolCall?.id,
|
|
43271
41728
|
name: toolName2
|
|
@@ -43285,7 +41742,7 @@ function createAskUserClarifyMiddleware() {
|
|
|
43285
41742
|
const result = await (0, import_langgraph15.interrupt)(md);
|
|
43286
41743
|
const response = result.data;
|
|
43287
41744
|
if (!response?.answers || response.answers.length === 0) {
|
|
43288
|
-
return new
|
|
41745
|
+
return new import_langchain79.ToolMessage({
|
|
43289
41746
|
content: "No clarification questions were answered.",
|
|
43290
41747
|
tool_call_id: toolCall?.id,
|
|
43291
41748
|
name: toolName2
|
|
@@ -43295,7 +41752,7 @@ function createAskUserClarifyMiddleware() {
|
|
|
43295
41752
|
(answer) => (answer.selectedOptions?.length ?? 0) > 0 || answer.otherText && answer.otherText.trim() !== "" || answer.filePath && answer.filePath.trim() !== ""
|
|
43296
41753
|
);
|
|
43297
41754
|
if (answeredQuestions.length === 0) {
|
|
43298
|
-
return new
|
|
41755
|
+
return new import_langchain79.ToolMessage({
|
|
43299
41756
|
content: "No clarification questions were answered.",
|
|
43300
41757
|
tool_call_id: toolCall?.id,
|
|
43301
41758
|
name: toolName2
|
|
@@ -43325,7 +41782,7 @@ function createAskUserClarifyMiddleware() {
|
|
|
43325
41782
|
}
|
|
43326
41783
|
lines.push("");
|
|
43327
41784
|
}
|
|
43328
|
-
return new
|
|
41785
|
+
return new import_langchain79.ToolMessage({
|
|
43329
41786
|
content: lines.join("\n"),
|
|
43330
41787
|
tool_call_id: toolCall?.id,
|
|
43331
41788
|
name: toolName2
|
|
@@ -43351,11 +41808,11 @@ var askUserClarifyPlugin = {
|
|
|
43351
41808
|
};
|
|
43352
41809
|
|
|
43353
41810
|
// src/middlewares/widgetMiddleware.ts
|
|
43354
|
-
var
|
|
41811
|
+
var import_langchain82 = require("langchain");
|
|
43355
41812
|
|
|
43356
41813
|
// src/tool_lattice/widget/loadGuidelines.ts
|
|
43357
|
-
var
|
|
43358
|
-
var
|
|
41814
|
+
var import_langchain80 = require("langchain");
|
|
41815
|
+
var import_zod66 = require("zod");
|
|
43359
41816
|
|
|
43360
41817
|
// src/middlewares/guidelines/index.ts
|
|
43361
41818
|
var CORE = `# Imagine \u2014 Visual Creation Suite
|
|
@@ -44146,13 +42603,13 @@ function getGuidelines(modules) {
|
|
|
44146
42603
|
var AVAILABLE_MODULES = Object.keys(MODULE_SECTIONS);
|
|
44147
42604
|
|
|
44148
42605
|
// src/tool_lattice/widget/loadGuidelines.ts
|
|
44149
|
-
var LoadGuidelinesInputSchema =
|
|
44150
|
-
modules:
|
|
42606
|
+
var LoadGuidelinesInputSchema = import_zod66.z.object({
|
|
42607
|
+
modules: import_zod66.z.array(import_zod66.z.string()).describe(
|
|
44151
42608
|
"Which design modules to load. Choose all that apply. Available modules: [" + AVAILABLE_MODULES.join(",") + "]"
|
|
44152
42609
|
)
|
|
44153
42610
|
});
|
|
44154
42611
|
function createLoadGuidelinesTool() {
|
|
44155
|
-
return (0,
|
|
42612
|
+
return (0, import_langchain80.tool)(
|
|
44156
42613
|
async (input) => {
|
|
44157
42614
|
const result = getGuidelines(input.modules);
|
|
44158
42615
|
return result;
|
|
@@ -44166,8 +42623,8 @@ function createLoadGuidelinesTool() {
|
|
|
44166
42623
|
}
|
|
44167
42624
|
|
|
44168
42625
|
// src/tool_lattice/widget/showWidget.ts
|
|
44169
|
-
var
|
|
44170
|
-
var
|
|
42626
|
+
var import_langchain81 = require("langchain");
|
|
42627
|
+
var import_zod67 = require("zod");
|
|
44171
42628
|
function containsForbiddenTags(code) {
|
|
44172
42629
|
const forbiddenPatterns = [
|
|
44173
42630
|
/<!DOCTYPE/i,
|
|
@@ -44189,20 +42646,20 @@ function validateWidgetCode(code) {
|
|
|
44189
42646
|
}
|
|
44190
42647
|
return { valid: true };
|
|
44191
42648
|
}
|
|
44192
|
-
var ShowWidgetInputSchema =
|
|
44193
|
-
i_have_seen_guidelines:
|
|
42649
|
+
var ShowWidgetInputSchema = import_zod67.z.object({
|
|
42650
|
+
i_have_seen_guidelines: import_zod67.z.boolean().describe(
|
|
44194
42651
|
"Must be true. Confirm you have called load_guidelines first."
|
|
44195
42652
|
),
|
|
44196
|
-
title:
|
|
44197
|
-
loading_messages:
|
|
42653
|
+
title: import_zod67.z.string().describe("Title displayed above the widget"),
|
|
42654
|
+
loading_messages: import_zod67.z.array(import_zod67.z.string()).optional().describe(
|
|
44198
42655
|
"1-4 short strings shown while the widget renders"
|
|
44199
42656
|
),
|
|
44200
|
-
widget_code:
|
|
42657
|
+
widget_code: import_zod67.z.string().describe(
|
|
44201
42658
|
"HTML fragment to render. Rules: 1. No DOCTYPE, <html>, <head>, or <body> tags. 2. Order: <style> block first, then HTML content, then <script> last. 3. Use only CSS variables for colors (e.g. var(--color-accent)). 4. No gradients, shadows, or blur effects. For SVG: start directly with <svg> tag."
|
|
44202
42659
|
)
|
|
44203
42660
|
});
|
|
44204
42661
|
function createShowWidgetTool() {
|
|
44205
|
-
return (0,
|
|
42662
|
+
return (0, import_langchain81.tool)(
|
|
44206
42663
|
async (input) => {
|
|
44207
42664
|
if (!input.i_have_seen_guidelines) {
|
|
44208
42665
|
return "Error: You must call load_guidelines before using show_widget. Set i_have_seen_guidelines to true only after loading guidelines.";
|
|
@@ -44233,7 +42690,7 @@ function createWidgetMiddleware() {
|
|
|
44233
42690
|
createLoadGuidelinesTool(),
|
|
44234
42691
|
createShowWidgetTool()
|
|
44235
42692
|
];
|
|
44236
|
-
return (0,
|
|
42693
|
+
return (0, import_langchain82.createMiddleware)({
|
|
44237
42694
|
name: "widgetMiddleware",
|
|
44238
42695
|
contextSchema,
|
|
44239
42696
|
tools
|
|
@@ -44257,8 +42714,8 @@ var widgetPlugin = {
|
|
|
44257
42714
|
};
|
|
44258
42715
|
|
|
44259
42716
|
// src/middlewares/taskMiddleware.ts
|
|
44260
|
-
var
|
|
44261
|
-
var
|
|
42717
|
+
var import_langchain83 = require("langchain");
|
|
42718
|
+
var import_zod68 = require("zod");
|
|
44262
42719
|
var import_langgraph16 = require("@langchain/langgraph");
|
|
44263
42720
|
|
|
44264
42721
|
// src/util/truncateForJson.ts
|
|
@@ -44318,7 +42775,7 @@ function truncateForJson(value, options = {}) {
|
|
|
44318
42775
|
}
|
|
44319
42776
|
|
|
44320
42777
|
// src/middlewares/taskMiddleware.ts
|
|
44321
|
-
var
|
|
42778
|
+
var import_protocols33 = require("@axiom-lattice/protocols");
|
|
44322
42779
|
|
|
44323
42780
|
// src/middlewares/taskResponseSerialization.ts
|
|
44324
42781
|
var TASK_RESPONSE_SCALAR_MAX_BYTES = 4096;
|
|
@@ -44786,7 +43243,7 @@ function classifyTaskAuthority(runConfig) {
|
|
|
44786
43243
|
return delegatedTaskId ? { kind: "delegated", taskId: delegatedTaskId } : { kind: "ordinary" };
|
|
44787
43244
|
}
|
|
44788
43245
|
try {
|
|
44789
|
-
const trusted = (0,
|
|
43246
|
+
const trusted = (0, import_protocols33.parseTrustedRunContext)(hasProjectTask ? { projectTask: runConfig.projectTask } : { projectRoom: runConfig.projectRoom });
|
|
44790
43247
|
return { kind: hasProjectTask ? "projectTask" : "projectRoom", trusted };
|
|
44791
43248
|
} catch {
|
|
44792
43249
|
return { kind: "invalid" };
|
|
@@ -45119,7 +43576,7 @@ function getTaskWorkItemStore() {
|
|
|
45119
43576
|
return getStoreLattice("default", "taskWorkItem").store;
|
|
45120
43577
|
}
|
|
45121
43578
|
function getProjectTaskWorkItemStore() {
|
|
45122
|
-
return (0,
|
|
43579
|
+
return (0, import_protocols33.requireProjectTaskWorkItemStore)(getTaskWorkItemStore());
|
|
45123
43580
|
}
|
|
45124
43581
|
function reviewInterruption(task) {
|
|
45125
43582
|
const value = task.context?.interruption;
|
|
@@ -45135,73 +43592,73 @@ function buildReviewMarkdown(task) {
|
|
|
45135
43592
|
result: task.result
|
|
45136
43593
|
});
|
|
45137
43594
|
}
|
|
45138
|
-
var manageTaskSchema =
|
|
45139
|
-
action:
|
|
45140
|
-
id:
|
|
45141
|
-
title:
|
|
45142
|
-
description:
|
|
45143
|
-
priority:
|
|
45144
|
-
status:
|
|
45145
|
-
dueDate:
|
|
45146
|
-
metadata:
|
|
45147
|
-
metadataFilter:
|
|
45148
|
-
|
|
43595
|
+
var manageTaskSchema = import_zod68.z.object({
|
|
43596
|
+
action: import_zod68.z.enum(["create", "get", "list", "update", "set_status", "add_activity", "delete"]).describe("Action to perform. Available: create, get, list, update, set_status, add_activity, delete. To change status, use set_status. To change content fields, use update."),
|
|
43597
|
+
id: import_zod68.z.string().optional().describe("Task ID (required for get, update, add_activity; required for delete unless ids is given)"),
|
|
43598
|
+
title: import_zod68.z.string().optional().describe("Task title (required for create)"),
|
|
43599
|
+
description: import_zod68.z.string().optional().describe("Task description in Markdown"),
|
|
43600
|
+
priority: import_zod68.z.enum(["low", "medium", "high"]).optional().describe("Priority level"),
|
|
43601
|
+
status: import_zod68.z.enum(["pending", "in_progress", "review", "failed", "interrupted", "completed", "cancelled"]).optional().describe("Task status. For status-only changes, prefer set_status action. Set 'in_progress' when you start processing a task you hold; 'completed'/'failed' require the task to be 'in_progress'. Agent summary-only interrupted updates default to missing_input"),
|
|
43602
|
+
dueDate: import_zod68.z.string().optional().describe("Due date (ISO 8601 format)"),
|
|
43603
|
+
metadata: import_zod68.z.record(import_zod68.z.unknown()).optional().describe("Structured metadata (e.g. projectId, module)"),
|
|
43604
|
+
metadataFilter: import_zod68.z.record(
|
|
43605
|
+
import_zod68.z.union([import_zod68.z.string(), import_zod68.z.number(), import_zod68.z.boolean()])
|
|
45149
43606
|
).optional().describe("List-only filter. Every key must equal the task metadata value, e.g. {projectId:'p1', retries:2}. Multiple keys AND together."),
|
|
45150
|
-
parentId:
|
|
45151
|
-
sourceId:
|
|
45152
|
-
context:
|
|
45153
|
-
ownerType:
|
|
45154
|
-
ownerId:
|
|
45155
|
-
requireReview:
|
|
45156
|
-
dependencies:
|
|
45157
|
-
dependencyTaskIds:
|
|
45158
|
-
result:
|
|
45159
|
-
failureReason:
|
|
45160
|
-
files:
|
|
45161
|
-
uri:
|
|
45162
|
-
name:
|
|
45163
|
-
addedBy:
|
|
43607
|
+
parentId: import_zod68.z.string().optional().describe("Parent task ID for grouping subtasks"),
|
|
43608
|
+
sourceId: import_zod68.z.string().optional().describe("Source session/thread ID"),
|
|
43609
|
+
context: import_zod68.z.record(import_zod68.z.unknown()).optional().describe("Additional context data"),
|
|
43610
|
+
ownerType: import_zod68.z.enum(["user", "agent"]).optional().describe("Owner type. Defaults to 'user' if omitted"),
|
|
43611
|
+
ownerId: import_zod68.z.string().optional().describe("Owner ID. Auto-filled from current user/agent if omitted"),
|
|
43612
|
+
requireReview: import_zod68.z.boolean().optional().describe("If true, agent completion pauses as interrupted(review_required) for HITL approval"),
|
|
43613
|
+
dependencies: import_zod68.z.array(import_zod68.z.string()).optional().describe("List of task IDs that must be completed before this task can start"),
|
|
43614
|
+
dependencyTaskIds: import_zod68.z.array(import_zod68.z.string().trim().min(1)).optional().describe("Exact blocking task IDs required for an external_dependency interruption"),
|
|
43615
|
+
result: import_zod68.z.string().optional().describe("Result summary. Used with set_status status='completed' or update status='completed'"),
|
|
43616
|
+
failureReason: import_zod68.z.string().optional().describe("Failure reason. Used with set_status status='failed' or update status='failed'"),
|
|
43617
|
+
files: import_zod68.z.array(import_zod68.z.object({
|
|
43618
|
+
uri: import_zod68.z.string().describe("Uniquely locates the resource: http(s):// URL, /s/:token share, or sandbox path"),
|
|
43619
|
+
name: import_zod68.z.string().optional().describe("Display name"),
|
|
43620
|
+
addedBy: import_zod68.z.enum(["user", "agent"]).optional().describe("Who attached the file")
|
|
45164
43621
|
})).optional().describe("File references attached to this task"),
|
|
45165
|
-
beliefImpact:
|
|
45166
|
-
key:
|
|
45167
|
-
after:
|
|
45168
|
-
basis:
|
|
45169
|
-
isNew:
|
|
43622
|
+
beliefImpact: import_zod68.z.array(import_zod68.z.object({
|
|
43623
|
+
key: import_zod68.z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
|
|
43624
|
+
after: import_zod68.z.number().int().min(0).max(100),
|
|
43625
|
+
basis: import_zod68.z.string().trim().min(1).max(1e3),
|
|
43626
|
+
isNew: import_zod68.z.boolean().optional().describe("Set true only to add a belief key that is absent from the belief owner's Belief State; omit for keys that already exist")
|
|
45170
43627
|
})).optional().describe("Structured belief reports required when an agent-owned task completes; existing keys update the belief owner's table, and a brand-new key must be declared with isNew: true"),
|
|
45171
|
-
content:
|
|
45172
|
-
summary:
|
|
45173
|
-
executionResultId:
|
|
43628
|
+
content: import_zod68.z.string().optional().describe("Markdown content required for add_activity"),
|
|
43629
|
+
summary: import_zod68.z.string().optional().describe("Brief summary of the operation"),
|
|
43630
|
+
executionResultId: import_zod68.z.string().refine(import_protocols33.isExecutionResultEventKey, {
|
|
45174
43631
|
message: "executionResultId must be the execution-result:<threadId> event key returned by task()"
|
|
45175
43632
|
}).optional().describe(
|
|
45176
43633
|
"Canonical ASCII `execution-result:<suffix>` event key returned by task(); the nonempty suffix allows only A-Z, a-z, 0-9, period, underscore, colon, and hyphen, and is not a database row ID"
|
|
45177
43634
|
),
|
|
45178
|
-
ids:
|
|
43635
|
+
ids: import_zod68.z.array(import_zod68.z.string().trim().min(1)).optional().describe("Task IDs to delete in one batch (delete action only). Use with or instead of id.")
|
|
45179
43636
|
}).superRefine((input, context) => {
|
|
45180
43637
|
if (input.executionResultId && input.action !== "update" && input.action !== "set_status" && input.action !== "add_activity") {
|
|
45181
43638
|
context.addIssue({
|
|
45182
|
-
code:
|
|
43639
|
+
code: import_zod68.z.ZodIssueCode.custom,
|
|
45183
43640
|
path: ["executionResultId"],
|
|
45184
43641
|
message: "executionResultId is valid only for update, set_status, or add_activity"
|
|
45185
43642
|
});
|
|
45186
43643
|
}
|
|
45187
43644
|
if (input.metadataFilter && input.action !== "list") {
|
|
45188
43645
|
context.addIssue({
|
|
45189
|
-
code:
|
|
43646
|
+
code: import_zod68.z.ZodIssueCode.custom,
|
|
45190
43647
|
path: ["metadataFilter"],
|
|
45191
43648
|
message: "metadataFilter is valid only for list"
|
|
45192
43649
|
});
|
|
45193
43650
|
}
|
|
45194
43651
|
if (input.ids && input.action !== "delete") {
|
|
45195
43652
|
context.addIssue({
|
|
45196
|
-
code:
|
|
43653
|
+
code: import_zod68.z.ZodIssueCode.custom,
|
|
45197
43654
|
path: ["ids"],
|
|
45198
43655
|
message: "ids is valid only for delete"
|
|
45199
43656
|
});
|
|
45200
43657
|
}
|
|
45201
43658
|
});
|
|
45202
|
-
var startTaskSchema =
|
|
45203
|
-
taskId:
|
|
45204
|
-
agentId:
|
|
43659
|
+
var startTaskSchema = import_zod68.z.object({
|
|
43660
|
+
taskId: import_zod68.z.string().trim().min(1).describe("ID of the persisted TaskItem to start"),
|
|
43661
|
+
agentId: import_zod68.z.string().trim().min(1).describe(
|
|
45205
43662
|
`ID of the Agent that should execute the task. Use "general-purpose" to run the caller's own capabilities as an isolated worker.`
|
|
45206
43663
|
)
|
|
45207
43664
|
});
|
|
@@ -45235,7 +43692,7 @@ async function getPendingExecutionResultIds(store, tenantId2, taskId) {
|
|
|
45235
43692
|
order: "desc",
|
|
45236
43693
|
limit: PENDING_EXECUTION_RESULT_LIMIT + 1
|
|
45237
43694
|
});
|
|
45238
|
-
const canonicalCandidates = candidates.slice(0, PENDING_EXECUTION_RESULT_LIMIT + 1).filter((item) => (0,
|
|
43695
|
+
const canonicalCandidates = candidates.slice(0, PENDING_EXECUTION_RESULT_LIMIT + 1).filter((item) => (0, import_protocols33.isExecutionResultEventKey)(item.eventKey));
|
|
45239
43696
|
const reconciliationRows = new Array(canonicalCandidates.length);
|
|
45240
43697
|
let nextCandidateIndex = 0;
|
|
45241
43698
|
let firstError;
|
|
@@ -45877,8 +44334,8 @@ function createTaskMiddleware(options = {}) {
|
|
|
45877
44334
|
let reconciliationMetadata = {};
|
|
45878
44335
|
let descriptionMutated = false;
|
|
45879
44336
|
if (isAgentTask && input.description !== void 0 && !valuesEqual(input.description, existing.description)) {
|
|
45880
|
-
const oldBelief = (0,
|
|
45881
|
-
const newBelief = (0,
|
|
44337
|
+
const oldBelief = (0, import_protocols33.parseTaskBeliefState)(existing.description ?? "");
|
|
44338
|
+
const newBelief = (0, import_protocols33.parseTaskBeliefState)(input.description);
|
|
45882
44339
|
const hasBeliefState = oldBelief.success || newBelief.success;
|
|
45883
44340
|
if (hasBeliefState) {
|
|
45884
44341
|
await validateExecutionResult();
|
|
@@ -46576,12 +45033,12 @@ function createTaskMiddleware(options = {}) {
|
|
|
46576
45033
|
...trustedCaller ? { callerMembershipId: trustedCaller.membershipId, callerAssistantId: trustedCaller.assistantId } : {}
|
|
46577
45034
|
}));
|
|
46578
45035
|
};
|
|
46579
|
-
return (0,
|
|
45036
|
+
return (0, import_langchain83.createMiddleware)({
|
|
46580
45037
|
name: "TaskMiddleware",
|
|
46581
45038
|
contextSchema,
|
|
46582
45039
|
// Persisted between invocations (ADRs: the run↔task binding survives turns).
|
|
46583
|
-
stateSchema:
|
|
46584
|
-
taskId:
|
|
45040
|
+
stateSchema: import_zod68.z.object({
|
|
45041
|
+
taskId: import_zod68.z.string().default("")
|
|
46585
45042
|
}),
|
|
46586
45043
|
// CLAIM: a run that holds a task moves it to in_progress (idempotent).
|
|
46587
45044
|
beforeAgent: async (state, runtime) => {
|
|
@@ -46691,7 +45148,7 @@ ${TASK_CONVERGENCE_GUIDANCE}
|
|
|
46691
45148
|
});
|
|
46692
45149
|
},
|
|
46693
45150
|
tools: [
|
|
46694
|
-
(0,
|
|
45151
|
+
(0, import_langchain83.tool)(
|
|
46695
45152
|
handleManageTask,
|
|
46696
45153
|
{
|
|
46697
45154
|
name: "manage_task",
|
|
@@ -46737,7 +45194,7 @@ to an expert \u2014 never re-dispatch the task you are processing.`,
|
|
|
46737
45194
|
schema: manageTaskSchema
|
|
46738
45195
|
}
|
|
46739
45196
|
),
|
|
46740
|
-
(0,
|
|
45197
|
+
(0, import_langchain83.tool)(handleStartTask, {
|
|
46741
45198
|
name: "task",
|
|
46742
45199
|
description: `Start a persisted TaskItem with any existing Agent in a fresh isolated thread. Use this to delegate work \u2014 dispatch a subtask you created to the agent that should execute it; never re-dispatch the task you are currently processing (give the expert a child task instead). Pass agentId "general-purpose" for the general-purpose worker \u2014 ${DEFAULT_GENERAL_PURPOSE_DESCRIPTION} It has access to all the caller's tools, model, and middleware, so use it for general-purpose subtasks, to isolate context and token usage, and whenever no specialized agent fits. The target does NOT need task-management tools: it runs and returns an observation plus an executionResultId, and the caller passes that executionResultId to the manage_task update or add_activity that interprets and records it. A project task instead returns a managed result (success:true, managed:true) because the project-lifecycle queue owns execution.`,
|
|
46743
45200
|
schema: startTaskSchema
|
|
@@ -46881,8 +45338,8 @@ canonical Belief State:
|
|
|
46881
45338
|
};
|
|
46882
45339
|
|
|
46883
45340
|
// src/middlewares/documentLearningMiddleware.ts
|
|
46884
|
-
var
|
|
46885
|
-
var
|
|
45341
|
+
var import_protocols34 = require("@axiom-lattice/protocols");
|
|
45342
|
+
var import_langchain84 = require("langchain");
|
|
46886
45343
|
|
|
46887
45344
|
// src/middlewares/documentLearningSkills.ts
|
|
46888
45345
|
var LEARN_CAPABILITY_SKILL = `---
|
|
@@ -47121,7 +45578,7 @@ patterns discovered, recommendations. Include validation coverage: user-sample N
|
|
|
47121
45578
|
`;
|
|
47122
45579
|
|
|
47123
45580
|
// src/middlewares/documentLearningMiddleware.ts
|
|
47124
|
-
var createDocumentLearningMiddleware = () => (0,
|
|
45581
|
+
var createDocumentLearningMiddleware = () => (0, import_langchain84.createMiddleware)({
|
|
47125
45582
|
name: "DocumentLearningMiddleware",
|
|
47126
45583
|
contextSchema,
|
|
47127
45584
|
tools: []
|
|
@@ -47148,7 +45605,7 @@ var documentLearningPlugin = {
|
|
|
47148
45605
|
key: "document-learner",
|
|
47149
45606
|
name: "Document Learning Agent",
|
|
47150
45607
|
description: "Read documents and build structured skill systems with evaluations. Use this agent when you need to extract knowledge from documents and turn it into reusable, testable agent skills.",
|
|
47151
|
-
type:
|
|
45608
|
+
type: import_protocols34.AgentType.DEEP_AGENT,
|
|
47152
45609
|
prompt: DOCUMENT_LEARNER_SYSTEM_PROMPT,
|
|
47153
45610
|
subAgents: ["document-parser-benchmark"],
|
|
47154
45611
|
tools: [
|
|
@@ -47239,12 +45696,12 @@ var documentLearningPlugin = {
|
|
|
47239
45696
|
};
|
|
47240
45697
|
|
|
47241
45698
|
// src/middlewares/documentParserMiddleware.ts
|
|
47242
|
-
var
|
|
45699
|
+
var import_langchain86 = require("langchain");
|
|
47243
45700
|
|
|
47244
45701
|
// src/tool_lattice/document_parser/index.ts
|
|
47245
45702
|
var path7 = __toESM(require("path"));
|
|
47246
|
-
var
|
|
47247
|
-
var
|
|
45703
|
+
var import_zod69 = __toESM(require("zod"));
|
|
45704
|
+
var import_langchain85 = require("langchain");
|
|
47248
45705
|
var PARSE_DOCUMENT_DESCRIPTION = `Parse a document file (docx, pdf) into structured Markdown using a remote document parsing service.
|
|
47249
45706
|
This tool handles the full pipeline internally: file upload \u2192 document parsing \u2192 polling until complete \u2192 download result \u2192 save to filesystem.
|
|
47250
45707
|
|
|
@@ -47367,7 +45824,7 @@ function createParseDocumentTool({
|
|
|
47367
45824
|
baseUrl = "",
|
|
47368
45825
|
apiKey = ""
|
|
47369
45826
|
}) {
|
|
47370
|
-
return (0,
|
|
45827
|
+
return (0, import_langchain85.tool)(
|
|
47371
45828
|
async (input, exe_config) => {
|
|
47372
45829
|
try {
|
|
47373
45830
|
const runConfig = exe_config?.configurable?.runConfig ?? { assistant_id: "", thread_id: "" };
|
|
@@ -47438,17 +45895,17 @@ function createParseDocumentTool({
|
|
|
47438
45895
|
{
|
|
47439
45896
|
name: "parse_document",
|
|
47440
45897
|
description: PARSE_DOCUMENT_DESCRIPTION,
|
|
47441
|
-
schema:
|
|
47442
|
-
file_path:
|
|
45898
|
+
schema: import_zod69.default.object({
|
|
45899
|
+
file_path: import_zod69.default.string().describe(
|
|
47443
45900
|
'Absolute path to the document file. Must point to an existing .docx or .pdf file. Example: "/project/reports/contract.docx". The file must be accessible from the current workspace.'
|
|
47444
45901
|
),
|
|
47445
|
-
engine:
|
|
45902
|
+
engine: import_zod69.default.string().describe(
|
|
47446
45903
|
'Parsing engine to use. Available options: "textin" (recommended, works with local files, supports docx/pdf), "datalab" (alternative engine for docx/pdf), "mineru" (requires public URL, use only if textin/datalab fail), "paddleocr_remote" (PaddleOCR, good for scanned documents), "qwen_ocr" (OCR-focused, best for image-heavy PDFs).'
|
|
47447
45904
|
),
|
|
47448
|
-
output_path:
|
|
45905
|
+
output_path: import_zod69.default.string().optional().describe(
|
|
47449
45906
|
'Path to save the parsed result. If not specified, the input extension is replaced with .md. Example: "/project/report.docx" becomes "/project/report.md". Parent directories are created automatically.'
|
|
47450
45907
|
),
|
|
47451
|
-
output_format:
|
|
45908
|
+
output_format: import_zod69.default.enum(["markdown", "json"]).optional().default("markdown").describe(
|
|
47452
45909
|
'Output format. "markdown": structured Markdown with tables, headers, formatting preserved (recommended). "json": raw JSON output from the parsing engine (for programmatic use).'
|
|
47453
45910
|
)
|
|
47454
45911
|
})
|
|
@@ -47457,7 +45914,7 @@ function createParseDocumentTool({
|
|
|
47457
45914
|
}
|
|
47458
45915
|
|
|
47459
45916
|
// src/middlewares/documentParserMiddleware.ts
|
|
47460
|
-
var
|
|
45917
|
+
var import_protocols35 = require("@axiom-lattice/protocols");
|
|
47461
45918
|
|
|
47462
45919
|
// src/middlewares/documentBenchmarkWorkflow.ts
|
|
47463
45920
|
var DOCUMENT_PARSER_BENCHMARK_YAML = `name: document-parser-benchmark
|
|
@@ -47866,7 +46323,7 @@ def main() -> None:
|
|
|
47866
46323
|
if __name__ == "__main__":
|
|
47867
46324
|
main()
|
|
47868
46325
|
`;
|
|
47869
|
-
var
|
|
46326
|
+
var resources = {
|
|
47870
46327
|
"references/api_reference.md": { mimeType: "text/markdown", content: `# API reference
|
|
47871
46328
|
|
|
47872
46329
|
The supported command-line form is 'markitdown input -o output.md'. The Python API uses 'MarkItDown().convert(path)' upstream, but this runtime prefers the installed CLI and does not provide direct Python SDK LLM calls. Use local conversion for local files and keep output as Markdown.` },
|
|
@@ -47895,7 +46352,7 @@ Single file: 'markitdown input -o output.md'. Ordinary directory: 'scripts/batch
|
|
|
47895
46352
|
var DOCUMENT_PARSER_MARKITDOWN_SKILL = {
|
|
47896
46353
|
version: "1.1.0",
|
|
47897
46354
|
content: MARKITDOWN_SKILL_CONTENT,
|
|
47898
|
-
resources
|
|
46355
|
+
resources
|
|
47899
46356
|
};
|
|
47900
46357
|
|
|
47901
46358
|
// src/middlewares/documentParserMiddleware.ts
|
|
@@ -47904,7 +46361,7 @@ function createDocumentParserMiddleware(config) {
|
|
|
47904
46361
|
const baseUrl = config.baseUrl || "";
|
|
47905
46362
|
const apiKey = config.apiKey || "";
|
|
47906
46363
|
const connections = Array.isArray(config.connections) ? config.connections.filter((key5) => typeof key5 === "string") : [];
|
|
47907
|
-
return (0,
|
|
46364
|
+
return (0, import_langchain86.createMiddleware)({
|
|
47908
46365
|
name: "DocumentParser",
|
|
47909
46366
|
contextSchema,
|
|
47910
46367
|
tools: [createParseDocumentTool({ connectAll, connections, baseUrl, apiKey })]
|
|
@@ -47982,7 +46439,7 @@ var documentParserPlugin = {
|
|
|
47982
46439
|
agents: {
|
|
47983
46440
|
"document-parser-benchmark": {
|
|
47984
46441
|
key: "document-parser-benchmark",
|
|
47985
|
-
type:
|
|
46442
|
+
type: import_protocols35.AgentType.WORKFLOW,
|
|
47986
46443
|
name: "Document Parser Benchmark",
|
|
47987
46444
|
description: "Benchmark document parsing engines. Parses a document with 5 engines in parallel, scores results, and produces a ranking report. Use this when you need to evaluate which parsing engine works best for a given document.",
|
|
47988
46445
|
prompt: "Benchmark document parsing engines: parse with 5 engines, score, and rank results.",
|
|
@@ -48019,9 +46476,9 @@ var documentParserPlugin = {
|
|
|
48019
46476
|
|
|
48020
46477
|
// src/middlewares/projectRoomMiddleware.ts
|
|
48021
46478
|
var import_crypto10 = require("crypto");
|
|
48022
|
-
var
|
|
48023
|
-
var
|
|
48024
|
-
var
|
|
46479
|
+
var import_protocols36 = require("@axiom-lattice/protocols");
|
|
46480
|
+
var import_langchain87 = require("langchain");
|
|
46481
|
+
var import_zod70 = require("zod");
|
|
48025
46482
|
var PROJECT_ROOM_CONTEXT_REQUIRED = "PROJECT_ROOM_CONTEXT_REQUIRED";
|
|
48026
46483
|
var PROJECT_ROOM_POST_FAILED = "PROJECT_ROOM_POST_FAILED";
|
|
48027
46484
|
var PROJECT_ROOM_ROSTER_FAILED = "PROJECT_ROOM_ROSTER_FAILED";
|
|
@@ -48041,15 +46498,15 @@ var ROSTER_FAILED = JSON.stringify({
|
|
|
48041
46498
|
error: PROJECT_ROOM_ROSTER_FAILED,
|
|
48042
46499
|
message: PROJECT_ROOM_ROSTER_FAILED_MESSAGE
|
|
48043
46500
|
});
|
|
48044
|
-
var postSchema =
|
|
48045
|
-
text:
|
|
46501
|
+
var postSchema = import_zod70.z.object({
|
|
46502
|
+
text: import_zod70.z.string().trim().min(1).max(2e4)
|
|
48046
46503
|
}).strict();
|
|
48047
|
-
var listSchema =
|
|
46504
|
+
var listSchema = import_zod70.z.object({}).strict();
|
|
48048
46505
|
function ownDataValue2(record, key5) {
|
|
48049
46506
|
if (typeof record !== "object" || record === null || Array.isArray(record)) return void 0;
|
|
48050
46507
|
try {
|
|
48051
46508
|
const descriptor = Object.getOwnPropertyDescriptor(record, key5);
|
|
48052
|
-
return (0,
|
|
46509
|
+
return (0, import_protocols36.descriptorDataValue)(descriptor)?.value;
|
|
48053
46510
|
} catch {
|
|
48054
46511
|
return void 0;
|
|
48055
46512
|
}
|
|
@@ -48059,14 +46516,14 @@ function readTrustedRoomScope(config) {
|
|
|
48059
46516
|
const runConfig = ownDataValue2(configurable, "runConfig");
|
|
48060
46517
|
const projectRoom = ownDataValue2(runConfig, "projectRoom");
|
|
48061
46518
|
try {
|
|
48062
|
-
return (0,
|
|
46519
|
+
return (0, import_protocols36.parseTrustedRunContext)({ projectRoom }).projectRoom;
|
|
48063
46520
|
} catch {
|
|
48064
46521
|
return void 0;
|
|
48065
46522
|
}
|
|
48066
46523
|
}
|
|
48067
46524
|
function exactValues2(value, required, optional = []) {
|
|
48068
46525
|
try {
|
|
48069
|
-
return (0,
|
|
46526
|
+
return (0, import_protocols36.snapshotExactRecord)(value, required, optional);
|
|
48070
46527
|
} catch {
|
|
48071
46528
|
return void 0;
|
|
48072
46529
|
}
|
|
@@ -48102,7 +46559,7 @@ function snapshotMembership3(value) {
|
|
|
48102
46559
|
return { ...values, joinedAt, updatedAt };
|
|
48103
46560
|
}
|
|
48104
46561
|
function snapshotRows(value) {
|
|
48105
|
-
return (0,
|
|
46562
|
+
return (0, import_protocols36.snapshotExactArray)(value) ?? [];
|
|
48106
46563
|
}
|
|
48107
46564
|
async function hasActiveCurrentMembership(scope) {
|
|
48108
46565
|
const memberships = getStoreLattice("default", "projectBotMembership").store;
|
|
@@ -48111,10 +46568,10 @@ async function hasActiveCurrentMembership(scope) {
|
|
|
48111
46568
|
return true;
|
|
48112
46569
|
}
|
|
48113
46570
|
function createProjectRoomMiddleware() {
|
|
48114
|
-
return (0,
|
|
46571
|
+
return (0, import_langchain87.createMiddleware)({
|
|
48115
46572
|
name: "ProjectRoomMiddleware",
|
|
48116
46573
|
tools: [
|
|
48117
|
-
(0,
|
|
46574
|
+
(0, import_langchain87.tool)(async (input, config) => {
|
|
48118
46575
|
const { text } = input;
|
|
48119
46576
|
const scope = readTrustedRoomScope(config);
|
|
48120
46577
|
if (!scope) return CONTEXT_REQUIRED;
|
|
@@ -48145,7 +46602,7 @@ function createProjectRoomMiddleware() {
|
|
|
48145
46602
|
description: "Post a text reply to the current trusted Project Room message",
|
|
48146
46603
|
schema: postSchema
|
|
48147
46604
|
}),
|
|
48148
|
-
(0,
|
|
46605
|
+
(0, import_langchain87.tool)(async (_input, config) => {
|
|
48149
46606
|
const scope = readTrustedRoomScope(config);
|
|
48150
46607
|
if (!scope) return CONTEXT_REQUIRED;
|
|
48151
46608
|
try {
|
|
@@ -48187,9 +46644,9 @@ var projectRoomPlugin = {
|
|
|
48187
46644
|
};
|
|
48188
46645
|
|
|
48189
46646
|
// src/middlewares/sandboxPluginsMiddleware.ts
|
|
48190
|
-
var
|
|
48191
|
-
var
|
|
48192
|
-
var
|
|
46647
|
+
var import_langchain88 = require("langchain");
|
|
46648
|
+
var import_zod71 = require("zod");
|
|
46649
|
+
var import_protocols37 = require("@axiom-lattice/protocols");
|
|
48193
46650
|
|
|
48194
46651
|
// src/middlewares/sandboxPluginsSkills.ts
|
|
48195
46652
|
var PLUGIN_JSON_TEMPLATE = `{
|
|
@@ -48910,16 +47367,16 @@ function tenantIdFrom(exeConfig) {
|
|
|
48910
47367
|
const c = exeConfig;
|
|
48911
47368
|
return c?.configurable?.runConfig?.tenantId ?? "default";
|
|
48912
47369
|
}
|
|
48913
|
-
var managePluginSchema =
|
|
48914
|
-
action:
|
|
48915
|
-
type:
|
|
48916
|
-
manifest:
|
|
48917
|
-
handlers:
|
|
48918
|
-
target:
|
|
48919
|
-
kind:
|
|
48920
|
-
name:
|
|
48921
|
-
input:
|
|
48922
|
-
connectionKey:
|
|
47370
|
+
var managePluginSchema = import_zod71.z.object({
|
|
47371
|
+
action: import_zod71.z.enum(["list", "get", "validate", "create", "update", "delete", "reload", "test"]),
|
|
47372
|
+
type: import_zod71.z.string().optional(),
|
|
47373
|
+
manifest: import_zod71.z.record(import_zod71.z.unknown()).optional(),
|
|
47374
|
+
handlers: import_zod71.z.record(import_zod71.z.string()).optional(),
|
|
47375
|
+
target: import_zod71.z.object({
|
|
47376
|
+
kind: import_zod71.z.enum(["tool", "connection-test", "connection-discover"]),
|
|
47377
|
+
name: import_zod71.z.string().optional(),
|
|
47378
|
+
input: import_zod71.z.unknown().optional(),
|
|
47379
|
+
connectionKey: import_zod71.z.string().optional()
|
|
48923
47380
|
}).optional()
|
|
48924
47381
|
});
|
|
48925
47382
|
var sandboxPluginsPlugin = {
|
|
@@ -48939,7 +47396,7 @@ var sandboxPluginsPlugin = {
|
|
|
48939
47396
|
key: "plugin-builder",
|
|
48940
47397
|
name: "Plugin Builder",
|
|
48941
47398
|
description: "Author and manage tenant plugins in the shared sandbox: clarify goal, inputs/outputs, credentials, and whether a UI is needed; then write the manifest and JS handlers, add an optional HTML MCP App UI, and validate/test with the manage_plugin tool.",
|
|
48942
|
-
type:
|
|
47399
|
+
type: import_protocols37.AgentType.DEEP_AGENT,
|
|
48943
47400
|
prompt: PLUGIN_BUILDER_PROMPT,
|
|
48944
47401
|
middleware: [
|
|
48945
47402
|
{
|
|
@@ -48993,10 +47450,10 @@ var sandboxPluginsPlugin = {
|
|
|
48993
47450
|
]
|
|
48994
47451
|
}
|
|
48995
47452
|
},
|
|
48996
|
-
middleware: () => (0,
|
|
47453
|
+
middleware: () => (0, import_langchain88.createMiddleware)({
|
|
48997
47454
|
name: "SandboxPluginsMiddleware",
|
|
48998
47455
|
tools: [
|
|
48999
|
-
(0,
|
|
47456
|
+
(0, import_langchain88.tool)(
|
|
49000
47457
|
async (input, exeConfig) => {
|
|
49001
47458
|
const tenantId2 = tenantIdFrom(exeConfig);
|
|
49002
47459
|
const catalog2 = getSandboxPluginCatalog();
|
|
@@ -49137,7 +47594,6 @@ var BUILTIN_PLUGINS = [
|
|
|
49137
47594
|
sqlPlugin,
|
|
49138
47595
|
skillPlugin,
|
|
49139
47596
|
metricsPlugin,
|
|
49140
|
-
semanticMetricsPlugin,
|
|
49141
47597
|
askUserClarifyPlugin,
|
|
49142
47598
|
widgetPlugin,
|
|
49143
47599
|
clawPlugin,
|
|
@@ -49777,7 +48233,6 @@ registerBuiltinPlugins();
|
|
|
49777
48233
|
createSandboxProvider,
|
|
49778
48234
|
createSandboxResolver,
|
|
49779
48235
|
createSchedulerMiddleware,
|
|
49780
|
-
createSemanticMetricsMiddleware,
|
|
49781
48236
|
createSharePayload,
|
|
49782
48237
|
createTaskExecutionService,
|
|
49783
48238
|
createTaskLifecycleService,
|
|
@@ -49936,7 +48391,6 @@ registerBuiltinPlugins();
|
|
|
49936
48391
|
sandboxLatticeManager,
|
|
49937
48392
|
sanitizeToolCallId,
|
|
49938
48393
|
scheduleLatticeManager,
|
|
49939
|
-
semanticMetricsPlugin,
|
|
49940
48394
|
serializePluginMeta,
|
|
49941
48395
|
serializeTaskMutationSuccess,
|
|
49942
48396
|
serializeTaskNormalizationFallback,
|