@vibeapi/api-helper 0.0.105 → 0.0.106
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/lib/tools/codex.js +1 -1
- package/package.json +1 -1
package/dist/lib/tools/codex.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as e,readFileSync as t,rmSync as o}from"fs";import{join as n}from"path";import*as r from"@iarna/toml";import{logger as i}from"../../utils/logger.js";import{i18n as l}from"../i18n.js";import{backupBeforeWrite as a,atomicWriteFile as s}from"./backup.js";import{pickModel as d,toolHome as c,withV1 as m}from"./types.js";import{getToolDefaultModel as u}from"../model-registry.js";import{buildCodexCatalog as p,codexCatalogPath as _,loadBundledCodexModels as g,loadPreviousCodexModels as f,previousGatewayModelIds as x}from"./codex-catalog.js";import{gatewayModelSpecs as y,modelFamily as h}from"../gateway-models.js";import{mirrorInstallCommand as k,brandInstallScripts as b}from"./tool-installs.js";const j=()=>n(c(),".codex"),w=()=>n(j(),"config.toml"),O=()=>n(j(),"auth.json"),v="OPENAI_API_KEY",C="custom",M=1e6,E=9e5;export const CODEX_ONE_MILLION_CONTEXT_SETTING="one_million_context";function N(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function S(e,t){return N(e[t])||(e[t]={}),e[t]}function A(){if(!e(w()))return{};const o=t(w(),"utf-8");if(!o.trim())return{};try{const e=r.parse(o);if(!N(e))throw new Error("config.toml root must be a TOML table");return e}catch(e){throw new Error(`Existing ~/.codex/config.toml cannot be parsed, back it up and fix it first: ${e instanceof Error?e.message:String(e)}`)}}function P(){if(!e(O()))return{};try{const e=JSON.parse(t(O(),"utf-8"));return N(e)?e:{}}catch{return{}}}let T=null;function I(e){const t=e.profiles;if(N(t)){for(const[e,o]of Object.entries(t))N(o)&&2===Object.keys(o).length&&o.model_provider===C&&o.model===e&&delete t[e];0===Object.keys(t).length&&delete e.profiles}}let L=null;function D(o,n,r){const l=!1!==n.settings?.one_million_context;!function(e){e.model_context_window===M&&delete e.model_context_window,e.model_auto_compact_token_limit===E&&delete e.model_auto_compact_token_limit}(o);const d=g()??f();if(!d)return i.logError("codexAdapter.writeModelCatalog",new Error("no Codex binary found; model catalog skipped")),L="skipped",o.model_catalog_json===_()&&delete o.model_catalog_json,void(l&&(o.model_context_window=M,o.model_auto_compact_token_limit=E));const c=n.catalog,m=p({bundled:d,specs:y("codex",c?.clientModels),...c?{keyModels:c.models}:{},gatewayAvailable:c?.models??x(),oneMillion:l,selectedModel:r,..."gateway"===c?.oneMillionSource?{claudeOneMillion:c.oneMillion}:{}});L={listed:m.models.filter(e=>"list"===e.visibility).map(e=>({id:String(e.slug),name:String(e.display_name??e.slug)}))};const u=JSON.stringify(m,null,2)+"\n",h=_();e(h)&&t(h,"utf-8")===u||(a(h),s(h,u)),o.model_catalog_json=h}export function setCodexOneMillionContext(e,t){const o=A(),n=r.stringify(o),i="string"==typeof o.model?o.model:u("codex");D(o,{settings:{[CODEX_ONE_MILLION_CONTEXT_SETTING]:e},catalog:t},i);const l=r.stringify(o);l!==n&&(a(w()),s(w(),l))}const J={command:"codex",npmPackage:"@openai/codex",native:{binDir:"win32"===process.platform?["AppData","Local","Programs","OpenAI","Codex","bin"]:[".local","bin"],updateArgs:["update"],updateTimeoutMs:12e4,dataDirs:[[".codex","packages","standalone"]]},mirrorScript:b("codex"),brew:"codex"};export const codexAdapter={name:"codex",displayName:"Codex",command:"codex",installCommand:k(J),installSpec:J,configPath:w(),wantsModelCatalog:!0,listedModels(){if(A().model_catalog_json!==_())return null;try{return(JSON.parse(t(_(),"utf-8")).models??[]).filter(e=>"list"===e.visibility).map(e=>String(e.slug))}catch{return null}},refreshModelMenu(e){A().model_catalog_json===_()&&setCodexOneMillionContext(!1!==e.settings?.one_million_context,e.catalog)},applyNotes(){if("skipped"===L)return[{kind:"action",text:l.t("tools.codex.catalog_skipped")}];if(!L)return[];const e=new Map;for(const t of L.listed)e.set(h(t.id),(e.get(h(t.id))??0)+1);const t=["gpt","claude","gemini","other","grok"].filter(t=>e.has(t)).map(t=>`${l.t(`tools.model_family.${t}`)} ${e.get(t)}`).join(" · ");return[{kind:"summary",text:l.t("tools.codex.catalog_written",{count:String(L.listed.length),breakdown:t})},{kind:"detail",text:L.listed.map(e=>e.name).join(", ")}]},loadPrivateConfig(e){const t=u("codex"),o=d(e.models,t),n=function(e){return/(?:^|\/)claude(?:-|$)/i.test(e)}(o)?t:o,i=m(e.baseUrl),l=A();l.model=n,l.model_provider=C,l.model_reasoning_effort="high",D(l,e,n);const c=S(l,"model_providers"),p=N(c[C])?{...c[C]}:{};delete p.env_key;const{experimental_bearer_token:_,...g}=p;c[C]={...g,name:"custom",wire_api:"responses",requires_openai_auth:!0,base_url:i},I(l),S(S(l,"tui"),"model_availability_nux")[n]=4;const f=S(l,"features");f.goals=!0,f.js_repl=!1,a(w()),s(w(),r.stringify(l)),function(e){const t=e.trim();if(!t)return;const o={...P(),auth_mode:"apikey",[v]:t};a(O()),s(O(),JSON.stringify(o,null,2)+"\n")}(e.apiKey)},unloadPrivateConfig(t){if(T=function(e){const t=P(),n="string"==typeof t[v]?t[v].trim():"";if(!n)return N(t.tokens)?"chatgpt":null;if(!e.includes(n))return"other_key";const{[v]:r,auth_mode:i,...l}=t;return a(O()),N(l.tokens)?(s(O(),JSON.stringify({...l,auth_mode:"chatgpt"},null,2)+"\n"),"chatgpt"):(o(O(),{force:!0}),"signed_out")}(t?.savedKeys??[]),!e(w()))return;let n;try{n=A()}catch(e){return void i.logError("codexAdapter.unloadPrivateConfig",e)}const l=n.model_providers;N(l)&&(delete l[C],0===Object.keys(l).length&&delete n.model_providers),n.model_provider===C&&delete n.model_provider,n.model_catalog_json===_()&&delete n.model_catalog_json,I(n),a(w()),s(w(),r.stringify(n))},unloadNotes(){switch(T){case"chatgpt":return[{kind:"action",text:l.t("tools.codex.unload_chatgpt_restored")}];case"other_key":return[{kind:"action",text:l.t("tools.codex.unload_other_key")}];default:return[{kind:"action",text:l.t("tools.codex.unload_sign_in")}]}},detectCurrentConfig(){const e=P()[v];return{apiKey:"string"==typeof e&&e.trim()?e.trim():null}},getConfig(){try{return A()}catch(e){return i.logError("codexAdapter.getConfig",e),null}},backupPaths:()=>[w(),O(),_()]};export function codexAuthProblem(){try{const e=A(),t=e.model_providers?.[C];if(e.model_provider!==C||!t)return null;if("string"==typeof t.experimental_bearer_token&&t.experimental_bearer_token)return"stale_bearer";const o=P();return!0===t.requires_openai_auth&&"chatgpt"===o.auth_mode?"chatgpt_login":null}catch{return null}}
|
|
1
|
+
import{existsSync as e,readFileSync as t,rmSync as o}from"fs";import{join as n}from"path";import*as r from"@iarna/toml";import{logger as i}from"../../utils/logger.js";import{i18n as l}from"../i18n.js";import{backupBeforeWrite as a,atomicWriteFile as s}from"./backup.js";import{pickModel as d,toolHome as c,withV1 as m}from"./types.js";import{getToolDefaultModel as u}from"../model-registry.js";import{buildCodexCatalog as p,codexCatalogPath as _,loadBundledCodexModels as g,loadPreviousCodexModels as f,previousGatewayModelIds as x}from"./codex-catalog.js";import{gatewayModelSpecs as y,modelFamily as h}from"../gateway-models.js";import{mirrorInstallCommand as k,brandInstallScripts as b}from"./tool-installs.js";const j=()=>n(c(),".codex"),w=()=>n(j(),"config.toml"),O=()=>n(j(),"auth.json"),v="OPENAI_API_KEY",C="custom",M=1e6,E=9e5;export const CODEX_ONE_MILLION_CONTEXT_SETTING="one_million_context";function N(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function S(e,t){return N(e[t])||(e[t]={}),e[t]}function A(){if(!e(w()))return{};const o=t(w(),"utf-8");if(!o.trim())return{};try{const e=r.parse(o);if(!N(e))throw new Error("config.toml root must be a TOML table");return e}catch(e){throw new Error(`Existing ~/.codex/config.toml cannot be parsed, back it up and fix it first: ${e instanceof Error?e.message:String(e)}`)}}function P(){if(!e(O()))return{};try{const e=JSON.parse(t(O(),"utf-8"));return N(e)?e:{}}catch{return{}}}let T=null;function I(e){const t=e.profiles;if(N(t)){for(const[e,o]of Object.entries(t))N(o)&&2===Object.keys(o).length&&o.model_provider===C&&o.model===e&&delete t[e];0===Object.keys(t).length&&delete e.profiles}}let L=null;function D(o,n,r){const l=!1!==n.settings?.one_million_context;!function(e){e.model_context_window===M&&delete e.model_context_window,e.model_auto_compact_token_limit===E&&delete e.model_auto_compact_token_limit}(o);const d=g()??f();if(!d)return i.logError("codexAdapter.writeModelCatalog",new Error("no Codex binary found; model catalog skipped")),L="skipped",o.model_catalog_json===_()&&delete o.model_catalog_json,void(l&&(o.model_context_window=M,o.model_auto_compact_token_limit=E));const c=n.catalog,m=p({bundled:d,specs:y("codex",c?.clientModels),...c?{keyModels:c.models}:{},gatewayAvailable:c?.models??x(),oneMillion:l,selectedModel:r,..."gateway"===c?.oneMillionSource?{claudeOneMillion:c.oneMillion}:{}});L={listed:m.models.filter(e=>"list"===e.visibility).map(e=>({id:String(e.slug),name:String(e.display_name??e.slug)}))};const u=JSON.stringify(m,null,2)+"\n",h=_();e(h)&&t(h,"utf-8")===u||(a(h),s(h,u)),o.model_catalog_json=h}export function setCodexOneMillionContext(e,t){const o=A(),n=r.stringify(o),i="string"==typeof o.model?o.model:u("codex");D(o,{settings:{[CODEX_ONE_MILLION_CONTEXT_SETTING]:e},catalog:t},i);const l=r.stringify(o);l!==n&&(a(w()),s(w(),l))}const J={command:"codex",npmPackage:"@openai/codex",native:{binDir:"win32"===process.platform?["AppData","Local","Programs","OpenAI","Codex","bin"]:[".local","bin"],updateArgs:["update"],updateTimeoutMs:12e4,dataDirs:[[".codex","packages","standalone"]]},mirrorScript:b("codex"),brew:"codex"};export const codexAdapter={name:"codex",displayName:"Codex",command:"codex",installCommand:k(J),installSpec:J,configPath:w(),wantsModelCatalog:!0,listedModels(){if(A().model_catalog_json!==_())return null;try{return(JSON.parse(t(_(),"utf-8")).models??[]).filter(e=>"list"===e.visibility).map(e=>String(e.slug))}catch{return null}},refreshModelMenu(e){A().model_catalog_json===_()&&setCodexOneMillionContext(!1!==e.settings?.one_million_context,e.catalog)},applyNotes(){if("skipped"===L)return[{kind:"action",text:l.t("tools.codex.catalog_skipped")}];if(!L)return[];const e=new Map;for(const t of L.listed)e.set(h(t.id),(e.get(h(t.id))??0)+1);const t=["gpt","claude","gemini","other","grok"].filter(t=>e.has(t)).map(t=>`${l.t(`tools.model_family.${t}`)} ${e.get(t)}`).join(" · ");return[{kind:"summary",text:l.t("tools.codex.catalog_written",{count:String(L.listed.length),breakdown:t})},{kind:"detail",text:L.listed.map(e=>e.name).join(", ")}]},loadPrivateConfig(e){const t=u("codex"),o=d(e.models,t),n=function(e){return/(?:^|\/)claude(?:-|$)/i.test(e)}(o)?t:o,i=m(e.baseUrl),l=A();l.model=n,l.model_provider=C,l.model_reasoning_effort="high",D(l,e,n);const c=S(l,"model_providers"),p=N(c[C])?{...c[C]}:{};delete p.env_key;const{experimental_bearer_token:_,...g}=p;c[C]={...g,name:"custom",wire_api:"responses",requires_openai_auth:!0,base_url:i},I(l),S(S(l,"tui"),"model_availability_nux")[n]=4;const f=S(l,"features");f.goals=!0,f.js_repl=!1,a(w()),s(w(),r.stringify(l)),function(e){const t=e.trim();if(!t)return;const o={...P(),auth_mode:"apikey",[v]:t};a(O()),s(O(),JSON.stringify(o,null,2)+"\n",384)}(e.apiKey)},unloadPrivateConfig(t){if(T=function(e){const t=P(),n="string"==typeof t[v]?t[v].trim():"";if(!n)return N(t.tokens)?"chatgpt":null;if(!e.includes(n))return"other_key";const{[v]:r,auth_mode:i,...l}=t;return a(O()),N(l.tokens)?(s(O(),JSON.stringify({...l,auth_mode:"chatgpt"},null,2)+"\n",384),"chatgpt"):(o(O(),{force:!0}),"signed_out")}(t?.savedKeys??[]),!e(w()))return;let n;try{n=A()}catch(e){return void i.logError("codexAdapter.unloadPrivateConfig",e)}const l=n.model_providers;N(l)&&(delete l[C],0===Object.keys(l).length&&delete n.model_providers),n.model_provider===C&&delete n.model_provider,n.model_catalog_json===_()&&delete n.model_catalog_json,I(n),a(w()),s(w(),r.stringify(n))},unloadNotes(){switch(T){case"chatgpt":return[{kind:"action",text:l.t("tools.codex.unload_chatgpt_restored")}];case"other_key":return[{kind:"action",text:l.t("tools.codex.unload_other_key")}];default:return[{kind:"action",text:l.t("tools.codex.unload_sign_in")}]}},detectCurrentConfig(){const e=P()[v];return{apiKey:"string"==typeof e&&e.trim()?e.trim():null}},getConfig(){try{return A()}catch(e){return i.logError("codexAdapter.getConfig",e),null}},backupPaths:()=>[w(),O(),_()]};export function codexAuthProblem(){try{const e=A(),t=e.model_providers?.[C];if(e.model_provider!==C||!t)return null;if("string"==typeof t.experimental_bearer_token&&t.experimental_bearer_token)return"stale_bearer";const o=P();return!0===t.requires_openai_auth&&"chatgpt"===o.auth_mode?"chatgpt_login":null}catch{return null}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibeapi/api-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.106",
|
|
4
4
|
"description": "CLI tool for managing AI coding assistants (Claude Code, Codex, OpenClaw, Hermes, AtomCode, Grok Build) with one unified config",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|