@openclaw/googlechat 2026.7.2-beta.2 → 2026.7.2-beta.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.
Files changed (46) hide show
  1. package/dist/{actions-B4nbMjmi.js → actions-DBF3ImbA.js} +5 -5
  2. package/dist/api.js +2 -2
  3. package/dist/{approval-auth-B2m8ckdj.js → approval-auth-BztBRceh.js} +3 -3
  4. package/dist/{approval-handler.runtime-DH6QCsS8.js → approval-handler.runtime-CWoYapMp.js} +4 -4
  5. package/dist/{channel-CST-JKw9.js → channel-DMP6V9MO.js} +18 -17
  6. package/dist/{channel-base-fY2AAQj5.js → channel-base-BOLIr2sb.js} +138 -49
  7. package/dist/channel-plugin-api.js +1 -1
  8. package/dist/{channel.adapters-Dhy4lV4f.js → channel.adapters-X7Hlcajj.js} +305 -18
  9. package/dist/{channel.runtime-CE5zWkzP.js → channel.runtime-rGazhnxA.js} +306 -124
  10. package/dist/directory-contract-api.js +1 -1
  11. package/dist/{doctor-contract-CvhD0eoX.js → doctor-contract-CWlBAcKf.js} +38 -61
  12. package/dist/doctor-contract-api.js +1 -1
  13. package/dist/{runtime-api-1v-DgldF.js → runtime-api-Dh0CNVS4.js} +1 -2
  14. package/dist/runtime-api.js +2 -2
  15. package/dist/{secret-contract-D__4IIu_.js → secret-contract-BFYyuE0F.js} +21 -25
  16. package/dist/secret-contract-api.js +1 -1
  17. package/dist/setup-plugin-api.js +1 -1
  18. package/node_modules/gaxios/build/cjs/src/gaxios.js +1 -1
  19. package/node_modules/gaxios/build/cjs/src/gaxios.js.map +1 -1
  20. package/node_modules/gaxios/build/cjs/test/test.getch.js +66 -0
  21. package/node_modules/gaxios/build/cjs/test/test.getch.js.map +1 -1
  22. package/node_modules/gaxios/build/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  23. package/node_modules/gaxios/build/esm/src/gaxios.js +1 -1
  24. package/node_modules/gaxios/build/esm/src/gaxios.js.map +1 -1
  25. package/node_modules/gaxios/build/esm/test/test.getch.js +66 -0
  26. package/node_modules/gaxios/build/esm/test/test.getch.js.map +1 -1
  27. package/node_modules/gaxios/build/esm/tsconfig.tsbuildinfo +1 -1
  28. package/node_modules/gaxios/package.json +4 -4
  29. package/node_modules/google-logging-utils/build/src/colours.d.ts +1 -29
  30. package/node_modules/google-logging-utils/build/src/colours.js +13 -13
  31. package/node_modules/google-logging-utils/build/src/colours.js.map +1 -1
  32. package/node_modules/google-logging-utils/build/src/index.d.ts +1 -0
  33. package/node_modules/google-logging-utils/build/src/index.js +1 -1
  34. package/node_modules/google-logging-utils/build/src/index.js.map +1 -1
  35. package/node_modules/google-logging-utils/build/src/logging-utils.d.ts +2 -135
  36. package/node_modules/google-logging-utils/build/src/logging-utils.js +35 -58
  37. package/node_modules/google-logging-utils/build/src/logging-utils.js.map +1 -1
  38. package/node_modules/google-logging-utils/build/src/temporal.js +8 -8
  39. package/node_modules/google-logging-utils/build/src/temporal.js.map +1 -1
  40. package/node_modules/google-logging-utils/build/src/types.d.ts +78 -0
  41. package/node_modules/google-logging-utils/build/src/types.js +16 -0
  42. package/node_modules/google-logging-utils/build/src/types.js.map +1 -0
  43. package/node_modules/google-logging-utils/package.json +11 -9
  44. package/npm-shrinkwrap.json +9 -9
  45. package/openclaw.plugin.json +403 -499
  46. package/package.json +81 -22
@@ -1,13 +1,15 @@
1
- import { A as releaseGoogleChatApprovalCardBinding, C as claimGoogleChatApprovalCardBinding, D as readGoogleChatApprovalActionToken, E as getGoogleChatApprovalCardBinding, _ as probeGoogleChat, b as verifyGoogleChatRequest, c as buildGoogleChatGroupPolicyScope, g as downloadGoogleChatMedia, h as deleteGoogleChatMessage, l as isGoogleChatGroupSpace, v as sendGoogleChatMessage, w as completeGoogleChatApprovalCardBinding, y as updateGoogleChatMessage } from "./channel.adapters-Dhy4lV4f.js";
2
- import { C as resolveInboundRouteEnvelopeBuilderWithRuntime, D as warnMissingProviderGroupPolicyFallbackOnce, b as resolveAllowlistProviderRuntimeGroupPolicy, c as createChannelPairingController, f as isDangerousNameMatchingEnabled, k as getGoogleChatRuntime, n as GROUP_POLICY_BLOCKED_LABEL, w as resolveWebhookPath, x as resolveDefaultGroupPolicy } from "./runtime-api-1v-DgldF.js";
3
- import { n as googleChatApprovalAuth } from "./approval-auth-B2m8ckdj.js";
1
+ import { A as releaseGoogleChatApprovalCardBinding, C as claimGoogleChatApprovalCardBinding, D as readGoogleChatApprovalActionToken, E as getGoogleChatApprovalCardBinding, _ as probeGoogleChat, b as verifyGoogleChatRequest, c as buildGoogleChatGroupPolicyScope, g as downloadGoogleChatMedia, h as deleteGoogleChatMessage, l as isGoogleChatGroupSpace, v as sendGoogleChatMessage, w as completeGoogleChatApprovalCardBinding, y as updateGoogleChatMessage } from "./channel.adapters-X7Hlcajj.js";
2
+ import { C as resolveWebhookPath, E as warnMissingProviderGroupPolicyFallbackOnce, O as getGoogleChatRuntime, b as resolveAllowlistProviderRuntimeGroupPolicy, c as createChannelPairingController, f as isDangerousNameMatchingEnabled, n as GROUP_POLICY_BLOCKED_LABEL, x as resolveDefaultGroupPolicy } from "./runtime-api-Dh0CNVS4.js";
3
+ import { n as googleChatApprovalAuth } from "./approval-auth-BztBRceh.js";
4
4
  import { normalizeLowercaseStringOrEmpty, normalizeOptionalLowercaseString, normalizeOptionalString, normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
5
5
  import { mergePairLoopGuardConfig } from "openclaw/plugin-sdk/pair-loop-guard-runtime";
6
- import { recordChannelBotPairLoopAndCheckSuppression } from "openclaw/plugin-sdk/channel-inbound";
6
+ import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
7
+ import { collectErrorGraphCandidates, formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
8
+ import { createChannelIngressMonitor } from "openclaw/plugin-sdk/channel-outbound";
9
+ import { recordChannelBotPairLoopAndCheckSuppression, resolveChannelInboundRouteEnvelope, toInboundMediaFacts } from "openclaw/plugin-sdk/channel-inbound";
7
10
  import { WEBHOOK_RATE_LIMIT_DEFAULTS, createFixedWindowRateLimiter, normalizeWebhookPath, resolveRequestClientIp } from "openclaw/plugin-sdk/webhook-ingress";
8
11
  import { registerWebhookTargetWithPluginRoute, resolveWebhookTargetWithAuthOrReject, withResolvedWebhookRequestPipeline } from "openclaw/plugin-sdk/webhook-targets";
9
12
  import { createWebhookInFlightLimiter, readJsonWebhookBodyOrReject, runDetachedWebhookWork } from "openclaw/plugin-sdk/webhook-request-guards";
10
- import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
11
13
  import { resolveApprovalOverGateway } from "openclaw/plugin-sdk/approval-gateway-runtime";
12
14
  import { channelIngressRoutes, createChannelIngressResolver, defineStableChannelIngressIdentity } from "openclaw/plugin-sdk/channel-ingress-runtime";
13
15
  import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
@@ -272,8 +274,8 @@ async function applyGoogleChatInboundAccessPolicy(params) {
272
274
  const groupEntry = groupConfigResolved.entry;
273
275
  const groupUsers = groupEntry?.users ?? account.config.groupAllowFrom ?? [];
274
276
  let effectiveWasMentioned;
275
- const dmPolicy = account.config.dm?.policy ?? "pairing";
276
- const rawConfigAllowFrom = normalizeStringEntries(account.config.dm?.allowFrom);
277
+ const dmPolicy = account.config.dmPolicy ?? "pairing";
278
+ const rawConfigAllowFrom = normalizeStringEntries(account.config.allowFrom);
277
279
  const shouldComputeAuth = core.channel.commands.shouldComputeCommandAuthorized(rawBody, config);
278
280
  const groupActivation = (() => {
279
281
  if (!isGroup) return;
@@ -443,6 +445,214 @@ function resolveGoogleChatDurableReplyOptions(params) {
443
445
  };
444
446
  }
445
447
  //#endregion
448
+ //#region extensions/googlechat/src/monitor-event.ts
449
+ var GoogleChatEventPayloadError = class extends Error {
450
+ constructor(message = "invalid payload") {
451
+ super(message);
452
+ this.name = "GoogleChatEventPayloadError";
453
+ }
454
+ };
455
+ function isRecord$2(value) {
456
+ return typeof value === "object" && value !== null && !Array.isArray(value);
457
+ }
458
+ function recordParamsToActionParameters(params) {
459
+ if (!params) return;
460
+ const entries = Object.entries(params).filter((entry) => typeof entry[1] === "string").map(([key, value]) => ({
461
+ key,
462
+ value
463
+ }));
464
+ return entries.length > 0 ? entries : void 0;
465
+ }
466
+ /** Normalize only at authenticated dispatch; durable admission stores the untouched envelope. */
467
+ function parseGoogleChatInboundPayload(raw) {
468
+ if (!isRecord$2(raw)) throw new GoogleChatEventPayloadError();
469
+ let eventPayload = raw;
470
+ let addOnBearerToken = "";
471
+ const rawObj = raw;
472
+ if (rawObj.commonEventObject?.hostApp === "CHAT") addOnBearerToken = typeof rawObj.authorizationEventObject?.systemIdToken === "string" ? rawObj.authorizationEventObject.systemIdToken.trim() : "";
473
+ const chat = rawObj.chat;
474
+ const messagePayload = chat?.messagePayload;
475
+ if (rawObj.commonEventObject?.hostApp === "CHAT" && chat && messagePayload) eventPayload = {
476
+ type: "MESSAGE",
477
+ space: messagePayload.space,
478
+ message: messagePayload.message,
479
+ user: chat.user,
480
+ eventTime: chat.eventTime
481
+ };
482
+ else if (rawObj.commonEventObject?.hostApp === "CHAT") {
483
+ const chatPayload = rawObj.chat;
484
+ const buttonClickedPayload = chatPayload?.buttonClickedPayload;
485
+ if (buttonClickedPayload) {
486
+ const invokedFunction = rawObj.commonEventObject.invokedFunction;
487
+ const actionParameters = recordParamsToActionParameters(rawObj.commonEventObject.parameters);
488
+ eventPayload = {
489
+ type: "CARD_CLICKED",
490
+ space: buttonClickedPayload.space,
491
+ message: buttonClickedPayload.message,
492
+ user: buttonClickedPayload.user ?? chatPayload?.user,
493
+ eventTime: chatPayload?.eventTime,
494
+ action: buttonClickedPayload.action ?? {
495
+ ...typeof invokedFunction === "string" ? { actionMethodName: invokedFunction } : {},
496
+ ...actionParameters ? { parameters: actionParameters } : {}
497
+ },
498
+ commonEventObject: {
499
+ ...typeof invokedFunction === "string" ? { invokedFunction } : {},
500
+ parameters: rawObj.commonEventObject.parameters
501
+ }
502
+ };
503
+ }
504
+ }
505
+ const event = eventPayload;
506
+ const eventType = event.type ?? event.eventType;
507
+ if (typeof eventType !== "string" || !isRecord$2(event.space)) throw new GoogleChatEventPayloadError();
508
+ if (eventType === "MESSAGE") {
509
+ if (!isRecord$2(event.message) || !event.space?.name?.trim() || !event.message?.name?.trim()) throw new GoogleChatEventPayloadError();
510
+ } else if (eventType === "CARD_CLICKED" && !isRecord$2(event.user)) throw new GoogleChatEventPayloadError();
511
+ return {
512
+ event,
513
+ addOnBearerToken
514
+ };
515
+ }
516
+ //#endregion
517
+ //#region extensions/googlechat/src/monitor-ingress.ts
518
+ const GOOGLECHAT_INGRESS_PAYLOAD_VERSION = 1;
519
+ const GOOGLECHAT_INGRESS_POLL_INTERVAL_MS = 500;
520
+ const GOOGLECHAT_INGRESS_PRUNE_INTERVAL_MS = 3600 * 1e3;
521
+ const GOOGLECHAT_INGRESS_MAX_CONCURRENT_DELIVERIES = 8;
522
+ const GOOGLECHAT_INGRESS_COMPLETED_TTL_MS = 720 * 60 * 60 * 1e3;
523
+ const GOOGLECHAT_INGRESS_COMPLETED_MAX_ENTRIES = 2e4;
524
+ const GOOGLECHAT_INGRESS_FAILED_TTL_MS = 720 * 60 * 60 * 1e3;
525
+ const GOOGLECHAT_INGRESS_FAILED_MAX_ENTRIES = 2e4;
526
+ var GoogleChatIngressPermanentError = class extends Error {
527
+ constructor(reason, message, options) {
528
+ super(message, options);
529
+ this.reason = reason;
530
+ this.name = "GoogleChatIngressPermanentError";
531
+ }
532
+ };
533
+ function isRecord$1(value) {
534
+ return typeof value === "object" && value !== null && !Array.isArray(value);
535
+ }
536
+ function requiredString(value, field) {
537
+ if (typeof value === "string" && value.trim()) return value.trim();
538
+ throw new GoogleChatIngressPermanentError("invalid-event", `Google Chat MESSAGE event is missing ${field}.`);
539
+ }
540
+ function inspectGoogleChatIngressEvent(raw) {
541
+ if (!isRecord$1(raw)) throw new GoogleChatIngressPermanentError("invalid-event", "Google Chat webhook envelope must be an object.");
542
+ const commonEventObject = isRecord$1(raw.commonEventObject) ? raw.commonEventObject : null;
543
+ const chat = isRecord$1(raw.chat) ? raw.chat : null;
544
+ const isAddOn = commonEventObject?.hostApp === "CHAT";
545
+ let eventType = raw.type ?? raw.eventType;
546
+ let space = isRecord$1(raw.space) ? raw.space : null;
547
+ let message = isRecord$1(raw.message) ? raw.message : null;
548
+ if (isAddOn) {
549
+ const messagePayload = isRecord$1(chat?.messagePayload) ? chat.messagePayload : null;
550
+ if (!messagePayload) return null;
551
+ eventType = "MESSAGE";
552
+ space = isRecord$1(messagePayload.space) ? messagePayload.space : null;
553
+ message = isRecord$1(messagePayload.message) ? messagePayload.message : null;
554
+ }
555
+ if (eventType !== "MESSAGE") return null;
556
+ const spaceName = requiredString(space?.name, "space.name");
557
+ return {
558
+ eventId: requiredString(message?.name, "message.name"),
559
+ laneKey: `space:${spaceName}`
560
+ };
561
+ }
562
+ function deserializeGoogleChatIngressEvent(rawEvent, claimedId) {
563
+ let raw;
564
+ try {
565
+ raw = JSON.parse(rawEvent);
566
+ } catch (error) {
567
+ throw new GoogleChatIngressPermanentError("invalid-event", `Google Chat ingress row ${claimedId} contains invalid JSON.`, { cause: error });
568
+ }
569
+ return raw;
570
+ }
571
+ function normalizeClaimedGoogleChatEvent(raw, claimedId) {
572
+ try {
573
+ const parsed = parseGoogleChatInboundPayload(raw);
574
+ if ((parsed.event.type ?? parsed.event.eventType) !== "MESSAGE") throw new GoogleChatEventPayloadError();
575
+ return parsed.event;
576
+ } catch (error) {
577
+ throw new GoogleChatIngressPermanentError("invalid-event", `Google Chat ingress row ${claimedId} cannot be normalized.`, { cause: error });
578
+ }
579
+ }
580
+ function resolveGoogleChatIngressNonRetryableFailure(error) {
581
+ for (const candidate of collectErrorGraphCandidates(error, (current) => [current.cause])) {
582
+ if (candidate instanceof GoogleChatIngressPermanentError) return {
583
+ reason: candidate.reason,
584
+ message: candidate.message
585
+ };
586
+ const message = formatErrorMessage(candidate);
587
+ if (/Google Chat API 401\b/.test(message) || /^(?:Missing Google Chat access token|Google Chat (?:credentials|service account)\b|(?:Failed to load|Invalid) Google Chat service account\b)/.test(message)) return {
588
+ reason: "googlechat-auth",
589
+ message
590
+ };
591
+ }
592
+ return null;
593
+ }
594
+ function createGoogleChatIngressMonitor(options) {
595
+ const serializeForIngress = (rawEvent) => {
596
+ if (!isRecord$1(rawEvent)) throw new GoogleChatIngressPermanentError("invalid-event", "Google Chat webhook envelope must be an object.");
597
+ const durableEvent = { ...rawEvent };
598
+ delete durableEvent.authorizationEventObject;
599
+ const serialized = JSON.stringify(durableEvent);
600
+ if (typeof serialized !== "string") throw new GoogleChatIngressPermanentError("invalid-event", "Google Chat webhook envelope cannot be serialized.");
601
+ return serialized;
602
+ };
603
+ const monitor = createChannelIngressMonitor({
604
+ queue: options.queue ?? (() => getGoogleChatRuntime().state.openChannelIngressQueue({ accountId: options.accountId })),
605
+ inspect: (rawEvent) => inspectGoogleChatIngressEvent(rawEvent),
606
+ payload: {
607
+ storage: "raw-event",
608
+ version: GOOGLECHAT_INGRESS_PAYLOAD_VERSION,
609
+ serialize: serializeForIngress,
610
+ deserialize: (rawEvent, { claim }) => deserializeGoogleChatIngressEvent(rawEvent, claim.id),
611
+ createClaimError: (kind, claim) => new GoogleChatIngressPermanentError("invalid-event", kind === "invalid-version" ? `Google Chat ingress row ${claim.id} has an invalid payload.` : `Google Chat ingress row ${claim.id} has invalid message identity.`)
612
+ },
613
+ deliver: (rawEvent, lifecycle, claim) => options.dispatch(normalizeClaimedGoogleChatEvent(rawEvent, claim.id), lifecycle),
614
+ pollIntervalMs: options.pollIntervalMs ?? GOOGLECHAT_INGRESS_POLL_INTERVAL_MS,
615
+ retention: {
616
+ pruneIntervalMs: GOOGLECHAT_INGRESS_PRUNE_INTERVAL_MS,
617
+ completedTtlMs: GOOGLECHAT_INGRESS_COMPLETED_TTL_MS,
618
+ completedMaxEntries: GOOGLECHAT_INGRESS_COMPLETED_MAX_ENTRIES,
619
+ failedTtlMs: GOOGLECHAT_INGRESS_FAILED_TTL_MS,
620
+ failedMaxEntries: GOOGLECHAT_INGRESS_FAILED_MAX_ENTRIES
621
+ },
622
+ drain: {
623
+ resolveNonRetryableFailure: resolveGoogleChatIngressNonRetryableFailure,
624
+ startLimit: GOOGLECHAT_INGRESS_MAX_CONCURRENT_DELIVERIES,
625
+ ...options.adoptionStallTimeoutMs === void 0 ? {} : { adoptionStallTimeoutMs: options.adoptionStallTimeoutMs },
626
+ onLog: (message) => options.runtime.error?.(`googlechat: ${message}`)
627
+ },
628
+ ...options.abortSignal ? { abortSignal: options.abortSignal } : {},
629
+ admissionMode: "while-running",
630
+ createStoppedError: () => /* @__PURE__ */ new Error("Google Chat ingress is stopped."),
631
+ onError: (error) => options.runtime.error?.(`googlechat ingress drain failed: ${formatErrorMessage(error)}`)
632
+ });
633
+ return {
634
+ receive: async (rawEvent) => {
635
+ if (!monitor.isRunning()) throw new Error("Google Chat ingress is stopped.");
636
+ let facts;
637
+ try {
638
+ facts = inspectGoogleChatIngressEvent(rawEvent);
639
+ } catch (error) {
640
+ if (error instanceof GoogleChatIngressPermanentError) return {
641
+ kind: "invalid",
642
+ message: error.message
643
+ };
644
+ throw error;
645
+ }
646
+ if (!facts) return { kind: "ignored" };
647
+ await monitor.admit(rawEvent, { facts });
648
+ return { kind: "durable" };
649
+ },
650
+ start: monitor.start,
651
+ stop: monitor.stop,
652
+ waitForIdle: monitor.waitForIdle
653
+ };
654
+ }
655
+ //#endregion
446
656
  //#region extensions/googlechat/src/monitor-reply-delivery.ts
447
657
  async function deliverGoogleChatReply(params) {
448
658
  const { payload, account, spaceId, runtime, core, config, statusSink } = params;
@@ -521,85 +731,21 @@ function extractBearerToken(header) {
521
731
  }
522
732
  const ADD_ON_PREAUTH_MAX_BYTES = 16 * 1024;
523
733
  const ADD_ON_PREAUTH_TIMEOUT_MS = 3e3;
524
- function recordParamsToActionParameters(params) {
525
- if (!params) return;
526
- const entries = Object.entries(params).filter((entry) => typeof entry[1] === "string").map(([key, value]) => ({
527
- key,
528
- value
529
- }));
530
- return entries.length > 0 ? entries : void 0;
734
+ function isRecord(value) {
735
+ return typeof value === "object" && value !== null && !Array.isArray(value);
531
736
  }
532
- function parseGoogleChatInboundPayload(raw, res) {
533
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
737
+ function parseGoogleChatInboundPayloadOrReject(raw, res) {
738
+ if (!isRecord(raw)) {
534
739
  res.statusCode = 400;
535
740
  res.end("invalid payload");
536
- return { ok: false };
741
+ return null;
537
742
  }
538
- let eventPayload = raw;
743
+ const commonEventObject = isRecord(raw.commonEventObject) ? raw.commonEventObject : null;
744
+ const authorizationEventObject = isRecord(raw.authorizationEventObject) ? raw.authorizationEventObject : null;
539
745
  let addOnBearerToken = "";
540
- const rawObj = raw;
541
- if (rawObj.commonEventObject?.hostApp === "CHAT") addOnBearerToken = typeof rawObj.authorizationEventObject?.systemIdToken === "string" ? rawObj.authorizationEventObject.systemIdToken.trim() : "";
542
- if (rawObj.commonEventObject?.hostApp === "CHAT" && rawObj.chat?.messagePayload) {
543
- const chat = rawObj.chat;
544
- const messagePayload = chat.messagePayload;
545
- eventPayload = {
546
- type: "MESSAGE",
547
- space: messagePayload?.space,
548
- message: messagePayload?.message,
549
- user: chat.user,
550
- eventTime: chat.eventTime
551
- };
552
- } else if (rawObj.commonEventObject?.hostApp === "CHAT") {
553
- const chat = rawObj.chat;
554
- const buttonClickedPayload = chat?.buttonClickedPayload;
555
- if (buttonClickedPayload) {
556
- const invokedFunction = rawObj.commonEventObject.invokedFunction;
557
- const actionParameters = recordParamsToActionParameters(rawObj.commonEventObject.parameters);
558
- eventPayload = {
559
- type: "CARD_CLICKED",
560
- space: buttonClickedPayload.space,
561
- message: buttonClickedPayload.message,
562
- user: buttonClickedPayload.user ?? chat.user,
563
- eventTime: chat.eventTime,
564
- action: buttonClickedPayload.action ?? {
565
- ...typeof invokedFunction === "string" ? { actionMethodName: invokedFunction } : {},
566
- ...actionParameters ? { parameters: actionParameters } : {}
567
- },
568
- commonEventObject: {
569
- ...typeof invokedFunction === "string" ? { invokedFunction } : {},
570
- parameters: rawObj.commonEventObject.parameters
571
- }
572
- };
573
- }
574
- }
575
- const event = eventPayload;
576
- const eventType = event.type ?? eventPayload.eventType;
577
- if (typeof eventType !== "string") {
578
- res.statusCode = 400;
579
- res.end("invalid payload");
580
- return { ok: false };
581
- }
582
- if (!event.space || typeof event.space !== "object" || Array.isArray(event.space)) {
583
- res.statusCode = 400;
584
- res.end("invalid payload");
585
- return { ok: false };
586
- }
587
- if (eventType === "MESSAGE") {
588
- if (!event.message || typeof event.message !== "object" || Array.isArray(event.message)) {
589
- res.statusCode = 400;
590
- res.end("invalid payload");
591
- return { ok: false };
592
- }
593
- } else if (eventType === "CARD_CLICKED") {
594
- if (!event.user || typeof event.user !== "object" || Array.isArray(event.user)) {
595
- res.statusCode = 400;
596
- res.end("invalid payload");
597
- return { ok: false };
598
- }
599
- }
746
+ if (commonEventObject?.hostApp === "CHAT" && typeof authorizationEventObject?.systemIdToken === "string") addOnBearerToken = authorizationEventObject.systemIdToken.trim();
600
747
  return {
601
- ok: true,
602
- event,
748
+ raw,
603
749
  addOnBearerToken
604
750
  };
605
751
  }
@@ -669,7 +815,7 @@ function createGoogleChatWebhookRequestHandler(params) {
669
815
  handle: async ({ targets }) => {
670
816
  const headerBearer = extractBearerToken(req.headers.authorization);
671
817
  let selectedTarget;
672
- let parsedEvent;
818
+ let parsedInbound;
673
819
  const readAndParseEvent = async (profile) => {
674
820
  const body = await readJsonWebhookBodyOrReject({
675
821
  req,
@@ -683,8 +829,7 @@ function createGoogleChatWebhookRequestHandler(params) {
683
829
  invalidJsonMessage: "invalid payload"
684
830
  });
685
831
  if (!body.ok) return null;
686
- const parsed = parseGoogleChatInboundPayload(body.value, res);
687
- return parsed.ok ? parsed : null;
832
+ return parseGoogleChatInboundPayloadOrReject(body.value, res);
688
833
  };
689
834
  if (headerBearer) {
690
835
  selectedTarget = await resolveGoogleChatWebhookTargetWithAuthOrReject({
@@ -695,11 +840,11 @@ function createGoogleChatWebhookRequestHandler(params) {
695
840
  if (!selectedTarget) return true;
696
841
  const parsed = await readAndParseEvent("post-auth");
697
842
  if (!parsed) return true;
698
- parsedEvent = parsed.event;
843
+ parsedInbound = parsed;
699
844
  } else {
700
845
  const parsed = await readAndParseEvent("pre-auth");
701
846
  if (!parsed) return true;
702
- parsedEvent = parsed.event;
847
+ parsedInbound = parsed;
703
848
  if (!parsed.addOnBearerToken) {
704
849
  logGoogleChatWebhookAuthRejectedForTargets(targets, "missing token");
705
850
  res.statusCode = 401;
@@ -713,16 +858,39 @@ function createGoogleChatWebhookRequestHandler(params) {
713
858
  });
714
859
  if (!selectedTarget) return true;
715
860
  }
716
- if (!selectedTarget || !parsedEvent) {
861
+ if (!selectedTarget || !parsedInbound) {
717
862
  res.statusCode = 401;
718
863
  res.end("unauthorized");
719
864
  return true;
720
865
  }
721
866
  const dispatchTarget = selectedTarget;
722
867
  dispatchTarget.statusSink?.({ lastInboundAt: Date.now() });
723
- runDetachedWebhookWork(() => params.processEvent(parsedEvent, dispatchTarget)).catch((err) => {
724
- dispatchTarget.runtime.error?.(`[${dispatchTarget.account.accountId}] Google Chat webhook failed: ${String(err)}`);
725
- });
868
+ try {
869
+ const admission = await dispatchTarget.ingress.receive(parsedInbound.raw);
870
+ if (admission.kind === "invalid") {
871
+ res.statusCode = 400;
872
+ res.end("invalid payload");
873
+ return true;
874
+ }
875
+ if (admission.kind === "ignored") {
876
+ let event;
877
+ try {
878
+ event = parseGoogleChatInboundPayload(parsedInbound.raw).event;
879
+ } catch {
880
+ res.statusCode = 400;
881
+ res.end("invalid payload");
882
+ return true;
883
+ }
884
+ runDetachedWebhookWork(() => params.processEvent(event, dispatchTarget)).catch((err) => {
885
+ dispatchTarget.runtime.error?.(`[${dispatchTarget.account.accountId}] Google Chat webhook failed: ${String(err)}`);
886
+ });
887
+ }
888
+ } catch (error) {
889
+ dispatchTarget.runtime.error?.(`[${dispatchTarget.account.accountId}] Google Chat durable admission failed: ${String(error)}`);
890
+ res.statusCode = 503;
891
+ res.end("failed to persist event");
892
+ return true;
893
+ }
726
894
  res.statusCode = 200;
727
895
  res.setHeader("Content-Type", "application/json");
728
896
  res.end("{}");
@@ -814,7 +982,7 @@ function shouldSuppressGoogleChatBotLoop(params) {
814
982
  logVerbose(params.core, params.runtime, `skip bot-to-bot loop in ${params.botLoopProtection.conversationId}`);
815
983
  return true;
816
984
  }
817
- async function processGoogleChatEvent(event, target) {
985
+ async function processGoogleChatEvent(event, target, turnAdoptionLifecycle) {
818
986
  const eventType = event.type ?? event.eventType;
819
987
  if (eventType === "CARD_CLICKED") {
820
988
  await maybeHandleGoogleChatApprovalCardClick({
@@ -832,7 +1000,8 @@ async function processGoogleChatEvent(event, target) {
832
1000
  runtime: target.runtime,
833
1001
  core: target.core,
834
1002
  statusSink: target.statusSink,
835
- mediaMaxMb: target.mediaMaxMb
1003
+ mediaMaxMb: target.mediaMaxMb,
1004
+ turnAdoptionLifecycle
836
1005
  });
837
1006
  }
838
1007
  /**
@@ -849,7 +1018,7 @@ function resolveBotDisplayName(params) {
849
1018
  return "OpenClaw";
850
1019
  }
851
1020
  async function processMessageWithPipeline(params) {
852
- const { event, account, config, runtime, core, statusSink, mediaMaxMb } = params;
1021
+ const { event, account, config, runtime, core, statusSink, mediaMaxMb, turnAdoptionLifecycle } = params;
853
1022
  const space = event.space;
854
1023
  const message = event.message;
855
1024
  if (!space || !message) return;
@@ -875,9 +1044,8 @@ async function processMessageWithPipeline(params) {
875
1044
  }
876
1045
  const messageText = (message.argumentText ?? message.text ?? "").trim();
877
1046
  const attachments = message.attachment ?? [];
878
- const hasMedia = attachments.length > 0;
879
- const rawBody = messageText || (hasMedia ? "<media:attachment>" : "");
880
- if (!rawBody) return;
1047
+ const rawBody = messageText;
1048
+ if (!rawBody && attachments.length === 0) return;
881
1049
  const access = await applyGoogleChatInboundAccessPolicy({
882
1050
  account,
883
1051
  config,
@@ -912,30 +1080,29 @@ async function processMessageWithPipeline(params) {
912
1080
  core,
913
1081
  runtime
914
1082
  })) return;
915
- const { route, buildEnvelope } = resolveInboundRouteEnvelopeBuilderWithRuntime({
1083
+ const { route, buildEnvelope } = resolveChannelInboundRouteEnvelope({
916
1084
  cfg: config,
917
1085
  channel: "googlechat",
918
1086
  accountId: account.accountId,
919
1087
  peer: {
920
1088
  kind: isGroup ? "group" : "direct",
921
1089
  id: spaceId
922
- },
923
- runtime: core.channel,
924
- sessionStore: config.session?.store
1090
+ }
925
1091
  });
926
- let mediaPath;
927
- let mediaType;
1092
+ const mediaInputs = attachments.map((attachment) => ({ contentType: attachment.contentType }));
928
1093
  const first = attachments.at(0);
929
1094
  if (first) {
930
1095
  const attachmentData = await downloadAttachment(first, account, mediaMaxMb, core);
931
- if (attachmentData) {
932
- mediaPath = attachmentData.path;
933
- mediaType = attachmentData.contentType;
934
- }
1096
+ if (attachmentData) mediaInputs[0] = {
1097
+ path: attachmentData.path,
1098
+ url: attachmentData.path,
1099
+ contentType: attachmentData.contentType ?? first.contentType
1100
+ };
935
1101
  }
1102
+ const media = toInboundMediaFacts(mediaInputs);
936
1103
  const fromLabel = isGroup ? space.displayName || `space:${spaceId}` : senderName || `user:${senderId}`;
937
1104
  const timestampMs = resolveGoogleChatTimestampMs(event.eventTime);
938
- const { storePath, body } = buildEnvelope({
1105
+ const body = buildEnvelope({
939
1106
  channel: "Google Chat",
940
1107
  from: fromLabel,
941
1108
  timestamp: timestampMs,
@@ -962,6 +1129,7 @@ async function processMessageWithPipeline(params) {
962
1129
  },
963
1130
  route: {
964
1131
  agentId: route.agentId,
1132
+ dmScope: route.dmScope,
965
1133
  accountId: route.accountId,
966
1134
  routeSessionKey: route.sessionKey
967
1135
  },
@@ -977,11 +1145,7 @@ async function processMessageWithPipeline(params) {
977
1145
  rawBody,
978
1146
  commandBody: rawBody
979
1147
  },
980
- media: mediaPath || mediaType ? [{
981
- path: mediaPath,
982
- url: mediaPath,
983
- contentType: mediaType
984
- }] : void 0,
1148
+ media: media.length > 0 ? media : void 0,
985
1149
  supplemental: { groupSystemPrompt: isGroup ? groupSystemPrompt : void 0 },
986
1150
  extra: {
987
1151
  ChatType: isGroup ? "channel" : "direct",
@@ -1020,6 +1184,7 @@ async function processMessageWithPipeline(params) {
1020
1184
  channel: "googlechat",
1021
1185
  accountId: route.accountId,
1022
1186
  raw: message,
1187
+ ...turnAdoptionLifecycle ? { turnAdoptionLifecycle } : {},
1023
1188
  adapter: {
1024
1189
  ingest: () => ({
1025
1190
  id: message.name ?? spaceId,
@@ -1033,12 +1198,11 @@ async function processMessageWithPipeline(params) {
1033
1198
  cfg: config,
1034
1199
  channel: "googlechat",
1035
1200
  accountId: route.accountId,
1036
- agentId: route.agentId,
1037
- routeSessionKey: route.sessionKey,
1038
- storePath,
1201
+ route: {
1202
+ agentId: route.agentId,
1203
+ sessionKey: route.sessionKey
1204
+ },
1039
1205
  ctxPayload,
1040
- recordInboundSession: core.channel.session.recordInboundSession,
1041
- dispatchReplyWithBufferedBlockDispatcher: core.channel.reply.dispatchReplyWithBufferedBlockDispatcher,
1042
1206
  delivery: {
1043
1207
  durable: (payload, info) => resolveGoogleChatDurableReplyOptions({
1044
1208
  payload,
@@ -1089,7 +1253,7 @@ async function downloadAttachment(attachment, account, mediaMaxMb, core) {
1089
1253
  contentType: saved.contentType
1090
1254
  };
1091
1255
  }
1092
- function monitorGoogleChatProvider(options) {
1256
+ async function monitorGoogleChatProvider(options) {
1093
1257
  const core = getGoogleChatRuntime();
1094
1258
  const webhookPath = resolveWebhookPath({
1095
1259
  webhookPath: options.webhookPath,
@@ -1098,7 +1262,7 @@ function monitorGoogleChatProvider(options) {
1098
1262
  });
1099
1263
  if (!webhookPath) {
1100
1264
  options.runtime.error?.(`[${options.account.accountId}] invalid webhook path`);
1101
- return () => {};
1265
+ return async () => {};
1102
1266
  }
1103
1267
  const audienceType = normalizeAudienceType(options.account.config.audienceType);
1104
1268
  const audience = options.account.config.audience?.trim();
@@ -1109,7 +1273,15 @@ function monitorGoogleChatProvider(options) {
1109
1273
  appPrincipal: options.account.config.appPrincipal,
1110
1274
  log: options.runtime.log
1111
1275
  });
1112
- const unregisterTarget = registerGoogleChatWebhookTarget({
1276
+ const ingress = createGoogleChatIngressMonitor({
1277
+ accountId: options.account.accountId,
1278
+ runtime: options.runtime,
1279
+ abortSignal: options.abortSignal,
1280
+ dispatch: async (event, lifecycle) => {
1281
+ await processGoogleChatEvent(event, target, lifecycle);
1282
+ }
1283
+ });
1284
+ const target = {
1113
1285
  account: options.account,
1114
1286
  config: options.config,
1115
1287
  runtime: options.runtime,
@@ -1118,14 +1290,24 @@ function monitorGoogleChatProvider(options) {
1118
1290
  audienceType,
1119
1291
  audience,
1120
1292
  statusSink: options.statusSink,
1121
- mediaMaxMb
1122
- });
1123
- return () => {
1124
- unregisterTarget();
1293
+ mediaMaxMb,
1294
+ ingress
1295
+ };
1296
+ ingress.start();
1297
+ let unregisterTarget;
1298
+ try {
1299
+ unregisterTarget = registerGoogleChatWebhookTarget(target);
1300
+ } catch (error) {
1301
+ await ingress.stop();
1302
+ throw error;
1303
+ }
1304
+ return async () => {
1305
+ unregisterTarget?.();
1306
+ await ingress.stop();
1125
1307
  };
1126
1308
  }
1127
1309
  async function startGoogleChatMonitor(params) {
1128
- return monitorGoogleChatProvider(params);
1310
+ return await monitorGoogleChatProvider(params);
1129
1311
  }
1130
1312
  function resolveGoogleChatWebhookPath(params) {
1131
1313
  return resolveWebhookPath({
@@ -1,4 +1,4 @@
1
- import { t as googlechatDirectoryAdapter } from "./channel.adapters-Dhy4lV4f.js";
1
+ import { t as googlechatDirectoryAdapter } from "./channel.adapters-X7Hlcajj.js";
2
2
  //#region extensions/googlechat/directory-contract-api.ts
3
3
  const googlechatDirectoryContractPlugin = {
4
4
  id: "googlechat",