# @loremllm/eve

Serve scripted turns over the eve agent protocol from any server.

```bash
npm install @loremllm/eve
```

`createStaticEveHandler` returns a `(request: Request) => Promise<Response>` function. Mount it in a Next.js route handler, Hono, Bun, a service worker, or a stubbed `fetch` in tests.

```ts title="app/api/eve/[[...eve]]/route.ts"
import { createStaticEveHandler } from "@loremllm/eve";

const handler = createStaticEveHandler({
  chunkDelayMs: [20, 50],
  async *mockResponse({ messages }) {
    const last = messages.at(-1);
    const said = last?.parts.find((part) => part.type === "text")?.text;

    yield { type: "text", text: `You said: ${said}` };
  },
});

export { handler as GET, handler as POST };
```

`mockResponse` yields the same parts as [@loremllm/ai-sdk](/docs/packages/ai-sdk), so one generator can back both. Its context matches the AI SDK transport's, except `messages` is the eve session history.

The handler serves `POST /eve/v1/session`, `POST /eve/v1/session/:id`, `GET /eve/v1/session/:id/stream` and `GET /eve/v1/health`. See the [eve endpoint](/docs/endpoints/eve) for the event list. Human-in-the-loop `inputResponses` turns aren't supported yet.

## Options [#options]

| Option                                | What it does                                                                               |
| ------------------------------------- | ------------------------------------------------------------------------------------------ |
| `mockResponse(context)`               | Yields parts for each turn: `text`, `reasoning`, `tool-*`, `dynamic-tool`, `step-start`    |
| `chunkDelayMs`                        | Delay between events                                                                       |
| `autoChunkText`, `autoChunkReasoning` | How text and reasoning split into `message.appended` events                                |
| `sessionStore`                        | Where sessions live. Defaults to `createMemoryEveSessionStore()`                           |
| `cors`                                | `true` (default) allows any origin, `false` sends no CORS headers, `{ origin }` allows one |
| `generateSessionId`, `now`            | Make ids and timestamps deterministic in tests                                             |

## From a mock definition [#from-a-mock-definition]

```ts
import { mockEveHandler } from "@loremllm/eve";

const handler = mockEveHandler(supportBot);
```