mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 23:01:30 +00:00
Add abort signal handling to read, write, and edit tools
All tools now check the abort signal before executing and throw "Operation aborted" error if the signal is already aborted. This ensures consistent abort behavior across all tools.
This commit is contained in:
parent
001beff394
commit
e6b47799a4
4 changed files with 84 additions and 2 deletions
66
packages/coding-agent/example.json
Normal file
66
packages/coding-agent/example.json
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
"name": "example",
|
||||
"version": "1.0.0",
|
||||
"description": "A JSON file formatted with tabs",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node index.js",
|
||||
"dev": "nodemon index.js",
|
||||
"build": "tsc",
|
||||
"lint": "eslint .",
|
||||
"format": "prettier --write .",
|
||||
"clean": "rm -rf dist node_modules"
|
||||
},
|
||||
"keywords": [
|
||||
"example",
|
||||
"json",
|
||||
"tabs",
|
||||
"nodejs",
|
||||
"typescript",
|
||||
"api"
|
||||
],
|
||||
"author": "Assistant",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/example/example-repo.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/example/example-repo/issues"
|
||||
},
|
||||
"homepage": "https://github.com/example/example-repo#readme",
|
||||
"engines": {
|
||||
"node": ">=18.0.0",
|
||||
"npm": ">=9.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.18.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"axios": "^1.6.0",
|
||||
"lodash": "^4.17.21",
|
||||
"mongoose": "^8.0.0",
|
||||
"redis": "^4.6.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"bcrypt": "^5.1.1",
|
||||
"winston": "^3.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.10.0",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/bcrypt": "^5.0.2",
|
||||
"@types/jsonwebtoken": "^9.0.5",
|
||||
"typescript": "^5.3.3",
|
||||
"nodemon": "^3.0.2",
|
||||
"eslint": "^8.55.0",
|
||||
"prettier": "^3.1.1",
|
||||
"vitest": "^1.0.4",
|
||||
"supertest": "^6.3.3"
|
||||
},
|
||||
"config": {
|
||||
"port": 3000,
|
||||
"env": "development"
|
||||
},
|
||||
"private": false
|
||||
}
|
||||
|
|
@ -32,7 +32,13 @@ export const editTool: AgentTool<typeof editSchema> = {
|
|||
execute: async (
|
||||
_toolCallId: string,
|
||||
{ path, oldText, newText }: { path: string; oldText: string; newText: string },
|
||||
signal?: AbortSignal,
|
||||
) => {
|
||||
// Check if already aborted
|
||||
if (signal?.aborted) {
|
||||
throw new Error("Operation aborted");
|
||||
}
|
||||
|
||||
const absolutePath = resolve(expandPath(path));
|
||||
|
||||
if (!existsSync(absolutePath)) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,12 @@ export const readTool: AgentTool<typeof readSchema> = {
|
|||
label: "read",
|
||||
description: "Read the contents of a file. Returns the full file content as text.",
|
||||
parameters: readSchema,
|
||||
execute: async (_toolCallId: string, { path }: { path: string }) => {
|
||||
execute: async (_toolCallId: string, { path }: { path: string }, signal?: AbortSignal) => {
|
||||
// Check if already aborted
|
||||
if (signal?.aborted) {
|
||||
throw new Error("Operation aborted");
|
||||
}
|
||||
|
||||
const absolutePath = resolve(expandPath(path));
|
||||
|
||||
if (!existsSync(absolutePath)) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,12 @@ export const writeTool: AgentTool<typeof writeSchema> = {
|
|||
description:
|
||||
"Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.",
|
||||
parameters: writeSchema,
|
||||
execute: async (_toolCallId: string, { path, content }: { path: string; content: string }) => {
|
||||
execute: async (_toolCallId: string, { path, content }: { path: string; content: string }, signal?: AbortSignal) => {
|
||||
// Check if already aborted
|
||||
if (signal?.aborted) {
|
||||
throw new Error("Operation aborted");
|
||||
}
|
||||
|
||||
const absolutePath = resolve(expandPath(path));
|
||||
const dir = dirname(absolutePath);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue