@codebolt/agent 5.0.8 → 5.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/unified/base/responseExecutor.js +10 -6
- package/package.json +5 -5
- package/dist/agent.d.ts +0 -86
- package/dist/agent.js +0 -324
- package/dist/builderpattern/agent.d.ts +0 -86
- package/dist/builderpattern/agent.js +0 -324
- package/dist/builderpattern/followupquestionbuilder.d.ts +0 -75
- package/dist/builderpattern/followupquestionbuilder.js +0 -197
- package/dist/builderpattern/index.d.ts +0 -14
- package/dist/builderpattern/index.js +0 -23
- package/dist/builderpattern/llmoutputhandler.d.ts +0 -102
- package/dist/builderpattern/llmoutputhandler.js +0 -452
- package/dist/builderpattern/promptbuilder.d.ts +0 -382
- package/dist/builderpattern/promptbuilder.js +0 -805
- package/dist/builderpattern/systemprompt.d.ts +0 -20
- package/dist/builderpattern/systemprompt.js +0 -48
- package/dist/builderpattern/taskInstruction.d.ts +0 -37
- package/dist/builderpattern/taskInstruction.js +0 -57
- package/dist/builderpattern/usermessage.d.ts +0 -70
- package/dist/builderpattern/usermessage.js +0 -123
- package/dist/composablepattern/agent.d.ts +0 -169
- package/dist/composablepattern/agent.js +0 -598
- package/dist/composablepattern/codebolt-storage.d.ts +0 -67
- package/dist/composablepattern/codebolt-storage.js +0 -320
- package/dist/composablepattern/document.d.ts +0 -149
- package/dist/composablepattern/document.js +0 -405
- package/dist/composablepattern/examples/codebolt-integration-example.d.ts +0 -12
- package/dist/composablepattern/examples/codebolt-integration-example.js +0 -218
- package/dist/composablepattern/examples/codebolt-storage-example.d.ts +0 -40
- package/dist/composablepattern/examples/codebolt-storage-example.js +0 -223
- package/dist/composablepattern/examples/custom-steps-example.d.ts +0 -20
- package/dist/composablepattern/examples/custom-steps-example.js +0 -455
- package/dist/composablepattern/examples/document-agent.d.ts +0 -17
- package/dist/composablepattern/examples/document-agent.js +0 -107
- package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +0 -8
- package/dist/composablepattern/examples/simple-codebolt-integration.js +0 -164
- package/dist/composablepattern/examples/weather-agent.d.ts +0 -18
- package/dist/composablepattern/examples/weather-agent.js +0 -86
- package/dist/composablepattern/examples/workflow-example.d.ts +0 -12
- package/dist/composablepattern/examples/workflow-example.js +0 -463
- package/dist/composablepattern/index.d.ts +0 -63
- package/dist/composablepattern/index.js +0 -115
- package/dist/composablepattern/memory.d.ts +0 -89
- package/dist/composablepattern/memory.js +0 -141
- package/dist/composablepattern/tool.d.ts +0 -84
- package/dist/composablepattern/tool.js +0 -260
- package/dist/composablepattern/types.d.ts +0 -194
- package/dist/composablepattern/types.js +0 -6
- package/dist/composablepattern/user-context.d.ts +0 -214
- package/dist/composablepattern/user-context.js +0 -275
- package/dist/composablepattern/workflow.d.ts +0 -388
- package/dist/composablepattern/workflow.js +0 -562
- package/dist/followupquestionbuilder.d.ts +0 -75
- package/dist/followupquestionbuilder.js +0 -197
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -23
- package/dist/llmoutputhandler.d.ts +0 -102
- package/dist/llmoutputhandler.js +0 -452
- package/dist/processor/agent/agentStep.d.ts +0 -49
- package/dist/processor/agent/agentStep.js +0 -241
- package/dist/processor/agent/toolExecutor.d.ts +0 -19
- package/dist/processor/agent/toolExecutor.js +0 -90
- package/dist/processor/index.d.ts +0 -7
- package/dist/processor/index.js +0 -36
- package/dist/processor/messageModifiers/baseMessageModifier.d.ts +0 -20
- package/dist/processor/messageModifiers/baseMessageModifier.js +0 -55
- package/dist/processor/processors/baseProcessor.d.ts +0 -14
- package/dist/processor/processors/baseProcessor.js +0 -29
- package/dist/processor/tools/baseTool.d.ts +0 -10
- package/dist/processor/tools/baseTool.js +0 -20
- package/dist/processor/tools/toolList.d.ts +0 -9
- package/dist/processor/tools/toolList.js +0 -22
- package/dist/processor/types/interfaces.d.ts +0 -94
- package/dist/processor/types/interfaces.js +0 -2
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +0 -22
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +0 -144
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +0 -15
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +0 -75
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +0 -11
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +0 -46
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +0 -12
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +0 -60
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +0 -18
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +0 -222
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +0 -22
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +0 -194
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +0 -41
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +0 -197
- package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +0 -26
- package/dist/processor-pieces/processors/chatCompressionProcessor.js +0 -90
- package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +0 -81
- package/dist/processor-pieces/processors/chatRecordingProcessor.js +0 -329
- package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +0 -40
- package/dist/processor-pieces/processors/contextManagementProcessor.js +0 -305
- package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +0 -30
- package/dist/processor-pieces/processors/loopDetectionProcessor.js +0 -137
- package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +0 -30
- package/dist/processor-pieces/processors/responseValidationProcessor.js +0 -228
- package/dist/processor-pieces/processors/telemetryProcessor.d.ts +0 -99
- package/dist/processor-pieces/processors/telemetryProcessor.js +0 -311
- package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +0 -37
- package/dist/processor-pieces/processors/tokenManagementProcessor.js +0 -178
- package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +0 -43
- package/dist/processor-pieces/processors/toolExecutionProcessor.js +0 -207
- package/dist/processor-pieces/tools/fileTools.d.ts +0 -26
- package/dist/processor-pieces/tools/fileTools.js +0 -162
- package/dist/promptbuilder.d.ts +0 -382
- package/dist/promptbuilder.js +0 -805
- package/dist/systemprompt.d.ts +0 -20
- package/dist/systemprompt.js +0 -48
- package/dist/taskInstruction.d.ts +0 -37
- package/dist/taskInstruction.js +0 -57
- package/dist/usermessage.d.ts +0 -70
- package/dist/usermessage.js +0 -123
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { BaseMessageModifier, MessageModifierInput, ProcessedMessage, ToolList } from '../../processor';
|
|
2
|
-
export interface AddToolsListMessageModifierOptions {
|
|
3
|
-
toolsList: ToolList;
|
|
4
|
-
addToolsLocation?: 'InsidePrompt' | 'Tool' | 'SystemMessage';
|
|
5
|
-
giveToolExamples?: boolean;
|
|
6
|
-
maxToolExamples?: number;
|
|
7
|
-
includeToolDescriptions?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare class AddToolsListMessageModifier extends BaseMessageModifier {
|
|
10
|
-
private readonly toolsList;
|
|
11
|
-
private readonly addToolsLocation;
|
|
12
|
-
private readonly giveToolExamples;
|
|
13
|
-
private readonly maxToolExamples;
|
|
14
|
-
private readonly includeToolDescriptions;
|
|
15
|
-
constructor(options: AddToolsListMessageModifierOptions);
|
|
16
|
-
modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
17
|
-
private addToolsInsidePrompt;
|
|
18
|
-
private addToolsAsSystemMessage;
|
|
19
|
-
private addToolsAsToolCalls;
|
|
20
|
-
private generateToolsInfo;
|
|
21
|
-
private generateToolExample;
|
|
22
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AddToolsListMessageModifier = void 0;
|
|
4
|
-
const processor_1 = require("../../processor");
|
|
5
|
-
class AddToolsListMessageModifier extends processor_1.BaseMessageModifier {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
super({ context: options });
|
|
8
|
-
this.toolsList = options.toolsList;
|
|
9
|
-
this.addToolsLocation = options.addToolsLocation || 'SystemMessage';
|
|
10
|
-
this.giveToolExamples = options.giveToolExamples || false;
|
|
11
|
-
this.maxToolExamples = options.maxToolExamples || 2;
|
|
12
|
-
this.includeToolDescriptions = options.includeToolDescriptions !== false; // default true
|
|
13
|
-
}
|
|
14
|
-
async modify(input) {
|
|
15
|
-
try {
|
|
16
|
-
const { originalRequest, createdMessage, context } = input;
|
|
17
|
-
const tools = this.toolsList.getAllTools();
|
|
18
|
-
if (tools.length === 0) {
|
|
19
|
-
return createdMessage;
|
|
20
|
-
}
|
|
21
|
-
switch (this.addToolsLocation) {
|
|
22
|
-
case 'InsidePrompt':
|
|
23
|
-
return this.addToolsInsidePrompt(createdMessage, tools);
|
|
24
|
-
case 'SystemMessage':
|
|
25
|
-
return this.addToolsAsSystemMessage(createdMessage, tools);
|
|
26
|
-
case 'Tool':
|
|
27
|
-
return this.addToolsAsToolCalls(createdMessage, tools);
|
|
28
|
-
default:
|
|
29
|
-
return createdMessage;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
console.error('Error in AddToolsListMessageModifier:', error);
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
addToolsInsidePrompt(createdMessage, tools) {
|
|
38
|
-
const toolsInfo = this.generateToolsInfo(tools);
|
|
39
|
-
// Modify the last user message to include tools information
|
|
40
|
-
const modifiedMessages = createdMessage.messages.map((message, index) => {
|
|
41
|
-
if (message.role === 'user' && index === createdMessage.messages.length - 1) {
|
|
42
|
-
return {
|
|
43
|
-
...message,
|
|
44
|
-
content: `${message.content}\n\n--- Available Tools ---\n${toolsInfo}`
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return message;
|
|
48
|
-
});
|
|
49
|
-
return {
|
|
50
|
-
messages: modifiedMessages,
|
|
51
|
-
metadata: {
|
|
52
|
-
...createdMessage.metadata,
|
|
53
|
-
toolsListAdded: true,
|
|
54
|
-
toolsLocation: 'InsidePrompt',
|
|
55
|
-
toolsCount: tools.length
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
addToolsAsSystemMessage(createdMessage, tools) {
|
|
60
|
-
const toolsInfo = this.generateToolsInfo(tools);
|
|
61
|
-
const toolsMessage = {
|
|
62
|
-
role: 'system',
|
|
63
|
-
content: `Available Tools:\n${toolsInfo}`,
|
|
64
|
-
name: 'tools-list'
|
|
65
|
-
};
|
|
66
|
-
return {
|
|
67
|
-
messages: [toolsMessage, ...createdMessage.messages],
|
|
68
|
-
metadata: {
|
|
69
|
-
...createdMessage.metadata,
|
|
70
|
-
toolsListAdded: true,
|
|
71
|
-
toolsLocation: 'SystemMessage',
|
|
72
|
-
toolsCount: tools.length
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
addToolsAsToolCalls(createdMessage, tools) {
|
|
77
|
-
// This would create a message that lists tools as available tool calls
|
|
78
|
-
const toolsMessage = {
|
|
79
|
-
role: 'assistant',
|
|
80
|
-
content: 'I have access to the following tools:',
|
|
81
|
-
tool_calls: tools.map((tool, index) => ({
|
|
82
|
-
id: `tool-info-${index}`,
|
|
83
|
-
function: {
|
|
84
|
-
name: tool.name,
|
|
85
|
-
arguments: tool.parameters || {}
|
|
86
|
-
}
|
|
87
|
-
}))
|
|
88
|
-
};
|
|
89
|
-
return {
|
|
90
|
-
messages: [...createdMessage.messages, toolsMessage],
|
|
91
|
-
metadata: {
|
|
92
|
-
...createdMessage.metadata,
|
|
93
|
-
toolsListAdded: true,
|
|
94
|
-
toolsLocation: 'Tool',
|
|
95
|
-
toolsCount: tools.length
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
generateToolsInfo(tools) {
|
|
100
|
-
const toolsInfo = [];
|
|
101
|
-
tools.forEach((tool, index) => {
|
|
102
|
-
let toolInfo = `${index + 1}. **${tool.name}**`;
|
|
103
|
-
if (this.includeToolDescriptions && tool.description) {
|
|
104
|
-
toolInfo += `\n Description: ${tool.description}`;
|
|
105
|
-
}
|
|
106
|
-
if (tool.parameters) {
|
|
107
|
-
const params = typeof tool.parameters === 'object'
|
|
108
|
-
? Object.keys(tool.parameters).join(', ')
|
|
109
|
-
: String(tool.parameters);
|
|
110
|
-
toolInfo += `\n Parameters: ${params}`;
|
|
111
|
-
}
|
|
112
|
-
if (this.giveToolExamples && index < this.maxToolExamples) {
|
|
113
|
-
const example = this.generateToolExample(tool);
|
|
114
|
-
if (example) {
|
|
115
|
-
toolInfo += `\n Example: ${example}`;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
toolsInfo.push(toolInfo);
|
|
119
|
-
});
|
|
120
|
-
return toolsInfo.join('\n\n');
|
|
121
|
-
}
|
|
122
|
-
generateToolExample(tool) {
|
|
123
|
-
// Generate simple examples based on tool name
|
|
124
|
-
const toolName = tool.name.toLowerCase();
|
|
125
|
-
if (toolName.includes('read') && toolName.includes('file')) {
|
|
126
|
-
return `${tool.name}({ filePath: "example.txt" })`;
|
|
127
|
-
}
|
|
128
|
-
if (toolName.includes('write') && toolName.includes('file')) {
|
|
129
|
-
return `${tool.name}({ filePath: "output.txt", content: "Hello World" })`;
|
|
130
|
-
}
|
|
131
|
-
if (toolName.includes('delete') && toolName.includes('file')) {
|
|
132
|
-
return `${tool.name}({ filePath: "temp.txt" })`;
|
|
133
|
-
}
|
|
134
|
-
if (toolName.includes('move') && toolName.includes('file')) {
|
|
135
|
-
return `${tool.name}({ sourcePath: "old.txt", destinationPath: "new.txt" })`;
|
|
136
|
-
}
|
|
137
|
-
if (toolName.includes('copy') && toolName.includes('file')) {
|
|
138
|
-
return `${tool.name}({ sourcePath: "source.txt", destinationPath: "copy.txt" })`;
|
|
139
|
-
}
|
|
140
|
-
// Generic example
|
|
141
|
-
return `${tool.name}({ /* parameters */ })`;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
exports.AddToolsListMessageModifier = AddToolsListMessageModifier;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
|
|
2
|
-
export interface BaseContextMessageModifierOptions {
|
|
3
|
-
prependmessage?: string;
|
|
4
|
-
datetime?: boolean;
|
|
5
|
-
osInfo?: boolean;
|
|
6
|
-
workingdir?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare class BaseContextMessageModifier extends BaseMessageModifier {
|
|
9
|
-
private readonly prependMessage;
|
|
10
|
-
private readonly includeDateTime;
|
|
11
|
-
private readonly includeOsInfo;
|
|
12
|
-
private readonly includeWorkingDir;
|
|
13
|
-
constructor(options?: BaseContextMessageModifierOptions);
|
|
14
|
-
modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
15
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BaseContextMessageModifier = void 0;
|
|
7
|
-
const processor_1 = require("../../processor");
|
|
8
|
-
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
9
|
-
const os_1 = __importDefault(require("os"));
|
|
10
|
-
class BaseContextMessageModifier extends processor_1.BaseMessageModifier {
|
|
11
|
-
constructor(options = {}) {
|
|
12
|
-
super({ context: options });
|
|
13
|
-
this.prependMessage = options.prependmessage || '';
|
|
14
|
-
this.includeDateTime = options.datetime || false;
|
|
15
|
-
this.includeOsInfo = options.osInfo || false;
|
|
16
|
-
this.includeWorkingDir = options.workingdir || false;
|
|
17
|
-
}
|
|
18
|
-
async modify(input) {
|
|
19
|
-
try {
|
|
20
|
-
const { originalRequest, createdMessage, context } = input;
|
|
21
|
-
const contextParts = [];
|
|
22
|
-
// Add prepend message if provided
|
|
23
|
-
if (this.prependMessage) {
|
|
24
|
-
contextParts.push(this.prependMessage);
|
|
25
|
-
}
|
|
26
|
-
// Add date/time if requested
|
|
27
|
-
if (this.includeDateTime) {
|
|
28
|
-
const now = new Date();
|
|
29
|
-
contextParts.push(`Current Date/Time: ${now.toISOString()}`);
|
|
30
|
-
}
|
|
31
|
-
// Add OS info if requested
|
|
32
|
-
if (this.includeOsInfo) {
|
|
33
|
-
const osInfo = {
|
|
34
|
-
platform: os_1.default.platform(),
|
|
35
|
-
arch: os_1.default.arch(),
|
|
36
|
-
version: os_1.default.version(),
|
|
37
|
-
hostname: os_1.default.hostname()
|
|
38
|
-
};
|
|
39
|
-
contextParts.push(`Operating System: ${JSON.stringify(osInfo, null, 2)}`);
|
|
40
|
-
}
|
|
41
|
-
// Add working directory if requested
|
|
42
|
-
if (this.includeWorkingDir) {
|
|
43
|
-
try {
|
|
44
|
-
const projectPath = await codeboltjs_1.default.project.getProjectPath();
|
|
45
|
-
contextParts.push(`Working Directory: ${projectPath}`);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
contextParts.push(`Working Directory: ${process.cwd()}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// Create context message if we have any context parts
|
|
52
|
-
if (contextParts.length > 0) {
|
|
53
|
-
const contextMessage = {
|
|
54
|
-
role: 'system',
|
|
55
|
-
content: contextParts.join('\n\n'),
|
|
56
|
-
name: 'base-context'
|
|
57
|
-
};
|
|
58
|
-
return {
|
|
59
|
-
messages: [contextMessage, ...createdMessage.messages],
|
|
60
|
-
metadata: {
|
|
61
|
-
...createdMessage.metadata,
|
|
62
|
-
baseContextAdded: true,
|
|
63
|
-
contextParts: contextParts.length
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return createdMessage;
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
console.error('Error in BaseContextMessageModifier:', error);
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.BaseContextMessageModifier = BaseContextMessageModifier;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
|
|
2
|
-
export interface BaseSystemInstructionMessageModifierOptions {
|
|
3
|
-
systemInstruction?: string;
|
|
4
|
-
position?: 'start' | 'end';
|
|
5
|
-
}
|
|
6
|
-
export declare class BaseSystemInstructionMessageModifier extends BaseMessageModifier {
|
|
7
|
-
private readonly systemInstruction;
|
|
8
|
-
private readonly position;
|
|
9
|
-
constructor(options?: BaseSystemInstructionMessageModifierOptions);
|
|
10
|
-
modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
11
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseSystemInstructionMessageModifier = void 0;
|
|
4
|
-
const processor_1 = require("../../processor");
|
|
5
|
-
class BaseSystemInstructionMessageModifier extends processor_1.BaseMessageModifier {
|
|
6
|
-
constructor(options = {}) {
|
|
7
|
-
super({ context: options });
|
|
8
|
-
this.systemInstruction = options.systemInstruction || 'You are a helpful assistant.';
|
|
9
|
-
this.position = options.position || 'start';
|
|
10
|
-
}
|
|
11
|
-
async modify(input) {
|
|
12
|
-
try {
|
|
13
|
-
const { originalRequest, createdMessage, context } = input;
|
|
14
|
-
// Create system instruction message
|
|
15
|
-
const systemMessage = {
|
|
16
|
-
role: 'system',
|
|
17
|
-
content: this.systemInstruction,
|
|
18
|
-
name: 'system-instruction'
|
|
19
|
-
};
|
|
20
|
-
let messages;
|
|
21
|
-
if (this.position === 'start') {
|
|
22
|
-
// Add system instruction at the beginning
|
|
23
|
-
messages = [systemMessage, ...createdMessage.messages];
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
// Add system instruction at the end (before user message)
|
|
27
|
-
const userMessages = createdMessage.messages.filter(m => m.role === 'user');
|
|
28
|
-
const otherMessages = createdMessage.messages.filter(m => m.role !== 'user');
|
|
29
|
-
messages = [...otherMessages, systemMessage, ...userMessages];
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
messages,
|
|
33
|
-
metadata: {
|
|
34
|
-
...createdMessage.metadata,
|
|
35
|
-
systemInstructionAdded: true,
|
|
36
|
-
systemInstructionPosition: this.position
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
console.error('Error in BaseSystemInstructionMessageModifier:', error);
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.BaseSystemInstructionMessageModifier = BaseSystemInstructionMessageModifier;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
|
|
2
|
-
export interface HandleUrlMessageModifierOptions {
|
|
3
|
-
googleSearchEnabled?: boolean;
|
|
4
|
-
fetchUrlContent?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export declare class HandleUrlMessageModifier extends BaseMessageModifier {
|
|
7
|
-
private readonly googleSearchEnabled;
|
|
8
|
-
private readonly fetchUrlContent;
|
|
9
|
-
constructor(options?: HandleUrlMessageModifierOptions);
|
|
10
|
-
modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
11
|
-
private extractUrls;
|
|
12
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HandleUrlMessageModifier = void 0;
|
|
4
|
-
const processor_1 = require("../../processor");
|
|
5
|
-
class HandleUrlMessageModifier extends processor_1.BaseMessageModifier {
|
|
6
|
-
constructor(options = {}) {
|
|
7
|
-
super({ context: options });
|
|
8
|
-
this.googleSearchEnabled = options.googleSearchEnabled || false;
|
|
9
|
-
this.fetchUrlContent = options.fetchUrlContent || false;
|
|
10
|
-
}
|
|
11
|
-
async modify(input) {
|
|
12
|
-
try {
|
|
13
|
-
const { originalRequest, createdMessage, context } = input;
|
|
14
|
-
// Check if the request contains URLs
|
|
15
|
-
const urls = this.extractUrls(originalRequest);
|
|
16
|
-
if (urls.length > 0) {
|
|
17
|
-
let contextContent = `URLs detected: ${urls.join(', ')}. ${this.googleSearchEnabled ? 'Google search is enabled.' : 'Google search is disabled.'}`;
|
|
18
|
-
// Fetch URL content if enabled
|
|
19
|
-
if (this.fetchUrlContent) {
|
|
20
|
-
contextContent += '\n\nURL Content Fetching: Enabled (content would be fetched in a real implementation)';
|
|
21
|
-
// In a real implementation, you would fetch the content here
|
|
22
|
-
// const urlContents = await Promise.all(urls.map(url => this.fetchContent(url)));
|
|
23
|
-
}
|
|
24
|
-
// Add URL context to the message
|
|
25
|
-
const urlContextMessage = {
|
|
26
|
-
role: 'system',
|
|
27
|
-
content: contextContent,
|
|
28
|
-
name: 'url-detector'
|
|
29
|
-
};
|
|
30
|
-
return {
|
|
31
|
-
messages: [...createdMessage.messages, urlContextMessage],
|
|
32
|
-
metadata: {
|
|
33
|
-
...createdMessage.metadata,
|
|
34
|
-
urlsDetected: urls,
|
|
35
|
-
googleSearchEnabled: this.googleSearchEnabled,
|
|
36
|
-
fetchUrlContent: this.fetchUrlContent
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
return createdMessage;
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
console.error('Error in HandleUrlMessageModifier:', error);
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
extractUrls(request) {
|
|
48
|
-
if (typeof request === 'string') {
|
|
49
|
-
const urlRegex = /https?:\/\/[^\s]+/g;
|
|
50
|
-
return request.match(urlRegex) || [];
|
|
51
|
-
}
|
|
52
|
-
if (typeof request === 'object' && request !== null) {
|
|
53
|
-
const requestString = JSON.stringify(request);
|
|
54
|
-
const urlRegex = /https?:\/\/[^\s]+/g;
|
|
55
|
-
return requestString.match(urlRegex) || [];
|
|
56
|
-
}
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.HandleUrlMessageModifier = HandleUrlMessageModifier;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
|
|
2
|
-
export interface ImageAttachmentMessageModifierOptions {
|
|
3
|
-
passImageAs?: 'URL' | 'Base64' | 'Path';
|
|
4
|
-
supportedFormats?: string[];
|
|
5
|
-
maxImageSize?: number;
|
|
6
|
-
}
|
|
7
|
-
export declare class ImageAttachmentMessageModifier extends BaseMessageModifier {
|
|
8
|
-
private readonly passImageAs;
|
|
9
|
-
private readonly supportedFormats;
|
|
10
|
-
private readonly maxImageSize;
|
|
11
|
-
constructor(options?: ImageAttachmentMessageModifierOptions);
|
|
12
|
-
modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
13
|
-
private extractImageReferences;
|
|
14
|
-
private isImagePath;
|
|
15
|
-
private processImage;
|
|
16
|
-
private processUrlImage;
|
|
17
|
-
private processLocalImage;
|
|
18
|
-
}
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ImageAttachmentMessageModifier = void 0;
|
|
37
|
-
const processor_1 = require("../../processor");
|
|
38
|
-
const fs = __importStar(require("fs/promises"));
|
|
39
|
-
const path = __importStar(require("path"));
|
|
40
|
-
class ImageAttachmentMessageModifier extends processor_1.BaseMessageModifier {
|
|
41
|
-
constructor(options = {}) {
|
|
42
|
-
super({ context: options });
|
|
43
|
-
this.passImageAs = options.passImageAs || 'URL';
|
|
44
|
-
this.supportedFormats = options.supportedFormats || ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp'];
|
|
45
|
-
this.maxImageSize = options.maxImageSize || 10 * 1024 * 1024; // 10MB default
|
|
46
|
-
}
|
|
47
|
-
async modify(input) {
|
|
48
|
-
try {
|
|
49
|
-
const { originalRequest, createdMessage, context } = input;
|
|
50
|
-
// Extract image references from the request
|
|
51
|
-
const imageReferences = this.extractImageReferences(originalRequest);
|
|
52
|
-
if (imageReferences.length === 0) {
|
|
53
|
-
return createdMessage;
|
|
54
|
-
}
|
|
55
|
-
const processedImages = [];
|
|
56
|
-
for (const imageRef of imageReferences) {
|
|
57
|
-
try {
|
|
58
|
-
const processedImage = await this.processImage(imageRef);
|
|
59
|
-
if (processedImage) {
|
|
60
|
-
processedImages.push(processedImage);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
console.error(`Error processing image ${imageRef}:`, error);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (processedImages.length === 0) {
|
|
68
|
-
return createdMessage;
|
|
69
|
-
}
|
|
70
|
-
// Add image context message
|
|
71
|
-
const imageContextMessage = {
|
|
72
|
-
role: 'system',
|
|
73
|
-
content: `Images attached to this conversation (${this.passImageAs} format):\n${processedImages.map((img, idx) => `${idx + 1}. ${img.description || img.reference}`).join('\n')}`,
|
|
74
|
-
name: 'image-attachments'
|
|
75
|
-
};
|
|
76
|
-
// Modify user messages to include image references
|
|
77
|
-
const modifiedMessages = createdMessage.messages.map(message => {
|
|
78
|
-
if (message.role === 'user') {
|
|
79
|
-
return {
|
|
80
|
-
...message,
|
|
81
|
-
attachments: processedImages
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return message;
|
|
85
|
-
});
|
|
86
|
-
return {
|
|
87
|
-
messages: [imageContextMessage, ...modifiedMessages],
|
|
88
|
-
metadata: {
|
|
89
|
-
...createdMessage.metadata,
|
|
90
|
-
imagesAttached: processedImages.length,
|
|
91
|
-
imageFormat: this.passImageAs,
|
|
92
|
-
processedImages
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
console.error('Error in ImageAttachmentMessageModifier:', error);
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
extractImageReferences(request) {
|
|
102
|
-
const imageRefs = [];
|
|
103
|
-
if (typeof request === 'string') {
|
|
104
|
-
// Look for image file paths or URLs
|
|
105
|
-
const imageRegex = /(?:\.png|\.jpg|\.jpeg|\.gif|\.webp|\.bmp|https?:\/\/[^\s]+\.(?:png|jpg|jpeg|gif|webp|bmp))/gi;
|
|
106
|
-
const matches = request.match(imageRegex);
|
|
107
|
-
if (matches) {
|
|
108
|
-
imageRefs.push(...matches);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (typeof request === 'object' && request !== null) {
|
|
112
|
-
// Look for image properties in the request object
|
|
113
|
-
const searchForImages = (obj) => {
|
|
114
|
-
if (Array.isArray(obj)) {
|
|
115
|
-
obj.forEach(searchForImages);
|
|
116
|
-
}
|
|
117
|
-
else if (typeof obj === 'object' && obj !== null) {
|
|
118
|
-
Object.values(obj).forEach(value => {
|
|
119
|
-
if (typeof value === 'string' && this.isImagePath(value)) {
|
|
120
|
-
imageRefs.push(value);
|
|
121
|
-
}
|
|
122
|
-
else if (typeof value === 'object') {
|
|
123
|
-
searchForImages(value);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
searchForImages(request);
|
|
129
|
-
}
|
|
130
|
-
return [...new Set(imageRefs)]; // Remove duplicates
|
|
131
|
-
}
|
|
132
|
-
isImagePath(str) {
|
|
133
|
-
const ext = path.extname(str).toLowerCase();
|
|
134
|
-
return this.supportedFormats.includes(ext) || /^https?:\/\/[^\s]+\.(?:png|jpg|jpeg|gif|webp|bmp)/i.test(str);
|
|
135
|
-
}
|
|
136
|
-
async processImage(imageRef) {
|
|
137
|
-
try {
|
|
138
|
-
if (imageRef.startsWith('http')) {
|
|
139
|
-
// URL image
|
|
140
|
-
return this.processUrlImage(imageRef);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
// Local file path
|
|
144
|
-
return this.processLocalImage(imageRef);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
console.error(`Error processing image ${imageRef}:`, error);
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
async processUrlImage(url) {
|
|
153
|
-
switch (this.passImageAs) {
|
|
154
|
-
case 'URL':
|
|
155
|
-
return {
|
|
156
|
-
type: 'url',
|
|
157
|
-
reference: url,
|
|
158
|
-
description: `Image from URL: ${url}`
|
|
159
|
-
};
|
|
160
|
-
case 'Base64':
|
|
161
|
-
// In a real implementation, you would fetch and convert to base64
|
|
162
|
-
return {
|
|
163
|
-
type: 'base64',
|
|
164
|
-
reference: url,
|
|
165
|
-
description: `Image from URL (would be converted to base64): ${url}`,
|
|
166
|
-
note: 'Base64 conversion not implemented for URLs in this demo'
|
|
167
|
-
};
|
|
168
|
-
case 'Path':
|
|
169
|
-
return {
|
|
170
|
-
type: 'path',
|
|
171
|
-
reference: url,
|
|
172
|
-
description: `Image URL: ${url}`
|
|
173
|
-
};
|
|
174
|
-
default:
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
async processLocalImage(filePath) {
|
|
179
|
-
try {
|
|
180
|
-
// Check if file exists and get stats
|
|
181
|
-
const stats = await fs.stat(filePath);
|
|
182
|
-
if (stats.size > this.maxImageSize) {
|
|
183
|
-
console.warn(`Image ${filePath} is too large (${stats.size} bytes)`);
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
switch (this.passImageAs) {
|
|
187
|
-
case 'Path':
|
|
188
|
-
return {
|
|
189
|
-
type: 'path',
|
|
190
|
-
reference: filePath,
|
|
191
|
-
description: `Local image: ${path.basename(filePath)}`,
|
|
192
|
-
size: stats.size
|
|
193
|
-
};
|
|
194
|
-
case 'Base64':
|
|
195
|
-
const imageBuffer = await fs.readFile(filePath);
|
|
196
|
-
const base64 = imageBuffer.toString('base64');
|
|
197
|
-
const ext = path.extname(filePath).substring(1);
|
|
198
|
-
return {
|
|
199
|
-
type: 'base64',
|
|
200
|
-
reference: `data:image/${ext};base64,${base64}`,
|
|
201
|
-
description: `Local image (base64): ${path.basename(filePath)}`,
|
|
202
|
-
size: stats.size
|
|
203
|
-
};
|
|
204
|
-
case 'URL':
|
|
205
|
-
// Convert local path to file:// URL
|
|
206
|
-
return {
|
|
207
|
-
type: 'url',
|
|
208
|
-
reference: `file://${path.resolve(filePath)}`,
|
|
209
|
-
description: `Local image (file URL): ${path.basename(filePath)}`,
|
|
210
|
-
size: stats.size
|
|
211
|
-
};
|
|
212
|
-
default:
|
|
213
|
-
return null;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
catch (error) {
|
|
217
|
-
console.error(`Error processing local image ${filePath}:`, error);
|
|
218
|
-
return null;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
exports.ImageAttachmentMessageModifier = ImageAttachmentMessageModifier;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
|
|
2
|
-
export interface WorkingDirectoryMessageModifierOptions {
|
|
3
|
-
showFolderStructureSummary?: boolean;
|
|
4
|
-
listFiles?: boolean;
|
|
5
|
-
listFilesDepth?: number;
|
|
6
|
-
listFilesLimit?: number;
|
|
7
|
-
listFilesIgnoreFromGitignore?: boolean;
|
|
8
|
-
listFilesIgnore?: string[];
|
|
9
|
-
}
|
|
10
|
-
export declare class WorkingDirectoryMessageModifier extends BaseMessageModifier {
|
|
11
|
-
private readonly showFolderStructureSummary;
|
|
12
|
-
private readonly listFiles;
|
|
13
|
-
private readonly listFilesDepth;
|
|
14
|
-
private readonly listFilesLimit;
|
|
15
|
-
private readonly listFilesIgnoreFromGitignore;
|
|
16
|
-
private readonly listFilesIgnore;
|
|
17
|
-
constructor(options?: WorkingDirectoryMessageModifierOptions);
|
|
18
|
-
modify(input: MessageModifierInput): Promise<ProcessedMessage>;
|
|
19
|
-
private generateFolderStructureSummary;
|
|
20
|
-
private generateFilesList;
|
|
21
|
-
private shouldIgnore;
|
|
22
|
-
}
|