openai 7.4.0 → 7.6.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 +424 -0
- package/README.md +59 -12
- package/_vendor/partial-json-parser/parser.d.mts.map +1 -1
- package/_vendor/partial-json-parser/parser.d.ts.map +1 -1
- package/_vendor/partial-json-parser/parser.js +52 -36
- package/_vendor/partial-json-parser/parser.js.map +1 -1
- package/_vendor/partial-json-parser/parser.mjs +52 -36
- package/_vendor/partial-json-parser/parser.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/Options.d.mts +3 -3
- package/_vendor/zod-to-json-schema/Options.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/Options.d.ts +3 -3
- package/_vendor/zod-to-json-schema/Options.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/Options.js +9 -2
- package/_vendor/zod-to-json-schema/Options.js.map +1 -1
- package/_vendor/zod-to-json-schema/Options.mjs +9 -2
- package/_vendor/zod-to-json-schema/Options.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/Refs.d.mts +2 -2
- package/_vendor/zod-to-json-schema/Refs.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/Refs.d.ts +2 -2
- package/_vendor/zod-to-json-schema/Refs.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/Refs.js +4 -4
- package/_vendor/zod-to-json-schema/Refs.js.map +1 -1
- package/_vendor/zod-to-json-schema/Refs.mjs +4 -4
- package/_vendor/zod-to-json-schema/Refs.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/errorMessages.d.mts +2 -2
- package/_vendor/zod-to-json-schema/errorMessages.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/errorMessages.d.ts +2 -2
- package/_vendor/zod-to-json-schema/errorMessages.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/errorMessages.js +2 -1
- package/_vendor/zod-to-json-schema/errorMessages.js.map +1 -1
- package/_vendor/zod-to-json-schema/errorMessages.mjs +2 -1
- package/_vendor/zod-to-json-schema/errorMessages.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/index.d.mts +1 -1
- package/_vendor/zod-to-json-schema/index.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/index.d.ts +1 -1
- package/_vendor/zod-to-json-schema/index.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/index.js +1 -1
- package/_vendor/zod-to-json-schema/index.js.map +1 -1
- package/_vendor/zod-to-json-schema/index.mjs +1 -1
- package/_vendor/zod-to-json-schema/index.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parseDef.d.mts +24 -24
- package/_vendor/zod-to-json-schema/parseDef.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parseDef.d.ts +24 -24
- package/_vendor/zod-to-json-schema/parseDef.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parseDef.js +98 -40
- package/_vendor/zod-to-json-schema/parseDef.js.map +1 -1
- package/_vendor/zod-to-json-schema/parseDef.mjs +98 -40
- package/_vendor/zod-to-json-schema/parseDef.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/array.d.mts +4 -4
- package/_vendor/zod-to-json-schema/parsers/array.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/array.d.ts +4 -4
- package/_vendor/zod-to-json-schema/parsers/array.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/array.js +1 -1
- package/_vendor/zod-to-json-schema/parsers/array.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/array.mjs +1 -1
- package/_vendor/zod-to-json-schema/parsers/array.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/bigint.d.mts +8 -8
- package/_vendor/zod-to-json-schema/parsers/bigint.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/bigint.d.ts +8 -8
- package/_vendor/zod-to-json-schema/parsers/bigint.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/bigint.js +8 -4
- package/_vendor/zod-to-json-schema/parsers/bigint.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/bigint.mjs +8 -4
- package/_vendor/zod-to-json-schema/parsers/bigint.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/branded.d.mts +3 -3
- package/_vendor/zod-to-json-schema/parsers/branded.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/branded.d.ts +3 -3
- package/_vendor/zod-to-json-schema/parsers/branded.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/catch.d.mts +3 -3
- package/_vendor/zod-to-json-schema/parsers/catch.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/catch.d.ts +3 -3
- package/_vendor/zod-to-json-schema/parsers/catch.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/catch.js +1 -3
- package/_vendor/zod-to-json-schema/parsers/catch.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/catch.mjs +1 -3
- package/_vendor/zod-to-json-schema/parsers/catch.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/date.d.mts +5 -5
- package/_vendor/zod-to-json-schema/parsers/date.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/date.d.ts +5 -5
- package/_vendor/zod-to-json-schema/parsers/date.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/date.js +10 -5
- package/_vendor/zod-to-json-schema/parsers/date.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/date.mjs +10 -5
- package/_vendor/zod-to-json-schema/parsers/date.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/default.d.mts +3 -3
- package/_vendor/zod-to-json-schema/parsers/default.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/default.d.ts +3 -3
- package/_vendor/zod-to-json-schema/parsers/default.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/default.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/default.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/effects.d.mts +3 -3
- package/_vendor/zod-to-json-schema/parsers/effects.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/effects.d.ts +3 -3
- package/_vendor/zod-to-json-schema/parsers/effects.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/effects.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/effects.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/enum.d.mts +1 -1
- package/_vendor/zod-to-json-schema/parsers/enum.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/enum.d.ts +1 -1
- package/_vendor/zod-to-json-schema/parsers/enum.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/intersection.d.mts +3 -3
- package/_vendor/zod-to-json-schema/parsers/intersection.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/intersection.d.ts +3 -3
- package/_vendor/zod-to-json-schema/parsers/intersection.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/intersection.js +6 -5
- package/_vendor/zod-to-json-schema/parsers/intersection.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/intersection.mjs +6 -5
- package/_vendor/zod-to-json-schema/parsers/intersection.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/literal.d.mts +5 -2
- package/_vendor/zod-to-json-schema/parsers/literal.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/literal.d.ts +5 -2
- package/_vendor/zod-to-json-schema/parsers/literal.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/literal.js +4 -0
- package/_vendor/zod-to-json-schema/parsers/literal.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/literal.mjs +4 -0
- package/_vendor/zod-to-json-schema/parsers/literal.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/map.d.mts +4 -4
- package/_vendor/zod-to-json-schema/parsers/map.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/map.d.ts +4 -4
- package/_vendor/zod-to-json-schema/parsers/map.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/map.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/map.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.d.mts +1 -1
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.d.ts +1 -1
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.js +7 -9
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.mjs +7 -9
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/null.d.mts +1 -1
- package/_vendor/zod-to-json-schema/parsers/null.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/null.d.ts +1 -1
- package/_vendor/zod-to-json-schema/parsers/null.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/null.js +2 -2
- package/_vendor/zod-to-json-schema/parsers/null.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/null.mjs +2 -2
- package/_vendor/zod-to-json-schema/parsers/null.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/nullable.d.mts +4 -4
- package/_vendor/zod-to-json-schema/parsers/nullable.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/nullable.d.ts +4 -4
- package/_vendor/zod-to-json-schema/parsers/nullable.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/nullable.js +2 -1
- package/_vendor/zod-to-json-schema/parsers/nullable.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/nullable.mjs +2 -1
- package/_vendor/zod-to-json-schema/parsers/nullable.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/number.d.mts +3 -3
- package/_vendor/zod-to-json-schema/parsers/number.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/number.d.ts +3 -3
- package/_vendor/zod-to-json-schema/parsers/number.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/number.js +10 -5
- package/_vendor/zod-to-json-schema/parsers/number.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/number.mjs +10 -5
- package/_vendor/zod-to-json-schema/parsers/number.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/object.d.mts +3 -3
- package/_vendor/zod-to-json-schema/parsers/object.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/object.d.ts +3 -3
- package/_vendor/zod-to-json-schema/parsers/object.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/object.js +43 -38
- package/_vendor/zod-to-json-schema/parsers/object.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/object.mjs +43 -38
- package/_vendor/zod-to-json-schema/parsers/object.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/optional.d.mts +3 -3
- package/_vendor/zod-to-json-schema/parsers/optional.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/optional.d.ts +3 -3
- package/_vendor/zod-to-json-schema/parsers/optional.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/optional.js +2 -2
- package/_vendor/zod-to-json-schema/parsers/optional.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/optional.mjs +2 -2
- package/_vendor/zod-to-json-schema/parsers/optional.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/pipeline.d.mts +4 -4
- package/_vendor/zod-to-json-schema/parsers/pipeline.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/pipeline.d.ts +4 -4
- package/_vendor/zod-to-json-schema/parsers/pipeline.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/pipeline.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/pipeline.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/promise.d.mts +3 -3
- package/_vendor/zod-to-json-schema/parsers/promise.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/promise.d.ts +3 -3
- package/_vendor/zod-to-json-schema/parsers/promise.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/promise.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/promise.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/readonly.d.mts +3 -3
- package/_vendor/zod-to-json-schema/parsers/readonly.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/readonly.d.ts +3 -3
- package/_vendor/zod-to-json-schema/parsers/readonly.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/readonly.js +1 -3
- package/_vendor/zod-to-json-schema/parsers/readonly.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/readonly.mjs +1 -3
- package/_vendor/zod-to-json-schema/parsers/readonly.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/record.d.mts +5 -5
- package/_vendor/zod-to-json-schema/parsers/record.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/record.d.ts +5 -5
- package/_vendor/zod-to-json-schema/parsers/record.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/record.js +5 -5
- package/_vendor/zod-to-json-schema/parsers/record.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/record.mjs +5 -5
- package/_vendor/zod-to-json-schema/parsers/record.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/set.d.mts +4 -4
- package/_vendor/zod-to-json-schema/parsers/set.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/set.d.ts +4 -4
- package/_vendor/zod-to-json-schema/parsers/set.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/set.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/set.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/string.d.mts +3 -3
- package/_vendor/zod-to-json-schema/parsers/string.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/string.d.ts +3 -3
- package/_vendor/zod-to-json-schema/parsers/string.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/string.js +55 -33
- package/_vendor/zod-to-json-schema/parsers/string.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/string.mjs +55 -33
- package/_vendor/zod-to-json-schema/parsers/string.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/tuple.d.mts +3 -3
- package/_vendor/zod-to-json-schema/parsers/tuple.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/tuple.d.ts +3 -3
- package/_vendor/zod-to-json-schema/parsers/tuple.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/tuple.js +12 -14
- package/_vendor/zod-to-json-schema/parsers/tuple.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/tuple.mjs +12 -14
- package/_vendor/zod-to-json-schema/parsers/tuple.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/union.d.mts +3 -3
- package/_vendor/zod-to-json-schema/parsers/union.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/union.d.ts +3 -3
- package/_vendor/zod-to-json-schema/parsers/union.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/union.js +43 -24
- package/_vendor/zod-to-json-schema/parsers/union.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/union.mjs +43 -24
- package/_vendor/zod-to-json-schema/parsers/union.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/util.d.mts +1 -1
- package/_vendor/zod-to-json-schema/util.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/util.d.ts +1 -1
- package/_vendor/zod-to-json-schema/util.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/util.js +6 -5
- package/_vendor/zod-to-json-schema/util.js.map +1 -1
- package/_vendor/zod-to-json-schema/util.mjs +6 -5
- package/_vendor/zod-to-json-schema/util.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/zodToJsonSchema.d.mts +4 -6
- package/_vendor/zod-to-json-schema/zodToJsonSchema.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/zodToJsonSchema.d.ts +4 -6
- package/_vendor/zod-to-json-schema/zodToJsonSchema.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/zodToJsonSchema.js +102 -36
- package/_vendor/zod-to-json-schema/zodToJsonSchema.js.map +1 -1
- package/_vendor/zod-to-json-schema/zodToJsonSchema.mjs +102 -36
- package/_vendor/zod-to-json-schema/zodToJsonSchema.mjs.map +1 -1
- package/auth/index.d.mts +1 -1
- package/auth/index.d.mts.map +1 -1
- package/auth/index.d.ts +1 -1
- package/auth/index.d.ts.map +1 -1
- package/auth/index.js.map +1 -1
- package/auth/index.mjs.map +1 -1
- package/auth/subject-token-providers.d.mts +52 -0
- package/auth/subject-token-providers.d.mts.map +1 -1
- package/auth/subject-token-providers.d.ts +52 -0
- package/auth/subject-token-providers.d.ts.map +1 -1
- package/auth/subject-token-providers.js +222 -7
- package/auth/subject-token-providers.js.map +1 -1
- package/auth/subject-token-providers.mjs +222 -7
- package/auth/subject-token-providers.mjs.map +1 -1
- package/auth/types.d.mts +31 -5
- package/auth/types.d.mts.map +1 -1
- package/auth/types.d.ts +31 -5
- package/auth/types.d.ts.map +1 -1
- package/auth/workload-identity-auth.d.mts +26 -1
- package/auth/workload-identity-auth.d.mts.map +1 -1
- package/auth/workload-identity-auth.d.ts +26 -1
- package/auth/workload-identity-auth.d.ts.map +1 -1
- package/auth/workload-identity-auth.js +139 -22
- package/auth/workload-identity-auth.js.map +1 -1
- package/auth/workload-identity-auth.mjs +139 -22
- package/auth/workload-identity-auth.mjs.map +1 -1
- package/auth/x509-transport.d.mts +5 -0
- package/auth/x509-transport.d.mts.map +1 -0
- package/auth/x509-transport.d.ts +5 -0
- package/auth/x509-transport.d.ts.map +1 -0
- package/auth/x509-transport.js +39 -0
- package/auth/x509-transport.js.map +1 -0
- package/auth/x509-transport.mjs +36 -0
- package/auth/x509-transport.mjs.map +1 -0
- package/azure.d.mts +38 -16
- package/azure.d.mts.map +1 -1
- package/azure.d.ts +38 -16
- package/azure.d.ts.map +1 -1
- package/azure.js +36 -19
- package/azure.js.map +1 -1
- package/azure.mjs +36 -19
- package/azure.mjs.map +1 -1
- package/bedrock.d.mts +23 -5
- package/bedrock.d.mts.map +1 -1
- package/bedrock.d.ts +23 -5
- package/bedrock.d.ts.map +1 -1
- package/bedrock.js +69 -8
- package/bedrock.js.map +1 -1
- package/bedrock.mjs +69 -8
- package/bedrock.mjs.map +1 -1
- package/beta/realtime/internal-base.d.mts +47 -4
- package/beta/realtime/internal-base.d.mts.map +1 -1
- package/beta/realtime/internal-base.d.ts +47 -4
- package/beta/realtime/internal-base.d.ts.map +1 -1
- package/beta/realtime/internal-base.js +53 -10
- package/beta/realtime/internal-base.js.map +1 -1
- package/beta/realtime/internal-base.mjs +52 -10
- package/beta/realtime/internal-base.mjs.map +1 -1
- package/beta/realtime/websocket.d.mts +63 -4
- package/beta/realtime/websocket.d.mts.map +1 -1
- package/beta/realtime/websocket.d.ts +63 -4
- package/beta/realtime/websocket.d.ts.map +1 -1
- package/beta/realtime/websocket.js +161 -26
- package/beta/realtime/websocket.js.map +1 -1
- package/beta/realtime/websocket.mjs +162 -27
- package/beta/realtime/websocket.mjs.map +1 -1
- package/beta/realtime/ws.d.mts +51 -3
- package/beta/realtime/ws.d.mts.map +1 -1
- package/beta/realtime/ws.d.ts +51 -3
- package/beta/realtime/ws.d.ts.map +1 -1
- package/beta/realtime/ws.js +82 -9
- package/beta/realtime/ws.js.map +1 -1
- package/beta/realtime/ws.mjs +83 -10
- package/beta/realtime/ws.mjs.map +1 -1
- package/client.d.mts +40 -2
- package/client.d.mts.map +1 -1
- package/client.d.ts +40 -2
- package/client.d.ts.map +1 -1
- package/client.js +597 -75
- package/client.js.map +1 -1
- package/client.mjs +598 -76
- package/client.mjs.map +1 -1
- package/core/EventEmitter.d.mts +10 -6
- package/core/EventEmitter.d.mts.map +1 -1
- package/core/EventEmitter.d.ts +10 -6
- package/core/EventEmitter.d.ts.map +1 -1
- package/core/EventEmitter.js +98 -16
- package/core/EventEmitter.js.map +1 -1
- package/core/EventEmitter.mjs +99 -17
- package/core/EventEmitter.mjs.map +1 -1
- package/core/api-promise.d.mts.map +1 -1
- package/core/api-promise.d.ts.map +1 -1
- package/core/api-promise.js +0 -1
- package/core/api-promise.js.map +1 -1
- package/core/api-promise.mjs +0 -1
- package/core/api-promise.mjs.map +1 -1
- package/core/error.d.mts.map +1 -1
- package/core/error.d.ts.map +1 -1
- package/core/error.js +5 -5
- package/core/error.js.map +1 -1
- package/core/error.mjs +5 -5
- package/core/error.mjs.map +1 -1
- package/core/pagination.d.mts.map +1 -1
- package/core/pagination.d.ts.map +1 -1
- package/core/pagination.js +0 -1
- package/core/pagination.js.map +1 -1
- package/core/pagination.mjs +0 -1
- package/core/pagination.mjs.map +1 -1
- package/core/resource.d.mts.map +1 -1
- package/core/resource.d.ts.map +1 -1
- package/core/resource.js +0 -1
- package/core/resource.js.map +1 -1
- package/core/resource.mjs +0 -1
- package/core/resource.mjs.map +1 -1
- package/core/streaming.d.mts +29 -2
- package/core/streaming.d.mts.map +1 -1
- package/core/streaming.d.ts +29 -2
- package/core/streaming.d.ts.map +1 -1
- package/core/streaming.js +177 -75
- package/core/streaming.js.map +1 -1
- package/core/streaming.mjs +177 -75
- package/core/streaming.mjs.map +1 -1
- package/helpers/audio.d.mts +29 -0
- package/helpers/audio.d.mts.map +1 -1
- package/helpers/audio.d.ts +29 -0
- package/helpers/audio.d.ts.map +1 -1
- package/helpers/audio.js +163 -28
- package/helpers/audio.js.map +1 -1
- package/helpers/audio.mjs +163 -28
- package/helpers/audio.mjs.map +1 -1
- package/helpers/standard-schema.d.mts +154 -18
- package/helpers/standard-schema.d.mts.map +1 -1
- package/helpers/standard-schema.d.ts +154 -18
- package/helpers/standard-schema.d.ts.map +1 -1
- package/helpers/standard-schema.js +92 -29
- package/helpers/standard-schema.js.map +1 -1
- package/helpers/standard-schema.mjs +93 -30
- package/helpers/standard-schema.mjs.map +1 -1
- package/helpers/zod-v3-strict-schema.d.mts +7 -0
- package/helpers/zod-v3-strict-schema.d.mts.map +1 -0
- package/helpers/zod-v3-strict-schema.d.ts +7 -0
- package/helpers/zod-v3-strict-schema.d.ts.map +1 -0
- package/helpers/zod-v3-strict-schema.js +403 -0
- package/helpers/zod-v3-strict-schema.js.map +1 -0
- package/helpers/zod-v3-strict-schema.mjs +399 -0
- package/helpers/zod-v3-strict-schema.mjs.map +1 -0
- package/helpers/zod.d.mts +79 -5
- package/helpers/zod.d.mts.map +1 -1
- package/helpers/zod.d.ts +79 -5
- package/helpers/zod.d.ts.map +1 -1
- package/helpers/zod.js +84 -23
- package/helpers/zod.js.map +1 -1
- package/helpers/zod.mjs +86 -25
- package/helpers/zod.mjs.map +1 -1
- package/index.d.mts +2 -2
- package/index.d.mts.map +1 -1
- package/index.d.ts +2 -2
- package/index.d.ts.map +1 -1
- package/index.js +0 -1
- package/index.js.map +1 -1
- package/index.mjs +0 -1
- package/index.mjs.map +1 -1
- package/internal/assistant-stream-delta.d.mts +7 -0
- package/internal/assistant-stream-delta.d.mts.map +1 -0
- package/internal/assistant-stream-delta.d.ts +7 -0
- package/internal/assistant-stream-delta.d.ts.map +1 -0
- package/internal/assistant-stream-delta.js +309 -0
- package/internal/assistant-stream-delta.js.map +1 -0
- package/internal/assistant-stream-delta.mjs +301 -0
- package/internal/assistant-stream-delta.mjs.map +1 -0
- package/internal/auth/x509-token-exchange.d.mts +16 -0
- package/internal/auth/x509-token-exchange.d.mts.map +1 -0
- package/internal/auth/x509-token-exchange.d.ts +16 -0
- package/internal/auth/x509-token-exchange.d.ts.map +1 -0
- package/internal/auth/x509-token-exchange.js +246 -0
- package/internal/auth/x509-token-exchange.js.map +1 -0
- package/internal/auth/x509-token-exchange.mjs +243 -0
- package/internal/auth/x509-token-exchange.mjs.map +1 -0
- package/internal/auth/x509-transport-capability.d.mts +37 -0
- package/internal/auth/x509-transport-capability.d.mts.map +1 -0
- package/internal/auth/x509-transport-capability.d.ts +37 -0
- package/internal/auth/x509-transport-capability.d.ts.map +1 -0
- package/internal/auth/x509-transport-capability.js +169 -0
- package/internal/auth/x509-transport-capability.js.map +1 -0
- package/internal/auth/x509-transport-capability.mjs +164 -0
- package/internal/auth/x509-transport-capability.mjs.map +1 -0
- package/internal/auth/x509-transport-registry.d.mts +63 -0
- package/internal/auth/x509-transport-registry.d.mts.map +1 -0
- package/internal/auth/x509-transport-registry.d.ts +63 -0
- package/internal/auth/x509-transport-registry.d.ts.map +1 -0
- package/internal/auth/x509-transport-registry.js +53 -0
- package/internal/auth/x509-transport-registry.js.map +1 -0
- package/internal/auth/x509-transport-registry.mjs +48 -0
- package/internal/auth/x509-transport-registry.mjs.map +1 -0
- package/internal/auth/x509-transport-state-browser.d.mts +21 -0
- package/internal/auth/x509-transport-state-browser.d.mts.map +1 -0
- package/internal/auth/x509-transport-state-browser.d.ts +21 -0
- package/internal/auth/x509-transport-state-browser.d.ts.map +1 -0
- package/internal/auth/x509-transport-state-browser.js +30 -0
- package/internal/auth/x509-transport-state-browser.js.map +1 -0
- package/internal/auth/x509-transport-state-browser.mjs +27 -0
- package/internal/auth/x509-transport-state-browser.mjs.map +1 -0
- package/internal/auth/x509-transport-state.cjs +30 -0
- package/internal/auth/x509-transport-state.cjs.map +1 -0
- package/internal/auth/x509-transport-state.d.cts +21 -0
- package/internal/auth/x509-transport-state.d.cts.map +1 -0
- package/internal/auth/x509-workload-identity-auth.d.mts +128 -0
- package/internal/auth/x509-workload-identity-auth.d.mts.map +1 -0
- package/internal/auth/x509-workload-identity-auth.d.ts +128 -0
- package/internal/auth/x509-workload-identity-auth.d.ts.map +1 -0
- package/internal/auth/x509-workload-identity-auth.js +767 -0
- package/internal/auth/x509-workload-identity-auth.js.map +1 -0
- package/internal/auth/x509-workload-identity-auth.mjs +757 -0
- package/internal/auth/x509-workload-identity-auth.mjs.map +1 -0
- package/internal/bedrock.d.mts +82 -5
- package/internal/bedrock.d.mts.map +1 -1
- package/internal/bedrock.d.ts +82 -5
- package/internal/bedrock.d.ts.map +1 -1
- package/internal/bedrock.js +312 -13
- package/internal/bedrock.js.map +1 -1
- package/internal/bedrock.mjs +307 -13
- package/internal/bedrock.mjs.map +1 -1
- package/internal/builtin-types.d.mts.map +1 -1
- package/internal/builtin-types.d.ts.map +1 -1
- package/internal/builtin-types.js +0 -1
- package/internal/builtin-types.js.map +1 -1
- package/internal/builtin-types.mjs +0 -1
- package/internal/builtin-types.mjs.map +1 -1
- package/internal/data-residency.d.mts +12 -0
- package/internal/data-residency.d.mts.map +1 -0
- package/internal/data-residency.d.ts +12 -0
- package/internal/data-residency.d.ts.map +1 -0
- package/internal/data-residency.js +34 -0
- package/internal/data-residency.js.map +1 -0
- package/internal/data-residency.mjs +30 -0
- package/internal/data-residency.mjs.map +1 -0
- package/internal/decoders/line.d.mts +25 -2
- package/internal/decoders/line.d.mts.map +1 -1
- package/internal/decoders/line.d.ts +25 -2
- package/internal/decoders/line.d.ts.map +1 -1
- package/internal/decoders/line.js +139 -54
- package/internal/decoders/line.js.map +1 -1
- package/internal/decoders/line.mjs +140 -55
- package/internal/decoders/line.mjs.map +1 -1
- package/internal/detect-platform.d.mts.map +1 -1
- package/internal/detect-platform.d.ts.map +1 -1
- package/internal/detect-platform.js +1 -2
- package/internal/detect-platform.js.map +1 -1
- package/internal/detect-platform.mjs +1 -2
- package/internal/detect-platform.mjs.map +1 -1
- package/internal/errors.d.mts.map +1 -1
- package/internal/errors.d.ts.map +1 -1
- package/internal/errors.js +0 -1
- package/internal/errors.js.map +1 -1
- package/internal/errors.mjs +0 -1
- package/internal/errors.mjs.map +1 -1
- package/internal/headers.d.mts.map +1 -1
- package/internal/headers.d.ts.map +1 -1
- package/internal/headers.js +0 -1
- package/internal/headers.js.map +1 -1
- package/internal/headers.mjs +0 -1
- package/internal/headers.mjs.map +1 -1
- package/internal/multipart-encoding.d.mts +8 -0
- package/internal/multipart-encoding.d.mts.map +1 -0
- package/internal/multipart-encoding.d.ts +8 -0
- package/internal/multipart-encoding.d.ts.map +1 -0
- package/internal/multipart-encoding.js +51 -0
- package/internal/multipart-encoding.js.map +1 -0
- package/internal/multipart-encoding.mjs +48 -0
- package/internal/multipart-encoding.mjs.map +1 -0
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +23 -3
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +23 -3
- package/internal/parse.mjs.map +1 -1
- package/internal/provider.d.mts +26 -0
- package/internal/provider.d.mts.map +1 -1
- package/internal/provider.d.ts +26 -0
- package/internal/provider.d.ts.map +1 -1
- package/internal/provider.js +11 -0
- package/internal/provider.js.map +1 -1
- package/internal/provider.mjs +11 -0
- package/internal/provider.mjs.map +1 -1
- package/internal/qs/formats.d.mts +1 -1
- package/internal/qs/formats.d.mts.map +1 -1
- package/internal/qs/formats.d.ts +1 -1
- package/internal/qs/formats.d.ts.map +1 -1
- package/internal/qs/formats.js +1 -2
- package/internal/qs/formats.js.map +1 -1
- package/internal/qs/formats.mjs +1 -1
- package/internal/qs/formats.mjs.map +1 -1
- package/internal/qs/stringify.d.mts.map +1 -1
- package/internal/qs/stringify.d.ts.map +1 -1
- package/internal/qs/stringify.js +57 -51
- package/internal/qs/stringify.js.map +1 -1
- package/internal/qs/stringify.mjs +57 -51
- package/internal/qs/stringify.mjs.map +1 -1
- package/internal/qs/types.d.mts +1 -1
- package/internal/qs/types.d.mts.map +1 -1
- package/internal/qs/types.d.ts +1 -1
- package/internal/qs/types.d.ts.map +1 -1
- package/internal/qs/utils.d.mts +1 -1
- package/internal/qs/utils.d.mts.map +1 -1
- package/internal/qs/utils.d.ts +1 -1
- package/internal/qs/utils.d.ts.map +1 -1
- package/internal/qs/utils.js +356 -50
- package/internal/qs/utils.js.map +1 -1
- package/internal/qs/utils.mjs +356 -50
- package/internal/qs/utils.mjs.map +1 -1
- package/internal/request-options.d.mts +7 -0
- package/internal/request-options.d.mts.map +1 -1
- package/internal/request-options.d.ts +7 -0
- package/internal/request-options.d.ts.map +1 -1
- package/internal/request-options.js +43 -2
- package/internal/request-options.js.map +1 -1
- package/internal/request-options.mjs +42 -2
- package/internal/request-options.mjs.map +1 -1
- package/internal/responses/canonical-output-text.d.mts +16 -0
- package/internal/responses/canonical-output-text.d.mts.map +1 -0
- package/internal/responses/canonical-output-text.d.ts +16 -0
- package/internal/responses/canonical-output-text.d.ts.map +1 -0
- package/internal/responses/canonical-output-text.js +123 -0
- package/internal/responses/canonical-output-text.js.map +1 -0
- package/internal/responses/canonical-output-text.mjs +115 -0
- package/internal/responses/canonical-output-text.mjs.map +1 -0
- package/internal/responses/output-text-index.d.mts +18 -0
- package/internal/responses/output-text-index.d.mts.map +1 -0
- package/internal/responses/output-text-index.d.ts +18 -0
- package/internal/responses/output-text-index.d.ts.map +1 -0
- package/internal/responses/output-text-index.js +77 -0
- package/internal/responses/output-text-index.js.map +1 -0
- package/internal/responses/output-text-index.mjs +73 -0
- package/internal/responses/output-text-index.mjs.map +1 -0
- package/internal/responses/response-accumulator.d.mts +11 -0
- package/internal/responses/response-accumulator.d.mts.map +1 -0
- package/internal/responses/response-accumulator.d.ts +11 -0
- package/internal/responses/response-accumulator.d.ts.map +1 -0
- package/internal/responses/response-accumulator.js +925 -0
- package/internal/responses/response-accumulator.js.map +1 -0
- package/internal/responses/response-accumulator.mjs +921 -0
- package/internal/responses/response-accumulator.mjs.map +1 -0
- package/internal/shim-types.d.mts.map +1 -1
- package/internal/shim-types.d.ts.map +1 -1
- package/internal/shim-types.js +6 -1
- package/internal/shim-types.js.map +1 -1
- package/internal/shim-types.mjs +6 -1
- package/internal/shim-types.mjs.map +1 -1
- package/internal/shims.d.mts.map +1 -1
- package/internal/shims.d.ts.map +1 -1
- package/internal/shims.js +6 -1
- package/internal/shims.js.map +1 -1
- package/internal/shims.mjs +6 -1
- package/internal/shims.mjs.map +1 -1
- package/internal/stream-utils.d.mts +10 -3
- package/internal/stream-utils.d.mts.map +1 -1
- package/internal/stream-utils.d.ts +10 -3
- package/internal/stream-utils.d.ts.map +1 -1
- package/internal/stream-utils.js +35 -7
- package/internal/stream-utils.js.map +1 -1
- package/internal/stream-utils.mjs +35 -7
- package/internal/stream-utils.mjs.map +1 -1
- package/internal/to-file.d.mts +39 -17
- package/internal/to-file.d.mts.map +1 -1
- package/internal/to-file.d.ts +39 -17
- package/internal/to-file.d.ts.map +1 -1
- package/internal/to-file.js +44 -22
- package/internal/to-file.js.map +1 -1
- package/internal/to-file.mjs +44 -22
- package/internal/to-file.mjs.map +1 -1
- package/internal/tslib.js +6 -0
- package/internal/tslib.mjs +6 -1
- package/internal/types.d.mts +4 -4
- package/internal/types.d.mts.map +1 -1
- package/internal/types.d.ts +4 -4
- package/internal/types.d.ts.map +1 -1
- package/internal/types.js +0 -1
- package/internal/types.js.map +1 -1
- package/internal/types.mjs +0 -1
- package/internal/types.mjs.map +1 -1
- package/internal/uploads.d.mts +84 -14
- package/internal/uploads.d.mts.map +1 -1
- package/internal/uploads.d.ts +84 -14
- package/internal/uploads.d.ts.map +1 -1
- package/internal/uploads.js +212 -75
- package/internal/uploads.js.map +1 -1
- package/internal/uploads.mjs +212 -75
- package/internal/uploads.mjs.map +1 -1
- package/internal/utils/base64.d.mts.map +1 -1
- package/internal/utils/base64.d.ts.map +1 -1
- package/internal/utils/base64.js +0 -1
- package/internal/utils/base64.js.map +1 -1
- package/internal/utils/base64.mjs +0 -1
- package/internal/utils/base64.mjs.map +1 -1
- package/internal/utils/bytes.d.mts +3 -0
- package/internal/utils/bytes.d.mts.map +1 -1
- package/internal/utils/bytes.d.ts +3 -0
- package/internal/utils/bytes.d.ts.map +1 -1
- package/internal/utils/bytes.js +3 -0
- package/internal/utils/bytes.js.map +1 -1
- package/internal/utils/bytes.mjs +3 -0
- package/internal/utils/bytes.mjs.map +1 -1
- package/internal/utils/env.d.mts.map +1 -1
- package/internal/utils/env.d.ts.map +1 -1
- package/internal/utils/env.js +9 -5
- package/internal/utils/env.js.map +1 -1
- package/internal/utils/env.mjs +9 -5
- package/internal/utils/env.mjs.map +1 -1
- package/internal/utils/log.d.mts.map +1 -1
- package/internal/utils/log.d.ts.map +1 -1
- package/internal/utils/log.js +3 -4
- package/internal/utils/log.js.map +1 -1
- package/internal/utils/log.mjs +3 -4
- package/internal/utils/log.mjs.map +1 -1
- package/internal/utils/path.d.mts +14 -2
- package/internal/utils/path.d.mts.map +1 -1
- package/internal/utils/path.d.ts +14 -2
- package/internal/utils/path.d.ts.map +1 -1
- package/internal/utils/path.js +48 -30
- package/internal/utils/path.js.map +1 -1
- package/internal/utils/path.mjs +48 -30
- package/internal/utils/path.mjs.map +1 -1
- package/internal/utils/query.d.mts.map +1 -1
- package/internal/utils/query.d.ts.map +1 -1
- package/internal/utils/query.js +0 -1
- package/internal/utils/query.js.map +1 -1
- package/internal/utils/query.mjs +0 -1
- package/internal/utils/query.mjs.map +1 -1
- package/internal/utils/sleep.d.mts.map +1 -1
- package/internal/utils/sleep.d.ts.map +1 -1
- package/internal/utils/sleep.js +0 -1
- package/internal/utils/sleep.js.map +1 -1
- package/internal/utils/sleep.mjs +0 -1
- package/internal/utils/sleep.mjs.map +1 -1
- package/internal/utils/uuid.d.mts.map +1 -1
- package/internal/utils/uuid.d.ts.map +1 -1
- package/internal/utils/uuid.js +0 -1
- package/internal/utils/uuid.js.map +1 -1
- package/internal/utils/uuid.mjs +0 -1
- package/internal/utils/uuid.mjs.map +1 -1
- package/internal/utils/values.d.mts.map +1 -1
- package/internal/utils/values.d.ts.map +1 -1
- package/internal/utils/values.js +0 -1
- package/internal/utils/values.js.map +1 -1
- package/internal/utils/values.mjs +0 -1
- package/internal/utils/values.mjs.map +1 -1
- package/internal/utils.d.mts.map +1 -1
- package/internal/utils.d.ts.map +1 -1
- package/internal/utils.js +0 -1
- package/internal/utils.js.map +1 -1
- package/internal/utils.mjs +0 -1
- package/internal/utils.mjs.map +1 -1
- package/internal/ws-adapter-browser.d.mts +26 -3
- package/internal/ws-adapter-browser.d.mts.map +1 -1
- package/internal/ws-adapter-browser.d.ts +26 -3
- package/internal/ws-adapter-browser.d.ts.map +1 -1
- package/internal/ws-adapter-browser.js +64 -21
- package/internal/ws-adapter-browser.js.map +1 -1
- package/internal/ws-adapter-browser.mjs +64 -21
- package/internal/ws-adapter-browser.mjs.map +1 -1
- package/internal/ws-adapter-node.d.mts +18 -3
- package/internal/ws-adapter-node.d.mts.map +1 -1
- package/internal/ws-adapter-node.d.ts +18 -3
- package/internal/ws-adapter-node.d.ts.map +1 -1
- package/internal/ws-adapter-node.js +90 -24
- package/internal/ws-adapter-node.js.map +1 -1
- package/internal/ws-adapter-node.mjs +90 -24
- package/internal/ws-adapter-node.mjs.map +1 -1
- package/internal/ws-adapter.d.mts +14 -0
- package/internal/ws-adapter.d.mts.map +1 -1
- package/internal/ws-adapter.d.ts +14 -0
- package/internal/ws-adapter.d.ts.map +1 -1
- package/internal/ws-adapter.js +4 -0
- package/internal/ws-adapter.js.map +1 -1
- package/internal/ws-adapter.mjs +4 -0
- package/internal/ws-adapter.mjs.map +1 -1
- package/internal/ws.d.mts +36 -8
- package/internal/ws.d.mts.map +1 -1
- package/internal/ws.d.ts +36 -8
- package/internal/ws.d.ts.map +1 -1
- package/internal/ws.js +116 -47
- package/internal/ws.js.map +1 -1
- package/internal/ws.mjs +115 -47
- package/internal/ws.mjs.map +1 -1
- package/lib/AbstractChatCompletionRunner.d.mts +26 -5
- package/lib/AbstractChatCompletionRunner.d.mts.map +1 -1
- package/lib/AbstractChatCompletionRunner.d.ts +26 -5
- package/lib/AbstractChatCompletionRunner.d.ts.map +1 -1
- package/lib/AbstractChatCompletionRunner.js +89 -39
- package/lib/AbstractChatCompletionRunner.js.map +1 -1
- package/lib/AbstractChatCompletionRunner.mjs +92 -42
- package/lib/AbstractChatCompletionRunner.mjs.map +1 -1
- package/lib/AssistantStream.d.mts +49 -8
- package/lib/AssistantStream.d.mts.map +1 -1
- package/lib/AssistantStream.d.ts +49 -8
- package/lib/AssistantStream.d.ts.map +1 -1
- package/lib/AssistantStream.js +388 -227
- package/lib/AssistantStream.js.map +1 -1
- package/lib/AssistantStream.mjs +389 -228
- package/lib/AssistantStream.mjs.map +1 -1
- package/lib/ChatCompletionRunner.d.mts +16 -5
- package/lib/ChatCompletionRunner.d.mts.map +1 -1
- package/lib/ChatCompletionRunner.d.ts +16 -5
- package/lib/ChatCompletionRunner.d.ts.map +1 -1
- package/lib/ChatCompletionRunner.js +4 -1
- package/lib/ChatCompletionRunner.js.map +1 -1
- package/lib/ChatCompletionRunner.mjs +5 -2
- package/lib/ChatCompletionRunner.mjs.map +1 -1
- package/lib/ChatCompletionStream.d.mts +137 -35
- package/lib/ChatCompletionStream.d.mts.map +1 -1
- package/lib/ChatCompletionStream.d.ts +137 -35
- package/lib/ChatCompletionStream.d.ts.map +1 -1
- package/lib/ChatCompletionStream.js +1252 -162
- package/lib/ChatCompletionStream.js.map +1 -1
- package/lib/ChatCompletionStream.mjs +1255 -165
- package/lib/ChatCompletionStream.mjs.map +1 -1
- package/lib/ChatCompletionStreamingRunner.d.mts +20 -7
- package/lib/ChatCompletionStreamingRunner.d.mts.map +1 -1
- package/lib/ChatCompletionStreamingRunner.d.ts +20 -7
- package/lib/ChatCompletionStreamingRunner.d.ts.map +1 -1
- package/lib/ChatCompletionStreamingRunner.js +27 -67
- package/lib/ChatCompletionStreamingRunner.js.map +1 -1
- package/lib/ChatCompletionStreamingRunner.mjs +28 -68
- package/lib/ChatCompletionStreamingRunner.mjs.map +1 -1
- package/lib/EventEmitter.d.mts +9 -6
- package/lib/EventEmitter.d.mts.map +1 -1
- package/lib/EventEmitter.d.ts +9 -6
- package/lib/EventEmitter.d.ts.map +1 -1
- package/lib/EventEmitter.js +89 -20
- package/lib/EventEmitter.js.map +1 -1
- package/lib/EventEmitter.mjs +90 -21
- package/lib/EventEmitter.mjs.map +1 -1
- package/lib/EventStream.d.mts +49 -9
- package/lib/EventStream.d.mts.map +1 -1
- package/lib/EventStream.d.ts +49 -9
- package/lib/EventStream.d.ts.map +1 -1
- package/lib/EventStream.js +1257 -51
- package/lib/EventStream.js.map +1 -1
- package/lib/EventStream.mjs +1258 -52
- package/lib/EventStream.mjs.map +1 -1
- package/lib/ResponsesParser.d.mts +52 -5
- package/lib/ResponsesParser.d.mts.map +1 -1
- package/lib/ResponsesParser.d.ts +52 -5
- package/lib/ResponsesParser.d.ts.map +1 -1
- package/lib/ResponsesParser.js +32 -17
- package/lib/ResponsesParser.js.map +1 -1
- package/lib/ResponsesParser.mjs +33 -18
- package/lib/ResponsesParser.mjs.map +1 -1
- package/lib/RunnableFunction.d.mts +38 -10
- package/lib/RunnableFunction.d.mts.map +1 -1
- package/lib/RunnableFunction.d.ts +38 -10
- package/lib/RunnableFunction.d.ts.map +1 -1
- package/lib/RunnableFunction.js +3 -0
- package/lib/RunnableFunction.js.map +1 -1
- package/lib/RunnableFunction.mjs +3 -0
- package/lib/RunnableFunction.mjs.map +1 -1
- package/lib/Util.d.mts +2 -0
- package/lib/Util.d.mts.map +1 -1
- package/lib/Util.d.ts +2 -0
- package/lib/Util.d.ts.map +1 -1
- package/lib/Util.js +7 -4
- package/lib/Util.js.map +1 -1
- package/lib/Util.mjs +7 -4
- package/lib/Util.mjs.map +1 -1
- package/lib/assistant-run-polling.d.mts +12 -0
- package/lib/assistant-run-polling.d.mts.map +1 -0
- package/lib/assistant-run-polling.d.ts +12 -0
- package/lib/assistant-run-polling.d.ts.map +1 -0
- package/lib/assistant-run-polling.js +17 -0
- package/lib/assistant-run-polling.js.map +1 -0
- package/lib/assistant-run-polling.mjs +14 -0
- package/lib/assistant-run-polling.mjs.map +1 -0
- package/lib/chatCompletionUtils.d.mts +4 -1
- package/lib/chatCompletionUtils.d.mts.map +1 -1
- package/lib/chatCompletionUtils.d.ts +4 -1
- package/lib/chatCompletionUtils.d.ts.map +1 -1
- package/lib/chatCompletionUtils.js +5 -6
- package/lib/chatCompletionUtils.js.map +1 -1
- package/lib/chatCompletionUtils.mjs +5 -6
- package/lib/chatCompletionUtils.mjs.map +1 -1
- package/lib/embeddings.d.mts +18 -0
- package/lib/embeddings.d.mts.map +1 -0
- package/lib/embeddings.d.ts +18 -0
- package/lib/embeddings.d.ts.map +1 -0
- package/lib/embeddings.js +50 -0
- package/lib/embeddings.js.map +1 -0
- package/lib/embeddings.mjs +47 -0
- package/lib/embeddings.mjs.map +1 -0
- package/lib/file-processing.d.mts +10 -0
- package/lib/file-processing.d.mts.map +1 -0
- package/lib/file-processing.d.ts +10 -0
- package/lib/file-processing.d.ts.map +1 -0
- package/lib/file-processing.js +30 -0
- package/lib/file-processing.js.map +1 -0
- package/lib/file-processing.mjs +27 -0
- package/lib/file-processing.mjs.map +1 -0
- package/lib/jsonschema.d.mts +70 -14
- package/lib/jsonschema.d.mts.map +1 -1
- package/lib/jsonschema.d.ts +70 -14
- package/lib/jsonschema.d.ts.map +1 -1
- package/lib/parser.d.mts +97 -6
- package/lib/parser.d.mts.map +1 -1
- package/lib/parser.d.ts +97 -6
- package/lib/parser.d.ts.map +1 -1
- package/lib/parser.js +128 -41
- package/lib/parser.js.map +1 -1
- package/lib/parser.mjs +126 -41
- package/lib/parser.mjs.map +1 -1
- package/lib/polling.d.mts +20 -0
- package/lib/polling.d.mts.map +1 -0
- package/lib/polling.d.ts +20 -0
- package/lib/polling.d.ts.map +1 -0
- package/lib/polling.js +130 -0
- package/lib/polling.js.map +1 -0
- package/lib/polling.mjs +127 -0
- package/lib/polling.mjs.map +1 -0
- package/lib/responses/EventTypes.d.mts +7 -2
- package/lib/responses/EventTypes.d.mts.map +1 -1
- package/lib/responses/EventTypes.d.ts +7 -2
- package/lib/responses/EventTypes.d.ts.map +1 -1
- package/lib/responses/ResponseAccumulator.d.mts +4 -1
- package/lib/responses/ResponseAccumulator.d.mts.map +1 -1
- package/lib/responses/ResponseAccumulator.d.ts +4 -1
- package/lib/responses/ResponseAccumulator.d.ts.map +1 -1
- package/lib/responses/ResponseAccumulator.js +2 -390
- package/lib/responses/ResponseAccumulator.js.map +1 -1
- package/lib/responses/ResponseAccumulator.mjs +2 -390
- package/lib/responses/ResponseAccumulator.mjs.map +1 -1
- package/lib/responses/ResponseInputItems.d.mts +1 -0
- package/lib/responses/ResponseInputItems.d.mts.map +1 -1
- package/lib/responses/ResponseInputItems.d.ts +1 -0
- package/lib/responses/ResponseInputItems.d.ts.map +1 -1
- package/lib/responses/ResponseInputItems.js.map +1 -1
- package/lib/responses/ResponseInputItems.mjs.map +1 -1
- package/lib/responses/ResponseStream.d.mts +29 -10
- package/lib/responses/ResponseStream.d.mts.map +1 -1
- package/lib/responses/ResponseStream.d.ts +29 -10
- package/lib/responses/ResponseStream.d.ts.map +1 -1
- package/lib/responses/ResponseStream.js +57 -71
- package/lib/responses/ResponseStream.js.map +1 -1
- package/lib/responses/ResponseStream.mjs +58 -72
- package/lib/responses/ResponseStream.mjs.map +1 -1
- package/lib/transform.d.mts +21 -0
- package/lib/transform.d.mts.map +1 -1
- package/lib/transform.d.ts +21 -0
- package/lib/transform.d.ts.map +1 -1
- package/lib/transform.js +126 -76
- package/lib/transform.js.map +1 -1
- package/lib/transform.mjs +126 -76
- package/lib/transform.mjs.map +1 -1
- package/lib/vector-store-polling.d.mts +22 -0
- package/lib/vector-store-polling.d.mts.map +1 -0
- package/lib/vector-store-polling.d.ts +22 -0
- package/lib/vector-store-polling.d.ts.map +1 -0
- package/lib/vector-store-polling.js +24 -0
- package/lib/vector-store-polling.js.map +1 -0
- package/lib/vector-store-polling.mjs +20 -0
- package/lib/vector-store-polling.mjs.map +1 -0
- package/lib/vector-store-upload.d.mts +17 -0
- package/lib/vector-store-upload.d.mts.map +1 -0
- package/lib/vector-store-upload.d.ts +17 -0
- package/lib/vector-store-upload.d.ts.map +1 -0
- package/lib/vector-store-upload.js +37 -0
- package/lib/vector-store-upload.js.map +1 -0
- package/lib/vector-store-upload.mjs +34 -0
- package/lib/vector-store-upload.mjs.map +1 -0
- package/lib/webhook-signature.d.mts +15 -0
- package/lib/webhook-signature.d.mts.map +1 -0
- package/lib/webhook-signature.d.ts +15 -0
- package/lib/webhook-signature.d.ts.map +1 -0
- package/lib/webhook-signature.js +125 -0
- package/lib/webhook-signature.js.map +1 -0
- package/lib/webhook-signature.mjs +121 -0
- package/lib/webhook-signature.mjs.map +1 -0
- package/package.json +23 -3
- package/providers/bedrock/aws.d.mts +35 -8
- package/providers/bedrock/aws.d.mts.map +1 -1
- package/providers/bedrock/aws.d.ts +35 -8
- package/providers/bedrock/aws.d.ts.map +1 -1
- package/providers/bedrock/aws.js +60 -21
- package/providers/bedrock/aws.js.map +1 -1
- package/providers/bedrock/aws.mjs +61 -22
- package/providers/bedrock/aws.mjs.map +1 -1
- package/providers/bedrock.d.mts +17 -2
- package/providers/bedrock.d.mts.map +1 -1
- package/providers/bedrock.d.ts +17 -2
- package/providers/bedrock.d.ts.map +1 -1
- package/providers/bedrock.js +19 -2
- package/providers/bedrock.js.map +1 -1
- package/providers/bedrock.mjs +20 -3
- package/providers/bedrock.mjs.map +1 -1
- package/realtime/internal-base.d.mts +99 -10
- package/realtime/internal-base.d.mts.map +1 -1
- package/realtime/internal-base.d.ts +99 -10
- package/realtime/internal-base.d.ts.map +1 -1
- package/realtime/internal-base.js +94 -29
- package/realtime/internal-base.js.map +1 -1
- package/realtime/internal-base.mjs +93 -29
- package/realtime/internal-base.mjs.map +1 -1
- package/realtime/websocket.d.mts +63 -4
- package/realtime/websocket.d.mts.map +1 -1
- package/realtime/websocket.d.ts +63 -4
- package/realtime/websocket.d.ts.map +1 -1
- package/realtime/websocket.js +152 -27
- package/realtime/websocket.js.map +1 -1
- package/realtime/websocket.mjs +153 -28
- package/realtime/websocket.mjs.map +1 -1
- package/realtime/ws.d.mts +58 -3
- package/realtime/ws.d.mts.map +1 -1
- package/realtime/ws.d.ts +58 -3
- package/realtime/ws.d.ts.map +1 -1
- package/realtime/ws.js +72 -8
- package/realtime/ws.js.map +1 -1
- package/realtime/ws.mjs +73 -9
- package/realtime/ws.mjs.map +1 -1
- package/resources/admin/admin.js +1 -1
- package/resources/admin/admin.js.map +1 -1
- package/resources/admin/admin.mjs +1 -1
- package/resources/admin/admin.mjs.map +1 -1
- package/resources/admin/index.js +1 -1
- package/resources/admin/index.js.map +1 -1
- package/resources/admin/index.mjs +1 -1
- package/resources/admin/index.mjs.map +1 -1
- package/resources/admin/organization/admin-api-keys.js +1 -1
- package/resources/admin/organization/admin-api-keys.js.map +1 -1
- package/resources/admin/organization/admin-api-keys.mjs +1 -1
- package/resources/admin/organization/admin-api-keys.mjs.map +1 -1
- package/resources/admin/organization/audit-logs.d.mts +2 -2
- package/resources/admin/organization/audit-logs.d.mts.map +1 -1
- package/resources/admin/organization/audit-logs.d.ts +2 -2
- package/resources/admin/organization/audit-logs.d.ts.map +1 -1
- package/resources/admin/organization/audit-logs.js +1 -1
- package/resources/admin/organization/audit-logs.js.map +1 -1
- package/resources/admin/organization/audit-logs.mjs +1 -1
- package/resources/admin/organization/audit-logs.mjs.map +1 -1
- package/resources/admin/organization/certificates.js +1 -1
- package/resources/admin/organization/certificates.js.map +1 -1
- package/resources/admin/organization/certificates.mjs +1 -1
- package/resources/admin/organization/certificates.mjs.map +1 -1
- package/resources/admin/organization/data-retention.js +1 -1
- package/resources/admin/organization/data-retention.js.map +1 -1
- package/resources/admin/organization/data-retention.mjs +1 -1
- package/resources/admin/organization/data-retention.mjs.map +1 -1
- package/resources/admin/organization/groups/groups.js +1 -1
- package/resources/admin/organization/groups/groups.js.map +1 -1
- package/resources/admin/organization/groups/groups.mjs +1 -1
- package/resources/admin/organization/groups/groups.mjs.map +1 -1
- package/resources/admin/organization/groups/index.js +1 -1
- package/resources/admin/organization/groups/index.js.map +1 -1
- package/resources/admin/organization/groups/index.mjs +1 -1
- package/resources/admin/organization/groups/index.mjs.map +1 -1
- package/resources/admin/organization/groups/roles.js +1 -1
- package/resources/admin/organization/groups/roles.js.map +1 -1
- package/resources/admin/organization/groups/roles.mjs +1 -1
- package/resources/admin/organization/groups/roles.mjs.map +1 -1
- package/resources/admin/organization/groups/users.js +1 -1
- package/resources/admin/organization/groups/users.js.map +1 -1
- package/resources/admin/organization/groups/users.mjs +1 -1
- package/resources/admin/organization/groups/users.mjs.map +1 -1
- package/resources/admin/organization/groups.js +1 -1
- package/resources/admin/organization/groups.js.map +1 -1
- package/resources/admin/organization/groups.mjs +1 -1
- package/resources/admin/organization/groups.mjs.map +1 -1
- package/resources/admin/organization/index.d.mts +2 -2
- package/resources/admin/organization/index.d.mts.map +1 -1
- package/resources/admin/organization/index.d.ts +2 -2
- package/resources/admin/organization/index.d.ts.map +1 -1
- package/resources/admin/organization/index.js +1 -1
- package/resources/admin/organization/index.js.map +1 -1
- package/resources/admin/organization/index.mjs +1 -1
- package/resources/admin/organization/index.mjs.map +1 -1
- package/resources/admin/organization/invites.js +1 -1
- package/resources/admin/organization/invites.js.map +1 -1
- package/resources/admin/organization/invites.mjs +1 -1
- package/resources/admin/organization/invites.mjs.map +1 -1
- package/resources/admin/organization/organization.d.mts +4 -4
- package/resources/admin/organization/organization.d.mts.map +1 -1
- package/resources/admin/organization/organization.d.ts +4 -4
- package/resources/admin/organization/organization.d.ts.map +1 -1
- package/resources/admin/organization/organization.js +1 -1
- package/resources/admin/organization/organization.js.map +1 -1
- package/resources/admin/organization/organization.mjs +1 -1
- package/resources/admin/organization/organization.mjs.map +1 -1
- package/resources/admin/organization/projects/api-keys.js +1 -1
- package/resources/admin/organization/projects/api-keys.js.map +1 -1
- package/resources/admin/organization/projects/api-keys.mjs +1 -1
- package/resources/admin/organization/projects/api-keys.mjs.map +1 -1
- package/resources/admin/organization/projects/certificates.js +1 -1
- package/resources/admin/organization/projects/certificates.js.map +1 -1
- package/resources/admin/organization/projects/certificates.mjs +1 -1
- package/resources/admin/organization/projects/certificates.mjs.map +1 -1
- package/resources/admin/organization/projects/data-retention.js +1 -1
- package/resources/admin/organization/projects/data-retention.js.map +1 -1
- package/resources/admin/organization/projects/data-retention.mjs +1 -1
- package/resources/admin/organization/projects/data-retention.mjs.map +1 -1
- package/resources/admin/organization/projects/groups/groups.js +1 -1
- package/resources/admin/organization/projects/groups/groups.js.map +1 -1
- package/resources/admin/organization/projects/groups/groups.mjs +1 -1
- package/resources/admin/organization/projects/groups/groups.mjs.map +1 -1
- package/resources/admin/organization/projects/groups/index.js +1 -1
- package/resources/admin/organization/projects/groups/index.js.map +1 -1
- package/resources/admin/organization/projects/groups/index.mjs +1 -1
- package/resources/admin/organization/projects/groups/index.mjs.map +1 -1
- package/resources/admin/organization/projects/groups/roles.js +1 -1
- package/resources/admin/organization/projects/groups/roles.js.map +1 -1
- package/resources/admin/organization/projects/groups/roles.mjs +1 -1
- package/resources/admin/organization/projects/groups/roles.mjs.map +1 -1
- package/resources/admin/organization/projects/groups.js +1 -1
- package/resources/admin/organization/projects/groups.js.map +1 -1
- package/resources/admin/organization/projects/groups.mjs +1 -1
- package/resources/admin/organization/projects/groups.mjs.map +1 -1
- package/resources/admin/organization/projects/hosted-tool-permissions.js +1 -1
- package/resources/admin/organization/projects/hosted-tool-permissions.js.map +1 -1
- package/resources/admin/organization/projects/hosted-tool-permissions.mjs +1 -1
- package/resources/admin/organization/projects/hosted-tool-permissions.mjs.map +1 -1
- package/resources/admin/organization/projects/index.d.mts +1 -1
- package/resources/admin/organization/projects/index.d.mts.map +1 -1
- package/resources/admin/organization/projects/index.d.ts +1 -1
- package/resources/admin/organization/projects/index.d.ts.map +1 -1
- package/resources/admin/organization/projects/index.js +1 -1
- package/resources/admin/organization/projects/index.js.map +1 -1
- package/resources/admin/organization/projects/index.mjs +1 -1
- package/resources/admin/organization/projects/index.mjs.map +1 -1
- package/resources/admin/organization/projects/model-permissions.js +1 -1
- package/resources/admin/organization/projects/model-permissions.js.map +1 -1
- package/resources/admin/organization/projects/model-permissions.mjs +1 -1
- package/resources/admin/organization/projects/model-permissions.mjs.map +1 -1
- package/resources/admin/organization/projects/projects.d.mts +22 -5
- package/resources/admin/organization/projects/projects.d.mts.map +1 -1
- package/resources/admin/organization/projects/projects.d.ts +22 -5
- package/resources/admin/organization/projects/projects.d.ts.map +1 -1
- package/resources/admin/organization/projects/projects.js +1 -1
- package/resources/admin/organization/projects/projects.js.map +1 -1
- package/resources/admin/organization/projects/projects.mjs +1 -1
- package/resources/admin/organization/projects/projects.mjs.map +1 -1
- package/resources/admin/organization/projects/rate-limits.js +1 -1
- package/resources/admin/organization/projects/rate-limits.js.map +1 -1
- package/resources/admin/organization/projects/rate-limits.mjs +1 -1
- package/resources/admin/organization/projects/rate-limits.mjs.map +1 -1
- package/resources/admin/organization/projects/roles.js +1 -1
- package/resources/admin/organization/projects/roles.js.map +1 -1
- package/resources/admin/organization/projects/roles.mjs +1 -1
- package/resources/admin/organization/projects/roles.mjs.map +1 -1
- package/resources/admin/organization/projects/service-accounts/api-keys.js +1 -1
- package/resources/admin/organization/projects/service-accounts/api-keys.js.map +1 -1
- package/resources/admin/organization/projects/service-accounts/api-keys.mjs +1 -1
- package/resources/admin/organization/projects/service-accounts/api-keys.mjs.map +1 -1
- package/resources/admin/organization/projects/service-accounts/index.js +1 -1
- package/resources/admin/organization/projects/service-accounts/index.js.map +1 -1
- package/resources/admin/organization/projects/service-accounts/index.mjs +1 -1
- package/resources/admin/organization/projects/service-accounts/index.mjs.map +1 -1
- package/resources/admin/organization/projects/service-accounts/service-accounts.js +1 -1
- package/resources/admin/organization/projects/service-accounts/service-accounts.js.map +1 -1
- package/resources/admin/organization/projects/service-accounts/service-accounts.mjs +1 -1
- package/resources/admin/organization/projects/service-accounts/service-accounts.mjs.map +1 -1
- package/resources/admin/organization/projects/service-accounts.js +1 -1
- package/resources/admin/organization/projects/service-accounts.js.map +1 -1
- package/resources/admin/organization/projects/service-accounts.mjs +1 -1
- package/resources/admin/organization/projects/service-accounts.mjs.map +1 -1
- package/resources/admin/organization/projects/spend-alerts.js +1 -1
- package/resources/admin/organization/projects/spend-alerts.js.map +1 -1
- package/resources/admin/organization/projects/spend-alerts.mjs +1 -1
- package/resources/admin/organization/projects/spend-alerts.mjs.map +1 -1
- package/resources/admin/organization/projects/spend-limit.js +1 -1
- package/resources/admin/organization/projects/spend-limit.js.map +1 -1
- package/resources/admin/organization/projects/spend-limit.mjs +1 -1
- package/resources/admin/organization/projects/spend-limit.mjs.map +1 -1
- package/resources/admin/organization/projects/users/index.js +1 -1
- package/resources/admin/organization/projects/users/index.js.map +1 -1
- package/resources/admin/organization/projects/users/index.mjs +1 -1
- package/resources/admin/organization/projects/users/index.mjs.map +1 -1
- package/resources/admin/organization/projects/users/roles.js +1 -1
- package/resources/admin/organization/projects/users/roles.js.map +1 -1
- package/resources/admin/organization/projects/users/roles.mjs +1 -1
- package/resources/admin/organization/projects/users/roles.mjs.map +1 -1
- package/resources/admin/organization/projects/users/users.js +1 -1
- package/resources/admin/organization/projects/users/users.js.map +1 -1
- package/resources/admin/organization/projects/users/users.mjs +1 -1
- package/resources/admin/organization/projects/users/users.mjs.map +1 -1
- package/resources/admin/organization/projects/users.js +1 -1
- package/resources/admin/organization/projects/users.js.map +1 -1
- package/resources/admin/organization/projects/users.mjs +1 -1
- package/resources/admin/organization/projects/users.mjs.map +1 -1
- package/resources/admin/organization/projects.js +1 -1
- package/resources/admin/organization/projects.js.map +1 -1
- package/resources/admin/organization/projects.mjs +1 -1
- package/resources/admin/organization/projects.mjs.map +1 -1
- package/resources/admin/organization/roles.js +1 -1
- package/resources/admin/organization/roles.js.map +1 -1
- package/resources/admin/organization/roles.mjs +1 -1
- package/resources/admin/organization/roles.mjs.map +1 -1
- package/resources/admin/organization/spend-alerts.js +1 -1
- package/resources/admin/organization/spend-alerts.js.map +1 -1
- package/resources/admin/organization/spend-alerts.mjs +1 -1
- package/resources/admin/organization/spend-alerts.mjs.map +1 -1
- package/resources/admin/organization/spend-limit.js +1 -1
- package/resources/admin/organization/spend-limit.js.map +1 -1
- package/resources/admin/organization/spend-limit.mjs +1 -1
- package/resources/admin/organization/spend-limit.mjs.map +1 -1
- package/resources/admin/organization/usage.d.mts +62 -1
- package/resources/admin/organization/usage.d.mts.map +1 -1
- package/resources/admin/organization/usage.d.ts +62 -1
- package/resources/admin/organization/usage.d.ts.map +1 -1
- package/resources/admin/organization/usage.js +1 -1
- package/resources/admin/organization/usage.js.map +1 -1
- package/resources/admin/organization/usage.mjs +1 -1
- package/resources/admin/organization/usage.mjs.map +1 -1
- package/resources/admin/organization/users/index.js +1 -1
- package/resources/admin/organization/users/index.js.map +1 -1
- package/resources/admin/organization/users/index.mjs +1 -1
- package/resources/admin/organization/users/index.mjs.map +1 -1
- package/resources/admin/organization/users/roles.js +1 -1
- package/resources/admin/organization/users/roles.js.map +1 -1
- package/resources/admin/organization/users/roles.mjs +1 -1
- package/resources/admin/organization/users/roles.mjs.map +1 -1
- package/resources/admin/organization/users/users.js +1 -1
- package/resources/admin/organization/users/users.js.map +1 -1
- package/resources/admin/organization/users/users.mjs +1 -1
- package/resources/admin/organization/users/users.mjs.map +1 -1
- package/resources/admin/organization/users.js +1 -1
- package/resources/admin/organization/users.js.map +1 -1
- package/resources/admin/organization/users.mjs +1 -1
- package/resources/admin/organization/users.mjs.map +1 -1
- package/resources/admin/organization.js +1 -1
- package/resources/admin/organization.js.map +1 -1
- package/resources/admin/organization.mjs +1 -1
- package/resources/admin/organization.mjs.map +1 -1
- package/resources/admin.js +1 -1
- package/resources/admin.js.map +1 -1
- package/resources/admin.mjs +1 -1
- package/resources/admin.mjs.map +1 -1
- package/resources/audio/audio.js +1 -1
- package/resources/audio/audio.js.map +1 -1
- package/resources/audio/audio.mjs +1 -1
- package/resources/audio/audio.mjs.map +1 -1
- package/resources/audio/index.js +1 -1
- package/resources/audio/index.js.map +1 -1
- package/resources/audio/index.mjs +1 -1
- package/resources/audio/index.mjs.map +1 -1
- package/resources/audio/speech.js +1 -1
- package/resources/audio/speech.js.map +1 -1
- package/resources/audio/speech.mjs +1 -1
- package/resources/audio/speech.mjs.map +1 -1
- package/resources/audio/transcriptions.d.mts +3 -1
- package/resources/audio/transcriptions.d.mts.map +1 -1
- package/resources/audio/transcriptions.d.ts +3 -1
- package/resources/audio/transcriptions.d.ts.map +1 -1
- package/resources/audio/transcriptions.js +1 -1
- package/resources/audio/transcriptions.js.map +1 -1
- package/resources/audio/transcriptions.mjs +1 -1
- package/resources/audio/transcriptions.mjs.map +1 -1
- package/resources/audio/translations.d.mts +3 -1
- package/resources/audio/translations.d.mts.map +1 -1
- package/resources/audio/translations.d.ts +3 -1
- package/resources/audio/translations.d.ts.map +1 -1
- package/resources/audio/translations.js +1 -1
- package/resources/audio/translations.js.map +1 -1
- package/resources/audio/translations.mjs +1 -1
- package/resources/audio/translations.mjs.map +1 -1
- package/resources/audio.js +1 -1
- package/resources/audio.js.map +1 -1
- package/resources/audio.mjs +1 -1
- package/resources/audio.mjs.map +1 -1
- package/resources/batches.js +1 -1
- package/resources/batches.js.map +1 -1
- package/resources/batches.mjs +1 -1
- package/resources/batches.mjs.map +1 -1
- package/resources/beta/assistants.js +1 -1
- package/resources/beta/assistants.js.map +1 -1
- package/resources/beta/assistants.mjs +1 -1
- package/resources/beta/assistants.mjs.map +1 -1
- package/resources/beta/beta.d.mts +2 -2
- package/resources/beta/beta.d.mts.map +1 -1
- package/resources/beta/beta.d.ts +2 -2
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js +1 -1
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs +1 -1
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/chatkit/chatkit.js +1 -1
- package/resources/beta/chatkit/chatkit.js.map +1 -1
- package/resources/beta/chatkit/chatkit.mjs +1 -1
- package/resources/beta/chatkit/chatkit.mjs.map +1 -1
- package/resources/beta/chatkit/index.js +1 -1
- package/resources/beta/chatkit/index.js.map +1 -1
- package/resources/beta/chatkit/index.mjs +1 -1
- package/resources/beta/chatkit/index.mjs.map +1 -1
- package/resources/beta/chatkit/sessions.js +1 -1
- package/resources/beta/chatkit/sessions.js.map +1 -1
- package/resources/beta/chatkit/sessions.mjs +1 -1
- package/resources/beta/chatkit/sessions.mjs.map +1 -1
- package/resources/beta/chatkit/threads.js +1 -1
- package/resources/beta/chatkit/threads.js.map +1 -1
- package/resources/beta/chatkit/threads.mjs +1 -1
- package/resources/beta/chatkit/threads.mjs.map +1 -1
- package/resources/beta/chatkit.js +1 -1
- package/resources/beta/chatkit.js.map +1 -1
- package/resources/beta/chatkit.mjs +1 -1
- package/resources/beta/chatkit.mjs.map +1 -1
- package/resources/beta/index.d.mts +1 -1
- package/resources/beta/index.d.mts.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 +1 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs +1 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/realtime/index.d.mts.map +1 -1
- package/resources/beta/realtime/index.d.ts.map +1 -1
- package/resources/beta/realtime/index.js +0 -1
- package/resources/beta/realtime/index.js.map +1 -1
- package/resources/beta/realtime/index.mjs +0 -1
- package/resources/beta/realtime/index.mjs.map +1 -1
- package/resources/beta/realtime/realtime.d.mts.map +1 -1
- package/resources/beta/realtime/realtime.d.ts.map +1 -1
- package/resources/beta/realtime/realtime.js +0 -1
- package/resources/beta/realtime/realtime.js.map +1 -1
- package/resources/beta/realtime/realtime.mjs +0 -1
- package/resources/beta/realtime/realtime.mjs.map +1 -1
- package/resources/beta/realtime/sessions.d.mts.map +1 -1
- package/resources/beta/realtime/sessions.d.ts.map +1 -1
- package/resources/beta/realtime/sessions.js +0 -1
- package/resources/beta/realtime/sessions.js.map +1 -1
- package/resources/beta/realtime/sessions.mjs +0 -1
- package/resources/beta/realtime/sessions.mjs.map +1 -1
- package/resources/beta/realtime/transcription-sessions.d.mts.map +1 -1
- package/resources/beta/realtime/transcription-sessions.d.ts.map +1 -1
- package/resources/beta/realtime/transcription-sessions.js +0 -1
- package/resources/beta/realtime/transcription-sessions.js.map +1 -1
- package/resources/beta/realtime/transcription-sessions.mjs +0 -1
- package/resources/beta/realtime/transcription-sessions.mjs.map +1 -1
- package/resources/beta/realtime.d.mts.map +1 -1
- package/resources/beta/realtime.d.ts.map +1 -1
- package/resources/beta/realtime.js +0 -1
- package/resources/beta/realtime.js.map +1 -1
- package/resources/beta/realtime.mjs +0 -1
- package/resources/beta/realtime.mjs.map +1 -1
- package/resources/beta/responses/index.d.mts +1 -1
- package/resources/beta/responses/index.d.mts.map +1 -1
- package/resources/beta/responses/index.d.ts +1 -1
- package/resources/beta/responses/index.d.ts.map +1 -1
- package/resources/beta/responses/index.js +1 -1
- package/resources/beta/responses/index.js.map +1 -1
- package/resources/beta/responses/index.mjs +1 -1
- package/resources/beta/responses/index.mjs.map +1 -1
- package/resources/beta/responses/input-items.js +1 -1
- package/resources/beta/responses/input-items.js.map +1 -1
- package/resources/beta/responses/input-items.mjs +1 -1
- package/resources/beta/responses/input-items.mjs.map +1 -1
- package/resources/beta/responses/input-tokens.js +1 -1
- package/resources/beta/responses/input-tokens.js.map +1 -1
- package/resources/beta/responses/input-tokens.mjs +1 -1
- package/resources/beta/responses/input-tokens.mjs.map +1 -1
- package/resources/beta/responses/internal-base.d.mts +6 -3
- package/resources/beta/responses/internal-base.d.mts.map +1 -1
- package/resources/beta/responses/internal-base.d.ts +6 -3
- package/resources/beta/responses/internal-base.d.ts.map +1 -1
- package/resources/beta/responses/internal-base.js +5 -2
- package/resources/beta/responses/internal-base.js.map +1 -1
- package/resources/beta/responses/internal-base.mjs +5 -2
- package/resources/beta/responses/internal-base.mjs.map +1 -1
- package/resources/beta/responses/responses.d.mts +1243 -132
- package/resources/beta/responses/responses.d.mts.map +1 -1
- package/resources/beta/responses/responses.d.ts +1243 -132
- package/resources/beta/responses/responses.d.ts.map +1 -1
- package/resources/beta/responses/responses.js +1 -1
- package/resources/beta/responses/responses.js.map +1 -1
- package/resources/beta/responses/responses.mjs +1 -1
- package/resources/beta/responses/responses.mjs.map +1 -1
- package/resources/beta/responses/ws-base.js +1 -1
- package/resources/beta/responses/ws-base.js.map +1 -1
- package/resources/beta/responses/ws-base.mjs +1 -1
- package/resources/beta/responses/ws-base.mjs.map +1 -1
- package/resources/beta/responses/ws.js +1 -1
- package/resources/beta/responses/ws.js.map +1 -1
- package/resources/beta/responses/ws.mjs +1 -1
- package/resources/beta/responses/ws.mjs.map +1 -1
- package/resources/beta/responses.js +1 -1
- package/resources/beta/responses.js.map +1 -1
- package/resources/beta/responses.mjs +1 -1
- package/resources/beta/responses.mjs.map +1 -1
- package/resources/beta/threads/index.js +1 -1
- package/resources/beta/threads/index.js.map +1 -1
- package/resources/beta/threads/index.mjs +1 -1
- package/resources/beta/threads/index.mjs.map +1 -1
- package/resources/beta/threads/messages.js +1 -1
- package/resources/beta/threads/messages.js.map +1 -1
- package/resources/beta/threads/messages.mjs +1 -1
- package/resources/beta/threads/messages.mjs.map +1 -1
- package/resources/beta/threads/runs/index.d.mts +1 -1
- package/resources/beta/threads/runs/index.d.mts.map +1 -1
- package/resources/beta/threads/runs/index.d.ts +1 -1
- package/resources/beta/threads/runs/index.d.ts.map +1 -1
- package/resources/beta/threads/runs/index.js +1 -1
- package/resources/beta/threads/runs/index.js.map +1 -1
- package/resources/beta/threads/runs/index.mjs +1 -1
- package/resources/beta/threads/runs/index.mjs.map +1 -1
- package/resources/beta/threads/runs/runs.d.mts.map +1 -1
- package/resources/beta/threads/runs/runs.d.ts.map +1 -1
- package/resources/beta/threads/runs/runs.js +3 -44
- package/resources/beta/threads/runs/runs.js.map +1 -1
- package/resources/beta/threads/runs/runs.mjs +3 -44
- package/resources/beta/threads/runs/runs.mjs.map +1 -1
- package/resources/beta/threads/runs/steps.js +1 -1
- package/resources/beta/threads/runs/steps.js.map +1 -1
- package/resources/beta/threads/runs/steps.mjs +1 -1
- package/resources/beta/threads/runs/steps.mjs.map +1 -1
- package/resources/beta/threads/runs.js +1 -1
- package/resources/beta/threads/runs.js.map +1 -1
- package/resources/beta/threads/runs.mjs +1 -1
- package/resources/beta/threads/runs.mjs.map +1 -1
- package/resources/beta/threads/threads.js +1 -1
- package/resources/beta/threads/threads.js.map +1 -1
- package/resources/beta/threads/threads.mjs +1 -1
- package/resources/beta/threads/threads.mjs.map +1 -1
- package/resources/beta/threads.js +1 -1
- package/resources/beta/threads.js.map +1 -1
- package/resources/beta/threads.mjs +1 -1
- package/resources/beta/threads.mjs.map +1 -1
- package/resources/beta.js +1 -1
- package/resources/beta.js.map +1 -1
- package/resources/beta.mjs +1 -1
- package/resources/beta.mjs.map +1 -1
- package/resources/chat/chat.js +1 -1
- package/resources/chat/chat.js.map +1 -1
- package/resources/chat/chat.mjs +1 -1
- package/resources/chat/chat.mjs.map +1 -1
- package/resources/chat/completions/completions.d.mts +36 -3
- package/resources/chat/completions/completions.d.mts.map +1 -1
- package/resources/chat/completions/completions.d.ts +36 -3
- package/resources/chat/completions/completions.d.ts.map +1 -1
- package/resources/chat/completions/completions.js +2 -5
- package/resources/chat/completions/completions.js.map +1 -1
- package/resources/chat/completions/completions.mjs +2 -5
- package/resources/chat/completions/completions.mjs.map +1 -1
- package/resources/chat/completions/index.js +1 -1
- package/resources/chat/completions/index.js.map +1 -1
- package/resources/chat/completions/index.mjs +1 -1
- package/resources/chat/completions/index.mjs.map +1 -1
- package/resources/chat/completions/messages.js +1 -1
- package/resources/chat/completions/messages.js.map +1 -1
- package/resources/chat/completions/messages.mjs +1 -1
- package/resources/chat/completions/messages.mjs.map +1 -1
- package/resources/chat/completions.js +1 -1
- package/resources/chat/completions.js.map +1 -1
- package/resources/chat/completions.mjs +1 -1
- package/resources/chat/completions.mjs.map +1 -1
- package/resources/chat/index.js +1 -1
- package/resources/chat/index.js.map +1 -1
- package/resources/chat/index.mjs +1 -1
- package/resources/chat/index.mjs.map +1 -1
- package/resources/chat.js +1 -1
- package/resources/chat.js.map +1 -1
- package/resources/chat.mjs +1 -1
- package/resources/chat.mjs.map +1 -1
- package/resources/completions.d.mts +12 -0
- package/resources/completions.d.mts.map +1 -1
- package/resources/completions.d.ts +12 -0
- package/resources/completions.d.ts.map +1 -1
- package/resources/completions.js +1 -1
- package/resources/completions.js.map +1 -1
- package/resources/completions.mjs +1 -1
- package/resources/completions.mjs.map +1 -1
- package/resources/containers/containers.js +1 -1
- package/resources/containers/containers.js.map +1 -1
- package/resources/containers/containers.mjs +1 -1
- package/resources/containers/containers.mjs.map +1 -1
- package/resources/containers/files/content.js +1 -1
- package/resources/containers/files/content.js.map +1 -1
- package/resources/containers/files/content.mjs +1 -1
- package/resources/containers/files/content.mjs.map +1 -1
- package/resources/containers/files/files.js +1 -1
- package/resources/containers/files/files.js.map +1 -1
- package/resources/containers/files/files.mjs +1 -1
- package/resources/containers/files/files.mjs.map +1 -1
- package/resources/containers/files/index.js +1 -1
- package/resources/containers/files/index.js.map +1 -1
- package/resources/containers/files/index.mjs +1 -1
- package/resources/containers/files/index.mjs.map +1 -1
- package/resources/containers/files.js +1 -1
- package/resources/containers/files.js.map +1 -1
- package/resources/containers/files.mjs +1 -1
- package/resources/containers/files.mjs.map +1 -1
- package/resources/containers/index.js +1 -1
- package/resources/containers/index.js.map +1 -1
- package/resources/containers/index.mjs +1 -1
- package/resources/containers/index.mjs.map +1 -1
- package/resources/containers.js +1 -1
- package/resources/containers.js.map +1 -1
- package/resources/containers.mjs +1 -1
- package/resources/containers.mjs.map +1 -1
- package/resources/content-provenance-checks.js +1 -1
- package/resources/content-provenance-checks.js.map +1 -1
- package/resources/content-provenance-checks.mjs +1 -1
- package/resources/content-provenance-checks.mjs.map +1 -1
- package/resources/conversations/conversations.d.mts +1 -1
- package/resources/conversations/conversations.d.mts.map +1 -1
- package/resources/conversations/conversations.d.ts +1 -1
- package/resources/conversations/conversations.d.ts.map +1 -1
- package/resources/conversations/conversations.js +1 -1
- package/resources/conversations/conversations.js.map +1 -1
- package/resources/conversations/conversations.mjs +1 -1
- package/resources/conversations/conversations.mjs.map +1 -1
- package/resources/conversations/index.js +1 -1
- package/resources/conversations/index.js.map +1 -1
- package/resources/conversations/index.mjs +1 -1
- package/resources/conversations/index.mjs.map +1 -1
- package/resources/conversations/items.d.mts +1 -1
- package/resources/conversations/items.d.mts.map +1 -1
- package/resources/conversations/items.d.ts +1 -1
- package/resources/conversations/items.d.ts.map +1 -1
- package/resources/conversations/items.js +1 -1
- package/resources/conversations/items.js.map +1 -1
- package/resources/conversations/items.mjs +1 -1
- package/resources/conversations/items.mjs.map +1 -1
- package/resources/conversations.js +1 -1
- package/resources/conversations.js.map +1 -1
- package/resources/conversations.mjs +1 -1
- package/resources/conversations.mjs.map +1 -1
- package/resources/embeddings.d.mts +9 -0
- package/resources/embeddings.d.mts.map +1 -1
- package/resources/embeddings.d.ts +9 -0
- package/resources/embeddings.d.ts.map +1 -1
- package/resources/embeddings.js +3 -47
- package/resources/embeddings.js.map +1 -1
- package/resources/embeddings.mjs +3 -47
- package/resources/embeddings.mjs.map +1 -1
- package/resources/evals/evals.js +1 -1
- package/resources/evals/evals.js.map +1 -1
- package/resources/evals/evals.mjs +1 -1
- package/resources/evals/evals.mjs.map +1 -1
- package/resources/evals/index.js +1 -1
- package/resources/evals/index.js.map +1 -1
- package/resources/evals/index.mjs +1 -1
- package/resources/evals/index.mjs.map +1 -1
- package/resources/evals/runs/index.js +1 -1
- package/resources/evals/runs/index.js.map +1 -1
- package/resources/evals/runs/index.mjs +1 -1
- package/resources/evals/runs/index.mjs.map +1 -1
- package/resources/evals/runs/output-items.js +1 -1
- package/resources/evals/runs/output-items.js.map +1 -1
- package/resources/evals/runs/output-items.mjs +1 -1
- package/resources/evals/runs/output-items.mjs.map +1 -1
- package/resources/evals/runs/runs.js +1 -1
- package/resources/evals/runs/runs.js.map +1 -1
- package/resources/evals/runs/runs.mjs +1 -1
- package/resources/evals/runs/runs.mjs.map +1 -1
- package/resources/evals/runs.js +1 -1
- package/resources/evals/runs.js.map +1 -1
- package/resources/evals/runs.mjs +1 -1
- package/resources/evals/runs.mjs.map +1 -1
- package/resources/evals.js +1 -1
- package/resources/evals.js.map +1 -1
- package/resources/evals.mjs +1 -1
- package/resources/evals.mjs.map +1 -1
- package/resources/files.d.mts +1 -1
- package/resources/files.d.mts.map +1 -1
- package/resources/files.d.ts +1 -1
- package/resources/files.d.ts.map +1 -1
- package/resources/files.js +4 -17
- package/resources/files.js.map +1 -1
- package/resources/files.mjs +4 -17
- package/resources/files.mjs.map +1 -1
- package/resources/fine-tuning/alpha/alpha.js +1 -1
- package/resources/fine-tuning/alpha/alpha.js.map +1 -1
- package/resources/fine-tuning/alpha/alpha.mjs +1 -1
- package/resources/fine-tuning/alpha/alpha.mjs.map +1 -1
- package/resources/fine-tuning/alpha/graders.js +1 -1
- package/resources/fine-tuning/alpha/graders.js.map +1 -1
- package/resources/fine-tuning/alpha/graders.mjs +1 -1
- package/resources/fine-tuning/alpha/graders.mjs.map +1 -1
- package/resources/fine-tuning/alpha/index.js +1 -1
- package/resources/fine-tuning/alpha/index.js.map +1 -1
- package/resources/fine-tuning/alpha/index.mjs +1 -1
- package/resources/fine-tuning/alpha/index.mjs.map +1 -1
- package/resources/fine-tuning/alpha.js +1 -1
- package/resources/fine-tuning/alpha.js.map +1 -1
- package/resources/fine-tuning/alpha.mjs +1 -1
- package/resources/fine-tuning/alpha.mjs.map +1 -1
- package/resources/fine-tuning/checkpoints/checkpoints.js +1 -1
- package/resources/fine-tuning/checkpoints/checkpoints.js.map +1 -1
- package/resources/fine-tuning/checkpoints/checkpoints.mjs +1 -1
- package/resources/fine-tuning/checkpoints/checkpoints.mjs.map +1 -1
- package/resources/fine-tuning/checkpoints/index.js +1 -1
- package/resources/fine-tuning/checkpoints/index.js.map +1 -1
- package/resources/fine-tuning/checkpoints/index.mjs +1 -1
- package/resources/fine-tuning/checkpoints/index.mjs.map +1 -1
- package/resources/fine-tuning/checkpoints/permissions.js +1 -1
- package/resources/fine-tuning/checkpoints/permissions.js.map +1 -1
- package/resources/fine-tuning/checkpoints/permissions.mjs +1 -1
- package/resources/fine-tuning/checkpoints/permissions.mjs.map +1 -1
- package/resources/fine-tuning/checkpoints.js +1 -1
- package/resources/fine-tuning/checkpoints.js.map +1 -1
- package/resources/fine-tuning/checkpoints.mjs +1 -1
- package/resources/fine-tuning/checkpoints.mjs.map +1 -1
- package/resources/fine-tuning/fine-tuning.js +1 -1
- package/resources/fine-tuning/fine-tuning.js.map +1 -1
- package/resources/fine-tuning/fine-tuning.mjs +1 -1
- package/resources/fine-tuning/fine-tuning.mjs.map +1 -1
- package/resources/fine-tuning/index.js +1 -1
- package/resources/fine-tuning/index.js.map +1 -1
- package/resources/fine-tuning/index.mjs +1 -1
- package/resources/fine-tuning/index.mjs.map +1 -1
- package/resources/fine-tuning/jobs/checkpoints.js +1 -1
- package/resources/fine-tuning/jobs/checkpoints.js.map +1 -1
- package/resources/fine-tuning/jobs/checkpoints.mjs +1 -1
- package/resources/fine-tuning/jobs/checkpoints.mjs.map +1 -1
- package/resources/fine-tuning/jobs/index.js +1 -1
- package/resources/fine-tuning/jobs/index.js.map +1 -1
- package/resources/fine-tuning/jobs/index.mjs +1 -1
- package/resources/fine-tuning/jobs/index.mjs.map +1 -1
- package/resources/fine-tuning/jobs/jobs.js +1 -1
- package/resources/fine-tuning/jobs/jobs.js.map +1 -1
- package/resources/fine-tuning/jobs/jobs.mjs +1 -1
- package/resources/fine-tuning/jobs/jobs.mjs.map +1 -1
- package/resources/fine-tuning/jobs.js +1 -1
- package/resources/fine-tuning/jobs.js.map +1 -1
- package/resources/fine-tuning/jobs.mjs +1 -1
- package/resources/fine-tuning/jobs.mjs.map +1 -1
- package/resources/fine-tuning/methods.js +1 -1
- package/resources/fine-tuning/methods.js.map +1 -1
- package/resources/fine-tuning/methods.mjs +1 -1
- package/resources/fine-tuning/methods.mjs.map +1 -1
- package/resources/fine-tuning.js +1 -1
- package/resources/fine-tuning.js.map +1 -1
- package/resources/fine-tuning.mjs +1 -1
- package/resources/fine-tuning.mjs.map +1 -1
- package/resources/graders/grader-models.js +1 -1
- package/resources/graders/grader-models.js.map +1 -1
- package/resources/graders/grader-models.mjs +1 -1
- package/resources/graders/grader-models.mjs.map +1 -1
- package/resources/graders/graders.js +1 -1
- package/resources/graders/graders.js.map +1 -1
- package/resources/graders/graders.mjs +1 -1
- package/resources/graders/graders.mjs.map +1 -1
- package/resources/graders/index.js +1 -1
- package/resources/graders/index.js.map +1 -1
- package/resources/graders/index.mjs +1 -1
- package/resources/graders/index.mjs.map +1 -1
- package/resources/graders.js +1 -1
- package/resources/graders.js.map +1 -1
- package/resources/graders.mjs +1 -1
- package/resources/graders.mjs.map +1 -1
- package/resources/images.d.mts +12 -22
- package/resources/images.d.mts.map +1 -1
- package/resources/images.d.ts +12 -22
- package/resources/images.d.ts.map +1 -1
- package/resources/images.js +8 -2
- package/resources/images.js.map +1 -1
- package/resources/images.mjs +8 -2
- package/resources/images.mjs.map +1 -1
- package/resources/index.js +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/models.d.mts +4 -0
- package/resources/models.d.mts.map +1 -1
- package/resources/models.d.ts +4 -0
- package/resources/models.d.ts.map +1 -1
- package/resources/models.js +1 -1
- package/resources/models.js.map +1 -1
- package/resources/models.mjs +1 -1
- package/resources/models.mjs.map +1 -1
- package/resources/moderations.js +1 -1
- package/resources/moderations.js.map +1 -1
- package/resources/moderations.mjs +1 -1
- package/resources/moderations.mjs.map +1 -1
- package/resources/realtime/calls.d.mts +23 -1
- package/resources/realtime/calls.d.mts.map +1 -1
- package/resources/realtime/calls.d.ts +23 -1
- package/resources/realtime/calls.d.ts.map +1 -1
- package/resources/realtime/calls.js +25 -1
- package/resources/realtime/calls.js.map +1 -1
- package/resources/realtime/calls.mjs +25 -1
- package/resources/realtime/calls.mjs.map +1 -1
- package/resources/realtime/client-secrets.js +1 -1
- package/resources/realtime/client-secrets.js.map +1 -1
- package/resources/realtime/client-secrets.mjs +1 -1
- package/resources/realtime/client-secrets.mjs.map +1 -1
- package/resources/realtime/index.d.mts +1 -1
- package/resources/realtime/index.d.mts.map +1 -1
- package/resources/realtime/index.d.ts +1 -1
- package/resources/realtime/index.d.ts.map +1 -1
- package/resources/realtime/index.js +1 -1
- package/resources/realtime/index.js.map +1 -1
- package/resources/realtime/index.mjs +2 -2
- package/resources/realtime/index.mjs.map +1 -1
- package/resources/realtime/realtime.d.mts +5 -4
- package/resources/realtime/realtime.d.mts.map +1 -1
- package/resources/realtime/realtime.d.ts +5 -4
- package/resources/realtime/realtime.d.ts.map +1 -1
- package/resources/realtime/realtime.js +1 -1
- package/resources/realtime/realtime.js.map +1 -1
- package/resources/realtime/realtime.mjs +1 -1
- package/resources/realtime/realtime.mjs.map +1 -1
- package/resources/realtime.js +1 -1
- package/resources/realtime.js.map +1 -1
- package/resources/realtime.mjs +1 -1
- package/resources/realtime.mjs.map +1 -1
- package/resources/responses/index.js +1 -1
- package/resources/responses/index.js.map +1 -1
- package/resources/responses/index.mjs +1 -1
- package/resources/responses/index.mjs.map +1 -1
- package/resources/responses/input-items.js +1 -1
- package/resources/responses/input-items.js.map +1 -1
- package/resources/responses/input-items.mjs +1 -1
- package/resources/responses/input-items.mjs.map +1 -1
- package/resources/responses/input-tokens.js +1 -1
- package/resources/responses/input-tokens.js.map +1 -1
- package/resources/responses/input-tokens.mjs +1 -1
- package/resources/responses/input-tokens.mjs.map +1 -1
- package/resources/responses/internal-base.d.mts +6 -3
- package/resources/responses/internal-base.d.mts.map +1 -1
- package/resources/responses/internal-base.d.ts +6 -3
- package/resources/responses/internal-base.d.ts.map +1 -1
- package/resources/responses/internal-base.js +5 -2
- package/resources/responses/internal-base.js.map +1 -1
- package/resources/responses/internal-base.mjs +5 -2
- package/resources/responses/internal-base.mjs.map +1 -1
- package/resources/responses/responses.d.mts +1059 -32
- package/resources/responses/responses.d.mts.map +1 -1
- package/resources/responses/responses.d.ts +1059 -32
- package/resources/responses/responses.d.ts.map +1 -1
- package/resources/responses/responses.js +1 -1
- package/resources/responses/responses.js.map +1 -1
- package/resources/responses/responses.mjs +1 -1
- package/resources/responses/responses.mjs.map +1 -1
- package/resources/responses/ws-base.js +1 -1
- package/resources/responses/ws-base.js.map +1 -1
- package/resources/responses/ws-base.mjs +1 -1
- package/resources/responses/ws-base.mjs.map +1 -1
- package/resources/responses/ws.js +1 -1
- package/resources/responses/ws.js.map +1 -1
- package/resources/responses/ws.mjs +1 -1
- package/resources/responses/ws.mjs.map +1 -1
- package/resources/responses.js +1 -1
- package/resources/responses.js.map +1 -1
- package/resources/responses.mjs +1 -1
- package/resources/responses.mjs.map +1 -1
- package/resources/shared.d.mts +3 -3
- package/resources/shared.d.mts.map +1 -1
- package/resources/shared.d.ts +3 -3
- package/resources/shared.d.ts.map +1 -1
- package/resources/shared.js +1 -1
- package/resources/shared.js.map +1 -1
- package/resources/shared.mjs +1 -1
- package/resources/shared.mjs.map +1 -1
- package/resources/skills/content.js +1 -1
- package/resources/skills/content.js.map +1 -1
- package/resources/skills/content.mjs +1 -1
- package/resources/skills/content.mjs.map +1 -1
- package/resources/skills/index.js +1 -1
- package/resources/skills/index.js.map +1 -1
- package/resources/skills/index.mjs +1 -1
- package/resources/skills/index.mjs.map +1 -1
- package/resources/skills/skills.d.mts.map +1 -1
- package/resources/skills/skills.d.ts.map +1 -1
- package/resources/skills/skills.js +4 -2
- package/resources/skills/skills.js.map +1 -1
- package/resources/skills/skills.mjs +4 -2
- package/resources/skills/skills.mjs.map +1 -1
- package/resources/skills/versions/content.js +1 -1
- package/resources/skills/versions/content.js.map +1 -1
- package/resources/skills/versions/content.mjs +1 -1
- package/resources/skills/versions/content.mjs.map +1 -1
- package/resources/skills/versions/index.js +1 -1
- package/resources/skills/versions/index.js.map +1 -1
- package/resources/skills/versions/index.mjs +1 -1
- package/resources/skills/versions/index.mjs.map +1 -1
- package/resources/skills/versions/versions.d.mts.map +1 -1
- package/resources/skills/versions/versions.d.ts.map +1 -1
- package/resources/skills/versions/versions.js +4 -2
- package/resources/skills/versions/versions.js.map +1 -1
- package/resources/skills/versions/versions.mjs +4 -2
- package/resources/skills/versions/versions.mjs.map +1 -1
- package/resources/skills/versions.js +1 -1
- package/resources/skills/versions.js.map +1 -1
- package/resources/skills/versions.mjs +1 -1
- package/resources/skills/versions.mjs.map +1 -1
- package/resources/skills.js +1 -1
- package/resources/skills.js.map +1 -1
- package/resources/skills.mjs +1 -1
- package/resources/skills.mjs.map +1 -1
- package/resources/uploads/index.js +1 -1
- package/resources/uploads/index.js.map +1 -1
- package/resources/uploads/index.mjs +1 -1
- package/resources/uploads/index.mjs.map +1 -1
- package/resources/uploads/parts.js +1 -1
- package/resources/uploads/parts.js.map +1 -1
- package/resources/uploads/parts.mjs +1 -1
- package/resources/uploads/parts.mjs.map +1 -1
- package/resources/uploads/uploads.js +1 -1
- package/resources/uploads/uploads.js.map +1 -1
- package/resources/uploads/uploads.mjs +1 -1
- package/resources/uploads/uploads.mjs.map +1 -1
- package/resources/uploads.js +1 -1
- package/resources/uploads.js.map +1 -1
- package/resources/uploads.mjs +1 -1
- package/resources/uploads.mjs.map +1 -1
- package/resources/vector-stores/file-batches.d.mts.map +1 -1
- package/resources/vector-stores/file-batches.d.ts.map +1 -1
- package/resources/vector-stores/file-batches.js +6 -63
- package/resources/vector-stores/file-batches.js.map +1 -1
- package/resources/vector-stores/file-batches.mjs +6 -63
- package/resources/vector-stores/file-batches.mjs.map +1 -1
- package/resources/vector-stores/files.d.mts +1 -1
- package/resources/vector-stores/files.d.mts.map +1 -1
- package/resources/vector-stores/files.d.ts +1 -1
- package/resources/vector-stores/files.d.ts.map +1 -1
- package/resources/vector-stores/files.js +3 -36
- package/resources/vector-stores/files.js.map +1 -1
- package/resources/vector-stores/files.mjs +3 -36
- package/resources/vector-stores/files.mjs.map +1 -1
- package/resources/vector-stores/index.js +1 -1
- package/resources/vector-stores/index.js.map +1 -1
- package/resources/vector-stores/index.mjs +1 -1
- package/resources/vector-stores/index.mjs.map +1 -1
- package/resources/vector-stores/vector-stores.js +1 -1
- package/resources/vector-stores/vector-stores.js.map +1 -1
- package/resources/vector-stores/vector-stores.mjs +1 -1
- package/resources/vector-stores/vector-stores.mjs.map +1 -1
- package/resources/vector-stores.js +1 -1
- package/resources/vector-stores.js.map +1 -1
- package/resources/vector-stores.mjs +1 -1
- package/resources/vector-stores.mjs.map +1 -1
- package/resources/videos.d.mts +23 -0
- package/resources/videos.d.mts.map +1 -1
- package/resources/videos.d.ts +23 -0
- package/resources/videos.d.ts.map +1 -1
- package/resources/videos.js +24 -1
- package/resources/videos.js.map +1 -1
- package/resources/videos.mjs +24 -1
- package/resources/videos.mjs.map +1 -1
- package/resources/webhooks/index.js +1 -1
- package/resources/webhooks/index.js.map +1 -1
- package/resources/webhooks/index.mjs +1 -1
- package/resources/webhooks/index.mjs.map +1 -1
- package/resources/webhooks/webhooks.d.mts.map +1 -1
- package/resources/webhooks/webhooks.d.ts.map +1 -1
- package/resources/webhooks/webhooks.js +6 -43
- package/resources/webhooks/webhooks.js.map +1 -1
- package/resources/webhooks/webhooks.mjs +6 -43
- package/resources/webhooks/webhooks.mjs.map +1 -1
- package/resources/webhooks.js +1 -1
- package/resources/webhooks.js.map +1 -1
- package/resources/webhooks.mjs +1 -1
- package/resources/webhooks.mjs.map +1 -1
- package/src/_vendor/partial-json-parser/parser.ts +63 -33
- package/src/_vendor/zod-to-json-schema/Options.ts +30 -18
- package/src/_vendor/zod-to-json-schema/Refs.ts +7 -6
- package/src/_vendor/zod-to-json-schema/errorMessages.ts +5 -3
- package/src/_vendor/zod-to-json-schema/index.ts +3 -1
- package/src/_vendor/zod-to-json-schema/parseDef.ts +150 -64
- package/src/_vendor/zod-to-json-schema/parsers/array.ts +8 -5
- package/src/_vendor/zod-to-json-schema/parsers/bigint.ts +18 -12
- package/src/_vendor/zod-to-json-schema/parsers/branded.ts +2 -2
- package/src/_vendor/zod-to-json-schema/parsers/catch.ts +4 -5
- package/src/_vendor/zod-to-json-schema/parsers/date.ts +16 -10
- package/src/_vendor/zod-to-json-schema/parsers/default.ts +4 -3
- package/src/_vendor/zod-to-json-schema/parsers/effects.ts +4 -3
- package/src/_vendor/zod-to-json-schema/parsers/enum.ts +1 -1
- package/src/_vendor/zod-to-json-schema/parsers/intersection.ts +12 -9
- package/src/_vendor/zod-to-json-schema/parsers/literal.ts +11 -2
- package/src/_vendor/zod-to-json-schema/parsers/map.ts +6 -4
- package/src/_vendor/zod-to-json-schema/parsers/nativeEnum.ts +10 -11
- package/src/_vendor/zod-to-json-schema/parsers/null.ts +3 -3
- package/src/_vendor/zod-to-json-schema/parsers/nullable.ts +8 -5
- package/src/_vendor/zod-to-json-schema/parsers/number.ts +15 -8
- package/src/_vendor/zod-to-json-schema/parsers/object.ts +57 -54
- package/src/_vendor/zod-to-json-schema/parsers/optional.ts +6 -5
- package/src/_vendor/zod-to-json-schema/parsers/pipeline.ts +5 -4
- package/src/_vendor/zod-to-json-schema/parsers/promise.ts +4 -3
- package/src/_vendor/zod-to-json-schema/parsers/readonly.ts +4 -5
- package/src/_vendor/zod-to-json-schema/parsers/record.ts +20 -19
- package/src/_vendor/zod-to-json-schema/parsers/set.ts +6 -4
- package/src/_vendor/zod-to-json-schema/parsers/string.ts +60 -36
- package/src/_vendor/zod-to-json-schema/parsers/tuple.ts +18 -18
- package/src/_vendor/zod-to-json-schema/parsers/union.ts +48 -33
- package/src/_vendor/zod-to-json-schema/util.ts +10 -6
- package/src/_vendor/zod-to-json-schema/zodToJsonSchema.ts +119 -45
- package/src/auth/index.ts +6 -1
- package/src/auth/subject-token-providers.ts +267 -12
- package/src/auth/types.ts +42 -5
- package/src/auth/workload-identity-auth.ts +164 -22
- package/src/auth/x509-transport.ts +49 -0
- package/src/azure.ts +81 -26
- package/src/bedrock.ts +93 -9
- package/src/beta/realtime/internal-base.ts +94 -15
- package/src/beta/realtime/websocket.ts +237 -44
- package/src/beta/realtime/ws.ts +124 -23
- package/src/client.ts +760 -104
- package/src/core/EventEmitter.ts +136 -24
- package/src/core/api-promise.ts +0 -2
- package/src/core/error.ts +6 -8
- package/src/core/pagination.ts +3 -5
- package/src/core/resource.ts +0 -2
- package/src/core/streaming.ts +216 -83
- package/src/helpers/audio.ts +177 -31
- package/src/helpers/standard-schema.ts +294 -57
- package/src/helpers/zod-v3-strict-schema.ts +514 -0
- package/src/helpers/zod.ts +151 -41
- package/src/index.ts +2 -4
- package/src/internal/assistant-stream-delta.ts +434 -0
- package/src/internal/auth/x509-token-exchange.ts +310 -0
- package/src/internal/auth/x509-transport-capability.ts +219 -0
- package/src/internal/auth/x509-transport-registry.ts +118 -0
- package/src/internal/auth/x509-transport-state-browser.ts +36 -0
- package/src/internal/auth/x509-transport-state.cts +36 -0
- package/src/internal/auth/x509-workload-identity-auth.ts +958 -0
- package/src/internal/bedrock.ts +410 -18
- package/src/internal/builtin-types.ts +0 -2
- package/src/internal/data-residency.ts +44 -0
- package/src/internal/decoders/line.ts +144 -61
- package/src/internal/detect-platform.ts +1 -3
- package/src/internal/errors.ts +0 -2
- package/src/internal/headers.ts +0 -2
- package/src/internal/multipart-encoding.ts +53 -0
- package/src/internal/parse.ts +31 -8
- package/src/internal/provider.ts +29 -0
- package/src/internal/qs/formats.ts +1 -1
- package/src/internal/qs/stringify.ts +54 -53
- package/src/internal/qs/types.ts +1 -1
- package/src/internal/qs/utils.ts +432 -54
- package/src/internal/request-options.ts +52 -3
- package/src/internal/responses/canonical-output-text.ts +160 -0
- package/src/internal/responses/output-text-index.ts +84 -0
- package/src/internal/responses/response-accumulator.ts +1232 -0
- package/src/internal/shim-types.ts +3 -4
- package/src/internal/shims.ts +0 -2
- package/src/internal/stream-utils.ts +37 -5
- package/src/internal/to-file.ts +87 -33
- package/src/internal/types.ts +21 -29
- package/src/internal/uploads.ts +323 -86
- package/src/internal/utils/base64.ts +0 -2
- package/src/internal/utils/bytes.ts +5 -0
- package/src/internal/utils/env.ts +9 -7
- package/src/internal/utils/log.ts +8 -12
- package/src/internal/utils/path.ts +51 -32
- package/src/internal/utils/query.ts +0 -2
- package/src/internal/utils/sleep.ts +0 -2
- package/src/internal/utils/uuid.ts +0 -2
- package/src/internal/utils/values.ts +0 -2
- package/src/internal/utils.ts +0 -2
- package/src/internal/ws-adapter-browser.ts +81 -24
- package/src/internal/ws-adapter-node.ts +105 -26
- package/src/internal/ws-adapter.ts +23 -0
- package/src/internal/ws.ts +153 -50
- package/src/lib/.keep +2 -2
- package/src/lib/AbstractChatCompletionRunner.ts +140 -62
- package/src/lib/AssistantStream.ts +498 -239
- package/src/lib/ChatCompletionRunner.ts +24 -16
- package/src/lib/ChatCompletionStream.ts +1783 -249
- package/src/lib/ChatCompletionStreamingRunner.ts +54 -94
- package/src/lib/EventEmitter.ts +127 -27
- package/src/lib/EventStream.ts +1704 -62
- package/src/lib/ResponsesParser.ts +95 -40
- package/src/lib/RunnableFunction.ts +62 -32
- package/src/lib/Util.ts +7 -5
- package/src/lib/assistant-run-polling.ts +27 -0
- package/src/lib/chatCompletionUtils.ts +9 -10
- package/src/lib/embeddings.ts +65 -0
- package/src/lib/file-processing.ts +36 -0
- package/src/lib/jsonschema.ts +74 -34
- package/src/lib/parser.ts +197 -61
- package/src/lib/polling.ts +144 -0
- package/src/lib/responses/EventTypes.ts +16 -1
- package/src/lib/responses/ResponseAccumulator.ts +8 -402
- package/src/lib/responses/ResponseInputItems.ts +1 -0
- package/src/lib/responses/ResponseStream.ts +105 -91
- package/src/lib/transform.ts +160 -108
- package/src/lib/vector-store-polling.ts +46 -0
- package/src/lib/vector-store-upload.ts +53 -0
- package/src/lib/webhook-signature.ts +164 -0
- package/src/providers/bedrock/aws.ts +114 -41
- package/src/providers/bedrock.ts +22 -4
- package/src/realtime/internal-base.ts +206 -41
- package/src/realtime/websocket.ts +226 -41
- package/src/realtime/ws.ts +112 -18
- package/src/resources/admin/admin.ts +1 -1
- package/src/resources/admin/index.ts +1 -1
- package/src/resources/admin/organization/admin-api-keys.ts +1 -1
- package/src/resources/admin/organization/audit-logs.ts +5 -1
- package/src/resources/admin/organization/certificates.ts +1 -1
- package/src/resources/admin/organization/data-retention.ts +1 -1
- package/src/resources/admin/organization/groups/groups.ts +1 -1
- package/src/resources/admin/organization/groups/index.ts +1 -1
- package/src/resources/admin/organization/groups/roles.ts +1 -1
- package/src/resources/admin/organization/groups/users.ts +1 -1
- package/src/resources/admin/organization/groups.ts +1 -1
- package/src/resources/admin/organization/index.ts +3 -1
- package/src/resources/admin/organization/invites.ts +1 -1
- package/src/resources/admin/organization/organization.ts +5 -1
- package/src/resources/admin/organization/projects/api-keys.ts +1 -1
- package/src/resources/admin/organization/projects/certificates.ts +1 -1
- package/src/resources/admin/organization/projects/data-retention.ts +1 -1
- package/src/resources/admin/organization/projects/groups/groups.ts +1 -1
- package/src/resources/admin/organization/projects/groups/index.ts +1 -1
- package/src/resources/admin/organization/projects/groups/roles.ts +1 -1
- package/src/resources/admin/organization/projects/groups.ts +1 -1
- package/src/resources/admin/organization/projects/hosted-tool-permissions.ts +1 -1
- package/src/resources/admin/organization/projects/index.ts +2 -1
- package/src/resources/admin/organization/projects/model-permissions.ts +1 -1
- package/src/resources/admin/organization/projects/projects.ts +38 -5
- package/src/resources/admin/organization/projects/rate-limits.ts +1 -1
- package/src/resources/admin/organization/projects/roles.ts +1 -1
- package/src/resources/admin/organization/projects/service-accounts/api-keys.ts +1 -1
- package/src/resources/admin/organization/projects/service-accounts/index.ts +1 -1
- package/src/resources/admin/organization/projects/service-accounts/service-accounts.ts +1 -1
- package/src/resources/admin/organization/projects/service-accounts.ts +1 -1
- package/src/resources/admin/organization/projects/spend-alerts.ts +1 -1
- package/src/resources/admin/organization/projects/spend-limit.ts +1 -1
- package/src/resources/admin/organization/projects/users/index.ts +1 -1
- package/src/resources/admin/organization/projects/users/roles.ts +1 -1
- package/src/resources/admin/organization/projects/users/users.ts +1 -1
- package/src/resources/admin/organization/projects/users.ts +1 -1
- package/src/resources/admin/organization/projects.ts +1 -1
- package/src/resources/admin/organization/roles.ts +1 -1
- package/src/resources/admin/organization/spend-alerts.ts +1 -1
- package/src/resources/admin/organization/spend-limit.ts +1 -1
- package/src/resources/admin/organization/usage.ts +84 -1
- package/src/resources/admin/organization/users/index.ts +1 -1
- package/src/resources/admin/organization/users/roles.ts +1 -1
- package/src/resources/admin/organization/users/users.ts +1 -1
- package/src/resources/admin/organization/users.ts +1 -1
- package/src/resources/admin/organization.ts +1 -1
- package/src/resources/admin.ts +1 -1
- package/src/resources/audio/audio.ts +1 -1
- package/src/resources/audio/index.ts +1 -1
- package/src/resources/audio/speech.ts +1 -1
- package/src/resources/audio/transcriptions.ts +4 -2
- package/src/resources/audio/translations.ts +4 -2
- package/src/resources/audio.ts +1 -1
- package/src/resources/batches.ts +1 -1
- package/src/resources/beta/assistants.ts +1 -1
- package/src/resources/beta/beta.ts +17 -1
- package/src/resources/beta/chatkit/chatkit.ts +1 -1
- package/src/resources/beta/chatkit/index.ts +1 -1
- package/src/resources/beta/chatkit/sessions.ts +1 -1
- package/src/resources/beta/chatkit/threads.ts +1 -1
- package/src/resources/beta/chatkit.ts +1 -1
- package/src/resources/beta/index.ts +9 -1
- package/src/resources/beta/realtime/index.ts +0 -2
- package/src/resources/beta/realtime/realtime.ts +0 -2
- package/src/resources/beta/realtime/sessions.ts +0 -2
- package/src/resources/beta/realtime/transcription-sessions.ts +0 -2
- package/src/resources/beta/realtime.ts +0 -2
- package/src/resources/beta/responses/index.ts +9 -1
- package/src/resources/beta/responses/input-items.ts +1 -1
- package/src/resources/beta/responses/input-tokens.ts +1 -1
- package/src/resources/beta/responses/internal-base.ts +11 -10
- package/src/resources/beta/responses/responses.ts +2276 -956
- package/src/resources/beta/responses/ws-base.ts +1 -1
- package/src/resources/beta/responses/ws.ts +1 -1
- package/src/resources/beta/responses.ts +1 -1
- package/src/resources/beta/threads/index.ts +1 -1
- package/src/resources/beta/threads/messages.ts +1 -1
- package/src/resources/beta/threads/runs/index.ts +2 -2
- package/src/resources/beta/threads/runs/runs.ts +3 -46
- package/src/resources/beta/threads/runs/steps.ts +1 -1
- package/src/resources/beta/threads/runs.ts +1 -1
- package/src/resources/beta/threads/threads.ts +1 -1
- package/src/resources/beta/threads.ts +1 -1
- package/src/resources/beta.ts +1 -1
- package/src/resources/chat/chat.ts +1 -1
- package/src/resources/chat/completions/completions.ts +46 -8
- package/src/resources/chat/completions/index.ts +1 -1
- package/src/resources/chat/completions/messages.ts +1 -1
- package/src/resources/chat/completions.ts +1 -1
- package/src/resources/chat/index.ts +1 -1
- package/src/resources/chat.ts +1 -1
- package/src/resources/completions.ts +16 -1
- package/src/resources/containers/containers.ts +1 -1
- package/src/resources/containers/files/content.ts +1 -1
- package/src/resources/containers/files/files.ts +1 -1
- package/src/resources/containers/files/index.ts +1 -1
- package/src/resources/containers/files.ts +1 -1
- package/src/resources/containers/index.ts +1 -1
- package/src/resources/containers.ts +1 -1
- package/src/resources/content-provenance-checks.ts +1 -1
- package/src/resources/conversations/conversations.ts +2 -2
- package/src/resources/conversations/index.ts +1 -1
- package/src/resources/conversations/items.ts +2 -2
- package/src/resources/conversations.ts +1 -1
- package/src/resources/embeddings.ts +16 -43
- package/src/resources/evals/evals.ts +1 -1
- package/src/resources/evals/index.ts +1 -1
- package/src/resources/evals/runs/index.ts +1 -1
- package/src/resources/evals/runs/output-items.ts +1 -1
- package/src/resources/evals/runs/runs.ts +1 -1
- package/src/resources/evals/runs.ts +1 -1
- package/src/resources/evals.ts +1 -1
- package/src/resources/files.ts +4 -21
- package/src/resources/fine-tuning/alpha/alpha.ts +1 -1
- package/src/resources/fine-tuning/alpha/graders.ts +1 -1
- package/src/resources/fine-tuning/alpha/index.ts +1 -1
- package/src/resources/fine-tuning/alpha.ts +1 -1
- package/src/resources/fine-tuning/checkpoints/checkpoints.ts +1 -1
- package/src/resources/fine-tuning/checkpoints/index.ts +1 -1
- package/src/resources/fine-tuning/checkpoints/permissions.ts +1 -1
- package/src/resources/fine-tuning/checkpoints.ts +1 -1
- package/src/resources/fine-tuning/fine-tuning.ts +1 -1
- package/src/resources/fine-tuning/index.ts +1 -1
- package/src/resources/fine-tuning/jobs/checkpoints.ts +1 -1
- package/src/resources/fine-tuning/jobs/index.ts +1 -1
- package/src/resources/fine-tuning/jobs/jobs.ts +1 -1
- package/src/resources/fine-tuning/jobs.ts +1 -1
- package/src/resources/fine-tuning/methods.ts +1 -1
- package/src/resources/fine-tuning.ts +1 -1
- package/src/resources/graders/grader-models.ts +1 -1
- package/src/resources/graders/graders.ts +1 -1
- package/src/resources/graders/index.ts +1 -1
- package/src/resources/graders.ts +1 -1
- package/src/resources/images.ts +20 -24
- package/src/resources/index.ts +1 -1
- package/src/resources/models.ts +6 -1
- package/src/resources/moderations.ts +1 -1
- package/src/resources/realtime/api.md +1 -0
- package/src/resources/realtime/calls.ts +47 -1
- package/src/resources/realtime/client-secrets.ts +1 -1
- package/src/resources/realtime/index.ts +8 -2
- package/src/resources/realtime/realtime.ts +6 -4
- package/src/resources/realtime.ts +1 -1
- package/src/resources/responses/api.md +8 -0
- package/src/resources/responses/index.ts +1 -1
- package/src/resources/responses/input-items.ts +1 -1
- package/src/resources/responses/input-tokens.ts +1 -1
- package/src/resources/responses/internal-base.ts +11 -10
- package/src/resources/responses/responses.ts +1530 -332
- package/src/resources/responses/ws-base.ts +1 -1
- package/src/resources/responses/ws.ts +1 -1
- package/src/resources/responses.ts +1 -1
- package/src/resources/shared.ts +14 -3
- package/src/resources/skills/content.ts +1 -1
- package/src/resources/skills/index.ts +1 -1
- package/src/resources/skills/skills.ts +4 -2
- package/src/resources/skills/versions/content.ts +1 -1
- package/src/resources/skills/versions/index.ts +1 -1
- package/src/resources/skills/versions/versions.ts +4 -2
- package/src/resources/skills/versions.ts +1 -1
- package/src/resources/skills.ts +1 -1
- package/src/resources/uploads/index.ts +1 -1
- package/src/resources/uploads/parts.ts +1 -1
- package/src/resources/uploads/uploads.ts +1 -1
- package/src/resources/uploads.ts +1 -1
- package/src/resources/vector-stores/file-batches.ts +13 -78
- package/src/resources/vector-stores/files.ts +4 -44
- package/src/resources/vector-stores/index.ts +1 -1
- package/src/resources/vector-stores/vector-stores.ts +1 -1
- package/src/resources/vector-stores.ts +1 -1
- package/src/resources/videos.ts +24 -1
- package/src/resources/webhooks/index.ts +1 -1
- package/src/resources/webhooks/webhooks.ts +6 -65
- package/src/resources/webhooks.ts +1 -1
- package/src/tsconfig.dist-src.d.ts +29 -0
- package/src/tsconfig.json +6 -3
- package/src/version.ts +2 -1
- package/version.d.mts +2 -1
- package/version.d.mts.map +1 -1
- package/version.d.ts +2 -1
- package/version.d.ts.map +1 -1
- package/version.js +2 -1
- package/version.js.map +1 -1
- package/version.mjs +2 -1
- package/version.mjs.map +1 -1
|
@@ -1,128 +1,192 @@
|
|
|
1
|
-
import { partialParse } from '../_vendor/partial-json-parser/parser';
|
|
1
|
+
import { MalformedJSON, partialParse } from '../_vendor/partial-json-parser/parser';
|
|
2
2
|
import {
|
|
3
3
|
APIUserAbortError,
|
|
4
4
|
ContentFilterFinishReasonError,
|
|
5
5
|
LengthFinishReasonError,
|
|
6
6
|
OpenAIError,
|
|
7
7
|
} from '../error';
|
|
8
|
-
import OpenAI from '../index';
|
|
9
|
-
import { RequestOptions } from '../internal/request-options';
|
|
10
|
-
import {
|
|
8
|
+
import type OpenAI from '../index';
|
|
9
|
+
import { observeJSONRequestBody, type RequestOptions } from '../internal/request-options';
|
|
10
|
+
import type { ReadableStream } from '../internal/shim-types';
|
|
11
11
|
import { uuid4 } from '../internal/utils/uuid';
|
|
12
|
+
import { hasOwn } from '../internal/utils/values';
|
|
12
13
|
import {
|
|
13
|
-
AutoParseableResponseFormat,
|
|
14
14
|
hasAutoParseableInput,
|
|
15
|
-
isAutoParsableResponseFormat,
|
|
16
15
|
isAutoParsableTool,
|
|
17
16
|
isChatCompletionFunctionTool,
|
|
17
|
+
isParseableResponseFormat,
|
|
18
18
|
maybeParseChatCompletion,
|
|
19
|
+
parseResponseFormatContent,
|
|
19
20
|
shouldParseToolCall,
|
|
20
21
|
} from '../lib/parser';
|
|
21
|
-
import { ChatCompletionFunctionTool, ParsedChatCompletion } from '../resources/chat/completions';
|
|
22
|
-
import {
|
|
23
|
-
|
|
22
|
+
import type { ChatCompletionFunctionTool, ParsedChatCompletion } from '../resources/chat/completions';
|
|
23
|
+
import type {
|
|
24
|
+
ChatCompletionAudio,
|
|
25
|
+
ChatCompletion,
|
|
26
|
+
ChatCompletionChunk,
|
|
27
|
+
ChatCompletionCreateParams,
|
|
28
|
+
ChatCompletionCreateParamsBase,
|
|
29
|
+
ChatCompletionCreateParamsStreaming,
|
|
30
|
+
ChatCompletionMessageParam,
|
|
31
|
+
ChatCompletionMessageToolCall,
|
|
32
|
+
ChatCompletionRole,
|
|
24
33
|
ChatCompletionTokenLogprob,
|
|
25
|
-
type ChatCompletion,
|
|
26
|
-
type ChatCompletionChunk,
|
|
27
|
-
type ChatCompletionCreateParams,
|
|
28
|
-
type ChatCompletionCreateParamsBase,
|
|
29
|
-
type ChatCompletionCreateParamsStreaming,
|
|
30
|
-
type ChatCompletionMessageParam,
|
|
31
|
-
type ChatCompletionRole,
|
|
32
34
|
} from '../resources/chat/completions/completions';
|
|
33
35
|
import { Stream } from '../streaming';
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
import { AbstractChatCompletionRunner } from './AbstractChatCompletionRunner';
|
|
37
|
+
import type { AbstractChatCompletionRunnerEvents } from './AbstractChatCompletionRunner';
|
|
38
|
+
|
|
39
|
+
function parseStructuredStreamingJSON(content: string): unknown {
|
|
40
|
+
try {
|
|
41
|
+
return partialParse(content);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error instanceof MalformedJSON || error instanceof SyntaxError) {
|
|
44
|
+
return parseResponseFormatContent({ type: 'json_schema', $parseRaw: undefined }, content);
|
|
45
|
+
}
|
|
38
46
|
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** An incremental assistant-text event and its accumulated state. */
|
|
39
52
|
export interface ContentDeltaEvent {
|
|
53
|
+
/** The new text received in this chunk. */
|
|
40
54
|
delta: string;
|
|
55
|
+
/** All assistant text received for this choice, including `delta`. */
|
|
41
56
|
snapshot: string;
|
|
57
|
+
/** The partially parsed structured output when an auto-parseable response format is supplied. */
|
|
42
58
|
parsed: unknown | null;
|
|
43
59
|
}
|
|
44
60
|
|
|
61
|
+
/** The completed assistant-text content and its fully parsed structured value. */
|
|
45
62
|
export interface ContentDoneEvent<ParsedT = null> {
|
|
63
|
+
/** The complete assistant text for the finished choice. */
|
|
46
64
|
content: string;
|
|
65
|
+
/** The fully parsed structured output, or `null` when no parser was supplied. */
|
|
47
66
|
parsed: ParsedT | null;
|
|
48
67
|
}
|
|
49
68
|
|
|
69
|
+
/** An incremental refusal-text event and its accumulated state. */
|
|
50
70
|
export interface RefusalDeltaEvent {
|
|
71
|
+
/** The new refusal text received in this chunk. */
|
|
51
72
|
delta: string;
|
|
73
|
+
/** All refusal text received for this choice, including `delta`. */
|
|
52
74
|
snapshot: string;
|
|
53
75
|
}
|
|
54
76
|
|
|
77
|
+
/** The complete refusal text emitted when the refusal finishes. */
|
|
55
78
|
export interface RefusalDoneEvent {
|
|
79
|
+
/** The model's complete refusal message. */
|
|
56
80
|
refusal: string;
|
|
57
81
|
}
|
|
58
82
|
|
|
83
|
+
/** An incremental function-tool argument event and its accumulated JSON state. */
|
|
59
84
|
export interface FunctionToolCallArgumentsDeltaEvent {
|
|
85
|
+
/** The name of the function being called. */
|
|
60
86
|
name: string;
|
|
61
87
|
|
|
88
|
+
/** The position of this tool call within the assistant message. */
|
|
62
89
|
index: number;
|
|
63
90
|
|
|
91
|
+
/** The complete argument JSON received so far, including `arguments_delta`. */
|
|
64
92
|
arguments: string;
|
|
65
93
|
|
|
94
|
+
/** The partially parsed arguments when the matching tool supports parsing. */
|
|
66
95
|
parsed_arguments: unknown;
|
|
67
96
|
|
|
97
|
+
/** The new argument JSON fragment received in this chunk. */
|
|
68
98
|
arguments_delta: string;
|
|
69
99
|
}
|
|
70
100
|
|
|
101
|
+
/** The final raw and parsed arguments for a completed function-tool call. */
|
|
71
102
|
export interface FunctionToolCallArgumentsDoneEvent {
|
|
103
|
+
/** The name of the function being called. */
|
|
72
104
|
name: string;
|
|
73
105
|
|
|
106
|
+
/** The position of this tool call within the assistant message. */
|
|
74
107
|
index: number;
|
|
75
108
|
|
|
109
|
+
/** The complete JSON argument string produced for the tool call. */
|
|
76
110
|
arguments: string;
|
|
77
111
|
|
|
112
|
+
/** The fully parsed arguments when the matching tool supports parsing. */
|
|
78
113
|
parsed_arguments: unknown;
|
|
79
114
|
}
|
|
80
115
|
|
|
116
|
+
/** Newly received assistant-content token probabilities and their accumulated snapshot. */
|
|
81
117
|
export interface LogProbsContentDeltaEvent {
|
|
82
|
-
|
|
83
|
-
|
|
118
|
+
/** Token probabilities received in the current chunk. */
|
|
119
|
+
content: ChatCompletionTokenLogprob[];
|
|
120
|
+
/** All assistant-content token probabilities received for this choice. */
|
|
121
|
+
snapshot: ChatCompletionTokenLogprob[];
|
|
84
122
|
}
|
|
85
123
|
|
|
124
|
+
/** The complete assistant-content token probabilities for a finished choice. */
|
|
86
125
|
export interface LogProbsContentDoneEvent {
|
|
87
|
-
content
|
|
126
|
+
/** Every assistant-content token probability produced for this choice. */
|
|
127
|
+
content: ChatCompletionTokenLogprob[];
|
|
88
128
|
}
|
|
89
129
|
|
|
130
|
+
/** Newly received refusal-token probabilities and their accumulated snapshot. */
|
|
90
131
|
export interface LogProbsRefusalDeltaEvent {
|
|
91
|
-
|
|
92
|
-
|
|
132
|
+
/** Refusal-token probabilities received in the current chunk. */
|
|
133
|
+
refusal: ChatCompletionTokenLogprob[];
|
|
134
|
+
/** All refusal-token probabilities received for this choice. */
|
|
135
|
+
snapshot: ChatCompletionTokenLogprob[];
|
|
93
136
|
}
|
|
94
137
|
|
|
138
|
+
/** The complete refusal-token probabilities for a finished choice. */
|
|
95
139
|
export interface LogProbsRefusalDoneEvent {
|
|
96
|
-
refusal
|
|
140
|
+
/** Every refusal-token probability produced for this choice. */
|
|
141
|
+
refusal: ChatCompletionTokenLogprob[];
|
|
97
142
|
}
|
|
98
143
|
|
|
144
|
+
/** Event listeners supported by a streamed Chat Completions helper. */
|
|
99
145
|
export interface ChatCompletionStreamEvents<ParsedT = null> extends AbstractChatCompletionRunnerEvents {
|
|
146
|
+
/** Called with each new text fragment and the complete text accumulated so far. */
|
|
100
147
|
content: (contentDelta: string, contentSnapshot: string) => void;
|
|
148
|
+
/** Called with each raw API chunk and its accumulated chat-completion snapshot. */
|
|
101
149
|
chunk: (chunk: ChatCompletionChunk, snapshot: ChatCompletionSnapshot) => void;
|
|
102
150
|
|
|
151
|
+
/** Called when assistant text arrives, including any partially parsed output. */
|
|
103
152
|
'content.delta': (props: ContentDeltaEvent) => void;
|
|
153
|
+
/** Called once the assistant text is complete and can be fully parsed. */
|
|
104
154
|
'content.done': (props: ContentDoneEvent<ParsedT>) => void;
|
|
105
155
|
|
|
156
|
+
/** Called when another fragment of a model refusal arrives. */
|
|
106
157
|
'refusal.delta': (props: RefusalDeltaEvent) => void;
|
|
158
|
+
/** Called once the model's complete refusal is available. */
|
|
107
159
|
'refusal.done': (props: RefusalDoneEvent) => void;
|
|
108
160
|
|
|
161
|
+
/** Called when another JSON argument fragment arrives for a function tool. */
|
|
109
162
|
'tool_calls.function.arguments.delta': (props: FunctionToolCallArgumentsDeltaEvent) => void;
|
|
163
|
+
/** Called once a function tool's complete arguments are available. */
|
|
110
164
|
'tool_calls.function.arguments.done': (props: FunctionToolCallArgumentsDoneEvent) => void;
|
|
111
165
|
|
|
166
|
+
/** Called when assistant-content token probabilities arrive. */
|
|
112
167
|
'logprobs.content.delta': (props: LogProbsContentDeltaEvent) => void;
|
|
168
|
+
/** Called once all assistant-content token probabilities are available. */
|
|
113
169
|
'logprobs.content.done': (props: LogProbsContentDoneEvent) => void;
|
|
114
170
|
|
|
171
|
+
/** Called when refusal-token probabilities arrive. */
|
|
115
172
|
'logprobs.refusal.delta': (props: LogProbsRefusalDeltaEvent) => void;
|
|
173
|
+
/** Called once all refusal-token probabilities are available. */
|
|
116
174
|
'logprobs.refusal.done': (props: LogProbsRefusalDoneEvent) => void;
|
|
117
175
|
}
|
|
118
176
|
|
|
177
|
+
/** Chat completion request parameters accepted by the streaming convenience helper. */
|
|
119
178
|
export type ChatCompletionStreamParams = Omit<ChatCompletionCreateParamsBase, 'stream'> & {
|
|
179
|
+
/** Streaming is always enabled by the helper and may be specified explicitly. */
|
|
120
180
|
stream?: true;
|
|
121
181
|
};
|
|
122
182
|
|
|
183
|
+
/** A conversation message embedded in a serialized chat completion stream. */
|
|
123
184
|
type ChatCompletionReadableStreamMessage = {
|
|
185
|
+
/** Identifies this readable-stream item as a serialized conversation message. */
|
|
124
186
|
type: 'message';
|
|
187
|
+
/** The conversation message to restore while replaying the serialized stream. */
|
|
125
188
|
message: ChatCompletionMessageParam;
|
|
189
|
+
/** Tool-call identifiers to restore on the preceding assistant completion. */
|
|
126
190
|
tool_call_ids?: string[];
|
|
127
191
|
};
|
|
128
192
|
|
|
@@ -130,16 +194,21 @@ type ChatCompletionReadableStreamMessage = {
|
|
|
130
194
|
// overwrites `object`, so the encoded payload does not leak into completions.
|
|
131
195
|
const CHAT_COMPLETION_READABLE_STREAM_MESSAGE_PREFIX = 'chat.completion.chunk.message:';
|
|
132
196
|
|
|
197
|
+
/** A serialized conversation message disguised as a backwards-compatible empty completion chunk. */
|
|
133
198
|
type ChatCompletionReadableStreamMessageChunk = Pick<ChatCompletionChunk, 'id' | 'created' | 'model'> & {
|
|
199
|
+
/** Empty choices keep the encoded message compatible with older completion-stream readers. */
|
|
134
200
|
choices: [];
|
|
201
|
+
/** Reserved object prefix followed by the JSON-encoded conversation-message payload. */
|
|
135
202
|
object: `${typeof CHAT_COMPLETION_READABLE_STREAM_MESSAGE_PREFIX}${string}`;
|
|
136
203
|
};
|
|
137
204
|
|
|
205
|
+
/** A raw completion chunk or serialized message preserved in a transportable stream. */
|
|
138
206
|
export type ChatCompletionReadableStreamItem =
|
|
139
207
|
| ChatCompletionChunk
|
|
140
208
|
| ChatCompletionReadableStreamMessage
|
|
141
209
|
| ChatCompletionReadableStreamMessageChunk;
|
|
142
210
|
|
|
211
|
+
/** Encodes a tool-result message as a backwards-compatible, empty completion chunk. */
|
|
143
212
|
export function makeChatCompletionReadableStreamMessageChunk(
|
|
144
213
|
chunk: ChatCompletionChunk,
|
|
145
214
|
message: ChatCompletionMessageParam,
|
|
@@ -183,15 +252,1002 @@ function getChatCompletionReadableStreamMessage(
|
|
|
183
252
|
) as ChatCompletionReadableStreamMessage;
|
|
184
253
|
}
|
|
185
254
|
|
|
255
|
+
/**
|
|
256
|
+
* A tool call snapshot while it is still being accumulated from stream chunks.
|
|
257
|
+
*
|
|
258
|
+
* Every property is optional because the deltas that make up a tool call arrive
|
|
259
|
+
* across chunks; once they have all been accumulated the entry satisfies
|
|
260
|
+
* {@link ChatCompletionSnapshot.Choice.Message.ToolCall}.
|
|
261
|
+
*/
|
|
262
|
+
type PartialToolCallSnapshot = {
|
|
263
|
+
id?: string;
|
|
264
|
+
type?: ChatCompletionSnapshot.Choice.Message.ToolCall['type'];
|
|
265
|
+
function?: ChatCompletionSnapshot.Choice.Message.ToolCall.Function;
|
|
266
|
+
custom?: ChatCompletionSnapshot.Choice.Message.ToolCall.CustomToolCall.Custom;
|
|
267
|
+
};
|
|
268
|
+
|
|
186
269
|
interface ChoiceEventState {
|
|
187
270
|
content_done: boolean;
|
|
271
|
+
content_parse_state: PartialJSONParseState | undefined;
|
|
188
272
|
refusal_done: boolean;
|
|
189
273
|
logprobs_content_done: boolean;
|
|
190
274
|
logprobs_refusal_done: boolean;
|
|
191
275
|
current_tool_call_index: number | null;
|
|
192
276
|
done_tool_calls: Set<number>;
|
|
277
|
+
tool_call_parse_states: Map<number, PartialJSONParseState>;
|
|
278
|
+
tool_call_identities: Map<number, ToolCallIdentity>;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
interface CapturedToolCallDeltaFrame {
|
|
282
|
+
readonly index: number;
|
|
283
|
+
readonly arguments_delta: string;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
interface CapturedChoiceToolCallFrames {
|
|
287
|
+
readonly index: number;
|
|
288
|
+
readonly tool_calls: readonly CapturedToolCallDeltaFrame[];
|
|
193
289
|
}
|
|
194
290
|
|
|
291
|
+
interface ValidatedChoiceSnapshot {
|
|
292
|
+
message: ChatCompletionSnapshot.Choice.Message;
|
|
293
|
+
content: string | null | undefined;
|
|
294
|
+
refusal: string | null | undefined;
|
|
295
|
+
toolCallCollection: ChatCompletionSnapshot.Choice.Message.ToolCall[] | undefined;
|
|
296
|
+
toolCalls: ReadonlyMap<number, ValidatedToolCallSnapshot>;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
interface ValidatedToolCallSnapshot {
|
|
300
|
+
tool: ChatCompletionSnapshot.Choice.Message.ToolCall;
|
|
301
|
+
function: ChatCompletionSnapshot.Choice.Message.ToolCall.Function;
|
|
302
|
+
type: 'function';
|
|
303
|
+
name: string;
|
|
304
|
+
arguments: string;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
interface ToolCallIdentity {
|
|
308
|
+
type: 'function';
|
|
309
|
+
name: string;
|
|
310
|
+
parseable: boolean;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
interface PartialJSONParseState {
|
|
314
|
+
bytes: number;
|
|
315
|
+
depth: number;
|
|
316
|
+
fragments: number;
|
|
317
|
+
work: number;
|
|
318
|
+
escaped: boolean;
|
|
319
|
+
has_non_whitespace: boolean;
|
|
320
|
+
in_string: boolean;
|
|
321
|
+
last_parsed_bytes: number;
|
|
322
|
+
pending_high_surrogate: boolean;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
interface PartialJSONParseBudget {
|
|
326
|
+
bytes: number;
|
|
327
|
+
fragments: number;
|
|
328
|
+
work: number;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// The Chat Completions schema limits n to 128. Replayed streams do not retain
|
|
332
|
+
// request parameters, so apply that choice limit independently and use the same
|
|
333
|
+
// conservative ceiling to prevent sparse tool-call arrays from growing unbounded.
|
|
334
|
+
const MAX_STREAM_CHOICES = 128;
|
|
335
|
+
const MAX_STREAM_TOOL_CALLS = 128;
|
|
336
|
+
const MAX_PARTIAL_JSON_BYTES = 16 * 1024 * 1024;
|
|
337
|
+
const MAX_PARTIAL_JSON_FRAGMENTS = 65_536;
|
|
338
|
+
const MAX_PARTIAL_JSON_DEPTH = 128;
|
|
339
|
+
const MAX_PARTIAL_JSON_PARSE_WORK = 64 * 1024 * 1024;
|
|
340
|
+
const EAGER_PARTIAL_JSON_BYTES = 1024;
|
|
341
|
+
|
|
342
|
+
function createPartialJSONParseState(): PartialJSONParseState {
|
|
343
|
+
return {
|
|
344
|
+
bytes: 0,
|
|
345
|
+
depth: 0,
|
|
346
|
+
fragments: 0,
|
|
347
|
+
work: 0,
|
|
348
|
+
escaped: false,
|
|
349
|
+
has_non_whitespace: false,
|
|
350
|
+
in_string: false,
|
|
351
|
+
last_parsed_bytes: 0,
|
|
352
|
+
pending_high_surrogate: false,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function recordPartialJSONFragment(
|
|
357
|
+
state: PartialJSONParseState,
|
|
358
|
+
budget: PartialJSONParseBudget,
|
|
359
|
+
fragment: string,
|
|
360
|
+
validationWorkBudget?: PartialJSONParseBudget,
|
|
361
|
+
): boolean {
|
|
362
|
+
if (budget.fragments >= MAX_PARTIAL_JSON_FRAGMENTS) {
|
|
363
|
+
throw new OpenAIError('Chat completion stream exceeded its structured JSON fragment limit');
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
let bytes = 0;
|
|
367
|
+
let { depth, escaped, has_non_whitespace: hasNonWhitespace, in_string: inString } = state;
|
|
368
|
+
let completed = false;
|
|
369
|
+
let firstCharacter = true;
|
|
370
|
+
|
|
371
|
+
for (const character of fragment) {
|
|
372
|
+
const previousBytes = bytes;
|
|
373
|
+
const codePoint = character.codePointAt(0)!;
|
|
374
|
+
if (firstCharacter && state.pending_high_surrogate && codePoint >= 0xdc_00 && codePoint <= 0xdf_ff) {
|
|
375
|
+
bytes += 1;
|
|
376
|
+
} else if (codePoint <= 0x7f) {
|
|
377
|
+
bytes += 1;
|
|
378
|
+
} else if (codePoint <= 0x7_ff) {
|
|
379
|
+
bytes += 2;
|
|
380
|
+
} else if (codePoint <= 0xff_ff) {
|
|
381
|
+
bytes += 3;
|
|
382
|
+
} else {
|
|
383
|
+
bytes += 4;
|
|
384
|
+
}
|
|
385
|
+
firstCharacter = false;
|
|
386
|
+
if (budget.bytes + bytes > MAX_PARTIAL_JSON_BYTES) {
|
|
387
|
+
throw new OpenAIError('Chat completion stream exceeded its structured JSON byte limit');
|
|
388
|
+
}
|
|
389
|
+
if (validationWorkBudget && validationWorkBudget.work + bytes > MAX_PARTIAL_JSON_PARSE_WORK) {
|
|
390
|
+
validationWorkBudget.work += previousBytes;
|
|
391
|
+
throw new OpenAIError('Chat completion stream exceeded its structured JSON parse-work limit');
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (character !== ' ' && character !== '\n' && character !== '\r' && character !== '\t') {
|
|
395
|
+
hasNonWhitespace = true;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (inString) {
|
|
399
|
+
if (escaped) {
|
|
400
|
+
escaped = false;
|
|
401
|
+
} else if (character === '\\') {
|
|
402
|
+
escaped = true;
|
|
403
|
+
} else if (character === '"') {
|
|
404
|
+
inString = false;
|
|
405
|
+
completed ||= depth === 0;
|
|
406
|
+
}
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (character === '"') {
|
|
411
|
+
inString = true;
|
|
412
|
+
} else if (character === '{' || character === '[') {
|
|
413
|
+
depth += 1;
|
|
414
|
+
if (depth > MAX_PARTIAL_JSON_DEPTH) {
|
|
415
|
+
throw new OpenAIError('Chat completion stream exceeded its structured JSON nesting depth limit');
|
|
416
|
+
}
|
|
417
|
+
} else if ((character === '}' || character === ']') && depth > 0) {
|
|
418
|
+
depth -= 1;
|
|
419
|
+
completed ||= depth === 0;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
state.bytes += bytes;
|
|
424
|
+
state.fragments += 1;
|
|
425
|
+
state.depth = depth;
|
|
426
|
+
state.escaped = escaped;
|
|
427
|
+
state.has_non_whitespace = hasNonWhitespace;
|
|
428
|
+
state.in_string = inString;
|
|
429
|
+
if (fragment.length > 0) {
|
|
430
|
+
const finalCodeUnit = fragment.codePointAt(fragment.length - 1) ?? 0;
|
|
431
|
+
state.pending_high_surrogate = finalCodeUnit >= 0xd8_00 && finalCodeUnit <= 0xdb_ff;
|
|
432
|
+
}
|
|
433
|
+
budget.bytes += bytes;
|
|
434
|
+
budget.fragments += 1;
|
|
435
|
+
if (validationWorkBudget) {
|
|
436
|
+
validationWorkBudget.work += bytes;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (!hasNonWhitespace || bytes === 0) {
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const minimumGrowth = Math.max(EAGER_PARTIAL_JSON_BYTES, Math.floor(state.last_parsed_bytes / 2));
|
|
444
|
+
if (
|
|
445
|
+
state.bytes > EAGER_PARTIAL_JSON_BYTES &&
|
|
446
|
+
!completed &&
|
|
447
|
+
state.bytes - state.last_parsed_bytes < minimumGrowth
|
|
448
|
+
) {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
return true;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function reservePartialJSONParse(state: PartialJSONParseState, budget: PartialJSONParseBudget): boolean {
|
|
456
|
+
if (budget.work + state.bytes > MAX_PARTIAL_JSON_PARSE_WORK) {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
budget.work += state.bytes;
|
|
461
|
+
state.work += state.bytes;
|
|
462
|
+
state.last_parsed_bytes = state.bytes;
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function captureStructuredJSONSnapshot(
|
|
467
|
+
snapshot: object,
|
|
468
|
+
property: 'content' | 'arguments' | 'refusal',
|
|
469
|
+
): string | null | undefined {
|
|
470
|
+
const descriptor = Object.getOwnPropertyDescriptor(snapshot, property);
|
|
471
|
+
if (!descriptor) {
|
|
472
|
+
let prototype = Object.getPrototypeOf(snapshot) as object | null;
|
|
473
|
+
for (let depth = 0; prototype !== null; depth += 1) {
|
|
474
|
+
if (depth >= MAX_PARTIAL_JSON_DEPTH || Object.getOwnPropertyDescriptor(prototype, property)) {
|
|
475
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
476
|
+
}
|
|
477
|
+
prototype = Object.getPrototypeOf(prototype) as object | null;
|
|
478
|
+
}
|
|
479
|
+
return undefined;
|
|
480
|
+
}
|
|
481
|
+
if (
|
|
482
|
+
!('value' in descriptor) ||
|
|
483
|
+
(typeof descriptor.value !== 'string' && descriptor.value !== null && descriptor.value !== undefined)
|
|
484
|
+
) {
|
|
485
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
return descriptor.value as string | null | undefined;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function captureStructuredMessageSnapshot(
|
|
492
|
+
choice: ChatCompletionSnapshot.Choice,
|
|
493
|
+
): ChatCompletionSnapshot.Choice.Message {
|
|
494
|
+
const descriptor = Object.getOwnPropertyDescriptor(choice, 'message');
|
|
495
|
+
if (
|
|
496
|
+
!descriptor ||
|
|
497
|
+
!('value' in descriptor) ||
|
|
498
|
+
typeof descriptor.value !== 'object' ||
|
|
499
|
+
descriptor.value === null
|
|
500
|
+
) {
|
|
501
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
return descriptor.value as ChatCompletionSnapshot.Choice.Message;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function captureSnapshotArray<Item>(
|
|
508
|
+
snapshot: object,
|
|
509
|
+
property: 'choices' | 'tool_calls',
|
|
510
|
+
maximum: number,
|
|
511
|
+
kind: 'choice' | 'tool-call',
|
|
512
|
+
): Item[] | undefined {
|
|
513
|
+
const descriptor = Object.getOwnPropertyDescriptor(snapshot, property);
|
|
514
|
+
if (!descriptor) {
|
|
515
|
+
let prototype = Object.getPrototypeOf(snapshot) as object | null;
|
|
516
|
+
for (let depth = 0; prototype !== null; depth += 1) {
|
|
517
|
+
if (depth >= MAX_PARTIAL_JSON_DEPTH || Object.getOwnPropertyDescriptor(prototype, property)) {
|
|
518
|
+
throw new OpenAIError(`Chat completion stream contains an unsafe snapshot ${kind} collection`);
|
|
519
|
+
}
|
|
520
|
+
prototype = Object.getPrototypeOf(prototype) as object | null;
|
|
521
|
+
}
|
|
522
|
+
return undefined;
|
|
523
|
+
}
|
|
524
|
+
if (!('value' in descriptor) || !Array.isArray(descriptor.value)) {
|
|
525
|
+
throw new OpenAIError(`Chat completion stream contains an unsafe snapshot ${kind} collection`);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const length = Object.getOwnPropertyDescriptor(descriptor.value, 'length');
|
|
529
|
+
if (!length || !('value' in length) || !Number.isSafeInteger(length.value) || length.value > maximum) {
|
|
530
|
+
throw new OpenAIError(`Chat completion stream exceeded its snapshot ${kind} limit`);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
return descriptor.value as Item[];
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function captureSnapshotArrayItem<Item>(array: Item[], index: number): Item | undefined {
|
|
537
|
+
const descriptor = Object.getOwnPropertyDescriptor(array, index);
|
|
538
|
+
if (!descriptor) {
|
|
539
|
+
return undefined;
|
|
540
|
+
}
|
|
541
|
+
if (!('value' in descriptor)) {
|
|
542
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return descriptor.value as Item;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function mapCapturedSnapshotArray<Item, Mapped>(
|
|
549
|
+
array: Item[],
|
|
550
|
+
maximum: number,
|
|
551
|
+
kind: 'choice' | 'tool-call',
|
|
552
|
+
map: (item: Item, index: number) => Mapped,
|
|
553
|
+
): Mapped[] {
|
|
554
|
+
const descriptor = Object.getOwnPropertyDescriptor(array, 'length');
|
|
555
|
+
const length: unknown = descriptor && 'value' in descriptor ? descriptor.value : undefined;
|
|
556
|
+
if (typeof length !== 'number' || !Number.isSafeInteger(length) || length < 0 || length > maximum) {
|
|
557
|
+
throw new OpenAIError(`Chat completion stream exceeded its snapshot ${kind} limit`);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const mapped: Mapped[] = [];
|
|
561
|
+
mapped.length = length;
|
|
562
|
+
for (let index = 0; index < length; index += 1) {
|
|
563
|
+
const item = Object.getOwnPropertyDescriptor(array, index);
|
|
564
|
+
if (!item) {
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
if (!('value' in item)) {
|
|
568
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
569
|
+
}
|
|
570
|
+
mapped[index] = map(item.value as Item, index);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
return mapped;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
function validateStructuredJSONSnapshot(
|
|
577
|
+
value: string,
|
|
578
|
+
budget?: PartialJSONParseBudget,
|
|
579
|
+
validationWorkBudget?: PartialJSONParseBudget,
|
|
580
|
+
): string {
|
|
581
|
+
const state = createPartialJSONParseState();
|
|
582
|
+
const parseBudget = budget ?? { bytes: 0, fragments: 0, work: 0 };
|
|
583
|
+
recordPartialJSONFragment(state, parseBudget, value, validationWorkBudget);
|
|
584
|
+
if (!reservePartialJSONParse(state, parseBudget)) {
|
|
585
|
+
throw new OpenAIError('Chat completion stream exceeded its structured JSON parse-work limit');
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return value;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
function ownFunctionToolIdentity(
|
|
592
|
+
toolCall: PartialToolCallSnapshot,
|
|
593
|
+
): Pick<ToolCallIdentity, 'type' | 'name'> | undefined {
|
|
594
|
+
const type = Object.getOwnPropertyDescriptor(toolCall, 'type');
|
|
595
|
+
const fn = Object.getOwnPropertyDescriptor(toolCall, 'function');
|
|
596
|
+
if (!type || !('value' in type) || type.value !== 'function' || !fn || !('value' in fn)) {
|
|
597
|
+
return undefined;
|
|
598
|
+
}
|
|
599
|
+
if (typeof fn.value !== 'object' || fn.value === null) {
|
|
600
|
+
return undefined;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
const name = Object.getOwnPropertyDescriptor(fn.value, 'name');
|
|
604
|
+
if (!name || !('value' in name) || typeof name.value !== 'string' || name.value.length === 0) {
|
|
605
|
+
return undefined;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
return { type: 'function', name: name.value };
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
function assertBoundToolCallIdentity(toolCall: PartialToolCallSnapshot, identity: ToolCallIdentity): void {
|
|
612
|
+
const current = ownFunctionToolIdentity(toolCall);
|
|
613
|
+
if (!current || current.name !== identity.name || current.type !== identity.type) {
|
|
614
|
+
throw new OpenAIError('Chat completion stream contains a changed tool call identity');
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function assignOwnProperties<T extends object>(target: T, source: object): T {
|
|
619
|
+
if (Object.prototype.propertyIsEnumerable.call(source, '__proto__') && !hasOwn(target, '__proto__')) {
|
|
620
|
+
Object.defineProperty(target, '__proto__', {
|
|
621
|
+
value: undefined,
|
|
622
|
+
writable: true,
|
|
623
|
+
enumerable: true,
|
|
624
|
+
configurable: true,
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
return Object.assign(target, source);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
function cloneParserConfigObject<Value extends object>(
|
|
632
|
+
value: Value,
|
|
633
|
+
stableFields: readonly PropertyKey[] = [],
|
|
634
|
+
): Value {
|
|
635
|
+
const descriptors: PropertyDescriptorMap = Object.getOwnPropertyDescriptors(value);
|
|
636
|
+
for (const field of stableFields) {
|
|
637
|
+
const descriptor = descriptors[field];
|
|
638
|
+
if (!descriptor && !(field in value)) {
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
descriptors[field] = {
|
|
643
|
+
value: descriptor && 'value' in descriptor ? descriptor.value : Reflect.get(value, field, value),
|
|
644
|
+
enumerable: descriptor?.enumerable ?? false,
|
|
645
|
+
configurable: descriptor?.configurable ?? true,
|
|
646
|
+
writable: descriptor && 'writable' in descriptor ? descriptor.writable : false,
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
return Object.create(Object.getPrototypeOf(value), descriptors) as Value;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
function snapshotChatCompletionParserParams(params: ChatCompletionCreateParams): ChatCompletionCreateParams {
|
|
654
|
+
const snapshot = cloneParserConfigObject(params);
|
|
655
|
+
|
|
656
|
+
if (params.tools) {
|
|
657
|
+
const stableTools: NonNullable<ChatCompletionCreateParams['tools']> = [];
|
|
658
|
+
const lengthDescriptor = Object.getOwnPropertyDescriptor(params.tools, 'length');
|
|
659
|
+
const length = lengthDescriptor && 'value' in lengthDescriptor ? lengthDescriptor.value : undefined;
|
|
660
|
+
const toolCount =
|
|
661
|
+
typeof length === 'number' && Number.isSafeInteger(length) && length >= 0
|
|
662
|
+
? Math.min(length, MAX_STREAM_TOOL_CALLS)
|
|
663
|
+
: 0;
|
|
664
|
+
|
|
665
|
+
for (let index = 0; index < toolCount; index += 1) {
|
|
666
|
+
const item = Object.getOwnPropertyDescriptor(params.tools, String(index));
|
|
667
|
+
if (!item || !('value' in item)) {
|
|
668
|
+
stableTools.length = index + 1;
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
const tool = item.value as NonNullable<ChatCompletionCreateParams['tools']>[number];
|
|
673
|
+
const stableTool = cloneParserConfigObject(tool, [
|
|
674
|
+
'type',
|
|
675
|
+
'$brand',
|
|
676
|
+
'$parseRaw',
|
|
677
|
+
'$callback',
|
|
678
|
+
'function',
|
|
679
|
+
]);
|
|
680
|
+
const descriptors = Object.getOwnPropertyDescriptors(stableTool);
|
|
681
|
+
|
|
682
|
+
if (isChatCompletionFunctionTool(stableTool)) {
|
|
683
|
+
const descriptor = descriptors.function;
|
|
684
|
+
descriptors.function = {
|
|
685
|
+
...(descriptor && 'value' in descriptor
|
|
686
|
+
? descriptor
|
|
687
|
+
: { configurable: true, enumerable: true, writable: true }),
|
|
688
|
+
value: cloneParserConfigObject(stableTool.function, ['name', 'strict']),
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
stableTools[index] = Object.create(Object.getPrototypeOf(tool), descriptors) as typeof tool;
|
|
693
|
+
}
|
|
694
|
+
snapshot.tools = stableTools;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
if (params.response_format) {
|
|
698
|
+
snapshot.response_format = cloneParserConfigObject(params.response_format, [
|
|
699
|
+
'type',
|
|
700
|
+
'$brand',
|
|
701
|
+
'$parseRaw',
|
|
702
|
+
]);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
return snapshot;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
type ChatCompletionInputTool = NonNullable<ChatCompletionCreateParams['tools']>[number];
|
|
709
|
+
type ChatCompletionResponseFormat = NonNullable<ChatCompletionCreateParams['response_format']>;
|
|
710
|
+
|
|
711
|
+
interface SerializedFunctionParserConfig {
|
|
712
|
+
source: ChatCompletionInputTool | undefined;
|
|
713
|
+
schemaMatches: boolean;
|
|
714
|
+
name?: string;
|
|
715
|
+
strict?: boolean;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
interface SerializedToolParserConfig {
|
|
719
|
+
source: ChatCompletionInputTool | undefined;
|
|
720
|
+
type?: string;
|
|
721
|
+
function?: SerializedFunctionParserConfig;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
interface SerializedResponseParserConfig {
|
|
725
|
+
source: ChatCompletionResponseFormat | undefined;
|
|
726
|
+
schemaMatches: boolean;
|
|
727
|
+
type?: string;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
interface SerializedParserSchemaBudget {
|
|
731
|
+
nodes: number;
|
|
732
|
+
bytes: number;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
const MAX_SERIALIZED_PARSER_SCHEMA_NODES = 4096;
|
|
736
|
+
const stringifyParserSchemaValue = JSON.stringify;
|
|
737
|
+
const MAX_SERIALIZED_PARSER_SCHEMA_BYTES = 1024 * 1024;
|
|
738
|
+
const MAX_SERIALIZED_PARSER_SCHEMA_DEPTH = 64;
|
|
739
|
+
const OMITTED_SERIALIZED_PARSER_VALUE = Symbol('omitted serialized parser value');
|
|
740
|
+
const UNSAFE_SERIALIZED_PARSER_VALUE = Symbol('unsafe serialized parser value');
|
|
741
|
+
|
|
742
|
+
type CanonicalSerializedParserValue =
|
|
743
|
+
| string
|
|
744
|
+
| typeof OMITTED_SERIALIZED_PARSER_VALUE
|
|
745
|
+
| typeof UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
746
|
+
|
|
747
|
+
function canonicalSerializedParserSchema(
|
|
748
|
+
value: unknown,
|
|
749
|
+
budget: SerializedParserSchemaBudget,
|
|
750
|
+
): string | undefined {
|
|
751
|
+
const ancestors = new WeakSet<object>();
|
|
752
|
+
|
|
753
|
+
const charge = (bytes: number): boolean => {
|
|
754
|
+
if (
|
|
755
|
+
!Number.isSafeInteger(bytes) ||
|
|
756
|
+
bytes < 0 ||
|
|
757
|
+
budget.bytes + bytes > MAX_SERIALIZED_PARSER_SCHEMA_BYTES
|
|
758
|
+
) {
|
|
759
|
+
return false;
|
|
760
|
+
}
|
|
761
|
+
budget.bytes += bytes;
|
|
762
|
+
return true;
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
const visit = (current: unknown, depth: number): CanonicalSerializedParserValue => {
|
|
766
|
+
if (depth > MAX_SERIALIZED_PARSER_SCHEMA_DEPTH || budget.nodes >= MAX_SERIALIZED_PARSER_SCHEMA_NODES) {
|
|
767
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
768
|
+
}
|
|
769
|
+
budget.nodes += 1;
|
|
770
|
+
|
|
771
|
+
if (current === undefined || typeof current === 'function' || typeof current === 'symbol') {
|
|
772
|
+
return OMITTED_SERIALIZED_PARSER_VALUE;
|
|
773
|
+
}
|
|
774
|
+
if (typeof current === 'bigint') {
|
|
775
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
776
|
+
}
|
|
777
|
+
if (current === null || typeof current === 'boolean' || typeof current === 'number') {
|
|
778
|
+
const serialized = stringifyParserSchemaValue(current);
|
|
779
|
+
return typeof serialized === 'string' && charge(serialized.length)
|
|
780
|
+
? serialized
|
|
781
|
+
: UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
782
|
+
}
|
|
783
|
+
if (typeof current === 'string') {
|
|
784
|
+
if (!charge(current.length * 6 + 2)) {
|
|
785
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
786
|
+
}
|
|
787
|
+
return stringifyParserSchemaValue(current);
|
|
788
|
+
}
|
|
789
|
+
if (typeof current !== 'object' || ancestors.has(current)) {
|
|
790
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
const array = Array.isArray(current);
|
|
794
|
+
const prototype = Object.getPrototypeOf(current) as object | null;
|
|
795
|
+
if (
|
|
796
|
+
(array && prototype !== Array.prototype) ||
|
|
797
|
+
(!array && prototype !== null && prototype !== Object.prototype)
|
|
798
|
+
) {
|
|
799
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
for (
|
|
803
|
+
let owner: object | null = current;
|
|
804
|
+
owner !== null;
|
|
805
|
+
owner = Object.getPrototypeOf(owner) as object | null
|
|
806
|
+
) {
|
|
807
|
+
const serializer = Object.getOwnPropertyDescriptor(owner, 'toJSON');
|
|
808
|
+
if (!serializer) {
|
|
809
|
+
continue;
|
|
810
|
+
}
|
|
811
|
+
if (!('value' in serializer) || typeof serializer.value === 'function') {
|
|
812
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
813
|
+
}
|
|
814
|
+
break;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
ancestors.add(current);
|
|
818
|
+
try {
|
|
819
|
+
if (!charge(2)) {
|
|
820
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
if (array) {
|
|
824
|
+
const lengthDescriptor = Object.getOwnPropertyDescriptor(current, 'length');
|
|
825
|
+
const length = lengthDescriptor && 'value' in lengthDescriptor ? lengthDescriptor.value : undefined;
|
|
826
|
+
if (
|
|
827
|
+
typeof length !== 'number' ||
|
|
828
|
+
!Number.isSafeInteger(length) ||
|
|
829
|
+
length < 0 ||
|
|
830
|
+
length > MAX_SERIALIZED_PARSER_SCHEMA_NODES - budget.nodes
|
|
831
|
+
) {
|
|
832
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
const items: string[] = [];
|
|
836
|
+
for (let index = 0; index < length; index += 1) {
|
|
837
|
+
const key = String(index);
|
|
838
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
839
|
+
if (!descriptor) {
|
|
840
|
+
if (
|
|
841
|
+
Object.getOwnPropertyDescriptor(Array.prototype, key) ||
|
|
842
|
+
Object.getOwnPropertyDescriptor(Object.prototype, key)
|
|
843
|
+
) {
|
|
844
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
845
|
+
}
|
|
846
|
+
budget.nodes += 1;
|
|
847
|
+
if (!charge(4)) {
|
|
848
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
849
|
+
}
|
|
850
|
+
items.push('null');
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
if (!('value' in descriptor)) {
|
|
854
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
const item = visit(descriptor.value, depth + 1);
|
|
858
|
+
if (item === UNSAFE_SERIALIZED_PARSER_VALUE) {
|
|
859
|
+
return item;
|
|
860
|
+
}
|
|
861
|
+
items.push(item === OMITTED_SERIALIZED_PARSER_VALUE ? 'null' : item);
|
|
862
|
+
}
|
|
863
|
+
return `[${items.join(',')}]`;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
const keys = Reflect.ownKeys(current);
|
|
867
|
+
if (keys.length > MAX_SERIALIZED_PARSER_SCHEMA_NODES - budget.nodes) {
|
|
868
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
const entries: [string, unknown][] = [];
|
|
872
|
+
for (const key of keys) {
|
|
873
|
+
if (typeof key !== 'string') {
|
|
874
|
+
continue;
|
|
875
|
+
}
|
|
876
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
877
|
+
if (!descriptor) {
|
|
878
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
879
|
+
}
|
|
880
|
+
if (!descriptor.enumerable) {
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
if (!('value' in descriptor)) {
|
|
884
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
885
|
+
}
|
|
886
|
+
entries.push([key, descriptor.value]);
|
|
887
|
+
}
|
|
888
|
+
entries.sort(([left], [right]) => {
|
|
889
|
+
if (left === right) {
|
|
890
|
+
return 0;
|
|
891
|
+
}
|
|
892
|
+
return left < right ? -1 : 1;
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
const fields: string[] = [];
|
|
896
|
+
for (const [key, entry] of entries) {
|
|
897
|
+
const normalized = visit(entry, depth + 1);
|
|
898
|
+
if (normalized === UNSAFE_SERIALIZED_PARSER_VALUE) {
|
|
899
|
+
return normalized;
|
|
900
|
+
}
|
|
901
|
+
if (normalized === OMITTED_SERIALIZED_PARSER_VALUE) {
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
if (!charge(key.length * 6 + 3)) {
|
|
905
|
+
return UNSAFE_SERIALIZED_PARSER_VALUE;
|
|
906
|
+
}
|
|
907
|
+
fields.push(`${stringifyParserSchemaValue(key)}:${normalized}`);
|
|
908
|
+
}
|
|
909
|
+
return `{${fields.join(',')}}`;
|
|
910
|
+
} finally {
|
|
911
|
+
ancestors.delete(current);
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
try {
|
|
916
|
+
const normalized = visit(value, 0);
|
|
917
|
+
return typeof normalized === 'string' ? normalized : undefined;
|
|
918
|
+
} catch {
|
|
919
|
+
return undefined;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
function rememberSerializedParserSchema(
|
|
924
|
+
signatures: WeakMap<object, string>,
|
|
925
|
+
source: object,
|
|
926
|
+
holder: object,
|
|
927
|
+
key: string,
|
|
928
|
+
): void {
|
|
929
|
+
const parser = Object.getOwnPropertyDescriptor(source, '$parseRaw');
|
|
930
|
+
const schema = Object.getOwnPropertyDescriptor(holder, key);
|
|
931
|
+
if (
|
|
932
|
+
!parser ||
|
|
933
|
+
!('value' in parser) ||
|
|
934
|
+
typeof parser.value !== 'function' ||
|
|
935
|
+
!schema ||
|
|
936
|
+
!('value' in schema)
|
|
937
|
+
) {
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
const normalized = canonicalSerializedParserSchema(schema.value, { nodes: 0, bytes: 0 });
|
|
942
|
+
if (normalized !== undefined) {
|
|
943
|
+
signatures.set(source, normalized);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
function hasMatchingSerializedParserSchema(
|
|
948
|
+
signatures: WeakMap<object, string>,
|
|
949
|
+
source: object | undefined,
|
|
950
|
+
holder: object,
|
|
951
|
+
key: string,
|
|
952
|
+
value: unknown,
|
|
953
|
+
): boolean {
|
|
954
|
+
const expected = source && signatures.get(source);
|
|
955
|
+
const descriptor = Object.getOwnPropertyDescriptor(holder, key);
|
|
956
|
+
return (
|
|
957
|
+
expected !== undefined &&
|
|
958
|
+
descriptor !== undefined &&
|
|
959
|
+
'value' in descriptor &&
|
|
960
|
+
canonicalSerializedParserSchema(value, { nodes: 0, bytes: 0 }) === expected
|
|
961
|
+
);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
function serializedParserDescriptor(
|
|
965
|
+
descriptor: PropertyDescriptor | undefined,
|
|
966
|
+
value: unknown,
|
|
967
|
+
): PropertyDescriptor {
|
|
968
|
+
return descriptor && 'value' in descriptor
|
|
969
|
+
? { ...descriptor, value }
|
|
970
|
+
: { configurable: true, enumerable: true, writable: true, value };
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
function shadowSerializedParserMetadata(
|
|
974
|
+
descriptors: PropertyDescriptorMap,
|
|
975
|
+
source: object,
|
|
976
|
+
fields: readonly string[],
|
|
977
|
+
): void {
|
|
978
|
+
for (const field of fields) {
|
|
979
|
+
const descriptor = descriptors[field];
|
|
980
|
+
if (!descriptor && !(field in source)) {
|
|
981
|
+
continue;
|
|
982
|
+
}
|
|
983
|
+
descriptors[field] =
|
|
984
|
+
descriptor && 'value' in descriptor
|
|
985
|
+
? { ...descriptor, value: undefined }
|
|
986
|
+
: {
|
|
987
|
+
configurable: descriptor?.configurable ?? true,
|
|
988
|
+
enumerable: descriptor?.enumerable ?? false,
|
|
989
|
+
writable: false,
|
|
990
|
+
value: undefined,
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
function snapshotSerializedParserTool(serialized: SerializedToolParserConfig): ChatCompletionInputTool {
|
|
996
|
+
const source =
|
|
997
|
+
serialized.source ??
|
|
998
|
+
({
|
|
999
|
+
type: serialized.type,
|
|
1000
|
+
...(serialized.type === 'function' ? { function: {} } : {}),
|
|
1001
|
+
} as ChatCompletionInputTool);
|
|
1002
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
1003
|
+
descriptors.type = serializedParserDescriptor(descriptors.type, serialized.type);
|
|
1004
|
+
|
|
1005
|
+
if (serialized.type !== 'function' || !serialized.function) {
|
|
1006
|
+
if (descriptors.function) {
|
|
1007
|
+
descriptors.function = serializedParserDescriptor(descriptors.function, undefined);
|
|
1008
|
+
}
|
|
1009
|
+
shadowSerializedParserMetadata(descriptors, source, ['$brand', '$parseRaw', '$callback']);
|
|
1010
|
+
return Object.create(Object.getPrototypeOf(source), descriptors) as ChatCompletionInputTool;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
const descriptor = descriptors.function;
|
|
1014
|
+
const original =
|
|
1015
|
+
descriptor && 'value' in descriptor && typeof descriptor.value === 'object' && descriptor.value !== null
|
|
1016
|
+
? (descriptor.value as object)
|
|
1017
|
+
: {};
|
|
1018
|
+
const functionDescriptors = Object.getOwnPropertyDescriptors(original);
|
|
1019
|
+
functionDescriptors['name'] = serializedParserDescriptor(
|
|
1020
|
+
functionDescriptors['name'],
|
|
1021
|
+
serialized.function.name,
|
|
1022
|
+
);
|
|
1023
|
+
functionDescriptors['strict'] = serializedParserDescriptor(
|
|
1024
|
+
functionDescriptors['strict'],
|
|
1025
|
+
serialized.function.strict,
|
|
1026
|
+
);
|
|
1027
|
+
descriptors.function = serializedParserDescriptor(
|
|
1028
|
+
descriptor,
|
|
1029
|
+
Object.create(Object.getPrototypeOf(original), functionDescriptors),
|
|
1030
|
+
);
|
|
1031
|
+
if (!serialized.function.schemaMatches) {
|
|
1032
|
+
shadowSerializedParserMetadata(descriptors, source, ['$brand', '$parseRaw', '$callback']);
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
return Object.create(Object.getPrototypeOf(source), descriptors) as ChatCompletionInputTool;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
function snapshotSerializedResponseFormat(
|
|
1039
|
+
serialized: SerializedResponseParserConfig,
|
|
1040
|
+
): ChatCompletionResponseFormat {
|
|
1041
|
+
const source = serialized.source ?? ({ type: serialized.type } as ChatCompletionResponseFormat);
|
|
1042
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
1043
|
+
descriptors.type = serializedParserDescriptor(descriptors.type, serialized.type);
|
|
1044
|
+
if (serialized.type !== 'json_schema' || !serialized.source || !serialized.schemaMatches) {
|
|
1045
|
+
shadowSerializedParserMetadata(descriptors, source, ['$brand', '$parseRaw']);
|
|
1046
|
+
}
|
|
1047
|
+
return Object.create(Object.getPrototypeOf(source), descriptors) as ChatCompletionResponseFormat;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
function ownSerializedParserObject(holder: object, key: string): object | undefined {
|
|
1051
|
+
const descriptor = Object.getOwnPropertyDescriptor(holder, key);
|
|
1052
|
+
if (!descriptor || !('value' in descriptor)) {
|
|
1053
|
+
return undefined;
|
|
1054
|
+
}
|
|
1055
|
+
const { value } = descriptor;
|
|
1056
|
+
return typeof value === 'object' && value !== null ? value : undefined;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
function observeSerializedChatCompletionParserParams(
|
|
1060
|
+
body: ChatCompletionCreateParams,
|
|
1061
|
+
initial: ChatCompletionCreateParams,
|
|
1062
|
+
update: (params: ChatCompletionCreateParams) => void,
|
|
1063
|
+
): () => void {
|
|
1064
|
+
const originalToolOwners = new WeakMap<object, ChatCompletionInputTool>();
|
|
1065
|
+
const originalSchemaSignatures = new WeakMap<object, string>();
|
|
1066
|
+
// At most 128 tools plus one response format each receive an independent
|
|
1067
|
+
// 4,096-node/1 MiB source and wire allowance (129 MiB maximum per pass).
|
|
1068
|
+
if (body.tools) {
|
|
1069
|
+
for (let index = 0; index < body.tools.length && index < MAX_STREAM_TOOL_CALLS; index += 1) {
|
|
1070
|
+
const owner = ownSerializedParserObject(body.tools, String(index));
|
|
1071
|
+
const source = initial.tools?.[index];
|
|
1072
|
+
if (owner && source) {
|
|
1073
|
+
originalToolOwners.set(owner, source);
|
|
1074
|
+
const originalFunction = ownSerializedParserObject(source, 'function');
|
|
1075
|
+
if (originalFunction) {
|
|
1076
|
+
rememberSerializedParserSchema(originalSchemaSignatures, source, originalFunction, 'parameters');
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
if (initial.response_format) {
|
|
1082
|
+
rememberSerializedParserSchema(
|
|
1083
|
+
originalSchemaSignatures,
|
|
1084
|
+
initial.response_format,
|
|
1085
|
+
initial.response_format,
|
|
1086
|
+
'json_schema',
|
|
1087
|
+
);
|
|
1088
|
+
}
|
|
1089
|
+
let root: object | undefined;
|
|
1090
|
+
let tools: object | undefined;
|
|
1091
|
+
let responseFormat: object | undefined;
|
|
1092
|
+
let responseFrame: SerializedResponseParserConfig | undefined;
|
|
1093
|
+
let frames: (SerializedToolParserConfig | undefined)[] = [];
|
|
1094
|
+
let toolFrames = new WeakMap<object, SerializedToolParserConfig>();
|
|
1095
|
+
let actualToolOwners = new Map<number, object | undefined>();
|
|
1096
|
+
let functionFrames = new WeakMap<object, SerializedFunctionParserConfig>();
|
|
1097
|
+
|
|
1098
|
+
return observeJSONRequestBody(body, {
|
|
1099
|
+
value(holder, key, value) {
|
|
1100
|
+
if (!root && key === '' && typeof value === 'object' && value !== null) {
|
|
1101
|
+
root = value;
|
|
1102
|
+
tools = undefined;
|
|
1103
|
+
responseFormat = undefined;
|
|
1104
|
+
responseFrame = undefined;
|
|
1105
|
+
frames = [];
|
|
1106
|
+
toolFrames = new WeakMap();
|
|
1107
|
+
actualToolOwners = new Map();
|
|
1108
|
+
functionFrames = new WeakMap();
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
if (holder === root && key === 'response_format') {
|
|
1113
|
+
if (typeof value === 'object' && value !== null) {
|
|
1114
|
+
responseFormat = value;
|
|
1115
|
+
const owner = ownSerializedParserObject(holder, key);
|
|
1116
|
+
responseFrame = {
|
|
1117
|
+
source: owner === body.response_format ? initial.response_format : undefined,
|
|
1118
|
+
schemaMatches: false,
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
return;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
if (holder === root && key === 'tools') {
|
|
1125
|
+
if (Array.isArray(value)) {
|
|
1126
|
+
tools = new Proxy(value, {
|
|
1127
|
+
get(target, property) {
|
|
1128
|
+
const actual = Reflect.get(target, property, target) as unknown;
|
|
1129
|
+
if (typeof property === 'string') {
|
|
1130
|
+
const index = Number(property);
|
|
1131
|
+
if (
|
|
1132
|
+
Number.isSafeInteger(index) &&
|
|
1133
|
+
index >= 0 &&
|
|
1134
|
+
index < MAX_STREAM_TOOL_CALLS &&
|
|
1135
|
+
String(index) === property
|
|
1136
|
+
) {
|
|
1137
|
+
actualToolOwners.set(
|
|
1138
|
+
index,
|
|
1139
|
+
typeof actual === 'object' && actual !== null ? actual : undefined,
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
return actual;
|
|
1144
|
+
},
|
|
1145
|
+
});
|
|
1146
|
+
return tools;
|
|
1147
|
+
}
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
if (holder === tools) {
|
|
1152
|
+
const index = Number(key);
|
|
1153
|
+
if (
|
|
1154
|
+
!Number.isSafeInteger(index) ||
|
|
1155
|
+
index < 0 ||
|
|
1156
|
+
index >= MAX_STREAM_TOOL_CALLS ||
|
|
1157
|
+
typeof value !== 'object' ||
|
|
1158
|
+
value === null
|
|
1159
|
+
) {
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
const owner = actualToolOwners.get(index);
|
|
1163
|
+
const source = owner ? originalToolOwners.get(owner) : undefined;
|
|
1164
|
+
const frame: SerializedToolParserConfig = { source };
|
|
1165
|
+
frames[index] = frame;
|
|
1166
|
+
toolFrames.set(value, frame);
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
const tool = toolFrames.get(holder);
|
|
1171
|
+
if (tool) {
|
|
1172
|
+
if (key === 'type' && typeof value === 'string') {
|
|
1173
|
+
tool.type = value;
|
|
1174
|
+
} else if (key === 'function' && typeof value === 'object' && value !== null) {
|
|
1175
|
+
const fn: SerializedFunctionParserConfig = { source: tool.source, schemaMatches: false };
|
|
1176
|
+
tool.function = fn;
|
|
1177
|
+
functionFrames.set(value, fn);
|
|
1178
|
+
}
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
if (holder === responseFormat && responseFrame) {
|
|
1183
|
+
if (key === 'type' && typeof value === 'string') {
|
|
1184
|
+
responseFrame.type = value;
|
|
1185
|
+
} else if (key === 'json_schema') {
|
|
1186
|
+
responseFrame.schemaMatches = hasMatchingSerializedParserSchema(
|
|
1187
|
+
originalSchemaSignatures,
|
|
1188
|
+
responseFrame.source,
|
|
1189
|
+
holder,
|
|
1190
|
+
key,
|
|
1191
|
+
value,
|
|
1192
|
+
);
|
|
1193
|
+
}
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
const fn = functionFrames.get(holder);
|
|
1198
|
+
if (fn) {
|
|
1199
|
+
if (key === 'name' && typeof value === 'string') {
|
|
1200
|
+
fn.name = value;
|
|
1201
|
+
} else if (key === 'strict' && typeof value === 'boolean') {
|
|
1202
|
+
fn.strict = value;
|
|
1203
|
+
} else if (key === 'parameters') {
|
|
1204
|
+
fn.schemaMatches = hasMatchingSerializedParserSchema(
|
|
1205
|
+
originalSchemaSignatures,
|
|
1206
|
+
fn.source,
|
|
1207
|
+
holder,
|
|
1208
|
+
key,
|
|
1209
|
+
value,
|
|
1210
|
+
);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
return undefined;
|
|
1214
|
+
},
|
|
1215
|
+
complete() {
|
|
1216
|
+
if (!root) {
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
const snapshot = cloneParserConfigObject(initial);
|
|
1220
|
+
if (tools) {
|
|
1221
|
+
const serializedTools: ChatCompletionInputTool[] = [];
|
|
1222
|
+
for (let index = 0; index < frames.length; index += 1) {
|
|
1223
|
+
const frame = frames[index];
|
|
1224
|
+
if (frame) {
|
|
1225
|
+
serializedTools[index] = snapshotSerializedParserTool(frame);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
snapshot.tools = serializedTools;
|
|
1229
|
+
} else {
|
|
1230
|
+
delete snapshot.tools;
|
|
1231
|
+
}
|
|
1232
|
+
if (responseFrame) {
|
|
1233
|
+
snapshot.response_format = snapshotSerializedResponseFormat(responseFrame);
|
|
1234
|
+
} else {
|
|
1235
|
+
delete snapshot.response_format;
|
|
1236
|
+
}
|
|
1237
|
+
update(snapshot);
|
|
1238
|
+
root = undefined;
|
|
1239
|
+
tools = undefined;
|
|
1240
|
+
responseFormat = undefined;
|
|
1241
|
+
responseFrame = undefined;
|
|
1242
|
+
frames = [];
|
|
1243
|
+
toolFrames = new WeakMap();
|
|
1244
|
+
actualToolOwners = new Map();
|
|
1245
|
+
functionFrames = new WeakMap();
|
|
1246
|
+
},
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
/** Streams chat completion chunks while accumulating snapshots, parsed output, and events. */
|
|
195
1251
|
export class ChatCompletionStream<ParsedT = null>
|
|
196
1252
|
extends AbstractChatCompletionRunner<ChatCompletionStreamEvents<ParsedT>, ParsedT>
|
|
197
1253
|
implements AsyncIterable<ChatCompletionChunk>
|
|
@@ -200,14 +1256,39 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
200
1256
|
#audioDoneChoiceIndexes: Set<number>;
|
|
201
1257
|
#choiceEventStates: ChoiceEventState[];
|
|
202
1258
|
#currentChatCompletionSnapshot: ChatCompletionSnapshot | undefined;
|
|
1259
|
+
#hasAutoParseableTool: boolean;
|
|
1260
|
+
#partialJSONParseBudget: PartialJSONParseBudget;
|
|
203
1261
|
|
|
1262
|
+
/** Creates an unstarted stream, retaining request parameters for structured-output parsing. */
|
|
204
1263
|
constructor(params: ChatCompletionCreateParams | null) {
|
|
205
1264
|
super();
|
|
206
1265
|
this.#params = params;
|
|
207
1266
|
this.#audioDoneChoiceIndexes = new Set();
|
|
208
1267
|
this.#choiceEventStates = [];
|
|
1268
|
+
this.#hasAutoParseableTool = false;
|
|
1269
|
+
const tools = params?.tools;
|
|
1270
|
+
const lengthDescriptor = tools && Object.getOwnPropertyDescriptor(tools, 'length');
|
|
1271
|
+
const length = lengthDescriptor && 'value' in lengthDescriptor ? lengthDescriptor.value : undefined;
|
|
1272
|
+
if (tools && typeof length === 'number' && Number.isSafeInteger(length) && length >= 0) {
|
|
1273
|
+
for (let index = 0; index < Math.min(length, MAX_STREAM_TOOL_CALLS); index += 1) {
|
|
1274
|
+
const descriptor = Object.getOwnPropertyDescriptor(tools, String(index));
|
|
1275
|
+
if (!descriptor || !('value' in descriptor)) {
|
|
1276
|
+
continue;
|
|
1277
|
+
}
|
|
1278
|
+
const tool = descriptor.value as ChatCompletionInputTool;
|
|
1279
|
+
if (
|
|
1280
|
+
isChatCompletionFunctionTool(tool) &&
|
|
1281
|
+
(isAutoParsableTool(tool) || tool.function.strict === true)
|
|
1282
|
+
) {
|
|
1283
|
+
this.#hasAutoParseableTool = true;
|
|
1284
|
+
break;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
this.#partialJSONParseBudget = { bytes: 0, fragments: 0, work: 0 };
|
|
209
1289
|
}
|
|
210
1290
|
|
|
1291
|
+
/** The latest accumulated completion, or `undefined` before a chunk arrives or after finalization. */
|
|
211
1292
|
get currentChatCompletionSnapshot(): ChatCompletionSnapshot | undefined {
|
|
212
1293
|
return this.#currentChatCompletionSnapshot;
|
|
213
1294
|
}
|
|
@@ -216,8 +1297,8 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
216
1297
|
* Intended for use on the frontend, consuming a stream produced with
|
|
217
1298
|
* `.toReadableStream()` on the backend.
|
|
218
1299
|
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
1300
|
+
* Original input messages are not included in the serialized stream. Tool-result
|
|
1301
|
+
* messages explicitly serialized by a streaming tool runner are replayed.
|
|
221
1302
|
*/
|
|
222
1303
|
static fromReadableStream(stream: ReadableStream): ChatCompletionStream<null> {
|
|
223
1304
|
const runner = new ChatCompletionStream(null);
|
|
@@ -225,6 +1306,7 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
225
1306
|
return runner;
|
|
226
1307
|
}
|
|
227
1308
|
|
|
1309
|
+
/** Starts a streaming chat completion request and returns its event-driven helper. */
|
|
228
1310
|
static createChatCompletion<ParsedT>(
|
|
229
1311
|
client: OpenAI,
|
|
230
1312
|
params: ChatCompletionStreamParams,
|
|
@@ -235,16 +1317,19 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
235
1317
|
runner._runChatCompletion(
|
|
236
1318
|
client,
|
|
237
1319
|
{ ...params, stream: true },
|
|
238
|
-
{ ...options,
|
|
1320
|
+
{ ...options, __metadata: { ...options?.__metadata, helperMethod: 'stream' } },
|
|
239
1321
|
),
|
|
240
1322
|
);
|
|
241
1323
|
return runner;
|
|
242
1324
|
}
|
|
243
1325
|
|
|
244
1326
|
#beginRequest() {
|
|
245
|
-
if (this.ended)
|
|
1327
|
+
if (this.ended) {
|
|
1328
|
+
return;
|
|
1329
|
+
}
|
|
246
1330
|
this.#audioDoneChoiceIndexes = new Set();
|
|
247
1331
|
this.#currentChatCompletionSnapshot = undefined;
|
|
1332
|
+
this.#partialJSONParseBudget = { bytes: 0, fragments: 0, work: 0 };
|
|
248
1333
|
}
|
|
249
1334
|
|
|
250
1335
|
#getChoiceEventState(choice: ChatCompletionSnapshot.Choice): ChoiceEventState {
|
|
@@ -255,58 +1340,70 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
255
1340
|
|
|
256
1341
|
state = {
|
|
257
1342
|
content_done: false,
|
|
1343
|
+
content_parse_state: undefined,
|
|
258
1344
|
refusal_done: false,
|
|
259
1345
|
logprobs_content_done: false,
|
|
260
1346
|
logprobs_refusal_done: false,
|
|
261
1347
|
done_tool_calls: new Set(),
|
|
262
1348
|
current_tool_call_index: null,
|
|
1349
|
+
tool_call_parse_states: new Map(),
|
|
1350
|
+
tool_call_identities: new Map(),
|
|
263
1351
|
};
|
|
264
1352
|
this.#choiceEventStates[choice.index] = state;
|
|
265
1353
|
return state;
|
|
266
1354
|
}
|
|
267
1355
|
|
|
268
1356
|
#addChunk(this: ChatCompletionStream<ParsedT>, chunk: ChatCompletionChunk) {
|
|
269
|
-
if (this.ended)
|
|
1357
|
+
if (this.ended) {
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
270
1360
|
|
|
271
|
-
const
|
|
1361
|
+
const capturedChoiceFrames = new WeakMap<object, CapturedChoiceToolCallFrames>();
|
|
1362
|
+
const completion = this.#accumulateChatCompletion(chunk, capturedChoiceFrames);
|
|
272
1363
|
this._emit('chunk', chunk, completion);
|
|
273
1364
|
|
|
274
1365
|
for (const choice of chunk.choices) {
|
|
275
|
-
const
|
|
1366
|
+
const capturedChoice = capturedChoiceFrames.get(choice);
|
|
1367
|
+
const choiceSnapshot = completion.choices[capturedChoice?.index ?? choice.index]!;
|
|
1368
|
+
const capturedToolCalls = capturedChoice?.tool_calls ?? [];
|
|
276
1369
|
const { delta } = choice;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
choiceSnapshot
|
|
281
|
-
choiceSnapshot.message
|
|
282
|
-
|
|
283
|
-
|
|
1370
|
+
const structuredResponse = isParseableResponseFormat(this.#params?.response_format);
|
|
1371
|
+
const boundedSnapshot = structuredResponse || this.#hasAutoParseableTool;
|
|
1372
|
+
const messageSnapshot = boundedSnapshot
|
|
1373
|
+
? captureStructuredMessageSnapshot(choiceSnapshot)
|
|
1374
|
+
: choiceSnapshot.message;
|
|
1375
|
+
const refusal = boundedSnapshot
|
|
1376
|
+
? captureStructuredJSONSnapshot(messageSnapshot, 'refusal')
|
|
1377
|
+
: messageSnapshot.refusal;
|
|
1378
|
+
const parseableContent = !refusal && structuredResponse;
|
|
1379
|
+
const messageContent = parseableContent
|
|
1380
|
+
? captureStructuredJSONSnapshot(messageSnapshot, 'content')
|
|
1381
|
+
: messageSnapshot.content;
|
|
1382
|
+
|
|
1383
|
+
if (delta?.content != null && messageSnapshot.role === 'assistant' && messageContent) {
|
|
1384
|
+
this._emit('content', delta.content, messageContent);
|
|
284
1385
|
this._emit('content.delta', {
|
|
285
1386
|
delta: delta.content,
|
|
286
|
-
snapshot:
|
|
287
|
-
parsed:
|
|
1387
|
+
snapshot: messageContent,
|
|
1388
|
+
parsed: messageSnapshot.parsed,
|
|
288
1389
|
});
|
|
289
1390
|
}
|
|
290
1391
|
|
|
291
|
-
if (
|
|
292
|
-
delta?.refusal != null &&
|
|
293
|
-
choiceSnapshot.message?.role === 'assistant' &&
|
|
294
|
-
choiceSnapshot.message?.refusal
|
|
295
|
-
) {
|
|
1392
|
+
if (delta?.refusal != null && messageSnapshot.role === 'assistant' && refusal) {
|
|
296
1393
|
this._emit('refusal.delta', {
|
|
297
1394
|
delta: delta.refusal,
|
|
298
|
-
snapshot:
|
|
1395
|
+
snapshot: refusal,
|
|
299
1396
|
});
|
|
300
1397
|
}
|
|
301
1398
|
|
|
302
|
-
if (choice.logprobs?.content != null &&
|
|
1399
|
+
if (choice.logprobs?.content != null && messageSnapshot.role === 'assistant') {
|
|
303
1400
|
this._emit('logprobs.content.delta', {
|
|
304
1401
|
content: choice.logprobs?.content,
|
|
305
1402
|
snapshot: choiceSnapshot.logprobs?.content ?? [],
|
|
306
1403
|
});
|
|
307
1404
|
}
|
|
308
1405
|
|
|
309
|
-
if (choice.logprobs?.refusal != null &&
|
|
1406
|
+
if (choice.logprobs?.refusal != null && messageSnapshot.role === 'assistant') {
|
|
310
1407
|
this._emit('logprobs.refusal.delta', {
|
|
311
1408
|
refusal: choice.logprobs?.refusal,
|
|
312
1409
|
snapshot: choiceSnapshot.logprobs?.refusal ?? [],
|
|
@@ -323,7 +1420,7 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
323
1420
|
}
|
|
324
1421
|
}
|
|
325
1422
|
|
|
326
|
-
for (const toolCall of
|
|
1423
|
+
for (const toolCall of capturedToolCalls) {
|
|
327
1424
|
if (state.current_tool_call_index !== toolCall.index) {
|
|
328
1425
|
this.#emitContentDoneEvents(choiceSnapshot);
|
|
329
1426
|
|
|
@@ -336,22 +1433,33 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
336
1433
|
state.current_tool_call_index = toolCall.index;
|
|
337
1434
|
}
|
|
338
1435
|
|
|
339
|
-
for (const toolCallDelta of
|
|
340
|
-
const toolCallSnapshot =
|
|
1436
|
+
for (const toolCallDelta of capturedToolCalls) {
|
|
1437
|
+
const toolCallSnapshot = messageSnapshot.tool_calls?.[toolCallDelta.index];
|
|
341
1438
|
if (!toolCallSnapshot?.type) {
|
|
342
1439
|
continue;
|
|
343
1440
|
}
|
|
344
1441
|
|
|
345
|
-
if (toolCallSnapshot
|
|
1442
|
+
if (toolCallSnapshot.type === 'function') {
|
|
1443
|
+
const boundIdentity = state.tool_call_identities.get(toolCallDelta.index);
|
|
1444
|
+
let argumentsSnapshot: string;
|
|
1445
|
+
if (boundIdentity?.parseable) {
|
|
1446
|
+
const capturedArguments = captureStructuredJSONSnapshot(toolCallSnapshot.function, 'arguments');
|
|
1447
|
+
if (typeof capturedArguments !== 'string') {
|
|
1448
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
1449
|
+
}
|
|
1450
|
+
argumentsSnapshot = capturedArguments;
|
|
1451
|
+
} else {
|
|
1452
|
+
argumentsSnapshot = toolCallSnapshot.function.arguments;
|
|
1453
|
+
}
|
|
346
1454
|
this._emit('tool_calls.function.arguments.delta', {
|
|
347
|
-
name: toolCallSnapshot.function
|
|
1455
|
+
name: toolCallSnapshot.function.name,
|
|
348
1456
|
index: toolCallDelta.index,
|
|
349
|
-
arguments:
|
|
1457
|
+
arguments: argumentsSnapshot,
|
|
350
1458
|
parsed_arguments: toolCallSnapshot.function.parsed_arguments,
|
|
351
|
-
arguments_delta: toolCallDelta.
|
|
1459
|
+
arguments_delta: toolCallDelta.arguments_delta,
|
|
352
1460
|
});
|
|
353
|
-
} else {
|
|
354
|
-
assertNever(toolCallSnapshot
|
|
1461
|
+
} else if (toolCallSnapshot.type !== 'custom') {
|
|
1462
|
+
assertNever(toolCallSnapshot);
|
|
355
1463
|
}
|
|
356
1464
|
}
|
|
357
1465
|
}
|
|
@@ -364,10 +1472,18 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
364
1472
|
return;
|
|
365
1473
|
}
|
|
366
1474
|
|
|
367
|
-
const
|
|
1475
|
+
const messageSnapshot = this.#hasAutoParseableTool
|
|
1476
|
+
? captureStructuredMessageSnapshot(choiceSnapshot)
|
|
1477
|
+
: choiceSnapshot.message;
|
|
1478
|
+
const toolCallSnapshot = messageSnapshot.tool_calls?.[toolCallIndex];
|
|
368
1479
|
if (!toolCallSnapshot) {
|
|
369
1480
|
throw new Error('no tool call snapshot');
|
|
370
1481
|
}
|
|
1482
|
+
const boundIdentity = state.tool_call_identities.get(toolCallIndex);
|
|
1483
|
+
if (boundIdentity) {
|
|
1484
|
+
assertBoundToolCallIdentity(toolCallSnapshot, boundIdentity);
|
|
1485
|
+
}
|
|
1486
|
+
|
|
371
1487
|
if (!toolCallSnapshot.type) {
|
|
372
1488
|
throw new Error('tool call snapshot missing `type`');
|
|
373
1489
|
}
|
|
@@ -377,38 +1493,82 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
377
1493
|
(tool) => isChatCompletionFunctionTool(tool) && tool.function.name === toolCallSnapshot.function.name,
|
|
378
1494
|
) as ChatCompletionFunctionTool | undefined; // TS doesn't narrow based on isChatCompletionTool
|
|
379
1495
|
|
|
1496
|
+
let parsedArguments: unknown = null;
|
|
1497
|
+
const parseable = isAutoParsableTool(inputTool) || inputTool?.function.strict === true;
|
|
1498
|
+
let argumentsSnapshot: string;
|
|
1499
|
+
if (parseable) {
|
|
1500
|
+
if (this.#currentChatCompletionSnapshot) {
|
|
1501
|
+
this.#validateStructuredSnapshots(this.#currentChatCompletionSnapshot);
|
|
1502
|
+
}
|
|
1503
|
+
const capturedArguments = captureStructuredJSONSnapshot(toolCallSnapshot.function, 'arguments');
|
|
1504
|
+
if (typeof capturedArguments !== 'string') {
|
|
1505
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
1506
|
+
}
|
|
1507
|
+
argumentsSnapshot = capturedArguments;
|
|
1508
|
+
} else {
|
|
1509
|
+
argumentsSnapshot = toolCallSnapshot.function.arguments;
|
|
1510
|
+
}
|
|
1511
|
+
if (isAutoParsableTool(inputTool)) {
|
|
1512
|
+
parsedArguments = inputTool.$parseRaw(validateStructuredJSONSnapshot(argumentsSnapshot));
|
|
1513
|
+
} else if (inputTool?.function.strict) {
|
|
1514
|
+
parsedArguments = parseResponseFormatContent(
|
|
1515
|
+
{ type: 'json_schema', $parseRaw: undefined },
|
|
1516
|
+
validateStructuredJSONSnapshot(argumentsSnapshot),
|
|
1517
|
+
);
|
|
1518
|
+
}
|
|
1519
|
+
|
|
380
1520
|
this._emit('tool_calls.function.arguments.done', {
|
|
381
1521
|
name: toolCallSnapshot.function.name,
|
|
382
1522
|
index: toolCallIndex,
|
|
383
|
-
arguments:
|
|
384
|
-
parsed_arguments:
|
|
385
|
-
isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCallSnapshot.function.arguments)
|
|
386
|
-
: inputTool?.function.strict ? JSON.parse(toolCallSnapshot.function.arguments)
|
|
387
|
-
: null,
|
|
1523
|
+
arguments: argumentsSnapshot,
|
|
1524
|
+
parsed_arguments: parsedArguments,
|
|
388
1525
|
});
|
|
389
|
-
} else {
|
|
390
|
-
assertNever(toolCallSnapshot
|
|
1526
|
+
} else if (toolCallSnapshot.type !== 'custom') {
|
|
1527
|
+
assertNever(toolCallSnapshot);
|
|
391
1528
|
}
|
|
392
1529
|
}
|
|
393
1530
|
|
|
394
1531
|
#emitContentDoneEvents(choiceSnapshot: ChatCompletionSnapshot.Choice) {
|
|
395
1532
|
const state = this.#getChoiceEventState(choiceSnapshot);
|
|
396
|
-
|
|
397
|
-
|
|
1533
|
+
const structuredResponse = isParseableResponseFormat(this.#params?.response_format);
|
|
1534
|
+
const boundedSnapshot = structuredResponse || this.#hasAutoParseableTool;
|
|
1535
|
+
const messageSnapshot = boundedSnapshot
|
|
1536
|
+
? captureStructuredMessageSnapshot(choiceSnapshot)
|
|
1537
|
+
: choiceSnapshot.message;
|
|
1538
|
+
const refusal = boundedSnapshot
|
|
1539
|
+
? captureStructuredJSONSnapshot(messageSnapshot, 'refusal')
|
|
1540
|
+
: messageSnapshot.refusal;
|
|
1541
|
+
const parseableContent = !refusal && structuredResponse;
|
|
1542
|
+
const content = parseableContent
|
|
1543
|
+
? captureStructuredJSONSnapshot(messageSnapshot, 'content')
|
|
1544
|
+
: messageSnapshot.content;
|
|
1545
|
+
|
|
1546
|
+
if (
|
|
1547
|
+
content != null &&
|
|
1548
|
+
(content !== '' ||
|
|
1549
|
+
(!refusal && !messageSnapshot.tool_calls?.length && !messageSnapshot.function_call)) &&
|
|
1550
|
+
!state.content_done
|
|
1551
|
+
) {
|
|
1552
|
+
if (parseableContent && this.#currentChatCompletionSnapshot) {
|
|
1553
|
+
this.#validateStructuredSnapshots(this.#currentChatCompletionSnapshot);
|
|
1554
|
+
}
|
|
398
1555
|
state.content_done = true;
|
|
399
1556
|
|
|
400
|
-
const responseFormat = this.#getAutoParseableResponseFormat();
|
|
401
|
-
|
|
402
1557
|
this._emit('content.done', {
|
|
403
|
-
content
|
|
404
|
-
parsed:
|
|
1558
|
+
content,
|
|
1559
|
+
parsed: refusal
|
|
1560
|
+
? null
|
|
1561
|
+
: parseResponseFormatContent<ParsedT>(
|
|
1562
|
+
this.#params?.response_format,
|
|
1563
|
+
parseableContent ? validateStructuredJSONSnapshot(content) : content,
|
|
1564
|
+
),
|
|
405
1565
|
});
|
|
406
1566
|
}
|
|
407
1567
|
|
|
408
|
-
if (
|
|
1568
|
+
if (refusal && !state.refusal_done) {
|
|
409
1569
|
state.refusal_done = true;
|
|
410
1570
|
|
|
411
|
-
this._emit('refusal.done', { refusal
|
|
1571
|
+
this._emit('refusal.done', { refusal });
|
|
412
1572
|
}
|
|
413
1573
|
|
|
414
1574
|
if (choiceSnapshot.logprobs?.content && !state.logprobs_content_done) {
|
|
@@ -424,6 +1584,119 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
424
1584
|
}
|
|
425
1585
|
}
|
|
426
1586
|
|
|
1587
|
+
#validateStructuredSnapshots(
|
|
1588
|
+
snapshot: ChatCompletionSnapshot,
|
|
1589
|
+
): WeakMap<ChatCompletionSnapshot.Choice, ValidatedChoiceSnapshot> {
|
|
1590
|
+
const finalJSONBudget: PartialJSONParseBudget = { bytes: 0, fragments: 0, work: 0 };
|
|
1591
|
+
const parseableContent = isParseableResponseFormat(this.#params?.response_format);
|
|
1592
|
+
const validatedMessages = new WeakMap<ChatCompletionSnapshot.Choice, ValidatedChoiceSnapshot>();
|
|
1593
|
+
const choices = captureSnapshotArray<ChatCompletionSnapshot.Choice>(
|
|
1594
|
+
snapshot,
|
|
1595
|
+
'choices',
|
|
1596
|
+
MAX_STREAM_CHOICES,
|
|
1597
|
+
'choice',
|
|
1598
|
+
);
|
|
1599
|
+
if (!choices) {
|
|
1600
|
+
throw new OpenAIError('Chat completion stream contains an unsafe snapshot choice collection');
|
|
1601
|
+
}
|
|
1602
|
+
for (let choiceIndex = 0; choiceIndex < choices.length; choiceIndex += 1) {
|
|
1603
|
+
const choice = captureSnapshotArrayItem(choices, choiceIndex);
|
|
1604
|
+
if (!choice) {
|
|
1605
|
+
continue;
|
|
1606
|
+
}
|
|
1607
|
+
const message = captureStructuredMessageSnapshot(choice);
|
|
1608
|
+
const refusal = captureStructuredJSONSnapshot(message, 'refusal');
|
|
1609
|
+
const content = captureStructuredJSONSnapshot(message, 'content');
|
|
1610
|
+
const validatedTools = new Map<number, ValidatedToolCallSnapshot>();
|
|
1611
|
+
const toolCalls = captureSnapshotArray<ChatCompletionSnapshot.Choice.Message.ToolCall>(
|
|
1612
|
+
message,
|
|
1613
|
+
'tool_calls',
|
|
1614
|
+
MAX_STREAM_TOOL_CALLS,
|
|
1615
|
+
'tool-call',
|
|
1616
|
+
);
|
|
1617
|
+
validatedMessages.set(
|
|
1618
|
+
choice,
|
|
1619
|
+
Object.freeze({
|
|
1620
|
+
message,
|
|
1621
|
+
content,
|
|
1622
|
+
refusal,
|
|
1623
|
+
toolCallCollection: toolCalls,
|
|
1624
|
+
toolCalls: validatedTools,
|
|
1625
|
+
}),
|
|
1626
|
+
);
|
|
1627
|
+
const state = this.#choiceEventStates[choice.index];
|
|
1628
|
+
if (parseableContent && !refusal && typeof content === 'string') {
|
|
1629
|
+
validateStructuredJSONSnapshot(content, finalJSONBudget, this.#partialJSONParseBudget);
|
|
1630
|
+
}
|
|
1631
|
+
for (const [index, identity] of state?.tool_call_identities ?? []) {
|
|
1632
|
+
const toolCall = toolCalls && captureSnapshotArrayItem(toolCalls, index);
|
|
1633
|
+
if (!toolCall) {
|
|
1634
|
+
throw new OpenAIError('Chat completion stream contains a changed tool call identity');
|
|
1635
|
+
}
|
|
1636
|
+
assertBoundToolCallIdentity(toolCall, identity);
|
|
1637
|
+
}
|
|
1638
|
+
if (!this.#hasAutoParseableTool) {
|
|
1639
|
+
continue;
|
|
1640
|
+
}
|
|
1641
|
+
for (let toolCallIndex = 0; toolCallIndex < (toolCalls?.length ?? 0); toolCallIndex += 1) {
|
|
1642
|
+
const toolCall = captureSnapshotArrayItem(toolCalls!, toolCallIndex);
|
|
1643
|
+
if (!toolCall) {
|
|
1644
|
+
continue;
|
|
1645
|
+
}
|
|
1646
|
+
const identity = ownFunctionToolIdentity(toolCall);
|
|
1647
|
+
if (!identity) {
|
|
1648
|
+
const type = Object.getOwnPropertyDescriptor(toolCall, 'type');
|
|
1649
|
+
if (type && !('value' in type)) {
|
|
1650
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
1651
|
+
}
|
|
1652
|
+
if (type?.value !== 'function') {
|
|
1653
|
+
continue;
|
|
1654
|
+
}
|
|
1655
|
+
const fn = Object.getOwnPropertyDescriptor(toolCall, 'function');
|
|
1656
|
+
if (fn && !('value' in fn)) {
|
|
1657
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
1658
|
+
}
|
|
1659
|
+
if (fn && typeof fn.value === 'object' && fn.value !== null) {
|
|
1660
|
+
const name = Object.getOwnPropertyDescriptor(fn.value, 'name');
|
|
1661
|
+
if (name && !('value' in name)) {
|
|
1662
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
continue;
|
|
1666
|
+
}
|
|
1667
|
+
if (
|
|
1668
|
+
!shouldParseToolCall(this.#params, {
|
|
1669
|
+
type: identity.type,
|
|
1670
|
+
function: { name: identity.name },
|
|
1671
|
+
})
|
|
1672
|
+
) {
|
|
1673
|
+
continue;
|
|
1674
|
+
}
|
|
1675
|
+
const descriptor = Object.getOwnPropertyDescriptor(toolCall, 'function');
|
|
1676
|
+
if (!descriptor || !('value' in descriptor)) {
|
|
1677
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
1678
|
+
}
|
|
1679
|
+
const fn = descriptor.value as ChatCompletionSnapshot.Choice.Message.ToolCall.Function;
|
|
1680
|
+
const argumentsSnapshot = captureStructuredJSONSnapshot(fn, 'arguments');
|
|
1681
|
+
if (typeof argumentsSnapshot !== 'string') {
|
|
1682
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
1683
|
+
}
|
|
1684
|
+
validateStructuredJSONSnapshot(argumentsSnapshot, finalJSONBudget, this.#partialJSONParseBudget);
|
|
1685
|
+
validatedTools.set(
|
|
1686
|
+
toolCallIndex,
|
|
1687
|
+
Object.freeze({
|
|
1688
|
+
tool: toolCall,
|
|
1689
|
+
function: fn,
|
|
1690
|
+
type: identity.type,
|
|
1691
|
+
name: identity.name,
|
|
1692
|
+
arguments: argumentsSnapshot,
|
|
1693
|
+
}),
|
|
1694
|
+
);
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
return validatedMessages;
|
|
1698
|
+
}
|
|
1699
|
+
|
|
427
1700
|
#endRequest(): ParsedChatCompletion<ParsedT> {
|
|
428
1701
|
if (this.ended) {
|
|
429
1702
|
throw new OpenAIError(`stream has ended, this shouldn't happen`);
|
|
@@ -432,11 +1705,12 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
432
1705
|
if (!snapshot) {
|
|
433
1706
|
throw new OpenAIError(`request ended without sending any chunks`);
|
|
434
1707
|
}
|
|
1708
|
+
const validatedMessages = this.#validateStructuredSnapshots(snapshot);
|
|
435
1709
|
const audioDoneChoiceIndexes = this.#audioDoneChoiceIndexes;
|
|
436
1710
|
this.#audioDoneChoiceIndexes = new Set();
|
|
437
1711
|
this.#currentChatCompletionSnapshot = undefined;
|
|
438
1712
|
this.#choiceEventStates = [];
|
|
439
|
-
return finalizeChatCompletion(snapshot, this.#params, audioDoneChoiceIndexes);
|
|
1713
|
+
return finalizeChatCompletion(snapshot, this.#params, audioDoneChoiceIndexes, validatedMessages);
|
|
440
1714
|
}
|
|
441
1715
|
|
|
442
1716
|
protected override async _createChatCompletion(
|
|
@@ -444,14 +1718,36 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
444
1718
|
params: ChatCompletionCreateParams,
|
|
445
1719
|
options?: RequestOptions,
|
|
446
1720
|
): Promise<ParsedChatCompletion<ParsedT>> {
|
|
447
|
-
super._createChatCompletion;
|
|
448
1721
|
this._listenForAbort(options?.signal);
|
|
1722
|
+
const requestParams = { ...params, stream: true as const };
|
|
1723
|
+
this.#params = requestParams;
|
|
449
1724
|
this.#beginRequest();
|
|
450
1725
|
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
1726
|
+
const parserParams = snapshotChatCompletionParserParams(requestParams);
|
|
1727
|
+
this.#params = parserParams;
|
|
1728
|
+
this.#hasAutoParseableTool =
|
|
1729
|
+
parserParams.tools?.some(
|
|
1730
|
+
(tool) =>
|
|
1731
|
+
isChatCompletionFunctionTool(tool) && (isAutoParsableTool(tool) || tool.function.strict === true),
|
|
1732
|
+
) ?? false;
|
|
1733
|
+
const stopObserving =
|
|
1734
|
+
requestParams.tools || requestParams.response_format
|
|
1735
|
+
? observeSerializedChatCompletionParserParams(requestParams, parserParams, (serialized) => {
|
|
1736
|
+
this.#params = serialized;
|
|
1737
|
+
this.#hasAutoParseableTool =
|
|
1738
|
+
serialized.tools?.some(
|
|
1739
|
+
(tool) =>
|
|
1740
|
+
isChatCompletionFunctionTool(tool) &&
|
|
1741
|
+
(isAutoParsableTool(tool) || tool.function.strict === true),
|
|
1742
|
+
) ?? false;
|
|
1743
|
+
})
|
|
1744
|
+
: undefined;
|
|
1745
|
+
const stream = await client.chat.completions
|
|
1746
|
+
.create(requestParams, {
|
|
1747
|
+
...options,
|
|
1748
|
+
signal: this.controller.signal,
|
|
1749
|
+
})
|
|
1750
|
+
.finally(stopObserving);
|
|
455
1751
|
this._connected();
|
|
456
1752
|
for await (const chunk of stream) {
|
|
457
1753
|
this.#addChunk(chunk);
|
|
@@ -501,7 +1797,9 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
501
1797
|
}
|
|
502
1798
|
|
|
503
1799
|
this.#addChunk(chunk);
|
|
504
|
-
if (chunk.id)
|
|
1800
|
+
if (chunk.id) {
|
|
1801
|
+
chatId = chunk.id;
|
|
1802
|
+
}
|
|
505
1803
|
}
|
|
506
1804
|
if (stream.controller.signal?.aborted) {
|
|
507
1805
|
throw new APIUserAbortError();
|
|
@@ -516,40 +1814,54 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
516
1814
|
throw new OpenAIError(`request ended without sending any chunks`);
|
|
517
1815
|
}
|
|
518
1816
|
|
|
519
|
-
#
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
return null;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
#accumulateChatCompletion(chunk: ChatCompletionChunk): ChatCompletionSnapshot {
|
|
1817
|
+
#accumulateChatCompletion(
|
|
1818
|
+
chunk: ChatCompletionChunk,
|
|
1819
|
+
capturedChoiceFrames: WeakMap<object, CapturedChoiceToolCallFrames>,
|
|
1820
|
+
): ChatCompletionSnapshot {
|
|
529
1821
|
let snapshot = this.#currentChatCompletionSnapshot;
|
|
530
|
-
const { choices, ...rest } = chunk;
|
|
1822
|
+
const { choices, obfuscation: _obfuscation, ...rest } = chunk;
|
|
531
1823
|
if (!snapshot) {
|
|
532
|
-
|
|
1824
|
+
const newSnapshot: ChatCompletionSnapshot = {
|
|
533
1825
|
...rest,
|
|
534
1826
|
choices: [],
|
|
535
1827
|
};
|
|
1828
|
+
this.#currentChatCompletionSnapshot = newSnapshot;
|
|
1829
|
+
snapshot = newSnapshot;
|
|
536
1830
|
} else if (chunk.id) {
|
|
537
|
-
|
|
1831
|
+
assignOwnProperties(snapshot, rest);
|
|
538
1832
|
}
|
|
539
1833
|
|
|
540
|
-
|
|
1834
|
+
const requestedChoiceCount = this.#params?.n;
|
|
1835
|
+
const maxChoices =
|
|
1836
|
+
typeof requestedChoiceCount === 'number' &&
|
|
1837
|
+
Number.isSafeInteger(requestedChoiceCount) &&
|
|
1838
|
+
requestedChoiceCount > 0
|
|
1839
|
+
? Math.min(requestedChoiceCount, MAX_STREAM_CHOICES)
|
|
1840
|
+
: MAX_STREAM_CHOICES;
|
|
1841
|
+
|
|
1842
|
+
for (const chunkChoice of chunk.choices) {
|
|
1843
|
+
const { delta, finish_reason, index, logprobs = null, ...other } = chunkChoice;
|
|
1844
|
+
const capturedToolCalls: CapturedToolCallDeltaFrame[] = [];
|
|
1845
|
+
capturedChoiceFrames.set(chunkChoice, Object.freeze({ index, tool_calls: capturedToolCalls }));
|
|
1846
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= maxChoices) {
|
|
1847
|
+
throw new OpenAIError(`Chat completion stream contains an invalid choice index: ${index}`);
|
|
1848
|
+
}
|
|
1849
|
+
|
|
541
1850
|
let choice = snapshot.choices[index];
|
|
542
1851
|
if (!choice) {
|
|
543
|
-
|
|
1852
|
+
const newChoice = { finish_reason, index, message: {}, logprobs: null, ...other };
|
|
1853
|
+
snapshot.choices[index] = newChoice;
|
|
1854
|
+
choice = newChoice;
|
|
1855
|
+
}
|
|
1856
|
+
if (isParseableResponseFormat(this.#params?.response_format) || this.#hasAutoParseableTool) {
|
|
1857
|
+
captureStructuredJSONSnapshot(captureStructuredMessageSnapshot(choice), 'refusal');
|
|
544
1858
|
}
|
|
545
1859
|
|
|
546
1860
|
if (logprobs) {
|
|
547
|
-
if (
|
|
548
|
-
choice.logprobs = Object.assign({}, logprobs);
|
|
549
|
-
} else {
|
|
1861
|
+
if (choice.logprobs) {
|
|
550
1862
|
const { content, refusal, ...rest } = logprobs;
|
|
551
1863
|
assertIsEmpty(rest);
|
|
552
|
-
|
|
1864
|
+
assignOwnProperties(choice.logprobs, rest);
|
|
553
1865
|
|
|
554
1866
|
if (content) {
|
|
555
1867
|
choice.logprobs.content ??= [];
|
|
@@ -560,6 +1872,16 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
560
1872
|
choice.logprobs.refusal ??= [];
|
|
561
1873
|
choice.logprobs.refusal.push(...refusal);
|
|
562
1874
|
}
|
|
1875
|
+
} else {
|
|
1876
|
+
choice.logprobs = { ...logprobs };
|
|
1877
|
+
|
|
1878
|
+
if (logprobs.content) {
|
|
1879
|
+
choice.logprobs.content = [...logprobs.content];
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
if (logprobs.refusal) {
|
|
1883
|
+
choice.logprobs.refusal = [...logprobs.refusal];
|
|
1884
|
+
}
|
|
563
1885
|
}
|
|
564
1886
|
}
|
|
565
1887
|
|
|
@@ -577,16 +1899,22 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
577
1899
|
}
|
|
578
1900
|
}
|
|
579
1901
|
|
|
580
|
-
|
|
1902
|
+
assignOwnProperties(choice, other);
|
|
581
1903
|
|
|
582
|
-
if (!delta)
|
|
1904
|
+
if (!delta) {
|
|
1905
|
+
Object.freeze(capturedToolCalls);
|
|
1906
|
+
continue;
|
|
1907
|
+
} // Shouldn't happen; just in case.
|
|
583
1908
|
|
|
584
1909
|
this.#audioDoneChoiceIndexes.delete(index);
|
|
585
|
-
const { audio, content, refusal, function_call, role,
|
|
586
|
-
|
|
587
|
-
|
|
1910
|
+
const { audio, content, refusal, function_call, role, ...capturedDeltaFields } =
|
|
1911
|
+
delta as typeof delta & {
|
|
1912
|
+
audio?: Partial<ChatCompletionAudio> | null;
|
|
1913
|
+
};
|
|
1914
|
+
const { tool_calls: capturedToolCallDelta, ...rest } = capturedDeltaFields;
|
|
1915
|
+
const tool_calls = hasOwn(capturedDeltaFields, 'tool_calls') ? capturedToolCallDelta : delta.tool_calls;
|
|
588
1916
|
assertIsEmpty(rest);
|
|
589
|
-
|
|
1917
|
+
assignOwnProperties(choice.message, rest);
|
|
590
1918
|
if (
|
|
591
1919
|
audio?.expires_at != null &&
|
|
592
1920
|
audio.id == null &&
|
|
@@ -606,121 +1934,196 @@ export class ChatCompletionStream<ParsedT = null>
|
|
|
606
1934
|
choice.message.refusal = (choice.message.refusal || '') + refusal;
|
|
607
1935
|
}
|
|
608
1936
|
|
|
609
|
-
if (role)
|
|
1937
|
+
if (role) {
|
|
1938
|
+
choice.message.role = role;
|
|
1939
|
+
}
|
|
610
1940
|
if (audio) {
|
|
611
1941
|
const audioSnapshot = (choice.message.audio ??= {});
|
|
612
|
-
if (audio.id != null)
|
|
613
|
-
|
|
1942
|
+
if (audio.id != null) {
|
|
1943
|
+
audioSnapshot.id = audio.id;
|
|
1944
|
+
}
|
|
1945
|
+
if (audio.data != null) {
|
|
1946
|
+
audioSnapshot.data = (audioSnapshot.data ?? '') + audio.data;
|
|
1947
|
+
}
|
|
614
1948
|
if (audio.transcript != null) {
|
|
615
1949
|
audioSnapshot.transcript = (audioSnapshot.transcript ?? '') + audio.transcript;
|
|
616
1950
|
}
|
|
617
|
-
if (audio.expires_at != null)
|
|
1951
|
+
if (audio.expires_at != null) {
|
|
1952
|
+
audioSnapshot.expires_at = audio.expires_at;
|
|
1953
|
+
}
|
|
618
1954
|
}
|
|
619
1955
|
if (function_call) {
|
|
620
|
-
if (
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
1956
|
+
if (choice.message.function_call) {
|
|
1957
|
+
if (function_call.name) {
|
|
1958
|
+
choice.message.function_call.name = function_call.name;
|
|
1959
|
+
}
|
|
624
1960
|
if (function_call.arguments) {
|
|
625
1961
|
choice.message.function_call.arguments ??= '';
|
|
626
1962
|
choice.message.function_call.arguments += function_call.arguments;
|
|
627
1963
|
}
|
|
1964
|
+
} else {
|
|
1965
|
+
choice.message.function_call = function_call;
|
|
628
1966
|
}
|
|
629
1967
|
}
|
|
630
|
-
if (content) {
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
choice.message.
|
|
1968
|
+
if (content != null) {
|
|
1969
|
+
if (!choice.message.refusal && isParseableResponseFormat(this.#params?.response_format)) {
|
|
1970
|
+
const eventState = this.#getChoiceEventState(choice);
|
|
1971
|
+
const parseState = (eventState.content_parse_state ??= createPartialJSONParseState());
|
|
1972
|
+
const shouldParse = recordPartialJSONFragment(parseState, this.#partialJSONParseBudget, content);
|
|
1973
|
+
choice.message.content = (captureStructuredJSONSnapshot(choice.message, 'content') || '') + content;
|
|
1974
|
+
|
|
1975
|
+
// The partial parser does not accept whitespace-only input. Once output
|
|
1976
|
+
// grows, coalesce prefix reparses while preserving every raw snapshot.
|
|
1977
|
+
if (!parseState.has_non_whitespace) {
|
|
1978
|
+
choice.message.parsed = null;
|
|
1979
|
+
} else if (shouldParse && reservePartialJSONParse(parseState, this.#partialJSONParseBudget)) {
|
|
1980
|
+
this.#validateStructuredSnapshots(snapshot);
|
|
1981
|
+
choice.message.parsed = parseStructuredStreamingJSON(
|
|
1982
|
+
validateStructuredJSONSnapshot(choice.message.content),
|
|
1983
|
+
);
|
|
1984
|
+
} else if (content.length > 0) {
|
|
1985
|
+
choice.message.parsed = null;
|
|
1986
|
+
}
|
|
1987
|
+
} else {
|
|
1988
|
+
choice.message.content = (choice.message.content || '') + content;
|
|
636
1989
|
}
|
|
637
1990
|
}
|
|
638
1991
|
|
|
639
1992
|
if (tool_calls) {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
if (
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
1993
|
+
// Tool calls are built up across chunks, so while the stream is in progress the
|
|
1994
|
+
// entries are only partially filled in; they match `ChatCompletionSnapshot.Choice.Message.ToolCall`
|
|
1995
|
+
// once every delta for them has been accumulated.
|
|
1996
|
+
const toolCallSnapshots = (choice.message.tool_calls ??= []) as PartialToolCallSnapshot[];
|
|
1997
|
+
|
|
1998
|
+
for (const toolCallDelta of tool_calls) {
|
|
1999
|
+
const { index, id, type, function: fn, custom, ...rest } = toolCallDelta;
|
|
2000
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= MAX_STREAM_TOOL_CALLS) {
|
|
2001
|
+
throw new OpenAIError(`Chat completion stream contains an invalid tool call index: ${index}`);
|
|
2002
|
+
}
|
|
2003
|
+
let argumentsDelta = '';
|
|
2004
|
+
|
|
2005
|
+
const tool_call = (toolCallSnapshots[index] ??= {});
|
|
2006
|
+
const functionName = fn?.name;
|
|
2007
|
+
const eventState = this.#hasAutoParseableTool ? this.#getChoiceEventState(choice) : undefined;
|
|
2008
|
+
let boundIdentity = eventState?.tool_call_identities.get(index);
|
|
2009
|
+
if (boundIdentity) {
|
|
2010
|
+
assertBoundToolCallIdentity(tool_call, boundIdentity);
|
|
2011
|
+
if (
|
|
2012
|
+
(type !== undefined && type !== boundIdentity.type) ||
|
|
2013
|
+
(functionName !== undefined && functionName !== boundIdentity.name)
|
|
2014
|
+
) {
|
|
2015
|
+
throw new OpenAIError('Chat completion stream contains a changed tool call identity');
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
assignOwnProperties(tool_call, rest);
|
|
2020
|
+
if (id) {
|
|
2021
|
+
tool_call.id = id;
|
|
2022
|
+
}
|
|
2023
|
+
if (type) {
|
|
2024
|
+
tool_call.type = type;
|
|
2025
|
+
}
|
|
2026
|
+
if (custom) {
|
|
2027
|
+
const customSnapshot = (tool_call.custom ??= { name: custom.name ?? '', input: '' });
|
|
2028
|
+
if (custom.name) {
|
|
2029
|
+
customSnapshot.name = custom.name;
|
|
2030
|
+
}
|
|
2031
|
+
if (custom.input) {
|
|
2032
|
+
customSnapshot.input += custom.input;
|
|
655
2033
|
}
|
|
656
2034
|
}
|
|
2035
|
+
if (fn) {
|
|
2036
|
+
const functionSnapshot = (tool_call.function ??= { name: functionName ?? '', arguments: '' });
|
|
2037
|
+
if (functionName) {
|
|
2038
|
+
functionSnapshot.name = functionName;
|
|
2039
|
+
}
|
|
2040
|
+
if (eventState && !boundIdentity) {
|
|
2041
|
+
const identity = ownFunctionToolIdentity(tool_call);
|
|
2042
|
+
const configuredTool =
|
|
2043
|
+
identity &&
|
|
2044
|
+
this.#params?.tools?.find(
|
|
2045
|
+
(tool) => isChatCompletionFunctionTool(tool) && tool.function.name === identity.name,
|
|
2046
|
+
);
|
|
2047
|
+
if (identity) {
|
|
2048
|
+
boundIdentity = {
|
|
2049
|
+
...identity,
|
|
2050
|
+
parseable:
|
|
2051
|
+
configuredTool !== undefined &&
|
|
2052
|
+
shouldParseToolCall(this.#params, {
|
|
2053
|
+
type: identity.type,
|
|
2054
|
+
function: { name: identity.name },
|
|
2055
|
+
}),
|
|
2056
|
+
};
|
|
2057
|
+
eventState.tool_call_identities.set(index, boundIdentity);
|
|
2058
|
+
if (!boundIdentity.parseable) {
|
|
2059
|
+
const provisionalState = eventState.tool_call_parse_states.get(index);
|
|
2060
|
+
if (provisionalState) {
|
|
2061
|
+
this.#partialJSONParseBudget.bytes -= provisionalState.bytes;
|
|
2062
|
+
this.#partialJSONParseBudget.fragments -= provisionalState.fragments;
|
|
2063
|
+
this.#partialJSONParseBudget.work -= provisionalState.work;
|
|
2064
|
+
eventState.tool_call_parse_states.delete(index);
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
const argumentFragment = fn.arguments;
|
|
2070
|
+
if (argumentFragment != null) {
|
|
2071
|
+
argumentsDelta = argumentFragment;
|
|
2072
|
+
if (eventState && boundIdentity?.parseable !== false) {
|
|
2073
|
+
let parseState = eventState.tool_call_parse_states.get(index);
|
|
2074
|
+
if (!parseState) {
|
|
2075
|
+
parseState = createPartialJSONParseState();
|
|
2076
|
+
eventState.tool_call_parse_states.set(index, parseState);
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
const shouldParse = recordPartialJSONFragment(
|
|
2080
|
+
parseState,
|
|
2081
|
+
this.#partialJSONParseBudget,
|
|
2082
|
+
argumentFragment,
|
|
2083
|
+
);
|
|
2084
|
+
const previousArguments = captureStructuredJSONSnapshot(functionSnapshot, 'arguments');
|
|
2085
|
+
if (typeof previousArguments !== 'string') {
|
|
2086
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
2087
|
+
}
|
|
2088
|
+
functionSnapshot.arguments = previousArguments + argumentFragment;
|
|
2089
|
+
if (
|
|
2090
|
+
shouldParse &&
|
|
2091
|
+
boundIdentity?.parseable === true &&
|
|
2092
|
+
reservePartialJSONParse(parseState, this.#partialJSONParseBudget)
|
|
2093
|
+
) {
|
|
2094
|
+
this.#validateStructuredSnapshots(snapshot);
|
|
2095
|
+
functionSnapshot.parsed_arguments = parseStructuredStreamingJSON(
|
|
2096
|
+
validateStructuredJSONSnapshot(functionSnapshot.arguments),
|
|
2097
|
+
);
|
|
2098
|
+
} else if (argumentFragment.length > 0 && hasOwn(functionSnapshot, 'parsed_arguments')) {
|
|
2099
|
+
functionSnapshot.parsed_arguments = undefined;
|
|
2100
|
+
}
|
|
2101
|
+
} else {
|
|
2102
|
+
functionSnapshot.arguments += argumentFragment;
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
capturedToolCalls.push(Object.freeze({ index, arguments_delta: argumentsDelta }));
|
|
657
2107
|
}
|
|
658
2108
|
}
|
|
2109
|
+
Object.freeze(capturedToolCalls);
|
|
659
2110
|
}
|
|
660
2111
|
return snapshot;
|
|
661
2112
|
}
|
|
662
2113
|
|
|
2114
|
+
/** Iterates over raw API chunks; stopping iteration early aborts the underlying request. */
|
|
663
2115
|
[Symbol.asyncIterator](this: ChatCompletionStream<ParsedT>): AsyncIterator<ChatCompletionChunk> {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
let done = false;
|
|
670
|
-
|
|
671
|
-
this.on('chunk', (chunk) => {
|
|
672
|
-
const reader = readQueue.shift();
|
|
673
|
-
if (reader) {
|
|
674
|
-
reader.resolve(chunk);
|
|
675
|
-
} else {
|
|
676
|
-
pushQueue.push(chunk);
|
|
677
|
-
}
|
|
678
|
-
});
|
|
679
|
-
|
|
680
|
-
this.on('end', () => {
|
|
681
|
-
done = true;
|
|
682
|
-
for (const reader of readQueue) {
|
|
683
|
-
reader.resolve(undefined);
|
|
684
|
-
}
|
|
685
|
-
readQueue.length = 0;
|
|
686
|
-
});
|
|
687
|
-
|
|
688
|
-
this.on('abort', (err) => {
|
|
689
|
-
done = true;
|
|
690
|
-
for (const reader of readQueue) {
|
|
691
|
-
reader.reject(err);
|
|
692
|
-
}
|
|
693
|
-
readQueue.length = 0;
|
|
694
|
-
});
|
|
695
|
-
|
|
696
|
-
this.on('error', (err) => {
|
|
697
|
-
done = true;
|
|
698
|
-
for (const reader of readQueue) {
|
|
699
|
-
reader.reject(err);
|
|
700
|
-
}
|
|
701
|
-
readQueue.length = 0;
|
|
702
|
-
});
|
|
703
|
-
|
|
704
|
-
return {
|
|
705
|
-
next: async (): Promise<IteratorResult<ChatCompletionChunk>> => {
|
|
706
|
-
if (!pushQueue.length) {
|
|
707
|
-
if (done) {
|
|
708
|
-
return { value: undefined, done: true };
|
|
709
|
-
}
|
|
710
|
-
return new Promise<ChatCompletionChunk | undefined>((resolve, reject) =>
|
|
711
|
-
readQueue.push({ resolve, reject }),
|
|
712
|
-
).then((chunk) => (chunk ? { value: chunk, done: false } : { value: undefined, done: true }));
|
|
713
|
-
}
|
|
714
|
-
const chunk = pushQueue.shift()!;
|
|
715
|
-
return { value: chunk, done: false };
|
|
716
|
-
},
|
|
717
|
-
return: async () => {
|
|
718
|
-
this.abort();
|
|
719
|
-
return { value: undefined, done: true };
|
|
2116
|
+
return this._createIterator<ChatCompletionChunk>(
|
|
2117
|
+
(push) => {
|
|
2118
|
+
const onChunk = (chunk: ChatCompletionChunk) => push(chunk);
|
|
2119
|
+
this.on('chunk', onChunk);
|
|
2120
|
+
return () => this.off('chunk', onChunk);
|
|
720
2121
|
},
|
|
721
|
-
|
|
2122
|
+
{ onReturn: () => this.abort() },
|
|
2123
|
+
);
|
|
722
2124
|
}
|
|
723
2125
|
|
|
2126
|
+
/** Serializes raw completion chunks into a readable stream for transfer to another runtime. */
|
|
724
2127
|
toReadableStream(): ReadableStream {
|
|
725
2128
|
const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);
|
|
726
2129
|
return stream.toReadableStream();
|
|
@@ -731,13 +2134,41 @@ function finalizeChatCompletion<ParsedT>(
|
|
|
731
2134
|
snapshot: ChatCompletionSnapshot,
|
|
732
2135
|
params: ChatCompletionCreateParams | null,
|
|
733
2136
|
audioDoneChoiceIndexes: ReadonlySet<number>,
|
|
2137
|
+
validatedMessages: WeakMap<ChatCompletionSnapshot.Choice, ValidatedChoiceSnapshot>,
|
|
734
2138
|
): ParsedChatCompletion<ParsedT> {
|
|
735
2139
|
const { id, choices, created, model, system_fingerprint, ...rest } = snapshot;
|
|
736
2140
|
const completion: ChatCompletion = {
|
|
737
2141
|
...rest,
|
|
738
2142
|
id,
|
|
739
|
-
choices:
|
|
740
|
-
|
|
2143
|
+
choices: mapCapturedSnapshotArray(
|
|
2144
|
+
choices,
|
|
2145
|
+
MAX_STREAM_CHOICES,
|
|
2146
|
+
'choice',
|
|
2147
|
+
(choice): ChatCompletion.Choice => {
|
|
2148
|
+
const validated = validatedMessages.get(choice);
|
|
2149
|
+
if (!validated) {
|
|
2150
|
+
throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
|
|
2151
|
+
}
|
|
2152
|
+
const stableChoice = new Proxy(choice, {
|
|
2153
|
+
get(target, property, receiver) {
|
|
2154
|
+
return property === 'message' ? validated.message : Reflect.get(target, property, receiver);
|
|
2155
|
+
},
|
|
2156
|
+
});
|
|
2157
|
+
const { message: sourceMessage, finish_reason, index, logprobs, ...choiceRest } = stableChoice;
|
|
2158
|
+
const message = new Proxy(sourceMessage, {
|
|
2159
|
+
get(target, property, receiver) {
|
|
2160
|
+
if (property === 'content') {
|
|
2161
|
+
return validated.content;
|
|
2162
|
+
}
|
|
2163
|
+
if (property === 'refusal') {
|
|
2164
|
+
return validated.refusal;
|
|
2165
|
+
}
|
|
2166
|
+
if (property === 'tool_calls') {
|
|
2167
|
+
return validated.toolCallCollection;
|
|
2168
|
+
}
|
|
2169
|
+
return Reflect.get(target, property, receiver);
|
|
2170
|
+
},
|
|
2171
|
+
});
|
|
741
2172
|
const { content = null, function_call, tool_calls, audio, ...messageRest } = message;
|
|
742
2173
|
// Audio streams can end with an expires_at-only chunk after the
|
|
743
2174
|
// generated audio, without a separate finish_reason.
|
|
@@ -790,30 +2221,91 @@ function finalizeChatCompletion<ParsedT>(
|
|
|
790
2221
|
role,
|
|
791
2222
|
content,
|
|
792
2223
|
refusal: message.refusal ?? null,
|
|
793
|
-
tool_calls:
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
2224
|
+
tool_calls: mapCapturedSnapshotArray(
|
|
2225
|
+
tool_calls,
|
|
2226
|
+
MAX_STREAM_TOOL_CALLS,
|
|
2227
|
+
'tool-call',
|
|
2228
|
+
(tool_call, i): ChatCompletionMessageToolCall => {
|
|
2229
|
+
const captured = validated.toolCalls.get(i);
|
|
2230
|
+
if (!captured) {
|
|
2231
|
+
const identity = ownFunctionToolIdentity(tool_call);
|
|
2232
|
+
if (
|
|
2233
|
+
identity &&
|
|
2234
|
+
shouldParseToolCall(params, {
|
|
2235
|
+
type: identity.type,
|
|
2236
|
+
function: { name: identity.name },
|
|
2237
|
+
})
|
|
2238
|
+
) {
|
|
2239
|
+
throw new OpenAIError(
|
|
2240
|
+
'Chat completion stream contains an unsafe structured JSON snapshot',
|
|
2241
|
+
);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
if (captured && captured.tool !== tool_call) {
|
|
2245
|
+
throw new OpenAIError('Chat completion stream contains a changed tool call identity');
|
|
2246
|
+
}
|
|
2247
|
+
const stableFunction =
|
|
2248
|
+
captured &&
|
|
2249
|
+
new Proxy(captured.function, {
|
|
2250
|
+
get(target, property, receiver) {
|
|
2251
|
+
if (property === 'arguments') {
|
|
2252
|
+
return captured.arguments;
|
|
2253
|
+
}
|
|
2254
|
+
if (property === 'name') {
|
|
2255
|
+
return captured.name;
|
|
2256
|
+
}
|
|
2257
|
+
return Reflect.get(target, property, receiver);
|
|
2258
|
+
},
|
|
2259
|
+
});
|
|
2260
|
+
const stableTool =
|
|
2261
|
+
captured && stableFunction
|
|
2262
|
+
? new Proxy(tool_call, {
|
|
2263
|
+
get(target, property, receiver) {
|
|
2264
|
+
if (property === 'type') {
|
|
2265
|
+
return captured.type;
|
|
2266
|
+
}
|
|
2267
|
+
if (property === 'function') {
|
|
2268
|
+
return stableFunction;
|
|
2269
|
+
}
|
|
2270
|
+
return Reflect.get(target, property, receiver);
|
|
2271
|
+
},
|
|
2272
|
+
})
|
|
2273
|
+
: tool_call;
|
|
2274
|
+
if (stableTool.type == null) {
|
|
2275
|
+
throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].type`);
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
if (stableTool.type === 'custom') {
|
|
2279
|
+
const { custom, type, id, ...toolRest } = stableTool;
|
|
2280
|
+
const { input = '', name, ...customRest } = custom || {};
|
|
2281
|
+
if (name == null) {
|
|
2282
|
+
throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].custom.name`);
|
|
2283
|
+
}
|
|
2284
|
+
return {
|
|
2285
|
+
...toolRest,
|
|
2286
|
+
id: id || `call_${uuid4()}`,
|
|
2287
|
+
type,
|
|
2288
|
+
custom: { ...customRest, name, input },
|
|
2289
|
+
};
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2292
|
+
const { function: fn, type, id, ...toolRest } = stableTool;
|
|
2293
|
+
const { arguments: args, name, ...fnRest } = fn || {};
|
|
2294
|
+
if (name == null) {
|
|
2295
|
+
throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].function.name`);
|
|
2296
|
+
}
|
|
2297
|
+
if (args == null) {
|
|
2298
|
+
throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].function.arguments`);
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
return {
|
|
2302
|
+
...toolRest,
|
|
2303
|
+
id: id || `call_${uuid4()}`,
|
|
2304
|
+
type,
|
|
2305
|
+
function: { ...fnRest, name, arguments: args },
|
|
2306
|
+
};
|
|
2307
|
+
},
|
|
2308
|
+
),
|
|
817
2309
|
},
|
|
818
2310
|
};
|
|
819
2311
|
}
|
|
@@ -841,13 +2333,9 @@ function isCompleteAudio(
|
|
|
841
2333
|
return audio?.id != null && audio.data != null && audio.transcript != null && audio.expires_at != null;
|
|
842
2334
|
}
|
|
843
2335
|
|
|
844
|
-
function str(x: unknown) {
|
|
845
|
-
return JSON.stringify(x);
|
|
846
|
-
}
|
|
847
|
-
|
|
848
2336
|
/**
|
|
849
|
-
*
|
|
850
|
-
*
|
|
2337
|
+
* The chat completion accumulated from every streamed chunk received so far.
|
|
2338
|
+
* Fields within each choice can remain incomplete until generation finishes.
|
|
851
2339
|
*/
|
|
852
2340
|
export interface ChatCompletionSnapshot {
|
|
853
2341
|
/**
|
|
@@ -859,7 +2347,7 @@ export interface ChatCompletionSnapshot {
|
|
|
859
2347
|
* A list of chat completion choices. Can be more than one if `n` is greater
|
|
860
2348
|
* than 1.
|
|
861
2349
|
*/
|
|
862
|
-
choices:
|
|
2350
|
+
choices: ChatCompletionSnapshot.Choice[];
|
|
863
2351
|
|
|
864
2352
|
/**
|
|
865
2353
|
* The Unix timestamp (in seconds) of when the chat completion was created.
|
|
@@ -867,7 +2355,7 @@ export interface ChatCompletionSnapshot {
|
|
|
867
2355
|
created: number;
|
|
868
2356
|
|
|
869
2357
|
/**
|
|
870
|
-
* The model
|
|
2358
|
+
* The model generating the completion.
|
|
871
2359
|
*/
|
|
872
2360
|
model: string;
|
|
873
2361
|
|
|
@@ -884,10 +2372,12 @@ export interface ChatCompletionSnapshot {
|
|
|
884
2372
|
system_fingerprint?: string;
|
|
885
2373
|
}
|
|
886
2374
|
|
|
2375
|
+
/** Nested shapes used by an in-progress chat completion snapshot. */
|
|
887
2376
|
export namespace ChatCompletionSnapshot {
|
|
2377
|
+
/** One in-progress assistant choice and the metadata accumulated for it. */
|
|
888
2378
|
export interface Choice {
|
|
889
2379
|
/**
|
|
890
|
-
*
|
|
2380
|
+
* The assistant message accumulated from streamed model response deltas.
|
|
891
2381
|
*/
|
|
892
2382
|
message: Choice.Message;
|
|
893
2383
|
|
|
@@ -895,8 +2385,8 @@ export namespace ChatCompletionSnapshot {
|
|
|
895
2385
|
* The reason the model stopped generating tokens. This will be `stop` if the model
|
|
896
2386
|
* hit a natural stop point or a provided stop sequence, `length` if the maximum
|
|
897
2387
|
* number of tokens specified in the request was reached, `content_filter` if
|
|
898
|
-
* content was omitted due to a flag from our content filters,
|
|
899
|
-
*
|
|
2388
|
+
* content was omitted due to a flag from our content filters, `tool_calls` if
|
|
2389
|
+
* the model called a tool, or the deprecated `function_call` value.
|
|
900
2390
|
*/
|
|
901
2391
|
finish_reason: ChatCompletion.Choice['finish_reason'] | null;
|
|
902
2392
|
|
|
@@ -911,20 +2401,24 @@ export namespace ChatCompletionSnapshot {
|
|
|
911
2401
|
index: number;
|
|
912
2402
|
}
|
|
913
2403
|
|
|
2404
|
+
/** Nested message shapes belonging to an in-progress completion choice. */
|
|
914
2405
|
export namespace Choice {
|
|
915
2406
|
/**
|
|
916
|
-
*
|
|
2407
|
+
* The assistant message accumulated from streamed response deltas.
|
|
917
2408
|
*/
|
|
918
2409
|
export interface Message {
|
|
919
2410
|
/**
|
|
920
|
-
* The
|
|
2411
|
+
* The assistant text accumulated for this message so far.
|
|
921
2412
|
*/
|
|
922
2413
|
content?: string | null;
|
|
923
2414
|
|
|
2415
|
+
/** Audio fields received so far; individual fields can remain absent until generation finishes. */
|
|
924
2416
|
audio?: Partial<ChatCompletionAudio> | null;
|
|
925
2417
|
|
|
2418
|
+
/** The model's refusal text accumulated so far, when the request is refused. */
|
|
926
2419
|
refusal?: string | null;
|
|
927
2420
|
|
|
2421
|
+
/** A best-effort partial parse of structured assistant content. */
|
|
928
2422
|
parsed?: unknown | null;
|
|
929
2423
|
|
|
930
2424
|
/**
|
|
@@ -933,7 +2427,8 @@ export namespace ChatCompletionSnapshot {
|
|
|
933
2427
|
*/
|
|
934
2428
|
function_call?: Message.FunctionCall;
|
|
935
2429
|
|
|
936
|
-
|
|
2430
|
+
/** Function and custom tool calls accumulated so far; inputs may still be incomplete. */
|
|
2431
|
+
tool_calls?: Message.ToolCall[];
|
|
937
2432
|
|
|
938
2433
|
/**
|
|
939
2434
|
* The role of the author of this message.
|
|
@@ -941,22 +2436,30 @@ export namespace ChatCompletionSnapshot {
|
|
|
941
2436
|
role?: ChatCompletionRole;
|
|
942
2437
|
}
|
|
943
2438
|
|
|
2439
|
+
/** Nested tool-call shapes belonging to an in-progress assistant message. */
|
|
944
2440
|
export namespace Message {
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
* The ID of the tool call.
|
|
948
|
-
*/
|
|
949
|
-
id: string;
|
|
2441
|
+
/** A function or custom tool call accumulated incrementally from streamed chunks. */
|
|
2442
|
+
export type ToolCall = ToolCall.FunctionToolCall | ToolCall.CustomToolCall;
|
|
950
2443
|
|
|
951
|
-
|
|
2444
|
+
/** Function and custom details nested under an in-progress tool call. */
|
|
2445
|
+
export namespace ToolCall {
|
|
2446
|
+
/** A function-tool call whose name, identifier, and arguments are streamed incrementally. */
|
|
2447
|
+
export interface FunctionToolCall {
|
|
2448
|
+
/**
|
|
2449
|
+
* The ID of the tool call.
|
|
2450
|
+
*/
|
|
2451
|
+
id: string;
|
|
952
2452
|
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
*/
|
|
956
|
-
type: 'function';
|
|
957
|
-
}
|
|
2453
|
+
/** The function name and the complete or partial JSON arguments received so far. */
|
|
2454
|
+
function: ToolCall.Function;
|
|
958
2455
|
|
|
959
|
-
|
|
2456
|
+
/**
|
|
2457
|
+
* The type of the tool.
|
|
2458
|
+
*/
|
|
2459
|
+
type: 'function';
|
|
2460
|
+
}
|
|
2461
|
+
|
|
2462
|
+
/** The name and incrementally accumulated arguments of a function-tool call. */
|
|
960
2463
|
export interface Function {
|
|
961
2464
|
/**
|
|
962
2465
|
* The arguments to call the function with, as generated by the model in JSON
|
|
@@ -966,6 +2469,7 @@ export namespace ChatCompletionSnapshot {
|
|
|
966
2469
|
*/
|
|
967
2470
|
arguments: string;
|
|
968
2471
|
|
|
2472
|
+
/** A best-effort partial parse of `arguments` for strict or auto-parseable tools. */
|
|
969
2473
|
parsed_arguments?: unknown;
|
|
970
2474
|
|
|
971
2475
|
/**
|
|
@@ -973,6 +2477,34 @@ export namespace ChatCompletionSnapshot {
|
|
|
973
2477
|
*/
|
|
974
2478
|
name: string;
|
|
975
2479
|
}
|
|
2480
|
+
|
|
2481
|
+
/** A custom-tool call whose name, identifier, and input are streamed incrementally. */
|
|
2482
|
+
export interface CustomToolCall {
|
|
2483
|
+
/**
|
|
2484
|
+
* The ID of the tool call.
|
|
2485
|
+
*/
|
|
2486
|
+
id: string;
|
|
2487
|
+
|
|
2488
|
+
/** The custom-tool name and complete or partial input received so far. */
|
|
2489
|
+
custom: CustomToolCall.Custom;
|
|
2490
|
+
|
|
2491
|
+
/**
|
|
2492
|
+
* The type of the tool.
|
|
2493
|
+
*/
|
|
2494
|
+
type: 'custom';
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
/** Custom-tool details nested under an in-progress tool call. */
|
|
2498
|
+
export namespace CustomToolCall {
|
|
2499
|
+
/** The name and incrementally accumulated input of a custom-tool call. */
|
|
2500
|
+
export interface Custom {
|
|
2501
|
+
/** The name of the custom tool to call. */
|
|
2502
|
+
name: string;
|
|
2503
|
+
|
|
2504
|
+
/** The custom tool's complete or partial free-form input. */
|
|
2505
|
+
input: string;
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
976
2508
|
}
|
|
977
2509
|
|
|
978
2510
|
/**
|
|
@@ -997,15 +2529,17 @@ export namespace ChatCompletionSnapshot {
|
|
|
997
2529
|
}
|
|
998
2530
|
}
|
|
999
2531
|
|
|
1000
|
-
type AssertIsEmpty<T extends
|
|
2532
|
+
type AssertIsEmpty<T extends object> = keyof T extends never ? T : never;
|
|
1001
2533
|
|
|
1002
2534
|
/**
|
|
1003
2535
|
* Ensures the given argument is an empty object, useful for
|
|
1004
2536
|
* asserting that all known properties on an object have been
|
|
1005
2537
|
* destructured.
|
|
1006
2538
|
*/
|
|
1007
|
-
function assertIsEmpty<T extends
|
|
1008
|
-
|
|
2539
|
+
function assertIsEmpty<T extends object>(obj: AssertIsEmpty<T>): asserts obj is AssertIsEmpty<T> {
|
|
2540
|
+
void obj;
|
|
1009
2541
|
}
|
|
1010
2542
|
|
|
1011
|
-
function assertNever(_x: never) {
|
|
2543
|
+
function assertNever(_x: never) {
|
|
2544
|
+
return _x;
|
|
2545
|
+
}
|