@unith-ai/core-client 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +0,0 @@
1
- import { WebsocketConnectionConfig } from "../types/connection";
2
- import { OnDisconnectCallback, OnMessageCallback, Message, OnPingPongCallback, PingEventData } from "../types/event";
3
- export declare class Connection {
4
- readonly socket: WebSocket;
5
- readonly userId: string;
6
- static create(config: WebsocketConnectionConfig): Promise<Connection>;
7
- private queue;
8
- private disconnectionDetails;
9
- private onDisconnectCallback;
10
- private onMessageCallback;
11
- private onPingPongCallback;
12
- private constructor();
13
- private disconnect;
14
- close(): void;
15
- sendMessage(message: Message): void;
16
- sendPingEvent(message: PingEventData): void;
17
- onPingPong(callback: OnPingPongCallback): void;
18
- onMessage(callback: OnMessageCallback): void;
19
- onDisconnect(callback: OnDisconnectCallback): void;
20
- }
@@ -1,3 +0,0 @@
1
- import { Environment } from "../types/environment";
2
- export declare function getApiBase(environment: Environment): string;
3
- export declare function getStreamBase(environment: Environment): string;
@@ -1,2 +0,0 @@
1
- import { AnyIncomingSocketEvent } from "../types/event";
2
- export declare function isValidSocketEvent(event: any): event is AnyIncomingSocketEvent;
@@ -1,8 +0,0 @@
1
- export declare class IdleVideo {
2
- readonly idleVideoSource: string;
3
- readonly videoId: string;
4
- constructor(idleVideoSource: string, videoId: string);
5
- static getIdleVideo(apiUrl: string, orgId: string, headId: string): Promise<IdleVideo>;
6
- getAvatarSrc(apiUrl: string, orgId: string, headId: string): Promise<string>;
7
- private static getIdleVideoId;
8
- }
@@ -1,32 +0,0 @@
1
- import { Connection } from "./connection";
2
- type LatencyStatus = "good" | "moderate" | "poor";
3
- interface LatencyStats {
4
- rtt: number;
5
- average: number;
6
- status: LatencyStatus;
7
- }
8
- type OnUpdateCallback = (stats: LatencyStats) => void;
9
- export declare class LatencyMonitor {
10
- connection: Connection;
11
- private intervalId;
12
- private pingInterval;
13
- private timeout;
14
- private lastPingTimestamp;
15
- private history;
16
- private maxHistory;
17
- private onUpdate?;
18
- constructor(connection: Connection, options?: {
19
- pingInterval?: number;
20
- timeout?: number;
21
- maxHistory?: number;
22
- onUpdate?: OnUpdateCallback;
23
- });
24
- start(): void;
25
- stop(): void;
26
- destroy(): void;
27
- private sendPing;
28
- private handleMessage;
29
- private recordLatency;
30
- private classifyLatency;
31
- }
32
- export {};
@@ -1,14 +0,0 @@
1
- import { SyncConfig } from "../types/sync";
2
- export declare class SyncController {
3
- private config;
4
- private driftHistory;
5
- private correctionInProgress;
6
- private lastAudioTiming;
7
- private lastVideoTiming;
8
- constructor(config: SyncConfig);
9
- updateAudioTime(relativeTime: number): void;
10
- updateVideoTime(relativeTime: number): void;
11
- resetTiming(): void;
12
- checkSync(): Promise<void>;
13
- private recordDrift;
14
- }
@@ -1,27 +0,0 @@
1
- import { ApiAsrTokenType, HeadType, TokenResponseType } from "../types/User";
2
- export declare class User {
3
- readonly id: string;
4
- username: string;
5
- readonly password: string;
6
- readonly orgId: string;
7
- readonly headId: string;
8
- readonly apiBase: string;
9
- static loginUser(username: string, password: string, apiUrl: string, orgId: string, headId: string): Promise<User>;
10
- private EXPIRATION_OFFSET;
11
- accessToken: string;
12
- tokenType: string;
13
- sessionId: number;
14
- private constructor();
15
- getHeadDetails(apiKey: string): Promise<HeadType>;
16
- getAuthToken(username: string, password: string): Promise<TokenResponseType>;
17
- getApiAsrToken(auth_jwt: string): Promise<ApiAsrTokenType>;
18
- getAccessToken(): Promise<{
19
- access_token: string;
20
- user_id: string | null | undefined;
21
- session_id: number;
22
- }>;
23
- getAsrToken(): Promise<{
24
- token: string | null | undefined;
25
- region: string | null | undefined;
26
- }>;
27
- }
@@ -1,61 +0,0 @@
1
- import { IdleVideoConfig } from "../types/idle-video";
2
- import { VideoFormatConfig, VideoTransitionType } from "../types/vp8";
3
- export interface VideoEffectConfig {
4
- background?: BackgroundConfig;
5
- }
6
- export interface BackgroundConfig {
7
- type: "color" | "image";
8
- value: number | string;
9
- }
10
- export declare class VideoOutput {
11
- private videoOutput;
12
- private container;
13
- private idleVideo;
14
- private cachedVideo;
15
- private idleVideoConfig;
16
- private videoTransitionConfig;
17
- private readonly CROSSFADE_DURATION;
18
- private isTransitioning;
19
- private isShowingIdleVideo;
20
- private bufferCheckAnimationId;
21
- private lastBufferCheckTime;
22
- private sessionStarted;
23
- private isShowingCachedVideo;
24
- private onIdleVideoShown?;
25
- private onIdleVideoHidden?;
26
- private onSpeakingStartCallback;
27
- private onSpeakingEndCallback;
28
- static createVideoOutput(container: HTMLElement, config: VideoFormatConfig & {
29
- effects?: VideoEffectConfig;
30
- idleVideo: IdleVideoConfig;
31
- transition: VideoTransitionType;
32
- }): Promise<VideoOutput>;
33
- private constructor();
34
- private setupIdleVideo;
35
- private setupCachedVideo;
36
- onSpeakingStart(speakingStartCallback: () => void): void;
37
- onSpeakingEnd(speakingEndCallback: () => void): void;
38
- startStreaming(init?: boolean): void;
39
- stopBufferMonitoring(): void;
40
- getBufferLength(): number;
41
- startBufferMonitoring(): void;
42
- toggleCacheVideoMute(): void;
43
- playCachedVideo(cachedVideoUrl: string): Promise<void>;
44
- private crossfadeFromIdleToCached;
45
- private crossfadeFromCachedToIdle;
46
- private cleanupCachedVideo;
47
- private hideIdleVideo;
48
- private hideIdleVideoBeforeStream;
49
- setEventCallbacks(callbacks: {
50
- onIdleVideoShown?: () => void;
51
- onIdleVideoHidden?: () => void;
52
- }): void;
53
- getStreamingStatus(): boolean;
54
- showIdleVideo(): Promise<void>;
55
- showIdleVideoAfterStream(): Promise<void>;
56
- addFrame(frameData: Blob | ArrayBuffer, timeStamp: number, isKeyframe?: boolean): Promise<void>;
57
- clearFrame(): void;
58
- toggleStream(status: boolean): Promise<void>;
59
- interrupt(fadeOut?: boolean): void;
60
- destroy(): void;
61
- }
@@ -1,41 +0,0 @@
1
- import { VideoState, VideoFormatConfig } from "../types/vp8";
2
- export declare class Vp8VideoOutput {
3
- private canvas;
4
- private ctx;
5
- private container;
6
- private config;
7
- private resizeObserver;
8
- private decoder;
9
- private state;
10
- private isProcessingFrame;
11
- private isStreaming;
12
- private startTime;
13
- private frameBuffer;
14
- private currentSequenceId;
15
- private animationFrameId;
16
- private renderLoop;
17
- private fpsCounter;
18
- private handleContextLoss;
19
- private handleContextRestore;
20
- private constructor();
21
- static create(container: HTMLElement, config: VideoFormatConfig): Promise<Vp8VideoOutput>;
22
- private initializeDecoder;
23
- private setupResizeHandling;
24
- private handleResize;
25
- getBufferLength(): number;
26
- getStreamingStatus(): boolean;
27
- addFrame(frameData: Uint8Array<ArrayBuffer>, timestamp: number, isKeyframe?: boolean): Promise<void>;
28
- toggleStream(status: boolean): Promise<void>;
29
- clearFrame(): void;
30
- interrupt(fadeOut?: boolean): void;
31
- destroy(): void;
32
- getState(): VideoState;
33
- startRenderingStreamingVideo(init: boolean): void;
34
- private render;
35
- private processNextFrame;
36
- private decodeVP8Frame;
37
- private renderVideoFrame;
38
- private clearCanvas;
39
- private fadeOutCanvas;
40
- private setupContextLossHandling;
41
- }
@@ -1,63 +0,0 @@
1
- import { Environment } from "./environment";
2
- import { EventType, IncomingSocketEvent, OnDisconnectCallback } from "./event";
3
- import { HeadType } from "./User";
4
- import { VideoTransitionType } from "./vp8";
5
- export type Language = "ar-AE" | "bg-BG" | "bs-BA" | "cs-CZ" | "de-DE" | "en-US" | "es-ES" | "fr-FR" | "hu-HU" | "id-ID" | "it-IT" | "ka-GE" | "kk-KZ" | "lt-LT" | "lv-LV" | "nl-NL" | "pl-PL" | "pt-PT" | "ro-RO" | "ru-RU" | "sk-SK" | "sr-RS" | "th-TH" | "uk-UA";
6
- export type Status = "connecting" | "connected" | "disconnecting" | "disconnected";
7
- export type DigitalHumanOptions = {
8
- username: string;
9
- password: string;
10
- apiKey: string;
11
- environment: Environment;
12
- mode: ConversationMode;
13
- language?: Language;
14
- allowWakeLock?: boolean;
15
- frameRate?: number;
16
- streamType: StreamingType;
17
- quality: QualityType;
18
- crop: boolean;
19
- showIdle: boolean;
20
- fadeTransitionsType?: VideoTransitionType;
21
- };
22
- export type HeadOptions = {
23
- orgId: string;
24
- headId: string;
25
- };
26
- export type VideoHtmlElement = {
27
- element: HTMLElement;
28
- };
29
- export type ConversationOptions = DigitalHumanOptions & HeadOptions;
30
- export type ConversationEvents = {
31
- onStatusChange: (prop: {
32
- status: Status;
33
- }) => void;
34
- onConnect: (prop: {
35
- userId: string;
36
- headInfo: HeadType;
37
- microphoneAccess: boolean;
38
- }) => void;
39
- onDisconnect: OnDisconnectCallback;
40
- onText: (prop: IncomingSocketEvent<EventType.TEXT>) => void;
41
- onJoin: (prop: IncomingSocketEvent<EventType.JOIN>) => void;
42
- onResponse: (prop: IncomingSocketEvent<EventType.RESPONSE>) => void;
43
- onStreaming: (prop: IncomingSocketEvent<EventType.STREAMING>) => void;
44
- onTimeoutWarning: (prop: IncomingSocketEvent<EventType.TIMEOUT_WARNING>) => void;
45
- onTimeout: (prop?: IncomingSocketEvent<EventType.TIME_OUT>) => void;
46
- onMuteStatusChange: (prop: {
47
- isMuted: boolean;
48
- }) => void;
49
- onSpeakingStart: () => void;
50
- onSpeakingEnd: () => void;
51
- onStoppingEnd: () => void;
52
- onKeepSession: (prop: IncomingSocketEvent<EventType.KEEP_SESSION>) => void;
53
- onError: (prop: {
54
- message: string;
55
- endConversation: boolean;
56
- type: "toast" | "modal" | "silent";
57
- }) => void;
58
- };
59
- export type ConversationMode = "chat" | "audio" | "video" | "default";
60
- export type Role = "user" | "ai";
61
- export type Mode = "speaking" | "listening" | "thinking" | "stopping";
62
- export type StreamingType = "jpg" | "vp8";
63
- export type QualityType = "low" | "standard" | "high" | "premium";
@@ -1,37 +0,0 @@
1
- import { Language } from "./Conversation";
2
- export type ApiErrorType = {
3
- response?: {
4
- data?: {
5
- detail?: string;
6
- };
7
- status_code?: number;
8
- status?: number;
9
- };
10
- name?: string;
11
- };
12
- export type TokenResponseType = {
13
- access_token: string;
14
- user_id: string;
15
- token_type: string;
16
- };
17
- export type HeadType = {
18
- alias: string;
19
- icon_config: undefined;
20
- lang_speech_recognition: string;
21
- language: Language;
22
- name: string;
23
- operation_mode: "ttt" | "oc" | "doc_qa";
24
- phrases: string[];
25
- streaming_enabled: boolean;
26
- allowed_iframe_origins: string[];
27
- avatarSrc?: string;
28
- };
29
- export type AuthTokenType = {
30
- exp: number;
31
- username: string;
32
- admin: boolean;
33
- };
34
- export type ApiAsrTokenType = {
35
- token: string;
36
- region: string;
37
- };
@@ -1,16 +0,0 @@
1
- import { ConversationMode, Language, QualityType, StreamingType } from "./Conversation";
2
- import { Environment } from "./environment";
3
- export type WebsocketConnectionConfig = {
4
- environment: Environment;
5
- orgId: string;
6
- headId: string;
7
- token: string;
8
- apiKey: string;
9
- mode: ConversationMode;
10
- language: Language;
11
- streamType: StreamingType;
12
- crop: boolean;
13
- quality: QualityType;
14
- onJoin?: () => void;
15
- onError?: (error: string) => void;
16
- };
@@ -1 +0,0 @@
1
- export type Environment = "production" | "staging" | "development";
@@ -1,134 +0,0 @@
1
- export declare enum EventType {
2
- TEXT = "text",
3
- CONVERSATION_END = "conversation_end",
4
- JOIN = "join",
5
- ERROR = "error",
6
- TIME_OUT = "timeout",
7
- UNITH_NLP_EXCEPTION = "unith_nlp_exception",
8
- ANALYTICS = "analytics-userFeedback",
9
- CHOICE = "choice",
10
- TIMEOUT_WARNING = "timeout_warning",
11
- KEEP_SESSION = "keep_session",
12
- RESPONSE = "response",
13
- STREAMING = "streaming",
14
- PING = "ping",
15
- PONG = "pong",
16
- BINARY = "binary"
17
- }
18
- export declare enum StreamingEventType {
19
- VIDEO_FRAME = "video_frame",
20
- AUDIO_FRAME = "audio_frame",
21
- METADATA = "metadata",
22
- ERROR = "error",
23
- CACHE = "cache"
24
- }
25
- export interface Message {
26
- id: number;
27
- timestamp: string;
28
- speaker: string;
29
- text: string;
30
- isSent: boolean;
31
- user_id: string;
32
- username?: string;
33
- event: EventType.TEXT | EventType.KEEP_SESSION;
34
- session_id?: string;
35
- visible: boolean;
36
- }
37
- export type JoinEventData = {
38
- granted: boolean;
39
- };
40
- export type GlobalEventData = {
41
- event: EventType;
42
- user_id: string;
43
- username: string;
44
- type?: string;
45
- };
46
- export type BinaryEventData = {
47
- data: ArrayBuffer;
48
- };
49
- export type SpeakerType = "user" | "backend";
50
- export type TextEventData = {
51
- id: string;
52
- timestamp: Date;
53
- speaker: SpeakerType;
54
- text: string;
55
- isSent: boolean;
56
- session_id: string;
57
- visible: boolean;
58
- is_last?: boolean;
59
- part_order?: number;
60
- input_message_id?: string;
61
- suggestions: string[];
62
- has_error?: boolean;
63
- error_code?: number;
64
- error_message?: string;
65
- media?: string[];
66
- video?: string;
67
- stream_id?: string;
68
- };
69
- export type ConversationEndEventData = {
70
- reason: string;
71
- duration: number;
72
- };
73
- export type TimeoutEventData = {
74
- remaining_time: number;
75
- };
76
- export type AnalyticsEventData = {
77
- feedback_type: string;
78
- rating: number;
79
- comment?: string;
80
- };
81
- export type ChoiceEventData = {
82
- choices: string[];
83
- selected_choice?: string;
84
- };
85
- export type StreamingEventData = {
86
- message?: string;
87
- metadata_type?: string;
88
- session_id?: string;
89
- event_timestamp_ms: number;
90
- type: StreamingEventType;
91
- video_url?: string;
92
- text?: string;
93
- error_type?: "resource_exhausted" | "deadline_exceeded" | "inactivity_timeout";
94
- format?: "jpeg" | "wav";
95
- frame_data?: string;
96
- height?: number;
97
- width?: string;
98
- sample_rate?: string;
99
- duration_ms?: number;
100
- is_keyframe?: boolean;
101
- };
102
- export type PingEventData = {
103
- event: EventType.PING;
104
- timestamp: string;
105
- id: string;
106
- };
107
- export type PongEventData = {
108
- type: EventType.PONG;
109
- timestamp: string;
110
- id: string;
111
- };
112
- export type IncomingSocketEvent<T extends EventType = EventType> = T extends EventType.BINARY ? GlobalEventData & BinaryEventData : T extends EventType.JOIN ? GlobalEventData & JoinEventData : T extends EventType.TEXT ? GlobalEventData & TextEventData : T extends EventType.RESPONSE ? GlobalEventData & TextEventData : T extends EventType.CONVERSATION_END ? GlobalEventData & ConversationEndEventData : T extends EventType.STREAMING ? GlobalEventData & StreamingEventData : T extends EventType.TIME_OUT ? GlobalEventData & TimeoutEventData : T extends EventType.TIMEOUT_WARNING ? GlobalEventData & TimeoutEventData : T extends EventType.KEEP_SESSION ? GlobalEventData & JoinEventData : T extends EventType.ANALYTICS ? GlobalEventData & AnalyticsEventData : T extends EventType.PING ? GlobalEventData & PingEventData : T extends EventType.PONG ? GlobalEventData & PongEventData : T extends EventType.CHOICE ? GlobalEventData & ChoiceEventData : GlobalEventData;
113
- export type AnyIncomingSocketEvent = IncomingSocketEvent<EventType.JOIN> | IncomingSocketEvent<EventType.TEXT> | IncomingSocketEvent<EventType.RESPONSE> | IncomingSocketEvent<EventType.STREAMING> | IncomingSocketEvent<EventType.BINARY> | IncomingSocketEvent<EventType.CONVERSATION_END> | IncomingSocketEvent<EventType.TIME_OUT> | IncomingSocketEvent<EventType.TIMEOUT_WARNING> | IncomingSocketEvent<EventType.KEEP_SESSION> | IncomingSocketEvent<EventType.ANALYTICS> | IncomingSocketEvent<EventType.CHOICE> | IncomingSocketEvent<EventType.PING> | IncomingSocketEvent<EventType.PONG> | (GlobalEventData & {
114
- event: Exclude<EventType, EventType.JOIN | EventType.TEXT | EventType.CONVERSATION_END | EventType.TIME_OUT | EventType.TIMEOUT_WARNING | EventType.ANALYTICS | EventType.CHOICE | EventType.RESPONSE | EventType.STREAMING | EventType.PING | EventType.KEEP_SESSION | EventType.BINARY>;
115
- });
116
- export type DisconnectionDetails = {
117
- reason: "error" | "user";
118
- message?: string;
119
- context?: Event;
120
- };
121
- export type OnDisconnectCallback = (details: DisconnectionDetails) => void;
122
- export type OnMessageCallback = (event: AnyIncomingSocketEvent) => void;
123
- export type OnPingPongCallback = (event: PongEventData) => void;
124
- export declare function isJoinEvent(event: AnyIncomingSocketEvent): event is IncomingSocketEvent<EventType.JOIN>;
125
- export declare function isTextEvent(event: AnyIncomingSocketEvent): event is IncomingSocketEvent<EventType.TEXT>;
126
- export declare function isResponseEvent(event: AnyIncomingSocketEvent): event is IncomingSocketEvent<EventType.RESPONSE>;
127
- export declare function isStreamingEvent(event: AnyIncomingSocketEvent): event is IncomingSocketEvent<EventType.STREAMING>;
128
- export declare function isStreamingErrorEvent(event: AnyIncomingSocketEvent): event is IncomingSocketEvent<EventType.STREAMING>;
129
- export declare function isBinaryEvent(event: AnyIncomingSocketEvent): event is IncomingSocketEvent<EventType.BINARY>;
130
- export declare function isConversationEndEvent(event: AnyIncomingSocketEvent): event is IncomingSocketEvent<EventType.CONVERSATION_END>;
131
- export declare function isPongEvent(event: AnyIncomingSocketEvent): event is IncomingSocketEvent<EventType.PONG>;
132
- export declare function isTimeoutWarningEvent(event: AnyIncomingSocketEvent): event is IncomingSocketEvent<EventType.TIMEOUT_WARNING>;
133
- export declare function isTimeoutEvent(event: AnyIncomingSocketEvent): event is IncomingSocketEvent<EventType.TIME_OUT>;
134
- export declare function isKeepSessionEvent(event: AnyIncomingSocketEvent): event is IncomingSocketEvent<EventType.KEEP_SESSION>;
@@ -1,48 +0,0 @@
1
- export interface FrameData {
2
- data: Uint8Array<ArrayBuffer>;
3
- timestamp: number;
4
- isKeyframe: boolean;
5
- sequenceId: number;
6
- size: number;
7
- }
8
- export interface VideoMetrics {
9
- framesRendered: number;
10
- framesDropped: number;
11
- actualFps: number;
12
- bufferSize: number;
13
- lastRenderTime: number;
14
- decoderQueueSize: number;
15
- }
16
- export declare enum VideoState {
17
- INITIALIZING = "initializing",
18
- READY = "ready",
19
- PLAYING = "playing",
20
- PAUSED = "paused",
21
- INTERRUPTED = "interrupted",
22
- DESTROYED = "destroyed"
23
- }
24
- export interface VideoTransitionConfig {
25
- enabled: boolean;
26
- type: VideoTransitionType;
27
- }
28
- export declare enum VideoTransitionType {
29
- NONE = "none",
30
- CROSSFADE = "crossfade",
31
- FADEIN = "fadein",
32
- FADEOUT = "fadeout"
33
- }
34
- export interface VideoFrameType {
35
- timeStamp: number;
36
- isKeyframe?: boolean;
37
- }
38
- export interface VideoFormatConfig {
39
- width: number;
40
- height: number;
41
- frameRate: number;
42
- format: "jpeg" | "webp" | "png";
43
- backgroundColor?: string;
44
- antialias?: boolean;
45
- resolution?: number;
46
- maxBufferSize?: number;
47
- enableAdaptiveQuality?: boolean;
48
- }
@@ -1,8 +0,0 @@
1
- export declare const loadAudioConcatProcessor: (worklet: AudioWorklet) => Promise<void>;
2
- export declare function base64ToArrayBuffer(base64: string): ArrayBuffer;
3
- export declare function detectAudioFormat(base64Data: string): {
4
- hasHeader: boolean;
5
- headerSize: number;
6
- format: string;
7
- shouldSlice: boolean;
8
- };
@@ -1,4 +0,0 @@
1
- export declare const getFromStorage: (key: string, orgId: string, headId: string) => string | null | undefined;
2
- export declare const setToStorage: (key: string, val: string, orgId: string, headId: string) => void;
3
- export declare const setCookie: (key: string, val: string) => void;
4
- export declare const getCookie: (key: string) => string | null | undefined;
@@ -1,2 +0,0 @@
1
- import { SyncConfig } from "../types/sync";
2
- export declare const DEFAULT_SYNC_CONFIG: SyncConfig;
@@ -1 +0,0 @@
1
- export declare function createWorkletModuleLoader(name: string, sourceCode: string): (worklet: AudioWorklet) => Promise<void>;