@axiom-lattice/core 2.1.36 → 2.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -400,6 +400,7 @@ declare class SqlDatabaseManager {
400
400
  private static instance;
401
401
  private databases;
402
402
  private defaultDatabaseKeys;
403
+ private configStore;
403
404
  private constructor();
404
405
  /**
405
406
  * Get the singleton instance
@@ -422,14 +423,20 @@ declare class SqlDatabaseManager {
422
423
  * @param key - Database key to set as default
423
424
  */
424
425
  setDefaultDatabase(tenantId: string, key: string): void;
426
+ /**
427
+ * Set the configuration store for on-demand database loading
428
+ * @param store - The database configuration store
429
+ */
430
+ setConfigStore(store: _axiom_lattice_protocols.DatabaseConfigStore): void;
425
431
  /**
426
432
  * Get a database by key for a specific tenant
433
+ * If database is not registered and configStore is set, will try to load from store
427
434
  * @param tenantId - Tenant identifier (required)
428
435
  * @param key - Database key (optional, uses default if not provided)
429
436
  * @returns ISqlDatabase instance
430
437
  * @throws Error if tenant or database not found
431
438
  */
432
- getDatabase(tenantId: string, key?: string): ISqlDatabase;
439
+ getDatabase(tenantId: string, key?: string): Promise<ISqlDatabase>;
433
440
  /**
434
441
  * Check if a database is registered for a tenant
435
442
  * @param tenantId - Tenant identifier
package/dist/index.d.ts CHANGED
@@ -400,6 +400,7 @@ declare class SqlDatabaseManager {
400
400
  private static instance;
401
401
  private databases;
402
402
  private defaultDatabaseKeys;
403
+ private configStore;
403
404
  private constructor();
404
405
  /**
405
406
  * Get the singleton instance
@@ -422,14 +423,20 @@ declare class SqlDatabaseManager {
422
423
  * @param key - Database key to set as default
423
424
  */
424
425
  setDefaultDatabase(tenantId: string, key: string): void;
426
+ /**
427
+ * Set the configuration store for on-demand database loading
428
+ * @param store - The database configuration store
429
+ */
430
+ setConfigStore(store: _axiom_lattice_protocols.DatabaseConfigStore): void;
425
431
  /**
426
432
  * Get a database by key for a specific tenant
433
+ * If database is not registered and configStore is set, will try to load from store
427
434
  * @param tenantId - Tenant identifier (required)
428
435
  * @param key - Database key (optional, uses default if not provided)
429
436
  * @returns ISqlDatabase instance
430
437
  * @throws Error if tenant or database not found
431
438
  */
432
- getDatabase(tenantId: string, key?: string): ISqlDatabase;
439
+ getDatabase(tenantId: string, key?: string): Promise<ISqlDatabase>;
433
440
  /**
434
441
  * Check if a database is registered for a tenant
435
442
  * @param tenantId - Tenant identifier
package/dist/index.js CHANGED
@@ -1081,6 +1081,7 @@ var SqlDatabaseManager = class _SqlDatabaseManager {
1081
1081
  constructor() {
1082
1082
  this.databases = /* @__PURE__ */ new Map();
1083
1083
  this.defaultDatabaseKeys = /* @__PURE__ */ new Map();
1084
+ this.configStore = null;
1084
1085
  }
1085
1086
  /**
1086
1087
  * Get the singleton instance
@@ -1139,27 +1140,53 @@ var SqlDatabaseManager = class _SqlDatabaseManager {
1139
1140
  }
1140
1141
  this.defaultDatabaseKeys.set(tenantId, key);
1141
1142
  }
1143
+ /**
1144
+ * Set the configuration store for on-demand database loading
1145
+ * @param store - The database configuration store
1146
+ */
1147
+ setConfigStore(store) {
1148
+ this.configStore = store;
1149
+ }
1142
1150
  /**
1143
1151
  * Get a database by key for a specific tenant
1152
+ * If database is not registered and configStore is set, will try to load from store
1144
1153
  * @param tenantId - Tenant identifier (required)
1145
1154
  * @param key - Database key (optional, uses default if not provided)
1146
1155
  * @returns ISqlDatabase instance
1147
1156
  * @throws Error if tenant or database not found
1148
1157
  */
1149
- getDatabase(tenantId, key) {
1158
+ async getDatabase(tenantId, key) {
1150
1159
  const tenantDbs = this.databases.get(tenantId);
1151
- if (!tenantDbs) {
1152
- throw new Error(`No databases registered for tenant '${tenantId}'`);
1153
- }
1154
1160
  const dbKey = key || this.defaultDatabaseKeys.get(tenantId);
1155
1161
  if (!dbKey) {
1156
1162
  throw new Error(`No default database set for tenant '${tenantId}'`);
1157
1163
  }
1158
- const database = tenantDbs.get(dbKey);
1159
- if (!database) {
1160
- throw new Error(`Database '${dbKey}' not found for tenant '${tenantId}'`);
1164
+ if (tenantDbs) {
1165
+ const database = tenantDbs.get(dbKey);
1166
+ if (database) {
1167
+ return database;
1168
+ }
1169
+ }
1170
+ if (this.configStore) {
1171
+ const configEntry = await this.configStore.getConfigByKey(tenantId, dbKey);
1172
+ if (configEntry) {
1173
+ this.registerDatabase(tenantId, dbKey, configEntry.config);
1174
+ if (!this.defaultDatabaseKeys.has(tenantId)) {
1175
+ this.defaultDatabaseKeys.set(tenantId, dbKey);
1176
+ }
1177
+ const newTenantDbs = this.databases.get(tenantId);
1178
+ if (newTenantDbs) {
1179
+ const database = newTenantDbs.get(dbKey);
1180
+ if (database) {
1181
+ return database;
1182
+ }
1183
+ }
1184
+ }
1185
+ }
1186
+ if (!tenantDbs) {
1187
+ throw new Error(`No databases registered for tenant '${tenantId}'`);
1161
1188
  }
1162
- return database;
1189
+ throw new Error(`Database '${dbKey}' not found for tenant '${tenantId}'`);
1163
1190
  }
1164
1191
  /**
1165
1192
  * Check if a database is registered for a tenant
@@ -1298,7 +1325,7 @@ ${databaseKeys.map(
1298
1325
  if (!databaseKeys.includes(databaseKey)) {
1299
1326
  return `Error: databaseKey "${databaseKey}" is not in the allowed list: [${databaseKeys.join(", ")}]`;
1300
1327
  }
1301
- const database = sqlDatabaseManager.getDatabase(databaseKey, tenantId);
1328
+ const database = await sqlDatabaseManager.getDatabase(tenantId, databaseKey);
1302
1329
  const tables = await database.listTables();
1303
1330
  if (tables.length === 0) {
1304
1331
  return "No tables found in the database.";
@@ -1345,7 +1372,7 @@ ${databaseKeys.map(
1345
1372
  if (!databaseKeys.includes(databaseKey)) {
1346
1373
  return `Error: databaseKey "${databaseKey}" is not in the allowed list: [${databaseKeys.join(", ")}]`;
1347
1374
  }
1348
- const database = sqlDatabaseManager.getDatabase(databaseKey, tenantId);
1375
+ const database = await sqlDatabaseManager.getDatabase(tenantId, databaseKey);
1349
1376
  const tableNames = tables.split(",").map((t) => t.trim()).filter((t) => t.length > 0);
1350
1377
  if (tableNames.length === 0) {
1351
1378
  return "Error: No table names provided. Please provide a comma-separated list of table names.";
@@ -1502,7 +1529,7 @@ ${trimmedQuery}
1502
1529
  }
1503
1530
  if (databaseKey && databaseKeys.includes(databaseKey)) {
1504
1531
  try {
1505
- const database = sqlDatabaseManager.getDatabase(databaseKey, tenantId);
1532
+ const database = await sqlDatabaseManager.getDatabase(tenantId, databaseKey);
1506
1533
  const dbType = database.getDatabaseType();
1507
1534
  if (dbType === "postgres") {
1508
1535
  try {
@@ -1603,7 +1630,7 @@ ${databaseKeys.map(
1603
1630
  if (!trimmedQuery) {
1604
1631
  return "Error: Empty query provided. Please provide a valid SQL query.";
1605
1632
  }
1606
- const database = sqlDatabaseManager.getDatabase(databaseKey, tenantId);
1633
+ const database = await sqlDatabaseManager.getDatabase(tenantId, databaseKey);
1607
1634
  const result = await database.executeQuery(trimmedQuery);
1608
1635
  return formatQueryResult(result.rows, result.fields);
1609
1636
  } catch (error) {
@@ -5064,11 +5091,20 @@ var SandboxFilesystem = class {
5064
5091
 
5065
5092
  // src/middlewares/codeEvalMiddleware.ts
5066
5093
  var import_langchain37 = require("langchain");
5094
+
5095
+ // src/middlewares/contextSchema.ts
5096
+ var import_zod41 = __toESM(require("zod"));
5097
+ var contextSchema = import_zod41.default.object({
5098
+ runConfig: import_zod41.default.any()
5099
+ });
5100
+
5101
+ // src/middlewares/codeEvalMiddleware.ts
5067
5102
  function createCodeEvalMiddleware(params = { isolatedLevel: "global" }) {
5068
5103
  const codeEvalTool = createCodeEvalTool({ isolatedLevel: params.isolatedLevel });
5069
5104
  const codeExecuteFileTool = createCodeExecuteFileTool({ isolatedLevel: params.isolatedLevel });
5070
5105
  return (0, import_langchain37.createMiddleware)({
5071
5106
  name: "codeEvalMiddleware",
5107
+ contextSchema,
5072
5108
  tools: [codeEvalTool, codeExecuteFileTool, getToolClient("convert_to_markdown")]
5073
5109
  });
5074
5110
  }
@@ -5103,6 +5139,7 @@ function createBrowserMiddleware(params = { isolatedLevel: "global" }) {
5103
5139
  ];
5104
5140
  return (0, import_langchain38.createMiddleware)({
5105
5141
  name: "browserMiddleware",
5142
+ contextSchema,
5106
5143
  tools
5107
5144
  });
5108
5145
  }
@@ -5123,6 +5160,7 @@ function createSqlMiddleware(params) {
5123
5160
  };
5124
5161
  return (0, import_langchain39.createMiddleware)({
5125
5162
  name: "sqlMiddleware",
5163
+ contextSchema,
5126
5164
  tools: [
5127
5165
  createListTablesSqlTool(toolParams),
5128
5166
  createInfoSqlTool(toolParams),
@@ -7142,11 +7180,11 @@ ${body}` : `${frontmatter}
7142
7180
  };
7143
7181
 
7144
7182
  // src/tool_lattice/skill/load_skills.ts
7145
- var import_zod41 = __toESM(require("zod"));
7183
+ var import_zod42 = __toESM(require("zod"));
7146
7184
  var import_langchain40 = require("langchain");
7147
7185
 
7148
7186
  // src/tool_lattice/skill/load_skill_content.ts
7149
- var import_zod42 = __toESM(require("zod"));
7187
+ var import_zod43 = __toESM(require("zod"));
7150
7188
  var import_langchain41 = require("langchain");
7151
7189
  var LOAD_SKILL_CONTENT_DESCRIPTION = `
7152
7190
  Execute a skill within the main conversation
@@ -7233,15 +7271,15 @@ ${content}`;
7233
7271
  {
7234
7272
  name: "skill",
7235
7273
  description: LOAD_SKILL_CONTENT_DESCRIPTION,
7236
- schema: import_zod42.default.object({
7237
- skill_name: import_zod42.default.string().describe("The name of the skill to load")
7274
+ schema: import_zod43.default.object({
7275
+ skill_name: import_zod43.default.string().describe("The name of the skill to load")
7238
7276
  })
7239
7277
  }
7240
7278
  );
7241
7279
  };
7242
7280
 
7243
7281
  // src/tool_lattice/skill/load_skill_resource.ts
7244
- var import_zod43 = __toESM(require("zod"));
7282
+ var import_zod44 = __toESM(require("zod"));
7245
7283
  var import_langchain42 = require("langchain");
7246
7284
  var LOAD_SKILL_RESOURCE_DESCRIPTION = `Load a specific resource file from a skill's resources directory. Use this tool when you need to access template files, example data, or other resources bundled with a skill. The resource paths are listed in the skill content when using the load_skill_content tool.`;
7247
7285
  var createLoadSkillResourceTool = () => {
@@ -7267,9 +7305,9 @@ var createLoadSkillResourceTool = () => {
7267
7305
  {
7268
7306
  name: "load_skill_resource",
7269
7307
  description: LOAD_SKILL_RESOURCE_DESCRIPTION,
7270
- schema: import_zod43.default.object({
7271
- skill_name: import_zod43.default.string().describe("The name of the skill containing the resource"),
7272
- resource_path: import_zod43.default.string().describe("The path to the resource relative to the skill's resources/ directory")
7308
+ schema: import_zod44.default.object({
7309
+ skill_name: import_zod44.default.string().describe("The name of the skill containing the resource"),
7310
+ resource_path: import_zod44.default.string().describe("The path to the resource relative to the skill's resources/ directory")
7273
7311
  })
7274
7312
  }
7275
7313
  );
@@ -7284,6 +7322,7 @@ function createSkillMiddleware(params = {}) {
7284
7322
  let latestSkills = [];
7285
7323
  return (0, import_langchain43.createMiddleware)({
7286
7324
  name: "skillMiddleware",
7325
+ contextSchema,
7287
7326
  tools: [
7288
7327
  // createLoadSkillsTool({ skills: readAll ? undefined : skills }),
7289
7328
  createLoadSkillContentTool(),
@@ -7291,25 +7330,28 @@ function createSkillMiddleware(params = {}) {
7291
7330
  ],
7292
7331
  beforeAgent: async (state, runtime) => {
7293
7332
  try {
7333
+ console.log("latestSkills_before", latestSkills);
7294
7334
  const storeLattice = getStoreLattice("default", "skill");
7295
7335
  const skillStore = storeLattice?.store;
7296
- const tenantId = runtime?.context?.tenantId || state?.tenantId || "default";
7336
+ const tenantId = runtime?.context?.runConfig?.tenantId;
7337
+ if (!tenantId) {
7338
+ throw new Error("tenantId is missing");
7339
+ }
7297
7340
  if (readAll) {
7298
- latestSkills = await skillStore.getAllSkills(tenantId);
7341
+ const allSkills = await skillStore.getAllSkills(tenantId);
7342
+ latestSkills = allSkills.filter((skill) => skill !== void 0 && skill !== null);
7299
7343
  } else if (skills && skills.length > 0) {
7300
- const skillLatticePromises = skills.map(
7301
- (skillId) => skillStore.getSkillById(tenantId, skillId)
7302
- );
7303
- const skillLattices = await Promise.all(skillLatticePromises);
7304
- latestSkills = skillLattices.filter((skill) => skill !== void 0);
7344
+ const allSkills = await skillStore.getAllSkills(tenantId);
7345
+ latestSkills = allSkills.filter((skill) => skills.includes(skill.id));
7305
7346
  }
7306
7347
  } catch (error) {
7307
7348
  console.error("Error fetching skills:", error);
7308
7349
  }
7309
7350
  },
7310
7351
  wrapModelCall: (request, handler) => {
7311
- const skillsPrompt = latestSkills.map((skill) => `## ${skill.name}
7312
- ${skill.description}`).join("\n");
7352
+ console.log("latestSkills_after", latestSkills);
7353
+ const skillsPrompt = latestSkills.filter((skill) => skill !== void 0 && skill !== null && !!skill.name).map((skill) => `## ${skill.name}
7354
+ ${skill.description || ""}`).join("\n");
7313
7355
  const skillsAddendum = `
7314
7356
 
7315
7357
  <available_skills>
@@ -7331,7 +7373,7 @@ ${skillsPrompt}
7331
7373
  var import_langchain44 = require("langchain");
7332
7374
  var import_langgraph4 = require("@langchain/langgraph");
7333
7375
  var import_v3 = require("zod/v3");
7334
- var import_zod44 = require("@langchain/langgraph/zod");
7376
+ var import_zod45 = require("@langchain/langgraph/zod");
7335
7377
 
7336
7378
  // src/deep_agent_new/backends/utils.ts
7337
7379
  var import_micromatch = __toESM(require("micromatch"));
@@ -7795,7 +7837,7 @@ function fileDataReducer(left, right) {
7795
7837
  return result;
7796
7838
  }
7797
7839
  var FilesystemStateSchema = import_v3.z.object({
7798
- files: (0, import_zod44.withLangGraph)(
7840
+ files: (0, import_zod45.withLangGraph)(
7799
7841
  import_v3.z.record(import_v3.z.string(), FileDataSchema).default({}),
7800
7842
  {
7801
7843
  reducer: {
@@ -8071,6 +8113,7 @@ function createFilesystemMiddleware(options = {}) {
8071
8113
  ];
8072
8114
  return (0, import_langchain44.createMiddleware)({
8073
8115
  name: "FilesystemMiddleware",
8116
+ contextSchema,
8074
8117
  stateSchema: FilesystemStateSchema,
8075
8118
  tools,
8076
8119
  wrapModelCall: systemPrompt ? async (request, handler) => {
@@ -8201,6 +8244,7 @@ function createMetricsMiddleware(params) {
8201
8244
  };
8202
8245
  return (0, import_langchain45.createMiddleware)({
8203
8246
  name: "metricsMiddleware",
8247
+ contextSchema,
8204
8248
  tools: [
8205
8249
  createListMetricsDataSourcesTool(toolParams),
8206
8250
  createQueryMetricsListTool(toolParams),
@@ -8219,16 +8263,16 @@ var import_langgraph5 = require("@langchain/langgraph");
8219
8263
 
8220
8264
  // src/tool_lattice/ask_user_to_clarify/index.ts
8221
8265
  var import_langchain46 = require("langchain");
8222
- var import_zod45 = __toESM(require("zod"));
8223
- var questionSchema = import_zod45.default.object({
8224
- question: import_zod45.default.string().describe("The question text to ask the user"),
8225
- options: import_zod45.default.array(import_zod45.default.string()).describe("List of EXACT, selectable values. Maximum 3 options allowed. DO NOT include any 'placeholder' options that require the user to type (e.g., do NOT add 'Enter manual value'). If manual input is needed, set allowOther to true instead."),
8226
- type: import_zod45.default.enum(["single", "multiple"]).describe("Whether the question allows single or multiple selections"),
8227
- required: import_zod45.default.boolean().optional().default(false).describe("Whether this question must be answered"),
8228
- allowOther: import_zod45.default.boolean().optional().default(true).describe("Set to true to append an 'Other' option that opens a free-text input field. Use this for open-ended answers or when the 3 options cannot cover all possibilities.")
8266
+ var import_zod46 = __toESM(require("zod"));
8267
+ var questionSchema = import_zod46.default.object({
8268
+ question: import_zod46.default.string().describe("The question text to ask the user"),
8269
+ options: import_zod46.default.array(import_zod46.default.string()).describe("List of EXACT, selectable values. Maximum 3 options allowed. DO NOT include any 'placeholder' options that require the user to type (e.g., do NOT add 'Enter manual value'). If manual input is needed, set allowOther to true instead."),
8270
+ type: import_zod46.default.enum(["single", "multiple"]).describe("Whether the question allows single or multiple selections"),
8271
+ required: import_zod46.default.boolean().optional().default(false).describe("Whether this question must be answered"),
8272
+ allowOther: import_zod46.default.boolean().optional().default(true).describe("Set to true to append an 'Other' option that opens a free-text input field. Use this for open-ended answers or when the 3 options cannot cover all possibilities.")
8229
8273
  });
8230
- var inputSchema = import_zod45.default.object({
8231
- questions: import_zod45.default.array(questionSchema).min(1, "At least one question is required").describe("A structured sequence of clarification questions. Use these to gather missing parameters or disambiguate user intent before proceeding.")
8274
+ var inputSchema = import_zod46.default.object({
8275
+ questions: import_zod46.default.array(questionSchema).min(1, "At least one question is required").describe("A structured sequence of clarification questions. Use these to gather missing parameters or disambiguate user intent before proceeding.")
8232
8276
  });
8233
8277
  function createAskUserToClarifyTool() {
8234
8278
  return (0, import_langchain46.tool)(
@@ -10355,7 +10399,7 @@ var MemoryBackend = class {
10355
10399
 
10356
10400
  // src/deep_agent_new/middleware/todos.ts
10357
10401
  var import_langgraph9 = require("@langchain/langgraph");
10358
- var import_zod46 = require("zod");
10402
+ var import_zod47 = require("zod");
10359
10403
  var import_langchain51 = require("langchain");
10360
10404
  var WRITE_TODOS_DESCRIPTION = `Use this tool to create and manage a structured task list for your current work session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
10361
10405
  It also helps the user understand the progress of the task and overall progress of their requests.
@@ -10583,12 +10627,12 @@ Writing todos takes time and tokens, use it when it is helpful for managing comp
10583
10627
  ## Important To-Do List Usage Notes to Remember
10584
10628
  - The \`write_todos\` tool should never be called multiple times in parallel.
10585
10629
  - Don't be afraid to revise the To-Do list as you go. New information may reveal new tasks that need to be done, or old tasks that are irrelevant.`;
10586
- var TodoStatus = import_zod46.z.enum(["pending", "in_progress", "completed"]).describe("Status of the todo");
10587
- var TodoSchema = import_zod46.z.object({
10588
- content: import_zod46.z.string().describe("Content of the todo item"),
10630
+ var TodoStatus = import_zod47.z.enum(["pending", "in_progress", "completed"]).describe("Status of the todo");
10631
+ var TodoSchema = import_zod47.z.object({
10632
+ content: import_zod47.z.string().describe("Content of the todo item"),
10589
10633
  status: TodoStatus
10590
10634
  });
10591
- var stateSchema = import_zod46.z.object({ todos: import_zod46.z.array(TodoSchema).default([]) });
10635
+ var stateSchema = import_zod47.z.object({ todos: import_zod47.z.array(TodoSchema).default([]) });
10592
10636
  function todoListMiddleware(options) {
10593
10637
  const writeTodos = (0, import_langchain51.tool)(
10594
10638
  ({ todos }, config) => {
@@ -10607,8 +10651,8 @@ function todoListMiddleware(options) {
10607
10651
  {
10608
10652
  name: "write_todos",
10609
10653
  description: options?.toolDescription ?? WRITE_TODOS_DESCRIPTION,
10610
- schema: import_zod46.z.object({
10611
- todos: import_zod46.z.array(TodoSchema).describe("List of todo items to update")
10654
+ schema: import_zod47.z.object({
10655
+ todos: import_zod47.z.array(TodoSchema).describe("List of todo items to update")
10612
10656
  })
10613
10657
  }
10614
10658
  );
@@ -10635,7 +10679,7 @@ function createDeepAgent(params = {}) {
10635
10679
  middleware: customMiddleware = [],
10636
10680
  subagents = [],
10637
10681
  responseFormat,
10638
- contextSchema,
10682
+ contextSchema: contextSchema2,
10639
10683
  checkpointer,
10640
10684
  store,
10641
10685
  backend,
@@ -10704,7 +10748,7 @@ ${BASE_PROMPT}` : BASE_PROMPT;
10704
10748
  tools,
10705
10749
  middleware,
10706
10750
  responseFormat,
10707
- contextSchema,
10751
+ contextSchema: contextSchema2,
10708
10752
  checkpointer,
10709
10753
  store,
10710
10754
  name