@codebolt/agent 6.1.19 → 6.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -10
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +11 -15
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.d.ts +0 -1
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +16 -33
- package/dist/processor-pieces/messageModifiers/capabilityContextModifier.js +3 -2
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.d.ts +7 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.js +135 -27
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +3 -3
- package/dist/processor-pieces/messageModifiers/contextAssemblyModifier.js +18 -12
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +15 -15
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +48 -2
- package/dist/processor-pieces/messageModifiers/ideContextModifier.js +3 -2
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +9 -15
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +17 -20
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +8 -19
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +1 -1
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +15 -15
- package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +3 -3
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +2 -2
- package/dist/processor-pieces/utils/messageModifierHelper.js +3 -3
- package/dist/types/libFunctionTypes.d.ts +5 -0
- package/dist/unified/agent/agent.d.ts +69 -2
- package/dist/unified/agent/agent.js +370 -48
- package/dist/unified/agent/tools.d.ts +17 -3
- package/dist/unified/agent/tools.js +82 -51
- package/dist/unified/base/agentStep.d.ts +1 -0
- package/dist/unified/base/agentStep.js +39 -11
- package/dist/unified/base/initialPromptGenerator.d.ts +2 -0
- package/dist/unified/base/initialPromptGenerator.js +98 -20
- package/dist/unified/base/promptContext.d.ts +3 -0
- package/dist/unified/base/promptContext.js +193 -15
- package/dist/unified/base/responseExecutor.d.ts +9 -1
- package/dist/unified/base/responseExecutor.js +248 -68
- package/dist/unified/index.d.ts +1 -2
- package/dist/unified/index.js +2 -4
- package/dist/unified/services/CompressionCoordinator.js +9 -9
- package/dist/unified/services/compaction/autoCompact.js +5 -5
- package/dist/unified/services/compaction/contextCollapse.js +2 -2
- package/dist/unified/services/compaction/reactiveCompact.js +5 -5
- package/dist/unified/types/libTypes.d.ts +6 -0
- package/dist/unified/utils/agentToolLoader.d.ts +10 -0
- package/dist/unified/utils/agentToolLoader.js +90 -24
- package/package.json +5 -1
- package/dist/unified/agent/codeboltAgent.d.ts +0 -61
- package/dist/unified/agent/codeboltAgent.js +0 -334
|
@@ -114,14 +114,54 @@ class Tool {
|
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
getZodDef(zodType) {
|
|
118
|
+
return (zodType._def || {});
|
|
119
|
+
}
|
|
120
|
+
getZodTypeName(zodType) {
|
|
121
|
+
const def = this.getZodDef(zodType);
|
|
122
|
+
return typeof def['typeName'] === 'string' ? def['typeName'] : undefined;
|
|
123
|
+
}
|
|
124
|
+
getZodDescription(zodType) {
|
|
125
|
+
const def = this.getZodDef(zodType);
|
|
126
|
+
return typeof def['description'] === 'string' ? def['description'] : undefined;
|
|
127
|
+
}
|
|
128
|
+
applyDescription(jsonSchema, zodType) {
|
|
129
|
+
const description = this.getZodDescription(zodType);
|
|
130
|
+
if (description) {
|
|
131
|
+
jsonSchema['description'] = description;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
withDescriptionFrom(jsonSchema, zodType) {
|
|
135
|
+
if (jsonSchema && typeof jsonSchema === 'object' && !Array.isArray(jsonSchema)) {
|
|
136
|
+
this.applyDescription(jsonSchema, zodType);
|
|
137
|
+
}
|
|
138
|
+
return jsonSchema;
|
|
139
|
+
}
|
|
140
|
+
getObjectShape(zodType) {
|
|
141
|
+
const directShape = zodType.shape;
|
|
142
|
+
if (directShape && typeof directShape === 'object') {
|
|
143
|
+
return directShape;
|
|
144
|
+
}
|
|
145
|
+
const defShape = this.getZodDef(zodType)['shape'];
|
|
146
|
+
if (typeof defShape === 'function') {
|
|
147
|
+
return defShape();
|
|
148
|
+
}
|
|
149
|
+
if (defShape && typeof defShape === 'object') {
|
|
150
|
+
return defShape;
|
|
151
|
+
}
|
|
152
|
+
return {};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Converts a Zod schema to JSON Schema format for OpenAI functions.
|
|
156
|
+
*
|
|
157
|
+
* The converter intentionally checks Zod's schema metadata instead of
|
|
158
|
+
* relying only on instanceof. Local tools are often created in another
|
|
159
|
+
* workspace package with its own zod module instance, which makes
|
|
160
|
+
* instanceof checks fail even though the schema is valid.
|
|
161
|
+
*/
|
|
120
162
|
zodSchemaToJsonSchema(schema) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (schema instanceof zod_1.z.ZodObject) {
|
|
124
|
-
const shape = schema.shape;
|
|
163
|
+
if (schema instanceof zod_1.z.ZodObject || this.getZodTypeName(schema) === 'ZodObject') {
|
|
164
|
+
const shape = this.getObjectShape(schema);
|
|
125
165
|
const properties = {};
|
|
126
166
|
const required = [];
|
|
127
167
|
for (const [key, value] of Object.entries(shape)) {
|
|
@@ -131,12 +171,14 @@ class Tool {
|
|
|
131
171
|
required.push(key);
|
|
132
172
|
}
|
|
133
173
|
}
|
|
134
|
-
|
|
174
|
+
const result = {
|
|
135
175
|
type: 'object',
|
|
136
176
|
properties,
|
|
137
177
|
required: required.length > 0 ? required : undefined,
|
|
138
178
|
additionalProperties: false
|
|
139
179
|
};
|
|
180
|
+
this.applyDescription(result, schema);
|
|
181
|
+
return result;
|
|
140
182
|
}
|
|
141
183
|
return this.zodTypeToJsonSchema(schema);
|
|
142
184
|
}
|
|
@@ -144,14 +186,12 @@ class Tool {
|
|
|
144
186
|
* Converts individual Zod types to JSON Schema
|
|
145
187
|
*/
|
|
146
188
|
zodTypeToJsonSchema(zodType) {
|
|
147
|
-
|
|
189
|
+
const typeName = this.getZodTypeName(zodType);
|
|
190
|
+
if (zodType instanceof zod_1.z.ZodString || typeName === 'ZodString') {
|
|
148
191
|
const result = { type: 'string' };
|
|
149
|
-
|
|
150
|
-
if (zodType._def.description) {
|
|
151
|
-
result.description = zodType._def.description;
|
|
152
|
-
}
|
|
192
|
+
this.applyDescription(result, zodType);
|
|
153
193
|
// Add constraints
|
|
154
|
-
const checks = zodType
|
|
194
|
+
const checks = this.getZodDef(zodType)['checks'] || [];
|
|
155
195
|
for (const check of checks) {
|
|
156
196
|
switch (check.kind) {
|
|
157
197
|
case 'min':
|
|
@@ -173,12 +213,10 @@ class Tool {
|
|
|
173
213
|
}
|
|
174
214
|
return result;
|
|
175
215
|
}
|
|
176
|
-
if (zodType instanceof zod_1.z.ZodNumber) {
|
|
216
|
+
if (zodType instanceof zod_1.z.ZodNumber || typeName === 'ZodNumber') {
|
|
177
217
|
const result = { type: 'number' };
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
const checks = zodType._def.checks || [];
|
|
218
|
+
this.applyDescription(result, zodType);
|
|
219
|
+
const checks = this.getZodDef(zodType)['checks'] || [];
|
|
182
220
|
for (const check of checks) {
|
|
183
221
|
switch (check.kind) {
|
|
184
222
|
case 'min':
|
|
@@ -194,22 +232,18 @@ class Tool {
|
|
|
194
232
|
}
|
|
195
233
|
return result;
|
|
196
234
|
}
|
|
197
|
-
if (zodType instanceof zod_1.z.ZodBoolean) {
|
|
235
|
+
if (zodType instanceof zod_1.z.ZodBoolean || typeName === 'ZodBoolean') {
|
|
198
236
|
const result = { type: 'boolean' };
|
|
199
|
-
|
|
200
|
-
result.description = zodType._def.description;
|
|
201
|
-
}
|
|
237
|
+
this.applyDescription(result, zodType);
|
|
202
238
|
return result;
|
|
203
239
|
}
|
|
204
|
-
if (zodType instanceof zod_1.z.ZodArray) {
|
|
240
|
+
if (zodType instanceof zod_1.z.ZodArray || typeName === 'ZodArray') {
|
|
205
241
|
const result = {
|
|
206
242
|
type: 'array',
|
|
207
|
-
items: this.zodTypeToJsonSchema(zodType
|
|
243
|
+
items: this.zodTypeToJsonSchema(this.getZodDef(zodType)['type'])
|
|
208
244
|
};
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
const checks = zodType._def.checks || [];
|
|
245
|
+
this.applyDescription(result, zodType);
|
|
246
|
+
const checks = this.getZodDef(zodType)['checks'] || [];
|
|
213
247
|
for (const check of checks) {
|
|
214
248
|
switch (check.kind) {
|
|
215
249
|
case 'min':
|
|
@@ -222,48 +256,45 @@ class Tool {
|
|
|
222
256
|
}
|
|
223
257
|
return result;
|
|
224
258
|
}
|
|
225
|
-
if (zodType instanceof zod_1.z.ZodEnum) {
|
|
259
|
+
if (zodType instanceof zod_1.z.ZodEnum || typeName === 'ZodEnum') {
|
|
226
260
|
const result = {
|
|
227
261
|
type: 'string',
|
|
228
|
-
enum: zodType
|
|
262
|
+
enum: this.getZodDef(zodType)['values']
|
|
229
263
|
};
|
|
230
|
-
|
|
231
|
-
result.description = zodType._def.description;
|
|
232
|
-
}
|
|
264
|
+
this.applyDescription(result, zodType);
|
|
233
265
|
return result;
|
|
234
266
|
}
|
|
235
|
-
if (zodType instanceof zod_1.z.ZodLiteral) {
|
|
267
|
+
if (zodType instanceof zod_1.z.ZodLiteral || typeName === 'ZodLiteral') {
|
|
268
|
+
const value = this.getZodDef(zodType)['value'];
|
|
236
269
|
const result = {
|
|
237
|
-
type: typeof
|
|
238
|
-
enum: [
|
|
270
|
+
type: typeof value,
|
|
271
|
+
enum: [value]
|
|
239
272
|
};
|
|
240
|
-
|
|
241
|
-
result.description = zodType._def.description;
|
|
242
|
-
}
|
|
273
|
+
this.applyDescription(result, zodType);
|
|
243
274
|
return result;
|
|
244
275
|
}
|
|
245
|
-
if (zodType instanceof zod_1.z.ZodUnion) {
|
|
246
|
-
const options = zodType
|
|
276
|
+
if (zodType instanceof zod_1.z.ZodUnion || typeName === 'ZodUnion') {
|
|
277
|
+
const options = this.getZodDef(zodType)['options'] || [];
|
|
247
278
|
const anyOf = options.map((option) => this.zodTypeToJsonSchema(option));
|
|
248
279
|
const result = { anyOf };
|
|
249
|
-
|
|
250
|
-
result.description = zodType._def.description;
|
|
251
|
-
}
|
|
280
|
+
this.applyDescription(result, zodType);
|
|
252
281
|
return result;
|
|
253
282
|
}
|
|
254
|
-
if (zodType instanceof zod_1.z.ZodOptional) {
|
|
255
|
-
return this.zodTypeToJsonSchema(zodType
|
|
283
|
+
if (zodType instanceof zod_1.z.ZodOptional || typeName === 'ZodOptional') {
|
|
284
|
+
return this.withDescriptionFrom(this.zodTypeToJsonSchema(this.getZodDef(zodType)['innerType']), zodType);
|
|
256
285
|
}
|
|
257
|
-
if (zodType instanceof zod_1.z.ZodNullable) {
|
|
258
|
-
const innerSchema = this.zodTypeToJsonSchema(zodType
|
|
259
|
-
|
|
286
|
+
if (zodType instanceof zod_1.z.ZodNullable || typeName === 'ZodNullable') {
|
|
287
|
+
const innerSchema = this.zodTypeToJsonSchema(this.getZodDef(zodType)['innerType']);
|
|
288
|
+
const result = {
|
|
260
289
|
anyOf: [
|
|
261
290
|
innerSchema,
|
|
262
291
|
{ type: 'null' }
|
|
263
292
|
]
|
|
264
293
|
};
|
|
294
|
+
this.applyDescription(result, zodType);
|
|
295
|
+
return result;
|
|
265
296
|
}
|
|
266
|
-
if (zodType instanceof zod_1.z.ZodObject) {
|
|
297
|
+
if (zodType instanceof zod_1.z.ZodObject || typeName === 'ZodObject') {
|
|
267
298
|
return this.zodSchemaToJsonSchema(zodType);
|
|
268
299
|
}
|
|
269
300
|
// Fallback for unknown types
|
|
@@ -17,6 +17,7 @@ export declare class AgentStep implements AgentStepInterface {
|
|
|
17
17
|
*/
|
|
18
18
|
executeStep(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<AgentStepOutput>;
|
|
19
19
|
private generateResponse;
|
|
20
|
+
private extractCompletion;
|
|
20
21
|
/**
|
|
21
22
|
* Update LLM configuration
|
|
22
23
|
*/
|
|
@@ -36,11 +36,11 @@ class AgentStep {
|
|
|
36
36
|
message: (0, promptContext_1.buildInferenceParams)(preparedMessage),
|
|
37
37
|
};
|
|
38
38
|
const rawLLMResponse = await this.generateResponse(actualMessageSentToLLM.message);
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
let modifiedMessage = (0, promptContext_1.appendTranscriptMessages)(preparedMessage,
|
|
39
|
+
const assistantResponseItems = ((_a = rawLLMResponse.items) !== null && _a !== void 0 ? _a : [])
|
|
40
|
+
.filter((item) => (((item === null || item === void 0 ? void 0 : item.type) === 'message' && item.role === 'assistant') ||
|
|
41
|
+
(item === null || item === void 0 ? void 0 : item.type) === 'function_call' ||
|
|
42
|
+
(item === null || item === void 0 ? void 0 : item.type) === 'tool_search_call'));
|
|
43
|
+
let modifiedMessage = (0, promptContext_1.appendTranscriptMessages)(preparedMessage, assistantResponseItems);
|
|
44
44
|
for (const postInferenceProcessor of this.postInferenceProcessors) {
|
|
45
45
|
try {
|
|
46
46
|
modifiedMessage = await postInferenceProcessor.modify(actualMessageSentToLLM, rawLLMResponse, modifiedMessage);
|
|
@@ -63,9 +63,14 @@ class AgentStep {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
async generateResponse(messageForLLM) {
|
|
66
|
-
var _a, _b, _c, _d;
|
|
66
|
+
var _a, _b, _c, _d, _e;
|
|
67
67
|
const response = await codeboltjs_1.default.llm.inference(messageForLLM);
|
|
68
|
-
const completion = response
|
|
68
|
+
const completion = this.extractCompletion(response);
|
|
69
|
+
if (!completion) {
|
|
70
|
+
const responseType = (response === null || response === void 0 ? void 0 : response.type) || 'unknown';
|
|
71
|
+
const responseMessage = (response === null || response === void 0 ? void 0 : response.message) || ((_a = response === null || response === void 0 ? void 0 : response.error) === null || _a === void 0 ? void 0 : _a.message) || 'No completion returned from LLM service';
|
|
72
|
+
throw new Error(`LLM response did not include completion data (${responseType}): ${responseMessage}`);
|
|
73
|
+
}
|
|
69
74
|
// Add tokenLimit and maxOutputTokens to completion object if available in response
|
|
70
75
|
if (completion) {
|
|
71
76
|
// Check if tokenLimit exists at response level or in completion
|
|
@@ -82,21 +87,44 @@ class AgentStep {
|
|
|
82
87
|
completion.compactionRequired = response.compactionRequired;
|
|
83
88
|
}
|
|
84
89
|
// Also check inside completion object itself (from LLM provider response)
|
|
85
|
-
if (((
|
|
90
|
+
if (((_b = completion.completion) === null || _b === void 0 ? void 0 : _b.tokenLimit) !== undefined) {
|
|
86
91
|
completion.tokenLimit = completion.completion.tokenLimit;
|
|
87
92
|
}
|
|
88
|
-
if (((
|
|
93
|
+
if (((_c = completion.completion) === null || _c === void 0 ? void 0 : _c.maxOutputTokens) !== undefined) {
|
|
89
94
|
completion.maxOutputTokens = completion.completion.maxOutputTokens;
|
|
90
95
|
}
|
|
91
|
-
if (((
|
|
96
|
+
if (((_d = completion.completion) === null || _d === void 0 ? void 0 : _d.contextCompaction) !== undefined) {
|
|
92
97
|
completion.contextCompaction = completion.completion.contextCompaction;
|
|
93
98
|
}
|
|
94
|
-
if (((
|
|
99
|
+
if (((_e = completion.completion) === null || _e === void 0 ? void 0 : _e.compactionRequired) !== undefined) {
|
|
95
100
|
completion.compactionRequired = completion.completion.compactionRequired;
|
|
96
101
|
}
|
|
97
102
|
}
|
|
98
103
|
return completion;
|
|
99
104
|
}
|
|
105
|
+
extractCompletion(response) {
|
|
106
|
+
if (!response || typeof response !== 'object') {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
if (response.completion && typeof response.completion === 'object') {
|
|
110
|
+
return response.completion;
|
|
111
|
+
}
|
|
112
|
+
if (Array.isArray(response.items) || typeof response.output_text === 'string') {
|
|
113
|
+
return {
|
|
114
|
+
...response,
|
|
115
|
+
items: Array.isArray(response.items) ? response.items : [],
|
|
116
|
+
output_text: response.output_text || response.message || response.content || '',
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (typeof response.message === 'string' || typeof response.content === 'string') {
|
|
120
|
+
return {
|
|
121
|
+
...response,
|
|
122
|
+
items: [],
|
|
123
|
+
output_text: response.message || response.content || '',
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
100
128
|
/**
|
|
101
129
|
* Update LLM configuration
|
|
102
130
|
*/
|
|
@@ -8,9 +8,11 @@ export declare class InitialPromptGenerator implements InitialPromptGeneratorInt
|
|
|
8
8
|
private metaData;
|
|
9
9
|
private enableLogging;
|
|
10
10
|
private baseSystemPrompt?;
|
|
11
|
+
private initialPrompt?;
|
|
11
12
|
constructor(options?: {
|
|
12
13
|
processors?: MessageModifier[];
|
|
13
14
|
baseSystemPrompt?: string;
|
|
15
|
+
initialPrompt?: ProcessedMessage;
|
|
14
16
|
metaData?: Record<string, unknown>;
|
|
15
17
|
enableLogging?: boolean;
|
|
16
18
|
templating?: boolean;
|
|
@@ -18,17 +18,80 @@ const mergeFlagLists = (existing, mentioned) => {
|
|
|
18
18
|
};
|
|
19
19
|
const formatFlagContext = (flags, mentionedFlags) => {
|
|
20
20
|
const normalizedMentionedFlags = normalizeFlagList(mentionedFlags);
|
|
21
|
-
|
|
21
|
+
const userFlags = (flags === null || flags === void 0 ? void 0 : flags.user) || [];
|
|
22
|
+
const projectFlags = (flags === null || flags === void 0 ? void 0 : flags.project) || [];
|
|
23
|
+
const threadFlags = mergeFlagLists(flags === null || flags === void 0 ? void 0 : flags.thread, normalizedMentionedFlags);
|
|
24
|
+
const effectiveFlags = mergeFlagLists(flags === null || flags === void 0 ? void 0 : flags.effective, normalizedMentionedFlags);
|
|
25
|
+
if (userFlags.length === 0 &&
|
|
26
|
+
projectFlags.length === 0 &&
|
|
27
|
+
threadFlags.length === 0 &&
|
|
28
|
+
effectiveFlags.length === 0) {
|
|
22
29
|
return null;
|
|
30
|
+
}
|
|
23
31
|
return [
|
|
24
32
|
'<flags>',
|
|
25
|
-
`user: ${formatFlagList(
|
|
26
|
-
`project: ${formatFlagList(
|
|
27
|
-
`thread: ${formatFlagList(
|
|
28
|
-
`effective: ${formatFlagList(
|
|
33
|
+
`user: ${formatFlagList(userFlags)}`,
|
|
34
|
+
`project: ${formatFlagList(projectFlags)}`,
|
|
35
|
+
`thread: ${formatFlagList(threadFlags)}`,
|
|
36
|
+
`effective: ${formatFlagList(effectiveFlags)}`,
|
|
29
37
|
'</flags>',
|
|
30
38
|
].join('\n');
|
|
31
39
|
};
|
|
40
|
+
const createImageUrlBlock = (mediaType, base64Data) => ({
|
|
41
|
+
type: 'image_url',
|
|
42
|
+
image_url: {
|
|
43
|
+
url: `data:${mediaType};base64,${base64Data}`,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
const normalizeImageAttachment = (image) => {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
if (!image)
|
|
49
|
+
return null;
|
|
50
|
+
if (typeof image === 'string') {
|
|
51
|
+
const dataUrlMatch = image.match(/^data:([^;,]+);base64,(.+)$/);
|
|
52
|
+
if (!dataUrlMatch)
|
|
53
|
+
return null;
|
|
54
|
+
const mediaType = dataUrlMatch[1];
|
|
55
|
+
const base64Data = dataUrlMatch[2];
|
|
56
|
+
if (!mediaType || !base64Data)
|
|
57
|
+
return null;
|
|
58
|
+
return createImageUrlBlock(mediaType, base64Data);
|
|
59
|
+
}
|
|
60
|
+
if (typeof image === 'object') {
|
|
61
|
+
const imageBlock = image;
|
|
62
|
+
if (imageBlock.type === 'image_url' &&
|
|
63
|
+
typeof ((_a = imageBlock.image_url) === null || _a === void 0 ? void 0 : _a.url) === 'string') {
|
|
64
|
+
return {
|
|
65
|
+
type: 'image_url',
|
|
66
|
+
image_url: {
|
|
67
|
+
url: imageBlock.image_url.url,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (imageBlock.type === 'image' &&
|
|
72
|
+
((_b = imageBlock.source) === null || _b === void 0 ? void 0 : _b.type) === 'base64' &&
|
|
73
|
+
typeof imageBlock.source.media_type === 'string' &&
|
|
74
|
+
typeof imageBlock.source.data === 'string') {
|
|
75
|
+
return createImageUrlBlock(imageBlock.source.media_type, imageBlock.source.data);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
};
|
|
80
|
+
const buildUserMessageContent = (text, uploadedImages) => {
|
|
81
|
+
const imageBlocks = (uploadedImages || [])
|
|
82
|
+
.map(normalizeImageAttachment)
|
|
83
|
+
.filter((image) => image !== null);
|
|
84
|
+
if (imageBlocks.length === 0) {
|
|
85
|
+
return text.trim();
|
|
86
|
+
}
|
|
87
|
+
return [
|
|
88
|
+
{
|
|
89
|
+
type: 'text',
|
|
90
|
+
text: text.trim() || 'Please use the attached image.',
|
|
91
|
+
},
|
|
92
|
+
...imageBlocks,
|
|
93
|
+
];
|
|
94
|
+
};
|
|
32
95
|
/**
|
|
33
96
|
* Initial prompt generator that combines message modifiers with unified processing
|
|
34
97
|
*/
|
|
@@ -42,6 +105,9 @@ class InitialPromptGenerator {
|
|
|
42
105
|
if (options.baseSystemPrompt !== undefined) {
|
|
43
106
|
this.baseSystemPrompt = options.baseSystemPrompt;
|
|
44
107
|
}
|
|
108
|
+
if (options.initialPrompt !== undefined) {
|
|
109
|
+
this.initialPrompt = options.initialPrompt;
|
|
110
|
+
}
|
|
45
111
|
}
|
|
46
112
|
/**
|
|
47
113
|
* Process and modify input messages using the message modifier pattern
|
|
@@ -51,24 +117,37 @@ class InitialPromptGenerator {
|
|
|
51
117
|
if (this.enableLogging) {
|
|
52
118
|
// console.log('[InitialPromptGenerator] Processing message:', input);
|
|
53
119
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
120
|
+
const isResumedPrompt = this.initialPrompt !== undefined;
|
|
121
|
+
let createdMessage = isResumedPrompt
|
|
122
|
+
? {
|
|
123
|
+
...this.initialPrompt,
|
|
124
|
+
metadata: {
|
|
125
|
+
...this.initialPrompt.metadata,
|
|
126
|
+
timestamp: new Date().toISOString(),
|
|
127
|
+
messageId: input.messageId,
|
|
128
|
+
threadId: input.threadId,
|
|
129
|
+
resumedPrompt: true,
|
|
130
|
+
},
|
|
63
131
|
}
|
|
64
|
-
|
|
132
|
+
: {
|
|
133
|
+
message: {
|
|
134
|
+
formatVersion: 'codebolt.llm.v2',
|
|
135
|
+
input: [],
|
|
136
|
+
tools: []
|
|
137
|
+
},
|
|
138
|
+
metadata: {
|
|
139
|
+
timestamp: new Date().toISOString(),
|
|
140
|
+
messageId: input.messageId,
|
|
141
|
+
threadId: input.threadId
|
|
142
|
+
}
|
|
143
|
+
};
|
|
65
144
|
createdMessage = (0, promptContext_1.syncProcessedMessageWithRuntimeContext)(createdMessage);
|
|
66
|
-
if (this.baseSystemPrompt !== undefined) {
|
|
145
|
+
if (!isResumedPrompt && this.baseSystemPrompt !== undefined) {
|
|
67
146
|
createdMessage = (0, promptContext_1.setSystemPrompt)(createdMessage, this.baseSystemPrompt);
|
|
68
147
|
}
|
|
69
148
|
createdMessage = (0, promptContext_1.appendTranscriptMessage)(createdMessage, {
|
|
70
149
|
role: 'user',
|
|
71
|
-
content: input.userMessage.
|
|
150
|
+
content: buildUserMessageContent(input.userMessage || '', input.uploadedImages),
|
|
72
151
|
});
|
|
73
152
|
const flagContext = formatFlagContext(input.flags, input.mentionedFlags);
|
|
74
153
|
if (flagContext) {
|
|
@@ -86,7 +165,7 @@ class InitialPromptGenerator {
|
|
|
86
165
|
console.error(`[InitialPromptGenerator] Error in message modifier:`, error);
|
|
87
166
|
}
|
|
88
167
|
}
|
|
89
|
-
|
|
168
|
+
const { todos } = await codeboltjs_1.default.todo.getAllIncompleteTodos();
|
|
90
169
|
if (todos && todos.length == 0) {
|
|
91
170
|
createdMessage = (0, promptContext_1.appendUserContextMessage)(createdMessage, {
|
|
92
171
|
role: 'user',
|
|
@@ -95,7 +174,7 @@ class InitialPromptGenerator {
|
|
|
95
174
|
}
|
|
96
175
|
if (this.enableLogging) {
|
|
97
176
|
// console.log('[InitialPromptGenerator] Processing completed:', {
|
|
98
|
-
// messageCount: createdMessage.message.
|
|
177
|
+
// messageCount: createdMessage.message.input.length,
|
|
99
178
|
// metadata: createdMessage.metadata
|
|
100
179
|
// });
|
|
101
180
|
}
|
|
@@ -130,7 +209,6 @@ class InitialPromptGenerator {
|
|
|
130
209
|
updateProcessors(processors) {
|
|
131
210
|
this.processors = processors;
|
|
132
211
|
}
|
|
133
|
-
;
|
|
134
212
|
getProcessors() {
|
|
135
213
|
return this.processors;
|
|
136
214
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ProcessedMessage } from '@codebolt/types/agent';
|
|
2
2
|
import type { LLMInferenceParams, MessageObject } from '@codebolt/types/sdk';
|
|
3
|
+
export declare function isGeneratedUserContextMessage(message: MessageObject): boolean;
|
|
3
4
|
export declare function syncProcessedMessageWithRuntimeContext(prompt: ProcessedMessage): ProcessedMessage;
|
|
4
5
|
export declare function reconcileRuntimePromptContext(prompt: ProcessedMessage): ProcessedMessage;
|
|
5
6
|
export declare function setSystemPrompt(prompt: ProcessedMessage, systemPrompt: string): ProcessedMessage;
|
|
@@ -10,4 +11,6 @@ export declare function appendTranscriptMessages(prompt: ProcessedMessage, messa
|
|
|
10
11
|
export declare function prependTranscriptMessages(prompt: ProcessedMessage, messages: MessageObject[]): ProcessedMessage;
|
|
11
12
|
export declare function replaceTranscriptMessages(prompt: ProcessedMessage, messages: MessageObject[]): ProcessedMessage;
|
|
12
13
|
export declare function getTranscriptMessages(prompt: ProcessedMessage): MessageObject[];
|
|
14
|
+
export declare function getCurrentUserMessage(prompt: ProcessedMessage): MessageObject | undefined;
|
|
15
|
+
export declare function updateCurrentUserMessage(prompt: ProcessedMessage, update: (message: MessageObject) => MessageObject): ProcessedMessage;
|
|
13
16
|
export declare function buildInferenceParams(prompt: ProcessedMessage): LLMInferenceParams;
|