opencode-with-claude 1.7.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 CHANGED
@@ -1 +1 @@
1
- import{scrubOpencodeFingerprints as Y}from"@rynfar/meridian-plugin-opencode-scrub";var M=/authenticat|credentials|expired|not logged in|exit(?:ed)? with code|crash|unhealthy|401|402|billing|subscription/i,N=/rate.limit|429|overloaded|503|stale.session|timeout|timed out/i;function x(e){return(r,n)=>e.app.log({body:{service:"opencode-with-claude",level:r,message:n}})}function L(e){return M.test(e)?"error":N.test(e)?"warn":"debug"}import{existsSync as _,readFileSync as H}from"fs";import{homedir as U}from"os";import{join as h}from"path";var w=()=>h(U(),".config","meridian"),R=()=>h(w(),"profiles.json"),S=()=>h(w(),"settings.json");function m(e,r){e?.("warn","[opencode-with-claude] ".concat(r))}function k(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function E(e,r,n){if(!Array.isArray(e))return m(n,"".concat(r," must be a JSON array of profile objects; got ").concat(typeof e,". Ignoring.")),[];let i=[];for(let o of e){if(!k(o)||typeof o.id!="string"||!o.id){m(n,"".concat(r,': dropping profile without a string "id" field.'));continue}let t={id:o.id};(o.type==="claude-max"||o.type==="api"||o.type==="oauth-token")&&(t.type=o.type),typeof o.claudeConfigDir=="string"&&(t.claudeConfigDir=o.claudeConfigDir),typeof o.apiKey=="string"&&(t.apiKey=o.apiKey),typeof o.baseUrl=="string"&&(t.baseUrl=o.baseUrl),typeof o.oauthToken=="string"&&(t.oauthToken=o.oauthToken),i.push(t)}return i}function I(e,r){if(_(e))try{return JSON.parse(H(e,"utf8"))}catch(n){let i=n instanceof Error?n.message:String(n);m(r,"failed to parse ".concat(e,": ").concat(i));return}}function j(e){let r=process.env.MERIDIAN_PROFILES;if(r)try{return E(JSON.parse(r),"MERIDIAN_PROFILES",e)}catch(n){let i=n instanceof Error?n.message:String(n);m(e,"failed to parse MERIDIAN_PROFILES env var: ".concat(i));return}}function W(e){let r=I(R(),e);return r===void 0?[]:E(r,R(),e)}function J(e){let r=I(S(),e);if(!k(r))return;let n=r.activeProfile;if(n!==void 0){if(typeof n!="string"||!n){m(e,"".concat(S(),': "activeProfile" must be a non-empty string; ignoring.'));return}return n}}function C(e){let r=[],n="none",i=j(e);if(i)r=i,n="env";else{let f=W(e);f.length>0&&(r=f,n="disk")}let o,t="none",g=process.env.MERIDIAN_DEFAULT_PROFILE?.trim();if(g)o=g,t="env";else{let f=J(e);f&&(o=f,t="disk")}return o&&r.length>0&&!r.some(f=>f.id===o)&&(m(e,'default profile "'.concat(o,'" (from ').concat(t,") not found among configured profiles; ignoring.")),o=void 0,t="none"),{profiles:r,defaultProfile:o,sources:{profiles:n,defaultProfile:t}}}function b(e){if(e.profiles.length===0)return;let r=e.profiles.map(t=>t.id).join(", "),n=e.defaultProfile??e.profiles[0]?.id,i=e.sources.profiles,o=e.sources.defaultProfile==="none"?"first":e.sources.defaultProfile;return"loaded ".concat(e.profiles.length," meridian profile(s) from ").concat(i,": ").concat(r," (active: ").concat(n," [").concat(o,"])")}import{startProxyServer as G}from"@rynfar/meridian";process.env.MERIDIAN_PASSTHROUGH??="true";var K=process.platform==="win32",F=3456,A="127.0.0.1";function z(e){return e.includes(":")&&!e.startsWith("[")?"[".concat(e,"]"):e}function v(){let e=process.env.MERIDIAN_HOST?.trim()||process.env.CLAUDE_PROXY_HOST?.trim()||A;return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e}function X(e=v()){return e==="0.0.0.0"?A:e==="::"||e==="[::]"?"::1":e}function D(e,r=v()){return"http://".concat(z(X(r)),":").concat(e)}async function $(e){let{port:r=F,log:n,profiles:i,defaultProfile:o}=e,t=v(),g=console.error;console.error=(...c)=>{let a=c.map(String).join(" ");if(a.startsWith("[PROXY]")){n?.(L(a),a);return}g.apply(console,c)};let f=c=>new Promise((a,y)=>{G({port:c,host:t,silent:!0,profiles:i,defaultProfile:o}).then(p=>{let P=O=>{y(O)};p.server.once("error",P),p.server.listening?(p.server.removeListener("error",P),a(p)):p.server.once("listening",()=>{p.server.removeListener("error",P),a(p)})},y)}),l=async c=>{try{return await f(c)}catch(a){if(c!==0&&a instanceof Error&&"code"in a&&a.code==="EADDRINUSE")return n?.("info","Port ".concat(c," in use, starting on a random port instead...")),f(0);throw a}},s;try{s=await l(typeof r=="string"?parseInt(r,10):r)}catch(c){throw console.error=g,c}let u=s.server.address()?.port??s.config?.port??F;return n?.("info","Claude Max proxy running on port ".concat(u)),{port:u,close:async()=>{console.error=g,await s.close()}}}function T(e){let r=!1,n=()=>{r||(r=!0,e.close())};process.on("exit",n),process.on("SIGINT",n),K||process.on("SIGTERM",n)}var ae=async({client:e})=>{let r=x(e),n=new Map,i=C(r),o=b(i);o&&r("info",o);let t=process.env.CLAUDE_PROXY_PORT||3456,g=await $({port:t,log:r,profiles:i.profiles,defaultProfile:i.defaultProfile}),f=D(g.port);return r("info","proxy ready at ".concat(f)),T(g),{async config(l){for(let[d,u]of Object.entries(l.agent??{}))u?.mode&&n.set(d.toLowerCase(),u.mode);let s=l.provider?.anthropic;s&&((s.options??={}).baseURL=f)},async"experimental.chat.system.transform"(l,s){if(l.model.providerID!=="anthropic")return;let d=s.system.join("\n\n"),u=Y(d);u!==d&&s.system.splice(0,s.system.length,u)},async"chat.headers"(l,s){if(l.model.providerID!=="anthropic")return;delete s.headers["anthropic-beta"];let d=l.agent,u=typeof d=="object"&&d!==null,c=u?d.name:d,a=String(c??"unknown").replace(/[^\x20-\x7E]/g,"").trim()||"unknown",y=u&&typeof d.mode=="string"?d.mode:n.get(a.toLowerCase())??"primary";s.headers["x-opencode-session"]=l.sessionID,s.headers["x-opencode-request"]=l.message.id,s.headers["x-opencode-agent-mode"]=y,s.headers["x-opencode-agent-name"]=a}}};export{ae as ClaudeMaxPlugin};
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/dist/proxy.d.ts CHANGED
@@ -12,6 +12,22 @@ export interface ProxyHandle {
12
12
  port: string | number;
13
13
  close(): Promise<void>;
14
14
  }
15
+ /**
16
+ * Read the installed Meridian version so it can be handed to
17
+ * `startProxyServer({ version })`.
18
+ *
19
+ * Meridian falls back to the literal string `"unknown"` on /health unless the
20
+ * host passes this in: its CLI reads its own package.json, but a library
21
+ * consumer such as this plugin has to do the same. Without it, /health, the
22
+ * dashboard, and any external monitor all report `"unknown"`.
23
+ *
24
+ * The manifest cannot be resolved as a subpath — Meridian's `exports` map only
25
+ * declares `"."`, so `require.resolve("@rynfar/meridian/package.json")` throws
26
+ * ERR_PACKAGE_PATH_NOT_EXPORTED. Resolve the entry point instead and walk up to
27
+ * the owning package root. Returns undefined if anything is unexpected, which
28
+ * simply leaves Meridian's own fallback in place.
29
+ */
30
+ export declare function resolveMeridianVersion(): string | undefined;
15
31
  export declare function getProxyHost(): string;
16
32
  export declare function getProxyConnectHost(host?: string): string;
17
33
  export declare function getProxyBaseURL(port: string | number, host?: string): string;
@@ -19,6 +35,12 @@ export declare function startProxy(opts: StartProxyOptions): Promise<ProxyHandle
19
35
  export interface HealthResult {
20
36
  ok: boolean;
21
37
  message?: string;
38
+ /** Meridian version behind the proxy. Absent on releases that omit it. */
39
+ version?: string;
40
+ /** Days until the Claude login itself expires, when Meridian reports it. */
41
+ daysUntilRenewal?: number;
42
+ /** True when Meridian flags the login as needing renewal soon. */
43
+ renewalRequiredSoon?: boolean;
22
44
  }
23
45
  export declare function checkProxyHealth(port: string | number, log: LogFn | undefined): Promise<HealthResult>;
24
46
  export declare function registerCleanup(proxy: ProxyHandle): void;
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.7.0",
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.55.1",
9
+ "@rynfar/meridian": "^1.62.6",
10
10
  "@rynfar/meridian-plugin-opencode-scrub": "^0.2.0"
11
11
  },
12
12
  "devDependencies": {