summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/utils
diff options
context:
space:
mode:
authorShoubhit Dash <[email protected]>2026-03-23 12:14:17 +0530
committerGitHub <[email protected]>2026-03-23 06:44:17 +0000
commit9239d877b9602a5a80e9e69e744abfe011f5f991 (patch)
tree7c097bec13af5e693a7f52a74aebcb7136de782a /packages/app/src/utils
parentfc68c244333a3829177fd0594aa3d5c018203487 (diff)
downloadopencode-9239d877b9602a5a80e9e69e744abfe011f5f991.tar.gz
opencode-9239d877b9602a5a80e9e69e744abfe011f5f991.zip
fix(app): batch multi-file prompt attachments (#18722)
Diffstat (limited to 'packages/app/src/utils')
-rw-r--r--packages/app/src/utils/prompt.test.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/app/src/utils/prompt.test.ts b/packages/app/src/utils/prompt.test.ts
new file mode 100644
index 000000000..1ecaf02c9
--- /dev/null
+++ b/packages/app/src/utils/prompt.test.ts
@@ -0,0 +1,44 @@
+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" },
+ ])
+ })
+})