Skip to content

Commit f302073

Browse files
committed
Fix re-export issues in toolAgent module
1 parent 5f3bb0f commit f302073

File tree

6 files changed

+19
-47
lines changed

6 files changed

+19
-47
lines changed

packages/agent/src/core/toolAgent.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/agent/src/core/toolAgent/index.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export * from './tokenTracking.js';
1414
export * from './types.js';
1515

1616
// Export default system prompt for convenience
17-
export const getDefaultSystemPrompt = (context: any) => {
17+
export const getDefaultSystemPrompt = (context: Record<string, unknown>) => {
1818
return `You are an AI agent that can use tools to accomplish tasks.
1919
2020
Current Context:
@@ -24,20 +24,3 @@ ${context.directoryListing ?? 'No directory listing available'}
2424
System: ${context.systemInfo ?? 'No system info available'}
2525
DateTime: ${new Date().toString()}`;
2626
};
27-
export const getDefaultSystemPrompt = (context: any) => {
28-
return `You are an AI agent that can use tools to accomplish tasks.
29-
30-
Current Context:
31-
Directory: ${context.workingDirectory}
32-
Files:
33-
${context.directoryListing ?? 'No directory listing available'}
34-
System: ${context.systemInfo ?? 'No system info available'}
35-
DateTime: ${new Date().toString()}`;
36-
};
37-
38-
// Re-export everything from the module
39-
export * from './config.js';
40-
export * from './messageUtils.js';
41-
export * from './toolExecutor.js';
42-
export * from './tokenTracking.js';
43-
export * from './types.js';

packages/agent/src/core/toolAgent/toolExecutor.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import { TokenTracker } from '../tokens.js';
55

66
import { Tool, ToolCallResult, ToolContext, ToolUseContent } from './types.js';
77

8+
const safeParse = (value: string) => {
9+
try {
10+
return JSON.parse(value);
11+
} catch (error) {
12+
console.error('Error parsing JSON:', error, 'original value:', value);
13+
return { error: value };
14+
}
15+
};
16+
817
/**
918
* Executes a list of tool calls and returns the results
1019
*/
@@ -67,7 +76,7 @@ export async function executeTools(
6776
type: 'tool-result',
6877
toolCallId: call.id,
6978
toolName: call.name,
70-
result: JSON.parse(toolResult),
79+
result: safeParse(toolResult),
7180
} satisfies ToolResultPart;
7281
}),
7382
);

packages/agent/src/core/toolAgent/types.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
// Re-export all types from the original types.ts file
2-
export * from '../types.js';
1+
// Import types from the core types file
2+
import { Tool, ToolContext } from '../types.js';
33

4-
// Only define new types specific to toolAgent here
4+
// Export the imported types explicitly
5+
export { Tool, ToolContext };
6+
7+
// Define types specific to toolAgent here
58
export interface ToolAgentResult {
69
result: string;
710
interactions: number;
@@ -10,7 +13,7 @@ export interface ToolAgentResult {
1013
export interface ToolCallResult {
1114
sequenceCompleted: boolean;
1215
completionResult?: string;
13-
toolResults: any[];
16+
toolResults: unknown[];
1417
respawn?: { context: string };
1518
}
1619

packages/agent/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export * from './tools/interaction/userPrompt.js';
2626
export * from './core/executeToolCall.js';
2727
export * from './core/types.js';
2828
export * from './core/toolAgent/index.js';
29-
export * from './core/toolAgent/config.js';
3029

3130
// Utils
3231
export * from './tools/getTools.js';

packages/agent/src/tools/interaction/subAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { z } from 'zod';
22
import { zodToJsonSchema } from 'zod-to-json-schema';
33

4-
import { getModel } from '../../core/toolAgent/config.js';
54
import {
65
getDefaultSystemPrompt,
6+
getModel,
77
toolAgent,
88
} from '../../core/toolAgent/index.js';
99
import { Tool, ToolContext } from '../../core/types.js';

0 commit comments

Comments
 (0)