UNPKG

@fishjam-cloud/js-server-sdk

Version:
180 lines (176 loc) 4.84 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/integrations/gemini.ts var gemini_exports = {}; __export(gemini_exports, { checkCredentials: () => checkCredentials, createClient: () => createClient, createClientAndValidate: () => createClientAndValidate, geminiInputAudioSettings: () => geminiInputAudioSettings, geminiOutputAudioSettings: () => geminiOutputAudioSettings, inputMimeType: () => inputMimeType }); module.exports = __toCommonJS(gemini_exports); var import_genai = require("@google/genai"); // package.json var package_default = { name: "@fishjam-cloud/js-server-sdk", version: "0.29.0", description: "Fishjam server SDK for JavaScript", homepage: "https://github.com/fishjam-cloud/js-server-sdk", author: "Fishjam Team", repository: { type: "git", url: "https://github.com/fishjam-cloud/js-server-sdk.git" }, bugs: { url: "https://github.com/fishjam-cloud/js-server-sdk/issues" }, license: "Apache-2.0", keywords: [ "webrtc", "fishjam", "server", "membrane" ], main: "./dist/index.js", types: "./dist/index.d.ts", files: [ "dist" ], exports: { ".": { types: "./dist/index.d.ts", import: "./dist/index.mjs", require: "./dist/index.js" }, "./gemini": { types: "./dist/integrations/gemini.d.ts", import: "./dist/integrations/gemini.mjs", require: "./dist/integrations/gemini.js" } }, scripts: { build: "tsup --dts-resolve", format: "prettier --write .", "format:check": "prettier --check .", typecheck: "tsc --noEmit", lint: "eslint . --fix", "lint:check": "eslint .", test: "vitest run" }, tsup: { entry: [ "src/index.ts", "src/integrations/gemini.ts", "src/proto.ts" ], noExternal: [ "fishjam-openapi", "fishjam-proto" ], minify: false, format: [ "cjs", "esm" ], outDir: "dist" }, dependencies: { uuid: "^11.1.0" }, engines: { node: ">=18" }, peerDependencies: { "@google/genai": "^1.0.0" }, peerDependenciesMeta: { "@google/genai": { optional: true } }, devDependencies: { "@fishjam-cloud/fishjam-openapi": "workspace:*", "@fishjam-cloud/fishjam-proto": "workspace:*", "@openapitools/openapi-generator-cli": "^2.18.4", "@types/node": "^22.13.16", "@types/websocket": "^1.0.10", eslint: "^9.33.0", prettier: "^3.6.2", tsup: "^8.4.0", "typed-emitter": "^2.1.0", vitest: "^3.0.0" }, "lint-staged": { "*.{js,ts,tsx,mjs,cjs}": [ "eslint --fix --config eslint.config.mjs" ] } }; // src/integrations/gemini.ts 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 import_genai.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"; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { checkCredentials, createClient, createClientAndValidate, geminiInputAudioSettings, geminiOutputAudioSettings, inputMimeType });