mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 19:18:26 +00:00
refactor(sessions): share session thread/topic parsing
This commit is contained in:
@@ -3,6 +3,7 @@ import { resolveAnnounceTargetFromKey } from "../agents/tools/sessions-send-help
|
||||
import { normalizeChannelId } from "../channels/plugins/index.js";
|
||||
import type { CliDeps } from "../cli/deps.js";
|
||||
import { resolveMainSessionKeyFromConfig } from "../config/sessions.js";
|
||||
import { parseSessionThreadInfo } from "../config/sessions/delivery-info.js";
|
||||
import { deliverOutboundPayloads } from "../infra/outbound/deliver.js";
|
||||
import { resolveOutboundTarget } from "../infra/outbound/targets.js";
|
||||
import {
|
||||
@@ -30,17 +31,7 @@ export async function scheduleRestartSentinelWake(_params: { deps: CliDeps }) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract topic/thread ID from sessionKey (supports both :topic: and :thread:)
|
||||
// Telegram uses :topic:, other platforms use :thread:
|
||||
const topicIndex = sessionKey.lastIndexOf(":topic:");
|
||||
const threadIndex = sessionKey.lastIndexOf(":thread:");
|
||||
const markerIndex = Math.max(topicIndex, threadIndex);
|
||||
const marker = topicIndex > threadIndex ? ":topic:" : ":thread:";
|
||||
|
||||
const baseSessionKey = markerIndex === -1 ? sessionKey : sessionKey.slice(0, markerIndex);
|
||||
const threadIdRaw =
|
||||
markerIndex === -1 ? undefined : sessionKey.slice(markerIndex + marker.length);
|
||||
const sessionThreadId = threadIdRaw?.trim() || undefined;
|
||||
const { baseSessionKey, threadId: sessionThreadId } = parseSessionThreadInfo(sessionKey);
|
||||
|
||||
const { cfg, entry } = loadSessionEntry(sessionKey);
|
||||
const parsedTarget = resolveAnnounceTargetFromKey(baseSessionKey);
|
||||
@@ -49,7 +40,7 @@ export async function scheduleRestartSentinelWake(_params: { deps: CliDeps }) {
|
||||
// Handles race condition where store wasn't flushed before restart
|
||||
const sentinelContext = payload.deliveryContext;
|
||||
let sessionDeliveryContext = deliveryContextFromSession(entry);
|
||||
if (!sessionDeliveryContext && markerIndex !== -1 && baseSessionKey) {
|
||||
if (!sessionDeliveryContext && baseSessionKey && baseSessionKey !== sessionKey) {
|
||||
const { entry: baseEntry } = loadSessionEntry(baseSessionKey);
|
||||
sessionDeliveryContext = deliveryContextFromSession(baseEntry);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user