mcp-agent-foundry 1.0.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 +477 -0
- package/dist/cli/install-skills.d.ts +11 -0
- package/dist/cli/install-skills.d.ts.map +1 -0
- package/dist/cli/install-skills.js +143 -0
- package/dist/cli/install-skills.js.map +1 -0
- package/dist/cli/recovery-commands.d.ts +41 -0
- package/dist/cli/recovery-commands.d.ts.map +1 -0
- package/dist/cli/recovery-commands.js +241 -0
- package/dist/cli/recovery-commands.js.map +1 -0
- package/dist/cli/setup-wizard.d.ts +25 -0
- package/dist/cli/setup-wizard.d.ts.map +1 -0
- package/dist/cli/setup-wizard.js +1417 -0
- package/dist/cli/setup-wizard.js.map +1 -0
- package/dist/cli/test-connection.d.ts +45 -0
- package/dist/cli/test-connection.d.ts.map +1 -0
- package/dist/cli/test-connection.js +317 -0
- package/dist/cli/test-connection.js.map +1 -0
- package/dist/cli.d.ts +75 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +704 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/defaults.d.ts +57 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +99 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/index.d.ts +14 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +22 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/manager.d.ts +184 -0
- package/dist/config/manager.d.ts.map +1 -0
- package/dist/config/manager.js +347 -0
- package/dist/config/manager.js.map +1 -0
- package/dist/config/merger.d.ts +76 -0
- package/dist/config/merger.d.ts.map +1 -0
- package/dist/config/merger.js +189 -0
- package/dist/config/merger.js.map +1 -0
- package/dist/config/schema.d.ts +20 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +20 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/validator.d.ts +254 -0
- package/dist/config/validator.d.ts.map +1 -0
- package/dist/config/validator.js +363 -0
- package/dist/config/validator.js.map +1 -0
- package/dist/config/worktree-defaults.d.ts +23 -0
- package/dist/config/worktree-defaults.d.ts.map +1 -0
- package/dist/config/worktree-defaults.js +78 -0
- package/dist/config/worktree-defaults.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/tools/compare-agents.d.ts +25 -0
- package/dist/mcp/tools/compare-agents.d.ts.map +1 -0
- package/dist/mcp/tools/compare-agents.js +177 -0
- package/dist/mcp/tools/compare-agents.js.map +1 -0
- package/dist/mcp/tools/critique-plan.d.ts +26 -0
- package/dist/mcp/tools/critique-plan.d.ts.map +1 -0
- package/dist/mcp/tools/critique-plan.js +162 -0
- package/dist/mcp/tools/critique-plan.js.map +1 -0
- package/dist/mcp/tools/design-feedback.d.ts +26 -0
- package/dist/mcp/tools/design-feedback.d.ts.map +1 -0
- package/dist/mcp/tools/design-feedback.js +216 -0
- package/dist/mcp/tools/design-feedback.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +50 -0
- package/dist/mcp/tools/index.d.ts.map +1 -0
- package/dist/mcp/tools/index.js +191 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/invoke-agent.d.ts +25 -0
- package/dist/mcp/tools/invoke-agent.d.ts.map +1 -0
- package/dist/mcp/tools/invoke-agent.js +141 -0
- package/dist/mcp/tools/invoke-agent.js.map +1 -0
- package/dist/mcp/tools/review-code.d.ts +25 -0
- package/dist/mcp/tools/review-code.d.ts.map +1 -0
- package/dist/mcp/tools/review-code.js +170 -0
- package/dist/mcp/tools/review-code.js.map +1 -0
- package/dist/mcp/tools/tasks/claim-next-task.d.ts +22 -0
- package/dist/mcp/tools/tasks/claim-next-task.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/claim-next-task.js +203 -0
- package/dist/mcp/tools/tasks/claim-next-task.js.map +1 -0
- package/dist/mcp/tools/tasks/create-routed-task.d.ts +17 -0
- package/dist/mcp/tools/tasks/create-routed-task.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/create-routed-task.js +178 -0
- package/dist/mcp/tools/tasks/create-routed-task.js.map +1 -0
- package/dist/mcp/tools/tasks/execute-pipeline.d.ts +22 -0
- package/dist/mcp/tools/tasks/execute-pipeline.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/execute-pipeline.js +401 -0
- package/dist/mcp/tools/tasks/execute-pipeline.js.map +1 -0
- package/dist/mcp/tools/tasks/execute-task.d.ts +32 -0
- package/dist/mcp/tools/tasks/execute-task.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/execute-task.js +284 -0
- package/dist/mcp/tools/tasks/execute-task.js.map +1 -0
- package/dist/mcp/tools/tasks/get-pipeline-status.d.ts +26 -0
- package/dist/mcp/tools/tasks/get-pipeline-status.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/get-pipeline-status.js +460 -0
- package/dist/mcp/tools/tasks/get-pipeline-status.js.map +1 -0
- package/dist/mcp/tools/tasks/index.d.ts +36 -0
- package/dist/mcp/tools/tasks/index.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/index.js +66 -0
- package/dist/mcp/tools/tasks/index.js.map +1 -0
- package/dist/mcp/tools/worktree/cleanup-worktrees.d.ts +17 -0
- package/dist/mcp/tools/worktree/cleanup-worktrees.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/cleanup-worktrees.js +147 -0
- package/dist/mcp/tools/worktree/cleanup-worktrees.js.map +1 -0
- package/dist/mcp/tools/worktree/get-worktree-status.d.ts +17 -0
- package/dist/mcp/tools/worktree/get-worktree-status.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/get-worktree-status.js +123 -0
- package/dist/mcp/tools/worktree/get-worktree-status.js.map +1 -0
- package/dist/mcp/tools/worktree/index.d.ts +41 -0
- package/dist/mcp/tools/worktree/index.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/index.js +69 -0
- package/dist/mcp/tools/worktree/index.js.map +1 -0
- package/dist/mcp/tools/worktree/list-worktrees.d.ts +17 -0
- package/dist/mcp/tools/worktree/list-worktrees.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/list-worktrees.js +136 -0
- package/dist/mcp/tools/worktree/list-worktrees.js.map +1 -0
- package/dist/mcp/tools/worktree/resolve-conflicts.d.ts +19 -0
- package/dist/mcp/tools/worktree/resolve-conflicts.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/resolve-conflicts.js +228 -0
- package/dist/mcp/tools/worktree/resolve-conflicts.js.map +1 -0
- package/dist/mcp/transport/stdio.d.ts +13 -0
- package/dist/mcp/transport/stdio.d.ts.map +1 -0
- package/dist/mcp/transport/stdio.js +15 -0
- package/dist/mcp/transport/stdio.js.map +1 -0
- package/dist/observability/logger.d.ts +137 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +235 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/metrics.d.ts +250 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +364 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/persistence/index.d.ts +9 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +9 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/state-schema.d.ts +116 -0
- package/dist/persistence/state-schema.d.ts.map +1 -0
- package/dist/persistence/state-schema.js +28 -0
- package/dist/persistence/state-schema.js.map +1 -0
- package/dist/persistence/state-store.d.ts +111 -0
- package/dist/persistence/state-store.d.ts.map +1 -0
- package/dist/persistence/state-store.js +291 -0
- package/dist/persistence/state-store.js.map +1 -0
- package/dist/providers/anthropic.d.ts +164 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +500 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/base.d.ts +151 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +227 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/gemini.d.ts +85 -0
- package/dist/providers/gemini.d.ts.map +1 -0
- package/dist/providers/gemini.js +414 -0
- package/dist/providers/gemini.js.map +1 -0
- package/dist/providers/kimi.d.ts +19 -0
- package/dist/providers/kimi.d.ts.map +1 -0
- package/dist/providers/kimi.js +20 -0
- package/dist/providers/kimi.js.map +1 -0
- package/dist/providers/manager.d.ts +160 -0
- package/dist/providers/manager.d.ts.map +1 -0
- package/dist/providers/manager.js +264 -0
- package/dist/providers/manager.js.map +1 -0
- package/dist/providers/ollama.d.ts +83 -0
- package/dist/providers/ollama.d.ts.map +1 -0
- package/dist/providers/ollama.js +453 -0
- package/dist/providers/ollama.js.map +1 -0
- package/dist/providers/openai.d.ts +96 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +457 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/zai.d.ts +19 -0
- package/dist/providers/zai.d.ts.map +1 -0
- package/dist/providers/zai.js +20 -0
- package/dist/providers/zai.js.map +1 -0
- package/dist/router/context-manager.d.ts +2 -0
- package/dist/router/context-manager.d.ts.map +1 -0
- package/dist/router/context-manager.js +3 -0
- package/dist/router/context-manager.js.map +1 -0
- package/dist/router/engine.d.ts +169 -0
- package/dist/router/engine.d.ts.map +1 -0
- package/dist/router/engine.js +435 -0
- package/dist/router/engine.js.map +1 -0
- package/dist/router/pattern-executor.d.ts +317 -0
- package/dist/router/pattern-executor.d.ts.map +1 -0
- package/dist/router/pattern-executor.js +571 -0
- package/dist/router/pattern-executor.js.map +1 -0
- package/dist/router/role-resolver.d.ts +59 -0
- package/dist/router/role-resolver.d.ts.map +1 -0
- package/dist/router/role-resolver.js +95 -0
- package/dist/router/role-resolver.js.map +1 -0
- package/dist/server.d.ts +32 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +223 -0
- package/dist/server.js.map +1 -0
- package/dist/startup.d.ts +78 -0
- package/dist/startup.d.ts.map +1 -0
- package/dist/startup.js +107 -0
- package/dist/startup.js.map +1 -0
- package/dist/tasks/coordinator.d.ts +141 -0
- package/dist/tasks/coordinator.d.ts.map +1 -0
- package/dist/tasks/coordinator.js +331 -0
- package/dist/tasks/coordinator.js.map +1 -0
- package/dist/tasks/index.d.ts +13 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +13 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/tasks/persistent-state-coordinator.d.ts +89 -0
- package/dist/tasks/persistent-state-coordinator.d.ts.map +1 -0
- package/dist/tasks/persistent-state-coordinator.js +371 -0
- package/dist/tasks/persistent-state-coordinator.js.map +1 -0
- package/dist/tasks/pipeline-manager.d.ts +103 -0
- package/dist/tasks/pipeline-manager.d.ts.map +1 -0
- package/dist/tasks/pipeline-manager.js +358 -0
- package/dist/tasks/pipeline-manager.js.map +1 -0
- package/dist/tasks/state-coordinator.d.ts +79 -0
- package/dist/tasks/state-coordinator.d.ts.map +1 -0
- package/dist/tasks/state-coordinator.js +200 -0
- package/dist/tasks/state-coordinator.js.map +1 -0
- package/dist/tasks/worker-mode.d.ts +65 -0
- package/dist/tasks/worker-mode.d.ts.map +1 -0
- package/dist/tasks/worker-mode.js +208 -0
- package/dist/tasks/worker-mode.js.map +1 -0
- package/dist/translation/errors.d.ts +203 -0
- package/dist/translation/errors.d.ts.map +1 -0
- package/dist/translation/errors.js +477 -0
- package/dist/translation/errors.js.map +1 -0
- package/dist/translation/index.d.ts +12 -0
- package/dist/translation/index.d.ts.map +1 -0
- package/dist/translation/index.js +32 -0
- package/dist/translation/index.js.map +1 -0
- package/dist/translation/messages.d.ts +295 -0
- package/dist/translation/messages.d.ts.map +1 -0
- package/dist/translation/messages.js +557 -0
- package/dist/translation/messages.js.map +1 -0
- package/dist/translation/streaming.d.ts +226 -0
- package/dist/translation/streaming.d.ts.map +1 -0
- package/dist/translation/streaming.js +520 -0
- package/dist/translation/streaming.js.map +1 -0
- package/dist/translation/tools.d.ts +209 -0
- package/dist/translation/tools.d.ts.map +1 -0
- package/dist/translation/tools.js +331 -0
- package/dist/translation/tools.js.map +1 -0
- package/dist/types.d.ts +747 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +86 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/circuit-breaker.d.ts +175 -0
- package/dist/utils/circuit-breaker.d.ts.map +1 -0
- package/dist/utils/circuit-breaker.js +315 -0
- package/dist/utils/circuit-breaker.js.map +1 -0
- package/dist/utils/env.d.ts +2 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +3 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/git.d.ts +58 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +197 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/merge-ordering.d.ts +45 -0
- package/dist/utils/merge-ordering.d.ts.map +1 -0
- package/dist/utils/merge-ordering.js +128 -0
- package/dist/utils/merge-ordering.js.map +1 -0
- package/dist/utils/retry.d.ts +106 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +188 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/worktrees/branch-manager.d.ts +55 -0
- package/dist/worktrees/branch-manager.d.ts.map +1 -0
- package/dist/worktrees/branch-manager.js +129 -0
- package/dist/worktrees/branch-manager.js.map +1 -0
- package/dist/worktrees/conflict-handler.d.ts +72 -0
- package/dist/worktrees/conflict-handler.d.ts.map +1 -0
- package/dist/worktrees/conflict-handler.js +287 -0
- package/dist/worktrees/conflict-handler.js.map +1 -0
- package/dist/worktrees/conflict-parser.d.ts +28 -0
- package/dist/worktrees/conflict-parser.d.ts.map +1 -0
- package/dist/worktrees/conflict-parser.js +140 -0
- package/dist/worktrees/conflict-parser.js.map +1 -0
- package/dist/worktrees/index.d.ts +20 -0
- package/dist/worktrees/index.d.ts.map +1 -0
- package/dist/worktrees/index.js +20 -0
- package/dist/worktrees/index.js.map +1 -0
- package/dist/worktrees/instructions.d.ts +20 -0
- package/dist/worktrees/instructions.d.ts.map +1 -0
- package/dist/worktrees/instructions.js +84 -0
- package/dist/worktrees/instructions.js.map +1 -0
- package/dist/worktrees/manager.d.ts +76 -0
- package/dist/worktrees/manager.d.ts.map +1 -0
- package/dist/worktrees/manager.js +277 -0
- package/dist/worktrees/manager.js.map +1 -0
- package/dist/worktrees/pipeline-merge-orchestrator.d.ts +55 -0
- package/dist/worktrees/pipeline-merge-orchestrator.d.ts.map +1 -0
- package/dist/worktrees/pipeline-merge-orchestrator.js +221 -0
- package/dist/worktrees/pipeline-merge-orchestrator.js.map +1 -0
- package/dist/worktrees/pool.d.ts +95 -0
- package/dist/worktrees/pool.d.ts.map +1 -0
- package/dist/worktrees/pool.js +271 -0
- package/dist/worktrees/pool.js.map +1 -0
- package/dist/worktrees/recovery.d.ts +94 -0
- package/dist/worktrees/recovery.d.ts.map +1 -0
- package/dist/worktrees/recovery.js +371 -0
- package/dist/worktrees/recovery.js.map +1 -0
- package/dist/worktrees/resource-manager.d.ts +74 -0
- package/dist/worktrees/resource-manager.d.ts.map +1 -0
- package/dist/worktrees/resource-manager.js +228 -0
- package/dist/worktrees/resource-manager.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Schema Translation
|
|
3
|
+
*
|
|
4
|
+
* Translates tool/function schemas between different LLM provider formats.
|
|
5
|
+
* Each provider has different conventions for defining tools that models can use.
|
|
6
|
+
*
|
|
7
|
+
* Format Comparison:
|
|
8
|
+
* | Feature | Anthropic | OpenAI | Gemini |
|
|
9
|
+
* |-----------------|------------------|---------------------|---------------------|
|
|
10
|
+
* | Schema key | input_schema | parameters | parameters |
|
|
11
|
+
* | Wrapper | none | function: { } | functionDeclarations|
|
|
12
|
+
* | Description | description | function.description| description |
|
|
13
|
+
*/
|
|
14
|
+
import { type Tool } from '../types.js';
|
|
15
|
+
/**
|
|
16
|
+
* Anthropic tool format.
|
|
17
|
+
* Tools are defined at the top level with input_schema for parameters.
|
|
18
|
+
*/
|
|
19
|
+
export interface AnthropicTool {
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
input_schema: {
|
|
23
|
+
type: 'object';
|
|
24
|
+
properties: Record<string, unknown>;
|
|
25
|
+
required?: string[];
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* OpenAI tool format.
|
|
30
|
+
* Tools are wrapped in a function object with type: "function".
|
|
31
|
+
*/
|
|
32
|
+
export interface OpenAITool {
|
|
33
|
+
type: 'function';
|
|
34
|
+
function: {
|
|
35
|
+
name: string;
|
|
36
|
+
description: string;
|
|
37
|
+
parameters: {
|
|
38
|
+
type: 'object';
|
|
39
|
+
properties: Record<string, unknown>;
|
|
40
|
+
required?: string[];
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* OpenAI function definition (inner part of OpenAITool).
|
|
46
|
+
* Used when providers expect just the function definition.
|
|
47
|
+
*/
|
|
48
|
+
export interface OpenAIFunction {
|
|
49
|
+
name: string;
|
|
50
|
+
description: string;
|
|
51
|
+
parameters: {
|
|
52
|
+
type: 'object';
|
|
53
|
+
properties: Record<string, unknown>;
|
|
54
|
+
required?: string[];
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Gemini function declaration.
|
|
59
|
+
* Used inside the functionDeclarations array.
|
|
60
|
+
*/
|
|
61
|
+
export interface GeminiFunctionDeclaration {
|
|
62
|
+
name: string;
|
|
63
|
+
description: string;
|
|
64
|
+
parameters: {
|
|
65
|
+
type: 'object';
|
|
66
|
+
properties: Record<string, unknown>;
|
|
67
|
+
required?: string[];
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Gemini tool format.
|
|
72
|
+
* Tools are wrapped in a functionDeclarations array.
|
|
73
|
+
*/
|
|
74
|
+
export interface GeminiTool {
|
|
75
|
+
functionDeclarations: GeminiFunctionDeclaration[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Translate tools to Anthropic format.
|
|
79
|
+
*
|
|
80
|
+
* Anthropic uses a straightforward format where tools are defined with:
|
|
81
|
+
* - name: The tool name
|
|
82
|
+
* - description: Human-readable description
|
|
83
|
+
* - input_schema: JSON Schema for parameters
|
|
84
|
+
*
|
|
85
|
+
* Since our internal Tool type follows the Anthropic format,
|
|
86
|
+
* this is essentially a pass-through with validation.
|
|
87
|
+
*
|
|
88
|
+
* @param tools - Array of tools in internal format
|
|
89
|
+
* @returns Array of tools in Anthropic format
|
|
90
|
+
* @throws TranslationError if validation fails
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* const tools = [{ name: "search", description: "Search the web", input_schema: {...} }];
|
|
94
|
+
* const anthropicTools = toAnthropicTools(tools);
|
|
95
|
+
* // Returns: [{ name: "search", description: "Search the web", input_schema: {...} }]
|
|
96
|
+
*/
|
|
97
|
+
export declare function toAnthropicTools(tools: Tool[]): AnthropicTool[];
|
|
98
|
+
/**
|
|
99
|
+
* Translate tools to OpenAI format.
|
|
100
|
+
*
|
|
101
|
+
* OpenAI wraps tools in a specific structure:
|
|
102
|
+
* - type: "function" (indicates it's a function tool)
|
|
103
|
+
* - function: Object containing name, description, and parameters
|
|
104
|
+
*
|
|
105
|
+
* The main difference from Anthropic is:
|
|
106
|
+
* - Uses `parameters` instead of `input_schema`
|
|
107
|
+
* - Wraps everything in a `function` object
|
|
108
|
+
* - Adds `type: "function"` at the top level
|
|
109
|
+
*
|
|
110
|
+
* @param tools - Array of tools in internal format
|
|
111
|
+
* @returns Array of tools in OpenAI format
|
|
112
|
+
* @throws TranslationError if validation fails
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* const tools = [{ name: "search", description: "Search the web", input_schema: {...} }];
|
|
116
|
+
* const openaiTools = toOpenAITools(tools);
|
|
117
|
+
* // Returns: [{ type: "function", function: { name: "search", description: "...", parameters: {...} } }]
|
|
118
|
+
*/
|
|
119
|
+
export declare function toOpenAITools(tools: Tool[]): OpenAITool[];
|
|
120
|
+
/**
|
|
121
|
+
* Translate tools to OpenAI function format (without wrapper).
|
|
122
|
+
*
|
|
123
|
+
* Some OpenAI-compatible APIs expect just the function definitions
|
|
124
|
+
* without the { type: "function", function: {...} } wrapper.
|
|
125
|
+
*
|
|
126
|
+
* @param tools - Array of tools in internal format
|
|
127
|
+
* @returns Array of function definitions
|
|
128
|
+
* @throws TranslationError if validation fails
|
|
129
|
+
*/
|
|
130
|
+
export declare function toOpenAIFunctions(tools: Tool[]): OpenAIFunction[];
|
|
131
|
+
/**
|
|
132
|
+
* Translate tools to Gemini format.
|
|
133
|
+
*
|
|
134
|
+
* Gemini uses a different structure where all function declarations
|
|
135
|
+
* are grouped into a single object:
|
|
136
|
+
* - functionDeclarations: Array of function definitions
|
|
137
|
+
*
|
|
138
|
+
* Each function declaration contains:
|
|
139
|
+
* - name: Function name
|
|
140
|
+
* - description: Human-readable description
|
|
141
|
+
* - parameters: JSON Schema for parameters
|
|
142
|
+
*
|
|
143
|
+
* Note: Gemini expects a single tool object containing all functions,
|
|
144
|
+
* not an array of tool objects.
|
|
145
|
+
*
|
|
146
|
+
* @param tools - Array of tools in internal format
|
|
147
|
+
* @returns Single Gemini tool object containing all function declarations
|
|
148
|
+
* @throws TranslationError if validation fails
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* const tools = [{ name: "search", description: "Search the web", input_schema: {...} }];
|
|
152
|
+
* const geminiTools = toGeminiTools(tools);
|
|
153
|
+
* // Returns: { functionDeclarations: [{ name: "search", description: "...", parameters: {...} }] }
|
|
154
|
+
*/
|
|
155
|
+
export declare function toGeminiTools(tools: Tool[]): GeminiTool;
|
|
156
|
+
/**
|
|
157
|
+
* Translate tools to Gemini format as an array (for API compatibility).
|
|
158
|
+
*
|
|
159
|
+
* Some Gemini API versions expect an array containing the tool object.
|
|
160
|
+
* This is a convenience wrapper around toGeminiTools.
|
|
161
|
+
*
|
|
162
|
+
* @param tools - Array of tools in internal format
|
|
163
|
+
* @returns Array containing a single Gemini tool object
|
|
164
|
+
* @throws TranslationError if validation fails
|
|
165
|
+
*/
|
|
166
|
+
export declare function toGeminiToolsArray(tools: Tool[]): GeminiTool[];
|
|
167
|
+
/**
|
|
168
|
+
* Translate Anthropic tools to internal format.
|
|
169
|
+
*
|
|
170
|
+
* Since our internal format matches Anthropic, this is essentially a pass-through
|
|
171
|
+
* with validation.
|
|
172
|
+
*
|
|
173
|
+
* @param tools - Array of Anthropic tools
|
|
174
|
+
* @returns Array of tools in internal format
|
|
175
|
+
* @throws TranslationError if validation fails
|
|
176
|
+
*/
|
|
177
|
+
export declare function fromAnthropicTools(tools: AnthropicTool[]): Tool[];
|
|
178
|
+
/**
|
|
179
|
+
* Translate OpenAI tools to internal format.
|
|
180
|
+
*
|
|
181
|
+
* Unwraps the function object and converts parameters to input_schema.
|
|
182
|
+
*
|
|
183
|
+
* @param tools - Array of OpenAI tools
|
|
184
|
+
* @returns Array of tools in internal format
|
|
185
|
+
* @throws TranslationError if validation fails
|
|
186
|
+
*/
|
|
187
|
+
export declare function fromOpenAITools(tools: OpenAITool[]): Tool[];
|
|
188
|
+
/**
|
|
189
|
+
* Translate Gemini tools to internal format.
|
|
190
|
+
*
|
|
191
|
+
* Extracts function declarations from the Gemini tool object.
|
|
192
|
+
*
|
|
193
|
+
* @param tool - Gemini tool object containing function declarations
|
|
194
|
+
* @returns Array of tools in internal format
|
|
195
|
+
* @throws TranslationError if validation fails
|
|
196
|
+
*/
|
|
197
|
+
export declare function fromGeminiTools(tool: GeminiTool): Tool[];
|
|
198
|
+
/**
|
|
199
|
+
* Translate tools to a specific provider format.
|
|
200
|
+
*
|
|
201
|
+
* Convenience function for dynamic provider selection.
|
|
202
|
+
*
|
|
203
|
+
* @param tools - Array of tools in internal format
|
|
204
|
+
* @param provider - Target provider name
|
|
205
|
+
* @returns Tools in the appropriate provider format
|
|
206
|
+
* @throws TranslationError if the provider is unknown
|
|
207
|
+
*/
|
|
208
|
+
export declare function translateTools(tools: Tool[], provider: 'anthropic' | 'openai' | 'google' | 'gemini' | 'ollama' | 'openrouter' | 'zai'): AnthropicTool[] | OpenAITool[] | GeminiTool;
|
|
209
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/translation/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,IAAI,EAAoB,MAAM,aAAa,CAAC;AAM1D;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE;QACZ,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACpC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ,CAAC;YACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACpC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;SACrB,CAAC;KACH,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,M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AAE,CAwBxD;AA+DD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,IAAI,EAAE,EACb,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,YAAY,GAAG,KAAK,GACvF,aAAa,EAAE,GAAG,UAAU,EAAE,GAAG,UAAU,CAqB7C"}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Schema Translation
|
|
3
|
+
*
|
|
4
|
+
* Translates tool/function schemas between different LLM provider formats.
|
|
5
|
+
* Each provider has different conventions for defining tools that models can use.
|
|
6
|
+
*
|
|
7
|
+
* Format Comparison:
|
|
8
|
+
* | Feature | Anthropic | OpenAI | Gemini |
|
|
9
|
+
* |-----------------|------------------|---------------------|---------------------|
|
|
10
|
+
* | Schema key | input_schema | parameters | parameters |
|
|
11
|
+
* | Wrapper | none | function: { } | functionDeclarations|
|
|
12
|
+
* | Description | description | function.description| description |
|
|
13
|
+
*/
|
|
14
|
+
import { TranslationError } from '../types.js';
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Translation Functions
|
|
17
|
+
// ============================================================================
|
|
18
|
+
/**
|
|
19
|
+
* Translate tools to Anthropic format.
|
|
20
|
+
*
|
|
21
|
+
* Anthropic uses a straightforward format where tools are defined with:
|
|
22
|
+
* - name: The tool name
|
|
23
|
+
* - description: Human-readable description
|
|
24
|
+
* - input_schema: JSON Schema for parameters
|
|
25
|
+
*
|
|
26
|
+
* Since our internal Tool type follows the Anthropic format,
|
|
27
|
+
* this is essentially a pass-through with validation.
|
|
28
|
+
*
|
|
29
|
+
* @param tools - Array of tools in internal format
|
|
30
|
+
* @returns Array of tools in Anthropic format
|
|
31
|
+
* @throws TranslationError if validation fails
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const tools = [{ name: "search", description: "Search the web", input_schema: {...} }];
|
|
35
|
+
* const anthropicTools = toAnthropicTools(tools);
|
|
36
|
+
* // Returns: [{ name: "search", description: "Search the web", input_schema: {...} }]
|
|
37
|
+
*/
|
|
38
|
+
export function toAnthropicTools(tools) {
|
|
39
|
+
if (!tools || tools.length === 0) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
return tools.map((tool, index) => {
|
|
43
|
+
validateTool(tool, index);
|
|
44
|
+
return {
|
|
45
|
+
name: tool.name,
|
|
46
|
+
description: tool.description,
|
|
47
|
+
input_schema: {
|
|
48
|
+
type: 'object',
|
|
49
|
+
properties: tool.input_schema.properties,
|
|
50
|
+
...(tool.input_schema.required && { required: tool.input_schema.required }),
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Translate tools to OpenAI format.
|
|
57
|
+
*
|
|
58
|
+
* OpenAI wraps tools in a specific structure:
|
|
59
|
+
* - type: "function" (indicates it's a function tool)
|
|
60
|
+
* - function: Object containing name, description, and parameters
|
|
61
|
+
*
|
|
62
|
+
* The main difference from Anthropic is:
|
|
63
|
+
* - Uses `parameters` instead of `input_schema`
|
|
64
|
+
* - Wraps everything in a `function` object
|
|
65
|
+
* - Adds `type: "function"` at the top level
|
|
66
|
+
*
|
|
67
|
+
* @param tools - Array of tools in internal format
|
|
68
|
+
* @returns Array of tools in OpenAI format
|
|
69
|
+
* @throws TranslationError if validation fails
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* const tools = [{ name: "search", description: "Search the web", input_schema: {...} }];
|
|
73
|
+
* const openaiTools = toOpenAITools(tools);
|
|
74
|
+
* // Returns: [{ type: "function", function: { name: "search", description: "...", parameters: {...} } }]
|
|
75
|
+
*/
|
|
76
|
+
export function toOpenAITools(tools) {
|
|
77
|
+
if (!tools || tools.length === 0) {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
return tools.map((tool, index) => {
|
|
81
|
+
validateTool(tool, index);
|
|
82
|
+
return {
|
|
83
|
+
type: 'function',
|
|
84
|
+
function: {
|
|
85
|
+
name: tool.name,
|
|
86
|
+
description: tool.description,
|
|
87
|
+
parameters: {
|
|
88
|
+
type: 'object',
|
|
89
|
+
properties: tool.input_schema.properties,
|
|
90
|
+
...(tool.input_schema.required && { required: tool.input_schema.required }),
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Translate tools to OpenAI function format (without wrapper).
|
|
98
|
+
*
|
|
99
|
+
* Some OpenAI-compatible APIs expect just the function definitions
|
|
100
|
+
* without the { type: "function", function: {...} } wrapper.
|
|
101
|
+
*
|
|
102
|
+
* @param tools - Array of tools in internal format
|
|
103
|
+
* @returns Array of function definitions
|
|
104
|
+
* @throws TranslationError if validation fails
|
|
105
|
+
*/
|
|
106
|
+
export function toOpenAIFunctions(tools) {
|
|
107
|
+
if (!tools || tools.length === 0) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
return tools.map((tool, index) => {
|
|
111
|
+
validateTool(tool, index);
|
|
112
|
+
return {
|
|
113
|
+
name: tool.name,
|
|
114
|
+
description: tool.description,
|
|
115
|
+
parameters: {
|
|
116
|
+
type: 'object',
|
|
117
|
+
properties: tool.input_schema.properties,
|
|
118
|
+
...(tool.input_schema.required && { required: tool.input_schema.required }),
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Translate tools to Gemini format.
|
|
125
|
+
*
|
|
126
|
+
* Gemini uses a different structure where all function declarations
|
|
127
|
+
* are grouped into a single object:
|
|
128
|
+
* - functionDeclarations: Array of function definitions
|
|
129
|
+
*
|
|
130
|
+
* Each function declaration contains:
|
|
131
|
+
* - name: Function name
|
|
132
|
+
* - description: Human-readable description
|
|
133
|
+
* - parameters: JSON Schema for parameters
|
|
134
|
+
*
|
|
135
|
+
* Note: Gemini expects a single tool object containing all functions,
|
|
136
|
+
* not an array of tool objects.
|
|
137
|
+
*
|
|
138
|
+
* @param tools - Array of tools in internal format
|
|
139
|
+
* @returns Single Gemini tool object containing all function declarations
|
|
140
|
+
* @throws TranslationError if validation fails
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* const tools = [{ name: "search", description: "Search the web", input_schema: {...} }];
|
|
144
|
+
* const geminiTools = toGeminiTools(tools);
|
|
145
|
+
* // Returns: { functionDeclarations: [{ name: "search", description: "...", parameters: {...} }] }
|
|
146
|
+
*/
|
|
147
|
+
export function toGeminiTools(tools) {
|
|
148
|
+
if (!tools || tools.length === 0) {
|
|
149
|
+
return { functionDeclarations: [] };
|
|
150
|
+
}
|
|
151
|
+
const functionDeclarations = tools.map((tool, index) => {
|
|
152
|
+
validateTool(tool, index);
|
|
153
|
+
return {
|
|
154
|
+
name: tool.name,
|
|
155
|
+
description: tool.description,
|
|
156
|
+
parameters: {
|
|
157
|
+
type: 'object',
|
|
158
|
+
properties: tool.input_schema.properties,
|
|
159
|
+
...(tool.input_schema.required && { required: tool.input_schema.required }),
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
return { functionDeclarations };
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Translate tools to Gemini format as an array (for API compatibility).
|
|
167
|
+
*
|
|
168
|
+
* Some Gemini API versions expect an array containing the tool object.
|
|
169
|
+
* This is a convenience wrapper around toGeminiTools.
|
|
170
|
+
*
|
|
171
|
+
* @param tools - Array of tools in internal format
|
|
172
|
+
* @returns Array containing a single Gemini tool object
|
|
173
|
+
* @throws TranslationError if validation fails
|
|
174
|
+
*/
|
|
175
|
+
export function toGeminiToolsArray(tools) {
|
|
176
|
+
if (!tools || tools.length === 0) {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
return [toGeminiTools(tools)];
|
|
180
|
+
}
|
|
181
|
+
// ============================================================================
|
|
182
|
+
// Reverse Translation (From Provider Format to Internal)
|
|
183
|
+
// ============================================================================
|
|
184
|
+
/**
|
|
185
|
+
* Translate Anthropic tools to internal format.
|
|
186
|
+
*
|
|
187
|
+
* Since our internal format matches Anthropic, this is essentially a pass-through
|
|
188
|
+
* with validation.
|
|
189
|
+
*
|
|
190
|
+
* @param tools - Array of Anthropic tools
|
|
191
|
+
* @returns Array of tools in internal format
|
|
192
|
+
* @throws TranslationError if validation fails
|
|
193
|
+
*/
|
|
194
|
+
export function fromAnthropicTools(tools) {
|
|
195
|
+
if (!tools || tools.length === 0) {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
return tools.map((tool, index) => {
|
|
199
|
+
if (!tool.name || typeof tool.name !== 'string') {
|
|
200
|
+
throw new TranslationError(`Anthropic tool at index ${index} is missing a valid name`, 'anthropic', 'internal');
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
name: tool.name,
|
|
204
|
+
description: tool.description || '',
|
|
205
|
+
input_schema: {
|
|
206
|
+
type: 'object',
|
|
207
|
+
properties: tool.input_schema?.properties || {},
|
|
208
|
+
...(tool.input_schema?.required && { required: tool.input_schema.required }),
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Translate OpenAI tools to internal format.
|
|
215
|
+
*
|
|
216
|
+
* Unwraps the function object and converts parameters to input_schema.
|
|
217
|
+
*
|
|
218
|
+
* @param tools - Array of OpenAI tools
|
|
219
|
+
* @returns Array of tools in internal format
|
|
220
|
+
* @throws TranslationError if validation fails
|
|
221
|
+
*/
|
|
222
|
+
export function fromOpenAITools(tools) {
|
|
223
|
+
if (!tools || tools.length === 0) {
|
|
224
|
+
return [];
|
|
225
|
+
}
|
|
226
|
+
return tools.map((tool, index) => {
|
|
227
|
+
if (tool.type !== 'function' || !tool.function) {
|
|
228
|
+
throw new TranslationError(`OpenAI tool at index ${index} is not a function tool or is missing function definition`, 'openai', 'internal');
|
|
229
|
+
}
|
|
230
|
+
const func = tool.function;
|
|
231
|
+
if (!func.name || typeof func.name !== 'string') {
|
|
232
|
+
throw new TranslationError(`OpenAI tool at index ${index} is missing a valid function name`, 'openai', 'internal');
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
name: func.name,
|
|
236
|
+
description: func.description || '',
|
|
237
|
+
input_schema: {
|
|
238
|
+
type: 'object',
|
|
239
|
+
properties: func.parameters?.properties || {},
|
|
240
|
+
...(func.parameters?.required && { required: func.parameters.required }),
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Translate Gemini tools to internal format.
|
|
247
|
+
*
|
|
248
|
+
* Extracts function declarations from the Gemini tool object.
|
|
249
|
+
*
|
|
250
|
+
* @param tool - Gemini tool object containing function declarations
|
|
251
|
+
* @returns Array of tools in internal format
|
|
252
|
+
* @throws TranslationError if validation fails
|
|
253
|
+
*/
|
|
254
|
+
export function fromGeminiTools(tool) {
|
|
255
|
+
if (!tool?.functionDeclarations || tool.functionDeclarations.length === 0) {
|
|
256
|
+
return [];
|
|
257
|
+
}
|
|
258
|
+
return tool.functionDeclarations.map((func, index) => {
|
|
259
|
+
if (!func.name || typeof func.name !== 'string') {
|
|
260
|
+
throw new TranslationError(`Gemini function declaration at index ${index} is missing a valid name`, 'gemini', 'internal');
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
name: func.name,
|
|
264
|
+
description: func.description || '',
|
|
265
|
+
input_schema: {
|
|
266
|
+
type: 'object',
|
|
267
|
+
properties: func.parameters?.properties || {},
|
|
268
|
+
...(func.parameters?.required && { required: func.parameters.required }),
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
// ============================================================================
|
|
274
|
+
// Helper Functions
|
|
275
|
+
// ============================================================================
|
|
276
|
+
/**
|
|
277
|
+
* Validate a tool definition.
|
|
278
|
+
*
|
|
279
|
+
* @param tool - Tool to validate
|
|
280
|
+
* @param index - Index in the array (for error messages)
|
|
281
|
+
* @throws TranslationError if the tool is invalid
|
|
282
|
+
*/
|
|
283
|
+
function validateTool(tool, index) {
|
|
284
|
+
if (!tool) {
|
|
285
|
+
throw new TranslationError(`Tool at index ${index} is null or undefined`, 'internal', 'provider');
|
|
286
|
+
}
|
|
287
|
+
if (!tool.name || typeof tool.name !== 'string') {
|
|
288
|
+
throw new TranslationError(`Tool at index ${index} is missing a valid name`, 'internal', 'provider');
|
|
289
|
+
}
|
|
290
|
+
if (!tool.description || typeof tool.description !== 'string') {
|
|
291
|
+
throw new TranslationError(`Tool "${tool.name}" at index ${index} is missing a valid description`, 'internal', 'provider');
|
|
292
|
+
}
|
|
293
|
+
if (!tool.input_schema || typeof tool.input_schema !== 'object') {
|
|
294
|
+
throw new TranslationError(`Tool "${tool.name}" at index ${index} is missing input_schema`, 'internal', 'provider');
|
|
295
|
+
}
|
|
296
|
+
if (tool.input_schema.type !== 'object') {
|
|
297
|
+
throw new TranslationError(`Tool "${tool.name}" at index ${index} has invalid input_schema type (expected "object")`, 'internal', 'provider');
|
|
298
|
+
}
|
|
299
|
+
if (!tool.input_schema.properties || typeof tool.input_schema.properties !== 'object') {
|
|
300
|
+
throw new TranslationError(`Tool "${tool.name}" at index ${index} is missing input_schema.properties`, 'internal', 'provider');
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Translate tools to a specific provider format.
|
|
305
|
+
*
|
|
306
|
+
* Convenience function for dynamic provider selection.
|
|
307
|
+
*
|
|
308
|
+
* @param tools - Array of tools in internal format
|
|
309
|
+
* @param provider - Target provider name
|
|
310
|
+
* @returns Tools in the appropriate provider format
|
|
311
|
+
* @throws TranslationError if the provider is unknown
|
|
312
|
+
*/
|
|
313
|
+
export function translateTools(tools, provider) {
|
|
314
|
+
switch (provider) {
|
|
315
|
+
case 'anthropic':
|
|
316
|
+
return toAnthropicTools(tools);
|
|
317
|
+
case 'openai':
|
|
318
|
+
case 'openrouter':
|
|
319
|
+
case 'zai':
|
|
320
|
+
return toOpenAITools(tools);
|
|
321
|
+
case 'google':
|
|
322
|
+
case 'gemini':
|
|
323
|
+
return toGeminiTools(tools);
|
|
324
|
+
case 'ollama':
|
|
325
|
+
// Ollama uses OpenAI-compatible format
|
|
326
|
+
return toOpenAITools(tools);
|
|
327
|
+
default:
|
|
328
|
+
throw new TranslationError(`Unknown provider: ${provider}`, 'internal', provider);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/translation/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAa,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAyE1D,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC/B,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAE1B,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,YAAY,EAAE;gBACZ,IAAI,EAAE,QAAiB;gBACvB,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU;gBACxC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;aAC5E;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;A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