Skip to content

Commit 6cf8784

Browse files
committed
sync
1 parent 95d5e1f commit 6cf8784

6 files changed

Lines changed: 62 additions & 12 deletions

File tree

packages/opencode/src/session/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ export namespace Session {
552552
await updateMessage(next)
553553
return step
554554
},
555-
toolCallStreaming: true,
555+
toolCallStreaming: false,
556556
abortSignal: abort.signal,
557557
stopWhen: stepCountIs(1000),
558558
messages: convertToModelMessages(msgs),

packages/opencode/src/session/message.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,18 @@ export namespace Message {
147147
])
148148
.optional(),
149149
sessionID: z.string(),
150-
tool: z.record(z.string(), z.any()),
150+
tool: z.record(
151+
z.string(),
152+
z
153+
.object({
154+
title: z.string().optional(),
155+
time: z.object({
156+
start: z.number(),
157+
end: z.number(),
158+
}),
159+
})
160+
.catchall(z.any()),
161+
),
151162
assistant: z
152163
.object({
153164
modelID: z.string(),

packages/opencode/src/tool/bash.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const BashTool = Tool.define({
6464
stderr,
6565
stdout,
6666
description: params.description,
67+
title: params.command,
6768
},
6869
output: stdout.replaceAll(/\x1b\[[0-9;]*m/g, ""),
6970
}

packages/opencode/src/tool/edit.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { LSP } from "../lsp"
66
import { createTwoFilesPatch } from "diff"
77
import { Permission } from "../permission"
88
import DESCRIPTION from "./edit.txt"
9+
import { App } from "../app/app"
910

1011
export const EditTool = Tool.define({
1112
id: "opencode.edit",
@@ -28,9 +29,10 @@ export const EditTool = Tool.define({
2829
throw new Error("filePath is required")
2930
}
3031

32+
const app = App.info()
3133
const filepath = path.isAbsolute(params.filePath)
3234
? params.filePath
33-
: path.join(process.cwd(), params.filePath)
35+
: path.join(app.path.cwd, params.filePath)
3436

3537
await Permission.ask({
3638
id: "opencode.edit",
@@ -105,6 +107,7 @@ export const EditTool = Tool.define({
105107
metadata: {
106108
diagnostics,
107109
diff,
110+
title: `${path.relative(app.path.root, filepath)}`,
108111
},
109112
output,
110113
}

packages/opencode/src/tool/tool.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import type { StandardSchemaV1 } from "@standard-schema/spec"
22

33
export namespace Tool {
4+
interface Metadata {
5+
title: string
6+
[key: string]: any
7+
}
48
export type Context = {
59
sessionID: string
610
abort: AbortSignal
711
}
812
export interface Info<
913
Parameters extends StandardSchemaV1 = StandardSchemaV1,
10-
Metadata extends Record<string, any> = Record<string, any>,
14+
M extends Metadata = Metadata,
1115
> {
1216
id: string
1317
description: string
@@ -16,14 +20,14 @@ export namespace Tool {
1620
args: StandardSchemaV1.InferOutput<Parameters>,
1721
ctx: Context,
1822
): Promise<{
19-
metadata: Metadata
23+
metadata: M
2024
output: string
2125
}>
2226
}
2327

2428
export function define<
2529
Parameters extends StandardSchemaV1,
26-
Result extends Record<string, any>,
30+
Result extends Metadata,
2731
>(input: Info<Parameters, Result>): Info<Parameters, Result> {
2832
return input
2933
}

packages/opencode/src/tool/webfetch.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,57 @@ export const WebFetchTool = Tool.define({
7272
const content = new TextDecoder().decode(arrayBuffer)
7373
const contentType = response.headers.get("content-type") || ""
7474

75+
const title = `${params.url} (${contentType})`
7576
switch (params.format) {
7677
case "text":
7778
if (contentType.includes("text/html")) {
7879
const text = extractTextFromHTML(content)
79-
return { output: text, metadata: {} }
80+
return {
81+
output: text,
82+
metadata: {
83+
title,
84+
},
85+
}
86+
}
87+
return {
88+
output: content,
89+
metadata: {
90+
title,
91+
},
8092
}
81-
return { output: content, metadata: {} }
8293

8394
case "markdown":
8495
if (contentType.includes("text/html")) {
8596
const markdown = convertHTMLToMarkdown(content)
86-
return { output: markdown, metadata: {} }
97+
return {
98+
output: markdown,
99+
metadata: {
100+
title,
101+
},
102+
}
103+
}
104+
return {
105+
output: "```\n" + content + "\n```",
106+
metadata: {
107+
title,
108+
},
87109
}
88-
return { output: "```\n" + content + "\n```", metadata: {} }
89110

90111
case "html":
91-
return { output: content, metadata: {} }
112+
return {
113+
output: content,
114+
metadata: {
115+
title,
116+
},
117+
}
92118

93119
default:
94-
return { output: content, metadata: {} }
120+
return {
121+
output: content,
122+
metadata: {
123+
title,
124+
},
125+
}
95126
}
96127
},
97128
})

0 commit comments

Comments
 (0)