@fishjam-cloud/js-server-sdk
Version:
Fishjam server SDK for JavaScript
55 lines (53 loc) • 1.46 kB
JavaScript
import {
package_default
} from "../chunk-3EYSX4WM.mjs";
// src/integrations/gemini.ts
import { GoogleGenAI } from "@google/genai";
var SDK_NAME = "fishjam-js-server-sdk";
var createClient = (options) => {
const trackingHeader = { "X-Goog-Api-Client": `${SDK_NAME}/${package_default.version}` };
const finalOptions = {
...options,
httpOptions: {
...options.httpOptions,
headers: {
...options.httpOptions?.headers,
...trackingHeader
}
}
};
return new GoogleGenAI(finalOptions);
};
var checkCredentials = async (client) => {
try {
await client.models.list();
} catch (error) {
throw new Error(
"Could not verify the Gemini API key. The key may be invalid/unauthorized (check the key and that the Gemini API is enabled for its project/region), or the request to Gemini failed (e.g. network connectivity). See the cause for details.",
{ cause: error }
);
}
};
var createClientAndValidate = async (options) => {
const client = createClient(options);
await checkCredentials(client);
return client;
};
var geminiOutputAudioSettings = {
encoding: "pcm16",
channels: 1,
sampleRate: 24e3
};
var geminiInputAudioSettings = {
audioFormat: "pcm16",
audioSampleRate: 16e3
};
var inputMimeType = "audio/pcm;rate=16000";
export {
checkCredentials,
createClient,
createClientAndValidate,
geminiInputAudioSettings,
geminiOutputAudioSettings,
inputMimeType
};