@crewx/sdk 0.8.0-rc.79 → 0.8.0-rc.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/adapter/context-builder.test.d.ts +1 -0
- package/dist/__tests__/adapter/plugin-helper.test.d.ts +1 -0
- package/dist/__tests__/adapter/registration-integration.test.d.ts +1 -0
- package/dist/__tests__/adapter/scoped-store.test.d.ts +1 -0
- package/dist/__tests__/plugins/conversation.test.d.ts +1 -0
- package/dist/__tests__/testing/createMockContext.test.d.ts +1 -0
- package/dist/adapter/context-builder.d.ts +0 -9
- package/dist/adapter/index.d.ts +0 -1
- package/dist/adapter/plugin-helper.d.ts +0 -7
- package/dist/adapter/scoped-store.d.ts +0 -10
- package/dist/adapter/types.d.ts +0 -7
- package/dist/agent/resolver.d.ts +0 -13
- package/dist/boxing/box-storage.interface.d.ts +0 -4
- package/dist/boxing/box.service.d.ts +0 -4
- package/dist/boxing/box.types.d.ts +0 -4
- package/dist/boxing/context-builder.d.ts +0 -4
- package/dist/client/CrewxClient.d.ts +0 -32
- package/dist/client/index.d.ts +0 -1
- package/dist/client/index.js +1 -6
- package/dist/config/loader.browser.d.ts +0 -8
- package/dist/config/loader.d.ts +0 -12
- package/dist/conversation/__tests__/sqlite-provider.test.d.ts +1 -0
- package/dist/conversation/__tests__/to-task-reader.test.d.ts +1 -0
- package/dist/conversation/index.d.ts +0 -1
- package/dist/conversation/sqlite-provider.d.ts +0 -9
- package/dist/conversation/to-task-reader.d.ts +0 -11
- package/dist/conversation/to-template-messages.d.ts +0 -13
- package/dist/conversation/types.d.ts +0 -58
- package/dist/esm/client/index.js +1 -2
- package/dist/esm/hooks/index.js +7 -6
- package/dist/esm/index.js +79 -60
- package/dist/esm/plugins/index.js +52 -0
- package/dist/esm/testing/index.js +1 -0
- package/dist/esm/tools/node/index.js +36 -54
- package/dist/events/TypedEventEmitter.d.ts +0 -24
- package/dist/events/types.d.ts +0 -43
- package/dist/facade/Crewx.browser.d.ts +0 -40
- package/dist/facade/Crewx.d.ts +0 -163
- package/dist/hooks/define.d.ts +0 -1
- package/dist/hooks/dispatch.d.ts +0 -12
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.js +7 -24
- package/dist/hooks/observer.d.ts +0 -1
- package/dist/hooks/plugin.d.ts +0 -1
- package/dist/hooks/tool-normalize.d.ts +0 -26
- package/dist/hooks/types.d.ts +0 -1
- package/dist/hooks/yaml-plugin.d.ts +0 -1
- package/dist/index.browser.d.ts +0 -7
- package/dist/index.browser.js +2 -25
- package/dist/index.d.ts +0 -4
- package/dist/index.js +79 -151
- package/dist/layout/loader.d.ts +0 -20
- package/dist/layout/props-validator.d.ts +0 -6
- package/dist/layout/renderer.d.ts +0 -24
- package/dist/layout/types.d.ts +0 -42
- package/dist/parallel/agent-runtime.d.ts +0 -11
- package/dist/parallel/helpers.d.ts +0 -1
- package/dist/parallel/index.d.ts +0 -1
- package/dist/parallel/parallel-runner.d.ts +0 -8
- package/dist/parallel/types.d.ts +0 -24
- package/dist/parsers/agent-call.util.d.ts +0 -3
- package/dist/parsers/claude.parser.d.ts +0 -8
- package/dist/parsers/codex.parser.d.ts +0 -8
- package/dist/parsers/copilot.parser.d.ts +0 -9
- package/dist/parsers/gemini.parser.d.ts +0 -10
- package/dist/parsers/opencode.parser.d.ts +0 -10
- package/dist/parsers/router.d.ts +0 -5
- package/dist/paths.d.ts +1 -0
- package/dist/platform/BrowserFsAdapter.d.ts +0 -20
- package/dist/platform/IFsAdapter.d.ts +0 -23
- package/dist/platform/NodeFsAdapter.d.ts +0 -8
- package/dist/plugin/plugin-provider.d.ts +0 -22
- package/dist/plugin/types.d.ts +0 -31
- package/dist/plugin.d.ts +0 -27
- package/dist/plugins/conversation.d.ts +0 -2
- package/dist/plugins/file-logger.d.ts +0 -13
- package/dist/plugins/index.d.ts +0 -10
- package/dist/plugins/index.js +52 -19
- package/dist/plugins/sqlite-tracing.d.ts +0 -13
- package/dist/plugins/sqlite-tracing.spec.d.ts +1 -0
- package/dist/provider/bridge.browser.d.ts +0 -20
- package/dist/provider/bridge.d.ts +0 -47
- package/dist/provider/parse-usage.d.ts +0 -14
- package/dist/provider/register-api.d.ts +0 -7
- package/dist/provider/vercel-runtime.d.ts +0 -29
- package/dist/remote/index.d.ts +0 -6
- package/dist/remote/remote-agent-manager.d.ts +0 -31
- package/dist/remote/remote-provider.d.ts +0 -15
- package/dist/remote/remote-transport.d.ts +0 -17
- package/dist/remote/types.d.ts +0 -59
- package/dist/server/auth.d.ts +0 -16
- package/dist/server/handler.d.ts +0 -17
- package/dist/server/index.d.ts +0 -4
- package/dist/server/tool-adapter.d.ts +0 -16
- package/dist/template/engine.d.ts +0 -19
- package/dist/template/helpers/exec.browser.d.ts +0 -7
- package/dist/template/helpers/exec.d.ts +0 -45
- package/dist/template/helpers/fenced_code.d.ts +0 -16
- package/dist/template/helpers/format-conversation.d.ts +0 -22
- package/dist/template/helpers/include.d.ts +0 -15
- package/dist/template/helpers/p1p2.d.ts +0 -32
- package/dist/template/loader/DocumentLoader.d.ts +0 -30
- package/dist/template/types.d.ts +0 -30
- package/dist/testing/index.d.ts +0 -1
- package/dist/testing/index.js +1 -16
- package/dist/testing/mock-audit.d.ts +0 -1
- package/dist/testing/mock-context.d.ts +0 -1
- package/dist/testing/mock-logger.d.ts +0 -1
- package/dist/testing/mock-router.d.ts +0 -1
- package/dist/testing/mock-storage.d.ts +0 -1
- package/dist/testing/mock-store.d.ts +0 -1
- package/dist/tools/delegate.d.ts +0 -7
- package/dist/tools/index.d.ts +0 -4
- package/dist/tools/node/builtin.d.ts +0 -16
- package/dist/tools/node/index.d.ts +0 -20
- package/dist/tools/node/index.js +36 -59
- package/dist/types/index.d.ts +0 -20
- package/dist/types/task-log.types.d.ts +0 -4
- package/dist/utils/env-defaults.d.ts +0 -16
- package/dist/utils/glob-match.d.ts +0 -16
- package/dist/utils/id.d.ts +0 -15
- package/dist/utils/timestamp.d.ts +0 -1
- package/dist/utils/workspace.d.ts +0 -4
- package/package.json +24 -25
- package/dist/adapter/context-builder.js +0 -87
- package/dist/adapter/index.js +0 -21
- package/dist/adapter/plugin-helper.js +0 -45
- package/dist/adapter/scoped-store.js +0 -43
- package/dist/adapter/types.js +0 -23
- package/dist/agent/resolver.js +0 -46
- package/dist/boxing/box-storage.interface.js +0 -6
- package/dist/boxing/box.service.js +0 -73
- package/dist/boxing/box.types.js +0 -6
- package/dist/boxing/context-builder.js +0 -79
- package/dist/client/CrewxClient.js +0 -86
- package/dist/config/loader.browser.js +0 -59
- package/dist/config/loader.js +0 -95
- package/dist/conversation/index.js +0 -25
- package/dist/conversation/sqlite-provider.js +0 -178
- package/dist/conversation/to-task-reader.js +0 -28
- package/dist/conversation/to-template-messages.js +0 -34
- package/dist/conversation/types.js +0 -10
- package/dist/esm/agent/resolver.js +0 -41
- package/dist/esm/boxing/box-storage.interface.js +0 -5
- package/dist/esm/boxing/box.service.js +0 -69
- package/dist/esm/boxing/box.types.js +0 -5
- package/dist/esm/boxing/context-builder.js +0 -76
- package/dist/esm/client/CrewxClient.js +0 -82
- package/dist/esm/config/loader.browser.js +0 -54
- package/dist/esm/config/loader.js +0 -77
- package/dist/esm/events/TypedEventEmitter.js +0 -61
- package/dist/esm/events/types.js +0 -8
- package/dist/esm/facade/Crewx.browser.js +0 -310
- package/dist/esm/facade/Crewx.js +0 -941
- package/dist/esm/hooks/define.js +0 -10
- package/dist/esm/hooks/dispatch.js +0 -76
- package/dist/esm/hooks/observer.js +0 -56
- package/dist/esm/hooks/plugin.js +0 -12
- package/dist/esm/hooks/types.js +0 -9
- package/dist/esm/index.browser.js +0 -15
- package/dist/esm/layout/loader.js +0 -268
- package/dist/esm/layout/props-validator.js +0 -297
- package/dist/esm/layout/renderer.js +0 -180
- package/dist/esm/layout/types.js +0 -31
- package/dist/esm/parallel/agent-runtime.js +0 -21
- package/dist/esm/parallel/helpers.js +0 -214
- package/dist/esm/parallel/index.js +0 -5
- package/dist/esm/parallel/parallel-runner.js +0 -221
- package/dist/esm/parallel/types.js +0 -5
- package/dist/esm/parsers/agent-call.util.js +0 -15
- package/dist/esm/parsers/claude.parser.js +0 -64
- package/dist/esm/parsers/codex.parser.js +0 -97
- package/dist/esm/parsers/copilot.parser.js +0 -63
- package/dist/esm/parsers/gemini.parser.js +0 -43
- package/dist/esm/parsers/opencode.parser.js +0 -73
- package/dist/esm/parsers/router.js +0 -53
- package/dist/esm/platform/BrowserFsAdapter.js +0 -80
- package/dist/esm/platform/IFsAdapter.js +0 -2
- package/dist/esm/platform/NodeFsAdapter.js +0 -34
- package/dist/esm/plugin/plugin-provider.js +0 -202
- package/dist/esm/plugin/types.js +0 -8
- package/dist/esm/plugin.js +0 -25
- package/dist/esm/provider/bridge.browser.js +0 -43
- package/dist/esm/provider/bridge.js +0 -373
- package/dist/esm/provider/parse-usage.js +0 -80
- package/dist/esm/provider/register-api.js +0 -21
- package/dist/esm/provider/vercel-runtime.js +0 -310
- package/dist/esm/remote/index.js +0 -10
- package/dist/esm/remote/remote-agent-manager.js +0 -194
- package/dist/esm/remote/remote-provider.js +0 -98
- package/dist/esm/remote/remote-transport.js +0 -79
- package/dist/esm/remote/types.js +0 -8
- package/dist/esm/server/auth.js +0 -31
- package/dist/esm/server/handler.js +0 -72
- package/dist/esm/server/index.js +0 -5
- package/dist/esm/server/tool-adapter.js +0 -92
- package/dist/esm/template/engine.js +0 -100
- package/dist/esm/template/helpers/exec.browser.js +0 -31
- package/dist/esm/template/helpers/exec.js +0 -220
- package/dist/esm/template/helpers/fenced_code.js +0 -17
- package/dist/esm/template/helpers/include.js +0 -20
- package/dist/esm/template/helpers/p1p2.js +0 -83
- package/dist/esm/template/loader/DocumentLoader.js +0 -124
- package/dist/esm/template/types.js +0 -5
- package/dist/esm/tools/delegate.js +0 -57
- package/dist/esm/tools/index.js +0 -5
- package/dist/esm/tools/node/builtin.js +0 -541
- package/dist/esm/types/index.js +0 -27
- package/dist/esm/types/task-log.types.js +0 -5
- package/dist/esm/utils/env-defaults.js +0 -23
- package/dist/esm/utils/glob-match.js +0 -38
- package/dist/esm/utils/id.js +0 -46
- package/dist/esm/utils/workspace.js +0 -21
- package/dist/events/TypedEventEmitter.js +0 -65
- package/dist/events/types.js +0 -9
- package/dist/facade/Crewx.browser.js +0 -314
- package/dist/facade/Crewx.js +0 -1299
- package/dist/hooks/define.js +0 -13
- package/dist/hooks/dispatch.js +0 -147
- package/dist/hooks/observer.js +0 -60
- package/dist/hooks/plugin.js +0 -17
- package/dist/hooks/tool-normalize.js +0 -110
- package/dist/hooks/types.js +0 -12
- package/dist/hooks/yaml-plugin.js +0 -356
- package/dist/layout/loader.js +0 -305
- package/dist/layout/props-validator.js +0 -301
- package/dist/layout/renderer.js +0 -193
- package/dist/layout/types.js +0 -36
- package/dist/parallel/agent-runtime.js +0 -25
- package/dist/parallel/helpers.js +0 -219
- package/dist/parallel/index.js +0 -13
- package/dist/parallel/parallel-runner.js +0 -226
- package/dist/parallel/types.js +0 -6
- package/dist/parsers/agent-call.util.js +0 -19
- package/dist/parsers/api.parser.d.ts +0 -10
- package/dist/parsers/api.parser.js +0 -26
- package/dist/parsers/claude.parser.js +0 -67
- package/dist/parsers/codex.parser.js +0 -100
- package/dist/parsers/copilot.parser.js +0 -66
- package/dist/parsers/gemini.parser.js +0 -46
- package/dist/parsers/opencode.parser.js +0 -76
- package/dist/parsers/router.js +0 -56
- package/dist/platform/BrowserFsAdapter.js +0 -84
- package/dist/platform/IFsAdapter.js +0 -3
- package/dist/platform/NodeFsAdapter.js +0 -38
- package/dist/plugin/plugin-provider.js +0 -207
- package/dist/plugin/types.js +0 -9
- package/dist/plugin.js +0 -29
- package/dist/plugins/conversation.js +0 -59
- package/dist/plugins/file-logger.js +0 -87
- package/dist/plugins/sqlite-tracing.js +0 -112
- package/dist/provider/bridge.browser.js +0 -49
- package/dist/provider/bridge.js +0 -381
- package/dist/provider/mastra-runtime.d.ts +0 -45
- package/dist/provider/mastra-runtime.js +0 -208
- package/dist/provider/parse-usage.js +0 -83
- package/dist/provider/register-api.js +0 -24
- package/dist/provider/vercel-runtime.js +0 -347
- package/dist/remote/index.js +0 -32
- package/dist/remote/remote-agent-manager.js +0 -198
- package/dist/remote/remote-provider.js +0 -141
- package/dist/remote/remote-transport.js +0 -83
- package/dist/remote/types.js +0 -9
- package/dist/server/auth.js +0 -35
- package/dist/server/handler.js +0 -75
- package/dist/server/index.js +0 -9
- package/dist/server/tool-adapter.js +0 -95
- package/dist/template/engine.js +0 -137
- package/dist/template/helpers/exec.browser.js +0 -41
- package/dist/template/helpers/exec.js +0 -230
- package/dist/template/helpers/fenced_code.js +0 -20
- package/dist/template/helpers/format-conversation.js +0 -53
- package/dist/template/helpers/include.js +0 -23
- package/dist/template/helpers/p1p2.js +0 -90
- package/dist/template/loader/DocumentLoader.js +0 -128
- package/dist/template/types.js +0 -6
- package/dist/testing/mock-audit.js +0 -13
- package/dist/testing/mock-context.js +0 -68
- package/dist/testing/mock-logger.js +0 -27
- package/dist/testing/mock-router.js +0 -67
- package/dist/testing/mock-storage.js +0 -21
- package/dist/testing/mock-store.js +0 -8
- package/dist/tools/delegate.js +0 -60
- package/dist/tools/index.js +0 -9
- package/dist/tools/node/builtin.js +0 -547
- package/dist/types/index.js +0 -32
- package/dist/types/task-log.types.js +0 -6
- package/dist/utils/env-defaults.js +0 -27
- package/dist/utils/glob-match.js +0 -42
- package/dist/utils/id.js +0 -50
- package/dist/utils/timestamp.js +0 -13
- package/dist/utils/workspace.js +0 -58
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Pure function to extract token usage from provider CLI stdout.
|
|
4
|
-
* Supports Claude / Codex / Gemini / Copilot / OpenCode JSONL formats.
|
|
5
|
-
* Uses last-match semantics: if multiple usage events are found, the last one wins.
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.parseUsage = parseUsage;
|
|
9
|
-
function extractFromFlat(obj) {
|
|
10
|
-
// Pattern: { type: "usage", input_tokens, output_tokens, [cache_read_input_tokens], [cached_input_tokens] }
|
|
11
|
-
if (obj['type'] !== 'usage' || !('input_tokens' in obj))
|
|
12
|
-
return null;
|
|
13
|
-
const inputRaw = Number(obj['input_tokens'] ?? 0);
|
|
14
|
-
const outputTokens = Number(obj['output_tokens'] ?? 0);
|
|
15
|
-
// cache_read_input_tokens takes precedence over cached_input_tokens
|
|
16
|
-
const hasCacheRead = 'cache_read_input_tokens' in obj;
|
|
17
|
-
const cacheRead = hasCacheRead ? Number(obj['cache_read_input_tokens']) : undefined;
|
|
18
|
-
const cachedInput = 'cached_input_tokens' in obj ? Number(obj['cached_input_tokens']) : undefined;
|
|
19
|
-
const cachedInputTokens = cacheRead !== undefined ? cacheRead : (cachedInput ?? 0);
|
|
20
|
-
// For cache_read_input_tokens: normalize — input_tokens represents fresh-only, total = input + cache_read
|
|
21
|
-
const inputTokens = cacheRead !== undefined ? inputRaw + cacheRead : inputRaw;
|
|
22
|
-
return { inputTokens, outputTokens, cachedInputTokens };
|
|
23
|
-
}
|
|
24
|
-
function extractFromNested(obj) {
|
|
25
|
-
// Pattern: { usage: { input_tokens, output_tokens, [cache_read_input_tokens], [cached_input_tokens] } }
|
|
26
|
-
const usageRaw = obj['usage'];
|
|
27
|
-
if (!usageRaw || typeof usageRaw !== 'object' || Array.isArray(usageRaw))
|
|
28
|
-
return null;
|
|
29
|
-
const usage = usageRaw;
|
|
30
|
-
if (!('input_tokens' in usage))
|
|
31
|
-
return null;
|
|
32
|
-
const inputRaw = Number(usage['input_tokens'] ?? 0);
|
|
33
|
-
const outputTokens = Number(usage['output_tokens'] ?? 0);
|
|
34
|
-
const hasCacheRead = 'cache_read_input_tokens' in usage;
|
|
35
|
-
const cacheRead = hasCacheRead ? Number(usage['cache_read_input_tokens']) : undefined;
|
|
36
|
-
const cachedInput = 'cached_input_tokens' in usage ? Number(usage['cached_input_tokens']) : undefined;
|
|
37
|
-
const cachedInputTokens = cacheRead !== undefined ? cacheRead : (cachedInput ?? 0);
|
|
38
|
-
const inputTokens = cacheRead !== undefined ? inputRaw + cacheRead : inputRaw;
|
|
39
|
-
return { inputTokens, outputTokens, cachedInputTokens };
|
|
40
|
-
}
|
|
41
|
-
function extractFromOpencode(obj) {
|
|
42
|
-
// Pattern: { type: "step_finish", part: { tokens: { input, output, cache: { read, write } } } }
|
|
43
|
-
if (obj['type'] !== 'step_finish')
|
|
44
|
-
return null;
|
|
45
|
-
const part = obj['part'];
|
|
46
|
-
const tokens = part?.['tokens'];
|
|
47
|
-
if (!tokens)
|
|
48
|
-
return null;
|
|
49
|
-
const inputRaw = Number(tokens['input'] ?? 0);
|
|
50
|
-
const outputTokens = Number(tokens['output'] ?? 0);
|
|
51
|
-
const cache = tokens['cache'];
|
|
52
|
-
const cacheRead = cache ? Number(cache['read'] ?? 0) : 0;
|
|
53
|
-
// normalize: cached tokens are included in input total (same as claude cache_read handling)
|
|
54
|
-
const inputTokens = inputRaw + cacheRead;
|
|
55
|
-
return { inputTokens, outputTokens, cachedInputTokens: cacheRead };
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Parse token usage from a provider CLI stdout string.
|
|
59
|
-
*
|
|
60
|
-
* Accepts JSONL (one JSON object per line) or a single JSON document.
|
|
61
|
-
* Returns the **last** usage found (last-match semantics).
|
|
62
|
-
* Returns `undefined` if no usage data is present.
|
|
63
|
-
*/
|
|
64
|
-
function parseUsage(stdout) {
|
|
65
|
-
if (!stdout || !stdout.trim())
|
|
66
|
-
return undefined;
|
|
67
|
-
let last = null;
|
|
68
|
-
for (const line of stdout.split('\n')) {
|
|
69
|
-
if (!line.trim())
|
|
70
|
-
continue;
|
|
71
|
-
try {
|
|
72
|
-
const obj = JSON.parse(line);
|
|
73
|
-
const result = extractFromFlat(obj) ?? extractFromNested(obj) ?? extractFromOpencode(obj);
|
|
74
|
-
if (result)
|
|
75
|
-
last = result;
|
|
76
|
-
}
|
|
77
|
-
catch {
|
|
78
|
-
// non-JSON line — skip
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return last ?? undefined;
|
|
82
|
-
}
|
|
83
|
-
//# sourceMappingURL=parse-usage.js.map
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* api/* namespace를 provider registry에 등록.
|
|
4
|
-
*
|
|
5
|
-
* crewx.yaml에서 provider: api/openrouter 등을 쓰면
|
|
6
|
-
* createProvider('api/openrouter') → VercelProviderRuntime 반환.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.registerApiProviders = registerApiProviders;
|
|
10
|
-
const bridge_1 = require("./bridge");
|
|
11
|
-
const vercel_runtime_1 = require("./vercel-runtime");
|
|
12
|
-
function registerApiProviders(globalConfig) {
|
|
13
|
-
(0, bridge_1.registerProviderFactory)('api', (id, providerStr) => {
|
|
14
|
-
const apiKey = globalConfig?.apiKeys?.[id];
|
|
15
|
-
return new vercel_runtime_1.VercelProviderRuntime({
|
|
16
|
-
provider: providerStr,
|
|
17
|
-
model: '', // query() 호출 시 options.model로 override
|
|
18
|
-
apiKey,
|
|
19
|
-
maxSteps: globalConfig?.defaults?.maxSteps,
|
|
20
|
-
temperature: globalConfig?.defaults?.temperature,
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=register-api.js.map
|
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* VercelProviderRuntime — API 프로바이더를 위한 ProviderRuntime 구현.
|
|
4
|
-
*
|
|
5
|
-
* Vercel AI SDK의 generateText() + tool()을 직접 사용하여 tool calling loop를 처리한다.
|
|
6
|
-
* @ai-sdk/* 기반 모델 인스턴스를 생성하여 OpenRouter, OpenAI, Anthropic, Google 지원.
|
|
7
|
-
*/
|
|
8
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
}) : (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
}));
|
|
19
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
-
}) : function(o, v) {
|
|
22
|
-
o["default"] = v;
|
|
23
|
-
});
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.VercelProviderRuntime = void 0;
|
|
43
|
-
const bridge_1 = require("./bridge");
|
|
44
|
-
const DEFAULT_MAX_STEPS = 10;
|
|
45
|
-
const MAX_STEPS_LIMIT = 50;
|
|
46
|
-
class VercelProviderRuntime {
|
|
47
|
-
config;
|
|
48
|
-
constructor(config) {
|
|
49
|
-
this.config = config;
|
|
50
|
-
}
|
|
51
|
-
async query(message, options) {
|
|
52
|
-
return this._run(message, 'query', options);
|
|
53
|
-
}
|
|
54
|
-
async execute(message, options) {
|
|
55
|
-
return this._run(message, 'execute', options);
|
|
56
|
-
}
|
|
57
|
-
async _run(message, _mode, options) {
|
|
58
|
-
const { generateText, tool } = await Promise.resolve().then(() => __importStar(require('ai')));
|
|
59
|
-
// 1. Vercel AI SDK tools 변환
|
|
60
|
-
const vercelTools = this.convertTools(options?.tools ?? [], tool);
|
|
61
|
-
// 2. Model 인스턴스 생성 (Vercel AI SDK)
|
|
62
|
-
const model = this.createModel(options?.model);
|
|
63
|
-
// 3. maxSteps 계산
|
|
64
|
-
const maxSteps = Math.min(options?.maxSteps ?? this.config.maxSteps ?? DEFAULT_MAX_STEPS, MAX_STEPS_LIMIT);
|
|
65
|
-
try {
|
|
66
|
-
// 4. generateText() — tool loop 자동 실행
|
|
67
|
-
let stepIndex = 0;
|
|
68
|
-
const result = await generateText({
|
|
69
|
-
model,
|
|
70
|
-
system: options?.systemPrompt ?? undefined,
|
|
71
|
-
prompt: message,
|
|
72
|
-
tools: vercelTools,
|
|
73
|
-
maxSteps,
|
|
74
|
-
...(this.config.temperature !== undefined && { temperature: this.config.temperature }),
|
|
75
|
-
...(this.config.maxTokens !== undefined && { maxTokens: this.config.maxTokens }),
|
|
76
|
-
onStepFinish: (event) => {
|
|
77
|
-
stepIndex++;
|
|
78
|
-
if (!options?.onOutput)
|
|
79
|
-
return;
|
|
80
|
-
// tool call 기록 — Claude stream-json 호환 포맷
|
|
81
|
-
if (event.toolCalls && event.toolCalls.length > 0) {
|
|
82
|
-
for (const tc of event.toolCalls) {
|
|
83
|
-
options.onOutput(JSON.stringify({
|
|
84
|
-
type: 'assistant',
|
|
85
|
-
message: {
|
|
86
|
-
content: [{ type: 'tool_use', id: tc.toolCallId, name: tc.toolName, input: tc.args }],
|
|
87
|
-
},
|
|
88
|
-
}), 'stdout');
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// tool result 기록 — Claude stream-json 호환 포맷
|
|
92
|
-
if (event.toolResults && event.toolResults.length > 0) {
|
|
93
|
-
for (const tr of event.toolResults) {
|
|
94
|
-
const output = typeof tr.result === 'string'
|
|
95
|
-
? tr.result
|
|
96
|
-
: JSON.stringify(tr.result);
|
|
97
|
-
options.onOutput(JSON.stringify({
|
|
98
|
-
type: 'user',
|
|
99
|
-
message: {
|
|
100
|
-
content: [{ type: 'tool_result', tool_use_id: tr.toolCallId, output, is_error: false }],
|
|
101
|
-
},
|
|
102
|
-
}), 'stdout');
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
// 5. Client tool detection — if generateText stopped because of a tool without execute
|
|
108
|
-
const clientToolNames = new Set((options?.tools ?? []).filter(t => !t.execute).map(t => t.name));
|
|
109
|
-
if (result.finishReason === 'tool-calls' &&
|
|
110
|
-
Array.isArray(result.toolCalls) &&
|
|
111
|
-
result.toolCalls.length > 0) {
|
|
112
|
-
const pendingCalls = result.toolCalls
|
|
113
|
-
.filter(tc => clientToolNames.has(tc.toolName));
|
|
114
|
-
if (pendingCalls.length > 0) {
|
|
115
|
-
const tc = pendingCalls[0];
|
|
116
|
-
throw new bridge_1.ClientToolCallRequiredError({ toolCallId: tc.toolCallId, toolName: tc.toolName, args: tc.args }, {
|
|
117
|
-
userMessage: message,
|
|
118
|
-
responseMessages: result.response?.messages ?? [],
|
|
119
|
-
toolDefinitions: options?.tools ?? [],
|
|
120
|
-
maxSteps,
|
|
121
|
-
systemPrompt: options?.systemPrompt,
|
|
122
|
-
modelOverride: options?.model,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
// 6. Usage 콜백
|
|
127
|
-
if (options?.onUsage && result.usage) {
|
|
128
|
-
const usage = {
|
|
129
|
-
inputTokens: result.usage.promptTokens ?? 0,
|
|
130
|
-
outputTokens: result.usage.completionTokens ?? 0,
|
|
131
|
-
cachedInputTokens: 0,
|
|
132
|
-
costUsd: 0,
|
|
133
|
-
};
|
|
134
|
-
options.onUsage(usage);
|
|
135
|
-
}
|
|
136
|
-
// 7. Model 콜백
|
|
137
|
-
if (options?.onModel) {
|
|
138
|
-
options.onModel(options.model ?? this.config.model);
|
|
139
|
-
}
|
|
140
|
-
return result.text ?? '';
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
// Re-throw ClientToolCallRequiredError as-is (not a provider error)
|
|
144
|
-
if (error instanceof bridge_1.ClientToolCallRequiredError)
|
|
145
|
-
throw error;
|
|
146
|
-
if (error.status === 401) {
|
|
147
|
-
throw new bridge_1.ProviderError(`Authentication failed for ${this.config.provider}. Check your API key.`, this.config.provider);
|
|
148
|
-
}
|
|
149
|
-
if (error.status === 429) {
|
|
150
|
-
throw new bridge_1.ProviderError(`Rate limit exceeded for ${this.config.provider}.`, this.config.provider);
|
|
151
|
-
}
|
|
152
|
-
throw new bridge_1.ProviderError(`Provider error: ${error.message}`, this.config.provider);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Resume a conversation after client-side tool results are provided.
|
|
157
|
-
* Reconstructs the message history and calls generateText() again.
|
|
158
|
-
*/
|
|
159
|
-
async continueWithToolResults(state, toolResults, options) {
|
|
160
|
-
const { generateText, tool: toolFn } = await Promise.resolve().then(() => __importStar(require('ai')));
|
|
161
|
-
const vercelTools = this.convertTools(state.toolDefinitions, toolFn);
|
|
162
|
-
const model = this.createModel(state.modelOverride);
|
|
163
|
-
const maxSteps = Math.min(state.maxSteps ?? this.config.maxSteps ?? DEFAULT_MAX_STEPS, MAX_STEPS_LIMIT);
|
|
164
|
-
// Build messages: original user message + previous response + new tool results
|
|
165
|
-
const messages = [
|
|
166
|
-
{ role: 'user', content: state.userMessage },
|
|
167
|
-
...state.responseMessages,
|
|
168
|
-
{
|
|
169
|
-
role: 'tool',
|
|
170
|
-
content: toolResults.map(tr => ({
|
|
171
|
-
type: 'tool-result',
|
|
172
|
-
toolCallId: tr.toolCallId,
|
|
173
|
-
toolName: tr.toolName,
|
|
174
|
-
result: typeof tr.result === 'string' ? tr.result : JSON.stringify(tr.result),
|
|
175
|
-
})),
|
|
176
|
-
},
|
|
177
|
-
];
|
|
178
|
-
try {
|
|
179
|
-
const result = await generateText({
|
|
180
|
-
model,
|
|
181
|
-
system: state.systemPrompt ?? undefined,
|
|
182
|
-
messages: messages,
|
|
183
|
-
tools: vercelTools,
|
|
184
|
-
maxSteps,
|
|
185
|
-
...(this.config.temperature !== undefined && { temperature: this.config.temperature }),
|
|
186
|
-
...(this.config.maxTokens !== undefined && { maxTokens: this.config.maxTokens }),
|
|
187
|
-
});
|
|
188
|
-
// Check again for client tool calls
|
|
189
|
-
const clientToolNames = new Set(state.toolDefinitions.filter(t => !t.execute).map(t => t.name));
|
|
190
|
-
if (result.finishReason === 'tool-calls' &&
|
|
191
|
-
Array.isArray(result.toolCalls) &&
|
|
192
|
-
result.toolCalls.length > 0) {
|
|
193
|
-
const pendingCalls = result.toolCalls
|
|
194
|
-
.filter(tc => clientToolNames.has(tc.toolName));
|
|
195
|
-
if (pendingCalls.length > 0) {
|
|
196
|
-
const tc = pendingCalls[0];
|
|
197
|
-
// Update continuation state with new messages
|
|
198
|
-
throw new bridge_1.ClientToolCallRequiredError({ toolCallId: tc.toolCallId, toolName: tc.toolName, args: tc.args }, {
|
|
199
|
-
userMessage: state.userMessage,
|
|
200
|
-
responseMessages: [
|
|
201
|
-
...state.responseMessages,
|
|
202
|
-
{
|
|
203
|
-
role: 'tool',
|
|
204
|
-
content: toolResults.map(tr => ({
|
|
205
|
-
type: 'tool-result',
|
|
206
|
-
toolCallId: tr.toolCallId,
|
|
207
|
-
toolName: tr.toolName,
|
|
208
|
-
result: typeof tr.result === 'string' ? tr.result : JSON.stringify(tr.result),
|
|
209
|
-
})),
|
|
210
|
-
},
|
|
211
|
-
...(result.response?.messages ?? []),
|
|
212
|
-
],
|
|
213
|
-
toolDefinitions: state.toolDefinitions,
|
|
214
|
-
maxSteps: state.maxSteps,
|
|
215
|
-
systemPrompt: state.systemPrompt,
|
|
216
|
-
modelOverride: state.modelOverride,
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
// Usage/model callbacks
|
|
221
|
-
if (options?.onUsage && result.usage) {
|
|
222
|
-
options.onUsage({
|
|
223
|
-
inputTokens: result.usage.promptTokens ?? 0,
|
|
224
|
-
outputTokens: result.usage.completionTokens ?? 0,
|
|
225
|
-
cachedInputTokens: 0,
|
|
226
|
-
costUsd: 0,
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
if (options?.onModel) {
|
|
230
|
-
options.onModel(state.modelOverride ?? this.config.model);
|
|
231
|
-
}
|
|
232
|
-
return result.text ?? '';
|
|
233
|
-
}
|
|
234
|
-
catch (error) {
|
|
235
|
-
if (error instanceof bridge_1.ClientToolCallRequiredError)
|
|
236
|
-
throw error;
|
|
237
|
-
throw new bridge_1.ProviderError(`Provider error: ${error.message}`, this.config.provider);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* CrewX ToolDefinition[] → Vercel AI SDK tool Record 변환.
|
|
242
|
-
* execute가 없는 tool은 client tool로 처리 (Vercel AI SDK 네이티브 지원).
|
|
243
|
-
*/
|
|
244
|
-
convertTools(tools, toolFn) {
|
|
245
|
-
const { z } = require('zod');
|
|
246
|
-
const vercelTools = {};
|
|
247
|
-
for (const td of tools) {
|
|
248
|
-
const parameters = this.jsonSchemaToZod(td.parameters ?? {}, z);
|
|
249
|
-
if (td.execute) {
|
|
250
|
-
// Server tool — execute 함수 있음
|
|
251
|
-
vercelTools[td.name] = toolFn({
|
|
252
|
-
description: td.description,
|
|
253
|
-
parameters,
|
|
254
|
-
execute: async (args) => {
|
|
255
|
-
return td.execute(args);
|
|
256
|
-
},
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
// Client tool — execute 없음 (Vercel AI SDK가 tool_result를 기다림)
|
|
261
|
-
vercelTools[td.name] = toolFn({
|
|
262
|
-
description: td.description,
|
|
263
|
-
parameters,
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return vercelTools;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* JSON Schema → Zod 간이 변환.
|
|
271
|
-
*/
|
|
272
|
-
jsonSchemaToZod(schema, z) {
|
|
273
|
-
if (!schema || !schema.properties)
|
|
274
|
-
return z.object({});
|
|
275
|
-
const shape = {};
|
|
276
|
-
const props = schema.properties;
|
|
277
|
-
const required = schema.required ?? [];
|
|
278
|
-
for (const [key, prop] of Object.entries(props)) {
|
|
279
|
-
let field;
|
|
280
|
-
switch (prop.type) {
|
|
281
|
-
case 'string':
|
|
282
|
-
field = z.string();
|
|
283
|
-
break;
|
|
284
|
-
case 'number':
|
|
285
|
-
field = z.number();
|
|
286
|
-
break;
|
|
287
|
-
case 'integer':
|
|
288
|
-
field = z.number().int();
|
|
289
|
-
break;
|
|
290
|
-
case 'boolean':
|
|
291
|
-
field = z.boolean();
|
|
292
|
-
break;
|
|
293
|
-
case 'array':
|
|
294
|
-
field = z.array(z.any());
|
|
295
|
-
break;
|
|
296
|
-
default: field = z.any();
|
|
297
|
-
}
|
|
298
|
-
if (prop.description)
|
|
299
|
-
field = field.describe(prop.description);
|
|
300
|
-
if (!required.includes(key))
|
|
301
|
-
field = field.optional();
|
|
302
|
-
shape[key] = field;
|
|
303
|
-
}
|
|
304
|
-
return z.object(shape);
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Vercel AI SDK model 인스턴스 생성.
|
|
308
|
-
* provider string에 따라 적절한 SDK 팩토리 사용.
|
|
309
|
-
*/
|
|
310
|
-
createModel(modelOverride) {
|
|
311
|
-
const { provider, apiKey, baseURL } = this.config;
|
|
312
|
-
const model = modelOverride || this.config.model;
|
|
313
|
-
switch (provider) {
|
|
314
|
-
case 'api/openrouter': {
|
|
315
|
-
const { createOpenAI } = require('@ai-sdk/openai');
|
|
316
|
-
return createOpenAI({
|
|
317
|
-
apiKey: apiKey || process.env.OPENROUTER_API_KEY,
|
|
318
|
-
baseURL: baseURL || 'https://openrouter.ai/api/v1',
|
|
319
|
-
})(model);
|
|
320
|
-
}
|
|
321
|
-
case 'api/openai': {
|
|
322
|
-
const { createOpenAI } = require('@ai-sdk/openai');
|
|
323
|
-
return createOpenAI({
|
|
324
|
-
apiKey: apiKey || process.env.OPENAI_API_KEY,
|
|
325
|
-
...(baseURL && { baseURL }),
|
|
326
|
-
})(model);
|
|
327
|
-
}
|
|
328
|
-
case 'api/anthropic': {
|
|
329
|
-
const { createAnthropic } = require('@ai-sdk/anthropic');
|
|
330
|
-
return createAnthropic({
|
|
331
|
-
apiKey: apiKey || process.env.ANTHROPIC_API_KEY,
|
|
332
|
-
...(baseURL && { baseURL }),
|
|
333
|
-
})(model);
|
|
334
|
-
}
|
|
335
|
-
case 'api/google': {
|
|
336
|
-
const { createGoogleGenerativeAI } = require('@ai-sdk/google');
|
|
337
|
-
return createGoogleGenerativeAI({
|
|
338
|
-
apiKey: apiKey || process.env.GOOGLE_API_KEY,
|
|
339
|
-
})(model);
|
|
340
|
-
}
|
|
341
|
-
default:
|
|
342
|
-
throw new bridge_1.ProviderError(`Unsupported API provider: ${provider}`, provider);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
exports.VercelProviderRuntime = VercelProviderRuntime;
|
|
347
|
-
//# sourceMappingURL=vercel-runtime.js.map
|
package/dist/remote/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Remote Agent Module
|
|
4
|
-
*
|
|
5
|
-
* SDK core module for remote agent communication via MCP protocol.
|
|
6
|
-
*/
|
|
7
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.resolveFileRemoteAgent = exports.createRemoteProviderFactory = exports.RemoteProviderRuntime = exports.RemoteAgentManager = exports.McpHttpTransport = void 0;
|
|
23
|
-
__exportStar(require("./types.js"), exports);
|
|
24
|
-
var remote_transport_js_1 = require("./remote-transport.js");
|
|
25
|
-
Object.defineProperty(exports, "McpHttpTransport", { enumerable: true, get: function () { return remote_transport_js_1.McpHttpTransport; } });
|
|
26
|
-
var remote_agent_manager_js_1 = require("./remote-agent-manager.js");
|
|
27
|
-
Object.defineProperty(exports, "RemoteAgentManager", { enumerable: true, get: function () { return remote_agent_manager_js_1.RemoteAgentManager; } });
|
|
28
|
-
var remote_provider_js_1 = require("./remote-provider.js");
|
|
29
|
-
Object.defineProperty(exports, "RemoteProviderRuntime", { enumerable: true, get: function () { return remote_provider_js_1.RemoteProviderRuntime; } });
|
|
30
|
-
Object.defineProperty(exports, "createRemoteProviderFactory", { enumerable: true, get: function () { return remote_provider_js_1.createRemoteProviderFactory; } });
|
|
31
|
-
Object.defineProperty(exports, "resolveFileRemoteAgent", { enumerable: true, get: function () { return remote_provider_js_1.resolveFileRemoteAgent; } });
|
|
32
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Remote Agent Manager
|
|
4
|
-
*
|
|
5
|
-
* Manages communication with remote MCP agents.
|
|
6
|
-
* Migrated from sdk-bak/src/core/remote/remote-agent-manager.ts
|
|
7
|
-
* and adapted to use the new RemoteTransport interface.
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.RemoteAgentManager = void 0;
|
|
11
|
-
const remote_transport_js_1 = require("./remote-transport.js");
|
|
12
|
-
/**
|
|
13
|
-
* Remote Agent Manager
|
|
14
|
-
*
|
|
15
|
-
* Manages communication with remote MCP agents.
|
|
16
|
-
* Each loaded agent config creates its own transport instance.
|
|
17
|
-
*/
|
|
18
|
-
class RemoteAgentManager {
|
|
19
|
-
logger;
|
|
20
|
-
configs = new Map();
|
|
21
|
-
transports = new Map();
|
|
22
|
-
constructor(options = {}) {
|
|
23
|
-
this.logger = options.logger ?? (() => { });
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Load configuration for a remote agent.
|
|
27
|
-
* Creates a transport instance for the agent.
|
|
28
|
-
*/
|
|
29
|
-
loadConfig(agentId, config) {
|
|
30
|
-
this.validateConfig(config);
|
|
31
|
-
this.configs.set(agentId, config);
|
|
32
|
-
this.transports.set(agentId, new remote_transport_js_1.McpHttpTransport({
|
|
33
|
-
url: config.url,
|
|
34
|
-
apiKey: config.apiKey,
|
|
35
|
-
headers: config.headers,
|
|
36
|
-
timeoutMs: config.timeoutMs,
|
|
37
|
-
}));
|
|
38
|
-
this.logger(`Loaded remote agent config for: ${agentId}`, 'debug');
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Load configuration with a custom transport (e.g. for testing).
|
|
42
|
-
*/
|
|
43
|
-
loadConfigWithTransport(agentId, config, transport) {
|
|
44
|
-
this.validateConfig(config);
|
|
45
|
-
this.configs.set(agentId, config);
|
|
46
|
-
this.transports.set(agentId, transport);
|
|
47
|
-
this.logger(`Loaded remote agent config for: ${agentId} (custom transport)`, 'debug');
|
|
48
|
-
}
|
|
49
|
-
/** Get configuration for a remote agent. */
|
|
50
|
-
getConfig(agentId) {
|
|
51
|
-
return this.configs.get(agentId);
|
|
52
|
-
}
|
|
53
|
-
/** Check if an agent is configured as remote. */
|
|
54
|
-
isRemoteAgent(agentId) {
|
|
55
|
-
return this.configs.has(agentId);
|
|
56
|
-
}
|
|
57
|
-
/** Get all configured remote agent IDs. */
|
|
58
|
-
getRemoteAgentIds() {
|
|
59
|
-
return Array.from(this.configs.keys());
|
|
60
|
-
}
|
|
61
|
-
/** Query a remote agent. */
|
|
62
|
-
async query(agentId, request) {
|
|
63
|
-
const config = this.requireConfig(agentId);
|
|
64
|
-
const toolName = config.tools?.query ?? 'crewx_queryAgent';
|
|
65
|
-
const remoteAgentId = config.agentId ?? agentId;
|
|
66
|
-
const payload = {
|
|
67
|
-
agentId: remoteAgentId,
|
|
68
|
-
query: request.query,
|
|
69
|
-
};
|
|
70
|
-
if (request.context)
|
|
71
|
-
payload.context = request.context;
|
|
72
|
-
if (request.model)
|
|
73
|
-
payload.model = request.model;
|
|
74
|
-
if (request.platform)
|
|
75
|
-
payload.platform = request.platform;
|
|
76
|
-
if (request.messages?.length)
|
|
77
|
-
payload.messages = request.messages;
|
|
78
|
-
try {
|
|
79
|
-
const result = await this.callRemoteTool(agentId, toolName, payload);
|
|
80
|
-
return this.normalizeResponse(result);
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
84
|
-
this.logger(`Remote query failed for agent ${agentId}: ${msg}`, 'error');
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
/** Execute a task on a remote agent. */
|
|
89
|
-
async execute(agentId, request) {
|
|
90
|
-
const config = this.requireConfig(agentId);
|
|
91
|
-
const toolName = config.tools?.execute ?? 'crewx_executeAgent';
|
|
92
|
-
const remoteAgentId = config.agentId ?? agentId;
|
|
93
|
-
const payload = {
|
|
94
|
-
agentId: remoteAgentId,
|
|
95
|
-
task: request.task,
|
|
96
|
-
};
|
|
97
|
-
if (request.context)
|
|
98
|
-
payload.context = request.context;
|
|
99
|
-
if (request.model)
|
|
100
|
-
payload.model = request.model;
|
|
101
|
-
if (request.platform)
|
|
102
|
-
payload.platform = request.platform;
|
|
103
|
-
if (request.messages?.length)
|
|
104
|
-
payload.messages = request.messages;
|
|
105
|
-
try {
|
|
106
|
-
const result = await this.callRemoteTool(agentId, toolName, payload);
|
|
107
|
-
return this.normalizeResponse(result);
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
111
|
-
this.logger(`Remote execute failed for agent ${agentId}: ${msg}`, 'error');
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
/** Map tool names for a remote agent. */
|
|
116
|
-
mapToolNames(agentId, mapping) {
|
|
117
|
-
const config = this.requireConfig(agentId);
|
|
118
|
-
config.tools = {
|
|
119
|
-
query: mapping.query ?? config.tools?.query ?? 'crewx_queryAgent',
|
|
120
|
-
execute: mapping.execute ?? config.tools?.execute ?? 'crewx_executeAgent',
|
|
121
|
-
};
|
|
122
|
-
this.logger(`Updated tool name mapping for agent ${agentId}`, 'debug');
|
|
123
|
-
}
|
|
124
|
-
/** Clear all configurations and close transports. */
|
|
125
|
-
async clearConfigs() {
|
|
126
|
-
for (const transport of this.transports.values()) {
|
|
127
|
-
await transport.close();
|
|
128
|
-
}
|
|
129
|
-
this.configs.clear();
|
|
130
|
-
this.transports.clear();
|
|
131
|
-
this.logger('Cleared all remote agent configurations', 'debug');
|
|
132
|
-
}
|
|
133
|
-
// ── Private ───────────────────────────────────────────────────────────────
|
|
134
|
-
requireConfig(agentId) {
|
|
135
|
-
const config = this.configs.get(agentId);
|
|
136
|
-
if (!config) {
|
|
137
|
-
throw new Error(`Agent ${agentId} is not configured as a remote agent`);
|
|
138
|
-
}
|
|
139
|
-
return config;
|
|
140
|
-
}
|
|
141
|
-
async callRemoteTool(agentId, toolName, args) {
|
|
142
|
-
const transport = this.transports.get(agentId);
|
|
143
|
-
if (!transport) {
|
|
144
|
-
throw new Error(`No transport available for agent ${agentId}`);
|
|
145
|
-
}
|
|
146
|
-
const request = {
|
|
147
|
-
jsonrpc: '2.0',
|
|
148
|
-
id: `${toolName}-${Date.now()}`,
|
|
149
|
-
method: 'tools/call',
|
|
150
|
-
params: {
|
|
151
|
-
name: toolName,
|
|
152
|
-
arguments: args,
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
this.logger(`Calling remote MCP tool ${toolName} for agent ${agentId}`, 'debug');
|
|
156
|
-
const response = await transport.send(request);
|
|
157
|
-
if (response.error) {
|
|
158
|
-
throw new Error(response.error.message || 'MCP server returned an error');
|
|
159
|
-
}
|
|
160
|
-
return response.result;
|
|
161
|
-
}
|
|
162
|
-
/** Normalize remote agent response to consistent format. */
|
|
163
|
-
normalizeResponse(result) {
|
|
164
|
-
if (!result) {
|
|
165
|
-
return {
|
|
166
|
-
success: false,
|
|
167
|
-
content: [{ type: 'text', text: 'Remote agent returned no response.' }],
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
const obj = result;
|
|
171
|
-
// Already has content array — return as-is
|
|
172
|
-
if (Array.isArray(obj.content) && obj.content.length > 0) {
|
|
173
|
-
return obj;
|
|
174
|
-
}
|
|
175
|
-
// Extract content from various possible fields
|
|
176
|
-
const fallbackContent = obj.response ?? obj.implementation ?? obj.message ?? obj.output;
|
|
177
|
-
const text = typeof fallbackContent === 'string'
|
|
178
|
-
? fallbackContent
|
|
179
|
-
: JSON.stringify(fallbackContent ?? result, null, 2);
|
|
180
|
-
return {
|
|
181
|
-
...obj,
|
|
182
|
-
content: [{ type: 'text', text }],
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
validateConfig(config) {
|
|
186
|
-
if (!config.url) {
|
|
187
|
-
throw new Error('Remote agent configuration requires a URL');
|
|
188
|
-
}
|
|
189
|
-
if (!config.url.startsWith('http://') && !config.url.startsWith('https://')) {
|
|
190
|
-
throw new Error('Remote agent URL must start with http:// or https://');
|
|
191
|
-
}
|
|
192
|
-
if (config.type !== 'mcp-http') {
|
|
193
|
-
throw new Error(`Unsupported remote agent type: ${config.type}`);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
exports.RemoteAgentManager = RemoteAgentManager;
|
|
198
|
-
//# sourceMappingURL=remote-agent-manager.js.map
|