@codebolt/agent 1.1.0 → 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,405 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Document handling for Composable Agent Pattern
|
|
4
|
+
* @description Provides document processing, chunking, and embedding capabilities
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.MDocument = void 0;
|
|
41
|
+
/**
|
|
42
|
+
* Document processing and management class
|
|
43
|
+
*/
|
|
44
|
+
class MDocument {
|
|
45
|
+
constructor(content, type = 'text', metadata = {}) {
|
|
46
|
+
this.content = content;
|
|
47
|
+
this.type = type;
|
|
48
|
+
this.metadata = {
|
|
49
|
+
...metadata,
|
|
50
|
+
createdAt: new Date().toISOString(),
|
|
51
|
+
wordCount: this.countWords(content),
|
|
52
|
+
charCount: content.length
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create MDocument from plain text
|
|
57
|
+
*
|
|
58
|
+
* @param text - Plain text content
|
|
59
|
+
* @param metadata - Optional metadata
|
|
60
|
+
* @returns MDocument instance
|
|
61
|
+
*/
|
|
62
|
+
static fromText(text, metadata) {
|
|
63
|
+
return new MDocument(text, 'text', metadata);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create MDocument from markdown
|
|
67
|
+
*
|
|
68
|
+
* @param markdown - Markdown content
|
|
69
|
+
* @param metadata - Optional metadata
|
|
70
|
+
* @returns MDocument instance
|
|
71
|
+
*/
|
|
72
|
+
static fromMarkdown(markdown, metadata) {
|
|
73
|
+
return new MDocument(markdown, 'markdown', metadata);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create MDocument from JSON
|
|
77
|
+
*
|
|
78
|
+
* @param json - JSON object or string
|
|
79
|
+
* @param metadata - Optional metadata
|
|
80
|
+
* @returns MDocument instance
|
|
81
|
+
*/
|
|
82
|
+
static fromJSON(json, metadata) {
|
|
83
|
+
const content = typeof json === 'string' ? json : JSON.stringify(json, null, 2);
|
|
84
|
+
return new MDocument(content, 'json', metadata);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Create MDocument from file path
|
|
88
|
+
*
|
|
89
|
+
* @param filePath - Path to the file
|
|
90
|
+
* @param metadata - Optional metadata
|
|
91
|
+
* @returns Promise<MDocument> instance
|
|
92
|
+
*/
|
|
93
|
+
static async fromFile(filePath, metadata) {
|
|
94
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
95
|
+
const path = await Promise.resolve().then(() => __importStar(require('path')));
|
|
96
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
97
|
+
const extension = path.extname(filePath).toLowerCase();
|
|
98
|
+
let type = 'text';
|
|
99
|
+
if (extension === '.md')
|
|
100
|
+
type = 'markdown';
|
|
101
|
+
else if (extension === '.json')
|
|
102
|
+
type = 'json';
|
|
103
|
+
else if (extension === '.xml')
|
|
104
|
+
type = 'xml';
|
|
105
|
+
const fileMetadata = {
|
|
106
|
+
...metadata,
|
|
107
|
+
filePath,
|
|
108
|
+
fileName: path.basename(filePath),
|
|
109
|
+
fileExtension: extension
|
|
110
|
+
};
|
|
111
|
+
return new MDocument(content, type, fileMetadata);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get document content
|
|
115
|
+
*/
|
|
116
|
+
getContent() {
|
|
117
|
+
return this.content;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get document type
|
|
121
|
+
*/
|
|
122
|
+
getType() {
|
|
123
|
+
return this.type;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get document metadata
|
|
127
|
+
*/
|
|
128
|
+
getMetadata() {
|
|
129
|
+
return { ...this.metadata };
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Update document metadata
|
|
133
|
+
*
|
|
134
|
+
* @param metadata - Metadata to merge
|
|
135
|
+
*/
|
|
136
|
+
updateMetadata(metadata) {
|
|
137
|
+
this.metadata = {
|
|
138
|
+
...this.metadata,
|
|
139
|
+
...metadata,
|
|
140
|
+
updatedAt: new Date().toISOString()
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Chunk the document into smaller pieces
|
|
145
|
+
*
|
|
146
|
+
* @param options - Chunking options
|
|
147
|
+
* @returns Array of text chunks
|
|
148
|
+
*/
|
|
149
|
+
chunk(options = {}) {
|
|
150
|
+
const { size = 1000, overlap = 100, strategy = 'paragraph' } = options;
|
|
151
|
+
let chunks;
|
|
152
|
+
switch (strategy) {
|
|
153
|
+
case 'sentence':
|
|
154
|
+
chunks = this.chunkBySentence(size, overlap);
|
|
155
|
+
break;
|
|
156
|
+
case 'paragraph':
|
|
157
|
+
chunks = this.chunkByParagraph(size, overlap);
|
|
158
|
+
break;
|
|
159
|
+
case 'semantic':
|
|
160
|
+
chunks = this.chunkSemantic(size, overlap);
|
|
161
|
+
break;
|
|
162
|
+
case 'fixed':
|
|
163
|
+
default:
|
|
164
|
+
chunks = this.chunkFixed(size, overlap);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
this.chunks = chunks;
|
|
168
|
+
this.updateMetadata({
|
|
169
|
+
chunkCount: chunks.length,
|
|
170
|
+
chunkStrategy: strategy,
|
|
171
|
+
chunkSize: size,
|
|
172
|
+
chunkOverlap: overlap
|
|
173
|
+
});
|
|
174
|
+
return chunks;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Get existing chunks or create them if they don't exist
|
|
178
|
+
*/
|
|
179
|
+
getChunks() {
|
|
180
|
+
if (!this.chunks) {
|
|
181
|
+
return this.chunk();
|
|
182
|
+
}
|
|
183
|
+
return this.chunks;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Set embeddings for the document or its chunks
|
|
187
|
+
*
|
|
188
|
+
* @param embeddings - Array of embedding vectors
|
|
189
|
+
*/
|
|
190
|
+
setEmbeddings(embeddings) {
|
|
191
|
+
var _a;
|
|
192
|
+
this.embeddings = embeddings;
|
|
193
|
+
this.updateMetadata({
|
|
194
|
+
hasEmbeddings: true,
|
|
195
|
+
embeddingCount: embeddings.length,
|
|
196
|
+
embeddingDimension: ((_a = embeddings[0]) === null || _a === void 0 ? void 0 : _a.length) || 0
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get embeddings
|
|
201
|
+
*/
|
|
202
|
+
getEmbeddings() {
|
|
203
|
+
return this.embeddings;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Convert to processed document format
|
|
207
|
+
*/
|
|
208
|
+
toProcessedDocument() {
|
|
209
|
+
return {
|
|
210
|
+
content: this.content,
|
|
211
|
+
chunks: this.chunks,
|
|
212
|
+
metadata: this.metadata,
|
|
213
|
+
embeddings: this.embeddings
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Convert to plain object
|
|
218
|
+
*/
|
|
219
|
+
toJSON() {
|
|
220
|
+
return {
|
|
221
|
+
content: this.content,
|
|
222
|
+
type: this.type,
|
|
223
|
+
metadata: this.metadata,
|
|
224
|
+
chunks: this.chunks,
|
|
225
|
+
embeddings: this.embeddings
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Create MDocument from processed document
|
|
230
|
+
*
|
|
231
|
+
* @param processed - Processed document data
|
|
232
|
+
* @returns MDocument instance
|
|
233
|
+
*/
|
|
234
|
+
static fromProcessedDocument(processed) {
|
|
235
|
+
const doc = new MDocument(processed.content, processed.metadata.type || 'text', processed.metadata);
|
|
236
|
+
if (processed.chunks) {
|
|
237
|
+
doc.chunks = processed.chunks;
|
|
238
|
+
}
|
|
239
|
+
if (processed.embeddings) {
|
|
240
|
+
doc.embeddings = processed.embeddings;
|
|
241
|
+
}
|
|
242
|
+
return doc;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Extract text content based on document type
|
|
246
|
+
*/
|
|
247
|
+
extractText() {
|
|
248
|
+
switch (this.type) {
|
|
249
|
+
case 'markdown':
|
|
250
|
+
return this.extractMarkdownText();
|
|
251
|
+
case 'json':
|
|
252
|
+
return this.extractJSONText();
|
|
253
|
+
case 'xml':
|
|
254
|
+
return this.extractXMLText();
|
|
255
|
+
default:
|
|
256
|
+
return this.content;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Count words in content
|
|
261
|
+
*/
|
|
262
|
+
countWords(content) {
|
|
263
|
+
return content.trim().split(/\s+/).filter(word => word.length > 0).length;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Fixed-size chunking with overlap
|
|
267
|
+
*/
|
|
268
|
+
chunkFixed(size, overlap) {
|
|
269
|
+
const chunks = [];
|
|
270
|
+
let start = 0;
|
|
271
|
+
while (start < this.content.length) {
|
|
272
|
+
const end = Math.min(start + size, this.content.length);
|
|
273
|
+
chunks.push(this.content.slice(start, end));
|
|
274
|
+
if (end === this.content.length)
|
|
275
|
+
break;
|
|
276
|
+
start = end - overlap;
|
|
277
|
+
}
|
|
278
|
+
return chunks;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Sentence-based chunking
|
|
282
|
+
*/
|
|
283
|
+
chunkBySentence(size, overlap) {
|
|
284
|
+
const sentences = this.content.split(/[.!?]+/).filter(s => s.trim().length > 0);
|
|
285
|
+
const chunks = [];
|
|
286
|
+
let currentChunk = '';
|
|
287
|
+
let currentSize = 0;
|
|
288
|
+
for (const sentence of sentences) {
|
|
289
|
+
const sentenceSize = sentence.length;
|
|
290
|
+
if (currentSize + sentenceSize > size && currentChunk) {
|
|
291
|
+
chunks.push(currentChunk.trim());
|
|
292
|
+
// Handle overlap by keeping some sentences
|
|
293
|
+
if (overlap > 0) {
|
|
294
|
+
const overlapSentences = currentChunk.split(/[.!?]+/).slice(-Math.ceil(overlap / 100));
|
|
295
|
+
currentChunk = overlapSentences.join('. ') + '. ';
|
|
296
|
+
currentSize = currentChunk.length;
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
currentChunk = '';
|
|
300
|
+
currentSize = 0;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
currentChunk += sentence + '. ';
|
|
304
|
+
currentSize += sentenceSize;
|
|
305
|
+
}
|
|
306
|
+
if (currentChunk.trim()) {
|
|
307
|
+
chunks.push(currentChunk.trim());
|
|
308
|
+
}
|
|
309
|
+
return chunks;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Paragraph-based chunking
|
|
313
|
+
*/
|
|
314
|
+
chunkByParagraph(size, overlap) {
|
|
315
|
+
const paragraphs = this.content.split(/\n\s*\n/).filter(p => p.trim().length > 0);
|
|
316
|
+
const chunks = [];
|
|
317
|
+
let currentChunk = '';
|
|
318
|
+
let currentSize = 0;
|
|
319
|
+
for (const paragraph of paragraphs) {
|
|
320
|
+
const paragraphSize = paragraph.length;
|
|
321
|
+
if (currentSize + paragraphSize > size && currentChunk) {
|
|
322
|
+
chunks.push(currentChunk.trim());
|
|
323
|
+
// Handle overlap
|
|
324
|
+
if (overlap > 0) {
|
|
325
|
+
const words = currentChunk.split(/\s+/);
|
|
326
|
+
const overlapWords = words.slice(-overlap);
|
|
327
|
+
currentChunk = overlapWords.join(' ') + ' ';
|
|
328
|
+
currentSize = currentChunk.length;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
currentChunk = '';
|
|
332
|
+
currentSize = 0;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
currentChunk += paragraph + '\n\n';
|
|
336
|
+
currentSize += paragraphSize;
|
|
337
|
+
}
|
|
338
|
+
if (currentChunk.trim()) {
|
|
339
|
+
chunks.push(currentChunk.trim());
|
|
340
|
+
}
|
|
341
|
+
return chunks;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Semantic chunking (basic implementation)
|
|
345
|
+
*/
|
|
346
|
+
chunkSemantic(size, overlap) {
|
|
347
|
+
// For now, fall back to paragraph chunking
|
|
348
|
+
// In a full implementation, this would use NLP techniques
|
|
349
|
+
return this.chunkByParagraph(size, overlap);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Extract text from markdown
|
|
353
|
+
*/
|
|
354
|
+
extractMarkdownText() {
|
|
355
|
+
// Simple markdown text extraction
|
|
356
|
+
return this.content
|
|
357
|
+
.replace(/^#+\s+/gm, '') // Remove headers
|
|
358
|
+
.replace(/\*\*(.*?)\*\*/g, '$1') // Remove bold
|
|
359
|
+
.replace(/\*(.*?)\*/g, '$1') // Remove italic
|
|
360
|
+
.replace(/`(.*?)`/g, '$1') // Remove inline code
|
|
361
|
+
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') // Remove links
|
|
362
|
+
.replace(/```[\s\S]*?```/g, '') // Remove code blocks
|
|
363
|
+
.trim();
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Extract text from JSON
|
|
367
|
+
*/
|
|
368
|
+
extractJSONText() {
|
|
369
|
+
try {
|
|
370
|
+
const obj = JSON.parse(this.content);
|
|
371
|
+
return this.extractTextFromObject(obj);
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
return this.content;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Extract text from XML
|
|
379
|
+
*/
|
|
380
|
+
extractXMLText() {
|
|
381
|
+
// Simple XML text extraction
|
|
382
|
+
return this.content.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim();
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Recursively extract text from object
|
|
386
|
+
*/
|
|
387
|
+
extractTextFromObject(obj) {
|
|
388
|
+
if (typeof obj === 'string')
|
|
389
|
+
return obj;
|
|
390
|
+
if (typeof obj === 'number')
|
|
391
|
+
return obj.toString();
|
|
392
|
+
if (typeof obj === 'boolean')
|
|
393
|
+
return obj.toString();
|
|
394
|
+
if (obj === null || obj === undefined)
|
|
395
|
+
return '';
|
|
396
|
+
if (Array.isArray(obj)) {
|
|
397
|
+
return obj.map(item => this.extractTextFromObject(item)).join(' ');
|
|
398
|
+
}
|
|
399
|
+
if (typeof obj === 'object') {
|
|
400
|
+
return Object.values(obj).map(value => this.extractTextFromObject(value)).join(' ');
|
|
401
|
+
}
|
|
402
|
+
return '';
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
exports.MDocument = MDocument;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview CodeBolt Integration Example
|
|
3
|
+
* @description Example showing how to use ComposableAgent within CodeBolt's onMessage system
|
|
4
|
+
*/
|
|
5
|
+
import { ComposableAgent } from '../index';
|
|
6
|
+
declare const myAgent: ComposableAgent;
|
|
7
|
+
declare const flexibleAgent: ComposableAgent;
|
|
8
|
+
declare const researchAgent: ComposableAgent;
|
|
9
|
+
declare const writingAgent: ComposableAgent;
|
|
10
|
+
declare const workflowAgent: ComposableAgent;
|
|
11
|
+
declare const complexWorkflow: import("../workflow").Workflow;
|
|
12
|
+
export { myAgent, flexibleAgent, researchAgent, writingAgent, workflowAgent, complexWorkflow };
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview CodeBolt Integration Example
|
|
4
|
+
* @description Example showing how to use ComposableAgent within CodeBolt's onMessage system
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.complexWorkflow = exports.workflowAgent = exports.writingAgent = exports.researchAgent = exports.flexibleAgent = exports.myAgent = void 0;
|
|
8
|
+
const index_1 = require("../index");
|
|
9
|
+
// This would typically be in a separate file, e.g., agent.js
|
|
10
|
+
const codebolt = require('@codebolt/codeboltjs');
|
|
11
|
+
// Create your tools
|
|
12
|
+
const weatherTool = (0, index_1.createTool)({
|
|
13
|
+
id: 'get-weather',
|
|
14
|
+
description: 'Get current weather for a location',
|
|
15
|
+
inputSchema: index_1.z.object({
|
|
16
|
+
location: index_1.z.string().describe('City name'),
|
|
17
|
+
}),
|
|
18
|
+
outputSchema: index_1.z.object({
|
|
19
|
+
temperature: index_1.z.number(),
|
|
20
|
+
conditions: index_1.z.string(),
|
|
21
|
+
location: index_1.z.string(),
|
|
22
|
+
}),
|
|
23
|
+
execute: async ({ context }) => {
|
|
24
|
+
// Mock weather data
|
|
25
|
+
return {
|
|
26
|
+
temperature: 22,
|
|
27
|
+
conditions: 'Sunny',
|
|
28
|
+
location: context.location
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
// Create your composable agent
|
|
33
|
+
const myAgent = new index_1.ComposableAgent({
|
|
34
|
+
name: 'Weather Assistant',
|
|
35
|
+
instructions: `
|
|
36
|
+
You are a helpful weather assistant.
|
|
37
|
+
Use the weather tool to get current weather information.
|
|
38
|
+
Be friendly and provide helpful responses.
|
|
39
|
+
`,
|
|
40
|
+
model: 'weathermodel', // References configuration in codeboltagents.yaml
|
|
41
|
+
tools: { weatherTool },
|
|
42
|
+
processing: {
|
|
43
|
+
// Configure what to process automatically
|
|
44
|
+
processMentionedMCPs: true, // Auto-add mentioned MCPs as tools
|
|
45
|
+
processRemixPrompt: true, // Use remix prompt to enhance instructions
|
|
46
|
+
processMentionedFiles: true, // Include mentioned file contents
|
|
47
|
+
processMentionedAgents: true // Add mentioned agents as sub-agents
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
exports.myAgent = myAgent;
|
|
51
|
+
// CodeBolt integration - this is how you'd use it in your agent
|
|
52
|
+
codebolt.onMessage(async (reqMessage) => {
|
|
53
|
+
try {
|
|
54
|
+
console.log('Received message:', reqMessage);
|
|
55
|
+
// Save the user message globally so the agent can access it
|
|
56
|
+
(0, index_1.saveUserMessage)(reqMessage, {
|
|
57
|
+
// You can override the auto-detection here if needed
|
|
58
|
+
processMentionedMCPs: true,
|
|
59
|
+
processRemixPrompt: true,
|
|
60
|
+
processMentionedFiles: false, // Don't process files for this agent
|
|
61
|
+
processMentionedAgents: true
|
|
62
|
+
});
|
|
63
|
+
// Now simply run the agent - it will automatically use the saved user context
|
|
64
|
+
const result = await myAgent.run();
|
|
65
|
+
if (result.success) {
|
|
66
|
+
return result.message;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
console.error('Agent failed:', result.error);
|
|
70
|
+
return 'Sorry, I encountered an error processing your request.';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error('Error in agent execution:', error);
|
|
75
|
+
return 'Sorry, something went wrong.';
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
// ================================
|
|
79
|
+
// Alternative Example: Manual Configuration per Message
|
|
80
|
+
// ================================
|
|
81
|
+
const flexibleAgent = new index_1.ComposableAgent({
|
|
82
|
+
name: 'Flexible Assistant',
|
|
83
|
+
instructions: 'I am a flexible assistant that adapts based on user context.',
|
|
84
|
+
model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
|
|
85
|
+
tools: { weatherTool }
|
|
86
|
+
// No processing config - will use global user config
|
|
87
|
+
});
|
|
88
|
+
exports.flexibleAgent = flexibleAgent;
|
|
89
|
+
codebolt.onMessage(async (reqMessage) => {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
try {
|
|
92
|
+
// Analyze the message to determine what to process
|
|
93
|
+
const shouldProcessMCPs = ((_a = reqMessage.mentionedMCPs) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
94
|
+
const shouldProcessFiles = (_b = reqMessage.mentionedFiles) === null || _b === void 0 ? void 0 : _b.some((file) => file.endsWith('.json') || file.endsWith('.yaml'));
|
|
95
|
+
// Save with custom configuration
|
|
96
|
+
(0, index_1.saveUserMessage)(reqMessage, {
|
|
97
|
+
processMentionedMCPs: shouldProcessMCPs,
|
|
98
|
+
processRemixPrompt: true,
|
|
99
|
+
processMentionedFiles: shouldProcessFiles,
|
|
100
|
+
processMentionedAgents: false // Don't use sub-agents for this example
|
|
101
|
+
});
|
|
102
|
+
// Run the agent
|
|
103
|
+
const result = await flexibleAgent.run();
|
|
104
|
+
return result.success ? result.message : 'Error occurred';
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.error('Error:', error);
|
|
108
|
+
return 'Error processing request';
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
// ================================
|
|
112
|
+
// Example: Multiple Agents with Shared Context
|
|
113
|
+
// ================================
|
|
114
|
+
const researchAgent = new index_1.ComposableAgent({
|
|
115
|
+
name: 'Research Agent',
|
|
116
|
+
instructions: 'Research and gather information on topics.',
|
|
117
|
+
model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
|
|
118
|
+
processing: { processMentionedFiles: true } // This agent processes files
|
|
119
|
+
});
|
|
120
|
+
exports.researchAgent = researchAgent;
|
|
121
|
+
const writingAgent = new index_1.ComposableAgent({
|
|
122
|
+
name: 'Writing Agent',
|
|
123
|
+
instructions: 'Write content based on research and requirements.',
|
|
124
|
+
model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
|
|
125
|
+
processing: { processRemixPrompt: true } // This agent uses remix prompts
|
|
126
|
+
});
|
|
127
|
+
exports.writingAgent = writingAgent;
|
|
128
|
+
codebolt.onMessage(async (reqMessage) => {
|
|
129
|
+
try {
|
|
130
|
+
// Save user message once for all agents to use
|
|
131
|
+
(0, index_1.saveUserMessage)(reqMessage);
|
|
132
|
+
let result;
|
|
133
|
+
// Determine which agent to use based on message content
|
|
134
|
+
if (reqMessage.userMessage.toLowerCase().includes('research')) {
|
|
135
|
+
result = await researchAgent.run();
|
|
136
|
+
}
|
|
137
|
+
else if (reqMessage.userMessage.toLowerCase().includes('write')) {
|
|
138
|
+
result = await writingAgent.run();
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
// Use the default agent
|
|
142
|
+
result = await myAgent.run();
|
|
143
|
+
}
|
|
144
|
+
return result.success ? result.message : 'Error occurred';
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.error('Error:', error);
|
|
148
|
+
return 'Error processing request';
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
// ================================
|
|
152
|
+
// Example: Workflow with Global Context
|
|
153
|
+
// ================================
|
|
154
|
+
const index_2 = require("../index");
|
|
155
|
+
const workflowAgent = new index_1.ComposableAgent({
|
|
156
|
+
name: 'Workflow Agent',
|
|
157
|
+
instructions: 'I coordinate complex multi-step tasks.',
|
|
158
|
+
model: 'gpt-4o-mini' // References configuration in codeboltagents.yaml
|
|
159
|
+
});
|
|
160
|
+
exports.workflowAgent = workflowAgent;
|
|
161
|
+
const complexWorkflow = (0, index_2.createWorkflow)({
|
|
162
|
+
name: 'Research and Write Workflow',
|
|
163
|
+
initialData: {}, // Will be populated from user context
|
|
164
|
+
steps: [
|
|
165
|
+
// Extract user context into workflow data
|
|
166
|
+
(0, index_2.createSimpleStep)({
|
|
167
|
+
id: 'setup-context',
|
|
168
|
+
name: 'Setup Workflow Context',
|
|
169
|
+
execute: () => {
|
|
170
|
+
const userMsg = (0, index_1.getUserMessage)();
|
|
171
|
+
const files = (0, index_1.getMentionedFiles)();
|
|
172
|
+
const mcps = (0, index_1.getMentionedMCPs)();
|
|
173
|
+
return {
|
|
174
|
+
userMessage: (userMsg === null || userMsg === void 0 ? void 0 : userMsg.userMessage) || '',
|
|
175
|
+
mentionedFiles: files,
|
|
176
|
+
mentionedMCPs: mcps,
|
|
177
|
+
setupComplete: true
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}),
|
|
181
|
+
// Use agent step that automatically gets user context
|
|
182
|
+
(0, index_2.createAgentStep)({
|
|
183
|
+
id: 'research-step',
|
|
184
|
+
name: 'Research Phase',
|
|
185
|
+
agent: researchAgent,
|
|
186
|
+
messageTemplate: 'Research this topic: {{userMessage}}',
|
|
187
|
+
outputMapping: { 'researchData': 'agentResult.message' }
|
|
188
|
+
}),
|
|
189
|
+
(0, index_2.createAgentStep)({
|
|
190
|
+
id: 'writing-step',
|
|
191
|
+
name: 'Writing Phase',
|
|
192
|
+
agent: writingAgent,
|
|
193
|
+
messageTemplate: 'Write content based on: {{researchData}}',
|
|
194
|
+
outputMapping: { 'finalContent': 'agentResult.message' }
|
|
195
|
+
})
|
|
196
|
+
]
|
|
197
|
+
});
|
|
198
|
+
exports.complexWorkflow = complexWorkflow;
|
|
199
|
+
codebolt.onMessage(async (reqMessage) => {
|
|
200
|
+
try {
|
|
201
|
+
// Save user message for all agents and workflow steps to use
|
|
202
|
+
(0, index_1.saveUserMessage)(reqMessage);
|
|
203
|
+
if (reqMessage.userMessage.includes('complex task')) {
|
|
204
|
+
// Use workflow for complex tasks
|
|
205
|
+
const workflowResult = await complexWorkflow.execute();
|
|
206
|
+
return workflowResult.success ? workflowResult.data.finalContent : 'Workflow failed';
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
// Use simple agent for regular tasks
|
|
210
|
+
const result = await workflowAgent.run();
|
|
211
|
+
return result.success ? result.message : 'Agent failed';
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
console.error('Error:', error);
|
|
216
|
+
return 'Error processing request';
|
|
217
|
+
}
|
|
218
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Example demonstrating CodeBolt backend storage for ComposableAgent
|
|
3
|
+
* @description Shows how to use CodeBolt's state and memory functions instead of SQLite
|
|
4
|
+
*/
|
|
5
|
+
import { ComposableAgent } from '../index';
|
|
6
|
+
/**
|
|
7
|
+
* Example: Weather Agent with CodeBolt Agent State Storage
|
|
8
|
+
* Data is stored in CodeBolt's agent state backend
|
|
9
|
+
*/
|
|
10
|
+
export declare const weatherAgentWithAgentStorage: ComposableAgent;
|
|
11
|
+
/**
|
|
12
|
+
* Example: Task Management Agent with CodeBolt Project State Storage
|
|
13
|
+
* Data is stored in CodeBolt's project state backend
|
|
14
|
+
*/
|
|
15
|
+
export declare const taskAgentWithProjectStorage: ComposableAgent;
|
|
16
|
+
/**
|
|
17
|
+
* Example: Knowledge Agent with CodeBolt Memory Database Storage
|
|
18
|
+
* Data is stored in CodeBolt's in-memory database backend
|
|
19
|
+
*/
|
|
20
|
+
export declare const knowledgeAgentWithDbStorage: ComposableAgent;
|
|
21
|
+
/**
|
|
22
|
+
* Example usage within CodeBolt onMessage
|
|
23
|
+
*/
|
|
24
|
+
export declare function setupCodeBoltStorageExample(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Example: Custom storage configuration
|
|
27
|
+
*/
|
|
28
|
+
export declare function createCustomStorageAgent(): ComposableAgent;
|
|
29
|
+
/**
|
|
30
|
+
* Example: Multiple agents with different storage backends
|
|
31
|
+
*/
|
|
32
|
+
export declare function setupMultiStorageAgents(): {
|
|
33
|
+
sessionAgent: ComposableAgent;
|
|
34
|
+
globalAgent: ComposableAgent;
|
|
35
|
+
cacheAgent: ComposableAgent;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Storage comparison and migration helper
|
|
39
|
+
*/
|
|
40
|
+
export declare function storageComparison(): Promise<void>;
|