agent-protocol
Advanced tools
Comparing version 1.0.1 to 1.0.2
export { v4 } from 'uuid'; | ||
/** | ||
* Input parameters for the task. Any value is allowed. | ||
*/ | ||
type TaskInput = any; | ||
/** | ||
* Artifact that the task has produced. Any value is allowed. | ||
*/ | ||
type Artifact = { | ||
@@ -17,9 +11,3 @@ artifact_id: string; | ||
}; | ||
/** | ||
* Input parameters for the task step. Any value is allowed. | ||
*/ | ||
type StepInput = any; | ||
/** | ||
* Output that the task step has produced. Any value is allowed. | ||
*/ | ||
type StepOutput = any; | ||
@@ -32,30 +20,9 @@ declare enum StepStatus { | ||
interface Step { | ||
/** | ||
* The name of the task step | ||
*/ | ||
name?: string; | ||
/** | ||
* Output of the task step | ||
*/ | ||
output?: StepOutput; | ||
/** | ||
* A list of artifacts that the step has produced. | ||
*/ | ||
artifacts?: Artifact[]; | ||
/** | ||
* Whether this is the last step in the task. | ||
*/ | ||
is_last?: boolean; | ||
input?: StepInput; | ||
/** | ||
* The ID of the task this step belongs to. | ||
*/ | ||
task_id: string; | ||
/** | ||
* The ID of the task step. | ||
*/ | ||
step_id: string; | ||
/** | ||
* Current status of step | ||
*/ | ||
status: StepStatus; | ||
@@ -67,17 +34,5 @@ } | ||
interface StepResult { | ||
/** | ||
* The name of the step | ||
*/ | ||
name?: string; | ||
/** | ||
* Output of the step | ||
*/ | ||
output?: StepOutput; | ||
/** | ||
* A list of artifacts that the step has produced. | ||
*/ | ||
artifacts?: Artifact[]; | ||
/** | ||
* Whether this is the last step in the task. | ||
*/ | ||
is_last?: boolean; | ||
@@ -87,9 +42,3 @@ } | ||
input?: TaskInput; | ||
/** | ||
* The ID of the task. | ||
*/ | ||
task_id: string; | ||
/** | ||
* A list of artifacts that the task has produced. | ||
*/ | ||
artifacts?: Artifact[]; | ||
@@ -101,16 +50,4 @@ } | ||
/** | ||
* A function that handles a step in a task. | ||
* Returns a step result. | ||
*/ | ||
type StepHandler = (input: StepInput | null) => Promise<StepResult>; | ||
/** | ||
* A function that handles a task. | ||
* Returns a step handler. | ||
*/ | ||
type TaskHandler = (taskId: String, input: TaskInput | null) => Promise<StepHandler>; | ||
/** | ||
* A step result with default values. | ||
* @returns StepResult | ||
*/ | ||
declare class StepResultWithDefaults implements StepResult { | ||
@@ -121,38 +58,7 @@ output?: StepOutput; | ||
} | ||
/** | ||
* Creates a task for the agent. | ||
* @param body TaskRequestBody | null | ||
* @returns Promise<Task> | ||
*/ | ||
declare const createAgentTask: (body: TaskRequestBody | null) => Promise<Task>; | ||
/** | ||
* Lists all tasks that have been created for the agent. | ||
* @returns Promise<string[]> | ||
*/ | ||
declare const listAgentTaskIDs: () => Promise<string[]>; | ||
/** | ||
* Get details about a specified agent task. | ||
* @param taskId string | ||
* @returns | ||
*/ | ||
declare const getAgentTask: (taskId: string) => Promise<Task>; | ||
/** | ||
* Lists all steps for the specified task. | ||
* @param taskId string | ||
* @returns Promise<string[]> | ||
*/ | ||
declare const listAgentTaskSteps: (taskId: string) => Promise<string[]>; | ||
/** | ||
* Execute a step in the specified agent task. | ||
* @param taskId string | ||
* @param body StepRequestBody | null | ||
* @returns Promise<Step> | ||
*/ | ||
declare const executeAgentTaskStep: (taskId: string, body: StepRequestBody | null) => Promise<Step>; | ||
/** | ||
* Get details about a specified task step. | ||
* @param taskId string | ||
* @param stepId string | ||
* @returns Promise<Step> | ||
*/ | ||
declare const getAgentTaskStep: (taskId: string, stepId: string) => Promise<Step>; | ||
@@ -159,0 +65,0 @@ interface AgentConfig { |
@@ -582,3 +582,3 @@ var B=Object.create;var g=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var U=(e,t)=>{for(var a in t)g(e,a,{get:t[a],enumerable:!0})},j=(e,t,a,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of O(t))!L.call(e,r)&&r!==a&&g(e,r,{get:()=>t[r],enumerable:!(s=N(t,r))||s.enumerable});return e};var l=(e,t,a)=>(a=e!=null?B(H(e)):{},j(t||!e||!e.__esModule?g(a,"default",{value:e,enumerable:!0}):a,e)),W=e=>j(g({},"__esModule",{value:!0}),e);var rt={};U(rt,{StepResult:()=>h,createAgentTask:()=>S,default:()=>st,executeAgentTaskStep:()=>I,getAgentTask:()=>m,getAgentTaskStep:()=>q,listAgentTaskIDs:()=>v,listAgentTaskSteps:()=>w,v4:()=>C.v4});module.exports=W(rt);var y=require("uuid"),_=l(require("fs")),c=l(require("path"));var $=l(require("express-openapi-validator")),E=l(require("js-yaml")),o=l(require("express"));var A=`openapi: 3.0.1 | ||
- message | ||
`;var P=e=>{let t=(0,o.default)();t.use(o.default.json()),t.use(o.default.text()),t.use(o.default.urlencoded({extended:!1}));let a=E.default.load(A);t.use($.middleware({apiSpec:a,validateRequests:!0,validateResponses:!0})),t.get("/openapi.yaml",(r,n)=>{n.setHeader("Content-Type","text/yaml").status(200).send(A)});let s=(0,o.Router)();e.routes.map(r=>{r(s,e.context)}),t.use("/ap/v1",s),t.listen(e.port,e.callback)};var d=[],R=[],T=null,h=class{output=null;artifacts=[];is_last=!1},S=async e=>{if(T==null)throw new Error("Task handler not defined");let t={task_id:(0,y.v4)(),input:(e==null?void 0:e.input)??null,artifacts:[]},a=await T(t.task_id,(e==null?void 0:e.input)??null);return d.push([t,a]),t},G=e=>{e.post("/agent/tasks",(t,a)=>{(async()=>{try{let s=await S(t.body);a.status(200).json(s)}catch(s){console.error(s),a.status(500).json({error:s.message})}})()})},v=async()=>d.map(([e,t])=>e.task_id),M=e=>{e.get("/agent/tasks",(t,a)=>{(async()=>{try{let s=await v();a.status(200).json(s)}catch(s){console.error(s),a.status(500).json({error:s.message})}})()})},m=async e=>{let t=d.find(([a,s])=>a.task_id===e);if(t==null)throw new Error(`Task with id ${e} not found`);return t[0]},V=e=>{e.get("/agent/tasks/:task_id",(t,a)=>{(async()=>{try{let s=await m(t.params.task_id);a.status(200).json(s)}catch(s){console.error(s),a.status(500).json({error:s.message})}})()})},w=async e=>{if(d.find(([a,s])=>a.task_id===e)==null)throw new Error(`Task with id ${e} not found`);return R.filter(a=>a.task_id===e).map(a=>a.step_id)},J=e=>{e.get("/agent/tasks/:task_id/steps",(t,a)=>{(async()=>{try{let s=await w(t.params.task_id);a.status(200).json(s)}catch(s){console.error(s),a.status(500).json({error:s.message})}})()})},I=async(e,t)=>{let a=d.find(([i,p])=>i.task_id===e);if(a==null)throw new Error(`Task with id ${e} not found`);let s=a[1],r=await s((t==null?void 0:t.input)??null),n={task_id:e,step_id:(0,y.v4)(),input:(t==null?void 0:t.input)??null,name:r.name,output:r.output??null,artifacts:r.artifacts??[],is_last:r.is_last??!1,status:"completed"};return n.artifacts&&n.artifacts.length>0&&(a[0].artifacts=a[0].artifacts??[],a[0].artifacts.push(...n.artifacts)),R.push(n),n},K=e=>{e.post("/agent/tasks/:task_id/steps",(t,a)=>{(async()=>{try{let s=await I(t.params.task_id,t.body);a.status(200).json(s)}catch(s){console.error(s),a.status(500).json({error:s.message})}})()})},q=async(e,t)=>{let a=R.find(s=>s.task_id===e&&s.step_id===t);if(a==null)throw new Error(`Step with task id ${e} and step id ${t} not found`);return a},Q=e=>{e.get("/agent/tasks/:task_id/steps/:step_id",(t,a)=>{(async()=>{try{let s=await q(t.params.task_id,t.params.step_id);a.status(200).json(s)}catch(s){console.error(s),a.status(500).json({error:s.message})}})()})},X=async e=>(await m(e)).artifacts,Y=e=>{e.get("/agent/tasks/:task_id/artifacts",(t,a)=>{(async()=>{let s=t.params.task_id;try{let r=await X(s),n=Number(t.query.current_page)||1,i=Number(t.query.page_size)||10;r||a.status(200).send({artifacts:[],pagination:{total_items:0,total_pages:0,current_page:n,page_size:i}});let p=r.length,x=Math.ceil(p/i),f=(n-1)*i,u=f+i,D=r.slice(f,u);a.status(200).send({artifacts:D,pagination:{total_items:p,total_pages:x,current_page:n,page_size:i}})}catch(r){console.error(r),a.status(404).json({error:r.message})}})()})},F=(e,t,a)=>{let s=c.isAbsolute(t)?t:c.join(process.cwd(),t);return c.join(s,e,a.relative_path??"",a.file_name)},Z=async(e,t,a,s)=>{let n={artifact_id:(0,y.v4)(),agent_created:!1,file_name:a.originalname,relative_path:s||null,created_at:Date.now().toString()};t.artifacts=t.artifacts||[],t.artifacts.push(n);let i=F(t.task_id,e,n);return _.mkdirSync(c.join(i,".."),{recursive:!0}),_.writeFileSync(i,a.buffer),n},tt=(e,t)=>{e.post("/agent/tasks/:task_id/artifacts",(a,s)=>{(async()=>{try{let r=a.params.task_id,n=a.body.relative_path,i=d.find(([{task_id:u}])=>u==r);i||s.status(404).json({message:"Unable to find task with the provided id"});let x=a.files.find(({fieldname:u})=>u=="file"),f=await Z(t.workspace,i[0],x,n);s.status(200).json(f)}catch(r){console.error(r),s.status(500).json({error:r.message})}})()})},et=async(e,t)=>{var r;let s=(r=(await m(e)).artifacts)==null?void 0:r.find(n=>n.artifact_id===t);if(!s)throw new Error(`Artifact with id ${t} in task with id ${e} was not found`);return s},at=(e,t)=>{e.get("/agent/tasks/:task_id/artifacts/:artifact_id",(a,s)=>{(async()=>{let r=a.params.task_id,n=a.params.artifact_id;try{let i=await et(r,n),p=F(r,t.workspace,i);s.status(200).sendFile(p)}catch(i){console.error(i),s.status(404).json({error:i.message})}})()})},b={port:8e3,workspace:"./workspace"},k=class e{constructor(t,a){this.taskHandler=t;this.config=a}static handleTask(t,a){return T=t,new e(t,{workspace:a.workspace||b.workspace,port:a.port||b.port})}start(t){let a={port:t||this.config.port||b.port,routes:[G,M,V,J,K,Q,Y,tt,at],callback:()=>{console.log(`Agent listening at http://localhost:${this.config.port}`)},context:{workspace:this.config.workspace}};P(a)}};var C=require("uuid");var st=k;0&&(module.exports={StepResult,createAgentTask,executeAgentTaskStep,getAgentTask,getAgentTaskStep,listAgentTaskIDs,listAgentTaskSteps,v4}); | ||
`;var P=e=>{let t=(0,o.default)();t.use(o.default.json()),t.use(o.default.text()),t.use(o.default.urlencoded({extended:!1}));let a=E.default.load(A);t.use($.middleware({apiSpec:a,validateRequests:!0,validateResponses:!0})),t.get("/openapi.yaml",(r,n)=>{n.setHeader("Content-Type","text/yaml").status(200).send(A)});let s=(0,o.Router)();e.routes.map(r=>{r(s,e.context)}),t.use("/ap/v1",s),t.listen(e.port,e.callback)};var d=[],R=[],T=null,h=class{constructor(){this.output=null;this.artifacts=[];this.is_last=!1}},S=async e=>{if(T==null)throw new Error("Task handler not defined");let t={task_id:(0,y.v4)(),input:(e==null?void 0:e.input)??null,artifacts:[]},a=await T(t.task_id,(e==null?void 0:e.input)??null);return d.push([t,a]),t},G=e=>{e.post("/agent/tasks",(t,a)=>{(async()=>{try{let s=await S(t.body);a.status(200).json(s)}catch(s){console.error(s),a.status(500).json({error:s.message})}})()})},v=async()=>d.map(([e,t])=>e.task_id),M=e=>{e.get("/agent/tasks",(t,a)=>{(async()=>{try{let s=await v();a.status(200).json(s)}catch(s){console.error(s),a.status(500).json({error:s.message})}})()})},m=async e=>{let t=d.find(([a,s])=>a.task_id===e);if(t==null)throw new Error(`Task with id ${e} not found`);return t[0]},V=e=>{e.get("/agent/tasks/:task_id",(t,a)=>{(async()=>{try{let s=await m(t.params.task_id);a.status(200).json(s)}catch(s){console.error(s),a.status(500).json({error:s.message})}})()})},w=async e=>{if(d.find(([a,s])=>a.task_id===e)==null)throw new Error(`Task with id ${e} not found`);return R.filter(a=>a.task_id===e).map(a=>a.step_id)},J=e=>{e.get("/agent/tasks/:task_id/steps",(t,a)=>{(async()=>{try{let s=await w(t.params.task_id);a.status(200).json(s)}catch(s){console.error(s),a.status(500).json({error:s.message})}})()})},I=async(e,t)=>{let a=d.find(([i,p])=>i.task_id===e);if(a==null)throw new Error(`Task with id ${e} not found`);let s=a[1],r=await s((t==null?void 0:t.input)??null),n={task_id:e,step_id:(0,y.v4)(),input:(t==null?void 0:t.input)??null,name:r.name,output:r.output??null,artifacts:r.artifacts??[],is_last:r.is_last??!1,status:"completed"};return n.artifacts&&n.artifacts.length>0&&(a[0].artifacts=a[0].artifacts??[],a[0].artifacts.push(...n.artifacts)),R.push(n),n},K=e=>{e.post("/agent/tasks/:task_id/steps",(t,a)=>{(async()=>{try{let s=await I(t.params.task_id,t.body);a.status(200).json(s)}catch(s){console.error(s),a.status(500).json({error:s.message})}})()})},q=async(e,t)=>{let a=R.find(s=>s.task_id===e&&s.step_id===t);if(a==null)throw new Error(`Step with task id ${e} and step id ${t} not found`);return a},Q=e=>{e.get("/agent/tasks/:task_id/steps/:step_id",(t,a)=>{(async()=>{try{let s=await q(t.params.task_id,t.params.step_id);a.status(200).json(s)}catch(s){console.error(s),a.status(500).json({error:s.message})}})()})},X=async e=>(await m(e)).artifacts,Y=e=>{e.get("/agent/tasks/:task_id/artifacts",(t,a)=>{(async()=>{let s=t.params.task_id;try{let r=await X(s);if(r==null)return a.status(404).json({error:`Task with id ${s} not found`});let n=Number(t.query.current_page)||1,i=Number(t.query.page_size)||10;r||a.status(200).send({artifacts:[],pagination:{total_items:0,total_pages:0,current_page:n,page_size:i}});let p=r.length,x=Math.ceil(p/i),f=(n-1)*i,u=f+i,D=r.slice(f,u);a.status(200).send({artifacts:D,pagination:{total_items:p,total_pages:x,current_page:n,page_size:i}})}catch(r){console.error(r),a.status(404).json({error:r.message})}})()})},F=(e,t,a)=>{let s=c.isAbsolute(t)?t:c.join(process.cwd(),t);return c.join(s,e,a.relative_path??"",a.file_name)},Z=async(e,t,a,s)=>{let n={artifact_id:(0,y.v4)(),agent_created:!1,file_name:a.originalname,relative_path:s||null,created_at:Date.now().toString()};t.artifacts=t.artifacts||[],t.artifacts.push(n);let i=F(t.task_id,e,n);return _.mkdirSync(c.join(i,".."),{recursive:!0}),_.writeFileSync(i,a.buffer),n},tt=(e,t)=>{e.post("/agent/tasks/:task_id/artifacts",(a,s)=>{(async()=>{try{let r=a.params.task_id,n=a.body.relative_path,i=d.find(([{task_id:u}])=>u==r);if(i===void 0)return s.status(404).json({message:"Unable to find task with the provided id"});let x=a.files.find(({fieldname:u})=>u=="file"),f=await Z(t.workspace,i[0],x,n);s.status(200).json(f)}catch(r){console.error(r),s.status(500).json({error:r.message})}})()})},et=async(e,t)=>{var r;let s=(r=(await m(e)).artifacts)==null?void 0:r.find(n=>n.artifact_id===t);if(!s)throw new Error(`Artifact with id ${t} in task with id ${e} was not found`);return s},at=(e,t)=>{e.get("/agent/tasks/:task_id/artifacts/:artifact_id",(a,s)=>{(async()=>{let r=a.params.task_id,n=a.params.artifact_id;try{let i=await et(r,n),p=F(r,t.workspace,i);s.status(200).sendFile(p)}catch(i){console.error(i),s.status(404).json({error:i.message})}})()})},b={port:8e3,workspace:"./workspace"},k=class e{constructor(t,a){this.taskHandler=t;this.config=a}static handleTask(t,a){return T=t,new e(t,{workspace:a.workspace||b.workspace,port:a.port||b.port})}start(t){let a={port:t||this.config.port||b.port,routes:[G,M,V,J,K,Q,Y,tt,at],callback:()=>{console.log(`Agent listening at http://localhost:${this.config.port}`)},context:{workspace:this.config.workspace}};P(a)}};var C=require("uuid");var st=k;0&&(module.exports={StepResult,createAgentTask,executeAgentTaskStep,getAgentTask,getAgentTaskStep,listAgentTaskIDs,listAgentTaskSteps,v4}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "agent-protocol", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "API for interacting with Agent", | ||
@@ -12,6 +12,6 @@ "homepage": "https://agentprotocol.ai", | ||
}, | ||
"bugs": "https://github.com/AI-Engineer-Foundation/agent-protocol-sdk-js/issues", | ||
"bugs": "https://github.com/AI-Engineer-Foundation/agent-protocol/issues", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/AI-Engineer-Foundation/agent-protocol-sdk-js" | ||
"url": "https://github.com/AI-Engineer-Foundation/agent-protocol/tree/main/packages/sdk/js" | ||
}, | ||
@@ -18,0 +18,0 @@ "main": "./dist/index.js", |
@@ -47,7 +47,6 @@ # Agent Communication Protocol - JavaScript/TypeScript SDK | ||
```bash | ||
git clone https://github.com/AI-Engineers-Foundation/agent-protocol-sdk-js | ||
cd ./agent-protocol-sdk-js | ||
git submodule update --init | ||
git clone https://github.com/AI-Engineers-Foundation/agent-protocol | ||
cd agent-protocol/sdk/js | ||
npm install | ||
npm run build | ||
``` |
Sorry, the diff of this file is not supported yet
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
0
73313
674
52