@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
65 lines (64 loc) • 3.12 kB
TypeScript
/**
* Native audio delivery to providers that can listen.
*
* ## The gap this closes
*
* Until this module existed, attaching an audio file produced a message
* containing only a metadata block:
*
* ## Audio File: "recording.mp3"
* Duration: 19s | Codec: MPEG 2 Layer 3 | Bitrate: 32 kbps |
* Sample Rate: 22050 Hz | Channels: 1 (Mono)
*
* No audio bytes were ever handed to the provider. Every question about what
* the recording *says* — transcribe this, who is speaking, what was agreed —
* was answered from a description of the file, and Gemini has accepted inline
* audio the whole time.
*
* The failure was invisible for an instructive reason: that metadata block
* answers precisely the questions a test is most tempted to ask. "How long is
* this audio?" and "what sample rate is it?" both succeed with no audio
* attached, so a suite built on them reports working audio support. It took an
* end-to-end test asking for a spoken word to expose it.
*
* ## Provider scope
*
* Deliberately a capability map rather than "send audio to everyone". A
* provider that cannot accept an audio part responds with an opaque HTTP 400,
* which is worse than the metadata summary it would otherwise have received —
* so an unlisted provider keeps the existing text-only behaviour and loses
* nothing.
*
* @module adapters/audioFormatSupport
*/
import type { AudioConversionResult } from "../types/index.js";
/**
* Whether `provider` can be handed raw audio bytes.
*
* `model` is optional and only consulted for the Vertex aliases, which serve
* both Gemini (native audio) and Claude (no native audio — routed to
* `@anthropic-ai/vertex-sdk`, whose message builder never reads an audio
* part). The Claude test is the one `GoogleVertexProvider` routes by
* (`isAnthropicModel` in providers/googleVertex/client.ts: case-insensitive,
* anywhere in the id). A stricter test here would call a model Gemini that
* Vertex actually sends to Claude. A caller that omits `model` on Vertex keeps
* today's behaviour. AI Studio / bare "gemini" aliases never serve Claude.
*/
export declare function supportsNativeAudio(provider: string, model?: string): boolean;
/** Whether `mimeType` must be re-encoded before a native provider will read it. */
export declare function needsAudioTranscode(mimeType: string): boolean;
/**
* Return audio bytes a native provider can read, transcoding when the source
* container is one it does not accept.
*
* Never throws for audio reasons. When conversion is impossible — no ffmpeg, an
* unreadable stream — the original bytes and MIME type come back with
* `converted: false`, and the caller falls back to the metadata summary. That
* keeps this from turning a previously-working (if limited) request into a
* failure.
*
* @param buffer - Raw audio bytes.
* @param mimeType - Detected MIME type of `buffer`.
* @param extension - Source extension, used so ffmpeg picks the right demuxer.
*/
export declare function toProviderCompatibleAudio(buffer: Buffer, mimeType: string, extension: string): Promise<AudioConversionResult>;