@d-id/client-sdk 1.0.13 → 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,26 +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 g(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 u = await s.text().catch(() => "Failed to fetch");
16
- try {
17
- const c = JSON.parse(u);
18
- c.description ? u = c.description : c.message && (u = c.message);
19
- } catch {
20
- }
21
- throw new Error(u);
14
+ if (!r.ok) {
15
+ let a = await r.text().catch(() => "Failed to fetch");
16
+ throw new Error(a);
22
17
  }
23
- return s.json();
18
+ return r.json();
24
19
  };
25
20
  return {
26
21
  get(e, t) {
@@ -29,94 +24,138 @@ function g(r, o = "https://api.d-id.com") {
29
24
  method: "GET"
30
25
  });
31
26
  },
32
- post(e, t, s) {
27
+ post(e, t, r) {
33
28
  return n(e, {
34
- ...s,
29
+ ...r,
35
30
  body: JSON.stringify(t),
36
31
  method: "POST"
37
32
  });
38
33
  },
39
- delete(e, t, s) {
34
+ delete(e, t, r) {
40
35
  return n(e, {
41
- ...s,
36
+ ...r,
42
37
  body: JSON.stringify(t),
43
38
  method: "DELETE"
44
39
  });
45
40
  },
46
- patch(e, t, s) {
41
+ patch(e, t, r) {
47
42
  return n(e, {
48
- ...s,
43
+ ...r,
49
44
  body: JSON.stringify(t),
50
45
  method: "PATCH"
51
46
  });
52
47
  }
53
48
  };
54
49
  }
55
- function K(r, o = "https://api.d-id.com") {
56
- const n = g(r, `${o}/knowledge`);
50
+ function R(o, s = "https://api.d-id.com") {
51
+ const n = h(o, `${s}/agents`);
57
52
  return {
58
- createKnowledge(e) {
59
- return n.post("/", e);
60
- },
61
- getKnowledgeBase() {
62
- return n.get("/");
63
- },
64
- getKnowledge(e) {
65
- return n.get(`/${e}`);
66
- },
67
- deleteKnowledge(e) {
68
- return n.delete(`/${e}`);
53
+ create(e, t) {
54
+ return n.post("/", e, t);
69
55
  },
70
- createDocument(e, t) {
71
- return n.post(`/${e}/documents`, t);
56
+ getAgents(e, t) {
57
+ return n.get(`/${e ? `?tag=${e}` : ""}`, t).then((r) => r ?? []);
72
58
  },
73
- deleteDocument(e, t) {
74
- return n.delete(`/${e}/documents/${t}`);
59
+ getById(e, t) {
60
+ return n.get(`/${e}`, t);
75
61
  },
76
- getDocuments(e) {
77
- return n.get(`/${e}/documents`);
62
+ delete(e, t) {
63
+ return n.delete(`/${e}`, void 0, t);
78
64
  },
79
- getDocument(e, t) {
80
- return n.get(`/${e}/documents/${t}`);
65
+ update(e, t, r) {
66
+ return n.patch(`/${e}`, t, r);
81
67
  },
82
- getRecords(e, t) {
83
- return n.get(`/${e}/documents/${t}/records`);
68
+ newChat(e, t) {
69
+ return n.post(`/${e}/chat`, void 0, t);
84
70
  },
85
- query(e, t) {
86
- return n.post(`/${e}/query`, {
87
- query: t
88
- });
71
+ chat(e, t, r, a) {
72
+ return n.post(`/${e}/chat/${t}`, r, a);
89
73
  }
90
74
  };
91
75
  }
92
- function O(r, o = "https://api.d-id.com") {
93
- const n = g(r, `${o}/agents`);
76
+ function M(o, s = "https://api.d-id.com") {
77
+ const n = h(o, `${s}/knowledge`);
94
78
  return {
95
- create(e) {
96
- return n.post("/", e);
79
+ createKnowledge(e, t) {
80
+ return n.post("/", e, t);
81
+ },
82
+ getKnowledgeBase(e) {
83
+ return n.get("/", e);
97
84
  },
98
- getAgents(e) {
99
- return n.get(`/${e ? `?tag=${e}` : ""}`);
85
+ getKnowledge(e, t) {
86
+ return n.get(`/${e}`, t);
100
87
  },
101
- getById(e) {
102
- return n.get(`/${e}`);
88
+ deleteKnowledge(e, t) {
89
+ return n.delete(`/${e}`, void 0, t);
103
90
  },
104
- delete(e) {
105
- return n.delete(`/${e}`);
91
+ createDocument(e, t, r) {
92
+ return n.post(`/${e}/documents`, t, r);
106
93
  },
107
- update(e, t) {
108
- return n.patch(`/${e}`, t);
94
+ deleteDocument(e, t, r) {
95
+ return n.delete(`/${e}/documents/${t}`, void 0, r);
109
96
  },
110
- newChat(e) {
111
- return n.post(`/${e}/chat`);
97
+ getDocuments(e, t) {
98
+ return n.get(`/${e}/documents`, t);
112
99
  },
113
- chat(e, t, s) {
114
- return n.post(`/${e}/chat/${t}`, s);
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);
115
110
  }
116
111
  };
117
112
  }
118
- function A(r, o) {
119
- const n = g(r, o);
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();
144
+ },
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
+ });
154
+ }
155
+ };
156
+ }
157
+ function v(o, s) {
158
+ const n = h(o, s);
120
159
  return {
121
160
  createStream(e) {
122
161
  return n.post("/clips/streams", {
@@ -125,22 +164,22 @@ function A(r, o) {
125
164
  compatibility_mode: e.compatibility_mode
126
165
  });
127
166
  },
128
- startConnection(e, t, s) {
167
+ startConnection(e, t, r) {
129
168
  return n.post(`/clips/streams/${e}/sdp`, {
130
- session_id: s,
169
+ session_id: r,
131
170
  answer: t
132
171
  });
133
172
  },
134
- addIceCandidate(e, t, s) {
173
+ addIceCandidate(e, t, r) {
135
174
  return n.post(`/clips/streams/${e}/ice`, {
136
- session_id: s,
175
+ session_id: r,
137
176
  ...t
138
177
  });
139
178
  },
140
- sendStreamRequest(e, t, s) {
179
+ sendStreamRequest(e, t, r) {
141
180
  return n.post(`/clips/streams/${e}`, {
142
181
  session_id: t,
143
- ...s
182
+ ...r
144
183
  });
145
184
  },
146
185
  close(e, t) {
@@ -150,97 +189,101 @@ function A(r, o) {
150
189
  }
151
190
  };
152
191
  }
153
- function T(r, o) {
154
- const n = g(r, o);
192
+ function K(o, s) {
193
+ const n = h(o, s);
155
194
  return {
156
- createStream(e) {
195
+ createStream(e, t) {
157
196
  return n.post("/talks/streams", {
158
197
  source_url: e.source_url,
159
198
  driver_url: e.driver_url,
160
199
  face: e.face,
161
200
  config: e.config
162
- });
201
+ }, t);
163
202
  },
164
- startConnection(e, t, s) {
203
+ startConnection(e, t, r, a) {
165
204
  return n.post(`/talks/streams/${e}/sdp`, {
166
- session_id: s,
205
+ session_id: r,
167
206
  answer: t
168
- });
207
+ }, a);
169
208
  },
170
- addIceCandidate(e, t, s) {
209
+ addIceCandidate(e, t, r, a) {
171
210
  return n.post(`/talks/streams/${e}/ice`, {
172
- session_id: s,
211
+ session_id: r,
173
212
  ...t
174
- });
213
+ }, a);
175
214
  },
176
- sendStreamRequest(e, t, s) {
215
+ sendStreamRequest(e, t, r, a) {
177
216
  return n.post(`/talks/streams/${e}`, {
178
217
  session_id: t,
179
- ...s
180
- });
218
+ ...r
219
+ }, a);
181
220
  },
182
- close(e, t) {
221
+ close(e, t, r) {
183
222
  return n.delete(`/talks/streams/${e}`, {
184
223
  session_id: t
185
- });
224
+ }, r);
186
225
  }
187
226
  };
188
227
  }
189
- var m = /* @__PURE__ */ ((r) => (r.Idle = "IDLE", r.Streaming = "STREAMING", r))(m || {}), $ = /* @__PURE__ */ ((r) => (r.Clip = "clip", r.Talk = "talk", r))($ || {});
190
- let f = !1;
191
- const d = (r, o) => f && console.log(r, o), D = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
192
- async function E(r, {
193
- 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,
194
232
  callbacks: n,
195
233
  auth: e,
196
234
  baseURL: t = "https://api.d-id.com"
197
235
  }) {
198
- f = o;
199
- let s = null;
236
+ _ = s;
200
237
  const {
201
- startConnection: u,
202
- sendStreamRequest: c,
203
- close: h,
238
+ startConnection: r,
239
+ sendStreamRequest: a,
240
+ close: w,
204
241
  createStream: S,
205
- addIceCandidate: _
206
- } = r.videoType === $.Clip ? A(e, t) : T(e, t), {
207
- id: l,
208
- offer: y,
209
- ice_servers: I,
210
- session_id: p
211
- } = await S(r), a = new D({
212
- iceServers: I
213
- }), C = a.createDataChannel("JanusDataChannel");
214
- if (!p)
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)
215
252
  throw new Error("Could not create session_id");
216
- a.onicecandidate = (i) => {
217
- d("peerConnection.onicecandidate", i), i.candidate && i.candidate.sdpMid && i.candidate.sdpMLineIndex !== null && _(l, {
253
+ d.onicecandidate = (i) => {
254
+ p("peerConnection.onicecandidate", i), i.candidate && i.candidate.sdpMid && i.candidate.sdpMLineIndex !== null && $(c, {
218
255
  candidate: i.candidate.candidate,
219
256
  sdpMid: i.candidate.sdpMid,
220
257
  sdpMLineIndex: i.candidate.sdpMLineIndex
221
- }, p);
222
- }, a.oniceconnectionstatechange = () => {
223
- d("peerConnection.oniceconnectionstatechange => " + a.iceConnectionState), n.onConnectionStateChange(a.iceConnectionState);
224
- }, a.ontrack = (i) => {
225
- d("peerConnection.ontrack", i), s = i.streams[0], n.onSrcObjectReady(s);
226
- }, C.onmessage = (i) => {
227
- C.readyState === "open" && n.onStreamingStateChange(i.data === "stream/done" ? m.Idle : m.Streaming);
228
- }, await a.setRemoteDescription(y), d("set remote description OK");
229
- const w = await a.createAnswer();
230
- return d("create answer OK"), await a.setLocalDescription(w), d("set local description OK"), await u(l, w, p), d("start connection OK"), {
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"), {
231
271
  speak(i) {
232
- return c(l, p, i);
272
+ return a(c, g, i);
233
273
  },
234
274
  async terminate() {
235
- l && (s && (s.getTracks().forEach((i) => i.stop()), s = null), a && (a.close(), a.oniceconnectionstatechange = null, a.onnegotiationneeded = null, a.onicecandidate = null, a.ontrack = null), await h(l, p), n.onConnectionStateChange("closed"), n.onStreamingStateChange(m.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));
236
277
  },
237
- sessionId: p,
238
- streamId: l
278
+ sessionId: g,
279
+ streamId: c
239
280
  };
240
281
  }
241
282
  export {
242
- O as createAgentsApi,
243
- g as createClient,
244
- K as createKnowledgeApi,
245
- E 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
246
289
  };
@@ -1 +1 @@
1
- (function(c,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(c=typeof globalThis<"u"?globalThis:c||self,g(c.index={}))})(this,function(c){"use strict";function g(r){return r.type==="bearer"?"Bearer "+r.token:r.type==="basic"?"Basic "+btoa(`${r.username}:${r.password}`):"Client-Key "+r.clientKey}function f(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:g(r),"Content-Type":"application/json"}});if(!i.ok){let l=await i.text().catch(()=>"Failed to fetch");try{const u=JSON.parse(l);u.description?l=u.description:u.message&&(l=u.message)}catch{}throw new Error(l)}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 y(r,o="https://api.d-id.com"){const n=f(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 _(r,o="https://api.d-id.com"){const n=f(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 A(r,o){const n=f(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 I(r,o){const n=f(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 C=(r=>(r.Idle="IDLE",r.Streaming="STREAMING",r))(C||{}),w=(r=>(r.Clip="clip",r.Talk="talk",r))(w||{});let h=!1;const d=(r,o)=>h&&console.log(r,o),T=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function k(r,{debug:o=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){h=o;let i=null;const{startConnection:l,sendStreamRequest:u,close:K,createStream:O,addIceCandidate:b}=r.videoType===w.Clip?A(e,t):I(e,t),{id:p,offer:D,ice_servers:E,session_id:m}=await O(r),a=new T({iceServers:E}),$=a.createDataChannel("JanusDataChannel");if(!m)throw new Error("Could not create session_id");a.onicecandidate=s=>{d("peerConnection.onicecandidate",s),s.candidate&&s.candidate.sdpMid&&s.candidate.sdpMLineIndex!==null&&b(p,{candidate:s.candidate.candidate,sdpMid:s.candidate.sdpMid,sdpMLineIndex:s.candidate.sdpMLineIndex},m)},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"?C.Idle:C.Streaming)},await a.setRemoteDescription(D),d("set remote description OK");const S=await a.createAnswer();return d("create answer OK"),await a.setLocalDescription(S),d("set local description OK"),await l(p,S,m),d("start connection OK"),{speak(s){return u(p,m,s)},async terminate(){p&&(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(p,m),n.onConnectionStateChange("closed"),n.onStreamingStateChange(C.Idle))},sessionId:m,streamId:p}}c.createAgentsApi=_,c.createClient=f,c.createKnowledgeApi=y,c.createStreamingManager=k,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.13",
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
+ }