@anam-ai/js-sdk 1.0.0 → 1.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -1
- package/dist/main/AnamClient.d.ts +2 -2
- package/dist/main/AnamClient.d.ts.map +1 -1
- package/dist/main/AnamClient.js +8 -8
- package/dist/main/AnamClient.js.map +1 -1
- package/dist/main/index.d.ts +17 -1
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +16 -0
- package/dist/main/index.js.map +1 -1
- package/dist/main/modules/CoreApiRestClient.js +1 -1
- package/dist/main/modules/CoreApiRestClient.js.map +1 -1
- package/dist/module/AnamClient.d.ts +2 -2
- package/dist/module/AnamClient.d.ts.map +1 -1
- package/dist/module/AnamClient.js +8 -8
- package/dist/module/AnamClient.js.map +1 -1
- package/dist/module/index.d.ts +17 -1
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +16 -0
- package/dist/module/index.js.map +1 -1
- package/dist/module/modules/CoreApiRestClient.js +1 -1
- package/dist/module/modules/CoreApiRestClient.js.map +1 -1
- package/dist/umd/anam.js +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -1,3 +1,182 @@
|
|
|
1
1
|
# Anam AI JavaScript SDK
|
|
2
2
|
|
|
3
|
-
JavaScript
|
|
3
|
+
This is the official JavaScript SDK for integrating Anam AI realtime digital personas into your product. It provides a simple and intuitive API to interact with Anam AI's services.
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
The Anam AI JavaScript SDK is designed to help developers integrate Anam AI's digital personas into their JavaScript applications. The SDK provides a set of APIs and utilities to make it easier to create, manage, and interact with digital personas in a realtime environment.
|
|
8
|
+
|
|
9
|
+
## Prerequisites
|
|
10
|
+
|
|
11
|
+
### An Anam AI account
|
|
12
|
+
|
|
13
|
+
Public account creation is currently unavailable. If you are a design partner your account will be created for you by our team.
|
|
14
|
+
|
|
15
|
+
### An Anam API key
|
|
16
|
+
|
|
17
|
+
Public API keys are not yet available. If you are a design partner an API key will be shared with you during onboarding.
|
|
18
|
+
|
|
19
|
+
## Getting Started
|
|
20
|
+
|
|
21
|
+
First, install the SDK in your project
|
|
22
|
+
|
|
23
|
+
```zsh
|
|
24
|
+
npm install @anam-ai/js-sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Local development
|
|
28
|
+
|
|
29
|
+
The quickest way to start testing the SDK is to use your API key directly with our SDK and [choose a default persona](#listing-personas) from our predefined examples.
|
|
30
|
+
To use the SDK you first need to create an instance of `AnamClient`. For local development you can do this using the `unsafe_createClientWithApiKey` method.
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { unsafe_createClientWithApiKey } from '@anam-ai/js-sdk';
|
|
34
|
+
|
|
35
|
+
const anamClient = unsafe_createClientWithApiKey('your-api-key', {
|
|
36
|
+
personaId: 'chosen-persona-id',
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**NOTE**: the method `unsafe_createClientWithApiKey` is unsafe for production use cases because it requires exposing your api key to the client. When deploying to production see [production usage](#usage-in-production) first.
|
|
41
|
+
|
|
42
|
+
Once you have an instance of the Anam client initialised you can start a session by streaming to audio and video elements in the DOM.
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
await anamClient.streamToVideoAndAudioElements(
|
|
46
|
+
'video-element-id',
|
|
47
|
+
'audio-element-id',
|
|
48
|
+
);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
This will start a new session using the pre-configured persona id and start streaming video and audio to the elements in the DOM with the matching element ids.
|
|
52
|
+
|
|
53
|
+
### Usage in production
|
|
54
|
+
|
|
55
|
+
When deploying to production it is important not to publically expose your API key. To avoid this issue you should first exchange your API key for a short-lived session token on the server side. Session tokens can then be passed to the client and used to initialise the Anam SDK.
|
|
56
|
+
**From the server**
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const response = await fetch(`https://api.anam.ai/v1/auth/session-token`, {
|
|
60
|
+
method: 'GET',
|
|
61
|
+
headers: {
|
|
62
|
+
'Content-Type': 'application/json',
|
|
63
|
+
Authorization: `Bearer ${apiKey}`,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const data = await response.json();
|
|
67
|
+
const sessionToken = data.sessionToken;
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Once you have a session token you can use the `createClient` method of the Anam SDK to intialise an Anam client instance.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { createClient } from '@anam-ai/js-sdk';
|
|
74
|
+
|
|
75
|
+
const anamClient = createClient('your-session-token', {
|
|
76
|
+
personaId: 'chosen-persona-id',
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Regardless of whether you intialise the client using an API key or session token the client exposes the same set of available methods for streaming.
|
|
81
|
+
|
|
82
|
+
## Personas
|
|
83
|
+
|
|
84
|
+
Available personas are managed via the [Anam API](https://api.anam.ai/api).
|
|
85
|
+
|
|
86
|
+
> **Note**: The examples below are shown using bash curl syntax. For the best expereince we reccommend trying queries directly from our [interactive Swagger Documentation](https://api.anam.ai/api). To use the ineractive Swagger documenation you will first need to authenticate by clicing the Authorize button in the top right and pasting your API key into the displayed box.
|
|
87
|
+
|
|
88
|
+
### Listing Available Personas
|
|
89
|
+
|
|
90
|
+
To list all personas available for your account use the `/v1/persona` endpoint.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Example Request
|
|
94
|
+
curl -X GET "https://api.anam.ai/v1/persona" -H "Authorization: Bearer your-api-key"
|
|
95
|
+
|
|
96
|
+
# Example Response
|
|
97
|
+
[
|
|
98
|
+
{
|
|
99
|
+
"id": "3c6025f0-698d-4e8d-b619-9c97a2750584",
|
|
100
|
+
"name": "Eva",
|
|
101
|
+
"description": "Eva is the virtual receptionist of the Sunset Hotel.",
|
|
102
|
+
"personaPreset": "eva",
|
|
103
|
+
"createdAt": "2021-01-01T00:00:00Z",
|
|
104
|
+
"updatedAt": "2021-01-02T00:00:00Z"
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
By default each account includes our example persona 'Eva'. The virtual receptionist of the Sunset Hotel.
|
|
110
|
+
|
|
111
|
+
> **Quickstart**: Make a note of the ID for the Eva persona and use this to initialise the SDK.
|
|
112
|
+
|
|
113
|
+
To show more detail about a specific persona you can use the `/v1/persona/{id}` endpoint.
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# Example Request
|
|
117
|
+
curl -X GET "https://api.anam.ai/v1/persona/3c6025f0-698d-4e8d-b619-9c97a2750584" -H "Authorization: Bearer your-api-key"
|
|
118
|
+
|
|
119
|
+
# Example Response
|
|
120
|
+
{
|
|
121
|
+
"id": "3c6025f0-698d-4e8d-b619-9c97a2750584",
|
|
122
|
+
"name": "Eva",
|
|
123
|
+
"description": "Eva is the virtual receptionist of the Sunset Hotel.",
|
|
124
|
+
"personaPreset": "eva",
|
|
125
|
+
"brain": {
|
|
126
|
+
"id": "3c4525f0-698d-4e8d-b619-8c97a23780512",
|
|
127
|
+
"personality": "You are role-playing as a text chatbot hotel receptionist at The Sunset Hotel. Your name is Eva.",
|
|
128
|
+
"systemPrompt": "You are role-playing as a text chatbot hotel receptionist at The Sunset Hotel...",
|
|
129
|
+
"fillerPhrases": ["One moment please.", "Let me check that for you."],
|
|
130
|
+
"createdAt": "2021-01-01T00:00:00Z",
|
|
131
|
+
"updatedAt": "2021-01-02T00:00:00Z"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Creating Custom Personas
|
|
137
|
+
|
|
138
|
+
You can create your own custom personas by using the `/v1/persona` endpoint via a `POST` request which defined the following properties:
|
|
139
|
+
| Persona parameter | Description |
|
|
140
|
+
|----------------|---------------------------------------------------------------------------------------------------------|
|
|
141
|
+
| `name` | The name for the persona. This is used as a human-readable identifier for the persona. |
|
|
142
|
+
| `description` | A brief description of the persona. This is optional and helps provide context about the persona's role. Not used by calls to the LLM|
|
|
143
|
+
| `personaPreset`| Defines the face and voice of the persona from a list of available presets. Currently the only available preset is `eva` |
|
|
144
|
+
| `brain` | Configuration for the persona's LLM 'brain' including the system prompt, personality, and filler phrases.|
|
|
145
|
+
|
|
146
|
+
| Brain Parameter | Description |
|
|
147
|
+
| --------------- | ----------------------------------------------------------------------------------------------------- |
|
|
148
|
+
| `systemPrompt` | The prompt used for initializing LLM interactions, setting the context for the persona's behavior. |
|
|
149
|
+
| `personality` | A short description of the persona's character traits which influences the choice of filler phrases. |
|
|
150
|
+
| `fillerPhrases` | Phrases used to enhance interaction response times, providing immediate feedback before a full reply. |
|
|
151
|
+
|
|
152
|
+
Example usage
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
# Example Request
|
|
156
|
+
curl -X POST "https://api.anam.ai/v1/persona" -H "Content-Type: application/json" -H "Authorization: Bearer your-api-key" -d '{
|
|
157
|
+
"name": "Eva",
|
|
158
|
+
"description": "Eva is the virtual receptionist of the Sunset Hotel.",
|
|
159
|
+
"personaPreset": "eva",
|
|
160
|
+
"brain": {
|
|
161
|
+
"systemPrompt": "You are Eva, a virtual receptionist...",
|
|
162
|
+
"personality": "You are role-playing as a text chatbot hotel receptionist at The Sunset Hotel. Your name is Eva.",
|
|
163
|
+
"fillerPhrases": ["One moment please.", "Let me check that for you."]
|
|
164
|
+
}
|
|
165
|
+
}'
|
|
166
|
+
|
|
167
|
+
# Example Response
|
|
168
|
+
{
|
|
169
|
+
"id": "new_persona_id",
|
|
170
|
+
"name": "Eva",
|
|
171
|
+
"description": "Eva is the virtual receptionist of the Sunset Hotel.",
|
|
172
|
+
"personaPreset": "eva",
|
|
173
|
+
"brain": {
|
|
174
|
+
"id": "new_brain_id",
|
|
175
|
+
"personality": "helpful and friendly",
|
|
176
|
+
"systemPrompt": "You are Eva, a virtual receptionist...",
|
|
177
|
+
"fillerPhrases": ["One moment please...", "Let me check that for you..."],
|
|
178
|
+
"createdAt": "2021-01-01T00:00:00Z",
|
|
179
|
+
"updatedAt": "2021-01-02T00:00:00Z"
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
@@ -11,8 +11,8 @@ export default class AnamClient {
|
|
|
11
11
|
constructor(sessionToken: string | undefined, personaConfig: PersonaConfig, options?: AnamClientOptions);
|
|
12
12
|
private startSession;
|
|
13
13
|
private startSessionIfNeeded;
|
|
14
|
-
stream(callbacks?: ConnectionCallbacks,
|
|
15
|
-
streamToVideoAndAudioElements(videoElementId: string, audioElementId: string, callbacks?: ConnectionCallbacks,
|
|
14
|
+
stream(callbacks?: ConnectionCallbacks, userProvidedAudioStream?: MediaStream): Promise<MediaStream[]>;
|
|
15
|
+
streamToVideoAndAudioElements(videoElementId: string, audioElementId: string, callbacks?: ConnectionCallbacks, userProvidedMediaStream?: MediaStream): Promise<void>;
|
|
16
16
|
talk(content: string): Promise<void>;
|
|
17
17
|
sendDataMessage(message: string): void;
|
|
18
18
|
stopStreaming(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnamClient.d.ts","sourceRoot":"","sources":["../../src/AnamClient.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,aAAa,EAEd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE9D,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAErC,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,YAAY,CAAS;gBAG3B,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,aAAa,EAAE,aAAa,EA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namClient.js
CHANGED
|
@@ -24,10 +24,10 @@ class AnamClient {
|
|
|
24
24
|
this.personaConfig = personaConfig;
|
|
25
25
|
this.apiClient = new CoreApiRestClient_1.CoreApiRestClient(sessionToken, options === null || options === void 0 ? void 0 : options.apiKey, options === null || options === void 0 ? void 0 : options.api);
|
|
26
26
|
}
|
|
27
|
-
startSession(
|
|
27
|
+
startSession(userProvidedAudioStream) {
|
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
29
|
try {
|
|
30
|
-
const config =
|
|
30
|
+
const config = this.personaConfig;
|
|
31
31
|
if (!config) {
|
|
32
32
|
throw new Error('A default persona configuration has not been set and no persona configuration was provided');
|
|
33
33
|
}
|
|
@@ -59,12 +59,12 @@ class AnamClient {
|
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
startSessionIfNeeded(
|
|
62
|
+
startSessionIfNeeded(userProvidedMediaStream) {
|
|
63
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
64
|
if (!this.sessionId || !this.streamingClient) {
|
|
65
65
|
console.warn('StreamToVideoAndAudioElements: session is not started. starting a new session');
|
|
66
66
|
try {
|
|
67
|
-
yield this.startSession(
|
|
67
|
+
yield this.startSession(userProvidedMediaStream);
|
|
68
68
|
}
|
|
69
69
|
catch (error) {
|
|
70
70
|
throw new Error('StreamToVideoAndAudioElements: Failed to start session');
|
|
@@ -76,8 +76,8 @@ class AnamClient {
|
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
stream() {
|
|
79
|
-
return __awaiter(this, arguments, void 0, function* (callbacks = {},
|
|
80
|
-
yield this.startSessionIfNeeded(
|
|
79
|
+
return __awaiter(this, arguments, void 0, function* (callbacks = {}, userProvidedAudioStream) {
|
|
80
|
+
yield this.startSessionIfNeeded(userProvidedAudioStream);
|
|
81
81
|
if (this._isStreaming) {
|
|
82
82
|
throw new Error('Already streaming');
|
|
83
83
|
}
|
|
@@ -108,8 +108,8 @@ class AnamClient {
|
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
streamToVideoAndAudioElements(videoElementId_1, audioElementId_1) {
|
|
111
|
-
return __awaiter(this, arguments, void 0, function* (videoElementId, audioElementId, callbacks = {},
|
|
112
|
-
yield this.startSessionIfNeeded(
|
|
111
|
+
return __awaiter(this, arguments, void 0, function* (videoElementId, audioElementId, callbacks = {}, userProvidedMediaStream) {
|
|
112
|
+
yield this.startSessionIfNeeded(userProvidedMediaStream);
|
|
113
113
|
if (this._isStreaming) {
|
|
114
114
|
throw new Error('Already streaming');
|
|
115
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnamClient.js","sourceRoot":"","sources":["../../src/AnamClient.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mEAAgE;AAChE,+DAA4D;AAQ5D,MAAqB,UAAU;IAU7B,YACE,YAAgC,EAChC,aAA4B,EAC5B,OAA2B;QARrB,cAAS,GAAkB,IAAI,CAAC;QAChC,oBAAe,GAA2B,IAAI,CAAC;QAE/C,iBAAY,GAAG,KAAK,CAAC;QAO3B,IAAI,CAAC,YAAY,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAA,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACpE,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC;QAC9B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QAEnC,IAAI,CAAC,SAAS,GAAG,IAAI,qCAAiB,CACpC,YAAY,EACZ,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,EACf,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CACb,CAAC;IACJ,CAAC;IAEa,YAAY,CACxB,
|
|
1
|
+
{"version":3,"file":"AnamClient.js","s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AAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;CACF;AAxMD,6BAwMC"}
|
package/dist/main/index.d.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import AnamClient from './AnamClient';
|
|
2
2
|
import { PersonaConfig } from './types';
|
|
3
3
|
import { AnamPublicClientOptions } from './types/AnamPublicClientOptions';
|
|
4
|
+
/**
|
|
5
|
+
* Create a new Anam client.
|
|
6
|
+
* @param sessionToken - A session token can be obtained from the Anam API.
|
|
7
|
+
* @param personaConfig - The persona configuration to use.
|
|
8
|
+
* @param options - Additional options.
|
|
9
|
+
* @returns A new Anam client instance.
|
|
10
|
+
*/
|
|
4
11
|
declare const createClient: (sessionToken: string, personaConfig: PersonaConfig, options?: AnamPublicClientOptions) => AnamClient;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new Anam client with an API key instead of a session token.
|
|
14
|
+
* This method is unsafe for production environments because it requires exposing your API key to the client side.
|
|
15
|
+
* Only use this method for local testing.
|
|
16
|
+
* @param apiKey - Your Anam API key.
|
|
17
|
+
* @param personaConfig - The persona configuration to use.
|
|
18
|
+
* @param options - Additional options.
|
|
19
|
+
* @returns A new Anam client instance.
|
|
20
|
+
*/
|
|
5
21
|
declare const unsafe_createClientWithApiKey: (apiKey: string, personaConfig: PersonaConfig, options?: AnamPublicClientOptions) => AnamClient;
|
|
6
22
|
export { createClient, unsafe_createClientWithApiKey };
|
|
7
|
-
export type { AnamClient };
|
|
23
|
+
export type { AnamClient, PersonaConfig, AnamPublicClientOptions };
|
|
8
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/main/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,QAAA,MAAM,YAAY,iBACF,MAAM,iBACL,aAAa,YAClB,uBAAuB,KAChC,UAEF,CAAC;AAEF,QAAA,MAAM,6BAA6B,WACzB,MAAM,iBACC,aAAa,YAClB,uBAAuB,KAChC,UAEF,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,6BAA6B,EAAE,CAAC;AACvD,YAAY,EAAE,UAAU,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE1E;;;;;;GAMG;AACH,QAAA,MAAM,YAAY,iBACF,MAAM,iBACL,aAAa,YAClB,uBAAuB,KAChC,UAEF,CAAC;AAEF;;;;;;;;GAQG;AACH,QAAA,MAAM,6BAA6B,WACzB,MAAM,iBACC,aAAa,YAClB,uBAAuB,KAChC,UAEF,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,6BAA6B,EAAE,CAAC;AACvD,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,uBAAuB,EAAE,CAAC"}
|
package/dist/main/index.js
CHANGED
|
@@ -5,10 +5,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.unsafe_createClientWithApiKey = exports.createClient = void 0;
|
|
7
7
|
const AnamClient_1 = __importDefault(require("./AnamClient"));
|
|
8
|
+
/**
|
|
9
|
+
* Create a new Anam client.
|
|
10
|
+
* @param sessionToken - A session token can be obtained from the Anam API.
|
|
11
|
+
* @param personaConfig - The persona configuration to use.
|
|
12
|
+
* @param options - Additional options.
|
|
13
|
+
* @returns A new Anam client instance.
|
|
14
|
+
*/
|
|
8
15
|
const createClient = (sessionToken, personaConfig, options) => {
|
|
9
16
|
return new AnamClient_1.default(sessionToken, personaConfig, options);
|
|
10
17
|
};
|
|
11
18
|
exports.createClient = createClient;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new Anam client with an API key instead of a session token.
|
|
21
|
+
* This method is unsafe for production environments because it requires exposing your API key to the client side.
|
|
22
|
+
* Only use this method for local testing.
|
|
23
|
+
* @param apiKey - Your Anam API key.
|
|
24
|
+
* @param personaConfig - The persona configuration to use.
|
|
25
|
+
* @param options - Additional options.
|
|
26
|
+
* @returns A new Anam client instance.
|
|
27
|
+
*/
|
|
12
28
|
const unsafe_createClientWithApiKey = (apiKey, personaConfig, options) => {
|
|
13
29
|
return new AnamClient_1.default(undefined, personaConfig, Object.assign(Object.assign({}, options), { apiKey }));
|
|
14
30
|
};
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAsC;AAItC,MAAM,YAAY,GAAG,CACnB,YAAoB,EACpB,aAA4B,EAC5B,OAAiC,EACrB,EAAE;IACd,OAAO,IAAI,oBAAU,CAAC,YAAY,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAsC;AAItC;;;;;;GAMG;AACH,MAAM,YAAY,GAAG,CACnB,YAAoB,EACpB,aAA4B,EAC5B,OAAiC,EACrB,EAAE;IACd,OAAO,IAAI,oBAAU,CAAC,YAAY,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC,CAAC;AAmBO,oCAAY;AAjBrB;;;;;;;;GAQG;AACH,MAAM,6BAA6B,GAAG,CACpC,MAAc,EACd,aAA4B,EAC5B,OAAiC,EACrB,EAAE;IACd,OAAO,IAAI,oBAAU,CAAC,SAAS,EAAE,aAAa,kCAAO,OA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,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IAC7C,CAAC;CACF;AAnED,8CAmEC"}
|
|
@@ -11,8 +11,8 @@ export default class AnamClient {
|
|
|
11
11
|
constructor(sessionToken: string | undefined, personaConfig: PersonaConfig, options?: AnamClientOptions);
|
|
12
12
|
private startSession;
|
|
13
13
|
private startSessionIfNeeded;
|
|
14
|
-
stream(callbacks?: ConnectionCallbacks,
|
|
15
|
-
streamToVideoAndAudioElements(videoElementId: string, audioElementId: string, callbacks?: ConnectionCallbacks,
|
|
14
|
+
stream(callbacks?: ConnectionCallbacks, userProvidedAudioStream?: MediaStream): Promise<MediaStream[]>;
|
|
15
|
+
streamToVideoAndAudioElements(videoElementId: string, audioElementId: string, callbacks?: ConnectionCallbacks, userProvidedMediaStream?: MediaStream): Promise<void>;
|
|
16
16
|
talk(content: string): Promise<void>;
|
|
17
17
|
sendDataMessage(message: string): void;
|
|
18
18
|
stopStreaming(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnamClient.d.ts","sourceRoot":"","sources":["../../src/AnamClient.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,aAAa,EAEd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE9D,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAErC,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,YAAY,CAAS;gBAG3B,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,aAAa,EAAE,aAAa,EAC5B,OAAO,CAAC,EAAE,iBAAiB;YAgBf,YAAY;
|
|
1
|
+
{"version":3,"file":"AnamClient.d.ts","sourceRoot":"","sources":["../../src/AnamClient.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,aAAa,EAEd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE9D,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAErC,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,YAAY,CAAS;gBAG3B,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,aAAa,EAAE,aAAa,EAC5B,OAAO,CAAC,EAAE,iBAAiB;YAgBf,YAAY;YAgDZ,oBAAoB;IAoBrB,MAAM,CACjB,SAAS,GAAE,mBAAwB,EACnC,uBAAuB,CAAC,EAAE,WAAW,GACpC,OAAO,CAAC,WAAW,EAAE,CAAC;IAmCZ,6BAA6B,CACxC,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,EACtB,SAAS,GAAE,mBAAwB,EACnC,uBAAuB,CAAC,EAAE,WAAW,GACpC,OAAO,CAAC,IAAI,CAAC;IAiBH,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAe1C,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAQhC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IASpC,WAAW,IAAI,OAAO;IAItB,gBAAgB,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI;IAIpD,gBAAgB,IAAI,aAAa,GAAG,SAAS;CAGrD"}
|
|
@@ -22,10 +22,10 @@ export default class AnamClient {
|
|
|
22
22
|
this.personaConfig = personaConfig;
|
|
23
23
|
this.apiClient = new CoreApiRestClient(sessionToken, options === null || options === void 0 ? void 0 : options.apiKey, options === null || options === void 0 ? void 0 : options.api);
|
|
24
24
|
}
|
|
25
|
-
startSession(
|
|
25
|
+
startSession(userProvidedAudioStream) {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
try {
|
|
28
|
-
const config =
|
|
28
|
+
const config = this.personaConfig;
|
|
29
29
|
if (!config) {
|
|
30
30
|
throw new Error('A default persona configuration has not been set and no persona configuration was provided');
|
|
31
31
|
}
|
|
@@ -57,12 +57,12 @@ export default class AnamClient {
|
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
startSessionIfNeeded(
|
|
60
|
+
startSessionIfNeeded(userProvidedMediaStream) {
|
|
61
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
62
|
if (!this.sessionId || !this.streamingClient) {
|
|
63
63
|
console.warn('StreamToVideoAndAudioElements: session is not started. starting a new session');
|
|
64
64
|
try {
|
|
65
|
-
yield this.startSession(
|
|
65
|
+
yield this.startSession(userProvidedMediaStream);
|
|
66
66
|
}
|
|
67
67
|
catch (error) {
|
|
68
68
|
throw new Error('StreamToVideoAndAudioElements: Failed to start session');
|
|
@@ -74,8 +74,8 @@ export default class AnamClient {
|
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
stream() {
|
|
77
|
-
return __awaiter(this, arguments, void 0, function* (callbacks = {},
|
|
78
|
-
yield this.startSessionIfNeeded(
|
|
77
|
+
return __awaiter(this, arguments, void 0, function* (callbacks = {}, userProvidedAudioStream) {
|
|
78
|
+
yield this.startSessionIfNeeded(userProvidedAudioStream);
|
|
79
79
|
if (this._isStreaming) {
|
|
80
80
|
throw new Error('Already streaming');
|
|
81
81
|
}
|
|
@@ -106,8 +106,8 @@ export default class AnamClient {
|
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
streamToVideoAndAudioElements(videoElementId_1, audioElementId_1) {
|
|
109
|
-
return __awaiter(this, arguments, void 0, function* (videoElementId, audioElementId, callbacks = {},
|
|
110
|
-
yield this.startSessionIfNeeded(
|
|
109
|
+
return __awaiter(this, arguments, void 0, function* (videoElementId, audioElementId, callbacks = {}, userProvidedMediaStream) {
|
|
110
|
+
yield this.startSessionIfNeeded(userProvidedMediaStream);
|
|
111
111
|
if (this._isStreaming) {
|
|
112
112
|
throw new Error('Already streaming');
|
|
113
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnamClient.js","sourceRoot":"","sources":["../../src/AnamClient.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAQ5D,MAAM,CAAC,OAAO,OAAO,UAAU;IAU7B,YACE,YAAgC,EAChC,aAA4B,EAC5B,OAA2B;QARrB,cAAS,GAAkB,IAAI,CAAC;QAChC,oBAAe,GAA2B,IAAI,CAAC;QAE/C,iBAAY,GAAG,KAAK,CAAC;QAO3B,IAAI,CAAC,YAAY,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAA,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACpE,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC;QAC9B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QAEnC,IAAI,CAAC,SAAS,GAAG,IAAI,iBAAiB,CACpC,YAAY,EACZ,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,EACf,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CACb,CAAC;IACJ,CAAC;IAEa,YAAY,CACxB,
|
|
1
|
+
{"version":3,"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AEM,gBAAgB,CAAC,aAA4B;QAClD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAEM,gBAAgB;QACrB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;CACF"}
|
package/dist/module/index.d.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import AnamClient from './AnamClient';
|
|
2
2
|
import { PersonaConfig } from './types';
|
|
3
3
|
import { AnamPublicClientOptions } from './types/AnamPublicClientOptions';
|
|
4
|
+
/**
|
|
5
|
+
* Create a new Anam client.
|
|
6
|
+
* @param sessionToken - A session token can be obtained from the Anam API.
|
|
7
|
+
* @param personaConfig - The persona configuration to use.
|
|
8
|
+
* @param options - Additional options.
|
|
9
|
+
* @returns A new Anam client instance.
|
|
10
|
+
*/
|
|
4
11
|
declare const createClient: (sessionToken: string, personaConfig: PersonaConfig, options?: AnamPublicClientOptions) => AnamClient;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new Anam client with an API key instead of a session token.
|
|
14
|
+
* This method is unsafe for production environments because it requires exposing your API key to the client side.
|
|
15
|
+
* Only use this method for local testing.
|
|
16
|
+
* @param apiKey - Your Anam API key.
|
|
17
|
+
* @param personaConfig - The persona configuration to use.
|
|
18
|
+
* @param options - Additional options.
|
|
19
|
+
* @returns A new Anam client instance.
|
|
20
|
+
*/
|
|
5
21
|
declare const unsafe_createClientWithApiKey: (apiKey: string, personaConfig: PersonaConfig, options?: AnamPublicClientOptions) => AnamClient;
|
|
6
22
|
export { createClient, unsafe_createClientWithApiKey };
|
|
7
|
-
export type { AnamClient };
|
|
23
|
+
export type { AnamClient, PersonaConfig, AnamPublicClientOptions };
|
|
8
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,QAAA,MAAM,YAAY,iBACF,MAAM,iBACL,aAAa,YAClB,uBAAuB,KAChC,UAEF,CAAC;AAEF,QAAA,MAAM,6BAA6B,WACzB,MAAM,iBACC,aAAa,YAClB,uBAAuB,KAChC,UAEF,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,6BAA6B,EAAE,CAAC;AACvD,YAAY,EAAE,UAAU,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE1E;;;;;;GAMG;AACH,QAAA,MAAM,YAAY,iBACF,MAAM,iBACL,aAAa,YAClB,uBAAuB,KAChC,UAEF,CAAC;AAEF;;;;;;;;GAQG;AACH,QAAA,MAAM,6BAA6B,WACzB,MAAM,iBACC,aAAa,YAClB,uBAAuB,KAChC,UAEF,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,6BAA6B,EAAE,CAAC;AACvD,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,uBAAuB,EAAE,CAAC"}
|
package/dist/module/index.js
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import AnamClient from './AnamClient';
|
|
2
|
+
/**
|
|
3
|
+
* Create a new Anam client.
|
|
4
|
+
* @param sessionToken - A session token can be obtained from the Anam API.
|
|
5
|
+
* @param personaConfig - The persona configuration to use.
|
|
6
|
+
* @param options - Additional options.
|
|
7
|
+
* @returns A new Anam client instance.
|
|
8
|
+
*/
|
|
2
9
|
const createClient = (sessionToken, personaConfig, options) => {
|
|
3
10
|
return new AnamClient(sessionToken, personaConfig, options);
|
|
4
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Create a new Anam client with an API key instead of a session token.
|
|
14
|
+
* This method is unsafe for production environments because it requires exposing your API key to the client side.
|
|
15
|
+
* Only use this method for local testing.
|
|
16
|
+
* @param apiKey - Your Anam API key.
|
|
17
|
+
* @param personaConfig - The persona configuration to use.
|
|
18
|
+
* @param options - Additional options.
|
|
19
|
+
* @returns A new Anam client instance.
|
|
20
|
+
*/
|
|
5
21
|
const unsafe_createClientWithApiKey = (apiKey, personaConfig, options) => {
|
|
6
22
|
return new AnamClient(undefined, personaConfig, Object.assign(Object.assign({}, options), { apiKey }));
|
|
7
23
|
};
|
package/dist/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,cAAc,CAAC;AAItC,MAAM,YAAY,GAAG,CACnB,YAAoB,EACpB,aAA4B,EAC5B,OAAiC,EACrB,EAAE;IACd,OAAO,IAAI,UAAU,CAAC,YAAY,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC,CAAC;AAEF,MAAM,6BAA6B,GAAG,CACpC,MAAc,EACd,aAA4B,EAC5B,OAAiC,EACrB,EAAE;IACd,OAAO,IAAI,UAAU,CAAC,SAAS,EAAE,aAAa,kCAAO,OAAO,KAAE,MAAM,IAAG,CAAC;AAC1E,CAAC,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,6BAA6B,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,cAAc,CAAC;AAItC;;;;;;GAMG;AACH,MAAM,YAAY,GAAG,CACnB,YAAoB,EACpB,aAA4B,EAC5B,OAAiC,EACrB,EAAE;IACd,OAAO,IAAI,UAAU,CAAC,YAAY,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC,CAAC;AAEF;;;;;;;;GAQG;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BACF,CAAC,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACnC,OAAO,IAAI,CAAC,YAAY,CAAC;YAC3B,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;KAAA;IAEO,SAAS;QACf,OAAO,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IAC7C,CAAC;CACF"}
|
package/dist/umd/anam.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.anam=t():e.anam=t()}(self,(()=>(()=>{"use strict";var e={816:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,s){function a(e){try{l(i.next(e))}catch(e){s(e)}}function r(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const o=n(18),s=n(577);t.default=class{constructor(e,t,n){if(this.sessionId=null,this.streamingClient=null,this._isStreaming=!1,!e&&!(null==n?void 0:n.apiKey))throw new Error("Either sessionToken or apiKey must be provided");this.sessionToken=e,this.apiKey=null==n?void 0:n.apiKey,this.personaConfig=t,this.apiClient=new o.CoreApiRestClient(e,null==n?void 0:n.apiKey,null==n?void 0:n.api)}startSession(e,t){return i(this,void 0,void 0,(function*(){try{const n=e||this.personaConfig;if(!n)throw new Error("A default persona configuration has not been set and no persona configuration was provided");const i=yield this.apiClient.startSession(n),{sessionId:o,clientConfig:a,engineHost:r,engineProtocol:l,signallingEndpoint:c}=i,{heartbeatIntervalSeconds:d,maxWsReconnectionAttempts:h,iceServers:u}=a;return this.streamingClient=new s.StreamingClient(o,{engine:{baseUrl:`${l}://${r}`},signalling:{heartbeatIntervalSeconds:d,maxWsReconnectionAttempts:h,url:{baseUrl:r,protocol:l,signallingPath:c}},iceServers:u,userProvidedMediaStream:t}),this.sessionId=o,o}catch(e){throw new Error("Failed to start session")}}))}startSessionIfNeeded(e,t){return i(this,void 0,void 0,(function*(){if(!this.sessionId||!this.streamingClient){console.warn("StreamToVideoAndAudioElements: session is not started. starting a new session");try{yield this.startSession(e,t)}catch(e){throw new Error("StreamToVideoAndAudioElements: Failed to start session")}if(!this.sessionId||!this.streamingClient)throw new Error("StreamToVideoAndAudioElements: session Id or streaming client is not available after starting session")}}))}stream(){return i(this,arguments,void 0,(function*(e={},t,n){if(yield this.startSessionIfNeeded(t,n),this._isStreaming)throw new Error("Already streaming");return this._isStreaming=!0,new Promise((t=>{var n,i,o;const s=[];let a=!1,r=!1;null===(n=this.streamingClient)||void 0===n||n.setOnVideoStreamStartCallback((e=>{s.push(e),a=!0,r&&t(s)})),null===(i=this.streamingClient)||void 0===i||i.setOnAudioStreamStartCallback((e=>{s.push(e),r=!0,a&&t(s)})),null===(o=this.streamingClient)||void 0===o||o.startConnection(e)}))}))}streamToVideoAndAudioElements(e,t){return i(this,arguments,void 0,(function*(e,t,n={},i,o){if(yield this.startSessionIfNeeded(i,o),this._isStreaming)throw new Error("Already streaming");if(this._isStreaming=!0,!this.streamingClient)throw new Error("Failed to stream: streaming client is not available");this.streamingClient.setMediaStreamTargetsById(e,t),this.streamingClient.startConnection(n)}))}talk(e){return i(this,void 0,void 0,(function*(){if(!this.streamingClient)throw new Error("Failed to send talk command: session is not started. Have you called startSession?");if(!this._isStreaming)throw new Error("Failed to send talk command: not currently streaming. Have you called stream?");yield this.streamingClient.sendTalkCommand(e)}))}sendDataMessage(e){if(!this.streamingClient)throw new Error("Failed to send message: session is not started.");this.streamingClient.sendDataMessage(e)}stopStreaming(){return i(this,void 0,void 0,(function*(){this.streamingClient&&(this.streamingClient.stopConnection(),this.streamingClient=null,this.sessionId=null,this._isStreaming=!1)}))}isStreaming(){return this._isStreaming}setPersonaConfig(e){this.personaConfig=e}getPersonaConfig(){return this.personaConfig}}},440:function(e,t,n){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.unsafe_createClientWithApiKey=t.createClient=void 0;const o=i(n(816));t.createClient=(e,t,n)=>new o.default(e,t,n),t.unsafe_createClientWithApiKey=(e,t,n)=>new o.default(void 0,t,Object.assign(Object.assign({},n),{apiKey:e}))},985:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DEFAULT_ICE_SERVERS=t.PUBLIC_MESSAGE_ON_WEBRTC_FAILURE=t.PUBLIC_MESSAGE_ON_SIGNALLING_CLIENT_CONNECTION_FAILURE=t.DEFAULT_ENGINE_BASE_URL=t.DEFAULT_API_VERSION=t.DEFAULT_API_BASE_URL=t.DEFAULT_HEADERS=void 0,t.DEFAULT_HEADERS={"Content-Type":"application/json"},t.DEFAULT_API_BASE_URL="https://api.anam.ai",t.DEFAULT_API_VERSION="/v1",t.DEFAULT_ENGINE_BASE_URL="http://localhost:8081",t.PUBLIC_MESSAGE_ON_SIGNALLING_CLIENT_CONNECTION_FAILURE="There was a problem connecting to our servers. Please try again.",t.PUBLIC_MESSAGE_ON_WEBRTC_FAILURE="There was an issue connecting to our servers. Please try again.",t.DEFAULT_ICE_SERVERS=[{urls:"stun:stun.relay.metered.ca:80"}]},18:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,s){function a(e){try{l(i.next(e))}catch(e){s(e)}}function r(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.CoreApiRestClient=void 0;const o=n(985);t.CoreApiRestClient=class{constructor(e,t,n){if(!e&&!t)throw new Error("Either sessionToken or apiKey must be provided");this.sessionToken=e||null,this.apiKey=t||null,this.baseUrl=(null==n?void 0:n.baseUrl)||o.DEFAULT_API_BASE_URL,this.apiVersion=(null==n?void 0:n.apiVersion)||o.DEFAULT_API_VERSION}startSession(e){return i(this,void 0,void 0,(function*(){this.sessionToken||(this.sessionToken=yield this.unsafe_getSessionToken());try{const t=yield fetch(`${this.getApiUrl()}/engine/session`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.sessionToken}`},body:JSON.stringify({personaConfig:e})});return yield t.json()}catch(e){throw new Error("Failed to start session")}}))}unsafe_getSessionToken(){return i(this,void 0,void 0,(function*(){if(console.warn("Using unsecure method. This method should not be used in production."),!this.apiKey)throw new Error("No apiKey provided");try{const e=yield fetch(`${this.getApiUrl()}/auth/session-token`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`}});return(yield e.json()).sessionToken}catch(e){throw new Error("Failed to get session token")}}))}getApiUrl(){return`${this.baseUrl}${this.apiVersion}`}}},529:function(e,t){var n=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,s){function a(e){try{l(i.next(e))}catch(e){s(e)}}function r(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.EngineApiRestClient=void 0,t.EngineApiRestClient=class{constructor(e,t){this.baseUrl=e,this.sessionId=t}sendTalkCommand(e){return n(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrl}/talk?session_id=${this.sessionId}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e})});if(!t.ok)throw new Error(`Failed to send talk command: ${t.status} ${t.statusText}`)}catch(e){throw console.error(e),new Error("EngineApiRestClient - sendTalkCommand: Failed to send talk command")}}))}}},279:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,s){function a(e){try{l(i.next(e))}catch(e){s(e)}}function r(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.SignallingClient=t.DEFATULT_OPTIONS=void 0;const o=n(985),s=n(170);t.DEFATULT_OPTIONS={heartbeatIntervalSeconds:5,maxWsReconnectionAttempts:5,url:{baseUrl:o.DEFAULT_ENGINE_BASE_URL,protocol:"ws"}},t.SignallingClient=class{constructor(e,n=t.DEFATULT_OPTIONS,i,o,s){var a;if(this.stopSignal=!1,this.sendingBuffer=[],this.wsConnectionAttempts=0,this.socket=null,this.heartBeatIntervalRef=null,!e)throw new Error("Signalling Client: sessionId is required");this.sessionId=e,i&&(this.onSignalMessageReceivedCallback=i),o&&(this.onClientConnectedCallback=o),s&&(this.onClientConnectionFailureCallback=s);const{heartbeatIntervalSeconds:r,maxWsReconnectionAttempts:l,url:c}=n;if(this.heartbeatIntervalSeconds=r||5,this.maxWsReconnectionAttempts=l||5,!c.baseUrl)throw new Error("Signalling Client: baseUrl is required");const d=`${c.protocol||"https"}://${c.baseUrl}`;this.url=new URL(d),this.url.protocol="http"===c.protocol?"ws:":"wss:",c.port&&(this.url.port=c.port),this.url.pathname=null!==(a=c.signallingPath)&&void 0!==a?a:"/ws",this.url.searchParams.append("session_id",e)}stop(){this.stopSignal=!0,this.closeSocket()}connect(){return this.socket=new WebSocket(this.url.href),this.socket.onopen=this.onOpen.bind(this),this.socket.onclose=this.onClose.bind(this),this.socket.onerror=this.onError.bind(this),this.socket}sendOffer(e){return i(this,void 0,void 0,(function*(){const t={connectionDescription:e,userUid:this.sessionId},n={actionType:s.SignalMessageAction.OFFER,sessionId:this.sessionId,payload:t};this.sendSignalMessage(n)}))}sendIceCandidate(e){return i(this,void 0,void 0,(function*(){const t={actionType:s.SignalMessageAction.ICE_CANDIDATE,sessionId:this.sessionId,payload:e.toJSON()};this.sendSignalMessage(t)}))}sendSignalMessage(e){var t;if((null===(t=this.socket)||void 0===t?void 0:t.readyState)===WebSocket.OPEN)try{this.socket.send(JSON.stringify(e))}catch(e){console.error("SignallingClient - sendSignalMessage: error sending message",e)}else this.sendingBuffer.push(e)}closeSocket(){this.socket&&(this.socket.close(),this.socket=null),this.heartBeatIntervalRef&&(clearInterval(this.heartBeatIntervalRef),this.heartBeatIntervalRef=null)}onOpen(){return i(this,void 0,void 0,(function*(){if(!this.socket)throw new Error("SignallingClient - onOpen: socket is null");try{this.wsConnectionAttempts=0,this.flushSendingBuffer(),this.socket.onmessage=this.onMessage.bind(this),this.startSendingHeartBeats(),this.onClientConnectedCallback&&(yield this.onClientConnectedCallback())}catch(e){console.error("SignallingClient - onOpen: error in onOpen",e),this.onClientConnectionFailureCallback&&this.onClientConnectionFailureCallback()}}))}onClose(){return i(this,void 0,void 0,(function*(){this.wsConnectionAttempts+=1,this.stopSignal||(this.wsConnectionAttempts<=this.maxWsReconnectionAttempts?(this.socket=null,setTimeout((()=>{this.connect()}),100*this.wsConnectionAttempts)):(this.heartBeatIntervalRef&&(clearInterval(this.heartBeatIntervalRef),this.heartBeatIntervalRef=null),this.onClientConnectionFailureCallback&&this.onClientConnectionFailureCallback()))}))}onError(e){this.stopSignal||console.error("SignallingClient - onError: ",e)}flushSendingBuffer(){const e=[];this.sendingBuffer.length>0&&this.sendingBuffer.forEach((t=>{var n;(null===(n=this.socket)||void 0===n?void 0:n.readyState)===WebSocket.OPEN?this.socket.send(JSON.stringify(t)):e.push(t)})),this.sendingBuffer=e}onMessage(e){return i(this,void 0,void 0,(function*(){const t=JSON.parse(e.data);this.onSignalMessageReceivedCallback&&(yield this.onSignalMessageReceivedCallback(t))}))}startSendingHeartBeats(){if(!this.socket)throw new Error("SignallingClient - startSendingHeartBeats: socket is null");this.heartBeatIntervalRef&&console.warn("SignallingClient - startSendingHeartBeats: heartbeat interval already set");const e=1e3*this.heartbeatIntervalSeconds,t={actionType:s.SignalMessageAction.HEARTBEAT,sessionId:this.sessionId,payload:""},n=JSON.stringify(t);this.heartBeatIntervalRef=setInterval((()=>{var e;this.stopSignal||(null===(e=this.socket)||void 0===e?void 0:e.readyState)===WebSocket.OPEN&&this.socket.send(n)}),e)}}},577:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,s){function a(e){try{l(i.next(e))}catch(e){s(e)}}function r(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.StreamingClient=void 0;const o=n(985),s=n(295),a=n(529),r=n(279),l={engine:{baseUrl:o.DEFAULT_ENGINE_BASE_URL},signalling:r.DEFATULT_OPTIONS,iceServers:o.DEFAULT_ICE_SERVERS};t.StreamingClient=class{constructor(e,t=l){this.iceServers=o.DEFAULT_ICE_SERVERS,this.peerConnection=null,this.connectionReceivedAnswer=!1,this.remoteIceCandidateBuffer=[],this.inputAudioStream=null,this.dataChannel=null,this.videoElement=null,this.videoStream=null,this.audioElement=null,this.audioStream=null,this.iceServers=t.iceServers||o.DEFAULT_ICE_SERVERS,this.signallingClient=new r.SignallingClient(e,t.signalling,this.onSignalMessage.bind(this),this.onSignallingClientConnected.bind(this),this.onSignallingClientFailed.bind(this)),this.engineApiRestClient=new a.EngineApiRestClient(t.engine.baseUrl,e),t.userProvidedMediaStream&&(this.inputAudioStream=t.userProvidedMediaStream)}getPeerConnection(){return this.peerConnection}getInputAudioStream(){return this.inputAudioStream}getVideoStream(){return this.videoStream}getAudioStream(){return this.audioStream}setOnVideoStreamStartCallback(e){this.onVideoStreamStartCallback=e}setOnAudioStreamStartCallback(e){this.onAudioStreamStartCallback=e}sendDataMessage(e){this.dataChannel&&"open"===this.dataChannel.readyState&&this.dataChannel.send(e)}setMediaStreamTargetsById(e,t){if(e){const t=document.getElementById(e);if(!t)throw new Error(`StreamingClient: video element with id ${e} not found`);this.videoElement=t}if(t){const e=document.getElementById(t);if(!e)throw new Error(`StreamingClient: audio element with id ${t} not found`);this.audioElement=e}}startConnection(e){try{if(this.peerConnection)return void console.error("StreamingClient - startConnection: peer connection already exists");this.setConnectionCallbacks(e),this.signallingClient.connect()}catch(e){this.handleWebrtcFailure(e)}}stopConnection(){this.shutdown()}sendTalkCommand(e){return i(this,void 0,void 0,(function*(){if(!this.peerConnection)throw new Error("StreamingClient - sendTalkCommand: peer connection is null");yield this.engineApiRestClient.sendTalkCommand(e)}))}setConnectionCallbacks({onReceiveMessageCallback:e,onConnectionEstablishedCallback:t,onConnectionClosedCallback:n,onInputAudioStreamStartCallback:i,onVideoStreamStartCallback:o,onVideoPlayStartedCallback:s,onAudioStreamStartCallback:a}){e&&(this.onReceiveMessageCallback=e),t&&(this.onConnectionEstablishedCallback=t),n&&(this.onConnectionClosedCallback=n),i&&(this.onInputAudioStreamStartCallback=i),o&&(this.onVideoStreamStartCallback=o),s&&(this.onVideoPlayStartedCallback=s),a&&(this.onAudioStreamStartCallback=a)}initPeerConnection(){return i(this,void 0,void 0,(function*(){this.peerConnection=new RTCPeerConnection({iceServers:this.iceServers}),this.peerConnection.onicecandidate=this.onIceCandidate.bind(this),this.peerConnection.oniceconnectionstatechange=this.onIceConnectionStateChange.bind(this),this.peerConnection.onconnectionstatechange=this.onConnectionStateChange.bind(this),this.peerConnection.addEventListener("track",this.onTrackEventHandler.bind(this)),yield this.setupDataChannels(),this.peerConnection.addTransceiver("video",{direction:"recvonly"}),this.peerConnection.addTransceiver("audio",{direction:"sendrecv"})}))}onSignalMessage(e){return i(this,void 0,void 0,(function*(){if(this.peerConnection)switch(e.actionType){case s.SignalMessageAction.ANSWER:const t=e.payload;yield this.peerConnection.setRemoteDescription(t),this.connectionReceivedAnswer=!0,this.flushRemoteIceCandidateBuffer();break;case s.SignalMessageAction.ICE_CANDIDATE:const n=e.payload,i=new RTCIceCandidate(n);this.connectionReceivedAnswer?yield this.peerConnection.addIceCandidate(i):this.remoteIceCandidateBuffer.push(i);break;case s.SignalMessageAction.END_SESSION:const o=e.payload;this.onConnectionClosedCallback&&this.onConnectionClosedCallback(o),this.shutdown();break;case s.SignalMessageAction.WARNING:const a=e.payload;console.warn("Warning received from server: "+a);break;default:console.error("StreamingClient - onSignalMessage: unknown signal message action type",e)}else console.error("StreamingClient - onSignalMessage: peerConnection is not initialized")}))}onSignallingClientConnected(){return i(this,void 0,void 0,(function*(){if(!this.peerConnection)try{yield this.initPeerConnectionAndSendOffer()}catch(e){console.error("StreamingClient - onSignallingClientConnected: Error initializing peer connection",e),this.handleWebrtcFailure(e)}}))}onSignallingClientFailed(){console.error("StreamingClient - onSignallingClientFailed: signalling client failed"),this.onConnectionClosedCallback&&this.onConnectionClosedCallback(o.PUBLIC_MESSAGE_ON_SIGNALLING_CLIENT_CONNECTION_FAILURE)}flushRemoteIceCandidateBuffer(){this.remoteIceCandidateBuffer.forEach((e=>{var t;null===(t=this.peerConnection)||void 0===t||t.addIceCandidate(e)})),this.remoteIceCandidateBuffer=[]}onIceCandidate(e){e.candidate&&this.signallingClient.sendIceCandidate(e.candidate)}onIceConnectionStateChange(){var e,t;"connected"!==(null===(e=this.peerConnection)||void 0===e?void 0:e.iceConnectionState)&&"completed"!==(null===(t=this.peerConnection)||void 0===t?void 0:t.iceConnectionState)||this.onConnectionEstablishedCallback&&this.onConnectionEstablishedCallback()}onConnectionStateChange(){var e;"closed"===(null===(e=this.peerConnection)||void 0===e?void 0:e.connectionState)&&(console.error("StreamingClient - onConnectionStateChange: Connection closed"),this.handleWebrtcFailure("The connection to our servers was lost. Please try again."))}handleWebrtcFailure(e){console.error("StreamingClient - handleWebrtcFailure: ",e);try{this.stopConnection()}catch(e){console.error("StreamingClient - handleWebrtcFailure: error stopping connection",e)}this.onConnectionClosedCallback&&this.onConnectionClosedCallback(o.PUBLIC_MESSAGE_ON_WEBRTC_FAILURE)}onTrackEventHandler(e){if("video"===e.track.kind){if(this.videoStream=e.streams[0],this.onVideoStreamStartCallback&&this.onVideoStreamStartCallback(this.videoStream),this.videoElement){this.videoElement.srcObject=this.videoStream;const e=this.videoElement.requestVideoFrameCallback((()=>{var t;null===(t=this.videoElement)||void 0===t||t.cancelVideoFrameCallback(e),this.onVideoPlayStartedCallback&&this.onVideoPlayStartedCallback()}))}}else"audio"===e.track.kind&&(this.audioStream=e.streams[0],this.onAudioStreamStartCallback&&this.onAudioStreamStartCallback(this.audioStream),this.audioElement&&(this.audioElement.srcObject=this.audioStream))}setupDataChannels(){return i(this,void 0,void 0,(function*(){if(!this.peerConnection)return void console.error("StreamingClient - setupDataChannels: peer connection is not initialized");if(this.inputAudioStream){if(!this.inputAudioStream.getAudioTracks().length)throw new Error("StreamingClient - setupDataChannels: user provided stream does not have audio tracks")}else this.inputAudioStream=yield navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0}});const e=this.inputAudioStream.getAudioTracks()[0];this.peerConnection.addTrack(e,this.inputAudioStream),this.onInputAudioStreamStartCallback&&this.onInputAudioStreamStartCallback(this.inputAudioStream);const t=this.peerConnection.createDataChannel("chat",{ordered:!0});t.onopen=()=>{this.dataChannel=null!=t?t:null},t.onclose=()=>{},t.onmessage=e=>{this.onReceiveMessageCallback&&this.onReceiveMessageCallback(JSON.parse(e.data))}}))}initPeerConnectionAndSendOffer(){return i(this,void 0,void 0,(function*(){if(yield this.initPeerConnection(),!this.peerConnection)return void console.error("StreamingClient - initPeerConnectionAndSendOffer: peer connection is not initialized");const e=yield this.peerConnection.createOffer();if(yield this.peerConnection.setLocalDescription(e),!this.peerConnection.localDescription)throw new Error("StreamingClient - initPeerConnectionAndSendOffer: local description is null");yield this.signallingClient.sendOffer(this.peerConnection.localDescription)}))}shutdown(){try{this.inputAudioStream&&this.inputAudioStream.getTracks().forEach((e=>{e.stop()})),this.inputAudioStream=null}catch(e){console.error("StreamingClient - shutdown: error stopping input audio stream",e)}try{this.signallingClient.stop()}catch(e){console.error("StreamingClient - shutdown: error stopping signallilng",e)}try{this.peerConnection&&"closed"!==this.peerConnection.connectionState&&(this.peerConnection.onconnectionstatechange=null,this.peerConnection.close(),this.peerConnection=null)}catch(e){console.error("StreamingClient - shutdown: error closing peer connection",e)}}}},170:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SignalMessageAction=void 0;var i=n(295);Object.defineProperty(t,"SignalMessageAction",{enumerable:!0,get:function(){return i.SignalMessageAction}})},656:(e,t)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.SignalMessageAction=void 0,function(e){e.OFFER="offer",e.ANSWER="answer",e.ICE_CANDIDATE="icecandidate",e.END_SESSION="endsession",e.HEARTBEAT="heartbeat",e.WARNING="warning"}(n||(t.SignalMessageAction=n={}))},295:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SignalMessageAction=void 0;var i=n(656);Object.defineProperty(t,"SignalMessageAction",{enumerable:!0,get:function(){return i.SignalMessageAction}})}},t={};return function n(i){var o=t[i];if(void 0!==o)return o.exports;var s=t[i]={exports:{}};return e[i].call(s.exports,s,s.exports,n),s.exports}(440)})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.anam=t():e.anam=t()}(self,(()=>(()=>{"use strict";var e={816:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,s){function a(e){try{l(i.next(e))}catch(e){s(e)}}function r(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const o=n(18),s=n(577);t.default=class{constructor(e,t,n){if(this.sessionId=null,this.streamingClient=null,this._isStreaming=!1,!e&&!(null==n?void 0:n.apiKey))throw new Error("Either sessionToken or apiKey must be provided");this.sessionToken=e,this.apiKey=null==n?void 0:n.apiKey,this.personaConfig=t,this.apiClient=new o.CoreApiRestClient(e,null==n?void 0:n.apiKey,null==n?void 0:n.api)}startSession(e){return i(this,void 0,void 0,(function*(){try{const t=this.personaConfig;if(!t)throw new Error("A default persona configuration has not been set and no persona configuration was provided");const n=yield this.apiClient.startSession(t),{sessionId:i,clientConfig:o,engineHost:a,engineProtocol:r,signallingEndpoint:l}=n,{heartbeatIntervalSeconds:c,maxWsReconnectionAttempts:d,iceServers:h}=o;return this.streamingClient=new s.StreamingClient(i,{engine:{baseUrl:`${r}://${a}`},signalling:{heartbeatIntervalSeconds:c,maxWsReconnectionAttempts:d,url:{baseUrl:a,protocol:r,signallingPath:l}},iceServers:h,userProvidedMediaStream:e}),this.sessionId=i,i}catch(e){throw new Error("Failed to start session")}}))}startSessionIfNeeded(e){return i(this,void 0,void 0,(function*(){if(!this.sessionId||!this.streamingClient){console.warn("StreamToVideoAndAudioElements: session is not started. starting a new session");try{yield this.startSession(e)}catch(e){throw new Error("StreamToVideoAndAudioElements: Failed to start session")}if(!this.sessionId||!this.streamingClient)throw new Error("StreamToVideoAndAudioElements: session Id or streaming client is not available after starting session")}}))}stream(){return i(this,arguments,void 0,(function*(e={},t){if(yield this.startSessionIfNeeded(t),this._isStreaming)throw new Error("Already streaming");return this._isStreaming=!0,new Promise((t=>{var n,i,o;const s=[];let a=!1,r=!1;null===(n=this.streamingClient)||void 0===n||n.setOnVideoStreamStartCallback((e=>{s.push(e),a=!0,r&&t(s)})),null===(i=this.streamingClient)||void 0===i||i.setOnAudioStreamStartCallback((e=>{s.push(e),r=!0,a&&t(s)})),null===(o=this.streamingClient)||void 0===o||o.startConnection(e)}))}))}streamToVideoAndAudioElements(e,t){return i(this,arguments,void 0,(function*(e,t,n={},i){if(yield this.startSessionIfNeeded(i),this._isStreaming)throw new Error("Already streaming");if(this._isStreaming=!0,!this.streamingClient)throw new Error("Failed to stream: streaming client is not available");this.streamingClient.setMediaStreamTargetsById(e,t),this.streamingClient.startConnection(n)}))}talk(e){return i(this,void 0,void 0,(function*(){if(!this.streamingClient)throw new Error("Failed to send talk command: session is not started. Have you called startSession?");if(!this._isStreaming)throw new Error("Failed to send talk command: not currently streaming. Have you called stream?");yield this.streamingClient.sendTalkCommand(e)}))}sendDataMessage(e){if(!this.streamingClient)throw new Error("Failed to send message: session is not started.");this.streamingClient.sendDataMessage(e)}stopStreaming(){return i(this,void 0,void 0,(function*(){this.streamingClient&&(this.streamingClient.stopConnection(),this.streamingClient=null,this.sessionId=null,this._isStreaming=!1)}))}isStreaming(){return this._isStreaming}setPersonaConfig(e){this.personaConfig=e}getPersonaConfig(){return this.personaConfig}}},440:function(e,t,n){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.unsafe_createClientWithApiKey=t.createClient=void 0;const o=i(n(816));t.createClient=(e,t,n)=>new o.default(e,t,n),t.unsafe_createClientWithApiKey=(e,t,n)=>new o.default(void 0,t,Object.assign(Object.assign({},n),{apiKey:e}))},985:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DEFAULT_ICE_SERVERS=t.PUBLIC_MESSAGE_ON_WEBRTC_FAILURE=t.PUBLIC_MESSAGE_ON_SIGNALLING_CLIENT_CONNECTION_FAILURE=t.DEFAULT_ENGINE_BASE_URL=t.DEFAULT_API_VERSION=t.DEFAULT_API_BASE_URL=t.DEFAULT_HEADERS=void 0,t.DEFAULT_HEADERS={"Content-Type":"application/json"},t.DEFAULT_API_BASE_URL="https://api.anam.ai",t.DEFAULT_API_VERSION="/v1",t.DEFAULT_ENGINE_BASE_URL="http://localhost:8081",t.PUBLIC_MESSAGE_ON_SIGNALLING_CLIENT_CONNECTION_FAILURE="There was a problem connecting to our servers. Please try again.",t.PUBLIC_MESSAGE_ON_WEBRTC_FAILURE="There was an issue connecting to our servers. Please try again.",t.DEFAULT_ICE_SERVERS=[{urls:"stun:stun.relay.metered.ca:80"}]},18:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,s){function a(e){try{l(i.next(e))}catch(e){s(e)}}function r(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.CoreApiRestClient=void 0;const o=n(985);t.CoreApiRestClient=class{constructor(e,t,n){if(!e&&!t)throw new Error("Either sessionToken or apiKey must be provided");this.sessionToken=e||null,this.apiKey=t||null,this.baseUrl=(null==n?void 0:n.baseUrl)||o.DEFAULT_API_BASE_URL,this.apiVersion=(null==n?void 0:n.apiVersion)||o.DEFAULT_API_VERSION}startSession(e){return i(this,void 0,void 0,(function*(){this.sessionToken||(this.sessionToken=yield this.unsafe_getSessionToken());try{const t=yield fetch(`${this.getApiUrl()}/engine/session`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.sessionToken}`},body:JSON.stringify({personaConfig:e})});return yield t.json()}catch(e){throw new Error("Failed to start session")}}))}unsafe_getSessionToken(){return i(this,void 0,void 0,(function*(){if(console.warn("Using unsecure method. This method should not be used in production."),!this.apiKey)throw new Error("No apiKey provided");try{const e=yield fetch(`${this.getApiUrl()}/auth/session-token`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`}});return(yield e.json()).sessionToken}catch(e){throw new Error("Failed to get session token")}}))}getApiUrl(){return`${this.baseUrl}${this.apiVersion}`}}},529:function(e,t){var n=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,s){function a(e){try{l(i.next(e))}catch(e){s(e)}}function r(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.EngineApiRestClient=void 0,t.EngineApiRestClient=class{constructor(e,t){this.baseUrl=e,this.sessionId=t}sendTalkCommand(e){return n(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrl}/talk?session_id=${this.sessionId}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e})});if(!t.ok)throw new Error(`Failed to send talk command: ${t.status} ${t.statusText}`)}catch(e){throw console.error(e),new Error("EngineApiRestClient - sendTalkCommand: Failed to send talk command")}}))}}},279:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,s){function a(e){try{l(i.next(e))}catch(e){s(e)}}function r(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.SignallingClient=t.DEFATULT_OPTIONS=void 0;const o=n(985),s=n(170);t.DEFATULT_OPTIONS={heartbeatIntervalSeconds:5,maxWsReconnectionAttempts:5,url:{baseUrl:o.DEFAULT_ENGINE_BASE_URL,protocol:"ws"}},t.SignallingClient=class{constructor(e,n=t.DEFATULT_OPTIONS,i,o,s){var a;if(this.stopSignal=!1,this.sendingBuffer=[],this.wsConnectionAttempts=0,this.socket=null,this.heartBeatIntervalRef=null,!e)throw new Error("Signalling Client: sessionId is required");this.sessionId=e,i&&(this.onSignalMessageReceivedCallback=i),o&&(this.onClientConnectedCallback=o),s&&(this.onClientConnectionFailureCallback=s);const{heartbeatIntervalSeconds:r,maxWsReconnectionAttempts:l,url:c}=n;if(this.heartbeatIntervalSeconds=r||5,this.maxWsReconnectionAttempts=l||5,!c.baseUrl)throw new Error("Signalling Client: baseUrl is required");const d=`${c.protocol||"https"}://${c.baseUrl}`;this.url=new URL(d),this.url.protocol="http"===c.protocol?"ws:":"wss:",c.port&&(this.url.port=c.port),this.url.pathname=null!==(a=c.signallingPath)&&void 0!==a?a:"/ws",this.url.searchParams.append("session_id",e)}stop(){this.stopSignal=!0,this.closeSocket()}connect(){return this.socket=new WebSocket(this.url.href),this.socket.onopen=this.onOpen.bind(this),this.socket.onclose=this.onClose.bind(this),this.socket.onerror=this.onError.bind(this),this.socket}sendOffer(e){return i(this,void 0,void 0,(function*(){const t={connectionDescription:e,userUid:this.sessionId},n={actionType:s.SignalMessageAction.OFFER,sessionId:this.sessionId,payload:t};this.sendSignalMessage(n)}))}sendIceCandidate(e){return i(this,void 0,void 0,(function*(){const t={actionType:s.SignalMessageAction.ICE_CANDIDATE,sessionId:this.sessionId,payload:e.toJSON()};this.sendSignalMessage(t)}))}sendSignalMessage(e){var t;if((null===(t=this.socket)||void 0===t?void 0:t.readyState)===WebSocket.OPEN)try{this.socket.send(JSON.stringify(e))}catch(e){console.error("SignallingClient - sendSignalMessage: error sending message",e)}else this.sendingBuffer.push(e)}closeSocket(){this.socket&&(this.socket.close(),this.socket=null),this.heartBeatIntervalRef&&(clearInterval(this.heartBeatIntervalRef),this.heartBeatIntervalRef=null)}onOpen(){return i(this,void 0,void 0,(function*(){if(!this.socket)throw new Error("SignallingClient - onOpen: socket is null");try{this.wsConnectionAttempts=0,this.flushSendingBuffer(),this.socket.onmessage=this.onMessage.bind(this),this.startSendingHeartBeats(),this.onClientConnectedCallback&&(yield this.onClientConnectedCallback())}catch(e){console.error("SignallingClient - onOpen: error in onOpen",e),this.onClientConnectionFailureCallback&&this.onClientConnectionFailureCallback()}}))}onClose(){return i(this,void 0,void 0,(function*(){this.wsConnectionAttempts+=1,this.stopSignal||(this.wsConnectionAttempts<=this.maxWsReconnectionAttempts?(this.socket=null,setTimeout((()=>{this.connect()}),100*this.wsConnectionAttempts)):(this.heartBeatIntervalRef&&(clearInterval(this.heartBeatIntervalRef),this.heartBeatIntervalRef=null),this.onClientConnectionFailureCallback&&this.onClientConnectionFailureCallback()))}))}onError(e){this.stopSignal||console.error("SignallingClient - onError: ",e)}flushSendingBuffer(){const e=[];this.sendingBuffer.length>0&&this.sendingBuffer.forEach((t=>{var n;(null===(n=this.socket)||void 0===n?void 0:n.readyState)===WebSocket.OPEN?this.socket.send(JSON.stringify(t)):e.push(t)})),this.sendingBuffer=e}onMessage(e){return i(this,void 0,void 0,(function*(){const t=JSON.parse(e.data);this.onSignalMessageReceivedCallback&&(yield this.onSignalMessageReceivedCallback(t))}))}startSendingHeartBeats(){if(!this.socket)throw new Error("SignallingClient - startSendingHeartBeats: socket is null");this.heartBeatIntervalRef&&console.warn("SignallingClient - startSendingHeartBeats: heartbeat interval already set");const e=1e3*this.heartbeatIntervalSeconds,t={actionType:s.SignalMessageAction.HEARTBEAT,sessionId:this.sessionId,payload:""},n=JSON.stringify(t);this.heartBeatIntervalRef=setInterval((()=>{var e;this.stopSignal||(null===(e=this.socket)||void 0===e?void 0:e.readyState)===WebSocket.OPEN&&this.socket.send(n)}),e)}}},577:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,s){function a(e){try{l(i.next(e))}catch(e){s(e)}}function r(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.StreamingClient=void 0;const o=n(985),s=n(295),a=n(529),r=n(279),l={engine:{baseUrl:o.DEFAULT_ENGINE_BASE_URL},signalling:r.DEFATULT_OPTIONS,iceServers:o.DEFAULT_ICE_SERVERS};t.StreamingClient=class{constructor(e,t=l){this.iceServers=o.DEFAULT_ICE_SERVERS,this.peerConnection=null,this.connectionReceivedAnswer=!1,this.remoteIceCandidateBuffer=[],this.inputAudioStream=null,this.dataChannel=null,this.videoElement=null,this.videoStream=null,this.audioElement=null,this.audioStream=null,this.iceServers=t.iceServers||o.DEFAULT_ICE_SERVERS,this.signallingClient=new r.SignallingClient(e,t.signalling,this.onSignalMessage.bind(this),this.onSignallingClientConnected.bind(this),this.onSignallingClientFailed.bind(this)),this.engineApiRestClient=new a.EngineApiRestClient(t.engine.baseUrl,e),t.userProvidedMediaStream&&(this.inputAudioStream=t.userProvidedMediaStream)}getPeerConnection(){return this.peerConnection}getInputAudioStream(){return this.inputAudioStream}getVideoStream(){return this.videoStream}getAudioStream(){return this.audioStream}setOnVideoStreamStartCallback(e){this.onVideoStreamStartCallback=e}setOnAudioStreamStartCallback(e){this.onAudioStreamStartCallback=e}sendDataMessage(e){this.dataChannel&&"open"===this.dataChannel.readyState&&this.dataChannel.send(e)}setMediaStreamTargetsById(e,t){if(e){const t=document.getElementById(e);if(!t)throw new Error(`StreamingClient: video element with id ${e} not found`);this.videoElement=t}if(t){const e=document.getElementById(t);if(!e)throw new Error(`StreamingClient: audio element with id ${t} not found`);this.audioElement=e}}startConnection(e){try{if(this.peerConnection)return void console.error("StreamingClient - startConnection: peer connection already exists");this.setConnectionCallbacks(e),this.signallingClient.connect()}catch(e){this.handleWebrtcFailure(e)}}stopConnection(){this.shutdown()}sendTalkCommand(e){return i(this,void 0,void 0,(function*(){if(!this.peerConnection)throw new Error("StreamingClient - sendTalkCommand: peer connection is null");yield this.engineApiRestClient.sendTalkCommand(e)}))}setConnectionCallbacks({onReceiveMessageCallback:e,onConnectionEstablishedCallback:t,onConnectionClosedCallback:n,onInputAudioStreamStartCallback:i,onVideoStreamStartCallback:o,onVideoPlayStartedCallback:s,onAudioStreamStartCallback:a}){e&&(this.onReceiveMessageCallback=e),t&&(this.onConnectionEstablishedCallback=t),n&&(this.onConnectionClosedCallback=n),i&&(this.onInputAudioStreamStartCallback=i),o&&(this.onVideoStreamStartCallback=o),s&&(this.onVideoPlayStartedCallback=s),a&&(this.onAudioStreamStartCallback=a)}initPeerConnection(){return i(this,void 0,void 0,(function*(){this.peerConnection=new RTCPeerConnection({iceServers:this.iceServers}),this.peerConnection.onicecandidate=this.onIceCandidate.bind(this),this.peerConnection.oniceconnectionstatechange=this.onIceConnectionStateChange.bind(this),this.peerConnection.onconnectionstatechange=this.onConnectionStateChange.bind(this),this.peerConnection.addEventListener("track",this.onTrackEventHandler.bind(this)),yield this.setupDataChannels(),this.peerConnection.addTransceiver("video",{direction:"recvonly"}),this.peerConnection.addTransceiver("audio",{direction:"sendrecv"})}))}onSignalMessage(e){return i(this,void 0,void 0,(function*(){if(this.peerConnection)switch(e.actionType){case s.SignalMessageAction.ANSWER:const t=e.payload;yield this.peerConnection.setRemoteDescription(t),this.connectionReceivedAnswer=!0,this.flushRemoteIceCandidateBuffer();break;case s.SignalMessageAction.ICE_CANDIDATE:const n=e.payload,i=new RTCIceCandidate(n);this.connectionReceivedAnswer?yield this.peerConnection.addIceCandidate(i):this.remoteIceCandidateBuffer.push(i);break;case s.SignalMessageAction.END_SESSION:const o=e.payload;this.onConnectionClosedCallback&&this.onConnectionClosedCallback(o),this.shutdown();break;case s.SignalMessageAction.WARNING:const a=e.payload;console.warn("Warning received from server: "+a);break;default:console.error("StreamingClient - onSignalMessage: unknown signal message action type",e)}else console.error("StreamingClient - onSignalMessage: peerConnection is not initialized")}))}onSignallingClientConnected(){return i(this,void 0,void 0,(function*(){if(!this.peerConnection)try{yield this.initPeerConnectionAndSendOffer()}catch(e){console.error("StreamingClient - onSignallingClientConnected: Error initializing peer connection",e),this.handleWebrtcFailure(e)}}))}onSignallingClientFailed(){console.error("StreamingClient - onSignallingClientFailed: signalling client failed"),this.onConnectionClosedCallback&&this.onConnectionClosedCallback(o.PUBLIC_MESSAGE_ON_SIGNALLING_CLIENT_CONNECTION_FAILURE)}flushRemoteIceCandidateBuffer(){this.remoteIceCandidateBuffer.forEach((e=>{var t;null===(t=this.peerConnection)||void 0===t||t.addIceCandidate(e)})),this.remoteIceCandidateBuffer=[]}onIceCandidate(e){e.candidate&&this.signallingClient.sendIceCandidate(e.candidate)}onIceConnectionStateChange(){var e,t;"connected"!==(null===(e=this.peerConnection)||void 0===e?void 0:e.iceConnectionState)&&"completed"!==(null===(t=this.peerConnection)||void 0===t?void 0:t.iceConnectionState)||this.onConnectionEstablishedCallback&&this.onConnectionEstablishedCallback()}onConnectionStateChange(){var e;"closed"===(null===(e=this.peerConnection)||void 0===e?void 0:e.connectionState)&&(console.error("StreamingClient - onConnectionStateChange: Connection closed"),this.handleWebrtcFailure("The connection to our servers was lost. Please try again."))}handleWebrtcFailure(e){console.error("StreamingClient - handleWebrtcFailure: ",e);try{this.stopConnection()}catch(e){console.error("StreamingClient - handleWebrtcFailure: error stopping connection",e)}this.onConnectionClosedCallback&&this.onConnectionClosedCallback(o.PUBLIC_MESSAGE_ON_WEBRTC_FAILURE)}onTrackEventHandler(e){if("video"===e.track.kind){if(this.videoStream=e.streams[0],this.onVideoStreamStartCallback&&this.onVideoStreamStartCallback(this.videoStream),this.videoElement){this.videoElement.srcObject=this.videoStream;const e=this.videoElement.requestVideoFrameCallback((()=>{var t;null===(t=this.videoElement)||void 0===t||t.cancelVideoFrameCallback(e),this.onVideoPlayStartedCallback&&this.onVideoPlayStartedCallback()}))}}else"audio"===e.track.kind&&(this.audioStream=e.streams[0],this.onAudioStreamStartCallback&&this.onAudioStreamStartCallback(this.audioStream),this.audioElement&&(this.audioElement.srcObject=this.audioStream))}setupDataChannels(){return i(this,void 0,void 0,(function*(){if(!this.peerConnection)return void console.error("StreamingClient - setupDataChannels: peer connection is not initialized");if(this.inputAudioStream){if(!this.inputAudioStream.getAudioTracks().length)throw new Error("StreamingClient - setupDataChannels: user provided stream does not have audio tracks")}else this.inputAudioStream=yield navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0}});const e=this.inputAudioStream.getAudioTracks()[0];this.peerConnection.addTrack(e,this.inputAudioStream),this.onInputAudioStreamStartCallback&&this.onInputAudioStreamStartCallback(this.inputAudioStream);const t=this.peerConnection.createDataChannel("chat",{ordered:!0});t.onopen=()=>{this.dataChannel=null!=t?t:null},t.onclose=()=>{},t.onmessage=e=>{this.onReceiveMessageCallback&&this.onReceiveMessageCallback(JSON.parse(e.data))}}))}initPeerConnectionAndSendOffer(){return i(this,void 0,void 0,(function*(){if(yield this.initPeerConnection(),!this.peerConnection)return void console.error("StreamingClient - initPeerConnectionAndSendOffer: peer connection is not initialized");const e=yield this.peerConnection.createOffer();if(yield this.peerConnection.setLocalDescription(e),!this.peerConnection.localDescription)throw new Error("StreamingClient - initPeerConnectionAndSendOffer: local description is null");yield this.signallingClient.sendOffer(this.peerConnection.localDescription)}))}shutdown(){try{this.inputAudioStream&&this.inputAudioStream.getTracks().forEach((e=>{e.stop()})),this.inputAudioStream=null}catch(e){console.error("StreamingClient - shutdown: error stopping input audio stream",e)}try{this.signallingClient.stop()}catch(e){console.error("StreamingClient - shutdown: error stopping signallilng",e)}try{this.peerConnection&&"closed"!==this.peerConnection.connectionState&&(this.peerConnection.onconnectionstatechange=null,this.peerConnection.close(),this.peerConnection=null)}catch(e){console.error("StreamingClient - shutdown: error closing peer connection",e)}}}},170:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SignalMessageAction=void 0;var i=n(295);Object.defineProperty(t,"SignalMessageAction",{enumerable:!0,get:function(){return i.SignalMessageAction}})},656:(e,t)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.SignalMessageAction=void 0,function(e){e.OFFER="offer",e.ANSWER="answer",e.ICE_CANDIDATE="icecandidate",e.END_SESSION="endsession",e.HEARTBEAT="heartbeat",e.WARNING="warning"}(n||(t.SignalMessageAction=n={}))},295:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SignalMessageAction=void 0;var i=n(656);Object.defineProperty(t,"SignalMessageAction",{enumerable:!0,get:function(){return i.SignalMessageAction}})}},t={};return function n(i){var o=t[i];if(void 0!==o)return o.exports;var s=t[i]={exports:{}};return e[i].call(s.exports,s,s.exports,n),s.exports}(440)})()));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anam-ai/js-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-alpha.2",
|
|
4
4
|
"description": "Client side JavaScript SDK for Anam AI",
|
|
5
5
|
"author": "Anam AI",
|
|
6
6
|
"main": "dist/main/index.js",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"homepage": "https://github.com/anam-org/javascript-sdk#readme",
|
|
32
32
|
"scripts": {
|
|
33
33
|
"clean": "rimraf dist",
|
|
34
|
+
"docs": "typedoc",
|
|
34
35
|
"build": "run-s clean format build:*",
|
|
35
36
|
"build:main": "tsc -p tsconfig.json",
|
|
36
37
|
"build:module": "tsc -p tsconfig.module.json",
|
|
@@ -58,6 +59,8 @@
|
|
|
58
59
|
"pretty-quick": "^4.0.0",
|
|
59
60
|
"rimraf": "^5.0.7",
|
|
60
61
|
"ts-loader": "^9.5.1",
|
|
62
|
+
"typedoc": "^0.25.13",
|
|
63
|
+
"typedoc-material-theme": "^1.0.2",
|
|
61
64
|
"typescript": "^5.4.5",
|
|
62
65
|
"typescript-eslint": "^7.9.0",
|
|
63
66
|
"webpack": "^5.91.0",
|