@codebolt/agent 6.1.20 → 6.1.22
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 +1 -0
- 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 +8 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.js +150 -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/index.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/index.js +3 -1
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +9 -15
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +17 -20
- package/dist/processor-pieces/messageModifiers/toolManifestPromptModifier.d.ts +18 -0
- package/dist/processor-pieces/messageModifiers/toolManifestPromptModifier.js +57 -0
- 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 +28 -20
- 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 +139 -7
- package/dist/unified/agent/agent.d.ts +13 -0
- package/dist/unified/agent/agent.js +180 -19
- package/dist/unified/agent/tools.d.ts +14 -0
- package/dist/unified/agent/tools.js +82 -51
- package/dist/unified/base/agentStep.d.ts +2 -1
- package/dist/unified/base/agentStep.js +47 -16
- package/dist/unified/base/initialPromptGenerator.d.ts +2 -0
- package/dist/unified/base/initialPromptGenerator.js +42 -19
- package/dist/unified/base/promptContext.d.ts +3 -0
- package/dist/unified/base/promptContext.js +193 -15
- package/dist/unified/base/responseExecutor.d.ts +6 -0
- package/dist/unified/base/responseExecutor.js +256 -69
- package/dist/unified/index.d.ts +1 -0
- package/dist/unified/index.js +3 -1
- package/dist/unified/services/CompressionCoordinator.js +9 -9
- package/dist/unified/services/compaction/autoCompact.d.ts +2 -1
- package/dist/unified/services/compaction/autoCompact.js +19 -11
- package/dist/unified/services/compaction/compactionOrchestrator.d.ts +1 -0
- package/dist/unified/services/compaction/compactionOrchestrator.js +8 -0
- package/dist/unified/services/compaction/contextCollapse.d.ts +2 -1
- package/dist/unified/services/compaction/contextCollapse.js +17 -9
- package/dist/unified/services/compaction/reactiveCompact.d.ts +3 -0
- package/dist/unified/services/compaction/reactiveCompact.js +17 -8
- package/dist/unified/types/libTypes.d.ts +189 -10
- package/dist/unified/utils/agentToolLoader.d.ts +17 -1
- package/dist/unified/utils/agentToolLoader.js +182 -31
- package/package.json +5 -1
|
@@ -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
|
*/
|
|
@@ -24,7 +25,7 @@ export declare class AgentStep implements AgentStepInterface {
|
|
|
24
25
|
/**
|
|
25
26
|
* Get current LLM configuration
|
|
26
27
|
*/
|
|
27
|
-
getLLMConfig(): string;
|
|
28
|
+
getLLMConfig(): string | undefined;
|
|
28
29
|
updatePreInferenceProcessors(processors: PreInferenceProcessor[]): void;
|
|
29
30
|
getPreInferenceProcessors(): PreInferenceProcessor[];
|
|
30
31
|
updatePostInferenceProcessors(processors: PostInferenceProcessor[]): void;
|
|
@@ -13,7 +13,7 @@ class AgentStep {
|
|
|
13
13
|
constructor(options = {}) {
|
|
14
14
|
this.preInferenceProcessors = options.preInferenceProcessors || [];
|
|
15
15
|
this.postInferenceProcessors = options.postInferenceProcessors || [];
|
|
16
|
-
this.llmRole = options.llmRole
|
|
16
|
+
this.llmRole = options.llmRole;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Execute a single agent step
|
|
@@ -33,14 +33,17 @@ class AgentStep {
|
|
|
33
33
|
}
|
|
34
34
|
const actualMessageSentToLLM = {
|
|
35
35
|
...preparedMessage,
|
|
36
|
-
message:
|
|
36
|
+
message: {
|
|
37
|
+
...(0, promptContext_1.buildInferenceParams)(preparedMessage),
|
|
38
|
+
...(this.llmRole ? { llmrole: this.llmRole } : {}),
|
|
39
|
+
},
|
|
37
40
|
};
|
|
38
41
|
const rawLLMResponse = await this.generateResponse(actualMessageSentToLLM.message);
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
let modifiedMessage = (0, promptContext_1.appendTranscriptMessages)(preparedMessage,
|
|
42
|
+
const assistantResponseItems = ((_a = rawLLMResponse.items) !== null && _a !== void 0 ? _a : [])
|
|
43
|
+
.filter((item) => (((item === null || item === void 0 ? void 0 : item.type) === 'message' && item.role === 'assistant') ||
|
|
44
|
+
(item === null || item === void 0 ? void 0 : item.type) === 'function_call' ||
|
|
45
|
+
(item === null || item === void 0 ? void 0 : item.type) === 'tool_search_call'));
|
|
46
|
+
let modifiedMessage = (0, promptContext_1.appendTranscriptMessages)(preparedMessage, assistantResponseItems);
|
|
44
47
|
for (const postInferenceProcessor of this.postInferenceProcessors) {
|
|
45
48
|
try {
|
|
46
49
|
modifiedMessage = await postInferenceProcessor.modify(actualMessageSentToLLM, rawLLMResponse, modifiedMessage);
|
|
@@ -63,9 +66,15 @@ class AgentStep {
|
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
async generateResponse(messageForLLM) {
|
|
66
|
-
var _a, _b, _c, _d;
|
|
69
|
+
var _a, _b, _c, _d, _e;
|
|
70
|
+
console.log('[AgentStep] llm.inference payload:', messageForLLM);
|
|
67
71
|
const response = await codeboltjs_1.default.llm.inference(messageForLLM);
|
|
68
|
-
const completion = response
|
|
72
|
+
const completion = this.extractCompletion(response);
|
|
73
|
+
if (!completion) {
|
|
74
|
+
const responseType = (response === null || response === void 0 ? void 0 : response.type) || 'unknown';
|
|
75
|
+
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';
|
|
76
|
+
throw new Error(`LLM response did not include completion data (${responseType}): ${responseMessage}`);
|
|
77
|
+
}
|
|
69
78
|
// Add tokenLimit and maxOutputTokens to completion object if available in response
|
|
70
79
|
if (completion) {
|
|
71
80
|
// Check if tokenLimit exists at response level or in completion
|
|
@@ -82,26 +91,50 @@ class AgentStep {
|
|
|
82
91
|
completion.compactionRequired = response.compactionRequired;
|
|
83
92
|
}
|
|
84
93
|
// Also check inside completion object itself (from LLM provider response)
|
|
85
|
-
if (((
|
|
94
|
+
if (((_b = completion.completion) === null || _b === void 0 ? void 0 : _b.tokenLimit) !== undefined) {
|
|
86
95
|
completion.tokenLimit = completion.completion.tokenLimit;
|
|
87
96
|
}
|
|
88
|
-
if (((
|
|
97
|
+
if (((_c = completion.completion) === null || _c === void 0 ? void 0 : _c.maxOutputTokens) !== undefined) {
|
|
89
98
|
completion.maxOutputTokens = completion.completion.maxOutputTokens;
|
|
90
99
|
}
|
|
91
|
-
if (((
|
|
100
|
+
if (((_d = completion.completion) === null || _d === void 0 ? void 0 : _d.contextCompaction) !== undefined) {
|
|
92
101
|
completion.contextCompaction = completion.completion.contextCompaction;
|
|
93
102
|
}
|
|
94
|
-
if (((
|
|
103
|
+
if (((_e = completion.completion) === null || _e === void 0 ? void 0 : _e.compactionRequired) !== undefined) {
|
|
95
104
|
completion.compactionRequired = completion.completion.compactionRequired;
|
|
96
105
|
}
|
|
97
106
|
}
|
|
98
107
|
return completion;
|
|
99
108
|
}
|
|
109
|
+
extractCompletion(response) {
|
|
110
|
+
if (!response || typeof response !== 'object') {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
if (response.completion && typeof response.completion === 'object') {
|
|
114
|
+
return response.completion;
|
|
115
|
+
}
|
|
116
|
+
if (Array.isArray(response.items) || typeof response.output_text === 'string') {
|
|
117
|
+
return {
|
|
118
|
+
...response,
|
|
119
|
+
items: Array.isArray(response.items) ? response.items : [],
|
|
120
|
+
output_text: response.output_text || response.message || response.content || '',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (typeof response.message === 'string' || typeof response.content === 'string') {
|
|
124
|
+
return {
|
|
125
|
+
...response,
|
|
126
|
+
items: [],
|
|
127
|
+
output_text: response.message || response.content || '',
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
100
132
|
/**
|
|
101
133
|
* Update LLM configuration
|
|
102
134
|
*/
|
|
103
135
|
setLLMConfig(config) {
|
|
104
|
-
|
|
136
|
+
const normalized = config.trim();
|
|
137
|
+
this.llmRole = normalized ? normalized : undefined;
|
|
105
138
|
}
|
|
106
139
|
/**
|
|
107
140
|
* Get current LLM configuration
|
|
@@ -112,14 +145,12 @@ class AgentStep {
|
|
|
112
145
|
updatePreInferenceProcessors(processors) {
|
|
113
146
|
this.preInferenceProcessors = processors;
|
|
114
147
|
}
|
|
115
|
-
;
|
|
116
148
|
getPreInferenceProcessors() {
|
|
117
149
|
return this.preInferenceProcessors;
|
|
118
150
|
}
|
|
119
151
|
updatePostInferenceProcessors(processors) {
|
|
120
152
|
this.postInferenceProcessors = processors;
|
|
121
153
|
}
|
|
122
|
-
;
|
|
123
154
|
getPostInferenceProcessors() {
|
|
124
155
|
return this.postInferenceProcessors;
|
|
125
156
|
}
|
|
@@ -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,14 +18,22 @@ 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
|
};
|
|
@@ -97,6 +105,9 @@ class InitialPromptGenerator {
|
|
|
97
105
|
if (options.baseSystemPrompt !== undefined) {
|
|
98
106
|
this.baseSystemPrompt = options.baseSystemPrompt;
|
|
99
107
|
}
|
|
108
|
+
if (options.initialPrompt !== undefined) {
|
|
109
|
+
this.initialPrompt = options.initialPrompt;
|
|
110
|
+
}
|
|
100
111
|
}
|
|
101
112
|
/**
|
|
102
113
|
* Process and modify input messages using the message modifier pattern
|
|
@@ -106,19 +117,32 @@ class InitialPromptGenerator {
|
|
|
106
117
|
if (this.enableLogging) {
|
|
107
118
|
// console.log('[InitialPromptGenerator] Processing message:', input);
|
|
108
119
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
+
},
|
|
118
131
|
}
|
|
119
|
-
|
|
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
|
+
};
|
|
120
144
|
createdMessage = (0, promptContext_1.syncProcessedMessageWithRuntimeContext)(createdMessage);
|
|
121
|
-
if (this.baseSystemPrompt !== undefined) {
|
|
145
|
+
if (!isResumedPrompt && this.baseSystemPrompt !== undefined) {
|
|
122
146
|
createdMessage = (0, promptContext_1.setSystemPrompt)(createdMessage, this.baseSystemPrompt);
|
|
123
147
|
}
|
|
124
148
|
createdMessage = (0, promptContext_1.appendTranscriptMessage)(createdMessage, {
|
|
@@ -141,7 +165,7 @@ class InitialPromptGenerator {
|
|
|
141
165
|
console.error(`[InitialPromptGenerator] Error in message modifier:`, error);
|
|
142
166
|
}
|
|
143
167
|
}
|
|
144
|
-
|
|
168
|
+
const { todos } = await codeboltjs_1.default.todo.getAllIncompleteTodos();
|
|
145
169
|
if (todos && todos.length == 0) {
|
|
146
170
|
createdMessage = (0, promptContext_1.appendUserContextMessage)(createdMessage, {
|
|
147
171
|
role: 'user',
|
|
@@ -150,7 +174,7 @@ class InitialPromptGenerator {
|
|
|
150
174
|
}
|
|
151
175
|
if (this.enableLogging) {
|
|
152
176
|
// console.log('[InitialPromptGenerator] Processing completed:', {
|
|
153
|
-
// messageCount: createdMessage.message.
|
|
177
|
+
// messageCount: createdMessage.message.input.length,
|
|
154
178
|
// metadata: createdMessage.metadata
|
|
155
179
|
// });
|
|
156
180
|
}
|
|
@@ -185,7 +209,6 @@ class InitialPromptGenerator {
|
|
|
185
209
|
updateProcessors(processors) {
|
|
186
210
|
this.processors = processors;
|
|
187
211
|
}
|
|
188
|
-
;
|
|
189
212
|
getProcessors() {
|
|
190
213
|
return this.processors;
|
|
191
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;
|