@juspay/neurolink 9.14.0 → 9.15.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/CHANGELOG.md +6 -0
- package/README.md +15 -15
- package/dist/auth/anthropicOAuth.d.ts +377 -0
- package/dist/auth/anthropicOAuth.js +914 -0
- package/dist/auth/index.d.ts +20 -0
- package/dist/auth/index.js +29 -0
- package/dist/auth/tokenStore.d.ts +225 -0
- package/dist/auth/tokenStore.js +521 -0
- package/dist/cli/commands/auth.d.ts +50 -0
- package/dist/cli/commands/auth.js +1115 -0
- package/dist/cli/factories/authCommandFactory.d.ts +52 -0
- package/dist/cli/factories/authCommandFactory.js +146 -0
- package/dist/cli/factories/commandFactory.d.ts +6 -0
- package/dist/cli/factories/commandFactory.js +92 -2
- package/dist/cli/parser.js +11 -2
- package/dist/constants/enums.d.ts +20 -0
- package/dist/constants/enums.js +30 -0
- package/dist/constants/index.d.ts +3 -1
- package/dist/constants/index.js +11 -1
- package/dist/index.d.ts +1 -1
- package/dist/lib/auth/anthropicOAuth.d.ts +377 -0
- package/dist/lib/auth/anthropicOAuth.js +915 -0
- package/dist/lib/auth/index.d.ts +20 -0
- package/dist/lib/auth/index.js +30 -0
- package/dist/lib/auth/tokenStore.d.ts +225 -0
- package/dist/lib/auth/tokenStore.js +522 -0
- package/dist/lib/constants/enums.d.ts +20 -0
- package/dist/lib/constants/enums.js +30 -0
- package/dist/lib/constants/index.d.ts +3 -1
- package/dist/lib/constants/index.js +11 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/models/anthropicModels.d.ts +267 -0
- package/dist/lib/models/anthropicModels.js +528 -0
- package/dist/lib/providers/anthropic.d.ts +123 -2
- package/dist/lib/providers/anthropic.js +800 -10
- package/dist/lib/types/errors.d.ts +62 -0
- package/dist/lib/types/errors.js +107 -0
- package/dist/lib/types/index.d.ts +2 -1
- package/dist/lib/types/index.js +2 -0
- package/dist/lib/types/providers.d.ts +107 -0
- package/dist/lib/types/providers.js +69 -0
- package/dist/lib/types/subscriptionTypes.d.ts +893 -0
- package/dist/lib/types/subscriptionTypes.js +8 -0
- package/dist/lib/utils/providerConfig.d.ts +167 -0
- package/dist/lib/utils/providerConfig.js +619 -9
- package/dist/models/anthropicModels.d.ts +267 -0
- package/dist/models/anthropicModels.js +527 -0
- package/dist/providers/anthropic.d.ts +123 -2
- package/dist/providers/anthropic.js +800 -10
- package/dist/types/errors.d.ts +62 -0
- package/dist/types/errors.js +107 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js +2 -0
- package/dist/types/providers.d.ts +107 -0
- package/dist/types/providers.js +69 -0
- package/dist/types/subscriptionTypes.d.ts +893 -0
- package/dist/types/subscriptionTypes.js +7 -0
- package/dist/utils/providerConfig.d.ts +167 -0
- package/dist/utils/providerConfig.js +619 -9
- package/package.json +2 -1
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic Models - Subscription Tier Access and Capabilities
|
|
3
|
+
*
|
|
4
|
+
* This module defines Anthropic Claude models, their availability by subscription tier,
|
|
5
|
+
* model capabilities, and provides helper functions for tier-based access control.
|
|
6
|
+
*/
|
|
7
|
+
import { ModelAccessError } from "../types/errors.js";
|
|
8
|
+
export { ModelAccessError };
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// ANTHROPIC MODEL ENUM
|
|
11
|
+
// ============================================================================
|
|
12
|
+
/**
|
|
13
|
+
* Anthropic Claude model identifiers
|
|
14
|
+
*
|
|
15
|
+
* @description Enum of all available Claude models with their exact API identifiers.
|
|
16
|
+
* Models are organized by family (Haiku, Sonnet, Opus) and version.
|
|
17
|
+
*/
|
|
18
|
+
export var AnthropicModel;
|
|
19
|
+
(function (AnthropicModel) {
|
|
20
|
+
// Claude 3 Haiku (Legacy - Fast, efficient)
|
|
21
|
+
AnthropicModel["CLAUDE_3_HAIKU"] = "claude-3-haiku-20240307";
|
|
22
|
+
// Claude 3.5 Haiku (Current fast model)
|
|
23
|
+
AnthropicModel["CLAUDE_3_5_HAIKU"] = "claude-3-5-haiku-20241022";
|
|
24
|
+
// Claude 3.5 Sonnet (Balanced performance)
|
|
25
|
+
AnthropicModel["CLAUDE_3_5_SONNET"] = "claude-3-5-sonnet-20241022";
|
|
26
|
+
// Claude 3.5 Sonnet V2 (Updated version)
|
|
27
|
+
AnthropicModel["CLAUDE_3_5_SONNET_V2"] = "claude-3-5-sonnet-v2-20241022";
|
|
28
|
+
// Claude Sonnet 4 (Latest Sonnet)
|
|
29
|
+
AnthropicModel["CLAUDE_SONNET_4"] = "claude-sonnet-4-20250514";
|
|
30
|
+
// Claude 3 Opus (Legacy flagship)
|
|
31
|
+
AnthropicModel["CLAUDE_3_OPUS"] = "claude-3-opus-20240229";
|
|
32
|
+
// Claude Opus 4 (Latest flagship)
|
|
33
|
+
AnthropicModel["CLAUDE_OPUS_4"] = "claude-opus-4-20250514";
|
|
34
|
+
})(AnthropicModel || (AnthropicModel = {}));
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// MODEL TIER ACCESS DEFINITIONS
|
|
37
|
+
// ============================================================================
|
|
38
|
+
/**
|
|
39
|
+
* Model access mapping by subscription tier
|
|
40
|
+
*
|
|
41
|
+
* Each tier includes progressively more models:
|
|
42
|
+
* - free: Basic models for casual use (Haiku only)
|
|
43
|
+
* - pro: Professional tier with Sonnet models
|
|
44
|
+
* - max: All models including the latest flagship Opus
|
|
45
|
+
* - api: Full API access to all models (based on API access)
|
|
46
|
+
*/
|
|
47
|
+
export const MODEL_TIER_ACCESS = {
|
|
48
|
+
// Free tier: Basic/older Haiku models only
|
|
49
|
+
free: [AnthropicModel.CLAUDE_3_HAIKU, AnthropicModel.CLAUDE_3_5_HAIKU],
|
|
50
|
+
// Pro tier: Haiku + Sonnet models
|
|
51
|
+
pro: [
|
|
52
|
+
// Haiku models
|
|
53
|
+
AnthropicModel.CLAUDE_3_HAIKU,
|
|
54
|
+
AnthropicModel.CLAUDE_3_5_HAIKU,
|
|
55
|
+
// Sonnet models
|
|
56
|
+
AnthropicModel.CLAUDE_3_5_SONNET,
|
|
57
|
+
AnthropicModel.CLAUDE_3_5_SONNET_V2,
|
|
58
|
+
AnthropicModel.CLAUDE_SONNET_4,
|
|
59
|
+
],
|
|
60
|
+
// Max tier: All models including Opus
|
|
61
|
+
max: ["*"], // All models
|
|
62
|
+
// Max 5x tier: Same access as max tier (5x usage multiplier)
|
|
63
|
+
max_5: ["*"], // All models
|
|
64
|
+
// Max 20x tier: Same access as max tier (20x usage multiplier)
|
|
65
|
+
max_20: ["*"], // All models
|
|
66
|
+
// API tier: Full access to all models (based on API access)
|
|
67
|
+
api: ["*"], // All models
|
|
68
|
+
};
|
|
69
|
+
// ============================================================================
|
|
70
|
+
// MODEL METADATA
|
|
71
|
+
// ============================================================================
|
|
72
|
+
/**
|
|
73
|
+
* Model metadata by model ID
|
|
74
|
+
*
|
|
75
|
+
* Comprehensive mapping of each Anthropic model's metadata,
|
|
76
|
+
* including display names, context windows, vision support, and extended thinking.
|
|
77
|
+
*/
|
|
78
|
+
export const MODEL_METADATA = {
|
|
79
|
+
// Claude 3 Haiku (Legacy)
|
|
80
|
+
[AnthropicModel.CLAUDE_3_HAIKU]: {
|
|
81
|
+
displayName: "Claude 3 Haiku",
|
|
82
|
+
contextWindow: 200000,
|
|
83
|
+
maxOutputTokens: 4096,
|
|
84
|
+
supportsVision: true,
|
|
85
|
+
supportsExtendedThinking: false,
|
|
86
|
+
supportsToolUse: true,
|
|
87
|
+
supportsStreaming: true,
|
|
88
|
+
deprecated: true,
|
|
89
|
+
family: "haiku",
|
|
90
|
+
description: "Fast and efficient model for simple tasks",
|
|
91
|
+
},
|
|
92
|
+
// Claude 3.5 Haiku
|
|
93
|
+
[AnthropicModel.CLAUDE_3_5_HAIKU]: {
|
|
94
|
+
displayName: "Claude 3.5 Haiku",
|
|
95
|
+
contextWindow: 200000,
|
|
96
|
+
maxOutputTokens: 8192,
|
|
97
|
+
supportsVision: false,
|
|
98
|
+
supportsExtendedThinking: false,
|
|
99
|
+
supportsToolUse: true,
|
|
100
|
+
supportsStreaming: true,
|
|
101
|
+
deprecated: false,
|
|
102
|
+
family: "haiku",
|
|
103
|
+
description: "Improved fast model with better performance",
|
|
104
|
+
},
|
|
105
|
+
// Claude 3.5 Sonnet
|
|
106
|
+
[AnthropicModel.CLAUDE_3_5_SONNET]: {
|
|
107
|
+
displayName: "Claude 3.5 Sonnet",
|
|
108
|
+
contextWindow: 200000,
|
|
109
|
+
maxOutputTokens: 8192,
|
|
110
|
+
supportsVision: true,
|
|
111
|
+
supportsExtendedThinking: false,
|
|
112
|
+
supportsToolUse: true,
|
|
113
|
+
supportsStreaming: true,
|
|
114
|
+
deprecated: false,
|
|
115
|
+
family: "sonnet",
|
|
116
|
+
description: "Balanced model for most tasks",
|
|
117
|
+
},
|
|
118
|
+
// Claude 3.5 Sonnet V2
|
|
119
|
+
[AnthropicModel.CLAUDE_3_5_SONNET_V2]: {
|
|
120
|
+
displayName: "Claude 3.5 Sonnet V2",
|
|
121
|
+
contextWindow: 200000,
|
|
122
|
+
maxOutputTokens: 8192,
|
|
123
|
+
supportsVision: true,
|
|
124
|
+
supportsExtendedThinking: false,
|
|
125
|
+
supportsToolUse: true,
|
|
126
|
+
supportsStreaming: true,
|
|
127
|
+
deprecated: false,
|
|
128
|
+
family: "sonnet",
|
|
129
|
+
description: "Updated Sonnet with improved capabilities",
|
|
130
|
+
},
|
|
131
|
+
// Claude Sonnet 4
|
|
132
|
+
[AnthropicModel.CLAUDE_SONNET_4]: {
|
|
133
|
+
displayName: "Claude Sonnet 4",
|
|
134
|
+
contextWindow: 200000,
|
|
135
|
+
maxOutputTokens: 64000,
|
|
136
|
+
supportsVision: true,
|
|
137
|
+
supportsExtendedThinking: true,
|
|
138
|
+
supportsToolUse: true,
|
|
139
|
+
supportsStreaming: true,
|
|
140
|
+
deprecated: false,
|
|
141
|
+
family: "sonnet",
|
|
142
|
+
description: "Latest Sonnet with extended thinking support",
|
|
143
|
+
},
|
|
144
|
+
// Claude 3 Opus (Legacy)
|
|
145
|
+
[AnthropicModel.CLAUDE_3_OPUS]: {
|
|
146
|
+
displayName: "Claude 3 Opus",
|
|
147
|
+
contextWindow: 200000,
|
|
148
|
+
maxOutputTokens: 4096,
|
|
149
|
+
supportsVision: true,
|
|
150
|
+
supportsExtendedThinking: false,
|
|
151
|
+
supportsToolUse: true,
|
|
152
|
+
supportsStreaming: true,
|
|
153
|
+
deprecated: true,
|
|
154
|
+
family: "opus",
|
|
155
|
+
description: "Legacy flagship model for complex tasks",
|
|
156
|
+
},
|
|
157
|
+
// Claude Opus 4
|
|
158
|
+
[AnthropicModel.CLAUDE_OPUS_4]: {
|
|
159
|
+
displayName: "Claude Opus 4",
|
|
160
|
+
contextWindow: 200000,
|
|
161
|
+
maxOutputTokens: 64000,
|
|
162
|
+
supportsVision: true,
|
|
163
|
+
supportsExtendedThinking: true,
|
|
164
|
+
supportsToolUse: true,
|
|
165
|
+
supportsStreaming: true,
|
|
166
|
+
deprecated: false,
|
|
167
|
+
family: "opus",
|
|
168
|
+
description: "Latest flagship model with advanced reasoning",
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
// ============================================================================
|
|
172
|
+
// DEFAULT MODELS BY TIER
|
|
173
|
+
// ============================================================================
|
|
174
|
+
/**
|
|
175
|
+
* Default model for each subscription tier
|
|
176
|
+
*
|
|
177
|
+
* These are the recommended default models that provide the best
|
|
178
|
+
* balance of capability and cost for each tier level.
|
|
179
|
+
*/
|
|
180
|
+
export const DEFAULT_MODELS_BY_TIER = {
|
|
181
|
+
free: AnthropicModel.CLAUDE_3_5_HAIKU,
|
|
182
|
+
pro: AnthropicModel.CLAUDE_SONNET_4,
|
|
183
|
+
max: AnthropicModel.CLAUDE_OPUS_4,
|
|
184
|
+
max_5: AnthropicModel.CLAUDE_OPUS_4,
|
|
185
|
+
max_20: AnthropicModel.CLAUDE_OPUS_4,
|
|
186
|
+
api: AnthropicModel.CLAUDE_SONNET_4, // Sonnet is often best balance for API usage
|
|
187
|
+
};
|
|
188
|
+
// ============================================================================
|
|
189
|
+
// HELPER FUNCTIONS
|
|
190
|
+
// ============================================================================
|
|
191
|
+
/**
|
|
192
|
+
* Get all available model IDs
|
|
193
|
+
*
|
|
194
|
+
* @returns Array of all model ID strings
|
|
195
|
+
*/
|
|
196
|
+
function getAllModelIds() {
|
|
197
|
+
return Object.values(AnthropicModel);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Check if a model is available for a given subscription tier
|
|
201
|
+
*
|
|
202
|
+
* @param model - The model ID to check (can be enum value or string)
|
|
203
|
+
* @param tier - The subscription tier to check against
|
|
204
|
+
* @returns true if the model is available for the tier
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* if (isModelAvailableForTier(AnthropicModel.CLAUDE_OPUS_4, "pro")) {
|
|
209
|
+
* // Model not available for pro tier
|
|
210
|
+
* }
|
|
211
|
+
*
|
|
212
|
+
* if (isModelAvailableForTier(AnthropicModel.CLAUDE_OPUS_4, "max")) {
|
|
213
|
+
* // Model available for max tier
|
|
214
|
+
* }
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export function isModelAvailableForTier(model, tier) {
|
|
218
|
+
const availableModels = MODEL_TIER_ACCESS[tier];
|
|
219
|
+
// Check for wildcard access (all models)
|
|
220
|
+
if (availableModels.includes("*")) {
|
|
221
|
+
// Verify model is a valid Anthropic model
|
|
222
|
+
return getAllModelIds().includes(model);
|
|
223
|
+
}
|
|
224
|
+
return availableModels.includes(model);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Get all models available for a given subscription tier
|
|
228
|
+
*
|
|
229
|
+
* @param tier - The subscription tier
|
|
230
|
+
* @returns Array of model IDs available for the tier
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* const models = getAvailableModelsForTier("pro");
|
|
235
|
+
* console.log(models);
|
|
236
|
+
* // ["claude-3-haiku-20240307", "claude-3-5-haiku-20241022", "claude-3-5-sonnet-20241022", ...]
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
export function getAvailableModelsForTier(tier) {
|
|
240
|
+
const availableModels = MODEL_TIER_ACCESS[tier];
|
|
241
|
+
// If wildcard, return all models
|
|
242
|
+
if (availableModels.includes("*")) {
|
|
243
|
+
return getAllModelIds();
|
|
244
|
+
}
|
|
245
|
+
return [...availableModels];
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Get the human-readable display name for a model
|
|
249
|
+
*
|
|
250
|
+
* @param model - The model ID
|
|
251
|
+
* @returns The display name, or the model ID if not found
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* const name = getModelDisplayName(AnthropicModel.CLAUDE_OPUS_4);
|
|
256
|
+
* console.log(name); // "Claude Opus 4"
|
|
257
|
+
*
|
|
258
|
+
* const unknown = getModelDisplayName("unknown-model");
|
|
259
|
+
* console.log(unknown); // "unknown-model"
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
export function getModelDisplayName(model) {
|
|
263
|
+
const metadata = MODEL_METADATA[model];
|
|
264
|
+
return metadata?.displayName ?? model;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Get the default/recommended model for a given subscription tier
|
|
268
|
+
*
|
|
269
|
+
* Returns the best default model that should be used for each tier.
|
|
270
|
+
*
|
|
271
|
+
* @param tier - The subscription tier
|
|
272
|
+
* @returns The default model ID for the tier
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* const model = getDefaultModelForTier("max");
|
|
277
|
+
* console.log(model); // "claude-opus-4-20250514"
|
|
278
|
+
*
|
|
279
|
+
* const proModel = getDefaultModelForTier("pro");
|
|
280
|
+
* console.log(proModel); // "claude-sonnet-4-20250514"
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
export function getDefaultModelForTier(tier) {
|
|
284
|
+
return DEFAULT_MODELS_BY_TIER[tier];
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Get metadata for a specific model
|
|
288
|
+
*
|
|
289
|
+
* @param model - The model ID
|
|
290
|
+
* @returns The model metadata, or undefined if not found
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```typescript
|
|
294
|
+
* const metadata = getModelMetadata(AnthropicModel.CLAUDE_OPUS_4);
|
|
295
|
+
* if (metadata?.supportsExtendedThinking) {
|
|
296
|
+
* // Enable extended thinking mode
|
|
297
|
+
* }
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
export function getModelMetadata(model) {
|
|
301
|
+
return MODEL_METADATA[model];
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Check if a model supports a specific capability
|
|
305
|
+
*
|
|
306
|
+
* @param model - The model ID
|
|
307
|
+
* @param capability - The capability to check
|
|
308
|
+
* @returns true if the model supports the capability
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```typescript
|
|
312
|
+
* if (modelSupportsCapability(AnthropicModel.CLAUDE_OPUS_4, "supportsExtendedThinking")) {
|
|
313
|
+
* // Use extended thinking
|
|
314
|
+
* }
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
export function modelSupportsCapability(model, capability) {
|
|
318
|
+
const metadata = MODEL_METADATA[model];
|
|
319
|
+
if (!metadata) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
const value = metadata[capability];
|
|
323
|
+
// For boolean capabilities, return the value directly
|
|
324
|
+
// For numeric capabilities, check if truthy (> 0)
|
|
325
|
+
return typeof value === "boolean" ? value : Boolean(value);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Get the minimum subscription tier required for a model
|
|
329
|
+
*
|
|
330
|
+
* @param model - The model ID to check
|
|
331
|
+
* @returns The minimum tier required, or "api" if model not found
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* const tier = getMinimumTierForModel(AnthropicModel.CLAUDE_OPUS_4);
|
|
336
|
+
* console.log(tier); // "max"
|
|
337
|
+
*
|
|
338
|
+
* const haikuTier = getMinimumTierForModel(AnthropicModel.CLAUDE_3_HAIKU);
|
|
339
|
+
* console.log(haikuTier); // "free"
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
export function getMinimumTierForModel(model) {
|
|
343
|
+
// Check tiers in order from lowest to highest
|
|
344
|
+
const tierOrder = [
|
|
345
|
+
"free",
|
|
346
|
+
"pro",
|
|
347
|
+
"max",
|
|
348
|
+
"max_5",
|
|
349
|
+
"max_20",
|
|
350
|
+
"api",
|
|
351
|
+
];
|
|
352
|
+
for (const tier of tierOrder) {
|
|
353
|
+
if (isModelAvailableForTier(model, tier)) {
|
|
354
|
+
return tier;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// Default to API tier if model not found (for custom/unknown models)
|
|
358
|
+
return "api";
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Get all models that support a specific capability
|
|
362
|
+
*
|
|
363
|
+
* @param capability - The capability to filter by
|
|
364
|
+
* @returns Array of model IDs that have the capability
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* ```typescript
|
|
368
|
+
* const thinkingModels = getModelsWithCapability("supportsExtendedThinking");
|
|
369
|
+
* console.log(thinkingModels);
|
|
370
|
+
* // ["claude-sonnet-4-20250514", "claude-opus-4-20250514"]
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
export function getModelsWithCapability(capability) {
|
|
374
|
+
return Object.entries(MODEL_METADATA)
|
|
375
|
+
.filter(([_, metadata]) => {
|
|
376
|
+
const value = metadata[capability];
|
|
377
|
+
return typeof value === "boolean" ? value : Boolean(value);
|
|
378
|
+
})
|
|
379
|
+
.map(([modelId]) => modelId);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Get models filtered by family (haiku, sonnet, opus)
|
|
383
|
+
*
|
|
384
|
+
* @param family - The model family to filter by
|
|
385
|
+
* @returns Array of model IDs in the specified family
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```typescript
|
|
389
|
+
* const opusModels = getModelsByFamily("opus");
|
|
390
|
+
* // ["claude-3-opus-20240229", "claude-opus-4-20250514"]
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
export function getModelsByFamily(family) {
|
|
394
|
+
return Object.entries(MODEL_METADATA)
|
|
395
|
+
.filter(([_, metadata]) => metadata.family === family)
|
|
396
|
+
.map(([modelId]) => modelId);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Get the latest (non-deprecated) model in each family
|
|
400
|
+
*
|
|
401
|
+
* @returns Object mapping family name to the latest model in that family
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```typescript
|
|
405
|
+
* const latest = getLatestModelsByFamily();
|
|
406
|
+
* console.log(latest.opus); // "claude-opus-4-20250514"
|
|
407
|
+
* console.log(latest.sonnet); // "claude-sonnet-4-20250514"
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
export function getLatestModelsByFamily() {
|
|
411
|
+
const result = {
|
|
412
|
+
haiku: undefined,
|
|
413
|
+
sonnet: undefined,
|
|
414
|
+
opus: undefined,
|
|
415
|
+
};
|
|
416
|
+
// Priority order for each family (latest first based on model version)
|
|
417
|
+
const familyPriority = {
|
|
418
|
+
haiku: [AnthropicModel.CLAUDE_3_5_HAIKU, AnthropicModel.CLAUDE_3_HAIKU],
|
|
419
|
+
sonnet: [
|
|
420
|
+
AnthropicModel.CLAUDE_SONNET_4,
|
|
421
|
+
AnthropicModel.CLAUDE_3_5_SONNET_V2,
|
|
422
|
+
AnthropicModel.CLAUDE_3_5_SONNET,
|
|
423
|
+
],
|
|
424
|
+
opus: [AnthropicModel.CLAUDE_OPUS_4, AnthropicModel.CLAUDE_3_OPUS],
|
|
425
|
+
};
|
|
426
|
+
for (const family of Object.keys(familyPriority)) {
|
|
427
|
+
for (const model of familyPriority[family]) {
|
|
428
|
+
const metadata = MODEL_METADATA[model];
|
|
429
|
+
if (metadata && !metadata.deprecated) {
|
|
430
|
+
result[family] = model;
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return result;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Validate that a model is accessible for a given tier, throwing if not
|
|
439
|
+
*
|
|
440
|
+
* @param model - The model ID to validate
|
|
441
|
+
* @param tier - The subscription tier to validate against
|
|
442
|
+
* @throws {ModelAccessError} If the model is not available for the tier
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* try {
|
|
447
|
+
* validateModelAccess(AnthropicModel.CLAUDE_OPUS_4, "free");
|
|
448
|
+
* } catch (error) {
|
|
449
|
+
* if (error instanceof ModelAccessError) {
|
|
450
|
+
* console.log(`Upgrade to ${error.requiredTier} to use this model`);
|
|
451
|
+
* }
|
|
452
|
+
* }
|
|
453
|
+
* ```
|
|
454
|
+
*/
|
|
455
|
+
export function validateModelAccess(model, tier) {
|
|
456
|
+
if (!isModelAvailableForTier(model, tier)) {
|
|
457
|
+
const requiredTier = getMinimumTierForModel(model);
|
|
458
|
+
throw new ModelAccessError(model, tier, requiredTier);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Compare subscription tiers
|
|
463
|
+
*
|
|
464
|
+
* @param tier1 - First tier to compare
|
|
465
|
+
* @param tier2 - Second tier to compare
|
|
466
|
+
* @returns Negative if tier1 < tier2, positive if tier1 > tier2, 0 if equal
|
|
467
|
+
*/
|
|
468
|
+
export function compareTiers(tier1, tier2) {
|
|
469
|
+
const tierOrder = [
|
|
470
|
+
"free",
|
|
471
|
+
"pro",
|
|
472
|
+
"max",
|
|
473
|
+
"max_5",
|
|
474
|
+
"max_20",
|
|
475
|
+
"api",
|
|
476
|
+
];
|
|
477
|
+
return tierOrder.indexOf(tier1) - tierOrder.indexOf(tier2);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Get context window size for a model
|
|
481
|
+
*
|
|
482
|
+
* @param model - The model ID
|
|
483
|
+
* @returns The context window size in tokens, or 0 if model not found
|
|
484
|
+
*/
|
|
485
|
+
export function getContextWindow(model) {
|
|
486
|
+
return MODEL_METADATA[model]?.contextWindow ?? 0;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Get max output tokens for a model
|
|
490
|
+
*
|
|
491
|
+
* @param model - The model ID
|
|
492
|
+
* @returns The max output tokens, or 0 if model not found
|
|
493
|
+
*/
|
|
494
|
+
export function getMaxOutputTokens(model) {
|
|
495
|
+
return MODEL_METADATA[model]?.maxOutputTokens ?? 0;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Check if a model supports vision/image input
|
|
499
|
+
*
|
|
500
|
+
* @param model - The model ID
|
|
501
|
+
* @returns true if the model supports vision
|
|
502
|
+
*/
|
|
503
|
+
export function supportsVision(model) {
|
|
504
|
+
return MODEL_METADATA[model]?.supportsVision ?? false;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Check if a model supports extended thinking
|
|
508
|
+
*
|
|
509
|
+
* @param model - The model ID
|
|
510
|
+
* @returns true if the model supports extended thinking
|
|
511
|
+
*/
|
|
512
|
+
export function supportsExtendedThinking(model) {
|
|
513
|
+
return MODEL_METADATA[model]?.supportsExtendedThinking ?? false;
|
|
514
|
+
}
|
|
515
|
+
// ============================================================================
|
|
516
|
+
// BACKWARD COMPATIBILITY ALIASES
|
|
517
|
+
// ============================================================================
|
|
518
|
+
/**
|
|
519
|
+
* Alias for getDefaultModelForTier for backward compatibility
|
|
520
|
+
* @deprecated Use getDefaultModelForTier instead
|
|
521
|
+
*/
|
|
522
|
+
export const getRecommendedModelForTier = getDefaultModelForTier;
|
|
523
|
+
/**
|
|
524
|
+
* Alias for getModelMetadata for backward compatibility
|
|
525
|
+
* @deprecated Use getModelMetadata instead
|
|
526
|
+
*/
|
|
527
|
+
export const getModelCapabilities = getModelMetadata;
|
|
528
|
+
//# sourceMappingURL=anthropicModels.js.map
|
|
@@ -1,15 +1,129 @@
|
|
|
1
1
|
import { type LanguageModelV1 } from "ai";
|
|
2
2
|
import { type AIProviderName } from "../constants/enums.js";
|
|
3
3
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
4
|
+
import type { TextGenerationOptions, EnhancedGenerateResult } from "../types/generateTypes.js";
|
|
4
5
|
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
5
6
|
import type { ValidationSchema } from "../types/typeAliases.js";
|
|
7
|
+
import type { ClaudeSubscriptionTier, AnthropicAuthMethod, AnthropicResponseMetadata, ClaudeUsageInfo } from "../types/subscriptionTypes.js";
|
|
8
|
+
import type { AnthropicProviderConfig } from "../types/providers.js";
|
|
9
|
+
/**
|
|
10
|
+
* Beta headers for Claude Code integration.
|
|
11
|
+
* These enable experimental features:
|
|
12
|
+
* - claude-code-20250219: Claude Code specific features
|
|
13
|
+
* - interleaved-thinking-2025-05-14: Interleaved thinking mode
|
|
14
|
+
* - fine-grained-tool-streaming-2025-05-14: Fine-grained tool streaming
|
|
15
|
+
*/
|
|
16
|
+
declare const ANTHROPIC_BETA_HEADERS: {
|
|
17
|
+
"anthropic-beta": string;
|
|
18
|
+
};
|
|
19
|
+
export type { AnthropicProviderConfig } from "../types/providers.js";
|
|
6
20
|
/**
|
|
7
21
|
* Anthropic Provider v2 - BaseProvider Implementation
|
|
8
|
-
*
|
|
22
|
+
* Enhanced with OAuth support, subscription tiers, and beta headers for Claude Code integration.
|
|
9
23
|
*/
|
|
10
24
|
export declare class AnthropicProvider extends BaseProvider {
|
|
11
25
|
private model;
|
|
12
|
-
|
|
26
|
+
private readonly authMethod;
|
|
27
|
+
private readonly subscriptionTier;
|
|
28
|
+
private readonly enableBetaFeatures;
|
|
29
|
+
private oauthToken;
|
|
30
|
+
private lastResponseMetadata;
|
|
31
|
+
private usageInfo;
|
|
32
|
+
private refreshPromise?;
|
|
33
|
+
/**
|
|
34
|
+
* Create a new Anthropic provider instance.
|
|
35
|
+
*
|
|
36
|
+
* @param modelName - Optional model name to use (defaults to CLAUDE_3_5_SONNET)
|
|
37
|
+
* @param sdk - Optional NeuroLink SDK instance
|
|
38
|
+
* @param config - Optional configuration options for auth, subscription tier, and beta features
|
|
39
|
+
*/
|
|
40
|
+
constructor(modelName?: string, sdk?: unknown, config?: AnthropicProviderConfig);
|
|
41
|
+
/**
|
|
42
|
+
* Get authentication headers based on current auth method and configuration.
|
|
43
|
+
*
|
|
44
|
+
* @returns Headers object containing auth and beta feature headers
|
|
45
|
+
*/
|
|
46
|
+
getAuthHeaders(): Record<string, string>;
|
|
47
|
+
/**
|
|
48
|
+
* Validate if a model is accessible with the current subscription tier.
|
|
49
|
+
*
|
|
50
|
+
* @param model - The model ID to validate
|
|
51
|
+
* @returns true if the model is accessible, false otherwise
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const provider = new AnthropicProvider();
|
|
56
|
+
* if (provider.validateModelAccess("claude-opus-4-5-20251101")) {
|
|
57
|
+
* // Use the model
|
|
58
|
+
* } else {
|
|
59
|
+
* // Fall back to a different model or show upgrade prompt
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
validateModelAccess(model: string): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Get current usage information.
|
|
66
|
+
*
|
|
67
|
+
* Returns usage tracking data including messages sent, tokens consumed,
|
|
68
|
+
* and remaining quotas. This information is updated after each API request.
|
|
69
|
+
*
|
|
70
|
+
* @returns Current usage info or null if no requests have been made
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const usage = provider.getUsageInfo();
|
|
75
|
+
* if (usage && usage.tokenQuotaPercent > 80) {
|
|
76
|
+
* console.warn("Approaching token quota limit");
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
getUsageInfo(): ClaudeUsageInfo | null;
|
|
81
|
+
/**
|
|
82
|
+
* Check if beta features are enabled for this provider instance.
|
|
83
|
+
*
|
|
84
|
+
* @returns true if beta features are enabled
|
|
85
|
+
*/
|
|
86
|
+
areBetaFeaturesEnabled(): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Get model capabilities for the current model.
|
|
89
|
+
*
|
|
90
|
+
* @returns The model capabilities or undefined if not found
|
|
91
|
+
*/
|
|
92
|
+
getModelCapabilities(): import("../types/subscriptionTypes.js").AnthropicModelMetadata | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Get the current subscription tier.
|
|
95
|
+
* @returns The detected or configured subscription tier
|
|
96
|
+
*/
|
|
97
|
+
getSubscriptionTier(): ClaudeSubscriptionTier;
|
|
98
|
+
/**
|
|
99
|
+
* Get the authentication method being used.
|
|
100
|
+
* @returns The current authentication method
|
|
101
|
+
*/
|
|
102
|
+
getAuthMethod(): AnthropicAuthMethod;
|
|
103
|
+
/**
|
|
104
|
+
* Refresh OAuth token if needed and possible.
|
|
105
|
+
* This method checks if the token is expired or about to expire,
|
|
106
|
+
* and attempts to refresh it using the refresh token if available.
|
|
107
|
+
*
|
|
108
|
+
* @returns Promise that resolves when refresh is complete (or not needed)
|
|
109
|
+
* @throws Error if refresh is needed but fails
|
|
110
|
+
*/
|
|
111
|
+
refreshAuthIfNeeded(): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Get the last response metadata including rate limit information.
|
|
114
|
+
* @returns The last response metadata or null if no request has been made
|
|
115
|
+
*/
|
|
116
|
+
getLastResponseMetadata(): AnthropicResponseMetadata | null;
|
|
117
|
+
/**
|
|
118
|
+
* Update response metadata from API response headers.
|
|
119
|
+
* This should be called after each API request to track rate limits.
|
|
120
|
+
* @param headers - Response headers from the API
|
|
121
|
+
* @param requestId - Optional request ID
|
|
122
|
+
*/
|
|
123
|
+
protected updateResponseMetadata(headers: Headers | Record<string, string>, requestId?: string, usageUpdate?: {
|
|
124
|
+
inputTokens?: number;
|
|
125
|
+
outputTokens?: number;
|
|
126
|
+
}): void;
|
|
13
127
|
getProviderName(): AIProviderName;
|
|
14
128
|
getDefaultModel(): string;
|
|
15
129
|
/**
|
|
@@ -17,8 +131,15 @@ export declare class AnthropicProvider extends BaseProvider {
|
|
|
17
131
|
*/
|
|
18
132
|
getAISDKModel(): LanguageModelV1;
|
|
19
133
|
protected formatProviderError(error: unknown): Error;
|
|
134
|
+
/**
|
|
135
|
+
* Override generate to refresh the OAuth token before delegating to
|
|
136
|
+
* BaseProvider so that expired tokens are renewed automatically.
|
|
137
|
+
*/
|
|
138
|
+
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ValidationSchema): Promise<EnhancedGenerateResult | null>;
|
|
20
139
|
protected executeStream(options: StreamOptions, _analysisSchema?: ValidationSchema): Promise<StreamResult>;
|
|
21
140
|
isAvailable(): Promise<boolean>;
|
|
22
141
|
getModel(): LanguageModelV1;
|
|
23
142
|
}
|
|
143
|
+
export { ModelAccessError, isModelAvailableForTier, getRecommendedModelForTier, getModelCapabilities, } from "../models/anthropicModels.js";
|
|
144
|
+
export { ANTHROPIC_BETA_HEADERS };
|
|
24
145
|
export default AnthropicProvider;
|