@puku-ai/sdk 4.0.0 → 4.0.2

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 (583) hide show
  1. package/README.md +29 -10
  2. package/dist/index.d.ts +26 -0
  3. package/dist/index.js +32 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/vendor/_vendor/partial-json-parser/parser.d.ts +2 -0
  6. package/dist/vendor/_vendor/partial-json-parser/parser.js +223 -0
  7. package/dist/vendor/_vendor/partial-json-parser/parser.js.map +1 -0
  8. package/dist/vendor/api-promise.d.ts +2 -0
  9. package/dist/vendor/api-promise.js +3 -0
  10. package/dist/vendor/api-promise.js.map +1 -0
  11. package/dist/vendor/client.d.ts +399 -0
  12. package/dist/vendor/client.js +976 -0
  13. package/dist/vendor/client.js.map +1 -0
  14. package/dist/vendor/core/api-promise.d.ts +49 -0
  15. package/dist/vendor/core/api-promise.js +77 -0
  16. package/dist/vendor/core/api-promise.js.map +1 -0
  17. package/dist/vendor/core/api.d.ts +10 -0
  18. package/dist/vendor/core/api.js +2 -0
  19. package/dist/vendor/core/api.js.map +1 -0
  20. package/dist/vendor/core/credentials.d.ts +130 -0
  21. package/dist/vendor/core/credentials.js +274 -0
  22. package/dist/vendor/core/credentials.js.map +1 -0
  23. package/dist/vendor/core/error.d.ts +82 -0
  24. package/dist/vendor/core/error.js +140 -0
  25. package/dist/vendor/core/error.js.map +1 -0
  26. package/dist/vendor/core/middleware.d.ts +153 -0
  27. package/dist/vendor/core/middleware.js +168 -0
  28. package/dist/vendor/core/middleware.js.map +1 -0
  29. package/dist/vendor/core/pagination.d.ts +121 -0
  30. package/dist/vendor/core/pagination.js +207 -0
  31. package/dist/vendor/core/pagination.js.map +1 -0
  32. package/dist/vendor/core/resource.d.ts +5 -0
  33. package/dist/vendor/core/resource.js +8 -0
  34. package/dist/vendor/core/resource.js.map +1 -0
  35. package/dist/vendor/core/streaming.d.ts +41 -0
  36. package/dist/vendor/core/streaming.js +342 -0
  37. package/dist/vendor/core/streaming.js.map +1 -0
  38. package/dist/vendor/core/uploads.d.ts +2 -0
  39. package/dist/vendor/core/uploads.js +2 -0
  40. package/dist/vendor/core/uploads.js.map +1 -0
  41. package/dist/vendor/error.d.ts +2 -0
  42. package/dist/vendor/error.js +3 -0
  43. package/dist/vendor/error.js.map +1 -0
  44. package/dist/vendor/helpers/beta/environments.d.ts +22 -0
  45. package/dist/vendor/helpers/beta/environments.js +23 -0
  46. package/dist/vendor/helpers/beta/environments.js.map +1 -0
  47. package/dist/vendor/helpers/beta/json-schema.d.ts +36 -0
  48. package/dist/vendor/helpers/beta/json-schema.js +53 -0
  49. package/dist/vendor/helpers/beta/json-schema.js.map +1 -0
  50. package/dist/vendor/helpers/beta/mcp.d.ts +302 -0
  51. package/dist/vendor/helpers/beta/mcp.js +406 -0
  52. package/dist/vendor/helpers/beta/mcp.js.map +1 -0
  53. package/dist/vendor/helpers/beta/memory.d.ts +10 -0
  54. package/dist/vendor/helpers/beta/memory.js +15 -0
  55. package/dist/vendor/helpers/beta/memory.js.map +1 -0
  56. package/dist/vendor/helpers/beta/standard-schema.d.ts +44 -0
  57. package/dist/vendor/helpers/beta/standard-schema.js +54 -0
  58. package/dist/vendor/helpers/beta/standard-schema.js.map +1 -0
  59. package/dist/vendor/helpers/beta/zod.d.ts +32 -0
  60. package/dist/vendor/helpers/beta/zod.js +52 -0
  61. package/dist/vendor/helpers/beta/zod.js.map +1 -0
  62. package/dist/vendor/helpers/index.d.ts +2 -0
  63. package/dist/vendor/helpers/index.js +3 -0
  64. package/dist/vendor/helpers/index.js.map +1 -0
  65. package/dist/vendor/helpers/json-schema.d.ts +17 -0
  66. package/dist/vendor/helpers/json-schema.js +34 -0
  67. package/dist/vendor/helpers/json-schema.js.map +1 -0
  68. package/dist/vendor/helpers/zod.d.ts +12 -0
  69. package/dist/vendor/helpers/zod.js +42 -0
  70. package/dist/vendor/helpers/zod.js.map +1 -0
  71. package/dist/vendor/index.d.ts +16 -0
  72. package/dist/vendor/index.js +23 -0
  73. package/dist/vendor/index.js.map +1 -0
  74. package/dist/vendor/internal/builtin-types.d.ts +72 -0
  75. package/dist/vendor/internal/builtin-types.js +3 -0
  76. package/dist/vendor/internal/builtin-types.js.map +1 -0
  77. package/dist/vendor/internal/constants.d.ts +4 -0
  78. package/dist/vendor/internal/constants.js +10 -0
  79. package/dist/vendor/internal/constants.js.map +1 -0
  80. package/dist/vendor/internal/decoders/jsonl.d.ts +9 -0
  81. package/dist/vendor/internal/decoders/jsonl.js +37 -0
  82. package/dist/vendor/internal/decoders/jsonl.js.map +1 -0
  83. package/dist/vendor/internal/decoders/line.d.ts +16 -0
  84. package/dist/vendor/internal/decoders/line.js +105 -0
  85. package/dist/vendor/internal/decoders/line.js.map +1 -0
  86. package/dist/vendor/internal/detect-platform.d.ts +14 -0
  87. package/dist/vendor/internal/detect-platform.js +155 -0
  88. package/dist/vendor/internal/detect-platform.js.map +1 -0
  89. package/dist/vendor/internal/errors.d.ts +2 -0
  90. package/dist/vendor/internal/errors.js +38 -0
  91. package/dist/vendor/internal/errors.js.map +1 -0
  92. package/dist/vendor/internal/file-store.d.ts +135 -0
  93. package/dist/vendor/internal/file-store.js +529 -0
  94. package/dist/vendor/internal/file-store.js.map +1 -0
  95. package/dist/vendor/internal/headers.d.ts +28 -0
  96. package/dist/vendor/internal/headers.js +114 -0
  97. package/dist/vendor/internal/headers.js.map +1 -0
  98. package/dist/vendor/internal/message-stream-utils.d.ts +9 -0
  99. package/dist/vendor/internal/message-stream-utils.js +30 -0
  100. package/dist/vendor/internal/message-stream-utils.js.map +1 -0
  101. package/dist/vendor/internal/node.browser.d.ts +8 -0
  102. package/dist/vendor/internal/node.browser.js +19 -0
  103. package/dist/vendor/internal/node.browser.js.map +1 -0
  104. package/dist/vendor/internal/node.d.ts +13 -0
  105. package/dist/vendor/internal/node.js +14 -0
  106. package/dist/vendor/internal/node.js.map +1 -0
  107. package/dist/vendor/internal/parse.d.ts +17 -0
  108. package/dist/vendor/internal/parse.js +62 -0
  109. package/dist/vendor/internal/parse.js.map +1 -0
  110. package/dist/vendor/internal/qs/formats.d.ts +6 -0
  111. package/dist/vendor/internal/qs/formats.js +9 -0
  112. package/dist/vendor/internal/qs/formats.js.map +1 -0
  113. package/dist/vendor/internal/qs/index.d.ts +9 -0
  114. package/dist/vendor/internal/qs/index.js +10 -0
  115. package/dist/vendor/internal/qs/index.js.map +1 -0
  116. package/dist/vendor/internal/qs/stringify.d.ts +2 -0
  117. package/dist/vendor/internal/qs/stringify.js +274 -0
  118. package/dist/vendor/internal/qs/stringify.js.map +1 -0
  119. package/dist/vendor/internal/qs/types.d.ts +56 -0
  120. package/dist/vendor/internal/qs/types.js +2 -0
  121. package/dist/vendor/internal/qs/types.js.map +1 -0
  122. package/dist/vendor/internal/qs/utils.d.ts +14 -0
  123. package/dist/vendor/internal/qs/utils.js +217 -0
  124. package/dist/vendor/internal/qs/utils.js.map +1 -0
  125. package/dist/vendor/internal/request-options.d.ts +126 -0
  126. package/dist/vendor/internal/request-options.js +27 -0
  127. package/dist/vendor/internal/request-options.js.map +1 -0
  128. package/dist/vendor/internal/request-signal.d.ts +3 -0
  129. package/dist/vendor/internal/request-signal.js +45 -0
  130. package/dist/vendor/internal/request-signal.js.map +1 -0
  131. package/dist/vendor/internal/shim-types.d.ts +16 -0
  132. package/dist/vendor/internal/shim-types.js +3 -0
  133. package/dist/vendor/internal/shim-types.js.map +1 -0
  134. package/dist/vendor/internal/shims.d.ts +25 -0
  135. package/dist/vendor/internal/shims.js +85 -0
  136. package/dist/vendor/internal/shims.js.map +1 -0
  137. package/dist/vendor/internal/stainless-helper-header.d.ts +59 -0
  138. package/dist/vendor/internal/stainless-helper-header.js +83 -0
  139. package/dist/vendor/internal/stainless-helper-header.js.map +1 -0
  140. package/dist/vendor/internal/stream-utils.d.ts +7 -0
  141. package/dist/vendor/internal/stream-utils.js +35 -0
  142. package/dist/vendor/internal/stream-utils.js.map +1 -0
  143. package/dist/vendor/internal/to-file.d.ts +44 -0
  144. package/dist/vendor/internal/to-file.js +93 -0
  145. package/dist/vendor/internal/to-file.js.map +1 -0
  146. package/dist/vendor/internal/types.d.ts +62 -0
  147. package/dist/vendor/internal/types.js +3 -0
  148. package/dist/vendor/internal/types.js.map +1 -0
  149. package/dist/vendor/internal/uploads.d.ts +41 -0
  150. package/dist/vendor/internal/uploads.js +139 -0
  151. package/dist/vendor/internal/uploads.js.map +1 -0
  152. package/dist/vendor/internal/utils/abort.d.ts +11 -0
  153. package/dist/vendor/internal/utils/abort.js +22 -0
  154. package/dist/vendor/internal/utils/abort.js.map +1 -0
  155. package/dist/vendor/internal/utils/async-queue.d.ts +30 -0
  156. package/dist/vendor/internal/utils/async-queue.js +66 -0
  157. package/dist/vendor/internal/utils/async-queue.js.map +1 -0
  158. package/dist/vendor/internal/utils/backoff.d.ts +22 -0
  159. package/dist/vendor/internal/utils/backoff.js +36 -0
  160. package/dist/vendor/internal/utils/backoff.js.map +1 -0
  161. package/dist/vendor/internal/utils/base64.d.ts +2 -0
  162. package/dist/vendor/internal/utils/base64.js +33 -0
  163. package/dist/vendor/internal/utils/base64.js.map +1 -0
  164. package/dist/vendor/internal/utils/bytes.d.ts +3 -0
  165. package/dist/vendor/internal/utils/bytes.js +26 -0
  166. package/dist/vendor/internal/utils/bytes.js.map +1 -0
  167. package/dist/vendor/internal/utils/env.d.ts +8 -0
  168. package/dist/vendor/internal/utils/env.js +18 -0
  169. package/dist/vendor/internal/utils/env.js.map +1 -0
  170. package/dist/vendor/internal/utils/log.d.ts +46 -0
  171. package/dist/vendor/internal/utils/log.js +105 -0
  172. package/dist/vendor/internal/utils/log.js.map +1 -0
  173. package/dist/vendor/internal/utils/path.d.ts +14 -0
  174. package/dist/vendor/internal/utils/path.js +74 -0
  175. package/dist/vendor/internal/utils/path.js.map +1 -0
  176. package/dist/vendor/internal/utils/promise.d.ts +10 -0
  177. package/dist/vendor/internal/utils/promise.js +15 -0
  178. package/dist/vendor/internal/utils/promise.js.map +1 -0
  179. package/dist/vendor/internal/utils/query.d.ts +1 -0
  180. package/dist/vendor/internal/utils/query.js +6 -0
  181. package/dist/vendor/internal/utils/query.js.map +1 -0
  182. package/dist/vendor/internal/utils/sleep.d.ts +9 -0
  183. package/dist/vendor/internal/utils/sleep.js +24 -0
  184. package/dist/vendor/internal/utils/sleep.js.map +1 -0
  185. package/dist/vendor/internal/utils/time.d.ts +2 -0
  186. package/dist/vendor/internal/utils/time.js +5 -0
  187. package/dist/vendor/internal/utils/time.js.map +1 -0
  188. package/dist/vendor/internal/utils/uuid.d.ts +4 -0
  189. package/dist/vendor/internal/utils/uuid.js +15 -0
  190. package/dist/vendor/internal/utils/uuid.js.map +1 -0
  191. package/dist/vendor/internal/utils/values.d.ts +24 -0
  192. package/dist/vendor/internal/utils/values.js +106 -0
  193. package/dist/vendor/internal/utils/values.js.map +1 -0
  194. package/dist/vendor/internal/utils.d.ts +7 -0
  195. package/dist/vendor/internal/utils.js +9 -0
  196. package/dist/vendor/internal/utils.js.map +1 -0
  197. package/dist/vendor/lib/BetaMessageStream.d.ts +123 -0
  198. package/dist/vendor/lib/BetaMessageStream.js +662 -0
  199. package/dist/vendor/lib/BetaMessageStream.js.map +1 -0
  200. package/dist/vendor/lib/MessageStream.d.ts +122 -0
  201. package/dist/vendor/lib/MessageStream.js +609 -0
  202. package/dist/vendor/lib/MessageStream.js.map +1 -0
  203. package/dist/vendor/lib/beta-parser.d.ts +36 -0
  204. package/dist/vendor/lib/beta-parser.js +75 -0
  205. package/dist/vendor/lib/beta-parser.js.map +1 -0
  206. package/dist/vendor/lib/credentials/credential-chain.d.ts +38 -0
  207. package/dist/vendor/lib/credentials/credential-chain.js +208 -0
  208. package/dist/vendor/lib/credentials/credential-chain.js.map +1 -0
  209. package/dist/vendor/lib/credentials/identity-token.d.ts +10 -0
  210. package/dist/vendor/lib/credentials/identity-token.js +35 -0
  211. package/dist/vendor/lib/credentials/identity-token.js.map +1 -0
  212. package/dist/vendor/lib/credentials/oidc-federation.d.ts +39 -0
  213. package/dist/vendor/lib/credentials/oidc-federation.js +79 -0
  214. package/dist/vendor/lib/credentials/oidc-federation.js.map +1 -0
  215. package/dist/vendor/lib/credentials/token-cache.d.ts +53 -0
  216. package/dist/vendor/lib/credentials/token-cache.js +110 -0
  217. package/dist/vendor/lib/credentials/token-cache.js.map +1 -0
  218. package/dist/vendor/lib/credentials/types.d.ts +95 -0
  219. package/dist/vendor/lib/credentials/types.js +226 -0
  220. package/dist/vendor/lib/credentials/types.js.map +1 -0
  221. package/dist/vendor/lib/credentials/user-oauth.d.ts +20 -0
  222. package/dist/vendor/lib/credentials/user-oauth.js +94 -0
  223. package/dist/vendor/lib/credentials/user-oauth.js.map +1 -0
  224. package/dist/vendor/lib/credentials.d.ts +3 -0
  225. package/dist/vendor/lib/credentials.js +3 -0
  226. package/dist/vendor/lib/credentials.js.map +1 -0
  227. package/dist/vendor/lib/environments/index.d.ts +3 -0
  228. package/dist/vendor/lib/environments/index.js +4 -0
  229. package/dist/vendor/lib/environments/index.js.map +1 -0
  230. package/dist/vendor/lib/environments/poller.d.ts +94 -0
  231. package/dist/vendor/lib/environments/poller.js +218 -0
  232. package/dist/vendor/lib/environments/poller.js.map +1 -0
  233. package/dist/vendor/lib/environments/worker.d.ts +226 -0
  234. package/dist/vendor/lib/environments/worker.js +572 -0
  235. package/dist/vendor/lib/environments/worker.js.map +1 -0
  236. package/dist/vendor/lib/helper-client.d.ts +30 -0
  237. package/dist/vendor/lib/helper-client.js +55 -0
  238. package/dist/vendor/lib/helper-client.js.map +1 -0
  239. package/dist/vendor/lib/middleware.d.ts +97 -0
  240. package/dist/vendor/lib/middleware.js +775 -0
  241. package/dist/vendor/lib/middleware.js.map +1 -0
  242. package/dist/vendor/lib/parser.d.ts +31 -0
  243. package/dist/vendor/lib/parser.js +62 -0
  244. package/dist/vendor/lib/parser.js.map +1 -0
  245. package/dist/vendor/lib/sessions/accumulate.d.ts +22 -0
  246. package/dist/vendor/lib/sessions/accumulate.js +42 -0
  247. package/dist/vendor/lib/sessions/accumulate.js.map +1 -0
  248. package/dist/vendor/lib/standard-schema.d.ts +130 -0
  249. package/dist/vendor/lib/standard-schema.js +41 -0
  250. package/dist/vendor/lib/standard-schema.js.map +1 -0
  251. package/dist/vendor/lib/tools/BetaRunnableTool.d.ts +48 -0
  252. package/dist/vendor/lib/tools/BetaRunnableTool.js +26 -0
  253. package/dist/vendor/lib/tools/BetaRunnableTool.js.map +1 -0
  254. package/dist/vendor/lib/tools/BetaToolRunner.d.ts +160 -0
  255. package/dist/vendor/lib/tools/BetaToolRunner.js +497 -0
  256. package/dist/vendor/lib/tools/BetaToolRunner.js.map +1 -0
  257. package/dist/vendor/lib/tools/CompactionControl.d.ts +29 -0
  258. package/dist/vendor/lib/tools/CompactionControl.js +25 -0
  259. package/dist/vendor/lib/tools/CompactionControl.js.map +1 -0
  260. package/dist/vendor/lib/tools/SessionToolRunner.d.ts +178 -0
  261. package/dist/vendor/lib/tools/SessionToolRunner.js +737 -0
  262. package/dist/vendor/lib/tools/SessionToolRunner.js.map +1 -0
  263. package/dist/vendor/lib/tools/ToolError.d.ts +32 -0
  264. package/dist/vendor/lib/tools/ToolError.js +43 -0
  265. package/dist/vendor/lib/tools/ToolError.js.map +1 -0
  266. package/dist/vendor/lib/transform-json-schema.d.ts +2 -0
  267. package/dist/vendor/lib/transform-json-schema.js +111 -0
  268. package/dist/vendor/lib/transform-json-schema.js.map +1 -0
  269. package/dist/vendor/pagination.d.ts +2 -0
  270. package/dist/vendor/pagination.js +3 -0
  271. package/dist/vendor/pagination.js.map +1 -0
  272. package/dist/vendor/resource.d.ts +2 -0
  273. package/dist/vendor/resource.js +3 -0
  274. package/dist/vendor/resource.js.map +1 -0
  275. package/dist/vendor/resources/beta/agents/agents.d.ts +1128 -0
  276. package/dist/vendor/resources/beta/agents/agents.js +123 -0
  277. package/dist/vendor/resources/beta/agents/agents.js.map +1 -0
  278. package/dist/vendor/resources/beta/agents/index.d.ts +2 -0
  279. package/dist/vendor/resources/beta/agents/index.js +4 -0
  280. package/dist/vendor/resources/beta/agents/index.js.map +1 -0
  281. package/dist/vendor/resources/beta/agents/versions.d.ts +32 -0
  282. package/dist/vendor/resources/beta/agents/versions.js +32 -0
  283. package/dist/vendor/resources/beta/agents/versions.js.map +1 -0
  284. package/dist/vendor/resources/beta/agents.d.ts +1 -0
  285. package/dist/vendor/resources/beta/agents.js +3 -0
  286. package/dist/vendor/resources/beta/agents.js.map +1 -0
  287. package/dist/vendor/resources/beta/beta.d.ts +131 -0
  288. package/dist/vendor/resources/beta/beta.js +69 -0
  289. package/dist/vendor/resources/beta/beta.js.map +1 -0
  290. package/dist/vendor/resources/beta/deployment-runs.d.ts +305 -0
  291. package/dist/vendor/resources/beta/deployment-runs.js +51 -0
  292. package/dist/vendor/resources/beta/deployment-runs.js.map +1 -0
  293. package/dist/vendor/resources/beta/deployments.d.ts +698 -0
  294. package/dist/vendor/resources/beta/deployments.js +192 -0
  295. package/dist/vendor/resources/beta/deployments.js.map +1 -0
  296. package/dist/vendor/resources/beta/dreams.d.ts +335 -0
  297. package/dist/vendor/resources/beta/dreams.js +112 -0
  298. package/dist/vendor/resources/beta/dreams.js.map +1 -0
  299. package/dist/vendor/resources/beta/environments/environments.d.ts +432 -0
  300. package/dist/vendor/resources/beta/environments/environments.js +142 -0
  301. package/dist/vendor/resources/beta/environments/environments.js.map +1 -0
  302. package/dist/vendor/resources/beta/environments/index.d.ts +2 -0
  303. package/dist/vendor/resources/beta/environments/index.js +4 -0
  304. package/dist/vendor/resources/beta/environments/index.js.map +1 -0
  305. package/dist/vendor/resources/beta/environments/work.d.ts +500 -0
  306. package/dist/vendor/resources/beta/environments/work.js +251 -0
  307. package/dist/vendor/resources/beta/environments/work.js.map +1 -0
  308. package/dist/vendor/resources/beta/environments.d.ts +1 -0
  309. package/dist/vendor/resources/beta/environments.js +3 -0
  310. package/dist/vendor/resources/beta/environments.js.map +1 -0
  311. package/dist/vendor/resources/beta/files.d.ts +190 -0
  312. package/dist/vendor/resources/beta/files.js +120 -0
  313. package/dist/vendor/resources/beta/files.js.map +1 -0
  314. package/dist/vendor/resources/beta/index.d.ts +17 -0
  315. package/dist/vendor/resources/beta/index.js +19 -0
  316. package/dist/vendor/resources/beta/index.js.map +1 -0
  317. package/dist/vendor/resources/beta/memory-stores/index.d.ts +3 -0
  318. package/dist/vendor/resources/beta/memory-stores/index.js +5 -0
  319. package/dist/vendor/resources/beta/memory-stores/index.js.map +1 -0
  320. package/dist/vendor/resources/beta/memory-stores/memories.d.ts +346 -0
  321. package/dist/vendor/resources/beta/memory-stores/memories.js +126 -0
  322. package/dist/vendor/resources/beta/memory-stores/memories.js.map +1 -0
  323. package/dist/vendor/resources/beta/memory-stores/memory-stores.d.ts +230 -0
  324. package/dist/vendor/resources/beta/memory-stores/memory-stores.js +137 -0
  325. package/dist/vendor/resources/beta/memory-stores/memory-stores.js.map +1 -0
  326. package/dist/vendor/resources/beta/memory-stores/memory-versions.d.ts +252 -0
  327. package/dist/vendor/resources/beta/memory-stores/memory-versions.js +77 -0
  328. package/dist/vendor/resources/beta/memory-stores/memory-versions.js.map +1 -0
  329. package/dist/vendor/resources/beta/memory-stores.d.ts +1 -0
  330. package/dist/vendor/resources/beta/memory-stores.js +3 -0
  331. package/dist/vendor/resources/beta/memory-stores.js.map +1 -0
  332. package/dist/vendor/resources/beta/messages/batches.d.ts +685 -0
  333. package/dist/vendor/resources/beta/messages/batches.js +203 -0
  334. package/dist/vendor/resources/beta/messages/batches.js.map +1 -0
  335. package/dist/vendor/resources/beta/messages/index.d.ts +3 -0
  336. package/dist/vendor/resources/beta/messages/index.js +5 -0
  337. package/dist/vendor/resources/beta/messages/index.js.map +1 -0
  338. package/dist/vendor/resources/beta/messages/messages.d.ts +5376 -0
  339. package/dist/vendor/resources/beta/messages/messages.js +158 -0
  340. package/dist/vendor/resources/beta/messages/messages.js.map +1 -0
  341. package/dist/vendor/resources/beta/messages.d.ts +1 -0
  342. package/dist/vendor/resources/beta/messages.js +3 -0
  343. package/dist/vendor/resources/beta/messages.js.map +1 -0
  344. package/dist/vendor/resources/beta/models.d.ts +217 -0
  345. package/dist/vendor/resources/beta/models.js +56 -0
  346. package/dist/vendor/resources/beta/models.js.map +1 -0
  347. package/dist/vendor/resources/beta/organization/api-keys.d.ts +176 -0
  348. package/dist/vendor/resources/beta/organization/api-keys.js +52 -0
  349. package/dist/vendor/resources/beta/organization/api-keys.js.map +1 -0
  350. package/dist/vendor/resources/beta/organization/compliance-settings.d.ts +73 -0
  351. package/dist/vendor/resources/beta/organization/compliance-settings.js +48 -0
  352. package/dist/vendor/resources/beta/organization/compliance-settings.js.map +1 -0
  353. package/dist/vendor/resources/beta/organization/external-keys.d.ts +271 -0
  354. package/dist/vendor/resources/beta/organization/external-keys.js +115 -0
  355. package/dist/vendor/resources/beta/organization/external-keys.js.map +1 -0
  356. package/dist/vendor/resources/beta/organization/federation/federation.d.ts +13 -0
  357. package/dist/vendor/resources/beta/organization/federation/federation.js +13 -0
  358. package/dist/vendor/resources/beta/organization/federation/federation.js.map +1 -0
  359. package/dist/vendor/resources/beta/organization/federation/index.d.ts +3 -0
  360. package/dist/vendor/resources/beta/organization/federation/index.js +5 -0
  361. package/dist/vendor/resources/beta/organization/federation/index.js.map +1 -0
  362. package/dist/vendor/resources/beta/organization/federation/issuers.d.ts +352 -0
  363. package/dist/vendor/resources/beta/organization/federation/issuers.js +165 -0
  364. package/dist/vendor/resources/beta/organization/federation/issuers.js.map +1 -0
  365. package/dist/vendor/resources/beta/organization/federation/rules/index.d.ts +2 -0
  366. package/dist/vendor/resources/beta/organization/federation/rules/index.js +4 -0
  367. package/dist/vendor/resources/beta/organization/federation/rules/index.js.map +1 -0
  368. package/dist/vendor/resources/beta/organization/federation/rules/rules.d.ts +467 -0
  369. package/dist/vendor/resources/beta/organization/federation/rules/rules.js +190 -0
  370. package/dist/vendor/resources/beta/organization/federation/rules/rules.js.map +1 -0
  371. package/dist/vendor/resources/beta/organization/federation/rules/workspaces.d.ts +123 -0
  372. package/dist/vendor/resources/beta/organization/federation/rules/workspaces.js +110 -0
  373. package/dist/vendor/resources/beta/organization/federation/rules/workspaces.js.map +1 -0
  374. package/dist/vendor/resources/beta/organization/federation/rules.d.ts +1 -0
  375. package/dist/vendor/resources/beta/organization/federation/rules.js +3 -0
  376. package/dist/vendor/resources/beta/organization/federation/rules.js.map +1 -0
  377. package/dist/vendor/resources/beta/organization/federation.d.ts +1 -0
  378. package/dist/vendor/resources/beta/organization/federation.js +3 -0
  379. package/dist/vendor/resources/beta/organization/federation.js.map +1 -0
  380. package/dist/vendor/resources/beta/organization/index.d.ts +10 -0
  381. package/dist/vendor/resources/beta/organization/index.js +12 -0
  382. package/dist/vendor/resources/beta/organization/index.js.map +1 -0
  383. package/dist/vendor/resources/beta/organization/invites.d.ts +161 -0
  384. package/dist/vendor/resources/beta/organization/invites.js +72 -0
  385. package/dist/vendor/resources/beta/organization/invites.js.map +1 -0
  386. package/dist/vendor/resources/beta/organization/organization.d.ts +72 -0
  387. package/dist/vendor/resources/beta/organization/organization.js +54 -0
  388. package/dist/vendor/resources/beta/organization/organization.js.map +1 -0
  389. package/dist/vendor/resources/beta/organization/rate-limits.d.ts +76 -0
  390. package/dist/vendor/resources/beta/organization/rate-limits.js +27 -0
  391. package/dist/vendor/resources/beta/organization/rate-limits.js.map +1 -0
  392. package/dist/vendor/resources/beta/organization/service-accounts/index.d.ts +2 -0
  393. package/dist/vendor/resources/beta/organization/service-accounts/index.js +4 -0
  394. package/dist/vendor/resources/beta/organization/service-accounts/index.js.map +1 -0
  395. package/dist/vendor/resources/beta/organization/service-accounts/service-accounts.d.ts +257 -0
  396. package/dist/vendor/resources/beta/organization/service-accounts/service-accounts.js +166 -0
  397. package/dist/vendor/resources/beta/organization/service-accounts/service-accounts.js.map +1 -0
  398. package/dist/vendor/resources/beta/organization/service-accounts/workspaces.d.ts +140 -0
  399. package/dist/vendor/resources/beta/organization/service-accounts/workspaces.js +121 -0
  400. package/dist/vendor/resources/beta/organization/service-accounts/workspaces.js.map +1 -0
  401. package/dist/vendor/resources/beta/organization/service-accounts.d.ts +1 -0
  402. package/dist/vendor/resources/beta/organization/service-accounts.js +3 -0
  403. package/dist/vendor/resources/beta/organization/service-accounts.js.map +1 -0
  404. package/dist/vendor/resources/beta/organization/users.d.ts +123 -0
  405. package/dist/vendor/resources/beta/organization/users.js +63 -0
  406. package/dist/vendor/resources/beta/organization/users.js.map +1 -0
  407. package/dist/vendor/resources/beta/organization/workspaces/index.d.ts +4 -0
  408. package/dist/vendor/resources/beta/organization/workspaces/index.js +6 -0
  409. package/dist/vendor/resources/beta/organization/workspaces/index.js.map +1 -0
  410. package/dist/vendor/resources/beta/organization/workspaces/members.d.ts +134 -0
  411. package/dist/vendor/resources/beta/organization/workspaces/members.js +98 -0
  412. package/dist/vendor/resources/beta/organization/workspaces/members.js.map +1 -0
  413. package/dist/vendor/resources/beta/organization/workspaces/rate-limits.d.ts +82 -0
  414. package/dist/vendor/resources/beta/organization/workspaces/rate-limits.js +30 -0
  415. package/dist/vendor/resources/beta/organization/workspaces/rate-limits.js.map +1 -0
  416. package/dist/vendor/resources/beta/organization/workspaces/service-accounts.d.ts +209 -0
  417. package/dist/vendor/resources/beta/organization/workspaces/service-accounts.js +185 -0
  418. package/dist/vendor/resources/beta/organization/workspaces/service-accounts.js.map +1 -0
  419. package/dist/vendor/resources/beta/organization/workspaces/workspaces.d.ts +302 -0
  420. package/dist/vendor/resources/beta/organization/workspaces/workspaces.js +104 -0
  421. package/dist/vendor/resources/beta/organization/workspaces/workspaces.js.map +1 -0
  422. package/dist/vendor/resources/beta/organization/workspaces.d.ts +1 -0
  423. package/dist/vendor/resources/beta/organization/workspaces.js +3 -0
  424. package/dist/vendor/resources/beta/organization/workspaces.js.map +1 -0
  425. package/dist/vendor/resources/beta/organization.d.ts +1 -0
  426. package/dist/vendor/resources/beta/organization.js +3 -0
  427. package/dist/vendor/resources/beta/organization.js.map +1 -0
  428. package/dist/vendor/resources/beta/sessions/events.d.ts +1513 -0
  429. package/dist/vendor/resources/beta/sessions/events.js +115 -0
  430. package/dist/vendor/resources/beta/sessions/events.js.map +1 -0
  431. package/dist/vendor/resources/beta/sessions/index.d.ts +4 -0
  432. package/dist/vendor/resources/beta/sessions/index.js +6 -0
  433. package/dist/vendor/resources/beta/sessions/index.js.map +1 -0
  434. package/dist/vendor/resources/beta/sessions/resources.d.ts +227 -0
  435. package/dist/vendor/resources/beta/sessions/resources.js +128 -0
  436. package/dist/vendor/resources/beta/sessions/resources.js.map +1 -0
  437. package/dist/vendor/resources/beta/sessions/sessions.d.ts +866 -0
  438. package/dist/vendor/resources/beta/sessions/sessions.js +150 -0
  439. package/dist/vendor/resources/beta/sessions/sessions.js.map +1 -0
  440. package/dist/vendor/resources/beta/sessions/threads/events.d.ts +77 -0
  441. package/dist/vendor/resources/beta/sessions/threads/events.js +57 -0
  442. package/dist/vendor/resources/beta/sessions/threads/events.js.map +1 -0
  443. package/dist/vendor/resources/beta/sessions/threads/index.d.ts +2 -0
  444. package/dist/vendor/resources/beta/sessions/threads/index.js +4 -0
  445. package/dist/vendor/resources/beta/sessions/threads/index.js.map +1 -0
  446. package/dist/vendor/resources/beta/sessions/threads/threads.d.ts +195 -0
  447. package/dist/vendor/resources/beta/sessions/threads/threads.js +80 -0
  448. package/dist/vendor/resources/beta/sessions/threads/threads.js.map +1 -0
  449. package/dist/vendor/resources/beta/sessions/threads.d.ts +1 -0
  450. package/dist/vendor/resources/beta/sessions/threads.js +3 -0
  451. package/dist/vendor/resources/beta/sessions/threads.js.map +1 -0
  452. package/dist/vendor/resources/beta/sessions.d.ts +1 -0
  453. package/dist/vendor/resources/beta/sessions.js +3 -0
  454. package/dist/vendor/resources/beta/sessions.js.map +1 -0
  455. package/dist/vendor/resources/beta/skills/index.d.ts +2 -0
  456. package/dist/vendor/resources/beta/skills/index.js +4 -0
  457. package/dist/vendor/resources/beta/skills/index.js.map +1 -0
  458. package/dist/vendor/resources/beta/skills/skills.d.ts +178 -0
  459. package/dist/vendor/resources/beta/skills/skills.js +96 -0
  460. package/dist/vendor/resources/beta/skills/skills.js.map +1 -0
  461. package/dist/vendor/resources/beta/skills/versions.d.ts +181 -0
  462. package/dist/vendor/resources/beta/skills/versions.js +125 -0
  463. package/dist/vendor/resources/beta/skills/versions.js.map +1 -0
  464. package/dist/vendor/resources/beta/skills.d.ts +1 -0
  465. package/dist/vendor/resources/beta/skills.js +3 -0
  466. package/dist/vendor/resources/beta/skills.js.map +1 -0
  467. package/dist/vendor/resources/beta/tunnels/certificates.d.ts +162 -0
  468. package/dist/vendor/resources/beta/tunnels/certificates.js +125 -0
  469. package/dist/vendor/resources/beta/tunnels/certificates.js.map +1 -0
  470. package/dist/vendor/resources/beta/tunnels/index.d.ts +2 -0
  471. package/dist/vendor/resources/beta/tunnels/index.js +4 -0
  472. package/dist/vendor/resources/beta/tunnels/index.js.map +1 -0
  473. package/dist/vendor/resources/beta/tunnels/tunnels.d.ts +211 -0
  474. package/dist/vendor/resources/beta/tunnels/tunnels.js +173 -0
  475. package/dist/vendor/resources/beta/tunnels/tunnels.js.map +1 -0
  476. package/dist/vendor/resources/beta/tunnels.d.ts +1 -0
  477. package/dist/vendor/resources/beta/tunnels.js +3 -0
  478. package/dist/vendor/resources/beta/tunnels.js.map +1 -0
  479. package/dist/vendor/resources/beta/user-profiles.d.ts +244 -0
  480. package/dist/vendor/resources/beta/user-profiles.js +114 -0
  481. package/dist/vendor/resources/beta/user-profiles.js.map +1 -0
  482. package/dist/vendor/resources/beta/vaults/credentials.d.ts +715 -0
  483. package/dist/vendor/resources/beta/vaults/credentials.js +173 -0
  484. package/dist/vendor/resources/beta/vaults/credentials.js.map +1 -0
  485. package/dist/vendor/resources/beta/vaults/index.d.ts +2 -0
  486. package/dist/vendor/resources/beta/vaults/index.js +4 -0
  487. package/dist/vendor/resources/beta/vaults/index.js.map +1 -0
  488. package/dist/vendor/resources/beta/vaults/vaults.d.ts +191 -0
  489. package/dist/vendor/resources/beta/vaults/vaults.js +141 -0
  490. package/dist/vendor/resources/beta/vaults/vaults.js.map +1 -0
  491. package/dist/vendor/resources/beta/vaults.d.ts +1 -0
  492. package/dist/vendor/resources/beta/vaults.js +3 -0
  493. package/dist/vendor/resources/beta/vaults.js.map +1 -0
  494. package/dist/vendor/resources/beta/webhooks.d.ts +464 -0
  495. package/dist/vendor/resources/beta/webhooks.js +29 -0
  496. package/dist/vendor/resources/beta/webhooks.js.map +1 -0
  497. package/dist/vendor/resources/beta.d.ts +1 -0
  498. package/dist/vendor/resources/beta.js +3 -0
  499. package/dist/vendor/resources/beta.js.map +1 -0
  500. package/dist/vendor/resources/completions.d.ts +172 -0
  501. package/dist/vendor/resources/completions.js +19 -0
  502. package/dist/vendor/resources/completions.js.map +1 -0
  503. package/dist/vendor/resources/files.d.ts +104 -0
  504. package/dist/vendor/resources/files.js +48 -0
  505. package/dist/vendor/resources/files.js.map +1 -0
  506. package/dist/vendor/resources/index.d.ts +7 -0
  507. package/dist/vendor/resources/index.js +9 -0
  508. package/dist/vendor/resources/index.js.map +1 -0
  509. package/dist/vendor/resources/messages/batches.d.ts +312 -0
  510. package/dist/vendor/resources/messages/batches.js +157 -0
  511. package/dist/vendor/resources/messages/batches.js.map +1 -0
  512. package/dist/vendor/resources/messages/index.d.ts +2 -0
  513. package/dist/vendor/resources/messages/index.js +4 -0
  514. package/dist/vendor/resources/messages/index.js.map +1 -0
  515. package/dist/vendor/resources/messages/messages.d.ts +3886 -0
  516. package/dist/vendor/resources/messages/messages.js +130 -0
  517. package/dist/vendor/resources/messages/messages.js.map +1 -0
  518. package/dist/vendor/resources/messages.d.ts +1 -0
  519. package/dist/vendor/resources/messages.js +3 -0
  520. package/dist/vendor/resources/messages.js.map +1 -0
  521. package/dist/vendor/resources/models.d.ts +196 -0
  522. package/dist/vendor/resources/models.js +41 -0
  523. package/dist/vendor/resources/models.js.map +1 -0
  524. package/dist/vendor/resources/shared.d.ts +43 -0
  525. package/dist/vendor/resources/shared.js +3 -0
  526. package/dist/vendor/resources/shared.js.map +1 -0
  527. package/dist/vendor/resources/skills/index.d.ts +2 -0
  528. package/dist/vendor/resources/skills/index.js +4 -0
  529. package/dist/vendor/resources/skills/index.js.map +1 -0
  530. package/dist/vendor/resources/skills/skills.d.ts +128 -0
  531. package/dist/vendor/resources/skills/skills.js +36 -0
  532. package/dist/vendor/resources/skills/skills.js.map +1 -0
  533. package/dist/vendor/resources/skills/versions.d.ts +103 -0
  534. package/dist/vendor/resources/skills/versions.js +37 -0
  535. package/dist/vendor/resources/skills/versions.js.map +1 -0
  536. package/dist/vendor/resources/skills.d.ts +1 -0
  537. package/dist/vendor/resources/skills.js +3 -0
  538. package/dist/vendor/resources/skills.js.map +1 -0
  539. package/dist/vendor/resources/top-level.d.ts +1 -0
  540. package/dist/vendor/resources/top-level.js +3 -0
  541. package/dist/vendor/resources/top-level.js.map +1 -0
  542. package/dist/vendor/resources.d.ts +1 -0
  543. package/dist/vendor/resources.js +2 -0
  544. package/dist/vendor/resources.js.map +1 -0
  545. package/dist/vendor/streaming.d.ts +2 -0
  546. package/dist/vendor/streaming.js +3 -0
  547. package/dist/vendor/streaming.js.map +1 -0
  548. package/dist/vendor/tools/agent-toolset/fs-util.d.ts +74 -0
  549. package/dist/vendor/tools/agent-toolset/fs-util.js +184 -0
  550. package/dist/vendor/tools/agent-toolset/fs-util.js.map +1 -0
  551. package/dist/vendor/tools/agent-toolset/memories.d.ts +172 -0
  552. package/dist/vendor/tools/agent-toolset/memories.js +910 -0
  553. package/dist/vendor/tools/agent-toolset/memories.js.map +1 -0
  554. package/dist/vendor/tools/agent-toolset/node.browser.d.ts +80 -0
  555. package/dist/vendor/tools/agent-toolset/node.browser.js +129 -0
  556. package/dist/vendor/tools/agent-toolset/node.browser.js.map +1 -0
  557. package/dist/vendor/tools/agent-toolset/node.d.ts +191 -0
  558. package/dist/vendor/tools/agent-toolset/node.js +886 -0
  559. package/dist/vendor/tools/agent-toolset/node.js.map +1 -0
  560. package/dist/vendor/tools/agent-toolset/skills.d.ts +73 -0
  561. package/dist/vendor/tools/agent-toolset/skills.js +320 -0
  562. package/dist/vendor/tools/agent-toolset/skills.js.map +1 -0
  563. package/dist/vendor/tools/agent-toolset/sync-interval.d.ts +18 -0
  564. package/dist/vendor/tools/agent-toolset/sync-interval.js +25 -0
  565. package/dist/vendor/tools/agent-toolset/sync-interval.js.map +1 -0
  566. package/dist/vendor/tools/memory/node.browser.d.ts +26 -0
  567. package/dist/vendor/tools/memory/node.browser.js +44 -0
  568. package/dist/vendor/tools/memory/node.browser.js.map +1 -0
  569. package/dist/vendor/tools/memory/node.d.ts +17 -0
  570. package/dist/vendor/tools/memory/node.js +327 -0
  571. package/dist/vendor/tools/memory/node.js.map +1 -0
  572. package/dist/vendor/uploads.d.ts +2 -0
  573. package/dist/vendor/uploads.js +3 -0
  574. package/dist/vendor/uploads.js.map +1 -0
  575. package/dist/vendor/version.d.ts +1 -0
  576. package/dist/vendor/version.js +2 -0
  577. package/dist/vendor/version.js.map +1 -0
  578. package/package.json +7 -14
  579. package/sdk.cjs +6 -6
  580. package/sdk.cjs.map +18 -18
  581. package/sdk.d.ts +10 -10
  582. package/sdk.mjs +21 -21
  583. package/sdk.mjs.map +18 -18
@@ -0,0 +1,82 @@
1
+ import type { ErrorType } from '../resources/shared';
2
+ /**
3
+ * Branded base error class for the Puku SDK. Every error the SDK throws
4
+ * is an instance of `PukuError`, so `err.toString()` and stack traces
5
+ * report `PukuError: …` consistently.
6
+ *
7
+ * `instanceof PukuError` is the canonical check. The class itself is
8
+ * re-exported from `@puku-ai/sdk` under both `PukuError` and the legacy
9
+ * `PukuError` name; both refer to the same constructor.
10
+ */
11
+ export declare class PukuError extends Error {
12
+ name: string;
13
+ constructor(message?: string);
14
+ }
15
+ /**
16
+ * Legacy base-error type alias for source compatibility with code that
17
+ * imports the SDK's base error type by its old name. Throw sites
18
+ * should always throw `PukuError` directly; the legacy alias exists only
19
+ * so consumers' `instanceof` checks keep working across the rename.
20
+ *
21
+ * @deprecated Import `PukuError` instead. The alias will be removed in
22
+ * the next major version.
23
+ */
24
+ export type LegacyBaseError = PukuError;
25
+ export declare class APIError<TStatus extends number | undefined = number | undefined, THeaders extends Headers | undefined = Headers | undefined, TError extends Object | undefined = Object | undefined> extends PukuError {
26
+ /** HTTP status for the response that caused the error */
27
+ readonly status: TStatus;
28
+ /** HTTP headers for the response that caused the error */
29
+ readonly headers: THeaders;
30
+ /** JSON body of the response that caused the error */
31
+ readonly error: TError;
32
+ readonly requestID: string | null | undefined;
33
+ readonly workspaceID: string | null | undefined;
34
+ /** The `error.type` from the API response body, e.g. `"rate_limit_error"` */
35
+ readonly type: ErrorType | null;
36
+ constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders, type?: ErrorType | null);
37
+ private static makeMessage;
38
+ static generate(status: number | undefined, errorResponse: Object | undefined, message: string | undefined, headers: Headers | undefined): APIError;
39
+ }
40
+ export declare class APIUserAbortError extends APIError<undefined, undefined, undefined> {
41
+ constructor({ message }?: {
42
+ message?: string;
43
+ });
44
+ }
45
+ export declare class APIConnectionError extends APIError<undefined, undefined, undefined> {
46
+ constructor({ message, cause }: {
47
+ message?: string | undefined;
48
+ cause?: Error | undefined;
49
+ });
50
+ }
51
+ export declare class APIConnectionTimeoutError extends APIConnectionError {
52
+ constructor({ message }?: {
53
+ message?: string;
54
+ });
55
+ }
56
+ /**
57
+ * An error that opts into the SDK's retry policy: throw it (e.g. from
58
+ * middleware) to have the attempt retried.
59
+ *
60
+ * Note that the request will only be retried when `maxRetries` has not been exhausted.
61
+ */
62
+ export declare class RetryableError extends PukuError {
63
+ constructor(message?: string, { cause }?: {
64
+ cause?: unknown;
65
+ });
66
+ }
67
+ export declare class BadRequestError extends APIError<400, Headers> {
68
+ }
69
+ export declare class AuthenticationError extends APIError<401, Headers> {
70
+ }
71
+ export declare class PermissionDeniedError extends APIError<403, Headers> {
72
+ }
73
+ export declare class NotFoundError extends APIError<404, Headers> {
74
+ }
75
+ export declare class ConflictError extends APIError<409, Headers> {
76
+ }
77
+ export declare class UnprocessableEntityError extends APIError<422, Headers> {
78
+ }
79
+ export declare class RateLimitError extends APIError<429, Headers> {
80
+ }
81
+ export declare class InternalServerError extends APIError<number, Headers> {
82
+ }
@@ -0,0 +1,140 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+ import { castToError } from '../internal/errors.js';
3
+ /**
4
+ * Branded base error class for the Puku SDK. Every error the SDK throws
5
+ * is an instance of `PukuError`, so `err.toString()` and stack traces
6
+ * report `PukuError: …` consistently.
7
+ *
8
+ * `instanceof PukuError` is the canonical check. The class itself is
9
+ * re-exported from `@puku-ai/sdk` under both `PukuError` and the legacy
10
+ * `PukuError` name; both refer to the same constructor.
11
+ */
12
+ export class PukuError extends Error {
13
+ name = 'PukuError';
14
+ constructor(message) {
15
+ super(message);
16
+ this.name = 'PukuError';
17
+ }
18
+ }
19
+ export class APIError extends PukuError {
20
+ /** HTTP status for the response that caused the error */
21
+ status;
22
+ /** HTTP headers for the response that caused the error */
23
+ headers;
24
+ /** JSON body of the response that caused the error */
25
+ error;
26
+ requestID;
27
+ workspaceID;
28
+ /** The `error.type` from the API response body, e.g. `"rate_limit_error"` */
29
+ type;
30
+ constructor(status, error, message, headers, type) {
31
+ super(`${APIError.makeMessage(status, error, message)}`);
32
+ this.status = status;
33
+ this.headers = headers;
34
+ this.requestID = headers?.get('request-id');
35
+ this.workspaceID = headers?.get('puku-workspace-id');
36
+ this.error = error;
37
+ this.type = type ?? null;
38
+ }
39
+ static makeMessage(status, error, message) {
40
+ const msg = error?.message ?
41
+ typeof error.message === 'string' ?
42
+ error.message
43
+ : JSON.stringify(error.message)
44
+ : error ? JSON.stringify(error)
45
+ : message;
46
+ if (status && msg) {
47
+ return `${status} ${msg}`;
48
+ }
49
+ if (status) {
50
+ return `${status} status code (no body)`;
51
+ }
52
+ if (msg) {
53
+ return msg;
54
+ }
55
+ return '(no status code or body)';
56
+ }
57
+ static generate(status, errorResponse, message, headers) {
58
+ if (!status || !headers) {
59
+ return new APIConnectionError({ message, cause: castToError(errorResponse) });
60
+ }
61
+ const error = errorResponse;
62
+ const type = error?.['error']?.['type'];
63
+ if (status === 400) {
64
+ return new BadRequestError(status, error, message, headers, type);
65
+ }
66
+ if (status === 401) {
67
+ return new AuthenticationError(status, error, message, headers, type);
68
+ }
69
+ if (status === 403) {
70
+ return new PermissionDeniedError(status, error, message, headers, type);
71
+ }
72
+ if (status === 404) {
73
+ return new NotFoundError(status, error, message, headers, type);
74
+ }
75
+ if (status === 409) {
76
+ return new ConflictError(status, error, message, headers, type);
77
+ }
78
+ if (status === 422) {
79
+ return new UnprocessableEntityError(status, error, message, headers, type);
80
+ }
81
+ if (status === 429) {
82
+ return new RateLimitError(status, error, message, headers, type);
83
+ }
84
+ if (status >= 500) {
85
+ return new InternalServerError(status, error, message, headers, type);
86
+ }
87
+ return new APIError(status, error, message, headers, type);
88
+ }
89
+ }
90
+ export class APIUserAbortError extends APIError {
91
+ constructor({ message } = {}) {
92
+ super(undefined, undefined, message || 'Request was aborted.', undefined);
93
+ }
94
+ }
95
+ export class APIConnectionError extends APIError {
96
+ constructor({ message, cause }) {
97
+ super(undefined, undefined, message || 'Connection error.', undefined);
98
+ // in some environments the 'cause' property is already declared
99
+ // @ts-ignore
100
+ if (cause)
101
+ this.cause = cause;
102
+ }
103
+ }
104
+ export class APIConnectionTimeoutError extends APIConnectionError {
105
+ constructor({ message } = {}) {
106
+ super({ message: message ?? 'Request timed out.' });
107
+ }
108
+ }
109
+ /**
110
+ * An error that opts into the SDK's retry policy: throw it (e.g. from
111
+ * middleware) to have the attempt retried.
112
+ *
113
+ * Note that the request will only be retried when `maxRetries` has not been exhausted.
114
+ */
115
+ export class RetryableError extends PukuError {
116
+ constructor(message, { cause } = {}) {
117
+ super(message ?? 'Retryable error.');
118
+ // in some environments the 'cause' property is already declared
119
+ // @ts-ignore
120
+ if (cause !== undefined)
121
+ this.cause = cause;
122
+ }
123
+ }
124
+ export class BadRequestError extends APIError {
125
+ }
126
+ export class AuthenticationError extends APIError {
127
+ }
128
+ export class PermissionDeniedError extends APIError {
129
+ }
130
+ export class NotFoundError extends APIError {
131
+ }
132
+ export class ConflictError extends APIError {
133
+ }
134
+ export class UnprocessableEntityError extends APIError {
135
+ }
136
+ export class RateLimitError extends APIError {
137
+ }
138
+ export class InternalServerError extends APIError {
139
+ }
140
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/vendor/core/error.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAEtF,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD;;;;;;;;GAQG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,IAAI,GAAW,WAAW,CAAC;IACpC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAaD,MAAM,OAAO,QAIX,SAAQ,SAAS;IACjB,yDAAyD;IAChD,MAAM,CAAU;IACzB,0DAA0D;IACjD,OAAO,CAAW;IAC3B,sDAAsD;IAC7C,KAAK,CAAS;IAEd,SAAS,CAA4B;IACrC,WAAW,CAA4B;IAEhD,6EAA6E;IACpE,IAAI,CAAmB;IAEhC,YACE,MAAe,EACf,KAAa,EACb,OAA2B,EAC3B,OAAiB,EACjB,IAAuB;QAEvB,KAAK,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,OAAO,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,OAAO,EAAE,G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AQ,QAAsB;CAAG;AAE7D,MAAM,OAAO,mBAAoB,SAAQ,QAAyB;CAAG"}
@@ -0,0 +1,153 @@
1
+ import type { BasePuku } from '../client';
2
+ import type { Fetch } from '../internal/builtin-types';
3
+ import type { FinalRequestOptions } from '../internal/request-options';
4
+ import { type Logger } from '../internal/utils/log';
5
+ import type { APIRequest } from './api';
6
+ /**
7
+ * Invokes the rest of the middleware chain, ending with the underlying `fetch`.
8
+ *
9
+ * This function can be invoked multiple times.
10
+ */
11
+ export type MiddlewareNext = (request: APIRequest) => Promise<Response>;
12
+ /**
13
+ * Helpers passed to each middleware alongside `next`, scoped to the request
14
+ * in flight (one context is shared by every middleware in the chain).
15
+ */
16
+ export interface MiddlewareContext {
17
+ /**
18
+ * The SDK request options the API call in flight was made with: `method`,
19
+ * `path`, the pre-encoded `body`, `stream`, etc.
20
+ *
21
+ * `undefined` when the chain isn't running for an SDK API request, i.e.
22
+ * for credential token-exchange requests.
23
+ */
24
+ readonly options?: FinalRequestOptions | undefined;
25
+ /**
26
+ * The client's logger, pre-filtered to the client's configured log level
27
+ * (the `logLevel` client option or the `PUKU_LOG` environment
28
+ * variable). Calls below the active level are no-ops, so it's always safe
29
+ * to call; with no logger configured it writes to the global `console`.
30
+ *
31
+ * Values are logged as-is — when logging request or response headers,
32
+ * redact credentials (`authorization`, `x-api-key`, `cookie`) the way the
33
+ * SDK's own logs do.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const mw: Middleware = async (request, next, ctx) => {
38
+ * ctx.logger.debug('->', request.method, request.url);
39
+ * return next(request);
40
+ * };
41
+ * ```
42
+ */
43
+ readonly logger: Logger;
44
+ /**
45
+ * Parse a response body the way the SDK would for the request in flight:
46
+ *
47
+ * - JSON responses are decoded, with the non-enumerable `_request_id`
48
+ * property attached like SDK return values, and anything else resolves
49
+ * to the body text.
50
+ * - For streaming requests ({@link options}`.stream`), resolves immediately
51
+ * with a {@link Stream} reading an independent copy of the response body —
52
+ * iterating it doesn't consume the client's events, and aborting or
53
+ * `break`ing out of it doesn't cancel the underlying request. Each call
54
+ * returns a fresh `Stream` (streams are single-consumer, so they aren't
55
+ * cached). Error (non-2xx) responses parse as JSON/text rather than as a
56
+ * stream, mirroring the SDK's own handling.
57
+ * - For binary requests, resolves with the `Response` itself, unconsumed.
58
+ *
59
+ * Reads through an internal `response.clone()`, so the response stays
60
+ * readable: the client (and any other middleware) can still consume the
61
+ * body afterwards. Non-stream results are cached per `Response` and shared
62
+ * across the middleware chain, so repeated calls cost a single read.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const mw: Middleware = async (request, next, ctx) => {
67
+ * const response = await next(request);
68
+ * const data = await ctx.parse<Message>(response);
69
+ * if (data.type === 'message') console.log(data.usage);
70
+ * return response;
71
+ * };
72
+ * ```
73
+ */
74
+ parse<T = unknown>(response: Response): Promise<T>;
75
+ }
76
+ /**
77
+ * A function that wraps each HTTP request made by the client.
78
+ *
79
+ * Middleware may observe or modify the request before calling `next`, observe
80
+ * or replace the response, short-circuit by returning a `Response` without
81
+ * calling `next`, or call `next` multiple times to implement custom retries.
82
+ *
83
+ * Middleware always observes the canonical PukuAI-shaped request — e.g.
84
+ * `POST .../v1/messages` with `model` and `stream` in the JSON body and
85
+ * `puku-beta` as a header — with the client's logical credentials
86
+ * (`x-api-key` / `Authorization`) applied. On clients for third-party
87
+ * backends (Bedrock, Vertex, Foundry), the backend adaptation — URL and body
88
+ * rewriting, request signing (e.g. AWS SigV4), and response normalization
89
+ * (e.g. AWS EventStream to SSE) — runs *inside* `next`, so middleware behaves
90
+ * identically on every backend: mutating the request is safe (signing covers
91
+ * the final body), and streaming responses are observed as SSE. Each `next()`
92
+ * call re-runs the adaptation, so custom retries re-sign from scratch. To
93
+ * observe the literal wire traffic instead, provide a custom `fetch`.
94
+ *
95
+ * Middleware must not consume the body of the `Response` it returns - the
96
+ * client still needs to read it. To inspect the body, use
97
+ * `await ctx.parse(response)` (cached, leaves the body readable) or read a
98
+ * clone (`await response.clone().text()`); to transform it, return a
99
+ * replacement, e.g. `new Response(body, response)`.
100
+ *
101
+ * Middleware runs per HTTP attempt, inside the SDK's retry loop; the attempt
102
+ * number is available via the `X-Stainless-Retry-Count` request header. An
103
+ * error thrown from middleware propagates to the caller as-is.
104
+ *
105
+ * Middleware errors are **not** retried apart from connection-level errors:
106
+ * timeout/abort errors, errors thrown by `fetch()`, and `APIConnectionError`s
107
+ * or `RetryableError`s — thrown directly or present anywhere in an error's
108
+ * `cause` chain. Retryable middleware errors still propagate to the caller
109
+ * as-is once retries are exhausted.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * const logger: Middleware = async (request, next, ctx) => {
114
+ * ctx.logger.debug('->', request.method, request.url);
115
+ * const response = await next(request);
116
+ * ctx.logger.debug('<-', response.status, request.url);
117
+ * return response;
118
+ * };
119
+ *
120
+ * const client = new PukuAI({ middleware: [logger] });
121
+ * ```
122
+ */
123
+ export type Middleware = (request: APIRequest, next: MiddlewareNext, ctx: MiddlewareContext) => Promise<Response>;
124
+ /** Whether `err` was thrown by the underlying `fetch` rather than by a middleware. */
125
+ export declare function isFetchOriginError(err: unknown): boolean;
126
+ /**
127
+ * Whether an error thrown by middleware should stay on the SDK's
128
+ * connection-error retry policy: fetch-origin, abort, `APIConnectionError`, or
129
+ * `RetryableError` — checked through the error's `cause` chain.
130
+ */
131
+ export declare function isRetryableError(err: unknown): boolean;
132
+ /**
133
+ * Wraps `fetchFn` so each call runs through `middleware`, keeping the same
134
+ * call signature as `fetch` itself.
135
+ *
136
+ * With no middleware, calls are passed straight through to `fetchFn`.
137
+ * Otherwise the arguments are normalized into an {@link APIRequest} (headers
138
+ * coerced to a `Headers` instance, URL stringified) before entering the
139
+ * chain. The chain is composed per call, so mutations of a `middleware`
140
+ * array are picked up by later requests.
141
+ *
142
+ * `options` — the SDK request options behind this call, when there are any —
143
+ * is surfaced to middleware as `ctx.options` and drives `ctx.parse`.
144
+ *
145
+ * `client` supplies `ctx.logger` (the client's level-filtered logger);
146
+ * without it, `ctx.logger` falls back to the client defaults: `console`,
147
+ * filtered to `PUKU_LOG` or `'warn'`.
148
+ */
149
+ export declare function wrapFetchWithMiddleware(fetchFn: Fetch, middleware: readonly Middleware[], options?: FinalRequestOptions | undefined, client?: BasePuku | undefined): Fetch;
150
+ /**
151
+ * Composes `middleware` around `fetchFn` and returns the entry point of the chain.
152
+ */
153
+ export declare function applyMiddleware(fetchFn: Fetch, middleware: readonly Middleware[], options?: FinalRequestOptions | undefined, client?: BasePuku | undefined): MiddlewareNext;
@@ -0,0 +1,168 @@
1
+ import { castToError, isAbortError } from '../internal/errors.js';
2
+ import { addResponseIDs } from '../internal/parse.js';
3
+ import { defaultLogger, loggerFor } from '../internal/utils/log.js';
4
+ import { PukuError, APIConnectionError, RetryableError } from './error.js';
5
+ import { Stream } from './streaming.js';
6
+ /**
7
+ * Errors thrown by the underlying `fetch`, as opposed to by a middleware.
8
+ *
9
+ * Tracked so the client can apply its connection-error retry policy to
10
+ * transport failures while letting errors thrown by middleware propagate to
11
+ * the caller untouched.
12
+ */
13
+ const fetchOriginErrors = new WeakSet();
14
+ /** Whether `err` was thrown by the underlying `fetch` rather than by a middleware. */
15
+ export function isFetchOriginError(err) {
16
+ return typeof err === 'object' && err !== null && fetchOriginErrors.has(err);
17
+ }
18
+ /**
19
+ * Whether an error thrown by middleware should stay on the SDK's
20
+ * connection-error retry policy: fetch-origin, abort, `APIConnectionError`, or
21
+ * `RetryableError` — checked through the error's `cause` chain.
22
+ */
23
+ export function isRetryableError(err) {
24
+ const seen = new Set(); // guard against `cause` cycles
25
+ while (typeof err === 'object' && err !== null && !seen.has(err)) {
26
+ seen.add(err);
27
+ if (isFetchOriginError(err) ||
28
+ isAbortError(err) ||
29
+ err instanceof APIConnectionError ||
30
+ err instanceof RetryableError) {
31
+ return true;
32
+ }
33
+ err = err.cause;
34
+ }
35
+ return false;
36
+ }
37
+ /**
38
+ * Wraps `fetchFn` so each call runs through `middleware`, keeping the same
39
+ * call signature as `fetch` itself.
40
+ *
41
+ * With no middleware, calls are passed straight through to `fetchFn`.
42
+ * Otherwise the arguments are normalized into an {@link APIRequest} (headers
43
+ * coerced to a `Headers` instance, URL stringified) before entering the
44
+ * chain. The chain is composed per call, so mutations of a `middleware`
45
+ * array are picked up by later requests.
46
+ *
47
+ * `options` — the SDK request options behind this call, when there are any —
48
+ * is surfaced to middleware as `ctx.options` and drives `ctx.parse`.
49
+ *
50
+ * `client` supplies `ctx.logger` (the client's level-filtered logger);
51
+ * without it, `ctx.logger` falls back to the client defaults: `console`,
52
+ * filtered to `PUKU_LOG` or `'warn'`.
53
+ */
54
+ export function wrapFetchWithMiddleware(fetchFn, middleware, options, client) {
55
+ return async (url, init = {}) => {
56
+ if (middleware.length === 0) {
57
+ // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
58
+ return fetchFn.call(undefined, url, init);
59
+ }
60
+ const headers = init.headers instanceof Headers ? init.headers : new Headers(init.headers);
61
+ const response = await applyMiddleware(fetchFn, middleware, options, client)({
62
+ ...init,
63
+ headers,
64
+ url: typeof url === 'string' ? url
65
+ : url instanceof URL ? url.href
66
+ : url.url,
67
+ });
68
+ // Catch a footgun before the client tries to read the body itself and
69
+ // fails with a confusing low-level stream error.
70
+ if (response.bodyUsed || response.body?.locked) {
71
+ throw new PukuError('middleware consumed the response body; use response.clone() to inspect it, ' +
72
+ 'or return new Response(body, response) to consume and replace it');
73
+ }
74
+ return response;
75
+ };
76
+ }
77
+ /**
78
+ * Creates the {@link MiddlewareContext} shared by every middleware in one chain.
79
+ */
80
+ function createMiddlewareContext(options, client) {
81
+ // Keyed on the Response so each `next()` call's response (e.g. with custom
82
+ // retries, or a middleware swapping in a replacement) parses independently,
83
+ // while several middleware parsing the same response share a single read.
84
+ const cache = new WeakMap();
85
+ return {
86
+ options,
87
+ // Resolved per chain, so changes to the client's `logLevel`/`logger`
88
+ // apply to subsequent requests.
89
+ logger: client ? loggerFor(client) : defaultLogger(),
90
+ parse(response) {
91
+ // Streams are single-consumer, so caching one would hand later callers
92
+ // an already-consumed stream; every call gets a fresh clone-backed one.
93
+ if (options?.stream && response.ok) {
94
+ return parseMiddlewareResponse(response, options, client);
95
+ }
96
+ let parsed = cache.get(response);
97
+ if (!parsed) {
98
+ parsed = parseMiddlewareResponse(response, options, client);
99
+ cache.set(response, parsed);
100
+ }
101
+ return parsed;
102
+ },
103
+ };
104
+ }
105
+ /**
106
+ * Mirrors the client's own response parsing (`defaultParseResponse` in
107
+ * `internal/parse.ts`), reading through a clone so the body stays available
108
+ * to the rest of the chain and the client itself.
109
+ */
110
+ async function parseMiddlewareResponse(response, options, client) {
111
+ if (response.bodyUsed || response.body?.locked) {
112
+ throw new PukuError('cannot ctx.parse() a response whose body was already consumed; ' +
113
+ 'call ctx.parse() instead of reading the body, or read via response.clone()');
114
+ }
115
+ // Error responses parse as JSON/text below — the SDK only stream-parses
116
+ // successful responses, and middleware typically wants the error body.
117
+ if (options?.stream && response.ok) {
118
+ // A fresh controller rather than the request's own: aborting (or
119
+ // `break`ing out of) the middleware's stream must not cancel the
120
+ // in-flight request the client is still reading.
121
+ return Stream.fromSSEResponse(response.clone(), new AbortController(), client);
122
+ }
123
+ // fetch refuses to read the body when the status code is 204.
124
+ if (response.status === 204) {
125
+ return null;
126
+ }
127
+ if (options?.__binaryResponse) {
128
+ return response;
129
+ }
130
+ const contentType = response.headers.get('content-type');
131
+ const mediaType = contentType?.split(';')[0]?.trim();
132
+ const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
133
+ if (isJSON) {
134
+ if (response.headers.get('content-length') === '0') {
135
+ // if there is no content we can't do anything
136
+ return undefined;
137
+ }
138
+ return addResponseIDs(await response.clone().json(), response);
139
+ }
140
+ return await response.clone().text();
141
+ }
142
+ /**
143
+ * Composes `middleware` around `fetchFn` and returns the entry point of the chain.
144
+ */
145
+ export function applyMiddleware(fetchFn, middleware, options, client) {
146
+ // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
147
+ let next = async ({ url, ...init }) => {
148
+ try {
149
+ return await fetchFn.call(undefined, url, init);
150
+ }
151
+ catch (err) {
152
+ // Brand the error as fetch-origin, normalizing with `castToError` first since a
153
+ // WeakSet can't hold primitives and the brand must be on the same object the
154
+ // client's own `castToError` will later pass through.
155
+ const error = castToError(err);
156
+ fetchOriginErrors.add(error);
157
+ throw error;
158
+ }
159
+ };
160
+ const ctx = createMiddlewareContext(options, client);
161
+ for (let i = middleware.length - 1; i >= 0; i--) {
162
+ const mw = middleware[i];
163
+ const nextInner = next;
164
+ next = async (request) => mw(request, nextInner, ctx);
165
+ }
166
+ return next;
167
+ }
168
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/vendor/core/middleware.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAe,MAAM,uBAAuB,CAAC;AAE9E,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAiIrC;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAAU,CAAC;AAEhD,sFAAsF;AACtF,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC7C,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC/E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAY;IAC3C,MAAM,IAAI,GAAG,IAAI,GAAG,EAAW,CAAC,CAAC,+BAA+B;IAChE,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,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