@anthropic-ai/claude-code 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +3 -0
- package/README.md +55 -0
- package/cli.mjs +1398 -0
- package/package.json +31 -0
- package/vendor/ripgrep/COPYING +3 -0
- package/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/vendor/ripgrep/arm64-linux/rg +0 -0
- package/vendor/ripgrep/x64-darwin/rg +0 -0
- package/vendor/ripgrep/x64-linux/rg +0 -0
- package/vendor/ripgrep/x64-win32/rg.exe +0 -0
- package/vendor/sdk/CHANGELOG.md +1421 -0
- package/vendor/sdk/LICENSE +8 -0
- package/vendor/sdk/README.md +536 -0
- package/vendor/sdk/_shims/MultipartBody.d.ts +9 -0
- package/vendor/sdk/_shims/MultipartBody.d.ts.map +1 -0
- package/vendor/sdk/_shims/MultipartBody.js +16 -0
- package/vendor/sdk/_shims/MultipartBody.js.map +1 -0
- package/vendor/sdk/_shims/MultipartBody.mjs +12 -0
- package/vendor/sdk/_shims/MultipartBody.mjs.map +1 -0
- package/vendor/sdk/_shims/README.md +46 -0
- package/vendor/sdk/_shims/auto/runtime-bun.d.ts +5 -0
- package/vendor/sdk/_shims/auto/runtime-bun.d.ts.map +1 -0
- package/vendor/sdk/_shims/auto/runtime-bun.js +21 -0
- package/vendor/sdk/_shims/auto/runtime-bun.js.map +1 -0
- package/vendor/sdk/_shims/auto/runtime-bun.mjs +2 -0
- package/vendor/sdk/_shims/auto/runtime-bun.mjs.map +1 -0
- package/vendor/sdk/_shims/auto/runtime-node.d.ts +5 -0
- package/vendor/sdk/_shims/auto/runtime-node.d.ts.map +1 -0
- package/vendor/sdk/_shims/auto/runtime-node.js +21 -0
- package/vendor/sdk/_shims/auto/runtime-node.js.map +1 -0
- package/vendor/sdk/_shims/auto/runtime-node.mjs +2 -0
- package/vendor/sdk/_shims/auto/runtime-node.mjs.map +1 -0
- package/vendor/sdk/_shims/auto/runtime.d.ts +5 -0
- package/vendor/sdk/_shims/auto/runtime.d.ts.map +1 -0
- package/vendor/sdk/_shims/auto/runtime.js +21 -0
- package/vendor/sdk/_shims/auto/runtime.js.map +1 -0
- package/vendor/sdk/_shims/auto/runtime.mjs +2 -0
- package/vendor/sdk/_shims/auto/runtime.mjs.map +1 -0
- package/vendor/sdk/_shims/auto/types-node.d.ts +5 -0
- package/vendor/sdk/_shims/auto/types-node.d.ts.map +1 -0
- package/vendor/sdk/_shims/auto/types-node.js +21 -0
- package/vendor/sdk/_shims/auto/types-node.js.map +1 -0
- package/vendor/sdk/_shims/auto/types-node.mjs +2 -0
- package/vendor/sdk/_shims/auto/types-node.mjs.map +1 -0
- package/vendor/sdk/_shims/auto/types.d.ts +101 -0
- package/vendor/sdk/_shims/auto/types.js +3 -0
- package/vendor/sdk/_shims/auto/types.mjs +3 -0
- package/vendor/sdk/_shims/bun-runtime.d.ts +6 -0
- package/vendor/sdk/_shims/bun-runtime.d.ts.map +1 -0
- package/vendor/sdk/_shims/bun-runtime.js +14 -0
- package/vendor/sdk/_shims/bun-runtime.js.map +1 -0
- package/vendor/sdk/_shims/bun-runtime.mjs +10 -0
- package/vendor/sdk/_shims/bun-runtime.mjs.map +1 -0
- package/vendor/sdk/_shims/index.d.ts +81 -0
- package/vendor/sdk/_shims/index.js +13 -0
- package/vendor/sdk/_shims/index.mjs +7 -0
- package/vendor/sdk/_shims/manual-types.d.ts +12 -0
- package/vendor/sdk/_shims/manual-types.js +3 -0
- package/vendor/sdk/_shims/manual-types.mjs +3 -0
- package/vendor/sdk/_shims/node-runtime.d.ts +3 -0
- package/vendor/sdk/_shims/node-runtime.d.ts.map +1 -0
- package/vendor/sdk/_shims/node-runtime.js +89 -0
- package/vendor/sdk/_shims/node-runtime.js.map +1 -0
- package/vendor/sdk/_shims/node-runtime.mjs +56 -0
- package/vendor/sdk/_shims/node-runtime.mjs.map +1 -0
- package/vendor/sdk/_shims/node-types.d.ts +42 -0
- package/vendor/sdk/_shims/node-types.js +3 -0
- package/vendor/sdk/_shims/node-types.mjs +3 -0
- package/vendor/sdk/_shims/registry.d.ts +37 -0
- package/vendor/sdk/_shims/registry.d.ts.map +1 -0
- package/vendor/sdk/_shims/registry.js +41 -0
- package/vendor/sdk/_shims/registry.js.map +1 -0
- package/vendor/sdk/_shims/registry.mjs +37 -0
- package/vendor/sdk/_shims/registry.mjs.map +1 -0
- package/vendor/sdk/_shims/web-runtime.d.ts +5 -0
- package/vendor/sdk/_shims/web-runtime.d.ts.map +1 -0
- package/vendor/sdk/_shims/web-runtime.js +78 -0
- package/vendor/sdk/_shims/web-runtime.js.map +1 -0
- package/vendor/sdk/_shims/web-runtime.mjs +71 -0
- package/vendor/sdk/_shims/web-runtime.mjs.map +1 -0
- package/vendor/sdk/_shims/web-types.d.ts +83 -0
- package/vendor/sdk/_shims/web-types.js +3 -0
- package/vendor/sdk/_shims/web-types.mjs +3 -0
- package/vendor/sdk/_vendor/partial-json-parser/parser.d.ts +3 -0
- package/vendor/sdk/_vendor/partial-json-parser/parser.d.ts.map +1 -0
- package/vendor/sdk/_vendor/partial-json-parser/parser.js +226 -0
- package/vendor/sdk/_vendor/partial-json-parser/parser.js.map +1 -0
- package/vendor/sdk/_vendor/partial-json-parser/parser.mjs +223 -0
- package/vendor/sdk/_vendor/partial-json-parser/parser.mjs.map +1 -0
- package/vendor/sdk/core.d.ts +248 -0
- package/vendor/sdk/core.d.ts.map +1 -0
- package/vendor/sdk/core.js +935 -0
- package/vendor/sdk/core.js.map +1 -0
- package/vendor/sdk/core.mjs +903 -0
- package/vendor/sdk/core.mjs.map +1 -0
- package/vendor/sdk/error.d.ts +48 -0
- package/vendor/sdk/error.d.ts.map +1 -0
- package/vendor/sdk/error.js +114 -0
- package/vendor/sdk/error.js.map +1 -0
- package/vendor/sdk/error.mjs +98 -0
- package/vendor/sdk/error.mjs.map +1 -0
- package/vendor/sdk/index.d.mts +152 -0
- package/vendor/sdk/index.d.ts +152 -0
- package/vendor/sdk/index.d.ts.map +1 -0
- package/vendor/sdk/index.js +179 -0
- package/vendor/sdk/index.js.map +1 -0
- package/vendor/sdk/index.mjs +136 -0
- package/vendor/sdk/index.mjs.map +1 -0
- package/vendor/sdk/internal/decoders/jsonl.d.ts +12 -0
- package/vendor/sdk/internal/decoders/jsonl.d.ts.map +1 -0
- package/vendor/sdk/internal/decoders/jsonl.js +35 -0
- package/vendor/sdk/internal/decoders/jsonl.js.map +1 -0
- package/vendor/sdk/internal/decoders/jsonl.mjs +31 -0
- package/vendor/sdk/internal/decoders/jsonl.mjs.map +1 -0
- package/vendor/sdk/internal/decoders/line.d.ts +20 -0
- package/vendor/sdk/internal/decoders/line.d.ts.map +1 -0
- package/vendor/sdk/internal/decoders/line.js +123 -0
- package/vendor/sdk/internal/decoders/line.js.map +1 -0
- package/vendor/sdk/internal/decoders/line.mjs +119 -0
- package/vendor/sdk/internal/decoders/line.mjs.map +1 -0
- package/vendor/sdk/internal/stream-utils.d.ts +8 -0
- package/vendor/sdk/internal/stream-utils.d.ts.map +1 -0
- package/vendor/sdk/internal/stream-utils.js +39 -0
- package/vendor/sdk/internal/stream-utils.js.map +1 -0
- package/vendor/sdk/internal/stream-utils.mjs +35 -0
- package/vendor/sdk/internal/stream-utils.mjs.map +1 -0
- package/vendor/sdk/lib/BetaMessageStream.d.ts +114 -0
- package/vendor/sdk/lib/BetaMessageStream.d.ts.map +1 -0
- package/vendor/sdk/lib/BetaMessageStream.js +547 -0
- package/vendor/sdk/lib/BetaMessageStream.js.map +1 -0
- package/vendor/sdk/lib/BetaMessageStream.mjs +543 -0
- package/vendor/sdk/lib/BetaMessageStream.mjs.map +1 -0
- package/vendor/sdk/lib/MessageStream.d.ts +114 -0
- package/vendor/sdk/lib/MessageStream.d.ts.map +1 -0
- package/vendor/sdk/lib/MessageStream.js +547 -0
- package/vendor/sdk/lib/MessageStream.js.map +1 -0
- package/vendor/sdk/lib/MessageStream.mjs +543 -0
- package/vendor/sdk/lib/MessageStream.mjs.map +1 -0
- package/vendor/sdk/node_modules/@types/node/LICENSE +21 -0
- package/vendor/sdk/node_modules/@types/node/README.md +15 -0
- package/vendor/sdk/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/vendor/sdk/node_modules/@types/node/assert.d.ts +985 -0
- package/vendor/sdk/node_modules/@types/node/async_hooks.d.ts +522 -0
- package/vendor/sdk/node_modules/@types/node/buffer.buffer.d.ts +385 -0
- package/vendor/sdk/node_modules/@types/node/buffer.d.ts +1903 -0
- package/vendor/sdk/node_modules/@types/node/child_process.d.ts +1549 -0
- package/vendor/sdk/node_modules/@types/node/cluster.d.ts +578 -0
- package/vendor/sdk/node_modules/@types/node/compatibility/disposable.d.ts +14 -0
- package/vendor/sdk/node_modules/@types/node/compatibility/index.d.ts +9 -0
- package/vendor/sdk/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
- package/vendor/sdk/node_modules/@types/node/compatibility/iterators.d.ts +20 -0
- package/vendor/sdk/node_modules/@types/node/console.d.ts +452 -0
- package/vendor/sdk/node_modules/@types/node/constants.d.ts +19 -0
- package/vendor/sdk/node_modules/@types/node/crypto.d.ts +4453 -0
- package/vendor/sdk/node_modules/@types/node/dgram.d.ts +596 -0
- package/vendor/sdk/node_modules/@types/node/diagnostics_channel.d.ts +546 -0
- package/vendor/sdk/node_modules/@types/node/dns/promises.d.ts +475 -0
- package/vendor/sdk/node_modules/@types/node/dns.d.ts +853 -0
- package/vendor/sdk/node_modules/@types/node/dom-events.d.ts +124 -0
- package/vendor/sdk/node_modules/@types/node/domain.d.ts +170 -0
- package/vendor/sdk/node_modules/@types/node/events.d.ts +819 -0
- package/vendor/sdk/node_modules/@types/node/fs/promises.d.ts +1205 -0
- package/vendor/sdk/node_modules/@types/node/fs.d.ts +4237 -0
- package/vendor/sdk/node_modules/@types/node/globals.d.ts +442 -0
- package/vendor/sdk/node_modules/@types/node/globals.typedarray.d.ts +21 -0
- package/vendor/sdk/node_modules/@types/node/http.d.ts +1839 -0
- package/vendor/sdk/node_modules/@types/node/http2.d.ts +2517 -0
- package/vendor/sdk/node_modules/@types/node/https.d.ts +544 -0
- package/vendor/sdk/node_modules/@types/node/index.d.ts +90 -0
- package/vendor/sdk/node_modules/@types/node/inspector.d.ts +2775 -0
- package/vendor/sdk/node_modules/@types/node/module.d.ts +291 -0
- package/vendor/sdk/node_modules/@types/node/net.d.ts +924 -0
- package/vendor/sdk/node_modules/@types/node/os.d.ts +473 -0
- package/vendor/sdk/node_modules/@types/node/package.json +225 -0
- package/vendor/sdk/node_modules/@types/node/path.d.ts +191 -0
- package/vendor/sdk/node_modules/@types/node/perf_hooks.d.ts +753 -0
- package/vendor/sdk/node_modules/@types/node/process.d.ts +1553 -0
- package/vendor/sdk/node_modules/@types/node/punycode.d.ts +117 -0
- package/vendor/sdk/node_modules/@types/node/querystring.d.ts +141 -0
- package/vendor/sdk/node_modules/@types/node/readline/promises.d.ts +154 -0
- package/vendor/sdk/node_modules/@types/node/readline.d.ts +715 -0
- package/vendor/sdk/node_modules/@types/node/repl.d.ts +430 -0
- package/vendor/sdk/node_modules/@types/node/stream/consumers.d.ts +12 -0
- package/vendor/sdk/node_modules/@types/node/stream/promises.d.ts +90 -0
- package/vendor/sdk/node_modules/@types/node/stream/web.d.ts +523 -0
- package/vendor/sdk/node_modules/@types/node/stream.d.ts +1731 -0
- package/vendor/sdk/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/vendor/sdk/node_modules/@types/node/test.d.ts +1245 -0
- package/vendor/sdk/node_modules/@types/node/timers/promises.d.ts +93 -0
- package/vendor/sdk/node_modules/@types/node/timers.d.ts +126 -0
- package/vendor/sdk/node_modules/@types/node/tls.d.ts +1203 -0
- package/vendor/sdk/node_modules/@types/node/trace_events.d.ts +171 -0
- package/vendor/sdk/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +385 -0
- package/vendor/sdk/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +19 -0
- package/vendor/sdk/node_modules/@types/node/ts5.6/index.d.ts +90 -0
- package/vendor/sdk/node_modules/@types/node/tty.d.ts +206 -0
- package/vendor/sdk/node_modules/@types/node/url.d.ts +957 -0
- package/vendor/sdk/node_modules/@types/node/util.d.ts +2083 -0
- package/vendor/sdk/node_modules/@types/node/v8.d.ts +753 -0
- package/vendor/sdk/node_modules/@types/node/vm.d.ts +666 -0
- package/vendor/sdk/node_modules/@types/node/wasi.d.ts +160 -0
- package/vendor/sdk/node_modules/@types/node/worker_threads.d.ts +695 -0
- package/vendor/sdk/node_modules/@types/node/zlib.d.ts +517 -0
- package/vendor/sdk/node_modules/undici-types/README.md +6 -0
- package/vendor/sdk/node_modules/undici-types/agent.d.ts +31 -0
- package/vendor/sdk/node_modules/undici-types/api.d.ts +43 -0
- package/vendor/sdk/node_modules/undici-types/balanced-pool.d.ts +18 -0
- package/vendor/sdk/node_modules/undici-types/cache.d.ts +36 -0
- package/vendor/sdk/node_modules/undici-types/client.d.ts +97 -0
- package/vendor/sdk/node_modules/undici-types/connector.d.ts +34 -0
- package/vendor/sdk/node_modules/undici-types/content-type.d.ts +21 -0
- package/vendor/sdk/node_modules/undici-types/cookies.d.ts +28 -0
- package/vendor/sdk/node_modules/undici-types/diagnostics-channel.d.ts +67 -0
- package/vendor/sdk/node_modules/undici-types/dispatcher.d.ts +241 -0
- package/vendor/sdk/node_modules/undici-types/errors.d.ts +128 -0
- package/vendor/sdk/node_modules/undici-types/fetch.d.ts +209 -0
- package/vendor/sdk/node_modules/undici-types/file.d.ts +39 -0
- package/vendor/sdk/node_modules/undici-types/filereader.d.ts +54 -0
- package/vendor/sdk/node_modules/undici-types/formdata.d.ts +108 -0
- package/vendor/sdk/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/vendor/sdk/node_modules/undici-types/global-origin.d.ts +7 -0
- package/vendor/sdk/node_modules/undici-types/handlers.d.ts +9 -0
- package/vendor/sdk/node_modules/undici-types/header.d.ts +4 -0
- package/vendor/sdk/node_modules/undici-types/index.d.ts +63 -0
- package/vendor/sdk/node_modules/undici-types/interceptors.d.ts +5 -0
- package/vendor/sdk/node_modules/undici-types/mock-agent.d.ts +50 -0
- package/vendor/sdk/node_modules/undici-types/mock-client.d.ts +25 -0
- package/vendor/sdk/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/vendor/sdk/node_modules/undici-types/mock-interceptor.d.ts +93 -0
- package/vendor/sdk/node_modules/undici-types/mock-pool.d.ts +25 -0
- package/vendor/sdk/node_modules/undici-types/package.json +55 -0
- package/vendor/sdk/node_modules/undici-types/patch.d.ts +71 -0
- package/vendor/sdk/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/vendor/sdk/node_modules/undici-types/pool.d.ts +28 -0
- package/vendor/sdk/node_modules/undici-types/proxy-agent.d.ts +30 -0
- package/vendor/sdk/node_modules/undici-types/readable.d.ts +61 -0
- package/vendor/sdk/node_modules/undici-types/webidl.d.ts +220 -0
- package/vendor/sdk/node_modules/undici-types/websocket.d.ts +131 -0
- package/vendor/sdk/package.json +124 -0
- package/vendor/sdk/pagination.d.ts +27 -0
- package/vendor/sdk/pagination.d.ts.map +1 -0
- package/vendor/sdk/pagination.js +60 -0
- package/vendor/sdk/pagination.js.map +1 -0
- package/vendor/sdk/pagination.mjs +56 -0
- package/vendor/sdk/pagination.mjs.map +1 -0
- package/vendor/sdk/resource.d.ts +6 -0
- package/vendor/sdk/resource.d.ts.map +1 -0
- package/vendor/sdk/resource.js +11 -0
- package/vendor/sdk/resource.js.map +1 -0
- package/vendor/sdk/resource.mjs +7 -0
- package/vendor/sdk/resource.mjs.map +1 -0
- package/vendor/sdk/resources/beta/beta.d.ts +57 -0
- package/vendor/sdk/resources/beta/beta.d.ts.map +1 -0
- package/vendor/sdk/resources/beta/beta.js +44 -0
- package/vendor/sdk/resources/beta/beta.js.map +1 -0
- package/vendor/sdk/resources/beta/beta.mjs +17 -0
- package/vendor/sdk/resources/beta/beta.mjs.map +1 -0
- package/vendor/sdk/resources/beta/index.d.ts +4 -0
- package/vendor/sdk/resources/beta/index.d.ts.map +1 -0
- package/vendor/sdk/resources/beta/index.js +12 -0
- package/vendor/sdk/resources/beta/index.js.map +1 -0
- package/vendor/sdk/resources/beta/index.mjs +5 -0
- package/vendor/sdk/resources/beta/index.mjs.map +1 -0
- package/vendor/sdk/resources/beta/messages/batches.d.ts +289 -0
- package/vendor/sdk/resources/beta/messages/batches.d.ts.map +1 -0
- package/vendor/sdk/resources/beta/messages/batches.js +112 -0
- package/vendor/sdk/resources/beta/messages/batches.js.map +1 -0
- package/vendor/sdk/resources/beta/messages/batches.mjs +107 -0
- package/vendor/sdk/resources/beta/messages/batches.mjs.map +1 -0
- package/vendor/sdk/resources/beta/messages/index.d.ts +3 -0
- package/vendor/sdk/resources/beta/messages/index.d.ts.map +1 -0
- package/vendor/sdk/resources/beta/messages/index.js +10 -0
- package/vendor/sdk/resources/beta/messages/index.js.map +1 -0
- package/vendor/sdk/resources/beta/messages/index.mjs +4 -0
- package/vendor/sdk/resources/beta/messages/index.mjs.map +1 -0
- package/vendor/sdk/resources/beta/messages/messages.d.ts +1038 -0
- package/vendor/sdk/resources/beta/messages/messages.d.ts.map +1 -0
- package/vendor/sdk/resources/beta/messages/messages.js +93 -0
- package/vendor/sdk/resources/beta/messages/messages.js.map +1 -0
- package/vendor/sdk/resources/beta/messages/messages.mjs +66 -0
- package/vendor/sdk/resources/beta/messages/messages.mjs.map +1 -0
- package/vendor/sdk/resources/beta/models.d.ts +49 -0
- package/vendor/sdk/resources/beta/models.d.ts.map +1 -0
- package/vendor/sdk/resources/beta/models.js +30 -0
- package/vendor/sdk/resources/beta/models.js.map +1 -0
- package/vendor/sdk/resources/beta/models.mjs +25 -0
- package/vendor/sdk/resources/beta/models.mjs.map +1 -0
- package/vendor/sdk/resources/completions.d.ts +166 -0
- package/vendor/sdk/resources/completions.d.ts.map +1 -0
- package/vendor/sdk/resources/completions.js +17 -0
- package/vendor/sdk/resources/completions.js.map +1 -0
- package/vendor/sdk/resources/completions.mjs +13 -0
- package/vendor/sdk/resources/completions.mjs.map +1 -0
- package/vendor/sdk/resources/index.d.ts +6 -0
- package/vendor/sdk/resources/index.d.ts.map +1 -0
- package/vendor/sdk/resources/index.js +29 -0
- package/vendor/sdk/resources/index.js.map +1 -0
- package/vendor/sdk/resources/index.mjs +7 -0
- package/vendor/sdk/resources/index.mjs.map +1 -0
- package/vendor/sdk/resources/messages/batches.d.ts +253 -0
- package/vendor/sdk/resources/messages/batches.d.ts.map +1 -0
- package/vendor/sdk/resources/messages/batches.js +102 -0
- package/vendor/sdk/resources/messages/batches.js.map +1 -0
- package/vendor/sdk/resources/messages/batches.mjs +97 -0
- package/vendor/sdk/resources/messages/batches.mjs.map +1 -0
- package/vendor/sdk/resources/messages/index.d.ts +3 -0
- package/vendor/sdk/resources/messages/index.d.ts.map +1 -0
- package/vendor/sdk/resources/messages/index.js +10 -0
- package/vendor/sdk/resources/messages/index.js.map +1 -0
- package/vendor/sdk/resources/messages/index.mjs +4 -0
- package/vendor/sdk/resources/messages/index.mjs.map +1 -0
- package/vendor/sdk/resources/messages/messages.d.ts +1028 -0
- package/vendor/sdk/resources/messages/messages.d.ts.map +1 -0
- package/vendor/sdk/resources/messages/messages.js +82 -0
- package/vendor/sdk/resources/messages/messages.js.map +1 -0
- package/vendor/sdk/resources/messages/messages.mjs +54 -0
- package/vendor/sdk/resources/messages/messages.mjs.map +1 -0
- package/vendor/sdk/resources/models.d.ts +49 -0
- package/vendor/sdk/resources/models.d.ts.map +1 -0
- package/vendor/sdk/resources/models.js +30 -0
- package/vendor/sdk/resources/models.js.map +1 -0
- package/vendor/sdk/resources/models.mjs +25 -0
- package/vendor/sdk/resources/models.mjs.map +1 -0
- package/vendor/sdk/resources/shared.d.ts +42 -0
- package/vendor/sdk/resources/shared.d.ts.map +1 -0
- package/vendor/sdk/resources/shared.js +4 -0
- package/vendor/sdk/resources/shared.js.map +1 -0
- package/vendor/sdk/resources/shared.mjs +3 -0
- package/vendor/sdk/resources/shared.mjs.map +1 -0
- package/vendor/sdk/resources/top-level.d.ts +2 -0
- package/vendor/sdk/resources/top-level.d.ts.map +1 -0
- package/vendor/sdk/resources/top-level.js +4 -0
- package/vendor/sdk/resources/top-level.js.map +1 -0
- package/vendor/sdk/resources/top-level.mjs +3 -0
- package/vendor/sdk/resources/top-level.mjs.map +1 -0
- package/vendor/sdk/shims/node.d.ts +30 -0
- package/vendor/sdk/shims/node.d.ts.map +1 -0
- package/vendor/sdk/shims/node.js +31 -0
- package/vendor/sdk/shims/node.js.map +1 -0
- package/vendor/sdk/shims/node.mjs +5 -0
- package/vendor/sdk/shims/node.mjs.map +1 -0
- package/vendor/sdk/shims/web.d.ts +26 -0
- package/vendor/sdk/shims/web.d.ts.map +1 -0
- package/vendor/sdk/shims/web.js +31 -0
- package/vendor/sdk/shims/web.js.map +1 -0
- package/vendor/sdk/shims/web.mjs +5 -0
- package/vendor/sdk/shims/web.mjs.map +1 -0
- package/vendor/sdk/src/_shims/MultipartBody.ts +9 -0
- package/vendor/sdk/src/_shims/README.md +46 -0
- package/vendor/sdk/src/_shims/auto/runtime-bun.ts +4 -0
- package/vendor/sdk/src/_shims/auto/runtime-node.ts +4 -0
- package/vendor/sdk/src/_shims/auto/runtime.ts +4 -0
- package/vendor/sdk/src/_shims/auto/types-node.ts +4 -0
- package/vendor/sdk/src/_shims/auto/types.d.ts +101 -0
- package/vendor/sdk/src/_shims/auto/types.js +3 -0
- package/vendor/sdk/src/_shims/auto/types.mjs +3 -0
- package/vendor/sdk/src/_shims/bun-runtime.ts +14 -0
- package/vendor/sdk/src/_shims/index.d.ts +81 -0
- package/vendor/sdk/src/_shims/index.js +13 -0
- package/vendor/sdk/src/_shims/index.mjs +7 -0
- package/vendor/sdk/src/_shims/manual-types.d.ts +12 -0
- package/vendor/sdk/src/_shims/manual-types.js +3 -0
- package/vendor/sdk/src/_shims/manual-types.mjs +3 -0
- package/vendor/sdk/src/_shims/node-runtime.ts +81 -0
- package/vendor/sdk/src/_shims/node-types.d.ts +42 -0
- package/vendor/sdk/src/_shims/node-types.js +3 -0
- package/vendor/sdk/src/_shims/node-types.mjs +3 -0
- package/vendor/sdk/src/_shims/registry.ts +67 -0
- package/vendor/sdk/src/_shims/web-runtime.ts +103 -0
- package/vendor/sdk/src/_shims/web-types.d.ts +83 -0
- package/vendor/sdk/src/_shims/web-types.js +3 -0
- package/vendor/sdk/src/_shims/web-types.mjs +3 -0
- package/vendor/sdk/src/_vendor/partial-json-parser/README.md +3 -0
- package/vendor/sdk/src/_vendor/partial-json-parser/parser.ts +264 -0
- package/vendor/sdk/src/core.ts +1250 -0
- package/vendor/sdk/src/error.ts +133 -0
- package/vendor/sdk/src/index.ts +465 -0
- package/vendor/sdk/src/internal/decoders/jsonl.ts +41 -0
- package/vendor/sdk/src/internal/decoders/line.ts +145 -0
- package/vendor/sdk/src/internal/stream-utils.ts +32 -0
- package/vendor/sdk/src/lib/.keep +4 -0
- package/vendor/sdk/src/lib/BetaMessageStream.ts +661 -0
- package/vendor/sdk/src/lib/MessageStream.ts +662 -0
- package/vendor/sdk/src/pagination.ts +92 -0
- package/vendor/sdk/src/resource.ts +11 -0
- package/vendor/sdk/src/resources/beta/beta.ts +249 -0
- package/vendor/sdk/src/resources/beta/index.ts +83 -0
- package/vendor/sdk/src/resources/beta/messages/batches.ts +486 -0
- package/vendor/sdk/src/resources/beta/messages/index.ts +87 -0
- package/vendor/sdk/src/resources/beta/messages/messages.ts +1444 -0
- package/vendor/sdk/src/resources/beta/models.ts +78 -0
- package/vendor/sdk/src/resources/completions.ts +210 -0
- package/vendor/sdk/src/resources/index.ts +95 -0
- package/vendor/sdk/src/resources/messages/batches.ts +352 -0
- package/vendor/sdk/src/resources/messages/index.ts +85 -0
- package/vendor/sdk/src/resources/messages/messages.ts +1412 -0
- package/vendor/sdk/src/resources/models.ts +75 -0
- package/vendor/sdk/src/resources/shared.ts +72 -0
- package/vendor/sdk/src/resources/top-level.ts +3 -0
- package/vendor/sdk/src/shims/node.ts +50 -0
- package/vendor/sdk/src/shims/web.ts +50 -0
- package/vendor/sdk/src/streaming.ts +372 -0
- package/vendor/sdk/src/tsconfig.json +11 -0
- package/vendor/sdk/src/uploads.ts +255 -0
- package/vendor/sdk/src/version.ts +1 -0
- package/vendor/sdk/streaming.d.ts +36 -0
- package/vendor/sdk/streaming.d.ts.map +1 -0
- package/vendor/sdk/streaming.js +316 -0
- package/vendor/sdk/streaming.js.map +1 -0
- package/vendor/sdk/streaming.mjs +310 -0
- package/vendor/sdk/streaming.mjs.map +1 -0
- package/vendor/sdk/uploads.d.ts +75 -0
- package/vendor/sdk/uploads.d.ts.map +1 -0
- package/vendor/sdk/uploads.js +171 -0
- package/vendor/sdk/uploads.js.map +1 -0
- package/vendor/sdk/uploads.mjs +158 -0
- package/vendor/sdk/uploads.mjs.map +1 -0
- package/vendor/sdk/version.d.ts +2 -0
- package/vendor/sdk/version.d.ts.map +1 -0
- package/vendor/sdk/version.js +5 -0
- package/vendor/sdk/version.js.map +1 -0
- package/vendor/sdk/version.mjs +2 -0
- package/vendor/sdk/version.mjs.map +1 -0
- package/yoga.wasm +0 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
|
|
2
|
+
import * as Core from '@anthropic-ai/sdk/core';
|
|
3
|
+
import { AnthropicError, APIUserAbortError } from '@anthropic-ai/sdk/error';
|
|
4
|
+
import { type ContentBlock, Messages, type Message, type MessageStreamEvent, type MessageParam, type MessageCreateParams, type MessageCreateParamsBase, type TextCitation } from '@anthropic-ai/sdk/resources/messages';
|
|
5
|
+
import { type ReadableStream, type Response } from '@anthropic-ai/sdk/_shims/index';
|
|
6
|
+
export interface MessageStreamEvents {
|
|
7
|
+
connect: () => void;
|
|
8
|
+
streamEvent: (event: MessageStreamEvent, snapshot: Message) => void;
|
|
9
|
+
text: (textDelta: string, textSnapshot: string) => void;
|
|
10
|
+
citation: (citation: TextCitation, citationsSnapshot: TextCitation[]) => void;
|
|
11
|
+
inputJson: (partialJson: string, jsonSnapshot: unknown) => void;
|
|
12
|
+
thinking: (thinkingDelta: string, thinkingSnapshot: string) => void;
|
|
13
|
+
message: (message: Message) => void;
|
|
14
|
+
contentBlock: (content: ContentBlock) => void;
|
|
15
|
+
finalMessage: (message: Message) => void;
|
|
16
|
+
error: (error: AnthropicError) => void;
|
|
17
|
+
abort: (error: APIUserAbortError) => void;
|
|
18
|
+
end: () => void;
|
|
19
|
+
}
|
|
20
|
+
export declare class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
21
|
+
#private;
|
|
22
|
+
messages: MessageParam[];
|
|
23
|
+
receivedMessages: Message[];
|
|
24
|
+
controller: AbortController;
|
|
25
|
+
constructor();
|
|
26
|
+
get response(): Response | null | undefined;
|
|
27
|
+
get request_id(): string | null | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Returns the `MessageStream` data, the raw `Response` instance and the ID of the request,
|
|
30
|
+
* returned vie the `request-id` header which is useful for debugging requests and resporting
|
|
31
|
+
* issues to Anthropic.
|
|
32
|
+
*
|
|
33
|
+
* This is the same as the `APIPromise.withResponse()` method.
|
|
34
|
+
*
|
|
35
|
+
* This method will raise an error if you created the stream using `MessageStream.fromReadableStream`
|
|
36
|
+
* as no `Response` is available.
|
|
37
|
+
*/
|
|
38
|
+
withResponse(): Promise<{
|
|
39
|
+
data: MessageStream;
|
|
40
|
+
response: Response;
|
|
41
|
+
request_id: string | null | undefined;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Intended for use on the frontend, consuming a stream produced with
|
|
45
|
+
* `.toReadableStream()` on the backend.
|
|
46
|
+
*
|
|
47
|
+
* Note that messages sent to the model do not appear in `.on('message')`
|
|
48
|
+
* in this context.
|
|
49
|
+
*/
|
|
50
|
+
static fromReadableStream(stream: ReadableStream): MessageStream;
|
|
51
|
+
static createMessage(messages: Messages, params: MessageCreateParamsBase, options?: Core.RequestOptions): MessageStream;
|
|
52
|
+
protected _run(executor: () => Promise<any>): void;
|
|
53
|
+
protected _addMessageParam(message: MessageParam): void;
|
|
54
|
+
protected _addMessage(message: Message, emit?: boolean): void;
|
|
55
|
+
protected _createMessage(messages: Messages, params: MessageCreateParams, options?: Core.RequestOptions): Promise<void>;
|
|
56
|
+
protected _connected(response: Response | null): void;
|
|
57
|
+
get ended(): boolean;
|
|
58
|
+
get errored(): boolean;
|
|
59
|
+
get aborted(): boolean;
|
|
60
|
+
abort(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Adds the listener function to the end of the listeners array for the event.
|
|
63
|
+
* No checks are made to see if the listener has already been added. Multiple calls passing
|
|
64
|
+
* the same combination of event and listener will result in the listener being added, and
|
|
65
|
+
* called, multiple times.
|
|
66
|
+
* @returns this MessageStream, so that calls can be chained
|
|
67
|
+
*/
|
|
68
|
+
on<Event extends keyof MessageStreamEvents>(event: Event, listener: MessageStreamEvents[Event]): this;
|
|
69
|
+
/**
|
|
70
|
+
* Removes the specified listener from the listener array for the event.
|
|
71
|
+
* off() will remove, at most, one instance of a listener from the listener array. If any single
|
|
72
|
+
* listener has been added multiple times to the listener array for the specified event, then
|
|
73
|
+
* off() must be called multiple times to remove each instance.
|
|
74
|
+
* @returns this MessageStream, so that calls can be chained
|
|
75
|
+
*/
|
|
76
|
+
off<Event extends keyof MessageStreamEvents>(event: Event, listener: MessageStreamEvents[Event]): this;
|
|
77
|
+
/**
|
|
78
|
+
* Adds a one-time listener function for the event. The next time the event is triggered,
|
|
79
|
+
* this listener is removed and then invoked.
|
|
80
|
+
* @returns this MessageStream, so that calls can be chained
|
|
81
|
+
*/
|
|
82
|
+
once<Event extends keyof MessageStreamEvents>(event: Event, listener: MessageStreamEvents[Event]): this;
|
|
83
|
+
/**
|
|
84
|
+
* This is similar to `.once()`, but returns a Promise that resolves the next time
|
|
85
|
+
* the event is triggered, instead of calling a listener callback.
|
|
86
|
+
* @returns a Promise that resolves the next time given event is triggered,
|
|
87
|
+
* or rejects if an error is emitted. (If you request the 'error' event,
|
|
88
|
+
* returns a promise that resolves with the error).
|
|
89
|
+
*
|
|
90
|
+
* Example:
|
|
91
|
+
*
|
|
92
|
+
* const message = await stream.emitted('message') // rejects if the stream errors
|
|
93
|
+
*/
|
|
94
|
+
emitted<Event extends keyof MessageStreamEvents>(event: Event): Promise<Parameters<MessageStreamEvents[Event]> extends [infer Param] ? Param : Parameters<MessageStreamEvents[Event]> extends [] ? void : Parameters<MessageStreamEvents[Event]>>;
|
|
95
|
+
done(): Promise<void>;
|
|
96
|
+
get currentMessage(): Message | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* @returns a promise that resolves with the the final assistant Message response,
|
|
99
|
+
* or rejects if an error occurred or the stream ended prematurely without producing a Message.
|
|
100
|
+
*/
|
|
101
|
+
finalMessage(): Promise<Message>;
|
|
102
|
+
/**
|
|
103
|
+
* @returns a promise that resolves with the the final assistant Message's text response, concatenated
|
|
104
|
+
* together if there are more than one text blocks.
|
|
105
|
+
* Rejects if an error occurred or the stream ended prematurely without producing a Message.
|
|
106
|
+
*/
|
|
107
|
+
finalText(): Promise<string>;
|
|
108
|
+
protected _emit<Event extends keyof MessageStreamEvents>(event: Event, ...args: Parameters<MessageStreamEvents[Event]>): void;
|
|
109
|
+
protected _emitFinal(): void;
|
|
110
|
+
protected _fromReadableStream(readableStream: ReadableStream, options?: Core.RequestOptions): Promise<void>;
|
|
111
|
+
[Symbol.asyncIterator](): AsyncIterator<MessageStreamEvent>;
|
|
112
|
+
toReadableStream(): ReadableStream;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=MessageStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageStream.d.ts","sourceRoot":"","sources":["../src/lib/MessageStream.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _MessageStream_instances, _MessageStream_currentMessageSnapshot, _MessageStream_connectedPromise, _MessageStream_resolveConnectedPromise, _MessageStream_rejectConnectedPromise, _MessageStream_endPromise, _MessageStream_resolveEndPromise, _MessageStream_rejectEndPromise, _MessageStream_listeners, _MessageStream_ended, _MessageStream_errored, _MessageStream_aborted, _MessageStream_catchingPromiseCreated, _MessageStream_response, _MessageStream_request_id, _MessageStream_getFinalMessage, _MessageStream_getFinalText, _MessageStream_handleError, _MessageStream_beginRequest, _MessageStream_addStreamEvent, _MessageStream_endRequest, _MessageStream_accumulateMessage;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MessageStream = void 0;
|
|
16
|
+
const error_1 = require("@anthropic-ai/sdk/error");
|
|
17
|
+
const streaming_1 = require("@anthropic-ai/sdk/streaming");
|
|
18
|
+
const parser_1 = require("../_vendor/partial-json-parser/parser.js");
|
|
19
|
+
const JSON_BUF_PROPERTY = '__json_buf';
|
|
20
|
+
class MessageStream {
|
|
21
|
+
constructor() {
|
|
22
|
+
_MessageStream_instances.add(this);
|
|
23
|
+
this.messages = [];
|
|
24
|
+
this.receivedMessages = [];
|
|
25
|
+
_MessageStream_currentMessageSnapshot.set(this, void 0);
|
|
26
|
+
this.controller = new AbortController();
|
|
27
|
+
_MessageStream_connectedPromise.set(this, void 0);
|
|
28
|
+
_MessageStream_resolveConnectedPromise.set(this, () => { });
|
|
29
|
+
_MessageStream_rejectConnectedPromise.set(this, () => { });
|
|
30
|
+
_MessageStream_endPromise.set(this, void 0);
|
|
31
|
+
_MessageStream_resolveEndPromise.set(this, () => { });
|
|
32
|
+
_MessageStream_rejectEndPromise.set(this, () => { });
|
|
33
|
+
_MessageStream_listeners.set(this, {});
|
|
34
|
+
_MessageStream_ended.set(this, false);
|
|
35
|
+
_MessageStream_errored.set(this, false);
|
|
36
|
+
_MessageStream_aborted.set(this, false);
|
|
37
|
+
_MessageStream_catchingPromiseCreated.set(this, false);
|
|
38
|
+
_MessageStream_response.set(this, void 0);
|
|
39
|
+
_MessageStream_request_id.set(this, void 0);
|
|
40
|
+
_MessageStream_handleError.set(this, (error) => {
|
|
41
|
+
__classPrivateFieldSet(this, _MessageStream_errored, true, "f");
|
|
42
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
43
|
+
error = new error_1.APIUserAbortError();
|
|
44
|
+
}
|
|
45
|
+
if (error instanceof error_1.APIUserAbortError) {
|
|
46
|
+
__classPrivateFieldSet(this, _MessageStream_aborted, true, "f");
|
|
47
|
+
return this._emit('abort', error);
|
|
48
|
+
}
|
|
49
|
+
if (error instanceof error_1.AnthropicError) {
|
|
50
|
+
return this._emit('error', error);
|
|
51
|
+
}
|
|
52
|
+
if (error instanceof Error) {
|
|
53
|
+
const anthropicError = new error_1.AnthropicError(error.message);
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
anthropicError.cause = error;
|
|
56
|
+
return this._emit('error', anthropicError);
|
|
57
|
+
}
|
|
58
|
+
return this._emit('error', new error_1.AnthropicError(String(error)));
|
|
59
|
+
});
|
|
60
|
+
__classPrivateFieldSet(this, _MessageStream_connectedPromise, new Promise((resolve, reject) => {
|
|
61
|
+
__classPrivateFieldSet(this, _MessageStream_resolveConnectedPromise, resolve, "f");
|
|
62
|
+
__classPrivateFieldSet(this, _MessageStream_rejectConnectedPromise, reject, "f");
|
|
63
|
+
}), "f");
|
|
64
|
+
__classPrivateFieldSet(this, _MessageStream_endPromise, new Promise((resolve, reject) => {
|
|
65
|
+
__classPrivateFieldSet(this, _MessageStream_resolveEndPromise, resolve, "f");
|
|
66
|
+
__classPrivateFieldSet(this, _MessageStream_rejectEndPromise, reject, "f");
|
|
67
|
+
}), "f");
|
|
68
|
+
// Don't let these promises cause unhandled rejection errors.
|
|
69
|
+
// we will manually cause an unhandled rejection error later
|
|
70
|
+
// if the user hasn't registered any error listener or called
|
|
71
|
+
// any promise-returning method.
|
|
72
|
+
__classPrivateFieldGet(this, _MessageStream_connectedPromise, "f").catch(() => { });
|
|
73
|
+
__classPrivateFieldGet(this, _MessageStream_endPromise, "f").catch(() => { });
|
|
74
|
+
}
|
|
75
|
+
get response() {
|
|
76
|
+
return __classPrivateFieldGet(this, _MessageStream_response, "f");
|
|
77
|
+
}
|
|
78
|
+
get request_id() {
|
|
79
|
+
return __classPrivateFieldGet(this, _MessageStream_request_id, "f");
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns the `MessageStream` data, the raw `Response` instance and the ID of the request,
|
|
83
|
+
* returned vie the `request-id` header which is useful for debugging requests and resporting
|
|
84
|
+
* issues to Anthropic.
|
|
85
|
+
*
|
|
86
|
+
* This is the same as the `APIPromise.withResponse()` method.
|
|
87
|
+
*
|
|
88
|
+
* This method will raise an error if you created the stream using `MessageStream.fromReadableStream`
|
|
89
|
+
* as no `Response` is available.
|
|
90
|
+
*/
|
|
91
|
+
async withResponse() {
|
|
92
|
+
const response = await __classPrivateFieldGet(this, _MessageStream_connectedPromise, "f");
|
|
93
|
+
if (!response) {
|
|
94
|
+
throw new Error('Could not resolve a `Response` object');
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
data: this,
|
|
98
|
+
response,
|
|
99
|
+
request_id: response.headers.get('request-id'),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Intended for use on the frontend, consuming a stream produced with
|
|
104
|
+
* `.toReadableStream()` on the backend.
|
|
105
|
+
*
|
|
106
|
+
* Note that messages sent to the model do not appear in `.on('message')`
|
|
107
|
+
* in this context.
|
|
108
|
+
*/
|
|
109
|
+
static fromReadableStream(stream) {
|
|
110
|
+
const runner = new MessageStream();
|
|
111
|
+
runner._run(() => runner._fromReadableStream(stream));
|
|
112
|
+
return runner;
|
|
113
|
+
}
|
|
114
|
+
static createMessage(messages, params, options) {
|
|
115
|
+
const runner = new MessageStream();
|
|
116
|
+
for (const message of params.messages) {
|
|
117
|
+
runner._addMessageParam(message);
|
|
118
|
+
}
|
|
119
|
+
runner._run(() => runner._createMessage(messages, { ...params, stream: true }, { ...options, headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' } }));
|
|
120
|
+
return runner;
|
|
121
|
+
}
|
|
122
|
+
_run(executor) {
|
|
123
|
+
executor().then(() => {
|
|
124
|
+
this._emitFinal();
|
|
125
|
+
this._emit('end');
|
|
126
|
+
}, __classPrivateFieldGet(this, _MessageStream_handleError, "f"));
|
|
127
|
+
}
|
|
128
|
+
_addMessageParam(message) {
|
|
129
|
+
this.messages.push(message);
|
|
130
|
+
}
|
|
131
|
+
_addMessage(message, emit = true) {
|
|
132
|
+
this.receivedMessages.push(message);
|
|
133
|
+
if (emit) {
|
|
134
|
+
this._emit('message', message);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async _createMessage(messages, params, options) {
|
|
138
|
+
const signal = options?.signal;
|
|
139
|
+
if (signal) {
|
|
140
|
+
if (signal.aborted)
|
|
141
|
+
this.controller.abort();
|
|
142
|
+
signal.addEventListener('abort', () => this.controller.abort());
|
|
143
|
+
}
|
|
144
|
+
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_beginRequest).call(this);
|
|
145
|
+
const { response, data: stream } = await messages
|
|
146
|
+
.create({ ...params, stream: true }, { ...options, signal: this.controller.signal })
|
|
147
|
+
.withResponse();
|
|
148
|
+
this._connected(response);
|
|
149
|
+
for await (const event of stream) {
|
|
150
|
+
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_addStreamEvent).call(this, event);
|
|
151
|
+
}
|
|
152
|
+
if (stream.controller.signal?.aborted) {
|
|
153
|
+
throw new error_1.APIUserAbortError();
|
|
154
|
+
}
|
|
155
|
+
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_endRequest).call(this);
|
|
156
|
+
}
|
|
157
|
+
_connected(response) {
|
|
158
|
+
if (this.ended)
|
|
159
|
+
return;
|
|
160
|
+
__classPrivateFieldSet(this, _MessageStream_response, response, "f");
|
|
161
|
+
__classPrivateFieldSet(this, _MessageStream_request_id, response?.headers.get('request-id'), "f");
|
|
162
|
+
__classPrivateFieldGet(this, _MessageStream_resolveConnectedPromise, "f").call(this, response);
|
|
163
|
+
this._emit('connect');
|
|
164
|
+
}
|
|
165
|
+
get ended() {
|
|
166
|
+
return __classPrivateFieldGet(this, _MessageStream_ended, "f");
|
|
167
|
+
}
|
|
168
|
+
get errored() {
|
|
169
|
+
return __classPrivateFieldGet(this, _MessageStream_errored, "f");
|
|
170
|
+
}
|
|
171
|
+
get aborted() {
|
|
172
|
+
return __classPrivateFieldGet(this, _MessageStream_aborted, "f");
|
|
173
|
+
}
|
|
174
|
+
abort() {
|
|
175
|
+
this.controller.abort();
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Adds the listener function to the end of the listeners array for the event.
|
|
179
|
+
* No checks are made to see if the listener has already been added. Multiple calls passing
|
|
180
|
+
* the same combination of event and listener will result in the listener being added, and
|
|
181
|
+
* called, multiple times.
|
|
182
|
+
* @returns this MessageStream, so that calls can be chained
|
|
183
|
+
*/
|
|
184
|
+
on(event, listener) {
|
|
185
|
+
const listeners = __classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] || (__classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] = []);
|
|
186
|
+
listeners.push({ listener });
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Removes the specified listener from the listener array for the event.
|
|
191
|
+
* off() will remove, at most, one instance of a listener from the listener array. If any single
|
|
192
|
+
* listener has been added multiple times to the listener array for the specified event, then
|
|
193
|
+
* off() must be called multiple times to remove each instance.
|
|
194
|
+
* @returns this MessageStream, so that calls can be chained
|
|
195
|
+
*/
|
|
196
|
+
off(event, listener) {
|
|
197
|
+
const listeners = __classPrivateFieldGet(this, _MessageStream_listeners, "f")[event];
|
|
198
|
+
if (!listeners)
|
|
199
|
+
return this;
|
|
200
|
+
const index = listeners.findIndex((l) => l.listener === listener);
|
|
201
|
+
if (index >= 0)
|
|
202
|
+
listeners.splice(index, 1);
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Adds a one-time listener function for the event. The next time the event is triggered,
|
|
207
|
+
* this listener is removed and then invoked.
|
|
208
|
+
* @returns this MessageStream, so that calls can be chained
|
|
209
|
+
*/
|
|
210
|
+
once(event, listener) {
|
|
211
|
+
const listeners = __classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] || (__classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] = []);
|
|
212
|
+
listeners.push({ listener, once: true });
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* This is similar to `.once()`, but returns a Promise that resolves the next time
|
|
217
|
+
* the event is triggered, instead of calling a listener callback.
|
|
218
|
+
* @returns a Promise that resolves the next time given event is triggered,
|
|
219
|
+
* or rejects if an error is emitted. (If you request the 'error' event,
|
|
220
|
+
* returns a promise that resolves with the error).
|
|
221
|
+
*
|
|
222
|
+
* Example:
|
|
223
|
+
*
|
|
224
|
+
* const message = await stream.emitted('message') // rejects if the stream errors
|
|
225
|
+
*/
|
|
226
|
+
emitted(event) {
|
|
227
|
+
return new Promise((resolve, reject) => {
|
|
228
|
+
__classPrivateFieldSet(this, _MessageStream_catchingPromiseCreated, true, "f");
|
|
229
|
+
if (event !== 'error')
|
|
230
|
+
this.once('error', reject);
|
|
231
|
+
this.once(event, resolve);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
async done() {
|
|
235
|
+
__classPrivateFieldSet(this, _MessageStream_catchingPromiseCreated, true, "f");
|
|
236
|
+
await __classPrivateFieldGet(this, _MessageStream_endPromise, "f");
|
|
237
|
+
}
|
|
238
|
+
get currentMessage() {
|
|
239
|
+
return __classPrivateFieldGet(this, _MessageStream_currentMessageSnapshot, "f");
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* @returns a promise that resolves with the the final assistant Message response,
|
|
243
|
+
* or rejects if an error occurred or the stream ended prematurely without producing a Message.
|
|
244
|
+
*/
|
|
245
|
+
async finalMessage() {
|
|
246
|
+
await this.done();
|
|
247
|
+
return __classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_getFinalMessage).call(this);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* @returns a promise that resolves with the the final assistant Message's text response, concatenated
|
|
251
|
+
* together if there are more than one text blocks.
|
|
252
|
+
* Rejects if an error occurred or the stream ended prematurely without producing a Message.
|
|
253
|
+
*/
|
|
254
|
+
async finalText() {
|
|
255
|
+
await this.done();
|
|
256
|
+
return __classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_getFinalText).call(this);
|
|
257
|
+
}
|
|
258
|
+
_emit(event, ...args) {
|
|
259
|
+
// make sure we don't emit any MessageStreamEvents after end
|
|
260
|
+
if (__classPrivateFieldGet(this, _MessageStream_ended, "f"))
|
|
261
|
+
return;
|
|
262
|
+
if (event === 'end') {
|
|
263
|
+
__classPrivateFieldSet(this, _MessageStream_ended, true, "f");
|
|
264
|
+
__classPrivateFieldGet(this, _MessageStream_resolveEndPromise, "f").call(this);
|
|
265
|
+
}
|
|
266
|
+
const listeners = __classPrivateFieldGet(this, _MessageStream_listeners, "f")[event];
|
|
267
|
+
if (listeners) {
|
|
268
|
+
__classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] = listeners.filter((l) => !l.once);
|
|
269
|
+
listeners.forEach(({ listener }) => listener(...args));
|
|
270
|
+
}
|
|
271
|
+
if (event === 'abort') {
|
|
272
|
+
const error = args[0];
|
|
273
|
+
if (!__classPrivateFieldGet(this, _MessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
274
|
+
Promise.reject(error);
|
|
275
|
+
}
|
|
276
|
+
__classPrivateFieldGet(this, _MessageStream_rejectConnectedPromise, "f").call(this, error);
|
|
277
|
+
__classPrivateFieldGet(this, _MessageStream_rejectEndPromise, "f").call(this, error);
|
|
278
|
+
this._emit('end');
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (event === 'error') {
|
|
282
|
+
// NOTE: _emit('error', error) should only be called from #handleError().
|
|
283
|
+
const error = args[0];
|
|
284
|
+
if (!__classPrivateFieldGet(this, _MessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
|
285
|
+
// Trigger an unhandled rejection if the user hasn't registered any error handlers.
|
|
286
|
+
// If you are seeing stack traces here, make sure to handle errors via either:
|
|
287
|
+
// - runner.on('error', () => ...)
|
|
288
|
+
// - await runner.done()
|
|
289
|
+
// - await runner.final...()
|
|
290
|
+
// - etc.
|
|
291
|
+
Promise.reject(error);
|
|
292
|
+
}
|
|
293
|
+
__classPrivateFieldGet(this, _MessageStream_rejectConnectedPromise, "f").call(this, error);
|
|
294
|
+
__classPrivateFieldGet(this, _MessageStream_rejectEndPromise, "f").call(this, error);
|
|
295
|
+
this._emit('end');
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
_emitFinal() {
|
|
299
|
+
const finalMessage = this.receivedMessages.at(-1);
|
|
300
|
+
if (finalMessage) {
|
|
301
|
+
this._emit('finalMessage', __classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_getFinalMessage).call(this));
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
async _fromReadableStream(readableStream, options) {
|
|
305
|
+
const signal = options?.signal;
|
|
306
|
+
if (signal) {
|
|
307
|
+
if (signal.aborted)
|
|
308
|
+
this.controller.abort();
|
|
309
|
+
signal.addEventListener('abort', () => this.controller.abort());
|
|
310
|
+
}
|
|
311
|
+
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_beginRequest).call(this);
|
|
312
|
+
this._connected(null);
|
|
313
|
+
const stream = streaming_1.Stream.fromReadableStream(readableStream, this.controller);
|
|
314
|
+
for await (const event of stream) {
|
|
315
|
+
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_addStreamEvent).call(this, event);
|
|
316
|
+
}
|
|
317
|
+
if (stream.controller.signal?.aborted) {
|
|
318
|
+
throw new error_1.APIUserAbortError();
|
|
319
|
+
}
|
|
320
|
+
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_endRequest).call(this);
|
|
321
|
+
}
|
|
322
|
+
[(_MessageStream_currentMessageSnapshot = new WeakMap(), _MessageStream_connectedPromise = new WeakMap(), _MessageStream_resolveConnectedPromise = new WeakMap(), _MessageStream_rejectConnectedPromise = new WeakMap(), _MessageStream_endPromise = new WeakMap(), _MessageStream_resolveEndPromise = new WeakMap(), _MessageStream_rejectEndPromise = new WeakMap(), _MessageStream_listeners = new WeakMap(), _MessageStream_ended = new WeakMap(), _MessageStream_errored = new WeakMap(), _MessageStream_aborted = new WeakMap(), _MessageStream_catchingPromiseCreated = new WeakMap(), _MessageStream_response = new WeakMap(), _MessageStream_request_id = new WeakMap(), _MessageStream_handleError = new WeakMap(), _MessageStream_instances = new WeakSet(), _MessageStream_getFinalMessage = function _MessageStream_getFinalMessage() {
|
|
323
|
+
if (this.receivedMessages.length === 0) {
|
|
324
|
+
throw new error_1.AnthropicError('stream ended without producing a Message with role=assistant');
|
|
325
|
+
}
|
|
326
|
+
return this.receivedMessages.at(-1);
|
|
327
|
+
}, _MessageStream_getFinalText = function _MessageStream_getFinalText() {
|
|
328
|
+
if (this.receivedMessages.length === 0) {
|
|
329
|
+
throw new error_1.AnthropicError('stream ended without producing a Message with role=assistant');
|
|
330
|
+
}
|
|
331
|
+
const textBlocks = this.receivedMessages
|
|
332
|
+
.at(-1)
|
|
333
|
+
.content.filter((block) => block.type === 'text')
|
|
334
|
+
.map((block) => block.text);
|
|
335
|
+
if (textBlocks.length === 0) {
|
|
336
|
+
throw new error_1.AnthropicError('stream ended without producing a content block with type=text');
|
|
337
|
+
}
|
|
338
|
+
return textBlocks.join(' ');
|
|
339
|
+
}, _MessageStream_beginRequest = function _MessageStream_beginRequest() {
|
|
340
|
+
if (this.ended)
|
|
341
|
+
return;
|
|
342
|
+
__classPrivateFieldSet(this, _MessageStream_currentMessageSnapshot, undefined, "f");
|
|
343
|
+
}, _MessageStream_addStreamEvent = function _MessageStream_addStreamEvent(event) {
|
|
344
|
+
if (this.ended)
|
|
345
|
+
return;
|
|
346
|
+
const messageSnapshot = __classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_accumulateMessage).call(this, event);
|
|
347
|
+
this._emit('streamEvent', event, messageSnapshot);
|
|
348
|
+
switch (event.type) {
|
|
349
|
+
case 'content_block_delta': {
|
|
350
|
+
const content = messageSnapshot.content.at(-1);
|
|
351
|
+
switch (event.delta.type) {
|
|
352
|
+
case 'text_delta': {
|
|
353
|
+
if (content.type === 'text') {
|
|
354
|
+
this._emit('text', event.delta.text, content.text || '');
|
|
355
|
+
}
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
case 'citations_delta': {
|
|
359
|
+
if (content.type === 'text') {
|
|
360
|
+
this._emit('citation', event.delta.citation, content.citations ?? []);
|
|
361
|
+
}
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
case 'input_json_delta': {
|
|
365
|
+
if (content.type === 'tool_use' && content.input) {
|
|
366
|
+
this._emit('inputJson', event.delta.partial_json, content.input);
|
|
367
|
+
}
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
case 'thinking_delta': {
|
|
371
|
+
if (content.type === 'thinking') {
|
|
372
|
+
this._emit('thinking', event.delta.thinking, content.thinking);
|
|
373
|
+
}
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
case 'signature_delta': {
|
|
377
|
+
// we don't emit anything special in this case.
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
default:
|
|
381
|
+
checkNever(event.delta);
|
|
382
|
+
}
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
case 'message_stop': {
|
|
386
|
+
this._addMessageParam(messageSnapshot);
|
|
387
|
+
this._addMessage(messageSnapshot, true);
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
case 'content_block_stop': {
|
|
391
|
+
this._emit('contentBlock', messageSnapshot.content.at(-1));
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
case 'message_start': {
|
|
395
|
+
__classPrivateFieldSet(this, _MessageStream_currentMessageSnapshot, messageSnapshot, "f");
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
case 'content_block_start':
|
|
399
|
+
case 'message_delta':
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
}, _MessageStream_endRequest = function _MessageStream_endRequest() {
|
|
403
|
+
if (this.ended) {
|
|
404
|
+
throw new error_1.AnthropicError(`stream has ended, this shouldn't happen`);
|
|
405
|
+
}
|
|
406
|
+
const snapshot = __classPrivateFieldGet(this, _MessageStream_currentMessageSnapshot, "f");
|
|
407
|
+
if (!snapshot) {
|
|
408
|
+
throw new error_1.AnthropicError(`request ended without sending any chunks`);
|
|
409
|
+
}
|
|
410
|
+
__classPrivateFieldSet(this, _MessageStream_currentMessageSnapshot, undefined, "f");
|
|
411
|
+
return snapshot;
|
|
412
|
+
}, _MessageStream_accumulateMessage = function _MessageStream_accumulateMessage(event) {
|
|
413
|
+
let snapshot = __classPrivateFieldGet(this, _MessageStream_currentMessageSnapshot, "f");
|
|
414
|
+
if (event.type === 'message_start') {
|
|
415
|
+
if (snapshot) {
|
|
416
|
+
throw new error_1.AnthropicError(`Unexpected event order, got ${event.type} before receiving "message_stop"`);
|
|
417
|
+
}
|
|
418
|
+
return event.message;
|
|
419
|
+
}
|
|
420
|
+
if (!snapshot) {
|
|
421
|
+
throw new error_1.AnthropicError(`Unexpected event order, got ${event.type} before "message_start"`);
|
|
422
|
+
}
|
|
423
|
+
switch (event.type) {
|
|
424
|
+
case 'message_stop':
|
|
425
|
+
return snapshot;
|
|
426
|
+
case 'message_delta':
|
|
427
|
+
snapshot.stop_reason = event.delta.stop_reason;
|
|
428
|
+
snapshot.stop_sequence = event.delta.stop_sequence;
|
|
429
|
+
snapshot.usage.output_tokens = event.usage.output_tokens;
|
|
430
|
+
return snapshot;
|
|
431
|
+
case 'content_block_start':
|
|
432
|
+
snapshot.content.push(event.content_block);
|
|
433
|
+
return snapshot;
|
|
434
|
+
case 'content_block_delta': {
|
|
435
|
+
const snapshotContent = snapshot.content.at(event.index);
|
|
436
|
+
switch (event.delta.type) {
|
|
437
|
+
case 'text_delta': {
|
|
438
|
+
if (snapshotContent?.type === 'text') {
|
|
439
|
+
snapshotContent.text += event.delta.text;
|
|
440
|
+
}
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
case 'citations_delta': {
|
|
444
|
+
if (snapshotContent?.type === 'text') {
|
|
445
|
+
snapshotContent.citations ?? (snapshotContent.citations = []);
|
|
446
|
+
snapshotContent.citations.push(event.delta.citation);
|
|
447
|
+
}
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
case 'input_json_delta': {
|
|
451
|
+
if (snapshotContent?.type === 'tool_use') {
|
|
452
|
+
// we need to keep track of the raw JSON string as well so that we can
|
|
453
|
+
// re-parse it for each delta, for now we just store it as an untyped
|
|
454
|
+
// non-enumerable property on the snapshot
|
|
455
|
+
let jsonBuf = snapshotContent[JSON_BUF_PROPERTY] || '';
|
|
456
|
+
jsonBuf += event.delta.partial_json;
|
|
457
|
+
Object.defineProperty(snapshotContent, JSON_BUF_PROPERTY, {
|
|
458
|
+
value: jsonBuf,
|
|
459
|
+
enumerable: false,
|
|
460
|
+
writable: true,
|
|
461
|
+
});
|
|
462
|
+
if (jsonBuf) {
|
|
463
|
+
snapshotContent.input = (0, parser_1.partialParse)(jsonBuf);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
case 'thinking_delta': {
|
|
469
|
+
if (snapshotContent?.type === 'thinking') {
|
|
470
|
+
snapshotContent.thinking += event.delta.thinking;
|
|
471
|
+
}
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
case 'signature_delta': {
|
|
475
|
+
if (snapshotContent?.type === 'thinking') {
|
|
476
|
+
snapshotContent.signature += event.delta.signature;
|
|
477
|
+
}
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
default:
|
|
481
|
+
checkNever(event.delta);
|
|
482
|
+
}
|
|
483
|
+
return snapshot;
|
|
484
|
+
}
|
|
485
|
+
case 'content_block_stop':
|
|
486
|
+
return snapshot;
|
|
487
|
+
}
|
|
488
|
+
}, Symbol.asyncIterator)]() {
|
|
489
|
+
const pushQueue = [];
|
|
490
|
+
const readQueue = [];
|
|
491
|
+
let done = false;
|
|
492
|
+
this.on('streamEvent', (event) => {
|
|
493
|
+
const reader = readQueue.shift();
|
|
494
|
+
if (reader) {
|
|
495
|
+
reader.resolve(event);
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
pushQueue.push(event);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
this.on('end', () => {
|
|
502
|
+
done = true;
|
|
503
|
+
for (const reader of readQueue) {
|
|
504
|
+
reader.resolve(undefined);
|
|
505
|
+
}
|
|
506
|
+
readQueue.length = 0;
|
|
507
|
+
});
|
|
508
|
+
this.on('abort', (err) => {
|
|
509
|
+
done = true;
|
|
510
|
+
for (const reader of readQueue) {
|
|
511
|
+
reader.reject(err);
|
|
512
|
+
}
|
|
513
|
+
readQueue.length = 0;
|
|
514
|
+
});
|
|
515
|
+
this.on('error', (err) => {
|
|
516
|
+
done = true;
|
|
517
|
+
for (const reader of readQueue) {
|
|
518
|
+
reader.reject(err);
|
|
519
|
+
}
|
|
520
|
+
readQueue.length = 0;
|
|
521
|
+
});
|
|
522
|
+
return {
|
|
523
|
+
next: async () => {
|
|
524
|
+
if (!pushQueue.length) {
|
|
525
|
+
if (done) {
|
|
526
|
+
return { value: undefined, done: true };
|
|
527
|
+
}
|
|
528
|
+
return new Promise((resolve, reject) => readQueue.push({ resolve, reject })).then((chunk) => (chunk ? { value: chunk, done: false } : { value: undefined, done: true }));
|
|
529
|
+
}
|
|
530
|
+
const chunk = pushQueue.shift();
|
|
531
|
+
return { value: chunk, done: false };
|
|
532
|
+
},
|
|
533
|
+
return: async () => {
|
|
534
|
+
this.abort();
|
|
535
|
+
return { value: undefined, done: true };
|
|
536
|
+
},
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
toReadableStream() {
|
|
540
|
+
const stream = new streaming_1.Stream(this[Symbol.asyncIterator].bind(this), this.controller);
|
|
541
|
+
return stream.toReadableStream();
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
exports.MessageStream = MessageStream;
|
|
545
|
+
// used to ensure exhaustive case matching without throwing a runtime error
|
|
546
|
+
function checkNever(x) { }
|
|
547
|
+
//# sourceMappingURL=MessageStream.js.map
|