Skip to content

Commit 263bc61

Browse files
committed
fix(server): keep path text only for images on an external OpenCode server
1 parent e7bde64 commit 263bc61

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,7 +2861,7 @@ describe("OpenCode2 adapter", () => {
28612861
}).pipe(Effect.scoped, Effect.provide(IdAllocator.layer)),
28622862
);
28632863

2864-
it("gives OpenCode a file URL for each pasted image and leaves other attachments as paths", () => {
2864+
it("gives a server T3 started a file URL for each pasted image, an external one none", () => {
28652865
const image = ChatImageAttachment.make({
28662866
type: "image",
28672867
id: ChatAttachmentId.make("thread-opencode2-adapter-12345678-1234-1234-1234-123456789abc"),
@@ -2876,12 +2876,14 @@ describe("OpenCode2 adapter", () => {
28762876
mimeType: "application/pdf",
28772877
sizeBytes: 4,
28782878
});
2879-
assert.deepEqual(promptImageFiles([image, document], "/home/a user/.t3/userdata/attachments"), [
2879+
const attachmentsDir = "/home/a user/.t3/userdata/attachments";
2880+
assert.deepEqual(promptImageFiles([image, document], attachmentsDir, false), [
28802881
{
28812882
uri: "file:///home/a%20user/.t3/userdata/attachments/thread-opencode2-adapter-12345678-1234-1234-1234-123456789abc.png",
28822883
name: "screen shot.png",
28832884
},
28842885
]);
2886+
assert.deepEqual(promptImageFiles([image, document], attachmentsDir, true), []);
28852887
});
28862888

28872889
it.effect("reads user and assistant text from the session's message list", () =>

‎apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,16 +810,22 @@ const skillsNamed = (text: string, known: ReadonlySet<string>) => [
810810
/**
811811
* A message's pasted images as prompt files, which OpenCode reads from T3's
812812
* attachment directory and gives the model as images. The prompt text still
813-
* names where each one is saved, as with 1.x.
813+
* names where each one is saved, as with 1.x. A server T3 did not start may
814+
* not see that directory, so it gets the path text only.
814815
*/
815816
export const promptImageFiles = (
816817
attachments: ReadonlyArray<ChatAttachment>,
817818
attachmentsDir: string,
819+
external: boolean,
818820
) =>
819-
attachments.filter(isProviderNativeImageAttachment).flatMap((attachment) => {
820-
const path = resolveAttachmentPath({ attachmentsDir, attachment });
821-
return path === null ? [] : [{ uri: NodeURL.pathToFileURL(path).href, name: attachment.name }];
822-
});
821+
external
822+
? []
823+
: attachments.filter(isProviderNativeImageAttachment).flatMap((attachment) => {
824+
const path = resolveAttachmentPath({ attachmentsDir, attachment });
825+
return path === null
826+
? []
827+
: [{ uri: NodeURL.pathToFileURL(path).href, name: attachment.name }];
828+
});
823829

824830
/**
825831
* The turn's own tokens: steps add up, and the last step's input is the live
@@ -3561,7 +3567,11 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
35613567
),
35623568
)
35633569
: [];
3564-
const files = promptImageFiles(turnInput.message.attachments, serverConfig.attachmentsDir);
3570+
const files = promptImageFiles(
3571+
turnInput.message.attachments,
3572+
serverConfig.attachmentsDir,
3573+
connection.external,
3574+
);
35653575
if (!sending()) return;
35663576
return yield* client.session
35673577
.prompt({
@@ -3907,6 +3917,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
39073917
const files = promptImageFiles(
39083918
steerInput.message.attachments,
39093919
serverConfig.attachmentsDir,
3920+
connection.external,
39103921
);
39113922
yield* client.session
39123923
.prompt({

0 commit comments

Comments
 (0)