perf(memory): lazy-load telegram context session helpers

This commit is contained in:
Vincent Koc
2026-04-02 14:31:48 +09:00
parent 1707493be4
commit 703a363589
2 changed files with 17 additions and 12 deletions

View File

@@ -0,0 +1,5 @@
export { readSessionUpdatedAt, resolveStorePath } from "openclaw/plugin-sdk/config-runtime";
export { recordInboundSession } from "openclaw/plugin-sdk/conversation-runtime";
export { finalizeInboundContext } from "openclaw/plugin-sdk/reply-runtime";
export { resolveInboundLastRouteSessionKey } from "openclaw/plugin-sdk/routing";
export { resolvePinnedMainDmOwnerFromAllowlist } from "openclaw/plugin-sdk/security-runtime";

View File

@@ -6,22 +6,17 @@ import {
} from "openclaw/plugin-sdk/channel-inbound";
import { normalizeCommandBody } from "openclaw/plugin-sdk/command-surface";
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
import { readSessionUpdatedAt, resolveStorePath } from "openclaw/plugin-sdk/config-runtime";
import type {
TelegramDirectConfig,
TelegramGroupConfig,
TelegramTopicConfig,
} from "openclaw/plugin-sdk/config-runtime";
import { recordInboundSession } from "openclaw/plugin-sdk/conversation-runtime";
import {
buildPendingHistoryContextFromMap,
type HistoryEntry,
} from "openclaw/plugin-sdk/reply-history";
import { finalizeInboundContext } from "openclaw/plugin-sdk/reply-runtime";
import type { ResolvedAgentRoute } from "openclaw/plugin-sdk/routing";
import { resolveInboundLastRouteSessionKey } from "openclaw/plugin-sdk/routing";
import { logVerbose, shouldLogVerbose } from "openclaw/plugin-sdk/runtime-env";
import { resolvePinnedMainDmOwnerFromAllowlist } from "openclaw/plugin-sdk/security-runtime";
import { normalizeAllowFrom } from "./bot-access.js";
import type {
TelegramMediaRef,
@@ -39,6 +34,10 @@ import {
import type { TelegramContext } from "./bot/types.js";
import { resolveTelegramGroupPromptSettings } from "./group-config-helpers.js";
type FinalizedTelegramInboundContext = ReturnType<
typeof import("./bot-message-context.session.runtime.js").finalizeInboundContext
>;
export async function buildTelegramInboundContextPayload(params: {
cfg: OpenClawConfig;
primaryCtx: TelegramContext;
@@ -68,7 +67,7 @@ export async function buildTelegramInboundContextPayload(params: {
options?: TelegramMessageContextOptions;
dmAllowFrom?: Array<string | number>;
}): Promise<{
ctxPayload: ReturnType<typeof finalizeInboundContext>;
ctxPayload: FinalizedTelegramInboundContext;
skillFilter: string[] | undefined;
}> {
const {
@@ -128,11 +127,12 @@ export async function buildTelegramInboundContextPayload(params: {
const conversationLabel = isGroup
? (groupLabel ?? `group:${chatId}`)
: buildSenderLabel(msg, senderId || chatId);
const storePath = resolveStorePath(cfg.session?.store, {
const sessionRuntime = await import("./bot-message-context.session.runtime.js");
const storePath = sessionRuntime.resolveStorePath(cfg.session?.store, {
agentId: route.agentId,
});
const envelopeOptions = resolveEnvelopeFormatOptions(cfg);
const previousTimestamp = readSessionUpdatedAt({
const previousTimestamp = sessionRuntime.readSessionUpdatedAt({
storePath,
sessionKey: route.sessionKey,
});
@@ -187,7 +187,7 @@ export async function buildTelegramInboundContextPayload(params: {
: undefined;
const currentMediaForContext = stickerCacheHit ? [] : allMedia;
const contextMedia = [...currentMediaForContext, ...replyMedia];
const ctxPayload = finalizeInboundContext({
const ctxPayload = sessionRuntime.finalizeInboundContext({
Body: combinedBody,
BodyForAgent: bodyText,
InboundHistory: inboundHistory,
@@ -252,13 +252,13 @@ export async function buildTelegramInboundContextPayload(params: {
});
const pinnedMainDmOwner = !isGroup
? resolvePinnedMainDmOwnerFromAllowlist({
? sessionRuntime.resolvePinnedMainDmOwnerFromAllowlist({
dmScope: cfg.session?.dmScope,
allowFrom: dmAllowFrom,
normalizeEntry: (entry) => normalizeAllowFrom([entry]).entries[0],
})
: null;
const updateLastRouteSessionKey = resolveInboundLastRouteSessionKey({
const updateLastRouteSessionKey = sessionRuntime.resolveInboundLastRouteSessionKey({
route,
sessionKey: route.sessionKey,
});
@@ -271,7 +271,7 @@ export async function buildTelegramInboundContextPayload(params: {
? String(dmThreadId)
: undefined;
await recordInboundSession({
await sessionRuntime.recordInboundSession({
storePath,
sessionKey: ctxPayload.SessionKey ?? route.sessionKey,
ctx: ctxPayload,