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.
Files changed (218) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/Context.ts +8 -47
  3. package/L.ts +4 -0
  4. package/assistant.ts +52 -0
  5. package/dist/Context.d.ts +13 -30
  6. package/dist/Context.js +9 -22
  7. package/dist/Context.js.map +1 -1
  8. package/dist/L.d.ts +4 -0
  9. package/dist/L.js +5 -0
  10. package/dist/L.js.map +1 -0
  11. package/dist/assistant.d.ts +9 -0
  12. package/dist/assistant.js +44 -0
  13. package/dist/assistant.js.map +1 -0
  14. package/dist/index.d.ts +2 -14
  15. package/dist/index.js +2 -14
  16. package/dist/index.js.map +1 -1
  17. package/dist/messages.d.ts +4 -0
  18. package/dist/messages.js +5 -0
  19. package/dist/messages.js.map +1 -0
  20. package/dist/set.d.ts +3 -0
  21. package/dist/set.js +11 -0
  22. package/dist/set.js.map +1 -0
  23. package/dist/strand.d.ts +15 -0
  24. package/dist/strand.js +19 -0
  25. package/dist/strand.js.map +1 -0
  26. package/dist/todo.test.js +3 -0
  27. package/dist/todo.test.js.map +1 -0
  28. package/dist/tsconfig.tsbuildinfo +1 -1
  29. package/dist/user.d.ts +6 -0
  30. package/dist/user.js +16 -0
  31. package/dist/user.js.map +1 -0
  32. package/dist/util/JSONValue.d.ts +0 -3
  33. package/dist/util/JSONValue.js +1 -31
  34. package/dist/util/JSONValue.js.map +1 -1
  35. package/index.ts +2 -14
  36. package/messages.ts +6 -0
  37. package/package.json +4 -3
  38. package/set.ts +11 -0
  39. package/strand.ts +38 -0
  40. package/todo.test.ts +3 -0
  41. package/user.ts +22 -0
  42. package/util/JSONValue.ts +0 -30
  43. package/Adapter.ts +0 -27
  44. package/AdapterRegistry.ts +0 -78
  45. package/Config.ts +0 -13
  46. package/Definition.ts +0 -48
  47. package/EventBase.ts +0 -23
  48. package/Handler.ts +0 -4
  49. package/L/L.ts +0 -24
  50. package/L/all.ts +0 -39
  51. package/L/assistant.ts +0 -28
  52. package/L/catch.ts +0 -38
  53. package/L/continuation.ts +0 -14
  54. package/L/emit.ts +0 -16
  55. package/L/focus.ts +0 -17
  56. package/L/infer.ts +0 -34
  57. package/L/message.ts +0 -16
  58. package/L/reflect.ts +0 -13
  59. package/L/run.ts +0 -29
  60. package/L/schema/_schema_common.ts +0 -30
  61. package/L/schema/anyOf.ts +0 -10
  62. package/L/schema/array.ts +0 -13
  63. package/L/schema/boolean.ts +0 -8
  64. package/L/schema/const.ts +0 -18
  65. package/L/schema/enum.ts +0 -18
  66. package/L/schema/integer.ts +0 -6
  67. package/L/schema/null.ts +0 -8
  68. package/L/schema/number.ts +0 -8
  69. package/L/schema/object.ts +0 -21
  70. package/L/schema/string.ts +0 -11
  71. package/L/strand.ts +0 -22
  72. package/L/stream.ts +0 -16
  73. package/L/system.ts +0 -19
  74. package/L/user.ts +0 -19
  75. package/LEvent.ts +0 -61
  76. package/LiminalAssertionError.ts +0 -19
  77. package/Message.ts +0 -16
  78. package/Rune.test.ts +0 -5
  79. package/Rune.ts +0 -60
  80. package/Schema.ts +0 -185
  81. package/Strand.ts +0 -284
  82. package/Tool.ts +0 -26
  83. package/TypeAdapter.ts +0 -3
  84. package/dist/Adapter.d.ts +0 -18
  85. package/dist/Adapter.js +0 -13
  86. package/dist/Adapter.js.map +0 -1
  87. package/dist/AdapterRegistry.d.ts +0 -27
  88. package/dist/AdapterRegistry.js +0 -62
  89. package/dist/AdapterRegistry.js.map +0 -1
  90. package/dist/Config.d.ts +0 -12
  91. package/dist/Config.js +0 -2
  92. package/dist/Config.js.map +0 -1
  93. package/dist/Definition.d.ts +0 -24
  94. package/dist/Definition.js +0 -29
  95. package/dist/Definition.js.map +0 -1
  96. package/dist/EventBase.d.ts +0 -11
  97. package/dist/EventBase.js +0 -16
  98. package/dist/EventBase.js.map +0 -1
  99. package/dist/Handler.d.ts +0 -3
  100. package/dist/Handler.js +0 -2
  101. package/dist/Handler.js.map +0 -1
  102. package/dist/L/L.d.ts +0 -24
  103. package/dist/L/L.js +0 -25
  104. package/dist/L/L.js.map +0 -1
  105. package/dist/L/all.d.ts +0 -14
  106. package/dist/L/all.js +0 -20
  107. package/dist/L/all.js.map +0 -1
  108. package/dist/L/assistant.d.ts +0 -11
  109. package/dist/L/assistant.js +0 -15
  110. package/dist/L/assistant.js.map +0 -1
  111. package/dist/L/catch.d.ts +0 -16
  112. package/dist/L/catch.js +0 -25
  113. package/dist/L/catch.js.map +0 -1
  114. package/dist/L/continuation.d.ts +0 -4
  115. package/dist/L/continuation.js +0 -13
  116. package/dist/L/continuation.js.map +0 -1
  117. package/dist/L/emit.d.ts +0 -7
  118. package/dist/L/emit.js +0 -15
  119. package/dist/L/emit.js.map +0 -1
  120. package/dist/L/focus.d.ts +0 -8
  121. package/dist/L/focus.js +0 -14
  122. package/dist/L/focus.js.map +0 -1
  123. package/dist/L/infer.d.ts +0 -8
  124. package/dist/L/infer.js +0 -30
  125. package/dist/L/infer.js.map +0 -1
  126. package/dist/L/message.d.ts +0 -8
  127. package/dist/L/message.js +0 -14
  128. package/dist/L/message.js.map +0 -1
  129. package/dist/L/reflect.d.ts +0 -5
  130. package/dist/L/reflect.js +0 -11
  131. package/dist/L/reflect.js.map +0 -1
  132. package/dist/L/run.d.ts +0 -14
  133. package/dist/L/run.js +0 -16
  134. package/dist/L/run.js.map +0 -1
  135. package/dist/L/schema/_schema_common.d.ts +0 -6
  136. package/dist/L/schema/_schema_common.js +0 -20
  137. package/dist/L/schema/_schema_common.js.map +0 -1
  138. package/dist/L/schema/anyOf.d.ts +0 -5
  139. package/dist/L/schema/anyOf.js +0 -5
  140. package/dist/L/schema/anyOf.js.map +0 -1
  141. package/dist/L/schema/array.d.ts +0 -5
  142. package/dist/L/schema/array.js +0 -8
  143. package/dist/L/schema/array.js.map +0 -1
  144. package/dist/L/schema/boolean.d.ts +0 -6
  145. package/dist/L/schema/boolean.js +0 -4
  146. package/dist/L/schema/boolean.js.map +0 -1
  147. package/dist/L/schema/const.d.ts +0 -8
  148. package/dist/L/schema/const.js +0 -10
  149. package/dist/L/schema/const.js.map +0 -1
  150. package/dist/L/schema/enum.d.ts +0 -8
  151. package/dist/L/schema/enum.js +0 -10
  152. package/dist/L/schema/enum.js.map +0 -1
  153. package/dist/L/schema/integer.d.ts +0 -5
  154. package/dist/L/schema/integer.js +0 -3
  155. package/dist/L/schema/integer.js.map +0 -1
  156. package/dist/L/schema/null.d.ts +0 -6
  157. package/dist/L/schema/null.js +0 -4
  158. package/dist/L/schema/null.js.map +0 -1
  159. package/dist/L/schema/number.d.ts +0 -6
  160. package/dist/L/schema/number.js +0 -4
  161. package/dist/L/schema/number.js.map +0 -1
  162. package/dist/L/schema/object.d.ts +0 -9
  163. package/dist/L/schema/object.js +0 -12
  164. package/dist/L/schema/object.js.map +0 -1
  165. package/dist/L/schema/string.d.ts +0 -8
  166. package/dist/L/schema/string.js +0 -4
  167. package/dist/L/schema/string.js.map +0 -1
  168. package/dist/L/strand.d.ts +0 -9
  169. package/dist/L/strand.js +0 -16
  170. package/dist/L/strand.js.map +0 -1
  171. package/dist/L/stream.d.ts +0 -4
  172. package/dist/L/stream.js +0 -15
  173. package/dist/L/stream.js.map +0 -1
  174. package/dist/L/system.d.ts +0 -4
  175. package/dist/L/system.js +0 -9
  176. package/dist/L/system.js.map +0 -1
  177. package/dist/L/user.d.ts +0 -4
  178. package/dist/L/user.js +0 -9
  179. package/dist/L/user.js.map +0 -1
  180. package/dist/LEvent.d.ts +0 -68
  181. package/dist/LEvent.js +0 -50
  182. package/dist/LEvent.js.map +0 -1
  183. package/dist/LiminalAssertionError.d.ts +0 -8
  184. package/dist/LiminalAssertionError.js +0 -20
  185. package/dist/LiminalAssertionError.js.map +0 -1
  186. package/dist/Message.d.ts +0 -14
  187. package/dist/Message.js +0 -2
  188. package/dist/Message.js.map +0 -1
  189. package/dist/Rune.d.ts +0 -46
  190. package/dist/Rune.js +0 -11
  191. package/dist/Rune.js.map +0 -1
  192. package/dist/Rune.test.js +0 -5
  193. package/dist/Rune.test.js.map +0 -1
  194. package/dist/Schema.d.ts +0 -46
  195. package/dist/Schema.js +0 -130
  196. package/dist/Schema.js.map +0 -1
  197. package/dist/Strand.d.ts +0 -81
  198. package/dist/Strand.js +0 -200
  199. package/dist/Strand.js.map +0 -1
  200. package/dist/Tool.d.ts +0 -10
  201. package/dist/Tool.js +0 -19
  202. package/dist/Tool.js.map +0 -1
  203. package/dist/TypeAdapter.d.ts +0 -1
  204. package/dist/TypeAdapter.js +0 -3
  205. package/dist/TypeAdapter.js.map +0 -1
  206. package/dist/errors.d.ts +0 -9
  207. package/dist/errors.js +0 -11
  208. package/dist/errors.js.map +0 -1
  209. package/dist/util/EnsureNarrow.d.ts +0 -1
  210. package/dist/util/EnsureNarrow.js +0 -2
  211. package/dist/util/EnsureNarrow.js.map +0 -1
  212. package/dist/util/attachCustomInspect.d.ts +0 -1
  213. package/dist/util/attachCustomInspect.js +0 -11
  214. package/dist/util/attachCustomInspect.js.map +0 -1
  215. package/errors.ts +0 -12
  216. package/util/EnsureNarrow.ts +0 -1
  217. package/util/attachCustomInspect.ts +0 -14
  218. /package/dist/{Rune.test.d.ts → todo.test.d.ts} +0 -0
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
@@ -1,3 +0,0 @@
1
- import { LiminalAssertionError } from "./LiminalAssertionError.ts"
2
- import { Schema } from "./Schema.ts"
3
- import type { JSONValueObject } from "./util/JSONValue.ts"
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
@@ -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 `Adapter`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 adapter */
10
- peek(): Adapter | undefined;
11
- /** Ensure */
12
- ensure(): Adapter;
13
- /**
14
- * Registers a new adapter and returns the created node
15
- * @param value The adapter to register
16
- */
17
- register(value: Adapter): ModelRegistryNode;
18
- /** Remove a adapter 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
- }
@@ -1,62 +0,0 @@
1
- import { LiminalAssertionError } from "./LiminalAssertionError.js";
2
- /**
3
- * An intrusive doubly-linked list for storing `Adapter`s.
4
- * Provides efficient insertion, removal, and lookups.
5
- */
6
- export class AdapterRegistry {
7
- /** Returns the most recently registered adapter */
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 adapter and returns the created node
18
- * @param value The adapter 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 adapter 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,mDAAmD;IACnD,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,0CAA0C;IAC1C,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
@@ -1,2 +0,0 @@
1
- import { AdapterRegistry } from "./AdapterRegistry.js";
2
- //# sourceMappingURL=Config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Config.js","sourceRoot":"","sources":["../Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA"}
@@ -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
- }
@@ -1,29 +0,0 @@
1
- export var Definition;
2
- (function (Definition) {
3
- /**
4
- * Converts a Definition into a RuneIterator.
5
- *
6
- * This function handles all the different forms a Definition can take:
7
- * - Synchronous iterables
8
- * - Asynchronous iterables
9
- * - Factory functions returning iterables
10
- *
11
- * @param definition The definition to unwrap.
12
- * @returns A RuneIterator ready for consumption.
13
- */
14
- function unwrap(definition) {
15
- if (Symbol.iterator in definition) {
16
- return definition[Symbol.iterator]();
17
- }
18
- else if (Symbol.asyncIterator in definition) {
19
- return definition[Symbol.asyncIterator]();
20
- }
21
- const iterable = definition();
22
- if (Symbol.iterator in iterable) {
23
- return iterable[Symbol.iterator]();
24
- }
25
- return iterable[Symbol.asyncIterator]();
26
- }
27
- Definition.unwrap = unwrap;
28
- })(Definition || (Definition = {}));
29
- //# sourceMappingURL=Definition.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Definition.js","sourceRoot":"","sources":["../Definition.ts"],"names":[],"mappings":"AAQA,MAAM,KAAW,UAAU,CAuC1B;AAvCD,WAAiB,UAAU;IAgBzB;;;;;;;;;;OAUG;IACH,SAAgB,MAAM,CAAyB,UAA4B;QACzE,IAAI,MAAM,CAAC,QAAQ,IAAI,UAAU,EAAE,CAAC;YAClC,OAAO,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;QACtC,CAAC;aAAM,IAAI,MAAM,CAAC,aAAa,IAAI,UAAU,EAAE,CAAC;YAC9C,OAAO,UAAU,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAA;QAC3C,CAAC;QACD,MAAM,QAAQ,GAAG,UAAU,EAAE,CAAA;QAC7B,IAAI,MAAM,CAAC,QAAQ,IAAI,QAAQ,EAAE,CAAC;YAChC,OAAO,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;QACpC,CAAC;QACD,OAAO,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAA;IACzC,CAAC;IAXe,iBAAM,SAWrB,CAAA;AACH,CAAC,EAvCgB,UAAU,KAAV,UAAU,QAuC1B"}
@@ -1,11 +0,0 @@
1
- export interface EventBase<B extends symbol = symbol, K extends string = string> {
2
- readonly brand: B;
3
- readonly type: K;
4
- }
5
- export declare function EventBase<B extends symbol, K extends string>(brand: B, type: K): {
6
- new (): {
7
- readonly brand: B;
8
- readonly type: K;
9
- };
10
- is<T>(this: new (...args: any) => T, value: unknown): value is T;
11
- };
package/dist/EventBase.js DELETED
@@ -1,16 +0,0 @@
1
- import { attachCustomInspect } from "./util/attachCustomInspect.js";
2
- export function EventBase(brand, type) {
3
- return class {
4
- static is(value) {
5
- return typeof value === "object" && value !== null
6
- && "brand" in value && value.brand === brand
7
- && "type" in value && value.type === type;
8
- }
9
- brand = brand;
10
- type = type;
11
- static {
12
- attachCustomInspect(this, ({ brand: _0, type: _1, ...rest }) => rest);
13
- }
14
- };
15
- }
16
- //# sourceMappingURL=EventBase.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EventBase.js","sourceRoot":"","sources":["../EventBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAOnE,MAAM,UAAU,SAAS,CAAqC,KAAQ,EAAE,IAAO;IAC7E,OAAO;QACL,MAAM,CAAC,EAAE,CAAkC,KAAc;YACvD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;mBAC7C,OAAO,IAAI,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,KAAK;mBACzC,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAA;QAC7C,CAAC;QAEQ,KAAK,GAAG,KAAK,CAAA;QACb,IAAI,GAAG,IAAI,CAAA;QAEpB;YACE,mBAAmB,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAA;QACvE,CAAC;KACF,CAAA;AACH,CAAC"}
package/dist/Handler.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { Rune } from "./Rune.ts";
2
- import type { Strand } from "./Strand.ts";
3
- export type Handler<Y extends Rune<any> = Rune<any>> = (this: Strand, event: Rune.E<Y>) => void;
package/dist/Handler.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Handler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Handler.js","sourceRoot":"","sources":["../Handler.ts"],"names":[],"mappings":""}
package/dist/L/L.d.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/dist/L/L.js DELETED
@@ -1,25 +0,0 @@
1
- export * from "./all.js";
2
- export * from "./assistant.js";
3
- export * from "./catch.js";
4
- export * from "./continuation.js";
5
- export * from "./emit.js";
6
- export * from "./focus.js";
7
- export * from "./infer.js";
8
- export * from "./message.js";
9
- export * from "./reflect.js";
10
- export * from "./run.js";
11
- export * from "./schema/anyOf.js";
12
- export * from "./schema/array.js";
13
- export * from "./schema/boolean.js";
14
- export * from "./schema/const.js";
15
- export * from "./schema/enum.js";
16
- export * from "./schema/integer.js";
17
- export * from "./schema/null.js";
18
- export * from "./schema/number";
19
- export * from "./schema/object.js";
20
- export * from "./schema/string.js";
21
- export * from "./strand.js";
22
- export * from "./stream.js";
23
- export * from "./system.js";
24
- export * from "./user.js";
25
- //# sourceMappingURL=L.js.map
package/dist/L/L.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"L.js","sourceRoot":"","sources":["../../L/L.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
package/dist/L/all.d.ts DELETED
@@ -1,14 +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
- /**
6
- * Runs multiple definitions in parallel and collects their results.
7
- * Can be used with an array or object of definitions.
8
- */
9
- export declare function all<A extends Array<Definition>>(definitions: A, context?: Context): Generator<Rune<LEvent> | Definition.Y<A[number]>, {
10
- [I in keyof A]: Definition.T<A[I]>;
11
- }>;
12
- export declare function all<A extends Record<keyof any, Definition>>(definitions: A, context?: Context): Generator<Rune<LEvent> | Definition.Y<A[keyof A]>, {
13
- [K in keyof A]: Definition.T<A[K]>;
14
- }>;
package/dist/L/all.js DELETED
@@ -1,20 +0,0 @@
1
- import { Definition } from "../Definition.js";
2
- import { Strand } from "../Strand.js";
3
- import { continuation } from "./continuation.js";
4
- import { reflect } from "./reflect.js";
5
- export function* all(definitions, context) {
6
- const parent = yield* reflect;
7
- const strands = [];
8
- for (const definition of Array.isArray(definitions) ? definitions : Object.values(definitions)) {
9
- strands.push(new Strand(definition, {
10
- parent,
11
- context: context?.clone() ?? parent.context.clone(),
12
- }));
13
- }
14
- const results = yield* continuation("all", () => Promise.all(strands));
15
- if (Array.isArray(strands))
16
- return results;
17
- const keys = Object.keys(strands);
18
- return Object.fromEntries(results.map((result, i) => [keys[i], result]));
19
- }
20
- //# sourceMappingURL=all.js.map