liminal 0.5.15 → 0.5.17

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 (65) hide show
  1. package/{Model.ts → Adapter.ts} +3 -3
  2. package/{ModelRegistry.ts → AdapterRegistry.ts} +24 -14
  3. package/CHANGELOG.md +12 -0
  4. package/Config.ts +2 -2
  5. package/Context.ts +4 -4
  6. package/L/L.ts +1 -1
  7. package/L/focus.ts +17 -0
  8. package/L/infer.ts +2 -4
  9. package/L/run.ts +2 -3
  10. package/L/schema/_schema_common.ts +2 -1
  11. package/L/stream.ts +3 -5
  12. package/L/system.ts +2 -1
  13. package/L/user.ts +2 -1
  14. package/LEvent.ts +5 -5
  15. package/dist/{Model.d.ts → Adapter.d.ts} +3 -3
  16. package/dist/Adapter.js +13 -0
  17. package/dist/Adapter.js.map +1 -0
  18. package/dist/AdapterRegistry.d.ts +27 -0
  19. package/dist/{ModelRegistry.js → AdapterRegistry.js} +18 -12
  20. package/dist/AdapterRegistry.js.map +1 -0
  21. package/dist/Config.d.ts +2 -2
  22. package/dist/Config.js +1 -1
  23. package/dist/Config.js.map +1 -1
  24. package/dist/Context.d.ts +2 -2
  25. package/dist/Context.js +3 -3
  26. package/dist/Context.js.map +1 -1
  27. package/dist/L/L.d.ts +1 -1
  28. package/dist/L/L.js +1 -1
  29. package/dist/L/L.js.map +1 -1
  30. package/dist/L/{model.d.ts → focus.d.ts} +2 -2
  31. package/dist/L/focus.js +14 -0
  32. package/dist/L/focus.js.map +1 -0
  33. package/dist/L/infer.js +2 -4
  34. package/dist/L/infer.js.map +1 -1
  35. package/dist/L/run.d.ts +0 -2
  36. package/dist/L/run.js +2 -2
  37. package/dist/L/run.js.map +1 -1
  38. package/dist/L/schema/_schema_common.js +2 -1
  39. package/dist/L/schema/_schema_common.js.map +1 -1
  40. package/dist/L/stream.js +3 -5
  41. package/dist/L/stream.js.map +1 -1
  42. package/dist/L/system.js +2 -1
  43. package/dist/L/system.js.map +1 -1
  44. package/dist/L/user.js +2 -1
  45. package/dist/L/user.js.map +1 -1
  46. package/dist/LEvent.d.ts +7 -7
  47. package/dist/LEvent.js +4 -4
  48. package/dist/LEvent.js.map +1 -1
  49. package/dist/index.d.ts +2 -2
  50. package/dist/index.js +2 -2
  51. package/dist/index.js.map +1 -1
  52. package/dist/tsconfig.tsbuildinfo +1 -1
  53. package/dist/util/fixTemplateStrings.d.ts +11 -0
  54. package/dist/util/fixTemplateStrings.js +83 -0
  55. package/dist/util/fixTemplateStrings.js.map +1 -0
  56. package/index.ts +2 -2
  57. package/package.json +1 -1
  58. package/util/fixTemplateStrings.ts +99 -0
  59. package/L/model.ts +0 -17
  60. package/dist/L/model.js +0 -14
  61. package/dist/L/model.js.map +0 -1
  62. package/dist/Model.js +0 -13
  63. package/dist/Model.js.map +0 -1
  64. package/dist/ModelRegistry.d.ts +0 -25
  65. package/dist/ModelRegistry.js.map +0 -1
@@ -3,14 +3,14 @@ import type { SchemaObject } from "./Schema.ts"
3
3
  import type { Tool } from "./Tool.ts"
4
4
  import { attachCustomInspect } from "./util/attachCustomInspect.ts"
5
5
 
6
- export class Model {
6
+ export class Adapter {
7
7
  constructor(
8
- readonly client: string,
8
+ readonly name: string,
9
9
  readonly seal: (envelope: Envelope) => SealedEnvelope,
10
10
  ) {}
11
11
 
12
12
  static {
13
- attachCustomInspect(this, ({ client }) => ({ client }))
13
+ attachCustomInspect(this, ({ name }) => ({ name }))
14
14
  }
15
15
  }
16
16
 
@@ -1,26 +1,36 @@
1
- import type { Model } from "./Model.ts"
1
+ import type { Adapter } from "./Adapter.ts"
2
+ import { LiminalAssertionError } from "./LiminalAssertionError.ts"
2
3
 
3
4
  /**
4
- * An intrusive doubly-linked list for storing `Model`s.
5
+ * An intrusive doubly-linked list for storing `Adapter`s.
5
6
  * Provides efficient insertion, removal, and lookups.
6
7
  */
7
- export class ModelRegistry {
8
+ export class AdapterRegistry {
8
9
  declare head?: ModelRegistryNode | undefined
9
10
  declare tail?: ModelRegistryNode | undefined
10
11
 
11
- /** Returns the most recently registered model */
12
+ /** Returns the most recently registered adapter */
12
13
  peek() {
13
- return this.tail?.model
14
+ return this.tail?.adapter
15
+ }
16
+
17
+ /** Ensure */
18
+ ensure(): Adapter {
19
+ LiminalAssertionError.assert(
20
+ this.tail,
21
+ "No conversation adapter registered. Use `L.focus` to focus a conversation adapter.",
22
+ )
23
+ return this.tail.adapter
14
24
  }
15
25
 
16
26
  /**
17
- * Registers a new model and returns the created node
18
- * @param value The model to register
27
+ * Registers a new adapter and returns the created node
28
+ * @param value The adapter to register
19
29
  */
20
- register(value: Model): ModelRegistryNode {
30
+ register(value: Adapter): ModelRegistryNode {
21
31
  const node: ModelRegistryNode = {
22
32
  prev: this.tail,
23
- model: value,
33
+ adapter: value,
24
34
  }
25
35
  if (this.tail) {
26
36
  this.tail.next = node
@@ -31,7 +41,7 @@ export class ModelRegistry {
31
41
  return node
32
42
  }
33
43
 
34
- /** Remove a model from the registry. */
44
+ /** Remove a adapter from the registry. */
35
45
  remove(node: ModelRegistryNode) {
36
46
  if (node.prev) {
37
47
  node.prev.next = node.next
@@ -51,10 +61,10 @@ export class ModelRegistry {
51
61
 
52
62
  /** Creates a deep copy of this registry. */
53
63
  clone() {
54
- const instance = new ModelRegistry()
64
+ const instance = new AdapterRegistry()
55
65
  for (let node = this.head; node; node = node.next) {
56
- if (node.model) {
57
- instance.register(node.model)
66
+ if (node.adapter) {
67
+ instance.register(node.adapter)
58
68
  }
59
69
  }
60
70
  return instance
@@ -63,6 +73,6 @@ export class ModelRegistry {
63
73
 
64
74
  export interface ModelRegistryNode {
65
75
  prev: ModelRegistryNode | undefined
66
- model: Model
76
+ adapter: Adapter
67
77
  next?: ModelRegistryNode | undefined
68
78
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # liminal
2
2
 
3
+ ## 0.5.17
4
+
5
+ ### Patch Changes
6
+
7
+ - 5c421c8: Re-add string dedenting for template-fn-style usage of user, system and schema.
8
+
9
+ ## 0.5.16
10
+
11
+ ### Patch Changes
12
+
13
+ - 6e70190: Renaming Model to Adapter and L.model to L.focus
14
+
3
15
  ## 0.5.15
4
16
 
5
17
  ### Patch Changes
package/Config.ts CHANGED
@@ -1,12 +1,12 @@
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
 
7
7
  export interface Config<Y extends Rune<any> = Rune<any>, T = any> {
8
8
  handler?: ((this: Strand<Y, T>, event: Rune.E<Y>) => void) | undefined
9
- models?: ModelRegistry | undefined
9
+ models?: AdapterRegistry | undefined
10
10
  messages?: Array<Message>
11
11
  tools?: Set<Tool> | undefined
12
12
  signal?: AbortSignal | undefined
package/Context.ts CHANGED
@@ -1,6 +1,6 @@
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
5
 
6
6
  /**
@@ -16,7 +16,7 @@ export interface Context {
16
16
  /** Event handler for processing events during strand execution. */
17
17
  readonly handler: Handler | undefined
18
18
  /** Registry of available models for inference. */
19
- readonly models: ModelRegistry
19
+ readonly adapters: AdapterRegistry
20
20
  /** Accumulated message history. */
21
21
  readonly messages: Array<Message>
22
22
  /** Set of tools available to the models. */
@@ -33,13 +33,13 @@ export interface Context {
33
33
  export function Context(context?: Omit<Context, "clone">): Context {
34
34
  return {
35
35
  handler: context?.handler,
36
- models: context?.models?.clone() ?? new ModelRegistry(),
36
+ adapters: context?.adapters?.clone() ?? new AdapterRegistry(),
37
37
  messages: [...(context?.messages ?? [])],
38
38
  tools: new Set(context?.tools),
39
39
  clone(): Context {
40
40
  return {
41
41
  handler: this.handler,
42
- models: this.models.clone(),
42
+ adapters: this.adapters.clone(),
43
43
  messages: [...this.messages],
44
44
  tools: new Set(this.tools),
45
45
  clone: this.clone,
package/L/L.ts CHANGED
@@ -3,9 +3,9 @@ export * from "./assistant.ts"
3
3
  export * from "./catch.ts"
4
4
  export * from "./continuation.ts"
5
5
  export * from "./emit.ts"
6
+ export * from "./focus.ts"
6
7
  export * from "./infer.ts"
7
8
  export * from "./message.ts"
8
- export * from "./model.ts"
9
9
  export * from "./reflect.ts"
10
10
  export * from "./run.ts"
11
11
  export * from "./schema/anyOf.ts"
package/L/focus.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { Adapter } from "../Adapter.ts"
2
+ import type { LEvent } from "../LEvent.ts"
3
+ import { AdapterFocused } from "../LEvent.ts"
4
+ import type { Rune } from "../Rune.ts"
5
+ import { emit } from "./emit.ts"
6
+ import { reflect } from "./reflect.ts"
7
+
8
+ /**
9
+ * Registers a model in the current context and emits a model registration event.
10
+ * Returns the registered model instance.
11
+ */
12
+ export function* focus(adapter: Adapter): Generator<Rune<LEvent>, Adapter> {
13
+ const { context: { adapters } } = yield* reflect
14
+ adapters.register(adapter)
15
+ yield* emit(new AdapterFocused(adapter))
16
+ return adapter
17
+ }
package/L/infer.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { InferenceRequested, Inferred, type LEvent } from "../LEvent.ts"
2
- import { LiminalAssertionError } from "../LiminalAssertionError.ts"
3
2
  import type { Rune } from "../Rune.ts"
4
3
  import { Schema } from "../Schema.ts"
5
4
  import { continuation } from "./continuation.ts"
@@ -11,9 +10,8 @@ import { reflect } from "./reflect.ts"
11
10
  * Emits inference-related events and returns the model's response as a string.
12
11
  */
13
12
  export function* infer(schema?: Schema): Generator<Rune<LEvent>, string> {
14
- const { context: { models, messages }, signal } = yield* reflect
15
- const model = models.peek()
16
- LiminalAssertionError.assert(model)
13
+ const { context: { adapters: models, messages }, signal } = yield* reflect
14
+ const model = models.ensure()
17
15
  const requestId = crypto.randomUUID()
18
16
  yield* emit(new InferenceRequested(requestId, schema))
19
17
  let inference = yield* continuation(
package/L/run.ts CHANGED
@@ -1,8 +1,8 @@
1
+ import { AdapterRegistry } from "../AdapterRegistry.ts"
1
2
  import { Context } from "../Context.ts"
2
3
  import type { Definition } from "../Definition.ts"
3
4
  import type { Handler } from "../Handler.ts"
4
5
  import type { Message } from "../Message.ts"
5
- import { ModelRegistry } from "../ModelRegistry.ts"
6
6
  import type { Rune } from "../Rune.ts"
7
7
  import { Strand } from "../Strand.ts"
8
8
  import type { Tool } from "../Tool.ts"
@@ -10,7 +10,6 @@ import type { Tool } from "../Tool.ts"
10
10
  /** Configuration options for running a definition. */
11
11
  export interface RunConfig<Y extends Rune<any>> {
12
12
  handler?: Handler<Y> | undefined
13
- models?: ModelRegistry | undefined
14
13
  messages?: Array<Message> | undefined
15
14
  tools?: Set<Tool> | undefined
16
15
  signal?: AbortSignal | undefined
@@ -19,7 +18,7 @@ export interface RunConfig<Y extends Rune<any>> {
19
18
  export function run<Y extends Rune<any>, T>(definition: Definition<Y, T>, config?: RunConfig<Y>): Strand<Y, T> {
20
19
  const context = Context({
21
20
  handler: config?.handler,
22
- models: config?.models ?? new ModelRegistry(),
21
+ adapters: new AdapterRegistry(),
23
22
  messages: config?.messages ?? [],
24
23
  tools: config?.tools ?? new Set(),
25
24
  })
@@ -1,4 +1,5 @@
1
1
  import type { Schema } from "../../Schema.ts"
2
+ import { fixTemplateStrings } from "../../util/fixTemplateStrings.ts"
2
3
  import { isTemplateStringsArray } from "../../util/isTemplateStringsArray.ts"
3
4
 
4
5
  export function make<S extends Schema>(schema: Omit<S, "T">, description?: string): S & TypeBase {
@@ -8,7 +9,7 @@ export function make<S extends Schema>(schema: Omit<S, "T">, description?: strin
8
9
  }
9
10
 
10
11
  const Type = Object.assign(function describe(e0?: TemplateStringsArray | string, ...rest: Array<string>) {
11
- const junction = isTemplateStringsArray(e0) ? String.raw(e0, ...rest) : e0
12
+ const junction = isTemplateStringsArray(e0) ? String.raw(fixTemplateStrings(e0), ...rest) : e0
12
13
  return make(
13
14
  schema_,
14
15
  description ? `${description}${junction ? `\n\n${junction}` : ""}` : junction,
package/L/stream.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { InferenceRequested, type LEvent } from "../LEvent.ts"
2
- import { LiminalAssertionError } from "../LiminalAssertionError.ts"
3
2
  import type { Rune } from "../Rune.ts"
4
3
  import { continuation } from "./continuation.ts"
5
4
  import { emit } from "./emit.ts"
@@ -8,11 +7,10 @@ import { reflect } from "./reflect.ts"
8
7
  /** Creates a readable stream of content from the current model. */
9
8
  export const stream: Iterable<Rune<LEvent>, ReadableStream<string>> = {
10
9
  *[Symbol.iterator]() {
11
- const { context: { models, messages }, signal } = yield* reflect
12
- const model = models.peek()
13
- LiminalAssertionError.assert(model)
10
+ const { context: { adapters, messages }, signal } = yield* reflect
11
+ const adapter = adapters.ensure()
14
12
  const requestId = crypto.randomUUID()
15
13
  yield* emit(new InferenceRequested(requestId))
16
- return yield* continuation("stream", model.seal({ messages, signal }).stream)
14
+ return yield* continuation("stream", adapter.seal({ messages, signal }).stream)
17
15
  },
18
16
  }
package/L/system.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { LEvent } from "../LEvent.ts"
2
2
  import type { Rune } from "../Rune.ts"
3
+ import { fixTemplateStrings } from "../util/fixTemplateStrings.ts"
3
4
  import { isTemplateStringsArray } from "../util/isTemplateStringsArray.ts"
4
5
  import { message } from "./message.ts"
5
6
 
@@ -13,6 +14,6 @@ export function system(
13
14
  ...rest: Array<number | string>
14
15
  ): Generator<Rune<LEvent>, void> {
15
16
  return message("system", [{
16
- part: isTemplateStringsArray(e0) ? String.raw(e0, ...rest) : e0,
17
+ part: isTemplateStringsArray(e0) ? String.raw(fixTemplateStrings(e0), ...rest) : e0,
17
18
  }])
18
19
  }
package/L/user.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { LEvent } from "../LEvent.ts"
2
2
  import type { Rune } from "../Rune.ts"
3
+ import { fixTemplateStrings } from "../util/fixTemplateStrings.ts"
3
4
  import { isTemplateStringsArray } from "../util/isTemplateStringsArray.ts"
4
5
  import { message } from "./message.ts"
5
6
 
@@ -13,6 +14,6 @@ export function user(
13
14
  ...rest: Array<number | string>
14
15
  ): Generator<Rune<LEvent>, void> {
15
16
  return message("user", [{
16
- part: isTemplateStringsArray(e0) ? String.raw(e0, ...rest) : e0,
17
+ part: isTemplateStringsArray(e0) ? String.raw(fixTemplateStrings(e0), ...rest) : e0,
17
18
  }])
18
19
  }
package/LEvent.ts CHANGED
@@ -1,15 +1,15 @@
1
+ import type { Adapter } from "./Adapter.ts"
1
2
  import { EventBase } from "./EventBase.ts"
2
3
  import type { Message } from "./Message.ts"
3
- import type { Model } from "./Model.ts"
4
4
  import type { Schema } from "./Schema.ts"
5
5
  import type { StrandStatus } from "./Strand.ts"
6
6
 
7
7
  export type LEvent =
8
- | StrandStatusChanged
8
+ | AdapterFocused
9
9
  | InferenceRequested
10
10
  | Inferred
11
11
  | MessageAppended
12
- | ModelRegistered
12
+ | StrandStatusChanged
13
13
 
14
14
  export namespace LEvent {
15
15
  export function is(value: unknown): value is LEvent {
@@ -20,8 +20,8 @@ export namespace LEvent {
20
20
  export const LEventTag: unique symbol = Symbol.for("liminal/LEvent")
21
21
  export type LEventTag = typeof LEventTag
22
22
 
23
- export class ModelRegistered extends EventBase(LEventTag, "model_registered") {
24
- constructor(readonly model: Model) {
23
+ export class AdapterFocused extends EventBase(LEventTag, "adapter_focused") {
24
+ constructor(readonly adapter: Adapter) {
25
25
  super()
26
26
  }
27
27
  }
@@ -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 client: string;
4
+ export declare class Adapter {
5
+ readonly name: string;
6
6
  readonly seal: (envelope: Envelope) => SealedEnvelope;
7
- constructor(client: 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>;
@@ -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 `Adapter`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 adapter */
10
+ peek(): Adapter | undefined;
11
+ /** Ensure */
12
+ ensure(): Adapter;
13
+ /**
14
+ * Registers a new adapter and returns the created node
15
+ * @param value The adapter to register
16
+ */
17
+ register(value: Adapter): ModelRegistryNode;
18
+ /** Remove a adapter 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
+ }
@@ -1,20 +1,26 @@
1
+ import { LiminalAssertionError } from "./LiminalAssertionError.js";
1
2
  /**
2
- * An intrusive doubly-linked list for storing `Model`s.
3
+ * An intrusive doubly-linked list for storing `Adapter`s.
3
4
  * Provides efficient insertion, removal, and lookups.
4
5
  */
5
- export class ModelRegistry {
6
- /** Returns the most recently registered model */
6
+ export class AdapterRegistry {
7
+ /** Returns the most recently registered adapter */
7
8
  peek() {
8
- return this.tail?.model;
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;
9
15
  }
10
16
  /**
11
- * Registers a new model and returns the created node
12
- * @param value The model to register
17
+ * Registers a new adapter and returns the created node
18
+ * @param value The adapter to register
13
19
  */
14
20
  register(value) {
15
21
  const node = {
16
22
  prev: this.tail,
17
- model: value,
23
+ adapter: value,
18
24
  };
19
25
  if (this.tail) {
20
26
  this.tail.next = node;
@@ -25,7 +31,7 @@ export class ModelRegistry {
25
31
  this.tail = node;
26
32
  return node;
27
33
  }
28
- /** Remove a model from the registry. */
34
+ /** Remove a adapter from the registry. */
29
35
  remove(node) {
30
36
  if (node.prev) {
31
37
  node.prev.next = node.next;
@@ -44,13 +50,13 @@ export class ModelRegistry {
44
50
  }
45
51
  /** Creates a deep copy of this registry. */
46
52
  clone() {
47
- const instance = new ModelRegistry();
53
+ const instance = new AdapterRegistry();
48
54
  for (let node = this.head; node; node = node.next) {
49
- if (node.model) {
50
- instance.register(node.model);
55
+ if (node.adapter) {
56
+ instance.register(node.adapter);
51
57
  }
52
58
  }
53
59
  return instance;
54
60
  }
55
61
  }
56
- //# sourceMappingURL=ModelRegistry.js.map
62
+ //# sourceMappingURL=AdapterRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"A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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,6 +1,6 @@
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
5
  /**
6
6
  * Context represents the execution environment for a Strand.
@@ -15,7 +15,7 @@ export interface Context {
15
15
  /** Event handler for processing events during strand execution. */
16
16
  readonly handler: Handler | undefined;
17
17
  /** Registry of available models for inference. */
18
- readonly models: ModelRegistry;
18
+ readonly adapters: AdapterRegistry;
19
19
  /** Accumulated message history. */
20
20
  readonly messages: Array<Message>;
21
21
  /** Set of tools available to the models. */
package/dist/Context.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ModelRegistry } from "./ModelRegistry.js";
1
+ import { AdapterRegistry } from "./AdapterRegistry.js";
2
2
  /**
3
3
  * Factory function to create a new Context.
4
4
  * @param context Optional base context from which to initialize.
@@ -7,13 +7,13 @@ import { ModelRegistry } from "./ModelRegistry.js";
7
7
  export function Context(context) {
8
8
  return {
9
9
  handler: context?.handler,
10
- models: context?.models?.clone() ?? new ModelRegistry(),
10
+ adapters: context?.adapters?.clone() ?? new AdapterRegistry(),
11
11
  messages: [...(context?.messages ?? [])],
12
12
  tools: new Set(context?.tools),
13
13
  clone() {
14
14
  return {
15
15
  handler: this.handler,
16
- models: this.models.clone(),
16
+ adapters: this.adapters.clone(),
17
17
  messages: [...this.messages],
18
18
  tools: new Set(this.tools),
19
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;AAyBlD;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,OAAgC;IACtD,OAAO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I,CAAC,KAAK,CAAC;gBAC1B,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
package/dist/L/L.d.ts CHANGED
@@ -3,9 +3,9 @@ export * from "./assistant.ts";
3
3
  export * from "./catch.ts";
4
4
  export * from "./continuation.ts";
5
5
  export * from "./emit.ts";
6
+ export * from "./focus.ts";
6
7
  export * from "./infer.ts";
7
8
  export * from "./message.ts";
8
- export * from "./model.ts";
9
9
  export * from "./reflect.ts";
10
10
  export * from "./run.ts";
11
11
  export * from "./schema/anyOf.ts";
package/dist/L/L.js CHANGED
@@ -3,9 +3,9 @@ export * from "./assistant.js";
3
3
  export * from "./catch.js";
4
4
  export * from "./continuation.js";
5
5
  export * from "./emit.js";
6
+ export * from "./focus.js";
6
7
  export * from "./infer.js";
7
8
  export * from "./message.js";
8
- export * from "./model.js";
9
9
  export * from "./reflect.js";
10
10
  export * from "./run.js";
11
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,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"}
@@ -1,8 +1,8 @@
1
+ import type { Adapter } from "../Adapter.ts";
1
2
  import type { LEvent } from "../LEvent.ts";
2
- import type { Model } from "../Model.ts";
3
3
  import type { Rune } from "../Rune.ts";
4
4
  /**
5
5
  * Registers a model in the current context and emits a model registration event.
6
6
  * Returns the registered model instance.
7
7
  */
8
- export declare function model(model: Model): Generator<Rune<LEvent>, Model>;
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.js CHANGED
@@ -1,5 +1,4 @@
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";
@@ -9,9 +8,8 @@ import { reflect } from "./reflect.js";
9
8
  * Emits inference-related events and returns the model's response as a string.
10
9
  */
11
10
  export function* infer(schema) {
12
- const { context: { models, messages }, signal } = yield* reflect;
13
- const model = models.peek();
14
- LiminalAssertionError.assert(model);
11
+ const { context: { adapters: models, messages }, signal } = yield* reflect;
12
+ const model = models.ensure();
15
13
  const requestId = crypto.randomUUID();
16
14
  yield* emit(new InferenceRequested(requestId, schema));
17
15
  let inference = yield* continuation("infer", model
@@ -1 +1 @@
1
- {"version":3,"file":"infer.js","sourceRoot":"","sources":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