|
| 1 | +import { describe, it, expect } from "@jest/globals"; |
| 2 | +import { transformScriptMessagesForLLM } from "./modelMessageTransform"; |
| 3 | +import type { MuxMessage } from "@/common/types/message"; |
| 4 | + |
| 5 | +describe("transformScriptMessagesForLLM", () => { |
| 6 | + it("should remove script execution messages that have no promptFile content", () => { |
| 7 | + const messages: MuxMessage[] = [ |
| 8 | + { |
| 9 | + id: "1", |
| 10 | + role: "user", |
| 11 | + parts: [{ type: "text", text: "Execute script" }], |
| 12 | + }, |
| 13 | + { |
| 14 | + id: "script-1", |
| 15 | + role: "user", |
| 16 | + parts: [{ type: "text", text: "Executed script: /script test" }], |
| 17 | + metadata: { |
| 18 | + muxMetadata: { |
| 19 | + type: "script-execution", |
| 20 | + id: "script-1", |
| 21 | + historySequence: 0, |
| 22 | + timestamp: 123, |
| 23 | + command: "/script test", |
| 24 | + scriptName: "test.sh", |
| 25 | + args: [], |
| 26 | + result: { |
| 27 | + success: true, |
| 28 | + output: "some stdout output", |
| 29 | + exitCode: 0, |
| 30 | + wall_duration_ms: 100, |
| 31 | + } as any, |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | + ]; |
| 36 | + |
| 37 | + const result = transformScriptMessagesForLLM(messages); |
| 38 | + expect(result).toHaveLength(1); |
| 39 | + expect(result[0].id).toBe("1"); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should include script execution messages that HAVE promptFile content", () => { |
| 43 | + const messages: MuxMessage[] = [ |
| 44 | + { |
| 45 | + id: "script-1", |
| 46 | + role: "user", |
| 47 | + parts: [{ type: "text", text: "Executed script: /script test" }], |
| 48 | + metadata: { |
| 49 | + muxMetadata: { |
| 50 | + type: "script-execution", |
| 51 | + id: "script-1", |
| 52 | + historySequence: 0, |
| 53 | + timestamp: 123, |
| 54 | + command: "/script test", |
| 55 | + scriptName: "test.sh", |
| 56 | + args: [], |
| 57 | + result: { |
| 58 | + success: true, |
| 59 | + output: "some stdout output", |
| 60 | + exitCode: 0, |
| 61 | + wall_duration_ms: 100, |
| 62 | + promptFile: "This is relevant for the LLM", |
| 63 | + } as any, |
| 64 | + }, |
| 65 | + }, |
| 66 | + }, |
| 67 | + ]; |
| 68 | + |
| 69 | + const result = transformScriptMessagesForLLM(messages); |
| 70 | + expect(result).toHaveLength(1); |
| 71 | + const textPart = result[0].parts[0]; |
| 72 | + expect(textPart.type).toBe("text"); |
| 73 | + if (textPart.type === "text") { |
| 74 | + expect(textPart.text).toContain("Script 'test.sh' executed"); |
| 75 | + expect(textPart.text).toContain("Output:"); |
| 76 | + expect(textPart.text).toContain("This is relevant for the LLM"); |
| 77 | + expect(textPart.text).not.toContain("some stdout output"); |
| 78 | + } |
| 79 | + }); |
| 80 | +}); |
0 commit comments