@libregrid/ai-gateway 1.3.3 → 1.3.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 +60 -46
- package/dist/conformanceCli.js +2 -0
- package/dist/server.js +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,26 +1,39 @@
|
|
|
1
1
|
# @libregrid/ai-gateway
|
|
2
2
|
|
|
3
|
-
A
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
protocol envelope. No provider credential is accepted from the browser.
|
|
3
|
+
A server-side HTTP handler and command-line service for LibreGrid AI commands.
|
|
4
|
+
It validates requests and provider output against the live grid schema.
|
|
5
|
+
Provider credentials and model selection stay on the server.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
[Documentation and examples](https://libregrid.dev/ai-toolkit)
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
| --- | --- |
|
|
12
|
-
| Any language, no AI route desired | Run the included container as a private sidecar/service and reverse-proxy `/v1/grid-command` through your existing authenticated API boundary. |
|
|
13
|
-
| Node or a Node framework with Web `Request`/`Response` support | Mount `createGridCommandHandler()` in one route; provider and validation behavior remain inside this package. |
|
|
14
|
-
| Java, C#, Go, Python, Rust, PHP, Ruby, or another stack | Generate a route stub from the shipped OpenAPI document, or call the sidecar. Run the conformance executable against the result. |
|
|
15
|
-
| Custom model/provider protocol | Implement only the small `GridModelProvider.complete()` port; the browser protocol, limits, validation, errors, and state safety remain unchanged. |
|
|
9
|
+
## Install
|
|
16
10
|
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
For the CLI or a Node application (Node.js `>=20.19.0`):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @libregrid/ai-gateway
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The gateway belongs on the server; do not bundle it in a TypeScript browser or
|
|
18
|
+
Angular application. Use [`@libregrid/ai-client`](../ai-client/README.md) there.
|
|
19
|
+
|
|
20
|
+
## Integration options
|
|
21
|
+
|
|
22
|
+
| Your server environment | Integration work |
|
|
23
|
+
| -------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| Any language, no AI route desired | Run the included container as a private sidecar/service and reverse-proxy `/v1/grid-command` through your existing authenticated API boundary. |
|
|
25
|
+
| Node or a Node framework with Web `Request`/`Response` support | Mount `createGridCommandHandler()` in one route; provider and validation behavior remain inside this package. |
|
|
26
|
+
| Java, C#, Go, Python, Rust, PHP, Ruby, or another stack | Generate a route stub from the shipped OpenAPI document, or call the sidecar. Run the conformance executable against the result. |
|
|
27
|
+
| Custom model/provider protocol | Implement the `GridModelProvider.complete()` interface; the browser protocol, limits, validation, errors, and state safety remain unchanged. |
|
|
28
|
+
|
|
29
|
+
Choose the handler for an existing Node application, the CLI or container for
|
|
30
|
+
a separate service, or the OpenAPI contract when implementing your own server.
|
|
19
31
|
|
|
20
32
|
## Run the included OpenAI gateway
|
|
21
33
|
|
|
22
34
|
```bash
|
|
23
|
-
OPENAI_API_KEY
|
|
35
|
+
# Set OPENAI_API_KEY and OPENAI_MODEL in your server environment first.
|
|
36
|
+
npx --package=@libregrid/ai-gateway libregrid-ai-gateway
|
|
24
37
|
```
|
|
25
38
|
|
|
26
39
|
It exposes `POST /v1/grid-command` and `GET /health` on `127.0.0.1:8787` by
|
|
@@ -34,29 +47,32 @@ corresponding optional routing headers. These values and `OPENAI_MODEL` are
|
|
|
34
47
|
server configuration; none are accepted from browser requests.
|
|
35
48
|
|
|
36
49
|
The included Dockerfile and `docker-compose.example.yml` provide the same
|
|
37
|
-
|
|
50
|
+
standalone deployment. Copy `.env.example`, set the provider key in your secret
|
|
38
51
|
manager or local environment (never in source control), then build from the
|
|
39
52
|
repository root.
|
|
40
53
|
|
|
41
54
|
```ts
|
|
42
|
-
import {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
55
|
+
import { createGridCommandHandler, createOpenAiResponsesProvider } from '@libregrid/ai-gateway';
|
|
56
|
+
|
|
57
|
+
export function createApplicationGateway(
|
|
58
|
+
apiKey: () => string,
|
|
59
|
+
model: string,
|
|
60
|
+
authorize: (request: Request) => boolean | Promise<boolean>,
|
|
61
|
+
) {
|
|
62
|
+
return createGridCommandHandler({
|
|
63
|
+
provider: createOpenAiResponsesProvider({ apiKey, model }),
|
|
64
|
+
authorize,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
54
67
|
```
|
|
55
68
|
|
|
69
|
+
Pass your secret reader, configured model, and session authorization function
|
|
70
|
+
to `createApplicationGateway`; mount the returned handler at
|
|
71
|
+
`POST /v1/grid-command` using your server framework’s route adapter.
|
|
72
|
+
|
|
56
73
|
The OpenAI adapter uses the Responses API strict `text.format` JSON Schema
|
|
57
|
-
contract. There is no OpenAI SDK dependency.
|
|
58
|
-
|
|
59
|
-
gateway; the HTTP contract and browser package do not change.
|
|
74
|
+
contract. There is no OpenAI SDK dependency. For other provider protocols, implement `GridModelProvider`. The grid-command
|
|
75
|
+
HTTP contract and browser client can stay the same.
|
|
60
76
|
|
|
61
77
|
`createMockProvider()` provides a deterministic, network-free adapter for CI,
|
|
62
78
|
local development, and contract tests. A production-oriented Dockerfile is
|
|
@@ -76,19 +92,20 @@ OPENAI_MODEL=openrouter/free
|
|
|
76
92
|
OPENROUTER_REQUIRE_PARAMETERS=true
|
|
77
93
|
```
|
|
78
94
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
95
|
+
The OpenRouter-specific `OPENROUTER_REQUIRE_PARAMETERS` setting requests
|
|
96
|
+
providers that support the supplied parameters. Check that your chosen model
|
|
97
|
+
and endpoint support structured output; provider validation still runs on
|
|
98
|
+
every response.
|
|
83
99
|
|
|
84
|
-
The gateway validates
|
|
85
|
-
|
|
86
|
-
|
|
100
|
+
The gateway validates provider responses, and the browser validates them again.
|
|
101
|
+
Output that fails schema validation produces `INVALID_PROVIDER_OUTPUT`. A
|
|
102
|
+
schema-valid response can still misunderstand user intent; use proposal review
|
|
103
|
+
in the browser when your workflow calls for it.
|
|
87
104
|
|
|
88
105
|
Verify any implementation—Node or otherwise—with the shipped executable:
|
|
89
106
|
|
|
90
107
|
```bash
|
|
91
|
-
libregrid-ai-conformance https://your-api.example/v1/grid-command
|
|
108
|
+
npx --package=@libregrid/ai-gateway libregrid-ai-conformance https://your-api.example/v1/grid-command
|
|
92
109
|
```
|
|
93
110
|
|
|
94
111
|
If the endpoint needs a bearer or application token, put the complete value in
|
|
@@ -97,8 +114,7 @@ If the endpoint needs a bearer or application token, put the complete value in
|
|
|
97
114
|
## Guard the public endpoint with Turnstile
|
|
98
115
|
|
|
99
116
|
Set `TURNSTILE_SECRET_KEY` and `TURNSTILE_HOSTNAMES` to require a valid
|
|
100
|
-
Cloudflare Turnstile token on every request. Without the secret
|
|
101
|
-
gateway accepts every request with no check. If the secret is set without an
|
|
117
|
+
Cloudflare Turnstile token on every request. Without that variable, the CLI does not perform a bot check. If the secret is set without an
|
|
102
118
|
approved hostname, the process refuses to start.
|
|
103
119
|
|
|
104
120
|
Get the secret key from the Turnstile widget settings in the Cloudflare
|
|
@@ -111,7 +127,7 @@ put it in browser code. You may commit it to source control.
|
|
|
111
127
|
```bash
|
|
112
128
|
TURNSTILE_SECRET_KEY=0x0000000000000000000000000000000AA \
|
|
113
129
|
TURNSTILE_HOSTNAMES=localhost,127.0.0.1 \
|
|
114
|
-
npx libregrid-ai-gateway
|
|
130
|
+
npx --package=@libregrid/ai-gateway libregrid-ai-gateway
|
|
115
131
|
```
|
|
116
132
|
|
|
117
133
|
The browser client sends the token in the `x-turnstile-token` header. The
|
|
@@ -129,9 +145,8 @@ line before you expose the endpoint publicly.
|
|
|
129
145
|
|
|
130
146
|
- Authenticate the caller before invoking the handler. The gateway deliberately
|
|
131
147
|
does not invent an identity system for your application.
|
|
132
|
-
-
|
|
133
|
-
|
|
134
|
-
secret means the endpoint accepts every request with no bot check.
|
|
148
|
+
- If using Turnstile, configure its secret and allowed hostnames. Bot checks
|
|
149
|
+
supplement application authentication; they do not identify an authorized user.
|
|
135
150
|
- Store `OPENAI_API_KEY` (or another provider credential) only in server-side
|
|
136
151
|
secret storage. The protocol has no credential or model-name request field.
|
|
137
152
|
- Treat the live grid schema, current GridState, command, and context metadata
|
|
@@ -151,6 +166,5 @@ line before you expose the endpoint publicly.
|
|
|
151
166
|
|
|
152
167
|
## License
|
|
153
168
|
|
|
154
|
-
MIT — see [LICENSE](./LICENSE). LibreGrid is an independent
|
|
169
|
+
MIT — see [LICENSE](./LICENSE) and [NOTICE](./NOTICE). LibreGrid is an independent
|
|
155
170
|
project and is not affiliated with, endorsed by, or sponsored by AG Grid Ltd.
|
|
156
|
-
See [NOTICE](./NOTICE) for third-party attribution.
|
package/dist/conformanceCli.js
CHANGED
package/dist/server.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libregrid/ai-gateway",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "Provider-neutral AI gateway for AG Grid Community — part of LibreGrid",
|
|
5
5
|
"keywords": ["libregrid", "ag-grid", "ai", "byom", "gateway", "openai"],
|
|
6
6
|
"homepage": "https://github.com/libregrid/libregrid#readme",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"type": "module",
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"engines": { "node": ">=20.19.0" },
|
|
17
|
-
"dependencies": { "@libregrid/ai-protocol": "^1.3.
|
|
17
|
+
"dependencies": { "@libregrid/ai-protocol": "^1.3.5" },
|
|
18
18
|
"files": ["dist", "Dockerfile", "docker-compose.example.yml", ".env.example", "LICENSE", "NOTICE", "README.md"],
|
|
19
19
|
"bin": {
|
|
20
20
|
"libregrid-ai-gateway": "./dist/server.js",
|