@messenger-agent/codex-agent 0.37.1-alpha.0 → 0.37.1-alpha.1
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.
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import{spawn as
|
|
1
|
+
import{spawn as x}from"node:child_process";import{EventEmitter as g}from"node:events";import{statSync as l}from"node:fs";import{createRequire as f}from"node:module";import o from"node:path";import{handleDynamicToolCall as q,inheritManagedTaskToolContextFromNotification as I}from"./dynamic-tools.js";import{logger as c}from"@messenger-agent/shared/logger";const h="@openai/codex",R={"x86_64-unknown-linux-musl":"@openai/codex-linux-x64","aarch64-unknown-linux-musl":"@openai/codex-linux-arm64","x86_64-apple-darwin":"@openai/codex-darwin-x64","aarch64-apple-darwin":"@openai/codex-darwin-arm64","x86_64-pc-windows-msvc":"@openai/codex-win32-x64","aarch64-pc-windows-msvc":"@openai/codex-win32-arm64"},v=f(import.meta.url);function y(){const{platform:s,arch:e}=process;let t=null;switch(s){case"linux":case"android":e==="x64"&&(t="x86_64-unknown-linux-musl"),e==="arm64"&&(t="aarch64-unknown-linux-musl");break;case"darwin":e==="x64"&&(t="x86_64-apple-darwin"),e==="arm64"&&(t="aarch64-apple-darwin");break;case"win32":e==="x64"&&(t="x86_64-pc-windows-msvc"),e==="arm64"&&(t="aarch64-pc-windows-msvc");break;default:break}if(!t)throw new Error(`Unsupported platform: ${s} (${e})`);const r=R[t];if(!r)throw new Error(`Unsupported target triple: ${t}`);let i;try{const a=v.resolve(`${h}/package.json`),m=f(a).resolve(`${r}/package.json`);i=o.join(o.dirname(m),"vendor")}catch{throw new Error(`Unable to locate Codex CLI binaries. Ensure ${h} is installed with optional dependencies.`)}const n=process.platform==="win32"?"codex.exe":"codex",d=E(i,t,n);if(!d)throw new Error(`Unable to locate Codex CLI binaries for ${t}. Ensure ${h} is installed with optional dependencies.`);return d.executablePath}function E(s,e,t){const r=o.join(s,e),i=o.join(r,"bin",t);if(p(i)&&p(o.join(r,"codex-package.json")))return{executablePath:i,pathDirs:w(o.join(r,"codex-path"))};const n=o.join(r,"codex",t);return p(n)?{executablePath:n,pathDirs:w(o.join(r,"path"))}:null}function w(...s){return s.filter(U)}function p(s){try{return l(s).isFile()}catch{return!1}}function U(s){try{return l(s).isDirectory()}catch{return!1}}function P(s){const e=s.trim();if(!e)return{command:"codex",args:["app-server","--listen","stdio://"]};const t=e.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g)??[],[r,...i]=t.map(n=>n.startsWith('"')&&n.endsWith('"')||n.startsWith("'")&&n.endsWith("'")?n.slice(1,-1):n);return{command:r??"codex",args:i}}class S extends g{toolHandler;child;nextId=1;pending=new Map;pendingUserInputRequests=new Map;notifiedUserInputRequests=new Set;answeredUserInputRequests=new Set;started;buffer="";constructor(e=q){super(),this.toolHandler=e}async request(e,t){return await this.ensureStarted(),this.writeRequest(e,t)}async writeRequest(e,t){if(!this.child)throw new Error("Codex app-server is not running");const r=this.nextId++,i=JSON.stringify({jsonrpc:"2.0",id:r,method:e,params:t});return new Promise((n,d)=>{this.pending.set(r,{resolve:a=>n(a),reject:d}),this.child?.stdin.write(`${i}
|
|
2
2
|
`,a=>{a&&(this.pending.delete(r),d(a))})})}async notify(e,t){if(await this.ensureStarted(),!this.child)throw new Error("Codex app-server is not running");this.child.stdin.write(`${JSON.stringify({jsonrpc:"2.0",method:e,params:t})}
|
|
3
3
|
`)}async respondToUserInput(e,t,r){if(await this.ensureStarted(),!this.child)throw new Error("Codex app-server is not running");const i=u(e,t);if(this.answeredUserInputRequests.has(i))throw new Error(`User input request already answered for item: ${t}`);const n=this.pendingUserInputRequests.get(i);return n?(this.pendingUserInputRequests.delete(i),this.answeredUserInputRequests.add(i),this.child.stdin.write(`${JSON.stringify({jsonrpc:"2.0",id:n.requestId,result:r})}
|
|
4
|
-
`),!0):!1}pendingUserInputTurnId(e,t){return this.pendingUserInputRequests.get(u(e,t))?.turnId}discardPendingUserInput(e,t){const r=u(e,t);this.pendingUserInputRequests.delete(r),this.notifiedUserInputRequests.delete(r),this.answeredUserInputRequests.delete(r)}async ensureStarted(){return this.started||(this.started=this.start()),this.started}async start(){const e=process.env.CODEX_APP_SERVER_COMMAND,{command:t,args:r}=e?P(e):{command:y(),args:["app-server","--listen","stdio://"]},i={...process.env};this.child=
|
|
4
|
+
`),!0):!1}pendingUserInputTurnId(e,t){return this.pendingUserInputRequests.get(u(e,t))?.turnId}discardPendingUserInput(e,t){const r=u(e,t);this.pendingUserInputRequests.delete(r),this.notifiedUserInputRequests.delete(r),this.answeredUserInputRequests.delete(r)}async ensureStarted(){return this.started||(this.started=this.start()),this.started}async start(){const e=process.env.CODEX_APP_SERVER_COMMAND,{command:t,args:r}=e?P(e):{command:y(),args:["app-server","--listen","stdio://"]},i={...process.env};if(this.child=x(t,r,{env:i,stdio:["pipe","pipe","pipe"]}),this.child.stdout.setEncoding("utf-8"),this.child.stderr.setEncoding("utf-8"),this.child.stdout.on("data",n=>this.handleStdout(n)),this.child.stderr.on("data",n=>c.debug(`codex app-server stderr: ${n.trimEnd()}`)),this.child.on("exit",(n,d)=>this.handleExit(n,d)),this.child.on("error",n=>this.handleProcessError(n)),await this.writeRequest("initialize",{clientInfo:{name:"codex-agent",title:"codex-agent",version:"0.1.0"},capabilities:{experimentalApi:!0,requestAttestation:!1}}),!this.child)throw new Error("Codex app-server is not running");this.child.stdin.write(`${JSON.stringify({jsonrpc:"2.0",method:"initialized",params:{}})}
|
|
5
|
+
`)}handleStdout(e){for(this.buffer+=e;;){const t=this.buffer.indexOf(`
|
|
5
6
|
`);if(t===-1)break;const r=this.buffer.slice(0,t).trim();if(this.buffer=this.buffer.slice(t+1),!!r)try{this.handleMessage(JSON.parse(r))}catch(i){c.error("Failed to parse codex app-server JSON-RPC message:",i)}}}handleMessage(e){if((!e.method||!(e.method.endsWith("/delta")||e.method.endsWith("/outputDelta")||e.method==="turn/diff/updated"))&&c.debug("Received message:",e),e.id!==void 0&&e.method){this.handleServerRequest(e).catch(t=>c.error("Failed to handle app-server request:",t));return}if(e.id!==void 0){const t=this.pending.get(e.id);if(!t)return;this.pending.delete(e.id),e.error?t.reject(new Error(e.error.message??`Codex app-server request failed: ${e.error.code}`)):t.resolve(e.result);return}e.method&&(I(e.method,e.params),this.emit("notification",{method:e.method,params:e.params}))}async handleServerRequest(e){if(!(!this.child||e.id===void 0||!e.method))try{if(e.method==="item/tool/call"){const t=await this.toolHandler(e.params);this.child.stdin.write(`${JSON.stringify({jsonrpc:"2.0",id:e.id,result:t})}
|
|
6
7
|
`);return}if(e.method==="item/tool/requestUserInput"){const t=e.params,r=u(t.threadId,t.itemId);if(this.pendingUserInputRequests.set(r,{threadId:t.threadId,turnId:t.turnId,itemId:t.itemId,requestId:e.id}),this.notifiedUserInputRequests.has(r))return;this.notifiedUserInputRequests.add(r),this.emit("notification",{method:e.method,params:t});return}this.child.stdin.write(`${JSON.stringify({jsonrpc:"2.0",id:e.id,error:{code:-32601,message:`Unsupported server request: ${e.method}`}})}
|
|
7
8
|
`)}catch(t){const r=t instanceof Error?t.message:String(t);this.child.stdin.write(`${JSON.stringify({jsonrpc:"2.0",id:e.id,error:{code:-32e3,message:r}})}
|
|
@@ -188,7 +188,7 @@ export type ContextCompactionItem = {
|
|
|
188
188
|
export type SubAgentActivityItem = {
|
|
189
189
|
type: "subAgentActivity";
|
|
190
190
|
id: string;
|
|
191
|
-
kind: "started" | "interacted" | "interrupted";
|
|
191
|
+
kind: "started" | "interacted" | "interrupted" | "completed";
|
|
192
192
|
agentThreadId: string;
|
|
193
193
|
agentPath: string;
|
|
194
194
|
};
|
|
@@ -197,7 +197,7 @@ export type CollabAgentToolCallItem = {
|
|
|
197
197
|
type: "collabAgentToolCall";
|
|
198
198
|
id: string;
|
|
199
199
|
tool: string;
|
|
200
|
-
status: "inProgress" | "completed" | "failed";
|
|
200
|
+
status: "inProgress" | "completed" | "failed" | "interrupted";
|
|
201
201
|
senderThreadId: string;
|
|
202
202
|
receiverThreadIds: string[];
|
|
203
203
|
prompt: string | null;
|
package/dist/routes/shared.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import{HTTPException as
|
|
2
|
-
`)}function
|
|
1
|
+
import{HTTPException as a}from"hono/http-exception";function h(t,e){const n=(t?.input_tokens??0)+e.input_tokens,o=(t?.output_tokens??0)+e.output_tokens,r=(t?.total_tokens??0)+e.total_tokens;if([n,o,r].every(Number.isSafeInteger))return{input_tokens:n,output_tokens:o,total_tokens:r}}function k(t){const e=s=>{const l=s?.input_tokens,i=s?.output_tokens,f=s?.total_tokens;if(!(typeof l!="number"||typeof i!="number"||typeof f!="number"||!Number.isSafeInteger(l)||l<0||!Number.isSafeInteger(i)||i<0||!Number.isSafeInteger(f)||f<0))return{input_tokens:l,output_tokens:i,total_tokens:f}},n=e(t?.total),o=e(t?.last),r=t?.model_context_window;if(!(!n||!o))return{total:n,last:o,...typeof r=="number"&&Number.isSafeInteger(r)&&r>0?{context:{used_tokens:o.total_tokens,window_tokens:r}}:{}}}function p(t){return typeof t=="string"?t:t.filter(e=>e.type==="input_text").map(e=>e.text??"").join(`
|
|
2
|
+
`)}function g(t,e,n,o){const r=(n?[o,e]:[o]).filter(u=>!!u),s=r.length>0?`${r.join(`
|
|
3
3
|
|
|
4
4
|
`)}
|
|
5
5
|
|
|
6
|
-
`:"";if(typeof t=="string")return`${s}${t}`;if(!Array.isArray(t))throw new
|
|
6
|
+
`:"";if(typeof t=="string")return`${s}${t}`;if(!Array.isArray(t))throw new a(400,{message:"Invalid input"});const l=[...t].reverse().find(u=>!!(u&&typeof u=="object"&&"role"in u&&u.role==="user"));if(!l)throw new a(400,{message:"No user message found"});let i=e;if(n&&!i){const u=[...t].reverse().find(c=>!!(c&&typeof c=="object"&&"role"in c)&&(c.role==="system"||c.role==="developer"));u&&(i=p(u.content))}const f=n?[o,i].filter(u=>!!u):[];return`${f.length>0?`${f.join(`
|
|
7
7
|
|
|
8
8
|
`)}
|
|
9
9
|
|
|
10
|
-
`:""}${p(l.content)}`}function m(t,e,n){return{collaborationMode:{mode:t==="plan"?"plan":"default",settings:{model:e||null,reasoning_effort:n
|
|
10
|
+
`:""}${p(l.content)}`}function m(t,e,n){return{collaborationMode:{mode:t==="plan"?"plan":"default",settings:{model:e||null,reasoning_effort:n,developer_instructions:null}}}}function _(t){if(t.type==="agentMessage")return t.text;if(t.type==="reasoning")return t.summary.join(`
|
|
11
11
|
`)||t.content.join(`
|
|
12
12
|
`);if(t.type==="plan")return t.text}function T(t){if(t.type==="commandExecution")return t}function b(t){if(t.type==="fileChange")return t}function C(t){if(t.type==="mcpToolCall")return t}function w(t){if(t.type==="dynamicToolCall")return t}function I(t){if(t.type==="webSearch")return t}function d(t){if(!Array.isArray(t))return;const e=t.map(n=>n&&typeof n=="object"&&"type"in n&&n.type==="text"&&"text"in n&&typeof n.text=="string"?n.text:"").filter(n=>n.length>0).join(`
|
|
13
13
|
`);return e.length>0?e:void 0}function j(t){const e=t.result?.structuredContent;return e&&typeof e=="object"&&"filePath"in e&&typeof e.filePath=="string"?e.filePath:d(t.result?.content)??JSON.stringify(t.result??null)}function x(t){let e=0,n="";for(;e<t.length;){const o=t[e];if(/\s/.test(o))break;if(o==="'"){for(e+=1;e<t.length;){if(t[e]==="'"){e+=1;break}n+=t[e],e+=1}continue}if(o==='"'){for(e+=1;e<t.length;){const r=t[e];if(r==='"'){e+=1;break}if(r==="\\"&&e+1<t.length){n+=t[e+1],e+=2;continue}n+=r,e+=1}continue}if(o==="\\"&&e+1<t.length){n+=t[e+1],e+=2;continue}n+=o,e+=1}return t.slice(e).trim()===""?n:void 0}function S(t){const e=t.match(/^\/bin\/bash\s+-lc\s+([\s\S]+)$/);return e?x(e[1].trim())??t:t}function v(t){return(t.contentItems??[]).map(n=>n.type==="inputText"?n.text:n.imageUrl).filter(n=>n.length>0).join(`
|
|
14
|
-
`)}function $(t){return{query:t.query,...t.action?{action:t.action}:null}}export{h as addTokenUsage,T as commandExecutionItem,S as displayCommand,w as dynamicToolCallItem,v as dynamicToolCallOutput,b as fileChangeItem,
|
|
14
|
+
`)}function $(t){return{query:t.query,...t.action?{action:t.action}:null}}export{h as addTokenUsage,T as commandExecutionItem,S as displayCommand,w as dynamicToolCallItem,v as dynamicToolCallOutput,b as fileChangeItem,g as inputToPrompt,_ as itemText,C as mcpToolCallItem,j as mcpToolCallOutput,p as textFromContent,k as toUsage,m as turnOptions,I as webSearchItem,$ as webSearchPayload};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@messenger-agent/codex-agent",
|
|
3
|
-
"version": "0.37.1-alpha.
|
|
3
|
+
"version": "0.37.1-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"@ai-sdk/openai": "^3.0.63",
|
|
16
16
|
"@hono/node-server": "^2.0.2",
|
|
17
17
|
"@hono/zod-validator": "^0.7.6",
|
|
18
|
-
"@openai/codex": "^0.
|
|
18
|
+
"@openai/codex": "^0.151.0",
|
|
19
19
|
"ai": "^6.0.182",
|
|
20
20
|
"hono": "^4.12.18",
|
|
21
21
|
"undici": "^8.4.1",
|
|
22
22
|
"ws": "^8.21.0",
|
|
23
23
|
"yaml": "^2.9.0",
|
|
24
24
|
"zod": "^4.4.3",
|
|
25
|
-
"@messenger-agent/shared": "0.37.1-alpha.
|
|
25
|
+
"@messenger-agent/shared": "0.37.1-alpha.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/ws": "^8.18.1"
|