






















@@ -1,7 +1,4 @@
11import { createHash } from "node:crypto";
2-import os from "node:os";
3-import path from "node:path";
4-import { loadJsonFile } from "openclaw/plugin-sdk/json-store";
52import type { PluginStateSyncKeyedStore } from "openclaw/plugin-sdk/plugin-state-runtime";
63import {
74releaseFeishuMessageProcessing,
@@ -20,11 +17,8 @@ type FeishuDedupStoreEntry = {
2017};
21182219const memory = new Map<string, number>();
23-const importedLegacyNamespaces = new Set<string>();
2420const cachedDedupStores = new Map<string, PluginStateSyncKeyedStore<FeishuDedupStoreEntry>>();
252126-type LegacyDedupeData = Record<string, number>;
27-2822function normalizeMessageId(messageId: string | undefined | null): string | null {
2923const trimmed = messageId?.trim();
3024return trimmed ? trimmed : null;
@@ -34,22 +28,6 @@ function normalizeNamespace(namespace?: string): string {
3428return namespace?.trim() || "global";
3529}
363037-function resolveLegacyStateDir(env: NodeJS.ProcessEnv = process.env): string {
38-const stateOverride = env.OPENCLAW_STATE_DIR?.trim();
39-if (stateOverride) {
40-return stateOverride;
41-}
42-if (env.VITEST || env.NODE_ENV === "test") {
43-return path.join(os.tmpdir(), ["openclaw-vitest", String(process.pid)].join("-"));
44-}
45-return path.join(os.homedir(), ".openclaw");
46-}
47-48-function resolveLegacyNamespaceFilePath(namespace: string): string {
49-const safe = namespace.replace(/[^a-zA-Z0-9_-]/g, "_");
50-return path.join(resolveLegacyStateDir(), "feishu", "dedup", `${safe}.json`);
51-}
52-5331function pluginStateNamespace(namespace: string): string {
5432return `dedup.${namespace.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
5533}
@@ -116,52 +94,6 @@ function hasMemory(namespace: string, messageId: string, now = Date.now()): bool
11694return false;
11795}
11896119-function sanitizeLegacyDedupeData(value: unknown): LegacyDedupeData {
120-if (!value || typeof value !== "object" || Array.isArray(value)) {
121-return {};
122-}
123-const out: LegacyDedupeData = {};
124-for (const [key, seenAt] of Object.entries(value as Record<string, unknown>)) {
125-if (typeof seenAt === "number" && Number.isFinite(seenAt) && seenAt > 0) {
126-out[key] = seenAt;
127-}
128-}
129-return out;
130-}
131-132-function importLegacyDedupNamespace(
133-namespace: string,
134-now = Date.now(),
135-log?: (...args: unknown[]) => void,
136-): void {
137-if (importedLegacyNamespaces.has(namespace)) {
138-return;
139-}
140-141-try {
142-const data = sanitizeLegacyDedupeData(loadJsonFile(resolveLegacyNamespaceFilePath(namespace)));
143-const store = openDedupStore(namespace);
144-for (const [messageId, seenAt] of Object.entries(data)) {
145-if (!isRecent(seenAt, now)) {
146-continue;
147-}
148-const key = dedupeStoreKey(namespace, messageId);
149-if (store.lookup(key) != null) {
150-continue;
151-}
152-store.register(
153-key,
154-{ namespace, messageId, seenAt },
155-{ ttlMs: Math.max(1, DEDUP_TTL_MS - (now - seenAt)) },
156-);
157-}
158-importedLegacyNamespaces.add(namespace);
159-} catch (error) {
160-importedLegacyNamespaces.delete(namespace);
161-log?.(`feishu-dedup: legacy state import failed: ${String(error)}`);
162-}
163-}
164-16597export { releaseFeishuMessageProcessing, tryBeginFeishuMessageProcessing };
1669816799export async function claimUnprocessedFeishuMessage(params: {
@@ -259,7 +191,6 @@ export async function tryRecordMessagePersistent(
259191return true;
260192}
261193const now = Date.now();
262-importLegacyDedupNamespace(normalizedNamespace, now, log);
263194if (hasMemory(normalizedNamespace, normalizedMessageId, now)) {
264195return false;
265196}
@@ -318,7 +249,6 @@ async function hasRecordedMessagePersistent(
318249return false;
319250}
320251const now = Date.now();
321-importLegacyDedupNamespace(normalizedNamespace, now, log);
322252if (hasMemory(normalizedNamespace, normalizedMessageId, now)) {
323253return true;
324254}
@@ -337,15 +267,14 @@ async function hasRecordedMessagePersistent(
337267}
338268}
339269340-export async function warmupDedupFromDisk(
270+export async function warmupDedupFromPluginState(
341271namespace: string,
342272log?: (...args: unknown[]) => void,
343273): Promise<number> {
344274const normalizedNamespace = normalizeNamespace(namespace);
345275try {
346276let loaded = 0;
347277const now = Date.now();
348-importLegacyDedupNamespace(normalizedNamespace, now, log);
349278for (const entry of openDedupStore(normalizedNamespace).entries()) {
350279if (entry.value.namespace !== normalizedNamespace || !isRecent(entry.value.seenAt, now)) {
351280continue;
@@ -363,7 +292,6 @@ export async function warmupDedupFromDisk(
363292export const testingHooks = {
364293resetFeishuDedupForTests() {
365294memory.clear();
366-importedLegacyNamespaces.clear();
367295for (const store of cachedDedupStores.values()) {
368296store.clear();
369297}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。