opencode-with-claude 1.2.0 → 1.3.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/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function d(
|
|
1
|
+
function d(o){return(a,t)=>o.app.log({body:{service:"opencode-with-claude",level:a,message:t}})}import{startProxyServer as y}from"opencode-claude-max-proxy";var f=process.platform==="win32",m=3456,x=/authenticat|credentials|expired|not logged in|exit(?:ed)? with code|crash|unhealthy|401|402|billing|subscription/i,P=/rate.limit|429|overloaded|503|stale.session|timeout|timed out/i;function w(o){return x.test(o)?"error":P.test(o)?"warn":"debug"}async function g(o){let{port:a=m,log:t}=o,e=console.error;console.error=(...r)=>{let n=r.map(String).join(" ");if(n.startsWith("[PROXY]")){t(w(n),n);return}e.apply(console,r)};let i=async r=>{try{return await y({port:r,host:"127.0.0.1",silent:!0})}catch(n){if(r!==0&&n instanceof Error&&"code"in n&&n.code==="EADDRINUSE")return await t("info",`Port ${r} in use, starting on a random port instead...`),y({port:0,host:"127.0.0.1",silent:!0});throw n}},s;try{s=await i(a)}catch(r){throw console.error=e,r}let c=s.server.address().port;return await t("info",`Claude Max proxy running on port ${c}`),{port:c,close:async()=>{console.error=e,await s.close()}}}async function p(o,a){try{let t=await fetch(`http://127.0.0.1:${o}/health`,{signal:AbortSignal.timeout(5e3)}),e=await t.json();if(e.status==="healthy")return{ok:!0};if(e.status==="degraded"){let s=typeof e.error=="string"?e.error:"Could not verify auth status";return await a("warn",`[claude-max] ${s}. Requests may still work \u2014 if they hang, try running 'claude login' in your terminal.`),{ok:!0,message:s}}let i=typeof e.error=="string"?e.error:`Proxy health check returned status: ${e.status??t.status}`;return await a("error",`[claude-max] ${i}`),{ok:!1,message:i}}catch(t){let e=t instanceof Error?t.message:String(t);return await a("error",`[claude-max] Health check failed: ${e}`),{ok:!1,message:`Health check failed: ${e}`}}}function h(o){let a=!1,t=()=>{a||(a=!0,o.close())};process.on("exit",t),process.on("SIGINT",t),f||process.on("SIGTERM",t)}var S=async({client:o,$:a,directory:t})=>{let e=d(o),i=parseInt(process.env.CLAUDE_PROXY_PORT||"",10)||void 0,s=await g({port:i,log:e}),l=`http://127.0.0.1:${s.port}`;await e("info",`proxy ready at ${l}`),h(s);let c=await p(s.port,e);return c.ok||await e("error",`[claude-max] Proxy started but is not healthy: ${c.message}. Requests will likely fail.`),{async config(r){r.provider??={},r.provider.anthropic??={},r.provider.anthropic.options??={},r.provider.anthropic.options.baseURL=l,r.provider.anthropic.options.apiKey="claude-max-proxy"},async"chat.params"(r,n){if(r.provider.info.id!=="anthropic")return;let u=await p(s.port,e);if(!u.ok)throw new Error(`Claude Max proxy is not healthy: ${u.message}`)},async"chat.headers"(r,n){r.model.providerID==="anthropic"&&(n.headers["x-opencode-session"]=r.sessionID,n.headers["x-opencode-request"]=r.message.id)}}};export{S as ClaudeMaxPlugin};
|
package/package.json
CHANGED