@alfe.ai/openclaw-database 0.0.8 → 0.0.10

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
@@ -488,10 +488,6 @@ const plugin = {
488
488
  version: "0.0.1",
489
489
  activate(api) {
490
490
  const log = api.logger;
491
- if (api.registrationMode === "cli-metadata") {
492
- log.debug("CLI metadata mode — skipping database init");
493
- return;
494
- }
495
491
  log.info("Database plugin activating...");
496
492
  let apiUrl;
497
493
  let apiKey;
@@ -503,20 +499,41 @@ const plugin = {
503
499
  log.error(`Database plugin: failed to resolve config — ${err instanceof Error ? err.message : String(err)}`);
504
500
  return;
505
501
  }
506
- ensureInitialized(apiUrl, apiKey).then(({ databases }) => {
507
- log.info(`Database plugin connected — ${String(databases.length)} databases available`);
508
- }).catch((err) => {
509
- log.warn(`Database plugin: background init failed (will retry on first tool use) — ${err instanceof Error ? err.message : String(err)}`);
510
- });
511
502
  registerTools(api, null, [], (entry) => {
512
503
  reportAudit(apiUrl, apiKey, entry);
513
504
  }, () => ensureInitialized(apiUrl, apiKey));
505
+ const startDatabaseService = () => {
506
+ ensureInitialized(apiUrl, apiKey).then(({ databases }) => {
507
+ log.info(`Database plugin connected — ${String(databases.length)} databases available`);
508
+ }).catch((err) => {
509
+ log.warn(`Database plugin: background init failed (will retry on first tool use) — ${err instanceof Error ? err.message : String(err)}`);
510
+ });
511
+ };
512
+ const stopDatabaseService = async () => {
513
+ if (mongoClient) {
514
+ await mongoClient.close();
515
+ mongoClient = null;
516
+ initPromise = null;
517
+ }
518
+ log.info("Database plugin deactivated");
519
+ };
520
+ if (api.registerService) api.registerService({
521
+ id: "alfe-database-mongo",
522
+ start() {
523
+ startDatabaseService();
524
+ },
525
+ async stop() {
526
+ await stopDatabaseService();
527
+ }
528
+ });
529
+ else startDatabaseService();
514
530
  },
515
531
  async deactivate(api) {
516
532
  api.logger.info("Database plugin deactivating...");
517
533
  if (mongoClient) {
518
534
  await mongoClient.close();
519
535
  mongoClient = null;
536
+ initPromise = null;
520
537
  }
521
538
  }
522
539
  };
package/dist/plugin2.js CHANGED
@@ -488,10 +488,6 @@ const plugin = {
488
488
  version: "0.0.1",
489
489
  activate(api) {
490
490
  const log = api.logger;
491
- if (api.registrationMode === "cli-metadata") {
492
- log.debug("CLI metadata mode — skipping database init");
493
- return;
494
- }
495
491
  log.info("Database plugin activating...");
496
492
  let apiUrl;
497
493
  let apiKey;
@@ -503,20 +499,41 @@ const plugin = {
503
499
  log.error(`Database plugin: failed to resolve config — ${err instanceof Error ? err.message : String(err)}`);
504
500
  return;
505
501
  }
506
- ensureInitialized(apiUrl, apiKey).then(({ databases }) => {
507
- log.info(`Database plugin connected — ${String(databases.length)} databases available`);
508
- }).catch((err) => {
509
- log.warn(`Database plugin: background init failed (will retry on first tool use) — ${err instanceof Error ? err.message : String(err)}`);
510
- });
511
502
  registerTools(api, null, [], (entry) => {
512
503
  reportAudit(apiUrl, apiKey, entry);
513
504
  }, () => ensureInitialized(apiUrl, apiKey));
505
+ const startDatabaseService = () => {
506
+ ensureInitialized(apiUrl, apiKey).then(({ databases }) => {
507
+ log.info(`Database plugin connected — ${String(databases.length)} databases available`);
508
+ }).catch((err) => {
509
+ log.warn(`Database plugin: background init failed (will retry on first tool use) — ${err instanceof Error ? err.message : String(err)}`);
510
+ });
511
+ };
512
+ const stopDatabaseService = async () => {
513
+ if (mongoClient) {
514
+ await mongoClient.close();
515
+ mongoClient = null;
516
+ initPromise = null;
517
+ }
518
+ log.info("Database plugin deactivated");
519
+ };
520
+ if (api.registerService) api.registerService({
521
+ id: "alfe-database-mongo",
522
+ start() {
523
+ startDatabaseService();
524
+ },
525
+ async stop() {
526
+ await stopDatabaseService();
527
+ }
528
+ });
529
+ else startDatabaseService();
514
530
  },
515
531
  async deactivate(api) {
516
532
  api.logger.info("Database plugin deactivating...");
517
533
  if (mongoClient) {
518
534
  await mongoClient.close();
519
535
  mongoClient = null;
536
+ initPromise = null;
520
537
  }
521
538
  }
522
539
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfe.ai/openclaw-database",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "OpenClaw database plugin — MongoDB access for agents via MCP tools",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin.js",