opencode-translate 1.0.7 → 2.0.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 (4) hide show
  1. package/README.md +94 -6
  2. package/dist/index.js +639 -2026
  3. package/index.d.ts +2 -2
  4. package/package.json +6 -13
package/README.md CHANGED
@@ -22,6 +22,10 @@ This plugin lets you write in your language while the model works in English —
22
22
 
23
23
  ## Install
24
24
 
25
+ Version 2 of this plugin uses OpenCode's **v2 public plugin API**. The verified release is OpenCode **2.0.3**.
26
+ For OpenCode v1, use `opencode-translate@1`.
27
+ Start a fresh v2 session when upgrading: v1 activation metadata and historical bilingual trailers are not migrated.
28
+
25
29
  ```bash
26
30
  bun add -g opencode-translate
27
31
  ```
@@ -32,16 +36,23 @@ Add to `~/.config/opencode/opencode.jsonc`:
32
36
 
33
37
  ```jsonc
34
38
  {
35
- "plugin": [
36
- ["opencode-translate", {
37
- "model": "openai/gpt-5.4-mini", // model to use for translation
38
- "variant": "minimal", // optional model variant / thinking effort
39
- "lang": "Korean" // language you speak
40
- }]
39
+ "$schema": "https://opencode.ai/config.json",
40
+ "plugins": [
41
+ {
42
+ "package": "opencode-translate",
43
+ "options": {
44
+ "model": "openai/gpt-5.4-mini", // model to use for translation
45
+ "variant": "minimal", // optional model variant / thinking effort
46
+ "lang": "Korean" // language you speak
47
+ }
48
+ }
41
49
  ]
42
50
  }
43
51
  ```
44
52
 
53
+ Quit and restart OpenCode after changing the plugin configuration. For a local build, run `bun install && bun run build`
54
+ and set `package` to the absolute **directory** `/path/to/opencode-translate/dist`.
55
+
45
56
  ## Usage
46
57
 
47
58
  Prefix any message with `$en` to activate translation for that session.
@@ -52,6 +63,83 @@ $en 프로젝트 루트의 package.json을 읽고 요약해줘
52
63
 
53
64
  All subsequent messages in the same session are translated automatically — no need to repeat `$en`.
54
65
 
66
+ - Your original message and its English translation remain visible in the transcript.
67
+ - The first successful `$en` prompt includes a `Translation enabled:` confirmation with the language and translator model.
68
+ - English assistant text streams normally; a translated Markdown section is appended when the text segment completes.
69
+ - Both the **terminal and web UI** display the same persisted bilingual assistant text. No UI-specific plugin is needed.
70
+ - Question forms are translated, with selected labels and custom answers converted back to English for the model.
71
+ - Translation activates only in root sessions. Its state survives plugin/server restarts.
72
+
73
+ Before model requests, the plugin removes its recorded display translations from context. It does not remove arbitrary
74
+ Markdown based on its appearance. On inbound translation failure, the transcript shows `Translation failed:` and the
75
+ error reason. The main model receives the original text without `$en` or the diagnostic; failed first-time activation
76
+ remains inactive, so retry with `$en` after fixing the error. On outbound failure, the English response is retained with
77
+ a translation-unavailable notice.
78
+
79
+ ### If `$en` has no effect
80
+
81
+ `$en` is a plugin control keyword, not an instruction for the main model. If the model comments on `$en`, inbound
82
+ translation did not complete. In version 2.0.0, an inbound failure was only logged on the server and left `$en` in the
83
+ prompt, making it indistinguishable from an unloaded plugin in the transcript.
84
+
85
+ Check the active server's plugin list and configuration, including the selected project location. It must load the v2
86
+ package, not an old pinned `opencode-translate@1.x`. Also check the configured **translation** model and variant; changing
87
+ the main-chat model does not change the translator. An API-key login or OAuth connection must exist on that server.
88
+ The server log message `[opencode-translate] inbound translation failed` contains the underlying generation error.
89
+
90
+ ## Authentication
91
+
92
+ Connect the translation model's provider in **OpenCode itself**. Translation uses the public `ctx.generate.text()` API,
93
+ so OpenCode owns provider selection, model variants, API keys, SQLite credentials, and OAuth refresh/persistence.
94
+ The plugin does not read `auth.json`/`auth-v2.json`, query the credential database, or maintain separate tokens.
95
+ Provider and OAuth support for the translation model is the support available in your OpenCode installation.
96
+
97
+ ## Inline reply support
98
+
99
+ V2 has no `experimental.text.complete` hook or public display-only message append operation. Inline translations use
100
+ `session.hook("http.response", ...)` with adapters for these **main-chat response protocols**:
101
+
102
+ | Protocol | Recognized endpoint | Support |
103
+ | --- | --- | --- |
104
+ | OpenAI Responses, including Codex | `…/responses` | SSE text deltas and final snapshots |
105
+ | OpenAI Chat Completions and compatible providers | `…/chat/completions` | SSE text choices |
106
+ | Anthropic Messages | `…/messages` | SSE text blocks |
107
+ | Gemini / Vertex Gemini | `…:streamGenerateContent` | SSE non-thinking text |
108
+
109
+ Unknown endpoints, non-SSE responses, and binary protocols such as Bedrock Converse pass through unchanged with a server
110
+ log message. They still support inbound/question translation when the translation model is available through OpenCode.
111
+ Reasoning, tool calls, images, and other non-text outputs are not translated.
112
+
113
+ **Transport:** OpenCode routes sessions through HTTP when HTTP hooks are registered. Loading this plugin therefore
114
+ disables the session WebSocket fast path in its location, including sessions that have not activated `$en`.
115
+ Translations add latency at text-completion boundaries and use additional model requests. Their usage is separate from
116
+ the primary model's reported token counts.
117
+
118
+ ## Development and verification
119
+
120
+ ```sh
121
+ bun install
122
+ bun run check:ci
123
+ bun run typecheck
124
+ bun run knip
125
+ bun test
126
+ bun run build
127
+ bun run test:package
128
+
129
+ # Requires Node 24 and an OpenCode v2 binary; uses an isolated server and fake provider.
130
+ OPENCODE_BINARY=/path/to/opencode bun run test:host
131
+
132
+ # Exercise a registry-installed package through OpenCode's actual package loader.
133
+ OPENCODE_BINARY=/path/to/opencode OPENCODE_TRANSLATE_PACKAGE=opencode-translate@latest bun run test:host
134
+ ```
135
+
136
+ Tests include OpenCode's actual native protocol parsers. The real-host smoke test loads the built plugin, creates and
137
+ rotates a test credential in an isolated SQLite database, checks bilingual persisted messages and English-only model
138
+ requests, and restarts the server to verify recovery. It does not use your live server, credentials, or paid models.
139
+
140
+ The old `opencode2 v0.0.0-dev-18322` binary does not pass this migration's host smoke test. Use the verified 2.0.3 release
141
+ rather than assuming that any binary named `opencode2` exposes the current plugin API.
142
+
55
143
  ## Options
56
144
 
57
145
  | Option | Type | Default | Description |