@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 CHANGED
@@ -1,26 +1,39 @@
1
1
  # @libregrid/ai-gateway
2
2
 
3
- A small provider-neutral HTTP gateway for LibreGrid grid commands. It validates
4
- the browser request, calls an injected provider through one tiny port, validates
5
- the provider output against the live grid schema, and returns the versioned
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
- ## Choose the lowest-burden integration
7
+ [Documentation and examples](https://libregrid.dev/ai-toolkit)
9
8
 
10
- | Your server environment | Integration work |
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
- This keeps framework and identity policy outside LibreGrid without making each
18
- consumer rebuild the provider plumbing.
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=... OPENAI_MODEL=gpt-5.6 npx libregrid-ai-gateway
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
- zero-code deployment. Copy `.env.example`, set the provider key in your secret
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
- createGridCommandHandler,
44
- createOpenAiResponsesProvider,
45
- } from '@libregrid/ai-gateway';
46
-
47
- const handler = createGridCommandHandler({
48
- provider: createOpenAiResponsesProvider({
49
- apiKey: () => secrets.OPENAI_API_KEY,
50
- model: 'gpt-5.6',
51
- }),
52
- authorize: (request) => verifyYourSession(request),
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. Inject another `GridModelProvider`
58
- for Azure OpenAI, Anthropic, Gemini, Ollama, vLLM, LocalAI, or an internal model
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
- Keep `OPENROUTER_REQUIRE_PARAMETERS` on. OpenRouter serves one model through
80
- more than one provider. Only some of those providers apply a JSON Schema as a
81
- constraint. The others apply it as a hint. This flag tells OpenRouter to use
82
- only the providers that apply the constraint.
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 every provider response, and the browser validates it a
85
- second time. A weak provider therefore causes a clean `INVALID_PROVIDER_OUTPUT`
86
- failure, not a bad grid change.
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 variable, the
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
- - Set `TURNSTILE_SECRET_KEY` and the public deployment's exact
133
- `TURNSTILE_HOSTNAMES` before you expose the endpoint publicly. An unset
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 open-source
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.
@@ -11,6 +11,8 @@ var GRID_STATE_KEYS = [
11
11
  "columnVisibility",
12
12
  "columnHeaderName",
13
13
  "filter",
14
+ "find",
15
+ "quickFilter",
14
16
  "focusedCell",
15
17
  "pagination",
16
18
  "rowPinning",
package/dist/server.js CHANGED
@@ -20,6 +20,8 @@ var GRID_STATE_KEYS = [
20
20
  "columnVisibility",
21
21
  "columnHeaderName",
22
22
  "filter",
23
+ "find",
24
+ "quickFilter",
23
25
  "focusedCell",
24
26
  "pagination",
25
27
  "rowPinning",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libregrid/ai-gateway",
3
- "version": "1.3.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.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",