@sowonai/crewx-sdk 0.1.0-dev.0 → 0.1.0-dev.1
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 +115 -0
- package/dist/core/parallel/index.d.ts +2 -0
- package/dist/core/parallel/index.js +8 -0
- package/dist/core/parallel/index.js.map +1 -0
- package/dist/core/parallel/parallel-runner.d.ts +16 -0
- package/dist/core/parallel/parallel-runner.js +230 -0
- package/dist/core/parallel/parallel-runner.js.map +1 -0
- package/dist/core/parallel/types.d.ts +41 -0
- package/dist/core/parallel/types.js +3 -0
- package/dist/core/parallel/types.js.map +1 -0
- package/dist/core/providers/base-ai.provider.d.ts +12 -26
- package/dist/core/providers/base-ai.provider.js +37 -30
- package/dist/core/providers/base-ai.provider.js.map +1 -1
- package/dist/core/providers/base-ai.types.d.ts +15 -0
- package/dist/core/providers/base-ai.types.js +3 -0
- package/dist/core/providers/base-ai.types.js.map +1 -0
- package/dist/core/providers/claude.provider.d.ts +4 -3
- package/dist/core/providers/claude.provider.js +16 -33
- package/dist/core/providers/claude.provider.js.map +1 -1
- package/dist/core/providers/codex.provider.d.ts +2 -1
- package/dist/core/providers/codex.provider.js +4 -18
- package/dist/core/providers/codex.provider.js.map +1 -1
- package/dist/core/providers/copilot.provider.d.ts +4 -3
- package/dist/core/providers/copilot.provider.js +10 -28
- package/dist/core/providers/copilot.provider.js.map +1 -1
- package/dist/core/providers/gemini.provider.d.ts +4 -3
- package/dist/core/providers/gemini.provider.js +18 -36
- package/dist/core/providers/gemini.provider.js.map +1 -1
- package/dist/core/providers/index.d.ts +5 -0
- package/dist/core/providers/index.js +14 -0
- package/dist/core/providers/index.js.map +1 -0
- package/dist/core/providers/tool-call.types.d.ts +39 -0
- package/dist/core/providers/tool-call.types.js +3 -0
- package/dist/core/providers/tool-call.types.js.map +1 -0
- package/dist/core/remote/index.d.ts +3 -0
- package/dist/core/remote/index.js +20 -0
- package/dist/core/remote/index.js.map +1 -0
- package/dist/core/remote/remote-agent-manager.d.ts +24 -0
- package/dist/core/remote/remote-agent-manager.js +195 -0
- package/dist/core/remote/remote-agent-manager.js.map +1 -0
- package/dist/core/remote/remote-transport.d.ts +15 -0
- package/dist/core/remote/remote-transport.js +70 -0
- package/dist/core/remote/remote-transport.js.map +1 -0
- package/dist/core/remote/types.d.ts +79 -0
- package/dist/core/remote/types.js +3 -0
- package/dist/core/remote/types.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/base-message-formatter.d.ts +32 -0
- package/dist/utils/base-message-formatter.js +170 -0
- package/dist/utils/base-message-formatter.js.map +1 -0
- package/package.json +1 -1
- package/dist/core/providers/dynamic-provider.factory.d.ts +0 -55
- package/dist/core/providers/dynamic-provider.factory.js +0 -587
- package/dist/core/providers/dynamic-provider.factory.js.map +0 -1
- package/dist/version.d.ts +0 -1
- package/dist/version.js +0 -17
- package/dist/version.js.map +0 -1
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var _a;
|
|
12
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
3
|
exports.GeminiProvider = void 0;
|
|
14
|
-
const common_1 = require("@nestjs/common");
|
|
15
4
|
const base_ai_provider_1 = require("./base-ai.provider");
|
|
16
5
|
const ai_provider_interface_1 = require("./ai-provider.interface");
|
|
17
|
-
|
|
18
|
-
constructor(
|
|
19
|
-
super('GeminiProvider');
|
|
6
|
+
class GeminiProvider extends base_ai_provider_1.BaseAIProvider {
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
super('GeminiProvider', options);
|
|
20
9
|
this.name = ai_provider_interface_1.BuiltInProviders.GEMINI;
|
|
21
|
-
if (toolCallService) {
|
|
22
|
-
this.setToolCallService(toolCallService);
|
|
23
|
-
}
|
|
24
10
|
}
|
|
25
11
|
getCliCommand() {
|
|
26
12
|
return 'gemini';
|
|
@@ -44,18 +30,18 @@ let GeminiProvider = class GeminiProvider extends base_ai_provider_1.BaseAIProvi
|
|
|
44
30
|
return prompt;
|
|
45
31
|
}
|
|
46
32
|
async query(prompt, options = {}) {
|
|
47
|
-
if (!this.
|
|
48
|
-
this.logger.warn('
|
|
33
|
+
if (!this.toolCallHandler) {
|
|
34
|
+
this.logger.warn('Tool call handler not available, falling back to regular query');
|
|
49
35
|
return super.query(prompt, options);
|
|
50
36
|
}
|
|
51
37
|
return this.queryWithTools(prompt, options);
|
|
52
38
|
}
|
|
53
39
|
async execute(prompt, options = {}) {
|
|
54
|
-
if (this.
|
|
40
|
+
if (this.toolCallHandler) {
|
|
55
41
|
this.logger.log('GeminiProvider: Using queryWithTools in execute mode');
|
|
56
42
|
return this.queryWithTools(prompt, options);
|
|
57
43
|
}
|
|
58
|
-
this.logger.warn('GeminiProvider:
|
|
44
|
+
this.logger.warn('GeminiProvider: Tool call handler not available, falling back to base execute');
|
|
59
45
|
return super.execute(prompt, options);
|
|
60
46
|
}
|
|
61
47
|
parseToolUseProviderSpecific(parsed) {
|
|
@@ -81,18 +67,18 @@ let GeminiProvider = class GeminiProvider extends base_ai_provider_1.BaseAIProvi
|
|
|
81
67
|
return { isToolUse: false };
|
|
82
68
|
}
|
|
83
69
|
async queryWithTools(prompt, options = {}, maxTurns = 5) {
|
|
84
|
-
if (!this.
|
|
85
|
-
this.logger.warn('
|
|
70
|
+
if (!this.toolCallHandler) {
|
|
71
|
+
this.logger.warn('Tool call handler not available, falling back to regular query');
|
|
86
72
|
return super.query(prompt, options);
|
|
87
73
|
}
|
|
88
74
|
let turn = 0;
|
|
89
75
|
let currentPrompt = prompt;
|
|
90
|
-
const tools = this.
|
|
76
|
+
const tools = this.toolCallHandler.list();
|
|
91
77
|
currentPrompt = this.buildPromptWithTools(currentPrompt, tools);
|
|
92
78
|
while (turn < maxTurns) {
|
|
93
79
|
this.logger.log(`Tool call turn ${turn + 1}/${maxTurns}`);
|
|
94
80
|
if (options.taskId) {
|
|
95
|
-
this
|
|
81
|
+
this.appendTaskLog(options.taskId, 'INFO', `--- Tool Call Turn ${turn + 1}/${maxTurns} ---`);
|
|
96
82
|
}
|
|
97
83
|
const response = await super.query(currentPrompt, options);
|
|
98
84
|
if (!response.success) {
|
|
@@ -101,20 +87,20 @@ let GeminiProvider = class GeminiProvider extends base_ai_provider_1.BaseAIProvi
|
|
|
101
87
|
const toolUse = this.parseToolUse(response.content);
|
|
102
88
|
if (!toolUse.isToolUse) {
|
|
103
89
|
if (options.taskId) {
|
|
104
|
-
this
|
|
90
|
+
this.appendTaskLog(options.taskId, 'INFO', `No tool use detected, returning final response`);
|
|
105
91
|
}
|
|
106
92
|
return response;
|
|
107
93
|
}
|
|
108
94
|
this.logger.log(`Executing tool: ${toolUse.toolName} with input ${JSON.stringify(toolUse.toolInput)}`);
|
|
109
95
|
if (options.taskId) {
|
|
110
|
-
this
|
|
111
|
-
this
|
|
96
|
+
this.appendTaskLog(options.taskId, 'INFO', `🔧 Gemini requested tool: ${toolUse.toolName}`);
|
|
97
|
+
this.appendTaskLog(options.taskId, 'INFO', `Tool input: ${JSON.stringify(toolUse.toolInput, null, 2)}`);
|
|
112
98
|
}
|
|
113
|
-
const toolResult = await this.
|
|
99
|
+
const toolResult = await this.toolCallHandler.execute(toolUse.toolName, toolUse.toolInput);
|
|
114
100
|
this.logger.log(`Tool result: ${JSON.stringify(toolResult)}`);
|
|
115
101
|
if (options.taskId) {
|
|
116
|
-
this
|
|
117
|
-
this
|
|
102
|
+
this.appendTaskLog(options.taskId, 'INFO', `✅ Tool executed successfully`);
|
|
103
|
+
this.appendTaskLog(options.taskId, 'INFO', `Tool result preview: ${JSON.stringify(toolResult).substring(0, 500)}...`);
|
|
118
104
|
}
|
|
119
105
|
currentPrompt = this.buildToolResultPrompt(toolUse.toolName, toolUse.toolInput, toolResult);
|
|
120
106
|
turn++;
|
|
@@ -138,10 +124,6 @@ ${JSON.stringify(resultData, null, 2)}
|
|
|
138
124
|
|
|
139
125
|
Based on the tool execution result above, please provide a clear, detailed, and user-friendly response to the user's original request. Present the information in an organized and easy-to-read format.`;
|
|
140
126
|
}
|
|
141
|
-
}
|
|
127
|
+
}
|
|
142
128
|
exports.GeminiProvider = GeminiProvider;
|
|
143
|
-
exports.GeminiProvider = GeminiProvider = __decorate([
|
|
144
|
-
(0, common_1.Injectable)(),
|
|
145
|
-
__metadata("design:paramtypes", [typeof (_a = typeof base_ai_provider_1.ToolCallService !== "undefined" && base_ai_provider_1.ToolCallService) === "function" ? _a : Object])
|
|
146
|
-
], GeminiProvider);
|
|
147
129
|
//# sourceMappingURL=gemini.provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.provider.js","sourceRoot":"","sources":["../../../src/core/providers/gemini.provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gemini.provider.js","sourceRoot":"","sources":["../../../src/core/providers/gemini.provider.ts"],"names":[],"mappings":";;;AAAA,yDAAoD;AAEpD,mEAAiG;AAGjG,MAAa,cAAe,SAAQ,iCAAc;IAGhD,YAAY,UAAiC,EAAE;QAC7C,KAAK,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAH1B,SAAI,GAAG,wCAAgB,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CAAC;QAExF,OAAO,OAAO,QAAQ;;;EAGxB,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;;;wMAGmK,CAAC;IACvM,CAAC;CACF;AA3LD,wCA2LC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CodexProvider = exports.CopilotProvider = exports.GeminiProvider = exports.ClaudeProvider = exports.BaseAIProvider = void 0;
|
|
4
|
+
var base_ai_provider_1 = require("./base-ai.provider");
|
|
5
|
+
Object.defineProperty(exports, "BaseAIProvider", { enumerable: true, get: function () { return base_ai_provider_1.BaseAIProvider; } });
|
|
6
|
+
var claude_provider_1 = require("./claude.provider");
|
|
7
|
+
Object.defineProperty(exports, "ClaudeProvider", { enumerable: true, get: function () { return claude_provider_1.ClaudeProvider; } });
|
|
8
|
+
var gemini_provider_1 = require("./gemini.provider");
|
|
9
|
+
Object.defineProperty(exports, "GeminiProvider", { enumerable: true, get: function () { return gemini_provider_1.GeminiProvider; } });
|
|
10
|
+
var copilot_provider_1 = require("./copilot.provider");
|
|
11
|
+
Object.defineProperty(exports, "CopilotProvider", { enumerable: true, get: function () { return copilot_provider_1.CopilotProvider; } });
|
|
12
|
+
var codex_provider_1 = require("./codex.provider");
|
|
13
|
+
Object.defineProperty(exports, "CodexProvider", { enumerable: true, get: function () { return codex_provider_1.CodexProvider; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/providers/index.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAA3C,kHAAA,cAAc,OAAA;AACvB,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AACxB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface Tool {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
input_schema: {
|
|
5
|
+
type: 'object';
|
|
6
|
+
properties: Record<string, any>;
|
|
7
|
+
required?: string[];
|
|
8
|
+
};
|
|
9
|
+
output_schema?: {
|
|
10
|
+
type: 'object';
|
|
11
|
+
properties: Record<string, any>;
|
|
12
|
+
required?: string[];
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface ToolExecutionContext {
|
|
16
|
+
input: Record<string, any>;
|
|
17
|
+
runId?: string;
|
|
18
|
+
threadId?: string;
|
|
19
|
+
resourceId?: string;
|
|
20
|
+
agentId?: string;
|
|
21
|
+
tracingContext?: {
|
|
22
|
+
taskId?: string;
|
|
23
|
+
parentSpan?: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface ToolExecutionResult<T = any> {
|
|
27
|
+
success: boolean;
|
|
28
|
+
data?: T;
|
|
29
|
+
error?: string;
|
|
30
|
+
metadata?: {
|
|
31
|
+
executionTime?: number;
|
|
32
|
+
toolName?: string;
|
|
33
|
+
runId?: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface ToolCallHandler {
|
|
37
|
+
list(): Tool[];
|
|
38
|
+
execute(name: string, input: Record<string, any>, context?: Partial<Omit<ToolExecutionContext, 'input'>>): Promise<ToolExecutionResult>;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-call.types.js","sourceRoot":"","sources":["../../../src/core/providers/tool-call.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./remote-transport"), exports);
|
|
19
|
+
__exportStar(require("./remote-agent-manager"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/remote/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMA,0CAAwB;AACxB,qDAAmC;AACnC,yDAAuC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RemoteAgentConfig, RemoteTransport, RemoteAgentQueryRequest, RemoteAgentExecuteRequest, RemoteAgentResponse, ToolNameMapping } from './types';
|
|
2
|
+
export interface RemoteAgentManagerOptions {
|
|
3
|
+
transport?: RemoteTransport;
|
|
4
|
+
logger?: (message: string, level?: 'debug' | 'info' | 'warn' | 'error') => void;
|
|
5
|
+
}
|
|
6
|
+
export declare class RemoteAgentManager {
|
|
7
|
+
private transport;
|
|
8
|
+
private logger;
|
|
9
|
+
private configs;
|
|
10
|
+
constructor(options?: RemoteAgentManagerOptions);
|
|
11
|
+
loadConfig(agentId: string, config: RemoteAgentConfig): void;
|
|
12
|
+
loadConfigs(configs: Map<string, RemoteAgentConfig> | Record<string, RemoteAgentConfig>): void;
|
|
13
|
+
getConfig(agentId: string): RemoteAgentConfig | undefined;
|
|
14
|
+
isRemoteAgent(agentId: string): boolean;
|
|
15
|
+
getRemoteAgentIds(): string[];
|
|
16
|
+
query(agentId: string, request: RemoteAgentQueryRequest): Promise<RemoteAgentResponse>;
|
|
17
|
+
execute(agentId: string, request: RemoteAgentExecuteRequest): Promise<RemoteAgentResponse>;
|
|
18
|
+
private callRemoteTool;
|
|
19
|
+
normalizeResponse(result: any): RemoteAgentResponse;
|
|
20
|
+
normalizeUrl(url: string): string;
|
|
21
|
+
mapToolNames(agentId: string, mapping: Partial<ToolNameMapping>): void;
|
|
22
|
+
private validateConfig;
|
|
23
|
+
clearConfigs(): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteAgentManager = void 0;
|
|
4
|
+
const remote_transport_1 = require("./remote-transport");
|
|
5
|
+
class RemoteAgentManager {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
this.configs = new Map();
|
|
8
|
+
this.transport = options.transport || new remote_transport_1.FetchRemoteTransport();
|
|
9
|
+
this.logger = options.logger || (() => { });
|
|
10
|
+
}
|
|
11
|
+
loadConfig(agentId, config) {
|
|
12
|
+
this.validateConfig(config);
|
|
13
|
+
this.configs.set(agentId, config);
|
|
14
|
+
this.logger(`Loaded remote agent config for: ${agentId}`, 'debug');
|
|
15
|
+
}
|
|
16
|
+
loadConfigs(configs) {
|
|
17
|
+
const configMap = configs instanceof Map ? configs : new Map(Object.entries(configs));
|
|
18
|
+
for (const [agentId, config] of configMap) {
|
|
19
|
+
this.loadConfig(agentId, config);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getConfig(agentId) {
|
|
23
|
+
return this.configs.get(agentId);
|
|
24
|
+
}
|
|
25
|
+
isRemoteAgent(agentId) {
|
|
26
|
+
return this.configs.has(agentId);
|
|
27
|
+
}
|
|
28
|
+
getRemoteAgentIds() {
|
|
29
|
+
return Array.from(this.configs.keys());
|
|
30
|
+
}
|
|
31
|
+
async query(agentId, request) {
|
|
32
|
+
const config = this.getConfig(agentId);
|
|
33
|
+
if (!config) {
|
|
34
|
+
throw new Error(`Agent ${agentId} is not configured as a remote agent`);
|
|
35
|
+
}
|
|
36
|
+
const toolName = config.tools?.query ?? 'crewx_queryAgent';
|
|
37
|
+
const remoteAgentId = config.agentId ?? agentId;
|
|
38
|
+
const payload = {
|
|
39
|
+
agentId: remoteAgentId,
|
|
40
|
+
query: request.query,
|
|
41
|
+
};
|
|
42
|
+
if (request.context) {
|
|
43
|
+
payload.context = request.context;
|
|
44
|
+
}
|
|
45
|
+
if (request.model) {
|
|
46
|
+
payload.model = request.model;
|
|
47
|
+
}
|
|
48
|
+
if (request.platform) {
|
|
49
|
+
payload.platform = request.platform;
|
|
50
|
+
}
|
|
51
|
+
if (request.messages && request.messages.length > 0) {
|
|
52
|
+
payload.messages = request.messages;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const result = await this.callRemoteTool(config, toolName, payload);
|
|
56
|
+
return this.normalizeResponse(result);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
this.logger(`Remote query failed for agent ${agentId}: ${error.message}`, 'error');
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async execute(agentId, request) {
|
|
64
|
+
const config = this.getConfig(agentId);
|
|
65
|
+
if (!config) {
|
|
66
|
+
throw new Error(`Agent ${agentId} is not configured as a remote agent`);
|
|
67
|
+
}
|
|
68
|
+
const toolName = config.tools?.execute ?? 'crewx_executeAgent';
|
|
69
|
+
const remoteAgentId = config.agentId ?? agentId;
|
|
70
|
+
const payload = {
|
|
71
|
+
agentId: remoteAgentId,
|
|
72
|
+
task: request.task,
|
|
73
|
+
};
|
|
74
|
+
if (request.context) {
|
|
75
|
+
payload.context = request.context;
|
|
76
|
+
}
|
|
77
|
+
if (request.model) {
|
|
78
|
+
payload.model = request.model;
|
|
79
|
+
}
|
|
80
|
+
if (request.platform) {
|
|
81
|
+
payload.platform = request.platform;
|
|
82
|
+
}
|
|
83
|
+
if (request.messages && request.messages.length > 0) {
|
|
84
|
+
payload.messages = request.messages;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const result = await this.callRemoteTool(config, toolName, payload);
|
|
88
|
+
return this.normalizeResponse(result);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
this.logger(`Remote execute failed for agent ${agentId}: ${error.message}`, 'error');
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async callRemoteTool(config, toolName, args) {
|
|
96
|
+
const baseUrl = this.normalizeUrl(config.url);
|
|
97
|
+
const url = `${baseUrl}/mcp`;
|
|
98
|
+
const request = {
|
|
99
|
+
jsonrpc: '2.0',
|
|
100
|
+
id: `${toolName}-${Date.now()}`,
|
|
101
|
+
method: 'tools/call',
|
|
102
|
+
params: {
|
|
103
|
+
name: toolName,
|
|
104
|
+
arguments: args,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
const headers = {
|
|
108
|
+
...(config.headers || {}),
|
|
109
|
+
};
|
|
110
|
+
if (config.apiKey) {
|
|
111
|
+
headers['Authorization'] = `Bearer ${config.apiKey}`;
|
|
112
|
+
}
|
|
113
|
+
this.logger(`Calling remote MCP tool ${toolName} on ${baseUrl}`, 'debug');
|
|
114
|
+
const response = await this.transport.request(url, {
|
|
115
|
+
method: 'POST',
|
|
116
|
+
headers,
|
|
117
|
+
body: request,
|
|
118
|
+
timeoutMs: config.timeoutMs,
|
|
119
|
+
});
|
|
120
|
+
if (response.error) {
|
|
121
|
+
throw new Error(response.error.message || 'MCP server returned an error');
|
|
122
|
+
}
|
|
123
|
+
return response.result;
|
|
124
|
+
}
|
|
125
|
+
normalizeResponse(result) {
|
|
126
|
+
if (!result) {
|
|
127
|
+
return {
|
|
128
|
+
success: false,
|
|
129
|
+
content: [
|
|
130
|
+
{
|
|
131
|
+
type: 'text',
|
|
132
|
+
text: 'Remote agent returned no response.',
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (Array.isArray(result.content) && result.content.length > 0) {
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
const fallbackContent = result.response ?? result.implementation ?? result.message ?? result.output;
|
|
141
|
+
const text = typeof fallbackContent === 'string'
|
|
142
|
+
? fallbackContent
|
|
143
|
+
: JSON.stringify(fallbackContent ?? result, null, 2);
|
|
144
|
+
return {
|
|
145
|
+
...result,
|
|
146
|
+
content: [
|
|
147
|
+
{
|
|
148
|
+
type: 'text',
|
|
149
|
+
text,
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
normalizeUrl(url) {
|
|
155
|
+
if (!url) {
|
|
156
|
+
return url;
|
|
157
|
+
}
|
|
158
|
+
const trimmed = url.trim();
|
|
159
|
+
if (!trimmed) {
|
|
160
|
+
return trimmed;
|
|
161
|
+
}
|
|
162
|
+
const withoutTrailingSlash = trimmed.replace(/\/+$/, '');
|
|
163
|
+
return withoutTrailingSlash.toLowerCase().endsWith('/mcp')
|
|
164
|
+
? withoutTrailingSlash.slice(0, -4)
|
|
165
|
+
: withoutTrailingSlash;
|
|
166
|
+
}
|
|
167
|
+
mapToolNames(agentId, mapping) {
|
|
168
|
+
const config = this.getConfig(agentId);
|
|
169
|
+
if (!config) {
|
|
170
|
+
throw new Error(`Agent ${agentId} is not configured as a remote agent`);
|
|
171
|
+
}
|
|
172
|
+
config.tools = {
|
|
173
|
+
query: mapping.query ?? config.tools?.query ?? 'crewx_queryAgent',
|
|
174
|
+
execute: mapping.execute ?? config.tools?.execute ?? 'crewx_executeAgent',
|
|
175
|
+
};
|
|
176
|
+
this.logger(`Updated tool name mapping for agent ${agentId}`, 'debug');
|
|
177
|
+
}
|
|
178
|
+
validateConfig(config) {
|
|
179
|
+
if (!config.url) {
|
|
180
|
+
throw new Error('Remote agent configuration requires a URL');
|
|
181
|
+
}
|
|
182
|
+
if (!config.url.startsWith('http://') && !config.url.startsWith('https://')) {
|
|
183
|
+
throw new Error('Remote agent URL must start with http:// or https://');
|
|
184
|
+
}
|
|
185
|
+
if (config.type !== 'mcp-http') {
|
|
186
|
+
throw new Error(`Unsupported remote agent type: ${config.type}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
clearConfigs() {
|
|
190
|
+
this.configs.clear();
|
|
191
|
+
this.logger('Cleared all remote agent configurations', 'debug');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.RemoteAgentManager = RemoteAgentManager;
|
|
195
|
+
//# sourceMappingURL=remote-agent-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-agent-manager.js","sourceRoot":"","sources":["../../../src/core/remote/remote-agent-manager.ts"],"names":[],"mappings":";;;AAwBA,yDAA0D;AAkB1D,MAAa,kBAAkB;IAK7B,YAAY,UAAqC,EAAE;QAF3C,YAAO,GAAG,IAAI,GAAG,EAA6B,CAAC;QAGrD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,uCAAoB,EAAE,CAAC;QACjE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC7C,CAAC;IAOD,UAAU,CAAC,OAAe,EAAE,MAAyB;QACnD,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,mCAAmC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;IAMD,WAAW,CAAC,OAA2E;QACrF,MAAM,SAAS,GAAG,OAAO,YAAY,GAAG,CAAC,CAAC,CAAC,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AM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC5E,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,kCAAkC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IAMD,YAAY;QACV,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,yCAAyC,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;CACF;AApTD,gDAoTC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RemoteTransport, RemoteTransportRequestOptions } from './types';
|
|
2
|
+
export declare class FetchRemoteTransport implements RemoteTransport {
|
|
3
|
+
request<T = any>(url: string, options: RemoteTransportRequestOptions): Promise<T>;
|
|
4
|
+
}
|
|
5
|
+
export declare class MockRemoteTransport implements RemoteTransport {
|
|
6
|
+
private mockResponses;
|
|
7
|
+
private requestLog;
|
|
8
|
+
setMockResponse(pattern: string | RegExp, response: any): void;
|
|
9
|
+
getRequestLog(): Array<{
|
|
10
|
+
url: string;
|
|
11
|
+
options: RemoteTransportRequestOptions;
|
|
12
|
+
}>;
|
|
13
|
+
clearRequestLog(): void;
|
|
14
|
+
request<T = any>(url: string, options: RemoteTransportRequestOptions): Promise<T>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MockRemoteTransport = exports.FetchRemoteTransport = void 0;
|
|
4
|
+
class FetchRemoteTransport {
|
|
5
|
+
async request(url, options) {
|
|
6
|
+
const controller = new AbortController();
|
|
7
|
+
const timeoutMs = options.timeoutMs ?? 15000;
|
|
8
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
9
|
+
try {
|
|
10
|
+
const response = await fetch(url, {
|
|
11
|
+
method: options.method,
|
|
12
|
+
headers: {
|
|
13
|
+
'Content-Type': 'application/json',
|
|
14
|
+
...(options.headers || {}),
|
|
15
|
+
},
|
|
16
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
17
|
+
signal: controller.signal,
|
|
18
|
+
});
|
|
19
|
+
clearTimeout(timeout);
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
const text = await response.text();
|
|
22
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}${text ? ` - ${text}` : ''}`);
|
|
23
|
+
}
|
|
24
|
+
const contentType = response.headers.get('content-type');
|
|
25
|
+
if (contentType?.includes('application/json')) {
|
|
26
|
+
return (await response.json());
|
|
27
|
+
}
|
|
28
|
+
return (await response.text());
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
clearTimeout(timeout);
|
|
32
|
+
if (error.name === 'AbortError') {
|
|
33
|
+
throw new Error(`Request timeout after ${timeoutMs}ms`);
|
|
34
|
+
}
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.FetchRemoteTransport = FetchRemoteTransport;
|
|
40
|
+
class MockRemoteTransport {
|
|
41
|
+
constructor() {
|
|
42
|
+
this.mockResponses = new Map();
|
|
43
|
+
this.requestLog = [];
|
|
44
|
+
}
|
|
45
|
+
setMockResponse(pattern, response) {
|
|
46
|
+
const key = pattern instanceof RegExp ? pattern.source : pattern;
|
|
47
|
+
this.mockResponses.set(key, response);
|
|
48
|
+
}
|
|
49
|
+
getRequestLog() {
|
|
50
|
+
return [...this.requestLog];
|
|
51
|
+
}
|
|
52
|
+
clearRequestLog() {
|
|
53
|
+
this.requestLog = [];
|
|
54
|
+
}
|
|
55
|
+
async request(url, options) {
|
|
56
|
+
this.requestLog.push({ url, options });
|
|
57
|
+
for (const [pattern, response] of this.mockResponses) {
|
|
58
|
+
const regex = new RegExp(pattern);
|
|
59
|
+
if (regex.test(url)) {
|
|
60
|
+
if (typeof response === 'function') {
|
|
61
|
+
return response(url, options);
|
|
62
|
+
}
|
|
63
|
+
return response;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`No mock response configured for URL: ${url}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.MockRemoteTransport = MockRemoteTransport;
|
|
70
|
+
//# sourceMappingURL=remote-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-transport.js","sourceRoot":"","sources":["../../../src/core/remote/remote-transport.ts"],"names":[],"mappings":";;;AAYA,MAAa,oBAAoB;IAC/B,KAAK,CAAC,OAAO,CACX,GAAW,EACX,OAAsC;QAEtC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;QAC7C,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAC;QAEhE,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAChC,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;iBAC3B;gBACD,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;gBAC7D,MAAM,EAAE,UAAU,CAAC,MAAM;aAC1B,CAAC,CAAC;YAEH,YAAY,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Aa;QACX,OAAO,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;IAED,eAAe;QACb,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,OAAO,CACX,GAAW,EACX,OAAsC;QAEtC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;QAGvC,KAAK,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACrD,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;YAClC,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;gBACpB,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;oBACnC,OAAO,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;gBAChC,CAAC;gBACD,OAAO,QAAa,CAAC;YACvB,CAAC;QACH,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,wCAAwC,GAAG,EAAE,CAAC,CAAC;IACjE,CAAC;CACF;AApCD,kDAoCC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export interface RemoteAgentConfig {
|
|
2
|
+
type: 'mcp-http';
|
|
3
|
+
url: string;
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
agentId?: string;
|
|
8
|
+
tools?: {
|
|
9
|
+
query?: string;
|
|
10
|
+
execute?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface RemoteTransport {
|
|
14
|
+
request<T = any>(url: string, options: RemoteTransportRequestOptions): Promise<T>;
|
|
15
|
+
}
|
|
16
|
+
export interface RemoteTransportRequestOptions {
|
|
17
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
body?: any;
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface RemoteAgentQueryRequest {
|
|
23
|
+
agentId: string;
|
|
24
|
+
query: string;
|
|
25
|
+
context?: string;
|
|
26
|
+
model?: string;
|
|
27
|
+
platform?: string;
|
|
28
|
+
messages?: Array<{
|
|
29
|
+
text: string;
|
|
30
|
+
isAssistant: boolean;
|
|
31
|
+
metadata?: Record<string, any>;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
export interface RemoteAgentExecuteRequest {
|
|
35
|
+
agentId: string;
|
|
36
|
+
task: string;
|
|
37
|
+
context?: string;
|
|
38
|
+
model?: string;
|
|
39
|
+
platform?: string;
|
|
40
|
+
messages?: Array<{
|
|
41
|
+
text: string;
|
|
42
|
+
isAssistant: boolean;
|
|
43
|
+
metadata?: Record<string, any>;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
export interface RemoteAgentResponse {
|
|
47
|
+
content: Array<{
|
|
48
|
+
type: string;
|
|
49
|
+
text: string;
|
|
50
|
+
}>;
|
|
51
|
+
success?: boolean;
|
|
52
|
+
error?: string;
|
|
53
|
+
[key: string]: any;
|
|
54
|
+
}
|
|
55
|
+
export interface McpJsonRpcRequest {
|
|
56
|
+
jsonrpc: '2.0';
|
|
57
|
+
id: string;
|
|
58
|
+
method: string;
|
|
59
|
+
params?: Record<string, any>;
|
|
60
|
+
}
|
|
61
|
+
export interface McpJsonRpcResponse<T = any> {
|
|
62
|
+
jsonrpc: '2.0';
|
|
63
|
+
id: string;
|
|
64
|
+
result?: T;
|
|
65
|
+
error?: {
|
|
66
|
+
code: number;
|
|
67
|
+
message: string;
|
|
68
|
+
data?: any;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export interface ToolNameMapping {
|
|
72
|
+
query: string;
|
|
73
|
+
execute: string;
|
|
74
|
+
}
|
|
75
|
+
export interface RemoteAgentDescriptor {
|
|
76
|
+
localAgentId: string;
|
|
77
|
+
remoteAgentId: string;
|
|
78
|
+
config: RemoteAgentConfig;
|
|
79
|
+
}
|