@alfe.ai/openclaw-google-chat 0.0.28 → 0.0.29
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 +48 -78
- package/dist/plugin2.js +48 -78
- package/package.json +4 -3
package/dist/plugin2.cjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
let node_module = require("node:module");
|
|
2
|
-
let node_path = require("node:path");
|
|
3
2
|
let _alfe_ai_config = require("@alfe.ai/config");
|
|
4
3
|
let _alfe_ai_agent_api_client = require("@alfe.ai/agent-api-client");
|
|
4
|
+
let _alfe_ai_openclaw_plugin_kit = require("@alfe.ai/openclaw-plugin-kit");
|
|
5
5
|
let node_fs_promises = require("node:fs/promises");
|
|
6
|
+
let node_path = require("node:path");
|
|
6
7
|
let node_os = require("node:os");
|
|
7
8
|
//#region src/gchat-state.ts
|
|
8
9
|
/**
|
|
@@ -532,34 +533,9 @@ function isTokenRevokedError(err) {
|
|
|
532
533
|
* → dispatchInboundDirectDmWithRuntime() → Agent pipeline
|
|
533
534
|
* ← deliver() callback → Google Chat API (reply as user)
|
|
534
535
|
*/
|
|
535
|
-
const
|
|
536
|
-
const pkg = require$1("../package.json");
|
|
536
|
+
const pkg = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("../package.json");
|
|
537
537
|
let dispatchInbound = null;
|
|
538
|
-
|
|
539
|
-
* Resolve OpenClaw SDK from the running process.
|
|
540
|
-
* Copied from @alfe.ai/openclaw-chat's resolution strategy.
|
|
541
|
-
*/
|
|
542
|
-
function resolveOpenClawSdk(log) {
|
|
543
|
-
const anchors = [require$1.main?.filename, process.argv[1]].filter(Boolean);
|
|
544
|
-
for (const anchor of anchors) try {
|
|
545
|
-
const channelInbound = (0, node_module.createRequire)(anchor)("openclaw/plugin-sdk/channel-inbound");
|
|
546
|
-
if (channelInbound.dispatchInboundDirectDmWithRuntime) {
|
|
547
|
-
dispatchInbound = channelInbound.dispatchInboundDirectDmWithRuntime;
|
|
548
|
-
log.info(`Resolved OpenClaw SDK from ${anchor}`);
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
} catch {}
|
|
552
|
-
try {
|
|
553
|
-
const derivedPath = (0, node_path.join)((0, node_path.resolve)((0, node_path.dirname)(process.execPath), ".."), "lib", "node_modules", "openclaw", "package.json");
|
|
554
|
-
const channelInbound = (0, node_module.createRequire)(derivedPath)("openclaw/plugin-sdk/channel-inbound");
|
|
555
|
-
if (channelInbound.dispatchInboundDirectDmWithRuntime) {
|
|
556
|
-
dispatchInbound = channelInbound.dispatchInboundDirectDmWithRuntime;
|
|
557
|
-
log.info(`Resolved OpenClaw SDK from ${derivedPath}`);
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
} catch {}
|
|
561
|
-
log.warn("OpenClaw SDK not resolvable — Google Chat dispatch will not work");
|
|
562
|
-
}
|
|
538
|
+
const GCHAT_ACTIVATION_KEY = (0, _alfe_ai_openclaw_plugin_kit.getActivationKey)("google-chat");
|
|
563
539
|
let pluginRuntime = null;
|
|
564
540
|
let poller = null;
|
|
565
541
|
const plugin = {
|
|
@@ -569,66 +545,60 @@ const plugin = {
|
|
|
569
545
|
version: pkg.version,
|
|
570
546
|
activate(api) {
|
|
571
547
|
const log = api.logger;
|
|
572
|
-
const startService =
|
|
573
|
-
|
|
574
|
-
log.
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
poller = new GChatPoller(init);
|
|
614
|
-
await poller.start();
|
|
615
|
-
log.info(`Google Chat poller started (account: ${creds.email})`);
|
|
548
|
+
const startService = () => {
|
|
549
|
+
(0, _alfe_ai_openclaw_plugin_kit.guardedStart)(GCHAT_ACTIVATION_KEY, log, async () => {
|
|
550
|
+
log.info("Google Chat plugin starting...");
|
|
551
|
+
dispatchInbound = (0, _alfe_ai_openclaw_plugin_kit.resolveOpenClawSdk)(log, { unresolvableNote: "OpenClaw SDK not resolvable — Google Chat dispatch will not work" });
|
|
552
|
+
pluginRuntime = api.runtime ?? null;
|
|
553
|
+
let client;
|
|
554
|
+
try {
|
|
555
|
+
const cfg = (0, _alfe_ai_config.resolveConfig)();
|
|
556
|
+
client = new _alfe_ai_agent_api_client.AgentApiClient({
|
|
557
|
+
apiKey: cfg.apiKey,
|
|
558
|
+
apiUrl: cfg.apiUrl
|
|
559
|
+
});
|
|
560
|
+
} catch (err) {
|
|
561
|
+
(0, _alfe_ai_openclaw_plugin_kit.resetActivation)(GCHAT_ACTIVATION_KEY);
|
|
562
|
+
log.error(`Failed to resolve config: ${err instanceof Error ? err.message : String(err)}`);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
let creds;
|
|
566
|
+
try {
|
|
567
|
+
creds = await client.getGoogleChatCredentials();
|
|
568
|
+
} catch (err) {
|
|
569
|
+
(0, _alfe_ai_openclaw_plugin_kit.resetActivation)(GCHAT_ACTIVATION_KEY);
|
|
570
|
+
log.info(`Google Chat not connected — polling disabled (${err instanceof Error ? err.message : String(err)})`);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
const init = {
|
|
574
|
+
tokenManager: new (await (Promise.resolve().then(() => require("./gchat-token.cjs")))).TokenManager({
|
|
575
|
+
refreshToken: creds.refreshToken,
|
|
576
|
+
clientId: creds.clientId,
|
|
577
|
+
clientSecret: creds.clientSecret
|
|
578
|
+
}, log),
|
|
579
|
+
dispatchInbound,
|
|
580
|
+
runtime: pluginRuntime,
|
|
581
|
+
log,
|
|
582
|
+
agentEmail: creds.email
|
|
583
|
+
};
|
|
584
|
+
init.agentClient = client;
|
|
585
|
+
poller = new GChatPoller(init);
|
|
586
|
+
await poller.start();
|
|
587
|
+
log.info(`Google Chat poller started (account: ${creds.email})`);
|
|
588
|
+
});
|
|
616
589
|
};
|
|
617
590
|
const stopService = () => {
|
|
618
|
-
globalThis.__alfeGoogleChatActivated = false;
|
|
619
591
|
poller?.stop();
|
|
620
592
|
poller = null;
|
|
621
593
|
pluginRuntime = null;
|
|
622
594
|
dispatchInbound = null;
|
|
595
|
+
(0, _alfe_ai_openclaw_plugin_kit.resetActivation)(GCHAT_ACTIVATION_KEY);
|
|
623
596
|
log.info("Google Chat plugin stopped");
|
|
624
597
|
};
|
|
625
598
|
api.registerService({
|
|
626
599
|
id: "google-chat-poller",
|
|
627
600
|
start: () => {
|
|
628
|
-
startService()
|
|
629
|
-
globalThis.__alfeGoogleChatActivated = false;
|
|
630
|
-
log.error(`Google Chat service start failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
631
|
-
});
|
|
601
|
+
startService();
|
|
632
602
|
},
|
|
633
603
|
stop: () => {
|
|
634
604
|
stopService();
|
|
@@ -637,12 +607,12 @@ const plugin = {
|
|
|
637
607
|
log.info("Google Chat plugin registered");
|
|
638
608
|
},
|
|
639
609
|
deactivate(api) {
|
|
640
|
-
globalThis.__alfeGoogleChatActivated = false;
|
|
641
610
|
const log = api.logger;
|
|
642
611
|
poller?.stop();
|
|
643
612
|
poller = null;
|
|
644
613
|
pluginRuntime = null;
|
|
645
614
|
dispatchInbound = null;
|
|
615
|
+
(0, _alfe_ai_openclaw_plugin_kit.resetActivation)(GCHAT_ACTIVATION_KEY);
|
|
646
616
|
log.info("Google Chat plugin deactivated");
|
|
647
617
|
}
|
|
648
618
|
};
|
package/dist/plugin2.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { dirname, join, resolve } from "node:path";
|
|
3
2
|
import { resolveConfig } from "@alfe.ai/config";
|
|
4
3
|
import { AgentApiClient } from "@alfe.ai/agent-api-client";
|
|
4
|
+
import { getActivationKey, guardedStart, resetActivation, resolveOpenClawSdk } from "@alfe.ai/openclaw-plugin-kit";
|
|
5
5
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
6
|
+
import { join } from "node:path";
|
|
6
7
|
import { homedir } from "node:os";
|
|
7
8
|
//#region src/gchat-state.ts
|
|
8
9
|
/**
|
|
@@ -532,34 +533,9 @@ function isTokenRevokedError(err) {
|
|
|
532
533
|
* → dispatchInboundDirectDmWithRuntime() → Agent pipeline
|
|
533
534
|
* ← deliver() callback → Google Chat API (reply as user)
|
|
534
535
|
*/
|
|
535
|
-
const
|
|
536
|
-
const pkg = require("../package.json");
|
|
536
|
+
const pkg = createRequire(import.meta.url)("../package.json");
|
|
537
537
|
let dispatchInbound = null;
|
|
538
|
-
|
|
539
|
-
* Resolve OpenClaw SDK from the running process.
|
|
540
|
-
* Copied from @alfe.ai/openclaw-chat's resolution strategy.
|
|
541
|
-
*/
|
|
542
|
-
function resolveOpenClawSdk(log) {
|
|
543
|
-
const anchors = [require.main?.filename, process.argv[1]].filter(Boolean);
|
|
544
|
-
for (const anchor of anchors) try {
|
|
545
|
-
const channelInbound = createRequire(anchor)("openclaw/plugin-sdk/channel-inbound");
|
|
546
|
-
if (channelInbound.dispatchInboundDirectDmWithRuntime) {
|
|
547
|
-
dispatchInbound = channelInbound.dispatchInboundDirectDmWithRuntime;
|
|
548
|
-
log.info(`Resolved OpenClaw SDK from ${anchor}`);
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
} catch {}
|
|
552
|
-
try {
|
|
553
|
-
const derivedPath = join(resolve(dirname(process.execPath), ".."), "lib", "node_modules", "openclaw", "package.json");
|
|
554
|
-
const channelInbound = createRequire(derivedPath)("openclaw/plugin-sdk/channel-inbound");
|
|
555
|
-
if (channelInbound.dispatchInboundDirectDmWithRuntime) {
|
|
556
|
-
dispatchInbound = channelInbound.dispatchInboundDirectDmWithRuntime;
|
|
557
|
-
log.info(`Resolved OpenClaw SDK from ${derivedPath}`);
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
} catch {}
|
|
561
|
-
log.warn("OpenClaw SDK not resolvable — Google Chat dispatch will not work");
|
|
562
|
-
}
|
|
538
|
+
const GCHAT_ACTIVATION_KEY = getActivationKey("google-chat");
|
|
563
539
|
let pluginRuntime = null;
|
|
564
540
|
let poller = null;
|
|
565
541
|
const plugin = {
|
|
@@ -569,66 +545,60 @@ const plugin = {
|
|
|
569
545
|
version: pkg.version,
|
|
570
546
|
activate(api) {
|
|
571
547
|
const log = api.logger;
|
|
572
|
-
const startService =
|
|
573
|
-
|
|
574
|
-
log.
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
poller = new GChatPoller(init);
|
|
614
|
-
await poller.start();
|
|
615
|
-
log.info(`Google Chat poller started (account: ${creds.email})`);
|
|
548
|
+
const startService = () => {
|
|
549
|
+
guardedStart(GCHAT_ACTIVATION_KEY, log, async () => {
|
|
550
|
+
log.info("Google Chat plugin starting...");
|
|
551
|
+
dispatchInbound = resolveOpenClawSdk(log, { unresolvableNote: "OpenClaw SDK not resolvable — Google Chat dispatch will not work" });
|
|
552
|
+
pluginRuntime = api.runtime ?? null;
|
|
553
|
+
let client;
|
|
554
|
+
try {
|
|
555
|
+
const cfg = resolveConfig();
|
|
556
|
+
client = new AgentApiClient({
|
|
557
|
+
apiKey: cfg.apiKey,
|
|
558
|
+
apiUrl: cfg.apiUrl
|
|
559
|
+
});
|
|
560
|
+
} catch (err) {
|
|
561
|
+
resetActivation(GCHAT_ACTIVATION_KEY);
|
|
562
|
+
log.error(`Failed to resolve config: ${err instanceof Error ? err.message : String(err)}`);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
let creds;
|
|
566
|
+
try {
|
|
567
|
+
creds = await client.getGoogleChatCredentials();
|
|
568
|
+
} catch (err) {
|
|
569
|
+
resetActivation(GCHAT_ACTIVATION_KEY);
|
|
570
|
+
log.info(`Google Chat not connected — polling disabled (${err instanceof Error ? err.message : String(err)})`);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
const init = {
|
|
574
|
+
tokenManager: new (await (import("./gchat-token.js"))).TokenManager({
|
|
575
|
+
refreshToken: creds.refreshToken,
|
|
576
|
+
clientId: creds.clientId,
|
|
577
|
+
clientSecret: creds.clientSecret
|
|
578
|
+
}, log),
|
|
579
|
+
dispatchInbound,
|
|
580
|
+
runtime: pluginRuntime,
|
|
581
|
+
log,
|
|
582
|
+
agentEmail: creds.email
|
|
583
|
+
};
|
|
584
|
+
init.agentClient = client;
|
|
585
|
+
poller = new GChatPoller(init);
|
|
586
|
+
await poller.start();
|
|
587
|
+
log.info(`Google Chat poller started (account: ${creds.email})`);
|
|
588
|
+
});
|
|
616
589
|
};
|
|
617
590
|
const stopService = () => {
|
|
618
|
-
globalThis.__alfeGoogleChatActivated = false;
|
|
619
591
|
poller?.stop();
|
|
620
592
|
poller = null;
|
|
621
593
|
pluginRuntime = null;
|
|
622
594
|
dispatchInbound = null;
|
|
595
|
+
resetActivation(GCHAT_ACTIVATION_KEY);
|
|
623
596
|
log.info("Google Chat plugin stopped");
|
|
624
597
|
};
|
|
625
598
|
api.registerService({
|
|
626
599
|
id: "google-chat-poller",
|
|
627
600
|
start: () => {
|
|
628
|
-
startService()
|
|
629
|
-
globalThis.__alfeGoogleChatActivated = false;
|
|
630
|
-
log.error(`Google Chat service start failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
631
|
-
});
|
|
601
|
+
startService();
|
|
632
602
|
},
|
|
633
603
|
stop: () => {
|
|
634
604
|
stopService();
|
|
@@ -637,12 +607,12 @@ const plugin = {
|
|
|
637
607
|
log.info("Google Chat plugin registered");
|
|
638
608
|
},
|
|
639
609
|
deactivate(api) {
|
|
640
|
-
globalThis.__alfeGoogleChatActivated = false;
|
|
641
610
|
const log = api.logger;
|
|
642
611
|
poller?.stop();
|
|
643
612
|
poller = null;
|
|
644
613
|
pluginRuntime = null;
|
|
645
614
|
dispatchInbound = null;
|
|
615
|
+
resetActivation(GCHAT_ACTIVATION_KEY);
|
|
646
616
|
log.info("Google Chat plugin deactivated");
|
|
647
617
|
}
|
|
648
618
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alfe.ai/openclaw-google-chat",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"description": "OpenClaw Google Chat plugin — DM polling and auto-reply via connected Google account",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/plugin.js",
|
|
@@ -27,8 +27,9 @@
|
|
|
27
27
|
"openclaw.plugin.json"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@alfe.ai/agent-api-client": "^0.
|
|
31
|
-
"@alfe.ai/config": "^0.
|
|
30
|
+
"@alfe.ai/agent-api-client": "^0.14.0",
|
|
31
|
+
"@alfe.ai/config": "^0.4.0",
|
|
32
|
+
"@alfe.ai/openclaw-plugin-kit": "0.1.0"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
|
34
35
|
"openclaw": ">=2026.3.0"
|