opencode-with-claude 1.8.0 → 1.9.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 +2 -2
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{scrubOpencodeFingerprints as ie}from"@rynfar/meridian-plugin-opencode-scrub";var H=/authenticat|credentials|expired|not logged in|exit(?:ed)? with code|crash|unhealthy|401|402|billing|subscription/i,j=/rate.limit|429|overloaded|503|stale.session|timeout|timed out/i;function x(e){return(n,r)=>e.app.log({body:{service:"opencode-with-claude",level:n,message:r}})}function S(e){return H.test(e)?"error":j.test(e)?"warn":"debug"}import{existsSync as q,readFileSync as W}from"fs";import{homedir as
|
|
1
|
+
import{scrubOpencodeFingerprints as ie}from"@rynfar/meridian-plugin-opencode-scrub";var H=/authenticat|credentials|expired|not logged in|exit(?:ed)? with code|crash|unhealthy|401|402|billing|subscription/i,j=/rate.limit|429|overloaded|503|stale.session|timeout|timed out/i;function x(e){return(n,r)=>e.app.log({body:{service:"opencode-with-claude",level:n,message:r}})}function S(e){return H.test(e)?"error":j.test(e)?"warn":"debug"}import{existsSync as q,readFileSync as W}from"fs";import{homedir as G}from"os";import{join as v}from"path";var b=()=>v(G(),".config","meridian"),k=()=>v(b(),"profiles.json"),L=()=>v(b(),"settings.json");function m(e,n){e?.("warn","[opencode-with-claude] ".concat(n))}function E(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function I(e,n,r){if(!Array.isArray(e))return m(r,"".concat(n," must be a JSON array of profile objects; got ").concat(typeof e,". Ignoring.")),[];let t=[];for(let o of e){if(!E(o)||typeof o.id!="string"||!o.id){m(r,"".concat(n,': dropping profile without a string "id" field.'));continue}let i={id:o.id};(o.type==="claude-max"||o.type==="api"||o.type==="oauth-token")&&(i.type=o.type),typeof o.claudeConfigDir=="string"&&(i.claudeConfigDir=o.claudeConfigDir),typeof o.apiKey=="string"&&(i.apiKey=o.apiKey),typeof o.baseUrl=="string"&&(i.baseUrl=o.baseUrl),typeof o.oauthToken=="string"&&(i.oauthToken=o.oauthToken),t.push(i)}return t}function A(e,n){if(q(e))try{return JSON.parse(W(e,"utf8"))}catch(r){let t=r instanceof Error?r.message:String(r);m(n,"failed to parse ".concat(e,": ").concat(t));return}}function J(e){let n=process.env.MERIDIAN_PROFILES;if(n)try{return I(JSON.parse(n),"MERIDIAN_PROFILES",e)}catch(r){let t=r instanceof Error?r.message:String(r);m(e,"failed to parse MERIDIAN_PROFILES env var: ".concat(t));return}}function K(e){let n=A(k(),e);return n===void 0?[]:I(n,k(),e)}function z(e){let n=A(L(),e);if(!E(n))return;let r=n.activeProfile;if(r!==void 0){if(typeof r!="string"||!r){m(e,"".concat(L(),': "activeProfile" must be a non-empty string; ignoring.'));return}return r}}function C(e){let n=[],r="none",t=J(e);if(t)n=t,r="env";else{let c=K(e);c.length>0&&(n=c,r="disk")}let o,i="none",l=process.env.MERIDIAN_DEFAULT_PROFILE?.trim();if(l)o=l,i="env";else{let c=z(e);c&&(o=c,i="disk")}return o&&n.length>0&&!n.some(c=>c.id===o)&&(m(e,'default profile "'.concat(o,'" (from ').concat(i,") not found among configured profiles; ignoring.")),o=void 0,i="none"),{profiles:n,defaultProfile:o,sources:{profiles:r,defaultProfile:i}}}function F(e){if(e.profiles.length===0)return;let n=e.profiles.map(i=>i.id).join(", "),r=e.defaultProfile??e.profiles[0]?.id,t=e.sources.profiles,o=e.sources.defaultProfile==="none"?"first":e.sources.defaultProfile;return"loaded ".concat(e.profiles.length," meridian profile(s) from ").concat(t,": ").concat(n," (active: ").concat(r," [").concat(o,"])")}import{existsSync as X,readFileSync as Y}from"fs";import{createRequire as B}from"module";import{dirname as $,join as V}from"path";import{startProxyServer as Q}from"@rynfar/meridian";process.env.MERIDIAN_PASSTHROUGH??="true";var Z=process.platform==="win32",D=3456,O="127.0.0.1",M="@rynfar/meridian";function ee(){try{let e=$(B(import.meta.url).resolve(M));for(let n=0;n<5;n++){let r=V(e,"package.json");if(X(r)){let o=JSON.parse(Y(r,"utf8"));if(o.name===M&&typeof o.version=="string")return o.version}let t=$(e);if(t===e)break;e=t}return}catch{return}}function ne(e){return e.includes(":")&&!e.startsWith("[")?"[".concat(e,"]"):e}function w(){let e=process.env.MERIDIAN_HOST?.trim()||process.env.CLAUDE_PROXY_HOST?.trim()||O;return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e}function re(e=w()){return e==="0.0.0.0"?O:e==="::"||e==="[::]"?"::1":e}function R(e,n=w()){return"http://".concat(ne(re(n)),":").concat(e)}async function T(e){let{port:n=D,log:r,profiles:t,defaultProfile:o}=e,i=w(),l=ee(),c=console.error;console.error=(...s)=>{let u=s.map(String).join(" ");if(u.startsWith("[PROXY]")){r?.(S(u),u);return}c.apply(console,s)};let p=s=>new Promise((u,y)=>{Q({port:s,host:i,silent:!0,profiles:t,defaultProfile:o,version:l}).then(g=>{let h=_=>{y(_)};g.server.once("error",h),g.server.listening?(g.server.removeListener("error",h),u(g)):g.server.once("listening",()=>{g.server.removeListener("error",h),u(g)})},y)}),P=async s=>{try{return await p(s)}catch(u){if(s!==0&&u instanceof Error&&"code"in u&&u.code==="EADDRINUSE")return r?.("info","Port ".concat(s," in use, starting on a random port instead...")),p(0);throw u}},a;try{a=await P(typeof n=="string"?parseInt(n,10):n)}catch(s){throw console.error=c,s}let d=a.server.address()?.port??a.config?.port??D;return r?.("info","Claude Max proxy running on port ".concat(d)),{port:d,close:async()=>{console.error=c,await a.close()}}}function oe(e){if(typeof e!="object"||e===null)return{};let n=e,r={};return typeof n.daysUntilRenewal=="number"&&Number.isFinite(n.daysUntilRenewal)&&(r.daysUntilRenewal=n.daysUntilRenewal),typeof n.renewalRequiredSoon=="boolean"&&(r.renewalRequiredSoon=n.renewalRequiredSoon),r}function te(e){return e===void 0?"soon":e<=0?"today":e===1?"in 1 day":"in ".concat(e," days")}async function N(e,n){try{let r=await fetch(R(e)+"/health",{signal:AbortSignal.timeout(5e3)}),t=await r.json(),o=t.version,i=typeof o=="string"&&o!=="unknown"?o:void 0,l=oe(t.auth);if(i&&n?.("info","[claude-max] meridian ".concat(i)),l.renewalRequiredSoon&&n?.("warn","[claude-max] Claude login expires ".concat(te(l.daysUntilRenewal),". Run 'claude login' to renew \u2014 the proxy cannot refresh it for you.")),t.status==="healthy")return{ok:!0,version:i,...l};if(t.status==="degraded"){let p=typeof t.error=="string"?t.error:"Could not verify auth status";return n?.("warn","[claude-max] ".concat(p,". Requests may still work \u2014 if they hang, try running 'claude login' in your terminal.")),{ok:!0,message:p,version:i,...l}}let c=typeof t.error=="string"?t.error:"Proxy health check returned status: ".concat(t.status??r.status);return n?.("error","[claude-max] ".concat(c)),{ok:!1,message:c,version:i,...l}}catch(r){let t=r instanceof Error?r.message:String(r);return n?.("error","[claude-max] Health check failed: ".concat(t)),{ok:!1,message:"Health check failed: ".concat(t)}}}function U(e){let n=!1,r=()=>{n||(n=!0,e.close())};process.on("exit",r),process.on("SIGINT",r),Z||process.on("SIGTERM",r)}var se=4096,xe=async({client:e})=>{let n=x(e),r=new Map,t=new Map,o=(a,f)=>"".concat(a,"\0").concat(f),i=C(n),l=F(i);l&&n("info",l);let c=process.env.CLAUDE_PROXY_PORT||3456,p=await T({port:c,log:n,profiles:i.profiles,defaultProfile:i.defaultProfile}),P=R(p.port);return n("info","proxy ready at ".concat(P)),U(p),N(p.port,n),{async config(a){for(let[d,s]of Object.entries(a.agent??{}))s?.mode&&r.set(d.toLowerCase(),s.mode);let f=a.provider?.anthropic;f&&(f.options||(f.options={}),f.options.baseURL=P)},async"chat.message"(a,f){let d=o(a.sessionID,f.message.id);if(t.delete(d),t.set(d,!0),t.size>se){let s=t.keys().next().value;s!==void 0&&t.delete(s)}},async"experimental.chat.system.transform"(a,f){if(a.model.providerID!=="anthropic")return;let d=f.system.join("\n\n"),s=ie(d);s!==d&&f.system.splice(0,f.system.length,s)},async"chat.headers"(a,f){if(a.model.providerID!=="anthropic")return;delete f.headers["anthropic-beta"];let d=a.agent,s=typeof d=="object"&&d!==null,u=s?d.name:d,y=String(u??"unknown").replace(/[^\x20-\x7E]/g,"").trim()||"unknown",g=s&&typeof d.mode=="string"?d.mode:r.get(y.toLowerCase())??"primary";f.headers["x-opencode-session"]=a.sessionID,f.headers["x-opencode-request"]=a.message.id,f.headers["x-opencode-request-kind"]=t.has(o(a.sessionID,a.message.id))?"human":"synthetic",f.headers["x-opencode-agent-mode"]=g,f.headers["x-opencode-agent-name"]=y}}};export{xe as ClaudeMaxPlugin};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-with-claude",
|
|
3
3
|
"description": "OpenCode plugin to use your Claude Max subscription via Meridian proxy",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.9.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@rynfar/meridian": "^1.
|
|
9
|
+
"@rynfar/meridian": "^1.62.6",
|
|
10
10
|
"@rynfar/meridian-plugin-opencode-scrub": "^0.2.0"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|