kagent-ts 0.1.3 → 0.1.5
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 +68 -21
- package/README.md +27 -371
- package/dist/compression/progressive-compressor.d.ts +66 -0
- package/dist/compression/progressive-compressor.d.ts.map +1 -0
- package/dist/compression/progressive-compressor.js +367 -0
- package/dist/compression/progressive-compressor.js.map +1 -0
- package/dist/compression/types.d.ts +1 -5
- package/dist/compression/types.d.ts.map +1 -1
- package/dist/context/context-manager.d.ts +34 -15
- package/dist/context/context-manager.d.ts.map +1 -1
- package/dist/context/context-manager.js +78 -28
- package/dist/context/context-manager.js.map +1 -1
- package/dist/context/types.d.ts +20 -4
- package/dist/context/types.d.ts.map +1 -1
- package/dist/core/agent.d.ts +407 -35
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +685 -70
- package/dist/core/agent.js.map +1 -1
- package/dist/core/fusion-agent.d.ts +207 -0
- package/dist/core/fusion-agent.d.ts.map +1 -0
- package/dist/core/fusion-agent.js +769 -0
- package/dist/core/fusion-agent.js.map +1 -0
- package/dist/core/hooks.d.ts +19 -7
- package/dist/core/hooks.d.ts.map +1 -1
- package/dist/core/plan-solve-agent.d.ts +1 -15
- package/dist/core/plan-solve-agent.d.ts.map +1 -1
- package/dist/core/plan-solve-agent.js +144 -117
- package/dist/core/plan-solve-agent.js.map +1 -1
- package/dist/core/react-agent.d.ts +0 -13
- package/dist/core/react-agent.d.ts.map +1 -1
- package/dist/core/react-agent.js +128 -101
- package/dist/core/react-agent.js.map +1 -1
- package/dist/core/response-schema.d.ts +65 -0
- package/dist/core/response-schema.d.ts.map +1 -1
- package/dist/core/response-schema.js +174 -1
- package/dist/core/response-schema.js.map +1 -1
- package/dist/core/system-prompts.d.ts +27 -0
- package/dist/core/system-prompts.d.ts.map +1 -0
- package/dist/core/system-prompts.js +112 -0
- package/dist/core/system-prompts.js.map +1 -0
- package/dist/eval/benchmark.d.ts +81 -0
- package/dist/eval/benchmark.d.ts.map +1 -0
- package/dist/eval/benchmark.js +292 -0
- package/dist/eval/benchmark.js.map +1 -0
- package/dist/eval/eval-runner.d.ts +79 -0
- package/dist/eval/eval-runner.d.ts.map +1 -0
- package/dist/eval/eval-runner.js +252 -0
- package/dist/eval/eval-runner.js.map +1 -0
- package/dist/eval/index.d.ts +7 -0
- package/dist/eval/index.d.ts.map +1 -0
- package/dist/eval/index.js +13 -0
- package/dist/eval/index.js.map +1 -0
- package/dist/eval/tool-call-evaluator.d.ts +72 -0
- package/dist/eval/tool-call-evaluator.d.ts.map +1 -0
- package/dist/eval/tool-call-evaluator.js +265 -0
- package/dist/eval/tool-call-evaluator.js.map +1 -0
- package/dist/eval/types.d.ts +219 -0
- package/dist/eval/types.d.ts.map +1 -0
- package/dist/eval/types.js +3 -0
- package/dist/eval/types.js.map +1 -0
- package/dist/index.d.ts +61 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +121 -8
- package/dist/index.js.map +1 -1
- package/dist/llm/anthropic-provider.d.ts +141 -0
- package/dist/llm/anthropic-provider.d.ts.map +1 -0
- package/dist/llm/anthropic-provider.js +486 -0
- package/dist/llm/anthropic-provider.js.map +1 -0
- package/dist/llm/errors.d.ts +26 -0
- package/dist/llm/errors.d.ts.map +1 -0
- package/dist/llm/errors.js +19 -0
- package/dist/llm/errors.js.map +1 -0
- package/dist/llm/factory.d.ts +73 -0
- package/dist/llm/factory.d.ts.map +1 -0
- package/dist/llm/factory.js +77 -0
- package/dist/llm/factory.js.map +1 -0
- package/dist/llm/fallback-provider.d.ts +47 -0
- package/dist/llm/fallback-provider.d.ts.map +1 -0
- package/dist/llm/fallback-provider.js +91 -0
- package/dist/llm/fallback-provider.js.map +1 -0
- package/dist/llm/interface.d.ts +54 -11
- package/dist/llm/interface.d.ts.map +1 -1
- package/dist/llm/interface.js +34 -0
- package/dist/llm/interface.js.map +1 -1
- package/dist/llm/model-router.d.ts +126 -0
- package/dist/llm/model-router.d.ts.map +1 -0
- package/dist/llm/model-router.js +178 -0
- package/dist/llm/model-router.js.map +1 -0
- package/dist/llm/openai-provider.d.ts +8 -32
- package/dist/llm/openai-provider.d.ts.map +1 -1
- package/dist/llm/openai-provider.js +27 -60
- package/dist/llm/openai-provider.js.map +1 -1
- package/dist/llm/rate-limiter.d.ts +41 -0
- package/dist/llm/rate-limiter.d.ts.map +1 -0
- package/dist/llm/rate-limiter.js +93 -0
- package/dist/llm/rate-limiter.js.map +1 -0
- package/dist/llm/retry.d.ts +26 -0
- package/dist/llm/retry.d.ts.map +1 -0
- package/dist/llm/retry.js +44 -0
- package/dist/llm/retry.js.map +1 -0
- package/dist/llm/token-budget.d.ts +97 -0
- package/dist/llm/token-budget.d.ts.map +1 -0
- package/dist/llm/token-budget.js +115 -0
- package/dist/llm/token-budget.js.map +1 -0
- package/dist/logging/index.d.ts +2 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +7 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger.d.ts +38 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +34 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +8 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/mcp-client-manager.d.ts +72 -0
- package/dist/mcp/mcp-client-manager.d.ts.map +1 -0
- package/dist/mcp/mcp-client-manager.js +235 -0
- package/dist/mcp/mcp-client-manager.js.map +1 -0
- package/dist/mcp/mcp-types.d.ts +58 -0
- package/dist/mcp/mcp-types.d.ts.map +1 -0
- package/dist/mcp/mcp-types.js +20 -0
- package/dist/mcp/mcp-types.js.map +1 -0
- package/dist/memory/index.d.ts +3 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +6 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/memory-manager.d.ts +119 -0
- package/dist/memory/memory-manager.d.ts.map +1 -0
- package/dist/memory/memory-manager.js +334 -0
- package/dist/memory/memory-manager.js.map +1 -0
- package/dist/messages/types.d.ts +2 -0
- package/dist/messages/types.d.ts.map +1 -1
- package/dist/orchestrator/index.d.ts +5 -0
- package/dist/orchestrator/index.d.ts.map +1 -0
- package/dist/orchestrator/index.js +13 -0
- package/dist/orchestrator/index.js.map +1 -0
- package/dist/orchestrator/json-extractor.d.ts +18 -0
- package/dist/orchestrator/json-extractor.d.ts.map +1 -0
- package/dist/orchestrator/json-extractor.js +111 -0
- package/dist/orchestrator/json-extractor.js.map +1 -0
- package/dist/orchestrator/orchestrator-agent.d.ts +152 -0
- package/dist/orchestrator/orchestrator-agent.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator-agent.js +675 -0
- package/dist/orchestrator/orchestrator-agent.js.map +1 -0
- package/dist/orchestrator/orchestrator-response.d.ts +40 -0
- package/dist/orchestrator/orchestrator-response.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator-response.js +275 -0
- package/dist/orchestrator/orchestrator-response.js.map +1 -0
- package/dist/orchestrator/orchestrator-types.d.ts +116 -0
- package/dist/orchestrator/orchestrator-types.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator-types.js +3 -0
- package/dist/orchestrator/orchestrator-types.js.map +1 -0
- package/dist/preferences/preference-manager.d.ts +8 -3
- package/dist/preferences/preference-manager.d.ts.map +1 -1
- package/dist/preferences/preference-manager.js +17 -4
- package/dist/preferences/preference-manager.js.map +1 -1
- package/dist/rag/chroma-store.d.ts +52 -0
- package/dist/rag/chroma-store.d.ts.map +1 -0
- package/dist/rag/chroma-store.js +110 -0
- package/dist/rag/chroma-store.js.map +1 -0
- package/dist/rag/document-loader.d.ts +21 -0
- package/dist/rag/document-loader.d.ts.map +1 -0
- package/dist/rag/document-loader.js +129 -0
- package/dist/rag/document-loader.js.map +1 -0
- package/dist/rag/embedding-provider.d.ts +36 -0
- package/dist/rag/embedding-provider.d.ts.map +1 -0
- package/dist/rag/embedding-provider.js +74 -0
- package/dist/rag/embedding-provider.js.map +1 -0
- package/dist/rag/index.d.ts +17 -0
- package/dist/rag/index.d.ts.map +1 -0
- package/dist/rag/index.js +27 -0
- package/dist/rag/index.js.map +1 -0
- package/dist/rag/keyword-index.d.ts +53 -0
- package/dist/rag/keyword-index.d.ts.map +1 -0
- package/dist/rag/keyword-index.js +161 -0
- package/dist/rag/keyword-index.js.map +1 -0
- package/dist/rag/llm-reranker.d.ts +36 -0
- package/dist/rag/llm-reranker.d.ts.map +1 -0
- package/dist/rag/llm-reranker.js +95 -0
- package/dist/rag/llm-reranker.js.map +1 -0
- package/dist/rag/rag-manager.d.ts +54 -0
- package/dist/rag/rag-manager.d.ts.map +1 -0
- package/dist/rag/rag-manager.js +179 -0
- package/dist/rag/rag-manager.js.map +1 -0
- package/dist/rag/rag-types.d.ts +143 -0
- package/dist/rag/rag-types.d.ts.map +1 -0
- package/dist/rag/rag-types.js +9 -0
- package/dist/rag/rag-types.js.map +1 -0
- package/dist/rag/rrf.d.ts +47 -0
- package/dist/rag/rrf.d.ts.map +1 -0
- package/dist/rag/rrf.js +70 -0
- package/dist/rag/rrf.js.map +1 -0
- package/dist/rag/search-knowledge.d.ts +24 -0
- package/dist/rag/search-knowledge.d.ts.map +1 -0
- package/dist/rag/search-knowledge.js +86 -0
- package/dist/rag/search-knowledge.js.map +1 -0
- package/dist/rag/text-splitter.d.ts +25 -0
- package/dist/rag/text-splitter.d.ts.map +1 -0
- package/dist/rag/text-splitter.js +136 -0
- package/dist/rag/text-splitter.js.map +1 -0
- package/dist/rag/vector-store.d.ts +34 -0
- package/dist/rag/vector-store.d.ts.map +1 -0
- package/dist/rag/vector-store.js +73 -0
- package/dist/rag/vector-store.js.map +1 -0
- package/dist/reflection/error-notebook.d.ts +125 -0
- package/dist/reflection/error-notebook.d.ts.map +1 -0
- package/dist/reflection/error-notebook.js +368 -0
- package/dist/reflection/error-notebook.js.map +1 -0
- package/dist/reflection/index.d.ts +8 -0
- package/dist/reflection/index.d.ts.map +1 -0
- package/dist/reflection/index.js +12 -0
- package/dist/reflection/index.js.map +1 -0
- package/dist/reflection/memory-reflector.d.ts +97 -0
- package/dist/reflection/memory-reflector.d.ts.map +1 -0
- package/dist/reflection/memory-reflector.js +215 -0
- package/dist/reflection/memory-reflector.js.map +1 -0
- package/dist/reflection/reflection-agent.d.ts +105 -0
- package/dist/reflection/reflection-agent.d.ts.map +1 -0
- package/dist/reflection/reflection-agent.js +234 -0
- package/dist/reflection/reflection-agent.js.map +1 -0
- package/dist/reflection/reflection-hook.d.ts +50 -0
- package/dist/reflection/reflection-hook.d.ts.map +1 -0
- package/dist/reflection/reflection-hook.js +108 -0
- package/dist/reflection/reflection-hook.js.map +1 -0
- package/dist/rules/project-rules.d.ts +47 -0
- package/dist/rules/project-rules.d.ts.map +1 -0
- package/dist/rules/project-rules.js +166 -0
- package/dist/rules/project-rules.js.map +1 -0
- package/dist/security/boundaries.d.ts +81 -0
- package/dist/security/boundaries.d.ts.map +1 -0
- package/dist/security/boundaries.js +158 -0
- package/dist/security/boundaries.js.map +1 -0
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +11 -0
- package/dist/security/index.js.map +1 -0
- package/dist/session/session-types.d.ts +25 -4
- package/dist/session/session-types.d.ts.map +1 -1
- package/dist/skills/file-skill-loader.d.ts +9 -20
- package/dist/skills/file-skill-loader.d.ts.map +1 -1
- package/dist/skills/file-skill-loader.js +35 -164
- package/dist/skills/file-skill-loader.js.map +1 -1
- package/dist/skills/index.d.ts +1 -1
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +1 -2
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/skill-manager.d.ts +22 -29
- package/dist/skills/skill-manager.d.ts.map +1 -1
- package/dist/skills/skill-manager.js +63 -85
- package/dist/skills/skill-manager.js.map +1 -1
- package/dist/skills/types.d.ts +4 -16
- package/dist/skills/types.d.ts.map +1 -1
- package/dist/subagent/index.d.ts +4 -0
- package/dist/subagent/index.d.ts.map +1 -0
- package/dist/subagent/index.js +8 -0
- package/dist/subagent/index.js.map +1 -0
- package/dist/subagent/subagent-loader.d.ts +53 -0
- package/dist/subagent/subagent-loader.d.ts.map +1 -0
- package/dist/subagent/subagent-loader.js +155 -0
- package/dist/subagent/subagent-loader.js.map +1 -0
- package/dist/subagent/subagent-manager.d.ts +161 -0
- package/dist/subagent/subagent-manager.d.ts.map +1 -0
- package/dist/subagent/subagent-manager.js +468 -0
- package/dist/subagent/subagent-manager.js.map +1 -0
- package/dist/subagent/subagent-types.d.ts +77 -0
- package/dist/subagent/subagent-types.d.ts.map +1 -0
- package/dist/subagent/subagent-types.js +3 -0
- package/dist/subagent/subagent-types.js.map +1 -0
- package/dist/tools/builtin/bash.d.ts +3 -0
- package/dist/tools/builtin/bash.d.ts.map +1 -0
- package/dist/tools/builtin/bash.js +87 -0
- package/dist/tools/builtin/bash.js.map +1 -0
- package/dist/tools/builtin/edit-file.d.ts.map +1 -1
- package/dist/tools/builtin/edit-file.js +1 -0
- package/dist/tools/builtin/edit-file.js.map +1 -1
- package/dist/tools/builtin/index.d.ts +14 -0
- package/dist/tools/builtin/index.d.ts.map +1 -1
- package/dist/tools/builtin/index.js +45 -1
- package/dist/tools/builtin/index.js.map +1 -1
- package/dist/tools/builtin/list-errors.d.ts +7 -0
- package/dist/tools/builtin/list-errors.d.ts.map +1 -0
- package/dist/tools/builtin/list-errors.js +64 -0
- package/dist/tools/builtin/list-errors.js.map +1 -0
- package/dist/tools/builtin/list-subagents.d.ts +7 -0
- package/dist/tools/builtin/list-subagents.d.ts.map +1 -0
- package/dist/tools/builtin/list-subagents.js +21 -0
- package/dist/tools/builtin/list-subagents.js.map +1 -0
- package/dist/tools/builtin/recall.d.ts +11 -0
- package/dist/tools/builtin/recall.d.ts.map +1 -0
- package/dist/tools/builtin/recall.js +60 -0
- package/dist/tools/builtin/recall.js.map +1 -0
- package/dist/tools/builtin/remember.d.ts +12 -0
- package/dist/tools/builtin/remember.d.ts.map +1 -0
- package/dist/tools/builtin/remember.js +72 -0
- package/dist/tools/builtin/remember.js.map +1 -0
- package/dist/tools/builtin/skill.d.ts +14 -0
- package/dist/tools/builtin/skill.d.ts.map +1 -0
- package/dist/tools/builtin/skill.js +71 -0
- package/dist/tools/builtin/skill.js.map +1 -0
- package/dist/tools/builtin/spawn-subagent.d.ts +7 -0
- package/dist/tools/builtin/spawn-subagent.d.ts.map +1 -0
- package/dist/tools/builtin/spawn-subagent.js +43 -0
- package/dist/tools/builtin/spawn-subagent.js.map +1 -0
- package/dist/tools/builtin/web-fetch.d.ts +3 -0
- package/dist/tools/builtin/web-fetch.d.ts.map +1 -0
- package/dist/tools/builtin/web-fetch.js +101 -0
- package/dist/tools/builtin/web-fetch.js.map +1 -0
- package/dist/tools/builtin/write-file.d.ts.map +1 -1
- package/dist/tools/builtin/write-file.js +1 -0
- package/dist/tools/builtin/write-file.js.map +1 -1
- package/dist/tools/circuit-breaker.d.ts +19 -10
- package/dist/tools/circuit-breaker.d.ts.map +1 -1
- package/dist/tools/circuit-breaker.js +22 -11
- package/dist/tools/circuit-breaker.js.map +1 -1
- package/dist/tools/error-tracker.d.ts +28 -44
- package/dist/tools/error-tracker.d.ts.map +1 -1
- package/dist/tools/error-tracker.js +39 -156
- package/dist/tools/error-tracker.js.map +1 -1
- package/dist/tools/tool-filter.d.ts +70 -0
- package/dist/tools/tool-filter.d.ts.map +1 -0
- package/dist/tools/tool-filter.js +92 -0
- package/dist/tools/tool-filter.js.map +1 -0
- package/dist/tools/tool-output-truncator.d.ts +36 -0
- package/dist/tools/tool-output-truncator.d.ts.map +1 -0
- package/dist/tools/tool-output-truncator.js +117 -0
- package/dist/tools/tool-output-truncator.js.map +1 -0
- package/dist/tools/tool-registry.d.ts +25 -9
- package/dist/tools/tool-registry.d.ts.map +1 -1
- package/dist/tools/tool-registry.js +77 -28
- package/dist/tools/tool-registry.js.map +1 -1
- package/dist/tools/tool-validator.d.ts +13 -0
- package/dist/tools/tool-validator.d.ts.map +1 -0
- package/dist/tools/tool-validator.js +116 -0
- package/dist/tools/tool-validator.js.map +1 -0
- package/dist/tools/types.d.ts +86 -3
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js +51 -2
- package/dist/tools/types.js.map +1 -1
- package/dist/trace/trace-logger.d.ts +30 -4
- package/dist/trace/trace-logger.d.ts.map +1 -1
- package/dist/trace/trace-logger.js +83 -7
- package/dist/trace/trace-logger.js.map +1 -1
- package/package.json +14 -4
- package/dist/compression/sliding-window.d.ts +0 -21
- package/dist/compression/sliding-window.d.ts.map +0 -1
- package/dist/compression/sliding-window.js +0 -44
- package/dist/compression/sliding-window.js.map +0 -1
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AnthropicProvider = void 0;
|
|
7
|
+
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
8
|
+
const interface_1 = require("./interface");
|
|
9
|
+
const types_1 = require("../messages/types");
|
|
10
|
+
const token_counter_1 = require("../utils/token-counter");
|
|
11
|
+
const retry_1 = require("./retry");
|
|
12
|
+
// ─── Anthropic-specific network error helpers ────────────────────────────────
|
|
13
|
+
/**
|
|
14
|
+
* Check whether an error is network-related and thus retryable.
|
|
15
|
+
* Anthropic-provider specific: checks `Anthropic.APIError` status codes.
|
|
16
|
+
*/
|
|
17
|
+
function isNetworkError(error) {
|
|
18
|
+
if (error instanceof Error && error.name === "LLMNetworkError")
|
|
19
|
+
return true;
|
|
20
|
+
if (error instanceof sdk_1.default.APIError) {
|
|
21
|
+
// 429 (rate-limit) and 5xx (server) are retryable
|
|
22
|
+
if (error.status === 429)
|
|
23
|
+
return true;
|
|
24
|
+
if (error.status !== undefined && error.status >= 500 && error.status < 600)
|
|
25
|
+
return true;
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
if (error instanceof Error) {
|
|
29
|
+
const msg = error.message.toLowerCase();
|
|
30
|
+
return (msg.includes("timeout") ||
|
|
31
|
+
msg.includes("econnrefused") ||
|
|
32
|
+
msg.includes("econnreset") ||
|
|
33
|
+
msg.includes("econnaborted") ||
|
|
34
|
+
msg.includes("enotfound") ||
|
|
35
|
+
msg.includes("fetch failed") ||
|
|
36
|
+
msg.includes("network") ||
|
|
37
|
+
msg.includes("socket hang up"));
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Map a raw error to its NetworkErrorCause category.
|
|
43
|
+
* Anthropic-provider specific: checks `Anthropic.APIError` status codes.
|
|
44
|
+
*/
|
|
45
|
+
function classifyError(error) {
|
|
46
|
+
if (error instanceof sdk_1.default.APIError) {
|
|
47
|
+
if (error.status === 429)
|
|
48
|
+
return "rate_limit";
|
|
49
|
+
if (error.status !== undefined && error.status >= 500)
|
|
50
|
+
return "server_error";
|
|
51
|
+
}
|
|
52
|
+
if (error instanceof Error) {
|
|
53
|
+
const msg = error.message.toLowerCase();
|
|
54
|
+
if (msg.includes("abort"))
|
|
55
|
+
return "aborted";
|
|
56
|
+
if (msg.includes("timeout"))
|
|
57
|
+
return "timeout";
|
|
58
|
+
if (msg.includes("econnrefused"))
|
|
59
|
+
return "connection_refused";
|
|
60
|
+
if (msg.includes("econnreset"))
|
|
61
|
+
return "connection_reset";
|
|
62
|
+
if (msg.includes("enotfound") || msg.includes("dns"))
|
|
63
|
+
return "dns_error";
|
|
64
|
+
}
|
|
65
|
+
return "unknown_network";
|
|
66
|
+
}
|
|
67
|
+
// ─── AnthropicConfig ─────────────────────────────────────────────────────────
|
|
68
|
+
/**
|
|
69
|
+
* Maximum output tokens for Anthropic models.
|
|
70
|
+
* Claude 4.x models support up to 16384. Default is 8192 to balance
|
|
71
|
+
* output capacity with token cost.
|
|
72
|
+
*/
|
|
73
|
+
const DEFAULT_MAX_TOKENS = 8192;
|
|
74
|
+
/** Retry callbacks shared by all AnthropicProvider instances. */
|
|
75
|
+
const anthropicRetryCallbacks = {
|
|
76
|
+
isRetryable: isNetworkError,
|
|
77
|
+
classifyError,
|
|
78
|
+
};
|
|
79
|
+
// ─── AnthropicProvider ───────────────────────────────────────────────────────
|
|
80
|
+
/**
|
|
81
|
+
* Anthropic implementation of the LLMProvider interface.
|
|
82
|
+
* Uses the official `@anthropic-ai/sdk` npm package.
|
|
83
|
+
*
|
|
84
|
+
* Features:
|
|
85
|
+
* - Tool/function calling support
|
|
86
|
+
* - Network error retry with exponential backoff (chat only)
|
|
87
|
+
* - Configurable timeout
|
|
88
|
+
* - Token counting via tiktoken (with model-aware encoding, falls back for Claude models)
|
|
89
|
+
*
|
|
90
|
+
* Message format conversion:
|
|
91
|
+
* The internal `MessageData[]` format (OpenAI-compatible) is converted to
|
|
92
|
+
* Anthropic's native format transparently:
|
|
93
|
+
* - System messages are extracted and passed as the top-level `system` parameter.
|
|
94
|
+
* - Tool messages (role "tool") become user messages with `tool_result` content blocks.
|
|
95
|
+
* - Assistant messages with tool_calls become content-block arrays with `tool_use` blocks.
|
|
96
|
+
*/
|
|
97
|
+
class AnthropicProvider {
|
|
98
|
+
model;
|
|
99
|
+
client;
|
|
100
|
+
temperature;
|
|
101
|
+
maxTokens;
|
|
102
|
+
retryConfig;
|
|
103
|
+
timeout;
|
|
104
|
+
cacheSystemPrompt;
|
|
105
|
+
constructor(config) {
|
|
106
|
+
this.client = new sdk_1.default({
|
|
107
|
+
apiKey: config.apiKey,
|
|
108
|
+
baseURL: config.baseURL,
|
|
109
|
+
timeout: config.timeout,
|
|
110
|
+
maxRetries: 0, // We handle retries ourselves via withRetry
|
|
111
|
+
});
|
|
112
|
+
if (!config.model) {
|
|
113
|
+
throw new Error("AnthropicProvider: `model` is required. " +
|
|
114
|
+
"Provide a model name (e.g. \"claude-sonnet-4-6\", \"claude-opus-4-8\") " +
|
|
115
|
+
"when constructing the provider.");
|
|
116
|
+
}
|
|
117
|
+
this.model = config.model;
|
|
118
|
+
this.temperature = config.temperature ?? 0.7;
|
|
119
|
+
this.maxTokens = config.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
120
|
+
this.timeout = config.timeout;
|
|
121
|
+
this.cacheSystemPrompt = config.cacheSystemPrompt ?? false;
|
|
122
|
+
this.retryConfig = {
|
|
123
|
+
maxRetries: config.retry?.maxRetries ?? 3,
|
|
124
|
+
baseDelayMs: config.retry?.baseDelayMs ?? 1000,
|
|
125
|
+
maxDelayMs: config.retry?.maxDelayMs ?? 30000,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
// ─── LLMProvider Implementation ─────────────────────────────────────────
|
|
129
|
+
/**
|
|
130
|
+
* Build the `system` parameter for the Anthropic API.
|
|
131
|
+
* When `cacheSystemPrompt` is enabled and the system prompt is non-empty,
|
|
132
|
+
* wraps it in a content block with `cache_control` so Anthropic caches it.
|
|
133
|
+
*/
|
|
134
|
+
buildSystemParam(systemPrompt) {
|
|
135
|
+
if (!systemPrompt)
|
|
136
|
+
return undefined;
|
|
137
|
+
if (!this.cacheSystemPrompt)
|
|
138
|
+
return systemPrompt;
|
|
139
|
+
return [
|
|
140
|
+
{
|
|
141
|
+
type: "text",
|
|
142
|
+
text: systemPrompt,
|
|
143
|
+
cache_control: { type: "ephemeral" },
|
|
144
|
+
},
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
async chat(messages, tools, signal) {
|
|
148
|
+
const { systemPrompt, formattedMessages } = AnthropicProvider.convertMessages(messages);
|
|
149
|
+
const anthropicTools = tools?.length ? AnthropicProvider.convertTools(tools) : undefined;
|
|
150
|
+
const response = await (0, retry_1.withRetry)(() => this.client.messages.create({
|
|
151
|
+
model: this.model,
|
|
152
|
+
system: this.buildSystemParam(systemPrompt),
|
|
153
|
+
messages: formattedMessages,
|
|
154
|
+
tools: anthropicTools,
|
|
155
|
+
max_tokens: this.maxTokens,
|
|
156
|
+
temperature: this.temperature,
|
|
157
|
+
}, { signal }), this.retryConfig, anthropicRetryCallbacks);
|
|
158
|
+
return AnthropicProvider.convertResponse(response);
|
|
159
|
+
}
|
|
160
|
+
async *chatStream(messages, tools, signal) {
|
|
161
|
+
const { systemPrompt, formattedMessages } = AnthropicProvider.convertMessages(messages);
|
|
162
|
+
const anthropicTools = tools?.length ? AnthropicProvider.convertTools(tools) : undefined;
|
|
163
|
+
// The Anthropic SDK's stream() is synchronous — it returns a MessageStream
|
|
164
|
+
// without initiating a network request. The actual connection happens on
|
|
165
|
+
// first iteration. We retry the initial stream setup only (which may fail
|
|
166
|
+
// for auth/config errors), but NOT mid-stream drops — those are handled
|
|
167
|
+
// by the agent's outer loop, same as the OpenAI provider.
|
|
168
|
+
const stream = await (0, retry_1.withRetry)(async () => this.client.messages.stream({
|
|
169
|
+
model: this.model,
|
|
170
|
+
system: this.buildSystemParam(systemPrompt),
|
|
171
|
+
messages: formattedMessages,
|
|
172
|
+
tools: anthropicTools,
|
|
173
|
+
max_tokens: this.maxTokens,
|
|
174
|
+
temperature: this.temperature,
|
|
175
|
+
}, { signal }), this.retryConfig, anthropicRetryCallbacks);
|
|
176
|
+
let emittedDone = false;
|
|
177
|
+
for await (const event of stream) {
|
|
178
|
+
switch (event.type) {
|
|
179
|
+
case "content_block_start":
|
|
180
|
+
if (event.content_block.type === "tool_use") {
|
|
181
|
+
yield {
|
|
182
|
+
type: "chunk",
|
|
183
|
+
tool_calls: [
|
|
184
|
+
{
|
|
185
|
+
index: event.index,
|
|
186
|
+
id: event.content_block.id,
|
|
187
|
+
function: { name: event.content_block.name },
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
case "content_block_delta":
|
|
194
|
+
if (event.delta.type === "text_delta") {
|
|
195
|
+
yield { type: "chunk", content: event.delta.text };
|
|
196
|
+
}
|
|
197
|
+
else if (event.delta.type === "input_json_delta") {
|
|
198
|
+
yield {
|
|
199
|
+
type: "chunk",
|
|
200
|
+
tool_calls: [
|
|
201
|
+
{
|
|
202
|
+
index: event.index,
|
|
203
|
+
function: { arguments: event.delta.partial_json },
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Retrieve usage from the final message. If the stream was aborted or
|
|
212
|
+
// the network dropped, finalMessage() throws — we catch and still emit
|
|
213
|
+
// a terminal "done" event so consumers don't hang.
|
|
214
|
+
try {
|
|
215
|
+
const finalMessage = await stream.finalMessage();
|
|
216
|
+
if (finalMessage.usage) {
|
|
217
|
+
emittedDone = true;
|
|
218
|
+
yield {
|
|
219
|
+
type: "done",
|
|
220
|
+
usage: {
|
|
221
|
+
prompt_tokens: finalMessage.usage.input_tokens,
|
|
222
|
+
completion_tokens: finalMessage.usage.output_tokens,
|
|
223
|
+
total_tokens: finalMessage.usage.input_tokens + finalMessage.usage.output_tokens,
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
// Stream terminated abnormally — usage stats unavailable.
|
|
230
|
+
}
|
|
231
|
+
if (!emittedDone) {
|
|
232
|
+
yield { type: "done" };
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Count tokens using tiktoken (with model-aware encoding) when available.
|
|
237
|
+
* Falls back to character-based estimation if tiktoken is not installed.
|
|
238
|
+
*
|
|
239
|
+
* Note: Claude models are not recognized by tiktoken's `encoding_for_model()`,
|
|
240
|
+
* so it falls through to the generic `o200k_base` encoding, which is a
|
|
241
|
+
* reasonable approximation for Claude's tokenizer.
|
|
242
|
+
*
|
|
243
|
+
* @param text The text to tokenize.
|
|
244
|
+
* @param model Optional model override. Defaults to this provider's model.
|
|
245
|
+
*/
|
|
246
|
+
getTokenCount(text, model) {
|
|
247
|
+
return (0, token_counter_1.countTokens)(text, model ?? this.model);
|
|
248
|
+
}
|
|
249
|
+
// ─── Private Helpers ────────────────────────────────────────────────────
|
|
250
|
+
// ─── Static Converters ──────────────────────────────────────────────────
|
|
251
|
+
/**
|
|
252
|
+
* Validate and convert internal Tool definitions to Anthropic tool format.
|
|
253
|
+
*
|
|
254
|
+
* Internal format: `{ name, description, parameters }` (JSON Schema)
|
|
255
|
+
* Anthropic format: `{ name, description, input_schema }`
|
|
256
|
+
*
|
|
257
|
+
* If `parameters` is missing the required `type` field, we wrap it in
|
|
258
|
+
* an object schema as a best-effort fallback.
|
|
259
|
+
*/
|
|
260
|
+
/**
|
|
261
|
+
* Build a valid Anthropic `input_schema` from a tool's raw parameters.
|
|
262
|
+
*
|
|
263
|
+
* Anthropic requires `{type: "object", properties: {...}}` at the top
|
|
264
|
+
* level. If the tool's parameters already provide this shape (i.e. it
|
|
265
|
+
* has `type: "object"`), we use `satisfies` to verify compatibility at
|
|
266
|
+
* compile time without runtime casting. Otherwise we wrap the params in
|
|
267
|
+
* an object schema.
|
|
268
|
+
*/
|
|
269
|
+
static buildInputSchema(params) {
|
|
270
|
+
if (params &&
|
|
271
|
+
params.type === "object" &&
|
|
272
|
+
params.properties &&
|
|
273
|
+
typeof params.properties === "object") {
|
|
274
|
+
return {
|
|
275
|
+
type: "object",
|
|
276
|
+
properties: params.properties,
|
|
277
|
+
...(params.required
|
|
278
|
+
? { required: params.required }
|
|
279
|
+
: {}),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
// Wrap in a minimal object schema.
|
|
283
|
+
return {
|
|
284
|
+
type: "object",
|
|
285
|
+
properties: params && Object.keys(params).length > 0 ? params : {},
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
static convertTools(tools) {
|
|
289
|
+
return tools.map((t) => ({
|
|
290
|
+
name: t.name,
|
|
291
|
+
description: t.description,
|
|
292
|
+
input_schema: AnthropicProvider.buildInputSchema(t.parameters),
|
|
293
|
+
}));
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Convert an Anthropic API response to the internal `LLMResponse` format.
|
|
297
|
+
*
|
|
298
|
+
* - Text blocks → `content`
|
|
299
|
+
* - Tool use blocks → `tool_calls` with `JSON.stringify(input)`
|
|
300
|
+
* - Thinking blocks → merged into `content` (Claude extended thinking)
|
|
301
|
+
* - Usage → mapped from Anthropic's input_tokens/output_tokens
|
|
302
|
+
* - Stop reason → preserved for agents to detect truncation / tool-use
|
|
303
|
+
*/
|
|
304
|
+
static convertResponse(response) {
|
|
305
|
+
const textBlocks = response.content.filter((b) => b.type === "text");
|
|
306
|
+
const toolUseBlocks = response.content.filter((b) => b.type === "tool_use");
|
|
307
|
+
// Claude extended thinking returns `type: "thinking"` blocks. These
|
|
308
|
+
// contain the model's internal reasoning and should be included in the
|
|
309
|
+
// content so the agent has full context.
|
|
310
|
+
const thinkingBlocks = response.content.filter((b) => b.type === "thinking");
|
|
311
|
+
// Build content from text + thinking blocks.
|
|
312
|
+
const parts = [];
|
|
313
|
+
parts.push(textBlocks.map((b) => b.text).join(""));
|
|
314
|
+
if (thinkingBlocks.length > 0) {
|
|
315
|
+
parts.push(thinkingBlocks.map((b) => b.thinking).join(""));
|
|
316
|
+
}
|
|
317
|
+
const content = parts.filter((p) => p.length > 0).join("");
|
|
318
|
+
const result = {
|
|
319
|
+
content,
|
|
320
|
+
tool_calls: toolUseBlocks.length > 0
|
|
321
|
+
? toolUseBlocks.map((b) => ({
|
|
322
|
+
id: b.id,
|
|
323
|
+
type: "function",
|
|
324
|
+
function: {
|
|
325
|
+
name: b.name,
|
|
326
|
+
arguments: JSON.stringify(b.input),
|
|
327
|
+
},
|
|
328
|
+
}))
|
|
329
|
+
: undefined,
|
|
330
|
+
usage: response.usage
|
|
331
|
+
? {
|
|
332
|
+
prompt_tokens: response.usage.input_tokens,
|
|
333
|
+
completion_tokens: response.usage.output_tokens,
|
|
334
|
+
total_tokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
335
|
+
}
|
|
336
|
+
: undefined,
|
|
337
|
+
stop_reason: response.stop_reason ?? undefined,
|
|
338
|
+
};
|
|
339
|
+
// Flag response-level quality issues
|
|
340
|
+
if (response.stop_reason === "max_tokens") {
|
|
341
|
+
result.responseError = {
|
|
342
|
+
code: interface_1.LLMResponseErrorCode.MAX_TOKENS,
|
|
343
|
+
message: "Response truncated: max_tokens reached. " +
|
|
344
|
+
"Content or tool call arguments may be incomplete.",
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Convert the internal `MessageData[]` format (OpenAI-compatible) to
|
|
351
|
+
* Anthropic's native message format.
|
|
352
|
+
*
|
|
353
|
+
* Conversion rules:
|
|
354
|
+
* 1. `role: "system"` messages are extracted, concatenated, and returned as
|
|
355
|
+
* the top-level `systemPrompt`.
|
|
356
|
+
* 2. `role: "user"` → `{ role: "user", content: string }`
|
|
357
|
+
* 3. `role: "assistant"` without tool_calls → `{ role: "assistant", content: string }`
|
|
358
|
+
* 4. `role: "assistant"` with tool_calls → content-block array with text + tool_use blocks
|
|
359
|
+
* 5. `role: "tool"` → `{ role: "user", content: [{ type: "tool_result", ... }] }`
|
|
360
|
+
* 6. Consecutive same-role messages are merged with synthetic separators
|
|
361
|
+
* to satisfy Anthropic's user/assistant alternation requirement.
|
|
362
|
+
* 7. If no non-system messages remain, a placeholder user message is inserted
|
|
363
|
+
* to satisfy Anthropic's requirement of at least one user/assistant message.
|
|
364
|
+
*/
|
|
365
|
+
static convertMessages(messages) {
|
|
366
|
+
// Extract system messages
|
|
367
|
+
const systemMessages = messages.filter((m) => m.role === types_1.Role.System);
|
|
368
|
+
const systemPrompt = systemMessages.length > 0
|
|
369
|
+
? systemMessages.map((m) => m.content).join("\n")
|
|
370
|
+
: undefined;
|
|
371
|
+
// Convert non-system messages
|
|
372
|
+
const nonSystem = messages.filter((m) => m.role !== types_1.Role.System);
|
|
373
|
+
const formattedMessages = [];
|
|
374
|
+
for (const msg of nonSystem) {
|
|
375
|
+
const converted = AnthropicProvider.convertSingleMessage(msg);
|
|
376
|
+
// An empty result means the message was skipped (e.g. empty content).
|
|
377
|
+
if (!converted)
|
|
378
|
+
continue;
|
|
379
|
+
// Ensure user/assistant alternation.
|
|
380
|
+
// If the converted message has the same role as the last one in the array,
|
|
381
|
+
// insert a synthetic message to break the consecutive sequence.
|
|
382
|
+
if (formattedMessages.length > 0) {
|
|
383
|
+
const lastRole = formattedMessages[formattedMessages.length - 1].role;
|
|
384
|
+
if (lastRole === converted.role) {
|
|
385
|
+
formattedMessages.push({
|
|
386
|
+
role: lastRole === "user" ? "assistant" : "user",
|
|
387
|
+
content: "(continued)",
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
formattedMessages.push(converted);
|
|
392
|
+
}
|
|
393
|
+
// Anthropic requires at least one user or assistant message.
|
|
394
|
+
// If all messages were system-level, insert a placeholder.
|
|
395
|
+
if (formattedMessages.length === 0) {
|
|
396
|
+
formattedMessages.push({
|
|
397
|
+
role: "user",
|
|
398
|
+
content: "(start)",
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
return { systemPrompt, formattedMessages };
|
|
402
|
+
}
|
|
403
|
+
/** Counter for generating unique synthetic tool_use_ids. */
|
|
404
|
+
static toolUseIdCounter = 0;
|
|
405
|
+
/**
|
|
406
|
+
* Convert a single internal `MessageData` to an Anthropic `MessageParam`.
|
|
407
|
+
* Returns `null` if the message should be skipped.
|
|
408
|
+
*/
|
|
409
|
+
static convertSingleMessage(msg) {
|
|
410
|
+
switch (msg.role) {
|
|
411
|
+
case types_1.Role.User:
|
|
412
|
+
return {
|
|
413
|
+
role: "user",
|
|
414
|
+
content: msg.content || "(empty)",
|
|
415
|
+
};
|
|
416
|
+
case types_1.Role.Assistant: {
|
|
417
|
+
const hasToolCalls = msg.tool_calls && msg.tool_calls.length > 0;
|
|
418
|
+
if (!hasToolCalls) {
|
|
419
|
+
return {
|
|
420
|
+
role: "assistant",
|
|
421
|
+
content: msg.content || "(empty)",
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
// Assistant message with tool calls → content-block array.
|
|
425
|
+
const contentBlocks = [];
|
|
426
|
+
// Add text block if there's non-empty content.
|
|
427
|
+
if (msg.content) {
|
|
428
|
+
contentBlocks.push({ type: "text", text: msg.content });
|
|
429
|
+
}
|
|
430
|
+
// Add tool_use blocks for each tool call.
|
|
431
|
+
for (const tc of msg.tool_calls) {
|
|
432
|
+
let input = {};
|
|
433
|
+
if (tc.function.arguments) {
|
|
434
|
+
try {
|
|
435
|
+
input = JSON.parse(tc.function.arguments);
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
// Unparseable arguments — use empty object as fallback.
|
|
439
|
+
input = {};
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
contentBlocks.push({
|
|
443
|
+
type: "tool_use",
|
|
444
|
+
id: tc.id,
|
|
445
|
+
name: tc.function.name,
|
|
446
|
+
input,
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
return {
|
|
450
|
+
role: "assistant",
|
|
451
|
+
content: contentBlocks,
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
case types_1.Role.Tool: {
|
|
455
|
+
// Tool messages become user messages with tool_result content blocks.
|
|
456
|
+
// Generate a unique fallback ID when tool_call_id is missing to avoid
|
|
457
|
+
// collisions (Anthropic requires unique tool_use_ids across the conversation).
|
|
458
|
+
let toolUseId = msg.tool_call_id;
|
|
459
|
+
if (!toolUseId) {
|
|
460
|
+
AnthropicProvider.toolUseIdCounter++;
|
|
461
|
+
toolUseId = msg.name
|
|
462
|
+
? `${msg.name}_${AnthropicProvider.toolUseIdCounter}`
|
|
463
|
+
: `tool_${AnthropicProvider.toolUseIdCounter}`;
|
|
464
|
+
}
|
|
465
|
+
return {
|
|
466
|
+
role: "user",
|
|
467
|
+
content: [
|
|
468
|
+
{
|
|
469
|
+
type: "tool_result",
|
|
470
|
+
tool_use_id: toolUseId,
|
|
471
|
+
content: msg.content || "",
|
|
472
|
+
},
|
|
473
|
+
],
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
default:
|
|
477
|
+
// Unknown roles are treated as user messages.
|
|
478
|
+
return {
|
|
479
|
+
role: "user",
|
|
480
|
+
content: msg.content || "(empty)",
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
exports.AnthropicProvider = AnthropicProvider;
|
|
486
|
+
//# sourceMappingURL=anthropic-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-provider.js","sourceRoot":"","sources":["../../src/llm/anthropic-provider.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA0C;AAE1C,2CAA6F;AAC7F,6CAAsD;AAEtD,0DAAqD;AAErD,mCAAoD;AAEpD,gFAAgF;AAEhF;;;GAGG;AACH,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB;QAAE,OAAO,IAAI,CAAC;IAE5E,IAAI,KAAK,YAAY,aAAS,CAAC,QAAQ,EAAE,CAAC;QACxC,kDAAkD;QAClD,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;QACtC,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG;YAAE,OAAO,IAAI,CAAC;QACzF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QACxC,OAAO,CACL,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC;YACvB,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC;YAC5B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,sEAAsE;gBACtE,+EAA+E;gBAC/E,IAAI,SAAS,GAAG,GAAG,CAAC,YAAY,CAAC;gBACjC,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,iBAAiB,CAAC,gBAAgB,EAAE,CAAC;oBACrC,SAAS,GAAG,GAAG,CAAC,IAAI;wBAClB,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,IAAI,iBAAiB,CAAC,gBAAgB,EAAE;wBACrD,CAAC,CAAC,QAAQ,iBAAiB,CAAC,gBAAgB,EAAE,CAAC;gBACnD,CAAC;gBAED,OAAO;oBACL,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,aAAa;4BACnB,WAAW,EAAE,SAAS;4BACtB,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE;yBACO;qBACY;iBAClD,CAAC;YACJ,CAAC;YAED;gBACE,8CAA8C;gBAC9C,OAAO;oBACL,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,SAAS;iBAClC,CAAC;QACN,CAAC;IACH,CAAC;;AAvdH,8CAwdC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Categories of network-related LLM failures.
|
|
3
|
+
* Used by both OpenAI and Anthropic providers.
|
|
4
|
+
*/
|
|
5
|
+
export type NetworkErrorCause = "timeout" | "connection_refused" | "connection_reset" | "dns_error" | "rate_limit" | "server_error" | "aborted" | "unknown_network";
|
|
6
|
+
/**
|
|
7
|
+
* Thrown by an LLM provider when all retry attempts for a network-related
|
|
8
|
+
* failure have been exhausted. The agent catches this to save a checkpoint
|
|
9
|
+
* and guide the user to resume their session.
|
|
10
|
+
*/
|
|
11
|
+
export declare class LLMNetworkError extends Error {
|
|
12
|
+
readonly cause: NetworkErrorCause;
|
|
13
|
+
constructor(message: string, cause: NetworkErrorCause);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Retry configuration shared by all LLM providers.
|
|
17
|
+
*/
|
|
18
|
+
export interface RetryConfig {
|
|
19
|
+
/** Max retry attempts for network errors (default: 3). */
|
|
20
|
+
maxRetries?: number;
|
|
21
|
+
/** Initial backoff delay in ms (default: 1000). */
|
|
22
|
+
baseDelayMs?: number;
|
|
23
|
+
/** Maximum backoff delay in ms (default: 30000). */
|
|
24
|
+
maxDelayMs?: number;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/llm/errors.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,oBAAoB,GACpB,kBAAkB,GAClB,WAAW,GACX,YAAY,GACZ,cAAc,GACd,SAAS,GACT,iBAAiB,CAAC;AAEtB;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,SAAgB,KAAK,EAAE,iBAAiB,CAAC;gBAE7B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB;CAKtD;AAID;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ─── Shared LLM Error Types ─────────────────────────────────────────────────
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.LLMNetworkError = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Thrown by an LLM provider when all retry attempts for a network-related
|
|
7
|
+
* failure have been exhausted. The agent catches this to save a checkpoint
|
|
8
|
+
* and guide the user to resume their session.
|
|
9
|
+
*/
|
|
10
|
+
class LLMNetworkError extends Error {
|
|
11
|
+
cause;
|
|
12
|
+
constructor(message, cause) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "LLMNetworkError";
|
|
15
|
+
this.cause = cause;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.LLMNetworkError = LLMNetworkError;
|
|
19
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/llm/errors.ts"],"names":[],"mappings":";AAAA,+EAA+E;;;AAgB/E;;;;GAIG;AACH,MAAa,eAAgB,SAAQ,KAAK;IACxB,KAAK,CAAoB;IAEzC,YAAY,OAAe,EAAE,KAAwB;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AARD,0CAQC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { LLMProvider } from "./interface";
|
|
2
|
+
import { RetryConfig } from "./errors";
|
|
3
|
+
/**
|
|
4
|
+
* Explicit provider selection for the factory.
|
|
5
|
+
* - `"openai"`: Always use OpenAI.
|
|
6
|
+
* - `"anthropic"`: Always use Anthropic.
|
|
7
|
+
* - `"auto"`: Detect from `baseURL` (default).
|
|
8
|
+
*/
|
|
9
|
+
export type ProviderType = "openai" | "anthropic" | "auto";
|
|
10
|
+
/**
|
|
11
|
+
* Unified configuration accepted by `createLLMProvider`.
|
|
12
|
+
* Pass this instead of provider-specific configs (`OpenAIConfig`, `AnthropicConfig`)
|
|
13
|
+
* to enable automatic provider detection.
|
|
14
|
+
*/
|
|
15
|
+
export interface LLMProviderConfig {
|
|
16
|
+
/** API key for the LLM service. */
|
|
17
|
+
apiKey: string;
|
|
18
|
+
/** Model identifier (e.g. "gpt-4o", "claude-sonnet-4-6"). */
|
|
19
|
+
model: string;
|
|
20
|
+
/** Sampling temperature (default: 0.7). */
|
|
21
|
+
temperature?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Maximum output tokens.
|
|
24
|
+
* Per-provider defaults: OpenAI 4096, Anthropic 8192.
|
|
25
|
+
*/
|
|
26
|
+
maxTokens?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Base URL for the LLM API endpoint.
|
|
29
|
+
* Used to auto-detect the provider when `provider` is `"auto"`.
|
|
30
|
+
* Examples:
|
|
31
|
+
* - `"https://api.openai.com/v1"` → OpenAI
|
|
32
|
+
* - `"https://api.anthropic.com"` → Anthropic
|
|
33
|
+
* - `undefined` → defaults to OpenAI (backward compatible)
|
|
34
|
+
*/
|
|
35
|
+
baseURL?: string;
|
|
36
|
+
/** Retry configuration for network resilience. */
|
|
37
|
+
retry?: RetryConfig;
|
|
38
|
+
/** Request timeout in ms. */
|
|
39
|
+
timeout?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Explicitly choose the provider. When `"auto"` or omitted,
|
|
42
|
+
* the factory detects the provider from `baseURL`.
|
|
43
|
+
*/
|
|
44
|
+
provider?: ProviderType;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create an LLM provider instance, auto-detecting the backend from `baseURL`.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* // Auto-detect: baseURL contains "anthropic" → AnthropicProvider
|
|
52
|
+
* const llm = createLLMProvider({
|
|
53
|
+
* apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
54
|
+
* model: "claude-sonnet-4-6",
|
|
55
|
+
* baseURL: "https://api.anthropic.com",
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* // Explicit provider selection
|
|
59
|
+
* const llm = createLLMProvider({
|
|
60
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
61
|
+
* model: "gpt-4o",
|
|
62
|
+
* provider: "openai",
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Backward-compatible: no baseURL → OpenAI
|
|
66
|
+
* const llm = createLLMProvider({
|
|
67
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
68
|
+
* model: "gpt-4o",
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function createLLMProvider(config: LLMProviderConfig): LLMProvider;
|
|
73
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/llm/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAIvC;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;AAI3D;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AA8BD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW,CAwBxE"}
|