ghc-tunnel 1.0.3 → 1.0.5
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 +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,14 +66,14 @@ Run `ghc-tunnel --setup --claudecode` or manually configure `~/.claude/settings.
|
|
|
66
66
|
|
|
67
67
|
`ghc-tunnel` exposes the OpenAI Responses API (`/v1/responses`) with Codex-specific adapters so the Codex CLI can drive Copilot models directly.
|
|
68
68
|
|
|
69
|
-
On startup ghc-tunnel automatically repairs `~/.codex/config.toml` — if any of `model`, `model_reasoning_effort`, `personality`, `model_provider`, or the `[model_providers.ghc-tunnel]` block is missing (or the block is partial), the missing pieces are filled in. When `model` or `model_reasoning_effort` is absent it prompts interactively (defaults: `gpt-5.
|
|
69
|
+
On startup ghc-tunnel automatically repairs `~/.codex/config.toml` — if any of `model`, `model_reasoning_effort`, `personality`, `model_provider`, or the `[model_providers.ghc-tunnel]` block is missing (or the block is partial), the missing pieces are filled in. When `model` or `model_reasoning_effort` is absent it prompts interactively (defaults: `gpt-5.5` / `high`, `xhigh` also valid).
|
|
70
70
|
|
|
71
71
|
`ghc-tunnel --setup` forces a full rewrite of those keys (still prompting for model + reasoning).
|
|
72
72
|
|
|
73
73
|
Resulting config:
|
|
74
74
|
|
|
75
75
|
```toml
|
|
76
|
-
model = "gpt-5.
|
|
76
|
+
model = "gpt-5.5"
|
|
77
77
|
model_reasoning_effort = "high"
|
|
78
78
|
personality = "pragmatic"
|
|
79
79
|
model_provider = "ghc-tunnel"
|
package/dist/index.js
CHANGED
|
@@ -90,7 +90,7 @@ Prefix Mappings: (none)`);console.log("=".repeat(60)+`
|
|
|
90
90
|
|
|
91
91
|
`);continue}try{let I=JSON.parse(H);a.push(I),I.usage&&(l=I.usage.prompt_tokens??0,p=I.usage.completion_tokens??0),m||t.write(`data: ${H}
|
|
92
92
|
|
|
93
|
-
`)}catch{}}}}catch(d){u=504,console.log(`[Stream] Error for ${n}: ${d}`)}m?$.updateRequestState(n,"error",{status_code:499}):t.end();let _=Math.round((Date.now()-r)/1e3*100)/100,R=xe(a);$.completeRequest(n,{request_body:e,response_body:R,model:i,translated_model:c!==i?c:null,endpoint:"/v1/chat/completions",status_code:m?499:u,request_size:s,response_size:a.reduce((d,y)=>d+JSON.stringify(y).length,0),input_tokens:l,output_tokens:p,duration:_})}oe.post(["/v1/responses","/responses"],async(t,e)=>{try{let o=Date.now();await U();let n=t.body,s=crypto.randomUUID(),r=n.model??"unknown",i=ne(r);if(i!==r&&(n={...n,model:i}),!nt(i))return e.status(400).json({error:{message:`Model '${r}' does not support the /v1/responses endpoint.`,type:"invalid_request_error",code:"unsupported_model"}});if(console.log(`[Responses API] Using OpenAI Responses API path for: ${i}`),Array.isArray(n.tools)&&(n={...n,tools:n.tools.map(_=>_.type==="custom"&&_.name==="apply_patch"?{type:"function",name:"apply_patch",description:"Use the `apply_patch` tool to edit files",parameters:{type:"object",properties:{input:{type:"string",description:"The entire contents of the apply_patch command"}},required:["input"]},strict:!1}:_)}),Array.isArray(n.tools)){let _=new Set(["
|
|
93
|
+
`)}catch{}}}}catch(d){u=504,console.log(`[Stream] Error for ${n}: ${d}`)}m?$.updateRequestState(n,"error",{status_code:499}):t.end();let _=Math.round((Date.now()-r)/1e3*100)/100,R=xe(a);$.completeRequest(n,{request_body:e,response_body:R,model:i,translated_model:c!==i?c:null,endpoint:"/v1/chat/completions",status_code:m?499:u,request_size:s,response_size:a.reduce((d,y)=>d+JSON.stringify(y).length,0),input_tokens:l,output_tokens:p,duration:_})}oe.post(["/v1/responses","/responses"],async(t,e)=>{try{let o=Date.now();await U();let n=t.body,s=crypto.randomUUID(),r=n.model??"unknown",i=ne(r);if(i!==r&&(n={...n,model:i}),!nt(i))return e.status(400).json({error:{message:`Model '${r}' does not support the /v1/responses endpoint.`,type:"invalid_request_error",code:"unsupported_model"}});if(console.log(`[Responses API] Using OpenAI Responses API path for: ${i}`),Array.isArray(n.tools)&&(n={...n,tools:n.tools.map(_=>_.type==="custom"&&_.name==="apply_patch"?{type:"function",name:"apply_patch",description:"Use the `apply_patch` tool to edit files",parameters:{type:"object",properties:{input:{type:"string",description:"The entire contents of the apply_patch command"}},required:["input"]},strict:!1}:_)}),Array.isArray(n.tools)){let _=new Set(["image_generation"]);n={...n,tools:n.tools.filter(R=>!(typeof R.type=="string"&&_.has(R.type)))}}if(Array.isArray(n.input)){let _=zt(n.input);_!==n.input&&(n={...n,input:_})}n={...n,service_tier:null};let c=Jt(n.input),a=Y(c);a["X-Initiator"]=Bt(n.input)?"agent":"user";let l=JSON.stringify(n).length;if(n.stream)return Ht(e,n,a,s,l,o,r,i);let p=await it(`${N()}/responses`,{method:"POST",headers:a,body:JSON.stringify(n)},s,"/v1/responses"),u=Math.round((Date.now()-o)/1e3*100)/100;if(!p)return e.status(504).json({error:`Upstream connection error after ${f.maxConnectionRetries+1} attempts`});let m=await p.text();if(p.ok){let _=JSON.parse(m),R=_.usage??{};$.addRequest(s,{request_body:n,response_body:_,model:r,translated_model:i!==r?i:null,endpoint:"/v1/responses",status_code:p.status,request_size:l,response_size:m.length,input_tokens:R.input_tokens??0,output_tokens:R.output_tokens??0,duration:u}),e.json(_)}else Z("/v1/responses",n,m,p.status),e.status(p.status).type("json").send(m)}catch(o){e.status(500).json({error:String(o)})}});async function Ht(t,e,o,n,s,r,i,c){$.startRequest(n,{request_body:e,model:i,translated_model:c!==i?c:null,endpoint:"/v1/responses",request_size:s}),t.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","X-Accel-Buffering":"no"});let a=0,l=0,p=200,u={},m=[],_=!1;t.on("close",()=>{_=!0});try{$.updateRequestState(n,"sending");let y=await fetch(`${N()}/responses`,{method:"POST",headers:o,body:JSON.stringify(e),signal:AbortSignal.timeout(12e5)});if(p=y.status,y.ok){let b=y.body.getReader(),k=new TextDecoder,x="";for($.updateRequestState(n,"receiving");;){let{done:T,value:q}=await b.read();if(T)break;if(_){b.cancel();break}_||t.write(q),x+=k.decode(q,{stream:!0});let C=x.split(`
|
|
94
94
|
`);x=C.pop();for(let H of C){let I=H.replace(/\r$/,"");if(!I.startsWith("data: "))continue;let V=I.slice(6);if(V!=="[DONE]")try{let A=JSON.parse(V);if(A.type==="response.completed"){let B=A.response??{};u=B;let O=B.usage??{};a=O.input_tokens??0,l=O.output_tokens??0}else A.type==="response.output_text.delta"&&m.push(A.delta??"")}catch{}}}}else{let b=await y.text();Z("/v1/responses",e,b,p),_||t.write(`event: error
|
|
95
95
|
data: ${JSON.stringify({status:p,body:b})}
|
|
96
96
|
|
|
@@ -175,7 +175,7 @@ tool_result_suffix_remove: []
|
|
|
175
175
|
|
|
176
176
|
max_connection_retries: 3
|
|
177
177
|
`;S.default.writeFileSync(r,i,"utf-8"),console.log(` ${D}\u2713${g} Config saved to ${K}${r}${g}`)}function ht(t,e){let o=M.default.join(process.env.HOME||"~",".claude"),n=M.default.join(o,"settings.json"),s={};if(S.default.existsSync(n))try{s=JSON.parse(S.default.readFileSync(n,"utf-8"))}catch{console.log(` ${se}\u26A0${g} Could not parse existing settings.json, creating new one`)}let r=`http://${e}:${t}/`,i=s.env??{};i.ANTHROPIC_BASE_URL=r,i.ANTHROPIC_AUTH_TOKEN="dummy",i.ANTHROPIC_MODEL=z,i.ANTHROPIC_DEFAULT_HAIKU_MODEL=z,i.DISABLE_NON_ESSENTIAL_MODEL_CALLS="1",i.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC="1",delete i.ANTHROPIC_SMALL_FAST_MODEL,s.env=i,S.default.mkdirSync(o,{recursive:!0}),S.default.writeFileSync(n,JSON.stringify(s,null,2)+`
|
|
178
|
-
`,"utf-8"),console.log(` ${D}\u2713${g} Claude Code settings updated at ${K}${n}${g}`),console.log(` ${w}ANTHROPIC_BASE_URL = ${r}${g}`),console.log(` ${w}ANTHROPIC_MODEL = ${z}${g}`),console.log(` ${w}ANTHROPIC_DEFAULT_HAIKU_MODEL = ${z}${g}`)}var ze="gpt-5.
|
|
178
|
+
`,"utf-8"),console.log(` ${D}\u2713${g} Claude Code settings updated at ${K}${n}${g}`),console.log(` ${w}ANTHROPIC_BASE_URL = ${r}${g}`),console.log(` ${w}ANTHROPIC_MODEL = ${z}${g}`),console.log(` ${w}ANTHROPIC_DEFAULT_HAIKU_MODEL = ${z}${g}`)}var ze="gpt-5.5",F="ghc-tunnel",yt="GHC TUNNEL",Je="high",Rt="pragmatic";function X(t,e,o){let n=t.search(/(^|\n)\[/),s=n===-1?t:t.slice(0,n),r=n===-1?"":t.slice(n),i=`${e} = ${o}`,c=new RegExp(`^${e}\\s*=.*$`,"m");if(c.test(s))return s.replace(c,i)+r;let a=s.length===0||s.endsWith(`
|
|
179
179
|
`)?"":`
|
|
180
180
|
`;return`${s}${a}${i}
|
|
181
181
|
${r}`}function kt(t,e,o,n){let s=e.replace(/[.[\]]/g,a=>`\\${a}`),r=new RegExp(`(^|\\n)\\[${s}\\][^\\[]*?(?=\\n\\[|$)`),i=`[${e}]
|