mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:30:43 +00:00
perf(sessions): use loaded thread-info seam
This commit is contained in:
47
src/channels/plugins/session-thread-info-loaded.ts
Normal file
47
src/channels/plugins/session-thread-info-loaded.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
parseRawSessionConversationRef,
|
||||
parseThreadSessionSuffix,
|
||||
type ParsedThreadSessionSuffix,
|
||||
} from "../../sessions/session-key-utils.js";
|
||||
import { normalizeOptionalString } from "../../shared/string-coerce.js";
|
||||
import { getLoadedChannelPluginForRead } from "./registry-loaded-read.js";
|
||||
|
||||
type SessionConversationHookResult = {
|
||||
id: string;
|
||||
threadId?: string | null;
|
||||
};
|
||||
|
||||
function resolveLoadedSessionConversationThreadInfo(
|
||||
sessionKey: string | undefined | null,
|
||||
): ParsedThreadSessionSuffix | null {
|
||||
const raw = parseRawSessionConversationRef(sessionKey);
|
||||
if (!raw) {
|
||||
return null;
|
||||
}
|
||||
const rawId = raw.rawId.trim();
|
||||
if (!rawId) {
|
||||
return null;
|
||||
}
|
||||
const messaging = getLoadedChannelPluginForRead(raw.channel)?.messaging;
|
||||
const resolved = messaging?.resolveSessionConversation?.({
|
||||
kind: raw.kind,
|
||||
rawId,
|
||||
}) as SessionConversationHookResult | null | undefined;
|
||||
if (!resolved?.id?.trim()) {
|
||||
return null;
|
||||
}
|
||||
const id = resolved.id.trim();
|
||||
const threadId = normalizeOptionalString(resolved.threadId);
|
||||
return {
|
||||
baseSessionKey: threadId ? `${raw.prefix}:${id}` : normalizeOptionalString(sessionKey),
|
||||
threadId,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveLoadedSessionThreadInfo(
|
||||
sessionKey: string | undefined | null,
|
||||
): ParsedThreadSessionSuffix {
|
||||
return (
|
||||
resolveLoadedSessionConversationThreadInfo(sessionKey) ?? parseThreadSessionSuffix(sessionKey)
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { resolveSessionThreadInfo } from "../../channels/plugins/session-conversation.js";
|
||||
import { resolveLoadedSessionThreadInfo } from "../../channels/plugins/session-thread-info-loaded.js";
|
||||
import {
|
||||
normalizeLowercaseStringOrEmpty,
|
||||
normalizeOptionalLowercaseString,
|
||||
@@ -28,7 +28,7 @@ export const DEFAULT_RESET_AT_HOUR = 4;
|
||||
const GROUP_SESSION_MARKERS = [":group:", ":channel:"];
|
||||
|
||||
export function isThreadSessionKey(sessionKey?: string | null): boolean {
|
||||
return Boolean(resolveSessionThreadInfo(sessionKey, { bundledFallback: false }).threadId);
|
||||
return Boolean(resolveLoadedSessionThreadInfo(sessionKey).threadId);
|
||||
}
|
||||
|
||||
export function resolveSessionResetType(params: {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { resolveSessionThreadInfo } from "../../channels/plugins/session-conversation.js";
|
||||
import { resolveLoadedSessionThreadInfo } from "../../channels/plugins/session-thread-info-loaded.js";
|
||||
|
||||
/**
|
||||
* Extract deliveryContext and threadId from a sessionKey.
|
||||
@@ -15,5 +16,5 @@ export function parseSessionThreadInfoFast(sessionKey: string | undefined): {
|
||||
baseSessionKey: string | undefined;
|
||||
threadId: string | undefined;
|
||||
} {
|
||||
return resolveSessionThreadInfo(sessionKey, { bundledFallback: false });
|
||||
return resolveLoadedSessionThreadInfo(sessionKey);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user