@alfe.ai/openclaw-google 0.0.41 → 0.0.43

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.js CHANGED
@@ -1,191 +1,2 @@
1
- import { createRequire } from "node:module";
2
- import { Type } from "@sinclair/typebox";
3
- import { resolveConfig } from "@alfe.ai/config";
4
- import { AgentApiClient, installToolErrorCapture } from "@alfe.ai/agent-api-client";
5
- import { defineTool, getActivationKey, guardedStart, resetActivation } from "@alfe.ai/openclaw-plugin-kit";
6
- import { execFile } from "node:child_process";
7
- import { join } from "node:path";
8
- import { homedir } from "node:os";
9
- //#region src/plugin.ts
10
- /**
11
- * @alfe/openclaw-google — OpenClaw native plugin
12
- *
13
- * Registers Google Workspace account management tools with OpenClaw.
14
- * Multi-account by design — every gws command requires an explicit
15
- * `email` (schema-enforced) so the LLM picks the target account per call.
16
- *
17
- * Tools:
18
- * - google_list_accounts — list connected Google accounts
19
- * - google_run_command — run a gws command (requires email)
20
- * - google_disconnect_account — disconnect an account
21
- *
22
- * 2026-05-14 (connections-redesign PR 1): the "default account" concept is
23
- * gone. Use `google_list_accounts` to discover available accounts, then
24
- * pass `email` to `google_run_command` to target one.
25
- */
26
- const pkg = createRequire(import.meta.url)("../package.json");
27
- const GOOGLE_ACTIVATION_KEY = getActivationKey("google");
28
- function sanitizeEmail(email) {
29
- return email.replace(/@/g, "-").replace(/\./g, "-");
30
- }
31
- function resolveConfigDir(email) {
32
- return join(homedir(), ".config", `gws-${sanitizeEmail(email)}`);
33
- }
34
- let client = null;
35
- let cachedAccounts = [];
36
- function getClient() {
37
- if (!client) {
38
- const config = resolveConfig();
39
- client = new AgentApiClient({
40
- apiKey: config.apiKey,
41
- apiUrl: config.apiUrl
42
- });
43
- }
44
- return client;
45
- }
46
- async function refreshAccountCache() {
47
- cachedAccounts = (await getClient().getGoogleCredentials()).accounts.map((a) => ({
48
- email: a.email,
49
- displayName: a.displayName,
50
- connectedAt: a.connectedAt,
51
- configDir: resolveConfigDir(a.email)
52
- }));
53
- return cachedAccounts;
54
- }
55
- function findAccount(email) {
56
- const account = cachedAccounts.find((a) => a.email === email);
57
- if (!account) throw new Error(`Google account "${email}" not found. Available: ${cachedAccounts.map((a) => a.email).join(", ")}`);
58
- return account;
59
- }
60
- function runGwsCommand(args, configDir) {
61
- return new Promise((resolve) => {
62
- execFile("gws", args, {
63
- env: {
64
- ...process.env,
65
- GOOGLE_WORKSPACE_CLI_CONFIG_DIR: configDir
66
- },
67
- timeout: 6e4,
68
- maxBuffer: 10 * 1024 * 1024
69
- }, (error, stdout, stderr) => {
70
- resolve({
71
- stdout,
72
- stderr,
73
- exitCode: typeof error?.code === "number" ? error.code : error ? 1 : 0
74
- });
75
- });
76
- });
77
- }
78
- const googleTools = [
79
- defineTool({
80
- name: "google_list_accounts",
81
- description: "List all connected Google Workspace accounts. Shows email, display name, when each account was connected, and the gws CLI config directory path. Use this to resolve which account to target (e.g., 'Kevin\\'s emails' → kevin@alfe.ai).",
82
- parameters: Type.Object({}),
83
- handler: async () => {
84
- const accounts = await refreshAccountCache();
85
- return {
86
- accounts: accounts.map((a) => ({
87
- email: a.email,
88
- displayName: a.displayName,
89
- connectedAt: a.connectedAt,
90
- configDir: a.configDir
91
- })),
92
- count: accounts.length
93
- };
94
- }
95
- }),
96
- defineTool({
97
- name: "google_run_command",
98
- description: "Run a gws (Google Workspace CLI) command targeting a specific account. Automatically sets GOOGLE_WORKSPACE_CLI_CONFIG_DIR for the target account. Email is required — call google_list_accounts first if you don't know which account to use. Example: google_run_command({ command: 'gmail list', email: 'kevin@alfe.ai' })",
99
- parameters: Type.Object({
100
- command: Type.String({ description: "The gws CLI command and arguments (e.g., 'gmail list', 'calendar agenda', 'drive list')" }),
101
- email: Type.String({ description: "Email of the Google account to use. Required — there is no implicit default." })
102
- }),
103
- handler: async (params) => {
104
- const { command, email } = params;
105
- if (cachedAccounts.length === 0) await refreshAccountCache();
106
- const account = findAccount(email);
107
- const args = command.split(/\s+/).filter(Boolean);
108
- if (args.length === 0) throw new Error("Command cannot be empty");
109
- const result = await runGwsCommand(args, account.configDir);
110
- return {
111
- account: account.email,
112
- command: `gws ${command}`,
113
- ...result
114
- };
115
- }
116
- }),
117
- defineTool({
118
- name: "google_disconnect_account",
119
- description: "Disconnect a specific Google account from this agent. Revokes the OAuth token and removes the account.",
120
- parameters: Type.Object({ email: Type.String({ description: "Email of the Google account to disconnect" }) }),
121
- handler: async (params) => {
122
- const { email } = params;
123
- const result = await getClient().disconnectGoogleAccount(email);
124
- await refreshAccountCache();
125
- return {
126
- message: `${email} has been disconnected`,
127
- remainingAccounts: result.accounts
128
- };
129
- }
130
- })
131
- ];
132
- const plugin = {
133
- id: "@alfe.ai/openclaw-google",
134
- name: "Alfe Google Workspace Plugin",
135
- description: "Multi-account Google Workspace management — list accounts and run gws commands with an explicit account selector",
136
- version: pkg.version,
137
- activate(api) {
138
- installToolErrorCapture(api, { plugin: "openclaw-google" });
139
- const log = api.logger;
140
- for (const tool of googleTools) api.registerTool(tool);
141
- log.info(`Registered ${googleTools.length.toString()} Google tools: ${googleTools.map((t) => t.name).join(", ")}`);
142
- const startGoogleService = () => {
143
- guardedStart(GOOGLE_ACTIVATION_KEY, log, () => {
144
- log.info("Alfe Google Workspace plugin activating...");
145
- try {
146
- const config = resolveConfig();
147
- client = new AgentApiClient({
148
- apiKey: config.apiKey,
149
- apiUrl: config.apiUrl
150
- });
151
- refreshAccountCache().then((accounts) => {
152
- log.info(`Cached ${accounts.length.toString()} Google account(s): ${accounts.map((a) => a.email).join(", ")}`);
153
- }).catch((err) => {
154
- log.warn(`Failed to pre-cache Google accounts: ${err instanceof Error ? err.message : "unknown"}`);
155
- });
156
- } catch (err) {
157
- log.error(`Failed to resolve config: ${err instanceof Error ? err.message : "unknown"}`);
158
- log.warn("Google tools will fail — no API config available");
159
- resetActivation(GOOGLE_ACTIVATION_KEY);
160
- return;
161
- }
162
- log.info("Alfe Google Workspace plugin activated");
163
- });
164
- };
165
- const stopGoogleService = () => {
166
- client = null;
167
- cachedAccounts = [];
168
- resetActivation(GOOGLE_ACTIVATION_KEY);
169
- log.info("Alfe Google Workspace plugin stopped");
170
- };
171
- if (api.registerService) api.registerService({
172
- id: "alfe-google-workspace",
173
- start: () => {
174
- startGoogleService();
175
- },
176
- stop: () => {
177
- stopGoogleService();
178
- }
179
- });
180
- },
181
- deactivate(api) {
182
- client = null;
183
- cachedAccounts = [];
184
- resetActivation(GOOGLE_ACTIVATION_KEY);
185
- api.logger.info("Alfe Google Workspace plugin deactivated");
186
- }
187
- };
188
- //#endregion
1
+ import { t as plugin } from "./plugin2.js";
189
2
  export { plugin as default };
190
-
191
- //# sourceMappingURL=plugin.js.map