@anthropic-ai/claude-code 0.2.9

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 (424) hide show
  1. package/LICENSE.md +3 -0
  2. package/README.md +55 -0
  3. package/cli.mjs +1398 -0
  4. package/package.json +31 -0
  5. package/vendor/ripgrep/COPYING +3 -0
  6. package/vendor/ripgrep/arm64-darwin/rg +0 -0
  7. package/vendor/ripgrep/arm64-linux/rg +0 -0
  8. package/vendor/ripgrep/x64-darwin/rg +0 -0
  9. package/vendor/ripgrep/x64-linux/rg +0 -0
  10. package/vendor/ripgrep/x64-win32/rg.exe +0 -0
  11. package/vendor/sdk/CHANGELOG.md +1421 -0
  12. package/vendor/sdk/LICENSE +8 -0
  13. package/vendor/sdk/README.md +536 -0
  14. package/vendor/sdk/_shims/MultipartBody.d.ts +9 -0
  15. package/vendor/sdk/_shims/MultipartBody.d.ts.map +1 -0
  16. package/vendor/sdk/_shims/MultipartBody.js +16 -0
  17. package/vendor/sdk/_shims/MultipartBody.js.map +1 -0
  18. package/vendor/sdk/_shims/MultipartBody.mjs +12 -0
  19. package/vendor/sdk/_shims/MultipartBody.mjs.map +1 -0
  20. package/vendor/sdk/_shims/README.md +46 -0
  21. package/vendor/sdk/_shims/auto/runtime-bun.d.ts +5 -0
  22. package/vendor/sdk/_shims/auto/runtime-bun.d.ts.map +1 -0
  23. package/vendor/sdk/_shims/auto/runtime-bun.js +21 -0
  24. package/vendor/sdk/_shims/auto/runtime-bun.js.map +1 -0
  25. package/vendor/sdk/_shims/auto/runtime-bun.mjs +2 -0
  26. package/vendor/sdk/_shims/auto/runtime-bun.mjs.map +1 -0
  27. package/vendor/sdk/_shims/auto/runtime-node.d.ts +5 -0
  28. package/vendor/sdk/_shims/auto/runtime-node.d.ts.map +1 -0
  29. package/vendor/sdk/_shims/auto/runtime-node.js +21 -0
  30. package/vendor/sdk/_shims/auto/runtime-node.js.map +1 -0
  31. package/vendor/sdk/_shims/auto/runtime-node.mjs +2 -0
  32. package/vendor/sdk/_shims/auto/runtime-node.mjs.map +1 -0
  33. package/vendor/sdk/_shims/auto/runtime.d.ts +5 -0
  34. package/vendor/sdk/_shims/auto/runtime.d.ts.map +1 -0
  35. package/vendor/sdk/_shims/auto/runtime.js +21 -0
  36. package/vendor/sdk/_shims/auto/runtime.js.map +1 -0
  37. package/vendor/sdk/_shims/auto/runtime.mjs +2 -0
  38. package/vendor/sdk/_shims/auto/runtime.mjs.map +1 -0
  39. package/vendor/sdk/_shims/auto/types-node.d.ts +5 -0
  40. package/vendor/sdk/_shims/auto/types-node.d.ts.map +1 -0
  41. package/vendor/sdk/_shims/auto/types-node.js +21 -0
  42. package/vendor/sdk/_shims/auto/types-node.js.map +1 -0
  43. package/vendor/sdk/_shims/auto/types-node.mjs +2 -0
  44. package/vendor/sdk/_shims/auto/types-node.mjs.map +1 -0
  45. package/vendor/sdk/_shims/auto/types.d.ts +101 -0
  46. package/vendor/sdk/_shims/auto/types.js +3 -0
  47. package/vendor/sdk/_shims/auto/types.mjs +3 -0
  48. package/vendor/sdk/_shims/bun-runtime.d.ts +6 -0
  49. package/vendor/sdk/_shims/bun-runtime.d.ts.map +1 -0
  50. package/vendor/sdk/_shims/bun-runtime.js +14 -0
  51. package/vendor/sdk/_shims/bun-runtime.js.map +1 -0
  52. package/vendor/sdk/_shims/bun-runtime.mjs +10 -0
  53. package/vendor/sdk/_shims/bun-runtime.mjs.map +1 -0
  54. package/vendor/sdk/_shims/index.d.ts +81 -0
  55. package/vendor/sdk/_shims/index.js +13 -0
  56. package/vendor/sdk/_shims/index.mjs +7 -0
  57. package/vendor/sdk/_shims/manual-types.d.ts +12 -0
  58. package/vendor/sdk/_shims/manual-types.js +3 -0
  59. package/vendor/sdk/_shims/manual-types.mjs +3 -0
  60. package/vendor/sdk/_shims/node-runtime.d.ts +3 -0
  61. package/vendor/sdk/_shims/node-runtime.d.ts.map +1 -0
  62. package/vendor/sdk/_shims/node-runtime.js +89 -0
  63. package/vendor/sdk/_shims/node-runtime.js.map +1 -0
  64. package/vendor/sdk/_shims/node-runtime.mjs +56 -0
  65. package/vendor/sdk/_shims/node-runtime.mjs.map +1 -0
  66. package/vendor/sdk/_shims/node-types.d.ts +42 -0
  67. package/vendor/sdk/_shims/node-types.js +3 -0
  68. package/vendor/sdk/_shims/node-types.mjs +3 -0
  69. package/vendor/sdk/_shims/registry.d.ts +37 -0
  70. package/vendor/sdk/_shims/registry.d.ts.map +1 -0
  71. package/vendor/sdk/_shims/registry.js +41 -0
  72. package/vendor/sdk/_shims/registry.js.map +1 -0
  73. package/vendor/sdk/_shims/registry.mjs +37 -0
  74. package/vendor/sdk/_shims/registry.mjs.map +1 -0
  75. package/vendor/sdk/_shims/web-runtime.d.ts +5 -0
  76. package/vendor/sdk/_shims/web-runtime.d.ts.map +1 -0
  77. package/vendor/sdk/_shims/web-runtime.js +78 -0
  78. package/vendor/sdk/_shims/web-runtime.js.map +1 -0
  79. package/vendor/sdk/_shims/web-runtime.mjs +71 -0
  80. package/vendor/sdk/_shims/web-runtime.mjs.map +1 -0
  81. package/vendor/sdk/_shims/web-types.d.ts +83 -0
  82. package/vendor/sdk/_shims/web-types.js +3 -0
  83. package/vendor/sdk/_shims/web-types.mjs +3 -0
  84. package/vendor/sdk/_vendor/partial-json-parser/parser.d.ts +3 -0
  85. package/vendor/sdk/_vendor/partial-json-parser/parser.d.ts.map +1 -0
  86. package/vendor/sdk/_vendor/partial-json-parser/parser.js +226 -0
  87. package/vendor/sdk/_vendor/partial-json-parser/parser.js.map +1 -0
  88. package/vendor/sdk/_vendor/partial-json-parser/parser.mjs +223 -0
  89. package/vendor/sdk/_vendor/partial-json-parser/parser.mjs.map +1 -0
  90. package/vendor/sdk/core.d.ts +248 -0
  91. package/vendor/sdk/core.d.ts.map +1 -0
  92. package/vendor/sdk/core.js +935 -0
  93. package/vendor/sdk/core.js.map +1 -0
  94. package/vendor/sdk/core.mjs +903 -0
  95. package/vendor/sdk/core.mjs.map +1 -0
  96. package/vendor/sdk/error.d.ts +48 -0
  97. package/vendor/sdk/error.d.ts.map +1 -0
  98. package/vendor/sdk/error.js +114 -0
  99. package/vendor/sdk/error.js.map +1 -0
  100. package/vendor/sdk/error.mjs +98 -0
  101. package/vendor/sdk/error.mjs.map +1 -0
  102. package/vendor/sdk/index.d.mts +152 -0
  103. package/vendor/sdk/index.d.ts +152 -0
  104. package/vendor/sdk/index.d.ts.map +1 -0
  105. package/vendor/sdk/index.js +179 -0
  106. package/vendor/sdk/index.js.map +1 -0
  107. package/vendor/sdk/index.mjs +136 -0
  108. package/vendor/sdk/index.mjs.map +1 -0
  109. package/vendor/sdk/internal/decoders/jsonl.d.ts +12 -0
  110. package/vendor/sdk/internal/decoders/jsonl.d.ts.map +1 -0
  111. package/vendor/sdk/internal/decoders/jsonl.js +35 -0
  112. package/vendor/sdk/internal/decoders/jsonl.js.map +1 -0
  113. package/vendor/sdk/internal/decoders/jsonl.mjs +31 -0
  114. package/vendor/sdk/internal/decoders/jsonl.mjs.map +1 -0
  115. package/vendor/sdk/internal/decoders/line.d.ts +20 -0
  116. package/vendor/sdk/internal/decoders/line.d.ts.map +1 -0
  117. package/vendor/sdk/internal/decoders/line.js +123 -0
  118. package/vendor/sdk/internal/decoders/line.js.map +1 -0
  119. package/vendor/sdk/internal/decoders/line.mjs +119 -0
  120. package/vendor/sdk/internal/decoders/line.mjs.map +1 -0
  121. package/vendor/sdk/internal/stream-utils.d.ts +8 -0
  122. package/vendor/sdk/internal/stream-utils.d.ts.map +1 -0
  123. package/vendor/sdk/internal/stream-utils.js +39 -0
  124. package/vendor/sdk/internal/stream-utils.js.map +1 -0
  125. package/vendor/sdk/internal/stream-utils.mjs +35 -0
  126. package/vendor/sdk/internal/stream-utils.mjs.map +1 -0
  127. package/vendor/sdk/lib/BetaMessageStream.d.ts +114 -0
  128. package/vendor/sdk/lib/BetaMessageStream.d.ts.map +1 -0
  129. package/vendor/sdk/lib/BetaMessageStream.js +547 -0
  130. package/vendor/sdk/lib/BetaMessageStream.js.map +1 -0
  131. package/vendor/sdk/lib/BetaMessageStream.mjs +543 -0
  132. package/vendor/sdk/lib/BetaMessageStream.mjs.map +1 -0
  133. package/vendor/sdk/lib/MessageStream.d.ts +114 -0
  134. package/vendor/sdk/lib/MessageStream.d.ts.map +1 -0
  135. package/vendor/sdk/lib/MessageStream.js +547 -0
  136. package/vendor/sdk/lib/MessageStream.js.map +1 -0
  137. package/vendor/sdk/lib/MessageStream.mjs +543 -0
  138. package/vendor/sdk/lib/MessageStream.mjs.map +1 -0
  139. package/vendor/sdk/node_modules/@types/node/LICENSE +21 -0
  140. package/vendor/sdk/node_modules/@types/node/README.md +15 -0
  141. package/vendor/sdk/node_modules/@types/node/assert/strict.d.ts +8 -0
  142. package/vendor/sdk/node_modules/@types/node/assert.d.ts +985 -0
  143. package/vendor/sdk/node_modules/@types/node/async_hooks.d.ts +522 -0
  144. package/vendor/sdk/node_modules/@types/node/buffer.buffer.d.ts +385 -0
  145. package/vendor/sdk/node_modules/@types/node/buffer.d.ts +1903 -0
  146. package/vendor/sdk/node_modules/@types/node/child_process.d.ts +1549 -0
  147. package/vendor/sdk/node_modules/@types/node/cluster.d.ts +578 -0
  148. package/vendor/sdk/node_modules/@types/node/compatibility/disposable.d.ts +14 -0
  149. package/vendor/sdk/node_modules/@types/node/compatibility/index.d.ts +9 -0
  150. package/vendor/sdk/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
  151. package/vendor/sdk/node_modules/@types/node/compatibility/iterators.d.ts +20 -0
  152. package/vendor/sdk/node_modules/@types/node/console.d.ts +452 -0
  153. package/vendor/sdk/node_modules/@types/node/constants.d.ts +19 -0
  154. package/vendor/sdk/node_modules/@types/node/crypto.d.ts +4453 -0
  155. package/vendor/sdk/node_modules/@types/node/dgram.d.ts +596 -0
  156. package/vendor/sdk/node_modules/@types/node/diagnostics_channel.d.ts +546 -0
  157. package/vendor/sdk/node_modules/@types/node/dns/promises.d.ts +475 -0
  158. package/vendor/sdk/node_modules/@types/node/dns.d.ts +853 -0
  159. package/vendor/sdk/node_modules/@types/node/dom-events.d.ts +124 -0
  160. package/vendor/sdk/node_modules/@types/node/domain.d.ts +170 -0
  161. package/vendor/sdk/node_modules/@types/node/events.d.ts +819 -0
  162. package/vendor/sdk/node_modules/@types/node/fs/promises.d.ts +1205 -0
  163. package/vendor/sdk/node_modules/@types/node/fs.d.ts +4237 -0
  164. package/vendor/sdk/node_modules/@types/node/globals.d.ts +442 -0
  165. package/vendor/sdk/node_modules/@types/node/globals.typedarray.d.ts +21 -0
  166. package/vendor/sdk/node_modules/@types/node/http.d.ts +1839 -0
  167. package/vendor/sdk/node_modules/@types/node/http2.d.ts +2517 -0
  168. package/vendor/sdk/node_modules/@types/node/https.d.ts +544 -0
  169. package/vendor/sdk/node_modules/@types/node/index.d.ts +90 -0
  170. package/vendor/sdk/node_modules/@types/node/inspector.d.ts +2775 -0
  171. package/vendor/sdk/node_modules/@types/node/module.d.ts +291 -0
  172. package/vendor/sdk/node_modules/@types/node/net.d.ts +924 -0
  173. package/vendor/sdk/node_modules/@types/node/os.d.ts +473 -0
  174. package/vendor/sdk/node_modules/@types/node/package.json +225 -0
  175. package/vendor/sdk/node_modules/@types/node/path.d.ts +191 -0
  176. package/vendor/sdk/node_modules/@types/node/perf_hooks.d.ts +753 -0
  177. package/vendor/sdk/node_modules/@types/node/process.d.ts +1553 -0
  178. package/vendor/sdk/node_modules/@types/node/punycode.d.ts +117 -0
  179. package/vendor/sdk/node_modules/@types/node/querystring.d.ts +141 -0
  180. package/vendor/sdk/node_modules/@types/node/readline/promises.d.ts +154 -0
  181. package/vendor/sdk/node_modules/@types/node/readline.d.ts +715 -0
  182. package/vendor/sdk/node_modules/@types/node/repl.d.ts +430 -0
  183. package/vendor/sdk/node_modules/@types/node/stream/consumers.d.ts +12 -0
  184. package/vendor/sdk/node_modules/@types/node/stream/promises.d.ts +90 -0
  185. package/vendor/sdk/node_modules/@types/node/stream/web.d.ts +523 -0
  186. package/vendor/sdk/node_modules/@types/node/stream.d.ts +1731 -0
  187. package/vendor/sdk/node_modules/@types/node/string_decoder.d.ts +67 -0
  188. package/vendor/sdk/node_modules/@types/node/test.d.ts +1245 -0
  189. package/vendor/sdk/node_modules/@types/node/timers/promises.d.ts +93 -0
  190. package/vendor/sdk/node_modules/@types/node/timers.d.ts +126 -0
  191. package/vendor/sdk/node_modules/@types/node/tls.d.ts +1203 -0
  192. package/vendor/sdk/node_modules/@types/node/trace_events.d.ts +171 -0
  193. package/vendor/sdk/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +385 -0
  194. package/vendor/sdk/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +19 -0
  195. package/vendor/sdk/node_modules/@types/node/ts5.6/index.d.ts +90 -0
  196. package/vendor/sdk/node_modules/@types/node/tty.d.ts +206 -0
  197. package/vendor/sdk/node_modules/@types/node/url.d.ts +957 -0
  198. package/vendor/sdk/node_modules/@types/node/util.d.ts +2083 -0
  199. package/vendor/sdk/node_modules/@types/node/v8.d.ts +753 -0
  200. package/vendor/sdk/node_modules/@types/node/vm.d.ts +666 -0
  201. package/vendor/sdk/node_modules/@types/node/wasi.d.ts +160 -0
  202. package/vendor/sdk/node_modules/@types/node/worker_threads.d.ts +695 -0
  203. package/vendor/sdk/node_modules/@types/node/zlib.d.ts +517 -0
  204. package/vendor/sdk/node_modules/undici-types/README.md +6 -0
  205. package/vendor/sdk/node_modules/undici-types/agent.d.ts +31 -0
  206. package/vendor/sdk/node_modules/undici-types/api.d.ts +43 -0
  207. package/vendor/sdk/node_modules/undici-types/balanced-pool.d.ts +18 -0
  208. package/vendor/sdk/node_modules/undici-types/cache.d.ts +36 -0
  209. package/vendor/sdk/node_modules/undici-types/client.d.ts +97 -0
  210. package/vendor/sdk/node_modules/undici-types/connector.d.ts +34 -0
  211. package/vendor/sdk/node_modules/undici-types/content-type.d.ts +21 -0
  212. package/vendor/sdk/node_modules/undici-types/cookies.d.ts +28 -0
  213. package/vendor/sdk/node_modules/undici-types/diagnostics-channel.d.ts +67 -0
  214. package/vendor/sdk/node_modules/undici-types/dispatcher.d.ts +241 -0
  215. package/vendor/sdk/node_modules/undici-types/errors.d.ts +128 -0
  216. package/vendor/sdk/node_modules/undici-types/fetch.d.ts +209 -0
  217. package/vendor/sdk/node_modules/undici-types/file.d.ts +39 -0
  218. package/vendor/sdk/node_modules/undici-types/filereader.d.ts +54 -0
  219. package/vendor/sdk/node_modules/undici-types/formdata.d.ts +108 -0
  220. package/vendor/sdk/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  221. package/vendor/sdk/node_modules/undici-types/global-origin.d.ts +7 -0
  222. package/vendor/sdk/node_modules/undici-types/handlers.d.ts +9 -0
  223. package/vendor/sdk/node_modules/undici-types/header.d.ts +4 -0
  224. package/vendor/sdk/node_modules/undici-types/index.d.ts +63 -0
  225. package/vendor/sdk/node_modules/undici-types/interceptors.d.ts +5 -0
  226. package/vendor/sdk/node_modules/undici-types/mock-agent.d.ts +50 -0
  227. package/vendor/sdk/node_modules/undici-types/mock-client.d.ts +25 -0
  228. package/vendor/sdk/node_modules/undici-types/mock-errors.d.ts +12 -0
  229. package/vendor/sdk/node_modules/undici-types/mock-interceptor.d.ts +93 -0
  230. package/vendor/sdk/node_modules/undici-types/mock-pool.d.ts +25 -0
  231. package/vendor/sdk/node_modules/undici-types/package.json +55 -0
  232. package/vendor/sdk/node_modules/undici-types/patch.d.ts +71 -0
  233. package/vendor/sdk/node_modules/undici-types/pool-stats.d.ts +19 -0
  234. package/vendor/sdk/node_modules/undici-types/pool.d.ts +28 -0
  235. package/vendor/sdk/node_modules/undici-types/proxy-agent.d.ts +30 -0
  236. package/vendor/sdk/node_modules/undici-types/readable.d.ts +61 -0
  237. package/vendor/sdk/node_modules/undici-types/webidl.d.ts +220 -0
  238. package/vendor/sdk/node_modules/undici-types/websocket.d.ts +131 -0
  239. package/vendor/sdk/package.json +124 -0
  240. package/vendor/sdk/pagination.d.ts +27 -0
  241. package/vendor/sdk/pagination.d.ts.map +1 -0
  242. package/vendor/sdk/pagination.js +60 -0
  243. package/vendor/sdk/pagination.js.map +1 -0
  244. package/vendor/sdk/pagination.mjs +56 -0
  245. package/vendor/sdk/pagination.mjs.map +1 -0
  246. package/vendor/sdk/resource.d.ts +6 -0
  247. package/vendor/sdk/resource.d.ts.map +1 -0
  248. package/vendor/sdk/resource.js +11 -0
  249. package/vendor/sdk/resource.js.map +1 -0
  250. package/vendor/sdk/resource.mjs +7 -0
  251. package/vendor/sdk/resource.mjs.map +1 -0
  252. package/vendor/sdk/resources/beta/beta.d.ts +57 -0
  253. package/vendor/sdk/resources/beta/beta.d.ts.map +1 -0
  254. package/vendor/sdk/resources/beta/beta.js +44 -0
  255. package/vendor/sdk/resources/beta/beta.js.map +1 -0
  256. package/vendor/sdk/resources/beta/beta.mjs +17 -0
  257. package/vendor/sdk/resources/beta/beta.mjs.map +1 -0
  258. package/vendor/sdk/resources/beta/index.d.ts +4 -0
  259. package/vendor/sdk/resources/beta/index.d.ts.map +1 -0
  260. package/vendor/sdk/resources/beta/index.js +12 -0
  261. package/vendor/sdk/resources/beta/index.js.map +1 -0
  262. package/vendor/sdk/resources/beta/index.mjs +5 -0
  263. package/vendor/sdk/resources/beta/index.mjs.map +1 -0
  264. package/vendor/sdk/resources/beta/messages/batches.d.ts +289 -0
  265. package/vendor/sdk/resources/beta/messages/batches.d.ts.map +1 -0
  266. package/vendor/sdk/resources/beta/messages/batches.js +112 -0
  267. package/vendor/sdk/resources/beta/messages/batches.js.map +1 -0
  268. package/vendor/sdk/resources/beta/messages/batches.mjs +107 -0
  269. package/vendor/sdk/resources/beta/messages/batches.mjs.map +1 -0
  270. package/vendor/sdk/resources/beta/messages/index.d.ts +3 -0
  271. package/vendor/sdk/resources/beta/messages/index.d.ts.map +1 -0
  272. package/vendor/sdk/resources/beta/messages/index.js +10 -0
  273. package/vendor/sdk/resources/beta/messages/index.js.map +1 -0
  274. package/vendor/sdk/resources/beta/messages/index.mjs +4 -0
  275. package/vendor/sdk/resources/beta/messages/index.mjs.map +1 -0
  276. package/vendor/sdk/resources/beta/messages/messages.d.ts +1038 -0
  277. package/vendor/sdk/resources/beta/messages/messages.d.ts.map +1 -0
  278. package/vendor/sdk/resources/beta/messages/messages.js +93 -0
  279. package/vendor/sdk/resources/beta/messages/messages.js.map +1 -0
  280. package/vendor/sdk/resources/beta/messages/messages.mjs +66 -0
  281. package/vendor/sdk/resources/beta/messages/messages.mjs.map +1 -0
  282. package/vendor/sdk/resources/beta/models.d.ts +49 -0
  283. package/vendor/sdk/resources/beta/models.d.ts.map +1 -0
  284. package/vendor/sdk/resources/beta/models.js +30 -0
  285. package/vendor/sdk/resources/beta/models.js.map +1 -0
  286. package/vendor/sdk/resources/beta/models.mjs +25 -0
  287. package/vendor/sdk/resources/beta/models.mjs.map +1 -0
  288. package/vendor/sdk/resources/completions.d.ts +166 -0
  289. package/vendor/sdk/resources/completions.d.ts.map +1 -0
  290. package/vendor/sdk/resources/completions.js +17 -0
  291. package/vendor/sdk/resources/completions.js.map +1 -0
  292. package/vendor/sdk/resources/completions.mjs +13 -0
  293. package/vendor/sdk/resources/completions.mjs.map +1 -0
  294. package/vendor/sdk/resources/index.d.ts +6 -0
  295. package/vendor/sdk/resources/index.d.ts.map +1 -0
  296. package/vendor/sdk/resources/index.js +29 -0
  297. package/vendor/sdk/resources/index.js.map +1 -0
  298. package/vendor/sdk/resources/index.mjs +7 -0
  299. package/vendor/sdk/resources/index.mjs.map +1 -0
  300. package/vendor/sdk/resources/messages/batches.d.ts +253 -0
  301. package/vendor/sdk/resources/messages/batches.d.ts.map +1 -0
  302. package/vendor/sdk/resources/messages/batches.js +102 -0
  303. package/vendor/sdk/resources/messages/batches.js.map +1 -0
  304. package/vendor/sdk/resources/messages/batches.mjs +97 -0
  305. package/vendor/sdk/resources/messages/batches.mjs.map +1 -0
  306. package/vendor/sdk/resources/messages/index.d.ts +3 -0
  307. package/vendor/sdk/resources/messages/index.d.ts.map +1 -0
  308. package/vendor/sdk/resources/messages/index.js +10 -0
  309. package/vendor/sdk/resources/messages/index.js.map +1 -0
  310. package/vendor/sdk/resources/messages/index.mjs +4 -0
  311. package/vendor/sdk/resources/messages/index.mjs.map +1 -0
  312. package/vendor/sdk/resources/messages/messages.d.ts +1028 -0
  313. package/vendor/sdk/resources/messages/messages.d.ts.map +1 -0
  314. package/vendor/sdk/resources/messages/messages.js +82 -0
  315. package/vendor/sdk/resources/messages/messages.js.map +1 -0
  316. package/vendor/sdk/resources/messages/messages.mjs +54 -0
  317. package/vendor/sdk/resources/messages/messages.mjs.map +1 -0
  318. package/vendor/sdk/resources/models.d.ts +49 -0
  319. package/vendor/sdk/resources/models.d.ts.map +1 -0
  320. package/vendor/sdk/resources/models.js +30 -0
  321. package/vendor/sdk/resources/models.js.map +1 -0
  322. package/vendor/sdk/resources/models.mjs +25 -0
  323. package/vendor/sdk/resources/models.mjs.map +1 -0
  324. package/vendor/sdk/resources/shared.d.ts +42 -0
  325. package/vendor/sdk/resources/shared.d.ts.map +1 -0
  326. package/vendor/sdk/resources/shared.js +4 -0
  327. package/vendor/sdk/resources/shared.js.map +1 -0
  328. package/vendor/sdk/resources/shared.mjs +3 -0
  329. package/vendor/sdk/resources/shared.mjs.map +1 -0
  330. package/vendor/sdk/resources/top-level.d.ts +2 -0
  331. package/vendor/sdk/resources/top-level.d.ts.map +1 -0
  332. package/vendor/sdk/resources/top-level.js +4 -0
  333. package/vendor/sdk/resources/top-level.js.map +1 -0
  334. package/vendor/sdk/resources/top-level.mjs +3 -0
  335. package/vendor/sdk/resources/top-level.mjs.map +1 -0
  336. package/vendor/sdk/shims/node.d.ts +30 -0
  337. package/vendor/sdk/shims/node.d.ts.map +1 -0
  338. package/vendor/sdk/shims/node.js +31 -0
  339. package/vendor/sdk/shims/node.js.map +1 -0
  340. package/vendor/sdk/shims/node.mjs +5 -0
  341. package/vendor/sdk/shims/node.mjs.map +1 -0
  342. package/vendor/sdk/shims/web.d.ts +26 -0
  343. package/vendor/sdk/shims/web.d.ts.map +1 -0
  344. package/vendor/sdk/shims/web.js +31 -0
  345. package/vendor/sdk/shims/web.js.map +1 -0
  346. package/vendor/sdk/shims/web.mjs +5 -0
  347. package/vendor/sdk/shims/web.mjs.map +1 -0
  348. package/vendor/sdk/src/_shims/MultipartBody.ts +9 -0
  349. package/vendor/sdk/src/_shims/README.md +46 -0
  350. package/vendor/sdk/src/_shims/auto/runtime-bun.ts +4 -0
  351. package/vendor/sdk/src/_shims/auto/runtime-node.ts +4 -0
  352. package/vendor/sdk/src/_shims/auto/runtime.ts +4 -0
  353. package/vendor/sdk/src/_shims/auto/types-node.ts +4 -0
  354. package/vendor/sdk/src/_shims/auto/types.d.ts +101 -0
  355. package/vendor/sdk/src/_shims/auto/types.js +3 -0
  356. package/vendor/sdk/src/_shims/auto/types.mjs +3 -0
  357. package/vendor/sdk/src/_shims/bun-runtime.ts +14 -0
  358. package/vendor/sdk/src/_shims/index.d.ts +81 -0
  359. package/vendor/sdk/src/_shims/index.js +13 -0
  360. package/vendor/sdk/src/_shims/index.mjs +7 -0
  361. package/vendor/sdk/src/_shims/manual-types.d.ts +12 -0
  362. package/vendor/sdk/src/_shims/manual-types.js +3 -0
  363. package/vendor/sdk/src/_shims/manual-types.mjs +3 -0
  364. package/vendor/sdk/src/_shims/node-runtime.ts +81 -0
  365. package/vendor/sdk/src/_shims/node-types.d.ts +42 -0
  366. package/vendor/sdk/src/_shims/node-types.js +3 -0
  367. package/vendor/sdk/src/_shims/node-types.mjs +3 -0
  368. package/vendor/sdk/src/_shims/registry.ts +67 -0
  369. package/vendor/sdk/src/_shims/web-runtime.ts +103 -0
  370. package/vendor/sdk/src/_shims/web-types.d.ts +83 -0
  371. package/vendor/sdk/src/_shims/web-types.js +3 -0
  372. package/vendor/sdk/src/_shims/web-types.mjs +3 -0
  373. package/vendor/sdk/src/_vendor/partial-json-parser/README.md +3 -0
  374. package/vendor/sdk/src/_vendor/partial-json-parser/parser.ts +264 -0
  375. package/vendor/sdk/src/core.ts +1250 -0
  376. package/vendor/sdk/src/error.ts +133 -0
  377. package/vendor/sdk/src/index.ts +465 -0
  378. package/vendor/sdk/src/internal/decoders/jsonl.ts +41 -0
  379. package/vendor/sdk/src/internal/decoders/line.ts +145 -0
  380. package/vendor/sdk/src/internal/stream-utils.ts +32 -0
  381. package/vendor/sdk/src/lib/.keep +4 -0
  382. package/vendor/sdk/src/lib/BetaMessageStream.ts +661 -0
  383. package/vendor/sdk/src/lib/MessageStream.ts +662 -0
  384. package/vendor/sdk/src/pagination.ts +92 -0
  385. package/vendor/sdk/src/resource.ts +11 -0
  386. package/vendor/sdk/src/resources/beta/beta.ts +249 -0
  387. package/vendor/sdk/src/resources/beta/index.ts +83 -0
  388. package/vendor/sdk/src/resources/beta/messages/batches.ts +486 -0
  389. package/vendor/sdk/src/resources/beta/messages/index.ts +87 -0
  390. package/vendor/sdk/src/resources/beta/messages/messages.ts +1444 -0
  391. package/vendor/sdk/src/resources/beta/models.ts +78 -0
  392. package/vendor/sdk/src/resources/completions.ts +210 -0
  393. package/vendor/sdk/src/resources/index.ts +95 -0
  394. package/vendor/sdk/src/resources/messages/batches.ts +352 -0
  395. package/vendor/sdk/src/resources/messages/index.ts +85 -0
  396. package/vendor/sdk/src/resources/messages/messages.ts +1412 -0
  397. package/vendor/sdk/src/resources/models.ts +75 -0
  398. package/vendor/sdk/src/resources/shared.ts +72 -0
  399. package/vendor/sdk/src/resources/top-level.ts +3 -0
  400. package/vendor/sdk/src/shims/node.ts +50 -0
  401. package/vendor/sdk/src/shims/web.ts +50 -0
  402. package/vendor/sdk/src/streaming.ts +372 -0
  403. package/vendor/sdk/src/tsconfig.json +11 -0
  404. package/vendor/sdk/src/uploads.ts +255 -0
  405. package/vendor/sdk/src/version.ts +1 -0
  406. package/vendor/sdk/streaming.d.ts +36 -0
  407. package/vendor/sdk/streaming.d.ts.map +1 -0
  408. package/vendor/sdk/streaming.js +316 -0
  409. package/vendor/sdk/streaming.js.map +1 -0
  410. package/vendor/sdk/streaming.mjs +310 -0
  411. package/vendor/sdk/streaming.mjs.map +1 -0
  412. package/vendor/sdk/uploads.d.ts +75 -0
  413. package/vendor/sdk/uploads.d.ts.map +1 -0
  414. package/vendor/sdk/uploads.js +171 -0
  415. package/vendor/sdk/uploads.js.map +1 -0
  416. package/vendor/sdk/uploads.mjs +158 -0
  417. package/vendor/sdk/uploads.mjs.map +1 -0
  418. package/vendor/sdk/version.d.ts +2 -0
  419. package/vendor/sdk/version.d.ts.map +1 -0
  420. package/vendor/sdk/version.js +5 -0
  421. package/vendor/sdk/version.js.map +1 -0
  422. package/vendor/sdk/version.mjs +2 -0
  423. package/vendor/sdk/version.mjs.map +1 -0
  424. package/yoga.wasm +0 -0
@@ -0,0 +1,310 @@
1
+ import { ReadableStream } from "./_shims/index.mjs";
2
+ import { AnthropicError } from "./error.mjs";
3
+ import { LineDecoder } from "./internal/decoders/line.mjs";
4
+ import { ReadableStreamToAsyncIterable } from "./internal/stream-utils.mjs";
5
+ import { createResponseHeaders } from "./core.mjs";
6
+ import { APIError } from "./error.mjs";
7
+ export class Stream {
8
+ constructor(iterator, controller) {
9
+ this.iterator = iterator;
10
+ this.controller = controller;
11
+ }
12
+ static fromSSEResponse(response, controller) {
13
+ let consumed = false;
14
+ async function* iterator() {
15
+ if (consumed) {
16
+ throw new Error('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');
17
+ }
18
+ consumed = true;
19
+ let done = false;
20
+ try {
21
+ for await (const sse of _iterSSEMessages(response, controller)) {
22
+ if (sse.event === 'completion') {
23
+ try {
24
+ yield JSON.parse(sse.data);
25
+ }
26
+ catch (e) {
27
+ console.error(`Could not parse message into JSON:`, sse.data);
28
+ console.error(`From chunk:`, sse.raw);
29
+ throw e;
30
+ }
31
+ }
32
+ if (sse.event === 'message_start' ||
33
+ sse.event === 'message_delta' ||
34
+ sse.event === 'message_stop' ||
35
+ sse.event === 'content_block_start' ||
36
+ sse.event === 'content_block_delta' ||
37
+ sse.event === 'content_block_stop') {
38
+ try {
39
+ yield JSON.parse(sse.data);
40
+ }
41
+ catch (e) {
42
+ console.error(`Could not parse message into JSON:`, sse.data);
43
+ console.error(`From chunk:`, sse.raw);
44
+ throw e;
45
+ }
46
+ }
47
+ if (sse.event === 'ping') {
48
+ continue;
49
+ }
50
+ if (sse.event === 'error') {
51
+ throw APIError.generate(undefined, `SSE Error: ${sse.data}`, sse.data, createResponseHeaders(response.headers));
52
+ }
53
+ }
54
+ done = true;
55
+ }
56
+ catch (e) {
57
+ // If the user calls `stream.controller.abort()`, we should exit without throwing.
58
+ if (e instanceof Error && e.name === 'AbortError')
59
+ return;
60
+ throw e;
61
+ }
62
+ finally {
63
+ // If the user `break`s, abort the ongoing request.
64
+ if (!done)
65
+ controller.abort();
66
+ }
67
+ }
68
+ return new Stream(iterator, controller);
69
+ }
70
+ /**
71
+ * Generates a Stream from a newline-separated ReadableStream
72
+ * where each item is a JSON value.
73
+ */
74
+ static fromReadableStream(readableStream, controller) {
75
+ let consumed = false;
76
+ async function* iterLines() {
77
+ const lineDecoder = new LineDecoder();
78
+ const iter = ReadableStreamToAsyncIterable(readableStream);
79
+ for await (const chunk of iter) {
80
+ for (const line of lineDecoder.decode(chunk)) {
81
+ yield line;
82
+ }
83
+ }
84
+ for (const line of lineDecoder.flush()) {
85
+ yield line;
86
+ }
87
+ }
88
+ async function* iterator() {
89
+ if (consumed) {
90
+ throw new Error('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');
91
+ }
92
+ consumed = true;
93
+ let done = false;
94
+ try {
95
+ for await (const line of iterLines()) {
96
+ if (done)
97
+ continue;
98
+ if (line)
99
+ yield JSON.parse(line);
100
+ }
101
+ done = true;
102
+ }
103
+ catch (e) {
104
+ // If the user calls `stream.controller.abort()`, we should exit without throwing.
105
+ if (e instanceof Error && e.name === 'AbortError')
106
+ return;
107
+ throw e;
108
+ }
109
+ finally {
110
+ // If the user `break`s, abort the ongoing request.
111
+ if (!done)
112
+ controller.abort();
113
+ }
114
+ }
115
+ return new Stream(iterator, controller);
116
+ }
117
+ [Symbol.asyncIterator]() {
118
+ return this.iterator();
119
+ }
120
+ /**
121
+ * Splits the stream into two streams which can be
122
+ * independently read from at different speeds.
123
+ */
124
+ tee() {
125
+ const left = [];
126
+ const right = [];
127
+ const iterator = this.iterator();
128
+ const teeIterator = (queue) => {
129
+ return {
130
+ next: () => {
131
+ if (queue.length === 0) {
132
+ const result = iterator.next();
133
+ left.push(result);
134
+ right.push(result);
135
+ }
136
+ return queue.shift();
137
+ },
138
+ };
139
+ };
140
+ return [
141
+ new Stream(() => teeIterator(left), this.controller),
142
+ new Stream(() => teeIterator(right), this.controller),
143
+ ];
144
+ }
145
+ /**
146
+ * Converts this stream to a newline-separated ReadableStream of
147
+ * JSON stringified values in the stream
148
+ * which can be turned back into a Stream with `Stream.fromReadableStream()`.
149
+ */
150
+ toReadableStream() {
151
+ const self = this;
152
+ let iter;
153
+ const encoder = new TextEncoder();
154
+ return new ReadableStream({
155
+ async start() {
156
+ iter = self[Symbol.asyncIterator]();
157
+ },
158
+ async pull(ctrl) {
159
+ try {
160
+ const { value, done } = await iter.next();
161
+ if (done)
162
+ return ctrl.close();
163
+ const bytes = encoder.encode(JSON.stringify(value) + '\n');
164
+ ctrl.enqueue(bytes);
165
+ }
166
+ catch (err) {
167
+ ctrl.error(err);
168
+ }
169
+ },
170
+ async cancel() {
171
+ await iter.return?.();
172
+ },
173
+ });
174
+ }
175
+ }
176
+ export async function* _iterSSEMessages(response, controller) {
177
+ if (!response.body) {
178
+ controller.abort();
179
+ throw new AnthropicError(`Attempted to iterate over a response with no body`);
180
+ }
181
+ const sseDecoder = new SSEDecoder();
182
+ const lineDecoder = new LineDecoder();
183
+ const iter = ReadableStreamToAsyncIterable(response.body);
184
+ for await (const sseChunk of iterSSEChunks(iter)) {
185
+ for (const line of lineDecoder.decode(sseChunk)) {
186
+ const sse = sseDecoder.decode(line);
187
+ if (sse)
188
+ yield sse;
189
+ }
190
+ }
191
+ for (const line of lineDecoder.flush()) {
192
+ const sse = sseDecoder.decode(line);
193
+ if (sse)
194
+ yield sse;
195
+ }
196
+ }
197
+ /**
198
+ * Given an async iterable iterator, iterates over it and yields full
199
+ * SSE chunks, i.e. yields when a double new-line is encountered.
200
+ */
201
+ async function* iterSSEChunks(iterator) {
202
+ let data = new Uint8Array();
203
+ for await (const chunk of iterator) {
204
+ if (chunk == null) {
205
+ continue;
206
+ }
207
+ const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
208
+ : typeof chunk === 'string' ? new TextEncoder().encode(chunk)
209
+ : chunk;
210
+ let newData = new Uint8Array(data.length + binaryChunk.length);
211
+ newData.set(data);
212
+ newData.set(binaryChunk, data.length);
213
+ data = newData;
214
+ let patternIndex;
215
+ while ((patternIndex = findDoubleNewlineIndex(data)) !== -1) {
216
+ yield data.slice(0, patternIndex);
217
+ data = data.slice(patternIndex);
218
+ }
219
+ }
220
+ if (data.length > 0) {
221
+ yield data;
222
+ }
223
+ }
224
+ function findDoubleNewlineIndex(buffer) {
225
+ // This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n)
226
+ // and returns the index right after the first occurrence of any pattern,
227
+ // or -1 if none of the patterns are found.
228
+ const newline = 0x0a; // \n
229
+ const carriage = 0x0d; // \r
230
+ for (let i = 0; i < buffer.length - 2; i++) {
231
+ if (buffer[i] === newline && buffer[i + 1] === newline) {
232
+ // \n\n
233
+ return i + 2;
234
+ }
235
+ if (buffer[i] === carriage && buffer[i + 1] === carriage) {
236
+ // \r\r
237
+ return i + 2;
238
+ }
239
+ if (buffer[i] === carriage &&
240
+ buffer[i + 1] === newline &&
241
+ i + 3 < buffer.length &&
242
+ buffer[i + 2] === carriage &&
243
+ buffer[i + 3] === newline) {
244
+ // \r\n\r\n
245
+ return i + 4;
246
+ }
247
+ }
248
+ return -1;
249
+ }
250
+ class SSEDecoder {
251
+ constructor() {
252
+ this.event = null;
253
+ this.data = [];
254
+ this.chunks = [];
255
+ }
256
+ decode(line) {
257
+ if (line.endsWith('\r')) {
258
+ line = line.substring(0, line.length - 1);
259
+ }
260
+ if (!line) {
261
+ // empty line and we didn't previously encounter any messages
262
+ if (!this.event && !this.data.length)
263
+ return null;
264
+ const sse = {
265
+ event: this.event,
266
+ data: this.data.join('\n'),
267
+ raw: this.chunks,
268
+ };
269
+ this.event = null;
270
+ this.data = [];
271
+ this.chunks = [];
272
+ return sse;
273
+ }
274
+ this.chunks.push(line);
275
+ if (line.startsWith(':')) {
276
+ return null;
277
+ }
278
+ let [fieldname, _, value] = partition(line, ':');
279
+ if (value.startsWith(' ')) {
280
+ value = value.substring(1);
281
+ }
282
+ if (fieldname === 'event') {
283
+ this.event = value;
284
+ }
285
+ else if (fieldname === 'data') {
286
+ this.data.push(value);
287
+ }
288
+ return null;
289
+ }
290
+ }
291
+ /** This is an internal helper function that's just used for testing */
292
+ export function _decodeChunks(chunks, { flush } = { flush: false }) {
293
+ const decoder = new LineDecoder();
294
+ const lines = [];
295
+ for (const chunk of chunks) {
296
+ lines.push(...decoder.decode(chunk));
297
+ }
298
+ if (flush) {
299
+ lines.push(...decoder.flush());
300
+ }
301
+ return lines;
302
+ }
303
+ function partition(str, delimiter) {
304
+ const index = str.indexOf(delimiter);
305
+ if (index !== -1) {
306
+ return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
307
+ }
308
+ return [str, '', ''];
309
+ }
310
+ //# sourceMappingURL=streaming.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming.mjs","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":"OAAO,EAAE,cAAc,EAAiB;OACjC,EAAE,cAAc,EAAE;OAClB,EAAE,WAAW,EAAE;OACf,EAAE,6BAA6B,EAAE;OAEjC,EAAE,qBAAqB,EAAE;OACzB,EAAE,QAAQ,EAAE;AAUnB,MAAM,OAAO,MAAM;IAGjB,YACU,QAAmC,EAC3C,UAA2B;QADnB,aAAQ,GAAR,QAAQ,CAA2B;QAG3C,IAAI,CA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AAE,GAAG,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;KACtF;IAED,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AACvB,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { type RequestOptions } from "./core.js";
2
+ import { FormData, type Blob, type FilePropertyBag, type FsReadStream } from "./_shims/index.js";
3
+ import { MultipartBody } from "./_shims/MultipartBody.js";
4
+ export { fileFromPath } from "./_shims/index.js";
5
+ type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | Uint8Array | DataView;
6
+ export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | Uint8Array | DataView;
7
+ /**
8
+ * Typically, this is a native "File" class.
9
+ *
10
+ * We provide the {@link toFile} utility to convert a variety of objects
11
+ * into the File class.
12
+ *
13
+ * For convenience, you can also pass a fetch Response, or in Node,
14
+ * the result of fs.createReadStream().
15
+ */
16
+ export type Uploadable = FileLike | ResponseLike | FsReadStream;
17
+ /**
18
+ * Intended to match web.Blob, node.Blob, node-fetch.Blob, etc.
19
+ */
20
+ export interface BlobLike {
21
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
22
+ readonly size: number;
23
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
24
+ readonly type: string;
25
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
26
+ text(): Promise<string>;
27
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
28
+ slice(start?: number, end?: number): BlobLike;
29
+ }
30
+ /**
31
+ * Intended to match web.File, node.File, node-fetch.File, etc.
32
+ */
33
+ export interface FileLike extends BlobLike {
34
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
35
+ readonly lastModified: number;
36
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
37
+ readonly name: string;
38
+ }
39
+ /**
40
+ * Intended to match web.Response, node.Response, node-fetch.Response, etc.
41
+ */
42
+ export interface ResponseLike {
43
+ url: string;
44
+ blob(): Promise<BlobLike>;
45
+ }
46
+ export declare const isResponseLike: (value: any) => value is ResponseLike;
47
+ export declare const isFileLike: (value: any) => value is FileLike;
48
+ /**
49
+ * The BlobLike type omits arrayBuffer() because @types/node-fetch@^2.6.4 lacks it; but this check
50
+ * adds the arrayBuffer() method type because it is available and used at runtime
51
+ */
52
+ export declare const isBlobLike: (value: any) => value is BlobLike & {
53
+ arrayBuffer(): Promise<ArrayBuffer>;
54
+ };
55
+ export declare const isUploadable: (value: any) => value is Uploadable;
56
+ export type ToFileInput = Uploadable | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
57
+ /**
58
+ * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
59
+ * @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
60
+ * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
61
+ * @param {Object=} options additional properties
62
+ * @param {string=} options.type the MIME type of the content
63
+ * @param {number=} options.lastModified the last modified timestamp
64
+ * @returns a {@link File} with the given properties
65
+ */
66
+ export declare function toFile(value: ToFileInput | PromiseLike<ToFileInput>, name?: string | null | undefined, options?: FilePropertyBag | undefined): Promise<FileLike>;
67
+ export declare const isMultipartBody: (body: any) => body is MultipartBody;
68
+ /**
69
+ * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
70
+ * Otherwise returns the request as is.
71
+ */
72
+ export declare const maybeMultipartFormRequestOptions: <T = Record<string, unknown>>(opts: RequestOptions<T>) => Promise<RequestOptions<MultipartBody | T>>;
73
+ export declare const multipartFormRequestOptions: <T = Record<string, unknown>>(opts: RequestOptions<T>) => Promise<RequestOptions<MultipartBody | T>>;
74
+ export declare const createForm: <T = Record<string, unknown>>(body: T | undefined) => Promise<FormData>;
75
+ //# sourceMappingURL=uploads.d.ts.map
@@ -0,0 +1 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AAQ,CAAC,CAAC;CAC3B;AAED,eAAO,MAAM,cAAc,UAAW,GAAG,0BAIP,CAAC;AAEnC,eAAO,MAAM,UAAU,UAAW,GAAG,sBAKlB,CAAC;AAEpB;;;GAGG;AACH,eAAO,MAAM,UAAU,UAAW,GAAG;mBAAwC,QAAQ,WAAW,CAAC;CAOxD,CAAC;AAE1C,eAAO,MAAM,YAAY,UAAW,GAAG,wBAEtC,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;AAEnG;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAC1B,KAAK,EAAE,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,EAC7C,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,GACpC,OAAO,CAAC,QAAQ,CAAC,CAiCnB;AAmDD,eAAO,MAAM,eAAe,SAAU,GAAG,0BACsD,CAAC;AAEhG;;;GAGG;AACH,eAAO,MAAM,gCAAgC,sGAO5C,CAAC;AAEF,eAAO,MAAM,2BAA2B,sGAKvC,CAAC;AAEF,eAAO,MAAM,UAAU,wDAA6D,QAAQ,QAAQ,CAInG,CAAC"}
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = exports.isMultipartBody = exports.toFile = exports.isUploadable = exports.isBlobLike = exports.isFileLike = exports.isResponseLike = exports.fileFromPath = void 0;
4
+ const index_1 = require("./_shims/index.js");
5
+ var index_2 = require("./_shims/index.js");
6
+ Object.defineProperty(exports, "fileFromPath", { enumerable: true, get: function () { return index_2.fileFromPath; } });
7
+ const isResponseLike = (value) => value != null &&
8
+ typeof value === 'object' &&
9
+ typeof value.url === 'string' &&
10
+ typeof value.blob === 'function';
11
+ exports.isResponseLike = isResponseLike;
12
+ const isFileLike = (value) => value != null &&
13
+ typeof value === 'object' &&
14
+ typeof value.name === 'string' &&
15
+ typeof value.lastModified === 'number' &&
16
+ (0, exports.isBlobLike)(value);
17
+ exports.isFileLike = isFileLike;
18
+ /**
19
+ * The BlobLike type omits arrayBuffer() because @types/node-fetch@^2.6.4 lacks it; but this check
20
+ * adds the arrayBuffer() method type because it is available and used at runtime
21
+ */
22
+ const isBlobLike = (value) => value != null &&
23
+ typeof value === 'object' &&
24
+ typeof value.size === 'number' &&
25
+ typeof value.type === 'string' &&
26
+ typeof value.text === 'function' &&
27
+ typeof value.slice === 'function' &&
28
+ typeof value.arrayBuffer === 'function';
29
+ exports.isBlobLike = isBlobLike;
30
+ const isUploadable = (value) => {
31
+ return (0, exports.isFileLike)(value) || (0, exports.isResponseLike)(value) || (0, index_1.isFsReadStream)(value);
32
+ };
33
+ exports.isUploadable = isUploadable;
34
+ /**
35
+ * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
36
+ * @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
37
+ * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
38
+ * @param {Object=} options additional properties
39
+ * @param {string=} options.type the MIME type of the content
40
+ * @param {number=} options.lastModified the last modified timestamp
41
+ * @returns a {@link File} with the given properties
42
+ */
43
+ async function toFile(value, name, options) {
44
+ // If it's a promise, resolve it.
45
+ value = await value;
46
+ // If we've been given a `File` we don't need to do anything
47
+ if ((0, exports.isFileLike)(value)) {
48
+ return value;
49
+ }
50
+ if ((0, exports.isResponseLike)(value)) {
51
+ const blob = await value.blob();
52
+ name || (name = new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file');
53
+ // we need to convert the `Blob` into an array buffer because the `Blob` class
54
+ // that `node-fetch` defines is incompatible with the web standard which results
55
+ // in `new File` interpreting it as a string instead of binary data.
56
+ const data = (0, exports.isBlobLike)(blob) ? [(await blob.arrayBuffer())] : [blob];
57
+ return new index_1.File(data, name, options);
58
+ }
59
+ const bits = await getBytes(value);
60
+ name || (name = getName(value) ?? 'unknown_file');
61
+ if (!options?.type) {
62
+ const type = bits[0]?.type;
63
+ if (typeof type === 'string') {
64
+ options = { ...options, type };
65
+ }
66
+ }
67
+ return new index_1.File(bits, name, options);
68
+ }
69
+ exports.toFile = toFile;
70
+ async function getBytes(value) {
71
+ let parts = [];
72
+ if (typeof value === 'string' ||
73
+ ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
74
+ value instanceof ArrayBuffer) {
75
+ parts.push(value);
76
+ }
77
+ else if ((0, exports.isBlobLike)(value)) {
78
+ parts.push(await value.arrayBuffer());
79
+ }
80
+ else if (isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc.
81
+ ) {
82
+ for await (const chunk of value) {
83
+ parts.push(chunk); // TODO, consider validating?
84
+ }
85
+ }
86
+ else {
87
+ throw new Error(`Unexpected data type: ${typeof value}; constructor: ${value?.constructor
88
+ ?.name}; props: ${propsForError(value)}`);
89
+ }
90
+ return parts;
91
+ }
92
+ function propsForError(value) {
93
+ const props = Object.getOwnPropertyNames(value);
94
+ return `[${props.map((p) => `"${p}"`).join(', ')}]`;
95
+ }
96
+ function getName(value) {
97
+ return (getStringFromMaybeBuffer(value.name) ||
98
+ getStringFromMaybeBuffer(value.filename) ||
99
+ // For fs.ReadStream
100
+ getStringFromMaybeBuffer(value.path)?.split(/[\\/]/).pop());
101
+ }
102
+ const getStringFromMaybeBuffer = (x) => {
103
+ if (typeof x === 'string')
104
+ return x;
105
+ if (typeof Buffer !== 'undefined' && x instanceof Buffer)
106
+ return String(x);
107
+ return undefined;
108
+ };
109
+ const isAsyncIterableIterator = (value) => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
110
+ const isMultipartBody = (body) => body && typeof body === 'object' && body.body && body[Symbol.toStringTag] === 'MultipartBody';
111
+ exports.isMultipartBody = isMultipartBody;
112
+ /**
113
+ * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
114
+ * Otherwise returns the request as is.
115
+ */
116
+ const maybeMultipartFormRequestOptions = async (opts) => {
117
+ if (!hasUploadableValue(opts.body))
118
+ return opts;
119
+ const form = await (0, exports.createForm)(opts.body);
120
+ return (0, index_1.getMultipartRequestOptions)(form, opts);
121
+ };
122
+ exports.maybeMultipartFormRequestOptions = maybeMultipartFormRequestOptions;
123
+ const multipartFormRequestOptions = async (opts) => {
124
+ const form = await (0, exports.createForm)(opts.body);
125
+ return (0, index_1.getMultipartRequestOptions)(form, opts);
126
+ };
127
+ exports.multipartFormRequestOptions = multipartFormRequestOptions;
128
+ const createForm = async (body) => {
129
+ const form = new index_1.FormData();
130
+ await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
131
+ return form;
132
+ };
133
+ exports.createForm = createForm;
134
+ const hasUploadableValue = (value) => {
135
+ if ((0, exports.isUploadable)(value))
136
+ return true;
137
+ if (Array.isArray(value))
138
+ return value.some(hasUploadableValue);
139
+ if (value && typeof value === 'object') {
140
+ for (const k in value) {
141
+ if (hasUploadableValue(value[k]))
142
+ return true;
143
+ }
144
+ }
145
+ return false;
146
+ };
147
+ const addFormValue = async (form, key, value) => {
148
+ if (value === undefined)
149
+ return;
150
+ if (value == null) {
151
+ throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
152
+ }
153
+ // TODO: make nested formats configurable
154
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
155
+ form.append(key, String(value));
156
+ }
157
+ else if ((0, exports.isUploadable)(value)) {
158
+ const file = await toFile(value);
159
+ form.append(key, file);
160
+ }
161
+ else if (Array.isArray(value)) {
162
+ await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
163
+ }
164
+ else if (typeof value === 'object') {
165
+ await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
166
+ }
167
+ else {
168
+ throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
169
+ }
170
+ };
171
+ //# sourceMappingURL=uploads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploads.js","sourceRoot":"","sources":["src/uploads.ts"],"names":[],"mappings":";;;AACA,6CAQwB;AAExB,2CAA8C;AAArC,qGAAA,YAAY,OAAA;AAiDd,MAAM,cAAc,GAAG,CAAC,KAAU,EAAyB,EAAE,CAClE,KAAK,IAAI,IAAI;IACb,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ;IAC7B,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;AAJtB,QAAA,cAAc,kBAIQ;AAE5B,MAAM,UAAU,GAAG,CAAC,KAAU,EAAqB,EAAE,CAC1D,KAAK,IAAI,IAAI;IACb,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;IAC9B,OAAO,KAAK,CAAC,YAAY,KAAK,QAAQ;IACtC,IAAA,kBAAU,EAAC,KAAK,CAAC,CAAC;AALP,QAAA,UAAU,cAKH;AAEpB;;;GAGG;AACI,MAAM,UAAU,GAAG,CAAC,KAAU,EAA+D,EAAE,CACpG,KAAK,IAAI,IAAI;IACb,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;IAC9B,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;IAC9B,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU;IAChC,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU;IACjC,OAAO,KAAK,CAAC,WAAW,KAAK,UAAU,CAAC;AAP7B,QAAA,UAAU,cAOmB;AAEnC,MAAM,YAAY,GAAG,CAAC,KAAU,EAAuB,EAAE;IAC9D,OAAO,IAAA,kBAAU,EAAC,KAAK,CAAC,IAAI,IAAA,sBAAc,EAAC,KAAK,CAAC,IAAI,IA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