phonic 0.9.0 → 0.11.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 +16 -0
- package/dist/index.d.mts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +24 -9
- package/dist/index.mjs +24 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -105,6 +105,22 @@ phonicWebSocket.onMessage((message) => {
|
|
|
105
105
|
});
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
+
Update the system prompt mid-conversation:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
phonicWebSocket.updateSystemPrompt({
|
|
112
|
+
systemPrompt: "..."
|
|
113
|
+
})
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Set an external ID for the conversation (can be the Twilio Call SID, for example):
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
phonicWebSocket.setExternalId({
|
|
120
|
+
externalId: "..."
|
|
121
|
+
})
|
|
122
|
+
```
|
|
123
|
+
|
|
108
124
|
To end the conversation, close the WebSocket:
|
|
109
125
|
|
|
110
126
|
```ts
|
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ import WebSocket from 'ws';
|
|
|
2
2
|
|
|
3
3
|
type PhonicConfig = {
|
|
4
4
|
baseUrl?: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
5
6
|
__downstreamWebSocketUrl?: string;
|
|
6
7
|
};
|
|
7
8
|
type FetchOptions = {
|
|
@@ -65,9 +66,15 @@ declare class PhonicSTSWebSocket {
|
|
|
65
66
|
onMessage(callback: OnMessageCallback): void;
|
|
66
67
|
onClose(callback: OnCloseCallback): void;
|
|
67
68
|
onError(callback: OnErrorCallback): void;
|
|
68
|
-
audioChunk(
|
|
69
|
+
audioChunk({ audio }: {
|
|
69
70
|
audio: string;
|
|
70
71
|
}): void;
|
|
72
|
+
updateSystemPrompt({ systemPrompt }: {
|
|
73
|
+
systemPrompt: string;
|
|
74
|
+
}): void;
|
|
75
|
+
setExternalId({ externalId }: {
|
|
76
|
+
externalId: string;
|
|
77
|
+
}): void;
|
|
71
78
|
close(code?: number): void;
|
|
72
79
|
}
|
|
73
80
|
|
|
@@ -104,7 +111,7 @@ declare class Phonic {
|
|
|
104
111
|
readonly apiKey: string;
|
|
105
112
|
readonly baseUrl: string;
|
|
106
113
|
readonly __downstreamWebSocketUrl: string | null;
|
|
107
|
-
|
|
114
|
+
readonly headers: Record<string, string>;
|
|
108
115
|
readonly voices: Voices;
|
|
109
116
|
readonly sts: SpeechToSpeech;
|
|
110
117
|
constructor(apiKey: string, config?: PhonicConfig);
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import WebSocket from 'ws';
|
|
|
2
2
|
|
|
3
3
|
type PhonicConfig = {
|
|
4
4
|
baseUrl?: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
5
6
|
__downstreamWebSocketUrl?: string;
|
|
6
7
|
};
|
|
7
8
|
type FetchOptions = {
|
|
@@ -65,9 +66,15 @@ declare class PhonicSTSWebSocket {
|
|
|
65
66
|
onMessage(callback: OnMessageCallback): void;
|
|
66
67
|
onClose(callback: OnCloseCallback): void;
|
|
67
68
|
onError(callback: OnErrorCallback): void;
|
|
68
|
-
audioChunk(
|
|
69
|
+
audioChunk({ audio }: {
|
|
69
70
|
audio: string;
|
|
70
71
|
}): void;
|
|
72
|
+
updateSystemPrompt({ systemPrompt }: {
|
|
73
|
+
systemPrompt: string;
|
|
74
|
+
}): void;
|
|
75
|
+
setExternalId({ externalId }: {
|
|
76
|
+
externalId: string;
|
|
77
|
+
}): void;
|
|
71
78
|
close(code?: number): void;
|
|
72
79
|
}
|
|
73
80
|
|
|
@@ -104,7 +111,7 @@ declare class Phonic {
|
|
|
104
111
|
readonly apiKey: string;
|
|
105
112
|
readonly baseUrl: string;
|
|
106
113
|
readonly __downstreamWebSocketUrl: string | null;
|
|
107
|
-
|
|
114
|
+
readonly headers: Record<string, string>;
|
|
108
115
|
readonly voices: Voices;
|
|
109
116
|
readonly sts: SpeechToSpeech;
|
|
110
117
|
constructor(apiKey: string, config?: PhonicConfig);
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
|
|
37
37
|
// package.json
|
|
38
|
-
var version = "0.
|
|
38
|
+
var version = "0.11.0";
|
|
39
39
|
|
|
40
40
|
// src/sts/index.ts
|
|
41
41
|
var import_ws = __toESM(require("ws"));
|
|
@@ -86,11 +86,27 @@ var PhonicSTSWebSocket = class {
|
|
|
86
86
|
onError(callback) {
|
|
87
87
|
this.onErrorCallback = callback;
|
|
88
88
|
}
|
|
89
|
-
audioChunk(
|
|
89
|
+
audioChunk({ audio }) {
|
|
90
90
|
this.ws.send(
|
|
91
91
|
JSON.stringify({
|
|
92
92
|
type: "audio_chunk",
|
|
93
|
-
|
|
93
|
+
audio
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
updateSystemPrompt({ systemPrompt }) {
|
|
98
|
+
this.ws.send(
|
|
99
|
+
JSON.stringify({
|
|
100
|
+
type: "update_system_prompt",
|
|
101
|
+
system_prompt: systemPrompt
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
setExternalId({ externalId }) {
|
|
106
|
+
this.ws.send(
|
|
107
|
+
JSON.stringify({
|
|
108
|
+
type: "set_external_id",
|
|
109
|
+
external_id: externalId
|
|
94
110
|
})
|
|
95
111
|
);
|
|
96
112
|
}
|
|
@@ -110,9 +126,7 @@ var SpeechToSpeech = class {
|
|
|
110
126
|
async connectToPhonicAPI(phonicApiWsUrl, config) {
|
|
111
127
|
return new Promise((resolve) => {
|
|
112
128
|
const ws = new import_ws.default(phonicApiWsUrl, {
|
|
113
|
-
headers:
|
|
114
|
-
Authorization: `Bearer ${this.phonic.apiKey}`
|
|
115
|
-
}
|
|
129
|
+
headers: this.phonic.headers
|
|
116
130
|
});
|
|
117
131
|
ws.onopen = () => {
|
|
118
132
|
ws.send(
|
|
@@ -232,11 +246,12 @@ var Phonic = class {
|
|
|
232
246
|
}
|
|
233
247
|
this.baseUrl = (config?.baseUrl ?? defaultBaseUrl).replace(/\/$/, "");
|
|
234
248
|
this.__downstreamWebSocketUrl = config?.__downstreamWebSocketUrl || null;
|
|
235
|
-
this.headers =
|
|
249
|
+
this.headers = {
|
|
236
250
|
Authorization: `Bearer ${this.apiKey}`,
|
|
237
251
|
"User-Agent": process.env.PHONIC_USER_AGENT || defaultUserAgent,
|
|
238
|
-
"Content-Type": "application/json"
|
|
239
|
-
|
|
252
|
+
"Content-Type": "application/json",
|
|
253
|
+
...config?.headers
|
|
254
|
+
};
|
|
240
255
|
}
|
|
241
256
|
baseUrl;
|
|
242
257
|
__downstreamWebSocketUrl;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "0.
|
|
2
|
+
var version = "0.11.0";
|
|
3
3
|
|
|
4
4
|
// src/sts/index.ts
|
|
5
5
|
import WebSocket from "ws";
|
|
@@ -50,11 +50,27 @@ var PhonicSTSWebSocket = class {
|
|
|
50
50
|
onError(callback) {
|
|
51
51
|
this.onErrorCallback = callback;
|
|
52
52
|
}
|
|
53
|
-
audioChunk(
|
|
53
|
+
audioChunk({ audio }) {
|
|
54
54
|
this.ws.send(
|
|
55
55
|
JSON.stringify({
|
|
56
56
|
type: "audio_chunk",
|
|
57
|
-
|
|
57
|
+
audio
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
updateSystemPrompt({ systemPrompt }) {
|
|
62
|
+
this.ws.send(
|
|
63
|
+
JSON.stringify({
|
|
64
|
+
type: "update_system_prompt",
|
|
65
|
+
system_prompt: systemPrompt
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
setExternalId({ externalId }) {
|
|
70
|
+
this.ws.send(
|
|
71
|
+
JSON.stringify({
|
|
72
|
+
type: "set_external_id",
|
|
73
|
+
external_id: externalId
|
|
58
74
|
})
|
|
59
75
|
);
|
|
60
76
|
}
|
|
@@ -74,9 +90,7 @@ var SpeechToSpeech = class {
|
|
|
74
90
|
async connectToPhonicAPI(phonicApiWsUrl, config) {
|
|
75
91
|
return new Promise((resolve) => {
|
|
76
92
|
const ws = new WebSocket(phonicApiWsUrl, {
|
|
77
|
-
headers:
|
|
78
|
-
Authorization: `Bearer ${this.phonic.apiKey}`
|
|
79
|
-
}
|
|
93
|
+
headers: this.phonic.headers
|
|
80
94
|
});
|
|
81
95
|
ws.onopen = () => {
|
|
82
96
|
ws.send(
|
|
@@ -196,11 +210,12 @@ var Phonic = class {
|
|
|
196
210
|
}
|
|
197
211
|
this.baseUrl = (config?.baseUrl ?? defaultBaseUrl).replace(/\/$/, "");
|
|
198
212
|
this.__downstreamWebSocketUrl = config?.__downstreamWebSocketUrl || null;
|
|
199
|
-
this.headers =
|
|
213
|
+
this.headers = {
|
|
200
214
|
Authorization: `Bearer ${this.apiKey}`,
|
|
201
215
|
"User-Agent": process.env.PHONIC_USER_AGENT || defaultUserAgent,
|
|
202
|
-
"Content-Type": "application/json"
|
|
203
|
-
|
|
216
|
+
"Content-Type": "application/json",
|
|
217
|
+
...config?.headers
|
|
218
|
+
};
|
|
204
219
|
}
|
|
205
220
|
baseUrl;
|
|
206
221
|
__downstreamWebSocketUrl;
|