liminal 0.5.13 → 0.5.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/L/L.ts +10 -0
  3. package/L/assistant.ts +1 -3
  4. package/L/infer.ts +4 -4
  5. package/L/message.ts +3 -3
  6. package/L/run.ts +1 -1
  7. package/L/schema/_schema_common.ts +29 -0
  8. package/L/schema/anyOf.ts +10 -0
  9. package/L/schema/array.ts +13 -0
  10. package/L/schema/boolean.ts +8 -0
  11. package/L/schema/const.ts +18 -0
  12. package/L/schema/enum.ts +18 -0
  13. package/L/schema/integer.ts +6 -0
  14. package/L/schema/null.ts +8 -0
  15. package/L/schema/number.ts +8 -0
  16. package/L/schema/object.ts +21 -0
  17. package/L/schema/string.ts +11 -0
  18. package/Message.ts +3 -2
  19. package/Schema.ts +4 -4
  20. package/dist/L/L.d.ts +10 -0
  21. package/dist/L/L.js +10 -0
  22. package/dist/L/L.js.map +1 -1
  23. package/dist/L/assistant.js +1 -3
  24. package/dist/L/assistant.js.map +1 -1
  25. package/dist/L/infer.js +4 -4
  26. package/dist/L/infer.js.map +1 -1
  27. package/dist/L/message.d.ts +2 -2
  28. package/dist/L/message.js +1 -1
  29. package/dist/L/message.js.map +1 -1
  30. package/dist/L/run.d.ts +1 -1
  31. package/dist/L/schema/_schema_common.d.ts +6 -0
  32. package/dist/L/schema/_schema_common.js +19 -0
  33. package/dist/L/schema/_schema_common.js.map +1 -0
  34. package/dist/L/schema/anyOf.d.ts +5 -0
  35. package/dist/L/schema/anyOf.js +5 -0
  36. package/dist/L/schema/anyOf.js.map +1 -0
  37. package/dist/L/schema/array.d.ts +5 -0
  38. package/dist/L/schema/array.js +8 -0
  39. package/dist/L/schema/array.js.map +1 -0
  40. package/dist/L/schema/boolean.d.ts +6 -0
  41. package/dist/L/schema/boolean.js +4 -0
  42. package/dist/L/schema/boolean.js.map +1 -0
  43. package/dist/L/schema/const.d.ts +8 -0
  44. package/dist/L/schema/const.js +10 -0
  45. package/dist/L/schema/const.js.map +1 -0
  46. package/dist/L/schema/enum.d.ts +8 -0
  47. package/dist/L/schema/enum.js +10 -0
  48. package/dist/L/schema/enum.js.map +1 -0
  49. package/dist/L/schema/integer.d.ts +5 -0
  50. package/dist/L/schema/integer.js +3 -0
  51. package/dist/L/schema/integer.js.map +1 -0
  52. package/dist/L/schema/null.d.ts +6 -0
  53. package/dist/L/schema/null.js +4 -0
  54. package/dist/L/schema/null.js.map +1 -0
  55. package/dist/L/schema/number.d.ts +6 -0
  56. package/dist/L/schema/number.js +4 -0
  57. package/dist/L/schema/number.js.map +1 -0
  58. package/dist/L/schema/object.d.ts +9 -0
  59. package/dist/L/schema/object.js +12 -0
  60. package/dist/L/schema/object.js.map +1 -0
  61. package/dist/L/schema/string.d.ts +8 -0
  62. package/dist/L/schema/string.js +4 -0
  63. package/dist/L/schema/string.js.map +1 -0
  64. package/dist/Message.d.ts +3 -2
  65. package/dist/Schema.d.ts +2 -2
  66. package/dist/Schema.js +2 -2
  67. package/dist/Schema.js.map +1 -1
  68. package/dist/tsconfig.tsbuildinfo +1 -1
  69. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # liminal
2
2
 
3
+ ## 0.5.14
4
+
5
+ ### Patch Changes
6
+
7
+ - d12049c: Fix L.run return type. Add L.<type> for JSON-schema building.
8
+
3
9
  ## 0.5.13
4
10
 
5
11
  ### Patch Changes
package/L/L.ts CHANGED
@@ -9,6 +9,16 @@ export * from "./message.ts"
9
9
  export * from "./model.ts"
10
10
  export * from "./reflect.ts"
11
11
  export * from "./run.ts"
12
+ export * from "./schema/anyOf.ts"
13
+ export * from "./schema/array.ts"
14
+ export * from "./schema/boolean.ts"
15
+ export * from "./schema/const.ts"
16
+ export * from "./schema/enum.ts"
17
+ export * from "./schema/integer.ts"
18
+ export * from "./schema/null.ts"
19
+ export * from "./schema/number"
20
+ export * from "./schema/object.ts"
21
+ export * from "./schema/string.ts"
12
22
  export * from "./strand.ts"
13
23
  export * from "./stream.ts"
14
24
  export * from "./system.ts"
package/L/assistant.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type { LEvent } from "../LEvent.ts"
2
2
  import type { Rune } from "../Rune.ts"
3
3
  import { Schema } from "../Schema.ts"
4
- import { continuation } from "./continuation.ts"
5
4
  import { infer } from "./infer.ts"
6
5
  import { message } from "./message.ts"
7
6
 
@@ -13,8 +12,7 @@ export const assistant: assistant = Object.assign(
13
12
  function* assistant<T>(schema: Schema<T>): Generator<Rune<LEvent>, T> {
14
13
  const inference = yield* infer(schema)
15
14
  yield* message("assistant", [{ part: inference }])
16
- const input = JSON.parse(inference)
17
- return yield* continuation("validate_assistant_message", () => Schema.validateValue(schema, input))
15
+ return JSON.parse(inference)
18
16
  },
19
17
  {
20
18
  *[Symbol.iterator]() {
package/L/infer.ts CHANGED
@@ -15,11 +15,11 @@ export function* infer(schema?: Schema): Generator<Rune<LEvent>, string> {
15
15
  let inference = yield* continuation("infer", () =>
16
16
  model.seal({
17
17
  messages,
18
- schema: schema
19
- ? schema.type === "object"
18
+ ...schema && {
19
+ schema: schema.type === "object"
20
20
  ? schema
21
- : Schema.wrap(schema)
22
- : undefined,
21
+ : Schema.wrap(schema),
22
+ },
23
23
  signal,
24
24
  }).resolve())
25
25
  if (schema?.type && schema.type !== "object") {
package/L/message.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { LEvent, MessageAppended } from "../LEvent.ts"
2
- import type { ContentPart, Message, MessageRole } from "../Message.ts"
2
+ import type { Content, Message, MessageRole } from "../Message.ts"
3
3
  import type { Rune } from "../Rune.ts"
4
4
  import { emit } from "./emit.ts"
5
5
  import { reflect } from "./reflect.ts"
6
6
 
7
- export function* message(role: MessageRole, content: Array<ContentPart>): Generator<Rune<LEvent>, void> {
7
+ export function* message(role: MessageRole, content: Array<Content>): Generator<Rune<LEvent>, void> {
8
8
  const { context: { messages } } = yield* reflect
9
- const message: Message = { role, content }
9
+ const message: Message = { role, parts: content }
10
10
  yield* emit(new MessageAppended(message))
11
11
  messages.push(message)
12
12
  }
package/L/run.ts CHANGED
@@ -15,7 +15,7 @@ export interface RunConfig<Y extends Rune<any>> {
15
15
  signal?: AbortSignal | undefined
16
16
  }
17
17
 
18
- export function run<Y extends Rune<any>, T>(definition: Definition<Y, T>, config?: RunConfig<Y>): Strand {
18
+ export function run<Y extends Rune<any>, T>(definition: Definition<Y, T>, config?: RunConfig<Y>): Strand<Y, T> {
19
19
  const context = Context({
20
20
  handler: config?.handler,
21
21
  models: config?.models ?? new ModelRegistry(),
@@ -0,0 +1,29 @@
1
+ import type { Schema } from "../../Schema.ts"
2
+ import { isTemplateStringsArray } from "../../util/isTemplateStringsArray.ts"
3
+
4
+ export function make<S extends Schema>(schema: Omit<S, "T">, description?: string): S & TypeBase {
5
+ const schema_ = {
6
+ ...schema,
7
+ ...description && { description },
8
+ }
9
+
10
+ const Type = Object.assign(function describe(e0?: TemplateStringsArray | string, ...rest: Array<string>) {
11
+ const junction = isTemplateStringsArray(e0) ? String.raw(e0, ...rest) : e0
12
+ return make(
13
+ schema_,
14
+ description ? `${description}${junction ? `\n\n${junction}` : ""}` : junction,
15
+ )
16
+ }, schema_)
17
+ Object.defineProperty(Type, "toJSON", {
18
+ value() {
19
+ return schema_
20
+ },
21
+ enumerable: false,
22
+ })
23
+ return Type as never
24
+ }
25
+
26
+ export interface TypeBase {
27
+ (template: TemplateStringsArray, ...substitutions: Array<string>): this
28
+ (...values: Array<string>): this
29
+ }
@@ -0,0 +1,10 @@
1
+ import type { Schema, SchemaAnyOf } from "../../Schema.ts"
2
+ import { make } from "./_schema_common.ts"
3
+
4
+ export interface anyOf<XA extends Array<Schema> = Array<Schema>> extends SchemaAnyOf<XA[number]["T"]> {
5
+ anyOf: XA
6
+ }
7
+
8
+ export function anyOf<XA extends Array<Schema>>(anyOf: XA): anyOf<XA> {
9
+ return make({ anyOf })
10
+ }
@@ -0,0 +1,13 @@
1
+ import type { Schema, SchemaArray } from "../../Schema.ts"
2
+ import { make } from "./_schema_common.ts"
3
+
4
+ export interface LArray<X extends Schema = Schema> extends SchemaArray<Array<X["T"]>> {
5
+ items: X
6
+ }
7
+
8
+ export function array<X extends Schema>(items: X): LArray<X> {
9
+ return make({
10
+ type: "array",
11
+ items,
12
+ })
13
+ }
@@ -0,0 +1,8 @@
1
+ import type { SchemaBoolean } from "../../Schema.ts"
2
+ import { make, type TypeBase } from "./_schema_common.ts"
3
+
4
+ interface boolean_ extends SchemaBoolean<boolean>, TypeBase {}
5
+
6
+ const boolean_: boolean_ = make({ type: "boolean" })
7
+
8
+ export { boolean_ as boolean }
@@ -0,0 +1,18 @@
1
+ import type { SchemaString } from "../../Schema.ts"
2
+ import { make, type TypeBase } from "./_schema_common.ts"
3
+
4
+ interface const_<K extends string> extends SchemaString<K>, TypeBase {
5
+ enum?: never
6
+ const: K
7
+ }
8
+
9
+ function const_<K extends string>(value: K): const_<K> {
10
+ return make({
11
+ type: "string",
12
+ const: value,
13
+ })
14
+ }
15
+
16
+ Object.defineProperty(const_, "name", { value: "const" })
17
+
18
+ export { const_ as const }
@@ -0,0 +1,18 @@
1
+ import type { SchemaString } from "../../Schema.ts"
2
+ import { make, type TypeBase } from "./_schema_common.ts"
3
+
4
+ interface enum_<V extends Array<string> = Array<string>> extends SchemaString<V[number]>, TypeBase {
5
+ enum: V
6
+ const?: never
7
+ }
8
+
9
+ function enum_<const V extends Array<string>>(...values: V): enum_<V> {
10
+ return make({
11
+ type: "string",
12
+ enum: values,
13
+ })
14
+ }
15
+
16
+ Object.defineProperty(enum_, "name", { value: "enum" })
17
+
18
+ export { enum_ as enum }
@@ -0,0 +1,6 @@
1
+ import type { SchemaInteger } from "../../Schema.ts"
2
+ import { make, type TypeBase } from "./_schema_common.ts"
3
+
4
+ export interface integer extends SchemaInteger<number>, TypeBase {}
5
+
6
+ export const integer: integer = make({ type: "integer" })
@@ -0,0 +1,8 @@
1
+ import type { SchemaNull } from "../../Schema.ts"
2
+ import { make, type TypeBase } from "./_schema_common.ts"
3
+
4
+ export interface null_ extends SchemaNull<null>, TypeBase {}
5
+
6
+ const null_: null_ = make({ type: "null" })
7
+
8
+ export { null_ as null }
@@ -0,0 +1,8 @@
1
+ import type { SchemaNumber } from "../../Schema.ts"
2
+ import { make, type TypeBase } from "./_schema_common.ts"
3
+
4
+ interface number_ extends SchemaNumber<number>, TypeBase {}
5
+
6
+ const number_: number_ = make({ type: "number" })
7
+
8
+ export { number_ as number }
@@ -0,0 +1,21 @@
1
+ import type { Schema, SchemaObject } from "../../Schema.ts"
2
+ import { make } from "./_schema_common.ts"
3
+
4
+ interface object_<F extends Record<string, Schema> = Record<string, Schema>>
5
+ extends SchemaObject<{ [K in keyof F]: F[K]["T"] }>
6
+ {
7
+ properties: F
8
+ required: Array<Extract<keyof F, string>>
9
+ }
10
+
11
+ function object_<XR extends Record<string, Schema>>(properties: XR): object_<XR> {
12
+ return make({
13
+ type: "object",
14
+ properties,
15
+ additionalProperties: false,
16
+ required: Object.keys(properties) as never,
17
+ })
18
+ }
19
+
20
+ Object.defineProperty(object_, "name", { value: "object" })
21
+ export { object_ as object }
@@ -0,0 +1,11 @@
1
+ import type { SchemaString } from "../../Schema.ts"
2
+ import { make, type TypeBase } from "./_schema_common.ts"
3
+
4
+ interface string_ extends SchemaString<string>, TypeBase {
5
+ enum?: never
6
+ const?: never
7
+ }
8
+
9
+ const string_: string_ = make({ type: "string" })
10
+
11
+ export { string_ as string }
package/Message.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  export interface Message {
2
2
  readonly role: MessageRole
3
- readonly content: Array<ContentPart>
3
+ readonly parts: Array<Content>
4
4
  }
5
5
 
6
6
  export type MessageRole = "system" | "user" | "assistant"
7
7
 
8
- export type ContentPart = {
8
+ export type Content = {
9
9
  readonly part: string
10
10
  readonly alt?: never
11
+ readonly mime?: never
11
12
  } | {
12
13
  readonly part: URL
13
14
  readonly alt: string
package/Schema.ts CHANGED
@@ -55,14 +55,14 @@ export interface SchemaBase<T> {
55
55
  export namespace Schema {
56
56
  const ids = new WeakMap<Schema, Record<string, string>>()
57
57
  const schemas = new WeakMap<WeakKey, Schema>()
58
- const validators = new WeakMap<Schema, (value: unknown) => Promise<unknown>>()
58
+ const validators = new WeakMap<Schema, (value: unknown) => unknown>()
59
59
 
60
60
  export function compile<T>(key: WeakKey, {
61
61
  schema: schema_,
62
62
  validate,
63
63
  }: {
64
64
  schema(): unknown
65
- validate(value: unknown): Promise<T>
65
+ validate(value: unknown): T
66
66
  }) {
67
67
  let schema = schemas.get(key)
68
68
  if (!schema) {
@@ -73,10 +73,10 @@ export namespace Schema {
73
73
  return schema
74
74
  }
75
75
 
76
- export async function validateValue<T>(schema: Schema<T>, value: unknown): Promise<T> {
76
+ export function validateValue<T>(schema: Schema<T>, value: unknown): T {
77
77
  const validator = validators.get(schema)
78
78
  LE.assert(validator)
79
- return await validator(value) as never
79
+ return validator(value) as never
80
80
  }
81
81
 
82
82
  export async function id(schema: Schema, description?: string): Promise<string> {
package/dist/L/L.d.ts CHANGED
@@ -9,6 +9,16 @@ export * from "./message.ts";
9
9
  export * from "./model.ts";
10
10
  export * from "./reflect.ts";
11
11
  export * from "./run.ts";
12
+ export * from "./schema/anyOf.ts";
13
+ export * from "./schema/array.ts";
14
+ export * from "./schema/boolean.ts";
15
+ export * from "./schema/const.ts";
16
+ export * from "./schema/enum.ts";
17
+ export * from "./schema/integer.ts";
18
+ export * from "./schema/null.ts";
19
+ export * from "./schema/number";
20
+ export * from "./schema/object.ts";
21
+ export * from "./schema/string.ts";
12
22
  export * from "./strand.ts";
13
23
  export * from "./stream.ts";
14
24
  export * from "./system.ts";
package/dist/L/L.js CHANGED
@@ -9,6 +9,16 @@ export * from "./message.js";
9
9
  export * from "./model.js";
10
10
  export * from "./reflect.js";
11
11
  export * from "./run.js";
12
+ export * from "./schema/anyOf.js";
13
+ export * from "./schema/array.js";
14
+ export * from "./schema/boolean.js";
15
+ export * from "./schema/const.js";
16
+ export * from "./schema/enum.js";
17
+ export * from "./schema/integer.js";
18
+ export * from "./schema/null.js";
19
+ export * from "./schema/number";
20
+ export * from "./schema/object.js";
21
+ export * from "./schema/string.js";
12
22
  export * from "./strand.js";
13
23
  export * from "./stream.js";
14
24
  export * from "./system.js";
package/dist/L/L.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"L.js","sourceRoot":"","sources":["../../L/L.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"L.js","sourceRoot":"","sources":["../../L/L.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
@@ -1,12 +1,10 @@
1
1
  import { Schema } from "../Schema.js";
2
- import { continuation } from "./continuation.js";
3
2
  import { infer } from "./infer.js";
4
3
  import { message } from "./message.js";
5
4
  export const assistant = Object.assign(function* assistant(schema) {
6
5
  const inference = yield* infer(schema);
7
6
  yield* message("assistant", [{ part: inference }]);
8
- const input = JSON.parse(inference);
9
- return yield* continuation("validate_assistant_message", () => Schema.validateValue(schema, input));
7
+ return JSON.parse(inference);
10
8
  }, {
11
9
  *[Symbol.iterator]() {
12
10
  const inference = yield* infer();
@@ -1 +1 @@
1
- {"version":3,"file":"assistant.js","sourceRoot":"","sources":["../../L/assistant.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAMtC,MAAM,CAAC,MAAM,SAAS,GAAc,MAAM,CAAC,MAAM,CAC/C,QAAQ,CAAC,CAAC,SAAS,CAAI,MAAiB;IACtC,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACtC,KAAK,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IAClD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IACnC,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,4BAA4B,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;AACrG,CAAC,EACD;IACE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,KAAK,EAAE,CAAA;QAChC,KAAK,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;QAClD,OAAO,SAAS,CAAA;IAClB,CAAC;CACF,CACF,CAAA"}
1
+ {"version":3,"file":"assistant.js","sourceRoot":"","sources":["../../L/assistant.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAMtC,MAAM,CAAC,MAAM,SAAS,GAAc,MAAM,CAAC,MAAM,CAC/C,QAAQ,CAAC,CAAC,SAAS,CAAI,MAAiB;IACtC,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACtC,KAAK,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IAClD,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;AAC9B,CAAC,EACD;IACE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,KAAK,EAAE,CAAA;QAChC,KAAK,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;QAClD,OAAO,SAAS,CAAA;IAClB,CAAC;CACF,CACF,CAAA"}
package/dist/L/infer.js CHANGED
@@ -12,11 +12,11 @@ export function* infer(schema) {
12
12
  yield* emit(new InferenceRequested(requestId, schema));
13
13
  let inference = yield* continuation("infer", () => model.seal({
14
14
  messages,
15
- schema: schema
16
- ? schema.type === "object"
15
+ ...schema && {
16
+ schema: schema.type === "object"
17
17
  ? schema
18
- : Schema.wrap(schema)
19
- : undefined,
18
+ : Schema.wrap(schema),
19
+ },
20
20
  signal,
21
21
  }).resolve());
22
22
  if (schema?.type && schema.type !== "object") {
@@ -1 +1 @@
1
- {"version":3,"file":"infer.js","sourceRoot":"","sources":["../../L/infer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAe,MAAM,cAAc,CAAA;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAEnE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,MAAM,SAAS,CAAC,CAAC,KAAK,CAAC,MAAe;IACpC,MAAM,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;IAChE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,CAAA;IAC3B,qBAAqB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACnC,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,EAAE,CAAA;IACrC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAA;IACtD,IAAI,SAAS,GAAG,KAAK,CAAC,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,CAChD,KAAK,CAAC,IAAI,CAAC;QACT,QAAQ;QACR,MAAM,EAAE,MAAM;YACZ,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,QAAQ;gBACxB,CAAC,CAAC,MAAM;gBACR,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;YACvB,CAAC,CAAC,SAAS;QACb,MAAM;KACP,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;IACf,IAAI,MAAM,EAAE,IAAI,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7C,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAA;IACzD,CAAC;IACD,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAA;IAC/C,OAAO,SAAS,CAAA;AAClB,CAAC"}
1
+ {"version":3,"file":"infer.js","sourceRoot":"","sources":["../../L/infer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAe,MAAM,cAAc,CAAA;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAEnE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,MAAM,SAAS,CAAC,CAAC,KAAK,CAAC,MAAe;IACpC,MAAM,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;IAChE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,CAAA;IAC3B,qBAAqB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACnC,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,EAAE,CAAA;IACrC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAA;IACtD,IAAI,SAAS,GAAG,KAAK,CAAC,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,CAChD,KAAK,CAAC,IAAI,CAAC;QACT,QAAQ;QACR,GAAG,MAAM,IAAI;YACX,MAAM,EAAE,MAAM,CAAC,IAAI,KAAK,QAAQ;gBAC9B,CAAC,CAAC,MAAM;gBACR,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SACxB;QACD,MAAM;KACP,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;IACf,IAAI,MAAM,EAAE,IAAI,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7C,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAA;IACzD,CAAC;IACD,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAA;IAC/C,OAAO,SAAS,CAAA;AAClB,CAAC"}
@@ -1,4 +1,4 @@
1
1
  import { LEvent } from "../LEvent.ts";
2
- import type { ContentPart, MessageRole } from "../Message.ts";
2
+ import type { Content, MessageRole } from "../Message.ts";
3
3
  import type { Rune } from "../Rune.ts";
4
- export declare function message(role: MessageRole, content: Array<ContentPart>): Generator<Rune<LEvent>, void>;
4
+ export declare function message(role: MessageRole, content: Array<Content>): Generator<Rune<LEvent>, void>;
package/dist/L/message.js CHANGED
@@ -3,7 +3,7 @@ import { emit } from "./emit.js";
3
3
  import { reflect } from "./reflect.js";
4
4
  export function* message(role, content) {
5
5
  const { context: { messages } } = yield* reflect;
6
- const message = { role, content };
6
+ const message = { role, parts: content };
7
7
  yield* emit(new MessageAppended(message));
8
8
  messages.push(message);
9
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","sourceRoot":"","sources":["../../L/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAGtD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,MAAM,SAAS,CAAC,CAAC,OAAO,CAAC,IAAiB,EAAE,OAA2B;IACrE,MAAM,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;IAChD,MAAM,OAAO,GAAY,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;IAC1C,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC,CAAA;IACzC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AACxB,CAAC"}
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../../L/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAGtD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,MAAM,SAAS,CAAC,CAAC,OAAO,CAAC,IAAiB,EAAE,OAAuB;IACjE,MAAM,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;IAChD,MAAM,OAAO,GAAY,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;IACjD,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC,CAAA;IACzC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AACxB,CAAC"}
package/dist/L/run.d.ts CHANGED
@@ -12,4 +12,4 @@ export interface RunConfig<Y extends Rune<any>> {
12
12
  tools?: Set<Tool> | undefined;
13
13
  signal?: AbortSignal | undefined;
14
14
  }
15
- export declare function run<Y extends Rune<any>, T>(definition: Definition<Y, T>, config?: RunConfig<Y>): Strand;
15
+ export declare function run<Y extends Rune<any>, T>(definition: Definition<Y, T>, config?: RunConfig<Y>): Strand<Y, T>;
@@ -0,0 +1,6 @@
1
+ import type { Schema } from "../../Schema.ts";
2
+ export declare function make<S extends Schema>(schema: Omit<S, "T">, description?: string): S & TypeBase;
3
+ export interface TypeBase {
4
+ (template: TemplateStringsArray, ...substitutions: Array<string>): this;
5
+ (...values: Array<string>): this;
6
+ }
@@ -0,0 +1,19 @@
1
+ import { isTemplateStringsArray } from "../../util/isTemplateStringsArray.js";
2
+ export function make(schema, description) {
3
+ const schema_ = {
4
+ ...schema,
5
+ ...description && { description },
6
+ };
7
+ const Type = Object.assign(function describe(e0, ...rest) {
8
+ const junction = isTemplateStringsArray(e0) ? String.raw(e0, ...rest) : e0;
9
+ return make(schema_, description ? `${description}${junction ? `\n\n${junction}` : ""}` : junction);
10
+ }, schema_);
11
+ Object.defineProperty(Type, "toJSON", {
12
+ value() {
13
+ return schema_;
14
+ },
15
+ enumerable: false,
16
+ });
17
+ return Type;
18
+ }
19
+ //# sourceMappingURL=_schema_common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_schema_common.js","sourceRoot":"","sources":["../../../L/schema/_schema_common.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAA;AAE7E,MAAM,UAAU,IAAI,CAAmB,MAAoB,EAAE,WAAoB;IAC/E,MAAM,OAAO,GAAG;QACd,GAAG,MAAM;QACT,GAAG,WAAW,IAAI,EAAE,WAAW,EAAE;KAClC,CAAA;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,QAAQ,CAAC,EAAkC,EAAE,GAAG,IAAmB;QACrG,MAAM,QAAQ,GAAG,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QAC1E,OAAO,IAAI,CACT,OAAO,EACP,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAC9E,CAAA;IACH,CAAC,EAAE,OAAO,CAAC,CAAA;IACX,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE;QACpC,KAAK;YACH,OAAO,OAAO,CAAA;QAChB,CAAC;QACD,UAAU,EAAE,KAAK;KAClB,CAAC,CAAA;IACF,OAAO,IAAa,CAAA;AACtB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Schema, SchemaAnyOf } from "../../Schema.ts";
2
+ export interface anyOf<XA extends Array<Schema> = Array<Schema>> extends SchemaAnyOf<XA[number]["T"]> {
3
+ anyOf: XA;
4
+ }
5
+ export declare function anyOf<XA extends Array<Schema>>(anyOf: XA): anyOf<XA>;
@@ -0,0 +1,5 @@
1
+ import { make } from "./_schema_common.js";
2
+ export function anyOf(anyOf) {
3
+ return make({ anyOf });
4
+ }
5
+ //# sourceMappingURL=anyOf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anyOf.js","sourceRoot":"","sources":["../../../L/schema/anyOf.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAM1C,MAAM,UAAU,KAAK,CAA2B,KAAS;IACvD,OAAO,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AACxB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Schema, SchemaArray } from "../../Schema.ts";
2
+ export interface LArray<X extends Schema = Schema> extends SchemaArray<Array<X["T"]>> {
3
+ items: X;
4
+ }
5
+ export declare function array<X extends Schema>(items: X): LArray<X>;
@@ -0,0 +1,8 @@
1
+ import { make } from "./_schema_common.js";
2
+ export function array(items) {
3
+ return make({
4
+ type: "array",
5
+ items,
6
+ });
7
+ }
8
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../../L/schema/array.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAM1C,MAAM,UAAU,KAAK,CAAmB,KAAQ;IAC9C,OAAO,IAAI,CAAC;QACV,IAAI,EAAE,OAAO;QACb,KAAK;KACN,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { SchemaBoolean } from "../../Schema.ts";
2
+ import { type TypeBase } from "./_schema_common.ts";
3
+ interface boolean_ extends SchemaBoolean<boolean>, TypeBase {
4
+ }
5
+ declare const boolean_: boolean_;
6
+ export { boolean_ as boolean };
@@ -0,0 +1,4 @@
1
+ import { make } from "./_schema_common.js";
2
+ const boolean_ = make({ type: "boolean" });
3
+ export { boolean_ as boolean };
4
+ //# sourceMappingURL=boolean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../L/schema/boolean.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAiB,MAAM,qBAAqB,CAAA;AAIzD,MAAM,QAAQ,GAAa,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;AAEpD,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { SchemaString } from "../../Schema.ts";
2
+ import { type TypeBase } from "./_schema_common.ts";
3
+ interface const_<K extends string> extends SchemaString<K>, TypeBase {
4
+ enum?: never;
5
+ const: K;
6
+ }
7
+ declare function const_<K extends string>(value: K): const_<K>;
8
+ export { const_ as const };
@@ -0,0 +1,10 @@
1
+ import { make } from "./_schema_common.js";
2
+ function const_(value) {
3
+ return make({
4
+ type: "string",
5
+ const: value,
6
+ });
7
+ }
8
+ Object.defineProperty(const_, "name", { value: "const" });
9
+ export { const_ as const };
10
+ //# sourceMappingURL=const.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.js","sourceRoot":"","sources":["../../../L/schema/const.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAiB,MAAM,qBAAqB,CAAA;AAOzD,SAAS,MAAM,CAAmB,KAAQ;IACxC,OAAO,IAAI,CAAC;QACV,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,KAAK;KACb,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAA;AAEzD,OAAO,EAAE,MAAM,IAAI,KAAK,EAAE,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { SchemaString } from "../../Schema.ts";
2
+ import { type TypeBase } from "./_schema_common.ts";
3
+ interface enum_<V extends Array<string> = Array<string>> extends SchemaString<V[number]>, TypeBase {
4
+ enum: V;
5
+ const?: never;
6
+ }
7
+ declare function enum_<const V extends Array<string>>(...values: V): enum_<V>;
8
+ export { enum_ as enum };
@@ -0,0 +1,10 @@
1
+ import { make } from "./_schema_common.js";
2
+ function enum_(...values) {
3
+ return make({
4
+ type: "string",
5
+ enum: values,
6
+ });
7
+ }
8
+ Object.defineProperty(enum_, "name", { value: "enum" });
9
+ export { enum_ as enum };
10
+ //# sourceMappingURL=enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../L/schema/enum.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAiB,MAAM,qBAAqB,CAAA;AAOzD,SAAS,KAAK,CAAgC,GAAG,MAAS;IACxD,OAAO,IAAI,CAAC;QACV,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,MAAM;KACb,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;AAEvD,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,CAAA"}
@@ -0,0 +1,5 @@
1
+ import type { SchemaInteger } from "../../Schema.ts";
2
+ import { type TypeBase } from "./_schema_common.ts";
3
+ export interface integer extends SchemaInteger<number>, TypeBase {
4
+ }
5
+ export declare const integer: integer;
@@ -0,0 +1,3 @@
1
+ import { make } from "./_schema_common.js";
2
+ export const integer = make({ type: "integer" });
3
+ //# sourceMappingURL=integer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integer.js","sourceRoot":"","sources":["../../../L/schema/integer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAiB,MAAM,qBAAqB,CAAA;AAIzD,MAAM,CAAC,MAAM,OAAO,GAAY,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA"}
@@ -0,0 +1,6 @@
1
+ import type { SchemaNull } from "../../Schema.ts";
2
+ import { type TypeBase } from "./_schema_common.ts";
3
+ export interface null_ extends SchemaNull<null>, TypeBase {
4
+ }
5
+ declare const null_: null_;
6
+ export { null_ as null };
@@ -0,0 +1,4 @@
1
+ import { make } from "./_schema_common.js";
2
+ const null_ = make({ type: "null" });
3
+ export { null_ as null };
4
+ //# sourceMappingURL=null.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"null.js","sourceRoot":"","sources":["../../../L/schema/null.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAiB,MAAM,qBAAqB,CAAA;AAIzD,MAAM,KAAK,GAAU,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;AAE3C,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,CAAA"}
@@ -0,0 +1,6 @@
1
+ import type { SchemaNumber } from "../../Schema.ts";
2
+ import { type TypeBase } from "./_schema_common.ts";
3
+ interface number_ extends SchemaNumber<number>, TypeBase {
4
+ }
5
+ declare const number_: number_;
6
+ export { number_ as number };
@@ -0,0 +1,4 @@
1
+ import { make } from "./_schema_common.js";
2
+ const number_ = make({ type: "number" });
3
+ export { number_ as number };
4
+ //# sourceMappingURL=number.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.js","sourceRoot":"","sources":["../../../L/schema/number.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAiB,MAAM,qBAAqB,CAAA;AAIzD,MAAM,OAAO,GAAY,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;AAEjD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,CAAA"}