@codebolt/agent 5.0.8 → 5.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/unified/base/responseExecutor.js +10 -6
- package/package.json +5 -5
- package/dist/agent.d.ts +0 -86
- package/dist/agent.js +0 -324
- package/dist/builderpattern/agent.d.ts +0 -86
- package/dist/builderpattern/agent.js +0 -324
- package/dist/builderpattern/followupquestionbuilder.d.ts +0 -75
- package/dist/builderpattern/followupquestionbuilder.js +0 -197
- package/dist/builderpattern/index.d.ts +0 -14
- package/dist/builderpattern/index.js +0 -23
- package/dist/builderpattern/llmoutputhandler.d.ts +0 -102
- package/dist/builderpattern/llmoutputhandler.js +0 -452
- package/dist/builderpattern/promptbuilder.d.ts +0 -382
- package/dist/builderpattern/promptbuilder.js +0 -805
- package/dist/builderpattern/systemprompt.d.ts +0 -20
- package/dist/builderpattern/systemprompt.js +0 -48
- package/dist/builderpattern/taskInstruction.d.ts +0 -37
- package/dist/builderpattern/taskInstruction.js +0 -57
- package/dist/builderpattern/usermessage.d.ts +0 -70
- package/dist/builderpattern/usermessage.js +0 -123
- package/dist/composablepattern/agent.d.ts +0 -169
- package/dist/composablepattern/agent.js +0 -598
- package/dist/composablepattern/codebolt-storage.d.ts +0 -67
- package/dist/composablepattern/codebolt-storage.js +0 -320
- package/dist/composablepattern/document.d.ts +0 -149
- package/dist/composablepattern/document.js +0 -405
- package/dist/composablepattern/examples/codebolt-integration-example.d.ts +0 -12
- package/dist/composablepattern/examples/codebolt-integration-example.js +0 -218
- package/dist/composablepattern/examples/codebolt-storage-example.d.ts +0 -40
- package/dist/composablepattern/examples/codebolt-storage-example.js +0 -223
- package/dist/composablepattern/examples/custom-steps-example.d.ts +0 -20
- package/dist/composablepattern/examples/custom-steps-example.js +0 -455
- package/dist/composablepattern/examples/document-agent.d.ts +0 -17
- package/dist/composablepattern/examples/document-agent.js +0 -107
- package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +0 -8
- package/dist/composablepattern/examples/simple-codebolt-integration.js +0 -164
- package/dist/composablepattern/examples/weather-agent.d.ts +0 -18
- package/dist/composablepattern/examples/weather-agent.js +0 -86
- package/dist/composablepattern/examples/workflow-example.d.ts +0 -12
- package/dist/composablepattern/examples/workflow-example.js +0 -463
- package/dist/composablepattern/index.d.ts +0 -63
- package/dist/composablepattern/index.js +0 -115
- package/dist/composablepattern/memory.d.ts +0 -89
- package/dist/composablepattern/memory.js +0 -141
- package/dist/composablepattern/tool.d.ts +0 -84
- package/dist/composablepattern/tool.js +0 -260
- package/dist/composablepattern/types.d.ts +0 -194
- package/dist/composablepattern/types.js +0 -6
- package/dist/composablepattern/user-context.d.ts +0 -214
- package/dist/composablepattern/user-context.js +0 -275
- package/dist/composablepattern/workflow.d.ts +0 -388
- package/dist/composablepattern/workflow.js +0 -562
- package/dist/followupquestionbuilder.d.ts +0 -75
- package/dist/followupquestionbuilder.js +0 -197
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -23
- package/dist/llmoutputhandler.d.ts +0 -102
- package/dist/llmoutputhandler.js +0 -452
- package/dist/processor/agent/agentStep.d.ts +0 -49
- package/dist/processor/agent/agentStep.js +0 -241
- package/dist/processor/agent/toolExecutor.d.ts +0 -19
- package/dist/processor/agent/toolExecutor.js +0 -90
- package/dist/processor/index.d.ts +0 -7
- package/dist/processor/index.js +0 -36
- package/dist/processor/messageModifiers/baseMessageModifier.d.ts +0 -20
- package/dist/processor/messageModifiers/baseMessageModifier.js +0 -55
- package/dist/processor/processors/baseProcessor.d.ts +0 -14
- package/dist/processor/processors/baseProcessor.js +0 -29
- package/dist/processor/tools/baseTool.d.ts +0 -10
- package/dist/processor/tools/baseTool.js +0 -20
- package/dist/processor/tools/toolList.d.ts +0 -9
- package/dist/processor/tools/toolList.js +0 -22
- package/dist/processor/types/interfaces.d.ts +0 -94
- package/dist/processor/types/interfaces.js +0 -2
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +0 -22
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +0 -144
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +0 -15
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +0 -75
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +0 -11
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +0 -46
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +0 -12
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +0 -60
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +0 -18
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +0 -222
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +0 -22
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +0 -194
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +0 -41
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +0 -197
- package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +0 -26
- package/dist/processor-pieces/processors/chatCompressionProcessor.js +0 -90
- package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +0 -81
- package/dist/processor-pieces/processors/chatRecordingProcessor.js +0 -329
- package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +0 -40
- package/dist/processor-pieces/processors/contextManagementProcessor.js +0 -305
- package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +0 -30
- package/dist/processor-pieces/processors/loopDetectionProcessor.js +0 -137
- package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +0 -30
- package/dist/processor-pieces/processors/responseValidationProcessor.js +0 -228
- package/dist/processor-pieces/processors/telemetryProcessor.d.ts +0 -99
- package/dist/processor-pieces/processors/telemetryProcessor.js +0 -311
- package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +0 -37
- package/dist/processor-pieces/processors/tokenManagementProcessor.js +0 -178
- package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +0 -43
- package/dist/processor-pieces/processors/toolExecutionProcessor.js +0 -207
- package/dist/processor-pieces/tools/fileTools.d.ts +0 -26
- package/dist/processor-pieces/tools/fileTools.js +0 -162
- package/dist/promptbuilder.d.ts +0 -382
- package/dist/promptbuilder.js +0 -805
- package/dist/systemprompt.d.ts +0 -20
- package/dist/systemprompt.js +0 -48
- package/dist/taskInstruction.d.ts +0 -37
- package/dist/taskInstruction.js +0 -57
- package/dist/usermessage.d.ts +0 -70
- package/dist/usermessage.js +0 -123
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LLMAgentStep = exports.AgentStep = void 0;
|
|
4
|
-
class AgentStep {
|
|
5
|
-
constructor(options = {}) {
|
|
6
|
-
this.inputProcessors = options.inputProcessors || [];
|
|
7
|
-
this.outputProcessors = options.outputProcessors || [];
|
|
8
|
-
this.toolList = options.toolList;
|
|
9
|
-
this.toolExecutor = options.toolExecutor;
|
|
10
|
-
this.maxIterations = options.maxIterations || 10;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Single step processing with input/output processors
|
|
14
|
-
*/
|
|
15
|
-
async step(message, context) {
|
|
16
|
-
var _a;
|
|
17
|
-
try {
|
|
18
|
-
let processedMessage = message;
|
|
19
|
-
// Apply input processors
|
|
20
|
-
for (const processor of this.inputProcessors) {
|
|
21
|
-
const results = await processor.processInput({
|
|
22
|
-
message: processedMessage,
|
|
23
|
-
context
|
|
24
|
-
});
|
|
25
|
-
// Find the processed message from results
|
|
26
|
-
const messageEvent = results.find(r => r.type === 'MessageProcessed' || r.type === 'MessageWithContext');
|
|
27
|
-
if (messageEvent && messageEvent.value) {
|
|
28
|
-
processedMessage = messageEvent.value;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
// Analyze for tool calls
|
|
32
|
-
const toolCalls = await this.analyzeForToolCalls(processedMessage, ((_a = this.toolList) === null || _a === void 0 ? void 0 : _a.getAllTools()) || [], context);
|
|
33
|
-
if (toolCalls && toolCalls.length > 0) {
|
|
34
|
-
// Execute tools if we have a tool executor
|
|
35
|
-
if (this.toolExecutor) {
|
|
36
|
-
const toolResults = await this.toolExecutor.executeTools({
|
|
37
|
-
toolCalls,
|
|
38
|
-
tools: this.toolList || { getAllTools: () => [], getTool: () => undefined, addTool: () => { }, removeTool: () => { } },
|
|
39
|
-
context
|
|
40
|
-
});
|
|
41
|
-
// Generate response with tool results
|
|
42
|
-
const stepOutput = await this.generateFinalResponse(processedMessage, toolResults, context);
|
|
43
|
-
processedMessage = stepOutput.response;
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
// Return message with tool calls for external execution
|
|
47
|
-
processedMessage = {
|
|
48
|
-
messages: [
|
|
49
|
-
...processedMessage.messages,
|
|
50
|
-
{
|
|
51
|
-
role: 'assistant',
|
|
52
|
-
content: `I need to use tools: ${toolCalls.map(t => t.tool).join(', ')}`,
|
|
53
|
-
tool_calls: toolCalls.map(t => ({
|
|
54
|
-
id: `tool-${Date.now()}`,
|
|
55
|
-
function: { name: t.tool, arguments: t.parameters }
|
|
56
|
-
}))
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
// No tool calls needed, generate final response
|
|
64
|
-
const stepOutput = await this.generateFinalResponse(processedMessage, null, context);
|
|
65
|
-
processedMessage = stepOutput.response;
|
|
66
|
-
}
|
|
67
|
-
// Apply output processors
|
|
68
|
-
for (const processor of this.outputProcessors) {
|
|
69
|
-
const results = await processor.processInput({
|
|
70
|
-
message: processedMessage,
|
|
71
|
-
context
|
|
72
|
-
});
|
|
73
|
-
// Find the processed message from results
|
|
74
|
-
const messageEvent = results.find(r => r.type === 'MessageProcessed' || r.type === 'FinalResponse');
|
|
75
|
-
if (messageEvent && messageEvent.value) {
|
|
76
|
-
processedMessage = messageEvent.value;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return processedMessage;
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
console.error('Error in AgentStep.step:', error);
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
async generateOneStep(input) {
|
|
87
|
-
try {
|
|
88
|
-
const { message, tools, context } = input;
|
|
89
|
-
// Analyze for tool calls
|
|
90
|
-
const toolCalls = await this.analyzeForToolCalls(message, tools, context);
|
|
91
|
-
if (toolCalls && toolCalls.length > 0) {
|
|
92
|
-
// Execute tools
|
|
93
|
-
const toolResults = await this.toolExecutor.executeTools({
|
|
94
|
-
toolCalls,
|
|
95
|
-
tools: { getAllTools: () => tools, getTool: (name) => tools.find(t => t.name === name), addTool: () => { }, removeTool: () => { } },
|
|
96
|
-
context
|
|
97
|
-
});
|
|
98
|
-
// Generate response with tool results
|
|
99
|
-
return await this.generateFinalResponse(message, toolResults, context);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
// No tool calls needed, generate final response
|
|
103
|
-
return await this.generateFinalResponse(message, null, context);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
console.error('Error in generateOneStep:', error);
|
|
108
|
-
throw error;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async generateWithToolExecution(input) {
|
|
112
|
-
try {
|
|
113
|
-
const { message, tools, context } = input;
|
|
114
|
-
// Analyze for tool calls
|
|
115
|
-
const toolCalls = await this.analyzeForToolCalls(message, tools, context);
|
|
116
|
-
if (toolCalls && toolCalls.length > 0) {
|
|
117
|
-
// Execute tools
|
|
118
|
-
const toolResults = await this.toolExecutor.executeTools({
|
|
119
|
-
toolCalls,
|
|
120
|
-
tools: { getAllTools: () => tools, getTool: (name) => tools.find(t => t.name === name), addTool: () => { }, removeTool: () => { } },
|
|
121
|
-
context
|
|
122
|
-
});
|
|
123
|
-
// Generate response with tool results
|
|
124
|
-
return await this.generateFinalResponse(message, toolResults, context);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
// No tool calls needed, generate final response
|
|
128
|
-
return await this.generateFinalResponse(message, null, context);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
console.error('Error in generateWithToolExecution:', error);
|
|
133
|
-
throw error;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
async loop(input, maxIterations) {
|
|
137
|
-
const maxIter = maxIterations || this.maxIterations;
|
|
138
|
-
let currentMessage = input.message;
|
|
139
|
-
let iteration = 0;
|
|
140
|
-
while (iteration < maxIter) {
|
|
141
|
-
iteration++;
|
|
142
|
-
// Generate one step
|
|
143
|
-
const stepResult = await this.generateOneStep({
|
|
144
|
-
message: currentMessage,
|
|
145
|
-
tools: input.tools,
|
|
146
|
-
context: input.context
|
|
147
|
-
});
|
|
148
|
-
// Check if finished
|
|
149
|
-
if (stepResult.finished) {
|
|
150
|
-
return stepResult;
|
|
151
|
-
}
|
|
152
|
-
// Update message for next iteration
|
|
153
|
-
currentMessage = stepResult.response;
|
|
154
|
-
}
|
|
155
|
-
// Max iterations reached
|
|
156
|
-
return await this.generateFinalResponse(currentMessage, null, input.context);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
exports.AgentStep = AgentStep;
|
|
160
|
-
class LLMAgentStep extends AgentStep {
|
|
161
|
-
constructor(options = {}) {
|
|
162
|
-
super(options);
|
|
163
|
-
this.llmConfig = options.llmconfig || { llmname: "DefaultLLM" };
|
|
164
|
-
}
|
|
165
|
-
async analyzeForToolCalls(message, tools, context) {
|
|
166
|
-
// Generic implementation that can work with any LLM
|
|
167
|
-
// In a real scenario, you would call your LLM service here
|
|
168
|
-
const lastMessage = message.messages[message.messages.length - 1];
|
|
169
|
-
const content = typeof lastMessage.content === 'string'
|
|
170
|
-
? lastMessage.content.toLowerCase()
|
|
171
|
-
: JSON.stringify(lastMessage.content).toLowerCase();
|
|
172
|
-
const toolCalls = [];
|
|
173
|
-
// Simple keyword-based tool detection (replace with actual LLM call)
|
|
174
|
-
if (content.includes('read') && content.includes('file')) {
|
|
175
|
-
const filePath = this.extractFilePath(content);
|
|
176
|
-
if (filePath) {
|
|
177
|
-
toolCalls.push({
|
|
178
|
-
tool: 'FileRead',
|
|
179
|
-
parameters: { filePath }
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
if (content.includes('write') && content.includes('file')) {
|
|
184
|
-
const filePath = this.extractFilePath(content);
|
|
185
|
-
if (filePath) {
|
|
186
|
-
toolCalls.push({
|
|
187
|
-
tool: 'FileWrite',
|
|
188
|
-
parameters: { filePath, content: 'Content to be written' }
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (content.includes('delete') && content.includes('file')) {
|
|
193
|
-
const filePath = this.extractFilePath(content);
|
|
194
|
-
if (filePath) {
|
|
195
|
-
toolCalls.push({
|
|
196
|
-
tool: 'FileDelete',
|
|
197
|
-
parameters: { filePath }
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return toolCalls.length > 0 ? toolCalls : null;
|
|
202
|
-
}
|
|
203
|
-
async generateFinalResponse(message, toolResults, context) {
|
|
204
|
-
// Generic implementation that can work with any LLM
|
|
205
|
-
// In a real scenario, you would call your LLM service here
|
|
206
|
-
const lastMessage = message.messages[message.messages.length - 1];
|
|
207
|
-
let responseContent = `I've processed your request: "${lastMessage.content}". Here's my response based on the available information.`;
|
|
208
|
-
// Add tool results if available
|
|
209
|
-
if (toolResults && toolResults.results) {
|
|
210
|
-
const toolResultsText = toolResults.results
|
|
211
|
-
.map((r) => `${r.tool}: ${r.success ? 'Success' : 'Failed'}`)
|
|
212
|
-
.join(', ');
|
|
213
|
-
responseContent += `\n\nTool execution results: ${toolResultsText}`;
|
|
214
|
-
}
|
|
215
|
-
const response = {
|
|
216
|
-
messages: [
|
|
217
|
-
...message.messages,
|
|
218
|
-
{
|
|
219
|
-
role: 'assistant',
|
|
220
|
-
content: responseContent
|
|
221
|
-
}
|
|
222
|
-
],
|
|
223
|
-
metadata: {
|
|
224
|
-
...message.metadata,
|
|
225
|
-
responseGenerated: true,
|
|
226
|
-
timestamp: new Date().toISOString(),
|
|
227
|
-
model: this.llmConfig.model || this.llmConfig.llmname || 'generic-llm'
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
return {
|
|
231
|
-
response,
|
|
232
|
-
finished: true
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
extractFilePath(content) {
|
|
236
|
-
// Simple file path extraction (replace with more sophisticated parsing)
|
|
237
|
-
const filePathMatch = content.match(/['"`]([^'"`]+\.\w+)['"`]/);
|
|
238
|
-
return filePathMatch ? filePathMatch[1] : null;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
exports.LLMAgentStep = LLMAgentStep;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ToolExecutor as IToolExecutor, ToolExecutionInput, ToolExecutionOutput, ToolList } from '../types/interfaces';
|
|
2
|
-
export interface ToolExecutorOptions {
|
|
3
|
-
maxRetries?: number;
|
|
4
|
-
retryDelay?: number;
|
|
5
|
-
enableLogging?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare class ToolExecutor implements IToolExecutor {
|
|
8
|
-
private readonly toolList;
|
|
9
|
-
private readonly maxRetries;
|
|
10
|
-
private readonly retryDelay;
|
|
11
|
-
private readonly enableLogging;
|
|
12
|
-
constructor(toolList: ToolList, options?: ToolExecutorOptions);
|
|
13
|
-
executeTools(input: ToolExecutionInput): Promise<ToolExecutionOutput>;
|
|
14
|
-
private executeToolWithRetry;
|
|
15
|
-
private delay;
|
|
16
|
-
addTool(tool: any): void;
|
|
17
|
-
removeTool(toolName: string): boolean;
|
|
18
|
-
getToolNames(): string[];
|
|
19
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ToolExecutor = void 0;
|
|
4
|
-
class ToolExecutor {
|
|
5
|
-
constructor(toolList, options = {}) {
|
|
6
|
-
this.toolList = toolList;
|
|
7
|
-
this.maxRetries = options.maxRetries || 3;
|
|
8
|
-
this.retryDelay = options.retryDelay || 1000;
|
|
9
|
-
this.enableLogging = options.enableLogging !== false;
|
|
10
|
-
}
|
|
11
|
-
async executeTools(input) {
|
|
12
|
-
try {
|
|
13
|
-
const { toolCalls, tools, context } = input;
|
|
14
|
-
const results = [];
|
|
15
|
-
for (const toolCall of toolCalls) {
|
|
16
|
-
try {
|
|
17
|
-
const tool = tools.getTool(toolCall.tool);
|
|
18
|
-
if (!tool) {
|
|
19
|
-
results.push({
|
|
20
|
-
tool: toolCall.tool,
|
|
21
|
-
result: null,
|
|
22
|
-
error: `Tool '${toolCall.tool}' not found`
|
|
23
|
-
});
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
// Execute tool with retry logic
|
|
27
|
-
const result = await this.executeToolWithRetry(tool, toolCall.parameters);
|
|
28
|
-
results.push({
|
|
29
|
-
tool: toolCall.tool,
|
|
30
|
-
result,
|
|
31
|
-
error: undefined
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
results.push({
|
|
36
|
-
tool: toolCall.tool,
|
|
37
|
-
result: null,
|
|
38
|
-
error: error instanceof Error ? error.message : String(error)
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const success = results.every(r => !r.error);
|
|
43
|
-
return {
|
|
44
|
-
results,
|
|
45
|
-
success
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
console.error('Error in ToolExecutor.executeTools:', error);
|
|
50
|
-
throw error;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
async executeToolWithRetry(tool, parameters) {
|
|
54
|
-
let lastError = null;
|
|
55
|
-
for (let attempt = 1; attempt <= this.maxRetries; attempt++) {
|
|
56
|
-
try {
|
|
57
|
-
if (this.enableLogging) {
|
|
58
|
-
console.log(`[ToolExecutor] Executing ${tool.name} (attempt ${attempt}/${this.maxRetries})`);
|
|
59
|
-
}
|
|
60
|
-
const result = await tool.execute(parameters);
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
65
|
-
if (this.enableLogging) {
|
|
66
|
-
console.warn(`[ToolExecutor] Attempt ${attempt} failed for ${tool.name}:`, lastError.message);
|
|
67
|
-
}
|
|
68
|
-
if (attempt < this.maxRetries) {
|
|
69
|
-
await this.delay(this.retryDelay);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
throw lastError || new Error(`Tool execution failed after ${this.maxRetries} attempts`);
|
|
74
|
-
}
|
|
75
|
-
delay(ms) {
|
|
76
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
77
|
-
}
|
|
78
|
-
// Helper methods for tool management
|
|
79
|
-
addTool(tool) {
|
|
80
|
-
this.toolList.addTool(tool);
|
|
81
|
-
}
|
|
82
|
-
removeTool(toolName) {
|
|
83
|
-
this.toolList.removeTool(toolName);
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
getToolNames() {
|
|
87
|
-
return this.toolList.getAllTools().map(tool => tool.name);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
exports.ToolExecutor = ToolExecutor;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export * from './types/interfaces';
|
|
2
|
-
export { BaseProcessor } from './processors/baseProcessor';
|
|
3
|
-
export { BaseMessageModifier, RequestMessage } from './messageModifiers/baseMessageModifier';
|
|
4
|
-
export { BaseTool } from './tools/baseTool';
|
|
5
|
-
export { AgentStep, AgentStepOptions, LLMAgentStep, LLMAgentStepOptions, LLMConfig } from './agent/agentStep';
|
|
6
|
-
export { ToolExecutor, ToolExecutorOptions } from './agent/toolExecutor';
|
|
7
|
-
export { ToolList as ToolListClass } from './tools/toolList';
|
package/dist/processor/index.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ToolListClass = exports.ToolExecutor = exports.LLMAgentStep = exports.AgentStep = exports.BaseTool = exports.RequestMessage = exports.BaseMessageModifier = exports.BaseProcessor = void 0;
|
|
18
|
-
// Core interfaces
|
|
19
|
-
__exportStar(require("./types/interfaces"), exports);
|
|
20
|
-
// Base classes
|
|
21
|
-
var baseProcessor_1 = require("./processors/baseProcessor");
|
|
22
|
-
Object.defineProperty(exports, "BaseProcessor", { enumerable: true, get: function () { return baseProcessor_1.BaseProcessor; } });
|
|
23
|
-
var baseMessageModifier_1 = require("./messageModifiers/baseMessageModifier");
|
|
24
|
-
Object.defineProperty(exports, "BaseMessageModifier", { enumerable: true, get: function () { return baseMessageModifier_1.BaseMessageModifier; } });
|
|
25
|
-
Object.defineProperty(exports, "RequestMessage", { enumerable: true, get: function () { return baseMessageModifier_1.RequestMessage; } });
|
|
26
|
-
var baseTool_1 = require("./tools/baseTool");
|
|
27
|
-
Object.defineProperty(exports, "BaseTool", { enumerable: true, get: function () { return baseTool_1.BaseTool; } });
|
|
28
|
-
// Agent components
|
|
29
|
-
var agentStep_1 = require("./agent/agentStep");
|
|
30
|
-
Object.defineProperty(exports, "AgentStep", { enumerable: true, get: function () { return agentStep_1.AgentStep; } });
|
|
31
|
-
Object.defineProperty(exports, "LLMAgentStep", { enumerable: true, get: function () { return agentStep_1.LLMAgentStep; } });
|
|
32
|
-
var toolExecutor_1 = require("./agent/toolExecutor");
|
|
33
|
-
Object.defineProperty(exports, "ToolExecutor", { enumerable: true, get: function () { return toolExecutor_1.ToolExecutor; } });
|
|
34
|
-
// Tool management
|
|
35
|
-
var toolList_1 = require("./tools/toolList");
|
|
36
|
-
Object.defineProperty(exports, "ToolListClass", { enumerable: true, get: function () { return toolList_1.ToolList; } });
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { MessageModifier, MessageModifierInput, ProcessedMessage } from '../types/interfaces';
|
|
2
|
-
export interface MessageModifierOptions {
|
|
3
|
-
context?: Record<string, any>;
|
|
4
|
-
}
|
|
5
|
-
export declare abstract class BaseMessageModifier implements MessageModifier {
|
|
6
|
-
protected context: Record<string, any>;
|
|
7
|
-
constructor(options?: MessageModifierOptions);
|
|
8
|
-
abstract modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
9
|
-
setContext(key: string, value: any): void;
|
|
10
|
-
getContext(key: string): any;
|
|
11
|
-
clearContext(): void;
|
|
12
|
-
}
|
|
13
|
-
export declare class RequestMessage {
|
|
14
|
-
private messageModifiers;
|
|
15
|
-
constructor(options?: {
|
|
16
|
-
messageModifiers?: MessageModifier[];
|
|
17
|
-
});
|
|
18
|
-
addModifier(modifier: MessageModifier): void;
|
|
19
|
-
modify(message: any): Promise<ProcessedMessage>;
|
|
20
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RequestMessage = exports.BaseMessageModifier = void 0;
|
|
4
|
-
class BaseMessageModifier {
|
|
5
|
-
constructor(options = {}) {
|
|
6
|
-
this.context = {};
|
|
7
|
-
this.context = options.context || {};
|
|
8
|
-
}
|
|
9
|
-
setContext(key, value) {
|
|
10
|
-
this.context[key] = value;
|
|
11
|
-
}
|
|
12
|
-
getContext(key) {
|
|
13
|
-
return this.context[key];
|
|
14
|
-
}
|
|
15
|
-
clearContext() {
|
|
16
|
-
this.context = {};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.BaseMessageModifier = BaseMessageModifier;
|
|
20
|
-
// New RequestMessage class that can chain multiple modifiers
|
|
21
|
-
class RequestMessage {
|
|
22
|
-
constructor(options = {}) {
|
|
23
|
-
this.messageModifiers = [];
|
|
24
|
-
this.messageModifiers = options.messageModifiers || [];
|
|
25
|
-
}
|
|
26
|
-
addModifier(modifier) {
|
|
27
|
-
this.messageModifiers.push(modifier);
|
|
28
|
-
}
|
|
29
|
-
async modify(message) {
|
|
30
|
-
let currentMessage = {
|
|
31
|
-
messages: [
|
|
32
|
-
{
|
|
33
|
-
role: 'user',
|
|
34
|
-
content: typeof message === 'string' ? message : JSON.stringify(message)
|
|
35
|
-
}
|
|
36
|
-
]
|
|
37
|
-
};
|
|
38
|
-
// Apply each modifier in sequence
|
|
39
|
-
for (const modifier of this.messageModifiers) {
|
|
40
|
-
try {
|
|
41
|
-
currentMessage = await modifier.modify({
|
|
42
|
-
originalRequest: message,
|
|
43
|
-
createdMessage: currentMessage,
|
|
44
|
-
context: {}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
console.error('Error applying message modifier:', error);
|
|
49
|
-
// Continue with other modifiers
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return currentMessage;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.RequestMessage = RequestMessage;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Processor, ProcessorInput, ProcessorOutput } from '../types/interfaces';
|
|
2
|
-
export declare abstract class BaseProcessor implements Processor {
|
|
3
|
-
protected context: Record<string, any>;
|
|
4
|
-
constructor(options?: Record<string, any>);
|
|
5
|
-
abstract processInput(input: ProcessorInput): Promise<ProcessorOutput[]>;
|
|
6
|
-
setContext(key: string, value: any): void;
|
|
7
|
-
getContext(key: string): any;
|
|
8
|
-
clearContext(): void;
|
|
9
|
-
protected createEvent(type: string, value?: any): ProcessorOutput;
|
|
10
|
-
protected createEvents(...events: Array<{
|
|
11
|
-
type: string;
|
|
12
|
-
value?: any;
|
|
13
|
-
}>): ProcessorOutput[];
|
|
14
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseProcessor = void 0;
|
|
4
|
-
class BaseProcessor {
|
|
5
|
-
constructor(options) {
|
|
6
|
-
this.context = {};
|
|
7
|
-
if (options) {
|
|
8
|
-
this.context = { ...options };
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
setContext(key, value) {
|
|
12
|
-
this.context[key] = value;
|
|
13
|
-
}
|
|
14
|
-
getContext(key) {
|
|
15
|
-
return this.context[key];
|
|
16
|
-
}
|
|
17
|
-
clearContext() {
|
|
18
|
-
this.context = {};
|
|
19
|
-
}
|
|
20
|
-
// Helper method to create events
|
|
21
|
-
createEvent(type, value) {
|
|
22
|
-
return { type, value };
|
|
23
|
-
}
|
|
24
|
-
// Helper method to create multiple events
|
|
25
|
-
createEvents(...events) {
|
|
26
|
-
return events.map(event => this.createEvent(event.type, event.value));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.BaseProcessor = BaseProcessor;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Tool } from '../types/interfaces';
|
|
2
|
-
export declare abstract class BaseTool implements Tool {
|
|
3
|
-
readonly name: string;
|
|
4
|
-
readonly description: string;
|
|
5
|
-
readonly parameters: Record<string, any>;
|
|
6
|
-
constructor(name: string, description: string, parameters: Record<string, any>);
|
|
7
|
-
abstract execute(params: any, abortSignal?: AbortSignal): Promise<any>;
|
|
8
|
-
protected checkAbortSignal(abortSignal?: AbortSignal): void;
|
|
9
|
-
protected validateParameters(params: any): boolean;
|
|
10
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseTool = void 0;
|
|
4
|
-
class BaseTool {
|
|
5
|
-
constructor(name, description, parameters) {
|
|
6
|
-
this.name = name;
|
|
7
|
-
this.description = description;
|
|
8
|
-
this.parameters = parameters;
|
|
9
|
-
}
|
|
10
|
-
checkAbortSignal(abortSignal) {
|
|
11
|
-
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
12
|
-
throw new Error('Operation was aborted');
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
validateParameters(params) {
|
|
16
|
-
// Basic validation - can be overridden by subclasses
|
|
17
|
-
return params && typeof params === 'object';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.BaseTool = BaseTool;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ToolList as IToolList, Tool } from '../types/interfaces';
|
|
2
|
-
export declare class ToolList implements IToolList {
|
|
3
|
-
private tools;
|
|
4
|
-
constructor(tools?: Tool[]);
|
|
5
|
-
getTool(name: string): Tool | undefined;
|
|
6
|
-
getAllTools(): Tool[];
|
|
7
|
-
addTool(tool: Tool): void;
|
|
8
|
-
removeTool(name: string): void;
|
|
9
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ToolList = void 0;
|
|
4
|
-
class ToolList {
|
|
5
|
-
constructor(tools = []) {
|
|
6
|
-
this.tools = new Map();
|
|
7
|
-
tools.forEach(tool => this.addTool(tool));
|
|
8
|
-
}
|
|
9
|
-
getTool(name) {
|
|
10
|
-
return this.tools.get(name);
|
|
11
|
-
}
|
|
12
|
-
getAllTools() {
|
|
13
|
-
return Array.from(this.tools.values());
|
|
14
|
-
}
|
|
15
|
-
addTool(tool) {
|
|
16
|
-
this.tools.set(tool.name, tool);
|
|
17
|
-
}
|
|
18
|
-
removeTool(name) {
|
|
19
|
-
this.tools.delete(name);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.ToolList = ToolList;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
export interface ToolCall {
|
|
2
|
-
id: string;
|
|
3
|
-
function: {
|
|
4
|
-
name: string;
|
|
5
|
-
arguments: string | Record<string, any>;
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
export interface Message {
|
|
9
|
-
role: 'user' | 'assistant' | 'tool' | 'system';
|
|
10
|
-
content: string | any[];
|
|
11
|
-
name?: string;
|
|
12
|
-
tool_calls?: ToolCall[];
|
|
13
|
-
tool_call_id?: string;
|
|
14
|
-
[key: string]: any;
|
|
15
|
-
}
|
|
16
|
-
export interface ProcessedMessage {
|
|
17
|
-
messages: Message[];
|
|
18
|
-
metadata?: Record<string, any>;
|
|
19
|
-
}
|
|
20
|
-
export interface ProcessorInput {
|
|
21
|
-
message: ProcessedMessage;
|
|
22
|
-
context?: Record<string, any>;
|
|
23
|
-
}
|
|
24
|
-
export interface ProcessorOutput {
|
|
25
|
-
type: string;
|
|
26
|
-
value?: any;
|
|
27
|
-
}
|
|
28
|
-
export interface Processor {
|
|
29
|
-
processInput(input: ProcessorInput): Promise<ProcessorOutput[]>;
|
|
30
|
-
setContext(key: string, value: any): void;
|
|
31
|
-
getContext(key: string): any;
|
|
32
|
-
clearContext(): void;
|
|
33
|
-
}
|
|
34
|
-
export interface MessageModifierInput {
|
|
35
|
-
originalRequest: any;
|
|
36
|
-
createdMessage: ProcessedMessage;
|
|
37
|
-
context?: Record<string, any>;
|
|
38
|
-
}
|
|
39
|
-
export interface MessageModifier {
|
|
40
|
-
modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
41
|
-
setContext(key: string, value: any): void;
|
|
42
|
-
getContext(key: string): any;
|
|
43
|
-
clearContext(): void;
|
|
44
|
-
}
|
|
45
|
-
export interface Tool {
|
|
46
|
-
name: string;
|
|
47
|
-
description: string;
|
|
48
|
-
parameters: Record<string, any>;
|
|
49
|
-
execute(params: any, abortSignal?: AbortSignal): Promise<any>;
|
|
50
|
-
}
|
|
51
|
-
export interface ToolList {
|
|
52
|
-
getTool(name: string): Tool | undefined;
|
|
53
|
-
getAllTools(): Tool[];
|
|
54
|
-
addTool(tool: Tool): void;
|
|
55
|
-
removeTool(name: string): void;
|
|
56
|
-
}
|
|
57
|
-
export interface AgentStepInput {
|
|
58
|
-
message: ProcessedMessage;
|
|
59
|
-
tools: Tool[];
|
|
60
|
-
context?: Record<string, any>;
|
|
61
|
-
}
|
|
62
|
-
export interface AgentStepOutput {
|
|
63
|
-
response: ProcessedMessage;
|
|
64
|
-
toolCalls?: Array<{
|
|
65
|
-
tool: string;
|
|
66
|
-
parameters: any;
|
|
67
|
-
}>;
|
|
68
|
-
finished: boolean;
|
|
69
|
-
}
|
|
70
|
-
export interface IAgentStep {
|
|
71
|
-
generateOneStep(input: AgentStepInput): Promise<AgentStepOutput>;
|
|
72
|
-
generateWithToolExecution(input: AgentStepInput): Promise<AgentStepOutput>;
|
|
73
|
-
loop(input: AgentStepInput, maxIterations?: number): Promise<AgentStepOutput>;
|
|
74
|
-
}
|
|
75
|
-
export interface ToolExecutionInput {
|
|
76
|
-
toolCalls: Array<{
|
|
77
|
-
tool: string;
|
|
78
|
-
parameters: any;
|
|
79
|
-
}>;
|
|
80
|
-
tools: ToolList;
|
|
81
|
-
context?: Record<string, any>;
|
|
82
|
-
}
|
|
83
|
-
export interface ToolExecutionOutput {
|
|
84
|
-
results: Array<{
|
|
85
|
-
tool: string;
|
|
86
|
-
result: any;
|
|
87
|
-
error?: string;
|
|
88
|
-
}>;
|
|
89
|
-
success: boolean;
|
|
90
|
-
}
|
|
91
|
-
export interface ToolExecutor {
|
|
92
|
-
executeTools(input: ToolExecutionInput): Promise<ToolExecutionOutput>;
|
|
93
|
-
}
|
|
94
|
-
export type AgentEventType = 'content' | 'tool_call_request' | 'tool_call_response' | 'tool_call_confirmation' | 'user_cancelled' | 'error' | 'chat_compressed' | 'thought' | 'max_session_turns' | 'finished' | 'loop_detected';
|