claude-sdk-proxy 3.1.1 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/proxy/server.ts +17 -1
package/package.json
CHANGED
package/src/proxy/server.ts
CHANGED
|
@@ -221,7 +221,23 @@ function parseToolUse(text: string): { toolCalls: ToolCall[]; textBefore: string
|
|
|
221
221
|
while ((m = xmlRegex.exec(text)) !== null) {
|
|
222
222
|
if (firstIdx < 0) firstIdx = m.index
|
|
223
223
|
try {
|
|
224
|
-
const
|
|
224
|
+
const raw = m[1]!.trim()
|
|
225
|
+
let p: any
|
|
226
|
+
try { p = JSON.parse(raw) } catch {
|
|
227
|
+
// Repair: models often emit raw newlines in heredocs/multiline commands
|
|
228
|
+
// which are invalid inside JSON strings. Escape them only inside quoted values.
|
|
229
|
+
let fixed = "", inStr = false, esc = false
|
|
230
|
+
for (const ch of raw) {
|
|
231
|
+
if (esc) { fixed += ch; esc = false; continue }
|
|
232
|
+
if (ch === "\\") { esc = true; fixed += ch; continue }
|
|
233
|
+
if (ch === '"') { inStr = !inStr; fixed += ch; continue }
|
|
234
|
+
if (inStr && ch === "\n") { fixed += "\\n"; continue }
|
|
235
|
+
if (inStr && ch === "\r") { fixed += "\\r"; continue }
|
|
236
|
+
if (inStr && ch === "\t") { fixed += "\\t"; continue }
|
|
237
|
+
fixed += ch
|
|
238
|
+
}
|
|
239
|
+
p = JSON.parse(fixed)
|
|
240
|
+
}
|
|
225
241
|
calls.push({
|
|
226
242
|
id: generateId("toolu_"),
|
|
227
243
|
name: String(p.name ?? ""),
|