Start typing to search the documentation.

Build navigation

Overview

@rewyyn/sdk hosts Rewyyn directly inside your application. Unlike the network client, it assembles the Rewyyn server and routes API calls through its HTTP router in memory. It opens no HTTP listener and adds no network hop between the client and server.

For Cloudflare Durable Objects, see the Cloudflare guide.

Install the SDK:

bun add @rewyyn/sdk

Create a host

Rewyyn.create() returns an explicitly owned host. Use await using to release its router, Location services, fibers, and scoped plugin registrations:

import { Rewyyn } from "@rewyyn/sdk"

await using rewyyn = await Rewyyn.create()
const session = await rewyyn.sessions.create({
  location: { directory: "/workspace" },
})

await rewyyn.sessions.prompt({
  sessionID: session.id,
  text: "Review the current changes",
})

Call await rewyyn.close() explicitly when explicit resource management is not available.

The embedded host uses the same Promise values, declared errors, request options, and AsyncIterable streams as @rewyyn/client. It exposes the full generated client and adds the convenience aliases sessions and events for the session and event groups.

Worktrees

Worktree operations require a projectID. Create and refresh load configuration and plugins from the project’s saved canonical checkout. List reads saved inventory only; remove activates canonical plugins and uses the recorded strategy, failing if that strategy is unavailable.

const projectID = session.projectID
const worktree = await rewyyn.worktree.create({ projectID, name: "task" })
await rewyyn.worktree.refresh({ projectID })
await rewyyn.worktree.remove({ projectID, directory: worktree.directory, force: false })

Refresh discovers worktrees across known checkout roots using all available strategies. Register a custom strategy through a plugin’s worktree transform.

Stream events

for await (const event of rewyyn.events.subscribe()) {
  console.log(event.type)
}

Pass an AbortSignal through the generated request options, or leave an iteration to cancel its response body.

Customize

Customize your Rewyyn instance by registering plugins. Pass plugins to Rewyyn.create() to customize agents, models, tools, and other behavior when the embedded host starts:

import { Plugin } from "@rewyyn/plugin"
import { Rewyyn } from "@rewyyn/sdk"

const plugin = Plugin.define({
  id: "customize-agent",
  async setup(ctx) {
    await ctx.agent.transform((agents) => {
      agents.update("build", (agent) => {
        agent.description = "Builds features and fixes bugs for our team"
      })
    })
  },
})

await using rewyyn = await Rewyyn.create({ plugins: [plugin] })

Call await rewyyn.plugin(plugin) to register another plugin after startup.

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