liminal 0.16.0 → 0.17.1

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 (275) hide show
  1. package/Accumulator.ts +97 -0
  2. package/Actor.ts +118 -0
  3. package/Audition.ts +105 -0
  4. package/CHANGELOG.md +2 -206
  5. package/Client.ts +560 -0
  6. package/ClientHandle.ts +39 -0
  7. package/F.ts +18 -0
  8. package/Method.ts +39 -0
  9. package/Protocol.ts +142 -0
  10. package/Send.ts +8 -0
  11. package/_constants.ts +1 -0
  12. package/_types.ts +27 -0
  13. package/_util/Mutex.ts +13 -0
  14. package/_util/phantom.ts +1 -0
  15. package/dist/Accumulator.d.ts +22 -0
  16. package/dist/Accumulator.js +33 -0
  17. package/dist/Accumulator.js.map +1 -0
  18. package/dist/Actor.d.ts +30 -0
  19. package/dist/Actor.js +31 -0
  20. package/dist/Actor.js.map +1 -0
  21. package/dist/Audition.d.ts +18 -0
  22. package/dist/Audition.js +27 -0
  23. package/dist/Audition.js.map +1 -0
  24. package/dist/Client.d.ts +65 -0
  25. package/dist/Client.js +248 -0
  26. package/dist/Client.js.map +1 -0
  27. package/dist/ClientHandle.d.ts +18 -0
  28. package/dist/ClientHandle.js +10 -0
  29. package/dist/ClientHandle.js.map +1 -0
  30. package/dist/F.d.ts +13 -0
  31. package/dist/F.js +4 -0
  32. package/dist/F.js.map +1 -0
  33. package/dist/Method.d.ts +23 -0
  34. package/dist/Method.js +4 -0
  35. package/dist/Method.js.map +1 -0
  36. package/dist/Protocol.d.ts +96 -0
  37. package/dist/Protocol.js +13 -0
  38. package/dist/Protocol.js.map +1 -0
  39. package/dist/Send.d.ts +3 -0
  40. package/dist/Send.js +2 -0
  41. package/dist/Send.js.map +1 -0
  42. package/dist/_constants.d.ts +1 -0
  43. package/dist/_constants.js +2 -0
  44. package/dist/_constants.js.map +1 -0
  45. package/dist/_types.d.ts +22 -0
  46. package/dist/_types.js +2 -0
  47. package/dist/_types.js.map +1 -0
  48. package/dist/_util/Mutex.d.ts +7 -0
  49. package/dist/_util/Mutex.js +9 -0
  50. package/dist/_util/Mutex.js.map +1 -0
  51. package/dist/_util/phantom.d.ts +3 -0
  52. package/dist/_util/phantom.js +2 -0
  53. package/dist/_util/phantom.js.map +1 -0
  54. package/dist/errors.d.ts +20 -0
  55. package/dist/errors.js +13 -0
  56. package/dist/errors.js.map +1 -0
  57. package/dist/experimental/BranchLive.d.ts +3 -0
  58. package/dist/experimental/BranchLive.js +5 -0
  59. package/dist/experimental/BranchLive.js.map +1 -0
  60. package/dist/experimental/L/L.d.ts +11 -0
  61. package/dist/experimental/L/L.js +12 -0
  62. package/dist/experimental/L/L.js.map +1 -0
  63. package/dist/experimental/L/append.d.ts +3 -0
  64. package/dist/experimental/L/append.js +4 -0
  65. package/dist/experimental/L/append.js.map +1 -0
  66. package/dist/experimental/L/assistant.d.ts +3 -0
  67. package/dist/experimental/L/assistant.js +13 -0
  68. package/dist/experimental/L/assistant.js.map +1 -0
  69. package/dist/experimental/L/assistantSchema.d.ts +3 -0
  70. package/dist/experimental/L/assistantSchema.js +13 -0
  71. package/dist/experimental/L/assistantSchema.js.map +1 -0
  72. package/dist/experimental/L/assistantStream.d.ts +3 -0
  73. package/dist/experimental/L/assistantStream.js +5 -0
  74. package/dist/experimental/L/assistantStream.js.map +1 -0
  75. package/dist/experimental/L/branch.d.ts +2 -0
  76. package/dist/experimental/L/branch.js +4 -0
  77. package/dist/experimental/L/branch.js.map +1 -0
  78. package/dist/experimental/L/clear.d.ts +3 -0
  79. package/dist/experimental/L/clear.js +7 -0
  80. package/dist/experimental/L/clear.js.map +1 -0
  81. package/dist/experimental/L/history.d.ts +3 -0
  82. package/dist/experimental/L/history.js +4 -0
  83. package/dist/experimental/L/history.js.map +1 -0
  84. package/dist/experimental/L/init.d.ts +3 -0
  85. package/dist/experimental/L/init.js +4 -0
  86. package/dist/experimental/L/init.js.map +1 -0
  87. package/dist/experimental/L/matrix.d.ts +10 -0
  88. package/dist/experimental/L/matrix.js +6 -0
  89. package/dist/experimental/L/matrix.js.map +1 -0
  90. package/dist/experimental/L/system.d.ts +1 -0
  91. package/dist/experimental/L/system.js +4 -0
  92. package/dist/experimental/L/system.js.map +1 -0
  93. package/dist/experimental/L/user.d.ts +1 -0
  94. package/dist/experimental/L/user.js +6 -0
  95. package/dist/experimental/L/user.js.map +1 -0
  96. package/dist/experimental/Loader.d.ts +16 -0
  97. package/dist/experimental/Loader.js +20 -0
  98. package/dist/experimental/Loader.js.map +1 -0
  99. package/dist/experimental/TaggedTemplateFunction.d.ts +11 -0
  100. package/dist/experimental/TaggedTemplateFunction.js +14 -0
  101. package/dist/experimental/TaggedTemplateFunction.js.map +1 -0
  102. package/dist/experimental/Template.d.ts +32 -0
  103. package/dist/experimental/Template.js +58 -0
  104. package/dist/experimental/Template.js.map +1 -0
  105. package/dist/experimental/index.d.ts +4 -0
  106. package/dist/experimental/index.js +5 -0
  107. package/dist/experimental/index.js.map +1 -0
  108. package/dist/index.d.ts +9 -5
  109. package/dist/index.js +9 -5
  110. package/dist/index.js.map +1 -1
  111. package/dist/tsconfig.tsbuildinfo +1 -1
  112. package/errors.ts +14 -0
  113. package/experimental/BranchLive.ts +6 -0
  114. package/experimental/L/L.ts +11 -0
  115. package/experimental/L/append.ts +12 -0
  116. package/experimental/L/assistant.ts +16 -0
  117. package/experimental/L/assistantSchema.ts +18 -0
  118. package/experimental/L/assistantStream.ts +9 -0
  119. package/experimental/L/branch.ts +5 -0
  120. package/experimental/L/clear.ts +7 -0
  121. package/experimental/L/history.ts +4 -0
  122. package/experimental/L/init.ts +4 -0
  123. package/experimental/L/matrix.ts +26 -0
  124. package/experimental/L/system.ts +5 -0
  125. package/experimental/L/user.ts +10 -0
  126. package/experimental/Loader.ts +35 -0
  127. package/experimental/TaggedTemplateFunction.ts +44 -0
  128. package/experimental/Template.ts +93 -0
  129. package/experimental/index.ts +4 -0
  130. package/index.ts +9 -5
  131. package/package.json +26 -23
  132. package/tsconfig.json +9 -0
  133. package/Envelope.ts +0 -48
  134. package/L/L.ts +0 -21
  135. package/L/Self.ts +0 -5
  136. package/L/append.ts +0 -14
  137. package/L/assistant.ts +0 -30
  138. package/L/assistantSchema.ts +0 -61
  139. package/L/assistantStream.ts +0 -22
  140. package/L/branch.ts +0 -33
  141. package/L/clear.ts +0 -14
  142. package/L/disable.ts +0 -13
  143. package/L/enable.ts +0 -24
  144. package/L/events.ts +0 -11
  145. package/L/fqn.ts +0 -9
  146. package/L/handle.ts +0 -26
  147. package/L/messages.ts +0 -10
  148. package/L/raw.ts +0 -30
  149. package/L/sequence.ts +0 -9
  150. package/L/system.ts +0 -14
  151. package/L/thread.ts +0 -28
  152. package/L/to.ts +0 -4
  153. package/L/toolkit.ts +0 -14
  154. package/L/user.test.ts +0 -30
  155. package/L/user.ts +0 -22
  156. package/L/userJson.ts +0 -14
  157. package/LEvent.ts +0 -23
  158. package/LPretty.ts +0 -41
  159. package/Thread.ts +0 -69
  160. package/dist/Envelope.d.ts +0 -15
  161. package/dist/Envelope.js +0 -30
  162. package/dist/Envelope.js.map +0 -1
  163. package/dist/L/L.d.ts +0 -21
  164. package/dist/L/L.js +0 -22
  165. package/dist/L/L.js.map +0 -1
  166. package/dist/L/Self.d.ts +0 -3
  167. package/dist/L/Self.js +0 -4
  168. package/dist/L/Self.js.map +0 -1
  169. package/dist/L/append.d.ts +0 -5
  170. package/dist/L/append.js +0 -10
  171. package/dist/L/append.js.map +0 -1
  172. package/dist/L/assistant.d.ts +0 -6
  173. package/dist/L/assistant.js +0 -26
  174. package/dist/L/assistant.js.map +0 -1
  175. package/dist/L/assistantSchema.d.ts +0 -13
  176. package/dist/L/assistantSchema.js +0 -44
  177. package/dist/L/assistantSchema.js.map +0 -1
  178. package/dist/L/assistantStream.d.ts +0 -7
  179. package/dist/L/assistantStream.js +0 -17
  180. package/dist/L/assistantStream.js.map +0 -1
  181. package/dist/L/branch.d.ts +0 -6
  182. package/dist/L/branch.js +0 -22
  183. package/dist/L/branch.js.map +0 -1
  184. package/dist/L/clear.d.ts +0 -5
  185. package/dist/L/clear.js +0 -12
  186. package/dist/L/clear.js.map +0 -1
  187. package/dist/L/disable.d.ts +0 -4
  188. package/dist/L/disable.js +0 -10
  189. package/dist/L/disable.js.map +0 -1
  190. package/dist/L/enable.d.ts +0 -5
  191. package/dist/L/enable.js +0 -13
  192. package/dist/L/enable.js.map +0 -1
  193. package/dist/L/events.d.ts +0 -5
  194. package/dist/L/events.js +0 -6
  195. package/dist/L/events.js.map +0 -1
  196. package/dist/L/fqn.d.ts +0 -3
  197. package/dist/L/fqn.js +0 -8
  198. package/dist/L/fqn.js.map +0 -1
  199. package/dist/L/handle.d.ts +0 -7
  200. package/dist/L/handle.js +0 -14
  201. package/dist/L/handle.js.map +0 -1
  202. package/dist/L/messages.d.ts +0 -5
  203. package/dist/L/messages.js +0 -5
  204. package/dist/L/messages.js.map +0 -1
  205. package/dist/L/raw.d.ts +0 -3
  206. package/dist/L/raw.js +0 -18
  207. package/dist/L/raw.js.map +0 -1
  208. package/dist/L/sequence.d.ts +0 -2
  209. package/dist/L/sequence.js +0 -5
  210. package/dist/L/sequence.js.map +0 -1
  211. package/dist/L/system.d.ts +0 -5
  212. package/dist/L/system.js +0 -12
  213. package/dist/L/system.js.map +0 -1
  214. package/dist/L/thread.d.ts +0 -6
  215. package/dist/L/thread.js +0 -17
  216. package/dist/L/thread.js.map +0 -1
  217. package/dist/L/to.d.ts +0 -3
  218. package/dist/L/to.js +0 -3
  219. package/dist/L/to.js.map +0 -1
  220. package/dist/L/toolkit.d.ts +0 -4
  221. package/dist/L/toolkit.js +0 -9
  222. package/dist/L/toolkit.js.map +0 -1
  223. package/dist/L/user.d.ts +0 -4
  224. package/dist/L/user.js +0 -13
  225. package/dist/L/user.js.map +0 -1
  226. package/dist/L/user.test.d.ts +0 -1
  227. package/dist/L/user.test.js.map +0 -1
  228. package/dist/L/userJson.d.ts +0 -6
  229. package/dist/L/userJson.js +0 -9
  230. package/dist/L/userJson.js.map +0 -1
  231. package/dist/LEvent.d.ts +0 -26
  232. package/dist/LEvent.js +0 -16
  233. package/dist/LEvent.js.map +0 -1
  234. package/dist/LPretty.d.ts +0 -4
  235. package/dist/LPretty.js +0 -37
  236. package/dist/LPretty.js.map +0 -1
  237. package/dist/Thread.d.ts +0 -55
  238. package/dist/Thread.js +0 -38
  239. package/dist/Thread.js.map +0 -1
  240. package/dist/patterns/Debate.d.ts +0 -1
  241. package/dist/patterns/Debate.js +0 -3
  242. package/dist/patterns/Debate.js.map +0 -1
  243. package/dist/patterns/Model.d.ts +0 -6
  244. package/dist/patterns/Model.js +0 -14
  245. package/dist/patterns/Model.js.map +0 -1
  246. package/dist/patterns/Route.d.ts +0 -3
  247. package/dist/patterns/Route.js +0 -14
  248. package/dist/patterns/Route.js.map +0 -1
  249. package/dist/util/JsonValue.d.ts +0 -8
  250. package/dist/util/JsonValue.js +0 -109
  251. package/dist/util/JsonValue.js.map +0 -1
  252. package/dist/util/NeverTool.d.ts +0 -3
  253. package/dist/util/NeverTool.js +0 -3
  254. package/dist/util/NeverTool.js.map +0 -1
  255. package/dist/util/Sequencer.d.ts +0 -4
  256. package/dist/util/Sequencer.js +0 -2
  257. package/dist/util/Sequencer.js.map +0 -1
  258. package/dist/util/Taggable.d.ts +0 -5
  259. package/dist/util/Taggable.js +0 -2
  260. package/dist/util/Taggable.js.map +0 -1
  261. package/dist/util/normalizeRaw.d.ts +0 -4
  262. package/dist/util/normalizeRaw.js +0 -75
  263. package/dist/util/normalizeRaw.js.map +0 -1
  264. package/dist/util/prefix.d.ts +0 -1
  265. package/dist/util/prefix.js +0 -2
  266. package/dist/util/prefix.js.map +0 -1
  267. package/patterns/Debate.ts +0 -2
  268. package/patterns/Model.ts +0 -29
  269. package/patterns/Route.ts +0 -21
  270. package/util/JsonValue.ts +0 -144
  271. package/util/NeverTool.ts +0 -10
  272. package/util/Sequencer.ts +0 -13
  273. package/util/Taggable.ts +0 -14
  274. package/util/normalizeRaw.ts +0 -93
  275. package/util/prefix.ts +0 -1
package/L/branch.ts DELETED
@@ -1,33 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import { flow } from "effect/Function"
3
- import * as Option from "effect/Option"
4
- import * as PubSub from "effect/PubSub"
5
- import type { LEvent } from "../LEvent.ts"
6
- import { Thread, ThreadState } from "../Thread.ts"
7
- import type { Sequencer } from "../util/Sequencer.ts"
8
- import { Self } from "./Self.ts"
9
- import { sequence } from "./sequence.ts"
10
-
11
- export interface branch extends Sequencer<never, Thread>, Effect.Effect<Thread, never, Thread> {}
12
-
13
- const branch_ = Effect.gen(function*() {
14
- const parent = yield* Self
15
- return Thread({
16
- parent: Option.some(parent),
17
- events: yield* PubSub.unbounded<LEvent>(),
18
- state: ThreadState.make({
19
- fqn: parent.state.fqn,
20
- system: parent.state.system,
21
- messages: [...parent.state.messages ?? []],
22
- }),
23
- tools: parent.tools.pipe(Option.map((v) => new Set(v))),
24
- })
25
- })
26
-
27
- export const branch: branch = Object.assign(
28
- flow(
29
- sequence,
30
- Effect.provideServiceEffect(Self, branch_),
31
- ),
32
- branch_,
33
- )
package/L/clear.ts DELETED
@@ -1,14 +0,0 @@
1
- import type { Message } from "@effect/ai/AiInput"
2
- import * as Effect from "effect/Effect"
3
- import { MessagesCleared } from "../LEvent.ts"
4
- import type { Thread } from "../Thread.ts"
5
- import { Self } from "./Self.ts"
6
-
7
- /** Clear the thread of messages. */
8
- export const clear: Effect.Effect<Array<Message>, never, Thread> = Effect.gen(function*() {
9
- const { state, events } = yield* Self
10
- const cleared = state.messages
11
- state.messages = []
12
- yield* events.publish(MessagesCleared.make({ cleared }))
13
- return cleared
14
- })
package/L/disable.ts DELETED
@@ -1,13 +0,0 @@
1
- import * as AiTool from "@effect/ai/AiTool"
2
- import * as Effect from "effect/Effect"
3
- import * as Option from "effect/Option"
4
- import type { Thread } from "../Thread.ts"
5
- import type { NeverTool } from "../util/NeverTool.ts"
6
- import { Self } from "./Self.ts"
7
-
8
- export const disable = (tool: AiTool.Any): Effect.Effect<void, never, Thread> =>
9
- Effect.map(Self, ({ tools }) => {
10
- if (Option.isSome(tools)) {
11
- tools.value.delete(tool as NeverTool)
12
- }
13
- })
package/L/enable.ts DELETED
@@ -1,24 +0,0 @@
1
- import type { AiTool, AnyStructSchema, Handler } from "@effect/ai/AiTool"
2
- import * as Effect from "effect/Effect"
3
- import * as Option from "effect/Option"
4
- import type { Schema } from "effect/Schema"
5
- import type { Thread } from "../Thread.ts"
6
- import type { NeverTool } from "../util/NeverTool.ts"
7
- import { Self } from "./Self.ts"
8
-
9
- export const enable = <
10
- K extends string,
11
- E extends Schema.All,
12
- R,
13
- >(
14
- tool: AiTool<K, AnyStructSchema, Schema.Any, E, R>,
15
- ): Effect.Effect<void, E, Handler<K> | Thread | R> =>
16
- Effect.map(Self, (thread) => {
17
- const tool_: NeverTool = tool as never
18
- Option.match(thread.tools, {
19
- onSome: (value) => value.add(tool_),
20
- onNone: () => {
21
- thread.tools = Option.some(new Set([tool_]))
22
- },
23
- })
24
- })
package/L/events.ts DELETED
@@ -1,11 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import * as Stream from "effect/Stream"
3
- import type { LEvent } from "../LEvent.ts"
4
- import type { Thread } from "../Thread.ts"
5
- import { Self } from "./Self.ts"
6
-
7
- /** A stream of thread events. */
8
- export const events: Stream.Stream<LEvent, never, Thread> = Self.pipe(
9
- Effect.map(({ events }) => Stream.fromPubSub(events)),
10
- Stream.unwrap,
11
- )
package/L/fqn.ts DELETED
@@ -1,9 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import * as Option from "effect/Option"
3
- import { type Thread, ThreadFqn } from "../Thread.ts"
4
- import { Self } from "./Self.ts"
5
-
6
- export const fqn = (id: string): Effect.Effect<void, never, Thread> =>
7
- Effect.map(Self, (thread) => {
8
- thread.state.fqn = Option.some(ThreadFqn.make(id))
9
- })
package/L/handle.ts DELETED
@@ -1,26 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import type { RuntimeFiber } from "effect/Fiber"
3
- import * as Scope from "effect/Scope"
4
- import * as Stream from "effect/Stream"
5
- import type { LEvent } from "../LEvent.ts"
6
- import type { Thread } from "../Thread.ts"
7
- import { Self } from "./Self.ts"
8
-
9
- /** Attach an event handler to process thread events. */
10
- export const listen: <A, E, R>(
11
- f: (event: LEvent) => Effect.Effect<A, E, R>,
12
- ) => Effect.Effect<RuntimeFiber<void, E>, never, Thread | R | Scope.Scope> = Effect.fnUntraced(function*(f) {
13
- const latch = yield* Effect.makeLatch(false)
14
- const { events } = yield* Self
15
- const dequeue = yield* events.subscribe
16
- const fiber = yield* latch.open.pipe(
17
- Effect.zipRight(
18
- Stream.fromQueue(dequeue).pipe(
19
- Stream.runForEach(f),
20
- Effect.fork,
21
- ),
22
- ),
23
- )
24
- yield* latch.await
25
- return fiber
26
- })
package/L/messages.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { Message } from "@effect/ai/AiInput"
2
- import * as Effect from "effect/Effect"
3
- import type { Thread } from "../Thread.ts"
4
- import { Self } from "./Self.ts"
5
-
6
- /** Get a copy of the current list of messages. */
7
- export const messages: Effect.Effect<Array<Message>, never, Thread> = Effect.map(
8
- Self,
9
- ({ state: { messages: [...messages] } }) => messages,
10
- )
package/L/raw.ts DELETED
@@ -1,30 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import { normalizeRaw } from "../util/normalizeRaw.ts"
3
- import type { TaggableArg0 } from "../util/Taggable.ts"
4
-
5
- export const raw: <
6
- A0 extends TaggableArg0 | Effect.Effect<string | undefined, any, any>,
7
- L extends Array<unknown>,
8
- >(
9
- a0: A0,
10
- ...aRest: L
11
- ) => Effect.Effect<
12
- string | (undefined extends A0 ? undefined : never)
13
- > = Effect.fnUntraced(function*(a0, ...aRest) {
14
- const a0_: TaggableArg0 = Effect.isEffect(a0)
15
- ? yield* a0 as Effect.Effect<TaggableArg0>
16
- : a0
17
- if (!a0_) return undefined as never
18
- const aRest_ = yield* Effect.all(
19
- aRest.map((v) =>
20
- Effect.isEffect(v)
21
- ? v
22
- : Effect.succeed(v)
23
- ),
24
- ) as never as Effect.Effect<Array<unknown>>
25
- return typeof a0_ === "string"
26
- ? aRest_.length === 0
27
- ? a0_
28
- : [a0_, ...aRest_].join("")
29
- : normalizeRaw(a0_, aRest_)
30
- })
package/L/sequence.ts DELETED
@@ -1,9 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import type { Sequencer } from "../util/Sequencer.ts"
3
-
4
- export const sequence: Sequencer = (...steps) =>
5
- Effect.all(steps, {
6
- concurrency: 1,
7
- }).pipe(
8
- Effect.map((v: Array<never>) => v.pop()!) as never,
9
- )
package/L/system.ts DELETED
@@ -1,14 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import * as Option from "effect/Option"
3
- import type { Thread } from "../Thread.ts"
4
- import type { Taggable } from "../util/Taggable.ts"
5
- import { raw } from "./raw.ts"
6
- import { Self } from "./Self.ts"
7
-
8
- /** Set the thread's system instruction. */
9
- export const system: Taggable<Option.Option<string>, never, Thread> = Effect.fnUntraced(function*(a0, ...aRest) {
10
- const { state } = yield* Self
11
- const { system } = state
12
- state.system = a0 ? Option.some(yield* raw(a0, ...aRest)) : Option.none()
13
- return system
14
- })
package/L/thread.ts DELETED
@@ -1,28 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import { flow } from "effect/Function"
3
- import * as Option from "effect/Option"
4
- import * as PubSub from "effect/PubSub"
5
- import type { LEvent } from "../LEvent.ts"
6
- import { Thread, ThreadState } from "../Thread.ts"
7
- import type { Sequencer } from "../util/Sequencer.ts"
8
- import { Self } from "./Self.ts"
9
- import { sequence } from "./sequence.ts"
10
-
11
- export interface thread extends Sequencer<Thread>, Effect.Effect<Thread> {}
12
-
13
- const thread_ = Effect.gen(function*() {
14
- return Thread({
15
- parent: yield* Effect.serviceOption(Self),
16
- events: yield* PubSub.unbounded<LEvent>(),
17
- state: ThreadState.default(),
18
- tools: Option.none(),
19
- })
20
- })
21
-
22
- export const thread: thread = Object.assign(
23
- flow(
24
- sequence,
25
- Effect.provideServiceEffect(Self, thread_),
26
- ),
27
- thread_,
28
- )
package/L/to.ts DELETED
@@ -1,4 +0,0 @@
1
- import { Envelope } from "../Envelope.ts"
2
- import type { Thread } from "../Thread.ts"
3
-
4
- export const to = (...to: Array<Thread>): Envelope => Envelope({ to })
package/L/toolkit.ts DELETED
@@ -1,14 +0,0 @@
1
- import * as AiToolkit from "@effect/ai/AiToolkit"
2
- import * as Effect from "effect/Effect"
3
- import * as Option from "effect/Option"
4
- import type { NeverTool } from "../util/NeverTool.ts"
5
- import { Self } from "./Self.ts"
6
-
7
- export const toolkit = Self.pipe(
8
- Effect.flatMap(({ tools }) =>
9
- Option.match(tools, {
10
- onSome: (tools) => AiToolkit.make(...tools),
11
- onNone: () => AiToolkit.make<ReadonlyArray<NeverTool>>(),
12
- })
13
- ),
14
- )
package/L/user.test.ts DELETED
@@ -1,30 +0,0 @@
1
- import { TextPart, UserMessage } from "@effect/ai/AiInput"
2
- import { expect, it } from "@effect/vitest"
3
- import * as Effect from "effect/Effect"
4
- import { messages } from "./messages.ts"
5
- import { thread } from "./thread.ts"
6
- import { user } from "./user.ts"
7
-
8
- it.effect("test success", () =>
9
- Effect.gen(function*() {
10
- yield* user`A`
11
- yield* user("B")
12
- expect(yield* messages).toStrictEqual([
13
- UserMessage.make({
14
- parts: [
15
- TextPart.make({
16
- text: "A",
17
- }),
18
- ],
19
- }),
20
- UserMessage.make({
21
- parts: [
22
- TextPart.make({
23
- text: "B",
24
- }),
25
- ],
26
- }),
27
- ])
28
- }).pipe(
29
- thread,
30
- ))
package/L/user.ts DELETED
@@ -1,22 +0,0 @@
1
- import { TextPart, UserMessage } from "@effect/ai/AiInput"
2
- import * as Effect from "effect/Effect"
3
- import type { Thread } from "../Thread.ts"
4
- import type { Taggable } from "../util/Taggable.ts"
5
- import { append } from "./append.ts"
6
- import { raw } from "./raw.ts"
7
-
8
- /** Append a user message to the conversation. */
9
- export const user: Taggable<void, never, Thread> = (a0, ...aRest) =>
10
- raw(a0, ...aRest).pipe(
11
- Effect.flatMap((text) =>
12
- text
13
- ? append(
14
- UserMessage.make({
15
- parts: [
16
- TextPart.make({ text }),
17
- ],
18
- }),
19
- )
20
- : Effect.succeed(undefined)
21
- ),
22
- )
package/L/userJson.ts DELETED
@@ -1,14 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import type * as Schema from "effect/Schema"
3
- import type { Thread } from "../Thread.ts"
4
- import { encodeJsonc, type JsonValue } from "../util/JsonValue.ts"
5
- import { user } from "./user.ts"
6
-
7
- /** Stringify and append some JSON as a user message to the conversation. */
8
- export const userJson: <A, I extends JsonValue>(
9
- value: A,
10
- schema?: Schema.Schema<A, I>,
11
- ) => Effect.Effect<void, never, Thread> = Effect.fnUntraced(function*(value, schema) {
12
- const encoded = schema ? encodeJsonc(schema)(value) : JSON.stringify(value, null, 2)
13
- return yield* user`\`\`\`json${schema ? "c" : ""}\n${encoded}\n\`\`\``
14
- })
package/LEvent.ts DELETED
@@ -1,23 +0,0 @@
1
- import { Message } from "@effect/ai/AiInput"
2
- import * as Schema from "effect/Schema"
3
-
4
- export class Messages extends Schema.Array(Message) {}
5
-
6
- /** An event in which one or more messages were added to the thread. */
7
- export class MessagesAppended extends Schema.TaggedClass<MessagesAppended>("MessagesAppended")("MessagesAppended", {
8
- messages: Messages,
9
- }) {}
10
-
11
- /** An event in which the thread is cleared of messages. */
12
- export class MessagesCleared extends Schema.TaggedClass<MessagesCleared>("MessagesCleared")("MessagesCleared", {
13
- cleared: Messages,
14
- }) {}
15
-
16
- export type LEvent = typeof LEvent["Type"]
17
- export const LEvent: Schema.Union<[
18
- typeof MessagesAppended,
19
- typeof MessagesCleared,
20
- ]> = Schema.Union(
21
- MessagesAppended,
22
- MessagesCleared,
23
- )
package/LPretty.ts DELETED
@@ -1,41 +0,0 @@
1
- import type { Message } from "@effect/ai/AiInput"
2
- import type { LEvent } from "./LEvent.ts"
3
-
4
- const GRAY = "\x1b[90m"
5
- const RESET = "\x1b[0m"
6
- const BOLD = "\x1b[1m"
7
- const GRAY_BG = "\x1b[47m"
8
-
9
- export const event: (event: typeof LEvent["Type"]) => string = (event) => {
10
- let text = `${GRAY}${event._tag}${RESET}`
11
- switch (event._tag) {
12
- case "MessagesAppended": {
13
- text += event.messages.map(message).join("\n")
14
- break
15
- }
16
- case "MessagesCleared": {
17
- text += `\n${event.cleared.length} messages cleared.`
18
- break
19
- }
20
- }
21
- return text
22
- }
23
-
24
- export const message = ({ _tag, parts }: Message): string => {
25
- let value = ""
26
- for (const part of parts) {
27
- value += `\n${BOLD}${_tag}\n${GRAY_BG}`
28
- switch (part._tag) {
29
- case "TextPart": {
30
- value += `${part.text}`
31
- break
32
- }
33
- default: {
34
- value += `${JSON.stringify(part, null, 2)}`
35
- break
36
- }
37
- }
38
- value += RESET
39
- }
40
- return value
41
- }
package/Thread.ts DELETED
@@ -1,69 +0,0 @@
1
- import { Message } from "@effect/ai/AiInput"
2
- import * as Effect from "effect/Effect"
3
- import * as Option from "effect/Option"
4
- import { type Pipeable, pipeArguments } from "effect/Pipeable"
5
- import * as PubSub from "effect/PubSub"
6
- import * as Schema from "effect/Schema"
7
- import type { Mutable } from "effect/Types"
8
- import { Self } from "./L/Self.ts"
9
- import { sequence } from "./L/sequence.ts"
10
- import type { LEvent } from "./LEvent.ts"
11
- import type { NeverTool } from "./util/NeverTool.ts"
12
- import { prefix } from "./util/prefix.ts"
13
- import type { Sequencer } from "./util/Sequencer.ts"
14
-
15
- export const ThreadFqnTypeId: unique symbol = Symbol.for(prefix("ThreadFqn"))
16
- export const ThreadFqn = Schema.String.pipe(Schema.brand(ThreadFqnTypeId))
17
- export type ThreadFqn = typeof ThreadFqn["Type"]
18
-
19
- export class ThreadState extends Schema.Class<ThreadState>(prefix("ThreadState"))({
20
- /** The key with which the thread is referenced by others. */
21
- fqn: Schema.Option(ThreadFqn),
22
- /** The system prompt to be passed along to the model. */
23
- system: Schema.Option(Schema.String),
24
- /** The messages based off of which the model infers the next message. */
25
- messages: Schema.Array(Message).pipe(Schema.mutable),
26
- }) {
27
- static default = (): ThreadState =>
28
- ThreadState.make({
29
- fqn: Option.none(),
30
- system: Option.none(),
31
- messages: [],
32
- })
33
- }
34
-
35
- export interface ThreadInit {
36
- /** The parent thread. */
37
- parent: Option.Option<Thread>
38
- /** The pubsub with which thread-specific events are emitted. */
39
- events: PubSub.PubSub<LEvent>
40
- /** The state of the current thread. */
41
- state: Mutable<ThreadState>
42
- /** The tools to be made accessible to the model. */
43
- tools: Option.Option<Set<NeverTool>>
44
- }
45
-
46
- export const ThreadTypeId: unique symbol = Symbol.for(prefix("Thread"))
47
- export type ThreadTypeId = typeof ThreadTypeId
48
-
49
- interface ThreadMembers extends ThreadInit, Pipeable {
50
- readonly [ThreadTypeId]: ThreadTypeId
51
- }
52
-
53
- /** A conversation isolate. */
54
- export interface Thread extends Sequencer<Thread>, ThreadMembers {}
55
-
56
- export const Thread = (init: ThreadInit): Thread => {
57
- const members = {
58
- [ThreadTypeId]: ThreadTypeId,
59
- ...init,
60
- pipe() {
61
- return pipeArguments(self, arguments)
62
- },
63
- } satisfies ThreadMembers
64
- const self = Object.assign(
65
- ((...args) => sequence(...args).pipe(Effect.provideService(Self, self))) satisfies Sequencer<Thread>,
66
- members,
67
- ) as Thread
68
- return self
69
- }
@@ -1,15 +0,0 @@
1
- import type { Thread } from "./Thread.ts";
2
- import { type Taggable } from "./util/Taggable.ts";
3
- export interface MessageHeaders {
4
- readonly to: Array<Thread>;
5
- readonly cc?: Array<Thread> | undefined;
6
- readonly bcc?: Array<Thread> | undefined;
7
- }
8
- export interface EnvelopeMembers {
9
- readonly headers: MessageHeaders;
10
- readonly cc: (...cc: Array<Thread>) => Envelope;
11
- readonly bcc: (...bcc: Array<Thread>) => Envelope;
12
- }
13
- export interface Envelope extends Taggable<void, never, Thread>, EnvelopeMembers {
14
- }
15
- export declare const Envelope: (headers: MessageHeaders) => Envelope;
package/dist/Envelope.js DELETED
@@ -1,30 +0,0 @@
1
- import * as AiInput from "@effect/ai/AiInput";
2
- import * as Effect from "effect/Effect";
3
- import * as Option from "effect/Option";
4
- import { append } from "./L/append.js";
5
- import { raw } from "./L/raw.js";
6
- import { Self } from "./L/Self.js";
7
- import {} from "./util/Taggable.js";
8
- // TODO: cc, bcc
9
- export const Envelope = (headers) => Object.assign(Effect.fnUntraced(function* (a0, ...aRest) {
10
- const { state: { fqn } } = yield* Self;
11
- const name = Option.getOrElse(fqn, () => "anonymous-entity");
12
- const text = yield* raw(a0, ...aRest);
13
- if (!text)
14
- return;
15
- const { to, cc: _cc, bcc: _bcc } = headers;
16
- for (const recipient of to) {
17
- yield* append(AiInput.UserMessage.make({
18
- parts: [
19
- AiInput.TextPart.make({
20
- text: `[FROM: ${name}]\n${text}`,
21
- }),
22
- ],
23
- })).pipe(Effect.provideService(Self, recipient));
24
- }
25
- }), {
26
- headers,
27
- cc: (...cc) => Envelope({ ...headers, cc }),
28
- bcc: (...bcc) => Envelope({ ...headers, bcc }),
29
- });
30
- //# sourceMappingURL=Envelope.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Envelope.js","sourceRoot":"","sources":["../Envelope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAC7C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAElC,OAAO,EAAiB,MAAM,oBAAoB,CAAA;AAgBlD,gBAAgB;AAChB,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAAuB,EAAY,EAAE,CAC5D,MAAM,CAAC,MAAM,CACX,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAC,EAAE,EAAE,GAAG,KAAK;IACtC,MAAM,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,IAAI,CAAA;IACtC,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,CAAA;IAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,KAAK,CAAC,CAAA;IACrC,IAAI,CAAC,IAAI;QAAE,OAAM;IACjB,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,OAAO,CAAA;IAC1C,KAAK,MAAM,SAAS,IAAI,EAAE,EAAE,CAAC;QAC3B,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC;YACrC,KAAK,EAAE;gBACL,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;oBACpB,IAAI,EAAE,UAAU,IAAI,MAAM,IAAI,EAAE;iBACjC,CAAC;aACH;SACF,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAA;IAClD,CAAC;AACH,CAAC,CAAyC,EAC1C;IACE,OAAO;IACP,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC;IAC3C,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,CAAC;CACrB,CAC5B,CAAA"}
package/dist/L/L.d.ts DELETED
@@ -1,21 +0,0 @@
1
- export * from "./append.ts";
2
- export * from "./assistant.ts";
3
- export * from "./assistantSchema.ts";
4
- export * from "./assistantStream.ts";
5
- export * from "./branch.ts";
6
- export * from "./clear.ts";
7
- export * from "./disable.ts";
8
- export * from "./enable.ts";
9
- export * from "./events.ts";
10
- export * from "./fqn.ts";
11
- export * from "./handle.ts";
12
- export * from "./messages.ts";
13
- export * from "./raw.ts";
14
- export * from "./Self.ts";
15
- export * from "./sequence.ts";
16
- export * from "./system.ts";
17
- export * from "./thread.ts";
18
- export * from "./to.ts";
19
- export * from "./toolkit.ts";
20
- export * from "./user.ts";
21
- export * from "./userJson.ts";
package/dist/L/L.js DELETED
@@ -1,22 +0,0 @@
1
- export * from "./append.js";
2
- export * from "./assistant.js";
3
- export * from "./assistantSchema.js";
4
- export * from "./assistantStream.js";
5
- export * from "./branch.js";
6
- export * from "./clear.js";
7
- export * from "./disable.js";
8
- export * from "./enable.js";
9
- export * from "./events.js";
10
- export * from "./fqn.js";
11
- export * from "./handle.js";
12
- export * from "./messages.js";
13
- export * from "./raw.js";
14
- export * from "./Self.js";
15
- export * from "./sequence.js";
16
- export * from "./system.js";
17
- export * from "./thread.js";
18
- export * from "./to.js";
19
- export * from "./toolkit.js";
20
- export * from "./user.js";
21
- export * from "./userJson.js";
22
- //# 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,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA"}
package/dist/L/Self.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import * as Context from "effect/Context";
2
- import type { Thread } from "../Thread.ts";
3
- export declare const Self: Context.Tag<Thread, Thread>;
package/dist/L/Self.js DELETED
@@ -1,4 +0,0 @@
1
- import * as Context from "effect/Context";
2
- import { prefix } from "../util/prefix.js";
3
- export const Self = Context.GenericTag(prefix("Self"));
4
- //# sourceMappingURL=Self.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Self.js","sourceRoot":"","sources":["../../L/Self.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,MAAM,CAAC,MAAM,IAAI,GAAgC,OAAO,CAAC,UAAU,CAAS,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA"}
@@ -1,5 +0,0 @@
1
- import type { Message } from "@effect/ai/AiInput";
2
- import * as Effect from "effect/Effect";
3
- import type { Thread } from "../Thread.ts";
4
- /** Append messages to the thread. */
5
- export declare const append: (...messages: Array<Message>) => Effect.Effect<void, never, Thread>;
package/dist/L/append.js DELETED
@@ -1,10 +0,0 @@
1
- import * as Effect from "effect/Effect";
2
- import { MessagesAppended } from "../LEvent.js";
3
- import { Self } from "./Self.js";
4
- /** Append messages to the thread. */
5
- export const append = Effect.fnUntraced(function* (...messages) {
6
- const { state, events } = yield* Self;
7
- state.messages.push(...messages);
8
- yield* events.publish(MessagesAppended.make({ messages }));
9
- });
10
- //# sourceMappingURL=append.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"append.js","sourceRoot":"","sources":["../../L/append.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,qCAAqC;AACrC,MAAM,CAAC,MAAM,MAAM,GAEuB,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAC,GAAG,QAAQ;IAC/E,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,IAAI,CAAA;IACrC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAA;IAChC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAA;AAC5D,CAAC,CAAC,CAAA"}
@@ -1,6 +0,0 @@
1
- import type { AiError } from "@effect/ai/AiError";
2
- import { AiLanguageModel } from "@effect/ai/AiLanguageModel";
3
- import * as Effect from "effect/Effect";
4
- import type { Thread } from "../Thread.ts";
5
- /** Infer an assistant message and append it to the thread. */
6
- export declare const assistant: Effect.Effect<string, AiError, AiLanguageModel | Thread>;
@@ -1,26 +0,0 @@
1
- import { AssistantMessage, TextPart } from "@effect/ai/AiInput";
2
- import { AiLanguageModel } from "@effect/ai/AiLanguageModel";
3
- import * as Effect from "effect/Effect";
4
- import * as Option from "effect/Option";
5
- import { append } from "./append.js";
6
- import { Self } from "./Self.js";
7
- import { toolkit } from "./toolkit.js";
8
- /** Infer an assistant message and append it to the thread. */
9
- export const assistant = Effect.gen(function* () {
10
- const model = yield* AiLanguageModel;
11
- const { state: { system, messages: prompt } } = yield* Self;
12
- let { text, results } = yield* model.generateText({
13
- system: Option.getOrUndefined(system),
14
- prompt,
15
- toolkit,
16
- });
17
- // TODO: this shouldn't be necessary. Bug in Effect AI?
18
- if (!text.trim()) {
19
- text = results.values().next().value?.result;
20
- }
21
- yield* append(AssistantMessage.make({
22
- parts: [TextPart.make({ text })],
23
- }));
24
- return text;
25
- });
26
- //# sourceMappingURL=assistant.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assistant.js","sourceRoot":"","sources":["../../L/assistant.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,SAAS,GAA6D,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACrG,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,eAAe,CAAA;IACpC,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,IAAI,CAAA;IAC3D,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC;QAChD,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC;QACrC,MAAM;QACN,OAAO;KACR,CAAC,CAAA;IACF,uDAAuD;IACvD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QACjB,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,MAAyB,CAAA;IACjE,CAAC;IACD,KAAK,CAAC,CAAC,MAAM,CACX,gBAAgB,CAAC,IAAI,CAAC;QACpB,KAAK,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;KACjC,CAAC,CACH,CAAA;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAC,CAAA"}