@baseera/node 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +356 -2
- package/dist/cli.js +340 -0
- package/dist/index.cjs +541 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +306 -0
- package/dist/index.d.ts +306 -0
- package/dist/index.js +504 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 GrayNest
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,357 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @baseera/node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @baseera/node
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
No peer dependencies. Node 20 or later. It also installs the `baseera` command (see "`baseera eval run`" below).
|
|
10
|
+
|
|
11
|
+
Server-side helpers for host apps. Server only: a secret key (`sk_…`) must never reach the browser.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { signUserToken, verifyFinish } from "@baseera/node";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## `signUserToken`
|
|
18
|
+
|
|
19
|
+
Signs the short-lived token your browser sends with every request, so Baseera knows who the user is.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
const token = await signUserToken(
|
|
23
|
+
{ userId: user.id, tenantId: org.id, name: user.name, locale: "ar" },
|
|
24
|
+
process.env.BASEERA_SECRET_KEY!,
|
|
25
|
+
);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
To keep some documents from some users, add the user's `role` and any `claims` you vouch for (`{ role: "staff", claims: { plan: "pro", groups: ["a", "b"] } }`) and give the documents `access` rules when you push them (see Knowledge below). Claims are signed with the rest of the token, so users cannot choose their own. A user whose token lacks a claim never gets a restricted document from a search, a citation or a source link.
|
|
29
|
+
|
|
30
|
+
## `verifyFinish`: guard your finish route
|
|
31
|
+
|
|
32
|
+
In immersive mode, `finish()` in the browser first asks Baseera to record the finish and gets a single-use **receipt**, then calls your `finish.action({ receipt, override })`. Your action sends the receipt to your route, and your route must call `verifyFinish` before it changes anything.
|
|
33
|
+
|
|
34
|
+
### What this guarantees (and what it doesn't)
|
|
35
|
+
|
|
36
|
+
Check results run in the browser, so Baseera cannot vouch that they are true. The guarantee is narrower and explicit:
|
|
37
|
+
|
|
38
|
+
- the finish was **recorded by Baseera first**, for this record and agent, once, in the last 10 minutes;
|
|
39
|
+
- the record says which blocking checks were open (as the browser reported them), who finished, when, and the written override reason (10 to 1,000 characters), which must cover every open check;
|
|
40
|
+
- if you pass your own **server-computed** blocking check ids (`openBlocking`), the override must cover those too. That is the part that does not depend on the browser, so compute them from your own data and always pass them.
|
|
41
|
+
|
|
42
|
+
A route that never calls `verifyFinish` gets none of this.
|
|
43
|
+
|
|
44
|
+
### Example (Next.js route handler)
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
// app/api/invoices/[id]/send/route.ts
|
|
48
|
+
import { verifyFinish } from "@baseera/node";
|
|
49
|
+
|
|
50
|
+
export async function POST(request: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
51
|
+
const { id } = await params;
|
|
52
|
+
const { receipt } = await request.json();
|
|
53
|
+
const invoice = await db.invoice.findUnique({ where: { id } });
|
|
54
|
+
if (!invoice || invoice.status === "closed") return Response.json({ error: "closed" }, { status: 409 });
|
|
55
|
+
|
|
56
|
+
// Your own blocking checks, computed here from your data, not taken from the browser.
|
|
57
|
+
const blocking: string[] = [];
|
|
58
|
+
if (!invoice.taxId) blocking.push("tax-id-missing");
|
|
59
|
+
if (invoice.total !== sumOfLines(invoice)) blocking.push("total-mismatch");
|
|
60
|
+
|
|
61
|
+
const result = await verifyFinish({
|
|
62
|
+
receipt,
|
|
63
|
+
entity: { type: "invoice", ref: id },
|
|
64
|
+
openBlocking: blocking, // the override must cover these
|
|
65
|
+
agentId: process.env.BASEERA_AGENT_ID!,
|
|
66
|
+
secretKey: process.env.BASEERA_SECRET_KEY!,
|
|
67
|
+
baseUrl: process.env.BASEERA_RUNTIME_URL!,
|
|
68
|
+
});
|
|
69
|
+
if (!result.ok) return Response.json({ error: result.code }, { status: result.code === "unavailable" ? 503 : 409 });
|
|
70
|
+
|
|
71
|
+
// result.finish: { userId, tenantId, openBlocking, override: { reason, checks } | null, createdAt }
|
|
72
|
+
await db.invoice.update({ where: { id }, data: { status: "sent", sentBy: result.finish.userId, overrideReason: result.finish.override?.reason } });
|
|
73
|
+
return Response.json({ ok: true });
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The same works in Express: read the receipt from `req.body`, call `verifyFinish`, answer 409 or 503 when it is not ok.
|
|
78
|
+
|
|
79
|
+
On the browser side:
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
useBaseeraImmersive({
|
|
83
|
+
// …
|
|
84
|
+
finish: {
|
|
85
|
+
label: "Send invoice",
|
|
86
|
+
closed: invoice.status === "closed", // no finish button on closed records
|
|
87
|
+
action: ({ receipt }) => fetch(`/api/invoices/${invoice.id}/send`, { method: "POST", body: JSON.stringify({ receipt }) }).then(assertOk),
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Result
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
{ ok: true, finish: { userId, tenantId, openBlocking, override: { reason, checks } | null, createdAt } }
|
|
96
|
+
{ ok: false, code: "receipt_not_found" | "entity_mismatch" | "receipt_expired" | "receipt_used" | "override_required" | "unavailable" }
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`verifyFinish` never throws and **fails closed**: a network error, a timeout (5 s), a redirect, a non-200 status, a body that is not JSON or is malformed, a bad key or a non-HTTPS `baseUrl` (except `localhost`) all return `{ ok: false, code: "unavailable" }`. Treat `unavailable` as a refusal and let the person retry. A successful call uses the receipt up: if your route fails after it, the person finishes again to get a new one (`receipt_used` otherwise).
|
|
100
|
+
|
|
101
|
+
It signs a fresh 60-second server token with your secret key for every call (purpose `verify_finish`, audience your agent). The key and the token are never logged or put in an error.
|
|
102
|
+
|
|
103
|
+
## `purgeTenantKnowledge`: forget a tenant
|
|
104
|
+
|
|
105
|
+
Deletes everything one of your tenants has in your organization's knowledge bases (sources, documents, chunks, embeddings). Knowledge shared by all tenants and other tenants are not touched. Call it from your server when a customer leaves or asks to be forgotten.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { purgeTenantKnowledge } from "@baseera/node";
|
|
109
|
+
|
|
110
|
+
const result = await purgeTenantKnowledge({
|
|
111
|
+
tenantId: org.id, // the same id you put in your users' tokens
|
|
112
|
+
agentId: process.env.BASEERA_AGENT_ID!,
|
|
113
|
+
secretKey: process.env.BASEERA_SECRET_KEY!,
|
|
114
|
+
baseUrl: process.env.BASEERA_RUNTIME_URL!,
|
|
115
|
+
});
|
|
116
|
+
if (result.ok) console.log(result.record); // { id, tenantId, sources, chunks, requestedAt, completedAt }
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Otherwise `{ ok: false, code: "invalid_server_token" | "invalid_request" | "unavailable" }`: nothing is known to be deleted, so retry on `unavailable` (purging twice is harmless). The record is also in the deletion log in the console (ids and counts only). Original files leave storage within about a minute. The token it signs has the purpose `purge_knowledge`, so it can't be used for anything else.
|
|
120
|
+
|
|
121
|
+
## `createBaseera().signal`: tell Baseera what happened while nobody was looking
|
|
122
|
+
|
|
123
|
+
Some events have no user on the page: a payment arrives, a carrier updates a shipment, a document finishes processing. Send them from your backend so the record's AI checks run again the next time someone opens it, with the event in front of them.
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { createBaseera } from "@baseera/node";
|
|
127
|
+
|
|
128
|
+
const baseera = createBaseera({ agentId: process.env.BASEERA_AGENT_ID!, secretKey: process.env.BASEERA_SECRET_KEY!, baseUrl: process.env.BASEERA_RUNTIME_URL! });
|
|
129
|
+
|
|
130
|
+
// The same entity { type, ref } you give <BaseeraImmersive>. Use your own event id as the idempotency key.
|
|
131
|
+
const result = await baseera.signal(
|
|
132
|
+
{ type: "invoice", ref: "INV-7" },
|
|
133
|
+
"payment.received",
|
|
134
|
+
{ amount: 120.5, currency: "SAR", method: "bank_transfer" },
|
|
135
|
+
{ idempotencyKey: `payment-${payment.id}`, tenantId: org.id }, // both optional
|
|
136
|
+
);
|
|
137
|
+
// { ok: true, duplicate: false } | { ok: false, code: "invalid_request" | "invalid_server_token" | "idempotency_conflict" | "rate_limited" | "unavailable", retryAfter? }
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
What to know:
|
|
141
|
+
|
|
142
|
+
- **Server only.** It signs a 60-second token of purpose `signal` with your secret key, so a publishable key or a browser can't send a signal. A secret key must never reach the browser.
|
|
143
|
+
- **Small, flat, secret-free data.** `name` is an identifier (letters, digits, `_ . : -`, up to 64). `data` is a flat object: up to 20 keys, values are strings (up to 500 characters), numbers, booleans or `null`, 2 KB in all. A key named like a secret (`password`, `token`, `apiKey`) or a value shaped like one is refused, and the SDK refuses it before anything is sent (`invalid_request`).
|
|
144
|
+
- **Retries are safe.** The SDK sends an `Idempotency-Key` (yours, or a random one) and tries once more after a network error or a 5xx. The same key with the same content answers `duplicate: true`; the same key with different content is `idempotency_conflict`. Nothing here throws.
|
|
145
|
+
- **What it does.** The signal is kept for the record (30 days, the newest 50 per record), marks the record's cached AI checks stale, and the checks see the newest five signals as untrusted data, never as instructions. Only sessions of your `tenantId` see a tenant's signal. Limits: 600 calls a minute per secret key and 1,200 per agent. The Immersive page of the console lists the latest signals (names, records and times; values are not shown).
|
|
146
|
+
- There is no Queue in Baseera yet, so a signal does not add a queue item.
|
|
147
|
+
|
|
148
|
+
## `createBaseera().kb`: push knowledge from your system
|
|
149
|
+
|
|
150
|
+
Keep a knowledge base in step with your own data: documents, records, pages. Each item has an `externalId` of your choosing; pushing it again replaces the old version, and content that hasn't changed isn't embedded again.
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { createBaseera } from "@baseera/node";
|
|
154
|
+
|
|
155
|
+
const baseera = createBaseera({
|
|
156
|
+
agentId: process.env.BASEERA_AGENT_ID!,
|
|
157
|
+
secretKey: process.env.BASEERA_SECRET_KEY!, // server only
|
|
158
|
+
baseUrl: process.env.BASEERA_RUNTIME_URL!,
|
|
159
|
+
});
|
|
160
|
+
const knowledgeBase = process.env.BASEERA_KNOWLEDGE_BASE_ID!; // from the console; must belong to the agent's organization
|
|
161
|
+
|
|
162
|
+
// Text or a record. metadata is stored on every chunk (and is meant for filtering later).
|
|
163
|
+
const one = await baseera.kb.upsert({
|
|
164
|
+
knowledgeBase,
|
|
165
|
+
externalId: "policy-7",
|
|
166
|
+
title: "Refund policy",
|
|
167
|
+
text: policy.markdown,
|
|
168
|
+
metadata: { lang: "en", tags: ["policy"], version: 3 },
|
|
169
|
+
tenantId: org.id, // optional: visible to this tenant only
|
|
170
|
+
access: { roles: ["staff"] }, // optional: only users whose token has role "staff" (or claims.roles) find it; null removes the rules
|
|
171
|
+
});
|
|
172
|
+
// { ok: true, item: { externalId: "policy-7", status: "queued" | "unchanged" | "rejected", error? } }
|
|
173
|
+
|
|
174
|
+
// A page Baseera fetches (public https only), or a file (PDF, DOCX, Markdown, TXT, HTML, CSV; up to 50 MB).
|
|
175
|
+
await baseera.kb.upsert({ knowledgeBase, externalId: "faq", title: "FAQ", url: "https://example.com/faq" });
|
|
176
|
+
await baseera.kb.upsert({ knowledgeBase, externalId: "manual", title: "User manual", file: { name: "manual.pdf", data: bytes } });
|
|
177
|
+
|
|
178
|
+
// Many at once: batches of up to 100 are made for you, results come back in input order.
|
|
179
|
+
const many = await baseera.kb.upsertMany(records.map((r) => ({ knowledgeBase, externalId: r.id, title: r.title, text: r.body })));
|
|
180
|
+
if (!many.ok) retryLater(many.retryAfter); // the items decided before the failure are in many.results
|
|
181
|
+
|
|
182
|
+
await baseera.kb.status({ knowledgeBase, externalId: "policy-7" }); // { ok: true, status: { status: "ready", version, searchableVersion, chunkCount, errorCode } }
|
|
183
|
+
await baseera.kb.delete({ knowledgeBase, externalId: "policy-7", tenantId: org.id }); // { ok: true, deleted: true }
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Nothing here throws and nothing logs a key or token. A whole call that fails is `{ ok: false, code }` with `code` one of `invalid_server_token`, `invalid_request`, `knowledge_base_not_found`, `message_too_large`, `rate_limited` (with `retryAfter` seconds) or `unavailable` (retry). A single item that is refused is `{ status: "rejected", error: { code, message } }` and never fails its neighbours. `queued` means a new version is being processed (the previous version keeps answering until it is ready, and if it fails; `status().searchableVersion` says which version is in use); `unchanged` means the content, title and metadata are the same as what is already indexed. Limits: 1,000 items a minute per secret key, `text` up to 1,000,000 characters (send longer documents as a file), metadata up to 20 keys. Files are hashed, reserved and uploaded straight to private storage for you (they never travel through Baseera's JSON API). The token it signs has the purpose `kb_write`, so it can't be used for anything else.
|
|
187
|
+
|
|
188
|
+
### Webhooks: know when an item is ready
|
|
189
|
+
|
|
190
|
+
Set a webhook address in the console (Knowledge page, owners and admins). When a pushed item becomes ready or fails, Baseera calls it with a signed body of ids and a status, never document text. Verify it with the raw body:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
import { verifyWebhook } from "@baseera/node";
|
|
194
|
+
|
|
195
|
+
export async function POST(request: Request) {
|
|
196
|
+
const raw = await request.text(); // the exact bytes, before any JSON parsing
|
|
197
|
+
const result = await verifyWebhook(raw, request.headers.get("baseera-signature"), process.env.BASEERA_WEBHOOK_SECRET!, { toleranceSec: 300 });
|
|
198
|
+
if (!result.ok) return new Response(null, { status: 400 });
|
|
199
|
+
const { id, type, data } = result.event; // knowledge.item.ready | knowledge.item.failed; data: { externalId, tenantId, status, errorCode, … }
|
|
200
|
+
if (await alreadyHandled(id)) return new Response(null, { status: 200 }); // deliveries are retried: ignore a repeated id
|
|
201
|
+
await handle(type, data);
|
|
202
|
+
return new Response(null, { status: 200 });
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Finish webhook: the trail of a finished record
|
|
207
|
+
|
|
208
|
+
Give an agent a webhook address on its Immersive page (owners and admins). When someone finishes a record, Baseera POSTs `immersive.record.finished` with the record's trail (flags, fixes, approvals, overrides, the finish, the override reason and the user). In a Fetch-style handler pass the `Request` itself:
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
import { verifyWebhook } from "@baseera/node";
|
|
212
|
+
|
|
213
|
+
export async function POST(request: Request) {
|
|
214
|
+
const result = await verifyWebhook(request, process.env.BASEERA_FINISH_WEBHOOK_SECRET!); // body and signature header are read for you
|
|
215
|
+
if (!result.ok) return new Response(null, { status: 400 });
|
|
216
|
+
if (result.event.type === "immersive.record.finished") {
|
|
217
|
+
const { entity, receiptId, trail, truncated } = result.event.data; // `truncated`: the oldest events were left out
|
|
218
|
+
await saveTrail(entity, receiptId, trail);
|
|
219
|
+
}
|
|
220
|
+
return new Response(null, { status: 200 }); // answer within 5 seconds; a failure is retried once
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
In Node frameworks pass the raw body and header: `verifyWebhook(rawBody, req.headers["baseera-signature"], secret)`. The address must be a public https address (private, loopback, link-local and metadata addresses are refused when it is saved and again at every send; redirects are not followed). The payload is up to about 250 KB. It is the user's browser's account of what happened, not proof: for a guarantee, confirm the receipt (`receiptId`) with `verifyFinish`.
|
|
225
|
+
|
|
226
|
+
The same address also receives `eval.run.finished` (see below); handlers should ignore event types they don't know.
|
|
227
|
+
|
|
228
|
+
`verifyWebhook` checks the HMAC-SHA256 signature in constant time, refuses a timestamp outside `toleranceSec` (default 300 seconds, replay protection) and never throws. Answer with any `2xx`; Baseera retries other answers six times over about an hour.
|
|
229
|
+
|
|
230
|
+
## `baseera eval run`: run an agent's tests from CI
|
|
231
|
+
|
|
232
|
+
The package installs a `baseera` command. It starts one of an agent's eval suites, waits for it, prints a summary and ends with an exit code your pipeline can act on, optionally writing a JUnit or JSON report.
|
|
233
|
+
|
|
234
|
+
```sh
|
|
235
|
+
export BASEERA_AGENT_ID=6f1c1f3e-2b7a-4d3e-9a51-0c1d2e3f4a5b # the agent's id from the console (a uuid)
|
|
236
|
+
export BASEERA_SECRET_KEY=sk_... # the agent's secret key: a CI secret, never in the repo
|
|
237
|
+
export BASEERA_URL=https://runtime.baseera.dev # the runtime's URL
|
|
238
|
+
|
|
239
|
+
npx baseera eval run --suite core --yes # the suite "core" on the version in production
|
|
240
|
+
npx baseera eval run --suite core --target draft --repeats 3 --min-pass-rate 90 \
|
|
241
|
+
--report junit --out reports/baseera.xml --yes
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
| Option | Meaning |
|
|
245
|
+
|---|---|
|
|
246
|
+
| `--agent <id>` | The agent's **id** (uuid). Default `$BASEERA_AGENT_ID`. Agent names are not unique, so there is no lookup by name: `--agent billing-copilot` in examples stands for the id. |
|
|
247
|
+
| `--suite <name\|id>` | A suite of that agent by name (unique per agent, case-insensitive; Arabic names work) or by id. |
|
|
248
|
+
| `--target <t>` | `production` (default), `draft` (the draft as it is when the run starts) or a version such as `v7`. |
|
|
249
|
+
| `--repeats <1-5>` | Run every case this many times (default 1). |
|
|
250
|
+
| `--min-pass-rate <0-100>` | Fail below this pass rate. Default: the agent's own minimum for publishing, which an owner or admin sets on the Deploy page (100 unless changed). |
|
|
251
|
+
| `--report junit\|json` | Write a report. With `--out <file>` it goes to the file; without, to standard output (and the summary to standard error). |
|
|
252
|
+
| `--timeout <seconds>` | Stop waiting after this long (10 to 3600, default 600). The run itself keeps going; stop it in the console if you don't want the spend. |
|
|
253
|
+
| `--yes` | Start the run. **A run calls the model with your organization's own provider key and costs money**, so without `--yes` the command only prints the estimate and exits 2. |
|
|
254
|
+
| `--url <url>` | The runtime's URL. Default `$BASEERA_URL`. Must be https (http only for localhost). |
|
|
255
|
+
|
|
256
|
+
**Exit codes.** `0` the suite reached the pass rate. `1` it did not (passed attempts of all attempts, where an attempt that could not finish counts as not passed). `2` anything else: bad usage or configuration, a rejected key, a run already in progress for the agent, a rate or cost limit, a run that could not finish (for example the provider rejected the key), a stopped run, a timeout, or a report that could not be written. A pipeline that must not pass on infrastructure trouble should treat any non-zero code as a failure; one that wants to tell "the agent regressed" from "the check could not run" can look for `1`.
|
|
257
|
+
|
|
258
|
+
**What it does and doesn't send.** It signs a fresh 60-second server token (purpose `eval_run`) with the secret key for every request and sends the token and the agent id, never the key. It never prints the key or the token and doesn't follow redirects. The runtime limits a key to 120 calls a minute, one run at a time per agent, 500 attempts per run and 30 runs per agent per hour. The API behind it (`POST /v0/evals/runs`, `GET /v0/evals/runs/{id}`) is documented in PROTOCOL.md.
|
|
259
|
+
|
|
260
|
+
**JUnit.** One `testsuite` for the run and one `testcase` per finished attempt (named after the case, `#2` and so on when `--repeats` is above 1), with a `failure` for an attempt that failed a check and an `error` for one that could not finish. Names and messages are escaped, characters XML can't hold are dropped, Arabic text is kept as it is. The suite's properties carry the run id, target, model, pass rate and the verdict.
|
|
261
|
+
|
|
262
|
+
A GitHub Actions job that blocks a pull request on the suite:
|
|
263
|
+
|
|
264
|
+
```yaml
|
|
265
|
+
name: agent-evals
|
|
266
|
+
on:
|
|
267
|
+
pull_request:
|
|
268
|
+
push:
|
|
269
|
+
branches: [main]
|
|
270
|
+
|
|
271
|
+
jobs:
|
|
272
|
+
evals:
|
|
273
|
+
runs-on: ubuntu-latest
|
|
274
|
+
timeout-minutes: 20
|
|
275
|
+
steps:
|
|
276
|
+
- uses: actions/setup-node@v4
|
|
277
|
+
with: { node-version: 22 }
|
|
278
|
+
- name: Run the billing agent's core suite on the draft
|
|
279
|
+
env:
|
|
280
|
+
BASEERA_AGENT_ID: ${{ vars.BASEERA_AGENT_ID }}
|
|
281
|
+
BASEERA_SECRET_KEY: ${{ secrets.BASEERA_SECRET_KEY }}
|
|
282
|
+
BASEERA_URL: ${{ vars.BASEERA_URL }}
|
|
283
|
+
# --yes: this spends the organization's provider key. Remove the pull_request trigger if that is not what you want.
|
|
284
|
+
run: npx --yes --package @baseera/node@latest baseera eval run --suite core --target draft --report junit --out baseera.xml --yes
|
|
285
|
+
- uses: actions/upload-artifact@v4
|
|
286
|
+
if: always()
|
|
287
|
+
with: { name: baseera-evals, path: baseera.xml }
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
With the package in your `devDependencies`, `npx baseera eval run ...` is enough. The package is published privately: give the job an npm token that can read the `@baseera` scope.
|
|
291
|
+
|
|
292
|
+
### Run the required tests when your app deploys
|
|
293
|
+
|
|
294
|
+
Instead of calling the CLI after your deploy, an owner or admin can turn on "Run the required tests when the app's tool manifest changes" on the agent's Deploy page. When your deployed app sends a different list of tools, Baseera runs the agent's required suites on the version in production, at most once every 10 minutes (and 10 a day) and never while another run is active, and sends `eval.run.finished` to the agent's webhook (see the finish webhook above). **This spends your provider key without anyone clicking Run, so it is off by default.** A run started from your CI also sends the event when it ends.
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
if (result.event.type === "eval.run.finished") {
|
|
298
|
+
const { runId, suiteName, passed, counts, target } = result.event.data; // pass or fail and counts only
|
|
299
|
+
if (!passed) await alertTeam(`${suiteName} failed on ${target}: ${counts.failed} failed, ${counts.errored} errored (run ${runId})`);
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Tenant uploads: let a tenant's admins add their own documents
|
|
304
|
+
|
|
305
|
+
Per-tenant knowledge: an admin of one of your tenants uploads documents that only that tenant's users get answers from. In the console, turn on **Let tenants add their own documents** on the agent's Knowledge page (off by default) and attach the knowledge base. In your app, show `<BaseeraKnowledgeUpload>` (from `@baseera/ui/connected`). It needs a token that **your server** signs after checking the user may manage that tenant's documents:
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
// app/api/baseera/upload-token/route.ts
|
|
309
|
+
import { createBaseera } from "@baseera/node";
|
|
310
|
+
|
|
311
|
+
const baseera = createBaseera({ agentId: process.env.BASEERA_AGENT_ID!, secretKey: process.env.BASEERA_SECRET_KEY!, baseUrl: process.env.BASEERA_RUNTIME_URL! });
|
|
312
|
+
|
|
313
|
+
export async function POST() {
|
|
314
|
+
const admin = await requireTenantAdmin(); // YOUR authorization: who is signed in, and may they manage this tenant's documents?
|
|
315
|
+
const result = await baseera.kb.createTenantUploadToken({
|
|
316
|
+
knowledgeBase: process.env.BASEERA_KNOWLEDGE_BASE_ID!,
|
|
317
|
+
tenantId: admin.organizationId, // the same id you put in this tenant's users' tokens
|
|
318
|
+
userId: admin.id,
|
|
319
|
+
ttlSeconds: 300, // default 300, at most 600
|
|
320
|
+
});
|
|
321
|
+
if (!result.ok) return new Response(null, { status: 500 });
|
|
322
|
+
return Response.json({ token: result.token });
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
```tsx
|
|
327
|
+
<BaseeraKnowledgeUpload
|
|
328
|
+
tenant="Acme Ltd" // shown as the heading
|
|
329
|
+
getUploadToken={() => fetch("/api/baseera/upload-token", { method: "POST" }).then((r) => r.json()).then((b) => b.token)}
|
|
330
|
+
/>
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
The token names the knowledge base, the tenant and the user; Baseera reads them from the token and nowhere else, so the browser can't upload for another tenant, and it only works with your agent's publishable key from your allowed domains. It expires in minutes (the component asks for a new one). `signTenantUploadToken({ agentId, secretKey, knowledgeBase, tenantId, userId })` is the lower-level function behind it (it throws on a missing field). Limits per tenant and knowledge base: 200 files, 200 MB in all, 25 MB a file. See PROTOCOL.md, "Tenant uploads".
|
|
334
|
+
|
|
335
|
+
## Peer dependencies
|
|
336
|
+
|
|
337
|
+
None.
|
|
338
|
+
|
|
339
|
+
## Bundle size
|
|
340
|
+
|
|
341
|
+
Server-side only; there is no browser bundle budget.
|
|
342
|
+
|
|
343
|
+
## Right to left and Arabic
|
|
344
|
+
|
|
345
|
+
Pass `locale: "ar"` for Arabic users. Arabic suite names work in `baseera eval run`, and Arabic text is kept as it is in the JUnit output.
|
|
346
|
+
|
|
347
|
+
## Security
|
|
348
|
+
|
|
349
|
+
Backend and CI only. Read `BASEERA_SECRET_KEY` from your secret manager or environment, never commit it, never pass it as a command-line argument, never import this package into browser code. Nothing here logs a key. See [SECURITY.md](https://github.com/Graynest-net/aeris/blob/main/SECURITY.md) for how to report a vulnerability.
|
|
350
|
+
|
|
351
|
+
## Documentation
|
|
352
|
+
|
|
353
|
+
Docs: https://baseera.dev/docs (placeholder until the docs site is live). The wire protocol is in [PROTOCOL.md](https://github.com/Graynest-net/aeris/blob/main/PROTOCOL.md).
|
|
354
|
+
|
|
355
|
+
## License
|
|
356
|
+
|
|
357
|
+
MIT, Copyright (c) 2026 GrayNest. See [LICENSE](./LICENSE).
|