refactor: drop legacy session store keys

This commit is contained in:
Peter Steinberger
2026-01-17 06:48:34 +00:00
parent 353d778988
commit 37a2eee837
22 changed files with 65 additions and 93 deletions

View File

@@ -63,8 +63,8 @@ export function resolveGroupSessionKey(ctx: MsgContext): GroupKeyResolution | nu
if (!isGroup) return null;
const providerHint = ctx.Provider?.trim().toLowerCase();
const hasLegacyGroupPrefix = from.startsWith("group:");
const raw = (hasLegacyGroupPrefix ? from.slice("group:".length) : from).trim();
const hasGroupPrefix = from.startsWith("group:");
const raw = (hasGroupPrefix ? from.slice("group:".length) : from).trim();
let provider: string | undefined;
let kind: "group" | "channel" | undefined;
@@ -97,7 +97,7 @@ export function resolveGroupSessionKey(ctx: MsgContext): GroupKeyResolution | nu
}
};
if (hasLegacyGroupPrefix) {
if (hasGroupPrefix) {
const legacyParts = raw.split(":").filter(Boolean);
if (legacyParts.length > 1) {
parseParts(legacyParts);
@@ -115,25 +115,19 @@ export function resolveGroupSessionKey(ctx: MsgContext): GroupKeyResolution | nu
const resolvedProvider = provider ?? providerHint;
if (!resolvedProvider) {
const legacy = hasLegacyGroupPrefix ? `group:${raw}` : `group:${from}`;
const legacy = hasGroupPrefix ? `group:${raw}` : `group:${from}`;
return {
key: legacy,
id: raw || from,
legacyKey: legacy,
chatType: "group",
};
}
const resolvedKind = kind === "channel" ? "channel" : "group";
const key = `${resolvedProvider}:${resolvedKind}:${id || raw || from}`;
let legacyKey: string | undefined;
if (hasLegacyGroupPrefix || from.includes("@g.us")) {
legacyKey = `group:${id || raw || from}`;
}
return {
key,
legacyKey,
channel: resolvedProvider,
id: id || raw || from,
chatType: resolvedKind === "channel" ? "channel" : "group",

View File

@@ -1,6 +1,7 @@
import crypto from "node:crypto";
import type { Skill } from "@mariozechner/pi-coding-agent";
import type { NormalizedChatType } from "../../channels/chat-type.js";
import type { ChannelId } from "../../channels/plugins/types.js";
import type { DeliveryContext } from "../../utils/delivery-context.js";
@@ -8,10 +9,7 @@ export type SessionScope = "per-sender" | "global";
export type SessionChannelId = ChannelId | "webchat";
export type SessionChatType =
| "direct"
| "group"
| "channel";
export type SessionChatType = NormalizedChatType;
export type SessionEntry = {
/**
@@ -90,7 +88,6 @@ export function mergeSessionEntry(
export type GroupKeyResolution = {
key: string;
legacyKey?: string;
channel?: string;
id?: string;
chatType?: SessionChatType;

View File

@@ -1,3 +1,5 @@
import type { NormalizedChatType } from "../channels/chat-type.js";
export type ReplyMode = "text" | "command";
export type TypingMode = "never" | "instant" | "thinking" | "message";
export type SessionScope = "per-sender" | "global";
@@ -41,7 +43,7 @@ export type HumanDelayConfig = {
export type SessionSendPolicyAction = "allow" | "deny";
export type SessionSendPolicyMatch = {
channel?: string;
chatType?: "direct" | "group" | "channel";
chatType?: NormalizedChatType;
keyPrefix?: string;
};
export type SessionSendPolicyRule = {

View File

@@ -1,8 +1,9 @@
import type { NormalizedChatType } from "../channels/chat-type.js";
import type { AgentElevatedAllowFromConfig, SessionSendPolicyAction } from "./types.base.js";
export type MediaUnderstandingScopeMatch = {
channel?: string;
chatType?: "direct" | "group" | "channel";
chatType?: NormalizedChatType;
keyPrefix?: string;
};