structured-outputs 0.1.0-beta.21 → 0.1.0-beta.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. package/README.md +46 -40
  2. package/esm/ResponseFormat.d.ts +8 -8
  3. package/esm/ResponseFormat.d.ts.map +1 -1
  4. package/esm/ResponseFormat.js +4 -7
  5. package/esm/ResponseFormat.js.map +1 -1
  6. package/esm/Tool.d.ts +2 -2
  7. package/esm/Tool.d.ts.map +1 -1
  8. package/esm/Tool.js +2 -2
  9. package/esm/Tool.js.map +1 -1
  10. package/esm/types/Ty.d.ts +26 -23
  11. package/esm/types/Ty.d.ts.map +1 -1
  12. package/esm/types/Ty.js +29 -12
  13. package/esm/types/Ty.js.map +1 -1
  14. package/esm/types/array.d.ts +1 -1
  15. package/esm/types/array.d.ts.map +1 -1
  16. package/esm/types/array.js +2 -3
  17. package/esm/types/array.js.map +1 -1
  18. package/esm/types/constantUnion.d.ts +1 -1
  19. package/esm/types/constantUnion.d.ts.map +1 -1
  20. package/esm/types/constantUnion.js +16 -19
  21. package/esm/types/constantUnion.js.map +1 -1
  22. package/esm/types/mod.d.ts +4 -5
  23. package/esm/types/mod.d.ts.map +1 -1
  24. package/esm/types/mod.js +4 -5
  25. package/esm/types/mod.js.map +1 -1
  26. package/esm/types/object.d.ts +4 -5
  27. package/esm/types/object.d.ts.map +1 -1
  28. package/esm/types/object.js +3 -4
  29. package/esm/types/object.js.map +1 -1
  30. package/esm/types/primitives.d.ts +6 -0
  31. package/esm/types/primitives.d.ts.map +1 -0
  32. package/esm/types/primitives.js +14 -0
  33. package/esm/types/primitives.js.map +1 -0
  34. package/esm/types/std/Date.d.ts +4 -0
  35. package/esm/types/std/Date.d.ts.map +1 -0
  36. package/esm/types/std/Date.js +14 -0
  37. package/esm/types/std/Date.js.map +1 -0
  38. package/esm/types/std/Option.d.ts +3 -2
  39. package/esm/types/std/Option.d.ts.map +1 -1
  40. package/esm/types/std/Option.js +2 -2
  41. package/esm/types/std/Option.js.map +1 -1
  42. package/esm/types/std/Wrapper.d.ts +0 -1
  43. package/esm/types/std/Wrapper.d.ts.map +1 -1
  44. package/esm/types/std/Wrapper.js.map +1 -1
  45. package/esm/types/std/color.d.ts +8 -0
  46. package/esm/types/std/color.d.ts.map +1 -0
  47. package/esm/types/std/color.js +13 -0
  48. package/esm/types/std/color.js.map +1 -0
  49. package/esm/types/std/mod.d.ts +2 -0
  50. package/esm/types/std/mod.d.ts.map +1 -1
  51. package/esm/types/std/mod.js +2 -0
  52. package/esm/types/std/mod.js.map +1 -1
  53. package/esm/types/taggedUnion.d.ts +2 -2
  54. package/esm/types/taggedUnion.d.ts.map +1 -1
  55. package/esm/types/taggedUnion.js +20 -15
  56. package/esm/types/taggedUnion.js.map +1 -1
  57. package/esm/types/transform.d.ts +3 -0
  58. package/esm/types/transform.d.ts.map +1 -0
  59. package/esm/types/transform.js +5 -0
  60. package/esm/types/transform.js.map +1 -0
  61. package/esm/types/tuple.d.ts +5 -0
  62. package/esm/types/tuple.d.ts.map +1 -0
  63. package/esm/types/tuple.js +11 -0
  64. package/esm/types/tuple.js.map +1 -0
  65. package/esm/util/recombine.d.ts +2 -0
  66. package/esm/util/recombine.d.ts.map +1 -0
  67. package/esm/util/recombine.js +4 -0
  68. package/esm/util/recombine.js.map +1 -0
  69. package/package.json +2 -2
  70. package/src/ResponseFormat.ts +14 -17
  71. package/src/Tool.ts +5 -5
  72. package/src/types/Ty.ts +75 -41
  73. package/src/types/array.ts +9 -6
  74. package/src/types/constantUnion.ts +17 -20
  75. package/src/types/mod.ts +4 -5
  76. package/src/types/object.ts +17 -13
  77. package/src/types/primitives.ts +17 -0
  78. package/src/types/std/Date.ts +19 -0
  79. package/src/types/std/Option.ts +3 -3
  80. package/src/types/std/Wrapper.ts +0 -2
  81. package/src/types/std/color.ts +27 -0
  82. package/src/types/std/mod.ts +2 -0
  83. package/src/types/taggedUnion.ts +29 -17
  84. package/src/types/transform.ts +8 -0
  85. package/src/types/tuple.ts +17 -0
  86. package/src/util/recombine.ts +3 -0
  87. package/esm/oai.d.ts +0 -5
  88. package/esm/oai.d.ts.map +0 -1
  89. package/esm/oai.js +0 -2
  90. package/esm/oai.js.map +0 -1
  91. package/esm/types/Ref.d.ts +0 -4
  92. package/esm/types/Ref.d.ts.map +0 -1
  93. package/esm/types/Ref.js +0 -11
  94. package/esm/types/Ref.js.map +0 -1
  95. package/esm/types/RootTy.d.ts +0 -8
  96. package/esm/types/RootTy.d.ts.map +0 -1
  97. package/esm/types/RootTy.js +0 -19
  98. package/esm/types/RootTy.js.map +0 -1
  99. package/esm/types/constant.d.ts +0 -3
  100. package/esm/types/constant.d.ts.map +0 -1
  101. package/esm/types/constant.js +0 -8
  102. package/esm/types/constant.js.map +0 -1
  103. package/esm/types/leaves.d.ts +0 -6
  104. package/esm/types/leaves.d.ts.map +0 -1
  105. package/esm/types/leaves.js +0 -18
  106. package/esm/types/leaves.js.map +0 -1
  107. package/esm/util/phantoms.d.ts +0 -2
  108. package/esm/util/phantoms.d.ts.map +0 -1
  109. package/esm/util/phantoms.js +0 -4
  110. package/esm/util/phantoms.js.map +0 -1
  111. package/esm/util/recombineTaggedTemplateArgs.d.ts +0 -2
  112. package/esm/util/recombineTaggedTemplateArgs.d.ts.map +0 -1
  113. package/esm/util/recombineTaggedTemplateArgs.js +0 -4
  114. package/esm/util/recombineTaggedTemplateArgs.js.map +0 -1
  115. package/src/oai.ts +0 -5
  116. package/src/types/Ref.ts +0 -16
  117. package/src/types/RootTy.ts +0 -40
  118. package/src/types/constant.ts +0 -8
  119. package/src/types/leaves.ts +0 -21
  120. package/src/util/phantoms.ts +0 -3
  121. package/src/util/recombineTaggedTemplateArgs.ts +0 -6
@@ -0,0 +1,19 @@
1
+ import { object } from "../object.js"
2
+ import { number } from "../primitives.js"
3
+ import { transform } from "../transform.js"
4
+ import type { Ty } from "../Ty.js"
5
+
6
+ export { Date_ as Date }
7
+ const Date_: Ty<Date, never, true> = transform(
8
+ object({
9
+ year: number,
10
+ month: number`Zero-based (0 for January, 11 for December).`,
11
+ day: number`Day of the month (1-31). Ensure within available range for the specified month.`,
12
+ hour: number`Zero-based (0-23)`,
13
+ minute: number`Zero-based (0-59)`,
14
+ second: number`Zero-based (0-59)`,
15
+ millisecond: number`Zero-based (0-999)`,
16
+ }),
17
+ ({ year, month, day, hour, minute, second, millisecond }) =>
18
+ new Date(year, month, day, hour, minute, second, millisecond),
19
+ )
@@ -1,11 +1,11 @@
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
 
5
- export function option<S extends Ty>(Some: S): ReturnType<
5
+ export function Option<S extends Ty>(Some: S): ReturnType<
6
6
  typeof taggedUnion<{
7
7
  Some: S
8
- None: Ty<null, never>
8
+ None: typeof none
9
9
  }>
10
10
  > {
11
11
  return taggedUnion({
@@ -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
  }
@@ -0,0 +1,27 @@
1
+ import { object } from "../object.js"
2
+ import { number } from "../primitives.js"
3
+ import { transform } from "../transform.js"
4
+ import type { Ty } from "../Ty.js"
5
+
6
+ export const Rgb: Ty<
7
+ {
8
+ r: number
9
+ g: number
10
+ b: number
11
+ },
12
+ never,
13
+ true
14
+ > = object({
15
+ r: number`Between 0 and 255`,
16
+ g: number`Between 0 and 255`,
17
+ b: number`Between 0 and 255`,
18
+ })
19
+
20
+ export const Hex: Ty<string, never, true> = transform(
21
+ Rgb,
22
+ ({ r, g, b }) => `${toHex(r)}${toHex(g)}${toHex(b)}"`,
23
+ )
24
+
25
+ function toHex(value: number): string {
26
+ return value.toString(16).padStart(2, "0")
27
+ }
@@ -1,2 +1,4 @@
1
+ export * from "./color.js"
2
+ export * from "./Date.js"
1
3
  export * from "./Option.js"
2
4
  export * from "./Wrapper.js"
@@ -1,28 +1,40 @@
1
- import { Ty } from "./Ty.js"
1
+ import { type Schema, Ty } from "./Ty.js"
2
2
 
3
3
  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
+ false
11
12
  > {
12
- return Ty((description, ref) => ({
13
- description,
14
- discriminator: "type",
15
- anyOf: Object.entries(members).map(([k, v]) => ({
16
- type: "object",
17
- properties: {
18
- type: {
19
- type: "string",
20
- const: k,
13
+ const entries = Object.entries(members)
14
+ return Ty(
15
+ (subschema) =>
16
+ entries.length === 1
17
+ ? variant(entries[0]![0], subschema(entries[0]![1]))
18
+ : {
19
+ discriminator: "type",
20
+ anyOf: entries.map(([k, v]) => variant(k, subschema(v))),
21
21
  },
22
- value: ref(v),
22
+ false,
23
+ (v) => members[v.type]![""].transform(v),
24
+ )
25
+ }
26
+
27
+ function variant(type: string, value: Schema) {
28
+ return {
29
+ type: "object",
30
+ properties: {
31
+ type: {
32
+ type: "string",
33
+ const: type,
23
34
  },
24
- required: ["type", "value"],
25
- additionalProperties: false,
26
- })),
27
- }))
35
+ value,
36
+ },
37
+ required: ["type", "value"],
38
+ additionalProperties: false,
39
+ }
28
40
  }
@@ -0,0 +1,8 @@
1
+ import { Ty } from "./Ty.js"
2
+
3
+ export function transform<T, P extends keyof any, R extends boolean, I>(
4
+ ty: Ty<I, P, R>,
5
+ transform: (value: I) => T,
6
+ ): Ty<T, P, R> {
7
+ return Ty<T, P, R, I>((ref) => ref(ty), ty[""].root, (value) => transform(value))
8
+ }
@@ -0,0 +1,17 @@
1
+ import { Ty } from "./Ty.js"
2
+
3
+ export function tuple<F extends Ty[]>(
4
+ ...elements: F
5
+ ): Ty<{ [K in keyof F]: F[K]["T"] }, F[number]["P"], true> {
6
+ const { length } = elements
7
+ return Ty(
8
+ (ref) => ({
9
+ type: "object",
10
+ properties: Object.fromEntries(Array.from({ length }, (_0, i) => [i, ref(elements[i]!)])),
11
+ additionalProperties: false,
12
+ required: Object.keys(Array.from({ length }, (_0, i) => i)),
13
+ }),
14
+ true,
15
+ (v) => Array.from({ length }, (_0, i) => elements[i]![""].transform(v[i])) as never,
16
+ )
17
+ }
@@ -0,0 +1,3 @@
1
+ export function recombine(strings: TemplateStringsArray, values: Array<number | string>): string {
2
+ return strings.reduce((acc, cur, i) => `${acc}${cur}${values[i] ?? ""}`, "")
3
+ }
package/esm/oai.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import type Openai from "openai";
2
- export type JsonSchema = Openai.ResponseFormatJSONSchema["json_schema"];
3
- export type ChatCompletion = Openai.Chat.ChatCompletion;
4
- export type ChatCompletionChoice = Openai.Chat.Completions.ChatCompletion.Choice;
5
- //# sourceMappingURL=oai.d.ts.map
package/esm/oai.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"oai.d.ts","sourceRoot":"","sources":["../src/oai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAEhC,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,aAAa,CAAC,CAAA;AACvE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAA;AACvD,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,MAAM,CAAA"}
package/esm/oai.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=oai.js.map
package/esm/oai.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"oai.js","sourceRoot":"","sources":["../src/oai.ts"],"names":[],"mappings":""}
@@ -1,4 +0,0 @@
1
- import type { Applied, Schema, Ty } from "./Ty.js";
2
- export type Ref = (ty: Ty) => Schema;
3
- export declare function Ref(applied: Applied): Ref;
4
- //# sourceMappingURL=Ref.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../src/types/Ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAGlD,MAAM,MAAM,GAAG,GAAG,CAAC,EAAE,EAAE,EAAE,KAAK,MAAM,CAAA;AAEpC,wBAAgB,GAAG,CAAC,OAAO,EAAE,OAAO,GAAG,GAAG,CAUzC"}
package/esm/types/Ref.js DELETED
@@ -1,11 +0,0 @@
1
- import { recombineTaggedTemplateArgs } from "../util/recombineTaggedTemplateArgs.js";
2
- export function Ref(applied) {
3
- return (ty) => {
4
- applied = { ...applied, ...ty.applied };
5
- const description = ty.descriptions
6
- .map(({ template, placeheld }) => recombineTaggedTemplateArgs(template, placeheld.map((k) => applied[k])))
7
- .join(" ");
8
- return ty.toSchema(description, Ref(applied));
9
- };
10
- }
11
- //# sourceMappingURL=Ref.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Ref.js","sourceRoot":"","sources":["../../src/types/Ref.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAA;AAIpF,MAAM,UAAU,GAAG,CAAC,OAAgB;IAClC,OAAO,CAAC,EAAE,EAAE,EAAE;QACZ,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAA;QACvC,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY;aAChC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,CAC/B,2BAA2B,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,CAAC,CACzE;aACA,IAAI,CAAC,GAAG,CAAC,CAAA;QACZ,OAAO,EAAE,CAAC,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;IAC/C,CAAC,CAAA;AACH,CAAC"}
@@ -1,8 +0,0 @@
1
- import type { Applied, Description, Schema, ToSchema, Ty } from "./Ty.js";
2
- export declare function RootTy<T, P extends string = never>(toSchema: ToSchema, descriptions?: Array<Description>, applied?: Applied): RootTy<T, P>;
3
- export interface RootTy<T = any, P extends string = string> extends Ty<T, P> {
4
- <P2 extends Array<string>>(template: TemplateStringsArray, ...placeheld: P2): RootTy<T, P | P2[number]>;
5
- apply: <A extends Partial<Record<P, number | string>>>(values: A) => RootTy<T, Exclude<P, keyof A>>;
6
- schema(this: RootTy<T, never>): Schema;
7
- }
8
- //# sourceMappingURL=RootTy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RootTy.d.ts","sourceRoot":"","sources":["../../src/types/RootTy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAEzE,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,KAAK,EAChD,QAAQ,EAAE,QAAQ,EAClB,YAAY,GAAE,KAAK,CAAC,WAAW,CAAM,EACrC,OAAO,GAAE,OAAY,GACpB,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAoBd;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAC1E,CAAC,EAAE,SAAS,KAAK,CAAC,MAAM,CAAC,EACvB,QAAQ,EAAE,oBAAoB,EAC9B,GAAG,SAAS,EAAE,EAAE,GACf,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,KAAK,EAAE,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EACnD,MAAM,EAAE,CAAC,KACN,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;IACnC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,CAAA;CACvC"}
@@ -1,19 +0,0 @@
1
- import { phantoms } from "../util/phantoms.js";
2
- import { Ref } from "./Ref.js";
3
- export function RootTy(toSchema, descriptions = [], applied = {}) {
4
- return Object.assign((template, ...placeheld) => RootTy(toSchema, [{ template, placeheld }, ...descriptions], applied), phantoms(), {
5
- toSchema,
6
- descriptions,
7
- applied,
8
- apply: (values) => {
9
- return RootTy(toSchema, descriptions, { ...applied, ...values });
10
- },
11
- schema() {
12
- return Ref({})(this);
13
- },
14
- isRoot() {
15
- return true;
16
- },
17
- });
18
- }
19
- //# sourceMappingURL=RootTy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RootTy.js","sourceRoot":"","sources":["../../src/types/RootTy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAG9B,MAAM,UAAU,MAAM,CACpB,QAAkB,EAClB,eAAmC,EAAE,EACrC,UAAmB,EAAE;IAErB,OAAO,MAAM,CAAC,MAAM,CAClB,CAA2B,QAA8B,EAAE,GAAG,SAAa,EAAE,EAAE,CAC7E,MAAM,CAAoB,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,GAAG,YAAY,CAAC,EAAE,OAAO,CAAC,EAC1F,QAAQ,EAA4B,EACpC;QACE,QAAQ;QACR,YAAY;QACZ,OAAO;QACP,KAAK,EAAE,CAAgD,MAAS,EAAE,EAAE;YAClE,OAAO,MAAM,CAAyB,QAAQ,EAAE,YAAY,EAAE,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;QAC1F,CAAC;QACD,MAAM;YACJ,OAAO,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;QACtB,CAAC;QACD,MAAM;YACJ,OAAO,IAAI,CAAA;QACb,CAAC;KACF,CACF,CAAA;AACH,CAAC"}
@@ -1,3 +0,0 @@
1
- import { Ty } from "./Ty.js";
2
- export declare function constant<V extends number | string>(value: V): Ty<V, never>;
3
- //# sourceMappingURL=constant.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../src/types/constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,CAK1E"}
@@ -1,8 +0,0 @@
1
- import { Ty } from "./Ty.js";
2
- export function constant(value) {
3
- return Ty((description) => ({
4
- const: value,
5
- description,
6
- }));
7
- }
8
- //# sourceMappingURL=constant.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constant.js","sourceRoot":"","sources":["../../src/types/constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,UAAU,QAAQ,CAA4B,KAAQ;IAC1D,OAAO,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAC1B,KAAK,EAAE,KAAK;QACZ,WAAW;KACZ,CAAC,CAAC,CAAA;AACL,CAAC"}
@@ -1,6 +0,0 @@
1
- import { Ty } from "./Ty.js";
2
- export declare const none: Ty<null, never>;
3
- export declare const boolean: Ty<boolean, never>;
4
- export declare const number: Ty<number, never>;
5
- export declare const string: Ty<string, never>;
6
- //# sourceMappingURL=leaves.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"leaves.d.ts","sourceRoot":"","sources":["../../src/types/leaves.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,CAG9B,CAAA;AAEH,eAAO,MAAM,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,CAGpC,CAAA;AAEH,eAAO,MAAM,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,CAGlC,CAAA;AAEH,eAAO,MAAM,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,CAGlC,CAAA"}
@@ -1,18 +0,0 @@
1
- import { Ty } from "./Ty.js";
2
- export const none = Ty((description) => ({
3
- type: "null",
4
- description,
5
- }));
6
- export const boolean = Ty((description) => ({
7
- type: "boolean",
8
- description,
9
- }));
10
- export const number = Ty((description) => ({
11
- type: "number",
12
- description,
13
- }));
14
- export const string = Ty((description) => ({
15
- type: "string",
16
- description,
17
- }));
18
- //# sourceMappingURL=leaves.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"leaves.js","sourceRoot":"","sources":["../../src/types/leaves.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,CAAC,MAAM,IAAI,GAAoB,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACxD,IAAI,EAAE,MAAM;IACZ,WAAW;CACZ,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,OAAO,GAAuB,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC9D,IAAI,EAAE,SAAS;IACf,WAAW;CACZ,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,MAAM,GAAsB,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC5D,IAAI,EAAE,QAAQ;IACd,WAAW;CACZ,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,MAAM,GAAsB,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC5D,IAAI,EAAE,QAAQ;IACd,WAAW;CACZ,CAAC,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export declare function phantoms<T>(): T;
2
- //# sourceMappingURL=phantoms.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"phantoms.d.ts","sourceRoot":"","sources":["../../src/util/phantoms.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,CAAC,KAAK,CAAC,CAE/B"}
@@ -1,4 +0,0 @@
1
- export function phantoms() {
2
- return {};
3
- }
4
- //# sourceMappingURL=phantoms.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"phantoms.js","sourceRoot":"","sources":["../../src/util/phantoms.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ;IACtB,OAAO,EAAO,CAAA;AAChB,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function recombineTaggedTemplateArgs(strings: TemplateStringsArray, values: Array<number | string>): string;
2
- //# sourceMappingURL=recombineTaggedTemplateArgs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"recombineTaggedTemplateArgs.d.ts","sourceRoot":"","sources":["../../src/util/recombineTaggedTemplateArgs.ts"],"names":[],"mappings":"AAAA,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAC7B,MAAM,CAER"}
@@ -1,4 +0,0 @@
1
- export function recombineTaggedTemplateArgs(strings, values) {
2
- return strings.reduce((acc, cur, i) => `${acc}${cur}${values[i] ?? ""}`, "");
3
- }
4
- //# sourceMappingURL=recombineTaggedTemplateArgs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"recombineTaggedTemplateArgs.js","sourceRoot":"","sources":["../../src/util/recombineTaggedTemplateArgs.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,2BAA2B,CACzC,OAA6B,EAC7B,MAA8B;IAE9B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;AAC9E,CAAC"}
package/src/oai.ts DELETED
@@ -1,5 +0,0 @@
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 DELETED
@@ -1,16 +0,0 @@
1
- import type { Applied, Schema, Ty } from "./Ty.js"
2
- import { recombineTaggedTemplateArgs } from "../util/recombineTaggedTemplateArgs.js"
3
-
4
- export type Ref = (ty: Ty) => Schema
5
-
6
- export function Ref(applied: Applied): Ref {
7
- return (ty) => {
8
- applied = { ...applied, ...ty.applied }
9
- const description = ty.descriptions
10
- .map(({ template, placeheld }) =>
11
- recombineTaggedTemplateArgs(template, placeheld.map((k) => applied[k]!))
12
- )
13
- .join(" ")
14
- return ty.toSchema(description, Ref(applied))
15
- }
16
- }
@@ -1,40 +0,0 @@
1
- import { phantoms } from "../util/phantoms.js"
2
- import { Ref } from "./Ref.js"
3
- import type { Applied, Description, Schema, ToSchema, Ty } from "./Ty.js"
4
-
5
- export function RootTy<T, P extends string = never>(
6
- toSchema: ToSchema,
7
- descriptions: Array<Description> = [],
8
- applied: Applied = {},
9
- ): RootTy<T, P> {
10
- return Object.assign(
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 }>(),
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 })
20
- },
21
- schema(this: RootTy<T, never>) {
22
- return Ref({})(this)
23
- },
24
- isRoot(): this is RootTy {
25
- return true
26
- },
27
- },
28
- )
29
- }
30
-
31
- export interface RootTy<T = any, P extends string = string> extends Ty<T, P> {
32
- <P2 extends Array<string>>(
33
- template: TemplateStringsArray,
34
- ...placeheld: P2
35
- ): RootTy<T, P | P2[number]>
36
- apply: <A extends Partial<Record<P, number | string>>>(
37
- values: A,
38
- ) => RootTy<T, Exclude<P, keyof A>>
39
- schema(this: RootTy<T, never>): Schema
40
- }
@@ -1,8 +0,0 @@
1
- import { Ty } from "./Ty.js"
2
-
3
- export function constant<V extends number | string>(value: V): Ty<V, never> {
4
- return Ty((description) => ({
5
- const: value,
6
- description,
7
- }))
8
- }
@@ -1,21 +0,0 @@
1
- import { Ty } from "./Ty.js"
2
-
3
- export const none: Ty<null, never> = Ty((description) => ({
4
- type: "null",
5
- description,
6
- }))
7
-
8
- export const boolean: Ty<boolean, never> = Ty((description) => ({
9
- type: "boolean",
10
- description,
11
- }))
12
-
13
- export const number: Ty<number, never> = Ty((description) => ({
14
- type: "number",
15
- description,
16
- }))
17
-
18
- export const string: Ty<string, never> = Ty((description) => ({
19
- type: "string",
20
- description,
21
- }))
@@ -1,3 +0,0 @@
1
- export function phantoms<T>(): T {
2
- return {} as T
3
- }
@@ -1,6 +0,0 @@
1
- export function recombineTaggedTemplateArgs(
2
- strings: TemplateStringsArray,
3
- values: Array<number | string>,
4
- ): string {
5
- return strings.reduce((acc, cur, i) => `${acc}${cur}${values[i] ?? ""}`, "")
6
- }