@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.
- package/CHANGELOG.md +12 -0
- package/README.md +15 -15
- package/dist/adapters/video/videoAnalyzer.d.ts +1 -1
- package/dist/adapters/video/videoAnalyzer.js +10 -8
- 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/commands/setup-anthropic.js +1 -14
- package/dist/cli/commands/setup-azure.js +1 -12
- package/dist/cli/commands/setup-bedrock.js +1 -9
- package/dist/cli/commands/setup-google-ai.js +1 -12
- package/dist/cli/commands/setup-openai.js +1 -14
- package/dist/cli/commands/workflow.d.ts +27 -0
- package/dist/cli/commands/workflow.js +216 -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 +171 -22
- package/dist/cli/index.js +0 -1
- package/dist/cli/parser.js +14 -2
- package/dist/cli/utils/maskCredential.d.ts +11 -0
- package/dist/cli/utils/maskCredential.js +23 -0
- package/dist/constants/contextWindows.js +107 -16
- package/dist/constants/enums.d.ts +119 -15
- package/dist/constants/enums.js +182 -22
- package/dist/constants/index.d.ts +3 -1
- package/dist/constants/index.js +11 -1
- package/dist/context/budgetChecker.js +1 -1
- package/dist/context/contextCompactor.js +31 -4
- package/dist/context/emergencyTruncation.d.ts +21 -0
- package/dist/context/emergencyTruncation.js +88 -0
- package/dist/context/errorDetection.d.ts +16 -0
- package/dist/context/errorDetection.js +48 -1
- package/dist/context/errors.d.ts +19 -0
- package/dist/context/errors.js +21 -0
- package/dist/context/stages/slidingWindowTruncator.d.ts +6 -0
- package/dist/context/stages/slidingWindowTruncator.js +159 -24
- package/dist/core/baseProvider.js +306 -200
- package/dist/core/conversationMemoryManager.js +104 -61
- package/dist/core/evaluationProviders.js +16 -33
- package/dist/core/factory.js +237 -164
- package/dist/core/modules/GenerationHandler.js +175 -116
- package/dist/core/modules/MessageBuilder.js +222 -170
- package/dist/core/modules/StreamHandler.d.ts +1 -0
- package/dist/core/modules/StreamHandler.js +95 -27
- package/dist/core/modules/TelemetryHandler.d.ts +10 -1
- package/dist/core/modules/TelemetryHandler.js +25 -7
- package/dist/core/modules/ToolsManager.js +115 -191
- package/dist/core/redisConversationMemoryManager.js +418 -282
- package/dist/factories/providerRegistry.d.ts +5 -0
- package/dist/factories/providerRegistry.js +20 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -2
- package/dist/lib/adapters/video/videoAnalyzer.d.ts +1 -1
- package/dist/lib/adapters/video/videoAnalyzer.js +10 -8
- 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/contextWindows.js +107 -16
- package/dist/lib/constants/enums.d.ts +119 -15
- package/dist/lib/constants/enums.js +182 -22
- package/dist/lib/constants/index.d.ts +3 -1
- package/dist/lib/constants/index.js +11 -1
- package/dist/lib/context/budgetChecker.js +1 -1
- package/dist/lib/context/contextCompactor.js +31 -4
- package/dist/lib/context/emergencyTruncation.d.ts +21 -0
- package/dist/lib/context/emergencyTruncation.js +89 -0
- package/dist/lib/context/errorDetection.d.ts +16 -0
- package/dist/lib/context/errorDetection.js +48 -1
- package/dist/lib/context/errors.d.ts +19 -0
- package/dist/lib/context/errors.js +22 -0
- package/dist/lib/context/stages/slidingWindowTruncator.d.ts +6 -0
- package/dist/lib/context/stages/slidingWindowTruncator.js +159 -24
- package/dist/lib/core/baseProvider.js +306 -200
- package/dist/lib/core/conversationMemoryManager.js +104 -61
- package/dist/lib/core/evaluationProviders.js +16 -33
- package/dist/lib/core/factory.js +237 -164
- package/dist/lib/core/modules/GenerationHandler.js +175 -116
- package/dist/lib/core/modules/MessageBuilder.js +222 -170
- package/dist/lib/core/modules/StreamHandler.d.ts +1 -0
- package/dist/lib/core/modules/StreamHandler.js +95 -27
- package/dist/lib/core/modules/TelemetryHandler.d.ts +10 -1
- package/dist/lib/core/modules/TelemetryHandler.js +25 -7
- package/dist/lib/core/modules/ToolsManager.js +115 -191
- package/dist/lib/core/redisConversationMemoryManager.js +418 -282
- package/dist/lib/factories/providerRegistry.d.ts +5 -0
- package/dist/lib/factories/providerRegistry.js +20 -2
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +4 -2
- package/dist/lib/mcp/externalServerManager.js +66 -0
- package/dist/lib/mcp/mcpCircuitBreaker.js +24 -0
- package/dist/lib/mcp/mcpClientFactory.js +16 -0
- package/dist/lib/mcp/toolDiscoveryService.js +32 -6
- package/dist/lib/mcp/toolRegistry.js +193 -123
- package/dist/lib/models/anthropicModels.d.ts +267 -0
- package/dist/lib/models/anthropicModels.js +528 -0
- package/dist/lib/neurolink.d.ts +6 -0
- package/dist/lib/neurolink.js +1162 -646
- package/dist/lib/providers/amazonBedrock.d.ts +1 -1
- package/dist/lib/providers/amazonBedrock.js +521 -319
- package/dist/lib/providers/anthropic.d.ts +123 -2
- package/dist/lib/providers/anthropic.js +873 -27
- package/dist/lib/providers/anthropicBaseProvider.js +77 -17
- package/dist/lib/providers/googleAiStudio.d.ts +1 -1
- package/dist/lib/providers/googleAiStudio.js +292 -227
- package/dist/lib/providers/googleVertex.d.ts +36 -1
- package/dist/lib/providers/googleVertex.js +553 -260
- package/dist/lib/providers/ollama.js +329 -278
- package/dist/lib/providers/openAI.js +77 -19
- package/dist/lib/providers/sagemaker/parsers.js +3 -3
- package/dist/lib/providers/sagemaker/streaming.js +3 -3
- package/dist/lib/proxy/proxyFetch.js +81 -48
- package/dist/lib/rag/ChunkerFactory.js +1 -1
- package/dist/lib/rag/chunkers/MarkdownChunker.d.ts +22 -0
- package/dist/lib/rag/chunkers/MarkdownChunker.js +213 -9
- package/dist/lib/rag/chunking/markdownChunker.d.ts +16 -0
- package/dist/lib/rag/chunking/markdownChunker.js +174 -2
- package/dist/lib/rag/pipeline/contextAssembly.js +2 -1
- package/dist/lib/rag/ragIntegration.d.ts +18 -1
- package/dist/lib/rag/ragIntegration.js +94 -14
- package/dist/lib/rag/retrieval/vectorQueryTool.js +21 -4
- package/dist/lib/server/abstract/baseServerAdapter.js +4 -1
- package/dist/lib/server/adapters/fastifyAdapter.js +35 -30
- package/dist/lib/services/server/ai/observability/instrumentation.d.ts +32 -0
- package/dist/lib/services/server/ai/observability/instrumentation.js +39 -0
- package/dist/lib/telemetry/attributes.d.ts +52 -0
- package/dist/lib/telemetry/attributes.js +61 -0
- package/dist/lib/telemetry/index.d.ts +3 -0
- package/dist/lib/telemetry/index.js +3 -0
- package/dist/lib/telemetry/telemetryService.d.ts +6 -0
- package/dist/lib/telemetry/telemetryService.js +6 -0
- package/dist/lib/telemetry/tracers.d.ts +15 -0
- package/dist/lib/telemetry/tracers.js +17 -0
- package/dist/lib/telemetry/withSpan.d.ts +9 -0
- package/dist/lib/telemetry/withSpan.js +35 -0
- package/dist/lib/types/contextTypes.d.ts +10 -0
- 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/streamTypes.d.ts +14 -0
- package/dist/lib/types/subscriptionTypes.d.ts +893 -0
- package/dist/lib/types/subscriptionTypes.js +8 -0
- package/dist/lib/utils/conversationMemory.js +121 -82
- package/dist/lib/utils/logger.d.ts +5 -0
- package/dist/lib/utils/logger.js +50 -2
- package/dist/lib/utils/messageBuilder.js +22 -42
- package/dist/lib/utils/modelDetection.js +3 -3
- package/dist/lib/utils/providerConfig.d.ts +167 -0
- package/dist/lib/utils/providerConfig.js +619 -9
- package/dist/lib/utils/providerRetry.d.ts +41 -0
- package/dist/lib/utils/providerRetry.js +114 -0
- package/dist/lib/utils/retryability.d.ts +14 -0
- package/dist/lib/utils/retryability.js +23 -0
- package/dist/lib/utils/sanitizers/svg.js +4 -5
- package/dist/lib/utils/tokenEstimation.d.ts +11 -1
- package/dist/lib/utils/tokenEstimation.js +19 -4
- package/dist/lib/utils/videoAnalysisProcessor.js +7 -3
- package/dist/mcp/externalServerManager.js +66 -0
- package/dist/mcp/mcpCircuitBreaker.js +24 -0
- package/dist/mcp/mcpClientFactory.js +16 -0
- package/dist/mcp/toolDiscoveryService.js +32 -6
- package/dist/mcp/toolRegistry.js +193 -123
- package/dist/models/anthropicModels.d.ts +267 -0
- package/dist/models/anthropicModels.js +527 -0
- package/dist/neurolink.d.ts +6 -0
- package/dist/neurolink.js +1162 -646
- package/dist/providers/amazonBedrock.d.ts +1 -1
- package/dist/providers/amazonBedrock.js +521 -319
- package/dist/providers/anthropic.d.ts +123 -2
- package/dist/providers/anthropic.js +873 -27
- package/dist/providers/anthropicBaseProvider.js +77 -17
- package/dist/providers/googleAiStudio.d.ts +1 -1
- package/dist/providers/googleAiStudio.js +292 -227
- package/dist/providers/googleVertex.d.ts +36 -1
- package/dist/providers/googleVertex.js +553 -260
- package/dist/providers/ollama.js +329 -278
- package/dist/providers/openAI.js +77 -19
- package/dist/providers/sagemaker/parsers.js +3 -3
- package/dist/providers/sagemaker/streaming.js +3 -3
- package/dist/proxy/proxyFetch.js +81 -48
- package/dist/rag/ChunkerFactory.js +1 -1
- package/dist/rag/chunkers/MarkdownChunker.d.ts +22 -0
- package/dist/rag/chunkers/MarkdownChunker.js +213 -9
- package/dist/rag/chunking/markdownChunker.d.ts +16 -0
- package/dist/rag/chunking/markdownChunker.js +174 -2
- package/dist/rag/pipeline/contextAssembly.js +2 -1
- package/dist/rag/ragIntegration.d.ts +18 -1
- package/dist/rag/ragIntegration.js +94 -14
- package/dist/rag/retrieval/vectorQueryTool.js +21 -4
- package/dist/server/abstract/baseServerAdapter.js +4 -1
- package/dist/server/adapters/fastifyAdapter.js +35 -30
- package/dist/services/server/ai/observability/instrumentation.d.ts +32 -0
- package/dist/services/server/ai/observability/instrumentation.js +39 -0
- package/dist/telemetry/attributes.d.ts +52 -0
- package/dist/telemetry/attributes.js +60 -0
- package/dist/telemetry/index.d.ts +3 -0
- package/dist/telemetry/index.js +3 -0
- package/dist/telemetry/telemetryService.d.ts +6 -0
- package/dist/telemetry/telemetryService.js +6 -0
- package/dist/telemetry/tracers.d.ts +15 -0
- package/dist/telemetry/tracers.js +16 -0
- package/dist/telemetry/withSpan.d.ts +9 -0
- package/dist/telemetry/withSpan.js +34 -0
- package/dist/types/contextTypes.d.ts +10 -0
- 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/streamTypes.d.ts +14 -0
- package/dist/types/subscriptionTypes.d.ts +893 -0
- package/dist/types/subscriptionTypes.js +7 -0
- package/dist/utils/conversationMemory.js +121 -82
- package/dist/utils/logger.d.ts +5 -0
- package/dist/utils/logger.js +50 -2
- package/dist/utils/messageBuilder.js +22 -42
- package/dist/utils/modelDetection.js +3 -3
- package/dist/utils/providerConfig.d.ts +167 -0
- package/dist/utils/providerConfig.js +619 -9
- package/dist/utils/providerRetry.d.ts +41 -0
- package/dist/utils/providerRetry.js +113 -0
- package/dist/utils/retryability.d.ts +14 -0
- package/dist/utils/retryability.js +22 -0
- package/dist/utils/sanitizers/svg.js +4 -5
- package/dist/utils/tokenEstimation.d.ts +11 -1
- package/dist/utils/tokenEstimation.js +19 -4
- package/dist/utils/videoAnalysisProcessor.js +7 -3
- package/dist/workflow/config.d.ts +26 -26
- package/package.json +2 -1
|
@@ -700,6 +700,45 @@ export async function setLangfuseContext(context, callback) {
|
|
|
700
700
|
export function getLangfuseContext() {
|
|
701
701
|
return contextStorage.getStore();
|
|
702
702
|
}
|
|
703
|
+
/**
|
|
704
|
+
* Capture the current Langfuse AsyncLocalStorage context and return a wrapper
|
|
705
|
+
* that re-enters that context when executing the provided callback.
|
|
706
|
+
*
|
|
707
|
+
* This is essential for preserving trace context across async boundaries that
|
|
708
|
+
* break the automatic ALS propagation chain, such as `setImmediate()`,
|
|
709
|
+
* `setTimeout()`, or event-emitter callbacks. Without this, spans created
|
|
710
|
+
* inside those callbacks become orphaned traces in Langfuse.
|
|
711
|
+
*
|
|
712
|
+
* **How it works:**
|
|
713
|
+
* 1. Captures the current ALS store at call time (synchronously).
|
|
714
|
+
* 2. Returns an async function that, when invoked, re-enters the captured
|
|
715
|
+
* context via `contextStorage.run()` before executing the callback.
|
|
716
|
+
* 3. If no context exists at capture time, the callback runs without
|
|
717
|
+
* ALS wrapping (no-op passthrough).
|
|
718
|
+
*
|
|
719
|
+
* @param fn - The async function to execute within the captured context
|
|
720
|
+
* @returns A new async function that preserves the Langfuse ALS context
|
|
721
|
+
*
|
|
722
|
+
* @example
|
|
723
|
+
* // Before (broken — setImmediate loses ALS context):
|
|
724
|
+
* setImmediate(async () => {
|
|
725
|
+
* await this.checkAndSummarize(session, threshold);
|
|
726
|
+
* });
|
|
727
|
+
*
|
|
728
|
+
* // After (fixed — context is captured and re-entered):
|
|
729
|
+
* const wrappedFn = runWithCurrentLangfuseContext(async () => {
|
|
730
|
+
* await this.checkAndSummarize(session, threshold);
|
|
731
|
+
* });
|
|
732
|
+
* setImmediate(wrappedFn);
|
|
733
|
+
*/
|
|
734
|
+
export function runWithCurrentLangfuseContext(fn) {
|
|
735
|
+
const capturedContext = contextStorage.getStore();
|
|
736
|
+
if (capturedContext) {
|
|
737
|
+
return () => contextStorage.run(capturedContext, fn);
|
|
738
|
+
}
|
|
739
|
+
// No context to preserve — return the function as-is
|
|
740
|
+
return fn;
|
|
741
|
+
}
|
|
703
742
|
/**
|
|
704
743
|
* Get an OpenTelemetry Tracer for creating custom spans
|
|
705
744
|
*
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export declare const ATTR: {
|
|
2
|
+
readonly GEN_AI_SYSTEM: "gen_ai.system";
|
|
3
|
+
readonly GEN_AI_MODEL: "gen_ai.request.model";
|
|
4
|
+
readonly GEN_AI_OPERATION: "gen_ai.operation.name";
|
|
5
|
+
readonly GEN_AI_INPUT_TOKENS: "gen_ai.usage.input_tokens";
|
|
6
|
+
readonly GEN_AI_OUTPUT_TOKENS: "gen_ai.usage.output_tokens";
|
|
7
|
+
readonly GEN_AI_FINISH_REASON: "gen_ai.response.finish_reason";
|
|
8
|
+
readonly GEN_AI_COST_USD: "gen_ai.cost_usd";
|
|
9
|
+
readonly GEN_AI_TOOL_NAME: "gen_ai.tool.name";
|
|
10
|
+
readonly GEN_AI_TEMPERATURE: "gen_ai.request.temperature";
|
|
11
|
+
readonly GEN_AI_MAX_TOKENS: "gen_ai.request.max_tokens";
|
|
12
|
+
readonly NL_PROVIDER: "neurolink.provider";
|
|
13
|
+
readonly NL_MODEL: "neurolink.model";
|
|
14
|
+
readonly NL_STREAM_MODE: "neurolink.stream_mode";
|
|
15
|
+
readonly NL_TOOL_COUNT: "neurolink.tool_count";
|
|
16
|
+
readonly NL_MESSAGE_COUNT: "neurolink.message_count";
|
|
17
|
+
readonly NL_HAS_TOOLS: "neurolink.has_tools";
|
|
18
|
+
readonly NL_INPUT_LENGTH: "neurolink.input_length";
|
|
19
|
+
readonly NL_OUTPUT_LENGTH: "neurolink.output_length";
|
|
20
|
+
readonly NL_REQUEST_ID: "neurolink.request_id";
|
|
21
|
+
readonly NL_PATH: "neurolink.path";
|
|
22
|
+
readonly NL_HAS_MEMORY: "neurolink.has_conversation_memory";
|
|
23
|
+
readonly NL_COST: "neurolink.cost";
|
|
24
|
+
readonly NL_STRUCTURED_OUTPUT: "neurolink.structured_output";
|
|
25
|
+
readonly NL_HAS_FALLBACK: "neurolink.has_fallback";
|
|
26
|
+
readonly MCP_SERVER_ID: "mcp.server_id";
|
|
27
|
+
readonly MCP_TOOL_NAME: "mcp.tool_name";
|
|
28
|
+
readonly MCP_TIMEOUT_MS: "mcp.timeout_ms";
|
|
29
|
+
readonly MCP_TRANSPORT: "mcp.transport";
|
|
30
|
+
readonly MCP_CIRCUIT_STATE: "mcp.circuit_state";
|
|
31
|
+
readonly SESSION_ID: "session.id";
|
|
32
|
+
readonly USER_ID: "user.id";
|
|
33
|
+
readonly MEMORY_TYPE: "memory.type";
|
|
34
|
+
readonly MESSAGE_COUNT: "message.count";
|
|
35
|
+
readonly CONTENT_LENGTH: "content.length";
|
|
36
|
+
readonly RAG_FILE_COUNT: "rag.file_count";
|
|
37
|
+
readonly RAG_STRATEGY: "rag.strategy";
|
|
38
|
+
readonly RAG_CHUNK_SIZE: "rag.chunk_size";
|
|
39
|
+
readonly RAG_TOP_K: "rag.top_k";
|
|
40
|
+
readonly RAG_RESULT_COUNT: "rag.result_count";
|
|
41
|
+
readonly MSG_COUNT: "message.build.count";
|
|
42
|
+
readonly MSG_HAS_IMAGES: "message.has_images";
|
|
43
|
+
readonly MSG_HAS_FILES: "message.has_files";
|
|
44
|
+
readonly MSG_HAS_SYSTEM_PROMPT: "message.has_system_prompt";
|
|
45
|
+
readonly MSG_TOTAL_CONTENT_LENGTH: "message.total_content_length";
|
|
46
|
+
readonly MSG_IS_MULTIMODAL: "message.is_multimodal";
|
|
47
|
+
readonly CONTEXT_STAGE: "context.compaction_stage";
|
|
48
|
+
readonly CONTEXT_TOKENS_BEFORE: "context.tokens_before";
|
|
49
|
+
readonly CONTEXT_TOKENS_AFTER: "context.tokens_after";
|
|
50
|
+
readonly MW_COUNT: "middleware.count";
|
|
51
|
+
readonly MW_NAMES: "middleware.names";
|
|
52
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const ATTR = {
|
|
2
|
+
// GenAI standard (OpenTelemetry semantic conventions)
|
|
3
|
+
GEN_AI_SYSTEM: "gen_ai.system",
|
|
4
|
+
GEN_AI_MODEL: "gen_ai.request.model",
|
|
5
|
+
GEN_AI_OPERATION: "gen_ai.operation.name",
|
|
6
|
+
GEN_AI_INPUT_TOKENS: "gen_ai.usage.input_tokens",
|
|
7
|
+
GEN_AI_OUTPUT_TOKENS: "gen_ai.usage.output_tokens",
|
|
8
|
+
GEN_AI_FINISH_REASON: "gen_ai.response.finish_reason",
|
|
9
|
+
GEN_AI_COST_USD: "gen_ai.cost_usd",
|
|
10
|
+
GEN_AI_TOOL_NAME: "gen_ai.tool.name",
|
|
11
|
+
GEN_AI_TEMPERATURE: "gen_ai.request.temperature",
|
|
12
|
+
GEN_AI_MAX_TOKENS: "gen_ai.request.max_tokens",
|
|
13
|
+
// NeuroLink custom
|
|
14
|
+
NL_PROVIDER: "neurolink.provider",
|
|
15
|
+
NL_MODEL: "neurolink.model",
|
|
16
|
+
NL_STREAM_MODE: "neurolink.stream_mode",
|
|
17
|
+
NL_TOOL_COUNT: "neurolink.tool_count",
|
|
18
|
+
NL_MESSAGE_COUNT: "neurolink.message_count",
|
|
19
|
+
NL_HAS_TOOLS: "neurolink.has_tools",
|
|
20
|
+
NL_INPUT_LENGTH: "neurolink.input_length",
|
|
21
|
+
NL_OUTPUT_LENGTH: "neurolink.output_length",
|
|
22
|
+
NL_REQUEST_ID: "neurolink.request_id",
|
|
23
|
+
NL_PATH: "neurolink.path",
|
|
24
|
+
NL_HAS_MEMORY: "neurolink.has_conversation_memory",
|
|
25
|
+
NL_COST: "neurolink.cost",
|
|
26
|
+
NL_STRUCTURED_OUTPUT: "neurolink.structured_output",
|
|
27
|
+
NL_HAS_FALLBACK: "neurolink.has_fallback",
|
|
28
|
+
// MCP
|
|
29
|
+
MCP_SERVER_ID: "mcp.server_id",
|
|
30
|
+
MCP_TOOL_NAME: "mcp.tool_name",
|
|
31
|
+
MCP_TIMEOUT_MS: "mcp.timeout_ms",
|
|
32
|
+
MCP_TRANSPORT: "mcp.transport",
|
|
33
|
+
MCP_CIRCUIT_STATE: "mcp.circuit_state",
|
|
34
|
+
// Session/Memory
|
|
35
|
+
SESSION_ID: "session.id",
|
|
36
|
+
USER_ID: "user.id",
|
|
37
|
+
MEMORY_TYPE: "memory.type",
|
|
38
|
+
MESSAGE_COUNT: "message.count",
|
|
39
|
+
CONTENT_LENGTH: "content.length",
|
|
40
|
+
// RAG
|
|
41
|
+
RAG_FILE_COUNT: "rag.file_count",
|
|
42
|
+
RAG_STRATEGY: "rag.strategy",
|
|
43
|
+
RAG_CHUNK_SIZE: "rag.chunk_size",
|
|
44
|
+
RAG_TOP_K: "rag.top_k",
|
|
45
|
+
RAG_RESULT_COUNT: "rag.result_count",
|
|
46
|
+
// Message building
|
|
47
|
+
MSG_COUNT: "message.build.count",
|
|
48
|
+
MSG_HAS_IMAGES: "message.has_images",
|
|
49
|
+
MSG_HAS_FILES: "message.has_files",
|
|
50
|
+
MSG_HAS_SYSTEM_PROMPT: "message.has_system_prompt",
|
|
51
|
+
MSG_TOTAL_CONTENT_LENGTH: "message.total_content_length",
|
|
52
|
+
MSG_IS_MULTIMODAL: "message.is_multimodal",
|
|
53
|
+
// Context
|
|
54
|
+
CONTEXT_STAGE: "context.compaction_stage",
|
|
55
|
+
CONTEXT_TOKENS_BEFORE: "context.tokens_before",
|
|
56
|
+
CONTEXT_TOKENS_AFTER: "context.tokens_after",
|
|
57
|
+
// Middleware
|
|
58
|
+
MW_COUNT: "middleware.count",
|
|
59
|
+
MW_NAMES: "middleware.names",
|
|
60
|
+
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { TelemetryService, type HealthMetrics } from "./telemetryService.js";
|
|
2
|
+
export { tracers } from "./tracers.js";
|
|
3
|
+
export { withSpan, withClientSpan, type SpanOptions } from "./withSpan.js";
|
|
4
|
+
export { ATTR } from "./attributes.js";
|
|
2
5
|
/**
|
|
3
6
|
* Initialize telemetry for NeuroLink
|
|
4
7
|
* OPTIONAL - Only works when NEUROLINK_TELEMETRY_ENABLED=true
|
package/dist/telemetry/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// Optional Telemetry Infrastructure (Phase 2)
|
|
2
2
|
export { TelemetryService } from "./telemetryService.js";
|
|
3
|
+
export { tracers } from "./tracers.js";
|
|
4
|
+
export { withSpan, withClientSpan } from "./withSpan.js";
|
|
5
|
+
export { ATTR } from "./attributes.js";
|
|
3
6
|
import { logger } from "../utils/logger.js";
|
|
4
7
|
/**
|
|
5
8
|
* Initialize telemetry for NeuroLink
|
|
@@ -32,6 +32,12 @@ export declare class TelemetryService {
|
|
|
32
32
|
private initializeTelemetry;
|
|
33
33
|
private initializeMetrics;
|
|
34
34
|
initialize(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Vercel AI SDK's experimental_telemetry creates ai.generateText/ai.streamText
|
|
37
|
+
* spans automatically via OpenTelemetry. Using this method would create duplicate spans.
|
|
38
|
+
* Kept for potential future use with non-Vercel providers (e.g., Amazon Bedrock).
|
|
39
|
+
* See: TelemetryHandler.getTelemetryConfig() for the active telemetry path.
|
|
40
|
+
*/
|
|
35
41
|
traceAIRequest<T>(provider: string, operation: () => Promise<T>, operationType?: string): Promise<T>;
|
|
36
42
|
recordAIRequest(provider: string, model: string, tokens: number, duration: number, cost?: number): void;
|
|
37
43
|
recordAIError(provider: string, error: Error): void;
|
|
@@ -112,6 +112,12 @@ export class TelemetryService {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
// AI Operation Tracing (NO-OP when disabled)
|
|
115
|
+
/**
|
|
116
|
+
* @deprecated Vercel AI SDK's experimental_telemetry creates ai.generateText/ai.streamText
|
|
117
|
+
* spans automatically via OpenTelemetry. Using this method would create duplicate spans.
|
|
118
|
+
* Kept for potential future use with non-Vercel providers (e.g., Amazon Bedrock).
|
|
119
|
+
* See: TelemetryHandler.getTelemetryConfig() for the active telemetry path.
|
|
120
|
+
*/
|
|
115
121
|
async traceAIRequest(provider, operation, operationType = "generate_text") {
|
|
116
122
|
if (!this.enabled || !this.tracer) {
|
|
117
123
|
return await operation();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const tracers: {
|
|
2
|
+
readonly sdk: import("@opentelemetry/api").Tracer;
|
|
3
|
+
readonly provider: import("@opentelemetry/api").Tracer;
|
|
4
|
+
readonly generation: import("@opentelemetry/api").Tracer;
|
|
5
|
+
readonly stream: import("@opentelemetry/api").Tracer;
|
|
6
|
+
readonly http: import("@opentelemetry/api").Tracer;
|
|
7
|
+
readonly mcp: import("@opentelemetry/api").Tracer;
|
|
8
|
+
readonly memory: import("@opentelemetry/api").Tracer;
|
|
9
|
+
readonly redis: import("@opentelemetry/api").Tracer;
|
|
10
|
+
readonly factory: import("@opentelemetry/api").Tracer;
|
|
11
|
+
readonly rag: import("@opentelemetry/api").Tracer;
|
|
12
|
+
readonly context: import("@opentelemetry/api").Tracer;
|
|
13
|
+
readonly middleware: import("@opentelemetry/api").Tracer;
|
|
14
|
+
readonly processor: import("@opentelemetry/api").Tracer;
|
|
15
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { trace } from "@opentelemetry/api";
|
|
2
|
+
export const tracers = {
|
|
3
|
+
sdk: trace.getTracer("neurolink"),
|
|
4
|
+
provider: trace.getTracer("neurolink.provider"),
|
|
5
|
+
generation: trace.getTracer("neurolink.generation"),
|
|
6
|
+
stream: trace.getTracer("neurolink.stream"),
|
|
7
|
+
http: trace.getTracer("neurolink.http"),
|
|
8
|
+
mcp: trace.getTracer("neurolink.mcp"),
|
|
9
|
+
memory: trace.getTracer("neurolink.memory"),
|
|
10
|
+
redis: trace.getTracer("neurolink.redis"),
|
|
11
|
+
factory: trace.getTracer("neurolink.factory"),
|
|
12
|
+
rag: trace.getTracer("neurolink.rag"),
|
|
13
|
+
context: trace.getTracer("neurolink.context"),
|
|
14
|
+
middleware: trace.getTracer("neurolink.middleware"),
|
|
15
|
+
processor: trace.getTracer("neurolink.processor"),
|
|
16
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Span, type Tracer, SpanKind } from "@opentelemetry/api";
|
|
2
|
+
export type SpanOptions = {
|
|
3
|
+
name: string;
|
|
4
|
+
tracer: Tracer;
|
|
5
|
+
kind?: SpanKind;
|
|
6
|
+
attributes?: Record<string, string | number | boolean | undefined>;
|
|
7
|
+
};
|
|
8
|
+
export declare function withSpan<T>(options: SpanOptions, fn: (span: Span) => Promise<T>): Promise<T>;
|
|
9
|
+
export declare function withClientSpan<T>(options: Omit<SpanOptions, "kind">, fn: (span: Span) => Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SpanKind, SpanStatusCode, } from "@opentelemetry/api";
|
|
2
|
+
export async function withSpan(options, fn) {
|
|
3
|
+
const { name, tracer, kind = SpanKind.INTERNAL, attributes } = options;
|
|
4
|
+
return tracer.startActiveSpan(name, { kind }, async (span) => {
|
|
5
|
+
if (attributes) {
|
|
6
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
7
|
+
if (value !== undefined) {
|
|
8
|
+
span.setAttribute(key, value);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const result = await fn(span);
|
|
14
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
span.setStatus({
|
|
19
|
+
code: SpanStatusCode.ERROR,
|
|
20
|
+
message: error instanceof Error ? error.message : String(error),
|
|
21
|
+
});
|
|
22
|
+
if (error instanceof Error) {
|
|
23
|
+
span.recordException(error);
|
|
24
|
+
}
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
span.end();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export async function withClientSpan(options, fn) {
|
|
33
|
+
return withSpan({ ...options, kind: SpanKind.CLIENT }, fn);
|
|
34
|
+
}
|
|
@@ -424,6 +424,16 @@ export type PruneResult = {
|
|
|
424
424
|
/** Configuration for sliding window truncation (Stage 4). */
|
|
425
425
|
export type TruncationConfig = {
|
|
426
426
|
fraction?: number;
|
|
427
|
+
/** Current estimated tokens (enables adaptive mode) */
|
|
428
|
+
currentTokens?: number;
|
|
429
|
+
/** Target token budget (enables adaptive mode) */
|
|
430
|
+
targetTokens?: number;
|
|
431
|
+
/** Provider for token estimation (enables adaptive mode) */
|
|
432
|
+
provider?: string;
|
|
433
|
+
/** Buffer above required reduction (default: 0.15 = 15%) */
|
|
434
|
+
adaptiveBuffer?: number;
|
|
435
|
+
/** Maximum iterations for adaptive truncation (default: 3) */
|
|
436
|
+
maxIterations?: number;
|
|
427
437
|
};
|
|
428
438
|
/** Result of sliding window truncation (Stage 4). */
|
|
429
439
|
export type TruncationResult = {
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -42,3 +42,65 @@ export declare class RateLimitError extends ProviderError {
|
|
|
42
42
|
export declare class InvalidModelError extends ProviderError {
|
|
43
43
|
constructor(message: string, provider?: string);
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Base class for OAuth-specific errors
|
|
47
|
+
*/
|
|
48
|
+
export declare class OAuthError extends BaseError {
|
|
49
|
+
code?: string | undefined;
|
|
50
|
+
constructor(message: string, code?: string | undefined);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Thrown when OAuth configuration is invalid or missing
|
|
54
|
+
*/
|
|
55
|
+
export declare class OAuthConfigurationError extends OAuthError {
|
|
56
|
+
constructor(message: string);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Thrown when authorization code exchange fails
|
|
60
|
+
*/
|
|
61
|
+
export declare class OAuthTokenExchangeError extends OAuthError {
|
|
62
|
+
statusCode?: number | undefined;
|
|
63
|
+
constructor(message: string, statusCode?: number | undefined);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Thrown when token refresh fails
|
|
67
|
+
*/
|
|
68
|
+
export declare class OAuthTokenRefreshError extends OAuthError {
|
|
69
|
+
statusCode?: number | undefined;
|
|
70
|
+
constructor(message: string, statusCode?: number | undefined);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Thrown when token validation fails
|
|
74
|
+
*/
|
|
75
|
+
export declare class OAuthTokenValidationError extends OAuthError {
|
|
76
|
+
constructor(message: string);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Thrown when token revocation fails
|
|
80
|
+
*/
|
|
81
|
+
export declare class OAuthTokenRevocationError extends OAuthError {
|
|
82
|
+
statusCode?: number | undefined;
|
|
83
|
+
constructor(message: string, statusCode?: number | undefined);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Thrown when callback server operations fail
|
|
87
|
+
*/
|
|
88
|
+
export declare class OAuthCallbackServerError extends OAuthError {
|
|
89
|
+
constructor(message: string);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Token storage error for authentication-related failures
|
|
93
|
+
*/
|
|
94
|
+
export declare class TokenStoreError extends BaseError {
|
|
95
|
+
readonly code: "STORAGE_ERROR" | "ENCRYPTION_ERROR" | "VALIDATION_ERROR" | "NOT_FOUND" | "REFRESH_ERROR";
|
|
96
|
+
constructor(message: string, code?: "STORAGE_ERROR" | "ENCRYPTION_ERROR" | "VALIDATION_ERROR" | "NOT_FOUND" | "REFRESH_ERROR");
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Error thrown when model access is denied based on subscription tier
|
|
100
|
+
*/
|
|
101
|
+
export declare class ModelAccessError extends BaseError {
|
|
102
|
+
readonly model: string;
|
|
103
|
+
readonly tier: string;
|
|
104
|
+
readonly requiredTier: string;
|
|
105
|
+
constructor(model: string, tier: string, requiredTier: string);
|
|
106
|
+
}
|
package/dist/types/errors.js
CHANGED
|
@@ -58,3 +58,110 @@ export class InvalidModelError extends ProviderError {
|
|
|
58
58
|
super(message, provider);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
// =============================================================================
|
|
62
|
+
// OAUTH ERROR CLASSES
|
|
63
|
+
// =============================================================================
|
|
64
|
+
/**
|
|
65
|
+
* Base class for OAuth-specific errors
|
|
66
|
+
*/
|
|
67
|
+
export class OAuthError extends BaseError {
|
|
68
|
+
code;
|
|
69
|
+
constructor(message, code) {
|
|
70
|
+
super(message);
|
|
71
|
+
this.code = code;
|
|
72
|
+
this.name = "OAuthError";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Thrown when OAuth configuration is invalid or missing
|
|
77
|
+
*/
|
|
78
|
+
export class OAuthConfigurationError extends OAuthError {
|
|
79
|
+
constructor(message) {
|
|
80
|
+
super(message, "CONFIGURATION_ERROR");
|
|
81
|
+
this.name = "OAuthConfigurationError";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Thrown when authorization code exchange fails
|
|
86
|
+
*/
|
|
87
|
+
export class OAuthTokenExchangeError extends OAuthError {
|
|
88
|
+
statusCode;
|
|
89
|
+
constructor(message, statusCode) {
|
|
90
|
+
super(message, "TOKEN_EXCHANGE_ERROR");
|
|
91
|
+
this.statusCode = statusCode;
|
|
92
|
+
this.name = "OAuthTokenExchangeError";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Thrown when token refresh fails
|
|
97
|
+
*/
|
|
98
|
+
export class OAuthTokenRefreshError extends OAuthError {
|
|
99
|
+
statusCode;
|
|
100
|
+
constructor(message, statusCode) {
|
|
101
|
+
super(message, "TOKEN_REFRESH_ERROR");
|
|
102
|
+
this.statusCode = statusCode;
|
|
103
|
+
this.name = "OAuthTokenRefreshError";
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Thrown when token validation fails
|
|
108
|
+
*/
|
|
109
|
+
export class OAuthTokenValidationError extends OAuthError {
|
|
110
|
+
constructor(message) {
|
|
111
|
+
super(message, "TOKEN_VALIDATION_ERROR");
|
|
112
|
+
this.name = "OAuthTokenValidationError";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Thrown when token revocation fails
|
|
117
|
+
*/
|
|
118
|
+
export class OAuthTokenRevocationError extends OAuthError {
|
|
119
|
+
statusCode;
|
|
120
|
+
constructor(message, statusCode) {
|
|
121
|
+
super(message, "TOKEN_REVOCATION_ERROR");
|
|
122
|
+
this.statusCode = statusCode;
|
|
123
|
+
this.name = "OAuthTokenRevocationError";
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Thrown when callback server operations fail
|
|
128
|
+
*/
|
|
129
|
+
export class OAuthCallbackServerError extends OAuthError {
|
|
130
|
+
constructor(message) {
|
|
131
|
+
super(message, "CALLBACK_SERVER_ERROR");
|
|
132
|
+
this.name = "OAuthCallbackServerError";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// =============================================================================
|
|
136
|
+
// TOKEN STORE ERROR
|
|
137
|
+
// =============================================================================
|
|
138
|
+
/**
|
|
139
|
+
* Token storage error for authentication-related failures
|
|
140
|
+
*/
|
|
141
|
+
export class TokenStoreError extends BaseError {
|
|
142
|
+
code;
|
|
143
|
+
constructor(message, code = "STORAGE_ERROR") {
|
|
144
|
+
super(message);
|
|
145
|
+
this.code = code;
|
|
146
|
+
this.name = "TokenStoreError";
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// =============================================================================
|
|
150
|
+
// MODEL ACCESS ERROR
|
|
151
|
+
// =============================================================================
|
|
152
|
+
/**
|
|
153
|
+
* Error thrown when model access is denied based on subscription tier
|
|
154
|
+
*/
|
|
155
|
+
export class ModelAccessError extends BaseError {
|
|
156
|
+
model;
|
|
157
|
+
tier;
|
|
158
|
+
requiredTier;
|
|
159
|
+
constructor(model, tier, requiredTier) {
|
|
160
|
+
super(`Model "${model}" is not available for tier "${tier}". ` +
|
|
161
|
+
`Required tier: "${requiredTier}" or higher.`);
|
|
162
|
+
this.name = "ModelAccessError";
|
|
163
|
+
this.model = model;
|
|
164
|
+
this.tier = tier;
|
|
165
|
+
this.requiredTier = requiredTier;
|
|
166
|
+
}
|
|
167
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export * from "./cli.js";
|
|
|
6
6
|
export * from "./common.js";
|
|
7
7
|
export type { AnalyticsConfig, BackupInfo, BackupMetadata, CacheConfig, ConfigUpdateOptions, ConfigValidationResult, FallbackConfig, NeuroLinkConfig, PerformanceConfig, RetryConfig, ToolConfig, } from "./configTypes.js";
|
|
8
8
|
export type { ExternalMCPConfigValidation, ExternalMCPManagerConfig, ExternalMCPOperationResult, ExternalMCPServerEvents, ExternalMCPServerHealth, ExternalMCPServerInstance, ExternalMCPServerStatus, ExternalMCPToolContext, ExternalMCPToolInfo, ExternalMCPToolResult, } from "./externalMcp.js";
|
|
9
|
-
export type { AuthorizationUrlResult, CircuitBreakerConfig, CircuitBreakerEvents, CircuitBreakerState, CircuitBreakerStats, DiscoveredMcp, ExternalToolExecutionOptions, FlexibleValidationResult, HTTPRetryConfig, MCPClientResult, MCPConnectedServer, MCPDiscoveredServer, MCPExecutableTool, MCPOAuthConfig, MCPServerCategory, MCPServerConfig, MCPServerConnectionStatus, MCPServerMetadata, MCPServerRegistryEntry, MCPServerStatus, MCPToolInfo, MCPToolMetadata, MCPTransportType, McpMetadata, McpRegistry, NeuroLinkExecutionContext, NeuroLinkMCPServer, NeuroLinkMCPTool, OAuthClientInformation, OAuthTokens, RateLimitConfig, TokenBucketRateLimitConfig, TokenExchangeRequest, TokenStorage, ToolDiscoveryResult, ToolRegistryEvents, ToolValidationResult, } from "./mcpTypes.js";
|
|
9
|
+
export type { AuthorizationUrlResult, CircuitBreakerConfig, CircuitBreakerEvents, CircuitBreakerState, CircuitBreakerStats, DiscoveredMcp, ExternalToolExecutionOptions, FlexibleValidationResult, HTTPRetryConfig, MCPClientResult, MCPConnectedServer, MCPDiscoveredServer, MCPExecutableTool, MCPOAuthConfig, MCPServerCategory, MCPServerConfig, MCPServerConnectionStatus, MCPServerMetadata, MCPServerRegistryEntry, MCPServerStatus, MCPToolInfo, MCPToolMetadata, MCPTransportType, McpMetadata, McpRegistry, NeuroLinkExecutionContext, NeuroLinkMCPServer, NeuroLinkMCPTool, OAuthClientInformation, OAuthTokens as McpOAuthTokens, RateLimitConfig, TokenBucketRateLimitConfig, TokenExchangeRequest, TokenStorage, ToolDiscoveryResult, ToolRegistryEvents, ToolValidationResult, } from "./mcpTypes.js";
|
|
10
10
|
export type { ModelCapability, ModelFilter, ModelPricing, ModelResolutionContext, ModelStats, ModelUseCase, } from "./providers.js";
|
|
11
11
|
export * from "./providers.js";
|
|
12
12
|
export * from "./taskClassificationTypes.js";
|
|
@@ -38,3 +38,4 @@ export * from "./contextTypes.js";
|
|
|
38
38
|
export * from "./fileReferenceTypes.js";
|
|
39
39
|
export * from "./ragTypes.js";
|
|
40
40
|
export * from "./conversationMemoryInterface.js";
|
|
41
|
+
export * from "./subscriptionTypes.js";
|
package/dist/types/index.js
CHANGED
|
@@ -48,3 +48,5 @@ export * from "./fileReferenceTypes.js";
|
|
|
48
48
|
export * from "./ragTypes.js";
|
|
49
49
|
// Conversation memory manager type
|
|
50
50
|
export * from "./conversationMemoryInterface.js";
|
|
51
|
+
// Subscription types (Claude subscription tiers, authentication, usage tracking)
|
|
52
|
+
export * from "./subscriptionTypes.js";
|
|
@@ -8,6 +8,8 @@ import type { ValidationSchema } from "./typeAliases.js";
|
|
|
8
8
|
import type { EnhancedGenerateResult, GenerateResult, TextGenerationOptions } from "./generateTypes.js";
|
|
9
9
|
import type { StreamOptions, StreamResult } from "./streamTypes.js";
|
|
10
10
|
import type { ExternalMCPToolInfo } from "./externalMcp.js";
|
|
11
|
+
import type { ClaudeSubscriptionTier, AnthropicAuthMethod, AnthropicAuthConfig, SubscriptionInfo } from "./subscriptionTypes.js";
|
|
12
|
+
export type { ClaudeSubscriptionTier, AnthropicAuthMethod, AnthropicAuthConfig, SubscriptionInfo, } from "./subscriptionTypes.js";
|
|
11
13
|
/**
|
|
12
14
|
* Generic AI SDK model interface
|
|
13
15
|
*/
|
|
@@ -33,6 +35,15 @@ export type ProviderStatus = {
|
|
|
33
35
|
error?: string;
|
|
34
36
|
responseTime?: number;
|
|
35
37
|
model?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Subscription information for providers that support subscription tiers
|
|
40
|
+
* (e.g., Anthropic Claude with Pro/Max/Team/Enterprise subscriptions)
|
|
41
|
+
*/
|
|
42
|
+
subscription?: SubscriptionInfo;
|
|
43
|
+
/**
|
|
44
|
+
* The authentication method currently in use for this provider
|
|
45
|
+
*/
|
|
46
|
+
authMethod?: AnthropicAuthMethod;
|
|
36
47
|
};
|
|
37
48
|
/**
|
|
38
49
|
* Provider error information
|
|
@@ -185,6 +196,16 @@ export type ProviderCapabilities = {
|
|
|
185
196
|
supportsAudio: boolean;
|
|
186
197
|
maxTokens?: number;
|
|
187
198
|
supportedModels: string[];
|
|
199
|
+
/**
|
|
200
|
+
* Whether the provider supports subscription-based features and tier management
|
|
201
|
+
* When true, the provider can adapt behavior based on subscription tier
|
|
202
|
+
*/
|
|
203
|
+
subscriptionAware?: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* List of authentication methods supported by this provider
|
|
206
|
+
* e.g., ["api_key", "oauth", "session_token", "environment"]
|
|
207
|
+
*/
|
|
208
|
+
supportedAuthMethods?: string[];
|
|
188
209
|
};
|
|
189
210
|
/**
|
|
190
211
|
* Provider configuration specifying provider and its available models (from core types)
|
|
@@ -202,8 +223,94 @@ export type IndividualProviderConfig = {
|
|
|
202
223
|
timeout?: number;
|
|
203
224
|
retries?: number;
|
|
204
225
|
model?: string;
|
|
226
|
+
/**
|
|
227
|
+
* The subscription tier for the provider (e.g., Claude Pro, Max, Team, Enterprise)
|
|
228
|
+
* Used to determine rate limits, available features, and pricing
|
|
229
|
+
*/
|
|
230
|
+
subscriptionTier?: ClaudeSubscriptionTier;
|
|
231
|
+
/**
|
|
232
|
+
* The authentication method to use for the provider
|
|
233
|
+
* Supports API key, OAuth, session token, or environment variable
|
|
234
|
+
*/
|
|
235
|
+
authMethod?: AnthropicAuthMethod;
|
|
236
|
+
/**
|
|
237
|
+
* Detailed authentication configuration including credentials and options
|
|
238
|
+
*/
|
|
239
|
+
authConfig?: AnthropicAuthConfig;
|
|
240
|
+
/**
|
|
241
|
+
* Whether to enable beta features for the provider
|
|
242
|
+
* Beta features may be unstable or subject to change
|
|
243
|
+
*/
|
|
244
|
+
enableBetaFeatures?: boolean;
|
|
205
245
|
[key: string]: unknown;
|
|
206
246
|
};
|
|
247
|
+
/**
|
|
248
|
+
* Anthropic-specific provider configuration
|
|
249
|
+
*
|
|
250
|
+
* @description Extends the base provider configuration with Anthropic-specific
|
|
251
|
+
* options for OAuth, subscription management, and beta features.
|
|
252
|
+
*/
|
|
253
|
+
export type AnthropicProviderConfig = IndividualProviderConfig & {
|
|
254
|
+
/**
|
|
255
|
+
* The subscription tier for Claude access
|
|
256
|
+
*/
|
|
257
|
+
subscriptionTier?: ClaudeSubscriptionTier;
|
|
258
|
+
/**
|
|
259
|
+
* The authentication method to use
|
|
260
|
+
*/
|
|
261
|
+
authMethod?: AnthropicAuthMethod;
|
|
262
|
+
/**
|
|
263
|
+
* Whether to enable beta features
|
|
264
|
+
*/
|
|
265
|
+
enableBetaFeatures?: boolean;
|
|
266
|
+
/**
|
|
267
|
+
* OAuth token for OAuth authentication.
|
|
268
|
+
* Required when authMethod is "oauth".
|
|
269
|
+
*/
|
|
270
|
+
oauthToken?: import("./subscriptionTypes.js").OAuthToken;
|
|
271
|
+
/**
|
|
272
|
+
* OAuth configuration for OAuth-based authentication
|
|
273
|
+
*/
|
|
274
|
+
oauthConfig?: {
|
|
275
|
+
/**
|
|
276
|
+
* OAuth client ID for the application
|
|
277
|
+
*/
|
|
278
|
+
clientId?: string;
|
|
279
|
+
/**
|
|
280
|
+
* OAuth redirect URI for the callback
|
|
281
|
+
*/
|
|
282
|
+
redirectUri?: string;
|
|
283
|
+
/**
|
|
284
|
+
* OAuth scopes to request
|
|
285
|
+
*/
|
|
286
|
+
scopes?: string[];
|
|
287
|
+
/**
|
|
288
|
+
* OAuth authorization endpoint URL
|
|
289
|
+
*/
|
|
290
|
+
authorizationEndpoint?: string;
|
|
291
|
+
/**
|
|
292
|
+
* OAuth token endpoint URL
|
|
293
|
+
*/
|
|
294
|
+
tokenEndpoint?: string;
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* Type guard to check if a configuration is an AnthropicProviderConfig
|
|
299
|
+
*
|
|
300
|
+
* @param config - The configuration object to check
|
|
301
|
+
* @returns True if the configuration is an AnthropicProviderConfig
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```typescript
|
|
305
|
+
* const config = getProviderConfig();
|
|
306
|
+
* if (isAnthropicConfig(config)) {
|
|
307
|
+
* // TypeScript knows config is AnthropicProviderConfig here
|
|
308
|
+
* console.log(config.subscriptionTier);
|
|
309
|
+
* console.log(config.oauthConfig?.clientId);
|
|
310
|
+
* }
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
export declare function isAnthropicConfig(config: unknown): config is AnthropicProviderConfig;
|
|
207
314
|
/**
|
|
208
315
|
* Configuration options for provider validation
|
|
209
316
|
*/
|