phonic 0.9.0 → 0.10.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 CHANGED
@@ -104,6 +104,12 @@ phonicWebSocket.onMessage((message) => {
104
104
  }
105
105
  });
106
106
  ```
107
+ Update the system prompt mid-conversation:
108
+ ```ts
109
+ phonicWebSocket.updateSystemPrompt({
110
+ systemPrompt = "..."
111
+ })
112
+ ```
107
113
 
108
114
  To end the conversation, close the WebSocket:
109
115
 
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 = {
@@ -68,6 +69,9 @@ declare class PhonicSTSWebSocket {
68
69
  audioChunk(message: {
69
70
  audio: string;
70
71
  }): void;
72
+ updateSystemPrompt(message: {
73
+ systemPrompt: string;
74
+ }): void;
71
75
  close(code?: number): void;
72
76
  }
73
77
 
@@ -104,7 +108,7 @@ declare class Phonic {
104
108
  readonly apiKey: string;
105
109
  readonly baseUrl: string;
106
110
  readonly __downstreamWebSocketUrl: string | null;
107
- private readonly headers;
111
+ readonly headers: Record<string, string>;
108
112
  readonly voices: Voices;
109
113
  readonly sts: SpeechToSpeech;
110
114
  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 = {
@@ -68,6 +69,9 @@ declare class PhonicSTSWebSocket {
68
69
  audioChunk(message: {
69
70
  audio: string;
70
71
  }): void;
72
+ updateSystemPrompt(message: {
73
+ systemPrompt: string;
74
+ }): void;
71
75
  close(code?: number): void;
72
76
  }
73
77
 
@@ -104,7 +108,7 @@ declare class Phonic {
104
108
  readonly apiKey: string;
105
109
  readonly baseUrl: string;
106
110
  readonly __downstreamWebSocketUrl: string | null;
107
- private readonly headers;
111
+ readonly headers: Record<string, string>;
108
112
  readonly voices: Voices;
109
113
  readonly sts: SpeechToSpeech;
110
114
  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.9.0";
38
+ var version = "0.10.0";
39
39
 
40
40
  // src/sts/index.ts
41
41
  var import_ws = __toESM(require("ws"));
@@ -94,6 +94,14 @@ var PhonicSTSWebSocket = class {
94
94
  })
95
95
  );
96
96
  }
97
+ updateSystemPrompt(message) {
98
+ this.ws.send(
99
+ JSON.stringify({
100
+ type: "update_system_prompt",
101
+ system_prompt: message.systemPrompt
102
+ })
103
+ );
104
+ }
97
105
  close(code) {
98
106
  this.ws.close(code ?? 1e3);
99
107
  }
@@ -110,9 +118,7 @@ var SpeechToSpeech = class {
110
118
  async connectToPhonicAPI(phonicApiWsUrl, config) {
111
119
  return new Promise((resolve) => {
112
120
  const ws = new import_ws.default(phonicApiWsUrl, {
113
- headers: {
114
- Authorization: `Bearer ${this.phonic.apiKey}`
115
- }
121
+ headers: this.phonic.headers
116
122
  });
117
123
  ws.onopen = () => {
118
124
  ws.send(
@@ -232,11 +238,12 @@ var Phonic = class {
232
238
  }
233
239
  this.baseUrl = (config?.baseUrl ?? defaultBaseUrl).replace(/\/$/, "");
234
240
  this.__downstreamWebSocketUrl = config?.__downstreamWebSocketUrl || null;
235
- this.headers = new Headers({
241
+ this.headers = {
236
242
  Authorization: `Bearer ${this.apiKey}`,
237
243
  "User-Agent": process.env.PHONIC_USER_AGENT || defaultUserAgent,
238
- "Content-Type": "application/json"
239
- });
244
+ "Content-Type": "application/json",
245
+ ...config?.headers
246
+ };
240
247
  }
241
248
  baseUrl;
242
249
  __downstreamWebSocketUrl;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.9.0";
2
+ var version = "0.10.0";
3
3
 
4
4
  // src/sts/index.ts
5
5
  import WebSocket from "ws";
@@ -58,6 +58,14 @@ var PhonicSTSWebSocket = class {
58
58
  })
59
59
  );
60
60
  }
61
+ updateSystemPrompt(message) {
62
+ this.ws.send(
63
+ JSON.stringify({
64
+ type: "update_system_prompt",
65
+ system_prompt: message.systemPrompt
66
+ })
67
+ );
68
+ }
61
69
  close(code) {
62
70
  this.ws.close(code ?? 1e3);
63
71
  }
@@ -74,9 +82,7 @@ var SpeechToSpeech = class {
74
82
  async connectToPhonicAPI(phonicApiWsUrl, config) {
75
83
  return new Promise((resolve) => {
76
84
  const ws = new WebSocket(phonicApiWsUrl, {
77
- headers: {
78
- Authorization: `Bearer ${this.phonic.apiKey}`
79
- }
85
+ headers: this.phonic.headers
80
86
  });
81
87
  ws.onopen = () => {
82
88
  ws.send(
@@ -196,11 +202,12 @@ var Phonic = class {
196
202
  }
197
203
  this.baseUrl = (config?.baseUrl ?? defaultBaseUrl).replace(/\/$/, "");
198
204
  this.__downstreamWebSocketUrl = config?.__downstreamWebSocketUrl || null;
199
- this.headers = new Headers({
205
+ this.headers = {
200
206
  Authorization: `Bearer ${this.apiKey}`,
201
207
  "User-Agent": process.env.PHONIC_USER_AGENT || defaultUserAgent,
202
- "Content-Type": "application/json"
203
- });
208
+ "Content-Type": "application/json",
209
+ ...config?.headers
210
+ };
204
211
  }
205
212
  baseUrl;
206
213
  __downstreamWebSocketUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phonic",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Phonic Node.js SDK",
5
5
  "scripts": {
6
6
  "build": "tsup",