Skip to content

Commit a04ae8b

Browse files
authored
Rework Event-handling Mechanism (#351)
1 parent 18eb524 commit a04ae8b

File tree

17 files changed

+100
-40
lines changed

17 files changed

+100
-40
lines changed

.changeset/heavy-ravens-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"liminal": minor
3+
---
4+
5+
Introduce L.handle / rework strand event-handling mechanism.

.github/workflows/liminal.land.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ concurrency:
1313
jobs:
1414
build:
1515
runs-on: ubuntu-latest
16-
timeout-minutes: 1
16+
timeout-minutes: 2
1717
steps:
1818
- uses: actions/checkout@v4
1919
- uses: oven-sh/setup-bun@v1
@@ -28,7 +28,7 @@ jobs:
2828
path: liminal.land/.vitepress/dist
2929
deploy:
3030
runs-on: ubuntu-latest
31-
timeout-minutes: 1
31+
timeout-minutes: 2
3232
environment:
3333
name: github-pages
3434
url: ${{ steps.deployment.outputs.page_url }}

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,42 @@ An effect is a conversation.
2121

2222
```ts
2323
import { FileSystem } from "@effect/platform"
24-
import { Console, Effect } from "effect"
24+
import { Effect } from "effect"
2525
import { L } from "liminal"
2626

2727
const conversation = Effect.gen(function*() {
28-
// Set system.
28+
// Set system instruction.
2929
yield* L.system`You are an expert TypeScript developer.`
3030

31+
// Get a file system service.
32+
const fs = yield* FileSystem.FileSystem
33+
3134
// Append messages.
3235
yield* L.user`
3336
It seems as though a new mental model may arise for
3437
LLM conversation state management.
3538
3639
What are your thoughts on the following DX?
40+
41+
${fs.readFileString("example.ts")}
3742
`
38-
const fs = yield* FileSystem.FileSystem
39-
const code = yield* fs.readFileString("example.ts")
40-
yield* L.user(code)
4143

4244
// Infer and append the assistant message.
43-
const reply = yield* L.assistant
45+
const answer = yield* L.assistant
46+
47+
answer satisfies string
48+
49+
// List all messages.
50+
const messages = yield* L.messages
51+
52+
// Clear all messages.
53+
yield* L.clear
4454

45-
reply satisfies string
46-
}).pipe(L.strand)
55+
// Re-append messages.
56+
yield* L.append(...messages)
57+
}).pipe(
58+
L.strand,
59+
)
4760
```
4861

4962
## Running Examples Locally

bun.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/_logger.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import { Console, Effect, flow, Stream } from "effect"
1+
import { Console, Effect, flow } from "effect"
22
import { L, LPretty } from "liminal"
33

4-
export const logger = L.events.pipe(
5-
Stream.runForEach(
6-
flow(
7-
LPretty.event,
8-
Console.log,
9-
Effect.andThen(Console.log()),
10-
),
11-
),
12-
Effect.fork,
13-
)
4+
export const logger = L.handle(flow(
5+
LPretty.event,
6+
Console.log,
7+
Effect.andThen(Console.log()),
8+
))

examples/activity_suggestions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Effect.gen(function*() {
2424
}
2525
}).pipe(
2626
L.strand,
27+
Effect.scoped,
2728
Effect.provide(ModelLive),
2829
Effect.runFork,
2930
)

examples/basic.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Effect } from "effect"
2+
import { L } from "liminal"
3+
import { ModelLive } from "./_layers.ts"
4+
import { logger } from "./_logger.ts"
5+
6+
Effect.gen(function*() {
7+
yield* logger
8+
yield* L.user`Hey`
9+
yield* L.assistant
10+
}).pipe(
11+
L.strand,
12+
Effect.scoped,
13+
Effect.provide(ModelLive),
14+
Effect.runFork,
15+
)

examples/chaining.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { logger } from "./_logger.ts"
55

66
Effect.gen(function*() {
77
yield* logger
8+
89
yield* L.system`Write persuasive marketing copy for: Buffy The Vampire Slayer.`
910
yield* L.user`Please generate the first draft.`
1011
let copy = yield* L.assistant
@@ -37,6 +38,7 @@ Effect.gen(function*() {
3738
return { copy, qualityMetrics }
3839
}).pipe(
3940
L.strand,
41+
Effect.scoped,
4042
Effect.provide(ModelLive),
4143
Effect.runFork,
4244
)

examples/compare_models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Effect.gen(function*() {
3232
return variants[key]
3333
}).pipe(
3434
L.strand,
35+
Effect.scoped,
3536
Effect.provide([ModelLive, ClientLive]),
3637
Effect.runFork,
3738
)

examples/optimizer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Effect.gen(function*() {
6767
}
6868
}).pipe(
6969
L.strand,
70+
Effect.scoped,
7071
Effect.provide([ModelLive, BunContext.layer]),
7172
Effect.runFork,
7273
)

0 commit comments

Comments
 (0)