@openclaw/imessage 2026.8.1-beta.3 → 2026.8.1

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 (156) hide show
  1. package/dist/{accounts-D00Njxg2.js → accounts-CCirBEIm.js} +4 -5
  2. package/dist/{actions.runtime-B_xJiBXF.js → actions.runtime-CAl3WcqD.js} +2 -3
  3. package/dist/api.js +6 -5
  4. package/dist/{approval-handler.runtime-BKku8aUf.js → approval-handler.runtime-UBd1j2Sg.js} +7 -7
  5. package/dist/{approval-reactions-BME5eA6T.js → approval-reactions-LL5yn1Rc.js} +5 -9
  6. package/dist/{channel-BFQTpvrG.js → channel-DNI9DKGN.js} +17 -16
  7. package/dist/channel-config-api.js +1 -1
  8. package/dist/channel-plugin-api.js +1 -1
  9. package/dist/{channel.runtime-BjkXwX9_.js → channel.runtime-HSkrmWfW.js} +58 -11
  10. package/dist/{config-schema-DV0KP5nC.js → config-schema-DuGbA8Kp.js} +8 -7
  11. package/dist/contract-api.js +1 -1
  12. package/dist/doctor-contract-api.js +8 -281
  13. package/dist/{group-policy-Ca3c5KES.js → group-policy-Dvc-BcWo.js} +12 -17
  14. package/dist/{media-contract-BEgdvYhW.js → media-contract-D-FhGE98.js} +1 -1
  15. package/dist/media-contract-api.js +1 -1
  16. package/dist/{message-tool-api-TZiNYA17.js → message-tool-api-CvIgJpOo.js} +3 -3
  17. package/dist/message-tool-api.js +1 -1
  18. package/dist/{monitor-Uv5RaRTk.js → monitor-BywJn1QW.js} +289 -28
  19. package/dist/{question-reactions-to0i8vxE.js → question-reactions-viP7ZcyG.js} +1 -1
  20. package/dist/{reaction-context-DaNrZqYo.js → reaction-context-BAYI7pz0.js} +2 -2
  21. package/dist/{remote-file-CDuk0joc.js → remote-file-6mCj2ZBy.js} +2 -2
  22. package/dist/runtime-Cza4CY5T.js +8 -0
  23. package/dist/runtime-api.js +10 -9
  24. package/dist/{sanitize-outbound-DaLmdkbf.js → sanitize-outbound-Du-r1lNQ.js} +344 -57
  25. package/dist/{send-Dake4Awx.js → send-mgWPKqSV.js} +132 -11
  26. package/dist/state-contract-4TK_cDDb.js +56 -0
  27. package/dist/state-migrations-SFdKp3GQ.js +277 -0
  28. package/node_modules/typebox/build/format/date.d.mts +1 -1
  29. package/node_modules/typebox/build/format/date.mjs +1 -1
  30. package/node_modules/typebox/build/format/date_time.d.mts +2 -2
  31. package/node_modules/typebox/build/format/date_time.mjs +3 -3
  32. package/node_modules/typebox/build/format/email.d.mts +1 -1
  33. package/node_modules/typebox/build/format/email.mjs +2 -2
  34. package/node_modules/typebox/build/format/hostname.mjs +2 -10
  35. package/node_modules/typebox/build/format/idn_email.d.mts +1 -1
  36. package/node_modules/typebox/build/format/idn_email.mjs +3 -3
  37. package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -0
  38. package/node_modules/typebox/build/format/idn_hostname.mjs +3 -11
  39. package/node_modules/typebox/build/format/idna/format/bidi.d.mts +3 -0
  40. package/node_modules/typebox/build/format/idna/format/bidi.mjs +98 -0
  41. package/node_modules/typebox/build/format/idna/format/puny.d.mts +3 -0
  42. package/node_modules/typebox/build/format/idna/format/puny.mjs +144 -0
  43. package/node_modules/typebox/build/format/idna/hostname.d.mts +1 -0
  44. package/node_modules/typebox/build/format/idna/hostname.mjs +16 -0
  45. package/node_modules/typebox/build/format/idna/idn-hostname.d.mts +1 -0
  46. package/node_modules/typebox/build/format/idna/idn-hostname.mjs +23 -0
  47. package/node_modules/typebox/build/format/idna/index.d.mts +2 -0
  48. package/node_modules/typebox/build/format/idna/index.mjs +2 -0
  49. package/node_modules/typebox/build/format/idna/label/ascii.d.mts +1 -0
  50. package/node_modules/typebox/build/format/idna/label/ascii.mjs +9 -0
  51. package/node_modules/typebox/build/format/idna/label/puny.d.mts +1 -0
  52. package/node_modules/typebox/build/format/idna/label/puny.mjs +28 -0
  53. package/node_modules/typebox/build/format/idna/label/unicode.d.mts +1 -0
  54. package/node_modules/typebox/build/format/idna/label/unicode.mjs +106 -0
  55. package/node_modules/typebox/build/format/idna/pattern/pattern.d.mts +30 -0
  56. package/node_modules/typebox/build/format/idna/pattern/pattern.mjs +70 -0
  57. package/node_modules/typebox/build/format/ipv4.d.mts +0 -1
  58. package/node_modules/typebox/build/format/ipv4.mjs +2 -32
  59. package/node_modules/typebox/build/format/ipv6.mjs +2 -61
  60. package/node_modules/typebox/build/format/iri.d.mts +2 -2
  61. package/node_modules/typebox/build/format/iri.mjs +26 -8
  62. package/node_modules/typebox/build/format/iri_reference.d.mts +2 -2
  63. package/node_modules/typebox/build/format/iri_reference.mjs +9 -55
  64. package/node_modules/typebox/build/format/regex.d.mts +1 -2
  65. package/node_modules/typebox/build/format/regex.mjs +2 -6
  66. package/node_modules/typebox/build/format/time.d.mts +2 -2
  67. package/node_modules/typebox/build/format/time.mjs +19 -14
  68. package/node_modules/typebox/build/format/uri.d.mts +1 -1
  69. package/node_modules/typebox/build/format/uri.mjs +3 -130
  70. package/node_modules/typebox/build/format/uri_reference.d.mts +1 -1
  71. package/node_modules/typebox/build/format/uri_reference.mjs +2 -3
  72. package/node_modules/typebox/build/format/uri_template.d.mts +2 -3
  73. package/node_modules/typebox/build/format/uri_template.mjs +4 -5
  74. package/node_modules/typebox/build/format/url.d.mts +3 -3
  75. package/node_modules/typebox/build/format/url.mjs +4 -5
  76. package/node_modules/typebox/build/guard/emit.d.mts +3 -1
  77. package/node_modules/typebox/build/guard/emit.mjs +12 -5
  78. package/node_modules/typebox/build/guard/guard.d.mts +8 -2
  79. package/node_modules/typebox/build/guard/guard.mjs +25 -4
  80. package/node_modules/typebox/build/guard/string.d.mts +2 -2
  81. package/node_modules/typebox/build/guard/string.mjs +7 -7
  82. package/node_modules/typebox/build/schema/engine/_context.mjs +3 -3
  83. package/node_modules/typebox/build/schema/engine/_functions.mjs +1 -2
  84. package/node_modules/typebox/build/schema/engine/_regexp.d.mts +2 -0
  85. package/node_modules/typebox/build/schema/engine/_regexp.mjs +4 -0
  86. package/node_modules/typebox/build/schema/engine/_stack.mjs +12 -13
  87. package/node_modules/typebox/build/schema/engine/additionalItems.mjs +17 -7
  88. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +4 -3
  89. package/node_modules/typebox/build/schema/engine/contains.mjs +18 -6
  90. package/node_modules/typebox/build/schema/engine/enum.mjs +1 -1
  91. package/node_modules/typebox/build/schema/engine/items.mjs +26 -6
  92. package/node_modules/typebox/build/schema/engine/maxContains.mjs +3 -3
  93. package/node_modules/typebox/build/schema/engine/minContains.mjs +14 -4
  94. package/node_modules/typebox/build/schema/engine/not.mjs +4 -2
  95. package/node_modules/typebox/build/schema/engine/oneOf.mjs +7 -6
  96. package/node_modules/typebox/build/schema/engine/pattern.mjs +3 -2
  97. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +4 -3
  98. package/node_modules/typebox/build/schema/engine/ref.mjs +1 -7
  99. package/node_modules/typebox/build/schema/engine/schema.mjs +13 -4
  100. package/node_modules/typebox/build/schema/engine/type.mjs +1 -1
  101. package/node_modules/typebox/build/schema/resolve/resolve.d.mts +4 -1
  102. package/node_modules/typebox/build/schema/resolve/resolve.mjs +202 -1
  103. package/node_modules/typebox/build/schema/static/propertyNames.d.mts +5 -0
  104. package/node_modules/typebox/build/schema/static/propertyNames.mjs +3 -0
  105. package/node_modules/typebox/build/schema/static/schema.d.mts +3 -0
  106. package/node_modules/typebox/build/schema/types/index.d.mts +0 -2
  107. package/node_modules/typebox/build/schema/types/index.mjs +0 -2
  108. package/node_modules/typebox/build/system/memory/clone.mjs +14 -11
  109. package/node_modules/typebox/build/system/memory/discard.mjs +6 -5
  110. package/node_modules/typebox/build/system/settings/settings.d.mts +9 -0
  111. package/node_modules/typebox/build/system/settings/settings.mjs +2 -0
  112. package/node_modules/typebox/build/type/engine/call/distribute_arguments.d.mts +6 -1
  113. package/node_modules/typebox/build/type/engine/call/distribute_arguments.mjs +16 -3
  114. package/node_modules/typebox/build/type/engine/call/instantiate.mjs +34 -4
  115. package/node_modules/typebox/build/type/engine/evaluate/broaden.d.mts +5 -5
  116. package/node_modules/typebox/build/type/engine/evaluate/broaden.mjs +20 -26
  117. package/node_modules/typebox/build/type/engine/evaluate/compare.d.mts +6 -10
  118. package/node_modules/typebox/build/type/engine/evaluate/compare.mjs +9 -13
  119. package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +7 -4
  120. package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +12 -19
  121. package/node_modules/typebox/build/type/engine/evaluate/distribute.d.mts +4 -20
  122. package/node_modules/typebox/build/type/engine/evaluate/distribute.mjs +8 -20
  123. package/node_modules/typebox/build/type/engine/evaluate/evaluate.d.mts +4 -4
  124. package/node_modules/typebox/build/type/engine/evaluate/evaluate.mjs +11 -8
  125. package/node_modules/typebox/build/type/engine/evaluate/flatten.d.mts +1 -1
  126. package/node_modules/typebox/build/type/engine/evaluate/flatten.mjs +3 -4
  127. package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +17 -2
  128. package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +26 -6
  129. package/node_modules/typebox/build/type/engine/exclude/operation.mjs +3 -4
  130. package/node_modules/typebox/build/type/engine/extract/operation.d.mts +1 -1
  131. package/node_modules/typebox/build/type/engine/extract/operation.mjs +3 -4
  132. package/node_modules/typebox/build/type/engine/priority/priority.d.mts +2 -2
  133. package/node_modules/typebox/build/type/engine/priority/priority.mjs +3 -4
  134. package/node_modules/typebox/build/type/script/mapping.d.mts +32 -29
  135. package/node_modules/typebox/build/type/script/mapping.mjs +18 -25
  136. package/node_modules/typebox/build/type/script/parser.d.mts +19 -25
  137. package/node_modules/typebox/build/type/script/parser.mjs +27 -23
  138. package/node_modules/typebox/build/value/errors/errors.d.mts +2 -2
  139. package/node_modules/typebox/build/value/errors/errors.mjs +1 -1
  140. package/node_modules/typebox/package.json +27 -27
  141. package/node_modules/typebox/readme.md +79 -82
  142. package/openclaw.plugin.json +0 -6
  143. package/package.json +5 -5
  144. package/dist/catchup-Dh-Rv4Ur.js +0 -294
  145. package/dist/monitor-reply-cache-BdeUQaHO.js +0 -353
  146. package/dist/persisted-echo-cache-DGxy-J4t.js +0 -143
  147. package/node_modules/typebox/build/format/_idna.d.mts +0 -2
  148. package/node_modules/typebox/build/format/_idna.mjs +0 -246
  149. package/node_modules/typebox/build/format/_puny.d.mts +0 -1
  150. package/node_modules/typebox/build/format/_puny.mjs +0 -77
  151. package/node_modules/typebox/build/schema/resolve/ref.d.mts +0 -3
  152. package/node_modules/typebox/build/schema/resolve/ref.mjs +0 -146
  153. package/node_modules/typebox/build/schema/types/contentEncoding.d.mts +0 -9
  154. package/node_modules/typebox/build/schema/types/contentEncoding.mjs +0 -13
  155. package/node_modules/typebox/build/schema/types/contentMediaType.d.mts +0 -9
  156. package/node_modules/typebox/build/schema/types/contentMediaType.mjs +0 -13
@@ -1,353 +0,0 @@
1
- import { normalizeE164 } from "openclaw/plugin-sdk/account-resolution";
2
- import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
3
- import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
4
- import { createHash } from "node:crypto";
5
- import { createPluginRuntimeStore } from "openclaw/plugin-sdk/runtime-store";
6
- //#region extensions/imessage/src/chat-context.ts
7
- const EMAIL_HANDLE_PATTERN = /^[^\s@]+@[^\s@]+$/u;
8
- function parseDirectChatIdentity(raw) {
9
- const trimmed = raw.trim();
10
- const parts = trimmed.split(";");
11
- if (parts.length === 3 && parts[1] === "-" && parts[2]) {
12
- const service = parts[0]?.toLowerCase();
13
- if (service === "imessage" || service === "sms" || service === "any") {
14
- const identifier = parts[2];
15
- return {
16
- service,
17
- identifier: EMAIL_HANDLE_PATTERN.test(identifier) ? identifier.toLowerCase() : identifier
18
- };
19
- }
20
- }
21
- if (parts.length !== 1) return;
22
- if (trimmed.startsWith("+") || EMAIL_HANDLE_PATTERN.test(trimmed)) return { identifier: trimmed.toLowerCase() };
23
- }
24
- function resolveIMessageDirectChatService(configuredService, chatGuid) {
25
- if (configuredService === "imessage" || configuredService === "sms") return configuredService;
26
- const observedService = chatGuid ? parseDirectChatIdentity(chatGuid)?.service : void 0;
27
- return observedService === "imessage" || observedService === "sms" ? observedService : void 0;
28
- }
29
- function isIMessageEmailChatIdentifier(raw) {
30
- const identity = parseDirectChatIdentity(raw);
31
- return Boolean(identity && EMAIL_HANDLE_PATTERN.test(identity.identifier));
32
- }
33
- /**
34
- * Strip the `iMessage;-;` / `SMS;-;` / `any;-;` service prefix that Messages
35
- * uses for direct chats. Different layers report direct DMs in different
36
- * forms, so raw comparison would falsely treat one DM as different chats.
37
- */
38
- function normalizeDirectChatIdentifier(raw) {
39
- const trimmed = raw.trim();
40
- return parseDirectChatIdentity(trimmed)?.identifier ?? trimmed;
41
- }
42
- function chatContextFromIMessageTarget(target, effectiveService) {
43
- if (target.kind === "chat_id") return { chatId: target.chatId };
44
- if (target.kind === "chat_guid") return { chatGuid: target.chatGuid };
45
- if (target.kind === "chat_identifier") return { chatIdentifier: target.chatIdentifier };
46
- const trimmedHandle = target.to.trim();
47
- const canonicalHandle = trimmedHandle.startsWith("+") ? normalizeE164(trimmedHandle) : /^[^\s@]+@[^\s@]+$/u.test(trimmedHandle) ? trimmedHandle.toLowerCase() : void 0;
48
- if (!canonicalHandle) return {};
49
- const service = target.service === "auto" ? effectiveService : target.service;
50
- if (service !== "imessage" && service !== "sms") return {};
51
- return { chatIdentifier: `${service === "sms" ? "SMS" : "iMessage"};-;${canonicalHandle}` };
52
- }
53
- function compareOptional(left, right) {
54
- return left === void 0 || right === void 0 ? void 0 : left === right;
55
- }
56
- function compareChatSelector(cachedRaw, currentRaw, crossKind = false) {
57
- const cached = normalizeOptionalString(cachedRaw);
58
- const current = normalizeOptionalString(currentRaw);
59
- if (!cached || !current) return;
60
- if (cached === current) return true;
61
- const cachedDirect = parseDirectChatIdentity(cached);
62
- const currentDirect = parseDirectChatIdentity(current);
63
- if (!cachedDirect || !currentDirect) return crossKind ? void 0 : false;
64
- if (cachedDirect.identifier !== currentDirect.identifier) return false;
65
- if (cachedDirect.service === "any") return true;
66
- if (!cachedDirect.service || !currentDirect.service) return;
67
- return cachedDirect.service === currentDirect.service;
68
- }
69
- function resolveIMessageChatMatch(cached, current) {
70
- const cachedChatGuid = normalizeOptionalString(cached.chatGuid);
71
- const currentChatGuid = normalizeOptionalString(current.chatGuid);
72
- const cachedChatIdentifier = normalizeOptionalString(cached.chatIdentifier);
73
- const currentChatIdentifier = normalizeOptionalString(current.chatIdentifier);
74
- const comparisons = [
75
- compareChatSelector(cachedChatGuid, currentChatGuid),
76
- compareChatSelector(cachedChatIdentifier, currentChatIdentifier),
77
- compareOptional(cached.chatId, current.chatId),
78
- compareChatSelector(cachedChatGuid, currentChatIdentifier, true),
79
- compareChatSelector(cachedChatIdentifier, currentChatGuid, true)
80
- ].filter((comparison) => comparison !== void 0);
81
- if (comparisons.length === 0) return "unknown";
82
- return comparisons.every(Boolean) ? "match" : "mismatch";
83
- }
84
- function isPositiveIMessageChatMatch(cached, current) {
85
- return resolveIMessageChatMatch(cached, current) === "match";
86
- }
87
- //#endregion
88
- //#region extensions/imessage/src/runtime.ts
89
- const { getRuntime: getIMessageRuntime, setRuntime: setIMessageRuntime, tryGetRuntime: getOptionalIMessageRuntime } = createPluginRuntimeStore({
90
- pluginId: "imessage",
91
- errorMessage: "iMessage runtime not initialized"
92
- });
93
- //#endregion
94
- //#region extensions/imessage/src/monitor-reply-cache.ts
95
- const IMESSAGE_REPLY_CACHE_NAMESPACE = "imessage.reply-cache";
96
- const IMESSAGE_REPLY_CACHE_MAX_ENTRIES = 2e3;
97
- const IMESSAGE_REPLY_CACHE_COUNTER_NAMESPACE = "imessage.reply-cache-counter";
98
- const IMESSAGE_REPLY_CACHE_COUNTER_KEY = "short-id-counter";
99
- const REPLY_CACHE_TTL_MS = 360 * 60 * 1e3;
100
- /** Recency window for the "react to the latest message" fallback. */
101
- const LATEST_FALLBACK_MS = 600 * 1e3;
102
- let persistenceFailureLogged = false;
103
- function reportPersistenceFailure(scope, err) {
104
- if (persistenceFailureLogged) return;
105
- persistenceFailureLogged = true;
106
- logVerbose(`imessage reply-cache: ${scope} disabled after first failure: ${String(err)}`);
107
- }
108
- const imessageReplyCacheByMessageId = /* @__PURE__ */ new Map();
109
- const imessageShortIdToUuid = /* @__PURE__ */ new Map();
110
- const imessageUuidToShortId = /* @__PURE__ */ new Map();
111
- let imessageShortIdCounter = 0;
112
- function resolveIMessageReplyCacheEntryKey(messageId) {
113
- return createHash("sha256").update(messageId, "utf8").digest("hex").slice(0, 32);
114
- }
115
- function openReplyCacheStore() {
116
- return getIMessageRuntime().state.openSyncKeyedStore({
117
- namespace: IMESSAGE_REPLY_CACHE_NAMESPACE,
118
- maxEntries: IMESSAGE_REPLY_CACHE_MAX_ENTRIES
119
- });
120
- }
121
- function openReplyCacheCounterStore() {
122
- return getIMessageRuntime().state.openSyncKeyedStore({
123
- namespace: IMESSAGE_REPLY_CACHE_COUNTER_NAMESPACE,
124
- maxEntries: 1
125
- });
126
- }
127
- function remainingTtlMs(timestamp) {
128
- const remaining = REPLY_CACHE_TTL_MS - Math.max(0, Date.now() - timestamp);
129
- return remaining > 0 ? remaining : void 0;
130
- }
131
- let hydrated = false;
132
- function hydrateFromStoreOnce() {
133
- if (hydrated) return;
134
- hydrated = true;
135
- const cutoff = Date.now() - REPLY_CACHE_TTL_MS;
136
- let entries;
137
- try {
138
- const counter = openReplyCacheCounterStore().lookup(IMESSAGE_REPLY_CACHE_COUNTER_KEY);
139
- if (counter && Number.isSafeInteger(counter.counter) && counter.counter > 0) imessageShortIdCounter = Math.max(imessageShortIdCounter, counter.counter);
140
- entries = openReplyCacheStore().entries().map(({ value }) => value).filter((entry) => entry.timestamp >= cutoff).toSorted((a, b) => a.timestamp - b.timestamp).slice(-2e3);
141
- for (const entry of entries) {
142
- const numeric = Number.parseInt(entry.shortId, 10);
143
- if (Number.isFinite(numeric) && numeric > imessageShortIdCounter) imessageShortIdCounter = numeric;
144
- }
145
- } catch (err) {
146
- reportPersistenceFailure("read", err);
147
- return;
148
- }
149
- if (entries.length === 0) return;
150
- for (const entry of entries) {
151
- imessageReplyCacheByMessageId.set(entry.messageId, entry);
152
- imessageShortIdToUuid.set(entry.shortId, entry.messageId);
153
- imessageUuidToShortId.set(entry.messageId, entry.shortId);
154
- }
155
- }
156
- function persistReplyCacheEntry(entry) {
157
- const ttlMs = remainingTtlMs(entry.timestamp);
158
- if (!ttlMs) return;
159
- try {
160
- openReplyCacheStore().register(resolveIMessageReplyCacheEntryKey(entry.messageId), entry, { ttlMs });
161
- } catch (err) {
162
- reportPersistenceFailure("write", err);
163
- }
164
- }
165
- function deleteReplyCacheEntry(messageId) {
166
- try {
167
- openReplyCacheStore().delete(resolveIMessageReplyCacheEntryKey(messageId));
168
- } catch (err) {
169
- reportPersistenceFailure("delete", err);
170
- }
171
- }
172
- function persistReplyCacheCounter() {
173
- try {
174
- openReplyCacheCounterStore().register(IMESSAGE_REPLY_CACHE_COUNTER_KEY, { counter: imessageShortIdCounter });
175
- } catch (err) {
176
- reportPersistenceFailure("counter", err);
177
- }
178
- }
179
- function buildReplyCacheEntry(entry, messageId, shortId) {
180
- return {
181
- accountId: entry.accountId,
182
- messageId,
183
- shortId,
184
- timestamp: entry.timestamp,
185
- ...typeof entry.chatGuid === "string" ? { chatGuid: entry.chatGuid } : {},
186
- ...typeof entry.chatIdentifier === "string" ? { chatIdentifier: entry.chatIdentifier } : {},
187
- ...typeof entry.chatId === "number" ? { chatId: entry.chatId } : {},
188
- ...typeof entry.isFromMe === "boolean" ? { isFromMe: entry.isFromMe } : {}
189
- };
190
- }
191
- function generateShortId() {
192
- imessageShortIdCounter += 1;
193
- persistReplyCacheCounter();
194
- return String(imessageShortIdCounter);
195
- }
196
- function rememberIMessageReplyCache(entry) {
197
- hydrateFromStoreOnce();
198
- const messageId = entry.messageId.trim();
199
- if (!messageId) return {
200
- ...entry,
201
- shortId: ""
202
- };
203
- let shortId = imessageUuidToShortId.get(messageId);
204
- if (!shortId) {
205
- shortId = generateShortId();
206
- imessageShortIdToUuid.set(shortId, messageId);
207
- imessageUuidToShortId.set(messageId, shortId);
208
- }
209
- const fullEntry = buildReplyCacheEntry(entry, messageId, shortId);
210
- imessageReplyCacheByMessageId.delete(messageId);
211
- imessageReplyCacheByMessageId.set(messageId, fullEntry);
212
- const cutoff = Date.now() - REPLY_CACHE_TTL_MS;
213
- let evicted = false;
214
- const deletedMessageIds = [];
215
- for (const [key, value] of imessageReplyCacheByMessageId) {
216
- if (value.timestamp >= cutoff) break;
217
- imessageReplyCacheByMessageId.delete(key);
218
- deletedMessageIds.push(key);
219
- if (value.shortId) {
220
- imessageShortIdToUuid.delete(value.shortId);
221
- imessageUuidToShortId.delete(key);
222
- }
223
- evicted = true;
224
- }
225
- while (imessageReplyCacheByMessageId.size > IMESSAGE_REPLY_CACHE_MAX_ENTRIES) {
226
- const oldest = imessageReplyCacheByMessageId.keys().next().value;
227
- if (!oldest) break;
228
- const oldEntry = imessageReplyCacheByMessageId.get(oldest);
229
- imessageReplyCacheByMessageId.delete(oldest);
230
- deletedMessageIds.push(oldest);
231
- if (oldEntry?.shortId) {
232
- imessageShortIdToUuid.delete(oldEntry.shortId);
233
- imessageUuidToShortId.delete(oldest);
234
- }
235
- evicted = true;
236
- }
237
- if (evicted) for (const messageIdToDelete of deletedMessageIds) deleteReplyCacheEntry(messageIdToDelete);
238
- persistReplyCacheEntry(fullEntry);
239
- return fullEntry;
240
- }
241
- function hasChatScope(ctx) {
242
- if (!ctx) return false;
243
- return Boolean(normalizeOptionalString(ctx.chatGuid) || normalizeOptionalString(ctx.chatIdentifier) || typeof ctx.chatId === "number");
244
- }
245
- function isCrossChatMismatch(cached, ctx) {
246
- return resolveIMessageChatMatch(cached, ctx) === "mismatch";
247
- }
248
- function describeChatForError(values) {
249
- const parts = [];
250
- if (normalizeOptionalString(values.chatGuid)) parts.push("chatGuid=<redacted>");
251
- if (normalizeOptionalString(values.chatIdentifier)) parts.push("chatIdentifier=<redacted>");
252
- if (typeof values.chatId === "number") parts.push("chatId=<redacted>");
253
- return parts.length === 0 ? "<unknown chat>" : parts.join(", ");
254
- }
255
- function describeMessageIdForError(inputId, inputKind) {
256
- if (inputKind === "short") return `<short:${inputId.length}-digit>`;
257
- return `<uuid:${inputId.slice(0, 8)}...>`;
258
- }
259
- function buildCrossChatError(inputId, inputKind, cached, ctx) {
260
- const remediation = inputKind === "short" ? "Use a message ID from the current chat target; MessageSidFull from another chat is rejected." : "Retry with the correct chat target.";
261
- return /* @__PURE__ */ new Error(`iMessage message id ${describeMessageIdForError(inputId, inputKind)} belongs to a different chat (${describeChatForError(cached)}) than the current call target (${describeChatForError(ctx)}). ${remediation}`);
262
- }
263
- function resolveIMessageMessageId(shortOrUuid, opts) {
264
- const trimmed = shortOrUuid.trim();
265
- if (!trimmed) return trimmed;
266
- hydrateFromStoreOnce();
267
- if (/^\d+$/.test(trimmed)) {
268
- const uuid = imessageShortIdToUuid.get(trimmed);
269
- if (uuid) {
270
- const cached = imessageReplyCacheByMessageId.get(uuid);
271
- if (opts?.chatContext && hasChatScope(opts.chatContext)) {
272
- if (cached && isCrossChatMismatch(cached, opts.chatContext)) throw buildCrossChatError(trimmed, "short", cached, opts.chatContext);
273
- }
274
- if (opts?.requireFromMe && cached?.isFromMe !== true) throw buildFromMeError(trimmed, "short");
275
- return uuid;
276
- }
277
- if (opts?.requireKnownShortId && !hasChatScope(opts.chatContext)) throw new Error(`iMessage short message id ${describeMessageIdForError(trimmed, "short")} requires a chat scope (chatGuid / chatIdentifier / chatId or a target).`);
278
- if (opts?.requireKnownShortId) throw new Error(`iMessage short message id ${describeMessageIdForError(trimmed, "short")} is no longer available. Use MessageSidFull.`);
279
- return trimmed;
280
- }
281
- const cached = imessageReplyCacheByMessageId.get(trimmed);
282
- if (opts?.chatContext) {
283
- if (cached && isCrossChatMismatch(cached, opts.chatContext)) throw buildCrossChatError(trimmed, "uuid", cached, opts.chatContext);
284
- }
285
- if (opts?.requireFromMe && cached?.isFromMe !== true) throw buildFromMeError(trimmed, "uuid");
286
- return trimmed;
287
- }
288
- function isKnownFromMeIMessageMessageId(messageId, ctx) {
289
- const trimmed = normalizeOptionalString(messageId);
290
- if (!trimmed || !ctx.accountId || !hasChatScope(ctx)) return false;
291
- hydrateFromStoreOnce();
292
- const cached = imessageReplyCacheByMessageId.get(trimmed);
293
- if (!cached || cached.isFromMe !== true || cached.accountId !== ctx.accountId) return false;
294
- return isPositiveIMessageChatMatch(cached, ctx);
295
- }
296
- function buildFromMeError(inputId, inputKind) {
297
- return /* @__PURE__ */ new Error(`iMessage message id ${describeMessageIdForError(inputId, inputKind)} is not one this agent sent. edit and unsend can only target messages the gateway delivered itself; messages received from other participants cannot be modified.`);
298
- }
299
- /**
300
- * Return the most recent cached entry whose chat scope matches the supplied
301
- * context. Used as a fallback when an agent calls a per-message action (e.g.
302
- * `react`) without specifying a `messageId` — the natural intent is "react
303
- * to the message I just received in this chat."
304
- *
305
- * Strict semantics for safety:
306
- * - Caller must supply a chat scope. We refuse to "guess" the active chat.
307
- * - Cached entry must positively match on at least one identifier kind
308
- * (chatGuid, chatIdentifier, chatId, or normalized direct-DM fingerprint).
309
- * We do NOT fall through on "no overlapping identifier" — that's how a
310
- * cached entry from a foreign chat could be returned when the caller's
311
- * context didn't share any identifier kind with the cache.
312
- * - Caller must supply an accountId; we never cross account boundaries.
313
- * - We only consider entries newer than `LATEST_FALLBACK_MS`. The intent
314
- * of "react to the latest" is "the message I just received," not
315
- * "anything in this chat from any time."
316
- */
317
- function findLatestIMessageEntryForChat(ctx) {
318
- if (!hasChatScope(ctx)) return;
319
- if (!ctx.accountId) return;
320
- const cutoff = Date.now() - LATEST_FALLBACK_MS;
321
- let best;
322
- for (const entry of imessageReplyCacheByMessageId.values()) {
323
- if (entry.accountId !== ctx.accountId) continue;
324
- if (entry.timestamp < cutoff) continue;
325
- if (!isPositiveIMessageChatMatch(entry, ctx)) continue;
326
- if (!best || entry.timestamp > best.timestamp) best = entry;
327
- }
328
- return best;
329
- }
330
- function resolveIMessageCachedResourceBinding(messageId, ctx) {
331
- hydrateFromStoreOnce();
332
- const entry = imessageReplyCacheByMessageId.get(messageId.trim());
333
- if (!entry) return "unknown";
334
- if (Date.now() - entry.timestamp > REPLY_CACHE_TTL_MS) return "unknown";
335
- if (entry.accountId !== ctx.accountId) return "mismatch";
336
- const chatMatch = resolveIMessageChatMatch(entry, ctx);
337
- if (chatMatch !== "match") return chatMatch;
338
- return "match";
339
- }
340
- function isIMessageCurrentMessageInChat(params) {
341
- if (!params.accountId || !hasChatScope(params.chatContext)) return false;
342
- const currentMessageId = normalizeOptionalString(String(params.currentMessageId));
343
- if (!currentMessageId) return false;
344
- hydrateFromStoreOnce();
345
- const fullMessageId = /^\d+$/.test(currentMessageId) ? imessageShortIdToUuid.get(currentMessageId) : currentMessageId;
346
- if (!fullMessageId) return false;
347
- return resolveIMessageCachedResourceBinding(fullMessageId, {
348
- ...params.chatContext,
349
- accountId: params.accountId
350
- }) === "match";
351
- }
352
- //#endregion
353
- export { normalizeDirectChatIdentifier as _, findLatestIMessageEntryForChat as a, rememberIMessageReplyCache as c, resolveIMessageReplyCacheEntryKey as d, getIMessageRuntime as f, isIMessageEmailChatIdentifier as g, chatContextFromIMessageTarget as h, IMESSAGE_REPLY_CACHE_NAMESPACE as i, resolveIMessageCachedResourceBinding as l, setIMessageRuntime as m, IMESSAGE_REPLY_CACHE_COUNTER_NAMESPACE as n, isIMessageCurrentMessageInChat as o, getOptionalIMessageRuntime as p, IMESSAGE_REPLY_CACHE_MAX_ENTRIES as r, isKnownFromMeIMessageMessageId as s, IMESSAGE_REPLY_CACHE_COUNTER_KEY as t, resolveIMessageMessageId as u, resolveIMessageDirectChatService as v };
@@ -1,143 +0,0 @@
1
- import { f as getIMessageRuntime } from "./monitor-reply-cache-BdeUQaHO.js";
2
- import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
3
- import { createHash } from "node:crypto";
4
- //#region extensions/imessage/src/monitor/echo-text-corruption.ts
5
- function isLeadingEchoTextCorruptionMarker(code) {
6
- return code === 0 || code === 65279 || code === 65533 || code === 65534 || code === 65535;
7
- }
8
- function stripLeadingEchoTextCorruptionMarkers(text) {
9
- let offset = 0;
10
- while (offset < text.length && isLeadingEchoTextCorruptionMarker(text.charCodeAt(offset))) offset += 1;
11
- return offset === 0 ? text : text.slice(offset);
12
- }
13
- //#endregion
14
- //#region extensions/imessage/src/monitor/persisted-echo-cache.ts
15
- const IMESSAGE_SENT_ECHOES_TTL_MS = 720 * 60 * 1e3;
16
- const IMESSAGE_SENT_ECHOES_NAMESPACE = "imessage.sent-echoes";
17
- function normalizeText(text) {
18
- if (!text) return;
19
- return stripLeadingEchoTextCorruptionMarkers(text.replace(/\r\n?/g, "\n").trim()).trim() || void 0;
20
- }
21
- function normalizeMessageId(messageId) {
22
- const normalized = messageId?.trim();
23
- if (!normalized || normalized === "ok" || normalized === "unknown") return;
24
- return normalized;
25
- }
26
- let mirror = null;
27
- let persistenceFailureLogged = false;
28
- function reportFailure(scope, err) {
29
- if (persistenceFailureLogged) return;
30
- persistenceFailureLogged = true;
31
- logVerbose(`imessage echo-cache: ${scope} disabled after first failure: ${String(err)}`);
32
- }
33
- function resolveIMessageSentEchoEntryKey(entry) {
34
- return createHash("sha256").update(JSON.stringify([
35
- entry.scope,
36
- entry.text ?? "",
37
- resolveIMessageEchoMediaKey(entry.media) ?? "",
38
- entry.messageId ?? "",
39
- entry.timestamp
40
- ])).digest("hex").slice(0, 32);
41
- }
42
- function resolveIMessageEchoMediaKey(media) {
43
- const contentType = media?.contentType?.trim().toLowerCase() || void 0;
44
- const kind = media?.kind && media.kind !== "unknown" ? media.kind : void 0;
45
- if (kind) return `kind:${kind}`;
46
- const normalizedContentType = contentType?.split(";", 1)[0]?.trim();
47
- return normalizedContentType ? `mime:${normalizedContentType}` : void 0;
48
- }
49
- function normalizeMedia(media) {
50
- if (!resolveIMessageEchoMediaKey(media)) return;
51
- const contentType = media?.contentType?.trim().toLowerCase() || void 0;
52
- const kind = media?.kind ?? void 0;
53
- return {
54
- ...kind ? { kind } : {},
55
- ...contentType ? { contentType } : {}
56
- };
57
- }
58
- function openPersistedEchoStore() {
59
- return getIMessageRuntime().state.openSyncKeyedStore({
60
- namespace: IMESSAGE_SENT_ECHOES_NAMESPACE,
61
- maxEntries: 256
62
- });
63
- }
64
- function remainingTtlMs(timestamp) {
65
- const remaining = IMESSAGE_SENT_ECHOES_TTL_MS - Math.max(0, Date.now() - timestamp);
66
- return remaining > 0 ? remaining : void 0;
67
- }
68
- function resolveEntryTtlMs(entry, ttlMs) {
69
- if (typeof ttlMs === "number" && Number.isFinite(ttlMs) && ttlMs > 0) return ttlMs;
70
- return remainingTtlMs(entry.timestamp);
71
- }
72
- function isLiveEntry(entry, now = Date.now()) {
73
- const cutoff = now - IMESSAGE_SENT_ECHOES_TTL_MS;
74
- return entry.timestamp >= cutoff && (entry.expiresAt == null || entry.expiresAt > now);
75
- }
76
- function loadMirrorFromStore() {
77
- try {
78
- mirror = openPersistedEchoStore().entries().map(({ value }) => value).filter((entry) => isLiveEntry(entry)).toSorted((a, b) => a.timestamp - b.timestamp).slice(-256);
79
- } catch (err) {
80
- reportFailure("read", err);
81
- mirror = [];
82
- }
83
- }
84
- function readRecentEntries() {
85
- loadMirrorFromStore();
86
- return mirror ?? [];
87
- }
88
- function persistEntry(entry, ttlMs) {
89
- const effectiveTtlMs = resolveEntryTtlMs(entry, ttlMs);
90
- if (!effectiveTtlMs) return;
91
- const key = resolveIMessageSentEchoEntryKey(entry);
92
- try {
93
- openPersistedEchoStore().register(key, entry, { ttlMs: effectiveTtlMs });
94
- } catch (err) {
95
- reportFailure("write", err);
96
- return;
97
- }
98
- return key;
99
- }
100
- function rememberPersistedIMessageEcho(params) {
101
- const text = normalizeText(params.text);
102
- const media = normalizeMedia(params.media);
103
- const messageId = normalizeMessageId(params.messageId);
104
- const entry = {
105
- scope: params.scope,
106
- timestamp: Date.now(),
107
- ...text ? { text } : {},
108
- ...media ? { media } : {},
109
- ...messageId ? { messageId } : {},
110
- ...params.pending ? { pending: true } : {}
111
- };
112
- if (typeof params.ttlMs === "number" && Number.isFinite(params.ttlMs) && params.ttlMs > 0) entry.expiresAt = entry.timestamp + params.ttlMs;
113
- if (!entry.text && !entry.media && !entry.messageId) return;
114
- loadMirrorFromStore();
115
- const key = persistEntry(entry, params.ttlMs);
116
- mirror = [...mirror ?? [], entry].filter((candidate) => isLiveEntry(candidate)).slice(-256);
117
- return key;
118
- }
119
- function forgetPersistedIMessageEchoKey(key) {
120
- if (!key) return;
121
- try {
122
- openPersistedEchoStore().delete(key);
123
- } catch (err) {
124
- reportFailure("delete", err);
125
- }
126
- mirror = (mirror ?? []).filter((entry) => resolveIMessageSentEchoEntryKey(entry) !== key);
127
- }
128
- function hasPersistedIMessageEcho(params) {
129
- const text = normalizeText(params.text);
130
- const mediaKey = resolveIMessageEchoMediaKey(params.media);
131
- const messageId = normalizeMessageId(params.messageId);
132
- if (!text && !mediaKey && !messageId) return false;
133
- for (const entry of readRecentEntries()) {
134
- if (entry.scope !== params.scope) continue;
135
- if (messageId && entry.messageId === messageId) return true;
136
- const hasConflictingMessageIds = Boolean(messageId && entry.messageId && messageId !== entry.messageId);
137
- if (text && (!hasConflictingMessageIds || params.skipIdShortCircuit) && entry.text === text && (!entry.pending || params.includePendingText)) return true;
138
- if (mediaKey && !hasConflictingMessageIds && resolveIMessageEchoMediaKey(entry.media) === mediaKey && (!entry.pending || params.includePendingText)) return true;
139
- }
140
- return false;
141
- }
142
- //#endregion
143
- export { rememberPersistedIMessageEcho as a, stripLeadingEchoTextCorruptionMarkers as c, hasPersistedIMessageEcho as i, IMESSAGE_SENT_ECHOES_TTL_MS as n, resolveIMessageEchoMediaKey as o, forgetPersistedIMessageEchoKey as r, resolveIMessageSentEchoEntryKey as s, IMESSAGE_SENT_ECHOES_NAMESPACE as t };
@@ -1,2 +0,0 @@
1
- export declare function IsIdnLabel(value: string): boolean;
2
- export declare function IsLabel(value: string): boolean;