structured-outputs 0.1.0-beta.20 → 0.1.0-beta.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (371) hide show
  1. package/README.md +46 -40
  2. package/esm/ResponseFormat.d.ts +21 -0
  3. package/esm/ResponseFormat.d.ts.map +1 -0
  4. package/esm/ResponseFormat.js +43 -19
  5. package/esm/ResponseFormat.js.map +1 -1
  6. package/{types → esm}/Tool.d.ts +1 -0
  7. package/esm/Tool.d.ts.map +1 -0
  8. package/esm/Tool.js +1 -0
  9. package/esm/Tool.js.map +1 -1
  10. package/esm/oai.d.ts +5 -0
  11. package/esm/oai.d.ts.map +1 -0
  12. package/esm/oai.js +2 -0
  13. package/esm/oai.js.map +1 -0
  14. package/esm/types/Ref.d.ts.map +1 -0
  15. package/esm/types/Ref.js +6 -3
  16. package/esm/types/Ref.js.map +1 -1
  17. package/esm/types/RootTy.d.ts +8 -0
  18. package/esm/types/RootTy.d.ts.map +1 -0
  19. package/esm/types/RootTy.js +5 -7
  20. package/esm/types/RootTy.js.map +1 -1
  21. package/esm/types/Ty.d.ts +23 -0
  22. package/esm/types/Ty.d.ts.map +1 -0
  23. package/esm/types/Ty.js +5 -9
  24. package/esm/types/Ty.js.map +1 -1
  25. package/{types → esm}/types/array.d.ts +1 -1
  26. package/{types → esm}/types/array.d.ts.map +1 -1
  27. package/esm/types/array.js +1 -2
  28. package/esm/types/array.js.map +1 -1
  29. package/{types → esm}/types/constant.d.ts.map +1 -1
  30. package/esm/types/constant.js +1 -2
  31. package/esm/types/constant.js.map +1 -1
  32. package/{types → esm}/types/constantUnion.d.ts.map +1 -1
  33. package/esm/types/constantUnion.js +16 -19
  34. package/esm/types/constantUnion.js.map +1 -1
  35. package/{types → esm}/types/mod.d.ts +3 -3
  36. package/esm/types/mod.d.ts.map +1 -0
  37. package/esm/types/mod.js +3 -3
  38. package/esm/types/mod.js.map +1 -1
  39. package/{types → esm}/types/object.d.ts +2 -2
  40. package/{types → esm}/types/object.d.ts.map +1 -1
  41. package/esm/types/object.js +1 -2
  42. package/esm/types/object.js.map +1 -1
  43. package/{types/types/leaves.d.ts → esm/types/primitives.d.ts} +1 -1
  44. package/esm/types/primitives.d.ts.map +1 -0
  45. package/esm/types/primitives.js +14 -0
  46. package/esm/types/primitives.js.map +1 -0
  47. package/esm/types/std/Option.js +1 -1
  48. package/esm/types/std/Option.js.map +1 -1
  49. package/{types → esm}/types/std/Wrapper.d.ts +0 -1
  50. package/esm/types/std/Wrapper.d.ts.map +1 -0
  51. package/esm/types/std/Wrapper.js.map +1 -1
  52. package/{types → esm}/types/taggedUnion.d.ts +2 -2
  53. package/{types → esm}/types/taggedUnion.d.ts.map +1 -1
  54. package/esm/types/taggedUnion.js +1 -2
  55. package/esm/types/taggedUnion.js.map +1 -1
  56. package/package.json +6 -11
  57. package/src/ResponseFormat.ts +48 -41
  58. package/src/Tool.ts +1 -0
  59. package/src/oai.ts +5 -0
  60. package/src/types/Ref.ts +7 -4
  61. package/src/types/RootTy.ts +11 -13
  62. package/src/types/Ty.ts +23 -30
  63. package/src/types/array.ts +2 -3
  64. package/src/types/constant.ts +1 -2
  65. package/src/types/constantUnion.ts +16 -19
  66. package/src/types/mod.ts +3 -3
  67. package/src/types/object.ts +4 -6
  68. package/src/types/primitives.ts +17 -0
  69. package/src/types/std/Option.ts +1 -1
  70. package/src/types/std/Wrapper.ts +0 -2
  71. package/src/types/taggedUnion.ts +3 -4
  72. package/esm/_dnt.shims.js +0 -58
  73. package/esm/_dnt.shims.js.map +0 -1
  74. package/esm/deps/jsr.io/@std/assert/1.0.8/almost_equals.js +0 -47
  75. package/esm/deps/jsr.io/@std/assert/1.0.8/almost_equals.js.map +0 -1
  76. package/esm/deps/jsr.io/@std/assert/1.0.8/array_includes.js +0 -47
  77. package/esm/deps/jsr.io/@std/assert/1.0.8/array_includes.js.map +0 -1
  78. package/esm/deps/jsr.io/@std/assert/1.0.8/assert.js +0 -23
  79. package/esm/deps/jsr.io/@std/assert/1.0.8/assert.js.map +0 -1
  80. package/esm/deps/jsr.io/@std/assert/1.0.8/assertion_error.js +0 -31
  81. package/esm/deps/jsr.io/@std/assert/1.0.8/assertion_error.js.map +0 -1
  82. package/esm/deps/jsr.io/@std/assert/1.0.8/equal.js +0 -184
  83. package/esm/deps/jsr.io/@std/assert/1.0.8/equal.js.map +0 -1
  84. package/esm/deps/jsr.io/@std/assert/1.0.8/equals.js +0 -46
  85. package/esm/deps/jsr.io/@std/assert/1.0.8/equals.js.map +0 -1
  86. package/esm/deps/jsr.io/@std/assert/1.0.8/exists.js +0 -28
  87. package/esm/deps/jsr.io/@std/assert/1.0.8/exists.js.map +0 -1
  88. package/esm/deps/jsr.io/@std/assert/1.0.8/fail.js +0 -21
  89. package/esm/deps/jsr.io/@std/assert/1.0.8/fail.js.map +0 -1
  90. package/esm/deps/jsr.io/@std/assert/1.0.8/false.js +0 -23
  91. package/esm/deps/jsr.io/@std/assert/1.0.8/false.js.map +0 -1
  92. package/esm/deps/jsr.io/@std/assert/1.0.8/greater.js +0 -30
  93. package/esm/deps/jsr.io/@std/assert/1.0.8/greater.js.map +0 -1
  94. package/esm/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.js +0 -30
  95. package/esm/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.js.map +0 -1
  96. package/esm/deps/jsr.io/@std/assert/1.0.8/instance_of.js +0 -53
  97. package/esm/deps/jsr.io/@std/assert/1.0.8/instance_of.js.map +0 -1
  98. package/esm/deps/jsr.io/@std/assert/1.0.8/is_error.js +0 -54
  99. package/esm/deps/jsr.io/@std/assert/1.0.8/is_error.js.map +0 -1
  100. package/esm/deps/jsr.io/@std/assert/1.0.8/less.js +0 -29
  101. package/esm/deps/jsr.io/@std/assert/1.0.8/less.js.map +0 -1
  102. package/esm/deps/jsr.io/@std/assert/1.0.8/less_or_equal.js +0 -30
  103. package/esm/deps/jsr.io/@std/assert/1.0.8/less_or_equal.js.map +0 -1
  104. package/esm/deps/jsr.io/@std/assert/1.0.8/match.js +0 -27
  105. package/esm/deps/jsr.io/@std/assert/1.0.8/match.js.map +0 -1
  106. package/esm/deps/jsr.io/@std/assert/1.0.8/mod.js +0 -46
  107. package/esm/deps/jsr.io/@std/assert/1.0.8/mod.js.map +0 -1
  108. package/esm/deps/jsr.io/@std/assert/1.0.8/not_equals.js +0 -33
  109. package/esm/deps/jsr.io/@std/assert/1.0.8/not_equals.js.map +0 -1
  110. package/esm/deps/jsr.io/@std/assert/1.0.8/not_instance_of.js +0 -30
  111. package/esm/deps/jsr.io/@std/assert/1.0.8/not_instance_of.js.map +0 -1
  112. package/esm/deps/jsr.io/@std/assert/1.0.8/not_match.js +0 -27
  113. package/esm/deps/jsr.io/@std/assert/1.0.8/not_match.js.map +0 -1
  114. package/esm/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.js +0 -33
  115. package/esm/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.js.map +0 -1
  116. package/esm/deps/jsr.io/@std/assert/1.0.8/object_match.js +0 -160
  117. package/esm/deps/jsr.io/@std/assert/1.0.8/object_match.js.map +0 -1
  118. package/esm/deps/jsr.io/@std/assert/1.0.8/rejects.js +0 -54
  119. package/esm/deps/jsr.io/@std/assert/1.0.8/rejects.js.map +0 -1
  120. package/esm/deps/jsr.io/@std/assert/1.0.8/strict_equals.js +0 -58
  121. package/esm/deps/jsr.io/@std/assert/1.0.8/strict_equals.js.map +0 -1
  122. package/esm/deps/jsr.io/@std/assert/1.0.8/string_includes.js +0 -27
  123. package/esm/deps/jsr.io/@std/assert/1.0.8/string_includes.js.map +0 -1
  124. package/esm/deps/jsr.io/@std/assert/1.0.8/throws.js +0 -45
  125. package/esm/deps/jsr.io/@std/assert/1.0.8/throws.js.map +0 -1
  126. package/esm/deps/jsr.io/@std/assert/1.0.8/unimplemented.js +0 -21
  127. package/esm/deps/jsr.io/@std/assert/1.0.8/unimplemented.js.map +0 -1
  128. package/esm/deps/jsr.io/@std/assert/1.0.8/unreachable.js +0 -21
  129. package/esm/deps/jsr.io/@std/assert/1.0.8/unreachable.js.map +0 -1
  130. package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.js +0 -111
  131. package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.js.map +0 -1
  132. package/esm/deps/jsr.io/@std/internal/1.0.5/diff.js +0 -277
  133. package/esm/deps/jsr.io/@std/internal/1.0.5/diff.js.map +0 -1
  134. package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.js +0 -180
  135. package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.js.map +0 -1
  136. package/esm/deps/jsr.io/@std/internal/1.0.5/format.js +0 -38
  137. package/esm/deps/jsr.io/@std/internal/1.0.5/format.js.map +0 -1
  138. package/esm/deps/jsr.io/@std/internal/1.0.5/styles.js +0 -208
  139. package/esm/deps/jsr.io/@std/internal/1.0.5/styles.js.map +0 -1
  140. package/esm/deps/jsr.io/@std/internal/1.0.5/types.js +0 -3
  141. package/esm/deps/jsr.io/@std/internal/1.0.5/types.js.map +0 -1
  142. package/esm/types/leaves.js +0 -18
  143. package/esm/types/leaves.js.map +0 -1
  144. package/src/_dnt.shims.ts +0 -60
  145. package/src/deps/jsr.io/@std/assert/1.0.8/almost_equals.ts +0 -55
  146. package/src/deps/jsr.io/@std/assert/1.0.8/array_includes.ts +0 -57
  147. package/src/deps/jsr.io/@std/assert/1.0.8/assert.ts +0 -23
  148. package/src/deps/jsr.io/@std/assert/1.0.8/assertion_error.ts +0 -31
  149. package/src/deps/jsr.io/@std/assert/1.0.8/equal.ts +0 -210
  150. package/src/deps/jsr.io/@std/assert/1.0.8/equals.ts +0 -52
  151. package/src/deps/jsr.io/@std/assert/1.0.8/exists.ts +0 -31
  152. package/src/deps/jsr.io/@std/assert/1.0.8/fail.ts +0 -21
  153. package/src/deps/jsr.io/@std/assert/1.0.8/false.ts +0 -26
  154. package/src/deps/jsr.io/@std/assert/1.0.8/greater.ts +0 -30
  155. package/src/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.ts +0 -36
  156. package/src/deps/jsr.io/@std/assert/1.0.8/instance_of.ts +0 -64
  157. package/src/deps/jsr.io/@std/assert/1.0.8/is_error.ts +0 -65
  158. package/src/deps/jsr.io/@std/assert/1.0.8/less.ts +0 -29
  159. package/src/deps/jsr.io/@std/assert/1.0.8/less_or_equal.ts +0 -36
  160. package/src/deps/jsr.io/@std/assert/1.0.8/match.ts +0 -30
  161. package/src/deps/jsr.io/@std/assert/1.0.8/mod.ts +0 -47
  162. package/src/deps/jsr.io/@std/assert/1.0.8/not_equals.ts +0 -36
  163. package/src/deps/jsr.io/@std/assert/1.0.8/not_instance_of.ts +0 -33
  164. package/src/deps/jsr.io/@std/assert/1.0.8/not_match.ts +0 -30
  165. package/src/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.ts +0 -42
  166. package/src/deps/jsr.io/@std/assert/1.0.8/object_match.ts +0 -202
  167. package/src/deps/jsr.io/@std/assert/1.0.8/rejects.ts +0 -123
  168. package/src/deps/jsr.io/@std/assert/1.0.8/strict_equals.ts +0 -67
  169. package/src/deps/jsr.io/@std/assert/1.0.8/string_includes.ts +0 -30
  170. package/src/deps/jsr.io/@std/assert/1.0.8/throws.ts +0 -111
  171. package/src/deps/jsr.io/@std/assert/1.0.8/unimplemented.ts +0 -21
  172. package/src/deps/jsr.io/@std/assert/1.0.8/unreachable.ts +0 -21
  173. package/src/deps/jsr.io/@std/internal/1.0.5/build_message.ts +0 -134
  174. package/src/deps/jsr.io/@std/internal/1.0.5/diff.ts +0 -317
  175. package/src/deps/jsr.io/@std/internal/1.0.5/diff_str.ts +0 -204
  176. package/src/deps/jsr.io/@std/internal/1.0.5/format.ts +0 -39
  177. package/src/deps/jsr.io/@std/internal/1.0.5/styles.ts +0 -233
  178. package/src/deps/jsr.io/@std/internal/1.0.5/types.ts +0 -18
  179. package/src/types/leaves.ts +0 -21
  180. package/types/ResponseFormat.d.ts +0 -26
  181. package/types/ResponseFormat.d.ts.map +0 -1
  182. package/types/Tool.d.ts.map +0 -1
  183. package/types/_dnt.shims.d.ts +0 -2
  184. package/types/_dnt.shims.d.ts.map +0 -1
  185. package/types/deps/jsr.io/@std/assert/1.0.8/almost_equals.d.ts +0 -29
  186. package/types/deps/jsr.io/@std/assert/1.0.8/almost_equals.d.ts.map +0 -1
  187. package/types/deps/jsr.io/@std/assert/1.0.8/array_includes.d.ts +0 -24
  188. package/types/deps/jsr.io/@std/assert/1.0.8/array_includes.d.ts.map +0 -1
  189. package/types/deps/jsr.io/@std/assert/1.0.8/assert.d.ts +0 -16
  190. package/types/deps/jsr.io/@std/assert/1.0.8/assert.d.ts.map +0 -1
  191. package/types/deps/jsr.io/@std/assert/1.0.8/assertion_error.d.ts +0 -26
  192. package/types/deps/jsr.io/@std/assert/1.0.8/assertion_error.d.ts.map +0 -1
  193. package/types/deps/jsr.io/@std/assert/1.0.8/equal.d.ts +0 -17
  194. package/types/deps/jsr.io/@std/assert/1.0.8/equal.d.ts.map +0 -1
  195. package/types/deps/jsr.io/@std/assert/1.0.8/equals.d.ts +0 -22
  196. package/types/deps/jsr.io/@std/assert/1.0.8/equals.d.ts.map +0 -1
  197. package/types/deps/jsr.io/@std/assert/1.0.8/exists.d.ts +0 -18
  198. package/types/deps/jsr.io/@std/assert/1.0.8/exists.d.ts.map +0 -1
  199. package/types/deps/jsr.io/@std/assert/1.0.8/fail.d.ts +0 -15
  200. package/types/deps/jsr.io/@std/assert/1.0.8/fail.d.ts.map +0 -1
  201. package/types/deps/jsr.io/@std/assert/1.0.8/false.d.ts +0 -18
  202. package/types/deps/jsr.io/@std/assert/1.0.8/false.d.ts.map +0 -1
  203. package/types/deps/jsr.io/@std/assert/1.0.8/greater.d.ts +0 -20
  204. package/types/deps/jsr.io/@std/assert/1.0.8/greater.d.ts.map +0 -1
  205. package/types/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.d.ts +0 -20
  206. package/types/deps/jsr.io/@std/assert/1.0.8/greater_or_equal.d.ts.map +0 -1
  207. package/types/deps/jsr.io/@std/assert/1.0.8/instance_of.d.ts +0 -23
  208. package/types/deps/jsr.io/@std/assert/1.0.8/instance_of.d.ts.map +0 -1
  209. package/types/deps/jsr.io/@std/assert/1.0.8/is_error.d.ts +0 -25
  210. package/types/deps/jsr.io/@std/assert/1.0.8/is_error.d.ts.map +0 -1
  211. package/types/deps/jsr.io/@std/assert/1.0.8/less.d.ts +0 -19
  212. package/types/deps/jsr.io/@std/assert/1.0.8/less.d.ts.map +0 -1
  213. package/types/deps/jsr.io/@std/assert/1.0.8/less_or_equal.d.ts +0 -20
  214. package/types/deps/jsr.io/@std/assert/1.0.8/less_or_equal.d.ts.map +0 -1
  215. package/types/deps/jsr.io/@std/assert/1.0.8/match.d.ts +0 -18
  216. package/types/deps/jsr.io/@std/assert/1.0.8/match.d.ts.map +0 -1
  217. package/types/deps/jsr.io/@std/assert/1.0.8/mod.d.ts +0 -44
  218. package/types/deps/jsr.io/@std/assert/1.0.8/mod.d.ts.map +0 -1
  219. package/types/deps/jsr.io/@std/assert/1.0.8/not_equals.d.ts +0 -21
  220. package/types/deps/jsr.io/@std/assert/1.0.8/not_equals.d.ts.map +0 -1
  221. package/types/deps/jsr.io/@std/assert/1.0.8/not_instance_of.d.ts +0 -20
  222. package/types/deps/jsr.io/@std/assert/1.0.8/not_instance_of.d.ts.map +0 -1
  223. package/types/deps/jsr.io/@std/assert/1.0.8/not_match.d.ts +0 -18
  224. package/types/deps/jsr.io/@std/assert/1.0.8/not_match.d.ts.map +0 -1
  225. package/types/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.d.ts +0 -23
  226. package/types/deps/jsr.io/@std/assert/1.0.8/not_strict_equals.d.ts.map +0 -1
  227. package/types/deps/jsr.io/@std/assert/1.0.8/object_match.d.ts +0 -28
  228. package/types/deps/jsr.io/@std/assert/1.0.8/object_match.d.ts.map +0 -1
  229. package/types/deps/jsr.io/@std/assert/1.0.8/rejects.d.ts +0 -42
  230. package/types/deps/jsr.io/@std/assert/1.0.8/rejects.d.ts.map +0 -1
  231. package/types/deps/jsr.io/@std/assert/1.0.8/strict_equals.d.ts +0 -24
  232. package/types/deps/jsr.io/@std/assert/1.0.8/strict_equals.d.ts.map +0 -1
  233. package/types/deps/jsr.io/@std/assert/1.0.8/string_includes.d.ts +0 -18
  234. package/types/deps/jsr.io/@std/assert/1.0.8/string_includes.d.ts.map +0 -1
  235. package/types/deps/jsr.io/@std/assert/1.0.8/throws.d.ts +0 -45
  236. package/types/deps/jsr.io/@std/assert/1.0.8/throws.d.ts.map +0 -1
  237. package/types/deps/jsr.io/@std/assert/1.0.8/unimplemented.d.ts +0 -15
  238. package/types/deps/jsr.io/@std/assert/1.0.8/unimplemented.d.ts.map +0 -1
  239. package/types/deps/jsr.io/@std/assert/1.0.8/unreachable.d.ts +0 -15
  240. package/types/deps/jsr.io/@std/assert/1.0.8/unreachable.d.ts.map +0 -1
  241. package/types/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts +0 -82
  242. package/types/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts.map +0 -1
  243. package/types/deps/jsr.io/@std/internal/1.0.5/diff.d.ts +0 -140
  244. package/types/deps/jsr.io/@std/internal/1.0.5/diff.d.ts.map +0 -1
  245. package/types/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts +0 -99
  246. package/types/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts.map +0 -1
  247. package/types/deps/jsr.io/@std/internal/1.0.5/format.d.ts +0 -2
  248. package/types/deps/jsr.io/@std/internal/1.0.5/format.d.ts.map +0 -1
  249. package/types/deps/jsr.io/@std/internal/1.0.5/styles.d.ts +0 -159
  250. package/types/deps/jsr.io/@std/internal/1.0.5/styles.d.ts.map +0 -1
  251. package/types/deps/jsr.io/@std/internal/1.0.5/types.d.ts +0 -16
  252. package/types/deps/jsr.io/@std/internal/1.0.5/types.d.ts.map +0 -1
  253. package/types/types/Ref.d.ts.map +0 -1
  254. package/types/types/RootTy.d.ts +0 -8
  255. package/types/types/RootTy.d.ts.map +0 -1
  256. package/types/types/Ty.d.ts +0 -27
  257. package/types/types/Ty.d.ts.map +0 -1
  258. package/types/types/leaves.d.ts.map +0 -1
  259. package/types/types/mod.d.ts.map +0 -1
  260. package/types/types/std/Wrapper.d.ts.map +0 -1
  261. /package/{types → esm}/_dnt.polyfills.d.ts +0 -0
  262. /package/{types → esm}/_dnt.polyfills.d.ts.map +0 -0
  263. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/_utils.d.ts +0 -0
  264. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/_utils.d.ts.map +0 -0
  265. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.d.ts +0 -0
  266. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/aggregate_groups.d.ts.map +0 -0
  267. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/associate_by.d.ts +0 -0
  268. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/associate_by.d.ts.map +0 -0
  269. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/associate_with.d.ts +0 -0
  270. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/associate_with.d.ts.map +0 -0
  271. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/chunk.d.ts +0 -0
  272. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/chunk.d.ts.map +0 -0
  273. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/deep_merge.d.ts +0 -0
  274. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/deep_merge.d.ts.map +0 -0
  275. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/distinct.d.ts +0 -0
  276. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/distinct.d.ts.map +0 -0
  277. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/distinct_by.d.ts +0 -0
  278. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/distinct_by.d.ts.map +0 -0
  279. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/drop_last_while.d.ts +0 -0
  280. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/drop_last_while.d.ts.map +0 -0
  281. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/drop_while.d.ts +0 -0
  282. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/drop_while.d.ts.map +0 -0
  283. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/filter_entries.d.ts +0 -0
  284. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/filter_entries.d.ts.map +0 -0
  285. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/filter_keys.d.ts +0 -0
  286. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/filter_keys.d.ts.map +0 -0
  287. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/filter_values.d.ts +0 -0
  288. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/filter_values.d.ts.map +0 -0
  289. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/find_single.d.ts +0 -0
  290. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/find_single.d.ts.map +0 -0
  291. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.d.ts +0 -0
  292. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/first_not_nullish_of.d.ts.map +0 -0
  293. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/includes_value.d.ts +0 -0
  294. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/includes_value.d.ts.map +0 -0
  295. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/intersect.d.ts +0 -0
  296. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/intersect.d.ts.map +0 -0
  297. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/invert.d.ts +0 -0
  298. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/invert.d.ts.map +0 -0
  299. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/invert_by.d.ts +0 -0
  300. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/invert_by.d.ts.map +0 -0
  301. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/join_to_string.d.ts +0 -0
  302. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/join_to_string.d.ts.map +0 -0
  303. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/map_entries.d.ts +0 -0
  304. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/map_entries.d.ts.map +0 -0
  305. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/map_keys.d.ts +0 -0
  306. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/map_keys.d.ts.map +0 -0
  307. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.d.ts +0 -0
  308. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/map_not_nullish.d.ts.map +0 -0
  309. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/map_values.d.ts +0 -0
  310. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/map_values.d.ts.map +0 -0
  311. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/max_by.d.ts +0 -0
  312. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/max_by.d.ts.map +0 -0
  313. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/max_of.d.ts +0 -0
  314. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/max_of.d.ts.map +0 -0
  315. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/max_with.d.ts +0 -0
  316. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/max_with.d.ts.map +0 -0
  317. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/min_by.d.ts +0 -0
  318. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/min_by.d.ts.map +0 -0
  319. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/min_of.d.ts +0 -0
  320. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/min_of.d.ts.map +0 -0
  321. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/min_with.d.ts +0 -0
  322. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/min_with.d.ts.map +0 -0
  323. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/mod.d.ts +0 -0
  324. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/mod.d.ts.map +0 -0
  325. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/omit.d.ts +0 -0
  326. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/omit.d.ts.map +0 -0
  327. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/partition.d.ts +0 -0
  328. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/partition.d.ts.map +0 -0
  329. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/partition_entries.d.ts +0 -0
  330. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/partition_entries.d.ts.map +0 -0
  331. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/permutations.d.ts +0 -0
  332. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/permutations.d.ts.map +0 -0
  333. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/pick.d.ts +0 -0
  334. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/pick.d.ts.map +0 -0
  335. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/reduce_groups.d.ts +0 -0
  336. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/reduce_groups.d.ts.map +0 -0
  337. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/running_reduce.d.ts +0 -0
  338. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/running_reduce.d.ts.map +0 -0
  339. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/sample.d.ts +0 -0
  340. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/sample.d.ts.map +0 -0
  341. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/sliding_windows.d.ts +0 -0
  342. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/sliding_windows.d.ts.map +0 -0
  343. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/sort_by.d.ts +0 -0
  344. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/sort_by.d.ts.map +0 -0
  345. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/sum_of.d.ts +0 -0
  346. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/sum_of.d.ts.map +0 -0
  347. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/take_last_while.d.ts +0 -0
  348. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/take_last_while.d.ts.map +0 -0
  349. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/take_while.d.ts +0 -0
  350. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/take_while.d.ts.map +0 -0
  351. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/union.d.ts +0 -0
  352. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/union.d.ts.map +0 -0
  353. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/unzip.d.ts +0 -0
  354. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/unzip.d.ts.map +0 -0
  355. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/without_all.d.ts +0 -0
  356. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/without_all.d.ts.map +0 -0
  357. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/zip.d.ts +0 -0
  358. /package/{types → esm}/deps/jsr.io/@std/collections/1.0.9/zip.d.ts.map +0 -0
  359. /package/{types → esm}/mod.d.ts +0 -0
  360. /package/{types → esm}/mod.d.ts.map +0 -0
  361. /package/{types → esm}/types/Ref.d.ts +0 -0
  362. /package/{types → esm}/types/constant.d.ts +0 -0
  363. /package/{types → esm}/types/constantUnion.d.ts +0 -0
  364. /package/{types → esm}/types/std/Option.d.ts +0 -0
  365. /package/{types → esm}/types/std/Option.d.ts.map +0 -0
  366. /package/{types → esm}/types/std/mod.d.ts +0 -0
  367. /package/{types → esm}/types/std/mod.d.ts.map +0 -0
  368. /package/{types → esm}/util/phantoms.d.ts +0 -0
  369. /package/{types → esm}/util/phantoms.d.ts.map +0 -0
  370. /package/{types → esm}/util/recombineTaggedTemplateArgs.d.ts +0 -0
  371. /package/{types → esm}/util/recombineTaggedTemplateArgs.d.ts.map +0 -0
@@ -0,0 +1,14 @@
1
+ import { Ty } from "./Ty.js";
2
+ export const none = Ty(() => ({
3
+ type: "null",
4
+ }));
5
+ export const boolean = Ty(() => ({
6
+ type: "boolean",
7
+ }));
8
+ export const number = Ty(() => ({
9
+ type: "number",
10
+ }));
11
+ export const string = Ty(() => ({
12
+ type: "string",
13
+ }));
14
+ //# sourceMappingURL=primitives.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/types/primitives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,CAAC,MAAM,IAAI,GAAoB,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IAC7C,IAAI,EAAE,MAAM;CACb,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,OAAO,GAAuB,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACnD,IAAI,EAAE,SAAS;CAChB,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,MAAM,GAAsB,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACjD,IAAI,EAAE,QAAQ;CACf,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,MAAM,GAAsB,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACjD,IAAI,EAAE,QAAQ;CACf,CAAC,CAAC,CAAA"}
@@ -1,4 +1,4 @@
1
- import { none } from "../leaves.js";
1
+ import { none } from "../primitives.js";
2
2
  import { taggedUnion } from "../taggedUnion.js";
3
3
  export function option(Some) {
4
4
  return taggedUnion({
@@ -1 +1 @@
1
- {"version":3,"file":"Option.js","sourceRoot":"","sources":["../../../src/types/std/Option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,MAAM,UAAU,MAAM,CAAe,IAAO;IAM1C,OAAO,WAAW,CAAC;QACjB,IAAI;QACJ,IAAI,EAAE,IAAI;KACX,CAAC,CAAA,uCAAuC,CAAA;AAC3C,CAAC"}
1
+ {"version":3,"file":"Option.js","sourceRoot":"","sources":["../../../src/types/std/Option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,MAAM,UAAU,MAAM,CAAe,IAAO;IAM1C,OAAO,WAAW,CAAC;QACjB,IAAI;QACJ,IAAI,EAAE,IAAI;KACX,CAAC,CAAA,uCAAuC,CAAA;AAC3C,CAAC"}
@@ -1,6 +1,5 @@
1
1
  import type { Ty } from "../mod.js";
2
2
  import { object } from "../object.js";
3
- export type Wrapper<X extends Ty = Ty> = ReturnType<typeof Wrapper<X>>;
4
3
  export declare function Wrapper<X extends Ty>(value: X): ReturnType<typeof object<{
5
4
  value: X;
6
5
  }>>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../../src/types/std/Wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,wBAAgB,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC;IAAE,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC,CAEvF"}
@@ -1 +1 @@
1
- {"version":3,"file":"Wrapper.js","sourceRoot":"","sources":["../../../src/types/std/Wrapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAIrC,MAAM,UAAU,OAAO,CAAe,KAAQ;IAC5C,OAAO,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AAC1B,CAAC"}
1
+ {"version":3,"file":"Wrapper.js","sourceRoot":"","sources":["../../../src/types/std/Wrapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,MAAM,UAAU,OAAO,CAAe,KAAQ;IAC5C,OAAO,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AAC1B,CAAC"}
@@ -2,7 +2,7 @@ import { Ty } from "./Ty.js";
2
2
  export declare function taggedUnion<M extends Record<string, Ty>>(members: M): Ty<{
3
3
  [K in keyof M]: {
4
4
  type: K;
5
- value: M[K][Ty.T];
5
+ value: M[K]["T"];
6
6
  };
7
- }[keyof M], M[keyof M][Ty.P]>;
7
+ }[keyof M], M[keyof M]["P"]>;
8
8
  //# sourceMappingURL=taggedUnion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"taggedUnion.d.ts","sourceRoot":"","sources":["../../src/types/taggedUnion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,CACvE;KACG,CAAC,IAAI,MAAM,CAAC,GAAG;QACd,IAAI,EAAE,CAAC,CAAA;QACP,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;KAClB;CACF,CAAC,MAAM,CAAC,CAAC,EACV,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CACjB,CAiBA"}
1
+ {"version":3,"file":"taggedUnion.d.ts","sourceRoot":"","sources":["../../src/types/taggedUnion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,CACvE;KACG,CAAC,IAAI,MAAM,CAAC,GAAG;QACd,IAAI,EAAE,CAAC,CAAA;QACP,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;KACjB;CACF,CAAC,MAAM,CAAC,CAAC,EACV,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAChB,CAgBA"}
@@ -1,7 +1,6 @@
1
1
  import { Ty } from "./Ty.js";
2
2
  export function taggedUnion(members) {
3
- return Ty((description, ref) => ({
4
- description,
3
+ return Ty((ref) => ({
5
4
  discriminator: "type",
6
5
  anyOf: Object.entries(members).map(([k, v]) => ({
7
6
  type: "object",
@@ -1 +1 @@
1
- {"version":3,"file":"taggedUnion.js","sourceRoot":"","sources":["../../src/types/taggedUnion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,UAAU,WAAW,CAA+B,OAAU;IASlE,OAAO,EAAE,CAAC,CAAC,WAAW,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAC/B,WAAW;QACX,aAAa,EAAE,MAAM;QACrB,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC9C,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,KAAK,EAAE,CAAC;iBACT;gBACD,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;aACd;YACD,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;YAC3B,oBAAoB,EAAE,KAAK;SAC5B,CAAC,CAAC;KACJ,CAAC,CAAC,CAAA;AACL,CAAC"}
1
+ {"version":3,"file":"taggedUnion.js","sourceRoot":"","sources":["../../src/types/taggedUnion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,UAAU,WAAW,CAA+B,OAAU;IASlE,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAClB,aAAa,EAAE,MAAM;QACrB,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC9C,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,KAAK,EAAE,CAAC;iBACT;gBACD,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;aACd;YACD,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;YAC3B,oBAAoB,EAAE,KAAK;SAC5B,CAAC,CAAC;KACJ,CAAC,CAAC,CAAA;AACL,CAAC"}
package/package.json CHANGED
@@ -1,23 +1,18 @@
1
1
  {
2
2
  "name": "structured-outputs",
3
- "version": "0.1.0-beta.20",
4
- "description": "Compose OpenAI structured output schemas.",
3
+ "version": "0.1.0-beta.22",
4
+ "description": "A library for working with OpenAI's structured outputs.",
5
5
  "repository": "github:harrysolovay/structured-outputs.git",
6
6
  "license": "Apache-2.0",
7
7
  "main": "./esm/mod.js",
8
8
  "module": "./esm/mod.js",
9
- "types": "./types/mod.d.ts",
10
9
  "exports": {
11
10
  ".": {
12
- "import": {
13
- "types": "./types/mod.d.ts",
14
- "default": "./esm/mod.js"
15
- }
11
+ "import": "./esm/mod.js"
16
12
  }
17
13
  },
18
- "dependencies": {
19
- "tslib": "^2.6.2",
14
+ "_generatedBy": "dnt@dev",
15
+ "peerDependencies": {
20
16
  "openai": "^4.68.1"
21
- },
22
- "_generatedBy": "dnt@dev"
17
+ }
23
18
  }
@@ -1,9 +1,18 @@
1
- import { assert } from "./deps/jsr.io/@std/assert/1.0.8/mod.js"
2
- import type Openai from "openai"
3
- import type { ResponseFormatJSONSchema } from "openai/resources/index.js"
1
+ import type { ChatCompletion, ChatCompletionChoice, JsonSchema } from "./oai.js"
4
2
  import type { RootTy } from "./types/mod.js"
5
3
  import { recombineTaggedTemplateArgs } from "./util/recombineTaggedTemplateArgs.js"
6
4
 
5
+ export interface ResponseFormat<T> {
6
+ (template: TemplateStringsArray, ...quasis: Array<string>): ResponseFormat<T>
7
+ type: "json_schema"
8
+ /** The desired return type in JSON Schema. */
9
+ json_schema: JsonSchema
10
+ /** Parse the content of the first choice into a typed object. */
11
+ parseFirstChoice(completion: ChatCompletion): T
12
+ /** Parse all choice contents into an array of typed object. */
13
+ parseChoices(completion: ChatCompletion): Array<T>
14
+ }
15
+
7
16
  export function ResponseFormat<T>(name: string, ty: RootTy<T, never>): ResponseFormat<T> {
8
17
  return ResponseFormat_(name, ty)
9
18
  }
@@ -28,25 +37,11 @@ function ResponseFormat_<T>(
28
37
  schema: ty.schema(),
29
38
  strict: true,
30
39
  },
31
- parse(completion: ChatCompletion): TypedChatCompletion<T> {
32
- return {
33
- ...completion,
34
- choices: completion.choices.map((choice) => ({
35
- ...choice,
36
- message: {
37
- ...choice.message,
38
- content: choice.message.content ? JSON.parse(choice.message.content) : null,
39
- },
40
- })),
41
- }
40
+ parseFirstChoice: (completion: ChatCompletion): T => {
41
+ return JSON.parse(ResponseFormat.unwrapFirstChoice(completion))
42
42
  },
43
- parseFirstOrThrow(completion: ChatCompletion): T {
44
- const { choices: [firstChoice], usage } = completion
45
- assert(firstChoice)
46
- const { finish_reason, message } = firstChoice
47
- const { content, refusal } = message
48
- assert(content, JSON.stringify({ finish_reason, refusal, usage }))
49
- return JSON.parse(content)
43
+ parseChoices: (completion: ChatCompletion): Array<T> => {
44
+ return ResponseFormat.unwrapChoices(completion).map((content) => JSON.parse(content))
50
45
  },
51
46
  toJSON() {
52
47
  const { type, json_schema } = this
@@ -56,27 +51,39 @@ function ResponseFormat_<T>(
56
51
  )
57
52
  }
58
53
 
59
- export interface ResponseFormat<T> {
60
- (template: TemplateStringsArray, ...quasis: Array<string>): ResponseFormat<T>
61
- type: "json_schema"
62
- /** The desired return type in JSON Schema. */
63
- json_schema: ResponseFormatJSONSchema.JSONSchema
64
- /** Parse inner responses into a typed object. */
65
- parse(completion: ChatCompletion): TypedChatCompletion<T>
66
- /** Parse and return the first inner response into a typed object. */
67
- parseFirstOrThrow(completion: ChatCompletion): T
68
- }
54
+ export namespace ResponseFormat {
55
+ export function unwrapFirstChoice(completion: ChatCompletion): string {
56
+ const { choices: [firstChoice] } = completion
57
+ if (!firstChoice) {
58
+ throw new ResponseFormatUnwrapError("No choices contained within the completion response.")
59
+ }
60
+ return unwrapChoice(firstChoice)
61
+ }
69
62
 
70
- export type TypedChatCompletion<T> = Omit<ChatCompletion, "choices"> & {
71
- choices: Array<
72
- Omit<ChatCompletionChoice, "message"> & {
73
- message: Omit<ChatCompletionMessage, "content"> & {
74
- content: T
75
- }
63
+ export function unwrapChoices(completions: ChatCompletion): string[] {
64
+ return completions.choices.map(unwrapChoice)
65
+ }
66
+
67
+ function unwrapChoice(choice: ChatCompletionChoice) {
68
+ const { finish_reason, message } = choice
69
+ if (finish_reason !== "stop") {
70
+ throw new ResponseFormatUnwrapError(
71
+ `Completion responded with "${finish_reason}" as finish reason; ${message}`,
72
+ )
73
+ }
74
+ const { content, refusal } = message
75
+ if (refusal) {
76
+ throw new ResponseFormatUnwrapError(
77
+ `Openai refused to fulfill completion request; ${refusal}`,
78
+ )
76
79
  }
77
- >
80
+ if (!content) {
81
+ throw new ResponseFormatUnwrapError("First response choice contained no content.")
82
+ }
83
+ return content
84
+ }
78
85
  }
79
86
 
80
- type ChatCompletion = Openai.Chat.ChatCompletion
81
- type ChatCompletionChoice = Openai.Chat.ChatCompletion.Choice
82
- type ChatCompletionMessage = Openai.Chat.Completions.ChatCompletionMessage
87
+ export class ResponseFormatUnwrapError extends Error {
88
+ override readonly name = "UnwrapResponseError"
89
+ }
package/src/Tool.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { RootTy, Schema } from "./types/mod.js"
2
2
  import { recombineTaggedTemplateArgs } from "./util/recombineTaggedTemplateArgs.js"
3
3
 
4
+ /** @experimental */
4
5
  export function Tool<T>(name: string, ty: RootTy<T, never>): Tool<T> {
5
6
  return Tool_(name, ty)
6
7
  }
package/src/oai.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type Openai from "openai"
2
+
3
+ export type JsonSchema = Openai.ResponseFormatJSONSchema["json_schema"]
4
+ export type ChatCompletion = Openai.Chat.ChatCompletion
5
+ export type ChatCompletionChoice = Openai.Chat.Completions.ChatCompletion.Choice
package/src/types/Ref.ts CHANGED
@@ -1,16 +1,19 @@
1
- import type { Applied, Schema, Ty } from "./Ty.js"
2
1
  import { recombineTaggedTemplateArgs } from "../util/recombineTaggedTemplateArgs.js"
2
+ import type { Applied, Schema, Ty } from "./Ty.js"
3
3
 
4
4
  export type Ref = (ty: Ty) => Schema
5
5
 
6
6
  export function Ref(applied: Applied): Ref {
7
7
  return (ty) => {
8
- applied = { ...applied, ...ty.applied }
9
- const description = ty.descriptions
8
+ applied = { ...applied, ...ty[""].applied }
9
+ const description = ty[""].context
10
10
  .map(({ template, placeheld }) =>
11
11
  recombineTaggedTemplateArgs(template, placeheld.map((k) => applied[k]!))
12
12
  )
13
13
  .join(" ")
14
- return ty.toSchema(description, Ref(applied))
14
+ return {
15
+ ...ty[""].toSchema(Ref(applied)),
16
+ ...description ? { description } : {},
17
+ }
15
18
  }
16
19
  }
@@ -1,22 +1,20 @@
1
1
  import { phantoms } from "../util/phantoms.js"
2
2
  import { Ref } from "./Ref.js"
3
- import type { Applied, Description, Schema, ToSchema, Ty } from "./Ty.js"
3
+ import type { Applied, Context, Schema, ToSchema, Ty } from "./Ty.js"
4
4
 
5
- export function RootTy<T, P extends string = never>(
5
+ export function RootTy<T, P extends keyof any = never>(
6
6
  toSchema: ToSchema,
7
- descriptions: Array<Description> = [],
7
+ context: Array<Context> = [],
8
8
  applied: Applied = {},
9
9
  ): RootTy<T, P> {
10
10
  return Object.assign(
11
11
  <P2 extends Array<string>>(template: TemplateStringsArray, ...placeheld: P2) =>
12
- RootTy<T, P | P2[number]>(toSchema, [{ template, placeheld }, ...descriptions], applied),
13
- phantoms<{ [Ty.T]: T; [Ty.P]: P }>(),
12
+ RootTy<T, P | P2[number]>(toSchema, [{ template, placeheld }, ...context], applied),
13
+ phantoms<{ T: T; P: P }>(),
14
14
  {
15
- toSchema,
16
- descriptions,
17
- applied,
18
- apply: <A extends Partial<Record<P, string | number>>>(values: A) => {
19
- return RootTy<T, Exclude<P, keyof A>>(toSchema, descriptions, { ...applied, ...values })
15
+ "": { toSchema, context, applied },
16
+ fill: <A extends Partial<Record<P, string | number>>>(values: A) => {
17
+ return RootTy<T, Exclude<P, keyof A>>(toSchema, context, { ...applied, ...values })
20
18
  },
21
19
  schema(this: RootTy<T, never>) {
22
20
  return Ref({})(this)
@@ -28,12 +26,12 @@ export function RootTy<T, P extends string = never>(
28
26
  )
29
27
  }
30
28
 
31
- export interface RootTy<T = any, P extends string = string> extends Ty<T, P> {
32
- <P2 extends Array<string>>(
29
+ export interface RootTy<T = any, P extends keyof any = keyof any> extends Ty<T, P> {
30
+ <P2 extends Array<keyof any>>(
33
31
  template: TemplateStringsArray,
34
32
  ...placeheld: P2
35
33
  ): RootTy<T, P | P2[number]>
36
- apply: <A extends Partial<Record<P, number | string>>>(
34
+ fill: <A extends Partial<Record<P, number | string>>>(
37
35
  values: A,
38
36
  ) => RootTy<T, Exclude<P, keyof A>>
39
37
  schema(this: RootTy<T, never>): Schema
package/src/types/Ty.ts CHANGED
@@ -1,22 +1,20 @@
1
- import type { Ref } from "./Ref.js"
2
1
  import { phantoms } from "../util/phantoms.js"
2
+ import type { Ref } from "./Ref.js"
3
3
  import type { RootTy } from "./RootTy.js"
4
4
 
5
- export function Ty<T, P extends string = never>(
5
+ export function Ty<T, P extends keyof any = never>(
6
6
  toSchema: ToSchema,
7
- descriptions: Array<Description> = [],
7
+ context: Array<Context> = [],
8
8
  applied: Applied = {},
9
9
  ): Ty<T, P> {
10
10
  return Object.assign(
11
- <P2 extends Array<string>>(template: TemplateStringsArray, ...placeheld: P2) =>
12
- Ty<T, P | P2[number]>(toSchema, [{ template, placeheld }, ...descriptions], applied),
13
- phantoms<{ [Ty.T]: T; [Ty.P]: P }>(),
11
+ <P2 extends Array<keyof any>>(template: TemplateStringsArray, ...placeheld: P2) =>
12
+ Ty<T, P | P2[number]>(toSchema, [{ template, placeheld }, ...context], applied),
13
+ phantoms<{ T: T; P: P }>(),
14
14
  {
15
- toSchema,
16
- descriptions,
17
- applied,
18
- apply: <A extends Partial<Record<P, string | number>>>(values: A) => {
19
- return Ty<T, Exclude<P, keyof A>>(toSchema, descriptions, { ...applied, ...values })
15
+ "": { toSchema, context, applied },
16
+ fill: <A extends Partial<Record<P, string | number>>>(values: A) => {
17
+ return Ty<T, Exclude<P, keyof A>>(toSchema, context, { ...applied, ...values })
20
18
  },
21
19
  isRoot(): this is RootTy {
22
20
  return false
@@ -25,33 +23,28 @@ export function Ty<T, P extends string = never>(
25
23
  )
26
24
  }
27
25
 
28
- export interface Ty<T = any, P extends string = string> {
29
- <P2 extends Array<string>>(
26
+ export interface Ty<T = any, P extends keyof any = keyof any> {
27
+ <P2 extends Array<keyof any>>(
30
28
  template: TemplateStringsArray,
31
29
  ...placeheld: P2
32
30
  ): Ty<T, P | P2[number]>
33
- [Ty.T]: T
34
- [Ty.P]: P
35
- toSchema: ToSchema
36
- descriptions: Array<Description>
37
- applied: Applied
38
- apply: <A extends Partial<Record<P, number | string>>>(values: A) => Ty<T, Exclude<P, keyof A>>
31
+ T: T
32
+ P: P
33
+ "": {
34
+ toSchema: ToSchema
35
+ context: Array<Context>
36
+ applied: Applied
37
+ }
38
+ fill: <A extends Partial<Record<P, number | string>>>(values: A) => Ty<T, Exclude<P, keyof A>>
39
39
  isRoot(): this is RootTy
40
40
  }
41
41
 
42
- export namespace Ty {
43
- export type T = typeof T
44
- export declare const T: unique symbol
45
- export type P = typeof P
46
- export declare const P: unique symbol
47
- }
48
-
49
- export type ToSchema = (description: string | undefined, ref: Ref) => Schema
42
+ export type ToSchema = (ref: Ref) => Schema
50
43
  export type Schema = Record<string, unknown>
51
44
 
52
- export interface Description {
45
+ export interface Context {
53
46
  template: TemplateStringsArray
54
- placeheld: Array<string>
47
+ placeheld: Array<keyof any>
55
48
  }
56
49
 
57
- export type Applied = Record<string, number | string>
50
+ export type Applied = Record<keyof any, number | string>
@@ -1,9 +1,8 @@
1
1
  import { Ty } from "./Ty.js"
2
2
 
3
- export function array<E extends Ty>(element: E): Ty<Array<E[Ty.T]>, E[Ty.P]> {
4
- return Ty((description, ref) => ({
3
+ export function array<E extends Ty>(element: E): Ty<Array<E["T"]>, E["P"]> {
4
+ return Ty((ref) => ({
5
5
  type: "array",
6
- description,
7
6
  items: ref(element),
8
7
  }))
9
8
  }
@@ -1,8 +1,7 @@
1
1
  import { Ty } from "./Ty.js"
2
2
 
3
3
  export function constant<V extends number | string>(value: V): Ty<V, never> {
4
- return Ty((description) => ({
4
+ return Ty(() => ({
5
5
  const: value,
6
- description,
7
6
  }))
8
7
  }
@@ -5,23 +5,20 @@ export function constantUnion<M extends Array<number | string>>(
5
5
  ...members: M
6
6
  ): Ty<M[number], never> {
7
7
  const [strings, numbers] = partition(members, (v) => typeof v === "string")
8
- return Ty((description) => {
9
- return {
10
- anyOf: [
11
- ...strings.length
12
- ? [{
13
- type: "string",
14
- enum: strings,
15
- }]
16
- : [],
17
- ...numbers.length
18
- ? [{
19
- type: "number",
20
- enum: numbers,
21
- }]
22
- : [],
23
- ],
24
- description,
25
- }
26
- })
8
+ return Ty(() => ({
9
+ anyOf: [
10
+ ...strings.length
11
+ ? [{
12
+ type: "string",
13
+ enum: strings,
14
+ }]
15
+ : [],
16
+ ...numbers.length
17
+ ? [{
18
+ type: "number",
19
+ enum: numbers,
20
+ }]
21
+ : [],
22
+ ],
23
+ }))
27
24
  }
package/src/types/mod.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  export * from "./array.js"
2
- export * from "./leaves.js"
3
2
  export * from "./constant.js"
4
3
  export * from "./constantUnion.js"
5
- export * from "./std/mod.js"
6
4
  export * from "./object.js"
5
+ export * from "./primitives.js"
7
6
  export * from "./Ref.js"
7
+ export * from "./RootTy.js"
8
+ export * from "./std/mod.js"
8
9
  export * from "./taggedUnion.js"
9
10
  export * from "./Ty.js"
10
- export * from "./RootTy.js"
@@ -1,13 +1,11 @@
1
1
  import { RootTy } from "./RootTy.js"
2
2
  import type { Ty } from "./Ty.js"
3
3
 
4
- export function object<F extends Record<string, Ty>>(fields: F): RootTy<
5
- { [K in keyof F]: F[K][Ty.T] },
6
- F[keyof F][Ty.P]
7
- > {
8
- return RootTy((description, ref) => ({
4
+ export function object<F extends Record<string, Ty>>(
5
+ fields: F,
6
+ ): RootTy<{ [K in keyof F]: F[K]["T"] }, F[keyof F]["P"]> {
7
+ return RootTy((ref) => ({
9
8
  type: "object",
10
- description,
11
9
  properties: Object.fromEntries(Object.entries(fields).map(([k, v]) => [k, ref(v)])),
12
10
  additionalProperties: false,
13
11
  required: Object.keys(fields),
@@ -0,0 +1,17 @@
1
+ import { Ty } from "./Ty.js"
2
+
3
+ export const none: Ty<null, never> = Ty(() => ({
4
+ type: "null",
5
+ }))
6
+
7
+ export const boolean: Ty<boolean, never> = Ty(() => ({
8
+ type: "boolean",
9
+ }))
10
+
11
+ export const number: Ty<number, never> = Ty(() => ({
12
+ type: "number",
13
+ }))
14
+
15
+ export const string: Ty<string, never> = Ty(() => ({
16
+ type: "string",
17
+ }))
@@ -1,4 +1,4 @@
1
- import { none } from "../leaves.js"
1
+ import { none } from "../primitives.js"
2
2
  import { taggedUnion } from "../taggedUnion.js"
3
3
  import type { Ty } from "../Ty.js"
4
4
 
@@ -1,8 +1,6 @@
1
1
  import type { Ty } from "../mod.js"
2
2
  import { object } from "../object.js"
3
3
 
4
- export type Wrapper<X extends Ty = Ty> = ReturnType<typeof Wrapper<X>>
5
-
6
4
  export function Wrapper<X extends Ty>(value: X): ReturnType<typeof object<{ value: X }>> {
7
5
  return object({ value })
8
6
  }
@@ -4,13 +4,12 @@ export function taggedUnion<M extends Record<string, Ty>>(members: M): Ty<
4
4
  {
5
5
  [K in keyof M]: {
6
6
  type: K
7
- value: M[K][Ty.T]
7
+ value: M[K]["T"]
8
8
  }
9
9
  }[keyof M],
10
- M[keyof M][Ty.P]
10
+ M[keyof M]["P"]
11
11
  > {
12
- return Ty((description, ref) => ({
13
- description,
12
+ return Ty((ref) => ({
14
13
  discriminator: "type",
15
14
  anyOf: Object.entries(members).map(([k, v]) => ({
16
15
  type: "object",
package/esm/_dnt.shims.js DELETED
@@ -1,58 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"_dnt.shims.js","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,EAClB,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AAEtE,SAAS,gBAAgB,CACvB,OAAU,EACV,MAAS;IAET,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE;QACxB,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS;YAC1B,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACnB,OAAQ,MAAc,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;iBAAM,CAAC;gBACN,OAAQ,OAAe,CAAC,IAAI,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;QACD,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK;YACtB,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACnB,OAAQ,MAAc,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;YACA,OAAe,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,cAAc,CAAC,OAAO,EAAE,IAAI;YAC1B,IAAI,OAAO,GAAG,KAAK,CAAC;YACpB,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACnB,OAAQ,MAAc,CAAC,IAAI,CAAC,CAAC;gBAC7B,OAAO,GAAG,IAAI,CAAC;YACjB,CAAC;YACD,IAAI,IAAI,IAAI,OAAO,EAAE,CAAC;gBACpB,OAAQ,OAAe,CAAC,IAAI,CAAC,CAAC;gBAC9B,OAAO,GAAG,IAAI,CAAC;YACjB,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,OAAO,CAAC,OAAO;YACb,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACxC,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"}