@juspay/neurolink 9.65.1 → 9.66.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 +8 -0
- package/dist/adapters/video/videoAnalyzer.d.ts +1 -1
- package/dist/agent/directTools.d.ts +9 -17
- package/dist/agent/directTools.js +1 -5
- package/dist/autoresearch/tools.d.ts +2 -214
- package/dist/autoresearch/tools.js +1 -1
- package/dist/browser/neurolink.min.js +388 -386
- package/dist/cli/commands/proxy.js +154 -5
- package/dist/client/reactHooks.js +16 -8
- package/dist/client/reactHooks.tsx +24 -9
- package/dist/core/baseProvider.d.ts +1 -6
- package/dist/core/baseProvider.js +1 -1
- package/dist/core/modules/GenerationHandler.d.ts +2 -2
- package/dist/core/modules/GenerationHandler.js +3 -1
- package/dist/core/modules/MessageBuilder.d.ts +1 -15
- package/dist/core/modules/MessageBuilder.js +0 -14
- package/dist/core/modules/StreamHandler.js +1 -1
- package/dist/core/modules/ToolsManager.d.ts +1 -17
- package/dist/core/modules/ToolsManager.js +1 -17
- package/dist/core/streamAnalytics.js +1 -1
- package/dist/evaluation/contextBuilder.d.ts +1 -4
- package/dist/evaluation/contextBuilder.js +0 -3
- package/dist/evaluation/index.d.ts +1 -4
- package/dist/evaluation/index.js +0 -3
- package/dist/files/fileTools.d.ts +2 -18
- package/dist/files/fileTools.js +3 -19
- package/dist/lib/adapters/video/videoAnalyzer.d.ts +1 -1
- package/dist/lib/agent/directTools.d.ts +9 -17
- package/dist/lib/agent/directTools.js +1 -5
- package/dist/lib/autoresearch/tools.d.ts +2 -214
- package/dist/lib/autoresearch/tools.js +1 -1
- package/dist/lib/client/reactHooks.js +16 -8
- package/dist/lib/core/baseProvider.d.ts +1 -6
- package/dist/lib/core/baseProvider.js +1 -1
- package/dist/lib/core/modules/GenerationHandler.d.ts +2 -2
- package/dist/lib/core/modules/GenerationHandler.js +3 -1
- package/dist/lib/core/modules/MessageBuilder.d.ts +1 -15
- package/dist/lib/core/modules/MessageBuilder.js +0 -14
- package/dist/lib/core/modules/StreamHandler.js +1 -1
- package/dist/lib/core/modules/ToolsManager.d.ts +1 -17
- package/dist/lib/core/modules/ToolsManager.js +1 -17
- package/dist/lib/core/streamAnalytics.js +1 -1
- package/dist/lib/evaluation/contextBuilder.d.ts +1 -4
- package/dist/lib/evaluation/contextBuilder.js +0 -3
- package/dist/lib/evaluation/index.d.ts +1 -4
- package/dist/lib/evaluation/index.js +0 -3
- package/dist/lib/files/fileTools.d.ts +2 -18
- package/dist/lib/files/fileTools.js +3 -19
- package/dist/lib/memory/memoryRetrievalTools.d.ts +2 -126
- package/dist/lib/memory/memoryRetrievalTools.js +1 -9
- package/dist/lib/middleware/builtin/autoEvaluation.d.ts +0 -3
- package/dist/lib/middleware/builtin/autoEvaluation.js +0 -3
- package/dist/lib/middleware/builtin/guardrails.js +1 -1
- package/dist/lib/middleware/builtin/lifecycle.d.ts +0 -9
- package/dist/lib/middleware/builtin/lifecycle.js +0 -9
- package/dist/lib/middleware/factory.d.ts +1 -1
- package/dist/lib/middleware/factory.js +1 -1
- package/dist/lib/middleware/registry.d.ts +1 -1
- package/dist/lib/neurolink.d.ts +14 -2
- package/dist/lib/neurolink.js +46 -18
- package/dist/lib/processors/media/AudioProcessor.js +8 -3
- package/dist/lib/providers/amazonBedrock.js +1 -2
- package/dist/lib/providers/amazonSagemaker.d.ts +1 -7
- package/dist/lib/providers/amazonSagemaker.js +0 -6
- package/dist/lib/providers/anthropic.d.ts +1 -1
- package/dist/lib/providers/anthropic.js +2 -1
- package/dist/lib/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/lib/providers/anthropicBaseProvider.js +2 -1
- package/dist/lib/providers/azureOpenai.d.ts +1 -1
- package/dist/lib/providers/azureOpenai.js +2 -1
- package/dist/lib/providers/cloudflare.d.ts +1 -1
- package/dist/lib/providers/cloudflare.js +2 -1
- package/dist/lib/providers/cohere.d.ts +1 -1
- package/dist/lib/providers/cohere.js +2 -1
- package/dist/lib/providers/deepseek.d.ts +1 -1
- package/dist/lib/providers/deepseek.js +2 -1
- package/dist/lib/providers/fireworks.d.ts +1 -1
- package/dist/lib/providers/fireworks.js +2 -1
- package/dist/lib/providers/googleAiStudio.d.ts +1 -1
- package/dist/lib/providers/googleAiStudio.js +0 -1
- package/dist/lib/providers/googleNativeGemini3.d.ts +1 -1
- package/dist/lib/providers/googleNativeGemini3.js +1 -1
- package/dist/lib/providers/googleVertex.d.ts +1 -1
- package/dist/lib/providers/googleVertex.js +0 -1
- package/dist/lib/providers/groq.d.ts +1 -1
- package/dist/lib/providers/groq.js +2 -1
- package/dist/lib/providers/huggingFace.d.ts +1 -1
- package/dist/lib/providers/huggingFace.js +3 -1
- package/dist/lib/providers/ideogram.d.ts +1 -1
- package/dist/lib/providers/jina.d.ts +1 -1
- package/dist/lib/providers/litellm.d.ts +1 -1
- package/dist/lib/providers/litellm.js +12 -6
- package/dist/lib/providers/llamaCpp.d.ts +1 -1
- package/dist/lib/providers/llamaCpp.js +2 -1
- package/dist/lib/providers/lmStudio.d.ts +1 -1
- package/dist/lib/providers/lmStudio.js +2 -1
- package/dist/lib/providers/mistral.d.ts +1 -1
- package/dist/lib/providers/mistral.js +2 -1
- package/dist/lib/providers/nvidiaNim.d.ts +1 -1
- package/dist/lib/providers/nvidiaNim.js +2 -1
- package/dist/lib/providers/ollama.d.ts +1 -1
- package/dist/lib/providers/ollama.js +1 -2
- package/dist/lib/providers/openAI.d.ts +1 -1
- package/dist/lib/providers/openAI.js +3 -1
- package/dist/lib/providers/openRouter.d.ts +1 -1
- package/dist/lib/providers/openRouter.js +3 -1
- package/dist/lib/providers/openaiCompatible.d.ts +1 -1
- package/dist/lib/providers/openaiCompatible.js +3 -1
- package/dist/lib/providers/perplexity.d.ts +1 -1
- package/dist/lib/providers/perplexity.js +2 -1
- package/dist/lib/providers/providerTypeUtils.d.ts +2 -7
- package/dist/lib/providers/providerTypeUtils.js +0 -6
- package/dist/lib/providers/recraft.d.ts +1 -1
- package/dist/lib/providers/replicate.d.ts +1 -1
- package/dist/lib/providers/stability.d.ts +1 -1
- package/dist/lib/providers/togetherAi.d.ts +1 -1
- package/dist/lib/providers/togetherAi.js +2 -1
- package/dist/lib/providers/voyage.d.ts +1 -1
- package/dist/lib/providers/xai.d.ts +1 -1
- package/dist/lib/providers/xai.js +2 -1
- package/dist/lib/proxy/claudeFormat.d.ts +0 -15
- package/dist/lib/proxy/claudeFormat.js +1 -11
- package/dist/lib/proxy/modelRouter.d.ts +5 -1
- package/dist/lib/proxy/modelRouter.js +8 -0
- package/dist/lib/proxy/openaiFormat.d.ts +137 -0
- package/dist/lib/proxy/openaiFormat.js +801 -0
- package/dist/lib/proxy/proxyTranslationEngine.d.ts +124 -0
- package/dist/lib/proxy/proxyTranslationEngine.js +679 -0
- package/dist/lib/rag/ragIntegration.d.ts +1 -12
- package/dist/lib/rag/ragIntegration.js +0 -8
- package/dist/lib/server/routes/claudeProxyRoutes.d.ts +6 -5
- package/dist/lib/server/routes/claudeProxyRoutes.js +22 -355
- package/dist/lib/server/routes/index.d.ts +1 -0
- package/dist/lib/server/routes/index.js +10 -2
- package/dist/lib/server/routes/openaiProxyRoutes.d.ts +30 -0
- package/dist/lib/server/routes/openaiProxyRoutes.js +337 -0
- package/dist/lib/tasks/tools/taskTools.d.ts +2 -117
- package/dist/lib/tasks/tools/taskTools.js +1 -10
- package/dist/lib/types/aliases.d.ts +1 -1
- package/dist/lib/types/conversation.d.ts +1 -0
- package/dist/lib/types/evaluation.d.ts +1 -5
- package/dist/lib/types/evaluation.js +0 -4
- package/dist/lib/types/generate.d.ts +2 -22
- package/dist/lib/types/guardrails.d.ts +1 -1
- package/dist/lib/types/middleware.d.ts +8 -3
- package/dist/lib/types/providers.d.ts +2 -1
- package/dist/lib/types/proxy.d.ts +179 -0
- package/dist/lib/types/rag.d.ts +1 -1
- package/dist/lib/types/rag.js +0 -6
- package/dist/lib/types/server.d.ts +3 -0
- package/dist/lib/types/stream.d.ts +2 -11
- package/dist/lib/types/tools.d.ts +2 -1
- package/dist/lib/utils/generation.d.ts +8 -0
- package/dist/lib/utils/generation.js +9 -0
- package/dist/lib/utils/generationErrors.d.ts +10 -0
- package/dist/lib/utils/generationErrors.js +11 -0
- package/dist/lib/utils/messageBuilder.d.ts +1 -6
- package/dist/lib/utils/messageBuilder.js +0 -5
- package/dist/lib/utils/noOutputSentinel.d.ts +0 -13
- package/dist/lib/utils/noOutputSentinel.js +1 -14
- package/dist/lib/utils/providerRetry.js +1 -1
- package/dist/lib/utils/tool.d.ts +8 -0
- package/dist/lib/utils/tool.js +9 -0
- package/dist/lib/utils/toolCallRepair.d.ts +1 -16
- package/dist/lib/utils/toolCallRepair.js +1 -16
- package/dist/lib/utils/toolChoice.d.ts +1 -1
- package/dist/lib/utils/videoAnalysisProcessor.d.ts +1 -8
- package/dist/lib/utils/videoAnalysisProcessor.js +0 -7
- package/dist/memory/memoryRetrievalTools.d.ts +2 -126
- package/dist/memory/memoryRetrievalTools.js +1 -9
- package/dist/middleware/builtin/autoEvaluation.d.ts +0 -3
- package/dist/middleware/builtin/autoEvaluation.js +0 -3
- package/dist/middleware/builtin/guardrails.js +1 -1
- package/dist/middleware/builtin/lifecycle.d.ts +0 -9
- package/dist/middleware/builtin/lifecycle.js +0 -9
- package/dist/middleware/factory.d.ts +1 -1
- package/dist/middleware/factory.js +1 -1
- package/dist/middleware/registry.d.ts +1 -1
- package/dist/neurolink.d.ts +14 -2
- package/dist/neurolink.js +46 -18
- package/dist/processors/media/AudioProcessor.js +8 -3
- package/dist/providers/amazonBedrock.js +1 -2
- package/dist/providers/amazonSagemaker.d.ts +1 -7
- package/dist/providers/amazonSagemaker.js +0 -6
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +2 -1
- package/dist/providers/anthropicBaseProvider.d.ts +1 -1
- package/dist/providers/anthropicBaseProvider.js +2 -1
- package/dist/providers/azureOpenai.d.ts +1 -1
- package/dist/providers/azureOpenai.js +2 -1
- package/dist/providers/cloudflare.d.ts +1 -1
- package/dist/providers/cloudflare.js +2 -1
- package/dist/providers/cohere.d.ts +1 -1
- package/dist/providers/cohere.js +2 -1
- package/dist/providers/deepseek.d.ts +1 -1
- package/dist/providers/deepseek.js +2 -1
- package/dist/providers/fireworks.d.ts +1 -1
- package/dist/providers/fireworks.js +2 -1
- package/dist/providers/googleAiStudio.d.ts +1 -1
- package/dist/providers/googleNativeGemini3.d.ts +1 -1
- package/dist/providers/googleNativeGemini3.js +1 -1
- package/dist/providers/googleVertex.d.ts +1 -1
- package/dist/providers/groq.d.ts +1 -1
- package/dist/providers/groq.js +2 -1
- package/dist/providers/huggingFace.d.ts +1 -1
- package/dist/providers/huggingFace.js +3 -1
- package/dist/providers/ideogram.d.ts +1 -1
- package/dist/providers/jina.d.ts +1 -1
- package/dist/providers/litellm.d.ts +1 -1
- package/dist/providers/litellm.js +12 -6
- package/dist/providers/llamaCpp.d.ts +1 -1
- package/dist/providers/llamaCpp.js +2 -1
- package/dist/providers/lmStudio.d.ts +1 -1
- package/dist/providers/lmStudio.js +2 -1
- package/dist/providers/mistral.d.ts +1 -1
- package/dist/providers/mistral.js +2 -1
- package/dist/providers/nvidiaNim.d.ts +1 -1
- package/dist/providers/nvidiaNim.js +2 -1
- package/dist/providers/ollama.d.ts +1 -1
- package/dist/providers/ollama.js +1 -2
- package/dist/providers/openAI.d.ts +1 -1
- package/dist/providers/openAI.js +3 -1
- package/dist/providers/openRouter.d.ts +1 -1
- package/dist/providers/openRouter.js +3 -1
- package/dist/providers/openaiCompatible.d.ts +1 -1
- package/dist/providers/openaiCompatible.js +3 -1
- package/dist/providers/perplexity.d.ts +1 -1
- package/dist/providers/perplexity.js +2 -1
- package/dist/providers/providerTypeUtils.d.ts +2 -7
- package/dist/providers/providerTypeUtils.js +0 -6
- package/dist/providers/recraft.d.ts +1 -1
- package/dist/providers/replicate.d.ts +1 -1
- package/dist/providers/stability.d.ts +1 -1
- package/dist/providers/togetherAi.d.ts +1 -1
- package/dist/providers/togetherAi.js +2 -1
- package/dist/providers/voyage.d.ts +1 -1
- package/dist/providers/xai.d.ts +1 -1
- package/dist/providers/xai.js +2 -1
- package/dist/proxy/claudeFormat.d.ts +0 -15
- package/dist/proxy/claudeFormat.js +1 -11
- package/dist/proxy/modelRouter.d.ts +5 -1
- package/dist/proxy/modelRouter.js +8 -0
- package/dist/proxy/openaiFormat.d.ts +137 -0
- package/dist/proxy/openaiFormat.js +800 -0
- package/dist/proxy/proxyTranslationEngine.d.ts +124 -0
- package/dist/proxy/proxyTranslationEngine.js +678 -0
- package/dist/rag/ragIntegration.d.ts +1 -12
- package/dist/rag/ragIntegration.js +0 -8
- package/dist/server/routes/claudeProxyRoutes.d.ts +6 -5
- package/dist/server/routes/claudeProxyRoutes.js +22 -355
- package/dist/server/routes/index.d.ts +1 -0
- package/dist/server/routes/index.js +10 -2
- package/dist/server/routes/openaiProxyRoutes.d.ts +30 -0
- package/dist/server/routes/openaiProxyRoutes.js +336 -0
- package/dist/tasks/tools/taskTools.d.ts +2 -117
- package/dist/tasks/tools/taskTools.js +1 -10
- package/dist/types/aliases.d.ts +1 -1
- package/dist/types/conversation.d.ts +1 -0
- package/dist/types/evaluation.d.ts +1 -5
- package/dist/types/evaluation.js +0 -4
- package/dist/types/generate.d.ts +2 -22
- package/dist/types/guardrails.d.ts +1 -1
- package/dist/types/middleware.d.ts +8 -3
- package/dist/types/providers.d.ts +2 -1
- package/dist/types/proxy.d.ts +179 -0
- package/dist/types/rag.d.ts +1 -1
- package/dist/types/rag.js +0 -6
- package/dist/types/server.d.ts +3 -0
- package/dist/types/stream.d.ts +2 -11
- package/dist/types/tools.d.ts +2 -1
- package/dist/utils/generation.d.ts +8 -0
- package/dist/utils/generation.js +8 -0
- package/dist/utils/generationErrors.d.ts +10 -0
- package/dist/utils/generationErrors.js +10 -0
- package/dist/utils/messageBuilder.d.ts +1 -6
- package/dist/utils/messageBuilder.js +0 -5
- package/dist/utils/noOutputSentinel.d.ts +0 -13
- package/dist/utils/noOutputSentinel.js +1 -14
- package/dist/utils/providerRetry.js +1 -1
- package/dist/utils/tool.d.ts +8 -0
- package/dist/utils/tool.js +8 -0
- package/dist/utils/toolCallRepair.d.ts +1 -16
- package/dist/utils/toolCallRepair.js +1 -16
- package/dist/utils/toolChoice.d.ts +1 -1
- package/dist/utils/videoAnalysisProcessor.d.ts +1 -8
- package/dist/utils/videoAnalysisProcessor.js +0 -7
- package/package.json +2 -3
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claude Messages API format conversion layer.
|
|
3
|
-
*
|
|
4
|
-
* Provides a request parser (Claude -> NeuroLink), a response serializer
|
|
5
|
-
* (NeuroLink -> Claude), a streaming SSE state machine, and an error
|
|
6
|
-
* envelope helper. Together they allow NeuroLink to act as a
|
|
7
|
-
* drop-in Claude API proxy.
|
|
8
|
-
*
|
|
9
|
-
* Reference: https://docs.anthropic.com/en/api/messages
|
|
10
|
-
*/
|
|
11
1
|
import type { ClaudeErrorResponse, ClaudeRequest, ClaudeResponse, ContentBlockType, InternalResult, ParsedClaudeRequest, StreamLifecycleState } from "../types/index.js";
|
|
12
2
|
/** Generate a unique message id in the Claude format. */
|
|
13
3
|
export declare function generateMessageId(): string;
|
|
14
4
|
/** Generate a Claude-format tool use ID (`toolu_` + 24 random chars). */
|
|
15
5
|
export declare function generateToolUseId(): string;
|
|
16
|
-
/**
|
|
17
|
-
* Reset the internal id counter (useful in tests).
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
export declare function _resetIdCounter(): void;
|
|
21
6
|
/**
|
|
22
7
|
* Parse an incoming Claude Messages API request into an intermediate
|
|
23
8
|
* representation consumable by NeuroLink's generate/stream pipeline.
|
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claude Messages API format conversion layer.
|
|
3
|
-
*
|
|
4
|
-
* Provides a request parser (Claude -> NeuroLink), a response serializer
|
|
5
|
-
* (NeuroLink -> Claude), a streaming SSE state machine, and an error
|
|
6
|
-
* envelope helper. Together they allow NeuroLink to act as a
|
|
7
|
-
* drop-in Claude API proxy.
|
|
8
|
-
*
|
|
9
|
-
* Reference: https://docs.anthropic.com/en/api/messages
|
|
10
|
-
*/
|
|
11
|
-
import { jsonSchema, tool } from "ai";
|
|
12
1
|
import { randomBytes } from "crypto";
|
|
13
2
|
import { normalizeJsonSchemaObject } from "../utils/schemaConversion.js";
|
|
3
|
+
import { jsonSchema, tool } from "../utils/tool.js";
|
|
14
4
|
// ---------------------------------------------------------------------------
|
|
15
5
|
// Helpers
|
|
16
6
|
// ---------------------------------------------------------------------------
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FallbackEntry, ProxyRoutingConfig, RouteResult } from "../types/index.js";
|
|
1
|
+
import type { FallbackEntry, ModelMapping, ProxyRoutingConfig, RouteResult } from "../types/index.js";
|
|
2
2
|
export declare class ModelRouter {
|
|
3
3
|
private readonly mappings;
|
|
4
4
|
private readonly passthrough;
|
|
@@ -7,4 +7,8 @@ export declare class ModelRouter {
|
|
|
7
7
|
resolve(requestedModel: string): RouteResult;
|
|
8
8
|
isClaudeTarget(requestedModel: string): boolean;
|
|
9
9
|
getFallbackChain(): FallbackEntry[];
|
|
10
|
+
/** Return the raw model mapping entries (used by /v1/models). */
|
|
11
|
+
getModelMappings(): ModelMapping[];
|
|
12
|
+
/** Return models configured for passthrough (used by /v1/models). */
|
|
13
|
+
getPassthroughModels(): string[];
|
|
10
14
|
}
|
|
@@ -29,5 +29,13 @@ export class ModelRouter {
|
|
|
29
29
|
getFallbackChain() {
|
|
30
30
|
return this.fallback;
|
|
31
31
|
}
|
|
32
|
+
/** Return the raw model mapping entries (used by /v1/models). */
|
|
33
|
+
getModelMappings() {
|
|
34
|
+
return Array.from(this.mappings.values());
|
|
35
|
+
}
|
|
36
|
+
/** Return models configured for passthrough (used by /v1/models). */
|
|
37
|
+
getPassthroughModels() {
|
|
38
|
+
return Array.from(this.passthrough);
|
|
39
|
+
}
|
|
32
40
|
}
|
|
33
41
|
//# sourceMappingURL=modelRouter.js.map
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Chat Completions API format conversion layer.
|
|
3
|
+
*
|
|
4
|
+
* Provides a request parser (OpenAI -> NeuroLink), a response serializer
|
|
5
|
+
* (NeuroLink -> OpenAI), a streaming SSE state machine, and an error
|
|
6
|
+
* envelope helper. Together they allow NeuroLink to act as a
|
|
7
|
+
* drop-in OpenAI API proxy.
|
|
8
|
+
*
|
|
9
|
+
* Reference: https://platform.openai.com/docs/api-reference/chat/create
|
|
10
|
+
*/
|
|
11
|
+
import type { ClaudeRequest, ClaudeResponse, InternalResult, OpenAICompletionRequest, OpenAICompletionResponse, OpenAIErrorResponse, ParsedOpenAIRequest, StreamLifecycleState } from "../types/index.js";
|
|
12
|
+
/** Generate a unique chat completion ID in the OpenAI format. */
|
|
13
|
+
export declare function generateChatCompletionId(): string;
|
|
14
|
+
/** Generate an OpenAI-format tool call ID (`call_` + random chars). */
|
|
15
|
+
export declare function generateOpenAIToolCallId(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Parse an incoming OpenAI Chat Completions request into an intermediate
|
|
18
|
+
* representation consumable by NeuroLink's generate/stream pipeline.
|
|
19
|
+
*
|
|
20
|
+
* Handles:
|
|
21
|
+
* - System prompt extraction from system messages
|
|
22
|
+
* - Message flattening (text + image parts)
|
|
23
|
+
* - Tool definition conversion
|
|
24
|
+
* - tool_choice mapping
|
|
25
|
+
* - top_p, temperature, max_tokens pass-through
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseOpenAIRequest(body: OpenAICompletionRequest): ParsedOpenAIRequest;
|
|
28
|
+
/**
|
|
29
|
+
* Serialize a NeuroLink GenerateResult into an OpenAI Chat Completions response.
|
|
30
|
+
*/
|
|
31
|
+
export declare function serializeOpenAIResponse(result: InternalResult, requestModel: string): OpenAICompletionResponse;
|
|
32
|
+
/**
|
|
33
|
+
* Build an OpenAI-compatible error envelope.
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildOpenAIError(status: number, message: string): OpenAIErrorResponse;
|
|
36
|
+
/**
|
|
37
|
+
* Format a single OpenAI SSE frame.
|
|
38
|
+
* OpenAI uses only `data:` lines (no `event:` prefix unlike Claude).
|
|
39
|
+
*/
|
|
40
|
+
export declare function formatOpenAISSE(data: unknown): string;
|
|
41
|
+
/**
|
|
42
|
+
* Stateful SSE serializer that emits a well-formed OpenAI streaming response.
|
|
43
|
+
*
|
|
44
|
+
* Tracks lifecycle state (`idle` -> `streaming` -> `done`) and the current
|
|
45
|
+
* tool call index for multi-tool streaming.
|
|
46
|
+
*
|
|
47
|
+
* Usage:
|
|
48
|
+
* ```ts
|
|
49
|
+
* const sse = new OpenAIStreamSerializer(requestModel);
|
|
50
|
+
*
|
|
51
|
+
* // Start the stream
|
|
52
|
+
* yield* sse.start();
|
|
53
|
+
*
|
|
54
|
+
* // Text deltas
|
|
55
|
+
* for await (const chunk of textStream) {
|
|
56
|
+
* yield* sse.pushDelta(chunk);
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* // Tool use
|
|
60
|
+
* yield* sse.pushToolUse(toolId, toolName, toolInput);
|
|
61
|
+
*
|
|
62
|
+
* // Finalize
|
|
63
|
+
* yield* sse.finish("stop", usage);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare class OpenAIStreamSerializer {
|
|
67
|
+
private state;
|
|
68
|
+
private readonly id;
|
|
69
|
+
private readonly model;
|
|
70
|
+
private started;
|
|
71
|
+
private toolCallIndex;
|
|
72
|
+
constructor(model: string);
|
|
73
|
+
/** Current lifecycle state (exposed for testing). */
|
|
74
|
+
getState(): StreamLifecycleState;
|
|
75
|
+
private makeChunk;
|
|
76
|
+
/**
|
|
77
|
+
* Emit the opening frame with `role: "assistant"`.
|
|
78
|
+
*/
|
|
79
|
+
start(): Generator<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Push a text content delta.
|
|
82
|
+
*/
|
|
83
|
+
pushDelta(text: string): Generator<string>;
|
|
84
|
+
/**
|
|
85
|
+
* Push the start of a tool call (id, name, empty arguments).
|
|
86
|
+
*/
|
|
87
|
+
pushToolCallStart(id: string, name: string): Generator<string>;
|
|
88
|
+
/**
|
|
89
|
+
* Push an arguments delta for the current tool call.
|
|
90
|
+
*/
|
|
91
|
+
pushToolCallArgDelta(index: number, argsChunk: string): Generator<string>;
|
|
92
|
+
/**
|
|
93
|
+
* Push a complete tool use: emits tool call start followed by chunked
|
|
94
|
+
* argument deltas (~100 chars per chunk).
|
|
95
|
+
*/
|
|
96
|
+
pushToolUse(id: string, name: string, input: unknown): Generator<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Finalize the stream: emit finish_reason chunk, then `data: [DONE]`.
|
|
99
|
+
*/
|
|
100
|
+
finish(finishReason?: string, usage?: {
|
|
101
|
+
input: number;
|
|
102
|
+
output: number;
|
|
103
|
+
total: number;
|
|
104
|
+
}): Generator<string>;
|
|
105
|
+
/**
|
|
106
|
+
* Emit an error event. Transitions to terminal ERROR state.
|
|
107
|
+
*/
|
|
108
|
+
emitError(message: string): Generator<string>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Convert an OpenAI Chat Completions request to a Claude Messages API request.
|
|
112
|
+
*
|
|
113
|
+
* Used by the OpenAI proxy endpoint to internally loopback requests targeting
|
|
114
|
+
* Claude models through the proxy's native /v1/messages passthrough path,
|
|
115
|
+
* so they benefit from OAuth account rotation, retry, SSE interception, etc.
|
|
116
|
+
*/
|
|
117
|
+
export declare function convertOpenAIToClaudeRequest(openai: OpenAICompletionRequest): ClaudeRequest;
|
|
118
|
+
/**
|
|
119
|
+
* Convert a non-streaming Claude Messages response to an OpenAI Chat
|
|
120
|
+
* Completions response by bridging through {@link InternalResult}.
|
|
121
|
+
*/
|
|
122
|
+
export declare function convertClaudeToOpenAIResponse(claude: ClaudeResponse, requestModel: string): OpenAICompletionResponse;
|
|
123
|
+
/**
|
|
124
|
+
* Create a TransformStream that parses Claude Messages API SSE events from
|
|
125
|
+
* the upstream response and re-emits them as OpenAI Chat Completions SSE
|
|
126
|
+
* frames.
|
|
127
|
+
*
|
|
128
|
+
* Handles the canonical Claude SSE event types:
|
|
129
|
+
* - message_start -> emits the opening `role: "assistant"` chunk
|
|
130
|
+
* - content_block_start -> text block: no-op; tool_use block: emit tool call start
|
|
131
|
+
* - content_block_delta -> text_delta: emit content delta;
|
|
132
|
+
* input_json_delta: emit tool call argument delta
|
|
133
|
+
* - content_block_stop -> no-op
|
|
134
|
+
* - message_delta -> captures stop_reason and output token usage
|
|
135
|
+
* - message_stop -> emits the final `finish_reason` chunk + `[DONE]`
|
|
136
|
+
*/
|
|
137
|
+
export declare function createClaudeToOpenAIStreamTransform(requestModel: string): TransformStream<Uint8Array, Uint8Array>;
|