@d-id/client-sdk 1.0.29-beta.55 → 1.1.0-beta.10

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.
Files changed (58) hide show
  1. package/README.md +287 -5
  2. package/dist/index.js +1725 -414
  3. package/dist/index.umd.cjs +1851 -1
  4. package/dist/src/api/agents.d.ts +16 -9
  5. package/dist/src/api/apiClient.d.ts +10 -0
  6. package/dist/src/api/knowledge.d.ts +1 -1
  7. package/dist/src/api/streams/clipStream.d.ts +2 -0
  8. package/dist/src/api/streams/index.d.ts +2 -0
  9. package/dist/src/api/streams/talkStream.d.ts +2 -0
  10. package/dist/src/auth/{getAuthHeader.d.ts → get-auth-header.d.ts} +1 -0
  11. package/dist/src/config/consts.d.ts +2 -0
  12. package/dist/src/{environment.d.ts → config/environment.d.ts} +0 -1
  13. package/dist/src/errors/base-error.d.ts +12 -0
  14. package/dist/src/errors/chat/chat-creation-failed.d.ts +5 -0
  15. package/dist/src/errors/chat/chat-mode-downgraded.d.ts +5 -0
  16. package/dist/src/errors/index.d.ts +4 -0
  17. package/dist/src/errors/validation-error.d.ts +5 -0
  18. package/dist/src/errors/ws-error.d.ts +4 -0
  19. package/dist/src/index.d.ts +3 -2
  20. package/dist/src/services/agent-manager/connect-to-manager.d.ts +7 -0
  21. package/dist/src/{createAgentManager.d.ts → services/agent-manager/index.d.ts} +12 -4
  22. package/dist/src/services/analytics/mixpanel.d.ts +21 -0
  23. package/dist/src/services/analytics/timestamp-tracker.d.ts +5 -0
  24. package/dist/src/services/chat/index.d.ts +7 -0
  25. package/dist/src/services/chat/intial-messages.d.ts +2 -0
  26. package/dist/src/services/socket-manager/index.d.ts +11 -0
  27. package/dist/src/services/socket-manager/message-queue.d.ts +11 -0
  28. package/dist/src/{createStreamingManager.d.ts → services/streaming-manager/index.d.ts} +4 -3
  29. package/dist/src/services/streaming-manager/stats/poll.d.ts +4 -0
  30. package/dist/src/services/streaming-manager/stats/report.d.ts +17 -0
  31. package/dist/src/types/entities/agents/agent.d.ts +14 -2
  32. package/dist/src/types/entities/agents/chat.d.ts +12 -4
  33. package/dist/src/types/entities/agents/knowledge.d.ts +2 -0
  34. package/dist/src/types/entities/agents/llm.d.ts +20 -17
  35. package/dist/src/types/entities/agents/manager.d.ts +106 -23
  36. package/dist/src/types/entities/agents/presenter.d.ts +8 -2
  37. package/dist/src/types/entities/video.d.ts +1 -0
  38. package/dist/src/types/face-rect.d.ts +6 -0
  39. package/dist/src/types/index.d.ts +4 -4
  40. package/dist/src/types/stream/api/clip.d.ts +21 -9
  41. package/dist/src/types/stream/api/talk.d.ts +31 -1
  42. package/dist/src/types/stream/rtc.d.ts +4 -3
  43. package/dist/src/types/stream/stream.d.ts +70 -4
  44. package/dist/src/types/{StreamScript.d.ts → stream-script.d.ts} +2 -2
  45. package/dist/src/types/voice/stt.d.ts +4 -0
  46. package/dist/src/utils/agent.d.ts +4 -0
  47. package/dist/src/utils/analytics.d.ts +15 -0
  48. package/dist/src/utils/chat.d.ts +2 -0
  49. package/dist/src/utils/index.d.ts +2 -0
  50. package/dist/src/utils/retry-operation.d.ts +38 -0
  51. package/package.json +3 -2
  52. package/dist/src/api/clipStream.d.ts +0 -2
  53. package/dist/src/api/getClient.d.ts +0 -7
  54. package/dist/src/api/ratings.d.ts +0 -7
  55. package/dist/src/api/talkStream.d.ts +0 -2
  56. package/dist/src/connectToSocket.d.ts +0 -9
  57. package/dist/src/utils/webrtc.d.ts +0 -2
  58. /package/dist/src/types/{tts.d.ts → voice/tts.d.ts} +0 -0
@@ -1,10 +1,17 @@
1
- import { Agent, AgentPayload, Auth, Chat, ChatPayload, ChatResponse } from '../types/index';
2
- export declare function createAgentsApi(auth: Auth, host?: string): {
3
- create(payload: AgentPayload, options?: RequestInit): Promise<Agent>;
4
- getAgents(tag?: string, options?: RequestInit): Promise<Agent[]>;
5
- getById(id: string, options?: RequestInit): Promise<Agent>;
6
- delete(id: string, options?: RequestInit): Promise<any>;
7
- update(id: string, payload: AgentPayload, options?: RequestInit): Promise<Agent>;
8
- newChat(agentId: string, options?: RequestInit): Promise<Chat>;
9
- chat(agentId: string, chatId: string, payload: ChatPayload, options?: RequestInit): Promise<ChatResponse>;
1
+ import { Agent, AgentPayload, Auth, Chat, ChatPayload, ChatResponse, RatingEntity, RatingPayload, STTTokenResponse } from '../types/index';
2
+ import { RequestOptions } from './apiClient';
3
+ export declare function createAgentsApi(auth: Auth, host?: string, onError?: (error: Error, errorData: object) => void): {
4
+ create(payload: AgentPayload, options?: RequestOptions): Promise<Agent>;
5
+ getAgents(tag?: string, options?: RequestOptions): Promise<Agent[]>;
6
+ getById(id: string, options?: RequestOptions): Promise<Agent>;
7
+ delete(id: string, options?: RequestOptions): Promise<any>;
8
+ update(id: string, payload: AgentPayload, options?: RequestOptions): Promise<Agent>;
9
+ newChat(agentId: string, payload: {
10
+ persist: boolean;
11
+ }, options?: RequestOptions): Promise<Chat>;
12
+ chat(agentId: string, chatId: string, payload: ChatPayload, options?: RequestOptions): Promise<ChatResponse>;
13
+ createRating(agentId: string, chatId: string, payload: RatingPayload, options?: RequestOptions): Promise<RatingEntity>;
14
+ updateRating(agentId: string, chatId: string, ratingId: string, payload: Partial<RatingPayload>, options?: RequestOptions): Promise<RatingEntity>;
15
+ deleteRating(agentId: string, chatId: string, ratingId: string, options?: RequestOptions): Promise<RatingEntity>;
16
+ getSTTToken(agentId: string, options?: RequestOptions): Promise<STTTokenResponse>;
10
17
  };
@@ -0,0 +1,10 @@
1
+ import { Auth } from '../types/auth';
2
+ export type RequestOptions = RequestInit & {
3
+ skipErrorHandler?: boolean;
4
+ };
5
+ export declare function createClient(auth: Auth, host?: string, onError?: (error: Error, errorData: object) => void): {
6
+ get<T = any>(url: string, options?: RequestOptions): Promise<T>;
7
+ post<T_1 = any>(url: string, body?: any, options?: RequestOptions): Promise<T_1>;
8
+ delete<T_2 = any>(url: string, body?: any, options?: RequestOptions): Promise<T_2>;
9
+ patch<T_3 = any>(url: string, body?: any, options?: RequestOptions): Promise<T_3>;
10
+ };
@@ -1,5 +1,5 @@
1
1
  import { Auth, CreateDocumentPayload, DocumentData, KnowledgeData, KnowledgePayload, QueryResult, RecordData } from '../types/index';
2
- export declare function createKnowledgeApi(auth: Auth, host?: string): {
2
+ export declare function createKnowledgeApi(auth: Auth, host?: string, onError?: (error: Error, errorData: object) => void): {
3
3
  createKnowledge(payload: KnowledgePayload, options?: RequestInit): Promise<KnowledgeData>;
4
4
  getKnowledgeBase(options?: RequestInit): Promise<KnowledgeData[]>;
5
5
  getKnowledge(knowledgeId: string, options?: RequestInit): Promise<KnowledgeData>;
@@ -0,0 +1,2 @@
1
+ import { Auth, RtcApi } from '../../types/index';
2
+ export declare function createClipApi(auth: Auth, host: string, agentId: string, onError?: (error: Error, errorData: object) => void): RtcApi;
@@ -0,0 +1,2 @@
1
+ export * from './clipStream';
2
+ export * from './talkStream';
@@ -0,0 +1,2 @@
1
+ import { Auth, RtcApi } from '../../types/index';
2
+ export declare function createTalkApi(auth: Auth, host: string, agentId: string, onError?: (error: Error, errorData: object) => void): RtcApi;
@@ -1,2 +1,3 @@
1
1
  import { Auth } from '../types/auth';
2
+ export declare function getExternalId(): string;
2
3
  export declare function getAuthHeader(auth: Auth): string;
@@ -0,0 +1,2 @@
1
+ export declare const CONNECTION_RETRY_TIMEOUT_MS: number;
2
+ export declare const PLAYGROUND_HEADER = "X-Playground-Chat";
@@ -2,5 +2,4 @@ export declare const nodeEnv: string;
2
2
  export declare const didApiUrl: string;
3
3
  export declare const didSocketApiUrl: string;
4
4
  export declare const mixpanelKey: string;
5
- export declare const clientKey: string;
6
5
  export declare const agentId: string;
@@ -0,0 +1,12 @@
1
+ interface BaseErrorParams {
2
+ kind: string;
3
+ description?: string;
4
+ error?: Error;
5
+ }
6
+ export declare class BaseError extends Error {
7
+ kind: string;
8
+ description?: string;
9
+ error?: Error;
10
+ constructor({ kind, description, error }: BaseErrorParams);
11
+ }
12
+ export {};
@@ -0,0 +1,5 @@
1
+ import { ChatMode } from '../../types';
2
+ import { BaseError } from '../base-error';
3
+ export declare class ChatCreationFailed extends BaseError {
4
+ constructor(mode: ChatMode, persistent: boolean);
5
+ }
@@ -0,0 +1,5 @@
1
+ import { ChatMode } from '../../types';
2
+ import { BaseError } from '../base-error';
3
+ export declare class ChatModeDowngraded extends BaseError {
4
+ constructor(mode: ChatMode);
5
+ }
@@ -0,0 +1,4 @@
1
+ export * from './chat/chat-creation-failed';
2
+ export * from './chat/chat-mode-downgraded';
3
+ export * from './validation-error';
4
+ export * from './ws-error';
@@ -0,0 +1,5 @@
1
+ import { BaseError } from './base-error';
2
+ export declare class ValidationError extends BaseError {
3
+ key?: string;
4
+ constructor(message: string, key?: string);
5
+ }
@@ -0,0 +1,4 @@
1
+ import { BaseError } from './base-error';
2
+ export declare class WsError extends BaseError {
3
+ constructor(message: string);
4
+ }
@@ -1,2 +1,3 @@
1
- export * from './createAgentManager';
2
- export * from './types/index';
1
+ export * from './errors';
2
+ export * from './services/agent-manager';
3
+ export * from './types';
@@ -0,0 +1,7 @@
1
+ import { StreamingManager } from '../streaming-manager';
2
+ import { Agent, AgentManagerOptions, AgentsAPI, Chat, CreateStreamOptions } from '../../types';
3
+ import { Analytics } from '../analytics/mixpanel';
4
+ export declare function initializeStreamAndChat(agent: Agent, options: AgentManagerOptions, agentsApi: AgentsAPI, analytics: Analytics, chat?: Chat): Promise<{
5
+ chat?: Chat;
6
+ streamingManager?: StreamingManager<CreateStreamOptions>;
7
+ }>;
@@ -1,6 +1,13 @@
1
- import { Agent, AgentManager, AgentManagerOptions } from './types/index';
2
- import { Auth } from '.';
3
- export declare function getAgent(agentId: string, auth: Auth, baseURL?: string): Promise<Agent>;
1
+ import { Agent, AgentManager, AgentManagerOptions, Auth, Chat, ChatMode, CreateStreamOptions, Message } from '../../types';
2
+ import { SocketManager } from '../socket-manager';
3
+ import { StreamingManager } from '../streaming-manager';
4
+ export interface AgentManagerItems {
5
+ chat?: Chat;
6
+ streamingManager?: StreamingManager<CreateStreamOptions>;
7
+ socketManager?: SocketManager;
8
+ messages: Message[];
9
+ chatMode: ChatMode;
10
+ }
4
11
  /**
5
12
  * Creates a new Agent Manager instance for interacting with an agent, chat, and related connections.
6
13
  *
@@ -13,4 +20,5 @@ export declare function getAgent(agentId: string, auth: Auth, baseURL?: string):
13
20
  * @example
14
21
  * const agentManager = await createAgentManager('id-agent123', { auth: { type: 'key', clientKey: '123', externalId: '123' } });
15
22
  */
16
- export declare function createAgentManager(agent: string | Agent, options: AgentManagerOptions): Promise<AgentManager>;
23
+ export declare function createAgentManager(agent: string, options: AgentManagerOptions): Promise<AgentManager>;
24
+ export declare function getAgent(agentId: string, auth: Auth, baseURL?: string): Promise<Agent>;
@@ -0,0 +1,21 @@
1
+ import { Agent } from '../../types';
2
+ export interface AnalyticsOptions {
3
+ token: string;
4
+ agent: Agent;
5
+ isEnabled?: boolean;
6
+ distinctId?: string;
7
+ }
8
+ export interface Analytics {
9
+ token: string;
10
+ distinct_id?: string;
11
+ isEnabled: boolean;
12
+ chatId?: string;
13
+ agentId: string;
14
+ owner_id: string;
15
+ getRandom(): string;
16
+ track(event: string, props?: Record<string, any>): Promise<any>;
17
+ linkTrack(mixpanelEvent: string, props: Record<string, any>, event: string, dependencies: string[]): any;
18
+ enrich(props: Record<string, any>): void;
19
+ additionalProperties: Record<string, any>;
20
+ }
21
+ export declare function initializeAnalytics(config: AnalyticsOptions): Analytics;
@@ -0,0 +1,5 @@
1
+ export declare const timestampTracker: {
2
+ reset: () => number;
3
+ update: () => number;
4
+ get: (delta?: boolean) => number;
5
+ };
@@ -0,0 +1,7 @@
1
+ import { Agent, AgentsAPI, Chat, ChatMode } from '../../types';
2
+ import { Analytics } from '../analytics/mixpanel';
3
+ export declare function getRequestHeaders(chatMode?: ChatMode): Record<string, Record<string, string>>;
4
+ export declare function createChat(agent: Agent, agentsApi: AgentsAPI, analytics: Analytics, chatMode?: ChatMode, persist?: boolean, chat?: Chat): Promise<{
5
+ chat: Chat | undefined;
6
+ chatMode: ChatMode | undefined;
7
+ }>;
@@ -0,0 +1,2 @@
1
+ import { Message } from '../../types';
2
+ export declare function getInitialMessages(initialMessages?: Message[]): Message[];
@@ -0,0 +1,11 @@
1
+ import { ChatProgressCallback } from '../../types';
2
+ import { Auth } from '../../types/auth';
3
+ export interface SocketManager {
4
+ socket?: WebSocket;
5
+ disconnect: () => void;
6
+ subscribeToEvents: (data: any) => void;
7
+ }
8
+ export declare function createSocketManager(auth: Auth, host: string, callbacks: {
9
+ onMessage: ChatProgressCallback;
10
+ onError?: (error: Error) => void;
11
+ }): Promise<SocketManager>;
@@ -0,0 +1,11 @@
1
+ import { Agent, AgentManagerOptions, ChatProgress, StreamEvents } from '../../types';
2
+ import { AgentManagerItems } from '../agent-manager';
3
+ import { Analytics } from '../analytics/mixpanel';
4
+ export interface ChatEventQueue {
5
+ [sequence: number]: string;
6
+ answer?: string;
7
+ }
8
+ export declare function createMessageEventQueue(analytics: Analytics, items: AgentManagerItems, options: AgentManagerOptions, agentEntity: Agent, onStreamDone: () => void): {
9
+ clearQueue: () => {};
10
+ onMessage: (event: ChatProgress | StreamEvents, data: any) => void;
11
+ };
@@ -1,10 +1,10 @@
1
- import { CreateStreamOptions, PayloadType, StreamingManagerOptions } from './types/index';
2
- export declare function createStreamingManager<T extends CreateStreamOptions>(agent: T, { debug, callbacks, auth, baseURL }: StreamingManagerOptions): Promise<{
1
+ import { CreateStreamOptions, PayloadType, StreamType, StreamingManagerOptions } from '../../types/index';
2
+ export declare function createStreamingManager<T extends CreateStreamOptions>(agentId: string, agent: T, { debug, callbacks, auth, baseURL, analytics }: StreamingManagerOptions): Promise<{
3
3
  /**
4
4
  * Method to send request to server to get clip or talk depend on you payload
5
5
  * @param payload
6
6
  */
7
- speak(payload: PayloadType<T>): Promise<import('./types/index').SendStreamPayloadResponse>;
7
+ speak(payload: PayloadType<T>): Promise<import('../../types/index').SendStreamPayloadResponse>;
8
8
  /**
9
9
  * Method to close RTC connection
10
10
  */
@@ -17,5 +17,6 @@ export declare function createStreamingManager<T extends CreateStreamOptions>(ag
17
17
  * Id of current RTC stream
18
18
  */
19
19
  streamId: string;
20
+ streamType: StreamType;
20
21
  }>;
21
22
  export type StreamingManager<T extends CreateStreamOptions> = Awaited<ReturnType<typeof createStreamingManager<T>>>;
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import { ConnectivityState, StreamingState } from '../../../types';
3
+ import { VideoRTCStatsReport } from './report';
4
+ export declare function pollStats(peerConnection: RTCPeerConnection, getIsConnected: () => boolean, onConnected: () => void, onVideoStateChange?: (state: StreamingState, statsReport?: VideoRTCStatsReport) => void, onConnectivityStateChange?: (state: ConnectivityState) => void, warmup?: boolean): NodeJS.Timeout;
@@ -0,0 +1,17 @@
1
+ import { AnalyticsRTCStatsReport, SlimRTCStatsReport } from '../../../types';
2
+ export interface VideoRTCStatsReport {
3
+ webRTCStats: {
4
+ anomalies: AnalyticsRTCStatsReport[];
5
+ aggregateReport: AnalyticsRTCStatsReport;
6
+ minRtt: number;
7
+ maxRtt: number;
8
+ avgRtt: number;
9
+ minJitterDelayInInterval: number;
10
+ maxJitterDelayInInterval: number;
11
+ avgJitterDelayInInterval: number;
12
+ };
13
+ codec: string;
14
+ resolution: string;
15
+ }
16
+ export declare function formatStats(stats: RTCStatsReport): SlimRTCStatsReport;
17
+ export declare function createVideoStatsReport(stats: SlimRTCStatsReport[], interval: number, previousStats?: SlimRTCStatsReport): VideoRTCStatsReport;
@@ -19,6 +19,14 @@ export declare enum PlanGroup {
19
19
  LAUNCH = "deid-api-launch",
20
20
  SCALE = "deid-api-scale"
21
21
  }
22
+ export declare enum AgentStatus {
23
+ Created = "created",
24
+ Started = "started",
25
+ Done = "done",
26
+ Error = "error",
27
+ Rejected = "rejected",
28
+ Ready = "ready"
29
+ }
22
30
  export interface Agent {
23
31
  id: string;
24
32
  username?: string;
@@ -36,8 +44,10 @@ export interface Agent {
36
44
  preview_name?: string;
37
45
  preview_description?: string;
38
46
  preview_thumbnail?: string;
47
+ logo?: string;
39
48
  preview_url?: string;
40
- idle_video?: string;
49
+ owner_id?: string;
50
+ status?: AgentStatus;
41
51
  }
42
52
  export type AgentPayload = Omit<Agent, 'type' | 'created_at' | 'modified_at' | 'id' | 'owner_id' | 'metadata' | 'idle_video_url'>;
43
53
  export interface AgentsAPI {
@@ -46,6 +56,8 @@ export interface AgentsAPI {
46
56
  getById(id: string, options?: RequestInit): Promise<Agent>;
47
57
  delete(id: string, options?: RequestInit): Promise<void>;
48
58
  update(id: string, payload: AgentPayload, options?: RequestInit): Promise<Agent>;
49
- newChat(agentId: string, options?: RequestInit): Promise<Chat>;
59
+ newChat(agentId: string, payload: {
60
+ persist: boolean;
61
+ }, options?: RequestInit): Promise<Chat>;
50
62
  chat(agentId: string, chatId: string, payload: ChatPayload, options?: RequestInit): Promise<ChatResponse>;
51
63
  }
@@ -15,18 +15,22 @@ export interface RatingEntity {
15
15
  score: 1 | -1;
16
16
  created_at: string;
17
17
  modified_at: string;
18
+ message_id: string;
18
19
  }
19
- export type RatingPayload = Omit<RatingEntity, 'owner_id' | 'id' | 'created_at' | 'modified_at' | 'created_by' | 'external_id'>;
20
+ export type RatingPayload = Omit<RatingEntity, 'owner_id' | 'id' | 'created_at' | 'modified_at' | 'created_by' | 'external_id' | 'agent_id' | 'chat_id'>;
20
21
  export interface Message {
22
+ id: string;
21
23
  role?: 'system' | 'assistant' | 'user' | 'function' | 'tool';
22
24
  content: string;
23
25
  created_at?: string;
24
26
  matches?: ChatResponse['matches'];
27
+ context?: string;
25
28
  }
26
29
  export interface ChatPayload {
27
30
  messages: Message[];
28
- streamId: string;
29
- sessionId: string;
31
+ streamId?: string;
32
+ sessionId?: string;
33
+ chatMode?: ChatMode;
30
34
  }
31
35
  export interface IRetrivalMetadata {
32
36
  id: string;
@@ -39,13 +43,16 @@ export interface IRetrivalMetadata {
39
43
  export declare enum ChatMode {
40
44
  Functional = "Functional",
41
45
  TextOnly = "TextOnly",
42
- Maintenance = "Maintenance"
46
+ Maintenance = "Maintenance",
47
+ Playground = "Playground",
48
+ DirectPlayback = "DirectPlayback"
43
49
  }
44
50
  export interface ChatResponse {
45
51
  result?: string;
46
52
  documentIds?: string[];
47
53
  matches?: IRetrivalMetadata[];
48
54
  chatMode?: ChatMode;
55
+ context?: string;
49
56
  }
50
57
  export interface Chat {
51
58
  id: string;
@@ -56,4 +63,5 @@ export interface Chat {
56
63
  messages: Message[];
57
64
  agent_id__created_at: string;
58
65
  agent_id__modified_at: string;
66
+ chat_mode?: ChatMode;
59
67
  }
@@ -2,9 +2,11 @@ export type KnowledgeProvider = 'pinecone' | 'redis';
2
2
  export interface KnowledgeEmbedder {
3
3
  provider: string;
4
4
  model: string;
5
+ is_limited_language?: boolean;
5
6
  }
6
7
  export interface Knowledge {
7
8
  id: string;
8
9
  provider: KnowledgeProvider;
10
+ starter_message?: string[];
9
11
  embedder?: KnowledgeEmbedder;
10
12
  }
@@ -1,19 +1,22 @@
1
- export type LLMType = 'knowledge' | 'custom';
2
- export type LLM = KnowledgeLLM | CustomLLM;
3
- export interface BaseLLM {
4
- type: LLMType;
5
- instructions?: string;
6
- }
7
- export interface KnowledgeLLM extends BaseLLM {
8
- type: 'knowledge';
9
- knowledge_id: string;
10
- store?: string;
1
+ export type LLMProvider = 'openai' | 'custom';
2
+ export type AgentTemplate = 'rag-grounded' | 'rag-ungrounded' | 'assistant';
3
+ export interface PromptCustomization {
4
+ role?: string;
5
+ personality?: string;
6
+ topics_to_avoid?: string[];
7
+ max_response_length?: number;
8
+ knowledge_source?: 'base_knowledge' | 'documents' | null;
11
9
  }
12
- export interface CustomLLM extends BaseLLM {
13
- type: 'custom';
14
- api_key?: string;
15
- model?: string;
16
- provider?: string;
17
- version?: string;
18
- config?: string;
10
+ export interface LLM {
11
+ provider: LLMProvider;
12
+ prompt_version?: 'v1' | 'v2' | null;
13
+ instructions?: string;
14
+ template?: AgentTemplate;
15
+ prompt_customization?: PromptCustomization;
16
+ temperature?: number;
17
+ custom?: {
18
+ api_key?: string;
19
+ url?: string;
20
+ streaming?: boolean;
21
+ };
19
22
  }
@@ -1,8 +1,9 @@
1
- import { SupportedStreamScipt } from '../../StreamScript';
1
+ import { STTTokenResponse } from '../..';
2
2
  import { Auth } from '../../auth';
3
- import { SendStreamPayloadResponse, StreamingState } from '../../stream';
3
+ import { AgentActivityState, CompatibilityMode, ConnectionState, ConnectivityState, SendStreamPayloadResponse, StreamEvents, StreamType, StreamingState } from '../../stream';
4
+ import { SupportedStreamScript } from '../../stream-script';
4
5
  import { Agent } from './agent';
5
- import { ChatResponse, Message, RatingEntity } from './chat';
6
+ import { ChatMode, ChatResponse, Message, RatingEntity } from './chat';
6
7
  /**
7
8
  * Types of events provided in Chat Progress Callback
8
9
  */
@@ -28,20 +29,20 @@ export declare enum ChatProgress {
28
29
  */
29
30
  Complete = "done"
30
31
  }
31
- export type ChatProgressCallback = (progress: ChatProgress, data: string) => void;
32
- export type ConnectionStateChangeCallback = (state: RTCIceConnectionState) => void;
32
+ export type ChatProgressCallback = (progress: ChatProgress | StreamEvents, data: any) => void;
33
+ export type ConnectionStateChangeCallback = (state: ConnectionState) => void;
33
34
  export type VideoStateChangeCallback = (state: StreamingState, data: any) => void;
34
35
  interface ManagerCallbacks {
35
36
  /**
36
37
  * Optional callback will be triggered each time the RTC connection changes state
37
38
  * @param state
38
39
  */
39
- onConnectionStateChange?(state: RTCIceConnectionState): void;
40
+ onConnectionStateChange?(state: ConnectionState): void;
40
41
  /**
41
42
  * Optional callback function that will be triggered each time video events happen
42
43
  * @param state
43
44
  */
44
- onVideoStateChange?(state: StreamingState, data?: any): void;
45
+ onVideoStateChange?(state: StreamingState): void;
45
46
  /**
46
47
  * Callback function that will be triggered each time the video stream starts or stops to update html element on webpage
47
48
  * Required callback for SDK
@@ -52,22 +53,86 @@ interface ManagerCallbacks {
52
53
  */
53
54
  onSrcObjectReady(srcObject: MediaStream): void;
54
55
  /**
55
- * Optional callback function that will be triggered each time any changes happen in the chat
56
- * @param progress
56
+ * Optional callback function that will be triggered each time new message is received
57
+ * @param messages - array of messages
57
58
  */
58
- onChatEvents?(progress: ChatProgress, data: any): void;
59
+ onNewMessage?(messages: Message[], type: 'answer' | 'partial' | 'user'): void;
59
60
  /**
60
- * Optional callback function that will be triggered when the agent is ready
61
- * @param agent - Agent instance you are working with
61
+ * Optional callback function that will be triggered each time new chat is created
62
+ * @param chatId - id of the new chat
62
63
  */
63
- onAgentReady?(agent: Agent): void;
64
+ onNewChat?(chatId: string): void;
65
+ /**
66
+ * Optional callback function that will be triggered each time the chat mode changes
67
+ * @param mode - ChatMode
68
+ */
69
+ onModeChange?(mode: ChatMode): void;
70
+ /**
71
+ * Optional callback function that will be triggered each time the user internet connectivity state change by realtime estimated bitrate
72
+ * @param state - ConnectivityState
73
+ */
74
+ onConnectivityStateChange?(state: ConnectivityState): void;
75
+ /**
76
+ * Optional callback function that will be triggered on fetch request errors
77
+ */
78
+ onError?: (error: Error, errorData?: object) => void;
79
+ /**
80
+ * Optional callback function that will be triggered each time the agent activity state changes
81
+ * @param state - AgentActivityState
82
+ */
83
+ onAgentActivityStateChange?(state: AgentActivityState): void;
84
+ }
85
+ interface StreamOptions {
86
+ /**
87
+ * Defines the video codec to be used in the stream.
88
+ * When set to on: VP8 will be used.
89
+ * When set to off: H264 will be used
90
+ * When set to auto the codec will be selected according to the browser.
91
+ * @default auto
92
+ */
93
+ compatibilityMode?: CompatibilityMode;
94
+ /**
95
+ * Whether to stream wamrup video on the connection.
96
+ * If set to true, will stream a warmup video when connection is established.
97
+ * At the end of the warmup video, a message containing "stream/ready" will be sent on the data channel.
98
+ * @default false
99
+ */
100
+ streamWarmup?: boolean;
101
+ /**
102
+ * Maximum duration (in seconds) between messages before session times out.
103
+ * Can only be used with proper permissions
104
+ * @maximum 300
105
+ * @example 180
106
+ */
107
+ sessionTimeout?: number;
108
+ /**
109
+ * Desired stream resolution for the session
110
+ * @minimum 150
111
+ * @maximum 1080
112
+ */
113
+ outputResolution?: number;
114
+ /**
115
+ * Whether to request fluent stream.
116
+ * @default false
117
+ */
118
+ fluent?: boolean;
64
119
  }
65
120
  export interface AgentManagerOptions {
121
+ auth: Auth;
66
122
  callbacks: ManagerCallbacks;
123
+ mode: ChatMode;
67
124
  baseURL?: string;
68
125
  wsURL?: string;
69
126
  debug?: boolean;
70
- auth: Auth;
127
+ enableAnalitics?: boolean;
128
+ mixpanelKey?: string;
129
+ /**
130
+ * Unique ID of agent user used in analytics. Pass it to override the default way to get distinctId
131
+ */
132
+ distinctId?: string;
133
+ streamOptions?: StreamOptions;
134
+ initialMessages?: Message[];
135
+ persistentChat?: boolean;
71
136
  }
72
137
  export interface AgentManager {
73
138
  /**
@@ -75,35 +140,43 @@ export interface AgentManager {
75
140
  * To know more about agents go to https://docs.d-id.com/reference/agents
76
141
  */
77
142
  agent: Agent;
143
+ /**
144
+ * Get the current stream type of the agent
145
+ */
146
+ getStreamType: () => StreamType | undefined;
78
147
  /**
79
148
  * Array of starter messages that will be sent to the agent when the chat starts
80
149
  */
81
150
  starterMessages: string[];
82
151
  /**
83
- * Method to be reconnected to chat
84
- * Since chat uses an RTC connection to communicate with the agent, it could be dropped and to continue to chat you need to reconnect
152
+ * Get a token for the Speech to Text service
153
+ * Only available after a chat has started and the agent has been connected
154
+ */
155
+ getSTTToken: () => Promise<STTTokenResponse | undefined>;
156
+ /**
157
+ * Method to connect to stream and chat
158
+ */
159
+ connect: () => Promise<void>;
160
+ /**
161
+ * Method to reconnect to stream and continue chat
85
162
  */
86
163
  reconnect: () => Promise<void>;
87
164
  /**
88
165
  * Method to close all connections with agent, stream and web socket
89
166
  */
90
167
  disconnect: () => Promise<void>;
91
- /**
92
- * ID of chat you are working on now
93
- */
94
- chatId: string;
95
168
  /**
96
169
  * Method to send a chat message to existing chat with the agent
97
170
  * @param messages
98
171
  */
99
- chat: (messages: Message[]) => Promise<ChatResponse>;
172
+ chat: (userMessage: string) => Promise<ChatResponse>;
100
173
  /**
101
174
  * Method to rate the answer in chat
102
175
  * @param score: 1 | -1 - score of the answer. 1 for positive, -1 for negative
103
176
  * @param matches - array of matches that were used to find the answer
104
177
  * @param id - id of Rating entity. Leave it empty to create a new, one or pass it to work with the existing one
105
178
  */
106
- rate: (score: 1 | -1, Message: Message, id?: string) => Promise<RatingEntity>;
179
+ rate: (messageId: string, score: 1 | -1, rateId?: string) => Promise<RatingEntity>;
107
180
  /**
108
181
  * Method to delete rating from answer in chat
109
182
  * @param id - id of Rating entity.
@@ -113,6 +186,16 @@ export interface AgentManager {
113
186
  * Method to make your agent read the text you provide or reproduce sound
114
187
  * @param payload
115
188
  */
116
- speak: (payload: SupportedStreamScipt) => Promise<SendStreamPayloadResponse>;
189
+ speak: (payload: SupportedStreamScript | string) => Promise<SendStreamPayloadResponse>;
190
+ /**
191
+ * Method to change the mode of the chat
192
+ * @param mode - ChatMode
193
+ */
194
+ changeMode(mode: ChatMode): void;
195
+ /**
196
+ * Method to enrich analytics properties
197
+ * @param properties flat json object with properties that will be added to analytics events fired from the sdk
198
+ */
199
+ enrichAnalytics: (properties: Record<string, any>) => void;
117
200
  }
118
201
  export {};