structured-outputs 0.1.0-beta.2 → 0.1.0-beta.20
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +77 -6
- package/esm/ResponseFormat.js +33 -5
- package/esm/ResponseFormat.js.map +1 -1
- package/esm/Tool.js +17 -0
- package/esm/Tool.js.map +1 -0
- package/esm/_dnt.polyfills.js +16 -0
- package/esm/_dnt.polyfills.js.map +1 -0
- package/esm/_dnt.shims.js +58 -0
- package/esm/_dnt.shims.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/almost_equals.js +47 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/almost_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/array_includes.js +47 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/array_includes.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/assert.js +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/assert.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/assertion_error.js +31 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/assertion_error.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/equal.js +184 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/equal.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/equals.js +46 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/exists.js +28 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/exists.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/fail.js +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/fail.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/false.js +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/false.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/greater.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/greater.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/instance_of.js +53 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/instance_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/is_error.js +54 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/is_error.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/less.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/less.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/less_or_equal.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/less_or_equal.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/match.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/match.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/mod.js +46 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/mod.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_equals.js +33 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_instance_of.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_instance_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_match.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_match.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.js +33 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/object_match.js +160 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/object_match.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/rejects.js +54 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/rejects.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/strict_equals.js +58 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/strict_equals.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/string_includes.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/string_includes.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/throws.js +45 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/throws.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/unimplemented.js +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/unimplemented.js.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/unreachable.js +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.8/unreachable.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/_utils.js +19 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/_utils.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.js +51 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/associate_by.js +45 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/associate_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/associate_with.js +41 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/associate_with.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/chunk.js +51 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/chunk.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/deep_merge.js +96 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/deep_merge.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/distinct.js +28 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/distinct.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/distinct_by.js +39 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/distinct_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/drop_last_while.js +33 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/drop_last_while.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/drop_while.js +34 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/drop_while.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_entries.js +43 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_entries.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_keys.js +46 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_keys.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_values.js +46 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/filter_values.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/find_single.js +45 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/find_single.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.js +42 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/includes_value.js +39 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/includes_value.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/intersect.js +36 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/intersect.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/invert.js +29 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/invert.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/invert_by.js +46 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/invert_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/join_to_string.js +59 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/join_to_string.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_entries.js +47 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_entries.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_keys.js +42 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_keys.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.js +43 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_values.js +13 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/map_values.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_by.js +15 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_of.js +17 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_with.js +41 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/max_with.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_by.js +15 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_of.js +17 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_with.js +37 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/min_with.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/mod.js +75 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/mod.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/omit.js +29 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/omit.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/partition.js +16 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/partition.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/partition_entries.js +54 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/partition_entries.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/permutations.js +58 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/permutations.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/pick.js +33 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/pick.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/reduce_groups.js +40 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/reduce_groups.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/running_reduce.js +32 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/running_reduce.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sample.js +35 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sample.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sliding_windows.js +57 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sliding_windows.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sort_by.js +30 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sort_by.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sum_of.js +37 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/sum_of.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/take_last_while.js +34 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/take_last_while.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/take_while.js +39 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/take_while.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/union.js +34 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/union.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/unzip.js +46 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/unzip.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/without_all.js +28 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/without_all.js.map +1 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/zip.js +43 -0
- package/esm/deps/jsr.io/@std/collections/1.0.9/zip.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.js +111 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff.js +277 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.js +180 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/format.js +38 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/format.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/styles.js +208 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/styles.js.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/types.js +3 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/types.js.map +1 -0
- package/esm/mod.js +3 -10
- package/esm/mod.js.map +1 -1
- package/esm/types/Ref.js +11 -0
- package/esm/types/Ref.js.map +1 -0
- package/esm/types/RootTy.js +19 -0
- package/esm/types/RootTy.js.map +1 -0
- package/esm/types/Ty.js +17 -0
- package/esm/types/Ty.js.map +1 -0
- package/esm/types/array.js +9 -0
- package/esm/types/array.js.map +1 -0
- package/esm/types/constant.js +8 -0
- package/esm/types/constant.js.map +1 -0
- package/esm/types/constantUnion.js +25 -0
- package/esm/types/constantUnion.js.map +1 -0
- package/esm/types/leaves.js +18 -0
- package/esm/types/leaves.js.map +1 -0
- package/esm/types/mod.js +11 -0
- package/esm/types/mod.js.map +1 -0
- package/esm/{object.js → types/object.js} +4 -4
- package/esm/types/object.js.map +1 -0
- package/esm/types/std/Option.js +9 -0
- package/esm/types/std/Option.js.map +1 -0
- package/esm/types/std/Wrapper.js +5 -0
- package/esm/types/std/Wrapper.js.map +1 -0
- package/esm/types/std/mod.js +3 -0
- package/esm/types/std/mod.js.map +1 -0
- package/esm/types/taggedUnion.js +20 -0
- package/esm/types/taggedUnion.js.map +1 -0
- package/esm/util/phantoms.js +4 -0
- package/esm/util/phantoms.js.map +1 -0
- package/esm/util/recombineTaggedTemplateArgs.js +4 -0
- package/esm/util/recombineTaggedTemplateArgs.js.map +1 -0
- package/package.json +10 -7
- package/src/ResponseFormat.ts +76 -25
- package/src/Tool.ts +38 -0
- package/src/_dnt.polyfills.ts +27 -0
- package/src/_dnt.shims.ts +60 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/almost_equals.ts +55 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/array_includes.ts +57 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/assert.ts +23 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/assertion_error.ts +31 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/equal.ts +210 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/equals.ts +52 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/exists.ts +31 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/fail.ts +21 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/false.ts +26 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/greater.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.ts +36 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/instance_of.ts +64 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/is_error.ts +65 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/less.ts +29 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/less_or_equal.ts +36 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/match.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/mod.ts +47 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/not_equals.ts +36 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/not_instance_of.ts +33 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/not_match.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.ts +42 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/object_match.ts +202 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/rejects.ts +123 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/strict_equals.ts +67 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/string_includes.ts +30 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/throws.ts +111 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/unimplemented.ts +21 -0
- package/src/deps/jsr.io/@std/assert/1.0.8/unreachable.ts +21 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/_utils.ts +26 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.ts +62 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/associate_by.ts +50 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/associate_with.ts +46 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/chunk.ts +56 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/deep_merge.ts +578 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/distinct.ts +29 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/distinct_by.ts +42 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/drop_last_while.ts +36 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/drop_while.ts +39 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/filter_entries.ts +48 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/filter_keys.ts +51 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/filter_values.ts +51 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/find_single.ts +48 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.ts +47 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/includes_value.ts +45 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/intersect.ts +35 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/invert.ts +38 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/invert_by.ts +56 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/join_to_string.ts +109 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/map_entries.ts +53 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/map_keys.ts +47 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.ts +49 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/map_values.ts +96 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/max_by.ts +153 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/max_of.ts +90 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/max_with.ts +46 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/min_by.ts +151 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/min_of.ts +90 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/min_with.ts +42 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/mod.ts +76 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/omit.ts +34 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/partition.ts +85 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/partition_entries.ts +58 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/permutations.ts +66 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/pick.ts +34 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/reduce_groups.ts +45 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/running_reduce.ts +38 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/sample.ts +36 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/sliding_windows.ts +86 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/sort_by.ts +219 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/sum_of.ts +42 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/take_last_while.ts +37 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/take_while.ts +44 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/union.ts +36 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/unzip.ts +50 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/without_all.ts +28 -0
- package/src/deps/jsr.io/@std/collections/1.0.9/zip.ts +49 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/build_message.ts +134 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/diff.ts +317 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/diff_str.ts +204 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/format.ts +39 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/styles.ts +233 -0
- package/src/deps/jsr.io/@std/internal/1.0.5/types.ts +18 -0
- package/src/mod.ts +3 -18
- package/src/types/Ref.ts +16 -0
- package/src/types/RootTy.ts +40 -0
- package/src/types/Ty.ts +57 -0
- package/src/types/array.ts +9 -0
- package/src/types/constant.ts +8 -0
- package/src/types/constantUnion.ts +27 -0
- package/src/types/leaves.ts +21 -0
- package/src/types/mod.ts +10 -0
- package/src/types/object.ts +15 -0
- package/src/types/std/Option.ts +15 -0
- package/src/types/std/Wrapper.ts +8 -0
- package/src/types/std/mod.ts +2 -0
- package/src/types/taggedUnion.ts +28 -0
- package/src/util/phantoms.ts +3 -0
- package/src/util/recombineTaggedTemplateArgs.ts +6 -0
- package/types/ResponseFormat.d.ts +26 -0
- package/types/ResponseFormat.d.ts.map +1 -0
- package/types/Tool.d.ts +13 -0
- package/types/Tool.d.ts.map +1 -0
- package/types/_dnt.polyfills.d.ts +12 -0
- package/types/_dnt.polyfills.d.ts.map +1 -0
- package/types/_dnt.shims.d.ts +2 -0
- package/types/_dnt.shims.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/almost_equals.d.ts +29 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/almost_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/array_includes.d.ts +24 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/array_includes.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/assert.d.ts +16 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/assert.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/assertion_error.d.ts +26 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/assertion_error.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/equal.d.ts +17 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/equal.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/equals.d.ts +22 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/exists.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/exists.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/fail.d.ts +15 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/fail.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/false.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/false.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/greater.d.ts +20 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/greater.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.d.ts +20 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/instance_of.d.ts +23 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/instance_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/is_error.d.ts +25 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/is_error.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/less.d.ts +19 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/less.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/less_or_equal.d.ts +20 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/less_or_equal.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/match.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/match.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/mod.d.ts +44 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/mod.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_equals.d.ts +21 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_instance_of.d.ts +20 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_instance_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_match.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_match.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.d.ts +23 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/object_match.d.ts +28 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/object_match.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/rejects.d.ts +42 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/rejects.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/strict_equals.d.ts +24 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/strict_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/string_includes.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/string_includes.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/throws.d.ts +45 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/throws.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/unimplemented.d.ts +15 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/unimplemented.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/unreachable.d.ts +15 -0
- package/types/deps/jsr.io/@std/assert/1.0.8/unreachable.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/_utils.d.ts +6 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/_utils.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.d.ts +41 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/associate_by.d.ts +37 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/associate_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/associate_with.d.ts +33 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/associate_with.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/chunk.d.ts +38 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/chunk.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/deep_merge.d.ts +322 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/deep_merge.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/distinct.d.ts +23 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/distinct.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/distinct_by.d.ts +26 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/distinct_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/drop_last_while.d.ts +26 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/drop_last_while.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/drop_while.d.ts +25 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/drop_while.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_entries.d.ts +32 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_entries.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_keys.d.ts +36 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_keys.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_values.d.ts +35 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/filter_values.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/find_single.d.ts +31 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/find_single.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.d.ts +32 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/includes_value.d.ts +29 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/includes_value.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/intersect.d.ts +25 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/intersect.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/invert.d.ts +29 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/invert.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/invert_by.d.ts +34 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/invert_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/join_to_string.d.ts +75 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/join_to_string.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_entries.d.ts +37 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_entries.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_keys.d.ts +33 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_keys.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.d.ts +32 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_values.d.ts +71 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/map_values.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_by.d.ts +117 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_of.d.ts +61 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_with.d.ts +29 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/max_with.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_by.d.ts +115 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_of.d.ts +61 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_with.d.ts +25 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/min_with.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/mod.d.ts +73 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/mod.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/omit.d.ts +24 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/omit.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/partition.d.ts +60 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/partition.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/partition_entries.d.ts +39 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/partition_entries.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/permutations.d.ts +27 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/permutations.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/pick.d.ts +25 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/pick.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/reduce_groups.d.ts +35 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/reduce_groups.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/running_reduce.d.ts +27 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/running_reduce.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sample.d.ts +24 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sample.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sliding_windows.d.ts +66 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sliding_windows.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sort_by.d.ts +161 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sort_by.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sum_of.d.ts +29 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/sum_of.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/take_last_while.d.ts +27 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/take_last_while.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/take_while.d.ts +30 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/take_while.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/union.d.ts +24 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/union.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/unzip.d.ts +32 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/unzip.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/without_all.d.ts +23 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/without_all.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/zip.d.ts +34 -0
- package/types/deps/jsr.io/@std/collections/1.0.9/zip.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts +82 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/diff.d.ts +140 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/diff.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts +99 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/format.d.ts +2 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/format.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/styles.d.ts +159 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/styles.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/types.d.ts +16 -0
- package/types/deps/jsr.io/@std/internal/1.0.5/types.d.ts.map +1 -0
- package/types/mod.d.ts +5 -0
- package/types/mod.d.ts.map +1 -0
- package/types/types/Ref.d.ts +4 -0
- package/types/types/Ref.d.ts.map +1 -0
- package/types/types/RootTy.d.ts +8 -0
- package/types/types/RootTy.d.ts.map +1 -0
- package/types/types/Ty.d.ts +27 -0
- package/types/types/Ty.d.ts.map +1 -0
- package/types/types/array.d.ts +3 -0
- package/types/types/array.d.ts.map +1 -0
- package/types/types/constant.d.ts +3 -0
- package/types/types/constant.d.ts.map +1 -0
- package/types/types/constantUnion.d.ts +3 -0
- package/types/types/constantUnion.d.ts.map +1 -0
- package/types/types/leaves.d.ts +6 -0
- package/types/types/leaves.d.ts.map +1 -0
- package/types/types/mod.d.ts +11 -0
- package/types/types/mod.d.ts.map +1 -0
- package/types/types/object.d.ts +6 -0
- package/types/types/object.d.ts.map +1 -0
- package/types/types/std/Option.d.ts +7 -0
- package/types/types/std/Option.d.ts.map +1 -0
- package/types/types/std/Wrapper.d.ts +7 -0
- package/types/types/std/Wrapper.d.ts.map +1 -0
- package/types/types/std/mod.d.ts +3 -0
- package/types/types/std/mod.d.ts.map +1 -0
- package/types/types/taggedUnion.d.ts +8 -0
- package/types/types/taggedUnion.d.ts.map +1 -0
- package/types/util/phantoms.d.ts +2 -0
- package/types/util/phantoms.d.ts.map +1 -0
- package/types/util/recombineTaggedTemplateArgs.d.ts +2 -0
- package/types/util/recombineTaggedTemplateArgs.d.ts.map +1 -0
- package/esm/F.d.ts +0 -13
- package/esm/F.d.ts.map +0 -1
- package/esm/F.js +0 -10
- package/esm/F.js.map +0 -1
- package/esm/ResponseFormat.d.ts +0 -14
- package/esm/ResponseFormat.d.ts.map +0 -1
- package/esm/_base.d.ts +0 -13
- package/esm/_base.d.ts.map +0 -1
- package/esm/_base.js +0 -40
- package/esm/_base.js.map +0 -1
- package/esm/array.d.ts +0 -4
- package/esm/array.d.ts.map +0 -1
- package/esm/array.js +0 -9
- package/esm/array.js.map +0 -1
- package/esm/common.d.ts +0 -6
- package/esm/common.d.ts.map +0 -1
- package/esm/common.js +0 -2
- package/esm/common.js.map +0 -1
- package/esm/literal.d.ts +0 -4
- package/esm/literal.d.ts.map +0 -1
- package/esm/literal.js +0 -8
- package/esm/literal.js.map +0 -1
- package/esm/mod.d.ts +0 -16
- package/esm/mod.d.ts.map +0 -1
- package/esm/number.d.ts +0 -4
- package/esm/number.d.ts.map +0 -1
- package/esm/number.js +0 -8
- package/esm/number.js.map +0 -1
- package/esm/object.d.ts +0 -7
- package/esm/object.d.ts.map +0 -1
- package/esm/object.js.map +0 -1
- package/esm/schema.d.ts +0 -4
- package/esm/schema.d.ts.map +0 -1
- package/esm/schema.js +0 -9
- package/esm/schema.js.map +0 -1
- package/esm/string.d.ts +0 -4
- package/esm/string.d.ts.map +0 -1
- package/esm/string.js +0 -8
- package/esm/string.js.map +0 -1
- package/esm/union.d.ts +0 -6
- package/esm/union.d.ts.map +0 -1
- package/esm/union.js +0 -8
- package/esm/union.js.map +0 -1
- package/src/F.ts +0 -27
- package/src/_base.ts +0 -25
- package/src/array.ts +0 -11
- package/src/common.ts +0 -6
- package/src/literal.ts +0 -10
- package/src/number.ts +0 -10
- package/src/object.ts +0 -17
- package/src/schema.ts +0 -10
- package/src/string.ts +0 -10
- package/src/union.ts +0 -12
package/README.md
CHANGED
@@ -1,8 +1,79 @@
|
|
1
|
-
#
|
1
|
+
# Structured Outputs
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
A TypeScript library for composing
|
4
|
+
[OpenAI structured output schemas](https://platform.openai.com/docs/guides/structured-outputs).
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
### Node
|
9
|
+
|
10
|
+
```sh
|
11
|
+
npm i structured-outputs
|
12
|
+
```
|
13
|
+
|
14
|
+
### Deno
|
15
|
+
|
16
|
+
```ts
|
17
|
+
deno add jsr:@crosshatch/structured-outputs
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### Basic Usage
|
23
|
+
|
24
|
+
```ts
|
25
|
+
import { ResponseFormat, T } from "structured-outputs"
|
26
|
+
|
27
|
+
// 1. Define the shape of the desired response.
|
28
|
+
const Character = T.object({
|
29
|
+
name: T.string,
|
30
|
+
age: T.number`Ensure between 1 and 110.`,
|
31
|
+
})
|
32
|
+
|
33
|
+
// 2. Create the response format object.
|
34
|
+
const response_format = ResponseFormat("create_character", Character)
|
35
|
+
|
36
|
+
// 3. Utilize the response format to create a chat completion.
|
37
|
+
const response = await openai.chat.completions.create({
|
38
|
+
model: MODEL,
|
39
|
+
messages: [{ role: "system", content: [] }],
|
40
|
+
response_format,
|
41
|
+
})
|
42
|
+
|
43
|
+
// 4. Use `response_format.parseFirstOrThrow` to unwrap the inner data with correct types.
|
44
|
+
const { name, age } = response_format.parseFirstOrThrow(response)
|
45
|
+
```
|
46
|
+
|
47
|
+
For more concise usage, chain off the completions promise.
|
48
|
+
|
49
|
+
```ts
|
50
|
+
const { name, age } = await openai.chat.completions
|
51
|
+
.create({
|
52
|
+
model: MODEL,
|
53
|
+
messages: [{ role: "system", content: [] }],
|
54
|
+
response_format,
|
55
|
+
})
|
56
|
+
.then(response_format.parseFirstOrThrow)
|
57
|
+
```
|
58
|
+
|
59
|
+
We can also attach a description to the response format.
|
60
|
+
|
61
|
+
```diff
|
62
|
+
- ResponseFormat("create_character", Character)
|
63
|
+
+ ResponseFormat("create_character", Character)`
|
64
|
+
+ Create a new character to be the protagonist of a children's story.
|
65
|
+
+ `
|
66
|
+
```
|
67
|
+
|
68
|
+
### Dependency Injection
|
69
|
+
|
70
|
+
```ts
|
71
|
+
const Character = T.object({
|
72
|
+
name: T.string`Preferably names common to those who are {"national identity"}.`,
|
73
|
+
age: T.number`Ensure between 1 and 110.`,
|
74
|
+
})
|
75
|
+
|
76
|
+
const AmericanCharacter = Character.apply({
|
77
|
+
"national identity": "american",
|
78
|
+
})
|
79
|
+
```
|
package/esm/ResponseFormat.js
CHANGED
@@ -1,13 +1,41 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
1
|
+
import { assert } from "./deps/jsr.io/@std/assert/1.0.8/mod.js";
|
2
|
+
import { recombineTaggedTemplateArgs } from "./util/recombineTaggedTemplateArgs.js";
|
3
|
+
export function ResponseFormat(name, ty) {
|
4
|
+
return ResponseFormat_(name, ty);
|
5
|
+
}
|
6
|
+
function ResponseFormat_(name, ty, description) {
|
7
|
+
return Object.assign((template, ...quasis) => ResponseFormat_(name, ty, description ? `${description} ${recombineTaggedTemplateArgs(template, quasis)}` : undefined), {
|
4
8
|
type: "json_schema",
|
5
9
|
json_schema: {
|
6
10
|
name,
|
7
11
|
description,
|
8
|
-
schema: schema(
|
12
|
+
schema: ty.schema(),
|
9
13
|
strict: true,
|
10
14
|
},
|
11
|
-
|
15
|
+
parse(completion) {
|
16
|
+
return {
|
17
|
+
...completion,
|
18
|
+
choices: completion.choices.map((choice) => ({
|
19
|
+
...choice,
|
20
|
+
message: {
|
21
|
+
...choice.message,
|
22
|
+
content: choice.message.content ? JSON.parse(choice.message.content) : null,
|
23
|
+
},
|
24
|
+
})),
|
25
|
+
};
|
26
|
+
},
|
27
|
+
parseFirstOrThrow(completion) {
|
28
|
+
const { choices: [firstChoice], usage } = completion;
|
29
|
+
assert(firstChoice);
|
30
|
+
const { finish_reason, message } = firstChoice;
|
31
|
+
const { content, refusal } = message;
|
32
|
+
assert(content, JSON.stringify({ finish_reason, refusal, usage }));
|
33
|
+
return JSON.parse(content);
|
34
|
+
},
|
35
|
+
toJSON() {
|
36
|
+
const { type, json_schema } = this;
|
37
|
+
return { type, json_schema };
|
38
|
+
},
|
39
|
+
});
|
12
40
|
}
|
13
41
|
//# sourceMappingURL=ResponseFormat.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ResponseFormat.js","sourceRoot":"","sources":["../src/ResponseFormat.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"ResponseFormat.js","sourceRoot":"","sources":["../src/ResponseFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wCAAwC,CAAA;AAI/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAA;AAEnF,MAAM,UAAU,cAAc,CAAI,IAAY,EAAE,EAAoB;IAClE,OAAO,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;AAClC,CAAC;AAED,SAAS,eAAe,CACtB,IAAY,EACZ,EAAoB,EACpB,WAAoB;IAEpB,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,QAA8B,EAAE,GAAG,MAAqB,EAAE,EAAE,CAC3D,eAAe,CACb,IAAI,EACJ,EAAE,EACF,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,IAAI,2BAA2B,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,C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ineTaggedTemplateArgs } from "./util/recombineTaggedTemplateArgs.js";
|
2
|
+
export function Tool(name, ty) {
|
3
|
+
return Tool_(name, ty);
|
4
|
+
}
|
5
|
+
function Tool_(name, ty, description) {
|
6
|
+
return Object.assign((template, ...quasis) => Tool_(name, ty, description ? `${description} ${recombineTaggedTemplateArgs(template, quasis)}` : undefined), {
|
7
|
+
type: "function",
|
8
|
+
name,
|
9
|
+
description,
|
10
|
+
parameters: ty.schema(),
|
11
|
+
toJson() {
|
12
|
+
const { type, name, description, parameters } = this;
|
13
|
+
return { type, name, description, parameters };
|
14
|
+
},
|
15
|
+
});
|
16
|
+
}
|
17
|
+
//# sourceMappingURL=Tool.js.map
|
package/esm/Tool.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Tool.js","sourceRoot":"","sources":["../src/Tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAA;AAEnF,MAAM,UAAU,IAAI,CAAI,IAAY,EAAE,EAAoB;IACxD,OAAO,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;AACxB,CAAC;AAED,SAAS,KAAK,CAAI,IAAY,EAAE,EAAoB,EAAE,WAAoB;IACxE,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,QAA8B,EAAE,GAAG,MAAqB,EAAE,EAAE,CAC3D,KAAK,CACH,IAAI,EACJ,EAAE,EACF,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,IAAI,2BAA2B,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAC5F,EACH;QACE,IAAI,EAAE,UAAmB;QACzB,IAAI;QACJ,WAAW;QACX,UAAU,EAAE,EAAE,CAAC,MAAM,EAAE;QACvB,MAAM;YACJ,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,CAAA;YACpD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,CAAA;QAChD,CAAC;KACF,CACF,CAAA;AACH,CAAC"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
|
2
|
+
if (!Object.hasOwn) {
|
3
|
+
Object.defineProperty(Object, "hasOwn", {
|
4
|
+
value: function (object, property) {
|
5
|
+
if (object == null) {
|
6
|
+
throw new TypeError("Cannot convert undefined or null to object");
|
7
|
+
}
|
8
|
+
return Object.prototype.hasOwnProperty.call(Object(object), property);
|
9
|
+
},
|
10
|
+
configurable: true,
|
11
|
+
enumerable: false,
|
12
|
+
writable: true,
|
13
|
+
});
|
14
|
+
}
|
15
|
+
export {};
|
16
|
+
//# sourceMappingURL=_dnt.polyfills.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"_dnt.polyfills.js","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE;QACtC,KAAK,EAAE,UAAU,MAAW,EAAE,QAAa;YACzC,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;gBACnB,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;YACpE,CAAC;YACD,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC;QACxE,CAAC;QACD,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;AACL,CAAC"}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
const dntGlobals = {};
|
2
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
3
|
+
function createMergeProxy(baseObj, extObj) {
|
4
|
+
return new Proxy(baseObj, {
|
5
|
+
get(_target, prop, _receiver) {
|
6
|
+
if (prop in extObj) {
|
7
|
+
return extObj[prop];
|
8
|
+
}
|
9
|
+
else {
|
10
|
+
return baseObj[prop];
|
11
|
+
}
|
12
|
+
},
|
13
|
+
set(_target, prop, value) {
|
14
|
+
if (prop in extObj) {
|
15
|
+
delete extObj[prop];
|
16
|
+
}
|
17
|
+
baseObj[prop] = value;
|
18
|
+
return true;
|
19
|
+
},
|
20
|
+
deleteProperty(_target, prop) {
|
21
|
+
let success = false;
|
22
|
+
if (prop in extObj) {
|
23
|
+
delete extObj[prop];
|
24
|
+
success = true;
|
25
|
+
}
|
26
|
+
if (prop in baseObj) {
|
27
|
+
delete baseObj[prop];
|
28
|
+
success = true;
|
29
|
+
}
|
30
|
+
return success;
|
31
|
+
},
|
32
|
+
ownKeys(_target) {
|
33
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
34
|
+
const extKeys = Reflect.ownKeys(extObj);
|
35
|
+
const extKeysSet = new Set(extKeys);
|
36
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
37
|
+
},
|
38
|
+
defineProperty(_target, prop, desc) {
|
39
|
+
if (prop in extObj) {
|
40
|
+
delete extObj[prop];
|
41
|
+
}
|
42
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
43
|
+
return true;
|
44
|
+
},
|
45
|
+
getOwnPropertyDescriptor(_target, prop) {
|
46
|
+
if (prop in extObj) {
|
47
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
48
|
+
}
|
49
|
+
else {
|
50
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
51
|
+
}
|
52
|
+
},
|
53
|
+
has(_target, prop) {
|
54
|
+
return prop in extObj || prop in baseObj;
|
55
|
+
},
|
56
|
+
});
|
57
|
+
}
|
58
|
+
//# sourceMappingURL=_dnt.shims.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"_dnt.shims.js","source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,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;YACpC,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC;QACrE,CAAC;QACD,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI;YAChC,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACnB,OAAQ,MAAc,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YAC5C,OAAO,IAAI,CAAC;QACd,CAAC;QACD,wBAAwB,CAAC,OAAO,EAAE,IAAI;YACpC,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACnB,OAAO,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACxD,CAAC;iBAAM,CAAC;gBACN,OAAO,OAAO,CAAC,wBAAwB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QACD,GAAG,CAAC,OAAO,EAAE,IAAI;YACf,OAAO,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,OAAO,CAAC;QAC3C,CAAC;KACF,CAAQ,CAAC;AACZ,CAAC"}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
import { AssertionError } from "./assertion_error.js";
|
4
|
+
/**
|
5
|
+
* Make an assertion that `actual` and `expected` are almost equal numbers
|
6
|
+
* through a given tolerance. It can be used to take into account IEEE-754
|
7
|
+
* double-precision floating-point representation limitations. If the values
|
8
|
+
* are not almost equal then throw.
|
9
|
+
*
|
10
|
+
* The default tolerance is one hundred thousandth of a percent of the
|
11
|
+
* expected value.
|
12
|
+
*
|
13
|
+
* @example Usage
|
14
|
+
* ```ts ignore
|
15
|
+
* import { assertAlmostEquals } from "@std/assert";
|
16
|
+
*
|
17
|
+
* assertAlmostEquals(0.01, 0.02); // Throws
|
18
|
+
* assertAlmostEquals(1e-8, 1e-9); // Throws
|
19
|
+
* assertAlmostEquals(1.000000001e-8, 1.000000002e-8); // Doesn't throw
|
20
|
+
* assertAlmostEquals(0.01, 0.02, 0.1); // Doesn't throw
|
21
|
+
* assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16); // Doesn't throw
|
22
|
+
* assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17); // Throws
|
23
|
+
* ```
|
24
|
+
*
|
25
|
+
* @param actual The actual value to compare.
|
26
|
+
* @param expected The expected value to compare.
|
27
|
+
* @param tolerance The tolerance to consider the values almost equal. The
|
28
|
+
* default is one hundred thousandth of a percent of the expected value.
|
29
|
+
* @param msg The optional message to include in the error.
|
30
|
+
*/
|
31
|
+
export function assertAlmostEquals(actual, expected, tolerance, msg) {
|
32
|
+
if (Object.is(actual, expected)) {
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
const delta = Math.abs(expected - actual);
|
36
|
+
if (tolerance === undefined) {
|
37
|
+
tolerance = isFinite(expected) ? Math.abs(expected * 1e-7) : 1e-7;
|
38
|
+
}
|
39
|
+
if (delta <= tolerance) {
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
const msgSuffix = msg ? `: ${msg}` : ".";
|
43
|
+
const f = (n) => Number.isInteger(n) ? n : n.toExponential();
|
44
|
+
throw new AssertionError(`Expected actual: "${f(actual)}" to be close to "${f(expected)}": \
|
45
|
+
delta "${f(delta)}" is greater than "${f(tolerance)}"${msgSuffix}`);
|
46
|
+
}
|
47
|
+
//# sourceMappingURL=almost_equals.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"almost_equals.js","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/1.0.8/almost_equals.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qCAAqC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAc,EACd,QAAgB,EAChB,SAAkB,EAClB,GAAY;IAEZ,IAAI,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC;QAChC,OAAO;IACT,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,MAAM,CAAC,CAAC;IAC1C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACpE,CAAC;IACD,IAAI,KAAK,IAAI,SAAS,EAAE,CAAC;QACvB,OAAO;IACT,CAAC;IAED,MAAM,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IACzC,MAAM,CAAC,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;IACrE,MAAM,IAAI,cAAc,CACtB,qBAAqB,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,QAAQ,CAAC;SACzD,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC,SAAS,CAAC,IAAI,SAAS,EAAE,CAC/D,CAAC;AACJ,CAAC"}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
import { equal } from "./equal.js";
|
4
|
+
import { format } from "../../internal/1.0.5/format.js";
|
5
|
+
import { AssertionError } from "./assertion_error.js";
|
6
|
+
/**
|
7
|
+
* Make an assertion that `actual` includes the `expected` values. If not then
|
8
|
+
* an error will be thrown.
|
9
|
+
*
|
10
|
+
* Type parameter can be specified to ensure values under comparison have the
|
11
|
+
* same type.
|
12
|
+
*
|
13
|
+
* @example Usage
|
14
|
+
* ```ts ignore
|
15
|
+
* import { assertArrayIncludes } from "@std/assert";
|
16
|
+
*
|
17
|
+
* assertArrayIncludes([1, 2], [2]); // Doesn't throw
|
18
|
+
* assertArrayIncludes([1, 2], [3]); // Throws
|
19
|
+
* ```
|
20
|
+
*
|
21
|
+
* @typeParam T The type of the elements in the array to compare.
|
22
|
+
* @param actual The array-like object to check for.
|
23
|
+
* @param expected The array-like object to check for.
|
24
|
+
* @param msg The optional message to display if the assertion fails.
|
25
|
+
*/
|
26
|
+
export function assertArrayIncludes(actual, expected, msg) {
|
27
|
+
const missing = [];
|
28
|
+
for (let i = 0; i < expected.length; i++) {
|
29
|
+
let found = false;
|
30
|
+
for (let j = 0; j < actual.length; j++) {
|
31
|
+
if (equal(expected[i], actual[j])) {
|
32
|
+
found = true;
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
if (!found) {
|
37
|
+
missing.push(expected[i]);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
if (missing.length === 0) {
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
const msgSuffix = msg ? `: ${msg}` : ".";
|
44
|
+
msg = `Expected actual: "${format(actual)}" to include: "${format(expected)}"${msgSuffix}\nmissing: ${format(missing)}`;
|
45
|
+
throw new AssertionError(msg);
|
46
|
+
}
|
47
|
+
//# sourceMappingURL=array_includes.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"array_includes.js","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/1.0.8/array_includes.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qCAAqC;A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2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
import { AssertionError } from "./assertion_error.js";
|
4
|
+
/**
|
5
|
+
* Make an assertion, error will be thrown if `expr` does not have truthy value.
|
6
|
+
*
|
7
|
+
* @example Usage
|
8
|
+
* ```ts ignore
|
9
|
+
* import { assert } from "@std/assert";
|
10
|
+
*
|
11
|
+
* assert("hello".includes("ello")); // Doesn't throw
|
12
|
+
* assert("hello".includes("world")); // Throws
|
13
|
+
* ```
|
14
|
+
*
|
15
|
+
* @param expr The expression to test.
|
16
|
+
* @param msg The optional message to display if the assertion fails.
|
17
|
+
*/
|
18
|
+
export function assert(expr, msg = "") {
|
19
|
+
if (!expr) {
|
20
|
+
throw new AssertionError(msg);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
//# sourceMappingURL=assert.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/1.0.8/assert.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qCAAqC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,MAAM,CAAC,IAAa,EAAE,GAAG,GAAG,EAAE;IAC5C,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,cAAc,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;AACH,CAAC"}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
/**
|
4
|
+
* Error thrown when an assertion fails.
|
5
|
+
*
|
6
|
+
* @example Usage
|
7
|
+
* ```ts ignore
|
8
|
+
* import { AssertionError } from "@std/assert";
|
9
|
+
*
|
10
|
+
* try {
|
11
|
+
* throw new AssertionError("foo", { cause: "bar" });
|
12
|
+
* } catch (error) {
|
13
|
+
* if (error instanceof AssertionError) {
|
14
|
+
* error.message === "foo"; // true
|
15
|
+
* error.cause === "bar"; // true
|
16
|
+
* }
|
17
|
+
* }
|
18
|
+
* ```
|
19
|
+
*/
|
20
|
+
export class AssertionError extends Error {
|
21
|
+
/** Constructs a new instance.
|
22
|
+
*
|
23
|
+
* @param message The error message.
|
24
|
+
* @param options Additional options. This argument is still unstable. It may change in the future release.
|
25
|
+
*/
|
26
|
+
constructor(message, options) {
|
27
|
+
super(message, options);
|
28
|
+
this.name = "AssertionError";
|
29
|
+
}
|
30
|
+
}
|
31
|
+
//# sourceMappingURL=assertion_error.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"assertion_error.js","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/1.0.8/assertion_error.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qCAAqC;AAErC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC;;;;OAIG;IACH,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF"}
|
@@ -0,0 +1,184 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
import * as dntShim from "../../../../../_dnt.shims.js";
|
4
|
+
function isKeyedCollection(x) {
|
5
|
+
return x instanceof Set || x instanceof Map;
|
6
|
+
}
|
7
|
+
function prototypesEqual(a, b) {
|
8
|
+
const pa = Object.getPrototypeOf(a);
|
9
|
+
const pb = Object.getPrototypeOf(b);
|
10
|
+
return pa === pb ||
|
11
|
+
pa === Object.prototype && pb === null ||
|
12
|
+
pa === null && pb === Object.prototype;
|
13
|
+
}
|
14
|
+
function isBasicObjectOrArray(obj) {
|
15
|
+
const proto = Object.getPrototypeOf(obj);
|
16
|
+
return proto === null || proto === Object.prototype ||
|
17
|
+
proto === Array.prototype;
|
18
|
+
}
|
19
|
+
// Slightly faster than Reflect.ownKeys in V8 as of 12.9.202.13-rusty (2024-10-28)
|
20
|
+
function ownKeys(obj) {
|
21
|
+
return [
|
22
|
+
...Object.getOwnPropertyNames(obj),
|
23
|
+
...Object.getOwnPropertySymbols(obj),
|
24
|
+
];
|
25
|
+
}
|
26
|
+
function getKeysDeep(obj) {
|
27
|
+
const keys = new Set();
|
28
|
+
while (obj !== Object.prototype && obj !== Array.prototype && obj != null) {
|
29
|
+
for (const key of ownKeys(obj)) {
|
30
|
+
keys.add(key);
|
31
|
+
}
|
32
|
+
obj = Object.getPrototypeOf(obj);
|
33
|
+
}
|
34
|
+
return keys;
|
35
|
+
}
|
36
|
+
// deno-lint-ignore no-explicit-any
|
37
|
+
const Temporal = dntShim.dntGlobalThis.Temporal ??
|
38
|
+
new Proxy({}, { get: () => { } });
|
39
|
+
/** A non-exhaustive list of prototypes that can be accurately fast-path compared with `String(instance)` */
|
40
|
+
const stringComparablePrototypes = new Set([
|
41
|
+
Intl.Locale,
|
42
|
+
RegExp,
|
43
|
+
Temporal.Duration,
|
44
|
+
Temporal.Instant,
|
45
|
+
Temporal.PlainDate,
|
46
|
+
Temporal.PlainDateTime,
|
47
|
+
Temporal.PlainTime,
|
48
|
+
Temporal.PlainYearMonth,
|
49
|
+
Temporal.PlainMonthDay,
|
50
|
+
Temporal.ZonedDateTime,
|
51
|
+
URL,
|
52
|
+
URLSearchParams,
|
53
|
+
].filter((x) => x != null).map((x) => x.prototype));
|
54
|
+
function isPrimitive(x) {
|
55
|
+
return typeof x === "string" ||
|
56
|
+
typeof x === "number" ||
|
57
|
+
typeof x === "boolean" ||
|
58
|
+
typeof x === "bigint" ||
|
59
|
+
typeof x === "symbol" ||
|
60
|
+
x == null;
|
61
|
+
}
|
62
|
+
const TypedArray = Object.getPrototypeOf(Uint8Array);
|
63
|
+
function compareTypedArrays(a, b) {
|
64
|
+
if (a.length !== b.length)
|
65
|
+
return false;
|
66
|
+
for (let i = 0; i < b.length; i++) {
|
67
|
+
if (!sameValueZero(a[i], b[i]))
|
68
|
+
return false;
|
69
|
+
}
|
70
|
+
return true;
|
71
|
+
}
|
72
|
+
/** Check both strict equality (`0 == -0`) and `Object.is` (`NaN == NaN`) */
|
73
|
+
function sameValueZero(a, b) {
|
74
|
+
return a === b || Object.is(a, b);
|
75
|
+
}
|
76
|
+
/**
|
77
|
+
* Deep equality comparison used in assertions.
|
78
|
+
*
|
79
|
+
* @param a The actual value
|
80
|
+
* @param b The expected value
|
81
|
+
* @returns `true` if the values are deeply equal, `false` otherwise
|
82
|
+
*
|
83
|
+
* @example Usage
|
84
|
+
* ```ts
|
85
|
+
* import { equal } from "@std/assert/equal";
|
86
|
+
*
|
87
|
+
* equal({ foo: "bar" }, { foo: "bar" }); // Returns `true`
|
88
|
+
* equal({ foo: "bar" }, { foo: "baz" }); // Returns `false`
|
89
|
+
* ```
|
90
|
+
*/
|
91
|
+
export function equal(a, b) {
|
92
|
+
const seen = new Map();
|
93
|
+
return (function compare(a, b) {
|
94
|
+
if (sameValueZero(a, b))
|
95
|
+
return true;
|
96
|
+
if (isPrimitive(a) || isPrimitive(b))
|
97
|
+
return false;
|
98
|
+
if (a instanceof Date && b instanceof Date) {
|
99
|
+
return Object.is(a.getTime(), b.getTime());
|
100
|
+
}
|
101
|
+
if (a && typeof a === "object" && b && typeof b === "object") {
|
102
|
+
if (!prototypesEqual(a, b)) {
|
103
|
+
return false;
|
104
|
+
}
|
105
|
+
if (a instanceof TypedArray) {
|
106
|
+
return compareTypedArrays(a, b);
|
107
|
+
}
|
108
|
+
if (a instanceof WeakMap) {
|
109
|
+
throw new TypeError("cannot compare WeakMap instances");
|
110
|
+
}
|
111
|
+
if (a instanceof WeakSet) {
|
112
|
+
throw new TypeError("cannot compare WeakSet instances");
|
113
|
+
}
|
114
|
+
if (a instanceof WeakRef) {
|
115
|
+
return compare(a.deref(), b.deref());
|
116
|
+
}
|
117
|
+
if (seen.get(a) === b) {
|
118
|
+
return true;
|
119
|
+
}
|
120
|
+
if (Object.keys(a).length !== Object.keys(b).length) {
|
121
|
+
return false;
|
122
|
+
}
|
123
|
+
seen.set(a, b);
|
124
|
+
if (isKeyedCollection(a) && isKeyedCollection(b)) {
|
125
|
+
if (a.size !== b.size) {
|
126
|
+
return false;
|
127
|
+
}
|
128
|
+
const aKeys = [...a.keys()];
|
129
|
+
const primitiveKeysFastPath = aKeys.every(isPrimitive);
|
130
|
+
if (primitiveKeysFastPath) {
|
131
|
+
if (a instanceof Set) {
|
132
|
+
return a.symmetricDifference(b).size === 0;
|
133
|
+
}
|
134
|
+
for (const key of aKeys) {
|
135
|
+
if (!b.has(key) ||
|
136
|
+
!compare(a.get(key), b.get(key))) {
|
137
|
+
return false;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
return true;
|
141
|
+
}
|
142
|
+
let unmatchedEntries = a.size;
|
143
|
+
for (const [aKey, aValue] of a.entries()) {
|
144
|
+
for (const [bKey, bValue] of b.entries()) {
|
145
|
+
/* Given that Map keys can be references, we need
|
146
|
+
* to ensure that they are also deeply equal */
|
147
|
+
if (!compare(aKey, bKey))
|
148
|
+
continue;
|
149
|
+
if ((aKey === aValue && bKey === bValue) ||
|
150
|
+
(compare(aValue, bValue))) {
|
151
|
+
unmatchedEntries--;
|
152
|
+
break;
|
153
|
+
}
|
154
|
+
}
|
155
|
+
}
|
156
|
+
return unmatchedEntries === 0;
|
157
|
+
}
|
158
|
+
let keys;
|
159
|
+
if (isBasicObjectOrArray(a)) {
|
160
|
+
// fast path
|
161
|
+
keys = ownKeys({ ...a, ...b });
|
162
|
+
}
|
163
|
+
else if (stringComparablePrototypes.has(Object.getPrototypeOf(a))) {
|
164
|
+
// medium path
|
165
|
+
return String(a) === String(b);
|
166
|
+
}
|
167
|
+
else {
|
168
|
+
// slow path
|
169
|
+
keys = getKeysDeep(a).union(getKeysDeep(b));
|
170
|
+
}
|
171
|
+
for (const key of keys) {
|
172
|
+
if (!compare(a[key], b[key])) {
|
173
|
+
return false;
|
174
|
+
}
|
175
|
+
if (((key in a) && (!(key in b))) || ((key in b) && (!(key in a)))) {
|
176
|
+
return false;
|
177
|
+
}
|
178
|
+
}
|
179
|
+
return true;
|
180
|
+
}
|
181
|
+
return false;
|
182
|
+
})(a, b);
|
183
|
+
}
|
184
|
+
//# sourceMappingURL=equal.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"equal.js","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/1.0.8/equal.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qCAAqC;AACrC,OAAO,KAAK,OAAO,MAAM,8BAA8B,CAAC;AAIxD,SAAS,iBAAiB,CAAC,CAAU;IACnC,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,GAAG,CAAC;AAC9C,CAAC;AAED,SAAS,eAAe,CAAC,CAAS,EAAE,CAAS;IAC3C,MAAM,EAAE,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IACpC,MAAM,EAAE,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IACpC,OAAO,EAAE,KAAK,EAAE;QACd,EAAE,KAAK,MAAM,CAAC,SAAS,IAAI,EAAE,KAAK,IAAI;QACtC,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,MAAM,CAAC,SAAS,CAAC;AAC3C,CAAC;AAED,SAAS,oBAAoB,CAAC,GAAW;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IACzC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,MAAM,CAAC,SAAS;QACjD,KAAK,KAAK,KAAK,CAAC,SAAS,CAAC;AAC9B,CAAC;AAED,kFAAkF;AAClF,SAAS,OAAO,CAAC,GAAW;IAC1B,OAAO;QACL,GAAG,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC;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AED,IAAI,IAA+B,CAAC;YAEpC,IAAI,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC5B,YAAY;gBACZ,IAAI,GAAG,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;YACjC,CAAC;iBAAM,IAAI,0BAA0B,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpE,cAAc;gBACd,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC;YACjC,CAAC;iBAAM,CAAC;gBACN,YAAY;gBACZ,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9C,CAAC;YAED,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBAEvB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAU,CAAC,EAAE,CAAC,CAAC,GAAU,CAAC,CAAC,EAAE,CAAC;oBAC3C,OAAO,KAAK,CAAC;gBACf,CAAC;gBACD,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnE,OAAO,KAAK,CAAC;gBACf,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACX,CAAC"}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2
|
+
// This module is browser compatible.
|
3
|
+
import { equal } from "./equal.js";
|
4
|
+
import { buildMessage } from "../../internal/1.0.5/build_message.js";
|
5
|
+
import { diff } from "../../internal/1.0.5/diff.js";
|
6
|
+
import { diffStr } from "../../internal/1.0.5/diff_str.js";
|
7
|
+
import { format } from "../../internal/1.0.5/format.js";
|
8
|
+
import { AssertionError } from "./assertion_error.js";
|
9
|
+
/**
|
10
|
+
* Make an assertion that `actual` and `expected` are equal, deeply. If not
|
11
|
+
* deeply equal, then throw.
|
12
|
+
*
|
13
|
+
* Type parameter can be specified to ensure values under comparison have the
|
14
|
+
* same type.
|
15
|
+
*
|
16
|
+
* @example Usage
|
17
|
+
* ```ts ignore
|
18
|
+
* import { assertEquals } from "@std/assert";
|
19
|
+
*
|
20
|
+
* assertEquals("world", "world"); // Doesn't throw
|
21
|
+
* assertEquals("hello", "world"); // Throws
|
22
|
+
* ```
|
23
|
+
*
|
24
|
+
* @typeParam T The type of the values to compare. This is usually inferred.
|
25
|
+
* @param actual The actual value to compare.
|
26
|
+
* @param expected The expected value to compare.
|
27
|
+
* @param msg The optional message to display if the assertion fails.
|
28
|
+
*/
|
29
|
+
export function assertEquals(actual, expected, msg) {
|
30
|
+
if (equal(actual, expected)) {
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
const msgSuffix = msg ? `: ${msg}` : ".";
|
34
|
+
let message = `Values are not equal${msgSuffix}`;
|
35
|
+
const actualString = format(actual);
|
36
|
+
const expectedString = format(expected);
|
37
|
+
const stringDiff = (typeof actual === "string") &&
|
38
|
+
(typeof expected === "string");
|
39
|
+
const diffResult = stringDiff
|
40
|
+
? diffStr(actual, expected)
|
41
|
+
: diff(actualString.split("\n"), expectedString.split("\n"));
|
42
|
+
const diffMsg = buildMessage(diffResult, { stringDiff }).join("\n");
|
43
|
+
message = `${message}\n${diffMsg}`;
|
44
|
+
throw new AssertionError(message);
|
45
|
+
}
|
46
|
+
//# sourceMappingURL=equals.js.map
|