@anthropic-ai/sdk 0.33.0 → 0.34.0-alpha.0
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.
- package/CHANGELOG.md +13 -0
- package/README.md +15 -11
- package/_vendor/partial-json-parser/parser.d.mts +3 -0
- package/_vendor/partial-json-parser/parser.d.mts.map +1 -0
- package/api-promise.d.mts +48 -0
- package/api-promise.d.mts.map +1 -0
- package/api-promise.d.ts +48 -0
- package/api-promise.d.ts.map +1 -0
- package/api-promise.js +71 -0
- package/api-promise.js.map +1 -0
- package/api-promise.mjs +67 -0
- package/api-promise.mjs.map +1 -0
- package/client.d.mts +212 -0
- package/client.d.mts.map +1 -0
- package/client.d.ts +212 -0
- package/client.d.ts.map +1 -0
- package/client.js +505 -0
- package/client.js.map +1 -0
- package/client.mjs +477 -0
- package/client.mjs.map +1 -0
- package/error.d.mts +48 -0
- package/error.d.mts.map +1 -0
- package/error.d.ts +2 -2
- package/error.d.ts.map +1 -1
- package/error.js +3 -3
- package/error.js.map +1 -1
- package/error.mjs +2 -2
- package/error.mjs.map +1 -1
- package/index.d.mts +5 -150
- package/index.d.mts.map +1 -0
- package/index.d.ts +5 -150
- package/index.d.ts.map +1 -1
- package/index.js +18 -159
- package/index.js.map +1 -1
- package/index.mjs +5 -133
- package/index.mjs.map +1 -1
- package/internal/builtin-types.d.mts +65 -0
- package/internal/builtin-types.d.mts.map +1 -0
- package/internal/builtin-types.d.ts +65 -0
- package/internal/builtin-types.d.ts.map +1 -0
- package/internal/builtin-types.js +4 -0
- package/internal/builtin-types.js.map +1 -0
- package/internal/builtin-types.mjs +3 -0
- package/internal/builtin-types.mjs.map +1 -0
- package/internal/decoders/jsonl.d.mts +11 -0
- package/internal/decoders/jsonl.d.mts.map +1 -0
- package/internal/decoders/jsonl.d.ts +0 -1
- package/internal/decoders/jsonl.d.ts.map +1 -1
- package/internal/decoders/jsonl.js.map +1 -1
- package/internal/decoders/jsonl.mjs.map +1 -1
- package/internal/decoders/line.d.mts +21 -0
- package/internal/decoders/line.d.mts.map +1 -0
- package/internal/decoders/line.d.ts +1 -0
- package/internal/decoders/line.d.ts.map +1 -1
- package/internal/detect-platform.d.mts +15 -0
- package/internal/detect-platform.d.mts.map +1 -0
- package/internal/detect-platform.d.ts +15 -0
- package/internal/detect-platform.d.ts.map +1 -0
- package/internal/detect-platform.js +162 -0
- package/internal/detect-platform.js.map +1 -0
- package/internal/detect-platform.mjs +157 -0
- package/internal/detect-platform.mjs.map +1 -0
- package/internal/errors.d.mts +3 -0
- package/internal/errors.d.mts.map +1 -0
- package/internal/errors.d.ts +3 -0
- package/internal/errors.d.ts.map +1 -0
- package/internal/errors.js +22 -0
- package/internal/errors.js.map +1 -0
- package/internal/errors.mjs +17 -0
- package/internal/errors.mjs.map +1 -0
- package/internal/headers.d.mts +21 -0
- package/internal/headers.d.mts.map +1 -0
- package/internal/headers.d.ts +21 -0
- package/internal/headers.d.ts.map +1 -0
- package/internal/headers.js +77 -0
- package/internal/headers.js.map +1 -0
- package/internal/headers.mjs +72 -0
- package/internal/headers.mjs.map +1 -0
- package/internal/parse.d.mts +14 -0
- package/internal/parse.d.mts.map +1 -0
- package/internal/parse.d.ts +14 -0
- package/internal/parse.d.ts.map +1 -0
- package/internal/parse.js +48 -0
- package/internal/parse.js.map +1 -0
- package/internal/parse.mjs +43 -0
- package/internal/parse.mjs.map +1 -0
- package/internal/polyfill/crypto.node.d.ts +10 -0
- package/internal/polyfill/crypto.node.js +11 -0
- package/internal/polyfill/crypto.node.mjs +2 -0
- package/internal/polyfill/file.node.d.ts +9 -0
- package/internal/polyfill/file.node.js +17 -0
- package/internal/polyfill/file.node.mjs +9 -0
- package/internal/request-options.d.mts +37 -0
- package/internal/request-options.d.mts.map +1 -0
- package/internal/request-options.d.ts +37 -0
- package/internal/request-options.d.ts.map +1 -0
- package/internal/request-options.js +40 -0
- package/internal/request-options.js.map +1 -0
- package/internal/request-options.mjs +35 -0
- package/internal/request-options.mjs.map +1 -0
- package/internal/shim-types.d.mts +28 -0
- package/internal/shim-types.d.ts +28 -0
- package/internal/shims.d.mts +65 -0
- package/internal/shims.d.mts.map +1 -0
- package/internal/shims.d.ts +65 -0
- package/internal/shims.d.ts.map +1 -0
- package/internal/shims.js +66 -0
- package/internal/shims.js.map +1 -0
- package/internal/shims.mjs +58 -0
- package/internal/shims.mjs.map +1 -0
- package/internal/types.d.mts +6 -0
- package/internal/types.d.mts.map +1 -0
- package/internal/types.d.ts +6 -0
- package/internal/types.d.ts.map +1 -0
- package/internal/types.js +4 -0
- package/internal/types.js.map +1 -0
- package/internal/types.mjs +3 -0
- package/internal/types.mjs.map +1 -0
- package/internal/utils/base64.d.mts +3 -0
- package/internal/utils/base64.d.mts.map +1 -0
- package/internal/utils/base64.d.ts +3 -0
- package/internal/utils/base64.d.ts.map +1 -0
- package/internal/utils/base64.js +33 -0
- package/internal/utils/base64.js.map +1 -0
- package/internal/utils/base64.mjs +28 -0
- package/internal/utils/base64.mjs.map +1 -0
- package/internal/utils/env.d.mts +9 -0
- package/internal/utils/env.d.mts.map +1 -0
- package/internal/utils/env.d.ts +9 -0
- package/internal/utils/env.d.ts.map +1 -0
- package/internal/utils/env.js +22 -0
- package/internal/utils/env.js.map +1 -0
- package/internal/utils/env.mjs +18 -0
- package/internal/utils/env.mjs.map +1 -0
- package/internal/utils/log.d.mts +2 -0
- package/internal/utils/log.d.mts.map +1 -0
- package/internal/utils/log.d.ts +2 -0
- package/internal/utils/log.d.ts.map +1 -0
- package/internal/utils/log.js +12 -0
- package/internal/utils/log.js.map +1 -0
- package/internal/utils/log.mjs +8 -0
- package/internal/utils/log.mjs.map +1 -0
- package/internal/utils/sleep.d.mts +2 -0
- package/internal/utils/sleep.d.mts.map +1 -0
- package/internal/utils/sleep.d.ts +2 -0
- package/internal/utils/sleep.d.ts.map +1 -0
- package/internal/utils/sleep.js +7 -0
- package/internal/utils/sleep.js.map +1 -0
- package/internal/utils/sleep.mjs +3 -0
- package/internal/utils/sleep.mjs.map +1 -0
- package/internal/utils/uuid.d.mts +5 -0
- package/internal/utils/uuid.d.mts.map +1 -0
- package/internal/utils/uuid.d.ts +5 -0
- package/internal/utils/uuid.d.ts.map +1 -0
- package/internal/utils/uuid.js +15 -0
- package/internal/utils/uuid.js.map +1 -0
- package/internal/utils/uuid.mjs +11 -0
- package/internal/utils/uuid.mjs.map +1 -0
- package/internal/utils/values.d.mts +15 -0
- package/internal/utils/values.d.mts.map +1 -0
- package/internal/utils/values.d.ts +15 -0
- package/internal/utils/values.d.ts.map +1 -0
- package/internal/utils/values.js +100 -0
- package/internal/utils/values.js.map +1 -0
- package/internal/utils/values.mjs +84 -0
- package/internal/utils/values.mjs.map +1 -0
- package/internal/utils.d.mts +7 -0
- package/internal/utils.d.mts.map +1 -0
- package/internal/utils.d.ts +7 -0
- package/internal/utils.d.ts.map +1 -0
- package/{_shims/auto/runtime-bun.js → internal/utils.js} +8 -5
- package/internal/utils.js.map +1 -0
- package/internal/utils.mjs +8 -0
- package/internal/utils.mjs.map +1 -0
- package/lib/MessageStream.d.mts +95 -0
- package/lib/MessageStream.d.mts.map +1 -0
- package/lib/MessageStream.d.ts +7 -7
- package/lib/MessageStream.d.ts.map +1 -1
- package/lib/MessageStream.js +2 -2
- package/lib/MessageStream.js.map +1 -1
- package/lib/MessageStream.mjs +2 -2
- package/lib/MessageStream.mjs.map +1 -1
- package/package.json +120 -64
- package/pagination.d.mts +63 -0
- package/pagination.d.mts.map +1 -0
- package/pagination.d.ts +41 -4
- package/pagination.d.ts.map +1 -1
- package/pagination.js +95 -21
- package/pagination.js.map +1 -1
- package/pagination.mjs +91 -19
- package/pagination.mjs.map +1 -1
- package/resource.d.mts +6 -0
- package/resource.d.mts.map +1 -0
- package/resource.d.ts +3 -3
- package/resource.d.ts.map +1 -1
- package/resource.js.map +1 -1
- package/resource.mjs.map +1 -1
- package/resources/beta/beta.d.mts +57 -0
- package/resources/beta/beta.d.mts.map +1 -0
- package/resources/beta/beta.d.ts +1 -1
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js +0 -1
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs +1 -2
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/index.d.mts +4 -0
- package/resources/beta/index.d.mts.map +1 -0
- package/resources/beta/index.d.ts +1 -1
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js +3 -4
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs +1 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/messages/batches.d.mts +261 -0
- package/resources/beta/messages/batches.d.mts.map +1 -0
- package/resources/beta/messages/batches.d.ts +33 -13
- package/resources/beta/messages/batches.d.ts.map +1 -1
- package/resources/beta/messages/batches.js +54 -29
- package/resources/beta/messages/batches.js.map +1 -1
- package/resources/beta/messages/batches.mjs +53 -27
- package/resources/beta/messages/batches.mjs.map +1 -1
- package/resources/beta/messages/index.d.mts +3 -0
- package/resources/beta/messages/index.d.mts.map +1 -0
- package/resources/beta/messages/index.d.ts +1 -1
- package/resources/beta/messages/index.d.ts.map +1 -1
- package/resources/beta/messages/index.js +1 -2
- package/resources/beta/messages/index.js.map +1 -1
- package/resources/beta/messages/index.mjs +1 -1
- package/resources/beta/messages/index.mjs.map +1 -1
- package/resources/beta/messages/messages.d.mts +879 -0
- package/resources/beta/messages/messages.d.mts.map +1 -0
- package/resources/beta/messages/messages.d.ts +8 -8
- package/resources/beta/messages/messages.d.ts.map +1 -1
- package/resources/beta/messages/messages.js +0 -1
- package/resources/beta/messages/messages.js.map +1 -1
- package/resources/beta/messages/messages.mjs +1 -2
- package/resources/beta/messages/messages.mjs.map +1 -1
- package/resources/beta/models.d.mts +48 -0
- package/resources/beta/models.d.mts.map +1 -0
- package/resources/beta/models.d.ts +7 -8
- package/resources/beta/models.d.ts.map +1 -1
- package/resources/beta/models.js +10 -12
- package/resources/beta/models.js.map +1 -1
- package/resources/beta/models.mjs +9 -10
- package/resources/beta/models.mjs.map +1 -1
- package/resources/completions.d.mts +166 -0
- package/resources/completions.d.mts.map +1 -0
- package/resources/completions.d.ts +5 -5
- package/resources/completions.d.ts.map +1 -1
- package/resources/completions.js.map +1 -1
- package/resources/completions.mjs.map +1 -1
- package/resources/index.d.mts +6 -0
- package/resources/index.d.mts.map +1 -0
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +1 -2
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/messages/batches.d.mts +229 -0
- package/resources/messages/batches.d.mts.map +1 -0
- package/resources/messages/batches.d.ts +27 -10
- package/resources/messages/batches.d.ts.map +1 -1
- package/resources/messages/batches.js +20 -16
- package/resources/messages/batches.js.map +1 -1
- package/resources/messages/batches.mjs +19 -14
- package/resources/messages/batches.mjs.map +1 -1
- package/resources/messages/index.d.mts +3 -0
- package/resources/messages/index.d.mts.map +1 -0
- package/resources/messages/index.d.ts +1 -1
- package/resources/messages/index.d.ts.map +1 -1
- package/resources/messages/index.js +1 -2
- package/resources/messages/index.js.map +1 -1
- package/resources/messages/index.mjs +1 -1
- package/resources/messages/index.mjs.map +1 -1
- package/resources/messages/messages.d.mts +859 -0
- package/resources/messages/messages.d.mts.map +1 -0
- package/resources/messages/messages.d.ts +9 -9
- package/resources/messages/messages.d.ts.map +1 -1
- package/resources/messages/messages.js +0 -1
- package/resources/messages/messages.js.map +1 -1
- package/resources/messages/messages.mjs +1 -2
- package/resources/messages/messages.mjs.map +1 -1
- package/resources/models.d.mts +48 -0
- package/resources/models.d.mts.map +1 -0
- package/resources/models.d.ts +7 -8
- package/resources/models.d.ts.map +1 -1
- package/resources/models.js +10 -12
- package/resources/models.js.map +1 -1
- package/resources/models.mjs +9 -10
- package/resources/models.mjs.map +1 -1
- package/resources/shared.d.mts +42 -0
- package/resources/shared.d.mts.map +1 -0
- package/resources/top-level.d.mts +2 -0
- package/resources/top-level.d.mts.map +1 -0
- package/src/api-promise.ts +93 -0
- package/src/client.ts +863 -0
- package/src/error.ts +3 -3
- package/src/index.ts +12 -406
- package/src/internal/builtin-types.ts +79 -0
- package/src/internal/decoders/jsonl.ts +3 -4
- package/src/internal/decoders/line.ts +1 -1
- package/src/internal/detect-platform.ts +192 -0
- package/src/internal/errors.ts +18 -0
- package/src/internal/headers.ts +96 -0
- package/src/internal/parse.ts +70 -0
- package/src/internal/polyfill/crypto.node.d.ts +10 -0
- package/src/internal/polyfill/crypto.node.js +11 -0
- package/src/internal/polyfill/crypto.node.mjs +2 -0
- package/src/internal/polyfill/file.node.d.ts +9 -0
- package/src/internal/polyfill/file.node.js +17 -0
- package/src/internal/polyfill/file.node.mjs +9 -0
- package/src/internal/request-options.ts +71 -0
- package/src/internal/shim-types.d.ts +28 -0
- package/src/internal/shims.ts +124 -0
- package/src/internal/types.ts +6 -0
- package/src/internal/utils/base64.ts +40 -0
- package/src/internal/utils/env.ts +20 -0
- package/src/internal/utils/log.ts +9 -0
- package/src/internal/utils/sleep.ts +3 -0
- package/src/internal/utils/uuid.ts +13 -0
- package/src/internal/utils/values.ts +94 -0
- package/src/internal/utils.ts +8 -0
- package/src/lib/MessageStream.ts +9 -9
- package/src/pagination.ts +122 -18
- package/src/resource.ts +3 -3
- package/src/resources/beta/beta.ts +6 -7
- package/src/resources/beta/index.ts +3 -3
- package/src/resources/beta/messages/batches.ts +76 -74
- package/src/resources/beta/messages/index.ts +5 -3
- package/src/resources/beta/messages/messages.ts +20 -17
- package/src/resources/beta/models.ts +12 -22
- package/src/resources/completions.ts +10 -13
- package/src/resources/index.ts +5 -5
- package/src/resources/messages/batches.ts +46 -32
- package/src/resources/messages/index.ts +4 -3
- package/src/resources/messages/messages.ts +18 -20
- package/src/resources/models.ts +12 -19
- package/src/streaming.ts +7 -12
- package/src/tsconfig.json +1 -1
- package/src/uploads.ts +57 -54
- package/src/version.ts +1 -1
- package/streaming.d.mts +41 -0
- package/streaming.d.mts.map +1 -0
- package/streaming.d.ts +1 -1
- package/streaming.d.ts.map +1 -1
- package/streaming.js +3 -4
- package/streaming.js.map +1 -1
- package/streaming.mjs +3 -4
- package/streaming.mjs.map +1 -1
- package/uploads.d.mts +79 -0
- package/uploads.d.mts.map +1 -0
- package/uploads.d.ts +23 -19
- package/uploads.d.ts.map +1 -1
- package/uploads.js +33 -27
- package/uploads.js.map +1 -1
- package/uploads.mjs +29 -21
- package/uploads.mjs.map +1 -1
- package/version.d.mts +2 -0
- package/version.d.mts.map +1 -0
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
- package/_shims/MultipartBody.d.ts +0 -9
- package/_shims/MultipartBody.d.ts.map +0 -1
- package/_shims/MultipartBody.js +0 -16
- package/_shims/MultipartBody.js.map +0 -1
- package/_shims/MultipartBody.mjs +0 -12
- package/_shims/MultipartBody.mjs.map +0 -1
- package/_shims/README.md +0 -46
- package/_shims/auto/runtime-bun.d.ts +0 -5
- package/_shims/auto/runtime-bun.d.ts.map +0 -1
- package/_shims/auto/runtime-bun.js.map +0 -1
- package/_shims/auto/runtime-bun.mjs +0 -2
- package/_shims/auto/runtime-bun.mjs.map +0 -1
- package/_shims/auto/runtime-node.d.ts +0 -5
- package/_shims/auto/runtime-node.d.ts.map +0 -1
- package/_shims/auto/runtime-node.js +0 -21
- package/_shims/auto/runtime-node.js.map +0 -1
- package/_shims/auto/runtime-node.mjs +0 -2
- package/_shims/auto/runtime-node.mjs.map +0 -1
- package/_shims/auto/runtime.d.ts +0 -5
- package/_shims/auto/runtime.d.ts.map +0 -1
- package/_shims/auto/runtime.js +0 -21
- package/_shims/auto/runtime.js.map +0 -1
- package/_shims/auto/runtime.mjs +0 -2
- package/_shims/auto/runtime.mjs.map +0 -1
- package/_shims/auto/types-node.d.ts +0 -5
- package/_shims/auto/types-node.d.ts.map +0 -1
- package/_shims/auto/types-node.js +0 -21
- package/_shims/auto/types-node.js.map +0 -1
- package/_shims/auto/types-node.mjs +0 -2
- package/_shims/auto/types-node.mjs.map +0 -1
- package/_shims/auto/types.d.ts +0 -101
- package/_shims/auto/types.js +0 -3
- package/_shims/auto/types.mjs +0 -3
- package/_shims/bun-runtime.d.ts +0 -6
- package/_shims/bun-runtime.d.ts.map +0 -1
- package/_shims/bun-runtime.js +0 -14
- package/_shims/bun-runtime.js.map +0 -1
- package/_shims/bun-runtime.mjs +0 -10
- package/_shims/bun-runtime.mjs.map +0 -1
- package/_shims/index.d.ts +0 -81
- package/_shims/index.js +0 -13
- package/_shims/index.mjs +0 -7
- package/_shims/manual-types.d.ts +0 -12
- package/_shims/manual-types.js +0 -3
- package/_shims/manual-types.mjs +0 -3
- package/_shims/node-runtime.d.ts +0 -3
- package/_shims/node-runtime.d.ts.map +0 -1
- package/_shims/node-runtime.js +0 -89
- package/_shims/node-runtime.js.map +0 -1
- package/_shims/node-runtime.mjs +0 -56
- package/_shims/node-runtime.mjs.map +0 -1
- package/_shims/node-types.d.ts +0 -42
- package/_shims/node-types.js +0 -3
- package/_shims/node-types.mjs +0 -3
- package/_shims/registry.d.ts +0 -37
- package/_shims/registry.d.ts.map +0 -1
- package/_shims/registry.js +0 -41
- package/_shims/registry.js.map +0 -1
- package/_shims/registry.mjs +0 -37
- package/_shims/registry.mjs.map +0 -1
- package/_shims/web-runtime.d.ts +0 -5
- package/_shims/web-runtime.d.ts.map +0 -1
- package/_shims/web-runtime.js +0 -78
- package/_shims/web-runtime.js.map +0 -1
- package/_shims/web-runtime.mjs +0 -71
- package/_shims/web-runtime.mjs.map +0 -1
- package/_shims/web-types.d.ts +0 -83
- package/_shims/web-types.js +0 -3
- package/_shims/web-types.mjs +0 -3
- package/core.d.ts +0 -248
- package/core.d.ts.map +0 -1
- package/core.js +0 -920
- package/core.js.map +0 -1
- package/core.mjs +0 -888
- package/core.mjs.map +0 -1
- package/shims/node.d.ts +0 -30
- package/shims/node.d.ts.map +0 -1
- package/shims/node.js +0 -31
- package/shims/node.js.map +0 -1
- package/shims/node.mjs +0 -5
- package/shims/node.mjs.map +0 -1
- package/shims/web.d.ts +0 -26
- package/shims/web.d.ts.map +0 -1
- package/shims/web.js +0 -31
- package/shims/web.js.map +0 -1
- package/shims/web.mjs +0 -5
- package/shims/web.mjs.map +0 -1
- package/src/_shims/MultipartBody.ts +0 -9
- package/src/_shims/README.md +0 -46
- package/src/_shims/auto/runtime-bun.ts +0 -4
- package/src/_shims/auto/runtime-node.ts +0 -4
- package/src/_shims/auto/runtime.ts +0 -4
- package/src/_shims/auto/types-node.ts +0 -4
- package/src/_shims/auto/types.d.ts +0 -101
- package/src/_shims/auto/types.js +0 -3
- package/src/_shims/auto/types.mjs +0 -3
- package/src/_shims/bun-runtime.ts +0 -14
- package/src/_shims/index.d.ts +0 -81
- package/src/_shims/index.js +0 -13
- package/src/_shims/index.mjs +0 -7
- package/src/_shims/manual-types.d.ts +0 -12
- package/src/_shims/manual-types.js +0 -3
- package/src/_shims/manual-types.mjs +0 -3
- package/src/_shims/node-runtime.ts +0 -81
- package/src/_shims/node-types.d.ts +0 -42
- package/src/_shims/node-types.js +0 -3
- package/src/_shims/node-types.mjs +0 -3
- package/src/_shims/registry.ts +0 -67
- package/src/_shims/web-runtime.ts +0 -103
- package/src/_shims/web-types.d.ts +0 -83
- package/src/_shims/web-types.js +0 -3
- package/src/_shims/web-types.mjs +0 -3
- package/src/core.ts +0 -1232
- package/src/shims/node.ts +0 -50
- package/src/shims/web.ts +0 -50
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
export {
|
|
4
|
-
MessageBatchesPage,
|
|
5
4
|
Batches,
|
|
5
|
+
type DeletedMessageBatch,
|
|
6
6
|
type MessageBatch,
|
|
7
7
|
type MessageBatchCanceledResult,
|
|
8
8
|
type MessageBatchErroredResult,
|
|
@@ -13,7 +13,8 @@ export {
|
|
|
13
13
|
type MessageBatchSucceededResult,
|
|
14
14
|
type BatchCreateParams,
|
|
15
15
|
type BatchListParams,
|
|
16
|
-
|
|
16
|
+
type MessageBatchesPage,
|
|
17
|
+
} from './batches';
|
|
17
18
|
export {
|
|
18
19
|
Messages,
|
|
19
20
|
type Base64PDFSource,
|
|
@@ -60,4 +61,4 @@ export {
|
|
|
60
61
|
type MessageCreateParamsNonStreaming,
|
|
61
62
|
type MessageCreateParamsStreaming,
|
|
62
63
|
type MessageCountTokensParams,
|
|
63
|
-
} from
|
|
64
|
+
} from './messages';
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { APIResource } from
|
|
4
|
-
import
|
|
5
|
-
import * as
|
|
6
|
-
import * as MessagesAPI from "./messages.js";
|
|
7
|
-
import * as BatchesAPI from "./batches.js";
|
|
3
|
+
import { APIResource } from '../../resource';
|
|
4
|
+
import * as MessagesAPI from './messages';
|
|
5
|
+
import * as BatchesAPI from './batches';
|
|
8
6
|
import {
|
|
9
7
|
BatchCreateParams,
|
|
10
8
|
BatchListParams,
|
|
11
9
|
Batches,
|
|
10
|
+
DeletedMessageBatch,
|
|
12
11
|
MessageBatch,
|
|
13
12
|
MessageBatchCanceledResult,
|
|
14
13
|
MessageBatchErroredResult,
|
|
@@ -18,11 +17,13 @@ import {
|
|
|
18
17
|
MessageBatchResult,
|
|
19
18
|
MessageBatchSucceededResult,
|
|
20
19
|
MessageBatchesPage,
|
|
21
|
-
} from
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
20
|
+
} from './batches';
|
|
21
|
+
import { APIPromise } from '../../api-promise';
|
|
22
|
+
import { Stream } from '../../streaming';
|
|
23
|
+
import { RequestOptions } from '../../internal/request-options';
|
|
24
|
+
import { MessageStream } from '../../lib/MessageStream';
|
|
24
25
|
|
|
25
|
-
export { MessageStream } from
|
|
26
|
+
export { MessageStream } from '../../lib/MessageStream';
|
|
26
27
|
|
|
27
28
|
export class Messages extends APIResource {
|
|
28
29
|
batches: BatchesAPI.Batches = new BatchesAPI.Batches(this._client);
|
|
@@ -34,18 +35,18 @@ export class Messages extends APIResource {
|
|
|
34
35
|
* The Messages API can be used for either single queries or stateless multi-turn
|
|
35
36
|
* conversations.
|
|
36
37
|
*/
|
|
37
|
-
create(body: MessageCreateParamsNonStreaming, options?:
|
|
38
|
+
create(body: MessageCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Message>;
|
|
38
39
|
create(
|
|
39
40
|
body: MessageCreateParamsStreaming,
|
|
40
|
-
options?:
|
|
41
|
+
options?: RequestOptions,
|
|
41
42
|
): APIPromise<Stream<RawMessageStreamEvent>>;
|
|
42
43
|
create(
|
|
43
44
|
body: MessageCreateParamsBase,
|
|
44
|
-
options?:
|
|
45
|
+
options?: RequestOptions,
|
|
45
46
|
): APIPromise<Stream<RawMessageStreamEvent> | Message>;
|
|
46
47
|
create(
|
|
47
48
|
body: MessageCreateParams,
|
|
48
|
-
options?:
|
|
49
|
+
options?: RequestOptions,
|
|
49
50
|
): APIPromise<Message> | APIPromise<Stream<RawMessageStreamEvent>> {
|
|
50
51
|
if (body.model in DEPRECATED_MODELS) {
|
|
51
52
|
console.warn(
|
|
@@ -65,7 +66,7 @@ export class Messages extends APIResource {
|
|
|
65
66
|
/**
|
|
66
67
|
* Create a Message stream
|
|
67
68
|
*/
|
|
68
|
-
stream(body: MessageStreamParams, options?:
|
|
69
|
+
stream(body: MessageStreamParams, options?: RequestOptions): MessageStream {
|
|
69
70
|
return MessageStream.createMessage(this, body, options);
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -75,10 +76,7 @@ export class Messages extends APIResource {
|
|
|
75
76
|
* The Token Count API can be used to count the number of tokens in a Message,
|
|
76
77
|
* including tools, images, and documents, without creating it.
|
|
77
78
|
*/
|
|
78
|
-
countTokens(
|
|
79
|
-
body: MessageCountTokensParams,
|
|
80
|
-
options?: Core.RequestOptions,
|
|
81
|
-
): Core.APIPromise<MessageTokensCount> {
|
|
79
|
+
countTokens(body: MessageCountTokensParams, options?: RequestOptions): APIPromise<MessageTokensCount> {
|
|
82
80
|
return this._client.post('/v1/messages/count_tokens', { body, ...options });
|
|
83
81
|
}
|
|
84
82
|
}
|
|
@@ -1061,7 +1059,6 @@ export interface MessageCountTokensParams {
|
|
|
1061
1059
|
}
|
|
1062
1060
|
|
|
1063
1061
|
Messages.Batches = Batches;
|
|
1064
|
-
Messages.MessageBatchesPage = MessageBatchesPage;
|
|
1065
1062
|
|
|
1066
1063
|
export declare namespace Messages {
|
|
1067
1064
|
export {
|
|
@@ -1114,6 +1111,7 @@ export declare namespace Messages {
|
|
|
1114
1111
|
|
|
1115
1112
|
export {
|
|
1116
1113
|
Batches as Batches,
|
|
1114
|
+
type DeletedMessageBatch as DeletedMessageBatch,
|
|
1117
1115
|
type MessageBatch as MessageBatch,
|
|
1118
1116
|
type MessageBatchCanceledResult as MessageBatchCanceledResult,
|
|
1119
1117
|
type MessageBatchErroredResult as MessageBatchErroredResult,
|
|
@@ -1122,7 +1120,7 @@ export declare namespace Messages {
|
|
|
1122
1120
|
type MessageBatchRequestCounts as MessageBatchRequestCounts,
|
|
1123
1121
|
type MessageBatchResult as MessageBatchResult,
|
|
1124
1122
|
type MessageBatchSucceededResult as MessageBatchSucceededResult,
|
|
1125
|
-
MessageBatchesPage as MessageBatchesPage,
|
|
1123
|
+
type MessageBatchesPage as MessageBatchesPage,
|
|
1126
1124
|
type BatchCreateParams as BatchCreateParams,
|
|
1127
1125
|
type BatchListParams as BatchListParams,
|
|
1128
1126
|
};
|
package/src/resources/models.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { APIResource } from
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
3
|
+
import { APIResource } from '../resource';
|
|
4
|
+
import { APIPromise } from '../api-promise';
|
|
5
|
+
import { Page, type PageParams, PagePromise } from '../pagination';
|
|
6
|
+
import { RequestOptions } from '../internal/request-options';
|
|
7
7
|
|
|
8
8
|
export class Models extends APIResource {
|
|
9
9
|
/**
|
|
@@ -12,8 +12,8 @@ export class Models extends APIResource {
|
|
|
12
12
|
* The Models API response can be used to determine information about a specific
|
|
13
13
|
* model or resolve a model alias to a model ID.
|
|
14
14
|
*/
|
|
15
|
-
retrieve(
|
|
16
|
-
return this._client.get(`/v1/models/${
|
|
15
|
+
retrieve(modelID: string, options?: RequestOptions): APIPromise<ModelInfo> {
|
|
16
|
+
return this._client.get(`/v1/models/${modelID}`, options);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -22,20 +22,15 @@ export class Models extends APIResource {
|
|
|
22
22
|
* The Models API response can be used to determine which models are available for
|
|
23
23
|
* use in the API. More recently released models are listed first.
|
|
24
24
|
*/
|
|
25
|
-
list(query?: ModelListParams, options?: Core.RequestOptions): Core.PagePromise<ModelInfosPage, ModelInfo>;
|
|
26
|
-
list(options?: Core.RequestOptions): Core.PagePromise<ModelInfosPage, ModelInfo>;
|
|
27
25
|
list(
|
|
28
|
-
query: ModelListParams |
|
|
29
|
-
options?:
|
|
30
|
-
):
|
|
31
|
-
|
|
32
|
-
return this.list({}, query);
|
|
33
|
-
}
|
|
34
|
-
return this._client.getAPIList('/v1/models', ModelInfosPage, { query, ...options });
|
|
26
|
+
query: ModelListParams | null | undefined = {},
|
|
27
|
+
options?: RequestOptions,
|
|
28
|
+
): PagePromise<ModelInfosPage, ModelInfo> {
|
|
29
|
+
return this._client.getAPIList('/v1/models', Page<ModelInfo>, { query, ...options });
|
|
35
30
|
}
|
|
36
31
|
}
|
|
37
32
|
|
|
38
|
-
export
|
|
33
|
+
export type ModelInfosPage = Page<ModelInfo>;
|
|
39
34
|
|
|
40
35
|
export interface ModelInfo {
|
|
41
36
|
/**
|
|
@@ -64,12 +59,10 @@ export interface ModelInfo {
|
|
|
64
59
|
|
|
65
60
|
export interface ModelListParams extends PageParams {}
|
|
66
61
|
|
|
67
|
-
Models.ModelInfosPage = ModelInfosPage;
|
|
68
|
-
|
|
69
62
|
export declare namespace Models {
|
|
70
63
|
export {
|
|
71
64
|
type ModelInfo as ModelInfo,
|
|
72
|
-
ModelInfosPage as ModelInfosPage,
|
|
65
|
+
type ModelInfosPage as ModelInfosPage,
|
|
73
66
|
type ModelListParams as ModelListParams,
|
|
74
67
|
};
|
|
75
68
|
}
|
package/src/streaming.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { AnthropicError } from './error';
|
|
2
|
+
import { type ReadableStream } from './internal/shim-types';
|
|
3
|
+
import { makeReadableStream } from './internal/shims';
|
|
4
|
+
import { LineDecoder } from './internal/decoders/line';
|
|
4
5
|
|
|
5
|
-
import {
|
|
6
|
-
import { APIError } from "./error.js";
|
|
6
|
+
import { APIError } from './error';
|
|
7
7
|
|
|
8
8
|
type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined;
|
|
9
9
|
|
|
@@ -66,12 +66,7 @@ export class Stream<Item> implements AsyncIterable<Item> {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
if (sse.event === 'error') {
|
|
69
|
-
throw APIError.generate(
|
|
70
|
-
undefined,
|
|
71
|
-
`SSE Error: ${sse.data}`,
|
|
72
|
-
sse.data,
|
|
73
|
-
createResponseHeaders(response.headers),
|
|
74
|
-
);
|
|
69
|
+
throw APIError.generate(undefined, `SSE Error: ${sse.data}`, sse.data, response.headers);
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
72
|
done = true;
|
|
@@ -177,7 +172,7 @@ export class Stream<Item> implements AsyncIterable<Item> {
|
|
|
177
172
|
let iter: AsyncIterator<Item>;
|
|
178
173
|
const encoder = new TextEncoder();
|
|
179
174
|
|
|
180
|
-
return
|
|
175
|
+
return makeReadableStream({
|
|
181
176
|
async start() {
|
|
182
177
|
iter = self[Symbol.asyncIterator]();
|
|
183
178
|
},
|
package/src/tsconfig.json
CHANGED
package/src/uploads.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import { type RequestOptions } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type Blob,
|
|
6
|
-
type FilePropertyBag,
|
|
7
|
-
getMultipartRequestOptions,
|
|
8
|
-
type FsReadStream,
|
|
9
|
-
isFsReadStream,
|
|
10
|
-
} from "./_shims/index.js";
|
|
11
|
-
import { MultipartBody } from "./_shims/MultipartBody.js";
|
|
12
|
-
export { fileFromPath } from "./_shims/index.js";
|
|
1
|
+
import { type RequestOptions } from './internal/request-options';
|
|
2
|
+
import { type FilePropertyBag } from './internal/builtin-types';
|
|
3
|
+
import { isFsReadStreamLike, type FsReadStreamLike } from './internal/shims';
|
|
4
|
+
import './internal/polyfill/file.node.js';
|
|
13
5
|
|
|
14
6
|
type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | Uint8Array | DataView;
|
|
15
7
|
export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | Uint8Array | DataView;
|
|
@@ -23,10 +15,10 @@ export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | Uint8Arra
|
|
|
23
15
|
* For convenience, you can also pass a fetch Response, or in Node,
|
|
24
16
|
* the result of fs.createReadStream().
|
|
25
17
|
*/
|
|
26
|
-
export type Uploadable = FileLike | ResponseLike |
|
|
18
|
+
export type Uploadable = FileLike | ResponseLike | FsReadStreamLike;
|
|
27
19
|
|
|
28
20
|
/**
|
|
29
|
-
* Intended to match web.Blob, node.Blob,
|
|
21
|
+
* Intended to match web.Blob, node.Blob, undici.Blob, etc.
|
|
30
22
|
*/
|
|
31
23
|
export interface BlobLike {
|
|
32
24
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
|
|
@@ -37,11 +29,22 @@ export interface BlobLike {
|
|
|
37
29
|
text(): Promise<string>;
|
|
38
30
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
|
|
39
31
|
slice(start?: number, end?: number): BlobLike;
|
|
40
|
-
// unfortunately @types/node-fetch@^2.6.4 doesn't type the arrayBuffer method
|
|
41
32
|
}
|
|
42
33
|
|
|
43
34
|
/**
|
|
44
|
-
*
|
|
35
|
+
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
|
36
|
+
*/
|
|
37
|
+
export const isBlobLike = (value: any): value is BlobLike & { arrayBuffer(): Promise<ArrayBuffer> } =>
|
|
38
|
+
value != null &&
|
|
39
|
+
typeof value === 'object' &&
|
|
40
|
+
typeof value.size === 'number' &&
|
|
41
|
+
typeof value.type === 'string' &&
|
|
42
|
+
typeof value.text === 'function' &&
|
|
43
|
+
typeof value.slice === 'function' &&
|
|
44
|
+
typeof value.arrayBuffer === 'function';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Intended to match web.File, node.File, undici.File, etc.
|
|
45
48
|
*/
|
|
46
49
|
export interface FileLike extends BlobLike {
|
|
47
50
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
|
|
@@ -49,9 +52,20 @@ export interface FileLike extends BlobLike {
|
|
|
49
52
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
|
|
50
53
|
readonly name: string;
|
|
51
54
|
}
|
|
55
|
+
declare var FileClass: {
|
|
56
|
+
prototype: FileLike;
|
|
57
|
+
new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): FileLike;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const isFileLike = (value: any): value is FileLike =>
|
|
61
|
+
value != null &&
|
|
62
|
+
typeof value === 'object' &&
|
|
63
|
+
typeof value.name === 'string' &&
|
|
64
|
+
typeof value.lastModified === 'number' &&
|
|
65
|
+
isBlobLike(value);
|
|
52
66
|
|
|
53
67
|
/**
|
|
54
|
-
* Intended to match web.Response, node.Response,
|
|
68
|
+
* Intended to match web.Response, node.Response, undici.Response, etc.
|
|
55
69
|
*/
|
|
56
70
|
export interface ResponseLike {
|
|
57
71
|
url: string;
|
|
@@ -64,32 +78,26 @@ export const isResponseLike = (value: any): value is ResponseLike =>
|
|
|
64
78
|
typeof value.url === 'string' &&
|
|
65
79
|
typeof value.blob === 'function';
|
|
66
80
|
|
|
67
|
-
export const isFileLike = (value: any): value is FileLike =>
|
|
68
|
-
value != null &&
|
|
69
|
-
typeof value === 'object' &&
|
|
70
|
-
typeof value.name === 'string' &&
|
|
71
|
-
typeof value.lastModified === 'number' &&
|
|
72
|
-
isBlobLike(value);
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The BlobLike type omits arrayBuffer() because @types/node-fetch@^2.6.4 lacks it; but this check
|
|
76
|
-
* adds the arrayBuffer() method type because it is available and used at runtime
|
|
77
|
-
*/
|
|
78
|
-
export const isBlobLike = (value: any): value is BlobLike & { arrayBuffer(): Promise<ArrayBuffer> } =>
|
|
79
|
-
value != null &&
|
|
80
|
-
typeof value === 'object' &&
|
|
81
|
-
typeof value.size === 'number' &&
|
|
82
|
-
typeof value.type === 'string' &&
|
|
83
|
-
typeof value.text === 'function' &&
|
|
84
|
-
typeof value.slice === 'function' &&
|
|
85
|
-
typeof value.arrayBuffer === 'function';
|
|
86
|
-
|
|
87
81
|
export const isUploadable = (value: any): value is Uploadable => {
|
|
88
|
-
return isFileLike(value) || isResponseLike(value) ||
|
|
82
|
+
return isFileLike(value) || isResponseLike(value) || isFsReadStreamLike(value);
|
|
89
83
|
};
|
|
90
84
|
|
|
91
85
|
export type ToFileInput = Uploadable | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
|
|
92
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Construct a `File` instance. This is used to ensure a helpful error is thrown
|
|
89
|
+
* for environments that don't define a global `File` yet and so that we don't
|
|
90
|
+
* accidentally rely on a global `File` type in our annotations.
|
|
91
|
+
*/
|
|
92
|
+
function makeFile(fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): FileLike {
|
|
93
|
+
const File = (globalThis as any).File as typeof FileClass | undefined;
|
|
94
|
+
if (typeof File === 'undefined') {
|
|
95
|
+
throw new Error('`File` is not defined as a global which is required for file uploads');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return new File(fileBits, fileName, options);
|
|
99
|
+
}
|
|
100
|
+
|
|
93
101
|
/**
|
|
94
102
|
* Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
|
|
95
103
|
* @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
|
|
@@ -121,7 +129,7 @@ export async function toFile(
|
|
|
121
129
|
// in `new File` interpreting it as a string instead of binary data.
|
|
122
130
|
const data = isBlobLike(blob) ? [(await blob.arrayBuffer()) as any] : [blob];
|
|
123
131
|
|
|
124
|
-
return
|
|
132
|
+
return makeFile(data, name, options);
|
|
125
133
|
}
|
|
126
134
|
|
|
127
135
|
const bits = await getBytes(value);
|
|
@@ -135,7 +143,7 @@ export async function toFile(
|
|
|
135
143
|
}
|
|
136
144
|
}
|
|
137
145
|
|
|
138
|
-
return
|
|
146
|
+
return makeFile(bits, name, options);
|
|
139
147
|
}
|
|
140
148
|
|
|
141
149
|
async function getBytes(value: ToFileInput): Promise<Array<BlobPart>> {
|
|
@@ -187,27 +195,22 @@ const getStringFromMaybeBuffer = (x: string | Buffer | unknown): string | undefi
|
|
|
187
195
|
const isAsyncIterableIterator = (value: any): value is AsyncIterableIterator<unknown> =>
|
|
188
196
|
value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
|
|
189
197
|
|
|
190
|
-
export const isMultipartBody = (body: any): body is MultipartBody =>
|
|
191
|
-
body && typeof body === 'object' && body.body && body[Symbol.toStringTag] === 'MultipartBody';
|
|
192
|
-
|
|
193
198
|
/**
|
|
194
199
|
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
|
195
200
|
* Otherwise returns the request as is.
|
|
196
201
|
*/
|
|
197
|
-
export const maybeMultipartFormRequestOptions = async
|
|
198
|
-
opts: RequestOptions<T>,
|
|
199
|
-
): Promise<RequestOptions<T | MultipartBody>> => {
|
|
202
|
+
export const maybeMultipartFormRequestOptions = async (opts: RequestOptions): Promise<RequestOptions> => {
|
|
200
203
|
if (!hasUploadableValue(opts.body)) return opts;
|
|
201
204
|
|
|
202
|
-
|
|
203
|
-
return getMultipartRequestOptions(form, opts);
|
|
205
|
+
return { ...opts, body: await createForm(opts.body) };
|
|
204
206
|
};
|
|
205
207
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & { body: unknown };
|
|
209
|
+
|
|
210
|
+
export const multipartFormRequestOptions = async (
|
|
211
|
+
opts: MultipartFormRequestOptions,
|
|
212
|
+
): Promise<RequestOptions> => {
|
|
213
|
+
return { ...opts, body: await createForm(opts.body) };
|
|
211
214
|
};
|
|
212
215
|
|
|
213
216
|
export const createForm = async <T = Record<string, unknown>>(body: T | undefined): Promise<FormData> => {
|
|
@@ -240,7 +243,7 @@ const addFormValue = async (form: FormData, key: string, value: unknown): Promis
|
|
|
240
243
|
form.append(key, String(value));
|
|
241
244
|
} else if (isUploadable(value)) {
|
|
242
245
|
const file = await toFile(value);
|
|
243
|
-
form.append(key, file as
|
|
246
|
+
form.append(key, file as any);
|
|
244
247
|
} else if (Array.isArray(value)) {
|
|
245
248
|
await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
|
|
246
249
|
} else if (typeof value === 'object') {
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.34.0-alpha.0'; // x-release-please-version
|
package/streaming.d.mts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
import { type ReadableStream } from "./internal/shim-types.mjs";
|
|
3
|
+
export type ServerSentEvent = {
|
|
4
|
+
event: string | null;
|
|
5
|
+
data: string;
|
|
6
|
+
raw: string[];
|
|
7
|
+
};
|
|
8
|
+
export declare class Stream<Item> implements AsyncIterable<Item> {
|
|
9
|
+
private iterator;
|
|
10
|
+
controller: AbortController;
|
|
11
|
+
constructor(iterator: () => AsyncIterator<Item>, controller: AbortController);
|
|
12
|
+
static fromSSEResponse<Item>(response: Response, controller: AbortController): Stream<Item>;
|
|
13
|
+
/**
|
|
14
|
+
* Generates a Stream from a newline-separated ReadableStream
|
|
15
|
+
* where each item is a JSON value.
|
|
16
|
+
*/
|
|
17
|
+
static fromReadableStream<Item>(readableStream: ReadableStream, controller: AbortController): Stream<Item>;
|
|
18
|
+
[Symbol.asyncIterator](): AsyncIterator<Item>;
|
|
19
|
+
/**
|
|
20
|
+
* Splits the stream into two streams which can be
|
|
21
|
+
* independently read from at different speeds.
|
|
22
|
+
*/
|
|
23
|
+
tee(): [Stream<Item>, Stream<Item>];
|
|
24
|
+
/**
|
|
25
|
+
* Converts this stream to a newline-separated ReadableStream of
|
|
26
|
+
* JSON stringified values in the stream
|
|
27
|
+
* which can be turned back into a Stream with `Stream.fromReadableStream()`.
|
|
28
|
+
*/
|
|
29
|
+
toReadableStream(): ReadableStream;
|
|
30
|
+
}
|
|
31
|
+
export declare function _iterSSEMessages(response: Response, controller: AbortController): AsyncGenerator<ServerSentEvent, void, unknown>;
|
|
32
|
+
/** This is an internal helper function that's just used for testing */
|
|
33
|
+
export declare function _decodeChunks(chunks: string[]): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Most browsers don't yet have async iterable support for ReadableStream,
|
|
36
|
+
* and Node has a very different way of reading bytes from its "ReadableStream".
|
|
37
|
+
*
|
|
38
|
+
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
39
|
+
*/
|
|
40
|
+
export declare function readableStreamAsyncIterable<T>(stream: any): AsyncIterableIterator<T>;
|
|
41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,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAyBpF"}
|
package/streaming.d.ts
CHANGED
package/streaming.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":";OACO,EAAE,KAAK,cAAc,EAAE;AAQ9B,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,EAAE,CAAC;CACf,CAAC;AAEF,qBAAa,MAAM,CAAC,IAAI,CAAE,YAAW,aAAa,CAAC,IAAI,CAAC;IAIpD,OAAO,CAAC,QAAQ;IAHlB,UAAU,EAAE,eAAe,CAAC;gBAGlB,QAAQ,EAAE,MAAM,aAAa,CAAC,IAAI,CAAC,EAC3C,UAAU,EAAE,eAAe;IAK7B,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC;IA4D3F;;;OAGG;IACH,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC;IA2C1G,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC;IAI7C;;;OAGG;IACH,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IAwBnC;;;;OAIG;IACH,gBAAgB,IAAI,cAAc;CA0BnC;AAED,wBAAuB,gBAAgB,CACrC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,eAAe,GAC1B,cAAc,CAAC,eAAe,EAAE,IAAI,EAAE,OAAO,CAAC,CAqBhD;AA0HD,uEAAuE;AACvE,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAQxD;AAWD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAyBpF"}
|
package/streaming.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readableStreamAsyncIterable = exports._decodeChunks = exports._iterSSEMessages = exports.Stream = void 0;
|
|
4
|
-
const index_1 = require("./_shims/index.js");
|
|
5
4
|
const error_1 = require("./error.js");
|
|
5
|
+
const shims_1 = require("./internal/shims.js");
|
|
6
6
|
const line_1 = require("./internal/decoders/line.js");
|
|
7
|
-
const core_1 = require("./core.js");
|
|
8
7
|
const error_2 = require("./error.js");
|
|
9
8
|
class Stream {
|
|
10
9
|
constructor(iterator, controller) {
|
|
@@ -50,7 +49,7 @@ class Stream {
|
|
|
50
49
|
continue;
|
|
51
50
|
}
|
|
52
51
|
if (sse.event === 'error') {
|
|
53
|
-
throw error_2.APIError.generate(undefined, `SSE Error: ${sse.data}`, sse.data,
|
|
52
|
+
throw error_2.APIError.generate(undefined, `SSE Error: ${sse.data}`, sse.data, response.headers);
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
done = true;
|
|
@@ -153,7 +152,7 @@ class Stream {
|
|
|
153
152
|
const self = this;
|
|
154
153
|
let iter;
|
|
155
154
|
const encoder = new TextEncoder();
|
|
156
|
-
return
|
|
155
|
+
return (0, shims_1.makeReadableStream)({
|
|
157
156
|
async start() {
|
|
158
157
|
iter = self[Symbol.asyncIterator]();
|
|
159
158
|
},
|
package/streaming.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":";;;AAAA,sCAAyC;AAEzC,+CAAsD;AACtD,sDAAuD;AAEvD,sCAAmC;AAUnC,MAAa,MAAM;IAGjB,YACU,QAAmC,EAC3C,UAA2B;QADnB,aAAQ,GAAR,QAAQ,CAA2B;QAG3C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,eAAe,CAAO,QAAkB,EAAE,UAA2B;QAC1E,IAAI,QAAQ,GAAG,KAAK,CAAC;QAErB,KAAK,SAAS,CAAC,CAAC,QAAQ;YACtB,IAAI,QAAQ,EAAE;gBACZ,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAC;aAC7F;YACD,QAAQ,GAAG,IAAI,CAAC;YAChB,IAAI,IAAI,GAAG,KAAK,CAAC;YACjB,IAAI;gBACF,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE;oBAC9D,IAAI,GAAG,CAAC,KAAK,KAAK,YAAY,EAAE;wBAC9B,IAAI;4BACF,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;yBAC5B;wBAAC,OAAO,CAAC,EAAE;4BACV,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;4BAC9D,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;4BACtC,MAAM,CAAC,CAAC;yBACT;qBACF;oBAED,IACE,GAAG,CAAC,KAAK,KAAK,eAAe;wBAC7B,GAAG,CAAC,KAAK,KAAK,eAAe;wBAC7B,GAAG,CAAC,KAAK,KAAK,cAAc;wBAC5B,GAAG,CAAC,KAAK,KAAK,qBAAqB;wB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} from "./_shims/index.mjs";
|
|
2
1
|
import { AnthropicError } from "./error.mjs";
|
|
2
|
+
import { makeReadableStream } from "./internal/shims.mjs";
|
|
3
3
|
import { LineDecoder } from "./internal/decoders/line.mjs";
|
|
4
|
-
import { createResponseHeaders } from "./core.mjs";
|
|
5
4
|
import { APIError } from "./error.mjs";
|
|
6
5
|
export class Stream {
|
|
7
6
|
constructor(iterator, controller) {
|
|
@@ -47,7 +46,7 @@ export class Stream {
|
|
|
47
46
|
continue;
|
|
48
47
|
}
|
|
49
48
|
if (sse.event === 'error') {
|
|
50
|
-
throw APIError.generate(undefined, `SSE Error: ${sse.data}`, sse.data,
|
|
49
|
+
throw APIError.generate(undefined, `SSE Error: ${sse.data}`, sse.data, response.headers);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
done = true;
|
|
@@ -150,7 +149,7 @@ export class Stream {
|
|
|
150
149
|
const self = this;
|
|
151
150
|
let iter;
|
|
152
151
|
const encoder = new TextEncoder();
|
|
153
|
-
return
|
|
152
|
+
return makeReadableStream({
|
|
154
153
|
async start() {
|
|
155
154
|
iter = self[Symbol.asyncIterator]();
|
|
156
155
|
},
|