phonic 0.32.11 → 0.32.13

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.
Files changed (138) hide show
  1. package/dist/cjs/BaseClient.js +2 -2
  2. package/dist/cjs/Client.d.ts +3 -0
  3. package/dist/cjs/Client.js +17 -12
  4. package/dist/cjs/api/resources/agents/client/Client.d.ts +3 -0
  5. package/dist/cjs/api/resources/agents/client/Client.js +3 -0
  6. package/dist/cjs/api/resources/agents/client/requests/AgentsAddCustomPhoneNumberRequest.d.ts +10 -7
  7. package/dist/cjs/api/resources/agents/client/requests/AgentsCreateRequest.d.ts +3 -1
  8. package/dist/cjs/api/resources/agents/client/requests/AgentsUpdatePhoneNumberRequest.d.ts +1 -1
  9. package/dist/cjs/api/resources/agents/client/requests/UpdateAgentRequest.d.ts +4 -2
  10. package/dist/cjs/api/resources/externalStoragePolicies/client/Client.d.ts +117 -0
  11. package/dist/cjs/api/resources/externalStoragePolicies/client/Client.js +427 -0
  12. package/dist/cjs/api/resources/externalStoragePolicies/client/index.d.ts +1 -0
  13. package/dist/cjs/api/resources/externalStoragePolicies/client/index.js +17 -0
  14. package/dist/cjs/api/resources/externalStoragePolicies/client/requests/CreateExternalStoragePolicyRequest.d.ts +43 -0
  15. package/dist/cjs/api/resources/externalStoragePolicies/client/requests/CreateExternalStoragePolicyRequest.js +13 -0
  16. package/dist/cjs/api/resources/externalStoragePolicies/client/requests/ExternalStoragePoliciesDeleteRequest.d.ts +10 -0
  17. package/dist/cjs/api/resources/externalStoragePolicies/client/requests/ExternalStoragePoliciesDeleteRequest.js +3 -0
  18. package/dist/cjs/api/resources/externalStoragePolicies/client/requests/ExternalStoragePoliciesGetRequest.d.ts +10 -0
  19. package/dist/cjs/api/resources/externalStoragePolicies/client/requests/ExternalStoragePoliciesGetRequest.js +3 -0
  20. package/dist/cjs/api/resources/externalStoragePolicies/client/requests/ExternalStoragePoliciesListRequest.d.ts +10 -0
  21. package/dist/cjs/api/resources/externalStoragePolicies/client/requests/ExternalStoragePoliciesListRequest.js +3 -0
  22. package/dist/cjs/api/resources/externalStoragePolicies/client/requests/UpdateExternalStoragePolicyRequest.d.ts +37 -0
  23. package/dist/cjs/api/resources/externalStoragePolicies/client/requests/UpdateExternalStoragePolicyRequest.js +13 -0
  24. package/dist/cjs/api/resources/externalStoragePolicies/client/requests/index.d.ts +5 -0
  25. package/dist/cjs/api/resources/externalStoragePolicies/client/requests/index.js +7 -0
  26. package/dist/cjs/api/resources/externalStoragePolicies/exports.d.ts +2 -0
  27. package/dist/cjs/api/resources/externalStoragePolicies/exports.js +21 -0
  28. package/dist/cjs/api/resources/externalStoragePolicies/index.d.ts +2 -0
  29. package/dist/cjs/api/resources/externalStoragePolicies/index.js +18 -0
  30. package/dist/cjs/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesCreateResponse.d.ts +6 -0
  31. package/dist/cjs/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesCreateResponse.js +3 -0
  32. package/dist/cjs/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesDeleteResponse.d.ts +4 -0
  33. package/dist/cjs/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesDeleteResponse.js +3 -0
  34. package/dist/cjs/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesGetResponse.d.ts +4 -0
  35. package/dist/cjs/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesGetResponse.js +3 -0
  36. package/dist/cjs/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesListResponse.d.ts +4 -0
  37. package/dist/cjs/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesListResponse.js +3 -0
  38. package/dist/cjs/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesUpdateResponse.d.ts +4 -0
  39. package/dist/cjs/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesUpdateResponse.js +3 -0
  40. package/dist/cjs/api/resources/externalStoragePolicies/types/index.d.ts +5 -0
  41. package/dist/cjs/api/resources/externalStoragePolicies/types/index.js +21 -0
  42. package/dist/cjs/api/resources/index.d.ts +3 -0
  43. package/dist/cjs/api/resources/index.js +4 -1
  44. package/dist/cjs/api/resources/tools/client/Client.d.ts +65 -0
  45. package/dist/cjs/api/resources/tools/client/Client.js +65 -0
  46. package/dist/cjs/api/resources/tools/client/requests/CreateToolRequest.d.ts +100 -6
  47. package/dist/cjs/api/resources/tools/client/requests/CreateToolRequest.js +7 -0
  48. package/dist/cjs/api/resources/tools/client/requests/UpdateToolRequest.d.ts +27 -6
  49. package/dist/cjs/api/resources/tools/client/requests/UpdateToolRequest.js +8 -1
  50. package/dist/cjs/api/types/Agent.d.ts +3 -1
  51. package/dist/cjs/api/types/ConfigOptions.d.ts +4 -2
  52. package/dist/cjs/api/types/CreateAgentRequest.d.ts +4 -2
  53. package/dist/cjs/api/types/ExternalStoragePolicy.d.ts +30 -0
  54. package/dist/cjs/api/types/ExternalStoragePolicy.js +13 -0
  55. package/dist/cjs/api/types/InlineWebSocketTool.d.ts +2 -0
  56. package/dist/cjs/api/types/OutboundCallConfig.d.ts +2 -2
  57. package/dist/cjs/api/types/Tool.d.ts +26 -2
  58. package/dist/cjs/api/types/Tool.js +7 -0
  59. package/dist/cjs/api/types/ToolParameter.d.ts +5 -2
  60. package/dist/cjs/api/types/ToolParameter.js +2 -1
  61. package/dist/cjs/api/types/ToolParametersJsonSchema.d.ts +15 -0
  62. package/dist/cjs/api/types/ToolParametersJsonSchema.js +3 -0
  63. package/dist/cjs/api/types/index.d.ts +2 -0
  64. package/dist/cjs/api/types/index.js +2 -0
  65. package/dist/cjs/version.d.ts +1 -1
  66. package/dist/cjs/version.js +1 -1
  67. package/dist/esm/BaseClient.mjs +2 -2
  68. package/dist/esm/Client.d.mts +3 -0
  69. package/dist/esm/Client.mjs +5 -0
  70. package/dist/esm/api/resources/agents/client/Client.d.mts +3 -0
  71. package/dist/esm/api/resources/agents/client/Client.mjs +3 -0
  72. package/dist/esm/api/resources/agents/client/requests/AgentsAddCustomPhoneNumberRequest.d.mts +10 -7
  73. package/dist/esm/api/resources/agents/client/requests/AgentsCreateRequest.d.mts +3 -1
  74. package/dist/esm/api/resources/agents/client/requests/AgentsUpdatePhoneNumberRequest.d.mts +1 -1
  75. package/dist/esm/api/resources/agents/client/requests/UpdateAgentRequest.d.mts +4 -2
  76. package/dist/esm/api/resources/externalStoragePolicies/client/Client.d.mts +117 -0
  77. package/dist/esm/api/resources/externalStoragePolicies/client/Client.mjs +390 -0
  78. package/dist/esm/api/resources/externalStoragePolicies/client/index.d.mts +1 -0
  79. package/dist/esm/api/resources/externalStoragePolicies/client/index.mjs +1 -0
  80. package/dist/esm/api/resources/externalStoragePolicies/client/requests/CreateExternalStoragePolicyRequest.d.mts +43 -0
  81. package/dist/esm/api/resources/externalStoragePolicies/client/requests/CreateExternalStoragePolicyRequest.mjs +10 -0
  82. package/dist/esm/api/resources/externalStoragePolicies/client/requests/ExternalStoragePoliciesDeleteRequest.d.mts +10 -0
  83. package/dist/esm/api/resources/externalStoragePolicies/client/requests/ExternalStoragePoliciesDeleteRequest.mjs +2 -0
  84. package/dist/esm/api/resources/externalStoragePolicies/client/requests/ExternalStoragePoliciesGetRequest.d.mts +10 -0
  85. package/dist/esm/api/resources/externalStoragePolicies/client/requests/ExternalStoragePoliciesGetRequest.mjs +2 -0
  86. package/dist/esm/api/resources/externalStoragePolicies/client/requests/ExternalStoragePoliciesListRequest.d.mts +10 -0
  87. package/dist/esm/api/resources/externalStoragePolicies/client/requests/ExternalStoragePoliciesListRequest.mjs +2 -0
  88. package/dist/esm/api/resources/externalStoragePolicies/client/requests/UpdateExternalStoragePolicyRequest.d.mts +37 -0
  89. package/dist/esm/api/resources/externalStoragePolicies/client/requests/UpdateExternalStoragePolicyRequest.mjs +10 -0
  90. package/dist/esm/api/resources/externalStoragePolicies/client/requests/index.d.mts +5 -0
  91. package/dist/esm/api/resources/externalStoragePolicies/client/requests/index.mjs +2 -0
  92. package/dist/esm/api/resources/externalStoragePolicies/exports.d.mts +2 -0
  93. package/dist/esm/api/resources/externalStoragePolicies/exports.mjs +3 -0
  94. package/dist/esm/api/resources/externalStoragePolicies/index.d.mts +2 -0
  95. package/dist/esm/api/resources/externalStoragePolicies/index.mjs +2 -0
  96. package/dist/esm/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesCreateResponse.d.mts +6 -0
  97. package/dist/esm/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesCreateResponse.mjs +2 -0
  98. package/dist/esm/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesDeleteResponse.d.mts +4 -0
  99. package/dist/esm/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesDeleteResponse.mjs +2 -0
  100. package/dist/esm/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesGetResponse.d.mts +4 -0
  101. package/dist/esm/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesGetResponse.mjs +2 -0
  102. package/dist/esm/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesListResponse.d.mts +4 -0
  103. package/dist/esm/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesListResponse.mjs +2 -0
  104. package/dist/esm/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesUpdateResponse.d.mts +4 -0
  105. package/dist/esm/api/resources/externalStoragePolicies/types/ExternalStoragePoliciesUpdateResponse.mjs +2 -0
  106. package/dist/esm/api/resources/externalStoragePolicies/types/index.d.mts +5 -0
  107. package/dist/esm/api/resources/externalStoragePolicies/types/index.mjs +5 -0
  108. package/dist/esm/api/resources/index.d.mts +3 -0
  109. package/dist/esm/api/resources/index.mjs +3 -0
  110. package/dist/esm/api/resources/tools/client/Client.d.mts +65 -0
  111. package/dist/esm/api/resources/tools/client/Client.mjs +65 -0
  112. package/dist/esm/api/resources/tools/client/requests/CreateToolRequest.d.mts +100 -6
  113. package/dist/esm/api/resources/tools/client/requests/CreateToolRequest.mjs +7 -0
  114. package/dist/esm/api/resources/tools/client/requests/UpdateToolRequest.d.mts +27 -6
  115. package/dist/esm/api/resources/tools/client/requests/UpdateToolRequest.mjs +8 -1
  116. package/dist/esm/api/types/Agent.d.mts +3 -1
  117. package/dist/esm/api/types/ConfigOptions.d.mts +4 -2
  118. package/dist/esm/api/types/CreateAgentRequest.d.mts +4 -2
  119. package/dist/esm/api/types/ExternalStoragePolicy.d.mts +30 -0
  120. package/dist/esm/api/types/ExternalStoragePolicy.mjs +10 -0
  121. package/dist/esm/api/types/InlineWebSocketTool.d.mts +2 -0
  122. package/dist/esm/api/types/OutboundCallConfig.d.mts +2 -2
  123. package/dist/esm/api/types/Tool.d.mts +26 -2
  124. package/dist/esm/api/types/Tool.mjs +7 -0
  125. package/dist/esm/api/types/ToolParameter.d.mts +5 -2
  126. package/dist/esm/api/types/ToolParameter.mjs +2 -1
  127. package/dist/esm/api/types/ToolParametersJsonSchema.d.mts +15 -0
  128. package/dist/esm/api/types/ToolParametersJsonSchema.mjs +2 -0
  129. package/dist/esm/api/types/index.d.mts +2 -0
  130. package/dist/esm/api/types/index.mjs +2 -0
  131. package/dist/esm/version.d.mts +1 -1
  132. package/dist/esm/version.mjs +1 -1
  133. package/dist/index.d.mts +240 -0
  134. package/dist/index.d.ts +240 -0
  135. package/dist/index.js +347 -0
  136. package/dist/index.mjs +310 -0
  137. package/package.json +12 -1
  138. package/reference.md +363 -0
@@ -3,6 +3,8 @@ export interface ToolParameter {
3
3
  type: ToolParameter.Type;
4
4
  /** Required only when type is "array". The type of items in the array. */
5
5
  item_type?: ToolParameter.ItemType | undefined;
6
+ /** Required only when type is "enum". The fixed set of allowed string values for the parameter. Values must be unique and non-empty. */
7
+ enum_values?: string[] | undefined;
6
8
  /** The parameter name. */
7
9
  name: string;
8
10
  /** Description of the parameter. */
@@ -14,7 +16,7 @@ export interface ToolParameter {
14
16
  * - For GET webhooks: defaults to `"query_string"` and `"request_body"` is not allowed.
15
17
  * - For POST webhooks: required, can be either `"request_body"` or `"query_string"`.
16
18
  * - Not allowed for `custom_websocket`, `built_in_transfer_to_phone_number`, or `built_in_transfer_to_agent` tools.
17
- * When updating a tool's type or endpoint_method, all parameters must include explicit `location` values.
19
+ * When switching a webhook tool's `endpoint_method` from POST to GET, its request body parameters must be re-sent with `"query_string"` locations.
18
20
  */
19
21
  location?: ToolParameter.Location | undefined;
20
22
  }
@@ -26,6 +28,7 @@ export declare namespace ToolParameter {
26
28
  readonly Number: "number";
27
29
  readonly Boolean: "boolean";
28
30
  readonly Array: "array";
31
+ readonly Enum: "enum";
29
32
  };
30
33
  type Type = (typeof Type)[keyof typeof Type];
31
34
  /** Required only when type is "array". The type of items in the array. */
@@ -41,7 +44,7 @@ export declare namespace ToolParameter {
41
44
  * - For GET webhooks: defaults to `"query_string"` and `"request_body"` is not allowed.
42
45
  * - For POST webhooks: required, can be either `"request_body"` or `"query_string"`.
43
46
  * - Not allowed for `custom_websocket`, `built_in_transfer_to_phone_number`, or `built_in_transfer_to_agent` tools.
44
- * When updating a tool's type or endpoint_method, all parameters must include explicit `location` values.
47
+ * When switching a webhook tool's `endpoint_method` from POST to GET, its request body parameters must be re-sent with `"query_string"` locations.
45
48
  */
46
49
  const Location: {
47
50
  readonly RequestBody: "request_body";
@@ -8,6 +8,7 @@ export var ToolParameter;
8
8
  Number: "number",
9
9
  Boolean: "boolean",
10
10
  Array: "array",
11
+ Enum: "enum",
11
12
  };
12
13
  /** Required only when type is "array". The type of items in the array. */
13
14
  ToolParameter.ItemType = {
@@ -21,7 +22,7 @@ export var ToolParameter;
21
22
  * - For GET webhooks: defaults to `"query_string"` and `"request_body"` is not allowed.
22
23
  * - For POST webhooks: required, can be either `"request_body"` or `"query_string"`.
23
24
  * - Not allowed for `custom_websocket`, `built_in_transfer_to_phone_number`, or `built_in_transfer_to_agent` tools.
24
- * When updating a tool's type or endpoint_method, all parameters must include explicit `location` values.
25
+ * When switching a webhook tool's `endpoint_method` from POST to GET, its request body parameters must be re-sent with `"query_string"` locations.
25
26
  */
26
27
  ToolParameter.Location = {
27
28
  RequestBody: "request_body",
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A tool's parameters expressed as a raw JSON Schema object, for parameters that the flat `ToolParameter` list cannot express: nested objects, arrays of objects, `anyOf` variants, `null`, and non-string enums.
3
+ * Each entry in `properties` is a JSON Schema value supporting `type` (`"string"`, `"integer"`, `"number"`, `"boolean"`, `"null"`, `"array"`, `"object"`), `description`, `enum` (string parameters only), `items` (for arrays), `properties`/`required`/`additionalProperties` (for objects) and `anyOf`. Values may be nested up to 5 levels deep.
4
+ * Parameter names cannot be any of the reserved names that Phonic injects into every tool call: `call_info`, `conversation_id`, `from_phone_number`, `to_phone_number`, `twilio_call_sid`.
5
+ * For `custom_webhook` tools, parameter placement is supplied separately in `parameter_locations` rather than inline on the schema.
6
+ */
7
+ export interface ToolParametersJsonSchema {
8
+ type: "object";
9
+ /** The tool's top-level parameters, as a map from parameter name to its JSON Schema. */
10
+ properties: Record<string, unknown>;
11
+ /** The names of the required top-level parameters. Every name must be defined in `properties`. */
12
+ required?: string[] | undefined;
13
+ /** Must be `false`. Tool parameter schemas do not allow properties beyond the ones declared. */
14
+ additionalProperties?: false | undefined;
15
+ }
@@ -0,0 +1,2 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export {};
@@ -33,6 +33,7 @@ export * from "./DataRetentionPolicy.mjs";
33
33
  export * from "./DtmfPayload.mjs";
34
34
  export * from "./Error_.mjs";
35
35
  export * from "./ErrorPayload.mjs";
36
+ export * from "./ExternalStoragePolicy.mjs";
36
37
  export * from "./ExtractionField.mjs";
37
38
  export * from "./ExtractionSchema.mjs";
38
39
  export * from "./GenerateReplyPayload.mjs";
@@ -67,6 +68,7 @@ export * from "./ToolCallPayload.mjs";
67
68
  export * from "./ToolDefinition.mjs";
68
69
  export * from "./ToolName.mjs";
69
70
  export * from "./ToolParameter.mjs";
71
+ export * from "./ToolParametersJsonSchema.mjs";
70
72
  export * from "./UnmutePayload.mjs";
71
73
  export * from "./UpdateSystemPromptPayload.mjs";
72
74
  export * from "./UpdateToolsSubsetPayload.mjs";
@@ -33,6 +33,7 @@ export * from "./DataRetentionPolicy.mjs";
33
33
  export * from "./DtmfPayload.mjs";
34
34
  export * from "./Error_.mjs";
35
35
  export * from "./ErrorPayload.mjs";
36
+ export * from "./ExternalStoragePolicy.mjs";
36
37
  export * from "./ExtractionField.mjs";
37
38
  export * from "./ExtractionSchema.mjs";
38
39
  export * from "./GenerateReplyPayload.mjs";
@@ -67,6 +68,7 @@ export * from "./ToolCallPayload.mjs";
67
68
  export * from "./ToolDefinition.mjs";
68
69
  export * from "./ToolName.mjs";
69
70
  export * from "./ToolParameter.mjs";
71
+ export * from "./ToolParametersJsonSchema.mjs";
70
72
  export * from "./UnmutePayload.mjs";
71
73
  export * from "./UpdateSystemPromptPayload.mjs";
72
74
  export * from "./UpdateToolsSubsetPayload.mjs";
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.32.11";
1
+ export declare const SDK_VERSION = "0.32.13";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.32.11";
1
+ export const SDK_VERSION = "0.32.13";
@@ -0,0 +1,240 @@
1
+ import WebSocket from 'ws';
2
+
3
+ type PhonicConfig = {
4
+ baseUrl?: string;
5
+ headers?: Record<string, string>;
6
+ __downstreamWebSocketUrl?: string;
7
+ };
8
+ type FetchOptions = {
9
+ method: "GET";
10
+ headers?: Record<string, string>;
11
+ } | {
12
+ method: "POST";
13
+ headers?: Record<string, string>;
14
+ body: string;
15
+ };
16
+ type DataOrError<T> = Promise<{
17
+ data: T;
18
+ error: null;
19
+ } | {
20
+ data: null;
21
+ error: {
22
+ message: string;
23
+ code?: string;
24
+ };
25
+ }>;
26
+ type ISODate = `${string}-${string}-${string}`;
27
+ type ISODateTime$1 = `${string}Z`;
28
+
29
+ type ISODateTime = `${string}Z`;
30
+ type ConversationItem = {
31
+ role: "user";
32
+ item_idx: number;
33
+ text: string;
34
+ duration_ms: number;
35
+ started_at: string;
36
+ } | {
37
+ role: "assistant";
38
+ item_idx: number;
39
+ text: string;
40
+ voice_id: string;
41
+ system_prompt: string;
42
+ output_audio_speed: number;
43
+ duration_ms: number;
44
+ started_at: string;
45
+ };
46
+ type Conversation = {
47
+ id: string;
48
+ external_id: string | null;
49
+ model: string;
50
+ welcome_message: string | null;
51
+ input_format: "pcm_44100" | "mulaw_8000";
52
+ output_format: "pcm_44100" | "mulaw_8000";
53
+ text: string;
54
+ duration_ms: number;
55
+ started_at: ISODateTime;
56
+ ended_at: ISODateTime;
57
+ items: Array<ConversationItem>;
58
+ };
59
+ type ConversationSuccessResponse = {
60
+ conversation: Conversation;
61
+ };
62
+ type ConversationsSuccessResponse = {
63
+ conversations: Array<Conversation>;
64
+ };
65
+
66
+ declare class Conversations {
67
+ private readonly phonic;
68
+ constructor(phonic: Phonic);
69
+ get(id: string): DataOrError<ConversationSuccessResponse>;
70
+ getByExternalId({ project, externalId, }: {
71
+ project?: string;
72
+ externalId: string;
73
+ }): DataOrError<ConversationSuccessResponse>;
74
+ list({ project, durationMin, durationMax, startedAtMin, startedAtMax, }: {
75
+ project?: string;
76
+ durationMin?: number;
77
+ durationMax?: number;
78
+ startedAtMin?: ISODate | ISODateTime$1;
79
+ startedAtMax?: ISODate | ISODateTime$1;
80
+ }): DataOrError<ConversationsSuccessResponse>;
81
+ }
82
+
83
+ type PhonicSTSConfig = {
84
+ project: string;
85
+ input_format: "pcm_44100" | "mulaw_8000";
86
+ system_prompt?: string;
87
+ welcome_message?: string;
88
+ voice_id?: string;
89
+ output_format?: "pcm_44100" | "mulaw_8000";
90
+ enable_silent_audio_fallback?: boolean;
91
+ experimental_params?: Record<string, unknown>;
92
+ tools?: string[];
93
+ vad_prebuffer_duration_ms?: number;
94
+ vad_min_speech_duration_ms?: number;
95
+ vad_min_silence_duration_ms?: number;
96
+ vad_threshold?: number;
97
+ };
98
+ type PhonicSTSWebSocketResponseMessage = {
99
+ type: "ready_to_start_conversation";
100
+ } | {
101
+ type: "input_text";
102
+ text: string;
103
+ } | {
104
+ type: "audio_chunk";
105
+ text: string;
106
+ audio: string;
107
+ } | {
108
+ type: "is_user_speaking";
109
+ isUserSpeaking: boolean;
110
+ } | {
111
+ type: "interrupted_response";
112
+ interruptedResponse: string;
113
+ } | {
114
+ type: "assistant_ended_conversation";
115
+ } | {
116
+ type: "error";
117
+ error: {
118
+ message: string;
119
+ code?: string;
120
+ };
121
+ param_errors?: {
122
+ input_format?: string;
123
+ system_prompt?: string;
124
+ welcome_message?: string;
125
+ voice_id?: string;
126
+ output_format?: string;
127
+ };
128
+ };
129
+ type OnMessageCallback = (message: PhonicSTSWebSocketResponseMessage) => void;
130
+ type OnCloseCallback = (event: WebSocket.CloseEvent) => void;
131
+ type OnErrorCallback = (event: WebSocket.ErrorEvent) => void;
132
+ type PhonicSTSOutboundCallConfig = Omit<PhonicSTSConfig, "input_format" | "output_format">;
133
+ type OutboundCallSuccessResponse = {
134
+ success: true;
135
+ };
136
+
137
+ type PhonicSTSTwilioOutboundCallParams = {
138
+ account_sid: string;
139
+ api_key_sid: string;
140
+ api_key_secret: string;
141
+ from_phone_number: string;
142
+ to_phone_number: string;
143
+ };
144
+ type PhonicSTSTwilioOutboundCallConfig = PhonicSTSOutboundCallConfig;
145
+ type TwilioOutboundCallSuccessResponse = {
146
+ success: true;
147
+ callSid: string;
148
+ };
149
+
150
+ declare class Twilio {
151
+ private readonly phonic;
152
+ constructor(phonic: Phonic);
153
+ outboundCall(params: PhonicSTSTwilioOutboundCallParams, config: PhonicSTSTwilioOutboundCallConfig): DataOrError<TwilioOutboundCallSuccessResponse>;
154
+ }
155
+
156
+ declare class PhonicSTSWebSocket {
157
+ private readonly ws;
158
+ private readonly config;
159
+ private onMessageCallback;
160
+ private onCloseCallback;
161
+ private onErrorCallback;
162
+ private buffer;
163
+ private isOpen;
164
+ constructor(ws: WebSocket, config: PhonicSTSConfig);
165
+ onMessage(callback: OnMessageCallback): void;
166
+ onClose(callback: OnCloseCallback): void;
167
+ onError(callback: OnErrorCallback): void;
168
+ audioChunk({ audio }: {
169
+ audio: string;
170
+ }): void;
171
+ updateSystemPrompt({ systemPrompt }: {
172
+ systemPrompt: string;
173
+ }): void;
174
+ setExternalId({ externalId }: {
175
+ externalId: string;
176
+ }): void;
177
+ close(code?: number): void;
178
+ }
179
+
180
+ declare class SpeechToSpeech {
181
+ private readonly phonic;
182
+ readonly twilio: Twilio;
183
+ constructor(phonic: Phonic);
184
+ websocket(config: PhonicSTSConfig): PhonicSTSWebSocket;
185
+ outboundCall(toPhoneNumber: string, config: PhonicSTSOutboundCallConfig): DataOrError<OutboundCallSuccessResponse>;
186
+ }
187
+
188
+ type Voice = {
189
+ id: string;
190
+ name: string;
191
+ };
192
+ type VoicesSuccessResponse = {
193
+ voices: Array<Voice>;
194
+ };
195
+ type VoiceSuccessResponse = {
196
+ voice: Voice;
197
+ };
198
+
199
+ declare class Voices {
200
+ private readonly phonic;
201
+ constructor(phonic: Phonic);
202
+ list({ model }: {
203
+ model: string;
204
+ }): DataOrError<VoicesSuccessResponse>;
205
+ get(id: string): DataOrError<VoiceSuccessResponse>;
206
+ }
207
+
208
+ declare class Phonic {
209
+ readonly apiKey: string;
210
+ readonly baseUrl: string;
211
+ readonly __downstreamWebSocketUrl: string | null;
212
+ readonly headers: Record<string, string>;
213
+ readonly conversations: Conversations;
214
+ readonly voices: Voices;
215
+ readonly sts: SpeechToSpeech;
216
+ constructor(apiKey: string, config?: PhonicConfig);
217
+ fetchRequest<T>(path: string, options: FetchOptions): DataOrError<T>;
218
+ get<T>(path: string): Promise<{
219
+ data: null;
220
+ error: {
221
+ message: string;
222
+ code?: string;
223
+ };
224
+ } | {
225
+ data: T;
226
+ error: null;
227
+ }>;
228
+ post<T>(path: string, body: Record<string, unknown>, headers?: Record<string, string>): Promise<{
229
+ data: null;
230
+ error: {
231
+ message: string;
232
+ code?: string;
233
+ };
234
+ } | {
235
+ data: T;
236
+ error: null;
237
+ }>;
238
+ }
239
+
240
+ export { Phonic, type PhonicSTSConfig, PhonicSTSWebSocket };
@@ -0,0 +1,240 @@
1
+ import WebSocket from 'ws';
2
+
3
+ type PhonicConfig = {
4
+ baseUrl?: string;
5
+ headers?: Record<string, string>;
6
+ __downstreamWebSocketUrl?: string;
7
+ };
8
+ type FetchOptions = {
9
+ method: "GET";
10
+ headers?: Record<string, string>;
11
+ } | {
12
+ method: "POST";
13
+ headers?: Record<string, string>;
14
+ body: string;
15
+ };
16
+ type DataOrError<T> = Promise<{
17
+ data: T;
18
+ error: null;
19
+ } | {
20
+ data: null;
21
+ error: {
22
+ message: string;
23
+ code?: string;
24
+ };
25
+ }>;
26
+ type ISODate = `${string}-${string}-${string}`;
27
+ type ISODateTime$1 = `${string}Z`;
28
+
29
+ type ISODateTime = `${string}Z`;
30
+ type ConversationItem = {
31
+ role: "user";
32
+ item_idx: number;
33
+ text: string;
34
+ duration_ms: number;
35
+ started_at: string;
36
+ } | {
37
+ role: "assistant";
38
+ item_idx: number;
39
+ text: string;
40
+ voice_id: string;
41
+ system_prompt: string;
42
+ output_audio_speed: number;
43
+ duration_ms: number;
44
+ started_at: string;
45
+ };
46
+ type Conversation = {
47
+ id: string;
48
+ external_id: string | null;
49
+ model: string;
50
+ welcome_message: string | null;
51
+ input_format: "pcm_44100" | "mulaw_8000";
52
+ output_format: "pcm_44100" | "mulaw_8000";
53
+ text: string;
54
+ duration_ms: number;
55
+ started_at: ISODateTime;
56
+ ended_at: ISODateTime;
57
+ items: Array<ConversationItem>;
58
+ };
59
+ type ConversationSuccessResponse = {
60
+ conversation: Conversation;
61
+ };
62
+ type ConversationsSuccessResponse = {
63
+ conversations: Array<Conversation>;
64
+ };
65
+
66
+ declare class Conversations {
67
+ private readonly phonic;
68
+ constructor(phonic: Phonic);
69
+ get(id: string): DataOrError<ConversationSuccessResponse>;
70
+ getByExternalId({ project, externalId, }: {
71
+ project?: string;
72
+ externalId: string;
73
+ }): DataOrError<ConversationSuccessResponse>;
74
+ list({ project, durationMin, durationMax, startedAtMin, startedAtMax, }: {
75
+ project?: string;
76
+ durationMin?: number;
77
+ durationMax?: number;
78
+ startedAtMin?: ISODate | ISODateTime$1;
79
+ startedAtMax?: ISODate | ISODateTime$1;
80
+ }): DataOrError<ConversationsSuccessResponse>;
81
+ }
82
+
83
+ type PhonicSTSConfig = {
84
+ project: string;
85
+ input_format: "pcm_44100" | "mulaw_8000";
86
+ system_prompt?: string;
87
+ welcome_message?: string;
88
+ voice_id?: string;
89
+ output_format?: "pcm_44100" | "mulaw_8000";
90
+ enable_silent_audio_fallback?: boolean;
91
+ experimental_params?: Record<string, unknown>;
92
+ tools?: string[];
93
+ vad_prebuffer_duration_ms?: number;
94
+ vad_min_speech_duration_ms?: number;
95
+ vad_min_silence_duration_ms?: number;
96
+ vad_threshold?: number;
97
+ };
98
+ type PhonicSTSWebSocketResponseMessage = {
99
+ type: "ready_to_start_conversation";
100
+ } | {
101
+ type: "input_text";
102
+ text: string;
103
+ } | {
104
+ type: "audio_chunk";
105
+ text: string;
106
+ audio: string;
107
+ } | {
108
+ type: "is_user_speaking";
109
+ isUserSpeaking: boolean;
110
+ } | {
111
+ type: "interrupted_response";
112
+ interruptedResponse: string;
113
+ } | {
114
+ type: "assistant_ended_conversation";
115
+ } | {
116
+ type: "error";
117
+ error: {
118
+ message: string;
119
+ code?: string;
120
+ };
121
+ param_errors?: {
122
+ input_format?: string;
123
+ system_prompt?: string;
124
+ welcome_message?: string;
125
+ voice_id?: string;
126
+ output_format?: string;
127
+ };
128
+ };
129
+ type OnMessageCallback = (message: PhonicSTSWebSocketResponseMessage) => void;
130
+ type OnCloseCallback = (event: WebSocket.CloseEvent) => void;
131
+ type OnErrorCallback = (event: WebSocket.ErrorEvent) => void;
132
+ type PhonicSTSOutboundCallConfig = Omit<PhonicSTSConfig, "input_format" | "output_format">;
133
+ type OutboundCallSuccessResponse = {
134
+ success: true;
135
+ };
136
+
137
+ type PhonicSTSTwilioOutboundCallParams = {
138
+ account_sid: string;
139
+ api_key_sid: string;
140
+ api_key_secret: string;
141
+ from_phone_number: string;
142
+ to_phone_number: string;
143
+ };
144
+ type PhonicSTSTwilioOutboundCallConfig = PhonicSTSOutboundCallConfig;
145
+ type TwilioOutboundCallSuccessResponse = {
146
+ success: true;
147
+ callSid: string;
148
+ };
149
+
150
+ declare class Twilio {
151
+ private readonly phonic;
152
+ constructor(phonic: Phonic);
153
+ outboundCall(params: PhonicSTSTwilioOutboundCallParams, config: PhonicSTSTwilioOutboundCallConfig): DataOrError<TwilioOutboundCallSuccessResponse>;
154
+ }
155
+
156
+ declare class PhonicSTSWebSocket {
157
+ private readonly ws;
158
+ private readonly config;
159
+ private onMessageCallback;
160
+ private onCloseCallback;
161
+ private onErrorCallback;
162
+ private buffer;
163
+ private isOpen;
164
+ constructor(ws: WebSocket, config: PhonicSTSConfig);
165
+ onMessage(callback: OnMessageCallback): void;
166
+ onClose(callback: OnCloseCallback): void;
167
+ onError(callback: OnErrorCallback): void;
168
+ audioChunk({ audio }: {
169
+ audio: string;
170
+ }): void;
171
+ updateSystemPrompt({ systemPrompt }: {
172
+ systemPrompt: string;
173
+ }): void;
174
+ setExternalId({ externalId }: {
175
+ externalId: string;
176
+ }): void;
177
+ close(code?: number): void;
178
+ }
179
+
180
+ declare class SpeechToSpeech {
181
+ private readonly phonic;
182
+ readonly twilio: Twilio;
183
+ constructor(phonic: Phonic);
184
+ websocket(config: PhonicSTSConfig): PhonicSTSWebSocket;
185
+ outboundCall(toPhoneNumber: string, config: PhonicSTSOutboundCallConfig): DataOrError<OutboundCallSuccessResponse>;
186
+ }
187
+
188
+ type Voice = {
189
+ id: string;
190
+ name: string;
191
+ };
192
+ type VoicesSuccessResponse = {
193
+ voices: Array<Voice>;
194
+ };
195
+ type VoiceSuccessResponse = {
196
+ voice: Voice;
197
+ };
198
+
199
+ declare class Voices {
200
+ private readonly phonic;
201
+ constructor(phonic: Phonic);
202
+ list({ model }: {
203
+ model: string;
204
+ }): DataOrError<VoicesSuccessResponse>;
205
+ get(id: string): DataOrError<VoiceSuccessResponse>;
206
+ }
207
+
208
+ declare class Phonic {
209
+ readonly apiKey: string;
210
+ readonly baseUrl: string;
211
+ readonly __downstreamWebSocketUrl: string | null;
212
+ readonly headers: Record<string, string>;
213
+ readonly conversations: Conversations;
214
+ readonly voices: Voices;
215
+ readonly sts: SpeechToSpeech;
216
+ constructor(apiKey: string, config?: PhonicConfig);
217
+ fetchRequest<T>(path: string, options: FetchOptions): DataOrError<T>;
218
+ get<T>(path: string): Promise<{
219
+ data: null;
220
+ error: {
221
+ message: string;
222
+ code?: string;
223
+ };
224
+ } | {
225
+ data: T;
226
+ error: null;
227
+ }>;
228
+ post<T>(path: string, body: Record<string, unknown>, headers?: Record<string, string>): Promise<{
229
+ data: null;
230
+ error: {
231
+ message: string;
232
+ code?: string;
233
+ };
234
+ } | {
235
+ data: T;
236
+ error: null;
237
+ }>;
238
+ }
239
+
240
+ export { Phonic, type PhonicSTSConfig, PhonicSTSWebSocket };