mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
fix: reduce overhead of task tool metadata
This commit is contained in:
parent
6a4ca92a6c
commit
3e36069f41
2 changed files with 25 additions and 9 deletions
|
|
@ -1522,7 +1522,7 @@ ToolRegistry.register<typeof TaskTool>({
|
|||
<box>
|
||||
<For each={props.metadata.summary ?? []}>
|
||||
{(task) => (
|
||||
<text style={{ fg: theme.textMuted }}>
|
||||
<text style={{ fg: task.state.status === "error" ? theme.error : theme.textMuted }}>
|
||||
∟ {Locale.titlecase(task.tool)} {task.state.status === "completed" ? task.state.title : ""}
|
||||
</text>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -52,16 +52,24 @@ export const TaskTool = Tool.define("task", async () => {
|
|||
})
|
||||
|
||||
const messageID = Identifier.ascending("message")
|
||||
const parts: Record<string, MessageV2.ToolPart> = {}
|
||||
const parts: Record<string, { id: string; tool: string; state: { status: string; title?: string } }> = {}
|
||||
const unsub = Bus.subscribe(MessageV2.Event.PartUpdated, async (evt) => {
|
||||
if (evt.properties.part.sessionID !== session.id) return
|
||||
if (evt.properties.part.messageID === messageID) return
|
||||
if (evt.properties.part.type !== "tool") return
|
||||
parts[evt.properties.part.id] = evt.properties.part
|
||||
const part = evt.properties.part
|
||||
parts[part.id] = {
|
||||
id: part.id,
|
||||
tool: part.tool,
|
||||
state: {
|
||||
status: part.state.status,
|
||||
title: part.state.status === "completed" ? part.state.title : undefined,
|
||||
},
|
||||
}
|
||||
ctx.metadata({
|
||||
title: params.description,
|
||||
metadata: {
|
||||
summary: Object.values(parts).sort((a, b) => a.id?.localeCompare(b.id)),
|
||||
summary: Object.values(parts).sort((a, b) => a.id.localeCompare(b.id)),
|
||||
sessionId: session.id,
|
||||
},
|
||||
})
|
||||
|
|
@ -98,10 +106,18 @@ export const TaskTool = Tool.define("task", async () => {
|
|||
parts: promptParts,
|
||||
})
|
||||
unsub()
|
||||
let all
|
||||
all = await Session.messages({ sessionID: session.id })
|
||||
all = all.filter((x) => x.info.role === "assistant")
|
||||
all = all.flatMap((msg) => msg.parts.filter((x: any) => x.type === "tool") as MessageV2.ToolPart[])
|
||||
const messages = await Session.messages({ sessionID: session.id })
|
||||
const summary = messages
|
||||
.filter((x) => x.info.role === "assistant")
|
||||
.flatMap((msg) => msg.parts.filter((x: any) => x.type === "tool") as MessageV2.ToolPart[])
|
||||
.map((part) => ({
|
||||
id: part.id,
|
||||
tool: part.tool,
|
||||
state: {
|
||||
status: part.state.status,
|
||||
title: part.state.status === "completed" ? part.state.title : undefined,
|
||||
},
|
||||
}))
|
||||
const text = result.parts.findLast((x) => x.type === "text")?.text ?? ""
|
||||
|
||||
const output = text + "\n\n" + ["<task_metadata>", `session_id: ${session.id}`, "</task_metadata>"].join("\n")
|
||||
|
|
@ -109,7 +125,7 @@ export const TaskTool = Tool.define("task", async () => {
|
|||
return {
|
||||
title: params.description,
|
||||
metadata: {
|
||||
summary: all,
|
||||
summary,
|
||||
sessionId: session.id,
|
||||
},
|
||||
output,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue