@juspay/neurolink 9.14.0 → 9.16.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.
Files changed (241) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +15 -15
  3. package/dist/adapters/video/videoAnalyzer.d.ts +1 -1
  4. package/dist/adapters/video/videoAnalyzer.js +10 -8
  5. package/dist/auth/anthropicOAuth.d.ts +377 -0
  6. package/dist/auth/anthropicOAuth.js +914 -0
  7. package/dist/auth/index.d.ts +20 -0
  8. package/dist/auth/index.js +29 -0
  9. package/dist/auth/tokenStore.d.ts +225 -0
  10. package/dist/auth/tokenStore.js +521 -0
  11. package/dist/cli/commands/auth.d.ts +50 -0
  12. package/dist/cli/commands/auth.js +1115 -0
  13. package/dist/cli/commands/setup-anthropic.js +1 -14
  14. package/dist/cli/commands/setup-azure.js +1 -12
  15. package/dist/cli/commands/setup-bedrock.js +1 -9
  16. package/dist/cli/commands/setup-google-ai.js +1 -12
  17. package/dist/cli/commands/setup-openai.js +1 -14
  18. package/dist/cli/commands/workflow.d.ts +27 -0
  19. package/dist/cli/commands/workflow.js +216 -0
  20. package/dist/cli/factories/authCommandFactory.d.ts +52 -0
  21. package/dist/cli/factories/authCommandFactory.js +146 -0
  22. package/dist/cli/factories/commandFactory.d.ts +6 -0
  23. package/dist/cli/factories/commandFactory.js +171 -22
  24. package/dist/cli/index.js +0 -1
  25. package/dist/cli/parser.js +14 -2
  26. package/dist/cli/utils/maskCredential.d.ts +11 -0
  27. package/dist/cli/utils/maskCredential.js +23 -0
  28. package/dist/constants/contextWindows.js +107 -16
  29. package/dist/constants/enums.d.ts +119 -15
  30. package/dist/constants/enums.js +182 -22
  31. package/dist/constants/index.d.ts +3 -1
  32. package/dist/constants/index.js +11 -1
  33. package/dist/context/budgetChecker.js +1 -1
  34. package/dist/context/contextCompactor.js +31 -4
  35. package/dist/context/emergencyTruncation.d.ts +21 -0
  36. package/dist/context/emergencyTruncation.js +88 -0
  37. package/dist/context/errorDetection.d.ts +16 -0
  38. package/dist/context/errorDetection.js +48 -1
  39. package/dist/context/errors.d.ts +19 -0
  40. package/dist/context/errors.js +21 -0
  41. package/dist/context/stages/slidingWindowTruncator.d.ts +6 -0
  42. package/dist/context/stages/slidingWindowTruncator.js +159 -24
  43. package/dist/core/baseProvider.js +306 -200
  44. package/dist/core/conversationMemoryManager.js +104 -61
  45. package/dist/core/evaluationProviders.js +16 -33
  46. package/dist/core/factory.js +237 -164
  47. package/dist/core/modules/GenerationHandler.js +175 -116
  48. package/dist/core/modules/MessageBuilder.js +222 -170
  49. package/dist/core/modules/StreamHandler.d.ts +1 -0
  50. package/dist/core/modules/StreamHandler.js +95 -27
  51. package/dist/core/modules/TelemetryHandler.d.ts +10 -1
  52. package/dist/core/modules/TelemetryHandler.js +25 -7
  53. package/dist/core/modules/ToolsManager.js +115 -191
  54. package/dist/core/redisConversationMemoryManager.js +418 -282
  55. package/dist/factories/providerRegistry.d.ts +5 -0
  56. package/dist/factories/providerRegistry.js +20 -2
  57. package/dist/index.d.ts +3 -3
  58. package/dist/index.js +4 -2
  59. package/dist/lib/adapters/video/videoAnalyzer.d.ts +1 -1
  60. package/dist/lib/adapters/video/videoAnalyzer.js +10 -8
  61. package/dist/lib/auth/anthropicOAuth.d.ts +377 -0
  62. package/dist/lib/auth/anthropicOAuth.js +915 -0
  63. package/dist/lib/auth/index.d.ts +20 -0
  64. package/dist/lib/auth/index.js +30 -0
  65. package/dist/lib/auth/tokenStore.d.ts +225 -0
  66. package/dist/lib/auth/tokenStore.js +522 -0
  67. package/dist/lib/constants/contextWindows.js +107 -16
  68. package/dist/lib/constants/enums.d.ts +119 -15
  69. package/dist/lib/constants/enums.js +182 -22
  70. package/dist/lib/constants/index.d.ts +3 -1
  71. package/dist/lib/constants/index.js +11 -1
  72. package/dist/lib/context/budgetChecker.js +1 -1
  73. package/dist/lib/context/contextCompactor.js +31 -4
  74. package/dist/lib/context/emergencyTruncation.d.ts +21 -0
  75. package/dist/lib/context/emergencyTruncation.js +89 -0
  76. package/dist/lib/context/errorDetection.d.ts +16 -0
  77. package/dist/lib/context/errorDetection.js +48 -1
  78. package/dist/lib/context/errors.d.ts +19 -0
  79. package/dist/lib/context/errors.js +22 -0
  80. package/dist/lib/context/stages/slidingWindowTruncator.d.ts +6 -0
  81. package/dist/lib/context/stages/slidingWindowTruncator.js +159 -24
  82. package/dist/lib/core/baseProvider.js +306 -200
  83. package/dist/lib/core/conversationMemoryManager.js +104 -61
  84. package/dist/lib/core/evaluationProviders.js +16 -33
  85. package/dist/lib/core/factory.js +237 -164
  86. package/dist/lib/core/modules/GenerationHandler.js +175 -116
  87. package/dist/lib/core/modules/MessageBuilder.js +222 -170
  88. package/dist/lib/core/modules/StreamHandler.d.ts +1 -0
  89. package/dist/lib/core/modules/StreamHandler.js +95 -27
  90. package/dist/lib/core/modules/TelemetryHandler.d.ts +10 -1
  91. package/dist/lib/core/modules/TelemetryHandler.js +25 -7
  92. package/dist/lib/core/modules/ToolsManager.js +115 -191
  93. package/dist/lib/core/redisConversationMemoryManager.js +418 -282
  94. package/dist/lib/factories/providerRegistry.d.ts +5 -0
  95. package/dist/lib/factories/providerRegistry.js +20 -2
  96. package/dist/lib/index.d.ts +3 -3
  97. package/dist/lib/index.js +4 -2
  98. package/dist/lib/mcp/externalServerManager.js +66 -0
  99. package/dist/lib/mcp/mcpCircuitBreaker.js +24 -0
  100. package/dist/lib/mcp/mcpClientFactory.js +16 -0
  101. package/dist/lib/mcp/toolDiscoveryService.js +32 -6
  102. package/dist/lib/mcp/toolRegistry.js +193 -123
  103. package/dist/lib/models/anthropicModels.d.ts +267 -0
  104. package/dist/lib/models/anthropicModels.js +528 -0
  105. package/dist/lib/neurolink.d.ts +6 -0
  106. package/dist/lib/neurolink.js +1162 -646
  107. package/dist/lib/providers/amazonBedrock.d.ts +1 -1
  108. package/dist/lib/providers/amazonBedrock.js +521 -319
  109. package/dist/lib/providers/anthropic.d.ts +123 -2
  110. package/dist/lib/providers/anthropic.js +873 -27
  111. package/dist/lib/providers/anthropicBaseProvider.js +77 -17
  112. package/dist/lib/providers/googleAiStudio.d.ts +1 -1
  113. package/dist/lib/providers/googleAiStudio.js +292 -227
  114. package/dist/lib/providers/googleVertex.d.ts +36 -1
  115. package/dist/lib/providers/googleVertex.js +553 -260
  116. package/dist/lib/providers/ollama.js +329 -278
  117. package/dist/lib/providers/openAI.js +77 -19
  118. package/dist/lib/providers/sagemaker/parsers.js +3 -3
  119. package/dist/lib/providers/sagemaker/streaming.js +3 -3
  120. package/dist/lib/proxy/proxyFetch.js +81 -48
  121. package/dist/lib/rag/ChunkerFactory.js +1 -1
  122. package/dist/lib/rag/chunkers/MarkdownChunker.d.ts +22 -0
  123. package/dist/lib/rag/chunkers/MarkdownChunker.js +213 -9
  124. package/dist/lib/rag/chunking/markdownChunker.d.ts +16 -0
  125. package/dist/lib/rag/chunking/markdownChunker.js +174 -2
  126. package/dist/lib/rag/pipeline/contextAssembly.js +2 -1
  127. package/dist/lib/rag/ragIntegration.d.ts +18 -1
  128. package/dist/lib/rag/ragIntegration.js +94 -14
  129. package/dist/lib/rag/retrieval/vectorQueryTool.js +21 -4
  130. package/dist/lib/server/abstract/baseServerAdapter.js +4 -1
  131. package/dist/lib/server/adapters/fastifyAdapter.js +35 -30
  132. package/dist/lib/services/server/ai/observability/instrumentation.d.ts +32 -0
  133. package/dist/lib/services/server/ai/observability/instrumentation.js +39 -0
  134. package/dist/lib/telemetry/attributes.d.ts +52 -0
  135. package/dist/lib/telemetry/attributes.js +61 -0
  136. package/dist/lib/telemetry/index.d.ts +3 -0
  137. package/dist/lib/telemetry/index.js +3 -0
  138. package/dist/lib/telemetry/telemetryService.d.ts +6 -0
  139. package/dist/lib/telemetry/telemetryService.js +6 -0
  140. package/dist/lib/telemetry/tracers.d.ts +15 -0
  141. package/dist/lib/telemetry/tracers.js +17 -0
  142. package/dist/lib/telemetry/withSpan.d.ts +9 -0
  143. package/dist/lib/telemetry/withSpan.js +35 -0
  144. package/dist/lib/types/contextTypes.d.ts +10 -0
  145. package/dist/lib/types/errors.d.ts +62 -0
  146. package/dist/lib/types/errors.js +107 -0
  147. package/dist/lib/types/index.d.ts +2 -1
  148. package/dist/lib/types/index.js +2 -0
  149. package/dist/lib/types/providers.d.ts +107 -0
  150. package/dist/lib/types/providers.js +69 -0
  151. package/dist/lib/types/streamTypes.d.ts +14 -0
  152. package/dist/lib/types/subscriptionTypes.d.ts +893 -0
  153. package/dist/lib/types/subscriptionTypes.js +8 -0
  154. package/dist/lib/utils/conversationMemory.js +121 -82
  155. package/dist/lib/utils/logger.d.ts +5 -0
  156. package/dist/lib/utils/logger.js +50 -2
  157. package/dist/lib/utils/messageBuilder.js +22 -42
  158. package/dist/lib/utils/modelDetection.js +3 -3
  159. package/dist/lib/utils/providerConfig.d.ts +167 -0
  160. package/dist/lib/utils/providerConfig.js +619 -9
  161. package/dist/lib/utils/providerRetry.d.ts +41 -0
  162. package/dist/lib/utils/providerRetry.js +114 -0
  163. package/dist/lib/utils/retryability.d.ts +14 -0
  164. package/dist/lib/utils/retryability.js +23 -0
  165. package/dist/lib/utils/sanitizers/svg.js +4 -5
  166. package/dist/lib/utils/tokenEstimation.d.ts +11 -1
  167. package/dist/lib/utils/tokenEstimation.js +19 -4
  168. package/dist/lib/utils/videoAnalysisProcessor.js +7 -3
  169. package/dist/mcp/externalServerManager.js +66 -0
  170. package/dist/mcp/mcpCircuitBreaker.js +24 -0
  171. package/dist/mcp/mcpClientFactory.js +16 -0
  172. package/dist/mcp/toolDiscoveryService.js +32 -6
  173. package/dist/mcp/toolRegistry.js +193 -123
  174. package/dist/models/anthropicModels.d.ts +267 -0
  175. package/dist/models/anthropicModels.js +527 -0
  176. package/dist/neurolink.d.ts +6 -0
  177. package/dist/neurolink.js +1162 -646
  178. package/dist/providers/amazonBedrock.d.ts +1 -1
  179. package/dist/providers/amazonBedrock.js +521 -319
  180. package/dist/providers/anthropic.d.ts +123 -2
  181. package/dist/providers/anthropic.js +873 -27
  182. package/dist/providers/anthropicBaseProvider.js +77 -17
  183. package/dist/providers/googleAiStudio.d.ts +1 -1
  184. package/dist/providers/googleAiStudio.js +292 -227
  185. package/dist/providers/googleVertex.d.ts +36 -1
  186. package/dist/providers/googleVertex.js +553 -260
  187. package/dist/providers/ollama.js +329 -278
  188. package/dist/providers/openAI.js +77 -19
  189. package/dist/providers/sagemaker/parsers.js +3 -3
  190. package/dist/providers/sagemaker/streaming.js +3 -3
  191. package/dist/proxy/proxyFetch.js +81 -48
  192. package/dist/rag/ChunkerFactory.js +1 -1
  193. package/dist/rag/chunkers/MarkdownChunker.d.ts +22 -0
  194. package/dist/rag/chunkers/MarkdownChunker.js +213 -9
  195. package/dist/rag/chunking/markdownChunker.d.ts +16 -0
  196. package/dist/rag/chunking/markdownChunker.js +174 -2
  197. package/dist/rag/pipeline/contextAssembly.js +2 -1
  198. package/dist/rag/ragIntegration.d.ts +18 -1
  199. package/dist/rag/ragIntegration.js +94 -14
  200. package/dist/rag/retrieval/vectorQueryTool.js +21 -4
  201. package/dist/server/abstract/baseServerAdapter.js +4 -1
  202. package/dist/server/adapters/fastifyAdapter.js +35 -30
  203. package/dist/services/server/ai/observability/instrumentation.d.ts +32 -0
  204. package/dist/services/server/ai/observability/instrumentation.js +39 -0
  205. package/dist/telemetry/attributes.d.ts +52 -0
  206. package/dist/telemetry/attributes.js +60 -0
  207. package/dist/telemetry/index.d.ts +3 -0
  208. package/dist/telemetry/index.js +3 -0
  209. package/dist/telemetry/telemetryService.d.ts +6 -0
  210. package/dist/telemetry/telemetryService.js +6 -0
  211. package/dist/telemetry/tracers.d.ts +15 -0
  212. package/dist/telemetry/tracers.js +16 -0
  213. package/dist/telemetry/withSpan.d.ts +9 -0
  214. package/dist/telemetry/withSpan.js +34 -0
  215. package/dist/types/contextTypes.d.ts +10 -0
  216. package/dist/types/errors.d.ts +62 -0
  217. package/dist/types/errors.js +107 -0
  218. package/dist/types/index.d.ts +2 -1
  219. package/dist/types/index.js +2 -0
  220. package/dist/types/providers.d.ts +107 -0
  221. package/dist/types/providers.js +69 -0
  222. package/dist/types/streamTypes.d.ts +14 -0
  223. package/dist/types/subscriptionTypes.d.ts +893 -0
  224. package/dist/types/subscriptionTypes.js +7 -0
  225. package/dist/utils/conversationMemory.js +121 -82
  226. package/dist/utils/logger.d.ts +5 -0
  227. package/dist/utils/logger.js +50 -2
  228. package/dist/utils/messageBuilder.js +22 -42
  229. package/dist/utils/modelDetection.js +3 -3
  230. package/dist/utils/providerConfig.d.ts +167 -0
  231. package/dist/utils/providerConfig.js +619 -9
  232. package/dist/utils/providerRetry.d.ts +41 -0
  233. package/dist/utils/providerRetry.js +113 -0
  234. package/dist/utils/retryability.d.ts +14 -0
  235. package/dist/utils/retryability.js +22 -0
  236. package/dist/utils/sanitizers/svg.js +4 -5
  237. package/dist/utils/tokenEstimation.d.ts +11 -1
  238. package/dist/utils/tokenEstimation.js +19 -4
  239. package/dist/utils/videoAnalysisProcessor.js +7 -3
  240. package/dist/workflow/config.d.ts +26 -26
  241. package/package.json +2 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [9.16.0](https://github.com/juspay/neurolink/compare/v9.15.0...v9.16.0) (2026-03-02)
2
+
3
+ ### Features
4
+
5
+ - **(sdk):** add models, observability, RAG enhancements, landing overhaul, and 45 review fixes ([eb79a1f](https://github.com/juspay/neurolink/commit/eb79a1f51dfd789da49130b6a05fa40ed38fd668))
6
+
7
+ ## [9.15.0](https://github.com/juspay/neurolink/compare/v9.14.0...v9.15.0) (2026-03-01)
8
+
9
+ ### Features
10
+
11
+ - **(anthropic):** add Claude subscription support with OAuth 2.0 authentication ([dbe0eb0](https://github.com/juspay/neurolink/commit/dbe0eb0219c565b2329f81e4f254849315c901a2))
12
+
1
13
  ## [9.14.0](https://github.com/juspay/neurolink/compare/v9.13.0...v9.14.0) (2026-02-27)
2
14
 
3
15
  ### Features
package/README.md CHANGED
@@ -160,21 +160,21 @@ NeuroLink is a comprehensive AI development platform. Every feature below is pro
160
160
 
161
161
  **13 providers unified under one API** - Switch providers with a single parameter change.
162
162
 
163
- | Provider | Models | Free Tier | Tool Support | Status | Documentation |
164
- | --------------------- | -------------------------------------------------- | --------------- | ------------ | ------------- | ----------------------------------------------------------------------- |
165
- | **OpenAI** | GPT-4o, GPT-4o-mini, o1 | ❌ | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#openai) |
166
- | **Anthropic** | Claude 4.5 Opus/Sonnet/Haiku, Claude 4 Opus/Sonnet | ❌ | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#anthropic) |
167
- | **Google AI Studio** | Gemini 3 Flash/Pro, Gemini 2.5 Flash/Pro | ✅ Free Tier | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#google-ai) |
168
- | **AWS Bedrock** | Claude, Titan, Llama, Nova | ❌ | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#bedrock) |
169
- | **Google Vertex** | Gemini 3/2.5 (gemini-3-\*-preview) | ❌ | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#vertex) |
170
- | **Azure OpenAI** | GPT-4, GPT-4o, o1 | ❌ | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#azure) |
171
- | **LiteLLM** | 100+ models unified | Varies | ✅ Full | ✅ Production | [Setup Guide](docs/litellm-integration.md) |
172
- | **AWS SageMaker** | Custom deployed models | ❌ | ✅ Full | ✅ Production | [Setup Guide](docs/sagemaker-integration.md) |
173
- | **Mistral AI** | Mistral Large, Small | ✅ Free Tier | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#mistral) |
174
- | **Hugging Face** | 100,000+ models | ✅ Free | ⚠️ Partial | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#huggingface) |
175
- | **Ollama** | Local models (Llama, Mistral) | ✅ Free (Local) | ⚠️ Partial | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#ollama) |
176
- | **OpenAI Compatible** | Any OpenAI-compatible endpoint | Varies | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#openai-compatible) |
177
- | **OpenRouter** | 200+ Models via OpenRouter | Varies | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/providers/openrouter.md) |
163
+ | Provider | Models | Free Tier | Tool Support | Status | Documentation |
164
+ | --------------------- | -------------------------------------------------- | --------------- | ------------ | ------------- | ----------------------------------------------------------------------------------------------------------------------------- |
165
+ | **OpenAI** | GPT-4o, GPT-4o-mini, o1 | ❌ | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#openai) |
166
+ | **Anthropic** | Claude 4.5 Opus/Sonnet/Haiku, Claude 4 Opus/Sonnet | ❌ | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#anthropic) \| [Subscription Guide](docs/features/claude-subscription.md) |
167
+ | **Google AI Studio** | Gemini 3 Flash/Pro, Gemini 2.5 Flash/Pro | ✅ Free Tier | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#google-ai) |
168
+ | **AWS Bedrock** | Claude, Titan, Llama, Nova | ❌ | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#bedrock) |
169
+ | **Google Vertex** | Gemini 3/2.5 (gemini-3-\*-preview) | ❌ | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#vertex) |
170
+ | **Azure OpenAI** | GPT-4, GPT-4o, o1 | ❌ | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#azure) |
171
+ | **LiteLLM** | 100+ models unified | Varies | ✅ Full | ✅ Production | [Setup Guide](docs/litellm-integration.md) |
172
+ | **AWS SageMaker** | Custom deployed models | ❌ | ✅ Full | ✅ Production | [Setup Guide](docs/sagemaker-integration.md) |
173
+ | **Mistral AI** | Mistral Large, Small | ✅ Free Tier | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#mistral) |
174
+ | **Hugging Face** | 100,000+ models | ✅ Free | ⚠️ Partial | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#huggingface) |
175
+ | **Ollama** | Local models (Llama, Mistral) | ✅ Free (Local) | ⚠️ Partial | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#ollama) |
176
+ | **OpenAI Compatible** | Any OpenAI-compatible endpoint | Varies | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/provider-setup.md#openai-compatible) |
177
+ | **OpenRouter** | 200+ Models via OpenRouter | Varies | ✅ Full | ✅ Production | [Setup Guide](docs/getting-started/providers/openrouter.md) |
178
178
 
179
179
  **[📖 Provider Comparison Guide](docs/reference/provider-comparison.md)** - Detailed feature matrix and selection criteria
180
180
  **[🔬 Provider Feature Compatibility](docs/reference/provider-feature-compatibility.md)** - Test-based compatibility reference for all 19 features across 13 providers
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Video Analysis Handler
3
3
  *
4
- * Provides video analysis using Google's Gemini 2.0 Flash model.
4
+ * Provides video analysis using Google's Gemini 2.5 Flash model.
5
5
  * Supports both Vertex AI and Gemini API providers.
6
6
  *
7
7
  * @module adapters/video/geminiVideoAnalyzer
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Video Analysis Handler
3
3
  *
4
- * Provides video analysis using Google's Gemini 2.0 Flash model.
4
+ * Provides video analysis using Google's Gemini 2.5 Flash model.
5
5
  * Supports both Vertex AI and Gemini API providers.
6
6
  *
7
7
  * @module adapters/video/geminiVideoAnalyzer
@@ -13,7 +13,7 @@ import { NeuroLinkError, ErrorFactory } from "../../utils/errorHandling.js";
13
13
  // ---------------------------------------------------------------------------
14
14
  // Shared config
15
15
  // ---------------------------------------------------------------------------
16
- const DEFAULT_MODEL = "gemini-2.0-flash";
16
+ const DEFAULT_MODEL = "gemini-2.5-flash";
17
17
  const DEFAULT_LOCATION = "us-central1";
18
18
  /**
19
19
  * Extract content items from user messages
@@ -223,14 +223,16 @@ async function getVertexConfig() {
223
223
  }
224
224
  export async function analyzeVideo(messages, options = {}) {
225
225
  const provider = options.provider || AIProviderName.AUTO;
226
- // Vertex — only when GOOGLE_VERTEX_PROJECT is explicitly set
227
- if (provider === AIProviderName.VERTEX || provider === AIProviderName.AUTO) {
226
+ // Vertex — only when Vertex credentials are configured
227
+ if (provider === AIProviderName.VERTEX ||
228
+ (provider === AIProviderName.AUTO &&
229
+ (process.env.GOOGLE_VERTEX_PROJECT || process.env.GOOGLE_CLOUD_PROJECT))) {
228
230
  return analyzeVideoWithVertexAI(messages, options);
229
231
  }
230
- // Gemini API — when GOOGLE_AI_API_KEY is set
231
- if (provider === AIProviderName.GOOGLE_AI && process.env.GOOGLE_AI_API_KEY) {
232
+ // Gemini API — when Google AI API key is available
233
+ if (provider === AIProviderName.GOOGLE_AI ||
234
+ (provider === AIProviderName.AUTO && process.env.GOOGLE_AI_API_KEY)) {
232
235
  return analyzeVideoWithGeminiAPI(messages, options);
233
236
  }
234
- throw new Error("No valid provider configuration found. " +
235
- "Set GOOGLE_VERTEX_PROJECT for Vertex AI or GOOGLE_AI_API_KEY for Gemini API.");
237
+ throw ErrorFactory.invalidConfiguration("video analysis provider", "No valid provider configuration found. Set GOOGLE_VERTEX_PROJECT for Vertex AI or GOOGLE_AI_API_KEY for Gemini API.");
236
238
  }
@@ -0,0 +1,377 @@
1
+ /**
2
+ * Anthropic OAuth 2.0 Authentication for Claude Pro/Max Subscriptions
3
+ *
4
+ * This module implements OAuth 2.0 flow with PKCE support for authenticating
5
+ * Claude Pro and Max subscription users through console.anthropic.com.
6
+ *
7
+ * OAuth Flow:
8
+ * 1. Generate PKCE code verifier and challenge
9
+ * 2. User is redirected to Anthropic authorization URL
10
+ * 3. User authenticates and grants permissions
11
+ * 4. Callback receives authorization code
12
+ * 5. Code is exchanged for access and refresh tokens
13
+ * 6. Tokens are used for API authentication
14
+ *
15
+ * @module auth/anthropicOAuth
16
+ */
17
+ import type { Server } from "http";
18
+ export { OAuthError, OAuthConfigurationError, OAuthTokenExchangeError, OAuthTokenRefreshError, OAuthTokenValidationError, OAuthTokenRevocationError, OAuthCallbackServerError, } from "../types/errors.js";
19
+ /**
20
+ * Claude Code's official OAuth client ID
21
+ * Used to authenticate with Anthropic's OAuth system
22
+ */
23
+ export declare const CLAUDE_CODE_CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
24
+ /**
25
+ * Anthropic OAuth authorization URL for Claude Pro/Max
26
+ */
27
+ export declare const ANTHROPIC_AUTH_URL = "https://claude.ai/oauth/authorize";
28
+ /**
29
+ * Anthropic OAuth token endpoint
30
+ */
31
+ export declare const ANTHROPIC_TOKEN_URL = "https://console.anthropic.com/v1/oauth/token";
32
+ /**
33
+ * Anthropic OAuth redirect URI (official callback)
34
+ */
35
+ export declare const ANTHROPIC_REDIRECT_URI = "https://console.anthropic.com/oauth/code/callback";
36
+ /**
37
+ * Default OAuth scopes for Claude subscription access
38
+ */
39
+ export declare const DEFAULT_SCOPES: readonly string[];
40
+ /**
41
+ * User-Agent string to spoof Claude CLI
42
+ */
43
+ export declare const CLAUDE_CLI_USER_AGENT = "claude-cli/2.1.2 (external, cli)";
44
+ /**
45
+ * Required beta headers for OAuth API requests.
46
+ * The "oauth-2025-04-20" header is CRITICAL for OAuth authentication.
47
+ * The "interleaved-thinking-2025-05-14" enables extended thinking.
48
+ */
49
+ export declare const OAUTH_BETA_HEADERS = "oauth-2025-04-20,interleaved-thinking-2025-05-14";
50
+ /**
51
+ * Tool name prefix required for OAuth API requests
52
+ */
53
+ export declare const MCP_TOOL_PREFIX = "mcp_";
54
+ /**
55
+ * @deprecated Use ANTHROPIC_AUTH_URL instead
56
+ */
57
+ export declare const ANTHROPIC_OAUTH_BASE_URL = "https://console.anthropic.com/oauth";
58
+ /**
59
+ * @deprecated Use ANTHROPIC_REDIRECT_URI instead
60
+ */
61
+ export declare const DEFAULT_REDIRECT_URI = "https://console.anthropic.com/oauth/code/callback";
62
+ /**
63
+ * Default local callback server port (for local testing only)
64
+ */
65
+ export declare const DEFAULT_CALLBACK_PORT = 8787;
66
+ import type { OAuthFlowTokens, TokenValidationResult, AnthropicOAuthConfig, PKCEParams, CallbackResult } from "../types/subscriptionTypes.js";
67
+ export type { OAuthTokenResponse, OAuthFlowTokens, OAuthFlowTokens as OAuthTokens, TokenValidationResult, AnthropicOAuthConfig, PKCEParams, CallbackResult, } from "../types/subscriptionTypes.js";
68
+ /**
69
+ * AnthropicOAuth - OAuth 2.0 authentication for Claude Pro/Max subscriptions
70
+ *
71
+ * Implements OAuth 2.0 authorization code flow with PKCE support for
72
+ * authenticating users with Claude Pro or Max subscriptions.
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * const oauth = new AnthropicOAuth({
77
+ * clientId: "your-client-id",
78
+ * redirectUri: "http://localhost:8787/callback",
79
+ * });
80
+ *
81
+ * // Generate PKCE parameters
82
+ * const codeVerifier = AnthropicOAuth.generateCodeVerifier();
83
+ * const codeChallenge = await AnthropicOAuth.generateCodeChallenge(codeVerifier);
84
+ *
85
+ * // Generate auth URL
86
+ * const authUrl = oauth.generateAuthUrl({
87
+ * codeChallenge,
88
+ * state: "random-state",
89
+ * });
90
+ *
91
+ * // After user authenticates, exchange code for tokens
92
+ * const tokens = await oauth.exchangeCodeForTokens(code, codeVerifier);
93
+ * ```
94
+ */
95
+ export declare class AnthropicOAuth {
96
+ private readonly clientId;
97
+ private readonly clientSecret?;
98
+ private readonly redirectUri;
99
+ private readonly scopes;
100
+ private readonly authorizationUrl;
101
+ private readonly tokenUrl;
102
+ private readonly validationUrl;
103
+ private readonly revocationUrl;
104
+ constructor(config?: AnthropicOAuthConfig);
105
+ /**
106
+ * Generates a cryptographically secure code verifier for PKCE
107
+ *
108
+ * The code verifier is a high-entropy random string between 43-128 characters
109
+ * using URL-safe characters (A-Z, a-z, 0-9, "-", ".", "_", "~").
110
+ *
111
+ * @returns A random code verifier string (64 characters)
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const codeVerifier = AnthropicOAuth.generateCodeVerifier();
116
+ * // Returns something like "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
117
+ * ```
118
+ */
119
+ static generateCodeVerifier(): string;
120
+ /**
121
+ * Generates a PKCE code challenge from a code verifier
122
+ *
123
+ * Uses SHA-256 hashing as per RFC 7636. The challenge is the
124
+ * base64url-encoded SHA-256 hash of the code verifier.
125
+ *
126
+ * @param verifier - The code verifier to generate challenge from
127
+ * @returns Promise resolving to the code challenge string
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * const verifier = AnthropicOAuth.generateCodeVerifier();
132
+ * const challenge = await AnthropicOAuth.generateCodeChallenge(verifier);
133
+ * ```
134
+ */
135
+ static generateCodeChallenge(verifier: string): Promise<string>;
136
+ /**
137
+ * Generates both code verifier and challenge for PKCE
138
+ *
139
+ * Convenience method that generates both PKCE parameters at once.
140
+ *
141
+ * @returns Promise resolving to PKCE parameters object
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * const pkce = await AnthropicOAuth.generatePKCE();
146
+ * console.log(pkce.codeVerifier);
147
+ * console.log(pkce.codeChallenge);
148
+ * ```
149
+ */
150
+ static generatePKCE(): Promise<PKCEParams>;
151
+ /**
152
+ * Generates the OAuth authorization URL with PKCE support
153
+ *
154
+ * Builds the complete authorization URL including all required parameters
155
+ * for the OAuth 2.0 authorization code flow with PKCE.
156
+ *
157
+ * @param config - Authorization URL configuration
158
+ * @param state - Optional state parameter for CSRF protection
159
+ * @returns The complete authorization URL
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * const pkce = await AnthropicOAuth.generatePKCE();
164
+ * const authUrl = oauth.generateAuthUrl({
165
+ * codeChallenge: pkce.codeChallenge,
166
+ * state: crypto.randomUUID(),
167
+ * });
168
+ * // Redirect user to authUrl
169
+ * ```
170
+ */
171
+ generateAuthUrl(config?: {
172
+ /** PKCE code challenge (required for public clients) */
173
+ codeChallenge?: string;
174
+ /** Additional URL parameters */
175
+ additionalParams?: Record<string, string>;
176
+ }, state?: string): string;
177
+ /**
178
+ * Exchanges an authorization code for access and refresh tokens
179
+ *
180
+ * Performs the token exchange step of the OAuth flow. For public clients
181
+ * using PKCE, the code verifier must be provided.
182
+ *
183
+ * @param code - The authorization code from the OAuth callback
184
+ * @param codeVerifier - The PKCE code verifier used to generate the challenge
185
+ * @param config - Optional additional configuration
186
+ * @returns Promise resolving to the parsed OAuth tokens
187
+ * @throws OAuthTokenExchangeError if the exchange fails
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * const tokens = await oauth.exchangeCodeForTokens(
192
+ * authorizationCode,
193
+ * pkce.codeVerifier
194
+ * );
195
+ * console.log("Access token:", tokens.accessToken);
196
+ * console.log("Expires at:", tokens.expiresAt);
197
+ * ```
198
+ */
199
+ exchangeCodeForTokens(code: string, codeVerifier: string, config?: AnthropicOAuthConfig): Promise<OAuthFlowTokens>;
200
+ /**
201
+ * Refreshes an expired access token using a refresh token
202
+ *
203
+ * @param refreshToken - The refresh token from a previous authentication
204
+ * @param config - Optional configuration overrides
205
+ * @returns Promise resolving to new OAuth tokens
206
+ * @throws OAuthTokenRefreshError if the refresh fails
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * if (AnthropicOAuth.isTokenExpired(tokens.expiresAt)) {
211
+ * const newTokens = await oauth.refreshAccessToken(tokens.refreshToken);
212
+ * console.log("New access token:", newTokens.accessToken);
213
+ * }
214
+ * ```
215
+ */
216
+ refreshAccessToken(refreshToken: string, config?: AnthropicOAuthConfig): Promise<OAuthFlowTokens>;
217
+ /**
218
+ * Validates an access token and returns token information
219
+ *
220
+ * Checks if the token is still valid by calling the validation endpoint.
221
+ * Returns user information if available.
222
+ *
223
+ * @param accessToken - The access token to validate
224
+ * @returns Promise resolving to validation result
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * const result = await oauth.validateToken(accessToken);
229
+ * if (result.isValid) {
230
+ * console.log("Token is valid, expires in:", result.expiresIn, "seconds");
231
+ * console.log("User email:", result.user?.email);
232
+ * } else {
233
+ * console.log("Token is invalid:", result.error);
234
+ * }
235
+ * ```
236
+ */
237
+ validateToken(accessToken: string): Promise<boolean>;
238
+ /**
239
+ * Validates token and returns detailed information
240
+ *
241
+ * @param accessToken - The access token to validate
242
+ * @returns Promise resolving to detailed validation result
243
+ */
244
+ validateTokenWithDetails(accessToken: string): Promise<TokenValidationResult>;
245
+ /**
246
+ * Revokes an access token or refresh token
247
+ *
248
+ * @param token - The token to revoke
249
+ * @param tokenType - Type of token ("access_token" or "refresh_token")
250
+ * @returns Promise that resolves when revocation is complete
251
+ * @throws OAuthTokenRevocationError if revocation fails
252
+ */
253
+ revokeToken(token: string, tokenType?: "access_token" | "refresh_token"): Promise<void>;
254
+ /**
255
+ * Parses a token response into structured OAuthFlowTokens
256
+ */
257
+ private parseTokenResponse;
258
+ /**
259
+ * Generates a random state parameter for CSRF protection
260
+ */
261
+ private generateState;
262
+ /**
263
+ * Checks if a token is expired or about to expire
264
+ *
265
+ * @param expiresAt - Token expiration date
266
+ * @param bufferSeconds - Buffer time before actual expiration (default: 60 seconds)
267
+ * @returns True if token is expired or will expire within buffer time
268
+ */
269
+ static isTokenExpired(expiresAt: Date, bufferSeconds?: number): boolean;
270
+ /**
271
+ * Gets the configured client ID
272
+ */
273
+ getClientId(): string;
274
+ /**
275
+ * Gets the configured redirect URI
276
+ */
277
+ getRedirectUri(): string;
278
+ /**
279
+ * Gets the configured scopes
280
+ */
281
+ getScopes(): readonly string[];
282
+ }
283
+ /**
284
+ * Creates and starts a local HTTP server to receive OAuth callbacks
285
+ *
286
+ * This helper function starts a temporary HTTP server that listens for
287
+ * the OAuth callback and extracts the authorization code.
288
+ *
289
+ * @param port - Port to listen on (default: 8787)
290
+ * @param path - Path to listen on (default: "/callback")
291
+ * @param timeout - Timeout in milliseconds (default: 5 minutes)
292
+ * @returns Promise resolving to the callback result with authorization code
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * // Start callback server before redirecting user
297
+ * const callbackPromise = startCallbackServer();
298
+ *
299
+ * // Generate auth URL and redirect user
300
+ * const authUrl = oauth.generateAuthUrl({ codeChallenge });
301
+ * console.log("Please visit:", authUrl);
302
+ *
303
+ * // Wait for callback
304
+ * const result = await callbackPromise;
305
+ * console.log("Got authorization code:", result.code);
306
+ *
307
+ * // Exchange for tokens
308
+ * const tokens = await oauth.exchangeCodeForTokens(result.code, codeVerifier);
309
+ * ```
310
+ */
311
+ export declare function startCallbackServer(port?: number, path?: string, timeout?: number): Promise<CallbackResult>;
312
+ /**
313
+ * Stops the callback server if running
314
+ * Note: The server automatically stops after receiving a callback or timing out
315
+ */
316
+ export declare function stopCallbackServer(server: Server): Promise<void>;
317
+ /**
318
+ * Creates an AnthropicOAuth instance with default configuration from environment
319
+ *
320
+ * @param overrides - Optional configuration overrides
321
+ * @returns Configured AnthropicOAuth instance
322
+ *
323
+ * @example
324
+ * ```typescript
325
+ * const oauth = createAnthropicOAuth();
326
+ * const authUrl = oauth.generateAuthUrl({ codeChallenge });
327
+ * ```
328
+ */
329
+ export declare function createAnthropicOAuth(overrides?: Partial<AnthropicOAuthConfig>): AnthropicOAuth;
330
+ /**
331
+ * Anthropic OAuth configuration creator for providerConfig pattern
332
+ *
333
+ * @returns Provider configuration options for Anthropic OAuth
334
+ */
335
+ export declare function createAnthropicOAuthConfig(): {
336
+ providerName: string;
337
+ envVarName: string;
338
+ setupUrl: string;
339
+ description: string;
340
+ instructions: string[];
341
+ fallbackEnvVars: never[];
342
+ };
343
+ /**
344
+ * Checks if Anthropic OAuth credentials are configured
345
+ *
346
+ * @returns True if OAuth client ID is available
347
+ */
348
+ export declare function hasAnthropicOAuthCredentials(): boolean;
349
+ /**
350
+ * Performs a complete OAuth flow including callback server
351
+ *
352
+ * This is a convenience function that handles the entire OAuth flow:
353
+ * 1. Generates PKCE parameters
354
+ * 2. Starts the callback server
355
+ * 3. Opens the browser (if possible)
356
+ * 4. Waits for the callback
357
+ * 5. Exchanges the code for tokens
358
+ *
359
+ * @param oauth - AnthropicOAuth instance
360
+ * @param options - Flow options
361
+ * @returns Promise resolving to OAuth tokens
362
+ *
363
+ * @example
364
+ * ```typescript
365
+ * const oauth = createAnthropicOAuth();
366
+ * const tokens = await performOAuthFlow(oauth);
367
+ * console.log("Authenticated! Token expires at:", tokens.expiresAt);
368
+ * ```
369
+ */
370
+ export declare function performOAuthFlow(oauth: AnthropicOAuth, options?: {
371
+ /** Port for callback server (default: 8787) */
372
+ port?: number;
373
+ /** Timeout in milliseconds (default: 5 minutes) */
374
+ timeout?: number;
375
+ /** Whether to automatically open browser (default: true) */
376
+ openBrowser?: boolean;
377
+ }): Promise<OAuthFlowTokens>;