@alfe.ai/openclaw-database 0.0.11 → 0.0.13

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/plugin2.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  let mongodb = require("mongodb");
2
2
  let _alfe_ai_config = require("@alfe.ai/config");
3
+ let _alfe_ai_agent_api_client = require("@alfe.ai/agent-api-client");
3
4
  let node_module = require("node:module");
4
5
  //#region src/tools.ts
5
6
  const DEFAULT_DB = "org_default";
@@ -432,41 +433,29 @@ function registerTools(api, _client, _databases, audit, lazyInit) {
432
433
  const pkg = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("../package.json");
433
434
  let mongoClient = null;
434
435
  let initPromise = null;
435
- async function fetchCredentials(apiUrl, apiKey) {
436
- const res = await fetch(`${apiUrl}/agents/database/register`, {
437
- method: "POST",
438
- headers: {
439
- "Content-Type": "application/json",
440
- Authorization: `Bearer ${apiKey}`
441
- }
442
- });
443
- if (!res.ok) throw new Error(`Failed to register database credentials: ${String(res.status)} ${res.statusText}`);
444
- return (await res.json()).data;
445
- }
446
436
  /**
447
437
  * Lazy initializer — fetches credentials and connects to MongoDB on first use.
448
438
  * Returns a shared promise so concurrent calls don't duplicate work.
449
439
  */
450
- function ensureInitialized(apiUrl, apiKey) {
440
+ function ensureInitialized(client) {
451
441
  if (initPromise) return initPromise;
452
442
  initPromise = (async () => {
453
- const credentials = await fetchCredentials(apiUrl, apiKey);
443
+ const credentials = await client.registerDatabaseCredentials();
454
444
  if (!credentials.connectionString) throw new Error("No connection string returned — cluster may still be provisioning");
455
445
  const url = new URL(credentials.connectionString);
456
446
  url.username = credentials.username;
457
447
  url.password = credentials.password;
458
- const client = new mongodb.MongoClient(url.toString(), {
448
+ const mc = new mongodb.MongoClient(url.toString(), {
459
449
  maxPoolSize: 3,
460
450
  minPoolSize: 1,
461
451
  serverSelectionTimeoutMS: 5e3
462
452
  });
463
- await client.connect();
464
- mongoClient = client;
453
+ await mc.connect();
454
+ mongoClient = mc;
465
455
  return {
466
- mongoClient: client,
456
+ mongoClient: mc,
467
457
  databases: credentials.databases,
468
- apiUrl,
469
- apiKey
458
+ client
470
459
  };
471
460
  })();
472
461
  initPromise.catch(() => {
@@ -474,16 +463,6 @@ function ensureInitialized(apiUrl, apiKey) {
474
463
  });
475
464
  return initPromise;
476
465
  }
477
- function reportAudit(apiUrl, apiKey, entry) {
478
- fetch(`${apiUrl}/agents/database/audit`, {
479
- method: "POST",
480
- headers: {
481
- "Content-Type": "application/json",
482
- Authorization: `Bearer ${apiKey}`
483
- },
484
- body: JSON.stringify(entry)
485
- }).catch(() => {});
486
- }
487
466
  const plugin = {
488
467
  id: "@alfe.ai/openclaw-database",
489
468
  name: "Alfe Database",
@@ -491,21 +470,22 @@ const plugin = {
491
470
  activate(api) {
492
471
  const log = api.logger;
493
472
  log.info("Database plugin activating...");
494
- let apiUrl;
495
- let apiKey;
473
+ let client;
496
474
  try {
497
475
  const config = (0, _alfe_ai_config.resolveConfig)();
498
- apiUrl = config.apiUrl;
499
- apiKey = config.apiKey;
476
+ client = new _alfe_ai_agent_api_client.AgentApiClient({
477
+ apiKey: config.apiKey,
478
+ apiUrl: config.apiUrl
479
+ });
500
480
  } catch (err) {
501
481
  log.error(`Database plugin: failed to resolve config — ${err instanceof Error ? err.message : String(err)}`);
502
482
  return;
503
483
  }
504
484
  registerTools(api, null, [], (entry) => {
505
- reportAudit(apiUrl, apiKey, entry);
506
- }, () => ensureInitialized(apiUrl, apiKey));
485
+ client.reportDatabaseAudit(entry);
486
+ }, () => ensureInitialized(client));
507
487
  const startDatabaseService = () => {
508
- ensureInitialized(apiUrl, apiKey).then(({ databases }) => {
488
+ ensureInitialized(client).then(({ databases }) => {
509
489
  log.info(`Database plugin connected — ${String(databases.length)} databases available`);
510
490
  }).catch((err) => {
511
491
  log.warn(`Database plugin: background init failed (will retry on first tool use) — ${err instanceof Error ? err.message : String(err)}`);
package/dist/plugin2.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { MongoClient } from "mongodb";
3
3
  import { resolveConfig } from "@alfe.ai/config";
4
+ import { AgentApiClient } from "@alfe.ai/agent-api-client";
4
5
  //#region src/tools.ts
5
6
  const DEFAULT_DB = "org_default";
6
7
  function str(required = true) {
@@ -432,41 +433,29 @@ function registerTools(api, _client, _databases, audit, lazyInit) {
432
433
  const pkg = createRequire(import.meta.url)("../package.json");
433
434
  let mongoClient = null;
434
435
  let initPromise = null;
435
- async function fetchCredentials(apiUrl, apiKey) {
436
- const res = await fetch(`${apiUrl}/agents/database/register`, {
437
- method: "POST",
438
- headers: {
439
- "Content-Type": "application/json",
440
- Authorization: `Bearer ${apiKey}`
441
- }
442
- });
443
- if (!res.ok) throw new Error(`Failed to register database credentials: ${String(res.status)} ${res.statusText}`);
444
- return (await res.json()).data;
445
- }
446
436
  /**
447
437
  * Lazy initializer — fetches credentials and connects to MongoDB on first use.
448
438
  * Returns a shared promise so concurrent calls don't duplicate work.
449
439
  */
450
- function ensureInitialized(apiUrl, apiKey) {
440
+ function ensureInitialized(client) {
451
441
  if (initPromise) return initPromise;
452
442
  initPromise = (async () => {
453
- const credentials = await fetchCredentials(apiUrl, apiKey);
443
+ const credentials = await client.registerDatabaseCredentials();
454
444
  if (!credentials.connectionString) throw new Error("No connection string returned — cluster may still be provisioning");
455
445
  const url = new URL(credentials.connectionString);
456
446
  url.username = credentials.username;
457
447
  url.password = credentials.password;
458
- const client = new MongoClient(url.toString(), {
448
+ const mc = new MongoClient(url.toString(), {
459
449
  maxPoolSize: 3,
460
450
  minPoolSize: 1,
461
451
  serverSelectionTimeoutMS: 5e3
462
452
  });
463
- await client.connect();
464
- mongoClient = client;
453
+ await mc.connect();
454
+ mongoClient = mc;
465
455
  return {
466
- mongoClient: client,
456
+ mongoClient: mc,
467
457
  databases: credentials.databases,
468
- apiUrl,
469
- apiKey
458
+ client
470
459
  };
471
460
  })();
472
461
  initPromise.catch(() => {
@@ -474,16 +463,6 @@ function ensureInitialized(apiUrl, apiKey) {
474
463
  });
475
464
  return initPromise;
476
465
  }
477
- function reportAudit(apiUrl, apiKey, entry) {
478
- fetch(`${apiUrl}/agents/database/audit`, {
479
- method: "POST",
480
- headers: {
481
- "Content-Type": "application/json",
482
- Authorization: `Bearer ${apiKey}`
483
- },
484
- body: JSON.stringify(entry)
485
- }).catch(() => {});
486
- }
487
466
  const plugin = {
488
467
  id: "@alfe.ai/openclaw-database",
489
468
  name: "Alfe Database",
@@ -491,21 +470,22 @@ const plugin = {
491
470
  activate(api) {
492
471
  const log = api.logger;
493
472
  log.info("Database plugin activating...");
494
- let apiUrl;
495
- let apiKey;
473
+ let client;
496
474
  try {
497
475
  const config = resolveConfig();
498
- apiUrl = config.apiUrl;
499
- apiKey = config.apiKey;
476
+ client = new AgentApiClient({
477
+ apiKey: config.apiKey,
478
+ apiUrl: config.apiUrl
479
+ });
500
480
  } catch (err) {
501
481
  log.error(`Database plugin: failed to resolve config — ${err instanceof Error ? err.message : String(err)}`);
502
482
  return;
503
483
  }
504
484
  registerTools(api, null, [], (entry) => {
505
- reportAudit(apiUrl, apiKey, entry);
506
- }, () => ensureInitialized(apiUrl, apiKey));
485
+ client.reportDatabaseAudit(entry);
486
+ }, () => ensureInitialized(client));
507
487
  const startDatabaseService = () => {
508
- ensureInitialized(apiUrl, apiKey).then(({ databases }) => {
488
+ ensureInitialized(client).then(({ databases }) => {
509
489
  log.info(`Database plugin connected — ${String(databases.length)} databases available`);
510
490
  }).catch((err) => {
511
491
  log.warn(`Database plugin: background init failed (will retry on first tool use) — ${err instanceof Error ? err.message : String(err)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfe.ai/openclaw-database",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "OpenClaw database plugin — MongoDB access for agents via MCP tools",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin.js",
@@ -28,6 +28,7 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "mongodb": "^6.12.0",
31
+ "@alfe.ai/agent-api-client": "0.1.0",
31
32
  "@alfe.ai/config": "0.0.8"
32
33
  },
33
34
  "license": "UNLICENSED",