headroom-opencode 0.40.0 → 0.42.0

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/README.md CHANGED
@@ -35,32 +35,36 @@ The generated provider uses `@ai-sdk/openai-compatible` and points model request
35
35
 
36
36
  ## Native OpenCode Plugin
37
37
 
38
- Use `HeadroomPlugin` when OpenCode should intercept provider traffic in-process and expose Headroom tooling from a plugin.
38
+ The package's default export is an OpenCode plugin that loads on both OpenCode 1.x and 2.x. Register it in `opencode.json`:
39
39
 
40
- ```ts
41
- import { HeadroomPlugin } from "headroom-opencode";
42
-
43
- export default async function plugin(input) {
44
- return HeadroomPlugin(input, {
45
- proxyUrl: process.env.HEADROOM_PROXY_URL ?? "http://127.0.0.1:8787",
46
- });
40
+ ```json
41
+ {
42
+ "plugin": [
43
+ ["headroom-opencode", { "proxyUrl": "http://127.0.0.1:8787" }]
44
+ ]
47
45
  }
48
46
  ```
49
47
 
50
- `HeadroomPlugin`:
48
+ OpenCode 2.x migrates the 1.x `plugin` key automatically. To configure it the 2.x way, use `"plugins": [{ "package": "headroom-opencode", "options": { ... } }]`.
49
+
50
+ The default export is `{ id: "headroom", server, setup }`. OpenCode 1.x calls `server` (`HeadroomPlugin`) and 2.x calls `setup` (`headroomSetup`); each ignores the other's field. Both entry points:
51
+
52
+ - install Headroom transport interception for OpenCode provider traffic.
53
+ - expose the `headroom_retrieve` tool (a direct tool on 2.x, not only through code mode).
54
+ - add `HEADROOM_ACTIVE`, `HEADROOM_PROXY_URL`, `HEADROOM_PROJECT` (and `HEADROOM_BACKEND` when set) to shell command environments.
55
+ - default to `HEADROOM_PROXY_URL`, then `http://127.0.0.1:8787`, when no `proxyUrl` option is supplied.
56
+ - skip routing for hosts listed in `excludeHosts` (or `HEADROOM_OPENCODE_EXCLUDE_HOSTS`); those requests go straight upstream with no compression or telemetry.
57
+
58
+ On 2.x, setup returns a cleanup that releases the transport, so hot reloads do not stack interceptors.
51
59
 
52
- - installs Headroom transport interception for OpenCode provider traffic.
53
- - exposes the `headroom_retrieve` tool.
54
- - publishes `HEADROOM_PROXY_URL` in the plugin output env.
55
- - defaults to `http://127.0.0.1:8787` when no proxy URL is supplied.
56
- - skips routing for hosts listed in `excludeHosts` (or `HEADROOM_OPENCODE_EXCLUDE_HOSTS`); those requests go straight upstream with no compression or telemetry.
60
+ OpenCode 2.x keeps its own reference to `fetch` from before plugins load, so patching `fetch` alone does not catch its model traffic. On 2.x the plugin also rewrites each remote model that uses the OpenAI chat-completions or responses format so that it points at the proxy. Headers name the real upstream, as the transport does. Models on other formats (Anthropic messages, Google) are left alone. `headroom wrap opencode` routes native Anthropic and OpenAI through the proxy separately, via their `baseURL`.
57
61
 
58
62
  To keep a provider off the proxy, list its host. An entry matches the host and all of its subdomains, and `.example.com` / `*.example.com` are accepted as spellings of `example.com`:
59
63
 
60
64
  ```jsonc
61
65
  // opencode.json
62
66
  {
63
- "plugin": [["/path/to/headroom/providers/opencode/_dist/entry.opencode.js", { "excludeHosts": ["opencode.ai"] }]]
67
+ "plugin": [["/path/to/headroom/providers/opencode/_dist", { "excludeHosts": ["opencode.ai"] }]]
64
68
  }
65
69
  ```
66
70