@cultured_computer/sight 0.8.3 → 0.9.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/CHANGELOG.md CHANGED
@@ -5,6 +5,43 @@ reconstructed from the repository: the `sdk-v*` release tags (dates are tag
5
5
  dates) and the commits between them. Where the history does not say what a
6
6
  version changed for SDK users, the entry says "see git history".
7
7
 
8
+ ## 0.9.0 (2026-10-16)
9
+
10
+ - New: the serving client. `createFieldClient({ apiKey, endpoint? })`
11
+ calls the Field API: `profiles.put`, `profiles.get`, `profiles.sessions`,
12
+ `conversations.start`, `turns.send` (JSON), `turns.stream` (the turn's
13
+ server-sent frames as an async iterator: `run`, `notice`, `reads`,
14
+ `delta`, `events`, `done`, `error`) and `sessions.get`. It uses the
15
+ global `fetch`, adds no dependency, keeps no state and never retries.
16
+ - The runtime record: `model`, `temperature`, `maxOutputTokens` and
17
+ `reasoningEffort` (including `none`) as `profiles.put` options, and as
18
+ `runtime` on `conversations.start` to choose them for one conversation
19
+ (a key with `profiles:write` only; `runtime_forbidden` otherwise). The
20
+ profile read's `maxOutputTokensSource` and `reasoningEffortSource`, and
21
+ the `run` frame's `maxOutputTokens` and `override`, are typed. These
22
+ need the Field's served runtime record deployed.
23
+ - Every refused request throws a `FieldRefusal` with `status`, `code`,
24
+ `reason` (the ended reason, or `empty_completion` and
25
+ `empty_completion_length` on a `provider_error`), `retryAfter`, and a
26
+ failed turn's `notices`, `events` and `turnIndex`.
27
+ `FIELD_REFUSAL_CODES` lists the codes.
28
+ - Capture is unchanged: `Sight` and every other export behave as in
29
+ 0.8.4, and the request a capture sends is pinned byte for byte by a
30
+ test.
31
+ - 0.8.4 never reached the registry (its publish failed), so 0.9.0 is the
32
+ first npm release carrying 0.8.4's changes, listed below.
33
+
34
+ ## 0.8.4 (2026-10-13)
35
+
36
+ - Capture slots and drain now include consuming or cancelling the HTTP
37
+ response body, not just receiving its headers. Unused response bodies
38
+ are cancelled, and debug acknowledgements are capped at 64 KiB under
39
+ the existing request timeout.
40
+ - Drain uses elapsed time rather than the system clock. An incomplete
41
+ accepted acknowledgement never retries capture; only the existing
42
+ single rate-limit retry remains. Public exports and capture payloads
43
+ are unchanged.
44
+
8
45
  ## 0.8.3 (2026-10-06)
9
46
 
10
47
  - `sight openrouter connect --house-trial`: marks the connection as the
package/README.md CHANGED
@@ -5,6 +5,9 @@ makes inside a session as one turn (the person's message, the reply, model,
5
5
  tokens, latency) and sends it to the Sight API without changing or delaying
6
6
  the response.
7
7
 
8
+ It also carries a serving client for the Field API, which serves a
9
+ `SOUL.md` profile for you: see [Serve a profile](#serve-a-profile).
10
+
8
11
  Full documentation: https://sight.cultured.computer/docs
9
12
 
10
13
  ## Requirements
@@ -188,14 +191,222 @@ environment variables. Secrets are read from the environment, never from a flag.
188
191
 
189
192
  Every flag: [CLI](https://sight.cultured.computer/docs/cli).
190
193
 
191
- ## Serving a profile
194
+ ## Serve a profile
195
+
196
+ The serving client puts a `SOUL.md` at a name on the Field API, serves it
197
+ turn by turn and reads its record. It is separate from capture: it takes
198
+ its own key and shares no state with `Sight`. It uses the global `fetch`,
199
+ keeps nothing between calls and never retries a request.
200
+
201
+ ### Setup
192
202
 
193
- - The Field API serves a profile on the same host, `https://api.cultured.computer`, with keys from the same API Keys page.
194
- - This package has no client and no CLI verbs for it.
195
- - Docs: [Serve a SOUL.md](https://sight.cultured.computer/docs/serve-a-soul-md).
203
+ - An App key (it carries `studio:serve` and `profiles:write`), set as
204
+ `SIGHT_APP_KEY`. Keep it on a server: it can rewrite the profile.
205
+ - The project's OpenRouter key, connected once with an Admin key. See call 1
206
+ of [Quickstart: serve a profile](https://sight.cultured.computer/docs/serve-a-soul-md),
207
+ or `sight openrouter connect`.
208
+ - The host is `https://api.cultured.computer`, the same as capture; set
209
+ `endpoint` only for a staging API.
210
+
211
+ ### Quickstart
212
+
213
+ ```ts
214
+ import { createFieldClient } from "@cultured_computer/sight";
215
+
216
+ const field = createFieldClient({ apiKey: process.env.SIGHT_APP_KEY! });
217
+ await field.profiles.put("listener", soulMarkdown);
218
+ await field.conversations.start("listener", { conversation: "conv-001", user: "user-481" });
219
+ const { reply, notices } = await field.turns.send("listener", { conversation: "conv-001", message: "Hi" });
220
+ ```
221
+
222
+ Show `notices` to the person before the reply: they are fixed platform
223
+ texts (an AI disclosure, a crisis referral), sent only by a profile with a
224
+ safeguard switched on.
225
+
226
+ To stream the reply, iterate the turn's frames:
227
+
228
+ ```ts
229
+ for await (const frame of field.turns.stream("listener", { conversation: "conv-001", message: "Hi" })) {
230
+ if (frame.event === "notice") showNotice(frame.data.text);
231
+ if (frame.event === "delta") write(frame.data.text);
232
+ if (frame.event === "error") console.error(frame.data.code, frame.data.reason);
233
+ }
234
+ ```
235
+
236
+ The frames come in order: `run`, then any `notice` and `reads` before the
237
+ first `delta`, the `delta`s, `events`, and last `done` or `error`. A frame
238
+ this version does not know arrives as `other`, with its `name`.
239
+
240
+ | Method | Route | Answers |
241
+ | --- | --- | --- |
242
+ | `profiles.put(name, soulMarkdown, options?)` | `PUT /v1/profiles/{name}` | `outcome`, `changed`, the version, the `runtime`, `refused` (parts of the file left out; check it after every put), `etag` |
243
+ | `profiles.get(name)` | `GET /v1/profiles/{name}` | The live version, the `runtime`, limits, safeguards, the connection, `etag` |
244
+ | `profiles.sessions(name, { conversation?, cursor?, limit?, version?, ended? })` | `GET /v1/profiles/{name}/sessions` | One page of sessions, newest first; pass `nextBefore` as `cursor` for the next |
245
+ | `conversations.start(profile, { conversation, user, runtime?, opening?, seed? })` | `POST /v1/profiles/{name}/conversations` | `runId`, `sessionId`, `record` |
246
+ | `turns.send(profile, { conversation, message, resume? })` | `POST /v1/profiles/{name}/turns`, JSON | `reply`, `notices`, `events`, `turnIndex` |
247
+ | `turns.stream(profile, { conversation, message, resume? })` | The same route, server-sent events | The frames, as an async iterator |
248
+ | `sessions.get(id)` | `GET /v1/sessions/{id}` | The session and its turns: each turn's `message`, then the `reply` it prompted |
249
+
250
+ Every method takes an optional `signal` (an `AbortSignal`). The client sets
251
+ no timeout of its own; the Field bounds a reply at 90 seconds.
252
+
253
+ ### The runtime record
254
+
255
+ What the reply call is sent. A profile sets it; a conversation can
256
+ override it.
257
+
258
+ | Setting | What it does | Default |
259
+ | --- | --- | --- |
260
+ | `model` | The OpenRouter model id that writes the reply, `vendor/model`. It must have an active route in the model catalogue. | None: the file or the put must name one. |
261
+ | `temperature` | Sampling temperature, 0 to 2. Left out of the request where the model's route takes none. | 0.7 |
262
+ | `maxOutputTokens` | The reply's output budget, in tokens: an integer from 256 to the model's catalogue `max_completion_tokens` (16,384 when it states none). A reasoning model's reasoning tokens count inside it, with the answer. | The smaller of 16,384 and the model's catalogue `max_completion_tokens`; 4,096 when the catalogue says nothing of the model |
263
+ | `reasoningEffort` | `none`, `minimal`, `low`, `medium`, `high`, `xhigh` or `max`. Sent only where the model's catalogue entry lists that effort; elsewhere left out. `none` asks for no reasoning. | `low` where the catalogue lists it, else the lowest effort it lists; nothing when it lists none |
264
+
265
+ - On a profile: write them in the `SOUL.md` frontmatter, or pass them to
266
+ `profiles.put` (the options override the file for that put). A changed
267
+ `reasoningEffort` or `maxOutputTokens` saves a new version.
268
+ `maxOutputTokens` in the frontmatter and as a put option.
269
+ - `profiles.get` answers what the replies are sent with, under `runtime`.
270
+ `maxOutputTokens` and `reasoningEffort` (`null` when nothing is
271
+ asked), each with its source, `maxOutputTokensSource` and
272
+ `reasoningEffortSource`: `profile` when the live version names it,
273
+ `default` for the house default.
274
+ - Each turn's `run` frame, and each turn of `sessions.get` under `sent`,
275
+ say what the call actually sent.
276
+
277
+ Every model the Field serves reasons by default, so a setting you leave
278
+ out is not "off": it is the house default above, per model.
279
+
280
+ Reasoning tokens count inside `maxOutputTokens`. A reasoning model at a
281
+ high effort with a small limit can spend the whole limit reasoning and
282
+ write no reply; that turn fails with `empty_completion_length` (below).
283
+ Reasoning before the first visible token also counts against the
284
+ 15-second first-token deadline.
285
+
286
+ ### Choosing a model per conversation
287
+
288
+ ```ts
289
+ await field.conversations.start("listener", {
290
+ conversation: "conv-002",
291
+ user: "user-481",
292
+ runtime: { model: "anthropic/claude-opus-5", reasoningEffort: "none", maxOutputTokens: 1024 },
293
+ });
294
+ ```
295
+
296
+ - `runtime` overrides the profile's settings for that one conversation;
297
+ a key left out keeps the profile's value.
298
+ - Only a key holding `profiles:write` (the App key) may send it; any
299
+ other key is refused with `runtime_forbidden`.
300
+ - `model` must have an active route in the catalogue (`model_unavailable`
301
+ otherwise); `maxOutputTokens` must be in that model's range and
302
+ `reasoningEffort` one of the efforts (`invalid_max_output_tokens`,
303
+ `invalid_reasoning_effort`). A refused start starts nothing.
304
+ - It is stored with the conversation and every turn uses it. A repeated
305
+ start of the same conversation must send the same `runtime`
306
+ (`opening_conflict` otherwise). Each turn's `run` frame names it as
307
+ `override`.
308
+ - The profile's file, its `## When` sentences and its safeguards are the
309
+ same for every conversation; only the runtime record changes.
310
+
311
+ ### Handling `empty_completion`
312
+
313
+ A model that finishes a turn with no reply text is a `provider_error`
314
+ (`502`) with a `reason`:
315
+
316
+ | `reason` | What happened | What to do |
317
+ | --- | --- | --- |
318
+ | `empty_completion` | The model answered nothing | The next message can be sent as usual. To change the model, start the next conversation with another `runtime.model`. |
319
+ | `empty_completion_length` | The output limit ended the call before any reply text: a reasoning model spent `maxOutputTokens` reasoning | Raise `maxOutputTokens`, or lower `reasoningEffort` |
320
+
321
+ A profile with a `fallback` model has that model answer such a turn
322
+ first. The turn index has moved; do not resend the same message as a new
323
+ turn without deciding to.
324
+
325
+ ```ts
326
+ import { FieldRefusal } from "@cultured_computer/sight";
327
+
328
+ try {
329
+ const { reply } = await field.turns.send("listener", { conversation, message });
330
+ } catch (error) {
331
+ if (error instanceof FieldRefusal && error.code === "provider_error" && error.reason === "empty_completion_length") {
332
+ // The limit was spent reasoning: start the next conversation with a larger maxOutputTokens.
333
+ }
334
+ throw error;
335
+ }
336
+ ```
337
+
338
+ In a stream the same failure is the `error` frame, with `code` and
339
+ `reason`; it ends the stream.
340
+
341
+ ### Refusals
342
+
343
+ Every answer that is not a `2xx` throws a `FieldRefusal`:
344
+
345
+ | Property | What it is |
346
+ | --- | --- |
347
+ | `status` | The HTTP status |
348
+ | `code` | The stable code (below), or `null` when the answer has none (`401`, a `403` for a missing permission, `413`) |
349
+ | `reason` | The `conversation_ended` reason (`idle`, `turn_cap`, `floor`, `failed`, `ended`), or the `provider_error` reason, or `null` |
350
+ | `retryAfter` | `Retry-After` in seconds, or `null` |
351
+ | `notices`, `events`, `turnIndex` | A failed turn's notices (show them), frames and index |
352
+ | `body` | The answer as sent |
353
+
354
+ Branch on `code`, never on the message. `FIELD_REFUSAL_CODES` lists every
355
+ code this version knows; a newer API may answer one it does not list.
356
+
357
+ | Code | Status | What to do |
358
+ | --- | --- | --- |
359
+ | `invalid_body` | `400` | Fix the body; `body.detail` names the fields |
360
+ | `no_owner` | `400` | The project has no owner. Ask us. |
361
+ | `forbidden` | `403` | A rehearsal link was used at a profile address. Use the App key. |
362
+ | `opening_forbidden` | `403` | An `opening` needs a key with `profiles:write` |
363
+ | `runtime_forbidden` | `403` | A `runtime` override needs a key with `profiles:write` |
364
+ | `no_such_profile`, `no_such_endpoint` | `404` | Check the name; put the profile first |
365
+ | `no_such_conversation` | `404` | Start the conversation before sending a turn |
366
+ | `conversation_unknown` | `409` | The conversation has not started |
367
+ | `conversation_conflict` | `409` | This conversation id was started with another `user`. Use a new id. |
368
+ | `opening_conflict` | `409` | This id was started with another `opening`, `seed` or `runtime`. Send the same ones, or use a new id. |
369
+ | `conversation_ended` | `409` | The id is spent; `reason` says why. Start a new conversation under a new id. |
370
+ | `turn_cap` | `409` | The conversation reached its turn cap. Start a new one. |
371
+ | `stale_turn_index` | `409` | `resume.turnIndex` is not the next turn; use the `turnIndex` in the answer |
372
+ | `busy` | `409` | A reply is in progress on this conversation. Wait, then send. |
373
+ | `interrupted`, `record_gap` | `409` | The conversation cannot continue. Start a new one. |
374
+ | `no_live_version` | `409` | Put the file |
375
+ | `model_unavailable` | `409` | The profile's model, or the start's `runtime.model`, has no active route in the catalogue. Name a model it carries. |
376
+ | `not_connected` | `409` | Connect the project's OpenRouter key |
377
+ | `budget` | `409` | The monthly budget is reached. Connect again with a larger budget. |
378
+ | `put_in_progress` | `409` | Another put of this profile is running. Retry after `retryAfter`. |
379
+ | `scene_live` | `409` | The profile serves a stepped scene. Put with `force: true` to replace it. |
380
+ | `request_conflict`, `request_pending`, `request_interrupted` | `409` | Logical turn requests only; not sent by this client |
381
+ | `not_a_soul_md`, `not_a_scene` | `406` | Profile read in another format; not sent by this client |
382
+ | `archived`, `revoked`, `link_inactive` | `410` | It does not come back |
383
+ | `request_unknown`, `replay_expired` | `404`, `410` | Logical turn requests only; not sent by this client |
384
+ | `precondition_failed` | `412` | `ifMatch` no longer names the live version. Read the profile, then put. |
385
+ | `invalid_consent`, `invalid_safeguards`, `invalid_scrub`, `invalid_fallback`, `invalid_scene`, `invalid_reasoning_effort` | `422` | Fix that setting (on a put, or a start's `runtime`); `body.accepted` lists the words. Nothing was stored. |
386
+ | `invalid_max_output_tokens` | `422` | `maxOutputTokens` (on a put, or a start's `runtime`) is not an integer in the model's range; `body.accepted` is `{ min, max }`. Nothing was stored. |
387
+ | `daily_cap` | `429` | The day's conversations are used up (UTC) |
388
+ | `link_session_cap` | `429` | A rehearsal link's session limit; not sent by this client |
389
+ | `rate_limited` | `429` | Wait `retryAfter` seconds, then retry |
390
+ | `turn_failed` | `500` | The turn broke and the conversation is closed. Start a new one. |
391
+ | `provider_error` | `502` | The provider or the model failed; see `reason` above |
392
+ | `provider_timeout` | `504` | A reply deadline passed. The next turn can be sent at once. |
393
+ | `not_enabled` | `503` | Serving is not enabled for the project. Ask us. |
394
+
395
+ Every route, body and refusal:
396
+ [Profile reference](https://sight.cultured.computer/docs/serve-a-profile-reference)
397
+ and [SDK reference](https://sight.cultured.computer/docs/sdk-reference#serve-a-profile).
196
398
 
197
399
  ## Troubleshooting
198
400
 
401
+ Capture sends have a 15-second deadline and at most 64 requests in flight.
402
+ That slot covers the response body as well as headers: unused bodies are
403
+ cancelled, and debug turn acknowledgements are read up to 64 KiB. Await
404
+ `Sight.shutdown()` before a short-lived process exits; its bounded drain also
405
+ waits for pending rate-limit retries. A successful HTTP status means ingest
406
+ accepted the turn, not that worker redaction has finished. An acknowledgement
407
+ body failure never retries an accepted capture; only a `429` permits the
408
+ existing single retry after `Retry-After`.
409
+
199
410
  Failed sends never throw. The first send the API rejects prints one
200
411
  warning on stderr without `debug`: once per process for `401`, once for
201
412
  `403`, once for any other `4xx` except `429`. Set `debug: true` on `init`
package/dist/cli.js CHANGED
@@ -18,7 +18,7 @@ function usage() {
18
18
  "Usage:",
19
19
  " sight auth login [--base <dashboard-url>] [--no-browser]",
20
20
  " sight auth logout",
21
- " sight export --project <slug> --deployment <slug> [--readings|--conditions] [--out file.jsonl]",
21
+ " sight export --project <slug> --deployment <slug> [--readings|--conditions|--labels] [--out file.jsonl]",
22
22
  " sight conditions --session <id-or-external-id> [--deployment <slug>] [--run <id>] [--since <iso>] [--until <iso>] [--base <dashboard-url>]",
23
23
  " sight account create [--openrouter --budget <usd>] [--api <base>]",
24
24
  " sight openrouter connect --budget <usd> [--house-trial] [--api <base>]",
@@ -28,7 +28,7 @@ function usage() {
28
28
  "Commands:",
29
29
  " auth login Sign this terminal in: approve the printed link in your browser.",
30
30
  " auth logout Delete the stored login token.",
31
- " export Write a deployment's record (or --readings, --conditions) as JSONL. Needs auth login, owner role.",
31
+ " export Write a deployment's record (or --readings, --conditions, --labels) as JSONL. Needs auth login, owner role.",
32
32
  " conditions Print a session's or a run's detector checks as NDJSON. Needs a key with studio:run.",
33
33
  " account create Redeem SIGHT_PROVISION_TOKEN; save the key to ~/.config/sight/machine.json (0600).",
34
34
  " openrouter connect Connect your OpenRouter key with a monthly USD budget. Needs a key with providers:write.",
@@ -351,8 +351,9 @@ async function exportRecord(args) {
351
351
  const out = flag(args, "--out") ?? null;
352
352
  const readings = args.includes("--readings");
353
353
  const conditions2 = args.includes("--conditions");
354
- if (!project || !deployment || readings && conditions2) {
355
- console.error("usage: sight export --project <slug> --deployment <slug> [--readings|--conditions] [--out file.jsonl]");
354
+ const labels = args.includes("--labels");
355
+ if (!project || !deployment || [readings, conditions2, labels].filter(Boolean).length > 1) {
356
+ console.error("usage: sight export --project <slug> --deployment <slug> [--readings|--conditions|--labels] [--out file.jsonl]");
356
357
  return 1;
357
358
  }
358
359
  const creds = readCredentials();
@@ -360,7 +361,7 @@ async function exportRecord(args) {
360
361
  console.error("no stored login. Run sight auth login first.");
361
362
  return 1;
362
363
  }
363
- const kind = conditions2 ? "conditions" : readings ? "readings" : null;
364
+ const kind = conditions2 ? "conditions" : readings ? "readings" : labels ? "labels" : null;
364
365
  const url = `${creds.base}/api/export?project=${encodeURIComponent(project)}&deployment=${encodeURIComponent(deployment)}` + (kind ? `&kind=${kind}` : "");
365
366
  const res = await fetch(url, {
366
367
  headers: { authorization: `Bearer ${creds.token}` }