opencode-claude-max-proxy 1.11.0 → 1.11.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 +51 -35
package/package.json
CHANGED
package/src/proxy/server.ts
CHANGED
|
@@ -454,44 +454,59 @@ export function createProxyServer(config: Partial<ProxyConfig> = {}) {
|
|
|
454
454
|
|
|
455
455
|
if (hasMultimodal) {
|
|
456
456
|
// Structured messages preserve image/document/file blocks for Claude to see.
|
|
457
|
-
//
|
|
458
|
-
//
|
|
459
|
-
const structured
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
457
|
+
// On resume, only send user messages (SDK has assistant context already).
|
|
458
|
+
// On first request, include everything.
|
|
459
|
+
const structured: Array<{ type: "user"; message: { role: string; content: any }; parent_tool_use_id: null }> = []
|
|
460
|
+
|
|
461
|
+
if (isResume) {
|
|
462
|
+
// Resume: only send user messages from the delta (SDK has the rest)
|
|
463
|
+
for (const m of messagesToConvert) {
|
|
464
|
+
if (m.role === "user") {
|
|
465
|
+
structured.push({
|
|
466
|
+
type: "user" as const,
|
|
467
|
+
message: { role: "user" as const, content: stripCacheControl(m.content) },
|
|
468
|
+
parent_tool_use_id: null,
|
|
469
|
+
})
|
|
465
470
|
}
|
|
466
471
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
if (
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
if (b.type === "tool_result") return `[Tool Result: ${typeof b.content === "string" ? b.content : JSON.stringify(b.content)}]`
|
|
476
|
-
return ""
|
|
477
|
-
}).filter(Boolean).join("\n")
|
|
478
|
-
} else {
|
|
479
|
-
text = `[Assistant: ${String(m.content)}]`
|
|
472
|
+
} else {
|
|
473
|
+
// First request: include system context + all messages
|
|
474
|
+
if (systemContext) {
|
|
475
|
+
structured.push({
|
|
476
|
+
type: "user" as const,
|
|
477
|
+
message: { role: "user", content: systemContext },
|
|
478
|
+
parent_tool_use_id: null,
|
|
479
|
+
})
|
|
480
480
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
481
|
+
for (const m of messagesToConvert) {
|
|
482
|
+
if (m.role === "user") {
|
|
483
|
+
structured.push({
|
|
484
|
+
type: "user" as const,
|
|
485
|
+
message: { role: "user" as const, content: stripCacheControl(m.content) },
|
|
486
|
+
parent_tool_use_id: null,
|
|
487
|
+
})
|
|
488
|
+
} else {
|
|
489
|
+
// Convert assistant messages to text summaries
|
|
490
|
+
let text: string
|
|
491
|
+
if (typeof m.content === "string") {
|
|
492
|
+
text = `[Assistant: ${m.content}]`
|
|
493
|
+
} else if (Array.isArray(m.content)) {
|
|
494
|
+
text = m.content.map((b: any) => {
|
|
495
|
+
if (b.type === "text" && b.text) return `[Assistant: ${b.text}]`
|
|
496
|
+
if (b.type === "tool_use") return `[Tool Use: ${b.name}(${JSON.stringify(b.input)})]`
|
|
497
|
+
if (b.type === "tool_result") return `[Tool Result: ${typeof b.content === "string" ? b.content : JSON.stringify(b.content)}]`
|
|
498
|
+
return ""
|
|
499
|
+
}).filter(Boolean).join("\n")
|
|
500
|
+
} else {
|
|
501
|
+
text = `[Assistant: ${String(m.content)}]`
|
|
502
|
+
}
|
|
503
|
+
structured.push({
|
|
504
|
+
type: "user" as const,
|
|
505
|
+
message: { role: "user" as const, content: text },
|
|
506
|
+
parent_tool_use_id: null,
|
|
507
|
+
})
|
|
508
|
+
}
|
|
485
509
|
}
|
|
486
|
-
})
|
|
487
|
-
|
|
488
|
-
// Prepend system context as a text message
|
|
489
|
-
if (systemContext) {
|
|
490
|
-
structured.unshift({
|
|
491
|
-
type: "user" as const,
|
|
492
|
-
message: { role: "user", content: systemContext },
|
|
493
|
-
parent_tool_use_id: null,
|
|
494
|
-
})
|
|
495
510
|
}
|
|
496
511
|
|
|
497
512
|
prompt = (async function* () { for (const msg of structured) yield msg })()
|
|
@@ -523,7 +538,8 @@ export function createProxyServer(config: Partial<ProxyConfig> = {}) {
|
|
|
523
538
|
})
|
|
524
539
|
.join("\n\n") || ""
|
|
525
540
|
|
|
526
|
-
|
|
541
|
+
// On resume, skip system context (SDK already has it)
|
|
542
|
+
prompt = (!isResume && systemContext)
|
|
527
543
|
? `${systemContext}\n\n${conversationParts}`
|
|
528
544
|
: conversationParts
|
|
529
545
|
}
|