Skip to content

Commit 0f9fd99

Browse files
authored
Merge pull request #6 from bhouston/check-for-updates
Check for updates
2 parents 6e8ca20 + c353b6f commit 0f9fd99

20 files changed

+356
-103
lines changed

src/commands/$default.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ export const handler = async (argv: ArgumentsCamelCase<Options>) => {
4848
if (argv.file) {
4949
try {
5050
prompt = await fs.readFile(argv.file, "utf-8");
51-
} catch (error) {
52-
logger.error(`Failed to read prompt file: ${argv.file}`);
51+
} catch (error: any) {
52+
logger.error(
53+
`Failed to read prompt file: ${argv.file}, ${error?.message}`
54+
);
5355
process.exit(1);
5456
}
5557
}

src/commands/tools.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ArgumentsCamelCase, Argv } from "yargs";
1+
import type { Argv } from "yargs";
22
import { getTools } from "../tools/getTools.js";
33
import type { JsonSchema7Type } from "zod-to-json-schema";
44

@@ -42,7 +42,7 @@ function formatSchema(schema: {
4242
return output;
4343
}
4444

45-
export const handler = async (_argv: ArgumentsCamelCase<ListToolsOptions>) => {
45+
export const handler = async () => {
4646
try {
4747
const tools = await getTools();
4848

@@ -61,8 +61,8 @@ export const handler = async (_argv: ArgumentsCamelCase<ListToolsOptions>) => {
6161
tool.parameters as {
6262
properties?: Record<string, JsonSchema7Type>;
6363
required?: string[];
64-
},
65-
),
64+
}
65+
)
6666
);
6767

6868
// Returns section
@@ -73,8 +73,8 @@ export const handler = async (_argv: ArgumentsCamelCase<ListToolsOptions>) => {
7373
tool.returns as {
7474
properties?: Record<string, JsonSchema7Type>;
7575
required?: string[];
76-
},
77-
),
76+
}
77+
)
7878
);
7979
} else {
8080
console.log(" Type: any");

src/core/executeToolCall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const OUTPUT_LIMIT = 12 * 1024; // 10KB limit
99
export const executeToolCall = async (
1010
toolCall: ToolCall,
1111
tools: Tool[],
12-
parentLogger: Logger
12+
parentLogger: Logger,
1313
): Promise<string> => {
1414
const logger = new Logger({
1515
name: `Tool:${toolCall.name}`,

src/core/toolAgent.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe("toolAgent", () => {
9696
input: { input: "test" },
9797
},
9898
[mockTool],
99-
logger
99+
logger,
100100
);
101101

102102
expect(result.includes("Processed: test")).toBeTruthy();
@@ -111,8 +111,8 @@ describe("toolAgent", () => {
111111
input: {},
112112
},
113113
[mockTool],
114-
logger
115-
)
114+
logger,
115+
),
116116
).rejects.toThrow("No tool with the name 'nonexistentTool' exists.");
117117
});
118118

@@ -142,8 +142,8 @@ describe("toolAgent", () => {
142142
input: {},
143143
},
144144
[errorTool],
145-
logger
146-
)
145+
logger,
146+
),
147147
).rejects.toThrow("Deliberate failure");
148148
});
149149

@@ -153,7 +153,7 @@ describe("toolAgent", () => {
153153
"Test prompt",
154154
[sequenceCompleteTool],
155155
logger,
156-
testConfig
156+
testConfig,
157157
);
158158

159159
expect(result.result).toBe("Test complete");

src/core/toolAgent.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async function executeTools(
112112
toolCalls: ToolUseContent[],
113113
tools: Tool[],
114114
messages: Message[],
115-
logger: Logger
115+
logger: Logger,
116116
): Promise<ToolCallResult> {
117117
if (toolCalls.length === 0) {
118118
return { sequenceCompleted: false, toolResults: [] };
@@ -134,7 +134,7 @@ async function executeTools(
134134
content: toolResult,
135135
isComplete: call.name === "sequenceComplete",
136136
};
137-
})
137+
}),
138138
);
139139

140140
const toolResults = results.map(({ type, tool_use_id, content }) => ({
@@ -160,7 +160,7 @@ export const toolAgent = async (
160160
initialPrompt: string,
161161
tools: Tool[],
162162
logger: Logger,
163-
config = CONFIG
163+
config = CONFIG,
164164
): Promise<ToolAgentResult> => {
165165
logger.verbose("Starting agent execution");
166166
logger.verbose("Initial prompt:", initialPrompt);
@@ -189,7 +189,7 @@ export const toolAgent = async (
189189
logger.verbose(
190190
`Requesting completion ${i + 1} with ${messages.length} messages with ${
191191
JSON.stringify(messages).length
192-
} bytes`
192+
} bytes`,
193193
);
194194

195195
interactions++;
@@ -218,15 +218,15 @@ export const toolAgent = async (
218218
interactions,
219219
};
220220
logger.verbose(
221-
`Agent completed with ${result.tokens.input} input tokens, ${result.tokens.output} output tokens in ${result.interactions} interactions`
221+
`Agent completed with ${result.tokens.input} input tokens, ${result.tokens.output} output tokens in ${result.interactions} interactions`,
222222
);
223223
return result;
224224
}
225225

226226
totalInputTokens += response.usage.input_tokens;
227227
totalOutputTokens += response.usage.output_tokens;
228228
logger.verbose(
229-
` Token usage: ${response.usage.input_tokens} input, ${response.usage.output_tokens} output`
229+
` Token usage: ${response.usage.input_tokens} input, ${response.usage.output_tokens} output`,
230230
);
231231

232232
const { content, toolCalls } = processResponse(response);
@@ -245,7 +245,7 @@ export const toolAgent = async (
245245
toolCalls,
246246
tools,
247247
messages,
248-
logger
248+
logger,
249249
);
250250

251251
if (sequenceCompleted) {
@@ -260,7 +260,7 @@ export const toolAgent = async (
260260
interactions,
261261
};
262262
logger.verbose(
263-
`Agent completed with ${result.tokens.input} input tokens, ${result.tokens.output} output tokens in ${result.interactions} interactions`
263+
`Agent completed with ${result.tokens.input} input tokens, ${result.tokens.output} output tokens in ${result.interactions} interactions`,
264264
);
265265
return result;
266266
}
@@ -276,7 +276,7 @@ export const toolAgent = async (
276276
interactions,
277277
};
278278
logger.verbose(
279-
`Agent completed with ${result.tokens.input} input tokens, ${result.tokens.output} output tokens in ${result.interactions} interactions`
279+
`Agent completed with ${result.tokens.input} input tokens, ${result.tokens.output} output tokens in ${result.interactions} interactions`,
280280
);
281281
return result;
282282
};

src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createRequire } from "module";
66
import { join } from "path";
77
import { fileURLToPath } from "url";
88
import { fileCommands } from "yargs-file-commands";
9+
import { checkForUpdates } from "./utils/versionCheck.js";
910

1011
import sourceMapSupport from "source-map-support";
1112

@@ -20,6 +21,11 @@ const main = async () => {
2021

2122
const logger = new Logger({ name: "Main", color: "white" });
2223

24+
const updateMessage = await checkForUpdates();
25+
if (updateMessage) {
26+
logger.info(updateMessage);
27+
}
28+
2329
// Error handling
2430
process.on("SIGINT", () => {
2531
logger.warn("\nGracefully shutting down...");
@@ -31,7 +37,7 @@ const main = async () => {
3137
"Fatal error:",
3238
error.constructor.name,
3339
error.message,
34-
error.stack
40+
error.stack,
3541
);
3642
process.exit(1);
3743
});
@@ -63,7 +69,7 @@ const main = async () => {
6369
await fileCommands({
6470
commandDirs: [commandsDir],
6571
logLevel: "info",
66-
})
72+
}),
6773
)
6874
.strict()
6975
.showHelpOnFail(true)

src/tools/getTools.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("getTools", () => {
3333
name: expect.any(String),
3434
description: expect.any(String),
3535
parameters: expect.any(Object),
36-
})
36+
}),
3737
);
3838
}
3939
});

src/tools/interaction/subAgent.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe("subAgent", () => {
4141
prompt: "Test sub-agent task",
4242
description: "A test agent for unit testing",
4343
},
44-
{ logger }
44+
{ logger },
4545
);
4646

4747
expect(result.toString()).toContain("Sub-agent task complete");
@@ -57,8 +57,8 @@ describe("subAgent", () => {
5757
prompt: "Test task",
5858
description: "An agent that should fail",
5959
},
60-
{ logger }
61-
)
60+
{ logger },
61+
),
6262
).rejects.toThrow("ANTHROPIC_API_KEY environment variable is not set");
6363
});
6464

@@ -72,8 +72,8 @@ describe("subAgent", () => {
7272
prompt: "Test task",
7373
description: longDescription,
7474
},
75-
{ logger }
76-
)
75+
{ logger },
76+
),
7777
).rejects.toThrow();
7878
});
7979
});

src/tools/interaction/subAgent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const parameterSchema = z.object({
1515
const returnSchema = z
1616
.string()
1717
.describe(
18-
"The response from the sub-agent including its reasoning and tool usage"
18+
"The response from the sub-agent including its reasoning and tool usage",
1919
);
2020

2121
type Parameters = z.infer<typeof parameterSchema>;
@@ -49,7 +49,7 @@ export const subAgentTool: Tool<Parameters, ReturnType> = {
4949
const { prompt } = parameterSchema.parse(params);
5050

5151
const tools = (await getTools()).filter(
52-
(tool) => tool.name !== "userPrompt"
52+
(tool) => tool.name !== "userPrompt",
5353
);
5454

5555
const result = await toolAgent(prompt, tools, logger, subAgentConfig);

src/tools/io/fetch.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const parameterSchema = z.object({
66
method: z
77
.string()
88
.describe(
9-
"HTTP method to use (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)"
9+
"HTTP method to use (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)",
1010
),
1111
url: z.string().describe("URL to make the request to"),
1212
params: z
@@ -39,7 +39,7 @@ export const fetchTool: Tool<Parameters, ReturnType> = {
3939
returns: zodToJsonSchema(returnSchema),
4040
execute: async (
4141
{ method, url, params, body, headers }: Parameters,
42-
{ logger }
42+
{ logger },
4343
): Promise<ReturnType> => {
4444
logger.verbose(`Starting ${method} request to ${url}`);
4545
const urlObj = new URL(url);
@@ -48,7 +48,7 @@ export const fetchTool: Tool<Parameters, ReturnType> = {
4848
if (params) {
4949
logger.verbose("Adding query parameters:", params);
5050
Object.entries(params).forEach(([key, value]) =>
51-
urlObj.searchParams.append(key, value as string)
51+
urlObj.searchParams.append(key, value as string),
5252
);
5353
}
5454

@@ -71,7 +71,7 @@ export const fetchTool: Tool<Parameters, ReturnType> = {
7171
logger.verbose("Request options:", options);
7272
const response = await fetch(urlObj.toString(), options);
7373
logger.verbose(
74-
`Request completed with status ${response.status} ${response.statusText}`
74+
`Request completed with status ${response.status} ${response.statusText}`,
7575
);
7676

7777
const contentType = response.headers.get("content-type");
@@ -91,7 +91,7 @@ export const fetchTool: Tool<Parameters, ReturnType> = {
9191
logParameters(params, { logger }) {
9292
const { method, url, params: queryParams } = params;
9393
logger.info(
94-
`${method} ${url}${queryParams ? `?${new URLSearchParams(queryParams)}` : ""}`
94+
`${method} ${url}${queryParams ? `?${new URLSearchParams(queryParams)}` : ""}`,
9595
);
9696
},
9797
};

0 commit comments

Comments
 (0)