@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,161 @@
|
|
|
1
|
+
import { ConfigManager } from '../core/config-manager.js';
|
|
2
|
+
import { ProcessManager } from '../core/process-manager.js';
|
|
3
|
+
import { TerminalManager } from '../core/terminal-manager.js';
|
|
4
|
+
import { FileManager } from '../core/file-manager.js';
|
|
5
|
+
import { MonitoringManager } from '../core/monitoring-manager.js';
|
|
6
|
+
import { StubServerManager } from '../core/server-manager.js';
|
|
7
|
+
import { SecurityManager } from '../security/manager.js';
|
|
8
|
+
import { CommandHistoryManager } from '../core/enhanced-history-manager.js';
|
|
9
|
+
import { ShellTools } from '../tools/shell-tools.js';
|
|
10
|
+
import { logger } from '../utils/helpers.js';
|
|
11
|
+
export { BackofficeServer } from '../backoffice/server.js';
|
|
12
|
+
export { MCPShellError } from '../utils/errors.js';
|
|
13
|
+
export { ShellExecuteParamsSchema, ShellGetExecutionParamsSchema, ShellSetDefaultWorkdirParamsSchema, FileListParamsSchema, FileReadParamsSchema, FileDeleteParamsSchema, TerminalListParamsSchema, TerminalGetParamsSchema, TerminalCloseParamsSchema, CleanupSuggestionsParamsSchema, AutoCleanupParamsSchema, CommandHistoryQueryParamsSchema, ServerCurrentParamsSchema, ServerListAttachableParamsSchema, ServerStartParamsSchema, ServerStopParamsSchema, ServerGetParamsSchema, ServerDetachParamsSchema, ServerReattachParamsSchema, } from '../types/schemas.js';
|
|
14
|
+
export { TerminalOperateParamsSchema } from '../types/quick-schemas.js';
|
|
15
|
+
export { logger };
|
|
16
|
+
export const TOOL_NAMES = [
|
|
17
|
+
'shell_execute',
|
|
18
|
+
'process_get_execution',
|
|
19
|
+
'shell_set_default_workdir',
|
|
20
|
+
'list_execution_outputs',
|
|
21
|
+
'read_execution_output',
|
|
22
|
+
'delete_execution_outputs',
|
|
23
|
+
'get_cleanup_suggestions',
|
|
24
|
+
'perform_auto_cleanup',
|
|
25
|
+
'terminal_operate',
|
|
26
|
+
'terminal_list',
|
|
27
|
+
'terminal_get_info',
|
|
28
|
+
'terminal_close',
|
|
29
|
+
'command_history_query',
|
|
30
|
+
'server_current',
|
|
31
|
+
'server_list_attachable',
|
|
32
|
+
'server_start',
|
|
33
|
+
'server_stop',
|
|
34
|
+
'server_get',
|
|
35
|
+
'server_detach',
|
|
36
|
+
'server_reattach',
|
|
37
|
+
];
|
|
38
|
+
export function createServerManager() {
|
|
39
|
+
return new StubServerManager();
|
|
40
|
+
}
|
|
41
|
+
function resolveWorkingDirectory(params, options) {
|
|
42
|
+
const paramRecord = params ?? {};
|
|
43
|
+
const cwdParam = typeof paramRecord['cwd'] === 'string' ? String(paramRecord['cwd']) : undefined;
|
|
44
|
+
return cwdParam || options.defaultWorkingDirectory || options.fallbackWorkingDirectory || process.cwd();
|
|
45
|
+
}
|
|
46
|
+
export async function dispatchToolCall(shellTools, serverManager, toolName, params, options = {}) {
|
|
47
|
+
const paramRecord = params ?? {};
|
|
48
|
+
switch (toolName) {
|
|
49
|
+
case 'shell_execute':
|
|
50
|
+
return shellTools.executeShellValidated(paramRecord);
|
|
51
|
+
case 'process_get_execution':
|
|
52
|
+
return shellTools.getExecutionValidated(paramRecord);
|
|
53
|
+
case 'shell_set_default_workdir':
|
|
54
|
+
return shellTools.setDefaultWorkingDirectoryValidated(paramRecord);
|
|
55
|
+
case 'list_execution_outputs':
|
|
56
|
+
return shellTools.listFilesValidated(paramRecord);
|
|
57
|
+
case 'read_execution_output':
|
|
58
|
+
return shellTools.readFileValidated(paramRecord);
|
|
59
|
+
case 'delete_execution_outputs':
|
|
60
|
+
return shellTools.deleteFilesValidated(paramRecord);
|
|
61
|
+
case 'get_cleanup_suggestions':
|
|
62
|
+
return shellTools.getCleanupSuggestionsValidated(paramRecord);
|
|
63
|
+
case 'perform_auto_cleanup':
|
|
64
|
+
return shellTools.performAutoCleanupValidated(paramRecord);
|
|
65
|
+
case 'terminal_operate':
|
|
66
|
+
return shellTools.terminalOperateValidated(paramRecord);
|
|
67
|
+
case 'terminal_list':
|
|
68
|
+
return shellTools.listTerminalsValidated(paramRecord);
|
|
69
|
+
case 'terminal_get_info':
|
|
70
|
+
return shellTools.getTerminalValidated(paramRecord);
|
|
71
|
+
case 'terminal_close':
|
|
72
|
+
return shellTools.closeTerminalValidated(paramRecord);
|
|
73
|
+
case 'command_history_query':
|
|
74
|
+
return shellTools.queryCommandHistoryValidated(paramRecord);
|
|
75
|
+
case 'server_current':
|
|
76
|
+
return serverManager.current();
|
|
77
|
+
case 'server_list_attachable': {
|
|
78
|
+
const cwd = resolveWorkingDirectory(params, options);
|
|
79
|
+
return serverManager.listAttachable({ cwd });
|
|
80
|
+
}
|
|
81
|
+
case 'server_start': {
|
|
82
|
+
const cwd = resolveWorkingDirectory(params, options);
|
|
83
|
+
const socketPath = typeof paramRecord['socket_path'] === 'string' ? String(paramRecord['socket_path']) : undefined;
|
|
84
|
+
const allowExisting = typeof paramRecord['allow_existing'] === 'boolean' ? Boolean(paramRecord['allow_existing']) : false;
|
|
85
|
+
return serverManager.start({
|
|
86
|
+
cwd,
|
|
87
|
+
...(socketPath ? { socketPath } : {}),
|
|
88
|
+
allowExisting,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
case 'server_stop': {
|
|
92
|
+
const serverId = typeof paramRecord['server_id'] === 'string' ? String(paramRecord['server_id']) : '';
|
|
93
|
+
const force = typeof paramRecord['force'] === 'boolean' ? Boolean(paramRecord['force']) : false;
|
|
94
|
+
await serverManager.stop({ serverId, force });
|
|
95
|
+
return { ok: true };
|
|
96
|
+
}
|
|
97
|
+
case 'server_get': {
|
|
98
|
+
const serverId = typeof paramRecord['server_id'] === 'string' ? String(paramRecord['server_id']) : '';
|
|
99
|
+
return serverManager.get({ serverId });
|
|
100
|
+
}
|
|
101
|
+
case 'server_detach': {
|
|
102
|
+
const serverId = typeof paramRecord['server_id'] === 'string' ? String(paramRecord['server_id']) : '';
|
|
103
|
+
await serverManager.detach({ serverId });
|
|
104
|
+
return { ok: true };
|
|
105
|
+
}
|
|
106
|
+
case 'server_reattach': {
|
|
107
|
+
const serverId = typeof paramRecord['server_id'] === 'string' ? String(paramRecord['server_id']) : '';
|
|
108
|
+
return serverManager.reattach({ serverId });
|
|
109
|
+
}
|
|
110
|
+
default:
|
|
111
|
+
throw new Error(`Unsupported tool: ${toolName}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export function createShellToolRuntime(options = {}) {
|
|
115
|
+
const fileManager = new FileManager();
|
|
116
|
+
const configManager = new ConfigManager();
|
|
117
|
+
const processManager = new ProcessManager(options.maxConcurrentProcesses ?? 50, options.outputDir ?? '/tmp/mcp-shell-outputs', fileManager);
|
|
118
|
+
const terminalManager = new TerminalManager();
|
|
119
|
+
const monitoringManager = new MonitoringManager();
|
|
120
|
+
const serverManager = createServerManager();
|
|
121
|
+
const enhancedConfig = configManager.getEnhancedSecurityConfig();
|
|
122
|
+
const commandHistoryManager = new CommandHistoryManager(enhancedConfig);
|
|
123
|
+
const securityManager = new SecurityManager();
|
|
124
|
+
if (options.enhancedConfigOverrides) {
|
|
125
|
+
securityManager.setEnhancedConfig(options.enhancedConfigOverrides);
|
|
126
|
+
}
|
|
127
|
+
if (securityManager.isEnhancedModeEnabled()) {
|
|
128
|
+
securityManager.initializeEnhancedEvaluator(commandHistoryManager, options.server, options.createMessage, options.elicitationHandler);
|
|
129
|
+
}
|
|
130
|
+
commandHistoryManager.loadHistory().catch((error) => {
|
|
131
|
+
logger.warn('Failed to load command history', { error: String(error) }, 'runtime');
|
|
132
|
+
});
|
|
133
|
+
if (options.defaultWorkingDirectory) {
|
|
134
|
+
try {
|
|
135
|
+
processManager.setDefaultWorkingDirectory(options.defaultWorkingDirectory);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
logger.warn('Failed to set default working directory', { error: String(error), workingDirectory: options.defaultWorkingDirectory }, 'runtime');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
processManager.setTerminalManager(terminalManager);
|
|
142
|
+
const shellTools = new ShellTools(processManager, terminalManager, fileManager, monitoringManager, securityManager, commandHistoryManager);
|
|
143
|
+
const cleanup = async () => {
|
|
144
|
+
processManager.cleanup();
|
|
145
|
+
terminalManager.cleanup();
|
|
146
|
+
await fileManager.cleanup();
|
|
147
|
+
monitoringManager.cleanup();
|
|
148
|
+
};
|
|
149
|
+
return {
|
|
150
|
+
processManager,
|
|
151
|
+
terminalManager,
|
|
152
|
+
fileManager,
|
|
153
|
+
monitoringManager,
|
|
154
|
+
securityManager,
|
|
155
|
+
commandHistoryManager,
|
|
156
|
+
shellTools,
|
|
157
|
+
serverManager,
|
|
158
|
+
cleanup
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=tool-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-runtime.js","sourceRoot":"","sources":["../../src/runtime/tool-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAsB,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAIzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,q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E,MAAM,CAAC,KAAK,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,uBAAuB,EAAE,EAC3E,SAAS,CACV,CAAC;QACJ,CAAC;IACH,CAAC;IAED,cAAc,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC;IAEnD,MAAM,UAAU,GAAG,IAAI,UAAU,CAC/B,cAAc,EACd,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,qBAAqB,CACtB,CAAC;IAEF,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE;QACzB,cAAc,CAAC,OAAO,EAAE,CAAC;QACzB,eAAe,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;QAC5B,iBAAiB,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC,CAAC;IAEF,OAAO;QACL,cAAc;QACd,eAAe;QACf,WAAW;QACX,iBAAiB;QACjB,eAAe;QACf,qBAAqB;QACrB,UAAU;QACV,aAAa;QACb,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export interface ToolDefinition {
|
|
4
|
+
type: 'function';
|
|
5
|
+
function: {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
parameters: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export type ToolDefinitions = Array<ToolDefinition>;
|
|
12
|
+
export interface CreateMessageCallback {
|
|
13
|
+
(request: {
|
|
14
|
+
messages: Array<{
|
|
15
|
+
role: 'user' | 'assistant' | 'tool';
|
|
16
|
+
content: {
|
|
17
|
+
type: 'text';
|
|
18
|
+
text: string;
|
|
19
|
+
};
|
|
20
|
+
tool_call_id?: string;
|
|
21
|
+
}>;
|
|
22
|
+
maxTokens?: number;
|
|
23
|
+
temperature?: number;
|
|
24
|
+
systemPrompt?: string;
|
|
25
|
+
includeContext?: 'none' | 'thisServer' | 'allServers';
|
|
26
|
+
stopSequences?: string[];
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
modelPreferences?: Record<string, unknown>;
|
|
29
|
+
tools?: ToolDefinitions;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
content: {
|
|
32
|
+
type: 'text';
|
|
33
|
+
text: string;
|
|
34
|
+
};
|
|
35
|
+
model?: string | undefined;
|
|
36
|
+
stopReason?: string | undefined;
|
|
37
|
+
tool_calls?: Array<{
|
|
38
|
+
id: string;
|
|
39
|
+
type: 'function';
|
|
40
|
+
function: {
|
|
41
|
+
name: string;
|
|
42
|
+
arguments: string;
|
|
43
|
+
};
|
|
44
|
+
}>;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
declare const CCCRequestSchema: z.ZodObject<{
|
|
48
|
+
model: z.ZodString;
|
|
49
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
50
|
+
role: z.ZodUnion<[z.ZodLiteral<"system">, z.ZodLiteral<"user">, z.ZodLiteral<"assistant">]>;
|
|
51
|
+
content: z.ZodString;
|
|
52
|
+
name: z.ZodOptional<z.ZodString>;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
content: string;
|
|
55
|
+
role: "system" | "user" | "assistant";
|
|
56
|
+
name?: string | undefined;
|
|
57
|
+
}, {
|
|
58
|
+
content: string;
|
|
59
|
+
role: "system" | "user" | "assistant";
|
|
60
|
+
name?: string | undefined;
|
|
61
|
+
}>, "many">;
|
|
62
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
63
|
+
max_tokens: z.ZodOptional<z.ZodNumber>;
|
|
64
|
+
stop: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
65
|
+
top_p: z.ZodOptional<z.ZodNumber>;
|
|
66
|
+
frequency_penalty: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
presence_penalty: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
69
|
+
type: z.ZodLiteral<"function">;
|
|
70
|
+
function: z.ZodObject<{
|
|
71
|
+
name: z.ZodString;
|
|
72
|
+
description: z.ZodString;
|
|
73
|
+
parameters: z.ZodObject<{
|
|
74
|
+
type: z.ZodLiteral<"object">;
|
|
75
|
+
properties: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
76
|
+
required: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
77
|
+
}, "strip", z.ZodTypeAny, {
|
|
78
|
+
type: "object";
|
|
79
|
+
properties: Record<string, unknown>;
|
|
80
|
+
required?: string[] | undefined;
|
|
81
|
+
}, {
|
|
82
|
+
type: "object";
|
|
83
|
+
properties: Record<string, unknown>;
|
|
84
|
+
required?: string[] | undefined;
|
|
85
|
+
}>;
|
|
86
|
+
}, "strip", z.ZodTypeAny, {
|
|
87
|
+
name: string;
|
|
88
|
+
description: string;
|
|
89
|
+
parameters: {
|
|
90
|
+
type: "object";
|
|
91
|
+
properties: Record<string, unknown>;
|
|
92
|
+
required?: string[] | undefined;
|
|
93
|
+
};
|
|
94
|
+
}, {
|
|
95
|
+
name: string;
|
|
96
|
+
description: string;
|
|
97
|
+
parameters: {
|
|
98
|
+
type: "object";
|
|
99
|
+
properties: Record<string, unknown>;
|
|
100
|
+
required?: string[] | undefined;
|
|
101
|
+
};
|
|
102
|
+
}>;
|
|
103
|
+
}, "strip", z.ZodTypeAny, {
|
|
104
|
+
function: {
|
|
105
|
+
name: string;
|
|
106
|
+
description: string;
|
|
107
|
+
parameters: {
|
|
108
|
+
type: "object";
|
|
109
|
+
properties: Record<string, unknown>;
|
|
110
|
+
required?: string[] | undefined;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
type: "function";
|
|
114
|
+
}, {
|
|
115
|
+
function: {
|
|
116
|
+
name: string;
|
|
117
|
+
description: string;
|
|
118
|
+
parameters: {
|
|
119
|
+
type: "object";
|
|
120
|
+
properties: Record<string, unknown>;
|
|
121
|
+
required?: string[] | undefined;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
type: "function";
|
|
125
|
+
}>, "many">>;
|
|
126
|
+
tool_choice: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"auto">, z.ZodLiteral<"none">, z.ZodObject<{
|
|
127
|
+
type: z.ZodLiteral<"function">;
|
|
128
|
+
function: z.ZodObject<{
|
|
129
|
+
name: z.ZodString;
|
|
130
|
+
}, "strip", z.ZodTypeAny, {
|
|
131
|
+
name: string;
|
|
132
|
+
}, {
|
|
133
|
+
name: string;
|
|
134
|
+
}>;
|
|
135
|
+
}, "strip", z.ZodTypeAny, {
|
|
136
|
+
function: {
|
|
137
|
+
name: string;
|
|
138
|
+
};
|
|
139
|
+
type: "function";
|
|
140
|
+
}, {
|
|
141
|
+
function: {
|
|
142
|
+
name: string;
|
|
143
|
+
};
|
|
144
|
+
type: "function";
|
|
145
|
+
}>, z.ZodObject<{
|
|
146
|
+
type: z.ZodLiteral<"tool">;
|
|
147
|
+
name: z.ZodString;
|
|
148
|
+
}, "strip", z.ZodTypeAny, {
|
|
149
|
+
type: "tool";
|
|
150
|
+
name: string;
|
|
151
|
+
}, {
|
|
152
|
+
type: "tool";
|
|
153
|
+
name: string;
|
|
154
|
+
}>]>>;
|
|
155
|
+
}, "strip", z.ZodTypeAny, {
|
|
156
|
+
messages: {
|
|
157
|
+
content: string;
|
|
158
|
+
role: "system" | "user" | "assistant";
|
|
159
|
+
name?: string | undefined;
|
|
160
|
+
}[];
|
|
161
|
+
model: string;
|
|
162
|
+
stop?: string[] | undefined;
|
|
163
|
+
temperature?: number | undefined;
|
|
164
|
+
tools?: {
|
|
165
|
+
function: {
|
|
166
|
+
name: string;
|
|
167
|
+
description: string;
|
|
168
|
+
parameters: {
|
|
169
|
+
type: "object";
|
|
170
|
+
properties: Record<string, unknown>;
|
|
171
|
+
required?: string[] | undefined;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
type: "function";
|
|
175
|
+
}[] | undefined;
|
|
176
|
+
tool_choice?: "auto" | "none" | {
|
|
177
|
+
function: {
|
|
178
|
+
name: string;
|
|
179
|
+
};
|
|
180
|
+
type: "function";
|
|
181
|
+
} | {
|
|
182
|
+
type: "tool";
|
|
183
|
+
name: string;
|
|
184
|
+
} | undefined;
|
|
185
|
+
max_tokens?: number | undefined;
|
|
186
|
+
top_p?: number | undefined;
|
|
187
|
+
frequency_penalty?: number | undefined;
|
|
188
|
+
presence_penalty?: number | undefined;
|
|
189
|
+
}, {
|
|
190
|
+
messages: {
|
|
191
|
+
content: string;
|
|
192
|
+
role: "system" | "user" | "assistant";
|
|
193
|
+
name?: string | undefined;
|
|
194
|
+
}[];
|
|
195
|
+
model: string;
|
|
196
|
+
stop?: string[] | undefined;
|
|
197
|
+
temperature?: number | undefined;
|
|
198
|
+
tools?: {
|
|
199
|
+
function: {
|
|
200
|
+
name: string;
|
|
201
|
+
description: string;
|
|
202
|
+
parameters: {
|
|
203
|
+
type: "object";
|
|
204
|
+
properties: Record<string, unknown>;
|
|
205
|
+
required?: string[] | undefined;
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
type: "function";
|
|
209
|
+
}[] | undefined;
|
|
210
|
+
tool_choice?: "auto" | "none" | {
|
|
211
|
+
function: {
|
|
212
|
+
name: string;
|
|
213
|
+
};
|
|
214
|
+
type: "function";
|
|
215
|
+
} | {
|
|
216
|
+
type: "tool";
|
|
217
|
+
name: string;
|
|
218
|
+
} | undefined;
|
|
219
|
+
max_tokens?: number | undefined;
|
|
220
|
+
top_p?: number | undefined;
|
|
221
|
+
frequency_penalty?: number | undefined;
|
|
222
|
+
presence_penalty?: number | undefined;
|
|
223
|
+
}>;
|
|
224
|
+
type CCCRequest = z.infer<typeof CCCRequestSchema>;
|
|
225
|
+
declare const CCCResponseSchema: z.ZodObject<{
|
|
226
|
+
choices: z.ZodArray<z.ZodObject<{
|
|
227
|
+
message: z.ZodObject<{
|
|
228
|
+
role: z.ZodLiteral<"assistant">;
|
|
229
|
+
content: z.ZodNullable<z.ZodString>;
|
|
230
|
+
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
231
|
+
id: z.ZodString;
|
|
232
|
+
type: z.ZodLiteral<"function">;
|
|
233
|
+
function: z.ZodObject<{
|
|
234
|
+
name: z.ZodString;
|
|
235
|
+
arguments: z.ZodString;
|
|
236
|
+
}, "strip", z.ZodTypeAny, {
|
|
237
|
+
name: string;
|
|
238
|
+
arguments: string;
|
|
239
|
+
}, {
|
|
240
|
+
name: string;
|
|
241
|
+
arguments: string;
|
|
242
|
+
}>;
|
|
243
|
+
}, "strip", z.ZodTypeAny, {
|
|
244
|
+
function: {
|
|
245
|
+
name: string;
|
|
246
|
+
arguments: string;
|
|
247
|
+
};
|
|
248
|
+
type: "function";
|
|
249
|
+
id: string;
|
|
250
|
+
}, {
|
|
251
|
+
function: {
|
|
252
|
+
name: string;
|
|
253
|
+
arguments: string;
|
|
254
|
+
};
|
|
255
|
+
type: "function";
|
|
256
|
+
id: string;
|
|
257
|
+
}>, "many">>;
|
|
258
|
+
}, "strip", z.ZodTypeAny, {
|
|
259
|
+
content: string | null;
|
|
260
|
+
role: "assistant";
|
|
261
|
+
tool_calls?: {
|
|
262
|
+
function: {
|
|
263
|
+
name: string;
|
|
264
|
+
arguments: string;
|
|
265
|
+
};
|
|
266
|
+
type: "function";
|
|
267
|
+
id: string;
|
|
268
|
+
}[] | undefined;
|
|
269
|
+
}, {
|
|
270
|
+
content: string | null;
|
|
271
|
+
role: "assistant";
|
|
272
|
+
tool_calls?: {
|
|
273
|
+
function: {
|
|
274
|
+
name: string;
|
|
275
|
+
arguments: string;
|
|
276
|
+
};
|
|
277
|
+
type: "function";
|
|
278
|
+
id: string;
|
|
279
|
+
}[] | undefined;
|
|
280
|
+
}>;
|
|
281
|
+
finish_reason: z.ZodUnion<[z.ZodLiteral<"stop">, z.ZodLiteral<"length">, z.ZodLiteral<"tool_calls">]>;
|
|
282
|
+
index: z.ZodOptional<z.ZodNumber>;
|
|
283
|
+
}, "strip", z.ZodTypeAny, {
|
|
284
|
+
message: {
|
|
285
|
+
content: string | null;
|
|
286
|
+
role: "assistant";
|
|
287
|
+
tool_calls?: {
|
|
288
|
+
function: {
|
|
289
|
+
name: string;
|
|
290
|
+
arguments: string;
|
|
291
|
+
};
|
|
292
|
+
type: "function";
|
|
293
|
+
id: string;
|
|
294
|
+
}[] | undefined;
|
|
295
|
+
};
|
|
296
|
+
finish_reason: "length" | "stop" | "tool_calls";
|
|
297
|
+
index?: number | undefined;
|
|
298
|
+
}, {
|
|
299
|
+
message: {
|
|
300
|
+
content: string | null;
|
|
301
|
+
role: "assistant";
|
|
302
|
+
tool_calls?: {
|
|
303
|
+
function: {
|
|
304
|
+
name: string;
|
|
305
|
+
arguments: string;
|
|
306
|
+
};
|
|
307
|
+
type: "function";
|
|
308
|
+
id: string;
|
|
309
|
+
}[] | undefined;
|
|
310
|
+
};
|
|
311
|
+
finish_reason: "length" | "stop" | "tool_calls";
|
|
312
|
+
index?: number | undefined;
|
|
313
|
+
}>, "many">;
|
|
314
|
+
usage: z.ZodOptional<z.ZodObject<{
|
|
315
|
+
prompt_tokens: z.ZodNumber;
|
|
316
|
+
completion_tokens: z.ZodNumber;
|
|
317
|
+
total_tokens: z.ZodNumber;
|
|
318
|
+
}, "strip", z.ZodTypeAny, {
|
|
319
|
+
prompt_tokens: number;
|
|
320
|
+
completion_tokens: number;
|
|
321
|
+
total_tokens: number;
|
|
322
|
+
}, {
|
|
323
|
+
prompt_tokens: number;
|
|
324
|
+
completion_tokens: number;
|
|
325
|
+
total_tokens: number;
|
|
326
|
+
}>>;
|
|
327
|
+
}, "strip", z.ZodTypeAny, {
|
|
328
|
+
choices: {
|
|
329
|
+
message: {
|
|
330
|
+
content: string | null;
|
|
331
|
+
role: "assistant";
|
|
332
|
+
tool_calls?: {
|
|
333
|
+
function: {
|
|
334
|
+
name: string;
|
|
335
|
+
arguments: string;
|
|
336
|
+
};
|
|
337
|
+
type: "function";
|
|
338
|
+
id: string;
|
|
339
|
+
}[] | undefined;
|
|
340
|
+
};
|
|
341
|
+
finish_reason: "length" | "stop" | "tool_calls";
|
|
342
|
+
index?: number | undefined;
|
|
343
|
+
}[];
|
|
344
|
+
usage?: {
|
|
345
|
+
prompt_tokens: number;
|
|
346
|
+
completion_tokens: number;
|
|
347
|
+
total_tokens: number;
|
|
348
|
+
} | undefined;
|
|
349
|
+
}, {
|
|
350
|
+
choices: {
|
|
351
|
+
message: {
|
|
352
|
+
content: string | null;
|
|
353
|
+
role: "assistant";
|
|
354
|
+
tool_calls?: {
|
|
355
|
+
function: {
|
|
356
|
+
name: string;
|
|
357
|
+
arguments: string;
|
|
358
|
+
};
|
|
359
|
+
type: "function";
|
|
360
|
+
id: string;
|
|
361
|
+
}[] | undefined;
|
|
362
|
+
};
|
|
363
|
+
finish_reason: "length" | "stop" | "tool_calls";
|
|
364
|
+
index?: number | undefined;
|
|
365
|
+
}[];
|
|
366
|
+
usage?: {
|
|
367
|
+
prompt_tokens: number;
|
|
368
|
+
completion_tokens: number;
|
|
369
|
+
total_tokens: number;
|
|
370
|
+
} | undefined;
|
|
371
|
+
}>;
|
|
372
|
+
type CCCResponse = z.infer<typeof CCCResponseSchema>;
|
|
373
|
+
export declare class CCCToMCPCMAdapter {
|
|
374
|
+
private createMessage;
|
|
375
|
+
constructor(createMessage: CreateMessageCallback);
|
|
376
|
+
static fromMCPServer(server: Server): CCCToMCPCMAdapter;
|
|
377
|
+
chatCompletion(request: CCCRequest): Promise<CCCResponse>;
|
|
378
|
+
/**
|
|
379
|
+
* Flexible response parsing inspired by content-parser.ts
|
|
380
|
+
* Handles various LLM response formats including content-based and tool_calls-based responses
|
|
381
|
+
*/
|
|
382
|
+
private parseFlexibleResponse;
|
|
383
|
+
private isValidObject;
|
|
384
|
+
private hasToolCalls;
|
|
385
|
+
private isString;
|
|
386
|
+
private isValidToolCall;
|
|
387
|
+
private isValidFunction;
|
|
388
|
+
private parseToolCallsArray;
|
|
389
|
+
private parseToolCall;
|
|
390
|
+
private extractStringValue;
|
|
391
|
+
private extractArguments;
|
|
392
|
+
private generateCallId;
|
|
393
|
+
private createDefaultToolCall;
|
|
394
|
+
private createToolCallFromArgs;
|
|
395
|
+
private tryParseDirectToolCalls;
|
|
396
|
+
/**
|
|
397
|
+
* Extract JSON objects from text, handling various formats
|
|
398
|
+
*/
|
|
399
|
+
private extractJsonObjects;
|
|
400
|
+
/**
|
|
401
|
+
* Get the expected tool from request
|
|
402
|
+
*/
|
|
403
|
+
private getExpectedTool;
|
|
404
|
+
/**
|
|
405
|
+
* Check if an object looks like function arguments for the expected tool
|
|
406
|
+
*/
|
|
407
|
+
private looksLikeFunctionArgs;
|
|
408
|
+
}
|
|
409
|
+
export declare function adaptOpenAIRequestToMCP(request: CCCRequest): {
|
|
410
|
+
messages: Array<{
|
|
411
|
+
role: "user" | "assistant";
|
|
412
|
+
content: {
|
|
413
|
+
type: "text";
|
|
414
|
+
text: string;
|
|
415
|
+
};
|
|
416
|
+
}>;
|
|
417
|
+
systemPrompt?: string;
|
|
418
|
+
includeContext?: "none" | "thisServer" | "allServers";
|
|
419
|
+
tools?: ToolDefinitions;
|
|
420
|
+
tool_choice?: "auto" | "none" | {
|
|
421
|
+
type: "function";
|
|
422
|
+
function: {
|
|
423
|
+
name: string;
|
|
424
|
+
};
|
|
425
|
+
} | {
|
|
426
|
+
type: "tool";
|
|
427
|
+
name: string;
|
|
428
|
+
};
|
|
429
|
+
maxTokens?: number;
|
|
430
|
+
temperature?: number;
|
|
431
|
+
stopSequences?: string[];
|
|
432
|
+
};
|
|
433
|
+
/**
|
|
434
|
+
* Creates a comprehensive system prompt from available tools and tool choice
|
|
435
|
+
* Based on OpenAI Function Calling standard format
|
|
436
|
+
*/
|
|
437
|
+
export declare function createSystemPromptFromTools(tools: ToolDefinitions, toolChoice: string): string;
|
|
438
|
+
/**
|
|
439
|
+
* Create a CreateMessageCallback from an MCP Server instance
|
|
440
|
+
*/
|
|
441
|
+
export declare function createMessageCallbackFromMCPServer(server: Server): CreateMessageCallback;
|
|
442
|
+
export {};
|
|
443
|
+
//# sourceMappingURL=chat-completion-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-completion-adapter.d.ts","sourceRoot":"","sources":["../../src/security/chat-completion-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACrC,CAAC;CACH;AAED,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,cAAc,CAAC,CAAC;AAGpD,MAAM,WAAW,qBAAqB;IACpC,CAAC,OAAO,EAAE;QACR,QAAQ,EAAE,KAAK,CAAC;YACd,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;YACpC,OAAO,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAC;gBAAC,IAAI,EAAE,MAAM,CAAA;aAAE,CAAC;YACxC,YAAY,CAAC,EAAE,MAAM,CAAC;SACvB,CAAC,CAAC;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,cAAc,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,YAAY,CAAC;QACtD,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;QACzB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACnC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAA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