@sberdevices/assistant-client
Version:
Модуль взаимодействия с виртуальным ассистентом
184 lines • 7.79 kB
TypeScript
import { ActionCommand } from '@salutejs/scenario';
import { AppInfo, AssistantAppState, AssistantSmartAppData, AssistantStartSmartSearch, VpsConfiguration, EmotionId, OriginalMessageType, SystemMessageDataType, CharacterId, AssistantBackgroundApp, AssistantCommand } from '../typings';
import { ProtocolError } from './client/protocol';
export interface AssistantSettings {
/** Отключение фичи воспроизведения голоса */
disableDubbing: boolean;
/** Отключение фичи слушания речи */
disableListening: boolean;
/** Отправка текстовых сообщений с type: application/ssml */
sendTextAsSsml: boolean;
}
export declare type AppEvent = {
type: 'run';
app: AppInfo;
} | {
type: 'close';
app: AppInfo;
} | {
type: 'command';
app: AppInfo;
command: AssistantSmartAppData | AssistantStartSmartSearch;
};
export declare type AssistantEvent = {
asr?: {
text: string;
last?: boolean;
mid?: OriginalMessageType['messageId'];
};
character?: CharacterId;
emotion?: EmotionId;
};
export declare type VpsEvent = {
type: 'ready';
} | {
type: 'error';
error: Event | undefined;
} | {
type: 'outcoming';
message: OriginalMessageType;
} | {
type: 'incoming';
systemMessage: SystemMessageDataType;
originalMessage: OriginalMessageType;
};
export declare type ActionCommandEvent = {
type: 'command';
command: ActionCommand;
};
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: OriginalMessageType['status']) => void;
error: (error: AssistantError) => void;
};
export interface CreateAssistantDevOptions {
getMeta?: () => Record<string, unknown>;
}
declare type BackgroundAppOnCommand<T> = (command: AssistantSmartAppData & {
smart_app_data: T;
}, messageId: string) => void;
export declare const createAssistant: ({ getMeta, ...configuration }: VpsConfiguration & CreateAssistantDevOptions) => {
readonly activeApp: AppInfo | null;
readonly settings: AssistantSettings;
destroy: () => void;
closeApp: () => void;
listen: ({ begin }?: {
begin?: ArrayBuffer[] | undefined;
}) => Promise<void>;
sendServerAction: (serverAction: unknown, messageName?: string, requestId?: string | undefined, actionApp?: AppInfo) => void;
sendText: (text: string, shouldSendDisableDubbing?: boolean) => 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 "command" | "error" | "status" | "assistant" | "app" | "vps" | "actionCommand">(event: K, ...args: Parameters<AssistantEvents[K]>) => void;
on: <K_1 extends "command" | "error" | "status" | "assistant" | "app" | "vps" | "actionCommand">(event: K_1, cb: AssistantEvents[K_1]) => () => void;
changeConfiguration: (obj: Pick<Partial<{
userId: string;
token: string;
userChannel: string;
messageName: string | undefined;
vpsToken: string | undefined;
version: import("../typings").VpsVersion;
}> | Partial<{
token: string;
messageName: string | undefined;
version: import("../typings").VpsVersion;
userId?: undefined;
userChannel?: undefined;
vpsToken?: undefined;
}>, "userId" | "userChannel" | "version" | "messageName" | "vpsToken">) => void;
changeSettings: (newSettings: Partial<AssistantSettings>) => void;
reconnect: () => void;
readonly protocol: {
clearQueue: () => void;
destroy: () => void;
on: <K_2 extends "incoming" | "outcoming" | "ready" | "error">(event: K_2, cb: import("./client/protocol").ProtocolEvents[K_2]) => () => void;
getMessageId: () => number;
sendCancel: (data: import("../proto").ICancel, last?: boolean, messageId?: number) => 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?: {
[k: string]: string;
} | undefined;
}, type?: string, messageId?: number) => void;
sendSystemMessage: ({ data, messageName: mesName }: {
data: Record<string, unknown>;
messageName?: string | undefined;
}, last?: boolean, messageId?: number, params?: {
meta?: {
[k: string]: string;
} | undefined;
}) => void;
sendVoice: (data: Uint8Array, last?: boolean, messageId?: number, mesName?: string | undefined, params?: {
meta?: {
[k: string]: string;
} | undefined;
}) => void;
send: (message: import("../proto").IMessage) => void;
batch: <T>(cb: (methods: import("./client/methods").BatchableMethods) => T) => T;
changeConfiguration: (obj: Pick<Partial<{
userId: string;
token: string;
userChannel: string;
messageName: string | undefined;
vpsToken: string | undefined;
version: import("../typings").VpsVersion;
}> | Partial<{
token: string;
messageName: string | undefined;
version: import("../typings").VpsVersion;
userId?: undefined;
userChannel?: undefined;
vpsToken?: undefined;
}>, "userId" | "userChannel" | "version" | "messageName" | "vpsToken">) => void;
changeDevice: (obj: Partial<import("../proto").IDevice> | undefined) => void;
changeSettings: (obj: Partial<import("../proto").ISettings>) => void;
reconnect: () => 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;
meta?: {
[k: string]: string;
} | undefined;
};
};
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;
};
};
export {};
//# sourceMappingURL=assistant.d.ts.map