Skip to content

Commit 01cd54f

Browse files
committed
feat(copilot): use xml tags
1 parent 4306140 commit 01cd54f

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

.opencode/plugin/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import { compose } from "../../packages/compose/dist/main"
22
import { forceAgent } from "../../packages/copilot/dist/main"
33
import { inspector } from "../../packages/inspector/dist/main"
44

5-
export const main = compose([forceAgent(), inspector()])
5+
export const main = compose([inspector(), forceAgent()])

packages/copilot/src/main.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ interface ForceAgentOptions {
55
}
66

77
const DEFAULT_SELF_MESSAGE: ForceAgentOptions["selfMessage"] = (original) =>
8-
`
9-
<query>
10-
${original}
11-
</query>
8+
`<query>${original}</query>
129
13-
I will now answer the query
14-
`.trim()
10+
I will now answer the query:
11+
12+
13+
`
1514

1615
export const forceAgent = (options: ForceAgentOptions = {}): Plugin => {
1716
const selfMessage = options.selfMessage ?? DEFAULT_SELF_MESSAGE
@@ -62,10 +61,27 @@ export const forceAgent = (options: ForceAgentOptions = {}): Plugin => {
6261
}
6362

6463
output.message.role = "assistant"
65-
const textPart = output.parts.find((part) => part.type === "text")
6664

67-
if (!textPart) return
68-
textPart.text = selfMessage(textPart.text)
65+
const textParts = output.parts.filter((part) => part.type === "text")
66+
const nonTextParts = output.parts.filter((part) => part.type !== "text")
67+
68+
const newPart = textParts.at(0)
69+
if (!newPart) {
70+
await client.app.log({
71+
body: {
72+
level: "error",
73+
message: "Text part is not found",
74+
service: "copilot-force-agent",
75+
},
76+
})
77+
throw new Error("Text part is not found")
78+
}
79+
80+
newPart.text = selfMessage(
81+
textParts.map((part) => part.text).join("\n"),
82+
)
83+
84+
output.parts = [newPart, ...nonTextParts]
6985
},
7086
}
7187
}

0 commit comments

Comments
 (0)