liminal 0.17.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 (287) 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 -212
  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 -7
  109. package/dist/index.js +9 -7
  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 -7
  131. package/package.json +21 -30
  132. package/tsconfig.json +9 -0
  133. package/Digest.ts +0 -30
  134. package/Envelope.ts +0 -16
  135. package/F/F.ts +0 -1
  136. package/L/L.ts +0 -20
  137. package/L/append.ts +0 -14
  138. package/L/assistant.ts +0 -30
  139. package/L/assistantSchema.ts +0 -61
  140. package/L/assistantStream.ts +0 -22
  141. package/L/branch.ts +0 -20
  142. package/L/clear.ts +0 -14
  143. package/L/disable.ts +0 -13
  144. package/L/enable.ts +0 -24
  145. package/L/events.ts +0 -11
  146. package/L/json.ts +0 -12
  147. package/L/line.ts +0 -22
  148. package/L/listen.ts +0 -26
  149. package/L/messages.ts +0 -10
  150. package/L/prev.ts +0 -4
  151. package/L/provide.ts +0 -10
  152. package/L/self.ts +0 -5
  153. package/L/send.ts +0 -56
  154. package/L/system.ts +0 -25
  155. package/L/thread.ts +0 -16
  156. package/L/toolkit.ts +0 -14
  157. package/L/user.test.ts +0 -33
  158. package/L/user.ts +0 -32
  159. package/LEvent.ts +0 -33
  160. package/Thread.ts +0 -67
  161. package/dist/Digest.d.ts +0 -17
  162. package/dist/Digest.js +0 -7
  163. package/dist/Digest.js.map +0 -1
  164. package/dist/Envelope.d.ts +0 -13
  165. package/dist/Envelope.js +0 -2
  166. package/dist/Envelope.js.map +0 -1
  167. package/dist/F/F.d.ts +0 -1
  168. package/dist/F/F.js +0 -2
  169. package/dist/F/F.js.map +0 -1
  170. package/dist/L/L.d.ts +0 -20
  171. package/dist/L/L.js +0 -21
  172. package/dist/L/L.js.map +0 -1
  173. package/dist/L/append.d.ts +0 -5
  174. package/dist/L/append.js +0 -10
  175. package/dist/L/append.js.map +0 -1
  176. package/dist/L/assistant.d.ts +0 -6
  177. package/dist/L/assistant.js +0 -26
  178. package/dist/L/assistant.js.map +0 -1
  179. package/dist/L/assistantSchema.d.ts +0 -13
  180. package/dist/L/assistantSchema.js +0 -44
  181. package/dist/L/assistantSchema.js.map +0 -1
  182. package/dist/L/assistantStream.d.ts +0 -7
  183. package/dist/L/assistantStream.js +0 -17
  184. package/dist/L/assistantStream.js.map +0 -1
  185. package/dist/L/branch.d.ts +0 -3
  186. package/dist/L/branch.js +0 -19
  187. package/dist/L/branch.js.map +0 -1
  188. package/dist/L/clear.d.ts +0 -5
  189. package/dist/L/clear.js +0 -12
  190. package/dist/L/clear.js.map +0 -1
  191. package/dist/L/disable.d.ts +0 -4
  192. package/dist/L/disable.js +0 -10
  193. package/dist/L/disable.js.map +0 -1
  194. package/dist/L/enable.d.ts +0 -5
  195. package/dist/L/enable.js +0 -13
  196. package/dist/L/enable.js.map +0 -1
  197. package/dist/L/events.d.ts +0 -5
  198. package/dist/L/events.js +0 -6
  199. package/dist/L/events.js.map +0 -1
  200. package/dist/L/json.d.ts +0 -5
  201. package/dist/L/json.js +0 -8
  202. package/dist/L/json.js.map +0 -1
  203. package/dist/L/line.d.ts +0 -5
  204. package/dist/L/line.js +0 -11
  205. package/dist/L/line.js.map +0 -1
  206. package/dist/L/listen.d.ts +0 -7
  207. package/dist/L/listen.js +0 -14
  208. package/dist/L/listen.js.map +0 -1
  209. package/dist/L/messages.d.ts +0 -5
  210. package/dist/L/messages.js +0 -5
  211. package/dist/L/messages.js.map +0 -1
  212. package/dist/L/prev.d.ts +0 -5
  213. package/dist/L/prev.js +0 -5
  214. package/dist/L/prev.js.map +0 -1
  215. package/dist/L/provide.d.ts +0 -3
  216. package/dist/L/provide.js +0 -4
  217. package/dist/L/provide.js.map +0 -1
  218. package/dist/L/self.d.ts +0 -3
  219. package/dist/L/self.js +0 -4
  220. package/dist/L/self.js.map +0 -1
  221. package/dist/L/send.d.ts +0 -6
  222. package/dist/L/send.js +0 -34
  223. package/dist/L/send.js.map +0 -1
  224. package/dist/L/system.d.ts +0 -5
  225. package/dist/L/system.js +0 -14
  226. package/dist/L/system.js.map +0 -1
  227. package/dist/L/thread.d.ts +0 -3
  228. package/dist/L/thread.js +0 -15
  229. package/dist/L/thread.js.map +0 -1
  230. package/dist/L/toolkit.d.ts +0 -4
  231. package/dist/L/toolkit.js +0 -9
  232. package/dist/L/toolkit.js.map +0 -1
  233. package/dist/L/user.d.ts +0 -6
  234. package/dist/L/user.js +0 -13
  235. package/dist/L/user.js.map +0 -1
  236. package/dist/L/user.test.d.ts +0 -1
  237. package/dist/L/user.test.js.map +0 -1
  238. package/dist/LEvent.d.ts +0 -154
  239. package/dist/LEvent.js +0 -19
  240. package/dist/LEvent.js.map +0 -1
  241. package/dist/Thread.d.ts +0 -52
  242. package/dist/Thread.js +0 -32
  243. package/dist/Thread.js.map +0 -1
  244. package/dist/patterns/Debate.d.ts +0 -1
  245. package/dist/patterns/Debate.js +0 -3
  246. package/dist/patterns/Debate.js.map +0 -1
  247. package/dist/patterns/Model.d.ts +0 -6
  248. package/dist/patterns/Model.js +0 -14
  249. package/dist/patterns/Model.js.map +0 -1
  250. package/dist/patterns/Route.d.ts +0 -3
  251. package/dist/patterns/Route.js +0 -14
  252. package/dist/patterns/Route.js.map +0 -1
  253. package/dist/util/JsonValue.d.ts +0 -8
  254. package/dist/util/JsonValue.js +0 -109
  255. package/dist/util/JsonValue.js.map +0 -1
  256. package/dist/util/NeverTool.d.ts +0 -3
  257. package/dist/util/NeverTool.js +0 -3
  258. package/dist/util/NeverTool.js.map +0 -1
  259. package/dist/util/Taggable.d.ts +0 -6
  260. package/dist/util/Taggable.js +0 -13
  261. package/dist/util/Taggable.js.map +0 -1
  262. package/dist/util/extract.d.ts +0 -3
  263. package/dist/util/extract.js +0 -2
  264. package/dist/util/extract.js.map +0 -1
  265. package/dist/util/messageCodec.d.ts +0 -98
  266. package/dist/util/messageCodec.js +0 -5
  267. package/dist/util/messageCodec.js.map +0 -1
  268. package/dist/util/normalizeRaw.d.ts +0 -4
  269. package/dist/util/normalizeRaw.js +0 -75
  270. package/dist/util/normalizeRaw.js.map +0 -1
  271. package/dist/util/prefix.d.ts +0 -1
  272. package/dist/util/prefix.js +0 -2
  273. package/dist/util/prefix.js.map +0 -1
  274. package/dist/util/raw.d.ts +0 -6
  275. package/dist/util/raw.js +0 -5
  276. package/dist/util/raw.js.map +0 -1
  277. package/patterns/Debate.ts +0 -2
  278. package/patterns/Model.ts +0 -29
  279. package/patterns/Route.ts +0 -25
  280. package/util/JsonValue.ts +0 -144
  281. package/util/NeverTool.ts +0 -10
  282. package/util/Taggable.ts +0 -33
  283. package/util/extract.ts +0 -7
  284. package/util/messageCodec.ts +0 -5
  285. package/util/normalizeRaw.ts +0 -93
  286. package/util/prefix.ts +0 -1
  287. package/util/raw.ts +0 -27
package/L/branch.ts DELETED
@@ -1,20 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import * as Option from "effect/Option"
3
- import * as PubSub from "effect/PubSub"
4
- import type { LEvent } from "../LEvent.ts"
5
- import { Thread, ThreadState } from "../Thread.ts"
6
- import { self } from "./self.ts"
7
-
8
- export const branch: Effect.Effect<Thread, never, Thread> = Effect.gen(function*() {
9
- const parent = yield* self
10
- return Thread({
11
- id: parent.id,
12
- parent: Option.some(parent),
13
- events: yield* PubSub.unbounded<LEvent>(),
14
- state: ThreadState.make({
15
- system: parent.state.system,
16
- messages: [...parent.state.messages ?? []],
17
- }),
18
- tools: parent.tools.pipe(Option.map((v) => new Set(v))),
19
- })
20
- })
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 { ThreadClearedEvent } 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(ThreadClearedEvent.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/json.ts DELETED
@@ -1,12 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import type * as Schema from "effect/Schema"
3
- import { encodeJsonc, type JsonValue } from "../util/JsonValue.ts"
4
-
5
- /** Stringify and append some JSON as a user message to the conversation. */
6
- export const json: <A, I extends JsonValue>(
7
- value: A,
8
- schema?: Schema.Schema<A, I>,
9
- ) => Effect.Effect<string> = Effect.fnUntraced(function*(value, schema) {
10
- const encoded = schema ? encodeJsonc(schema)(value) : JSON.stringify(value, null, 2)
11
- return `\`\`\`json${schema ? "c" : ""}\n${encoded}\n\`\`\``
12
- })
package/L/line.ts DELETED
@@ -1,22 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import { prev } from "./prev.ts"
3
-
4
- export interface line<RIn = never, E = never, ROut = never> {
5
- <Arg extends Array<Effect.All.EffectAny>>(
6
- ...steps: Arg
7
- ): Effect.Effect<
8
- Arg extends [] ? void
9
- : Arg extends [...infer _0, infer L extends Effect.All.EffectAny] ? Effect.Effect.Success<L>
10
- : never,
11
- Effect.Effect.Error<Arg[number]> | E,
12
- Exclude<Effect.Effect.Context<Arg[number]>, RIn> | ROut
13
- >
14
- }
15
- export const line: line = Effect.fnUntraced(function*(...steps) {
16
- let acc: unknown
17
- while (steps.length) {
18
- const current = steps.shift()!
19
- acc = yield* (current.pipe(Effect.provideService(prev, acc)) as Effect.Effect<any>)
20
- }
21
- return acc as never
22
- })
package/L/listen.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/prev.ts DELETED
@@ -1,4 +0,0 @@
1
- import * as Context from "effect/Context"
2
- import { prefix } from "../util/prefix.ts"
3
-
4
- export class prev extends Context.Tag(prefix("prev"))<prev, unknown>() {}
package/L/provide.ts DELETED
@@ -1,10 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import type { Thread } from "../Thread.ts"
3
- import { self } from "./self.ts"
4
-
5
- export const provide = <E, R>(
6
- thread: Effect.Effect<Thread, E, R>,
7
- ) =>
8
- <A1, E1, R1>(
9
- a: Effect.Effect<A1, E1, R1>,
10
- ): Effect.Effect<A1, E | E1, R | Exclude<R1, Thread>> => Effect.provideServiceEffect(self, thread)(a)
package/L/self.ts DELETED
@@ -1,5 +0,0 @@
1
- import * as Context from "effect/Context"
2
- import type { Thread } from "../Thread.ts"
3
- import { prefix } from "../util/prefix.ts"
4
-
5
- export const self: Context.Tag<Thread, Thread> = Context.GenericTag<Thread>(prefix("Self"))
package/L/send.ts DELETED
@@ -1,56 +0,0 @@
1
- import * as AiInput from "@effect/ai/AiInput"
2
- import * as Array from "effect/Array"
3
- import * as Effect from "effect/Effect"
4
- import type { YieldWrap } from "effect/Utils"
5
- import type { Envelope } from "../Envelope.ts"
6
- import type { Thread } from "../Thread.ts"
7
- import type { ExtractE, ExtractR } from "../util/extract.ts"
8
- import { raw } from "../util/raw.ts"
9
- import { normalize, type TaggableArg0, type TaggableArgRest } from "../util/Taggable.ts"
10
- import { append } from "./append.ts"
11
- import { self } from "./self.ts"
12
-
13
- export const send = (envelope: Envelope) =>
14
- Effect.fnUntraced(function*<
15
- A0 extends TaggableArg0,
16
- ARest extends TaggableArgRest<A0>,
17
- >(
18
- a0: A0,
19
- ...aRest: ARest
20
- ): Generator<
21
- YieldWrap<
22
- Effect.Effect<
23
- void,
24
- ExtractE<A0 | ARest[number]>,
25
- ExtractR<A0 | ARest[number]> | Thread
26
- >
27
- >,
28
- void,
29
- never
30
- > {
31
- const text = yield* normalize(a0, ...aRest)
32
- if (!text) return
33
- const { to, cc, bcc } = envelope
34
- const ccHeader = cc?.length
35
- ? yield* raw`; ${Effect.all(cc).pipe(Effect.map(Array.join(", ")))}`
36
- : ""
37
- const headers = raw`[FROM: ${self}${ccHeader}]`
38
- const knownRecipients = [...to ?? [], ...cc ?? []]
39
- const program = append(
40
- AiInput.UserMessage.make({
41
- parts: [
42
- AiInput.TextPart.make({
43
- text: `${headers}\n${text}`,
44
- }),
45
- ],
46
- }),
47
- )
48
- for (const recipient of knownRecipients) {
49
- yield* program.pipe(Effect.provideService(self, recipient))
50
- }
51
- if (bcc?.length) {
52
- for (const hiddenRecipient of bcc) {
53
- yield* program.pipe(Effect.provideService(self, hiddenRecipient))
54
- }
55
- }
56
- })
package/L/system.ts DELETED
@@ -1,25 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import * as Option from "effect/Option"
3
- import type { YieldWrap } from "effect/Utils"
4
- import { SystemSetEvent } from "../LEvent.ts"
5
- import { normalize, type TaggableArg0, type TaggableArgRest } from "../util/Taggable.ts"
6
- import { self } from "./self.ts"
7
-
8
- /** Set the thread's system instruction. */
9
- export const system = Effect.fnUntraced(function*<
10
- A0 extends TaggableArg0,
11
- ARest extends TaggableArgRest<A0>,
12
- >(
13
- a0: A0,
14
- ...aRest: ARest
15
- ): Generator<
16
- YieldWrap<typeof self | ReturnType<typeof normalize<A0, ARest>> | Effect.Effect<boolean>>,
17
- Option.Option<string>,
18
- never
19
- > {
20
- const { state, events } = yield* self
21
- const { system } = state
22
- state.system = a0 ? Option.some(yield* normalize(a0, ...aRest)) : Option.none()
23
- yield* events.publish(new SystemSetEvent({ system: state.system }))
24
- return system
25
- })
package/L/thread.ts DELETED
@@ -1,16 +0,0 @@
1
- import * as Effect from "effect/Effect"
2
- import * as Option from "effect/Option"
3
- import * as PubSub from "effect/PubSub"
4
- import type { LEvent } from "../LEvent.ts"
5
- import { Thread, ThreadId, ThreadState } from "../Thread.ts"
6
- import { self } from "./self.ts"
7
-
8
- export const thread: Effect.Effect<Thread> = Effect.gen(function*() {
9
- return Thread({
10
- id: ThreadId.make(crypto.randomUUID()),
11
- parent: yield* Effect.serviceOption(self),
12
- events: yield* PubSub.unbounded<LEvent>(),
13
- state: ThreadState.default(),
14
- tools: Option.none(),
15
- })
16
- })
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,33 +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 { provide } from "./provide.ts"
6
- import { thread } from "./thread.ts"
7
- import { user } from "./user.ts"
8
-
9
- it.effect("test success", () =>
10
- Effect.gen(function*() {
11
- yield* user`A`
12
- yield* user("B")
13
- expect(yield* messages).toStrictEqual([
14
- UserMessage.make({
15
- parts: [
16
- TextPart.make({
17
- text: "A",
18
- }),
19
- ],
20
- }),
21
- UserMessage.make({
22
- parts: [
23
- TextPart.make({
24
- text: "B",
25
- }),
26
- ],
27
- }),
28
- ])
29
- }).pipe(
30
- provide(
31
- thread,
32
- ),
33
- ))
package/L/user.ts DELETED
@@ -1,32 +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 { ExtractE, ExtractR } from "../util/extract.ts"
5
- import { normalize, type TaggableArg0, type TaggableArgRest } from "../util/Taggable.ts"
6
- import { append } from "./append.ts"
7
-
8
- /** Append a user message to the thread. */
9
- export const user = <
10
- A0 extends TaggableArg0,
11
- ARest extends TaggableArgRest<A0>,
12
- >(
13
- a0: A0,
14
- ...aRest: ARest
15
- ): Effect.Effect<
16
- void,
17
- ExtractE<A0 | ARest[number]>,
18
- ExtractR<A0 | ARest[number]> | Thread
19
- > =>
20
- normalize(a0, ...aRest).pipe(
21
- Effect.flatMap((text) =>
22
- text
23
- ? append(
24
- UserMessage.make({
25
- parts: [
26
- TextPart.make({ text }),
27
- ],
28
- }),
29
- )
30
- : Effect.succeed(undefined)
31
- ),
32
- )
package/LEvent.ts DELETED
@@ -1,33 +0,0 @@
1
- import { Message } from "@effect/ai/AiInput"
2
- import * as Schema from "effect/Schema"
3
-
4
- /** Event in which the thread's system is set to a new string. */
5
- export class SystemSetEvent extends Schema.TaggedClass<SystemSetEvent>("SystemSetEvent")("system_set", {
6
- system: Schema.Option(Schema.String),
7
- }) {}
8
-
9
- /** Event in which one or more messages were added to the thread. */
10
- export class MessagesAppendedEvent
11
- extends Schema.TaggedClass<MessagesAppendedEvent>("MessagesAppendedEvent")("messages_appended", {
12
- messages: Schema.Array(Message),
13
- })
14
- {}
15
-
16
- /** Event in which the thread is cleared of messages. */
17
- export class ThreadClearedEvent
18
- extends Schema.TaggedClass<ThreadClearedEvent>("MessagesClearedEvent")("messages_cleared", {})
19
- {}
20
-
21
- export type LEvent = typeof LEvent["Type"]
22
- export const LEvent: Schema.Union<[
23
- typeof SystemSetEvent,
24
- typeof MessagesAppendedEvent,
25
- typeof ThreadClearedEvent,
26
- ]> = Schema.Union(
27
- SystemSetEvent,
28
- MessagesAppendedEvent,
29
- ThreadClearedEvent,
30
- )
31
-
32
- export const encodeLEvent = Schema.encode(LEvent)
33
- export const decodeLEvent = Schema.decode(LEvent)
package/Thread.ts DELETED
@@ -1,67 +0,0 @@
1
- import { Message } from "@effect/ai/AiInput"
2
- import * as Brand from "effect/Brand"
3
- import * as Effect from "effect/Effect"
4
- import * as Option from "effect/Option"
5
- import * as PubSub from "effect/PubSub"
6
- import * as Schema from "effect/Schema"
7
- import type { Mutable } from "effect/Types"
8
- import { line } from "./L/line.ts"
9
- import { self } from "./L/self.ts"
10
- import type { LEvent } from "./LEvent.ts"
11
- import type { NeverTool } from "./util/NeverTool.ts"
12
- import { prefix } from "./util/prefix.ts"
13
-
14
- export const ThreadIdTypeId: unique symbol = Symbol.for(prefix("ThreadNameTypeId"))
15
- export type ThreadId = string & Brand.Brand<typeof ThreadIdTypeId>
16
- export const ThreadId: Schema.brand<typeof Schema.String, typeof ThreadIdTypeId> = Schema.String.pipe(
17
- Schema.brand(ThreadIdTypeId),
18
- )
19
-
20
- export class ThreadState extends Schema.Class<ThreadState>(prefix("ThreadState"))({
21
- /** The system prompt to be passed along to the model. */
22
- system: Schema.Option(Schema.String),
23
- /** The messages based off of which the model infers the next message. */
24
- messages: Schema.Array(Message).pipe(Schema.mutable),
25
- }) {
26
- static default = (): ThreadState =>
27
- ThreadState.make({
28
- system: Option.none(),
29
- messages: [],
30
- })
31
- }
32
-
33
- export interface ThreadInit {
34
- /** The unique id of the thread. */
35
- readonly id: ThreadId
36
- /** The parent thread. */
37
- readonly parent: Option.Option<Thread>
38
- /** The pubsub with which thread-specific events are emitted. */
39
- readonly events: PubSub.PubSub<LEvent>
40
- /** The state of the current thread. */
41
- readonly 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 {
50
- readonly [ThreadTypeId]: ThreadTypeId
51
- }
52
-
53
- /** A conversation isolate. */
54
- export interface Thread extends line<Thread>, ThreadMembers, Effect.Effect<ThreadId> {}
55
-
56
- export const Thread = (init: ThreadInit): Thread => {
57
- const members = {
58
- [ThreadTypeId]: ThreadTypeId,
59
- ...init,
60
- } satisfies ThreadMembers
61
- const self_ = Object.assign(
62
- ((...args) => line(...args).pipe(Effect.provideService(self, self_))) satisfies line<Thread>,
63
- Effect.succeed(init.id),
64
- members,
65
- ) as Thread
66
- return self_
67
- }
package/dist/Digest.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import * as Effect from "effect/Effect";
2
- import * as Layer from "effect/Layer";
3
- import * as Option from "effect/Option";
4
- import * as Schema from "effect/Schema";
5
- import type { Thread } from "./Thread.ts";
6
- export declare const DigestTypeId: unique symbol;
7
- export type DigestTypeId = typeof DigestTypeId;
8
- export declare const Digest: <const K extends string, A = string, I = string>(key: K, schema?: Schema.Schema<A, I>) => <Self>() => DigestClass<K, A, I, Self>;
9
- export interface DigestClass<K extends string, A, I, Self> extends Effect.Effect<A, never, Self> {
10
- new (_: never): this;
11
- readonly Type: A;
12
- readonly Encoded: I;
13
- readonly [DigestTypeId]: DigestTypeId;
14
- readonly key: K;
15
- readonly digest: Effect.Effect<void, never, Self>;
16
- readonly layer: <E, R>(f: (state: Option.Option<A>, inbox: Thread) => Effect.Effect<A, E, R>) => Layer.Layer<Self, E, Exclude<R, Self | Thread>>;
17
- }
package/dist/Digest.js DELETED
@@ -1,7 +0,0 @@
1
- import * as Effect from "effect/Effect";
2
- import * as Layer from "effect/Layer";
3
- import * as Option from "effect/Option";
4
- import * as Schema from "effect/Schema";
5
- import { prefix } from "./util/prefix.js";
6
- export const DigestTypeId = Symbol.for(prefix("Digest"));
7
- //# sourceMappingURL=Digest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Digest.js","sourceRoot":"","sources":["../Digest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,MAAM,CAAC,MAAM,YAAY,GAAkB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAA"}
@@ -1,13 +0,0 @@
1
- import { Thread } from "./Thread.ts";
2
- export type Envelope = ({
3
- to: Array<Thread>;
4
- cc?: never;
5
- } | {
6
- to?: never;
7
- cc: Array<Thread>;
8
- } | {
9
- to: Array<Thread>;
10
- cc: Array<Thread>;
11
- }) & {
12
- bcc?: Array<Thread>;
13
- };
package/dist/Envelope.js DELETED
@@ -1,2 +0,0 @@
1
- import { Thread } from "./Thread.js";
2
- //# sourceMappingURL=Envelope.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Envelope.js","sourceRoot":"","sources":["../Envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
package/dist/F/F.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "../L/json.ts";
package/dist/F/F.js DELETED
@@ -1,2 +0,0 @@
1
- export * from "../L/json.js";
2
- //# sourceMappingURL=F.js.map
package/dist/F/F.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"F.js","sourceRoot":"","sources":["../../F/F.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
package/dist/L/L.d.ts DELETED
@@ -1,20 +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 "./line.ts";
11
- export * from "./listen.ts";
12
- export * from "./messages.ts";
13
- export * from "./prev.ts";
14
- export * from "./provide.ts";
15
- export * from "./self.ts";
16
- export * from "./send.ts";
17
- export * from "./system.ts";
18
- export * from "./thread.ts";
19
- export * from "./toolkit.ts";
20
- export * from "./user.ts";
package/dist/L/L.js DELETED
@@ -1,21 +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 "./line.js";
11
- export * from "./listen.js";
12
- export * from "./messages.js";
13
- export * from "./prev.js";
14
- export * from "./provide.js";
15
- export * from "./self.js";
16
- export * from "./send.js";
17
- export * from "./system.js";
18
- export * from "./thread.js";
19
- export * from "./toolkit.js";
20
- export * from "./user.js";
21
- //# 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,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,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 { MessagesAppendedEvent } 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(MessagesAppendedEvent.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,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAEpD,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,qBAAqB,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAA;AACjE,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"}