@juspay/neurolink 9.66.0 → 9.67.1
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/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 +389 -383
- 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/providers/openaiCompatible.d.ts +46 -19
- package/dist/lib/providers/openaiCompatible.js +1069 -171
- package/dist/lib/types/avatar.d.ts +8 -1
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/index.js +1 -0
- package/dist/lib/types/middleware.d.ts +1 -1
- package/dist/lib/types/multimodal.d.ts +20 -7
- package/dist/lib/types/music.d.ts +8 -1
- package/dist/lib/types/openaiCompatible.d.ts +250 -0
- package/dist/lib/types/openaiCompatible.js +2 -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/providers/openaiCompatible.d.ts +46 -19
- package/dist/providers/openaiCompatible.js +1069 -171
- package/dist/types/avatar.d.ts +8 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/middleware.d.ts +1 -1
- package/dist/types/multimodal.d.ts +20 -7
- package/dist/types/music.d.ts +8 -1
- package/dist/types/openaiCompatible.d.ts +250 -0
- package/dist/types/openaiCompatible.js +1 -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 +66 -2
|
@@ -1389,9 +1389,13 @@ export class BaseProvider {
|
|
|
1389
1389
|
* // result.video contains the generated video
|
|
1390
1390
|
* ```
|
|
1391
1391
|
*/
|
|
1392
|
+
// eslint-disable-next-line max-lines-per-function
|
|
1392
1393
|
async handleVideoGeneration(options, startTime) {
|
|
1393
|
-
// Dynamic imports to avoid loading video dependencies unless needed
|
|
1394
|
-
|
|
1394
|
+
// Dynamic imports to avoid loading video dependencies unless needed.
|
|
1395
|
+
// Pull VideoError + VIDEO_ERROR_CODES from VideoProcessor (which already
|
|
1396
|
+
// re-exports both) so non-vertex routes don't carry a direct dependency
|
|
1397
|
+
// on the Vertex adapter's module.
|
|
1398
|
+
const { VideoProcessor, VideoError, VIDEO_ERROR_CODES } = await import("../utils/videoProcessor.js");
|
|
1395
1399
|
const { validateVideoGenerationInput, validateImageForVideo, validateDirectorModeInput, } = await import("../utils/parameterValidation.js");
|
|
1396
1400
|
const { ErrorFactory } = await import("../utils/errorHandling.js");
|
|
1397
1401
|
// Build GenerateOptions for validation
|
|
@@ -1559,17 +1563,54 @@ export class BaseProvider {
|
|
|
1559
1563
|
}
|
|
1560
1564
|
// Get prompt text
|
|
1561
1565
|
const prompt = options.prompt || options.input?.text || "";
|
|
1566
|
+
// Honor output.video.provider — when omitted, fall back to "vertex"
|
|
1567
|
+
// for backward compatibility with the original implementation.
|
|
1568
|
+
const requestedProvider = options.output?.video?.provider ?? "vertex";
|
|
1569
|
+
if (!VideoProcessor.supports(requestedProvider)) {
|
|
1570
|
+
throw new VideoError({
|
|
1571
|
+
code: VIDEO_ERROR_CODES.PROVIDER_NOT_SUPPORTED,
|
|
1572
|
+
message: `Video provider "${requestedProvider}" is not registered. Available: ${VideoProcessor.listProviders().join(", ")}`,
|
|
1573
|
+
retriable: false,
|
|
1574
|
+
context: {
|
|
1575
|
+
provider: requestedProvider,
|
|
1576
|
+
available: VideoProcessor.listProviders(),
|
|
1577
|
+
},
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1580
|
+
// Resolve the model name without hardcoding a Vertex default for
|
|
1581
|
+
// non-Vertex routes. Precedence: caller-supplied output.video.model,
|
|
1582
|
+
// then options.model (LLM-level field that the caller may have repurposed
|
|
1583
|
+
// for video), then the Vertex Veo default but only when we're actually
|
|
1584
|
+
// calling Vertex. Otherwise leave it null at this stage and let the
|
|
1585
|
+
// handler's metadata fill it in below.
|
|
1586
|
+
const requestedVideoModel = options.output?.video?.model;
|
|
1587
|
+
const resolvedRequestModel = requestedVideoModel ??
|
|
1588
|
+
options.model ??
|
|
1589
|
+
(requestedProvider === "vertex" ? "veo-3.1-generate-001" : undefined);
|
|
1562
1590
|
logger.info("Starting video generation", {
|
|
1563
|
-
provider:
|
|
1564
|
-
model:
|
|
1591
|
+
provider: requestedProvider,
|
|
1592
|
+
...(resolvedRequestModel ? { model: resolvedRequestModel } : {}),
|
|
1565
1593
|
promptLength: prompt.length,
|
|
1566
1594
|
imageSize: imageBuffer.length,
|
|
1567
1595
|
resolution: options.output?.video?.resolution || "720p",
|
|
1568
1596
|
duration: options.output?.video?.length || 6,
|
|
1569
1597
|
});
|
|
1570
|
-
//
|
|
1571
|
-
|
|
1598
|
+
// Dispatch through the central VideoProcessor — picks up vertex,
|
|
1599
|
+
// kling, runway, replicate (or any custom handler) registered via
|
|
1600
|
+
// ProviderRegistry / VideoProcessor.registerHandler(). Wrap in the
|
|
1601
|
+
// shared timeout helper so standard video gen honors the caller's
|
|
1602
|
+
// timeout the same way director mode does (see above ~Line 2062).
|
|
1603
|
+
const videoTimeout = options.timeout ?? 600_000; // 10 min default
|
|
1604
|
+
const videoResult = await this.executeWithTimeout(() => VideoProcessor.generate(requestedProvider, imageBuffer, prompt, options.output?.video ?? {}, options.region), { timeout: videoTimeout, operationType: "generate" });
|
|
1605
|
+
// Prefer the handler's own model id (more accurate — it knows the exact
|
|
1606
|
+
// checkpoint that ran). Fall back to the request-time value, and finally
|
|
1607
|
+
// to the Vertex default only when we're on the Vertex route.
|
|
1608
|
+
const responseModel = videoResult.metadata?.model ??
|
|
1609
|
+
resolvedRequestModel ??
|
|
1610
|
+
(requestedProvider === "vertex" ? "veo-3.1-generate-001" : "unknown");
|
|
1572
1611
|
logger.info("Video generation complete", {
|
|
1612
|
+
provider: requestedProvider,
|
|
1613
|
+
model: responseModel,
|
|
1573
1614
|
videoSize: videoResult.data.length,
|
|
1574
1615
|
duration: videoResult.metadata?.duration,
|
|
1575
1616
|
processingTime: videoResult.metadata?.processingTime,
|
|
@@ -1577,8 +1618,8 @@ export class BaseProvider {
|
|
|
1577
1618
|
// Build result
|
|
1578
1619
|
const baseResult = {
|
|
1579
1620
|
content: prompt, // Echo the prompt as content
|
|
1580
|
-
provider:
|
|
1581
|
-
model:
|
|
1621
|
+
provider: requestedProvider,
|
|
1622
|
+
model: responseModel,
|
|
1582
1623
|
usage: { input: 0, output: 0, total: 0 },
|
|
1583
1624
|
video: videoResult,
|
|
1584
1625
|
};
|
|
@@ -298,6 +298,29 @@ export class ProviderRegistry {
|
|
|
298
298
|
catch (err) {
|
|
299
299
|
logger.debug(`[ProviderRegistry] azure-tts registration skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
300
300
|
}
|
|
301
|
+
// Fish Audio and Cartesia also auto-register via the voice/index.ts
|
|
302
|
+
// barrel side-effect. The supports() guard here keeps registration
|
|
303
|
+
// idempotent across entry points — same handler, no overwrite warning.
|
|
304
|
+
try {
|
|
305
|
+
const { TTSProcessor } = await import("../utils/ttsProcessor.js");
|
|
306
|
+
if (!TTSProcessor.supports("fish-audio")) {
|
|
307
|
+
const { FishAudioTTS } = await import("../voice/providers/FishAudioTTS.js");
|
|
308
|
+
TTSProcessor.registerHandler("fish-audio", new FishAudioTTS());
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
catch (err) {
|
|
312
|
+
logger.debug(`[ProviderRegistry] fish-audio registration skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
const { TTSProcessor } = await import("../utils/ttsProcessor.js");
|
|
316
|
+
if (!TTSProcessor.supports("cartesia")) {
|
|
317
|
+
const { CartesiaTTS } = await import("../voice/providers/CartesiaTTS.js");
|
|
318
|
+
TTSProcessor.registerHandler("cartesia", new CartesiaTTS());
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
catch (err) {
|
|
322
|
+
logger.debug(`[ProviderRegistry] cartesia registration skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
323
|
+
}
|
|
301
324
|
// ===== STT HANDLER REGISTRATION =====
|
|
302
325
|
try {
|
|
303
326
|
const { STTProcessor } = await import("../utils/sttProcessor.js");
|
package/dist/index.d.ts
CHANGED
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
*/
|
|
34
34
|
import { AIProviderFactory } from "./core/factory.js";
|
|
35
35
|
export { AIProviderFactory };
|
|
36
|
-
export { GoogleTTSHandler } from "./adapters/tts/googleTTSHandler.js";
|
|
37
36
|
export { NeuroLinkConfigManager as ConfigManager } from "./config/configManager.js";
|
|
38
37
|
export { BaseFactory, BaseRegistry, NeuroLinkFeatureError, createErrorFactory, withRetry, TypedEventEmitter, } from "./core/infrastructure/index.js";
|
|
39
38
|
export { NeuroLinkClient, createClient, NeuroLinkApiError, NeuroLinkLanguageModel, NeuroLinkAIProvider, createNeuroLinkProvider, createNeuroLinkModel, createStreamingResponse, neurolink as neuroLinkAIInstance, createApiKeyAuthInterceptor, createBearerAuthInterceptor, createDynamicAuthInterceptor, createLoggingInterceptor, createRetryInterceptor, createRateLimitInterceptor, createRequestTransformInterceptor, createResponseTransformInterceptor, createCacheInterceptor, createTimeoutInterceptor, createErrorHandlerInterceptor, composeMiddleware, conditionalMiddleware, SSEClient, WebSocketStreamingClient, createStreamingClient, createAsyncStream, collectStream, OAuth2TokenManager, JWTTokenManager, createApiKeyMiddleware, createBearerTokenMiddleware, createTokenManagerMiddleware, createAuthWithRetryMiddleware, createMultiAuthMiddleware, OAuth2Error, OAuth2AuthError, TokenRefreshError, decodeJWTPayload, isJWTExpired, getJWTExpiry, getApiKeyFromEnv, ErrorCode as ClientErrorCode, NeuroLinkError as ClientNeuroLinkError, HttpError, ClientRateLimitError, ClientValidationError, ClientAuthenticationError, ClientAuthorizationError, NotFoundError, ClientNetworkError, ClientTimeoutError, ClientConnectionError, AbortError, ClientConfigurationError, StreamError, ClientProviderError, ContextLengthError, ContentFilterError, createErrorFromResponse, createErrorFromNative, mapStatusToErrorCode, isRetryableStatus, isRetryableError, isNeuroLinkError, isApiError, } from "./client/index.js";
|
|
@@ -52,6 +51,16 @@ export { AvatarProcessor } from "./utils/avatarProcessor.js";
|
|
|
52
51
|
export { AVATAR_ERROR_CODES, AvatarError } from "./utils/avatarProcessor.js";
|
|
53
52
|
export { MusicProcessor } from "./utils/musicProcessor.js";
|
|
54
53
|
export { MUSIC_ERROR_CODES, MusicError } from "./utils/musicProcessor.js";
|
|
54
|
+
export { STTProcessor } from "./utils/sttProcessor.js";
|
|
55
|
+
export { AzureTTS, AzureTTSHandler, CartesiaTTS, CartesiaTTSHandler, ElevenLabsTTS, ElevenLabsTTSHandler, FishAudioTTS, FishAudioTTSHandler, GoogleTTSHandler, OpenAITTS, OpenAITTSHandler, AzureSTT, AzureSTTHandler, DeepgramSTT, DeepgramSTTHandler, GoogleSTT, GoogleSTTHandler, OpenAISTT, OpenAISTTHandler, WhisperSTT, WhisperSTTHandler, BaseRealtimeHandler, GeminiLive, GeminiLiveHandler, OpenAIRealtime, OpenAIRealtimeHandler, RealtimeProcessor, RealtimeError, STTError, VoiceError, registerDefaultRealtimeHandlers, registerDefaultSTTHandlers, registerDefaultTTSHandlers, } from "./voice/index.js";
|
|
56
|
+
export { BeatovenMusic, BeatovenMusicHandler, ElevenLabsMusic, ElevenLabsMusicHandler, LyriaMusic, LyriaMusicHandler, registerDefaultMusicHandlers, ReplicateMusic, ReplicateMusicHandler, } from "./music/index.js";
|
|
57
|
+
export { DIDAvatar, DIDAvatarHandler, HeyGenAvatar, HeyGenAvatarHandler, registerDefaultAvatarHandlers, ReplicateAvatar, ReplicateAvatarHandler, } from "./avatar/index.js";
|
|
58
|
+
export { KlingVideoHandler } from "./adapters/video/klingVideoHandler.js";
|
|
59
|
+
export { ReplicateVideoHandler } from "./adapters/video/replicateVideoHandler.js";
|
|
60
|
+
export { RunwayVideoHandler } from "./adapters/video/runwayVideoHandler.js";
|
|
61
|
+
export { VertexVideoHandler, isVertexVideoConfigured, } from "./adapters/video/vertexVideoHandler.js";
|
|
62
|
+
export { ImageGenService } from "./image-gen/ImageGenService.js";
|
|
63
|
+
export { HITLManager } from "./hitl/hitlManager.js";
|
|
55
64
|
export { ProviderRegistry } from "./factories/providerRegistry.js";
|
|
56
65
|
import { NeuroLink } from "./neurolink.js";
|
|
57
66
|
export { NeuroLink };
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
// Core exports
|
|
35
35
|
import { AIProviderFactory } from "./core/factory.js";
|
|
36
36
|
export { AIProviderFactory };
|
|
37
|
-
export { GoogleTTSHandler } from "./adapters/tts/googleTTSHandler.js";
|
|
38
37
|
// Config Manager export
|
|
39
38
|
export { NeuroLinkConfigManager as ConfigManager } from "./config/configManager.js";
|
|
40
39
|
// Core Infrastructure exports (factory + registry patterns)
|
|
@@ -81,6 +80,42 @@ export { AVATAR_ERROR_CODES, AvatarError } from "./utils/avatarProcessor.js";
|
|
|
81
80
|
// Music utilities
|
|
82
81
|
export { MusicProcessor } from "./utils/musicProcessor.js";
|
|
83
82
|
export { MUSIC_ERROR_CODES, MusicError } from "./utils/musicProcessor.js";
|
|
83
|
+
// STT / Realtime processors (registries for speech-to-text + live voice)
|
|
84
|
+
export { STTProcessor } from "./utils/sttProcessor.js";
|
|
85
|
+
// STT_ERROR_CODES is surfaced via the types barrel (export * from "./types/index.js")
|
|
86
|
+
// STTError is re-exported below from the voice/index.js barrel
|
|
87
|
+
// ============================================================================
|
|
88
|
+
// MEDIA HANDLER CLASSES + AUTO-REGISTRATION
|
|
89
|
+
// ============================================================================
|
|
90
|
+
// Re-exporting from the voice/music/avatar barrels also triggers their
|
|
91
|
+
// module-level auto-registration side effects. Consumers who follow the
|
|
92
|
+
// documented `nl.generate(...)` flow get every shipped handler whose API
|
|
93
|
+
// key is present in process.env, with no manual registerHandler() needed.
|
|
94
|
+
// TTS, STT, Realtime handlers + RealtimeProcessor
|
|
95
|
+
export {
|
|
96
|
+
// TTS
|
|
97
|
+
AzureTTS, AzureTTSHandler, CartesiaTTS, CartesiaTTSHandler, ElevenLabsTTS, ElevenLabsTTSHandler, FishAudioTTS, FishAudioTTSHandler, GoogleTTSHandler, OpenAITTS, OpenAITTSHandler,
|
|
98
|
+
// STT
|
|
99
|
+
AzureSTT, AzureSTTHandler, DeepgramSTT, DeepgramSTTHandler, GoogleSTT, GoogleSTTHandler, OpenAISTT, OpenAISTTHandler, WhisperSTT, WhisperSTTHandler,
|
|
100
|
+
// Realtime
|
|
101
|
+
BaseRealtimeHandler, GeminiLive, GeminiLiveHandler, OpenAIRealtime, OpenAIRealtimeHandler, RealtimeProcessor,
|
|
102
|
+
// Voice error classes (RealtimeError + STTError + VoiceError)
|
|
103
|
+
RealtimeError, STTError, VoiceError,
|
|
104
|
+
// Auto-registration functions (exposed so consumers can re-run them
|
|
105
|
+
// after mutating process.env at runtime, e.g. in test setups)
|
|
106
|
+
registerDefaultRealtimeHandlers, registerDefaultSTTHandlers, registerDefaultTTSHandlers, } from "./voice/index.js";
|
|
107
|
+
// Music handlers
|
|
108
|
+
export { BeatovenMusic, BeatovenMusicHandler, ElevenLabsMusic, ElevenLabsMusicHandler, LyriaMusic, LyriaMusicHandler, registerDefaultMusicHandlers, ReplicateMusic, ReplicateMusicHandler, } from "./music/index.js";
|
|
109
|
+
// Avatar handlers
|
|
110
|
+
export { DIDAvatar, DIDAvatarHandler, HeyGenAvatar, HeyGenAvatarHandler, registerDefaultAvatarHandlers, ReplicateAvatar, ReplicateAvatarHandler, } from "./avatar/index.js";
|
|
111
|
+
// Video handlers (live under adapters/video; no separate video/ barrel)
|
|
112
|
+
export { KlingVideoHandler } from "./adapters/video/klingVideoHandler.js";
|
|
113
|
+
export { ReplicateVideoHandler } from "./adapters/video/replicateVideoHandler.js";
|
|
114
|
+
export { RunwayVideoHandler } from "./adapters/video/runwayVideoHandler.js";
|
|
115
|
+
export { VertexVideoHandler, isVertexVideoConfigured, } from "./adapters/video/vertexVideoHandler.js";
|
|
116
|
+
// Image generation + HITL — surfaced from their dedicated barrels
|
|
117
|
+
export { ImageGenService } from "./image-gen/ImageGenService.js";
|
|
118
|
+
export { HITLManager } from "./hitl/hitlManager.js";
|
|
84
119
|
// Provider registry (for tests, advanced consumers, and tools that need to
|
|
85
120
|
// invoke registerAllProviders() outside of constructing a NeuroLink instance)
|
|
86
121
|
export { ProviderRegistry } from "./factories/providerRegistry.js";
|
|
@@ -7,7 +7,20 @@
|
|
|
7
7
|
* Use `AvatarProcessor.generate(provider, options)` to dispatch to the
|
|
8
8
|
* registered handler for `provider`.
|
|
9
9
|
*
|
|
10
|
+
* Importing this module also auto-registers every shipped avatar 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.
|
|
14
|
+
*
|
|
10
15
|
* @module avatar
|
|
11
16
|
*/
|
|
12
17
|
export { AVATAR_ERROR_CODES, AvatarError, AvatarProcessor, } from "../utils/avatarProcessor.js";
|
|
13
18
|
export { DIDAvatar, DIDAvatar as DIDAvatarHandler, } from "./providers/DIDAvatar.js";
|
|
19
|
+
export { HeyGenAvatar, HeyGenAvatar as HeyGenAvatarHandler, } from "./providers/HeyGenAvatar.js";
|
|
20
|
+
export { ReplicateAvatar, ReplicateAvatar as ReplicateAvatarHandler, } from "./providers/ReplicateAvatar.js";
|
|
21
|
+
/**
|
|
22
|
+
* Register every shipped avatar handler whose backing credentials are
|
|
23
|
+
* present in the environment. Safe to call multiple times — existing
|
|
24
|
+
* registrations are preserved.
|
|
25
|
+
*/
|
|
26
|
+
export declare function registerDefaultAvatarHandlers(): void;
|
package/dist/lib/avatar/index.js
CHANGED
|
@@ -7,8 +7,80 @@
|
|
|
7
7
|
* Use `AvatarProcessor.generate(provider, options)` to dispatch to the
|
|
8
8
|
* registered handler for `provider`.
|
|
9
9
|
*
|
|
10
|
+
* Importing this module also auto-registers every shipped avatar 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.
|
|
14
|
+
*
|
|
10
15
|
* @module avatar
|
|
11
16
|
*/
|
|
17
|
+
import { logger } from "../utils/logger.js";
|
|
18
|
+
import { AvatarProcessor } from "../utils/avatarProcessor.js";
|
|
12
19
|
export { AVATAR_ERROR_CODES, AvatarError, AvatarProcessor, } from "../utils/avatarProcessor.js";
|
|
20
|
+
// ============================================================================
|
|
21
|
+
// HANDLER CLASSES
|
|
22
|
+
// ============================================================================
|
|
13
23
|
export { DIDAvatar, DIDAvatar as DIDAvatarHandler, } from "./providers/DIDAvatar.js";
|
|
24
|
+
export { HeyGenAvatar, HeyGenAvatar as HeyGenAvatarHandler, } from "./providers/HeyGenAvatar.js";
|
|
25
|
+
export { ReplicateAvatar, ReplicateAvatar as ReplicateAvatarHandler, } from "./providers/ReplicateAvatar.js";
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// AUTO-REGISTRATION
|
|
28
|
+
// ============================================================================
|
|
29
|
+
import { DIDAvatar } from "./providers/DIDAvatar.js";
|
|
30
|
+
import { HeyGenAvatar } from "./providers/HeyGenAvatar.js";
|
|
31
|
+
import { ReplicateAvatar } from "./providers/ReplicateAvatar.js";
|
|
32
|
+
const AVATAR_HANDLER_CANDIDATES = [
|
|
33
|
+
{ name: "d-id", factory: () => new DIDAvatar() },
|
|
34
|
+
{ name: "heygen", factory: () => new HeyGenAvatar() },
|
|
35
|
+
{
|
|
36
|
+
name: "replicate",
|
|
37
|
+
aliases: ["musetalk"],
|
|
38
|
+
factory: () => new ReplicateAvatar(),
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
/**
|
|
42
|
+
* Register every shipped avatar handler whose backing credentials are
|
|
43
|
+
* present in the environment. Safe to call multiple times — existing
|
|
44
|
+
* registrations are preserved.
|
|
45
|
+
*/
|
|
46
|
+
export function registerDefaultAvatarHandlers() {
|
|
47
|
+
for (const { name, aliases, factory } of AVATAR_HANDLER_CANDIDATES) {
|
|
48
|
+
// Compute missingName / missingAliases separately so a pre-registered
|
|
49
|
+
// primary doesn't block alias backfill — keeps "musetalk" reachable
|
|
50
|
+
// when only "replicate" was wired up via another path.
|
|
51
|
+
const missingName = !AvatarProcessor.supports(name);
|
|
52
|
+
const missingAliases = (aliases ?? []).filter((alias) => !AvatarProcessor.supports(alias));
|
|
53
|
+
if (!missingName && missingAliases.length === 0) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
// Reuse the already-registered primary's handler for alias backfill
|
|
58
|
+
// when one exists — wiring an alias to a factory-fresh instance
|
|
59
|
+
// would silently diverge from the canonical primary's config.
|
|
60
|
+
let handler;
|
|
61
|
+
if (!missingName) {
|
|
62
|
+
handler = AvatarProcessor.getHandler(name);
|
|
63
|
+
}
|
|
64
|
+
if (!handler) {
|
|
65
|
+
handler = factory();
|
|
66
|
+
if (!handler.isConfigured()) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (missingName) {
|
|
71
|
+
AvatarProcessor.registerHandler(name, handler);
|
|
72
|
+
}
|
|
73
|
+
for (const alias of missingAliases) {
|
|
74
|
+
AvatarProcessor.registerHandler(alias, handler);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
logger.debug(`[avatar] ${name} auto-registration skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Run once at module import so consumers who follow the documented
|
|
83
|
+
// `nl.generate(...)` flow get every configured handler without manually
|
|
84
|
+
// calling `registerHandler`.
|
|
85
|
+
registerDefaultAvatarHandlers();
|
|
14
86
|
//# sourceMappingURL=index.js.map
|
|
@@ -1389,9 +1389,13 @@ export class BaseProvider {
|
|
|
1389
1389
|
* // result.video contains the generated video
|
|
1390
1390
|
* ```
|
|
1391
1391
|
*/
|
|
1392
|
+
// eslint-disable-next-line max-lines-per-function
|
|
1392
1393
|
async handleVideoGeneration(options, startTime) {
|
|
1393
|
-
// Dynamic imports to avoid loading video dependencies unless needed
|
|
1394
|
-
|
|
1394
|
+
// Dynamic imports to avoid loading video dependencies unless needed.
|
|
1395
|
+
// Pull VideoError + VIDEO_ERROR_CODES from VideoProcessor (which already
|
|
1396
|
+
// re-exports both) so non-vertex routes don't carry a direct dependency
|
|
1397
|
+
// on the Vertex adapter's module.
|
|
1398
|
+
const { VideoProcessor, VideoError, VIDEO_ERROR_CODES } = await import("../utils/videoProcessor.js");
|
|
1395
1399
|
const { validateVideoGenerationInput, validateImageForVideo, validateDirectorModeInput, } = await import("../utils/parameterValidation.js");
|
|
1396
1400
|
const { ErrorFactory } = await import("../utils/errorHandling.js");
|
|
1397
1401
|
// Build GenerateOptions for validation
|
|
@@ -1559,17 +1563,54 @@ export class BaseProvider {
|
|
|
1559
1563
|
}
|
|
1560
1564
|
// Get prompt text
|
|
1561
1565
|
const prompt = options.prompt || options.input?.text || "";
|
|
1566
|
+
// Honor output.video.provider — when omitted, fall back to "vertex"
|
|
1567
|
+
// for backward compatibility with the original implementation.
|
|
1568
|
+
const requestedProvider = options.output?.video?.provider ?? "vertex";
|
|
1569
|
+
if (!VideoProcessor.supports(requestedProvider)) {
|
|
1570
|
+
throw new VideoError({
|
|
1571
|
+
code: VIDEO_ERROR_CODES.PROVIDER_NOT_SUPPORTED,
|
|
1572
|
+
message: `Video provider "${requestedProvider}" is not registered. Available: ${VideoProcessor.listProviders().join(", ")}`,
|
|
1573
|
+
retriable: false,
|
|
1574
|
+
context: {
|
|
1575
|
+
provider: requestedProvider,
|
|
1576
|
+
available: VideoProcessor.listProviders(),
|
|
1577
|
+
},
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1580
|
+
// Resolve the model name without hardcoding a Vertex default for
|
|
1581
|
+
// non-Vertex routes. Precedence: caller-supplied output.video.model,
|
|
1582
|
+
// then options.model (LLM-level field that the caller may have repurposed
|
|
1583
|
+
// for video), then the Vertex Veo default but only when we're actually
|
|
1584
|
+
// calling Vertex. Otherwise leave it null at this stage and let the
|
|
1585
|
+
// handler's metadata fill it in below.
|
|
1586
|
+
const requestedVideoModel = options.output?.video?.model;
|
|
1587
|
+
const resolvedRequestModel = requestedVideoModel ??
|
|
1588
|
+
options.model ??
|
|
1589
|
+
(requestedProvider === "vertex" ? "veo-3.1-generate-001" : undefined);
|
|
1562
1590
|
logger.info("Starting video generation", {
|
|
1563
|
-
provider:
|
|
1564
|
-
model:
|
|
1591
|
+
provider: requestedProvider,
|
|
1592
|
+
...(resolvedRequestModel ? { model: resolvedRequestModel } : {}),
|
|
1565
1593
|
promptLength: prompt.length,
|
|
1566
1594
|
imageSize: imageBuffer.length,
|
|
1567
1595
|
resolution: options.output?.video?.resolution || "720p",
|
|
1568
1596
|
duration: options.output?.video?.length || 6,
|
|
1569
1597
|
});
|
|
1570
|
-
//
|
|
1571
|
-
|
|
1598
|
+
// Dispatch through the central VideoProcessor — picks up vertex,
|
|
1599
|
+
// kling, runway, replicate (or any custom handler) registered via
|
|
1600
|
+
// ProviderRegistry / VideoProcessor.registerHandler(). Wrap in the
|
|
1601
|
+
// shared timeout helper so standard video gen honors the caller's
|
|
1602
|
+
// timeout the same way director mode does (see above ~Line 2062).
|
|
1603
|
+
const videoTimeout = options.timeout ?? 600_000; // 10 min default
|
|
1604
|
+
const videoResult = await this.executeWithTimeout(() => VideoProcessor.generate(requestedProvider, imageBuffer, prompt, options.output?.video ?? {}, options.region), { timeout: videoTimeout, operationType: "generate" });
|
|
1605
|
+
// Prefer the handler's own model id (more accurate — it knows the exact
|
|
1606
|
+
// checkpoint that ran). Fall back to the request-time value, and finally
|
|
1607
|
+
// to the Vertex default only when we're on the Vertex route.
|
|
1608
|
+
const responseModel = videoResult.metadata?.model ??
|
|
1609
|
+
resolvedRequestModel ??
|
|
1610
|
+
(requestedProvider === "vertex" ? "veo-3.1-generate-001" : "unknown");
|
|
1572
1611
|
logger.info("Video generation complete", {
|
|
1612
|
+
provider: requestedProvider,
|
|
1613
|
+
model: responseModel,
|
|
1573
1614
|
videoSize: videoResult.data.length,
|
|
1574
1615
|
duration: videoResult.metadata?.duration,
|
|
1575
1616
|
processingTime: videoResult.metadata?.processingTime,
|
|
@@ -1577,8 +1618,8 @@ export class BaseProvider {
|
|
|
1577
1618
|
// Build result
|
|
1578
1619
|
const baseResult = {
|
|
1579
1620
|
content: prompt, // Echo the prompt as content
|
|
1580
|
-
provider:
|
|
1581
|
-
model:
|
|
1621
|
+
provider: requestedProvider,
|
|
1622
|
+
model: responseModel,
|
|
1582
1623
|
usage: { input: 0, output: 0, total: 0 },
|
|
1583
1624
|
video: videoResult,
|
|
1584
1625
|
};
|
|
@@ -298,6 +298,29 @@ export class ProviderRegistry {
|
|
|
298
298
|
catch (err) {
|
|
299
299
|
logger.debug(`[ProviderRegistry] azure-tts registration skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
300
300
|
}
|
|
301
|
+
// Fish Audio and Cartesia also auto-register via the voice/index.ts
|
|
302
|
+
// barrel side-effect. The supports() guard here keeps registration
|
|
303
|
+
// idempotent across entry points — same handler, no overwrite warning.
|
|
304
|
+
try {
|
|
305
|
+
const { TTSProcessor } = await import("../utils/ttsProcessor.js");
|
|
306
|
+
if (!TTSProcessor.supports("fish-audio")) {
|
|
307
|
+
const { FishAudioTTS } = await import("../voice/providers/FishAudioTTS.js");
|
|
308
|
+
TTSProcessor.registerHandler("fish-audio", new FishAudioTTS());
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
catch (err) {
|
|
312
|
+
logger.debug(`[ProviderRegistry] fish-audio registration skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
const { TTSProcessor } = await import("../utils/ttsProcessor.js");
|
|
316
|
+
if (!TTSProcessor.supports("cartesia")) {
|
|
317
|
+
const { CartesiaTTS } = await import("../voice/providers/CartesiaTTS.js");
|
|
318
|
+
TTSProcessor.registerHandler("cartesia", new CartesiaTTS());
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
catch (err) {
|
|
322
|
+
logger.debug(`[ProviderRegistry] cartesia registration skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
323
|
+
}
|
|
301
324
|
// ===== STT HANDLER REGISTRATION =====
|
|
302
325
|
try {
|
|
303
326
|
const { STTProcessor } = await import("../utils/sttProcessor.js");
|
|
@@ -157,7 +157,7 @@ export declare function createFileTools(registry: FileReferenceRegistry): {
|
|
|
157
157
|
} | undefined;
|
|
158
158
|
columns?: string[] | undefined;
|
|
159
159
|
entry_path?: string | undefined;
|
|
160
|
-
format?: "text" | "
|
|
160
|
+
format?: "text" | "detailed" | "summary" | undefined;
|
|
161
161
|
}, {
|
|
162
162
|
success: false;
|
|
163
163
|
error: string | undefined;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
*/
|
|
34
34
|
import { AIProviderFactory } from "./core/factory.js";
|
|
35
35
|
export { AIProviderFactory };
|
|
36
|
-
export { GoogleTTSHandler } from "./adapters/tts/googleTTSHandler.js";
|
|
37
36
|
export { NeuroLinkConfigManager as ConfigManager } from "./config/configManager.js";
|
|
38
37
|
export { BaseFactory, BaseRegistry, NeuroLinkFeatureError, createErrorFactory, withRetry, TypedEventEmitter, } from "./core/infrastructure/index.js";
|
|
39
38
|
export { NeuroLinkClient, createClient, NeuroLinkApiError, NeuroLinkLanguageModel, NeuroLinkAIProvider, createNeuroLinkProvider, createNeuroLinkModel, createStreamingResponse, neurolink as neuroLinkAIInstance, createApiKeyAuthInterceptor, createBearerAuthInterceptor, createDynamicAuthInterceptor, createLoggingInterceptor, createRetryInterceptor, createRateLimitInterceptor, createRequestTransformInterceptor, createResponseTransformInterceptor, createCacheInterceptor, createTimeoutInterceptor, createErrorHandlerInterceptor, composeMiddleware, conditionalMiddleware, SSEClient, WebSocketStreamingClient, createStreamingClient, createAsyncStream, collectStream, OAuth2TokenManager, JWTTokenManager, createApiKeyMiddleware, createBearerTokenMiddleware, createTokenManagerMiddleware, createAuthWithRetryMiddleware, createMultiAuthMiddleware, OAuth2Error, OAuth2AuthError, TokenRefreshError, decodeJWTPayload, isJWTExpired, getJWTExpiry, getApiKeyFromEnv, ErrorCode as ClientErrorCode, NeuroLinkError as ClientNeuroLinkError, HttpError, ClientRateLimitError, ClientValidationError, ClientAuthenticationError, ClientAuthorizationError, NotFoundError, ClientNetworkError, ClientTimeoutError, ClientConnectionError, AbortError, ClientConfigurationError, StreamError, ClientProviderError, ContextLengthError, ContentFilterError, createErrorFromResponse, createErrorFromNative, mapStatusToErrorCode, isRetryableStatus, isRetryableError, isNeuroLinkError, isApiError, } from "./client/index.js";
|
|
@@ -52,6 +51,16 @@ export { AvatarProcessor } from "./utils/avatarProcessor.js";
|
|
|
52
51
|
export { AVATAR_ERROR_CODES, AvatarError } from "./utils/avatarProcessor.js";
|
|
53
52
|
export { MusicProcessor } from "./utils/musicProcessor.js";
|
|
54
53
|
export { MUSIC_ERROR_CODES, MusicError } from "./utils/musicProcessor.js";
|
|
54
|
+
export { STTProcessor } from "./utils/sttProcessor.js";
|
|
55
|
+
export { AzureTTS, AzureTTSHandler, CartesiaTTS, CartesiaTTSHandler, ElevenLabsTTS, ElevenLabsTTSHandler, FishAudioTTS, FishAudioTTSHandler, GoogleTTSHandler, OpenAITTS, OpenAITTSHandler, AzureSTT, AzureSTTHandler, DeepgramSTT, DeepgramSTTHandler, GoogleSTT, GoogleSTTHandler, OpenAISTT, OpenAISTTHandler, WhisperSTT, WhisperSTTHandler, BaseRealtimeHandler, GeminiLive, GeminiLiveHandler, OpenAIRealtime, OpenAIRealtimeHandler, RealtimeProcessor, RealtimeError, STTError, VoiceError, registerDefaultRealtimeHandlers, registerDefaultSTTHandlers, registerDefaultTTSHandlers, } from "./voice/index.js";
|
|
56
|
+
export { BeatovenMusic, BeatovenMusicHandler, ElevenLabsMusic, ElevenLabsMusicHandler, LyriaMusic, LyriaMusicHandler, registerDefaultMusicHandlers, ReplicateMusic, ReplicateMusicHandler, } from "./music/index.js";
|
|
57
|
+
export { DIDAvatar, DIDAvatarHandler, HeyGenAvatar, HeyGenAvatarHandler, registerDefaultAvatarHandlers, ReplicateAvatar, ReplicateAvatarHandler, } from "./avatar/index.js";
|
|
58
|
+
export { KlingVideoHandler } from "./adapters/video/klingVideoHandler.js";
|
|
59
|
+
export { ReplicateVideoHandler } from "./adapters/video/replicateVideoHandler.js";
|
|
60
|
+
export { RunwayVideoHandler } from "./adapters/video/runwayVideoHandler.js";
|
|
61
|
+
export { VertexVideoHandler, isVertexVideoConfigured, } from "./adapters/video/vertexVideoHandler.js";
|
|
62
|
+
export { ImageGenService } from "./image-gen/ImageGenService.js";
|
|
63
|
+
export { HITLManager } from "./hitl/hitlManager.js";
|
|
55
64
|
export { ProviderRegistry } from "./factories/providerRegistry.js";
|
|
56
65
|
import { NeuroLink } from "./neurolink.js";
|
|
57
66
|
export { NeuroLink };
|
package/dist/lib/index.js
CHANGED
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
// Core exports
|
|
35
35
|
import { AIProviderFactory } from "./core/factory.js";
|
|
36
36
|
export { AIProviderFactory };
|
|
37
|
-
export { GoogleTTSHandler } from "./adapters/tts/googleTTSHandler.js";
|
|
38
37
|
// Config Manager export
|
|
39
38
|
export { NeuroLinkConfigManager as ConfigManager } from "./config/configManager.js";
|
|
40
39
|
// Core Infrastructure exports (factory + registry patterns)
|
|
@@ -81,6 +80,42 @@ export { AVATAR_ERROR_CODES, AvatarError } from "./utils/avatarProcessor.js";
|
|
|
81
80
|
// Music utilities
|
|
82
81
|
export { MusicProcessor } from "./utils/musicProcessor.js";
|
|
83
82
|
export { MUSIC_ERROR_CODES, MusicError } from "./utils/musicProcessor.js";
|
|
83
|
+
// STT / Realtime processors (registries for speech-to-text + live voice)
|
|
84
|
+
export { STTProcessor } from "./utils/sttProcessor.js";
|
|
85
|
+
// STT_ERROR_CODES is surfaced via the types barrel (export * from "./types/index.js")
|
|
86
|
+
// STTError is re-exported below from the voice/index.js barrel
|
|
87
|
+
// ============================================================================
|
|
88
|
+
// MEDIA HANDLER CLASSES + AUTO-REGISTRATION
|
|
89
|
+
// ============================================================================
|
|
90
|
+
// Re-exporting from the voice/music/avatar barrels also triggers their
|
|
91
|
+
// module-level auto-registration side effects. Consumers who follow the
|
|
92
|
+
// documented `nl.generate(...)` flow get every shipped handler whose API
|
|
93
|
+
// key is present in process.env, with no manual registerHandler() needed.
|
|
94
|
+
// TTS, STT, Realtime handlers + RealtimeProcessor
|
|
95
|
+
export {
|
|
96
|
+
// TTS
|
|
97
|
+
AzureTTS, AzureTTSHandler, CartesiaTTS, CartesiaTTSHandler, ElevenLabsTTS, ElevenLabsTTSHandler, FishAudioTTS, FishAudioTTSHandler, GoogleTTSHandler, OpenAITTS, OpenAITTSHandler,
|
|
98
|
+
// STT
|
|
99
|
+
AzureSTT, AzureSTTHandler, DeepgramSTT, DeepgramSTTHandler, GoogleSTT, GoogleSTTHandler, OpenAISTT, OpenAISTTHandler, WhisperSTT, WhisperSTTHandler,
|
|
100
|
+
// Realtime
|
|
101
|
+
BaseRealtimeHandler, GeminiLive, GeminiLiveHandler, OpenAIRealtime, OpenAIRealtimeHandler, RealtimeProcessor,
|
|
102
|
+
// Voice error classes (RealtimeError + STTError + VoiceError)
|
|
103
|
+
RealtimeError, STTError, VoiceError,
|
|
104
|
+
// Auto-registration functions (exposed so consumers can re-run them
|
|
105
|
+
// after mutating process.env at runtime, e.g. in test setups)
|
|
106
|
+
registerDefaultRealtimeHandlers, registerDefaultSTTHandlers, registerDefaultTTSHandlers, } from "./voice/index.js";
|
|
107
|
+
// Music handlers
|
|
108
|
+
export { BeatovenMusic, BeatovenMusicHandler, ElevenLabsMusic, ElevenLabsMusicHandler, LyriaMusic, LyriaMusicHandler, registerDefaultMusicHandlers, ReplicateMusic, ReplicateMusicHandler, } from "./music/index.js";
|
|
109
|
+
// Avatar handlers
|
|
110
|
+
export { DIDAvatar, DIDAvatarHandler, HeyGenAvatar, HeyGenAvatarHandler, registerDefaultAvatarHandlers, ReplicateAvatar, ReplicateAvatarHandler, } from "./avatar/index.js";
|
|
111
|
+
// Video handlers (live under adapters/video; no separate video/ barrel)
|
|
112
|
+
export { KlingVideoHandler } from "./adapters/video/klingVideoHandler.js";
|
|
113
|
+
export { ReplicateVideoHandler } from "./adapters/video/replicateVideoHandler.js";
|
|
114
|
+
export { RunwayVideoHandler } from "./adapters/video/runwayVideoHandler.js";
|
|
115
|
+
export { VertexVideoHandler, isVertexVideoConfigured, } from "./adapters/video/vertexVideoHandler.js";
|
|
116
|
+
// Image generation + HITL — surfaced from their dedicated barrels
|
|
117
|
+
export { ImageGenService } from "./image-gen/ImageGenService.js";
|
|
118
|
+
export { HITLManager } from "./hitl/hitlManager.js";
|
|
84
119
|
// Provider registry (for tests, advanced consumers, and tools that need to
|
|
85
120
|
// invoke registerAllProviders() outside of constructing a NeuroLink instance)
|
|
86
121
|
export { ProviderRegistry } from "./factories/providerRegistry.js";
|
|
@@ -7,7 +7,21 @@
|
|
|
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
|
*/
|
|
12
17
|
export { MUSIC_ERROR_CODES, MusicError, MusicProcessor, } from "../utils/musicProcessor.js";
|
|
13
18
|
export { BeatovenMusic, BeatovenMusic as BeatovenMusicHandler, } from "./providers/BeatovenMusic.js";
|
|
19
|
+
export { ElevenLabsMusic, ElevenLabsMusic as ElevenLabsMusicHandler, } from "./providers/ElevenLabsMusic.js";
|
|
20
|
+
export { LyriaMusic, LyriaMusic as LyriaMusicHandler, } from "./providers/LyriaMusic.js";
|
|
21
|
+
export { ReplicateMusic, ReplicateMusic as ReplicateMusicHandler, } from "./providers/ReplicateMusic.js";
|
|
22
|
+
/**
|
|
23
|
+
* Register every shipped music handler whose backing credentials are
|
|
24
|
+
* present in the environment. Safe to call multiple times — existing
|
|
25
|
+
* registrations are preserved.
|
|
26
|
+
*/
|
|
27
|
+
export declare function registerDefaultMusicHandlers(): void;
|
package/dist/lib/music/index.js
CHANGED
|
@@ -7,8 +7,88 @@
|
|
|
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();
|
|
14
94
|
//# sourceMappingURL=index.js.map
|