@agentforge/tools 0.16.15 → 0.16.17

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.cjs CHANGED
@@ -4286,6 +4286,79 @@ async function initializeSQLiteConnection(connection) {
4286
4286
  const db = drizzle({ client });
4287
4287
  return { client, db };
4288
4288
  }
4289
+
4290
+ // src/data/relational/connection/query-execution.ts
4291
+ async function executeQuery(context, query, logger23) {
4292
+ logger23.debug("Executing SQL query", {
4293
+ vendor: context.vendor
4294
+ });
4295
+ if (context.vendor === "sqlite") {
4296
+ return executeSqliteQuery(
4297
+ context.db,
4298
+ query,
4299
+ context.isSqliteNonQueryError
4300
+ );
4301
+ }
4302
+ if (context.vendor === "mysql") {
4303
+ return normalizeMySqlResult(
4304
+ await context.db.execute(query)
4305
+ );
4306
+ }
4307
+ return context.db.execute(query);
4308
+ }
4309
+ async function executeSqliteQuery(db, query, isSqliteNonQueryError) {
4310
+ try {
4311
+ return db.all(query);
4312
+ } catch (error) {
4313
+ if (isSqliteNonQueryError(error)) {
4314
+ const runResult = db.run(query);
4315
+ return { ...runResult, affectedRows: runResult.changes ?? 0 };
4316
+ }
4317
+ throw error;
4318
+ }
4319
+ }
4320
+ function normalizeMySqlResult(raw) {
4321
+ if (Array.isArray(raw) && raw.length === 2) {
4322
+ return raw[0];
4323
+ }
4324
+ return raw;
4325
+ }
4326
+
4327
+ // src/data/relational/connection/session-adapters.ts
4328
+ async function executeInDedicatedConnection(context, callback) {
4329
+ if (context.vendor === "sqlite") {
4330
+ return callback(
4331
+ (query) => executeSqliteQuery(
4332
+ context.db,
4333
+ query,
4334
+ context.isSqliteNonQueryError
4335
+ )
4336
+ );
4337
+ }
4338
+ if (context.vendor === "postgresql") {
4339
+ const poolClient = await context.client.connect();
4340
+ try {
4341
+ const { drizzle } = await import('drizzle-orm/node-postgres');
4342
+ const sessionDb = drizzle({ client: poolClient });
4343
+ return await callback((query) => sessionDb.execute(query));
4344
+ } finally {
4345
+ poolClient.release();
4346
+ }
4347
+ }
4348
+ if (context.vendor === "mysql") {
4349
+ const mysqlConnection = await context.client.getConnection();
4350
+ try {
4351
+ const { drizzle } = await import('drizzle-orm/mysql2');
4352
+ const sessionDb = drizzle({ client: mysqlConnection });
4353
+ return await callback(
4354
+ async (query) => normalizeMySqlResult(await sessionDb.execute(query))
4355
+ );
4356
+ } finally {
4357
+ mysqlConnection.release();
4358
+ }
4359
+ }
4360
+ throw new Error(`Unsupported database vendor: ${context.vendor}`);
4361
+ }
4289
4362
  var logger8 = core.createLogger("agentforge:tools:data:relational:connection");
4290
4363
  var ConnectionManager = class extends events.EventEmitter {
4291
4364
  vendor;
@@ -4586,28 +4659,15 @@ var ConnectionManager = class extends events.EventEmitter {
4586
4659
  if (!this.db) {
4587
4660
  throw new Error("Database not initialized. Call initialize() first.");
4588
4661
  }
4589
- logger8.debug("Executing SQL query", {
4590
- vendor: this.vendor
4591
- });
4592
- if (this.vendor === "sqlite") {
4593
- try {
4594
- return this.db.all(query);
4595
- } catch (error) {
4596
- if (this.isSqliteNonQueryError(error)) {
4597
- const runResult = this.db.run(query);
4598
- return { ...runResult, affectedRows: runResult.changes ?? 0 };
4599
- }
4600
- throw error;
4601
- }
4602
- }
4603
- if (this.vendor === "mysql") {
4604
- const raw = await this.db.execute(query);
4605
- if (Array.isArray(raw) && raw.length === 2) {
4606
- return raw[0];
4607
- }
4608
- return raw;
4609
- }
4610
- return this.db.execute(query);
4662
+ return executeQuery(
4663
+ {
4664
+ vendor: this.vendor,
4665
+ db: this.db,
4666
+ isSqliteNonQueryError: (error) => this.isSqliteNonQueryError(error)
4667
+ },
4668
+ query,
4669
+ logger8
4670
+ );
4611
4671
  }
4612
4672
  /**
4613
4673
  * Execute a callback with a single dedicated database connection/session.
@@ -4619,46 +4679,15 @@ var ConnectionManager = class extends events.EventEmitter {
4619
4679
  if (!this.client || !this.db) {
4620
4680
  throw new Error("Database not initialized. Call connect() first.");
4621
4681
  }
4622
- if (this.vendor === "sqlite") {
4623
- return callback(async (query) => {
4624
- try {
4625
- return this.db.all(query);
4626
- } catch (error) {
4627
- if (this.isSqliteNonQueryError(error)) {
4628
- const runResult = this.db.run(query);
4629
- return { ...runResult, affectedRows: runResult.changes ?? 0 };
4630
- }
4631
- throw error;
4632
- }
4633
- });
4634
- }
4635
- if (this.vendor === "postgresql") {
4636
- const poolClient = await this.client.connect();
4637
- try {
4638
- const { drizzle } = await import('drizzle-orm/node-postgres');
4639
- const sessionDb = drizzle({ client: poolClient });
4640
- return await callback(async (query) => sessionDb.execute(query));
4641
- } finally {
4642
- poolClient.release();
4643
- }
4644
- }
4645
- if (this.vendor === "mysql") {
4646
- const mysqlConnection = await this.client.getConnection();
4647
- try {
4648
- const { drizzle } = await import('drizzle-orm/mysql2');
4649
- const sessionDb = drizzle({ client: mysqlConnection });
4650
- return await callback(async (query) => {
4651
- const raw = await sessionDb.execute(query);
4652
- if (Array.isArray(raw) && raw.length === 2) {
4653
- return raw[0];
4654
- }
4655
- return raw;
4656
- });
4657
- } finally {
4658
- mysqlConnection.release();
4659
- }
4660
- }
4661
- throw new Error(`Unsupported database vendor: ${this.vendor}`);
4682
+ return executeInDedicatedConnection(
4683
+ {
4684
+ vendor: this.vendor,
4685
+ client: this.client,
4686
+ db: this.db,
4687
+ isSqliteNonQueryError: (error) => this.isSqliteNonQueryError(error)
4688
+ },
4689
+ callback
4690
+ );
4662
4691
  }
4663
4692
  /**
4664
4693
  * Get connection pool metrics
@@ -4877,7 +4906,7 @@ function buildParameterizedQuery(sqlString, params) {
4877
4906
  return sqlChunks.length > 0 ? drizzleOrm.sql.join(sqlChunks, drizzleOrm.sql.raw("")) : drizzleOrm.sql.raw(sqlString);
4878
4907
  }
4879
4908
  }
4880
- async function executeQuery(manager, input, context) {
4909
+ async function executeQuery2(manager, input, context) {
4881
4910
  const startTime = Date.now();
4882
4911
  logger9.debug("Executing query", {
4883
4912
  vendor: input.vendor,
@@ -5948,11 +5977,11 @@ async function withTransaction(manager, operation, options) {
5948
5977
  ...resolvedOptions.isolationLevel ? { isolationLevel: resolvedOptions.isolationLevel } : {},
5949
5978
  ...resolvedOptions.timeoutMs !== void 0 ? { timeoutMs: resolvedOptions.timeoutMs } : {}
5950
5979
  });
5951
- return manager.executeInConnection(async (executeQuery2) => {
5980
+ return manager.executeInConnection(async (executeQuery3) => {
5952
5981
  const transaction = new ManagedTransaction({
5953
5982
  id: transactionId,
5954
5983
  vendor,
5955
- executeQuery: executeQuery2,
5984
+ executeQuery: executeQuery3,
5956
5985
  options: resolvedOptions
5957
5986
  });
5958
5987
  await transaction.begin();
@@ -6318,7 +6347,7 @@ var SchemaInspector = class _SchemaInspector {
6318
6347
  };
6319
6348
  }
6320
6349
  async runQueryRows(query) {
6321
- const result = await executeQuery(this.manager, {
6350
+ const result = await executeQuery2(this.manager, {
6322
6351
  sql: query,
6323
6352
  vendor: this.vendor
6324
6353
  });
@@ -7042,7 +7071,7 @@ var relationalQuery = core.toolBuilder().name("relational-query").displayName("R
7042
7071
  });
7043
7072
  try {
7044
7073
  await manager.initialize();
7045
- const result = await executeQuery(manager, {
7074
+ const result = await executeQuery2(manager, {
7046
7075
  sql: input.sql,
7047
7076
  params: input.params,
7048
7077
  vendor: input.vendor
@@ -10393,7 +10422,7 @@ exports.directoryOperationTools = directoryOperationTools;
10393
10422
  exports.emailValidator = emailValidator;
10394
10423
  exports.embeddingManager = embeddingManager;
10395
10424
  exports.executeBatchedTask = executeBatchedTask;
10396
- exports.executeQuery = executeQuery;
10425
+ exports.executeQuery = executeQuery2;
10397
10426
  exports.executeStreamingSelect = executeStreamingSelect;
10398
10427
  exports.exportSchemaToJson = exportSchemaToJson;
10399
10428
  exports.extractImages = extractImages;