liminal 0.5.13 → 0.5.15

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 (134) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/Context.ts +21 -4
  3. package/Definition.ts +16 -0
  4. package/L/L.ts +10 -1
  5. package/L/all.ts +4 -0
  6. package/L/assistant.ts +5 -3
  7. package/L/catch.ts +4 -0
  8. package/L/continuation.ts +3 -2
  9. package/L/emit.ts +6 -2
  10. package/L/infer.ts +16 -10
  11. package/L/message.ts +7 -3
  12. package/L/model.ts +4 -0
  13. package/L/reflect.ts +2 -1
  14. package/L/run.ts +2 -1
  15. package/L/schema/_schema_common.ts +29 -0
  16. package/L/schema/anyOf.ts +10 -0
  17. package/L/schema/array.ts +13 -0
  18. package/L/schema/boolean.ts +8 -0
  19. package/L/schema/const.ts +18 -0
  20. package/L/schema/enum.ts +18 -0
  21. package/L/schema/integer.ts +6 -0
  22. package/L/schema/null.ts +8 -0
  23. package/L/schema/number.ts +8 -0
  24. package/L/schema/object.ts +21 -0
  25. package/L/schema/string.ts +11 -0
  26. package/L/strand.ts +6 -2
  27. package/L/stream.ts +2 -1
  28. package/Message.ts +3 -2
  29. package/Model.ts +4 -4
  30. package/ModelRegistry.ts +16 -3
  31. package/Rune.ts +36 -7
  32. package/Schema.ts +4 -4
  33. package/Strand.ts +37 -6
  34. package/dist/Context.d.ts +19 -0
  35. package/dist/Context.js +7 -2
  36. package/dist/Context.js.map +1 -1
  37. package/dist/Definition.d.ts +14 -0
  38. package/dist/Definition.js +11 -0
  39. package/dist/Definition.js.map +1 -1
  40. package/dist/L/L.d.ts +10 -1
  41. package/dist/L/L.js +10 -1
  42. package/dist/L/L.js.map +1 -1
  43. package/dist/L/all.d.ts +4 -0
  44. package/dist/L/all.js.map +1 -1
  45. package/dist/L/assistant.d.ts +4 -0
  46. package/dist/L/assistant.js +1 -3
  47. package/dist/L/assistant.js.map +1 -1
  48. package/dist/L/catch.d.ts +4 -0
  49. package/dist/L/catch.js +4 -0
  50. package/dist/L/catch.js.map +1 -1
  51. package/dist/L/continuation.d.ts +1 -0
  52. package/dist/L/continuation.js +3 -2
  53. package/dist/L/continuation.js.map +1 -1
  54. package/dist/L/emit.d.ts +4 -0
  55. package/dist/L/emit.js +6 -2
  56. package/dist/L/emit.js.map +1 -1
  57. package/dist/L/infer.d.ts +4 -0
  58. package/dist/L/infer.js +11 -7
  59. package/dist/L/infer.js.map +1 -1
  60. package/dist/L/message.d.ts +6 -2
  61. package/dist/L/message.js +5 -1
  62. package/dist/L/message.js.map +1 -1
  63. package/dist/L/model.d.ts +4 -0
  64. package/dist/L/model.js +4 -0
  65. package/dist/L/model.js.map +1 -1
  66. package/dist/L/reflect.d.ts +1 -0
  67. package/dist/L/reflect.js +2 -1
  68. package/dist/L/reflect.js.map +1 -1
  69. package/dist/L/run.d.ts +2 -1
  70. package/dist/L/run.js.map +1 -1
  71. package/dist/L/schema/_schema_common.d.ts +6 -0
  72. package/dist/L/schema/_schema_common.js +19 -0
  73. package/dist/L/schema/_schema_common.js.map +1 -0
  74. package/dist/L/schema/anyOf.d.ts +5 -0
  75. package/dist/L/schema/anyOf.js +5 -0
  76. package/dist/L/schema/anyOf.js.map +1 -0
  77. package/dist/L/schema/array.d.ts +5 -0
  78. package/dist/L/schema/array.js +8 -0
  79. package/dist/L/schema/array.js.map +1 -0
  80. package/dist/L/schema/boolean.d.ts +6 -0
  81. package/dist/L/schema/boolean.js +4 -0
  82. package/dist/L/schema/boolean.js.map +1 -0
  83. package/dist/L/schema/const.d.ts +8 -0
  84. package/dist/L/schema/const.js +10 -0
  85. package/dist/L/schema/const.js.map +1 -0
  86. package/dist/L/schema/enum.d.ts +8 -0
  87. package/dist/L/schema/enum.js +10 -0
  88. package/dist/L/schema/enum.js.map +1 -0
  89. package/dist/L/schema/integer.d.ts +5 -0
  90. package/dist/L/schema/integer.js +3 -0
  91. package/dist/L/schema/integer.js.map +1 -0
  92. package/dist/L/schema/null.d.ts +6 -0
  93. package/dist/L/schema/null.js +4 -0
  94. package/dist/L/schema/null.js.map +1 -0
  95. package/dist/L/schema/number.d.ts +6 -0
  96. package/dist/L/schema/number.js +4 -0
  97. package/dist/L/schema/number.js.map +1 -0
  98. package/dist/L/schema/object.d.ts +9 -0
  99. package/dist/L/schema/object.js +12 -0
  100. package/dist/L/schema/object.js.map +1 -0
  101. package/dist/L/schema/string.d.ts +8 -0
  102. package/dist/L/schema/string.js +4 -0
  103. package/dist/L/schema/string.js.map +1 -0
  104. package/dist/L/strand.d.ts +4 -0
  105. package/dist/L/strand.js +6 -2
  106. package/dist/L/strand.js.map +1 -1
  107. package/dist/L/stream.d.ts +1 -0
  108. package/dist/L/stream.js +2 -1
  109. package/dist/L/stream.js.map +1 -1
  110. package/dist/Message.d.ts +3 -2
  111. package/dist/Model.d.ts +4 -4
  112. package/dist/Model.js +4 -4
  113. package/dist/ModelRegistry.d.ts +11 -1
  114. package/dist/ModelRegistry.js +16 -3
  115. package/dist/ModelRegistry.js.map +1 -1
  116. package/dist/Rune.d.ts +29 -8
  117. package/dist/Rune.js +2 -0
  118. package/dist/Rune.js.map +1 -1
  119. package/dist/Schema.d.ts +2 -2
  120. package/dist/Schema.js +2 -2
  121. package/dist/Schema.js.map +1 -1
  122. package/dist/Strand.d.ts +24 -0
  123. package/dist/Strand.js +27 -4
  124. package/dist/Strand.js.map +1 -1
  125. package/dist/tsconfig.tsbuildinfo +1 -1
  126. package/dist/util/JSONValue.d.ts +1 -1
  127. package/dist/util/JSONValue.js +21 -9
  128. package/dist/util/JSONValue.js.map +1 -1
  129. package/package.json +1 -1
  130. package/util/JSONValue.ts +23 -8
  131. package/L/context.ts +0 -12
  132. package/dist/L/context.d.ts +0 -2
  133. package/dist/L/context.js +0 -12
  134. package/dist/L/context.js.map +0 -1
package/Rune.ts CHANGED
@@ -1,31 +1,60 @@
1
1
  import type { Context } from "./Context.ts"
2
2
  import type { Definition } from "./Definition.ts"
3
3
 
4
+ /**
5
+ * `Rune` represents a computational unit within a Strand execution.
6
+ * It is a specialized protocol for expressing different kinds of operations
7
+ * that can be yielded from generator functions to control message state
8
+ * and concurrency within the Liminal runtime.
9
+ * @template E The event type this Rune can handle
10
+ */
4
11
  export interface Rune<E> {
5
12
  [RuneKey]: true
6
- value: {
7
- kind: "continuation"
13
+ instruction: RuneInstruction<E>
14
+ }
15
+
16
+ export type RuneInstruction<E> =
17
+ | RuneInstruction.Continue
18
+ | RuneInstruction.Emit<E>
19
+ | RuneInstruction.Reflect
20
+ | RuneInstruction.CreateChild
21
+ export namespace RuneInstruction {
22
+ /** Tells the runtime to call this function and and pass the result to the next iteration. */
23
+ export interface Continue {
24
+ kind: "continue"
8
25
  debug: string
9
26
  f: () => any
10
- } | {
11
- kind: "event"
27
+ }
28
+
29
+ /** Dispatch an event to the registered handler. */
30
+ export interface Emit<E> {
31
+ kind: "emit"
12
32
  event: E
13
- } | {
33
+ }
34
+
35
+ /** Tells the runtime to provide a reference to the current strand */
36
+ export interface Reflect {
14
37
  kind: "reflect"
15
- } | {
16
- kind: "child"
38
+ }
39
+
40
+ /** Creates a nested execution context with its own definition. */
41
+ export interface CreateChild {
42
+ kind: "create_child"
17
43
  definition: Definition
18
44
  context?: Context | undefined
19
45
  }
20
46
  }
21
47
 
22
48
  export namespace Rune {
49
+ /** Extract the event type from a Rune type. */
23
50
  export type E<X extends Rune<any>> = X extends Rune<infer E> ? E : never
24
51
 
52
+ /** Type guard to check if a value is a Rune. */
25
53
  export function is(value: unknown): value is Rune<any> {
26
54
  return typeof value === "object" && value !== null && RuneKey in value
27
55
  }
28
56
  }
29
57
 
58
+ /** Symbol used to identify Rune objects. */
30
59
  export const RuneKey: unique symbol = Symbol.for("liminal/RuneKey")
31
60
  export type RuneKey = typeof RuneKey
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/Strand.ts CHANGED
@@ -6,26 +6,53 @@ import { StrandStatusChanged } from "./LEvent.ts"
6
6
  import type { Rune } from "./Rune.ts"
7
7
  import { attachCustomInspect } from "./util/attachCustomInspect.ts"
8
8
 
9
+ /** Configuration options for creating a new Strand. */
9
10
  export interface StrandConfig {
11
+ /** Optional parent strand that this strand will be a child of */
10
12
  parent?: Strand | undefined
13
+ /** Optional context for the strand execution */
11
14
  context?: Context | undefined
15
+ /** Optional abort signal that can be used to cancel strand execution */
12
16
  signal?: AbortSignal | undefined
13
17
  }
14
18
 
15
19
  let nextIndex: number = 0
16
20
 
21
+ /**
22
+ * A "Strand" is the core unit of execution in Liminal.
23
+ *
24
+ * It represents a suspendable computation that can yield Runes to control conversation state.
25
+ * Strands implement both the Iterable and PromiseLike interfaces to enable both
26
+ * running (via awaiting) and joining to parent strands (via yielding).
27
+ *
28
+ * Strands maintain their own state and can be hierarchically organized with parent-child
29
+ * relationships. Child strands are bound to their parents, ensuring consistent
30
+ * cancellation behavior.
31
+ *
32
+ * @template Y The type of Runes this Strand can yield.
33
+ * @template T The result type of the Strand.
34
+ */
17
35
  export class Strand<Y extends Rune<any> = Rune<any>, T = any> implements Iterable<Y, T>, PromiseLike<T> {
18
36
  declare T: T
19
37
  declare Y: Y
20
38
 
39
+ /** Controls abort signal propagation. */
21
40
  readonly #controller: AbortController = new AbortController()
41
+ /** Signal that can be used to detect when this strand is aborted. */
22
42
  readonly signal: AbortSignal = this.#controller.signal
43
+ /** Optional event handler function. */
23
44
  #handle?: ((this: Strand, event: any) => void) | undefined
45
+ /** The definition (usually via generator function) that powers this strand. */
24
46
  #definition: Definition<Y, T>
47
+ /** Current status of the strand (untouched, pending, resolved, rejected) */
25
48
  status: StrandStatus<T> = { type: "untouched" }
49
+ /** Unique identifier for this strand. */
26
50
  readonly index: number = nextIndex++
51
+ /** Nesting depth in the strand hierarchy. */
27
52
  readonly depth: number
53
+ /** The parent strand or undefined. */
28
54
  declare readonly parent?: Strand
55
+ /** The conversation state with which the strand operates. */
29
56
  readonly context: Context
30
57
 
31
58
  constructor(definition: Definition<Y, T>, config: StrandConfig) {
@@ -123,22 +150,22 @@ export class Strand<Y extends Rune<any> = Rune<any>, T = any> implements Iterabl
123
150
  let current = await iterator.next()
124
151
  while (!current.done) {
125
152
  const rune = current.value
126
- const { value } = rune
153
+ const { instruction: value } = rune
127
154
  switch (value.kind) {
128
155
  case "reflect": {
129
156
  nextArg = this
130
157
  break
131
158
  }
132
- case "continuation": {
159
+ case "continue": {
133
160
  nextArg = await value.f()
134
161
  break
135
162
  }
136
- case "event": {
163
+ case "emit": {
137
164
  this.#handle?.(value.event)
138
165
  nextArg = undefined
139
166
  break
140
167
  }
141
- case "child": {
168
+ case "create_child": {
142
169
  nextArg = await new Strand(value.definition, {
143
170
  parent: this,
144
171
  context: value.context ?? this.context.clone(),
@@ -185,6 +212,7 @@ export class Strand<Y extends Rune<any> = Rune<any>, T = any> implements Iterabl
185
212
  case "config_signal_aborted":
186
213
  case "parent_aborted":
187
214
  case "continuation_exception_thrown":
215
+ // case "model_error":
188
216
  case "handler_exception_thrown": {
189
217
  return Promise.reject(new StrandRejectedError(status))
190
218
  }
@@ -230,8 +258,6 @@ export namespace StrandStatus {
230
258
  | Rejected.ContinuationExceptionThrown
231
259
  | Rejected.HandlerExceptionThrown
232
260
  // | Rejected.ModelError
233
- // | Rejected.ValidationError
234
- // | Rejected.Timeout
235
261
  export namespace Rejected {
236
262
  export interface ConfigSignalAborted {
237
263
  type: "config_signal_aborted"
@@ -249,5 +275,10 @@ export namespace StrandStatus {
249
275
  type: "handler_exception_thrown"
250
276
  exception: unknown
251
277
  }
278
+ // export interface ModelError {
279
+ // type: "model_error"
280
+ // model: string
281
+ // error: unknown
282
+ // }
252
283
  }
253
284
  }
package/dist/Context.d.ts CHANGED
@@ -2,11 +2,30 @@ import type { Handler } from "./Handler.ts";
2
2
  import type { Message } from "./Message.ts";
3
3
  import { ModelRegistry } from "./ModelRegistry.ts";
4
4
  import type { Tool } from "./Tool.ts";
5
+ /**
6
+ * Context represents the execution environment for a Strand.
7
+ *
8
+ * It holds all the stateful components needed during strand execution:
9
+ * - Message history.
10
+ * - Event handler for processing events.
11
+ * - Model registry for tracking available language models.
12
+ * - Available tools for model-driven function calling.
13
+ */
5
14
  export interface Context {
15
+ /** Event handler for processing events during strand execution. */
6
16
  readonly handler: Handler | undefined;
17
+ /** Registry of available models for inference. */
7
18
  readonly models: ModelRegistry;
19
+ /** Accumulated message history. */
8
20
  readonly messages: Array<Message>;
21
+ /** Set of tools available to the models. */
9
22
  readonly tools: Set<Tool>;
23
+ /** Creates a copy of the current `Context` for child strands. */
10
24
  clone(): Context;
11
25
  }
26
+ /**
27
+ * Factory function to create a new Context.
28
+ * @param context Optional base context from which to initialize.
29
+ * @returns A newly created Context.
30
+ */
12
31
  export declare function Context(context?: Omit<Context, "clone">): Context;
package/dist/Context.js CHANGED
@@ -1,9 +1,14 @@
1
1
  import { ModelRegistry } from "./ModelRegistry.js";
2
+ /**
3
+ * Factory function to create a new Context.
4
+ * @param context Optional base context from which to initialize.
5
+ * @returns A newly created Context.
6
+ */
2
7
  export function Context(context) {
3
8
  return {
4
9
  handler: context?.handler,
5
- models: context?.models.clone() ?? new ModelRegistry(),
6
- messages: [],
10
+ models: context?.models?.clone() ?? new ModelRegistry(),
11
+ messages: [...(context?.messages ?? [])],
7
12
  tools: new Set(context?.tools),
8
13
  clone() {
9
14
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"Context.js","sourceRoot":"","sources":["../Context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAYlD,MAAM,UAAU,OAAO,CAAC,OAAgC;IACtD,OAAO;QACL,OAAO,EAAE,OAAO,EAAE,OAAO;QACzB,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI,IAAI,aAAa,EAAE;QACtD,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC;QAE9B,KAAK;YACH,OAAO;gBACL,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;gBAC3B,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;gBAC5B,KAAK,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC1B,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"Context.js","sourceRoot":"","sources":["../Context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAyBlD;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,OAAgC;IACtD,OAAO;QACL,OAAO,EAAE,OAAO,EAAE,OAAO;QACzB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,IAAI,aAAa,EAAE;QACvD,QAAQ,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAC;QACxC,KAAK,EAAE,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC;QAC9B,KAAK;YACH,OAAO;gBACL,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;gBAC3B,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;gBAC5B,KAAK,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC1B,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -3,8 +3,22 @@ export type RuneIterator<Y extends Rune<any> = Rune<any>, T = any> = Iterator<Y,
3
3
  export type RuneIterable<Y extends Rune<any> = Rune<any>, T = any> = Iterable<Y, T> | AsyncIterable<Y, T>;
4
4
  export type Definition<Y extends Rune<any> = Rune<any>, T = any> = RuneIterable<Y, T> | (() => RuneIterable<Y, T>);
5
5
  export declare namespace Definition {
6
+ /** Extracts the Rune type from a Definition. */
6
7
  type Y<X extends Definition> = X extends RuneIterable<infer Y> ? Y : X extends () => RuneIterable<infer Y> ? Y : X extends RuneIterator<infer Y> ? Y : never;
8
+ /** Extracts the result type from a Definition. */
7
9
  type T<X extends Definition> = X extends RuneIterable<Rune<any>, infer T> ? T : X extends () => RuneIterable<Rune<any>, infer T> ? T : X extends RuneIterator<Rune<any>, infer T> ? T : never;
10
+ /** Extracts the event type from a Definition. */
8
11
  type E<X extends Definition> = Rune.E<Y<X>>;
12
+ /**
13
+ * Converts a Definition into a RuneIterator.
14
+ *
15
+ * This function handles all the different forms a Definition can take:
16
+ * - Synchronous iterables
17
+ * - Asynchronous iterables
18
+ * - Factory functions returning iterables
19
+ *
20
+ * @param definition The definition to unwrap.
21
+ * @returns A RuneIterator ready for consumption.
22
+ */
9
23
  function unwrap<Y extends Rune<any>, T>(definition: Definition<Y, T>): RuneIterator<Y, T>;
10
24
  }
@@ -1,5 +1,16 @@
1
1
  export var Definition;
2
2
  (function (Definition) {
3
+ /**
4
+ * Converts a Definition into a RuneIterator.
5
+ *
6
+ * This function handles all the different forms a Definition can take:
7
+ * - Synchronous iterables
8
+ * - Asynchronous iterables
9
+ * - Factory functions returning iterables
10
+ *
11
+ * @param definition The definition to unwrap.
12
+ * @returns A RuneIterator ready for consumption.
13
+ */
3
14
  function unwrap(definition) {
4
15
  if (Symbol.iterator in definition) {
5
16
  return definition[Symbol.iterator]();
@@ -1 +1 @@
1
- {"version":3,"file":"Definition.js","sourceRoot":"","sources":["../Definition.ts"],"names":[],"mappings":"AAMA,MAAM,KAAW,UAAU,CAyB1B;AAzBD,WAAiB,UAAU;IAazB,SAAgB,MAAM,CAAyB,UAA4B;QACzE,IAAI,MAAM,CAAC,QAAQ,IAAI,UAAU,EAAE,CAAC;YAClC,OAAO,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;QACtC,CAAC;aAAM,IAAI,MAAM,CAAC,aAAa,IAAI,UAAU,EAAE,CAAC;YAC9C,OAAO,UAAU,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAA;QAC3C,CAAC;QACD,MAAM,QAAQ,GAAG,UAAU,EAAE,CAAA;QAC7B,IAAI,MAAM,CAAC,QAAQ,IAAI,QAAQ,EAAE,CAAC;YAChC,OAAO,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;QACpC,CAAC;QACD,OAAO,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAA;IACzC,CAAC;IAXe,iBAAM,SAWrB,CAAA;AACH,CAAC,EAzBgB,UAAU,KAAV,UAAU,QAyB1B"}
1
+ {"version":3,"file":"Definition.js","sourceRoot":"","sources":["../Definition.ts"],"names":[],"mappings":"AAQA,MAAM,KAAW,UAAU,CAuC1B;AAvCD,WAAiB,UAAU;IAgBzB;;;;;;;;;;OAUG;IACH,SAAgB,MAAM,CAAyB,UAA4B;QACzE,IAAI,MAAM,CAAC,QAAQ,IAAI,UAAU,EAAE,CAAC;YAClC,OAAO,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;QACtC,CAAC;aAAM,IAAI,MAAM,CAAC,aAAa,IAAI,UAAU,EAAE,CAAC;YAC9C,OAAO,UAAU,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAA;QAC3C,CAAC;QACD,MAAM,QAAQ,GAAG,UAAU,EAAE,CAAA;QAC7B,IAAI,MAAM,CAAC,QAAQ,IAAI,QAAQ,EAAE,CAAC;YAChC,OAAO,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;QACpC,CAAC;QACD,OAAO,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAA;IACzC,CAAC;IAXe,iBAAM,SAWrB,CAAA;AACH,CAAC,EAvCgB,UAAU,KAAV,UAAU,QAuC1B"}
package/dist/L/L.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from "./all.ts";
2
2
  export * from "./assistant.ts";
3
3
  export * from "./catch.ts";
4
- export * from "./context.ts";
5
4
  export * from "./continuation.ts";
6
5
  export * from "./emit.ts";
7
6
  export * from "./infer.ts";
@@ -9,6 +8,16 @@ export * from "./message.ts";
9
8
  export * from "./model.ts";
10
9
  export * from "./reflect.ts";
11
10
  export * from "./run.ts";
11
+ export * from "./schema/anyOf.ts";
12
+ export * from "./schema/array.ts";
13
+ export * from "./schema/boolean.ts";
14
+ export * from "./schema/const.ts";
15
+ export * from "./schema/enum.ts";
16
+ export * from "./schema/integer.ts";
17
+ export * from "./schema/null.ts";
18
+ export * from "./schema/number";
19
+ export * from "./schema/object.ts";
20
+ export * from "./schema/string.ts";
12
21
  export * from "./strand.ts";
13
22
  export * from "./stream.ts";
14
23
  export * from "./system.ts";
package/dist/L/L.js CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from "./all.js";
2
2
  export * from "./assistant.js";
3
3
  export * from "./catch.js";
4
- export * from "./context.js";
5
4
  export * from "./continuation.js";
6
5
  export * from "./emit.js";
7
6
  export * from "./infer.js";
@@ -9,6 +8,16 @@ export * from "./message.js";
9
8
  export * from "./model.js";
10
9
  export * from "./reflect.js";
11
10
  export * from "./run.js";
11
+ export * from "./schema/anyOf.js";
12
+ export * from "./schema/array.js";
13
+ export * from "./schema/boolean.js";
14
+ export * from "./schema/const.js";
15
+ export * from "./schema/enum.js";
16
+ export * from "./schema/integer.js";
17
+ export * from "./schema/null.js";
18
+ export * from "./schema/number";
19
+ export * from "./schema/object.js";
20
+ export * from "./schema/string.js";
12
21
  export * from "./strand.js";
13
22
  export * from "./stream.js";
14
23
  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,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"}
package/dist/L/all.d.ts CHANGED
@@ -2,6 +2,10 @@ import type { Context } from "../Context.ts";
2
2
  import { Definition } from "../Definition.ts";
3
3
  import type { LEvent } from "../LEvent.ts";
4
4
  import type { Rune } from "../Rune.ts";
5
+ /**
6
+ * Runs multiple definitions in parallel and collects their results.
7
+ * Can be used with an array or object of definitions.
8
+ */
5
9
  export declare function all<A extends Array<Definition>>(definitions: A, context?: Context): Generator<Rune<LEvent> | Definition.Y<A[number]>, {
6
10
  [I in keyof A]: Definition.T<A[I]>;
7
11
  }>;
package/dist/L/all.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"all.js","sourceRoot":"","sources":["../../L/all.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAUtC,MAAM,SAAS,CAAC,CAAC,GAAG,CAClB,WAAc,EACd,OAAiB;IAEjB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;IAC7B,MAAM,OAAO,GAAkB,EAAE,CAAA;IACjC,KAAK,MAAM,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/F,OAAO,CAAC,IAAI,CACV,IAAI,MAAM,CAAC,UAAU,EAAE;YACrB,MAAM;YACN,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE;SACpD,CAAC,CACH,CAAA;IACH,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;IACtE,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAA;IAC1C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACjC,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;AAC1E,CAAC"}
1
+ {"version":3,"file":"all.js","sourceRoot":"","sources":["../../L/all.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AActC,MAAM,SAAS,CAAC,CAAC,GAAG,CAClB,WAAc,EACd,OAAiB;IAEjB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;IAC7B,MAAM,OAAO,GAAkB,EAAE,CAAA;IACjC,KAAK,MAAM,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/F,OAAO,CAAC,IAAI,CACV,IAAI,MAAM,CAAC,UAAU,EAAE;YACrB,MAAM;YACN,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE;SACpD,CAAC,CACH,CAAA;IACH,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;IACtE,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAA;IAC1C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACjC,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;AAC1E,CAAC"}
@@ -1,6 +1,10 @@
1
1
  import type { LEvent } from "../LEvent.ts";
2
2
  import type { Rune } from "../Rune.ts";
3
3
  import { Schema } from "../Schema.ts";
4
+ /**
5
+ * Produces an assistant message when yielded. Can be called with a schema
6
+ * for structured output. Otherwise produces a string.
7
+ */
4
8
  export interface assistant extends Iterable<Rune<LEvent>, string> {
5
9
  <T>(schema: Schema<T>): Generator<Rune<LEvent>, T>;
6
10
  }
@@ -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;AAUtC,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/catch.d.ts CHANGED
@@ -2,6 +2,10 @@ import type { Definition } from "../Definition.ts";
2
2
  import type { LEvent } from "../LEvent.ts";
3
3
  import type { Rune } from "../Rune.ts";
4
4
  export { catch_ as catch };
5
+ /**
6
+ * Error handling utility that catches exceptions from running a definition.
7
+ * Returns a result object indicating whether the operation succeeded or failed.
8
+ */
5
9
  declare function catch_<Y extends Rune<any>, T>(definition: Definition<Y, T>): Generator<Rune<LEvent> | Rune<Y>, CatchResult<T>>;
6
10
  export type CatchResult<T> = {
7
11
  resolved: T;
package/dist/L/catch.js CHANGED
@@ -2,6 +2,10 @@ import { Strand } from "../Strand.js";
2
2
  import { continuation } from "./continuation.js";
3
3
  import { reflect } from "./reflect.js";
4
4
  export { catch_ as catch };
5
+ /**
6
+ * Error handling utility that catches exceptions from running a definition.
7
+ * Returns a result object indicating whether the operation succeeded or failed.
8
+ */
5
9
  function* catch_(definition) {
6
10
  const parent = yield* reflect;
7
11
  return yield* continuation("catch", async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"catch.js","sourceRoot":"","sources":["../../L/catch.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,MAAM,IAAI,KAAK,EAAE,CAAA;AAE1B,QAAQ,CAAC,CAAC,MAAM,CACd,UAA4B;IAE5B,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;IAC7B,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE;QAC7C,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,MAAM,CAAC,UAAU,EAAE;gBAC5C,MAAM;gBACN,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE;aAChC,CAAC,CAAC,IAAI,EAAE,CAAA;YACT,OAAO,EAAE,QAAQ,EAAE,CAAA;QACrB,CAAC;QAAC,OAAO,SAAkB,EAAE,CAAC;YAC5B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAA;QAChC,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AACD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAA"}
1
+ {"version":3,"file":"catch.js","sourceRoot":"","sources":["../../L/catch.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,MAAM,IAAI,KAAK,EAAE,CAAA;AAE1B;;;GAGG;AACH,QAAQ,CAAC,CAAC,MAAM,CACd,UAA4B;IAE5B,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;IAC7B,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE;QAC7C,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,MAAM,CAAC,UAAU,EAAE;gBAC5C,MAAM;gBACN,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE;aAChC,CAAC,CAAC,IAAI,EAAE,CAAA;YACT,OAAO,EAAE,QAAQ,EAAE,CAAA;QACrB,CAAC;QAAC,OAAO,SAAkB,EAAE,CAAC;YAC5B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAA;QAChC,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AACD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAA"}
@@ -1,3 +1,4 @@
1
1
  import type { LEvent } from "../LEvent.ts";
2
2
  import { Rune } from "../Rune.ts";
3
+ /** Yields a continuation rune that executes a function and passes its result to the next iteration. */
3
4
  export declare function continuation<R>(debug: string, f: () => R): Generator<Rune<LEvent>, Awaited<R>>;
@@ -1,9 +1,10 @@
1
1
  import { Rune, RuneKey } from "../Rune.js";
2
+ /** Yields a continuation rune that executes a function and passes its result to the next iteration. */
2
3
  export function* continuation(debug, f) {
3
4
  return yield {
4
5
  [RuneKey]: true,
5
- value: {
6
- kind: "continuation",
6
+ instruction: {
7
+ kind: "continue",
7
8
  debug,
8
9
  f,
9
10
  },
@@ -1 +1 @@
1
- {"version":3,"file":"continuation.js","sourceRoot":"","sources":["../../L/continuation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAE1C,MAAM,SAAS,CAAC,CAAC,YAAY,CAAI,KAAa,EAAE,CAAU;IACxD,OAAO,MAAM;QACX,CAAC,OAAO,CAAC,EAAE,IAAI;QACf,KAAK,EAAE;YACL,IAAI,EAAE,cAAc;YACpB,KAAK;YACL,CAAC;SACF;KACF,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"continuation.js","sourceRoot":"","sources":["../../L/continuation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAE1C,uGAAuG;AACvG,MAAM,SAAS,CAAC,CAAC,YAAY,CAAI,KAAa,EAAE,CAAU;IACxD,OAAO,MAAM;QACX,CAAC,OAAO,CAAC,EAAE,IAAI;QACf,WAAW,EAAE;YACX,IAAI,EAAE,UAAU;YAChB,KAAK;YACL,CAAC;SACF;KACF,CAAA;AACH,CAAC"}
package/dist/L/emit.d.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  import { Rune } from "../Rune.ts";
2
2
  import type { EnsureNarrow } from "../util/EnsureNarrow.ts";
3
+ /**
4
+ * Emits an event to be supplied to handlers.
5
+ * Used for broadcasting state changes and triggering side effects.
6
+ */
3
7
  export declare function emit<E>(event: EnsureNarrow<E>): Generator<Rune<E>, void>;
package/dist/L/emit.js CHANGED
@@ -1,9 +1,13 @@
1
1
  import { Rune, RuneKey } from "../Rune.js";
2
+ /**
3
+ * Emits an event to be supplied to handlers.
4
+ * Used for broadcasting state changes and triggering side effects.
5
+ */
2
6
  export function* emit(event) {
3
7
  return yield {
4
8
  [RuneKey]: true,
5
- value: {
6
- kind: "event",
9
+ instruction: {
10
+ kind: "emit",
7
11
  event,
8
12
  },
9
13
  };
@@ -1 +1 @@
1
- {"version":3,"file":"emit.js","sourceRoot":"","sources":["../../L/emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAG1C,MAAM,SAAS,CAAC,CAAC,IAAI,CAAI,KAAsB;IAC7C,OAAO,MAAM;QACX,CAAC,OAAO,CAAC,EAAE,IAAI;QACf,KAAK,EAAE;YACL,IAAI,EAAE,OAAO;YACb,KAAK;SACN;KACF,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"emit.js","sourceRoot":"","sources":["../../L/emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAG1C;;;GAGG;AACH,MAAM,SAAS,CAAC,CAAC,IAAI,CAAI,KAAsB;IAC7C,OAAO,MAAM;QACX,CAAC,OAAO,CAAC,EAAE,IAAI;QACf,WAAW,EAAE;YACX,IAAI,EAAE,MAAM;YACZ,KAAK;SACN;KACF,CAAA;AACH,CAAC"}
package/dist/L/infer.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import { type LEvent } from "../LEvent.ts";
2
2
  import type { Rune } from "../Rune.ts";
3
3
  import { Schema } from "../Schema.ts";
4
+ /**
5
+ * Requests an inference from the current model, optionally with a schema.
6
+ * Emits inference-related events and returns the model's response as a string.
7
+ */
4
8
  export declare function infer(schema?: Schema): Generator<Rune<LEvent>, string>;
package/dist/L/infer.js CHANGED
@@ -4,21 +4,25 @@ import { Schema } from "../Schema.js";
4
4
  import { continuation } from "./continuation.js";
5
5
  import { emit } from "./emit.js";
6
6
  import { reflect } from "./reflect.js";
7
+ /**
8
+ * Requests an inference from the current model, optionally with a schema.
9
+ * Emits inference-related events and returns the model's response as a string.
10
+ */
7
11
  export function* infer(schema) {
8
12
  const { context: { models, messages }, signal } = yield* reflect;
9
13
  const model = models.peek();
10
14
  LiminalAssertionError.assert(model);
11
15
  const requestId = crypto.randomUUID();
12
16
  yield* emit(new InferenceRequested(requestId, schema));
13
- let inference = yield* continuation("infer", () => model.seal({
17
+ let inference = yield* continuation("infer", model
18
+ .seal({
14
19
  messages,
15
- schema: schema
16
- ? schema.type === "object"
17
- ? schema
18
- : Schema.wrap(schema)
19
- : undefined,
20
+ ...schema && {
21
+ schema: schema.type === "object" ? schema : Schema.wrap(schema),
22
+ },
20
23
  signal,
21
- }).resolve());
24
+ })
25
+ .resolve);
22
26
  if (schema?.type && schema.type !== "object") {
23
27
  inference = JSON.stringify(JSON.parse(inference).value);
24
28
  }
@@ -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;;;GAGG;AACH,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,CACjC,OAAO,EACP,KAAK;SACF,IAAI,CAAC;QACJ,QAAQ;QACR,GAAG,MAAM,IAAI;YACX,MAAM,EAAE,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SAChE;QACD,MAAM;KACP,CAAC;SACD,OAAO,CACX,CAAA;IACD,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,8 @@
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
+ /**
5
+ * Adds a new message to the current context's message list.
6
+ * Emits a message append event to observers.
7
+ */
8
+ export declare function message(role: MessageRole, content: Array<Content>): Generator<Rune<LEvent>, void>;
package/dist/L/message.js CHANGED
@@ -1,9 +1,13 @@
1
1
  import { LEvent, MessageAppended } from "../LEvent.js";
2
2
  import { emit } from "./emit.js";
3
3
  import { reflect } from "./reflect.js";
4
+ /**
5
+ * Adds a new message to the current context's message list.
6
+ * Emits a message append event to observers.
7
+ */
4
8
  export function* message(role, content) {
5
9
  const { context: { messages } } = yield* reflect;
6
- const message = { role, content };
10
+ const message = { role, parts: content };
7
11
  yield* emit(new MessageAppended(message));
8
12
  messages.push(message);
9
13
  }
@@ -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;;;GAGG;AACH,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/model.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import type { LEvent } from "../LEvent.ts";
2
2
  import type { Model } from "../Model.ts";
3
3
  import type { Rune } from "../Rune.ts";
4
+ /**
5
+ * Registers a model in the current context and emits a model registration event.
6
+ * Returns the registered model instance.
7
+ */
4
8
  export declare function model(model: Model): Generator<Rune<LEvent>, Model>;
package/dist/L/model.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import { ModelRegistered } from "../LEvent.js";
2
2
  import { emit } from "./emit.js";
3
3
  import { reflect } from "./reflect.js";
4
+ /**
5
+ * Registers a model in the current context and emits a model registration event.
6
+ * Returns the registered model instance.
7
+ */
4
8
  export function* model(model) {
5
9
  const { context: { models } } = yield* reflect;
6
10
  models.register(model);
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","sourceRoot":"","sources":["../../L/model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,MAAM,SAAS,CAAC,CAAC,KAAK,CAAC,KAAY;IACjC,MAAM,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;IAC9C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACtB,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC,CAAA;IACvC,OAAO,KAAK,CAAA;AACd,CAAC"}
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../L/model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC;;;GAGG;AACH,MAAM,SAAS,CAAC,CAAC,KAAK,CAAC,KAAY;IACjC,MAAM,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;IAC9C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACtB,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC,CAAA;IACvC,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import type { LEvent } from "../LEvent.ts";
2
2
  import { Rune } from "../Rune.ts";
3
3
  import type { Strand } from "../Strand.ts";
4
+ /** Returns the current strand instance, providing access to context and parent information. */
4
5
  export declare const reflect: Iterable<Rune<LEvent>, Strand>;