liminal 0.17.0 → 0.17.2

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 (288) hide show
  1. package/Accumulator.ts +103 -0
  2. package/Actor.ts +124 -0
  3. package/Audition.ts +110 -0
  4. package/CHANGELOG.md +4 -208
  5. package/Client.ts +525 -0
  6. package/ClientHandle.ts +50 -0
  7. package/F.ts +12 -0
  8. package/LICENSE +202 -0
  9. package/Method.ts +37 -0
  10. package/Protocol.ts +120 -0
  11. package/Send.ts +12 -0
  12. package/_constants.ts +1 -0
  13. package/_util/Diagnostic.ts +16 -0
  14. package/_util/Mutex.ts +13 -0
  15. package/_util/phantom.ts +1 -0
  16. package/dist/Accumulator.d.ts +22 -0
  17. package/dist/Accumulator.js +37 -0
  18. package/dist/Accumulator.js.map +1 -0
  19. package/dist/Actor.d.ts +29 -0
  20. package/dist/Actor.js +22 -0
  21. package/dist/Actor.js.map +1 -0
  22. package/dist/Audition.d.ts +17 -0
  23. package/dist/Audition.js +29 -0
  24. package/dist/Audition.js.map +1 -0
  25. package/dist/Client.d.ts +46 -0
  26. package/dist/Client.js +228 -0
  27. package/dist/Client.js.map +1 -0
  28. package/dist/ClientHandle.d.ts +17 -0
  29. package/dist/ClientHandle.js +10 -0
  30. package/dist/ClientHandle.js.map +1 -0
  31. package/dist/F.d.ts +4 -0
  32. package/dist/F.js +2 -0
  33. package/dist/F.js.map +1 -0
  34. package/dist/Method.d.ts +22 -0
  35. package/dist/Method.js +4 -0
  36. package/dist/Method.js.map +1 -0
  37. package/dist/Protocol.d.ts +53 -0
  38. package/dist/Protocol.js +37 -0
  39. package/dist/Protocol.js.map +1 -0
  40. package/dist/Send.d.ts +2 -0
  41. package/dist/Send.js +2 -0
  42. package/dist/Send.js.map +1 -0
  43. package/dist/_constants.d.ts +1 -0
  44. package/dist/_constants.js +2 -0
  45. package/dist/_constants.js.map +1 -0
  46. package/dist/_util/Diagnostic.d.ts +5 -0
  47. package/dist/_util/Diagnostic.js +10 -0
  48. package/dist/_util/Diagnostic.js.map +1 -0
  49. package/dist/_util/Mutex.d.ts +7 -0
  50. package/dist/_util/Mutex.js +9 -0
  51. package/dist/_util/Mutex.js.map +1 -0
  52. package/dist/_util/phantom.d.ts +3 -0
  53. package/dist/_util/phantom.js +2 -0
  54. package/dist/_util/phantom.js.map +1 -0
  55. package/dist/errors.d.ts +23 -0
  56. package/dist/errors.js +15 -0
  57. package/dist/errors.js.map +1 -0
  58. package/dist/experimental/BranchLive.d.ts +3 -0
  59. package/dist/experimental/BranchLive.js +5 -0
  60. package/dist/experimental/BranchLive.js.map +1 -0
  61. package/dist/experimental/L/L.d.ts +11 -0
  62. package/dist/experimental/L/L.js +12 -0
  63. package/dist/experimental/L/L.js.map +1 -0
  64. package/dist/experimental/L/append.d.ts +3 -0
  65. package/dist/experimental/L/append.js +4 -0
  66. package/dist/experimental/L/append.js.map +1 -0
  67. package/dist/experimental/L/assistant.d.ts +3 -0
  68. package/dist/experimental/L/assistant.js +13 -0
  69. package/dist/experimental/L/assistant.js.map +1 -0
  70. package/dist/experimental/L/assistantSchema.d.ts +3 -0
  71. package/dist/experimental/L/assistantSchema.js +13 -0
  72. package/dist/experimental/L/assistantSchema.js.map +1 -0
  73. package/dist/experimental/L/assistantStream.d.ts +3 -0
  74. package/dist/experimental/L/assistantStream.js +5 -0
  75. package/dist/experimental/L/assistantStream.js.map +1 -0
  76. package/dist/experimental/L/branch.d.ts +2 -0
  77. package/dist/experimental/L/branch.js +4 -0
  78. package/dist/experimental/L/branch.js.map +1 -0
  79. package/dist/experimental/L/clear.d.ts +3 -0
  80. package/dist/experimental/L/clear.js +7 -0
  81. package/dist/experimental/L/clear.js.map +1 -0
  82. package/dist/experimental/L/history.d.ts +3 -0
  83. package/dist/experimental/L/history.js +4 -0
  84. package/dist/experimental/L/history.js.map +1 -0
  85. package/dist/experimental/L/init.d.ts +3 -0
  86. package/dist/experimental/L/init.js +4 -0
  87. package/dist/experimental/L/init.js.map +1 -0
  88. package/dist/experimental/L/matrix.d.ts +10 -0
  89. package/dist/experimental/L/matrix.js +6 -0
  90. package/dist/experimental/L/matrix.js.map +1 -0
  91. package/dist/experimental/L/system.d.ts +1 -0
  92. package/dist/experimental/L/system.js +4 -0
  93. package/dist/experimental/L/system.js.map +1 -0
  94. package/dist/experimental/L/user.d.ts +1 -0
  95. package/dist/experimental/L/user.js +6 -0
  96. package/dist/experimental/L/user.js.map +1 -0
  97. package/dist/experimental/Loader.d.ts +16 -0
  98. package/dist/experimental/Loader.js +20 -0
  99. package/dist/experimental/Loader.js.map +1 -0
  100. package/dist/experimental/TaggedTemplateFunction.d.ts +11 -0
  101. package/dist/experimental/TaggedTemplateFunction.js +14 -0
  102. package/dist/experimental/TaggedTemplateFunction.js.map +1 -0
  103. package/dist/experimental/Template.d.ts +28 -0
  104. package/dist/experimental/Template.js +60 -0
  105. package/dist/experimental/Template.js.map +1 -0
  106. package/dist/experimental/index.d.ts +4 -0
  107. package/dist/experimental/index.js +5 -0
  108. package/dist/experimental/index.js.map +1 -0
  109. package/dist/index.d.ts +9 -7
  110. package/dist/index.js +9 -7
  111. package/dist/index.js.map +1 -1
  112. package/dist/tsconfig.tsbuildinfo +1 -1
  113. package/errors.ts +22 -0
  114. package/experimental/BranchLive.ts +6 -0
  115. package/experimental/L/L.ts +11 -0
  116. package/experimental/L/append.ts +12 -0
  117. package/experimental/L/assistant.ts +16 -0
  118. package/experimental/L/assistantSchema.ts +18 -0
  119. package/experimental/L/assistantStream.ts +9 -0
  120. package/experimental/L/branch.ts +5 -0
  121. package/experimental/L/clear.ts +7 -0
  122. package/experimental/L/history.ts +4 -0
  123. package/experimental/L/init.ts +4 -0
  124. package/experimental/L/matrix.ts +26 -0
  125. package/experimental/L/system.ts +5 -0
  126. package/experimental/L/user.ts +10 -0
  127. package/experimental/Loader.ts +35 -0
  128. package/experimental/TaggedTemplateFunction.ts +44 -0
  129. package/experimental/Template.ts +85 -0
  130. package/experimental/index.ts +4 -0
  131. package/index.ts +9 -7
  132. package/package.json +17 -30
  133. package/tsconfig.json +9 -0
  134. package/Digest.ts +0 -30
  135. package/Envelope.ts +0 -16
  136. package/F/F.ts +0 -1
  137. package/L/L.ts +0 -20
  138. package/L/append.ts +0 -14
  139. package/L/assistant.ts +0 -30
  140. package/L/assistantSchema.ts +0 -61
  141. package/L/assistantStream.ts +0 -22
  142. package/L/branch.ts +0 -20
  143. package/L/clear.ts +0 -14
  144. package/L/disable.ts +0 -13
  145. package/L/enable.ts +0 -24
  146. package/L/events.ts +0 -11
  147. package/L/json.ts +0 -12
  148. package/L/line.ts +0 -22
  149. package/L/listen.ts +0 -26
  150. package/L/messages.ts +0 -10
  151. package/L/prev.ts +0 -4
  152. package/L/provide.ts +0 -10
  153. package/L/self.ts +0 -5
  154. package/L/send.ts +0 -56
  155. package/L/system.ts +0 -25
  156. package/L/thread.ts +0 -16
  157. package/L/toolkit.ts +0 -14
  158. package/L/user.test.ts +0 -33
  159. package/L/user.ts +0 -32
  160. package/LEvent.ts +0 -33
  161. package/Thread.ts +0 -67
  162. package/dist/Digest.d.ts +0 -17
  163. package/dist/Digest.js +0 -7
  164. package/dist/Digest.js.map +0 -1
  165. package/dist/Envelope.d.ts +0 -13
  166. package/dist/Envelope.js +0 -2
  167. package/dist/Envelope.js.map +0 -1
  168. package/dist/F/F.d.ts +0 -1
  169. package/dist/F/F.js +0 -2
  170. package/dist/F/F.js.map +0 -1
  171. package/dist/L/L.d.ts +0 -20
  172. package/dist/L/L.js +0 -21
  173. package/dist/L/L.js.map +0 -1
  174. package/dist/L/append.d.ts +0 -5
  175. package/dist/L/append.js +0 -10
  176. package/dist/L/append.js.map +0 -1
  177. package/dist/L/assistant.d.ts +0 -6
  178. package/dist/L/assistant.js +0 -26
  179. package/dist/L/assistant.js.map +0 -1
  180. package/dist/L/assistantSchema.d.ts +0 -13
  181. package/dist/L/assistantSchema.js +0 -44
  182. package/dist/L/assistantSchema.js.map +0 -1
  183. package/dist/L/assistantStream.d.ts +0 -7
  184. package/dist/L/assistantStream.js +0 -17
  185. package/dist/L/assistantStream.js.map +0 -1
  186. package/dist/L/branch.d.ts +0 -3
  187. package/dist/L/branch.js +0 -19
  188. package/dist/L/branch.js.map +0 -1
  189. package/dist/L/clear.d.ts +0 -5
  190. package/dist/L/clear.js +0 -12
  191. package/dist/L/clear.js.map +0 -1
  192. package/dist/L/disable.d.ts +0 -4
  193. package/dist/L/disable.js +0 -10
  194. package/dist/L/disable.js.map +0 -1
  195. package/dist/L/enable.d.ts +0 -5
  196. package/dist/L/enable.js +0 -13
  197. package/dist/L/enable.js.map +0 -1
  198. package/dist/L/events.d.ts +0 -5
  199. package/dist/L/events.js +0 -6
  200. package/dist/L/events.js.map +0 -1
  201. package/dist/L/json.d.ts +0 -5
  202. package/dist/L/json.js +0 -8
  203. package/dist/L/json.js.map +0 -1
  204. package/dist/L/line.d.ts +0 -5
  205. package/dist/L/line.js +0 -11
  206. package/dist/L/line.js.map +0 -1
  207. package/dist/L/listen.d.ts +0 -7
  208. package/dist/L/listen.js +0 -14
  209. package/dist/L/listen.js.map +0 -1
  210. package/dist/L/messages.d.ts +0 -5
  211. package/dist/L/messages.js +0 -5
  212. package/dist/L/messages.js.map +0 -1
  213. package/dist/L/prev.d.ts +0 -5
  214. package/dist/L/prev.js +0 -5
  215. package/dist/L/prev.js.map +0 -1
  216. package/dist/L/provide.d.ts +0 -3
  217. package/dist/L/provide.js +0 -4
  218. package/dist/L/provide.js.map +0 -1
  219. package/dist/L/self.d.ts +0 -3
  220. package/dist/L/self.js +0 -4
  221. package/dist/L/self.js.map +0 -1
  222. package/dist/L/send.d.ts +0 -6
  223. package/dist/L/send.js +0 -34
  224. package/dist/L/send.js.map +0 -1
  225. package/dist/L/system.d.ts +0 -5
  226. package/dist/L/system.js +0 -14
  227. package/dist/L/system.js.map +0 -1
  228. package/dist/L/thread.d.ts +0 -3
  229. package/dist/L/thread.js +0 -15
  230. package/dist/L/thread.js.map +0 -1
  231. package/dist/L/toolkit.d.ts +0 -4
  232. package/dist/L/toolkit.js +0 -9
  233. package/dist/L/toolkit.js.map +0 -1
  234. package/dist/L/user.d.ts +0 -6
  235. package/dist/L/user.js +0 -13
  236. package/dist/L/user.js.map +0 -1
  237. package/dist/L/user.test.d.ts +0 -1
  238. package/dist/L/user.test.js.map +0 -1
  239. package/dist/LEvent.d.ts +0 -154
  240. package/dist/LEvent.js +0 -19
  241. package/dist/LEvent.js.map +0 -1
  242. package/dist/Thread.d.ts +0 -52
  243. package/dist/Thread.js +0 -32
  244. package/dist/Thread.js.map +0 -1
  245. package/dist/patterns/Debate.d.ts +0 -1
  246. package/dist/patterns/Debate.js +0 -3
  247. package/dist/patterns/Debate.js.map +0 -1
  248. package/dist/patterns/Model.d.ts +0 -6
  249. package/dist/patterns/Model.js +0 -14
  250. package/dist/patterns/Model.js.map +0 -1
  251. package/dist/patterns/Route.d.ts +0 -3
  252. package/dist/patterns/Route.js +0 -14
  253. package/dist/patterns/Route.js.map +0 -1
  254. package/dist/util/JsonValue.d.ts +0 -8
  255. package/dist/util/JsonValue.js +0 -109
  256. package/dist/util/JsonValue.js.map +0 -1
  257. package/dist/util/NeverTool.d.ts +0 -3
  258. package/dist/util/NeverTool.js +0 -3
  259. package/dist/util/NeverTool.js.map +0 -1
  260. package/dist/util/Taggable.d.ts +0 -6
  261. package/dist/util/Taggable.js +0 -13
  262. package/dist/util/Taggable.js.map +0 -1
  263. package/dist/util/extract.d.ts +0 -3
  264. package/dist/util/extract.js +0 -2
  265. package/dist/util/extract.js.map +0 -1
  266. package/dist/util/messageCodec.d.ts +0 -98
  267. package/dist/util/messageCodec.js +0 -5
  268. package/dist/util/messageCodec.js.map +0 -1
  269. package/dist/util/normalizeRaw.d.ts +0 -4
  270. package/dist/util/normalizeRaw.js +0 -75
  271. package/dist/util/normalizeRaw.js.map +0 -1
  272. package/dist/util/prefix.d.ts +0 -1
  273. package/dist/util/prefix.js +0 -2
  274. package/dist/util/prefix.js.map +0 -1
  275. package/dist/util/raw.d.ts +0 -6
  276. package/dist/util/raw.js +0 -5
  277. package/dist/util/raw.js.map +0 -1
  278. package/patterns/Debate.ts +0 -2
  279. package/patterns/Model.ts +0 -29
  280. package/patterns/Route.ts +0 -25
  281. package/util/JsonValue.ts +0 -144
  282. package/util/NeverTool.ts +0 -10
  283. package/util/Taggable.ts +0 -33
  284. package/util/extract.ts +0 -7
  285. package/util/messageCodec.ts +0 -5
  286. package/util/normalizeRaw.ts +0 -93
  287. package/util/prefix.ts +0 -1
  288. package/util/raw.ts +0 -27
package/Accumulator.ts ADDED
@@ -0,0 +1,103 @@
1
+ import { Deferred, Types, Option, Ref, PubSub, Stream, Effect, Context, Layer, Semaphore } from "effect"
2
+
3
+ import * as Diagnostic from "./_util/Diagnostic.ts"
4
+
5
+ const { debug } = Diagnostic.module("Accumulator")
6
+
7
+ const TypeId = "~liminal/Accumulator" as const
8
+
9
+ export interface Service<State> {
10
+ readonly ref: Ref.Ref<State>
11
+
12
+ readonly pubsub: PubSub.PubSub<State>
13
+ }
14
+
15
+ export interface AccumulatorLayerConfig<Item, E, R, State, E2, R2, E3, R3> {
16
+ readonly source: Stream.Stream<Item, E, R>
17
+
18
+ readonly reduce: (item: Item) => (state: State) => Effect.Effect<State, E2, R2>
19
+
20
+ readonly initial: (item: Item) => Effect.Effect<Option.Option<State>, E3, R3>
21
+ }
22
+
23
+ export type Reduce<State, Item, K extends Types.Tags<Item> = Types.Tags<Item>, E = never, R = never> = (
24
+ item: Types.ExtractTag<Item, K>,
25
+ ) => (accumulator: State) => Effect.Effect<State, E, R>
26
+
27
+ export interface Accumulator<Self, Id extends string, State> extends Context.Service<Self, Service<State>> {
28
+ new (_: never): Context.ServiceClass.Shape<Id, Service<State>>
29
+
30
+ readonly [TypeId]: typeof TypeId
31
+
32
+ readonly get: Effect.Effect<State, never, Self>
33
+
34
+ readonly stream: Stream.Stream<State, never, Self>
35
+
36
+ readonly reducer: <Item>() => <K extends Types.Tags<Item>, E, R>(
37
+ _tag: K,
38
+ f: Reduce<State, Item, K, E, R>,
39
+ ) => Reduce<State, Item, K, E, R>
40
+
41
+ readonly layer: <Item, E, R, E2, R2, E3, R3>(
42
+ config: AccumulatorLayerConfig<Item, E, R, State, E2, R2, E3, R3>,
43
+ ) => Layer.Layer<Self, E | E2 | E3, R | R2 | R3>
44
+ }
45
+
46
+ export const Service =
47
+ <Self, State>() =>
48
+ <Id extends string>(id: Id): Accumulator<Self, Id, State> => {
49
+ const tag = Context.Service<Self, Service<State>>()(id)
50
+
51
+ const get = tag.asEffect().pipe(
52
+ Effect.map(({ ref }) => ref),
53
+ Effect.flatMap(Ref.get),
54
+ )
55
+
56
+ const stream = tag.asEffect().pipe(
57
+ Effect.map(({ pubsub }) => Stream.fromPubSub(pubsub)),
58
+ Stream.unwrap,
59
+ )
60
+
61
+ const reducer =
62
+ <Item>() =>
63
+ <K extends Types.Tags<Item>, E, R>(_tag: K, f: Reduce<State, Item, K, E, R>): Reduce<State, Item, K, E, R> =>
64
+ f
65
+
66
+ const layer = <Item, E, R, E2, R2, E3, R3>({
67
+ source,
68
+ initial,
69
+ reduce,
70
+ }: AccumulatorLayerConfig<Item, E, R, State, E2, R2, E3, R3>): Layer.Layer<Self, E | E2 | E3, R | R2 | R3> =>
71
+ Effect.gen(function* () {
72
+ const semaphore = yield* Semaphore.make(1)
73
+ const deferred = yield* Deferred.make<State>()
74
+ const pubsub = yield* PubSub.unbounded<State>({ replay: 1 })
75
+ yield* source.pipe(
76
+ Stream.runForEach(
77
+ Effect.fn(function* (item) {
78
+ if (!(yield* Deferred.isDone(deferred))) {
79
+ const match = yield* initial(item)
80
+ if (Option.isSome(match)) {
81
+ const { value } = match
82
+ yield* Deferred.succeed(deferred, value)
83
+ yield* debug("InitializedState", { state: value })
84
+ }
85
+ return
86
+ }
87
+ const current = yield* Ref.get(ref)
88
+ const reduced = yield* reduce(item)(current)
89
+ yield* Ref.set(ref, reduced)
90
+ yield* PubSub.publish(pubsub, reduced)
91
+ yield* debug("ReducedState", { item, previous: current, current: reduced })
92
+ }, semaphore.withPermits(1)),
93
+ ),
94
+ Effect.forkScoped,
95
+ )
96
+ const initial_ = yield* Deferred.await(deferred)
97
+ const ref = yield* Ref.make(initial_)
98
+ yield* PubSub.publish(pubsub, initial_)
99
+ return { ref, pubsub }
100
+ }).pipe(Layer.effect(tag))
101
+
102
+ return Object.assign(tag, { [TypeId]: TypeId, get, stream, reducer, layer })
103
+ }
package/Actor.ts ADDED
@@ -0,0 +1,124 @@
1
+ import { Context, Schema as S, Effect } from "effect"
2
+
3
+ import type * as ActorClient from "./Client.ts"
4
+ import type * as ClientHandle from "./ClientHandle.ts"
5
+ import type { MethodDefinition } from "./Method.ts"
6
+ import type { Send } from "./Send.ts"
7
+
8
+ import * as Diagnostic from "./_util/Diagnostic.ts"
9
+ import * as Method from "./Method.ts"
10
+
11
+ const { span } = Diagnostic.module("Actor")
12
+
13
+ export const TypeId = "~liminal/Actor" as const
14
+
15
+ export interface Service<
16
+ ActorSelf,
17
+ NameA,
18
+ AttachmentFields extends S.Struct.Fields,
19
+ EventDefinitions extends Record<string, S.Struct.Fields>,
20
+ > {
21
+ readonly name: NameA
22
+
23
+ readonly currentClient: ClientHandle.ClientHandle<ActorSelf, AttachmentFields, EventDefinitions>
24
+
25
+ readonly clients: ReadonlySet<ClientHandle.ClientHandle<ActorSelf, AttachmentFields, EventDefinitions>>
26
+ }
27
+
28
+ export interface ActorDefinition<
29
+ NameA,
30
+ AttachmentFields extends S.Struct.Fields,
31
+ ClientSelf,
32
+ ClientId extends string,
33
+ MethodDefinitions extends Record<string, MethodDefinition.Any>,
34
+ EventDefinitions extends Record<string, S.Struct.Fields>,
35
+ > {
36
+ readonly name: S.Codec<NameA, string>
37
+
38
+ readonly attachments: AttachmentFields
39
+
40
+ readonly client: ActorClient.Client<ClientSelf, ClientId, MethodDefinitions, EventDefinitions>
41
+ }
42
+
43
+ export interface Actor<
44
+ ActorSelf,
45
+ ActorId extends string,
46
+ NameA,
47
+ AttachmentFields extends S.Struct.Fields,
48
+ ActorClientSelf,
49
+ ActorClientId extends string,
50
+ MethodDefinitions extends Record<string, MethodDefinition.Any>,
51
+ EventDefinitions extends Record<string, S.Struct.Fields>,
52
+ > extends Context.Service<ActorSelf, Service<ActorSelf, NameA, AttachmentFields, EventDefinitions>> {
53
+ new (_: never): Context.ServiceClass.Shape<ActorId, Service<ActorSelf, NameA, AttachmentFields, EventDefinitions>>
54
+
55
+ readonly [TypeId]: typeof TypeId
56
+
57
+ readonly definition: ActorDefinition<
58
+ NameA,
59
+ AttachmentFields,
60
+ ActorClientSelf,
61
+ ActorClientId,
62
+ MethodDefinitions,
63
+ EventDefinitions
64
+ >
65
+
66
+ readonly schema: {
67
+ readonly attachments: S.Codec<S.Struct<AttachmentFields>["Type"], S.Struct<AttachmentFields>["Encoded"]>
68
+ }
69
+
70
+ readonly sendAll: Send<ActorSelf, EventDefinitions>
71
+
72
+ readonly disconnectAll: Effect.Effect<void, never, ActorSelf>
73
+
74
+ readonly handler: <K extends keyof MethodDefinitions, R>(
75
+ tag: K,
76
+ f: Method.Handler<MethodDefinitions[K], R>,
77
+ ) => Method.Handler<MethodDefinitions[K], R>
78
+ }
79
+
80
+ export const Service =
81
+ <ActorSelf>() =>
82
+ <
83
+ ActorId extends string,
84
+ NameA,
85
+ AttachmentFields extends S.Struct.Fields,
86
+ ClientSelf,
87
+ ClientId extends string,
88
+ MethodDefinitions extends Record<string, MethodDefinition.Any>,
89
+ EventDefinitions extends Record<string, S.Struct.Fields>,
90
+ >(
91
+ id: ActorId,
92
+ definition: ActorDefinition<NameA, AttachmentFields, ClientSelf, ClientId, MethodDefinitions, EventDefinitions>,
93
+ ): Actor<ActorSelf, ActorId, NameA, AttachmentFields, ClientSelf, ClientId, MethodDefinitions, EventDefinitions> => {
94
+ const tag = Context.Service<ActorSelf, Service<ActorSelf, NameA, AttachmentFields, EventDefinitions>>()(id)
95
+
96
+ const sendAll: Send<ActorSelf, EventDefinitions> = (key, payload) =>
97
+ tag.asEffect().pipe(
98
+ Effect.flatMap(({ clients }) =>
99
+ Effect.forEach(clients, (client) => client.send(key, payload), { concurrency: "unbounded" }),
100
+ ),
101
+ span("sendAll"),
102
+ )
103
+
104
+ const disconnectAll = tag.asEffect().pipe(
105
+ Effect.flatMap(({ clients }) => Effect.forEach(clients, ({ disconnect }) => disconnect)),
106
+ span("disconnectAll"),
107
+ )
108
+
109
+ const handler = <K extends keyof MethodDefinitions, R>(
110
+ _tag: K,
111
+ f: Method.Handler<MethodDefinitions[K], R>,
112
+ ): Method.Handler<MethodDefinitions[K], R> => f
113
+
114
+ return Object.assign(tag, {
115
+ [TypeId]: TypeId,
116
+ definition,
117
+ schema: {
118
+ attachments: S.Struct(definition.attachments) as never,
119
+ },
120
+ sendAll,
121
+ disconnectAll,
122
+ handler,
123
+ })
124
+ }
package/Audition.ts ADDED
@@ -0,0 +1,110 @@
1
+ import { Schema as S, Pipeable, Stream, Effect, Function } from "effect"
2
+
3
+ import type { F } from "./F.ts"
4
+ import type * as Method from "./Method.ts"
5
+
6
+ import * as Diagnostic from "./_util/Diagnostic.ts"
7
+ import * as Client from "./Client.ts"
8
+ import { type ClientError, AuditionError } from "./errors.ts"
9
+
10
+ const { debug, span } = Diagnostic.module("Audition")
11
+
12
+ const TypeId = "~liminal/Audition" as const
13
+
14
+ export interface Audition<ClientSelf, MethodDefinitions extends Record<string, Method.MethodDefinition.Any>, Event>
15
+ extends Pipeable.Pipeable {
16
+ readonly [TypeId]: typeof TypeId
17
+
18
+ readonly events: Stream.Stream<Event, ClientError, ClientSelf>
19
+
20
+ readonly f: F<ClientSelf, MethodDefinitions>
21
+ }
22
+
23
+ export const empty: Audition<never, never, never> = {
24
+ [TypeId]: TypeId,
25
+ pipe() {
26
+ return Pipeable.pipeArguments(this, arguments)
27
+ },
28
+ events: Stream.fail(new AuditionError()),
29
+ f: () => () => new AuditionError().asEffect(),
30
+ }
31
+
32
+ export const add: {
33
+ <
34
+ ClientSelf,
35
+ ClientId extends string,
36
+ ClientMethodDefinitions extends Record<string, Method.MethodDefinition.Any>,
37
+ ClientEventDefinitions extends Record<string, S.Struct.Fields>,
38
+ >(
39
+ client: Client.Client<ClientSelf, ClientId, ClientMethodDefinitions, ClientEventDefinitions>,
40
+ ): <AuditionSelf, AuditionMethodDefinitions extends Record<string, Method.MethodDefinition.Any>, AuditionEvent>(
41
+ audition: Audition<AuditionSelf, AuditionMethodDefinitions, AuditionEvent>,
42
+ ) => Audition<
43
+ AuditionSelf | ClientSelf,
44
+ Method.MethodDefinition.Merge<AuditionMethodDefinitions, ClientMethodDefinitions>,
45
+ AuditionEvent | ReturnType<typeof S.TaggedUnion<ClientEventDefinitions>>["Type"]
46
+ >
47
+ <
48
+ AuditionClientSelf,
49
+ AuditionMethodDefinitions extends Record<string, Method.MethodDefinition.Any>,
50
+ AuditionEvent,
51
+ ClientSelf,
52
+ ClientId extends string,
53
+ ClientMethodDefinitions extends Record<string, Method.MethodDefinition.Any>,
54
+ ClientEventDefinitions extends Record<string, S.Struct.Fields>,
55
+ >(
56
+ audition: Audition<AuditionClientSelf, AuditionMethodDefinitions, AuditionEvent>,
57
+ client: Client.Client<ClientSelf, ClientId, ClientMethodDefinitions, ClientEventDefinitions>,
58
+ ): Audition<
59
+ AuditionClientSelf | ClientSelf,
60
+ Method.MethodDefinition.Merge<AuditionMethodDefinitions, ClientMethodDefinitions>,
61
+ AuditionEvent | ReturnType<typeof S.TaggedUnion<ClientEventDefinitions>>["Type"]
62
+ >
63
+ } = Function.dual(
64
+ 2,
65
+ <
66
+ AuditionSelf,
67
+ AuditionMethodDefinitions extends Record<string, Method.MethodDefinition.Any>,
68
+ AuditionEvent,
69
+ ClientSelf,
70
+ ClientId extends string,
71
+ ClientMethodDefinitions extends Record<string, Method.MethodDefinition.Any>,
72
+ ClientEventDefinitions extends Record<string, S.Struct.Fields>,
73
+ >(
74
+ audition: Audition<AuditionSelf, AuditionMethodDefinitions, AuditionEvent>,
75
+ client: Client.Client<ClientSelf, ClientId, ClientMethodDefinitions, ClientEventDefinitions>,
76
+ ): Audition<
77
+ AuditionSelf | ClientSelf,
78
+ Method.MethodDefinition.Merge<AuditionMethodDefinitions, ClientMethodDefinitions>,
79
+ AuditionEvent | ReturnType<typeof S.TaggedUnion<ClientEventDefinitions>>["Type"]
80
+ > => {
81
+ const f: F<
82
+ AuditionSelf | ClientSelf,
83
+ Method.MethodDefinition.Merge<AuditionMethodDefinitions, ClientMethodDefinitions>
84
+ > = (method) => (payload) =>
85
+ audition
86
+ .f(method as never)(payload)
87
+ .pipe(
88
+ Effect.catchTag("AuditionError", () => client.f(method as never)(payload)),
89
+ span("f"),
90
+ )
91
+
92
+ const events = audition.events.pipe(
93
+ Stream.catchTag("AuditionError", () =>
94
+ Effect.succeed(client.events).pipe(
95
+ Effect.tap(() => debug("AuditionStaged", { client: client.key })),
96
+ Stream.unwrap,
97
+ ),
98
+ ),
99
+ )
100
+
101
+ return {
102
+ [TypeId]: TypeId,
103
+ pipe() {
104
+ return Pipeable.pipeArguments(this, arguments)
105
+ },
106
+ events,
107
+ f,
108
+ }
109
+ },
110
+ )
package/CHANGELOG.md CHANGED
@@ -1,217 +1,13 @@
1
1
  # liminal
2
2
 
3
- ## 0.17.0
4
-
5
- ### Minor Changes
6
-
7
- - 8212083: Refactor L.sequence -> L.line. Decouple thread effects from the providing of effects via L.provide.
8
-
9
- ## 0.16.0
10
-
11
- ### Minor Changes
12
-
13
- - 2e96076: Refactoring "strands" into "threads", which can provide a handle with which to operate on the thread context outside of the thread's sequencers arguments.
14
-
15
- ## 0.15.0
16
-
17
- ### Minor Changes
18
-
19
- - 3b4ec1a: - Instead of providing `AiToolkit` to `L.enable`/`L.disable`, we now provide tools directly.
20
- - Also includes the beginnings of a `coalesceModels` pattern.
21
-
22
- ## 0.14.0
23
-
24
- ### Minor Changes
25
-
26
- - e7006b7: Implement tool enablement and disablement.
27
-
28
- ## 0.13.0
29
-
30
- ### Minor Changes
31
-
32
- - 0e4954e: Rename `L.assistantStruct` to `L.assistantSchema`, is it now supports all schemas, not just struct schemas. Template tag calls are properly dedented and normalized. Additionally, `L.userJson` now uses the optional schema to JSONC-encode with description annotations as comments on corresponding fields.
33
-
34
- ## 0.12.1
35
-
36
- ### Patch Changes
37
-
38
- - 6df720c: Fix NPM publish.
39
-
40
- ## 0.12.0
41
-
42
- ### Minor Changes
43
-
44
- - a04ae8b: Introduce L.handle / rework strand event-handling mechanism.
45
-
46
- ## 0.11.1
47
-
48
- ### Patch Changes
49
-
50
- - feee30f: Testing provenance capture in changeset-driven publishes.
51
-
52
- ## 0.11.0
53
-
54
- ### Minor Changes
55
-
56
- - 48aa187: Rework mechanism of denoting strand boundary.
57
-
58
- ## 0.10.0
59
-
60
- ### Minor Changes
61
-
62
- - 866e64a: Redesigning much of the API.
63
-
64
- ## 0.9.0
65
-
66
- ### Minor Changes
67
-
68
- - df8861a: Separate L.assistant into L.assistantText and L.assistantStruct.
69
-
70
- ## 0.8.0
71
-
72
- ### Minor Changes
73
-
74
- - bf980fb: Major redesign of the Liminal API to be more effect-idiomatic.
75
-
76
- ## 0.7.0
77
-
78
- ### Minor Changes
79
-
80
- - d6fe173: Remove approach to passing handlers to strands.
81
-
82
- ## 0.6.0
83
-
84
- ### Minor Changes
85
-
86
- - e88b9af: Rewrite using Effect-TS.
87
-
88
- ## 0.5.17
89
-
90
- ### Patch Changes
91
-
92
- - 5c421c8: Re-add string dedenting for template-fn-style usage of user, system and schema.
93
-
94
- ## 0.5.16
95
-
96
- ### Patch Changes
97
-
98
- - 6e70190: Renaming Model to Adapter and L.model to L.focus
99
-
100
- ## 0.5.15
101
-
102
- ### Patch Changes
103
-
104
- - 9c276c3: Fix message list cloning, add streaming to ollama adapter.
105
-
106
- ## 0.5.14
107
-
108
- ### Patch Changes
109
-
110
- - d12049c: Fix L.run return type. Add L.<type> for JSON-schema building.
111
-
112
- ## 0.5.13
113
-
114
- ### Patch Changes
115
-
116
- - bbd0e74: Liminal schema and util now exist within the liminal package itself. Runtime type compatibility changes.
117
-
118
- ## 0.5.12
119
-
120
- ### Patch Changes
121
-
122
- - 4808a57: Fix handling of standalone iterables supplied to L.strand. Also introduce strandard, a standard library of strands.
123
- - Updated dependencies [4808a57]
124
- - liminal-util@0.0.7
125
-
126
- ## 0.5.11
127
-
128
- ### Patch Changes
129
-
130
- - cf42ed2: Agent -> Strand. Making the API more uniform. Ie. Agent -> L.strand. L.branch -> L.strand.
131
- - Updated dependencies [cf42ed2]
132
- - liminal-schema@0.0.5
133
- - liminal-util@0.0.6
134
-
135
- ## 0.5.10
136
-
137
- ### Patch Changes
138
-
139
- - aef5564: Update Model interface to support streaming. Improve event-related functionality and emit fiber-related events.
140
- - Updated dependencies [aef5564]
141
- - liminal-schema@0.0.4
142
- - liminal-util@0.0.5
143
-
144
- ## 0.5.9
145
-
146
- ### Patch Changes
147
-
148
- - dbd5e93: Reintroduced tools and various examples.
149
-
150
- ## 0.5.8
151
-
152
- ### Patch Changes
153
-
154
- - 23a24ae: Reintroduce L.catch and clean up parts of the generator runtime.
155
- - f2f360c: Continue to clean up the generator runtime internals.
156
- - Updated dependencies [23a24ae]
157
- - Updated dependencies [f2f360c]
158
- - liminal-schema@0.0.3
159
- - liminal-util@0.0.4
160
-
161
- ## 0.5.7
162
-
163
- ### Patch Changes
164
-
165
- - a56f121: Re-flatten events. Make fiber info available in event handler via this.
166
- - Updated dependencies [a56f121]
167
- - liminal-util@0.0.3
168
-
169
- ## 0.5.6
170
-
171
- ### Patch Changes
172
-
173
- - f79205e: Include fiber information in the event type supplied to user-specified handlers. Continue reworking runtime implementation.
174
-
175
- ## 0.5.5
176
-
177
- ### Patch Changes
178
-
179
- - 43afd27: Fixing misc. bugs and refactoring context management.
180
-
181
- ## 0.5.4
182
-
183
- ### Patch Changes
184
-
185
- - 284adab: Reintroduce AI SDK adapter and begin simplifying runic execution.
186
- - Updated dependencies [284adab]
187
- - liminal-schema@0.0.2
188
- - liminal-util@0.0.2
189
-
190
- ## 0.5.3
191
-
192
- ### Patch Changes
193
-
194
- - 2d3a717: Complete rewrite of Liminal. Includes new packages for various integrations.
195
- - Updated dependencies [2d3a717]
196
- - Updated dependencies [ff04b9f]
197
- - liminal-schema@0.0.1
198
- - liminal-util@0.0.1
199
-
200
- ## 0.5.2
201
-
202
- ### Patch Changes
203
-
204
- - de74823: Various API changes, such as infer as a callable object (the object of which implements Symbol.iterator and yields the actual action). Introduced initial "section" action. Also created an adapter for Ollama.
205
-
206
- ## 0.5.1
3
+ ## 0.17.2
207
4
 
208
5
  ### Patch Changes
209
6
 
210
- - 96339de: Fixing continuous publishing. No other changes contained in this release.
7
+ - 366c080: Migrate to Effect v4.
211
8
 
212
- ## 0.1.1
9
+ ## 0.17.1
213
10
 
214
11
  ### Patch Changes
215
12
 
216
- - 171acfe: Initial publish of Liminal and the Vercel AI adapter library. Still heavily WIP.
217
- More publishes to come!
13
+ - 17342eb: This version marks a complete reimagining of Liminal. More information coming soon.