@openclaw/googlechat 2026.11.3 → 2026.11.5-beta.2

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 (140) hide show
  1. package/dist/.setup/{actions-CTuBGHVR.mjs → actions-UltP4TmA.mjs} +3 -3
  2. package/dist/.setup/{approval-auth-Dd-6ne22.mjs → approval-auth-C-AJm9xZ.mjs} +2 -2
  3. package/dist/.setup/{approval-handler.runtime-ZJkCErV1.mjs → approval-handler.runtime-dh__rR4O.mjs} +3 -3
  4. package/dist/.setup/{channel-p2FLMhYl.mjs → channel-DHpMDrjU.mjs} +78 -88
  5. package/dist/.setup/{channel-base-sWlG7EP1.mjs → channel-base-DZs1uOyW.mjs} +13 -14
  6. package/dist/.setup/{channel.adapters-CLzwB-5-.mjs → channel.adapters-BVT76qsz.mjs} +239 -315
  7. package/dist/.setup/{channel.runtime-Dlp4xvi9.mjs → channel.runtime-I9jyPEzh.mjs} +294 -343
  8. package/dist/.setup/secret-contract-api-BG_8yVjr.mjs +2 -0
  9. package/dist/.setup/setup-plugin-api-DW0Pq8Dd.mjs +2 -0
  10. package/dist/.source-module-urls/974ffefea973cf3ea18e1534d25b091bcf1b68760a2b9eda0cd9bd9392096c64.json +1 -0
  11. package/dist/api.js +2 -2
  12. package/dist/channel-plugin-api.js +1 -2
  13. package/dist/directory-contract-api.js +1 -1
  14. package/dist/doctor-contract-api.js +1 -2
  15. package/dist/runtime-api.js +1 -2
  16. package/dist/secret-contract-api.js +1 -2
  17. package/dist/setup-entry.js +2 -2
  18. package/dist/setup-plugin-api.js +1 -2
  19. package/node_modules/google-auth-library/build/src/auth/authclient.js.map +1 -0
  20. package/node_modules/google-auth-library/build/src/auth/awsclient.js.map +1 -0
  21. package/node_modules/google-auth-library/build/src/auth/awsrequestsigner.js.map +1 -0
  22. package/node_modules/google-auth-library/build/src/auth/baseexternalclient.js.map +1 -0
  23. package/node_modules/google-auth-library/build/src/auth/certificatesubjecttokensupplier.js.map +1 -0
  24. package/node_modules/google-auth-library/build/src/auth/computeclient.js.map +1 -0
  25. package/node_modules/google-auth-library/build/src/auth/credentials.js.map +1 -0
  26. package/node_modules/google-auth-library/build/src/auth/defaultawssecuritycredentialssupplier.js.map +1 -0
  27. package/node_modules/google-auth-library/build/src/auth/downscopedclient.js.map +1 -0
  28. package/node_modules/google-auth-library/build/src/auth/envDetect.js.map +1 -0
  29. package/node_modules/google-auth-library/build/src/auth/executable-response.js.map +1 -0
  30. package/node_modules/google-auth-library/build/src/auth/externalAccountAuthorizedUserClient.js.map +1 -0
  31. package/node_modules/google-auth-library/build/src/auth/externalclient.js.map +1 -0
  32. package/node_modules/google-auth-library/build/src/auth/filesubjecttokensupplier.js.map +1 -0
  33. package/node_modules/google-auth-library/build/src/auth/gdchclient.js.map +1 -0
  34. package/node_modules/google-auth-library/build/src/auth/googleauth.js.map +1 -0
  35. package/node_modules/google-auth-library/build/src/auth/iam.js.map +1 -0
  36. package/node_modules/google-auth-library/build/src/auth/identitypoolclient.js.map +1 -0
  37. package/node_modules/google-auth-library/build/src/auth/idtokenclient.js.map +1 -0
  38. package/node_modules/google-auth-library/build/src/auth/impersonated.js.map +1 -0
  39. package/node_modules/google-auth-library/build/src/auth/jwtaccess.js.map +1 -0
  40. package/node_modules/google-auth-library/build/src/auth/jwtclient.js.map +1 -0
  41. package/node_modules/google-auth-library/build/src/auth/loginticket.js.map +1 -0
  42. package/node_modules/google-auth-library/build/src/auth/oauth2client.js.map +1 -0
  43. package/node_modules/google-auth-library/build/src/auth/oauth2common.js.map +1 -0
  44. package/node_modules/google-auth-library/build/src/auth/passthrough.js.map +1 -0
  45. package/node_modules/google-auth-library/build/src/auth/pluggable-auth-client.js.map +1 -0
  46. package/node_modules/google-auth-library/build/src/auth/pluggable-auth-handler.js.map +1 -0
  47. package/node_modules/google-auth-library/build/src/auth/refreshclient.js.map +1 -0
  48. package/node_modules/google-auth-library/build/src/auth/stscredentials.js.map +1 -0
  49. package/node_modules/google-auth-library/build/src/auth/urlsubjecttokensupplier.js.map +1 -0
  50. package/node_modules/google-auth-library/build/src/crypto/browser/crypto.js.map +1 -0
  51. package/node_modules/google-auth-library/build/src/crypto/crypto.js.map +1 -0
  52. package/node_modules/google-auth-library/build/src/crypto/node/crypto.js.map +1 -0
  53. package/node_modules/google-auth-library/build/src/crypto/shared.js.map +1 -0
  54. package/node_modules/google-auth-library/build/src/gtoken/errorWithCode.js.map +1 -0
  55. package/node_modules/google-auth-library/build/src/gtoken/getCredentials.js.map +1 -0
  56. package/node_modules/google-auth-library/build/src/gtoken/getToken.js.map +1 -0
  57. package/node_modules/google-auth-library/build/src/gtoken/googleToken.js.map +1 -0
  58. package/node_modules/google-auth-library/build/src/gtoken/jwsSign.js.map +1 -0
  59. package/node_modules/google-auth-library/build/src/gtoken/revokeToken.js.map +1 -0
  60. package/node_modules/google-auth-library/build/src/gtoken/tokenHandler.js.map +1 -0
  61. package/node_modules/google-auth-library/build/src/gtoken/tokenOptions.js.map +1 -0
  62. package/node_modules/google-auth-library/build/src/index.js.map +1 -0
  63. package/node_modules/google-auth-library/build/src/shared.cjs.map +1 -0
  64. package/node_modules/google-auth-library/build/src/util.js.map +1 -0
  65. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/gaxios.js +166 -5
  66. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/gaxios.js.map +1 -1
  67. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/retry.js +12 -2
  68. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/src/retry.js.map +1 -1
  69. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/gaxios.js +167 -6
  70. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/gaxios.js.map +1 -1
  71. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/retry.js +12 -2
  72. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/src/retry.js.map +1 -1
  73. package/node_modules/google-auth-library/node_modules/gaxios/package.json +32 -25
  74. package/node_modules/google-auth-library/node_modules/gcp-metadata/build/src/index.js +14 -1
  75. package/node_modules/google-auth-library/node_modules/gcp-metadata/build/src/index.js.map +1 -1
  76. package/node_modules/google-auth-library/node_modules/gcp-metadata/package.json +19 -20
  77. package/node_modules/google-auth-library/node_modules/google-logging-utils/package.json +2 -2
  78. package/node_modules/google-auth-library/package.json +7 -9
  79. package/node_modules/zod/package.json +1 -1
  80. package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
  81. package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
  82. package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
  83. package/node_modules/zod/src/v4/core/compile.ts +9 -0
  84. package/node_modules/zod/src/v4/core/schemas.ts +35 -1
  85. package/node_modules/zod/src/v4/core/util.ts +13 -0
  86. package/node_modules/zod/src/v4/core/versions.ts +1 -1
  87. package/node_modules/zod/v4/core/compile.cjs +8 -0
  88. package/node_modules/zod/v4/core/compile.js +8 -0
  89. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  90. package/node_modules/zod/v4/core/schemas.d.cts +3 -1
  91. package/node_modules/zod/v4/core/schemas.d.ts +3 -1
  92. package/node_modules/zod/v4/core/schemas.js +30 -0
  93. package/node_modules/zod/v4/core/util.cjs +15 -0
  94. package/node_modules/zod/v4/core/util.d.cts +2 -0
  95. package/node_modules/zod/v4/core/util.d.ts +2 -0
  96. package/node_modules/zod/v4/core/util.js +14 -0
  97. package/node_modules/zod/v4/core/versions.cjs +1 -1
  98. package/node_modules/zod/v4/core/versions.js +1 -1
  99. package/openclaw.plugin.json +0 -30
  100. package/package.json +6 -6
  101. package/dist/.setup/secret-contract-api-Dx8QYxoR.mjs +0 -3
  102. package/dist/.setup/setup-plugin-api-yGEtLeXV.mjs +0 -3
  103. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/browser-test/browser-test-runner.d.ts +0 -1
  104. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/browser-test/browser-test-runner.js +0 -109
  105. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/browser-test/browser-test-runner.js.map +0 -1
  106. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/browser-test/test.browser.d.ts +0 -1
  107. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/browser-test/test.browser.js +0 -81
  108. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/browser-test/test.browser.js.map +0 -1
  109. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/system-test/test.install.d.ts +0 -1
  110. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/system-test/test.install.js +0 -128
  111. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/system-test/test.install.js.map +0 -1
  112. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.getch.d.ts +0 -1
  113. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.getch.js +0 -1510
  114. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.getch.js.map +0 -1
  115. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.index.d.ts +0 -1
  116. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.index.js +0 -61
  117. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.index.js.map +0 -1
  118. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.retry.d.ts +0 -1
  119. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.retry.js +0 -367
  120. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/test/test.retry.js.map +0 -1
  121. package/node_modules/google-auth-library/node_modules/gaxios/build/cjs/tsconfig.cjs.tsbuildinfo +0 -1
  122. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/browser-test/browser-test-runner.d.ts +0 -1
  123. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/browser-test/browser-test-runner.js +0 -71
  124. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/browser-test/browser-test-runner.js.map +0 -1
  125. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/browser-test/test.browser.d.ts +0 -1
  126. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/browser-test/test.browser.js +0 -76
  127. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/browser-test/test.browser.js.map +0 -1
  128. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/system-test/test.install.d.ts +0 -1
  129. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/system-test/test.install.js +0 -123
  130. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/system-test/test.install.js.map +0 -1
  131. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.getch.d.ts +0 -1
  132. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.getch.js +0 -1472
  133. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.getch.js.map +0 -1
  134. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.index.d.ts +0 -1
  135. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.index.js +0 -23
  136. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.index.js.map +0 -1
  137. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.retry.d.ts +0 -1
  138. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.retry.js +0 -362
  139. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/test/test.retry.js.map +0 -1
  140. package/node_modules/google-auth-library/node_modules/gaxios/build/esm/tsconfig.tsbuildinfo +0 -1
@@ -1,15 +1,16 @@
1
- import { C as sendGoogleChatMessage, O as googleChatApprovalControls, S as probeGoogleChat, T as verifyGoogleChatRequest, b as deleteGoogleChatMessage, c as googleChatIngressIdentity, d as formatGoogleChatMediaText, f as formatGoogleChatTextChunks, k as readGoogleChatApprovalActionToken, l as normalizeGoogleChatUserId, p as isGoogleChatGroupSpace, u as buildGoogleChatGroupPolicyScope, w as updateGoogleChatMessage, x as downloadGoogleChatMedia, y as GoogleChatApiError } from "./channel.adapters-CLzwB-5-.mjs";
2
- import { n as googleChatApprovalAuth } from "./approval-auth-Dd-6ne22.mjs";
1
+ import { C as sendGoogleChatMessage, O as googleChatApprovalControls, S as probeGoogleChat, T as verifyGoogleChatRequest, b as deleteGoogleChatMessage, c as googleChatIngressIdentity, d as formatGoogleChatMediaText, f as formatGoogleChatTextChunks, k as readGoogleChatApprovalActionToken, l as normalizeGoogleChatUserId, p as isGoogleChatGroupSpace, u as buildGoogleChatGroupPolicyScope, w as updateGoogleChatMessage, x as downloadGoogleChatMedia, y as GoogleChatApiError } from "./channel.adapters-BVT76qsz.mjs";
2
+ import { n as googleChatApprovalAuth } from "./approval-auth-C-AJm9xZ.mjs";
3
3
  import { t as getGoogleChatRuntime } from "./runtime-C5OOOlaP.mjs";
4
4
  import { n as escapeGoogleChatApprovalCardText, t as buildGoogleChatApprovalTextWidget } from "./approval-card-text-BKg_4mXq.mjs";
5
+ import { createChannelIngressError } from "openclaw/plugin-sdk/channel-outbound";
6
+ import { channelBlockedPatch, channelReadyPatch } from "openclaw/plugin-sdk/gateway-runtime";
5
7
  import { normalizeLowercaseStringOrEmpty, normalizeOptionalString, normalizeStringEntries, normalizeTrimmedStringList } from "openclaw/plugin-sdk/string-coerce-runtime";
6
8
  import { mergePairLoopGuardConfig } from "openclaw/plugin-sdk/pair-loop-guard-runtime";
7
9
  import { PlatformMessageNotDispatchedError, collectErrorGraphCandidates, formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
8
10
  import { MediaFetchError } from "openclaw/plugin-sdk/media-runtime";
11
+ import { formatApprovalDecisionLabel } from "openclaw/plugin-sdk/approval-runtime";
9
12
  import { channelIngressRoutes, createStandardRawEventIngressMonitor } from "openclaw/plugin-sdk/channel-ingress-runtime";
10
- import { createChannelIngressError } from "openclaw/plugin-sdk/channel-outbound";
11
13
  import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
12
- import { channelBlockedPatch, channelReadyPatch } from "openclaw/plugin-sdk/gateway-runtime";
13
14
  import { isRecord as isRecord$1 } from "openclaw/plugin-sdk/channel-secret-basic-runtime";
14
15
  import { resolveAgentConfig } from "openclaw/plugin-sdk/agent-scope-runtime";
15
16
  import { createChannelInboundEnvelopeBuilderAsync, createChannelPartialDeliveryError, formatInboundMediaUnavailableText, recordChannelBotPairLoopAndCheckSuppression, toInboundMediaFactsWithMetadata } from "openclaw/plugin-sdk/channel-inbound";
@@ -23,16 +24,11 @@ import { isDangerousNameMatchingEnabled } from "openclaw/plugin-sdk/dangerous-na
23
24
  import { GROUP_POLICY_BLOCKED_LABEL, resolveAllowlistProviderRuntimeGroupPolicy, resolveDefaultGroupPolicy, warnMissingProviderGroupPolicyFallbackOnce } from "openclaw/plugin-sdk/runtime-group-policy";
24
25
  import { createWebhookInFlightLimiter, readJsonWebhookBodyOrReject, runDetachedWebhookWork } from "openclaw/plugin-sdk/webhook-request-guards";
25
26
  import { registerWebhookTargetWithPluginRoute, resolveWebhookTargetWithAuthOrReject, withResolvedWebhookRequestPipeline } from "openclaw/plugin-sdk/webhook-targets";
26
- //#region extensions/googlechat/src/approval-terminal-card.ts
27
+ //#region extensions/googlechat/src/approval-card-click.ts
27
28
  const GOOGLECHAT_APPROVAL_CARD_ID = "openclaw-approval";
28
29
  function formatCanonicalOutcome(approval) {
29
- switch (approval.status) {
30
- case "allowed": return approval.decision === "allow-always" ? "Allowed always" : "Allowed once";
31
- case "denied": return "Denied";
32
- case "expired": return "Expired";
33
- case "cancelled": return "Cancelled";
34
- }
35
- return "Unavailable";
30
+ if (approval.status === "allowed" || approval.status === "denied") return formatApprovalDecisionLabel(approval.decision);
31
+ return approval.status === "expired" ? "Expired" : approval.status === "cancelled" ? "Cancelled" : "Unavailable";
36
32
  }
37
33
  function buildSubjectSection(presentation) {
38
34
  if (presentation.kind === "exec") return {
@@ -46,32 +42,6 @@ function buildSubjectSection(presentation) {
46
42
  widgets: [buildGoogleChatApprovalTextWidget(requestText, "html")]
47
43
  };
48
44
  }
49
- /** Render the canonical first-answer result without retaining any actionable buttons. */
50
- function buildGoogleChatCanonicalApprovalTerminalCards(result) {
51
- const { approval } = result;
52
- const kindLabel = approval.presentation.kind === "plugin" ? "Plugin" : "Exec";
53
- const detailLines = [
54
- `<b>Approval ID:</b> ${escapeGoogleChatApprovalCardText(JSON.stringify(approval.id).slice(1, -1))}`,
55
- `<b>Status:</b> ${escapeGoogleChatApprovalCardText(approval.status)}`,
56
- ...approval.status === "allowed" || approval.status === "denied" ? [`<b>Decision:</b> ${escapeGoogleChatApprovalCardText(approval.decision)}`] : [],
57
- `<b>Reason:</b> ${escapeGoogleChatApprovalCardText(approval.reason)}`
58
- ];
59
- return [{
60
- cardId: GOOGLECHAT_APPROVAL_CARD_ID,
61
- card: {
62
- header: {
63
- title: `${kindLabel} Approval: ${formatCanonicalOutcome(approval)}`,
64
- subtitle: result.applied ? "Resolved by this action" : "Already resolved"
65
- },
66
- sections: [buildSubjectSection(approval.presentation), {
67
- header: "Details",
68
- widgets: [buildGoogleChatApprovalTextWidget(detailLines.join("<br>"), "html")]
69
- }]
70
- }
71
- }];
72
- }
73
- //#endregion
74
- //#region extensions/googlechat/src/approval-card-click.ts
75
45
  function logIgnored(target, message) {
76
46
  target.runtime.log?.(`[${target.account.accountId}] googlechat approval ignored: ${message}`);
77
47
  }
@@ -121,10 +91,30 @@ async function maybeHandleGoogleChatApprovalCardClick(params) {
121
91
  accountId: params.target.account.accountId,
122
92
  senderId: actor
123
93
  });
94
+ const { approval } = result;
95
+ const kindLabel = approval.presentation.kind === "plugin" ? "Plugin" : "Exec";
96
+ const detailLines = [
97
+ `<b>Approval ID:</b> ${escapeGoogleChatApprovalCardText(JSON.stringify(approval.id).slice(1, -1))}`,
98
+ `<b>Status:</b> ${escapeGoogleChatApprovalCardText(approval.status)}`,
99
+ ...approval.status === "allowed" || approval.status === "denied" ? [`<b>Decision:</b> ${escapeGoogleChatApprovalCardText(approval.decision)}`] : [],
100
+ `<b>Reason:</b> ${escapeGoogleChatApprovalCardText(approval.reason)}`
101
+ ];
124
102
  await updateGoogleChatMessage({
125
103
  account: params.target.account,
126
104
  messageName: consumed.messageName,
127
- cardsV2: buildGoogleChatCanonicalApprovalTerminalCards(result)
105
+ cardsV2: [{
106
+ cardId: GOOGLECHAT_APPROVAL_CARD_ID,
107
+ card: {
108
+ header: {
109
+ title: `${kindLabel} Approval: ${formatCanonicalOutcome(approval)}`,
110
+ subtitle: result.applied ? "Resolved by this action" : "Already resolved"
111
+ },
112
+ sections: [buildSubjectSection(approval.presentation), {
113
+ header: "Details",
114
+ widgets: [buildGoogleChatApprovalTextWidget(detailLines.join("<br>"), "html")]
115
+ }]
116
+ }
117
+ }]
128
118
  });
129
119
  return result;
130
120
  });
@@ -140,36 +130,6 @@ async function maybeHandleGoogleChatApprovalCardClick(params) {
140
130
  }
141
131
  //#endregion
142
132
  //#region extensions/googlechat/src/monitor-access.ts
143
- function resolveGoogleChatGroupConfig(params) {
144
- const { groupId, groupName, groups } = params;
145
- const entries = groups ?? {};
146
- const keys = Object.keys(entries);
147
- if (keys.length === 0) return {
148
- entry: void 0,
149
- allowlistConfigured: false,
150
- deprecatedNameMatch: false
151
- };
152
- const { "*": fallback, ...scopes } = entries;
153
- const scope = buildGoogleChatGroupPolicyScope({
154
- tree: {
155
- defaults: fallback,
156
- scopes
157
- },
158
- groupId
159
- });
160
- const entry = scope.matchKey ? entries[scope.matchKey] : void 0;
161
- const normalizedGroupName = normalizeLowercaseStringOrEmpty(groupName ?? "");
162
- const deprecatedNameMatch = !entry && Boolean(groupName && keys.some((key) => {
163
- const trimmed = key.trim();
164
- if (!trimmed || trimmed === "*" || /^spaces\//i.test(trimmed)) return false;
165
- return trimmed === groupName || normalizeLowercaseStringOrEmpty(trimmed) === normalizedGroupName;
166
- }));
167
- return {
168
- entry: deprecatedNameMatch ? void 0 : entry ?? fallback,
169
- allowlistConfigured: true,
170
- deprecatedNameMatch
171
- };
172
- }
173
133
  function extractMentionInfo(annotations, botUser) {
174
134
  const mentionAnnotations = annotations.filter((entry) => entry.type === "USER_MENTION");
175
135
  const hasAnyMention = mentionAnnotations.length > 0;
@@ -186,21 +146,15 @@ function extractMentionInfo(annotations, botUser) {
186
146
  }
187
147
  const warnedDeprecatedUsersEmailAllowFrom = /* @__PURE__ */ new Set();
188
148
  const warnedMutableGroupKeys = /* @__PURE__ */ new Set();
149
+ function markDeprecatedEntriesWarning(entries, warned) {
150
+ const key = entries.map((entry) => normalizeLowercaseStringOrEmpty(entry)).toSorted((a, b) => a.localeCompare(b)).join(",");
151
+ if (entries.length === 0 || warned.has(key)) return false;
152
+ warned.add(key);
153
+ return true;
154
+ }
189
155
  function warnDeprecatedUsersEmailEntries(logVerbose, entries) {
190
156
  const deprecated = normalizeTrimmedStringList(entries).filter((v) => /^users\/.+@.+/i.test(v));
191
- if (deprecated.length === 0) return;
192
- const key = deprecated.map((v) => normalizeLowercaseStringOrEmpty(v)).toSorted((a, b) => a.localeCompare(b)).join(",");
193
- if (warnedDeprecatedUsersEmailAllowFrom.has(key)) return;
194
- warnedDeprecatedUsersEmailAllowFrom.add(key);
195
- logVerbose(`Deprecated allowFrom entry detected: "users/<email>" is no longer treated as an email allowlist. Use raw email (alice@example.com) or immutable user id (users/<id>). entries=${deprecated.join(", ")}`);
196
- }
197
- function warnMutableGroupKeysConfigured(logVerbose, groups) {
198
- const mutableKeys = Object.keys(groups ?? {}).map((key) => key.trim()).filter((key) => key && key !== "*" && !/^spaces\//i.test(key));
199
- if (mutableKeys.length === 0) return;
200
- const warningKey = mutableKeys.map((key) => normalizeLowercaseStringOrEmpty(key)).toSorted((a, b) => a.localeCompare(b)).join(",");
201
- if (warnedMutableGroupKeys.has(warningKey)) return;
202
- warnedMutableGroupKeys.add(warningKey);
203
- logVerbose(`Deprecated Google Chat group key detected: group routing now requires stable space ids (spaces/<spaceId>). Update channels.googlechat.groups keys: ${mutableKeys.join(", ")}`);
157
+ if (markDeprecatedEntriesWarning(deprecated, warnedDeprecatedUsersEmailAllowFrom)) logVerbose(`Deprecated allowFrom entry detected: "users/<email>" is no longer treated as an email allowlist. Use raw email (alice@example.com) or immutable user id (users/<id>). entries=${deprecated.join(", ")}`);
204
158
  }
205
159
  async function applyGoogleChatInboundAccessPolicy(params) {
206
160
  const { account, config, core, space, message, isGroup, senderId, senderName, senderEmail, rawBody, statusSink, logVerbose } = params;
@@ -224,12 +178,39 @@ async function applyGoogleChatInboundAccessPolicy(params) {
224
178
  blockedLabel: GROUP_POLICY_BLOCKED_LABEL.space,
225
179
  log: logVerbose
226
180
  });
227
- warnMutableGroupKeysConfigured(logVerbose, account.config.groups ?? void 0);
228
- const groupConfigResolved = resolveGoogleChatGroupConfig({
229
- groupId: spaceId,
230
- groupName: space.displayName ?? null,
231
- groups: account.config.groups ?? void 0
232
- });
181
+ const mutableKeys = Object.keys(account.config.groups ?? {}).map((key) => key.trim()).filter((key) => key && key !== "*" && !/^spaces\//i.test(key));
182
+ if (markDeprecatedEntriesWarning(mutableKeys, warnedMutableGroupKeys)) logVerbose(`Deprecated Google Chat group key detected: group routing now requires stable space ids (spaces/<spaceId>). Update channels.googlechat.groups keys: ${mutableKeys.join(", ")}`);
183
+ const groupName = space.displayName ?? null;
184
+ const groups = account.config.groups;
185
+ const groupConfigResolved = (() => {
186
+ const entries = groups ?? {};
187
+ const keys = Object.keys(entries);
188
+ if (keys.length === 0) return {
189
+ entry: void 0,
190
+ allowlistConfigured: false,
191
+ deprecatedNameMatch: false
192
+ };
193
+ const { "*": fallback, ...scopes } = entries;
194
+ const scope = buildGoogleChatGroupPolicyScope({
195
+ tree: {
196
+ defaults: fallback,
197
+ scopes
198
+ },
199
+ groupId: spaceId
200
+ });
201
+ const entry = scope.matchKey ? entries[scope.matchKey] : void 0;
202
+ const normalizedGroupName = normalizeLowercaseStringOrEmpty(groupName ?? "");
203
+ const deprecatedNameMatch = !entry && Boolean(groupName && keys.some((key) => {
204
+ const trimmed = key.trim();
205
+ if (!trimmed || trimmed === "*" || /^spaces\//i.test(trimmed)) return false;
206
+ return trimmed === groupName || normalizeLowercaseStringOrEmpty(trimmed) === normalizedGroupName;
207
+ }));
208
+ return {
209
+ entry: deprecatedNameMatch ? void 0 : entry ?? fallback,
210
+ allowlistConfigured: true,
211
+ deprecatedNameMatch
212
+ };
213
+ })();
233
214
  const groupEntry = groupConfigResolved.entry;
234
215
  const groupUsers = groupEntry?.users ?? account.config.groupAllowFrom ?? [];
235
216
  let effectiveWasMentioned;
@@ -391,39 +372,10 @@ async function applyGoogleChatInboundAccessPolicy(params) {
391
372
  };
392
373
  }
393
374
  //#endregion
394
- //#region extensions/googlechat/src/monitor-durable.ts
395
- function resolveGoogleChatDurableReplyOptions(params) {
396
- if (params.infoKind !== "final" || params.hasTypingMessage) return false;
397
- const threadId = params.payload.replyToId?.trim() || void 0;
398
- if (!threadId) return {
399
- to: params.spaceId,
400
- replyToId: null
401
- };
402
- return {
403
- to: params.spaceId,
404
- replyToId: threadId,
405
- threadId
406
- };
407
- }
408
- //#endregion
409
375
  //#region extensions/googlechat/src/monitor-event.ts
410
- var GoogleChatEventPayloadError = class extends Error {
411
- constructor() {
412
- super("invalid payload");
413
- this.name = "GoogleChatEventPayloadError";
414
- }
415
- };
416
- function recordParamsToActionParameters(params) {
417
- if (!params) return;
418
- const entries = Object.entries(params).filter((entry) => typeof entry[1] === "string").map(([key, value]) => ({
419
- key,
420
- value
421
- }));
422
- return entries.length > 0 ? entries : void 0;
423
- }
424
376
  /** Normalize only at authenticated dispatch; durable admission stores the untouched envelope. */
425
377
  function parseGoogleChatInboundPayload(raw) {
426
- if (!isRecord$1(raw)) throw new GoogleChatEventPayloadError();
378
+ if (!isRecord$1(raw)) throw new Error("invalid payload");
427
379
  let eventPayload = raw;
428
380
  const rawObj = raw;
429
381
  const chat = rawObj.chat;
@@ -440,7 +392,12 @@ function parseGoogleChatInboundPayload(raw) {
440
392
  const buttonClickedPayload = chatPayload?.buttonClickedPayload;
441
393
  if (buttonClickedPayload) {
442
394
  const invokedFunction = rawObj.commonEventObject.invokedFunction;
443
- const actionParameters = recordParamsToActionParameters(rawObj.commonEventObject.parameters);
395
+ const parameters = rawObj.commonEventObject.parameters;
396
+ const entries = parameters ? Object.entries(parameters).filter((entry) => typeof entry[1] === "string").map(([key, value]) => ({
397
+ key,
398
+ value
399
+ })) : [];
400
+ const actionParameters = entries.length > 0 ? entries : void 0;
444
401
  eventPayload = {
445
402
  type: "CARD_CLICKED",
446
403
  space: buttonClickedPayload.space,
@@ -460,10 +417,10 @@ function parseGoogleChatInboundPayload(raw) {
460
417
  }
461
418
  const event = eventPayload;
462
419
  const eventType = event.type ?? event.eventType;
463
- if (typeof eventType !== "string" || !isRecord$1(event.space)) throw new GoogleChatEventPayloadError();
420
+ if (typeof eventType !== "string" || !isRecord$1(event.space)) throw new Error("invalid payload");
464
421
  if (eventType === "MESSAGE") {
465
- if (!isRecord$1(event.message) || !event.space?.name?.trim() || !event.message?.name?.trim()) throw new GoogleChatEventPayloadError();
466
- } else if (eventType === "CARD_CLICKED" && !isRecord$1(event.user)) throw new GoogleChatEventPayloadError();
422
+ if (!isRecord$1(event.message) || !event.space?.name?.trim() || !event.message?.name?.trim()) throw new Error("invalid payload");
423
+ } else if (eventType === "CARD_CLICKED" && !isRecord$1(event.user)) throw new Error("invalid payload");
467
424
  return event;
468
425
  }
469
426
  //#endregion
@@ -530,9 +487,7 @@ function createGoogleChatIngressMonitor(options) {
530
487
  if (!isRecord$1(rawEvent)) throw new GoogleChatIngressPermanentError("invalid-event", "Google Chat webhook envelope must be an object.");
531
488
  const durableEvent = { ...rawEvent };
532
489
  delete durableEvent.authorizationEventObject;
533
- const serialized = JSON.stringify(durableEvent);
534
- if (typeof serialized !== "string") throw new GoogleChatIngressPermanentError("invalid-event", "Google Chat webhook envelope cannot be serialized.");
535
- return serialized;
490
+ return JSON.stringify(durableEvent);
536
491
  };
537
492
  return createStandardRawEventIngressMonitor({
538
493
  queue: () => getGoogleChatRuntime().state.openChannelIngressQueue({ accountId: options.accountId }),
@@ -554,120 +509,6 @@ function createGoogleChatIngressMonitor(options) {
554
509
  });
555
510
  }
556
511
  //#endregion
557
- //#region extensions/googlechat/src/monitor-reply-delivery.ts
558
- function createGoogleChatTypingMessage(params) {
559
- const name = params.messageName.trim();
560
- const requestedThreadName = params.requestedThreadName?.trim();
561
- if (!requestedThreadName) return {
562
- placement: "top-level",
563
- name
564
- };
565
- return {
566
- placement: "thread",
567
- name,
568
- requestedThreadName,
569
- deliveredThreadName: params.deliveredThreadName?.trim() || requestedThreadName
570
- };
571
- }
572
- async function deliverGoogleChatReply(params) {
573
- const { payload, account, spaceId, runtime, core, config, statusSink } = params;
574
- let typingMessage = params.typingMessage;
575
- const replyThreadName = payload.replyToId?.trim() || void 0;
576
- const reply = resolveSendableOutboundReplyParts(payload);
577
- let deliveryThreadName = replyThreadName;
578
- const acceptedText = [];
579
- const runTextOperation = async (operation) => await operation.catch((error) => {
580
- if (acceptedText.length === 0) throw error;
581
- throw createChannelPartialDeliveryError(error, {
582
- messageIds: acceptedText.flatMap(({ id }) => id ? [id] : []),
583
- content: acceptedText.map(({ text }) => text).join("\n"),
584
- visibleReplySent: true
585
- });
586
- });
587
- const typingMatchesReply = typingMessage?.placement === "thread" ? typingMessage.requestedThreadName === replyThreadName : typingMessage?.placement === "top-level" ? replyThreadName === void 0 : false;
588
- if (typingMessage && !typingMatchesReply) {
589
- try {
590
- await deleteGoogleChatMessage({
591
- account,
592
- messageName: typingMessage.name
593
- });
594
- } catch (err) {
595
- runtime.error?.(`Google Chat typing cleanup failed: ${String(err)}`);
596
- }
597
- typingMessage = void 0;
598
- } else if (typingMessage?.placement === "thread") deliveryThreadName = typingMessage.deliveredThreadName;
599
- let text = reply.text;
600
- let mediaError;
601
- try {
602
- text = formatGoogleChatMediaText(reply.text, reply.mediaUrls);
603
- } catch (error) {
604
- mediaError = error;
605
- }
606
- const chunkLimit = account.config.textChunkLimit ?? 4e3;
607
- const chunkMode = core.channel.text.resolveChunkMode(config, "googlechat", account.accountId);
608
- const chunks = formatGoogleChatTextChunks(text, chunkLimit).flatMap((chunk) => core.channel.text.chunkMarkdownTextWithMode(chunk, chunkLimit, chunkMode));
609
- const rejection = mediaError ? formatErrorMessage(mediaError) : text && !chunks.some((chunk) => chunk) ? "Google Chat reply has no visible text after formatting." : void 0;
610
- if (rejection) {
611
- try {
612
- if (typingMessage) await deleteGoogleChatMessage({
613
- account,
614
- messageName: typingMessage.name
615
- });
616
- } catch (err) {
617
- runtime.error?.(`Google Chat typing cleanup failed: ${String(err)}`);
618
- }
619
- throw new PlatformMessageNotDispatchedError(rejection, {
620
- cause: mediaError,
621
- retryable: false
622
- });
623
- }
624
- const recordOutboundStatus = () => {
625
- try {
626
- statusSink?.({ lastOutboundAt: Date.now() });
627
- } catch (err) {
628
- runtime.error?.(`Google Chat outbound status update failed: ${String(err)}`);
629
- }
630
- };
631
- const sendTextMessage = async (chunk) => {
632
- const sent = await runTextOperation(sendGoogleChatMessage({
633
- account,
634
- space: spaceId,
635
- text: chunk,
636
- thread: deliveryThreadName
637
- }));
638
- if (sent) acceptedText.push({
639
- id: sent.messageName?.trim() || void 0,
640
- text: chunk
641
- });
642
- if (replyThreadName) deliveryThreadName = sent?.threadName?.trim() || deliveryThreadName;
643
- };
644
- for (const chunk of chunks) {
645
- if (!chunk) continue;
646
- if (typingMessage) {
647
- try {
648
- const updated = await updateGoogleChatMessage({
649
- account,
650
- messageName: typingMessage.name,
651
- text: chunk
652
- });
653
- acceptedText.push({
654
- id: updated.messageName?.trim() || typingMessage.name,
655
- text: chunk
656
- });
657
- } catch (error) {
658
- if (!(error instanceof GoogleChatApiError) || error.status !== 404) throw error;
659
- runtime.error?.(`Google Chat typing update failed: ${String(error)}`);
660
- await sendTextMessage(chunk);
661
- }
662
- typingMessage = void 0;
663
- recordOutboundStatus();
664
- continue;
665
- }
666
- await sendTextMessage(chunk);
667
- recordOutboundStatus();
668
- }
669
- }
670
- //#endregion
671
512
  //#region extensions/googlechat/src/monitor-reply-target.ts
672
513
  /**
673
514
  * Google Chat only accepts a thread resource (`spaces/x/threads/y`) as a reply
@@ -871,16 +712,23 @@ function registerGoogleChatWebhookTarget(target) {
871
712
  //#endregion
872
713
  //#region extensions/googlechat/src/monitor.ts
873
714
  setGoogleChatWebhookEventProcessor(processGoogleChatEvent);
715
+ function createGoogleChatTypingMessage(params) {
716
+ const name = params.messageName.trim();
717
+ const requestedThreadName = params.requestedThreadName?.trim();
718
+ if (!requestedThreadName) return {
719
+ placement: "top-level",
720
+ name
721
+ };
722
+ return {
723
+ placement: "thread",
724
+ name,
725
+ requestedThreadName,
726
+ deliveredThreadName: params.deliveredThreadName?.trim() || requestedThreadName
727
+ };
728
+ }
874
729
  function logVerbose(core, runtime, message) {
875
730
  if (core.logging.shouldLogVerbose()) runtime.log?.(`[googlechat] ${message}`);
876
731
  }
877
- function resolveBotDisplayName(params) {
878
- const { accountName, agentId, config } = params;
879
- if (accountName?.trim()) return accountName.trim();
880
- const agent = resolveAgentConfig(config, agentId);
881
- if (agent?.name?.trim()) return agent.name.trim();
882
- return agent?.identity?.name?.trim() || "OpenClaw";
883
- }
884
732
  async function processGoogleChatEvent(event, target, turnAdoptionLifecycle, config = target.config) {
885
733
  const eventType = event.type ?? event.eventType;
886
734
  if (eventType === "CARD_CLICKED") {
@@ -901,7 +749,7 @@ async function processGoogleChatEvent(event, target, turnAdoptionLifecycle, conf
901
749
  const sender = message.sender ?? event.user;
902
750
  const senderId = sender?.name ?? "";
903
751
  const senderName = sender?.displayName ?? "";
904
- const senderEmail = sender?.email ?? void 0;
752
+ const senderEmail = sender?.email;
905
753
  const isBotSender = sender?.type?.toUpperCase() === "BOT";
906
754
  const appUserId = account.config.botUser?.trim() || "users/app";
907
755
  const allowBots = account.config.allowBots === true;
@@ -966,38 +814,28 @@ async function processGoogleChatEvent(event, target, turnAdoptionLifecycle, conf
966
814
  }
967
815
  }
968
816
  const mediaInputs = attachments.map((attachment) => ({ contentType: attachment.contentType }));
969
- const first = attachments.at(0);
970
- if (first) try {
971
- const attachmentData = await downloadAttachment(first, account, mediaMaxMb, core);
972
- if (attachmentData) mediaInputs[0] = {
973
- path: attachmentData.path,
974
- url: attachmentData.path,
975
- contentType: attachmentData.contentType ?? first.contentType
976
- };
977
- else {
978
- const notice = `[Google Chat attachment unavailable: ${first.driveDataRef ? "Google Drive files are not downloadable" : "unsupported attachment source"}; upload the file directly]`;
979
- rawBody = formatInboundMediaUnavailableText({
980
- body: rawBody,
981
- notice
982
- });
983
- runtime.error?.(`[${account.accountId}] ${notice}`);
984
- }
985
- } catch (error) {
986
- if (!(error instanceof MediaFetchError) || error.code !== "max_bytes") throw error;
987
- const notice = `[Google Chat attachment too large; maximum ${mediaMaxMb} MB]`;
988
- rawBody = formatInboundMediaUnavailableText({
989
- body: rawBody,
990
- notice
991
- });
992
- runtime.error?.(`[${account.accountId}] ${notice} Increase channels.googlechat.mediaMaxMb to process larger attachments.`);
993
- }
994
- const additionalCount = attachments.length - 1;
995
- if (additionalCount > 0) {
996
- const notice = `[Google Chat: ${additionalCount} additional ${additionalCount === 1 ? "attachment was" : "attachments were"} not processed; only the first attachment is supported]`;
817
+ const attachmentNotices = /* @__PURE__ */ new Set();
818
+ const reportAttachmentUnavailable = (notice, hint = "") => {
819
+ if (attachmentNotices.has(notice)) return;
820
+ attachmentNotices.add(notice);
997
821
  rawBody = formatInboundMediaUnavailableText({
998
822
  body: rawBody,
999
823
  notice
1000
824
  });
825
+ runtime.error?.(`[${account.accountId}] ${notice}${hint}`);
826
+ };
827
+ for (const [index, attachment] of attachments.entries()) try {
828
+ const attachmentData = await downloadAttachment(attachment, account, mediaMaxMb, core);
829
+ if (attachmentData) mediaInputs[index] = {
830
+ path: attachmentData.path,
831
+ url: attachmentData.path,
832
+ contentType: attachmentData.contentType ?? attachment.contentType
833
+ };
834
+ else reportAttachmentUnavailable(`[Google Chat attachment unavailable: ${attachment.driveDataRef ? "Google Drive files are not downloadable" : "unsupported attachment source"}; upload the file directly]`);
835
+ } catch (error) {
836
+ const missing = error instanceof GoogleChatApiError && error.status === 404;
837
+ if (!missing && (!(error instanceof MediaFetchError) || error.code !== "max_bytes")) throw error;
838
+ reportAttachmentUnavailable(missing ? "[Google Chat attachment unavailable: file not found; upload the file directly]" : `[Google Chat attachment too large; maximum ${mediaMaxMb} MB]`, missing ? "" : " Increase channels.googlechat.mediaMaxMb to process larger attachments.");
1001
839
  }
1002
840
  const media = mediaInputs.length === 0 ? [] : await toInboundMediaFactsWithMetadata(mediaInputs);
1003
841
  const fromLabel = isGroup ? space.displayName || `space:${spaceId}` : senderName || `user:${senderId}`;
@@ -1056,7 +894,7 @@ async function processGoogleChatEvent(event, target, turnAdoptionLifecycle, conf
1056
894
  WasMentioned: isGroup ? effectiveWasMentioned : void 0,
1057
895
  CommandAuthorized: commandAuthorized,
1058
896
  GroupSubject: void 0,
1059
- GroupSpace: isGroup ? space.displayName ?? void 0 : void 0
897
+ GroupSpace: isGroup ? space.displayName : void 0
1060
898
  }
1061
899
  });
1062
900
  let typingIndicator = account.config.typingIndicator ?? "message";
@@ -1067,11 +905,14 @@ async function processGoogleChatEvent(event, target, turnAdoptionLifecycle, conf
1067
905
  let typingMessage;
1068
906
  const effectiveReplyThreadName = account.config.replyToMode && account.config.replyToMode !== "off" ? replyThreadName : void 0;
1069
907
  if (typingIndicator === "message") try {
1070
- const botName = resolveBotDisplayName({
1071
- accountName: account.config.name,
1072
- agentId: route.agentId,
1073
- config
1074
- });
908
+ const accountName = account.config.name;
909
+ const agentId = route.agentId;
910
+ let botName;
911
+ if (accountName?.trim()) botName = accountName.trim();
912
+ else {
913
+ const agent = resolveAgentConfig(config, agentId);
914
+ botName = agent?.name?.trim() ? agent.name.trim() : agent?.identity?.name?.trim() || "OpenClaw";
915
+ }
1075
916
  const result = await sendGoogleChatMessage({
1076
917
  account,
1077
918
  space: spaceId,
@@ -1086,76 +927,186 @@ async function processGoogleChatEvent(event, target, turnAdoptionLifecycle, conf
1086
927
  } catch (err) {
1087
928
  runtime.error?.(`Failed sending typing message: ${String(err)}`);
1088
929
  }
1089
- await core.channel.inbound.run({
1090
- channel: "googlechat",
1091
- accountId: route.accountId,
1092
- raw: message,
1093
- ...turnAdoptionLifecycle ? { turnAdoptionLifecycle } : {},
1094
- adapter: {
1095
- ingest: () => ({
1096
- id: message.name ?? spaceId,
1097
- timestamp: timestampMs,
1098
- rawText: rawBody,
1099
- textForAgent: rawBody,
1100
- textForCommands: rawBody,
1101
- raw: message
1102
- }),
1103
- resolveTurn: () => ({
1104
- cfg: config,
1105
- channel: "googlechat",
1106
- accountId: route.accountId,
1107
- route: {
1108
- agentId: route.agentId,
1109
- sessionKey: route.sessionKey
1110
- },
1111
- ctxPayload,
1112
- delivery: {
1113
- durable: (payload, info) => resolveGoogleChatDurableReplyOptions({
1114
- payload: normalizeGoogleChatReplyTarget({
1115
- payload,
1116
- sourceMessageName: message.name,
1117
- replyThreadName: effectiveReplyThreadName
1118
- }),
1119
- infoKind: info.kind,
1120
- spaceId,
1121
- hasTypingMessage: Boolean(typingMessage)
1122
- }),
1123
- deliver: async (payload) => {
1124
- await deliverGoogleChatReply({
1125
- payload: normalizeGoogleChatReplyTarget({
930
+ const cleanupTypingMessage = async () => {
931
+ const placeholder = typingMessage;
932
+ typingMessage = void 0;
933
+ if (!placeholder) return;
934
+ try {
935
+ await deleteGoogleChatMessage({
936
+ account,
937
+ messageName: placeholder.name
938
+ });
939
+ } catch (error) {
940
+ runtime.error?.(`Google Chat typing cleanup failed: ${String(error)}`);
941
+ }
942
+ };
943
+ let deferred = false;
944
+ const typingTurnLifecycle = typingMessage ? {
945
+ ...turnAdoptionLifecycle,
946
+ onAdopted: () => turnAdoptionLifecycle?.onAdopted(),
947
+ onDeferred: () => {
948
+ turnAdoptionLifecycle?.onDeferred();
949
+ deferred = true;
950
+ },
951
+ onSettled: () => deferred ? cleanupTypingMessage() : void 0
952
+ } : turnAdoptionLifecycle;
953
+ try {
954
+ await core.channel.inbound.run({
955
+ channel: "googlechat",
956
+ accountId: route.accountId,
957
+ raw: message,
958
+ ...typingTurnLifecycle ? { turnAdoptionLifecycle: typingTurnLifecycle } : {},
959
+ adapter: {
960
+ ingest: () => ({
961
+ id: message.name ?? spaceId,
962
+ timestamp: timestampMs,
963
+ rawText: rawBody,
964
+ textForAgent: rawBody,
965
+ textForCommands: rawBody,
966
+ raw: message
967
+ }),
968
+ resolveTurn: () => ({
969
+ cfg: config,
970
+ channel: "googlechat",
971
+ accountId: route.accountId,
972
+ route: {
973
+ agentId: route.agentId,
974
+ sessionKey: route.sessionKey
975
+ },
976
+ ctxPayload,
977
+ delivery: {
978
+ durable: (payload, info) => {
979
+ const normalizedPayload = normalizeGoogleChatReplyTarget({
1126
980
  payload,
1127
981
  sourceMessageName: message.name,
1128
982
  replyThreadName: effectiveReplyThreadName
1129
- }),
1130
- account,
1131
- spaceId,
1132
- runtime,
1133
- core,
1134
- config,
1135
- statusSink,
1136
- typingMessage
1137
- });
1138
- typingMessage = void 0;
1139
- },
1140
- onDelivered: () => {
1141
- statusSink?.({ lastOutboundAt: Date.now() });
983
+ });
984
+ if (info.kind !== "final" || Boolean(typingMessage)) return false;
985
+ const threadId = normalizedPayload.replyToId?.trim() || void 0;
986
+ if (!threadId) return {
987
+ to: spaceId,
988
+ replyToId: null
989
+ };
990
+ return {
991
+ to: spaceId,
992
+ replyToId: threadId,
993
+ threadId
994
+ };
995
+ },
996
+ deliver: async (payload) => {
997
+ const normalizedPayload = normalizeGoogleChatReplyTarget({
998
+ payload,
999
+ sourceMessageName: message.name,
1000
+ replyThreadName: effectiveReplyThreadName
1001
+ });
1002
+ let deliveryTypingMessage = typingMessage;
1003
+ const targetThreadName = normalizedPayload.replyToId?.trim() || void 0;
1004
+ const reply = resolveSendableOutboundReplyParts(normalizedPayload);
1005
+ let deliveryThreadName = targetThreadName;
1006
+ const acceptedText = [];
1007
+ const runTextOperation = async (operation) => await operation.catch((error) => {
1008
+ if (acceptedText.length === 0) throw error;
1009
+ throw createChannelPartialDeliveryError(error, {
1010
+ messageIds: acceptedText.flatMap(({ id }) => id ? [id] : []),
1011
+ content: acceptedText.map(({ text }) => text).join("\n"),
1012
+ visibleReplySent: true
1013
+ });
1014
+ });
1015
+ const typingMatchesReply = deliveryTypingMessage?.placement === "thread" ? deliveryTypingMessage.requestedThreadName === targetThreadName : deliveryTypingMessage?.placement === "top-level" ? targetThreadName === void 0 : false;
1016
+ if (deliveryTypingMessage && !typingMatchesReply) {
1017
+ await cleanupTypingMessage();
1018
+ deliveryTypingMessage = void 0;
1019
+ } else if (deliveryTypingMessage?.placement === "thread") deliveryThreadName = deliveryTypingMessage.deliveredThreadName;
1020
+ let text;
1021
+ try {
1022
+ text = formatGoogleChatMediaText(reply.text, reply.mediaUrls);
1023
+ } catch (cause) {
1024
+ await cleanupTypingMessage();
1025
+ throw new PlatformMessageNotDispatchedError(cause instanceof Error ? cause.message : String(cause), {
1026
+ cause,
1027
+ retryable: false
1028
+ });
1029
+ }
1030
+ const chunkLimit = account.config.textChunkLimit ?? 4e3;
1031
+ const chunkMode = core.channel.text.resolveChunkMode(config, "googlechat", account.accountId);
1032
+ const chunks = formatGoogleChatTextChunks(text, chunkLimit).flatMap((chunk) => core.channel.text.chunkMarkdownTextWithMode(chunk, chunkLimit, chunkMode));
1033
+ const rejection = text && !chunks.some((chunk) => chunk) ? "Google Chat reply has no visible text after formatting." : void 0;
1034
+ if (rejection) {
1035
+ await cleanupTypingMessage();
1036
+ throw new PlatformMessageNotDispatchedError(rejection, {
1037
+ cause: void 0,
1038
+ retryable: false
1039
+ });
1040
+ }
1041
+ const recordOutboundStatus = () => {
1042
+ try {
1043
+ statusSink?.({ lastOutboundAt: Date.now() });
1044
+ } catch (err) {
1045
+ runtime.error?.(`Google Chat outbound status update failed: ${String(err)}`);
1046
+ }
1047
+ };
1048
+ const sendTextMessage = async (chunk) => {
1049
+ const sent = await runTextOperation(sendGoogleChatMessage({
1050
+ account,
1051
+ space: spaceId,
1052
+ text: chunk,
1053
+ thread: deliveryThreadName
1054
+ }));
1055
+ if (sent) acceptedText.push({
1056
+ id: sent.messageName?.trim() || void 0,
1057
+ text: chunk
1058
+ });
1059
+ if (targetThreadName) deliveryThreadName = sent?.threadName?.trim() || deliveryThreadName;
1060
+ };
1061
+ for (const chunk of chunks) {
1062
+ if (!chunk) continue;
1063
+ if (deliveryTypingMessage) {
1064
+ typingMessage = void 0;
1065
+ try {
1066
+ const updated = await updateGoogleChatMessage({
1067
+ account,
1068
+ messageName: deliveryTypingMessage.name,
1069
+ text: chunk
1070
+ });
1071
+ acceptedText.push({
1072
+ id: updated.messageName?.trim() || deliveryTypingMessage.name,
1073
+ text: chunk
1074
+ });
1075
+ } catch (error) {
1076
+ if (!(error instanceof GoogleChatApiError) || error.status !== 404) throw error;
1077
+ runtime.error?.(`Google Chat typing update failed: ${String(error)}`);
1078
+ await sendTextMessage(chunk);
1079
+ }
1080
+ deliveryTypingMessage = void 0;
1081
+ recordOutboundStatus();
1082
+ continue;
1083
+ }
1084
+ await sendTextMessage(chunk);
1085
+ recordOutboundStatus();
1086
+ }
1087
+ },
1088
+ onDelivered: () => {
1089
+ statusSink?.({ lastOutboundAt: Date.now() });
1090
+ },
1091
+ onError: (err, info) => {
1092
+ runtime.error?.(`[${account.accountId}] Google Chat ${info.kind} reply failed: ${String(err)}`);
1093
+ }
1142
1094
  },
1143
- onError: (err, info) => {
1144
- runtime.error?.(`[${account.accountId}] Google Chat ${info.kind} reply failed: ${String(err)}`);
1145
- }
1146
- },
1147
- replyPipeline: {},
1148
- record: { onRecordError: (err) => {
1149
- runtime.error?.(`googlechat: failed updating session meta: ${String(err)}`);
1150
- } }
1151
- })
1152
- }
1153
- });
1095
+ replyPipeline: {},
1096
+ record: { onRecordError: (err) => {
1097
+ runtime.error?.(`googlechat: failed updating session meta: ${String(err)}`);
1098
+ } }
1099
+ })
1100
+ }
1101
+ });
1102
+ } finally {
1103
+ if (!deferred) await cleanupTypingMessage();
1104
+ }
1154
1105
  }
1155
1106
  async function downloadAttachment(attachment, account, mediaMaxMb, core) {
1156
1107
  const resourceName = attachment.attachmentDataRef?.resourceName;
1157
1108
  if (!resourceName) return null;
1158
- const maxBytes = Math.max(1, mediaMaxMb) * 1024 * 1024;
1109
+ const maxBytes = mediaMaxMb * 1024 * 1024;
1159
1110
  const downloaded = await downloadGoogleChatMedia({
1160
1111
  account,
1161
1112
  resourceName,