liminal 0.5.14 → 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 (83) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/Context.ts +21 -4
  3. package/Definition.ts +16 -0
  4. package/L/L.ts +0 -1
  5. package/L/all.ts +4 -0
  6. package/L/assistant.ts +4 -0
  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 +4 -0
  12. package/L/model.ts +4 -0
  13. package/L/reflect.ts +2 -1
  14. package/L/run.ts +1 -0
  15. package/L/strand.ts +6 -2
  16. package/L/stream.ts +2 -1
  17. package/Model.ts +4 -4
  18. package/ModelRegistry.ts +16 -3
  19. package/Rune.ts +36 -7
  20. package/Strand.ts +37 -6
  21. package/dist/Context.d.ts +19 -0
  22. package/dist/Context.js +7 -2
  23. package/dist/Context.js.map +1 -1
  24. package/dist/Definition.d.ts +14 -0
  25. package/dist/Definition.js +11 -0
  26. package/dist/Definition.js.map +1 -1
  27. package/dist/L/L.d.ts +0 -1
  28. package/dist/L/L.js +0 -1
  29. package/dist/L/L.js.map +1 -1
  30. package/dist/L/all.d.ts +4 -0
  31. package/dist/L/all.js.map +1 -1
  32. package/dist/L/assistant.d.ts +4 -0
  33. package/dist/L/assistant.js.map +1 -1
  34. package/dist/L/catch.d.ts +4 -0
  35. package/dist/L/catch.js +4 -0
  36. package/dist/L/catch.js.map +1 -1
  37. package/dist/L/continuation.d.ts +1 -0
  38. package/dist/L/continuation.js +3 -2
  39. package/dist/L/continuation.js.map +1 -1
  40. package/dist/L/emit.d.ts +4 -0
  41. package/dist/L/emit.js +6 -2
  42. package/dist/L/emit.js.map +1 -1
  43. package/dist/L/infer.d.ts +4 -0
  44. package/dist/L/infer.js +9 -5
  45. package/dist/L/infer.js.map +1 -1
  46. package/dist/L/message.d.ts +4 -0
  47. package/dist/L/message.js +4 -0
  48. package/dist/L/message.js.map +1 -1
  49. package/dist/L/model.d.ts +4 -0
  50. package/dist/L/model.js +4 -0
  51. package/dist/L/model.js.map +1 -1
  52. package/dist/L/reflect.d.ts +1 -0
  53. package/dist/L/reflect.js +2 -1
  54. package/dist/L/reflect.js.map +1 -1
  55. package/dist/L/run.d.ts +1 -0
  56. package/dist/L/run.js.map +1 -1
  57. package/dist/L/strand.d.ts +4 -0
  58. package/dist/L/strand.js +6 -2
  59. package/dist/L/strand.js.map +1 -1
  60. package/dist/L/stream.d.ts +1 -0
  61. package/dist/L/stream.js +2 -1
  62. package/dist/L/stream.js.map +1 -1
  63. package/dist/Model.d.ts +4 -4
  64. package/dist/Model.js +4 -4
  65. package/dist/ModelRegistry.d.ts +11 -1
  66. package/dist/ModelRegistry.js +16 -3
  67. package/dist/ModelRegistry.js.map +1 -1
  68. package/dist/Rune.d.ts +29 -8
  69. package/dist/Rune.js +2 -0
  70. package/dist/Rune.js.map +1 -1
  71. package/dist/Strand.d.ts +24 -0
  72. package/dist/Strand.js +27 -4
  73. package/dist/Strand.js.map +1 -1
  74. package/dist/tsconfig.tsbuildinfo +1 -1
  75. package/dist/util/JSONValue.d.ts +1 -1
  76. package/dist/util/JSONValue.js +21 -9
  77. package/dist/util/JSONValue.js.map +1 -1
  78. package/package.json +1 -1
  79. package/util/JSONValue.ts +23 -8
  80. package/L/context.ts +0 -12
  81. package/dist/L/context.d.ts +0 -2
  82. package/dist/L/context.js +0 -12
  83. package/dist/L/context.js.map +0 -1
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";
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";
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,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,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AAU,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,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAMtC,MAAM,CAAC,MAAM,SAAS,GAAc,MAAM,CAAC,MAAM,CAC/C,QAAQ,CAAC,CAAC,SAAS,CAAI,MAAiB;IACtC,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,K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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,C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AAC,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
20
  ...schema && {
16
- schema: schema.type === "object"
17
- ? schema
18
- : Schema.wrap(schema),
21
+ schema: schema.type === "object" ? schema : Schema.wrap(schema),
19
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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une.ts";
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 declare function message(role: MessageRole, content: Array<Content>): Generator<Rune<LEvent>, void>;
package/dist/L/message.js CHANGED
@@ -1,6 +1,10 @@
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
10
  const message = { role, parts: content };
@@ -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,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"}
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>;
package/dist/L/reflect.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { Rune, RuneKey } from "../Rune.js";
2
+ /** Returns the current strand instance, providing access to context and parent information. */
2
3
  export const reflect = {
3
4
  *[Symbol.iterator]() {
4
5
  return yield {
5
6
  [RuneKey]: true,
6
- value: { kind: "reflect" },
7
+ instruction: { kind: "reflect" },
7
8
  };
8
9
  },
9
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"reflect.js","sourceRoot":"","sources":["../../L/reflect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAG1C,MAAM,CAAC,MAAM,OAAO,GAAmC;IACrD,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,OAAO,MAAM;YACX,CAAC,OAAO,CAAC,EAAE,IAAI;YACf,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;SAC3B,CAAA;IACH,CAAC;CACF,CAAA"}
1
+ {"version":3,"file":"reflect.js","sourceRoot":"","sources":["../../L/reflect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAG1C,+FAA+F;AAC/F,MAAM,CAAC,MAAM,OAAO,GAAmC;IACrD,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,OAAO,MAAM;YACX,CAAC,OAAO,CAAC,EAAE,IAAI;YACf,WAAW,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;SACjC,CAAA;IACH,CAAC;CACF,CAAA"}
package/dist/L/run.d.ts CHANGED
@@ -5,6 +5,7 @@ import { ModelRegistry } from "../ModelRegistry.ts";
5
5
  import type { Rune } from "../Rune.ts";
6
6
  import { Strand } from "../Strand.ts";
7
7
  import type { Tool } from "../Tool.ts";
8
+ /** Configuration options for running a definition. */
8
9
  export interface RunConfig<Y extends Rune<any>> {
9
10
  handler?: Handler<Y> | undefined;
10
11
  models?: ModelRegistry | undefined;
package/dist/L/run.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"run.js","sourceRoot":"","sources":["../../L/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAIvC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAWrC,MAAM,UAAU,GAAG,CAAyB,UAA4B,EAAE,MAAqB;IAC7F,MAAM,OAAO,GAAG,OAAO,CAAC;QACtB,OAAO,EAAE,MAAM,EAAE,OAAO;QACxB,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,IAAI,aAAa,EAAE;QAC7C,QAAQ,EAAE,MAAM,EAAE,QAAQ,IAAI,EAAE;QAChC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,IAAI,GAAG,EAAE;KAClC,CAAC,CAAA;IACF,OAAO,IAAI,MAAM,CAAC,UAAU,EAAE;QAC5B,MAAM,EAAE,MAAM,EAAE,MAAM;QACtB,GAAG,MAAM,IAAI,EAAE,OAAO,EAAE;KACzB,CAAC,CAAA;AACJ,CAAC"}
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../../L/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAIvC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAYrC,MAAM,UAAU,GAAG,CAAyB,UAA4B,EAAE,MAAqB;IAC7F,MAAM,OAAO,GAAG,OAAO,CAAC;QACtB,OAAO,EAAE,MAAM,EAAE,OAAO;QACxB,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,IAAI,aAAa,EAAE;QAC7C,QAAQ,EAAE,MAAM,EAAE,QAAQ,IAAI,EAAE;QAChC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,IAAI,GAAG,EAAE;KAClC,CAAC,CAAA;IACF,OAAO,IAAI,MAAM,CAAC,UAAU,EAAE;QAC5B,MAAM,EAAE,MAAM,EAAE,MAAM;QACtB,GAAG,MAAM,IAAI,EAAE,OAAO,EAAE;KACzB,CAAC,CAAA;AACJ,CAAC"}
@@ -2,4 +2,8 @@ import type { Context } from "../Context.ts";
2
2
  import type { Definition } from "../Definition.ts";
3
3
  import type { LEvent } from "../LEvent.ts";
4
4
  import { type Rune } from "../Rune.ts";
5
+ /**
6
+ * Creates a child strand that executes a definition.
7
+ * Optionally specify the context. Otherwise the current context is inherited.
8
+ */
5
9
  export declare function strand<Y extends Rune<any>, T>(definition: Definition<Y, T>, context?: Context): Generator<Rune<LEvent>, T>;
package/dist/L/strand.js CHANGED
@@ -1,9 +1,13 @@
1
1
  import { RuneKey } from "../Rune.js";
2
+ /**
3
+ * Creates a child strand that executes a definition.
4
+ * Optionally specify the context. Otherwise the current context is inherited.
5
+ */
2
6
  export function* strand(definition, context) {
3
7
  return yield {
4
8
  [RuneKey]: true,
5
- value: {
6
- kind: "child",
9
+ instruction: {
10
+ kind: "create_child",
7
11
  definition,
8
12
  context,
9
13
  },
@@ -1 +1 @@
1
- {"version":3,"file":"strand.js","sourceRoot":"","sources":["../../L/strand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,OAAO,EAAE,MAAM,YAAY,CAAA;AAE/C,MAAM,SAAS,CAAC,CAAC,MAAM,CACrB,UAA4B,EAC5B,OAAiB;IAEjB,OAAO,MAAM;QACX,CAAC,OAAO,CAAC,EAAE,IAAI;QACf,KAAK,EAAE;YACL,IAAI,EAAE,OAAO;YACb,UAAU;YACV,OAAO;SACR;KACF,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"strand.js","sourceRoot":"","sources":["../../L/strand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,OAAO,EAAE,MAAM,YAAY,CAAA;AAE/C;;;GAGG;AACH,MAAM,SAAS,CAAC,CAAC,MAAM,CACrB,UAA4B,EAC5B,OAAiB;IAEjB,OAAO,MAAM;QACX,CAAC,OAAO,CAAC,EAAE,IAAI;QACf,WAAW,EAAE;YACX,IAAI,EAAE,cAAc;YACpB,UAAU;YACV,OAAO;SACR;KACF,CAAA;AACH,CAAC"}
@@ -1,3 +1,4 @@
1
1
  import { type LEvent } from "../LEvent.ts";
2
2
  import type { Rune } from "../Rune.ts";
3
+ /** Creates a readable stream of content from the current model. */
3
4
  export declare const stream: Iterable<Rune<LEvent>, ReadableStream<string>>;
package/dist/L/stream.js CHANGED
@@ -3,6 +3,7 @@ import { LiminalAssertionError } from "../LiminalAssertionError.js";
3
3
  import { continuation } from "./continuation.js";
4
4
  import { emit } from "./emit.js";
5
5
  import { reflect } from "./reflect.js";
6
+ /** Creates a readable stream of content from the current model. */
6
7
  export const stream = {
7
8
  *[Symbol.iterator]() {
8
9
  const { context: { models, messages }, signal } = yield* reflect;
@@ -10,7 +11,7 @@ export const stream = {
10
11
  LiminalAssertionError.assert(model);
11
12
  const requestId = crypto.randomUUID();
12
13
  yield* emit(new InferenceRequested(requestId));
13
- return yield* continuation("stream", () => model.seal({ messages, signal }).stream());
14
+ return yield* continuation("stream", model.seal({ messages, signal }).stream);
14
15
  },
15
16
  };
16
17
  //# sourceMappingURL=stream.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../L/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAe,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAEnE,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,CAAC,MAAM,MAAM,GAAmD;IACpE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,MAAM,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;QAChE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,CAAA;QAC3B,qBAAqB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACnC,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,EAAE,CAAA;QACrC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAAA;QAC9C,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;IACvF,CAAC;CACF,CAAA"}
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../L/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAe,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,mEAAmE;AACnE,MAAM,CAAC,MAAM,MAAM,GAAmD;IACpE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,MAAM,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;QAChE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,CAAA;QAC3B,qBAAqB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACnC,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,EAAE,CAAA;QACrC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAAA;QAC9C,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;IAC/E,CAAC;CACF,CAAA"}
package/dist/Model.d.ts CHANGED
@@ -2,9 +2,9 @@ import type { Message } from "./Message.ts";
2
2
  import type { SchemaObject } from "./Schema.ts";
3
3
  import type { Tool } from "./Tool.ts";
4
4
  export declare class Model {
5
- readonly vendor: string;
5
+ readonly client: string;
6
6
  readonly seal: (envelope: Envelope) => SealedEnvelope;
7
- constructor(vendor: string, seal: (envelope: Envelope) => SealedEnvelope);
7
+ constructor(client: 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
  }
package/dist/Model.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { attachCustomInspect } from "./util/attachCustomInspect.js";
2
2
  export class Model {
3
- vendor;
3
+ client;
4
4
  seal;
5
- constructor(vendor, seal) {
6
- this.vendor = vendor;
5
+ constructor(client, seal) {
6
+ this.client = client;
7
7
  this.seal = seal;
8
8
  }
9
9
  static {
10
- attachCustomInspect(this, ({ vendor }) => ({ vendor }));
10
+ attachCustomInspect(this, ({ client }) => ({ client }));
11
11
  }
12
12
  }
13
13
  //# sourceMappingURL=Model.js.map
@@ -1,11 +1,21 @@
1
1
  import type { Model } from "./Model.ts";
2
- /** An intrusive list for storing `Model`s. */
2
+ /**
3
+ * An intrusive doubly-linked list for storing `Model`s.
4
+ * Provides efficient insertion, removal, and lookups.
5
+ */
3
6
  export declare class ModelRegistry {
4
7
  head?: ModelRegistryNode | undefined;
5
8
  tail?: ModelRegistryNode | undefined;
9
+ /** Returns the most recently registered model */
6
10
  peek(): Model | undefined;
11
+ /**
12
+ * Registers a new model and returns the created node
13
+ * @param value The model to register
14
+ */
7
15
  register(value: Model): ModelRegistryNode;
16
+ /** Remove a model from the registry. */
8
17
  remove(node: ModelRegistryNode): void;
18
+ /** Creates a deep copy of this registry. */
9
19
  clone(): ModelRegistry;
10
20
  }
11
21
  export interface ModelRegistryNode {
@@ -1,8 +1,16 @@
1
- /** An intrusive list for storing `Model`s. */
1
+ /**
2
+ * An intrusive doubly-linked list for storing `Model`s.
3
+ * Provides efficient insertion, removal, and lookups.
4
+ */
2
5
  export class ModelRegistry {
6
+ /** Returns the most recently registered model */
3
7
  peek() {
4
8
  return this.tail?.model;
5
9
  }
10
+ /**
11
+ * Registers a new model and returns the created node
12
+ * @param value The model to register
13
+ */
6
14
  register(value) {
7
15
  const node = {
8
16
  prev: this.tail,
@@ -17,6 +25,7 @@ export class ModelRegistry {
17
25
  this.tail = node;
18
26
  return node;
19
27
  }
28
+ /** Remove a model from the registry. */
20
29
  remove(node) {
21
30
  if (node.prev) {
22
31
  node.prev.next = node.next;
@@ -30,12 +39,16 @@ export class ModelRegistry {
30
39
  if (node === this.tail) {
31
40
  this.tail = node.prev;
32
41
  }
33
- node.prev = node.next = undefined;
42
+ node.prev = undefined;
43
+ delete node.next;
34
44
  }
45
+ /** Creates a deep copy of this registry. */
35
46
  clone() {
36
47
  const instance = new ModelRegistry();
37
48
  for (let node = this.head; node; node = node.next) {
38
- instance.register(node.model);
49
+ if (node.model) {
50
+ instance.register(node.model);
51
+ }
39
52
  }
40
53
  return instance;
41
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ModelRegistry.js","sourceRoot":"","sources":["../ModelRegistry.ts"],"names":[],"mappings":"AAEA,8CAA8C;AAC9C,MAAM,OAAO,aAAa;IAIxB,IAAI;QACF,OAAO,IAAI,CAAC,IAAI,EAAE,KAAK,CAAA;IACzB,CAAC;IAED,QAAQ,CAAC,KAAY;QACnB,MAAM,IAAI,GAAsB;YAC9B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,KAAK;SACb,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,MAAM,CAAC,IAAuB;QAC5B,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ts";
3
+ /**
4
+ * `Rune` represents a computational unit within a Strand execution.
5
+ * It is a specialized protocol for expressing different kinds of operations
6
+ * that can be yielded from generator functions to control message state
7
+ * and concurrency within the Liminal runtime.
8
+ * @template E The event type this Rune can handle
9
+ */
3
10
  export interface Rune<E> {
4
11
  [RuneKey]: true;
5
- value: {
6
- kind: "continuation";
12
+ instruction: RuneInstruction<E>;
13
+ }
14
+ export type RuneInstruction<E> = RuneInstruction.Continue | RuneInstruction.Emit<E> | RuneInstruction.Reflect | RuneInstruction.CreateChild;
15
+ export declare namespace RuneInstruction {
16
+ /** Tells the runtime to call this function and and pass the result to the next iteration. */
17
+ interface Continue {
18
+ kind: "continue";
7
19
  debug: string;
8
20
  f: () => any;
9
- } | {
10
- kind: "event";
21
+ }
22
+ /** Dispatch an event to the registered handler. */
23
+ interface Emit<E> {
24
+ kind: "emit";
11
25
  event: E;
12
- } | {
26
+ }
27
+ /** Tells the runtime to provide a reference to the current strand */
28
+ interface Reflect {
13
29
  kind: "reflect";
14
- } | {
15
- kind: "child";
30
+ }
31
+ /** Creates a nested execution context with its own definition. */
32
+ interface CreateChild {
33
+ kind: "create_child";
16
34
  definition: Definition;
17
35
  context?: Context | undefined;
18
- };
36
+ }
19
37
  }
20
38
  export declare namespace Rune {
39
+ /** Extract the event type from a Rune type. */
21
40
  type E<X extends Rune<any>> = X extends Rune<infer E> ? E : never;
41
+ /** Type guard to check if a value is a Rune. */
22
42
  function is(value: unknown): value is Rune<any>;
23
43
  }
44
+ /** Symbol used to identify Rune objects. */
24
45
  export declare const RuneKey: unique symbol;
25
46
  export type RuneKey = typeof RuneKey;
package/dist/Rune.js CHANGED
@@ -1,9 +1,11 @@
1
1
  export var Rune;
2
2
  (function (Rune) {
3
+ /** Type guard to check if a value is a Rune. */
3
4
  function is(value) {
4
5
  return typeof value === "object" && value !== null && RuneKey in value;
5
6
  }
6
7
  Rune.is = is;
7
8
  })(Rune || (Rune = {}));
9
+ /** Symbol used to identify Rune objects. */
8
10
  export const RuneKey = Symbol.for("liminal/RuneKey");
9
11
  //# sourceMappingURL=Rune.js.map
package/dist/Rune.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Rune.js","sourceRoot":"","sources":["../Rune.ts"],"names":[],"mappings":"AAqBA,MAAM,KAAW,IAAI,CAMpB;AAND,WAAiB,IAAI;IAGnB,SAAgB,EAAE,CAAC,KAAc;QAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,CAAA;IACxE,CAAC;IAFe,OAAE,KAEjB,CAAA;AACH,CAAC,EANgB,IAAI,KAAJ,IAAI,QAMpB;AAED,MAAM,CAAC,MAAM,OAAO,GAAkB,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA"}
1
+ {"version":3,"file":"Rune.js","sourceRoot":"","sources":["../Rune.ts"],"names":[],"mappings":"AA+CA,MAAM,KAAW,IAAI,CAQpB;AARD,WAAiB,IAAI;IAInB,gDAAgD;IAChD,SAAgB,EAAE,CAAC,KAAc;QAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,CAAA;IACxE,CAAC;IAFe,OAAE,KAEjB,CAAA;AACH,CAAC,EARgB,IAAI,KAAJ,IAAI,QAQpB;AAED,4CAA4C;AAC5C,MAAM,CAAC,MAAM,OAAO,GAAkB,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA"}
package/dist/Strand.d.ts CHANGED
@@ -1,20 +1,44 @@
1
1
  import { Context } from "./Context.ts";
2
2
  import { Definition } from "./Definition.ts";
3
3
  import type { Rune } from "./Rune.ts";
4
+ /** Configuration options for creating a new Strand. */
4
5
  export interface StrandConfig {
6
+ /** Optional parent strand that this strand will be a child of */
5
7
  parent?: Strand | undefined;
8
+ /** Optional context for the strand execution */
6
9
  context?: Context | undefined;
10
+ /** Optional abort signal that can be used to cancel strand execution */
7
11
  signal?: AbortSignal | undefined;
8
12
  }
13
+ /**
14
+ * A "Strand" is the core unit of execution in Liminal.
15
+ *
16
+ * It represents a suspendable computation that can yield Runes to control conversation state.
17
+ * Strands implement both the Iterable and PromiseLike interfaces to enable both
18
+ * running (via awaiting) and joining to parent strands (via yielding).
19
+ *
20
+ * Strands maintain their own state and can be hierarchically organized with parent-child
21
+ * relationships. Child strands are bound to their parents, ensuring consistent
22
+ * cancellation behavior.
23
+ *
24
+ * @template Y The type of Runes this Strand can yield.
25
+ * @template T The result type of the Strand.
26
+ */
9
27
  export declare class Strand<Y extends Rune<any> = Rune<any>, T = any> implements Iterable<Y, T>, PromiseLike<T> {
10
28
  #private;
11
29
  T: T;
12
30
  Y: Y;
31
+ /** Signal that can be used to detect when this strand is aborted. */
13
32
  readonly signal: AbortSignal;
33
+ /** Current status of the strand (untouched, pending, resolved, rejected) */
14
34
  status: StrandStatus<T>;
35
+ /** Unique identifier for this strand. */
15
36
  readonly index: number;
37
+ /** Nesting depth in the strand hierarchy. */
16
38
  readonly depth: number;
39
+ /** The parent strand or undefined. */
17
40
  readonly parent?: Strand;
41
+ /** The conversation state with which the strand operates. */
18
42
  readonly context: Context;
19
43
  constructor(definition: Definition<Y, T>, config: StrandConfig);
20
44
  then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;