@juspay/neurolink 9.65.2 → 9.67.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 +12 -12
- package/dist/avatar/index.d.ts +13 -0
- package/dist/avatar/index.js +72 -0
- package/dist/browser/neurolink.min.js +355 -347
- package/dist/cli/commands/proxy.js +154 -5
- package/dist/core/baseProvider.js +49 -8
- package/dist/factories/providerRegistry.js +23 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +36 -1
- package/dist/lib/avatar/index.d.ts +13 -0
- package/dist/lib/avatar/index.js +72 -0
- package/dist/lib/core/baseProvider.js +49 -8
- package/dist/lib/factories/providerRegistry.js +23 -0
- package/dist/lib/files/fileTools.d.ts +1 -1
- package/dist/lib/index.d.ts +10 -1
- package/dist/lib/index.js +36 -1
- package/dist/lib/music/index.d.ts +14 -0
- package/dist/lib/music/index.js +80 -0
- 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/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/types/avatar.d.ts +8 -1
- package/dist/lib/types/multimodal.d.ts +20 -7
- package/dist/lib/types/music.d.ts +8 -1
- package/dist/lib/types/proxy.d.ts +179 -0
- package/dist/lib/types/server.d.ts +3 -0
- package/dist/lib/types/tts.d.ts +9 -1
- package/dist/lib/utils/avatarProcessor.d.ts +7 -1
- package/dist/lib/utils/avatarProcessor.js +6 -0
- package/dist/lib/utils/musicProcessor.d.ts +7 -1
- package/dist/lib/utils/musicProcessor.js +6 -0
- package/dist/lib/utils/parameterValidation.js +5 -1
- package/dist/lib/utils/sttProcessor.d.ts +5 -3
- package/dist/lib/utils/sttProcessor.js +4 -2
- package/dist/lib/utils/ttsProcessor.d.ts +6 -3
- package/dist/lib/utils/ttsProcessor.js +5 -2
- package/dist/lib/voice/RealtimeVoiceAPI.d.ts +5 -2
- package/dist/lib/voice/RealtimeVoiceAPI.js +4 -1
- package/dist/lib/voice/index.d.ts +23 -0
- package/dist/lib/voice/index.js +124 -2
- package/dist/lib/voice/providers/CartesiaTTS.d.ts +31 -0
- package/dist/lib/voice/providers/CartesiaTTS.js +189 -0
- package/dist/lib/workflow/config.d.ts +3 -3
- package/dist/music/index.d.ts +14 -0
- package/dist/music/index.js +80 -0
- 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/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/types/avatar.d.ts +8 -1
- package/dist/types/multimodal.d.ts +20 -7
- package/dist/types/music.d.ts +8 -1
- package/dist/types/proxy.d.ts +179 -0
- package/dist/types/server.d.ts +3 -0
- package/dist/types/tts.d.ts +9 -1
- package/dist/utils/avatarProcessor.d.ts +7 -1
- package/dist/utils/avatarProcessor.js +6 -0
- package/dist/utils/musicProcessor.d.ts +7 -1
- package/dist/utils/musicProcessor.js +6 -0
- package/dist/utils/parameterValidation.js +5 -1
- package/dist/utils/sttProcessor.d.ts +5 -3
- package/dist/utils/sttProcessor.js +4 -2
- package/dist/utils/ttsProcessor.d.ts +6 -3
- package/dist/utils/ttsProcessor.js +5 -2
- package/dist/voice/RealtimeVoiceAPI.d.ts +5 -2
- package/dist/voice/RealtimeVoiceAPI.js +4 -1
- package/dist/voice/index.d.ts +23 -0
- package/dist/voice/index.js +124 -2
- package/dist/voice/providers/CartesiaTTS.d.ts +31 -0
- package/dist/voice/providers/CartesiaTTS.js +188 -0
- package/package.json +65 -2
package/dist/music/index.js
CHANGED
|
@@ -7,7 +7,87 @@
|
|
|
7
7
|
* Use `MusicProcessor.generate(provider, options)` to dispatch to the
|
|
8
8
|
* registered handler for `provider`.
|
|
9
9
|
*
|
|
10
|
+
* Importing this module also auto-registers every shipped music handler
|
|
11
|
+
* whose backing API key is present in `process.env`. Registration is
|
|
12
|
+
* idempotent and silently skipped if a provider is already registered or
|
|
13
|
+
* its constructor throws (e.g. missing optional native dependency).
|
|
14
|
+
*
|
|
10
15
|
* @module music
|
|
11
16
|
*/
|
|
17
|
+
import { logger } from "../utils/logger.js";
|
|
18
|
+
import { MusicProcessor } from "../utils/musicProcessor.js";
|
|
12
19
|
export { MUSIC_ERROR_CODES, MusicError, MusicProcessor, } from "../utils/musicProcessor.js";
|
|
20
|
+
// ============================================================================
|
|
21
|
+
// HANDLER CLASSES
|
|
22
|
+
// ============================================================================
|
|
13
23
|
export { BeatovenMusic, BeatovenMusic as BeatovenMusicHandler, } from "./providers/BeatovenMusic.js";
|
|
24
|
+
export { ElevenLabsMusic, ElevenLabsMusic as ElevenLabsMusicHandler, } from "./providers/ElevenLabsMusic.js";
|
|
25
|
+
export { LyriaMusic, LyriaMusic as LyriaMusicHandler, } from "./providers/LyriaMusic.js";
|
|
26
|
+
export { ReplicateMusic, ReplicateMusic as ReplicateMusicHandler, } from "./providers/ReplicateMusic.js";
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// AUTO-REGISTRATION
|
|
29
|
+
// ============================================================================
|
|
30
|
+
import { BeatovenMusic } from "./providers/BeatovenMusic.js";
|
|
31
|
+
import { ElevenLabsMusic } from "./providers/ElevenLabsMusic.js";
|
|
32
|
+
import { LyriaMusic } from "./providers/LyriaMusic.js";
|
|
33
|
+
import { ReplicateMusic } from "./providers/ReplicateMusic.js";
|
|
34
|
+
const MUSIC_HANDLER_CANDIDATES = [
|
|
35
|
+
{ name: "beatoven", factory: () => new BeatovenMusic() },
|
|
36
|
+
{
|
|
37
|
+
name: "elevenlabs-music",
|
|
38
|
+
aliases: ["elevenlabs-sound"],
|
|
39
|
+
factory: () => new ElevenLabsMusic(),
|
|
40
|
+
},
|
|
41
|
+
{ name: "lyria", factory: () => new LyriaMusic() },
|
|
42
|
+
{
|
|
43
|
+
name: "replicate",
|
|
44
|
+
aliases: ["musicgen"],
|
|
45
|
+
factory: () => new ReplicateMusic(),
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
/**
|
|
49
|
+
* Register every shipped music handler whose backing credentials are
|
|
50
|
+
* present in the environment. Safe to call multiple times — existing
|
|
51
|
+
* registrations are preserved.
|
|
52
|
+
*/
|
|
53
|
+
export function registerDefaultMusicHandlers() {
|
|
54
|
+
for (const { name, aliases, factory } of MUSIC_HANDLER_CANDIDATES) {
|
|
55
|
+
// Compute missingName / missingAliases separately so a pre-registered
|
|
56
|
+
// primary doesn't block alias backfill — keeps "musicgen" reachable
|
|
57
|
+
// when only "replicate" was wired up via another path (and likewise
|
|
58
|
+
// "elevenlabs-sound" vs "elevenlabs-music").
|
|
59
|
+
const missingName = !MusicProcessor.supports(name);
|
|
60
|
+
const missingAliases = (aliases ?? []).filter((alias) => !MusicProcessor.supports(alias));
|
|
61
|
+
if (!missingName && missingAliases.length === 0) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
// Reuse the already-registered primary's handler for alias backfill
|
|
66
|
+
// when one exists — wiring an alias to a factory-fresh instance
|
|
67
|
+
// would silently diverge from the canonical primary's config.
|
|
68
|
+
let handler;
|
|
69
|
+
if (!missingName) {
|
|
70
|
+
handler = MusicProcessor.getHandler(name);
|
|
71
|
+
}
|
|
72
|
+
if (!handler) {
|
|
73
|
+
handler = factory();
|
|
74
|
+
if (!handler.isConfigured()) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (missingName) {
|
|
79
|
+
MusicProcessor.registerHandler(name, handler);
|
|
80
|
+
}
|
|
81
|
+
for (const alias of missingAliases) {
|
|
82
|
+
MusicProcessor.registerHandler(alias, handler);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
logger.debug(`[music] ${name} auto-registration skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Run once at module import so consumers who follow the documented
|
|
91
|
+
// `nl.generate(...)` flow get every configured handler without manually
|
|
92
|
+
// calling `registerHandler`.
|
|
93
|
+
registerDefaultMusicHandlers();
|
|
@@ -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,4 +29,12 @@ 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
|
}
|
|
@@ -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>;
|