liminal 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/L.ts +14 -81
- package/LEvent.ts +23 -0
- package/Sequence.ts +14 -0
- package/Strand.ts +19 -41
- package/append.ts +13 -0
- package/assistant.ts +23 -0
- package/assistantStruct.ts +34 -0
- package/branch.ts +26 -0
- package/clear.ts +15 -0
- package/dist/L.d.ts +14 -15
- package/dist/L.js +14 -56
- package/dist/L.js.map +1 -1
- package/dist/LEvent.d.ts +26 -0
- package/dist/LEvent.js +16 -0
- package/dist/LEvent.js.map +1 -0
- package/dist/Sequence.d.ts +2 -0
- package/dist/Sequence.js +2 -0
- package/dist/Sequence.js.map +1 -0
- package/dist/Strand.d.ts +20 -20
- package/dist/Strand.js +3 -19
- package/dist/Strand.js.map +1 -1
- package/dist/append.d.ts +5 -0
- package/dist/append.js +11 -0
- package/dist/append.js.map +1 -0
- package/dist/assistant.d.ts +6 -0
- package/dist/assistant.js +20 -0
- package/dist/assistant.js.map +1 -0
- package/dist/assistantStruct.d.ts +12 -0
- package/dist/assistantStruct.js +22 -0
- package/dist/assistantStruct.js.map +1 -0
- package/dist/branch.d.ts +4 -0
- package/dist/branch.js +18 -0
- package/dist/branch.js.map +1 -0
- package/dist/clear.d.ts +5 -0
- package/dist/clear.js +15 -0
- package/dist/clear.js.map +1 -0
- package/dist/events.d.ts +5 -0
- package/dist/events.js +6 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/JsonValue.d.ts +5 -0
- package/dist/internal/JsonValue.js +2 -0
- package/dist/internal/JsonValue.js.map +1 -0
- package/dist/internal/Taggable.d.ts +11 -0
- package/dist/internal/Taggable.js +2 -0
- package/dist/internal/Taggable.js.map +1 -0
- package/dist/messages.d.ts +5 -0
- package/dist/messages.js +5 -0
- package/dist/messages.js.map +1 -0
- package/dist/pretty.d.ts +2 -0
- package/dist/pretty.js +37 -0
- package/dist/pretty.js.map +1 -0
- package/dist/reduce.d.ts +4 -0
- package/dist/reduce.js +20 -0
- package/dist/reduce.js.map +1 -0
- package/dist/sequence_.d.ts +2 -0
- package/dist/sequence_.js +5 -0
- package/dist/sequence_.js.map +1 -0
- package/dist/strand_.d.ts +4 -0
- package/dist/strand_.js +18 -0
- package/dist/strand_.js.map +1 -0
- package/dist/system.d.ts +5 -0
- package/dist/system.js +11 -0
- package/dist/system.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/user.d.ts +5 -0
- package/dist/user.js +14 -0
- package/dist/user.js.map +1 -0
- package/dist/userJson.d.ts +6 -0
- package/dist/userJson.js +8 -0
- package/dist/userJson.js.map +1 -0
- package/events.ts +9 -0
- package/index.ts +3 -1
- package/internal/JsonValue.ts +5 -0
- package/internal/Taggable.ts +17 -0
- package/messages.ts +9 -0
- package/package.json +10 -6
- package/pretty.ts +41 -0
- package/reduce.ts +32 -0
- package/sequence_.ts +9 -0
- package/strand_.ts +25 -0
- package/system.ts +13 -0
- package/tsconfig.json +11 -1
- package/user.ts +17 -0
- package/userJson.ts +12 -0
- package/dist/util/JSONValue.d.ts +0 -5
- package/dist/util/JSONValue.js +0 -2
- package/dist/util/JSONValue.js.map +0 -1
- package/dist/util/fixTemplateStrings.d.ts +0 -11
- package/dist/util/fixTemplateStrings.js +0 -83
- package/dist/util/fixTemplateStrings.js.map +0 -1
- package/dist/util/isTemplateStringsArray.d.ts +0 -1
- package/dist/util/isTemplateStringsArray.js +0 -4
- package/dist/util/isTemplateStringsArray.js.map +0 -1
- package/util/JSONValue.ts +0 -5
- package/util/fixTemplateStrings.ts +0 -99
- package/util/isTemplateStringsArray.ts +0 -3
package/CHANGELOG.md
CHANGED
package/L.ts
CHANGED
|
@@ -1,81 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const { messages, onMessage } = yield* Strand.Strand
|
|
16
|
-
const text = isTemplateStringsArray(a0) ? String.raw({ raw: a0 }, ...aRest) : a0
|
|
17
|
-
const message = new AiInput.UserMessage({
|
|
18
|
-
parts: [new AiInput.TextPart({ text })],
|
|
19
|
-
})
|
|
20
|
-
yield* onMessage(message)
|
|
21
|
-
messages.push(message)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
export const messages: Effect.Effect<Array<AiInput.Message>, never, Strand.Strand> = Effect.map(
|
|
25
|
-
Strand.Strand,
|
|
26
|
-
({ messages }) => messages,
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
export const setMessages: (
|
|
30
|
-
messages: Iterable<AiInput.Message>,
|
|
31
|
-
) => Effect.Effect<Array<AiInput.Message>, never, Strand.Strand> = Effect.fnUntraced(
|
|
32
|
-
function*(messages: Iterable<AiInput.Message>) {
|
|
33
|
-
const strand = yield* Strand.Strand
|
|
34
|
-
const { messages: prev } = strand
|
|
35
|
-
strand.messages = [...messages]
|
|
36
|
-
return prev
|
|
37
|
-
},
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
export const assistantText: Effect.Effect<
|
|
41
|
-
string,
|
|
42
|
-
AiError.AiError,
|
|
43
|
-
AiLanguageModel.AiLanguageModel | Strand.Strand
|
|
44
|
-
> = Effect.gen(function*() {
|
|
45
|
-
const model = yield* AiLanguageModel.AiLanguageModel
|
|
46
|
-
const { system, messages, tools } = yield* Strand.Strand
|
|
47
|
-
const response = yield* model.generateText({
|
|
48
|
-
system,
|
|
49
|
-
prompt: messages,
|
|
50
|
-
toolkit: AiToolkit.make(...tools ?? []) as never,
|
|
51
|
-
})
|
|
52
|
-
const { text } = response
|
|
53
|
-
yield* append(text)
|
|
54
|
-
return text
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
export const assistantStruct: <O, I extends Record<string, unknown>>(
|
|
58
|
-
schema: Schema.Schema<O, I, never>,
|
|
59
|
-
) => Effect.Effect<O, AiError.AiError, AiLanguageModel.AiLanguageModel | Strand.Strand> = Effect.fnUntraced(
|
|
60
|
-
function*(schema) {
|
|
61
|
-
const model = yield* AiLanguageModel.AiLanguageModel
|
|
62
|
-
const { system, messages } = yield* Strand.Strand
|
|
63
|
-
const response = yield* model.generateObject({
|
|
64
|
-
system,
|
|
65
|
-
schema,
|
|
66
|
-
prompt: messages,
|
|
67
|
-
})
|
|
68
|
-
const { value, text } = response
|
|
69
|
-
yield* append(text)
|
|
70
|
-
return value
|
|
71
|
-
},
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
const append = Effect.fnUntraced(function*(text: string) {
|
|
75
|
-
const { messages, onMessage } = yield* Strand.Strand
|
|
76
|
-
const message = new AiInput.AssistantMessage({
|
|
77
|
-
parts: [new AiInput.TextPart({ text })],
|
|
78
|
-
})
|
|
79
|
-
yield* onMessage(message)
|
|
80
|
-
messages.push(message)
|
|
81
|
-
})
|
|
1
|
+
export * from "./append.ts"
|
|
2
|
+
export * from "./assistant.ts"
|
|
3
|
+
export * from "./assistantStruct.ts"
|
|
4
|
+
export * from "./branch.ts"
|
|
5
|
+
export * from "./clear.ts"
|
|
6
|
+
export * from "./events.ts"
|
|
7
|
+
export * from "./messages.ts"
|
|
8
|
+
export * from "./reduce.ts"
|
|
9
|
+
export * from "./Sequence.ts"
|
|
10
|
+
export * from "./sequence_.ts"
|
|
11
|
+
export * from "./strand_.ts"
|
|
12
|
+
export * from "./system.ts"
|
|
13
|
+
export * from "./user.ts"
|
|
14
|
+
export * from "./userJson.ts"
|
package/LEvent.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Message } from "@effect/ai/AiInput"
|
|
2
|
+
import * as Schema from "effect/Schema"
|
|
3
|
+
|
|
4
|
+
export class Messages extends Schema.Array(Message) {}
|
|
5
|
+
|
|
6
|
+
/** An event in which one or more messages were added to the current strand's message list. */
|
|
7
|
+
export class MessagesAppended extends Schema.TaggedClass<MessagesAppended>("MessagesAppended")("MessagesAppended", {
|
|
8
|
+
messages: Messages,
|
|
9
|
+
}) {}
|
|
10
|
+
|
|
11
|
+
/** An event in which the current strand's message list is cleared. */
|
|
12
|
+
export class MessagesCleared extends Schema.TaggedClass<MessagesCleared>("MessagesCleared")("MessagesCleared", {
|
|
13
|
+
cleared: Messages,
|
|
14
|
+
}) {}
|
|
15
|
+
|
|
16
|
+
export type LEvent = typeof LEvent["Type"]
|
|
17
|
+
export const LEvent: Schema.Union<[
|
|
18
|
+
typeof MessagesAppended,
|
|
19
|
+
typeof MessagesCleared,
|
|
20
|
+
]> = Schema.Union(
|
|
21
|
+
MessagesAppended,
|
|
22
|
+
MessagesCleared,
|
|
23
|
+
)
|
package/Sequence.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect"
|
|
2
|
+
|
|
3
|
+
export type Sequence<P = never, R1 = never> = <Arg extends Array<Effect.Effect<any, any, any>>>(
|
|
4
|
+
...steps: Arg
|
|
5
|
+
) => Effect.Effect<
|
|
6
|
+
Arg extends [] ? void
|
|
7
|
+
: [Arg extends [...infer _0, infer L] ? L : never] extends [Effect.Effect<infer A, infer _E, infer _R>] ? A
|
|
8
|
+
: never,
|
|
9
|
+
Arg[number] extends never ? never : [Arg[number]] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never,
|
|
10
|
+
Exclude<
|
|
11
|
+
Arg[number] extends never ? never : [Arg[number]] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never,
|
|
12
|
+
P
|
|
13
|
+
> | R1
|
|
14
|
+
>
|
package/Strand.ts
CHANGED
|
@@ -1,46 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Message } from "@effect/ai/AiInput"
|
|
2
|
+
import type { AiTool } from "@effect/ai/AiTool"
|
|
3
3
|
import * as Context from "effect/Context"
|
|
4
|
-
import * as Effect from "effect/Effect"
|
|
5
|
-
import * as Layer from "effect/Layer"
|
|
6
4
|
import * as Option from "effect/Option"
|
|
5
|
+
import * as PubSub from "effect/PubSub"
|
|
6
|
+
import type { LEvent } from "./LEvent.ts"
|
|
7
7
|
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
export declare namespace Strand {
|
|
9
|
+
export interface Service {
|
|
10
|
+
/** The parent strand. */
|
|
11
|
+
readonly parent: Option.Option<Service>
|
|
12
|
+
/** The pubsub with which the current strand's events are emitted. */
|
|
13
|
+
readonly events: PubSub.PubSub<LEvent>
|
|
14
|
+
/** The current system prompt to be passed along to the model. */
|
|
15
|
+
system: Option.Option<string>
|
|
16
|
+
/** The list of messages that the model uses to infer the next message. */
|
|
17
|
+
messages: Array<Message>
|
|
18
|
+
/** The tools available to the model. */
|
|
19
|
+
tools: Array<AiTool<string>>
|
|
20
|
+
}
|
|
15
21
|
}
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
messages: Array<AiInput.Message>
|
|
20
|
-
tools?: Array<AiTool.AiTool<string>>
|
|
21
|
-
onMessage: (message: AiInput.Message) => Effect.Effect<void>
|
|
22
|
-
}>() {}
|
|
23
|
-
|
|
24
|
-
/** Create an isolated clone of the current conversation to provide for an effect. */
|
|
25
|
-
export const make: <E = never, R = never>(
|
|
26
|
-
config?: StrandConfig<E, R>,
|
|
27
|
-
) => Effect.Effect<Strand["Type"], E, R> = (config) =>
|
|
28
|
-
Effect.map(
|
|
29
|
-
Effect.serviceOption(Strand),
|
|
30
|
-
Option.match({
|
|
31
|
-
onSome: ({ system, messages, tools, onMessage }) => ({
|
|
32
|
-
system: config ? config?.system : system,
|
|
33
|
-
messages: [...config ? config?.messages ?? [] : messages],
|
|
34
|
-
tools: [...tools ?? []],
|
|
35
|
-
onMessage: onMessage ?? (() => Effect.succeed(undefined)),
|
|
36
|
-
}),
|
|
37
|
-
onNone: () => ({
|
|
38
|
-
system: config?.system,
|
|
39
|
-
messages: config?.messages ?? [],
|
|
40
|
-
onMessage: (config?.onMessage ?? (() => Effect.succeed(undefined))) as never,
|
|
41
|
-
}),
|
|
42
|
-
}),
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
export const layer: <E = never, R = never>(config?: StrandConfig<E, R>) => Layer.Layer<Strand, E, R> = (config) =>
|
|
46
|
-
Layer.effect(Strand, make(config))
|
|
23
|
+
/** A context tag that denotes the boundary of a conversation isolate. */
|
|
24
|
+
export class Strand extends Context.Tag("liminal/Strand")<Strand, Strand.Service>() {}
|
package/append.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Message } from "@effect/ai/AiInput"
|
|
2
|
+
import * as Effect from "effect/Effect"
|
|
3
|
+
import { MessagesAppended } from "./LEvent.ts"
|
|
4
|
+
import { Strand } from "./Strand.ts"
|
|
5
|
+
|
|
6
|
+
/** Append messages to the current strand's message list. */
|
|
7
|
+
export const append: (
|
|
8
|
+
...messages: Array<Message>
|
|
9
|
+
) => Effect.Effect<void, never, Strand> = Effect.fnUntraced(function*(...messages) {
|
|
10
|
+
const strand = yield* Strand
|
|
11
|
+
strand.messages.push(...messages)
|
|
12
|
+
yield* strand.events.publish(MessagesAppended.make({ messages }))
|
|
13
|
+
})
|
package/assistant.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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 { append } from "./append.ts"
|
|
7
|
+
import { Strand } from "./Strand.ts"
|
|
8
|
+
|
|
9
|
+
/** Infer an assistant message and append it to the conversation. */
|
|
10
|
+
export const assistant: Effect.Effect<string, AiError, AiLanguageModel | Strand> = Effect.gen(function*() {
|
|
11
|
+
const model = yield* AiLanguageModel
|
|
12
|
+
const { system, messages } = yield* Strand
|
|
13
|
+
const { text } = yield* model.generateText({
|
|
14
|
+
system: Option.getOrUndefined(system),
|
|
15
|
+
prompt: messages,
|
|
16
|
+
})
|
|
17
|
+
yield* append(
|
|
18
|
+
new AssistantMessage({
|
|
19
|
+
parts: [new TextPart({ text })],
|
|
20
|
+
}),
|
|
21
|
+
)
|
|
22
|
+
return text
|
|
23
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { append } from "./append.ts"
|
|
8
|
+
import { Strand } from "./Strand.ts"
|
|
9
|
+
|
|
10
|
+
/** Infer a structured assistant message and append its JSON representation to the conversation. */
|
|
11
|
+
export const assistantStruct: {
|
|
12
|
+
<F extends Record<string, Schema.Schema.AnyNoContext>>(
|
|
13
|
+
fields: F,
|
|
14
|
+
): Effect.Effect<{ [K in keyof F]: Schema.Schema.Type<F[K]> }, AiError, AiLanguageModel | Strand>
|
|
15
|
+
<O, I extends Record<string, unknown>>(
|
|
16
|
+
schema: Schema.Schema<O, I, never>,
|
|
17
|
+
): Effect.Effect<O, AiError, AiLanguageModel | Strand>
|
|
18
|
+
} = Effect.fnUntraced(
|
|
19
|
+
function*(schema) {
|
|
20
|
+
const model = yield* AiLanguageModel
|
|
21
|
+
const { system, messages } = yield* Strand
|
|
22
|
+
const { value, text } = yield* model.generateObject({
|
|
23
|
+
system: Option.getOrUndefined(system),
|
|
24
|
+
schema: Schema.isSchema(schema) ? schema as Schema.Schema.AnyNoContext : Schema.Struct(schema),
|
|
25
|
+
prompt: messages,
|
|
26
|
+
})
|
|
27
|
+
yield* append(
|
|
28
|
+
new AssistantMessage({
|
|
29
|
+
parts: [new TextPart({ text })],
|
|
30
|
+
}),
|
|
31
|
+
)
|
|
32
|
+
return value
|
|
33
|
+
},
|
|
34
|
+
)
|
package/branch.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect"
|
|
2
|
+
import { flow, identity } from "effect/Function"
|
|
3
|
+
import * as Option from "effect/Option"
|
|
4
|
+
import * as PubSub from "effect/PubSub"
|
|
5
|
+
import type { LEvent } from "./LEvent.ts"
|
|
6
|
+
import type { Sequence } from "./Sequence.ts"
|
|
7
|
+
import { sequence } from "./sequence_.ts"
|
|
8
|
+
import { Strand } from "./Strand.ts"
|
|
9
|
+
|
|
10
|
+
/** Isolate the effect with a new strand in context. */
|
|
11
|
+
export const branch: Sequence<never, Strand> = flow(
|
|
12
|
+
sequence,
|
|
13
|
+
Effect.provideServiceEffect(
|
|
14
|
+
Strand,
|
|
15
|
+
Effect.gen(function*() {
|
|
16
|
+
const parent = yield* Strand
|
|
17
|
+
return Strand.of({
|
|
18
|
+
parent: Option.some(parent),
|
|
19
|
+
system: Option.map(parent.system, identity),
|
|
20
|
+
events: yield* PubSub.unbounded<LEvent>(),
|
|
21
|
+
messages: parent.messages.slice(),
|
|
22
|
+
tools: parent.tools.slice(),
|
|
23
|
+
})
|
|
24
|
+
}),
|
|
25
|
+
),
|
|
26
|
+
)
|
package/clear.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Message } from "@effect/ai/AiInput"
|
|
2
|
+
import * as Effect from "effect/Effect"
|
|
3
|
+
import { MessagesCleared } from "./LEvent.ts"
|
|
4
|
+
import { Strand } from "./Strand.ts"
|
|
5
|
+
|
|
6
|
+
/** Clear the strand's conversation. */
|
|
7
|
+
export const clear: Effect.Effect<Array<Message>, never, Strand> = Effect.gen(function*() {
|
|
8
|
+
const strand = yield* Strand
|
|
9
|
+
const { messages, events } = strand
|
|
10
|
+
strand.messages = []
|
|
11
|
+
yield* events.publish(MessagesCleared.make({
|
|
12
|
+
cleared: messages,
|
|
13
|
+
}))
|
|
14
|
+
return messages
|
|
15
|
+
})
|
package/dist/L.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export declare const assistantStruct: <O, I extends Record<string, unknown>>(schema: Schema.Schema<O, I, never>) => Effect.Effect<O, AiError.AiError, AiLanguageModel.AiLanguageModel | Strand.Strand>;
|
|
1
|
+
export * from "./append.ts";
|
|
2
|
+
export * from "./assistant.ts";
|
|
3
|
+
export * from "./assistantStruct.ts";
|
|
4
|
+
export * from "./branch.ts";
|
|
5
|
+
export * from "./clear.ts";
|
|
6
|
+
export * from "./events.ts";
|
|
7
|
+
export * from "./messages.ts";
|
|
8
|
+
export * from "./reduce.ts";
|
|
9
|
+
export * from "./Sequence.ts";
|
|
10
|
+
export * from "./sequence_.ts";
|
|
11
|
+
export * from "./strand_.ts";
|
|
12
|
+
export * from "./system.ts";
|
|
13
|
+
export * from "./user.ts";
|
|
14
|
+
export * from "./userJson.ts";
|
package/dist/L.js
CHANGED
|
@@ -1,57 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
yield* onMessage(message);
|
|
16
|
-
messages.push(message);
|
|
17
|
-
});
|
|
18
|
-
export const messages = Effect.map(Strand.Strand, ({ messages }) => messages);
|
|
19
|
-
export const setMessages = Effect.fnUntraced(function* (messages) {
|
|
20
|
-
const strand = yield* Strand.Strand;
|
|
21
|
-
const { messages: prev } = strand;
|
|
22
|
-
strand.messages = [...messages];
|
|
23
|
-
return prev;
|
|
24
|
-
});
|
|
25
|
-
export const assistantText = Effect.gen(function* () {
|
|
26
|
-
const model = yield* AiLanguageModel.AiLanguageModel;
|
|
27
|
-
const { system, messages, tools } = yield* Strand.Strand;
|
|
28
|
-
const response = yield* model.generateText({
|
|
29
|
-
system,
|
|
30
|
-
prompt: messages,
|
|
31
|
-
toolkit: AiToolkit.make(...tools ?? []),
|
|
32
|
-
});
|
|
33
|
-
const { text } = response;
|
|
34
|
-
yield* append(text);
|
|
35
|
-
return text;
|
|
36
|
-
});
|
|
37
|
-
export const assistantStruct = Effect.fnUntraced(function* (schema) {
|
|
38
|
-
const model = yield* AiLanguageModel.AiLanguageModel;
|
|
39
|
-
const { system, messages } = yield* Strand.Strand;
|
|
40
|
-
const response = yield* model.generateObject({
|
|
41
|
-
system,
|
|
42
|
-
schema,
|
|
43
|
-
prompt: messages,
|
|
44
|
-
});
|
|
45
|
-
const { value, text } = response;
|
|
46
|
-
yield* append(text);
|
|
47
|
-
return value;
|
|
48
|
-
});
|
|
49
|
-
const append = Effect.fnUntraced(function* (text) {
|
|
50
|
-
const { messages, onMessage } = yield* Strand.Strand;
|
|
51
|
-
const message = new AiInput.AssistantMessage({
|
|
52
|
-
parts: [new AiInput.TextPart({ text })],
|
|
53
|
-
});
|
|
54
|
-
yield* onMessage(message);
|
|
55
|
-
messages.push(message);
|
|
56
|
-
});
|
|
1
|
+
export * from "./append.js";
|
|
2
|
+
export * from "./assistant.js";
|
|
3
|
+
export * from "./assistantStruct.js";
|
|
4
|
+
export * from "./branch.js";
|
|
5
|
+
export * from "./clear.js";
|
|
6
|
+
export * from "./events.js";
|
|
7
|
+
export * from "./messages.js";
|
|
8
|
+
export * from "./reduce.js";
|
|
9
|
+
export * from "./Sequence.js";
|
|
10
|
+
export * from "./sequence_.js";
|
|
11
|
+
export * from "./strand_.js";
|
|
12
|
+
export * from "./system.js";
|
|
13
|
+
export * from "./user.js";
|
|
14
|
+
export * from "./userJson.js";
|
|
57
15
|
//# sourceMappingURL=L.js.map
|
package/dist/L.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"L.js","sourceRoot":"","sources":["../L.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"L.js","sourceRoot":"","sources":["../L.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA"}
|
package/dist/LEvent.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
declare const Messages_base: Schema.Array$<Schema.Union<[typeof import("@effect/ai/AiInput").UserMessage, typeof import("@effect/ai/AiInput").AssistantMessage, typeof import("@effect/ai/AiInput").ToolMessage]>>;
|
|
3
|
+
export declare class Messages extends Messages_base {
|
|
4
|
+
}
|
|
5
|
+
declare const MessagesAppended_base: Schema.TaggedClass<MessagesAppended, "MessagesAppended", {
|
|
6
|
+
readonly _tag: Schema.tag<"MessagesAppended">;
|
|
7
|
+
} & {
|
|
8
|
+
messages: typeof Messages;
|
|
9
|
+
}>;
|
|
10
|
+
/** An event in which one or more messages were added to the current strand's message list. */
|
|
11
|
+
export declare class MessagesAppended extends MessagesAppended_base {
|
|
12
|
+
}
|
|
13
|
+
declare const MessagesCleared_base: Schema.TaggedClass<MessagesCleared, "MessagesCleared", {
|
|
14
|
+
readonly _tag: Schema.tag<"MessagesCleared">;
|
|
15
|
+
} & {
|
|
16
|
+
cleared: typeof Messages;
|
|
17
|
+
}>;
|
|
18
|
+
/** An event in which the current strand's message list is cleared. */
|
|
19
|
+
export declare class MessagesCleared extends MessagesCleared_base {
|
|
20
|
+
}
|
|
21
|
+
export type LEvent = typeof LEvent["Type"];
|
|
22
|
+
export declare const LEvent: Schema.Union<[
|
|
23
|
+
typeof MessagesAppended,
|
|
24
|
+
typeof MessagesCleared
|
|
25
|
+
]>;
|
|
26
|
+
export {};
|
package/dist/LEvent.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Message } from "@effect/ai/AiInput";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
export class Messages extends Schema.Array(Message) {
|
|
4
|
+
}
|
|
5
|
+
/** An event in which one or more messages were added to the current strand's message list. */
|
|
6
|
+
export class MessagesAppended extends Schema.TaggedClass("MessagesAppended")("MessagesAppended", {
|
|
7
|
+
messages: Messages,
|
|
8
|
+
}) {
|
|
9
|
+
}
|
|
10
|
+
/** An event in which the current strand's message list is cleared. */
|
|
11
|
+
export class MessagesCleared extends Schema.TaggedClass("MessagesCleared")("MessagesCleared", {
|
|
12
|
+
cleared: Messages,
|
|
13
|
+
}) {
|
|
14
|
+
}
|
|
15
|
+
export const LEvent = Schema.Union(MessagesAppended, MessagesCleared);
|
|
16
|
+
//# sourceMappingURL=LEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LEvent.js","sourceRoot":"","sources":["../LEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,MAAM,OAAO,QAAS,SAAQ,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;CAAG;AAEtD,8FAA8F;AAC9F,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC,WAAW,CAAmB,kBAAkB,CAAC,CAAC,kBAAkB,EAAE;IACjH,QAAQ,EAAE,QAAQ;CACnB,CAAC;CAAG;AAEL,sEAAsE;AACtE,MAAM,OAAO,eAAgB,SAAQ,MAAM,CAAC,WAAW,CAAkB,iBAAiB,CAAC,CAAC,iBAAiB,EAAE;IAC7G,OAAO,EAAE,QAAQ;CAClB,CAAC;CAAG;AAGL,MAAM,CAAC,MAAM,MAAM,GAGd,MAAM,CAAC,KAAK,CACf,gBAAgB,EAChB,eAAe,CAChB,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
export type Sequence<P = never, R1 = never> = <Arg extends Array<Effect.Effect<any, any, any>>>(...steps: Arg) => Effect.Effect<Arg extends [] ? void : [Arg extends [...infer _0, infer L] ? L : never] extends [Effect.Effect<infer A, infer _E, infer _R>] ? A : never, Arg[number] extends never ? never : [Arg[number]] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, Exclude<Arg[number] extends never ? never : [Arg[number]] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never, P> | R1>;
|
package/dist/Sequence.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sequence.js","sourceRoot":"","sources":["../Sequence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA"}
|
package/dist/Strand.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Message } from "@effect/ai/AiInput";
|
|
2
|
+
import type { AiTool } from "@effect/ai/AiTool";
|
|
3
3
|
import * as Context from "effect/Context";
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
import * as PubSub from "effect/PubSub";
|
|
6
|
+
import type { LEvent } from "./LEvent.ts";
|
|
7
|
+
export declare namespace Strand {
|
|
8
|
+
interface Service {
|
|
9
|
+
/** The parent strand. */
|
|
10
|
+
readonly parent: Option.Option<Service>;
|
|
11
|
+
/** The pubsub with which the current strand's events are emitted. */
|
|
12
|
+
readonly events: PubSub.PubSub<LEvent>;
|
|
13
|
+
/** The current system prompt to be passed along to the model. */
|
|
14
|
+
system: Option.Option<string>;
|
|
15
|
+
/** The list of messages that the model uses to infer the next message. */
|
|
16
|
+
messages: Array<Message>;
|
|
17
|
+
/** The tools available to the model. */
|
|
18
|
+
tools: Array<AiTool<string>>;
|
|
19
|
+
}
|
|
13
20
|
}
|
|
14
|
-
declare const Strand_base: Context.TagClass<Strand, "liminal/Strand",
|
|
15
|
-
|
|
16
|
-
messages: Array<AiInput.Message>;
|
|
17
|
-
tools?: Array<AiTool.AiTool<string>>;
|
|
18
|
-
onMessage: (message: AiInput.Message) => Effect.Effect<void>;
|
|
19
|
-
}>;
|
|
21
|
+
declare const Strand_base: Context.TagClass<Strand, "liminal/Strand", Strand.Service>;
|
|
22
|
+
/** A context tag that denotes the boundary of a conversation isolate. */
|
|
20
23
|
export declare class Strand extends Strand_base {
|
|
21
24
|
}
|
|
22
|
-
/** Create an isolated clone of the current conversation to provide for an effect. */
|
|
23
|
-
export declare const make: <E = never, R = never>(config?: StrandConfig<E, R>) => Effect.Effect<Strand["Type"], E, R>;
|
|
24
|
-
export declare const layer: <E = never, R = never>(config?: StrandConfig<E, R>) => Layer.Layer<Strand, E, R>;
|
|
25
25
|
export {};
|
package/dist/Strand.js
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as AiTool from "@effect/ai/AiTool";
|
|
1
|
+
import { Message } from "@effect/ai/AiInput";
|
|
3
2
|
import * as Context from "effect/Context";
|
|
4
|
-
import * as Effect from "effect/Effect";
|
|
5
|
-
import * as Layer from "effect/Layer";
|
|
6
3
|
import * as Option from "effect/Option";
|
|
4
|
+
import * as PubSub from "effect/PubSub";
|
|
5
|
+
/** A context tag that denotes the boundary of a conversation isolate. */
|
|
7
6
|
export class Strand extends Context.Tag("liminal/Strand")() {
|
|
8
7
|
}
|
|
9
|
-
/** Create an isolated clone of the current conversation to provide for an effect. */
|
|
10
|
-
export const make = (config) => Effect.map(Effect.serviceOption(Strand), Option.match({
|
|
11
|
-
onSome: ({ system, messages, tools, onMessage }) => ({
|
|
12
|
-
system: config ? config?.system : system,
|
|
13
|
-
messages: [...config ? config?.messages ?? [] : messages],
|
|
14
|
-
tools: [...tools ?? []],
|
|
15
|
-
onMessage: onMessage ?? (() => Effect.succeed(undefined)),
|
|
16
|
-
}),
|
|
17
|
-
onNone: () => ({
|
|
18
|
-
system: config?.system,
|
|
19
|
-
messages: config?.messages ?? [],
|
|
20
|
-
onMessage: (config?.onMessage ?? (() => Effect.succeed(undefined))),
|
|
21
|
-
}),
|
|
22
|
-
}));
|
|
23
|
-
export const layer = (config) => Layer.effect(Strand, make(config));
|
|
24
8
|
//# sourceMappingURL=Strand.js.map
|
package/dist/Strand.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Strand.js","sourceRoot":"","sources":["../Strand.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Strand.js","sourceRoot":"","sources":["../Strand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAE5C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAkBvC,yEAAyE;AACzE,MAAM,OAAO,MAAO,SAAQ,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAA0B;CAAG"}
|
package/dist/append.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Message } from "@effect/ai/AiInput";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { Strand } from "./Strand.ts";
|
|
4
|
+
/** Append messages to the current strand's message list. */
|
|
5
|
+
export declare const append: (...messages: Array<Message>) => Effect.Effect<void, never, Strand>;
|
package/dist/append.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Message } from "@effect/ai/AiInput";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { MessagesAppended } from "./LEvent.js";
|
|
4
|
+
import { Strand } from "./Strand.js";
|
|
5
|
+
/** Append messages to the current strand's message list. */
|
|
6
|
+
export const append = Effect.fnUntraced(function* (...messages) {
|
|
7
|
+
const strand = yield* Strand;
|
|
8
|
+
strand.messages.push(...messages);
|
|
9
|
+
yield* strand.events.publish(MessagesAppended.make({ messages }));
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=append.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"append.js","sourceRoot":"","sources":["../append.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,MAAM,GAEuB,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAC,GAAG,QAAQ;IAC/E,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAA;IAC5B,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAA;IACjC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAA;AACnE,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AiError } from "@effect/ai/AiError";
|
|
2
|
+
import { AiLanguageModel } from "@effect/ai/AiLanguageModel";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import { Strand } from "./Strand.ts";
|
|
5
|
+
/** Infer an assistant message and append it to the conversation. */
|
|
6
|
+
export declare const assistant: Effect.Effect<string, AiError, AiLanguageModel | Strand>;
|