mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:11:35 +00:00
refactor: unify peer kind to ChatType, rename dm to direct (#11881)
* fix: use .js extension for ESM imports of RoutePeerKind
The imports incorrectly used .ts extension which doesn't resolve
with moduleResolution: NodeNext. Changed to .js and added 'type'
import modifier.
* fix tsconfig
* refactor: unify peer kind to ChatType, rename dm to direct
- Replace RoutePeerKind with ChatType throughout codebase
- Change 'dm' literal values to 'direct' in routing/session keys
- Keep backward compat: normalizeChatType accepts 'dm' -> 'direct'
- Add ChatType export to plugin-sdk, deprecate RoutePeerKind
- Update session key parsing to accept both 'dm' and 'direct' markers
- Update all channel monitors and extensions to use ChatType
BREAKING CHANGE: Session keys now use 'direct' instead of 'dm'.
Existing 'dm' keys still work via backward compat layer.
* fix tests
* test: update session key expectations for dmdirect migration
- Fix test expectations to expect :direct: in generated output
- Add explicit backward compat test for normalizeChatType('dm')
- Keep input test data with :dm: keys to verify backward compat
* fix: accept legacy 'dm' in session key parsing for backward compat
getDmHistoryLimitFromSessionKey now accepts both :dm: and :direct:
to ensure old session keys continue to work correctly.
* test: add explicit backward compat tests for dmdirect migration
- session-key.test.ts: verify both :dm: and :direct: keys are valid
- getDmHistoryLimitFromSessionKey: verify both formats work
* feat: backward compat for resetByType.dm config key
* test: skip unix-path Nix tests on Windows
This commit is contained in:
72
src/config/sessions/reset.test.ts
Normal file
72
src/config/sessions/reset.test.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { SessionConfig } from "../types.base.js";
|
||||
import { resolveSessionResetPolicy } from "./reset.js";
|
||||
|
||||
describe("resolveSessionResetPolicy", () => {
|
||||
describe("backward compatibility: resetByType.dm → direct", () => {
|
||||
it("uses resetByType.direct when available", () => {
|
||||
const sessionCfg = {
|
||||
resetByType: {
|
||||
direct: { mode: "idle" as const, idleMinutes: 30 },
|
||||
},
|
||||
} satisfies SessionConfig;
|
||||
|
||||
const policy = resolveSessionResetPolicy({
|
||||
sessionCfg,
|
||||
resetType: "direct",
|
||||
});
|
||||
|
||||
expect(policy.mode).toBe("idle");
|
||||
expect(policy.idleMinutes).toBe(30);
|
||||
});
|
||||
|
||||
it("falls back to resetByType.dm (legacy) when direct is missing", () => {
|
||||
// Simulating legacy config with "dm" key instead of "direct"
|
||||
const sessionCfg = {
|
||||
resetByType: {
|
||||
dm: { mode: "idle" as const, idleMinutes: 45 },
|
||||
},
|
||||
} as unknown as SessionConfig;
|
||||
|
||||
const policy = resolveSessionResetPolicy({
|
||||
sessionCfg,
|
||||
resetType: "direct",
|
||||
});
|
||||
|
||||
expect(policy.mode).toBe("idle");
|
||||
expect(policy.idleMinutes).toBe(45);
|
||||
});
|
||||
|
||||
it("prefers resetByType.direct over resetByType.dm when both present", () => {
|
||||
const sessionCfg = {
|
||||
resetByType: {
|
||||
direct: { mode: "daily" as const },
|
||||
dm: { mode: "idle" as const, idleMinutes: 99 },
|
||||
},
|
||||
} as unknown as SessionConfig;
|
||||
|
||||
const policy = resolveSessionResetPolicy({
|
||||
sessionCfg,
|
||||
resetType: "direct",
|
||||
});
|
||||
|
||||
expect(policy.mode).toBe("daily");
|
||||
});
|
||||
|
||||
it("does not use dm fallback for group/thread types", () => {
|
||||
const sessionCfg = {
|
||||
resetByType: {
|
||||
dm: { mode: "idle" as const, idleMinutes: 45 },
|
||||
},
|
||||
} as unknown as SessionConfig;
|
||||
|
||||
const groupPolicy = resolveSessionResetPolicy({
|
||||
sessionCfg,
|
||||
resetType: "group",
|
||||
});
|
||||
|
||||
// Should use default mode since group has no config and dm doesn't apply
|
||||
expect(groupPolicy.mode).toBe("daily");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -3,7 +3,7 @@ import { normalizeMessageChannel } from "../../utils/message-channel.js";
|
||||
import { DEFAULT_IDLE_MINUTES } from "./types.js";
|
||||
|
||||
export type SessionResetMode = "daily" | "idle";
|
||||
export type SessionResetType = "dm" | "group" | "thread";
|
||||
export type SessionResetType = "direct" | "group" | "thread";
|
||||
|
||||
export type SessionResetPolicy = {
|
||||
mode: SessionResetMode;
|
||||
@@ -46,7 +46,7 @@ export function resolveSessionResetType(params: {
|
||||
if (GROUP_SESSION_MARKERS.some((marker) => normalized.includes(marker))) {
|
||||
return "group";
|
||||
}
|
||||
return "dm";
|
||||
return "direct";
|
||||
}
|
||||
|
||||
export function resolveThreadFlag(params: {
|
||||
@@ -88,7 +88,13 @@ export function resolveSessionResetPolicy(params: {
|
||||
}): SessionResetPolicy {
|
||||
const sessionCfg = params.sessionCfg;
|
||||
const baseReset = params.resetOverride ?? sessionCfg?.reset;
|
||||
const typeReset = params.resetOverride ? undefined : sessionCfg?.resetByType?.[params.resetType];
|
||||
// Backward compat: accept legacy "dm" key as alias for "direct"
|
||||
const typeReset = params.resetOverride
|
||||
? undefined
|
||||
: (sessionCfg?.resetByType?.[params.resetType] ??
|
||||
(params.resetType === "direct"
|
||||
? (sessionCfg?.resetByType as { dm?: SessionResetConfig } | undefined)?.dm
|
||||
: undefined));
|
||||
const hasExplicitReset = Boolean(baseReset || sessionCfg?.resetByType);
|
||||
const legacyIdleMinutes = params.resetOverride ? undefined : sessionCfg?.idleMinutes;
|
||||
const mode =
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Skill } from "@mariozechner/pi-coding-agent";
|
||||
import crypto from "node:crypto";
|
||||
import type { NormalizedChatType } from "../../channels/chat-type.js";
|
||||
import type { ChatType } from "../../channels/chat-type.js";
|
||||
import type { ChannelId } from "../../channels/plugins/types.js";
|
||||
import type { DeliveryContext } from "../../utils/delivery-context.js";
|
||||
import type { TtsAutoMode } from "../types.tts.js";
|
||||
@@ -9,7 +9,7 @@ export type SessionScope = "per-sender" | "global";
|
||||
|
||||
export type SessionChannelId = ChannelId | "webchat";
|
||||
|
||||
export type SessionChatType = NormalizedChatType;
|
||||
export type SessionChatType = ChatType;
|
||||
|
||||
export type SessionOrigin = {
|
||||
label?: string;
|
||||
|
||||
Reference in New Issue
Block a user