openai 4.53.2 → 4.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +2 -2
- package/_vendor/partial-json-parser/parser.d.ts +3 -0
- package/_vendor/partial-json-parser/parser.d.ts.map +1 -0
- package/_vendor/partial-json-parser/parser.js +226 -0
- package/_vendor/partial-json-parser/parser.js.map +1 -0
- package/_vendor/partial-json-parser/parser.mjs +223 -0
- package/_vendor/partial-json-parser/parser.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/Options.d.ts +32 -0
- package/_vendor/zod-to-json-schema/Options.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/Options.js +36 -0
- package/_vendor/zod-to-json-schema/Options.js.map +1 -0
- package/_vendor/zod-to-json-schema/Options.mjs +32 -0
- package/_vendor/zod-to-json-schema/Options.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/Refs.d.ts +15 -0
- package/_vendor/zod-to-json-schema/Refs.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/Refs.js +26 -0
- package/_vendor/zod-to-json-schema/Refs.js.map +1 -0
- package/_vendor/zod-to-json-schema/Refs.mjs +22 -0
- package/_vendor/zod-to-json-schema/Refs.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/errorMessages.d.ts +12 -0
- package/_vendor/zod-to-json-schema/errorMessages.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/errorMessages.js +20 -0
- package/_vendor/zod-to-json-schema/errorMessages.js.map +1 -0
- package/_vendor/zod-to-json-schema/errorMessages.mjs +15 -0
- package/_vendor/zod-to-json-schema/errorMessages.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/index.d.ts +38 -0
- package/_vendor/zod-to-json-schema/index.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/index.js +54 -0
- package/_vendor/zod-to-json-schema/index.js.map +1 -0
- package/_vendor/zod-to-json-schema/index.mjs +38 -0
- package/_vendor/zod-to-json-schema/index.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parseDef.d.ts +38 -0
- package/_vendor/zod-to-json-schema/parseDef.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parseDef.js +168 -0
- package/_vendor/zod-to-json-schema/parseDef.js.map +1 -0
- package/_vendor/zod-to-json-schema/parseDef.mjs +164 -0
- package/_vendor/zod-to-json-schema/parseDef.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/any.d.ts +3 -0
- package/_vendor/zod-to-json-schema/parsers/any.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/any.js +8 -0
- package/_vendor/zod-to-json-schema/parsers/any.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/any.mjs +4 -0
- package/_vendor/zod-to-json-schema/parsers/any.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/array.d.ts +13 -0
- package/_vendor/zod-to-json-schema/parsers/array.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/array.js +30 -0
- package/_vendor/zod-to-json-schema/parsers/array.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/array.mjs +26 -0
- package/_vendor/zod-to-json-schema/parsers/array.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/bigint.d.ts +15 -0
- package/_vendor/zod-to-json-schema/parsers/bigint.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/bigint.js +54 -0
- package/_vendor/zod-to-json-schema/parsers/bigint.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/bigint.mjs +50 -0
- package/_vendor/zod-to-json-schema/parsers/bigint.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/boolean.d.ts +5 -0
- package/_vendor/zod-to-json-schema/parsers/boolean.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/boolean.js +10 -0
- package/_vendor/zod-to-json-schema/parsers/boolean.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/boolean.mjs +6 -0
- package/_vendor/zod-to-json-schema/parsers/boolean.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/branded.d.ts +4 -0
- package/_vendor/zod-to-json-schema/parsers/branded.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/branded.js +9 -0
- package/_vendor/zod-to-json-schema/parsers/branded.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/branded.mjs +5 -0
- package/_vendor/zod-to-json-schema/parsers/branded.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/catch.d.ts +4 -0
- package/_vendor/zod-to-json-schema/parsers/catch.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/catch.js +9 -0
- package/_vendor/zod-to-json-schema/parsers/catch.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/catch.mjs +5 -0
- package/_vendor/zod-to-json-schema/parsers/catch.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/date.d.ts +16 -0
- package/_vendor/zod-to-json-schema/parsers/date.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/date.js +51 -0
- package/_vendor/zod-to-json-schema/parsers/date.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/date.mjs +47 -0
- package/_vendor/zod-to-json-schema/parsers/date.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/default.d.ts +7 -0
- package/_vendor/zod-to-json-schema/parsers/default.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/default.js +12 -0
- package/_vendor/zod-to-json-schema/parsers/default.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/default.mjs +8 -0
- package/_vendor/zod-to-json-schema/parsers/default.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/effects.d.ts +5 -0
- package/_vendor/zod-to-json-schema/parsers/effects.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/effects.js +9 -0
- package/_vendor/zod-to-json-schema/parsers/effects.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/effects.mjs +5 -0
- package/_vendor/zod-to-json-schema/parsers/effects.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/enum.d.ts +7 -0
- package/_vendor/zod-to-json-schema/parsers/enum.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/enum.js +11 -0
- package/_vendor/zod-to-json-schema/parsers/enum.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/enum.mjs +7 -0
- package/_vendor/zod-to-json-schema/parsers/enum.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/intersection.d.ts +9 -0
- package/_vendor/zod-to-json-schema/parsers/intersection.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/intersection.js +54 -0
- package/_vendor/zod-to-json-schema/parsers/intersection.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/intersection.mjs +50 -0
- package/_vendor/zod-to-json-schema/parsers/intersection.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/literal.d.ts +10 -0
- package/_vendor/zod-to-json-schema/parsers/literal.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/literal.js +26 -0
- package/_vendor/zod-to-json-schema/parsers/literal.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/literal.mjs +22 -0
- package/_vendor/zod-to-json-schema/parsers/literal.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/map.d.ts +16 -0
- package/_vendor/zod-to-json-schema/parsers/map.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/map.js +30 -0
- package/_vendor/zod-to-json-schema/parsers/map.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/map.mjs +26 -0
- package/_vendor/zod-to-json-schema/parsers/map.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.d.ts +7 -0
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.js +21 -0
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.mjs +17 -0
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/never.d.ts +5 -0
- package/_vendor/zod-to-json-schema/parsers/never.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/never.js +10 -0
- package/_vendor/zod-to-json-schema/parsers/never.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/never.mjs +6 -0
- package/_vendor/zod-to-json-schema/parsers/never.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/null.d.ts +6 -0
- package/_vendor/zod-to-json-schema/parsers/null.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/null.js +15 -0
- package/_vendor/zod-to-json-schema/parsers/null.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/null.mjs +11 -0
- package/_vendor/zod-to-json-schema/parsers/null.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/nullable.d.ts +11 -0
- package/_vendor/zod-to-json-schema/parsers/nullable.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/nullable.js +35 -0
- package/_vendor/zod-to-json-schema/parsers/nullable.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/nullable.mjs +31 -0
- package/_vendor/zod-to-json-schema/parsers/nullable.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/number.d.ts +14 -0
- package/_vendor/zod-to-json-schema/parsers/number.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/number.js +57 -0
- package/_vendor/zod-to-json-schema/parsers/number.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/number.mjs +53 -0
- package/_vendor/zod-to-json-schema/parsers/number.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/object.d.ts +11 -0
- package/_vendor/zod-to-json-schema/parsers/object.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/object.js +51 -0
- package/_vendor/zod-to-json-schema/parsers/object.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/object.mjs +47 -0
- package/_vendor/zod-to-json-schema/parsers/object.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/optional.d.ts +5 -0
- package/_vendor/zod-to-json-schema/parsers/optional.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/optional.js +25 -0
- package/_vendor/zod-to-json-schema/parsers/optional.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/optional.mjs +21 -0
- package/_vendor/zod-to-json-schema/parsers/optional.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/pipeline.d.ts +6 -0
- package/_vendor/zod-to-json-schema/parsers/pipeline.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/pipeline.js +25 -0
- package/_vendor/zod-to-json-schema/parsers/pipeline.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/pipeline.mjs +21 -0
- package/_vendor/zod-to-json-schema/parsers/pipeline.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/promise.d.ts +5 -0
- package/_vendor/zod-to-json-schema/parsers/promise.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/promise.js +9 -0
- package/_vendor/zod-to-json-schema/parsers/promise.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/promise.mjs +5 -0
- package/_vendor/zod-to-json-schema/parsers/promise.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/readonly.d.ts +4 -0
- package/_vendor/zod-to-json-schema/parsers/readonly.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/readonly.js +9 -0
- package/_vendor/zod-to-json-schema/parsers/readonly.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/readonly.mjs +5 -0
- package/_vendor/zod-to-json-schema/parsers/readonly.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/record.d.ts +14 -0
- package/_vendor/zod-to-json-schema/parsers/record.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/record.js +50 -0
- package/_vendor/zod-to-json-schema/parsers/record.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/record.mjs +46 -0
- package/_vendor/zod-to-json-schema/parsers/record.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/set.d.ts +14 -0
- package/_vendor/zod-to-json-schema/parsers/set.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/set.js +25 -0
- package/_vendor/zod-to-json-schema/parsers/set.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/set.mjs +21 -0
- package/_vendor/zod-to-json-schema/parsers/set.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/string.d.ts +70 -0
- package/_vendor/zod-to-json-schema/parsers/string.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/string.js +316 -0
- package/_vendor/zod-to-json-schema/parsers/string.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/string.mjs +312 -0
- package/_vendor/zod-to-json-schema/parsers/string.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/tuple.d.ts +14 -0
- package/_vendor/zod-to-json-schema/parsers/tuple.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/tuple.js +37 -0
- package/_vendor/zod-to-json-schema/parsers/tuple.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/tuple.mjs +33 -0
- package/_vendor/zod-to-json-schema/parsers/tuple.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/undefined.d.ts +5 -0
- package/_vendor/zod-to-json-schema/parsers/undefined.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/undefined.js +10 -0
- package/_vendor/zod-to-json-schema/parsers/undefined.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/undefined.mjs +6 -0
- package/_vendor/zod-to-json-schema/parsers/undefined.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/union.d.ts +24 -0
- package/_vendor/zod-to-json-schema/parsers/union.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/union.js +77 -0
- package/_vendor/zod-to-json-schema/parsers/union.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/union.mjs +73 -0
- package/_vendor/zod-to-json-schema/parsers/union.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/unknown.d.ts +3 -0
- package/_vendor/zod-to-json-schema/parsers/unknown.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/unknown.js +8 -0
- package/_vendor/zod-to-json-schema/parsers/unknown.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/unknown.mjs +4 -0
- package/_vendor/zod-to-json-schema/parsers/unknown.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/zodToJsonSchema.d.ts +11 -0
- package/_vendor/zod-to-json-schema/zodToJsonSchema.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/zodToJsonSchema.js +53 -0
- package/_vendor/zod-to-json-schema/zodToJsonSchema.js.map +1 -0
- package/_vendor/zod-to-json-schema/zodToJsonSchema.mjs +50 -0
- package/_vendor/zod-to-json-schema/zodToJsonSchema.mjs.map +1 -0
- package/error.d.ts +6 -0
- package/error.d.ts.map +1 -1
- package/error.js +13 -1
- package/error.js.map +1 -1
- package/error.mjs +10 -0
- package/error.mjs.map +1 -1
- package/helpers/zod.d.ts +57 -0
- package/helpers/zod.d.ts.map +1 -0
- package/helpers/zod.js +79 -0
- package/helpers/zod.js.map +1 -0
- package/helpers/zod.mjs +74 -0
- package/helpers/zod.mjs.map +1 -0
- package/index.d.mts +8 -0
- package/index.d.ts +8 -0
- package/index.d.ts.map +1 -1
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/index.mjs +1 -0
- package/index.mjs.map +1 -1
- package/lib/AbstractChatCompletionRunner.d.ts +15 -68
- package/lib/AbstractChatCompletionRunner.d.ts.map +1 -1
- package/lib/AbstractChatCompletionRunner.js +47 -200
- package/lib/AbstractChatCompletionRunner.js.map +1 -1
- package/lib/AbstractChatCompletionRunner.mjs +48 -201
- package/lib/AbstractChatCompletionRunner.mjs.map +1 -1
- package/lib/AssistantStream.d.ts +10 -6
- package/lib/AssistantStream.d.ts.map +1 -1
- package/lib/AssistantStream.js +18 -6
- package/lib/AssistantStream.js.map +1 -1
- package/lib/AssistantStream.mjs +18 -6
- package/lib/AssistantStream.mjs.map +1 -1
- package/lib/ChatCompletionRunner.d.ts +8 -6
- package/lib/ChatCompletionRunner.d.ts.map +1 -1
- package/lib/ChatCompletionRunner.js +4 -4
- package/lib/ChatCompletionRunner.js.map +1 -1
- package/lib/ChatCompletionRunner.mjs +4 -4
- package/lib/ChatCompletionRunner.mjs.map +1 -1
- package/lib/ChatCompletionStream.d.ts +71 -12
- package/lib/ChatCompletionStream.d.ts.map +1 -1
- package/lib/ChatCompletionStream.js +233 -42
- package/lib/ChatCompletionStream.js.map +1 -1
- package/lib/ChatCompletionStream.mjs +234 -43
- package/lib/ChatCompletionStream.mjs.map +1 -1
- package/lib/ChatCompletionStreamingRunner.d.ts +8 -6
- package/lib/ChatCompletionStreamingRunner.d.ts.map +1 -1
- package/lib/ChatCompletionStreamingRunner.js +9 -7
- package/lib/ChatCompletionStreamingRunner.js.map +1 -1
- package/lib/ChatCompletionStreamingRunner.mjs +9 -7
- package/lib/ChatCompletionStreamingRunner.mjs.map +1 -1
- package/lib/EventStream.d.ts +63 -0
- package/lib/EventStream.d.ts.map +1 -0
- package/lib/EventStream.js +200 -0
- package/lib/EventStream.js.map +1 -0
- package/lib/EventStream.mjs +196 -0
- package/lib/EventStream.mjs.map +1 -0
- package/lib/RunnableFunction.d.ts +4 -2
- package/lib/RunnableFunction.d.ts.map +1 -1
- package/lib/RunnableFunction.js.map +1 -1
- package/lib/RunnableFunction.mjs.map +1 -1
- package/lib/parser.d.ts +37 -0
- package/lib/parser.d.ts.map +1 -0
- package/lib/parser.js +133 -0
- package/lib/parser.js.map +1 -0
- package/lib/parser.mjs +121 -0
- package/lib/parser.mjs.map +1 -0
- package/package.json +10 -2
- package/resources/audio/audio.d.ts +4 -0
- package/resources/audio/audio.d.ts.map +1 -1
- package/resources/audio/audio.js.map +1 -1
- package/resources/audio/audio.mjs.map +1 -1
- package/resources/audio/index.d.ts +2 -2
- package/resources/audio/index.d.ts.map +1 -1
- package/resources/audio/index.js.map +1 -1
- package/resources/audio/index.mjs.map +1 -1
- package/resources/audio/speech.d.ts +3 -1
- package/resources/audio/speech.d.ts.map +1 -1
- package/resources/audio/speech.js.map +1 -1
- package/resources/audio/speech.mjs.map +1 -1
- package/resources/audio/transcriptions.d.ts +2 -1
- package/resources/audio/transcriptions.d.ts.map +1 -1
- package/resources/audio/transcriptions.js.map +1 -1
- package/resources/audio/transcriptions.mjs.map +1 -1
- package/resources/audio/translations.d.ts +2 -1
- package/resources/audio/translations.d.ts.map +1 -1
- package/resources/audio/translations.js.map +1 -1
- package/resources/audio/translations.mjs.map +1 -1
- package/resources/beta/assistants.d.ts +19 -3
- package/resources/beta/assistants.d.ts.map +1 -1
- package/resources/beta/assistants.js.map +1 -1
- package/resources/beta/assistants.mjs.map +1 -1
- package/resources/beta/beta.d.ts +0 -1
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/chat/completions.d.ts +25 -5
- package/resources/beta/chat/completions.d.ts.map +1 -1
- package/resources/beta/chat/completions.js +17 -5
- package/resources/beta/chat/completions.js.map +1 -1
- package/resources/beta/chat/completions.mjs +17 -5
- package/resources/beta/chat/completions.mjs.map +1 -1
- package/resources/beta/index.d.ts +1 -1
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/threads/index.d.ts +2 -2
- package/resources/beta/threads/index.d.ts.map +1 -1
- package/resources/beta/threads/index.js.map +1 -1
- package/resources/beta/threads/index.mjs.map +1 -1
- package/resources/beta/threads/messages.d.ts +28 -2
- package/resources/beta/threads/messages.d.ts.map +1 -1
- package/resources/beta/threads/messages.js.map +1 -1
- package/resources/beta/threads/messages.mjs.map +1 -1
- package/resources/beta/threads/runs/runs.d.ts +12 -1
- package/resources/beta/threads/runs/runs.d.ts.map +1 -1
- package/resources/beta/threads/runs/runs.js.map +1 -1
- package/resources/beta/threads/runs/runs.mjs.map +1 -1
- package/resources/beta/threads/threads.d.ts +22 -8
- package/resources/beta/threads/threads.d.ts.map +1 -1
- package/resources/beta/threads/threads.js.map +1 -1
- package/resources/beta/threads/threads.mjs.map +1 -1
- package/resources/beta/vector-stores/files.d.ts +1 -1
- package/resources/beta/vector-stores/files.d.ts.map +1 -1
- package/resources/chat/chat.d.ts +2 -1
- package/resources/chat/chat.d.ts.map +1 -1
- package/resources/chat/chat.js.map +1 -1
- package/resources/chat/chat.mjs.map +1 -1
- package/resources/chat/completions.d.ts +37 -26
- package/resources/chat/completions.d.ts.map +1 -1
- package/resources/chat/completions.js.map +1 -1
- package/resources/chat/completions.mjs.map +1 -1
- package/resources/chat/index.d.ts +1 -1
- package/resources/chat/index.d.ts.map +1 -1
- package/resources/chat/index.js.map +1 -1
- package/resources/chat/index.mjs.map +1 -1
- package/resources/fine-tuning/jobs/jobs.d.ts +3 -3
- package/resources/fine-tuning/jobs/jobs.d.ts.map +1 -1
- package/resources/images.d.ts +5 -3
- package/resources/images.d.ts.map +1 -1
- package/resources/images.js.map +1 -1
- package/resources/images.mjs.map +1 -1
- package/resources/index.d.ts +3 -3
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/moderations.d.ts +3 -1
- package/resources/moderations.d.ts.map +1 -1
- package/resources/moderations.js.map +1 -1
- package/resources/moderations.mjs.map +1 -1
- package/resources/shared.d.ts +53 -0
- package/resources/shared.d.ts.map +1 -1
- package/src/_vendor/partial-json-parser/README.md +3 -0
- package/src/_vendor/partial-json-parser/parser.ts +264 -0
- package/src/_vendor/zod-to-json-schema/Options.ts +73 -0
- package/src/_vendor/zod-to-json-schema/Refs.ts +39 -0
- package/src/_vendor/zod-to-json-schema/errorMessages.ts +31 -0
- package/src/_vendor/zod-to-json-schema/index.ts +37 -0
- package/src/_vendor/zod-to-json-schema/parseDef.ts +231 -0
- package/src/_vendor/zod-to-json-schema/parsers/any.ts +5 -0
- package/src/_vendor/zod-to-json-schema/parsers/array.ts +36 -0
- package/src/_vendor/zod-to-json-schema/parsers/bigint.ts +60 -0
- package/src/_vendor/zod-to-json-schema/parsers/boolean.ts +9 -0
- package/src/_vendor/zod-to-json-schema/parsers/branded.ts +7 -0
- package/src/_vendor/zod-to-json-schema/parsers/catch.ts +7 -0
- package/src/_vendor/zod-to-json-schema/parsers/date.ts +83 -0
- package/src/_vendor/zod-to-json-schema/parsers/default.ts +10 -0
- package/src/_vendor/zod-to-json-schema/parsers/effects.ts +7 -0
- package/src/_vendor/zod-to-json-schema/parsers/enum.ts +13 -0
- package/src/_vendor/zod-to-json-schema/parsers/intersection.ts +64 -0
- package/src/_vendor/zod-to-json-schema/parsers/literal.ts +37 -0
- package/src/_vendor/zod-to-json-schema/parsers/map.ts +42 -0
- package/src/_vendor/zod-to-json-schema/parsers/nativeEnum.ts +27 -0
- package/src/_vendor/zod-to-json-schema/parsers/never.ts +9 -0
- package/src/_vendor/zod-to-json-schema/parsers/null.ts +16 -0
- package/src/_vendor/zod-to-json-schema/parsers/nullable.ts +49 -0
- package/src/_vendor/zod-to-json-schema/parsers/number.ts +62 -0
- package/src/_vendor/zod-to-json-schema/parsers/object.ts +63 -0
- package/src/_vendor/zod-to-json-schema/parsers/optional.ts +25 -0
- package/src/_vendor/zod-to-json-schema/parsers/pipeline.ts +28 -0
- package/src/_vendor/zod-to-json-schema/parsers/promise.ts +7 -0
- package/src/_vendor/zod-to-json-schema/parsers/readonly.ts +7 -0
- package/src/_vendor/zod-to-json-schema/parsers/record.ts +73 -0
- package/src/_vendor/zod-to-json-schema/parsers/set.ts +36 -0
- package/src/_vendor/zod-to-json-schema/parsers/string.ts +400 -0
- package/src/_vendor/zod-to-json-schema/parsers/tuple.ts +54 -0
- package/src/_vendor/zod-to-json-schema/parsers/undefined.ts +9 -0
- package/src/_vendor/zod-to-json-schema/parsers/union.ts +119 -0
- package/src/_vendor/zod-to-json-schema/parsers/unknown.ts +5 -0
- package/src/_vendor/zod-to-json-schema/zodToJsonSchema.ts +91 -0
- package/src/error.ts +12 -0
- package/src/helpers/zod.ts +102 -0
- package/src/index.ts +8 -0
- package/src/lib/AbstractChatCompletionRunner.ts +72 -258
- package/src/lib/AssistantStream.ts +47 -19
- package/src/lib/ChatCompletionRunner.ts +16 -12
- package/src/lib/ChatCompletionStream.ts +423 -47
- package/src/lib/ChatCompletionStreamingRunner.ts +19 -15
- package/src/lib/{AbstractAssistantStreamRunner.ts → EventStream.ts} +37 -138
- package/src/lib/RunnableFunction.ts +4 -2
- package/src/lib/parser.ts +235 -0
- package/src/resources/audio/audio.ts +5 -0
- package/src/resources/audio/index.ts +2 -2
- package/src/resources/audio/speech.ts +4 -1
- package/src/resources/audio/transcriptions.ts +2 -1
- package/src/resources/audio/translations.ts +2 -1
- package/src/resources/beta/assistants.ts +19 -26
- package/src/resources/beta/beta.ts +0 -1
- package/src/resources/beta/chat/completions.ts +77 -27
- package/src/resources/beta/index.ts +0 -1
- package/src/resources/beta/threads/index.ts +2 -1
- package/src/resources/beta/threads/messages.ts +41 -2
- package/src/resources/beta/threads/runs/runs.ts +12 -25
- package/src/resources/beta/threads/threads.ts +26 -32
- package/src/resources/beta/vector-stores/files.ts +1 -1
- package/src/resources/chat/chat.ts +2 -0
- package/src/resources/chat/completions.ts +47 -27
- package/src/resources/chat/index.ts +1 -0
- package/src/resources/fine-tuning/jobs/jobs.ts +3 -3
- package/src/resources/images.ts +6 -3
- package/src/resources/index.ts +9 -2
- package/src/resources/moderations.ts +4 -1
- package/src/resources/shared.ts +62 -0
- package/src/version.ts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/lib/AbstractAssistantStreamRunner.d.ts +0 -74
- package/lib/AbstractAssistantStreamRunner.d.ts.map +0 -1
- package/lib/AbstractAssistantStreamRunner.js +0 -246
- package/lib/AbstractAssistantStreamRunner.js.map +0 -1
- package/lib/AbstractAssistantStreamRunner.mjs +0 -242
- package/lib/AbstractAssistantStreamRunner.mjs.map +0 -1
- package/lib/ChatCompletionRunFunctions.test.d.ts +0 -2
- package/lib/ChatCompletionRunFunctions.test.d.ts.map +0 -1
- package/lib/ChatCompletionRunFunctions.test.js +0 -2177
- package/lib/ChatCompletionRunFunctions.test.js.map +0 -1
- package/lib/ChatCompletionRunFunctions.test.mjs +0 -2172
- package/lib/ChatCompletionRunFunctions.test.mjs.map +0 -1
- package/src/lib/ChatCompletionRunFunctions.test.ts +0 -2328
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { ZodStringDef } from 'zod';
|
|
3
|
+
import { ErrorMessages, setResponseValueAndErrors } from '../errorMessages';
|
|
4
|
+
import { Refs } from '../Refs';
|
|
5
|
+
|
|
6
|
+
let emojiRegex: RegExp | undefined;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Generated from the regular expressions found here as of 2024-05-22:
|
|
10
|
+
* https://github.com/colinhacks/zod/blob/master/src/types.ts.
|
|
11
|
+
*
|
|
12
|
+
* Expressions with /i flag have been changed accordingly.
|
|
13
|
+
*/
|
|
14
|
+
export const zodPatterns = {
|
|
15
|
+
/**
|
|
16
|
+
* `c` was changed to `[cC]` to replicate /i flag
|
|
17
|
+
*/
|
|
18
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
19
|
+
cuid2: /^[0-9a-z]+$/,
|
|
20
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
21
|
+
/**
|
|
22
|
+
* `a-z` was added to replicate /i flag
|
|
23
|
+
*/
|
|
24
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
25
|
+
/**
|
|
26
|
+
* Constructed a valid Unicode RegExp
|
|
27
|
+
*
|
|
28
|
+
* Lazily instantiate since this type of regex isn't supported
|
|
29
|
+
* in all envs (e.g. React Native).
|
|
30
|
+
*
|
|
31
|
+
* See:
|
|
32
|
+
* https://github.com/colinhacks/zod/issues/2433
|
|
33
|
+
* Fix in Zod:
|
|
34
|
+
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
35
|
+
*/
|
|
36
|
+
emoji: () => {
|
|
37
|
+
if (emojiRegex === undefined) {
|
|
38
|
+
emojiRegex = RegExp('^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$', 'u');
|
|
39
|
+
}
|
|
40
|
+
return emojiRegex;
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* Unused
|
|
44
|
+
*/
|
|
45
|
+
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
46
|
+
/**
|
|
47
|
+
* Unused
|
|
48
|
+
*/
|
|
49
|
+
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
50
|
+
/**
|
|
51
|
+
* Unused
|
|
52
|
+
*/
|
|
53
|
+
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
54
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
55
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
56
|
+
} as const;
|
|
57
|
+
|
|
58
|
+
export type JsonSchema7StringType = {
|
|
59
|
+
type: 'string';
|
|
60
|
+
minLength?: number;
|
|
61
|
+
maxLength?: number;
|
|
62
|
+
format?:
|
|
63
|
+
| 'email'
|
|
64
|
+
| 'idn-email'
|
|
65
|
+
| 'uri'
|
|
66
|
+
| 'uuid'
|
|
67
|
+
| 'date-time'
|
|
68
|
+
| 'ipv4'
|
|
69
|
+
| 'ipv6'
|
|
70
|
+
| 'date'
|
|
71
|
+
| 'time'
|
|
72
|
+
| 'duration';
|
|
73
|
+
pattern?: string;
|
|
74
|
+
allOf?: {
|
|
75
|
+
pattern: string;
|
|
76
|
+
errorMessage?: ErrorMessages<{ pattern: string }>;
|
|
77
|
+
}[];
|
|
78
|
+
anyOf?: {
|
|
79
|
+
format: string;
|
|
80
|
+
errorMessage?: ErrorMessages<{ format: string }>;
|
|
81
|
+
}[];
|
|
82
|
+
errorMessage?: ErrorMessages<JsonSchema7StringType>;
|
|
83
|
+
contentEncoding?: string;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export function parseStringDef(def: ZodStringDef, refs: Refs): JsonSchema7StringType {
|
|
87
|
+
const res: JsonSchema7StringType = {
|
|
88
|
+
type: 'string',
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
function processPattern(value: string): string {
|
|
92
|
+
return refs.patternStrategy === 'escape' ? escapeNonAlphaNumeric(value) : value;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (def.checks) {
|
|
96
|
+
for (const check of def.checks) {
|
|
97
|
+
switch (check.kind) {
|
|
98
|
+
case 'min':
|
|
99
|
+
setResponseValueAndErrors(
|
|
100
|
+
res,
|
|
101
|
+
'minLength',
|
|
102
|
+
typeof res.minLength === 'number' ? Math.max(res.minLength, check.value) : check.value,
|
|
103
|
+
check.message,
|
|
104
|
+
refs,
|
|
105
|
+
);
|
|
106
|
+
break;
|
|
107
|
+
case 'max':
|
|
108
|
+
setResponseValueAndErrors(
|
|
109
|
+
res,
|
|
110
|
+
'maxLength',
|
|
111
|
+
typeof res.maxLength === 'number' ? Math.min(res.maxLength, check.value) : check.value,
|
|
112
|
+
check.message,
|
|
113
|
+
refs,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
break;
|
|
117
|
+
case 'email':
|
|
118
|
+
switch (refs.emailStrategy) {
|
|
119
|
+
case 'format:email':
|
|
120
|
+
addFormat(res, 'email', check.message, refs);
|
|
121
|
+
break;
|
|
122
|
+
case 'format:idn-email':
|
|
123
|
+
addFormat(res, 'idn-email', check.message, refs);
|
|
124
|
+
break;
|
|
125
|
+
case 'pattern:zod':
|
|
126
|
+
addPattern(res, zodPatterns.email, check.message, refs);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
break;
|
|
131
|
+
case 'url':
|
|
132
|
+
addFormat(res, 'uri', check.message, refs);
|
|
133
|
+
break;
|
|
134
|
+
case 'uuid':
|
|
135
|
+
addFormat(res, 'uuid', check.message, refs);
|
|
136
|
+
break;
|
|
137
|
+
case 'regex':
|
|
138
|
+
addPattern(res, check.regex, check.message, refs);
|
|
139
|
+
break;
|
|
140
|
+
case 'cuid':
|
|
141
|
+
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
142
|
+
break;
|
|
143
|
+
case 'cuid2':
|
|
144
|
+
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
145
|
+
break;
|
|
146
|
+
case 'startsWith':
|
|
147
|
+
addPattern(res, RegExp(`^${processPattern(check.value)}`), check.message, refs);
|
|
148
|
+
break;
|
|
149
|
+
case 'endsWith':
|
|
150
|
+
addPattern(res, RegExp(`${processPattern(check.value)}$`), check.message, refs);
|
|
151
|
+
break;
|
|
152
|
+
|
|
153
|
+
case 'datetime':
|
|
154
|
+
addFormat(res, 'date-time', check.message, refs);
|
|
155
|
+
break;
|
|
156
|
+
case 'date':
|
|
157
|
+
addFormat(res, 'date', check.message, refs);
|
|
158
|
+
break;
|
|
159
|
+
case 'time':
|
|
160
|
+
addFormat(res, 'time', check.message, refs);
|
|
161
|
+
break;
|
|
162
|
+
case 'duration':
|
|
163
|
+
addFormat(res, 'duration', check.message, refs);
|
|
164
|
+
break;
|
|
165
|
+
case 'length':
|
|
166
|
+
setResponseValueAndErrors(
|
|
167
|
+
res,
|
|
168
|
+
'minLength',
|
|
169
|
+
typeof res.minLength === 'number' ? Math.max(res.minLength, check.value) : check.value,
|
|
170
|
+
check.message,
|
|
171
|
+
refs,
|
|
172
|
+
);
|
|
173
|
+
setResponseValueAndErrors(
|
|
174
|
+
res,
|
|
175
|
+
'maxLength',
|
|
176
|
+
typeof res.maxLength === 'number' ? Math.min(res.maxLength, check.value) : check.value,
|
|
177
|
+
check.message,
|
|
178
|
+
refs,
|
|
179
|
+
);
|
|
180
|
+
break;
|
|
181
|
+
case 'includes': {
|
|
182
|
+
addPattern(res, RegExp(processPattern(check.value)), check.message, refs);
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
case 'ip': {
|
|
186
|
+
if (check.version !== 'v6') {
|
|
187
|
+
addFormat(res, 'ipv4', check.message, refs);
|
|
188
|
+
}
|
|
189
|
+
if (check.version !== 'v4') {
|
|
190
|
+
addFormat(res, 'ipv6', check.message, refs);
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case 'emoji':
|
|
195
|
+
addPattern(res, zodPatterns.emoji, check.message, refs);
|
|
196
|
+
break;
|
|
197
|
+
case 'ulid': {
|
|
198
|
+
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
case 'base64': {
|
|
202
|
+
switch (refs.base64Strategy) {
|
|
203
|
+
case 'format:binary': {
|
|
204
|
+
addFormat(res, 'binary' as any, check.message, refs);
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
case 'contentEncoding:base64': {
|
|
209
|
+
setResponseValueAndErrors(res, 'contentEncoding', 'base64', check.message, refs);
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
case 'pattern:zod': {
|
|
214
|
+
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
case 'nanoid': {
|
|
221
|
+
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
222
|
+
}
|
|
223
|
+
case 'toLowerCase':
|
|
224
|
+
case 'toUpperCase':
|
|
225
|
+
case 'trim':
|
|
226
|
+
break;
|
|
227
|
+
default:
|
|
228
|
+
((_: never) => {})(check);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return res;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const escapeNonAlphaNumeric = (value: string) =>
|
|
237
|
+
Array.from(value)
|
|
238
|
+
.map((c) => (/[a-zA-Z0-9]/.test(c) ? c : `\\${c}`))
|
|
239
|
+
.join('');
|
|
240
|
+
|
|
241
|
+
const addFormat = (
|
|
242
|
+
schema: JsonSchema7StringType,
|
|
243
|
+
value: Required<JsonSchema7StringType>['format'],
|
|
244
|
+
message: string | undefined,
|
|
245
|
+
refs: Refs,
|
|
246
|
+
) => {
|
|
247
|
+
if (schema.format || schema.anyOf?.some((x) => x.format)) {
|
|
248
|
+
if (!schema.anyOf) {
|
|
249
|
+
schema.anyOf = [];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (schema.format) {
|
|
253
|
+
schema.anyOf!.push({
|
|
254
|
+
format: schema.format,
|
|
255
|
+
...(schema.errorMessage &&
|
|
256
|
+
refs.errorMessages && {
|
|
257
|
+
errorMessage: { format: schema.errorMessage.format },
|
|
258
|
+
}),
|
|
259
|
+
});
|
|
260
|
+
delete schema.format;
|
|
261
|
+
if (schema.errorMessage) {
|
|
262
|
+
delete schema.errorMessage.format;
|
|
263
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
264
|
+
delete schema.errorMessage;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
schema.anyOf!.push({
|
|
270
|
+
format: value,
|
|
271
|
+
...(message && refs.errorMessages && { errorMessage: { format: message } }),
|
|
272
|
+
});
|
|
273
|
+
} else {
|
|
274
|
+
setResponseValueAndErrors(schema, 'format', value, message, refs);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const addPattern = (
|
|
279
|
+
schema: JsonSchema7StringType,
|
|
280
|
+
regex: RegExp | (() => RegExp),
|
|
281
|
+
message: string | undefined,
|
|
282
|
+
refs: Refs,
|
|
283
|
+
) => {
|
|
284
|
+
if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
|
|
285
|
+
if (!schema.allOf) {
|
|
286
|
+
schema.allOf = [];
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (schema.pattern) {
|
|
290
|
+
schema.allOf!.push({
|
|
291
|
+
pattern: schema.pattern,
|
|
292
|
+
...(schema.errorMessage &&
|
|
293
|
+
refs.errorMessages && {
|
|
294
|
+
errorMessage: { pattern: schema.errorMessage.pattern },
|
|
295
|
+
}),
|
|
296
|
+
});
|
|
297
|
+
delete schema.pattern;
|
|
298
|
+
if (schema.errorMessage) {
|
|
299
|
+
delete schema.errorMessage.pattern;
|
|
300
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
301
|
+
delete schema.errorMessage;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
schema.allOf!.push({
|
|
307
|
+
pattern: processRegExp(regex, refs),
|
|
308
|
+
...(message && refs.errorMessages && { errorMessage: { pattern: message } }),
|
|
309
|
+
});
|
|
310
|
+
} else {
|
|
311
|
+
setResponseValueAndErrors(schema, 'pattern', processRegExp(regex, refs), message, refs);
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
// Mutate z.string.regex() in a best attempt to accommodate for regex flags when applyRegexFlags is true
|
|
316
|
+
const processRegExp = (regexOrFunction: RegExp | (() => RegExp), refs: Refs): string => {
|
|
317
|
+
const regex = typeof regexOrFunction === 'function' ? regexOrFunction() : regexOrFunction;
|
|
318
|
+
if (!refs.applyRegexFlags || !regex.flags) return regex.source;
|
|
319
|
+
|
|
320
|
+
// Currently handled flags
|
|
321
|
+
const flags = {
|
|
322
|
+
i: regex.flags.includes('i'), // Case-insensitive
|
|
323
|
+
m: regex.flags.includes('m'), // `^` and `$` matches adjacent to newline characters
|
|
324
|
+
s: regex.flags.includes('s'), // `.` matches newlines
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// The general principle here is to step through each character, one at a time, applying mutations as flags require. We keep track when the current character is escaped, and when it's inside a group /like [this]/ or (also) a range like /[a-z]/. The following is fairly brittle imperative code; edit at your peril!
|
|
328
|
+
|
|
329
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
330
|
+
let pattern = '';
|
|
331
|
+
let isEscaped = false;
|
|
332
|
+
let inCharGroup = false;
|
|
333
|
+
let inCharRange = false;
|
|
334
|
+
|
|
335
|
+
for (let i = 0; i < source.length; i++) {
|
|
336
|
+
if (isEscaped) {
|
|
337
|
+
pattern += source[i];
|
|
338
|
+
isEscaped = false;
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (flags.i) {
|
|
343
|
+
if (inCharGroup) {
|
|
344
|
+
if (source[i].match(/[a-z]/)) {
|
|
345
|
+
if (inCharRange) {
|
|
346
|
+
pattern += source[i];
|
|
347
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
348
|
+
inCharRange = false;
|
|
349
|
+
} else if (source[i + 1] === '-' && source[i + 2]?.match(/[a-z]/)) {
|
|
350
|
+
pattern += source[i];
|
|
351
|
+
inCharRange = true;
|
|
352
|
+
} else {
|
|
353
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
354
|
+
}
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
358
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (flags.m) {
|
|
364
|
+
if (source[i] === '^') {
|
|
365
|
+
pattern += `(^|(?<=[\r\n]))`;
|
|
366
|
+
continue;
|
|
367
|
+
} else if (source[i] === '$') {
|
|
368
|
+
pattern += `($|(?=[\r\n]))`;
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (flags.s && source[i] === '.') {
|
|
374
|
+
pattern += inCharGroup ? `${source[i]}\r\n` : `[${source[i]}\r\n]`;
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
pattern += source[i];
|
|
379
|
+
if (source[i] === '\\') {
|
|
380
|
+
isEscaped = true;
|
|
381
|
+
} else if (inCharGroup && source[i] === ']') {
|
|
382
|
+
inCharGroup = false;
|
|
383
|
+
} else if (!inCharGroup && source[i] === '[') {
|
|
384
|
+
inCharGroup = true;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
try {
|
|
389
|
+
const regexTest = new RegExp(pattern);
|
|
390
|
+
} catch {
|
|
391
|
+
console.warn(
|
|
392
|
+
`Could not convert regex pattern at ${refs.currentPath.join(
|
|
393
|
+
'/',
|
|
394
|
+
)} to a flag-independent form! Falling back to the flag-ignorant source`,
|
|
395
|
+
);
|
|
396
|
+
return regex.source;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return pattern;
|
|
400
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ZodTupleDef, ZodTupleItems, ZodTypeAny } from 'zod';
|
|
2
|
+
import { JsonSchema7Type, parseDef } from '../parseDef';
|
|
3
|
+
import { Refs } from '../Refs';
|
|
4
|
+
|
|
5
|
+
export type JsonSchema7TupleType = {
|
|
6
|
+
type: 'array';
|
|
7
|
+
minItems: number;
|
|
8
|
+
items: JsonSchema7Type[];
|
|
9
|
+
} & (
|
|
10
|
+
| {
|
|
11
|
+
maxItems: number;
|
|
12
|
+
}
|
|
13
|
+
| {
|
|
14
|
+
additionalItems?: JsonSchema7Type | undefined;
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export function parseTupleDef(
|
|
19
|
+
def: ZodTupleDef<ZodTupleItems | [], ZodTypeAny | null>,
|
|
20
|
+
refs: Refs,
|
|
21
|
+
): JsonSchema7TupleType {
|
|
22
|
+
if (def.rest) {
|
|
23
|
+
return {
|
|
24
|
+
type: 'array',
|
|
25
|
+
minItems: def.items.length,
|
|
26
|
+
items: def.items
|
|
27
|
+
.map((x, i) =>
|
|
28
|
+
parseDef(x._def, {
|
|
29
|
+
...refs,
|
|
30
|
+
currentPath: [...refs.currentPath, 'items', `${i}`],
|
|
31
|
+
}),
|
|
32
|
+
)
|
|
33
|
+
.reduce((acc: JsonSchema7Type[], x) => (x === undefined ? acc : [...acc, x]), []),
|
|
34
|
+
additionalItems: parseDef(def.rest._def, {
|
|
35
|
+
...refs,
|
|
36
|
+
currentPath: [...refs.currentPath, 'additionalItems'],
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
} else {
|
|
40
|
+
return {
|
|
41
|
+
type: 'array',
|
|
42
|
+
minItems: def.items.length,
|
|
43
|
+
maxItems: def.items.length,
|
|
44
|
+
items: def.items
|
|
45
|
+
.map((x, i) =>
|
|
46
|
+
parseDef(x._def, {
|
|
47
|
+
...refs,
|
|
48
|
+
currentPath: [...refs.currentPath, 'items', `${i}`],
|
|
49
|
+
}),
|
|
50
|
+
)
|
|
51
|
+
.reduce((acc: JsonSchema7Type[], x) => (x === undefined ? acc : [...acc, x]), []),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { ZodDiscriminatedUnionDef, ZodLiteralDef, ZodTypeAny, ZodUnionDef } from 'zod';
|
|
2
|
+
import { JsonSchema7Type, parseDef } from '../parseDef';
|
|
3
|
+
import { Refs } from '../Refs';
|
|
4
|
+
|
|
5
|
+
export const primitiveMappings = {
|
|
6
|
+
ZodString: 'string',
|
|
7
|
+
ZodNumber: 'number',
|
|
8
|
+
ZodBigInt: 'integer',
|
|
9
|
+
ZodBoolean: 'boolean',
|
|
10
|
+
ZodNull: 'null',
|
|
11
|
+
} as const;
|
|
12
|
+
type ZodPrimitive = keyof typeof primitiveMappings;
|
|
13
|
+
type JsonSchema7Primitive = (typeof primitiveMappings)[keyof typeof primitiveMappings];
|
|
14
|
+
|
|
15
|
+
export type JsonSchema7UnionType = JsonSchema7PrimitiveUnionType | JsonSchema7AnyOfType;
|
|
16
|
+
|
|
17
|
+
type JsonSchema7PrimitiveUnionType =
|
|
18
|
+
| {
|
|
19
|
+
type: JsonSchema7Primitive | JsonSchema7Primitive[];
|
|
20
|
+
}
|
|
21
|
+
| {
|
|
22
|
+
type: JsonSchema7Primitive | JsonSchema7Primitive[];
|
|
23
|
+
enum: (string | number | bigint | boolean | null)[];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type JsonSchema7AnyOfType = {
|
|
27
|
+
anyOf: JsonSchema7Type[];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export function parseUnionDef(
|
|
31
|
+
def: ZodUnionDef | ZodDiscriminatedUnionDef<any, any>,
|
|
32
|
+
refs: Refs,
|
|
33
|
+
): JsonSchema7PrimitiveUnionType | JsonSchema7AnyOfType | undefined {
|
|
34
|
+
if (refs.target === 'openApi3') return asAnyOf(def, refs);
|
|
35
|
+
|
|
36
|
+
const options: readonly ZodTypeAny[] =
|
|
37
|
+
def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
38
|
+
|
|
39
|
+
// This blocks tries to look ahead a bit to produce nicer looking schemas with type array instead of anyOf.
|
|
40
|
+
if (
|
|
41
|
+
options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))
|
|
42
|
+
) {
|
|
43
|
+
// all types in union are primitive and lack checks, so might as well squash into {type: [...]}
|
|
44
|
+
|
|
45
|
+
const types = options.reduce((types: JsonSchema7Primitive[], x) => {
|
|
46
|
+
const type = primitiveMappings[x._def.typeName as ZodPrimitive]; //Can be safely casted due to row 43
|
|
47
|
+
return type && !types.includes(type) ? [...types, type] : types;
|
|
48
|
+
}, []);
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
type: types.length > 1 ? types : types[0]!,
|
|
52
|
+
};
|
|
53
|
+
} else if (options.every((x) => x._def.typeName === 'ZodLiteral' && !x.description)) {
|
|
54
|
+
// all options literals
|
|
55
|
+
|
|
56
|
+
const types = options.reduce((acc: JsonSchema7Primitive[], x: { _def: ZodLiteralDef }) => {
|
|
57
|
+
const type = typeof x._def.value;
|
|
58
|
+
switch (type) {
|
|
59
|
+
case 'string':
|
|
60
|
+
case 'number':
|
|
61
|
+
case 'boolean':
|
|
62
|
+
return [...acc, type];
|
|
63
|
+
case 'bigint':
|
|
64
|
+
return [...acc, 'integer' as const];
|
|
65
|
+
case 'object':
|
|
66
|
+
if (x._def.value === null) return [...acc, 'null' as const];
|
|
67
|
+
case 'symbol':
|
|
68
|
+
case 'undefined':
|
|
69
|
+
case 'function':
|
|
70
|
+
default:
|
|
71
|
+
return acc;
|
|
72
|
+
}
|
|
73
|
+
}, []);
|
|
74
|
+
|
|
75
|
+
if (types.length === options.length) {
|
|
76
|
+
// all the literals are primitive, as far as null can be considered primitive
|
|
77
|
+
|
|
78
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
79
|
+
return {
|
|
80
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0]!,
|
|
81
|
+
enum: options.reduce(
|
|
82
|
+
(acc, x) => {
|
|
83
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
84
|
+
},
|
|
85
|
+
[] as (string | number | bigint | boolean | null)[],
|
|
86
|
+
),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
} else if (options.every((x) => x._def.typeName === 'ZodEnum')) {
|
|
90
|
+
return {
|
|
91
|
+
type: 'string',
|
|
92
|
+
enum: options.reduce(
|
|
93
|
+
(acc: string[], x) => [...acc, ...x._def.values.filter((x: string) => !acc.includes(x))],
|
|
94
|
+
[],
|
|
95
|
+
),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return asAnyOf(def, refs);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const asAnyOf = (
|
|
103
|
+
def: ZodUnionDef | ZodDiscriminatedUnionDef<any, any>,
|
|
104
|
+
refs: Refs,
|
|
105
|
+
): JsonSchema7PrimitiveUnionType | JsonSchema7AnyOfType | undefined => {
|
|
106
|
+
const anyOf = ((def.options instanceof Map ? Array.from(def.options.values()) : def.options) as any[])
|
|
107
|
+
.map((x, i) =>
|
|
108
|
+
parseDef(x._def, {
|
|
109
|
+
...refs,
|
|
110
|
+
currentPath: [...refs.currentPath, 'anyOf', `${i}`],
|
|
111
|
+
}),
|
|
112
|
+
)
|
|
113
|
+
.filter(
|
|
114
|
+
(x): x is JsonSchema7Type =>
|
|
115
|
+
!!x && (!refs.strictUnions || (typeof x === 'object' && Object.keys(x).length > 0)),
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
return anyOf.length ? { anyOf } : undefined;
|
|
119
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ZodSchema } from 'zod';
|
|
2
|
+
import { Options, Targets } from './Options';
|
|
3
|
+
import { JsonSchema7Type, parseDef } from './parseDef';
|
|
4
|
+
import { getRefs } from './Refs';
|
|
5
|
+
|
|
6
|
+
const zodToJsonSchema = <Target extends Targets = 'jsonSchema7'>(
|
|
7
|
+
schema: ZodSchema<any>,
|
|
8
|
+
options?: Partial<Options<Target>> | string,
|
|
9
|
+
): (Target extends 'jsonSchema7' ? JsonSchema7Type : object) & {
|
|
10
|
+
$schema?: string;
|
|
11
|
+
definitions?: {
|
|
12
|
+
[key: string]: Target extends 'jsonSchema7' ? JsonSchema7Type
|
|
13
|
+
: Target extends 'jsonSchema2019-09' ? JsonSchema7Type
|
|
14
|
+
: object;
|
|
15
|
+
};
|
|
16
|
+
} => {
|
|
17
|
+
const refs = getRefs(options);
|
|
18
|
+
|
|
19
|
+
const definitions =
|
|
20
|
+
typeof options === 'object' && options.definitions ?
|
|
21
|
+
Object.entries(options.definitions).reduce(
|
|
22
|
+
(acc, [name, schema]) => ({
|
|
23
|
+
...acc,
|
|
24
|
+
[name]:
|
|
25
|
+
parseDef(
|
|
26
|
+
schema._def,
|
|
27
|
+
{
|
|
28
|
+
...refs,
|
|
29
|
+
currentPath: [...refs.basePath, refs.definitionPath, name],
|
|
30
|
+
},
|
|
31
|
+
true,
|
|
32
|
+
) ?? {},
|
|
33
|
+
}),
|
|
34
|
+
{},
|
|
35
|
+
)
|
|
36
|
+
: undefined;
|
|
37
|
+
|
|
38
|
+
const name =
|
|
39
|
+
typeof options === 'string' ? options
|
|
40
|
+
: options?.nameStrategy === 'title' ? undefined
|
|
41
|
+
: options?.name;
|
|
42
|
+
|
|
43
|
+
const main =
|
|
44
|
+
parseDef(
|
|
45
|
+
schema._def,
|
|
46
|
+
name === undefined ? refs : (
|
|
47
|
+
{
|
|
48
|
+
...refs,
|
|
49
|
+
currentPath: [...refs.basePath, refs.definitionPath, name],
|
|
50
|
+
}
|
|
51
|
+
),
|
|
52
|
+
false,
|
|
53
|
+
) ?? {};
|
|
54
|
+
|
|
55
|
+
const title =
|
|
56
|
+
typeof options === 'object' && options.name !== undefined && options.nameStrategy === 'title' ?
|
|
57
|
+
options.name
|
|
58
|
+
: undefined;
|
|
59
|
+
|
|
60
|
+
if (title !== undefined) {
|
|
61
|
+
main.title = title;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const combined: ReturnType<typeof zodToJsonSchema<Target>> =
|
|
65
|
+
name === undefined ?
|
|
66
|
+
definitions ?
|
|
67
|
+
{
|
|
68
|
+
...main,
|
|
69
|
+
[refs.definitionPath]: definitions,
|
|
70
|
+
}
|
|
71
|
+
: main
|
|
72
|
+
: {
|
|
73
|
+
$ref: [...(refs.$refStrategy === 'relative' ? [] : refs.basePath), refs.definitionPath, name].join(
|
|
74
|
+
'/',
|
|
75
|
+
),
|
|
76
|
+
[refs.definitionPath]: {
|
|
77
|
+
...definitions,
|
|
78
|
+
[name]: main,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
if (refs.target === 'jsonSchema7') {
|
|
83
|
+
combined.$schema = 'http://json-schema.org/draft-07/schema#';
|
|
84
|
+
} else if (refs.target === 'jsonSchema2019-09') {
|
|
85
|
+
combined.$schema = 'https://json-schema.org/draft/2019-09/schema#';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return combined;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export { zodToJsonSchema };
|
package/src/error.ts
CHANGED
|
@@ -156,3 +156,15 @@ export class RateLimitError extends APIError {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
export class InternalServerError extends APIError {}
|
|
159
|
+
|
|
160
|
+
export class LengthFinishReasonError extends OpenAIError {
|
|
161
|
+
constructor() {
|
|
162
|
+
super(`Could not parse response content as the length limit was reached`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export class ContentFilterFinishReasonError extends OpenAIError {
|
|
167
|
+
constructor() {
|
|
168
|
+
super(`Could not parse response content as the request was rejected by the content filter`);
|
|
169
|
+
}
|
|
170
|
+
}
|