@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.
- package/README.md +36 -31
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,55 +1,60 @@
|
|
|
1
1
|
# @anvia/server
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
##
|
|
6
|
-
|
|
7
|
-
Bun 1.3.14 is the currently tested and supported runtime baseline:
|
|
6
|
+
## Install
|
|
8
7
|
|
|
9
8
|
```sh
|
|
10
|
-
|
|
9
|
+
pnpm add @anvia/server @anvia/client @anvia/core @anvia/openai
|
|
11
10
|
```
|
|
12
11
|
|
|
13
|
-
|
|
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
|
-
##
|
|
14
|
+
## Quickstart
|
|
17
15
|
|
|
18
|
-
|
|
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
|
|
26
|
-
if (
|
|
27
|
-
const
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
`
|
|
35
|
-
`
|
|
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
|
-
##
|
|
47
|
+
## Capabilities
|
|
42
48
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
54
|
+
Your application owns routing, authentication, request error handling, and durable storage.
|
|
48
55
|
|
|
49
|
-
|
|
50
|
-
- `createSseStream({ events, ...options })`
|
|
51
|
-
- `createResumableStream({ events, ...options })`
|
|
52
|
-
- `resumeStreamEvents(options)`
|
|
53
|
-
- `createMemoryResumableStreamStore()`
|
|
56
|
+
## Learn more
|
|
54
57
|
|
|
55
|
-
|
|
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.
|
|
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.
|
|
29
|
+
"@vitest/coverage-v8": "4.1.11",
|
|
30
30
|
"tsup": "^8.5.0",
|
|
31
31
|
"typescript": "^5.9.3",
|
|
32
|
-
"vitest": "^4.
|
|
33
|
-
"@anvia/client": "1.2.
|
|
32
|
+
"vitest": "^4.1.11",
|
|
33
|
+
"@anvia/client": "1.2.1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@anvia/client": "^1.2.
|
|
36
|
+
"@anvia/client": "^1.2.1"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsup src/index.ts --format esm --dts --sourcemap --clean",
|