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,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic Provider Implementation
|
|
3
|
+
*
|
|
4
|
+
* Provider adapter for the Anthropic Claude API.
|
|
5
|
+
* Handles message formatting, streaming, and tool use for Claude models.
|
|
6
|
+
*
|
|
7
|
+
* Supports two access modes:
|
|
8
|
+
* - 'api': Direct HTTP calls to Anthropic API (requires API key)
|
|
9
|
+
* - 'subscription': Uses Claude Agent SDK (requires CLAUDE_CODE_OAUTH_TOKEN)
|
|
10
|
+
*/
|
|
11
|
+
import { BaseProvider } from './base.js';
|
|
12
|
+
import type { CompletionRequest, CompletionResponse, StreamChunk } from '../types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Anthropic Claude API provider adapter.
|
|
15
|
+
*
|
|
16
|
+
* Implements the Provider interface for Anthropic's Claude models.
|
|
17
|
+
* Handles:
|
|
18
|
+
* - Message format translation (our format -> Anthropic format)
|
|
19
|
+
* - Streaming SSE event parsing
|
|
20
|
+
* - Tool use formatting
|
|
21
|
+
* - Authentication via x-api-key header
|
|
22
|
+
*/
|
|
23
|
+
export declare class AnthropicProvider extends BaseProvider {
|
|
24
|
+
readonly name = "anthropic";
|
|
25
|
+
/** Default Anthropic API base URL */
|
|
26
|
+
private readonly DEFAULT_BASE_URL;
|
|
27
|
+
/** Required API version header value */
|
|
28
|
+
private readonly API_VERSION;
|
|
29
|
+
/** Default max tokens if not specified in request */
|
|
30
|
+
private readonly DEFAULT_MAX_TOKENS;
|
|
31
|
+
/**
|
|
32
|
+
* Build Anthropic-specific HTTP headers.
|
|
33
|
+
* Uses x-api-key instead of Bearer token for authentication.
|
|
34
|
+
*/
|
|
35
|
+
protected buildHeaders(): Record<string, string>;
|
|
36
|
+
/**
|
|
37
|
+
* Execute a completion request and return the full response.
|
|
38
|
+
*
|
|
39
|
+
* Supports two modes:
|
|
40
|
+
* - API mode (access_mode: 'api'): Direct HTTP calls to Anthropic API
|
|
41
|
+
* - Subscription mode (access_mode: 'subscription'): Uses Claude Agent SDK
|
|
42
|
+
*
|
|
43
|
+
* @param request - The completion request
|
|
44
|
+
* @returns Promise resolving to the normalized completion response
|
|
45
|
+
*/
|
|
46
|
+
complete(request: CompletionRequest): Promise<CompletionResponse>;
|
|
47
|
+
/**
|
|
48
|
+
* Execute a completion using Claude Agent SDK (subscription mode).
|
|
49
|
+
* Uses CLAUDE_CODE_OAUTH_TOKEN for authentication.
|
|
50
|
+
*
|
|
51
|
+
* @param request - The completion request
|
|
52
|
+
* @returns Promise resolving to the normalized completion response
|
|
53
|
+
*/
|
|
54
|
+
private completeViaSubscription;
|
|
55
|
+
/**
|
|
56
|
+
* Build a single prompt string from messages array.
|
|
57
|
+
* Used for subscription mode where SDK expects a simple prompt.
|
|
58
|
+
*
|
|
59
|
+
* @param messages - Array of messages
|
|
60
|
+
* @returns Combined prompt string
|
|
61
|
+
*/
|
|
62
|
+
private buildPromptFromMessages;
|
|
63
|
+
/**
|
|
64
|
+
* Execute a streaming completion request.
|
|
65
|
+
* Yields normalized StreamChunk events as they arrive.
|
|
66
|
+
*
|
|
67
|
+
* @param request - The completion request
|
|
68
|
+
* @returns Async iterable of stream chunks
|
|
69
|
+
*/
|
|
70
|
+
completeStream(request: CompletionRequest): AsyncIterable<StreamChunk>;
|
|
71
|
+
/**
|
|
72
|
+
* Check if the Anthropic API is available and credentials are valid.
|
|
73
|
+
*
|
|
74
|
+
* @throws ProviderError if the health check fails
|
|
75
|
+
*/
|
|
76
|
+
healthCheck(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Translate our normalized request format to Anthropic's format.
|
|
79
|
+
*
|
|
80
|
+
* @param request - Normalized completion request
|
|
81
|
+
* @returns Anthropic API request body
|
|
82
|
+
*/
|
|
83
|
+
private translateRequest;
|
|
84
|
+
/**
|
|
85
|
+
* Translate normalized messages to Anthropic format.
|
|
86
|
+
* Filters out system messages (handled separately).
|
|
87
|
+
*
|
|
88
|
+
* @param messages - Normalized messages
|
|
89
|
+
* @returns Anthropic-formatted messages
|
|
90
|
+
*/
|
|
91
|
+
private translateMessages;
|
|
92
|
+
/**
|
|
93
|
+
* Translate message content to Anthropic format.
|
|
94
|
+
*
|
|
95
|
+
* @param content - String or content blocks
|
|
96
|
+
* @returns Anthropic-formatted content
|
|
97
|
+
*/
|
|
98
|
+
private translateMessageContent;
|
|
99
|
+
/**
|
|
100
|
+
* Translate a single content block to Anthropic format.
|
|
101
|
+
*
|
|
102
|
+
* @param block - Normalized content block
|
|
103
|
+
* @returns Anthropic content block
|
|
104
|
+
*/
|
|
105
|
+
private translateContentBlock;
|
|
106
|
+
/**
|
|
107
|
+
* Extract system prompt from messages.
|
|
108
|
+
* Our format may include it in messages; Anthropic uses a separate parameter.
|
|
109
|
+
*
|
|
110
|
+
* @returns System prompt string or undefined
|
|
111
|
+
*/
|
|
112
|
+
private extractSystemPrompt;
|
|
113
|
+
/**
|
|
114
|
+
* Translate tools to Anthropic format.
|
|
115
|
+
* Our tool format is already compatible with Anthropic's format.
|
|
116
|
+
*
|
|
117
|
+
* @param tools - Normalized tools
|
|
118
|
+
* @returns Anthropic tool definitions
|
|
119
|
+
*/
|
|
120
|
+
private translateTools;
|
|
121
|
+
/**
|
|
122
|
+
* Translate Anthropic response to our normalized format.
|
|
123
|
+
*
|
|
124
|
+
* @param response - Anthropic API response
|
|
125
|
+
* @returns Normalized completion response
|
|
126
|
+
*/
|
|
127
|
+
private translateResponse;
|
|
128
|
+
/**
|
|
129
|
+
* Translate Anthropic content blocks to our normalized format.
|
|
130
|
+
*
|
|
131
|
+
* @param content - Anthropic content blocks
|
|
132
|
+
* @returns Normalized content blocks
|
|
133
|
+
*/
|
|
134
|
+
private translateResponseContent;
|
|
135
|
+
/**
|
|
136
|
+
* Translate Anthropic usage info to our normalized format.
|
|
137
|
+
*
|
|
138
|
+
* @param usage - Anthropic usage info
|
|
139
|
+
* @returns Normalized usage info
|
|
140
|
+
*/
|
|
141
|
+
private translateUsage;
|
|
142
|
+
/**
|
|
143
|
+
* Parse Anthropic SSE stream and yield normalized stream chunks.
|
|
144
|
+
*
|
|
145
|
+
* @param body - ReadableStream from fetch response
|
|
146
|
+
* @returns Async generator of normalized stream chunks
|
|
147
|
+
*/
|
|
148
|
+
private parseSSEStream;
|
|
149
|
+
/**
|
|
150
|
+
* Translate an Anthropic SSE event to our normalized StreamChunk format.
|
|
151
|
+
*
|
|
152
|
+
* @param event - Anthropic stream event
|
|
153
|
+
* @returns Normalized stream chunk or undefined to skip
|
|
154
|
+
*/
|
|
155
|
+
private translateStreamEvent;
|
|
156
|
+
/**
|
|
157
|
+
* Translate a content block from a stream event.
|
|
158
|
+
*
|
|
159
|
+
* @param block - Anthropic content block from stream
|
|
160
|
+
* @returns Normalized content block
|
|
161
|
+
*/
|
|
162
|
+
private translateContentBlockFromStream;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EAKZ,MAAM,aAAa,CAAC;AA2JrB;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,SAAQ,YAAY;IACjD,SAAgB,IAAI,eAAe;IAEnC,qCAAqC;IACrC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA+B;IAEhE,wCAAwC;IACxC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgB;IAE5C,qDAAqD;IACrD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAQ;IAE3C;;;OAGG;cACgB,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAmBzD;;;;;;;;;OASG;IACU,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAqB9E;;;;;;OAMG;YACW,uBAAuB;IAqDrC;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IAW/B;;;;;;OAMG;IACW,cAAc,CAAC,OAAO,EAAE,iBAAiB,GAAG,aAAa,CAAC,WAAW,CAAC;IAsBpF;;;;OAIG;IACU,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAqBzC;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IA8BxB;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IASzB;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;IAW/B;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;IA+B7B;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAO3B;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;IAQtB;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAUzB;;;;;OAKG;IACH,OAAO,CAAC,wBAAwB;IAiChC;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAiBtB;;;;;OAKG;YACY,cAAc;IAkD7B;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAkC5B;;;;;OAKG;IACH,OAAO,CAAC,+BAA+B;CAuBxC"}
|
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic Provider Implementation
|
|
3
|
+
*
|
|
4
|
+
* Provider adapter for the Anthropic Claude API.
|
|
5
|
+
* Handles message formatting, streaming, and tool use for Claude models.
|
|
6
|
+
*
|
|
7
|
+
* Supports two access modes:
|
|
8
|
+
* - 'api': Direct HTTP calls to Anthropic API (requires API key)
|
|
9
|
+
* - 'subscription': Uses Claude Agent SDK (requires CLAUDE_CODE_OAUTH_TOKEN)
|
|
10
|
+
*/
|
|
11
|
+
import { BaseProvider } from './base.js';
|
|
12
|
+
import { query } from '@anthropic-ai/claude-agent-sdk';
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Anthropic Provider
|
|
15
|
+
// ============================================================================
|
|
16
|
+
/**
|
|
17
|
+
* Anthropic Claude API provider adapter.
|
|
18
|
+
*
|
|
19
|
+
* Implements the Provider interface for Anthropic's Claude models.
|
|
20
|
+
* Handles:
|
|
21
|
+
* - Message format translation (our format -> Anthropic format)
|
|
22
|
+
* - Streaming SSE event parsing
|
|
23
|
+
* - Tool use formatting
|
|
24
|
+
* - Authentication via x-api-key header
|
|
25
|
+
*/
|
|
26
|
+
export class AnthropicProvider extends BaseProvider {
|
|
27
|
+
name = 'anthropic';
|
|
28
|
+
/** Default Anthropic API base URL */
|
|
29
|
+
DEFAULT_BASE_URL = 'https://api.anthropic.com';
|
|
30
|
+
/** Required API version header value */
|
|
31
|
+
API_VERSION = '2023-06-01';
|
|
32
|
+
/** Default max tokens if not specified in request */
|
|
33
|
+
DEFAULT_MAX_TOKENS = 4096;
|
|
34
|
+
/**
|
|
35
|
+
* Build Anthropic-specific HTTP headers.
|
|
36
|
+
* Uses x-api-key instead of Bearer token for authentication.
|
|
37
|
+
*/
|
|
38
|
+
buildHeaders() {
|
|
39
|
+
const headers = {
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
'anthropic-version': this.API_VERSION,
|
|
42
|
+
};
|
|
43
|
+
// Anthropic uses x-api-key header instead of Bearer token
|
|
44
|
+
if (this.config.api_key) {
|
|
45
|
+
headers['x-api-key'] = this.config.api_key;
|
|
46
|
+
}
|
|
47
|
+
// Add any custom headers from config
|
|
48
|
+
if (this.config.headers) {
|
|
49
|
+
Object.assign(headers, this.config.headers);
|
|
50
|
+
}
|
|
51
|
+
return headers;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Execute a completion request and return the full response.
|
|
55
|
+
*
|
|
56
|
+
* Supports two modes:
|
|
57
|
+
* - API mode (access_mode: 'api'): Direct HTTP calls to Anthropic API
|
|
58
|
+
* - Subscription mode (access_mode: 'subscription'): Uses Claude Agent SDK
|
|
59
|
+
*
|
|
60
|
+
* @param request - The completion request
|
|
61
|
+
* @returns Promise resolving to the normalized completion response
|
|
62
|
+
*/
|
|
63
|
+
async complete(request) {
|
|
64
|
+
// Use subscription mode if configured (no API key, uses CLAUDE_CODE_OAUTH_TOKEN)
|
|
65
|
+
if (this.config.access_mode === 'subscription') {
|
|
66
|
+
return this.completeViaSubscription(request);
|
|
67
|
+
}
|
|
68
|
+
// Default: API mode with direct HTTP calls
|
|
69
|
+
const url = `${this.getBaseUrl(this.DEFAULT_BASE_URL)}/v1/messages`;
|
|
70
|
+
const anthropicRequest = this.translateRequest(request);
|
|
71
|
+
const response = await this.makeRequest({
|
|
72
|
+
method: 'POST',
|
|
73
|
+
url,
|
|
74
|
+
headers: this.buildHeaders(),
|
|
75
|
+
body: anthropicRequest,
|
|
76
|
+
timeoutMs: request.timeout_ms ?? this.defaultTimeoutMs,
|
|
77
|
+
});
|
|
78
|
+
return this.translateResponse(response);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Execute a completion using Claude Agent SDK (subscription mode).
|
|
82
|
+
* Uses CLAUDE_CODE_OAUTH_TOKEN for authentication.
|
|
83
|
+
*
|
|
84
|
+
* @param request - The completion request
|
|
85
|
+
* @returns Promise resolving to the normalized completion response
|
|
86
|
+
*/
|
|
87
|
+
async completeViaSubscription(request) {
|
|
88
|
+
// Build prompt from messages
|
|
89
|
+
const prompt = this.buildPromptFromMessages(request.messages);
|
|
90
|
+
// Use the Claude Agent SDK's query function
|
|
91
|
+
const q = query({
|
|
92
|
+
prompt,
|
|
93
|
+
options: {
|
|
94
|
+
model: request.model,
|
|
95
|
+
// Pass environment to subprocess (includes CLAUDE_CODE_OAUTH_TOKEN)
|
|
96
|
+
env: { ...process.env },
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
// Collect all text content from the response
|
|
100
|
+
let responseText = '';
|
|
101
|
+
let inputTokens = 0;
|
|
102
|
+
let outputTokens = 0;
|
|
103
|
+
for await (const message of q) {
|
|
104
|
+
// Handle different message types from the SDK
|
|
105
|
+
if (message.type === 'assistant') {
|
|
106
|
+
// SDKAssistantMessage contains BetaMessage with content and usage
|
|
107
|
+
const betaMessage = message.message;
|
|
108
|
+
// Extract text from content blocks
|
|
109
|
+
for (const block of betaMessage.content) {
|
|
110
|
+
if (block.type === 'text') {
|
|
111
|
+
responseText += block.text;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Extract usage from BetaMessage
|
|
115
|
+
if (betaMessage.usage) {
|
|
116
|
+
inputTokens = betaMessage.usage.input_tokens || 0;
|
|
117
|
+
outputTokens = betaMessage.usage.output_tokens || 0;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Return normalized response
|
|
122
|
+
return {
|
|
123
|
+
id: `sub_${Date.now()}`,
|
|
124
|
+
content: [{ type: 'text', text: responseText }],
|
|
125
|
+
model: request.model,
|
|
126
|
+
stop_reason: 'end_turn',
|
|
127
|
+
usage: {
|
|
128
|
+
input_tokens: inputTokens,
|
|
129
|
+
output_tokens: outputTokens,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Build a single prompt string from messages array.
|
|
135
|
+
* Used for subscription mode where SDK expects a simple prompt.
|
|
136
|
+
*
|
|
137
|
+
* @param messages - Array of messages
|
|
138
|
+
* @returns Combined prompt string
|
|
139
|
+
*/
|
|
140
|
+
buildPromptFromMessages(messages) {
|
|
141
|
+
return messages
|
|
142
|
+
.map((msg) => {
|
|
143
|
+
const content = typeof msg.content === 'string'
|
|
144
|
+
? msg.content
|
|
145
|
+
: msg.content.map(b => b.type === 'text' ? b.text : '').join('');
|
|
146
|
+
return `${msg.role}: ${content}`;
|
|
147
|
+
})
|
|
148
|
+
.join('\n\n');
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Execute a streaming completion request.
|
|
152
|
+
* Yields normalized StreamChunk events as they arrive.
|
|
153
|
+
*
|
|
154
|
+
* @param request - The completion request
|
|
155
|
+
* @returns Async iterable of stream chunks
|
|
156
|
+
*/
|
|
157
|
+
async *completeStream(request) {
|
|
158
|
+
const url = `${this.getBaseUrl(this.DEFAULT_BASE_URL)}/v1/messages`;
|
|
159
|
+
const anthropicRequest = this.translateRequest(request);
|
|
160
|
+
anthropicRequest.stream = true;
|
|
161
|
+
const response = await this.makeStreamingRequest({
|
|
162
|
+
method: 'POST',
|
|
163
|
+
url,
|
|
164
|
+
headers: this.buildHeaders(),
|
|
165
|
+
body: anthropicRequest,
|
|
166
|
+
timeoutMs: request.timeout_ms ?? this.defaultTimeoutMs,
|
|
167
|
+
stream: true,
|
|
168
|
+
});
|
|
169
|
+
if (!response.body) {
|
|
170
|
+
throw new Error('Response body is null');
|
|
171
|
+
}
|
|
172
|
+
// Parse SSE stream
|
|
173
|
+
yield* this.parseSSEStream(response.body);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Check if the Anthropic API is available and credentials are valid.
|
|
177
|
+
*
|
|
178
|
+
* @throws ProviderError if the health check fails
|
|
179
|
+
*/
|
|
180
|
+
async healthCheck() {
|
|
181
|
+
// For subscription mode, we can't easily verify without spawning SDK
|
|
182
|
+
// Just check if the OAuth token exists
|
|
183
|
+
if (this.config.access_mode === 'subscription') {
|
|
184
|
+
if (!process.env['CLAUDE_CODE_OAUTH_TOKEN']) {
|
|
185
|
+
throw new Error('Subscription mode requires CLAUDE_CODE_OAUTH_TOKEN environment variable');
|
|
186
|
+
}
|
|
187
|
+
return; // Token exists, assume healthy
|
|
188
|
+
}
|
|
189
|
+
// API mode: Make a minimal request to verify credentials
|
|
190
|
+
const request = {
|
|
191
|
+
model: 'claude-3-haiku-20240307',
|
|
192
|
+
messages: [{ role: 'user', content: 'ping' }],
|
|
193
|
+
max_tokens: 1,
|
|
194
|
+
};
|
|
195
|
+
// If this throws, the health check failed
|
|
196
|
+
await this.complete(request);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Translate our normalized request format to Anthropic's format.
|
|
200
|
+
*
|
|
201
|
+
* @param request - Normalized completion request
|
|
202
|
+
* @returns Anthropic API request body
|
|
203
|
+
*/
|
|
204
|
+
translateRequest(request) {
|
|
205
|
+
const anthropicRequest = {
|
|
206
|
+
model: request.model,
|
|
207
|
+
messages: this.translateMessages(request.messages),
|
|
208
|
+
max_tokens: request.max_tokens ?? this.DEFAULT_MAX_TOKENS,
|
|
209
|
+
};
|
|
210
|
+
// Add optional parameters
|
|
211
|
+
if (request.temperature !== undefined) {
|
|
212
|
+
anthropicRequest.temperature = request.temperature;
|
|
213
|
+
}
|
|
214
|
+
// Extract system prompt from messages if present
|
|
215
|
+
const systemPrompt = this.extractSystemPrompt();
|
|
216
|
+
if (systemPrompt) {
|
|
217
|
+
anthropicRequest.system = systemPrompt;
|
|
218
|
+
}
|
|
219
|
+
// Translate tools if present
|
|
220
|
+
if (request.tools && request.tools.length > 0) {
|
|
221
|
+
anthropicRequest.tools = this.translateTools(request.tools);
|
|
222
|
+
}
|
|
223
|
+
if (request.stream) {
|
|
224
|
+
anthropicRequest.stream = true;
|
|
225
|
+
}
|
|
226
|
+
return anthropicRequest;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Translate normalized messages to Anthropic format.
|
|
230
|
+
* Filters out system messages (handled separately).
|
|
231
|
+
*
|
|
232
|
+
* @param messages - Normalized messages
|
|
233
|
+
* @returns Anthropic-formatted messages
|
|
234
|
+
*/
|
|
235
|
+
translateMessages(messages) {
|
|
236
|
+
return messages
|
|
237
|
+
.filter((msg) => msg.role === 'user' || msg.role === 'assistant')
|
|
238
|
+
.map((msg) => ({
|
|
239
|
+
role: msg.role,
|
|
240
|
+
content: this.translateMessageContent(msg.content),
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Translate message content to Anthropic format.
|
|
245
|
+
*
|
|
246
|
+
* @param content - String or content blocks
|
|
247
|
+
* @returns Anthropic-formatted content
|
|
248
|
+
*/
|
|
249
|
+
translateMessageContent(content) {
|
|
250
|
+
if (typeof content === 'string') {
|
|
251
|
+
return content;
|
|
252
|
+
}
|
|
253
|
+
// Translate content blocks
|
|
254
|
+
return content.map((block) => this.translateContentBlock(block));
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Translate a single content block to Anthropic format.
|
|
258
|
+
*
|
|
259
|
+
* @param block - Normalized content block
|
|
260
|
+
* @returns Anthropic content block
|
|
261
|
+
*/
|
|
262
|
+
translateContentBlock(block) {
|
|
263
|
+
switch (block.type) {
|
|
264
|
+
case 'text':
|
|
265
|
+
return {
|
|
266
|
+
type: 'text',
|
|
267
|
+
text: block.text ?? '',
|
|
268
|
+
};
|
|
269
|
+
case 'tool_use':
|
|
270
|
+
return {
|
|
271
|
+
type: 'tool_use',
|
|
272
|
+
id: block.id ?? '',
|
|
273
|
+
name: block.name ?? '',
|
|
274
|
+
input: block.input ?? {},
|
|
275
|
+
};
|
|
276
|
+
case 'tool_result':
|
|
277
|
+
return {
|
|
278
|
+
type: 'tool_result',
|
|
279
|
+
tool_use_id: block.tool_use_id ?? '',
|
|
280
|
+
content: block.content ?? '',
|
|
281
|
+
};
|
|
282
|
+
default:
|
|
283
|
+
return {
|
|
284
|
+
type: 'text',
|
|
285
|
+
text: '',
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Extract system prompt from messages.
|
|
291
|
+
* Our format may include it in messages; Anthropic uses a separate parameter.
|
|
292
|
+
*
|
|
293
|
+
* @returns System prompt string or undefined
|
|
294
|
+
*/
|
|
295
|
+
extractSystemPrompt() {
|
|
296
|
+
// Look for a system message (not part of standard Message type, but may be passed)
|
|
297
|
+
// For now, we don't have system role in Message type, so return undefined
|
|
298
|
+
// The system prompt should be passed via the role config, not in messages
|
|
299
|
+
return undefined;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Translate tools to Anthropic format.
|
|
303
|
+
* Our tool format is already compatible with Anthropic's format.
|
|
304
|
+
*
|
|
305
|
+
* @param tools - Normalized tools
|
|
306
|
+
* @returns Anthropic tool definitions
|
|
307
|
+
*/
|
|
308
|
+
translateTools(tools) {
|
|
309
|
+
return tools.map((tool) => ({
|
|
310
|
+
name: tool.name,
|
|
311
|
+
description: tool.description,
|
|
312
|
+
input_schema: tool.input_schema,
|
|
313
|
+
}));
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Translate Anthropic response to our normalized format.
|
|
317
|
+
*
|
|
318
|
+
* @param response - Anthropic API response
|
|
319
|
+
* @returns Normalized completion response
|
|
320
|
+
*/
|
|
321
|
+
translateResponse(response) {
|
|
322
|
+
return {
|
|
323
|
+
id: response.id,
|
|
324
|
+
content: this.translateResponseContent(response.content),
|
|
325
|
+
model: response.model,
|
|
326
|
+
stop_reason: response.stop_reason,
|
|
327
|
+
usage: this.translateUsage(response.usage),
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Translate Anthropic content blocks to our normalized format.
|
|
332
|
+
*
|
|
333
|
+
* @param content - Anthropic content blocks
|
|
334
|
+
* @returns Normalized content blocks
|
|
335
|
+
*/
|
|
336
|
+
translateResponseContent(content) {
|
|
337
|
+
return content.map((block) => {
|
|
338
|
+
switch (block.type) {
|
|
339
|
+
case 'text':
|
|
340
|
+
return {
|
|
341
|
+
type: 'text',
|
|
342
|
+
text: block.text ?? '',
|
|
343
|
+
};
|
|
344
|
+
case 'tool_use':
|
|
345
|
+
return {
|
|
346
|
+
type: 'tool_use',
|
|
347
|
+
id: block.id ?? '',
|
|
348
|
+
name: block.name ?? '',
|
|
349
|
+
input: block.input ?? {},
|
|
350
|
+
};
|
|
351
|
+
case 'tool_result':
|
|
352
|
+
return {
|
|
353
|
+
type: 'tool_result',
|
|
354
|
+
tool_use_id: block.tool_use_id ?? '',
|
|
355
|
+
content: block.content ?? '',
|
|
356
|
+
};
|
|
357
|
+
default:
|
|
358
|
+
return {
|
|
359
|
+
type: 'text',
|
|
360
|
+
text: '',
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Translate Anthropic usage info to our normalized format.
|
|
367
|
+
*
|
|
368
|
+
* @param usage - Anthropic usage info
|
|
369
|
+
* @returns Normalized usage info
|
|
370
|
+
*/
|
|
371
|
+
translateUsage(usage) {
|
|
372
|
+
const result = {
|
|
373
|
+
input_tokens: usage.input_tokens,
|
|
374
|
+
output_tokens: usage.output_tokens,
|
|
375
|
+
};
|
|
376
|
+
// Only add cache tokens if they are defined
|
|
377
|
+
if (usage.cache_creation_input_tokens !== undefined) {
|
|
378
|
+
result.cache_creation_input_tokens = usage.cache_creation_input_tokens;
|
|
379
|
+
}
|
|
380
|
+
if (usage.cache_read_input_tokens !== undefined) {
|
|
381
|
+
result.cache_read_input_tokens = usage.cache_read_input_tokens;
|
|
382
|
+
}
|
|
383
|
+
return result;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Parse Anthropic SSE stream and yield normalized stream chunks.
|
|
387
|
+
*
|
|
388
|
+
* @param body - ReadableStream from fetch response
|
|
389
|
+
* @returns Async generator of normalized stream chunks
|
|
390
|
+
*/
|
|
391
|
+
async *parseSSEStream(body) {
|
|
392
|
+
const reader = body.getReader();
|
|
393
|
+
const decoder = new TextDecoder();
|
|
394
|
+
let buffer = '';
|
|
395
|
+
try {
|
|
396
|
+
while (true) {
|
|
397
|
+
const { done, value } = await reader.read();
|
|
398
|
+
if (done) {
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
buffer += decoder.decode(value, { stream: true });
|
|
402
|
+
// Process complete events from buffer
|
|
403
|
+
const lines = buffer.split('\n');
|
|
404
|
+
buffer = lines.pop() ?? ''; // Keep incomplete line in buffer
|
|
405
|
+
for (const line of lines) {
|
|
406
|
+
const trimmedLine = line.trim();
|
|
407
|
+
// Skip empty lines and comments
|
|
408
|
+
if (!trimmedLine || trimmedLine.startsWith(':')) {
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
// Parse SSE data line
|
|
412
|
+
if (trimmedLine.startsWith('data: ')) {
|
|
413
|
+
const data = trimmedLine.slice(6);
|
|
414
|
+
// Handle stream end marker
|
|
415
|
+
if (data === '[DONE]') {
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
try {
|
|
419
|
+
const event = JSON.parse(data);
|
|
420
|
+
const chunk = this.translateStreamEvent(event);
|
|
421
|
+
if (chunk) {
|
|
422
|
+
yield chunk;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
catch {
|
|
426
|
+
// Skip malformed JSON
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
finally {
|
|
433
|
+
reader.releaseLock();
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Translate an Anthropic SSE event to our normalized StreamChunk format.
|
|
438
|
+
*
|
|
439
|
+
* @param event - Anthropic stream event
|
|
440
|
+
* @returns Normalized stream chunk or undefined to skip
|
|
441
|
+
*/
|
|
442
|
+
translateStreamEvent(event) {
|
|
443
|
+
switch (event.type) {
|
|
444
|
+
case 'content_block_start':
|
|
445
|
+
return {
|
|
446
|
+
type: 'content_block_start',
|
|
447
|
+
index: event.index,
|
|
448
|
+
content_block: this.translateContentBlockFromStream(event.content_block),
|
|
449
|
+
};
|
|
450
|
+
case 'content_block_delta': {
|
|
451
|
+
const delta = {
|
|
452
|
+
type: event.delta.type,
|
|
453
|
+
};
|
|
454
|
+
if (event.delta.text !== undefined) {
|
|
455
|
+
delta.text = event.delta.text;
|
|
456
|
+
}
|
|
457
|
+
return {
|
|
458
|
+
type: 'content_block_delta',
|
|
459
|
+
index: event.index,
|
|
460
|
+
delta,
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
case 'message_stop':
|
|
464
|
+
return {
|
|
465
|
+
type: 'message_stop',
|
|
466
|
+
};
|
|
467
|
+
// Skip other events (message_start, content_block_stop, ping, etc.)
|
|
468
|
+
default:
|
|
469
|
+
return undefined;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Translate a content block from a stream event.
|
|
474
|
+
*
|
|
475
|
+
* @param block - Anthropic content block from stream
|
|
476
|
+
* @returns Normalized content block
|
|
477
|
+
*/
|
|
478
|
+
translateContentBlockFromStream(block) {
|
|
479
|
+
switch (block.type) {
|
|
480
|
+
case 'text':
|
|
481
|
+
return {
|
|
482
|
+
type: 'text',
|
|
483
|
+
text: block.text ?? '',
|
|
484
|
+
};
|
|
485
|
+
case 'tool_use':
|
|
486
|
+
return {
|
|
487
|
+
type: 'tool_use',
|
|
488
|
+
id: block.id ?? '',
|
|
489
|
+
name: block.name ?? '',
|
|
490
|
+
input: block.input ?? {},
|
|
491
|
+
};
|
|
492
|
+
default:
|
|
493
|
+
return {
|
|
494
|
+
type: 'text',
|
|
495
|
+
text: '',
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAiKvD,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E;;;;;;;;;GASG;AACH,MAAM,OAAO,iBAAkB,SAAQ,YAAY;IACjC,IAAI,GAAG,WAAW,CAAC;IAEnC,qCAAqC;IACpB,gBAAgB,GAAG,2BAA2B,CAAC;IAEhE,wCAAwC;IACvB,WAAW,GAAG,YAAY,CAAC;IAE5C,qDAAqD;IACpC,kBAAkB,GAAG,IAAI,CAAC;IAE3C;;;OAGG;IACgB,YAAY;QAC7B,MAAM,OAAO,GAA2B;YACtC,cAAc,EAAE,kBAAkB;YAClC,mBAAmB,EAAE,IAAI,CAAC,WAAW;SACtC,CAAC;QAEF,0DAA0D;QAC1D,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACxB,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QAC7C,CAAC;QAED,qCAAqC;QACrC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACxB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC9C,CAA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