@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,893 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Subscription Types for NeuroLink
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for Claude subscription tiers, authentication methods,
|
|
5
|
+
* and usage tracking for Anthropic API access.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Claude subscription tier levels
|
|
9
|
+
*
|
|
10
|
+
* @description Represents the different subscription tiers available for Claude:
|
|
11
|
+
* - "free": Free tier with basic access and limited usage
|
|
12
|
+
* - "pro": Professional tier with higher limits and priority access
|
|
13
|
+
* - "max": Maximum tier with highest limits and advanced features (alias for max_5)
|
|
14
|
+
* - "max_5": Max 5x usage tier
|
|
15
|
+
* - "max_20": Max 20x usage tier
|
|
16
|
+
* - "api": Direct API access tier for developers and enterprises
|
|
17
|
+
*/
|
|
18
|
+
export type ClaudeSubscriptionTier = "free" | "pro" | "max" | "max_5" | "max_20" | "api";
|
|
19
|
+
/**
|
|
20
|
+
* Authentication methods supported for Anthropic API access
|
|
21
|
+
*
|
|
22
|
+
* @description Defines the available authentication methods:
|
|
23
|
+
* - "api_key": Traditional API key authentication for direct API access
|
|
24
|
+
* - "oauth": OAuth 2.0 authentication for subscription-based access
|
|
25
|
+
*/
|
|
26
|
+
export type AnthropicAuthMethod = "api_key" | "oauth";
|
|
27
|
+
/**
|
|
28
|
+
* OAuth token structure for Claude subscriptions
|
|
29
|
+
*
|
|
30
|
+
* @description Contains the OAuth token information for authenticated sessions
|
|
31
|
+
*/
|
|
32
|
+
export type OAuthToken = {
|
|
33
|
+
/**
|
|
34
|
+
* The access token for API requests
|
|
35
|
+
*/
|
|
36
|
+
accessToken: string;
|
|
37
|
+
/**
|
|
38
|
+
* The refresh token for obtaining new access tokens
|
|
39
|
+
*/
|
|
40
|
+
refreshToken?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Token expiration timestamp (Unix milliseconds, i.e. Date.now() scale)
|
|
43
|
+
*/
|
|
44
|
+
expiresAt?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Token type (typically "Bearer")
|
|
47
|
+
*/
|
|
48
|
+
tokenType?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Scopes granted to this token
|
|
51
|
+
*/
|
|
52
|
+
scopes?: string[];
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Rate limit information parsed from Anthropic API response headers
|
|
56
|
+
*
|
|
57
|
+
* @see https://docs.anthropic.com/en/api/rate-limits
|
|
58
|
+
*/
|
|
59
|
+
export type AnthropicRateLimitInfo = {
|
|
60
|
+
/**
|
|
61
|
+
* Maximum number of requests allowed in the current window
|
|
62
|
+
*/
|
|
63
|
+
requestsLimit?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Number of requests remaining in the current window
|
|
66
|
+
*/
|
|
67
|
+
requestsRemaining?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Time when the request limit resets (ISO 8601 timestamp)
|
|
70
|
+
*/
|
|
71
|
+
requestsReset?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Maximum number of tokens allowed in the current window
|
|
74
|
+
*/
|
|
75
|
+
tokensLimit?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Number of tokens remaining in the current window
|
|
78
|
+
*/
|
|
79
|
+
tokensRemaining?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Time when the token limit resets (ISO 8601 timestamp)
|
|
82
|
+
*/
|
|
83
|
+
tokensReset?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Retry-After header value in seconds (present on 429 responses)
|
|
86
|
+
*/
|
|
87
|
+
retryAfter?: number;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Response metadata including rate limit information
|
|
91
|
+
*
|
|
92
|
+
* @description Contains metadata from Anthropic API responses
|
|
93
|
+
*/
|
|
94
|
+
export type AnthropicResponseMetadata = {
|
|
95
|
+
/**
|
|
96
|
+
* Rate limit information from response headers
|
|
97
|
+
*/
|
|
98
|
+
rateLimit?: AnthropicRateLimitInfo;
|
|
99
|
+
/**
|
|
100
|
+
* Request ID for debugging
|
|
101
|
+
*/
|
|
102
|
+
requestId?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Server timing information
|
|
105
|
+
*/
|
|
106
|
+
serverTiming?: string;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Anthropic authentication configuration
|
|
110
|
+
*
|
|
111
|
+
* @description Configuration interface for authenticating with Anthropic services.
|
|
112
|
+
* Supports both API key and OAuth authentication methods.
|
|
113
|
+
*/
|
|
114
|
+
export type AnthropicAuthConfig = {
|
|
115
|
+
/**
|
|
116
|
+
* Authentication method to use
|
|
117
|
+
* @see AnthropicAuthMethod
|
|
118
|
+
*/
|
|
119
|
+
method: AnthropicAuthMethod;
|
|
120
|
+
/**
|
|
121
|
+
* API key for API key authentication method
|
|
122
|
+
* @description Required when method is "api_key"
|
|
123
|
+
*/
|
|
124
|
+
apiKey?: string;
|
|
125
|
+
/**
|
|
126
|
+
* OAuth token object for OAuth authentication method
|
|
127
|
+
* @description Full OAuth token with access, refresh, and expiry information
|
|
128
|
+
*/
|
|
129
|
+
oauthToken?: OAuthToken;
|
|
130
|
+
/**
|
|
131
|
+
* OAuth access token for OAuth authentication method
|
|
132
|
+
* @description Required when method is "oauth", obtained through OAuth flow
|
|
133
|
+
* @deprecated Use oauthToken.accessToken instead
|
|
134
|
+
*/
|
|
135
|
+
accessToken?: string;
|
|
136
|
+
/**
|
|
137
|
+
* OAuth refresh token for obtaining new access tokens
|
|
138
|
+
* @description Optional for OAuth method, enables automatic token refresh
|
|
139
|
+
* @deprecated Use oauthToken.refreshToken instead
|
|
140
|
+
*/
|
|
141
|
+
refreshToken?: string;
|
|
142
|
+
/**
|
|
143
|
+
* Token expiry timestamp in milliseconds (Unix epoch)
|
|
144
|
+
* @description Used to determine when access token needs to be refreshed
|
|
145
|
+
* @deprecated Use oauthToken.expiresAt instead
|
|
146
|
+
*/
|
|
147
|
+
tokenExpiry?: number;
|
|
148
|
+
/**
|
|
149
|
+
* User's subscription tier
|
|
150
|
+
* @description Determines rate limits, features, and capabilities available
|
|
151
|
+
*/
|
|
152
|
+
subscriptionTier?: ClaudeSubscriptionTier;
|
|
153
|
+
/**
|
|
154
|
+
* Whether to automatically refresh OAuth tokens
|
|
155
|
+
* @description When true, tokens will be refreshed before expiry
|
|
156
|
+
*/
|
|
157
|
+
autoRefresh?: boolean;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Subscription information for Claude API access
|
|
161
|
+
*
|
|
162
|
+
* @description Contains subscription tier and related metadata
|
|
163
|
+
* for providers that support subscription-based access
|
|
164
|
+
*/
|
|
165
|
+
export type SubscriptionInfo = {
|
|
166
|
+
/**
|
|
167
|
+
* The subscription tier
|
|
168
|
+
*/
|
|
169
|
+
tier: ClaudeSubscriptionTier;
|
|
170
|
+
/**
|
|
171
|
+
* Whether the subscription is active
|
|
172
|
+
*/
|
|
173
|
+
isActive: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Subscription start date (ISO 8601 timestamp)
|
|
176
|
+
*/
|
|
177
|
+
startDate?: string;
|
|
178
|
+
/**
|
|
179
|
+
* Subscription renewal date (ISO 8601 timestamp)
|
|
180
|
+
*/
|
|
181
|
+
renewalDate?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Current rate limit information
|
|
184
|
+
*/
|
|
185
|
+
rateLimit?: AnthropicRateLimitInfo;
|
|
186
|
+
/**
|
|
187
|
+
* Features available with this subscription
|
|
188
|
+
*/
|
|
189
|
+
features?: SubscriptionFeatures;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Claude quota information for tracking usage limits
|
|
193
|
+
*
|
|
194
|
+
* @description Represents the quota limits for a Claude subscription,
|
|
195
|
+
* including message limits, token limits, and model access restrictions.
|
|
196
|
+
*/
|
|
197
|
+
export type ClaudeQuotaInfo = {
|
|
198
|
+
/**
|
|
199
|
+
* Maximum messages allowed per time period
|
|
200
|
+
* @description Number of messages the user can send within the reset period
|
|
201
|
+
*/
|
|
202
|
+
maxMessagesPerPeriod: number;
|
|
203
|
+
/**
|
|
204
|
+
* Maximum tokens allowed per time period
|
|
205
|
+
* @description Total tokens (input + output) allowed within the reset period
|
|
206
|
+
*/
|
|
207
|
+
maxTokensPerPeriod: number;
|
|
208
|
+
/**
|
|
209
|
+
* Maximum tokens per individual request
|
|
210
|
+
* @description Limit on tokens for a single API request
|
|
211
|
+
*/
|
|
212
|
+
maxTokensPerRequest: number;
|
|
213
|
+
/**
|
|
214
|
+
* Time period for quota reset in milliseconds
|
|
215
|
+
* @description Duration after which quota counters reset (e.g., 3600000 for 1 hour)
|
|
216
|
+
*/
|
|
217
|
+
resetPeriodMs: number;
|
|
218
|
+
/**
|
|
219
|
+
* Timestamp when quota will reset (Unix epoch in milliseconds)
|
|
220
|
+
* @description Next quota reset time
|
|
221
|
+
*/
|
|
222
|
+
nextResetTimestamp: number;
|
|
223
|
+
/**
|
|
224
|
+
* List of models accessible with current subscription
|
|
225
|
+
* @description Model identifiers the user has access to based on tier
|
|
226
|
+
*/
|
|
227
|
+
availableModels: string[];
|
|
228
|
+
/**
|
|
229
|
+
* Whether priority queue access is enabled
|
|
230
|
+
* @description Priority access reduces wait times during high traffic
|
|
231
|
+
*/
|
|
232
|
+
hasPriorityAccess: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Maximum concurrent requests allowed
|
|
235
|
+
* @description Number of simultaneous API requests permitted
|
|
236
|
+
*/
|
|
237
|
+
maxConcurrentRequests: number;
|
|
238
|
+
/**
|
|
239
|
+
* Whether extended thinking is available
|
|
240
|
+
* @description Access to extended thinking/reasoning capabilities
|
|
241
|
+
*/
|
|
242
|
+
hasExtendedThinking: boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Maximum context window size in tokens
|
|
245
|
+
* @description Maximum context length supported for the subscription tier
|
|
246
|
+
*/
|
|
247
|
+
maxContextWindow: number;
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* Claude usage information for tracking current consumption
|
|
251
|
+
*
|
|
252
|
+
* @description Represents the current usage state within a billing period,
|
|
253
|
+
* tracking messages sent, tokens consumed, and remaining quotas.
|
|
254
|
+
*/
|
|
255
|
+
export type ClaudeUsageInfo = {
|
|
256
|
+
/**
|
|
257
|
+
* Messages sent in current period
|
|
258
|
+
* @description Count of messages sent since last quota reset
|
|
259
|
+
*/
|
|
260
|
+
messagesUsed: number;
|
|
261
|
+
/**
|
|
262
|
+
* Messages remaining in current period
|
|
263
|
+
* @description Calculated as maxMessagesPerPeriod - messagesUsed
|
|
264
|
+
*/
|
|
265
|
+
messagesRemaining: number;
|
|
266
|
+
/**
|
|
267
|
+
* Tokens consumed in current period
|
|
268
|
+
* @description Total tokens (input + output) used since last reset
|
|
269
|
+
*/
|
|
270
|
+
tokensUsed: number;
|
|
271
|
+
/**
|
|
272
|
+
* Tokens remaining in current period
|
|
273
|
+
* @description Calculated as maxTokensPerPeriod - tokensUsed
|
|
274
|
+
*/
|
|
275
|
+
tokensRemaining: number;
|
|
276
|
+
/**
|
|
277
|
+
* Input tokens consumed in current period
|
|
278
|
+
* @description Prompt/input tokens used since last reset
|
|
279
|
+
*/
|
|
280
|
+
inputTokensUsed: number;
|
|
281
|
+
/**
|
|
282
|
+
* Output tokens consumed in current period
|
|
283
|
+
* @description Response/output tokens used since last reset
|
|
284
|
+
*/
|
|
285
|
+
outputTokensUsed: number;
|
|
286
|
+
/**
|
|
287
|
+
* Timestamp of last API request (Unix epoch in milliseconds)
|
|
288
|
+
* @description When the last successful request was made
|
|
289
|
+
*/
|
|
290
|
+
lastRequestTimestamp: number;
|
|
291
|
+
/**
|
|
292
|
+
* Current rate limit status
|
|
293
|
+
* @description Whether the user is currently rate limited
|
|
294
|
+
*/
|
|
295
|
+
isRateLimited: boolean;
|
|
296
|
+
/**
|
|
297
|
+
* Timestamp when rate limit expires (Unix epoch in milliseconds)
|
|
298
|
+
* @description When rate limiting will be lifted, if applicable
|
|
299
|
+
*/
|
|
300
|
+
rateLimitExpiresAt?: number;
|
|
301
|
+
/**
|
|
302
|
+
* Total requests made in current period
|
|
303
|
+
* @description Count of all API requests since last reset
|
|
304
|
+
*/
|
|
305
|
+
requestCount: number;
|
|
306
|
+
/**
|
|
307
|
+
* Usage percentage of message quota
|
|
308
|
+
* @description Percentage of message quota consumed (0-100)
|
|
309
|
+
*/
|
|
310
|
+
messageQuotaPercent: number;
|
|
311
|
+
/**
|
|
312
|
+
* Usage percentage of token quota
|
|
313
|
+
* @description Percentage of token quota consumed (0-100)
|
|
314
|
+
*/
|
|
315
|
+
tokenQuotaPercent: number;
|
|
316
|
+
};
|
|
317
|
+
/**
|
|
318
|
+
* Subscription features defining capabilities per tier
|
|
319
|
+
*
|
|
320
|
+
* @description Defines what features and capabilities are available
|
|
321
|
+
* for each subscription tier. Used to determine access to specific
|
|
322
|
+
* functionality and feature gating.
|
|
323
|
+
*/
|
|
324
|
+
export type SubscriptionFeatures = {
|
|
325
|
+
/**
|
|
326
|
+
* Subscription tier this feature set belongs to
|
|
327
|
+
*/
|
|
328
|
+
tier: ClaudeSubscriptionTier;
|
|
329
|
+
/**
|
|
330
|
+
* Whether chat/conversation access is enabled
|
|
331
|
+
* @description Basic chat functionality with Claude
|
|
332
|
+
*/
|
|
333
|
+
hasChat: boolean;
|
|
334
|
+
/**
|
|
335
|
+
* Whether API access is enabled
|
|
336
|
+
* @description Programmatic access to Claude via API
|
|
337
|
+
*/
|
|
338
|
+
hasApiAccess: boolean;
|
|
339
|
+
/**
|
|
340
|
+
* Whether extended thinking/reasoning is enabled
|
|
341
|
+
* @description Access to extended thinking capabilities for complex reasoning
|
|
342
|
+
*/
|
|
343
|
+
hasExtendedThinking: boolean;
|
|
344
|
+
/**
|
|
345
|
+
* Whether priority queue access is enabled
|
|
346
|
+
* @description Faster response times during high traffic periods
|
|
347
|
+
*/
|
|
348
|
+
hasPriorityAccess: boolean;
|
|
349
|
+
/**
|
|
350
|
+
* Whether vision/image analysis is enabled
|
|
351
|
+
* @description Ability to analyze images and visual content
|
|
352
|
+
*/
|
|
353
|
+
hasVision: boolean;
|
|
354
|
+
/**
|
|
355
|
+
* Whether file/document analysis is enabled
|
|
356
|
+
* @description Ability to process PDFs, documents, and other files
|
|
357
|
+
*/
|
|
358
|
+
hasFileAnalysis: boolean;
|
|
359
|
+
/**
|
|
360
|
+
* Whether code execution is enabled
|
|
361
|
+
* @description Access to code execution/analysis features
|
|
362
|
+
*/
|
|
363
|
+
hasCodeExecution: boolean;
|
|
364
|
+
/**
|
|
365
|
+
* Whether MCP (Model Context Protocol) tools are enabled
|
|
366
|
+
* @description Access to external tool integrations via MCP
|
|
367
|
+
*/
|
|
368
|
+
hasMcpTools: boolean;
|
|
369
|
+
/**
|
|
370
|
+
* Whether computer use capability is enabled
|
|
371
|
+
* @description Access to computer use/automation features
|
|
372
|
+
*/
|
|
373
|
+
hasComputerUse: boolean;
|
|
374
|
+
/**
|
|
375
|
+
* Whether web search is enabled
|
|
376
|
+
* @description Access to web search capabilities
|
|
377
|
+
*/
|
|
378
|
+
hasWebSearch: boolean;
|
|
379
|
+
/**
|
|
380
|
+
* Maximum context window size in tokens
|
|
381
|
+
* @description Limit on context/conversation length
|
|
382
|
+
*/
|
|
383
|
+
maxContextWindow: number;
|
|
384
|
+
/**
|
|
385
|
+
* Maximum output tokens per request
|
|
386
|
+
* @description Limit on response length per request
|
|
387
|
+
*/
|
|
388
|
+
maxOutputTokens: number;
|
|
389
|
+
/**
|
|
390
|
+
* List of accessible model identifiers
|
|
391
|
+
* @description Which Claude models are available for this tier
|
|
392
|
+
*/
|
|
393
|
+
availableModels: string[];
|
|
394
|
+
/**
|
|
395
|
+
* Daily message limit
|
|
396
|
+
* @description Maximum messages per day, -1 for unlimited
|
|
397
|
+
*/
|
|
398
|
+
dailyMessageLimit: number;
|
|
399
|
+
/**
|
|
400
|
+
* Monthly token limit
|
|
401
|
+
* @description Maximum tokens per month, -1 for unlimited
|
|
402
|
+
*/
|
|
403
|
+
monthlyTokenLimit: number;
|
|
404
|
+
/**
|
|
405
|
+
* Whether usage analytics are available
|
|
406
|
+
* @description Access to detailed usage statistics and analytics
|
|
407
|
+
*/
|
|
408
|
+
hasUsageAnalytics: boolean;
|
|
409
|
+
/**
|
|
410
|
+
* Whether team/organization features are enabled
|
|
411
|
+
* @description Access to team management and collaboration features
|
|
412
|
+
*/
|
|
413
|
+
hasTeamFeatures: boolean;
|
|
414
|
+
/**
|
|
415
|
+
* Custom feature flags for extensibility
|
|
416
|
+
* @description Additional feature flags for future capabilities
|
|
417
|
+
*/
|
|
418
|
+
customFeatures?: Record<string, boolean>;
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* Subscription tier comparison result
|
|
422
|
+
*
|
|
423
|
+
* @description Result of comparing two subscription tiers
|
|
424
|
+
*/
|
|
425
|
+
export type TierComparisonResult = {
|
|
426
|
+
/** Whether the first tier is higher than the second */
|
|
427
|
+
isHigher: boolean;
|
|
428
|
+
/** Whether the first tier is lower than the second */
|
|
429
|
+
isLower: boolean;
|
|
430
|
+
/** Whether the tiers are equal */
|
|
431
|
+
isEqual: boolean;
|
|
432
|
+
/** Numeric difference between tier levels (positive = first is higher) */
|
|
433
|
+
levelDifference: number;
|
|
434
|
+
};
|
|
435
|
+
/**
|
|
436
|
+
* Authentication state for tracking auth status
|
|
437
|
+
*
|
|
438
|
+
* @description Represents the current authentication state
|
|
439
|
+
*/
|
|
440
|
+
export type AuthenticationState = {
|
|
441
|
+
/** Whether the user is authenticated */
|
|
442
|
+
isAuthenticated: boolean;
|
|
443
|
+
/** Current authentication method in use */
|
|
444
|
+
method?: AnthropicAuthMethod;
|
|
445
|
+
/** Current subscription tier */
|
|
446
|
+
tier?: ClaudeSubscriptionTier;
|
|
447
|
+
/** Whether tokens need to be refreshed */
|
|
448
|
+
needsRefresh: boolean;
|
|
449
|
+
/** Error message if authentication failed */
|
|
450
|
+
error?: string;
|
|
451
|
+
/** Timestamp of last successful authentication */
|
|
452
|
+
lastAuthenticatedAt?: number;
|
|
453
|
+
};
|
|
454
|
+
/**
|
|
455
|
+
* Quota check result for determining if an operation can proceed
|
|
456
|
+
*
|
|
457
|
+
* @description Result of checking whether quota allows an operation
|
|
458
|
+
*/
|
|
459
|
+
export type QuotaCheckResult = {
|
|
460
|
+
/** Whether the operation is allowed within quota */
|
|
461
|
+
allowed: boolean;
|
|
462
|
+
/** Reason if operation is not allowed */
|
|
463
|
+
reason?: string;
|
|
464
|
+
/** Estimated tokens required for the operation */
|
|
465
|
+
estimatedTokens?: number;
|
|
466
|
+
/** Tokens remaining after operation (if allowed) */
|
|
467
|
+
tokensRemainingAfter?: number;
|
|
468
|
+
/** Suggested wait time in ms if rate limited */
|
|
469
|
+
suggestedWaitMs?: number;
|
|
470
|
+
};
|
|
471
|
+
/**
|
|
472
|
+
* OAuth tokens structure for Claude subscription authentication
|
|
473
|
+
*
|
|
474
|
+
* @description Contains OAuth token information for authenticated sessions.
|
|
475
|
+
* This is the preferred type for OAuth token storage.
|
|
476
|
+
*/
|
|
477
|
+
export type OAuthTokens = {
|
|
478
|
+
/**
|
|
479
|
+
* The access token for API requests
|
|
480
|
+
*/
|
|
481
|
+
accessToken: string;
|
|
482
|
+
/**
|
|
483
|
+
* The refresh token for obtaining new access tokens
|
|
484
|
+
*/
|
|
485
|
+
refreshToken?: string;
|
|
486
|
+
/**
|
|
487
|
+
* Token expiration timestamp (Unix epoch in seconds or milliseconds)
|
|
488
|
+
*/
|
|
489
|
+
expiresAt?: number;
|
|
490
|
+
/**
|
|
491
|
+
* Token type (typically "Bearer")
|
|
492
|
+
*/
|
|
493
|
+
tokenType?: string;
|
|
494
|
+
/**
|
|
495
|
+
* OAuth scopes granted to this token
|
|
496
|
+
*/
|
|
497
|
+
scope?: string;
|
|
498
|
+
};
|
|
499
|
+
/**
|
|
500
|
+
* OAuth configuration for Claude subscription authentication
|
|
501
|
+
*
|
|
502
|
+
* @description Configuration for OAuth 2.0 authentication flow with Claude/Anthropic.
|
|
503
|
+
* Used to configure the OAuth client for subscription-based access.
|
|
504
|
+
*/
|
|
505
|
+
export type OAuthConfig = {
|
|
506
|
+
/**
|
|
507
|
+
* OAuth client ID for the application
|
|
508
|
+
* @description Obtained from Anthropic developer console
|
|
509
|
+
*/
|
|
510
|
+
clientId: string;
|
|
511
|
+
/**
|
|
512
|
+
* OAuth redirect URI for the callback
|
|
513
|
+
* @description Must match the registered redirect URI in Anthropic console
|
|
514
|
+
*/
|
|
515
|
+
redirectUri: string;
|
|
516
|
+
/**
|
|
517
|
+
* OAuth scopes to request
|
|
518
|
+
* @description Array of scope strings defining requested permissions
|
|
519
|
+
*/
|
|
520
|
+
scopes: string[];
|
|
521
|
+
/**
|
|
522
|
+
* OAuth client secret (optional, for confidential clients)
|
|
523
|
+
* @description Only used for server-side OAuth flows
|
|
524
|
+
*/
|
|
525
|
+
clientSecret?: string;
|
|
526
|
+
/**
|
|
527
|
+
* OAuth authorization endpoint URL
|
|
528
|
+
* @description Anthropic's OAuth authorization URL
|
|
529
|
+
*/
|
|
530
|
+
authorizationEndpoint?: string;
|
|
531
|
+
/**
|
|
532
|
+
* OAuth token endpoint URL
|
|
533
|
+
* @description Anthropic's OAuth token exchange URL
|
|
534
|
+
*/
|
|
535
|
+
tokenEndpoint?: string;
|
|
536
|
+
/**
|
|
537
|
+
* PKCE code verifier (for public clients)
|
|
538
|
+
* @description Used with PKCE flow for enhanced security
|
|
539
|
+
*/
|
|
540
|
+
codeVerifier?: string;
|
|
541
|
+
/**
|
|
542
|
+
* State parameter for CSRF protection
|
|
543
|
+
* @description Random string to prevent CSRF attacks
|
|
544
|
+
*/
|
|
545
|
+
state?: string;
|
|
546
|
+
};
|
|
547
|
+
/**
|
|
548
|
+
* Usage quota for tracking Claude subscription usage
|
|
549
|
+
*
|
|
550
|
+
* @description Simplified quota tracking structure for monitoring
|
|
551
|
+
* subscription usage against limits. Used for real-time quota monitoring.
|
|
552
|
+
*/
|
|
553
|
+
export type UsageQuota = {
|
|
554
|
+
/**
|
|
555
|
+
* Current subscription tier
|
|
556
|
+
*/
|
|
557
|
+
tier: ClaudeSubscriptionTier;
|
|
558
|
+
/**
|
|
559
|
+
* Daily tokens used in current period
|
|
560
|
+
*/
|
|
561
|
+
dailyTokensUsed: number;
|
|
562
|
+
/**
|
|
563
|
+
* Daily token limit for current tier
|
|
564
|
+
*/
|
|
565
|
+
dailyTokensLimit: number;
|
|
566
|
+
/**
|
|
567
|
+
* Messages used in current period
|
|
568
|
+
*/
|
|
569
|
+
messagesUsed: number;
|
|
570
|
+
/**
|
|
571
|
+
* Message limit for current tier
|
|
572
|
+
*/
|
|
573
|
+
messagesLimit: number;
|
|
574
|
+
/**
|
|
575
|
+
* Time when usage counters will reset
|
|
576
|
+
*/
|
|
577
|
+
resetTime: Date;
|
|
578
|
+
/**
|
|
579
|
+
* Current requests used in rate limit window
|
|
580
|
+
*/
|
|
581
|
+
requestsUsed?: number;
|
|
582
|
+
/**
|
|
583
|
+
* Request limit for rate limit window
|
|
584
|
+
*/
|
|
585
|
+
requestsLimit?: number;
|
|
586
|
+
/**
|
|
587
|
+
* Whether quota is currently exceeded
|
|
588
|
+
*/
|
|
589
|
+
isExceeded?: boolean;
|
|
590
|
+
/**
|
|
591
|
+
* Percentage of quota used (0-100)
|
|
592
|
+
*/
|
|
593
|
+
usagePercent?: number;
|
|
594
|
+
};
|
|
595
|
+
/**
|
|
596
|
+
* Anthropic beta feature flags for beta header configuration
|
|
597
|
+
*
|
|
598
|
+
* @description Defines available beta features that can be enabled via
|
|
599
|
+
* the anthropic-beta header. Each feature enables specific beta functionality.
|
|
600
|
+
*
|
|
601
|
+
* @see https://docs.anthropic.com/en/api/versioning#beta-headers
|
|
602
|
+
*/
|
|
603
|
+
export type AnthropicBetaFeatures = {
|
|
604
|
+
/**
|
|
605
|
+
* Enable computer use capability
|
|
606
|
+
* @description Allows Claude to interact with computer interfaces
|
|
607
|
+
* Header value: "computer-use-2024-10-22"
|
|
608
|
+
*/
|
|
609
|
+
computerUse?: boolean;
|
|
610
|
+
/**
|
|
611
|
+
* Enable extended thinking/reasoning
|
|
612
|
+
* @description Allows extended thinking for complex reasoning tasks
|
|
613
|
+
* Header value: "extended-thinking-2025-01-24"
|
|
614
|
+
*/
|
|
615
|
+
extendedThinking?: boolean;
|
|
616
|
+
/**
|
|
617
|
+
* Enable prompt caching
|
|
618
|
+
* @description Allows caching of prompts for reduced latency
|
|
619
|
+
* Header value: "prompt-caching-2024-07-31"
|
|
620
|
+
*/
|
|
621
|
+
promptCaching?: boolean;
|
|
622
|
+
/**
|
|
623
|
+
* Enable token counting
|
|
624
|
+
* @description Allows pre-counting tokens before generation
|
|
625
|
+
* Header value: "token-counting-2024-11-01"
|
|
626
|
+
*/
|
|
627
|
+
tokenCounting?: boolean;
|
|
628
|
+
/**
|
|
629
|
+
* Enable message batches
|
|
630
|
+
* @description Allows batch processing of multiple messages
|
|
631
|
+
* Header value: "message-batches-2024-09-24"
|
|
632
|
+
*/
|
|
633
|
+
messageBatches?: boolean;
|
|
634
|
+
/**
|
|
635
|
+
* Enable PDF support
|
|
636
|
+
* @description Allows processing PDF documents
|
|
637
|
+
* Header value: "pdfs-2024-09-25"
|
|
638
|
+
*/
|
|
639
|
+
pdfs?: boolean;
|
|
640
|
+
/**
|
|
641
|
+
* Enable max tokens override (for higher output limits)
|
|
642
|
+
* @description Allows requesting more output tokens than default
|
|
643
|
+
* Header value: "max-tokens-3-5-sonnet-2024-07-15"
|
|
644
|
+
*/
|
|
645
|
+
maxTokensOverride?: boolean;
|
|
646
|
+
/**
|
|
647
|
+
* Enable interleaved thinking (for multi-turn reasoning)
|
|
648
|
+
* @description Allows interleaved thinking in conversations
|
|
649
|
+
* Header value: "interleaved-thinking-2025-01-24"
|
|
650
|
+
*/
|
|
651
|
+
interleavedThinking?: boolean;
|
|
652
|
+
/**
|
|
653
|
+
* Enable files API
|
|
654
|
+
* @description Allows using the Files API for document processing
|
|
655
|
+
* Header value: "files-api-2025-01-15"
|
|
656
|
+
*/
|
|
657
|
+
filesApi?: boolean;
|
|
658
|
+
/**
|
|
659
|
+
* Enable MCP connectors
|
|
660
|
+
* @description Allows using MCP connectors for tool integrations
|
|
661
|
+
* Header value: "mcp-connectors-2025-01-01"
|
|
662
|
+
*/
|
|
663
|
+
mcpConnectors?: boolean;
|
|
664
|
+
/**
|
|
665
|
+
* Enable code execution
|
|
666
|
+
* @description Allows Claude to execute code
|
|
667
|
+
* Header value: "code-execution-2025-01-24"
|
|
668
|
+
*/
|
|
669
|
+
codeExecution?: boolean;
|
|
670
|
+
/**
|
|
671
|
+
* Custom beta features as raw strings
|
|
672
|
+
* @description For beta features not yet added to this type
|
|
673
|
+
*/
|
|
674
|
+
custom?: string[];
|
|
675
|
+
};
|
|
676
|
+
/**
|
|
677
|
+
* Anthropic beta header string values
|
|
678
|
+
*
|
|
679
|
+
* @description The actual string values used in the anthropic-beta header.
|
|
680
|
+
* Use AnthropicBetaFeatures for configuration, this is for internal use.
|
|
681
|
+
*/
|
|
682
|
+
export type AnthropicBetaHeader = "computer-use-2024-10-22" | "extended-thinking-2025-01-24" | "prompt-caching-2024-07-31" | "token-counting-2024-11-01" | "message-batches-2024-09-24" | "pdfs-2024-09-25" | "max-tokens-3-5-sonnet-2024-07-15" | "interleaved-thinking-2025-01-24" | "files-api-2025-01-15" | "mcp-connectors-2025-01-01" | "code-execution-2025-01-24" | string;
|
|
683
|
+
/**
|
|
684
|
+
* Subscription information summary for display purposes
|
|
685
|
+
*
|
|
686
|
+
* @description Extended subscription information including human-readable
|
|
687
|
+
* tier descriptions and usage data. Use for UI display and status reporting.
|
|
688
|
+
* For basic subscription state, see SubscriptionInfo.
|
|
689
|
+
*/
|
|
690
|
+
export type SubscriptionInfoSummary = {
|
|
691
|
+
/** Current subscription tier */
|
|
692
|
+
tier: ClaudeSubscriptionTier;
|
|
693
|
+
/** Human-readable tier name */
|
|
694
|
+
tierName: string;
|
|
695
|
+
/** Human-readable tier description */
|
|
696
|
+
description: string;
|
|
697
|
+
/** Messages allowed per day (-1 for unlimited) */
|
|
698
|
+
messagesPerDay: number | "unlimited";
|
|
699
|
+
/** Maximum context window size in tokens */
|
|
700
|
+
contextWindow: number;
|
|
701
|
+
/** Whether the user has priority access */
|
|
702
|
+
priorityAccess: boolean;
|
|
703
|
+
/** Whether the subscription is active */
|
|
704
|
+
isActive: boolean;
|
|
705
|
+
/** Subscription expiration date (if applicable) */
|
|
706
|
+
expiresAt?: number;
|
|
707
|
+
/** Current usage information */
|
|
708
|
+
usage?: ClaudeUsageInfo;
|
|
709
|
+
/** Available features for this tier */
|
|
710
|
+
features?: SubscriptionFeatures;
|
|
711
|
+
};
|
|
712
|
+
/**
|
|
713
|
+
* OAuth 2.0 token response from Anthropic (raw API response shape)
|
|
714
|
+
*/
|
|
715
|
+
export interface OAuthTokenResponse {
|
|
716
|
+
/** The access token for API authentication */
|
|
717
|
+
access_token: string;
|
|
718
|
+
/** Token type (typically "Bearer") */
|
|
719
|
+
token_type: string;
|
|
720
|
+
/** Token expiration time in seconds */
|
|
721
|
+
expires_in: number;
|
|
722
|
+
/** Refresh token for obtaining new access tokens */
|
|
723
|
+
refresh_token?: string;
|
|
724
|
+
/** Granted scopes (space-separated) */
|
|
725
|
+
scope?: string;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Parsed OAuth tokens from a fresh OAuth flow.
|
|
729
|
+
* Uses Date for expiresAt (vs number in OAuthTokens for storage).
|
|
730
|
+
*/
|
|
731
|
+
export interface OAuthFlowTokens {
|
|
732
|
+
/** The access token for API authentication */
|
|
733
|
+
accessToken: string;
|
|
734
|
+
/** Token type (typically "Bearer") */
|
|
735
|
+
tokenType: string;
|
|
736
|
+
/** Expiration timestamp (Date object) */
|
|
737
|
+
expiresAt: Date;
|
|
738
|
+
/** Refresh token for obtaining new access tokens */
|
|
739
|
+
refreshToken?: string;
|
|
740
|
+
/** Granted scopes as an array */
|
|
741
|
+
scopes: string[];
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Token validation result
|
|
745
|
+
*/
|
|
746
|
+
export interface TokenValidationResult {
|
|
747
|
+
/** Whether the token is valid */
|
|
748
|
+
isValid: boolean;
|
|
749
|
+
/** Remaining time in seconds until expiration */
|
|
750
|
+
expiresIn?: number;
|
|
751
|
+
/** Scopes associated with the token */
|
|
752
|
+
scopes?: string[];
|
|
753
|
+
/** User information if available */
|
|
754
|
+
user?: {
|
|
755
|
+
id: string;
|
|
756
|
+
email?: string;
|
|
757
|
+
subscription?: string;
|
|
758
|
+
};
|
|
759
|
+
/** Error message if validation failed */
|
|
760
|
+
error?: string;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* OAuth configuration options for AnthropicOAuth class
|
|
764
|
+
*/
|
|
765
|
+
export interface AnthropicOAuthConfig {
|
|
766
|
+
/** OAuth client ID (optional, uses env var if not provided) */
|
|
767
|
+
clientId?: string;
|
|
768
|
+
/** OAuth client secret (optional, for confidential clients) */
|
|
769
|
+
clientSecret?: string;
|
|
770
|
+
/** Redirect URI for OAuth callback */
|
|
771
|
+
redirectUri?: string;
|
|
772
|
+
/** OAuth scopes to request */
|
|
773
|
+
scopes?: string[];
|
|
774
|
+
/** Custom authorization endpoint URL */
|
|
775
|
+
authorizationUrl?: string;
|
|
776
|
+
/** Custom token endpoint URL */
|
|
777
|
+
tokenUrl?: string;
|
|
778
|
+
/** Custom token validation endpoint URL */
|
|
779
|
+
validationUrl?: string;
|
|
780
|
+
/** Custom token revocation endpoint URL */
|
|
781
|
+
revocationUrl?: string;
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* PKCE (Proof Key for Code Exchange) parameters
|
|
785
|
+
*/
|
|
786
|
+
export interface PKCEParams {
|
|
787
|
+
/** Code verifier - random string used to generate challenge */
|
|
788
|
+
codeVerifier: string;
|
|
789
|
+
/** Code challenge - SHA-256 hash of verifier, base64url encoded */
|
|
790
|
+
codeChallenge: string;
|
|
791
|
+
/** Code challenge method - always "S256" */
|
|
792
|
+
codeChallengeMethod: "S256";
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Callback server result containing the authorization code
|
|
796
|
+
*/
|
|
797
|
+
export interface CallbackResult {
|
|
798
|
+
/** Authorization code from OAuth callback */
|
|
799
|
+
code: string;
|
|
800
|
+
/** State parameter for CSRF verification */
|
|
801
|
+
state?: string;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Anthropic authentication configuration result for providerConfig
|
|
805
|
+
* Extended version with OAuth token details for configuration detection
|
|
806
|
+
*/
|
|
807
|
+
export type AnthropicAuthConfigResult = {
|
|
808
|
+
method: AnthropicAuthMethod;
|
|
809
|
+
tier: ClaudeSubscriptionTier;
|
|
810
|
+
apiKey?: string;
|
|
811
|
+
accessToken?: string;
|
|
812
|
+
refreshToken?: string;
|
|
813
|
+
isConfigured: boolean;
|
|
814
|
+
error?: string;
|
|
815
|
+
};
|
|
816
|
+
/**
|
|
817
|
+
* Unified authentication options for NeuroLink
|
|
818
|
+
*
|
|
819
|
+
* Supports both direct API key authentication and OAuth-based authentication
|
|
820
|
+
* for Claude Pro/Max subscriptions.
|
|
821
|
+
*/
|
|
822
|
+
export interface NeuroLinkAuthOptions {
|
|
823
|
+
/**
|
|
824
|
+
* Authentication method to use
|
|
825
|
+
* - "api-key": Use ANTHROPIC_API_KEY environment variable
|
|
826
|
+
* - "oauth": Use OAuth 2.0 flow for Claude Pro/Max subscriptions
|
|
827
|
+
*/
|
|
828
|
+
method: "api-key" | "oauth";
|
|
829
|
+
/**
|
|
830
|
+
* OAuth configuration (required when method is "oauth")
|
|
831
|
+
*/
|
|
832
|
+
oauth?: {
|
|
833
|
+
/** OAuth client ID */
|
|
834
|
+
clientId?: string;
|
|
835
|
+
/** OAuth redirect URI */
|
|
836
|
+
redirectUri?: string;
|
|
837
|
+
/** Custom scopes to request */
|
|
838
|
+
scopes?: string[];
|
|
839
|
+
};
|
|
840
|
+
/**
|
|
841
|
+
* Token storage configuration (optional, defaults to file-based storage)
|
|
842
|
+
*/
|
|
843
|
+
tokenStorage?: {
|
|
844
|
+
/** Enable encryption for stored tokens */
|
|
845
|
+
encryptionEnabled?: boolean;
|
|
846
|
+
/** Custom storage path */
|
|
847
|
+
customStoragePath?: string;
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Authentication status result
|
|
852
|
+
*/
|
|
853
|
+
export interface AuthStatus {
|
|
854
|
+
/** Whether the user is authenticated */
|
|
855
|
+
isAuthenticated: boolean;
|
|
856
|
+
/** Authentication method in use */
|
|
857
|
+
method: "api-key" | "oauth" | "none";
|
|
858
|
+
/** Token expiration time (for OAuth) */
|
|
859
|
+
expiresAt?: Date;
|
|
860
|
+
/** Whether token refresh is needed (for OAuth) */
|
|
861
|
+
needsRefresh?: boolean;
|
|
862
|
+
/** User information (for OAuth) */
|
|
863
|
+
user?: {
|
|
864
|
+
id?: string;
|
|
865
|
+
email?: string;
|
|
866
|
+
subscription?: string;
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Model metadata definition for Anthropic models
|
|
871
|
+
*/
|
|
872
|
+
export interface AnthropicModelMetadata {
|
|
873
|
+
/** Human-readable display name */
|
|
874
|
+
displayName: string;
|
|
875
|
+
/** Maximum context window size in tokens */
|
|
876
|
+
contextWindow: number;
|
|
877
|
+
/** Maximum output tokens */
|
|
878
|
+
maxOutputTokens: number;
|
|
879
|
+
/** Whether the model supports vision/image input */
|
|
880
|
+
supportsVision: boolean;
|
|
881
|
+
/** Whether the model supports extended thinking mode */
|
|
882
|
+
supportsExtendedThinking: boolean;
|
|
883
|
+
/** Whether the model supports tool/function calling */
|
|
884
|
+
supportsToolUse: boolean;
|
|
885
|
+
/** Whether the model supports streaming */
|
|
886
|
+
supportsStreaming: boolean;
|
|
887
|
+
/** Whether the model is deprecated */
|
|
888
|
+
deprecated: boolean;
|
|
889
|
+
/** Model family (haiku, sonnet, opus) */
|
|
890
|
+
family: "haiku" | "sonnet" | "opus";
|
|
891
|
+
/** Short description of the model */
|
|
892
|
+
description: string;
|
|
893
|
+
}
|