@sberdevices/assistant-client
Version:
Модуль взаимодействия с виртуальным ассистентом
430 lines • 12.4 kB
TypeScript
/// <reference types="long" />
import { Action, ActionCommand, BubbleCommand, CardCommand, Suggestions, Hints, AppInfo, Character, UUID, Meta } from '@salutejs/scenario';
import { IDevice, ILegacyDevice, IMessage, ISettings, Message } from './proto';
export { Message } from './proto';
export { Suggestions, TextAction, DeepLinkAction, Action, ActionCommand, AppInfo, UUID, Bubble, Card, Meta, PermissionType, PermissionStatus, Character, CharacterId, Hints, } from '@salutejs/scenario';
export declare type ThemeColorName = 'dark' | 'light';
export declare type Theme = {
name: ThemeColorName;
};
export declare enum VpsVersion {
'1.0' = 1,
'2.0' = 2,
'3.0' = 3,
'4.0' = 4,
'5.0' = 5
}
export declare const MessageNames: {
ANSWER_TO_USER: string;
STT: string;
MUSIC_RECOGNITION: string;
DO_NOTHING: string;
};
export interface DPMessage extends IMessage {
sessionId: string;
uuid: UUID;
}
export interface AssistantAppStateBase<T> {
[key: string]: unknown;
item_selector?: {
ignored_words?: string[];
items: AssistantViewItemBase<T>[];
};
}
export declare type AssistantAppState = AssistantAppStateBase<Action>;
export interface AssistantViewItemBase<T> {
number?: number;
id?: string;
title?: string;
aliases?: string[];
server_action?: AssistantServerAction;
action?: T;
[key: string]: unknown;
}
export declare type AssistantViewItem = AssistantViewItemBase<Action>;
export interface AssistantServerActionAppInfo {
projectId: string;
applicationId?: string;
appversionId?: string;
}
export declare type AssistantServerAction = {
action_id: string;
parameters?: Record<string, unknown>;
} | {
type: string;
payload?: Record<string, unknown>;
};
export declare type AssistantCommands = ActionCommand | AssistantThemeCommand | AssistantCharacterCommand | AssistantCloseAppCommand | AssistantNavigationCommand | AssistantSmartAppCommand | AssistantVisibilityCommand | AssistantPlayerCommand | AssistantSystemCommand;
export interface SdkMeta {
mid?: string;
requestId?: string;
}
export interface AssistantThemeCommand {
type: 'theme';
theme: Theme;
sdk_meta?: SdkMeta;
}
export interface AssistantCharacterCommand {
type: 'character';
character: Character;
sdk_meta: SdkMeta;
}
export interface Insets {
left: number;
top: number;
right: number;
bottom: number;
}
export interface AssistantInsetsCommand {
type: 'insets';
insets: Insets;
sdk_meta: SdkMeta;
}
export interface AssistantCloseAppCommand {
type: 'close_app';
}
export interface AssistantNavigationCommand {
type: 'navigation';
navigation: {
command: 'UP' | 'DOWN' | 'LEFT' | 'RIGHT' | 'FORWARD';
};
sdk_meta?: SdkMeta;
}
export interface AssistantActionCommand {
type: 'action';
action: {
type: string;
[key: string]: unknown;
};
}
export interface AssistantSmartAppData {
type: 'smart_app_data';
smart_app_data: Record<string, unknown>;
sdk_meta?: SdkMeta;
}
export interface AssistantSmartAppError {
type: 'smart_app_error';
smart_app_error: {
code: number;
description: string;
};
sdk_meta?: SdkMeta;
}
export interface AssistantSmartAppCommand extends AssistantSmartAppData {
smart_app_data: {
type: string;
payload?: Record<string, unknown>;
};
sdk_meta?: SdkMeta;
}
export interface AssistantStartSmartSearch {
type: 'start_smart_search';
start_smart_search: {
query: string;
timeoutMS: string;
};
sdk_meta?: SdkMeta;
}
export interface AppContext {
app_info: AppInfo;
device_id: string;
platform: string;
sdk_version: string;
}
export interface AssistantAppContext {
type: 'app_context';
app_context: AppContext;
sdk_meta?: SdkMeta;
}
export interface AssistantPlayerCommand {
type: 'player_command';
player_command: {
[key: string]: unknown;
};
}
export interface AssistantVisibilityCommand {
type: 'visibility';
visibility: 'visible' | 'hidden';
sdk_meta?: SdkMeta;
}
export interface AssistantSystemCommand {
type: 'system';
system: {
command: string;
[key: string]: unknown;
};
}
export declare type AssistantClientCustomizedCommand<T extends AssistantSmartAppData> = AssistantAppContext | AssistantThemeCommand | AssistantCharacterCommand | AssistantNavigationCommand | AssistantVisibilityCommand | AssistantInsetsCommand | AssistantSmartAppError | T;
export declare type AssistantClientCommand = AssistantClientCustomizedCommand<AssistantSmartAppCommand>;
export interface AssistantClient {
onStart?: () => void;
onRequestState?: () => Record<string, unknown>;
onRequestRecoveryState?: () => unknown;
onData?: (command: AssistantClientCommand) => void;
}
export interface AssistantHost {
cancelTts?: (options: string) => void;
close: () => void;
ready: () => void;
sendData: (action: string, message: string | null) => void;
sendDataContainer: (container: string) => void;
sendText: (message: string) => void;
setSuggests: (suggest: string) => void;
setHints: (hints: string) => void;
}
export interface AssistantWindow {
AssistantHost: AssistantHost;
AssistantClient?: AssistantClient;
appInitialData: Array<AssistantClientCommand>;
appRecoveryState: unknown;
__dangerouslySendDataMessage?: (data: {}, name: string) => void;
__dangerouslySendVoiceMessage?: (message: string) => void;
__dangerouslyGetAssistantAppState?: () => AssistantAppState;
__dangerouslySendTextMessage?: (text: string) => void;
}
export interface AssistantBackgroundApp {
appInfo: AppInfo;
getState?: () => Promise<Record<string, unknown>>;
}
export interface Device {
platformType?: string | null;
platformVersion?: string | null;
surface?: string | null;
surfaceVersion?: string | null;
features?: string | null;
capabilities?: string | null;
deviceId?: string | null;
deviceManufacturer?: string | null;
deviceModel?: string | null;
additionalInfo?: string | null;
tenant?: string | null;
}
export interface LegacyDevice {
clientType?: string | null;
channel?: string | null;
channelVersion?: string | null;
platformName?: string | null;
platformVersion?: string | null;
sdkVersion?: string | null;
protocolVersion?: string | null;
}
export interface Settings {
dubbing?: number | null;
echo?: number | null;
ttsEngine?: string | null;
asrEngine?: string | null;
asrAutoStop?: number | null;
devMode?: number | null;
authConnector?: string | null;
surface?: string | null;
}
export declare type EventsType = {
connecting: () => void;
ready: () => void;
close: () => void;
message: (message: OriginalMessageType) => void;
systemMessage: (systemMessageData: SystemMessageDataType, originalMessage: OriginalMessageType) => void;
outcoming: (message: OriginalMessageType) => void;
connectionError: (error: Event) => void;
};
export declare type ItemType = Partial<BubbleCommand> & Partial<CardCommand> & Partial<ActionCommand> & {
command?: AssistantCommand;
};
export declare type AssistantCommand = Omit<AssistantSmartAppData, 'sdk_meta'> | Omit<AssistantStartSmartSearch, 'sdk_meta'> | Omit<AssistantSystemCommand, 'sdk_meta'> | Omit<AssistantNavigationCommand, 'sdk_meta'> | {
type: string;
[k: string]: unknown;
};
export declare type EmotionId = 'bespokoistvo' | 'idle' | 'igrivost' | 'laugh' | 'listen' | 'load' | 'neznayu' | 'ok_prinyato' | 'oups' | 'podavleniye_gneva' | 'predvkusheniye' | 'simpatiya' | 'smushchennaya_ulibka' | 'talk' | 'udovolstvie' | 'vinovatiy' | 'zadumalsa' | 'zhdu_otvet';
export declare type SystemMessageDataType = {
activate_app_info?: boolean;
app_info?: AppInfo;
auto_listening: boolean;
items?: Array<ItemType>;
suggestions?: Suggestions;
hints?: Hints;
character?: Character;
emotion?: {
emotionId: EmotionId;
};
server_action?: AssistantServerAction;
meta?: {
current_app: {
app_info: AppInfo;
state: AssistantAppState;
};
background_apps: {
app_info: AppInfo;
state: AssistantAppState;
}[];
} | Meta;
sdk_meta?: SdkMeta;
};
export interface OriginalMessageType {
messageId: number | Long;
last: number;
messageName: string;
token?: string | null;
userId?: string | null;
vpsToken?: string | null;
version?: number;
bytes?: {
data?: Uint8Array | null;
desc?: string | null;
} | null;
voice?: {
data?: Uint8Array | null;
} | null;
text?: {
data?: string | null;
type?: string | null;
} | null;
status?: {
code?: number | null;
description?: string | null;
technicalDescription?: string | null;
} | null;
initialSettings?: {
userId?: string | null;
userChannel?: string | null;
device?: Device | null;
settings?: Settings | null;
locale?: string | null;
} | null;
cancel?: {} | null;
device?: Device | null;
legacyDevice?: LegacyDevice | null;
settings?: Settings | null;
systemMessage?: {
data?: string | null;
} | null;
timestamp?: number | Long | null;
meta?: {
[k: string]: string;
} | null;
}
export interface WSCreator {
(url: string): WebSocket;
}
export interface FakeVpsParams {
createFakeWS: WSCreator;
}
export declare type VpsConfiguration = {
url: string;
userId: string;
userChannel: string;
locale?: string;
device?: IDevice;
settings: ISettings;
fakeVps?: FakeVpsParams;
legacyDevice?: ILegacyDevice;
version: VpsVersion;
messageName?: string;
vpsToken?: string;
meta?: {
[k: string]: string;
};
logger?: ClientLogger;
getToken: () => Promise<string>;
};
export interface IncomingMessage {
type: 'incoming';
text?: {
data?: string | null;
};
message?: {
data: SystemMessageDataType;
name: string;
sdk_meta?: SdkMeta;
};
}
export interface OutcomingMessage {
type: 'outcoming';
text?: {
data?: string | null;
};
message?: {
data: {
server_action?: any;
[key: string]: any;
};
name: string;
sdk_meta?: SdkMeta;
};
}
export declare type ClientLoggerInitEntryData = Omit<VpsConfiguration, 'getToken' | 'logger'> & {
token: string;
};
export declare type ClientLoggerInitEntry = {
type: 'init';
params: ClientLoggerInitEntryData;
};
export declare type ClientLoggerIncomingEntry = {
type: 'incoming';
message: Message;
};
export declare type ClientLoggerOutcomingEntry = {
type: 'outcoming';
message: Message;
};
export declare type ClientLoggerEntry = ClientLoggerInitEntry | ClientLoggerIncomingEntry | ClientLoggerOutcomingEntry;
export interface ClientLogger {
(entry: ClientLoggerEntry): void;
}
export interface AssistantRecord {
parameters?: ClientLoggerInitEntryData;
entries: Array<IncomingMessage | OutcomingMessage>;
version: string;
}
export interface RecordSaver {
save: (record: object) => void;
}
export interface AssistantSettings {
dubbing?: boolean;
echo?: number | null;
ttsEngine?: string | null;
asrEngine?: string | null;
asrAutoStop?: number | null;
devMode?: number | null;
authConnector?: string | null;
surface?: string | null;
}
export declare type AssistantPostMessage = {
type: 'sendDataContainer';
payload: string;
} | {
type: 'close';
} | {
type: 'sendData';
payload: string;
} | {
type: 'setSuggests';
payload: string;
} | {
type: 'setHints';
payload: string;
} | {
type: 'sendText';
payload: string;
} | {
type: 'ready';
} | {
type: 'onStart';
} | {
type: 'onData';
payload: AssistantClientCommand;
} | {
type: 'onRequestState';
requestId: string;
} | {
type: 'onRequestRecoveryState';
} | {
type: 'state';
payload: Record<string, unknown> | undefined;
requestId: string;
} | {
type: 'recoveryState';
payload: unknown;
} | {
type: 'onBack';
};
//# sourceMappingURL=typings.d.ts.map