fix(discord): clean migrated thread binding state (#89552)

* fix(discord): clean migrated thread binding state

* fix(discord): omit undefined thread binding fields

---------

Co-authored-by: Hex <hex@openclaw.ai>
This commit is contained in:
Syu
2026-06-11 20:09:39 +09:00
committed by GitHub
parent 4b4211e6c7
commit 038da08073
3 changed files with 25 additions and 9 deletions

View File

@@ -193,7 +193,7 @@ describe("Discord model picker preference migration", () => {
expect(plan.pluginId).toBe("discord");
expect(plan.namespace).toBe("thread-bindings");
const entries = await plan.readEntries();
expect(entries).toEqual([
expect(entries).toStrictEqual([
{
key: "default:legacy-thread",
value: {

View File

@@ -195,7 +195,10 @@ export const detectDiscordLegacyStateMigrations: BundledChannelLegacyStateMigrat
)) {
const normalized = normalizePersistedBinding(rawKey, rawEntry);
if (normalized) {
out.push({ key: toBindingRecordKey(normalized), value: normalized });
out.push({
key: toBindingRecordKey(normalized),
value: normalized,
});
}
}
return out;

View File

@@ -215,23 +215,36 @@ export function normalizePersistedBinding(
}
}
return {
const record: ThreadBindingRecord = {
accountId,
channelId,
threadId,
targetKind,
targetSessionKey,
agentId,
label,
webhookId,
webhookToken,
boundBy,
boundAt,
lastActivityAt,
idleTimeoutMs: migratedIdleTimeoutMs,
maxAgeMs: migratedMaxAgeMs,
metadata,
};
if (label !== undefined) {
record.label = label;
}
if (webhookId !== undefined) {
record.webhookId = webhookId;
}
if (webhookToken !== undefined) {
record.webhookToken = webhookToken;
}
if (migratedIdleTimeoutMs !== undefined) {
record.idleTimeoutMs = migratedIdleTimeoutMs;
}
if (migratedMaxAgeMs !== undefined) {
record.maxAgeMs = migratedMaxAgeMs;
}
if (metadata !== undefined) {
record.metadata = metadata;
}
return record;
}
export function normalizeThreadBindingDurationMs(raw: unknown, defaultsTo: number): number {