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