@codebolt/agent 6.1.21 → 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/chatHistoryMessageModifier.d.ts +2 -1
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.js +24 -9
- package/dist/processor-pieces/messageModifiers/index.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/index.js +3 -1
- package/dist/processor-pieces/messageModifiers/toolManifestPromptModifier.d.ts +18 -0
- package/dist/processor-pieces/messageModifiers/toolManifestPromptModifier.js +57 -0
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +13 -5
- package/dist/types/libFunctionTypes.d.ts +137 -10
- package/dist/unified/agent/agent.d.ts +3 -0
- package/dist/unified/agent/agent.js +14 -4
- package/dist/unified/base/agentStep.d.ts +1 -1
- package/dist/unified/base/agentStep.js +8 -5
- package/dist/unified/base/responseExecutor.js +49 -26
- package/dist/unified/index.d.ts +1 -0
- package/dist/unified/index.js +3 -1
- package/dist/unified/services/compaction/autoCompact.d.ts +2 -1
- package/dist/unified/services/compaction/autoCompact.js +14 -6
- 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 +15 -7
- package/dist/unified/services/compaction/reactiveCompact.d.ts +3 -0
- package/dist/unified/services/compaction/reactiveCompact.js +12 -3
- package/dist/unified/types/libTypes.d.ts +187 -14
- package/dist/unified/utils/agentToolLoader.d.ts +17 -1
- package/dist/unified/utils/agentToolLoader.js +166 -20
- package/package.json +1 -1
|
@@ -56,6 +56,26 @@ function extractDiscoveredToolSchemas(content) {
|
|
|
56
56
|
.map(normalizeDiscoveredToolSchema)
|
|
57
57
|
.filter((schema) => !!schema);
|
|
58
58
|
}
|
|
59
|
+
function isToolSearchOutput(content) {
|
|
60
|
+
return !!content &&
|
|
61
|
+
typeof content === 'object' &&
|
|
62
|
+
!Array.isArray(content) &&
|
|
63
|
+
content.type === 'tool_search_output';
|
|
64
|
+
}
|
|
65
|
+
function normalizeToolSearchOutput(content, toolCallId) {
|
|
66
|
+
const contentCallId = content['call_id'];
|
|
67
|
+
const contentStatus = content['status'];
|
|
68
|
+
return {
|
|
69
|
+
...content,
|
|
70
|
+
type: 'tool_search_output',
|
|
71
|
+
call_id: typeof contentCallId === 'string' && contentCallId.length > 0
|
|
72
|
+
? contentCallId
|
|
73
|
+
: toolCallId,
|
|
74
|
+
status: typeof contentStatus === 'string' && contentStatus.length > 0
|
|
75
|
+
? contentStatus
|
|
76
|
+
: 'completed',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
59
79
|
class ResponseExecutor {
|
|
60
80
|
constructor(options) {
|
|
61
81
|
this.preToolCallProcessors = [];
|
|
@@ -253,16 +273,8 @@ class ResponseExecutor {
|
|
|
253
273
|
return [
|
|
254
274
|
...toolExecution.toolResults.map((toolResult) => {
|
|
255
275
|
const content = toolResult.content;
|
|
256
|
-
if (content
|
|
257
|
-
|
|
258
|
-
!Array.isArray(content) &&
|
|
259
|
-
content.type === 'tool_search_output') {
|
|
260
|
-
return {
|
|
261
|
-
...content,
|
|
262
|
-
type: 'tool_search_output',
|
|
263
|
-
call_id: content.call_id || toolResult.tool_call_id,
|
|
264
|
-
status: content.status || 'completed',
|
|
265
|
-
};
|
|
276
|
+
if (isToolSearchOutput(content)) {
|
|
277
|
+
return normalizeToolSearchOutput(content, toolResult.tool_call_id);
|
|
266
278
|
}
|
|
267
279
|
return {
|
|
268
280
|
type: 'function_call_output',
|
|
@@ -467,6 +479,9 @@ class ResponseExecutor {
|
|
|
467
479
|
userMessage: String(toolCall.toolInput['task'] || toolCall.toolInput['userMessage'] || ''),
|
|
468
480
|
selectedAgent: toolCall.toolInput['selectedAgent'],
|
|
469
481
|
isGrouped: Boolean(toolCall.toolInput['isGrouped']),
|
|
482
|
+
...(toolCall.toolInput['llm'] && typeof toolCall.toolInput['llm'] === 'object'
|
|
483
|
+
? { llm: toolCall.toolInput['llm'] }
|
|
484
|
+
: {}),
|
|
470
485
|
...(typeof toolCall.toolInput['groupId'] === 'string'
|
|
471
486
|
? { groupId: toolCall.toolInput['groupId'] }
|
|
472
487
|
: {}),
|
|
@@ -475,7 +490,9 @@ class ResponseExecutor {
|
|
|
475
490
|
}
|
|
476
491
|
else if (toolCall.toolName.startsWith('subagent--')) {
|
|
477
492
|
const task = toolCall.toolInput['task'];
|
|
478
|
-
await codeboltjs_1.default.agent.startAgent(toolCall.toolName.replace('subagent--', ''), typeof task === 'string' ? task : JSON.stringify(task)
|
|
493
|
+
await codeboltjs_1.default.agent.startAgent(toolCall.toolName.replace('subagent--', ''), typeof task === 'string' ? task : JSON.stringify(task), toolCall.toolInput['llm'] && typeof toolCall.toolInput['llm'] === 'object'
|
|
494
|
+
? { llm: toolCall.toolInput['llm'] }
|
|
495
|
+
: undefined);
|
|
479
496
|
resultTuple = [false, 'tool result is successful'];
|
|
480
497
|
}
|
|
481
498
|
else {
|
|
@@ -505,7 +522,7 @@ class ResponseExecutor {
|
|
|
505
522
|
}
|
|
506
523
|
}
|
|
507
524
|
async executeTool(toolName, toolInput, input) {
|
|
508
|
-
var _a, _b
|
|
525
|
+
var _a, _b;
|
|
509
526
|
const executionToolName = (0, agentToolLoader_1.resolveToolExecutionName)(toolName);
|
|
510
527
|
const localTool = this.localToolsByExecutionName.get(executionToolName);
|
|
511
528
|
if (localTool) {
|
|
@@ -521,15 +538,17 @@ class ResponseExecutor {
|
|
|
521
538
|
}
|
|
522
539
|
return [false, (_a = localResult.result) !== null && _a !== void 0 ? _a : ''];
|
|
523
540
|
}
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
541
|
+
const toolGateway = codeboltjs_1.default.tools;
|
|
542
|
+
if (typeof (toolGateway === null || toolGateway === void 0 ? void 0 : toolGateway.execute) === 'function') {
|
|
543
|
+
const response = await toolGateway.execute(executionToolName, toolInput);
|
|
544
|
+
const data = (_b = response.data) !== null && _b !== void 0 ? _b : response.result;
|
|
545
|
+
if (Array.isArray(data) && data.length >= 2) {
|
|
546
|
+
const [didUserReject, content] = data;
|
|
547
|
+
return [Boolean(didUserReject), content];
|
|
548
|
+
}
|
|
549
|
+
return [false, data];
|
|
531
550
|
}
|
|
532
|
-
|
|
551
|
+
throw new Error('codebolt.tools.execute is required for runtime tool execution.');
|
|
533
552
|
}
|
|
534
553
|
parseToolResult(tool_call_id, content) {
|
|
535
554
|
let parsedStructuredContent = content;
|
|
@@ -556,11 +575,8 @@ class ResponseExecutor {
|
|
|
556
575
|
catch {
|
|
557
576
|
// Preserve the raw tool result when it is not JSON.
|
|
558
577
|
}
|
|
559
|
-
const contentForModel = (parsedStructuredContent
|
|
560
|
-
|
|
561
|
-
!Array.isArray(parsedStructuredContent) &&
|
|
562
|
-
parsedStructuredContent.type === 'tool_search_output')
|
|
563
|
-
? parsedStructuredContent
|
|
578
|
+
const contentForModel = isToolSearchOutput(parsedStructuredContent)
|
|
579
|
+
? normalizeToolSearchOutput(parsedStructuredContent, tool_call_id)
|
|
564
580
|
: serializedContent;
|
|
565
581
|
return {
|
|
566
582
|
role: 'tool',
|
|
@@ -594,6 +610,9 @@ class ResponseExecutor {
|
|
|
594
610
|
const isToolSearch = toolName === 'tool_search' ||
|
|
595
611
|
toolName === 'codebolt--tool_search' ||
|
|
596
612
|
toolName.endsWith('--tool_search') ||
|
|
613
|
+
toolName === 'get_available_tools_manifest' ||
|
|
614
|
+
toolName === 'codebolt--get_available_tools_manifest' ||
|
|
615
|
+
toolName.endsWith('--get_available_tools_manifest') ||
|
|
597
616
|
toolName === 'search_mcp_tool' ||
|
|
598
617
|
toolName === 'codebolt--search_mcp_tool' ||
|
|
599
618
|
toolName.endsWith('--search_mcp_tool') ||
|
|
@@ -616,7 +635,11 @@ class ResponseExecutor {
|
|
|
616
635
|
const rawName = schemaFunction === null || schemaFunction === void 0 ? void 0 : schemaFunction.name;
|
|
617
636
|
if (!rawName)
|
|
618
637
|
continue;
|
|
619
|
-
const
|
|
638
|
+
const isLocalToolName = this.localToolsByExecutionName.has(rawName) ||
|
|
639
|
+
this.localToolsByExecutionName.has((0, agentToolLoader_1.resolveToolExecutionName)(rawName));
|
|
640
|
+
const prefixedName = rawName.includes('--') || isLocalToolName || existingToolNames.has(rawName)
|
|
641
|
+
? rawName
|
|
642
|
+
: `codebolt--${rawName}`;
|
|
620
643
|
if (existingToolNames.has(prefixedName))
|
|
621
644
|
continue;
|
|
622
645
|
const prefixedSchema = {
|
package/dist/unified/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export { CompressionCoordinator, type CompressionCoordinatorOptions, type Compre
|
|
|
19
19
|
export { Agent, createAgent, type AgentOptions, type AgentRunResult, type AgentRunOptions, type AgentRunState, type CreateAgentOptions } from './agent/agent';
|
|
20
20
|
export { Tool, createTool } from './agent/tools';
|
|
21
21
|
export { Workflow } from './agent/workflow';
|
|
22
|
+
export { listAgentRuntimeTools, type ToolSourceType, type RuntimeToolDescriptor, } from './utils/agentToolLoader';
|
|
22
23
|
export { type OpenAIMessage, type OpenAITool, type ToolResult, type CodeboltAPI, type AgentExecutionResult, type StreamChunk, type StreamCallback } from './types/libTypes';
|
|
23
24
|
export { type LLMConfig } from './types/libTypes';
|
|
24
25
|
export { CompactionOrchestrator, type CompactionPipelineResult, } from './services/compaction/compactionOrchestrator';
|
package/dist/unified/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* The framework is designed to be modular, extensible, and easy to use.
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.TokenEstimator = exports.PostCompactCleanup = exports.ReactiveCompact = exports.AutoCompact = exports.ContextCollapse = exports.MicroCompact = exports.SnipCompact = exports.CompactionOrchestrator = exports.Workflow = exports.createTool = exports.Tool = exports.createAgent = exports.Agent = exports.CompressionCoordinator = exports.LoopType = exports.LoopDetectionService = exports.ResponseExecutor = exports.AgentStep = exports.InitialPromptGenerator = exports.createDefaultMessageProcessor = exports.UnifiedToolExecutionError = exports.UnifiedResponseExecutionError = exports.UnifiedStepExecutionError = exports.UnifiedMessageProcessingError = exports.UnifiedAgentError = void 0;
|
|
13
|
+
exports.TokenEstimator = exports.PostCompactCleanup = exports.ReactiveCompact = exports.AutoCompact = exports.ContextCollapse = exports.MicroCompact = exports.SnipCompact = exports.CompactionOrchestrator = exports.listAgentRuntimeTools = exports.Workflow = exports.createTool = exports.Tool = exports.createAgent = exports.Agent = exports.CompressionCoordinator = exports.LoopType = exports.LoopDetectionService = exports.ResponseExecutor = exports.AgentStep = exports.InitialPromptGenerator = exports.createDefaultMessageProcessor = exports.UnifiedToolExecutionError = exports.UnifiedResponseExecutionError = exports.UnifiedStepExecutionError = exports.UnifiedMessageProcessingError = exports.UnifiedAgentError = void 0;
|
|
14
14
|
// Error types
|
|
15
15
|
var types_1 = require("./types/types");
|
|
16
16
|
Object.defineProperty(exports, "UnifiedAgentError", { enumerable: true, get: function () { return types_1.UnifiedAgentError; } });
|
|
@@ -41,6 +41,8 @@ Object.defineProperty(exports, "Tool", { enumerable: true, get: function () { re
|
|
|
41
41
|
Object.defineProperty(exports, "createTool", { enumerable: true, get: function () { return tools_1.createTool; } });
|
|
42
42
|
var workflow_1 = require("./agent/workflow");
|
|
43
43
|
Object.defineProperty(exports, "Workflow", { enumerable: true, get: function () { return workflow_1.Workflow; } });
|
|
44
|
+
var agentToolLoader_1 = require("./utils/agentToolLoader");
|
|
45
|
+
Object.defineProperty(exports, "listAgentRuntimeTools", { enumerable: true, get: function () { return agentToolLoader_1.listAgentRuntimeTools; } });
|
|
44
46
|
// Workflow step factories
|
|
45
47
|
// Multi-layer compaction system
|
|
46
48
|
var compactionOrchestrator_1 = require("./services/compaction/compactionOrchestrator");
|
|
@@ -23,7 +23,7 @@ export interface AutoCompactOptions {
|
|
|
23
23
|
modelTokenLimit?: number;
|
|
24
24
|
/** Fraction of recent history to preserve after compression (default: 0.3) */
|
|
25
25
|
preserveThreshold?: number;
|
|
26
|
-
/** LLM role for summarization calls
|
|
26
|
+
/** LLM role for summarization calls */
|
|
27
27
|
llmRole?: string;
|
|
28
28
|
/** Enable logging (default: false) */
|
|
29
29
|
enableLogging?: boolean;
|
|
@@ -40,6 +40,7 @@ export declare class AutoCompact implements CompactionLayer {
|
|
|
40
40
|
private consecutiveFailures;
|
|
41
41
|
private tracking;
|
|
42
42
|
constructor(options?: AutoCompactOptions);
|
|
43
|
+
private normalizeLLMRole;
|
|
43
44
|
shouldApply(ctx: CompactionContext): boolean;
|
|
44
45
|
apply(ctx: CompactionContext): Promise<CompactionContext>;
|
|
45
46
|
reset(): void;
|
|
@@ -25,7 +25,7 @@ const DEFAULT_MAX_CONSECUTIVE_FAILURES = 3;
|
|
|
25
25
|
const DEFAULT_MODEL_TOKEN_LIMIT = 128000;
|
|
26
26
|
class AutoCompact {
|
|
27
27
|
constructor(options) {
|
|
28
|
-
var _a, _b, _c, _d, _e
|
|
28
|
+
var _a, _b, _c, _d, _e;
|
|
29
29
|
this.name = 'auto';
|
|
30
30
|
this.consecutiveFailures = 0;
|
|
31
31
|
this.options = {
|
|
@@ -33,10 +33,14 @@ class AutoCompact {
|
|
|
33
33
|
maxConsecutiveFailures: (_b = options === null || options === void 0 ? void 0 : options.maxConsecutiveFailures) !== null && _b !== void 0 ? _b : DEFAULT_MAX_CONSECUTIVE_FAILURES,
|
|
34
34
|
modelTokenLimit: (_c = options === null || options === void 0 ? void 0 : options.modelTokenLimit) !== null && _c !== void 0 ? _c : DEFAULT_MODEL_TOKEN_LIMIT,
|
|
35
35
|
preserveThreshold: (_d = options === null || options === void 0 ? void 0 : options.preserveThreshold) !== null && _d !== void 0 ? _d : 0.3,
|
|
36
|
-
llmRole: (
|
|
37
|
-
enableLogging: (
|
|
36
|
+
llmRole: this.normalizeLLMRole(options === null || options === void 0 ? void 0 : options.llmRole),
|
|
37
|
+
enableLogging: (_e = options === null || options === void 0 ? void 0 : options.enableLogging) !== null && _e !== void 0 ? _e : false,
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
+
normalizeLLMRole(llmRole) {
|
|
41
|
+
const normalized = llmRole === null || llmRole === void 0 ? void 0 : llmRole.trim();
|
|
42
|
+
return normalized ? normalized : undefined;
|
|
43
|
+
}
|
|
40
44
|
shouldApply(ctx) {
|
|
41
45
|
// Don't auto-compact if context collapse is handling it
|
|
42
46
|
if (ctx.contextCollapseEnabled) {
|
|
@@ -255,15 +259,19 @@ CRITICAL RULES:
|
|
|
255
259
|
- Include the FULL original user request, not a paraphrase
|
|
256
260
|
- Do not summarize away technical details
|
|
257
261
|
- Focus on facts and specifics`;
|
|
258
|
-
const
|
|
259
|
-
|
|
262
|
+
const inferencePayload = {
|
|
263
|
+
formatVersion: 'codebolt.llm.v2',
|
|
264
|
+
input: [
|
|
260
265
|
{
|
|
261
266
|
role: 'system',
|
|
262
267
|
content: 'You are a precise conversation compression assistant. Be comprehensive but concise.',
|
|
263
268
|
},
|
|
264
269
|
{ role: 'user', content: prompt },
|
|
265
270
|
],
|
|
266
|
-
|
|
271
|
+
...(this.options.llmRole ? { llmrole: this.options.llmRole } : {}),
|
|
272
|
+
};
|
|
273
|
+
console.log('[AutoCompact] llm.inference payload:', inferencePayload);
|
|
274
|
+
const response = await codebolt.llm.inference(inferencePayload);
|
|
267
275
|
// Extract summary from response
|
|
268
276
|
let summary;
|
|
269
277
|
if (typeof ((_a = response === null || response === void 0 ? void 0 : response.completion) === null || _a === void 0 ? void 0 : _a.output_text) === 'string') {
|
|
@@ -42,6 +42,7 @@ export declare class CompactionOrchestrator {
|
|
|
42
42
|
private readonly layerOrder;
|
|
43
43
|
private readonly layers;
|
|
44
44
|
constructor(options?: CompactionOrchestratorOptions);
|
|
45
|
+
private normalizeLLMRole;
|
|
45
46
|
/**
|
|
46
47
|
* Run the full compaction pipeline.
|
|
47
48
|
* Each layer is checked and applied in priority order.
|
|
@@ -35,6 +35,7 @@ class CompactionOrchestrator {
|
|
|
35
35
|
modelTokenLimit: (_a = options === null || options === void 0 ? void 0 : options.modelTokenLimit) !== null && _a !== void 0 ? _a : DEFAULT_MODEL_TOKEN_LIMIT,
|
|
36
36
|
autoCompactEnabled: (_b = options === null || options === void 0 ? void 0 : options.autoCompactEnabled) !== null && _b !== void 0 ? _b : true,
|
|
37
37
|
contextCollapseEnabled: (_c = options === null || options === void 0 ? void 0 : options.contextCollapseEnabled) !== null && _c !== void 0 ? _c : false,
|
|
38
|
+
llmRole: this.normalizeLLMRole(options === null || options === void 0 ? void 0 : options.llmRole),
|
|
38
39
|
enableLogging: (_d = options === null || options === void 0 ? void 0 : options.enableLogging) !== null && _d !== void 0 ? _d : false,
|
|
39
40
|
};
|
|
40
41
|
this.snip = new snipCompact_1.SnipCompact({ enableLogging: this.options.enableLogging });
|
|
@@ -42,14 +43,17 @@ class CompactionOrchestrator {
|
|
|
42
43
|
this.collapse = new contextCollapse_1.ContextCollapse({
|
|
43
44
|
modelTokenLimit: this.options.modelTokenLimit,
|
|
44
45
|
enableLogging: this.options.enableLogging,
|
|
46
|
+
...(this.options.llmRole ? { llmRole: this.options.llmRole } : {}),
|
|
45
47
|
});
|
|
46
48
|
this.auto = new autoCompact_1.AutoCompact({
|
|
47
49
|
modelTokenLimit: this.options.modelTokenLimit,
|
|
48
50
|
enableLogging: this.options.enableLogging,
|
|
51
|
+
...(this.options.llmRole ? { llmRole: this.options.llmRole } : {}),
|
|
49
52
|
});
|
|
50
53
|
this.reactive = new reactiveCompact_1.ReactiveCompact({
|
|
51
54
|
modelTokenLimit: this.options.modelTokenLimit,
|
|
52
55
|
enableLogging: this.options.enableLogging,
|
|
56
|
+
...(this.options.llmRole ? { llmRole: this.options.llmRole } : {}),
|
|
53
57
|
});
|
|
54
58
|
this.cleanup = new postCompactCleanup_1.PostCompactCleanup({
|
|
55
59
|
enableLogging: this.options.enableLogging,
|
|
@@ -63,6 +67,10 @@ class CompactionOrchestrator {
|
|
|
63
67
|
];
|
|
64
68
|
this.layers = new Map(layerEntries);
|
|
65
69
|
}
|
|
70
|
+
normalizeLLMRole(llmRole) {
|
|
71
|
+
const normalized = llmRole === null || llmRole === void 0 ? void 0 : llmRole.trim();
|
|
72
|
+
return normalized ? normalized : undefined;
|
|
73
|
+
}
|
|
66
74
|
/**
|
|
67
75
|
* Run the full compaction pipeline.
|
|
68
76
|
* Each layer is checked and applied in priority order.
|
|
@@ -22,7 +22,7 @@ export interface ContextCollapseOptions {
|
|
|
22
22
|
blockingThreshold?: number;
|
|
23
23
|
/** Model token limit (default: 128000) */
|
|
24
24
|
modelTokenLimit?: number;
|
|
25
|
-
/** LLM role for granular summarization
|
|
25
|
+
/** LLM role for granular summarization */
|
|
26
26
|
llmRole?: string;
|
|
27
27
|
/** Max summaries to keep in the collapse store (default: 20) */
|
|
28
28
|
maxSummaries?: number;
|
|
@@ -37,6 +37,7 @@ export declare class ContextCollapse implements CompactionLayer {
|
|
|
37
37
|
/** Staged collapses waiting for API confirmation */
|
|
38
38
|
private staged;
|
|
39
39
|
constructor(options?: ContextCollapseOptions);
|
|
40
|
+
private normalizeLLMRole;
|
|
40
41
|
shouldApply(ctx: CompactionContext): boolean;
|
|
41
42
|
apply(ctx: CompactionContext): Promise<CompactionContext>;
|
|
42
43
|
/**
|
|
@@ -25,7 +25,7 @@ const DEFAULT_BLOCKING_THRESHOLD = 0.95;
|
|
|
25
25
|
const MIN_COLLAPSE_TOKENS = 2000;
|
|
26
26
|
class ContextCollapse {
|
|
27
27
|
constructor(options) {
|
|
28
|
-
var _a, _b, _c, _d, _e
|
|
28
|
+
var _a, _b, _c, _d, _e;
|
|
29
29
|
this.name = 'collapse';
|
|
30
30
|
/** The collapse store: ordered list of collapsed ranges */
|
|
31
31
|
this.store = [];
|
|
@@ -35,11 +35,15 @@ class ContextCollapse {
|
|
|
35
35
|
commitThreshold: (_a = options === null || options === void 0 ? void 0 : options.commitThreshold) !== null && _a !== void 0 ? _a : DEFAULT_COMMIT_THRESHOLD,
|
|
36
36
|
blockingThreshold: (_b = options === null || options === void 0 ? void 0 : options.blockingThreshold) !== null && _b !== void 0 ? _b : DEFAULT_BLOCKING_THRESHOLD,
|
|
37
37
|
modelTokenLimit: (_c = options === null || options === void 0 ? void 0 : options.modelTokenLimit) !== null && _c !== void 0 ? _c : 128000,
|
|
38
|
-
llmRole: (
|
|
39
|
-
maxSummaries: (
|
|
40
|
-
enableLogging: (
|
|
38
|
+
llmRole: this.normalizeLLMRole(options === null || options === void 0 ? void 0 : options.llmRole),
|
|
39
|
+
maxSummaries: (_d = options === null || options === void 0 ? void 0 : options.maxSummaries) !== null && _d !== void 0 ? _d : 20,
|
|
40
|
+
enableLogging: (_e = options === null || options === void 0 ? void 0 : options.enableLogging) !== null && _e !== void 0 ? _e : false,
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
+
normalizeLLMRole(llmRole) {
|
|
44
|
+
const normalized = llmRole === null || llmRole === void 0 ? void 0 : llmRole.trim();
|
|
45
|
+
return normalized ? normalized : undefined;
|
|
46
|
+
}
|
|
43
47
|
shouldApply(ctx) {
|
|
44
48
|
if (!ctx.contextCollapseEnabled)
|
|
45
49
|
return false;
|
|
@@ -238,12 +242,16 @@ class ContextCollapse {
|
|
|
238
242
|
const prompt = `Summarize this conversation segment concisely. Preserve: key decisions, file paths, code changes, errors encountered, current task state. Be factual and specific.
|
|
239
243
|
|
|
240
244
|
${historyText}`;
|
|
241
|
-
const
|
|
242
|
-
|
|
245
|
+
const inferencePayload = {
|
|
246
|
+
formatVersion: 'codebolt.llm.v2',
|
|
247
|
+
input: [
|
|
243
248
|
{ role: 'system', content: 'You are a precise conversation summarizer. Be concise but complete.' },
|
|
244
249
|
{ role: 'user', content: prompt },
|
|
245
250
|
],
|
|
246
|
-
|
|
251
|
+
...(this.options.llmRole ? { llmrole: this.options.llmRole } : {}),
|
|
252
|
+
};
|
|
253
|
+
console.log('[ContextCollapse] llm.inference payload:', inferencePayload);
|
|
254
|
+
const response = await codebolt.llm.inference(inferencePayload);
|
|
247
255
|
const summary = ((_a = response === null || response === void 0 ? void 0 : response.completion) === null || _a === void 0 ? void 0 : _a.output_text) || ((_b = response === null || response === void 0 ? void 0 : response.completion) === null || _b === void 0 ? void 0 : _b.content);
|
|
248
256
|
if (summary && typeof summary === 'string' && summary.trim().length > 0) {
|
|
249
257
|
return summary.trim();
|
|
@@ -18,6 +18,8 @@ export interface ReactiveCompactOptions {
|
|
|
18
18
|
retryLimit?: number;
|
|
19
19
|
/** Model token limit (default: 128000) */
|
|
20
20
|
modelTokenLimit?: number;
|
|
21
|
+
/** LLM role for emergency summarization calls */
|
|
22
|
+
llmRole?: string;
|
|
21
23
|
/** Enable logging (default: false) */
|
|
22
24
|
enableLogging?: boolean;
|
|
23
25
|
}
|
|
@@ -34,6 +36,7 @@ export declare class ReactiveCompact implements CompactionLayer {
|
|
|
34
36
|
private hasAttemptedThisTurn;
|
|
35
37
|
private retryCount;
|
|
36
38
|
constructor(options?: ReactiveCompactOptions);
|
|
39
|
+
private normalizeLLMRole;
|
|
37
40
|
shouldApply(_ctx: CompactionContext): boolean;
|
|
38
41
|
apply(_ctx: CompactionContext): Promise<CompactionContext>;
|
|
39
42
|
reset(): void;
|
|
@@ -39,9 +39,14 @@ class ReactiveCompact {
|
|
|
39
39
|
this.options = {
|
|
40
40
|
retryLimit: (_a = options === null || options === void 0 ? void 0 : options.retryLimit) !== null && _a !== void 0 ? _a : 1,
|
|
41
41
|
modelTokenLimit: (_b = options === null || options === void 0 ? void 0 : options.modelTokenLimit) !== null && _b !== void 0 ? _b : 128000,
|
|
42
|
+
llmRole: this.normalizeLLMRole(options === null || options === void 0 ? void 0 : options.llmRole),
|
|
42
43
|
enableLogging: (_c = options === null || options === void 0 ? void 0 : options.enableLogging) !== null && _c !== void 0 ? _c : false,
|
|
43
44
|
};
|
|
44
45
|
}
|
|
46
|
+
normalizeLLMRole(llmRole) {
|
|
47
|
+
const normalized = llmRole === null || llmRole === void 0 ? void 0 : llmRole.trim();
|
|
48
|
+
return normalized ? normalized : undefined;
|
|
49
|
+
}
|
|
45
50
|
shouldApply(_ctx) {
|
|
46
51
|
// Reactive only fires when explicitly triggered by an error
|
|
47
52
|
// via tryRecoverFromError(), not proactively
|
|
@@ -266,15 +271,19 @@ class ReactiveCompact {
|
|
|
266
271
|
|
|
267
272
|
Conversation:
|
|
268
273
|
${historyText}`;
|
|
269
|
-
const
|
|
270
|
-
|
|
274
|
+
const inferencePayload = {
|
|
275
|
+
formatVersion: 'codebolt.llm.v2',
|
|
276
|
+
input: [
|
|
271
277
|
{
|
|
272
278
|
role: 'system',
|
|
273
279
|
content: 'Create an extremely concise summary. Focus on actionable facts only.',
|
|
274
280
|
},
|
|
275
281
|
{ role: 'user', content: prompt },
|
|
276
282
|
],
|
|
277
|
-
|
|
283
|
+
...(this.options.llmRole ? { llmrole: this.options.llmRole } : {}),
|
|
284
|
+
};
|
|
285
|
+
console.log('[ReactiveCompact] llm.inference payload:', inferencePayload);
|
|
286
|
+
const response = await codebolt.llm.inference(inferencePayload);
|
|
278
287
|
let summary;
|
|
279
288
|
if (typeof ((_a = response === null || response === void 0 ? void 0 : response.completion) === null || _a === void 0 ? void 0 : _a.output_text) === 'string') {
|
|
280
289
|
summary = response.completion.output_text;
|
|
@@ -175,22 +175,193 @@ export interface CodeboltAPI {
|
|
|
175
175
|
/** Stream LLM response */
|
|
176
176
|
stream(params: LLMInferenceParams): AsyncIterable<LLMResponse>;
|
|
177
177
|
};
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
|
|
182
|
-
|
|
178
|
+
/** Generic tool operations */
|
|
179
|
+
tools?: {
|
|
180
|
+
/** List CodeBoltJS built-in tools */
|
|
181
|
+
listBuiltInTools(options?: {
|
|
182
|
+
namespace?: string;
|
|
183
|
+
grep?: string;
|
|
184
|
+
limit?: number;
|
|
185
|
+
}): Promise<{
|
|
186
|
+
data: {
|
|
187
|
+
tools: Array<{
|
|
188
|
+
name: string;
|
|
189
|
+
toolName: string;
|
|
190
|
+
namespace: string;
|
|
191
|
+
sourceType: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
192
|
+
sourceId?: string;
|
|
193
|
+
displayName?: string;
|
|
194
|
+
description?: string;
|
|
195
|
+
inputSchema: Record<string, unknown>;
|
|
196
|
+
}>;
|
|
197
|
+
};
|
|
198
|
+
}>;
|
|
199
|
+
/** List external tools: MCP, plugin, and project-local */
|
|
200
|
+
listExternalTools(options?: {
|
|
201
|
+
namespace?: string;
|
|
202
|
+
sourceType?: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
203
|
+
sourceId?: string;
|
|
204
|
+
grep?: string;
|
|
205
|
+
limit?: number;
|
|
206
|
+
}): Promise<{
|
|
207
|
+
data: {
|
|
208
|
+
tools: Array<{
|
|
209
|
+
name: string;
|
|
210
|
+
toolName: string;
|
|
211
|
+
namespace: string;
|
|
212
|
+
sourceType: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
213
|
+
sourceId?: string;
|
|
214
|
+
displayName?: string;
|
|
215
|
+
description?: string;
|
|
216
|
+
inputSchema: Record<string, unknown>;
|
|
217
|
+
}>;
|
|
218
|
+
};
|
|
219
|
+
}>;
|
|
220
|
+
/** List all tools callable in the current runtime context */
|
|
221
|
+
listRuntimeTools(options?: {
|
|
222
|
+
includeBuiltIn?: boolean;
|
|
223
|
+
includeExternal?: boolean;
|
|
224
|
+
includeAgentLocal?: boolean;
|
|
225
|
+
namespace?: string;
|
|
226
|
+
sourceType?: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
227
|
+
sourceId?: string;
|
|
228
|
+
grep?: string;
|
|
229
|
+
limit?: number;
|
|
230
|
+
}): Promise<{
|
|
231
|
+
data: {
|
|
232
|
+
tools: Array<{
|
|
233
|
+
name: string;
|
|
234
|
+
toolName: string;
|
|
235
|
+
namespace: string;
|
|
236
|
+
sourceType: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
237
|
+
sourceId?: string;
|
|
238
|
+
displayName?: string;
|
|
239
|
+
description?: string;
|
|
240
|
+
inputSchema: Record<string, unknown>;
|
|
241
|
+
}>;
|
|
242
|
+
};
|
|
243
|
+
}>;
|
|
244
|
+
/** List tool namespaces such as fs, terminal, browser, or an MCP server name */
|
|
245
|
+
listToolNamespaces(options?: {
|
|
246
|
+
includeBuiltIn?: boolean;
|
|
247
|
+
includeExternal?: boolean;
|
|
248
|
+
includeAgentLocal?: boolean;
|
|
249
|
+
namespace?: string;
|
|
250
|
+
sourceType?: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
251
|
+
sourceId?: string;
|
|
252
|
+
grep?: string;
|
|
253
|
+
limit?: number;
|
|
254
|
+
}): Promise<{
|
|
255
|
+
data: {
|
|
256
|
+
namespaces: Array<{
|
|
257
|
+
namespace: string;
|
|
258
|
+
sourceType?: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
259
|
+
sourceId?: string;
|
|
260
|
+
displayName?: string;
|
|
261
|
+
toolCount?: number;
|
|
262
|
+
}>;
|
|
263
|
+
};
|
|
264
|
+
}>;
|
|
265
|
+
/** List tools in one namespace */
|
|
266
|
+
listToolsByNamespace(namespace: string, options?: {
|
|
267
|
+
includeBuiltIn?: boolean;
|
|
268
|
+
includeExternal?: boolean;
|
|
269
|
+
includeAgentLocal?: boolean;
|
|
270
|
+
sourceType?: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
271
|
+
sourceId?: string;
|
|
272
|
+
grep?: string;
|
|
273
|
+
limit?: number;
|
|
274
|
+
}): Promise<{
|
|
275
|
+
data: {
|
|
276
|
+
tools: Array<{
|
|
277
|
+
name: string;
|
|
278
|
+
toolName: string;
|
|
279
|
+
namespace: string;
|
|
280
|
+
sourceType: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
281
|
+
sourceId?: string;
|
|
282
|
+
displayName?: string;
|
|
283
|
+
description?: string;
|
|
284
|
+
inputSchema: Record<string, unknown>;
|
|
285
|
+
}>;
|
|
286
|
+
};
|
|
287
|
+
}>;
|
|
288
|
+
/** List tool sources such as built-in, MCP, plugin, project-local, and agent-local identities */
|
|
289
|
+
listToolSources(options?: {
|
|
290
|
+
includeBuiltIn?: boolean;
|
|
291
|
+
includeExternal?: boolean;
|
|
292
|
+
includeAgentLocal?: boolean;
|
|
293
|
+
namespace?: string;
|
|
294
|
+
sourceType?: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
295
|
+
sourceId?: string;
|
|
296
|
+
grep?: string;
|
|
297
|
+
limit?: number;
|
|
298
|
+
}): Promise<{
|
|
299
|
+
data: {
|
|
300
|
+
sources: Array<{
|
|
301
|
+
sourceId: string;
|
|
302
|
+
sourceType: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
303
|
+
displayName?: string;
|
|
304
|
+
namespaces?: string[];
|
|
305
|
+
toolCount?: number;
|
|
306
|
+
}>;
|
|
307
|
+
};
|
|
308
|
+
}>;
|
|
309
|
+
/** List tools supplied by one source identity */
|
|
310
|
+
listToolsBySource(sourceId: string, options?: {
|
|
311
|
+
includeBuiltIn?: boolean;
|
|
312
|
+
includeExternal?: boolean;
|
|
313
|
+
includeAgentLocal?: boolean;
|
|
314
|
+
namespace?: string;
|
|
315
|
+
sourceType?: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
316
|
+
grep?: string;
|
|
317
|
+
limit?: number;
|
|
318
|
+
}): Promise<{
|
|
319
|
+
data: {
|
|
320
|
+
tools: Array<{
|
|
321
|
+
name: string;
|
|
322
|
+
toolName: string;
|
|
323
|
+
namespace: string;
|
|
324
|
+
sourceType: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
325
|
+
sourceId?: string;
|
|
326
|
+
displayName?: string;
|
|
327
|
+
description?: string;
|
|
328
|
+
inputSchema: Record<string, unknown>;
|
|
329
|
+
}>;
|
|
330
|
+
};
|
|
183
331
|
}>;
|
|
184
|
-
/**
|
|
185
|
-
|
|
186
|
-
data
|
|
187
|
-
|
|
332
|
+
/** Get one runtime tool descriptor */
|
|
333
|
+
getRuntimeTool(name: string): Promise<{
|
|
334
|
+
data: {
|
|
335
|
+
tool?: {
|
|
336
|
+
name: string;
|
|
337
|
+
toolName: string;
|
|
338
|
+
namespace: string;
|
|
339
|
+
sourceType: 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
340
|
+
sourceId?: string;
|
|
341
|
+
displayName?: string;
|
|
342
|
+
description?: string;
|
|
343
|
+
inputSchema: Record<string, unknown>;
|
|
344
|
+
};
|
|
188
345
|
};
|
|
189
346
|
}>;
|
|
190
|
-
/**
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
347
|
+
/** Execute a tool by runtime name */
|
|
348
|
+
execute(toolName: string, params?: unknown, options?: {
|
|
349
|
+
namespace?: string;
|
|
350
|
+
sourceId?: string;
|
|
351
|
+
}): Promise<{
|
|
352
|
+
data?: unknown;
|
|
353
|
+
result?: unknown;
|
|
354
|
+
}>;
|
|
355
|
+
};
|
|
356
|
+
/** MCP server lifecycle/configuration operations */
|
|
357
|
+
mcp: {
|
|
358
|
+
getEnabledMCPServers(): Promise<unknown>;
|
|
359
|
+
getLocalMCPServers(): Promise<unknown>;
|
|
360
|
+
getMentionedMCPServers(userMessage: unknown): Promise<unknown>;
|
|
361
|
+
searchAvailableMCPServers(query: string): Promise<unknown>;
|
|
362
|
+
configureMCPServer(name: string, config: Record<string, unknown>): Promise<unknown>;
|
|
363
|
+
getMcpList(): Promise<unknown>;
|
|
364
|
+
getEnabledMcps(): Promise<unknown>;
|
|
194
365
|
};
|
|
195
366
|
/** File system operations */
|
|
196
367
|
fs: {
|
|
@@ -206,7 +377,9 @@ export interface CodeboltAPI {
|
|
|
206
377
|
/** Agent operations */
|
|
207
378
|
agent?: {
|
|
208
379
|
/** Start a sub-agent */
|
|
209
|
-
startAgent(agentName: string, params: unknown
|
|
380
|
+
startAgent(agentName: string, params: unknown, options?: {
|
|
381
|
+
llm?: unknown;
|
|
382
|
+
}): Promise<{
|
|
210
383
|
data: unknown;
|
|
211
384
|
}>;
|
|
212
385
|
/** List available agents */
|