@darthph0enix/commandcode-go-opencode-provider 0.7.0 → 0.7.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.
Files changed (2) hide show
  1. package/package.json +10 -3
  2. package/src/convert.ts +49 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darthph0enix/commandcode-go-opencode-provider",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "author": "Brent Weatherall",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,8 +24,15 @@
24
24
  "url": "https://github.com/Darthph0enix7/opencode-commandcode-provider/issues"
25
25
  },
26
26
  "description": "Command Code API provider for opencode — use Claude, GPT, Gemini, DeepSeek, Qwen, Kimi, GLM, MiniMax, and Step models via Command Code",
27
- "engines": { "bun": ">=1.0.0" },
28
- "files": ["index.ts", "plugin.ts", "models.json", "src/"],
27
+ "engines": {
28
+ "bun": ">=1.0.0"
29
+ },
30
+ "files": [
31
+ "index.ts",
32
+ "plugin.ts",
33
+ "models.json",
34
+ "src/"
35
+ ],
29
36
  "homepage": "https://github.com/Darthph0enix7/opencode-commandcode-provider#readme",
30
37
  "keywords": [
31
38
  "opencode",
package/src/convert.ts CHANGED
@@ -560,6 +560,54 @@ function modelAcceptsImageInput(modelId: string): boolean {
560
560
  return hit ?? true
561
561
  }
562
562
 
563
+
564
+ /**
565
+ * Every tool call must be answered by a tool result in the transcript that
566
+ * reaches the API. Hosts (and context managers that strip bulky tool output)
567
+ * can remove the result while leaving the call, which an Anthropic-shaped API
568
+ * rejects with:
569
+ *
570
+ * "Tool results are missing for tool calls toolu_…"
571
+ *
572
+ * A missing pair is not recoverable from the arguments, so the call is answered
573
+ * with an explicit "result removed" text. That keeps the transcript valid
574
+ * everywhere while telling the model the truth: the output is gone, re-run the
575
+ * tool if you still need it. Empty tool messages are dropped.
576
+ */
577
+ function pairToolResults(messages: CCMessage[]): CCMessage[] {
578
+ const answered = new Set<string>()
579
+ for (const message of messages) {
580
+ if (message.role !== "tool") continue
581
+ for (const part of message.content) answered.add(part.toolCallId)
582
+ }
583
+
584
+ const paired: CCMessage[] = []
585
+ for (const message of messages) {
586
+ if (message.role === "tool" && message.content.length === 0) continue
587
+ paired.push(message)
588
+ if (message.role !== "assistant") continue
589
+ const unanswered = message.content.filter(
590
+ (part): part is Extract<CCAssistantContent, { type: "tool-call" }> =>
591
+ part.type === "tool-call" && !answered.has(part.toolCallId),
592
+ )
593
+ if (unanswered.length === 0) continue
594
+ paired.push({
595
+ role: "tool",
596
+ content: unanswered.map((call) => ({
597
+ type: "tool-result" as const,
598
+ toolCallId: call.toolCallId,
599
+ toolName: call.toolName,
600
+ output: {
601
+ type: "text" as const,
602
+ value:
603
+ "[tool result unavailable — it was removed from this conversation to keep the request within the context window. Re-run the tool if you still need the output.]",
604
+ },
605
+ })),
606
+ })
607
+ }
608
+ return paired
609
+ }
610
+
563
611
  export function buildRequest(
564
612
  modelId: string,
565
613
  options: LanguageModelV3CallOptions,
@@ -614,7 +662,7 @@ export function buildRequest(
614
662
 
615
663
  const params: CCRequestEnvelope["params"] = {
616
664
  model: modelId,
617
- messages,
665
+ messages: pairToolResults(messages),
618
666
  tools: convertTools(options.tools),
619
667
  system: systemPrompt,
620
668
  max_tokens: options.maxOutputTokens ?? 16384,