mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:30:43 +00:00
perf: trim msteams authz graph mock
This commit is contained in:
@@ -39,10 +39,40 @@ const graphThreadMockState = vi.hoisted(() => ({
|
||||
>(async () => []),
|
||||
}));
|
||||
|
||||
vi.mock("../graph-thread.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../graph-thread.js")>("../graph-thread.js");
|
||||
vi.mock("../graph-thread.js", () => {
|
||||
const stripHtmlFromTeamsMessage = (html: string) =>
|
||||
html
|
||||
.replace(/<at[^>]*>(.*?)<\/at>/gi, "@$1")
|
||||
.replace(/<[^>]*>/g, " ")
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, "'")
|
||||
.replace(/ /g, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
const formatThreadContext = (messages: GraphThreadMessage[], currentMessageId?: string) => {
|
||||
const lines: string[] = [];
|
||||
for (const msg of messages) {
|
||||
if (msg.id && msg.id === currentMessageId) {
|
||||
continue;
|
||||
}
|
||||
const sender = msg.from?.user?.displayName ?? msg.from?.application?.displayName ?? "unknown";
|
||||
const rawContent = msg.body?.content ?? "";
|
||||
const content =
|
||||
msg.body?.contentType === "html"
|
||||
? stripHtmlFromTeamsMessage(rawContent)
|
||||
: rawContent.trim();
|
||||
if (content) {
|
||||
lines.push(`${sender}: ${content}`);
|
||||
}
|
||||
}
|
||||
return lines.join("\n");
|
||||
};
|
||||
return {
|
||||
...actual,
|
||||
stripHtmlFromTeamsMessage,
|
||||
formatThreadContext,
|
||||
resolveTeamGroupId: graphThreadMockState.resolveTeamGroupId,
|
||||
fetchChannelMessage: graphThreadMockState.fetchChannelMessage,
|
||||
fetchThreadReplies: graphThreadMockState.fetchThreadReplies,
|
||||
|
||||
Reference in New Issue
Block a user