@messenger-agent/codex-agent 0.37.1 → 0.37.2

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,5 +1,6 @@
1
1
  import type { MatrixTaskEvent } from "@messenger-agent/shared/workspace-tasks";
2
2
  import type { DynamicToolCallParams, DynamicToolCallResponse, DynamicToolSpec } from "./app-server-protocol.js";
3
+ export declare function resolveImageFilePath(storePath: string | undefined, workingDirectory: string): Promise<string>;
3
4
  type ManagedTaskToolContext = {
4
5
  workspaceRoot: string;
5
6
  threadRef?: string;
@@ -1 +1 @@
1
- import l from"node:path";import{mkdir as f,writeFile as y}from"node:fs/promises";import{generateImage as T}from"ai";import{createOpenAI as w}from"@ai-sdk/openai";import{Agent as I,fetch as x}from"undici";import{z as r}from"zod";import{executeManagedTaskTool as S,isManagedTaskToolName as b,MANAGED_TASK_TOOL_DEFINITIONS as A}from"@messenger-agent/shared/managed-task-tools";import{AgentFileError as k,resolveAgentFilePath as v}from"@messenger-agent/shared/agent-files";import{executeScheduleTool as E,SCHEDULE_TOOL_DEFINITION as c,ScheduleToolError as _}from"@messenger-agent/shared/schedule-tools";const d=1200*1e3,M=new I({headersTimeout:d,bodyTimeout:d}),R=(t,e)=>x(t,{...e,dispatcher:M}),p=r.object({prompt:r.string().describe("The text prompt describing the image to generate"),store_path:r.string().describe("Absolute file path (including filename) to save the image. If omitted, saves to the current working directory with an auto-generated name.").optional(),size:r.enum(["1024x1024","1536x1024","1024x1536"]).describe("Image size. Leave it undefined to use the auto size.").optional()}),m=r.object({path:r.string().describe("File to send. Absolute paths use the system path; relative paths resolve from the active workspace.")}),N=r.toJSONSchema(p),O=r.toJSONSchema(m);function g(t){return{contentItems:[{type:"inputText",text:JSON.stringify(t)}],success:!0}}const a=new Map;function F(t,e){const o=e.threadRef?.trim();a.set(t,{workspaceRoot:e.workspaceRoot,...o?{threadRef:o}:null,...e.matrixEvent?{matrixEvent:e.matrixEvent}:null,...e.llmProxyBinding?{llmProxyBinding:e.llmProxyBinding}:null})}function u(t,e){const o=a.get(t);if(o)for(const n of e)n&&n!==t&&F(n,o)}function $(t,e){if(t!=="item/started"&&t!=="item/completed"||!e||typeof e!="object")return;const o=e,n=o.item;if(!n||typeof n!="object")return;const i=n;if(i.type==="subAgentActivity"&&i.kind==="started"&&typeof o.threadId=="string"&&typeof i.agentThreadId=="string"){u(o.threadId,[i.agentThreadId]);return}i.type==="collabAgentToolCall"&&i.tool==="spawnAgent"&&typeof i.senderThreadId=="string"&&Array.isArray(i.receiverThreadIds)&&u(i.senderThreadId,i.receiverThreadIds.filter(s=>typeof s=="string"))}async function h(t){const e=a.get(t);if(e)return e.workspaceRoot;const{sessionManager:o}=await import("./codex.js"),n=o.workdirFor(t);if(!n)throw new Error(`No workspace context for thread ${t}; the session may not exist in this process`);return n}async function L(t){const{appConfig:e}=await import("./config.js");if(!e.openai.apiKey)throw new Error("Missing openai.api_key in LLM config");return{apiKey:e.openai.apiKey,baseURL:e.openai.baseUrl,imageModel:e.openai.imageModel,llmProxyBinding:a.get(t)?.llmProxyBinding}}async function C(){const{appConfig:t}=await import("./config.js");return t.schedule}function H(t=!1){const e=[{name:"generate_image",description:"Generate an image from a text prompt. The image is saved to the specified path (absolute path including filename) or the current working directory if not specified. Returns the saved file path.",inputSchema:N},{name:"send_file",description:"Send any readable file to the client. Absolute paths use the system path; relative paths resolve from the active workspace. The agent runtime captures this tool call and performs the actual send.",inputSchema:O},...A.map(o=>({name:o.name,description:o.description,inputSchema:o.inputSchema}))];return t&&e.push({name:c.name,description:c.description,inputSchema:c.inputSchema}),e}async function V(t){try{if(t.tool==="generate_image"){const e=p.parse(t.arguments),o=await L(t.threadId),n=w({apiKey:o.apiKey,baseURL:o.baseURL,fetch:R,...o.llmProxyBinding?{headers:{"X-Elevo-LLM-Binding":o.llmProxyBinding}}:null}),{image:i}=await T({model:n.image(o.imageModel),prompt:e.prompt,size:e.size,maxRetries:0,abortSignal:AbortSignal.timeout(d)}),s=e.store_path?l.resolve(e.store_path):l.join(process.cwd(),`generated_${Date.now()}.png`);return await f(l.dirname(s),{recursive:!0}),await y(s,Buffer.from(i.uint8Array)),{contentItems:[{type:"inputText",text:s}],success:!0}}if(t.tool==="send_file"){const e=m.parse(t.arguments),o=await v(e.path,await h(t.threadId));return{contentItems:[{type:"inputText",text:JSON.stringify({path:o})}],success:!0}}if(b(t.tool)){const e=await S(await h(t.threadId),t.tool,t.arguments,a.get(t.threadId));return g(e)}if(t.tool===c.name)return g(await E(await C(),a.get(t.threadId),t.arguments,fetch,t.callId));throw new Error(`Unknown dynamic tool: ${t.tool}`)}catch(e){const o=e instanceof k&&e.code==="INVALID_PATH"||e instanceof Error?e.message:String(e),n=e instanceof _?{error:{code:e.code,message:e.message,retryable:e.retryable,currentRevision:e.currentRevision}}:o;return{contentItems:[{type:"inputText",text:typeof n=="string"?n:JSON.stringify(n)}],success:!1}}}export{H as dynamicToolSpecs,V as handleDynamicToolCall,u as inheritManagedTaskToolContext,$ as inheritManagedTaskToolContextFromNotification,F as setManagedTaskToolContext};
1
+ import s from"node:path";import{mkdir as f,stat as y,writeFile as T}from"node:fs/promises";import{generateImage as w}from"ai";import{createOpenAI as I}from"@ai-sdk/openai";import{Agent as x,fetch as S}from"undici";import{z as a}from"zod";import{executeManagedTaskTool as v,isManagedTaskToolName as A,MANAGED_TASK_TOOL_DEFINITIONS as b}from"@messenger-agent/shared/managed-task-tools";import{AgentFileError as k,resolveAgentFilePath as E}from"@messenger-agent/shared/agent-files";import{executeScheduleTool as N,SCHEDULE_TOOL_DEFINITION as d,ScheduleToolError as M}from"@messenger-agent/shared/schedule-tools";const l=1200*1e3,_=new x({headersTimeout:l,bodyTimeout:l}),R=(t,e)=>S(t,{...e,dispatcher:_}),p=a.object({prompt:a.string().describe("The text prompt describing the image to generate"),store_path:a.string().describe("File path or directory to save the image. Directory paths (including paths ending with a slash) use an auto-generated filename. If omitted, saves to the current working directory with an auto-generated name.").optional(),size:a.enum(["1024x1024","1536x1024","1024x1536"]).describe("Image size. Leave it undefined to use the auto size.").optional()}),m=a.object({path:a.string().describe("File to send. Absolute paths use the system path; relative paths resolve from the active workspace.")}),F=a.toJSONSchema(p),O=a.toJSONSchema(m);function L(t){return t.endsWith(s.posix.sep)||t.endsWith(s.win32.sep)}async function C(t,e){const o=`generated_${Date.now()}.png`;if(!t)return s.join(e,o);const n=s.resolve(t);let r=L(t);if(!r)try{r=(await y(n)).isDirectory()}catch(i){if(i.code!=="ENOENT")throw i}return r?s.join(n,o):n}function g(t){return{contentItems:[{type:"inputText",text:JSON.stringify(t)}],success:!0}}const c=new Map;function D(t,e){const o=e.threadRef?.trim();c.set(t,{workspaceRoot:e.workspaceRoot,...o?{threadRef:o}:null,...e.matrixEvent?{matrixEvent:e.matrixEvent}:null,...e.llmProxyBinding?{llmProxyBinding:e.llmProxyBinding}:null})}function h(t,e){const o=c.get(t);if(o)for(const n of e)n&&n!==t&&D(n,o)}function V(t,e){if(t!=="item/started"&&t!=="item/completed"||!e||typeof e!="object")return;const o=e,n=o.item;if(!n||typeof n!="object")return;const r=n;if(r.type==="subAgentActivity"&&r.kind==="started"&&typeof o.threadId=="string"&&typeof r.agentThreadId=="string"){h(o.threadId,[r.agentThreadId]);return}r.type==="collabAgentToolCall"&&r.tool==="spawnAgent"&&typeof r.senderThreadId=="string"&&Array.isArray(r.receiverThreadIds)&&h(r.senderThreadId,r.receiverThreadIds.filter(i=>typeof i=="string"))}async function u(t){const e=c.get(t);if(e)return e.workspaceRoot;const{sessionManager:o}=await import("./codex.js"),n=o.workdirFor(t);if(!n)throw new Error(`No workspace context for thread ${t}; the session may not exist in this process`);return n}async function P(t){const{appConfig:e}=await import("./config.js");if(!e.openai.apiKey)throw new Error("Missing openai.api_key in LLM config");return{apiKey:e.openai.apiKey,baseURL:e.openai.baseUrl,imageModel:e.openai.imageModel,llmProxyBinding:c.get(t)?.llmProxyBinding}}async function B(){const{appConfig:t}=await import("./config.js");return t.schedule}function X(t=!1){const e=[{name:"generate_image",description:"Generate an image from a text prompt. The image is saved to the specified file path or directory, or the current working directory if not specified. Returns the saved file path.",inputSchema:F},{name:"send_file",description:"Send any readable file to the client. Absolute paths use the system path; relative paths resolve from the active workspace. The agent runtime captures this tool call and performs the actual send.",inputSchema:O},...b.map(o=>({name:o.name,description:o.description,inputSchema:o.inputSchema}))];return t&&e.push({name:d.name,description:d.description,inputSchema:d.inputSchema}),e}async function q(t){try{if(t.tool==="generate_image"){const e=p.parse(t.arguments),o=await P(t.threadId),n=I({apiKey:o.apiKey,baseURL:o.baseURL,fetch:R,...o.llmProxyBinding?{headers:{"X-Elevo-LLM-Binding":o.llmProxyBinding}}:null}),{image:r}=await w({model:n.image(o.imageModel),prompt:e.prompt,size:e.size,maxRetries:0,abortSignal:AbortSignal.timeout(l)}),i=await C(e.store_path,process.cwd());return await f(s.dirname(i),{recursive:!0}),await T(i,Buffer.from(r.uint8Array)),{contentItems:[{type:"inputText",text:i}],success:!0}}if(t.tool==="send_file"){const e=m.parse(t.arguments),o=await E(e.path,await u(t.threadId));return{contentItems:[{type:"inputText",text:JSON.stringify({path:o})}],success:!0}}if(A(t.tool)){const e=await v(await u(t.threadId),t.tool,t.arguments,c.get(t.threadId));return g(e)}if(t.tool===d.name)return g(await N(await B(),c.get(t.threadId),t.arguments,fetch,t.callId));throw new Error(`Unknown dynamic tool: ${t.tool}`)}catch(e){const o=e instanceof k&&e.code==="INVALID_PATH"||e instanceof Error?e.message:String(e),n=e instanceof M?{error:{code:e.code,message:e.message,retryable:e.retryable,currentRevision:e.currentRevision}}:o;return{contentItems:[{type:"inputText",text:typeof n=="string"?n:JSON.stringify(n)}],success:!1}}}export{X as dynamicToolSpecs,q as handleDynamicToolCall,h as inheritManagedTaskToolContext,V as inheritManagedTaskToolContextFromNotification,C as resolveImageFilePath,D as setManagedTaskToolContext};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@messenger-agent/codex-agent",
3
- "version": "0.37.1",
3
+ "version": "0.37.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -22,7 +22,7 @@
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"
25
+ "@messenger-agent/shared": "0.37.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/ws": "^8.18.1"