@juspay/neurolink 9.54.6 → 9.54.8
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 +8 -0
- package/dist/action/actionInputs.d.ts +1 -1
- package/dist/adapters/video/directorPipeline.js +6 -0
- package/dist/adapters/video/vertexVideoHandler.js +6 -0
- package/dist/agent/directTools.d.ts +3 -23
- package/dist/auth/AuthProviderFactory.d.ts +1 -3
- package/dist/auth/anthropicOAuth.d.ts +4 -7
- package/dist/auth/anthropicOAuth.js +23 -0
- package/dist/auth/errors.d.ts +1 -1
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.js +14 -0
- package/dist/auth/middleware/AuthMiddleware.d.ts +5 -60
- package/dist/auth/middleware/AuthMiddleware.js +3 -0
- package/dist/auth/middleware/rateLimitByUser.d.ts +4 -93
- package/dist/auth/middleware/rateLimitByUser.js +4 -0
- package/dist/auth/providers/BaseAuthProvider.d.ts +1 -1
- package/dist/auth/providers/CognitoProvider.js +3 -0
- package/dist/auth/providers/KeycloakProvider.js +3 -0
- package/dist/auth/providers/auth0.d.ts +1 -1
- package/dist/auth/sessionManager.d.ts +2 -0
- package/dist/auth/sessionManager.js +53 -11
- package/dist/auth/tokenStore.d.ts +2 -0
- package/dist/auth/tokenStore.js +45 -4
- package/dist/autoresearch/tools.d.ts +1 -16
- package/dist/browser/neurolink.min.js +358 -358
- package/dist/cli/commands/config.d.ts +3 -123
- package/dist/cli/commands/config.js +4 -2
- package/dist/cli/commands/evaluate.d.ts +1 -19
- package/dist/cli/commands/proxy.d.ts +1 -1
- package/dist/cli/commands/proxy.js +3 -0
- package/dist/cli/commands/rag.js +3 -0
- package/dist/cli/commands/setup-anthropic.d.ts +2 -6
- package/dist/cli/commands/setup-anthropic.js +1 -1
- package/dist/cli/commands/setup-azure.d.ts +2 -6
- package/dist/cli/commands/setup-azure.js +1 -1
- package/dist/cli/commands/setup-bedrock.d.ts +2 -6
- package/dist/cli/commands/setup-bedrock.js +1 -1
- package/dist/cli/commands/setup-gcp.d.ts +2 -6
- package/dist/cli/commands/setup-google-ai.d.ts +2 -6
- package/dist/cli/commands/setup-google-ai.js +1 -1
- package/dist/cli/commands/setup-huggingface.d.ts +1 -5
- package/dist/cli/commands/setup-mistral.d.ts +1 -5
- package/dist/cli/commands/setup-openai.d.ts +2 -6
- package/dist/cli/commands/setup-openai.js +1 -1
- package/dist/cli/commands/setup.d.ts +1 -8
- package/dist/cli/commands/task.js +1 -0
- package/dist/cli/commands/voiceServer.d.ts +1 -4
- package/dist/cli/loop/session.js +31 -10
- package/dist/cli/utils/interactiveSetup.d.ts +2 -15
- package/dist/cli/utils/videoFileUtils.d.ts +1 -15
- package/dist/client/aiSdkAdapter.d.ts +1 -1
- package/dist/client/aiSdkAdapter.js +1 -0
- package/dist/client/httpClient.d.ts +1 -0
- package/dist/client/httpClient.js +13 -0
- package/dist/client/sseClient.d.ts +1 -0
- package/dist/client/sseClient.js +29 -0
- package/dist/client/streamingClient.d.ts +2 -0
- package/dist/client/streamingClient.js +19 -0
- package/dist/client/wsClient.d.ts +6 -0
- package/dist/client/wsClient.js +90 -10
- package/dist/context/budgetChecker.js +3 -1
- package/dist/context/contextCompactor.js +163 -143
- package/dist/context/fileSummarizationService.d.ts +1 -9
- package/dist/context/summarizationEngine.js +29 -16
- package/dist/core/baseProvider.js +124 -153
- package/dist/core/infrastructure/baseRegistry.d.ts +1 -7
- package/dist/core/modules/GenerationHandler.d.ts +3 -2
- package/dist/core/modules/GenerationHandler.js +9 -1
- package/dist/core/modules/StreamHandler.js +9 -0
- package/dist/core/modules/ToolsManager.js +18 -2
- package/dist/evaluation/BatchEvaluator.d.ts +1 -97
- package/dist/evaluation/EvaluationAggregator.d.ts +1 -118
- package/dist/evaluation/EvaluatorFactory.d.ts +1 -13
- package/dist/evaluation/EvaluatorRegistry.d.ts +1 -50
- package/dist/evaluation/errors/EvaluationError.d.ts +2 -27
- package/dist/evaluation/hooks/langfuseAdapter.d.ts +1 -39
- package/dist/evaluation/hooks/observabilityHooks.d.ts +3 -55
- package/dist/evaluation/hooks/observabilityHooks.js +3 -0
- package/dist/evaluation/pipeline/strategies/batchStrategy.d.ts +7 -61
- package/dist/evaluation/pipeline/strategies/batchStrategy.js +7 -7
- package/dist/evaluation/ragasEvaluator.js +54 -37
- package/dist/evaluation/reporting/metricsCollector.d.ts +1 -60
- package/dist/evaluation/reporting/reportGenerator.d.ts +1 -17
- package/dist/evaluation/scorers/rule/contentSimilarityScorer.d.ts +1 -29
- package/dist/evaluation/scorers/rule/formatScorer.d.ts +1 -42
- package/dist/evaluation/scorers/rule/keywordCoverageScorer.d.ts +1 -19
- package/dist/evaluation/scorers/rule/lengthScorer.d.ts +1 -33
- package/dist/factories/providerFactory.d.ts +1 -16
- package/dist/factories/providerFactory.js +2 -0
- package/dist/image-gen/ImageGenService.d.ts +3 -0
- package/dist/image-gen/ImageGenService.js +3 -0
- package/dist/lib/action/actionInputs.d.ts +1 -1
- package/dist/lib/adapters/video/directorPipeline.js +6 -0
- package/dist/lib/adapters/video/vertexVideoHandler.js +6 -0
- package/dist/lib/agent/directTools.d.ts +3 -23
- package/dist/lib/auth/AuthProviderFactory.d.ts +1 -3
- package/dist/lib/auth/anthropicOAuth.d.ts +4 -7
- package/dist/lib/auth/anthropicOAuth.js +23 -0
- package/dist/lib/auth/errors.d.ts +1 -1
- package/dist/lib/auth/index.d.ts +11 -0
- package/dist/lib/auth/index.js +14 -0
- package/dist/lib/auth/middleware/AuthMiddleware.d.ts +5 -60
- package/dist/lib/auth/middleware/AuthMiddleware.js +3 -0
- package/dist/lib/auth/middleware/rateLimitByUser.d.ts +4 -93
- package/dist/lib/auth/middleware/rateLimitByUser.js +4 -0
- package/dist/lib/auth/providers/BaseAuthProvider.d.ts +1 -1
- package/dist/lib/auth/providers/CognitoProvider.js +3 -0
- package/dist/lib/auth/providers/KeycloakProvider.js +3 -0
- package/dist/lib/auth/providers/auth0.d.ts +1 -1
- package/dist/lib/auth/sessionManager.d.ts +2 -0
- package/dist/lib/auth/sessionManager.js +53 -11
- package/dist/lib/auth/tokenStore.d.ts +2 -0
- package/dist/lib/auth/tokenStore.js +45 -4
- package/dist/lib/autoresearch/tools.d.ts +1 -16
- package/dist/lib/client/aiSdkAdapter.d.ts +1 -1
- package/dist/lib/client/aiSdkAdapter.js +1 -0
- package/dist/lib/client/httpClient.d.ts +1 -0
- package/dist/lib/client/httpClient.js +13 -0
- package/dist/lib/client/sseClient.d.ts +1 -0
- package/dist/lib/client/sseClient.js +29 -0
- package/dist/lib/client/streamingClient.d.ts +2 -0
- package/dist/lib/client/streamingClient.js +19 -0
- package/dist/lib/client/wsClient.d.ts +6 -0
- package/dist/lib/client/wsClient.js +90 -10
- package/dist/lib/context/budgetChecker.js +3 -1
- package/dist/lib/context/contextCompactor.js +163 -143
- package/dist/lib/context/fileSummarizationService.d.ts +1 -9
- package/dist/lib/context/summarizationEngine.js +29 -16
- package/dist/lib/core/baseProvider.js +124 -153
- package/dist/lib/core/infrastructure/baseRegistry.d.ts +1 -7
- package/dist/lib/core/modules/GenerationHandler.d.ts +3 -2
- package/dist/lib/core/modules/GenerationHandler.js +9 -1
- package/dist/lib/core/modules/StreamHandler.js +9 -0
- package/dist/lib/core/modules/ToolsManager.js +18 -2
- package/dist/lib/evaluation/BatchEvaluator.d.ts +1 -97
- package/dist/lib/evaluation/EvaluationAggregator.d.ts +1 -118
- package/dist/lib/evaluation/EvaluatorFactory.d.ts +1 -13
- package/dist/lib/evaluation/EvaluatorRegistry.d.ts +1 -50
- package/dist/lib/evaluation/errors/EvaluationError.d.ts +2 -27
- package/dist/lib/evaluation/hooks/langfuseAdapter.d.ts +1 -39
- package/dist/lib/evaluation/hooks/observabilityHooks.d.ts +3 -55
- package/dist/lib/evaluation/hooks/observabilityHooks.js +3 -0
- package/dist/lib/evaluation/pipeline/strategies/batchStrategy.d.ts +7 -61
- package/dist/lib/evaluation/pipeline/strategies/batchStrategy.js +7 -7
- package/dist/lib/evaluation/ragasEvaluator.js +54 -37
- package/dist/lib/evaluation/reporting/metricsCollector.d.ts +1 -60
- package/dist/lib/evaluation/reporting/reportGenerator.d.ts +1 -17
- package/dist/lib/evaluation/scorers/rule/contentSimilarityScorer.d.ts +1 -29
- package/dist/lib/evaluation/scorers/rule/formatScorer.d.ts +1 -42
- package/dist/lib/evaluation/scorers/rule/keywordCoverageScorer.d.ts +1 -19
- package/dist/lib/evaluation/scorers/rule/lengthScorer.d.ts +1 -33
- package/dist/lib/factories/providerFactory.d.ts +1 -16
- package/dist/lib/factories/providerFactory.js +2 -0
- package/dist/lib/image-gen/ImageGenService.d.ts +3 -0
- package/dist/lib/image-gen/ImageGenService.js +3 -0
- package/dist/lib/mcp/batching/requestBatcher.js +99 -73
- package/dist/lib/mcp/httpRateLimiter.js +3 -1
- package/dist/lib/mcp/httpRetryHandler.js +3 -1
- package/dist/lib/mcp/mcpClientFactory.js +3 -1
- package/dist/lib/mcp/multiServerManager.d.ts +1 -14
- package/dist/lib/mcp/servers/aiProviders/aiAnalysisTools.js +5 -1
- package/dist/lib/mcp/servers/aiProviders/aiWorkflowTools.js +1 -0
- package/dist/lib/mcp/toolDiscoveryService.js +70 -57
- package/dist/lib/mcp/toolRegistry.js +11 -1
- package/dist/lib/memory/memoryRetrievalTools.js +182 -141
- package/dist/lib/neurolink.js +236 -40
- package/dist/lib/observability/exporterRegistry.d.ts +3 -21
- package/dist/lib/observability/exporters/sentryExporter.js +1 -0
- package/dist/lib/observability/metricsAggregator.d.ts +1 -31
- package/dist/lib/observability/tokenTracker.d.ts +7 -16
- package/dist/lib/observability/tokenTracker.js +6 -4
- package/dist/lib/observability/utils/spanSerializer.d.ts +5 -1
- package/dist/lib/observability/utils/spanSerializer.js +24 -4
- package/dist/lib/processors/base/BaseFileProcessor.js +66 -53
- package/dist/lib/processors/document/ExcelProcessor.d.ts +1 -1
- package/dist/lib/processors/errors/errorHelpers.d.ts +1 -31
- package/dist/lib/processors/errors/errorSerializer.d.ts +1 -45
- package/dist/lib/processors/registry/ProcessorRegistry.js +17 -6
- package/dist/lib/providers/amazonBedrock.js +189 -15
- package/dist/lib/providers/amazonSagemaker.js +25 -11
- package/dist/lib/providers/anthropic.js +13 -0
- package/dist/lib/providers/azureOpenai.js +2 -0
- package/dist/lib/providers/googleAiStudio.js +96 -26
- package/dist/lib/providers/googleVertex.js +66 -27
- package/dist/lib/providers/huggingFace.js +2 -0
- package/dist/lib/providers/litellm.js +2 -0
- package/dist/lib/providers/mistral.js +2 -0
- package/dist/lib/providers/ollama.js +84 -5
- package/dist/lib/providers/openAI.d.ts +2 -0
- package/dist/lib/providers/openAI.js +17 -6
- package/dist/lib/providers/openRouter.js +2 -0
- package/dist/lib/providers/openaiCompatible.js +2 -0
- package/dist/lib/providers/sagemaker/detection.d.ts +1 -33
- package/dist/lib/providers/sagemaker/diagnostics.d.ts +1 -25
- package/dist/lib/providers/sagemaker/language-model.d.ts +1 -1
- package/dist/lib/proxy/proxyConfig.js +4 -0
- package/dist/lib/proxy/proxyEnv.d.ts +1 -17
- package/dist/lib/proxy/proxyTracer.d.ts +1 -36
- package/dist/lib/proxy/proxyTracer.js +9 -0
- package/dist/lib/proxy/quietDetector.d.ts +1 -7
- package/dist/lib/proxy/rawStreamCapture.d.ts +1 -10
- package/dist/lib/proxy/requestLogger.d.ts +1 -21
- package/dist/lib/proxy/sseInterceptor.d.ts +1 -66
- package/dist/lib/proxy/sseInterceptor.js +6 -0
- package/dist/lib/proxy/updateChecker.d.ts +1 -6
- package/dist/lib/proxy/updateState.d.ts +1 -12
- package/dist/lib/rag/chunkers/BaseChunker.js +36 -22
- package/dist/lib/rag/chunking/jsonChunker.d.ts +1 -1
- package/dist/lib/rag/errors/RAGError.d.ts +1 -2
- package/dist/lib/rag/ragIntegration.js +45 -32
- package/dist/lib/rag/reranker/reranker.js +151 -122
- package/dist/lib/rag/retrieval/vectorQueryTool.js +79 -65
- package/dist/lib/sdk/toolRegistration.d.ts +10 -44
- package/dist/lib/sdk/toolRegistration.js +1 -1
- package/dist/lib/server/middleware/abortSignal.d.ts +1 -11
- package/dist/lib/server/middleware/auth.d.ts +1 -21
- package/dist/lib/server/middleware/auth.js +12 -0
- package/dist/lib/server/middleware/common.js +48 -32
- package/dist/lib/server/middleware/deprecation.d.ts +1 -20
- package/dist/lib/server/middleware/rateLimit.d.ts +1 -75
- package/dist/lib/server/middleware/validation.d.ts +3 -81
- package/dist/lib/server/middleware/validation.js +3 -0
- package/dist/lib/server/openapi/generator.d.ts +1 -47
- package/dist/lib/server/routes/agentRoutes.js +112 -57
- package/dist/lib/server/routes/claudeProxyRoutes.d.ts +1 -6
- package/dist/lib/server/routes/claudeProxyRoutes.js +127 -13
- package/dist/lib/server/routes/healthRoutes.js +58 -12
- package/dist/lib/server/routes/index.d.ts +1 -26
- package/dist/lib/server/routes/mcpRoutes.js +40 -7
- package/dist/lib/server/routes/memoryRoutes.js +22 -7
- package/dist/lib/server/routes/openApiRoutes.js +30 -6
- package/dist/lib/server/routes/toolRoutes.js +140 -68
- package/dist/lib/server/streaming/dataStream.d.ts +1 -35
- package/dist/lib/server/streaming/dataStream.js +15 -0
- package/dist/lib/services/server/ai/observability/instrumentation.js +114 -14
- package/dist/lib/session/globalSessionState.d.ts +1 -10
- package/dist/lib/tasks/tools/taskTools.d.ts +2 -2
- package/dist/lib/telemetry/traceContext.d.ts +9 -0
- package/dist/lib/telemetry/traceContext.js +19 -0
- package/dist/lib/telemetry/tracers.d.ts +2 -0
- package/dist/lib/telemetry/tracers.js +2 -0
- package/dist/lib/types/action.d.ts +2 -0
- package/dist/lib/types/artifact.d.ts +7 -0
- package/dist/lib/types/auth.d.ts +125 -18
- package/dist/lib/types/autoresearch.d.ts +12 -0
- package/dist/lib/types/cli.d.ts +415 -0
- package/dist/lib/types/client.d.ts +34 -0
- package/dist/lib/types/common.d.ts +12 -41
- package/dist/lib/types/context.d.ts +5 -0
- package/dist/lib/types/evaluation.d.ts +332 -1
- package/dist/lib/types/file.d.ts +4 -0
- package/dist/lib/types/mcp.d.ts +102 -2
- package/dist/lib/types/middleware.d.ts +116 -0
- package/dist/lib/types/multimodal.d.ts +65 -0
- package/dist/lib/types/observability.d.ts +81 -0
- package/dist/lib/types/processor.d.ts +47 -0
- package/dist/lib/types/providers.d.ts +120 -16
- package/dist/lib/types/proxy.d.ts +321 -1
- package/dist/lib/types/rag.d.ts +22 -0
- package/dist/lib/types/scorer.d.ts +141 -0
- package/dist/lib/types/server.d.ts +99 -0
- package/dist/lib/types/span.d.ts +2 -1
- package/dist/lib/types/span.js +1 -0
- package/dist/lib/types/tools.d.ts +44 -0
- package/dist/lib/types/tts.d.ts +6 -0
- package/dist/lib/types/utilities.d.ts +22 -0
- package/dist/lib/types/workflow.d.ts +18 -0
- package/dist/lib/utils/async/retry.d.ts +2 -8
- package/dist/lib/utils/async/retry.js +9 -9
- package/dist/lib/utils/imageCompressor.d.ts +1 -21
- package/dist/lib/utils/imageCompressor.js +5 -1
- package/dist/lib/utils/messageBuilder.d.ts +1 -1
- package/dist/lib/utils/redis.d.ts +1 -4
- package/dist/lib/utils/toolEndEmitter.d.ts +25 -0
- package/dist/lib/utils/toolEndEmitter.js +65 -0
- package/dist/lib/workflow/config.d.ts +7 -32
- package/dist/lib/workflow/core/ensembleExecutor.js +28 -0
- package/dist/lib/workflow/core/judgeScorer.js +23 -0
- package/dist/lib/workflow/core/responseConditioner.js +17 -0
- package/dist/lib/workflow/core/workflowRunner.d.ts +1 -19
- package/dist/lib/workflow/core/workflowRunner.js +202 -147
- package/dist/mcp/batching/requestBatcher.js +99 -73
- package/dist/mcp/httpRateLimiter.js +3 -1
- package/dist/mcp/httpRetryHandler.js +3 -1
- package/dist/mcp/mcpClientFactory.js +3 -1
- package/dist/mcp/multiServerManager.d.ts +1 -14
- package/dist/mcp/servers/aiProviders/aiAnalysisTools.js +5 -1
- package/dist/mcp/servers/aiProviders/aiWorkflowTools.js +1 -0
- package/dist/mcp/toolDiscoveryService.js +70 -57
- package/dist/mcp/toolRegistry.js +11 -1
- package/dist/memory/memoryRetrievalTools.js +182 -141
- package/dist/neurolink.js +236 -40
- package/dist/observability/exporterRegistry.d.ts +3 -21
- package/dist/observability/exporters/sentryExporter.js +1 -0
- package/dist/observability/metricsAggregator.d.ts +1 -31
- package/dist/observability/tokenTracker.d.ts +7 -16
- package/dist/observability/tokenTracker.js +6 -4
- package/dist/observability/utils/spanSerializer.d.ts +5 -1
- package/dist/observability/utils/spanSerializer.js +24 -4
- package/dist/processors/base/BaseFileProcessor.js +66 -53
- package/dist/processors/document/ExcelProcessor.d.ts +1 -1
- package/dist/processors/errors/errorHelpers.d.ts +1 -31
- package/dist/processors/errors/errorSerializer.d.ts +1 -45
- package/dist/processors/registry/ProcessorRegistry.js +17 -6
- package/dist/providers/amazonBedrock.js +189 -15
- package/dist/providers/amazonSagemaker.js +25 -11
- package/dist/providers/anthropic.js +13 -0
- package/dist/providers/azureOpenai.js +2 -0
- package/dist/providers/googleAiStudio.js +96 -26
- package/dist/providers/googleVertex.js +66 -27
- package/dist/providers/huggingFace.js +2 -0
- package/dist/providers/litellm.js +2 -0
- package/dist/providers/mistral.js +2 -0
- package/dist/providers/ollama.js +84 -5
- package/dist/providers/openAI.d.ts +2 -0
- package/dist/providers/openAI.js +17 -6
- package/dist/providers/openRouter.js +2 -0
- package/dist/providers/openaiCompatible.js +2 -0
- package/dist/providers/sagemaker/detection.d.ts +1 -33
- package/dist/providers/sagemaker/diagnostics.d.ts +1 -25
- package/dist/providers/sagemaker/language-model.d.ts +1 -1
- package/dist/proxy/proxyConfig.js +4 -0
- package/dist/proxy/proxyEnv.d.ts +1 -17
- package/dist/proxy/proxyTracer.d.ts +1 -36
- package/dist/proxy/proxyTracer.js +9 -0
- package/dist/proxy/quietDetector.d.ts +1 -7
- package/dist/proxy/rawStreamCapture.d.ts +1 -10
- package/dist/proxy/requestLogger.d.ts +1 -21
- package/dist/proxy/sseInterceptor.d.ts +1 -66
- package/dist/proxy/sseInterceptor.js +6 -0
- package/dist/proxy/updateChecker.d.ts +1 -6
- package/dist/proxy/updateState.d.ts +1 -12
- package/dist/rag/chunkers/BaseChunker.js +36 -22
- package/dist/rag/chunking/jsonChunker.d.ts +1 -1
- package/dist/rag/errors/RAGError.d.ts +1 -2
- package/dist/rag/ragIntegration.js +45 -32
- package/dist/rag/reranker/reranker.js +151 -122
- package/dist/rag/retrieval/vectorQueryTool.js +79 -65
- package/dist/sdk/toolRegistration.d.ts +10 -44
- package/dist/sdk/toolRegistration.js +1 -1
- package/dist/server/middleware/abortSignal.d.ts +1 -11
- package/dist/server/middleware/auth.d.ts +1 -21
- package/dist/server/middleware/auth.js +12 -0
- package/dist/server/middleware/common.js +48 -32
- package/dist/server/middleware/deprecation.d.ts +1 -20
- package/dist/server/middleware/rateLimit.d.ts +1 -75
- package/dist/server/middleware/validation.d.ts +3 -81
- package/dist/server/middleware/validation.js +3 -0
- package/dist/server/openapi/generator.d.ts +1 -47
- package/dist/server/routes/agentRoutes.js +112 -57
- package/dist/server/routes/claudeProxyRoutes.d.ts +1 -6
- package/dist/server/routes/claudeProxyRoutes.js +127 -13
- package/dist/server/routes/healthRoutes.js +58 -12
- package/dist/server/routes/index.d.ts +1 -26
- package/dist/server/routes/mcpRoutes.js +40 -7
- package/dist/server/routes/memoryRoutes.js +22 -7
- package/dist/server/routes/openApiRoutes.js +30 -6
- package/dist/server/routes/toolRoutes.js +140 -68
- package/dist/server/streaming/dataStream.d.ts +1 -35
- package/dist/server/streaming/dataStream.js +15 -0
- package/dist/services/server/ai/observability/instrumentation.js +114 -14
- package/dist/session/globalSessionState.d.ts +1 -10
- package/dist/tasks/tools/taskTools.d.ts +2 -2
- package/dist/telemetry/traceContext.d.ts +9 -0
- package/dist/telemetry/traceContext.js +18 -0
- package/dist/telemetry/tracers.d.ts +2 -0
- package/dist/telemetry/tracers.js +2 -0
- package/dist/types/action.d.ts +2 -0
- package/dist/types/artifact.d.ts +7 -0
- package/dist/types/auth.d.ts +125 -18
- package/dist/types/autoresearch.d.ts +12 -0
- package/dist/types/cli.d.ts +415 -0
- package/dist/types/client.d.ts +34 -0
- package/dist/types/common.d.ts +12 -41
- package/dist/types/context.d.ts +5 -0
- package/dist/types/evaluation.d.ts +332 -1
- package/dist/types/file.d.ts +4 -0
- package/dist/types/mcp.d.ts +102 -2
- package/dist/types/middleware.d.ts +116 -0
- package/dist/types/multimodal.d.ts +65 -0
- package/dist/types/observability.d.ts +81 -0
- package/dist/types/processor.d.ts +47 -0
- package/dist/types/providers.d.ts +120 -16
- package/dist/types/proxy.d.ts +321 -1
- package/dist/types/rag.d.ts +22 -0
- package/dist/types/scorer.d.ts +141 -0
- package/dist/types/server.d.ts +99 -0
- package/dist/types/span.d.ts +2 -1
- package/dist/types/span.js +1 -0
- package/dist/types/tools.d.ts +44 -0
- package/dist/types/tts.d.ts +6 -0
- package/dist/types/utilities.d.ts +22 -0
- package/dist/types/workflow.d.ts +18 -0
- package/dist/utils/async/retry.d.ts +2 -8
- package/dist/utils/async/retry.js +9 -9
- package/dist/utils/imageCompressor.d.ts +1 -21
- package/dist/utils/imageCompressor.js +5 -1
- package/dist/utils/messageBuilder.d.ts +1 -1
- package/dist/utils/redis.d.ts +1 -4
- package/dist/utils/toolEndEmitter.d.ts +25 -0
- package/dist/utils/toolEndEmitter.js +64 -0
- package/dist/workflow/config.d.ts +4 -29
- package/dist/workflow/core/ensembleExecutor.js +28 -0
- package/dist/workflow/core/judgeScorer.js +23 -0
- package/dist/workflow/core/responseConditioner.js +17 -0
- package/dist/workflow/core/workflowRunner.d.ts +1 -19
- package/dist/workflow/core/workflowRunner.js +202 -147
- package/package.json +2 -8
|
@@ -55,7 +55,7 @@ export declare const AuthError: {
|
|
|
55
55
|
readonly JWKS_FETCH_FAILED: "AUTH-070";
|
|
56
56
|
readonly JWKS_KEY_NOT_FOUND: "AUTH-071";
|
|
57
57
|
};
|
|
58
|
-
create: (code: "INVALID_TOKEN" | "EXPIRED_TOKEN" | "MISSING_TOKEN" | "TOKEN_DECODE_FAILED" | "INVALID_SIGNATURE" | "
|
|
58
|
+
create: (code: "SESSION_NOT_FOUND" | "RATE_LIMITED" | "CONFIGURATION_ERROR" | "PROVIDER_ERROR" | "INVALID_TOKEN" | "EXPIRED_TOKEN" | "MISSING_TOKEN" | "TOKEN_DECODE_FAILED" | "INVALID_SIGNATURE" | "SESSION_EXPIRED" | "SESSION_REVOKED" | "INSUFFICIENT_PERMISSIONS" | "INSUFFICIENT_ROLES" | "ACCESS_DENIED" | "USER_NOT_FOUND" | "USER_DISABLED" | "EMAIL_NOT_VERIFIED" | "MFA_REQUIRED" | "PROVIDER_NOT_FOUND" | "PROVIDER_INIT_FAILED" | "CREATION_FAILED" | "REGISTRATION_FAILED" | "DUPLICATE_REGISTRATION" | "MIDDLEWARE_ERROR" | "JWKS_FETCH_FAILED" | "JWKS_KEY_NOT_FOUND", message: string, options?: {
|
|
59
59
|
retryable?: boolean;
|
|
60
60
|
details?: Record<string, unknown>;
|
|
61
61
|
cause?: Error;
|
package/dist/lib/auth/index.d.ts
CHANGED
|
@@ -27,3 +27,14 @@ export { createSessionStorage, MemorySessionStorage, RedisSessionStorage, Sessio
|
|
|
27
27
|
export { AuthContextHolder, createAuthenticatedContext, getAuthContext, getCurrentSession, getCurrentUser, globalAuthContext, hasAllPermissions, hasAnyRole, hasPermission, hasRole, isAuthenticated, requireAuth, requirePermission, requireRole, requireUser, runWithAuthContext, } from "./authContext.js";
|
|
28
28
|
export { RequestContext, NEUROLINK_RESOURCE_ID_KEY, NEUROLINK_THREAD_ID_KEY, } from "./RequestContext.js";
|
|
29
29
|
export { createAuthValidatorFromProvider } from "./serverBridge.js";
|
|
30
|
+
export { Auth0Provider } from "./providers/auth0.js";
|
|
31
|
+
export { BetterAuthProvider } from "./providers/betterAuth.js";
|
|
32
|
+
export { ClerkProvider } from "./providers/clerk.js";
|
|
33
|
+
export { CognitoProvider } from "./providers/CognitoProvider.js";
|
|
34
|
+
export { CustomAuthProvider } from "./providers/custom.js";
|
|
35
|
+
export { FirebaseAuthProvider } from "./providers/firebase.js";
|
|
36
|
+
export { JWTProvider } from "./providers/jwt.js";
|
|
37
|
+
export { KeycloakProvider } from "./providers/KeycloakProvider.js";
|
|
38
|
+
export { OAuth2Provider } from "./providers/oauth2.js";
|
|
39
|
+
export { SupabaseAuthProvider } from "./providers/supabase.js";
|
|
40
|
+
export { WorkOSProvider } from "./providers/workos.js";
|
package/dist/lib/auth/index.js
CHANGED
|
@@ -65,4 +65,18 @@ export { RequestContext, NEUROLINK_RESOURCE_ID_KEY, NEUROLINK_THREAD_ID_KEY, } f
|
|
|
65
65
|
// Auth Types
|
|
66
66
|
// Server Bridge
|
|
67
67
|
export { createAuthValidatorFromProvider } from "./serverBridge.js";
|
|
68
|
+
// =============================================================================
|
|
69
|
+
// AUTH PROVIDER CLASSES — public re-exports (match the module docstring above)
|
|
70
|
+
// =============================================================================
|
|
71
|
+
export { Auth0Provider } from "./providers/auth0.js";
|
|
72
|
+
export { BetterAuthProvider } from "./providers/betterAuth.js";
|
|
73
|
+
export { ClerkProvider } from "./providers/clerk.js";
|
|
74
|
+
export { CognitoProvider } from "./providers/CognitoProvider.js";
|
|
75
|
+
export { CustomAuthProvider } from "./providers/custom.js";
|
|
76
|
+
export { FirebaseAuthProvider } from "./providers/firebase.js";
|
|
77
|
+
export { JWTProvider } from "./providers/jwt.js";
|
|
78
|
+
export { KeycloakProvider } from "./providers/KeycloakProvider.js";
|
|
79
|
+
export { OAuth2Provider } from "./providers/oauth2.js";
|
|
80
|
+
export { SupabaseAuthProvider } from "./providers/supabase.js";
|
|
81
|
+
export { WorkOSProvider } from "./providers/workos.js";
|
|
68
82
|
//# sourceMappingURL=index.js.map
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - RBAC enforcement
|
|
8
8
|
* - Public route handling
|
|
9
9
|
*/
|
|
10
|
-
import type {
|
|
10
|
+
import type { AuthMiddlewareConfig, AuthMiddlewareHandler, AuthRequestContext, AuthenticatedContext, ExpressMiddleware, IncomingRequest, RBACMiddlewareConfig, TokenExtractionConfig } from "../../types/index.js";
|
|
11
11
|
/**
|
|
12
12
|
* Auth middleware error codes
|
|
13
13
|
*/
|
|
@@ -31,66 +31,12 @@ export declare const AuthMiddlewareError: {
|
|
|
31
31
|
readonly PROVIDER_ERROR: "AUTH_MIDDLEWARE-005";
|
|
32
32
|
readonly CONFIGURATION_ERROR: "AUTH_MIDDLEWARE-006";
|
|
33
33
|
};
|
|
34
|
-
create: (code: "
|
|
34
|
+
create: (code: "UNAUTHORIZED" | "FORBIDDEN" | "CONFIGURATION_ERROR" | "PROVIDER_ERROR" | "INVALID_TOKEN" | "MISSING_TOKEN", message: string, options?: {
|
|
35
35
|
retryable?: boolean;
|
|
36
36
|
details?: Record<string, unknown>;
|
|
37
37
|
cause?: Error;
|
|
38
38
|
} | undefined) => import("../../core/infrastructure/baseError.js").NeuroLinkFeatureError;
|
|
39
39
|
};
|
|
40
|
-
/**
|
|
41
|
-
* Minimal request object accepted by {@link createRequestContext}.
|
|
42
|
-
*
|
|
43
|
-
* Avoids `any` for Express/Koa/Hono request objects while remaining
|
|
44
|
-
* compatible with any framework that exposes these standard fields.
|
|
45
|
-
*/
|
|
46
|
-
type IncomingRequest = {
|
|
47
|
-
method?: string;
|
|
48
|
-
url?: string;
|
|
49
|
-
path?: string;
|
|
50
|
-
headers?: Record<string, string | string[] | undefined>;
|
|
51
|
-
cookies?: Record<string, string>;
|
|
52
|
-
query?: Record<string, string | string[] | undefined>;
|
|
53
|
-
body?: unknown;
|
|
54
|
-
ip?: string;
|
|
55
|
-
/** Populated by auth middleware after successful authentication */
|
|
56
|
-
user?: AuthUser;
|
|
57
|
-
/** Populated by auth middleware after successful authentication */
|
|
58
|
-
authContext?: AuthenticatedContext;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Minimal response object for Express-style middleware.
|
|
62
|
-
*/
|
|
63
|
-
type OutgoingResponse = {
|
|
64
|
-
status(code: number): OutgoingResponse;
|
|
65
|
-
json(body: unknown): void;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Middleware handler function type
|
|
69
|
-
*/
|
|
70
|
-
type MiddlewareHandler<TContext = AuthRequestContext> = (context: TContext) => Promise<MiddlewareResult>;
|
|
71
|
-
/**
|
|
72
|
-
* Middleware result
|
|
73
|
-
*/
|
|
74
|
-
type MiddlewareResult = {
|
|
75
|
-
/** Whether to proceed to next handler */
|
|
76
|
-
proceed: boolean;
|
|
77
|
-
/** Updated context (if authenticated) */
|
|
78
|
-
context?: AuthenticatedContext;
|
|
79
|
-
/** Error response if not proceeding */
|
|
80
|
-
error?: {
|
|
81
|
-
statusCode: number;
|
|
82
|
-
message: string;
|
|
83
|
-
code?: string;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Next function for middleware chaining
|
|
88
|
-
*/
|
|
89
|
-
type NextFunction = () => Promise<void>;
|
|
90
|
-
/**
|
|
91
|
-
* Express-style middleware function
|
|
92
|
-
*/
|
|
93
|
-
type ExpressMiddleware = (req: IncomingRequest, res: OutgoingResponse, next: NextFunction) => Promise<void>;
|
|
94
40
|
/**
|
|
95
41
|
* Extract token from request context based on configuration
|
|
96
42
|
*/
|
|
@@ -123,7 +69,7 @@ export declare function extractToken(context: AuthRequestContext, config?: Token
|
|
|
123
69
|
* }
|
|
124
70
|
* ```
|
|
125
71
|
*/
|
|
126
|
-
export declare function createAuthMiddleware(config: AuthMiddlewareConfig): Promise<
|
|
72
|
+
export declare function createAuthMiddleware(config: AuthMiddlewareConfig): Promise<AuthMiddlewareHandler<AuthRequestContext>>;
|
|
127
73
|
/**
|
|
128
74
|
* Create RBAC (Role-Based Access Control) middleware
|
|
129
75
|
*
|
|
@@ -146,7 +92,7 @@ export declare function createAuthMiddleware(config: AuthMiddlewareConfig): Prom
|
|
|
146
92
|
* }
|
|
147
93
|
* ```
|
|
148
94
|
*/
|
|
149
|
-
export declare function createRBACMiddleware(config: RBACMiddlewareConfig):
|
|
95
|
+
export declare function createRBACMiddleware(config: RBACMiddlewareConfig): AuthMiddlewareHandler<AuthenticatedContext>;
|
|
150
96
|
/**
|
|
151
97
|
* Create combined auth + RBAC middleware
|
|
152
98
|
*
|
|
@@ -170,7 +116,7 @@ export declare function createRBACMiddleware(config: RBACMiddlewareConfig): Midd
|
|
|
170
116
|
export declare function createProtectedMiddleware(config: {
|
|
171
117
|
auth: AuthMiddlewareConfig;
|
|
172
118
|
rbac?: RBACMiddlewareConfig;
|
|
173
|
-
}): Promise<
|
|
119
|
+
}): Promise<AuthMiddlewareHandler<AuthRequestContext>>;
|
|
174
120
|
/**
|
|
175
121
|
* Create request context from standard request object
|
|
176
122
|
*/
|
|
@@ -179,4 +125,3 @@ export declare function createRequestContext(req: IncomingRequest): AuthRequestC
|
|
|
179
125
|
* Create Express-compatible middleware
|
|
180
126
|
*/
|
|
181
127
|
export declare function createExpressAuthMiddleware(config: AuthMiddlewareConfig): Promise<ExpressMiddleware>;
|
|
182
|
-
export {};
|
|
@@ -43,6 +43,9 @@ function createAuthErrorInfo(message, code) {
|
|
|
43
43
|
return err;
|
|
44
44
|
}
|
|
45
45
|
// =============================================================================
|
|
46
|
+
// TYPES
|
|
47
|
+
// =============================================================================
|
|
48
|
+
// =============================================================================
|
|
46
49
|
// TOKEN EXTRACTION
|
|
47
50
|
// =============================================================================
|
|
48
51
|
/**
|
|
@@ -1,84 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
* Token bucket state for a single user
|
|
4
|
-
*/
|
|
5
|
-
type TokenBucket = {
|
|
6
|
-
/** Current number of tokens available */
|
|
7
|
-
tokens: number;
|
|
8
|
-
/** Last time tokens were added */
|
|
9
|
-
lastRefill: number;
|
|
10
|
-
/** User identifier */
|
|
11
|
-
userId: string;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Rate limit configuration per user or role
|
|
15
|
-
*/
|
|
16
|
-
type RateLimitConfig = {
|
|
17
|
-
/** Maximum requests allowed in the window */
|
|
18
|
-
maxRequests: number;
|
|
19
|
-
/** Time window in milliseconds */
|
|
20
|
-
windowMs: number;
|
|
21
|
-
/** Optional: Different limits per role (role -> maxRequests) */
|
|
22
|
-
roleLimits?: Record<string, number>;
|
|
23
|
-
/** Optional: Different limits per user ID (userId -> maxRequests) */
|
|
24
|
-
userLimits?: Record<string, number>;
|
|
25
|
-
/** Skip rate limiting for these roles */
|
|
26
|
-
skipRoles?: string[];
|
|
27
|
-
/** Error message when rate limited */
|
|
28
|
-
message?: string;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Rate limit result
|
|
32
|
-
*/
|
|
33
|
-
type RateLimitResult = {
|
|
34
|
-
/** Whether the request is allowed */
|
|
35
|
-
allowed: boolean;
|
|
36
|
-
/** Remaining requests in the current window */
|
|
37
|
-
remaining: number;
|
|
38
|
-
/** Time until the bucket resets (ms) */
|
|
39
|
-
resetIn: number;
|
|
40
|
-
/** Total limit for this user */
|
|
41
|
-
limit: number;
|
|
42
|
-
/** Error message if rate limited */
|
|
43
|
-
error?: string;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Result of an atomic consume operation
|
|
47
|
-
*/
|
|
48
|
-
type AtomicConsumeResult = {
|
|
49
|
-
/** Updated bucket after the operation */
|
|
50
|
-
bucket: TokenBucket;
|
|
51
|
-
/** Whether a token was successfully consumed */
|
|
52
|
-
consumed: boolean;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Interface for rate limit storage backends
|
|
56
|
-
*/
|
|
57
|
-
type RateLimitStorage = {
|
|
58
|
-
/** Get the current bucket for a user */
|
|
59
|
-
getBucket(userId: string): Promise<TokenBucket | null>;
|
|
60
|
-
/** Set the bucket for a user */
|
|
61
|
-
setBucket(userId: string, bucket: TokenBucket): Promise<void>;
|
|
62
|
-
/** Delete a bucket (for cleanup) */
|
|
63
|
-
deleteBucket(userId: string): Promise<void>;
|
|
64
|
-
/** Check storage health */
|
|
65
|
-
healthCheck(): Promise<boolean>;
|
|
66
|
-
/** Cleanup resources */
|
|
67
|
-
cleanup(): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* Atomically refill and consume a token from the bucket.
|
|
70
|
-
*
|
|
71
|
-
* Implementations SHOULD perform the refill-and-consume in a single
|
|
72
|
-
* atomic step (e.g. Lua script for Redis) to prevent race conditions
|
|
73
|
-
* where parallel requests read the same token count and both succeed.
|
|
74
|
-
*
|
|
75
|
-
* The default in-memory implementation is inherently single-threaded,
|
|
76
|
-
* so atomicity comes for free.
|
|
77
|
-
*
|
|
78
|
-
* @returns null when no bucket exists yet (caller should create one)
|
|
79
|
-
*/
|
|
80
|
-
atomicConsume?(userId: string, limit: number, windowMs: number, nowMs: number): Promise<AtomicConsumeResult | null>;
|
|
81
|
-
};
|
|
1
|
+
import type { AtomicConsumeResult, AuthRateLimitConfig, AuthRequestContext, AuthUser, AuthenticatedContext, RateLimitMiddlewareResult, RateLimitResult, RateLimitStorage, TokenBucket } from "../../types/index.js";
|
|
82
2
|
/**
|
|
83
3
|
* In-memory storage for rate limiting (single instance deployments)
|
|
84
4
|
*/
|
|
@@ -136,7 +56,7 @@ export declare class RedisRateLimitStorage implements RateLimitStorage {
|
|
|
136
56
|
export declare class UserRateLimiter {
|
|
137
57
|
private storage;
|
|
138
58
|
private config;
|
|
139
|
-
constructor(config:
|
|
59
|
+
constructor(config: AuthRateLimitConfig, storage?: RateLimitStorage);
|
|
140
60
|
/**
|
|
141
61
|
* Get the rate limit for a specific user based on their roles
|
|
142
62
|
*/
|
|
@@ -175,14 +95,6 @@ export declare class UserRateLimiter {
|
|
|
175
95
|
/**
|
|
176
96
|
* Middleware result type
|
|
177
97
|
*/
|
|
178
|
-
type RateLimitMiddlewareResult = {
|
|
179
|
-
/** Whether to proceed with the request */
|
|
180
|
-
proceed: boolean;
|
|
181
|
-
/** Rate limit result */
|
|
182
|
-
rateLimitResult: RateLimitResult;
|
|
183
|
-
/** Error response if rate limited */
|
|
184
|
-
response?: Response;
|
|
185
|
-
};
|
|
186
98
|
/**
|
|
187
99
|
* Create rate limiting middleware for authenticated requests
|
|
188
100
|
*
|
|
@@ -212,7 +124,7 @@ type RateLimitMiddlewareResult = {
|
|
|
212
124
|
* });
|
|
213
125
|
* ```
|
|
214
126
|
*/
|
|
215
|
-
export declare function createRateLimitByUserMiddleware(config:
|
|
127
|
+
export declare function createRateLimitByUserMiddleware(config: AuthRateLimitConfig, storage?: RateLimitStorage): (context: AuthenticatedContext) => Promise<RateLimitMiddlewareResult>;
|
|
216
128
|
/**
|
|
217
129
|
* Create a combined auth and rate limit middleware
|
|
218
130
|
*
|
|
@@ -242,7 +154,7 @@ export declare function createAuthenticatedRateLimitMiddleware(authMiddleware: (
|
|
|
242
154
|
proceed: boolean;
|
|
243
155
|
context?: AuthenticatedContext;
|
|
244
156
|
response?: Response;
|
|
245
|
-
}>, rateLimitConfig:
|
|
157
|
+
}>, rateLimitConfig: AuthRateLimitConfig, storage?: RateLimitStorage): (context: AuthRequestContext) => Promise<{
|
|
246
158
|
proceed: boolean;
|
|
247
159
|
context?: AuthenticatedContext;
|
|
248
160
|
rateLimitResult?: RateLimitResult;
|
|
@@ -279,4 +191,3 @@ export declare function createRateLimitStorage(config: {
|
|
|
279
191
|
};
|
|
280
192
|
cleanupIntervalMs?: number;
|
|
281
193
|
}): RateLimitStorage;
|
|
282
|
-
export {};
|
|
@@ -217,6 +217,7 @@ export class RedisRateLimitStorage {
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
+
// Type for Redis client (simplified interface)
|
|
220
221
|
/**
|
|
221
222
|
* Token bucket rate limiter implementation
|
|
222
223
|
*
|
|
@@ -406,6 +407,9 @@ export class UserRateLimiter {
|
|
|
406
407
|
await this.storage.cleanup();
|
|
407
408
|
}
|
|
408
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Middleware result type
|
|
412
|
+
*/
|
|
409
413
|
/**
|
|
410
414
|
* Create rate limiting middleware for authenticated requests
|
|
411
415
|
*
|
|
@@ -44,7 +44,7 @@ export declare const AuthProviderError: {
|
|
|
44
44
|
readonly JWKS_FETCH_FAILED: "AUTH-070";
|
|
45
45
|
readonly JWKS_KEY_NOT_FOUND: "AUTH-071";
|
|
46
46
|
};
|
|
47
|
-
create: (code: "INVALID_TOKEN" | "EXPIRED_TOKEN" | "MISSING_TOKEN" | "TOKEN_DECODE_FAILED" | "INVALID_SIGNATURE" | "
|
|
47
|
+
create: (code: "SESSION_NOT_FOUND" | "RATE_LIMITED" | "CONFIGURATION_ERROR" | "PROVIDER_ERROR" | "INVALID_TOKEN" | "EXPIRED_TOKEN" | "MISSING_TOKEN" | "TOKEN_DECODE_FAILED" | "INVALID_SIGNATURE" | "SESSION_EXPIRED" | "SESSION_REVOKED" | "INSUFFICIENT_PERMISSIONS" | "INSUFFICIENT_ROLES" | "ACCESS_DENIED" | "USER_NOT_FOUND" | "USER_DISABLED" | "EMAIL_NOT_VERIFIED" | "MFA_REQUIRED" | "PROVIDER_NOT_FOUND" | "PROVIDER_INIT_FAILED" | "CREATION_FAILED" | "REGISTRATION_FAILED" | "DUPLICATE_REGISTRATION" | "MIDDLEWARE_ERROR" | "JWKS_FETCH_FAILED" | "JWKS_KEY_NOT_FOUND", message: string, options?: {
|
|
48
48
|
retryable?: boolean;
|
|
49
49
|
details?: Record<string, unknown>;
|
|
50
50
|
cause?: Error;
|
|
@@ -7,6 +7,9 @@ import { importJWK, jwtVerify } from "jose";
|
|
|
7
7
|
import { logger } from "../../utils/logger.js";
|
|
8
8
|
import { AuthError } from "../errors.js";
|
|
9
9
|
import { BaseAuthProvider } from "./BaseAuthProvider.js";
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// JWKS CACHE
|
|
12
|
+
// =============================================================================
|
|
10
13
|
const jwksCache = new Map();
|
|
11
14
|
// =============================================================================
|
|
12
15
|
// COGNITO PROVIDER
|
|
@@ -7,6 +7,9 @@ import { importJWK, jwtVerify } from "jose";
|
|
|
7
7
|
import { logger } from "../../utils/logger.js";
|
|
8
8
|
import { AuthError } from "../errors.js";
|
|
9
9
|
import { BaseAuthProvider } from "./BaseAuthProvider.js";
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// JWKS CACHE
|
|
12
|
+
// =============================================================================
|
|
10
13
|
const jwksCache = new Map();
|
|
11
14
|
// =============================================================================
|
|
12
15
|
// KEYCLOAK PROVIDER
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseAuthProvider } from "./BaseAuthProvider.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Auth0Config, AuthHealthCheck, AuthProviderConfig, AuthProviderType, AuthRequestContext, AuthUser, TokenValidationResult } from "../../types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Auth0 Authentication Provider
|
|
5
5
|
*
|
|
@@ -67,12 +67,14 @@ export declare class SessionManager {
|
|
|
67
67
|
userAgent?: string;
|
|
68
68
|
deviceId?: string;
|
|
69
69
|
}): Promise<AuthSession>;
|
|
70
|
+
private _createSession;
|
|
70
71
|
/**
|
|
71
72
|
* Get a session by ID
|
|
72
73
|
*
|
|
73
74
|
* Optionally auto-refreshes if close to expiration.
|
|
74
75
|
*/
|
|
75
76
|
getSession(sessionId: string, autoRefresh?: boolean | undefined): Promise<AuthSession | null>;
|
|
77
|
+
private _getSession;
|
|
76
78
|
/**
|
|
77
79
|
* Check if session should be refreshed
|
|
78
80
|
*/
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// src/lib/auth/sessionManager.ts
|
|
2
2
|
import { withTimeout } from "../utils/async/withTimeout.js";
|
|
3
3
|
import { logger } from "../utils/logger.js";
|
|
4
|
+
import { withSpan } from "../telemetry/withSpan.js";
|
|
5
|
+
import { tracers } from "../telemetry/tracers.js";
|
|
4
6
|
/** Mask an identifier for safe logging: show first 4 chars + "***" */
|
|
5
7
|
function maskId(id) {
|
|
6
8
|
if (id.length <= 4) {
|
|
@@ -333,6 +335,16 @@ export class SessionManager {
|
|
|
333
335
|
* Create a new session
|
|
334
336
|
*/
|
|
335
337
|
async createSession(user, metadata) {
|
|
338
|
+
return withSpan({
|
|
339
|
+
name: "neurolink.auth.session.create",
|
|
340
|
+
tracer: tracers.auth,
|
|
341
|
+
attributes: {
|
|
342
|
+
"auth.user_id": maskId(user.id),
|
|
343
|
+
"auth.storage": this.config.storage ?? "memory",
|
|
344
|
+
},
|
|
345
|
+
}, async () => this._createSession(user, metadata));
|
|
346
|
+
}
|
|
347
|
+
async _createSession(user, metadata) {
|
|
336
348
|
const sessionId = crypto.randomUUID();
|
|
337
349
|
const now = new Date();
|
|
338
350
|
const duration = this.config.duration || 3600;
|
|
@@ -356,6 +368,20 @@ export class SessionManager {
|
|
|
356
368
|
* Optionally auto-refreshes if close to expiration.
|
|
357
369
|
*/
|
|
358
370
|
async getSession(sessionId, autoRefresh = this.config.autoRefresh) {
|
|
371
|
+
return withSpan({
|
|
372
|
+
name: "neurolink.auth.session.get",
|
|
373
|
+
tracer: tracers.auth,
|
|
374
|
+
attributes: {
|
|
375
|
+
"auth.session_id": maskId(sessionId),
|
|
376
|
+
"auth.auto_refresh": autoRefresh ?? false,
|
|
377
|
+
},
|
|
378
|
+
}, async (span) => {
|
|
379
|
+
const result = await this._getSession(sessionId, autoRefresh);
|
|
380
|
+
span.setAttribute("auth.found", result !== null);
|
|
381
|
+
return result;
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
async _getSession(sessionId, autoRefresh = this.config.autoRefresh) {
|
|
359
385
|
const session = await this.storage.get(sessionId);
|
|
360
386
|
if (!session) {
|
|
361
387
|
return null;
|
|
@@ -381,15 +407,23 @@ export class SessionManager {
|
|
|
381
407
|
* Refresh a session
|
|
382
408
|
*/
|
|
383
409
|
async refreshSession(sessionId) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
410
|
+
return withSpan({
|
|
411
|
+
name: "neurolink.auth.session.refresh",
|
|
412
|
+
tracer: tracers.auth,
|
|
413
|
+
attributes: { "auth.session_id": maskId(sessionId) },
|
|
414
|
+
}, async (span) => {
|
|
415
|
+
const session = await this.storage.get(sessionId);
|
|
416
|
+
if (!session) {
|
|
417
|
+
span.setAttribute("auth.found", false);
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
const duration = this.config.duration || 3600;
|
|
421
|
+
session.expiresAt = new Date(Date.now() + duration * 1000);
|
|
422
|
+
await this.storage.set(session);
|
|
423
|
+
span.setAttribute("auth.found", true);
|
|
424
|
+
logger.debug(`Session refreshed: ${maskId(sessionId)}`);
|
|
425
|
+
return session;
|
|
426
|
+
});
|
|
393
427
|
}
|
|
394
428
|
/**
|
|
395
429
|
* Destroy a session
|
|
@@ -415,8 +449,16 @@ export class SessionManager {
|
|
|
415
449
|
* Validate a session is still active
|
|
416
450
|
*/
|
|
417
451
|
async validateSession(sessionId) {
|
|
418
|
-
|
|
419
|
-
|
|
452
|
+
return withSpan({
|
|
453
|
+
name: "neurolink.auth.session.validate",
|
|
454
|
+
tracer: tracers.auth,
|
|
455
|
+
attributes: { "auth.session_id": maskId(sessionId) },
|
|
456
|
+
}, async (span) => {
|
|
457
|
+
const session = await this.storage.get(sessionId);
|
|
458
|
+
const valid = session !== null && session.isValid;
|
|
459
|
+
span.setAttribute("auth.valid", valid);
|
|
460
|
+
return valid;
|
|
461
|
+
});
|
|
420
462
|
}
|
|
421
463
|
/**
|
|
422
464
|
* Update session metadata
|
|
@@ -107,6 +107,7 @@ export declare class TokenStore {
|
|
|
107
107
|
* @throws TokenStoreError if deletion fails
|
|
108
108
|
*/
|
|
109
109
|
clearTokens(provider: string): Promise<void>;
|
|
110
|
+
private _clearTokensImpl;
|
|
110
111
|
/**
|
|
111
112
|
* Checks if the given tokens are expired
|
|
112
113
|
*
|
|
@@ -126,6 +127,7 @@ export declare class TokenStore {
|
|
|
126
127
|
* @throws TokenStoreError if refresh fails
|
|
127
128
|
*/
|
|
128
129
|
getValidToken(provider: string): Promise<string | null>;
|
|
130
|
+
private _getValidTokenImpl;
|
|
129
131
|
/**
|
|
130
132
|
* Sets the token refresher function for a provider
|
|
131
133
|
*
|
|
@@ -19,6 +19,8 @@ import { createHash } from "crypto";
|
|
|
19
19
|
import { logger } from "../utils/logger.js";
|
|
20
20
|
import { TokenStoreError } from "../types/index.js";
|
|
21
21
|
import { AsyncMutex } from "../utils/asyncMutex.js";
|
|
22
|
+
import { withSpan } from "../telemetry/withSpan.js";
|
|
23
|
+
import { tracers } from "../telemetry/tracers.js";
|
|
22
24
|
const { readFile, writeFile, mkdir, unlink, access, chmod, rename } = fs;
|
|
23
25
|
// =============================================================================
|
|
24
26
|
// TOKEN STORE CLASS
|
|
@@ -106,9 +108,17 @@ export class TokenStore {
|
|
|
106
108
|
* @throws TokenStoreError if storage fails
|
|
107
109
|
*/
|
|
108
110
|
async saveTokens(provider, tokens) {
|
|
109
|
-
return
|
|
111
|
+
return withSpan({
|
|
112
|
+
name: "neurolink.auth.token.save",
|
|
113
|
+
tracer: tracers.auth,
|
|
114
|
+
attributes: {
|
|
115
|
+
"auth.provider": provider,
|
|
116
|
+
"auth.has_refresh_token": Boolean(tokens.refreshToken),
|
|
117
|
+
"auth.token_type": tokens.tokenType,
|
|
118
|
+
},
|
|
119
|
+
}, async () => this._mutex.runExclusive(async () => {
|
|
110
120
|
await this._saveTokensInternal(provider, tokens);
|
|
111
|
-
});
|
|
121
|
+
}));
|
|
112
122
|
}
|
|
113
123
|
/**
|
|
114
124
|
* Internal save without mutex — callers must already hold the mutex.
|
|
@@ -178,8 +188,19 @@ export class TokenStore {
|
|
|
178
188
|
* @throws TokenStoreError if reading fails (other than file not found)
|
|
179
189
|
*/
|
|
180
190
|
async loadTokens(provider) {
|
|
181
|
-
return
|
|
182
|
-
|
|
191
|
+
return withSpan({
|
|
192
|
+
name: "neurolink.auth.token.load",
|
|
193
|
+
tracer: tracers.auth,
|
|
194
|
+
attributes: { "auth.provider": provider },
|
|
195
|
+
}, async (span) => {
|
|
196
|
+
const result = await this._mutex.runExclusive(async () => {
|
|
197
|
+
return this._loadTokensInternal(provider);
|
|
198
|
+
});
|
|
199
|
+
span.setAttribute("auth.found", result !== null);
|
|
200
|
+
if (result) {
|
|
201
|
+
span.setAttribute("auth.expired", this.isTokenExpired(result, 0));
|
|
202
|
+
}
|
|
203
|
+
return result;
|
|
183
204
|
});
|
|
184
205
|
}
|
|
185
206
|
/**
|
|
@@ -217,6 +238,13 @@ export class TokenStore {
|
|
|
217
238
|
* @throws TokenStoreError if deletion fails
|
|
218
239
|
*/
|
|
219
240
|
async clearTokens(provider) {
|
|
241
|
+
return withSpan({
|
|
242
|
+
name: "neurolink.auth.token.clear",
|
|
243
|
+
tracer: tracers.auth,
|
|
244
|
+
attributes: { "auth.provider": provider },
|
|
245
|
+
}, async () => this._clearTokensImpl(provider));
|
|
246
|
+
}
|
|
247
|
+
async _clearTokensImpl(provider) {
|
|
220
248
|
return this._mutex.runExclusive(async () => {
|
|
221
249
|
// Clear in-memory refresh state so re-adding an account starts fresh
|
|
222
250
|
this.inFlightRefreshes.delete(provider);
|
|
@@ -274,6 +302,13 @@ export class TokenStore {
|
|
|
274
302
|
* @throws TokenStoreError if refresh fails
|
|
275
303
|
*/
|
|
276
304
|
async getValidToken(provider) {
|
|
305
|
+
return withSpan({
|
|
306
|
+
name: "neurolink.auth.token.get_valid",
|
|
307
|
+
tracer: tracers.auth,
|
|
308
|
+
attributes: { "auth.provider": provider },
|
|
309
|
+
}, async (span) => this._getValidTokenImpl(provider, span));
|
|
310
|
+
}
|
|
311
|
+
async _getValidTokenImpl(provider, span) {
|
|
277
312
|
// Phase 1: Read token under mutex (fast)
|
|
278
313
|
const snapshot = await this._mutex.runExclusive(async () => {
|
|
279
314
|
const tokens = await this._loadTokensInternal(provider);
|
|
@@ -283,13 +318,18 @@ export class TokenStore {
|
|
|
283
318
|
return { ...tokens };
|
|
284
319
|
});
|
|
285
320
|
if (!snapshot) {
|
|
321
|
+
span.setAttribute("auth.found", false);
|
|
286
322
|
logger.debug("No tokens found for provider", { provider });
|
|
287
323
|
return null;
|
|
288
324
|
}
|
|
325
|
+
span.setAttribute("auth.found", true);
|
|
289
326
|
// Token is still valid — return immediately
|
|
290
327
|
if (!this.isTokenExpired(snapshot)) {
|
|
328
|
+
span.setAttribute("auth.refreshed", false);
|
|
329
|
+
span.setAttribute("auth.expired", false);
|
|
291
330
|
return snapshot.accessToken;
|
|
292
331
|
}
|
|
332
|
+
span.setAttribute("auth.expired", true);
|
|
293
333
|
logger.debug("Token expired or expiring soon", {
|
|
294
334
|
provider,
|
|
295
335
|
expiresAt: new Date(snapshot.expiresAt).toISOString(),
|
|
@@ -368,6 +408,7 @@ export class TokenStore {
|
|
|
368
408
|
this.inFlightRefreshes.set(provider, refreshPromise);
|
|
369
409
|
try {
|
|
370
410
|
const newTokens = await refreshPromise;
|
|
411
|
+
span.setAttribute("auth.refreshed", true);
|
|
371
412
|
return newTokens.accessToken;
|
|
372
413
|
}
|
|
373
414
|
finally {
|
|
@@ -7,21 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module autoresearch/tools
|
|
9
9
|
*/
|
|
10
|
-
import type { ExperimentRecord,
|
|
11
|
-
import type { RepoPolicy } from "./repoPolicy.js";
|
|
12
|
-
import type { ResultRecorder } from "./resultRecorder.js";
|
|
13
|
-
import type { ExperimentRunner } from "./runner.js";
|
|
14
|
-
import type { ResearchStateStore } from "./stateStore.js";
|
|
15
|
-
/**
|
|
16
|
-
* Dependencies required to create research tools.
|
|
17
|
-
*/
|
|
18
|
-
type ResearchToolsDeps = {
|
|
19
|
-
config: ResearchConfig;
|
|
20
|
-
stateStore: ResearchStateStore;
|
|
21
|
-
repoPolicy: RepoPolicy;
|
|
22
|
-
runner: ExperimentRunner;
|
|
23
|
-
recorder: ResultRecorder;
|
|
24
|
-
};
|
|
10
|
+
import type { ExperimentRecord, ResearchToolsDeps } from "../types/index.js";
|
|
25
11
|
/**
|
|
26
12
|
* Create research management tools bound to a research session.
|
|
27
13
|
*
|
|
@@ -251,4 +237,3 @@ export declare function createResearchTools(deps: ResearchToolsDeps): {
|
|
|
251
237
|
error?: undefined;
|
|
252
238
|
}>;
|
|
253
239
|
};
|
|
254
|
-
export {};
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module @neurolink/ai-sdk
|
|
9
9
|
*/
|
|
10
|
-
import type { ClientLanguageModel, ClientLanguageModelCallOptions, ClientLanguageModelResponse, ClientLanguageModelStreamResponse,
|
|
10
|
+
import type { ClientLanguageModel, ClientLanguageModelCallOptions, ClientLanguageModelResponse, ClientLanguageModelStreamResponse, ClientModelOptions, NeuroLinkProviderOptions } from "../types/index.js";
|
|
11
11
|
import { NeuroLinkClient } from "./httpClient.js";
|
|
12
12
|
/**
|
|
13
13
|
* NeuroLink Language Model implementation compatible with Vercel AI SDK
|
|
@@ -107,6 +107,7 @@ export class NeuroLinkLanguageModel {
|
|
|
107
107
|
}
|
|
108
108
|
// Extract system message if present
|
|
109
109
|
const systemPrompt = system ?? messages?.find((m) => m.role === "system")?.content;
|
|
110
|
+
// ---- Async queue (push/pull pattern) ----
|
|
110
111
|
const buffer = [];
|
|
111
112
|
let finished = false;
|
|
112
113
|
let notifyConsumer = null;
|