@@ -39,10 +39,40 @@ const graphThreadMockState = vi.hoisted(() => ({
|
39 | 39 | >(async () => []), |
40 | 40 | })); |
41 | 41 | |
42 | | -vi.mock("../graph-thread.js", async () => { |
43 | | -const actual = await vi.importActual<typeof import("../graph-thread.js")>("../graph-thread.js"); |
| 42 | +vi.mock("../graph-thread.js", () => { |
| 43 | +const stripHtmlFromTeamsMessage = (html: string) => |
| 44 | +html |
| 45 | +.replace(/<at[^>]*>(.*?)<\/at>/gi, "@$1") |
| 46 | +.replace(/<[^>]*>/g, " ") |
| 47 | +.replace(/&/g, "&") |
| 48 | +.replace(/</g, "<") |
| 49 | +.replace(/>/g, ">") |
| 50 | +.replace(/"/g, '"') |
| 51 | +.replace(/'/g, "'") |
| 52 | +.replace(/ /g, " ") |
| 53 | +.replace(/\s+/g, " ") |
| 54 | +.trim(); |
| 55 | +const formatThreadContext = (messages: GraphThreadMessage[], currentMessageId?: string) => { |
| 56 | +const lines: string[] = []; |
| 57 | +for (const msg of messages) { |
| 58 | +if (msg.id && msg.id === currentMessageId) { |
| 59 | +continue; |
| 60 | +} |
| 61 | +const sender = msg.from?.user?.displayName ?? msg.from?.application?.displayName ?? "unknown"; |
| 62 | +const rawContent = msg.body?.content ?? ""; |
| 63 | +const content = |
| 64 | +msg.body?.contentType === "html" |
| 65 | + ? stripHtmlFromTeamsMessage(rawContent) |
| 66 | + : rawContent.trim(); |
| 67 | +if (content) { |
| 68 | +lines.push(`${sender}: ${content}`); |
| 69 | +} |
| 70 | +} |
| 71 | +return lines.join("\n"); |
| 72 | +}; |
44 | 73 | return { |
45 | | - ...actual, |
| 74 | + stripHtmlFromTeamsMessage, |
| 75 | + formatThreadContext, |
46 | 76 | resolveTeamGroupId: graphThreadMockState.resolveTeamGroupId, |
47 | 77 | fetchChannelMessage: graphThreadMockState.fetchChannelMessage, |
48 | 78 | fetchThreadReplies: graphThreadMockState.fetchThreadReplies, |
|