opencode-with-claude 1.6.10 → 1.6.11
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
|
-
import{scrubOpencodeFingerprints as z}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,
|
|
1
|
+
import{scrubOpencodeFingerprints as z}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 R(e){return M.test(e)?"error":N.test(e)?"warn":"debug"}import{existsSync as T,readFileSync as U}from"fs";import{homedir as H}from"os";import{join as v}from"path";var S=()=>v(H(),".config","meridian"),L=()=>v(S(),"profiles.json"),I=()=>v(S(),"settings.json");function g(e,r){e?.("warn","[opencode-with-claude] ".concat(r))}function E(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function w(e,r,n){if(!Array.isArray(e))return g(n,"".concat(r," must be a JSON array of profile objects; got ").concat(typeof e,". Ignoring.")),[];let s=[];for(let o of e){if(!E(o)||typeof o.id!="string"||!o.id){g(n,"".concat(r,': dropping profile without a string "id" field.'));continue}let i={id:o.id};(o.type==="claude-max"||o.type==="api")&&(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),s.push(i)}return s}function C(e,r){if(T(e))try{return JSON.parse(U(e,"utf8"))}catch(n){let s=n instanceof Error?n.message:String(n);g(r,"failed to parse ".concat(e,": ").concat(s));return}}function j(e){let r=process.env.MERIDIAN_PROFILES;if(r)try{return w(JSON.parse(r),"MERIDIAN_PROFILES",e)}catch(n){let s=n instanceof Error?n.message:String(n);g(e,"failed to parse MERIDIAN_PROFILES env var: ".concat(s));return}}function W(e){let r=C(L(),e);return r===void 0?[]:w(r,L(),e)}function K(e){let r=C(I(),e);if(!E(r))return;let n=r.activeProfile;if(n!==void 0){if(typeof n!="string"||!n){g(e,"".concat(I(),': "activeProfile" must be a non-empty string; ignoring.'));return}return n}}function D(e){let r=[],n="none",s=j(e);if(s)r=s,n="env";else{let d=W(e);d.length>0&&(r=d,n="disk")}let o,i="none",p=process.env.MERIDIAN_DEFAULT_PROFILE?.trim();if(p)o=p,i="env";else{let d=K(e);d&&(o=d,i="disk")}return o&&r.length>0&&!r.some(d=>d.id===o)&&(g(e,'default profile "'.concat(o,'" (from ').concat(i,") not found among configured profiles; ignoring.")),o=void 0,i="none"),{profiles:r,defaultProfile:o,sources:{profiles:n,defaultProfile:i}}}function A(e){if(e.profiles.length===0)return;let r=e.profiles.map(i=>i.id).join(", "),n=e.defaultProfile??e.profiles[0]?.id,s=e.sources.profiles,o=e.sources.defaultProfile==="none"?"first":e.sources.defaultProfile;return"loaded ".concat(e.profiles.length," meridian profile(s) from ").concat(s,": ").concat(r," (active: ").concat(n," [").concat(o,"])")}import{startProxyServer as J}from"@rynfar/meridian";process.env.MERIDIAN_PASSTHROUGH??="true";var G=process.platform==="win32",b=3456,k="127.0.0.1";function X(e){return e.includes(":")&&!e.startsWith("[")?"[".concat(e,"]"):e}function h(){let e=process.env.MERIDIAN_HOST?.trim()||process.env.CLAUDE_PROXY_HOST?.trim()||k;return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e}function Y(e=h()){return e==="0.0.0.0"?k:e==="::"||e==="[::]"?"::1":e}function F(e,r=h()){return"http://".concat(X(Y(r)),":").concat(e)}async function O(e){let{port:r=b,log:n,profiles:s,defaultProfile:o}=e,i=h(),p=console.error;console.error=(...t)=>{let l=t.map(String).join(" ");if(l.startsWith("[PROXY]")){n?.(R(l),l);return}p.apply(console,t)};let d=t=>new Promise((l,m)=>{J({port:t,host:i,silent:!0,profiles:s,defaultProfile:o}).then(u=>{let P=_=>{m(_)};u.server.once("error",P),u.server.listening?(u.server.removeListener("error",P),l(u)):u.server.once("listening",()=>{u.server.removeListener("error",P),l(u)})},m)}),y=async t=>{try{return await d(t)}catch(l){if(t!==0&&l instanceof Error&&"code"in l&&l.code==="EADDRINUSE")return n?.("info","Port ".concat(t," in use, starting on a random port instead...")),d(0);throw l}},a;try{a=await y(typeof r=="string"?parseInt(r,10):r)}catch(t){throw console.error=p,t}let f=a.server.address()?.port??a.config?.port??b;return n?.("info","Claude Max proxy running on port ".concat(f)),{port:f,close:async()=>{console.error=p,await a.close()}}}function $(e){let r=!1,n=()=>{r||(r=!0,e.close())};process.on("exit",n),process.on("SIGINT",n),G||process.on("SIGTERM",n)}var ae=async({client:e,directory:r})=>{let n=x(e),s=new Map;r&&!process.env.MERIDIAN_WORKDIR&&!process.env.CLAUDE_PROXY_WORKDIR&&(process.env.MERIDIAN_WORKDIR=r);let o=D(n),i=A(o);i&&n("info",i);let p=process.env.CLAUDE_PROXY_PORT||3456,d=await O({port:p,log:n,profiles:o.profiles,defaultProfile:o.defaultProfile}),y=F(d.port);return n("info","proxy ready at ".concat(y)),$(d),{async config(a){for(let[f,t]of Object.entries(a.agent??{}))t?.mode&&s.set(f.toLowerCase(),t.mode);let c=a.provider?.anthropic;c&&((c.options??={}).baseURL=y)},async"experimental.chat.system.transform"(a,c){if(a.model.providerID!=="anthropic")return;let f=c.system.join("\n\n"),t=z(f);t!==f&&c.system.splice(0,c.system.length,t)},async"chat.headers"(a,c){if(a.model.providerID!=="anthropic")return;delete c.headers["anthropic-beta"];let f=a.agent,t=typeof f=="object"&&f!==null,l=t?f.name:f,m=String(l??"unknown").replace(/[^\x20-\x7E]/g,"").trim()||"unknown",u=t&&typeof f.mode=="string"?f.mode:s.get(m.toLowerCase())??"primary";c.headers["x-opencode-session"]=a.sessionID,c.headers["x-opencode-request"]=a.message.id,c.headers["x-opencode-agent-mode"]=u,c.headers["x-opencode-agent-name"]=m}}};export{ae as ClaudeMaxPlugin};
|
package/package.json
CHANGED