@alfe.ai/openclaw-google-chat 0.0.2 → 0.0.4

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.
@@ -0,0 +1,59 @@
1
+ //#region src/gchat-token.ts
2
+ const GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
3
+ const REFRESH_MARGIN_MS = 300 * 1e3;
4
+ var TokenManager = class {
5
+ refreshToken;
6
+ clientId;
7
+ clientSecret;
8
+ log;
9
+ cached = null;
10
+ refreshPromise = null;
11
+ constructor(init, log) {
12
+ this.refreshToken = init.refreshToken;
13
+ this.clientId = init.clientId;
14
+ this.clientSecret = init.clientSecret;
15
+ this.log = log;
16
+ }
17
+ /** Get a valid access token, refreshing if needed. */
18
+ async getAccessToken() {
19
+ if (this.cached && Date.now() < this.cached.expiresAt - REFRESH_MARGIN_MS) return this.cached.accessToken;
20
+ if (this.refreshPromise) return this.refreshPromise;
21
+ this.refreshPromise = this.doRefresh();
22
+ try {
23
+ return await this.refreshPromise;
24
+ } finally {
25
+ this.refreshPromise = null;
26
+ }
27
+ }
28
+ /** Invalidate the current token (call after a 401). */
29
+ invalidate() {
30
+ this.cached = null;
31
+ }
32
+ async doRefresh() {
33
+ this.log.debug("Refreshing Google access token");
34
+ const response = await fetch(GOOGLE_TOKEN_URL, {
35
+ method: "POST",
36
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
37
+ body: new URLSearchParams({
38
+ client_id: this.clientId,
39
+ client_secret: this.clientSecret,
40
+ refresh_token: this.refreshToken,
41
+ grant_type: "refresh_token"
42
+ })
43
+ });
44
+ if (!response.ok) {
45
+ const body = await response.text().catch(() => "");
46
+ this.log.error(`Token refresh failed (${String(response.status)}): ${body}`);
47
+ throw new Error(`Google token refresh failed: ${String(response.status)}`);
48
+ }
49
+ const data = await response.json();
50
+ this.cached = {
51
+ accessToken: data.access_token,
52
+ expiresAt: Date.now() + data.expires_in * 1e3
53
+ };
54
+ this.log.debug("Google access token refreshed");
55
+ return this.cached.accessToken;
56
+ }
57
+ };
58
+ //#endregion
59
+ exports.TokenManager = TokenManager;
@@ -0,0 +1,59 @@
1
+ //#region src/gchat-token.ts
2
+ const GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
3
+ const REFRESH_MARGIN_MS = 300 * 1e3;
4
+ var TokenManager = class {
5
+ refreshToken;
6
+ clientId;
7
+ clientSecret;
8
+ log;
9
+ cached = null;
10
+ refreshPromise = null;
11
+ constructor(init, log) {
12
+ this.refreshToken = init.refreshToken;
13
+ this.clientId = init.clientId;
14
+ this.clientSecret = init.clientSecret;
15
+ this.log = log;
16
+ }
17
+ /** Get a valid access token, refreshing if needed. */
18
+ async getAccessToken() {
19
+ if (this.cached && Date.now() < this.cached.expiresAt - REFRESH_MARGIN_MS) return this.cached.accessToken;
20
+ if (this.refreshPromise) return this.refreshPromise;
21
+ this.refreshPromise = this.doRefresh();
22
+ try {
23
+ return await this.refreshPromise;
24
+ } finally {
25
+ this.refreshPromise = null;
26
+ }
27
+ }
28
+ /** Invalidate the current token (call after a 401). */
29
+ invalidate() {
30
+ this.cached = null;
31
+ }
32
+ async doRefresh() {
33
+ this.log.debug("Refreshing Google access token");
34
+ const response = await fetch(GOOGLE_TOKEN_URL, {
35
+ method: "POST",
36
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
37
+ body: new URLSearchParams({
38
+ client_id: this.clientId,
39
+ client_secret: this.clientSecret,
40
+ refresh_token: this.refreshToken,
41
+ grant_type: "refresh_token"
42
+ })
43
+ });
44
+ if (!response.ok) {
45
+ const body = await response.text().catch(() => "");
46
+ this.log.error(`Token refresh failed (${String(response.status)}): ${body}`);
47
+ throw new Error(`Google token refresh failed: ${String(response.status)}`);
48
+ }
49
+ const data = await response.json();
50
+ this.cached = {
51
+ accessToken: data.access_token,
52
+ expiresAt: Date.now() + data.expires_in * 1e3
53
+ };
54
+ this.log.debug("Google access token refreshed");
55
+ return this.cached.accessToken;
56
+ }
57
+ };
58
+ //#endregion
59
+ export { TokenManager };
package/dist/index.cjs CHANGED
@@ -1,3 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_google_chat_channel = require("./google-chat-channel.cjs");
3
- exports.createGoogleChatChannelPlugin = require_google_chat_channel.createGoogleChatChannelPlugin;
1
+ const require_plugin = require("./plugin2.cjs");
2
+ module.exports = require_plugin.plugin;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,2 @@
1
- import { t as createGoogleChatChannelPlugin } from "./google-chat-channel.cjs";
2
-
3
- //#region src/types.d.ts
4
- /** OpenClaw config shape for the Google Chat channel. */
5
- interface GoogleChatChannelConfig {
6
- workspaceDomain?: string;
7
- email?: string;
8
- }
9
- //# sourceMappingURL=types.d.ts.map
10
- //#endregion
11
- export { type GoogleChatChannelConfig, createGoogleChatChannelPlugin };
12
- //# sourceMappingURL=index.d.cts.map
1
+ import plugin from "./plugin.cjs";
2
+ export { plugin as default };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,2 @@
1
- import { t as createGoogleChatChannelPlugin } from "./google-chat-channel.js";
2
-
3
- //#region src/types.d.ts
4
- /** OpenClaw config shape for the Google Chat channel. */
5
- interface GoogleChatChannelConfig {
6
- workspaceDomain?: string;
7
- email?: string;
8
- }
9
- //# sourceMappingURL=types.d.ts.map
10
- //#endregion
11
- export { type GoogleChatChannelConfig, createGoogleChatChannelPlugin };
12
- //# sourceMappingURL=index.d.ts.map
1
+ import plugin from "./plugin.js";
2
+ export { plugin as default };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as createGoogleChatChannelPlugin } from "./google-chat-channel.js";
2
- export { createGoogleChatChannelPlugin };
1
+ import { t as plugin } from "./plugin2.js";
2
+ export { plugin as default };
package/dist/plugin.cjs CHANGED
@@ -1,28 +1,2 @@
1
- const require_google_chat_channel = require("./google-chat-channel.cjs");
2
- //#region src/plugin.ts
3
- /**
4
- * @alfe.ai/openclaw-google-chat — OpenClaw Google Chat channel plugin.
5
- *
6
- * Registers the 'google-chat' channel with OpenClaw. This is a lightweight
7
- * metadata-only plugin — all message transport is handled by the backend
8
- * Google service (Lambda) and Google relay (Fly.io).
9
- */
10
- const plugin = {
11
- id: "@alfe.ai/openclaw-google-chat",
12
- name: "Google Chat Plugin",
13
- description: "Google Chat channel — spaces, DMs, and threads via Google Workspace",
14
- version: "0.0.1",
15
- activate(api) {
16
- const log = api.logger;
17
- log.info("Google Chat plugin registering...");
18
- const googleChatChannel = require_google_chat_channel.createGoogleChatChannelPlugin();
19
- api.registerChannel(googleChatChannel);
20
- log.info(`Registered channel: ${googleChatChannel.id}`);
21
- log.info("Google Chat plugin registered");
22
- },
23
- deactivate(api) {
24
- api.logger.info("Google Chat plugin deactivated");
25
- }
26
- };
27
- //#endregion
28
- module.exports = plugin;
1
+ const require_plugin = require("./plugin2.cjs");
2
+ module.exports = require_plugin.plugin;
package/dist/plugin.d.cts CHANGED
@@ -1,16 +1,48 @@
1
- import { t as createGoogleChatChannelPlugin } from "./google-chat-channel.cjs";
2
-
3
1
  //#region src/plugin.d.ts
4
-
2
+ /**
3
+ * @alfe.ai/openclaw-google-chat — OpenClaw Google Chat channel plugin.
4
+ *
5
+ * Polls Google Chat DM spaces and dispatches user messages through
6
+ * OpenClaw's auto-reply pipeline via dispatchInboundDirectDmWithRuntime().
7
+ * Replies are sent back to Google Chat as the connected user.
8
+ *
9
+ * Architecture:
10
+ * Google Chat API (poll every 1-30s)
11
+ * → GChatPoller
12
+ * → dispatchInboundDirectDmWithRuntime() → Agent pipeline
13
+ * ← deliver() callback → Google Chat API (reply as user)
14
+ */
5
15
  interface PluginLogger {
6
16
  info(msg: string, ...args: unknown[]): void;
7
17
  warn(msg: string, ...args: unknown[]): void;
8
18
  error(msg: string, ...args: unknown[]): void;
9
19
  debug(msg: string, ...args: unknown[]): void;
10
20
  }
21
+ interface PluginRuntime {
22
+ config: {
23
+ loadConfig(): Record<string, unknown>;
24
+ };
25
+ channel: unknown;
26
+ }
27
+ interface PluginServiceContext {
28
+ config: Record<string, unknown>;
29
+ workspaceDir?: string;
30
+ stateDir: string;
31
+ logger: PluginLogger;
32
+ }
11
33
  interface PluginApi {
12
34
  logger: PluginLogger;
13
- registerChannel(channel: ReturnType<typeof createGoogleChatChannelPlugin>): void;
35
+ registrationMode?: 'full' | 'setup-only' | 'setup-runtime' | 'cli-metadata';
36
+ config?: Record<string, unknown>;
37
+ runtime?: PluginRuntime;
38
+ registerService?(service: {
39
+ id: string;
40
+ start: (ctx: PluginServiceContext) => void | Promise<void>;
41
+ stop?: (ctx: PluginServiceContext) => void | Promise<void>;
42
+ }): void;
43
+ on(event: string, handler: (...args: unknown[]) => void | Promise<void>, options?: {
44
+ priority?: number;
45
+ }): void;
14
46
  }
15
47
  declare const plugin: {
16
48
  id: string;
@@ -21,5 +53,4 @@ declare const plugin: {
21
53
  deactivate(api: PluginApi): void;
22
54
  };
23
55
  //#endregion
24
- export { plugin as default };
25
- //# sourceMappingURL=plugin.d.cts.map
56
+ export { plugin as default };
package/dist/plugin.d.ts CHANGED
@@ -1,16 +1,48 @@
1
- import { t as createGoogleChatChannelPlugin } from "./google-chat-channel.js";
2
-
3
1
  //#region src/plugin.d.ts
4
-
2
+ /**
3
+ * @alfe.ai/openclaw-google-chat — OpenClaw Google Chat channel plugin.
4
+ *
5
+ * Polls Google Chat DM spaces and dispatches user messages through
6
+ * OpenClaw's auto-reply pipeline via dispatchInboundDirectDmWithRuntime().
7
+ * Replies are sent back to Google Chat as the connected user.
8
+ *
9
+ * Architecture:
10
+ * Google Chat API (poll every 1-30s)
11
+ * → GChatPoller
12
+ * → dispatchInboundDirectDmWithRuntime() → Agent pipeline
13
+ * ← deliver() callback → Google Chat API (reply as user)
14
+ */
5
15
  interface PluginLogger {
6
16
  info(msg: string, ...args: unknown[]): void;
7
17
  warn(msg: string, ...args: unknown[]): void;
8
18
  error(msg: string, ...args: unknown[]): void;
9
19
  debug(msg: string, ...args: unknown[]): void;
10
20
  }
21
+ interface PluginRuntime {
22
+ config: {
23
+ loadConfig(): Record<string, unknown>;
24
+ };
25
+ channel: unknown;
26
+ }
27
+ interface PluginServiceContext {
28
+ config: Record<string, unknown>;
29
+ workspaceDir?: string;
30
+ stateDir: string;
31
+ logger: PluginLogger;
32
+ }
11
33
  interface PluginApi {
12
34
  logger: PluginLogger;
13
- registerChannel(channel: ReturnType<typeof createGoogleChatChannelPlugin>): void;
35
+ registrationMode?: 'full' | 'setup-only' | 'setup-runtime' | 'cli-metadata';
36
+ config?: Record<string, unknown>;
37
+ runtime?: PluginRuntime;
38
+ registerService?(service: {
39
+ id: string;
40
+ start: (ctx: PluginServiceContext) => void | Promise<void>;
41
+ stop?: (ctx: PluginServiceContext) => void | Promise<void>;
42
+ }): void;
43
+ on(event: string, handler: (...args: unknown[]) => void | Promise<void>, options?: {
44
+ priority?: number;
45
+ }): void;
14
46
  }
15
47
  declare const plugin: {
16
48
  id: string;
@@ -21,5 +53,4 @@ declare const plugin: {
21
53
  deactivate(api: PluginApi): void;
22
54
  };
23
55
  //#endregion
24
- export { plugin as default };
25
- //# sourceMappingURL=plugin.d.ts.map
56
+ export { plugin as default };
package/dist/plugin.js CHANGED
@@ -1,30 +1,2 @@
1
- import { t as createGoogleChatChannelPlugin } from "./google-chat-channel.js";
2
- //#region src/plugin.ts
3
- /**
4
- * @alfe.ai/openclaw-google-chat — OpenClaw Google Chat channel plugin.
5
- *
6
- * Registers the 'google-chat' channel with OpenClaw. This is a lightweight
7
- * metadata-only plugin — all message transport is handled by the backend
8
- * Google service (Lambda) and Google relay (Fly.io).
9
- */
10
- const plugin = {
11
- id: "@alfe.ai/openclaw-google-chat",
12
- name: "Google Chat Plugin",
13
- description: "Google Chat channel — spaces, DMs, and threads via Google Workspace",
14
- version: "0.0.1",
15
- activate(api) {
16
- const log = api.logger;
17
- log.info("Google Chat plugin registering...");
18
- const googleChatChannel = createGoogleChatChannelPlugin();
19
- api.registerChannel(googleChatChannel);
20
- log.info(`Registered channel: ${googleChatChannel.id}`);
21
- log.info("Google Chat plugin registered");
22
- },
23
- deactivate(api) {
24
- api.logger.info("Google Chat plugin deactivated");
25
- }
26
- };
27
- //#endregion
1
+ import { t as plugin } from "./plugin2.js";
28
2
  export { plugin as default };
29
-
30
- //# sourceMappingURL=plugin.js.map