Add OpenCode Go as a cleanup and agent provider

OpenCode Go serves open coding models from an OpenAI-compatible endpoint. It cannot transcribe, so it joins
the two LLM jobs: transcript cleanup and the plain-chat agent. The key
falls back to OPENCODE_API_KEY, and api.chat() stops hardcoding the
OpenRouter name so the same call serves both.
This commit is contained in:
sudoeren
2026-08-25 21:05:18 +03:00
parent 3663c7fd57
commit 0a6c6128a2
6 changed files with 124 additions and 29 deletions
+39
View File
@@ -59,6 +59,7 @@ class Provider(DikteTest):
self.assertEqual(assistant.executable("claude"), "claude")
self.assertEqual(assistant.executable("codex"), "codex")
self.assertEqual(assistant.executable("openrouter"), "")
self.assertEqual(assistant.executable("opencode"), "")
def test_what_each_one_is_called(self):
self.assertEqual(assistant.display_name(self.config()), "Claude")
@@ -67,6 +68,9 @@ class Provider(DikteTest):
self.assertEqual(
assistant.display_name(self.config(assistant_provider="openrouter")),
"OpenRouter")
self.assertEqual(
assistant.display_name(self.config(assistant_provider="opencode")),
"OpenCode Go")
class Effort(unittest.TestCase):
@@ -507,6 +511,41 @@ class AskOpenRouter(DikteTest):
assistant.ask("when is it", conf)
class AskOpenCode(DikteTest):
def test_a_question_and_an_answer(self):
conf = self.config(assistant_provider="opencode",
opencode_api_key="opencode-test-key")
with fake_urlopen({"choices": [{"message": {"content": "on Thursday"}}]}):
answer, warning = assistant.ask("when is it", conf)
self.assertEqual(answer, "on Thursday")
self.assertEqual(warning, "")
def test_the_conversation_is_ours_to_keep(self):
conf = self.config(assistant_provider="opencode",
opencode_api_key="opencode-test-key")
with fake_urlopen({"choices": [{"message": {"content": "on Thursday"}}]}):
assistant.ask("when is it", conf)
stored = assistant.read_messages("opencode", 1800)
self.assertEqual([row["content"] for row in stored],
["when is it", "on Thursday"])
def test_the_model_and_endpoint_are_opencode_s_own(self):
conf = self.config(assistant_provider="opencode",
opencode_api_key="opencode-test-key",
assistant_opencode_model="glm-5.3")
with fake_urlopen({"choices": [{"message": {"content": "on Thursday"}}]}) as calls:
assistant.ask("when is it", conf)
sent = json.loads(calls[0].data.decode("utf-8"))
self.assertEqual(sent["model"], "glm-5.3")
self.assertIn("https://opencode.ai/zen/go/v1/chat/completions",
calls[0].full_url)
def test_an_api_failure_reads_as_an_assistant_failure(self):
conf = self.config(assistant_provider="opencode")
with self.assertRaises(assistant.AssistantError):
assistant.ask("when is it", conf)
class Ask(DikteTest):
def test_a_cli_that_is_not_installed_says_where_to_change_it(self):
with only_these_tools(), \