UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

3 lines 3.18 kB
import{loadContext}from"#context/container.js";import{ContextKey}from"#context/key.js";const TodoStateKey=new ContextKey(`eve.todo`);function formatTodoSummary(e){return e.items.length===0?void 0:`[Your task list was preserved across context compaction]\n${e.items.map(e=>`- [${e.status===`completed`?`x`:e.status===`cancelled`?`-`:` `}] [${e.priority}] ${e.content}`).join(` `)}`}function getTodoCompactionMessage(){let t=loadContext().get(TodoStateKey);if(t===void 0||t.items.length===0)return;let r=formatTodoSummary(t);if(r!==void 0)return{content:r,role:`user`}}function formatTodoResult(e){let{items:t}=e,n={cancelled:0,completed:0,in_progress:0,pending:0,total:t.length};for(let e of t)n[e.status]++;return{counts:n,todos:t}}function executeTodoTool(t){let r=loadContext(),{todos:i}=t??{};if(i!==void 0){let e={items:[...i]};return r.set(TodoStateKey,e),formatTodoResult(e)}return formatTodoResult(r.ensure(TodoStateKey,()=>({items:[]})))}const TODO_ITEM_SCHEMA={additionalProperties:!1,properties:{content:{description:`Brief description of the task.`,type:`string`},priority:{description:`Priority level of the task.`,enum:[`high`,`medium`,`low`],type:`string`},status:{description:`Current status of the task.`,enum:[`pending`,`in_progress`,`completed`,`cancelled`],type:`string`}},required:[`content`,`status`,`priority`],type:`object`},TODO_OUTPUT_SCHEMA={additionalProperties:!1,properties:{counts:{additionalProperties:!1,properties:{cancelled:{minimum:0,type:`integer`},completed:{minimum:0,type:`integer`},in_progress:{minimum:0,type:`integer`},pending:{minimum:0,type:`integer`},total:{minimum:0,type:`integer`}},required:[`cancelled`,`completed`,`in_progress`,`pending`,`total`],type:`object`},todos:{items:TODO_ITEM_SCHEMA,type:`array`}},required:[`counts`,`todos`],type:`object`},TODO_TOOL_DEFINITION={description:[`Use this tool to create and manage a structured task list for the current session.`,`This helps you track progress, organize complex tasks, and demonstrate thoroughness.`,``,`When to use:`,`- Complex multistep tasks requiring 3 or more distinct steps`,`- When the user provides multiple tasks or a numbered list`,`- After receiving new instructions, to capture requirements`,`- After completing a task, to mark it complete and add follow-ups`,``,`When NOT to use:`,`- Single, straightforward tasks that need no tracking`,`- Purely conversational or informational requests`,``,`Usage:`,"- Call with `todos` to replace the entire list (full replacement write)","- Call without `todos` to read the current list",`- Both return the full current list with status counts`,`- Mark tasks in_progress when you start, completed when done`,`- Only have ONE task in_progress at a time`].join(` `),execute:async e=>executeTodoTool(e??{}),inputSchema:{additionalProperties:!1,properties:{todos:{description:`The updated todo list. Omit to read the current list without modifying it.`,items:TODO_ITEM_SCHEMA,type:`array`}},type:`object`},logicalPath:`eve:framework/todo`,name:`todo`,outputSchema:TODO_OUTPUT_SCHEMA,sourceId:`eve:todo-tool`,sourceKind:`module`};export{TODO_OUTPUT_SCHEMA,TODO_TOOL_DEFINITION,TodoStateKey,executeTodoTool,getTodoCompactionMessage};