The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 04:30 UTC
fix(opencode): OpenCode 2 titles for image messages skip images the server cannot open (#29819)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Alex Southwell committed
Nov 3, 2026 at 23:30 UTC
5e53057afbfe08e8d0e3af59e899f696582af981
2 files changed
+71
-27
apps/server/src/textGeneration/OpenCode2TextGeneration.test.ts
+56
-23
@@ -1,12 +1,15 @@
1
import { assert, it } from "@effect/vitest";
2
import * as NodeServices from "@effect/platform-node/NodeServices";
3
-import { ProviderInstanceId } from "@t3tools/contracts";
3
+import * as NodeURL from "node:url";
4
+import { ChatAttachmentId, ChatImageAttachment, ProviderInstanceId } from "@t3tools/contracts";
5
import * as Deferred from "effect/Deferred";
6
import * as Effect from "effect/Effect";
7
+import * as FileSystem from "effect/FileSystem";
8
import * as Fiber from "effect/Fiber";
9
import * as Layer from "effect/Layer";
10
import { TestClock } from "effect/testing";
11
12
+import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
13
import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost";
14
import * as OpenCode2AdapterV2Testkit from "../orchestration-v2/Adapters/OpenCode2AdapterV2.testkit.ts";
15
import * as OpenCode2Server from "@t3tools/provider-opencode/server/v2/OpenCode2Server";
@@ -16,28 +19,58 @@ import { OPENCODE2_TITLE_GENERATION } from "./OpenCode2TextGeneration.fixture.ts
19
const layer = TestProviderHost.layer().pipe(Layer.provideMerge(NodeServices.layer));
20
21
it.layer(layer)("OpenCode2TextGeneration", (it) => {
19
- it.effect("generates a title in a temporary session on the free tier and removes it", () =>
20
- Effect.gen(function* () {
21
- const server = yield* OpenCode2AdapterV2Testkit.replayServer({
22
- provider: "opencode",
23
- protocol: OpenCode2AdapterV2Testkit.OPENCODE2_HTTP_PROTOCOL,
24
- version: "2.0.18",
25
- scenario: "opencode2_title_generation",
26
- entries: [...OPENCODE2_TITLE_GENERATION, { type: "runtime_exit", status: "success" }],
27
- });
28
- const textGeneration = yield* OpenCode2TextGeneration.make().pipe(
29
- Effect.provideService(OpenCode2Server.OpenCode2Server, server),
30
- );
31
- const title = yield* textGeneration.generateThreadTitle({
32
- cwd: process.cwd(),
33
- message: "fix the login redirect loop after oauth",
34
- modelSelection: {
35
- instanceId: ProviderInstanceId.make("opencode"),
36
- model: "opencode/big-pickle",
37
- },
38
- });
39
- assert.equal(title.title, "Fix OAuth Login Redirect Loop");
40
- }).pipe(Effect.scoped),
22
+ it.effect.each([false, true] as const)(
23
+ "generates a title in a temporary session on the free tier and removes it (external: %s)",
24
+ (external) =>
25
+ Effect.gen(function* () {
26
+ const host = yield* ProviderHost.ProviderHost;
27
+ const fileSystem = yield* FileSystem.FileSystem;
28
+ const image = (id: string, name: string, mimeType: string) =>
29
+ ChatImageAttachment.make({
30
+ type: "image",
31
+ id: ChatAttachmentId.make(id),
32
+ name,
33
+ mimeType,
34
+ sizeBytes: 4,
35
+ });
36
+ const screenshot = image("oc2-title-screenshot", "screen.png", "image/png");
37
+ const missing = image("oc2-title-missing", "missing.png", "image/png");
38
+ const unsupported = image("oc2-title-diagram", "diagram.svg", "image/svg+xml");
39
+ const screenshotPath = host.resolveAttachmentPath(screenshot)!;
40
+ yield* fileSystem.writeFileString(screenshotPath, "data");
41
+ yield* fileSystem.writeFileString(host.resolveAttachmentPath(unsupported)!, "<svg/>");
42
+ const prompts: Array<unknown> = [];
43
+ const server = yield* OpenCode2AdapterV2Testkit.replayServer(
44
+ {
45
+ provider: "opencode",
46
+ protocol: OpenCode2AdapterV2Testkit.OPENCODE2_HTTP_PROTOCOL,
47
+ version: "2.0.18",
48
+ scenario: "opencode2_title_generation",
49
+ entries: [...OPENCODE2_TITLE_GENERATION, { type: "runtime_exit", status: "success" }],
50
+ },
51
+ { external, onPrompt: (input) => prompts.push(input) },
52
+ );
53
+ const textGeneration = yield* OpenCode2TextGeneration.make().pipe(
54
+ Effect.provideService(OpenCode2Server.OpenCode2Server, server),
55
+ );
56
+ const title = yield* textGeneration.generateThreadTitle({
57
+ cwd: process.cwd(),
58
+ message: "fix the login redirect loop after oauth",
59
+ attachments: [screenshot, missing, unsupported],
60
+ modelSelection: {
61
+ instanceId: ProviderInstanceId.make("opencode"),
62
+ model: "opencode/big-pickle",
63
+ },
64
+ });
65
+ assert.equal(title.title, "Fix OAuth Login Redirect Loop");
66
+ if (external) {
67
+ assert.notProperty(prompts[0], "files");
68
+ } else {
69
+ assert.deepInclude(prompts[0], {
70
+ files: [{ uri: NodeURL.pathToFileURL(screenshotPath).href, name: "screen.png" }],
71
+ });
72
+ }
73
+ }).pipe(Effect.scoped),
74
);
75
76
it.effect("keeps a provider's own error message out of the caller-visible detail", () =>
packages/provider-opencode/src/server/v2/textGeneration.ts
+15
-4
@@ -2,11 +2,14 @@
2
import { AbsolutePath, Location, Model, Provider, Session } from "@opencode/client/effect";
3
import { TextGenerationError } from "@t3tools/contracts";
4
import { getModelSelectionStringOptionValue } from "@t3tools/shared/model";
5
+import * as NodeURL from "node:url";
6
import * as Deferred from "effect/Deferred";
7
import * as Effect from "effect/Effect";
8
+import * as FileSystem from "effect/FileSystem";
9
import * as Schema from "effect/Schema";
10
import * as Stream from "effect/Stream";
11
12
+import { isProviderNativeImageAttachment } from "@t3tools/provider-core/server/attachmentPrompt";
13
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
14
import * as OpenCode2Server from "./OpenCode2Server.ts";
15
import * as OpenCodeRuntime from "../OpenCodeRuntime.ts";
@@ -29,6 +32,7 @@ const runOnServer = Effect.fn("Opencode2TextGeneration.runOnServer")(function* (
32
input: TextGenerationOperations.Request<Schema.Top>,
33
) {
34
const { resolveAttachmentPath } = yield* ProviderHost.ProviderHost;
35
+ const fileSystem = yield* FileSystem.FileSystem;
36
const { client } = connection;
37
const parsed = OpenCodeRuntime.parseOpenCodeModelSlug(input.modelSelection.model);
38
if (parsed === null) {
@@ -131,11 +135,16 @@ const runOnServer = Effect.fn("Opencode2TextGeneration.runOnServer")(function* (
135
.remove({ sessionID: session.id })
136
.pipe(Effect.timeout("5 seconds"), Effect.ignore({ log: true })),
137
);
134
- const images = (input.attachments ?? []).flatMap((attachment) => {
135
- if (attachment.type !== "image") return [];
138
+ const images: Array<{ uri: string; name: string }> = [];
139
+ // As in the adapter: an external server may not share T3's attachment directory, and
140
+ // OpenCode rejects the whole prompt if an attached file is missing.
141
+ for (const attachment of connection.external ? [] : (input.attachments ?? [])) {
142
+ if (!isProviderNativeImageAttachment(attachment)) continue;
143
const path = resolveAttachmentPath(attachment);
137
- return path === null ? [] : [{ uri: `file://${path}`, name: attachment.name }];
138
- });
144
+ if (path === null) continue;
145
+ const exists = yield* fileSystem.exists(path).pipe(Effect.orElseSucceed(() => false));
146
+ if (exists) images.push({ uri: NodeURL.pathToFileURL(path).href, name: attachment.name });
147
+ }
148
yield* client.session.prompt({
149
sessionID: session.id,
150
text: input.prompt,
@@ -179,11 +188,13 @@ const runOnServer = Effect.fn("Opencode2TextGeneration.runOnServer")(function* (
188
export const make = Effect.fn("OpenCode2TextGeneration.make")(function* () {
189
const server = yield* OpenCode2Server.OpenCode2Server;
190
const host = yield* ProviderHost.ProviderHost;
191
+ const fileSystem = yield* FileSystem.FileSystem;
192
const run: TextGenerationOperations.Runner = (input) =>
193
server
194
.withConnection((connection) => runOnServer(connection, input))
195
.pipe(
196
Effect.provideService(ProviderHost.ProviderHost, host),
197
+ Effect.provideService(FileSystem.FileSystem, fileSystem),
198
Effect.mapError((cause) =>
199
isTextGenerationError(cause)
200
? cause