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/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>
|
package/Strand.ts
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
import { Context } from "./Context.ts"
|
|
2
|
-
import { Definition } from "./Definition.ts"
|
|
3
|
-
import { StrandRejectedError } from "./errors.ts"
|
|
4
|
-
import { continuation } from "./L/continuation.ts"
|
|
5
|
-
import { StrandStatusChanged } from "./LEvent.ts"
|
|
6
|
-
import type { Rune } from "./Rune.ts"
|
|
7
|
-
import { attachCustomInspect } from "./util/attachCustomInspect.ts"
|
|
8
|
-
|
|
9
|
-
/** Configuration options for creating a new Strand. */
|
|
10
|
-
export interface StrandConfig {
|
|
11
|
-
/** Optional parent strand that this strand will be a child of */
|
|
12
|
-
parent?: Strand | undefined
|
|
13
|
-
/** Optional context for the strand execution */
|
|
14
|
-
context?: Context | undefined
|
|
15
|
-
/** Optional abort signal that can be used to cancel strand execution */
|
|
16
|
-
signal?: AbortSignal | undefined
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
let nextIndex: number = 0
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* A "Strand" is the core unit of execution in Liminal.
|
|
23
|
-
*
|
|
24
|
-
* It represents a suspendable computation that can yield Runes to control conversation state.
|
|
25
|
-
* Strands implement both the Iterable and PromiseLike interfaces to enable both
|
|
26
|
-
* running (via awaiting) and joining to parent strands (via yielding).
|
|
27
|
-
*
|
|
28
|
-
* Strands maintain their own state and can be hierarchically organized with parent-child
|
|
29
|
-
* relationships. Child strands are bound to their parents, ensuring consistent
|
|
30
|
-
* cancellation behavior.
|
|
31
|
-
*
|
|
32
|
-
* @template Y The type of Runes this Strand can yield.
|
|
33
|
-
* @template T The result type of the Strand.
|
|
34
|
-
*/
|
|
35
|
-
export class Strand<Y extends Rune<any> = Rune<any>, T = any> implements Iterable<Y, T>, PromiseLike<T> {
|
|
36
|
-
declare T: T
|
|
37
|
-
declare Y: Y
|
|
38
|
-
|
|
39
|
-
/** Controls abort signal propagation. */
|
|
40
|
-
readonly #controller: AbortController = new AbortController()
|
|
41
|
-
/** Signal that can be used to detect when this strand is aborted. */
|
|
42
|
-
readonly signal: AbortSignal = this.#controller.signal
|
|
43
|
-
/** Optional event handler function. */
|
|
44
|
-
#handle?: ((this: Strand, event: any) => void) | undefined
|
|
45
|
-
/** The definition (usually via generator function) that powers this strand. */
|
|
46
|
-
#definition: Definition<Y, T>
|
|
47
|
-
/** Current status of the strand (untouched, pending, resolved, rejected) */
|
|
48
|
-
status: StrandStatus<T> = { type: "untouched" }
|
|
49
|
-
/** Unique identifier for this strand. */
|
|
50
|
-
readonly index: number = nextIndex++
|
|
51
|
-
/** Nesting depth in the strand hierarchy. */
|
|
52
|
-
readonly depth: number
|
|
53
|
-
/** The parent strand or undefined. */
|
|
54
|
-
declare readonly parent?: Strand
|
|
55
|
-
/** The conversation state with which the strand operates. */
|
|
56
|
-
readonly context: Context
|
|
57
|
-
|
|
58
|
-
constructor(definition: Definition<Y, T>, config: StrandConfig) {
|
|
59
|
-
this.#definition = definition
|
|
60
|
-
this.depth = (config?.parent?.depth ?? -1) + 1
|
|
61
|
-
const { parent, context, signal: configSignal } = config ?? {}
|
|
62
|
-
if (parent) {
|
|
63
|
-
this.parent = parent
|
|
64
|
-
this.#attachSignal(parent.signal, () => ({
|
|
65
|
-
type: "parent_aborted",
|
|
66
|
-
reason: parent.signal.reason,
|
|
67
|
-
}))
|
|
68
|
-
}
|
|
69
|
-
if (configSignal) {
|
|
70
|
-
this.#attachSignal(configSignal, () => ({
|
|
71
|
-
type: "config_signal_aborted",
|
|
72
|
-
reason: configSignal.reason,
|
|
73
|
-
}))
|
|
74
|
-
}
|
|
75
|
-
if (context) {
|
|
76
|
-
this.context = context
|
|
77
|
-
const { handler } = context
|
|
78
|
-
if (handler) {
|
|
79
|
-
this.#handle = (function(this: Strand, event: any) {
|
|
80
|
-
try {
|
|
81
|
-
handler.call(this, event)
|
|
82
|
-
} catch (exception) {
|
|
83
|
-
this.#setTerminalStatus({
|
|
84
|
-
type: "handler_exception_thrown",
|
|
85
|
-
exception,
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
}).bind(this)
|
|
89
|
-
this.#handle(new StrandStatusChanged(this.status))
|
|
90
|
-
}
|
|
91
|
-
} else {
|
|
92
|
-
this.context = Context()
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
#setStatus(status: StrandStatus<T>): void {
|
|
97
|
-
this.status = status
|
|
98
|
-
this.#handle?.(new StrandStatusChanged(this.status))
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
#setTerminalStatus = (status: StrandStatus.Rejected | StrandStatus.Resolved<T>): void => {
|
|
102
|
-
this.#setStatus(status)
|
|
103
|
-
this.#controller.abort(this.status)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
#attachSignal(
|
|
107
|
-
signal: AbortSignal,
|
|
108
|
-
getStatus: () => StrandStatus.Rejected.ConfigSignalAborted | StrandStatus.Rejected.ParentAborted,
|
|
109
|
-
): void {
|
|
110
|
-
const f = () => {
|
|
111
|
-
this.#setTerminalStatus(getStatus())
|
|
112
|
-
}
|
|
113
|
-
if (signal.aborted) {
|
|
114
|
-
return f()
|
|
115
|
-
}
|
|
116
|
-
signal.addEventListener("abort", f, { once: true })
|
|
117
|
-
this.#controller.signal.addEventListener(
|
|
118
|
-
"abort",
|
|
119
|
-
() => {
|
|
120
|
-
signal.removeEventListener("abort", f)
|
|
121
|
-
},
|
|
122
|
-
{ once: true },
|
|
123
|
-
)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
then<TResult1 = T, TResult2 = never>(
|
|
127
|
-
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
|
|
128
|
-
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
|
|
129
|
-
): PromiseLike<TResult1 | TResult2> {
|
|
130
|
-
if (this.status.type !== "untouched") {
|
|
131
|
-
return this.#replay(this.status).then(onfulfilled, onrejected)
|
|
132
|
-
}
|
|
133
|
-
let resolve: (value: T) => void = undefined!
|
|
134
|
-
let reject: (reason?: unknown) => void = undefined!
|
|
135
|
-
const promise = new Promise<T>((resolve_, reject_) => {
|
|
136
|
-
resolve = resolve_
|
|
137
|
-
reject = reject_
|
|
138
|
-
})
|
|
139
|
-
this.status = {
|
|
140
|
-
type: "pending",
|
|
141
|
-
promise,
|
|
142
|
-
resolve,
|
|
143
|
-
reject,
|
|
144
|
-
}
|
|
145
|
-
this.#handle?.(new StrandStatusChanged(this.status))
|
|
146
|
-
const iterator = Definition.unwrap(this.#definition)
|
|
147
|
-
let nextArg: unknown
|
|
148
|
-
queueMicrotask(async () => {
|
|
149
|
-
try {
|
|
150
|
-
let current = await iterator.next()
|
|
151
|
-
while (!current.done) {
|
|
152
|
-
const rune = current.value
|
|
153
|
-
const { instruction: value } = rune
|
|
154
|
-
switch (value.kind) {
|
|
155
|
-
case "reflect": {
|
|
156
|
-
nextArg = this
|
|
157
|
-
break
|
|
158
|
-
}
|
|
159
|
-
case "continue": {
|
|
160
|
-
nextArg = await value.f()
|
|
161
|
-
break
|
|
162
|
-
}
|
|
163
|
-
case "emit": {
|
|
164
|
-
this.#handle?.(value.event)
|
|
165
|
-
nextArg = undefined
|
|
166
|
-
break
|
|
167
|
-
}
|
|
168
|
-
case "create_child": {
|
|
169
|
-
nextArg = await new Strand(value.definition, {
|
|
170
|
-
parent: this,
|
|
171
|
-
context: value.context ?? this.context.clone(),
|
|
172
|
-
}).then()
|
|
173
|
-
break
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
switch (this.status.type) {
|
|
177
|
-
case "config_signal_aborted":
|
|
178
|
-
case "parent_aborted":
|
|
179
|
-
case "continuation_exception_thrown":
|
|
180
|
-
case "handler_exception_thrown": {
|
|
181
|
-
try {
|
|
182
|
-
await iterator.return?.(undefined)
|
|
183
|
-
} catch (exception) {}
|
|
184
|
-
return Promise.reject(new StrandRejectedError(this.status))
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
current = await iterator.next(nextArg)
|
|
188
|
-
}
|
|
189
|
-
const { value } = current
|
|
190
|
-
this.#setTerminalStatus({
|
|
191
|
-
type: "resolved",
|
|
192
|
-
value,
|
|
193
|
-
})
|
|
194
|
-
resolve(value)
|
|
195
|
-
} catch (exception) {
|
|
196
|
-
this.#setTerminalStatus({
|
|
197
|
-
type: "continuation_exception_thrown",
|
|
198
|
-
exception,
|
|
199
|
-
})
|
|
200
|
-
reject(exception)
|
|
201
|
-
}
|
|
202
|
-
})
|
|
203
|
-
return promise.then(onfulfilled, onrejected)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
*[Symbol.iterator](): Generator<Y, T> {
|
|
207
|
-
return yield* continuation("run_strand", () => this.then()) as any
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
#replay(status: Exclude<StrandStatus, StrandStatus.Untouched>): Promise<T> {
|
|
211
|
-
switch (status.type) {
|
|
212
|
-
case "config_signal_aborted":
|
|
213
|
-
case "parent_aborted":
|
|
214
|
-
case "continuation_exception_thrown":
|
|
215
|
-
// case "model_error":
|
|
216
|
-
case "handler_exception_thrown": {
|
|
217
|
-
return Promise.reject(new StrandRejectedError(status))
|
|
218
|
-
}
|
|
219
|
-
case "resolved": {
|
|
220
|
-
return Promise.resolve(status.value)
|
|
221
|
-
}
|
|
222
|
-
case "pending": {
|
|
223
|
-
return status.promise
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
static {
|
|
229
|
-
attachCustomInspect(this, ({ index, parent }) => ({ index, ...parent && { parent } }))
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export type StrandStatus<T = any> =
|
|
234
|
-
| StrandStatus.Untouched
|
|
235
|
-
| StrandStatus.Pending<T>
|
|
236
|
-
| StrandStatus.Resolved<T>
|
|
237
|
-
| StrandStatus.Rejected
|
|
238
|
-
export namespace StrandStatus {
|
|
239
|
-
export interface Untouched {
|
|
240
|
-
type: "untouched"
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export interface Pending<T> {
|
|
244
|
-
type: "pending"
|
|
245
|
-
promise: Promise<T>
|
|
246
|
-
resolve: (value: T) => void
|
|
247
|
-
reject: (reason?: unknown) => void
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export interface Resolved<T> {
|
|
251
|
-
type: "resolved"
|
|
252
|
-
value: T
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export type Rejected =
|
|
256
|
-
| Rejected.ConfigSignalAborted
|
|
257
|
-
| Rejected.ParentAborted
|
|
258
|
-
| Rejected.ContinuationExceptionThrown
|
|
259
|
-
| Rejected.HandlerExceptionThrown
|
|
260
|
-
// | Rejected.ModelError
|
|
261
|
-
export namespace Rejected {
|
|
262
|
-
export interface ConfigSignalAborted {
|
|
263
|
-
type: "config_signal_aborted"
|
|
264
|
-
reason: unknown
|
|
265
|
-
}
|
|
266
|
-
export interface ParentAborted {
|
|
267
|
-
type: "parent_aborted"
|
|
268
|
-
reason: unknown
|
|
269
|
-
}
|
|
270
|
-
export interface ContinuationExceptionThrown {
|
|
271
|
-
type: "continuation_exception_thrown"
|
|
272
|
-
exception: unknown
|
|
273
|
-
}
|
|
274
|
-
export interface HandlerExceptionThrown {
|
|
275
|
-
type: "handler_exception_thrown"
|
|
276
|
-
exception: unknown
|
|
277
|
-
}
|
|
278
|
-
// export interface ModelError {
|
|
279
|
-
// type: "model_error"
|
|
280
|
-
// model: string
|
|
281
|
-
// error: unknown
|
|
282
|
-
// }
|
|
283
|
-
}
|
|
284
|
-
}
|
package/Tool.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Schema } from "./Schema.ts"
|
|
2
|
-
import type { JSONValue } from "./util/JSONValue.ts"
|
|
3
|
-
|
|
4
|
-
export class Tool {
|
|
5
|
-
static async make<T extends JSONValue>(
|
|
6
|
-
description: string,
|
|
7
|
-
schema: Schema<T>,
|
|
8
|
-
f: (arg: T) => JSONValue | Promise<JSONValue>,
|
|
9
|
-
) {
|
|
10
|
-
return new Tool(
|
|
11
|
-
await Schema.id(schema, description),
|
|
12
|
-
description,
|
|
13
|
-
schema,
|
|
14
|
-
async (arg) => {
|
|
15
|
-
return await f(await Schema.validateValue(schema, arg))
|
|
16
|
-
},
|
|
17
|
-
)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
constructor(
|
|
21
|
-
readonly name: string,
|
|
22
|
-
readonly description: string,
|
|
23
|
-
readonly parameterSchema: Schema,
|
|
24
|
-
readonly f: (arg: any) => JSONValue | Promise<JSONValue>,
|
|
25
|
-
) {}
|
|
26
|
-
}
|
package/TypeAdapter.ts
DELETED
package/dist/Adapter.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Message } from "./Message.ts";
|
|
2
|
-
import type { SchemaObject } from "./Schema.ts";
|
|
3
|
-
import type { Tool } from "./Tool.ts";
|
|
4
|
-
export declare class Adapter {
|
|
5
|
-
readonly name: string;
|
|
6
|
-
readonly seal: (envelope: Envelope) => SealedEnvelope;
|
|
7
|
-
constructor(name: string, seal: (envelope: Envelope) => SealedEnvelope);
|
|
8
|
-
}
|
|
9
|
-
export interface Envelope {
|
|
10
|
-
messages: Array<Message>;
|
|
11
|
-
schema?: SchemaObject | undefined;
|
|
12
|
-
signal: AbortSignal;
|
|
13
|
-
tools?: Set<Tool> | undefined;
|
|
14
|
-
}
|
|
15
|
-
export interface SealedEnvelope {
|
|
16
|
-
resolve: () => Promise<string>;
|
|
17
|
-
stream: () => ReadableStream<string>;
|
|
18
|
-
}
|
package/dist/Adapter.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { attachCustomInspect } from "./util/attachCustomInspect.js";
|
|
2
|
-
export class Adapter {
|
|
3
|
-
name;
|
|
4
|
-
seal;
|
|
5
|
-
constructor(name, seal) {
|
|
6
|
-
this.name = name;
|
|
7
|
-
this.seal = seal;
|
|
8
|
-
}
|
|
9
|
-
static {
|
|
10
|
-
attachCustomInspect(this, ({ name }) => ({ name }));
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=Adapter.js.map
|
package/dist/Adapter.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Adapter.js","sourceRoot":"","sources":["../Adapter.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAEnE,MAAM,OAAO,OAAO;IAEP;IACA;IAFX,YACW,IAAY,EACZ,IAA4C;QAD5C,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAwC;IACpD,CAAC;IAEJ;QACE,mBAAmB,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACrD,CAAC;CACF"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Adapter } from "./Adapter.ts";
|
|
2
|
-
/**
|
|
3
|
-
* An intrusive doubly-linked list for storing `Model`s.
|
|
4
|
-
* Provides efficient insertion, removal, and lookups.
|
|
5
|
-
*/
|
|
6
|
-
export declare class AdapterRegistry {
|
|
7
|
-
head?: ModelRegistryNode | undefined;
|
|
8
|
-
tail?: ModelRegistryNode | undefined;
|
|
9
|
-
/** Returns the most recently registered model */
|
|
10
|
-
peek(): Adapter | undefined;
|
|
11
|
-
/** Ensure */
|
|
12
|
-
ensure(): Adapter;
|
|
13
|
-
/**
|
|
14
|
-
* Registers a new model and returns the created node
|
|
15
|
-
* @param value The model to register
|
|
16
|
-
*/
|
|
17
|
-
register(value: Adapter): ModelRegistryNode;
|
|
18
|
-
/** Remove a model from the registry. */
|
|
19
|
-
remove(node: ModelRegistryNode): void;
|
|
20
|
-
/** Creates a deep copy of this registry. */
|
|
21
|
-
clone(): AdapterRegistry;
|
|
22
|
-
}
|
|
23
|
-
export interface ModelRegistryNode {
|
|
24
|
-
prev: ModelRegistryNode | undefined;
|
|
25
|
-
adapter: Adapter;
|
|
26
|
-
next?: ModelRegistryNode | undefined;
|
|
27
|
-
}
|
package/dist/AdapterRegistry.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { LiminalAssertionError } from "./LiminalAssertionError.js";
|
|
2
|
-
/**
|
|
3
|
-
* An intrusive doubly-linked list for storing `Model`s.
|
|
4
|
-
* Provides efficient insertion, removal, and lookups.
|
|
5
|
-
*/
|
|
6
|
-
export class AdapterRegistry {
|
|
7
|
-
/** Returns the most recently registered model */
|
|
8
|
-
peek() {
|
|
9
|
-
return this.tail?.adapter;
|
|
10
|
-
}
|
|
11
|
-
/** Ensure */
|
|
12
|
-
ensure() {
|
|
13
|
-
LiminalAssertionError.assert(this.tail, "No conversation adapter registered. Use `L.focus` to focus a conversation adapter.");
|
|
14
|
-
return this.tail.adapter;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Registers a new model and returns the created node
|
|
18
|
-
* @param value The model to register
|
|
19
|
-
*/
|
|
20
|
-
register(value) {
|
|
21
|
-
const node = {
|
|
22
|
-
prev: this.tail,
|
|
23
|
-
adapter: value,
|
|
24
|
-
};
|
|
25
|
-
if (this.tail) {
|
|
26
|
-
this.tail.next = node;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
this.head = node;
|
|
30
|
-
}
|
|
31
|
-
this.tail = node;
|
|
32
|
-
return node;
|
|
33
|
-
}
|
|
34
|
-
/** Remove a model from the registry. */
|
|
35
|
-
remove(node) {
|
|
36
|
-
if (node.prev) {
|
|
37
|
-
node.prev.next = node.next;
|
|
38
|
-
}
|
|
39
|
-
if (node.next) {
|
|
40
|
-
node.next.prev = node.prev;
|
|
41
|
-
}
|
|
42
|
-
if (node === this.head) {
|
|
43
|
-
this.head = node.next;
|
|
44
|
-
}
|
|
45
|
-
if (node === this.tail) {
|
|
46
|
-
this.tail = node.prev;
|
|
47
|
-
}
|
|
48
|
-
node.prev = undefined;
|
|
49
|
-
delete node.next;
|
|
50
|
-
}
|
|
51
|
-
/** Creates a deep copy of this registry. */
|
|
52
|
-
clone() {
|
|
53
|
-
const instance = new AdapterRegistry();
|
|
54
|
-
for (let node = this.head; node; node = node.next) {
|
|
55
|
-
if (node.adapter) {
|
|
56
|
-
instance.register(node.adapter);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return instance;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=AdapterRegistry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AdapterRegistry.js","sourceRoot":"","sources":["../AdapterRegistry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAElE;;;GAGG;AACH,MAAM,OAAO,eAAe;IAI1B,iDAAiD;IACjD,IAAI;QACF,OAAO,IAAI,CAAC,IAAI,EAAE,OAAO,CAAA;IAC3B,CAAC;IAED,aAAa;IACb,MAAM;QACJ,qBAAqB,CAAC,MAAM,CAC1B,IAAI,CAAC,IAAI,EACT,oFAAoF,CACrF,CAAA;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAA;IAC1B,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,KAAc;QACrB,MAAM,IAAI,GAAsB;YAC9B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,KAAK;SACf,CAAA;QACD,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QACvB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAClB,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,wCAAwC;IACxC,MAAM,CAAC,IAAuB;QAC5B,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QAC5B,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QAC5B,CAAC;QACD,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACvB,CAAC;QACD,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACvB,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,SAAS,CAAA;QACrB,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED,4CAA4C;IAC5C,KAAK;QACH,MAAM,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAA;QACtC,KAAK,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAClD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjB,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACjC,CAAC;QACH,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF"}
|
package/dist/Config.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { AdapterRegistry } from "./AdapterRegistry.ts";
|
|
2
|
-
import type { Message } from "./Message.ts";
|
|
3
|
-
import type { Rune } from "./Rune.ts";
|
|
4
|
-
import type { Strand } from "./Strand.ts";
|
|
5
|
-
import type { Tool } from "./Tool.ts";
|
|
6
|
-
export interface Config<Y extends Rune<any> = Rune<any>, T = any> {
|
|
7
|
-
handler?: ((this: Strand<Y, T>, event: Rune.E<Y>) => void) | undefined;
|
|
8
|
-
models?: AdapterRegistry | undefined;
|
|
9
|
-
messages?: Array<Message>;
|
|
10
|
-
tools?: Set<Tool> | undefined;
|
|
11
|
-
signal?: AbortSignal | undefined;
|
|
12
|
-
}
|
package/dist/Config.js
DELETED
package/dist/Config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Config.js","sourceRoot":"","sources":["../Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA"}
|
package/dist/Definition.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Rune } from "./Rune.ts";
|
|
2
|
-
export type RuneIterator<Y extends Rune<any> = Rune<any>, T = any> = Iterator<Y, T> | AsyncIterator<Y, T>;
|
|
3
|
-
export type RuneIterable<Y extends Rune<any> = Rune<any>, T = any> = Iterable<Y, T> | AsyncIterable<Y, T>;
|
|
4
|
-
export type Definition<Y extends Rune<any> = Rune<any>, T = any> = RuneIterable<Y, T> | (() => RuneIterable<Y, T>);
|
|
5
|
-
export declare namespace Definition {
|
|
6
|
-
/** Extracts the Rune type from a Definition. */
|
|
7
|
-
type Y<X extends Definition> = X extends RuneIterable<infer Y> ? Y : X extends () => RuneIterable<infer Y> ? Y : X extends RuneIterator<infer Y> ? Y : never;
|
|
8
|
-
/** Extracts the result type from a Definition. */
|
|
9
|
-
type T<X extends Definition> = X extends RuneIterable<Rune<any>, infer T> ? T : X extends () => RuneIterable<Rune<any>, infer T> ? T : X extends RuneIterator<Rune<any>, infer T> ? T : never;
|
|
10
|
-
/** Extracts the event type from a Definition. */
|
|
11
|
-
type E<X extends Definition> = Rune.E<Y<X>>;
|
|
12
|
-
/**
|
|
13
|
-
* Converts a Definition into a RuneIterator.
|
|
14
|
-
*
|
|
15
|
-
* This function handles all the different forms a Definition can take:
|
|
16
|
-
* - Synchronous iterables
|
|
17
|
-
* - Asynchronous iterables
|
|
18
|
-
* - Factory functions returning iterables
|
|
19
|
-
*
|
|
20
|
-
* @param definition The definition to unwrap.
|
|
21
|
-
* @returns A RuneIterator ready for consumption.
|
|
22
|
-
*/
|
|
23
|
-
function unwrap<Y extends Rune<any>, T>(definition: Definition<Y, T>): RuneIterator<Y, T>;
|
|
24
|
-
}
|