@openclaw/googlechat 2026.7.2-beta.3 → 2026.7.2-beta.5

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 (31) hide show
  1. package/README.md +1 -1
  2. package/dist/{actions-C9M27Xgq.js → actions-wnreW-IQ.js} +2 -2
  3. package/dist/api.js +2 -2
  4. package/dist/{approval-auth-DXkKpb-s.js → approval-auth-G-OFufNc.js} +3 -3
  5. package/dist/{approval-handler.runtime-DemP1cMx.js → approval-handler.runtime-BJXVLK9y.js} +3 -3
  6. package/dist/{channel-Bylft8ql.js → channel-CehfTiWZ.js} +13 -13
  7. package/dist/{channel-base-CuSSPg6I.js → channel-base-CC85hRUC.js} +92 -64
  8. package/dist/channel-plugin-api.js +1 -1
  9. package/dist/{channel.adapters-CAVl8EUt.js → channel.adapters-DLatFGZz.js} +289 -12
  10. package/dist/{channel.runtime-tLQQKXrg.js → channel.runtime-Bz0__ttC.js} +296 -112
  11. package/dist/directory-contract-api.js +1 -1
  12. package/dist/doctor-contract-BpuSvJro.js +115 -0
  13. package/dist/doctor-contract-api.js +1 -1
  14. package/dist/{secret-contract-ZFiLJ7Yn.js → secret-contract-BFYyuE0F.js} +7 -21
  15. package/dist/secret-contract-api.js +1 -1
  16. package/dist/setup-plugin-api.js +1 -1
  17. package/node_modules/gaxios/build/cjs/src/gaxios.js +1 -1
  18. package/node_modules/gaxios/build/cjs/src/gaxios.js.map +1 -1
  19. package/node_modules/gaxios/build/cjs/test/test.getch.js +66 -0
  20. package/node_modules/gaxios/build/cjs/test/test.getch.js.map +1 -1
  21. package/node_modules/gaxios/build/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  22. package/node_modules/gaxios/build/esm/src/gaxios.js +1 -1
  23. package/node_modules/gaxios/build/esm/src/gaxios.js.map +1 -1
  24. package/node_modules/gaxios/build/esm/test/test.getch.js +66 -0
  25. package/node_modules/gaxios/build/esm/test/test.getch.js.map +1 -1
  26. package/node_modules/gaxios/build/esm/tsconfig.tsbuildinfo +1 -1
  27. package/node_modules/gaxios/package.json +4 -4
  28. package/openclaw.plugin.json +403 -499
  29. package/package.json +81 -23
  30. package/dist/doctor-contract-CvhD0eoX.js +0 -167
  31. package/npm-shrinkwrap.json +0 -313
@@ -1,10 +1,12 @@
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-CAVl8EUt.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-DLatFGZz.js";
2
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-DXkKpb-s.js";
3
+ import { n as googleChatApprovalAuth } from "./approval-auth-G-OFufNc.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
6
  import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
7
- import { recordChannelBotPairLoopAndCheckSuppression, resolveChannelInboundRouteEnvelope } from "openclaw/plugin-sdk/channel-inbound";
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";
8
10
  import { WEBHOOK_RATE_LIMIT_DEFAULTS, createFixedWindowRateLimiter, normalizeWebhookPath, resolveRequestClientIp } from "openclaw/plugin-sdk/webhook-ingress";
9
11
  import { registerWebhookTargetWithPluginRoute, resolveWebhookTargetWithAuthOrReject, withResolvedWebhookRequestPipeline } from "openclaw/plugin-sdk/webhook-targets";
10
12
  import { createWebhookInFlightLimiter, readJsonWebhookBodyOrReject, runDetachedWebhookWork } from "openclaw/plugin-sdk/webhook-request-guards";
@@ -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,
@@ -921,16 +1089,17 @@ async function processMessageWithPipeline(params) {
921
1089
  id: spaceId
922
1090
  }
923
1091
  });
924
- let mediaPath;
925
- let mediaType;
1092
+ const mediaInputs = attachments.map((attachment) => ({ contentType: attachment.contentType }));
926
1093
  const first = attachments.at(0);
927
1094
  if (first) {
928
1095
  const attachmentData = await downloadAttachment(first, account, mediaMaxMb, core);
929
- if (attachmentData) {
930
- mediaPath = attachmentData.path;
931
- mediaType = attachmentData.contentType;
932
- }
1096
+ if (attachmentData) mediaInputs[0] = {
1097
+ path: attachmentData.path,
1098
+ url: attachmentData.path,
1099
+ contentType: attachmentData.contentType ?? first.contentType
1100
+ };
933
1101
  }
1102
+ const media = toInboundMediaFacts(mediaInputs);
934
1103
  const fromLabel = isGroup ? space.displayName || `space:${spaceId}` : senderName || `user:${senderId}`;
935
1104
  const timestampMs = resolveGoogleChatTimestampMs(event.eventTime);
936
1105
  const body = buildEnvelope({
@@ -976,11 +1145,7 @@ async function processMessageWithPipeline(params) {
976
1145
  rawBody,
977
1146
  commandBody: rawBody
978
1147
  },
979
- media: mediaPath || mediaType ? [{
980
- path: mediaPath,
981
- url: mediaPath,
982
- contentType: mediaType
983
- }] : void 0,
1148
+ media: media.length > 0 ? media : void 0,
984
1149
  supplemental: { groupSystemPrompt: isGroup ? groupSystemPrompt : void 0 },
985
1150
  extra: {
986
1151
  ChatType: isGroup ? "channel" : "direct",
@@ -1019,6 +1184,7 @@ async function processMessageWithPipeline(params) {
1019
1184
  channel: "googlechat",
1020
1185
  accountId: route.accountId,
1021
1186
  raw: message,
1187
+ ...turnAdoptionLifecycle ? { turnAdoptionLifecycle } : {},
1022
1188
  adapter: {
1023
1189
  ingest: () => ({
1024
1190
  id: message.name ?? spaceId,
@@ -1087,7 +1253,7 @@ async function downloadAttachment(attachment, account, mediaMaxMb, core) {
1087
1253
  contentType: saved.contentType
1088
1254
  };
1089
1255
  }
1090
- function monitorGoogleChatProvider(options) {
1256
+ async function monitorGoogleChatProvider(options) {
1091
1257
  const core = getGoogleChatRuntime();
1092
1258
  const webhookPath = resolveWebhookPath({
1093
1259
  webhookPath: options.webhookPath,
@@ -1096,7 +1262,7 @@ function monitorGoogleChatProvider(options) {
1096
1262
  });
1097
1263
  if (!webhookPath) {
1098
1264
  options.runtime.error?.(`[${options.account.accountId}] invalid webhook path`);
1099
- return () => {};
1265
+ return async () => {};
1100
1266
  }
1101
1267
  const audienceType = normalizeAudienceType(options.account.config.audienceType);
1102
1268
  const audience = options.account.config.audience?.trim();
@@ -1107,7 +1273,15 @@ function monitorGoogleChatProvider(options) {
1107
1273
  appPrincipal: options.account.config.appPrincipal,
1108
1274
  log: options.runtime.log
1109
1275
  });
1110
- 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 = {
1111
1285
  account: options.account,
1112
1286
  config: options.config,
1113
1287
  runtime: options.runtime,
@@ -1116,14 +1290,24 @@ function monitorGoogleChatProvider(options) {
1116
1290
  audienceType,
1117
1291
  audience,
1118
1292
  statusSink: options.statusSink,
1119
- mediaMaxMb
1120
- });
1121
- return () => {
1122
- 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();
1123
1307
  };
1124
1308
  }
1125
1309
  async function startGoogleChatMonitor(params) {
1126
- return monitorGoogleChatProvider(params);
1310
+ return await monitorGoogleChatProvider(params);
1127
1311
  }
1128
1312
  function resolveGoogleChatWebhookPath(params) {
1129
1313
  return resolveWebhookPath({
@@ -1,4 +1,4 @@
1
- import { t as googlechatDirectoryAdapter } from "./channel.adapters-CAVl8EUt.js";
1
+ import { t as googlechatDirectoryAdapter } from "./channel.adapters-DLatFGZz.js";
2
2
  //#region extensions/googlechat/directory-contract-api.ts
3
3
  const googlechatDirectoryContractPlugin = {
4
4
  id: "googlechat",
@@ -0,0 +1,115 @@
1
+ import { asObjectRecord, defineChannelAliasMigration, defineKeyMoveMigration, hasLegacyAccountStreamingAliases, normalizeChannelConfigEntries } from "openclaw/plugin-sdk/runtime-doctor";
2
+ //#region extensions/googlechat/src/doctor-contract.ts
3
+ const streamingAliasMigration = defineChannelAliasMigration({
4
+ channelId: "googlechat",
5
+ streaming: {
6
+ defaultMode: "partial",
7
+ deliveryOnly: true
8
+ },
9
+ accountStreamingInheritsDefaultAccount: true,
10
+ dm: {
11
+ root: true,
12
+ accounts: true
13
+ }
14
+ });
15
+ function hasLegacyGoogleChatStreamMode(value) {
16
+ return asObjectRecord(value)?.streamMode !== void 0;
17
+ }
18
+ function hasRetiredReactions(value) {
19
+ return Object.hasOwn(asObjectRecord(asObjectRecord(value)?.actions) ?? {}, "reactions");
20
+ }
21
+ const groupAllowMigration = defineKeyMoveMigration({
22
+ scope: ["groups", "*"],
23
+ from: ["allow"],
24
+ to: ["enabled"]
25
+ });
26
+ function normalizeGoogleChatEntry(params) {
27
+ let updated = params.entry;
28
+ let changed = false;
29
+ if (updated.streamMode !== void 0) {
30
+ updated = { ...updated };
31
+ delete updated.streamMode;
32
+ params.changes.push(`Removed ${params.pathPrefix}.streamMode (legacy key no longer used).`);
33
+ changed = true;
34
+ }
35
+ if (hasRetiredReactions(updated)) {
36
+ const actions = { ...asObjectRecord(updated.actions) };
37
+ delete actions.reactions;
38
+ updated = { ...updated };
39
+ if (Object.keys(actions).length > 0) updated.actions = actions;
40
+ else delete updated.actions;
41
+ params.changes.push(`Removed ${params.pathPrefix}.actions.reactions (Google Chat does not support reactions).`);
42
+ changed = true;
43
+ }
44
+ const groups = groupAllowMigration.normalize({
45
+ ...params,
46
+ entry: updated
47
+ });
48
+ updated = groups.entry;
49
+ changed = changed || groups.changed;
50
+ return {
51
+ entry: updated,
52
+ changed
53
+ };
54
+ }
55
+ const legacyConfigRules = [
56
+ {
57
+ path: ["channels", "googlechat"],
58
+ message: "channels.googlechat.actions.reactions is retired and ignored. Run \"openclaw doctor --fix\".",
59
+ match: hasRetiredReactions
60
+ },
61
+ {
62
+ path: [
63
+ "channels",
64
+ "googlechat",
65
+ "accounts"
66
+ ],
67
+ message: "channels.googlechat.accounts.<id>.actions.reactions is retired and ignored. Run \"openclaw doctor --fix\".",
68
+ match: (value) => hasLegacyAccountStreamingAliases(value, hasRetiredReactions)
69
+ },
70
+ {
71
+ path: ["channels", "googlechat"],
72
+ message: "channels.googlechat.streamMode is legacy and no longer used; it is removed on load.",
73
+ match: hasLegacyGoogleChatStreamMode
74
+ },
75
+ {
76
+ path: [
77
+ "channels",
78
+ "googlechat",
79
+ "accounts"
80
+ ],
81
+ message: "channels.googlechat.accounts.<id>.streamMode is legacy and no longer used; it is removed on load.",
82
+ match: (value) => hasLegacyAccountStreamingAliases(value, hasLegacyGoogleChatStreamMode)
83
+ },
84
+ {
85
+ path: ["channels", "googlechat"],
86
+ message: "channels.googlechat.groups.<id>.allow is legacy; use channels.googlechat.groups.<id>.enabled instead. Run \"openclaw doctor --fix\".",
87
+ match: groupAllowMigration.hasLegacy
88
+ },
89
+ {
90
+ path: [
91
+ "channels",
92
+ "googlechat",
93
+ "accounts"
94
+ ],
95
+ message: "channels.googlechat.accounts.<id>.groups.<id>.allow is legacy; use channels.googlechat.accounts.<id>.groups.<id>.enabled instead. Run \"openclaw doctor --fix\".",
96
+ match: (value) => hasLegacyAccountStreamingAliases(value, groupAllowMigration.hasLegacy)
97
+ },
98
+ ...streamingAliasMigration.legacyConfigRules
99
+ ];
100
+ function normalizeRetiredGoogleChatKeys(cfg) {
101
+ return normalizeChannelConfigEntries({
102
+ cfg,
103
+ channelId: "googlechat",
104
+ normalizeEntry: normalizeGoogleChatEntry
105
+ });
106
+ }
107
+ function normalizeCompatibilityConfig({ cfg }) {
108
+ const retired = normalizeRetiredGoogleChatKeys(cfg);
109
+ return streamingAliasMigration.normalizeChannelConfig({
110
+ cfg: retired.config,
111
+ changes: retired.changes
112
+ });
113
+ }
114
+ //#endregion
115
+ export { normalizeCompatibilityConfig as n, legacyConfigRules as t };
@@ -1,2 +1,2 @@
1
- import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-CvhD0eoX.js";
1
+ import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-BpuSvJro.js";
2
2
  export { legacyConfigRules, normalizeCompatibilityConfig };