liminal 0.5.3 → 0.5.4

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 (93) hide show
  1. package/Agent.ts +5 -5
  2. package/CHANGELOG.md +9 -0
  3. package/EventBase.ts +13 -0
  4. package/Fiber.ts +42 -92
  5. package/Globals.ts +1 -1
  6. package/L/L.ts +0 -1
  7. package/L/_infer.ts +27 -22
  8. package/L/_message.ts +5 -7
  9. package/L/assistant.ts +2 -9
  10. package/L/branch.ts +30 -24
  11. package/L/emit.ts +2 -3
  12. package/L/fork.ts +18 -16
  13. package/L/model.ts +3 -2
  14. package/L/rune.ts +2 -2
  15. package/L/self.ts +3 -3
  16. package/LEvent.ts +40 -17
  17. package/Rune.ts +2 -2
  18. package/dist/Agent.d.ts +1 -1
  19. package/dist/Agent.js +4 -5
  20. package/dist/Agent.js.map +1 -1
  21. package/dist/EventBase.d.ts +7 -0
  22. package/dist/EventBase.js +14 -0
  23. package/dist/EventBase.js.map +1 -0
  24. package/dist/Fiber.d.ts +8 -22
  25. package/dist/Fiber.js +32 -74
  26. package/dist/Fiber.js.map +1 -1
  27. package/dist/Globals.d.ts +0 -1
  28. package/dist/L/L.d.ts +0 -1
  29. package/dist/L/L.js +0 -1
  30. package/dist/L/L.js.map +1 -1
  31. package/dist/L/_infer.d.ts +2 -2
  32. package/dist/L/_infer.js +19 -16
  33. package/dist/L/_infer.js.map +1 -1
  34. package/dist/L/_message.js +5 -7
  35. package/dist/L/_message.js.map +1 -1
  36. package/dist/L/assistant.js +2 -7
  37. package/dist/L/assistant.js.map +1 -1
  38. package/dist/L/branch.js +31 -22
  39. package/dist/L/branch.js.map +1 -1
  40. package/dist/L/emit.js +2 -3
  41. package/dist/L/emit.js.map +1 -1
  42. package/dist/L/fork.d.ts +1 -7
  43. package/dist/L/fork.js +19 -10
  44. package/dist/L/fork.js.map +1 -1
  45. package/dist/L/model.js +3 -2
  46. package/dist/L/model.js.map +1 -1
  47. package/dist/L/rune.d.ts +2 -2
  48. package/dist/L/rune.js.map +1 -1
  49. package/dist/L/self.d.ts +2 -2
  50. package/dist/L/self.js +1 -1
  51. package/dist/L/self.js.map +1 -1
  52. package/dist/LEvent.d.ts +22 -19
  53. package/dist/LEvent.js +44 -0
  54. package/dist/LEvent.js.map +1 -1
  55. package/dist/Rune.d.ts +2 -2
  56. package/dist/index.d.ts +2 -0
  57. package/dist/index.js +2 -0
  58. package/dist/index.js.map +1 -1
  59. package/dist/run.d.ts +3 -0
  60. package/dist/run.js +35 -0
  61. package/dist/run.js.map +1 -0
  62. package/dist/state/Context.d.ts +8 -0
  63. package/dist/state/Context.js +17 -0
  64. package/dist/state/Context.js.map +1 -0
  65. package/dist/state/MessageRegistry.d.ts +1 -0
  66. package/dist/state/MessageRegistry.js +3 -0
  67. package/dist/state/MessageRegistry.js.map +1 -1
  68. package/dist/state/ModelRegistry.d.ts +1 -0
  69. package/dist/state/ModelRegistry.js +9 -0
  70. package/dist/state/ModelRegistry.js.map +1 -1
  71. package/dist/state/StateMap.d.ts +3 -2
  72. package/dist/state/StateMap.js +8 -0
  73. package/dist/state/StateMap.js.map +1 -1
  74. package/dist/tsconfig.tsbuildinfo +1 -1
  75. package/index.ts +2 -0
  76. package/package.json +3 -4
  77. package/run.ts +39 -0
  78. package/state/Context.ts +19 -0
  79. package/state/MessageRegistry.ts +4 -0
  80. package/state/ModelRegistry.ts +10 -0
  81. package/state/StateMap.ts +11 -2
  82. package/L/state.ts +0 -20
  83. package/dist/L/state.d.ts +0 -7
  84. package/dist/L/state.js +0 -14
  85. package/dist/L/state.js.map +0 -1
  86. package/dist/state/Counter.d.ts +0 -6
  87. package/dist/state/Counter.js +0 -13
  88. package/dist/state/Counter.js.map +0 -1
  89. package/dist/state/DefaultStateMap.d.ts +0 -4
  90. package/dist/state/DefaultStateMap.js +0 -14
  91. package/dist/state/DefaultStateMap.js.map +0 -1
  92. package/state/Counter.ts +0 -11
  93. package/state/DefaultStateMap.ts +0 -14
package/Agent.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Fiber, type FiberInfo } from "./Fiber.ts"
1
+ import type { FiberConfig, FiberInfo } from "./Fiber.ts"
2
+ import { run } from "./run.ts"
2
3
  import type { Rune, RuneKey } from "./Rune.ts"
3
4
  import type { Runic } from "./Runic.ts"
4
5
 
@@ -10,14 +11,13 @@ export interface Agent<out T, out E> extends PromiseLike<T> {
10
11
  export function Agent<Y extends Rune, T>(runic: Runic<Y, T>, config?: AgentConfig<Y, T>): Agent<T, Rune.E<Y>> {
11
12
  return {
12
13
  then(onfulfilled, onrejected) {
13
- const root = Fiber({
14
+ return run(runic, {
15
+ T: null!,
14
16
  globals: {
15
17
  handler: config?.handler ?? (() => {}),
16
18
  },
17
- runic,
18
19
  signal: config?.signal,
19
- })
20
- return root.run().then(onfulfilled, onrejected)
20
+ }).then(onfulfilled, onrejected)
21
21
  },
22
22
  } satisfies Omit<Agent<T, Rune.E<Y>>, "E" | "T"> as never
23
23
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # liminal
2
2
 
3
+ ## 0.5.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 284adab: Reintroduce AI SDK adapter and begin simplifying runic execution.
8
+ - Updated dependencies [284adab]
9
+ - liminal-schema@0.0.2
10
+ - liminal-util@0.0.2
11
+
3
12
  ## 0.5.3
4
13
 
5
14
  ### Patch Changes
package/EventBase.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { inspect, type InspectOptions } from "node:util"
2
+
3
+ export abstract class EventBase<B extends symbol, K extends string> {
4
+ constructor(
5
+ readonly brand: B,
6
+ readonly type: K,
7
+ ) {}
8
+
9
+ [inspect.custom](depth: number, options: InspectOptions) {
10
+ const { brand: _0, type: _1, ...rest } = this
11
+ return `${this.constructor.name} ` + inspect(rest, { ...options, depth })
12
+ }
13
+ }
package/Fiber.ts CHANGED
@@ -1,32 +1,18 @@
1
+ import { assert } from "liminal-util"
1
2
  import type { Globals } from "./Globals.ts"
2
- import { type FiberCreated, type FiberResolved, type FiberStarted, LEventTag } from "./LEvent.ts"
3
+ import { FiberCreated, FiberResolved, FiberStarted } from "./LEvent.ts"
3
4
  import type { Rune } from "./Rune.ts"
4
5
  import { Runic } from "./Runic.ts"
5
- import { DefaultStateMap } from "./state/DefaultStateMap.ts"
6
- import { StateMap } from "./state/StateMap.ts"
6
+ import type { StateMap } from "./state/StateMap.ts"
7
7
 
8
8
  export interface Fiber<out T = any> {
9
9
  T: T
10
+ runic: Runic<Rune, T>
11
+ globals: Globals
10
12
  parent: Fiber<any> | undefined
11
- status: FiberStatus<T>
12
13
  fiberId: number
13
- state: StateMap
14
- globals: Globals
15
- run(this: this): Promise<T>
16
14
  handler<E>(event: E): void
17
- }
18
-
19
- export type FiberStatus<T> = {
20
- type: "untouched"
21
- } | {
22
- type: "pending"
23
- promise: Promise<T>
24
- } | {
25
- type: "resolved"
26
- value: T
27
- } | {
28
- type: "rejected"
29
- reason?: unknown
15
+ run(): Promise<T>
30
16
  }
31
17
 
32
18
  export interface FiberInfo {
@@ -36,82 +22,46 @@ export interface FiberInfo {
36
22
 
37
23
  let nextFiberId = 0
38
24
 
39
- export interface FiberConfig<T> {
40
- parent?: Fiber<any>
25
+ export interface FiberConfig<T = any> {
26
+ T: T
27
+ signal?: AbortSignal | undefined
41
28
  globals: Globals
42
- runic: Runic<Rune, T>
43
29
  state?: StateMap | undefined
44
- signal?: AbortSignal | undefined
45
30
  }
46
31
 
47
- export function Fiber<T>(config: FiberConfig<T>): Fiber<T> {
48
- const fiber = {
49
- state: config.state ?? new DefaultStateMap(),
50
- globals: config.globals,
51
- parent: config.parent,
52
- status: { type: "untouched" },
53
- fiberId: nextFiberId++,
54
- run,
55
- handler,
56
- } satisfies Omit<Fiber<T>, "T"> as Fiber<T>
57
- fiber.handler<FiberCreated>({
58
- [LEventTag]: "fiber_created",
32
+ export function handler<E>(fiberConfig: FiberConfig, event: E): void {
33
+ fiberConfig.globals.handler(event, {
34
+ // fiber: fiberConfig.fiberId,
35
+ timestamp: Date.now(),
59
36
  })
60
- return fiber
37
+ }
61
38
 
62
- function handler<E>(this: Fiber<T>, event: E): void {
63
- config.globals.handler(event, {
64
- fiber: this.fiberId,
65
- timestamp: Date.now(),
66
- })
67
- }
39
+ // export interface FiberConfig<T> {
40
+ // parent?: Fiber<any>
41
+ // globals: Globals
42
+ // runic: Runic<Rune, T>
43
+ // signal?: AbortSignal | undefined
44
+ // }
68
45
 
69
- async function run(this: Fiber<T>): Promise<T> {
70
- if (this.status.type === "pending") {
71
- return await this.status.promise
72
- } else if (this.status.type === "resolved") {
73
- return this.status.value
74
- } else if (this.status.type === "rejected") {
75
- throw this.status.reason
76
- }
77
- this.handler<FiberStarted>({
78
- [LEventTag]: "fiber_started",
79
- })
80
- const { promise, resolve, reject } = Promise.withResolvers<T>()
81
- if (config.signal) {
82
- if (config.signal.aborted) {
83
- reject(config.signal.reason)
84
- return await promise
85
- } else {
86
- config.signal.addEventListener("abort", () => {
87
- reject(config.signal?.reason)
88
- })
89
- }
90
- }
91
- this.status = {
92
- type: "pending",
93
- promise,
94
- }
95
- queueMicrotask(async () => {
96
- const iterator = Runic.unwrap(config.runic)
97
- let nextArg: any
98
- try {
99
- let current = await iterator.next(nextArg)
100
- while (!current.done) {
101
- const rune = current.value
102
- const nextArg = await rune(this)
103
- current = await iterator.next(nextArg)
104
- }
105
- const { value } = current
106
- this.handler<FiberResolved>({
107
- [LEventTag]: "fiber_resolved",
108
- value,
109
- })
110
- resolve(value)
111
- } catch (reason: unknown) {
112
- reject(reason)
113
- }
114
- })
115
- return await promise
116
- }
117
- }
46
+ // export function Fiber<T>(config: FiberConfig<T>): Fiber<T> {
47
+ // const fiber = {
48
+ // runic: config.runic,
49
+ // globals: config.globals,
50
+ // parent: config.parent,
51
+ // fiberId: nextFiberId++,
52
+ // handler,
53
+ // run,
54
+ // } satisfies Omit<Fiber<T>, "T"> as Fiber<T>
55
+
56
+ // fiber.handler(new FiberCreated())
57
+ // return fiber
58
+
59
+ // async function run(this: Fiber<T>): Promise<T> {
60
+ // fiber.handler(new FiberStarted())
61
+ // const iterator = Runic.unwrap(this.runic)
62
+ // const result = await iterator.next()
63
+ // assert(result.done)
64
+ // fiber.handler(new FiberResolved(result.value))
65
+ // return result.value
66
+ // }
67
+ // }
package/Globals.ts CHANGED
@@ -3,7 +3,7 @@ export interface Globals {
3
3
  }
4
4
 
5
5
  export interface EventInfo {
6
- fiber: number
6
+ // fiber: number
7
7
  timestamp: number
8
8
  // group
9
9
  // depth
package/L/L.ts CHANGED
@@ -8,6 +8,5 @@ export * from "./fork.ts"
8
8
  export * from "./join.ts"
9
9
  export * from "./model.ts"
10
10
  export * from "./self.ts"
11
- export * from "./state.ts"
12
11
  export * from "./system.ts"
13
12
  export * from "./user.ts"
package/L/_infer.ts CHANGED
@@ -1,35 +1,40 @@
1
- import type { SchemaRoot } from "liminal-schema"
1
+ import type { SchemaObject } from "liminal-schema"
2
2
  import { assert } from "liminal-util"
3
- import { type InferenceRequested, type Inferred, type LEvent, LEventTag } from "../LEvent.ts"
3
+ import { InferenceRequested, Inferred, type LEvent } from "../LEvent.ts"
4
4
  import type { Rune } from "../Rune.ts"
5
- import { Counter } from "../state/Counter.ts"
5
+ import { context } from "../state/Context.ts"
6
6
  import { MessageRegistry } from "../state/MessageRegistry.ts"
7
7
  import { ModelRegistry } from "../state/ModelRegistry.ts"
8
8
  import { emit } from "./emit.ts"
9
9
  import { rune } from "./rune.ts"
10
- import { state } from "./state.ts"
11
10
 
12
- export function* _infer(schema?: SchemaRoot): Generator<Rune<LEvent>, string> {
13
- const [modelRegistry, { messages }, counter] = yield* state(
14
- ModelRegistry,
15
- MessageRegistry,
16
- InferenceRequestCounter,
17
- )
11
+ export function* _infer(schema?: SchemaObject): Generator<Rune<LEvent>, string> {
12
+ const state = context.get()
13
+ const modelRegistry = state.getOrInit(ModelRegistry.make)
18
14
  const model = modelRegistry.peek()
15
+ const messageRegistry = state.getOrInit(MessageRegistry.make)
16
+ const counter = state.getOrInit(InferenceRequestCounter)
19
17
  assert(model)
20
18
  const requestId = counter.next()
21
- yield* emit<InferenceRequested>({
22
- [LEventTag]: "inference_requested",
23
- ...schema && { schema },
24
- requestId,
25
- })
26
- const inference = yield* rune(() => model.resolve(messages, schema))
27
- yield* emit<Inferred>({
28
- [LEventTag]: "inferred",
29
- inference,
30
- requestId,
31
- })
19
+ yield* emit(new InferenceRequested(requestId, schema))
20
+ const inference = yield* rune(() => model.resolve(messageRegistry.messages, schema))
21
+ yield* emit(new Inferred(requestId, inference))
32
22
  return inference
33
23
  }
34
24
 
35
- class InferenceRequestCounter extends Counter {}
25
+ function InferenceRequestCounter(instance?: Counter) {
26
+ return {
27
+ count: instance?.count ?? 0,
28
+ next() {
29
+ return this.count++
30
+ },
31
+ clone() {
32
+ return InferenceRequestCounter(this)
33
+ },
34
+ }
35
+ }
36
+
37
+ interface Counter {
38
+ count: number
39
+ next(): number
40
+ }
package/L/_message.ts CHANGED
@@ -1,18 +1,16 @@
1
- import { type LEvent, LEventTag, type MessageAppended } from "../LEvent.ts"
1
+ import { type LEvent, MessageAppended } from "../LEvent.ts"
2
2
  import type { ContentPart, Message, MessageRole } from "../Message.ts"
3
3
  import type { Rune } from "../Rune.ts"
4
+ import { context } from "../state/Context.ts"
4
5
  import { MessageRegistry } from "../state/MessageRegistry.ts"
5
6
  import { emit } from "./emit.ts"
6
- import { state } from "./state.ts"
7
7
 
8
8
  export interface _message extends Generator<Rune<LEvent>, void> {}
9
9
 
10
10
  export function* _message(role: MessageRole, content: Array<ContentPart>): _message {
11
- const [messageRegistry] = yield* state(MessageRegistry)
11
+ const state = context.get()
12
+ const messageRegistry = state.getOrInit(MessageRegistry.make)
12
13
  const message: Message = { role, content }
13
- yield* emit<MessageAppended>({
14
- [LEventTag]: "message_appended",
15
- message,
16
- })
14
+ yield* emit(new MessageAppended(message))
17
15
  messageRegistry.append(message)
18
16
  }
package/L/assistant.ts CHANGED
@@ -1,7 +1,4 @@
1
- import type { StandardSchemaV1 } from "@standard-schema/spec"
2
- import { type LType, toJSONSchema } from "liminal-schema"
3
- import type { json } from "liminal-util"
4
- import { LiminalAssertionError } from "liminal-util"
1
+ import { type LType, toJSONSchema, validate } from "liminal-schema"
5
2
  import type { LEvent } from "../LEvent.ts"
6
3
  import type { Rune } from "../Rune.ts"
7
4
  import { _infer } from "./_infer.ts"
@@ -18,11 +15,7 @@ export const assistant: assistant = Object.assign(
18
15
  const inference = yield* _infer(schema)
19
16
  yield* _message("assistant", [{ part: inference }])
20
17
  const input = JSON.parse(inference)
21
- const result = yield* rune(() => (type as StandardSchemaV1<json.ValueObject, T>)["~standard"].validate(input))
22
- if (result.issues) {
23
- throw new LiminalAssertionError(JSON.stringify(result.issues, null, 2))
24
- }
25
- return result.value
18
+ return yield* rune(() => validate(type, input))
26
19
  },
27
20
  {
28
21
  *[Symbol.iterator]() {
package/L/branch.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { Fiber } from "../Fiber.ts"
1
+ import type { FiberConfig } from "../Fiber.ts"
2
+ import { run } from "../run.ts"
2
3
  import { type Rune } from "../Rune.ts"
3
4
  import type { Runic } from "../Runic.ts"
4
- import { all } from "./all.ts"
5
- import { fork } from "./fork.ts"
6
- import { join } from "./join.ts"
5
+ import { context } from "../state/Context.ts"
6
+ import { rune } from "./rune.ts"
7
7
  import { self } from "./self.ts"
8
8
 
9
9
  export interface branch<Y extends Rune, T> extends Generator<Y, T> {}
@@ -17,29 +17,35 @@ export function branch<XR extends Record<keyof any, Runic>>(
17
17
  ): branch<Runic.Y<XR[keyof XR]> | Rune<never>, { [K in keyof XR]: Runic.T<XR[K]> }>
18
18
  export function* branch(value: Runic | Array<Runic> | Record<keyof any, Runic>): branch<Rune, any> {
19
19
  const parent = yield* self
20
- const { globals, state } = parent
20
+ const { globals } = parent
21
21
  if (Array.isArray(value)) {
22
- const fibers = value.map((runic) =>
23
- Fiber({
22
+ const runners = value.map((runic) => {
23
+ const state = context.get()
24
+ const fiberConfig: FiberConfig = {
25
+ T: null!,
24
26
  globals,
25
- parent,
26
- runic,
27
- state: state.clone(),
28
- })
29
- )
30
- return yield* join(yield* all(...fibers))
27
+ state,
28
+ }
29
+ return () => run(runic, fiberConfig)
30
+ })
31
+ return yield* rune(() => Promise.all(runners.map((runner) => runner())))
31
32
  } else if (typeof value === "object") {
32
- const fibers = Object.values(value).map((runic) =>
33
- Fiber({
33
+ const runners = Object.entries(value).map(([key, runic]) => {
34
+ const state = context.get()
35
+ const fiberConfig: FiberConfig = {
36
+ T: null!,
34
37
  globals,
35
- parent,
36
- runic,
37
- state: state.clone(),
38
- })
39
- )
40
- const resolved = yield* join(yield* all(...fibers))
41
- return Object.fromEntries(Object.keys(value).map((key, i) => [key, resolved[i]]))
38
+ state,
39
+ }
40
+ return async () => [key, await run(runic, fiberConfig)]
41
+ })
42
+ return yield* rune(() => Promise.all(runners.map((runner) => runner())).then(Object.fromEntries))
42
43
  }
43
- const fiber = yield* fork(typeof value === "function" ? value() : value, state.clone())
44
- return yield* join(fiber)
44
+ const state = context.get()
45
+ const fiberConfig: FiberConfig = {
46
+ T: null!,
47
+ globals,
48
+ state,
49
+ }
50
+ return yield* rune(() => run(typeof value === "function" ? value() : value, fiberConfig))
45
51
  }
package/L/emit.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import type { EnsureNarrow } from "liminal-util"
2
+ import { handler } from "../Fiber.ts"
2
3
  import type { Rune } from "../Rune.ts"
3
4
  import { rune } from "./rune.ts"
4
5
 
5
6
  export interface emit<E> extends Generator<Rune<E>, void> {}
6
7
 
7
8
  export function* emit<const E>(event: EnsureNarrow<E>): emit<E> {
8
- yield* rune((fiber) => {
9
- fiber.handler(event)
10
- })<E>()
9
+ yield* rune((fiberConfig) => handler(fiberConfig, event))<E>()
11
10
  }
package/L/fork.ts CHANGED
@@ -1,18 +1,20 @@
1
- import { Fiber } from "../Fiber.ts"
2
- import type { Rune } from "../Rune.ts"
3
- import type { Runic } from "../Runic.ts"
4
- import type { StateMap } from "../state/StateMap.ts"
5
- import { rune } from "./rune.ts"
1
+ // import type { FiberConfig } from "../Fiber.ts"
2
+ // import type { Rune } from "../Rune.ts"
3
+ // import type { Runic } from "../Runic.ts"
4
+ // import { runic as runic_ } from "./runic.ts"
5
+ // import { self } from "./self.ts"
6
6
 
7
- export interface fork<Y extends Rune, T> extends Generator<Rune<never> | Y, Fiber<T>> {}
7
+ // export interface fork<Y extends Rune, T> extends Generator<Rune<any> | Y, FiberConfig<T>> {}
8
8
 
9
- export function* fork<Y extends Rune, T>(runic: Runic<Y, T>, state?: StateMap): fork<Y, T> {
10
- return yield* rune((parent) =>
11
- Fiber({
12
- globals: parent.globals,
13
- parent,
14
- runic,
15
- state: state?.clone(),
16
- })
17
- )
18
- }
9
+ // export function* fork<Y extends Rune, T>(runic: Runic<Y, T>): fork<Y, T> {
10
+ // const parent = yield* self
11
+ // const { globals, state, signal } = parent
12
+ // const controller = new AbortController()
13
+ // const fiberConfig: FiberConfig = {
14
+ // T: null!,
15
+ // globals,
16
+ // signal: controller.signal,
17
+ // state: state?.clone(),
18
+ // }
19
+ // return (yield* runic_(runic, fiberConfig)) as never
20
+ // }
package/L/model.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import type { Model } from "../Model.ts"
2
2
  import type { Rune } from "../Rune.ts"
3
+ import { context } from "../state/Context.ts"
3
4
  import { ModelRegistry } from "../state/ModelRegistry.ts"
4
- import { state } from "./state.ts"
5
5
 
6
6
  export interface model extends Generator<Rune<never>, void> {}
7
7
 
8
8
  export function* model(model: Model): model {
9
- const [modelRegistry] = yield* state(ModelRegistry)
9
+ const state = context.get()
10
+ const modelRegistry = state.getOrInit(ModelRegistry.make)
10
11
  modelRegistry.register(model)
11
12
  }
package/L/rune.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { Fiber } from "../Fiber.ts"
1
+ import type { FiberConfig } from "../Fiber.ts"
2
2
  import { type Rune, RuneKey } from "../Rune.ts"
3
3
 
4
4
  export interface rune<T> extends Iterable<Rune<never>, T> {
5
5
  <E>(): Generator<Rune<E>, T>
6
6
  }
7
7
 
8
- export function rune<R>(source: (fiber: Fiber) => R): rune<Awaited<R>> {
8
+ export function rune<R>(source: (fiberConfig: FiberConfig) => R): rune<Awaited<R>> {
9
9
  return Object.assign(
10
10
  function*<E>(): Generator<Rune<E>, Awaited<R>> {
11
11
  return yield Object.assign(source, { [RuneKey]: {} as never })
package/L/self.ts CHANGED
@@ -1,13 +1,13 @@
1
- import type { Fiber } from "../Fiber.ts"
1
+ import type { FiberConfig } from "../Fiber.ts"
2
2
  import type { Rune } from "../Rune.ts"
3
3
  import { rune } from "./rune.ts"
4
4
 
5
5
  export interface self {
6
- [Symbol.iterator](): Generator<Rune<never>, Fiber>
6
+ [Symbol.iterator](): Generator<Rune<never>, FiberConfig>
7
7
  }
8
8
 
9
9
  export const self: self = {
10
10
  *[Symbol.iterator]() {
11
- return yield* rune((fiber) => fiber)
11
+ return yield* rune((fiberConfig) => fiberConfig)
12
12
  },
13
13
  }
package/LEvent.ts CHANGED
@@ -1,34 +1,57 @@
1
- import type { SchemaRoot } from "liminal-schema"
1
+ import type { SchemaObject } from "liminal-schema"
2
+ import { EventBase } from "./EventBase.ts"
2
3
  import type { Message } from "./Message.ts"
3
4
 
4
5
  export type LEvent = InferenceRequested | Inferred | MessageAppended | FiberCreated | FiberStarted | FiberResolved
5
6
 
6
- export interface InferenceRequested extends LEventBase<"inference_requested"> {
7
- requestId: number
8
- schema?: SchemaRoot
7
+ export const LEventTag: unique symbol = Symbol.for("liminal/LEvent")
8
+ export type LEventTag = typeof LEventTag
9
+
10
+ export class InferenceRequested extends EventBase<LEventTag, "inference_requested"> {
11
+ declare schema?: SchemaObject
12
+ constructor(
13
+ readonly requestId: number,
14
+ schema?: SchemaObject | undefined,
15
+ ) {
16
+ super(LEventTag, "inference_requested")
17
+ if (schema) {
18
+ this.schema = schema
19
+ }
20
+ }
9
21
  }
10
22
 
11
- export interface Inferred extends LEventBase<"inferred"> {
12
- requestId: number
13
- inference: string
23
+ export class Inferred extends EventBase<LEventTag, "inferred"> {
24
+ constructor(
25
+ readonly requestId: number,
26
+ readonly inference: string,
27
+ ) {
28
+ super(LEventTag, "inferred")
29
+ }
14
30
  }
15
31
 
16
- export interface MessageAppended extends LEventBase<"message_appended"> {
17
- message: Message
32
+ export class MessageAppended extends EventBase<LEventTag, "message_appended"> {
33
+ constructor(readonly message: Message) {
34
+ super(LEventTag, "message_appended")
35
+ }
18
36
  }
19
37
 
20
- export interface FiberCreated extends LEventBase<"fiber_created"> {}
21
- export interface FiberStarted extends LEventBase<"fiber_started"> {}
22
- export interface FiberResolved extends LEventBase<"fiber_resolved"> {
23
- value: any
38
+ export class FiberCreated extends EventBase<LEventTag, "fiber_created"> {
39
+ constructor() {
40
+ super(LEventTag, "fiber_created")
41
+ }
24
42
  }
25
43
 
26
- interface LEventBase<K extends string> {
27
- [LEventTag]: K
44
+ export class FiberStarted extends EventBase<LEventTag, "fiber_started"> {
45
+ constructor() {
46
+ super(LEventTag, "fiber_started")
47
+ }
28
48
  }
29
49
 
30
- export const LEventTag: unique symbol = Symbol.for("liminal/LEvent")
31
- export type LEventTag = typeof LEventTag
50
+ export class FiberResolved extends EventBase<LEventTag, "fiber_resolved"> {
51
+ constructor(readonly value: any) {
52
+ super(LEventTag, "fiber_resolved")
53
+ }
54
+ }
32
55
 
33
56
  export function isLEvent(value: unknown): value is LEvent {
34
57
  return typeof value === "object" && value !== null && LEventTag in value
package/Rune.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { Fiber } from "./Fiber.ts"
1
+ import type { FiberConfig } from "./Fiber.ts"
2
2
 
3
3
  export interface Rune<out E = any> {
4
- (fiber: Fiber): any
4
+ (fiber: FiberConfig): any
5
5
  [RuneKey]: E
6
6
  }
7
7
 
package/dist/Agent.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type FiberInfo } from "./Fiber.ts";
1
+ import type { FiberInfo } from "./Fiber.ts";
2
2
  import type { Rune, RuneKey } from "./Rune.ts";
3
3
  import type { Runic } from "./Runic.ts";
4
4
  export interface Agent<out T, out E> extends PromiseLike<T> {
package/dist/Agent.js CHANGED
@@ -1,15 +1,14 @@
1
- import { Fiber } from "./Fiber.js";
1
+ import { run } from "./run.js";
2
2
  export function Agent(runic, config) {
3
3
  return {
4
4
  then(onfulfilled, onrejected) {
5
- const root = Fiber({
5
+ return run(runic, {
6
+ T: null,
6
7
  globals: {
7
8
  handler: config?.handler ?? (() => { }),
8
9
  },
9
- runic,
10
10
  signal: config?.signal,
11
- });
12
- return root.run().then(onfulfilled, onrejected);
11
+ }).then(onfulfilled, onrejected);
13
12
  },
14
13
  };
15
14
  }
package/dist/Agent.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Agent.js","sourceRoot":"","sources":["../Agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAkB,MAAM,YAAY,CAAA;AASlD,MAAM,UAAU,KAAK,CAAoB,KAAkB,EAAE,MAA0B;IACrF,OAAO;QACL,IAAI,CAAC,WAAW,EAAE,UAAU;YAC1B,MAAM,IAAI,GAAG,KAAK,CAAC;gBACjB,OAAO,EAAE;oBACP,OAAO,EAAE,MAAM,EAAE,OAAO,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;iBACvC;gBACD,KAAK;gBACL,MAAM,EAAE,MAAM,EAAE,MAAM;aACvB,CAAC,CAAA;YACF,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;QACjD,CAAC;KACsD,CAAA;AAC3D,CAAC"}
1
+ {"version":3,"file":"Agent.js","sourceRoot":"","sources":["../Agent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAS9B,MAAM,UAAU,KAAK,CAAoB,KAAkB,EAAE,MAA0B;IACrF,OAAO;QACL,IAAI,CAAC,WAAW,EAAE,UAAU;YAC1B,OAAO,GAAG,CAAC,KAAK,EAAE;gBAChB,CAAC,EAAE,IAAK;gBACR,OAAO,EAAE;oBACP,OAAO,EAAE,MAAM,EAAE,OAAO,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;iBACvC;gBACD,MAAM,EAAE,MAAM,EAAE,MAAM;aACvB,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;QAClC,CAAC;KACsD,CAAA;AAC3D,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { inspect, type InspectOptions } from "node:util";
2
+ export declare abstract class EventBase<B extends symbol, K extends string> {
3
+ readonly brand: B;
4
+ readonly type: K;
5
+ constructor(brand: B, type: K);
6
+ [inspect.custom](depth: number, options: InspectOptions): string;
7
+ }