mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-24 07:31:44 +00:00
test: reuse plugin session key surfaces
This commit is contained in:
@@ -1,51 +1,24 @@
|
||||
import { loadBundledPluginPublicSurfaceSync } from "./bundled-plugin-public-surface.js";
|
||||
import { createTestRegistry } from "./channel-plugins.js";
|
||||
|
||||
function parseTelegramTopicConversation(rawId: string) {
|
||||
const match = /^(-?\d+):topic:(\d+)$/i.exec(rawId.trim());
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
id: match[1],
|
||||
threadId: match[2],
|
||||
parentConversationCandidates: [match[1]],
|
||||
};
|
||||
type SessionConversationSurface = {
|
||||
resolveSessionConversation?: (params: { kind: "group" | "channel"; rawId: string }) => {
|
||||
id: string;
|
||||
threadId?: string | null;
|
||||
baseConversationId?: string | null;
|
||||
parentConversationCandidates?: string[];
|
||||
} | null;
|
||||
};
|
||||
|
||||
function loadSessionConversationSurface(pluginId: string) {
|
||||
return loadBundledPluginPublicSurfaceSync<SessionConversationSurface>({
|
||||
pluginId,
|
||||
artifactBasename: "session-key-api.js",
|
||||
}).resolveSessionConversation;
|
||||
}
|
||||
|
||||
function resolveFeishuConversation(rawId: string) {
|
||||
const trimmed = rawId.trim();
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
const topicSenderMatch = /^(.+):topic:([^:]+):sender:([^:]+)$/i.exec(trimmed);
|
||||
if (topicSenderMatch) {
|
||||
const [, chatId, topicId, senderId] = topicSenderMatch;
|
||||
return {
|
||||
id: `${chatId}:topic:${topicId}:sender:${senderId}`,
|
||||
parentConversationCandidates: [`${chatId}:topic:${topicId}`, chatId],
|
||||
};
|
||||
}
|
||||
const topicMatch = /^(.+):topic:([^:]+)$/i.exec(trimmed);
|
||||
if (topicMatch) {
|
||||
const [, chatId, topicId] = topicMatch;
|
||||
return {
|
||||
id: `${chatId}:topic:${topicId}`,
|
||||
parentConversationCandidates: [chatId],
|
||||
};
|
||||
}
|
||||
const senderMatch = /^(.+):sender:([^:]+)$/i.exec(trimmed);
|
||||
if (senderMatch) {
|
||||
const [, chatId, senderId] = senderMatch;
|
||||
return {
|
||||
id: `${chatId}:sender:${senderId}`,
|
||||
parentConversationCandidates: [chatId],
|
||||
};
|
||||
}
|
||||
return {
|
||||
id: trimmed,
|
||||
parentConversationCandidates: [],
|
||||
};
|
||||
}
|
||||
const resolveTelegramSessionConversation = loadSessionConversationSurface("telegram");
|
||||
const resolveFeishuSessionConversation = loadSessionConversationSurface("feishu");
|
||||
|
||||
export function createSessionConversationTestRegistry() {
|
||||
return createTestRegistry([
|
||||
@@ -130,8 +103,7 @@ export function createSessionConversationTestRegistry() {
|
||||
capabilities: { chatTypes: ["direct", "group", "thread"] },
|
||||
messaging: {
|
||||
normalizeTarget: (raw: string) => raw.replace(/^group:/, ""),
|
||||
resolveSessionConversation: ({ rawId }: { rawId: string }) =>
|
||||
parseTelegramTopicConversation(rawId),
|
||||
resolveSessionConversation: resolveTelegramSessionConversation,
|
||||
},
|
||||
config: {
|
||||
listAccountIds: () => ["default"],
|
||||
@@ -154,8 +126,7 @@ export function createSessionConversationTestRegistry() {
|
||||
capabilities: { chatTypes: ["direct", "group", "thread"] },
|
||||
messaging: {
|
||||
normalizeTarget: (raw: string) => raw.replace(/^group:/, ""),
|
||||
resolveSessionConversation: ({ rawId }: { rawId: string }) =>
|
||||
resolveFeishuConversation(rawId),
|
||||
resolveSessionConversation: resolveFeishuSessionConversation,
|
||||
},
|
||||
config: {
|
||||
listAccountIds: () => ["default"],
|
||||
|
||||
Reference in New Issue
Block a user