@codebolt/agent 5.0.1 → 5.0.6

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.
Files changed (160) hide show
  1. package/dist/agent.d.ts +86 -0
  2. package/dist/agent.js +324 -0
  3. package/dist/builderpattern/agent.js +2 -2
  4. package/dist/builderpattern/followupquestionbuilder.js +1 -1
  5. package/dist/builderpattern/llmoutputhandler.js +7 -7
  6. package/dist/builderpattern/usermessage.d.ts +1 -6
  7. package/dist/composablepattern/document.js +35 -2
  8. package/dist/followupquestionbuilder.d.ts +75 -0
  9. package/dist/followupquestionbuilder.js +197 -0
  10. package/dist/index.d.ts +14 -0
  11. package/dist/index.js +23 -0
  12. package/dist/llmoutputhandler.d.ts +102 -0
  13. package/dist/llmoutputhandler.js +452 -0
  14. package/dist/processor/types/interfaces.d.ts +21 -44
  15. package/dist/processor-pieces/index.d.ts +3 -0
  16. package/dist/processor-pieces/index.js +3 -0
  17. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +5 -14
  18. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +40 -41
  19. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +13 -5
  20. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +58 -50
  21. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +8 -6
  22. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +22 -66
  23. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +2 -3
  24. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +2 -1
  25. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +2 -3
  26. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +2 -1
  27. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +4 -1
  28. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +2 -18
  29. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +93 -291
  30. package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +18 -0
  31. package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +41 -0
  32. package/dist/processor-pieces/postToolCallProcessors/index.d.ts +2 -1
  33. package/dist/processor-pieces/postToolCallProcessors/index.js +5 -0
  34. package/dist/processor-pieces/preInferenceProcessors/index.d.ts +1 -1
  35. package/dist/processor-pieces/preInferenceProcessors/index.js +3 -0
  36. package/dist/processor-pieces/pretoolCallProcessors/index.d.ts +2 -1
  37. package/dist/processor-pieces/pretoolCallProcessors/index.js +5 -0
  38. package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.d.ts +21 -0
  39. package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.js +32 -0
  40. package/dist/processor-pieces/pretoolCallProcessors/toolValidationModifier.d.ts +16 -0
  41. package/dist/processor-pieces/pretoolCallProcessors/toolValidationModifier.js +37 -0
  42. package/dist/promptbuilder.d.ts +382 -0
  43. package/dist/promptbuilder.js +805 -0
  44. package/dist/systemprompt.d.ts +20 -0
  45. package/dist/systemprompt.js +48 -0
  46. package/dist/taskInstruction.d.ts +37 -0
  47. package/dist/taskInstruction.js +57 -0
  48. package/dist/unified/agent/agent.js +2 -2
  49. package/dist/unified/agent/codeboltAgent.d.ts +122 -0
  50. package/dist/unified/agent/codeboltAgent.js +210 -0
  51. package/dist/unified/base/initialPromptGenerator.js +18 -4
  52. package/dist/unified/base/responseExecutor.d.ts +3 -2
  53. package/dist/unified/base/responseExecutor.js +100 -56
  54. package/dist/unified/index.d.ts +4 -0
  55. package/dist/unified/index.js +12 -1
  56. package/dist/usermessage.d.ts +70 -0
  57. package/dist/usermessage.js +123 -0
  58. package/package.json +5 -5
  59. package/dist/local-tools/fileTools.d.ts +0 -26
  60. package/dist/local-tools/fileTools.js +0 -162
  61. package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +0 -13
  62. package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +0 -68
  63. package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +0 -15
  64. package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +0 -212
  65. package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +0 -19
  66. package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +0 -110
  67. package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +0 -23
  68. package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +0 -173
  69. package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +0 -14
  70. package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +0 -93
  71. package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +0 -30
  72. package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +0 -330
  73. package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +0 -26
  74. package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +0 -269
  75. package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +0 -38
  76. package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +0 -217
  77. package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +0 -34
  78. package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +0 -147
  79. package/dist/processor-pieces/additionalModifiers/index.d.ts +0 -12
  80. package/dist/processor-pieces/additionalModifiers/index.js +0 -28
  81. package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +0 -29
  82. package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +0 -155
  83. package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +0 -15
  84. package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +0 -129
  85. package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +0 -25
  86. package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +0 -169
  87. package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +0 -20
  88. package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +0 -152
  89. package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +0 -7
  90. package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +0 -93
  91. package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +0 -9
  92. package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +0 -77
  93. package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +0 -19
  94. package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +0 -110
  95. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +0 -20
  96. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +0 -124
  97. package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +0 -41
  98. package/dist/processor-pieces/messageModifiers/environmentContext.js +0 -355
  99. package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +0 -23
  100. package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +0 -207
  101. package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +0 -7
  102. package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +0 -26
  103. package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +0 -1
  104. package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +0 -2
  105. package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +0 -7
  106. package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +0 -24
  107. package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +0 -41
  108. package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +0 -197
  109. package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +0 -26
  110. package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +0 -90
  111. package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +0 -81
  112. package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +0 -329
  113. package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +0 -40
  114. package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +0 -272
  115. package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +0 -49
  116. package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +0 -291
  117. package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +0 -49
  118. package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +0 -293
  119. package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +0 -47
  120. package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +0 -249
  121. package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +0 -30
  122. package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +0 -137
  123. package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +0 -30
  124. package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +0 -228
  125. package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +0 -99
  126. package/dist/processor-pieces/postToolCall/telemetryProcessor.js +0 -278
  127. package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +0 -37
  128. package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +0 -178
  129. package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +0 -43
  130. package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +0 -207
  131. package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +0 -52
  132. package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +0 -264
  133. package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +0 -49
  134. package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +0 -293
  135. package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +0 -7
  136. package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +0 -31
  137. package/dist/processor-pieces/preToolCall/index.d.ts +0 -9
  138. package/dist/processor-pieces/preToolCall/index.js +0 -18
  139. package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +0 -58
  140. package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +0 -444
  141. package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +0 -44
  142. package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +0 -367
  143. package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +0 -58
  144. package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +0 -391
  145. package/dist/unified/agent/tool.d.ts +0 -99
  146. package/dist/unified/agent/tool.js +0 -440
  147. package/dist/unified/examples/agentExample.d.ts +0 -46
  148. package/dist/unified/examples/agentExample.js +0 -464
  149. package/dist/unified/examples/documentationPatternExample.d.ts +0 -10
  150. package/dist/unified/examples/documentationPatternExample.js +0 -385
  151. package/dist/unified/examples/followUpProcessorsExample.d.ts +0 -45
  152. package/dist/unified/examples/followUpProcessorsExample.js +0 -311
  153. package/dist/unified/examples/orchestratorExample.d.ts +0 -16
  154. package/dist/unified/examples/orchestratorExample.js +0 -415
  155. package/dist/unified/examples/preToolCallProcessorsExample.d.ts +0 -36
  156. package/dist/unified/examples/preToolCallProcessorsExample.js +0 -458
  157. package/dist/unified/examples/workflowExample.d.ts +0 -12
  158. package/dist/unified/examples/workflowExample.js +0 -497
  159. package/dist/unified/orchestrator/orchestrator.d.ts +0 -260
  160. package/dist/unified/orchestrator/orchestrator.js +0 -519
@@ -1,162 +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.FileCopyTool = exports.FileMoveTool = exports.FileDeleteTool = exports.FileWriteTool = exports.FileReadTool = void 0;
37
- const processor_1 = require("../processor");
38
- const fs = __importStar(require("fs/promises"));
39
- const path = __importStar(require("path"));
40
- class FileReadTool extends processor_1.BaseTool {
41
- constructor() {
42
- super('FileRead', 'Read content from a file', {
43
- filePath: { type: 'string', required: true, description: 'Path to the file to read' }
44
- });
45
- }
46
- async execute(params, abortSignal) {
47
- await this.checkAbortSignal(abortSignal);
48
- if (!this.validateParameters(params)) {
49
- throw new Error('Invalid parameters: filePath is required');
50
- }
51
- const { filePath } = params;
52
- const content = await fs.readFile(filePath, 'utf-8');
53
- return content;
54
- }
55
- validateParameters(params) {
56
- return params && typeof params.filePath === 'string' && params.filePath.trim() !== '';
57
- }
58
- }
59
- exports.FileReadTool = FileReadTool;
60
- class FileWriteTool extends processor_1.BaseTool {
61
- constructor() {
62
- super('FileWrite', 'Write content to a file', {
63
- filePath: { type: 'string', required: true, description: 'Path to the file to write' },
64
- content: { type: 'string', required: true, description: 'Content to write to the file' }
65
- });
66
- }
67
- async execute(params, abortSignal) {
68
- await this.checkAbortSignal(abortSignal);
69
- if (!this.validateParameters(params)) {
70
- throw new Error('Invalid parameters: filePath and content are required');
71
- }
72
- const { filePath, content } = params;
73
- // Ensure directory exists
74
- const dir = path.dirname(filePath);
75
- await fs.mkdir(dir, { recursive: true });
76
- await fs.writeFile(filePath, content, 'utf-8');
77
- return `Successfully wrote ${content.length} characters to ${filePath}`;
78
- }
79
- validateParameters(params) {
80
- return params &&
81
- typeof params.filePath === 'string' &&
82
- params.filePath.trim() !== '' &&
83
- typeof params.content === 'string';
84
- }
85
- }
86
- exports.FileWriteTool = FileWriteTool;
87
- class FileDeleteTool extends processor_1.BaseTool {
88
- constructor() {
89
- super('FileDelete', 'Delete a file', {
90
- filePath: { type: 'string', required: true, description: 'Path to the file to delete' }
91
- });
92
- }
93
- async execute(params, abortSignal) {
94
- await this.checkAbortSignal(abortSignal);
95
- if (!this.validateParameters(params)) {
96
- throw new Error('Invalid parameters: filePath is required');
97
- }
98
- const { filePath } = params;
99
- await fs.unlink(filePath);
100
- return `Successfully deleted ${filePath}`;
101
- }
102
- validateParameters(params) {
103
- return params && typeof params.filePath === 'string' && params.filePath.trim() !== '';
104
- }
105
- }
106
- exports.FileDeleteTool = FileDeleteTool;
107
- class FileMoveTool extends processor_1.BaseTool {
108
- constructor() {
109
- super('FileMove', 'Move a file from one location to another', {
110
- sourcePath: { type: 'string', required: true, description: 'Source file path' },
111
- destinationPath: { type: 'string', required: true, description: 'Destination file path' }
112
- });
113
- }
114
- async execute(params, abortSignal) {
115
- await this.checkAbortSignal(abortSignal);
116
- if (!this.validateParameters(params)) {
117
- throw new Error('Invalid parameters: sourcePath and destinationPath are required');
118
- }
119
- const { sourcePath, destinationPath } = params;
120
- // Ensure destination directory exists
121
- const dir = path.dirname(destinationPath);
122
- await fs.mkdir(dir, { recursive: true });
123
- await fs.rename(sourcePath, destinationPath);
124
- return `Successfully moved ${sourcePath} to ${destinationPath}`;
125
- }
126
- validateParameters(params) {
127
- return params &&
128
- typeof params.sourcePath === 'string' &&
129
- params.sourcePath.trim() !== '' &&
130
- typeof params.destinationPath === 'string' &&
131
- params.destinationPath.trim() !== '';
132
- }
133
- }
134
- exports.FileMoveTool = FileMoveTool;
135
- class FileCopyTool extends processor_1.BaseTool {
136
- constructor() {
137
- super('FileCopy', 'Copy a file from one location to another', {
138
- sourcePath: { type: 'string', required: true, description: 'Source file path' },
139
- destinationPath: { type: 'string', required: true, description: 'Destination file path' }
140
- });
141
- }
142
- async execute(params, abortSignal) {
143
- await this.checkAbortSignal(abortSignal);
144
- if (!this.validateParameters(params)) {
145
- throw new Error('Invalid parameters: sourcePath and destinationPath are required');
146
- }
147
- const { sourcePath, destinationPath } = params;
148
- // Ensure destination directory exists
149
- const dir = path.dirname(destinationPath);
150
- await fs.mkdir(dir, { recursive: true });
151
- await fs.copyFile(sourcePath, destinationPath);
152
- return `Successfully copied ${sourcePath} to ${destinationPath}`;
153
- }
154
- validateParameters(params) {
155
- return params &&
156
- typeof params.sourcePath === 'string' &&
157
- params.sourcePath.trim() !== '' &&
158
- typeof params.destinationPath === 'string' &&
159
- params.destinationPath.trim() !== '';
160
- }
161
- }
162
- exports.FileCopyTool = FileCopyTool;
@@ -1,13 +0,0 @@
1
- import { ProcessedMessage } from "@codebolt/types/agent";
2
- import { BaseMessageModifier } from "../base";
3
- import { FlatUserMessage } from "@codebolt/types/sdk";
4
- export interface ArgumentProcessorOptions {
5
- appendRawInvocation?: boolean;
6
- argumentSeparator?: string;
7
- includeCommandName?: boolean;
8
- }
9
- export declare class ArgumentProcessorModifier extends BaseMessageModifier {
10
- private readonly options;
11
- constructor(options?: ArgumentProcessorOptions);
12
- modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
13
- }
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArgumentProcessorModifier = void 0;
4
- const base_1 = require("../base");
5
- class ArgumentProcessorModifier extends base_1.BaseMessageModifier {
6
- constructor(options = {}) {
7
- super();
8
- this.options = {
9
- appendRawInvocation: options.appendRawInvocation !== false,
10
- argumentSeparator: options.argumentSeparator || ' ',
11
- includeCommandName: options.includeCommandName || false
12
- };
13
- }
14
- modify(originalRequest, createdMessage) {
15
- var _a;
16
- try {
17
- // Get arguments from metadata
18
- const invocation = (_a = createdMessage.metadata) === null || _a === void 0 ? void 0 : _a.invocation;
19
- if (!(invocation === null || invocation === void 0 ? void 0 : invocation.args)) {
20
- return Promise.resolve(createdMessage);
21
- }
22
- // Find the user message to append arguments to
23
- const userMessage = createdMessage.message.messages.find(msg => msg.role === 'user');
24
- if (!userMessage || typeof userMessage.content !== 'string') {
25
- return Promise.resolve(createdMessage);
26
- }
27
- let appendContent = '';
28
- if (this.options.appendRawInvocation && invocation.raw) {
29
- // Append the full raw command invocation
30
- appendContent = `\n\nFull command: ${invocation.raw}`;
31
- }
32
- else {
33
- // Append just the arguments
34
- let argsToAppend = invocation.args;
35
- if (this.options.includeCommandName && invocation.name) {
36
- argsToAppend = `${invocation.name}${this.options.argumentSeparator}${argsToAppend}`;
37
- }
38
- appendContent = `\n\nArguments: ${argsToAppend}`;
39
- }
40
- // Update the user message with appended arguments
41
- const updatedMessages = createdMessage.message.messages.map(msg => {
42
- if (msg.role === 'user' && typeof msg.content === 'string' && msg === userMessage) {
43
- return {
44
- ...msg,
45
- content: msg.content + appendContent
46
- };
47
- }
48
- return msg;
49
- });
50
- return Promise.resolve({
51
- message: {
52
- ...createdMessage.message,
53
- messages: updatedMessages
54
- },
55
- metadata: {
56
- ...createdMessage.metadata,
57
- argumentsProcessed: true,
58
- argumentsAppended: appendContent.trim()
59
- }
60
- });
61
- }
62
- catch (error) {
63
- console.error('Error in ArgumentProcessorModifier:', error);
64
- return Promise.resolve(createdMessage);
65
- }
66
- }
67
- }
68
- exports.ArgumentProcessorModifier = ArgumentProcessorModifier;
@@ -1,15 +0,0 @@
1
- import { ProcessedMessage } from "@codebolt/types/agent";
2
- import { BaseMessageModifier } from "../base";
3
- import { FlatUserMessage } from "@codebolt/types/sdk";
4
- export interface AtFileProcessorOptions {
5
- maxFileSize?: number;
6
- allowedExtensions?: string[];
7
- basePath?: string;
8
- }
9
- export declare class AtFileProcessorModifier extends BaseMessageModifier {
10
- private readonly options;
11
- constructor(options?: AtFileProcessorOptions);
12
- modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
13
- private readFileContent;
14
- private getFolderStructure;
15
- }
@@ -1,212 +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.AtFileProcessorModifier = void 0;
37
- const base_1 = require("../base");
38
- const fs = __importStar(require("fs"));
39
- const path = __importStar(require("path"));
40
- class AtFileProcessorModifier extends base_1.BaseMessageModifier {
41
- constructor(options = {}) {
42
- super();
43
- this.options = {
44
- maxFileSize: options.maxFileSize || 1024 * 1024, // 1MB default
45
- allowedExtensions: options.allowedExtensions || ['.ts', '.js', '.json', '.md', '.txt', '.yml', '.yaml', '.xml', '.html', '.css', '.py', '.java', '.cpp', '.c', '.h'],
46
- basePath: options.basePath || process.cwd()
47
- };
48
- }
49
- async modify(originalRequest, createdMessage) {
50
- try {
51
- const mentionedFiles = originalRequest.mentionedFiles || [];
52
- const mentionedFolders = originalRequest.mentionedFolders || [];
53
- if (mentionedFiles.length === 0 && mentionedFolders.length === 0) {
54
- return createdMessage;
55
- }
56
- const contextParts = [];
57
- // Process mentioned files
58
- if (mentionedFiles.length > 0) {
59
- const fileContents = await Promise.all(mentionedFiles.map(async (filePath) => {
60
- try {
61
- const content = await this.readFileContent(filePath);
62
- return `--- Content from ${filePath} ---\n${content}\n--- End of ${filePath} ---`;
63
- }
64
- catch (error) {
65
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
66
- return `[Error loading ${filePath}: ${errorMessage}]`;
67
- }
68
- }));
69
- contextParts.push(`File Contents:\n${fileContents.join('\n\n')}`);
70
- }
71
- // Process mentioned folders
72
- if (mentionedFolders.length > 0) {
73
- const folderContents = await Promise.all(mentionedFolders.map(async (folderPath) => {
74
- try {
75
- const structure = await this.getFolderStructure(folderPath);
76
- return `--- Structure of ${folderPath} ---\n${structure}\n--- End of ${folderPath} ---`;
77
- }
78
- catch (error) {
79
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
80
- return `[Error reading folder ${folderPath}: ${errorMessage}]`;
81
- }
82
- }));
83
- contextParts.push(`Folder Structures:\n${folderContents.join('\n\n')}`);
84
- }
85
- // Find the last user message and append context to it
86
- const messages = [...createdMessage.message.messages];
87
- let lastUserMessageIndex = -1;
88
- for (let i = messages.length - 1; i >= 0; i--) {
89
- if (messages[i].role === 'user') {
90
- lastUserMessageIndex = i;
91
- break;
92
- }
93
- }
94
- if (lastUserMessageIndex !== -1) {
95
- const lastUserMessage = messages[lastUserMessageIndex];
96
- const currentContent = Array.isArray(lastUserMessage.content)
97
- ? lastUserMessage.content
98
- : [{ type: 'text', text: lastUserMessage.content }];
99
- // Add context as additional content parts
100
- const contextContent = {
101
- type: 'text',
102
- text: contextParts.join('\n\n')
103
- };
104
- messages[lastUserMessageIndex] = {
105
- ...lastUserMessage,
106
- content: [...currentContent, contextContent]
107
- };
108
- }
109
- return Promise.resolve({
110
- message: {
111
- ...createdMessage.message,
112
- messages
113
- },
114
- metadata: {
115
- ...createdMessage.metadata,
116
- atFileProcessed: true,
117
- processedFiles: mentionedFiles,
118
- processedFolders: mentionedFolders
119
- }
120
- });
121
- }
122
- catch (error) {
123
- console.error('Error in AtFileProcessorModifier:', error);
124
- return createdMessage;
125
- }
126
- }
127
- async readFileContent(filePath) {
128
- // Resolve path relative to base path
129
- const resolvedPath = path.isAbsolute(filePath) ? filePath : path.resolve(this.options.basePath, filePath);
130
- // Security check: ensure the file is within allowed directory
131
- const relativePath = path.relative(this.options.basePath, resolvedPath);
132
- if (relativePath.startsWith('..')) {
133
- throw new Error(`Access denied: ${filePath} is outside the allowed directory`);
134
- }
135
- // Check if file exists
136
- try {
137
- await fs.promises.access(resolvedPath, fs.constants.R_OK);
138
- }
139
- catch (error) {
140
- throw new Error(`File not found or not readable: ${filePath}`);
141
- }
142
- // Check file size
143
- const stats = await fs.promises.stat(resolvedPath);
144
- if (stats.size > this.options.maxFileSize) {
145
- throw new Error(`File too large: ${filePath} (${stats.size} bytes, max ${this.options.maxFileSize} bytes)`);
146
- }
147
- // Check file extension if allowedExtensions is specified
148
- if (this.options.allowedExtensions.length > 0) {
149
- const ext = path.extname(resolvedPath).toLowerCase();
150
- if (!this.options.allowedExtensions.includes(ext)) {
151
- throw new Error(`File type not allowed: ${ext}`);
152
- }
153
- }
154
- // Read and return file content
155
- const content = await fs.promises.readFile(resolvedPath, 'utf-8');
156
- return content;
157
- }
158
- async getFolderStructure(folderPath) {
159
- // Resolve path relative to base path
160
- const resolvedPath = path.isAbsolute(folderPath) ? folderPath : path.resolve(this.options.basePath, folderPath);
161
- // Security check: ensure the folder is within allowed directory
162
- const relativePath = path.relative(this.options.basePath, resolvedPath);
163
- if (relativePath.startsWith('..')) {
164
- throw new Error(`Access denied: ${folderPath} is outside the allowed directory`);
165
- }
166
- // Check if folder exists and is readable
167
- try {
168
- await fs.promises.access(resolvedPath, fs.constants.R_OK);
169
- const stats = await fs.promises.stat(resolvedPath);
170
- if (!stats.isDirectory()) {
171
- throw new Error(`${folderPath} is not a directory`);
172
- }
173
- }
174
- catch (error) {
175
- throw new Error(`Folder not found or not readable: ${folderPath}`);
176
- }
177
- // Read directory structure
178
- try {
179
- const entries = await fs.promises.readdir(resolvedPath, { withFileTypes: true });
180
- const lines = [];
181
- // Sort entries: directories first, then files
182
- const sortedEntries = entries.sort((a, b) => {
183
- if (a.isDirectory() && !b.isDirectory())
184
- return -1;
185
- if (!a.isDirectory() && b.isDirectory())
186
- return 1;
187
- return a.name.localeCompare(b.name);
188
- });
189
- for (const entry of sortedEntries.slice(0, 50)) { // Limit to 50 entries
190
- if (entry.name.startsWith('.'))
191
- continue; // Skip hidden files
192
- if (entry.isDirectory()) {
193
- lines.push(`${folderPath}/${entry.name}/`);
194
- }
195
- else {
196
- const filePath = path.join(resolvedPath, entry.name);
197
- const stats = await fs.promises.stat(filePath);
198
- const size = stats.size < 1024 ? `${stats.size}B` : `${Math.round(stats.size / 1024)}KB`;
199
- lines.push(`${folderPath}/${entry.name} (${size})`);
200
- }
201
- }
202
- if (entries.length > 50) {
203
- lines.push(`... and ${entries.length - 50} more items`);
204
- }
205
- return lines.join('\n');
206
- }
207
- catch (error) {
208
- throw new Error(`Error reading folder structure: ${error instanceof Error ? error.message : 'unknown error'}`);
209
- }
210
- }
211
- }
212
- exports.AtFileProcessorModifier = AtFileProcessorModifier;
@@ -1,19 +0,0 @@
1
- import { ProcessedMessage } from "@codebolt/types/agent";
2
- import { BaseMessageModifier } from "../base";
3
- import { FlatUserMessage } from "@codebolt/types/sdk";
4
- export interface ChatCompressionOptions {
5
- tokenThreshold?: number;
6
- compressionRatio?: number;
7
- preserveRecentMessages?: number;
8
- enableCompression?: boolean;
9
- }
10
- export declare class ChatCompressionModifier extends BaseMessageModifier {
11
- private readonly options;
12
- private hasFailedCompressionAttempt;
13
- constructor(options?: ChatCompressionOptions);
14
- modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
15
- private shouldCompressChat;
16
- private compressMessages;
17
- private createConversationSummary;
18
- resetCompressionState(): void;
19
- }
@@ -1,110 +0,0 @@
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;
@@ -1,23 +0,0 @@
1
- import { ProcessedMessage } from "@codebolt/types/agent";
2
- import { BaseMessageModifier } from "../base";
3
- import { FlatUserMessage } from "@codebolt/types/sdk";
4
- export interface ChatRecordingOptions {
5
- enableRecording?: boolean;
6
- recordingPath?: string;
7
- maxRecordingSize?: number;
8
- includeMetadata?: boolean;
9
- recordingFormat?: 'json' | 'markdown';
10
- }
11
- export declare class ChatRecordingModifier extends BaseMessageModifier {
12
- private readonly options;
13
- private recordingFile?;
14
- constructor(options?: ChatRecordingOptions);
15
- modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
16
- private initializeRecording;
17
- private recordMessages;
18
- private writeRecord;
19
- startRecording(customPath?: string): void;
20
- stopRecording(): void;
21
- getRecordingFile(): string | undefined;
22
- isRecording(): boolean;
23
- }