@ainative/cody-sdk 0.1.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/.github/logo.svg +3 -0
- package/CHANGELOG.md +2345 -0
- package/LICENSE +8 -0
- package/README.md +45 -0
- package/_vendor/partial-json-parser/parser.d.mts +3 -0
- package/_vendor/partial-json-parser/parser.d.mts.map +1 -0
- package/_vendor/partial-json-parser/parser.d.ts +3 -0
- package/_vendor/partial-json-parser/parser.d.ts.map +1 -0
- package/_vendor/partial-json-parser/parser.js +226 -0
- package/_vendor/partial-json-parser/parser.js.map +1 -0
- package/_vendor/partial-json-parser/parser.mjs +223 -0
- package/_vendor/partial-json-parser/parser.mjs.map +1 -0
- package/ainative.d.mts +32 -0
- package/ainative.d.mts.map +1 -0
- package/ainative.d.ts +32 -0
- package/ainative.d.ts.map +1 -0
- package/ainative.js +78 -0
- package/ainative.js.map +1 -0
- package/ainative.mjs +71 -0
- package/ainative.mjs.map +1 -0
- package/api-promise.d.mts +2 -0
- package/api-promise.d.mts.map +1 -0
- package/api-promise.d.ts +2 -0
- package/api-promise.d.ts.map +1 -0
- package/api-promise.js +6 -0
- package/api-promise.js.map +1 -0
- package/api-promise.mjs +2 -0
- package/api-promise.mjs.map +1 -0
- package/bin/cli +53 -0
- package/bin/migration-config.json +82 -0
- package/client.d.mts +247 -0
- package/client.d.mts.map +1 -0
- package/client.d.ts +247 -0
- package/client.d.ts.map +1 -0
- package/client.js +567 -0
- package/client.js.map +1 -0
- package/client.mjs +562 -0
- package/client.mjs.map +1 -0
- package/core/api-promise.d.mts +49 -0
- package/core/api-promise.d.mts.map +1 -0
- package/core/api-promise.d.ts +49 -0
- package/core/api-promise.d.ts.map +1 -0
- package/core/api-promise.js +76 -0
- package/core/api-promise.js.map +1 -0
- package/core/api-promise.mjs +72 -0
- package/core/api-promise.mjs.map +1 -0
- package/core/error.d.mts +50 -0
- package/core/error.d.mts.map +1 -0
- package/core/error.d.ts +50 -0
- package/core/error.d.ts.map +1 -0
- package/core/error.js +116 -0
- package/core/error.js.map +1 -0
- package/core/error.mjs +100 -0
- package/core/error.mjs.map +1 -0
- package/core/pagination.d.mts +105 -0
- package/core/pagination.d.mts.map +1 -0
- package/core/pagination.d.ts +105 -0
- package/core/pagination.d.ts.map +1 -0
- package/core/pagination.js +185 -0
- package/core/pagination.js.map +1 -0
- package/core/pagination.mjs +177 -0
- package/core/pagination.mjs.map +1 -0
- package/core/resource.d.mts +6 -0
- package/core/resource.d.mts.map +1 -0
- package/core/resource.d.ts +6 -0
- package/core/resource.d.ts.map +1 -0
- package/core/resource.js +11 -0
- package/core/resource.js.map +1 -0
- package/core/resource.mjs +7 -0
- package/core/resource.mjs.map +1 -0
- package/core/streaming.d.mts +33 -0
- package/core/streaming.d.mts.map +1 -0
- package/core/streaming.d.ts +33 -0
- package/core/streaming.d.ts.map +1 -0
- package/core/streaming.js +290 -0
- package/core/streaming.js.map +1 -0
- package/core/streaming.mjs +285 -0
- package/core/streaming.mjs.map +1 -0
- package/core/uploads.d.mts +3 -0
- package/core/uploads.d.mts.map +1 -0
- package/core/uploads.d.ts +3 -0
- package/core/uploads.d.ts.map +1 -0
- package/core/uploads.js +6 -0
- package/core/uploads.js.map +1 -0
- package/core/uploads.mjs +2 -0
- package/core/uploads.mjs.map +1 -0
- package/error.d.mts +2 -0
- package/error.d.mts.map +1 -0
- package/error.d.ts +2 -0
- package/error.d.ts.map +1 -0
- package/error.js +6 -0
- package/error.js.map +1 -0
- package/error.mjs +2 -0
- package/error.mjs.map +1 -0
- package/helpers/beta/json-schema.d.mts +31 -0
- package/helpers/beta/json-schema.d.mts.map +1 -0
- package/helpers/beta/json-schema.d.ts +31 -0
- package/helpers/beta/json-schema.d.ts.map +1 -0
- package/helpers/beta/json-schema.js +56 -0
- package/helpers/beta/json-schema.js.map +1 -0
- package/helpers/beta/json-schema.mjs +52 -0
- package/helpers/beta/json-schema.mjs.map +1 -0
- package/helpers/beta/mcp.d.mts +303 -0
- package/helpers/beta/mcp.d.mts.map +1 -0
- package/helpers/beta/mcp.d.ts +303 -0
- package/helpers/beta/mcp.d.ts.map +1 -0
- package/helpers/beta/mcp.js +419 -0
- package/helpers/beta/mcp.js.map +1 -0
- package/helpers/beta/mcp.mjs +406 -0
- package/helpers/beta/mcp.mjs.map +1 -0
- package/helpers/beta/memory.d.mts +11 -0
- package/helpers/beta/memory.d.mts.map +1 -0
- package/helpers/beta/memory.d.ts +11 -0
- package/helpers/beta/memory.d.ts.map +1 -0
- package/helpers/beta/memory.js +18 -0
- package/helpers/beta/memory.js.map +1 -0
- package/helpers/beta/memory.mjs +15 -0
- package/helpers/beta/memory.mjs.map +1 -0
- package/helpers/beta/zod.d.mts +27 -0
- package/helpers/beta/zod.d.mts.map +1 -0
- package/helpers/beta/zod.d.ts +27 -0
- package/helpers/beta/zod.d.ts.map +1 -0
- package/helpers/beta/zod.js +57 -0
- package/helpers/beta/zod.js.map +1 -0
- package/helpers/beta/zod.mjs +52 -0
- package/helpers/beta/zod.mjs.map +1 -0
- package/helpers/index.d.mts +3 -0
- package/helpers/index.d.mts.map +1 -0
- package/helpers/index.d.ts +3 -0
- package/helpers/index.d.ts.map +1 -0
- package/helpers/index.js +8 -0
- package/helpers/index.js.map +1 -0
- package/helpers/index.mjs +3 -0
- package/helpers/index.mjs.map +1 -0
- package/helpers/json-schema.d.mts +18 -0
- package/helpers/json-schema.d.mts.map +1 -0
- package/helpers/json-schema.d.ts +18 -0
- package/helpers/json-schema.d.ts.map +1 -0
- package/helpers/json-schema.js +37 -0
- package/helpers/json-schema.js.map +1 -0
- package/helpers/json-schema.mjs +34 -0
- package/helpers/json-schema.mjs.map +1 -0
- package/helpers/zod.d.mts +13 -0
- package/helpers/zod.d.mts.map +1 -0
- package/helpers/zod.d.ts +13 -0
- package/helpers/zod.d.ts.map +1 -0
- package/helpers/zod.js +47 -0
- package/helpers/zod.js.map +1 -0
- package/helpers/zod.mjs +43 -0
- package/helpers/zod.mjs.map +1 -0
- package/index.d.mts +9 -0
- package/index.d.mts.map +1 -0
- package/index.d.ts +9 -0
- package/index.d.ts.map +1 -0
- package/index.js +42 -0
- package/index.js.map +1 -0
- package/index.mjs +9 -0
- package/index.mjs.map +1 -0
- package/internal/builtin-types.d.mts +73 -0
- package/internal/builtin-types.d.mts.map +1 -0
- package/internal/builtin-types.d.ts +73 -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/constants.d.mts +5 -0
- package/internal/constants.d.mts.map +1 -0
- package/internal/constants.d.ts +5 -0
- package/internal/constants.d.ts.map +1 -0
- package/internal/constants.js +18 -0
- package/internal/constants.js.map +1 -0
- package/internal/constants.mjs +15 -0
- package/internal/constants.mjs.map +1 -0
- package/internal/decoders/jsonl.d.mts +10 -0
- package/internal/decoders/jsonl.d.mts.map +1 -0
- package/internal/decoders/jsonl.d.ts +10 -0
- package/internal/decoders/jsonl.d.ts.map +1 -0
- package/internal/decoders/jsonl.js +39 -0
- package/internal/decoders/jsonl.js.map +1 -0
- package/internal/decoders/jsonl.mjs +35 -0
- package/internal/decoders/jsonl.mjs.map +1 -0
- package/internal/decoders/line.d.mts +17 -0
- package/internal/decoders/line.d.mts.map +1 -0
- package/internal/decoders/line.d.ts +17 -0
- package/internal/decoders/line.d.ts.map +1 -0
- package/internal/decoders/line.js +113 -0
- package/internal/decoders/line.js.map +1 -0
- package/internal/decoders/line.mjs +108 -0
- package/internal/decoders/line.mjs.map +1 -0
- 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 +41 -0
- package/internal/errors.js.map +1 -0
- package/internal/errors.mjs +36 -0
- package/internal/errors.mjs.map +1 -0
- package/internal/headers.d.mts +22 -0
- package/internal/headers.d.mts.map +1 -0
- package/internal/headers.d.ts +22 -0
- package/internal/headers.d.ts.map +1 -0
- package/internal/headers.js +79 -0
- package/internal/headers.js.map +1 -0
- package/internal/headers.mjs +74 -0
- package/internal/headers.mjs.map +1 -0
- package/internal/parse.d.mts +17 -0
- package/internal/parse.d.mts.map +1 -0
- package/internal/parse.d.ts +17 -0
- package/internal/parse.d.ts.map +1 -0
- package/internal/parse.js +60 -0
- package/internal/parse.js.map +1 -0
- package/internal/parse.mjs +56 -0
- package/internal/parse.mjs.map +1 -0
- package/internal/request-options.d.mts +77 -0
- package/internal/request-options.d.mts.map +1 -0
- package/internal/request-options.d.ts +77 -0
- package/internal/request-options.d.ts.map +1 -0
- package/internal/request-options.js +14 -0
- package/internal/request-options.js.map +1 -0
- package/internal/request-options.mjs +10 -0
- package/internal/request-options.mjs.map +1 -0
- package/internal/shim-types.d.mts +17 -0
- package/internal/shim-types.d.mts.map +1 -0
- package/internal/shim-types.d.ts +17 -0
- package/internal/shim-types.d.ts.map +1 -0
- package/internal/shim-types.js +4 -0
- package/internal/shim-types.js.map +1 -0
- package/internal/shim-types.mjs +3 -0
- package/internal/shim-types.mjs.map +1 -0
- package/internal/shims.d.mts +20 -0
- package/internal/shims.d.mts.map +1 -0
- package/internal/shims.d.ts +20 -0
- package/internal/shims.d.ts.map +1 -0
- package/internal/shims.js +92 -0
- package/internal/shims.js.map +1 -0
- package/internal/shims.mjs +85 -0
- package/internal/shims.mjs.map +1 -0
- package/internal/stream-utils.d.mts +8 -0
- package/internal/stream-utils.d.mts.map +1 -0
- package/internal/stream-utils.d.ts +8 -0
- package/internal/stream-utils.d.ts.map +1 -0
- package/internal/stream-utils.js +38 -0
- package/internal/stream-utils.js.map +1 -0
- package/internal/stream-utils.mjs +35 -0
- package/internal/stream-utils.mjs.map +1 -0
- package/internal/to-file.d.mts +45 -0
- package/internal/to-file.d.mts.map +1 -0
- package/internal/to-file.d.ts +45 -0
- package/internal/to-file.d.ts.map +1 -0
- package/internal/to-file.js +96 -0
- package/internal/to-file.js.map +1 -0
- package/internal/to-file.mjs +93 -0
- package/internal/to-file.mjs.map +1 -0
- package/internal/tslib.js +81 -0
- package/internal/tslib.mjs +17 -0
- package/internal/types.d.mts +69 -0
- package/internal/types.d.mts.map +1 -0
- package/internal/types.d.ts +69 -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/uploads.d.mts +42 -0
- package/internal/uploads.d.mts.map +1 -0
- package/internal/uploads.d.ts +42 -0
- package/internal/uploads.d.ts.map +1 -0
- package/internal/uploads.js +145 -0
- package/internal/uploads.js.map +1 -0
- package/internal/uploads.mjs +135 -0
- package/internal/uploads.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 +38 -0
- package/internal/utils/base64.js.map +1 -0
- package/internal/utils/base64.mjs +33 -0
- package/internal/utils/base64.mjs.map +1 -0
- package/internal/utils/bytes.d.mts +4 -0
- package/internal/utils/bytes.d.mts.map +1 -0
- package/internal/utils/bytes.d.ts +4 -0
- package/internal/utils/bytes.d.ts.map +1 -0
- package/internal/utils/bytes.js +31 -0
- package/internal/utils/bytes.js.map +1 -0
- package/internal/utils/bytes.mjs +26 -0
- package/internal/utils/bytes.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 +37 -0
- package/internal/utils/log.d.mts.map +1 -0
- package/internal/utils/log.d.ts +37 -0
- package/internal/utils/log.d.ts.map +1 -0
- package/internal/utils/log.js +86 -0
- package/internal/utils/log.js.map +1 -0
- package/internal/utils/log.mjs +80 -0
- package/internal/utils/log.mjs.map +1 -0
- package/internal/utils/path.d.mts +15 -0
- package/internal/utils/path.d.mts.map +1 -0
- package/internal/utils/path.d.ts +15 -0
- package/internal/utils/path.d.ts.map +1 -0
- package/internal/utils/path.js +79 -0
- package/internal/utils/path.js.map +1 -0
- package/internal/utils/path.mjs +74 -0
- package/internal/utils/path.mjs.map +1 -0
- package/internal/utils/query.d.mts +5 -0
- package/internal/utils/query.d.mts.map +1 -0
- package/internal/utils/query.d.ts +5 -0
- package/internal/utils/query.d.ts.map +1 -0
- package/internal/utils/query.js +23 -0
- package/internal/utils/query.js.map +1 -0
- package/internal/utils/query.mjs +20 -0
- package/internal/utils/query.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 +19 -0
- package/internal/utils/uuid.js.map +1 -0
- package/internal/utils/uuid.mjs +15 -0
- package/internal/utils/uuid.mjs.map +1 -0
- package/internal/utils/values.d.mts +19 -0
- package/internal/utils/values.d.mts.map +1 -0
- package/internal/utils/values.d.ts +19 -0
- package/internal/utils/values.d.ts.map +1 -0
- package/internal/utils/values.js +119 -0
- package/internal/utils/values.js.map +1 -0
- package/internal/utils/values.mjs +100 -0
- package/internal/utils/values.mjs.map +1 -0
- package/internal/utils.d.mts +8 -0
- package/internal/utils.d.mts.map +1 -0
- package/internal/utils.d.ts +8 -0
- package/internal/utils.d.ts.map +1 -0
- package/internal/utils.js +12 -0
- package/internal/utils.js.map +1 -0
- package/internal/utils.mjs +9 -0
- package/internal/utils.mjs.map +1 -0
- package/lib/BetaMessageStream.d.mts +122 -0
- package/lib/BetaMessageStream.d.mts.map +1 -0
- package/lib/BetaMessageStream.d.ts +122 -0
- package/lib/BetaMessageStream.d.ts.map +1 -0
- package/lib/BetaMessageStream.js +620 -0
- package/lib/BetaMessageStream.js.map +1 -0
- package/lib/BetaMessageStream.mjs +616 -0
- package/lib/BetaMessageStream.mjs.map +1 -0
- package/lib/MessageStream.d.mts +121 -0
- package/lib/MessageStream.d.mts.map +1 -0
- package/lib/MessageStream.d.ts +121 -0
- package/lib/MessageStream.d.ts.map +1 -0
- package/lib/MessageStream.js +595 -0
- package/lib/MessageStream.js.map +1 -0
- package/lib/MessageStream.mjs +591 -0
- package/lib/MessageStream.mjs.map +1 -0
- package/lib/beta-parser.d.mts +37 -0
- package/lib/beta-parser.d.mts.map +1 -0
- package/lib/beta-parser.d.ts +37 -0
- package/lib/beta-parser.d.ts.map +1 -0
- package/lib/beta-parser.js +79 -0
- package/lib/beta-parser.js.map +1 -0
- package/lib/beta-parser.mjs +75 -0
- package/lib/beta-parser.mjs.map +1 -0
- package/lib/parser.d.mts +32 -0
- package/lib/parser.d.mts.map +1 -0
- package/lib/parser.d.ts +32 -0
- package/lib/parser.d.ts.map +1 -0
- package/lib/parser.js +66 -0
- package/lib/parser.js.map +1 -0
- package/lib/parser.mjs +62 -0
- package/lib/parser.mjs.map +1 -0
- package/lib/stainless-helper-header.d.mts +34 -0
- package/lib/stainless-helper-header.d.mts.map +1 -0
- package/lib/stainless-helper-header.d.ts +34 -0
- package/lib/stainless-helper-header.d.ts.map +1 -0
- package/lib/stainless-helper-header.js +70 -0
- package/lib/stainless-helper-header.js.map +1 -0
- package/lib/stainless-helper-header.mjs +63 -0
- package/lib/stainless-helper-header.mjs.map +1 -0
- package/lib/tools/BetaRunnableTool.d.mts +12 -0
- package/lib/tools/BetaRunnableTool.d.mts.map +1 -0
- package/lib/tools/BetaRunnableTool.d.ts +12 -0
- package/lib/tools/BetaRunnableTool.d.ts.map +1 -0
- package/lib/tools/BetaRunnableTool.js +3 -0
- package/lib/tools/BetaRunnableTool.js.map +1 -0
- package/lib/tools/BetaRunnableTool.mjs +2 -0
- package/lib/tools/BetaRunnableTool.mjs.map +1 -0
- package/lib/tools/BetaToolRunner.d.mts +141 -0
- package/lib/tools/BetaToolRunner.d.mts.map +1 -0
- package/lib/tools/BetaToolRunner.d.ts +141 -0
- package/lib/tools/BetaToolRunner.d.ts.map +1 -0
- package/lib/tools/BetaToolRunner.js +381 -0
- package/lib/tools/BetaToolRunner.js.map +1 -0
- package/lib/tools/BetaToolRunner.mjs +377 -0
- package/lib/tools/BetaToolRunner.mjs.map +1 -0
- package/lib/tools/CompactionControl.d.mts +30 -0
- package/lib/tools/CompactionControl.d.mts.map +1 -0
- package/lib/tools/CompactionControl.d.ts +30 -0
- package/lib/tools/CompactionControl.d.ts.map +1 -0
- package/lib/tools/CompactionControl.js +28 -0
- package/lib/tools/CompactionControl.js.map +1 -0
- package/lib/tools/CompactionControl.mjs +25 -0
- package/lib/tools/CompactionControl.mjs.map +1 -0
- package/lib/tools/ToolError.d.mts +33 -0
- package/lib/tools/ToolError.d.mts.map +1 -0
- package/lib/tools/ToolError.d.ts +33 -0
- package/lib/tools/ToolError.d.ts.map +1 -0
- package/lib/tools/ToolError.js +42 -0
- package/lib/tools/ToolError.js.map +1 -0
- package/lib/tools/ToolError.mjs +38 -0
- package/lib/tools/ToolError.mjs.map +1 -0
- package/lib/tools/ToolRunner.d.mts +132 -0
- package/lib/tools/ToolRunner.d.mts.map +1 -0
- package/lib/tools/ToolRunner.d.ts +132 -0
- package/lib/tools/ToolRunner.d.ts.map +1 -0
- package/lib/tools/ToolRunner.js +294 -0
- package/lib/tools/ToolRunner.js.map +1 -0
- package/lib/tools/ToolRunner.mjs +290 -0
- package/lib/tools/ToolRunner.mjs.map +1 -0
- package/lib/transform-json-schema.d.mts +3 -0
- package/lib/transform-json-schema.d.mts.map +1 -0
- package/lib/transform-json-schema.d.ts +3 -0
- package/lib/transform-json-schema.d.ts.map +1 -0
- package/lib/transform-json-schema.js +114 -0
- package/lib/transform-json-schema.js.map +1 -0
- package/lib/transform-json-schema.mjs +111 -0
- package/lib/transform-json-schema.mjs.map +1 -0
- package/package.json +246 -0
- package/pagination.d.mts +2 -0
- package/pagination.d.mts.map +1 -0
- package/pagination.d.ts +2 -0
- package/pagination.d.ts.map +1 -0
- package/pagination.js +6 -0
- package/pagination.js.map +1 -0
- package/pagination.mjs +2 -0
- package/pagination.mjs.map +1 -0
- package/resource.d.mts +2 -0
- package/resource.d.mts.map +1 -0
- package/resource.d.ts +2 -0
- package/resource.d.ts.map +1 -0
- package/resource.js +6 -0
- package/resource.js.map +1 -0
- package/resource.mjs +2 -0
- package/resource.mjs.map +1 -0
- package/resources/beta/beta.d.mts +66 -0
- package/resources/beta/beta.d.mts.map +1 -0
- package/resources/beta/beta.d.ts +66 -0
- package/resources/beta/beta.d.ts.map +1 -0
- package/resources/beta/beta.js +29 -0
- package/resources/beta/beta.js.map +1 -0
- package/resources/beta/beta.mjs +24 -0
- package/resources/beta/beta.mjs.map +1 -0
- package/resources/beta/files.d.mts +151 -0
- package/resources/beta/files.d.mts.map +1 -0
- package/resources/beta/files.d.ts +151 -0
- package/resources/beta/files.d.ts.map +1 -0
- package/resources/beta/files.js +124 -0
- package/resources/beta/files.js.map +1 -0
- package/resources/beta/files.mjs +120 -0
- package/resources/beta/files.mjs.map +1 -0
- package/resources/beta/index.d.mts +6 -0
- package/resources/beta/index.d.mts.map +1 -0
- package/resources/beta/index.d.ts +6 -0
- package/resources/beta/index.d.ts.map +1 -0
- package/resources/beta/index.js +15 -0
- package/resources/beta/index.js.map +1 -0
- package/resources/beta/index.mjs +7 -0
- package/resources/beta/index.mjs.map +1 -0
- package/resources/beta/messages/batches.d.mts +646 -0
- package/resources/beta/messages/batches.d.mts.map +1 -0
- package/resources/beta/messages/batches.d.ts +646 -0
- package/resources/beta/messages/batches.d.ts.map +1 -0
- package/resources/beta/messages/batches.js +204 -0
- package/resources/beta/messages/batches.js.map +1 -0
- package/resources/beta/messages/batches.mjs +200 -0
- package/resources/beta/messages/batches.mjs.map +1 -0
- package/resources/beta/messages/index.d.mts +4 -0
- package/resources/beta/messages/index.d.mts.map +1 -0
- package/resources/beta/messages/index.d.ts +4 -0
- package/resources/beta/messages/index.d.ts.map +1 -0
- package/resources/beta/messages/index.js +12 -0
- package/resources/beta/messages/index.js.map +1 -0
- package/resources/beta/messages/index.mjs +5 -0
- package/resources/beta/messages/index.mjs.map +1 -0
- package/resources/beta/messages/messages.d.mts +2993 -0
- package/resources/beta/messages/messages.d.mts.map +1 -0
- package/resources/beta/messages/messages.d.ts +2993 -0
- package/resources/beta/messages/messages.d.ts.map +1 -0
- package/resources/beta/messages/messages.js +163 -0
- package/resources/beta/messages/messages.js.map +1 -0
- package/resources/beta/messages/messages.mjs +156 -0
- package/resources/beta/messages/messages.mjs.map +1 -0
- package/resources/beta/messages.d.mts +2 -0
- package/resources/beta/messages.d.mts.map +1 -0
- package/resources/beta/messages.d.ts +2 -0
- package/resources/beta/messages.d.ts.map +1 -0
- package/resources/beta/messages.js +6 -0
- package/resources/beta/messages.js.map +1 -0
- package/resources/beta/messages.mjs +3 -0
- package/resources/beta/messages.mjs.map +1 -0
- package/resources/beta/models.d.mts +208 -0
- package/resources/beta/models.d.mts.map +1 -0
- package/resources/beta/models.d.ts +208 -0
- package/resources/beta/models.d.ts.map +1 -0
- package/resources/beta/models.js +60 -0
- package/resources/beta/models.js.map +1 -0
- package/resources/beta/models.mjs +56 -0
- package/resources/beta/models.mjs.map +1 -0
- package/resources/beta/skills/index.d.mts +3 -0
- package/resources/beta/skills/index.d.mts.map +1 -0
- package/resources/beta/skills/index.d.ts +3 -0
- package/resources/beta/skills/index.d.ts.map +1 -0
- package/resources/beta/skills/index.js +9 -0
- package/resources/beta/skills/index.js.map +1 -0
- package/resources/beta/skills/index.mjs +4 -0
- package/resources/beta/skills/index.mjs.map +1 -0
- package/resources/beta/skills/skills.d.mts +249 -0
- package/resources/beta/skills/skills.d.mts.map +1 -0
- package/resources/beta/skills/skills.d.ts +249 -0
- package/resources/beta/skills/skills.d.ts.map +1 -0
- package/resources/beta/skills/skills.js +98 -0
- package/resources/beta/skills/skills.js.map +1 -0
- package/resources/beta/skills/skills.mjs +93 -0
- package/resources/beta/skills/skills.mjs.map +1 -0
- package/resources/beta/skills/versions.d.mts +257 -0
- package/resources/beta/skills/versions.d.mts.map +1 -0
- package/resources/beta/skills/versions.d.ts +257 -0
- package/resources/beta/skills/versions.d.ts.map +1 -0
- package/resources/beta/skills/versions.js +100 -0
- package/resources/beta/skills/versions.js.map +1 -0
- package/resources/beta/skills/versions.mjs +96 -0
- package/resources/beta/skills/versions.mjs.map +1 -0
- package/resources/beta/skills.d.mts +2 -0
- package/resources/beta/skills.d.mts.map +1 -0
- package/resources/beta/skills.d.ts +2 -0
- package/resources/beta/skills.d.ts.map +1 -0
- package/resources/beta/skills.js +6 -0
- package/resources/beta/skills.js.map +1 -0
- package/resources/beta/skills.mjs +3 -0
- package/resources/beta/skills.mjs.map +1 -0
- package/resources/beta.d.mts +2 -0
- package/resources/beta.d.mts.map +1 -0
- package/resources/beta.d.ts +2 -0
- package/resources/beta.d.ts.map +1 -0
- package/resources/beta.js +6 -0
- package/resources/beta.js.map +1 -0
- package/resources/beta.mjs +3 -0
- package/resources/beta.mjs.map +1 -0
- package/resources/completions.d.mts +182 -0
- package/resources/completions.d.mts.map +1 -0
- package/resources/completions.d.ts +182 -0
- package/resources/completions.d.ts.map +1 -0
- package/resources/completions.js +23 -0
- package/resources/completions.js.map +1 -0
- package/resources/completions.mjs +19 -0
- package/resources/completions.mjs.map +1 -0
- package/resources/index.d.mts +6 -0
- package/resources/index.d.mts.map +1 -0
- package/resources/index.d.ts +6 -0
- package/resources/index.d.ts.map +1 -0
- package/resources/index.js +15 -0
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +7 -0
- package/resources/index.mjs.map +1 -0
- package/resources/messages/batches.d.mts +304 -0
- package/resources/messages/batches.d.mts.map +1 -0
- package/resources/messages/batches.d.ts +304 -0
- package/resources/messages/batches.d.ts.map +1 -0
- package/resources/messages/batches.js +153 -0
- package/resources/messages/batches.js.map +1 -0
- package/resources/messages/batches.mjs +149 -0
- package/resources/messages/batches.mjs.map +1 -0
- package/resources/messages/index.d.mts +3 -0
- package/resources/messages/index.d.mts.map +1 -0
- package/resources/messages/index.d.ts +3 -0
- package/resources/messages/index.d.ts.map +1 -0
- package/resources/messages/index.js +9 -0
- package/resources/messages/index.js.map +1 -0
- package/resources/messages/index.mjs +4 -0
- package/resources/messages/index.mjs.map +1 -0
- package/resources/messages/messages.d.mts +2285 -0
- package/resources/messages/messages.d.mts.map +1 -0
- package/resources/messages/messages.d.ts +2285 -0
- package/resources/messages/messages.d.ts.map +1 -0
- package/resources/messages/messages.js +128 -0
- package/resources/messages/messages.js.map +1 -0
- package/resources/messages/messages.mjs +123 -0
- package/resources/messages/messages.mjs.map +1 -0
- package/resources/messages.d.mts +2 -0
- package/resources/messages.d.mts.map +1 -0
- package/resources/messages.d.ts +2 -0
- package/resources/messages.d.ts.map +1 -0
- package/resources/messages.js +6 -0
- package/resources/messages.js.map +1 -0
- package/resources/messages.mjs +3 -0
- package/resources/messages.mjs.map +1 -0
- package/resources/models.d.mts +193 -0
- package/resources/models.d.mts.map +1 -0
- package/resources/models.d.ts +193 -0
- package/resources/models.d.ts.map +1 -0
- package/resources/models.js +45 -0
- package/resources/models.js.map +1 -0
- package/resources/models.mjs +41 -0
- package/resources/models.mjs.map +1 -0
- package/resources/shared.d.mts +44 -0
- package/resources/shared.d.mts.map +1 -0
- package/resources/shared.d.ts +44 -0
- package/resources/shared.d.ts.map +1 -0
- package/resources/shared.js +4 -0
- package/resources/shared.js.map +1 -0
- package/resources/shared.mjs +3 -0
- package/resources/shared.mjs.map +1 -0
- package/resources/top-level.d.mts +2 -0
- package/resources/top-level.d.mts.map +1 -0
- package/resources/top-level.d.ts +2 -0
- package/resources/top-level.d.ts.map +1 -0
- package/resources/top-level.js +4 -0
- package/resources/top-level.js.map +1 -0
- package/resources/top-level.mjs +3 -0
- package/resources/top-level.mjs.map +1 -0
- package/resources.d.mts +2 -0
- package/resources.d.mts.map +1 -0
- package/resources.d.ts +2 -0
- package/resources.d.ts.map +1 -0
- package/resources.js +5 -0
- package/resources.js.map +1 -0
- package/resources.mjs +2 -0
- package/resources.mjs.map +1 -0
- package/src/_vendor/partial-json-parser/README.md +3 -0
- package/src/_vendor/partial-json-parser/parser.ts +264 -0
- package/src/ainative.ts +85 -0
- package/src/api-promise.ts +2 -0
- package/src/client.ts +1326 -0
- package/src/core/README.md +3 -0
- package/src/core/api-promise.ts +101 -0
- package/src/core/error.ts +145 -0
- package/src/core/pagination.ts +331 -0
- package/src/core/resource.ts +11 -0
- package/src/core/streaming.ts +348 -0
- package/src/core/uploads.ts +2 -0
- package/src/error.ts +2 -0
- package/src/helpers/beta/json-schema.ts +75 -0
- package/src/helpers/beta/mcp.ts +624 -0
- package/src/helpers/beta/memory.ts +28 -0
- package/src/helpers/beta/zod.ts +72 -0
- package/src/helpers/index.ts +2 -0
- package/src/helpers/json-schema.ts +48 -0
- package/src/helpers/zod.ts +58 -0
- package/src/index.ts +40 -0
- package/src/internal/README.md +3 -0
- package/src/internal/builtin-types.ts +93 -0
- package/src/internal/constants.ts +15 -0
- package/src/internal/decoders/jsonl.ts +48 -0
- package/src/internal/decoders/line.ts +135 -0
- package/src/internal/detect-platform.ts +196 -0
- package/src/internal/errors.ts +33 -0
- package/src/internal/headers.ts +99 -0
- package/src/internal/parse.ts +90 -0
- package/src/internal/request-options.ts +93 -0
- package/src/internal/shim-types.ts +26 -0
- package/src/internal/shims.ts +107 -0
- package/src/internal/stream-utils.ts +32 -0
- package/src/internal/to-file.ts +159 -0
- package/src/internal/types.ts +95 -0
- package/src/internal/uploads.ts +204 -0
- package/src/internal/utils/base64.ts +40 -0
- package/src/internal/utils/bytes.ts +32 -0
- package/src/internal/utils/env.ts +18 -0
- package/src/internal/utils/log.ts +127 -0
- package/src/internal/utils/path.ts +88 -0
- package/src/internal/utils/query.ts +23 -0
- package/src/internal/utils/sleep.ts +3 -0
- package/src/internal/utils/uuid.ts +17 -0
- package/src/internal/utils/values.ts +112 -0
- package/src/internal/utils.ts +9 -0
- package/src/lib/.keep +4 -0
- package/src/lib/BetaMessageStream.ts +764 -0
- package/src/lib/MessageStream.ts +743 -0
- package/src/lib/beta-parser.ts +148 -0
- package/src/lib/parser.ts +125 -0
- package/src/lib/stainless-helper-header.ts +80 -0
- package/src/lib/tools/BetaRunnableTool.ts +40 -0
- package/src/lib/tools/BetaToolRunner.ts +494 -0
- package/src/lib/tools/CompactionControl.ts +57 -0
- package/src/lib/tools/ToolError.ts +47 -0
- package/src/lib/tools/ToolRunner.ts +381 -0
- package/src/lib/transform-json-schema.ts +124 -0
- package/src/pagination.ts +2 -0
- package/src/resource.ts +2 -0
- package/src/resources/beta/beta.ts +603 -0
- package/src/resources/beta/files.ts +261 -0
- package/src/resources/beta/index.ts +259 -0
- package/src/resources/beta/messages/batches.ts +827 -0
- package/src/resources/beta/messages/index.ts +229 -0
- package/src/resources/beta/messages/messages.ts +4372 -0
- package/src/resources/beta/messages.ts +3 -0
- package/src/resources/beta/models.ts +284 -0
- package/src/resources/beta/skills/index.ts +26 -0
- package/src/resources/beta/skills/skills.ts +384 -0
- package/src/resources/beta/skills/versions.ts +374 -0
- package/src/resources/beta/skills.ts +3 -0
- package/src/resources/beta.ts +3 -0
- package/src/resources/completions.ts +230 -0
- package/src/resources/index.ts +206 -0
- package/src/resources/messages/batches.ts +396 -0
- package/src/resources/messages/index.ts +189 -0
- package/src/resources/messages/messages.ts +3361 -0
- package/src/resources/messages.ts +3 -0
- package/src/resources/models.ts +269 -0
- package/src/resources/shared.ts +85 -0
- package/src/resources/top-level.ts +3 -0
- package/src/resources.ts +1 -0
- package/src/streaming.ts +2 -0
- package/src/tools/memory/node.ts +392 -0
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +2 -0
- package/src/version.ts +1 -0
- package/streaming.d.mts +2 -0
- package/streaming.d.mts.map +1 -0
- package/streaming.d.ts +2 -0
- package/streaming.d.ts.map +1 -0
- package/streaming.js +6 -0
- package/streaming.js.map +1 -0
- package/streaming.mjs +2 -0
- package/streaming.mjs.map +1 -0
- package/tools/memory/node.d.mts +18 -0
- package/tools/memory/node.d.mts.map +1 -0
- package/tools/memory/node.d.ts +18 -0
- package/tools/memory/node.d.ts.map +1 -0
- package/tools/memory/node.js +324 -0
- package/tools/memory/node.js.map +1 -0
- package/tools/memory/node.mjs +318 -0
- package/tools/memory/node.mjs.map +1 -0
- package/uploads.d.mts +2 -0
- package/uploads.d.mts.map +1 -0
- package/uploads.d.ts +2 -0
- package/uploads.d.ts.map +1 -0
- package/uploads.js +6 -0
- package/uploads.js.map +1 -0
- package/uploads.mjs +2 -0
- package/uploads.mjs.map +1 -0
- package/version.d.mts +2 -0
- package/version.d.mts.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +5 -0
- package/version.js.map +1 -0
- package/version.mjs +2 -0
- package/version.mjs.map +1 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ReadableStream } from "../internal/shim-types.mjs";
|
|
2
|
+
import type { BaseAnthropic } from "../client.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;
|
|
10
|
+
private iterator;
|
|
11
|
+
controller: AbortController;
|
|
12
|
+
constructor(iterator: () => AsyncIterator<Item>, controller: AbortController, client?: BaseAnthropic);
|
|
13
|
+
static fromSSEResponse<Item>(response: Response, controller: AbortController, client?: BaseAnthropic): Stream<Item>;
|
|
14
|
+
/**
|
|
15
|
+
* Generates a Stream from a newline-separated ReadableStream
|
|
16
|
+
* where each item is a JSON value.
|
|
17
|
+
*/
|
|
18
|
+
static fromReadableStream<Item>(readableStream: ReadableStream, controller: AbortController, client?: BaseAnthropic): Stream<Item>;
|
|
19
|
+
[Symbol.asyncIterator](): AsyncIterator<Item>;
|
|
20
|
+
/**
|
|
21
|
+
* Splits the stream into two streams which can be
|
|
22
|
+
* independently read from at different speeds.
|
|
23
|
+
*/
|
|
24
|
+
tee(): [Stream<Item>, Stream<Item>];
|
|
25
|
+
/**
|
|
26
|
+
* Converts this stream to a newline-separated ReadableStream of
|
|
27
|
+
* JSON stringified values in the stream
|
|
28
|
+
* which can be turned back into a Stream with `Stream.fromReadableStream()`.
|
|
29
|
+
*/
|
|
30
|
+
toReadableStream(): ReadableStream;
|
|
31
|
+
}
|
|
32
|
+
export declare function _iterSSEMessages(response: Response, controller: AbortController): AsyncGenerator<ServerSentEvent, void, unknown>;
|
|
33
|
+
//# sourceMappingURL=streaming.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.mts","sourceRoot":"","sources":["../src/core/streaming.ts"],"names":[],"mappings":"OACO,EAAE,KAAK,cAAc,EAAE;OAQvB,KAAK,EAAE,aAAa,EAAE;AAO7B,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;;IAKpD,OAAO,CAAC,QAAQ;IAJlB,UAAU,EAAE,eAAe,CAAC;gBAIlB,QAAQ,EAAE,MAAM,aAAa,CAAC,IAAI,CAAC,EAC3C,UAAU,EAAE,eAAe,EAC3B,MAAM,CAAC,EAAE,aAAa;IAMxB,MAAM,CAAC,eAAe,CAAC,IAAI,EACzB,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,eAAe,EAC3B,MAAM,CAAC,EAAE,aAAa,GACrB,MAAM,CAAC,IAAI,CAAC;IA+Df;;;OAGG;IACH,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAC5B,cAAc,EAAE,cAAc,EAC9B,UAAU,EAAE,eAAe,EAC3B,MAAM,CAAC,EAAE,aAAa,GACrB,MAAM,CAAC,IAAI,CAAC;IA2Cf,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;CAyBnC;AAED,wBAAuB,gBAAgB,CACrC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,eAAe,GAC1B,cAAc,CAAC,eAAe,EAAE,IAAI,EAAE,OAAO,CAAC,CA6BhD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ReadableStream } from "../internal/shim-types.js";
|
|
2
|
+
import type { BaseAnthropic } from "../client.js";
|
|
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;
|
|
10
|
+
private iterator;
|
|
11
|
+
controller: AbortController;
|
|
12
|
+
constructor(iterator: () => AsyncIterator<Item>, controller: AbortController, client?: BaseAnthropic);
|
|
13
|
+
static fromSSEResponse<Item>(response: Response, controller: AbortController, client?: BaseAnthropic): Stream<Item>;
|
|
14
|
+
/**
|
|
15
|
+
* Generates a Stream from a newline-separated ReadableStream
|
|
16
|
+
* where each item is a JSON value.
|
|
17
|
+
*/
|
|
18
|
+
static fromReadableStream<Item>(readableStream: ReadableStream, controller: AbortController, client?: BaseAnthropic): Stream<Item>;
|
|
19
|
+
[Symbol.asyncIterator](): AsyncIterator<Item>;
|
|
20
|
+
/**
|
|
21
|
+
* Splits the stream into two streams which can be
|
|
22
|
+
* independently read from at different speeds.
|
|
23
|
+
*/
|
|
24
|
+
tee(): [Stream<Item>, Stream<Item>];
|
|
25
|
+
/**
|
|
26
|
+
* Converts this stream to a newline-separated ReadableStream of
|
|
27
|
+
* JSON stringified values in the stream
|
|
28
|
+
* which can be turned back into a Stream with `Stream.fromReadableStream()`.
|
|
29
|
+
*/
|
|
30
|
+
toReadableStream(): ReadableStream;
|
|
31
|
+
}
|
|
32
|
+
export declare function _iterSSEMessages(response: Response, controller: AbortController): AsyncGenerator<ServerSentEvent, void, unknown>;
|
|
33
|
+
//# sourceMappingURL=streaming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/core/streaming.ts"],"names":[],"mappings":"OACO,EAAE,KAAK,cAAc,EAAE;OAQvB,KAAK,EAAE,aAAa,EAAE;AAO7B,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;;IAKpD,OAAO,CAAC,QAAQ;IAJlB,UAAU,EAAE,eAAe,CAAC;gBAIlB,QAAQ,EAAE,MAAM,aAAa,CAAC,IAAI,CAAC,EAC3C,UAAU,EAAE,eAAe,EAC3B,MAAM,CAAC,EAAE,aAAa;IAMxB,MAAM,CAAC,eAAe,CAAC,IAAI,EACzB,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,eAAe,EAC3B,MAAM,CAAC,EAAE,aAAa,GACrB,MAAM,CAAC,IAAI,CAAC;IA+Df;;;OAGG;IACH,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAC5B,cAAc,EAAE,cAAc,EAC9B,UAAU,EAAE,eAAe,EAC3B,MAAM,CAAC,EAAE,aAAa,GACrB,MAAM,CAAC,IAAI,CAAC;IA2Cf,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;CAyBnC;AAED,wBAAuB,gBAAgB,CACrC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,eAAe,GAC1B,cAAc,CAAC,eAAe,EAAE,IAAI,EAAE,OAAO,CAAC,CA6BhD"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _Stream_client;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Stream = void 0;
|
|
5
|
+
exports._iterSSEMessages = _iterSSEMessages;
|
|
6
|
+
const tslib_1 = require("../internal/tslib.js");
|
|
7
|
+
const error_1 = require("./error.js");
|
|
8
|
+
const shims_1 = require("../internal/shims.js");
|
|
9
|
+
const line_1 = require("../internal/decoders/line.js");
|
|
10
|
+
const shims_2 = require("../internal/shims.js");
|
|
11
|
+
const errors_1 = require("../internal/errors.js");
|
|
12
|
+
const values_1 = require("../internal/utils/values.js");
|
|
13
|
+
const bytes_1 = require("../internal/utils/bytes.js");
|
|
14
|
+
const log_1 = require("../internal/utils/log.js");
|
|
15
|
+
const error_2 = require("./error.js");
|
|
16
|
+
class Stream {
|
|
17
|
+
constructor(iterator, controller, client) {
|
|
18
|
+
this.iterator = iterator;
|
|
19
|
+
_Stream_client.set(this, void 0);
|
|
20
|
+
this.controller = controller;
|
|
21
|
+
tslib_1.__classPrivateFieldSet(this, _Stream_client, client, "f");
|
|
22
|
+
}
|
|
23
|
+
static fromSSEResponse(response, controller, client) {
|
|
24
|
+
let consumed = false;
|
|
25
|
+
const logger = client ? (0, log_1.loggerFor)(client) : console;
|
|
26
|
+
async function* iterator() {
|
|
27
|
+
if (consumed) {
|
|
28
|
+
throw new error_1.AnthropicError('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');
|
|
29
|
+
}
|
|
30
|
+
consumed = true;
|
|
31
|
+
let done = false;
|
|
32
|
+
try {
|
|
33
|
+
for await (const sse of _iterSSEMessages(response, controller)) {
|
|
34
|
+
if (sse.event === 'completion') {
|
|
35
|
+
try {
|
|
36
|
+
yield JSON.parse(sse.data);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
logger.error(`Could not parse message into JSON:`, sse.data);
|
|
40
|
+
logger.error(`From chunk:`, sse.raw);
|
|
41
|
+
throw e;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (sse.event === 'message_start' ||
|
|
45
|
+
sse.event === 'message_delta' ||
|
|
46
|
+
sse.event === 'message_stop' ||
|
|
47
|
+
sse.event === 'content_block_start' ||
|
|
48
|
+
sse.event === 'content_block_delta' ||
|
|
49
|
+
sse.event === 'content_block_stop') {
|
|
50
|
+
try {
|
|
51
|
+
yield JSON.parse(sse.data);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
logger.error(`Could not parse message into JSON:`, sse.data);
|
|
55
|
+
logger.error(`From chunk:`, sse.raw);
|
|
56
|
+
throw e;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (sse.event === 'ping') {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (sse.event === 'error') {
|
|
63
|
+
const body = (0, values_1.safeJSON)(sse.data) ?? sse.data;
|
|
64
|
+
const type = body?.error?.type;
|
|
65
|
+
throw new error_2.APIError(undefined, body, undefined, response.headers, type);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
done = true;
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
|
72
|
+
if ((0, errors_1.isAbortError)(e))
|
|
73
|
+
return;
|
|
74
|
+
throw e;
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
// If the user `break`s, abort the ongoing request.
|
|
78
|
+
if (!done)
|
|
79
|
+
controller.abort();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return new Stream(iterator, controller, client);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Generates a Stream from a newline-separated ReadableStream
|
|
86
|
+
* where each item is a JSON value.
|
|
87
|
+
*/
|
|
88
|
+
static fromReadableStream(readableStream, controller, client) {
|
|
89
|
+
let consumed = false;
|
|
90
|
+
async function* iterLines() {
|
|
91
|
+
const lineDecoder = new line_1.LineDecoder();
|
|
92
|
+
const iter = (0, shims_2.ReadableStreamToAsyncIterable)(readableStream);
|
|
93
|
+
for await (const chunk of iter) {
|
|
94
|
+
for (const line of lineDecoder.decode(chunk)) {
|
|
95
|
+
yield line;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
for (const line of lineDecoder.flush()) {
|
|
99
|
+
yield line;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function* iterator() {
|
|
103
|
+
if (consumed) {
|
|
104
|
+
throw new error_1.AnthropicError('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');
|
|
105
|
+
}
|
|
106
|
+
consumed = true;
|
|
107
|
+
let done = false;
|
|
108
|
+
try {
|
|
109
|
+
for await (const line of iterLines()) {
|
|
110
|
+
if (done)
|
|
111
|
+
continue;
|
|
112
|
+
if (line)
|
|
113
|
+
yield JSON.parse(line);
|
|
114
|
+
}
|
|
115
|
+
done = true;
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
|
119
|
+
if ((0, errors_1.isAbortError)(e))
|
|
120
|
+
return;
|
|
121
|
+
throw e;
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
// If the user `break`s, abort the ongoing request.
|
|
125
|
+
if (!done)
|
|
126
|
+
controller.abort();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return new Stream(iterator, controller, client);
|
|
130
|
+
}
|
|
131
|
+
[(_Stream_client = new WeakMap(), Symbol.asyncIterator)]() {
|
|
132
|
+
return this.iterator();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Splits the stream into two streams which can be
|
|
136
|
+
* independently read from at different speeds.
|
|
137
|
+
*/
|
|
138
|
+
tee() {
|
|
139
|
+
const left = [];
|
|
140
|
+
const right = [];
|
|
141
|
+
const iterator = this.iterator();
|
|
142
|
+
const teeIterator = (queue) => {
|
|
143
|
+
return {
|
|
144
|
+
next: () => {
|
|
145
|
+
if (queue.length === 0) {
|
|
146
|
+
const result = iterator.next();
|
|
147
|
+
left.push(result);
|
|
148
|
+
right.push(result);
|
|
149
|
+
}
|
|
150
|
+
return queue.shift();
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
return [
|
|
155
|
+
new Stream(() => teeIterator(left), this.controller, tslib_1.__classPrivateFieldGet(this, _Stream_client, "f")),
|
|
156
|
+
new Stream(() => teeIterator(right), this.controller, tslib_1.__classPrivateFieldGet(this, _Stream_client, "f")),
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Converts this stream to a newline-separated ReadableStream of
|
|
161
|
+
* JSON stringified values in the stream
|
|
162
|
+
* which can be turned back into a Stream with `Stream.fromReadableStream()`.
|
|
163
|
+
*/
|
|
164
|
+
toReadableStream() {
|
|
165
|
+
const self = this;
|
|
166
|
+
let iter;
|
|
167
|
+
return (0, shims_1.makeReadableStream)({
|
|
168
|
+
async start() {
|
|
169
|
+
iter = self[Symbol.asyncIterator]();
|
|
170
|
+
},
|
|
171
|
+
async pull(ctrl) {
|
|
172
|
+
try {
|
|
173
|
+
const { value, done } = await iter.next();
|
|
174
|
+
if (done)
|
|
175
|
+
return ctrl.close();
|
|
176
|
+
const bytes = (0, bytes_1.encodeUTF8)(JSON.stringify(value) + '\n');
|
|
177
|
+
ctrl.enqueue(bytes);
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
ctrl.error(err);
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
async cancel() {
|
|
184
|
+
await iter.return?.();
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.Stream = Stream;
|
|
190
|
+
async function* _iterSSEMessages(response, controller) {
|
|
191
|
+
if (!response.body) {
|
|
192
|
+
controller.abort();
|
|
193
|
+
if (typeof globalThis.navigator !== 'undefined' &&
|
|
194
|
+
globalThis.navigator.product === 'ReactNative') {
|
|
195
|
+
throw new error_1.AnthropicError(`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`);
|
|
196
|
+
}
|
|
197
|
+
throw new error_1.AnthropicError(`Attempted to iterate over a response with no body`);
|
|
198
|
+
}
|
|
199
|
+
const sseDecoder = new SSEDecoder();
|
|
200
|
+
const lineDecoder = new line_1.LineDecoder();
|
|
201
|
+
const iter = (0, shims_2.ReadableStreamToAsyncIterable)(response.body);
|
|
202
|
+
for await (const sseChunk of iterSSEChunks(iter)) {
|
|
203
|
+
for (const line of lineDecoder.decode(sseChunk)) {
|
|
204
|
+
const sse = sseDecoder.decode(line);
|
|
205
|
+
if (sse)
|
|
206
|
+
yield sse;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
for (const line of lineDecoder.flush()) {
|
|
210
|
+
const sse = sseDecoder.decode(line);
|
|
211
|
+
if (sse)
|
|
212
|
+
yield sse;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Given an async iterable iterator, iterates over it and yields full
|
|
217
|
+
* SSE chunks, i.e. yields when a double new-line is encountered.
|
|
218
|
+
*/
|
|
219
|
+
async function* iterSSEChunks(iterator) {
|
|
220
|
+
let data = new Uint8Array();
|
|
221
|
+
for await (const chunk of iterator) {
|
|
222
|
+
if (chunk == null) {
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
|
|
226
|
+
: typeof chunk === 'string' ? (0, bytes_1.encodeUTF8)(chunk)
|
|
227
|
+
: chunk;
|
|
228
|
+
let newData = new Uint8Array(data.length + binaryChunk.length);
|
|
229
|
+
newData.set(data);
|
|
230
|
+
newData.set(binaryChunk, data.length);
|
|
231
|
+
data = newData;
|
|
232
|
+
let patternIndex;
|
|
233
|
+
while ((patternIndex = (0, line_1.findDoubleNewlineIndex)(data)) !== -1) {
|
|
234
|
+
yield data.slice(0, patternIndex);
|
|
235
|
+
data = data.slice(patternIndex);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (data.length > 0) {
|
|
239
|
+
yield data;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
class SSEDecoder {
|
|
243
|
+
constructor() {
|
|
244
|
+
this.event = null;
|
|
245
|
+
this.data = [];
|
|
246
|
+
this.chunks = [];
|
|
247
|
+
}
|
|
248
|
+
decode(line) {
|
|
249
|
+
if (line.endsWith('\r')) {
|
|
250
|
+
line = line.substring(0, line.length - 1);
|
|
251
|
+
}
|
|
252
|
+
if (!line) {
|
|
253
|
+
// empty line and we didn't previously encounter any messages
|
|
254
|
+
if (!this.event && !this.data.length)
|
|
255
|
+
return null;
|
|
256
|
+
const sse = {
|
|
257
|
+
event: this.event,
|
|
258
|
+
data: this.data.join('\n'),
|
|
259
|
+
raw: this.chunks,
|
|
260
|
+
};
|
|
261
|
+
this.event = null;
|
|
262
|
+
this.data = [];
|
|
263
|
+
this.chunks = [];
|
|
264
|
+
return sse;
|
|
265
|
+
}
|
|
266
|
+
this.chunks.push(line);
|
|
267
|
+
if (line.startsWith(':')) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
let [fieldname, _, value] = partition(line, ':');
|
|
271
|
+
if (value.startsWith(' ')) {
|
|
272
|
+
value = value.substring(1);
|
|
273
|
+
}
|
|
274
|
+
if (fieldname === 'event') {
|
|
275
|
+
this.event = value;
|
|
276
|
+
}
|
|
277
|
+
else if (fieldname === 'data') {
|
|
278
|
+
this.data.push(value);
|
|
279
|
+
}
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function partition(str, delimiter) {
|
|
284
|
+
const index = str.indexOf(delimiter);
|
|
285
|
+
if (index !== -1) {
|
|
286
|
+
return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
|
|
287
|
+
}
|
|
288
|
+
return [str, '', ''];
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=streaming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../src/core/streaming.ts"],"names":[],"mappings":";;;;AAyNA,4CAgCC;;AAzPD,sCAAyC;AAEzC,gDAAuD;AACvD,uDAAgF;AAChF,gDAAkE;AAClE,kDAAkD;AAClD,wDAAoD;AACpD,sDAAqD;AACrD,kDAAkD;AAGlD,sCAAmC;AAWnC,MAAa,MAAM;IAIjB,YACU,QAAmC,EAC3C,UAA2B,EAC3B,MAAsB;QAFd,aAAQ,GAAR,QAAQ,CAA2B;QAH7C,iCAAmC;QAOjC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,+BAAA,IAAI,kBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,eAAe,CACpB,QAAkB,EA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AAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC7B,CAAC;QAED,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;YAC1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,CAAC;aAAM,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;YAChC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,SAAS,SAAS,CAAC,GAAW,EAAE,SAAiB;IAC/C,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACrC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QACjB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IACvF,CAAC;IAED,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
var _Stream_client;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "../internal/tslib.mjs";
|
|
3
|
+
import { AnthropicError } from "./error.mjs";
|
|
4
|
+
import { makeReadableStream } from "../internal/shims.mjs";
|
|
5
|
+
import { findDoubleNewlineIndex, LineDecoder } from "../internal/decoders/line.mjs";
|
|
6
|
+
import { ReadableStreamToAsyncIterable } from "../internal/shims.mjs";
|
|
7
|
+
import { isAbortError } from "../internal/errors.mjs";
|
|
8
|
+
import { safeJSON } from "../internal/utils/values.mjs";
|
|
9
|
+
import { encodeUTF8 } from "../internal/utils/bytes.mjs";
|
|
10
|
+
import { loggerFor } from "../internal/utils/log.mjs";
|
|
11
|
+
import { APIError } from "./error.mjs";
|
|
12
|
+
export class Stream {
|
|
13
|
+
constructor(iterator, controller, client) {
|
|
14
|
+
this.iterator = iterator;
|
|
15
|
+
_Stream_client.set(this, void 0);
|
|
16
|
+
this.controller = controller;
|
|
17
|
+
__classPrivateFieldSet(this, _Stream_client, client, "f");
|
|
18
|
+
}
|
|
19
|
+
static fromSSEResponse(response, controller, client) {
|
|
20
|
+
let consumed = false;
|
|
21
|
+
const logger = client ? loggerFor(client) : console;
|
|
22
|
+
async function* iterator() {
|
|
23
|
+
if (consumed) {
|
|
24
|
+
throw new AnthropicError('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');
|
|
25
|
+
}
|
|
26
|
+
consumed = true;
|
|
27
|
+
let done = false;
|
|
28
|
+
try {
|
|
29
|
+
for await (const sse of _iterSSEMessages(response, controller)) {
|
|
30
|
+
if (sse.event === 'completion') {
|
|
31
|
+
try {
|
|
32
|
+
yield JSON.parse(sse.data);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
logger.error(`Could not parse message into JSON:`, sse.data);
|
|
36
|
+
logger.error(`From chunk:`, sse.raw);
|
|
37
|
+
throw e;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (sse.event === 'message_start' ||
|
|
41
|
+
sse.event === 'message_delta' ||
|
|
42
|
+
sse.event === 'message_stop' ||
|
|
43
|
+
sse.event === 'content_block_start' ||
|
|
44
|
+
sse.event === 'content_block_delta' ||
|
|
45
|
+
sse.event === 'content_block_stop') {
|
|
46
|
+
try {
|
|
47
|
+
yield JSON.parse(sse.data);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
logger.error(`Could not parse message into JSON:`, sse.data);
|
|
51
|
+
logger.error(`From chunk:`, sse.raw);
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (sse.event === 'ping') {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (sse.event === 'error') {
|
|
59
|
+
const body = safeJSON(sse.data) ?? sse.data;
|
|
60
|
+
const type = body?.error?.type;
|
|
61
|
+
throw new APIError(undefined, body, undefined, response.headers, type);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
done = true;
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
|
68
|
+
if (isAbortError(e))
|
|
69
|
+
return;
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
// If the user `break`s, abort the ongoing request.
|
|
74
|
+
if (!done)
|
|
75
|
+
controller.abort();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return new Stream(iterator, controller, client);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Generates a Stream from a newline-separated ReadableStream
|
|
82
|
+
* where each item is a JSON value.
|
|
83
|
+
*/
|
|
84
|
+
static fromReadableStream(readableStream, controller, client) {
|
|
85
|
+
let consumed = false;
|
|
86
|
+
async function* iterLines() {
|
|
87
|
+
const lineDecoder = new LineDecoder();
|
|
88
|
+
const iter = ReadableStreamToAsyncIterable(readableStream);
|
|
89
|
+
for await (const chunk of iter) {
|
|
90
|
+
for (const line of lineDecoder.decode(chunk)) {
|
|
91
|
+
yield line;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
for (const line of lineDecoder.flush()) {
|
|
95
|
+
yield line;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function* iterator() {
|
|
99
|
+
if (consumed) {
|
|
100
|
+
throw new AnthropicError('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');
|
|
101
|
+
}
|
|
102
|
+
consumed = true;
|
|
103
|
+
let done = false;
|
|
104
|
+
try {
|
|
105
|
+
for await (const line of iterLines()) {
|
|
106
|
+
if (done)
|
|
107
|
+
continue;
|
|
108
|
+
if (line)
|
|
109
|
+
yield JSON.parse(line);
|
|
110
|
+
}
|
|
111
|
+
done = true;
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
|
115
|
+
if (isAbortError(e))
|
|
116
|
+
return;
|
|
117
|
+
throw e;
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
// If the user `break`s, abort the ongoing request.
|
|
121
|
+
if (!done)
|
|
122
|
+
controller.abort();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return new Stream(iterator, controller, client);
|
|
126
|
+
}
|
|
127
|
+
[(_Stream_client = new WeakMap(), Symbol.asyncIterator)]() {
|
|
128
|
+
return this.iterator();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Splits the stream into two streams which can be
|
|
132
|
+
* independently read from at different speeds.
|
|
133
|
+
*/
|
|
134
|
+
tee() {
|
|
135
|
+
const left = [];
|
|
136
|
+
const right = [];
|
|
137
|
+
const iterator = this.iterator();
|
|
138
|
+
const teeIterator = (queue) => {
|
|
139
|
+
return {
|
|
140
|
+
next: () => {
|
|
141
|
+
if (queue.length === 0) {
|
|
142
|
+
const result = iterator.next();
|
|
143
|
+
left.push(result);
|
|
144
|
+
right.push(result);
|
|
145
|
+
}
|
|
146
|
+
return queue.shift();
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
return [
|
|
151
|
+
new Stream(() => teeIterator(left), this.controller, __classPrivateFieldGet(this, _Stream_client, "f")),
|
|
152
|
+
new Stream(() => teeIterator(right), this.controller, __classPrivateFieldGet(this, _Stream_client, "f")),
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Converts this stream to a newline-separated ReadableStream of
|
|
157
|
+
* JSON stringified values in the stream
|
|
158
|
+
* which can be turned back into a Stream with `Stream.fromReadableStream()`.
|
|
159
|
+
*/
|
|
160
|
+
toReadableStream() {
|
|
161
|
+
const self = this;
|
|
162
|
+
let iter;
|
|
163
|
+
return makeReadableStream({
|
|
164
|
+
async start() {
|
|
165
|
+
iter = self[Symbol.asyncIterator]();
|
|
166
|
+
},
|
|
167
|
+
async pull(ctrl) {
|
|
168
|
+
try {
|
|
169
|
+
const { value, done } = await iter.next();
|
|
170
|
+
if (done)
|
|
171
|
+
return ctrl.close();
|
|
172
|
+
const bytes = encodeUTF8(JSON.stringify(value) + '\n');
|
|
173
|
+
ctrl.enqueue(bytes);
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
ctrl.error(err);
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
async cancel() {
|
|
180
|
+
await iter.return?.();
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
export async function* _iterSSEMessages(response, controller) {
|
|
186
|
+
if (!response.body) {
|
|
187
|
+
controller.abort();
|
|
188
|
+
if (typeof globalThis.navigator !== 'undefined' &&
|
|
189
|
+
globalThis.navigator.product === 'ReactNative') {
|
|
190
|
+
throw new AnthropicError(`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`);
|
|
191
|
+
}
|
|
192
|
+
throw new AnthropicError(`Attempted to iterate over a response with no body`);
|
|
193
|
+
}
|
|
194
|
+
const sseDecoder = new SSEDecoder();
|
|
195
|
+
const lineDecoder = new LineDecoder();
|
|
196
|
+
const iter = ReadableStreamToAsyncIterable(response.body);
|
|
197
|
+
for await (const sseChunk of iterSSEChunks(iter)) {
|
|
198
|
+
for (const line of lineDecoder.decode(sseChunk)) {
|
|
199
|
+
const sse = sseDecoder.decode(line);
|
|
200
|
+
if (sse)
|
|
201
|
+
yield sse;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
for (const line of lineDecoder.flush()) {
|
|
205
|
+
const sse = sseDecoder.decode(line);
|
|
206
|
+
if (sse)
|
|
207
|
+
yield sse;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Given an async iterable iterator, iterates over it and yields full
|
|
212
|
+
* SSE chunks, i.e. yields when a double new-line is encountered.
|
|
213
|
+
*/
|
|
214
|
+
async function* iterSSEChunks(iterator) {
|
|
215
|
+
let data = new Uint8Array();
|
|
216
|
+
for await (const chunk of iterator) {
|
|
217
|
+
if (chunk == null) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
|
|
221
|
+
: typeof chunk === 'string' ? encodeUTF8(chunk)
|
|
222
|
+
: chunk;
|
|
223
|
+
let newData = new Uint8Array(data.length + binaryChunk.length);
|
|
224
|
+
newData.set(data);
|
|
225
|
+
newData.set(binaryChunk, data.length);
|
|
226
|
+
data = newData;
|
|
227
|
+
let patternIndex;
|
|
228
|
+
while ((patternIndex = findDoubleNewlineIndex(data)) !== -1) {
|
|
229
|
+
yield data.slice(0, patternIndex);
|
|
230
|
+
data = data.slice(patternIndex);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (data.length > 0) {
|
|
234
|
+
yield data;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
class SSEDecoder {
|
|
238
|
+
constructor() {
|
|
239
|
+
this.event = null;
|
|
240
|
+
this.data = [];
|
|
241
|
+
this.chunks = [];
|
|
242
|
+
}
|
|
243
|
+
decode(line) {
|
|
244
|
+
if (line.endsWith('\r')) {
|
|
245
|
+
line = line.substring(0, line.length - 1);
|
|
246
|
+
}
|
|
247
|
+
if (!line) {
|
|
248
|
+
// empty line and we didn't previously encounter any messages
|
|
249
|
+
if (!this.event && !this.data.length)
|
|
250
|
+
return null;
|
|
251
|
+
const sse = {
|
|
252
|
+
event: this.event,
|
|
253
|
+
data: this.data.join('\n'),
|
|
254
|
+
raw: this.chunks,
|
|
255
|
+
};
|
|
256
|
+
this.event = null;
|
|
257
|
+
this.data = [];
|
|
258
|
+
this.chunks = [];
|
|
259
|
+
return sse;
|
|
260
|
+
}
|
|
261
|
+
this.chunks.push(line);
|
|
262
|
+
if (line.startsWith(':')) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
let [fieldname, _, value] = partition(line, ':');
|
|
266
|
+
if (value.startsWith(' ')) {
|
|
267
|
+
value = value.substring(1);
|
|
268
|
+
}
|
|
269
|
+
if (fieldname === 'event') {
|
|
270
|
+
this.event = value;
|
|
271
|
+
}
|
|
272
|
+
else if (fieldname === 'data') {
|
|
273
|
+
this.data.push(value);
|
|
274
|
+
}
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function partition(str, delimiter) {
|
|
279
|
+
const index = str.indexOf(delimiter);
|
|
280
|
+
if (index !== -1) {
|
|
281
|
+
return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
|
|
282
|
+
}
|
|
283
|
+
return [str, '', ''];
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=streaming.mjs.map
|