@cartesia/cartesia-js 3.0.0-b11 → 3.0.0-b12
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 +9 -0
- package/backcompat/errors.d.mts +1 -1
- package/backcompat/errors.d.mts.map +1 -1
- package/backcompat/errors.d.ts +1 -1
- package/backcompat/errors.d.ts.map +1 -1
- package/backcompat/errors.js +1 -1
- package/backcompat/errors.js.map +1 -1
- package/backcompat/errors.mjs +1 -1
- package/backcompat/errors.mjs.map +1 -1
- package/backcompat/index.d.mts.map +1 -1
- package/backcompat/index.d.ts.map +1 -1
- package/backcompat/index.js +5 -5
- package/backcompat/index.js.map +1 -1
- package/backcompat/index.mjs +5 -5
- package/backcompat/index.mjs.map +1 -1
- package/backcompat/tts-wrapper.d.mts +33 -10
- package/backcompat/tts-wrapper.d.mts.map +1 -1
- package/backcompat/tts-wrapper.d.ts +33 -10
- package/backcompat/tts-wrapper.d.ts.map +1 -1
- package/backcompat/tts-wrapper.js +83 -26
- package/backcompat/tts-wrapper.js.map +1 -1
- package/backcompat/tts-wrapper.mjs +85 -28
- package/backcompat/tts-wrapper.mjs.map +1 -1
- package/backcompat/types.d.mts +1 -1
- package/backcompat/types.d.mts.map +1 -1
- package/backcompat/types.d.ts +1 -1
- package/backcompat/types.d.ts.map +1 -1
- package/backcompat/voice-changer-wrapper.d.mts +4 -4
- package/backcompat/voice-changer-wrapper.d.mts.map +1 -1
- package/backcompat/voice-changer-wrapper.d.ts +4 -4
- package/backcompat/voice-changer-wrapper.d.ts.map +1 -1
- package/backcompat/voice-changer-wrapper.js +6 -6
- package/backcompat/voice-changer-wrapper.js.map +1 -1
- package/backcompat/voice-changer-wrapper.mjs +7 -7
- package/backcompat/voice-changer-wrapper.mjs.map +1 -1
- package/backcompat/voices-wrapper.d.mts +18 -5
- package/backcompat/voices-wrapper.d.mts.map +1 -1
- package/backcompat/voices-wrapper.d.ts +18 -5
- package/backcompat/voices-wrapper.d.ts.map +1 -1
- package/backcompat/voices-wrapper.js +63 -0
- package/backcompat/voices-wrapper.js.map +1 -1
- package/backcompat/voices-wrapper.mjs +63 -0
- package/backcompat/voices-wrapper.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/agents/agents.d.mts +4 -4
- package/resources/agents/agents.d.mts.map +1 -1
- package/resources/agents/agents.d.ts +4 -4
- package/resources/agents/agents.d.ts.map +1 -1
- package/resources/agents/agents.js +9 -9
- package/resources/agents/agents.js.map +1 -1
- package/resources/agents/agents.mjs +9 -9
- package/resources/agents/agents.mjs.map +1 -1
- package/resources/agents/calls.d.mts +1 -1
- package/resources/agents/calls.d.mts.map +1 -1
- package/resources/agents/calls.d.ts +1 -1
- package/resources/agents/calls.d.ts.map +1 -1
- package/resources/agents/calls.js +1 -2
- package/resources/agents/calls.js.map +1 -1
- package/resources/agents/calls.mjs +1 -2
- package/resources/agents/calls.mjs.map +1 -1
- package/resources/datasets/datasets.d.mts +3 -3
- package/resources/datasets/datasets.d.mts.map +1 -1
- package/resources/datasets/datasets.d.ts +3 -3
- package/resources/datasets/datasets.d.ts.map +1 -1
- package/resources/datasets/datasets.js +1 -1
- package/resources/datasets/datasets.mjs +1 -1
- package/resources/datasets/files.d.mts +3 -3
- package/resources/datasets/files.d.ts +3 -3
- package/resources/datasets/files.js +1 -1
- package/resources/datasets/files.mjs +1 -1
- package/resources/datasets/index.d.mts +1 -1
- package/resources/datasets/index.d.ts +1 -1
- package/resources/infill.d.mts +1 -1
- package/resources/infill.d.mts.map +1 -1
- package/resources/infill.d.ts +1 -1
- package/resources/infill.d.ts.map +1 -1
- package/resources/infill.js +1 -6
- package/resources/infill.js.map +1 -1
- package/resources/infill.mjs +1 -6
- package/resources/infill.mjs.map +1 -1
- package/resources/pronunciation-dicts.d.mts +1 -1
- package/resources/pronunciation-dicts.d.ts +1 -1
- package/resources/pronunciation-dicts.js +1 -1
- package/resources/pronunciation-dicts.mjs +1 -1
- package/resources/voice-changer.d.mts +1 -1
- package/resources/voice-changer.d.mts.map +1 -1
- package/resources/voice-changer.d.ts +1 -1
- package/resources/voice-changer.d.ts.map +1 -1
- package/resources/voice-changer.js +1 -6
- package/resources/voice-changer.js.map +1 -1
- package/resources/voice-changer.mjs +1 -6
- package/resources/voice-changer.mjs.map +1 -1
- package/resources/voices.d.mts +9 -9
- package/resources/voices.d.mts.map +1 -1
- package/resources/voices.d.ts +9 -9
- package/resources/voices.d.ts.map +1 -1
- package/resources/voices.js +14 -14
- package/resources/voices.js.map +1 -1
- package/resources/voices.mjs +14 -14
- package/resources/voices.mjs.map +1 -1
- package/src/backcompat/errors.ts +32 -40
- package/src/backcompat/index.ts +64 -67
- package/src/backcompat/tts-wrapper.ts +405 -322
- package/src/backcompat/types.ts +13 -13
- package/src/backcompat/voice-changer-wrapper.ts +58 -56
- package/src/backcompat/voices-wrapper.ts +217 -150
- package/src/resources/agents/agents.ts +10 -10
- package/src/resources/agents/calls.ts +2 -3
- package/src/resources/datasets/datasets.ts +3 -3
- package/src/resources/datasets/files.ts +3 -3
- package/src/resources/datasets/index.ts +1 -1
- package/src/resources/infill.ts +2 -7
- package/src/resources/pronunciation-dicts.ts +1 -1
- package/src/resources/voice-changer.ts +2 -7
- package/src/resources/voices.ts +15 -15
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/backcompat/index.ts
CHANGED
|
@@ -1,48 +1,46 @@
|
|
|
1
|
-
import { Cartesia, type ClientOptions } from
|
|
2
|
-
import { TTSWrapper } from
|
|
3
|
-
import { VoicesWrapper } from
|
|
4
|
-
import { VoiceChangerWrapper } from
|
|
5
|
-
import type { CartesiaClientOptions, Supplier } from
|
|
1
|
+
import { Cartesia, type ClientOptions } from '../client';
|
|
2
|
+
import { TTSWrapper } from './tts-wrapper';
|
|
3
|
+
import { VoicesWrapper } from './voices-wrapper';
|
|
4
|
+
import { VoiceChangerWrapper } from './voice-changer-wrapper';
|
|
5
|
+
import type { CartesiaClientOptions, Supplier } from './types';
|
|
6
6
|
|
|
7
7
|
async function resolveSupplier<T>(supplier: Supplier<T>): Promise<T> {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
if (typeof supplier === 'function') {
|
|
9
|
+
return (supplier as () => T | Promise<T>)();
|
|
10
|
+
}
|
|
11
|
+
return supplier;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
class DynamicCartesia extends Cartesia {
|
|
15
|
-
|
|
15
|
+
private apiKeySupplier?: Supplier<string | undefined>;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.apiKeySupplier = options.apiKeySupplier;
|
|
22
|
-
}
|
|
17
|
+
constructor(options: ClientOptions & { apiKeySupplier?: Supplier<string | undefined> }) {
|
|
18
|
+
super(options);
|
|
19
|
+
this.apiKeySupplier = options.apiKeySupplier;
|
|
20
|
+
}
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
protected override async prepareRequest(
|
|
23
|
+
request: RequestInit,
|
|
24
|
+
_context: { url: string; options: any },
|
|
25
|
+
): Promise<void> {
|
|
26
|
+
await super.prepareRequest(request, _context);
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
28
|
+
if (this.apiKeySupplier) {
|
|
29
|
+
const key = await resolveSupplier(this.apiKeySupplier);
|
|
30
|
+
if (key) {
|
|
31
|
+
const authHeader = `Bearer ${key}`;
|
|
32
|
+
if (!request.headers) {
|
|
33
|
+
request.headers = { Authorization: authHeader };
|
|
34
|
+
} else if (request.headers instanceof Headers) {
|
|
35
|
+
request.headers.set('Authorization', authHeader);
|
|
36
|
+
} else if (Array.isArray(request.headers)) {
|
|
37
|
+
request.headers.push(['Authorization', authHeader]);
|
|
38
|
+
} else {
|
|
39
|
+
(request.headers as Record<string, string>)['Authorization'] = authHeader;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
/**
|
|
@@ -51,39 +49,38 @@ class DynamicCartesia extends Cartesia {
|
|
|
51
49
|
* This class is provided for backward compatibility with the legacy SDK and may be removed in a future release.
|
|
52
50
|
*/
|
|
53
51
|
export class CartesiaClient {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
private client: Cartesia;
|
|
53
|
+
public tts: TTSWrapper;
|
|
54
|
+
public voices: VoicesWrapper;
|
|
55
|
+
public voiceChanger: VoiceChangerWrapper;
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
constructor(options: CartesiaClientOptions = {}) {
|
|
58
|
+
const newOptions: ClientOptions = {};
|
|
59
|
+
let apiKeySupplier: Supplier<string | undefined> | undefined;
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
if (options.apiKey) {
|
|
62
|
+
if (typeof options.apiKey === 'function') {
|
|
63
|
+
apiKeySupplier = options.apiKey;
|
|
64
|
+
} else {
|
|
65
|
+
newOptions.apiKey = options.apiKey as string;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
70
68
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
if (options.baseUrl) {
|
|
70
|
+
newOptions.baseURL = options.baseUrl as string;
|
|
71
|
+
} else if (options.environment) {
|
|
72
|
+
newOptions.baseURL = options.environment as string;
|
|
73
|
+
}
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
this.client = new DynamicCartesia({ ...newOptions, apiKeySupplier });
|
|
76
|
+
this.tts = new TTSWrapper(this.client);
|
|
77
|
+
this.voices = new VoicesWrapper(this.client);
|
|
78
|
+
this.voiceChanger = new VoiceChangerWrapper(this.client);
|
|
79
|
+
}
|
|
82
80
|
}
|
|
83
81
|
|
|
84
|
-
export * from
|
|
85
|
-
export * from
|
|
86
|
-
export * from
|
|
87
|
-
export * from
|
|
88
|
-
export * from
|
|
89
|
-
|
|
82
|
+
export * from './tts-wrapper';
|
|
83
|
+
export * from './voices-wrapper';
|
|
84
|
+
export * from './voice-changer-wrapper';
|
|
85
|
+
export * from './types';
|
|
86
|
+
export * from './errors';
|