@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.
@@ -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, ManagerOptions, PayloadType } from '../../../common/types/src/index';
2
- export declare function createStreamingManager<T extends CreateStreamOptions>(agent: T, { debug, callbacks, auth, baseURL }: ManagerOptions): Promise<{
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;
@@ -1,4 +1,5 @@
1
+ export * from './api/agents';
1
2
  export * from './api/getClient';
2
3
  export * from './api/knowledge';
3
- export * from './api/agents';
4
+ export * from './createAgentManager';
4
5
  export * from './createStreamingManager';
@@ -9,6 +9,7 @@ export interface Agent {
9
9
  knowledge?: Knowledge;
10
10
  use_case?: string;
11
11
  tags?: string[];
12
+ chats?: number;
12
13
  access?: 'private' | 'pending-public' | 'unlisted' | 'rejected' | 'public';
13
14
  preview_name?: string;
14
15
  preview_description?: 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: Message[];
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
- id: string;
31
+ messages: Message[];
32
+ agent_id__created_at: string;
33
+ agent_id__modified_at: string;
21
34
  }
@@ -1,2 +1,3 @@
1
1
  export * from './agent';
2
2
  export * from './chat';
3
+ export * from './manager';
@@ -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
- Idle = "IDLE",
8
- Streaming = "STREAMING"
7
+ Start = "START",
8
+ Stop = "STOP"
9
9
  }
10
10
  export interface ManagerCallbacks {
11
- onStreamingStateChange: (state: StreamingState) => void;
12
- onConnectionStateChange: (state: RTCIceConnectionState) => void;
13
- onSrcObjectReady: (value: MediaStream) => void;
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 ManagerOptions {
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 k(r) {
2
- return r.type === "bearer" ? "Bearer " + r.token : r.type === "basic" ? "Basic " + btoa(`${r.username}:${r.password}`) : "Client-Key " + r.clientKey;
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 p(r, o = "https://api.d-id.com") {
4
+ function h(o, s = "https://api.d-id.com") {
5
5
  const n = async (e, t) => {
6
- const s = await fetch(o + (e != null && e.startsWith("/") ? e : `/${e}`), {
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: k(r),
10
+ Authorization: T(o),
11
11
  "Content-Type": "application/json"
12
12
  }
13
13
  });
14
- if (!s.ok) {
15
- let m = await s.text().catch(() => "Failed to fetch");
16
- throw new Error(m);
14
+ if (!r.ok) {
15
+ let a = await r.text().catch(() => "Failed to fetch");
16
+ throw new Error(a);
17
17
  }
18
- return s.json();
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, s) {
27
+ post(e, t, r) {
28
28
  return n(e, {
29
- ...s,
29
+ ...r,
30
30
  body: JSON.stringify(t),
31
31
  method: "POST"
32
32
  });
33
33
  },
34
- delete(e, t, s) {
34
+ delete(e, t, r) {
35
35
  return n(e, {
36
- ...s,
36
+ ...r,
37
37
  body: JSON.stringify(t),
38
38
  method: "DELETE"
39
39
  });
40
40
  },
41
- patch(e, t, s) {
41
+ patch(e, t, r) {
42
42
  return n(e, {
43
- ...s,
43
+ ...r,
44
44
  body: JSON.stringify(t),
45
45
  method: "PATCH"
46
46
  });
47
47
  }
48
48
  };
49
49
  }
50
- function K(r, o = "https://api.d-id.com") {
51
- const n = p(r, `${o}/knowledge`);
50
+ function R(o, s = "https://api.d-id.com") {
51
+ const n = h(o, `${s}/agents`);
52
52
  return {
53
- createKnowledge(e) {
54
- return n.post("/", e);
53
+ create(e, t) {
54
+ return n.post("/", e, t);
55
55
  },
56
- getKnowledgeBase() {
57
- return n.get("/");
56
+ getAgents(e, t) {
57
+ return n.get(`/${e ? `?tag=${e}` : ""}`, t).then((r) => r ?? []);
58
58
  },
59
- getKnowledge(e) {
60
- return n.get(`/${e}`);
59
+ getById(e, t) {
60
+ return n.get(`/${e}`, t);
61
61
  },
62
- deleteKnowledge(e) {
63
- return n.delete(`/${e}`);
62
+ delete(e, t) {
63
+ return n.delete(`/${e}`, void 0, t);
64
64
  },
65
- createDocument(e, t) {
66
- return n.post(`/${e}/documents`, t);
65
+ update(e, t, r) {
66
+ return n.patch(`/${e}`, t, r);
67
67
  },
68
- deleteDocument(e, t) {
69
- return n.delete(`/${e}/documents/${t}`);
68
+ newChat(e, t) {
69
+ return n.post(`/${e}/chat`, void 0, t);
70
70
  },
71
- getDocuments(e) {
72
- return n.get(`/${e}/documents`);
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 O(r, o = "https://api.d-id.com") {
88
- const n = p(r, `${o}/agents`);
76
+ function M(o, s = "https://api.d-id.com") {
77
+ const n = h(o, `${s}/knowledge`);
89
78
  return {
90
- create(e) {
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
- getAgents(e) {
94
- return n.get(`/${e ? `?tag=${e}` : ""}`);
85
+ getKnowledge(e, t) {
86
+ return n.get(`/${e}`, t);
95
87
  },
96
- getById(e) {
97
- return n.get(`/${e}`);
88
+ deleteKnowledge(e, t) {
89
+ return n.delete(`/${e}`, void 0, t);
98
90
  },
99
- delete(e) {
100
- return n.delete(`/${e}`);
91
+ createDocument(e, t, r) {
92
+ return n.post(`/${e}/documents`, t, r);
101
93
  },
102
- update(e, t) {
103
- return n.patch(`/${e}`, t);
94
+ deleteDocument(e, t, r) {
95
+ return n.delete(`/${e}/documents/${t}`, void 0, r);
104
96
  },
105
- newChat(e) {
106
- return n.post(`/${e}/chat`);
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
- chat(e, t, s) {
109
- return n.post(`/${e}/chat/${t}`, s);
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 A(r, o) {
114
- const n = p(r, o);
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, s) {
167
+ startConnection(e, t, r) {
124
168
  return n.post(`/clips/streams/${e}/sdp`, {
125
- session_id: s,
169
+ session_id: r,
126
170
  answer: t
127
171
  });
128
172
  },
129
- addIceCandidate(e, t, s) {
173
+ addIceCandidate(e, t, r) {
130
174
  return n.post(`/clips/streams/${e}/ice`, {
131
- session_id: s,
175
+ session_id: r,
132
176
  ...t
133
177
  });
134
178
  },
135
- sendStreamRequest(e, t, s) {
179
+ sendStreamRequest(e, t, r) {
136
180
  return n.post(`/clips/streams/${e}`, {
137
181
  session_id: t,
138
- ...s
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 T(r, o) {
149
- const n = p(r, o);
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, s) {
203
+ startConnection(e, t, r, a) {
160
204
  return n.post(`/talks/streams/${e}/sdp`, {
161
- session_id: s,
205
+ session_id: r,
162
206
  answer: t
163
- });
207
+ }, a);
164
208
  },
165
- addIceCandidate(e, t, s) {
209
+ addIceCandidate(e, t, r, a) {
166
210
  return n.post(`/talks/streams/${e}/ice`, {
167
- session_id: s,
211
+ session_id: r,
168
212
  ...t
169
- });
213
+ }, a);
170
214
  },
171
- sendStreamRequest(e, t, s) {
215
+ sendStreamRequest(e, t, r, a) {
172
216
  return n.post(`/talks/streams/${e}`, {
173
217
  session_id: t,
174
- ...s
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
- var l = /* @__PURE__ */ ((r) => (r.Idle = "IDLE", r.Streaming = "STREAMING", r))(l || {}), w = /* @__PURE__ */ ((r) => (r.Clip = "clip", r.Talk = "talk", r))(w || {});
185
- let $ = !1;
186
- const c = (r, o) => $ && console.log(r, o), D = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
187
- async function R(r, {
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
- $ = o;
194
- let s = null;
236
+ _ = s;
195
237
  const {
196
- startConnection: m,
197
- sendStreamRequest: f,
198
- close: h,
238
+ startConnection: r,
239
+ sendStreamRequest: a,
240
+ close: w,
199
241
  createStream: S,
200
- addIceCandidate: _
201
- } = r.videoType === w.Clip ? A(e, t) : T(e, t), {
202
- id: d,
203
- offer: y,
204
- ice_servers: I,
205
- session_id: u
206
- } = await S(r), i = new D({
207
- iceServers: I
208
- }), g = i.createDataChannel("JanusDataChannel");
209
- if (!u)
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
- i.onicecandidate = (a) => {
212
- c("peerConnection.onicecandidate", a), a.candidate && a.candidate.sdpMid && a.candidate.sdpMLineIndex !== null && _(d, {
213
- candidate: a.candidate.candidate,
214
- sdpMid: a.candidate.sdpMid,
215
- sdpMLineIndex: a.candidate.sdpMLineIndex
216
- }, u);
217
- }, i.oniceconnectionstatechange = () => {
218
- c("peerConnection.oniceconnectionstatechange => " + i.iceConnectionState), n.onConnectionStateChange(i.iceConnectionState);
219
- }, i.ontrack = (a) => {
220
- c("peerConnection.ontrack", a), s = a.streams[0], n.onSrcObjectReady(s);
221
- }, g.onmessage = (a) => {
222
- g.readyState === "open" && n.onStreamingStateChange(a.data === "stream/done" ? l.Idle : l.Streaming);
223
- }, await i.setRemoteDescription(y), c("set remote description OK");
224
- const C = await i.createAnswer();
225
- return c("create answer OK"), await i.setLocalDescription(C), c("set local description OK"), await m(d, C, u), c("start connection OK"), {
226
- speak(a) {
227
- return f(d, u, a);
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
- d && (s && (s.getTracks().forEach((a) => a.stop()), s = null), i && (i.close(), i.oniceconnectionstatechange = null, i.onnegotiationneeded = null, i.onicecandidate = null, i.ontrack = null), await h(d, u), n.onConnectionStateChange("closed"), n.onStreamingStateChange(l.Idle));
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: u,
233
- streamId: d
278
+ sessionId: g,
279
+ streamId: c
234
280
  };
235
281
  }
236
282
  export {
237
- O as createAgentsApi,
238
- p as createClient,
239
- K as createKnowledgeApi,
240
- R as createStreamingManager
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
  };
@@ -1 +1 @@
1
- (function(c,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(c=typeof globalThis<"u"?globalThis:c||self,p(c.index={}))})(this,function(c){"use strict";function p(r){return r.type==="bearer"?"Bearer "+r.token:r.type==="basic"?"Basic "+btoa(`${r.username}:${r.password}`):"Client-Key "+r.clientKey}function m(r,o="https://api.d-id.com"){const n=async(e,t)=>{const i=await fetch(o+(e!=null&&e.startsWith("/")?e:`/${e}`),{...t,headers:{...t==null?void 0:t.headers,Authorization:p(r),"Content-Type":"application/json"}});if(!i.ok){let f=await i.text().catch(()=>"Failed to fetch");throw new Error(f)}return i.json()};return{get(e,t){return n(e,{...t,method:"GET"})},post(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"POST"})},delete(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"DELETE"})},patch(e,t,i){return n(e,{...i,body:JSON.stringify(t),method:"PATCH"})}}}function S(r,o="https://api.d-id.com"){const n=m(r,`${o}/knowledge`);return{createKnowledge(e){return n.post("/",e)},getKnowledgeBase(){return n.get("/")},getKnowledge(e){return n.get(`/${e}`)},deleteKnowledge(e){return n.delete(`/${e}`)},createDocument(e,t){return n.post(`/${e}/documents`,t)},deleteDocument(e,t){return n.delete(`/${e}/documents/${t}`)},getDocuments(e){return n.get(`/${e}/documents`)},getDocument(e,t){return n.get(`/${e}/documents/${t}`)},getRecords(e,t){return n.get(`/${e}/documents/${t}/records`)},query(e,t){return n.post(`/${e}/query`,{query:t})}}}function y(r,o="https://api.d-id.com"){const n=m(r,`${o}/agents`);return{create(e){return n.post("/",e)},getAgents(e){return n.get(`/${e?`?tag=${e}`:""}`)},getById(e){return n.get(`/${e}`)},delete(e){return n.delete(`/${e}`)},update(e,t){return n.patch(`/${e}`,t)},newChat(e){return n.post(`/${e}/chat`)},chat(e,t,i){return n.post(`/${e}/chat/${t}`,i)}}}function _(r,o){const n=m(r,o);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,i){return n.post(`/clips/streams/${e}/sdp`,{session_id:i,answer:t})},addIceCandidate(e,t,i){return n.post(`/clips/streams/${e}/ice`,{session_id:i,...t})},sendStreamRequest(e,t,i){return n.post(`/clips/streams/${e}`,{session_id:t,...i})},close(e,t){return n.delete(`/clips/streams/${e}`,{session_id:t})}}}function A(r,o){const n=m(r,o);return{createStream(e){return n.post("/talks/streams",{source_url:e.source_url,driver_url:e.driver_url,face:e.face,config:e.config})},startConnection(e,t,i){return n.post(`/talks/streams/${e}/sdp`,{session_id:i,answer:t})},addIceCandidate(e,t,i){return n.post(`/talks/streams/${e}/ice`,{session_id:i,...t})},sendStreamRequest(e,t,i){return n.post(`/talks/streams/${e}`,{session_id:t,...i})},close(e,t){return n.delete(`/talks/streams/${e}`,{session_id:t})}}}var g=(r=>(r.Idle="IDLE",r.Streaming="STREAMING",r))(g||{}),C=(r=>(r.Clip="clip",r.Talk="talk",r))(C||{});let w=!1;const d=(r,o)=>w&&console.log(r,o),I=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function T(r,{debug:o=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){w=o;let i=null;const{startConnection:f,sendStreamRequest:k,close:K,createStream:b,addIceCandidate:D}=r.videoType===C.Clip?_(e,t):A(e,t),{id:u,offer:O,ice_servers:M,session_id:l}=await b(r),a=new I({iceServers:M}),$=a.createDataChannel("JanusDataChannel");if(!l)throw new Error("Could not create session_id");a.onicecandidate=s=>{d("peerConnection.onicecandidate",s),s.candidate&&s.candidate.sdpMid&&s.candidate.sdpMLineIndex!==null&&D(u,{candidate:s.candidate.candidate,sdpMid:s.candidate.sdpMid,sdpMLineIndex:s.candidate.sdpMLineIndex},l)},a.oniceconnectionstatechange=()=>{d("peerConnection.oniceconnectionstatechange => "+a.iceConnectionState),n.onConnectionStateChange(a.iceConnectionState)},a.ontrack=s=>{d("peerConnection.ontrack",s),i=s.streams[0],n.onSrcObjectReady(i)},$.onmessage=s=>{$.readyState==="open"&&n.onStreamingStateChange(s.data==="stream/done"?g.Idle:g.Streaming)},await a.setRemoteDescription(O),d("set remote description OK");const h=await a.createAnswer();return d("create answer OK"),await a.setLocalDescription(h),d("set local description OK"),await f(u,h,l),d("start connection OK"),{speak(s){return k(u,l,s)},async terminate(){u&&(i&&(i.getTracks().forEach(s=>s.stop()),i=null),a&&(a.close(),a.oniceconnectionstatechange=null,a.onnegotiationneeded=null,a.onicecandidate=null,a.ontrack=null),await K(u,l),n.onConnectionStateChange("closed"),n.onStreamingStateChange(g.Idle))},sessionId:l,streamId:u}}c.createAgentsApi=y,c.createClient=m,c.createKnowledgeApi=S,c.createStreamingManager=T,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
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.14",
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": "tsc && vite build",
34
- "build:dev": "tsc && vite build --mode development",
35
- "dopublish": "yarn build && npm publish --access public",
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
+ }