import { ChatReplyParam, Star, StarBase } from '../types/common'; import { AuthRequest, AuthResponseData, GetConversationMessageParam, GetConversationMessageResult, GetStarsParam, StreamAvatarServerHelperConfig, STSResponse, STSResponseWithTranscript, STTParam } from '../types/server'; /** * The `StreamAvatarServerHelper` class provides an interface to the Stream Avatar server, * enabling you to authenticate users, retrieve available avatar/character information, * manage conversation sessions, and obtain chat responses or speech-to-text transcriptions. * * **Important**: All methods in this class should be called on the server side, since they * require an API key that should not be exposed to clients. */ export declare class StreamAvatarServerHelper { private siteURL; private apikey; /** * Creates an instance of `StreamAvatarServerHelper`. * * @param {StreamAvatarServerHelperConfig} config - The configuration object for the helper. * @param {string} [config.url] - The base URL for the Stream Avatar server API. * @param {string} config.apikey - The API key needed to authenticate requests. */ constructor(config: StreamAvatarServerHelperConfig); /** * Obtains an authentication token (and optionally a stream token) for a user. * * This is the most important method, as it provides the Bearer token required for * many further actions (such as creating conversations or getting chat replies). * * @async * @function * @param {AuthRequest} request - The request object containing user identification. * @param {string} request.remote_id - A unique identifier for the user on your system. * @param {string} [request.name] - The user's full name. * @param {string} [request.dob] - The user's date of birth in YYYY-MM-DD format. * @param {string} [request.gender] - The user's gender. * @param {string} [request.nickname] - The user's nickname. * @returns {Promise} A promise that resolves with the authentication data, * including a `token` and a `stream_token`. * @throws {Error} Throws an error if the request fails, if the response is not OK, * or if the server returns a status of 'error'. */ getToken(request: AuthRequest): Promise; /** * Retrieves a paginated list of available Stars (characters) from the server. * * This method does **not** require a Bearer token, but it still needs an API key. * The result can be displayed in a list where users can select a Star/character * for interaction. * * @async * @function * @param {GetStarsParam} param - The pagination parameters. * @param {number} [param.page=1] - The page number to fetch. * @param {number} [param.limit=10] - The number of items per page. * @returns {Promise} A promise that resolves with an array of basic Star information. * @throws {Error} Throws an error if the request fails, if the response is not OK, * or if the server returns a status of 'error'. */ getStars(param: GetStarsParam): Promise; /** * Retrieves detailed information for a specific Star (character). * * This includes the Star's configuration and related interactive character data * if available (i.e., `interactive_config`). This method is useful for getting all * properties of a Star. * * @async * @function * @param {string} uid - The unique identifier of the Star. * @returns {Promise} A promise that resolves with detailed Star information, * including interactive configuration if it exists. * @throws {Error} Throws an error if the request fails, if the response is not OK, * or if the server returns a status of 'error'. */ getStarByUID(uid: string): Promise; /** * Retrieves interactive character configuration data for a given character UID. * * This is a private helper method used internally by `getStarByUID`. It fetches * additional interactive configuration for Stars that have `interactive_character_uid`. * * @private * @async * @function * @param {string} uid - The unique identifier of the interactive character. * @returns {Promise} A promise resolving with the interactive configuration data. * @throws {Error} Throws an error if the request fails, if the response is not OK, * or if the server returns a status of 'error'. */ private getInteractiveCharacter; /** * Retrieves or creates a conversation for a given Star and returns the conversation UID. * * This is crucial for saving and tracking chat history. If no conversation exists * for the given Star, a new one is created. You need a valid Bearer token * (retrieved via `getToken`) to call this method. * * @async * @function * @param {string} starUID - The unique identifier of the Star. * @param {string} token - The Bearer token for authorization (from `getToken`). * @returns {Promise} A promise that resolves with the conversation UID. * @throws {Error} Throws an error if the request fails, if the response is not OK, * or if the server returns a status of 'error'. */ getConversationUID(starUID: string, token: string): Promise; /** * Retrieves conversation message history for a given conversation UID. * * This method is useful for displaying chat history to users * * @async * @function * @param {string} uid - The unique identifier of the Star. * @param {string} token - The Bearer token for authorization (from `getToken`). * @param {GetConversationMessageParam} param - Additional parameters for fetching messages. * @returns {Promise} A promise that resolves with the conversation UID. * @throws {Error} Throws an error if the request fails, if the response is not OK, * or if the server returns a status of 'error'. */ getMessageHistoryByConversationUID(uid: string, token: string, param?: GetConversationMessageParam): Promise; /** * Checks if a conversation already exists for a given Star. If it does, returns * the conversation object; otherwise returns null. This is used internally * by `getConversationUID`. * * @private * @async * @function * @param {string} starUID - The unique identifier of the Star. * @param {string} token - The Bearer token for authorization. * @returns {Promise} A promise that resolves * with either the conversation data or `null` if no conversation is found. * @throws {Error} Throws an error if the request fails, if the response is not OK, * or if the server returns a status of 'error'. */ private getConversationByStarUID; /** * Sends a chat message to the server and retrieves the AI-generated reply from the Star. * * You need a valid Bearer token (from `getToken`) and a valid conversation UID * (from `getConversationUID`) to call this method. * * @async * @function * @param {ChatReplyParam} param - The parameters for the chat message. * @param {string} param.conversation_uid - The conversation UID. * @param {string} param.message - The user's message to the Star. * @param {string} token - The Bearer token for authorization. * @returns {Promise} A promise that resolves with the Star's reply to the chat message. * @throws {Error} Throws an error if the request fails, if the response is not OK, * or if the server returns a status of 'error'. */ getChatReply(param: ChatReplyParam, token: string): Promise; /** * Performs Speech-To-Text (STT) on an audio file and returns the transcribed text. * * This method requires a valid Bearer token (from `getToken`) and the user's audio data. * Internally, it uploads the audio file in a multipart/form-data request to the server. * * @async * @function * @param {STTParam} param - The Speech-To-Text parameters. * @param {ArrayBuffer} param.audio_file - The raw audio data as an ArrayBuffer. * @param {string} [param.language] - The language code for transcription. * @param {string} token - The Bearer token for authorization. * @returns {Promise} A promise that resolves with the transcribed text. * @throws {Error} Throws an error if the request fails, if the response is not OK, * or if the server returns a status of 'error'. */ stt(param: STTParam, token: string): Promise; /** * Performs Speech-To-Text (STT) on an audio file using the V2 API endpoint and returns the transcribed text. * * This is an updated version of the STT endpoint with potential improvements in accuracy and performance. * Like the original STT method, it requires a valid Bearer token (from `getToken`) and the user's audio data. * Internally, it uploads the audio file in a multipart/form-data request to the server. * * @async * @function * @param {STTParam} param - The Speech-To-Text parameters. * @param {ArrayBuffer} param.audio_file - The raw audio data as an ArrayBuffer. * @param {string} [param.language] - The language code for transcription. * @param {string} token - The Bearer token for authorization. * @returns {Promise} A promise that resolves with the transcribed text. * @throws {Error} Throws an error if the request fails, if the response is not OK, * or if the server returns a status of 'error'. */ sttV2(param: STTParam, token: string): Promise; /** * Performs Speech-To-Speech (STS) on an audio file and returns the streaming audio. * * This method requires a valid Bearer token (from `getToken`) and the user's audio data. * Internally, it uploads the audio file in a multipart/form-data request to the server. * * @async * @function * @param {FormData} form - The form data containing file. * @param {string} token - The Bearer token for authorization. * @returns {Promise} A promise that resolves with the STSResponse. * @throws {Error} Throws an error if the request fails, if the response is not OK, * or if the server returns a status of 'error'. */ sts(form: FormData, token: string): Promise; /** * Performs Speech-To-Speech (STS) on an audio file and returns the streaming audio with transcript. * * This method requires a valid Bearer token (from `getToken`) and the user's audio data. * Internally, it uploads the audio file in a multipart/form-data request to the server. * * @async * @function * @param {FormData} form - The form data containing file. * @param {string} token - The Bearer token for authorization. * @returns {Promise} A promise that resolves with the STSResponseWithTranscript. * @throws {Error} Throws an error if the request fails, if the response is not OK, * or if the server returns a status of 'error'. */ stsWithTransript(form: FormData, token: string): Promise; }