Skip to content

Commit aa6b552

Browse files
authored
Revert pr that was mistakenly merged (#11844)
1 parent a3f1918 commit aa6b552

6 files changed

Lines changed: 33 additions & 122 deletions

File tree

packages/opencode/src/session/processor.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,6 @@ export namespace SessionProcessor {
172172
case "tool-result": {
173173
const match = toolcalls[value.toolCallId]
174174
if (match && match.state.status === "running") {
175-
const attachments = value.output.attachments?.map(
176-
(attachment: Omit<MessageV2.FilePart, "id" | "messageID" | "sessionID">) => ({
177-
...attachment,
178-
id: Identifier.ascending("part"),
179-
messageID: match.messageID,
180-
sessionID: match.sessionID,
181-
}),
182-
)
183175
await Session.updatePart({
184176
...match,
185177
state: {
@@ -192,7 +184,7 @@ export namespace SessionProcessor {
192184
start: match.state.time.start,
193185
end: Date.now(),
194186
},
195-
attachments,
187+
attachments: value.output.attachments,
196188
},
197189
})
198190

packages/opencode/src/session/prompt.ts

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -187,52 +187,47 @@ export namespace SessionPrompt {
187187
text: template,
188188
},
189189
]
190-
const matches = ConfigMarkdown.files(template)
190+
const files = ConfigMarkdown.files(template)
191191
const seen = new Set<string>()
192-
const names = matches
193-
.map((match) => match[1])
194-
.filter((name) => {
195-
if (seen.has(name)) return false
192+
await Promise.all(
193+
files.map(async (match) => {
194+
const name = match[1]
195+
if (seen.has(name)) return
196196
seen.add(name)
197-
return true
198-
})
199-
const resolved = await Promise.all(
200-
names.map(async (name) => {
201197
const filepath = name.startsWith("~/")
202198
? path.join(os.homedir(), name.slice(2))
203199
: path.resolve(Instance.worktree, name)
204200

205201
const stats = await fs.stat(filepath).catch(() => undefined)
206202
if (!stats) {
207203
const agent = await Agent.get(name)
208-
if (!agent) return undefined
209-
return {
210-
type: "agent",
211-
name: agent.name,
212-
} satisfies PromptInput["parts"][number]
204+
if (agent) {
205+
parts.push({
206+
type: "agent",
207+
name: agent.name,
208+
})
209+
}
210+
return
213211
}
214212

215213
if (stats.isDirectory()) {
216-
return {
214+
parts.push({
217215
type: "file",
218216
url: `file://${filepath}`,
219217
filename: name,
220218
mime: "application/x-directory",
221-
} satisfies PromptInput["parts"][number]
219+
})
220+
return
222221
}
223222

224-
return {
223+
parts.push({
225224
type: "file",
226225
url: `file://${filepath}`,
227226
filename: name,
228227
mime: "text/plain",
229-
} satisfies PromptInput["parts"][number]
228+
})
230229
}),
231230
)
232-
for (const item of resolved) {
233-
if (!item) continue
234-
parts.push(item)
235-
}
236231
return parts
237232
}
238233

@@ -432,12 +427,6 @@ export namespace SessionPrompt {
432427
assistantMessage.time.completed = Date.now()
433428
await Session.updateMessage(assistantMessage)
434429
if (result && part.state.status === "running") {
435-
const attachments = result.attachments?.map((attachment) => ({
436-
...attachment,
437-
id: Identifier.ascending("part"),
438-
messageID: assistantMessage.id,
439-
sessionID: assistantMessage.sessionID,
440-
}))
441430
await Session.updatePart({
442431
...part,
443432
state: {
@@ -446,7 +435,7 @@ export namespace SessionPrompt {
446435
title: result.title,
447436
metadata: result.metadata,
448437
output: result.output,
449-
attachments,
438+
attachments: result.attachments,
450439
time: {
451440
...part.state.time,
452441
end: Date.now(),
@@ -785,13 +774,16 @@ export namespace SessionPrompt {
785774
)
786775

787776
const textParts: string[] = []
788-
const attachments: Omit<MessageV2.FilePart, "id" | "messageID" | "sessionID">[] = []
777+
const attachments: MessageV2.FilePart[] = []
789778

790779
for (const contentItem of result.content) {
791780
if (contentItem.type === "text") {
792781
textParts.push(contentItem.text)
793782
} else if (contentItem.type === "image") {
794783
attachments.push({
784+
id: Identifier.ascending("part"),
785+
sessionID: input.session.id,
786+
messageID: input.processor.message.id,
795787
type: "file",
796788
mime: contentItem.mimeType,
797789
url: `data:${contentItem.mimeType};base64,${contentItem.data}`,
@@ -803,6 +795,9 @@ export namespace SessionPrompt {
803795
}
804796
if (resource.blob) {
805797
attachments.push({
798+
id: Identifier.ascending("part"),
799+
sessionID: input.session.id,
800+
messageID: input.processor.message.id,
806801
type: "file",
807802
mime: resource.mimeType ?? "application/octet-stream",
808803
url: `data:${resource.mimeType ?? "application/octet-stream"};base64,${resource.blob}`,
@@ -1051,7 +1046,6 @@ export namespace SessionPrompt {
10511046
pieces.push(
10521047
...result.attachments.map((attachment) => ({
10531048
...attachment,
1054-
id: Identifier.ascending("part"),
10551049
synthetic: true,
10561050
filename: attachment.filename ?? part.filename,
10571051
messageID: info.id,
@@ -1189,18 +1183,7 @@ export namespace SessionPrompt {
11891183
},
11901184
]
11911185
}),
1192-
)
1193-
.then((x) => x.flat())
1194-
.then((drafts) =>
1195-
drafts.map(
1196-
(part): MessageV2.Part => ({
1197-
...part,
1198-
id: Identifier.ascending("part"),
1199-
messageID: info.id,
1200-
sessionID: input.sessionID,
1201-
}),
1202-
),
1203-
)
1186+
).then((x) => x.flat())
12041187

12051188
await Plugin.trigger(
12061189
"chat.message",

packages/opencode/src/tool/batch.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ export const BatchTool = Tool.define("batch", async () => {
7777
})
7878

7979
const result = await tool.execute(validatedParams, { ...ctx, callID: partID })
80-
const attachments = result.attachments?.map((attachment) => ({
81-
...attachment,
82-
id: Identifier.ascending("part"),
83-
messageID: ctx.messageID,
84-
sessionID: ctx.sessionID,
85-
}))
8680

8781
await Session.updatePart({
8882
id: partID,
@@ -97,7 +91,7 @@ export const BatchTool = Tool.define("batch", async () => {
9791
output: result.output,
9892
title: result.title,
9993
metadata: result.metadata,
100-
attachments,
94+
attachments: result.attachments,
10195
time: {
10296
start: callStartTime,
10397
end: Date.now(),

packages/opencode/src/tool/read.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { LSP } from "../lsp"
66
import { FileTime } from "../file/time"
77
import DESCRIPTION from "./read.txt"
88
import { Instance } from "../project/instance"
9+
import { Identifier } from "../id/id"
910
import { assertExternalDirectory } from "./external-directory"
1011
import { InstructionPrompt } from "../session/instruction"
1112

@@ -78,6 +79,9 @@ export const ReadTool = Tool.define("read", {
7879
},
7980
attachments: [
8081
{
82+
id: Identifier.ascending("part"),
83+
sessionID: ctx.sessionID,
84+
messageID: ctx.messageID,
8185
type: "file",
8286
mime,
8387
url: `data:${mime};base64,${Buffer.from(await file.bytes()).toString("base64")}`,

packages/opencode/src/tool/tool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export namespace Tool {
3636
title: string
3737
metadata: M
3838
output: string
39-
attachments?: Omit<MessageV2.FilePart, "id" | "sessionID" | "messageID">[]
39+
attachments?: MessageV2.FilePart[]
4040
}>
4141
formatValidationError?(error: z.ZodError): string
4242
}>

packages/opencode/test/session/prompt.test.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)