liminal 0.5.17 → 0.7.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 +8 -47
- package/L.ts +4 -0
- package/assistant.ts +52 -0
- package/dist/Context.d.ts +13 -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/assistant.d.ts +9 -0
- package/dist/assistant.js +44 -0
- package/dist/assistant.js.map +1 -0
- package/dist/index.d.ts +2 -14
- package/dist/index.js +2 -14
- package/dist/index.js.map +1 -1
- package/dist/messages.d.ts +4 -0
- package/dist/messages.js +5 -0
- package/dist/messages.js.map +1 -0
- package/dist/set.d.ts +3 -0
- package/dist/set.js +11 -0
- package/dist/set.js.map +1 -0
- package/dist/strand.d.ts +15 -0
- package/dist/strand.js +19 -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 +16 -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/index.ts +2 -14
- package/messages.ts +6 -0
- package/package.json +4 -3
- package/set.ts +11 -0
- package/strand.ts +38 -0
- package/todo.test.ts +3 -0
- package/user.ts +22 -0
- package/util/JSONValue.ts +0 -30
- 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 -29
- package/L/schema/_schema_common.ts +0 -30
- 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 -19
- package/L/user.ts +0 -19
- package/LEvent.ts +0 -61
- 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 -14
- 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 -20
- 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 -9
- package/dist/L/system.js.map +0 -1
- package/dist/L/user.d.ts +0 -4
- package/dist/L/user.js +0 -9
- package/dist/L/user.js.map +0 -1
- package/dist/LEvent.d.ts +0 -68
- package/dist/LEvent.js +0 -50
- package/dist/LEvent.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/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,29 +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
|
-
messages?: Array<Message> | undefined
|
|
14
|
-
tools?: Set<Tool> | undefined
|
|
15
|
-
signal?: AbortSignal | undefined
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function run<Y extends Rune<any>, T>(definition: Definition<Y, T>, config?: RunConfig<Y>): Strand<Y, T> {
|
|
19
|
-
const context = Context({
|
|
20
|
-
handler: config?.handler,
|
|
21
|
-
adapters: new AdapterRegistry(),
|
|
22
|
-
messages: config?.messages ?? [],
|
|
23
|
-
tools: config?.tools ?? new Set(),
|
|
24
|
-
})
|
|
25
|
-
return new Strand(definition, {
|
|
26
|
-
signal: config?.signal,
|
|
27
|
-
...config && { context },
|
|
28
|
-
})
|
|
29
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Schema } from "../../Schema.ts"
|
|
2
|
-
import { fixTemplateStrings } from "../../util/fixTemplateStrings.ts"
|
|
3
|
-
import { isTemplateStringsArray } from "../../util/isTemplateStringsArray.ts"
|
|
4
|
-
|
|
5
|
-
export function make<S extends Schema>(schema: Omit<S, "T">, description?: string): S & TypeBase {
|
|
6
|
-
const schema_ = {
|
|
7
|
-
...schema,
|
|
8
|
-
...description && { description },
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const Type = Object.assign(function describe(e0?: TemplateStringsArray | string, ...rest: Array<string>) {
|
|
12
|
-
const junction = isTemplateStringsArray(e0) ? String.raw(fixTemplateStrings(e0), ...rest) : e0
|
|
13
|
-
return make(
|
|
14
|
-
schema_,
|
|
15
|
-
description ? `${description}${junction ? `\n\n${junction}` : ""}` : junction,
|
|
16
|
-
)
|
|
17
|
-
}, schema_)
|
|
18
|
-
Object.defineProperty(Type, "toJSON", {
|
|
19
|
-
value() {
|
|
20
|
-
return schema_
|
|
21
|
-
},
|
|
22
|
-
enumerable: false,
|
|
23
|
-
})
|
|
24
|
-
return Type as never
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface TypeBase {
|
|
28
|
-
(template: TemplateStringsArray, ...substitutions: Array<string>): this
|
|
29
|
-
(...values: Array<string>): this
|
|
30
|
-
}
|
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,19 +0,0 @@
|
|
|
1
|
-
import type { LEvent } from "../LEvent.ts"
|
|
2
|
-
import type { Rune } from "../Rune.ts"
|
|
3
|
-
import { fixTemplateStrings } from "../util/fixTemplateStrings.ts"
|
|
4
|
-
import { isTemplateStringsArray } from "../util/isTemplateStringsArray.ts"
|
|
5
|
-
import { message } from "./message.ts"
|
|
6
|
-
|
|
7
|
-
export function system(
|
|
8
|
-
template: TemplateStringsArray,
|
|
9
|
-
...substitutions: Array<number | string>
|
|
10
|
-
): Generator<Rune<LEvent>, void>
|
|
11
|
-
export function system(value: string): Generator<Rune<LEvent>, void>
|
|
12
|
-
export function system(
|
|
13
|
-
e0: TemplateStringsArray | string,
|
|
14
|
-
...rest: Array<number | string>
|
|
15
|
-
): Generator<Rune<LEvent>, void> {
|
|
16
|
-
return message("system", [{
|
|
17
|
-
part: isTemplateStringsArray(e0) ? String.raw(fixTemplateStrings(e0), ...rest) : e0,
|
|
18
|
-
}])
|
|
19
|
-
}
|
package/L/user.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { LEvent } from "../LEvent.ts"
|
|
2
|
-
import type { Rune } from "../Rune.ts"
|
|
3
|
-
import { fixTemplateStrings } from "../util/fixTemplateStrings.ts"
|
|
4
|
-
import { isTemplateStringsArray } from "../util/isTemplateStringsArray.ts"
|
|
5
|
-
import { message } from "./message.ts"
|
|
6
|
-
|
|
7
|
-
export function user(
|
|
8
|
-
template: TemplateStringsArray,
|
|
9
|
-
...substitutions: Array<number | string>
|
|
10
|
-
): Generator<Rune<LEvent>, void>
|
|
11
|
-
export function user(value: string): Generator<Rune<LEvent>, void>
|
|
12
|
-
export function user(
|
|
13
|
-
e0: TemplateStringsArray | string,
|
|
14
|
-
...rest: Array<number | string>
|
|
15
|
-
): Generator<Rune<LEvent>, void> {
|
|
16
|
-
return message("user", [{
|
|
17
|
-
part: isTemplateStringsArray(e0) ? String.raw(fixTemplateStrings(e0), ...rest) : e0,
|
|
18
|
-
}])
|
|
19
|
-
}
|
package/LEvent.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Adapter } from "./Adapter.ts"
|
|
2
|
-
import { EventBase } from "./EventBase.ts"
|
|
3
|
-
import type { Message } from "./Message.ts"
|
|
4
|
-
import type { Schema } from "./Schema.ts"
|
|
5
|
-
import type { StrandStatus } from "./Strand.ts"
|
|
6
|
-
|
|
7
|
-
export type LEvent =
|
|
8
|
-
| AdapterFocused
|
|
9
|
-
| InferenceRequested
|
|
10
|
-
| Inferred
|
|
11
|
-
| MessageAppended
|
|
12
|
-
| StrandStatusChanged
|
|
13
|
-
|
|
14
|
-
export namespace LEvent {
|
|
15
|
-
export function is(value: unknown): value is LEvent {
|
|
16
|
-
return typeof value === "object" && value !== null && "brand" in value && value.brand === LEventTag
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const LEventTag: unique symbol = Symbol.for("liminal/LEvent")
|
|
21
|
-
export type LEventTag = typeof LEventTag
|
|
22
|
-
|
|
23
|
-
export class AdapterFocused extends EventBase(LEventTag, "adapter_focused") {
|
|
24
|
-
constructor(readonly adapter: Adapter) {
|
|
25
|
-
super()
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class InferenceRequested extends EventBase(LEventTag, "inference_requested") {
|
|
30
|
-
declare schema?: Schema
|
|
31
|
-
constructor(
|
|
32
|
-
readonly requestId: string,
|
|
33
|
-
schema?: Schema | undefined,
|
|
34
|
-
) {
|
|
35
|
-
super()
|
|
36
|
-
if (schema) {
|
|
37
|
-
this.schema = schema
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class Inferred extends EventBase(LEventTag, "inferred") {
|
|
43
|
-
constructor(
|
|
44
|
-
readonly requestId: string,
|
|
45
|
-
readonly inference: string,
|
|
46
|
-
) {
|
|
47
|
-
super()
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export class MessageAppended extends EventBase(LEventTag, "message_appended") {
|
|
52
|
-
constructor(readonly message: Message) {
|
|
53
|
-
super()
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export class StrandStatusChanged extends EventBase(LEventTag, "strand_status_changed") {
|
|
58
|
-
constructor(readonly status: StrandStatus) {
|
|
59
|
-
super()
|
|
60
|
-
}
|
|
61
|
-
}
|
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
|
package/Schema.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { subtle } from "node:crypto"
|
|
2
|
-
import { LiminalAssertionError as LE } from "./LiminalAssertionError.ts"
|
|
3
|
-
|
|
4
|
-
export type Schema<T = any> = SchemaType<T> | SchemaAnyOf<T>
|
|
5
|
-
|
|
6
|
-
export type SchemaType<T = any> =
|
|
7
|
-
| SchemaNull<T>
|
|
8
|
-
| SchemaBoolean<T>
|
|
9
|
-
| SchemaInteger<T>
|
|
10
|
-
| SchemaNumber<T>
|
|
11
|
-
| SchemaString<T>
|
|
12
|
-
| SchemaArray<T>
|
|
13
|
-
| SchemaObject<T>
|
|
14
|
-
|
|
15
|
-
export interface SchemaNull<T = any> extends SchemaTypeBase<"null", T> {}
|
|
16
|
-
|
|
17
|
-
export interface SchemaBoolean<T = any> extends SchemaTypeBase<"boolean", T> {}
|
|
18
|
-
|
|
19
|
-
export interface SchemaInteger<T = any> extends SchemaTypeBase<"integer", T> {}
|
|
20
|
-
|
|
21
|
-
export interface SchemaNumber<T = any> extends SchemaTypeBase<"number", T> {}
|
|
22
|
-
|
|
23
|
-
export interface SchemaString<T = any> extends SchemaTypeBase<"string", T> {
|
|
24
|
-
enum?: Array<string>
|
|
25
|
-
const?: string
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface SchemaArray<T = any> extends SchemaTypeBase<"array", T> {
|
|
29
|
-
items: Schema
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface SchemaObject<T = any> extends SchemaTypeBase<"object", T> {
|
|
33
|
-
properties: Record<string, Schema>
|
|
34
|
-
required: Array<string>
|
|
35
|
-
additionalProperties: false
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
interface SchemaTypeBase<K extends SchemaTypeName, T> extends SchemaBase<T> {
|
|
39
|
-
type: K
|
|
40
|
-
anyOf?: never
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type SchemaTypeName = "null" | "boolean" | "integer" | "number" | "string" | "array" | "object"
|
|
44
|
-
|
|
45
|
-
export interface SchemaAnyOf<T = any> extends SchemaBase<T> {
|
|
46
|
-
type?: never
|
|
47
|
-
anyOf: Array<Schema>
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface SchemaBase<T> {
|
|
51
|
-
T: T
|
|
52
|
-
description?: string
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export namespace Schema {
|
|
56
|
-
const ids = new WeakMap<Schema, Record<string, string>>()
|
|
57
|
-
const schemas = new WeakMap<WeakKey, Schema>()
|
|
58
|
-
const validators = new WeakMap<Schema, (value: unknown) => unknown>()
|
|
59
|
-
|
|
60
|
-
export function compile<T>(key: WeakKey, {
|
|
61
|
-
schema: schema_,
|
|
62
|
-
validate,
|
|
63
|
-
}: {
|
|
64
|
-
schema(): unknown
|
|
65
|
-
validate(value: unknown): T
|
|
66
|
-
}) {
|
|
67
|
-
let schema = schemas.get(key)
|
|
68
|
-
if (!schema) {
|
|
69
|
-
schema = Schema.validate(schema_())
|
|
70
|
-
schemas.set(key, schema)
|
|
71
|
-
}
|
|
72
|
-
validators.set(schema, validate)
|
|
73
|
-
return schema
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function validateValue<T>(schema: Schema<T>, value: unknown): T {
|
|
77
|
-
const validator = validators.get(schema)
|
|
78
|
-
LE.assert(validator)
|
|
79
|
-
return validator(value) as never
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export async function id(schema: Schema, description?: string): Promise<string> {
|
|
83
|
-
description = description ?? ""
|
|
84
|
-
if (!ids.has(schema)) {
|
|
85
|
-
ids.set(schema, {})
|
|
86
|
-
}
|
|
87
|
-
const schemaIds = ids.get(schema)!
|
|
88
|
-
let id = schemaIds[description]
|
|
89
|
-
if (!id) {
|
|
90
|
-
const content = `${description}_${JSON.stringify(schema)}`
|
|
91
|
-
const bytes = new Uint8Array(await subtle.digest("SHA-256", new TextEncoder().encode(content)))
|
|
92
|
-
let binary = ""
|
|
93
|
-
for (const b of bytes) binary += String.fromCharCode(b)
|
|
94
|
-
id = btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")
|
|
95
|
-
schemaIds[description] = id
|
|
96
|
-
}
|
|
97
|
-
return id
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function wrap(schema: Schema): SchemaObject {
|
|
101
|
-
return {
|
|
102
|
-
type: "object",
|
|
103
|
-
properties: { value: schema },
|
|
104
|
-
additionalProperties: false,
|
|
105
|
-
required: ["value"],
|
|
106
|
-
} satisfies Omit<SchemaObject, "T"> as never
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function validate(value: unknown): Schema {
|
|
110
|
-
LE.assert(typeof value === "object")
|
|
111
|
-
LE.assert(value !== null)
|
|
112
|
-
if ("anyOf" in value) {
|
|
113
|
-
LE.assert(Array.isArray(value.anyOf))
|
|
114
|
-
return {
|
|
115
|
-
anyOf: value.anyOf.map(validate),
|
|
116
|
-
} satisfies Omit<SchemaAnyOf, "T"> as never
|
|
117
|
-
} else {
|
|
118
|
-
if ("enum" in value) {
|
|
119
|
-
LE.assert(Array.isArray(value.enum))
|
|
120
|
-
LE.assert(!("const" in value))
|
|
121
|
-
value.enum.forEach((v) => LE.assert(typeof v === "string"))
|
|
122
|
-
return {
|
|
123
|
-
type: "string",
|
|
124
|
-
enum: value.enum,
|
|
125
|
-
} satisfies Omit<SchemaString, "T"> as never
|
|
126
|
-
} else if ("const" in value) {
|
|
127
|
-
LE.assert(typeof value.const === "string")
|
|
128
|
-
return {
|
|
129
|
-
type: "string",
|
|
130
|
-
const: value.const,
|
|
131
|
-
} satisfies Omit<SchemaString, "T"> as never
|
|
132
|
-
} else if ("type" in value) {
|
|
133
|
-
LE.assert("type" in value)
|
|
134
|
-
LE.assert(typeof value.type === "string")
|
|
135
|
-
LE.assert(SCHEMA_TYPE_NAMES[value.type])
|
|
136
|
-
switch (value.type) {
|
|
137
|
-
case "null":
|
|
138
|
-
case "boolean":
|
|
139
|
-
case "integer":
|
|
140
|
-
case "number": {
|
|
141
|
-
break
|
|
142
|
-
}
|
|
143
|
-
case "string": {
|
|
144
|
-
if ("const" in value) {
|
|
145
|
-
LE.assert(typeof value.const === "string")
|
|
146
|
-
}
|
|
147
|
-
break
|
|
148
|
-
}
|
|
149
|
-
case "array": {
|
|
150
|
-
LE.assert("items" in value)
|
|
151
|
-
return {
|
|
152
|
-
type: "array",
|
|
153
|
-
items: validate(value.items),
|
|
154
|
-
} satisfies Omit<SchemaArray, "T"> as never
|
|
155
|
-
}
|
|
156
|
-
case "object": {
|
|
157
|
-
LE.assert("properties" in value)
|
|
158
|
-
LE.assert(typeof value.properties === "object")
|
|
159
|
-
const { properties } = value
|
|
160
|
-
LE.assert(properties !== null)
|
|
161
|
-
return {
|
|
162
|
-
type: "object",
|
|
163
|
-
properties: Object.fromEntries(
|
|
164
|
-
Object.entries(properties).map(([key, value]) => [key, validate(value)]),
|
|
165
|
-
),
|
|
166
|
-
required: Object.keys(properties),
|
|
167
|
-
additionalProperties: false,
|
|
168
|
-
} satisfies Omit<SchemaObject, "T"> as never
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return value as Schema
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const SCHEMA_TYPE_NAMES: Record<string, boolean> = {
|
|
178
|
-
null: true,
|
|
179
|
-
boolean: true,
|
|
180
|
-
integer: true,
|
|
181
|
-
number: true,
|
|
182
|
-
string: true,
|
|
183
|
-
array: true,
|
|
184
|
-
object: true,
|
|
185
|
-
} satisfies Record<SchemaTypeName, true>
|