@letta-ai/letta-client 0.1.170 → 0.1.172

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 (286) hide show
  1. package/README.md +16 -3
  2. package/api/errors/BadRequestError.d.ts +2 -1
  3. package/api/errors/BadRequestError.js +2 -1
  4. package/api/errors/ConflictError.d.ts +2 -1
  5. package/api/errors/ConflictError.js +2 -1
  6. package/api/errors/InternalServerError.d.ts +2 -1
  7. package/api/errors/InternalServerError.js +2 -1
  8. package/api/errors/NotFoundError.d.ts +2 -1
  9. package/api/errors/NotFoundError.js +2 -1
  10. package/api/errors/PaymentRequiredError.d.ts +2 -1
  11. package/api/errors/PaymentRequiredError.js +2 -1
  12. package/api/errors/UnprocessableEntityError.d.ts +2 -1
  13. package/api/errors/UnprocessableEntityError.js +2 -1
  14. package/api/resources/agents/client/Client.d.ts +20 -10
  15. package/api/resources/agents/client/Client.js +166 -82
  16. package/api/resources/agents/resources/blocks/client/Client.d.ts +10 -5
  17. package/api/resources/agents/resources/blocks/client/Client.js +90 -45
  18. package/api/resources/agents/resources/context/client/Client.d.ts +2 -1
  19. package/api/resources/agents/resources/context/client/Client.js +18 -9
  20. package/api/resources/agents/resources/coreMemory/client/Client.d.ts +2 -1
  21. package/api/resources/agents/resources/coreMemory/client/Client.js +18 -9
  22. package/api/resources/agents/resources/files/client/Client.d.ts +6 -3
  23. package/api/resources/agents/resources/files/client/Client.js +45 -21
  24. package/api/resources/agents/resources/folders/client/Client.d.ts +6 -3
  25. package/api/resources/agents/resources/folders/client/Client.js +54 -27
  26. package/api/resources/agents/resources/groups/client/Client.d.ts +2 -1
  27. package/api/resources/agents/resources/groups/client/Client.js +19 -10
  28. package/api/resources/agents/resources/memoryVariables/client/Client.d.ts +2 -1
  29. package/api/resources/agents/resources/memoryVariables/client/Client.js +18 -9
  30. package/api/resources/agents/resources/messages/client/Client.d.ts +16 -8
  31. package/api/resources/agents/resources/messages/client/Client.js +155 -83
  32. package/api/resources/agents/resources/passages/client/Client.d.ts +8 -4
  33. package/api/resources/agents/resources/passages/client/Client.js +64 -31
  34. package/api/resources/agents/resources/sources/client/Client.d.ts +6 -3
  35. package/api/resources/agents/resources/sources/client/Client.js +54 -27
  36. package/api/resources/agents/resources/templates/client/Client.d.ts +6 -3
  37. package/api/resources/agents/resources/templates/client/Client.js +54 -27
  38. package/api/resources/agents/resources/tools/client/Client.d.ts +6 -3
  39. package/api/resources/agents/resources/tools/client/Client.js +54 -27
  40. package/api/resources/batches/client/Client.d.ts +8 -4
  41. package/api/resources/batches/client/Client.js +63 -30
  42. package/api/resources/blocks/client/Client.d.ts +12 -6
  43. package/api/resources/blocks/client/Client.js +100 -49
  44. package/api/resources/blocks/resources/agents/client/Client.d.ts +2 -1
  45. package/api/resources/blocks/resources/agents/client/Client.js +19 -10
  46. package/api/resources/clientSideAccessTokens/client/Client.d.ts +6 -3
  47. package/api/resources/clientSideAccessTokens/client/Client.js +46 -22
  48. package/api/resources/embeddingModels/client/Client.d.ts +2 -1
  49. package/api/resources/embeddingModels/client/Client.js +18 -9
  50. package/api/resources/folders/client/Client.d.ts +18 -9
  51. package/api/resources/folders/client/Client.js +154 -76
  52. package/api/resources/folders/resources/files/client/Client.d.ts +6 -3
  53. package/api/resources/folders/resources/files/client/Client.js +48 -24
  54. package/api/resources/folders/resources/passages/client/Client.d.ts +2 -1
  55. package/api/resources/folders/resources/passages/client/Client.js +19 -10
  56. package/api/resources/groups/client/Client.d.ts +12 -6
  57. package/api/resources/groups/client/Client.js +105 -52
  58. package/api/resources/groups/resources/messages/client/Client.d.ts +10 -5
  59. package/api/resources/groups/resources/messages/client/Client.js +91 -49
  60. package/api/resources/health/client/Client.d.ts +2 -1
  61. package/api/resources/health/client/Client.js +17 -8
  62. package/api/resources/identities/client/Client.d.ts +14 -7
  63. package/api/resources/identities/client/Client.js +123 -61
  64. package/api/resources/identities/resources/properties/client/Client.d.ts +2 -1
  65. package/api/resources/identities/resources/properties/client/Client.js +9 -3
  66. package/api/resources/jobs/client/Client.d.ts +10 -5
  67. package/api/resources/jobs/client/Client.js +92 -47
  68. package/api/resources/messages/client/Client.d.ts +2 -1
  69. package/api/resources/messages/client/Client.js +19 -10
  70. package/api/resources/models/client/Client.d.ts +2 -1
  71. package/api/resources/models/client/Client.js +27 -14
  72. package/api/resources/projects/client/Client.d.ts +2 -1
  73. package/api/resources/projects/client/Client.js +18 -9
  74. package/api/resources/providers/client/Client.d.ts +10 -5
  75. package/api/resources/providers/client/Client.js +77 -36
  76. package/api/resources/runs/client/Client.d.ts +8 -4
  77. package/api/resources/runs/client/Client.js +74 -38
  78. package/api/resources/runs/resources/messages/client/Client.d.ts +2 -1
  79. package/api/resources/runs/resources/messages/client/Client.js +21 -12
  80. package/api/resources/runs/resources/steps/client/Client.d.ts +2 -1
  81. package/api/resources/runs/resources/steps/client/Client.js +19 -10
  82. package/api/resources/runs/resources/usage/client/Client.d.ts +2 -1
  83. package/api/resources/runs/resources/usage/client/Client.js +18 -9
  84. package/api/resources/sources/client/Client.d.ts +20 -10
  85. package/api/resources/sources/client/Client.js +173 -86
  86. package/api/resources/sources/resources/files/client/Client.d.ts +6 -3
  87. package/api/resources/sources/resources/files/client/Client.js +48 -24
  88. package/api/resources/sources/resources/passages/client/Client.d.ts +2 -1
  89. package/api/resources/sources/resources/passages/client/Client.js +19 -10
  90. package/api/resources/steps/client/Client.d.ts +4 -2
  91. package/api/resources/steps/client/Client.js +41 -21
  92. package/api/resources/steps/resources/feedback/client/Client.d.ts +2 -1
  93. package/api/resources/steps/resources/feedback/client/Client.js +23 -12
  94. package/api/resources/tags/client/Client.d.ts +2 -1
  95. package/api/resources/tags/client/Client.js +19 -10
  96. package/api/resources/telemetry/client/Client.d.ts +2 -1
  97. package/api/resources/telemetry/client/Client.js +18 -9
  98. package/api/resources/templates/client/Client.d.ts +2 -1
  99. package/api/resources/templates/client/Client.js +18 -9
  100. package/api/resources/templates/resources/agents/client/Client.d.ts +2 -1
  101. package/api/resources/templates/resources/agents/client/Client.js +19 -10
  102. package/api/resources/tools/client/Client.d.ts +40 -20
  103. package/api/resources/tools/client/Client.js +356 -182
  104. package/api/resources/voice/client/Client.d.ts +2 -1
  105. package/api/resources/voice/client/Client.js +9 -3
  106. package/api/types/LettaStreamingRequest.d.ts +2 -0
  107. package/core/fetcher/APIResponse.d.ts +10 -0
  108. package/core/fetcher/Fetcher.d.ts +1 -1
  109. package/core/fetcher/Fetcher.js +11 -3
  110. package/core/fetcher/Headers.d.ts +2 -0
  111. package/core/fetcher/Headers.js +84 -0
  112. package/core/fetcher/HttpResponsePromise.d.ts +58 -0
  113. package/core/fetcher/HttpResponsePromise.js +103 -0
  114. package/core/fetcher/RawResponse.d.ts +29 -0
  115. package/core/fetcher/RawResponse.js +44 -0
  116. package/core/fetcher/createRequestUrl.d.ts +1 -1
  117. package/core/fetcher/getRequestBody.js +2 -1
  118. package/core/fetcher/index.d.ts +3 -0
  119. package/core/fetcher/index.js +7 -1
  120. package/core/fetcher/requestWithRetries.js +1 -1
  121. package/core/form-data-utils/FormDataWrapper.d.ts +3 -0
  122. package/core/form-data-utils/FormDataWrapper.js +53 -10
  123. package/core/form-data-utils/encodeAsFormParameter.d.ts +4 -0
  124. package/core/form-data-utils/encodeAsFormParameter.js +18 -0
  125. package/core/form-data-utils/index.d.ts +1 -0
  126. package/core/form-data-utils/index.js +3 -0
  127. package/core/json.d.ts +15 -0
  128. package/core/json.js +24 -0
  129. package/core/schemas/Schema.d.ts +2 -0
  130. package/core/schemas/Schema.js +2 -0
  131. package/core/schemas/builders/bigint/bigint.d.ts +1 -1
  132. package/core/schemas/builders/bigint/bigint.js +21 -17
  133. package/core/schemas/builders/object/object.js +1 -0
  134. package/core/schemas/builders/record/record.js +1 -2
  135. package/core/schemas/builders/schema-utils/getSchemaUtils.d.ts +4 -0
  136. package/core/schemas/builders/schema-utils/getSchemaUtils.js +64 -0
  137. package/core/schemas/utils/addQuestionMarksToNullableProperties.d.ts +1 -1
  138. package/dist/api/errors/BadRequestError.d.ts +2 -1
  139. package/dist/api/errors/BadRequestError.js +2 -1
  140. package/dist/api/errors/ConflictError.d.ts +2 -1
  141. package/dist/api/errors/ConflictError.js +2 -1
  142. package/dist/api/errors/InternalServerError.d.ts +2 -1
  143. package/dist/api/errors/InternalServerError.js +2 -1
  144. package/dist/api/errors/NotFoundError.d.ts +2 -1
  145. package/dist/api/errors/NotFoundError.js +2 -1
  146. package/dist/api/errors/PaymentRequiredError.d.ts +2 -1
  147. package/dist/api/errors/PaymentRequiredError.js +2 -1
  148. package/dist/api/errors/UnprocessableEntityError.d.ts +2 -1
  149. package/dist/api/errors/UnprocessableEntityError.js +2 -1
  150. package/dist/api/resources/agents/client/Client.d.ts +20 -10
  151. package/dist/api/resources/agents/client/Client.js +166 -82
  152. package/dist/api/resources/agents/resources/blocks/client/Client.d.ts +10 -5
  153. package/dist/api/resources/agents/resources/blocks/client/Client.js +90 -45
  154. package/dist/api/resources/agents/resources/context/client/Client.d.ts +2 -1
  155. package/dist/api/resources/agents/resources/context/client/Client.js +18 -9
  156. package/dist/api/resources/agents/resources/coreMemory/client/Client.d.ts +2 -1
  157. package/dist/api/resources/agents/resources/coreMemory/client/Client.js +18 -9
  158. package/dist/api/resources/agents/resources/files/client/Client.d.ts +6 -3
  159. package/dist/api/resources/agents/resources/files/client/Client.js +45 -21
  160. package/dist/api/resources/agents/resources/folders/client/Client.d.ts +6 -3
  161. package/dist/api/resources/agents/resources/folders/client/Client.js +54 -27
  162. package/dist/api/resources/agents/resources/groups/client/Client.d.ts +2 -1
  163. package/dist/api/resources/agents/resources/groups/client/Client.js +19 -10
  164. package/dist/api/resources/agents/resources/memoryVariables/client/Client.d.ts +2 -1
  165. package/dist/api/resources/agents/resources/memoryVariables/client/Client.js +18 -9
  166. package/dist/api/resources/agents/resources/messages/client/Client.d.ts +16 -8
  167. package/dist/api/resources/agents/resources/messages/client/Client.js +155 -83
  168. package/dist/api/resources/agents/resources/passages/client/Client.d.ts +8 -4
  169. package/dist/api/resources/agents/resources/passages/client/Client.js +64 -31
  170. package/dist/api/resources/agents/resources/sources/client/Client.d.ts +6 -3
  171. package/dist/api/resources/agents/resources/sources/client/Client.js +54 -27
  172. package/dist/api/resources/agents/resources/templates/client/Client.d.ts +6 -3
  173. package/dist/api/resources/agents/resources/templates/client/Client.js +54 -27
  174. package/dist/api/resources/agents/resources/tools/client/Client.d.ts +6 -3
  175. package/dist/api/resources/agents/resources/tools/client/Client.js +54 -27
  176. package/dist/api/resources/batches/client/Client.d.ts +8 -4
  177. package/dist/api/resources/batches/client/Client.js +63 -30
  178. package/dist/api/resources/blocks/client/Client.d.ts +12 -6
  179. package/dist/api/resources/blocks/client/Client.js +100 -49
  180. package/dist/api/resources/blocks/resources/agents/client/Client.d.ts +2 -1
  181. package/dist/api/resources/blocks/resources/agents/client/Client.js +19 -10
  182. package/dist/api/resources/clientSideAccessTokens/client/Client.d.ts +6 -3
  183. package/dist/api/resources/clientSideAccessTokens/client/Client.js +46 -22
  184. package/dist/api/resources/embeddingModels/client/Client.d.ts +2 -1
  185. package/dist/api/resources/embeddingModels/client/Client.js +18 -9
  186. package/dist/api/resources/folders/client/Client.d.ts +18 -9
  187. package/dist/api/resources/folders/client/Client.js +154 -76
  188. package/dist/api/resources/folders/resources/files/client/Client.d.ts +6 -3
  189. package/dist/api/resources/folders/resources/files/client/Client.js +48 -24
  190. package/dist/api/resources/folders/resources/passages/client/Client.d.ts +2 -1
  191. package/dist/api/resources/folders/resources/passages/client/Client.js +19 -10
  192. package/dist/api/resources/groups/client/Client.d.ts +12 -6
  193. package/dist/api/resources/groups/client/Client.js +105 -52
  194. package/dist/api/resources/groups/resources/messages/client/Client.d.ts +10 -5
  195. package/dist/api/resources/groups/resources/messages/client/Client.js +91 -49
  196. package/dist/api/resources/health/client/Client.d.ts +2 -1
  197. package/dist/api/resources/health/client/Client.js +17 -8
  198. package/dist/api/resources/identities/client/Client.d.ts +14 -7
  199. package/dist/api/resources/identities/client/Client.js +123 -61
  200. package/dist/api/resources/identities/resources/properties/client/Client.d.ts +2 -1
  201. package/dist/api/resources/identities/resources/properties/client/Client.js +9 -3
  202. package/dist/api/resources/jobs/client/Client.d.ts +10 -5
  203. package/dist/api/resources/jobs/client/Client.js +92 -47
  204. package/dist/api/resources/messages/client/Client.d.ts +2 -1
  205. package/dist/api/resources/messages/client/Client.js +19 -10
  206. package/dist/api/resources/models/client/Client.d.ts +2 -1
  207. package/dist/api/resources/models/client/Client.js +27 -14
  208. package/dist/api/resources/projects/client/Client.d.ts +2 -1
  209. package/dist/api/resources/projects/client/Client.js +18 -9
  210. package/dist/api/resources/providers/client/Client.d.ts +10 -5
  211. package/dist/api/resources/providers/client/Client.js +77 -36
  212. package/dist/api/resources/runs/client/Client.d.ts +8 -4
  213. package/dist/api/resources/runs/client/Client.js +74 -38
  214. package/dist/api/resources/runs/resources/messages/client/Client.d.ts +2 -1
  215. package/dist/api/resources/runs/resources/messages/client/Client.js +21 -12
  216. package/dist/api/resources/runs/resources/steps/client/Client.d.ts +2 -1
  217. package/dist/api/resources/runs/resources/steps/client/Client.js +19 -10
  218. package/dist/api/resources/runs/resources/usage/client/Client.d.ts +2 -1
  219. package/dist/api/resources/runs/resources/usage/client/Client.js +18 -9
  220. package/dist/api/resources/sources/client/Client.d.ts +20 -10
  221. package/dist/api/resources/sources/client/Client.js +173 -86
  222. package/dist/api/resources/sources/resources/files/client/Client.d.ts +6 -3
  223. package/dist/api/resources/sources/resources/files/client/Client.js +48 -24
  224. package/dist/api/resources/sources/resources/passages/client/Client.d.ts +2 -1
  225. package/dist/api/resources/sources/resources/passages/client/Client.js +19 -10
  226. package/dist/api/resources/steps/client/Client.d.ts +4 -2
  227. package/dist/api/resources/steps/client/Client.js +41 -21
  228. package/dist/api/resources/steps/resources/feedback/client/Client.d.ts +2 -1
  229. package/dist/api/resources/steps/resources/feedback/client/Client.js +23 -12
  230. package/dist/api/resources/tags/client/Client.d.ts +2 -1
  231. package/dist/api/resources/tags/client/Client.js +19 -10
  232. package/dist/api/resources/telemetry/client/Client.d.ts +2 -1
  233. package/dist/api/resources/telemetry/client/Client.js +18 -9
  234. package/dist/api/resources/templates/client/Client.d.ts +2 -1
  235. package/dist/api/resources/templates/client/Client.js +18 -9
  236. package/dist/api/resources/templates/resources/agents/client/Client.d.ts +2 -1
  237. package/dist/api/resources/templates/resources/agents/client/Client.js +19 -10
  238. package/dist/api/resources/tools/client/Client.d.ts +40 -20
  239. package/dist/api/resources/tools/client/Client.js +356 -182
  240. package/dist/api/resources/voice/client/Client.d.ts +2 -1
  241. package/dist/api/resources/voice/client/Client.js +9 -3
  242. package/dist/api/types/LettaStreamingRequest.d.ts +2 -0
  243. package/dist/core/fetcher/APIResponse.d.ts +10 -0
  244. package/dist/core/fetcher/Fetcher.d.ts +1 -1
  245. package/dist/core/fetcher/Fetcher.js +11 -3
  246. package/dist/core/fetcher/Headers.d.ts +2 -0
  247. package/dist/core/fetcher/Headers.js +84 -0
  248. package/dist/core/fetcher/HttpResponsePromise.d.ts +58 -0
  249. package/dist/core/fetcher/HttpResponsePromise.js +103 -0
  250. package/dist/core/fetcher/RawResponse.d.ts +29 -0
  251. package/dist/core/fetcher/RawResponse.js +44 -0
  252. package/dist/core/fetcher/createRequestUrl.d.ts +1 -1
  253. package/dist/core/fetcher/getRequestBody.js +2 -1
  254. package/dist/core/fetcher/index.d.ts +3 -0
  255. package/dist/core/fetcher/index.js +7 -1
  256. package/dist/core/fetcher/requestWithRetries.js +1 -1
  257. package/dist/core/form-data-utils/FormDataWrapper.d.ts +3 -0
  258. package/dist/core/form-data-utils/FormDataWrapper.js +53 -10
  259. package/dist/core/form-data-utils/encodeAsFormParameter.d.ts +4 -0
  260. package/dist/core/form-data-utils/encodeAsFormParameter.js +18 -0
  261. package/dist/core/form-data-utils/index.d.ts +1 -0
  262. package/dist/core/form-data-utils/index.js +3 -0
  263. package/dist/core/json.d.ts +15 -0
  264. package/dist/core/json.js +24 -0
  265. package/dist/core/schemas/Schema.d.ts +2 -0
  266. package/dist/core/schemas/Schema.js +2 -0
  267. package/dist/core/schemas/builders/bigint/bigint.d.ts +1 -1
  268. package/dist/core/schemas/builders/bigint/bigint.js +21 -17
  269. package/dist/core/schemas/builders/object/object.js +1 -0
  270. package/dist/core/schemas/builders/record/record.js +1 -2
  271. package/dist/core/schemas/builders/schema-utils/getSchemaUtils.d.ts +4 -0
  272. package/dist/core/schemas/builders/schema-utils/getSchemaUtils.js +64 -0
  273. package/dist/core/schemas/utils/addQuestionMarksToNullableProperties.d.ts +1 -1
  274. package/dist/errors/LettaError.d.ts +4 -1
  275. package/dist/errors/LettaError.js +6 -8
  276. package/dist/serialization/types/LettaStreamingRequest.d.ts +1 -0
  277. package/dist/serialization/types/LettaStreamingRequest.js +1 -0
  278. package/dist/version.d.ts +1 -1
  279. package/dist/version.js +1 -1
  280. package/errors/LettaError.d.ts +4 -1
  281. package/errors/LettaError.js +6 -8
  282. package/package.json +4 -4
  283. package/serialization/types/LettaStreamingRequest.d.ts +1 -0
  284. package/serialization/types/LettaStreamingRequest.js +1 -0
  285. package/version.d.ts +1 -1
  286. package/version.js +1 -1
@@ -44,7 +44,8 @@ export declare class Voice {
44
44
  * }
45
45
  * })
46
46
  */
47
- createVoiceChatCompletions(agentId: string, request: Letta.CreateVoiceChatCompletionsRequest, requestOptions?: Voice.RequestOptions): Promise<unknown>;
47
+ createVoiceChatCompletions(agentId: string, request: Letta.CreateVoiceChatCompletionsRequest, requestOptions?: Voice.RequestOptions): core.HttpResponsePromise<unknown>;
48
+ private __createVoiceChatCompletions;
48
49
  protected _getCustomAuthorizationHeaders(): Promise<{
49
50
  Authorization: string;
50
51
  }>;
@@ -74,6 +74,9 @@ class Voice {
74
74
  * })
75
75
  */
76
76
  createVoiceChatCompletions(agentId, request, requestOptions) {
77
+ return core.HttpResponsePromise.fromPromise(this.__createVoiceChatCompletions(agentId, request, requestOptions));
78
+ }
79
+ __createVoiceChatCompletions(agentId, request, requestOptions) {
77
80
  return __awaiter(this, void 0, void 0, function* () {
78
81
  var _a, _b, _c;
79
82
  const { userId, body: _body } = request;
@@ -82,7 +85,7 @@ class Voice {
82
85
  method: "POST",
83
86
  headers: Object.assign(Object.assign({ "X-Project": (yield core.Supplier.get(this._options.project)) != null
84
87
  ? yield core.Supplier.get(this._options.project)
85
- : undefined, "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@letta-ai/letta-client", "X-Fern-SDK-Version": "0.1.170", "User-Agent": "@letta-ai/letta-client/0.1.170", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, "user-id": userId != null ? userId : undefined }, (yield this._getCustomAuthorizationHeaders())), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
88
+ : undefined, "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@letta-ai/letta-client", "X-Fern-SDK-Version": "0.1.172", "User-Agent": "@letta-ai/letta-client/0.1.172", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, "user-id": userId != null ? userId : undefined }, (yield this._getCustomAuthorizationHeaders())), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
86
89
  contentType: "application/json",
87
90
  requestType: "json",
88
91
  body: serializers.voice.createVoiceChatCompletions.Request.jsonOrThrow(_body, {
@@ -93,7 +96,7 @@ class Voice {
93
96
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
94
97
  });
95
98
  if (_response.ok) {
96
- return _response.body;
99
+ return { data: _response.body, rawResponse: _response.rawResponse };
97
100
  }
98
101
  if (_response.error.reason === "status-code") {
99
102
  switch (_response.error.statusCode) {
@@ -104,11 +107,12 @@ class Voice {
104
107
  allowUnrecognizedEnumValues: true,
105
108
  skipValidation: true,
106
109
  breadcrumbsPrefix: ["response"],
107
- }));
110
+ }), _response.rawResponse);
108
111
  default:
109
112
  throw new errors.LettaError({
110
113
  statusCode: _response.error.statusCode,
111
114
  body: _response.error.body,
115
+ rawResponse: _response.rawResponse,
112
116
  });
113
117
  }
114
118
  }
@@ -117,12 +121,14 @@ class Voice {
117
121
  throw new errors.LettaError({
118
122
  statusCode: _response.error.statusCode,
119
123
  body: _response.error.rawBody,
124
+ rawResponse: _response.rawResponse,
120
125
  });
121
126
  case "timeout":
122
127
  throw new errors.LettaTimeoutError("Timeout exceeded when calling POST /v1/voice-beta/{agent_id}/chat/completions.");
123
128
  case "unknown":
124
129
  throw new errors.LettaError({
125
130
  message: _response.error.errorMessage,
131
+ rawResponse: _response.rawResponse,
126
132
  });
127
133
  }
128
134
  });
@@ -19,4 +19,6 @@ export interface LettaStreamingRequest {
19
19
  enableThinking?: string;
20
20
  /** Flag to determine if individual tokens should be streamed. Set to True for token streaming (requires stream_steps = True). */
21
21
  streamTokens?: boolean;
22
+ /** Whether to include periodic keepalive ping messages in the stream to prevent connection timeouts. */
23
+ includePings?: boolean;
22
24
  }
@@ -1,10 +1,20 @@
1
+ import { RawResponse } from "./RawResponse";
2
+ /**
3
+ * The response of an API call.
4
+ * It is a successful response or a failed response.
5
+ */
1
6
  export type APIResponse<Success, Failure> = SuccessfulResponse<Success> | FailedResponse<Failure>;
2
7
  export interface SuccessfulResponse<T> {
3
8
  ok: true;
4
9
  body: T;
10
+ /**
11
+ * @deprecated Use `rawResponse` instead
12
+ */
5
13
  headers?: Record<string, any>;
14
+ rawResponse: RawResponse;
6
15
  }
7
16
  export interface FailedResponse<T> {
8
17
  ok: false;
9
18
  error: T;
19
+ rawResponse: RawResponse;
10
20
  }
@@ -6,7 +6,7 @@ export declare namespace Fetcher {
6
6
  method: string;
7
7
  contentType?: string;
8
8
  headers?: Record<string, string | undefined>;
9
- queryParameters?: Record<string, string | string[] | object | object[]>;
9
+ queryParameters?: Record<string, string | string[] | object | object[] | null>;
10
10
  body?: unknown;
11
11
  timeoutMs?: number;
12
12
  maxRetries?: number;
@@ -11,6 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.fetcher = void 0;
13
13
  exports.fetcherImpl = fetcherImpl;
14
+ const json_1 = require("../json");
15
+ const RawResponse_1 = require("./RawResponse");
14
16
  const createRequestUrl_1 = require("./createRequestUrl");
15
17
  const getFetchFn_1 = require("./getFetchFn");
16
18
  const getRequestBody_1 = require("./getRequestBody");
@@ -31,7 +33,7 @@ function fetcherImpl(args) {
31
33
  }
32
34
  }
33
35
  const url = (0, createRequestUrl_1.createRequestUrl)(args.url, args.queryParameters);
34
- let requestBody = yield (0, getRequestBody_1.getRequestBody)({
36
+ const requestBody = yield (0, getRequestBody_1.getRequestBody)({
35
37
  body: args.body,
36
38
  type: args.requestType === "json" ? "json" : "other",
37
39
  });
@@ -40,12 +42,13 @@ function fetcherImpl(args) {
40
42
  const response = yield (0, requestWithRetries_1.requestWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
41
43
  return (0, makeRequest_1.makeRequest)(fetchFn, url, args.method, headers, requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex);
42
44
  }), args.maxRetries);
43
- let responseBody = yield (0, getResponseBody_1.getResponseBody)(response, args.responseType);
45
+ const responseBody = yield (0, getResponseBody_1.getResponseBody)(response, args.responseType);
44
46
  if (response.status >= 200 && response.status < 400) {
45
47
  return {
46
48
  ok: true,
47
49
  body: responseBody,
48
50
  headers: response.headers,
51
+ rawResponse: (0, RawResponse_1.toRawResponse)(response),
49
52
  };
50
53
  }
51
54
  else {
@@ -56,6 +59,7 @@ function fetcherImpl(args) {
56
59
  statusCode: response.status,
57
60
  body: responseBody,
58
61
  },
62
+ rawResponse: (0, RawResponse_1.toRawResponse)(response),
59
63
  };
60
64
  }
61
65
  }
@@ -67,6 +71,7 @@ function fetcherImpl(args) {
67
71
  reason: "unknown",
68
72
  errorMessage: "The user aborted a request",
69
73
  },
74
+ rawResponse: RawResponse_1.abortRawResponse,
70
75
  };
71
76
  }
72
77
  else if (error instanceof Error && error.name === "AbortError") {
@@ -75,6 +80,7 @@ function fetcherImpl(args) {
75
80
  error: {
76
81
  reason: "timeout",
77
82
  },
83
+ rawResponse: RawResponse_1.abortRawResponse,
78
84
  };
79
85
  }
80
86
  else if (error instanceof Error) {
@@ -84,14 +90,16 @@ function fetcherImpl(args) {
84
90
  reason: "unknown",
85
91
  errorMessage: error.message,
86
92
  },
93
+ rawResponse: RawResponse_1.unknownRawResponse,
87
94
  };
88
95
  }
89
96
  return {
90
97
  ok: false,
91
98
  error: {
92
99
  reason: "unknown",
93
- errorMessage: JSON.stringify(error),
100
+ errorMessage: (0, json_1.toJson)(error),
94
101
  },
102
+ rawResponse: RawResponse_1.unknownRawResponse,
95
103
  };
96
104
  }
97
105
  });
@@ -0,0 +1,2 @@
1
+ declare let Headers: typeof globalThis.Headers;
2
+ export { Headers };
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Headers = void 0;
4
+ let Headers;
5
+ if (typeof globalThis.Headers !== "undefined") {
6
+ exports.Headers = Headers = globalThis.Headers;
7
+ }
8
+ else {
9
+ exports.Headers = Headers = class Headers {
10
+ constructor(init) {
11
+ this.headers = new Map();
12
+ if (init) {
13
+ if (init instanceof Headers) {
14
+ init.forEach((value, key) => this.append(key, value));
15
+ }
16
+ else if (Array.isArray(init)) {
17
+ for (const [key, value] of init) {
18
+ if (typeof key === "string" && typeof value === "string") {
19
+ this.append(key, value);
20
+ }
21
+ else {
22
+ throw new TypeError("Each header entry must be a [string, string] tuple");
23
+ }
24
+ }
25
+ }
26
+ else {
27
+ for (const [key, value] of Object.entries(init)) {
28
+ if (typeof value === "string") {
29
+ this.append(key, value);
30
+ }
31
+ else {
32
+ throw new TypeError("Header values must be strings");
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+ append(name, value) {
39
+ const key = name.toLowerCase();
40
+ const existing = this.headers.get(key) || [];
41
+ this.headers.set(key, [...existing, value]);
42
+ }
43
+ delete(name) {
44
+ const key = name.toLowerCase();
45
+ this.headers.delete(key);
46
+ }
47
+ get(name) {
48
+ const key = name.toLowerCase();
49
+ const values = this.headers.get(key);
50
+ return values ? values.join(", ") : null;
51
+ }
52
+ has(name) {
53
+ const key = name.toLowerCase();
54
+ return this.headers.has(key);
55
+ }
56
+ set(name, value) {
57
+ const key = name.toLowerCase();
58
+ this.headers.set(key, [value]);
59
+ }
60
+ forEach(callbackfn, thisArg) {
61
+ const boundCallback = thisArg ? callbackfn.bind(thisArg) : callbackfn;
62
+ this.headers.forEach((values, key) => boundCallback(values.join(", "), key, this));
63
+ }
64
+ getSetCookie() {
65
+ return this.headers.get("set-cookie") || [];
66
+ }
67
+ *entries() {
68
+ for (const [key, values] of this.headers.entries()) {
69
+ yield [key, values.join(", ")];
70
+ }
71
+ }
72
+ *keys() {
73
+ yield* this.headers.keys();
74
+ }
75
+ *values() {
76
+ for (const values of this.headers.values()) {
77
+ yield values.join(", ");
78
+ }
79
+ }
80
+ [Symbol.iterator]() {
81
+ return this.entries();
82
+ }
83
+ };
84
+ }
@@ -0,0 +1,58 @@
1
+ import { WithRawResponse } from "./RawResponse";
2
+ /**
3
+ * A promise that returns the parsed response and lets you retrieve the raw response too.
4
+ */
5
+ export declare class HttpResponsePromise<T> extends Promise<T> {
6
+ private innerPromise;
7
+ private unwrappedPromise;
8
+ private constructor();
9
+ /**
10
+ * Creates an `HttpResponsePromise` from a function that returns a promise.
11
+ *
12
+ * @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
13
+ * @param args - Arguments to pass to the function.
14
+ * @returns An `HttpResponsePromise` instance.
15
+ */
16
+ static fromFunction<F extends (...args: never[]) => Promise<WithRawResponse<T>>, T>(fn: F, ...args: Parameters<F>): HttpResponsePromise<T>;
17
+ /**
18
+ * Creates a function that returns an `HttpResponsePromise` from a function that returns a promise.
19
+ *
20
+ * @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
21
+ * @returns A function that returns an `HttpResponsePromise` instance.
22
+ */
23
+ static interceptFunction<F extends (...args: never[]) => Promise<WithRawResponse<T>>, T = Awaited<ReturnType<F>>["data"]>(fn: F): (...args: Parameters<F>) => HttpResponsePromise<T>;
24
+ /**
25
+ * Creates an `HttpResponsePromise` from an existing promise.
26
+ *
27
+ * @param promise - A promise resolving to a `WithRawResponse` object.
28
+ * @returns An `HttpResponsePromise` instance.
29
+ */
30
+ static fromPromise<T>(promise: Promise<WithRawResponse<T>>): HttpResponsePromise<T>;
31
+ /**
32
+ * Creates an `HttpResponsePromise` from an executor function.
33
+ *
34
+ * @param executor - A function that takes resolve and reject callbacks to create a promise.
35
+ * @returns An `HttpResponsePromise` instance.
36
+ */
37
+ static fromExecutor<T>(executor: (resolve: (value: WithRawResponse<T>) => void, reject: (reason?: unknown) => void) => void): HttpResponsePromise<T>;
38
+ /**
39
+ * Creates an `HttpResponsePromise` from a resolved result.
40
+ *
41
+ * @param result - A `WithRawResponse` object to resolve immediately.
42
+ * @returns An `HttpResponsePromise` instance.
43
+ */
44
+ static fromResult<T>(result: WithRawResponse<T>): HttpResponsePromise<T>;
45
+ private unwrap;
46
+ /** @inheritdoc */
47
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
48
+ /** @inheritdoc */
49
+ catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
50
+ /** @inheritdoc */
51
+ finally(onfinally?: (() => void) | null): Promise<T>;
52
+ /**
53
+ * Retrieves the data and raw response.
54
+ *
55
+ * @returns A promise resolving to a `WithRawResponse` object.
56
+ */
57
+ withRawResponse(): Promise<WithRawResponse<T>>;
58
+ }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.HttpResponsePromise = void 0;
13
+ /**
14
+ * A promise that returns the parsed response and lets you retrieve the raw response too.
15
+ */
16
+ class HttpResponsePromise extends Promise {
17
+ constructor(promise) {
18
+ // Initialize with a no-op to avoid premature parsing
19
+ super((resolve) => {
20
+ resolve(undefined);
21
+ });
22
+ this.innerPromise = promise;
23
+ }
24
+ /**
25
+ * Creates an `HttpResponsePromise` from a function that returns a promise.
26
+ *
27
+ * @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
28
+ * @param args - Arguments to pass to the function.
29
+ * @returns An `HttpResponsePromise` instance.
30
+ */
31
+ static fromFunction(fn, ...args) {
32
+ return new HttpResponsePromise(fn(...args));
33
+ }
34
+ /**
35
+ * Creates a function that returns an `HttpResponsePromise` from a function that returns a promise.
36
+ *
37
+ * @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
38
+ * @returns A function that returns an `HttpResponsePromise` instance.
39
+ */
40
+ static interceptFunction(fn) {
41
+ return (...args) => {
42
+ return HttpResponsePromise.fromPromise(fn(...args));
43
+ };
44
+ }
45
+ /**
46
+ * Creates an `HttpResponsePromise` from an existing promise.
47
+ *
48
+ * @param promise - A promise resolving to a `WithRawResponse` object.
49
+ * @returns An `HttpResponsePromise` instance.
50
+ */
51
+ static fromPromise(promise) {
52
+ return new HttpResponsePromise(promise);
53
+ }
54
+ /**
55
+ * Creates an `HttpResponsePromise` from an executor function.
56
+ *
57
+ * @param executor - A function that takes resolve and reject callbacks to create a promise.
58
+ * @returns An `HttpResponsePromise` instance.
59
+ */
60
+ static fromExecutor(executor) {
61
+ const promise = new Promise(executor);
62
+ return new HttpResponsePromise(promise);
63
+ }
64
+ /**
65
+ * Creates an `HttpResponsePromise` from a resolved result.
66
+ *
67
+ * @param result - A `WithRawResponse` object to resolve immediately.
68
+ * @returns An `HttpResponsePromise` instance.
69
+ */
70
+ static fromResult(result) {
71
+ const promise = Promise.resolve(result);
72
+ return new HttpResponsePromise(promise);
73
+ }
74
+ unwrap() {
75
+ if (!this.unwrappedPromise) {
76
+ this.unwrappedPromise = this.innerPromise.then(({ data }) => data);
77
+ }
78
+ return this.unwrappedPromise;
79
+ }
80
+ /** @inheritdoc */
81
+ then(onfulfilled, onrejected) {
82
+ return this.unwrap().then(onfulfilled, onrejected);
83
+ }
84
+ /** @inheritdoc */
85
+ catch(onrejected) {
86
+ return this.unwrap().catch(onrejected);
87
+ }
88
+ /** @inheritdoc */
89
+ finally(onfinally) {
90
+ return this.unwrap().finally(onfinally);
91
+ }
92
+ /**
93
+ * Retrieves the data and raw response.
94
+ *
95
+ * @returns A promise resolving to a `WithRawResponse` object.
96
+ */
97
+ withRawResponse() {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ return yield this.innerPromise;
100
+ });
101
+ }
102
+ }
103
+ exports.HttpResponsePromise = HttpResponsePromise;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The raw response from the fetch call excluding the body.
3
+ */
4
+ export type RawResponse = Omit<{
5
+ [K in keyof Response as Response[K] extends Function ? never : K]: Response[K];
6
+ }, "ok" | "body" | "bodyUsed">;
7
+ /**
8
+ * A raw response indicating that the request was aborted.
9
+ */
10
+ export declare const abortRawResponse: RawResponse;
11
+ /**
12
+ * A raw response indicating an unknown error.
13
+ */
14
+ export declare const unknownRawResponse: RawResponse;
15
+ /**
16
+ * Converts a `RawResponse` object into a `RawResponse` by extracting its properties,
17
+ * excluding the `body` and `bodyUsed` fields.
18
+ *
19
+ * @param response - The `RawResponse` object to convert.
20
+ * @returns A `RawResponse` object containing the extracted properties of the input response.
21
+ */
22
+ export declare function toRawResponse(response: Response): RawResponse;
23
+ /**
24
+ * Creates a `RawResponse` from a standard `Response` object.
25
+ */
26
+ export interface WithRawResponse<T> {
27
+ readonly data: T;
28
+ readonly rawResponse: RawResponse;
29
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unknownRawResponse = exports.abortRawResponse = void 0;
4
+ exports.toRawResponse = toRawResponse;
5
+ const Headers_1 = require("./Headers");
6
+ /**
7
+ * A raw response indicating that the request was aborted.
8
+ */
9
+ exports.abortRawResponse = {
10
+ headers: new Headers_1.Headers(),
11
+ redirected: false,
12
+ status: 499,
13
+ statusText: "Client Closed Request",
14
+ type: "error",
15
+ url: "",
16
+ };
17
+ /**
18
+ * A raw response indicating an unknown error.
19
+ */
20
+ exports.unknownRawResponse = {
21
+ headers: new Headers_1.Headers(),
22
+ redirected: false,
23
+ status: 0,
24
+ statusText: "Unknown Error",
25
+ type: "error",
26
+ url: "",
27
+ };
28
+ /**
29
+ * Converts a `RawResponse` object into a `RawResponse` by extracting its properties,
30
+ * excluding the `body` and `bodyUsed` fields.
31
+ *
32
+ * @param response - The `RawResponse` object to convert.
33
+ * @returns A `RawResponse` object containing the extracted properties of the input response.
34
+ */
35
+ function toRawResponse(response) {
36
+ return {
37
+ headers: response.headers,
38
+ redirected: response.redirected,
39
+ status: response.status,
40
+ statusText: response.statusText,
41
+ type: response.type,
42
+ url: response.url,
43
+ };
44
+ }
@@ -1 +1 @@
1
- export declare function createRequestUrl(baseUrl: string, queryParameters?: Record<string, string | string[] | object | object[]>): string;
1
+ export declare function createRequestUrl(baseUrl: string, queryParameters?: Record<string, string | string[] | object | object[] | null>): string;
@@ -10,10 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getRequestBody = getRequestBody;
13
+ const json_1 = require("../json");
13
14
  function getRequestBody(_a) {
14
15
  return __awaiter(this, arguments, void 0, function* ({ body, type }) {
15
16
  if (type.includes("json")) {
16
- return JSON.stringify(body);
17
+ return (0, json_1.toJson)(body);
17
18
  }
18
19
  else {
19
20
  return body;
@@ -3,3 +3,6 @@ export { fetcher } from "./Fetcher";
3
3
  export type { Fetcher, FetchFunction } from "./Fetcher";
4
4
  export { getHeader } from "./getHeader";
5
5
  export { Supplier } from "./Supplier";
6
+ export { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse";
7
+ export type { RawResponse, WithRawResponse } from "./RawResponse";
8
+ export { HttpResponsePromise } from "./HttpResponsePromise";
@@ -1,9 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Supplier = exports.getHeader = exports.fetcher = void 0;
3
+ exports.HttpResponsePromise = exports.unknownRawResponse = exports.toRawResponse = exports.abortRawResponse = exports.Supplier = exports.getHeader = exports.fetcher = void 0;
4
4
  var Fetcher_1 = require("./Fetcher");
5
5
  Object.defineProperty(exports, "fetcher", { enumerable: true, get: function () { return Fetcher_1.fetcher; } });
6
6
  var getHeader_1 = require("./getHeader");
7
7
  Object.defineProperty(exports, "getHeader", { enumerable: true, get: function () { return getHeader_1.getHeader; } });
8
8
  var Supplier_1 = require("./Supplier");
9
9
  Object.defineProperty(exports, "Supplier", { enumerable: true, get: function () { return Supplier_1.Supplier; } });
10
+ var RawResponse_1 = require("./RawResponse");
11
+ Object.defineProperty(exports, "abortRawResponse", { enumerable: true, get: function () { return RawResponse_1.abortRawResponse; } });
12
+ Object.defineProperty(exports, "toRawResponse", { enumerable: true, get: function () { return RawResponse_1.toRawResponse; } });
13
+ Object.defineProperty(exports, "unknownRawResponse", { enumerable: true, get: function () { return RawResponse_1.unknownRawResponse; } });
14
+ var HttpResponsePromise_1 = require("./HttpResponsePromise");
15
+ Object.defineProperty(exports, "HttpResponsePromise", { enumerable: true, get: function () { return HttpResponsePromise_1.HttpResponsePromise; } });
@@ -23,7 +23,7 @@ function requestWithRetries(requestFn_1) {
23
23
  return __awaiter(this, arguments, void 0, function* (requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
24
24
  let response = yield requestFn();
25
25
  for (let i = 0; i < maxRetries; ++i) {
26
- if ([408, 409, 429].includes(response.status) || response.status >= 500) {
26
+ if ([408, 429].includes(response.status) || response.status >= 500) {
27
27
  // Calculate base delay using exponential backoff (in milliseconds)
28
28
  const baseDelay = Math.min(INITIAL_RETRY_DELAY * Math.pow(2, i), MAX_RETRY_DELAY);
29
29
  // Add jitter to the delay
@@ -21,6 +21,7 @@ export declare class Node18FormData implements CrossPlatformFormData {
21
21
  private fd;
22
22
  setup(): Promise<void>;
23
23
  append(key: string, value: any): void;
24
+ private getFileName;
24
25
  appendFile(key: string, value: unknown, fileName?: string): Promise<void>;
25
26
  getRequest(): Promise<FormDataRequest<unknown>>;
26
27
  }
@@ -41,6 +42,7 @@ export declare class Node16FormData implements CrossPlatformFormData {
41
42
  private fd;
42
43
  setup(): Promise<void>;
43
44
  append(key: string, value: any): void;
45
+ private getFileName;
44
46
  appendFile(key: string, value: unknown, fileName?: string): Promise<void>;
45
47
  getRequest(): FormDataRequest<Node16FormDataFd>;
46
48
  }
@@ -54,6 +56,7 @@ export declare class WebFormData implements CrossPlatformFormData {
54
56
  protected fd: WebFormDataFd;
55
57
  setup(): Promise<void>;
56
58
  append(key: string, value: any): void;
59
+ private getFileName;
57
60
  appendFile(key: string, value: any, fileName?: string): Promise<void>;
58
61
  getRequest(): FormDataRequest<WebFormDataFd>;
59
62
  }