liminal 0.5.14 → 0.5.16

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 (107) hide show
  1. package/{Model.ts → Adapter.ts} +5 -5
  2. package/AdapterRegistry.ts +78 -0
  3. package/CHANGELOG.md +12 -0
  4. package/Config.ts +2 -2
  5. package/Context.ts +24 -7
  6. package/Definition.ts +16 -0
  7. package/L/L.ts +1 -2
  8. package/L/all.ts +4 -0
  9. package/L/assistant.ts +4 -0
  10. package/L/catch.ts +4 -0
  11. package/L/continuation.ts +3 -2
  12. package/L/emit.ts +6 -2
  13. package/L/focus.ts +17 -0
  14. package/L/infer.ts +18 -14
  15. package/L/message.ts +4 -0
  16. package/L/reflect.ts +2 -1
  17. package/L/run.ts +4 -3
  18. package/L/strand.ts +6 -2
  19. package/L/stream.ts +4 -5
  20. package/LEvent.ts +5 -5
  21. package/Rune.ts +36 -7
  22. package/Strand.ts +37 -6
  23. package/dist/{Model.d.ts → Adapter.d.ts} +5 -5
  24. package/dist/Adapter.js +13 -0
  25. package/dist/Adapter.js.map +1 -0
  26. package/dist/AdapterRegistry.d.ts +27 -0
  27. package/dist/AdapterRegistry.js +62 -0
  28. package/dist/AdapterRegistry.js.map +1 -0
  29. package/dist/Config.d.ts +2 -2
  30. package/dist/Config.js +1 -1
  31. package/dist/Config.js.map +1 -1
  32. package/dist/Context.d.ts +21 -2
  33. package/dist/Context.js +9 -4
  34. package/dist/Context.js.map +1 -1
  35. package/dist/Definition.d.ts +14 -0
  36. package/dist/Definition.js +11 -0
  37. package/dist/Definition.js.map +1 -1
  38. package/dist/L/L.d.ts +1 -2
  39. package/dist/L/L.js +1 -2
  40. package/dist/L/L.js.map +1 -1
  41. package/dist/L/all.d.ts +4 -0
  42. package/dist/L/all.js.map +1 -1
  43. package/dist/L/assistant.d.ts +4 -0
  44. package/dist/L/assistant.js.map +1 -1
  45. package/dist/L/catch.d.ts +4 -0
  46. package/dist/L/catch.js +4 -0
  47. package/dist/L/catch.js.map +1 -1
  48. package/dist/L/continuation.d.ts +1 -0
  49. package/dist/L/continuation.js +3 -2
  50. package/dist/L/continuation.js.map +1 -1
  51. package/dist/L/emit.d.ts +4 -0
  52. package/dist/L/emit.js +6 -2
  53. package/dist/L/emit.js.map +1 -1
  54. package/dist/L/focus.d.ts +8 -0
  55. package/dist/L/focus.js +14 -0
  56. package/dist/L/focus.js.map +1 -0
  57. package/dist/L/infer.d.ts +4 -0
  58. package/dist/L/infer.js +11 -9
  59. package/dist/L/infer.js.map +1 -1
  60. package/dist/L/message.d.ts +4 -0
  61. package/dist/L/message.js +4 -0
  62. package/dist/L/message.js.map +1 -1
  63. package/dist/L/reflect.d.ts +1 -0
  64. package/dist/L/reflect.js +2 -1
  65. package/dist/L/reflect.js.map +1 -1
  66. package/dist/L/run.d.ts +3 -2
  67. package/dist/L/run.js +2 -2
  68. package/dist/L/run.js.map +1 -1
  69. package/dist/L/strand.d.ts +4 -0
  70. package/dist/L/strand.js +6 -2
  71. package/dist/L/strand.js.map +1 -1
  72. package/dist/L/stream.d.ts +1 -0
  73. package/dist/L/stream.js +4 -5
  74. package/dist/L/stream.js.map +1 -1
  75. package/dist/LEvent.d.ts +7 -7
  76. package/dist/LEvent.js +4 -4
  77. package/dist/LEvent.js.map +1 -1
  78. package/dist/Rune.d.ts +29 -8
  79. package/dist/Rune.js +2 -0
  80. package/dist/Rune.js.map +1 -1
  81. package/dist/Strand.d.ts +24 -0
  82. package/dist/Strand.js +27 -4
  83. package/dist/Strand.js.map +1 -1
  84. package/dist/index.d.ts +2 -2
  85. package/dist/index.js +2 -2
  86. package/dist/index.js.map +1 -1
  87. package/dist/tsconfig.tsbuildinfo +1 -1
  88. package/dist/util/JSONValue.d.ts +1 -1
  89. package/dist/util/JSONValue.js +21 -9
  90. package/dist/util/JSONValue.js.map +1 -1
  91. package/index.ts +2 -2
  92. package/package.json +1 -1
  93. package/util/JSONValue.ts +23 -8
  94. package/L/context.ts +0 -12
  95. package/L/model.ts +0 -13
  96. package/ModelRegistry.ts +0 -55
  97. package/dist/L/context.d.ts +0 -2
  98. package/dist/L/context.js +0 -12
  99. package/dist/L/context.js.map +0 -1
  100. package/dist/L/model.d.ts +0 -4
  101. package/dist/L/model.js +0 -10
  102. package/dist/L/model.js.map +0 -1
  103. package/dist/Model.js +0 -13
  104. package/dist/Model.js.map +0 -1
  105. package/dist/ModelRegistry.d.ts +0 -15
  106. package/dist/ModelRegistry.js +0 -43
  107. package/dist/ModelRegistry.js.map +0 -1
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
  }
@@ -1,10 +1,10 @@
1
1
  import type { Message } from "./Message.ts";
2
2
  import type { SchemaObject } from "./Schema.ts";
3
3
  import type { Tool } from "./Tool.ts";
4
- export declare class Model {
5
- readonly vendor: string;
4
+ export declare class Adapter {
5
+ readonly name: string;
6
6
  readonly seal: (envelope: Envelope) => SealedEnvelope;
7
- constructor(vendor: string, seal: (envelope: Envelope) => SealedEnvelope);
7
+ constructor(name: string, seal: (envelope: Envelope) => SealedEnvelope);
8
8
  }
9
9
  export interface Envelope {
10
10
  messages: Array<Message>;
@@ -13,6 +13,6 @@ export interface Envelope {
13
13
  tools?: Set<Tool> | undefined;
14
14
  }
15
15
  export interface SealedEnvelope {
16
- resolve(): Promise<string>;
17
- stream(): ReadableStream<string>;
16
+ resolve: () => Promise<string>;
17
+ stream: () => ReadableStream<string>;
18
18
  }
@@ -0,0 +1,13 @@
1
+ import { attachCustomInspect } from "./util/attachCustomInspect.js";
2
+ export class Adapter {
3
+ name;
4
+ seal;
5
+ constructor(name, seal) {
6
+ this.name = name;
7
+ this.seal = seal;
8
+ }
9
+ static {
10
+ attachCustomInspect(this, ({ name }) => ({ name }));
11
+ }
12
+ }
13
+ //# sourceMappingURL=Adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Adapter.js","sourceRoot":"","sources":["../Adapter.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAEnE,MAAM,OAAO,OAAO;IAEP;IACA;IAFX,YACW,IAAY,EACZ,IAA4C;QAD5C,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAwC;IACpD,CAAC;IAEJ;QACE,mBAAmB,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACrD,CAAC;CACF"}
@@ -0,0 +1,27 @@
1
+ import type { Adapter } from "./Adapter.ts";
2
+ /**
3
+ * An intrusive doubly-linked list for storing `Model`s.
4
+ * Provides efficient insertion, removal, and lookups.
5
+ */
6
+ export declare class AdapterRegistry {
7
+ head?: ModelRegistryNode | undefined;
8
+ tail?: ModelRegistryNode | undefined;
9
+ /** Returns the most recently registered model */
10
+ peek(): Adapter | undefined;
11
+ /** Ensure */
12
+ ensure(): Adapter;
13
+ /**
14
+ * Registers a new model and returns the created node
15
+ * @param value The model to register
16
+ */
17
+ register(value: Adapter): ModelRegistryNode;
18
+ /** Remove a model from the registry. */
19
+ remove(node: ModelRegistryNode): void;
20
+ /** Creates a deep copy of this registry. */
21
+ clone(): AdapterRegistry;
22
+ }
23
+ export interface ModelRegistryNode {
24
+ prev: ModelRegistryNode | undefined;
25
+ adapter: Adapter;
26
+ next?: ModelRegistryNode | undefined;
27
+ }
@@ -0,0 +1,62 @@
1
+ import { LiminalAssertionError } from "./LiminalAssertionError.js";
2
+ /**
3
+ * An intrusive doubly-linked list for storing `Model`s.
4
+ * Provides efficient insertion, removal, and lookups.
5
+ */
6
+ export class AdapterRegistry {
7
+ /** Returns the most recently registered model */
8
+ peek() {
9
+ return this.tail?.adapter;
10
+ }
11
+ /** Ensure */
12
+ ensure() {
13
+ LiminalAssertionError.assert(this.tail, "No conversation adapter registered. Use `L.focus` to focus a conversation adapter.");
14
+ return this.tail.adapter;
15
+ }
16
+ /**
17
+ * Registers a new model and returns the created node
18
+ * @param value The model to register
19
+ */
20
+ register(value) {
21
+ const node = {
22
+ prev: this.tail,
23
+ adapter: value,
24
+ };
25
+ if (this.tail) {
26
+ this.tail.next = node;
27
+ }
28
+ else {
29
+ this.head = node;
30
+ }
31
+ this.tail = node;
32
+ return node;
33
+ }
34
+ /** Remove a model from the registry. */
35
+ remove(node) {
36
+ if (node.prev) {
37
+ node.prev.next = node.next;
38
+ }
39
+ if (node.next) {
40
+ node.next.prev = node.prev;
41
+ }
42
+ if (node === this.head) {
43
+ this.head = node.next;
44
+ }
45
+ if (node === this.tail) {
46
+ this.tail = node.prev;
47
+ }
48
+ node.prev = undefined;
49
+ delete node.next;
50
+ }
51
+ /** Creates a deep copy of this registry. */
52
+ clone() {
53
+ const instance = new AdapterRegistry();
54
+ for (let node = this.head; node; node = node.next) {
55
+ if (node.adapter) {
56
+ instance.register(node.adapter);
57
+ }
58
+ }
59
+ return instance;
60
+ }
61
+ }
62
+ //# sourceMappingURL=AdapterRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdapterRegistry.js","sourceRoot":"","sources":["../AdapterRegistry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAElE;;;GAGG;AACH,MAAM,OAAO,eAAe;IAI1B,iDAAiD;IACjD,IAAI;QACF,OAAO,IAAI,CAAC,IAAI,EAAE,OAAO,CAAA;IAC3B,CAAC;IAED,aAAa;IACb,MAAM;QACJ,qBAAqB,CAAC,MAAM,CAC1B,IAAI,CAAC,IAAI,EACT,oFAAoF,CACrF,CAAA;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAA;IAC1B,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,KAAc;QACrB,MAAM,IAAI,GAAsB;YAC9B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,KAAK;SACf,CAAA;QACD,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QACvB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAClB,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,wCAAwC;IACxC,MAAM,CAAC,IAAuB;QAC5B,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QAC5B,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QAC5B,CAAC;QACD,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACvB,CAAC;QACD,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACvB,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,SAAS,CAAA;QACrB,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED,4CAA4C;IAC5C,KAAK;QACH,MAAM,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAA;QACtC,KAAK,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAClD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjB,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACjC,CAAC;QACH,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF"}
package/dist/Config.d.ts CHANGED
@@ -1,11 +1,11 @@
1
+ import { AdapterRegistry } from "./AdapterRegistry.ts";
1
2
  import type { Message } from "./Message.ts";
2
- import { ModelRegistry } from "./ModelRegistry.ts";
3
3
  import type { Rune } from "./Rune.ts";
4
4
  import type { Strand } from "./Strand.ts";
5
5
  import type { Tool } from "./Tool.ts";
6
6
  export interface Config<Y extends Rune<any> = Rune<any>, T = any> {
7
7
  handler?: ((this: Strand<Y, T>, event: Rune.E<Y>) => void) | undefined;
8
- models?: ModelRegistry | undefined;
8
+ models?: AdapterRegistry | undefined;
9
9
  messages?: Array<Message>;
10
10
  tools?: Set<Tool> | undefined;
11
11
  signal?: AbortSignal | undefined;
package/dist/Config.js CHANGED
@@ -1,2 +1,2 @@
1
- import { ModelRegistry } from "./ModelRegistry.js";
1
+ import { AdapterRegistry } from "./AdapterRegistry.js";
2
2
  //# sourceMappingURL=Config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Config.js","sourceRoot":"","sources":["../Config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA"}
1
+ {"version":3,"file":"Config.js","sourceRoot":"","sources":["../Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA"}
package/dist/Context.d.ts CHANGED
@@ -1,12 +1,31 @@
1
+ import { AdapterRegistry } from "./AdapterRegistry.ts";
1
2
  import type { Handler } from "./Handler.ts";
2
3
  import type { Message } from "./Message.ts";
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;
7
- readonly models: ModelRegistry;
17
+ /** Registry of available models for inference. */
18
+ readonly adapters: AdapterRegistry;
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,14 +1,19 @@
1
- import { ModelRegistry } from "./ModelRegistry.js";
1
+ import { AdapterRegistry } from "./AdapterRegistry.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
+ adapters: context?.adapters?.clone() ?? new AdapterRegistry(),
11
+ messages: [...(context?.messages ?? [])],
7
12
  tools: new Set(context?.tools),
8
13
  clone() {
9
14
  return {
10
15
  handler: this.handler,
11
- models: this.models.clone(),
16
+ adapters: this.adapters.clone(),
12
17
  messages: [...this.messages],
13
18
  tools: new Set(this.tools),
14
19
  clone: this.clone,
@@ -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":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AA2BtD;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,OAAgC;IACtD,OAAO;QACL,OAAO,EAAE,OAAO,EAAE,OAAO;QACzB,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,IAAI,eAAe,EAAE;QAC7D,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,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE;gBAC/B,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,12 +1,11 @@
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";
6
+ export * from "./focus.ts";
7
7
  export * from "./infer.ts";
8
8
  export * from "./message.ts";
9
- export * from "./model.ts";
10
9
  export * from "./reflect.ts";
11
10
  export * from "./run.ts";
12
11
  export * from "./schema/anyOf.ts";
package/dist/L/L.js CHANGED
@@ -1,12 +1,11 @@
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";
6
+ export * from "./focus.js";
7
7
  export * from "./infer.js";
8
8
  export * from "./message.js";
9
- export * from "./model.js";
10
9
  export * from "./reflect.js";
11
10
  export * from "./run.js";
12
11
  export * from "./schema/anyOf.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,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
+ {"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,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,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,GA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C,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 +1 @@
1
- {"version":3,"file":"assistant.js","sourceRoot":"","sources":["../../L/assistant.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,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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,C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T,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"}
@@ -0,0 +1,8 @@
1
+ import type { Adapter } from "../Adapter.ts";
2
+ import type { LEvent } from "../LEvent.ts";
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
+ */
8
+ export declare function focus(adapter: Adapter): Generator<Rune<LEvent>, Adapter>;
@@ -0,0 +1,14 @@
1
+ import { AdapterFocused } from "../LEvent.js";
2
+ import { emit } from "./emit.js";
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
+ */
8
+ export function* focus(adapter) {
9
+ const { context: { adapters } } = yield* reflect;
10
+ adapters.register(adapter);
11
+ yield* emit(new AdapterFocused(adapter));
12
+ return adapter;
13
+ }
14
+ //# sourceMappingURL=focus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus.js","sourceRoot":"","sources":["../../L/focus.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC;;;GAGG;AACH,MAAM,SAAS,CAAC,CAAC,KAAK,CAAC,OAAgB;IACrC,MAAM,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;IAChD,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;IACxC,OAAO,OAAO,CAAA;AAChB,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
@@ -1,24 +1,26 @@
1
1
  import { InferenceRequested, Inferred } from "../LEvent.js";
2
- import { LiminalAssertionError } from "../LiminalAssertionError.js";
3
2
  import { Schema } from "../Schema.js";
4
3
  import { continuation } from "./continuation.js";
5
4
  import { emit } from "./emit.js";
6
5
  import { reflect } from "./reflect.js";
6
+ /**
7
+ * Requests an inference from the current model, optionally with a schema.
8
+ * Emits inference-related events and returns the model's response as a string.
9
+ */
7
10
  export function* infer(schema) {
8
- const { context: { models, messages }, signal } = yield* reflect;
9
- const model = models.peek();
10
- LiminalAssertionError.assert(model);
11
+ const { context: { adapters: models, messages }, signal } = yield* reflect;
12
+ const model = models.ensure();
11
13
  const requestId = crypto.randomUUID();
12
14
  yield* emit(new InferenceRequested(requestId, schema));
13
- let inference = yield* continuation("infer", () => model.seal({
15
+ let inference = yield* continuation("infer", model
16
+ .seal({
14
17
  messages,
15
18
  ...schema && {
16
- schema: schema.type === "object"
17
- ? schema
18
- : Schema.wrap(schema),
19
+ schema: schema.type === "object" ? schema : Schema.wrap(schema),
19
20
  },
20
21
  signal,
21
- }).resolve());
22
+ })
23
+ .resolve);
22
24
  if (schema?.type && schema.type !== "object") {
23
25
  inference = JSON.stringify(JSON.parse(inference).value);
24
26
  }