Start typing to search the documentation.

Build navigation

Effect

@rewyyn/sdk/effect is the Effect-native embedded SDK. Operations return typed Effects and Streams, and closing the owning Scope releases the router, Location services, fibers, and plugin registrations.

bun add @rewyyn/sdk effect@4.0.1

Create a host

Create the host inside Effect.scoped, then use its generated API groups or the sessions alias.

import { AbsolutePath, Location, Rewyyn } from "@rewyyn/sdk/effect"
import { Effect } from "effect"

const program = Effect.scoped(
  Effect.gen(function* () {
    const rewyyn = yield* Rewyyn.create()
    const session = yield* rewyyn.sessions.create({
      location: Location.Ref.make({ directory: AbsolutePath.make("/workspace") }),
    })
    yield* rewyyn.sessions.prompt({
      sessionID: session.id,
      text: "Review the current changes",
    })
    return session
  }),
)

const session = await Effect.runPromise(program)

The embedded host uses the same schema values, declared errors, request options, and Streams as @rewyyn/client/effect.

const info = yield* rewyyn.server.info()
const sessions = yield* rewyyn.sessions.list()

Stream events

Streaming endpoints return Effect Stream values. Fork consumers in the host Scope when they should run in the background.

import { Effect, Stream } from "effect"

yield* rewyyn.events.subscribe().pipe(
  Stream.runForEach((event) => Effect.logInfo("Rewyyn event", { type: event.type })),
  Effect.forkScoped,
)

Customize

Customize your Rewyyn instance by registering Effect plugins. Use the embedded host to customize agents, models, tools, and other behavior:

import { Plugin } from "@rewyyn/plugin/effect"
import { Effect } from "effect"

const plugin = Plugin.define({
  id: "customize-agent",
  effect: (ctx) =>
    Effect.gen(function* () {
      const agent = ctx.agent
      yield* agent.transform((agents) => {
        agents.update("build", (agent) => {
          agent.description = "Builds features and fixes bugs for our team"
        })
      })
    }),
})

yield* rewyyn.plugin(plugin)

See the full Effect plugins documentation for plugin hooks, transforms, tools, and the complete plugin context.

Layer

Use Rewyyn.layer() when the embedded host should be an application service.

import { Rewyyn } from "@rewyyn/sdk/effect"
import { Effect } from "effect"

const program = Effect.gen(function* () {
  const rewyyn = yield* Rewyyn.Service
  return yield* rewyyn.server.info()
})

const health = await Effect.runPromise(program.pipe(Effect.provide(Rewyyn.layer())))