@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.
- package/README.md +287 -5
- package/dist/index.js +1725 -414
- package/dist/index.umd.cjs +1851 -1
- package/dist/src/api/agents.d.ts +16 -9
- package/dist/src/api/apiClient.d.ts +10 -0
- package/dist/src/api/knowledge.d.ts +1 -1
- package/dist/src/api/streams/clipStream.d.ts +2 -0
- package/dist/src/api/streams/index.d.ts +2 -0
- package/dist/src/api/streams/talkStream.d.ts +2 -0
- package/dist/src/auth/{getAuthHeader.d.ts → get-auth-header.d.ts} +1 -0
- package/dist/src/config/consts.d.ts +2 -0
- package/dist/src/{environment.d.ts → config/environment.d.ts} +0 -1
- package/dist/src/errors/base-error.d.ts +12 -0
- package/dist/src/errors/chat/chat-creation-failed.d.ts +5 -0
- package/dist/src/errors/chat/chat-mode-downgraded.d.ts +5 -0
- package/dist/src/errors/index.d.ts +4 -0
- package/dist/src/errors/validation-error.d.ts +5 -0
- package/dist/src/errors/ws-error.d.ts +4 -0
- package/dist/src/index.d.ts +3 -2
- package/dist/src/services/agent-manager/connect-to-manager.d.ts +7 -0
- package/dist/src/{createAgentManager.d.ts → services/agent-manager/index.d.ts} +12 -4
- package/dist/src/services/analytics/mixpanel.d.ts +21 -0
- package/dist/src/services/analytics/timestamp-tracker.d.ts +5 -0
- package/dist/src/services/chat/index.d.ts +7 -0
- package/dist/src/services/chat/intial-messages.d.ts +2 -0
- package/dist/src/services/socket-manager/index.d.ts +11 -0
- package/dist/src/services/socket-manager/message-queue.d.ts +11 -0
- package/dist/src/{createStreamingManager.d.ts → services/streaming-manager/index.d.ts} +4 -3
- package/dist/src/services/streaming-manager/stats/poll.d.ts +4 -0
- package/dist/src/services/streaming-manager/stats/report.d.ts +17 -0
- package/dist/src/types/entities/agents/agent.d.ts +14 -2
- package/dist/src/types/entities/agents/chat.d.ts +12 -4
- package/dist/src/types/entities/agents/knowledge.d.ts +2 -0
- package/dist/src/types/entities/agents/llm.d.ts +20 -17
- package/dist/src/types/entities/agents/manager.d.ts +106 -23
- package/dist/src/types/entities/agents/presenter.d.ts +8 -2
- package/dist/src/types/entities/video.d.ts +1 -0
- package/dist/src/types/face-rect.d.ts +6 -0
- package/dist/src/types/index.d.ts +4 -4
- package/dist/src/types/stream/api/clip.d.ts +21 -9
- package/dist/src/types/stream/api/talk.d.ts +31 -1
- package/dist/src/types/stream/rtc.d.ts +4 -3
- package/dist/src/types/stream/stream.d.ts +70 -4
- package/dist/src/types/{StreamScript.d.ts → stream-script.d.ts} +2 -2
- package/dist/src/types/voice/stt.d.ts +4 -0
- package/dist/src/utils/agent.d.ts +4 -0
- package/dist/src/utils/analytics.d.ts +15 -0
- package/dist/src/utils/chat.d.ts +2 -0
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/retry-operation.d.ts +38 -0
- package/package.json +3 -2
- package/dist/src/api/clipStream.d.ts +0 -2
- package/dist/src/api/getClient.d.ts +0 -7
- package/dist/src/api/ratings.d.ts +0 -7
- package/dist/src/api/talkStream.d.ts +0 -2
- package/dist/src/connectToSocket.d.ts +0 -9
- package/dist/src/utils/webrtc.d.ts +0 -2
- /package/dist/src/types/{tts.d.ts → voice/tts.d.ts} +0 -0
package/dist/src/api/agents.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import { Agent, AgentPayload, Auth, Chat, ChatPayload, ChatResponse } from '../types/index';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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,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 {};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
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 '
|
|
2
|
-
import {
|
|
3
|
-
|
|
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
|
|
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,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,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 '
|
|
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('
|
|
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
|
-
|
|
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,
|
|
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
|
|
29
|
-
sessionId
|
|
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
|
|
2
|
-
export type
|
|
3
|
-
export interface
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 {
|
|
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:
|
|
32
|
-
export type ConnectionStateChangeCallback = (state:
|
|
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:
|
|
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
|
|
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
|
|
56
|
-
* @param
|
|
56
|
+
* Optional callback function that will be triggered each time new message is received
|
|
57
|
+
* @param messages - array of messages
|
|
57
58
|
*/
|
|
58
|
-
|
|
59
|
+
onNewMessage?(messages: Message[], type: 'answer' | 'partial' | 'user'): void;
|
|
59
60
|
/**
|
|
60
|
-
* Optional callback function that will be triggered
|
|
61
|
-
* @param
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
84
|
-
*
|
|
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: (
|
|
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,
|
|
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:
|
|
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 {};
|