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.
- package/Accumulator.ts +103 -0
- package/Actor.ts +124 -0
- package/Audition.ts +110 -0
- package/CHANGELOG.md +4 -208
- package/Client.ts +525 -0
- package/ClientHandle.ts +50 -0
- package/F.ts +12 -0
- package/LICENSE +202 -0
- package/Method.ts +37 -0
- package/Protocol.ts +120 -0
- package/Send.ts +12 -0
- package/_constants.ts +1 -0
- package/_util/Diagnostic.ts +16 -0
- package/_util/Mutex.ts +13 -0
- package/_util/phantom.ts +1 -0
- package/dist/Accumulator.d.ts +22 -0
- package/dist/Accumulator.js +37 -0
- package/dist/Accumulator.js.map +1 -0
- package/dist/Actor.d.ts +29 -0
- package/dist/Actor.js +22 -0
- package/dist/Actor.js.map +1 -0
- package/dist/Audition.d.ts +17 -0
- package/dist/Audition.js +29 -0
- package/dist/Audition.js.map +1 -0
- package/dist/Client.d.ts +46 -0
- package/dist/Client.js +228 -0
- package/dist/Client.js.map +1 -0
- package/dist/ClientHandle.d.ts +17 -0
- package/dist/ClientHandle.js +10 -0
- package/dist/ClientHandle.js.map +1 -0
- package/dist/F.d.ts +4 -0
- package/dist/F.js +2 -0
- package/dist/F.js.map +1 -0
- package/dist/Method.d.ts +22 -0
- package/dist/Method.js +4 -0
- package/dist/Method.js.map +1 -0
- package/dist/Protocol.d.ts +53 -0
- package/dist/Protocol.js +37 -0
- package/dist/Protocol.js.map +1 -0
- package/dist/Send.d.ts +2 -0
- package/dist/Send.js +2 -0
- package/dist/Send.js.map +1 -0
- package/dist/_constants.d.ts +1 -0
- package/dist/_constants.js +2 -0
- package/dist/_constants.js.map +1 -0
- package/dist/_util/Diagnostic.d.ts +5 -0
- package/dist/_util/Diagnostic.js +10 -0
- package/dist/_util/Diagnostic.js.map +1 -0
- package/dist/_util/Mutex.d.ts +7 -0
- package/dist/_util/Mutex.js +9 -0
- package/dist/_util/Mutex.js.map +1 -0
- package/dist/_util/phantom.d.ts +3 -0
- package/dist/_util/phantom.js +2 -0
- package/dist/_util/phantom.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -0
- package/dist/experimental/BranchLive.d.ts +3 -0
- package/dist/experimental/BranchLive.js +5 -0
- package/dist/experimental/BranchLive.js.map +1 -0
- package/dist/experimental/L/L.d.ts +11 -0
- package/dist/experimental/L/L.js +12 -0
- package/dist/experimental/L/L.js.map +1 -0
- package/dist/experimental/L/append.d.ts +3 -0
- package/dist/experimental/L/append.js +4 -0
- package/dist/experimental/L/append.js.map +1 -0
- package/dist/experimental/L/assistant.d.ts +3 -0
- package/dist/experimental/L/assistant.js +13 -0
- package/dist/experimental/L/assistant.js.map +1 -0
- package/dist/experimental/L/assistantSchema.d.ts +3 -0
- package/dist/experimental/L/assistantSchema.js +13 -0
- package/dist/experimental/L/assistantSchema.js.map +1 -0
- package/dist/experimental/L/assistantStream.d.ts +3 -0
- package/dist/experimental/L/assistantStream.js +5 -0
- package/dist/experimental/L/assistantStream.js.map +1 -0
- package/dist/experimental/L/branch.d.ts +2 -0
- package/dist/experimental/L/branch.js +4 -0
- package/dist/experimental/L/branch.js.map +1 -0
- package/dist/experimental/L/clear.d.ts +3 -0
- package/dist/experimental/L/clear.js +7 -0
- package/dist/experimental/L/clear.js.map +1 -0
- package/dist/experimental/L/history.d.ts +3 -0
- package/dist/experimental/L/history.js +4 -0
- package/dist/experimental/L/history.js.map +1 -0
- package/dist/experimental/L/init.d.ts +3 -0
- package/dist/experimental/L/init.js +4 -0
- package/dist/experimental/L/init.js.map +1 -0
- package/dist/experimental/L/matrix.d.ts +10 -0
- package/dist/experimental/L/matrix.js +6 -0
- package/dist/experimental/L/matrix.js.map +1 -0
- package/dist/experimental/L/system.d.ts +1 -0
- package/dist/experimental/L/system.js +4 -0
- package/dist/experimental/L/system.js.map +1 -0
- package/dist/experimental/L/user.d.ts +1 -0
- package/dist/experimental/L/user.js +6 -0
- package/dist/experimental/L/user.js.map +1 -0
- package/dist/experimental/Loader.d.ts +16 -0
- package/dist/experimental/Loader.js +20 -0
- package/dist/experimental/Loader.js.map +1 -0
- package/dist/experimental/TaggedTemplateFunction.d.ts +11 -0
- package/dist/experimental/TaggedTemplateFunction.js +14 -0
- package/dist/experimental/TaggedTemplateFunction.js.map +1 -0
- package/dist/experimental/Template.d.ts +28 -0
- package/dist/experimental/Template.js +60 -0
- package/dist/experimental/Template.js.map +1 -0
- package/dist/experimental/index.d.ts +4 -0
- package/dist/experimental/index.js +5 -0
- package/dist/experimental/index.js.map +1 -0
- package/dist/index.d.ts +9 -7
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/errors.ts +22 -0
- package/experimental/BranchLive.ts +6 -0
- package/experimental/L/L.ts +11 -0
- package/experimental/L/append.ts +12 -0
- package/experimental/L/assistant.ts +16 -0
- package/experimental/L/assistantSchema.ts +18 -0
- package/experimental/L/assistantStream.ts +9 -0
- package/experimental/L/branch.ts +5 -0
- package/experimental/L/clear.ts +7 -0
- package/experimental/L/history.ts +4 -0
- package/experimental/L/init.ts +4 -0
- package/experimental/L/matrix.ts +26 -0
- package/experimental/L/system.ts +5 -0
- package/experimental/L/user.ts +10 -0
- package/experimental/Loader.ts +35 -0
- package/experimental/TaggedTemplateFunction.ts +44 -0
- package/experimental/Template.ts +85 -0
- package/experimental/index.ts +4 -0
- package/index.ts +9 -7
- package/package.json +17 -30
- package/tsconfig.json +9 -0
- package/Digest.ts +0 -30
- package/Envelope.ts +0 -16
- package/F/F.ts +0 -1
- package/L/L.ts +0 -20
- package/L/append.ts +0 -14
- package/L/assistant.ts +0 -30
- package/L/assistantSchema.ts +0 -61
- package/L/assistantStream.ts +0 -22
- package/L/branch.ts +0 -20
- package/L/clear.ts +0 -14
- package/L/disable.ts +0 -13
- package/L/enable.ts +0 -24
- package/L/events.ts +0 -11
- package/L/json.ts +0 -12
- package/L/line.ts +0 -22
- package/L/listen.ts +0 -26
- package/L/messages.ts +0 -10
- package/L/prev.ts +0 -4
- package/L/provide.ts +0 -10
- package/L/self.ts +0 -5
- package/L/send.ts +0 -56
- package/L/system.ts +0 -25
- package/L/thread.ts +0 -16
- package/L/toolkit.ts +0 -14
- package/L/user.test.ts +0 -33
- package/L/user.ts +0 -32
- package/LEvent.ts +0 -33
- package/Thread.ts +0 -67
- package/dist/Digest.d.ts +0 -17
- package/dist/Digest.js +0 -7
- package/dist/Digest.js.map +0 -1
- package/dist/Envelope.d.ts +0 -13
- package/dist/Envelope.js +0 -2
- package/dist/Envelope.js.map +0 -1
- package/dist/F/F.d.ts +0 -1
- package/dist/F/F.js +0 -2
- package/dist/F/F.js.map +0 -1
- package/dist/L/L.d.ts +0 -20
- package/dist/L/L.js +0 -21
- package/dist/L/L.js.map +0 -1
- package/dist/L/append.d.ts +0 -5
- package/dist/L/append.js +0 -10
- package/dist/L/append.js.map +0 -1
- package/dist/L/assistant.d.ts +0 -6
- package/dist/L/assistant.js +0 -26
- package/dist/L/assistant.js.map +0 -1
- package/dist/L/assistantSchema.d.ts +0 -13
- package/dist/L/assistantSchema.js +0 -44
- package/dist/L/assistantSchema.js.map +0 -1
- package/dist/L/assistantStream.d.ts +0 -7
- package/dist/L/assistantStream.js +0 -17
- package/dist/L/assistantStream.js.map +0 -1
- package/dist/L/branch.d.ts +0 -3
- package/dist/L/branch.js +0 -19
- package/dist/L/branch.js.map +0 -1
- package/dist/L/clear.d.ts +0 -5
- package/dist/L/clear.js +0 -12
- package/dist/L/clear.js.map +0 -1
- package/dist/L/disable.d.ts +0 -4
- package/dist/L/disable.js +0 -10
- package/dist/L/disable.js.map +0 -1
- package/dist/L/enable.d.ts +0 -5
- package/dist/L/enable.js +0 -13
- package/dist/L/enable.js.map +0 -1
- package/dist/L/events.d.ts +0 -5
- package/dist/L/events.js +0 -6
- package/dist/L/events.js.map +0 -1
- package/dist/L/json.d.ts +0 -5
- package/dist/L/json.js +0 -8
- package/dist/L/json.js.map +0 -1
- package/dist/L/line.d.ts +0 -5
- package/dist/L/line.js +0 -11
- package/dist/L/line.js.map +0 -1
- package/dist/L/listen.d.ts +0 -7
- package/dist/L/listen.js +0 -14
- package/dist/L/listen.js.map +0 -1
- package/dist/L/messages.d.ts +0 -5
- package/dist/L/messages.js +0 -5
- package/dist/L/messages.js.map +0 -1
- package/dist/L/prev.d.ts +0 -5
- package/dist/L/prev.js +0 -5
- package/dist/L/prev.js.map +0 -1
- package/dist/L/provide.d.ts +0 -3
- package/dist/L/provide.js +0 -4
- package/dist/L/provide.js.map +0 -1
- package/dist/L/self.d.ts +0 -3
- package/dist/L/self.js +0 -4
- package/dist/L/self.js.map +0 -1
- package/dist/L/send.d.ts +0 -6
- package/dist/L/send.js +0 -34
- package/dist/L/send.js.map +0 -1
- package/dist/L/system.d.ts +0 -5
- package/dist/L/system.js +0 -14
- package/dist/L/system.js.map +0 -1
- package/dist/L/thread.d.ts +0 -3
- package/dist/L/thread.js +0 -15
- package/dist/L/thread.js.map +0 -1
- package/dist/L/toolkit.d.ts +0 -4
- package/dist/L/toolkit.js +0 -9
- package/dist/L/toolkit.js.map +0 -1
- package/dist/L/user.d.ts +0 -6
- package/dist/L/user.js +0 -13
- package/dist/L/user.js.map +0 -1
- package/dist/L/user.test.d.ts +0 -1
- package/dist/L/user.test.js.map +0 -1
- package/dist/LEvent.d.ts +0 -154
- package/dist/LEvent.js +0 -19
- package/dist/LEvent.js.map +0 -1
- package/dist/Thread.d.ts +0 -52
- package/dist/Thread.js +0 -32
- package/dist/Thread.js.map +0 -1
- package/dist/patterns/Debate.d.ts +0 -1
- package/dist/patterns/Debate.js +0 -3
- package/dist/patterns/Debate.js.map +0 -1
- package/dist/patterns/Model.d.ts +0 -6
- package/dist/patterns/Model.js +0 -14
- package/dist/patterns/Model.js.map +0 -1
- package/dist/patterns/Route.d.ts +0 -3
- package/dist/patterns/Route.js +0 -14
- package/dist/patterns/Route.js.map +0 -1
- package/dist/util/JsonValue.d.ts +0 -8
- package/dist/util/JsonValue.js +0 -109
- package/dist/util/JsonValue.js.map +0 -1
- package/dist/util/NeverTool.d.ts +0 -3
- package/dist/util/NeverTool.js +0 -3
- package/dist/util/NeverTool.js.map +0 -1
- package/dist/util/Taggable.d.ts +0 -6
- package/dist/util/Taggable.js +0 -13
- package/dist/util/Taggable.js.map +0 -1
- package/dist/util/extract.d.ts +0 -3
- package/dist/util/extract.js +0 -2
- package/dist/util/extract.js.map +0 -1
- package/dist/util/messageCodec.d.ts +0 -98
- package/dist/util/messageCodec.js +0 -5
- package/dist/util/messageCodec.js.map +0 -1
- package/dist/util/normalizeRaw.d.ts +0 -4
- package/dist/util/normalizeRaw.js +0 -75
- package/dist/util/normalizeRaw.js.map +0 -1
- package/dist/util/prefix.d.ts +0 -1
- package/dist/util/prefix.js +0 -2
- package/dist/util/prefix.js.map +0 -1
- package/dist/util/raw.d.ts +0 -6
- package/dist/util/raw.js +0 -5
- package/dist/util/raw.js.map +0 -1
- package/patterns/Debate.ts +0 -2
- package/patterns/Model.ts +0 -29
- package/patterns/Route.ts +0 -25
- package/util/JsonValue.ts +0 -144
- package/util/NeverTool.ts +0 -10
- package/util/Taggable.ts +0 -33
- package/util/extract.ts +0 -7
- package/util/messageCodec.ts +0 -5
- package/util/normalizeRaw.ts +0 -93
- package/util/prefix.ts +0 -1
- package/util/raw.ts +0 -27
package/errors.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Schema as S } from "effect"
|
|
2
|
+
|
|
3
|
+
import type { MethodDefinition } from "./Method.ts"
|
|
4
|
+
|
|
5
|
+
export class AuditionError extends S.TaggedErrorClass<AuditionError>()("AuditionError", {
|
|
6
|
+
value: S.Struct({
|
|
7
|
+
client: S.String,
|
|
8
|
+
routed: S.String,
|
|
9
|
+
}).pipe(S.optional),
|
|
10
|
+
}) {}
|
|
11
|
+
|
|
12
|
+
export class ConnectionError extends S.TaggedErrorClass<ConnectionError>()("ConnectionError", {
|
|
13
|
+
cause: S.Unknown,
|
|
14
|
+
}) {}
|
|
15
|
+
|
|
16
|
+
export type ClientError = AuditionError | ConnectionError
|
|
17
|
+
|
|
18
|
+
export class UnresolvedError extends S.TaggedErrorClass<UnresolvedError>()("UnresolvedError", {}) {}
|
|
19
|
+
|
|
20
|
+
export type FError<MethodDefinitions extends Record<string, MethodDefinition.Any>> = [
|
|
21
|
+
MethodDefinitions[keyof MethodDefinitions]["failure"]["Type"] | ClientError | UnresolvedError,
|
|
22
|
+
][0]
|
|
@@ -0,0 +1,11 @@
|
|
|
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 "./history.ts"
|
|
8
|
+
export * from "./init.ts"
|
|
9
|
+
export * from "./matrix.ts"
|
|
10
|
+
export * from "./system.ts"
|
|
11
|
+
export * from "./user.ts"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Effect, flow, Ref } from "effect"
|
|
2
|
+
import { Prompt, Chat } from "effect/unstable/ai"
|
|
3
|
+
|
|
4
|
+
export const append = (message: Prompt.Message) =>
|
|
5
|
+
Chat.Chat.asEffect().pipe(
|
|
6
|
+
Effect.flatMap(
|
|
7
|
+
flow(
|
|
8
|
+
({ history }) => history,
|
|
9
|
+
Ref.update(({ content }) => Prompt.fromMessages([...content, message])),
|
|
10
|
+
),
|
|
11
|
+
),
|
|
12
|
+
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Effect } from "effect"
|
|
2
|
+
import { Prompt, LanguageModel } from "effect/unstable/ai"
|
|
3
|
+
|
|
4
|
+
import { append } from "./append.ts"
|
|
5
|
+
import { history } from "./history.ts"
|
|
6
|
+
|
|
7
|
+
export const assistant = Effect.gen(function* () {
|
|
8
|
+
const prompt = yield* history
|
|
9
|
+
const { text } = yield* LanguageModel.generateText({ prompt })
|
|
10
|
+
yield* append(
|
|
11
|
+
Prompt.assistantMessage({
|
|
12
|
+
content: [Prompt.textPart({ text })],
|
|
13
|
+
}),
|
|
14
|
+
)
|
|
15
|
+
return text
|
|
16
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Effect, Schema as S } from "effect"
|
|
2
|
+
import { Prompt, LanguageModel } from "effect/unstable/ai"
|
|
3
|
+
|
|
4
|
+
import { append } from "./append.ts"
|
|
5
|
+
import { history } from "./history.ts"
|
|
6
|
+
|
|
7
|
+
export const assistantSchema = Effect.fnUntraced(function* <A, I extends Record<string, unknown>>(
|
|
8
|
+
schema: S.Codec<A, I>,
|
|
9
|
+
) {
|
|
10
|
+
const prompt = yield* history
|
|
11
|
+
const { text, value } = yield* LanguageModel.generateObject({ prompt, schema })
|
|
12
|
+
yield* append(
|
|
13
|
+
Prompt.assistantMessage({
|
|
14
|
+
content: [Prompt.textPart({ text })],
|
|
15
|
+
}),
|
|
16
|
+
)
|
|
17
|
+
return value
|
|
18
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Effect, Stream } from "effect"
|
|
2
|
+
import { LanguageModel } from "effect/unstable/ai"
|
|
3
|
+
|
|
4
|
+
import { history } from "./history.ts"
|
|
5
|
+
|
|
6
|
+
export const assistantStream = history.pipe(
|
|
7
|
+
Effect.map((prompt) => LanguageModel.streamText({ prompt })),
|
|
8
|
+
Stream.unwrap,
|
|
9
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Effect, Function, Layer } from "effect"
|
|
2
|
+
|
|
3
|
+
import { branch } from "./branch.ts"
|
|
4
|
+
|
|
5
|
+
type LayerRecord = Record<string, Layer.Any>
|
|
6
|
+
|
|
7
|
+
export type MatrixEffect<A, E, R, Layers extends LayerRecord> = Effect.Effect<
|
|
8
|
+
{
|
|
9
|
+
readonly [K in keyof Layers]: A
|
|
10
|
+
},
|
|
11
|
+
E | Layer.Error<Layers[keyof Layers]>,
|
|
12
|
+
R | Layer.Services<Layers[keyof Layers]>
|
|
13
|
+
>
|
|
14
|
+
|
|
15
|
+
export const matrix: {
|
|
16
|
+
<Layers extends LayerRecord>(
|
|
17
|
+
layers: Layers,
|
|
18
|
+
): <A, E, R>(effect: Effect.Effect<A, E, R>) => MatrixEffect<A, E, R, Layers>
|
|
19
|
+
<Layers extends LayerRecord, A, E, R>(effect: Effect.Effect<A, E, R>, layers: Layers): MatrixEffect<A, E, R, Layers>
|
|
20
|
+
} = Function.dual(2, <Layers extends LayerRecord, A, E, R>(effect: Effect.Effect<A, E, R>, layers: Layers) => {
|
|
21
|
+
return Effect.all(
|
|
22
|
+
Object.fromEntries(
|
|
23
|
+
Object.entries(layers).map(([key, Live]) => [key, effect.pipe(branch, Effect.provide(Live as never))]),
|
|
24
|
+
),
|
|
25
|
+
)
|
|
26
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Path, FileSystem } from "effect"
|
|
2
|
+
import { Option, Layer, Effect, Data, Context } from "effect"
|
|
3
|
+
|
|
4
|
+
export class LoaderError extends Data.TaggedError("LoaderError")<{
|
|
5
|
+
readonly url: string
|
|
6
|
+
}> {}
|
|
7
|
+
|
|
8
|
+
export class Loader extends Context.Service<
|
|
9
|
+
Loader,
|
|
10
|
+
{
|
|
11
|
+
readonly load: (key: string) => Effect.Effect<Option.Option<string>, LoaderError>
|
|
12
|
+
}
|
|
13
|
+
>()("liminal/Loader") {}
|
|
14
|
+
|
|
15
|
+
export const layerFs = Layer.effect(
|
|
16
|
+
Loader,
|
|
17
|
+
Effect.gen(function* () {
|
|
18
|
+
const path = yield* Path.Path
|
|
19
|
+
const fs = yield* FileSystem.FileSystem
|
|
20
|
+
|
|
21
|
+
const load = Effect.fnUntraced(function* (url: string) {
|
|
22
|
+
const { dir, name } = path.parse(new URL(url).pathname)
|
|
23
|
+
const templatePathname = path.join(dir, `${name}.md`)
|
|
24
|
+
if (yield* fs.exists(templatePathname).pipe(Effect.mapError(() => new LoaderError({ url })))) {
|
|
25
|
+
return yield* fs.readFileString(templatePathname).pipe(
|
|
26
|
+
Effect.map(Option.some),
|
|
27
|
+
Effect.mapError(() => new LoaderError({ url })),
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
return Option.none()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
return { load }
|
|
34
|
+
}),
|
|
35
|
+
)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Effect } from "effect"
|
|
2
|
+
|
|
3
|
+
export type TemplateStringsArrayLike = {
|
|
4
|
+
raw: ReadonlyArray<string> | ArrayLike<string>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type ExtractE<T> = [Extract<T, Effect.Effect<any, any, any>>] extends [never]
|
|
8
|
+
? never
|
|
9
|
+
: Effect.Error<Extract<T, Effect.Effect<any, any, any>>>
|
|
10
|
+
|
|
11
|
+
type ExtractR<T> = [Extract<T, Effect.Effect<any, any, any>>] extends [never]
|
|
12
|
+
? never
|
|
13
|
+
: Effect.Services<Extract<T, Effect.Effect<any, any, any>>>
|
|
14
|
+
|
|
15
|
+
export const raw = Effect.fnUntraced(function* <Substitutions extends Array<unknown>>(
|
|
16
|
+
template: TemplateStringsArrayLike,
|
|
17
|
+
...substitutions: Substitutions
|
|
18
|
+
): Effect.fn.Return<string, ExtractE<Substitutions[number]>, ExtractR<Substitutions[number]>> {
|
|
19
|
+
return String.raw(
|
|
20
|
+
template,
|
|
21
|
+
...(yield* Effect.all(substitutions.map((v) => (Effect.isEffect(v) ? v : Effect.succeed(v)))) as Effect.Effect<
|
|
22
|
+
Array<string>,
|
|
23
|
+
ExtractE<Substitutions[number]>,
|
|
24
|
+
ExtractR<Substitutions[number]>
|
|
25
|
+
>),
|
|
26
|
+
)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
export type TaggableHead = TemplateStringsArrayLike | string | Effect.Effect<string, any, any>
|
|
30
|
+
|
|
31
|
+
export type TaggableRest<H extends TaggableHead> = H extends TemplateStringsArrayLike ? Array<unknown> : []
|
|
32
|
+
|
|
33
|
+
export const normalize = Effect.fnUntraced(function* <H extends TaggableHead, ARest extends TaggableRest<H>>(
|
|
34
|
+
a0: H,
|
|
35
|
+
...aRest: ARest
|
|
36
|
+
): Effect.fn.Return<string, ExtractE<H | ARest[number]>, ExtractR<H | ARest[number]>> {
|
|
37
|
+
if (Effect.isEffect(a0)) {
|
|
38
|
+
return yield* a0
|
|
39
|
+
}
|
|
40
|
+
if (typeof a0 === "string") {
|
|
41
|
+
return a0
|
|
42
|
+
}
|
|
43
|
+
return yield* raw(a0, ...aRest)
|
|
44
|
+
})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Layer, Effect, Schema as S, Data, Context } from "effect"
|
|
2
|
+
|
|
3
|
+
import * as Loader from "./Loader.ts"
|
|
4
|
+
|
|
5
|
+
export type Template<A> = (...[value]: A extends undefined ? [] : [value: A]) => string
|
|
6
|
+
|
|
7
|
+
export class TemplateMisalignedError extends Data.TaggedError("TemplateMisalignedError")<{
|
|
8
|
+
readonly url: string
|
|
9
|
+
readonly keys: ReadonlyArray<string>
|
|
10
|
+
}> {}
|
|
11
|
+
|
|
12
|
+
export class NoSuchTemplateError extends Data.TaggedError("NoSuchTemplateError")<{ url: string }> {}
|
|
13
|
+
|
|
14
|
+
export interface TemplateClass<Self, Id extends string, A> extends Context.Service<Self, Template<A>> {
|
|
15
|
+
new (_: never): Context.ServiceClass.Shape<Id, Template<A>>
|
|
16
|
+
|
|
17
|
+
readonly layer: Layer.Layer<Self, NoSuchTemplateError | TemplateMisalignedError | Loader.LoaderError, Loader.Loader>
|
|
18
|
+
|
|
19
|
+
readonly synthesize: (...[value]: A extends undefined ? [] : [value: A]) => Effect.Effect<string, never, Self>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const Service =
|
|
23
|
+
<Self>() =>
|
|
24
|
+
<const Id extends string, const P extends S.Struct.Fields>(
|
|
25
|
+
_id: Id,
|
|
26
|
+
_config: {
|
|
27
|
+
readonly url: string
|
|
28
|
+
readonly payload: P
|
|
29
|
+
},
|
|
30
|
+
): TemplateClass<Self, Id, S.Struct<P>["Type"]> => {
|
|
31
|
+
throw 0
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// type Make_ = Template<Payload.FromDefinition<P>>
|
|
35
|
+
// type Self_ = TemplateClass<Self, Id, Payload.FromDefinition<P>>
|
|
36
|
+
// const tag = Context.Service<Self, Make_>()(id)
|
|
37
|
+
// const layer = Effect.gen(function* () {
|
|
38
|
+
// const loader = yield* Loader.Loader
|
|
39
|
+
// const template = yield* loader.load(url).pipe(Effect.map(Option.getOrUndefined))
|
|
40
|
+
// if (!template) {
|
|
41
|
+
// return yield* new NoSuchTemplateError({ url })
|
|
42
|
+
// }
|
|
43
|
+
// const [head, ...rest] = pipe(template, String.trim, String.split("{{"))
|
|
44
|
+
// if ((!payload || !Object.keys(payload).length) && !rest.length) {
|
|
45
|
+
// return () => template
|
|
46
|
+
// }
|
|
47
|
+
// const segments = rest.flatMap((part) => {
|
|
48
|
+
// const i = part.indexOf("}}")
|
|
49
|
+
// if (i === -1) {
|
|
50
|
+
// return []
|
|
51
|
+
// }
|
|
52
|
+
// return {
|
|
53
|
+
// key: part.slice(0, i).trim(),
|
|
54
|
+
// tail: part.slice(i + 2),
|
|
55
|
+
// }
|
|
56
|
+
// })
|
|
57
|
+
// const keys = segments.map(({ key }) => key)
|
|
58
|
+
// if (payload) {
|
|
59
|
+
// const keys_ = new Set(keys)
|
|
60
|
+
// const dne = new Set<string>()
|
|
61
|
+
// const schema = S.Struct(payload)
|
|
62
|
+
// for (const field of schema.ast.propertySignatures) {
|
|
63
|
+
// if (!SchemaAST.isOptional(field.type) && !keys_.has(field.name.toString())) {
|
|
64
|
+
// dne.add(field.name.toString())
|
|
65
|
+
// }
|
|
66
|
+
// }
|
|
67
|
+
// if (dne.size) {
|
|
68
|
+
// return yield* new TemplateMisalignedError({
|
|
69
|
+
// url,
|
|
70
|
+
// keys: [...dne.values()],
|
|
71
|
+
// })
|
|
72
|
+
// }
|
|
73
|
+
// } else if (segments.length) {
|
|
74
|
+
// return yield* new TemplateMisalignedError({ url, keys })
|
|
75
|
+
// }
|
|
76
|
+
// const make: Make_ = (value?) =>
|
|
77
|
+
// value
|
|
78
|
+
// ? head + segments.map(({ key, tail }) => `${(value as Record<typeof key, string>)[key]}${tail}`).join("")
|
|
79
|
+
// : template
|
|
80
|
+
// return make
|
|
81
|
+
// }).pipe(Layer.effect(tag))
|
|
82
|
+
|
|
83
|
+
// const synthesize = (...args) => tag.pipe(Effect.map((make) => make(...args)))
|
|
84
|
+
|
|
85
|
+
// return Object.assign(tag, { synthesize })
|
package/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * as
|
|
4
|
-
export * as
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * as
|
|
1
|
+
export * as Accumulator from "./Accumulator.ts"
|
|
2
|
+
export * as Actor from "./Actor.ts"
|
|
3
|
+
export * as Audition from "./Audition.ts"
|
|
4
|
+
export * as Client from "./Client.ts"
|
|
5
|
+
export * as ClientHandle from "./ClientHandle.ts"
|
|
6
|
+
export * as Method from "./Method.ts"
|
|
7
|
+
export * as Protocol from "./Protocol.ts"
|
|
8
|
+
export * from "./F.ts"
|
|
9
|
+
export * from "./errors.ts"
|
package/package.json
CHANGED
|
@@ -1,43 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "liminal",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.2",
|
|
4
|
+
"description": "Actors x Effects",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/crosshatch/liminal/issues"
|
|
7
|
+
},
|
|
8
|
+
"license": "Apache-2.0",
|
|
4
9
|
"repository": {
|
|
5
10
|
"type": "git",
|
|
6
|
-
"url": "https://github.com/
|
|
11
|
+
"url": "https://github.com/crosshatch/liminal.git",
|
|
7
12
|
"directory": "liminal"
|
|
8
13
|
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
9
16
|
"exports": {
|
|
10
17
|
".": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
},
|
|
14
|
-
"./package.json": "./package.json",
|
|
15
|
-
"./patterns/Route": {
|
|
16
|
-
"import": "./dist/patterns/Route.js",
|
|
17
|
-
"bun": "./patterns/Route.ts"
|
|
18
|
+
"types": "./index.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
18
20
|
},
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
21
|
+
"./*": {
|
|
22
|
+
"types": "./*.ts",
|
|
23
|
+
"default": "./dist/*.js"
|
|
22
24
|
},
|
|
23
|
-
"./
|
|
24
|
-
"import": "./dist/patterns/Debate.js",
|
|
25
|
-
"bun": "./patterns/Debate.ts"
|
|
26
|
-
}
|
|
25
|
+
"./package.json": "./package.json"
|
|
27
26
|
},
|
|
28
|
-
"description": "An Effect AI toolkit for conversation state management.",
|
|
29
|
-
"homepage": "https://liminal.land",
|
|
30
|
-
"license": "Apache-2.0",
|
|
31
|
-
"llms": "https://liminal.land/llms.txt",
|
|
32
|
-
"llmsFull": "https://liminal.land/llmsFull.txt",
|
|
33
|
-
"publishConfig": {
|
|
34
|
-
"access": "public",
|
|
35
|
-
"provenance": true
|
|
36
|
-
},
|
|
37
|
-
"sideEffects": false,
|
|
38
|
-
"type": "module",
|
|
39
27
|
"peerDependencies": {
|
|
40
|
-
"
|
|
41
|
-
"effect": "^3.17.7"
|
|
28
|
+
"effect": "4.0.0-beta.50"
|
|
42
29
|
}
|
|
43
|
-
}
|
|
30
|
+
}
|
package/tsconfig.json
ADDED
package/Digest.ts
DELETED
|
@@ -1,30 +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
|
-
import { prefix } from "./util/prefix.ts"
|
|
7
|
-
|
|
8
|
-
export const DigestTypeId: unique symbol = Symbol.for(prefix("Digest"))
|
|
9
|
-
export type DigestTypeId = typeof DigestTypeId
|
|
10
|
-
|
|
11
|
-
export declare const Digest: <const K extends string, A = string, I = string>(
|
|
12
|
-
key: K,
|
|
13
|
-
schema?: Schema.Schema<A, I>,
|
|
14
|
-
) => <Self>() => DigestClass<K, A, I, Self>
|
|
15
|
-
|
|
16
|
-
export interface DigestClass<K extends string, A, I, Self> extends Effect.Effect<A, never, Self> {
|
|
17
|
-
new(_: never): this
|
|
18
|
-
|
|
19
|
-
readonly Type: A
|
|
20
|
-
readonly Encoded: I
|
|
21
|
-
readonly [DigestTypeId]: DigestTypeId
|
|
22
|
-
readonly key: K
|
|
23
|
-
readonly digest: Effect.Effect<void, never, Self>
|
|
24
|
-
readonly layer: <E, R>(
|
|
25
|
-
f: (
|
|
26
|
-
state: Option.Option<A>,
|
|
27
|
-
inbox: Thread,
|
|
28
|
-
) => Effect.Effect<A, E, R>,
|
|
29
|
-
) => Layer.Layer<Self, E, Exclude<R, Self | Thread>>
|
|
30
|
-
}
|
package/Envelope.ts
DELETED
package/F/F.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../L/json.ts"
|
package/L/L.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/L/append.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Message } from "@effect/ai/AiInput"
|
|
2
|
-
import * as Effect from "effect/Effect"
|
|
3
|
-
import { MessagesAppendedEvent } from "../LEvent.ts"
|
|
4
|
-
import type { Thread } from "../Thread.ts"
|
|
5
|
-
import { self } from "./self.ts"
|
|
6
|
-
|
|
7
|
-
/** Append messages to the thread. */
|
|
8
|
-
export const append: (
|
|
9
|
-
...messages: Array<Message>
|
|
10
|
-
) => Effect.Effect<void, never, Thread> = Effect.fnUntraced(function*(...messages) {
|
|
11
|
-
const { state, events } = yield* self
|
|
12
|
-
state.messages.push(...messages)
|
|
13
|
-
yield* events.publish(MessagesAppendedEvent.make({ messages }))
|
|
14
|
-
})
|
package/L/assistant.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { AiError } from "@effect/ai/AiError"
|
|
2
|
-
import { AssistantMessage, TextPart } from "@effect/ai/AiInput"
|
|
3
|
-
import { AiLanguageModel } from "@effect/ai/AiLanguageModel"
|
|
4
|
-
import * as Effect from "effect/Effect"
|
|
5
|
-
import * as Option from "effect/Option"
|
|
6
|
-
import type { Thread } from "../Thread.ts"
|
|
7
|
-
import { append } from "./append.ts"
|
|
8
|
-
import { self } from "./self.ts"
|
|
9
|
-
import { toolkit } from "./toolkit.ts"
|
|
10
|
-
|
|
11
|
-
/** Infer an assistant message and append it to the thread. */
|
|
12
|
-
export const assistant: Effect.Effect<string, AiError, AiLanguageModel | Thread> = Effect.gen(function*() {
|
|
13
|
-
const model = yield* AiLanguageModel
|
|
14
|
-
const { state: { system, messages: prompt } } = yield* self
|
|
15
|
-
let { text, results } = yield* model.generateText({
|
|
16
|
-
system: Option.getOrUndefined(system),
|
|
17
|
-
prompt,
|
|
18
|
-
toolkit,
|
|
19
|
-
})
|
|
20
|
-
// TODO: this shouldn't be necessary. Bug in Effect AI?
|
|
21
|
-
if (!text.trim()) {
|
|
22
|
-
text = results.values().next().value?.result as never as string
|
|
23
|
-
}
|
|
24
|
-
yield* append(
|
|
25
|
-
AssistantMessage.make({
|
|
26
|
-
parts: [TextPart.make({ text })],
|
|
27
|
-
}),
|
|
28
|
-
)
|
|
29
|
-
return text
|
|
30
|
-
})
|
package/L/assistantSchema.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { AiError } from "@effect/ai/AiError"
|
|
2
|
-
import { AssistantMessage, TextPart } from "@effect/ai/AiInput"
|
|
3
|
-
import { AiLanguageModel } from "@effect/ai/AiLanguageModel"
|
|
4
|
-
import * as Effect from "effect/Effect"
|
|
5
|
-
import * as Option from "effect/Option"
|
|
6
|
-
import * as Schema from "effect/Schema"
|
|
7
|
-
import * as SchemaAST from "effect/SchemaAST"
|
|
8
|
-
import type { Thread } from "../Thread.ts"
|
|
9
|
-
import { encodeJsonc, type JsonValue } from "../util/JsonValue.ts"
|
|
10
|
-
import { append } from "./append.ts"
|
|
11
|
-
import { self } from "./self.ts"
|
|
12
|
-
|
|
13
|
-
/** Infer a structured assistant message and append its JSON representation to the conversation. */
|
|
14
|
-
export const assistantSchema: {
|
|
15
|
-
<F extends Record<string, Schema.Schema.AnyNoContext>>(
|
|
16
|
-
fields: F,
|
|
17
|
-
): Effect.Effect<{ [K in keyof F]: Schema.Schema.Type<F[K]> }, AiError, AiLanguageModel | Thread>
|
|
18
|
-
<O, I extends JsonValue>(
|
|
19
|
-
schema: Schema.Schema<O, I, never>,
|
|
20
|
-
): Effect.Effect<O, AiError, AiLanguageModel | Thread>
|
|
21
|
-
} = Effect.fnUntraced(function*(schema) {
|
|
22
|
-
const model = yield* AiLanguageModel
|
|
23
|
-
const { state: { system, messages } } = yield* self
|
|
24
|
-
|
|
25
|
-
const isSchema = Schema.isSchema(schema)
|
|
26
|
-
const schema_ = isSchema ? schema : Schema.Struct(schema) as Schema.Schema.AnyNoContext
|
|
27
|
-
const isObject = !isSchema || isObjectSchema(SchemaAST.encodedAST(schema.ast))
|
|
28
|
-
const wrapped = isObject ? schema_ : Schema.Struct({ inner: schema_ })
|
|
29
|
-
|
|
30
|
-
const value = yield* model.generateObject({
|
|
31
|
-
system: Option.getOrUndefined(system),
|
|
32
|
-
schema: wrapped,
|
|
33
|
-
prompt: messages,
|
|
34
|
-
}).pipe(
|
|
35
|
-
Effect.map(({ value }) => isObject ? value : value["inner"]),
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
yield* append(
|
|
39
|
-
AssistantMessage.make({
|
|
40
|
-
parts: [
|
|
41
|
-
TextPart.make({
|
|
42
|
-
text: yield* encodeJsonc(schema_)(value),
|
|
43
|
-
}),
|
|
44
|
-
],
|
|
45
|
-
}),
|
|
46
|
-
)
|
|
47
|
-
return value
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
const isObjectSchema = (ast: SchemaAST.AST): boolean => {
|
|
51
|
-
switch (ast._tag) {
|
|
52
|
-
case "TypeLiteral": {
|
|
53
|
-
return true
|
|
54
|
-
}
|
|
55
|
-
case "Refinement":
|
|
56
|
-
case "Transformation": {
|
|
57
|
-
return isObjectSchema(ast.from)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return false
|
|
61
|
-
}
|
package/L/assistantStream.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { AiError } from "@effect/ai/AiError"
|
|
2
|
-
import { AiLanguageModel } from "@effect/ai/AiLanguageModel"
|
|
3
|
-
import type { AiResponse } from "@effect/ai/AiResponse"
|
|
4
|
-
import * as Effect from "effect/Effect"
|
|
5
|
-
import * as Option from "effect/Option"
|
|
6
|
-
import * as Stream from "effect/Stream"
|
|
7
|
-
import type { Thread } from "../Thread.ts"
|
|
8
|
-
import { self } from "./self.ts"
|
|
9
|
-
import { toolkit } from "./toolkit.ts"
|
|
10
|
-
|
|
11
|
-
/** Get a stream of an assistant message (does not append the message to the thread). */
|
|
12
|
-
export const assistantStream: Stream.Stream<AiResponse, AiError, AiLanguageModel | Thread> = Stream.unwrap(
|
|
13
|
-
Effect.gen(function*() {
|
|
14
|
-
const model = yield* AiLanguageModel
|
|
15
|
-
const { state: { system, messages: prompt } } = yield* self
|
|
16
|
-
return model.streamText({
|
|
17
|
-
system: Option.getOrUndefined(system),
|
|
18
|
-
prompt,
|
|
19
|
-
toolkit,
|
|
20
|
-
})
|
|
21
|
-
}),
|
|
22
|
-
)
|