@anvia/server 1.1.4 → 1.1.5

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.
Files changed (2) hide show
  1. package/README.md +36 -31
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,55 +1,60 @@
1
1
  # @anvia/server
2
2
 
3
- Server response helpers for the Anvia client protocol and explicitly generic event streams.
3
+ Serve Anvia completions and Agent runs over HTTP. These framework-neutral response helpers turn
4
+ async events into streaming `Response` objects for Anvia clients, with JSONL, SSE, and replay support.
4
5
 
5
- ## Bun
6
-
7
- Bun 1.3.14 is the currently tested and supported runtime baseline:
6
+ ## Install
8
7
 
9
8
  ```sh
10
- bun add @anvia/server @anvia/client
9
+ pnpm add @anvia/server @anvia/client @anvia/core @anvia/openai
11
10
  ```
12
11
 
13
- Compatibility tests run these helpers through `Bun.serve`, covering framed JSONL and SSE,
14
- resumable replay, cancellation cleanup, and installation from packed package artifacts.
12
+ The quickstart uses OpenAI; choose another provider adapter if needed.
15
13
 
16
- ## Client protocol responses
14
+ ## Quickstart
17
15
 
18
- Adapt native runtime events at the server boundary, then frame them for the client:
16
+ Set `OPENAI_API_KEY` on your server and mount this handler in a framework that accepts Web
17
+ `Request` and `Response` objects:
19
18
 
20
19
  ```ts
21
20
  import { completionToClientStream, parseClientStreamRequest } from "@anvia/client";
22
21
  import { streamCompletion } from "@anvia/core";
22
+ import { OpenAIClient } from "@anvia/openai";
23
23
  import { createClientStreamResponse } from "@anvia/server";
24
24
 
25
- const body = parseClientStreamRequest(await request.json());
26
- if (body.type !== "messages") throw new Error("This completion endpoint accepts messages only.");
27
- const events = completionToClientStream({
28
- events: streamCompletion({ model, messages: body.messages }),
25
+ const apiKey = process.env.OPENAI_API_KEY;
26
+ if (!apiKey) throw new Error("Set OPENAI_API_KEY.");
27
+ const model = new OpenAIClient({ apiKey }).completionModel({
28
+ modelId: "gpt-5",
29
+ api: "responses",
29
30
  });
30
31
 
31
- return createClientStreamResponse({ events }); // JSONL by default
32
+ export async function POST(request: Request): Promise<Response> {
33
+ const body = parseClientStreamRequest(await request.json());
34
+ if (body.type !== "messages") {
35
+ return new Response("This endpoint accepts messages only.", { status: 400 });
36
+ }
37
+ const events = completionToClientStream({
38
+ events: streamCompletion({ model, messages: body.messages, abortSignal: request.signal }),
39
+ });
40
+ return createClientStreamResponse({ events });
41
+ }
32
42
  ```
33
43
 
34
- `createClientStreamResponse({ events, ...options })` always emits `stream_start`, ordered
35
- `stream_event` frames, and `stream_end`, and sets
36
- `x-anvia-stream-protocol: anvia.client.v3`. Use `format: "sse"` for SSE framing.
37
-
38
- For resumable streams, pass `{ resumable: { streamId, store } }` when creating the response and
39
- call `resumeClientStreamResponse({ streamId, after, store })` for a resume request.
44
+ Connect with `createHttpClientTransport` from `@anvia/client`, or use it with the `@anvia/react`
45
+ hooks. Add `format: "sse"` to the response options for SSE instead of the default JSONL.
40
46
 
41
- ## Generic event responses
47
+ ## Capabilities
42
48
 
43
- `createEventStreamResponse({ events, ...options })` and `resumeEventStreamResponse(options)` are
44
- separate, generic helpers. They serialize the event type supplied by the application and do not
45
- claim that it is the Anvia client protocol.
49
+ - Framed client responses with protocol headers and ordered event IDs.
50
+ - Resumable streams backed by a store you provide, with an in-memory store for local use.
51
+ - Separate generic event responses for application-defined protocols.
52
+ - Lower-level JSONL and SSE stream helpers.
46
53
 
47
- The lower-level exports are:
54
+ Your application owns routing, authentication, request error handling, and durable storage.
48
55
 
49
- - `createJsonlStream({ events, ...options })`
50
- - `createSseStream({ events, ...options })`
51
- - `createResumableStream({ events, ...options })`
52
- - `resumeStreamEvents(options)`
53
- - `createMemoryResumableStreamStore()`
56
+ ## Learn more
54
57
 
55
- There are no compatibility aliases for the removed ambiguous response APIs.
58
+ - [Server streaming guide](https://github.com/anvia-hq/anvia/blob/main/docs/packages/server.md)
59
+ - [Client protocol](https://github.com/anvia-hq/anvia/tree/main/packages/client#readme)
60
+ - [React hooks](https://github.com/anvia-hq/anvia/tree/main/packages/react#readme)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anvia/server",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Server-side client protocol and generic event stream responses for Anvia.",
5
5
  "author": "anvia",
6
6
  "license": "MIT",
@@ -26,14 +26,14 @@
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^24.9.1",
29
- "@vitest/coverage-v8": "4.1.5",
29
+ "@vitest/coverage-v8": "4.1.11",
30
30
  "tsup": "^8.5.0",
31
31
  "typescript": "^5.9.3",
32
- "vitest": "^4.0.8",
33
- "@anvia/client": "1.2.0"
32
+ "vitest": "^4.1.11",
33
+ "@anvia/client": "1.2.1"
34
34
  },
35
35
  "peerDependencies": {
36
- "@anvia/client": "^1.2.0"
36
+ "@anvia/client": "^1.2.1"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "tsup src/index.ts --format esm --dts --sourcemap --clean",