liminal 0.5.16 → 0.6.0
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/CHANGELOG.md +12 -0
- package/Context.ts +11 -47
- package/L.ts +4 -0
- package/LEvent.ts +20 -53
- package/_emit.ts +16 -0
- package/assistant.ts +53 -0
- package/dist/Context.d.ts +15 -30
- package/dist/Context.js +9 -22
- package/dist/Context.js.map +1 -1
- package/dist/L.d.ts +4 -0
- package/dist/L.js +5 -0
- package/dist/L.js.map +1 -0
- package/dist/LEvent.d.ts +29 -62
- package/dist/LEvent.js +14 -46
- package/dist/LEvent.js.map +1 -1
- package/dist/_emit.d.ts +2 -0
- package/dist/_emit.js +16 -0
- package/dist/_emit.js.map +1 -0
- package/dist/assistant.d.ts +8 -0
- package/dist/assistant.js +46 -0
- package/dist/assistant.js.map +1 -0
- package/dist/index.d.ts +2 -13
- package/dist/index.js +2 -13
- package/dist/index.js.map +1 -1
- package/dist/messages.d.ts +4 -0
- package/dist/messages.js +4 -0
- package/dist/messages.js.map +1 -0
- package/dist/set.d.ts +4 -0
- package/dist/set.js +9 -0
- package/dist/set.js.map +1 -0
- package/dist/strand.d.ts +16 -0
- package/dist/strand.js +16 -0
- package/dist/strand.js.map +1 -0
- package/dist/todo.test.js +3 -0
- package/dist/todo.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/user.d.ts +6 -0
- package/dist/user.js +18 -0
- package/dist/user.js.map +1 -0
- package/dist/util/JSONValue.d.ts +0 -3
- package/dist/util/JSONValue.js +1 -31
- package/dist/util/JSONValue.js.map +1 -1
- package/dist/util/fixTemplateStrings.d.ts +11 -0
- package/dist/util/fixTemplateStrings.js +83 -0
- package/dist/util/fixTemplateStrings.js.map +1 -0
- package/index.ts +2 -13
- package/messages.ts +5 -0
- package/package.json +4 -3
- package/set.ts +10 -0
- package/strand.ts +38 -0
- package/todo.test.ts +3 -0
- package/user.ts +24 -0
- package/util/JSONValue.ts +0 -30
- package/util/fixTemplateStrings.ts +99 -0
- package/Adapter.ts +0 -27
- package/AdapterRegistry.ts +0 -78
- package/Config.ts +0 -13
- package/Definition.ts +0 -48
- package/EventBase.ts +0 -23
- package/Handler.ts +0 -4
- package/L/L.ts +0 -24
- package/L/all.ts +0 -39
- package/L/assistant.ts +0 -28
- package/L/catch.ts +0 -38
- package/L/continuation.ts +0 -14
- package/L/emit.ts +0 -16
- package/L/focus.ts +0 -17
- package/L/infer.ts +0 -34
- package/L/message.ts +0 -16
- package/L/reflect.ts +0 -13
- package/L/run.ts +0 -30
- package/L/schema/_schema_common.ts +0 -29
- package/L/schema/anyOf.ts +0 -10
- package/L/schema/array.ts +0 -13
- package/L/schema/boolean.ts +0 -8
- package/L/schema/const.ts +0 -18
- package/L/schema/enum.ts +0 -18
- package/L/schema/integer.ts +0 -6
- package/L/schema/null.ts +0 -8
- package/L/schema/number.ts +0 -8
- package/L/schema/object.ts +0 -21
- package/L/schema/string.ts +0 -11
- package/L/strand.ts +0 -22
- package/L/stream.ts +0 -16
- package/L/system.ts +0 -18
- package/L/user.ts +0 -18
- package/LiminalAssertionError.ts +0 -19
- package/Message.ts +0 -16
- package/Rune.test.ts +0 -5
- package/Rune.ts +0 -60
- package/Schema.ts +0 -185
- package/Strand.ts +0 -284
- package/Tool.ts +0 -26
- package/TypeAdapter.ts +0 -3
- package/dist/Adapter.d.ts +0 -18
- package/dist/Adapter.js +0 -13
- package/dist/Adapter.js.map +0 -1
- package/dist/AdapterRegistry.d.ts +0 -27
- package/dist/AdapterRegistry.js +0 -62
- package/dist/AdapterRegistry.js.map +0 -1
- package/dist/Config.d.ts +0 -12
- package/dist/Config.js +0 -2
- package/dist/Config.js.map +0 -1
- package/dist/Definition.d.ts +0 -24
- package/dist/Definition.js +0 -29
- package/dist/Definition.js.map +0 -1
- package/dist/EventBase.d.ts +0 -11
- package/dist/EventBase.js +0 -16
- package/dist/EventBase.js.map +0 -1
- package/dist/Handler.d.ts +0 -3
- package/dist/Handler.js +0 -2
- package/dist/Handler.js.map +0 -1
- package/dist/L/L.d.ts +0 -24
- package/dist/L/L.js +0 -25
- package/dist/L/L.js.map +0 -1
- package/dist/L/all.d.ts +0 -14
- package/dist/L/all.js +0 -20
- package/dist/L/all.js.map +0 -1
- package/dist/L/assistant.d.ts +0 -11
- package/dist/L/assistant.js +0 -15
- package/dist/L/assistant.js.map +0 -1
- package/dist/L/catch.d.ts +0 -16
- package/dist/L/catch.js +0 -25
- package/dist/L/catch.js.map +0 -1
- package/dist/L/continuation.d.ts +0 -4
- package/dist/L/continuation.js +0 -13
- package/dist/L/continuation.js.map +0 -1
- package/dist/L/emit.d.ts +0 -7
- package/dist/L/emit.js +0 -15
- package/dist/L/emit.js.map +0 -1
- package/dist/L/focus.d.ts +0 -8
- package/dist/L/focus.js +0 -14
- package/dist/L/focus.js.map +0 -1
- package/dist/L/infer.d.ts +0 -8
- package/dist/L/infer.js +0 -30
- package/dist/L/infer.js.map +0 -1
- package/dist/L/message.d.ts +0 -8
- package/dist/L/message.js +0 -14
- package/dist/L/message.js.map +0 -1
- package/dist/L/reflect.d.ts +0 -5
- package/dist/L/reflect.js +0 -11
- package/dist/L/reflect.js.map +0 -1
- package/dist/L/run.d.ts +0 -16
- package/dist/L/run.js +0 -16
- package/dist/L/run.js.map +0 -1
- package/dist/L/schema/_schema_common.d.ts +0 -6
- package/dist/L/schema/_schema_common.js +0 -19
- package/dist/L/schema/_schema_common.js.map +0 -1
- package/dist/L/schema/anyOf.d.ts +0 -5
- package/dist/L/schema/anyOf.js +0 -5
- package/dist/L/schema/anyOf.js.map +0 -1
- package/dist/L/schema/array.d.ts +0 -5
- package/dist/L/schema/array.js +0 -8
- package/dist/L/schema/array.js.map +0 -1
- package/dist/L/schema/boolean.d.ts +0 -6
- package/dist/L/schema/boolean.js +0 -4
- package/dist/L/schema/boolean.js.map +0 -1
- package/dist/L/schema/const.d.ts +0 -8
- package/dist/L/schema/const.js +0 -10
- package/dist/L/schema/const.js.map +0 -1
- package/dist/L/schema/enum.d.ts +0 -8
- package/dist/L/schema/enum.js +0 -10
- package/dist/L/schema/enum.js.map +0 -1
- package/dist/L/schema/integer.d.ts +0 -5
- package/dist/L/schema/integer.js +0 -3
- package/dist/L/schema/integer.js.map +0 -1
- package/dist/L/schema/null.d.ts +0 -6
- package/dist/L/schema/null.js +0 -4
- package/dist/L/schema/null.js.map +0 -1
- package/dist/L/schema/number.d.ts +0 -6
- package/dist/L/schema/number.js +0 -4
- package/dist/L/schema/number.js.map +0 -1
- package/dist/L/schema/object.d.ts +0 -9
- package/dist/L/schema/object.js +0 -12
- package/dist/L/schema/object.js.map +0 -1
- package/dist/L/schema/string.d.ts +0 -8
- package/dist/L/schema/string.js +0 -4
- package/dist/L/schema/string.js.map +0 -1
- package/dist/L/strand.d.ts +0 -9
- package/dist/L/strand.js +0 -16
- package/dist/L/strand.js.map +0 -1
- package/dist/L/stream.d.ts +0 -4
- package/dist/L/stream.js +0 -15
- package/dist/L/stream.js.map +0 -1
- package/dist/L/system.d.ts +0 -4
- package/dist/L/system.js +0 -8
- package/dist/L/system.js.map +0 -1
- package/dist/L/user.d.ts +0 -4
- package/dist/L/user.js +0 -8
- package/dist/L/user.js.map +0 -1
- package/dist/LiminalAssertionError.d.ts +0 -8
- package/dist/LiminalAssertionError.js +0 -20
- package/dist/LiminalAssertionError.js.map +0 -1
- package/dist/Message.d.ts +0 -14
- package/dist/Message.js +0 -2
- package/dist/Message.js.map +0 -1
- package/dist/Rune.d.ts +0 -46
- package/dist/Rune.js +0 -11
- package/dist/Rune.js.map +0 -1
- package/dist/Rune.test.js +0 -5
- package/dist/Rune.test.js.map +0 -1
- package/dist/Schema.d.ts +0 -46
- package/dist/Schema.js +0 -130
- package/dist/Schema.js.map +0 -1
- package/dist/Strand.d.ts +0 -81
- package/dist/Strand.js +0 -200
- package/dist/Strand.js.map +0 -1
- package/dist/Tool.d.ts +0 -10
- package/dist/Tool.js +0 -19
- package/dist/Tool.js.map +0 -1
- package/dist/TypeAdapter.d.ts +0 -1
- package/dist/TypeAdapter.js +0 -3
- package/dist/TypeAdapter.js.map +0 -1
- package/dist/errors.d.ts +0 -9
- package/dist/errors.js +0 -11
- package/dist/errors.js.map +0 -1
- package/dist/util/EnsureNarrow.d.ts +0 -1
- package/dist/util/EnsureNarrow.js +0 -2
- package/dist/util/EnsureNarrow.js.map +0 -1
- package/dist/util/attachCustomInspect.d.ts +0 -1
- package/dist/util/attachCustomInspect.js +0 -11
- package/dist/util/attachCustomInspect.js.map +0 -1
- package/errors.ts +0 -12
- package/util/EnsureNarrow.ts +0 -1
- package/util/attachCustomInspect.ts +0 -14
- /package/dist/{Rune.test.d.ts → todo.test.d.ts} +0 -0
package/L/L.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export * from "./all.ts"
|
|
2
|
-
export * from "./assistant.ts"
|
|
3
|
-
export * from "./catch.ts"
|
|
4
|
-
export * from "./continuation.ts"
|
|
5
|
-
export * from "./emit.ts"
|
|
6
|
-
export * from "./focus.ts"
|
|
7
|
-
export * from "./infer.ts"
|
|
8
|
-
export * from "./message.ts"
|
|
9
|
-
export * from "./reflect.ts"
|
|
10
|
-
export * from "./run.ts"
|
|
11
|
-
export * from "./schema/anyOf.ts"
|
|
12
|
-
export * from "./schema/array.ts"
|
|
13
|
-
export * from "./schema/boolean.ts"
|
|
14
|
-
export * from "./schema/const.ts"
|
|
15
|
-
export * from "./schema/enum.ts"
|
|
16
|
-
export * from "./schema/integer.ts"
|
|
17
|
-
export * from "./schema/null.ts"
|
|
18
|
-
export * from "./schema/number"
|
|
19
|
-
export * from "./schema/object.ts"
|
|
20
|
-
export * from "./schema/string.ts"
|
|
21
|
-
export * from "./strand.ts"
|
|
22
|
-
export * from "./stream.ts"
|
|
23
|
-
export * from "./system.ts"
|
|
24
|
-
export * from "./user.ts"
|
package/L/all.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Context } from "../Context.ts"
|
|
2
|
-
import { Definition } from "../Definition.ts"
|
|
3
|
-
import type { LEvent } from "../LEvent.ts"
|
|
4
|
-
import type { Rune } from "../Rune.ts"
|
|
5
|
-
import { Strand } from "../Strand.ts"
|
|
6
|
-
import { continuation } from "./continuation.ts"
|
|
7
|
-
import { reflect } from "./reflect.ts"
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Runs multiple definitions in parallel and collects their results.
|
|
11
|
-
* Can be used with an array or object of definitions.
|
|
12
|
-
*/
|
|
13
|
-
export function all<A extends Array<Definition>>(
|
|
14
|
-
definitions: A,
|
|
15
|
-
context?: Context,
|
|
16
|
-
): Generator<Rune<LEvent> | Definition.Y<A[number]>, { [I in keyof A]: Definition.T<A[I]> }>
|
|
17
|
-
export function all<A extends Record<keyof any, Definition>>(
|
|
18
|
-
definitions: A,
|
|
19
|
-
context?: Context,
|
|
20
|
-
): Generator<Rune<LEvent> | Definition.Y<A[keyof A]>, { [K in keyof A]: Definition.T<A[K]> }>
|
|
21
|
-
export function* all<A extends Array<Definition> | Record<keyof any, Definition>>(
|
|
22
|
-
definitions: A,
|
|
23
|
-
context?: Context,
|
|
24
|
-
): Generator<Rune<any>, any> { // TODO: although it's somewhat irrelevant, type this
|
|
25
|
-
const parent = yield* reflect
|
|
26
|
-
const strands: Array<Strand> = []
|
|
27
|
-
for (const definition of Array.isArray(definitions) ? definitions : Object.values(definitions)) {
|
|
28
|
-
strands.push(
|
|
29
|
-
new Strand(definition, {
|
|
30
|
-
parent,
|
|
31
|
-
context: context?.clone() ?? parent.context.clone(),
|
|
32
|
-
}),
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
const results = yield* continuation("all", () => Promise.all(strands))
|
|
36
|
-
if (Array.isArray(strands)) return results
|
|
37
|
-
const keys = Object.keys(strands)
|
|
38
|
-
return Object.fromEntries(results.map((result, i) => [keys[i], result]))
|
|
39
|
-
}
|
package/L/assistant.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { LEvent } from "../LEvent.ts"
|
|
2
|
-
import type { Rune } from "../Rune.ts"
|
|
3
|
-
import { Schema } from "../Schema.ts"
|
|
4
|
-
import { infer } from "./infer.ts"
|
|
5
|
-
import { message } from "./message.ts"
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Produces an assistant message when yielded. Can be called with a schema
|
|
9
|
-
* for structured output. Otherwise produces a string.
|
|
10
|
-
*/
|
|
11
|
-
export interface assistant extends Iterable<Rune<LEvent>, string> {
|
|
12
|
-
<T>(schema: Schema<T>): Generator<Rune<LEvent>, T>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const assistant: assistant = Object.assign(
|
|
16
|
-
function* assistant<T>(schema: Schema<T>): Generator<Rune<LEvent>, T> {
|
|
17
|
-
const inference = yield* infer(schema)
|
|
18
|
-
yield* message("assistant", [{ part: inference }])
|
|
19
|
-
return JSON.parse(inference)
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
*[Symbol.iterator]() {
|
|
23
|
-
const inference = yield* infer()
|
|
24
|
-
yield* message("assistant", [{ part: inference }])
|
|
25
|
-
return inference
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
)
|
package/L/catch.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { Definition } from "../Definition.ts"
|
|
2
|
-
import type { LEvent } from "../LEvent.ts"
|
|
3
|
-
import type { Rune } from "../Rune.ts"
|
|
4
|
-
import { Strand } from "../Strand.ts"
|
|
5
|
-
import { continuation } from "./continuation.ts"
|
|
6
|
-
import { reflect } from "./reflect.ts"
|
|
7
|
-
|
|
8
|
-
export { catch_ as catch }
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Error handling utility that catches exceptions from running a definition.
|
|
12
|
-
* Returns a result object indicating whether the operation succeeded or failed.
|
|
13
|
-
*/
|
|
14
|
-
function* catch_<Y extends Rune<any>, T>(
|
|
15
|
-
definition: Definition<Y, T>,
|
|
16
|
-
): Generator<Rune<LEvent> | Rune<Y>, CatchResult<T>> {
|
|
17
|
-
const parent = yield* reflect
|
|
18
|
-
return yield* continuation("catch", async () => {
|
|
19
|
-
try {
|
|
20
|
-
const resolved = await new Strand(definition, {
|
|
21
|
-
parent,
|
|
22
|
-
context: parent.context.clone(),
|
|
23
|
-
}).then()
|
|
24
|
-
return { resolved }
|
|
25
|
-
} catch (exception: unknown) {
|
|
26
|
-
return { rejected: exception }
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
Object.defineProperty(catch_, "name", { value: "catch" })
|
|
31
|
-
|
|
32
|
-
export type CatchResult<T> = {
|
|
33
|
-
resolved: T
|
|
34
|
-
rejected?: never
|
|
35
|
-
} | {
|
|
36
|
-
resolved?: never
|
|
37
|
-
rejected: unknown
|
|
38
|
-
}
|
package/L/continuation.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { LEvent } from "../LEvent.ts"
|
|
2
|
-
import { Rune, RuneKey } from "../Rune.ts"
|
|
3
|
-
|
|
4
|
-
/** Yields a continuation rune that executes a function and passes its result to the next iteration. */
|
|
5
|
-
export function* continuation<R>(debug: string, f: () => R): Generator<Rune<LEvent>, Awaited<R>> {
|
|
6
|
-
return yield {
|
|
7
|
-
[RuneKey]: true,
|
|
8
|
-
instruction: {
|
|
9
|
-
kind: "continue",
|
|
10
|
-
debug,
|
|
11
|
-
f,
|
|
12
|
-
},
|
|
13
|
-
}
|
|
14
|
-
}
|
package/L/emit.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Rune, RuneKey } from "../Rune.ts"
|
|
2
|
-
import type { EnsureNarrow } from "../util/EnsureNarrow.ts"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Emits an event to be supplied to handlers.
|
|
6
|
-
* Used for broadcasting state changes and triggering side effects.
|
|
7
|
-
*/
|
|
8
|
-
export function* emit<E>(event: EnsureNarrow<E>): Generator<Rune<E>, void> {
|
|
9
|
-
return yield {
|
|
10
|
-
[RuneKey]: true,
|
|
11
|
-
instruction: {
|
|
12
|
-
kind: "emit",
|
|
13
|
-
event,
|
|
14
|
-
},
|
|
15
|
-
}
|
|
16
|
-
}
|
package/L/focus.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { InferenceRequested, Inferred, type LEvent } from "../LEvent.ts"
|
|
2
|
-
import type { Rune } from "../Rune.ts"
|
|
3
|
-
import { Schema } from "../Schema.ts"
|
|
4
|
-
import { continuation } from "./continuation.ts"
|
|
5
|
-
import { emit } from "./emit.ts"
|
|
6
|
-
import { reflect } from "./reflect.ts"
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Requests an inference from the current model, optionally with a schema.
|
|
10
|
-
* Emits inference-related events and returns the model's response as a string.
|
|
11
|
-
*/
|
|
12
|
-
export function* infer(schema?: Schema): Generator<Rune<LEvent>, string> {
|
|
13
|
-
const { context: { adapters: models, messages }, signal } = yield* reflect
|
|
14
|
-
const model = models.ensure()
|
|
15
|
-
const requestId = crypto.randomUUID()
|
|
16
|
-
yield* emit(new InferenceRequested(requestId, schema))
|
|
17
|
-
let inference = yield* continuation(
|
|
18
|
-
"infer",
|
|
19
|
-
model
|
|
20
|
-
.seal({
|
|
21
|
-
messages,
|
|
22
|
-
...schema && {
|
|
23
|
-
schema: schema.type === "object" ? schema : Schema.wrap(schema),
|
|
24
|
-
},
|
|
25
|
-
signal,
|
|
26
|
-
})
|
|
27
|
-
.resolve,
|
|
28
|
-
)
|
|
29
|
-
if (schema?.type && schema.type !== "object") {
|
|
30
|
-
inference = JSON.stringify(JSON.parse(inference).value)
|
|
31
|
-
}
|
|
32
|
-
yield* emit(new Inferred(requestId, inference))
|
|
33
|
-
return inference
|
|
34
|
-
}
|
package/L/message.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { LEvent, MessageAppended } from "../LEvent.ts"
|
|
2
|
-
import type { Content, Message, MessageRole } from "../Message.ts"
|
|
3
|
-
import type { Rune } from "../Rune.ts"
|
|
4
|
-
import { emit } from "./emit.ts"
|
|
5
|
-
import { reflect } from "./reflect.ts"
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Adds a new message to the current context's message list.
|
|
9
|
-
* Emits a message append event to observers.
|
|
10
|
-
*/
|
|
11
|
-
export function* message(role: MessageRole, content: Array<Content>): Generator<Rune<LEvent>, void> {
|
|
12
|
-
const { context: { messages } } = yield* reflect
|
|
13
|
-
const message: Message = { role, parts: content }
|
|
14
|
-
yield* emit(new MessageAppended(message))
|
|
15
|
-
messages.push(message)
|
|
16
|
-
}
|
package/L/reflect.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { LEvent } from "../LEvent.ts"
|
|
2
|
-
import { Rune, RuneKey } from "../Rune.ts"
|
|
3
|
-
import type { Strand } from "../Strand.ts"
|
|
4
|
-
|
|
5
|
-
/** Returns the current strand instance, providing access to context and parent information. */
|
|
6
|
-
export const reflect: Iterable<Rune<LEvent>, Strand> = {
|
|
7
|
-
*[Symbol.iterator]() {
|
|
8
|
-
return yield {
|
|
9
|
-
[RuneKey]: true,
|
|
10
|
-
instruction: { kind: "reflect" },
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
}
|
package/L/run.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { AdapterRegistry } from "../AdapterRegistry.ts"
|
|
2
|
-
import { Context } from "../Context.ts"
|
|
3
|
-
import type { Definition } from "../Definition.ts"
|
|
4
|
-
import type { Handler } from "../Handler.ts"
|
|
5
|
-
import type { Message } from "../Message.ts"
|
|
6
|
-
import type { Rune } from "../Rune.ts"
|
|
7
|
-
import { Strand } from "../Strand.ts"
|
|
8
|
-
import type { Tool } from "../Tool.ts"
|
|
9
|
-
|
|
10
|
-
/** Configuration options for running a definition. */
|
|
11
|
-
export interface RunConfig<Y extends Rune<any>> {
|
|
12
|
-
handler?: Handler<Y> | undefined
|
|
13
|
-
models?: AdapterRegistry | undefined
|
|
14
|
-
messages?: Array<Message> | undefined
|
|
15
|
-
tools?: Set<Tool> | undefined
|
|
16
|
-
signal?: AbortSignal | undefined
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function run<Y extends Rune<any>, T>(definition: Definition<Y, T>, config?: RunConfig<Y>): Strand<Y, T> {
|
|
20
|
-
const context = Context({
|
|
21
|
-
handler: config?.handler,
|
|
22
|
-
adapters: config?.models ?? new AdapterRegistry(),
|
|
23
|
-
messages: config?.messages ?? [],
|
|
24
|
-
tools: config?.tools ?? new Set(),
|
|
25
|
-
})
|
|
26
|
-
return new Strand(definition, {
|
|
27
|
-
signal: config?.signal,
|
|
28
|
-
...config && { context },
|
|
29
|
-
})
|
|
30
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Schema } from "../../Schema.ts"
|
|
2
|
-
import { isTemplateStringsArray } from "../../util/isTemplateStringsArray.ts"
|
|
3
|
-
|
|
4
|
-
export function make<S extends Schema>(schema: Omit<S, "T">, description?: string): S & TypeBase {
|
|
5
|
-
const schema_ = {
|
|
6
|
-
...schema,
|
|
7
|
-
...description && { description },
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const Type = Object.assign(function describe(e0?: TemplateStringsArray | string, ...rest: Array<string>) {
|
|
11
|
-
const junction = isTemplateStringsArray(e0) ? String.raw(e0, ...rest) : e0
|
|
12
|
-
return make(
|
|
13
|
-
schema_,
|
|
14
|
-
description ? `${description}${junction ? `\n\n${junction}` : ""}` : junction,
|
|
15
|
-
)
|
|
16
|
-
}, schema_)
|
|
17
|
-
Object.defineProperty(Type, "toJSON", {
|
|
18
|
-
value() {
|
|
19
|
-
return schema_
|
|
20
|
-
},
|
|
21
|
-
enumerable: false,
|
|
22
|
-
})
|
|
23
|
-
return Type as never
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface TypeBase {
|
|
27
|
-
(template: TemplateStringsArray, ...substitutions: Array<string>): this
|
|
28
|
-
(...values: Array<string>): this
|
|
29
|
-
}
|
package/L/schema/anyOf.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Schema, SchemaAnyOf } from "../../Schema.ts"
|
|
2
|
-
import { make } from "./_schema_common.ts"
|
|
3
|
-
|
|
4
|
-
export interface anyOf<XA extends Array<Schema> = Array<Schema>> extends SchemaAnyOf<XA[number]["T"]> {
|
|
5
|
-
anyOf: XA
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function anyOf<XA extends Array<Schema>>(anyOf: XA): anyOf<XA> {
|
|
9
|
-
return make({ anyOf })
|
|
10
|
-
}
|
package/L/schema/array.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Schema, SchemaArray } from "../../Schema.ts"
|
|
2
|
-
import { make } from "./_schema_common.ts"
|
|
3
|
-
|
|
4
|
-
export interface LArray<X extends Schema = Schema> extends SchemaArray<Array<X["T"]>> {
|
|
5
|
-
items: X
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function array<X extends Schema>(items: X): LArray<X> {
|
|
9
|
-
return make({
|
|
10
|
-
type: "array",
|
|
11
|
-
items,
|
|
12
|
-
})
|
|
13
|
-
}
|
package/L/schema/boolean.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { SchemaBoolean } from "../../Schema.ts"
|
|
2
|
-
import { make, type TypeBase } from "./_schema_common.ts"
|
|
3
|
-
|
|
4
|
-
interface boolean_ extends SchemaBoolean<boolean>, TypeBase {}
|
|
5
|
-
|
|
6
|
-
const boolean_: boolean_ = make({ type: "boolean" })
|
|
7
|
-
|
|
8
|
-
export { boolean_ as boolean }
|
package/L/schema/const.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { SchemaString } from "../../Schema.ts"
|
|
2
|
-
import { make, type TypeBase } from "./_schema_common.ts"
|
|
3
|
-
|
|
4
|
-
interface const_<K extends string> extends SchemaString<K>, TypeBase {
|
|
5
|
-
enum?: never
|
|
6
|
-
const: K
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function const_<K extends string>(value: K): const_<K> {
|
|
10
|
-
return make({
|
|
11
|
-
type: "string",
|
|
12
|
-
const: value,
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
Object.defineProperty(const_, "name", { value: "const" })
|
|
17
|
-
|
|
18
|
-
export { const_ as const }
|
package/L/schema/enum.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { SchemaString } from "../../Schema.ts"
|
|
2
|
-
import { make, type TypeBase } from "./_schema_common.ts"
|
|
3
|
-
|
|
4
|
-
interface enum_<V extends Array<string> = Array<string>> extends SchemaString<V[number]>, TypeBase {
|
|
5
|
-
enum: V
|
|
6
|
-
const?: never
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function enum_<const V extends Array<string>>(...values: V): enum_<V> {
|
|
10
|
-
return make({
|
|
11
|
-
type: "string",
|
|
12
|
-
enum: values,
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
Object.defineProperty(enum_, "name", { value: "enum" })
|
|
17
|
-
|
|
18
|
-
export { enum_ as enum }
|
package/L/schema/integer.ts
DELETED
package/L/schema/null.ts
DELETED
package/L/schema/number.ts
DELETED
package/L/schema/object.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Schema, SchemaObject } from "../../Schema.ts"
|
|
2
|
-
import { make } from "./_schema_common.ts"
|
|
3
|
-
|
|
4
|
-
interface object_<F extends Record<string, Schema> = Record<string, Schema>>
|
|
5
|
-
extends SchemaObject<{ [K in keyof F]: F[K]["T"] }>
|
|
6
|
-
{
|
|
7
|
-
properties: F
|
|
8
|
-
required: Array<Extract<keyof F, string>>
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function object_<XR extends Record<string, Schema>>(properties: XR): object_<XR> {
|
|
12
|
-
return make({
|
|
13
|
-
type: "object",
|
|
14
|
-
properties,
|
|
15
|
-
additionalProperties: false,
|
|
16
|
-
required: Object.keys(properties) as never,
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
Object.defineProperty(object_, "name", { value: "object" })
|
|
21
|
-
export { object_ as object }
|
package/L/schema/string.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { SchemaString } from "../../Schema.ts"
|
|
2
|
-
import { make, type TypeBase } from "./_schema_common.ts"
|
|
3
|
-
|
|
4
|
-
interface string_ extends SchemaString<string>, TypeBase {
|
|
5
|
-
enum?: never
|
|
6
|
-
const?: never
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const string_: string_ = make({ type: "string" })
|
|
10
|
-
|
|
11
|
-
export { string_ as string }
|
package/L/strand.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Context } from "../Context.ts"
|
|
2
|
-
import type { Definition } from "../Definition.ts"
|
|
3
|
-
import type { LEvent } from "../LEvent.ts"
|
|
4
|
-
import { type Rune, RuneKey } from "../Rune.ts"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Creates a child strand that executes a definition.
|
|
8
|
-
* Optionally specify the context. Otherwise the current context is inherited.
|
|
9
|
-
*/
|
|
10
|
-
export function* strand<Y extends Rune<any>, T>(
|
|
11
|
-
definition: Definition<Y, T>,
|
|
12
|
-
context?: Context,
|
|
13
|
-
): Generator<Rune<LEvent>, T> {
|
|
14
|
-
return yield {
|
|
15
|
-
[RuneKey]: true,
|
|
16
|
-
instruction: {
|
|
17
|
-
kind: "create_child",
|
|
18
|
-
definition,
|
|
19
|
-
context,
|
|
20
|
-
},
|
|
21
|
-
}
|
|
22
|
-
}
|
package/L/stream.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { InferenceRequested, type LEvent } from "../LEvent.ts"
|
|
2
|
-
import type { Rune } from "../Rune.ts"
|
|
3
|
-
import { continuation } from "./continuation.ts"
|
|
4
|
-
import { emit } from "./emit.ts"
|
|
5
|
-
import { reflect } from "./reflect.ts"
|
|
6
|
-
|
|
7
|
-
/** Creates a readable stream of content from the current model. */
|
|
8
|
-
export const stream: Iterable<Rune<LEvent>, ReadableStream<string>> = {
|
|
9
|
-
*[Symbol.iterator]() {
|
|
10
|
-
const { context: { adapters, messages }, signal } = yield* reflect
|
|
11
|
-
const adapter = adapters.ensure()
|
|
12
|
-
const requestId = crypto.randomUUID()
|
|
13
|
-
yield* emit(new InferenceRequested(requestId))
|
|
14
|
-
return yield* continuation("stream", adapter.seal({ messages, signal }).stream)
|
|
15
|
-
},
|
|
16
|
-
}
|
package/L/system.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { LEvent } from "../LEvent.ts"
|
|
2
|
-
import type { Rune } from "../Rune.ts"
|
|
3
|
-
import { isTemplateStringsArray } from "../util/isTemplateStringsArray.ts"
|
|
4
|
-
import { message } from "./message.ts"
|
|
5
|
-
|
|
6
|
-
export function system(
|
|
7
|
-
template: TemplateStringsArray,
|
|
8
|
-
...substitutions: Array<number | string>
|
|
9
|
-
): Generator<Rune<LEvent>, void>
|
|
10
|
-
export function system(value: string): Generator<Rune<LEvent>, void>
|
|
11
|
-
export function system(
|
|
12
|
-
e0: TemplateStringsArray | string,
|
|
13
|
-
...rest: Array<number | string>
|
|
14
|
-
): Generator<Rune<LEvent>, void> {
|
|
15
|
-
return message("system", [{
|
|
16
|
-
part: isTemplateStringsArray(e0) ? String.raw(e0, ...rest) : e0,
|
|
17
|
-
}])
|
|
18
|
-
}
|
package/L/user.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { LEvent } from "../LEvent.ts"
|
|
2
|
-
import type { Rune } from "../Rune.ts"
|
|
3
|
-
import { isTemplateStringsArray } from "../util/isTemplateStringsArray.ts"
|
|
4
|
-
import { message } from "./message.ts"
|
|
5
|
-
|
|
6
|
-
export function user(
|
|
7
|
-
template: TemplateStringsArray,
|
|
8
|
-
...substitutions: Array<number | string>
|
|
9
|
-
): Generator<Rune<LEvent>, void>
|
|
10
|
-
export function user(value: string): Generator<Rune<LEvent>, void>
|
|
11
|
-
export function user(
|
|
12
|
-
e0: TemplateStringsArray | string,
|
|
13
|
-
...rest: Array<number | string>
|
|
14
|
-
): Generator<Rune<LEvent>, void> {
|
|
15
|
-
return message("user", [{
|
|
16
|
-
part: isTemplateStringsArray(e0) ? String.raw(e0, ...rest) : e0,
|
|
17
|
-
}])
|
|
18
|
-
}
|
package/LiminalAssertionError.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export class LiminalAssertionError extends Error {
|
|
2
|
-
override readonly name = "LiminalAssertionError"
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export namespace LiminalAssertionError {
|
|
6
|
-
export function assert(expr: unknown, msg = ""): asserts expr {
|
|
7
|
-
if (!expr) {
|
|
8
|
-
throw new LiminalAssertionError(msg)
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function unimplemented(): never {
|
|
13
|
-
throw new LiminalAssertionError()
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function unreachable(): never {
|
|
17
|
-
throw new LiminalAssertionError()
|
|
18
|
-
}
|
|
19
|
-
}
|
package/Message.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export interface Message {
|
|
2
|
-
readonly role: MessageRole
|
|
3
|
-
readonly parts: Array<Content>
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export type MessageRole = "system" | "user" | "assistant"
|
|
7
|
-
|
|
8
|
-
export type Content = {
|
|
9
|
-
readonly part: string
|
|
10
|
-
readonly alt?: never
|
|
11
|
-
readonly mime?: never
|
|
12
|
-
} | {
|
|
13
|
-
readonly part: URL
|
|
14
|
-
readonly alt: string
|
|
15
|
-
readonly mime?: string
|
|
16
|
-
}
|
package/Rune.test.ts
DELETED
package/Rune.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { Context } from "./Context.ts"
|
|
2
|
-
import type { Definition } from "./Definition.ts"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* `Rune` represents a computational unit within a Strand execution.
|
|
6
|
-
* It is a specialized protocol for expressing different kinds of operations
|
|
7
|
-
* that can be yielded from generator functions to control message state
|
|
8
|
-
* and concurrency within the Liminal runtime.
|
|
9
|
-
* @template E The event type this Rune can handle
|
|
10
|
-
*/
|
|
11
|
-
export interface Rune<E> {
|
|
12
|
-
[RuneKey]: true
|
|
13
|
-
instruction: RuneInstruction<E>
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type RuneInstruction<E> =
|
|
17
|
-
| RuneInstruction.Continue
|
|
18
|
-
| RuneInstruction.Emit<E>
|
|
19
|
-
| RuneInstruction.Reflect
|
|
20
|
-
| RuneInstruction.CreateChild
|
|
21
|
-
export namespace RuneInstruction {
|
|
22
|
-
/** Tells the runtime to call this function and and pass the result to the next iteration. */
|
|
23
|
-
export interface Continue {
|
|
24
|
-
kind: "continue"
|
|
25
|
-
debug: string
|
|
26
|
-
f: () => any
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Dispatch an event to the registered handler. */
|
|
30
|
-
export interface Emit<E> {
|
|
31
|
-
kind: "emit"
|
|
32
|
-
event: E
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Tells the runtime to provide a reference to the current strand */
|
|
36
|
-
export interface Reflect {
|
|
37
|
-
kind: "reflect"
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Creates a nested execution context with its own definition. */
|
|
41
|
-
export interface CreateChild {
|
|
42
|
-
kind: "create_child"
|
|
43
|
-
definition: Definition
|
|
44
|
-
context?: Context | undefined
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export namespace Rune {
|
|
49
|
-
/** Extract the event type from a Rune type. */
|
|
50
|
-
export type E<X extends Rune<any>> = X extends Rune<infer E> ? E : never
|
|
51
|
-
|
|
52
|
-
/** Type guard to check if a value is a Rune. */
|
|
53
|
-
export function is(value: unknown): value is Rune<any> {
|
|
54
|
-
return typeof value === "object" && value !== null && RuneKey in value
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Symbol used to identify Rune objects. */
|
|
59
|
-
export const RuneKey: unique symbol = Symbol.for("liminal/RuneKey")
|
|
60
|
-
export type RuneKey = typeof RuneKey
|