phonic 0.30.3 → 0.30.4

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 (387) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/Client.js +2 -2
  3. package/dist/cjs/version.d.ts +1 -1
  4. package/dist/cjs/version.js +1 -1
  5. package/dist/esm/Client.d.mts +50 -0
  6. package/dist/esm/Client.mjs +47 -0
  7. package/dist/esm/api/errors/BadRequestError.d.mts +8 -0
  8. package/dist/esm/api/errors/BadRequestError.mjs +15 -0
  9. package/dist/esm/api/errors/ConflictError.d.mts +8 -0
  10. package/dist/esm/api/errors/ConflictError.mjs +15 -0
  11. package/dist/esm/api/errors/ForbiddenError.d.mts +8 -0
  12. package/dist/esm/api/errors/ForbiddenError.mjs +15 -0
  13. package/dist/esm/api/errors/GatewayTimeoutError.d.mts +9 -0
  14. package/dist/esm/api/errors/GatewayTimeoutError.mjs +15 -0
  15. package/dist/esm/api/errors/InternalServerError.d.mts +9 -0
  16. package/dist/esm/api/errors/InternalServerError.mjs +15 -0
  17. package/dist/esm/api/errors/NotFoundError.d.mts +8 -0
  18. package/dist/esm/api/errors/NotFoundError.mjs +15 -0
  19. package/dist/esm/api/errors/UnauthorizedError.d.mts +9 -0
  20. package/dist/esm/api/errors/UnauthorizedError.mjs +15 -0
  21. package/dist/esm/api/errors/index.d.mts +7 -0
  22. package/dist/esm/api/errors/index.mjs +7 -0
  23. package/dist/esm/api/index.d.mts +4 -0
  24. package/dist/esm/api/index.mjs +4 -0
  25. package/dist/esm/api/resources/agents/client/Client.d.mts +208 -0
  26. package/dist/esm/api/resources/agents/client/Client.mjs +558 -0
  27. package/dist/esm/api/resources/agents/client/index.d.mts +2 -0
  28. package/dist/esm/api/resources/agents/client/index.mjs +1 -0
  29. package/dist/esm/api/resources/agents/client/requests/AgentsCreateRequest.d.mts +41 -0
  30. package/dist/esm/api/resources/agents/client/requests/AgentsCreateRequest.mjs +4 -0
  31. package/dist/esm/api/resources/agents/client/requests/AgentsDeleteRequest.d.mts +13 -0
  32. package/dist/esm/api/resources/agents/client/requests/AgentsDeleteRequest.mjs +4 -0
  33. package/dist/esm/api/resources/agents/client/requests/AgentsGetRequest.d.mts +13 -0
  34. package/dist/esm/api/resources/agents/client/requests/AgentsGetRequest.mjs +4 -0
  35. package/dist/esm/api/resources/agents/client/requests/AgentsListRequest.d.mts +11 -0
  36. package/dist/esm/api/resources/agents/client/requests/AgentsListRequest.mjs +4 -0
  37. package/dist/esm/api/resources/agents/client/requests/UpdateAgentRequest.d.mts +102 -0
  38. package/dist/esm/api/resources/agents/client/requests/UpdateAgentRequest.mjs +10 -0
  39. package/dist/esm/api/resources/agents/client/requests/UpsertAgentRequest.d.mts +38 -0
  40. package/dist/esm/api/resources/agents/client/requests/UpsertAgentRequest.mjs +4 -0
  41. package/dist/esm/api/resources/agents/client/requests/index.d.mts +6 -0
  42. package/dist/esm/api/resources/agents/client/requests/index.mjs +1 -0
  43. package/dist/esm/api/resources/agents/index.d.mts +2 -0
  44. package/dist/esm/api/resources/agents/index.mjs +2 -0
  45. package/dist/esm/api/resources/agents/types/AgentsCreateResponse.d.mts +9 -0
  46. package/dist/esm/api/resources/agents/types/AgentsCreateResponse.mjs +4 -0
  47. package/dist/esm/api/resources/agents/types/AgentsDeleteResponse.d.mts +7 -0
  48. package/dist/esm/api/resources/agents/types/AgentsDeleteResponse.mjs +4 -0
  49. package/dist/esm/api/resources/agents/types/AgentsGetResponse.d.mts +7 -0
  50. package/dist/esm/api/resources/agents/types/AgentsGetResponse.mjs +4 -0
  51. package/dist/esm/api/resources/agents/types/AgentsListResponse.d.mts +7 -0
  52. package/dist/esm/api/resources/agents/types/AgentsListResponse.mjs +4 -0
  53. package/dist/esm/api/resources/agents/types/AgentsUpdateResponse.d.mts +7 -0
  54. package/dist/esm/api/resources/agents/types/AgentsUpdateResponse.mjs +4 -0
  55. package/dist/esm/api/resources/agents/types/AgentsUpsertResponse.d.mts +11 -0
  56. package/dist/esm/api/resources/agents/types/AgentsUpsertResponse.mjs +4 -0
  57. package/dist/esm/api/resources/agents/types/index.d.mts +6 -0
  58. package/dist/esm/api/resources/agents/types/index.mjs +6 -0
  59. package/dist/esm/api/resources/conversations/client/Client.d.mts +236 -0
  60. package/dist/esm/api/resources/conversations/client/Client.mjs +858 -0
  61. package/dist/esm/api/resources/conversations/client/Socket.d.mts +64 -0
  62. package/dist/esm/api/resources/conversations/client/Socket.mjs +159 -0
  63. package/dist/esm/api/resources/conversations/client/index.d.mts +2 -0
  64. package/dist/esm/api/resources/conversations/client/index.mjs +1 -0
  65. package/dist/esm/api/resources/conversations/client/requests/ConversationsListRequest.d.mts +30 -0
  66. package/dist/esm/api/resources/conversations/client/requests/ConversationsListRequest.mjs +4 -0
  67. package/dist/esm/api/resources/conversations/client/requests/ConversationsSipOutboundCallRequest.d.mts +29 -0
  68. package/dist/esm/api/resources/conversations/client/requests/ConversationsSipOutboundCallRequest.mjs +4 -0
  69. package/dist/esm/api/resources/conversations/client/requests/EvaluateConversationRequest.d.mts +13 -0
  70. package/dist/esm/api/resources/conversations/client/requests/EvaluateConversationRequest.mjs +4 -0
  71. package/dist/esm/api/resources/conversations/client/requests/ExtractDataRequest.d.mts +13 -0
  72. package/dist/esm/api/resources/conversations/client/requests/ExtractDataRequest.mjs +4 -0
  73. package/dist/esm/api/resources/conversations/client/requests/OutboundCallRequest.d.mts +30 -0
  74. package/dist/esm/api/resources/conversations/client/requests/OutboundCallRequest.mjs +4 -0
  75. package/dist/esm/api/resources/conversations/client/requests/index.d.mts +5 -0
  76. package/dist/esm/api/resources/conversations/client/requests/index.mjs +1 -0
  77. package/dist/esm/api/resources/conversations/index.d.mts +2 -0
  78. package/dist/esm/api/resources/conversations/index.mjs +2 -0
  79. package/dist/esm/api/resources/conversations/types/ConversationsCancelResponse.d.mts +7 -0
  80. package/dist/esm/api/resources/conversations/types/ConversationsCancelResponse.mjs +4 -0
  81. package/dist/esm/api/resources/conversations/types/ConversationsExtractDataResponse.d.mts +7 -0
  82. package/dist/esm/api/resources/conversations/types/ConversationsExtractDataResponse.mjs +4 -0
  83. package/dist/esm/api/resources/conversations/types/ConversationsGetAnalysisResponse.d.mts +7 -0
  84. package/dist/esm/api/resources/conversations/types/ConversationsGetAnalysisResponse.mjs +4 -0
  85. package/dist/esm/api/resources/conversations/types/ConversationsGetResponse.d.mts +7 -0
  86. package/dist/esm/api/resources/conversations/types/ConversationsGetResponse.mjs +4 -0
  87. package/dist/esm/api/resources/conversations/types/ConversationsListEvaluationsResponse.d.mts +7 -0
  88. package/dist/esm/api/resources/conversations/types/ConversationsListEvaluationsResponse.mjs +4 -0
  89. package/dist/esm/api/resources/conversations/types/ConversationsListExtractionsResponse.d.mts +7 -0
  90. package/dist/esm/api/resources/conversations/types/ConversationsListExtractionsResponse.mjs +4 -0
  91. package/dist/esm/api/resources/conversations/types/ConversationsListResponse.d.mts +9 -0
  92. package/dist/esm/api/resources/conversations/types/ConversationsListResponse.mjs +4 -0
  93. package/dist/esm/api/resources/conversations/types/ConversationsOutboundCallResponse.d.mts +7 -0
  94. package/dist/esm/api/resources/conversations/types/ConversationsOutboundCallResponse.mjs +4 -0
  95. package/dist/esm/api/resources/conversations/types/ConversationsSipOutboundCallResponse.d.mts +7 -0
  96. package/dist/esm/api/resources/conversations/types/ConversationsSipOutboundCallResponse.mjs +4 -0
  97. package/dist/esm/api/resources/conversations/types/index.d.mts +9 -0
  98. package/dist/esm/api/resources/conversations/types/index.mjs +9 -0
  99. package/dist/esm/api/resources/extractionSchemas/client/Client.d.mts +142 -0
  100. package/dist/esm/api/resources/extractionSchemas/client/Client.mjs +436 -0
  101. package/dist/esm/api/resources/extractionSchemas/client/index.d.mts +2 -0
  102. package/dist/esm/api/resources/extractionSchemas/client/index.mjs +1 -0
  103. package/dist/esm/api/resources/extractionSchemas/client/requests/CreateExtractionSchemaRequest.d.mts +35 -0
  104. package/dist/esm/api/resources/extractionSchemas/client/requests/CreateExtractionSchemaRequest.mjs +4 -0
  105. package/dist/esm/api/resources/extractionSchemas/client/requests/ExtractionSchemasDeleteRequest.d.mts +13 -0
  106. package/dist/esm/api/resources/extractionSchemas/client/requests/ExtractionSchemasDeleteRequest.mjs +4 -0
  107. package/dist/esm/api/resources/extractionSchemas/client/requests/ExtractionSchemasGetRequest.d.mts +13 -0
  108. package/dist/esm/api/resources/extractionSchemas/client/requests/ExtractionSchemasGetRequest.mjs +4 -0
  109. package/dist/esm/api/resources/extractionSchemas/client/requests/ExtractionSchemasListRequest.d.mts +13 -0
  110. package/dist/esm/api/resources/extractionSchemas/client/requests/ExtractionSchemasListRequest.mjs +4 -0
  111. package/dist/esm/api/resources/extractionSchemas/client/requests/UpdateExtractionSchemaRequest.d.mts +31 -0
  112. package/dist/esm/api/resources/extractionSchemas/client/requests/UpdateExtractionSchemaRequest.mjs +4 -0
  113. package/dist/esm/api/resources/extractionSchemas/client/requests/index.d.mts +5 -0
  114. package/dist/esm/api/resources/extractionSchemas/client/requests/index.mjs +1 -0
  115. package/dist/esm/api/resources/extractionSchemas/index.d.mts +2 -0
  116. package/dist/esm/api/resources/extractionSchemas/index.mjs +2 -0
  117. package/dist/esm/api/resources/extractionSchemas/types/ExtractionSchemasCreateResponse.d.mts +9 -0
  118. package/dist/esm/api/resources/extractionSchemas/types/ExtractionSchemasCreateResponse.mjs +4 -0
  119. package/dist/esm/api/resources/extractionSchemas/types/ExtractionSchemasDeleteResponse.d.mts +7 -0
  120. package/dist/esm/api/resources/extractionSchemas/types/ExtractionSchemasDeleteResponse.mjs +4 -0
  121. package/dist/esm/api/resources/extractionSchemas/types/ExtractionSchemasGetResponse.d.mts +7 -0
  122. package/dist/esm/api/resources/extractionSchemas/types/ExtractionSchemasGetResponse.mjs +4 -0
  123. package/dist/esm/api/resources/extractionSchemas/types/ExtractionSchemasListResponse.d.mts +7 -0
  124. package/dist/esm/api/resources/extractionSchemas/types/ExtractionSchemasListResponse.mjs +4 -0
  125. package/dist/esm/api/resources/extractionSchemas/types/ExtractionSchemasUpdateResponse.d.mts +7 -0
  126. package/dist/esm/api/resources/extractionSchemas/types/ExtractionSchemasUpdateResponse.mjs +4 -0
  127. package/dist/esm/api/resources/extractionSchemas/types/index.d.mts +5 -0
  128. package/dist/esm/api/resources/extractionSchemas/types/index.mjs +5 -0
  129. package/dist/esm/api/resources/index.d.mts +18 -0
  130. package/dist/esm/api/resources/index.mjs +18 -0
  131. package/dist/esm/api/resources/projects/client/Client.d.mts +157 -0
  132. package/dist/esm/api/resources/projects/client/Client.mjs +547 -0
  133. package/dist/esm/api/resources/projects/client/index.d.mts +2 -0
  134. package/dist/esm/api/resources/projects/client/index.mjs +1 -0
  135. package/dist/esm/api/resources/projects/client/requests/CreateConversationEvalPromptRequest.d.mts +16 -0
  136. package/dist/esm/api/resources/projects/client/requests/CreateConversationEvalPromptRequest.mjs +4 -0
  137. package/dist/esm/api/resources/projects/client/requests/CreateProjectRequest.d.mts +13 -0
  138. package/dist/esm/api/resources/projects/client/requests/CreateProjectRequest.mjs +4 -0
  139. package/dist/esm/api/resources/projects/client/requests/UpdateProjectRequest.d.mts +15 -0
  140. package/dist/esm/api/resources/projects/client/requests/UpdateProjectRequest.mjs +4 -0
  141. package/dist/esm/api/resources/projects/client/requests/index.d.mts +3 -0
  142. package/dist/esm/api/resources/projects/client/requests/index.mjs +1 -0
  143. package/dist/esm/api/resources/projects/index.d.mts +2 -0
  144. package/dist/esm/api/resources/projects/index.mjs +2 -0
  145. package/dist/esm/api/resources/projects/types/ProjectsCreateEvalPromptResponse.d.mts +7 -0
  146. package/dist/esm/api/resources/projects/types/ProjectsCreateEvalPromptResponse.mjs +4 -0
  147. package/dist/esm/api/resources/projects/types/ProjectsCreateResponse.d.mts +9 -0
  148. package/dist/esm/api/resources/projects/types/ProjectsCreateResponse.mjs +4 -0
  149. package/dist/esm/api/resources/projects/types/ProjectsDeleteResponse.d.mts +7 -0
  150. package/dist/esm/api/resources/projects/types/ProjectsDeleteResponse.mjs +4 -0
  151. package/dist/esm/api/resources/projects/types/ProjectsGetResponse.d.mts +7 -0
  152. package/dist/esm/api/resources/projects/types/ProjectsGetResponse.mjs +4 -0
  153. package/dist/esm/api/resources/projects/types/ProjectsListEvalPromptsResponse.d.mts +7 -0
  154. package/dist/esm/api/resources/projects/types/ProjectsListEvalPromptsResponse.mjs +4 -0
  155. package/dist/esm/api/resources/projects/types/ProjectsListResponse.d.mts +7 -0
  156. package/dist/esm/api/resources/projects/types/ProjectsListResponse.mjs +4 -0
  157. package/dist/esm/api/resources/projects/types/ProjectsUpdateResponse.d.mts +7 -0
  158. package/dist/esm/api/resources/projects/types/ProjectsUpdateResponse.mjs +4 -0
  159. package/dist/esm/api/resources/projects/types/index.d.mts +7 -0
  160. package/dist/esm/api/resources/projects/types/index.mjs +7 -0
  161. package/dist/esm/api/resources/tools/client/Client.d.mts +170 -0
  162. package/dist/esm/api/resources/tools/client/Client.mjs +457 -0
  163. package/dist/esm/api/resources/tools/client/index.d.mts +2 -0
  164. package/dist/esm/api/resources/tools/client/index.mjs +1 -0
  165. package/dist/esm/api/resources/tools/client/requests/CreateToolRequest.d.mts +103 -0
  166. package/dist/esm/api/resources/tools/client/requests/CreateToolRequest.mjs +15 -0
  167. package/dist/esm/api/resources/tools/client/requests/ToolsDeleteRequest.d.mts +13 -0
  168. package/dist/esm/api/resources/tools/client/requests/ToolsDeleteRequest.mjs +4 -0
  169. package/dist/esm/api/resources/tools/client/requests/ToolsGetRequest.d.mts +23 -0
  170. package/dist/esm/api/resources/tools/client/requests/ToolsGetRequest.mjs +4 -0
  171. package/dist/esm/api/resources/tools/client/requests/ToolsListRequest.d.mts +13 -0
  172. package/dist/esm/api/resources/tools/client/requests/ToolsListRequest.mjs +4 -0
  173. package/dist/esm/api/resources/tools/client/requests/UpdateToolRequest.d.mts +55 -0
  174. package/dist/esm/api/resources/tools/client/requests/UpdateToolRequest.mjs +15 -0
  175. package/dist/esm/api/resources/tools/client/requests/index.d.mts +5 -0
  176. package/dist/esm/api/resources/tools/client/requests/index.mjs +1 -0
  177. package/dist/esm/api/resources/tools/index.d.mts +2 -0
  178. package/dist/esm/api/resources/tools/index.mjs +2 -0
  179. package/dist/esm/api/resources/tools/types/ToolsCreateResponse.d.mts +9 -0
  180. package/dist/esm/api/resources/tools/types/ToolsCreateResponse.mjs +4 -0
  181. package/dist/esm/api/resources/tools/types/ToolsDeleteResponse.d.mts +7 -0
  182. package/dist/esm/api/resources/tools/types/ToolsDeleteResponse.mjs +4 -0
  183. package/dist/esm/api/resources/tools/types/ToolsGetResponse.d.mts +7 -0
  184. package/dist/esm/api/resources/tools/types/ToolsGetResponse.mjs +4 -0
  185. package/dist/esm/api/resources/tools/types/ToolsListResponse.d.mts +7 -0
  186. package/dist/esm/api/resources/tools/types/ToolsListResponse.mjs +4 -0
  187. package/dist/esm/api/resources/tools/types/ToolsUpdateResponse.d.mts +7 -0
  188. package/dist/esm/api/resources/tools/types/ToolsUpdateResponse.mjs +4 -0
  189. package/dist/esm/api/resources/tools/types/index.d.mts +5 -0
  190. package/dist/esm/api/resources/tools/types/index.mjs +5 -0
  191. package/dist/esm/api/resources/voices/client/Client.d.mts +65 -0
  192. package/dist/esm/api/resources/voices/client/Client.mjs +168 -0
  193. package/dist/esm/api/resources/voices/client/index.d.mts +2 -0
  194. package/dist/esm/api/resources/voices/client/index.mjs +1 -0
  195. package/dist/esm/api/resources/voices/client/requests/VoicesListRequest.d.mts +13 -0
  196. package/dist/esm/api/resources/voices/client/requests/VoicesListRequest.mjs +4 -0
  197. package/dist/esm/api/resources/voices/client/requests/index.d.mts +1 -0
  198. package/dist/esm/api/resources/voices/client/requests/index.mjs +1 -0
  199. package/dist/esm/api/resources/voices/index.d.mts +2 -0
  200. package/dist/esm/api/resources/voices/index.mjs +2 -0
  201. package/dist/esm/api/resources/voices/types/VoicesGetResponse.d.mts +7 -0
  202. package/dist/esm/api/resources/voices/types/VoicesGetResponse.mjs +4 -0
  203. package/dist/esm/api/resources/voices/types/VoicesListResponse.d.mts +7 -0
  204. package/dist/esm/api/resources/voices/types/VoicesListResponse.mjs +4 -0
  205. package/dist/esm/api/resources/voices/types/index.d.mts +2 -0
  206. package/dist/esm/api/resources/voices/types/index.mjs +2 -0
  207. package/dist/esm/api/types/Agent.d.mts +80 -0
  208. package/dist/esm/api/types/Agent.mjs +10 -0
  209. package/dist/esm/api/types/AssistantChoseNotToRespondPayload.d.mts +6 -0
  210. package/dist/esm/api/types/AssistantChoseNotToRespondPayload.mjs +4 -0
  211. package/dist/esm/api/types/AssistantEndedConversationPayload.d.mts +6 -0
  212. package/dist/esm/api/types/AssistantEndedConversationPayload.mjs +4 -0
  213. package/dist/esm/api/types/AudioChunkPayload.d.mts +10 -0
  214. package/dist/esm/api/types/AudioChunkPayload.mjs +4 -0
  215. package/dist/esm/api/types/AudioChunkResponsePayload.d.mts +10 -0
  216. package/dist/esm/api/types/AudioChunkResponsePayload.mjs +4 -0
  217. package/dist/esm/api/types/AudioFinishedPayload.d.mts +6 -0
  218. package/dist/esm/api/types/AudioFinishedPayload.mjs +4 -0
  219. package/dist/esm/api/types/BadRequestErrorBody.d.mts +5 -0
  220. package/dist/esm/api/types/BadRequestErrorBody.mjs +4 -0
  221. package/dist/esm/api/types/BasicError.d.mts +14 -0
  222. package/dist/esm/api/types/BasicError.mjs +4 -0
  223. package/dist/esm/api/types/ConfigPayload.d.mts +66 -0
  224. package/dist/esm/api/types/ConfigPayload.mjs +14 -0
  225. package/dist/esm/api/types/Conversation.d.mts +51 -0
  226. package/dist/esm/api/types/Conversation.mjs +4 -0
  227. package/dist/esm/api/types/ConversationAnalysis.d.mts +9 -0
  228. package/dist/esm/api/types/ConversationAnalysis.mjs +4 -0
  229. package/dist/esm/api/types/ConversationCreatedPayload.d.mts +8 -0
  230. package/dist/esm/api/types/ConversationCreatedPayload.mjs +4 -0
  231. package/dist/esm/api/types/ConversationEval.d.mts +4 -0
  232. package/dist/esm/api/types/ConversationEval.mjs +4 -0
  233. package/dist/esm/api/types/ConversationEvalPrompt.d.mts +11 -0
  234. package/dist/esm/api/types/ConversationEvalPrompt.mjs +4 -0
  235. package/dist/esm/api/types/ConversationEvaluation.d.mts +8 -0
  236. package/dist/esm/api/types/ConversationEvaluation.mjs +4 -0
  237. package/dist/esm/api/types/ConversationEvaluationResult.d.mts +32 -0
  238. package/dist/esm/api/types/ConversationEvaluationResult.mjs +12 -0
  239. package/dist/esm/api/types/ConversationExtraction.d.mts +22 -0
  240. package/dist/esm/api/types/ConversationExtraction.mjs +4 -0
  241. package/dist/esm/api/types/ConversationItem.d.mts +31 -0
  242. package/dist/esm/api/types/ConversationItem.mjs +10 -0
  243. package/dist/esm/api/types/CreateAgentRequest.d.mts +70 -0
  244. package/dist/esm/api/types/CreateAgentRequest.mjs +10 -0
  245. package/dist/esm/api/types/DtmfPayload.d.mts +8 -0
  246. package/dist/esm/api/types/DtmfPayload.mjs +4 -0
  247. package/dist/esm/api/types/ErrorPayload.d.mts +17 -0
  248. package/dist/esm/api/types/ErrorPayload.mjs +4 -0
  249. package/dist/esm/api/types/Error_.d.mts +5 -0
  250. package/dist/esm/api/types/Error_.mjs +4 -0
  251. package/dist/esm/api/types/ExtractionField.d.mts +23 -0
  252. package/dist/esm/api/types/ExtractionField.mjs +12 -0
  253. package/dist/esm/api/types/ExtractionSchema.d.mts +14 -0
  254. package/dist/esm/api/types/ExtractionSchema.mjs +4 -0
  255. package/dist/esm/api/types/InputCancelledPayload.d.mts +6 -0
  256. package/dist/esm/api/types/InputCancelledPayload.mjs +4 -0
  257. package/dist/esm/api/types/InputTextPayload.d.mts +8 -0
  258. package/dist/esm/api/types/InputTextPayload.mjs +4 -0
  259. package/dist/esm/api/types/InterruptedResponsePayload.d.mts +8 -0
  260. package/dist/esm/api/types/InterruptedResponsePayload.mjs +4 -0
  261. package/dist/esm/api/types/IsUserSpeakingPayload.d.mts +8 -0
  262. package/dist/esm/api/types/IsUserSpeakingPayload.mjs +4 -0
  263. package/dist/esm/api/types/OutboundCallConfig.d.mts +39 -0
  264. package/dist/esm/api/types/OutboundCallConfig.mjs +4 -0
  265. package/dist/esm/api/types/Project.d.mts +22 -0
  266. package/dist/esm/api/types/Project.mjs +4 -0
  267. package/dist/esm/api/types/ReadyToStartConversationPayload.d.mts +6 -0
  268. package/dist/esm/api/types/ReadyToStartConversationPayload.mjs +4 -0
  269. package/dist/esm/api/types/SetExternalIdPayload.d.mts +8 -0
  270. package/dist/esm/api/types/SetExternalIdPayload.mjs +4 -0
  271. package/dist/esm/api/types/SetTwilioCallSidPayload.d.mts +8 -0
  272. package/dist/esm/api/types/SetTwilioCallSidPayload.mjs +4 -0
  273. package/dist/esm/api/types/Task.d.mts +9 -0
  274. package/dist/esm/api/types/Task.mjs +4 -0
  275. package/dist/esm/api/types/Tool.d.mts +54 -0
  276. package/dist/esm/api/types/Tool.mjs +15 -0
  277. package/dist/esm/api/types/ToolCallInterruptedPayload.d.mts +12 -0
  278. package/dist/esm/api/types/ToolCallInterruptedPayload.mjs +4 -0
  279. package/dist/esm/api/types/ToolCallOutputPayload.d.mts +9 -0
  280. package/dist/esm/api/types/ToolCallOutputPayload.mjs +4 -0
  281. package/dist/esm/api/types/ToolCallOutputProcessedPayload.d.mts +35 -0
  282. package/dist/esm/api/types/ToolCallOutputProcessedPayload.mjs +4 -0
  283. package/dist/esm/api/types/ToolCallPayload.d.mts +12 -0
  284. package/dist/esm/api/types/ToolCallPayload.mjs +4 -0
  285. package/dist/esm/api/types/ToolParameter.d.mts +38 -0
  286. package/dist/esm/api/types/ToolParameter.mjs +19 -0
  287. package/dist/esm/api/types/UpdateSystemPromptPayload.d.mts +8 -0
  288. package/dist/esm/api/types/UpdateSystemPromptPayload.mjs +4 -0
  289. package/dist/esm/api/types/UserFinishedSpeakingPayload.d.mts +6 -0
  290. package/dist/esm/api/types/UserFinishedSpeakingPayload.mjs +4 -0
  291. package/dist/esm/api/types/UserStartedSpeakingPayload.d.mts +6 -0
  292. package/dist/esm/api/types/UserStartedSpeakingPayload.mjs +4 -0
  293. package/dist/esm/api/types/ValidationError.d.mts +14 -0
  294. package/dist/esm/api/types/ValidationError.mjs +4 -0
  295. package/dist/esm/api/types/Voice.d.mts +11 -0
  296. package/dist/esm/api/types/Voice.mjs +4 -0
  297. package/dist/esm/api/types/index.d.mts +45 -0
  298. package/dist/esm/api/types/index.mjs +45 -0
  299. package/dist/esm/api/types/overrides.d.mts +50 -0
  300. package/dist/esm/api/types/overrides.mjs +1 -0
  301. package/dist/esm/core/auth/AuthProvider.d.mts +4 -0
  302. package/dist/esm/core/auth/AuthProvider.mjs +1 -0
  303. package/dist/esm/core/auth/AuthRequest.d.mts +9 -0
  304. package/dist/esm/core/auth/AuthRequest.mjs +1 -0
  305. package/dist/esm/core/auth/BasicAuth.d.mts +8 -0
  306. package/dist/esm/core/auth/BasicAuth.mjs +23 -0
  307. package/dist/esm/core/auth/BearerToken.d.mts +5 -0
  308. package/dist/esm/core/auth/BearerToken.mjs +12 -0
  309. package/dist/esm/core/auth/index.d.mts +4 -0
  310. package/dist/esm/core/auth/index.mjs +2 -0
  311. package/dist/esm/core/base64.d.mts +2 -0
  312. package/dist/esm/core/base64.mjs +22 -0
  313. package/dist/esm/core/fetcher/APIResponse.d.mts +20 -0
  314. package/dist/esm/core/fetcher/APIResponse.mjs +1 -0
  315. package/dist/esm/core/fetcher/BinaryResponse.d.mts +20 -0
  316. package/dist/esm/core/fetcher/BinaryResponse.mjs +14 -0
  317. package/dist/esm/core/fetcher/Fetcher.d.mts +40 -0
  318. package/dist/esm/core/fetcher/Fetcher.mjs +116 -0
  319. package/dist/esm/core/fetcher/Headers.d.mts +2 -0
  320. package/dist/esm/core/fetcher/Headers.mjs +82 -0
  321. package/dist/esm/core/fetcher/HttpResponsePromise.d.mts +58 -0
  322. package/dist/esm/core/fetcher/HttpResponsePromise.mjs +99 -0
  323. package/dist/esm/core/fetcher/RawResponse.d.mts +29 -0
  324. package/dist/esm/core/fetcher/RawResponse.mjs +40 -0
  325. package/dist/esm/core/fetcher/ResponseWithBody.d.mts +4 -0
  326. package/dist/esm/core/fetcher/ResponseWithBody.mjs +3 -0
  327. package/dist/esm/core/fetcher/Supplier.d.mts +4 -0
  328. package/dist/esm/core/fetcher/Supplier.mjs +19 -0
  329. package/dist/esm/core/fetcher/createRequestUrl.d.mts +1 -0
  330. package/dist/esm/core/fetcher/createRequestUrl.mjs +5 -0
  331. package/dist/esm/core/fetcher/getErrorResponseBody.d.mts +1 -0
  332. package/dist/esm/core/fetcher/getErrorResponseBody.mjs +41 -0
  333. package/dist/esm/core/fetcher/getFetchFn.d.mts +1 -0
  334. package/dist/esm/core/fetcher/getFetchFn.mjs +14 -0
  335. package/dist/esm/core/fetcher/getHeader.d.mts +1 -0
  336. package/dist/esm/core/fetcher/getHeader.mjs +8 -0
  337. package/dist/esm/core/fetcher/getRequestBody.d.mts +7 -0
  338. package/dist/esm/core/fetcher/getRequestBody.mjs +20 -0
  339. package/dist/esm/core/fetcher/getResponseBody.d.mts +1 -0
  340. package/dist/esm/core/fetcher/getResponseBody.mjs +52 -0
  341. package/dist/esm/core/fetcher/index.d.mts +9 -0
  342. package/dist/esm/core/fetcher/index.mjs +5 -0
  343. package/dist/esm/core/fetcher/makeRequest.d.mts +1 -0
  344. package/dist/esm/core/fetcher/makeRequest.mjs +38 -0
  345. package/dist/esm/core/fetcher/requestWithRetries.d.mts +1 -0
  346. package/dist/esm/core/fetcher/requestWithRetries.mjs +37 -0
  347. package/dist/esm/core/fetcher/signals.d.mts +11 -0
  348. package/dist/esm/core/fetcher/signals.mjs +32 -0
  349. package/dist/esm/core/headers.d.mts +3 -0
  350. package/dist/esm/core/headers.mjs +25 -0
  351. package/dist/esm/core/index.d.mts +6 -0
  352. package/dist/esm/core/index.mjs +6 -0
  353. package/dist/esm/core/json.d.mts +15 -0
  354. package/dist/esm/core/json.mjs +19 -0
  355. package/dist/esm/core/runtime/index.d.mts +1 -0
  356. package/dist/esm/core/runtime/index.mjs +1 -0
  357. package/dist/esm/core/runtime/runtime.d.mts +9 -0
  358. package/dist/esm/core/runtime/runtime.mjs +99 -0
  359. package/dist/esm/core/url/index.d.mts +2 -0
  360. package/dist/esm/core/url/index.mjs +2 -0
  361. package/dist/esm/core/url/join.d.mts +1 -0
  362. package/dist/esm/core/url/join.mjs +66 -0
  363. package/dist/esm/core/url/qs.d.mts +6 -0
  364. package/dist/esm/core/url/qs.mjs +61 -0
  365. package/dist/esm/core/websocket/events.d.mts +36 -0
  366. package/dist/esm/core/websocket/events.mjs +21 -0
  367. package/dist/esm/core/websocket/index.d.mts +1 -0
  368. package/dist/esm/core/websocket/index.mjs +1 -0
  369. package/dist/esm/core/websocket/ws.d.mts +147 -0
  370. package/dist/esm/core/websocket/ws.mjs +423 -0
  371. package/dist/esm/environments.d.mts +14 -0
  372. package/dist/esm/environments.mjs +9 -0
  373. package/dist/esm/errors/PhonicError.d.mts +15 -0
  374. package/dist/esm/errors/PhonicError.mjs +26 -0
  375. package/dist/esm/errors/PhonicTimeoutError.d.mts +6 -0
  376. package/dist/esm/errors/PhonicTimeoutError.mjs +9 -0
  377. package/dist/esm/errors/index.d.mts +2 -0
  378. package/dist/esm/errors/index.mjs +2 -0
  379. package/dist/esm/index.d.mts +4 -0
  380. package/dist/esm/index.mjs +4 -0
  381. package/dist/esm/version.d.mts +1 -0
  382. package/dist/esm/version.mjs +1 -0
  383. package/package.json +1 -1
  384. package/dist/index.d.mts +0 -640
  385. package/dist/index.d.ts +0 -640
  386. package/dist/index.js +0 -628
  387. package/dist/index.mjs +0 -591
@@ -0,0 +1,61 @@
1
+ const defaultQsOptions = {
2
+ arrayFormat: "indices",
3
+ encode: true,
4
+ };
5
+ function encodeValue(value, shouldEncode) {
6
+ if (value === undefined) {
7
+ return "";
8
+ }
9
+ if (value === null) {
10
+ return "";
11
+ }
12
+ const stringValue = String(value);
13
+ return shouldEncode ? encodeURIComponent(stringValue) : stringValue;
14
+ }
15
+ function stringifyObject(obj, prefix = "", options) {
16
+ const parts = [];
17
+ for (const [key, value] of Object.entries(obj)) {
18
+ const fullKey = prefix ? `${prefix}[${key}]` : key;
19
+ if (value === undefined) {
20
+ continue;
21
+ }
22
+ if (Array.isArray(value)) {
23
+ if (value.length === 0) {
24
+ continue;
25
+ }
26
+ for (let i = 0; i < value.length; i++) {
27
+ const item = value[i];
28
+ if (item === undefined) {
29
+ continue;
30
+ }
31
+ if (typeof item === "object" && !Array.isArray(item) && item !== null) {
32
+ const arrayKey = options.arrayFormat === "indices" ? `${fullKey}[${i}]` : fullKey;
33
+ parts.push(...stringifyObject(item, arrayKey, options));
34
+ }
35
+ else {
36
+ const arrayKey = options.arrayFormat === "indices" ? `${fullKey}[${i}]` : fullKey;
37
+ const encodedKey = options.encode ? encodeURIComponent(arrayKey) : arrayKey;
38
+ parts.push(`${encodedKey}=${encodeValue(item, options.encode)}`);
39
+ }
40
+ }
41
+ }
42
+ else if (typeof value === "object" && value !== null) {
43
+ if (Object.keys(value).length === 0) {
44
+ continue;
45
+ }
46
+ parts.push(...stringifyObject(value, fullKey, options));
47
+ }
48
+ else {
49
+ const encodedKey = options.encode ? encodeURIComponent(fullKey) : fullKey;
50
+ parts.push(`${encodedKey}=${encodeValue(value, options.encode)}`);
51
+ }
52
+ }
53
+ return parts;
54
+ }
55
+ export function toQueryString(obj, options) {
56
+ if (obj == null || typeof obj !== "object") {
57
+ return "";
58
+ }
59
+ const parts = stringifyObject(obj, "", Object.assign(Object.assign({}, defaultQsOptions), options));
60
+ return parts.join("&");
61
+ }
@@ -0,0 +1,36 @@
1
+ export declare class Event {
2
+ target: any;
3
+ type: string;
4
+ constructor(type: string, target: any);
5
+ }
6
+ export declare class ErrorEvent extends Event {
7
+ message: string;
8
+ error: Error;
9
+ constructor(error: Error, target: any);
10
+ }
11
+ export declare class CloseEvent extends Event {
12
+ code: number;
13
+ reason: string;
14
+ wasClean: boolean;
15
+ constructor(code: number | undefined, reason: string | undefined, target: any);
16
+ }
17
+ export interface WebSocketEventMap {
18
+ close: CloseEvent;
19
+ error: ErrorEvent;
20
+ message: MessageEvent;
21
+ open: Event;
22
+ }
23
+ export interface WebSocketEventListenerMap {
24
+ close: (event: CloseEvent) => void | {
25
+ handleEvent: (event: CloseEvent) => void;
26
+ };
27
+ error: (event: ErrorEvent) => void | {
28
+ handleEvent: (event: ErrorEvent) => void;
29
+ };
30
+ message: (event: MessageEvent) => void | {
31
+ handleEvent: (event: MessageEvent) => void;
32
+ };
33
+ open: (event: Event) => void | {
34
+ handleEvent: (event: Event) => void;
35
+ };
36
+ }
@@ -0,0 +1,21 @@
1
+ export class Event {
2
+ constructor(type, target) {
3
+ this.target = target;
4
+ this.type = type;
5
+ }
6
+ }
7
+ export class ErrorEvent extends Event {
8
+ constructor(error, target) {
9
+ super("error", target);
10
+ this.message = error.message;
11
+ this.error = error;
12
+ }
13
+ }
14
+ export class CloseEvent extends Event {
15
+ constructor(code = 1000, reason = "", target) {
16
+ super("close", target);
17
+ this.wasClean = true;
18
+ this.code = code;
19
+ this.reason = reason;
20
+ }
21
+ }
@@ -0,0 +1 @@
1
+ export * from "./ws.mjs";
@@ -0,0 +1 @@
1
+ export * from "./ws.mjs";
@@ -0,0 +1,147 @@
1
+ import * as Events from "./events.mjs";
2
+ export type Event = Events.Event;
3
+ export type ErrorEvent = Events.ErrorEvent;
4
+ export type CloseEvent = Events.CloseEvent;
5
+ export declare namespace ReconnectingWebSocket {
6
+ interface Args {
7
+ url: string;
8
+ protocols?: string | string[];
9
+ options?: ReconnectingWebSocket.Options;
10
+ headers?: Record<string, string>;
11
+ queryParameters?: Record<string, string | string[] | object | object[] | null | undefined>;
12
+ }
13
+ type Options = {
14
+ WebSocket?: any;
15
+ maxReconnectionDelay?: number;
16
+ minReconnectionDelay?: number;
17
+ reconnectionDelayGrowFactor?: number;
18
+ minUptime?: number;
19
+ connectionTimeout?: number;
20
+ maxRetries?: number;
21
+ maxEnqueuedMessages?: number;
22
+ startClosed?: boolean;
23
+ debug?: boolean;
24
+ };
25
+ type UrlProvider = string | (() => string) | (() => Promise<string>);
26
+ type Message = string | ArrayBuffer | Blob | ArrayBufferView;
27
+ type ListenersMap = {
28
+ error: Array<Events.WebSocketEventListenerMap["error"]>;
29
+ message: Array<Events.WebSocketEventListenerMap["message"]>;
30
+ open: Array<Events.WebSocketEventListenerMap["open"]>;
31
+ close: Array<Events.WebSocketEventListenerMap["close"]>;
32
+ };
33
+ }
34
+ export declare class ReconnectingWebSocket {
35
+ private _ws?;
36
+ private _listeners;
37
+ private _retryCount;
38
+ private _uptimeTimeout;
39
+ private _connectTimeout;
40
+ private _shouldReconnect;
41
+ private _connectLock;
42
+ private _binaryType;
43
+ private _closeCalled;
44
+ private _messageQueue;
45
+ private readonly _url;
46
+ private readonly _protocols?;
47
+ private readonly _options;
48
+ private readonly _headers?;
49
+ private readonly _queryParameters?;
50
+ constructor({ url, protocols, options, headers, queryParameters }: ReconnectingWebSocket.Args);
51
+ static get CONNECTING(): number;
52
+ static get OPEN(): number;
53
+ static get CLOSING(): number;
54
+ static get CLOSED(): number;
55
+ get CONNECTING(): number;
56
+ get OPEN(): number;
57
+ get CLOSING(): number;
58
+ get CLOSED(): number;
59
+ get binaryType(): BinaryType;
60
+ set binaryType(value: BinaryType);
61
+ /**
62
+ * Returns the number or connection retries
63
+ */
64
+ get retryCount(): number;
65
+ /**
66
+ * The number of bytes of data that have been queued using calls to send() but not yet
67
+ * transmitted to the network. This value resets to zero once all queued data has been sent.
68
+ * This value does not reset to zero when the connection is closed; if you keep calling send(),
69
+ * this will continue to climb. Read only
70
+ */
71
+ get bufferedAmount(): number;
72
+ /**
73
+ * The extensions selected by the server. This is currently only the empty string or a list of
74
+ * extensions as negotiated by the connection
75
+ */
76
+ get extensions(): string;
77
+ /**
78
+ * A string indicating the name of the sub-protocol the server selected;
79
+ * this will be one of the strings specified in the protocols parameter when creating the
80
+ * WebSocket object
81
+ */
82
+ get protocol(): string;
83
+ /**
84
+ * The current state of the connection; this is one of the Ready state constants
85
+ */
86
+ get readyState(): number;
87
+ /**
88
+ * The URL as resolved by the constructor
89
+ */
90
+ get url(): string;
91
+ /**
92
+ * An event listener to be called when the WebSocket connection's readyState changes to CLOSED
93
+ */
94
+ onclose: ((event: Events.CloseEvent) => void) | null;
95
+ /**
96
+ * An event listener to be called when an error occurs
97
+ */
98
+ onerror: ((event: Events.ErrorEvent) => void) | null;
99
+ /**
100
+ * An event listener to be called when a message is received from the server
101
+ */
102
+ onmessage: ((event: MessageEvent) => void) | null;
103
+ /**
104
+ * An event listener to be called when the WebSocket connection's readyState changes to OPEN;
105
+ * this indicates that the connection is ready to send and receive data
106
+ */
107
+ onopen: ((event: Event) => void) | null;
108
+ /**
109
+ * Closes the WebSocket connection or connection attempt, if any. If the connection is already
110
+ * CLOSED, this method does nothing
111
+ */
112
+ close(code?: number, reason?: string): void;
113
+ /**
114
+ * Closes the WebSocket connection or connection attempt and connects again.
115
+ * Resets retry counter;
116
+ */
117
+ reconnect(code?: number, reason?: string): void;
118
+ /**
119
+ * Enqueue specified data to be transmitted to the server over the WebSocket connection
120
+ */
121
+ send(data: ReconnectingWebSocket.Message): void;
122
+ /**
123
+ * Register an event handler of a specific event type
124
+ */
125
+ addEventListener<T extends keyof Events.WebSocketEventListenerMap>(type: T, listener: Events.WebSocketEventListenerMap[T]): void;
126
+ dispatchEvent(event: Event): boolean;
127
+ /**
128
+ * Removes an event listener
129
+ */
130
+ removeEventListener<T extends keyof Events.WebSocketEventListenerMap>(type: T, listener: Events.WebSocketEventListenerMap[T]): void;
131
+ private _debug;
132
+ private _getNextDelay;
133
+ private _wait;
134
+ private _getNextUrl;
135
+ private _connect;
136
+ private _handleTimeout;
137
+ private _disconnect;
138
+ private _acceptOpen;
139
+ private _callEventListener;
140
+ private _handleOpen;
141
+ private _handleMessage;
142
+ private _handleError;
143
+ private _handleClose;
144
+ private _removeListeners;
145
+ private _addListeners;
146
+ private _clearTimeouts;
147
+ }
@@ -0,0 +1,423 @@
1
+ import { WebSocket as NodeWebSocket } from "ws";
2
+ import { RUNTIME } from "../runtime/index.mjs";
3
+ import { toQueryString } from "../url/qs.mjs";
4
+ import * as Events from "./events.mjs";
5
+ const getGlobalWebSocket = () => {
6
+ if (RUNTIME.type === "node") {
7
+ return NodeWebSocket;
8
+ }
9
+ else if (typeof WebSocket !== "undefined") {
10
+ // @ts-ignore
11
+ return WebSocket;
12
+ }
13
+ return undefined;
14
+ };
15
+ /**
16
+ * Returns true if given argument looks like a WebSocket class
17
+ */
18
+ const isWebSocket = (w) => typeof w !== "undefined" && !!w && w.CLOSING === 2;
19
+ const DEFAULT_OPTIONS = {
20
+ maxReconnectionDelay: 10000,
21
+ minReconnectionDelay: 1000 + Math.random() * 4000,
22
+ minUptime: 5000,
23
+ reconnectionDelayGrowFactor: 1.3,
24
+ connectionTimeout: 4000,
25
+ maxRetries: Infinity,
26
+ maxEnqueuedMessages: Infinity,
27
+ startClosed: false,
28
+ debug: false,
29
+ };
30
+ export class ReconnectingWebSocket {
31
+ constructor({ url, protocols, options, headers, queryParameters }) {
32
+ this._listeners = {
33
+ error: [],
34
+ message: [],
35
+ open: [],
36
+ close: [],
37
+ };
38
+ this._retryCount = -1;
39
+ this._shouldReconnect = true;
40
+ this._connectLock = false;
41
+ this._binaryType = "blob";
42
+ this._closeCalled = false;
43
+ this._messageQueue = [];
44
+ /**
45
+ * An event listener to be called when the WebSocket connection's readyState changes to CLOSED
46
+ */
47
+ this.onclose = null;
48
+ /**
49
+ * An event listener to be called when an error occurs
50
+ */
51
+ this.onerror = null;
52
+ /**
53
+ * An event listener to be called when a message is received from the server
54
+ */
55
+ this.onmessage = null;
56
+ /**
57
+ * An event listener to be called when the WebSocket connection's readyState changes to OPEN;
58
+ * this indicates that the connection is ready to send and receive data
59
+ */
60
+ this.onopen = null;
61
+ this._handleOpen = (event) => {
62
+ this._debug("open event");
63
+ const { minUptime = DEFAULT_OPTIONS.minUptime } = this._options;
64
+ clearTimeout(this._connectTimeout);
65
+ this._uptimeTimeout = setTimeout(() => this._acceptOpen(), minUptime);
66
+ this._ws.binaryType = this._binaryType;
67
+ // send enqueued messages (messages sent before websocket open event)
68
+ this._messageQueue.forEach((message) => { var _a; return (_a = this._ws) === null || _a === void 0 ? void 0 : _a.send(message); });
69
+ this._messageQueue = [];
70
+ if (this.onopen) {
71
+ this.onopen(event);
72
+ }
73
+ this._listeners.open.forEach((listener) => this._callEventListener(event, listener));
74
+ };
75
+ this._handleMessage = (event) => {
76
+ this._debug("message event");
77
+ if (this.onmessage) {
78
+ this.onmessage(event);
79
+ }
80
+ this._listeners.message.forEach((listener) => this._callEventListener(event, listener));
81
+ };
82
+ this._handleError = (event) => {
83
+ this._debug("error event", event.message);
84
+ this._disconnect(undefined, event.message === "TIMEOUT" ? "timeout" : undefined);
85
+ if (this.onerror) {
86
+ this.onerror(event);
87
+ }
88
+ this._debug("exec error listeners");
89
+ this._listeners.error.forEach((listener) => this._callEventListener(event, listener));
90
+ this._connect();
91
+ };
92
+ this._handleClose = (event) => {
93
+ this._debug("close event");
94
+ this._clearTimeouts();
95
+ if (event.code === 1000) {
96
+ this._shouldReconnect = false;
97
+ }
98
+ if (this._shouldReconnect) {
99
+ this._connect();
100
+ }
101
+ if (this.onclose) {
102
+ this.onclose(event);
103
+ }
104
+ this._listeners.close.forEach((listener) => this._callEventListener(event, listener));
105
+ };
106
+ this._url = url;
107
+ this._protocols = protocols;
108
+ this._options = options !== null && options !== void 0 ? options : DEFAULT_OPTIONS;
109
+ this._headers = headers;
110
+ this._queryParameters = queryParameters;
111
+ if (this._options.startClosed) {
112
+ this._shouldReconnect = false;
113
+ }
114
+ this._connect();
115
+ }
116
+ static get CONNECTING() {
117
+ return 0;
118
+ }
119
+ static get OPEN() {
120
+ return 1;
121
+ }
122
+ static get CLOSING() {
123
+ return 2;
124
+ }
125
+ static get CLOSED() {
126
+ return 3;
127
+ }
128
+ get CONNECTING() {
129
+ return ReconnectingWebSocket.CONNECTING;
130
+ }
131
+ get OPEN() {
132
+ return ReconnectingWebSocket.OPEN;
133
+ }
134
+ get CLOSING() {
135
+ return ReconnectingWebSocket.CLOSING;
136
+ }
137
+ get CLOSED() {
138
+ return ReconnectingWebSocket.CLOSED;
139
+ }
140
+ get binaryType() {
141
+ return this._ws ? this._ws.binaryType : this._binaryType;
142
+ }
143
+ set binaryType(value) {
144
+ this._binaryType = value;
145
+ if (this._ws) {
146
+ this._ws.binaryType = value;
147
+ }
148
+ }
149
+ /**
150
+ * Returns the number or connection retries
151
+ */
152
+ get retryCount() {
153
+ return Math.max(this._retryCount, 0);
154
+ }
155
+ /**
156
+ * The number of bytes of data that have been queued using calls to send() but not yet
157
+ * transmitted to the network. This value resets to zero once all queued data has been sent.
158
+ * This value does not reset to zero when the connection is closed; if you keep calling send(),
159
+ * this will continue to climb. Read only
160
+ */
161
+ get bufferedAmount() {
162
+ const bytes = this._messageQueue.reduce((acc, message) => {
163
+ if (typeof message === "string") {
164
+ acc += message.length; // not byte size
165
+ }
166
+ else if (message instanceof Blob) {
167
+ acc += message.size;
168
+ }
169
+ else {
170
+ acc += message.byteLength;
171
+ }
172
+ return acc;
173
+ }, 0);
174
+ return bytes + (this._ws ? this._ws.bufferedAmount : 0);
175
+ }
176
+ /**
177
+ * The extensions selected by the server. This is currently only the empty string or a list of
178
+ * extensions as negotiated by the connection
179
+ */
180
+ get extensions() {
181
+ return this._ws ? this._ws.extensions : "";
182
+ }
183
+ /**
184
+ * A string indicating the name of the sub-protocol the server selected;
185
+ * this will be one of the strings specified in the protocols parameter when creating the
186
+ * WebSocket object
187
+ */
188
+ get protocol() {
189
+ return this._ws ? this._ws.protocol : "";
190
+ }
191
+ /**
192
+ * The current state of the connection; this is one of the Ready state constants
193
+ */
194
+ get readyState() {
195
+ if (this._ws) {
196
+ return this._ws.readyState;
197
+ }
198
+ return this._options.startClosed ? ReconnectingWebSocket.CLOSED : ReconnectingWebSocket.CONNECTING;
199
+ }
200
+ /**
201
+ * The URL as resolved by the constructor
202
+ */
203
+ get url() {
204
+ return this._ws ? this._ws.url : "";
205
+ }
206
+ /**
207
+ * Closes the WebSocket connection or connection attempt, if any. If the connection is already
208
+ * CLOSED, this method does nothing
209
+ */
210
+ close(code = 1000, reason) {
211
+ this._closeCalled = true;
212
+ this._shouldReconnect = false;
213
+ this._clearTimeouts();
214
+ if (!this._ws) {
215
+ this._debug("close enqueued: no ws instance");
216
+ return;
217
+ }
218
+ if (this._ws.readyState === this.CLOSED) {
219
+ this._debug("close: already closed");
220
+ return;
221
+ }
222
+ this._ws.close(code, reason);
223
+ }
224
+ /**
225
+ * Closes the WebSocket connection or connection attempt and connects again.
226
+ * Resets retry counter;
227
+ */
228
+ reconnect(code, reason) {
229
+ this._shouldReconnect = true;
230
+ this._closeCalled = false;
231
+ this._retryCount = -1;
232
+ if (!this._ws || this._ws.readyState === this.CLOSED) {
233
+ this._connect();
234
+ }
235
+ else {
236
+ this._disconnect(code, reason);
237
+ this._connect();
238
+ }
239
+ }
240
+ /**
241
+ * Enqueue specified data to be transmitted to the server over the WebSocket connection
242
+ */
243
+ send(data) {
244
+ if (this._ws && this._ws.readyState === this.OPEN) {
245
+ this._debug("send", data);
246
+ this._ws.send(data);
247
+ }
248
+ else {
249
+ const { maxEnqueuedMessages = DEFAULT_OPTIONS.maxEnqueuedMessages } = this._options;
250
+ if (this._messageQueue.length < maxEnqueuedMessages) {
251
+ this._debug("enqueue", data);
252
+ this._messageQueue.push(data);
253
+ }
254
+ }
255
+ }
256
+ /**
257
+ * Register an event handler of a specific event type
258
+ */
259
+ addEventListener(type, listener) {
260
+ if (this._listeners[type]) {
261
+ // @ts-ignore
262
+ this._listeners[type].push(listener);
263
+ }
264
+ }
265
+ dispatchEvent(event) {
266
+ const listeners = this._listeners[event.type];
267
+ if (listeners) {
268
+ for (const listener of listeners) {
269
+ this._callEventListener(event, listener);
270
+ }
271
+ }
272
+ return true;
273
+ }
274
+ /**
275
+ * Removes an event listener
276
+ */
277
+ removeEventListener(type, listener) {
278
+ if (this._listeners[type]) {
279
+ // @ts-ignore
280
+ this._listeners[type] = this._listeners[type].filter(
281
+ // @ts-ignore
282
+ (l) => l !== listener);
283
+ }
284
+ }
285
+ _debug(...args) {
286
+ if (this._options.debug) {
287
+ // not using spread because compiled version uses Symbols
288
+ // tslint:disable-next-line
289
+ // biome-ignore lint/suspicious/noConsole: allow console
290
+ console.log.apply(console, ["RWS>", ...args]);
291
+ }
292
+ }
293
+ _getNextDelay() {
294
+ const { reconnectionDelayGrowFactor = DEFAULT_OPTIONS.reconnectionDelayGrowFactor, minReconnectionDelay = DEFAULT_OPTIONS.minReconnectionDelay, maxReconnectionDelay = DEFAULT_OPTIONS.maxReconnectionDelay, } = this._options;
295
+ let delay = 0;
296
+ if (this._retryCount > 0) {
297
+ delay = minReconnectionDelay * Math.pow(reconnectionDelayGrowFactor, this._retryCount - 1);
298
+ if (delay > maxReconnectionDelay) {
299
+ delay = maxReconnectionDelay;
300
+ }
301
+ }
302
+ this._debug("next delay", delay);
303
+ return delay;
304
+ }
305
+ _wait() {
306
+ return new Promise((resolve) => {
307
+ setTimeout(resolve, this._getNextDelay());
308
+ });
309
+ }
310
+ _getNextUrl(urlProvider) {
311
+ if (typeof urlProvider === "string") {
312
+ return Promise.resolve(urlProvider);
313
+ }
314
+ if (typeof urlProvider === "function") {
315
+ const url = urlProvider();
316
+ if (typeof url === "string") {
317
+ return Promise.resolve(url);
318
+ }
319
+ // @ts-ignore redundant check
320
+ if (url.then) {
321
+ return url;
322
+ }
323
+ }
324
+ throw Error("Invalid URL");
325
+ }
326
+ _connect() {
327
+ if (this._connectLock || !this._shouldReconnect) {
328
+ return;
329
+ }
330
+ this._connectLock = true;
331
+ const { maxRetries = DEFAULT_OPTIONS.maxRetries, connectionTimeout = DEFAULT_OPTIONS.connectionTimeout, WebSocket = getGlobalWebSocket(), } = this._options;
332
+ if (this._retryCount >= maxRetries) {
333
+ this._debug("max retries reached", this._retryCount, ">=", maxRetries);
334
+ return;
335
+ }
336
+ this._retryCount++;
337
+ this._debug("connect", this._retryCount);
338
+ this._removeListeners();
339
+ if (!isWebSocket(WebSocket)) {
340
+ throw Error("No valid WebSocket class provided");
341
+ }
342
+ this._wait()
343
+ .then(() => this._getNextUrl(this._url))
344
+ .then((url) => {
345
+ if (this._closeCalled) {
346
+ return;
347
+ }
348
+ const options = {};
349
+ if (this._headers) {
350
+ options.headers = this._headers;
351
+ }
352
+ if (this._queryParameters && Object.keys(this._queryParameters).length > 0) {
353
+ const queryString = toQueryString(this._queryParameters, { arrayFormat: "repeat" });
354
+ if (queryString) {
355
+ url = `${url}?${queryString}`;
356
+ }
357
+ }
358
+ this._ws = new WebSocket(url, this._protocols, options);
359
+ this._ws.binaryType = this._binaryType;
360
+ this._connectLock = false;
361
+ this._addListeners();
362
+ this._connectTimeout = setTimeout(() => this._handleTimeout(), connectionTimeout);
363
+ });
364
+ }
365
+ _handleTimeout() {
366
+ this._debug("timeout event");
367
+ this._handleError(new Events.ErrorEvent(Error("TIMEOUT"), this));
368
+ }
369
+ _disconnect(code = 1000, reason) {
370
+ this._clearTimeouts();
371
+ if (!this._ws) {
372
+ return;
373
+ }
374
+ this._removeListeners();
375
+ try {
376
+ this._ws.close(code, reason);
377
+ this._handleClose(new Events.CloseEvent(code, reason, this));
378
+ }
379
+ catch (error) {
380
+ // ignore
381
+ }
382
+ }
383
+ _acceptOpen() {
384
+ this._debug("accept open");
385
+ this._retryCount = 0;
386
+ }
387
+ _callEventListener(event, listener) {
388
+ if ("handleEvent" in listener) {
389
+ // @ts-ignore
390
+ listener.handleEvent(event);
391
+ }
392
+ else {
393
+ // @ts-ignore
394
+ listener(event);
395
+ }
396
+ }
397
+ _removeListeners() {
398
+ if (!this._ws) {
399
+ return;
400
+ }
401
+ this._debug("removeListeners");
402
+ this._ws.removeEventListener("open", this._handleOpen);
403
+ this._ws.removeEventListener("close", this._handleClose);
404
+ this._ws.removeEventListener("message", this._handleMessage);
405
+ // @ts-ignore
406
+ this._ws.removeEventListener("error", this._handleError);
407
+ }
408
+ _addListeners() {
409
+ if (!this._ws) {
410
+ return;
411
+ }
412
+ this._debug("addListeners");
413
+ this._ws.addEventListener("open", this._handleOpen);
414
+ this._ws.addEventListener("close", this._handleClose);
415
+ this._ws.addEventListener("message", this._handleMessage);
416
+ // @ts-ignore
417
+ this._ws.addEventListener("error", this._handleError);
418
+ }
419
+ _clearTimeouts() {
420
+ clearTimeout(this._connectTimeout);
421
+ clearTimeout(this._uptimeTimeout);
422
+ }
423
+ }