openai 4.0.0-beta.0 → 4.0.0-beta.10
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/README.md +107 -52
- package/_shims/ReadableStream.d.ts +38 -0
- package/_shims/ReadableStream.js +5 -0
- package/_shims/ReadableStream.mjs +7 -0
- package/_shims/ReadableStream.node.d.ts +6 -0
- package/_shims/ReadableStream.node.d.ts.map +1 -0
- package/_shims/ReadableStream.node.js +14 -0
- package/_shims/ReadableStream.node.js.map +1 -0
- package/_shims/ReadableStream.node.mjs +3 -0
- package/_shims/ReadableStream.node.mjs.map +1 -0
- package/_shims/agent.d.ts +9 -0
- package/_shims/agent.d.ts.map +1 -0
- package/_shims/agent.js +14 -0
- package/_shims/agent.js.map +1 -0
- package/_shims/agent.mjs +10 -0
- package/_shims/agent.mjs.map +1 -0
- package/_shims/agent.node.d.ts +7 -0
- package/_shims/agent.node.d.ts.map +1 -0
- package/_shims/agent.node.js +28 -0
- package/_shims/agent.node.js.map +1 -0
- package/_shims/agent.node.mjs +16 -0
- package/_shims/agent.node.mjs.map +1 -0
- package/_shims/fetch.d.ts +59 -0
- package/_shims/fetch.js +13 -0
- package/_shims/fetch.mjs +15 -0
- package/_shims/fetch.node.d.ts +63 -0
- package/_shims/fetch.node.js +12 -0
- package/_shims/fetch.node.mjs +14 -0
- package/_shims/fileFromPath.d.ts +22 -0
- package/_shims/fileFromPath.d.ts.map +1 -0
- package/_shims/fileFromPath.js +16 -0
- package/_shims/fileFromPath.js.map +1 -0
- package/_shims/fileFromPath.mjs +12 -0
- package/_shims/fileFromPath.mjs.map +1 -0
- package/_shims/fileFromPath.node.d.ts +17 -0
- package/_shims/fileFromPath.node.d.ts.map +1 -0
- package/_shims/fileFromPath.node.js +17 -0
- package/_shims/fileFromPath.node.js.map +1 -0
- package/_shims/fileFromPath.node.mjs +13 -0
- package/_shims/fileFromPath.node.mjs.map +1 -0
- package/_shims/formdata.d.ts +43 -0
- package/_shims/formdata.js +9 -0
- package/_shims/formdata.mjs +11 -0
- package/_shims/formdata.node.d.ts +45 -0
- package/_shims/formdata.node.js +11 -0
- package/_shims/formdata.node.mjs +9 -0
- package/_shims/getMultipartRequestOptions.d.ts +10 -0
- package/_shims/getMultipartRequestOptions.d.ts.map +1 -0
- package/_shims/getMultipartRequestOptions.js +12 -0
- package/_shims/getMultipartRequestOptions.js.map +1 -0
- package/_shims/getMultipartRequestOptions.mjs +8 -0
- package/_shims/getMultipartRequestOptions.mjs.map +1 -0
- package/_shims/getMultipartRequestOptions.node.d.ts +10 -0
- package/_shims/getMultipartRequestOptions.node.d.ts.map +1 -0
- package/_shims/getMultipartRequestOptions.node.js +22 -0
- package/_shims/getMultipartRequestOptions.node.js.map +1 -0
- package/_shims/getMultipartRequestOptions.node.mjs +18 -0
- package/_shims/getMultipartRequestOptions.node.mjs.map +1 -0
- package/_shims/node-readable.d.ts +23 -0
- package/_shims/node-readable.d.ts.map +1 -0
- package/_shims/node-readable.js +11 -0
- package/_shims/node-readable.js.map +1 -0
- package/_shims/node-readable.mjs +7 -0
- package/_shims/node-readable.mjs.map +1 -0
- package/_shims/node-readable.node.d.ts +8 -0
- package/_shims/node-readable.node.d.ts.map +1 -0
- package/_shims/node-readable.node.js +9 -0
- package/_shims/node-readable.node.js.map +1 -0
- package/_shims/node-readable.node.mjs +5 -0
- package/_shims/node-readable.node.mjs.map +1 -0
- package/bin/cli +21 -0
- package/{dist/cjs/core.d.ts → core.d.ts} +108 -57
- package/core.d.ts.map +1 -0
- package/core.js +858 -0
- package/core.js.map +1 -0
- package/core.mjs +786 -0
- package/core.mjs.map +1 -0
- package/{dist/cjs/error.d.ts → error.d.ts} +6 -1
- package/error.d.ts.map +1 -0
- package/{dist/cjs/error.js → error.js} +23 -7
- package/error.js.map +1 -0
- package/error.mjs +120 -0
- package/error.mjs.map +1 -0
- package/index.d.mts +163 -0
- package/index.d.ts +163 -0
- package/index.d.ts.map +1 -0
- package/{dist/cjs/index.js → index.js} +62 -21
- package/index.js.map +1 -0
- package/index.mjs +118 -0
- package/index.mjs.map +1 -0
- package/package.json +60 -24
- package/pagination.d.ts +21 -0
- package/pagination.d.ts.map +1 -0
- package/pagination.js +31 -0
- package/pagination.js.map +1 -0
- package/pagination.mjs +27 -0
- package/pagination.mjs.map +1 -0
- package/{dist/cjs/resource.d.ts → resource.d.ts} +1 -1
- package/resource.d.ts.map +1 -0
- package/resource.js.map +1 -0
- package/resource.mjs +13 -0
- package/resource.mjs.map +1 -0
- package/resources/audio/audio.d.ts +17 -0
- package/resources/audio/audio.d.ts.map +1 -0
- package/resources/audio/audio.js +61 -0
- package/resources/audio/audio.js.map +1 -0
- package/resources/audio/audio.mjs +17 -0
- package/resources/audio/audio.mjs.map +1 -0
- package/resources/audio/index.d.ts +4 -0
- package/resources/audio/index.d.ts.map +1 -0
- package/resources/audio/index.js +26 -0
- package/resources/audio/index.js.map +1 -0
- package/resources/audio/index.mjs +5 -0
- package/resources/audio/index.mjs.map +1 -0
- package/{dist/cjs/resources → resources}/audio/transcriptions.d.ts +12 -10
- package/resources/audio/transcriptions.d.ts.map +1 -0
- package/{dist/cjs/resources → resources}/audio/transcriptions.js +4 -6
- package/resources/audio/transcriptions.js.map +1 -0
- package/resources/audio/transcriptions.mjs +13 -0
- package/resources/audio/transcriptions.mjs.map +1 -0
- package/{dist/cjs/resources → resources}/audio/translations.d.ts +12 -10
- package/resources/audio/translations.d.ts.map +1 -0
- package/{dist/cjs/resources → resources}/audio/translations.js +5 -7
- package/resources/audio/translations.js.map +1 -0
- package/resources/audio/translations.mjs +13 -0
- package/resources/audio/translations.mjs.map +1 -0
- package/resources/chat/chat.d.ts +17 -0
- package/resources/chat/chat.d.ts.map +1 -0
- package/resources/chat/chat.js +58 -0
- package/resources/chat/chat.js.map +1 -0
- package/resources/chat/chat.mjs +14 -0
- package/resources/chat/chat.mjs.map +1 -0
- package/resources/chat/completions.d.ts +338 -0
- package/resources/chat/completions.d.ts.map +1 -0
- package/{dist/cjs/resources → resources/chat}/completions.js +7 -7
- package/resources/chat/completions.js.map +1 -0
- package/resources/chat/completions.mjs +14 -0
- package/resources/chat/completions.mjs.map +1 -0
- package/resources/chat/index.d.ts +12 -0
- package/resources/chat/index.d.ts.map +1 -0
- package/resources/chat/index.js +19 -0
- package/resources/chat/index.js.map +1 -0
- package/resources/chat/index.mjs +4 -0
- package/resources/chat/index.mjs.map +1 -0
- package/resources/completions.d.ts +217 -0
- package/resources/completions.d.ts.map +1 -0
- package/{dist/cjs/resources/chat → resources}/completions.js +7 -7
- package/resources/completions.js.map +1 -0
- package/resources/completions.mjs +14 -0
- package/resources/completions.mjs.map +1 -0
- package/{dist/cjs/resources → resources}/edits.d.ts +18 -18
- package/resources/edits.d.ts.map +1 -0
- package/{dist/cjs/resources → resources}/edits.js +7 -2
- package/resources/edits.js.map +1 -0
- package/resources/edits.mjs +16 -0
- package/resources/edits.mjs.map +1 -0
- package/{dist/cjs/resources → resources}/embeddings.d.ts +9 -4
- package/resources/embeddings.d.ts.map +1 -0
- package/{dist/cjs/resources → resources}/embeddings.js +3 -2
- package/resources/embeddings.js.map +1 -0
- package/resources/embeddings.mjs +12 -0
- package/resources/embeddings.mjs.map +1 -0
- package/{dist/cjs/resources → resources}/files.d.ts +33 -24
- package/resources/files.d.ts.map +1 -0
- package/{dist/cjs/resources → resources}/files.js +19 -14
- package/resources/files.js.map +1 -0
- package/resources/files.mjs +51 -0
- package/resources/files.mjs.map +1 -0
- package/{dist/cjs/resources → resources}/fine-tunes.d.ts +87 -50
- package/resources/fine-tunes.d.ts.map +1 -0
- package/{dist/cjs/resources → resources}/fine-tunes.js +20 -13
- package/resources/fine-tunes.js.map +1 -0
- package/resources/fine-tunes.mjs +54 -0
- package/resources/fine-tunes.mjs.map +1 -0
- package/{dist/cjs/resources → resources}/images.d.ts +17 -12
- package/resources/images.d.ts.map +1 -0
- package/{dist/cjs/resources → resources}/images.js +6 -11
- package/resources/images.js.map +1 -0
- package/resources/images.mjs +25 -0
- package/resources/images.mjs.map +1 -0
- package/resources/index.d.ts +35 -0
- package/resources/index.d.ts.map +1 -0
- package/{dist/cjs/resources → resources}/index.js +38 -33
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +12 -0
- package/resources/index.mjs.map +1 -0
- package/resources/models.d.ts +43 -0
- package/resources/models.d.ts.map +1 -0
- package/{dist/cjs/resources → resources}/models.js +10 -3
- package/resources/models.js.map +1 -0
- package/resources/models.mjs +31 -0
- package/resources/models.mjs.map +1 -0
- package/{dist/cjs/resources → resources}/moderations.d.ts +10 -4
- package/resources/moderations.d.ts.map +1 -0
- package/{dist/cjs/resources → resources}/moderations.js +3 -2
- package/resources/moderations.js.map +1 -0
- package/resources/moderations.mjs +12 -0
- package/resources/moderations.mjs.map +1 -0
- package/src/_shims/ReadableStream.d.ts +38 -0
- package/src/_shims/ReadableStream.js +5 -0
- package/src/_shims/ReadableStream.mjs +7 -0
- package/src/_shims/ReadableStream.node.ts +6 -0
- package/src/_shims/agent.node.ts +22 -0
- package/src/_shims/agent.ts +12 -0
- package/src/_shims/fetch.d.ts +59 -0
- package/src/_shims/fetch.deno.ts +23 -0
- package/src/_shims/fetch.js +13 -0
- package/src/_shims/fetch.mjs +15 -0
- package/src/_shims/fetch.node.d.ts +63 -0
- package/src/_shims/fetch.node.js +12 -0
- package/src/_shims/fetch.node.mjs +14 -0
- package/src/_shims/fileFromPath.node.ts +29 -0
- package/src/_shims/fileFromPath.ts +29 -0
- package/src/_shims/formdata.d.ts +43 -0
- package/src/_shims/formdata.deno.ts +16 -0
- package/src/_shims/formdata.js +9 -0
- package/src/_shims/formdata.mjs +11 -0
- package/src/_shims/formdata.node.d.ts +45 -0
- package/src/_shims/formdata.node.js +11 -0
- package/src/_shims/formdata.node.mjs +9 -0
- package/src/_shims/getMultipartRequestOptions.node.ts +25 -0
- package/src/_shims/getMultipartRequestOptions.ts +14 -0
- package/src/_shims/node-readable.node.ts +10 -0
- package/src/_shims/node-readable.ts +30 -0
- package/{core.ts → src/core.ts} +420 -193
- package/{error.ts → src/error.ts} +22 -5
- package/src/index.ts +246 -0
- package/src/pagination.ts +42 -0
- package/src/resources/audio/audio.ts +21 -0
- package/src/resources/audio/index.ts +5 -0
- package/{resources → src/resources}/audio/transcriptions.ts +13 -11
- package/{resources → src/resources}/audio/translations.ts +13 -11
- package/src/resources/chat/chat.ts +20 -0
- package/src/resources/chat/completions.ts +406 -0
- package/src/resources/chat/index.ts +13 -0
- package/src/resources/completions.ts +264 -0
- package/{resources → src/resources}/edits.ts +19 -23
- package/{resources → src/resources}/embeddings.ts +10 -4
- package/{resources → src/resources}/files.ts +40 -31
- package/{resources → src/resources}/fine-tunes.ts +102 -56
- package/{resources → src/resources}/images.ts +18 -13
- package/{resources → src/resources}/index.ts +14 -14
- package/src/resources/models.ts +62 -0
- package/{resources → src/resources}/moderations.ts +11 -4
- package/{streaming.ts → src/streaming.ts} +146 -79
- package/src/uploads.ts +250 -0
- package/src/version.ts +1 -0
- package/{dist/cjs/streaming.d.ts → streaming.d.ts} +4 -7
- package/streaming.d.ts.map +1 -0
- package/streaming.js +218 -0
- package/streaming.js.map +1 -0
- package/streaming.mjs +214 -0
- package/streaming.mjs.map +1 -0
- package/uploads.d.ts +91 -0
- package/uploads.d.ts.map +1 -0
- package/uploads.js +208 -0
- package/uploads.js.map +1 -0
- package/uploads.mjs +175 -0
- package/uploads.mjs.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/{dist/cjs/version.js → version.js} +1 -1
- package/version.js.map +1 -0
- package/version.mjs +2 -0
- package/version.mjs.map +1 -0
- package/.eslintrc.js +0 -10
- package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -56
- package/.github/ISSUE_TEMPLATE/config.yml +0 -7
- package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -20
- package/.github/workflows/test.yml +0 -24
- package/.prettierignore +0 -1
- package/.prettierrc +0 -6
- package/.stats.yml +0 -1
- package/api.md +0 -157
- package/bin/check-test-server +0 -50
- package/build +0 -12
- package/check-version.ts +0 -18
- package/dist/cjs/check-version.d.ts +0 -2
- package/dist/cjs/check-version.d.ts.map +0 -1
- package/dist/cjs/check-version.js +0 -23
- package/dist/cjs/check-version.js.map +0 -1
- package/dist/cjs/core.d.ts.map +0 -1
- package/dist/cjs/core.js +0 -854
- package/dist/cjs/core.js.map +0 -1
- package/dist/cjs/error.d.ts.map +0 -1
- package/dist/cjs/error.js.map +0 -1
- package/dist/cjs/examples/demo.d.ts +0 -3
- package/dist/cjs/examples/demo.d.ts.map +0 -1
- package/dist/cjs/examples/demo.js +0 -119
- package/dist/cjs/examples/demo.js.map +0 -1
- package/dist/cjs/examples/errors.d.ts +0 -3
- package/dist/cjs/examples/errors.d.ts.map +0 -1
- package/dist/cjs/examples/errors.js +0 -100
- package/dist/cjs/examples/errors.js.map +0 -1
- package/dist/cjs/examples/fine-tunes.d.ts +0 -10
- package/dist/cjs/examples/fine-tunes.d.ts.map +0 -1
- package/dist/cjs/examples/fine-tunes.js +0 -160
- package/dist/cjs/examples/fine-tunes.js.map +0 -1
- package/dist/cjs/fetch-polyfill.d.ts +0 -6
- package/dist/cjs/fetch-polyfill.d.ts.map +0 -1
- package/dist/cjs/fetch-polyfill.js +0 -57
- package/dist/cjs/fetch-polyfill.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -100
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/resource.d.ts.map +0 -1
- package/dist/cjs/resource.js.map +0 -1
- package/dist/cjs/resources/answers.d.ts +0 -150
- package/dist/cjs/resources/answers.d.ts.map +0 -1
- package/dist/cjs/resources/answers.js +0 -20
- package/dist/cjs/resources/answers.js.map +0 -1
- package/dist/cjs/resources/audio/audio.d.ts +0 -8
- package/dist/cjs/resources/audio/audio.d.ts.map +0 -1
- package/dist/cjs/resources/audio/audio.js +0 -16
- package/dist/cjs/resources/audio/audio.js.map +0 -1
- package/dist/cjs/resources/audio/index.d.ts +0 -3
- package/dist/cjs/resources/audio/index.d.ts.map +0 -1
- package/dist/cjs/resources/audio/index.js +0 -4
- package/dist/cjs/resources/audio/index.js.map +0 -1
- package/dist/cjs/resources/audio/transcriptions.d.ts.map +0 -1
- package/dist/cjs/resources/audio/transcriptions.js.map +0 -1
- package/dist/cjs/resources/audio/translations.d.ts.map +0 -1
- package/dist/cjs/resources/audio/translations.js.map +0 -1
- package/dist/cjs/resources/chat/chat.d.ts +0 -6
- package/dist/cjs/resources/chat/chat.d.ts.map +0 -1
- package/dist/cjs/resources/chat/chat.js +0 -14
- package/dist/cjs/resources/chat/chat.js.map +0 -1
- package/dist/cjs/resources/chat/completions.d.ts +0 -472
- package/dist/cjs/resources/chat/completions.d.ts.map +0 -1
- package/dist/cjs/resources/chat/completions.js.map +0 -1
- package/dist/cjs/resources/chat/index.d.ts +0 -2
- package/dist/cjs/resources/chat/index.d.ts.map +0 -1
- package/dist/cjs/resources/chat/index.js +0 -4
- package/dist/cjs/resources/chat/index.js.map +0 -1
- package/dist/cjs/resources/classifications.d.ts +0 -142
- package/dist/cjs/resources/classifications.d.ts.map +0 -1
- package/dist/cjs/resources/classifications.js +0 -24
- package/dist/cjs/resources/classifications.js.map +0 -1
- package/dist/cjs/resources/completions.d.ts +0 -313
- package/dist/cjs/resources/completions.d.ts.map +0 -1
- package/dist/cjs/resources/completions.js.map +0 -1
- package/dist/cjs/resources/edits.d.ts.map +0 -1
- package/dist/cjs/resources/edits.js.map +0 -1
- package/dist/cjs/resources/embeddings.d.ts.map +0 -1
- package/dist/cjs/resources/embeddings.js.map +0 -1
- package/dist/cjs/resources/files.d.ts.map +0 -1
- package/dist/cjs/resources/files.js.map +0 -1
- package/dist/cjs/resources/fine-tunes.d.ts.map +0 -1
- package/dist/cjs/resources/fine-tunes.js.map +0 -1
- package/dist/cjs/resources/images.d.ts.map +0 -1
- package/dist/cjs/resources/images.js.map +0 -1
- package/dist/cjs/resources/index.d.ts +0 -35
- package/dist/cjs/resources/index.d.ts.map +0 -1
- package/dist/cjs/resources/index.js.map +0 -1
- package/dist/cjs/resources/models.d.ts +0 -34
- package/dist/cjs/resources/models.d.ts.map +0 -1
- package/dist/cjs/resources/models.js.map +0 -1
- package/dist/cjs/resources/moderations.d.ts.map +0 -1
- package/dist/cjs/resources/moderations.js.map +0 -1
- package/dist/cjs/streaming.d.ts.map +0 -1
- package/dist/cjs/streaming.js +0 -287
- package/dist/cjs/streaming.js.map +0 -1
- package/dist/cjs/tests/api-resources/answers.test.d.ts +0 -2
- package/dist/cjs/tests/api-resources/answers.test.d.ts.map +0 -1
- package/dist/cjs/tests/api-resources/answers.test.js +0 -279
- package/dist/cjs/tests/api-resources/answers.test.js.map +0 -1
- package/dist/cjs/tests/api-resources/audio/transcriptions.test.d.ts +0 -2
- package/dist/cjs/tests/api-resources/audio/transcriptions.test.d.ts.map +0 -1
- package/dist/cjs/tests/api-resources/audio/transcriptions.test.js +0 -65
- package/dist/cjs/tests/api-resources/audio/transcriptions.test.js.map +0 -1
- package/dist/cjs/tests/api-resources/audio/translations.test.d.ts +0 -2
- package/dist/cjs/tests/api-resources/audio/translations.test.d.ts.map +0 -1
- package/dist/cjs/tests/api-resources/audio/translations.test.js +0 -64
- package/dist/cjs/tests/api-resources/audio/translations.test.js.map +0 -1
- package/dist/cjs/tests/api-resources/chat/completions.test.d.ts +0 -2
- package/dist/cjs/tests/api-resources/chat/completions.test.d.ts.map +0 -1
- package/dist/cjs/tests/api-resources/chat/completions.test.js +0 -77
- package/dist/cjs/tests/api-resources/chat/completions.test.js.map +0 -1
- package/dist/cjs/tests/api-resources/classifications.test.d.ts +0 -2
- package/dist/cjs/tests/api-resources/classifications.test.d.ts.map +0 -1
- package/dist/cjs/tests/api-resources/classifications.test.js +0 -73
- package/dist/cjs/tests/api-resources/classifications.test.js.map +0 -1
- package/dist/cjs/tests/api-resources/completions.test.d.ts +0 -2
- package/dist/cjs/tests/api-resources/completions.test.d.ts.map +0 -1
- package/dist/cjs/tests/api-resources/completions.test.js +0 -69
- package/dist/cjs/tests/api-resources/completions.test.js.map +0 -1
- package/dist/cjs/tests/api-resources/edits.test.d.ts +0 -2
- package/dist/cjs/tests/api-resources/edits.test.d.ts.map +0 -1
- package/dist/cjs/tests/api-resources/edits.test.js +0 -62
- package/dist/cjs/tests/api-resources/edits.test.js.map +0 -1
- package/dist/cjs/tests/api-resources/embeddings.test.d.ts +0 -2
- package/dist/cjs/tests/api-resources/embeddings.test.d.ts.map +0 -1
- package/dist/cjs/tests/api-resources/embeddings.test.js +0 -59
- package/dist/cjs/tests/api-resources/embeddings.test.js.map +0 -1
- package/dist/cjs/tests/api-resources/files.test.d.ts +0 -2
- package/dist/cjs/tests/api-resources/files.test.d.ts.map +0 -1
- package/dist/cjs/tests/api-resources/files.test.js +0 -107
- package/dist/cjs/tests/api-resources/files.test.js.map +0 -1
- package/dist/cjs/tests/api-resources/fine-tunes.test.d.ts +0 -2
- package/dist/cjs/tests/api-resources/fine-tunes.test.d.ts.map +0 -1
- package/dist/cjs/tests/api-resources/fine-tunes.test.js +0 -115
- package/dist/cjs/tests/api-resources/fine-tunes.test.js.map +0 -1
- package/dist/cjs/tests/api-resources/images.test.d.ts +0 -2
- package/dist/cjs/tests/api-resources/images.test.d.ts.map +0 -1
- package/dist/cjs/tests/api-resources/images.test.js +0 -100
- package/dist/cjs/tests/api-resources/images.test.js.map +0 -1
- package/dist/cjs/tests/api-resources/models.test.d.ts +0 -2
- package/dist/cjs/tests/api-resources/models.test.d.ts.map +0 -1
- package/dist/cjs/tests/api-resources/models.test.js +0 -77
- package/dist/cjs/tests/api-resources/models.test.js.map +0 -1
- package/dist/cjs/tests/api-resources/moderations.test.d.ts +0 -2
- package/dist/cjs/tests/api-resources/moderations.test.d.ts.map +0 -1
- package/dist/cjs/tests/api-resources/moderations.test.js +0 -55
- package/dist/cjs/tests/api-resources/moderations.test.js.map +0 -1
- package/dist/cjs/tests/form.test.d.ts +0 -2
- package/dist/cjs/tests/form.test.d.ts.map +0 -1
- package/dist/cjs/tests/form.test.js +0 -61
- package/dist/cjs/tests/form.test.js.map +0 -1
- package/dist/cjs/tests/index.test.d.ts +0 -2
- package/dist/cjs/tests/index.test.d.ts.map +0 -1
- package/dist/cjs/tests/index.test.js +0 -75
- package/dist/cjs/tests/index.test.js.map +0 -1
- package/dist/cjs/tests/responses.test.d.ts +0 -2
- package/dist/cjs/tests/responses.test.d.ts.map +0 -1
- package/dist/cjs/tests/responses.test.js +0 -60
- package/dist/cjs/tests/responses.test.js.map +0 -1
- package/dist/cjs/version.d.ts +0 -2
- package/dist/cjs/version.d.ts.map +0 -1
- package/dist/cjs/version.js.map +0 -1
- package/examples/demo.ts +0 -28
- package/examples/errors.ts +0 -28
- package/examples/fine-tune-data.jsonl +0 -3
- package/examples/fine-tunes.ts +0 -37
- package/fetch-polyfill.ts +0 -69
- package/index.ts +0 -157
- package/jest.config.js +0 -8
- package/resources/answers.ts +0 -180
- package/resources/audio/audio.ts +0 -10
- package/resources/audio/index.ts +0 -4
- package/resources/chat/chat.ts +0 -8
- package/resources/chat/completions.ts +0 -559
- package/resources/chat/index.ts +0 -3
- package/resources/classifications.ts +0 -169
- package/resources/completions.ts +0 -371
- package/resources/models.ts +0 -53
- package/tests/api-resources/answers.test.ts +0 -242
- package/tests/api-resources/audio/transcriptions.test.ts +0 -28
- package/tests/api-resources/audio/translations.test.ts +0 -27
- package/tests/api-resources/chat/completions.test.ts +0 -40
- package/tests/api-resources/classifications.test.ts +0 -36
- package/tests/api-resources/completions.test.ts +0 -32
- package/tests/api-resources/edits.test.ts +0 -25
- package/tests/api-resources/embeddings.test.ts +0 -22
- package/tests/api-resources/files.test.ts +0 -64
- package/tests/api-resources/fine-tunes.test.ts +0 -78
- package/tests/api-resources/images.test.ts +0 -61
- package/tests/api-resources/models.test.ts +0 -40
- package/tests/api-resources/moderations.test.ts +0 -18
- package/tests/form.test.ts +0 -27
- package/tests/index.test.ts +0 -76
- package/tests/responses.test.ts +0 -25
- package/tsconfig.cjs.json +0 -8
- package/tsconfig.json +0 -39
- package/typings/digest-fetch/index.d.ts +0 -33
- package/version.ts +0 -1
- /package/{dist/cjs/resource.js → resource.js} +0 -0
- /package/{resource.ts → src/resource.ts} +0 -0
package/README.md
CHANGED
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://npmjs.org/package/openai)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
It includes TypeScript definitions for all request params and response fields.
|
|
5
|
+
This library provides convenient access to the OpenAI REST API from TypeScript or JavaScript.
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## Documentation
|
|
7
|
+
It is generated from our [OpenAPI specification](https://github.com/openai/openai-openapi) with [Stainless](https://stainlessapi.com/).
|
|
11
8
|
|
|
12
9
|
To learn how to use the OpenAI API, check out our [API Reference](https://platform.openai.com/docs/api-reference) and [Documentation](https://platform.openai.com/docs).
|
|
13
10
|
|
|
@@ -21,24 +18,26 @@ yarn add openai
|
|
|
21
18
|
|
|
22
19
|
## Usage
|
|
23
20
|
|
|
21
|
+
> [!IMPORTANT]
|
|
22
|
+
> Previous versions of this SDK used a `Configuration` class. See the [v3 to v4 migration guide](https://github.com/openai/openai-node/discussions/217).
|
|
23
|
+
|
|
24
24
|
```js
|
|
25
25
|
import OpenAI from 'openai';
|
|
26
26
|
|
|
27
|
-
const
|
|
27
|
+
const openai = new OpenAI({
|
|
28
28
|
apiKey: 'my api key', // defaults to process.env["OPENAI_API_KEY"]
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
async function main() {
|
|
32
|
-
const completion = await
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
max_tokens: 6,
|
|
36
|
-
temperature: 0,
|
|
32
|
+
const completion = await openai.chat.completions.create({
|
|
33
|
+
messages: [{ role: 'user', content: 'Say this is a test' }],
|
|
34
|
+
model: 'gpt-3.5-turbo',
|
|
37
35
|
});
|
|
38
36
|
|
|
39
37
|
console.log(completion.choices);
|
|
40
38
|
}
|
|
41
|
-
|
|
39
|
+
|
|
40
|
+
main();
|
|
42
41
|
```
|
|
43
42
|
|
|
44
43
|
## Streaming Responses
|
|
@@ -48,60 +47,83 @@ We provide support for streaming responses using Server Side Events (SSE).
|
|
|
48
47
|
```ts
|
|
49
48
|
import OpenAI from 'openai';
|
|
50
49
|
|
|
51
|
-
const
|
|
50
|
+
const openai = new OpenAI();
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
async function main() {
|
|
53
|
+
const stream = await openai.chat.completions.create({
|
|
54
|
+
model: 'gpt-4',
|
|
55
|
+
messages: [{ role: 'user', content: 'Say this is a test' }],
|
|
56
|
+
stream: true,
|
|
57
|
+
});
|
|
58
|
+
for await (const part of stream) {
|
|
59
|
+
process.stdout.write(part.choices[0]?.delta?.content || '');
|
|
60
|
+
}
|
|
60
61
|
}
|
|
62
|
+
|
|
63
|
+
main();
|
|
61
64
|
```
|
|
62
65
|
|
|
63
66
|
If you need to cancel a stream, you can `break` from the loop
|
|
64
67
|
or call `stream.controller.abort()`.
|
|
65
68
|
|
|
66
|
-
###
|
|
69
|
+
### Request & Response types
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
If you like, you may reference our types directly:
|
|
71
|
+
This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:
|
|
70
72
|
|
|
71
73
|
```ts
|
|
72
74
|
import OpenAI from 'openai';
|
|
73
75
|
|
|
74
|
-
const
|
|
76
|
+
const openai = new OpenAI({
|
|
75
77
|
apiKey: 'my api key', // defaults to process.env["OPENAI_API_KEY"]
|
|
76
78
|
});
|
|
77
79
|
|
|
78
80
|
async function main() {
|
|
79
|
-
const params: OpenAI.CompletionCreateParams = {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
max_tokens: 6,
|
|
83
|
-
temperature: 0,
|
|
81
|
+
const params: OpenAI.Chat.CompletionCreateParams = {
|
|
82
|
+
messages: [{ role: 'user', content: 'Say this is a test' }],
|
|
83
|
+
model: 'gpt-3.5-turbo',
|
|
84
84
|
};
|
|
85
|
-
const completion: OpenAI.
|
|
85
|
+
const completion: OpenAI.Chat.ChatCompletion = await openai.chat.completions.create(params);
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
|
|
88
|
+
main();
|
|
88
89
|
```
|
|
89
90
|
|
|
90
91
|
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
|
|
91
92
|
|
|
92
93
|
## File Uploads
|
|
93
94
|
|
|
94
|
-
Request parameters that correspond to file uploads can be passed
|
|
95
|
+
Request parameters that correspond to file uploads can be passed in many different forms:
|
|
95
96
|
|
|
96
|
-
|
|
97
|
+
- `File` (or an object with the same structure)
|
|
98
|
+
- a `fetch` `Response` (or an object with the same structure)
|
|
99
|
+
- an `fs.ReadStream`
|
|
100
|
+
- the return value of our `toFile` helper
|
|
97
101
|
|
|
98
102
|
```ts
|
|
99
|
-
import
|
|
103
|
+
import fs from 'fs';
|
|
104
|
+
import fetch from 'node-fetch';
|
|
105
|
+
import OpenAI, { toFile } from 'openai';
|
|
106
|
+
|
|
107
|
+
const openai = new OpenAI();
|
|
100
108
|
|
|
101
|
-
|
|
109
|
+
// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
|
|
110
|
+
await openai.files.create({ file: fs.createReadStream('input.jsonl'), purpose: 'fine-tune' });
|
|
102
111
|
|
|
103
|
-
|
|
104
|
-
await
|
|
112
|
+
// Or if you have the web `File` API you can pass a `File` instance:
|
|
113
|
+
await openai.files.create({ file: new File(['my bytes'], 'input.jsonl'), purpose: 'fine-tune' });
|
|
114
|
+
|
|
115
|
+
// You can also pass a `fetch` `Response`:
|
|
116
|
+
await openai.files.create({ file: await fetch('https://somesite/input.jsonl'), purpose: 'fine-tune' });
|
|
117
|
+
|
|
118
|
+
// Finally, if none of the above are convenient, you can use our `toFile` helper:
|
|
119
|
+
await openai.files.create({
|
|
120
|
+
file: await toFile(Buffer.from('my bytes'), 'input.jsonl'),
|
|
121
|
+
purpose: 'fine-tune',
|
|
122
|
+
});
|
|
123
|
+
await openai.files.create({
|
|
124
|
+
file: await toFile(new Uint8Array([0, 1, 2]), 'input.jsonl'),
|
|
125
|
+
purpose: 'fine-tune',
|
|
126
|
+
});
|
|
105
127
|
```
|
|
106
128
|
|
|
107
129
|
## Handling errors
|
|
@@ -112,7 +134,7 @@ a subclass of `APIError` will be thrown:
|
|
|
112
134
|
|
|
113
135
|
```ts
|
|
114
136
|
async function main() {
|
|
115
|
-
const fineTune = await
|
|
137
|
+
const fineTune = await openai.fineTunes
|
|
116
138
|
.create({ training_file: 'file-XGinujblHPwGLSztz8cPS8XY' })
|
|
117
139
|
.catch((err) => {
|
|
118
140
|
if (err instanceof OpenAI.APIError) {
|
|
@@ -120,10 +142,13 @@ async function main() {
|
|
|
120
142
|
console.log(err.name); // BadRequestError
|
|
121
143
|
|
|
122
144
|
console.log(err.headers); // {server: 'nginx', ...}
|
|
145
|
+
} else {
|
|
146
|
+
throw err;
|
|
123
147
|
}
|
|
124
148
|
});
|
|
125
149
|
}
|
|
126
|
-
|
|
150
|
+
|
|
151
|
+
main();
|
|
127
152
|
```
|
|
128
153
|
|
|
129
154
|
Error codes are as followed:
|
|
@@ -150,12 +175,12 @@ You can use the `maxRetries` option to configure or disable this:
|
|
|
150
175
|
<!-- prettier-ignore -->
|
|
151
176
|
```js
|
|
152
177
|
// Configure the default for all requests:
|
|
153
|
-
const
|
|
178
|
+
const openai = new OpenAI({
|
|
154
179
|
maxRetries: 0, // default is 2
|
|
155
180
|
});
|
|
156
181
|
|
|
157
182
|
// Or, configure per-request:
|
|
158
|
-
|
|
183
|
+
await openai.chat.completions.create({ messages: [{ role: 'user', content: 'How can I get the name of the current day in Node.js?' }], model: 'gpt-3.5-turbo' }, {
|
|
159
184
|
maxRetries: 5,
|
|
160
185
|
});
|
|
161
186
|
```
|
|
@@ -167,12 +192,12 @@ Requests time out after 60 seconds by default. You can configure this with a `ti
|
|
|
167
192
|
<!-- prettier-ignore -->
|
|
168
193
|
```ts
|
|
169
194
|
// Configure the default for all requests:
|
|
170
|
-
const
|
|
195
|
+
const openai = new OpenAI({
|
|
171
196
|
timeout: 20 * 1000, // 20 seconds (default is 60s)
|
|
172
197
|
});
|
|
173
198
|
|
|
174
199
|
// Override per-request:
|
|
175
|
-
|
|
200
|
+
await openai.chat.completions.create({ messages: [{ role: 'user', content: 'How can I list all files in a directory using Python?' }], model: 'gpt-3.5-turbo' }, {
|
|
176
201
|
timeout: 5 * 1000,
|
|
177
202
|
});
|
|
178
203
|
```
|
|
@@ -181,6 +206,30 @@ On timeout, an `APIConnectionTimeoutError` is thrown.
|
|
|
181
206
|
|
|
182
207
|
Note that requests which time out will be [retried twice by default](#retries).
|
|
183
208
|
|
|
209
|
+
## Advanced Usage
|
|
210
|
+
|
|
211
|
+
### Accessing raw Response data (e.g., headers)
|
|
212
|
+
|
|
213
|
+
The "raw" `Response` returned by `fetch()` can be accessed through the `.asResponse()` method on the `APIPromise` type that all methods return.
|
|
214
|
+
|
|
215
|
+
You can also use the `.withResponse()` method to get the raw `Response` along with the parsed data.
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
const openai = new OpenAI();
|
|
219
|
+
|
|
220
|
+
const response = await openai.chat.completions
|
|
221
|
+
.create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-3.5-turbo' })
|
|
222
|
+
.asResponse();
|
|
223
|
+
console.log(response.headers.get('X-My-Header'));
|
|
224
|
+
console.log(response.statusText); // access the underlying Response object
|
|
225
|
+
|
|
226
|
+
const { data: completions, response: raw } = await openai.chat.completions
|
|
227
|
+
.create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-3.5-turbo' })
|
|
228
|
+
.withResponse();
|
|
229
|
+
console.log(raw.headers.get('X-My-Header'));
|
|
230
|
+
console.log(completions.choices);
|
|
231
|
+
```
|
|
232
|
+
|
|
184
233
|
## Configuring an HTTP(S) Agent (e.g., for proxies)
|
|
185
234
|
|
|
186
235
|
By default, this library uses a stable agent for all http/https requests to reuse TCP connections, eliminating many TCP & TLS handshakes and shaving around 100ms off most requests.
|
|
@@ -193,22 +242,26 @@ import http from 'http';
|
|
|
193
242
|
import HttpsProxyAgent from 'https-proxy-agent';
|
|
194
243
|
|
|
195
244
|
// Configure the default for all requests:
|
|
196
|
-
const
|
|
245
|
+
const openai = new OpenAI({
|
|
197
246
|
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
|
|
198
247
|
});
|
|
199
248
|
|
|
200
249
|
// Override per-request:
|
|
201
|
-
|
|
250
|
+
await openai.models.list({
|
|
202
251
|
baseURL: 'http://localhost:8080/test-api',
|
|
203
252
|
httpAgent: new http.Agent({ keepAlive: false }),
|
|
204
253
|
})
|
|
205
254
|
```
|
|
206
255
|
|
|
207
|
-
##
|
|
256
|
+
## Semantic Versioning
|
|
257
|
+
|
|
258
|
+
This package generally attempts to follow [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
|
|
259
|
+
|
|
260
|
+
1. Changes that only affect static types, without breaking runtime behavior.
|
|
261
|
+
2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_.
|
|
262
|
+
3. Changes that we do not expect to impact the vast majority of users in practice.
|
|
208
263
|
|
|
209
|
-
|
|
210
|
-
and subject to change without a major semver bump;
|
|
211
|
-
please reach out if you rely on any undocumented behavior.
|
|
264
|
+
We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
|
|
212
265
|
|
|
213
266
|
We are keen for your feedback; please open an [issue](https://www.github.com/openai/openai-node/issues) with questions, bugs, or suggestions.
|
|
214
267
|
|
|
@@ -216,8 +269,10 @@ We are keen for your feedback; please open an [issue](https://www.github.com/ope
|
|
|
216
269
|
|
|
217
270
|
The following runtimes are supported:
|
|
218
271
|
|
|
219
|
-
- Node.js
|
|
220
|
-
- Deno v1.28.0 or higher
|
|
221
|
-
|
|
272
|
+
- Node.js 16 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
|
|
273
|
+
- Deno v1.28.0 or higher, using `import OpenAI from "npm:openai"`.
|
|
274
|
+
Deno Deploy is not yet supported.
|
|
275
|
+
- Cloudflare Workers.
|
|
276
|
+
- Vercel Edge Runtime.
|
|
222
277
|
|
|
223
278
|
If you are interested in other runtime environments, please open or upvote an issue on GitHub.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* >>> Confused? <<<
|
|
7
|
+
*
|
|
8
|
+
* If you're getting errors from these types, try adding "lib": ["DOM"]
|
|
9
|
+
* to your tsconfig.json, or otherwise configure the appropriate builtin
|
|
10
|
+
* `ReadableStream` type for your environment.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
type _ReadableStream<R = any> = unknown extends ReadableStream ? never : ReadableStream<R>;
|
|
15
|
+
declare const _ReadableStream: {
|
|
16
|
+
prototype: _ReadableStream;
|
|
17
|
+
new (
|
|
18
|
+
underlyingSource: _UnderlyingByteSource,
|
|
19
|
+
strategy?: { highWaterMark?: number },
|
|
20
|
+
): _ReadableStream<Uint8Array>;
|
|
21
|
+
new <R = any>(
|
|
22
|
+
underlyingSource: _UnderlyingDefaultSource<R>,
|
|
23
|
+
strategy?: _QueuingStrategy<R>,
|
|
24
|
+
): _ReadableStream<R>;
|
|
25
|
+
new <R = any>(underlyingSource?: _UnderlyingSource<R>, strategy?: _QueuingStrategy<R>): _ReadableStream<R>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
type _UnderlyingSource<R = any> = unknown extends UnderlyingSource ? never : UnderlyingSource<R>;
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
type _UnderlyingByteSource = unknown extends UnderlyingByteSource ? never : UnderlyingByteSource;
|
|
32
|
+
type _UnderlyingDefaultSource<R = any> =
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
unknown extends UnderlyingDefaultSource ? never : UnderlyingDefaultSource<R>;
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
type _QueuingStrategy<R = any> = unknown extends QueuingStrategy ? never : QueuingStrategy<R>;
|
|
37
|
+
|
|
38
|
+
export { _ReadableStream as ReadableStream };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReadableStream.node.d.ts","sourceRoot":"","sources":["../src/_shims/ReadableStream.node.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.ReadableStream = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
6
|
+
*/
|
|
7
|
+
const web_streams_polyfill_1 = require('web-streams-polyfill');
|
|
8
|
+
Object.defineProperty(exports, 'ReadableStream', {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return web_streams_polyfill_1.ReadableStream;
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=ReadableStream.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReadableStream.node.js","sourceRoot":"","sources":["../src/_shims/ReadableStream.node.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,+DAAsD;AAE7C,+FAFA,qCAAc,OAEA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReadableStream.node.mjs","sourceRoot":"","sources":["../src/_shims/ReadableStream.node.ts"],"names":[],"mappings":"OAGO,EAAE,cAAc,EAAE,MAAM,sBAAsB;AAErD,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
|
+
*
|
|
4
|
+
* This is a stub for non-node environments.
|
|
5
|
+
* In node environments, it gets replaced agent.node.ts by the package export map
|
|
6
|
+
*/
|
|
7
|
+
export type Agent = any;
|
|
8
|
+
export declare const getDefaultAgent: (url: string) => any;
|
|
9
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/_shims/agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,KAAK,GAAG,GAAG,CAAC;AAExB,eAAO,MAAM,eAAe,QAAS,MAAM,KAAG,GAE7C,CAAC"}
|
package/_shims/agent.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
4
|
+
*
|
|
5
|
+
* This is a stub for non-node environments.
|
|
6
|
+
* In node environments, it gets replaced agent.node.ts by the package export map
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
exports.getDefaultAgent = void 0;
|
|
10
|
+
const getDefaultAgent = (url) => {
|
|
11
|
+
return undefined;
|
|
12
|
+
};
|
|
13
|
+
exports.getDefaultAgent = getDefaultAgent;
|
|
14
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/_shims/agent.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAII,MAAM,eAAe,GAAG,CAAC,GAAW,EAAO,EAAE;IAClD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B"}
|
package/_shims/agent.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
|
+
*
|
|
4
|
+
* This is a stub for non-node environments.
|
|
5
|
+
* In node environments, it gets replaced agent.node.ts by the package export map
|
|
6
|
+
*/
|
|
7
|
+
export const getDefaultAgent = (url) => {
|
|
8
|
+
return undefined;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=agent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.mjs","sourceRoot":"","sources":["../src/_shims/agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAW,EAAO,EAAE;IAClD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
|
+
*/
|
|
4
|
+
import type { Agent } from 'node:http';
|
|
5
|
+
export type { Agent };
|
|
6
|
+
export declare const getDefaultAgent: (url: string) => Agent | undefined;
|
|
7
|
+
//# sourceMappingURL=agent.node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.node.d.ts","sourceRoot":"","sources":["../src/_shims/agent.node.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAGvC,YAAY,EAAE,KAAK,EAAE,CAAC;AAUtB,eAAO,MAAM,eAAe,QAAS,MAAM,KAAG,KAAK,GAAG,SAGrD,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault =
|
|
6
|
+
(this && this.__importDefault) ||
|
|
7
|
+
function (mod) {
|
|
8
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
+
exports.getDefaultAgent = void 0;
|
|
12
|
+
const agentkeepalive_1 = __importDefault(require('agentkeepalive'));
|
|
13
|
+
const abort_controller_1 = require('abort-controller');
|
|
14
|
+
const defaultHttpAgent = new agentkeepalive_1.default({ keepAlive: true, timeout: 5 * 60 * 1000 });
|
|
15
|
+
const defaultHttpsAgent = new agentkeepalive_1.default.HttpsAgent({
|
|
16
|
+
keepAlive: true,
|
|
17
|
+
timeout: 5 * 60 * 1000,
|
|
18
|
+
});
|
|
19
|
+
// Polyfill global object if needed.
|
|
20
|
+
if (typeof AbortController === 'undefined') {
|
|
21
|
+
AbortController = abort_controller_1.AbortController;
|
|
22
|
+
}
|
|
23
|
+
const getDefaultAgent = (url) => {
|
|
24
|
+
if (defaultHttpsAgent && url.startsWith('https')) return defaultHttpsAgent;
|
|
25
|
+
return defaultHttpAgent;
|
|
26
|
+
};
|
|
27
|
+
exports.getDefaultAgent = getDefaultAgent;
|
|
28
|
+
//# sourceMappingURL=agent.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.node.js","sourceRoot":"","sources":["../src/_shims/agent.node.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,oEAA4C;AAE5C,uDAA8E;AAI9E,MAAM,gBAAgB,GAAU,IAAI,wBAAc,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AAChG,MAAM,iBAAiB,GAAU,IAAI,wBAAc,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AAE5G,oCAAoC;AACpC,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE;IAC1C,eAAe,GAAG,kCAAwD,CAAC;CAC5E;AAEM,MAAM,eAAe,GAAG,CAAC,GAAW,EAAqB,EAAE;IAChE,IAAI,iBAAiB,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,iBAAiB,CAAC;IAC3E,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAHW,QAAA,eAAe,mBAG1B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
|
+
*/
|
|
4
|
+
import KeepAliveAgent from 'agentkeepalive';
|
|
5
|
+
import { AbortController as AbortControllerPolyfill } from 'abort-controller';
|
|
6
|
+
const defaultHttpAgent = new KeepAliveAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });
|
|
7
|
+
const defaultHttpsAgent = new KeepAliveAgent.HttpsAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });
|
|
8
|
+
// Polyfill global object if needed.
|
|
9
|
+
if (typeof AbortController === 'undefined') {
|
|
10
|
+
AbortController = AbortControllerPolyfill;
|
|
11
|
+
}
|
|
12
|
+
export const getDefaultAgent = (url) => {
|
|
13
|
+
if (defaultHttpsAgent && url.startsWith('https')) return defaultHttpsAgent;
|
|
14
|
+
return defaultHttpAgent;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=agent.node.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.node.mjs","sourceRoot":"","sources":["../src/_shims/agent.node.ts"],"names":[],"mappings":"AAAA;;GAEG;OAEI,cAAc,MAAM,gBAAgB;OAEpC,EAAE,eAAe,IAAI,uBAAuB,EAAE,MAAM,kBAAkB;AAI7E,MAAM,gBAAgB,GAAU,IAAI,cAAc,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AAChG,MAAM,iBAAiB,GAAU,IAAI,cAAc,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AAE5G,oCAAoC;AACpC,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE;IAC1C,eAAe,GAAG,uBAAwD,CAAC;CAC5E;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAW,EAAqB,EAAE;IAChE,IAAI,iBAAiB,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,iBAAiB,CAAC;IAC3E,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Use builtin web types if present; else never (user should
|
|
6
|
+
// add appropriate lib or types to tsconfig)
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* >>> Confused? <<<
|
|
10
|
+
*
|
|
11
|
+
* If you're getting errors from these types, try adding "lib": ["DOM"]
|
|
12
|
+
* to your tsconfig.json, or otherwise configure the appropriate builtin
|
|
13
|
+
* `fetch` types for your environment.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
type _fetch = unknown extends typeof fetch ? never : typeof fetch;
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
type _Request = unknown extends Request ? never : Request;
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
type _RequestInfo = unknown extends RequestInfo ? never : RequestInfo;
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
type _RequestInit = unknown extends RequestInit ? never : RequestInit;
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
type _Response = unknown extends Response ? never : Response;
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
type _ResponseInit = unknown extends ResponseInit ? never : ResponseInit;
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
type _ResponseType = unknown extends ResponseType ? never : ResponseType;
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
type _BodyInit = unknown extends BodyInit ? never : BodyInit;
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
type _Headers = unknown extends Headers ? never : Headers;
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
type _HeadersInit = unknown extends HeadersInit ? never : HeadersInit;
|
|
36
|
+
|
|
37
|
+
declare const _fetch: _fetch;
|
|
38
|
+
declare const _Request: {
|
|
39
|
+
prototype: _Request;
|
|
40
|
+
new (input: _RequestInfo | URL, init?: _RequestInit): _Request;
|
|
41
|
+
};
|
|
42
|
+
declare const _Response: {
|
|
43
|
+
prototype: _Response;
|
|
44
|
+
new (body?: _BodyInit | null, init?: _ResponseInit): _Response;
|
|
45
|
+
};
|
|
46
|
+
declare const _Headers: {
|
|
47
|
+
prototype: _Headers;
|
|
48
|
+
new (init?: _HeadersInit): _Headers;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const isPolyfilled = false;
|
|
52
|
+
|
|
53
|
+
export { _fetch as fetch, _Request as Request, _Response as Response, _Headers as Headers };
|
|
54
|
+
export type {
|
|
55
|
+
_RequestInit as RequestInit,
|
|
56
|
+
_RequestInfo as RequestInfo,
|
|
57
|
+
_ResponseType as ResponseType,
|
|
58
|
+
_BodyInit as BodyInit,
|
|
59
|
+
};
|
package/_shims/fetch.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// If we accidentally call fetch with the wrong this binding,
|
|
6
|
+
// in the browser it would throw:
|
|
7
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
8
|
+
exports.fetch = fetch.bind(undefined);
|
|
9
|
+
exports.Request = Request;
|
|
10
|
+
exports.Response = Response;
|
|
11
|
+
exports.Headers = Headers;
|
|
12
|
+
|
|
13
|
+
exports.isPolyfilled = false;
|
package/_shims/fetch.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// If we accidentally call fetch with the wrong this binding,
|
|
6
|
+
// in the browser it would throw:
|
|
7
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
8
|
+
const _fetch = fetch.bind(undefined);
|
|
9
|
+
const _Request = Request;
|
|
10
|
+
const _Response = Response;
|
|
11
|
+
const _Headers = Headers;
|
|
12
|
+
|
|
13
|
+
export const isPolyfilled = false;
|
|
14
|
+
|
|
15
|
+
export { _fetch as fetch, _Request as Request, _Response as Response, _Headers as Headers };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as nf from 'node-fetch';
|
|
6
|
+
|
|
7
|
+
// Use builtin web types if present; else node-fetch types
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* >>> Confused? <<<
|
|
11
|
+
*
|
|
12
|
+
* If you're getting errors from these types, try adding "lib": ["DOM"]
|
|
13
|
+
* to your tsconfig.json, or otherwise configure the appropriate builtin
|
|
14
|
+
* `fetch` types for your environment.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
type _fetch = unknown extends typeof fetch ? typeof nf.default : typeof fetch;
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
type _Request = unknown extends Request ? nf.Request : Request;
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
type _RequestInfo = unknown extends RequestInfo ? nf.RequestInfo : RequestInfo;
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
type _RequestInit = unknown extends RequestInit ? nf.RequestInit : RequestInit;
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
type _Response = unknown extends Response ? nf.Response : Response;
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
type _ResponseInit = unknown extends ResponseInit ? nf.ResponseInit : ResponseInit;
|
|
29
|
+
type _ResponseType =
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
unknown extends ResponseType ? 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect'
|
|
32
|
+
: // @ts-ignore
|
|
33
|
+
ResponseType;
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
type _BodyInit = unknown extends BodyInit ? nf.BodyInit : BodyInit;
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
type _Headers = unknown extends Headers ? nf.Headers : Headers;
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
type _HeadersInit = unknown extends HeadersInit ? nf.HeadersInit : HeadersInit;
|
|
40
|
+
|
|
41
|
+
declare const _fetch: _fetch;
|
|
42
|
+
declare const _Request: {
|
|
43
|
+
prototype: _Request;
|
|
44
|
+
new (input: _RequestInfo | URL, init?: _RequestInit): _Request;
|
|
45
|
+
};
|
|
46
|
+
declare const _Response: {
|
|
47
|
+
prototype: _Response;
|
|
48
|
+
new (body?: _BodyInit | null, init?: _ResponseInit): _Response;
|
|
49
|
+
};
|
|
50
|
+
declare const _Headers: {
|
|
51
|
+
prototype: _Headers;
|
|
52
|
+
new (init?: _HeadersInit): _Headers;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const isPolyfilled = false;
|
|
56
|
+
|
|
57
|
+
export { _fetch as fetch, _Request as Request, _Response as Response, _Headers as Headers };
|
|
58
|
+
export type {
|
|
59
|
+
_RequestInit as RequestInit,
|
|
60
|
+
_RequestInfo as RequestInfo,
|
|
61
|
+
_ResponseType as ResponseType,
|
|
62
|
+
_BodyInit as BodyInit,
|
|
63
|
+
};
|