opencode-claude-max-proxy 1.11.0 → 1.11.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/proxy/server.ts +51 -35
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-claude-max-proxy",
3
- "version": "1.11.0",
3
+ "version": "1.11.1",
4
4
  "description": "Use your Claude Max subscription with OpenCode via proxy server",
5
5
  "type": "module",
6
6
  "main": "./src/proxy/server.ts",
@@ -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
- // The SDK only accepts role:"user" in SDKUserMessage, so assistant messages
458
- // are converted to text summaries wrapped as user messages.
459
- const structured = messagesToConvert.map((m: any) => {
460
- if (m.role === "user") {
461
- return {
462
- type: "user" as const,
463
- message: { role: "user" as const, content: stripCacheControl(m.content) },
464
- parent_tool_use_id: null,
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
- // Convert assistant/tool messages to text summary
468
- let text: string
469
- if (typeof m.content === "string") {
470
- text = `[Assistant: ${m.content}]`
471
- } else if (Array.isArray(m.content)) {
472
- text = m.content.map((b: any) => {
473
- if (b.type === "text" && b.text) return `[Assistant: ${b.text}]`
474
- if (b.type === "tool_use") return `[Tool Use: ${b.name}(${JSON.stringify(b.input)})]`
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
- return {
482
- type: "user" as const,
483
- message: { role: "user" as const, content: text },
484
- parent_tool_use_id: null,
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
- prompt = systemContext
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
  }