Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
fix(sdk): health() accepts the liveness-only answer the server now gives (#812)
Nandakishord8a2e59781ca
diff --git a/docs/docker.md b/docs/docker.mdindex a1a6089f..db137bdb 100644--- a/docs/docker.md+++ b/docs/docker.md@@ -310,7 +310,9 @@ Compose files.The port is published on `127.0.0.1` only. The API has no authentication until`LAYA_API_KEY` is set, so set a key before exposing it with`LAYA_BIND_ADDRESS=0.0.0.0`, and put a TLS reverse proxy in front for remote clients.-`/health` does not require authentication in either case.+`/health` does not require authentication in either case, so the healthcheck below keeps+working; with a key set it answers an unauthenticated caller `{"status": "ok"}` and withholds the+checkpoint, revision and device fields, which need the bearer.The service has a healthcheck on `/health`. The server preloads before it startslistening, so with `LAYA_PRELOAD=1` a healthy container has its checkpoints loaded.diff --git a/sdk/typescript/README.md b/sdk/typescript/README.mdindex 72acbc80..4fa747c5 100644--- a/sdk/typescript/README.md+++ b/sdk/typescript/README.md@@ -223,7 +223,7 @@ authenticated gateway. A shared server key embedded in browser code is public.Laya's server binds to `0.0.0.0` by default; the quickstart sets `LAYA_HOST=127.0.0.1`for local use. Set `LAYA_API_KEY` in its environment to require Bearer-authentication for predictions. `/health` remains public. `HF_TOKEN`, if needed+authentication for predictions. `/health` remains public for liveness; `loaded` and `device` need the bearer. `HF_TOKEN`, if neededfor checkpoint downloads, is a separate server-only credential. Configure CORSand TLS at your application proxy or gateway.@@ -231,7 +231,7 @@ and TLS at your application proxy or gateway.| Endpoint | Request | Response || --- | --- | --- |-| `GET /health` | None | `{status, loaded, device}` |+| `GET /health` | None for liveness | `{status}`, plus `loaded` and `device` with the bearer || `POST /v1/systemone` | `{state, questions, model?}` | `{model, answers, usage}` plus optional `routing` |Laya errors use FastAPI's `{detail: ...}` body: 400 for malformed requests, 401diff --git a/sdk/typescript/src/response.ts b/sdk/typescript/src/response.tsindex 4092b858..d6eb8468 100644--- a/sdk/typescript/src/response.ts+++ b/sdk/typescript/src/response.ts@@ -24,8 +24,14 @@ export function validateRoute(value: unknown): void {}export function validateHealth(value: unknown): void {- expect(isRecord(value) && value.status === 'ok' && typeof value.device === 'string', 'health');- expect(Array.isArray(value.loaded) && value.loaded.every(model), 'loaded');+ // Liveness is the only field every caller gets. The rest is withheld from an unauthenticated+ // probe on a server with LAYA_API_KEY set, so requiring it here would reject a healthy+ // response; each field is still checked when the server does send it.+ expect(isRecord(value) && value.status === 'ok', 'health');+ if (value.device !== undefined) expect(typeof value.device === 'string', 'device');+ if (value.loaded !== undefined) {+ expect(Array.isArray(value.loaded) && value.loaded.every(model), 'loaded');+ }}export function validatePrediction(value: unknown, questions: Questions): void {diff --git a/sdk/typescript/src/types.ts b/sdk/typescript/src/types.tsindex d6ea74a9..5a0b62a3 100644--- a/sdk/typescript/src/types.ts+++ b/sdk/typescript/src/types.ts@@ -104,11 +104,17 @@ export interface Prediction<Q extends Questions = Questions> {/** Optional routing metadata returned by Laya. */routing?: RouteDecision;}-/** Laya's self-hosted health probe. */+/** Laya's self-hosted health probe.+ *+ * `status` is always present. The rest is only answered to a caller the server can authenticate:+ * on a deployment that set `LAYA_API_KEY`, an anonymous probe gets `{status: 'ok'}` and nothing+ * else, because the other fields name resident checkpoints, their revision SHAs and the host's+ * device state. A deployment with no key set answers every field to everyone.+ */export interface Health {status: 'ok';- loaded: ModelName[];- device: string;+ loaded?: ModelName[];+ device?: string;}/** Preserve question IDs, primitive types, and literal choice labels when declaring a schema. */diff --git a/sdk/typescript/test/client.test.mjs b/sdk/typescript/test/client.test.mjsindex e222b024..c862f012 100644--- a/sdk/typescript/test/client.test.mjs+++ b/sdk/typescript/test/client.test.mjs@@ -36,6 +36,24 @@ test('systemone request preserves Unicode/JSON, auth, model override and proxy passert.equal(calls, 1);});+test('health accepts the liveness-only answer a locked-down server gives an anonymous probe', async () => {+ // A server with LAYA_API_KEY set answers an unauthenticated /health with {status: 'ok'} and+ // withholds loaded/device, because those name resident checkpoints, their revision SHAs and+ // the host device state. That is a healthy response and must not be a LayaResponseError.+ const client = new Laya({ fetch: async () => json({ status: 'ok' }) });+ assert.deepEqual(await client.health(), { status: 'ok' });++ // the detail is still validated whenever the server does send it+ const bad = new Laya({ fetch: async () => json({ status: 'ok', loaded: ['nope'], device: 'cpu' }) });+ await assert.rejects(bad.health(), LayaResponseError);+ const badDevice = new Laya({ fetch: async () => json({ status: 'ok', device: 7 }) });+ await assert.rejects(badDevice.health(), LayaResponseError);+ // and a missing or wrong status is still a failure+ for (const payload of [{}, { status: 'degraded' }]) {+ await assert.rejects(new Laya({ fetch: async () => json(payload) }).health(), LayaResponseError);+ }+});+test('Laya health uses GET and accepts the existing server response', async () => {const calls = [];const client = new Laya({ fetch: async (url, init) => {