phonic 0.11.0 → 0.12.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/README.md +24 -2
- package/dist/index.d.mts +42 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +21 -1
- package/dist/index.mjs +21 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@ Node.js library for the Phonic API.
|
|
|
7
7
|
- [Usage](#usage)
|
|
8
8
|
- [Get voices](#get-voices)
|
|
9
9
|
- [Get voice by id](#get-voice-by-id)
|
|
10
|
+
- [Get conversation by id](#get-conversation-by-id)
|
|
11
|
+
- [Get conversation by external id](#get-conversation-by-external-id)
|
|
10
12
|
- [Speech-to-speech via WebSocket](#speech-to-speech-via-websocket)
|
|
11
13
|
|
|
12
14
|
## Installation
|
|
@@ -38,7 +40,7 @@ if (error === null) {
|
|
|
38
40
|
```
|
|
39
41
|
|
|
40
42
|
|
|
41
|
-
### Get voice by
|
|
43
|
+
### Get voice by id
|
|
42
44
|
|
|
43
45
|
```ts
|
|
44
46
|
const { data, error } = await phonic.voices.get("meredith");
|
|
@@ -48,6 +50,26 @@ if (error === null) {
|
|
|
48
50
|
}
|
|
49
51
|
```
|
|
50
52
|
|
|
53
|
+
### Get conversation by id
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const { data, error } = await phonic.conversations.get("conv_b1804883-5be4-42fe-b1cf-aa84450d5c84");
|
|
57
|
+
|
|
58
|
+
if (error === null) {
|
|
59
|
+
console.log(data.conversation);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Get conversation by external id
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const { data, error } = await phonic.conversations.getByExternalId("CAdb9c032c809fec7feb932ea4c96d71e1");
|
|
67
|
+
|
|
68
|
+
if (error === null) {
|
|
69
|
+
console.log(data.conversation);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
51
73
|
### Speech-to-speech via WebSocket
|
|
52
74
|
|
|
53
75
|
To start a conversation, open a WebSocket connection:
|
|
@@ -113,7 +135,7 @@ phonicWebSocket.updateSystemPrompt({
|
|
|
113
135
|
})
|
|
114
136
|
```
|
|
115
137
|
|
|
116
|
-
Set an external
|
|
138
|
+
Set an external id for the conversation (can be the Twilio Call SID, for example):
|
|
117
139
|
|
|
118
140
|
```ts
|
|
119
141
|
phonicWebSocket.setExternalId({
|
package/dist/index.d.mts
CHANGED
|
@@ -20,6 +20,47 @@ type DataOrError<T> = Promise<{
|
|
|
20
20
|
error: ErrorResponse;
|
|
21
21
|
}>;
|
|
22
22
|
|
|
23
|
+
type ISODateTime = `${string}Z`;
|
|
24
|
+
type ConversationItem = {
|
|
25
|
+
role: "user";
|
|
26
|
+
item_idx: number;
|
|
27
|
+
text: string;
|
|
28
|
+
duration_ms: number;
|
|
29
|
+
started_at: string;
|
|
30
|
+
} | {
|
|
31
|
+
role: "assistant";
|
|
32
|
+
item_idx: number;
|
|
33
|
+
text: string;
|
|
34
|
+
voice_id: string;
|
|
35
|
+
system_prompt: string;
|
|
36
|
+
output_audio_speed: number;
|
|
37
|
+
duration_ms: number;
|
|
38
|
+
started_at: string;
|
|
39
|
+
};
|
|
40
|
+
type Conversation = {
|
|
41
|
+
id: string;
|
|
42
|
+
external_id: string | null;
|
|
43
|
+
model: string;
|
|
44
|
+
welcome_message: string | null;
|
|
45
|
+
input_format: "pcm_44100" | "mulaw_8000";
|
|
46
|
+
output_format: "pcm_44100" | "mulaw_8000";
|
|
47
|
+
text: string;
|
|
48
|
+
duration_ms: number;
|
|
49
|
+
started_at: ISODateTime;
|
|
50
|
+
ended_at: ISODateTime;
|
|
51
|
+
items: Array<ConversationItem>;
|
|
52
|
+
};
|
|
53
|
+
type ConversationSuccessResponse = {
|
|
54
|
+
conversation: Conversation;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
declare class Conversations {
|
|
58
|
+
private readonly phonic;
|
|
59
|
+
constructor(phonic: Phonic);
|
|
60
|
+
get(id: string): DataOrError<ConversationSuccessResponse>;
|
|
61
|
+
getByExternalId(externalId: string): DataOrError<ConversationSuccessResponse>;
|
|
62
|
+
}
|
|
63
|
+
|
|
23
64
|
type PhonicSTSConfig = {
|
|
24
65
|
input_format: "pcm_44100" | "mulaw_8000";
|
|
25
66
|
system_prompt?: string;
|
|
@@ -112,6 +153,7 @@ declare class Phonic {
|
|
|
112
153
|
readonly baseUrl: string;
|
|
113
154
|
readonly __downstreamWebSocketUrl: string | null;
|
|
114
155
|
readonly headers: Record<string, string>;
|
|
156
|
+
readonly conversations: Conversations;
|
|
115
157
|
readonly voices: Voices;
|
|
116
158
|
readonly sts: SpeechToSpeech;
|
|
117
159
|
constructor(apiKey: string, config?: PhonicConfig);
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,47 @@ type DataOrError<T> = Promise<{
|
|
|
20
20
|
error: ErrorResponse;
|
|
21
21
|
}>;
|
|
22
22
|
|
|
23
|
+
type ISODateTime = `${string}Z`;
|
|
24
|
+
type ConversationItem = {
|
|
25
|
+
role: "user";
|
|
26
|
+
item_idx: number;
|
|
27
|
+
text: string;
|
|
28
|
+
duration_ms: number;
|
|
29
|
+
started_at: string;
|
|
30
|
+
} | {
|
|
31
|
+
role: "assistant";
|
|
32
|
+
item_idx: number;
|
|
33
|
+
text: string;
|
|
34
|
+
voice_id: string;
|
|
35
|
+
system_prompt: string;
|
|
36
|
+
output_audio_speed: number;
|
|
37
|
+
duration_ms: number;
|
|
38
|
+
started_at: string;
|
|
39
|
+
};
|
|
40
|
+
type Conversation = {
|
|
41
|
+
id: string;
|
|
42
|
+
external_id: string | null;
|
|
43
|
+
model: string;
|
|
44
|
+
welcome_message: string | null;
|
|
45
|
+
input_format: "pcm_44100" | "mulaw_8000";
|
|
46
|
+
output_format: "pcm_44100" | "mulaw_8000";
|
|
47
|
+
text: string;
|
|
48
|
+
duration_ms: number;
|
|
49
|
+
started_at: ISODateTime;
|
|
50
|
+
ended_at: ISODateTime;
|
|
51
|
+
items: Array<ConversationItem>;
|
|
52
|
+
};
|
|
53
|
+
type ConversationSuccessResponse = {
|
|
54
|
+
conversation: Conversation;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
declare class Conversations {
|
|
58
|
+
private readonly phonic;
|
|
59
|
+
constructor(phonic: Phonic);
|
|
60
|
+
get(id: string): DataOrError<ConversationSuccessResponse>;
|
|
61
|
+
getByExternalId(externalId: string): DataOrError<ConversationSuccessResponse>;
|
|
62
|
+
}
|
|
63
|
+
|
|
23
64
|
type PhonicSTSConfig = {
|
|
24
65
|
input_format: "pcm_44100" | "mulaw_8000";
|
|
25
66
|
system_prompt?: string;
|
|
@@ -112,6 +153,7 @@ declare class Phonic {
|
|
|
112
153
|
readonly baseUrl: string;
|
|
113
154
|
readonly __downstreamWebSocketUrl: string | null;
|
|
114
155
|
readonly headers: Record<string, string>;
|
|
156
|
+
readonly conversations: Conversations;
|
|
115
157
|
readonly voices: Voices;
|
|
116
158
|
readonly sts: SpeechToSpeech;
|
|
117
159
|
constructor(apiKey: string, config?: PhonicConfig);
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,26 @@ __export(index_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
|
|
37
37
|
// package.json
|
|
38
|
-
var version = "0.
|
|
38
|
+
var version = "0.12.0";
|
|
39
|
+
|
|
40
|
+
// src/conversations/index.ts
|
|
41
|
+
var Conversations = class {
|
|
42
|
+
constructor(phonic) {
|
|
43
|
+
this.phonic = phonic;
|
|
44
|
+
}
|
|
45
|
+
async get(id) {
|
|
46
|
+
const response = await this.phonic.get(
|
|
47
|
+
`/conversations/${id}`
|
|
48
|
+
);
|
|
49
|
+
return response;
|
|
50
|
+
}
|
|
51
|
+
async getByExternalId(externalId) {
|
|
52
|
+
const response = await this.phonic.get(
|
|
53
|
+
`/conversations?external_id=${externalId}`
|
|
54
|
+
);
|
|
55
|
+
return response;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
39
58
|
|
|
40
59
|
// src/sts/index.ts
|
|
41
60
|
var import_ws = __toESM(require("ws"));
|
|
@@ -256,6 +275,7 @@ var Phonic = class {
|
|
|
256
275
|
baseUrl;
|
|
257
276
|
__downstreamWebSocketUrl;
|
|
258
277
|
headers;
|
|
278
|
+
conversations = new Conversations(this);
|
|
259
279
|
voices = new Voices(this);
|
|
260
280
|
sts = new SpeechToSpeech(this);
|
|
261
281
|
async fetchRequest(path, options) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "0.
|
|
2
|
+
var version = "0.12.0";
|
|
3
|
+
|
|
4
|
+
// src/conversations/index.ts
|
|
5
|
+
var Conversations = class {
|
|
6
|
+
constructor(phonic) {
|
|
7
|
+
this.phonic = phonic;
|
|
8
|
+
}
|
|
9
|
+
async get(id) {
|
|
10
|
+
const response = await this.phonic.get(
|
|
11
|
+
`/conversations/${id}`
|
|
12
|
+
);
|
|
13
|
+
return response;
|
|
14
|
+
}
|
|
15
|
+
async getByExternalId(externalId) {
|
|
16
|
+
const response = await this.phonic.get(
|
|
17
|
+
`/conversations?external_id=${externalId}`
|
|
18
|
+
);
|
|
19
|
+
return response;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
3
22
|
|
|
4
23
|
// src/sts/index.ts
|
|
5
24
|
import WebSocket from "ws";
|
|
@@ -220,6 +239,7 @@ var Phonic = class {
|
|
|
220
239
|
baseUrl;
|
|
221
240
|
__downstreamWebSocketUrl;
|
|
222
241
|
headers;
|
|
242
|
+
conversations = new Conversations(this);
|
|
223
243
|
voices = new Voices(this);
|
|
224
244
|
sts = new SpeechToSpeech(this);
|
|
225
245
|
async fetchRequest(path, options) {
|