@codebolt/agent 1.2.1 → 2.2.2
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/README.md +157 -66
- package/dist/builderpattern/agent.d.ts +86 -0
- package/dist/builderpattern/agent.js +324 -0
- package/dist/builderpattern/followupquestionbuilder.d.ts +75 -0
- package/dist/builderpattern/followupquestionbuilder.js +197 -0
- package/dist/builderpattern/index.d.ts +14 -0
- package/dist/builderpattern/index.js +23 -0
- package/dist/builderpattern/llmoutputhandler.d.ts +102 -0
- package/dist/builderpattern/llmoutputhandler.js +452 -0
- package/dist/builderpattern/promptbuilder.d.ts +382 -0
- package/dist/builderpattern/promptbuilder.js +805 -0
- package/dist/builderpattern/systemprompt.d.ts +20 -0
- package/dist/builderpattern/systemprompt.js +48 -0
- package/dist/builderpattern/taskInstruction.d.ts +37 -0
- package/dist/builderpattern/taskInstruction.js +57 -0
- package/dist/builderpattern/usermessage.d.ts +70 -0
- package/dist/builderpattern/usermessage.js +123 -0
- package/dist/composablepattern/agent.d.ts +169 -0
- package/dist/composablepattern/agent.js +598 -0
- package/dist/composablepattern/codebolt-storage.d.ts +67 -0
- package/dist/composablepattern/codebolt-storage.js +320 -0
- package/dist/composablepattern/document.d.ts +149 -0
- package/dist/composablepattern/document.js +405 -0
- package/dist/composablepattern/examples/codebolt-integration-example.d.ts +12 -0
- package/dist/composablepattern/examples/codebolt-integration-example.js +218 -0
- package/dist/composablepattern/examples/codebolt-storage-example.d.ts +40 -0
- package/dist/composablepattern/examples/codebolt-storage-example.js +223 -0
- package/dist/composablepattern/examples/custom-steps-example.d.ts +20 -0
- package/dist/composablepattern/examples/custom-steps-example.js +455 -0
- package/dist/composablepattern/examples/document-agent.d.ts +17 -0
- package/dist/composablepattern/examples/document-agent.js +107 -0
- package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +8 -0
- package/dist/composablepattern/examples/simple-codebolt-integration.js +164 -0
- package/dist/composablepattern/examples/weather-agent.d.ts +18 -0
- package/dist/composablepattern/examples/weather-agent.js +86 -0
- package/dist/composablepattern/examples/workflow-example.d.ts +12 -0
- package/dist/composablepattern/examples/workflow-example.js +463 -0
- package/dist/composablepattern/index.d.ts +63 -0
- package/dist/composablepattern/index.js +115 -0
- package/dist/composablepattern/memory.d.ts +89 -0
- package/dist/composablepattern/memory.js +141 -0
- package/dist/composablepattern/tool.d.ts +84 -0
- package/dist/composablepattern/tool.js +260 -0
- package/dist/composablepattern/types.d.ts +194 -0
- package/dist/composablepattern/types.js +6 -0
- package/dist/composablepattern/user-context.d.ts +214 -0
- package/dist/composablepattern/user-context.js +275 -0
- package/dist/composablepattern/workflow.d.ts +388 -0
- package/dist/composablepattern/workflow.js +562 -0
- package/dist/processor/agent/agentStep.d.ts +49 -0
- package/dist/processor/agent/agentStep.js +241 -0
- package/dist/processor/agent/toolExecutor.d.ts +19 -0
- package/dist/processor/agent/toolExecutor.js +90 -0
- package/dist/processor/index.d.ts +7 -0
- package/dist/processor/index.js +36 -0
- package/dist/processor/messageModifiers/baseMessageModifier.d.ts +20 -0
- package/dist/processor/messageModifiers/baseMessageModifier.js +55 -0
- package/dist/processor/processors/baseProcessor.d.ts +14 -0
- package/dist/processor/processors/baseProcessor.js +29 -0
- package/dist/processor/tools/baseTool.d.ts +10 -0
- package/dist/processor/tools/baseTool.js +20 -0
- package/dist/processor/tools/toolList.d.ts +9 -0
- package/dist/processor/tools/toolList.js +22 -0
- package/dist/processor/types/interfaces.d.ts +94 -0
- package/dist/processor/types/interfaces.js +2 -0
- package/dist/processor-pieces/base/baseMessageModifier.d.ts +12 -0
- package/dist/processor-pieces/base/baseMessageModifier.js +15 -0
- package/dist/processor-pieces/base/basePostInferenceProcessor.d.ts +13 -0
- package/dist/processor-pieces/base/basePostInferenceProcessor.js +18 -0
- package/dist/processor-pieces/base/basePostToolCallProcessor.d.ts +15 -0
- package/dist/processor-pieces/base/basePostToolCallProcessor.js +25 -0
- package/dist/processor-pieces/base/basePreInferenceProcessor.d.ts +12 -0
- package/dist/processor-pieces/base/basePreInferenceProcessor.js +17 -0
- package/dist/processor-pieces/base/basePreToolCallProcessor.d.ts +18 -0
- package/dist/processor-pieces/base/basePreToolCallProcessor.js +66 -0
- package/dist/processor-pieces/base/index.d.ts +9 -0
- package/dist/processor-pieces/base/index.js +18 -0
- package/dist/processor-pieces/index.d.ts +1 -0
- package/dist/processor-pieces/index.js +59 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +22 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +144 -0
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.d.ts +13 -0
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +68 -0
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.d.ts +25 -0
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +453 -0
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +15 -0
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +75 -0
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +11 -0
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +46 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.d.ts +18 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.js +104 -0
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.d.ts +23 -0
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +173 -0
- package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.d.ts +14 -0
- package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.js +130 -0
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +36 -0
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +418 -0
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +26 -0
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +260 -0
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +12 -0
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +60 -0
- package/dist/processor-pieces/messageModifiers/ideContextModifier.d.ts +34 -0
- package/dist/processor-pieces/messageModifiers/ideContextModifier.js +157 -0
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +18 -0
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +222 -0
- package/dist/processor-pieces/messageModifiers/index.d.ts +11 -0
- package/dist/processor-pieces/messageModifiers/index.js +26 -0
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.d.ts +15 -0
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +129 -0
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.d.ts +20 -0
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +152 -0
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +22 -0
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +194 -0
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.d.ts +29 -0
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +174 -0
- package/dist/processor-pieces/postToolCallProcessors/index.d.ts +1 -0
- package/dist/processor-pieces/postToolCallProcessors/index.js +2 -0
- package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.d.ts +25 -0
- package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +225 -0
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.d.ts +35 -0
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +255 -0
- package/dist/processor-pieces/preInferenceProcessors/index.d.ts +1 -0
- package/dist/processor-pieces/preInferenceProcessors/index.js +2 -0
- package/dist/processor-pieces/pretoolCallProcessors/index.d.ts +1 -0
- package/dist/processor-pieces/pretoolCallProcessors/index.js +2 -0
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +41 -0
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +197 -0
- package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +26 -0
- package/dist/processor-pieces/processors/chatCompressionProcessor.js +90 -0
- package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +81 -0
- package/dist/processor-pieces/processors/chatRecordingProcessor.js +329 -0
- package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +40 -0
- package/dist/processor-pieces/processors/contextManagementProcessor.js +305 -0
- package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +30 -0
- package/dist/processor-pieces/processors/loopDetectionProcessor.js +137 -0
- package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +30 -0
- package/dist/processor-pieces/processors/responseValidationProcessor.js +228 -0
- package/dist/processor-pieces/processors/telemetryProcessor.d.ts +99 -0
- package/dist/processor-pieces/processors/telemetryProcessor.js +311 -0
- package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +37 -0
- package/dist/processor-pieces/processors/tokenManagementProcessor.js +178 -0
- package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +43 -0
- package/dist/processor-pieces/processors/toolExecutionProcessor.js +207 -0
- package/dist/processor-pieces/tools/fileTools.d.ts +26 -0
- package/dist/processor-pieces/tools/fileTools.js +162 -0
- package/dist/processor-pieces/utils/messageModifierHelper.d.ts +4 -0
- package/dist/processor-pieces/utils/messageModifierHelper.js +58 -0
- package/dist/types/commonTypes.d.ts +4 -0
- package/dist/types/processorTypes.d.ts +67 -0
- package/dist/types/processorTypes.js +58 -0
- package/dist/unified/agent/agent.d.ts +17 -0
- package/dist/unified/agent/agent.js +79 -0
- package/dist/unified/agent/team.d.ts +2 -0
- package/dist/unified/agent/team.js +6 -0
- package/dist/unified/agent/tools.d.ts +44 -0
- package/dist/unified/agent/tools.js +487 -0
- package/dist/unified/agent/workflow.d.ts +24 -0
- package/dist/unified/agent/workflow.js +275 -0
- package/dist/unified/agent/workflowControls.d.ts +11 -0
- package/dist/unified/agent/workflowControls.js +20 -0
- package/dist/unified/agent/workflowSteps.d.ts +63 -0
- package/dist/unified/agent/workflowSteps.js +284 -0
- package/dist/unified/base/agentStep.d.ts +32 -0
- package/dist/unified/base/agentStep.js +96 -0
- package/dist/unified/base/create/createInitialPromptGenerators.d.ts +5 -0
- package/dist/unified/base/create/createInitialPromptGenerators.js +17 -0
- package/dist/unified/base/index.d.ts +5 -0
- package/dist/unified/base/index.js +13 -0
- package/dist/unified/base/initialPromptGenerator.d.ts +48 -0
- package/dist/unified/base/initialPromptGenerator.js +118 -0
- package/dist/unified/base/responseExecutor.d.ts +36 -0
- package/dist/unified/base/responseExecutor.js +283 -0
- package/dist/unified/index.d.ts +18 -0
- package/dist/unified/index.js +42 -0
- package/dist/unified/team/team.d.ts +1 -0
- package/dist/unified/team/team.js +2 -0
- package/dist/unified/types/libTypes.d.ts +378 -0
- package/dist/unified/types/libTypes.js +6 -0
- package/dist/unified/types/types.d.ts +212 -0
- package/dist/unified/types/types.js +43 -0
- package/dist/unified/utils/utils.d.ts +40 -0
- package/dist/unified/utils/utils.js +219 -0
- package/package.json +29 -7
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Memory and Storage implementations for Composable Agent Pattern
|
|
3
|
+
* @description Provides memory management and various storage providers for agent conversations
|
|
4
|
+
*/
|
|
5
|
+
import type { MemoryConfig, StorageProvider, Message } from './types';
|
|
6
|
+
import { type CodeBoltStoreConfig } from './codebolt-storage';
|
|
7
|
+
/**
|
|
8
|
+
* Memory management for agent conversations
|
|
9
|
+
*/
|
|
10
|
+
export declare class Memory {
|
|
11
|
+
private storage;
|
|
12
|
+
private maxMessages;
|
|
13
|
+
private autoSave;
|
|
14
|
+
private conversationKey;
|
|
15
|
+
constructor(config: MemoryConfig);
|
|
16
|
+
/**
|
|
17
|
+
* Save messages to storage
|
|
18
|
+
*
|
|
19
|
+
* @param messages - Array of messages to save
|
|
20
|
+
* @param key - Optional key for storage (defaults to conversation_history)
|
|
21
|
+
*/
|
|
22
|
+
saveMessages(messages: Message[], key?: string): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Load messages from storage
|
|
25
|
+
*
|
|
26
|
+
* @param key - Optional key for storage (defaults to conversation_history)
|
|
27
|
+
* @returns Array of loaded messages
|
|
28
|
+
*/
|
|
29
|
+
loadMessages(key?: string): Promise<Message[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Add a message to the conversation and optionally save
|
|
32
|
+
*
|
|
33
|
+
* @param message - Message to add
|
|
34
|
+
* @param messages - Current messages array
|
|
35
|
+
* @param save - Whether to auto-save to storage
|
|
36
|
+
* @returns Updated messages array
|
|
37
|
+
*/
|
|
38
|
+
addMessage(message: Message, messages: Message[], save?: boolean): Promise<Message[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Clear conversation history
|
|
41
|
+
*
|
|
42
|
+
* @param key - Optional key for storage (defaults to conversation_history)
|
|
43
|
+
*/
|
|
44
|
+
clearMessages(key?: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Get storage provider for custom operations
|
|
47
|
+
*/
|
|
48
|
+
getStorage(): StorageProvider;
|
|
49
|
+
/**
|
|
50
|
+
* Set conversation key for multi-conversation support
|
|
51
|
+
*
|
|
52
|
+
* @param key - New conversation key
|
|
53
|
+
*/
|
|
54
|
+
setConversationKey(key: string): void;
|
|
55
|
+
/**
|
|
56
|
+
* List all conversation keys
|
|
57
|
+
*
|
|
58
|
+
* @returns Array of conversation keys
|
|
59
|
+
*/
|
|
60
|
+
listConversations(): Promise<string[]>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create a Memory instance with CodeBolt backend storage
|
|
64
|
+
*
|
|
65
|
+
* @param config - CodeBolt storage configuration
|
|
66
|
+
* @returns Memory instance
|
|
67
|
+
*/
|
|
68
|
+
export declare function createCodeBoltMemory(config: CodeBoltStoreConfig): Memory;
|
|
69
|
+
/**
|
|
70
|
+
* Create a Memory instance with CodeBolt agent state storage
|
|
71
|
+
*
|
|
72
|
+
* @param prefix - Optional prefix for storage keys
|
|
73
|
+
* @returns Memory instance
|
|
74
|
+
*/
|
|
75
|
+
export declare function createCodeBoltAgentMemory(prefix?: string): Memory;
|
|
76
|
+
/**
|
|
77
|
+
* Create a Memory instance with CodeBolt project state storage
|
|
78
|
+
*
|
|
79
|
+
* @param prefix - Optional prefix for storage keys
|
|
80
|
+
* @returns Memory instance
|
|
81
|
+
*/
|
|
82
|
+
export declare function createCodeBoltProjectMemory(prefix?: string): Memory;
|
|
83
|
+
/**
|
|
84
|
+
* Create a Memory instance with CodeBolt memory database storage
|
|
85
|
+
*
|
|
86
|
+
* @param prefix - Optional prefix for storage keys
|
|
87
|
+
* @returns Memory instance
|
|
88
|
+
*/
|
|
89
|
+
export declare function createCodeBoltDbMemory(prefix?: string): Memory;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Memory and Storage implementations for Composable Agent Pattern
|
|
4
|
+
* @description Provides memory management and various storage providers for agent conversations
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Memory = void 0;
|
|
8
|
+
exports.createCodeBoltMemory = createCodeBoltMemory;
|
|
9
|
+
exports.createCodeBoltAgentMemory = createCodeBoltAgentMemory;
|
|
10
|
+
exports.createCodeBoltProjectMemory = createCodeBoltProjectMemory;
|
|
11
|
+
exports.createCodeBoltDbMemory = createCodeBoltDbMemory;
|
|
12
|
+
const codebolt_storage_1 = require("./codebolt-storage");
|
|
13
|
+
/**
|
|
14
|
+
* Memory management for agent conversations
|
|
15
|
+
*/
|
|
16
|
+
class Memory {
|
|
17
|
+
constructor(config) {
|
|
18
|
+
var _a;
|
|
19
|
+
this.conversationKey = 'conversation_history';
|
|
20
|
+
this.storage = config.storage;
|
|
21
|
+
this.maxMessages = config.maxMessages || 100;
|
|
22
|
+
this.autoSave = (_a = config.autoSave) !== null && _a !== void 0 ? _a : true;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Save messages to storage
|
|
26
|
+
*
|
|
27
|
+
* @param messages - Array of messages to save
|
|
28
|
+
* @param key - Optional key for storage (defaults to conversation_history)
|
|
29
|
+
*/
|
|
30
|
+
async saveMessages(messages, key) {
|
|
31
|
+
const storageKey = key || this.conversationKey;
|
|
32
|
+
// Trim messages if they exceed max limit
|
|
33
|
+
const trimmedMessages = this.maxMessages > 0 && messages.length > this.maxMessages
|
|
34
|
+
? messages.slice(-this.maxMessages)
|
|
35
|
+
: messages;
|
|
36
|
+
await this.storage.set(storageKey, trimmedMessages);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Load messages from storage
|
|
40
|
+
*
|
|
41
|
+
* @param key - Optional key for storage (defaults to conversation_history)
|
|
42
|
+
* @returns Array of loaded messages
|
|
43
|
+
*/
|
|
44
|
+
async loadMessages(key) {
|
|
45
|
+
const storageKey = key || this.conversationKey;
|
|
46
|
+
const messages = await this.storage.get(storageKey);
|
|
47
|
+
return Array.isArray(messages) ? messages : [];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Add a message to the conversation and optionally save
|
|
51
|
+
*
|
|
52
|
+
* @param message - Message to add
|
|
53
|
+
* @param messages - Current messages array
|
|
54
|
+
* @param save - Whether to auto-save to storage
|
|
55
|
+
* @returns Updated messages array
|
|
56
|
+
*/
|
|
57
|
+
async addMessage(message, messages, save = this.autoSave) {
|
|
58
|
+
const updatedMessages = [...messages, message];
|
|
59
|
+
if (save) {
|
|
60
|
+
await this.saveMessages(updatedMessages);
|
|
61
|
+
}
|
|
62
|
+
return updatedMessages;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Clear conversation history
|
|
66
|
+
*
|
|
67
|
+
* @param key - Optional key for storage (defaults to conversation_history)
|
|
68
|
+
*/
|
|
69
|
+
async clearMessages(key) {
|
|
70
|
+
const storageKey = key || this.conversationKey;
|
|
71
|
+
await this.storage.delete(storageKey);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get storage provider for custom operations
|
|
75
|
+
*/
|
|
76
|
+
getStorage() {
|
|
77
|
+
return this.storage;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Set conversation key for multi-conversation support
|
|
81
|
+
*
|
|
82
|
+
* @param key - New conversation key
|
|
83
|
+
*/
|
|
84
|
+
setConversationKey(key) {
|
|
85
|
+
this.conversationKey = key;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* List all conversation keys
|
|
89
|
+
*
|
|
90
|
+
* @returns Array of conversation keys
|
|
91
|
+
*/
|
|
92
|
+
async listConversations() {
|
|
93
|
+
const allKeys = await this.storage.keys();
|
|
94
|
+
return allKeys.filter(key => key.includes('conversation') || key.includes('history'));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.Memory = Memory;
|
|
98
|
+
/**
|
|
99
|
+
* Create a Memory instance with CodeBolt backend storage
|
|
100
|
+
*
|
|
101
|
+
* @param config - CodeBolt storage configuration
|
|
102
|
+
* @returns Memory instance
|
|
103
|
+
*/
|
|
104
|
+
function createCodeBoltMemory(config) {
|
|
105
|
+
return new Memory({
|
|
106
|
+
storage: (0, codebolt_storage_1.createCodeBoltStore)(config)
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Create a Memory instance with CodeBolt agent state storage
|
|
111
|
+
*
|
|
112
|
+
* @param prefix - Optional prefix for storage keys
|
|
113
|
+
* @returns Memory instance
|
|
114
|
+
*/
|
|
115
|
+
function createCodeBoltAgentMemory(prefix) {
|
|
116
|
+
return new Memory({
|
|
117
|
+
storage: (0, codebolt_storage_1.createCodeBoltStore)({ type: 'agent', prefix })
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create a Memory instance with CodeBolt project state storage
|
|
122
|
+
*
|
|
123
|
+
* @param prefix - Optional prefix for storage keys
|
|
124
|
+
* @returns Memory instance
|
|
125
|
+
*/
|
|
126
|
+
function createCodeBoltProjectMemory(prefix) {
|
|
127
|
+
return new Memory({
|
|
128
|
+
storage: (0, codebolt_storage_1.createCodeBoltStore)({ type: 'project', prefix })
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Create a Memory instance with CodeBolt memory database storage
|
|
133
|
+
*
|
|
134
|
+
* @param prefix - Optional prefix for storage keys
|
|
135
|
+
* @returns Memory instance
|
|
136
|
+
*/
|
|
137
|
+
function createCodeBoltDbMemory(prefix) {
|
|
138
|
+
return new Memory({
|
|
139
|
+
storage: (0, codebolt_storage_1.createCodeBoltStore)({ type: 'memory', prefix })
|
|
140
|
+
});
|
|
141
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Tool creation and management for Composable Agent Pattern
|
|
3
|
+
* @description Provides utilities for creating and managing tools in the composable agent framework
|
|
4
|
+
*/
|
|
5
|
+
import type { Tool, ToolConfig } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new tool with input/output validation and execution logic
|
|
8
|
+
*
|
|
9
|
+
* @template TInput - Type for tool input parameters
|
|
10
|
+
* @template TOutput - Type for tool output
|
|
11
|
+
* @param config - Tool configuration object
|
|
12
|
+
* @returns Fully configured tool with validation methods
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const weatherTool = createTool({
|
|
17
|
+
* id: 'get-weather',
|
|
18
|
+
* description: 'Get current weather for a location',
|
|
19
|
+
* inputSchema: z.object({
|
|
20
|
+
* location: z.string().describe('City name'),
|
|
21
|
+
* }),
|
|
22
|
+
* outputSchema: z.object({
|
|
23
|
+
* temperature: z.number(),
|
|
24
|
+
* conditions: z.string(),
|
|
25
|
+
* location: z.string(),
|
|
26
|
+
* }),
|
|
27
|
+
* execute: async ({ context }) => {
|
|
28
|
+
* return await getWeather(context.location);
|
|
29
|
+
* },
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function createTool<TInput = any, TOutput = any>(config: ToolConfig<TInput, TOutput>): Tool<TInput, TOutput>;
|
|
34
|
+
/**
|
|
35
|
+
* Converts a tool to OpenAI function format for LLM usage
|
|
36
|
+
*
|
|
37
|
+
* @param tool - The tool to convert
|
|
38
|
+
* @returns OpenAI function specification
|
|
39
|
+
*/
|
|
40
|
+
export declare function toolToOpenAIFunction(tool: Tool): any;
|
|
41
|
+
/**
|
|
42
|
+
* Converts multiple tools to OpenAI functions format
|
|
43
|
+
*
|
|
44
|
+
* @param tools - Record of tools to convert
|
|
45
|
+
* @returns Array of OpenAI function specifications
|
|
46
|
+
*/
|
|
47
|
+
export declare function toolsToOpenAIFunctions(tools: Record<string, Tool>): any[];
|
|
48
|
+
/**
|
|
49
|
+
* Executes a tool with proper error handling and validation
|
|
50
|
+
*
|
|
51
|
+
* @param tool - The tool to execute
|
|
52
|
+
* @param input - Input parameters for the tool
|
|
53
|
+
* @param agent - Optional agent instance for context
|
|
54
|
+
* @returns Tool execution result
|
|
55
|
+
*/
|
|
56
|
+
export declare function executeTool<TInput, TOutput>(tool: Tool<TInput, TOutput>, input: unknown, agent?: any): Promise<{
|
|
57
|
+
success: boolean;
|
|
58
|
+
result?: TOutput;
|
|
59
|
+
error?: string;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Built-in tool for task completion
|
|
63
|
+
*/
|
|
64
|
+
export declare const attemptCompletionTool: Tool<{
|
|
65
|
+
result: string;
|
|
66
|
+
}, {
|
|
67
|
+
completed: boolean;
|
|
68
|
+
message: string;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Built-in tool for asking follow-up questions
|
|
72
|
+
*/
|
|
73
|
+
export declare const askFollowUpTool: Tool<{
|
|
74
|
+
question: string;
|
|
75
|
+
}, {
|
|
76
|
+
question: string;
|
|
77
|
+
waiting_for_response: boolean;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Creates default tools that are automatically available to all agents
|
|
81
|
+
*
|
|
82
|
+
* @returns Record of default tools
|
|
83
|
+
*/
|
|
84
|
+
export declare function createDefaultTools(): Record<string, Tool>;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Tool creation and management for Composable Agent Pattern
|
|
4
|
+
* @description Provides utilities for creating and managing tools in the composable agent framework
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.askFollowUpTool = exports.attemptCompletionTool = void 0;
|
|
8
|
+
exports.createTool = createTool;
|
|
9
|
+
exports.toolToOpenAIFunction = toolToOpenAIFunction;
|
|
10
|
+
exports.toolsToOpenAIFunctions = toolsToOpenAIFunctions;
|
|
11
|
+
exports.executeTool = executeTool;
|
|
12
|
+
exports.createDefaultTools = createDefaultTools;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new tool with input/output validation and execution logic
|
|
16
|
+
*
|
|
17
|
+
* @template TInput - Type for tool input parameters
|
|
18
|
+
* @template TOutput - Type for tool output
|
|
19
|
+
* @param config - Tool configuration object
|
|
20
|
+
* @returns Fully configured tool with validation methods
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const weatherTool = createTool({
|
|
25
|
+
* id: 'get-weather',
|
|
26
|
+
* description: 'Get current weather for a location',
|
|
27
|
+
* inputSchema: z.object({
|
|
28
|
+
* location: z.string().describe('City name'),
|
|
29
|
+
* }),
|
|
30
|
+
* outputSchema: z.object({
|
|
31
|
+
* temperature: z.number(),
|
|
32
|
+
* conditions: z.string(),
|
|
33
|
+
* location: z.string(),
|
|
34
|
+
* }),
|
|
35
|
+
* execute: async ({ context }) => {
|
|
36
|
+
* return await getWeather(context.location);
|
|
37
|
+
* },
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
function createTool(config) {
|
|
42
|
+
return {
|
|
43
|
+
...config,
|
|
44
|
+
/**
|
|
45
|
+
* Validates input against the tool's input schema
|
|
46
|
+
* @param input - Raw input to validate
|
|
47
|
+
* @returns Validated and typed input
|
|
48
|
+
* @throws {z.ZodError} If validation fails
|
|
49
|
+
*/
|
|
50
|
+
validateInput(input) {
|
|
51
|
+
try {
|
|
52
|
+
return config.inputSchema.parse(input);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
56
|
+
throw new Error(`Tool "${config.id}" input validation failed: ${error.issues
|
|
57
|
+
.map((issue) => `${issue.path.join('.')}: ${issue.message}`)
|
|
58
|
+
.join(', ')}`);
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* Validates output against the tool's output schema
|
|
65
|
+
* @param output - Raw output to validate
|
|
66
|
+
* @returns Validated and typed output
|
|
67
|
+
* @throws {z.ZodError} If validation fails
|
|
68
|
+
*/
|
|
69
|
+
validateOutput(output) {
|
|
70
|
+
try {
|
|
71
|
+
return config.outputSchema.parse(output);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
75
|
+
throw new Error(`Tool "${config.id}" output validation failed: ${error.issues
|
|
76
|
+
.map((issue) => `${issue.path.join('.')}: ${issue.message}`)
|
|
77
|
+
.join(', ')}`);
|
|
78
|
+
}
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Converts a tool to OpenAI function format for LLM usage
|
|
86
|
+
*
|
|
87
|
+
* @param tool - The tool to convert
|
|
88
|
+
* @returns OpenAI function specification
|
|
89
|
+
*/
|
|
90
|
+
function toolToOpenAIFunction(tool) {
|
|
91
|
+
return {
|
|
92
|
+
type: 'function',
|
|
93
|
+
function: {
|
|
94
|
+
name: tool.id,
|
|
95
|
+
description: tool.description,
|
|
96
|
+
parameters: zodSchemaToJsonSchema(tool.inputSchema)
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Converts multiple tools to OpenAI functions format
|
|
102
|
+
*
|
|
103
|
+
* @param tools - Record of tools to convert
|
|
104
|
+
* @returns Array of OpenAI function specifications
|
|
105
|
+
*/
|
|
106
|
+
function toolsToOpenAIFunctions(tools) {
|
|
107
|
+
return Object.values(tools).map(toolToOpenAIFunction);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Executes a tool with proper error handling and validation
|
|
111
|
+
*
|
|
112
|
+
* @param tool - The tool to execute
|
|
113
|
+
* @param input - Input parameters for the tool
|
|
114
|
+
* @param agent - Optional agent instance for context
|
|
115
|
+
* @returns Tool execution result
|
|
116
|
+
*/
|
|
117
|
+
async function executeTool(tool, input, agent) {
|
|
118
|
+
try {
|
|
119
|
+
// Validate input
|
|
120
|
+
const validatedInput = tool.validateInput(input);
|
|
121
|
+
// Execute tool
|
|
122
|
+
const result = await tool.execute({ context: validatedInput, agent });
|
|
123
|
+
// Validate output
|
|
124
|
+
const validatedResult = tool.validateOutput(result);
|
|
125
|
+
return { success: true, result: validatedResult };
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
return {
|
|
129
|
+
success: false,
|
|
130
|
+
error: error instanceof Error ? error.message : String(error)
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Converts a Zod schema to JSON Schema format
|
|
136
|
+
* This is a simplified version - in production you might want to use a library like zod-to-json-schema
|
|
137
|
+
*
|
|
138
|
+
* @param schema - Zod schema to convert
|
|
139
|
+
* @returns JSON Schema object
|
|
140
|
+
*/
|
|
141
|
+
function zodSchemaToJsonSchema(schema) {
|
|
142
|
+
// This is a basic implementation - you might want to use a proper converter
|
|
143
|
+
// like zod-to-json-schema for production use
|
|
144
|
+
if (schema instanceof zod_1.z.ZodObject) {
|
|
145
|
+
const shape = schema.shape;
|
|
146
|
+
const properties = {};
|
|
147
|
+
const required = [];
|
|
148
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
149
|
+
properties[key] = zodTypeToJsonSchema(value);
|
|
150
|
+
// Check if field is required (not optional)
|
|
151
|
+
if (!(value instanceof zod_1.z.ZodOptional)) {
|
|
152
|
+
required.push(key);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
type: 'object',
|
|
157
|
+
properties,
|
|
158
|
+
required: required.length > 0 ? required : undefined,
|
|
159
|
+
additionalProperties: false
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return zodTypeToJsonSchema(schema);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Converts individual Zod types to JSON Schema
|
|
166
|
+
*
|
|
167
|
+
* @param schema - Zod type to convert
|
|
168
|
+
* @returns JSON Schema type definition
|
|
169
|
+
*/
|
|
170
|
+
function zodTypeToJsonSchema(schema) {
|
|
171
|
+
if (schema instanceof zod_1.z.ZodString) {
|
|
172
|
+
const result = { type: 'string' };
|
|
173
|
+
if (schema.description) {
|
|
174
|
+
result.description = schema.description;
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
if (schema instanceof zod_1.z.ZodNumber) {
|
|
179
|
+
const result = { type: 'number' };
|
|
180
|
+
if (schema.description) {
|
|
181
|
+
result.description = schema.description;
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
if (schema instanceof zod_1.z.ZodBoolean) {
|
|
186
|
+
const result = { type: 'boolean' };
|
|
187
|
+
if (schema.description) {
|
|
188
|
+
result.description = schema.description;
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
if (schema instanceof zod_1.z.ZodArray) {
|
|
193
|
+
return {
|
|
194
|
+
type: 'array',
|
|
195
|
+
items: zodTypeToJsonSchema(schema.element)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
if (schema instanceof zod_1.z.ZodOptional) {
|
|
199
|
+
return zodTypeToJsonSchema(schema.unwrap());
|
|
200
|
+
}
|
|
201
|
+
if (schema instanceof zod_1.z.ZodEnum) {
|
|
202
|
+
return {
|
|
203
|
+
type: 'string',
|
|
204
|
+
enum: schema.options
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
// Fallback for unsupported types
|
|
208
|
+
return { type: 'string' };
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Built-in tool for task completion
|
|
212
|
+
*/
|
|
213
|
+
exports.attemptCompletionTool = createTool({
|
|
214
|
+
id: 'attempt_completion',
|
|
215
|
+
description: 'Indicates that the task has been completed successfully',
|
|
216
|
+
inputSchema: zod_1.z.object({
|
|
217
|
+
result: zod_1.z.string().describe('Summary of what was accomplished')
|
|
218
|
+
}),
|
|
219
|
+
outputSchema: zod_1.z.object({
|
|
220
|
+
completed: zod_1.z.boolean(),
|
|
221
|
+
message: zod_1.z.string()
|
|
222
|
+
}),
|
|
223
|
+
execute: async ({ context }) => {
|
|
224
|
+
return {
|
|
225
|
+
completed: true,
|
|
226
|
+
message: context.result
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
/**
|
|
231
|
+
* Built-in tool for asking follow-up questions
|
|
232
|
+
*/
|
|
233
|
+
exports.askFollowUpTool = createTool({
|
|
234
|
+
id: 'ask_followup_question',
|
|
235
|
+
description: 'Ask the user a follow-up question when more information is needed',
|
|
236
|
+
inputSchema: zod_1.z.object({
|
|
237
|
+
question: zod_1.z.string().describe('The question to ask the user')
|
|
238
|
+
}),
|
|
239
|
+
outputSchema: zod_1.z.object({
|
|
240
|
+
question: zod_1.z.string(),
|
|
241
|
+
waiting_for_response: zod_1.z.boolean()
|
|
242
|
+
}),
|
|
243
|
+
execute: async ({ context }) => {
|
|
244
|
+
return {
|
|
245
|
+
question: context.question,
|
|
246
|
+
waiting_for_response: true
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
/**
|
|
251
|
+
* Creates default tools that are automatically available to all agents
|
|
252
|
+
*
|
|
253
|
+
* @returns Record of default tools
|
|
254
|
+
*/
|
|
255
|
+
function createDefaultTools() {
|
|
256
|
+
return {
|
|
257
|
+
attempt_completion: exports.attemptCompletionTool,
|
|
258
|
+
ask_followup_question: exports.askFollowUpTool
|
|
259
|
+
};
|
|
260
|
+
}
|