Buckets:
| import { describe, expect, test } from "bun:test" | |
| import type { Part } from "@opencode-ai/sdk/v2" | |
| import { extractPromptFromParts } from "./prompt" | |
| describe("extractPromptFromParts", () => { | |
| test("restores multiple uploaded attachments", () => { | |
| const parts = [ | |
| { | |
| id: "text_1", | |
| type: "text", | |
| text: "check these", | |
| sessionID: "ses_1", | |
| messageID: "msg_1", | |
| }, | |
| { | |
| id: "file_1", | |
| type: "file", | |
| mime: "image/png", | |
| url: "data:image/png;base64,AAA", | |
| filename: "a.png", | |
| sessionID: "ses_1", | |
| messageID: "msg_1", | |
| }, | |
| { | |
| id: "file_2", | |
| type: "file", | |
| mime: "application/pdf", | |
| url: "data:application/pdf;base64,BBB", | |
| filename: "b.pdf", | |
| sessionID: "ses_1", | |
| messageID: "msg_1", | |
| }, | |
| ] satisfies Part[] | |
| const result = extractPromptFromParts(parts) | |
| expect(result).toHaveLength(3) | |
| expect(result[0]).toMatchObject({ type: "text", content: "check these" }) | |
| expect(result.slice(1)).toMatchObject([ | |
| { type: "image", filename: "a.png", mime: "image/png", dataUrl: "data:image/png;base64,AAA" }, | |
| { type: "image", filename: "b.pdf", mime: "application/pdf", dataUrl: "data:application/pdf;base64,BBB" }, | |
| ]) | |
| }) | |
| }) | |
Xet Storage Details
- Size:
- 1.31 kB
- Xet hash:
- dc3fcb4480d65ca79ea71e6b1f69a9e7db0b31ddfa1becbe16b1d0ba14433820
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.