From 9d429b866395e66a29e18c1b1aa6bb0a05e90ed5 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 5 Oct 2026 05:05:53 +0800 Subject: [PATCH] =?UTF-8?q?trae=200.1.13:=20a=20=20with=20onl?= =?UTF-8?q?y=20DeepSeek's=20closing=20tags=20after=20it=20says=20nothing,?= =?UTF-8?q?=20and=20one=20wrapping=20DeepSeek's=20own=20invoke=20is=20the?= =?UTF-8?q?=20call=20(magpie#823=20again,=20Dazzle-sys:=20Trae=20CN's=20De?= =?UTF-8?q?epSeek=20V4.1=20Flash=20in=20Pi=20showed=20=20=20=20=20was=20read=20only=20for=20a=20JSON=20object,=20so=20with?= =?UTF-8?q?=20none=20it=20was=20held=20to=20the=20end=20and=20handed=20on?= =?UTF-8?q?=20as=20text,=20which=20the=20agent=20showed=20and=20the=20mode?= =?UTF-8?q?l=20read=20back.=20A=20=20whose=20content=20starts?= =?UTF-8?q?=20with=20a=20tag=20(or=20is=20empty=20at=20the=20end)=20now=20?= =?UTF-8?q?has=20its=20opener=20dropped=20and=20what=20follows=20read=20as?= =?UTF-8?q?=20it=20is:=20an=20invoke=20in=20it=20is=20a=20call,=20stray=20?= =?UTF-8?q?tags=20are=20dropped,=20and=20a=20tag=20cut=20short=20at=20the?= =?UTF-8?q?=20end=20( k.startsWith(this.buf)))) break + // a tag cut short at the end ( 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) diff --git a/packages/trae/package.json b/packages/trae/package.json index f40f2ee..d72d719 100644 --- a/packages/trae/package.json +++ b/packages/trae/package.json @@ -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", diff --git a/packages/trae/request.test.mjs b/packages/trae/request.test.mjs index 76244a6..2ffd2b4 100644 --- a/packages/trae/request.test.mjs +++ b/packages/trae/request.test.mjs @@ -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 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 = "\n\n\n o.text).join("")).toBe("") + expect(out.flatMap((o) => o.calls)).toEqual([]) + } + const wrapped = 'Looking.\n<|DSML|invoke name="bash">\n<|DSML|parameter name="command" string="true">ls\n\n' + 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("hello ok"), u.push("", true)].map((o) => o.text).join("")).toBe("hello ok") +})