phonic 0.11.0 → 0.13.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
@@ -7,6 +7,9 @@ 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)
12
+ - [List conversations](#list-conversations)
10
13
  - [Speech-to-speech via WebSocket](#speech-to-speech-via-websocket)
11
14
 
12
15
  ## Installation
@@ -38,7 +41,7 @@ if (error === null) {
38
41
  ```
39
42
 
40
43
 
41
- ### Get voice by ID
44
+ ### Get voice by id
42
45
 
43
46
  ```ts
44
47
  const { data, error } = await phonic.voices.get("meredith");
@@ -48,6 +51,41 @@ if (error === null) {
48
51
  }
49
52
  ```
50
53
 
54
+ ### Get conversation by id
55
+
56
+ ```ts
57
+ const { data, error } = await phonic.conversations.get("conv_b1804883-5be4-42fe-b1cf-aa84450d5c84");
58
+
59
+ if (error === null) {
60
+ console.log(data.conversation);
61
+ }
62
+ ```
63
+
64
+ ### Get conversation by external id
65
+
66
+ ```ts
67
+ const { data, error } = await phonic.conversations.getByExternalId("CAdb9c032c809fec7feb932ea4c96d71e1");
68
+
69
+ if (error === null) {
70
+ console.log(data.conversation);
71
+ }
72
+ ```
73
+
74
+ ### List conversations
75
+
76
+ ```ts
77
+ const { data, error } = await phonic.conversations.list({
78
+ durationMin: 10000, // ms
79
+ durationMax: 20000, // ms
80
+ startedAtMin: "2025-04-17", // 00:00:00 UTC time is assumed
81
+ startedAtMax: "2025-09-05T10:30:00.000Z",
82
+ });
83
+
84
+ if (error === null) {
85
+ console.log(data.conversations);
86
+ }
87
+ ```
88
+
51
89
  ### Speech-to-speech via WebSocket
52
90
 
53
91
  To start a conversation, open a WebSocket connection:
@@ -113,7 +151,7 @@ phonicWebSocket.updateSystemPrompt({
113
151
  })
114
152
  ```
115
153
 
116
- Set an external ID for the conversation (can be the Twilio Call SID, for example):
154
+ Set an external id for the conversation (can be the Twilio Call SID, for example):
117
155
 
118
156
  ```ts
119
157
  phonicWebSocket.setExternalId({
package/dist/index.d.mts CHANGED
@@ -19,6 +19,58 @@ type DataOrError<T> = Promise<{
19
19
  data: null;
20
20
  error: ErrorResponse;
21
21
  }>;
22
+ type ISODate = `${string}-${string}-${string}`;
23
+ type ISODateTime$1 = `${string}Z`;
24
+
25
+ type ISODateTime = `${string}Z`;
26
+ type ConversationItem = {
27
+ role: "user";
28
+ item_idx: number;
29
+ text: string;
30
+ duration_ms: number;
31
+ started_at: string;
32
+ } | {
33
+ role: "assistant";
34
+ item_idx: number;
35
+ text: string;
36
+ voice_id: string;
37
+ system_prompt: string;
38
+ output_audio_speed: number;
39
+ duration_ms: number;
40
+ started_at: string;
41
+ };
42
+ type Conversation = {
43
+ id: string;
44
+ external_id: string | null;
45
+ model: string;
46
+ welcome_message: string | null;
47
+ input_format: "pcm_44100" | "mulaw_8000";
48
+ output_format: "pcm_44100" | "mulaw_8000";
49
+ text: string;
50
+ duration_ms: number;
51
+ started_at: ISODateTime;
52
+ ended_at: ISODateTime;
53
+ items: Array<ConversationItem>;
54
+ };
55
+ type ConversationSuccessResponse = {
56
+ conversation: Conversation;
57
+ };
58
+ type ConversationsSuccessResponse = {
59
+ conversations: Array<Conversation>;
60
+ };
61
+
62
+ declare class Conversations {
63
+ private readonly phonic;
64
+ constructor(phonic: Phonic);
65
+ get(id: string): DataOrError<ConversationSuccessResponse>;
66
+ getByExternalId(externalId: string): DataOrError<ConversationSuccessResponse>;
67
+ list({ durationMin, durationMax, startedAtMin, startedAtMax, }: {
68
+ durationMin?: number;
69
+ durationMax?: number;
70
+ startedAtMin?: ISODate | ISODateTime$1;
71
+ startedAtMax?: ISODate | ISODateTime$1;
72
+ }): DataOrError<ConversationsSuccessResponse>;
73
+ }
22
74
 
23
75
  type PhonicSTSConfig = {
24
76
  input_format: "pcm_44100" | "mulaw_8000";
@@ -112,6 +164,7 @@ declare class Phonic {
112
164
  readonly baseUrl: string;
113
165
  readonly __downstreamWebSocketUrl: string | null;
114
166
  readonly headers: Record<string, string>;
167
+ readonly conversations: Conversations;
115
168
  readonly voices: Voices;
116
169
  readonly sts: SpeechToSpeech;
117
170
  constructor(apiKey: string, config?: PhonicConfig);
package/dist/index.d.ts CHANGED
@@ -19,6 +19,58 @@ type DataOrError<T> = Promise<{
19
19
  data: null;
20
20
  error: ErrorResponse;
21
21
  }>;
22
+ type ISODate = `${string}-${string}-${string}`;
23
+ type ISODateTime$1 = `${string}Z`;
24
+
25
+ type ISODateTime = `${string}Z`;
26
+ type ConversationItem = {
27
+ role: "user";
28
+ item_idx: number;
29
+ text: string;
30
+ duration_ms: number;
31
+ started_at: string;
32
+ } | {
33
+ role: "assistant";
34
+ item_idx: number;
35
+ text: string;
36
+ voice_id: string;
37
+ system_prompt: string;
38
+ output_audio_speed: number;
39
+ duration_ms: number;
40
+ started_at: string;
41
+ };
42
+ type Conversation = {
43
+ id: string;
44
+ external_id: string | null;
45
+ model: string;
46
+ welcome_message: string | null;
47
+ input_format: "pcm_44100" | "mulaw_8000";
48
+ output_format: "pcm_44100" | "mulaw_8000";
49
+ text: string;
50
+ duration_ms: number;
51
+ started_at: ISODateTime;
52
+ ended_at: ISODateTime;
53
+ items: Array<ConversationItem>;
54
+ };
55
+ type ConversationSuccessResponse = {
56
+ conversation: Conversation;
57
+ };
58
+ type ConversationsSuccessResponse = {
59
+ conversations: Array<Conversation>;
60
+ };
61
+
62
+ declare class Conversations {
63
+ private readonly phonic;
64
+ constructor(phonic: Phonic);
65
+ get(id: string): DataOrError<ConversationSuccessResponse>;
66
+ getByExternalId(externalId: string): DataOrError<ConversationSuccessResponse>;
67
+ list({ durationMin, durationMax, startedAtMin, startedAtMax, }: {
68
+ durationMin?: number;
69
+ durationMax?: number;
70
+ startedAtMin?: ISODate | ISODateTime$1;
71
+ startedAtMax?: ISODate | ISODateTime$1;
72
+ }): DataOrError<ConversationsSuccessResponse>;
73
+ }
22
74
 
23
75
  type PhonicSTSConfig = {
24
76
  input_format: "pcm_44100" | "mulaw_8000";
@@ -112,6 +164,7 @@ declare class Phonic {
112
164
  readonly baseUrl: string;
113
165
  readonly __downstreamWebSocketUrl: string | null;
114
166
  readonly headers: Record<string, string>;
167
+ readonly conversations: Conversations;
115
168
  readonly voices: Voices;
116
169
  readonly sts: SpeechToSpeech;
117
170
  constructor(apiKey: string, config?: PhonicConfig);
package/dist/index.js CHANGED
@@ -35,7 +35,46 @@ __export(index_exports, {
35
35
  module.exports = __toCommonJS(index_exports);
36
36
 
37
37
  // package.json
38
- var version = "0.11.0";
38
+ var version = "0.13.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 queryString = new URLSearchParams({
53
+ external_id: externalId
54
+ }).toString();
55
+ const response = await this.phonic.get(
56
+ `/conversations?${queryString}`
57
+ );
58
+ return response;
59
+ }
60
+ async list({
61
+ durationMin,
62
+ durationMax,
63
+ startedAtMin,
64
+ startedAtMax
65
+ }) {
66
+ const queryString = new URLSearchParams({
67
+ ...durationMin !== void 0 && { duration_min: String(durationMin) },
68
+ ...durationMax !== void 0 && { duration_max: String(durationMax) },
69
+ ...startedAtMin !== void 0 && { started_at_min: startedAtMin },
70
+ ...startedAtMax !== void 0 && { started_at_max: startedAtMax }
71
+ }).toString();
72
+ const response = await this.phonic.get(
73
+ `/conversations?${queryString}`
74
+ );
75
+ return response;
76
+ }
77
+ };
39
78
 
40
79
  // src/sts/index.ts
41
80
  var import_ws = __toESM(require("ws"));
@@ -256,6 +295,7 @@ var Phonic = class {
256
295
  baseUrl;
257
296
  __downstreamWebSocketUrl;
258
297
  headers;
298
+ conversations = new Conversations(this);
259
299
  voices = new Voices(this);
260
300
  sts = new SpeechToSpeech(this);
261
301
  async fetchRequest(path, options) {
package/dist/index.mjs CHANGED
@@ -1,5 +1,44 @@
1
1
  // package.json
2
- var version = "0.11.0";
2
+ var version = "0.13.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 queryString = new URLSearchParams({
17
+ external_id: externalId
18
+ }).toString();
19
+ const response = await this.phonic.get(
20
+ `/conversations?${queryString}`
21
+ );
22
+ return response;
23
+ }
24
+ async list({
25
+ durationMin,
26
+ durationMax,
27
+ startedAtMin,
28
+ startedAtMax
29
+ }) {
30
+ const queryString = new URLSearchParams({
31
+ ...durationMin !== void 0 && { duration_min: String(durationMin) },
32
+ ...durationMax !== void 0 && { duration_max: String(durationMax) },
33
+ ...startedAtMin !== void 0 && { started_at_min: startedAtMin },
34
+ ...startedAtMax !== void 0 && { started_at_max: startedAtMax }
35
+ }).toString();
36
+ const response = await this.phonic.get(
37
+ `/conversations?${queryString}`
38
+ );
39
+ return response;
40
+ }
41
+ };
3
42
 
4
43
  // src/sts/index.ts
5
44
  import WebSocket from "ws";
@@ -220,6 +259,7 @@ var Phonic = class {
220
259
  baseUrl;
221
260
  __downstreamWebSocketUrl;
222
261
  headers;
262
+ conversations = new Conversations(this);
223
263
  voices = new Voices(this);
224
264
  sts = new SpeechToSpeech(this);
225
265
  async fetchRequest(path, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phonic",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "Phonic Node.js SDK",
5
5
  "scripts": {
6
6
  "build": "tsup",