@bernierllc/ai-provider-anthropic 1.2.5 → 1.4.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/dist/AnthropicProvider.js +1 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -1
- package/dist/models/model-registry.d.ts +0 -9
- package/dist/models/model-registry.js +4 -19
- package/dist/utils/error-handling.js +7 -11
- package/package.json +6 -1
- package/.eslintrc.js +0 -34
- package/CHANGELOG.md +0 -103
- package/__tests__/AnthropicProvider.test.ts +0 -655
- package/__tests__/error-handling.test.ts +0 -208
- package/__tests__/message-conversion.test.ts +0 -161
- package/__tests__/model-registry.test.ts +0 -150
- package/jest.config.js +0 -30
- package/src/AnthropicProvider.ts +0 -392
- package/src/index.ts +0 -19
- package/src/models/model-registry.ts +0 -120
- package/src/types/anthropic-types.ts +0 -60
- package/src/types/index.ts +0 -9
- package/src/utils/error-handling.ts +0 -71
- package/src/utils/index.ts +0 -10
- package/src/utils/message-conversion.ts +0 -78
- package/tsconfig.json +0 -29
|
@@ -21,6 +21,7 @@ const error_handling_1 = require("./utils/error-handling");
|
|
|
21
21
|
* Concrete implementation of the AI provider interface for Anthropic's Claude API
|
|
22
22
|
*/
|
|
23
23
|
class AnthropicProvider extends ai_provider_core_1.AIProvider {
|
|
24
|
+
client;
|
|
24
25
|
constructor(config) {
|
|
25
26
|
super(config);
|
|
26
27
|
this.client = new sdk_1.default({
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type AIProviderAnthropicErrorCode = 'AI_PROVIDER_ANTHROPIC_ERROR' | 'AI_PROVIDER_ANTHROPIC_AUTH_ERROR' | 'AI_PROVIDER_ANTHROPIC_RATE_LIMIT' | 'AI_PROVIDER_ANTHROPIC_INVALID_REQUEST' | 'AI_PROVIDER_ANTHROPIC_API_ERROR';
|
|
2
|
+
export interface AIProviderAnthropicErrorOptions {
|
|
3
|
+
cause?: Error;
|
|
4
|
+
code?: AIProviderAnthropicErrorCode;
|
|
5
|
+
context?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export declare class AIProviderAnthropicError extends Error {
|
|
8
|
+
readonly code: AIProviderAnthropicErrorCode;
|
|
9
|
+
readonly context?: Record<string, unknown>;
|
|
10
|
+
constructor(message: string, options?: AIProviderAnthropicErrorOptions);
|
|
11
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (c) 2025 Bernier LLC
|
|
4
|
+
|
|
5
|
+
This file is licensed to the client under a limited-use license.
|
|
6
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
7
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.AIProviderAnthropicError = void 0;
|
|
11
|
+
class AIProviderAnthropicError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
context;
|
|
14
|
+
constructor(message, options) {
|
|
15
|
+
super(message, options?.cause ? { cause: options.cause } : undefined);
|
|
16
|
+
this.name = 'AIProviderAnthropicError';
|
|
17
|
+
this.code = options?.code ?? 'AI_PROVIDER_ANTHROPIC_ERROR';
|
|
18
|
+
if (options?.context !== undefined) {
|
|
19
|
+
this.context = options.context;
|
|
20
|
+
}
|
|
21
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.AIProviderAnthropicError = AIProviderAnthropicError;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ export { AnthropicProvider } from './AnthropicProvider';
|
|
|
2
2
|
export * from './types';
|
|
3
3
|
export { ClaudeModelRegistry } from './models/model-registry';
|
|
4
4
|
export * from './utils';
|
|
5
|
+
export { AIProviderAnthropicError } from './errors';
|
|
6
|
+
export type { AIProviderAnthropicErrorCode, AIProviderAnthropicErrorOptions } from './errors';
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
21
21
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
22
22
|
};
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.ClaudeModelRegistry = exports.AnthropicProvider = void 0;
|
|
24
|
+
exports.AIProviderAnthropicError = exports.ClaudeModelRegistry = exports.AnthropicProvider = void 0;
|
|
25
25
|
// Main provider class
|
|
26
26
|
var AnthropicProvider_1 = require("./AnthropicProvider");
|
|
27
27
|
Object.defineProperty(exports, "AnthropicProvider", { enumerable: true, get: function () { return AnthropicProvider_1.AnthropicProvider; } });
|
|
@@ -32,3 +32,6 @@ var model_registry_1 = require("./models/model-registry");
|
|
|
32
32
|
Object.defineProperty(exports, "ClaudeModelRegistry", { enumerable: true, get: function () { return model_registry_1.ClaudeModelRegistry; } });
|
|
33
33
|
// Utilities
|
|
34
34
|
__exportStar(require("./utils"), exports);
|
|
35
|
+
// Errors
|
|
36
|
+
var errors_1 = require("./errors");
|
|
37
|
+
Object.defineProperty(exports, "AIProviderAnthropicError", { enumerable: true, get: function () { return errors_1.AIProviderAnthropicError; } });
|
|
@@ -9,17 +9,8 @@ export declare class ClaudeModelRegistry {
|
|
|
9
9
|
* Initialize the model registry with Claude 3 models
|
|
10
10
|
*/
|
|
11
11
|
static initialize(): void;
|
|
12
|
-
/**
|
|
13
|
-
* Get a specific model by ID
|
|
14
|
-
*/
|
|
15
12
|
static getModel(modelId: string): ModelInfo | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* Get all available models
|
|
18
|
-
*/
|
|
19
13
|
static getAllModels(): ModelInfo[];
|
|
20
|
-
/**
|
|
21
|
-
* Check if a model ID is valid
|
|
22
|
-
*/
|
|
23
14
|
static isValidModel(modelId: string): boolean;
|
|
24
15
|
/**
|
|
25
16
|
* Get pricing for a specific model
|
|
@@ -13,6 +13,10 @@ exports.ClaudeModelRegistry = void 0;
|
|
|
13
13
|
* Contains information about all available Claude models
|
|
14
14
|
*/
|
|
15
15
|
class ClaudeModelRegistry {
|
|
16
|
+
static models = new Map();
|
|
17
|
+
static {
|
|
18
|
+
ClaudeModelRegistry.initialize();
|
|
19
|
+
}
|
|
16
20
|
/**
|
|
17
21
|
* Initialize the model registry with Claude 3 models
|
|
18
22
|
*/
|
|
@@ -62,31 +66,13 @@ class ClaudeModelRegistry {
|
|
|
62
66
|
this.models.set(model.id, model);
|
|
63
67
|
});
|
|
64
68
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Get a specific model by ID
|
|
67
|
-
*/
|
|
68
69
|
static getModel(modelId) {
|
|
69
|
-
if (this.models.size === 0) {
|
|
70
|
-
this.initialize();
|
|
71
|
-
}
|
|
72
70
|
return this.models.get(modelId);
|
|
73
71
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Get all available models
|
|
76
|
-
*/
|
|
77
72
|
static getAllModels() {
|
|
78
|
-
if (this.models.size === 0) {
|
|
79
|
-
this.initialize();
|
|
80
|
-
}
|
|
81
73
|
return Array.from(this.models.values());
|
|
82
74
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Check if a model ID is valid
|
|
85
|
-
*/
|
|
86
75
|
static isValidModel(modelId) {
|
|
87
|
-
if (this.models.size === 0) {
|
|
88
|
-
this.initialize();
|
|
89
|
-
}
|
|
90
76
|
return this.models.has(modelId);
|
|
91
77
|
}
|
|
92
78
|
/**
|
|
@@ -108,6 +94,5 @@ class ClaudeModelRegistry {
|
|
|
108
94
|
}
|
|
109
95
|
}
|
|
110
96
|
exports.ClaudeModelRegistry = ClaudeModelRegistry;
|
|
111
|
-
ClaudeModelRegistry.models = new Map();
|
|
112
97
|
// Initialize on module load
|
|
113
98
|
ClaudeModelRegistry.initialize();
|
|
@@ -18,13 +18,6 @@ const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
|
18
18
|
* Handle Anthropic API errors and convert to provider error format
|
|
19
19
|
*/
|
|
20
20
|
function handleAnthropicError(error) {
|
|
21
|
-
if (error instanceof sdk_1.default.APIError) {
|
|
22
|
-
const status = error.status || 'unknown';
|
|
23
|
-
const message = `Anthropic API Error (${status}): ${error.message}`;
|
|
24
|
-
const providerError = new Error(message);
|
|
25
|
-
providerError.name = 'AnthropicAPIError';
|
|
26
|
-
return providerError;
|
|
27
|
-
}
|
|
28
21
|
if (error instanceof sdk_1.default.AuthenticationError) {
|
|
29
22
|
const providerError = new Error('Anthropic authentication failed. Check your API key.');
|
|
30
23
|
providerError.name = 'AnthropicAuthError';
|
|
@@ -35,6 +28,13 @@ function handleAnthropicError(error) {
|
|
|
35
28
|
providerError.name = 'AnthropicRateLimitError';
|
|
36
29
|
return providerError;
|
|
37
30
|
}
|
|
31
|
+
if (error instanceof sdk_1.default.APIError) {
|
|
32
|
+
const status = error.status || 'unknown';
|
|
33
|
+
const message = `Anthropic API Error (${status}): ${error.message}`;
|
|
34
|
+
const providerError = new Error(message);
|
|
35
|
+
providerError.name = 'AnthropicAPIError';
|
|
36
|
+
return providerError;
|
|
37
|
+
}
|
|
38
38
|
if (error instanceof Error) {
|
|
39
39
|
return error;
|
|
40
40
|
}
|
|
@@ -45,13 +45,9 @@ function handleAnthropicError(error) {
|
|
|
45
45
|
*/
|
|
46
46
|
function isRetryableError(error) {
|
|
47
47
|
if (error instanceof sdk_1.default.APIError) {
|
|
48
|
-
// Retry on 5xx errors and rate limits
|
|
49
48
|
const status = error.status || 0;
|
|
50
49
|
return status >= 500 || status === 429;
|
|
51
50
|
}
|
|
52
|
-
if (error instanceof sdk_1.default.RateLimitError) {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
51
|
return false;
|
|
56
52
|
}
|
|
57
53
|
/**
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bernierllc/ai-provider-anthropic",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Anthropic Claude API adapter implementing the unified AI provider interface",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
7
12
|
"keywords": [
|
|
8
13
|
"ai",
|
|
9
14
|
"provider",
|
package/.eslintrc.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2025 Bernier LLC
|
|
3
|
-
|
|
4
|
-
This file is licensed to the client under a limited-use license.
|
|
5
|
-
The client may use and modify this code only within the scope of the project it was delivered for.
|
|
6
|
-
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
parser: '@typescript-eslint/parser',
|
|
11
|
-
parserOptions: {
|
|
12
|
-
ecmaVersion: 2020,
|
|
13
|
-
sourceType: 'module',
|
|
14
|
-
project: './tsconfig.json'
|
|
15
|
-
},
|
|
16
|
-
extends: [
|
|
17
|
-
'eslint:recommended',
|
|
18
|
-
'plugin:@typescript-eslint/recommended',
|
|
19
|
-
'plugin:@typescript-eslint/recommended-requiring-type-checking'
|
|
20
|
-
],
|
|
21
|
-
plugins: ['@typescript-eslint'],
|
|
22
|
-
env: {
|
|
23
|
-
node: true,
|
|
24
|
-
jest: true,
|
|
25
|
-
es6: true
|
|
26
|
-
},
|
|
27
|
-
rules: {
|
|
28
|
-
'@typescript-eslint/explicit-function-return-type': 'warn',
|
|
29
|
-
'@typescript-eslint/no-explicit-any': 'error',
|
|
30
|
-
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
31
|
-
'@typescript-eslint/no-floating-promises': 'error',
|
|
32
|
-
'no-console': 'off'
|
|
33
|
-
}
|
|
34
|
-
};
|
package/CHANGELOG.md
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
## [1.2.5](https://github.com/bernierllc/tools/compare/@bernierllc/ai-provider-anthropic@1.2.4...@bernierllc/ai-provider-anthropic@1.2.5) (2026-05-19)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @bernierllc/ai-provider-anthropic
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## [1.2.4](https://github.com/bernierllc/tools/compare/@bernierllc/ai-provider-anthropic@1.2.3...@bernierllc/ai-provider-anthropic@1.2.4) (2026-05-19)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @bernierllc/ai-provider-anthropic
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## [1.2.3](https://github.com/bernierllc/tools/compare/@bernierllc/ai-provider-anthropic@1.2.2...@bernierllc/ai-provider-anthropic@1.2.3) (2026-03-30)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @bernierllc/ai-provider-anthropic
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## [1.2.2](https://github.com/bernierllc/tools/compare/@bernierllc/ai-provider-anthropic@1.2.1...@bernierllc/ai-provider-anthropic@1.2.2) (2026-03-09)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @bernierllc/ai-provider-anthropic
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
## [1.2.1](https://github.com/bernierllc/tools/compare/@bernierllc/ai-provider-anthropic@1.2.0...@bernierllc/ai-provider-anthropic@1.2.1) (2026-03-03)
|
|
39
|
-
|
|
40
|
-
**Note:** Version bump only for package @bernierllc/ai-provider-anthropic
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
# 1.2.0 (2025-12-25)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
### Bug Fixes
|
|
50
|
-
|
|
51
|
-
* **ci:** add lerna version step before publish ([3d20300](https://github.com/bernierllc/tools/commit/3d203002143bf353fffafe4f8a78a99009567347))
|
|
52
|
-
* **ci:** correct jest testEnvironment paths for CI ([c47144c](https://github.com/bernierllc/tools/commit/c47144c3d78aec2be1e1454066c235c2227823fd))
|
|
53
|
-
* **ci:** fix release workflow + convert internal deps to workspace:* ([01c078b](https://github.com/bernierllc/tools/commit/01c078b49d6025f7eef750f79207a1c71c8d85dc))
|
|
54
|
-
* **jest:** move global options to root config and fix typos ([c14710c](https://github.com/bernierllc/tools/commit/c14710c11e8fc34dd7f773edf01328151564323a))
|
|
55
|
-
* **jest:** resolve Node.js v25+ localStorage SecurityError ([8ffc512](https://github.com/bernierllc/tools/commit/8ffc512805519bc5ba523bdbcd1c457e84998c9e))
|
|
56
|
-
* update neverhub-adapter deps to workspace:* and publish 0.1.2 ([f0e3d04](https://github.com/bernierllc/tools/commit/f0e3d04d8d4f094e3bb899ddf81e93243d16e2c2))
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
### Features
|
|
60
|
-
|
|
61
|
-
* **ai-provider-anthropic:** Complete implementation with 96% compliance ([053ec23](https://github.com/bernierllc/tools/commit/053ec23b31c8dfa46ae1f0e0585a26af2b389d61))
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
# 1.1.0 (2025-12-25)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
### Bug Fixes
|
|
71
|
-
|
|
72
|
-
* **ci:** correct jest testEnvironment paths for CI ([c47144c](https://github.com/bernierllc/tools/commit/c47144c3d78aec2be1e1454066c235c2227823fd))
|
|
73
|
-
* **ci:** fix release workflow + convert internal deps to workspace:* ([01c078b](https://github.com/bernierllc/tools/commit/01c078b49d6025f7eef750f79207a1c71c8d85dc))
|
|
74
|
-
* **jest:** move global options to root config and fix typos ([c14710c](https://github.com/bernierllc/tools/commit/c14710c11e8fc34dd7f773edf01328151564323a))
|
|
75
|
-
* **jest:** resolve Node.js v25+ localStorage SecurityError ([8ffc512](https://github.com/bernierllc/tools/commit/8ffc512805519bc5ba523bdbcd1c457e84998c9e))
|
|
76
|
-
* update neverhub-adapter deps to workspace:* and publish 0.1.2 ([f0e3d04](https://github.com/bernierllc/tools/commit/f0e3d04d8d4f094e3bb899ddf81e93243d16e2c2))
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
### Features
|
|
80
|
-
|
|
81
|
-
* **ai-provider-anthropic:** Complete implementation with 96% compliance ([053ec23](https://github.com/bernierllc/tools/commit/053ec23b31c8dfa46ae1f0e0585a26af2b389d61))
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
# @bernierllc/ai-provider-anthropic
|
|
88
|
-
|
|
89
|
-
## 1.0.2
|
|
90
|
-
|
|
91
|
-
### Patch Changes
|
|
92
|
-
|
|
93
|
-
- Updated dependencies [[`73c1d1e`](https://github.com/bernierllc/tools/commit/73c1d1e46114cf2ccfd5b74b83743361247f4502)]:
|
|
94
|
-
- @bernierllc/logger@1.1.0
|
|
95
|
-
- @bernierllc/ai-provider-core@1.0.3
|
|
96
|
-
|
|
97
|
-
## 1.0.1
|
|
98
|
-
|
|
99
|
-
### Patch Changes
|
|
100
|
-
|
|
101
|
-
- Updated dependencies [[`24899fa`](https://github.com/bernierllc/tools/commit/24899fa4eaf80ae329f7bd74483cf97a132f5d4c)]:
|
|
102
|
-
- @bernierllc/logger@1.0.4
|
|
103
|
-
- @bernierllc/ai-provider-core@1.0.2
|