@codebolt/agent 6.1.7 → 6.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/processor-pieces/messageModifiers/capabilityContextModifier.d.ts +14 -0
- package/dist/processor-pieces/messageModifiers/capabilityContextModifier.js +165 -0
- package/dist/processor-pieces/messageModifiers/index.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/index.js +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ProcessedMessage } from "@codebolt/types/agent";
|
|
2
|
+
import { BaseMessageModifier } from "../base";
|
|
3
|
+
import { FlatUserMessage } from "@codebolt/types/sdk";
|
|
4
|
+
export interface CapabilityContextModifierOptions {
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class CapabilityContextModifier extends BaseMessageModifier {
|
|
8
|
+
private readonly options;
|
|
9
|
+
constructor(options?: CapabilityContextModifierOptions);
|
|
10
|
+
modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
11
|
+
private normalizeCapabilities;
|
|
12
|
+
private resolveSelectedCapability;
|
|
13
|
+
private formatSelectedCapabilitiesContext;
|
|
14
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CapabilityContextModifier = void 0;
|
|
7
|
+
const base_1 = require("../base");
|
|
8
|
+
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
9
|
+
const promptContext_1 = require("../../unified/base/promptContext");
|
|
10
|
+
class CapabilityContextModifier extends base_1.BaseMessageModifier {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
super();
|
|
13
|
+
this.options = options;
|
|
14
|
+
}
|
|
15
|
+
async modify(originalRequest, createdMessage) {
|
|
16
|
+
const selectedCapabilities = this.normalizeCapabilities(originalRequest.selectedCapabilities);
|
|
17
|
+
if (selectedCapabilities.length === 0) {
|
|
18
|
+
return createdMessage;
|
|
19
|
+
}
|
|
20
|
+
const skillContexts = [];
|
|
21
|
+
const selectedCapabilityInfo = [];
|
|
22
|
+
const capabilityErrors = [];
|
|
23
|
+
for (const capabilityName of selectedCapabilities) {
|
|
24
|
+
const resolvedContext = await this.resolveSelectedCapability(capabilityName, originalRequest);
|
|
25
|
+
if (resolvedContext.info) {
|
|
26
|
+
selectedCapabilityInfo.push(resolvedContext.info);
|
|
27
|
+
}
|
|
28
|
+
if (resolvedContext.context) {
|
|
29
|
+
skillContexts.push(resolvedContext.context);
|
|
30
|
+
}
|
|
31
|
+
if (resolvedContext.error) {
|
|
32
|
+
capabilityErrors.push(resolvedContext.error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const contextMessage = {
|
|
36
|
+
role: 'user',
|
|
37
|
+
content: this.formatSelectedCapabilitiesContext(selectedCapabilities, selectedCapabilityInfo, skillContexts),
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
...(0, promptContext_1.appendUserContextMessage)(createdMessage, contextMessage),
|
|
41
|
+
metadata: {
|
|
42
|
+
...createdMessage.metadata,
|
|
43
|
+
selectedCapabilities,
|
|
44
|
+
selectedCapabilitiesProcessed: true,
|
|
45
|
+
selectedCapabilityNames: skillContexts.map((context) => context.name),
|
|
46
|
+
selectedCapabilityErrors: capabilityErrors,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
normalizeCapabilities(selectedCapabilities) {
|
|
51
|
+
if (!Array.isArray(selectedCapabilities)) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
return Array.from(new Set(selectedCapabilities
|
|
55
|
+
.map((capabilityName) => capabilityName.trim())
|
|
56
|
+
.filter(Boolean)));
|
|
57
|
+
}
|
|
58
|
+
async resolveSelectedCapability(capabilityName, originalRequest) {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
try {
|
|
61
|
+
const capabilityDetail = await codeboltjs_1.default.capability.getCapabilityDetail(capabilityName);
|
|
62
|
+
if (!(capabilityDetail === null || capabilityDetail === void 0 ? void 0 : capabilityDetail.success) || !((_a = capabilityDetail.capability) === null || _a === void 0 ? void 0 : _a.type)) {
|
|
63
|
+
return {
|
|
64
|
+
error: {
|
|
65
|
+
name: capabilityName,
|
|
66
|
+
error: (capabilityDetail === null || capabilityDetail === void 0 ? void 0 : capabilityDetail.error) || 'Capability detail did not include a capability type',
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const capabilityType = capabilityDetail.capability.type;
|
|
71
|
+
if (capabilityType !== 'skill') {
|
|
72
|
+
return {
|
|
73
|
+
info: {
|
|
74
|
+
name: capabilityName,
|
|
75
|
+
type: capabilityType,
|
|
76
|
+
autoLoaded: false,
|
|
77
|
+
reason: 'Only skill capabilities are auto-loaded. Talents and powers stay selected and must be invoked with the capability tool if needed.',
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const response = await codeboltjs_1.default.capability.startSkill(capabilityName, {
|
|
82
|
+
arguments: originalRequest.userMessage,
|
|
83
|
+
input: originalRequest.userMessage,
|
|
84
|
+
task: originalRequest.userMessage,
|
|
85
|
+
}, this.options.timeout);
|
|
86
|
+
if (!(response === null || response === void 0 ? void 0 : response.success)) {
|
|
87
|
+
return {
|
|
88
|
+
info: {
|
|
89
|
+
name: capabilityName,
|
|
90
|
+
type: capabilityType,
|
|
91
|
+
autoLoaded: false,
|
|
92
|
+
},
|
|
93
|
+
error: {
|
|
94
|
+
name: capabilityName,
|
|
95
|
+
error: (response === null || response === void 0 ? void 0 : response.error) || 'Skill did not return a successful response',
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const skillPrompt = ((_b = response.additionalContext) === null || _b === void 0 ? void 0 : _b['skillPrompt']) || response.result;
|
|
100
|
+
const prompt = typeof (skillPrompt === null || skillPrompt === void 0 ? void 0 : skillPrompt.prompt) === 'string' ? skillPrompt.prompt.trim() : '';
|
|
101
|
+
if (!prompt) {
|
|
102
|
+
return {
|
|
103
|
+
info: {
|
|
104
|
+
name: capabilityName,
|
|
105
|
+
type: capabilityType,
|
|
106
|
+
autoLoaded: false,
|
|
107
|
+
},
|
|
108
|
+
error: {
|
|
109
|
+
name: capabilityName,
|
|
110
|
+
error: 'Skill response did not include prompt context',
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
info: {
|
|
116
|
+
name: capabilityName,
|
|
117
|
+
type: capabilityType,
|
|
118
|
+
autoLoaded: true,
|
|
119
|
+
},
|
|
120
|
+
context: {
|
|
121
|
+
name: skillPrompt.skillName || capabilityName,
|
|
122
|
+
type: 'skill',
|
|
123
|
+
prompt,
|
|
124
|
+
refs: skillPrompt.refs,
|
|
125
|
+
metadata: skillPrompt.metadata,
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
return {
|
|
131
|
+
error: {
|
|
132
|
+
name: capabilityName,
|
|
133
|
+
error: error instanceof Error ? error.message : String(error),
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
formatSelectedCapabilitiesContext(selectedCapabilities, selectedCapabilityInfo, skillContexts) {
|
|
139
|
+
const infoByName = new Map(selectedCapabilityInfo.map((info) => [info.name, info]));
|
|
140
|
+
const selectedSections = selectedCapabilities.map((capabilityName) => {
|
|
141
|
+
const info = infoByName.get(capabilityName);
|
|
142
|
+
const type = (info === null || info === void 0 ? void 0 : info.type) ? ` (${info.type})` : '';
|
|
143
|
+
const status = (info === null || info === void 0 ? void 0 : info.autoLoaded) ? 'skill context loaded' : 'not auto-loaded';
|
|
144
|
+
const reason = (info === null || info === void 0 ? void 0 : info.reason) ? ` - ${info.reason}` : '';
|
|
145
|
+
return `- ${capabilityName}${type}: ${status}${reason}`;
|
|
146
|
+
});
|
|
147
|
+
const skillContextSections = skillContexts.map((context) => {
|
|
148
|
+
const refs = Array.isArray(context.refs) && context.refs.length > 0
|
|
149
|
+
? `\n\nCapability references:\n${context.refs.map((ref) => `- ${JSON.stringify(ref)}`).join('\n')}`
|
|
150
|
+
: '';
|
|
151
|
+
return `--- Selected skill capability: ${context.name} ---\n${context.prompt}${refs}`;
|
|
152
|
+
});
|
|
153
|
+
return [
|
|
154
|
+
'The user selected the following capabilities for this turn:',
|
|
155
|
+
...selectedSections,
|
|
156
|
+
'',
|
|
157
|
+
'Skill capabilities are auto-loaded as prompt context below. Talents and powers are not auto-started.',
|
|
158
|
+
'Use the capability tool to inspect or invoke selected talents/powers only if the user request needs them.',
|
|
159
|
+
...(skillContextSections.length > 0
|
|
160
|
+
? ['', ...skillContextSections]
|
|
161
|
+
: []),
|
|
162
|
+
].join('\n');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.CapabilityContextModifier = CapabilityContextModifier;
|
|
@@ -3,6 +3,7 @@ export { CoreSystemPromptModifier, type CoreSystemPromptOptions } from './coreSy
|
|
|
3
3
|
export { DirectoryContextModifier, type DirectoryContextOptions } from './directoryContextModifier';
|
|
4
4
|
export { IdeContextModifier, type IdeContextOptions, type FileInfo, type IdeContext } from './ideContextModifier';
|
|
5
5
|
export { AtFileProcessorModifier, type AtFileProcessorOptions } from './atFileProcessorModifier';
|
|
6
|
+
export { CapabilityContextModifier, type CapabilityContextModifierOptions } from './capabilityContextModifier';
|
|
6
7
|
export { ArgumentProcessorModifier, type ArgumentProcessorOptions } from './argumentProcessorModifier';
|
|
7
8
|
export { MemoryImportModifier, type MemoryImportOptions } from './memoryImportModifier';
|
|
8
9
|
export { LoopDetectionModifier, type LoopDetectionOptions } from '../postInferenceProcessors/loopDetectionModifier';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MemoryTypeContextModifier = exports.RuleBasedContextModifier = exports.ContextAssemblyModifier = exports.ChatHistoryMessageModifier = exports.ChatRecordingModifier = exports.ToolInjectionModifier = exports.LoopDetectionModifier = exports.MemoryImportModifier = exports.ArgumentProcessorModifier = exports.AtFileProcessorModifier = exports.IdeContextModifier = exports.DirectoryContextModifier = exports.CoreSystemPromptModifier = exports.EnvironmentContextModifier = void 0;
|
|
3
|
+
exports.MemoryTypeContextModifier = exports.RuleBasedContextModifier = exports.ContextAssemblyModifier = exports.ChatHistoryMessageModifier = exports.ChatRecordingModifier = exports.ToolInjectionModifier = exports.LoopDetectionModifier = exports.MemoryImportModifier = exports.ArgumentProcessorModifier = exports.CapabilityContextModifier = exports.AtFileProcessorModifier = exports.IdeContextModifier = exports.DirectoryContextModifier = exports.CoreSystemPromptModifier = exports.EnvironmentContextModifier = void 0;
|
|
4
4
|
// Gemini-CLI equivalent modifiers
|
|
5
5
|
var environmentContextModifier_1 = require("./environmentContextModifier");
|
|
6
6
|
Object.defineProperty(exports, "EnvironmentContextModifier", { enumerable: true, get: function () { return environmentContextModifier_1.EnvironmentContextModifier; } });
|
|
@@ -12,6 +12,8 @@ var ideContextModifier_1 = require("./ideContextModifier");
|
|
|
12
12
|
Object.defineProperty(exports, "IdeContextModifier", { enumerable: true, get: function () { return ideContextModifier_1.IdeContextModifier; } });
|
|
13
13
|
var atFileProcessorModifier_1 = require("./atFileProcessorModifier");
|
|
14
14
|
Object.defineProperty(exports, "AtFileProcessorModifier", { enumerable: true, get: function () { return atFileProcessorModifier_1.AtFileProcessorModifier; } });
|
|
15
|
+
var capabilityContextModifier_1 = require("./capabilityContextModifier");
|
|
16
|
+
Object.defineProperty(exports, "CapabilityContextModifier", { enumerable: true, get: function () { return capabilityContextModifier_1.CapabilityContextModifier; } });
|
|
15
17
|
var argumentProcessorModifier_1 = require("./argumentProcessorModifier");
|
|
16
18
|
Object.defineProperty(exports, "ArgumentProcessorModifier", { enumerable: true, get: function () { return argumentProcessorModifier_1.ArgumentProcessorModifier; } });
|
|
17
19
|
var memoryImportModifier_1 = require("./memoryImportModifier");
|