@alfe.ai/openclaw-database 0.0.9 → 0.0.11

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/plugin.d.cts CHANGED
@@ -1,13 +1,25 @@
1
1
  //#region src/plugin.d.ts
2
+ interface PluginLogger {
3
+ info: (...args: unknown[]) => void;
4
+ warn: (...args: unknown[]) => void;
5
+ error: (...args: unknown[]) => void;
6
+ debug: (...args: unknown[]) => void;
7
+ }
8
+ interface PluginServiceContext {
9
+ config: Record<string, unknown>;
10
+ workspaceDir?: string;
11
+ stateDir: string;
12
+ logger: PluginLogger;
13
+ }
2
14
  interface PluginApi {
3
- logger: {
4
- info: (...args: unknown[]) => void;
5
- warn: (...args: unknown[]) => void;
6
- error: (...args: unknown[]) => void;
7
- debug: (...args: unknown[]) => void;
8
- };
15
+ logger: PluginLogger;
9
16
  registrationMode?: 'full' | 'setup-only' | 'setup-runtime' | 'cli-metadata';
10
17
  registerTool(tool: unknown): void;
18
+ registerService?(service: {
19
+ id: string;
20
+ start: (ctx: PluginServiceContext) => void | Promise<void>;
21
+ stop?: (ctx: PluginServiceContext) => void | Promise<void>;
22
+ }): void;
11
23
  }
12
24
  declare const plugin: {
13
25
  id: string;
package/dist/plugin.d.ts CHANGED
@@ -1,13 +1,25 @@
1
1
  //#region src/plugin.d.ts
2
+ interface PluginLogger {
3
+ info: (...args: unknown[]) => void;
4
+ warn: (...args: unknown[]) => void;
5
+ error: (...args: unknown[]) => void;
6
+ debug: (...args: unknown[]) => void;
7
+ }
8
+ interface PluginServiceContext {
9
+ config: Record<string, unknown>;
10
+ workspaceDir?: string;
11
+ stateDir: string;
12
+ logger: PluginLogger;
13
+ }
2
14
  interface PluginApi {
3
- logger: {
4
- info: (...args: unknown[]) => void;
5
- warn: (...args: unknown[]) => void;
6
- error: (...args: unknown[]) => void;
7
- debug: (...args: unknown[]) => void;
8
- };
15
+ logger: PluginLogger;
9
16
  registrationMode?: 'full' | 'setup-only' | 'setup-runtime' | 'cli-metadata';
10
17
  registerTool(tool: unknown): void;
18
+ registerService?(service: {
19
+ id: string;
20
+ start: (ctx: PluginServiceContext) => void | Promise<void>;
21
+ stop?: (ctx: PluginServiceContext) => void | Promise<void>;
22
+ }): void;
11
23
  }
12
24
  declare const plugin: {
13
25
  id: string;
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 node_module = require("node:module");
3
4
  //#region src/tools.ts
4
5
  const DEFAULT_DB = "org_default";
5
6
  function str(required = true) {
@@ -428,6 +429,7 @@ function registerTools(api, _client, _databases, audit, lazyInit) {
428
429
  }
429
430
  //#endregion
430
431
  //#region src/plugin.ts
432
+ const pkg = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("../package.json");
431
433
  let mongoClient = null;
432
434
  let initPromise = null;
433
435
  async function fetchCredentials(apiUrl, apiKey) {
@@ -485,10 +487,9 @@ function reportAudit(apiUrl, apiKey, entry) {
485
487
  const plugin = {
486
488
  id: "@alfe.ai/openclaw-database",
487
489
  name: "Alfe Database",
488
- version: "0.0.1",
490
+ version: pkg.version,
489
491
  activate(api) {
490
492
  const log = api.logger;
491
- if (api.registrationMode && api.registrationMode !== "full") return;
492
493
  log.info("Database plugin activating...");
493
494
  let apiUrl;
494
495
  let apiKey;
@@ -500,20 +501,41 @@ const plugin = {
500
501
  log.error(`Database plugin: failed to resolve config — ${err instanceof Error ? err.message : String(err)}`);
501
502
  return;
502
503
  }
503
- ensureInitialized(apiUrl, apiKey).then(({ databases }) => {
504
- log.info(`Database plugin connected — ${String(databases.length)} databases available`);
505
- }).catch((err) => {
506
- log.warn(`Database plugin: background init failed (will retry on first tool use) — ${err instanceof Error ? err.message : String(err)}`);
507
- });
508
504
  registerTools(api, null, [], (entry) => {
509
505
  reportAudit(apiUrl, apiKey, entry);
510
506
  }, () => ensureInitialized(apiUrl, apiKey));
507
+ const startDatabaseService = () => {
508
+ ensureInitialized(apiUrl, apiKey).then(({ databases }) => {
509
+ log.info(`Database plugin connected — ${String(databases.length)} databases available`);
510
+ }).catch((err) => {
511
+ log.warn(`Database plugin: background init failed (will retry on first tool use) — ${err instanceof Error ? err.message : String(err)}`);
512
+ });
513
+ };
514
+ const stopDatabaseService = async () => {
515
+ if (mongoClient) {
516
+ await mongoClient.close();
517
+ mongoClient = null;
518
+ initPromise = null;
519
+ }
520
+ log.info("Database plugin deactivated");
521
+ };
522
+ if (api.registerService) api.registerService({
523
+ id: "alfe-database-mongo",
524
+ start() {
525
+ startDatabaseService();
526
+ },
527
+ async stop() {
528
+ await stopDatabaseService();
529
+ }
530
+ });
531
+ else startDatabaseService();
511
532
  },
512
533
  async deactivate(api) {
513
534
  api.logger.info("Database plugin deactivating...");
514
535
  if (mongoClient) {
515
536
  await mongoClient.close();
516
537
  mongoClient = null;
538
+ initPromise = null;
517
539
  }
518
540
  }
519
541
  };
package/dist/plugin2.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { createRequire } from "node:module";
1
2
  import { MongoClient } from "mongodb";
2
3
  import { resolveConfig } from "@alfe.ai/config";
3
4
  //#region src/tools.ts
@@ -428,6 +429,7 @@ function registerTools(api, _client, _databases, audit, lazyInit) {
428
429
  }
429
430
  //#endregion
430
431
  //#region src/plugin.ts
432
+ const pkg = createRequire(import.meta.url)("../package.json");
431
433
  let mongoClient = null;
432
434
  let initPromise = null;
433
435
  async function fetchCredentials(apiUrl, apiKey) {
@@ -485,10 +487,9 @@ function reportAudit(apiUrl, apiKey, entry) {
485
487
  const plugin = {
486
488
  id: "@alfe.ai/openclaw-database",
487
489
  name: "Alfe Database",
488
- version: "0.0.1",
490
+ version: pkg.version,
489
491
  activate(api) {
490
492
  const log = api.logger;
491
- if (api.registrationMode && api.registrationMode !== "full") return;
492
493
  log.info("Database plugin activating...");
493
494
  let apiUrl;
494
495
  let apiKey;
@@ -500,20 +501,41 @@ const plugin = {
500
501
  log.error(`Database plugin: failed to resolve config — ${err instanceof Error ? err.message : String(err)}`);
501
502
  return;
502
503
  }
503
- ensureInitialized(apiUrl, apiKey).then(({ databases }) => {
504
- log.info(`Database plugin connected — ${String(databases.length)} databases available`);
505
- }).catch((err) => {
506
- log.warn(`Database plugin: background init failed (will retry on first tool use) — ${err instanceof Error ? err.message : String(err)}`);
507
- });
508
504
  registerTools(api, null, [], (entry) => {
509
505
  reportAudit(apiUrl, apiKey, entry);
510
506
  }, () => ensureInitialized(apiUrl, apiKey));
507
+ const startDatabaseService = () => {
508
+ ensureInitialized(apiUrl, apiKey).then(({ databases }) => {
509
+ log.info(`Database plugin connected — ${String(databases.length)} databases available`);
510
+ }).catch((err) => {
511
+ log.warn(`Database plugin: background init failed (will retry on first tool use) — ${err instanceof Error ? err.message : String(err)}`);
512
+ });
513
+ };
514
+ const stopDatabaseService = async () => {
515
+ if (mongoClient) {
516
+ await mongoClient.close();
517
+ mongoClient = null;
518
+ initPromise = null;
519
+ }
520
+ log.info("Database plugin deactivated");
521
+ };
522
+ if (api.registerService) api.registerService({
523
+ id: "alfe-database-mongo",
524
+ start() {
525
+ startDatabaseService();
526
+ },
527
+ async stop() {
528
+ await stopDatabaseService();
529
+ }
530
+ });
531
+ else startDatabaseService();
511
532
  },
512
533
  async deactivate(api) {
513
534
  api.logger.info("Database plugin deactivating...");
514
535
  if (mongoClient) {
515
536
  await mongoClient.close();
516
537
  mongoClient = null;
538
+ initPromise = null;
517
539
  }
518
540
  }
519
541
  };
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "id": "@alfe.ai/openclaw-database",
3
3
  "name": "Alfe Database",
4
- "version": "0.0.1",
5
4
  "description": "MongoDB database access for agents — query, insert, update, delete, and manage collections",
6
5
  "entry": "./dist/plugin.js",
7
6
  "configSchema": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfe.ai/openclaw-database",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "OpenClaw database plugin — MongoDB access for agents via MCP tools",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin.js",