@salutejs/client
Version:
Модуль взаимодействия с виртуальным ассистентом
224 lines • 10.1 kB
TypeScript
import { ActionCommand } from '@salutejs/scenario';
import { AppInfo, AssistantAppState, AssistantSmartAppData, AssistantSmartAppError, AssistantStartSmartSearch, VpsConfiguration, EmotionId, OriginalMessageType, SystemMessageDataType, AssistantBackgroundApp, AssistantMeta, AssistantCommand, HistoryMessages, AdditionalMeta, Status, AssistantServerActionMode, CharacterId, Mid } from '../typings';
import { ProtocolError } from './client/protocol';
import { CreateTransportParams } from './client/transport';
import { TtsEvent } from './voice/voice';
import { VoiceListenerStatus } from './voice/listener/voiceListener';
import { Music2TrackProtocol } from './voice/recognizers/mtt';
import { MetaStringified } from './client/methods';
export declare type AppEvent = {
type: 'run';
app: AppInfo;
} | {
type: 'close';
app: AppInfo;
} | {
type: 'command';
app: AppInfo;
command: AssistantSmartAppData | AssistantSmartAppError | AssistantStartSmartSearch;
};
export declare type AssistantEvent = {
asr?: {
text: string;
last?: boolean;
mid?: OriginalMessageType['messageId'];
};
/**
* @deprecated Use the `on('assistant', { listener })` and `on('tts', tts)` subscriptions to receive voice events
*/
emotion?: EmotionId;
mtt?: {
response: Music2TrackProtocol.MttResponse;
mid: OriginalMessageType['messageId'];
};
listener?: {
status: VoiceListenerStatus;
};
voiceAnalyser?: {
data: Uint8Array;
};
};
export declare type VpsEvent = {
type: 'ready';
} | {
type: 'error';
error: Event | Error | undefined;
} | {
type: 'outcoming';
message: OriginalMessageType;
} | {
type: 'incoming';
systemMessage: SystemMessageDataType;
originalMessage: OriginalMessageType;
};
export declare type ActionCommandEvent = {
type: 'command';
command: ActionCommand;
appInfo: AppInfo;
};
export declare type AssistantError = ProtocolError;
export declare type AssistantEvents = {
app: (event: AppEvent) => void;
assistant: (event: AssistantEvent) => void;
vps: (event: VpsEvent) => void;
actionCommand: (event: ActionCommandEvent) => void;
command: (command: AssistantCommand) => void;
status: (status: Status, mid: Mid) => void;
error: (error: AssistantError) => void;
history: (history: HistoryMessages[]) => void;
tts: (event: TtsEvent) => void;
};
export interface CreateAssistantDevOptions {
getMeta?: () => Record<string, unknown>;
getInitialMeta?: () => Promise<Record<string, unknown>>;
/** Подставляет мету в первый чанк с голосом для управления рекогнайзером */
getVoiceMeta?: () => Record<string, unknown>;
}
declare type BackgroundAppOnCommand<T> = (command: (AssistantSmartAppData & {
smart_app_data?: T;
}) | AssistantSmartAppError | AssistantStartSmartSearch, messageId: string) => void;
export declare type AssistantSettings = {
/** Отключение фичи воспроизведения голоса */
disableDubbing: boolean;
/** Отключение фичи слушания речи */
disableListening: boolean;
/** Отправка текстовых сообщений с type: application/ssml */
sendTextAsSsml: boolean;
};
export declare type Assistant = ReturnType<typeof createAssistant>;
export declare type AssistantParams = VpsConfiguration & CreateAssistantDevOptions & Pick<CreateTransportParams, 'checkCertUrl'>;
export declare const createAssistant: ({ getMeta, getInitialMeta, getVoiceMeta, checkCertUrl, ...configuration }: AssistantParams) => {
readonly activeApp: AppInfo | null;
readonly settings: {
disableDubbing: boolean;
disableListening: boolean;
sendTextAsSsml: boolean;
};
destroy: () => void;
closeApp: (closing?: AppInfo) => void;
listen: ({ begin }?: {
begin?: Uint8Array[] | undefined;
}, isAutoListening?: boolean | undefined) => Promise<void>;
shazam: () => Promise<void>;
sendServerAction: (serverAction: unknown, messageName?: string, requestId?: string | undefined, actionApp?: AppInfo, mode?: AssistantServerActionMode | undefined) => void;
getHistoryRequest: (data?: import("../proto").IChatHistoryRequest & {
history?: import("../typings").GetHistoryRequestClient | undefined;
}) => void;
sendText: (text: string, shouldSendDisableDubbing?: boolean, additionalMeta?: AdditionalMeta | undefined) => Promise<Mid | undefined>;
sendVoice: (chunks: Uint8Array[], messageName?: "MUSIC_RECOGNITION" | undefined) => Promise<void>;
streamVoice: (chunks: Uint8Array[], last: boolean, messageName?: "MUSIC_RECOGNITION" | undefined) => Promise<void>;
start: ({ disableGreetings, initPhrase, isFirstSession, }?: {
/** Отключение приветственного сообщения при старте */
disableGreetings?: boolean | undefined;
initPhrase?: string | undefined;
isFirstSession?: boolean | undefined;
}) => Promise<SystemMessageDataType | undefined>;
stop: () => void;
stopTts: () => void;
stopVoice: () => void;
emit: <K extends keyof AssistantEvents>(event: K, ...args: Parameters<AssistantEvents[K]>) => void;
on: <K_1 extends keyof AssistantEvents>(event: K_1, cb: AssistantEvents[K_1]) => () => void;
changeConfiguration: (obj: Omit<Partial<{
userId: string;
token: string;
userChannel: string;
messageName: string | undefined;
vpsToken: string | undefined;
version: import("../typings").VpsVersion;
} | {
token: string;
messageName: string | undefined;
version: import("../typings").VpsVersion;
userId?: undefined;
userChannel?: undefined;
vpsToken?: undefined;
}>, "token">) => void;
changeSettings: (object: Partial<{
disableDubbing: boolean;
disableListening: boolean;
sendTextAsSsml: boolean;
}>) => void;
changeSdkMeta: (nextSdkMeta: Partial<AssistantMeta>) => void;
reconnect: () => void;
readonly protocol: {
clearQueue: () => void;
destroy: () => void;
on: <K_2 extends keyof import("./client/protocol").ProtocolEvents>(event: K_2, cb: import("./client/protocol").ProtocolEvents[K_2]) => () => void;
getHistoryRequest: (data?: import("../proto").IChatHistoryRequest & {
history?: import("../typings").GetHistoryRequestClient | undefined;
}) => void;
getMessageId: () => Mid;
sendCancel: (data: import("../proto").ICancel, last?: boolean, messageId?: Mid) => void;
sendMute: (data: import("../proto").IMute, last?: boolean, messageId?: Mid) => void;
sendText: (data: string, params?: {
messageId?: number | undefined;
last?: 1 | -1 | undefined;
messageName?: string | undefined;
vpsToken?: string | undefined;
userId?: string | undefined;
token?: string | undefined;
userChannel?: string | undefined;
version?: import("../typings").VpsVersion | undefined;
meta?: MetaStringified | undefined;
}, type?: string, messageId?: Mid) => void;
sendSystemMessage: ({ data, messageName: mesName }: {
data: Record<string, unknown>;
messageName?: string | undefined;
}, last?: boolean, messageId?: Mid, params?: {
meta?: MetaStringified | undefined;
}) => void;
sendVoice: (data: Uint8Array, last?: boolean, messageId?: Mid, mesName?: string | undefined, params?: {
meta?: MetaStringified | undefined;
}) => void;
send: (message: import("../proto").IMessage) => void;
batch: <T>(cb: (methods: import("./client/methods").BatchableMethods) => T) => T;
changeConfiguration: (obj: Omit<Partial<{
userId: string;
token: string;
userChannel: string;
messageName: string | undefined;
vpsToken: string | undefined;
version: import("../typings").VpsVersion;
} | {
token: string;
messageName: string | undefined;
version: import("../typings").VpsVersion;
userId?: undefined;
userChannel?: undefined;
vpsToken?: undefined;
}>, "token">) => void;
changeDevice: (obj: Partial<import("../proto").IDevice | undefined>) => void;
changeSettings: (obj: Partial<import("../proto").ISettings>) => void;
reconnect: () => void;
init: () => Promise<void>;
readonly currentMessageId: number;
readonly configuration: {
token: string;
url: string;
userId: string;
userChannel: string;
locale?: string | undefined;
device?: import("../proto").IDevice | undefined;
settings: import("../proto").ISettings;
fakeVps?: import("../typings").FakeVpsParams | undefined;
legacyDevice?: import("../proto").ILegacyDevice | undefined;
version: import("../typings").VpsVersion;
messageName?: string | undefined;
vpsToken?: string | undefined;
};
readonly status: "ready" | "connecting" | "connected" | "closed";
};
setActiveApp: (info: AppInfo, getState?: (() => Promise<AssistantAppState>) | undefined) => void;
addBackgroundApp: ({ appInfo, getState }: AssistantBackgroundApp) => {
remove: () => void;
onCommand: <T_1>(subscriber: BackgroundAppOnCommand<T_1>) => {
clearSubscribers: () => void;
};
sendServerAction: (serverAction: unknown, messageName?: string, requestId?: string | undefined) => void;
};
readonly status: "ready" | "connecting" | "connected" | "closed";
setDefaultCharacterMeta(characterId: CharacterId): void;
toggleVoiceAnalyser: (enable: boolean) => void;
};
export {};
//# sourceMappingURL=assistant.d.ts.map