@closerepo/ai-provider 1.0.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/codex-network-guard.js +6 -0
- package/dist/codex-simple-policy.js +2 -0
- package/dist/codex-simple-process.js +1 -0
- package/dist/codex-simple-protocol.js +1 -0
- package/dist/codex-simple-worker.js +2 -0
- package/dist/codex.d.ts +189 -0
- package/dist/codex.js +7 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.js +1 -0
- package/dist/openai-compatible.d.ts +130 -0
- package/dist/openai-compatible.js +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{createServer as e}from"node:http";import{Socket as t}from"node:net";function n(e){if(e===void 0||e.length===0)return null;try{let t=new URL(`http://${e}`),n=t.port.length===0?443:Number(t.port);return t.username.length>0||t.password.length>0||t.pathname!==`/`||t.search.length>0||t.hash.length>0||t.hostname.length===0||!Number.isSafeInteger(n)||n<1||n>65535?null:{host:t.hostname.toLowerCase(),port:n}}catch{return null}}function r(e,t){return t.some(t=>e===t||e.endsWith(`.${t}`))}function i(e){return Object.freeze({connectionCount:e.connectionCount,receivedBytes:e.receivedBytes,violation:e.violation===null?null:Object.freeze({...e.violation})})}async function a(a){let o=new Set,s=0,c=0,l=null,u=!1,d=()=>{for(let e of o)e.destroy()},f=(e,t)=>{l===null&&(l=Object.freeze({kind:e,destinationHost:t}),d())},p=e=>{o.add(e),e.once(`close`,()=>o.delete(e))},m=e((e,t)=>{t.writeHead(502,{Connection:`close`}),t.end(),f(`destination_blocked`,null)});m.on(`connection`,p),m.on(`connect`,(e,i,o)=>{let u=n(e.url);if(u===null){i.end(`HTTP/1.1 400 Bad Request\r
|
|
2
|
+
Connection: close\r
|
|
3
|
+
\r
|
|
4
|
+
`);return}if(s+=1,l!==null){i.destroy();return}if(r(u.host,a.blockedHostSuffixes)){f(`destination_blocked`,u.host),i.destroy();return}let d=new t;d.connect({host:u.host,port:u.port}),p(d);let m=()=>{i.destroy(),d.destroy()};i.once(`error`,m),d.once(`error`,m),i.once(`close`,()=>d.destroy()),d.once(`close`,()=>i.destroy()),d.once(`connect`,()=>{i.write(`HTTP/1.1 200 Connection Established\r
|
|
5
|
+
\r
|
|
6
|
+
`),o.byteLength>0&&d.write(o),i.pipe(d),d.on(`data`,e=>{c+=e.byteLength,i.write(e)||(d.pause(),i.once(`drain`,()=>d.resume()))})})}),await new Promise((e,t)=>{let n=e=>{m.off(`listening`,r),t(e)},r=()=>{m.off(`error`,n),e()};m.once(`error`,n),m.once(`listening`,r),m.listen(0,`127.0.0.1`)});let h=m.address();if(h===null||typeof h==`string`)throw m.close(),Error(`codex_network_guard_address_unavailable`);let g=`http://127.0.0.1:${h.port}`;return Object.freeze({environment:Object.freeze({ALL_PROXY:g,HTTP_PROXY:g,HTTPS_PROXY:g,NO_PROXY:``,all_proxy:g,http_proxy:g,https_proxy:g,no_proxy:``}),observe(){return i({connectionCount:s,receivedBytes:c,violation:l})},async close(){u||(u=!0,d(),await new Promise((e,t)=>{m.close(n=>n===void 0?e():t(n))}))}})}export{a as createCodexNetworkGuard};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=Object.freeze({"agents.enabled":!1,project_doc_max_bytes:0,"features.apps":!1,"features.code_mode":!1,"features.code_mode_host":!1,"features.code_mode_only":!1,"features.goals":!1,"features.hooks":!1,"features.image_generation":!1,"features.multi_agent":!1,"features.multi_agent_v2":!1,"features.personality":!1,"features.plugin_sharing":!1,"features.plugins":!1,"features.remote_plugin":!1,"features.respect_system_proxy":!0,"features.shell_tool":!1,"features.skill_search":!1,"features.unified_exec":!1,"features.workspace_dependencies":!1,"orchestrator.mcp.enabled":!1,"orchestrator.skills.enabled":!1,"tools.experimental_request_user_input.enabled":!1,"tools.web_search":!1}),t=Object.freeze({...e,include_apps_instructions:!1,include_collaboration_mode_instructions:!1,include_environment_context:!1,include_permissions_instructions:!1,"skills.include_instructions":!1}),n=Object.freeze([`check_for_update_on_startup = false`,...Object.entries(t).map(([e,t])=>`${e} = ${String(t)}`),``].join(`
|
|
2
|
+
`));export{n as isolatedCodexConfig,e as simpleCodexConfigOverrides};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{spawn as e}from"node:child_process";import{resolve as t}from"node:path";import{fileURLToPath as n}from"node:url";const r=[`invalid_configuration`,`unsupported_response_format`,`aborted`,`timeout`,`unavailable`,`provider_rejected`,`invalid_response`,`protocol_incompatible`,`unsafe_provider_event`,`network_destination_blocked`,`network_guard_unobserved`,`output_limit_exceeded`,`cleanup_failed`],i=[`initialize`,`thread_start`,`turn_start`,`turn_execution`,`response_receive`,`response_read`,`response_parse`,`response_normalize`],a=`json_rpc_parse_error.json_rpc_invalid_request.json_rpc_method_not_found.json_rpc_invalid_params.json_rpc_internal_error.codex_context_window_exceeded.codex_session_budget_exceeded.codex_usage_limit_exceeded.codex_server_overloaded.codex_cyber_policy.codex_internal_server_error.codex_unauthorized.codex_bad_request.codex_thread_rollback_failed.codex_sandbox_error.codex_other.codex_http_connection_failed.codex_response_stream_connection_failed.codex_response_stream_disconnected.codex_response_too_many_failed_attempts.codex_active_turn_not_steerable.fetch_response_invalid.response_body_missing.response_body_read_failed.response_json_invalid.response_choices_invalid.response_message_invalid.response_model_invalid.codex_executable_not_configured.codex_executable_path_invalid.codex_executable_unavailable`.split(`.`),o=Symbol.for(`@closerepo/ai-provider/AiProviderError`),s=new Set(r),c=new Set(i),l=new Set(a);function u(e){if(typeof e!=`object`||!e)return!1;let t=e;return Object.keys(t).length===3&&typeof t.phase==`string`&&c.has(t.phase)&&(t.providerCode===null||typeof t.providerCode==`string`&&l.has(t.providerCode))&&(t.httpStatusCode===null||Number.isInteger(t.httpStatusCode)&&t.httpStatusCode>=100&&t.httpStatusCode<=599)}function d(e){if(typeof e!=`object`||!e)return!1;let t=e;return t[o]===!0&&t.name===`AiProviderError`&&typeof t.code==`string`&&s.has(t.code)&&(t.providerRequestId===null||typeof t.providerRequestId==`string`)&&(t.diagnostic===null||u(t.diagnostic))}var f=class extends Error{code;providerRequestId;diagnostic;constructor(e){if(typeof e!=`object`||!e||!s.has(e.code)||e.providerRequestId!==void 0&&e.providerRequestId!==null&&(typeof e.providerRequestId!=`string`||e.providerRequestId.length===0||e.providerRequestId.length>256||/[\u0000-\u001F\u007F]/.test(e.providerRequestId))||e.diagnostic!==void 0&&e.diagnostic!==null&&!u(e.diagnostic))throw TypeError(`invalid_ai_provider_error`);super(e.code),this.name=`AiProviderError`,this.code=e.code,this.providerRequestId=e.providerRequestId??null,this.diagnostic=e.diagnostic===void 0||e.diagnostic===null?null:Object.freeze({...e.diagnostic}),this.stack=`${this.name}: ${this.message}`,Object.defineProperty(this,o,{value:!0})}static[Symbol.hasInstance](e){return d(e)}};const p=2e3,m=new Set([`invalid_configuration`,`unsupported_response_format`,`aborted`,`timeout`,`unavailable`,`provider_rejected`,`invalid_response`,`protocol_incompatible`,`unsafe_provider_event`,`network_destination_blocked`,`network_guard_unobserved`,`output_limit_exceeded`,`cleanup_failed`]),h=new Set([`initialize`,`thread_start`,`turn_start`,`turn_execution`,`response_receive`,`response_read`,`response_parse`,`response_normalize`]),g=new Set([`codex_usage_limit_exceeded`]);function _(){let e=import.meta.url.endsWith(`.ts`)?`.ts`:`.js`;return n(new URL(`./codex-simple-worker${e}`,import.meta.url))}function v(e,t){let n=process.env[t];typeof n==`string`&&n.length>0&&(e[t]=n)}function y(e){let t={...e,NO_COLOR:`1`,RUST_LOG:`error`};for(let e of process.platform===`win32`?[`PATH`,`Path`,`PATHEXT`,`SystemRoot`,`WINDIR`,`ComSpec`]:[`PATH`])v(t,e);return t}function b(e,t){let n=e+String(t);if(Buffer.byteLength(n)>5242880)throw new f({code:`output_limit_exceeded`});return n}function x(){return new f({code:`cleanup_failed`})}function S(e,t){return typeof e==`object`&&!!e&&`code`in e&&e.code===t}async function C(n,r){let i=process.env.SystemRoot??process.env.WINDIR,a=i===void 0?`taskkill.exe`:t(i,`System32`,`taskkill.exe`);return await new Promise(t=>{let i=!1,o=!1,s,c,l=e=>{i||(i=!0,s!==void 0&&clearTimeout(s),c!==void 0&&clearTimeout(c),t(e))};try{let t=e(a,[`/pid`,String(n),`/t`,...r?[`/f`]:[]],{stdio:`ignore`,windowsHide:!0});t.once(`error`,()=>l(!1)),t.once(`close`,e=>l(!o&&e===0)),s=setTimeout(()=>{o=!0;try{t.kill()}catch{}c=setTimeout(()=>l(!1),250)},r?3e3:500)}catch{l(!1)}})}async function w(e,t,n){if(t())return!0;let r,i=new Promise(e=>{r=setTimeout(()=>e(!1),n)}),a=await Promise.race([e.then(()=>!0),i]);return r!==void 0&&clearTimeout(r),a}function T(e){try{return process.kill(-e,0),!0}catch(e){return!S(e,`ESRCH`)}}function E(e,t,n){try{process.kill(-t,n)}catch{try{e.kill(n)}catch{}}}async function D(e,t,n){let r=performance.now()+n;for(;performance.now()<r;){if(t()&&!T(e))return!0;await new Promise(e=>{setTimeout(e,25)})}return t()&&!T(e)}async function O(e,t,n){if(n())return;let r=e.pid;if(r===void 0){if(await w(t,n,p))return;throw x()}if(process.platform===`win32`){let e=await C(r,!1);if(e&&await w(t,n,500))return;let i=await C(r,!0);if(await w(t,n,p)&&(i||e))return;throw x()}if(E(e,r,`SIGTERM`),!await D(r,n,500)&&(E(e,r,`SIGKILL`),!await D(r,n,p)))throw x()}function k(e){let t=e.split(/\r?\n/u).findLast(e=>e.startsWith(`closerepo-ai-provider-result:`));if(t===void 0)throw new f({code:`invalid_response`});let n;try{n=JSON.parse(t.slice(29))}catch{throw new f({code:`invalid_response`})}if(typeof n!=`object`||!n||!(`ok`in n))throw new f({code:`invalid_response`});return n}function A(e){if(e.ok)throw new f({code:`invalid_response`});let t=m.has(e.error.code)?e.error.code:`provider_rejected`,n=e.error.phase!==void 0&&h.has(e.error.phase)?e.error.phase:void 0,r=e.error.providerCode!==void 0&&g.has(e.error.providerCode)?e.error.providerCode:null;return new f({code:t,...n===void 0?{}:{diagnostic:{phase:n,providerCode:r,httpStatusCode:null}}})}async function j(t,n,r){if(r.aborted)throw new DOMException(`aborted`,`AbortError`);let i=e(process.execPath,[_()],{cwd:t.cwd,env:y(n),stdio:[`pipe`,`pipe`,`pipe`],windowsHide:!0,detached:process.platform!==`win32`}),a=``,o=``,s=null,c=!1,l=!1,u=null,d=new Promise(e=>{i.once(`error`,e=>{u=e}),i.once(`close`,t=>{l=!0,e({code:t,spawnError:u})})}),p=()=>{},m=()=>{},h=new Promise((e,t)=>{p=e,m=t}),g=null,v=()=>{if(g!==null)return g;let e=O(i,d,()=>l);return g=e,e.then(p,m),e};i.stdout?.setEncoding(`utf8`),i.stderr?.setEncoding(`utf8`),i.stdout?.on(`data`,e=>{if(s===null)try{a=b(a,e)}catch(e){s=e,v()}}),i.stderr?.on(`data`,e=>{if(s===null)try{o=b(o,e)}catch(e){s=e,v()}});let x=()=>{c=!0,v()};r.addEventListener(`abort`,x,{once:!0}),r.aborted&&x();try{i.stdin?.end(JSON.stringify(t));let e=await Promise.race([d,h.then(()=>d)]);if(c)throw new DOMException(`aborted`,`AbortError`);if(s!==null)throw s;if(e.spawnError!==null||e.code!==0)throw new f({code:e.spawnError===null?`provider_rejected`:`unavailable`});let n=k(a);if(!n.ok)throw A(n);return n.observation}finally{r.removeEventListener(`abort`,x),g===null?l||await v():await g}}export{j as runIsolatedCodexProcess};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=`closerepo-ai-provider-result:`;export{e as codexSimpleWorkerResultPrefix};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"node:child_process";import{syncBuiltinESMExports as t}from"node:module";import{resolve as n}from"node:path";import{NoObjectGeneratedError as r,NoOutputGeneratedError as i,Output as a,generateText as o,jsonSchema as s}from"ai";const c=Object.freeze({"agents.enabled":!1,project_doc_max_bytes:0,"features.apps":!1,"features.code_mode":!1,"features.code_mode_host":!1,"features.code_mode_only":!1,"features.goals":!1,"features.hooks":!1,"features.image_generation":!1,"features.multi_agent":!1,"features.multi_agent_v2":!1,"features.personality":!1,"features.plugin_sharing":!1,"features.plugins":!1,"features.remote_plugin":!1,"features.respect_system_proxy":!0,"features.shell_tool":!1,"features.skill_search":!1,"features.unified_exec":!1,"features.workspace_dependencies":!1,"orchestrator.mcp.enabled":!1,"orchestrator.skills.enabled":!1,"tools.experimental_request_user_input.enabled":!1,"tools.web_search":!1}),l=Object.freeze({...c,include_apps_instructions:!1,include_collaboration_mode_instructions:!1,include_environment_context:!1,include_permissions_instructions:!1,"skills.include_instructions":!1});Object.freeze([`check_for_update_on_startup = false`,...Object.entries(l).map(([e,t])=>`${e} = ${String(t)}`),``].join(`
|
|
2
|
+
`));function u(e){let t=JSON.stringify(e,(e,t)=>{if(t===void 0||typeof t==`bigint`||typeof t==`function`||typeof t==`symbol`||typeof t==`number`&&!Number.isFinite(t))throw TypeError(`invalid_json_value`);return t});if(typeof t!=`string`)throw TypeError(`invalid_json_value`);return t}const d=e.spawn,f=[];Object.assign(e,{spawn:((...e)=>{let t=d(...e),n={child:t,closed:!1,close:Promise.resolve()};return n.close=new Promise(e=>{let r=()=>{n.closed||(n.closed=!0,e())};t.once(`exit`,r),t.once(`close`,r),t.once(`error`,r)}),f.push(n),t})}),t();function p(e){return typeof e==`object`&&!!e}function m(e,t){let n=e;for(let e=0;e<4;e+=1){if(!p(n))return!1;if(n.code===t)return!0;n=n.cause}return!1}function h(e){let t=e;for(let e=0;e<4;e+=1){if(!p(t))return!1;if(typeof t.message==`string`&&(/\bhit your usage limit\b/iu.test(t.message)||/\busage[_\s-]+limit[_\s-]+(?:exceeded|reached)\b/iu.test(t.message)))return!0;t=t.cause}return!1}function g(e){return typeof e==`string`&&e.length>0&&e.length<=256&&!/[\u0000-\u001F\u007F]/u.test(e)?e:null}function _(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0?e:null}function v(e){return JSON.parse(JSON.stringify(e))}async function y(){let e=``;process.stdin.setEncoding(`utf8`);for await(let t of process.stdin)e+=String(t);return JSON.parse(e)}async function b(e,t){if(e.every(e=>e.closed))return!0;let n,r=new Promise(e=>{n=setTimeout(()=>e(!1),t)}),i=Promise.all(e.map(e=>e.close)).then(()=>!0),a=await Promise.race([i,r]);return n!==void 0&&clearTimeout(n),a}async function x(e){let t=process.env.SystemRoot??process.env.WINDIR,r=t===void 0?`taskkill.exe`:n(t,`System32`,`taskkill.exe`);await new Promise(t=>{let n=d(r,[`/pid`,String(e),`/t`,`/f`],{stdio:`ignore`,windowsHide:!0});n.once(`error`,()=>t()),n.once(`close`,()=>t())})}async function S(e){if(!(e.closed||e.child.pid===void 0)){if(process.platform===`win32`){await x(e.child.pid);return}try{e.child.kill(`SIGKILL`)}catch{return}}}async function C(){let e=[...f];if(!await b(e,2e3)&&(await Promise.all(e.map(S)),!await b(e,3e3)))throw Error(`codex_child_cleanup_failed`)}function w(e,t){if(m(e,`ENOENT`))return{code:`unavailable`,phase:`initialize`};if(h(e))return{code:`provider_rejected`,phase:`turn_execution`,providerCode:`codex_usage_limit_exceeded`};try{if(t.isUnsupportedFeatureError(e))return{code:`protocol_incompatible`,phase:`turn_execution`}}catch{}try{if(t.isAuthenticationError(e))return{code:`provider_rejected`,phase:`turn_execution`}}catch{}return r.isInstance(e)||i.isInstance(e)?{code:`invalid_response`,phase:`response_parse`}:p(e)&&e.name===`AbortError`?{code:`aborted`}:{code:`provider_rejected`,phase:`turn_execution`}}async function T(e){let t=await import(`ai-sdk-provider-codex-cli`),n=t.createCodexAppServer({defaultSettings:{codexPath:e.executable,cwd:e.cwd,connectionTimeoutMs:Math.min(e.timeoutMs,3e4),requestTimeoutMs:Math.min(2147483647,e.timeoutMs+1e3),idleTimeoutMs:e.timeoutMs,logger:!1}}),r;try{let t={model:n(e.model,{threadMode:`stateless`,autoApprove:!1,approvalPolicy:`never`,sandboxPolicy:`read-only`,personality:`none`,baseInstructions:[`You are a single-turn text generation engine.`,`Follow only the developer instructions and user input supplied for this request.`,`Do not inspect files, invoke tools, use skills, access the network, or rely on external context.`,`Return only the requested output.`].join(` `),mcpServers:{},rmcpClient:!1,configOverrides:{...c,...e.reasoningEffort===void 0?{}:{model_reasoning_effort:e.reasoningEffort}}}),instructions:e.instructions,prompt:e.input,maxRetries:0},i=e.responseFormat.type===`json_schema`?await o({...t,output:a.object({name:e.responseFormat.name,schema:s(v(e.responseFormat.schema))})}):await o(t),l=e.responseFormat.type===`json_schema`?JSON.stringify(i.output):i.text,d=i.steps.at(-1)?.usage.raw??i.usage.raw,f=d===void 0?void 0:JSON.parse(u(d));r={ok:!0,observation:{text:l,providerRequestId:g(i.response.id),model:g(i.response.modelId)??e.model,usage:{inputTokens:_(i.usage.inputTokens),inputTokenDetails:{noCacheTokens:_(i.usage.inputTokenDetails.noCacheTokens),cacheReadTokens:_(i.usage.inputTokenDetails.cacheReadTokens),cacheWriteTokens:_(i.usage.inputTokenDetails.cacheWriteTokens)},outputTokens:_(i.usage.outputTokens),outputTokenDetails:{textTokens:_(i.usage.outputTokenDetails.textTokens),reasoningTokens:_(i.usage.outputTokenDetails.reasoningTokens)},totalTokens:_(i.usage.totalTokens),...f===void 0?{}:{raw:f}}}}}catch(e){r={ok:!1,error:w(e,t)}}try{await n.close(),await C()}catch{return{ok:!1,error:{code:`cleanup_failed`}}}return r}async function E(e){let t=`closerepo-ai-provider-result:${JSON.stringify(e)}\n`;await new Promise((e,n)=>{process.stdout.write(t,t=>{t==null?e():n(t)})})}let D;try{D=await T(await y())}catch{D={ok:!1,error:{code:`unavailable`,phase:`initialize`}}}await E(D);
|
package/dist/codex.d.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { CodexAppServerSettings } from "ai-sdk-provider-codex-cli";
|
|
2
|
+
import { LanguageModelV4 } from "@ai-sdk/provider";
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare const aiProviderErrorCodes: readonly ["invalid_configuration", "unsupported_response_format", "aborted", "timeout", "unavailable", "provider_rejected", "invalid_response", "protocol_incompatible", "unsafe_provider_event", "network_destination_blocked", "network_guard_unobserved", "output_limit_exceeded", "cleanup_failed"];
|
|
5
|
+
declare const aiProviderErrorPhases: readonly ["initialize", "thread_start", "turn_start", "turn_execution", "response_receive", "response_read", "response_parse", "response_normalize"];
|
|
6
|
+
declare const aiProviderDiagnosticCodes: readonly ["json_rpc_parse_error", "json_rpc_invalid_request", "json_rpc_method_not_found", "json_rpc_invalid_params", "json_rpc_internal_error", "codex_context_window_exceeded", "codex_session_budget_exceeded", "codex_usage_limit_exceeded", "codex_server_overloaded", "codex_cyber_policy", "codex_internal_server_error", "codex_unauthorized", "codex_bad_request", "codex_thread_rollback_failed", "codex_sandbox_error", "codex_other", "codex_http_connection_failed", "codex_response_stream_connection_failed", "codex_response_stream_disconnected", "codex_response_too_many_failed_attempts", "codex_active_turn_not_steerable", "fetch_response_invalid", "response_body_missing", "response_body_read_failed", "response_json_invalid", "response_choices_invalid", "response_message_invalid", "response_model_invalid", "codex_executable_not_configured", "codex_executable_path_invalid", "codex_executable_unavailable"];
|
|
7
|
+
declare namespace AiProvider {
|
|
8
|
+
/** A JSON-compatible primitive accepted by structured output schemas. */
|
|
9
|
+
type JsonPrimitive = boolean | number | string | null;
|
|
10
|
+
/** A recursively JSON-compatible value accepted by provider adapters. */
|
|
11
|
+
type JsonValue = JsonPrimitive | readonly JsonValue[] | {
|
|
12
|
+
readonly [key: string]: JsonValue;
|
|
13
|
+
};
|
|
14
|
+
/** A JSON object used as the provider-neutral structured output schema. */
|
|
15
|
+
type JsonObject = {
|
|
16
|
+
readonly [key: string]: JsonValue;
|
|
17
|
+
};
|
|
18
|
+
/** The output shape requested from a text generation provider. */
|
|
19
|
+
type ResponseFormat = {
|
|
20
|
+
readonly type: "text";
|
|
21
|
+
} | {
|
|
22
|
+
readonly type: "json_object";
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: "json_schema";
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly schema: JsonObject;
|
|
27
|
+
readonly strict?: boolean;
|
|
28
|
+
};
|
|
29
|
+
/** The adapter, provider, and effective model that produced a result. */
|
|
30
|
+
interface Identity {
|
|
31
|
+
readonly adapterId: string;
|
|
32
|
+
readonly providerId: string;
|
|
33
|
+
readonly model: string;
|
|
34
|
+
}
|
|
35
|
+
/** Token usage when the underlying provider reports it. */
|
|
36
|
+
interface Usage {
|
|
37
|
+
readonly inputTokens: number | null;
|
|
38
|
+
/** Standard input-token breakdown exposed by the adapter. */
|
|
39
|
+
readonly inputTokenDetails?: {
|
|
40
|
+
readonly noCacheTokens: number | null;
|
|
41
|
+
readonly cacheReadTokens: number | null;
|
|
42
|
+
readonly cacheWriteTokens: number | null;
|
|
43
|
+
};
|
|
44
|
+
readonly outputTokens: number | null;
|
|
45
|
+
/** Standard output-token breakdown exposed by the adapter. */
|
|
46
|
+
readonly outputTokenDetails?: {
|
|
47
|
+
readonly textTokens: number | null;
|
|
48
|
+
readonly reasoningTokens: number | null;
|
|
49
|
+
};
|
|
50
|
+
readonly totalTokens: number | null;
|
|
51
|
+
/** Provider-native usage fields, retained for evidence that cannot be reconstructed later. */
|
|
52
|
+
readonly raw?: JsonObject;
|
|
53
|
+
}
|
|
54
|
+
/** Observable network traffic owned by an adapter-level transport guard. */
|
|
55
|
+
interface NetworkUsage {
|
|
56
|
+
readonly connectionCount: number;
|
|
57
|
+
readonly receivedBytes: number;
|
|
58
|
+
}
|
|
59
|
+
/** One stateless text generation request. */
|
|
60
|
+
interface TextGenerationRequest {
|
|
61
|
+
readonly instructions: string;
|
|
62
|
+
readonly input: string;
|
|
63
|
+
readonly responseFormat?: ResponseFormat;
|
|
64
|
+
readonly temperature?: number;
|
|
65
|
+
readonly signal?: AbortSignal;
|
|
66
|
+
}
|
|
67
|
+
/** The normalized result of one text generation request. */
|
|
68
|
+
interface TextGenerationResult {
|
|
69
|
+
readonly text: string;
|
|
70
|
+
readonly identity: Identity;
|
|
71
|
+
readonly providerRequestId: string | null;
|
|
72
|
+
readonly latencyMs: number;
|
|
73
|
+
readonly usage: Usage;
|
|
74
|
+
readonly networkUsage?: NetworkUsage;
|
|
75
|
+
}
|
|
76
|
+
/** A stateless provider that performs one text generation request at a time. */
|
|
77
|
+
interface TextGenerationProvider {
|
|
78
|
+
readonly identity: Identity;
|
|
79
|
+
readonly supportedResponseFormats: readonly ResponseFormat["type"][];
|
|
80
|
+
generate(request: TextGenerationRequest): Promise<TextGenerationResult>;
|
|
81
|
+
}
|
|
82
|
+
/** Stable technical failures emitted by built-in adapters. */
|
|
83
|
+
type ErrorCode = (typeof aiProviderErrorCodes)[number];
|
|
84
|
+
/** Stable adapter phase at which a provider failure became observable. */
|
|
85
|
+
type ErrorPhase = (typeof aiProviderErrorPhases)[number];
|
|
86
|
+
/** Allowlisted machine code extracted from a provider protocol failure. */
|
|
87
|
+
type DiagnosticCode = (typeof aiProviderDiagnosticCodes)[number];
|
|
88
|
+
/** Safe failure metadata that excludes provider messages and payloads. */
|
|
89
|
+
interface ErrorDiagnostic {
|
|
90
|
+
readonly phase: ErrorPhase;
|
|
91
|
+
readonly providerCode: DiagnosticCode | null;
|
|
92
|
+
readonly httpStatusCode: number | null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
type TextGenerationProvider = AiProvider.TextGenerationProvider;
|
|
96
|
+
type TextGenerationRequest = AiProvider.TextGenerationRequest;
|
|
97
|
+
type TextGenerationResult = AiProvider.TextGenerationResult;
|
|
98
|
+
type AiProviderErrorDiagnostic = AiProvider.ErrorDiagnostic;
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/codex-network-guard.d.ts
|
|
101
|
+
type CodexNetworkViolationKind = "destination_blocked";
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/codex.d.ts
|
|
104
|
+
type ManagedProcessSetting = "codexPath" | "connectionTimeoutMs" | "cwd" | "env" | "idleTimeoutMs" | "logger" | "minCodexVersion" | "requestTimeoutMs" | "verbose";
|
|
105
|
+
declare const codexExecutableBrand: unique symbol;
|
|
106
|
+
declare namespace Codex {
|
|
107
|
+
/** Host-resolved Codex executable used to start the App Server. */
|
|
108
|
+
interface Executable {
|
|
109
|
+
readonly command: string;
|
|
110
|
+
readonly [codexExecutableBrand]: true;
|
|
111
|
+
}
|
|
112
|
+
/** Safe diagnostics emitted when the simple provider cannot finish a turn. */
|
|
113
|
+
interface RuntimeEvent {
|
|
114
|
+
readonly schemaVersion: 1;
|
|
115
|
+
readonly event: "turn_error";
|
|
116
|
+
readonly willRetry: false;
|
|
117
|
+
readonly retryCount: 0;
|
|
118
|
+
readonly elapsedMs: number;
|
|
119
|
+
readonly diagnostic: AiProviderErrorDiagnostic;
|
|
120
|
+
readonly network?: {
|
|
121
|
+
readonly connectionCount: number;
|
|
122
|
+
readonly receivedBytes: number;
|
|
123
|
+
readonly destinationHost: string | null;
|
|
124
|
+
readonly violation: CodexNetworkViolationKind | "unobserved";
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/** Configuration for the provider-neutral, per-request Codex adapter. */
|
|
128
|
+
interface Config {
|
|
129
|
+
readonly model: string;
|
|
130
|
+
readonly reasoningEffort?: string;
|
|
131
|
+
readonly timeoutMs: number;
|
|
132
|
+
readonly executable: Executable;
|
|
133
|
+
readonly onRuntimeEvent?: (event: RuntimeEvent) => void;
|
|
134
|
+
}
|
|
135
|
+
/** Process settings owned by the managed Codex boundary. */
|
|
136
|
+
interface ManagedConfig {
|
|
137
|
+
readonly executable: Executable;
|
|
138
|
+
readonly cwd?: string;
|
|
139
|
+
readonly connectionTimeoutMs?: number;
|
|
140
|
+
readonly requestTimeoutMs?: number;
|
|
141
|
+
readonly idleTimeoutMs?: number;
|
|
142
|
+
readonly minimumCodexVersion?: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* AI SDK model settings that remain caller-owned.
|
|
146
|
+
*
|
|
147
|
+
* Process path, environment, logging, working directory, and lifecycle
|
|
148
|
+
* timeouts stay on ManagedConfig so one owner controls the child process.
|
|
149
|
+
*/
|
|
150
|
+
type ManagedModelSettings = Omit<CodexAppServerSettings, ManagedProcessSetting>;
|
|
151
|
+
/** Safe model metadata projected from the local Codex catalog. */
|
|
152
|
+
interface Model {
|
|
153
|
+
readonly id: string;
|
|
154
|
+
readonly displayName: string | null;
|
|
155
|
+
readonly description: string | null;
|
|
156
|
+
readonly hidden: boolean;
|
|
157
|
+
readonly isDefault: boolean;
|
|
158
|
+
}
|
|
159
|
+
/** Optional filter used when reading the local Codex model catalog. */
|
|
160
|
+
interface ModelQuery {
|
|
161
|
+
readonly modelProviders?: readonly string[];
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Managed AI SDK-native Codex provider.
|
|
165
|
+
*
|
|
166
|
+
* The caller passes model() directly to AI SDK generateText or streamText
|
|
167
|
+
* and must close this owner when the host lifecycle ends.
|
|
168
|
+
*/
|
|
169
|
+
interface ManagedProvider {
|
|
170
|
+
model(modelId: string, settings?: ManagedModelSettings): LanguageModelV4;
|
|
171
|
+
listModels(query?: ModelQuery): Promise<readonly Model[]>;
|
|
172
|
+
close(): Promise<void>;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** Host environment key that owns the local Codex executable path. */
|
|
176
|
+
declare const codexExecutableEnvironmentVariable: "CODEX_EXECUTABLE_PATH";
|
|
177
|
+
/** Resolves the one host-owned Codex executable without consulting PATH. */
|
|
178
|
+
declare function resolveCodexExecutable(): Codex.Executable;
|
|
179
|
+
/**
|
|
180
|
+
* Creates an AI SDK-native Codex provider with one explicit process owner.
|
|
181
|
+
*
|
|
182
|
+
* Use model() directly with AI SDK generateText or streamText, then call
|
|
183
|
+
* close() when the host lifecycle ends.
|
|
184
|
+
*/
|
|
185
|
+
declare function createManagedCodexProvider(config: Codex.ManagedConfig): Codex.ManagedProvider;
|
|
186
|
+
/** Creates the provider-neutral adapter backed by AI SDK Codex App Server. */
|
|
187
|
+
declare function createCodexProvider(config: Codex.Config): TextGenerationProvider;
|
|
188
|
+
//#endregion
|
|
189
|
+
export { Codex, codexExecutableEnvironmentVariable, createCodexProvider, createManagedCodexProvider, resolveCodexExecutable };
|
package/dist/codex.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{statSync as e}from"node:fs";import{chmod as t,copyFile as n,mkdir as r,mkdtemp as i,rm as a,stat as o,writeFile as s}from"node:fs/promises";import{homedir as c,tmpdir as l}from"node:os";import{isAbsolute as u,join as d,resolve as f}from"node:path";import{NoObjectGeneratedError as p,NoOutputGeneratedError as m,wrapLanguageModel as h}from"ai";import{createCodexAppServer as g,isAuthenticationError as ee,isUnsupportedFeatureError as te}from"ai-sdk-provider-codex-cli";import{spawn as _}from"node:child_process";import{fileURLToPath as ne}from"node:url";import{createServer as re}from"node:http";import{Socket as ie}from"node:net";const ae=[`invalid_configuration`,`unsupported_response_format`,`aborted`,`timeout`,`unavailable`,`provider_rejected`,`invalid_response`,`protocol_incompatible`,`unsafe_provider_event`,`network_destination_blocked`,`network_guard_unobserved`,`output_limit_exceeded`,`cleanup_failed`],oe=[`initialize`,`thread_start`,`turn_start`,`turn_execution`,`response_receive`,`response_read`,`response_parse`,`response_normalize`],se=`json_rpc_parse_error.json_rpc_invalid_request.json_rpc_method_not_found.json_rpc_invalid_params.json_rpc_internal_error.codex_context_window_exceeded.codex_session_budget_exceeded.codex_usage_limit_exceeded.codex_server_overloaded.codex_cyber_policy.codex_internal_server_error.codex_unauthorized.codex_bad_request.codex_thread_rollback_failed.codex_sandbox_error.codex_other.codex_http_connection_failed.codex_response_stream_connection_failed.codex_response_stream_disconnected.codex_response_too_many_failed_attempts.codex_active_turn_not_steerable.fetch_response_invalid.response_body_missing.response_body_read_failed.response_json_invalid.response_choices_invalid.response_message_invalid.response_model_invalid.codex_executable_not_configured.codex_executable_path_invalid.codex_executable_unavailable`.split(`.`),v=Symbol.for(`@closerepo/ai-provider/AiProviderError`),y=new Set(ae),ce=new Set(oe),le=new Set(se);function b(e){if(typeof e!=`object`||!e)return!1;let t=e;return Object.keys(t).length===3&&typeof t.phase==`string`&&ce.has(t.phase)&&(t.providerCode===null||typeof t.providerCode==`string`&&le.has(t.providerCode))&&(t.httpStatusCode===null||Number.isInteger(t.httpStatusCode)&&t.httpStatusCode>=100&&t.httpStatusCode<=599)}function ue(e){if(typeof e!=`object`||!e)return!1;let t=e;return t[v]===!0&&t.name===`AiProviderError`&&typeof t.code==`string`&&y.has(t.code)&&(t.providerRequestId===null||typeof t.providerRequestId==`string`)&&(t.diagnostic===null||b(t.diagnostic))}var x=class extends Error{code;providerRequestId;diagnostic;constructor(e){if(typeof e!=`object`||!e||!y.has(e.code)||e.providerRequestId!==void 0&&e.providerRequestId!==null&&(typeof e.providerRequestId!=`string`||e.providerRequestId.length===0||e.providerRequestId.length>256||/[\u0000-\u001F\u007F]/.test(e.providerRequestId))||e.diagnostic!==void 0&&e.diagnostic!==null&&!b(e.diagnostic))throw TypeError(`invalid_ai_provider_error`);super(e.code),this.name=`AiProviderError`,this.code=e.code,this.providerRequestId=e.providerRequestId??null,this.diagnostic=e.diagnostic===void 0||e.diagnostic===null?null:Object.freeze({...e.diagnostic}),this.stack=`${this.name}: ${this.message}`,Object.defineProperty(this,v,{value:!0})}static[Symbol.hasInstance](e){return ue(e)}};function S(e){return e instanceof x}function de(e){let t=JSON.stringify(e,(e,t)=>{if(t===void 0||typeof t==`bigint`||typeof t==`function`||typeof t==`symbol`||typeof t==`number`&&!Number.isFinite(t))throw TypeError(`invalid_json_value`);return t});if(typeof t!=`string`)throw TypeError(`invalid_json_value`);return t}const C=2e3,fe=new Set([`invalid_configuration`,`unsupported_response_format`,`aborted`,`timeout`,`unavailable`,`provider_rejected`,`invalid_response`,`protocol_incompatible`,`unsafe_provider_event`,`network_destination_blocked`,`network_guard_unobserved`,`output_limit_exceeded`,`cleanup_failed`]),pe=new Set([`initialize`,`thread_start`,`turn_start`,`turn_execution`,`response_receive`,`response_read`,`response_parse`,`response_normalize`]),me=new Set([`codex_usage_limit_exceeded`]);function he(){let e=import.meta.url.endsWith(`.ts`)?`.ts`:`.js`;return ne(new URL(`./codex-simple-worker${e}`,import.meta.url))}function ge(e,t){let n=process.env[t];typeof n==`string`&&n.length>0&&(e[t]=n)}function _e(e){let t={...e,NO_COLOR:`1`,RUST_LOG:`error`};for(let e of process.platform===`win32`?[`PATH`,`Path`,`PATHEXT`,`SystemRoot`,`WINDIR`,`ComSpec`]:[`PATH`])ge(t,e);return t}function w(e,t){let n=e+String(t);if(Buffer.byteLength(n)>5242880)throw new x({code:`output_limit_exceeded`});return n}function T(){return new x({code:`cleanup_failed`})}function ve(e,t){return typeof e==`object`&&!!e&&`code`in e&&e.code===t}async function E(e,t){let n=process.env.SystemRoot??process.env.WINDIR,r=n===void 0?`taskkill.exe`:f(n,`System32`,`taskkill.exe`);return await new Promise(n=>{let i=!1,a=!1,o,s,c=e=>{i||(i=!0,o!==void 0&&clearTimeout(o),s!==void 0&&clearTimeout(s),n(e))};try{let n=_(r,[`/pid`,String(e),`/t`,...t?[`/f`]:[]],{stdio:`ignore`,windowsHide:!0});n.once(`error`,()=>c(!1)),n.once(`close`,e=>c(!a&&e===0)),o=setTimeout(()=>{a=!0;try{n.kill()}catch{}s=setTimeout(()=>c(!1),250)},t?3e3:500)}catch{c(!1)}})}async function D(e,t,n){if(t())return!0;let r,i=new Promise(e=>{r=setTimeout(()=>e(!1),n)}),a=await Promise.race([e.then(()=>!0),i]);return r!==void 0&&clearTimeout(r),a}function O(e){try{return process.kill(-e,0),!0}catch(e){return!ve(e,`ESRCH`)}}function k(e,t,n){try{process.kill(-t,n)}catch{try{e.kill(n)}catch{}}}async function A(e,t,n){let r=performance.now()+n;for(;performance.now()<r;){if(t()&&!O(e))return!0;await new Promise(e=>{setTimeout(e,25)})}return t()&&!O(e)}async function ye(e,t,n){if(n())return;let r=e.pid;if(r===void 0){if(await D(t,n,C))return;throw T()}if(process.platform===`win32`){let e=await E(r,!1);if(e&&await D(t,n,500))return;let i=await E(r,!0);if(await D(t,n,C)&&(i||e))return;throw T()}if(k(e,r,`SIGTERM`),!await A(r,n,500)&&(k(e,r,`SIGKILL`),!await A(r,n,C)))throw T()}function be(e){let t=e.split(/\r?\n/u).findLast(e=>e.startsWith(`closerepo-ai-provider-result:`));if(t===void 0)throw new x({code:`invalid_response`});let n;try{n=JSON.parse(t.slice(29))}catch{throw new x({code:`invalid_response`})}if(typeof n!=`object`||!n||!(`ok`in n))throw new x({code:`invalid_response`});return n}function xe(e){if(e.ok)throw new x({code:`invalid_response`});let t=fe.has(e.error.code)?e.error.code:`provider_rejected`,n=e.error.phase!==void 0&&pe.has(e.error.phase)?e.error.phase:void 0,r=e.error.providerCode!==void 0&&me.has(e.error.providerCode)?e.error.providerCode:null;return new x({code:t,...n===void 0?{}:{diagnostic:{phase:n,providerCode:r,httpStatusCode:null}}})}async function j(e,t,n){if(n.aborted)throw new DOMException(`aborted`,`AbortError`);let r=_(process.execPath,[he()],{cwd:e.cwd,env:_e(t),stdio:[`pipe`,`pipe`,`pipe`],windowsHide:!0,detached:process.platform!==`win32`}),i=``,a=``,o=null,s=!1,c=!1,l=null,u=new Promise(e=>{r.once(`error`,e=>{l=e}),r.once(`close`,t=>{c=!0,e({code:t,spawnError:l})})}),d=()=>{},f=()=>{},p=new Promise((e,t)=>{d=e,f=t}),m=null,h=()=>{if(m!==null)return m;let e=ye(r,u,()=>c);return m=e,e.then(d,f),e};r.stdout?.setEncoding(`utf8`),r.stderr?.setEncoding(`utf8`),r.stdout?.on(`data`,e=>{if(o===null)try{i=w(i,e)}catch(e){o=e,h()}}),r.stderr?.on(`data`,e=>{if(o===null)try{a=w(a,e)}catch(e){o=e,h()}});let g=()=>{s=!0,h()};n.addEventListener(`abort`,g,{once:!0}),n.aborted&&g();try{r.stdin?.end(JSON.stringify(e));let t=await Promise.race([u,p.then(()=>u)]);if(s)throw new DOMException(`aborted`,`AbortError`);if(o!==null)throw o;if(t.spawnError!==null||t.code!==0)throw new x({code:t.spawnError===null?`provider_rejected`:`unavailable`});let n=be(i);if(!n.ok)throw xe(n);return n.observation}finally{n.removeEventListener(`abort`,g),m===null?c||await h():await m}}const M=Object.freeze({"agents.enabled":!1,project_doc_max_bytes:0,"features.apps":!1,"features.code_mode":!1,"features.code_mode_host":!1,"features.code_mode_only":!1,"features.goals":!1,"features.hooks":!1,"features.image_generation":!1,"features.multi_agent":!1,"features.multi_agent_v2":!1,"features.personality":!1,"features.plugin_sharing":!1,"features.plugins":!1,"features.remote_plugin":!1,"features.respect_system_proxy":!0,"features.shell_tool":!1,"features.skill_search":!1,"features.unified_exec":!1,"features.workspace_dependencies":!1,"orchestrator.mcp.enabled":!1,"orchestrator.skills.enabled":!1,"tools.experimental_request_user_input.enabled":!1,"tools.web_search":!1}),Se=Object.freeze({...M,include_apps_instructions:!1,include_collaboration_mode_instructions:!1,include_environment_context:!1,include_permissions_instructions:!1,"skills.include_instructions":!1}),Ce=Object.freeze([`check_for_update_on_startup = false`,...Object.entries(Se).map(([e,t])=>`${e} = ${String(t)}`),``].join(`
|
|
2
|
+
`));function we(e){if(e===void 0||e.length===0)return null;try{let t=new URL(`http://${e}`),n=t.port.length===0?443:Number(t.port);return t.username.length>0||t.password.length>0||t.pathname!==`/`||t.search.length>0||t.hash.length>0||t.hostname.length===0||!Number.isSafeInteger(n)||n<1||n>65535?null:{host:t.hostname.toLowerCase(),port:n}}catch{return null}}function Te(e,t){return t.some(t=>e===t||e.endsWith(`.${t}`))}function Ee(e){return Object.freeze({connectionCount:e.connectionCount,receivedBytes:e.receivedBytes,violation:e.violation===null?null:Object.freeze({...e.violation})})}async function De(e){let t=new Set,n=0,r=0,i=null,a=!1,o=()=>{for(let e of t)e.destroy()},s=(e,t)=>{i===null&&(i=Object.freeze({kind:e,destinationHost:t}),o())},c=e=>{t.add(e),e.once(`close`,()=>t.delete(e))},l=re((e,t)=>{t.writeHead(502,{Connection:`close`}),t.end(),s(`destination_blocked`,null)});l.on(`connection`,c),l.on(`connect`,(t,a,o)=>{let l=we(t.url);if(l===null){a.end(`HTTP/1.1 400 Bad Request\r
|
|
3
|
+
Connection: close\r
|
|
4
|
+
\r
|
|
5
|
+
`);return}if(n+=1,i!==null){a.destroy();return}if(Te(l.host,e.blockedHostSuffixes)){s(`destination_blocked`,l.host),a.destroy();return}let u=new ie;u.connect({host:l.host,port:l.port}),c(u);let d=()=>{a.destroy(),u.destroy()};a.once(`error`,d),u.once(`error`,d),a.once(`close`,()=>u.destroy()),u.once(`close`,()=>a.destroy()),u.once(`connect`,()=>{a.write(`HTTP/1.1 200 Connection Established\r
|
|
6
|
+
\r
|
|
7
|
+
`),o.byteLength>0&&u.write(o),a.pipe(u),u.on(`data`,e=>{r+=e.byteLength,a.write(e)||(u.pause(),a.once(`drain`,()=>u.resume()))})})}),await new Promise((e,t)=>{let n=e=>{l.off(`listening`,r),t(e)},r=()=>{l.off(`error`,n),e()};l.once(`error`,n),l.once(`listening`,r),l.listen(0,`127.0.0.1`)});let u=l.address();if(u===null||typeof u==`string`)throw l.close(),Error(`codex_network_guard_address_unavailable`);let d=`http://127.0.0.1:${u.port}`;return Object.freeze({environment:Object.freeze({ALL_PROXY:d,HTTP_PROXY:d,HTTPS_PROXY:d,NO_PROXY:``,all_proxy:d,http_proxy:d,https_proxy:d,no_proxy:``}),observe(){return Ee({connectionCount:n,receivedBytes:r,violation:i})},async close(){a||(a=!0,o(),await new Promise((e,t)=>{l.close(n=>n===void 0?e():t(n))}))}})}const Oe=Symbol(`@closerepo/ai-provider/codex-executable`),N=new WeakSet,P=`CODEX_EXECUTABLE_PATH`,ke={runIsolatedCodexProcess:j,createCodexNetworkGuard:De},F=32*1024,Ae=/^[A-Za-z0-9_-]{1,64}$/,je=/^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?$/,I=/[\u0000-\u001F\u007F]/,Me=Object.freeze([`oaiusercontent.com`]),Ne=new Set([`codexPath`,`connectionTimeoutMs`,`cwd`,`env`,`idleTimeoutMs`,`logger`,`minCodexVersion`,`requestTimeoutMs`,`verbose`]);function L(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function R(e){return e.trim().length>0}function z(){return new x({code:`invalid_configuration`})}function B(e){return new x({code:`invalid_configuration`,diagnostic:{phase:`initialize`,providerCode:e,httpStatusCode:null}})}function V(t){if(typeof t!=`string`||!R(t)||t.length>F||I.test(t))throw B(`codex_executable_path_invalid`);let n=t.trim();if(!u(n))throw B(`codex_executable_path_invalid`);try{if(!e(n).isFile())throw B(`codex_executable_unavailable`)}catch(e){throw S(e)?e:B(`codex_executable_unavailable`)}return n}function Pe(e){return L(e)&&N.has(e)}function H(e){if(e===void 0)throw B(`codex_executable_not_configured`);if(!Pe(e)||Object.keys(e).some(e=>e!==`command`))throw B(`codex_executable_path_invalid`);return V(e.command),e}function Fe(){let e=process.env[P];if(e===void 0||e.trim().length===0)throw B(`codex_executable_not_configured`);let t=Object.freeze({[Oe]:!0,command:V(e)});return N.add(t),t}function U(e){return{phase:e,providerCode:null,httpStatusCode:null}}function W(e,t){if(typeof e!=`string`||!R(e)||e.length>t||I.test(e))throw z()}function G(e){if(typeof e!=`number`||!Number.isInteger(e)||e<=0||e>2147483647)throw z()}function Ie(e){if(!L(e)||typeof e.aborted!=`boolean`||typeof e.addEventListener!=`function`||typeof e.removeEventListener!=`function`)throw z()}function K(e){let t;try{t=de(e)}catch{throw z()}if(new TextEncoder().encode(t).byteLength>1048576)throw z();return t}function Le(e){if(e===void 0)throw B(`codex_executable_not_configured`);if(!L(e))throw z();let t=e,n=H(t.executable);if(t.cwd!==void 0&&W(t.cwd,F),t.connectionTimeoutMs!==void 0&&G(t.connectionTimeoutMs),t.requestTimeoutMs!==void 0&&G(t.requestTimeoutMs),t.idleTimeoutMs!==void 0&&G(t.idleTimeoutMs),t.minimumCodexVersion!==void 0&&(typeof t.minimumCodexVersion!=`string`||!je.test(t.minimumCodexVersion)))throw z();return{executable:n,...t.cwd===void 0?{}:{cwd:t.cwd},connectionTimeoutMs:t.connectionTimeoutMs??3e4,requestTimeoutMs:t.requestTimeoutMs??6e5,idleTimeoutMs:t.idleTimeoutMs??3e5,minimumCodexVersion:t.minimumCodexVersion??`0.144.0`}}function Re(e){if(!L(e)||(W(e.model,256),G(e.timeoutMs),e.reasoningEffort!==void 0&&W(e.reasoningEffort,64),e.onRuntimeEvent!==void 0&&typeof e.onRuntimeEvent!=`function`))throw z();let t=H(e.executable);return{model:e.model.trim(),...e.reasoningEffort===void 0?{}:{reasoningEffort:e.reasoningEffort.trim()},timeoutMs:e.timeoutMs,executable:t,...e.onRuntimeEvent===void 0?{}:{onRuntimeEvent:e.onRuntimeEvent}}}function ze(){let e=process.env.CODEX_HOME?.trim();return f(e===void 0||e.length===0?d(c(),`.codex`):e)}async function Be(e){try{return(await o(e)).isFile()}catch(e){if(L(e)&&e.code===`ENOENT`)return!1;throw e}}async function q(e){for(let t=1;t<=120;t+=1)try{await a(e,{recursive:!0,force:!0});return}catch(e){if(t===120)throw e;await new Promise(e=>{setTimeout(e,250)})}}async function Ve(){let e=await i(d(l(),`closerepo-ai-provider-codex-`)),a=d(e,`workspace`),o=d(e,`user-home`),c=d(e,`codex-home`),u=d(o,`.config`),f=d(o,`.local`,`share`);try{await Promise.all([r(a,{recursive:!0,mode:448}),r(o,{recursive:!0,mode:448}),r(c,{recursive:!0,mode:448}),r(u,{recursive:!0,mode:448}),r(f,{recursive:!0,mode:448})]),await s(d(c,`config.toml`),Ce,{encoding:`utf8`,flag:`wx`,mode:384});let e=d(ze(),`auth.json`);if(await Be(e)){let r=d(c,`auth.json`);await n(e,r),await t(r,384)}}catch(t){try{await q(e)}catch{throw new x({code:`cleanup_failed`})}throw t}let p=!1;return{root:e,cwd:a,environment:Object.freeze({CODEX_HOME:c,HOME:o,USERPROFILE:o,XDG_CONFIG_HOME:u,XDG_DATA_HOME:f}),async cleanup(){p||=(await q(e),!0)}}}function He(e){if(!L(e)||typeof e.instructions!=`string`||typeof e.input!=`string`||e.temperature!==void 0)throw z();e.signal!==void 0&&Ie(e.signal);let t=e.responseFormat??{type:`text`};if(!L(t)||typeof t.type!=`string`)throw z();if(t.type===`json_object`)throw new x({code:`unsupported_response_format`});if(t.type===`text`){let t=K({input:e.input,instructions:e.instructions,responseFormat:{type:`text`}});return JSON.parse(t)}if(t.type!==`json_schema`||typeof t.name!=`string`||!Ae.test(t.name)||!L(t.schema)||t.strict!==void 0&&typeof t.strict!=`boolean`)throw z();let n=K({input:e.input,instructions:e.instructions,responseFormat:{type:`json_schema`,name:t.name,schema:t.schema,...t.strict===void 0?{}:{strict:t.strict}}});return JSON.parse(n)}function Ue(e){if(e!==void 0&&(!L(e)||Object.keys(e).some(e=>Ne.has(e))))throw z()}function We(e,t){let n=new AbortController,r=null,i=()=>{r===null&&(r=`aborted`,n.abort())};e?.aborted===!0?i():e?.addEventListener(`abort`,i,{once:!0});let a=setTimeout(()=>{r===null&&(r=`timeout`,n.abort())},t);return{signal:n.signal,reason:()=>r,cleanup(){clearTimeout(a),e?.removeEventListener(`abort`,i)}}}function J(e){return new x({code:e})}function Ge(e,t){let n=e;for(let e=0;e<4;e+=1){if(!L(n))return!1;if(n.code===t)return!0;n=n.cause}return!1}function Y(e){try{return ee(e)}catch{return!1}}function Ke(e){try{return te(e)}catch{return!1}}function X(e,t,n=null){return n===null?S(e)?e:Ge(e,`ENOENT`)?new x({code:`unavailable`,diagnostic:U(`initialize`)}):Ke(e)?new x({code:`protocol_incompatible`,diagnostic:U(t)}):Y(e)?new x({code:`provider_rejected`,diagnostic:U(t)}):p.isInstance(e)||m.isInstance(e)?new x({code:`invalid_response`,diagnostic:U(t)}):L(e)&&(e.name===`AbortError`||e.name===`TimeoutError`)?new x({code:e.name===`TimeoutError`?`timeout`:`aborted`}):new x({code:`provider_rejected`,diagnostic:U(t)}):J(n)}function qe(e){return S(e)?e:new x({code:`unavailable`,diagnostic:U(`initialize`)})}function Z(e){return typeof e==`string`&&R(e)&&e.length<=256&&!I.test(e)?e:null}function Q(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0?e:null}function Je(e){if(typeof e!=`string`||e.length===0)throw new x({code:`invalid_response`});if(new TextEncoder().encode(e).byteLength>4194304)throw new x({code:`output_limit_exceeded`});return e}function Ye(e){let t=Z(e.id);if(t===null)throw new x({code:`invalid_response`});return Object.freeze({id:t,displayName:Z(e.displayName??e.name)??null,description:typeof e.description==`string`&&e.description.length<=F?e.description:null,hidden:e.hidden===!0,isDefault:e.isDefault===!0})}function $(e,t,n,r=null){if(e===void 0)return;let i=t.diagnostic??U(`turn_execution`),a=r===null||t.code!==`network_destination_blocked`&&t.code!==`network_guard_unobserved`?void 0:Object.freeze({connectionCount:r.connectionCount,receivedBytes:r.receivedBytes,destinationHost:r.violation?.destinationHost??null,violation:t.code===`network_guard_unobserved`?`unobserved`:r.violation?.kind??`destination_blocked`}),o=Object.freeze({schemaVersion:1,event:`turn_error`,willRetry:!1,retryCount:0,elapsedMs:Math.max(0,Math.round(performance.now()-n)),diagnostic:Object.freeze({...i}),...a===void 0?{}:{network:a}});try{e(o)}catch{}}function Xe(e){let t=e.getReader(),n=!1,r=()=>{n||(n=!0,t.releaseLock())};return new ReadableStream({async pull(e){try{let n=await t.read();if(n.done){r(),e.close();return}e.enqueue(n.value.type===`error`?{...n.value,error:X(n.value.error,`turn_execution`)}:n.value)}catch(t){r(),e.error(X(t,`turn_execution`))}},async cancel(e){try{await t.cancel(e)}catch(e){throw X(e,`turn_execution`)}finally{r()}}})}const Ze={specificationVersion:`v4`,async wrapGenerate({doGenerate:e}){try{return await e()}catch(e){throw X(e,`turn_execution`)}},async wrapStream({doStream:e}){let t;try{t=await e()}catch(e){throw X(e,`turn_execution`)}return{...t,stream:Xe(t.stream)}}};var Qe=class{upstream;closed=!1;closePromise=null;constructor(e){this.upstream=g({defaultSettings:{codexPath:e.executable.command,...e.cwd===void 0?{}:{cwd:e.cwd},...e.environment===void 0?{}:{env:{...e.environment}},connectionTimeoutMs:e.connectionTimeoutMs,requestTimeoutMs:e.requestTimeoutMs,idleTimeoutMs:e.idleTimeoutMs,minCodexVersion:e.minimumCodexVersion,logger:!1}})}model(e,t){this.assertOpen(),W(e,256),Ue(t);try{return h({model:this.upstream.languageModel(e.trim(),t),middleware:Ze})}catch{throw z()}}async listModels(e){this.assertOpen();let t=e?.modelProviders;if(e!==void 0&&(!L(e)||e.modelProviders!==void 0&&(!Array.isArray(e.modelProviders)||e.modelProviders.some(e=>typeof e!=`string`||!R(e)||e.length>256||I.test(e)))))throw z();try{let e=await this.upstream.listModels(t===void 0?void 0:[...t]);return Object.freeze(e.models.map(Ye))}catch(e){throw X(e,`initialize`)}}close(){return this.closePromise===null?(this.closed=!0,this.closePromise=Promise.resolve().then(()=>this.upstream.close()).catch(()=>{throw new x({code:`cleanup_failed`})}),this.closePromise):this.closePromise}assertOpen(){if(this.closed)throw new x({code:`unavailable`})}};function $e(e){return et(Le(e))}function et(e){try{return new Qe(e)}catch{throw z()}}function tt(e,t=ke){let n=Re(e),r=Object.freeze({adapterId:`codex-app-server`,providerId:`codex`,model:n.model});return Object.freeze({identity:r,supportedResponseFormats:Object.freeze([`text`,`json_schema`]),async generate(e){let i=performance.now(),a=He(e),o=We(e.signal,n.timeoutMs);if(o.reason()!==null)throw o.cleanup(),J(o.reason());let s=null,c=null,l=null,u=null,d=null;try{l=await Ve(),u=await t.createCodexNetworkGuard({blockedHostSuffixes:Me})}catch(e){let t=o.reason()===null?qe(e):J(o.reason());if(l!==null)try{await l.cleanup()}catch{t=new x({code:`cleanup_failed`})}throw o.cleanup(),$(n.onRuntimeEvent,t,i),t}try{let e=await t.runIsolatedCodexProcess({executable:n.executable.command,cwd:l.cwd,model:n.model,...n.reasoningEffort===void 0?{}:{reasoningEffort:n.reasoningEffort},timeoutMs:n.timeoutMs,instructions:a.instructions,input:a.input,responseFormat:a.responseFormat},Object.freeze({...l.environment,...u.environment}),o.signal);s={text:Je(e.text),providerRequestId:Z(e.providerRequestId),model:Z(e.model)??n.model,usage:{inputTokens:Q(e.usage.inputTokens),...e.usage.inputTokenDetails===void 0?{}:{inputTokenDetails:{noCacheTokens:Q(e.usage.inputTokenDetails.noCacheTokens),cacheReadTokens:Q(e.usage.inputTokenDetails.cacheReadTokens),cacheWriteTokens:Q(e.usage.inputTokenDetails.cacheWriteTokens)}},outputTokens:Q(e.usage.outputTokens),...e.usage.outputTokenDetails===void 0?{}:{outputTokenDetails:{textTokens:Q(e.usage.outputTokenDetails.textTokens),reasoningTokens:Q(e.usage.outputTokenDetails.reasoningTokens)}},totalTokens:Q(e.usage.totalTokens),...e.usage.raw===void 0?{}:{raw:e.usage.raw}}},o.reason()!==null&&(c=J(o.reason()))}catch(e){c=X(e,`turn_execution`,o.reason())}d=u.observe(),d.violation===null?s!==null&&d.connectionCount===0&&(c=new x({code:`network_guard_unobserved`,diagnostic:U(`turn_execution`)})):c=new x({code:`network_destination_blocked`,diagnostic:U(`turn_execution`)});try{await u.close()}catch{c=new x({code:`cleanup_failed`})}try{await l.cleanup()}catch{c=new x({code:`cleanup_failed`})}finally{o.cleanup()}if(c!==null)throw $(n.onRuntimeEvent,c,i,d),c;if(s===null){let e=new x({code:`invalid_response`});throw $(n.onRuntimeEvent,e,i),e}return{text:s.text,identity:Object.freeze({...r,model:s.model}),providerRequestId:s.providerRequestId,latencyMs:performance.now()-i,usage:Object.freeze({...s.usage}),networkUsage:Object.freeze({connectionCount:d.connectionCount,receivedBytes:d.receivedBytes})}}})}export{P as codexExecutableEnvironmentVariable,tt as createCodexProvider,$e as createManagedCodexProvider,Fe as resolveCodexExecutable};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
declare const aiProviderErrorCodes: readonly ["invalid_configuration", "unsupported_response_format", "aborted", "timeout", "unavailable", "provider_rejected", "invalid_response", "protocol_incompatible", "unsafe_provider_event", "network_destination_blocked", "network_guard_unobserved", "output_limit_exceeded", "cleanup_failed"];
|
|
3
|
+
declare const aiProviderErrorPhases: readonly ["initialize", "thread_start", "turn_start", "turn_execution", "response_receive", "response_read", "response_parse", "response_normalize"];
|
|
4
|
+
declare const aiProviderDiagnosticCodes: readonly ["json_rpc_parse_error", "json_rpc_invalid_request", "json_rpc_method_not_found", "json_rpc_invalid_params", "json_rpc_internal_error", "codex_context_window_exceeded", "codex_session_budget_exceeded", "codex_usage_limit_exceeded", "codex_server_overloaded", "codex_cyber_policy", "codex_internal_server_error", "codex_unauthorized", "codex_bad_request", "codex_thread_rollback_failed", "codex_sandbox_error", "codex_other", "codex_http_connection_failed", "codex_response_stream_connection_failed", "codex_response_stream_disconnected", "codex_response_too_many_failed_attempts", "codex_active_turn_not_steerable", "fetch_response_invalid", "response_body_missing", "response_body_read_failed", "response_json_invalid", "response_choices_invalid", "response_message_invalid", "response_model_invalid", "codex_executable_not_configured", "codex_executable_path_invalid", "codex_executable_unavailable"];
|
|
5
|
+
declare namespace AiProvider {
|
|
6
|
+
/** A JSON-compatible primitive accepted by structured output schemas. */
|
|
7
|
+
type JsonPrimitive = boolean | number | string | null;
|
|
8
|
+
/** A recursively JSON-compatible value accepted by provider adapters. */
|
|
9
|
+
type JsonValue = JsonPrimitive | readonly JsonValue[] | {
|
|
10
|
+
readonly [key: string]: JsonValue;
|
|
11
|
+
};
|
|
12
|
+
/** A JSON object used as the provider-neutral structured output schema. */
|
|
13
|
+
type JsonObject = {
|
|
14
|
+
readonly [key: string]: JsonValue;
|
|
15
|
+
};
|
|
16
|
+
/** The output shape requested from a text generation provider. */
|
|
17
|
+
type ResponseFormat = {
|
|
18
|
+
readonly type: "text";
|
|
19
|
+
} | {
|
|
20
|
+
readonly type: "json_object";
|
|
21
|
+
} | {
|
|
22
|
+
readonly type: "json_schema";
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly schema: JsonObject;
|
|
25
|
+
readonly strict?: boolean;
|
|
26
|
+
};
|
|
27
|
+
/** The adapter, provider, and effective model that produced a result. */
|
|
28
|
+
interface Identity {
|
|
29
|
+
readonly adapterId: string;
|
|
30
|
+
readonly providerId: string;
|
|
31
|
+
readonly model: string;
|
|
32
|
+
}
|
|
33
|
+
/** Token usage when the underlying provider reports it. */
|
|
34
|
+
interface Usage {
|
|
35
|
+
readonly inputTokens: number | null;
|
|
36
|
+
/** Standard input-token breakdown exposed by the adapter. */
|
|
37
|
+
readonly inputTokenDetails?: {
|
|
38
|
+
readonly noCacheTokens: number | null;
|
|
39
|
+
readonly cacheReadTokens: number | null;
|
|
40
|
+
readonly cacheWriteTokens: number | null;
|
|
41
|
+
};
|
|
42
|
+
readonly outputTokens: number | null;
|
|
43
|
+
/** Standard output-token breakdown exposed by the adapter. */
|
|
44
|
+
readonly outputTokenDetails?: {
|
|
45
|
+
readonly textTokens: number | null;
|
|
46
|
+
readonly reasoningTokens: number | null;
|
|
47
|
+
};
|
|
48
|
+
readonly totalTokens: number | null;
|
|
49
|
+
/** Provider-native usage fields, retained for evidence that cannot be reconstructed later. */
|
|
50
|
+
readonly raw?: JsonObject;
|
|
51
|
+
}
|
|
52
|
+
/** Observable network traffic owned by an adapter-level transport guard. */
|
|
53
|
+
interface NetworkUsage {
|
|
54
|
+
readonly connectionCount: number;
|
|
55
|
+
readonly receivedBytes: number;
|
|
56
|
+
}
|
|
57
|
+
/** One stateless text generation request. */
|
|
58
|
+
interface TextGenerationRequest {
|
|
59
|
+
readonly instructions: string;
|
|
60
|
+
readonly input: string;
|
|
61
|
+
readonly responseFormat?: ResponseFormat;
|
|
62
|
+
readonly temperature?: number;
|
|
63
|
+
readonly signal?: AbortSignal;
|
|
64
|
+
}
|
|
65
|
+
/** The normalized result of one text generation request. */
|
|
66
|
+
interface TextGenerationResult {
|
|
67
|
+
readonly text: string;
|
|
68
|
+
readonly identity: Identity;
|
|
69
|
+
readonly providerRequestId: string | null;
|
|
70
|
+
readonly latencyMs: number;
|
|
71
|
+
readonly usage: Usage;
|
|
72
|
+
readonly networkUsage?: NetworkUsage;
|
|
73
|
+
}
|
|
74
|
+
/** A stateless provider that performs one text generation request at a time. */
|
|
75
|
+
interface TextGenerationProvider {
|
|
76
|
+
readonly identity: Identity;
|
|
77
|
+
readonly supportedResponseFormats: readonly ResponseFormat["type"][];
|
|
78
|
+
generate(request: TextGenerationRequest): Promise<TextGenerationResult>;
|
|
79
|
+
}
|
|
80
|
+
/** Stable technical failures emitted by built-in adapters. */
|
|
81
|
+
type ErrorCode = (typeof aiProviderErrorCodes)[number];
|
|
82
|
+
/** Stable adapter phase at which a provider failure became observable. */
|
|
83
|
+
type ErrorPhase = (typeof aiProviderErrorPhases)[number];
|
|
84
|
+
/** Allowlisted machine code extracted from a provider protocol failure. */
|
|
85
|
+
type DiagnosticCode = (typeof aiProviderDiagnosticCodes)[number];
|
|
86
|
+
/** Safe failure metadata that excludes provider messages and payloads. */
|
|
87
|
+
interface ErrorDiagnostic {
|
|
88
|
+
readonly phase: ErrorPhase;
|
|
89
|
+
readonly providerCode: DiagnosticCode | null;
|
|
90
|
+
readonly httpStatusCode: number | null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
type TextGenerationProvider = AiProvider.TextGenerationProvider;
|
|
94
|
+
type TextGenerationRequest = AiProvider.TextGenerationRequest;
|
|
95
|
+
type TextGenerationResult = AiProvider.TextGenerationResult;
|
|
96
|
+
type TextGenerationResponseFormat = AiProvider.ResponseFormat;
|
|
97
|
+
type AiProviderIdentity = AiProvider.Identity;
|
|
98
|
+
type AiProviderUsage = AiProvider.Usage;
|
|
99
|
+
type AiProviderNetworkUsage = AiProvider.NetworkUsage;
|
|
100
|
+
type AiProviderErrorCode = AiProvider.ErrorCode;
|
|
101
|
+
type AiProviderErrorPhase = AiProvider.ErrorPhase;
|
|
102
|
+
type AiProviderDiagnosticCode = AiProvider.DiagnosticCode;
|
|
103
|
+
type AiProviderErrorDiagnostic = AiProvider.ErrorDiagnostic;
|
|
104
|
+
type AiProviderJsonObject = AiProvider.JsonObject;
|
|
105
|
+
type AiProviderJsonValue = AiProvider.JsonValue;
|
|
106
|
+
/** A safe provider failure that omits provider bodies, prompts, and credentials. */
|
|
107
|
+
declare class AiProviderError extends Error {
|
|
108
|
+
readonly code: AiProviderErrorCode;
|
|
109
|
+
readonly providerRequestId: string | null;
|
|
110
|
+
readonly diagnostic: AiProviderErrorDiagnostic | null;
|
|
111
|
+
constructor(input: {
|
|
112
|
+
code: AiProviderErrorCode;
|
|
113
|
+
providerRequestId?: string | null;
|
|
114
|
+
diagnostic?: AiProviderErrorDiagnostic | null;
|
|
115
|
+
});
|
|
116
|
+
static [Symbol.hasInstance](value: unknown): boolean;
|
|
117
|
+
}
|
|
118
|
+
/** Returns whether a value is an AI provider error, including across package entry bundles. */
|
|
119
|
+
declare function isAiProviderError(value: unknown): value is AiProviderError;
|
|
120
|
+
//#endregion
|
|
121
|
+
export { AiProvider, AiProviderDiagnosticCode, AiProviderError, AiProviderErrorCode, AiProviderErrorDiagnostic, AiProviderErrorPhase, AiProviderIdentity, AiProviderJsonObject, AiProviderJsonValue, AiProviderNetworkUsage, AiProviderUsage, TextGenerationProvider, TextGenerationRequest, TextGenerationResponseFormat, TextGenerationResult, isAiProviderError };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=[`invalid_configuration`,`unsupported_response_format`,`aborted`,`timeout`,`unavailable`,`provider_rejected`,`invalid_response`,`protocol_incompatible`,`unsafe_provider_event`,`network_destination_blocked`,`network_guard_unobserved`,`output_limit_exceeded`,`cleanup_failed`],t=[`initialize`,`thread_start`,`turn_start`,`turn_execution`,`response_receive`,`response_read`,`response_parse`,`response_normalize`],n=`json_rpc_parse_error.json_rpc_invalid_request.json_rpc_method_not_found.json_rpc_invalid_params.json_rpc_internal_error.codex_context_window_exceeded.codex_session_budget_exceeded.codex_usage_limit_exceeded.codex_server_overloaded.codex_cyber_policy.codex_internal_server_error.codex_unauthorized.codex_bad_request.codex_thread_rollback_failed.codex_sandbox_error.codex_other.codex_http_connection_failed.codex_response_stream_connection_failed.codex_response_stream_disconnected.codex_response_too_many_failed_attempts.codex_active_turn_not_steerable.fetch_response_invalid.response_body_missing.response_body_read_failed.response_json_invalid.response_choices_invalid.response_message_invalid.response_model_invalid.codex_executable_not_configured.codex_executable_path_invalid.codex_executable_unavailable`.split(`.`),r=Symbol.for(`@closerepo/ai-provider/AiProviderError`),i=new Set(e),a=new Set(t),o=new Set(n);function s(e){if(typeof e!=`object`||!e)return!1;let t=e;return Object.keys(t).length===3&&typeof t.phase==`string`&&a.has(t.phase)&&(t.providerCode===null||typeof t.providerCode==`string`&&o.has(t.providerCode))&&(t.httpStatusCode===null||Number.isInteger(t.httpStatusCode)&&t.httpStatusCode>=100&&t.httpStatusCode<=599)}function c(e){if(typeof e!=`object`||!e)return!1;let t=e;return t[r]===!0&&t.name===`AiProviderError`&&typeof t.code==`string`&&i.has(t.code)&&(t.providerRequestId===null||typeof t.providerRequestId==`string`)&&(t.diagnostic===null||s(t.diagnostic))}var l=class extends Error{code;providerRequestId;diagnostic;constructor(e){if(typeof e!=`object`||!e||!i.has(e.code)||e.providerRequestId!==void 0&&e.providerRequestId!==null&&(typeof e.providerRequestId!=`string`||e.providerRequestId.length===0||e.providerRequestId.length>256||/[\u0000-\u001F\u007F]/.test(e.providerRequestId))||e.diagnostic!==void 0&&e.diagnostic!==null&&!s(e.diagnostic))throw TypeError(`invalid_ai_provider_error`);super(e.code),this.name=`AiProviderError`,this.code=e.code,this.providerRequestId=e.providerRequestId??null,this.diagnostic=e.diagnostic===void 0||e.diagnostic===null?null:Object.freeze({...e.diagnostic}),this.stack=`${this.name}: ${this.message}`,Object.defineProperty(this,r,{value:!0})}static[Symbol.hasInstance](e){return c(e)}};function u(e){return e instanceof l}export{l as AiProviderError,u as isAiProviderError};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
declare const aiProviderErrorCodes: readonly ["invalid_configuration", "unsupported_response_format", "aborted", "timeout", "unavailable", "provider_rejected", "invalid_response", "protocol_incompatible", "unsafe_provider_event", "network_destination_blocked", "network_guard_unobserved", "output_limit_exceeded", "cleanup_failed"];
|
|
3
|
+
declare const aiProviderErrorPhases: readonly ["initialize", "thread_start", "turn_start", "turn_execution", "response_receive", "response_read", "response_parse", "response_normalize"];
|
|
4
|
+
declare const aiProviderDiagnosticCodes: readonly ["json_rpc_parse_error", "json_rpc_invalid_request", "json_rpc_method_not_found", "json_rpc_invalid_params", "json_rpc_internal_error", "codex_context_window_exceeded", "codex_session_budget_exceeded", "codex_usage_limit_exceeded", "codex_server_overloaded", "codex_cyber_policy", "codex_internal_server_error", "codex_unauthorized", "codex_bad_request", "codex_thread_rollback_failed", "codex_sandbox_error", "codex_other", "codex_http_connection_failed", "codex_response_stream_connection_failed", "codex_response_stream_disconnected", "codex_response_too_many_failed_attempts", "codex_active_turn_not_steerable", "fetch_response_invalid", "response_body_missing", "response_body_read_failed", "response_json_invalid", "response_choices_invalid", "response_message_invalid", "response_model_invalid", "codex_executable_not_configured", "codex_executable_path_invalid", "codex_executable_unavailable"];
|
|
5
|
+
declare namespace AiProvider {
|
|
6
|
+
/** A JSON-compatible primitive accepted by structured output schemas. */
|
|
7
|
+
type JsonPrimitive = boolean | number | string | null;
|
|
8
|
+
/** A recursively JSON-compatible value accepted by provider adapters. */
|
|
9
|
+
type JsonValue = JsonPrimitive | readonly JsonValue[] | {
|
|
10
|
+
readonly [key: string]: JsonValue;
|
|
11
|
+
};
|
|
12
|
+
/** A JSON object used as the provider-neutral structured output schema. */
|
|
13
|
+
type JsonObject = {
|
|
14
|
+
readonly [key: string]: JsonValue;
|
|
15
|
+
};
|
|
16
|
+
/** The output shape requested from a text generation provider. */
|
|
17
|
+
type ResponseFormat = {
|
|
18
|
+
readonly type: "text";
|
|
19
|
+
} | {
|
|
20
|
+
readonly type: "json_object";
|
|
21
|
+
} | {
|
|
22
|
+
readonly type: "json_schema";
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly schema: JsonObject;
|
|
25
|
+
readonly strict?: boolean;
|
|
26
|
+
};
|
|
27
|
+
/** The adapter, provider, and effective model that produced a result. */
|
|
28
|
+
interface Identity {
|
|
29
|
+
readonly adapterId: string;
|
|
30
|
+
readonly providerId: string;
|
|
31
|
+
readonly model: string;
|
|
32
|
+
}
|
|
33
|
+
/** Token usage when the underlying provider reports it. */
|
|
34
|
+
interface Usage {
|
|
35
|
+
readonly inputTokens: number | null;
|
|
36
|
+
/** Standard input-token breakdown exposed by the adapter. */
|
|
37
|
+
readonly inputTokenDetails?: {
|
|
38
|
+
readonly noCacheTokens: number | null;
|
|
39
|
+
readonly cacheReadTokens: number | null;
|
|
40
|
+
readonly cacheWriteTokens: number | null;
|
|
41
|
+
};
|
|
42
|
+
readonly outputTokens: number | null;
|
|
43
|
+
/** Standard output-token breakdown exposed by the adapter. */
|
|
44
|
+
readonly outputTokenDetails?: {
|
|
45
|
+
readonly textTokens: number | null;
|
|
46
|
+
readonly reasoningTokens: number | null;
|
|
47
|
+
};
|
|
48
|
+
readonly totalTokens: number | null;
|
|
49
|
+
/** Provider-native usage fields, retained for evidence that cannot be reconstructed later. */
|
|
50
|
+
readonly raw?: JsonObject;
|
|
51
|
+
}
|
|
52
|
+
/** Observable network traffic owned by an adapter-level transport guard. */
|
|
53
|
+
interface NetworkUsage {
|
|
54
|
+
readonly connectionCount: number;
|
|
55
|
+
readonly receivedBytes: number;
|
|
56
|
+
}
|
|
57
|
+
/** One stateless text generation request. */
|
|
58
|
+
interface TextGenerationRequest {
|
|
59
|
+
readonly instructions: string;
|
|
60
|
+
readonly input: string;
|
|
61
|
+
readonly responseFormat?: ResponseFormat;
|
|
62
|
+
readonly temperature?: number;
|
|
63
|
+
readonly signal?: AbortSignal;
|
|
64
|
+
}
|
|
65
|
+
/** The normalized result of one text generation request. */
|
|
66
|
+
interface TextGenerationResult {
|
|
67
|
+
readonly text: string;
|
|
68
|
+
readonly identity: Identity;
|
|
69
|
+
readonly providerRequestId: string | null;
|
|
70
|
+
readonly latencyMs: number;
|
|
71
|
+
readonly usage: Usage;
|
|
72
|
+
readonly networkUsage?: NetworkUsage;
|
|
73
|
+
}
|
|
74
|
+
/** A stateless provider that performs one text generation request at a time. */
|
|
75
|
+
interface TextGenerationProvider {
|
|
76
|
+
readonly identity: Identity;
|
|
77
|
+
readonly supportedResponseFormats: readonly ResponseFormat["type"][];
|
|
78
|
+
generate(request: TextGenerationRequest): Promise<TextGenerationResult>;
|
|
79
|
+
}
|
|
80
|
+
/** Stable technical failures emitted by built-in adapters. */
|
|
81
|
+
type ErrorCode = (typeof aiProviderErrorCodes)[number];
|
|
82
|
+
/** Stable adapter phase at which a provider failure became observable. */
|
|
83
|
+
type ErrorPhase = (typeof aiProviderErrorPhases)[number];
|
|
84
|
+
/** Allowlisted machine code extracted from a provider protocol failure. */
|
|
85
|
+
type DiagnosticCode = (typeof aiProviderDiagnosticCodes)[number];
|
|
86
|
+
/** Safe failure metadata that excludes provider messages and payloads. */
|
|
87
|
+
interface ErrorDiagnostic {
|
|
88
|
+
readonly phase: ErrorPhase;
|
|
89
|
+
readonly providerCode: DiagnosticCode | null;
|
|
90
|
+
readonly httpStatusCode: number | null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
type TextGenerationProvider = AiProvider.TextGenerationProvider;
|
|
94
|
+
type TextGenerationRequest = AiProvider.TextGenerationRequest;
|
|
95
|
+
type TextGenerationResult = AiProvider.TextGenerationResult;
|
|
96
|
+
type AiProviderErrorDiagnostic = AiProvider.ErrorDiagnostic;
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/openai-compatible.d.ts
|
|
99
|
+
declare namespace OpenAiCompatible {
|
|
100
|
+
/** Fetch-compatible transport injected by nonstandard runtimes or tests. */
|
|
101
|
+
type Fetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
102
|
+
/** Explicit authentication applied to the configured endpoint. */
|
|
103
|
+
type Authentication = {
|
|
104
|
+
readonly type: "none";
|
|
105
|
+
} | {
|
|
106
|
+
readonly type: "bearer";
|
|
107
|
+
readonly apiKey: string;
|
|
108
|
+
};
|
|
109
|
+
/** Explicit diagnostic event for an invalid provider response. */
|
|
110
|
+
interface InvalidResponseEvent {
|
|
111
|
+
readonly diagnostic: AiProviderErrorDiagnostic;
|
|
112
|
+
readonly providerRequestId: string | null;
|
|
113
|
+
readonly responseContentType: string | null;
|
|
114
|
+
readonly rawResponse: string | null;
|
|
115
|
+
}
|
|
116
|
+
/** Configuration for one exact OpenAI-compatible Chat Completions endpoint. */
|
|
117
|
+
interface Config {
|
|
118
|
+
readonly endpoint: string;
|
|
119
|
+
readonly providerId: string;
|
|
120
|
+
readonly model: string;
|
|
121
|
+
readonly authentication: Authentication;
|
|
122
|
+
readonly timeoutMs: number;
|
|
123
|
+
readonly fetch?: Fetch;
|
|
124
|
+
readonly onInvalidResponse?: (event: InvalidResponseEvent) => void;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Creates a bounded, non-streaming OpenAI-compatible text provider. */
|
|
128
|
+
declare function createOpenAiCompatibleProvider(config: OpenAiCompatible.Config): TextGenerationProvider;
|
|
129
|
+
//#endregion
|
|
130
|
+
export { OpenAiCompatible, createOpenAiCompatibleProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=[`invalid_configuration`,`unsupported_response_format`,`aborted`,`timeout`,`unavailable`,`provider_rejected`,`invalid_response`,`protocol_incompatible`,`unsafe_provider_event`,`network_destination_blocked`,`network_guard_unobserved`,`output_limit_exceeded`,`cleanup_failed`],t=[`initialize`,`thread_start`,`turn_start`,`turn_execution`,`response_receive`,`response_read`,`response_parse`,`response_normalize`],n=`json_rpc_parse_error.json_rpc_invalid_request.json_rpc_method_not_found.json_rpc_invalid_params.json_rpc_internal_error.codex_context_window_exceeded.codex_session_budget_exceeded.codex_usage_limit_exceeded.codex_server_overloaded.codex_cyber_policy.codex_internal_server_error.codex_unauthorized.codex_bad_request.codex_thread_rollback_failed.codex_sandbox_error.codex_other.codex_http_connection_failed.codex_response_stream_connection_failed.codex_response_stream_disconnected.codex_response_too_many_failed_attempts.codex_active_turn_not_steerable.fetch_response_invalid.response_body_missing.response_body_read_failed.response_json_invalid.response_choices_invalid.response_message_invalid.response_model_invalid.codex_executable_not_configured.codex_executable_path_invalid.codex_executable_unavailable`.split(`.`),r=Symbol.for(`@closerepo/ai-provider/AiProviderError`),i=new Set(e),a=new Set(t),o=new Set(n);function s(e){if(typeof e!=`object`||!e)return!1;let t=e;return Object.keys(t).length===3&&typeof t.phase==`string`&&a.has(t.phase)&&(t.providerCode===null||typeof t.providerCode==`string`&&o.has(t.providerCode))&&(t.httpStatusCode===null||Number.isInteger(t.httpStatusCode)&&t.httpStatusCode>=100&&t.httpStatusCode<=599)}function c(e){if(typeof e!=`object`||!e)return!1;let t=e;return t[r]===!0&&t.name===`AiProviderError`&&typeof t.code==`string`&&i.has(t.code)&&(t.providerRequestId===null||typeof t.providerRequestId==`string`)&&(t.diagnostic===null||s(t.diagnostic))}var l=class extends Error{code;providerRequestId;diagnostic;constructor(e){if(typeof e!=`object`||!e||!i.has(e.code)||e.providerRequestId!==void 0&&e.providerRequestId!==null&&(typeof e.providerRequestId!=`string`||e.providerRequestId.length===0||e.providerRequestId.length>256||/[\u0000-\u001F\u007F]/.test(e.providerRequestId))||e.diagnostic!==void 0&&e.diagnostic!==null&&!s(e.diagnostic))throw TypeError(`invalid_ai_provider_error`);super(e.code),this.name=`AiProviderError`,this.code=e.code,this.providerRequestId=e.providerRequestId??null,this.diagnostic=e.diagnostic===void 0||e.diagnostic===null?null:Object.freeze({...e.diagnostic}),this.stack=`${this.name}: ${this.message}`,Object.defineProperty(this,r,{value:!0})}static[Symbol.hasInstance](e){return c(e)}};function u(e){let t=JSON.stringify(e,(e,t)=>{if(t===void 0||typeof t==`bigint`||typeof t==`function`||typeof t==`symbol`||typeof t==`number`&&!Number.isFinite(t))throw TypeError(`invalid_json_value`);return t});if(typeof t!=`string`)throw TypeError(`invalid_json_value`);return t}const d=/^[A-Za-z0-9_-]{1,64}$/;function f(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function p(e){return!f(e)||typeof e.ok!=`boolean`||!f(e.headers)||typeof e.headers.get!=`function`?!1:e.body===null||f(e.body)&&typeof e.body.cancel==`function`&&typeof e.body.getReader==`function`}function m(e){return typeof e==`string`&&e.trim().length>0}function h(e){return m(e)&&e===e.trim()&&e.length<=256&&!/[\u0000-\u001F\u007F]/.test(e)}function g(e){let t;try{t=new URL(e)}catch{throw new l({code:`invalid_configuration`})}if(t.protocol!==`http:`&&t.protocol!==`https:`||t.username.length>0||t.password.length>0||t.hash.length>0)throw new l({code:`invalid_configuration`});return t.toString()}function _(e){if(!f(e)||!h(e.providerId)||!h(e.model)||typeof e.endpoint!=`string`||e.endpoint.length>16384||e.endpoint!==e.endpoint.trim()||!Number.isSafeInteger(e.timeoutMs)||e.timeoutMs<=0||e.timeoutMs>2147483647||!f(e.authentication))throw new l({code:`invalid_configuration`});if(e.authentication.type===`bearer`){if(!m(e.authentication.apiKey)||e.authentication.apiKey.length>65536||/[\u0000-\u001F\u007F]/.test(e.authentication.apiKey))throw new l({code:`invalid_configuration`})}else if(e.authentication.type!==`none`)throw new l({code:`invalid_configuration`});if(e.fetch!==void 0&&typeof e.fetch!=`function`||e.onInvalidResponse!==void 0&&typeof e.onInvalidResponse!=`function`)throw new l({code:`invalid_configuration`})}function v(e){if(!f(e)||typeof e.instructions!=`string`||typeof e.input!=`string`||e.signal!==void 0&&(!f(e.signal)||typeof e.signal.aborted!=`boolean`||typeof e.signal.addEventListener!=`function`||typeof e.signal.removeEventListener!=`function`)||e.temperature!==void 0&&(!Number.isFinite(e.temperature)||e.temperature<0||e.temperature>2))throw new l({code:`invalid_configuration`});let t=e.responseFormat;if(t!==void 0&&(!f(t)||t.type!==`text`&&t.type!==`json_object`&&(t.type!==`json_schema`||typeof t.name!=`string`||!d.test(t.name)||!f(t.schema)||t.strict!==void 0&&typeof t.strict!=`boolean`)))throw new l({code:`invalid_configuration`})}function y(e){if(e===void 0||e.type===`text`)return;if(e.type===`json_object`)return{type:`json_object`};let t={name:e.name,schema:e.schema};return e.strict!==void 0&&(t.strict=e.strict),{type:`json_schema`,json_schema:t}}function b(e,t){let n={model:e,stream:!1,messages:[{role:`system`,content:t.instructions},{role:`user`,content:t.input}]};t.temperature!==void 0&&(n.temperature=t.temperature);let r=y(t.responseFormat);return r!==void 0&&(n.response_format=r),n}function x(e,t){v(t);let n;try{n=u(b(e,t))}catch{throw new l({code:`invalid_configuration`})}if(new TextEncoder().encode(n).byteLength>1048576)throw new l({code:`invalid_configuration`});return n}function S(e,t){let n=e[t];return Number.isSafeInteger(n)&&n>=0?n:null}function C(e,t){let n=e[t];return f(n)?n:null}function w(e){return JSON.parse(u(e))}function T(e){if(!f(e))return{inputTokens:null,outputTokens:null,totalTokens:null};let t=C(e,`prompt_tokens_details`),n=C(e,`completion_tokens_details`);return{inputTokens:S(e,`prompt_tokens`),inputTokenDetails:{noCacheTokens:null,cacheReadTokens:t===null?null:S(t,`cached_tokens`),cacheWriteTokens:null},outputTokens:S(e,`completion_tokens`),outputTokenDetails:{textTokens:null,reasoningTokens:n===null?null:S(n,`reasoning_tokens`)},totalTokens:S(e,`total_tokens`),raw:w(e)}}function E(e){return typeof e==`string`&&e.length>0&&e.length<=256&&!/[\u0000-\u001F\u007F]/.test(e)?e:null}function D(e,t,n){let r=Object.freeze({phase:t,providerCode:n,httpStatusCode:e.httpStatusCode});try{e.onInvalidResponse?.(Object.freeze({diagnostic:r,providerRequestId:e.providerRequestId,responseContentType:e.responseContentType,rawResponse:e.rawResponse}))}catch{}return new l({code:`invalid_response`,providerRequestId:e.providerRequestId,diagnostic:r})}function O(e,t,n,r){if(!f(e)||!Array.isArray(e.choices))throw D(r,`response_normalize`,`response_choices_invalid`);let i=e.choices.at(0),a=f(i)&&f(i.message)?i.message:null,o=a?.content;if(a?.role!==`assistant`||typeof o!=`string`||o.length===0)throw D({...r,providerRequestId:E(e.id)},`response_normalize`,`response_message_invalid`);let s=t.model;if(e.model!==void 0){if(!h(e.model))throw D({...r,providerRequestId:E(e.id)},`response_normalize`,`response_model_invalid`);s=e.model}return{text:o,identity:Object.freeze({...t,model:s}),providerRequestId:E(e.id),latencyMs:n,usage:T(e.usage)}}async function k(e,t,n){if(e.body===null)throw D(n,`response_read`,`response_body_missing`);let r=e.body.getReader(),i=new TextDecoder,a=0,o=0,s=``;try{for(;;){let n=await j(r.read(),t);if(n.done)return s+=i.decode(),s;if(o+=1,a+=n.value.byteLength,a>4194304||o>16384)throw r.cancel().catch(()=>{}),new l({code:`output_limit_exceeded`,providerRequestId:E(e.headers.get(`x-request-id`))});s+=i.decode(n.value,{stream:!0})}}catch(e){throw t.signal.aborted&&r.cancel().catch(()=>{}),e}finally{r.releaseLock()}}function A(e,t){let n=new AbortController,r=null,i=()=>{r??=`aborted`,n.abort()};e?.aborted?i():e?.addEventListener(`abort`,i,{once:!0});let a=setTimeout(()=>{r??=`timeout`,n.abort()},t);return{signal:n.signal,reason:()=>r,cleanup:()=>{clearTimeout(a),e?.removeEventListener(`abort`,i)}}}async function j(e,t){if(t.signal.aborted)throw new l({code:t.reason()??`unavailable`});let n,r=new Promise((e,r)=>{n=()=>{r(new l({code:t.reason()??`unavailable`}))},t.signal.addEventListener(`abort`,n,{once:!0})});try{return await Promise.race([e,r])}finally{n!==void 0&&t.signal.removeEventListener(`abort`,n)}}function M(e){_(e);let t=g(e.endpoint),n=e.model,r=e.timeoutMs,i=e.authentication.type===`bearer`?{type:`bearer`,apiKey:e.authentication.apiKey}:{type:`none`},a=e.fetch??globalThis.fetch,o=e.onInvalidResponse,s=Object.freeze({adapterId:`openai-compatible`,providerId:e.providerId,model:n});return Object.freeze({identity:s,supportedResponseFormats:Object.freeze([`text`,`json_object`,`json_schema`]),async generate(e){let c=performance.now(),u=x(n,e),d=r-(performance.now()-c);if(d<=0)throw new l({code:`timeout`});let f=A(e.signal,d);if(f.reason()!==null)throw f.cleanup(),new l({code:f.reason()??`unavailable`});try{let e=new Headers({"content-type":`application/json`});i.type===`bearer`&&e.set(`authorization`,`Bearer ${i.apiKey}`);let n,d=null,m;try{d=a(t,{method:`POST`,headers:e,body:u,signal:f.signal}),m=await j(d,f)}catch{throw f.reason()!==null&&d!==null&&d.then(e=>e.body?.cancel()).catch(()=>{}),new l({code:f.reason()??`unavailable`})}if(!p(m))throw D({onInvalidResponse:o,providerRequestId:null,responseContentType:null,httpStatusCode:null,rawResponse:null},`response_receive`,`fetch_response_invalid`);if(n=m,f.reason()!==null)throw new l({code:f.reason()??`unavailable`});if(!n.ok)throw n.body?.cancel().catch(()=>{}),new l({code:`provider_rejected`,providerRequestId:E(n.headers.get(`x-request-id`)),diagnostic:{phase:`response_receive`,providerCode:null,httpStatusCode:n.status}});let h,g={onInvalidResponse:o,providerRequestId:E(n.headers.get(`x-request-id`)),responseContentType:n.headers.get(`content-type`),httpStatusCode:n.status,rawResponse:null};try{h=await k(n,f,g)}catch(e){throw e instanceof l?e:f.reason()===null?D(g,`response_read`,`response_body_read_failed`):new l({code:f.reason()??`unavailable`})}if(f.reason()!==null)throw new l({code:f.reason()??`unavailable`});let _;try{_=JSON.parse(h)}catch{throw D({...g,rawResponse:h},`response_parse`,`response_json_invalid`)}let v=performance.now()-c;if(v>=r)throw new l({code:`timeout`});return O(_,s,v,{...g,rawResponse:h})}catch(e){throw e instanceof l?e:new l({code:f.reason()??`invalid_response`})}finally{f.cleanup()}}})}export{M as createOpenAiCompatibleProvider};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@closerepo/ai-provider",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/closerepo/packages.git",
|
|
9
|
+
"directory": "packages/ai-provider"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@ai-sdk/provider": "4.0.4",
|
|
16
|
+
"@types/json-schema": "7.0.15",
|
|
17
|
+
"ai": "7.0.44",
|
|
18
|
+
"ai-sdk-provider-codex-cli": "2.1.2",
|
|
19
|
+
"zod": "4.4.3"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist/index.d.ts",
|
|
23
|
+
"dist/index.js",
|
|
24
|
+
"dist/openai-compatible.d.ts",
|
|
25
|
+
"dist/openai-compatible.js",
|
|
26
|
+
"dist/codex.d.ts",
|
|
27
|
+
"dist/codex.js",
|
|
28
|
+
"dist/codex-network-guard.js",
|
|
29
|
+
"dist/codex-simple-process.js",
|
|
30
|
+
"dist/codex-simple-policy.js",
|
|
31
|
+
"dist/codex-simple-protocol.js",
|
|
32
|
+
"dist/codex-simple-worker.js"
|
|
33
|
+
],
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./openai-compatible": {
|
|
40
|
+
"types": "./dist/openai-compatible.d.ts",
|
|
41
|
+
"import": "./dist/openai-compatible.js"
|
|
42
|
+
},
|
|
43
|
+
"./codex": {
|
|
44
|
+
"types": "./dist/codex.d.ts",
|
|
45
|
+
"import": "./dist/codex.js"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|