@codebolt/agent 2.2.2 → 2.2.5
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/builderpattern/agent.js +2 -2
- package/dist/builderpattern/followupquestionbuilder.js +1 -1
- package/dist/builderpattern/llmoutputhandler.js +7 -7
- package/dist/builderpattern/usermessage.d.ts +6 -1
- package/dist/composablepattern/document.js +2 -35
- package/dist/local-tools/fileTools.d.ts +26 -0
- package/dist/local-tools/fileTools.js +162 -0
- package/dist/processor/types/interfaces.d.ts +44 -21
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +13 -0
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +68 -0
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +15 -0
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +212 -0
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +19 -0
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +110 -0
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +23 -0
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +173 -0
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +14 -0
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +93 -0
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +30 -0
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +330 -0
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +26 -0
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +269 -0
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +38 -0
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +217 -0
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +34 -0
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +147 -0
- package/dist/processor-pieces/additionalModifiers/index.d.ts +12 -0
- package/dist/processor-pieces/additionalModifiers/index.js +28 -0
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +29 -0
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +155 -0
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +15 -0
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +129 -0
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +25 -0
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +169 -0
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +20 -0
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +152 -0
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +7 -0
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +93 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +14 -5
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +41 -40
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +9 -0
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +77 -0
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +5 -5
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +5 -13
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +50 -58
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +6 -8
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +66 -22
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +19 -0
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +110 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +20 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +124 -0
- package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +41 -0
- package/dist/processor-pieces/messageModifiers/environmentContext.js +355 -0
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +3 -2
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +1 -2
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +3 -2
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +1 -2
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +23 -0
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +207 -0
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +7 -0
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +26 -0
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +18 -2
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +291 -93
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +1 -0
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +2 -0
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +7 -0
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +24 -0
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +41 -0
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +197 -0
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +26 -0
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +90 -0
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +81 -0
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +329 -0
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +40 -0
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +272 -0
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +49 -0
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +291 -0
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +49 -0
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +293 -0
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +47 -0
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +249 -0
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +30 -0
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +137 -0
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +30 -0
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +228 -0
- package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +99 -0
- package/dist/processor-pieces/postToolCall/telemetryProcessor.js +278 -0
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +37 -0
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +178 -0
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +43 -0
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +207 -0
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +52 -0
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +264 -0
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +49 -0
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +293 -0
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +7 -0
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +31 -0
- package/dist/processor-pieces/preToolCall/index.d.ts +9 -0
- package/dist/processor-pieces/preToolCall/index.js +18 -0
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +58 -0
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +444 -0
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +44 -0
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +367 -0
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +58 -0
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +391 -0
- package/dist/unified/agent/agent.js +2 -2
- package/dist/unified/agent/tool.d.ts +99 -0
- package/dist/unified/agent/tool.js +440 -0
- package/dist/unified/base/initialPromptGenerator.js +5 -5
- package/dist/unified/base/responseExecutor.js +6 -6
- package/dist/unified/examples/agentExample.d.ts +46 -0
- package/dist/unified/examples/agentExample.js +464 -0
- package/dist/unified/examples/documentationPatternExample.d.ts +10 -0
- package/dist/unified/examples/documentationPatternExample.js +385 -0
- package/dist/unified/examples/followUpProcessorsExample.d.ts +45 -0
- package/dist/unified/examples/followUpProcessorsExample.js +311 -0
- package/dist/unified/examples/orchestratorExample.d.ts +16 -0
- package/dist/unified/examples/orchestratorExample.js +415 -0
- package/dist/unified/examples/preToolCallProcessorsExample.d.ts +36 -0
- package/dist/unified/examples/preToolCallProcessorsExample.js +458 -0
- package/dist/unified/examples/workflowExample.d.ts +12 -0
- package/dist/unified/examples/workflowExample.js +497 -0
- package/dist/unified/orchestrator/orchestrator.d.ts +260 -0
- package/dist/unified/orchestrator/orchestrator.js +519 -0
- package/package.json +5 -5
- package/dist/agent.d.ts +0 -86
- package/dist/agent.js +0 -324
- 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/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
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatCompressionModifier = void 0;
|
|
4
|
+
const base_1 = require("../base");
|
|
5
|
+
class ChatCompressionModifier extends base_1.BaseMessageModifier {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
super();
|
|
8
|
+
this.hasFailedCompressionAttempt = false;
|
|
9
|
+
this.options = {
|
|
10
|
+
tokenThreshold: options.tokenThreshold || 8000, // Approximate token threshold
|
|
11
|
+
compressionRatio: options.compressionRatio || 0.5, // Compress to 50% of original
|
|
12
|
+
preserveRecentMessages: options.preserveRecentMessages || 5,
|
|
13
|
+
enableCompression: options.enableCompression !== false
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
async modify(originalRequest, createdMessage) {
|
|
17
|
+
try {
|
|
18
|
+
if (!this.options.enableCompression || this.hasFailedCompressionAttempt) {
|
|
19
|
+
return createdMessage;
|
|
20
|
+
}
|
|
21
|
+
const messages = createdMessage.message.messages;
|
|
22
|
+
// Skip compression if we don't have enough messages
|
|
23
|
+
if (messages.length <= this.options.preserveRecentMessages) {
|
|
24
|
+
return createdMessage;
|
|
25
|
+
}
|
|
26
|
+
const shouldCompress = await this.shouldCompressChat(messages);
|
|
27
|
+
if (!shouldCompress) {
|
|
28
|
+
return createdMessage;
|
|
29
|
+
}
|
|
30
|
+
const compressedMessages = await this.compressMessages(messages);
|
|
31
|
+
return Promise.resolve({
|
|
32
|
+
message: {
|
|
33
|
+
...createdMessage.message,
|
|
34
|
+
messages: compressedMessages
|
|
35
|
+
},
|
|
36
|
+
metadata: {
|
|
37
|
+
...createdMessage.metadata,
|
|
38
|
+
chatCompressed: true,
|
|
39
|
+
originalMessageCount: messages.length,
|
|
40
|
+
compressedMessageCount: compressedMessages.length
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error('Error in ChatCompressionModifier:', error);
|
|
46
|
+
this.hasFailedCompressionAttempt = true;
|
|
47
|
+
return createdMessage;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async shouldCompressChat(messages) {
|
|
51
|
+
// Estimate token count (rough approximation: 4 characters per token)
|
|
52
|
+
const totalCharacters = messages.reduce((sum, msg) => {
|
|
53
|
+
return sum + (typeof msg.content === 'string' ? msg.content.length : JSON.stringify(msg.content).length);
|
|
54
|
+
}, 0);
|
|
55
|
+
const estimatedTokens = totalCharacters / 4;
|
|
56
|
+
return estimatedTokens > this.options.tokenThreshold;
|
|
57
|
+
}
|
|
58
|
+
async compressMessages(messages) {
|
|
59
|
+
const preserveCount = this.options.preserveRecentMessages;
|
|
60
|
+
const recentMessages = messages.slice(-preserveCount);
|
|
61
|
+
const messagesToCompress = messages.slice(0, -preserveCount);
|
|
62
|
+
if (messagesToCompress.length === 0) {
|
|
63
|
+
return messages;
|
|
64
|
+
}
|
|
65
|
+
// Create a summary of the messages to compress
|
|
66
|
+
const conversationSummary = this.createConversationSummary(messagesToCompress);
|
|
67
|
+
const compressionMessage = {
|
|
68
|
+
role: 'system',
|
|
69
|
+
content: `[Conversation Summary - Previous ${messagesToCompress.length} messages compressed]
|
|
70
|
+
|
|
71
|
+
${conversationSummary}
|
|
72
|
+
|
|
73
|
+
[End of Summary - Continuing with recent conversation...]`
|
|
74
|
+
};
|
|
75
|
+
return [compressionMessage, ...recentMessages];
|
|
76
|
+
}
|
|
77
|
+
createConversationSummary(messages) {
|
|
78
|
+
const summaryParts = [];
|
|
79
|
+
let currentTopic = '';
|
|
80
|
+
let userQuestions = [];
|
|
81
|
+
let assistantResponses = [];
|
|
82
|
+
for (const message of messages) {
|
|
83
|
+
const content = typeof message.content === 'string' ? message.content : JSON.stringify(message.content);
|
|
84
|
+
if (message.role === 'user') {
|
|
85
|
+
// Extract key questions or requests
|
|
86
|
+
if (content.length > 20) { // Only include substantial messages
|
|
87
|
+
userQuestions.push(content.substring(0, 100) + (content.length > 100 ? '...' : ''));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (message.role === 'assistant') {
|
|
91
|
+
// Extract key responses or actions
|
|
92
|
+
if (content.length > 20) {
|
|
93
|
+
assistantResponses.push(content.substring(0, 100) + (content.length > 100 ? '...' : ''));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (userQuestions.length > 0) {
|
|
98
|
+
summaryParts.push(`Key user requests: ${userQuestions.slice(0, 3).join('; ')}`);
|
|
99
|
+
}
|
|
100
|
+
if (assistantResponses.length > 0) {
|
|
101
|
+
summaryParts.push(`Key assistant actions: ${assistantResponses.slice(0, 3).join('; ')}`);
|
|
102
|
+
}
|
|
103
|
+
summaryParts.push(`Total messages compressed: ${messages.length}`);
|
|
104
|
+
return summaryParts.join('\n');
|
|
105
|
+
}
|
|
106
|
+
resetCompressionState() {
|
|
107
|
+
this.hasFailedCompressionAttempt = false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.ChatCompressionModifier = ChatCompressionModifier;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example usage of ChatHistoryMessageModifier
|
|
3
|
+
*
|
|
4
|
+
* This file demonstrates how to integrate chat history into your agent's message processing pipeline.
|
|
5
|
+
*/
|
|
6
|
+
import { InitialPromptGenerator } from '@codebolt/agent/unified';
|
|
7
|
+
import { FlatUserMessage } from '@codebolt/types/sdk';
|
|
8
|
+
export declare function createBasicChatHistoryAgent(): InitialPromptGenerator;
|
|
9
|
+
export declare function createCompactChatHistoryAgent(): InitialPromptGenerator;
|
|
10
|
+
export declare function createThreadAwareChatHistoryAgent(): InitialPromptGenerator;
|
|
11
|
+
export declare function processMessageWithHistory(userMessage: FlatUserMessage): Promise<import("@codebolt/types/agent").ProcessedMessage>;
|
|
12
|
+
export declare const chatHistoryOptions: {
|
|
13
|
+
enableChatHistory: boolean;
|
|
14
|
+
maxHistoryMessages: number;
|
|
15
|
+
includeSystemMessages: boolean;
|
|
16
|
+
historyContextLabel: string;
|
|
17
|
+
filterByThreadId: boolean;
|
|
18
|
+
includeTimestamps: boolean;
|
|
19
|
+
compactFormat: boolean;
|
|
20
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Example usage of ChatHistoryMessageModifier
|
|
4
|
+
*
|
|
5
|
+
* This file demonstrates how to integrate chat history into your agent's message processing pipeline.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.chatHistoryOptions = void 0;
|
|
9
|
+
exports.createBasicChatHistoryAgent = createBasicChatHistoryAgent;
|
|
10
|
+
exports.createCompactChatHistoryAgent = createCompactChatHistoryAgent;
|
|
11
|
+
exports.createThreadAwareChatHistoryAgent = createThreadAwareChatHistoryAgent;
|
|
12
|
+
exports.processMessageWithHistory = processMessageWithHistory;
|
|
13
|
+
const chatHistoryMessageModifier_1 = require("./chatHistoryMessageModifier");
|
|
14
|
+
const unified_1 = require("@codebolt/agent/unified");
|
|
15
|
+
// Example 1: Basic chat history integration
|
|
16
|
+
function createBasicChatHistoryAgent() {
|
|
17
|
+
return new unified_1.InitialPromptGenerator({
|
|
18
|
+
processors: [
|
|
19
|
+
// Add chat history before other processors
|
|
20
|
+
new chatHistoryMessageModifier_1.ChatHistoryMessageModifier({
|
|
21
|
+
enableChatHistory: true,
|
|
22
|
+
maxHistoryMessages: 5,
|
|
23
|
+
includeTimestamps: true,
|
|
24
|
+
compactFormat: false
|
|
25
|
+
}),
|
|
26
|
+
// ... other processors like system prompts, tools, etc.
|
|
27
|
+
],
|
|
28
|
+
baseSystemPrompt: "You are a helpful assistant."
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
// Example 2: Compact chat history for token efficiency
|
|
32
|
+
function createCompactChatHistoryAgent() {
|
|
33
|
+
return new unified_1.InitialPromptGenerator({
|
|
34
|
+
processors: [
|
|
35
|
+
new chatHistoryMessageModifier_1.ChatHistoryMessageModifier({
|
|
36
|
+
enableChatHistory: true,
|
|
37
|
+
maxHistoryMessages: 10,
|
|
38
|
+
includeTimestamps: false,
|
|
39
|
+
compactFormat: true,
|
|
40
|
+
includeSystemMessages: false,
|
|
41
|
+
historyContextLabel: "Previous Conversation"
|
|
42
|
+
}),
|
|
43
|
+
],
|
|
44
|
+
baseSystemPrompt: "You are a helpful assistant."
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// Example 3: Thread-specific chat history (when API supports it)
|
|
48
|
+
function createThreadAwareChatHistoryAgent() {
|
|
49
|
+
return new unified_1.InitialPromptGenerator({
|
|
50
|
+
processors: [
|
|
51
|
+
new chatHistoryMessageModifier_1.ChatHistoryMessageModifier({
|
|
52
|
+
enableChatHistory: true,
|
|
53
|
+
maxHistoryMessages: 8,
|
|
54
|
+
filterByThreadId: true, // Filter by thread ID when supported
|
|
55
|
+
includeTimestamps: true,
|
|
56
|
+
compactFormat: false,
|
|
57
|
+
historyContextLabel: "Thread History"
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
60
|
+
baseSystemPrompt: "You are a helpful assistant."
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// Example 4: Usage in a real agent scenario
|
|
64
|
+
async function processMessageWithHistory(userMessage) {
|
|
65
|
+
const promptGenerator = new unified_1.InitialPromptGenerator({
|
|
66
|
+
processors: [
|
|
67
|
+
// Chat history comes first to provide context
|
|
68
|
+
new chatHistoryMessageModifier_1.ChatHistoryMessageModifier({
|
|
69
|
+
enableChatHistory: true,
|
|
70
|
+
maxHistoryMessages: 5,
|
|
71
|
+
includeTimestamps: false,
|
|
72
|
+
compactFormat: true
|
|
73
|
+
}),
|
|
74
|
+
// Add other processors after history
|
|
75
|
+
// new EnvironmentContextModifier(),
|
|
76
|
+
// new CoreSystemPromptModifier({ systemPrompt: "..." }),
|
|
77
|
+
// new ToolInjectionModifier(),
|
|
78
|
+
],
|
|
79
|
+
baseSystemPrompt: "You are a helpful AI assistant."
|
|
80
|
+
});
|
|
81
|
+
try {
|
|
82
|
+
const processedMessage = await promptGenerator.processMessage(userMessage);
|
|
83
|
+
console.log('Message processed with chat history context');
|
|
84
|
+
return processedMessage;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
console.error('Error processing message with history:', error);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Example 5: Configuration options explained
|
|
92
|
+
exports.chatHistoryOptions = {
|
|
93
|
+
// Enable/disable chat history entirely
|
|
94
|
+
enableChatHistory: true,
|
|
95
|
+
// Maximum number of previous messages to include
|
|
96
|
+
maxHistoryMessages: 10,
|
|
97
|
+
// Include system messages in history
|
|
98
|
+
includeSystemMessages: false,
|
|
99
|
+
// Custom label for the history section
|
|
100
|
+
historyContextLabel: "Previous Conversation",
|
|
101
|
+
// Filter by thread ID (when API supports it)
|
|
102
|
+
filterByThreadId: true,
|
|
103
|
+
// Include timestamps with messages
|
|
104
|
+
includeTimestamps: true,
|
|
105
|
+
// Use compact format to save tokens
|
|
106
|
+
compactFormat: false
|
|
107
|
+
};
|
|
108
|
+
// Example output format:
|
|
109
|
+
/*
|
|
110
|
+
=== Chat History ===
|
|
111
|
+
Thread ID: 6536c82f-c7d1-4dbd-8e68-c90f7ef5ebc3
|
|
112
|
+
Recent 3 messages:
|
|
113
|
+
|
|
114
|
+
**User (2025-01-15 10:30:15):**
|
|
115
|
+
Can you help me with my React component?
|
|
116
|
+
|
|
117
|
+
**Assistant (2025-01-15 10:30:45):**
|
|
118
|
+
Of course! I'd be happy to help you with your React component. Could you please share the code or describe what specific issue you're facing?
|
|
119
|
+
|
|
120
|
+
**User (2025-01-15 10:31:20):**
|
|
121
|
+
I'm having trouble with state management in my component.
|
|
122
|
+
|
|
123
|
+
=== End Chat History ===
|
|
124
|
+
*/
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export interface Part {
|
|
7
|
+
text: string;
|
|
8
|
+
}
|
|
9
|
+
export interface EnvironmentContextOptions {
|
|
10
|
+
workspaceDirectories: string[];
|
|
11
|
+
includeFullContext?: boolean;
|
|
12
|
+
maxItems?: number;
|
|
13
|
+
ignoredFolders?: Set<string>;
|
|
14
|
+
fileIncludePattern?: RegExp;
|
|
15
|
+
respectGitIgnore?: boolean;
|
|
16
|
+
respectGeminiIgnore?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface FolderStructureOptions {
|
|
19
|
+
maxItems?: number;
|
|
20
|
+
ignoredFolders?: Set<string>;
|
|
21
|
+
fileIncludePattern?: RegExp;
|
|
22
|
+
respectGitIgnore?: boolean;
|
|
23
|
+
respectGeminiIgnore?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Standalone version of getFolderStructure
|
|
27
|
+
*/
|
|
28
|
+
export declare function getFolderStructure(targetPath: string, options?: FolderStructureOptions): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Standalone version of getDirectoryContextString
|
|
31
|
+
*/
|
|
32
|
+
export declare function getDirectoryContextString(workspaceDirectories: string[], options?: FolderStructureOptions): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Standalone version of getEnvironmentContext
|
|
35
|
+
*/
|
|
36
|
+
export declare function getEnvironmentContext(options: EnvironmentContextOptions): Promise<Part[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Utility function to read multiple files (basic implementation for full context)
|
|
39
|
+
* This is a simplified version - extend as needed for your use case
|
|
40
|
+
*/
|
|
41
|
+
export declare function readMultipleFiles(basePath: string, patterns?: string[], options?: FolderStructureOptions): Promise<string>;
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2025 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.getFolderStructure = getFolderStructure;
|
|
42
|
+
exports.getDirectoryContextString = getDirectoryContextString;
|
|
43
|
+
exports.getEnvironmentContext = getEnvironmentContext;
|
|
44
|
+
exports.readMultipleFiles = readMultipleFiles;
|
|
45
|
+
const fs = __importStar(require("fs/promises"));
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
const MAX_ITEMS = 200;
|
|
48
|
+
const DEFAULT_IGNORED_FOLDERS = new Set(['node_modules', '.git', 'dist']);
|
|
49
|
+
/**
|
|
50
|
+
* Simple gitignore pattern matcher (basic implementation)
|
|
51
|
+
* For production use, consider using a dedicated gitignore library
|
|
52
|
+
*/
|
|
53
|
+
function shouldIgnoreFile(filePath, options) {
|
|
54
|
+
if (!options.respectGitIgnore && !options.respectGeminiIgnore) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
// Basic ignore patterns - in production, you'd want to read actual .gitignore/.geminiignore files
|
|
58
|
+
const commonIgnorePatterns = [
|
|
59
|
+
/node_modules/,
|
|
60
|
+
/\.git/,
|
|
61
|
+
/dist/,
|
|
62
|
+
/build/,
|
|
63
|
+
/\.DS_Store/,
|
|
64
|
+
/\.env/,
|
|
65
|
+
/\.log$/,
|
|
66
|
+
/\.tmp$/,
|
|
67
|
+
/\.cache/
|
|
68
|
+
];
|
|
69
|
+
return commonIgnorePatterns.some(pattern => pattern.test(filePath));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Reads the full folder structure recursively
|
|
73
|
+
*/
|
|
74
|
+
async function readFullStructure(rootPath, options) {
|
|
75
|
+
const rootName = path.basename(rootPath);
|
|
76
|
+
const rootNode = {
|
|
77
|
+
name: rootName,
|
|
78
|
+
path: rootPath,
|
|
79
|
+
files: [],
|
|
80
|
+
subFolders: [],
|
|
81
|
+
totalChildren: 0,
|
|
82
|
+
totalFiles: 0,
|
|
83
|
+
};
|
|
84
|
+
const queue = [
|
|
85
|
+
{ folderInfo: rootNode, currentPath: rootPath },
|
|
86
|
+
];
|
|
87
|
+
let currentItemCount = 0;
|
|
88
|
+
const processedPaths = new Set();
|
|
89
|
+
while (queue.length > 0) {
|
|
90
|
+
const { folderInfo, currentPath } = queue.shift();
|
|
91
|
+
if (processedPaths.has(currentPath)) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
processedPaths.add(currentPath);
|
|
95
|
+
if (currentItemCount >= options.maxItems) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
let entries;
|
|
99
|
+
try {
|
|
100
|
+
const rawEntries = await fs.readdir(currentPath, { withFileTypes: true });
|
|
101
|
+
entries = rawEntries.sort((a, b) => a.name.localeCompare(b.name));
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (error.code === 'EACCES' || error.code === 'ENOENT') {
|
|
105
|
+
console.warn(`Warning: Could not read directory ${currentPath}: ${error.message}`);
|
|
106
|
+
if (currentPath === rootPath && error.code === 'ENOENT') {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
const filesInCurrentDir = [];
|
|
114
|
+
const subFoldersInCurrentDir = [];
|
|
115
|
+
// Process files first
|
|
116
|
+
for (const entry of entries) {
|
|
117
|
+
if (entry.isFile()) {
|
|
118
|
+
if (currentItemCount >= options.maxItems) {
|
|
119
|
+
folderInfo.hasMoreFiles = true;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
const fileName = entry.name;
|
|
123
|
+
const filePath = path.join(currentPath, fileName);
|
|
124
|
+
if (shouldIgnoreFile(filePath, options)) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (!options.fileIncludePattern || options.fileIncludePattern.test(fileName)) {
|
|
128
|
+
filesInCurrentDir.push(fileName);
|
|
129
|
+
currentItemCount++;
|
|
130
|
+
folderInfo.totalFiles++;
|
|
131
|
+
folderInfo.totalChildren++;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
folderInfo.files = filesInCurrentDir;
|
|
136
|
+
// Process directories
|
|
137
|
+
for (const entry of entries) {
|
|
138
|
+
if (entry.isDirectory()) {
|
|
139
|
+
if (currentItemCount >= options.maxItems) {
|
|
140
|
+
folderInfo.hasMoreSubfolders = true;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
const subFolderName = entry.name;
|
|
144
|
+
const subFolderPath = path.join(currentPath, subFolderName);
|
|
145
|
+
if (options.ignoredFolders.has(subFolderName) || shouldIgnoreFile(subFolderPath, options)) {
|
|
146
|
+
const ignoredSubFolder = {
|
|
147
|
+
name: subFolderName,
|
|
148
|
+
path: subFolderPath,
|
|
149
|
+
files: [],
|
|
150
|
+
subFolders: [],
|
|
151
|
+
totalChildren: 0,
|
|
152
|
+
totalFiles: 0,
|
|
153
|
+
isIgnored: true,
|
|
154
|
+
};
|
|
155
|
+
subFoldersInCurrentDir.push(ignoredSubFolder);
|
|
156
|
+
currentItemCount++;
|
|
157
|
+
folderInfo.totalChildren++;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const subFolderNode = {
|
|
161
|
+
name: subFolderName,
|
|
162
|
+
path: subFolderPath,
|
|
163
|
+
files: [],
|
|
164
|
+
subFolders: [],
|
|
165
|
+
totalChildren: 0,
|
|
166
|
+
totalFiles: 0,
|
|
167
|
+
};
|
|
168
|
+
subFoldersInCurrentDir.push(subFolderNode);
|
|
169
|
+
currentItemCount++;
|
|
170
|
+
folderInfo.totalChildren++;
|
|
171
|
+
queue.push({ folderInfo: subFolderNode, currentPath: subFolderPath });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
folderInfo.subFolders = subFoldersInCurrentDir;
|
|
175
|
+
}
|
|
176
|
+
return rootNode;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Formats a folder structure into a readable string representation
|
|
180
|
+
*/
|
|
181
|
+
function formatFolderStructure(folderInfo, prefix = '', isLast = true) {
|
|
182
|
+
const connector = isLast ? '└── ' : '├── ';
|
|
183
|
+
const extension = isLast ? ' ' : '│ ';
|
|
184
|
+
let result = `${prefix}${connector}${folderInfo.name}`;
|
|
185
|
+
if (folderInfo.isIgnored) {
|
|
186
|
+
result += ' (ignored)';
|
|
187
|
+
}
|
|
188
|
+
result += '\n';
|
|
189
|
+
// Add files
|
|
190
|
+
const allFiles = [...folderInfo.files];
|
|
191
|
+
if (folderInfo.hasMoreFiles) {
|
|
192
|
+
allFiles.push('...');
|
|
193
|
+
}
|
|
194
|
+
allFiles.forEach((file, index) => {
|
|
195
|
+
const isLastFile = index === allFiles.length - 1 && folderInfo.subFolders.length === 0;
|
|
196
|
+
const fileConnector = isLastFile ? '└── ' : '├── ';
|
|
197
|
+
result += `${prefix}${extension}${fileConnector}${file}\n`;
|
|
198
|
+
});
|
|
199
|
+
// Add subfolders
|
|
200
|
+
folderInfo.subFolders.forEach((subFolder, index) => {
|
|
201
|
+
const isLastSubFolder = index === folderInfo.subFolders.length - 1;
|
|
202
|
+
result += formatFolderStructure(subFolder, prefix + extension, isLastSubFolder);
|
|
203
|
+
});
|
|
204
|
+
if (folderInfo.hasMoreSubfolders) {
|
|
205
|
+
const moreConnector = '└── ';
|
|
206
|
+
result += `${prefix}${extension}${moreConnector}...\n`;
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Standalone version of getFolderStructure
|
|
212
|
+
*/
|
|
213
|
+
async function getFolderStructure(targetPath, options = {}) {
|
|
214
|
+
var _a, _b, _c, _d, _e;
|
|
215
|
+
const mergedOptions = {
|
|
216
|
+
maxItems: (_a = options.maxItems) !== null && _a !== void 0 ? _a : MAX_ITEMS,
|
|
217
|
+
ignoredFolders: (_b = options.ignoredFolders) !== null && _b !== void 0 ? _b : DEFAULT_IGNORED_FOLDERS,
|
|
218
|
+
fileIncludePattern: (_c = options.fileIncludePattern) !== null && _c !== void 0 ? _c : /.*/,
|
|
219
|
+
respectGitIgnore: (_d = options.respectGitIgnore) !== null && _d !== void 0 ? _d : true,
|
|
220
|
+
respectGeminiIgnore: (_e = options.respectGeminiIgnore) !== null && _e !== void 0 ? _e : true,
|
|
221
|
+
};
|
|
222
|
+
try {
|
|
223
|
+
const folderInfo = await readFullStructure(targetPath, mergedOptions);
|
|
224
|
+
if (!folderInfo) {
|
|
225
|
+
return `Error: Directory not found or inaccessible: ${targetPath}`;
|
|
226
|
+
}
|
|
227
|
+
return formatFolderStructure(folderInfo).trim();
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
return `Error reading folder structure: ${error.message}`;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Standalone version of getDirectoryContextString
|
|
235
|
+
*/
|
|
236
|
+
async function getDirectoryContextString(workspaceDirectories, options = {}) {
|
|
237
|
+
const folderStructures = await Promise.all(workspaceDirectories.map((dir) => getFolderStructure(dir, options)));
|
|
238
|
+
const folderStructure = folderStructures.join('\n');
|
|
239
|
+
let workingDirPreamble;
|
|
240
|
+
if (workspaceDirectories.length === 1) {
|
|
241
|
+
workingDirPreamble = `I'm currently working in the directory: ${workspaceDirectories[0]}`;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
const dirList = workspaceDirectories.map((dir) => ` - ${dir}`).join('\n');
|
|
245
|
+
workingDirPreamble = `I'm currently working in the following directories:\n${dirList}`;
|
|
246
|
+
}
|
|
247
|
+
return `${workingDirPreamble}
|
|
248
|
+
Here is the folder structure of the current working directories:
|
|
249
|
+
|
|
250
|
+
${folderStructure}`;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Standalone version of getEnvironmentContext
|
|
254
|
+
*/
|
|
255
|
+
async function getEnvironmentContext(options) {
|
|
256
|
+
const today = new Date().toLocaleDateString(undefined, {
|
|
257
|
+
weekday: 'long',
|
|
258
|
+
year: 'numeric',
|
|
259
|
+
month: 'long',
|
|
260
|
+
day: 'numeric',
|
|
261
|
+
});
|
|
262
|
+
const platform = process.platform;
|
|
263
|
+
const directoryContext = await getDirectoryContextString(options.workspaceDirectories, {
|
|
264
|
+
maxItems: options.maxItems,
|
|
265
|
+
ignoredFolders: options.ignoredFolders,
|
|
266
|
+
fileIncludePattern: options.fileIncludePattern,
|
|
267
|
+
respectGitIgnore: options.respectGitIgnore,
|
|
268
|
+
respectGeminiIgnore: options.respectGeminiIgnore,
|
|
269
|
+
});
|
|
270
|
+
const context = `
|
|
271
|
+
This is the Gemini CLI. We are setting up the context for our chat.
|
|
272
|
+
Today's date is ${today}.
|
|
273
|
+
My operating system is: ${platform}
|
|
274
|
+
${directoryContext}
|
|
275
|
+
`.trim();
|
|
276
|
+
const initialParts = [{ text: context }];
|
|
277
|
+
// Add full file context if requested
|
|
278
|
+
if (options.includeFullContext) {
|
|
279
|
+
try {
|
|
280
|
+
// This is a simplified version - in the original, this would use read_many_files tool
|
|
281
|
+
// For standalone use, you might want to implement your own file reading logic
|
|
282
|
+
const fullContextNote = `
|
|
283
|
+
--- Full File Context (Standalone Version) ---
|
|
284
|
+
Note: Full file context reading would require implementing file reading logic
|
|
285
|
+
based on your specific needs. The original implementation uses the read_many_files tool
|
|
286
|
+
from the Gemini CLI tool registry.
|
|
287
|
+
`;
|
|
288
|
+
initialParts.push({ text: fullContextNote });
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
console.error('Error reading full file context:', error);
|
|
292
|
+
initialParts.push({
|
|
293
|
+
text: '\n--- Error reading full file context ---',
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return initialParts;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Utility function to read multiple files (basic implementation for full context)
|
|
301
|
+
* This is a simplified version - extend as needed for your use case
|
|
302
|
+
*/
|
|
303
|
+
async function readMultipleFiles(basePath, patterns = ['**/*'], options = {}) {
|
|
304
|
+
// This is a basic implementation - for production use, consider using a glob library
|
|
305
|
+
// like 'glob' or 'fast-glob' for pattern matching
|
|
306
|
+
try {
|
|
307
|
+
const files = [];
|
|
308
|
+
async function collectFiles(dirPath, currentDepth = 0) {
|
|
309
|
+
var _a;
|
|
310
|
+
if (currentDepth > 10)
|
|
311
|
+
return; // Prevent infinite recursion
|
|
312
|
+
try {
|
|
313
|
+
const entries = await fs.readdir(dirPath, { withFileTypes: true });
|
|
314
|
+
for (const entry of entries) {
|
|
315
|
+
const fullPath = path.join(dirPath, entry.name);
|
|
316
|
+
if (shouldIgnoreFile(fullPath, options)) {
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (entry.isFile()) {
|
|
320
|
+
files.push(fullPath);
|
|
321
|
+
}
|
|
322
|
+
else if (entry.isDirectory() && !((_a = options.ignoredFolders) === null || _a === void 0 ? void 0 : _a.has(entry.name))) {
|
|
323
|
+
await collectFiles(fullPath, currentDepth + 1);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
// Skip directories we can't read
|
|
329
|
+
console.warn(`Warning: Could not read directory ${dirPath}: ${error.message}`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
await collectFiles(basePath);
|
|
333
|
+
// Read file contents (limit to reasonable size)
|
|
334
|
+
const fileContents = [];
|
|
335
|
+
for (const filePath of files.slice(0, 100)) { // Limit to first 100 files
|
|
336
|
+
try {
|
|
337
|
+
const stats = await fs.stat(filePath);
|
|
338
|
+
if (stats.size > 100 * 1024) { // Skip files larger than 100KB
|
|
339
|
+
fileContents.push(`${filePath}: [File too large, skipped]`);
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
343
|
+
const relativePath = path.relative(basePath, filePath);
|
|
344
|
+
fileContents.push(`--- ${relativePath} ---\n${content}\n`);
|
|
345
|
+
}
|
|
346
|
+
catch (error) {
|
|
347
|
+
fileContents.push(`${filePath}: [Error reading file: ${error.message}]`);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return fileContents.join('\n');
|
|
351
|
+
}
|
|
352
|
+
catch (error) {
|
|
353
|
+
return `Error reading multiple files: ${error.message}`;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FlatUserMessage } from '@codebolt/types/sdk';
|
|
2
|
+
import { BaseMessageModifier, ProcessedMessage } from '../../processor';
|
|
2
3
|
export interface HandleUrlMessageModifierOptions {
|
|
3
4
|
googleSearchEnabled?: boolean;
|
|
4
5
|
fetchUrlContent?: boolean;
|
|
@@ -7,6 +8,6 @@ export declare class HandleUrlMessageModifier extends BaseMessageModifier {
|
|
|
7
8
|
private readonly googleSearchEnabled;
|
|
8
9
|
private readonly fetchUrlContent;
|
|
9
10
|
constructor(options?: HandleUrlMessageModifierOptions);
|
|
10
|
-
modify(
|
|
11
|
+
modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
11
12
|
private extractUrls;
|
|
12
13
|
}
|
|
@@ -8,9 +8,8 @@ class HandleUrlMessageModifier extends processor_1.BaseMessageModifier {
|
|
|
8
8
|
this.googleSearchEnabled = options.googleSearchEnabled || false;
|
|
9
9
|
this.fetchUrlContent = options.fetchUrlContent || false;
|
|
10
10
|
}
|
|
11
|
-
async modify(
|
|
11
|
+
async modify(originalRequest, createdMessage) {
|
|
12
12
|
try {
|
|
13
|
-
const { originalRequest, createdMessage, context } = input;
|
|
14
13
|
// Check if the request contains URLs
|
|
15
14
|
const urls = this.extractUrls(originalRequest);
|
|
16
15
|
if (urls.length > 0) {
|