@d-id/client-sdk 1.0.14 → 1.0.15
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/dist/apps/sdk/lib/api/agents.d.ts +8 -8
- package/dist/apps/sdk/lib/api/knowledge.d.ts +10 -10
- package/dist/apps/sdk/lib/createAgentManager.d.ts +9 -0
- package/dist/apps/sdk/lib/createStreamingManager.d.ts +2 -2
- package/dist/apps/sdk/lib/index.d.ts +2 -1
- package/dist/common/types/src/entities/agents/agent.d.ts +1 -0
- package/dist/common/types/src/entities/agents/chat.d.ts +18 -5
- package/dist/common/types/src/entities/agents/index.d.ts +1 -0
- package/dist/common/types/src/entities/agents/manager.d.ts +21 -0
- package/dist/common/types/src/stream/stream.d.ts +7 -7
- package/dist/index.js +173 -125
- package/dist/index.umd.cjs +1 -1
- package/package.json +11 -10
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Agent, AgentPayload, Auth, Chat, ChatPayload } from '../../../../common/types/src/index';
|
|
1
|
+
import { Agent, AgentPayload, Auth, Chat, ChatPayload, ChatResponse } from '../../../../common/types/src/index';
|
|
2
2
|
export declare function createAgentsApi(auth: Auth, host?: string): {
|
|
3
|
-
create(payload: AgentPayload): Promise<Agent>;
|
|
4
|
-
getAgents(tag?: string): Promise<Agent[]>;
|
|
5
|
-
getById(id: string): Promise<Agent>;
|
|
6
|
-
delete(id: string): Promise<any>;
|
|
7
|
-
update(id: string, payload: AgentPayload): Promise<Agent>;
|
|
8
|
-
newChat(agentId: string): Promise<Chat>;
|
|
9
|
-
chat(agentId: string, chatId: string, payload: ChatPayload): Promise<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<string | ChatResponse>;
|
|
10
10
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Auth, CreateDocumentPayload, DocumentData, KnowledgeData, KnowledgePayload, QueryResult, RecordData } from '../../../../common/types/src/index';
|
|
2
2
|
export declare function createKnowledgeApi(auth: Auth, host?: string): {
|
|
3
|
-
createKnowledge(payload: KnowledgePayload): Promise<KnowledgeData>;
|
|
4
|
-
getKnowledgeBase(): Promise<KnowledgeData[]>;
|
|
5
|
-
getKnowledge(knowledgeId: string): Promise<KnowledgeData>;
|
|
6
|
-
deleteKnowledge(knowledgeId: string): Promise<any>;
|
|
7
|
-
createDocument(knowledgeId: string, payload: CreateDocumentPayload): Promise<DocumentData>;
|
|
8
|
-
deleteDocument(knowledgeId: string, documentId: string): Promise<any>;
|
|
9
|
-
getDocuments(knowledgeId: string): Promise<DocumentData[]>;
|
|
10
|
-
getDocument(knowledgeId: string, documentId: string): Promise<DocumentData>;
|
|
11
|
-
getRecords(knowledgeId: string, documentId: string): Promise<RecordData[]>;
|
|
12
|
-
query(knowledgeId: string, query: string): Promise<QueryResult>;
|
|
3
|
+
createKnowledge(payload: KnowledgePayload, options?: RequestInit): Promise<KnowledgeData>;
|
|
4
|
+
getKnowledgeBase(options?: RequestInit): Promise<KnowledgeData[]>;
|
|
5
|
+
getKnowledge(knowledgeId: string, options?: RequestInit): Promise<KnowledgeData>;
|
|
6
|
+
deleteKnowledge(knowledgeId: string, options?: RequestInit): Promise<any>;
|
|
7
|
+
createDocument(knowledgeId: string, payload: CreateDocumentPayload, options?: RequestInit): Promise<DocumentData>;
|
|
8
|
+
deleteDocument(knowledgeId: string, documentId: string, options?: RequestInit): Promise<any>;
|
|
9
|
+
getDocuments(knowledgeId: string, options?: RequestInit): Promise<DocumentData[]>;
|
|
10
|
+
getDocument(knowledgeId: string, documentId: string, options?: RequestInit): Promise<DocumentData>;
|
|
11
|
+
getRecords(knowledgeId: string, documentId: string, options?: RequestInit): Promise<RecordData[]>;
|
|
12
|
+
query(knowledgeId: string, query: string, options?: RequestInit): Promise<QueryResult>;
|
|
13
13
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Agent, AgentManagerOptions, CreateStreamOptions, Message } from '../../../common/types/src/index';
|
|
2
|
+
export declare function getAgentStreamArgs(agent: Agent): CreateStreamOptions;
|
|
3
|
+
export declare function createAgentManager(agentId: string, { callbacks, ...options }: AgentManagerOptions): Promise<{
|
|
4
|
+
agent: Agent;
|
|
5
|
+
terminate(): Promise<void>;
|
|
6
|
+
chatId: string;
|
|
7
|
+
chat(messages: Message[]): Promise<string | import('../../../common/types/src/index').ChatResponse>;
|
|
8
|
+
}>;
|
|
9
|
+
export type AgentManager = Awaited<ReturnType<typeof createAgentManager>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CreateStreamOptions,
|
|
2
|
-
export declare function createStreamingManager<T extends CreateStreamOptions>(agent: T, { debug, callbacks, auth, baseURL }:
|
|
1
|
+
import { CreateStreamOptions, PayloadType, StreamingManagerOptions } from '../../../common/types/src/index';
|
|
2
|
+
export declare function createStreamingManager<T extends CreateStreamOptions>(agent: T, { debug, callbacks, auth, baseURL }: StreamingManagerOptions): Promise<{
|
|
3
3
|
speak(payload: PayloadType<T>): Promise<import('../../../common/types/src/index').SendStreamPayloadResponse>;
|
|
4
4
|
terminate(): Promise<void>;
|
|
5
5
|
sessionId: string;
|
|
@@ -9,13 +9,26 @@ export interface ChatPayload {
|
|
|
9
9
|
streamId: string;
|
|
10
10
|
sessionId: string;
|
|
11
11
|
}
|
|
12
|
+
export interface IRetrivalMetadata {
|
|
13
|
+
id: string;
|
|
14
|
+
data: string;
|
|
15
|
+
title: string;
|
|
16
|
+
document_id: string;
|
|
17
|
+
knowledge_id: string;
|
|
18
|
+
source_url: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ChatResponse {
|
|
21
|
+
result: string;
|
|
22
|
+
documentIds?: string[];
|
|
23
|
+
matches?: IRetrivalMetadata[];
|
|
24
|
+
}
|
|
12
25
|
export interface Chat {
|
|
26
|
+
id: string;
|
|
13
27
|
agent_id: string;
|
|
14
|
-
created:
|
|
15
|
-
messages: string;
|
|
16
|
-
agent_id__created_at: string;
|
|
17
|
-
agent_id__modified_at: string;
|
|
28
|
+
created: string;
|
|
18
29
|
modified: string;
|
|
19
30
|
owner_id: string;
|
|
20
|
-
|
|
31
|
+
messages: Message[];
|
|
32
|
+
agent_id__created_at: string;
|
|
33
|
+
agent_id__modified_at: string;
|
|
21
34
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Auth } from '../../auth';
|
|
2
|
+
import { StreamingState } from '../../stream';
|
|
3
|
+
declare enum ChatProgress {
|
|
4
|
+
Embed = 0,
|
|
5
|
+
Query = 1,
|
|
6
|
+
Answer = 2,
|
|
7
|
+
Complete = 3
|
|
8
|
+
}
|
|
9
|
+
interface ManagerCallbacks {
|
|
10
|
+
onConnectionStateChange?(state: RTCIceConnectionState): void;
|
|
11
|
+
onVideoStateChange?(state: StreamingState): void;
|
|
12
|
+
onSrcObjectReady?(srcObject: MediaStream): void;
|
|
13
|
+
onChatEvents?(progress: ChatProgress): void;
|
|
14
|
+
}
|
|
15
|
+
export interface AgentManagerOptions {
|
|
16
|
+
callbacks: ManagerCallbacks;
|
|
17
|
+
baseURL?: string;
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
auth: Auth;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Auth } from '../auth';
|
|
2
|
-
import { CreateClipStreamRequest, CreateTalkStreamRequest, SendClipStreamPayload, SendTalkStreamPayload } from './api';
|
|
3
2
|
import { VideoType } from '../entities';
|
|
3
|
+
import { CreateClipStreamRequest, CreateTalkStreamRequest, SendClipStreamPayload, SendTalkStreamPayload } from './api';
|
|
4
4
|
import { ICreateStreamRequestResponse, IceCandidate, SendStreamPayloadResponse, Status } from './rtc';
|
|
5
5
|
export type CompatibilityMode = 'on' | 'off' | 'auto';
|
|
6
6
|
export declare enum StreamingState {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
Start = "START",
|
|
8
|
+
Stop = "STOP"
|
|
9
9
|
}
|
|
10
10
|
export interface ManagerCallbacks {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
onSrcObjectReady
|
|
11
|
+
onConnectionStateChange?: (state: RTCIceConnectionState) => void;
|
|
12
|
+
onVideoStateChange?: (state: StreamingState) => void;
|
|
13
|
+
onSrcObjectReady?: (value: MediaStream) => void;
|
|
14
14
|
}
|
|
15
15
|
export interface TalkStreamOptions extends CreateTalkStreamRequest {
|
|
16
16
|
videoType: VideoType.Talk;
|
|
@@ -27,7 +27,7 @@ export interface RtcApi {
|
|
|
27
27
|
sendStreamRequest(streamId: string, sessionId: string, payload: SendClipStreamPayload | SendTalkStreamPayload): Promise<SendStreamPayloadResponse>;
|
|
28
28
|
close(streamId: string, sessionId: string): Promise<Status>;
|
|
29
29
|
}
|
|
30
|
-
export interface
|
|
30
|
+
export interface StreamingManagerOptions {
|
|
31
31
|
callbacks: ManagerCallbacks;
|
|
32
32
|
baseURL?: string;
|
|
33
33
|
debug?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
function
|
|
2
|
-
return
|
|
1
|
+
function T(o) {
|
|
2
|
+
return o.type === "bearer" ? "Bearer " + o.token : o.type === "basic" ? "Basic " + btoa(`${o.username}:${o.password}`) : "Client-Key " + o.clientKey;
|
|
3
3
|
}
|
|
4
|
-
function
|
|
4
|
+
function h(o, s = "https://api.d-id.com") {
|
|
5
5
|
const n = async (e, t) => {
|
|
6
|
-
const
|
|
6
|
+
const r = await fetch(s + (e != null && e.startsWith("/") ? e : `/${e}`), {
|
|
7
7
|
...t,
|
|
8
8
|
headers: {
|
|
9
9
|
...t == null ? void 0 : t.headers,
|
|
10
|
-
Authorization:
|
|
10
|
+
Authorization: T(o),
|
|
11
11
|
"Content-Type": "application/json"
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
-
if (!
|
|
15
|
-
let
|
|
16
|
-
throw new Error(
|
|
14
|
+
if (!r.ok) {
|
|
15
|
+
let a = await r.text().catch(() => "Failed to fetch");
|
|
16
|
+
throw new Error(a);
|
|
17
17
|
}
|
|
18
|
-
return
|
|
18
|
+
return r.json();
|
|
19
19
|
};
|
|
20
20
|
return {
|
|
21
21
|
get(e, t) {
|
|
@@ -24,94 +24,138 @@ function p(r, o = "https://api.d-id.com") {
|
|
|
24
24
|
method: "GET"
|
|
25
25
|
});
|
|
26
26
|
},
|
|
27
|
-
post(e, t,
|
|
27
|
+
post(e, t, r) {
|
|
28
28
|
return n(e, {
|
|
29
|
-
...
|
|
29
|
+
...r,
|
|
30
30
|
body: JSON.stringify(t),
|
|
31
31
|
method: "POST"
|
|
32
32
|
});
|
|
33
33
|
},
|
|
34
|
-
delete(e, t,
|
|
34
|
+
delete(e, t, r) {
|
|
35
35
|
return n(e, {
|
|
36
|
-
...
|
|
36
|
+
...r,
|
|
37
37
|
body: JSON.stringify(t),
|
|
38
38
|
method: "DELETE"
|
|
39
39
|
});
|
|
40
40
|
},
|
|
41
|
-
patch(e, t,
|
|
41
|
+
patch(e, t, r) {
|
|
42
42
|
return n(e, {
|
|
43
|
-
...
|
|
43
|
+
...r,
|
|
44
44
|
body: JSON.stringify(t),
|
|
45
45
|
method: "PATCH"
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
const n =
|
|
50
|
+
function R(o, s = "https://api.d-id.com") {
|
|
51
|
+
const n = h(o, `${s}/agents`);
|
|
52
52
|
return {
|
|
53
|
-
|
|
54
|
-
return n.post("/", e);
|
|
53
|
+
create(e, t) {
|
|
54
|
+
return n.post("/", e, t);
|
|
55
55
|
},
|
|
56
|
-
|
|
57
|
-
return n.get("
|
|
56
|
+
getAgents(e, t) {
|
|
57
|
+
return n.get(`/${e ? `?tag=${e}` : ""}`, t).then((r) => r ?? []);
|
|
58
58
|
},
|
|
59
|
-
|
|
60
|
-
return n.get(`/${e}
|
|
59
|
+
getById(e, t) {
|
|
60
|
+
return n.get(`/${e}`, t);
|
|
61
61
|
},
|
|
62
|
-
|
|
63
|
-
return n.delete(`/${e}
|
|
62
|
+
delete(e, t) {
|
|
63
|
+
return n.delete(`/${e}`, void 0, t);
|
|
64
64
|
},
|
|
65
|
-
|
|
66
|
-
return n.
|
|
65
|
+
update(e, t, r) {
|
|
66
|
+
return n.patch(`/${e}`, t, r);
|
|
67
67
|
},
|
|
68
|
-
|
|
69
|
-
return n.
|
|
68
|
+
newChat(e, t) {
|
|
69
|
+
return n.post(`/${e}/chat`, void 0, t);
|
|
70
70
|
},
|
|
71
|
-
|
|
72
|
-
return n.
|
|
73
|
-
},
|
|
74
|
-
getDocument(e, t) {
|
|
75
|
-
return n.get(`/${e}/documents/${t}`);
|
|
76
|
-
},
|
|
77
|
-
getRecords(e, t) {
|
|
78
|
-
return n.get(`/${e}/documents/${t}/records`);
|
|
79
|
-
},
|
|
80
|
-
query(e, t) {
|
|
81
|
-
return n.post(`/${e}/query`, {
|
|
82
|
-
query: t
|
|
83
|
-
});
|
|
71
|
+
chat(e, t, r, a) {
|
|
72
|
+
return n.post(`/${e}/chat/${t}`, r, a);
|
|
84
73
|
}
|
|
85
74
|
};
|
|
86
75
|
}
|
|
87
|
-
function
|
|
88
|
-
const n =
|
|
76
|
+
function M(o, s = "https://api.d-id.com") {
|
|
77
|
+
const n = h(o, `${s}/knowledge`);
|
|
89
78
|
return {
|
|
90
|
-
|
|
91
|
-
return n.post("/", e);
|
|
79
|
+
createKnowledge(e, t) {
|
|
80
|
+
return n.post("/", e, t);
|
|
81
|
+
},
|
|
82
|
+
getKnowledgeBase(e) {
|
|
83
|
+
return n.get("/", e);
|
|
92
84
|
},
|
|
93
|
-
|
|
94
|
-
return n.get(`/${e
|
|
85
|
+
getKnowledge(e, t) {
|
|
86
|
+
return n.get(`/${e}`, t);
|
|
95
87
|
},
|
|
96
|
-
|
|
97
|
-
return n.
|
|
88
|
+
deleteKnowledge(e, t) {
|
|
89
|
+
return n.delete(`/${e}`, void 0, t);
|
|
98
90
|
},
|
|
99
|
-
|
|
100
|
-
return n.
|
|
91
|
+
createDocument(e, t, r) {
|
|
92
|
+
return n.post(`/${e}/documents`, t, r);
|
|
101
93
|
},
|
|
102
|
-
|
|
103
|
-
return n.
|
|
94
|
+
deleteDocument(e, t, r) {
|
|
95
|
+
return n.delete(`/${e}/documents/${t}`, void 0, r);
|
|
104
96
|
},
|
|
105
|
-
|
|
106
|
-
return n.
|
|
97
|
+
getDocuments(e, t) {
|
|
98
|
+
return n.get(`/${e}/documents`, t);
|
|
99
|
+
},
|
|
100
|
+
getDocument(e, t, r) {
|
|
101
|
+
return n.get(`/${e}/documents/${t}`, r);
|
|
102
|
+
},
|
|
103
|
+
getRecords(e, t, r) {
|
|
104
|
+
return n.get(`/${e}/documents/${t}/records`, r);
|
|
105
|
+
},
|
|
106
|
+
query(e, t, r) {
|
|
107
|
+
return n.post(`/${e}/query`, {
|
|
108
|
+
query: t
|
|
109
|
+
}, r);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
var C = /* @__PURE__ */ ((o) => (o.Start = "START", o.Stop = "STOP", o))(C || {}), m = /* @__PURE__ */ ((o) => (o.Clip = "clip", o.Talk = "talk", o))(m || {});
|
|
114
|
+
function I(o) {
|
|
115
|
+
return o.presenter.type === m.Clip ? {
|
|
116
|
+
videoType: m.Clip,
|
|
117
|
+
driver_id: o.presenter.driver_id,
|
|
118
|
+
presenter_id: o.presenter.presenter_id
|
|
119
|
+
} : {
|
|
120
|
+
videoType: m.Talk,
|
|
121
|
+
source_url: o.presenter.source_url
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
async function P(o, {
|
|
125
|
+
callbacks: s,
|
|
126
|
+
...n
|
|
127
|
+
}) {
|
|
128
|
+
const e = new AbortController(), t = R(n.auth, n.baseURL), r = await t.getById(o), a = await t.newChat(o), {
|
|
129
|
+
terminate: w,
|
|
130
|
+
sessionId: S,
|
|
131
|
+
streamId: $
|
|
132
|
+
} = await O(I(r), {
|
|
133
|
+
...n,
|
|
134
|
+
callbacks: {
|
|
135
|
+
onSrcObjectReady: s.onSrcObjectReady,
|
|
136
|
+
onVideoStateChange: s == null ? void 0 : s.onVideoStateChange,
|
|
137
|
+
onConnectionStateChange: s.onConnectionStateChange
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
agent: r,
|
|
142
|
+
terminate() {
|
|
143
|
+
return e.abort(), w();
|
|
107
144
|
},
|
|
108
|
-
|
|
109
|
-
|
|
145
|
+
chatId: a.id,
|
|
146
|
+
chat(c) {
|
|
147
|
+
return t.chat(o, a.id, {
|
|
148
|
+
sessionId: S,
|
|
149
|
+
streamId: $,
|
|
150
|
+
messages: c
|
|
151
|
+
}, {
|
|
152
|
+
signal: e.signal
|
|
153
|
+
});
|
|
110
154
|
}
|
|
111
155
|
};
|
|
112
156
|
}
|
|
113
|
-
function
|
|
114
|
-
const n =
|
|
157
|
+
function v(o, s) {
|
|
158
|
+
const n = h(o, s);
|
|
115
159
|
return {
|
|
116
160
|
createStream(e) {
|
|
117
161
|
return n.post("/clips/streams", {
|
|
@@ -120,22 +164,22 @@ function A(r, o) {
|
|
|
120
164
|
compatibility_mode: e.compatibility_mode
|
|
121
165
|
});
|
|
122
166
|
},
|
|
123
|
-
startConnection(e, t,
|
|
167
|
+
startConnection(e, t, r) {
|
|
124
168
|
return n.post(`/clips/streams/${e}/sdp`, {
|
|
125
|
-
session_id:
|
|
169
|
+
session_id: r,
|
|
126
170
|
answer: t
|
|
127
171
|
});
|
|
128
172
|
},
|
|
129
|
-
addIceCandidate(e, t,
|
|
173
|
+
addIceCandidate(e, t, r) {
|
|
130
174
|
return n.post(`/clips/streams/${e}/ice`, {
|
|
131
|
-
session_id:
|
|
175
|
+
session_id: r,
|
|
132
176
|
...t
|
|
133
177
|
});
|
|
134
178
|
},
|
|
135
|
-
sendStreamRequest(e, t,
|
|
179
|
+
sendStreamRequest(e, t, r) {
|
|
136
180
|
return n.post(`/clips/streams/${e}`, {
|
|
137
181
|
session_id: t,
|
|
138
|
-
...
|
|
182
|
+
...r
|
|
139
183
|
});
|
|
140
184
|
},
|
|
141
185
|
close(e, t) {
|
|
@@ -145,97 +189,101 @@ function A(r, o) {
|
|
|
145
189
|
}
|
|
146
190
|
};
|
|
147
191
|
}
|
|
148
|
-
function
|
|
149
|
-
const n =
|
|
192
|
+
function K(o, s) {
|
|
193
|
+
const n = h(o, s);
|
|
150
194
|
return {
|
|
151
|
-
createStream(e) {
|
|
195
|
+
createStream(e, t) {
|
|
152
196
|
return n.post("/talks/streams", {
|
|
153
197
|
source_url: e.source_url,
|
|
154
198
|
driver_url: e.driver_url,
|
|
155
199
|
face: e.face,
|
|
156
200
|
config: e.config
|
|
157
|
-
});
|
|
201
|
+
}, t);
|
|
158
202
|
},
|
|
159
|
-
startConnection(e, t,
|
|
203
|
+
startConnection(e, t, r, a) {
|
|
160
204
|
return n.post(`/talks/streams/${e}/sdp`, {
|
|
161
|
-
session_id:
|
|
205
|
+
session_id: r,
|
|
162
206
|
answer: t
|
|
163
|
-
});
|
|
207
|
+
}, a);
|
|
164
208
|
},
|
|
165
|
-
addIceCandidate(e, t,
|
|
209
|
+
addIceCandidate(e, t, r, a) {
|
|
166
210
|
return n.post(`/talks/streams/${e}/ice`, {
|
|
167
|
-
session_id:
|
|
211
|
+
session_id: r,
|
|
168
212
|
...t
|
|
169
|
-
});
|
|
213
|
+
}, a);
|
|
170
214
|
},
|
|
171
|
-
sendStreamRequest(e, t,
|
|
215
|
+
sendStreamRequest(e, t, r, a) {
|
|
172
216
|
return n.post(`/talks/streams/${e}`, {
|
|
173
217
|
session_id: t,
|
|
174
|
-
...
|
|
175
|
-
});
|
|
218
|
+
...r
|
|
219
|
+
}, a);
|
|
176
220
|
},
|
|
177
|
-
close(e, t) {
|
|
221
|
+
close(e, t, r) {
|
|
178
222
|
return n.delete(`/talks/streams/${e}`, {
|
|
179
223
|
session_id: t
|
|
180
|
-
});
|
|
224
|
+
}, r);
|
|
181
225
|
}
|
|
182
226
|
};
|
|
183
227
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
debug: o = !1,
|
|
228
|
+
let _ = !1;
|
|
229
|
+
const p = (o, s) => _ && console.log(o, s), D = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
|
|
230
|
+
async function O(o, {
|
|
231
|
+
debug: s = !1,
|
|
189
232
|
callbacks: n,
|
|
190
233
|
auth: e,
|
|
191
234
|
baseURL: t = "https://api.d-id.com"
|
|
192
235
|
}) {
|
|
193
|
-
|
|
194
|
-
let s = null;
|
|
236
|
+
_ = s;
|
|
195
237
|
const {
|
|
196
|
-
startConnection:
|
|
197
|
-
sendStreamRequest:
|
|
198
|
-
close:
|
|
238
|
+
startConnection: r,
|
|
239
|
+
sendStreamRequest: a,
|
|
240
|
+
close: w,
|
|
199
241
|
createStream: S,
|
|
200
|
-
addIceCandidate:
|
|
201
|
-
} =
|
|
202
|
-
id:
|
|
203
|
-
offer:
|
|
204
|
-
ice_servers:
|
|
205
|
-
session_id:
|
|
206
|
-
} = await S(
|
|
207
|
-
iceServers:
|
|
208
|
-
}),
|
|
209
|
-
if (!
|
|
242
|
+
addIceCandidate: $
|
|
243
|
+
} = o.videoType === m.Clip ? v(e, t) : K(e, t), {
|
|
244
|
+
id: c,
|
|
245
|
+
offer: l,
|
|
246
|
+
ice_servers: A,
|
|
247
|
+
session_id: g
|
|
248
|
+
} = await S(o), d = new D({
|
|
249
|
+
iceServers: A
|
|
250
|
+
}), f = d.createDataChannel("JanusDataChannel");
|
|
251
|
+
if (!g)
|
|
210
252
|
throw new Error("Could not create session_id");
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
candidate:
|
|
214
|
-
sdpMid:
|
|
215
|
-
sdpMLineIndex:
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
},
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
253
|
+
d.onicecandidate = (i) => {
|
|
254
|
+
p("peerConnection.onicecandidate", i), i.candidate && i.candidate.sdpMid && i.candidate.sdpMLineIndex !== null && $(c, {
|
|
255
|
+
candidate: i.candidate.candidate,
|
|
256
|
+
sdpMid: i.candidate.sdpMid,
|
|
257
|
+
sdpMLineIndex: i.candidate.sdpMLineIndex
|
|
258
|
+
}, g);
|
|
259
|
+
}, d.oniceconnectionstatechange = () => {
|
|
260
|
+
var i;
|
|
261
|
+
p("peerConnection.oniceconnectionstatechange => " + d.iceConnectionState), (i = n.onConnectionStateChange) == null || i.call(n, d.iceConnectionState);
|
|
262
|
+
}, d.ontrack = (i) => {
|
|
263
|
+
var u;
|
|
264
|
+
p("peerConnection.ontrack", i), (u = n.onSrcObjectReady) == null || u.call(n, i.streams[0]);
|
|
265
|
+
}, f.onmessage = (i) => {
|
|
266
|
+
var u;
|
|
267
|
+
f.readyState === "open" && ((u = n.onVideoStateChange) == null || u.call(n, i.data === "stream/done" ? C.Stop : C.Start));
|
|
268
|
+
}, await d.setRemoteDescription(l), p("set remote description OK");
|
|
269
|
+
const y = await d.createAnswer();
|
|
270
|
+
return p("create answer OK"), await d.setLocalDescription(y), p("set local description OK"), await r(c, y, g), p("start connection OK"), {
|
|
271
|
+
speak(i) {
|
|
272
|
+
return a(c, g, i);
|
|
228
273
|
},
|
|
229
274
|
async terminate() {
|
|
230
|
-
|
|
275
|
+
var i, u;
|
|
276
|
+
c && (d && (d.close(), d.oniceconnectionstatechange = null, d.onnegotiationneeded = null, d.onicecandidate = null, d.ontrack = null), await w(c, g), (i = n.onConnectionStateChange) == null || i.call(n, "closed"), (u = n.onVideoStateChange) == null || u.call(n, C.Stop));
|
|
231
277
|
},
|
|
232
|
-
sessionId:
|
|
233
|
-
streamId:
|
|
278
|
+
sessionId: g,
|
|
279
|
+
streamId: c
|
|
234
280
|
};
|
|
235
281
|
}
|
|
236
282
|
export {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
283
|
+
P as createAgentManager,
|
|
284
|
+
R as createAgentsApi,
|
|
285
|
+
h as createClient,
|
|
286
|
+
M as createKnowledgeApi,
|
|
287
|
+
O as createStreamingManager,
|
|
288
|
+
I as getAgentStreamArgs
|
|
241
289
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,
|
|
1
|
+
(function(c,C){typeof exports=="object"&&typeof module<"u"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(c=typeof globalThis<"u"?globalThis:c||self,C(c.index={}))})(this,function(c){"use strict";function C(i){return i.type==="bearer"?"Bearer "+i.token:i.type==="basic"?"Basic "+btoa(`${i.username}:${i.password}`):"Client-Key "+i.clientKey}function f(i,d="https://api.d-id.com"){const n=async(e,t)=>{const r=await fetch(d+(e!=null&&e.startsWith("/")?e:`/${e}`),{...t,headers:{...t==null?void 0:t.headers,Authorization:C(i),"Content-Type":"application/json"}});if(!r.ok){let a=await r.text().catch(()=>"Failed to fetch");throw new Error(a)}return r.json()};return{get(e,t){return n(e,{...t,method:"GET"})},post(e,t,r){return n(e,{...r,body:JSON.stringify(t),method:"POST"})},delete(e,t,r){return n(e,{...r,body:JSON.stringify(t),method:"DELETE"})},patch(e,t,r){return n(e,{...r,body:JSON.stringify(t),method:"PATCH"})}}}function y(i,d="https://api.d-id.com"){const n=f(i,`${d}/agents`);return{create(e,t){return n.post("/",e,t)},getAgents(e,t){return n.get(`/${e?`?tag=${e}`:""}`,t).then(r=>r??[])},getById(e,t){return n.get(`/${e}`,t)},delete(e,t){return n.delete(`/${e}`,void 0,t)},update(e,t,r){return n.patch(`/${e}`,t,r)},newChat(e,t){return n.post(`/${e}/chat`,void 0,t)},chat(e,t,r,a){return n.post(`/${e}/chat/${t}`,r,a)}}}function I(i,d="https://api.d-id.com"){const n=f(i,`${d}/knowledge`);return{createKnowledge(e,t){return n.post("/",e,t)},getKnowledgeBase(e){return n.get("/",e)},getKnowledge(e,t){return n.get(`/${e}`,t)},deleteKnowledge(e,t){return n.delete(`/${e}`,void 0,t)},createDocument(e,t,r){return n.post(`/${e}/documents`,t,r)},deleteDocument(e,t,r){return n.delete(`/${e}/documents/${t}`,void 0,r)},getDocuments(e,t){return n.get(`/${e}/documents`,t)},getDocument(e,t,r){return n.get(`/${e}/documents/${t}`,r)},getRecords(e,t,r){return n.get(`/${e}/documents/${t}/records`,r)},query(e,t,r){return n.post(`/${e}/query`,{query:t},r)}}}var w=(i=>(i.Start="START",i.Stop="STOP",i))(w||{}),h=(i=>(i.Clip="clip",i.Talk="talk",i))(h||{});function _(i){return i.presenter.type===h.Clip?{videoType:h.Clip,driver_id:i.presenter.driver_id,presenter_id:i.presenter.presenter_id}:{videoType:h.Talk,source_url:i.presenter.source_url}}async function K(i,{callbacks:d,...n}){const e=new AbortController,t=y(n.auth,n.baseURL),r=await t.getById(i),a=await t.newChat(i),{terminate:S,sessionId:$,streamId:l}=await T(_(r),{...n,callbacks:{onSrcObjectReady:d.onSrcObjectReady,onVideoStateChange:d==null?void 0:d.onVideoStateChange,onConnectionStateChange:d.onConnectionStateChange}});return{agent:r,terminate(){return e.abort(),S()},chatId:a.id,chat(u){return t.chat(i,a.id,{sessionId:$,streamId:l,messages:u},{signal:e.signal})}}}function M(i,d){const n=f(i,d);return{createStream(e){return n.post("/clips/streams",{driver_id:e.driver_id,presenter_id:e.presenter_id,compatibility_mode:e.compatibility_mode})},startConnection(e,t,r){return n.post(`/clips/streams/${e}/sdp`,{session_id:r,answer:t})},addIceCandidate(e,t,r){return n.post(`/clips/streams/${e}/ice`,{session_id:r,...t})},sendStreamRequest(e,t,r){return n.post(`/clips/streams/${e}`,{session_id:t,...r})},close(e,t){return n.delete(`/clips/streams/${e}`,{session_id:t})}}}function D(i,d){const n=f(i,d);return{createStream(e,t){return n.post("/talks/streams",{source_url:e.source_url,driver_url:e.driver_url,face:e.face,config:e.config},t)},startConnection(e,t,r,a){return n.post(`/talks/streams/${e}/sdp`,{session_id:r,answer:t},a)},addIceCandidate(e,t,r,a){return n.post(`/talks/streams/${e}/ice`,{session_id:r,...t},a)},sendStreamRequest(e,t,r,a){return n.post(`/talks/streams/${e}`,{session_id:t,...r},a)},close(e,t,r){return n.delete(`/talks/streams/${e}`,{session_id:t},r)}}}let A=!1;const g=(i,d)=>A&&console.log(i,d),O=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function T(i,{debug:d=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){A=d;const{startConnection:r,sendStreamRequest:a,close:S,createStream:$,addIceCandidate:l}=i.videoType===h.Clip?M(e,t):D(e,t),{id:u,offer:P,ice_servers:j,session_id:m}=await $(i),s=new O({iceServers:j}),R=s.createDataChannel("JanusDataChannel");if(!m)throw new Error("Could not create session_id");s.onicecandidate=o=>{g("peerConnection.onicecandidate",o),o.candidate&&o.candidate.sdpMid&&o.candidate.sdpMLineIndex!==null&&l(u,{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex},m)},s.oniceconnectionstatechange=()=>{var o;g("peerConnection.oniceconnectionstatechange => "+s.iceConnectionState),(o=n.onConnectionStateChange)==null||o.call(n,s.iceConnectionState)},s.ontrack=o=>{var p;g("peerConnection.ontrack",o),(p=n.onSrcObjectReady)==null||p.call(n,o.streams[0])},R.onmessage=o=>{var p;R.readyState==="open"&&((p=n.onVideoStateChange)==null||p.call(n,o.data==="stream/done"?w.Stop:w.Start))},await s.setRemoteDescription(P),g("set remote description OK");const v=await s.createAnswer();return g("create answer OK"),await s.setLocalDescription(v),g("set local description OK"),await r(u,v,m),g("start connection OK"),{speak(o){return a(u,m,o)},async terminate(){var o,p;u&&(s&&(s.close(),s.oniceconnectionstatechange=null,s.onnegotiationneeded=null,s.onicecandidate=null,s.ontrack=null),await S(u,m),(o=n.onConnectionStateChange)==null||o.call(n,"closed"),(p=n.onVideoStateChange)==null||p.call(n,w.Stop))},sessionId:m,streamId:u}}c.createAgentManager=K,c.createAgentsApi=y,c.createClient=f,c.createKnowledgeApi=I,c.createStreamingManager=T,c.getAgentStreamArgs=_,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-id/client-sdk",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.15",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "d-id client sdk",
|
|
7
7
|
"repository": {
|
|
@@ -30,22 +30,23 @@
|
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"dev": "vite",
|
|
33
|
-
"build": "
|
|
34
|
-
"build:dev": "
|
|
35
|
-
"
|
|
33
|
+
"build": "node ./infra/build.js -m production",
|
|
34
|
+
"build:dev": "node ./infra/build.js -m development",
|
|
35
|
+
"deploy:prod": "node ./infra/deploy.js --version patch",
|
|
36
36
|
"preview": "vite preview"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@preact/preset-vite": "^2.5.0",
|
|
40
|
+
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
|
41
|
+
"commander": "^11.1.0",
|
|
40
42
|
"glob": "^10.3.10",
|
|
41
43
|
"preact": "^10.5.13",
|
|
42
|
-
"vite": "^4.4.5",
|
|
43
|
-
"vite-plugin-dts": "^3.6.0",
|
|
44
|
-
"vite-plugin-html-env": "^1.2.8",
|
|
45
|
-
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
|
46
44
|
"prettier": "^3.1.0",
|
|
47
45
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
48
46
|
"serverless": "3.32.2",
|
|
49
|
-
"typescript": "^5.3.2"
|
|
47
|
+
"typescript": "^5.3.2",
|
|
48
|
+
"vite": "^4.4.5",
|
|
49
|
+
"vite-plugin-dts": "^3.6.0",
|
|
50
|
+
"vite-plugin-html-env": "^1.2.8"
|
|
50
51
|
}
|
|
51
|
-
}
|
|
52
|
+
}
|