@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.mjs CHANGED
@@ -445,11 +445,11 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
445
445
  * @param key Lattice键名
446
446
  * @param tool 已有的StructuredTool实例
447
447
  */
448
- registerExistingTool(key5, tool71) {
448
+ registerExistingTool(key5, tool68) {
449
449
  const config = {
450
- name: tool71.name,
451
- description: tool71.description,
452
- schema: tool71.schema,
450
+ name: tool68.name,
451
+ description: tool68.description,
452
+ schema: tool68.schema,
453
453
  // StructuredTool的schema已经是Zod兼容的
454
454
  needUserApprove: false
455
455
  // MCP工具默认不需要用户批准
@@ -457,7 +457,7 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
457
457
  const toolLattice = {
458
458
  key: key5,
459
459
  config,
460
- client: tool71
460
+ client: tool68
461
461
  };
462
462
  this.register(key5, toolLattice);
463
463
  }
@@ -468,14 +468,14 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
468
468
  * @param key - tool lattice key (no tenant prefix)
469
469
  * @param tool - the StructuredTool client
470
470
  */
471
- registerExistingToolWithTenant(tenantId2, key5, tool71) {
471
+ registerExistingToolWithTenant(tenantId2, key5, tool68) {
472
472
  const config = {
473
- name: tool71.name,
474
- description: tool71.description,
475
- schema: tool71.schema,
473
+ name: tool68.name,
474
+ description: tool68.description,
475
+ schema: tool68.schema,
476
476
  needUserApprove: false
477
477
  };
478
- const toolLattice = { key: key5, config, client: tool71 };
478
+ const toolLattice = { key: key5, config, client: tool68 };
479
479
  this.registerWithTenant(tenantId2, key5, toolLattice);
480
480
  }
481
481
  /**
@@ -525,8 +525,8 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
525
525
  };
526
526
  var toolLatticeManager = ToolLatticeManager.getInstance();
527
527
  var registerToolLattice = (key5, config, executor) => toolLatticeManager.registerLattice(key5, config, executor);
528
- var registerExistingTool = (key5, tool71) => toolLatticeManager.registerExistingTool(key5, tool71);
529
- var registerExistingToolWithTenant = (tenantId2, key5, tool71) => toolLatticeManager.registerExistingToolWithTenant(tenantId2, key5, tool71);
528
+ var registerExistingTool = (key5, tool68) => toolLatticeManager.registerExistingTool(key5, tool68);
529
+ var registerExistingToolWithTenant = (tenantId2, key5, tool68) => toolLatticeManager.registerExistingToolWithTenant(tenantId2, key5, tool68);
530
530
  var getToolLattice = (key5) => toolLatticeManager.getToolLattice(key5);
531
531
  var getToolClientWithTenant = (tenantId2, key5) => toolLatticeManager.getToolClientWithTenant(tenantId2, key5);
532
532
  var getToolDefinition = (key5) => toolLatticeManager.getToolDefinition(key5);
@@ -1363,15 +1363,15 @@ ${body}` : `${frontmatter}
1363
1363
  const resourcesDir = path.join(skillDir, "resources");
1364
1364
  try {
1365
1365
  const entries = await fs.readdir(resourcesDir, { withFileTypes: true, recursive: true });
1366
- const resources3 = [];
1366
+ const resources2 = [];
1367
1367
  for (const entry of entries) {
1368
1368
  if (!entry.isDirectory()) {
1369
1369
  const fullPath = path.join(entry.path, entry.name);
1370
1370
  const relativePath = path.relative(resourcesDir, fullPath);
1371
- resources3.push(relativePath.replace(/\\/g, "/"));
1371
+ resources2.push(relativePath.replace(/\\/g, "/"));
1372
1372
  }
1373
1373
  }
1374
- return resources3.sort();
1374
+ return resources2.sort();
1375
1375
  } catch (error) {
1376
1376
  if (error.code === "ENOENT") {
1377
1377
  return [];
@@ -11661,11 +11661,11 @@ var PluginRegistry = class {
11661
11661
  if (!isRecord2(rawDefinition) || typeof rawDefinition.version !== "string" || rawDefinition.version.trim().length === 0 || typeof rawDefinition.content !== "string") {
11662
11662
  throw new Error(`Plugin "${key5}": skill "${name}" version and content must be a string`);
11663
11663
  }
11664
- const resources3 = rawDefinition.resources;
11665
- if (resources3 !== void 0 && !isRecord2(resources3)) {
11664
+ const resources2 = rawDefinition.resources;
11665
+ if (resources2 !== void 0 && !isRecord2(resources2)) {
11666
11666
  throw new Error(`Plugin "${key5}": skill "${name}" resources must be an object`);
11667
11667
  }
11668
- for (const [path8, resource] of Object.entries(resources3 ?? {})) {
11668
+ for (const [path8, resource] of Object.entries(resources2 ?? {})) {
11669
11669
  try {
11670
11670
  validateRelativePath(path8, "resource");
11671
11671
  } catch {
@@ -12818,7 +12818,7 @@ function isSafeUiPath(path8) {
12818
12818
  }
12819
12819
  function validateSandboxPluginManifest(args) {
12820
12820
  const diagnostics = [];
12821
- const error = (code, message, pluginType, tool71) => diagnostics.push({ level: "error", code, message, pluginType, tool: tool71 });
12821
+ const error = (code, message, pluginType, tool68) => diagnostics.push({ level: "error", code, message, pluginType, tool: tool68 });
12822
12822
  const raw = args.raw;
12823
12823
  if (!isRecord5(raw)) {
12824
12824
  error("MANIFEST_NOT_OBJECT", "manifest must be a JSON object", args.dirName);
@@ -13826,9 +13826,9 @@ function freezeMetadata(metadata) {
13826
13826
  ...resourceSelector ? { resourceSelector } : {}
13827
13827
  });
13828
13828
  }
13829
- function toolName(tool71) {
13830
- if (typeof tool71 !== "object" || tool71 === null || !("name" in tool71)) return void 0;
13831
- return typeof tool71.name === "string" ? tool71.name : void 0;
13829
+ function toolName(tool68) {
13830
+ if (typeof tool68 !== "object" || tool68 === null || !("name" in tool68)) return void 0;
13831
+ return typeof tool68.name === "string" ? tool68.name : void 0;
13832
13832
  }
13833
13833
  function schemaHasConnectionKey(schema6) {
13834
13834
  const definition = isRecord7(schema6._def) ? schema6._def : void 0;
@@ -13836,10 +13836,10 @@ function schemaHasConnectionKey(schema6) {
13836
13836
  const fields = typeof shape === "function" ? shape() : shape;
13837
13837
  return isRecord7(fields) && Object.prototype.hasOwnProperty.call(fields, "connectionKey");
13838
13838
  }
13839
- function hasConnectionKeySchema(tool71) {
13840
- if (!isRecord7(tool71) || !isRecord7(tool71.schema)) return false;
13841
- if (schemaHasConnectionKey(tool71.schema)) return true;
13842
- const definition = isRecord7(tool71.schema._def) ? tool71.schema._def : void 0;
13839
+ function hasConnectionKeySchema(tool68) {
13840
+ if (!isRecord7(tool68) || !isRecord7(tool68.schema)) return false;
13841
+ if (schemaHasConnectionKey(tool68.schema)) return true;
13842
+ const definition = isRecord7(tool68.schema._def) ? tool68.schema._def : void 0;
13843
13843
  if (Array.isArray(definition?.options) && definition.options.length > 0) {
13844
13844
  return definition.options.every(
13845
13845
  (option) => isRecord7(option) && schemaHasConnectionKey(option)
@@ -13894,8 +13894,8 @@ var CapabilityToolRegistry = class {
13894
13894
  * @remarks Standard connection authorization is captured only for tools whose
13895
13895
  * schema declares `connectionKey`; legacy selectors remain explicit metadata.
13896
13896
  */
13897
- register(name, metadata, tool71) {
13898
- this.registerInternal(name, metadata, hasConnectionKeySchema(tool71));
13897
+ register(name, metadata, tool68) {
13898
+ this.registerInternal(name, metadata, hasConnectionKeySchema(tool68));
13899
13899
  }
13900
13900
  /**
13901
13901
  * Registers all tools actually exposed by a middleware instance.
@@ -13906,13 +13906,13 @@ var CapabilityToolRegistry = class {
13906
13906
  * @returns Nothing.
13907
13907
  */
13908
13908
  registerMiddleware(capabilityType, middleware, resourceSelectors = {}) {
13909
- for (const tool71 of middleware.tools ?? []) {
13910
- const name = toolName(tool71);
13909
+ for (const tool68 of middleware.tools ?? []) {
13910
+ const name = toolName(tool68);
13911
13911
  if (name) {
13912
13912
  this.registerInternal(name, {
13913
13913
  capabilityType,
13914
13914
  resourceSelector: resourceSelectors[name]
13915
- }, hasConnectionKeySchema(tool71));
13915
+ }, hasConnectionKeySchema(tool68));
13916
13916
  }
13917
13917
  }
13918
13918
  }
@@ -14604,9 +14604,9 @@ var ReActAgentGraphBuilder = class {
14604
14604
  */
14605
14605
  async build(agentLattice, params) {
14606
14606
  const tools = params.tools.map((t) => {
14607
- const tool71 = getToolClientWithTenant(params.tenantId ?? "default", t.key);
14608
- return tool71;
14609
- }).filter((tool71) => tool71 !== void 0);
14607
+ const tool68 = getToolClientWithTenant(params.tenantId ?? "default", t.key);
14608
+ return tool68;
14609
+ }).filter((tool68) => tool68 !== void 0);
14610
14610
  const stateSchema2 = createReactAgentSchema(params.stateSchema);
14611
14611
  const middlewareConfigs = params.middleware || [];
14612
14612
  const filesystemBackend = createFilesystemBackendFactory(middlewareConfigs);
@@ -15779,8 +15779,8 @@ function validateCapability(value, index) {
15779
15779
  fieldPath: `/capabilities/${index}/allowedTools`
15780
15780
  });
15781
15781
  }
15782
- for (const [toolIndex, tool71] of capability.allowedTools.entries()) {
15783
- if (typeof tool71 !== "string") {
15782
+ for (const [toolIndex, tool68] of capability.allowedTools.entries()) {
15783
+ if (typeof tool68 !== "string") {
15784
15784
  throw new CapabilityBundleValidationError(
15785
15785
  "CAPABILITY_BUNDLE_INVALID_CAPABILITY",
15786
15786
  "allowedTools entries must be strings",
@@ -15794,10 +15794,10 @@ function validateCapability(value, index) {
15794
15794
  fieldPath: `/capabilities/${index}/allowedTools`
15795
15795
  });
15796
15796
  }
15797
- const toolNames = new Set(plugin.meta.tools.map((tool71) => tool71.name));
15798
- for (const [toolIndex, tool71] of capability.allowedTools.entries()) {
15799
- if (typeof tool71 !== "string" || !toolNames.has(tool71)) {
15800
- throw new CapabilityBundleValidationError("CAPABILITY_BUNDLE_UNKNOWN_TOOL", `Unknown tool '${String(tool71)}'`, {
15797
+ const toolNames = new Set(plugin.meta.tools.map((tool68) => tool68.name));
15798
+ for (const [toolIndex, tool68] of capability.allowedTools.entries()) {
15799
+ if (typeof tool68 !== "string" || !toolNames.has(tool68)) {
15800
+ throw new CapabilityBundleValidationError("CAPABILITY_BUNDLE_UNKNOWN_TOOL", `Unknown tool '${String(tool68)}'`, {
15801
15801
  capabilityType,
15802
15802
  fieldPath: `/capabilities/${index}/allowedTools/${toolIndex}`
15803
15803
  });
@@ -16280,7 +16280,7 @@ function applyStaticCeiling(capabilities, staticMiddleware) {
16280
16280
  const projectTools = capability.allowedTools;
16281
16281
  const staticTools = ceiling.allowedTools;
16282
16282
  const effectiveStaticTools = staticTools?.length === 0 ? void 0 : staticTools;
16283
- const allowedTools = projectTools === void 0 ? effectiveStaticTools : effectiveStaticTools === void 0 ? projectTools : projectTools.filter((tool71) => effectiveStaticTools.includes(tool71));
16283
+ const allowedTools = projectTools === void 0 ? effectiveStaticTools : effectiveStaticTools === void 0 ? projectTools : projectTools.filter((tool68) => effectiveStaticTools.includes(tool68));
16284
16284
  runtime[capability.type] = structuredClone({
16285
16285
  ...capability,
16286
16286
  config: applyStaticResourceCeiling(capability, ceiling),
@@ -22040,7 +22040,7 @@ var DeepAgentGraphBuilder = class {
22040
22040
  const tools = params.tools.map((t) => {
22041
22041
  const toolClient = getToolClientWithTenant(params.tenantId ?? "default", t.key);
22042
22042
  return toolClient;
22043
- }).filter((tool71) => tool71 !== void 0);
22043
+ }).filter((tool68) => tool68 !== void 0);
22044
22044
  const subagents = await Promise.all(params.subAgents.map(async (sa) => {
22045
22045
  if (sa.client) {
22046
22046
  return {
@@ -23688,7 +23688,7 @@ var TeamAgentGraphBuilder = class {
23688
23688
  const tools = params.tools.map((t) => {
23689
23689
  const toolClient = getToolClientWithTenant(params.tenantId ?? "default", t.key);
23690
23690
  return toolClient;
23691
- }).filter((tool71) => tool71 !== void 0);
23691
+ }).filter((tool68) => tool68 !== void 0);
23692
23692
  const teammates = params.subAgents.map((sa) => {
23693
23693
  const baseConfig = sa.config;
23694
23694
  return {
@@ -28080,7 +28080,7 @@ function requireSkillDeclaration(skillLoaded) {
28080
28080
  return void 0;
28081
28081
  }
28082
28082
  async function validateAgentReferences(input, tenantId2) {
28083
- const availableTools = getAvailableTools(tenantId2).map((tool71) => tool71.key);
28083
+ const availableTools = getAvailableTools(tenantId2).map((tool68) => tool68.key);
28084
28084
  const availableMiddlewareTypes = getAvailableMiddlewareTypes();
28085
28085
  const availableCustomMiddlewareKeys = CustomMiddlewareRegistry.list().filter(
28086
28086
  (key5) => CustomMiddlewareRegistry.get(key5) !== void 0
@@ -31065,15 +31065,15 @@ var McpLatticeManager = class _McpLatticeManager extends BaseLatticeManager {
31065
31065
  const metaByName = new Map(metaList.map((m) => [m.name, m.meta]));
31066
31066
  this.unregisterServerTools(tenantId2, serverKey);
31067
31067
  const keys = [];
31068
- for (const tool71 of tools) {
31069
- if (rt.selectedTools && !rt.selectedTools.includes(tool71.name)) continue;
31070
- const meta = metaByName.get(tool71.name);
31068
+ for (const tool68 of tools) {
31069
+ if (rt.selectedTools && !rt.selectedTools.includes(tool68.name)) continue;
31070
+ const meta = metaByName.get(tool68.name);
31071
31071
  const rawVisibility = meta?.ui?.visibility;
31072
31072
  const visibility = Array.isArray(rawVisibility) ? rawVisibility : typeof rawVisibility === "string" ? [rawVisibility] : void 0;
31073
31073
  if (visibility && !visibility.includes("model")) continue;
31074
31074
  const ref = extractAppsRef(meta, serverKey);
31075
- const registered = ref ? wrapMcpToolWithUi(tool71, ref) : tool71;
31076
- const toolKey = _McpLatticeManager.buildToolKey(serverKey, tool71.name);
31075
+ const registered = ref ? wrapMcpToolWithUi(tool68, ref) : tool68;
31076
+ const toolKey = _McpLatticeManager.buildToolKey(serverKey, tool68.name);
31077
31077
  try {
31078
31078
  toolLatticeManager.registerExistingToolWithTenant(tenantId2, toolKey, registered);
31079
31079
  keys.push(toolKey);
@@ -38862,10 +38862,10 @@ var createLoadSkillContentTool = (pluginSkills, pluginSkillOwnersOrStaticSelecti
38862
38862
  lockIdentity
38863
38863
  );
38864
38864
  let result2 = pluginSkill.definition.content;
38865
- const resources3 = Object.entries(pluginSkill.definition.resources ?? {});
38866
- if (resources3.length > 0) {
38865
+ const resources2 = Object.entries(pluginSkill.definition.resources ?? {});
38866
+ if (resources2.length > 0) {
38867
38867
  result2 += "\n\n---\n\n**Resources** (synced to the sandbox; use `read_file` to access):\n";
38868
- for (const [resourcePath, resource] of resources3) {
38868
+ for (const [resourcePath, resource] of resources2) {
38869
38869
  result2 += `- ${resourcePath} (mime type: ${resource.mimeType ?? "not specified"})
38870
38870
  `;
38871
38871
  }
@@ -38892,10 +38892,10 @@ var createLoadSkillContentTool = (pluginSkills, pluginSkillOwnersOrStaticSelecti
38892
38892
  `/root/.agents/skills/${input.skill_name}/resources`,
38893
38893
  { recursive: false }
38894
38894
  );
38895
- const resources3 = resourcesResult.files.map((f) => f.path.split("/").pop()).filter(Boolean);
38896
- if (resources3.length > 0) {
38895
+ const resources2 = resourcesResult.files.map((f) => f.path.split("/").pop()).filter(Boolean);
38896
+ if (resources2.length > 0) {
38897
38897
  result += "\n\n---\n\n**Resources** (use `read_file` tool to access):\n";
38898
- resources3.forEach((r) => {
38898
+ resources2.forEach((r) => {
38899
38899
  result += `- ${r}
38900
38900
  `;
38901
38901
  });
@@ -39217,1554 +39217,13 @@ var skillPlugin = {
39217
39217
  })
39218
39218
  };
39219
39219
 
39220
- // src/middlewares/semanticMetricsMiddleware.ts
39220
+ // src/middlewares/collectionMiddleware.ts
39221
39221
  import { createMiddleware as createMiddleware20 } from "langchain";
39222
39222
 
39223
- // src/tool_lattice/semantic_metrics/metrics_datasource_tool.ts
39223
+ // src/tool_lattice/collection/list_collections.ts
39224
39224
  import z57 from "zod";
39225
39225
  import { tool as tool51 } from "langchain";
39226
39226
 
39227
- // src/tool_lattice/semantic_metrics/types.ts
39228
- function readToolRunConfig(exeConfig) {
39229
- return exeConfig?.configurable?.runConfig;
39230
- }
39231
- function resolveDatasourceId(input, exeConfig) {
39232
- const id = input.datasourceId ?? readToolRunConfig(exeConfig)?.metricsDataSource?.datasourceId;
39233
- if (id === void 0 || id === null || id === "") {
39234
- throw new Error("datasourceId is required (provide it or set runConfig.metricsDataSource.datasourceId)");
39235
- }
39236
- return Number(id);
39237
- }
39238
- function assertDatasourceSelected(scope, datasourceId) {
39239
- if (scope.unrestricted) return;
39240
- if (!scope.ids.includes(datasourceId)) {
39241
- throw new Error(
39242
- `DATASOURCE_NOT_SELECTED: datasource ${datasourceId} is not in the effective scope [${scope.ids.join(", ")}]`
39243
- );
39244
- }
39245
- }
39246
- function effectiveDatasourceScope(connectionScope) {
39247
- return connectionScope.length > 0 ? { unrestricted: false, ids: [...connectionScope] } : { unrestricted: true, ids: [] };
39248
- }
39249
- var DDL_DML_KEYWORDS = [
39250
- "insert",
39251
- "update",
39252
- "delete",
39253
- "drop",
39254
- "alter",
39255
- "create",
39256
- "truncate",
39257
- "grant",
39258
- "revoke",
39259
- "merge",
39260
- "replace",
39261
- "upsert"
39262
- ];
39263
- var DDL_DML_RE = new RegExp(`\\b(?:${DDL_DML_KEYWORDS.join("|")})\\b`, "i");
39264
- var SELECT_INTO_RE = /\bselect\b[\s\S]*?\binto\b/i;
39265
- function validateSql(sql) {
39266
- const trimmed = sql.trim();
39267
- if (!trimmed) {
39268
- return { ok: false, reason: "SQL is empty" };
39269
- }
39270
- const withoutComments = trimmed.replace(/--[^\n]*/g, " ").replace(/\/\*[\s\S]*?\*\//g, " ");
39271
- const statements = withoutComments.split(";").map((s) => s.trim()).filter(Boolean);
39272
- if (statements.length > 1) {
39273
- return { ok: false, reason: "Multiple statements are not allowed" };
39274
- }
39275
- const firstKeyword = withoutComments.trim().split(/\s+/)[0].toLowerCase();
39276
- if (firstKeyword !== "select" && firstKeyword !== "with") {
39277
- return { ok: false, reason: `Only SELECT or WITH queries are allowed (got "${firstKeyword}")` };
39278
- }
39279
- if (SELECT_INTO_RE.test(withoutComments)) {
39280
- return { ok: false, reason: "SELECT INTO is not allowed (creates a table)" };
39281
- }
39282
- if (DDL_DML_RE.test(withoutComments)) {
39283
- return { ok: false, reason: "Only read-only queries are allowed (DML/DDL detected)" };
39284
- }
39285
- return { ok: true };
39286
- }
39287
-
39288
- // src/tool_lattice/semantic_metrics/SemanticMetricsV2Client.ts
39289
- 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.";
39290
- async function resolveMetricsClientFromSelector(selector, scope, connectionKey) {
39291
- let resolved;
39292
- try {
39293
- resolved = await resolvePluginConnections(selector.connectionType, selector, scope);
39294
- } catch (error) {
39295
- if (error instanceof Error && error.message === "ConnectionStore not configured") {
39296
- throw new Error(NO_CONNECTION_HINT);
39297
- }
39298
- throw error;
39299
- }
39300
- const available = resolved.map((c) => c.key).join(", ");
39301
- if (resolved.length === 0) {
39302
- throw new Error(NO_CONNECTION_HINT);
39303
- }
39304
- const key5 = connectionKey?.trim() || (resolved.length === 1 ? resolved[0].key : "");
39305
- if (!key5) {
39306
- throw new Error(
39307
- `connectionKey is required. Available connections: ${available}`
39308
- );
39309
- }
39310
- const entry = resolved.find((c) => c.key === key5);
39311
- if (!entry) {
39312
- throw new Error(`Connection "${key5}" not found. Available connections: ${available}`);
39313
- }
39314
- const config = entry.config;
39315
- return new SemanticMetricsV2Client(config);
39316
- }
39317
- var SemanticMetricsV2Client = class {
39318
- /**
39319
- * @param config - Connection configuration (server URL, optional API key and headers).
39320
- */
39321
- constructor(config) {
39322
- this.config = config;
39323
- this.baseUrl = config.serverUrl.replace(/\/$/, "");
39324
- }
39325
- /**
39326
- * Build default request headers: `Accept: application/json`, custom headers,
39327
- * and a Bearer `Authorization` header when an API key is configured.
39328
- *
39329
- * @returns Merged headers.
39330
- */
39331
- getHeaders() {
39332
- const headers = {
39333
- Accept: "application/json",
39334
- ...this.config.headers ?? {}
39335
- };
39336
- if (this.config.apiKey) {
39337
- headers["Authorization"] = `Bearer ${this.config.apiKey}`;
39338
- }
39339
- return headers;
39340
- }
39341
- /**
39342
- * Numeric selected resource ids of this connection (normalized).
39343
- *
39344
- * Reads `selectedEntities` — the standard connection resource-selection
39345
- * field written by the connection UI (`connection.discover` + selection).
39346
- *
39347
- * @returns The selected resource ids; empty when unrestricted.
39348
- */
39349
- getSelectedEntities() {
39350
- const raw = this.config.selectedEntities;
39351
- if (!Array.isArray(raw)) return [];
39352
- return raw.map((v) => Number(v)).filter((n) => Number.isFinite(n));
39353
- }
39354
- /**
39355
- * Perform a JSON request against the base URL.
39356
- *
39357
- * The Metrics Server wraps every response as `{ code, message, data }`. A
39358
- * `code` of 200 resolves to `data`; any other `code` throws a business error
39359
- * carrying the server message (regardless of HTTP status). Non-envelope
39360
- * bodies are returned as-is.
39361
- *
39362
- * @param path - Path appended to the base URL (must start with `/`).
39363
- * @param init - Optional `fetch` init overrides (method, body, per-call headers).
39364
- * @returns The unwrapped `data` payload of the response envelope.
39365
- * @throws When the server returns a non-200 `code`, or the HTTP response is not OK.
39366
- */
39367
- async request(path8, init = {}) {
39368
- const response = await fetch(`${this.baseUrl}${path8}`, {
39369
- ...init,
39370
- method: init.method ?? "GET",
39371
- headers: { ...this.getHeaders(), ...init.headers ?? {} }
39372
- });
39373
- const text = await response.text().catch(() => "");
39374
- const parsed = this.parseBody(text);
39375
- if (parsed?.envelope === true) {
39376
- if (parsed.code !== 200) {
39377
- throw new Error(`API ${parsed.code}: ${parsed.message || "Unknown error"}`);
39378
- }
39379
- return parsed.data;
39380
- }
39381
- if (!response.ok) {
39382
- throw new Error(`HTTP ${response.status}: ${text || response.statusText}`);
39383
- }
39384
- return parsed?.value ?? void 0;
39385
- }
39386
- /**
39387
- * Parse a response body text. Detects the server envelope `{ code, message, data }`.
39388
- *
39389
- * @param text - Raw response body text.
39390
- * @returns `{ envelope: true, code, message, data }` for an envelope body,
39391
- * `{ envelope: false, value }` for anything else (or `{ envelope: false }` when empty/invalid).
39392
- */
39393
- parseBody(text) {
39394
- if (!text.trim()) return { envelope: false };
39395
- try {
39396
- const value = JSON.parse(text);
39397
- if (value !== null && typeof value === "object" && !Array.isArray(value)) {
39398
- const record = value;
39399
- if (typeof record.code === "number") {
39400
- return {
39401
- envelope: true,
39402
- code: record.code,
39403
- message: typeof record.message === "string" ? record.message : void 0,
39404
- data: record.data
39405
- };
39406
- }
39407
- }
39408
- return { envelope: false, value };
39409
- } catch {
39410
- return { envelope: false, value: text };
39411
- }
39412
- }
39413
- /**
39414
- * POST a JSON body to a path.
39415
- *
39416
- * @param path - Path appended to the base URL.
39417
- * @param body - Payload serialized as JSON.
39418
- * @returns Parsed JSON response body.
39419
- */
39420
- post(path8, body) {
39421
- return this.request(path8, {
39422
- method: "POST",
39423
- headers: { "Content-Type": "application/json" },
39424
- body: JSON.stringify(body)
39425
- });
39426
- }
39427
- /**
39428
- * PUT a JSON body to a path.
39429
- *
39430
- * @param path - Path appended to the base URL.
39431
- * @param body - Payload serialized as JSON.
39432
- * @returns Parsed JSON response body.
39433
- */
39434
- put(path8, body) {
39435
- return this.request(path8, {
39436
- method: "PUT",
39437
- headers: { "Content-Type": "application/json" },
39438
- body: JSON.stringify(body)
39439
- });
39440
- }
39441
- /**
39442
- * List all datasources.
39443
- *
39444
- * @returns Parsed JSON response body.
39445
- */
39446
- listDatasources() {
39447
- return this.request("/datasources");
39448
- }
39449
- /**
39450
- * Get table grants for a datasource.
39451
- *
39452
- * @param datasourceId - Datasource identifier.
39453
- * @returns Parsed JSON response body.
39454
- */
39455
- getTableGrants(datasourceId) {
39456
- return this.request(`/datasources/${encodeURIComponent(datasourceId)}/table-grants`);
39457
- }
39458
- /**
39459
- * Run a read-only SQL query against a datasource.
39460
- *
39461
- * @param datasourceId - Datasource identifier.
39462
- * @param input - Query input: `sql` (SELECT/WITH only), optional `params`, `maxRows`, `debug`.
39463
- * @returns Parsed JSON response body.
39464
- * @throws When `sql` fails read-only validation (rejected before any fetch).
39465
- */
39466
- async queryDatasource(datasourceId, input) {
39467
- const validation = validateSql(input.sql);
39468
- if (!validation.ok) throw new Error(`SQL_NOT_ALLOWED: ${validation.reason}`);
39469
- return this.post(`/datasources/${encodeURIComponent(datasourceId)}/query`, input);
39470
- }
39471
- /**
39472
- * Test a datasource connection.
39473
- *
39474
- * @param datasourceId - Datasource identifier.
39475
- * @returns Parsed JSON response body.
39476
- */
39477
- testDatasource(datasourceId) {
39478
- return this.post(`/datasources/${encodeURIComponent(datasourceId)}/test`, {});
39479
- }
39480
- /**
39481
- * Get connection-pool status for a datasource.
39482
- *
39483
- * @param datasourceId - Datasource identifier.
39484
- * @returns Parsed JSON response body.
39485
- */
39486
- getPoolStatus(datasourceId) {
39487
- return this.request(`/datasources/${encodeURIComponent(datasourceId)}/pool`);
39488
- }
39489
- /**
39490
- * List table metadata for a datasource, auto-paginating.
39491
- *
39492
- * The server pages this collection (`page`/`pageSize`, default page size 20),
39493
- * so requests aggregate every page into one `{ items, total }` result.
39494
- *
39495
- * @param datasourceId - Datasource identifier.
39496
- * @returns `{ items: [...], total }` covering all pages.
39497
- */
39498
- async listTables(datasourceId) {
39499
- return this.listMetaPage(`/datasources/${encodeURIComponent(datasourceId)}/meta/tables`);
39500
- }
39501
- /**
39502
- * Shared pagination walk for the paged meta collections (`{items,total,page,pageSize}`).
39503
- *
39504
- * @param basePath - Collection path (tables or metrics).
39505
- * @returns `{ items, total }` aggregated across all pages.
39506
- */
39507
- async listMetaPage(basePath) {
39508
- const pageSize = 100;
39509
- const items = [];
39510
- let total = Number.POSITIVE_INFINITY;
39511
- for (let page = 1; items.length < total; page += 1) {
39512
- const body = await this.request(`${basePath}?page=${page}&pageSize=${pageSize}`);
39513
- const record = body !== null && typeof body === "object" ? body : {};
39514
- const batch = Array.isArray(record.items) ? record.items : [];
39515
- items.push(...batch);
39516
- total = typeof record.total === "number" ? record.total : items.length;
39517
- if (batch.length === 0) break;
39518
- }
39519
- return { items, total: items.length };
39520
- }
39521
- /**
39522
- * Get metadata for a single table.
39523
- *
39524
- * @param datasourceId - Datasource identifier.
39525
- * @param tableKey - Table key.
39526
- * @returns Parsed JSON response body.
39527
- */
39528
- getTable(datasourceId, tableKey) {
39529
- return this.request(
39530
- `/datasources/${encodeURIComponent(datasourceId)}/meta/tables/${encodeURIComponent(tableKey)}`
39531
- );
39532
- }
39533
- /**
39534
- * Create a table definition for a datasource.
39535
- *
39536
- * @param datasourceId - Datasource identifier.
39537
- * @param payload - Table definition payload.
39538
- * @returns Parsed JSON response body.
39539
- */
39540
- createTable(datasourceId, payload) {
39541
- return this.post(`/datasources/${encodeURIComponent(datasourceId)}/meta/tables`, payload);
39542
- }
39543
- /**
39544
- * Update a table definition for a datasource.
39545
- *
39546
- * @param datasourceId - Datasource identifier.
39547
- * @param tableKey - Table key.
39548
- * @param payload - Table definition payload.
39549
- * @returns Parsed JSON response body.
39550
- */
39551
- /**
39552
- * Update a published table meta via read-modify-write.
39553
- *
39554
- * The server's PUT replaces the whole payload, so the current payload is
39555
- * fetched first and the incoming fields are merged on top; fields not
39556
- * mentioned are preserved.
39557
- */
39558
- async updateTable(datasourceId, tableKey, payload) {
39559
- const existing = await this.readMetaPayload(`${this.baseUrl}/datasources/${encodeURIComponent(datasourceId)}/meta/tables/${encodeURIComponent(tableKey)}`);
39560
- return this.put(
39561
- `/datasources/${encodeURIComponent(datasourceId)}/meta/tables/${encodeURIComponent(tableKey)}`,
39562
- { payload: { ...existing, ...payload } }
39563
- );
39564
- }
39565
- /**
39566
- * List metric definitions for a datasource.
39567
- *
39568
- * @param datasourceId - Datasource identifier.
39569
- * @returns Parsed JSON response body.
39570
- */
39571
- /**
39572
- * List metric metadata for a datasource, auto-paginating.
39573
- *
39574
- * The server pages this collection (`page`/`pageSize`, default page size 20),
39575
- * so requests aggregate every page into one `{ items, total }` result.
39576
- *
39577
- * @param datasourceId - Datasource identifier.
39578
- * @returns `{ items: [...], total }` covering all pages.
39579
- */
39580
- async listMetrics(datasourceId) {
39581
- return this.listMetaPage(`/datasources/${encodeURIComponent(datasourceId)}/meta/metrics`);
39582
- }
39583
- /**
39584
- * Get a single metric definition.
39585
- *
39586
- * @param datasourceId - Datasource identifier.
39587
- * @param metricKey - Metric key.
39588
- * @returns Parsed JSON response body.
39589
- */
39590
- getMetric(datasourceId, metricKey) {
39591
- return this.request(
39592
- `/datasources/${encodeURIComponent(datasourceId)}/meta/metrics/${encodeURIComponent(metricKey)}`
39593
- );
39594
- }
39595
- /**
39596
- * Create a metric definition for a datasource.
39597
- *
39598
- * @param datasourceId - Datasource identifier.
39599
- * @param payload - Metric definition payload.
39600
- * @returns Parsed JSON response body.
39601
- */
39602
- createMetric(datasourceId, payload) {
39603
- return this.post(`/datasources/${encodeURIComponent(datasourceId)}/meta/metrics`, payload);
39604
- }
39605
- /**
39606
- * Update a metric definition for a datasource.
39607
- *
39608
- * @param datasourceId - Datasource identifier.
39609
- * @param metricKey - Metric key.
39610
- * @param payload - Metric definition payload.
39611
- * @returns Parsed JSON response body.
39612
- */
39613
- /**
39614
- * Update a published metric meta via read-modify-write.
39615
- *
39616
- * The server's PUT replaces the whole payload, so the current payload is
39617
- * fetched first and the incoming fields are merged on top; fields not
39618
- * mentioned are preserved.
39619
- */
39620
- async updateMetric(datasourceId, metricKey, payload) {
39621
- const existing = await this.readMetaPayload(`${this.baseUrl}/datasources/${encodeURIComponent(datasourceId)}/meta/metrics/${encodeURIComponent(metricKey)}`);
39622
- return this.put(
39623
- `/datasources/${encodeURIComponent(datasourceId)}/meta/metrics/${encodeURIComponent(metricKey)}`,
39624
- { payload: { ...existing, ...payload } }
39625
- );
39626
- }
39627
- /**
39628
- * Fetch the current `payload` object of a published meta entry.
39629
- *
39630
- * The single-entry read returns `{ code, data: [entry] }` (already unwrapped
39631
- * to the array by {@link request}); the payload lives on the first entry.
39632
- *
39633
- * @param absoluteUrl - Full URL of the single-entry meta read.
39634
- * @returns The stored payload object (empty when none exists).
39635
- */
39636
- async readMetaPayload(absoluteUrl) {
39637
- const response = await fetch(absoluteUrl, { headers: this.getHeaders() });
39638
- const text = await response.text().catch(() => "");
39639
- if (!response.ok) {
39640
- throw new Error(`HTTP ${response.status}: ${text || response.statusText}`);
39641
- }
39642
- const parsed = this.parseBody(text);
39643
- const data = parsed?.envelope === true ? parsed.data : parsed?.value;
39644
- const entry = Array.isArray(data) ? data[0] : data;
39645
- const payload = entry?.payload;
39646
- return payload !== null && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
39647
- }
39648
- /**
39649
- * Get runtime metadata for a datasource.
39650
- *
39651
- * @param datasourceId - Datasource identifier.
39652
- * @returns Parsed JSON response body.
39653
- */
39654
- getRuntimeMeta(datasourceId) {
39655
- return this.request(`/datasources/${encodeURIComponent(datasourceId)}/meta`);
39656
- }
39657
- /**
39658
- * Run a metrics query.
39659
- *
39660
- * @param request - Metrics query request payload.
39661
- * @returns Parsed JSON response body.
39662
- */
39663
- queryMetrics(request) {
39664
- return this.post("/metrics/query", request);
39665
- }
39666
- /**
39667
- * Run an ad-hoc custom SQL query, validated as read-only before sending.
39668
- *
39669
- * @param request - Request with `datasourceId`, `customSql` (SELECT/WITH only),
39670
- * and optional `limit` / `debug`.
39671
- * @returns Parsed JSON response body.
39672
- * @throws When `customSql` fails read-only validation (rejected before any fetch).
39673
- */
39674
- async customSql(request) {
39675
- const validation = validateSql(request.customSql);
39676
- if (!validation.ok) throw new Error(`SQL_NOT_ALLOWED: ${validation.reason}`);
39677
- return this.post("/metrics/query", request);
39678
- }
39679
- };
39680
-
39681
- // src/tool_lattice/semantic_metrics/metrics_datasource_tool.ts
39682
- var DESCRIPTION = `PHYSICAL LAYER EXPLORATION \u2014 the only tool for probing raw datasource structure (Builder/Admin only; business agents do not need it).
39683
-
39684
- 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.
39685
-
39686
- DOES NOT OWN:
39687
- - Published semantic assets (table meta / metric meta) \u2192 use metrics_meta_tool.
39688
- - Runtime meta and business metric queries \u2192 use metrics_runtime_tool.
39689
-
39690
- 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.
39691
-
39692
- COMMON MISTAKES (do not):
39693
- - 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).
39694
- - Do not read or publish semantic meta through this tool \u2014 metrics_meta_tool owns the semantic layer.
39695
- - Do not probe tables outside the tenant's table-grants; un-granted probes are rejected and break the exploration boundary.
39696
- - Do not attempt writes \u2014 SQL is validated read-only and rejected before sending.`;
39697
- function createMetricsDatasourceTool(params) {
39698
- const { connectionType, connections, connectAll } = params;
39699
- return tool51(
39700
- async (input, exeConfig) => {
39701
- try {
39702
- const client = await resolveMetricsClientFromSelector(
39703
- { connectionType, connections, connectAll },
39704
- readToolRunConfig(exeConfig) ?? {},
39705
- input.connectionKey
39706
- );
39707
- const scope = effectiveDatasourceScope(client.getSelectedEntities());
39708
- switch (input.action) {
39709
- case "list_datasources": {
39710
- const result = await client.listDatasources();
39711
- const filtered = scope.unrestricted ? result : result.filter((d) => scope.ids.includes(Number(d.id)));
39712
- const safe = filtered.map((d) => ({
39713
- id: d.id,
39714
- name: d.name,
39715
- sourceType: d.sourceType,
39716
- description: d.description,
39717
- statusLabel: d.statusLabel
39718
- }));
39719
- return JSON.stringify(safe, null, 2);
39720
- }
39721
- case "get_grants": {
39722
- const ds = resolveDatasourceId(input, exeConfig);
39723
- assertDatasourceSelected(scope, ds);
39724
- const result = await client.getTableGrants(ds);
39725
- return JSON.stringify(result, null, 2);
39726
- }
39727
- case "query_sql": {
39728
- const ds = resolveDatasourceId(input, exeConfig);
39729
- assertDatasourceSelected(scope, ds);
39730
- if (!input.sql) throw new Error("sql is required for the 'query_sql' action");
39731
- const result = await client.queryDatasource(ds, {
39732
- sql: input.sql,
39733
- params: input.params,
39734
- maxRows: input.maxRows
39735
- });
39736
- return JSON.stringify(result, null, 2);
39737
- }
39738
- case "test_connection": {
39739
- const ds = resolveDatasourceId(input, exeConfig);
39740
- assertDatasourceSelected(scope, ds);
39741
- const result = await client.testDatasource(ds);
39742
- return JSON.stringify(result, null, 2);
39743
- }
39744
- case "pool_status": {
39745
- const ds = resolveDatasourceId(input, exeConfig);
39746
- assertDatasourceSelected(scope, ds);
39747
- const result = await client.getPoolStatus(ds);
39748
- return JSON.stringify(result, null, 2);
39749
- }
39750
- }
39751
- } catch (error) {
39752
- return `Error: ${error instanceof Error ? error.message : String(error)}`;
39753
- }
39754
- },
39755
- {
39756
- name: "metrics_datasource_tool",
39757
- description: DESCRIPTION,
39758
- schema: z57.object({
39759
- action: z57.enum(["list_datasources", "get_grants", "query_sql", "test_connection", "pool_status"]).describe(
39760
- "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"
39761
- ),
39762
- connectionKey: z57.string().optional().describe("Connection key. Omit when only one semantic-metrics connection exists"),
39763
- datasourceId: z57.coerce.number().optional().describe("Numeric datasource id, e.g. 15 (required for all actions except list_datasources; optional if set in runConfig.metricsDataSource)"),
39764
- sql: z57.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"),
39765
- params: z57.record(z57.union([z57.string(), z57.number(), z57.boolean()])).optional().describe("Named :param values for the SQL"),
39766
- maxRows: z57.number().optional().describe("Max rows to return")
39767
- })
39768
- }
39769
- );
39770
- }
39771
-
39772
- // src/tool_lattice/semantic_metrics/metrics_meta_tool.ts
39773
- import z58 from "zod";
39774
- import { tool as tool52 } from "langchain";
39775
- 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).
39776
-
39777
- 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).
39778
-
39779
- DOES NOT OWN:
39780
- - Running queries or reading the aggregated runtime view \u2192 metrics_runtime_tool (get_meta / query / custom_sql).
39781
- - Probing physical tables, columns, grants, or samples \u2192 metrics_datasource_tool.
39782
-
39783
- 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.
39784
-
39785
- COMMON MISTAKES (do not):
39786
- - Do not call get_meta here \u2014 that action belongs to metrics_runtime_tool, not this tool.
39787
- - Do not try to "query numbers" through this tool \u2014 list/read actions return definitions only; use metrics_runtime_tool query for data.
39788
- - 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.
39789
- - The builder assistant must load the semantic-metrics-modeling skill and pass modelingSkillLoaded: true on write actions; no removal actions are exposed on purpose.`;
39790
- var MODELING_SKILL_NAME = "semantic-metrics-modeling";
39791
- var BUILDER_ASSISTANT_ID = "semantic-metrics-builder";
39792
- function requireModelingSkillLoaded(action, input, exeConfig) {
39793
- const isWriteAction = action === "create_table" || action === "update_table" || action === "create_metric" || action === "update_metric";
39794
- if (!isWriteAction) return void 0;
39795
- const runConfig = readToolRunConfig(exeConfig);
39796
- const assistantId = runConfig?.assistant_id;
39797
- if (assistantId === BUILDER_ASSISTANT_ID && input.modelingSkillLoaded !== true) {
39798
- return JSON.stringify({
39799
- success: false,
39800
- error: `Load the '${MODELING_SKILL_NAME}' skill before publishing meta.`
39801
- });
39802
- }
39803
- return void 0;
39804
- }
39805
- function actionRequiresPayload(action) {
39806
- return action === "create_table" || action === "update_table" || action === "create_metric" || action === "update_metric";
39807
- }
39808
- function createMetricsMetaTool(params) {
39809
- const { connectionType, connections, connectAll } = params;
39810
- return tool52(
39811
- async (input, exeConfig) => {
39812
- try {
39813
- const guardError = requireModelingSkillLoaded(input.action, input, exeConfig);
39814
- if (guardError !== void 0) return guardError;
39815
- const client = await resolveMetricsClientFromSelector(
39816
- { connectionType, connections, connectAll },
39817
- readToolRunConfig(exeConfig) ?? {},
39818
- input.connectionKey
39819
- );
39820
- const ds = resolveDatasourceId(input, exeConfig);
39821
- assertDatasourceSelected(effectiveDatasourceScope(client.getSelectedEntities()), ds);
39822
- if (actionRequiresPayload(input.action) && input.payload === void 0) {
39823
- throw new Error(`payload is required for ${input.action}`);
39824
- }
39825
- const payload = input.payload ?? {};
39826
- switch (input.action) {
39827
- case "list_tables": {
39828
- return JSON.stringify(await client.listTables(ds), null, 2);
39829
- }
39830
- case "read_table_meta": {
39831
- if (!input.objectKey) throw new Error("objectKey is required for read_table_meta");
39832
- return JSON.stringify(await client.getTable(ds, input.objectKey), null, 2);
39833
- }
39834
- case "create_table": {
39835
- return JSON.stringify(await client.createTable(ds, payload), null, 2);
39836
- }
39837
- case "update_table": {
39838
- if (!input.objectKey) throw new Error("objectKey is required for update_table");
39839
- return JSON.stringify(await client.updateTable(ds, input.objectKey, payload), null, 2);
39840
- }
39841
- case "list_metrics": {
39842
- return JSON.stringify(await client.listMetrics(ds), null, 2);
39843
- }
39844
- case "read_metric_meta": {
39845
- if (!input.objectKey) throw new Error("objectKey is required for read_metric_meta");
39846
- return JSON.stringify(await client.getMetric(ds, input.objectKey), null, 2);
39847
- }
39848
- case "create_metric": {
39849
- return JSON.stringify(await client.createMetric(ds, payload), null, 2);
39850
- }
39851
- case "update_metric": {
39852
- if (!input.objectKey) throw new Error("objectKey is required for update_metric");
39853
- return JSON.stringify(await client.updateMetric(ds, input.objectKey, payload), null, 2);
39854
- }
39855
- }
39856
- } catch (error) {
39857
- return `Error: ${error instanceof Error ? error.message : String(error)}`;
39858
- }
39859
- },
39860
- {
39861
- name: "metrics_meta_tool",
39862
- description: DESCRIPTION2,
39863
- schema: z58.object({
39864
- action: z58.enum([
39865
- "list_tables",
39866
- "read_table_meta",
39867
- "create_table",
39868
- "update_table",
39869
- "list_metrics",
39870
- "read_metric_meta",
39871
- "create_metric",
39872
- "update_metric"
39873
- ]).describe(
39874
- "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)"
39875
- ),
39876
- connectionKey: z58.string().optional().describe("Connection key. Omit when only one semantic-metrics connection exists"),
39877
- datasourceId: z58.coerce.number().optional().describe("Numeric datasource id, e.g. 15 (optional if set in runConfig.metricsDataSource)"),
39878
- objectKey: z58.string().optional().describe("Semantic table/metric key (required for read_table_meta/update_table/read_metric_meta/update_metric)"),
39879
- payload: z58.record(z58.unknown()).optional().describe("Meta payload (required for create/update actions; objectType/objectKey/status/payload/accessGrant)"),
39880
- modelingSkillLoaded: z58.literal(true).optional().describe("Set true after loading the semantic-metrics-modeling skill (required for the builder assistant on write actions)")
39881
- })
39882
- }
39883
- );
39884
- }
39885
-
39886
- // src/tool_lattice/semantic_metrics/metrics_runtime_tool.ts
39887
- import z59 from "zod";
39888
- import { tool as tool53 } from "langchain";
39889
- 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.
39890
-
39891
- 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).
39892
-
39893
- DOES NOT OWN:
39894
- - 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).
39895
- - Physical exploration of raw tables, grants, or samples \u2192 metrics_datasource_tool (query_sql).
39896
- - Free-form custom SQL \u2014 intentionally not provided; use query against published metrics.
39897
-
39898
- 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).
39899
-
39900
- COMMON MISTAKES (do not):
39901
- - 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.
39902
- - 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.
39903
- - Metrics and dimensions in query_metrics must already be published; querying an unpublished metric fails with "not found in catalog".`;
39904
- function createMetricsRuntimeTool(params) {
39905
- const { connectionType, connections, connectAll } = params;
39906
- return tool53(
39907
- async (input, exeConfig) => {
39908
- try {
39909
- const client = await resolveMetricsClientFromSelector(
39910
- { connectionType, connections, connectAll },
39911
- readToolRunConfig(exeConfig) ?? {},
39912
- input.connectionKey
39913
- );
39914
- const scope = effectiveDatasourceScope(client.getSelectedEntities());
39915
- switch (input.action) {
39916
- case "list_datasources": {
39917
- const result = await client.listDatasources();
39918
- const filtered = scope.unrestricted ? result : result.filter((d) => scope.ids.includes(Number(d.id)));
39919
- const safe = filtered.map((d) => ({
39920
- id: d.id,
39921
- name: d.name,
39922
- sourceType: d.sourceType,
39923
- description: d.description,
39924
- statusLabel: d.statusLabel
39925
- }));
39926
- return JSON.stringify(safe, null, 2);
39927
- }
39928
- case "read_semantic_catalog": {
39929
- const ds = resolveDatasourceId(input, exeConfig);
39930
- assertDatasourceSelected(scope, ds);
39931
- return JSON.stringify(await client.getRuntimeMeta(ds), null, 2);
39932
- }
39933
- case "query_metrics": {
39934
- if (!input.query) throw new Error("query is required for the 'query_metrics' action");
39935
- const bodyDatasourceId = input.query.datasourceId;
39936
- if (bodyDatasourceId !== void 0) {
39937
- assertDatasourceSelected(scope, Number(bodyDatasourceId));
39938
- }
39939
- return JSON.stringify(await client.queryMetrics(input.query), null, 2);
39940
- }
39941
- }
39942
- } catch (error) {
39943
- return `Error: ${error instanceof Error ? error.message : String(error)}`;
39944
- }
39945
- },
39946
- {
39947
- name: "metrics_runtime_tool",
39948
- description: DESCRIPTION3,
39949
- schema: z59.object({
39950
- action: z59.enum(["list_datasources", "read_semantic_catalog", "query_metrics"]).describe(
39951
- "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"
39952
- ),
39953
- connectionKey: z59.string().optional().describe("Connection key. Omit when only one semantic-metrics connection exists"),
39954
- datasourceId: z59.coerce.number().optional().describe("Numeric datasource id, e.g. 15 (required for read_semantic_catalog; optional if set in runConfig.metricsDataSource)"),
39955
- query: z59.record(z59.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 }')
39956
- })
39957
- }
39958
- );
39959
- }
39960
-
39961
- // src/middlewares/semanticMetricsModelingSkill.ts
39962
- var CONTENT = `---
39963
- name: semantic-metrics-modeling
39964
- 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.
39965
- ---
39966
-
39967
- # Semantic Metrics Modeling
39968
-
39969
- You are the Semantic Metrics Builder. You turn physical datasource tables into reusable
39970
- **semantic tables** and **business metrics** on a Metrics Server (\`/api/v1\`). Work is
39971
- governed, observable, and continuously refined \u2014 never a one-shot guess.
39972
-
39973
- You always operate in exactly ONE of two roles:
39974
-
39975
- - **Orchestrator** (default; no \`## Bound Task\` section in your context): you face the
39976
- user. You agree the Goal Model, propose the model, plan persistent tasks, dispatch
39977
- execution to workers, reconcile belief, and own every user interaction.
39978
- - **Worker** (your context contains a \`## Bound Task\` section naming you executor of one
39979
- task): you execute that task's brief only. See **Worker mode** \u2014 its rules override the
39980
- orchestrator policy.
39981
-
39982
- ## Goal Model
39983
-
39984
- Before any exploration or publishing, agree with the user on:
39985
- - **Real goal**: the business outcome (which metrics, for what decision), not just "make a table".
39986
- - **Consumer**: who reads the result and how.
39987
- - **Usable state**: observable conditions that make the published meta useful.
39988
- - **Scope**: which datasource/tables, and what is explicitly out of scope.
39989
- - **Acceptance evidence**: objective criteria (e.g. "metric \`sell_in_nes\` returns sane monthly
39990
- totals for 2024") used to decide success. Verbatim acceptance evidence is required later by
39991
- the Verify dispatch \u2014 record it exactly.
39992
- Do not guess material goals, consumers, or acceptance evidence.
39993
-
39994
- **Vague requests** (e.g. "build the metric layer") \u2014 do not act and do not ask blind questions.
39995
- First run cheap read-only observations (\`list_datasources\`, \`get_grants\`, \`list_metrics\`) to
39996
- see what is authorized and already published, then ask focused questions that carry that
39997
- context and offer concrete options (which datasource/tables, which business questions, extend
39998
- existing metrics or build new). Every clarification question must include enough context and
39999
- options for the user to answer in one step. Only after the user picks a direction does the
40000
- Goal Model become confirmable \u2014 record it, create the task, and proceed to the workflow.
40001
-
40002
- ## Target model and quality bar
40003
-
40004
- Your goal is a specific, verifiable artifact, not "some tables and metrics".
40005
-
40006
- **Target shape** \u2014 one delivery is:
40007
- - a published \`table_view_detail\` meta per logical table, with every column tagged
40008
- \`role\` (dimension | measure) and a business-readable \`label\`;
40009
- - a \`metric_index\` + \`metric_detail\` pair per metric, using the SQL-free \`calculation\` DSL;
40010
- - the set, taken together, answers the user's concrete business question.
40011
-
40012
- **Publish gate (self-check every metric before create)** \u2014 if any fails, do **not** publish; go
40013
- explore or ask the user:
40014
- 1. measure: an aggregation is chosen **and** its business meaning is confirmed (net/gross, currency, dedupe or not);
40015
- 2. dimension: has a business meaning and a grain (day/month/year/\u2026);
40016
- 3. \`displayName\`/\`label\` are business-readable;
40017
- 4. the metric answers one concrete question from the user's stated goal;
40018
- 5. a runtime \`query\` returns numbers consistent with the confirmed meaning.
40019
-
40020
- **Intent gaps first** \u2014 before diving into exploration, list the inputs you still need to meet the
40021
- quality bar (business meaning, grain, target metric list, table scope, consumer) and ask for them
40022
- explicitly. Exploration and user questions are both driven by this target shape and quality bar:
40023
- missing business meaning \u2192 ask; unclear field semantics \u2192 probe or ask; right shape but it does not
40024
- answer the business question \u2192 do not publish.
40025
-
40026
- ## FEP Loop
40027
-
40028
- Apply this loop to every step (explore, publish table, publish metric, verify):
40029
- **OBSERVE \u2192 HYPOTHESIZE \u2192 ACT \u2192 VERIFY \u2192 DECIDE \u2192 RECONCILE**
40030
-
40031
- - **Observe**: current state, grants, published meta, and decision-relevant uncertainty.
40032
- - **Hypothesize**: what evidence should appear if your model is right, and how each outcome changes the decision.
40033
- - **Act**: one proportional action \u2014 no more than necessary.
40034
- - **Verify**: compare the observed result (e.g. a runtime \`query\`) against the prediction.
40035
- - **Decide**: classify as **RETAIN** (confirmed), **REVERT** (rejected), or **INCONCLUSIVE**.
40036
- - **Reconcile**: update the belief state and plan, then repeat while decision-relevant action remains.
40037
-
40038
- The orchestrator applies the loop **between dispatches** (each observation updates the plan
40039
- before the next brief is written). A worker applies it **inside its brief**.
40040
-
40041
- Renew user approval when a foundational assumption or the goal changes.
40042
-
40043
- ## Orchestrator: Task Policy
40044
-
40045
- You are an orchestrator, not the hands. Exactly five duties:
40046
-
40047
- 1. **Goal Model agreement** \u2014 including cheap read-only observation for vague requests
40048
- (\`list_datasources\`, \`get_grants\`, \`list_metrics\`). This is your ONLY inline datasource
40049
- access; do not use \`write_todos\`.
40050
- 2. **Propose the model** and get user approval.
40051
- 3. **Task tree** \u2014 parent task = contract + \`## Belief State\`; child tasks = independently
40052
- verifiable outcomes (explore / publish-table / publish-metric / verify), one per dispatch.
40053
- See the \`task-definition\` skill for \`manage_task\` operation details.
40054
- 4. **Dispatch and collect** \u2014 \`task { taskId, agentId: "general-purpose" }\`; read the
40055
- observation; record the \`executionResultId\` on the child task with \`manage_task update\` or
40056
- \`add_activity\`; reconcile \`## Belief State\`.
40057
- 5. **HITL** \u2014 every \`ask_user_to_clarify\` is yours. Workers never ask the user.
40058
-
40059
- Hard rules:
40060
- - Never run exploration SQL inline. Never build or publish payloads inline (sole exception:
40061
- the Publish/Verify inline fallback below).
40062
- - **Belief State: you are the sole writer.** Workers return findings in their results; you
40063
- update \`## Belief State\` via \`manage_task update\` on the parent task. Workers never touch it.
40064
- - **Dispatch serially** \u2014 one worker at a time; reconcile belief before writing the next brief.
40065
- - **Distinguish dispatch failure from worker outcome**: a dispatch failure is a tool-level
40066
- error where the worker never ran. A worker returning INCONCLUSIVE or failed is a normal FEP
40067
- input \u2014 reconcile it, never treat it as a dispatch failure.
40068
-
40069
- Dispatch failure handling (worker never ran, tool error):
40070
- 1. Retry the dispatch once (recreate the child task if the store reports it unusable).
40071
- 2. **Explore: never execute inline.** If the retry fails, stop and ask the user via
40072
- \`ask_user_to_clarify\` (report what is blocked and why).
40073
- 3. **Publish/Verify: after a failed retry you MAY execute inline** to preserve delivery \u2014
40074
- the payload decisions are already in your context. Follow the same gate self-check as a
40075
- worker would.
40076
-
40077
- ## Delegation Protocol
40078
-
40079
- Mechanics every brief must be designed around:
40080
-
40081
- - A worker sees ONLY: its task title + description, the parent task's description, and the
40082
- results of completed dependency tasks. It does NOT see this conversation.
40083
- - Therefore **every brief is self-contained**: all decisions, boundaries, and evidence travel
40084
- inside the task description.
40085
- - Dispatch is synchronous: \`task { taskId, agentId: "general-purpose" }\` returns an
40086
- observation (the worker's final message, truncated at ~8k chars) and an
40087
- \`executionResultId\`. Record the id on the child task (\`manage_task update\`/\`add_activity\`).
40088
- - The worker settles its own task (\`set_status\` with \`result\`/\`failureReason\`). Read both the
40089
- observation and the task result before reconciling.
40090
-
40091
- Write briefs as field checklists adapted to the situation \u2014 decisions and evidence, not prose.
40092
- The worker assembles payloads from the reference sections of this skill; the brief carries the
40093
- approved decisions, never full payload JSON.
40094
-
40095
- ### Explore brief (\`Explore <schema>.<table> for <goal>\`)
40096
-
40097
- Required fields:
40098
- 1. Datasource: serverKey/connectionKey + datasourceId (and \`runConfig.metricsDataSource\` preset if present).
40099
- 2. Grant boundary: the allowed schema + table pattern from \`get_grants\`, verbatim; never probe outside it.
40100
- 3. Target table(s): schema-qualified names; one brief per table.
40101
- 4. Question list: per column (or column group) \u2014 business meaning candidates, expected role
40102
- (dimension | measure | time), net/gross, grain.
40103
- 5. Method: read-only SELECT/WITH only; use the \`references/metadata-sql.md\` templates
40104
- (columns, sample rows, value distribution); cap sample size (e.g. \u22641000 rows, \u226450 groups).
40105
- Prefer targeted queries over bulk catalog dumps. A large single read (e.g. full
40106
- \`read_semantic_catalog\` detail) is allowed \u2014 your isolation protects the orchestrator's
40107
- context \u2014 but findings must be compressed to conclusion level.
40108
- 6. Output contract: structured findings \u2014 per column: observed type, sample values,
40109
- distribution highlights, role candidate + evidence, \`INCONCLUSIVE\` marking for unresolved
40110
- semantics.
40111
- 7. Invariants: read-only only; grant boundary absolute; never guess \u2014 \`INCONCLUSIVE\` instead.
40112
- 8. Closing: settle the task (\`set_status completed\`, result = findings summary); final message
40113
- = the structured findings (it becomes the observation).
40114
-
40115
- ### Publish-table brief (\`Publish table meta <objectKey>\`)
40116
-
40117
- Required fields:
40118
- 1. Approved decisions: full column list (name/type/role/label/description), grain,
40119
- displayName/docType/shortDesc/sourceSystem/sourceTables.
40120
- 2. Identity: \`objectKey\` (stable, unique per datasource) + \`schemaName.tableName\`.
40121
- 3. Assembly instruction: full \`table_view_detail\` payload per **Publish table meta** below,
40122
- plus the identity twin (\`table_catalog\`, same \`objectKey\`), plus an EXACT \`accessGrant\`
40123
- matching the tenant grant.
40124
- 4. Gate self-check: publish gate items 1\u20133 \u2014 do not publish if any fails.
40125
- 5. Publish via \`metrics_meta_tool\` \`create_table\`; then \`get_meta\` to confirm visibility.
40126
- 6. Mistakes: fix with \`update_table\`; never leave a partial publish.
40127
- 7. Invariants: EXACT patternType; every column tagged and labeled.
40128
- 8. Closing: settle the task; final message = receipts (objectKeys + get_meta confirmation).
40129
-
40130
- ### Publish-metric brief (\`Publish metric <objectKey>\`)
40131
-
40132
- Required fields (per metric):
40133
- 1. Identity: \`objectKey\` = \`metric_name\`, display_name, domain, description, data_type, format.
40134
- 2. Source: schema-qualified \`source.table_view\` (must match the published table meta).
40135
- 3. Calculation: aggregate (\`aggregation\` + \`measure\`, with the confirmed business meaning) or
40136
- derived (ratio references / formula) \u2014 exactly as approved in Propose the model.
40137
- 4. \`supported_dimensions\`: array of objects \`{dim_id, field_name, label, data_type}\`,
40138
- including the time dimension.
40139
- 5. \`default_time_context\`: time_dimension + granularity + supported_grains (+ window if requested).
40140
- 6. \`ai_agent_context\`: polarity, synonyms, human_readable_explanation.
40141
- 7. Assembly instruction: \`metric_index\` then \`metric_detail\` in the FULL runtime style per
40142
- **Publish metric meta** below; publish via \`metrics_meta_tool\` \`create_metric\`.
40143
- 8. Gate self-check + smoke \`query\` (one grouping by the default time grain) + \`get_meta\`
40144
- receipts; closing = settle the task, final message = receipts.
40145
-
40146
- ### Verify brief (\`Verify <metric> against acceptance evidence\`)
40147
-
40148
- Required fields:
40149
- 1. Acceptance evidence verbatim (from the Goal Model).
40150
- 2. Queries to run (semantic \`query\` via \`metrics_runtime_tool\`) and the expected shape/values.
40151
- 3. Report contract: PASS/FAIL verdict + actual vs expected; on FAIL include the differences
40152
- and a suspicion list \u2014 do NOT modify meta (fixes are new Publish tasks).
40153
- 4. Invariants: read-only only.
40154
- 5. Closing: settle the task; final message = the verdict summary.
40155
-
40156
- ### Brief closing (all types)
40157
-
40158
- - Invariants line: grant boundary + read-only SQL + publish gate before any create.
40159
- - Result structure: the structured summary the orchestrator expects back.
40160
- - Finish by settling the task (\`set_status completed\` with result, or \`failed\` with
40161
- failureReason) and making the final message that structured summary.
40162
-
40163
- ## Worker mode
40164
-
40165
- Trigger: your context contains \`## Bound Task\`. You are a worker; these rules override the
40166
- orchestrator policy (Safety and the reference sections still apply):
40167
-
40168
- - Execute the bound task's brief only. Read the contract with \`manage_task get\`; the task
40169
- description is authoritative. Load this skill if the bootstrap asks \u2014 you need its payload
40170
- reference sections.
40171
- - Do NOT: re-agree the Goal Model, create sibling or child tasks, dispatch \`task\`, call
40172
- \`ask_user_to_clarify\`, or update the parent task's \`## Belief State\`.
40173
- - Apply the FEP loop inside the brief; obey the grant boundary and read-only SQL; run the
40174
- publish gate before any create.
40175
- - Unclear semantics: mark \`INCONCLUSIVE\` with candidates + evidence in your findings. Never
40176
- guess, never publish on a guess.
40177
- - Finish: \`set_status completed\` with a structured result (or \`failed\` with failureReason),
40178
- and make your final message the structured summary \u2014 it is the observation your
40179
- orchestrator reads.
40180
-
40181
- ## Belief State (orchestrator-owned)
40182
-
40183
- The parent task's description carries a \`## Belief State\` section as a Markdown table:
40184
-
40185
- \`\`\`
40186
- | Belief Key | Probability | Target | Basis |
40187
- |---|---|---|---|
40188
- | sell-in-nes-source-table | 70% | 100% | column \`nes\` probed as numeric measure in grant |
40189
- \`\`\`
40190
-
40191
- Rules: belief keys are lowercase kebab-case; probability/target are percentages 0\u2013100% that
40192
- represent evidence support, not calibrated probability. Only the orchestrator writes this
40193
- section \u2014 after each dispatch it folds the worker's findings into the table so the parent
40194
- task always reflects the current evidence.
40195
-
40196
- ## Workflow
40197
-
40198
- 1. **Pick the datasource + cheap observation.** \`metrics_datasource_tool\` action
40199
- \`list_datasources\`, or the preset \`runConfig.metricsDataSource\` (\`serverKey\`\u2192connectionKey,
40200
- \`datasourceId\`). Inline, read-only.
40201
- 2. **Agree the Goal Model.** (HITL)
40202
- 3. **Create the parent task** \u2014 contract + \`## Belief State\` (seeded from the Goal Model).
40203
- 4. **Explore by dispatch** \u2014 one Explore brief per table, serial; collect findings; reconcile
40204
- \`## Belief State\`; collect \`INCONCLUSIVE\` columns.
40205
- 5. **Propose the model** (HITL) \u2014 present table columns (with \`role: dimension | measure\`)
40206
- and the metrics (aggregate/derived) for approval; include clarify questions for
40207
- \`INCONCLUSIVE\` columns in the same ask.
40208
- 6. **Publish tables by dispatch** \u2014 one Publish-table brief per table; check receipts.
40209
- 7. **Publish metrics by dispatch** \u2014 one Publish-metric brief per metric; receipts + smoke query.
40210
- 8. **Verify by dispatch** \u2014 Verify brief against acceptance evidence. FAIL \u2192 reconcile
40211
- belief \u2192 fix decisions \u2192 new Publish task (\`update_table\`/\`update_metric\`) \u2192 re-Verify.
40212
- PASS \u2192 complete the parent task (result = acceptance evidence met).
40213
-
40214
- ## Explore (reference)
40215
-
40216
- Read \`table-grants\`, then probe with \`query\`. SQL is validated read-only by the client and the
40217
- server enforces the grant; un-granted tables return \`TABLE_NOT_GRANTED\`. Prefer the
40218
- \`references/metadata-sql.md\` templates because dialect varies (PostgreSQL / SQL Server / HANA).
40219
- If the user provides a data dictionary or sample data file, read it with filesystem and
40220
- reconcile it against the probed columns.
40221
-
40222
- ## Unclear field semantics
40223
-
40224
- A probed column name may not reveal its business meaning (e.g. whether \`nes\` is a net amount to
40225
- sum, a rate to average, or an enum to filter). Publishing meta on a misunderstood field pollutes
40226
- the runtime and every downstream metric that depends on it, and delete is not available. Treat this
40227
- as FEP **INCONCLUSIVE** \u2014 never guess, and never publish on an unverified guess.
40228
-
40229
- Resolve in order of increasing cost (inside the Explore brief):
40230
- 1. **Probe sample values and distribution** (\`query\`, templates in \`references/metadata-sql.md\`):
40231
- - numbers in (0,1) or clustered near 100 \u2192 likely a ratio/percentage \u2192 dimension or \`avg\`, rarely \`sum\`;
40232
- - large additive amounts (currency, counts) \u2192 measure with \`sum\`;
40233
- - small enumerations (year 2023/2024, 0/1 flags, codes) \u2192 dimension.
40234
- The share of zeros/negatives and the value scale usually disambiguate semantics.
40235
- 2. **Read user-provided docs**: if the user supplied a data dictionary or sample file, read it via
40236
- filesystem and reconcile it against the probed columns.
40237
- 3. **Cross-field correlation**: compare the unclear field with fields whose semantics are confirmed.
40238
-
40239
- If evidence is still INCONCLUSIVE:
40240
- - Do **not** publish meta that depends on the unclear field.
40241
- - The worker marks the column \`INCONCLUSIVE\` (candidates + evidence) in its findings; the
40242
- **orchestrator** lists it with candidate interpretations in the **Propose the model** step
40243
- and asks the user to confirm its semantics (role, value meaning, net/gross) via
40244
- \`ask_user_to_clarify\`. The user does not need to see the table \u2014 probed schema, samples, and
40245
- candidates are enough.
40246
- - The orchestrator records a low-probability belief entry (e.g.
40247
- \`| sales-nes-semantics | 40% | 100% | user must confirm role / net amount |\`) so verify/refine
40248
- can revisit it later instead of assuming it is settled.
40249
-
40250
- ## Publish table meta (\`create_table\`)
40251
-
40252
- Publish the authoritative shape below (objectType \`table_view_detail\`, with an EXACT accessGrant):
40253
-
40254
- \`\`\`json
40255
- {
40256
- "objectType": "table_view_detail",
40257
- "objectKey": "hankel_view_sales_summary",
40258
- "status": 1,
40259
- "payload": {
40260
- "schemaName": "public",
40261
- "tableName": "hankel_view_sales_summary",
40262
- "displayName": "Hankel Sales Summary",
40263
- "docType": "Sales Summary",
40264
- "docTypeEn": "Sales Summary",
40265
- "shortDesc": "Sales-level progress summary.",
40266
- "grain": "canonical_sales_name",
40267
- "sourceSystem": "Hankel Run for Gold",
40268
- "sourceTables": ["hankel_project_opportunity_lines", "hankel_new_order_lines"],
40269
- "columns": [
40270
- { "name": "canonical_sales_name", "label": "Canonical Sales Name", "type": "string", "role": "dimension", "description": "Standardized sales name used for grouping." },
40271
- { "name": "nes", "label": "NES", "type": "number", "role": "measure", "description": "Net external sales amount." },
40272
- { "name": "report_cutoff_date", "label": "Report Cutoff Date", "type": "date", "role": "time", "description": "Cutoff date of the report snapshot." }
40273
- ]
40274
- },
40275
- "accessGrant": {
40276
- "schemaName": "public",
40277
- "tablePattern": "hankel_view_sales_summary",
40278
- "patternType": "EXACT",
40279
- "caseSensitive": false,
40280
- "status": 1
40281
- }
40282
- }
40283
- \`\`\`
40284
-
40285
- Design rules:
40286
- - \`objectKey\` is stable and unique per datasource (the view/table key).
40287
- - \`columns[].role\` has THREE values: \`dimension\` (grouping/filtering), \`measure\` (aggregated numbers), \`time\` (the report cutoff/snapshot date used by default_time_context).
40288
- - Give every column a business \`description\`.
40289
- - Lineage fields (\`docType\`, \`shortDesc\`, \`grain\`, \`sourceSystem\`, \`sourceTables\`) make the asset findable and trustworthy \u2014 fill them from exploration evidence.
40290
- - Runtime table publication uses \`patternType: "EXACT"\` (\`PREFIX\` is only for datasource-level exploration scopes).
40291
- - For each semantic table also publish the identity twin: the same body with \`objectType: "table_catalog"\` and the same \`objectKey\` (same or richer payload).
40292
-
40293
- ## Publish metric meta (\`create_metric\`)
40294
-
40295
- Two steps for the same \`objectKey\`.
40296
-
40297
- ### 3a. Metric index (for lists/search)
40298
-
40299
- \`\`\`json
40300
- {
40301
- "objectType": "metric_index",
40302
- "objectKey": "sell_in_nes",
40303
- "status": 1,
40304
- "payload": {
40305
- "metric_name": "sell_in_nes",
40306
- "display_name": "Sell-in NES",
40307
- "domain": "sales",
40308
- "short_desc": "Net external sales amount from distributor sell-in rows.",
40309
- "search_keywords": ["sell in", "nes", "net external sales"],
40310
- "source_type": "cdp_postgres",
40311
- "source": { "table_view": "public.hankel_distr_sell_in" }
40312
- }
40313
- }
40314
- \`\`\`
40315
-
40316
- \`search_keywords\` drive metric retrieval for natural-language questions \u2014 include business synonyms.
40317
-
40318
- ### 3b. Metric detail (the calculation)
40319
-
40320
- IMPORTANT \u2014 runtime schema requirement: the Metrics Server query runtime only recognizes metrics
40321
- published in the FULL runtime style below (the same shape as existing working metrics, with
40322
- snake_case fields like \`metric_name\`, \`source.table_view\`, \`supported_dimensions\` objects, and
40323
- \`default_time_context\`). A minimal \`{name, sourceTable, calculation, dimensions}\` payload is
40324
- accepted by the publish API but is NOT queryable \u2014 querying it returns 403 "not authorized".
40325
-
40326
- Aggregate metric (full runtime style):
40327
-
40328
- \`\`\`json
40329
- {
40330
- "objectType": "metric_detail",
40331
- "objectKey": "sell_in_nes",
40332
- "status": 1,
40333
- "payload": {
40334
- "metric_name": "sell_in_nes",
40335
- "display_name": "Sell-in NES",
40336
- "domain": "sales",
40337
- "description": "Net external sales amount from distributor sell-in rows.",
40338
- "data_type": "numeric",
40339
- "format": "currency",
40340
- "source_type": "cdp_postgres",
40341
- "source": { "table_view": "public.hankel_distr_sell_in", "base_filters": [] },
40342
- "calculation": { "type": "aggregate", "aggregation": "sum", "measure": "nes" },
40343
- "supported_dimensions": [
40344
- { "dim_id": "posting_year", "field_name": "posting_year", "label": "Posting Year", "data_type": "number" },
40345
- { "dim_id": "sales_team", "field_name": "sales_team", "label": "Sales Team", "data_type": "string" }
40346
- ],
40347
- "default_time_context": {
40348
- "time_dimension": "posting_date",
40349
- "label": "Posting date",
40350
- "granularity": "month",
40351
- "window": "YTD",
40352
- "supported_grains": ["month", "year"]
40353
- },
40354
- "ai_agent_context": {
40355
- "polarity": "positive",
40356
- "synonyms": ["sell in", "nes", "net external sales"],
40357
- "human_readable_explanation": "Higher sell-in NES means more goods purchased from the distributor."
40358
- }
40359
- }
40360
- }
40361
- \`\`\`
40362
-
40363
- Derived ratio metric (references two aggregate metrics):
40364
-
40365
- \`\`\`json
40366
- {
40367
- "objectType": "metric_detail",
40368
- "objectKey": "gross_margin_rate",
40369
- "status": 1,
40370
- "payload": {
40371
- "metric_name": "gross_margin_rate",
40372
- "display_name": "Gross Margin Rate",
40373
- "description": "Gross margin divided by sell-in NES.",
40374
- "domain": "sales",
40375
- "data_type": "numeric",
40376
- "format": "percent",
40377
- "source_type": "cdp_postgres",
40378
- "source": { "table_view": "public.hankel_distr_sell_in", "base_filters": [] },
40379
- "calculation": { "type": "derived", "operator": "ratio", "numerator": "gross_margin", "denominator": "sell_in_nes" },
40380
- "supported_dimensions": [
40381
- { "dim_id": "posting_year", "field_name": "posting_year", "label": "Posting Year", "data_type": "number" }
40382
- ],
40383
- "default_time_context": { "time_dimension": "posting_date", "granularity": "month", "supported_grains": ["month", "year"] }
40384
- }
40385
- }
40386
- \`\`\`
40387
-
40388
- Design rules:
40389
- - \`objectKey\` unique per datasource (index and detail share it).
40390
- - \`payload.metric_name\` must equal \`objectKey\`.
40391
- - \`source.table_view\` must be schema-qualified and match the published table meta's physical table.
40392
- - \`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.
40393
- - \`calculation.type: "aggregate"\` = one measure + aggregation (sum/avg/count/min/max/count_distinct).
40394
- - \`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.
40395
- - \`default_time_context\` (\`time_dimension\` + \`granularity\` + \`supported_grains\`, optionally \`window\`) is required by the query runtime; its \`time_dimension\` must appear in supported_dimensions.
40396
- - \`ai_agent_context\` (\`polarity\`, \`synonyms\`, \`human_readable_explanation\`) improves natural-language metric retrieval \u2014 always provide it.
40397
- - 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\`.
40398
- - Do not inline raw SQL for new DB-backed metrics (complex logic belongs in a view).
40399
- - Use \`update_metric\` / \`update_table\` to correct mistakes; no removal actions are exposed.
40400
-
40401
- ## Verify and refine
40402
-
40403
- - Verify is **dispatched** (Verify brief). The worker runs \`get_meta\` \u2192 confirms the table and
40404
- metric are visible, then \`query\`es the metric against acceptance evidence.
40405
- - On FAIL the worker reports differences; the **orchestrator** applies the FEP reconcile:
40406
- update \`## Belief State\`, fix the decisions, and dispatch a new Publish task
40407
- (\`update_table\`/\`update_metric\`) \u2014 then re-Verify \u2014 until acceptance evidence is met.
40408
-
40409
- ## Troubleshooting
40410
-
40411
- | Symptom | Cause / fix |
40412
- |---|---|
40413
- | \`TABLE_NOT_GRANTED\` | SQL referenced a table outside the tenant grant; pick an in-grant table |
40414
- | metric create fails: sourceTable missing | publish the table meta first |
40415
- | metric create fails: unknown dimension | publish the dimension column with \`role: dimension\` |
40416
- | derived metric create fails | numerator/denominator metrics don't exist yet \u2014 publish them first |
40417
- | datasource \`query\` rejected | SQL was not read-only (SELECT/WITH only) or multi-statement |
40418
- | \`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 |
40419
- | worker observation truncated | findings exceeded ~8k chars; worker must keep the final message a compact structured summary |
40420
- | dispatch failed (tool error) | retry once; Explore never goes inline \u2014 ask the user; Publish/Verify may go inline after the failed retry |
40421
-
40422
- ## Safety
40423
-
40424
- - Only query tables that match the tenant's \`table-grants\`.
40425
- - Never return a full physical-table inventory or reveal whether an un-granted table exists.
40426
- - SQL is validated read-only; let the server reject anything outside that.
40427
- `;
40428
- var resources = {
40429
- "references/metadata-sql.md": {
40430
- content: `# Datasource exploration SQL templates (read-only)
40431
-
40432
- Pick the block matching the server's database. These run through the datasource \`query\` action;
40433
- the SQL is validated read-only.
40434
-
40435
- ## PostgreSQL
40436
- - 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\`
40437
- - Columns: \`select column_name, data_type from information_schema.columns where table_schema = :schemaName and table_name = :tableName order by ordinal_position\`
40438
- - Sample: \`select * from :schemaName.:tableName limit :maxRows\` \u2014 pass a concrete table, not a bound param, if the server does not support binding identifiers.
40439
-
40440
- ## SQL Server
40441
- - Tables: \`select table_schema, table_name from information_schema.tables order by table_schema, table_name\`
40442
- - Columns: \`select column_name, data_type from information_schema.columns where table_schema = :schemaName and table_name = :tableName order by ordinal_position\`
40443
-
40444
- ## HANA
40445
- - Tables: \`select schema_name, table_name from sys.tables where schema_name = :schemaName order by table_name\`
40446
- - Columns: \`select column_name, data_type_name from table_columns where schema_name = :schemaName and table_name = :tableName order by position\`
40447
-
40448
- ## Value distribution (any dialect)
40449
- \`select <dim>, count(*) as row_count from <table> group by <dim> order by row_count desc limit :maxRows\`
40450
- `
40451
- },
40452
- "examples/table-meta.json": {
40453
- content: `{
40454
- "objectType": "table_view_detail",
40455
- "objectKey": "hankel_distr_sell_in",
40456
- "status": 1,
40457
- "payload": {
40458
- "schemaName": "public",
40459
- "tableName": "hankel_distr_sell_in",
40460
- "displayName": "Hankel Distributor Sell In",
40461
- "description": "Distributor sell-in transaction rows for the Hankel tenant.",
40462
- "columns": [
40463
- { "name": "posting_year", "label": "Posting Year", "type": "number", "role": "dimension" },
40464
- { "name": "posting_month", "label": "Posting Month", "type": "number", "role": "dimension" },
40465
- { "name": "sales_team", "label": "Sales Team", "type": "string", "role": "dimension" },
40466
- { "name": "region", "label": "Region", "type": "string", "role": "dimension" },
40467
- { "name": "nes", "label": "Net External Sales", "type": "number", "role": "measure" },
40468
- { "name": "gross_margin", "label": "Gross Margin", "type": "number", "role": "measure" }
40469
- ]
40470
- }
40471
- }
40472
- `
40473
- },
40474
- "examples/metric-aggregate.json": {
40475
- content: `{
40476
- "objectType": "metric_detail",
40477
- "objectKey": "sell_in_nes",
40478
- "status": 1,
40479
- "payload": {
40480
- "metric_name": "sell_in_nes",
40481
- "display_name": "Sell-in NES",
40482
- "domain": "sales",
40483
- "description": "Net external sales amount from distributor sell-in rows.",
40484
- "data_type": "numeric",
40485
- "format": "currency",
40486
- "source_type": "cdp_postgres",
40487
- "source": { "table_view": "public.hankel_distr_sell_in", "base_filters": [] },
40488
- "calculation": { "type": "aggregate", "aggregation": "sum", "measure": "nes" },
40489
- "supported_dimensions": [
40490
- { "dim_id": "posting_year", "field_name": "posting_year", "label": "Posting Year", "data_type": "number" },
40491
- { "dim_id": "sales_team", "field_name": "sales_team", "label": "Sales Team", "data_type": "string" },
40492
- { "dim_id": "posting_date", "field_name": "posting_date", "label": "Posting Date", "data_type": "string" }
40493
- ],
40494
- "default_time_context": {
40495
- "time_dimension": "posting_date",
40496
- "label": "Posting date",
40497
- "granularity": "month",
40498
- "window": "YTD",
40499
- "supported_grains": ["month", "year"]
40500
- },
40501
- "ai_agent_context": {
40502
- "polarity": "positive",
40503
- "synonyms": ["sell in", "nes", "net external sales"],
40504
- "human_readable_explanation": "Higher sell-in NES means more goods purchased from the distributor."
40505
- }
40506
- }
40507
- }
40508
- `
40509
- },
40510
- "examples/metric-derived.json": {
40511
- content: `{
40512
- "objectType": "metric_detail",
40513
- "objectKey": "gross_margin_rate",
40514
- "status": 1,
40515
- "payload": {
40516
- "metric_name": "gross_margin_rate",
40517
- "display_name": "Gross Margin Rate",
40518
- "domain": "sales",
40519
- "description": "Gross margin divided by sell-in NES.",
40520
- "data_type": "numeric",
40521
- "format": "percent",
40522
- "source_type": "cdp_postgres",
40523
- "source": { "table_view": "public.hankel_distr_sell_in", "base_filters": [] },
40524
- "calculation": { "type": "derived", "operator": "ratio", "numerator": "gross_margin", "denominator": "sell_in_nes" },
40525
- "supported_dimensions": [
40526
- { "dim_id": "posting_year", "field_name": "posting_year", "label": "Posting Year", "data_type": "number" },
40527
- { "dim_id": "posting_date", "field_name": "posting_date", "label": "Posting Date", "data_type": "string" }
40528
- ],
40529
- "default_time_context": {
40530
- "time_dimension": "posting_date",
40531
- "label": "Posting date",
40532
- "granularity": "month",
40533
- "supported_grains": ["month", "year"]
40534
- },
40535
- "ai_agent_context": {
40536
- "polarity": "positive",
40537
- "synonyms": ["gross margin rate", "margin rate"],
40538
- "human_readable_explanation": "Gross margin rate divides gross margin by sell-in NES; higher means more margin retained on sold-in goods."
40539
- }
40540
- }
40541
- }
40542
- `
40543
- }
40544
- };
40545
- var SEMANTIC_METRICS_MODELING_SKILL = {
40546
- version: "1.1.2",
40547
- content: CONTENT,
40548
- resources
40549
- };
40550
-
40551
- // src/middlewares/semanticMetricsBuilderPrompt.ts
40552
- var SEMANTIC_METRICS_BUILDER_PROMPT = `You are the Semantic Metrics Builder.
40553
-
40554
- CRITICAL FIRST ACTION: Before any response or other action, call the \`skill\`
40555
- tool with skill_name: "semantic-metrics-modeling" to load semantic-metrics-modeling and follow it.
40556
- Never announce the skill load. If it fails, retry once, then stop and explicitly
40557
- report that the required Semantic Metrics Builder skill could not be loaded.`;
40558
-
40559
- // src/middlewares/semanticMetricsMiddleware.ts
40560
- import { AgentType as AgentType9 } from "@axiom-lattice/protocols";
40561
- function createSemanticMetricsMiddleware(config) {
40562
- const connections = config.connections ?? [];
40563
- const connectAll = config.connectAll === true;
40564
- const selector = { connectionType: "semantic-metrics", connections, connectAll };
40565
- return createMiddleware20({
40566
- name: "SemanticMetrics",
40567
- contextSchema,
40568
- tools: [
40569
- createMetricsDatasourceTool(selector),
40570
- createMetricsMetaTool(selector),
40571
- createMetricsRuntimeTool(selector)
40572
- ]
40573
- });
40574
- }
40575
- function buildConnectionHeaders(config) {
40576
- const headers = {
40577
- Accept: "application/json",
40578
- ...config.headers !== void 0 && config.headers !== null ? config.headers : {}
40579
- };
40580
- if (config.apiKey) headers["Authorization"] = `Bearer ${config.apiKey}`;
40581
- return headers;
40582
- }
40583
- function resolveBaseUrl(config) {
40584
- const serverUrl = config.serverUrl;
40585
- if (!serverUrl) {
40586
- throw new Error("serverUrl is required");
40587
- }
40588
- return serverUrl.replace(/\/$/, "");
40589
- }
40590
- var semanticMetricsPlugin = {
40591
- meta: {
40592
- type: "semantic-metrics",
40593
- category: "data",
40594
- capabilityBundleEligible: true,
40595
- openExpose: [
40596
- // Query-only surface: no writes reach either tool (SQL is read-only).
40597
- { name: "metrics_datasource_tool", readOnly: true },
40598
- { name: "metrics_runtime_tool", readOnly: true }
40599
- ],
40600
- name: "Semantic Metrics",
40601
- 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.",
40602
- version: "1.0.0",
40603
- tools: [
40604
- { name: "metrics_datasource_tool", description: "Explore datasource structure within the tenant's granted scope" },
40605
- { name: "metrics_meta_tool", description: "Publish and maintain runtime semantic tables and metrics" },
40606
- { name: "metrics_runtime_tool", description: "Read runtime meta and execute semantic metric queries" }
40607
- ],
40608
- configSchema: {
40609
- type: "object",
40610
- title: "Semantic Metrics Configuration",
40611
- 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).",
40612
- properties: {
40613
- connections: {
40614
- type: "array",
40615
- title: "Connections",
40616
- items: { type: "string" },
40617
- widget: "connectionSelect"
40618
- },
40619
- connectAll: {
40620
- type: "boolean",
40621
- title: "Connect All",
40622
- default: false,
40623
- widget: "switch"
40624
- }
40625
- }
40626
- },
40627
- defaultConfig: { connections: [], connectAll: false }
40628
- },
40629
- connection: {
40630
- // PluginConnectionFieldSchema.type supports only string/number/boolean/password,
40631
- // so headers is NOT a form field; the V2 client still reads config.headers at runtime.
40632
- fields: [
40633
- { key: "serverUrl", type: "string", title: "Metrics Server Base URL (include /api/v1)", required: true },
40634
- { key: "apiKey", type: "password", title: "API Key (optional)" }
40635
- ],
40636
- test: async (config) => {
40637
- try {
40638
- const baseUrl = resolveBaseUrl(config);
40639
- const res = await fetch(`${baseUrl}/datasources`, {
40640
- headers: buildConnectionHeaders(config)
40641
- });
40642
- const text = await res.text().catch(() => "");
40643
- let ok = res.ok;
40644
- let detail = "";
40645
- try {
40646
- const parsed = JSON.parse(text);
40647
- if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
40648
- const code = parsed.code;
40649
- if (typeof code === "number") {
40650
- ok = res.ok && code === 200;
40651
- if (!ok) detail = ` (${parsed.message ?? code})`;
40652
- }
40653
- }
40654
- } catch {
40655
- }
40656
- return {
40657
- ok,
40658
- message: ok ? `Reachable at ${baseUrl}` : `HTTP ${res.status}${detail}`
40659
- };
40660
- } catch (err) {
40661
- return {
40662
- ok: false,
40663
- message: `Cannot connect: ${err instanceof Error ? err.message : String(err)}`
40664
- };
40665
- }
40666
- },
40667
- discover: async (config) => {
40668
- try {
40669
- const baseUrl = resolveBaseUrl(config);
40670
- const res = await fetch(`${baseUrl}/datasources`, {
40671
- headers: buildConnectionHeaders(config)
40672
- });
40673
- const text = await res.text();
40674
- if (!res.ok) {
40675
- throw new Error(`HTTP ${res.status}${text ? `: ${text.slice(0, 200)}` : ""}`);
40676
- }
40677
- const parsed = JSON.parse(text);
40678
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
40679
- throw new Error("Metrics server returned an unexpected payload (expected a JSON envelope)");
40680
- }
40681
- const envelope = parsed;
40682
- if (typeof envelope.code === "number" && envelope.code !== 200) {
40683
- throw new Error(envelope.message || `API ${envelope.code}`);
40684
- }
40685
- const data = envelope.data;
40686
- if (!Array.isArray(data)) {
40687
- throw new Error("Metrics server returned an unexpected payload (expected a datasource array)");
40688
- }
40689
- return data.filter((d) => {
40690
- if (d === null || typeof d !== "object") return false;
40691
- const id = d.id;
40692
- return id !== void 0 && id !== null && id !== "";
40693
- }).map((item) => ({
40694
- id: String(item.id),
40695
- name: item.name ?? String(item.id)
40696
- }));
40697
- } catch (err) {
40698
- throw new Error(
40699
- `Cannot discover datasources: ${err instanceof Error ? err.message : String(err)}`
40700
- );
40701
- }
40702
- }
40703
- },
40704
- skills: {
40705
- "semantic-metrics-modeling": SEMANTIC_METRICS_MODELING_SKILL
40706
- },
40707
- agents: {
40708
- "semantic-metrics-builder": {
40709
- key: "semantic-metrics-builder",
40710
- name: "Semantic Metrics Builder",
40711
- 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.",
40712
- type: AgentType9.DEEP_AGENT,
40713
- prompt: SEMANTIC_METRICS_BUILDER_PROMPT,
40714
- middleware: [
40715
- {
40716
- id: "semantic-metrics",
40717
- type: "semantic-metrics",
40718
- name: "Semantic Metrics",
40719
- description: "Explore datasources, publish table/meta metrics, query runtime",
40720
- enabled: true,
40721
- config: { connections: [], connectAll: true }
40722
- },
40723
- {
40724
- id: "skill",
40725
- type: "skill",
40726
- name: "Skill",
40727
- description: "Load the semantic-metrics-modeling policy and task-definition reference",
40728
- enabled: true,
40729
- config: { readAll: false, skills: ["semantic-metrics-modeling", "task-definition"] }
40730
- },
40731
- {
40732
- id: "task",
40733
- type: "task",
40734
- name: "Task",
40735
- description: "Persistent TaskItems as the planning surface; update Belief State in task descriptions",
40736
- enabled: true,
40737
- config: {}
40738
- },
40739
- {
40740
- id: "ask_user_to_clarify",
40741
- type: "ask_user_to_clarify",
40742
- name: "Ask User",
40743
- description: "Wait for user input at modeling approval gates",
40744
- enabled: true,
40745
- config: {}
40746
- },
40747
- {
40748
- id: "filesystem",
40749
- type: "filesystem",
40750
- name: "Filesystem",
40751
- description: "Read user-provided schema docs, data dictionaries, or sample data files",
40752
- enabled: true,
40753
- config: {}
40754
- }
40755
- ]
40756
- }
40757
- },
40758
- middleware: (config) => createSemanticMetricsMiddleware(config)
40759
- };
40760
-
40761
- // src/middlewares/collectionMiddleware.ts
40762
- import { createMiddleware as createMiddleware21 } from "langchain";
40763
-
40764
- // src/tool_lattice/collection/list_collections.ts
40765
- import z60 from "zod";
40766
- import { tool as tool54 } from "langchain";
40767
-
40768
39227
  // src/tool_lattice/collection/utils.ts
40769
39228
  function getEffectiveCollectionScope(exeConfig, staticScope) {
40770
39229
  const runtimeConfig = getRuntimeCapabilityConfig(exeConfig, "collection");
@@ -40786,7 +39245,7 @@ var createListCollectionsTool = ({
40786
39245
  collectionKeys,
40787
39246
  connectAll
40788
39247
  }) => {
40789
- return tool54(
39248
+ return tool51(
40790
39249
  async (_input, _exeConfig) => {
40791
39250
  try {
40792
39251
  const tenantId2 = _exeConfig?.configurable?.runConfig?.tenantId || "default";
@@ -40821,23 +39280,23 @@ var createListCollectionsTool = ({
40821
39280
  {
40822
39281
  name: "list_collections",
40823
39282
  description: LIST_COLLECTIONS_DESCRIPTION,
40824
- schema: z60.object({})
39283
+ schema: z57.object({})
40825
39284
  }
40826
39285
  );
40827
39286
  };
40828
39287
 
40829
39288
  // src/tool_lattice/collection/search_collection.ts
40830
- import z61 from "zod";
40831
- import { tool as tool55 } from "langchain";
39289
+ import z58 from "zod";
39290
+ import { tool as tool52 } from "langchain";
40832
39291
  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.`;
40833
- var searchSchema = z61.object({
40834
- collection: z61.string().describe("The collection name to search in"),
40835
- query: z61.string().describe("The search query text"),
40836
- filter: z61.record(z61.unknown()).optional().describe("Metadata filter conditions"),
40837
- top_k: z61.number().optional().default(5).describe("Number of results to return")
39292
+ var searchSchema = z58.object({
39293
+ collection: z58.string().describe("The collection name to search in"),
39294
+ query: z58.string().describe("The search query text"),
39295
+ filter: z58.record(z58.unknown()).optional().describe("Metadata filter conditions"),
39296
+ top_k: z58.number().optional().default(5).describe("Number of results to return")
40838
39297
  });
40839
39298
  var createSearchCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => {
40840
- return tool55(
39299
+ return tool52(
40841
39300
  async (input, _exeConfig) => {
40842
39301
  try {
40843
39302
  const { collection, query, filter: filter2, top_k } = input;
@@ -40903,10 +39362,10 @@ var createSearchCollectionTool = (scope = { collectionKeys: [], connectAll: true
40903
39362
  };
40904
39363
 
40905
39364
  // src/tool_lattice/collection/get_collection.ts
40906
- import z62 from "zod";
40907
- import { tool as tool56 } from "langchain";
39365
+ import z59 from "zod";
39366
+ import { tool as tool53 } from "langchain";
40908
39367
  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.`;
40909
- var createGetCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => tool56(
39368
+ var createGetCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => tool53(
40910
39369
  async (input, _exeConfig) => {
40911
39370
  try {
40912
39371
  const scopeError = validateCollectionScope(input.name, _exeConfig, scope);
@@ -40931,24 +39390,24 @@ Embedding: ${c.embeddingKey}${fieldsDesc}`;
40931
39390
  return `Error: ${error.message}`;
40932
39391
  }
40933
39392
  },
40934
- { name: "get_collection", description: GET_COLLECTION_DESCRIPTION, schema: z62.object({ name: z62.string().describe("Collection name") }) }
39393
+ { name: "get_collection", description: GET_COLLECTION_DESCRIPTION, schema: z59.object({ name: z59.string().describe("Collection name") }) }
40935
39394
  );
40936
39395
 
40937
39396
  // src/tool_lattice/collection/create_collection.ts
40938
- import z63 from "zod";
40939
- import { tool as tool57 } from "langchain";
40940
- var createSchema = z63.object({
40941
- name: z63.string().describe("Collection name (lowercase, underscores only)"),
40942
- label: z63.string().describe("Display name"),
40943
- embeddingKey: z63.string().describe("Embedding model key"),
40944
- fields: z63.array(z63.object({
40945
- key: z63.string().describe("Field key name"),
40946
- type: z63.enum(["string", "number", "enum"]).describe("Field data type"),
40947
- enumValues: z63.array(z63.string()).optional().describe("Valid values for enum type"),
40948
- required: z63.boolean().optional().default(false).describe("Whether field is required")
39397
+ import z60 from "zod";
39398
+ import { tool as tool54 } from "langchain";
39399
+ var createSchema = z60.object({
39400
+ name: z60.string().describe("Collection name (lowercase, underscores only)"),
39401
+ label: z60.string().describe("Display name"),
39402
+ embeddingKey: z60.string().describe("Embedding model key"),
39403
+ fields: z60.array(z60.object({
39404
+ key: z60.string().describe("Field key name"),
39405
+ type: z60.enum(["string", "number", "enum"]).describe("Field data type"),
39406
+ enumValues: z60.array(z60.string()).optional().describe("Valid values for enum type"),
39407
+ required: z60.boolean().optional().default(false).describe("Whether field is required")
40949
39408
  })).optional().describe("Custom field definitions for entries in this collection")
40950
39409
  });
40951
- var createCreateCollectionTool = (scope = {}) => tool57(
39410
+ var createCreateCollectionTool = (scope = {}) => tool54(
40952
39411
  async (input, _exeConfig) => {
40953
39412
  try {
40954
39413
  const tenantId2 = _exeConfig?.configurable?.runConfig?.tenantId || "default";
@@ -40974,20 +39433,20 @@ var createCreateCollectionTool = (scope = {}) => tool57(
40974
39433
  );
40975
39434
 
40976
39435
  // src/tool_lattice/collection/update_collection.ts
40977
- import z64 from "zod";
40978
- import { tool as tool58 } from "langchain";
40979
- var schema = z64.object({
40980
- name: z64.string().describe("Collection name"),
40981
- label: z64.string().optional().describe("New display name"),
40982
- embeddingKey: z64.string().optional().describe("New embedding model key"),
40983
- fields: z64.array(z64.object({
40984
- key: z64.string().describe("Field key name"),
40985
- type: z64.enum(["string", "number", "enum"]).describe("Field data type"),
40986
- enumValues: z64.array(z64.string()).optional().describe("Valid values for enum type"),
40987
- required: z64.boolean().optional().default(false).describe("Whether field is required")
39436
+ import z61 from "zod";
39437
+ import { tool as tool55 } from "langchain";
39438
+ var schema = z61.object({
39439
+ name: z61.string().describe("Collection name"),
39440
+ label: z61.string().optional().describe("New display name"),
39441
+ embeddingKey: z61.string().optional().describe("New embedding model key"),
39442
+ fields: z61.array(z61.object({
39443
+ key: z61.string().describe("Field key name"),
39444
+ type: z61.enum(["string", "number", "enum"]).describe("Field data type"),
39445
+ enumValues: z61.array(z61.string()).optional().describe("Valid values for enum type"),
39446
+ required: z61.boolean().optional().default(false).describe("Whether field is required")
40988
39447
  })).optional().describe("Custom field definitions for entries (replaces existing schema)")
40989
39448
  });
40990
- var createUpdateCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => tool58(
39449
+ var createUpdateCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => tool55(
40991
39450
  async (input, _exeConfig) => {
40992
39451
  try {
40993
39452
  const scopeError = validateCollectionScope(input.name, _exeConfig, scope);
@@ -41008,9 +39467,9 @@ var createUpdateCollectionTool = (scope = { collectionKeys: [], connectAll: true
41008
39467
  );
41009
39468
 
41010
39469
  // src/tool_lattice/collection/delete_collection.ts
41011
- import z65 from "zod";
41012
- import { tool as tool59 } from "langchain";
41013
- var createDeleteCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => tool59(
39470
+ import z62 from "zod";
39471
+ import { tool as tool56 } from "langchain";
39472
+ var createDeleteCollectionTool = (scope = { collectionKeys: [], connectAll: true }) => tool56(
41014
39473
  async (input, _exeConfig) => {
41015
39474
  try {
41016
39475
  const scopeError = validateCollectionScope(input.name, _exeConfig, scope);
@@ -41022,19 +39481,19 @@ var createDeleteCollectionTool = (scope = { collectionKeys: [], connectAll: true
41022
39481
  return `Error: ${e.message}`;
41023
39482
  }
41024
39483
  },
41025
- { name: "delete_collection", description: `Delete a collection and all its entries. This cannot be undone.`, schema: z65.object({ name: z65.string().describe("Collection name") }) }
39484
+ { name: "delete_collection", description: `Delete a collection and all its entries. This cannot be undone.`, schema: z62.object({ name: z62.string().describe("Collection name") }) }
41026
39485
  );
41027
39486
 
41028
39487
  // src/tool_lattice/collection/list_entries.ts
41029
- import z66 from "zod";
41030
- import { tool as tool60 } from "langchain";
41031
- var schema2 = z66.object({
41032
- collection: z66.string().describe("Collection name")
39488
+ import z63 from "zod";
39489
+ import { tool as tool57 } from "langchain";
39490
+ var schema2 = z63.object({
39491
+ collection: z63.string().describe("Collection name")
41033
39492
  });
41034
39493
  function buildKey2(tenantId2, name) {
41035
39494
  return `${tenantId2}:${name}`;
41036
39495
  }
41037
- var createListEntriesTool = (scope = { collectionKeys: [], connectAll: true }) => tool60(
39496
+ var createListEntriesTool = (scope = { collectionKeys: [], connectAll: true }) => tool57(
41038
39497
  async (input, _exeConfig) => {
41039
39498
  try {
41040
39499
  const scopeError = validateCollectionScope(input.collection, _exeConfig, scope);
@@ -41063,19 +39522,19 @@ var createListEntriesTool = (scope = { collectionKeys: [], connectAll: true }) =
41063
39522
  );
41064
39523
 
41065
39524
  // src/tool_lattice/collection/add_entry.ts
41066
- import z67 from "zod";
41067
- import { tool as tool61 } from "langchain";
39525
+ import z64 from "zod";
39526
+ import { tool as tool58 } from "langchain";
41068
39527
  import { Document } from "@langchain/core/documents";
41069
39528
  import { v4 as uuidv48 } from "uuid";
41070
- var schema3 = z67.object({
41071
- collection: z67.string().describe("Collection name"),
41072
- content: z67.string().describe("Entry content text"),
41073
- metadata: z67.record(z67.unknown()).optional().describe("Metadata fields matching the collection schema")
39529
+ var schema3 = z64.object({
39530
+ collection: z64.string().describe("Collection name"),
39531
+ content: z64.string().describe("Entry content text"),
39532
+ metadata: z64.record(z64.unknown()).optional().describe("Metadata fields matching the collection schema")
41074
39533
  });
41075
39534
  function key2(t, n) {
41076
39535
  return `${t}:${n}`;
41077
39536
  }
41078
- var createAddEntryTool = (scope = { collectionKeys: [], connectAll: true }) => tool61(
39537
+ var createAddEntryTool = (scope = { collectionKeys: [], connectAll: true }) => tool58(
41079
39538
  async (input, _exeConfig) => {
41080
39539
  try {
41081
39540
  const scopeError = validateCollectionScope(input.collection, _exeConfig, scope);
@@ -41107,18 +39566,18 @@ var createAddEntryTool = (scope = { collectionKeys: [], connectAll: true }) => t
41107
39566
  );
41108
39567
 
41109
39568
  // src/tool_lattice/collection/update_entry.ts
41110
- import z68 from "zod";
41111
- import { tool as tool62 } from "langchain";
41112
- var schema4 = z68.object({
41113
- collection: z68.string().describe("Collection name"),
41114
- entryId: z68.string().describe("Entry ID to update"),
41115
- content: z68.string().optional().describe("New content"),
41116
- metadata: z68.record(z68.unknown()).optional().describe("New metadata")
39569
+ import z65 from "zod";
39570
+ import { tool as tool59 } from "langchain";
39571
+ var schema4 = z65.object({
39572
+ collection: z65.string().describe("Collection name"),
39573
+ entryId: z65.string().describe("Entry ID to update"),
39574
+ content: z65.string().optional().describe("New content"),
39575
+ metadata: z65.record(z65.unknown()).optional().describe("New metadata")
41117
39576
  });
41118
39577
  function key3(t, n) {
41119
39578
  return `${t}:${n}`;
41120
39579
  }
41121
- var createUpdateEntryTool = (scope = { collectionKeys: [], connectAll: true }) => tool62(
39580
+ var createUpdateEntryTool = (scope = { collectionKeys: [], connectAll: true }) => tool59(
41122
39581
  async (input, _exeConfig) => {
41123
39582
  try {
41124
39583
  const scopeError = validateCollectionScope(input.collection, _exeConfig, scope);
@@ -41139,16 +39598,16 @@ var createUpdateEntryTool = (scope = { collectionKeys: [], connectAll: true }) =
41139
39598
  );
41140
39599
 
41141
39600
  // src/tool_lattice/collection/delete_entry.ts
41142
- import z69 from "zod";
41143
- import { tool as tool63 } from "langchain";
41144
- var schema5 = z69.object({
41145
- collection: z69.string().describe("Collection name"),
41146
- entryId: z69.string().describe("Entry ID to delete")
39601
+ import z66 from "zod";
39602
+ import { tool as tool60 } from "langchain";
39603
+ var schema5 = z66.object({
39604
+ collection: z66.string().describe("Collection name"),
39605
+ entryId: z66.string().describe("Entry ID to delete")
41147
39606
  });
41148
39607
  function key4(t, n) {
41149
39608
  return `${t}:${n}`;
41150
39609
  }
41151
- var createDeleteEntryTool = (scope = { collectionKeys: [], connectAll: true }) => tool63(
39610
+ var createDeleteEntryTool = (scope = { collectionKeys: [], connectAll: true }) => tool60(
41152
39611
  async (input, _exeConfig) => {
41153
39612
  try {
41154
39613
  const scopeError = validateCollectionScope(input.collection, _exeConfig, scope);
@@ -41168,7 +39627,7 @@ var createDeleteEntryTool = (scope = { collectionKeys: [], connectAll: true }) =
41168
39627
  function createCollectionMiddleware(params) {
41169
39628
  const { collectionKeys, connectAll, compileStableCandidateTools = false } = params;
41170
39629
  if (!compileStableCandidateTools && !connectAll && (!collectionKeys || collectionKeys.length === 0)) {
41171
- return createMiddleware21({
39630
+ return createMiddleware20({
41172
39631
  name: "collectionMiddleware",
41173
39632
  contextSchema,
41174
39633
  tools: [
@@ -41178,7 +39637,7 @@ function createCollectionMiddleware(params) {
41178
39637
  });
41179
39638
  }
41180
39639
  const toolParams = { collectionKeys, connectAll };
41181
- return createMiddleware21({
39640
+ return createMiddleware20({
41182
39641
  name: "collectionMiddleware",
41183
39642
  contextSchema,
41184
39643
  tools: [
@@ -41241,24 +39700,24 @@ var collectionPlugin = {
41241
39700
  };
41242
39701
 
41243
39702
  // src/middlewares/askUserClarifyMiddleware.ts
41244
- import { createMiddleware as createMiddleware22, ToolMessage as ToolMessage11 } from "langchain";
39703
+ import { createMiddleware as createMiddleware21, ToolMessage as ToolMessage11 } from "langchain";
41245
39704
  import { interrupt as interrupt3 } from "@langchain/langgraph";
41246
39705
 
41247
39706
  // src/tool_lattice/ask_user_to_clarify/index.ts
41248
- import { tool as tool64 } from "langchain";
41249
- import z70 from "zod";
41250
- var questionSchema = z70.object({
41251
- question: z70.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?'"),
41252
- options: z70.array(z70.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."),
41253
- type: z70.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."),
41254
- required: z70.boolean().optional().default(false).describe("Whether this question must be answered"),
41255
- allowOther: z70.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.")
39707
+ import { tool as tool61 } from "langchain";
39708
+ import z67 from "zod";
39709
+ var questionSchema = z67.object({
39710
+ question: z67.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?'"),
39711
+ options: z67.array(z67.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."),
39712
+ type: z67.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."),
39713
+ required: z67.boolean().optional().default(false).describe("Whether this question must be answered"),
39714
+ allowOther: z67.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.")
41256
39715
  });
41257
- var inputSchema = z70.object({
41258
- questions: z70.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.")
39716
+ var inputSchema = z67.object({
39717
+ questions: z67.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.")
41259
39718
  });
41260
39719
  function createAskUserToClarifyTool() {
41261
- return tool64(
39720
+ return tool61(
41262
39721
  async (input) => {
41263
39722
  return JSON.stringify(input);
41264
39723
  },
@@ -41283,7 +39742,7 @@ function isProjectRoomRun(request) {
41283
39742
  return isRecord9(runConfig?.projectRoom);
41284
39743
  }
41285
39744
  function createAskUserClarifyMiddleware() {
41286
- return createMiddleware22({
39745
+ return createMiddleware21({
41287
39746
  name: "AskUserClarifyMiddleware",
41288
39747
  tools: [createAskUserToClarifyTool()],
41289
39748
  wrapToolCall: async (request, handler) => {
@@ -41387,11 +39846,11 @@ var askUserClarifyPlugin = {
41387
39846
  };
41388
39847
 
41389
39848
  // src/middlewares/widgetMiddleware.ts
41390
- import { createMiddleware as createMiddleware23 } from "langchain";
39849
+ import { createMiddleware as createMiddleware22 } from "langchain";
41391
39850
 
41392
39851
  // src/tool_lattice/widget/loadGuidelines.ts
41393
- import { tool as tool65 } from "langchain";
41394
- import { z as z71 } from "zod";
39852
+ import { tool as tool62 } from "langchain";
39853
+ import { z as z68 } from "zod";
41395
39854
 
41396
39855
  // src/middlewares/guidelines/index.ts
41397
39856
  var CORE = `# Imagine \u2014 Visual Creation Suite
@@ -42182,13 +40641,13 @@ function getGuidelines(modules) {
42182
40641
  var AVAILABLE_MODULES = Object.keys(MODULE_SECTIONS);
42183
40642
 
42184
40643
  // src/tool_lattice/widget/loadGuidelines.ts
42185
- var LoadGuidelinesInputSchema = z71.object({
42186
- modules: z71.array(z71.string()).describe(
40644
+ var LoadGuidelinesInputSchema = z68.object({
40645
+ modules: z68.array(z68.string()).describe(
42187
40646
  "Which design modules to load. Choose all that apply. Available modules: [" + AVAILABLE_MODULES.join(",") + "]"
42188
40647
  )
42189
40648
  });
42190
40649
  function createLoadGuidelinesTool() {
42191
- return tool65(
40650
+ return tool62(
42192
40651
  async (input) => {
42193
40652
  const result = getGuidelines(input.modules);
42194
40653
  return result;
@@ -42202,8 +40661,8 @@ function createLoadGuidelinesTool() {
42202
40661
  }
42203
40662
 
42204
40663
  // src/tool_lattice/widget/showWidget.ts
42205
- import { tool as tool66 } from "langchain";
42206
- import { z as z72 } from "zod";
40664
+ import { tool as tool63 } from "langchain";
40665
+ import { z as z69 } from "zod";
42207
40666
  function containsForbiddenTags(code) {
42208
40667
  const forbiddenPatterns = [
42209
40668
  /<!DOCTYPE/i,
@@ -42225,20 +40684,20 @@ function validateWidgetCode(code) {
42225
40684
  }
42226
40685
  return { valid: true };
42227
40686
  }
42228
- var ShowWidgetInputSchema = z72.object({
42229
- i_have_seen_guidelines: z72.boolean().describe(
40687
+ var ShowWidgetInputSchema = z69.object({
40688
+ i_have_seen_guidelines: z69.boolean().describe(
42230
40689
  "Must be true. Confirm you have called load_guidelines first."
42231
40690
  ),
42232
- title: z72.string().describe("Title displayed above the widget"),
42233
- loading_messages: z72.array(z72.string()).optional().describe(
40691
+ title: z69.string().describe("Title displayed above the widget"),
40692
+ loading_messages: z69.array(z69.string()).optional().describe(
42234
40693
  "1-4 short strings shown while the widget renders"
42235
40694
  ),
42236
- widget_code: z72.string().describe(
40695
+ widget_code: z69.string().describe(
42237
40696
  "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."
42238
40697
  )
42239
40698
  });
42240
40699
  function createShowWidgetTool() {
42241
- return tool66(
40700
+ return tool63(
42242
40701
  async (input) => {
42243
40702
  if (!input.i_have_seen_guidelines) {
42244
40703
  return "Error: You must call load_guidelines before using show_widget. Set i_have_seen_guidelines to true only after loading guidelines.";
@@ -42269,7 +40728,7 @@ function createWidgetMiddleware() {
42269
40728
  createLoadGuidelinesTool(),
42270
40729
  createShowWidgetTool()
42271
40730
  ];
42272
- return createMiddleware23({
40731
+ return createMiddleware22({
42273
40732
  name: "widgetMiddleware",
42274
40733
  contextSchema,
42275
40734
  tools
@@ -42293,8 +40752,8 @@ var widgetPlugin = {
42293
40752
  };
42294
40753
 
42295
40754
  // src/middlewares/taskMiddleware.ts
42296
- import { createMiddleware as createMiddleware24, tool as tool67 } from "langchain";
42297
- import { z as z73 } from "zod";
40755
+ import { createMiddleware as createMiddleware23, tool as tool64 } from "langchain";
40756
+ import { z as z70 } from "zod";
42298
40757
  import { GraphInterrupt as GraphInterrupt3, interrupt as interrupt4 } from "@langchain/langgraph";
42299
40758
 
42300
40759
  // src/util/truncateForJson.ts
@@ -43176,73 +41635,73 @@ function buildReviewMarkdown(task) {
43176
41635
  result: task.result
43177
41636
  });
43178
41637
  }
43179
- var manageTaskSchema = z73.object({
43180
- action: z73.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."),
43181
- id: z73.string().optional().describe("Task ID (required for get, update, add_activity; required for delete unless ids is given)"),
43182
- title: z73.string().optional().describe("Task title (required for create)"),
43183
- description: z73.string().optional().describe("Task description in Markdown"),
43184
- priority: z73.enum(["low", "medium", "high"]).optional().describe("Priority level"),
43185
- status: z73.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"),
43186
- dueDate: z73.string().optional().describe("Due date (ISO 8601 format)"),
43187
- metadata: z73.record(z73.unknown()).optional().describe("Structured metadata (e.g. projectId, module)"),
43188
- metadataFilter: z73.record(
43189
- z73.union([z73.string(), z73.number(), z73.boolean()])
41638
+ var manageTaskSchema = z70.object({
41639
+ action: z70.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."),
41640
+ id: z70.string().optional().describe("Task ID (required for get, update, add_activity; required for delete unless ids is given)"),
41641
+ title: z70.string().optional().describe("Task title (required for create)"),
41642
+ description: z70.string().optional().describe("Task description in Markdown"),
41643
+ priority: z70.enum(["low", "medium", "high"]).optional().describe("Priority level"),
41644
+ status: z70.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"),
41645
+ dueDate: z70.string().optional().describe("Due date (ISO 8601 format)"),
41646
+ metadata: z70.record(z70.unknown()).optional().describe("Structured metadata (e.g. projectId, module)"),
41647
+ metadataFilter: z70.record(
41648
+ z70.union([z70.string(), z70.number(), z70.boolean()])
43190
41649
  ).optional().describe("List-only filter. Every key must equal the task metadata value, e.g. {projectId:'p1', retries:2}. Multiple keys AND together."),
43191
- parentId: z73.string().optional().describe("Parent task ID for grouping subtasks"),
43192
- sourceId: z73.string().optional().describe("Source session/thread ID"),
43193
- context: z73.record(z73.unknown()).optional().describe("Additional context data"),
43194
- ownerType: z73.enum(["user", "agent"]).optional().describe("Owner type. Defaults to 'user' if omitted"),
43195
- ownerId: z73.string().optional().describe("Owner ID. Auto-filled from current user/agent if omitted"),
43196
- requireReview: z73.boolean().optional().describe("If true, agent completion pauses as interrupted(review_required) for HITL approval"),
43197
- dependencies: z73.array(z73.string()).optional().describe("List of task IDs that must be completed before this task can start"),
43198
- dependencyTaskIds: z73.array(z73.string().trim().min(1)).optional().describe("Exact blocking task IDs required for an external_dependency interruption"),
43199
- result: z73.string().optional().describe("Result summary. Used with set_status status='completed' or update status='completed'"),
43200
- failureReason: z73.string().optional().describe("Failure reason. Used with set_status status='failed' or update status='failed'"),
43201
- files: z73.array(z73.object({
43202
- uri: z73.string().describe("Uniquely locates the resource: http(s):// URL, /s/:token share, or sandbox path"),
43203
- name: z73.string().optional().describe("Display name"),
43204
- addedBy: z73.enum(["user", "agent"]).optional().describe("Who attached the file")
41650
+ parentId: z70.string().optional().describe("Parent task ID for grouping subtasks"),
41651
+ sourceId: z70.string().optional().describe("Source session/thread ID"),
41652
+ context: z70.record(z70.unknown()).optional().describe("Additional context data"),
41653
+ ownerType: z70.enum(["user", "agent"]).optional().describe("Owner type. Defaults to 'user' if omitted"),
41654
+ ownerId: z70.string().optional().describe("Owner ID. Auto-filled from current user/agent if omitted"),
41655
+ requireReview: z70.boolean().optional().describe("If true, agent completion pauses as interrupted(review_required) for HITL approval"),
41656
+ dependencies: z70.array(z70.string()).optional().describe("List of task IDs that must be completed before this task can start"),
41657
+ dependencyTaskIds: z70.array(z70.string().trim().min(1)).optional().describe("Exact blocking task IDs required for an external_dependency interruption"),
41658
+ result: z70.string().optional().describe("Result summary. Used with set_status status='completed' or update status='completed'"),
41659
+ failureReason: z70.string().optional().describe("Failure reason. Used with set_status status='failed' or update status='failed'"),
41660
+ files: z70.array(z70.object({
41661
+ uri: z70.string().describe("Uniquely locates the resource: http(s):// URL, /s/:token share, or sandbox path"),
41662
+ name: z70.string().optional().describe("Display name"),
41663
+ addedBy: z70.enum(["user", "agent"]).optional().describe("Who attached the file")
43205
41664
  })).optional().describe("File references attached to this task"),
43206
- beliefImpact: z73.array(z73.object({
43207
- key: z73.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
43208
- after: z73.number().int().min(0).max(100),
43209
- basis: z73.string().trim().min(1).max(1e3),
43210
- isNew: z73.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")
41665
+ beliefImpact: z70.array(z70.object({
41666
+ key: z70.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
41667
+ after: z70.number().int().min(0).max(100),
41668
+ basis: z70.string().trim().min(1).max(1e3),
41669
+ isNew: z70.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")
43211
41670
  })).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"),
43212
- content: z73.string().optional().describe("Markdown content required for add_activity"),
43213
- summary: z73.string().optional().describe("Brief summary of the operation"),
43214
- executionResultId: z73.string().refine(isExecutionResultEventKey3, {
41671
+ content: z70.string().optional().describe("Markdown content required for add_activity"),
41672
+ summary: z70.string().optional().describe("Brief summary of the operation"),
41673
+ executionResultId: z70.string().refine(isExecutionResultEventKey3, {
43215
41674
  message: "executionResultId must be the execution-result:<threadId> event key returned by task()"
43216
41675
  }).optional().describe(
43217
41676
  "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"
43218
41677
  ),
43219
- ids: z73.array(z73.string().trim().min(1)).optional().describe("Task IDs to delete in one batch (delete action only). Use with or instead of id.")
41678
+ ids: z70.array(z70.string().trim().min(1)).optional().describe("Task IDs to delete in one batch (delete action only). Use with or instead of id.")
43220
41679
  }).superRefine((input, context) => {
43221
41680
  if (input.executionResultId && input.action !== "update" && input.action !== "set_status" && input.action !== "add_activity") {
43222
41681
  context.addIssue({
43223
- code: z73.ZodIssueCode.custom,
41682
+ code: z70.ZodIssueCode.custom,
43224
41683
  path: ["executionResultId"],
43225
41684
  message: "executionResultId is valid only for update, set_status, or add_activity"
43226
41685
  });
43227
41686
  }
43228
41687
  if (input.metadataFilter && input.action !== "list") {
43229
41688
  context.addIssue({
43230
- code: z73.ZodIssueCode.custom,
41689
+ code: z70.ZodIssueCode.custom,
43231
41690
  path: ["metadataFilter"],
43232
41691
  message: "metadataFilter is valid only for list"
43233
41692
  });
43234
41693
  }
43235
41694
  if (input.ids && input.action !== "delete") {
43236
41695
  context.addIssue({
43237
- code: z73.ZodIssueCode.custom,
41696
+ code: z70.ZodIssueCode.custom,
43238
41697
  path: ["ids"],
43239
41698
  message: "ids is valid only for delete"
43240
41699
  });
43241
41700
  }
43242
41701
  });
43243
- var startTaskSchema = z73.object({
43244
- taskId: z73.string().trim().min(1).describe("ID of the persisted TaskItem to start"),
43245
- agentId: z73.string().trim().min(1).describe(
41702
+ var startTaskSchema = z70.object({
41703
+ taskId: z70.string().trim().min(1).describe("ID of the persisted TaskItem to start"),
41704
+ agentId: z70.string().trim().min(1).describe(
43246
41705
  `ID of the Agent that should execute the task. Use "general-purpose" to run the caller's own capabilities as an isolated worker.`
43247
41706
  )
43248
41707
  });
@@ -44617,12 +43076,12 @@ function createTaskMiddleware(options = {}) {
44617
43076
  ...trustedCaller ? { callerMembershipId: trustedCaller.membershipId, callerAssistantId: trustedCaller.assistantId } : {}
44618
43077
  }));
44619
43078
  };
44620
- return createMiddleware24({
43079
+ return createMiddleware23({
44621
43080
  name: "TaskMiddleware",
44622
43081
  contextSchema,
44623
43082
  // Persisted between invocations (ADRs: the run↔task binding survives turns).
44624
- stateSchema: z73.object({
44625
- taskId: z73.string().default("")
43083
+ stateSchema: z70.object({
43084
+ taskId: z70.string().default("")
44626
43085
  }),
44627
43086
  // CLAIM: a run that holds a task moves it to in_progress (idempotent).
44628
43087
  beforeAgent: async (state, runtime) => {
@@ -44732,7 +43191,7 @@ ${TASK_CONVERGENCE_GUIDANCE}
44732
43191
  });
44733
43192
  },
44734
43193
  tools: [
44735
- tool67(
43194
+ tool64(
44736
43195
  handleManageTask,
44737
43196
  {
44738
43197
  name: "manage_task",
@@ -44778,7 +43237,7 @@ to an expert \u2014 never re-dispatch the task you are processing.`,
44778
43237
  schema: manageTaskSchema
44779
43238
  }
44780
43239
  ),
44781
- tool67(handleStartTask, {
43240
+ tool64(handleStartTask, {
44782
43241
  name: "task",
44783
43242
  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.`,
44784
43243
  schema: startTaskSchema
@@ -44922,8 +43381,8 @@ canonical Belief State:
44922
43381
  };
44923
43382
 
44924
43383
  // src/middlewares/documentLearningMiddleware.ts
44925
- import { AgentType as AgentType10 } from "@axiom-lattice/protocols";
44926
- import { createMiddleware as createMiddleware25 } from "langchain";
43384
+ import { AgentType as AgentType9 } from "@axiom-lattice/protocols";
43385
+ import { createMiddleware as createMiddleware24 } from "langchain";
44927
43386
 
44928
43387
  // src/middlewares/documentLearningSkills.ts
44929
43388
  var LEARN_CAPABILITY_SKILL = `---
@@ -45162,7 +43621,7 @@ patterns discovered, recommendations. Include validation coverage: user-sample N
45162
43621
  `;
45163
43622
 
45164
43623
  // src/middlewares/documentLearningMiddleware.ts
45165
- var createDocumentLearningMiddleware = () => createMiddleware25({
43624
+ var createDocumentLearningMiddleware = () => createMiddleware24({
45166
43625
  name: "DocumentLearningMiddleware",
45167
43626
  contextSchema,
45168
43627
  tools: []
@@ -45189,7 +43648,7 @@ var documentLearningPlugin = {
45189
43648
  key: "document-learner",
45190
43649
  name: "Document Learning Agent",
45191
43650
  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.",
45192
- type: AgentType10.DEEP_AGENT,
43651
+ type: AgentType9.DEEP_AGENT,
45193
43652
  prompt: DOCUMENT_LEARNER_SYSTEM_PROMPT,
45194
43653
  subAgents: ["document-parser-benchmark"],
45195
43654
  tools: [
@@ -45280,12 +43739,12 @@ var documentLearningPlugin = {
45280
43739
  };
45281
43740
 
45282
43741
  // src/middlewares/documentParserMiddleware.ts
45283
- import { createMiddleware as createMiddleware26 } from "langchain";
43742
+ import { createMiddleware as createMiddleware25 } from "langchain";
45284
43743
 
45285
43744
  // src/tool_lattice/document_parser/index.ts
45286
43745
  import * as path7 from "path";
45287
- import z74 from "zod";
45288
- import { tool as tool68 } from "langchain";
43746
+ import z71 from "zod";
43747
+ import { tool as tool65 } from "langchain";
45289
43748
  var PARSE_DOCUMENT_DESCRIPTION = `Parse a document file (docx, pdf) into structured Markdown using a remote document parsing service.
45290
43749
  This tool handles the full pipeline internally: file upload \u2192 document parsing \u2192 polling until complete \u2192 download result \u2192 save to filesystem.
45291
43750
 
@@ -45408,7 +43867,7 @@ function createParseDocumentTool({
45408
43867
  baseUrl = "",
45409
43868
  apiKey = ""
45410
43869
  }) {
45411
- return tool68(
43870
+ return tool65(
45412
43871
  async (input, exe_config) => {
45413
43872
  try {
45414
43873
  const runConfig = exe_config?.configurable?.runConfig ?? { assistant_id: "", thread_id: "" };
@@ -45479,17 +43938,17 @@ function createParseDocumentTool({
45479
43938
  {
45480
43939
  name: "parse_document",
45481
43940
  description: PARSE_DOCUMENT_DESCRIPTION,
45482
- schema: z74.object({
45483
- file_path: z74.string().describe(
43941
+ schema: z71.object({
43942
+ file_path: z71.string().describe(
45484
43943
  '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.'
45485
43944
  ),
45486
- engine: z74.string().describe(
43945
+ engine: z71.string().describe(
45487
43946
  '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).'
45488
43947
  ),
45489
- output_path: z74.string().optional().describe(
43948
+ output_path: z71.string().optional().describe(
45490
43949
  '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.'
45491
43950
  ),
45492
- output_format: z74.enum(["markdown", "json"]).optional().default("markdown").describe(
43951
+ output_format: z71.enum(["markdown", "json"]).optional().default("markdown").describe(
45493
43952
  'Output format. "markdown": structured Markdown with tables, headers, formatting preserved (recommended). "json": raw JSON output from the parsing engine (for programmatic use).'
45494
43953
  )
45495
43954
  })
@@ -45498,7 +43957,7 @@ function createParseDocumentTool({
45498
43957
  }
45499
43958
 
45500
43959
  // src/middlewares/documentParserMiddleware.ts
45501
- import { AgentType as AgentType11 } from "@axiom-lattice/protocols";
43960
+ import { AgentType as AgentType10 } from "@axiom-lattice/protocols";
45502
43961
 
45503
43962
  // src/middlewares/documentBenchmarkWorkflow.ts
45504
43963
  var DOCUMENT_PARSER_BENCHMARK_YAML = `name: document-parser-benchmark
@@ -45907,7 +44366,7 @@ def main() -> None:
45907
44366
  if __name__ == "__main__":
45908
44367
  main()
45909
44368
  `;
45910
- var resources2 = {
44369
+ var resources = {
45911
44370
  "references/api_reference.md": { mimeType: "text/markdown", content: `# API reference
45912
44371
 
45913
44372
  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.` },
@@ -45936,7 +44395,7 @@ Single file: 'markitdown input -o output.md'. Ordinary directory: 'scripts/batch
45936
44395
  var DOCUMENT_PARSER_MARKITDOWN_SKILL = {
45937
44396
  version: "1.1.0",
45938
44397
  content: MARKITDOWN_SKILL_CONTENT,
45939
- resources: resources2
44398
+ resources
45940
44399
  };
45941
44400
 
45942
44401
  // src/middlewares/documentParserMiddleware.ts
@@ -45945,7 +44404,7 @@ function createDocumentParserMiddleware(config) {
45945
44404
  const baseUrl = config.baseUrl || "";
45946
44405
  const apiKey = config.apiKey || "";
45947
44406
  const connections = Array.isArray(config.connections) ? config.connections.filter((key5) => typeof key5 === "string") : [];
45948
- return createMiddleware26({
44407
+ return createMiddleware25({
45949
44408
  name: "DocumentParser",
45950
44409
  contextSchema,
45951
44410
  tools: [createParseDocumentTool({ connectAll, connections, baseUrl, apiKey })]
@@ -46023,7 +44482,7 @@ var documentParserPlugin = {
46023
44482
  agents: {
46024
44483
  "document-parser-benchmark": {
46025
44484
  key: "document-parser-benchmark",
46026
- type: AgentType11.WORKFLOW,
44485
+ type: AgentType10.WORKFLOW,
46027
44486
  name: "Document Parser Benchmark",
46028
44487
  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.",
46029
44488
  prompt: "Benchmark document parsing engines: parse with 5 engines, score, and rank results.",
@@ -46066,8 +44525,8 @@ import {
46066
44525
  snapshotExactArray as snapshotExactArray3,
46067
44526
  snapshotExactRecord as snapshotExactRecord8
46068
44527
  } from "@axiom-lattice/protocols";
46069
- import { createMiddleware as createMiddleware27, tool as tool69 } from "langchain";
46070
- import { z as z75 } from "zod";
44528
+ import { createMiddleware as createMiddleware26, tool as tool66 } from "langchain";
44529
+ import { z as z72 } from "zod";
46071
44530
  var PROJECT_ROOM_CONTEXT_REQUIRED = "PROJECT_ROOM_CONTEXT_REQUIRED";
46072
44531
  var PROJECT_ROOM_POST_FAILED = "PROJECT_ROOM_POST_FAILED";
46073
44532
  var PROJECT_ROOM_ROSTER_FAILED = "PROJECT_ROOM_ROSTER_FAILED";
@@ -46087,10 +44546,10 @@ var ROSTER_FAILED = JSON.stringify({
46087
44546
  error: PROJECT_ROOM_ROSTER_FAILED,
46088
44547
  message: PROJECT_ROOM_ROSTER_FAILED_MESSAGE
46089
44548
  });
46090
- var postSchema = z75.object({
46091
- text: z75.string().trim().min(1).max(2e4)
44549
+ var postSchema = z72.object({
44550
+ text: z72.string().trim().min(1).max(2e4)
46092
44551
  }).strict();
46093
- var listSchema = z75.object({}).strict();
44552
+ var listSchema = z72.object({}).strict();
46094
44553
  function ownDataValue2(record, key5) {
46095
44554
  if (typeof record !== "object" || record === null || Array.isArray(record)) return void 0;
46096
44555
  try {
@@ -46157,10 +44616,10 @@ async function hasActiveCurrentMembership(scope) {
46157
44616
  return true;
46158
44617
  }
46159
44618
  function createProjectRoomMiddleware() {
46160
- return createMiddleware27({
44619
+ return createMiddleware26({
46161
44620
  name: "ProjectRoomMiddleware",
46162
44621
  tools: [
46163
- tool69(async (input, config) => {
44622
+ tool66(async (input, config) => {
46164
44623
  const { text } = input;
46165
44624
  const scope = readTrustedRoomScope(config);
46166
44625
  if (!scope) return CONTEXT_REQUIRED;
@@ -46191,7 +44650,7 @@ function createProjectRoomMiddleware() {
46191
44650
  description: "Post a text reply to the current trusted Project Room message",
46192
44651
  schema: postSchema
46193
44652
  }),
46194
- tool69(async (_input, config) => {
44653
+ tool66(async (_input, config) => {
46195
44654
  const scope = readTrustedRoomScope(config);
46196
44655
  if (!scope) return CONTEXT_REQUIRED;
46197
44656
  try {
@@ -46233,9 +44692,9 @@ var projectRoomPlugin = {
46233
44692
  };
46234
44693
 
46235
44694
  // src/middlewares/sandboxPluginsMiddleware.ts
46236
- import { createMiddleware as createMiddleware28, tool as tool70 } from "langchain";
46237
- import { z as z76 } from "zod";
46238
- import { AgentType as AgentType12 } from "@axiom-lattice/protocols";
44695
+ import { createMiddleware as createMiddleware27, tool as tool67 } from "langchain";
44696
+ import { z as z73 } from "zod";
44697
+ import { AgentType as AgentType11 } from "@axiom-lattice/protocols";
46239
44698
 
46240
44699
  // src/middlewares/sandboxPluginsSkills.ts
46241
44700
  var PLUGIN_JSON_TEMPLATE = `{
@@ -46956,16 +45415,16 @@ function tenantIdFrom(exeConfig) {
46956
45415
  const c = exeConfig;
46957
45416
  return c?.configurable?.runConfig?.tenantId ?? "default";
46958
45417
  }
46959
- var managePluginSchema = z76.object({
46960
- action: z76.enum(["list", "get", "validate", "create", "update", "delete", "reload", "test"]),
46961
- type: z76.string().optional(),
46962
- manifest: z76.record(z76.unknown()).optional(),
46963
- handlers: z76.record(z76.string()).optional(),
46964
- target: z76.object({
46965
- kind: z76.enum(["tool", "connection-test", "connection-discover"]),
46966
- name: z76.string().optional(),
46967
- input: z76.unknown().optional(),
46968
- connectionKey: z76.string().optional()
45418
+ var managePluginSchema = z73.object({
45419
+ action: z73.enum(["list", "get", "validate", "create", "update", "delete", "reload", "test"]),
45420
+ type: z73.string().optional(),
45421
+ manifest: z73.record(z73.unknown()).optional(),
45422
+ handlers: z73.record(z73.string()).optional(),
45423
+ target: z73.object({
45424
+ kind: z73.enum(["tool", "connection-test", "connection-discover"]),
45425
+ name: z73.string().optional(),
45426
+ input: z73.unknown().optional(),
45427
+ connectionKey: z73.string().optional()
46969
45428
  }).optional()
46970
45429
  });
46971
45430
  var sandboxPluginsPlugin = {
@@ -46985,7 +45444,7 @@ var sandboxPluginsPlugin = {
46985
45444
  key: "plugin-builder",
46986
45445
  name: "Plugin Builder",
46987
45446
  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.",
46988
- type: AgentType12.DEEP_AGENT,
45447
+ type: AgentType11.DEEP_AGENT,
46989
45448
  prompt: PLUGIN_BUILDER_PROMPT,
46990
45449
  middleware: [
46991
45450
  {
@@ -47039,10 +45498,10 @@ var sandboxPluginsPlugin = {
47039
45498
  ]
47040
45499
  }
47041
45500
  },
47042
- middleware: () => createMiddleware28({
45501
+ middleware: () => createMiddleware27({
47043
45502
  name: "SandboxPluginsMiddleware",
47044
45503
  tools: [
47045
- tool70(
45504
+ tool67(
47046
45505
  async (input, exeConfig) => {
47047
45506
  const tenantId2 = tenantIdFrom(exeConfig);
47048
45507
  const catalog2 = getSandboxPluginCatalog();
@@ -47183,7 +45642,6 @@ var BUILTIN_PLUGINS = [
47183
45642
  sqlPlugin,
47184
45643
  skillPlugin,
47185
45644
  metricsPlugin,
47186
- semanticMetricsPlugin,
47187
45645
  askUserClarifyPlugin,
47188
45646
  widgetPlugin,
47189
45647
  clawPlugin,
@@ -47815,7 +46273,6 @@ export {
47815
46273
  createSandboxProvider,
47816
46274
  createSandboxResolver,
47817
46275
  createSchedulerMiddleware,
47818
- createSemanticMetricsMiddleware,
47819
46276
  createSharePayload,
47820
46277
  createTaskExecutionService,
47821
46278
  createTaskLifecycleService,
@@ -47974,7 +46431,6 @@ export {
47974
46431
  sandboxLatticeManager,
47975
46432
  sanitizeToolCallId,
47976
46433
  scheduleLatticeManager,
47977
- semanticMetricsPlugin,
47978
46434
  serializePluginMeta,
47979
46435
  serializeTaskMutationSuccess,
47980
46436
  serializeTaskNormalizationFallback,