@mako10k/shell-server 0.1.0
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/LICENSE +21 -0
- package/README.md +114 -0
- package/dist/backoffice/index.d.ts +2 -0
- package/dist/backoffice/index.d.ts.map +1 -0
- package/dist/backoffice/index.js +47 -0
- package/dist/backoffice/index.js.map +1 -0
- package/dist/backoffice/server.d.ts +45 -0
- package/dist/backoffice/server.d.ts.map +1 -0
- package/dist/backoffice/server.js +610 -0
- package/dist/backoffice/server.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +525 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/config-manager.d.ts +80 -0
- package/dist/core/config-manager.d.ts.map +1 -0
- package/dist/core/config-manager.js +218 -0
- package/dist/core/config-manager.js.map +1 -0
- package/dist/core/enhanced-history-manager.d.ts +84 -0
- package/dist/core/enhanced-history-manager.d.ts.map +1 -0
- package/dist/core/enhanced-history-manager.js +319 -0
- package/dist/core/enhanced-history-manager.js.map +1 -0
- package/dist/core/file-manager.d.ts +79 -0
- package/dist/core/file-manager.d.ts.map +1 -0
- package/dist/core/file-manager.js +338 -0
- package/dist/core/file-manager.js.map +1 -0
- package/dist/core/file-storage-subscriber.d.ts +38 -0
- package/dist/core/file-storage-subscriber.d.ts.map +1 -0
- package/dist/core/file-storage-subscriber.js +132 -0
- package/dist/core/file-storage-subscriber.js.map +1 -0
- package/dist/core/monitoring-manager.d.ts +32 -0
- package/dist/core/monitoring-manager.d.ts.map +1 -0
- package/dist/core/monitoring-manager.js +296 -0
- package/dist/core/monitoring-manager.js.map +1 -0
- package/dist/core/process-manager.d.ts +105 -0
- package/dist/core/process-manager.d.ts.map +1 -0
- package/dist/core/process-manager.js +1374 -0
- package/dist/core/process-manager.js.map +1 -0
- package/dist/core/realtime-stream-subscriber.d.ts +93 -0
- package/dist/core/realtime-stream-subscriber.d.ts.map +1 -0
- package/dist/core/realtime-stream-subscriber.js +200 -0
- package/dist/core/realtime-stream-subscriber.js.map +1 -0
- package/dist/core/remote-http-client.d.ts +15 -0
- package/dist/core/remote-http-client.d.ts.map +1 -0
- package/dist/core/remote-http-client.js +60 -0
- package/dist/core/remote-http-client.js.map +1 -0
- package/dist/core/remote-process-service.d.ts +50 -0
- package/dist/core/remote-process-service.d.ts.map +1 -0
- package/dist/core/remote-process-service.js +20 -0
- package/dist/core/remote-process-service.js.map +1 -0
- package/dist/core/server-manager.d.ts +71 -0
- package/dist/core/server-manager.d.ts.map +1 -0
- package/dist/core/server-manager.js +680 -0
- package/dist/core/server-manager.js.map +1 -0
- package/dist/core/stream-publisher.d.ts +75 -0
- package/dist/core/stream-publisher.d.ts.map +1 -0
- package/dist/core/stream-publisher.js +127 -0
- package/dist/core/stream-publisher.js.map +1 -0
- package/dist/core/streaming-pipeline-reader.d.ts +67 -0
- package/dist/core/streaming-pipeline-reader.d.ts.map +1 -0
- package/dist/core/streaming-pipeline-reader.js +191 -0
- package/dist/core/streaming-pipeline-reader.js.map +1 -0
- package/dist/core/terminal-manager.d.ts +96 -0
- package/dist/core/terminal-manager.d.ts.map +1 -0
- package/dist/core/terminal-manager.js +515 -0
- package/dist/core/terminal-manager.js.map +1 -0
- package/dist/daemon/server.d.ts +8 -0
- package/dist/daemon/server.d.ts.map +1 -0
- package/dist/daemon/server.js +416 -0
- package/dist/daemon/server.js.map +1 -0
- package/dist/daemon/uds-transport.d.ts +31 -0
- package/dist/daemon/uds-transport.d.ts.map +1 -0
- package/dist/daemon/uds-transport.js +149 -0
- package/dist/daemon/uds-transport.js.map +1 -0
- package/dist/executor/server.d.ts +20 -0
- package/dist/executor/server.d.ts.map +1 -0
- package/dist/executor/server.js +375 -0
- package/dist/executor/server.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/daemon-runtime.d.ts +4 -0
- package/dist/runtime/daemon-runtime.d.ts.map +1 -0
- package/dist/runtime/daemon-runtime.js +4 -0
- package/dist/runtime/daemon-runtime.js.map +1 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +3 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/tool-runtime.d.ts +52 -0
- package/dist/runtime/tool-runtime.d.ts.map +1 -0
- package/dist/runtime/tool-runtime.js +161 -0
- package/dist/runtime/tool-runtime.js.map +1 -0
- package/dist/security/chat-completion-adapter.d.ts +443 -0
- package/dist/security/chat-completion-adapter.d.ts.map +1 -0
- package/dist/security/chat-completion-adapter.js +475 -0
- package/dist/security/chat-completion-adapter.js.map +1 -0
- package/dist/security/enhanced-evaluator.d.ts +139 -0
- package/dist/security/enhanced-evaluator.d.ts.map +1 -0
- package/dist/security/enhanced-evaluator.js +1208 -0
- package/dist/security/enhanced-evaluator.js.map +1 -0
- package/dist/security/evaluator-types.d.ts +614 -0
- package/dist/security/evaluator-types.d.ts.map +1 -0
- package/dist/security/evaluator-types.js +124 -0
- package/dist/security/evaluator-types.js.map +1 -0
- package/dist/security/manager.d.ts +76 -0
- package/dist/security/manager.d.ts.map +1 -0
- package/dist/security/manager.js +445 -0
- package/dist/security/manager.js.map +1 -0
- package/dist/security/security-llm-prompt-generator.d.ts +105 -0
- package/dist/security/security-llm-prompt-generator.d.ts.map +1 -0
- package/dist/security/security-llm-prompt-generator.js +323 -0
- package/dist/security/security-llm-prompt-generator.js.map +1 -0
- package/dist/security/security-tools.d.ts +174 -0
- package/dist/security/security-tools.d.ts.map +1 -0
- package/dist/security/security-tools.js +159 -0
- package/dist/security/security-tools.js.map +1 -0
- package/dist/security/validator-criteria-manager.d.ts +47 -0
- package/dist/security/validator-criteria-manager.d.ts.map +1 -0
- package/dist/security/validator-criteria-manager.js +169 -0
- package/dist/security/validator-criteria-manager.js.map +1 -0
- package/dist/tools/shell-tools.d.ts +474 -0
- package/dist/tools/shell-tools.d.ts.map +1 -0
- package/dist/tools/shell-tools.js +861 -0
- package/dist/tools/shell-tools.js.map +1 -0
- package/dist/types/enhanced-security.d.ts +529 -0
- package/dist/types/enhanced-security.d.ts.map +1 -0
- package/dist/types/enhanced-security.js +286 -0
- package/dist/types/enhanced-security.js.map +1 -0
- package/dist/types/index.d.ts +282 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +158 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/quick-schemas.d.ts +177 -0
- package/dist/types/quick-schemas.d.ts.map +1 -0
- package/dist/types/quick-schemas.js +113 -0
- package/dist/types/quick-schemas.js.map +1 -0
- package/dist/types/response-schemas.d.ts +41 -0
- package/dist/types/response-schemas.d.ts.map +1 -0
- package/dist/types/response-schemas.js +41 -0
- package/dist/types/response-schemas.js.map +1 -0
- package/dist/types/schemas.d.ts +578 -0
- package/dist/types/schemas.d.ts.map +1 -0
- package/dist/types/schemas.js +498 -0
- package/dist/types/schemas.js.map +1 -0
- package/dist/utils/criteria-manager.d.ts +47 -0
- package/dist/utils/criteria-manager.d.ts.map +1 -0
- package/dist/utils/criteria-manager.js +228 -0
- package/dist/utils/criteria-manager.js.map +1 -0
- package/dist/utils/errors.d.ts +27 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +67 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/helpers.d.ts +85 -0
- package/dist/utils/helpers.d.ts.map +1 -0
- package/dist/utils/helpers.js +400 -0
- package/dist/utils/helpers.js.map +1 -0
- package/dist/utils/json-repair.d.ts +23 -0
- package/dist/utils/json-repair.d.ts.map +1 -0
- package/dist/utils/json-repair.js +208 -0
- package/dist/utils/json-repair.js.map +1 -0
- package/dist/utils/process-utils.d.ts +31 -0
- package/dist/utils/process-utils.d.ts.map +1 -0
- package/dist/utils/process-utils.js +217 -0
- package/dist/utils/process-utils.js.map +1 -0
- package/dist/utils/server-helpers.d.ts +4 -0
- package/dist/utils/server-helpers.d.ts.map +1 -0
- package/dist/utils/server-helpers.js +10 -0
- package/dist/utils/server-helpers.js.map +1 -0
- package/dist/utils/sse.d.ts +2 -0
- package/dist/utils/sse.d.ts.map +1 -0
- package/dist/utils/sse.js +6 -0
- package/dist/utils/sse.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ToolCallSchema, ToolChoiceSchema } from './evaluator-types.js';
|
|
3
|
+
const CCCMessageSchema = z.array(z.object({
|
|
4
|
+
role: z.union([z.literal('system'), z.literal('user'), z.literal('assistant')]),
|
|
5
|
+
content: z.string(),
|
|
6
|
+
name: z.string().optional(),
|
|
7
|
+
}));
|
|
8
|
+
const CCCToolsSchema = z
|
|
9
|
+
.array(z.object({
|
|
10
|
+
type: z.literal('function'),
|
|
11
|
+
function: z.object({
|
|
12
|
+
name: z.string(),
|
|
13
|
+
description: z.string(),
|
|
14
|
+
parameters: z.object({
|
|
15
|
+
type: z.literal('object'),
|
|
16
|
+
properties: z.record(z.unknown()),
|
|
17
|
+
required: z.array(z.string()).optional(),
|
|
18
|
+
}),
|
|
19
|
+
}),
|
|
20
|
+
}));
|
|
21
|
+
const CCCRequestSchema = z.object({
|
|
22
|
+
model: z.string(),
|
|
23
|
+
messages: CCCMessageSchema,
|
|
24
|
+
temperature: z.number().optional(),
|
|
25
|
+
max_tokens: z.number().optional(),
|
|
26
|
+
stop: z.array(z.string()).optional(),
|
|
27
|
+
top_p: z.number().optional(),
|
|
28
|
+
frequency_penalty: z.number().optional(),
|
|
29
|
+
presence_penalty: z.number().optional(),
|
|
30
|
+
tools: CCCToolsSchema.optional(),
|
|
31
|
+
tool_choice: ToolChoiceSchema.optional(),
|
|
32
|
+
});
|
|
33
|
+
const CCCResponseSchema = z.object({
|
|
34
|
+
choices: z.array(z.object({
|
|
35
|
+
message: z.object({
|
|
36
|
+
role: z.literal('assistant'),
|
|
37
|
+
content: z.string().nullable(), // Function calls can have null content
|
|
38
|
+
tool_calls: z.array(ToolCallSchema).optional(),
|
|
39
|
+
}),
|
|
40
|
+
finish_reason: z.union([
|
|
41
|
+
z.literal('stop'),
|
|
42
|
+
z.literal('length'),
|
|
43
|
+
z.literal('tool_calls'),
|
|
44
|
+
]),
|
|
45
|
+
index: z.number().optional(),
|
|
46
|
+
})),
|
|
47
|
+
usage: z
|
|
48
|
+
.object({
|
|
49
|
+
prompt_tokens: z.number(),
|
|
50
|
+
completion_tokens: z.number(),
|
|
51
|
+
total_tokens: z.number(),
|
|
52
|
+
})
|
|
53
|
+
.optional(),
|
|
54
|
+
});
|
|
55
|
+
export class CCCToMCPCMAdapter {
|
|
56
|
+
createMessage;
|
|
57
|
+
constructor(createMessage) {
|
|
58
|
+
this.createMessage = createMessage;
|
|
59
|
+
}
|
|
60
|
+
static fromMCPServer(server) {
|
|
61
|
+
return new CCCToMCPCMAdapter(createMessageCallbackFromMCPServer(server));
|
|
62
|
+
}
|
|
63
|
+
// Update chatCompletion to handle optional properties explicitly
|
|
64
|
+
async chatCompletion(request) {
|
|
65
|
+
// Use the schemas for validation in chatCompletion
|
|
66
|
+
CCCRequestSchema.parse(request);
|
|
67
|
+
// Use adaptOpenAIRequestToMCP to convert the request
|
|
68
|
+
const mcpRequest = adaptOpenAIRequestToMCP(request);
|
|
69
|
+
const mcpResponse = await this.createMessage(mcpRequest);
|
|
70
|
+
// Parse Function Calls from MCP response if present
|
|
71
|
+
let toolCalls;
|
|
72
|
+
let content = null;
|
|
73
|
+
let finishReason = 'stop';
|
|
74
|
+
if (mcpResponse.content.type === 'text') {
|
|
75
|
+
const responseText = mcpResponse.content.text;
|
|
76
|
+
// Use flexible parsing
|
|
77
|
+
const parseResult = await this.parseFlexibleResponse(responseText, request);
|
|
78
|
+
if (parseResult.toolCalls) {
|
|
79
|
+
toolCalls = parseResult.toolCalls;
|
|
80
|
+
finishReason = 'tool_calls';
|
|
81
|
+
content = null;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
content = parseResult.content || responseText;
|
|
85
|
+
finishReason = 'stop';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
content = 'Non-text response';
|
|
90
|
+
finishReason = 'stop';
|
|
91
|
+
}
|
|
92
|
+
// Override with actual stopReason if available
|
|
93
|
+
if (mcpResponse.stopReason) {
|
|
94
|
+
finishReason = mcpResponse.stopReason;
|
|
95
|
+
}
|
|
96
|
+
const cccResponse = {
|
|
97
|
+
choices: [
|
|
98
|
+
{
|
|
99
|
+
message: {
|
|
100
|
+
role: 'assistant',
|
|
101
|
+
content: content,
|
|
102
|
+
...(toolCalls && { tool_calls: toolCalls }),
|
|
103
|
+
},
|
|
104
|
+
finish_reason: finishReason,
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
};
|
|
108
|
+
// Now validate the converted response
|
|
109
|
+
CCCResponseSchema.parse(cccResponse);
|
|
110
|
+
return cccResponse;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Flexible response parsing inspired by content-parser.ts
|
|
114
|
+
* Handles various LLM response formats including content-based and tool_calls-based responses
|
|
115
|
+
*/
|
|
116
|
+
async parseFlexibleResponse(responseText, request) {
|
|
117
|
+
// Try to extract JSON objects from the response
|
|
118
|
+
const jsonObjects = this.extractJsonObjects(responseText);
|
|
119
|
+
// Look for Function Call patterns
|
|
120
|
+
for (const obj of jsonObjects) {
|
|
121
|
+
// Type guard for object
|
|
122
|
+
if (!this.isValidObject(obj))
|
|
123
|
+
continue;
|
|
124
|
+
const objRecord = obj;
|
|
125
|
+
// Standard OpenAI format: {"tool_calls": [...]}
|
|
126
|
+
if (this.hasToolCalls(objRecord)) {
|
|
127
|
+
const toolCalls = this.parseToolCallsArray(objRecord['tool_calls']);
|
|
128
|
+
if (toolCalls.length > 0) {
|
|
129
|
+
return { toolCalls };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Check if this looks like direct function arguments
|
|
133
|
+
if (request.tools && request.tools.length > 0) {
|
|
134
|
+
const expectedTool = this.getExpectedTool(request);
|
|
135
|
+
if (expectedTool && this.looksLikeFunctionArgs(objRecord, expectedTool)) {
|
|
136
|
+
const toolCall = this.createToolCallFromArgs(expectedTool.function.name, objRecord);
|
|
137
|
+
return { toolCalls: [toolCall] };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Special case: Check if the entire response text is a JSON string containing tool_calls
|
|
142
|
+
const directToolCalls = await this.tryParseDirectToolCalls(responseText);
|
|
143
|
+
if (directToolCalls) {
|
|
144
|
+
return { toolCalls: directToolCalls };
|
|
145
|
+
}
|
|
146
|
+
// No valid function calls found, return as content
|
|
147
|
+
return { content: responseText };
|
|
148
|
+
}
|
|
149
|
+
// Type guard functions
|
|
150
|
+
isValidObject(value) {
|
|
151
|
+
return typeof value === 'object' && value !== null;
|
|
152
|
+
}
|
|
153
|
+
hasToolCalls(obj) {
|
|
154
|
+
return !!obj['tool_calls'] && Array.isArray(obj['tool_calls']);
|
|
155
|
+
}
|
|
156
|
+
isString(value) {
|
|
157
|
+
return typeof value === 'string';
|
|
158
|
+
}
|
|
159
|
+
isValidToolCall(call) {
|
|
160
|
+
return this.isValidObject(call);
|
|
161
|
+
}
|
|
162
|
+
isValidFunction(func) {
|
|
163
|
+
return this.isValidObject(func);
|
|
164
|
+
}
|
|
165
|
+
// Helper functions for parsing
|
|
166
|
+
parseToolCallsArray(toolCallsData) {
|
|
167
|
+
if (!Array.isArray(toolCallsData))
|
|
168
|
+
return [];
|
|
169
|
+
return toolCallsData
|
|
170
|
+
.filter(this.isValidToolCall.bind(this))
|
|
171
|
+
.map(call => this.parseToolCall(call));
|
|
172
|
+
}
|
|
173
|
+
parseToolCall(call) {
|
|
174
|
+
const id = this.extractStringValue(call['id']) || this.generateCallId();
|
|
175
|
+
const functionData = call['function'];
|
|
176
|
+
if (!this.isValidFunction(functionData)) {
|
|
177
|
+
return this.createDefaultToolCall(id);
|
|
178
|
+
}
|
|
179
|
+
const name = this.extractStringValue(functionData['name']) || 'unknown_function';
|
|
180
|
+
const args = this.extractArguments(functionData['arguments']);
|
|
181
|
+
return {
|
|
182
|
+
id,
|
|
183
|
+
type: 'function',
|
|
184
|
+
function: { name, arguments: args }
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
extractStringValue(value) {
|
|
188
|
+
return this.isString(value) ? value : null;
|
|
189
|
+
}
|
|
190
|
+
extractArguments(args) {
|
|
191
|
+
if (this.isString(args)) {
|
|
192
|
+
return args;
|
|
193
|
+
}
|
|
194
|
+
return JSON.stringify(args || {});
|
|
195
|
+
}
|
|
196
|
+
generateCallId() {
|
|
197
|
+
return `call_${Math.random().toString(36).substr(2, 15)}`;
|
|
198
|
+
}
|
|
199
|
+
createDefaultToolCall(id) {
|
|
200
|
+
return {
|
|
201
|
+
id,
|
|
202
|
+
type: 'function',
|
|
203
|
+
function: { name: 'unknown_function', arguments: '{}' }
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
createToolCallFromArgs(functionName, args) {
|
|
207
|
+
return {
|
|
208
|
+
id: this.generateCallId(),
|
|
209
|
+
type: 'function',
|
|
210
|
+
function: {
|
|
211
|
+
name: functionName,
|
|
212
|
+
arguments: JSON.stringify(args)
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
async tryParseDirectToolCalls(responseText) {
|
|
217
|
+
try {
|
|
218
|
+
const parsed = JSON.parse(responseText);
|
|
219
|
+
if (this.isValidObject(parsed) && this.hasToolCalls(parsed)) {
|
|
220
|
+
return this.parseToolCallsArray(parsed['tool_calls']);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (parseError) {
|
|
224
|
+
// Try with JSON repair if standard parsing fails
|
|
225
|
+
try {
|
|
226
|
+
const { repairAndParseJson } = await import('../utils/json-repair.js');
|
|
227
|
+
const repairResult = repairAndParseJson(responseText);
|
|
228
|
+
if (repairResult.success && this.isValidObject(repairResult.value)) {
|
|
229
|
+
const valueObj = repairResult.value;
|
|
230
|
+
if (this.hasToolCalls(valueObj)) {
|
|
231
|
+
return this.parseToolCallsArray(valueObj['tool_calls']);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch (repairError) {
|
|
236
|
+
// JSON repair also failed, continue with other methods
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Extract JSON objects from text, handling various formats
|
|
243
|
+
*/
|
|
244
|
+
extractJsonObjects(text) {
|
|
245
|
+
const objects = [];
|
|
246
|
+
// Try parsing the entire text as JSON first
|
|
247
|
+
try {
|
|
248
|
+
const parsed = JSON.parse(text);
|
|
249
|
+
objects.push(parsed);
|
|
250
|
+
return objects;
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
// Continue with extraction methods
|
|
254
|
+
}
|
|
255
|
+
// Look for JSON objects in code blocks or plain text
|
|
256
|
+
const jsonPatterns = [
|
|
257
|
+
/```json\s*(\{[\s\S]*?\})\s*```/g,
|
|
258
|
+
/```\s*(\{[\s\S]*?\})\s*```/g,
|
|
259
|
+
/(\{[^{}]*\{[^{}]*\}[^{}]*\})/g, // Nested objects
|
|
260
|
+
/(\{[^{}]+\})/g // Simple objects
|
|
261
|
+
];
|
|
262
|
+
for (const pattern of jsonPatterns) {
|
|
263
|
+
let match;
|
|
264
|
+
while ((match = pattern.exec(text)) !== null) {
|
|
265
|
+
const jsonText = match[1];
|
|
266
|
+
if (jsonText) {
|
|
267
|
+
try {
|
|
268
|
+
const parsed = JSON.parse(jsonText);
|
|
269
|
+
objects.push(parsed);
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
// Invalid JSON, continue
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return objects;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Get the expected tool from request
|
|
281
|
+
*/
|
|
282
|
+
getExpectedTool(request) {
|
|
283
|
+
if (!request.tools || request.tools.length === 0)
|
|
284
|
+
return null;
|
|
285
|
+
// If tool_choice specifies a function, use that
|
|
286
|
+
if (request.tool_choice && typeof request.tool_choice === 'object' && 'function' in request.tool_choice) {
|
|
287
|
+
const toolChoice = request.tool_choice;
|
|
288
|
+
return request.tools.find(tool => tool.function.name === toolChoice.function.name) || null;
|
|
289
|
+
}
|
|
290
|
+
// Otherwise use the first tool
|
|
291
|
+
return request.tools[0] || null;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Check if an object looks like function arguments for the expected tool
|
|
295
|
+
*/
|
|
296
|
+
looksLikeFunctionArgs(obj, expectedTool) {
|
|
297
|
+
// Get expected parameter names from tool schema
|
|
298
|
+
const expectedParams = expectedTool.function.parameters?.['properties'];
|
|
299
|
+
if (!expectedParams)
|
|
300
|
+
return true; // If no schema, assume it's valid
|
|
301
|
+
const expectedKeys = Object.keys(expectedParams);
|
|
302
|
+
const objKeys = Object.keys(obj);
|
|
303
|
+
// Check if at least some expected keys are present
|
|
304
|
+
const hasExpectedKeys = expectedKeys.some(key => objKeys.includes(key));
|
|
305
|
+
return hasExpectedKeys;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
// Adapt OpenAI Request to MCP Request
|
|
309
|
+
export function adaptOpenAIRequestToMCP(request) {
|
|
310
|
+
// (1) Filter messages and extract SystemMessage
|
|
311
|
+
const systemMessages = request.messages.filter(msg => msg.role === 'system');
|
|
312
|
+
const filteredMessages = request.messages
|
|
313
|
+
.filter(msg => msg.role !== 'system') // 'system' を除外
|
|
314
|
+
.map(msg => ({
|
|
315
|
+
role: msg.role, // 明示的に型をキャスト
|
|
316
|
+
content: { type: 'text', text: msg.content } // type を "text" に固定
|
|
317
|
+
}));
|
|
318
|
+
// Convert tool_choice to string for system prompt generation
|
|
319
|
+
const toolChoiceString = typeof request.tool_choice === 'string'
|
|
320
|
+
? request.tool_choice
|
|
321
|
+
: request.tool_choice?.type === 'function'
|
|
322
|
+
? request.tool_choice.function.name
|
|
323
|
+
: request.tool_choice?.type === 'tool'
|
|
324
|
+
? request.tool_choice.name
|
|
325
|
+
: 'none';
|
|
326
|
+
const systemPrompt = [
|
|
327
|
+
...systemMessages.map(msg => msg.content),
|
|
328
|
+
createSystemPromptFromTools(request.tools || [], toolChoiceString),
|
|
329
|
+
].join('\n');
|
|
330
|
+
// Generate MCPRequest with type-safe approach
|
|
331
|
+
const mcpRequest = {
|
|
332
|
+
messages: filteredMessages,
|
|
333
|
+
systemPrompt,
|
|
334
|
+
includeContext: 'none',
|
|
335
|
+
// Add tools if available (convert OpenAI format to MCP format)
|
|
336
|
+
...(request.tools && request.tools.length > 0 && { tools: request.tools }),
|
|
337
|
+
// Add tool_choice if specified
|
|
338
|
+
...(request.tool_choice && request.tool_choice !== 'auto' && { tool_choice: request.tool_choice }),
|
|
339
|
+
};
|
|
340
|
+
// Conditionally add optional properties
|
|
341
|
+
if (request.max_tokens !== undefined) {
|
|
342
|
+
mcpRequest.maxTokens = request.max_tokens;
|
|
343
|
+
}
|
|
344
|
+
if (request.temperature !== undefined) {
|
|
345
|
+
mcpRequest.temperature = request.temperature;
|
|
346
|
+
}
|
|
347
|
+
if (request.stop !== undefined) {
|
|
348
|
+
mcpRequest.stopSequences = request.stop;
|
|
349
|
+
}
|
|
350
|
+
return mcpRequest;
|
|
351
|
+
}
|
|
352
|
+
// Generates a system prompt string based on the provided tools and tool choices.
|
|
353
|
+
/**
|
|
354
|
+
* Creates a comprehensive system prompt from available tools and tool choice
|
|
355
|
+
* Based on OpenAI Function Calling standard format
|
|
356
|
+
*/
|
|
357
|
+
export function createSystemPromptFromTools(tools, toolChoice) {
|
|
358
|
+
// Handle case with no tools
|
|
359
|
+
if (!tools || tools.length === 0) {
|
|
360
|
+
return 'You are a helpful assistant. No tools are currently available for this request.';
|
|
361
|
+
}
|
|
362
|
+
// Build the system prompt with explicit Function Calling instructions
|
|
363
|
+
// Based on OpenAI Function Calls specification
|
|
364
|
+
return `# Function Calling Assistant
|
|
365
|
+
|
|
366
|
+
⚠️ **CRITICAL JSON REQUIREMENT**: All JSON responses MUST be properly escaped to prevent parsing errors.
|
|
367
|
+
|
|
368
|
+
You are a helpful assistant that responds using function calls when tools are available.
|
|
369
|
+
|
|
370
|
+
## Available Functions
|
|
371
|
+
${tools.map(tool => `- ${tool.function.name}: ${tool.function.description}`).join('\n')}
|
|
372
|
+
|
|
373
|
+
## Function Call Requirements
|
|
374
|
+
${toolChoice && toolChoice !== 'none' && toolChoice !== 'auto'
|
|
375
|
+
? `You MUST call the "${toolChoice}" function for this request.`
|
|
376
|
+
: 'You MUST use function calls to respond when appropriate.'}
|
|
377
|
+
|
|
378
|
+
## Function Schemas
|
|
379
|
+
${tools.map(tool => `
|
|
380
|
+
### ${tool.function.name}
|
|
381
|
+
- Description: ${tool.function.description}
|
|
382
|
+
- Parameters: ${JSON.stringify(tool.function.parameters, null, 2)}
|
|
383
|
+
`).join('\n')}
|
|
384
|
+
|
|
385
|
+
## Response Format
|
|
386
|
+
When making function calls, respond with a JSON object containing a "tool_calls" array:
|
|
387
|
+
|
|
388
|
+
{
|
|
389
|
+
"tool_calls": [
|
|
390
|
+
{
|
|
391
|
+
"id": "call_[random_string]",
|
|
392
|
+
"type": "function",
|
|
393
|
+
"function": {
|
|
394
|
+
"name": "[function_name]",
|
|
395
|
+
"arguments": "[json_string_with_arguments]"
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
]
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
## Critical JSON Formatting Requirements
|
|
402
|
+
|
|
403
|
+
### JSON Escaping Rules (MANDATORY)
|
|
404
|
+
- **Double Quotes**: Always escape with \\" inside JSON strings
|
|
405
|
+
- **Backslashes**: Always escape with \\\\ inside JSON strings
|
|
406
|
+
- **Newlines**: Use \\n for line breaks in JSON strings
|
|
407
|
+
- **Tab Characters**: Use \\t for tabs in JSON strings
|
|
408
|
+
|
|
409
|
+
### Function Call Structure
|
|
410
|
+
- The "id" field should be "call_" followed by a random string
|
|
411
|
+
- The "type" field must always be "function"
|
|
412
|
+
- The "arguments" field must be a valid JSON string (not an object)
|
|
413
|
+
- Multiple function calls can be made by adding more objects to the tool_calls array
|
|
414
|
+
- Ensure your function arguments match the required schema exactly
|
|
415
|
+
- **ALL string values in arguments must follow the escaping rules above**
|
|
416
|
+
|
|
417
|
+
Make function calls as needed to fulfill the user's request.`;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Create a CreateMessageCallback from an MCP Server instance
|
|
421
|
+
*/
|
|
422
|
+
export function createMessageCallbackFromMCPServer(server) {
|
|
423
|
+
return async (request) => {
|
|
424
|
+
try {
|
|
425
|
+
// Convert request to MCP format
|
|
426
|
+
const mcpMessages = request.messages
|
|
427
|
+
.filter((msg) => msg.role !== 'tool') // Filter out tool messages as MCP doesn't support them
|
|
428
|
+
.map((msg) => ({
|
|
429
|
+
role: msg.role,
|
|
430
|
+
content: { type: 'text', text: msg.content.text },
|
|
431
|
+
}));
|
|
432
|
+
// Create MCP request with only defined values
|
|
433
|
+
const mcpRequest = {
|
|
434
|
+
messages: mcpMessages,
|
|
435
|
+
includeContext: request.includeContext || 'none',
|
|
436
|
+
};
|
|
437
|
+
if (request.maxTokens !== undefined) {
|
|
438
|
+
mcpRequest['maxTokens'] = request.maxTokens;
|
|
439
|
+
}
|
|
440
|
+
if (request.temperature !== undefined) {
|
|
441
|
+
mcpRequest['temperature'] = request.temperature;
|
|
442
|
+
}
|
|
443
|
+
if (request.systemPrompt !== undefined) {
|
|
444
|
+
mcpRequest['systemPrompt'] = request.systemPrompt;
|
|
445
|
+
}
|
|
446
|
+
// Call MCP createMessage method with type assertion
|
|
447
|
+
const result = await server.createMessage(mcpRequest);
|
|
448
|
+
// Build response object conditionally
|
|
449
|
+
const response = {
|
|
450
|
+
content: { type: 'text', text: String(result.content?.text || '') },
|
|
451
|
+
};
|
|
452
|
+
if (result.model) {
|
|
453
|
+
response.model = result.model;
|
|
454
|
+
}
|
|
455
|
+
if (result.stopReason) {
|
|
456
|
+
response.stopReason = result.stopReason;
|
|
457
|
+
}
|
|
458
|
+
if (result['tool_calls']) {
|
|
459
|
+
const toolCalls = result['tool_calls'];
|
|
460
|
+
response.tool_calls = toolCalls.map((call, index) => ({
|
|
461
|
+
id: `call_${index}`, // Generate ID for compatibility
|
|
462
|
+
...call,
|
|
463
|
+
}));
|
|
464
|
+
}
|
|
465
|
+
return response;
|
|
466
|
+
}
|
|
467
|
+
catch (error) {
|
|
468
|
+
console.error('Error in createMessageCallbackFromMCPServer:', error);
|
|
469
|
+
throw error;
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
// Tools for Function Calling (external use only)
|
|
474
|
+
// import { securityEvaluationTool } from './security-tools.js';
|
|
475
|
+
//# sourceMappingURL=chat-completion-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-completion-adapter.js","sourceRoot":"","sources":["../../src/security/chat-completion-adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AA6CxE,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAC9B,CAAC,CAAC,MAAM,CAAC;IACP,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IAC/E,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC5B,CAAC,CACH,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC;KACrB,KAAK,CACJ,CAAC,CAAC,MAAM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U,CAAC;YAC1C,CAAC;YACD,IAAI,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;gBACzB,MAAM,SAAS,GAAG,MAAM,CAAC,YAAY,CAGnC,CAAC;gBACH,QAAQ,CAAC,UAAU,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;oBACpD,EAAE,EAAE,QAAQ,KAAK,EAAE,EAAE,gCAAgC;oBACrD,GAAG,IAAI;iBACR,CAAC,CAAC,CAAC;YACN,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,8CAA8C,EAAE,KAAK,CAAC,CAAC;YACrE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AACD,iDAAiD;AACjD,gEAAgE"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { CommandHistoryEntry, FunctionCallContext, FunctionCallResult, FunctionCallHandler } from '../types/enhanced-security.js';
|
|
2
|
+
import { SecurityManager } from './manager.js';
|
|
3
|
+
import { SafetyEvaluationResult } from '../types/index.js';
|
|
4
|
+
import type { ElicitationHandler } from './evaluator-types.js';
|
|
5
|
+
import { CommandHistoryManager } from '../core/enhanced-history-manager.js';
|
|
6
|
+
import { CreateMessageCallback } from './chat-completion-adapter.js';
|
|
7
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Enhanced Security Evaluator (Unified)
|
|
10
|
+
* LLM-centric security evaluation with structured output
|
|
11
|
+
*/
|
|
12
|
+
export declare class EnhancedSafetyEvaluator {
|
|
13
|
+
private chatAdapter;
|
|
14
|
+
private promptGenerator;
|
|
15
|
+
private securityManager;
|
|
16
|
+
private historyManager;
|
|
17
|
+
private mcpServer;
|
|
18
|
+
private elicitationHandler;
|
|
19
|
+
private functionCallHandlers;
|
|
20
|
+
constructor(securityManager: SecurityManager, historyManager: CommandHistoryManager, createMessage: CreateMessageCallback, mcpServer?: Server, elicitationHandler?: ElicitationHandler);
|
|
21
|
+
/**
|
|
22
|
+
* Initialize Function Call handlers registry
|
|
23
|
+
*/
|
|
24
|
+
private initializeFunctionCallHandlers;
|
|
25
|
+
/**
|
|
26
|
+
* Handler for evaluate_command_security Function Call
|
|
27
|
+
* This is for external API usage - returns the same evaluation logic
|
|
28
|
+
*/
|
|
29
|
+
private handleEvaluateCommandSecurity;
|
|
30
|
+
/**
|
|
31
|
+
* Handler for reevaluate_with_user_intent Function Call
|
|
32
|
+
* This performs reevaluation with user intent context
|
|
33
|
+
*/
|
|
34
|
+
private handleReevaluateWithUserIntent;
|
|
35
|
+
/**
|
|
36
|
+
* Handler for reevaluate_with_additional_context Function Call
|
|
37
|
+
* This performs reevaluation with additional command history and execution results
|
|
38
|
+
*/
|
|
39
|
+
private handleReevaluateWithAdditionalContext;
|
|
40
|
+
/**
|
|
41
|
+
* Execute a Function Call by looking up the handler and calling it
|
|
42
|
+
*/
|
|
43
|
+
private executeFunctionCall;
|
|
44
|
+
/**
|
|
45
|
+
* Public method for testing Function Call execution
|
|
46
|
+
* Execute a Function Call with OpenAI-style function call object
|
|
47
|
+
*/
|
|
48
|
+
executeTestFunctionCall(functionCall: {
|
|
49
|
+
name: string;
|
|
50
|
+
arguments: string;
|
|
51
|
+
}, context: FunctionCallContext): Promise<FunctionCallResult>;
|
|
52
|
+
/**
|
|
53
|
+
* Get the function call registry for testing
|
|
54
|
+
*/
|
|
55
|
+
getFunctionCallRegistry(): Map<string, FunctionCallHandler>;
|
|
56
|
+
setMCPServer(server: Server): void;
|
|
57
|
+
/**
|
|
58
|
+
* Simple LLM-centric command safety evaluation
|
|
59
|
+
*/
|
|
60
|
+
evaluateCommandSafety(command: string, workingDirectory: string, history: CommandHistoryEntry[], comment?: string, forceUserConfirm?: boolean): Promise<SafetyEvaluationResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Handle elicitation and add result to messages
|
|
63
|
+
*/
|
|
64
|
+
private handleElicitationInLoop;
|
|
65
|
+
/**
|
|
66
|
+
* LLM-centric evaluation flow (improved with message-based approach)
|
|
67
|
+
*/
|
|
68
|
+
private performLLMCentricEvaluation;
|
|
69
|
+
/**
|
|
70
|
+
* Call LLM for evaluation using message-based approach
|
|
71
|
+
* Responsibility: Pure LLM communication and ToolCall parsing only
|
|
72
|
+
*/
|
|
73
|
+
private callLLMForEvaluationWithMessages;
|
|
74
|
+
/**
|
|
75
|
+
* Parse ToolCall to LLMEvaluationResult - Simple data transformation only
|
|
76
|
+
* Responsibility: Convert LLM Function Call into standardized evaluation result
|
|
77
|
+
*/
|
|
78
|
+
private parseToolCallToEvaluationResult;
|
|
79
|
+
/**
|
|
80
|
+
* Handle additional context requests by modifying messages
|
|
81
|
+
*/
|
|
82
|
+
private handleAdditionalContextRequest;
|
|
83
|
+
/**
|
|
84
|
+
* Get recent execution results for context
|
|
85
|
+
*/
|
|
86
|
+
private getRecentExecutionResults;
|
|
87
|
+
/**
|
|
88
|
+
* Elicit user intent using MCP protocol
|
|
89
|
+
*/
|
|
90
|
+
private elicitUserIntent;
|
|
91
|
+
/**
|
|
92
|
+
* Convert LLMEvaluationResult directly to SafetyEvaluationResult using factory pattern
|
|
93
|
+
*/
|
|
94
|
+
private convertLLMResultToSafetyResult;
|
|
95
|
+
/**
|
|
96
|
+
* Parse 'allow' tool - command is safe to execute
|
|
97
|
+
* Responsibility: Simple data transformation from ToolCall to LLMEvaluationResult
|
|
98
|
+
*/
|
|
99
|
+
private parseAllowTool;
|
|
100
|
+
/**
|
|
101
|
+
* Parse 'deny' tool - command is too dangerous
|
|
102
|
+
* Responsibility: Simple data transformation from ToolCall to LLMEvaluationResult
|
|
103
|
+
*/
|
|
104
|
+
private parseDenyTool;
|
|
105
|
+
/**
|
|
106
|
+
* Parse 'user_confirm' tool - requires user confirmation
|
|
107
|
+
* Responsibility: Simple data transformation from ToolCall to LLMEvaluationResult
|
|
108
|
+
*/
|
|
109
|
+
private parseUserConfirmTool;
|
|
110
|
+
/**
|
|
111
|
+
* Parse 'add_more_history' tool - needs additional context
|
|
112
|
+
* Responsibility: Simple data transformation from ToolCall to LLMEvaluationResult
|
|
113
|
+
*/
|
|
114
|
+
private parseAddMoreHistoryTool;
|
|
115
|
+
/**
|
|
116
|
+
* Parse 'ai_assistant_confirm' tool - needs AI assistant info
|
|
117
|
+
* Responsibility: Simple data transformation from ToolCall to LLMEvaluationResult
|
|
118
|
+
*/
|
|
119
|
+
private parseAiAssistantConfirmTool;
|
|
120
|
+
/**
|
|
121
|
+
* Helper: Parse and validate tool arguments with JSON repair fallback
|
|
122
|
+
*/
|
|
123
|
+
private parseToolArguments;
|
|
124
|
+
/**
|
|
125
|
+
* Expand $COMMAND variable in text with the actual command
|
|
126
|
+
*/
|
|
127
|
+
private expandCommandVariable;
|
|
128
|
+
/**
|
|
129
|
+
* Validator-side criteria adjustment
|
|
130
|
+
* Allows internal adjustment of security evaluation criteria
|
|
131
|
+
*/
|
|
132
|
+
adjustValidatorCriteria(criteriaText: string, appendMode?: boolean, backupExisting?: boolean): Promise<{
|
|
133
|
+
success: boolean;
|
|
134
|
+
message: string;
|
|
135
|
+
backupPath?: string;
|
|
136
|
+
criteriaPath: string;
|
|
137
|
+
}>;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=enhanced-evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enhanced-evaluator.d.ts","sourceRoot":"","sources":["../../src/security/enhanced-evaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAGnB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EAIpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EACL,sBAAsB,EAGvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAGV,kBAAkB,EACnB,MAAM,sBAA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