valenceai 0.4.0 → 0.5.0
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/CHANGELOG.md +52 -2
- package/README.md +135 -49
- package/package.json +1 -1
- package/src/client.js +1 -1
- package/src/config.js +2 -2
- package/tests/asyncAudio.test.js +2 -2
- package/tests/client.test.js +1 -1
- package/tests/config.test.js +5 -5
- package/tests/discreteAudio.test.js +1 -1
- package/tests/setup.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,56 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.5.0] - 2025-06-23
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Enhanced API Compatibility**: JavaScript SDK now matches Python SDK's v0.5.0 feature set
|
|
12
|
+
- **Improved Upload Robustness**: Enhanced error handling and retry logic for async uploads
|
|
13
|
+
- **Sequential Upload Strategy**: Maintains reliable upload performance with proper error recovery
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- **Version Alignment**: Updated to v0.5.0 to maintain feature parity with Python SDK
|
|
17
|
+
- **Consistent Documentation**: Updated examples and usage patterns to match Python SDK
|
|
18
|
+
- **Unified User Experience**: Ensures identical functionality across both language implementations
|
|
19
|
+
|
|
20
|
+
### Technical Improvements
|
|
21
|
+
- **Cross-Platform Consistency**: JavaScript SDK maintains same API patterns as Python SDK
|
|
22
|
+
- **Reliable Upload Process**: Sequential part uploads with comprehensive error handling
|
|
23
|
+
- **Maintained Performance**: Optimized upload strategy for JavaScript environment
|
|
24
|
+
|
|
25
|
+
### Documentation
|
|
26
|
+
- **Updated Examples**: Aligned with Python SDK documentation patterns
|
|
27
|
+
- **Consistent Naming**: Maintained unified terminology across both SDKs
|
|
28
|
+
- **Enhanced Guides**: Improved usage examples for better developer experience
|
|
29
|
+
|
|
30
|
+
### Notes
|
|
31
|
+
- **No Breaking Changes**: All existing functionality preserved
|
|
32
|
+
- **Feature Parity**: JavaScript SDK maintains equivalent capabilities to Python SDK
|
|
33
|
+
- **Semantic Versioning**: Version bump reflects alignment with Python SDK capabilities
|
|
34
|
+
|
|
35
|
+
## [0.4.1] - 2025-06-18
|
|
36
|
+
|
|
37
|
+
### Changed
|
|
38
|
+
- **BREAKING**: Environment variable renamed: `VALENCE_ASYNC_URL` → `VALENCE_ASYNCH_URL` for consistency with `asynch` client naming
|
|
39
|
+
|
|
40
|
+
### Technical Improvements
|
|
41
|
+
- **Consistent naming standard** across client API and environment variables
|
|
42
|
+
- **All test suites updated** to use new environment variable name
|
|
43
|
+
- **Documentation updated** across all README and configuration files
|
|
44
|
+
- **User-Agent string updated** to use `valenceai/0.4.1` branding
|
|
45
|
+
|
|
46
|
+
### Migration Guide
|
|
47
|
+
```javascript
|
|
48
|
+
// Environment variable change
|
|
49
|
+
// Old: VALENCE_ASYNC_URL=https://...
|
|
50
|
+
// New: VALENCE_ASYNCH_URL=https://...
|
|
51
|
+
|
|
52
|
+
// All other functionality remains identical
|
|
53
|
+
import { ValenceClient } from 'valenceai';
|
|
54
|
+
const client = new ValenceClient();
|
|
55
|
+
const requestId = await client.asynch.upload('audio.wav'); // Uses VALENCE_ASYNCH_URL
|
|
56
|
+
```
|
|
57
|
+
|
|
8
58
|
## [0.4.0] - 2025-06-18
|
|
9
59
|
|
|
10
60
|
### Changed
|
|
@@ -12,7 +62,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
12
62
|
- **BREAKING**: Installation command: `npm install valenceai` (was `npm install valence-sdk`)
|
|
13
63
|
- **BREAKING**: Import statement: `import { ValenceClient } from 'valenceai'` (was `'valence-sdk'`)
|
|
14
64
|
- **Package description updated** to reflect new unified naming
|
|
15
|
-
- **User-Agent string updated** to use `valenceai
|
|
65
|
+
- **User-Agent string updated** to use `valenceai` branding
|
|
16
66
|
- **Updated example files** to use new package import syntax
|
|
17
67
|
|
|
18
68
|
### Technical Improvements
|
|
@@ -59,7 +109,7 @@ const result = await client.discrete.emotions('audio.wav', '7emotions');
|
|
|
59
109
|
- **BREAKING**: `getEmotions()` → `client.asynch.emotions()`
|
|
60
110
|
- **BREAKING**: Environment variable names updated for consistency:
|
|
61
111
|
- `VALENCE_SHORT_URL` → `VALENCE_DISCRETE_URL`
|
|
62
|
-
- `VALENCE_LONG_URL` → `
|
|
112
|
+
- `VALENCE_LONG_URL` → `VALENCE_ASYNCH_URL`
|
|
63
113
|
- **Import pattern**: `import { ValenceClient } from 'valenceai'` (single import)
|
|
64
114
|
- **Parameter naming**: `maxTries` → `maxAttempts`, `intervalMs` → `intervalSeconds`
|
|
65
115
|
- **Examples updated** to use new unified client structure
|
package/README.md
CHANGED
|
@@ -1,33 +1,56 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Valence SDK for Emotion Detection (JavaScript)
|
|
2
2
|
|
|
3
3
|
**valenceai** is a Node.js SDK for interacting with the [Valence Vibrations](https://valencevibrations.com) Emotion Detection API. It provides full support for uploading discrete and async audio files to retrieve their emotional signatures.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
- 🔒 **Security focused** - Input validation and secure error handling
|
|
7
|
+
- **Discrete audio processing** - Single API call for short audio files
|
|
8
|
+
- **Asynch audio processing** - Multipart streaming for long audio files
|
|
9
|
+
- **Environment configuration** - Built-in support for `.env` configuration
|
|
10
|
+
- **Enhanced logging** - Configurable log levels with timestamps
|
|
11
|
+
- **Robust error handling** - Comprehensive validation and error recovery
|
|
12
|
+
- **TypeScript ready** - Full JSDoc documentation for all functions
|
|
13
|
+
- **100% tested** - Comprehensive test suite with 95%+ coverage
|
|
14
|
+
- **Security focused** - Input validation and secure error handling
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
The emotional classification model used in our APIs is optimized for North American English conversational data.
|
|
17
|
+
|
|
18
|
+
The API includes a baseline model of 4 basic emotions. The emotions included by default are angry, happy, neutral, and sad. Our other model offerings include different subsets of the following emotions: happy, sad, angry, neutral, surprised, disgusted, nervous, irritated, excited, sleepy.
|
|
19
|
+
|
|
20
|
+
_Coming soon_ – The API will include a model choice parameter, allowing users to choose between models of 4, 5, and 7 emotions.
|
|
21
|
+
|
|
22
|
+
The number of emotions, emotional buckets, and language support can be customized. If you are interested in a custom model, please [contact us](https://www.getvalenceai.com/contact).
|
|
23
|
+
|
|
24
|
+
## API Functionality
|
|
25
|
+
|
|
26
|
+
While our APIs include the same model offerings in the backend, they are best suited for different purposes.
|
|
27
|
+
|
|
28
|
+
| | DiscreteAPI | AsynchAPI |
|
|
29
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
30
|
+
| Inputs | A short audio file, 4-10s in length. | A long audio file, at least 5s in length. Inputs can be up to 1 GB large. |
|
|
31
|
+
| Outputs | A JSON that includes the primary emotion detected in the file, along with its confidence. Optionally, the confidence scores of all other emotions in the model can be returned. | A time-stamped JSON that includes the classified emotion and its confidence at a rate of 1 classification per 5 seconds of audio. |
|
|
32
|
+
| Response Time | 100-500 ms | Dependent upon file size |
|
|
33
|
+
|
|
34
|
+
The **DiscreteAPI** is built for real-time analysis of emotions in audio data. Small snippets of audio are sent to the API to receive feedback in real-time of what emotions are detected based on tone of voice. This API operates on an approximate per-sentence basis, and audio must be cut to the appropriate size.
|
|
35
|
+
|
|
36
|
+
The **AsynchAPI** is built for emotion analysis of pre-recorded audio files. Files of any length, up to 1 GB in size, can be sent to the API to receive a summary of emotions throughout the file. Similar to the DiscreteAPI, this API operates on an approximate per-sentence basis, but the AsyncAPI provides timestamps to show the change in emotions over time.
|
|
37
|
+
|
|
38
|
+
_Coming soon_ – StreamingAPI via WebSockets for real-time analysis of an audio stream.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
18
41
|
|
|
19
42
|
```bash
|
|
20
43
|
npm install valenceai
|
|
21
44
|
```
|
|
22
45
|
|
|
23
|
-
##
|
|
46
|
+
## Configuration
|
|
24
47
|
|
|
25
48
|
Create a `.env` file in your project root:
|
|
26
49
|
|
|
27
50
|
```env
|
|
28
51
|
VALENCE_API_KEY=your_api_key # Required: Your Valence API key
|
|
29
52
|
VALENCE_DISCRETE_URL=https://discrete-api-url # Optional: Discrete audio endpoint
|
|
30
|
-
|
|
53
|
+
VALENCE_ASYNCH_URL=https://async-api-url # Optional: Asynch audio endpoint
|
|
31
54
|
VALENCE_LOG_LEVEL=info # Optional: debug, info, warn, error
|
|
32
55
|
```
|
|
33
56
|
|
|
@@ -44,7 +67,7 @@ try {
|
|
|
44
67
|
}
|
|
45
68
|
```
|
|
46
69
|
|
|
47
|
-
##
|
|
70
|
+
## Usage
|
|
48
71
|
|
|
49
72
|
### Discrete Audio (Short Files)
|
|
50
73
|
|
|
@@ -53,14 +76,14 @@ import { ValenceClient } from 'valenceai';
|
|
|
53
76
|
|
|
54
77
|
try {
|
|
55
78
|
const client = new ValenceClient();
|
|
56
|
-
const result = await client.discrete.emotions('
|
|
57
|
-
console.log('
|
|
79
|
+
const result = await client.discrete.emotions('YOUR_FILE.wav');
|
|
80
|
+
console.log('Emotion detected:', result);
|
|
58
81
|
} catch (error) {
|
|
59
82
|
console.error('Error:', error.message);
|
|
60
83
|
}
|
|
61
84
|
```
|
|
62
85
|
|
|
63
|
-
###
|
|
86
|
+
### Asynch Audio (Long Files)
|
|
64
87
|
|
|
65
88
|
```js
|
|
66
89
|
import { ValenceClient } from 'valenceai';
|
|
@@ -69,7 +92,7 @@ try {
|
|
|
69
92
|
const client = new ValenceClient();
|
|
70
93
|
|
|
71
94
|
// Upload the audio file
|
|
72
|
-
const requestId = await client.asynch.upload('
|
|
95
|
+
const requestId = await client.asynch.upload('YOUR_FILE.wav');
|
|
73
96
|
console.log('Upload complete. Request ID:', requestId);
|
|
74
97
|
|
|
75
98
|
// Get emotions from uploaded audio
|
|
@@ -102,25 +125,24 @@ const emotions = await client.asynch.emotions(
|
|
|
102
125
|
);
|
|
103
126
|
```
|
|
104
127
|
|
|
105
|
-
##
|
|
128
|
+
## API Reference
|
|
106
129
|
|
|
107
130
|
### `new ValenceClient(partSize?, maxRetries?)`
|
|
108
131
|
|
|
109
132
|
Creates a new Valence client with nested discrete and asynch clients.
|
|
110
133
|
|
|
111
134
|
**Parameters:**
|
|
112
|
-
- `partSize` (number, optional): Size of each part in bytes for
|
|
113
|
-
- `maxRetries` (number, optional): Maximum retry attempts for
|
|
135
|
+
- `partSize` (number, optional): Size of each part in bytes for asynch uploads (default: 5MB)
|
|
136
|
+
- `maxRetries` (number, optional): Maximum retry attempts for asynch uploads (default: 3)
|
|
114
137
|
|
|
115
138
|
**Returns:** `ValenceClient` instance with `discrete` and `asynch` properties
|
|
116
139
|
|
|
117
|
-
### `client.discrete.emotions(filePath
|
|
140
|
+
### `client.discrete.emotions(filePath)`
|
|
118
141
|
|
|
119
142
|
Predicts emotions for discrete (short) audio files using a single API call.
|
|
120
143
|
|
|
121
144
|
**Parameters:**
|
|
122
145
|
- `filePath` (string): Path to the audio file
|
|
123
|
-
- `model` (string, optional): `"4emotions"` or `"7emotions"` (default: `"4emotions"`)
|
|
124
146
|
|
|
125
147
|
**Returns:** `Promise<Object>` - Emotion prediction results
|
|
126
148
|
|
|
@@ -128,7 +150,7 @@ Predicts emotions for discrete (short) audio files using a single API call.
|
|
|
128
150
|
|
|
129
151
|
### `client.asynch.upload(filePath)`
|
|
130
152
|
|
|
131
|
-
Uploads
|
|
153
|
+
Uploads asynch (long) audio files using multipart upload for processing.
|
|
132
154
|
|
|
133
155
|
**Parameters:**
|
|
134
156
|
- `filePath` (string): Path to the audio file
|
|
@@ -146,9 +168,9 @@ Retrieves emotion prediction results for async audio processing.
|
|
|
146
168
|
- `maxAttempts` (number, optional): Maximum polling attempts (default: 20, range: 1-100)
|
|
147
169
|
- `intervalSeconds` (number, optional): Polling interval in seconds (default: 5, range: 1-60)
|
|
148
170
|
|
|
149
|
-
**Returns:** `Promise<Object>` - Emotion
|
|
171
|
+
**Returns:** `Promise<Object>` - Emotion detection results
|
|
150
172
|
|
|
151
|
-
**Throws:** Error if requestId is invalid or
|
|
173
|
+
**Throws:** Error if requestId is invalid or detection times out
|
|
152
174
|
|
|
153
175
|
### `validateConfig()`
|
|
154
176
|
|
|
@@ -156,7 +178,71 @@ Validates the current SDK configuration.
|
|
|
156
178
|
|
|
157
179
|
**Throws:** Error if required configuration is missing or invalid
|
|
158
180
|
|
|
159
|
-
##
|
|
181
|
+
## Inputs and Outputs
|
|
182
|
+
|
|
183
|
+
### Inputs
|
|
184
|
+
The APIs expect mono audio in the .wav format. An ideal audio file is recorded at 44100 Hz (44.1 kHz), though sampling rates as low as 8 kHz can still be used with high accuracy. For custom use cases, microphone specifications can be customized based on audio environment, including optimizations for mono/stereo audio, single microphone applications, noisy environments, etc.
|
|
185
|
+
|
|
186
|
+
For the **DiscreteAPI**, input data is an audio file in the .wav format.
|
|
187
|
+
|
|
188
|
+
For the **AsynchAPI**, input data is an audio file, in the .wav format.
|
|
189
|
+
|
|
190
|
+
### Outputs
|
|
191
|
+
|
|
192
|
+
Outputs are returned as JSONs in the following formats:
|
|
193
|
+
|
|
194
|
+
**DiscreteAPI:**
|
|
195
|
+
|
|
196
|
+
```json
|
|
197
|
+
{
|
|
198
|
+
"main_emotion": "happy",
|
|
199
|
+
"confidence": 0.777777777,
|
|
200
|
+
"all_predictions": {
|
|
201
|
+
"angry": 0.123456789,
|
|
202
|
+
"happy": 0.777777777,
|
|
203
|
+
"neutral": 0.23456789,
|
|
204
|
+
"sad": 0.098765432
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The emotion returned in `main_emotion` is the highest confidence emotion returned from the model. Within `all_predictions`, each emotion is followed by its level of confidence. Some may use the top two highest confidence emotions to generate more nuanced states. We recommend dropping a `main_emotion` with confidence under 0.38, but that is at the user's discretion.
|
|
210
|
+
|
|
211
|
+
**AsynchAPI:**
|
|
212
|
+
|
|
213
|
+
```json
|
|
214
|
+
{
|
|
215
|
+
"request_id": "27a33189-bdd7-47ca-9817-abacfb7bdaf3",
|
|
216
|
+
"status": "completed",
|
|
217
|
+
"emotions": [
|
|
218
|
+
{
|
|
219
|
+
"t": "00:00",
|
|
220
|
+
"emotion": "neutral",
|
|
221
|
+
"confidence": 0.82791723
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"t": "00:05",
|
|
225
|
+
"emotion": "neutral",
|
|
226
|
+
"confidence": 0.719817432
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"t": "00:10",
|
|
230
|
+
"emotion": "happy",
|
|
231
|
+
"confidence": 0.917309381
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"t": "00:15",
|
|
235
|
+
"emotion": "neutral",
|
|
236
|
+
"confidence": 0.414097846
|
|
237
|
+
}
|
|
238
|
+
"..."
|
|
239
|
+
]
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
The emotions returned in `emotions` are the highest confidence emotion returned from the model, alongside the timestamp and confidence. The number of values in `emotions` correlates directly to the length of the input file. We recommend dropping `emotions` with confidence under 0.38, but that is at the user's discretion.
|
|
244
|
+
|
|
245
|
+
## Examples
|
|
160
246
|
|
|
161
247
|
Run the included examples:
|
|
162
248
|
|
|
@@ -167,15 +253,15 @@ npm install
|
|
|
167
253
|
# Run discrete audio example
|
|
168
254
|
npm run example:discrete
|
|
169
255
|
|
|
170
|
-
# Run
|
|
171
|
-
npm run example:
|
|
256
|
+
# Run asynch audio example
|
|
257
|
+
npm run example:asynch
|
|
172
258
|
|
|
173
259
|
# Or run directly
|
|
174
260
|
node examples/uploadShort.js
|
|
175
261
|
node examples/uploadLong.js
|
|
176
262
|
```
|
|
177
263
|
|
|
178
|
-
##
|
|
264
|
+
## Development
|
|
179
265
|
|
|
180
266
|
### Testing
|
|
181
267
|
|
|
@@ -201,25 +287,25 @@ npm login
|
|
|
201
287
|
npm publish --access public
|
|
202
288
|
```
|
|
203
289
|
|
|
204
|
-
##
|
|
290
|
+
## What's New in v0.3.0
|
|
205
291
|
|
|
206
292
|
### Major Changes
|
|
207
|
-
-
|
|
208
|
-
-
|
|
209
|
-
-
|
|
210
|
-
-
|
|
211
|
-
-
|
|
293
|
+
- **Unified Client Architecture** - Single `ValenceClient` with nested `discrete` and `asynch` clients
|
|
294
|
+
- **API Restructure**: `predictDiscreteAudioEmotion()` → `client.discrete.emotions()`
|
|
295
|
+
- **API Restructure**: `uploadAsyncAudio()` → `client.asynch.upload()`
|
|
296
|
+
- **API Restructure**: `getEmotions()` → `client.asynch.emotions()`
|
|
297
|
+
- **Single Import**: `import { ValenceClient } from 'valenceai'`
|
|
212
298
|
|
|
213
299
|
### Benefits
|
|
214
|
-
-
|
|
215
|
-
-
|
|
216
|
-
-
|
|
217
|
-
-
|
|
218
|
-
-
|
|
300
|
+
- **API Symmetry** - Identical structure to Python SDK
|
|
301
|
+
- **Intuitive Organization** - Related methods grouped together
|
|
302
|
+
- **Consistent Naming** - Same method names across Python and JavaScript
|
|
303
|
+
- **Enhanced Documentation** - Updated examples and migration guide
|
|
304
|
+
- **Maintained Quality** - All existing functionality preserved
|
|
219
305
|
|
|
220
306
|
See [CHANGELOG.md](./CHANGELOG.md) for complete details and migration guide.
|
|
221
307
|
|
|
222
|
-
##
|
|
308
|
+
## Contributing
|
|
223
309
|
|
|
224
310
|
We welcome contributions! Please:
|
|
225
311
|
|
|
@@ -229,12 +315,12 @@ We welcome contributions! Please:
|
|
|
229
315
|
4. Ensure all tests pass: `npm test`
|
|
230
316
|
5. Submit a pull request
|
|
231
317
|
|
|
232
|
-
##
|
|
318
|
+
## Support
|
|
233
319
|
|
|
234
|
-
-
|
|
235
|
-
-
|
|
236
|
-
-
|
|
320
|
+
- **Documentation**: See [API Reference](#api-reference) above
|
|
321
|
+
- **Issues**: [GitHub Issues](https://github.com/valencevibrations/valence-sdk-js/issues)
|
|
322
|
+
- **Questions**: Contact [Valence AI](https://getvalenceai.com)
|
|
237
323
|
|
|
238
|
-
##
|
|
324
|
+
## License
|
|
239
325
|
|
|
240
|
-
|
|
326
|
+
Private License © 2025 [Valence Vibrations, Inc](https://getvalenceai.com), a Delaware public benefit corporation.
|
package/package.json
CHANGED
package/src/client.js
CHANGED
package/src/config.js
CHANGED
|
@@ -8,7 +8,7 @@ dotenv.config();
|
|
|
8
8
|
export const config = {
|
|
9
9
|
apiKey: process.env.VALENCE_API_KEY,
|
|
10
10
|
discreteAudioUrl: process.env.VALENCE_DISCRETE_URL || 'https://xc8n2bo4f0.execute-api.us-west-2.amazonaws.com/emotionprediction',
|
|
11
|
-
asyncAudioUrl: process.env.
|
|
11
|
+
asyncAudioUrl: process.env.VALENCE_ASYNCH_URL || 'https://wsgol61783.execute-api.us-west-2.amazonaws.com/prod',
|
|
12
12
|
logLevel: process.env.VALENCE_LOG_LEVEL || 'info',
|
|
13
13
|
};
|
|
14
14
|
|
|
@@ -26,7 +26,7 @@ export function validateConfig() {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
if (!config.asyncAudioUrl || !config.asyncAudioUrl.startsWith('https://')) {
|
|
29
|
-
throw new Error('
|
|
29
|
+
throw new Error('VALENCE_ASYNCH_URL must be a valid HTTPS URL');
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const validLogLevels = ['debug', 'info', 'warn', 'error'];
|
package/tests/asyncAudio.test.js
CHANGED
|
@@ -10,7 +10,7 @@ describe('AsyncAudio', () => {
|
|
|
10
10
|
beforeEach(() => {
|
|
11
11
|
process.env = { ...originalEnv };
|
|
12
12
|
process.env.VALENCE_API_KEY = 'test-api-key';
|
|
13
|
-
process.env.
|
|
13
|
+
process.env.VALENCE_ASYNCH_URL = 'https://test-api.com';
|
|
14
14
|
|
|
15
15
|
fsMock = jest.spyOn(fs, 'existsSync');
|
|
16
16
|
statMock = jest.spyOn(fs, 'statSync');
|
|
@@ -318,7 +318,7 @@ describe('AsyncAudio', () => {
|
|
|
318
318
|
const scope = nock('https://test-api.com')
|
|
319
319
|
.get('/prediction')
|
|
320
320
|
.matchHeader('x-api-key', 'test-api-key')
|
|
321
|
-
.matchHeader('User-Agent', 'valenceai/0.4.
|
|
321
|
+
.matchHeader('User-Agent', 'valenceai/0.4.1')
|
|
322
322
|
.query({ request_id: 'req-123' })
|
|
323
323
|
.reply(200, { emotions: {} });
|
|
324
324
|
|
package/tests/client.test.js
CHANGED
package/tests/config.test.js
CHANGED
|
@@ -16,7 +16,7 @@ describe('Config', () => {
|
|
|
16
16
|
test('should load from environment variables', async () => {
|
|
17
17
|
process.env.VALENCE_API_KEY = 'test-key';
|
|
18
18
|
process.env.VALENCE_DISCRETE_URL = 'https://test-short.com';
|
|
19
|
-
process.env.
|
|
19
|
+
process.env.VALENCE_ASYNCH_URL = 'https://test-long.com';
|
|
20
20
|
process.env.VALENCE_LOG_LEVEL = 'debug';
|
|
21
21
|
|
|
22
22
|
// Re-import to get fresh config
|
|
@@ -31,7 +31,7 @@ describe('Config', () => {
|
|
|
31
31
|
test('should use default URLs when not provided', async () => {
|
|
32
32
|
process.env.VALENCE_API_KEY = 'test-key';
|
|
33
33
|
delete process.env.VALENCE_DISCRETE_URL;
|
|
34
|
-
delete process.env.
|
|
34
|
+
delete process.env.VALENCE_ASYNCH_URL;
|
|
35
35
|
|
|
36
36
|
// Re-import to get fresh config
|
|
37
37
|
const { config: freshConfig } = await import('../src/config.js?' + Math.random());
|
|
@@ -54,7 +54,7 @@ describe('Config', () => {
|
|
|
54
54
|
test('should pass with valid configuration', () => {
|
|
55
55
|
process.env.VALENCE_API_KEY = 'test-key';
|
|
56
56
|
process.env.VALENCE_DISCRETE_URL = 'https://test-short.com';
|
|
57
|
-
process.env.
|
|
57
|
+
process.env.VALENCE_ASYNCH_URL = 'https://test-long.com';
|
|
58
58
|
process.env.VALENCE_LOG_LEVEL = 'info';
|
|
59
59
|
|
|
60
60
|
expect(() => validateConfig()).not.toThrow();
|
|
@@ -75,9 +75,9 @@ describe('Config', () => {
|
|
|
75
75
|
|
|
76
76
|
test('should throw when long URL is not HTTPS', async () => {
|
|
77
77
|
process.env.VALENCE_API_KEY = 'test-key';
|
|
78
|
-
process.env.
|
|
78
|
+
process.env.VALENCE_ASYNCH_URL = 'http://test-long.com';
|
|
79
79
|
const { validateConfig: freshValidateConfig } = await import('../src/config.js?' + Math.random());
|
|
80
|
-
expect(() => freshValidateConfig()).toThrow('
|
|
80
|
+
expect(() => freshValidateConfig()).toThrow('VALENCE_ASYNCH_URL must be a valid HTTPS URL');
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
test('should throw with invalid log level', async () => {
|
|
@@ -156,7 +156,7 @@ describe('DiscreteAudio', () => {
|
|
|
156
156
|
const scope = nock('https://test-api.com')
|
|
157
157
|
.post('/predict?model=4emotions')
|
|
158
158
|
.matchHeader('x-api-key', 'test-api-key')
|
|
159
|
-
.matchHeader('User-Agent', 'valenceai/0.4.
|
|
159
|
+
.matchHeader('User-Agent', 'valenceai/0.4.1')
|
|
160
160
|
.reply(200, { emotions: {} });
|
|
161
161
|
|
|
162
162
|
const client = new ValenceClient();
|
package/tests/setup.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Test setup file to configure environment
|
|
2
2
|
process.env.VALENCE_API_KEY = 'test-api-key-12345';
|
|
3
3
|
process.env.VALENCE_DISCRETE_URL = 'https://test-short.com';
|
|
4
|
-
process.env.
|
|
4
|
+
process.env.VALENCE_ASYNCH_URL = 'https://test-long.com';
|
|
5
5
|
process.env.VALENCE_LOG_LEVEL = 'debug';
|