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.
- package/Agent.ts +5 -5
- package/CHANGELOG.md +9 -0
- package/EventBase.ts +13 -0
- package/Fiber.ts +42 -92
- package/Globals.ts +1 -1
- package/L/L.ts +0 -1
- package/L/_infer.ts +27 -22
- package/L/_message.ts +5 -7
- package/L/assistant.ts +2 -9
- package/L/branch.ts +30 -24
- package/L/emit.ts +2 -3
- package/L/fork.ts +18 -16
- package/L/model.ts +3 -2
- package/L/rune.ts +2 -2
- package/L/self.ts +3 -3
- package/LEvent.ts +40 -17
- package/Rune.ts +2 -2
- package/dist/Agent.d.ts +1 -1
- package/dist/Agent.js +4 -5
- package/dist/Agent.js.map +1 -1
- package/dist/EventBase.d.ts +7 -0
- package/dist/EventBase.js +14 -0
- package/dist/EventBase.js.map +1 -0
- package/dist/Fiber.d.ts +8 -22
- package/dist/Fiber.js +32 -74
- package/dist/Fiber.js.map +1 -1
- package/dist/Globals.d.ts +0 -1
- package/dist/L/L.d.ts +0 -1
- package/dist/L/L.js +0 -1
- package/dist/L/L.js.map +1 -1
- package/dist/L/_infer.d.ts +2 -2
- package/dist/L/_infer.js +19 -16
- package/dist/L/_infer.js.map +1 -1
- package/dist/L/_message.js +5 -7
- package/dist/L/_message.js.map +1 -1
- package/dist/L/assistant.js +2 -7
- package/dist/L/assistant.js.map +1 -1
- package/dist/L/branch.js +31 -22
- package/dist/L/branch.js.map +1 -1
- package/dist/L/emit.js +2 -3
- package/dist/L/emit.js.map +1 -1
- package/dist/L/fork.d.ts +1 -7
- package/dist/L/fork.js +19 -10
- package/dist/L/fork.js.map +1 -1
- package/dist/L/model.js +3 -2
- package/dist/L/model.js.map +1 -1
- package/dist/L/rune.d.ts +2 -2
- package/dist/L/rune.js.map +1 -1
- package/dist/L/self.d.ts +2 -2
- package/dist/L/self.js +1 -1
- package/dist/L/self.js.map +1 -1
- package/dist/LEvent.d.ts +22 -19
- package/dist/LEvent.js +44 -0
- package/dist/LEvent.js.map +1 -1
- package/dist/Rune.d.ts +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/run.d.ts +3 -0
- package/dist/run.js +35 -0
- package/dist/run.js.map +1 -0
- package/dist/state/Context.d.ts +8 -0
- package/dist/state/Context.js +17 -0
- package/dist/state/Context.js.map +1 -0
- package/dist/state/MessageRegistry.d.ts +1 -0
- package/dist/state/MessageRegistry.js +3 -0
- package/dist/state/MessageRegistry.js.map +1 -1
- package/dist/state/ModelRegistry.d.ts +1 -0
- package/dist/state/ModelRegistry.js +9 -0
- package/dist/state/ModelRegistry.js.map +1 -1
- package/dist/state/StateMap.d.ts +3 -2
- package/dist/state/StateMap.js +8 -0
- package/dist/state/StateMap.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.ts +2 -0
- package/package.json +3 -4
- package/run.ts +39 -0
- package/state/Context.ts +19 -0
- package/state/MessageRegistry.ts +4 -0
- package/state/ModelRegistry.ts +10 -0
- package/state/StateMap.ts +11 -2
- package/L/state.ts +0 -20
- package/dist/L/state.d.ts +0 -7
- package/dist/L/state.js +0 -14
- package/dist/L/state.js.map +0 -1
- package/dist/state/Counter.d.ts +0 -6
- package/dist/state/Counter.js +0 -13
- package/dist/state/Counter.js.map +0 -1
- package/dist/state/DefaultStateMap.d.ts +0 -4
- package/dist/state/DefaultStateMap.js +0 -14
- package/dist/state/DefaultStateMap.js.map +0 -1
- package/state/Counter.ts +0 -11
- package/state/DefaultStateMap.ts +0 -14
package/Agent.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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
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 {
|
|
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 {
|
|
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
|
-
|
|
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
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
37
|
+
}
|
|
61
38
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
package/L/L.ts
CHANGED
package/L/_infer.ts
CHANGED
|
@@ -1,35 +1,40 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SchemaObject } from "liminal-schema"
|
|
2
2
|
import { assert } from "liminal-util"
|
|
3
|
-
import {
|
|
3
|
+
import { InferenceRequested, Inferred, type LEvent } from "../LEvent.ts"
|
|
4
4
|
import type { Rune } from "../Rune.ts"
|
|
5
|
-
import {
|
|
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?:
|
|
13
|
-
const
|
|
14
|
-
|
|
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
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
|
11
|
+
const state = context.get()
|
|
12
|
+
const messageRegistry = state.getOrInit(MessageRegistry.make)
|
|
12
13
|
const message: Message = { role, content }
|
|
13
|
-
yield* emit
|
|
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
|
|
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
|
-
|
|
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 {
|
|
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 {
|
|
5
|
-
import {
|
|
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
|
|
20
|
+
const { globals } = parent
|
|
21
21
|
if (Array.isArray(value)) {
|
|
22
|
-
const
|
|
23
|
-
|
|
22
|
+
const runners = value.map((runic) => {
|
|
23
|
+
const state = context.get()
|
|
24
|
+
const fiberConfig: FiberConfig = {
|
|
25
|
+
T: null!,
|
|
24
26
|
globals,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
33
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
44
|
-
|
|
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((
|
|
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 {
|
|
2
|
-
import type { Rune } from "../Rune.ts"
|
|
3
|
-
import type { Runic } from "../Runic.ts"
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
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<
|
|
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
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
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 {
|
|
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: (
|
|
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 {
|
|
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>,
|
|
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((
|
|
11
|
+
return yield* rune((fiberConfig) => fiberConfig)
|
|
12
12
|
},
|
|
13
13
|
}
|
package/LEvent.ts
CHANGED
|
@@ -1,34 +1,57 @@
|
|
|
1
|
-
import type {
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
export class FiberCreated extends EventBase<LEventTag, "fiber_created"> {
|
|
39
|
+
constructor() {
|
|
40
|
+
super(LEventTag, "fiber_created")
|
|
41
|
+
}
|
|
24
42
|
}
|
|
25
43
|
|
|
26
|
-
|
|
27
|
-
|
|
44
|
+
export class FiberStarted extends EventBase<LEventTag, "fiber_started"> {
|
|
45
|
+
constructor() {
|
|
46
|
+
super(LEventTag, "fiber_started")
|
|
47
|
+
}
|
|
28
48
|
}
|
|
29
49
|
|
|
30
|
-
export
|
|
31
|
-
|
|
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
package/dist/Agent.d.ts
CHANGED
package/dist/Agent.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { run } from "./run.js";
|
|
2
2
|
export function Agent(runic, config) {
|
|
3
3
|
return {
|
|
4
4
|
then(onfulfilled, onrejected) {
|
|
5
|
-
|
|
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":"
|
|
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
|
+
}
|