trae 0.1.13: a <tool_call> with only DeepSeek's closing tags after it says nothing, and one wrapping DeepSeek's own invoke is the call (magpie#823 again, Dazzle-sys: Trae CN's DeepSeek V4.1 Flash in Pi showed <tool_call> </|DSML|parameter> </|DSML|invoke> </ as its reply) — the reply (17 tokens out) was our opener with no JSON in it, then DeepSeek's closes, cut short. A <tool_call> was read only for a JSON object, so with none it was held to the end and handed on as text, which the agent showed and the model read back. A <tool_call> whose content starts with a tag (or is empty at the end) now has its opener dropped and what follows read as it is: an invoke in it is a call, stray tags are dropped, and a tag cut short at the end (</) after them too. A block holding plain text stays as it was. The new test fails on 0.1.12; bun test (36 pass) and bun scripts/check.mjs trae under a temp HOME pass. Not tried with a real Trae CN account (none here).

This commit is contained in:
yetone
2026-10-05 05:05:53 +08:00
parent c172d93901
commit 9d429b8663
3 changed files with 35 additions and 1 deletions
+15
View File
@@ -557,6 +557,11 @@ class TextTools {
const m = this.buf.match(LEFTOVER)
if (m) this.buf = this.buf.slice(m[0].length)
if (!this.buf || (!end && MARKS.some((k) => k.startsWith(this.buf)))) break
// a tag cut short at the end (</), after the others: dropped too
if (end && this.buf.length > 1 && MARKS.some((k) => k.startsWith(this.buf.trimEnd()))) {
this.buf = ""
break
}
this.after = false
}
const i = this.buf.indexOf(OPEN)
@@ -597,6 +602,16 @@ class TextTools {
continue
}
const o = objectEnd(this.buf, i + OPEN.length)
const inner = this.buf.slice(i + OPEN.length).trimStart()
if (inner.startsWith("<") || (end && !inner)) {
// no JSON in it: DeepSeek's own invoke, or only the closes of one
// (magpie#823 again); the opener is dropped and what follows read
// as it is
text += this.buf.slice(0, i)
this.buf = inner
this.after = true
continue
}
const v = o > 0 ? looseJSON(this.buf.slice(i + OPEN.length, o)) : null
if (v?.name) {
text += this.buf.slice(0, i)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-trae-auth",
"version": "0.1.12",
"version": "0.1.13",
"description": "OpenCode provider plugin for Trae CN (trae.cn): your Trae CN account's models, free tier included, with Trae's own browser sign-in",
"type": "module",
"main": "./index.mjs",
+19
View File
@@ -227,3 +227,22 @@ test("a block DeepSeek closes with its own tags, or writes as its own invoke, is
])
expect(c.at(-2).choices[0].finish_reason).toBe("tool_calls")
})
test("a <tool_call> with only DeepSeek's closing tags after it says nothing; one wrapping its invoke is the call (magpie#823 again)", () => {
// Dazzle-sys' pi screenshot: the whole reply, cut short
const junk = "<tool_call>\n</|DSML|parameter>\n</|DSML|invoke>\n</"
for (const cut of [5, 14, 30, junk.length]) {
const t = new _internal.TextTools()
const out = [t.push(junk.slice(0, cut)), t.push(junk.slice(cut)), t.push("", true)]
expect(out.map((o) => o.text).join("")).toBe("")
expect(out.flatMap((o) => o.calls)).toEqual([])
}
const wrapped = 'Looking.<tool_call>\n<|DSML|invoke name="bash">\n<|DSML|parameter name="command" string="true">ls</|DSML|parameter>\n</|DSML|invoke>\n</tool_call>'
const t = new _internal.TextTools()
const out = [t.push(wrapped.slice(0, 20)), t.push(wrapped.slice(20)), t.push("", true)]
expect(out.map((o) => o.text).join("")).toBe("Looking.")
expect(out.flatMap((o) => o.calls).map((c) => [c.name, JSON.parse(c.arguments)])).toEqual([["bash", { command: "ls" }]])
// a block that's text, not tags, stays as it was
const u = new _internal.TextTools()
expect([u.push("<tool_call>hello</tool_call> ok"), u.push("", true)].map((o) => o.text).join("")).toBe("<tool_call>hello</tool_call> ok")
})