mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-07 22:09:57 +00:00
chore: Run pnpm format:fix.
This commit is contained in:
@@ -33,7 +33,8 @@ function listEnabledAccounts(cfg: OpenClawConfig) {
|
||||
function isReactionsEnabled(accounts: ReturnType<typeof listEnabledAccounts>, cfg: OpenClawConfig) {
|
||||
for (const account of accounts) {
|
||||
const gate = createActionGate(
|
||||
(account.config.actions ?? (cfg.channels?.["googlechat"] as { actions?: unknown })?.actions) as Record<
|
||||
(account.config.actions ??
|
||||
(cfg.channels?.["googlechat"] as { actions?: unknown })?.actions) as Record<
|
||||
string,
|
||||
boolean | undefined
|
||||
>,
|
||||
@@ -103,7 +104,12 @@ export const googlechatMessageActions: ChannelMessageActionAdapter = {
|
||||
text: content,
|
||||
thread: threadId ?? undefined,
|
||||
attachments: upload.attachmentUploadToken
|
||||
? [{ attachmentUploadToken: upload.attachmentUploadToken, contentName: loaded.filename }]
|
||||
? [
|
||||
{
|
||||
attachmentUploadToken: upload.attachmentUploadToken,
|
||||
contentName: loaded.filename,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
});
|
||||
return jsonResult({ ok: true, to: space });
|
||||
|
||||
@@ -90,7 +90,8 @@ export async function verifyGoogleChatRequest(params: {
|
||||
});
|
||||
const payload = ticket.getPayload();
|
||||
const email = payload?.email ?? "";
|
||||
const ok = payload?.email_verified && (email === CHAT_ISSUER || ADDON_ISSUER_PATTERN.test(email));
|
||||
const ok =
|
||||
payload?.email_verified && (email === CHAT_ISSUER || ADDON_ISSUER_PATTERN.test(email));
|
||||
return ok ? { ok: true } : { ok: false, reason: `invalid issuer: ${email}` };
|
||||
} catch (err) {
|
||||
return { ok: false, reason: err instanceof Error ? err.message : "invalid token" };
|
||||
|
||||
@@ -59,7 +59,8 @@ export const googlechatDock: ChannelDock = {
|
||||
outbound: { textChunkLimit: 4000 },
|
||||
config: {
|
||||
resolveAllowFrom: ({ cfg, accountId }) =>
|
||||
(resolveGoogleChatAccount({ cfg: cfg as OpenClawConfig, accountId }).config.dm?.allowFrom ??
|
||||
(
|
||||
resolveGoogleChatAccount({ cfg: cfg as OpenClawConfig, accountId }).config.dm?.allowFrom ??
|
||||
[]
|
||||
).map((entry) => String(entry)),
|
||||
formatAllowFrom: ({ allowFrom }) =>
|
||||
@@ -166,10 +167,11 @@ export const googlechatPlugin: ChannelPlugin<ResolvedGoogleChatAccount> = {
|
||||
credentialSource: account.credentialSource,
|
||||
}),
|
||||
resolveAllowFrom: ({ cfg, accountId }) =>
|
||||
(resolveGoogleChatAccount({
|
||||
cfg: cfg as OpenClawConfig,
|
||||
accountId,
|
||||
}).config.dm?.allowFrom ?? []
|
||||
(
|
||||
resolveGoogleChatAccount({
|
||||
cfg: cfg as OpenClawConfig,
|
||||
accountId,
|
||||
}).config.dm?.allowFrom ?? []
|
||||
).map((entry) => String(entry)),
|
||||
formatAllowFrom: ({ allowFrom }) =>
|
||||
allowFrom
|
||||
@@ -342,7 +344,7 @@ export const googlechatPlugin: ChannelPlugin<ResolvedGoogleChatAccount> = {
|
||||
...next,
|
||||
channels: {
|
||||
...next.channels,
|
||||
"googlechat": {
|
||||
googlechat: {
|
||||
...(next.channels?.["googlechat"] ?? {}),
|
||||
enabled: true,
|
||||
...configPatch,
|
||||
@@ -354,7 +356,7 @@ export const googlechatPlugin: ChannelPlugin<ResolvedGoogleChatAccount> = {
|
||||
...next,
|
||||
channels: {
|
||||
...next.channels,
|
||||
"googlechat": {
|
||||
googlechat: {
|
||||
...(next.channels?.["googlechat"] ?? {}),
|
||||
enabled: true,
|
||||
accounts: {
|
||||
@@ -372,8 +374,7 @@ export const googlechatPlugin: ChannelPlugin<ResolvedGoogleChatAccount> = {
|
||||
},
|
||||
outbound: {
|
||||
deliveryMode: "direct",
|
||||
chunker: (text, limit) =>
|
||||
getGoogleChatRuntime().channel.text.chunkMarkdownText(text, limit),
|
||||
chunker: (text, limit) => getGoogleChatRuntime().channel.text.chunkMarkdownText(text, limit),
|
||||
chunkerMode: "markdown",
|
||||
textChunkLimit: 4000,
|
||||
resolveTarget: ({ to, allowFrom, mode }) => {
|
||||
@@ -445,8 +446,11 @@ export const googlechatPlugin: ChannelPlugin<ResolvedGoogleChatAccount> = {
|
||||
const maxBytes = resolveChannelMediaMaxBytes({
|
||||
cfg: cfg as OpenClawConfig,
|
||||
resolveChannelLimitMb: ({ cfg, accountId }) =>
|
||||
(cfg.channels?.["googlechat"] as { accounts?: Record<string, { mediaMaxMb?: number }>; mediaMaxMb?: number } | undefined)
|
||||
?.accounts?.[accountId]?.mediaMaxMb ??
|
||||
(
|
||||
cfg.channels?.["googlechat"] as
|
||||
| { accounts?: Record<string, { mediaMaxMb?: number }>; mediaMaxMb?: number }
|
||||
| undefined
|
||||
)?.accounts?.[accountId]?.mediaMaxMb ??
|
||||
(cfg.channels?.["googlechat"] as { mediaMaxMb?: number } | undefined)?.mediaMaxMb,
|
||||
accountId,
|
||||
});
|
||||
|
||||
@@ -4,15 +4,11 @@ import { isSenderAllowed } from "./monitor.js";
|
||||
|
||||
describe("isSenderAllowed", () => {
|
||||
it("matches allowlist entries with users/<email>", () => {
|
||||
expect(
|
||||
isSenderAllowed("users/123", "Jane@Example.com", ["users/jane@example.com"]),
|
||||
).toBe(true);
|
||||
expect(isSenderAllowed("users/123", "Jane@Example.com", ["users/jane@example.com"])).toBe(true);
|
||||
});
|
||||
|
||||
it("matches allowlist entries with raw email", () => {
|
||||
expect(isSenderAllowed("users/123", "Jane@Example.com", ["jane@example.com"])).toBe(
|
||||
true,
|
||||
);
|
||||
expect(isSenderAllowed("users/123", "Jane@Example.com", ["jane@example.com"])).toBe(true);
|
||||
});
|
||||
|
||||
it("still matches user id entries", () => {
|
||||
|
||||
@@ -3,9 +3,7 @@ import type { IncomingMessage, ServerResponse } from "node:http";
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
||||
import { resolveMentionGatingWithBypass } from "openclaw/plugin-sdk";
|
||||
|
||||
import {
|
||||
type ResolvedGoogleChatAccount
|
||||
} from "./accounts.js";
|
||||
import { type ResolvedGoogleChatAccount } from "./accounts.js";
|
||||
import {
|
||||
downloadGoogleChatMedia,
|
||||
deleteGoogleChatMessage,
|
||||
@@ -143,7 +141,11 @@ function normalizeAudienceType(value?: string | null): GoogleChatAudienceType |
|
||||
if (normalized === "app-url" || normalized === "app_url" || normalized === "app") {
|
||||
return "app-url";
|
||||
}
|
||||
if (normalized === "project-number" || normalized === "project_number" || normalized === "project") {
|
||||
if (
|
||||
normalized === "project-number" ||
|
||||
normalized === "project_number" ||
|
||||
normalized === "project"
|
||||
) {
|
||||
return "project-number";
|
||||
}
|
||||
return undefined;
|
||||
@@ -205,7 +207,7 @@ export async function handleGoogleChatWebhookRequest(
|
||||
user: chat.user,
|
||||
eventTime: chat.eventTime,
|
||||
};
|
||||
|
||||
|
||||
// For Add-ons, the bearer token may be in authorizationEventObject.systemIdToken
|
||||
const systemIdToken = rawObj.authorizationEventObject?.systemIdToken;
|
||||
if (!bearer && systemIdToken) {
|
||||
@@ -322,7 +324,16 @@ export function isSenderAllowed(
|
||||
function resolveGroupConfig(params: {
|
||||
groupId: string;
|
||||
groupName?: string | null;
|
||||
groups?: Record<string, { requireMention?: boolean; allow?: boolean; enabled?: boolean; users?: Array<string | number>; systemPrompt?: string }>;
|
||||
groups?: Record<
|
||||
string,
|
||||
{
|
||||
requireMention?: boolean;
|
||||
allow?: boolean;
|
||||
enabled?: boolean;
|
||||
users?: Array<string | number>;
|
||||
systemPrompt?: string;
|
||||
}
|
||||
>;
|
||||
}) {
|
||||
const { groupId, groupName, groups } = params;
|
||||
const entries = groups ?? {};
|
||||
@@ -429,8 +440,7 @@ async function processMessageWithPipeline(params: {
|
||||
return;
|
||||
}
|
||||
const groupAllowlistConfigured = groupConfigResolved.allowlistConfigured;
|
||||
const groupAllowed =
|
||||
Boolean(groupEntry) || Boolean((account.config.groups ?? {})["*"]);
|
||||
const groupAllowed = Boolean(groupEntry) || Boolean((account.config.groups ?? {})["*"]);
|
||||
if (groupPolicy === "allowlist") {
|
||||
if (!groupAllowlistConfigured) {
|
||||
logVerbose(
|
||||
@@ -451,7 +461,11 @@ async function processMessageWithPipeline(params: {
|
||||
}
|
||||
|
||||
if (groupUsers.length > 0) {
|
||||
const ok = isSenderAllowed(senderId, senderEmail, groupUsers.map((v) => String(v)));
|
||||
const ok = isSenderAllowed(
|
||||
senderId,
|
||||
senderEmail,
|
||||
groupUsers.map((v) => String(v)),
|
||||
);
|
||||
if (!ok) {
|
||||
logVerbose(core, runtime, `drop group message (sender not allowed, ${senderId})`);
|
||||
return;
|
||||
@@ -625,7 +639,7 @@ async function processMessageWithPipeline(params: {
|
||||
MediaPath: mediaPath,
|
||||
MediaType: mediaType,
|
||||
MediaUrl: mediaPath,
|
||||
GroupSpace: isGroup ? space.displayName ?? undefined : undefined,
|
||||
GroupSpace: isGroup ? (space.displayName ?? undefined) : undefined,
|
||||
GroupSystemPrompt: isGroup ? groupSystemPrompt : undefined,
|
||||
OriginatingChannel: "googlechat",
|
||||
OriginatingTo: `googlechat:${spaceId}`,
|
||||
@@ -730,7 +744,8 @@ async function deliverGoogleChatReply(params: {
|
||||
statusSink?: (patch: { lastInboundAt?: number; lastOutboundAt?: number }) => void;
|
||||
typingMessageName?: string;
|
||||
}): Promise<void> {
|
||||
const { payload, account, spaceId, runtime, core, config, statusSink, typingMessageName } = params;
|
||||
const { payload, account, spaceId, runtime, core, config, statusSink, typingMessageName } =
|
||||
params;
|
||||
const mediaList = payload.mediaUrls?.length
|
||||
? payload.mediaUrls
|
||||
: payload.mediaUrl
|
||||
@@ -801,16 +816,8 @@ async function deliverGoogleChatReply(params: {
|
||||
|
||||
if (payload.text) {
|
||||
const chunkLimit = account.config.textChunkLimit ?? 4000;
|
||||
const chunkMode = core.channel.text.resolveChunkMode(
|
||||
config,
|
||||
"googlechat",
|
||||
account.accountId,
|
||||
);
|
||||
const chunks = core.channel.text.chunkMarkdownTextWithMode(
|
||||
payload.text,
|
||||
chunkLimit,
|
||||
chunkMode,
|
||||
);
|
||||
const chunkMode = core.channel.text.resolveChunkMode(config, "googlechat", account.accountId);
|
||||
const chunks = core.channel.text.chunkMarkdownTextWithMode(payload.text, chunkLimit, chunkMode);
|
||||
for (let i = 0; i < chunks.length; i++) {
|
||||
const chunk = chunks[i];
|
||||
try {
|
||||
@@ -882,17 +889,19 @@ export function monitorGoogleChatProvider(options: GoogleChatMonitorOptions): ()
|
||||
return unregister;
|
||||
}
|
||||
|
||||
export async function startGoogleChatMonitor(params: GoogleChatMonitorOptions): Promise<() => void> {
|
||||
export async function startGoogleChatMonitor(
|
||||
params: GoogleChatMonitorOptions,
|
||||
): Promise<() => void> {
|
||||
return monitorGoogleChatProvider(params);
|
||||
}
|
||||
|
||||
export function resolveGoogleChatWebhookPath(params: {
|
||||
account: ResolvedGoogleChatAccount;
|
||||
}): string {
|
||||
return resolveWebhookPath(
|
||||
params.account.config.webhookPath,
|
||||
params.account.config.webhookUrl,
|
||||
) ?? "/googlechat";
|
||||
return (
|
||||
resolveWebhookPath(params.account.config.webhookPath, params.account.config.webhookUrl) ??
|
||||
"/googlechat"
|
||||
);
|
||||
}
|
||||
|
||||
export function computeGoogleChatMediaMaxMb(params: { account: ResolvedGoogleChatAccount }) {
|
||||
|
||||
@@ -31,7 +31,7 @@ function setGoogleChatDmPolicy(cfg: OpenClawConfig, policy: DmPolicy) {
|
||||
...cfg,
|
||||
channels: {
|
||||
...cfg.channels,
|
||||
"googlechat": {
|
||||
googlechat: {
|
||||
...(cfg.channels?.["googlechat"] ?? {}),
|
||||
dm: {
|
||||
...(cfg.channels?.["googlechat"]?.dm ?? {}),
|
||||
@@ -67,7 +67,7 @@ async function promptAllowFrom(params: {
|
||||
...params.cfg,
|
||||
channels: {
|
||||
...params.cfg.channels,
|
||||
"googlechat": {
|
||||
googlechat: {
|
||||
...(params.cfg.channels?.["googlechat"] ?? {}),
|
||||
enabled: true,
|
||||
dm: {
|
||||
@@ -101,7 +101,7 @@ function applyAccountConfig(params: {
|
||||
...cfg,
|
||||
channels: {
|
||||
...cfg.channels,
|
||||
"googlechat": {
|
||||
googlechat: {
|
||||
...(cfg.channels?.["googlechat"] ?? {}),
|
||||
enabled: true,
|
||||
...patch,
|
||||
@@ -113,7 +113,7 @@ function applyAccountConfig(params: {
|
||||
...cfg,
|
||||
channels: {
|
||||
...cfg.channels,
|
||||
"googlechat": {
|
||||
googlechat: {
|
||||
...(cfg.channels?.["googlechat"] ?? {}),
|
||||
enabled: true,
|
||||
accounts: {
|
||||
@@ -137,8 +137,7 @@ async function promptCredentials(params: {
|
||||
const { cfg, prompter, accountId } = params;
|
||||
const envReady =
|
||||
accountId === DEFAULT_ACCOUNT_ID &&
|
||||
(Boolean(process.env[ENV_SERVICE_ACCOUNT]) ||
|
||||
Boolean(process.env[ENV_SERVICE_ACCOUNT_FILE]));
|
||||
(Boolean(process.env[ENV_SERVICE_ACCOUNT]) || Boolean(process.env[ENV_SERVICE_ACCOUNT_FILE]));
|
||||
if (envReady) {
|
||||
const useEnv = await prompter.confirm({
|
||||
message: "Use GOOGLE_CHAT_SERVICE_ACCOUNT env vars?",
|
||||
@@ -173,7 +172,7 @@ async function promptCredentials(params: {
|
||||
|
||||
const json = await prompter.text({
|
||||
message: "Service account JSON (single line)",
|
||||
placeholder: "{\"type\":\"service_account\", ... }",
|
||||
placeholder: '{"type":"service_account", ... }',
|
||||
validate: (value) => (String(value ?? "").trim() ? undefined : "Required"),
|
||||
});
|
||||
return applyAccountConfig({
|
||||
@@ -237,18 +236,11 @@ export const googlechatOnboardingAdapter: ChannelOnboardingAdapter = {
|
||||
return {
|
||||
channel,
|
||||
configured,
|
||||
statusLines: [
|
||||
`Google Chat: ${configured ? "configured" : "needs service account"}`,
|
||||
],
|
||||
statusLines: [`Google Chat: ${configured ? "configured" : "needs service account"}`],
|
||||
selectionHint: configured ? "configured" : "needs auth",
|
||||
};
|
||||
},
|
||||
configure: async ({
|
||||
cfg,
|
||||
prompter,
|
||||
accountOverrides,
|
||||
shouldPromptAccountIds,
|
||||
}) => {
|
||||
configure: async ({ cfg, prompter, accountOverrides, shouldPromptAccountIds }) => {
|
||||
const override = accountOverrides["googlechat"]?.trim();
|
||||
const defaultAccountId = resolveDefaultGoogleChatAccountId(cfg);
|
||||
let accountId = override ? normalizeAccountId(override) : defaultAccountId;
|
||||
|
||||
@@ -10,9 +10,7 @@ describe("normalizeGoogleChatTarget", () => {
|
||||
it("normalizes provider prefixes", () => {
|
||||
expect(normalizeGoogleChatTarget("googlechat:users/123")).toBe("users/123");
|
||||
expect(normalizeGoogleChatTarget("google-chat:spaces/AAA")).toBe("spaces/AAA");
|
||||
expect(normalizeGoogleChatTarget("gchat:user:User@Example.com")).toBe(
|
||||
"users/user@example.com",
|
||||
);
|
||||
expect(normalizeGoogleChatTarget("gchat:user:User@Example.com")).toBe("users/user@example.com");
|
||||
});
|
||||
|
||||
it("normalizes email targets to users/<email>", () => {
|
||||
|
||||
Reference in New Issue
Block a user