@d-id/client-sdk 1.0.14 → 1.0.16

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<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<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';
@@ -1,3 +1,4 @@
1
+ import { Message } from './entities';
1
2
  import { StreamTextToSpeechProviders } from './tts';
2
3
  export type StreamScriptType = 'text' | 'audio';
3
4
  export interface BaseStreamScript {
@@ -11,7 +12,7 @@ export interface Stream_Text_Script extends BaseStreamScript {
11
12
  /**
12
13
  * text-to-speech provider from list of supported providers. default is microsoft tts
13
14
  */
14
- provider?: StreamTextToSpeechProviders;
15
+ provider: StreamTextToSpeechProviders;
15
16
  /**
16
17
  * The input text that will be synthesized to an audio file.
17
18
  * Note that each provider has its own limitations on the text length.
@@ -37,4 +38,15 @@ export interface Stream_Audio_Script extends BaseStreamScript {
37
38
  */
38
39
  audio_url: string;
39
40
  }
40
- export type StreamScript = Stream_Text_Script | Stream_Audio_Script;
41
+ export interface Stream_LLM_Script {
42
+ type: 'llm';
43
+ provider: StreamTextToSpeechProviders;
44
+ ssml?: boolean;
45
+ llm: {
46
+ messages: Message[];
47
+ provider: 'openai';
48
+ };
49
+ input?: string;
50
+ stream_audio?: boolean;
51
+ }
52
+ export type StreamScript = Stream_Text_Script | Stream_Audio_Script | Stream_LLM_Script;
@@ -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 {};
@@ -31,5 +31,6 @@ export interface KnowledgeData {
31
31
  vector_store: string;
32
32
  description: string;
33
33
  name: string;
34
+ starter_message?: string[];
34
35
  }
35
36
  export type KnowledgePayload = Omit<KnowledgeData, 'created_by' | 'type' | 'created_at' | 'modified_at' | 'id' | 'owner_id'>;
@@ -42,4 +42,6 @@ export interface SendTalkStreamPayload {
42
42
  };
43
43
  user_data?: Record<string, any>;
44
44
  name?: string;
45
+ audio_optimization?: number;
46
+ metadata: Record<string, any>;
45
47
  }
@@ -1,16 +1,22 @@
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
+ }
10
+ export declare enum StreamEvents {
11
+ ChatPartial = "chat/partial",
12
+ StreamDone = "stream/done",
13
+ StreamStarted = "stream/started"
9
14
  }
10
15
  export interface ManagerCallbacks {
11
- onStreamingStateChange: (state: StreamingState) => void;
12
- onConnectionStateChange: (state: RTCIceConnectionState) => void;
13
- onSrcObjectReady: (value: MediaStream) => void;
16
+ onMessage?: (event: string, data: string) => void;
17
+ onConnectionStateChange?: (state: RTCIceConnectionState) => void;
18
+ onVideoStateChange?: (state: StreamingState) => void;
19
+ onSrcObjectReady?: (value: MediaStream) => void;
14
20
  }
15
21
  export interface TalkStreamOptions extends CreateTalkStreamRequest {
16
22
  videoType: VideoType.Talk;
@@ -27,7 +33,7 @@ export interface RtcApi {
27
33
  sendStreamRequest(streamId: string, sessionId: string, payload: SendClipStreamPayload | SendTalkStreamPayload): Promise<SendStreamPayloadResponse>;
28
34
  close(streamId: string, sessionId: string): Promise<Status>;
29
35
  }
30
- export interface ManagerOptions {
36
+ export interface StreamingManagerOptions {
31
37
  callbacks: ManagerCallbacks;
32
38
  baseURL?: string;
33
39
  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 l(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, d = "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(d + (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: l(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 M(o, d = "https://api.d-id.com") {
51
+ const n = h(o, `${d}/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 B(o, d = "https://api.d-id.com") {
77
+ const n = h(o, `${d}/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);
84
+ },
85
+ getKnowledge(e, t) {
86
+ return n.get(`/${e}`, t);
92
87
  },
93
- getAgents(e) {
94
- return n.get(`/${e ? `?tag=${e}` : ""}`);
88
+ deleteKnowledge(e, t) {
89
+ return n.delete(`/${e}`, void 0, t);
95
90
  },
96
- getById(e) {
97
- return n.get(`/${e}`);
91
+ createDocument(e, t, r) {
92
+ return n.post(`/${e}/documents`, t, r);
98
93
  },
99
- delete(e) {
100
- return n.delete(`/${e}`);
94
+ deleteDocument(e, t, r) {
95
+ return n.delete(`/${e}/documents/${t}`, void 0, r);
101
96
  },
102
- update(e, t) {
103
- return n.patch(`/${e}`, t);
97
+ getDocuments(e, t) {
98
+ return n.get(`/${e}/documents`, t);
104
99
  },
105
- newChat(e) {
106
- return n.post(`/${e}/chat`);
100
+ getDocument(e, t, r) {
101
+ return n.get(`/${e}/documents/${t}`, r);
107
102
  },
108
- chat(e, t, s) {
109
- return n.post(`/${e}/chat/${t}`, s);
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
110
  }
111
111
  };
112
112
  }
113
- function A(r, o) {
114
- const n = p(r, o);
113
+ var C = /* @__PURE__ */ ((o) => (o.Start = "START", o.Stop = "STOP", o))(C || {}), y = /* @__PURE__ */ ((o) => (o.ChatPartial = "chat/partial", o.StreamDone = "stream/done", o.StreamStarted = "stream/started", o))(y || {}), m = /* @__PURE__ */ ((o) => (o.Clip = "clip", o.Talk = "talk", o))(m || {});
114
+ function O(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 L(o, {
125
+ callbacks: d,
126
+ ...n
127
+ }) {
128
+ const e = new AbortController(), t = M(n.auth, n.baseURL), r = await t.getById(o), a = await t.newChat(o), {
129
+ terminate: w,
130
+ sessionId: S,
131
+ streamId: f
132
+ } = await x(O(r), {
133
+ ...n,
134
+ callbacks: {
135
+ onSrcObjectReady: d.onSrcObjectReady,
136
+ onVideoStateChange: d == null ? void 0 : d.onVideoStateChange,
137
+ onConnectionStateChange: d.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: f,
150
+ messages: c
151
+ }, {
152
+ signal: e.signal
153
+ });
154
+ }
155
+ };
156
+ }
157
+ function P(o, d) {
158
+ const n = h(o, d);
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,105 @@ function A(r, o) {
145
189
  }
146
190
  };
147
191
  }
148
- function T(r, o) {
149
- const n = p(r, o);
192
+ function q(o, d) {
193
+ const n = h(o, d);
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 I = !1;
229
+ const p = (o, d) => I && console.log(o, d), j = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
230
+ async function x(o, {
231
+ debug: d = !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
+ I = d;
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: f
243
+ } = o.videoType === m.Clip ? P(e, t) : q(e, t), {
244
+ id: c,
245
+ offer: D,
246
+ ice_servers: v,
247
+ session_id: g
248
+ } = await S(o), s = new j({
249
+ iceServers: v
250
+ }), A = s.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
+ s.onicecandidate = (i) => {
254
+ p("peerConnection.onicecandidate", i), i.candidate && i.candidate.sdpMid && i.candidate.sdpMLineIndex !== null && f(c, {
255
+ candidate: i.candidate.candidate,
256
+ sdpMid: i.candidate.sdpMid,
257
+ sdpMLineIndex: i.candidate.sdpMLineIndex
258
+ }, g);
259
+ }, s.oniceconnectionstatechange = () => {
260
+ var i;
261
+ p("peerConnection.oniceconnectionstatechange => " + s.iceConnectionState), (i = n.onConnectionStateChange) == null || i.call(n, s.iceConnectionState);
262
+ }, s.ontrack = (i) => {
263
+ var u;
264
+ p("peerConnection.ontrack", i), (u = n.onSrcObjectReady) == null || u.call(n, i.streams[0]);
265
+ }, A.onmessage = (i) => {
266
+ var u, $, R;
267
+ if (A.readyState === "open") {
268
+ const [_, K] = i.data.split(":");
269
+ _ === y.StreamDone ? (u = n.onVideoStateChange) == null || u.call(n, C.Stop) : _ === y.StreamStarted ? ($ = n.onVideoStateChange) == null || $.call(n, C.Start) : (R = n.onMessage) == null || R.call(n, _, decodeURIComponent(K));
270
+ }
271
+ }, await s.setRemoteDescription(D), p("set remote description OK");
272
+ const T = await s.createAnswer();
273
+ return p("create answer OK"), await s.setLocalDescription(T), p("set local description OK"), await r(c, T, g), p("start connection OK"), {
274
+ speak(i) {
275
+ return a(c, g, i);
228
276
  },
229
277
  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));
278
+ var i, u;
279
+ c && (s && (s.close(), s.oniceconnectionstatechange = null, s.onnegotiationneeded = null, s.onicecandidate = null, s.ontrack = null), await w(c, g).catch(($) => {
280
+ }), (i = n.onConnectionStateChange) == null || i.call(n, "closed"), (u = n.onVideoStateChange) == null || u.call(n, C.Stop));
231
281
  },
232
- sessionId: u,
233
- streamId: d
282
+ sessionId: g,
283
+ streamId: c
234
284
  };
235
285
  }
236
286
  export {
237
- O as createAgentsApi,
238
- p as createClient,
239
- K as createKnowledgeApi,
240
- R as createStreamingManager
287
+ L as createAgentManager,
288
+ M as createAgentsApi,
289
+ h as createClient,
290
+ B as createKnowledgeApi,
291
+ x as createStreamingManager,
292
+ O as getAgentStreamArgs
241
293
  };
@@ -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 h(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 l(i,d="https://api.d-id.com"){const n=h(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 O(i,d="https://api.d-id.com"){const n=h(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 S=(i=>(i.Start="START",i.Stop="STOP",i))(S||{}),w=(i=>(i.ChatPartial="chat/partial",i.StreamDone="stream/done",i.StreamStarted="stream/started",i))(w||{}),f=(i=>(i.Clip="clip",i.Talk="talk",i))(f||{});function R(i){return i.presenter.type===f.Clip?{videoType:f.Clip,driver_id:i.presenter.driver_id,presenter_id:i.presenter.presenter_id}:{videoType:f.Talk,source_url:i.presenter.source_url}}async function P(i,{callbacks:d,...n}){const e=new AbortController,t=l(n.auth,n.baseURL),r=await t.getById(i),a=await t.newChat(i),{terminate:$,sessionId:y,streamId:_}=await v(R(r),{...n,callbacks:{onSrcObjectReady:d.onSrcObjectReady,onVideoStateChange:d==null?void 0:d.onVideoStateChange,onConnectionStateChange:d.onConnectionStateChange}});return{agent:r,terminate(){return e.abort(),$()},chatId:a.id,chat(u){return t.chat(i,a.id,{sessionId:y,streamId:_,messages:u},{signal:e.signal})}}}function j(i,d){const n=h(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 q(i,d){const n=h(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 I=!1;const g=(i,d)=>I&&console.log(i,d),B=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function v(i,{debug:d=!1,callbacks:n,auth:e,baseURL:t="https://api.d-id.com"}){I=d;const{startConnection:r,sendStreamRequest:a,close:$,createStream:y,addIceCandidate:_}=i.videoType===f.Clip?j(e,t):q(e,t),{id:u,offer:L,ice_servers:E,session_id:m}=await y(i),s=new B({iceServers:E}),D=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&&_(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])},D.onmessage=o=>{var p,A,M;if(D.readyState==="open"){const[T,J]=o.data.split(":");T===w.StreamDone?(p=n.onVideoStateChange)==null||p.call(n,S.Stop):T===w.StreamStarted?(A=n.onVideoStateChange)==null||A.call(n,S.Start):(M=n.onMessage)==null||M.call(n,T,decodeURIComponent(J))}},await s.setRemoteDescription(L),g("set remote description OK");const K=await s.createAnswer();return g("create answer OK"),await s.setLocalDescription(K),g("set local description OK"),await r(u,K,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 $(u,m).catch(A=>{}),(o=n.onConnectionStateChange)==null||o.call(n,"closed"),(p=n.onVideoStateChange)==null||p.call(n,S.Stop))},sessionId:m,streamId:u}}c.createAgentManager=P,c.createAgentsApi=l,c.createClient=h,c.createKnowledgeApi=O,c.createStreamingManager=v,c.getAgentStreamArgs=R,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.16",
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
+ }