@cultured_computer/sight 0.8.4 → 0.10.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 +49 -0
- package/README.md +207 -4
- package/dist/cli.js +584 -2
- package/dist/index.cjs +331 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +614 -27
- package/dist/index.d.ts +614 -27
- package/dist/index.js +327 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,55 @@ 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
|
+
## Unreleased
|
|
9
|
+
|
|
10
|
+
- Nothing yet.
|
|
11
|
+
|
|
12
|
+
## 0.10.0 (2026-11-17)
|
|
13
|
+
|
|
14
|
+
- New CLI verb: `sight import <file> --deployment <slug> --batch <name>`
|
|
15
|
+
sends historical conversations from a JSONL file through the capture
|
|
16
|
+
route with their original times: one turn for each assistant message,
|
|
17
|
+
then a session end. Each turn's id is derived from the deployment, the
|
|
18
|
+
conversation id and the turn's position, so sending the same file again
|
|
19
|
+
adds nothing to the record (each accepted request is still counted). `--dry-run` checks the file and sends nothing; `--rate`
|
|
20
|
+
sets the requests per minute (1 to 600, default 120). The SDK's exports
|
|
21
|
+
and the request a capture sends are unchanged.
|
|
22
|
+
- `sight import` reads calls between two people: a conversation may say
|
|
23
|
+
`"replies_by": "person"` (or the command `--replies-by person` for the
|
|
24
|
+
whole file) when a person wrote the replies and no model took part. The
|
|
25
|
+
agent's lines carry the role `assistant`. Each of its turns is sent
|
|
26
|
+
with `repliesBy: "person"`, and the session records it. A conversation
|
|
27
|
+
that says a person replies and also names a model is refused. The
|
|
28
|
+
summary counts the conversations that name no model and do not say a
|
|
29
|
+
person replies: an evaluator run over those is refused.
|
|
30
|
+
|
|
31
|
+
## 0.9.0 (2026-10-16)
|
|
32
|
+
|
|
33
|
+
- New: the serving client. `createFieldClient({ apiKey, endpoint? })`
|
|
34
|
+
calls the Field API: `profiles.put`, `profiles.get`, `profiles.sessions`,
|
|
35
|
+
`conversations.start`, `turns.send` (JSON), `turns.stream` (the turn's
|
|
36
|
+
server-sent frames as an async iterator: `run`, `notice`, `reads`,
|
|
37
|
+
`delta`, `events`, `done`, `error`) and `sessions.get`. It uses the
|
|
38
|
+
global `fetch`, adds no dependency, keeps no state and never retries.
|
|
39
|
+
- The runtime record: `model`, `temperature`, `maxOutputTokens` and
|
|
40
|
+
`reasoningEffort` (including `none`) as `profiles.put` options, and as
|
|
41
|
+
`runtime` on `conversations.start` to choose them for one conversation
|
|
42
|
+
(a key with `profiles:write` only; `runtime_forbidden` otherwise). The
|
|
43
|
+
profile read's `maxOutputTokensSource` and `reasoningEffortSource`, and
|
|
44
|
+
the `run` frame's `maxOutputTokens` and `override`, are typed. These
|
|
45
|
+
need the Field's served runtime record deployed.
|
|
46
|
+
- Every refused request throws a `FieldRefusal` with `status`, `code`,
|
|
47
|
+
`reason` (the ended reason, or `empty_completion` and
|
|
48
|
+
`empty_completion_length` on a `provider_error`), `retryAfter`, and a
|
|
49
|
+
failed turn's `notices`, `events` and `turnIndex`.
|
|
50
|
+
`FIELD_REFUSAL_CODES` lists the codes.
|
|
51
|
+
- Capture is unchanged: `Sight` and every other export behave as in
|
|
52
|
+
0.8.4, and the request a capture sends is pinned byte for byte by a
|
|
53
|
+
test.
|
|
54
|
+
- 0.8.4 never reached the registry (its publish failed), so 0.9.0 is the
|
|
55
|
+
first npm release carrying 0.8.4's changes, listed below.
|
|
56
|
+
|
|
8
57
|
## 0.8.4 (2026-10-13)
|
|
9
58
|
|
|
10
59
|
- Capture slots and drain now include consuming or cancelling the HTTP
|
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
|
|
@@ -181,6 +184,7 @@ environment variables. Secrets are read from the environment, never from a flag.
|
|
|
181
184
|
| `sight auth logout` | Deletes the stored login token | None |
|
|
182
185
|
| `sight export --project <slug> --deployment <slug>` | Writes a deployment's record as JSONL (`--out <file>`, default stdout) | `auth login`; owner role on the project |
|
|
183
186
|
| `sight conditions --session <id>` | Prints one session's detector checks as NDJSON | A key with `studio:run`: `SIGHT_API_KEY`, or the key saved by `account create` |
|
|
187
|
+
| `sight import <file> --deployment <slug> --batch <name>` | Sends historical conversations from a JSONL file through the capture route with their original times; `--dry-run` checks the file and sends nothing; `--replies-by person` (or `"replies_by": "person"` on a conversation) sends a call between two people, where no model took part | A key with `ingest`: `SIGHT_API_KEY`, or the key saved by `account create` |
|
|
184
188
|
| `sight account create` | Redeems a one-time token and saves the key to `~/.config/sight/machine.json` (mode `0600`) | `SIGHT_PROVISION_TOKEN` |
|
|
185
189
|
| `sight openrouter connect --budget <usd> [--house-trial]` | Connects your OpenRouter key (`OPENROUTER_API_KEY`) to the project; `--house-trial` marks it as the operator's key for a demo | A key with `providers:write` |
|
|
186
190
|
| `sight openrouter status` | Prints the stored connection: status, last four characters, budget | A key with `studio:run` or `providers:write` |
|
|
@@ -188,11 +192,210 @@ environment variables. Secrets are read from the environment, never from a flag.
|
|
|
188
192
|
|
|
189
193
|
Every flag: [CLI](https://sight.cultured.computer/docs/cli).
|
|
190
194
|
|
|
191
|
-
##
|
|
195
|
+
## Serve a profile
|
|
196
|
+
|
|
197
|
+
The serving client puts a `SOUL.md` at a name on the Field API, serves it
|
|
198
|
+
turn by turn and reads its record. It is separate from capture: it takes
|
|
199
|
+
its own key and shares no state with `Sight`. It uses the global `fetch`,
|
|
200
|
+
keeps nothing between calls and never retries a request.
|
|
201
|
+
|
|
202
|
+
### Setup
|
|
203
|
+
|
|
204
|
+
- An App key (it carries `studio:serve` and `profiles:write`), set as
|
|
205
|
+
`SIGHT_APP_KEY`. Keep it on a server: it can rewrite the profile.
|
|
206
|
+
- The project's OpenRouter key, connected once with an Admin key. See call 1
|
|
207
|
+
of [Quickstart: serve a profile](https://sight.cultured.computer/docs/serve-a-soul-md),
|
|
208
|
+
or `sight openrouter connect`.
|
|
209
|
+
- The host is `https://api.cultured.computer`, the same as capture; set
|
|
210
|
+
`endpoint` only for a staging API.
|
|
211
|
+
|
|
212
|
+
### Quickstart
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
import { createFieldClient } from "@cultured_computer/sight";
|
|
216
|
+
|
|
217
|
+
const field = createFieldClient({ apiKey: process.env.SIGHT_APP_KEY! });
|
|
218
|
+
await field.profiles.put("listener", soulMarkdown);
|
|
219
|
+
await field.conversations.start("listener", { conversation: "conv-001", user: "user-481" });
|
|
220
|
+
const { reply, notices } = await field.turns.send("listener", { conversation: "conv-001", message: "Hi" });
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Show `notices` to the person before the reply: they are fixed platform
|
|
224
|
+
texts (an AI disclosure, a crisis referral), sent only by a profile with a
|
|
225
|
+
safeguard switched on.
|
|
226
|
+
|
|
227
|
+
To stream the reply, iterate the turn's frames:
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
for await (const frame of field.turns.stream("listener", { conversation: "conv-001", message: "Hi" })) {
|
|
231
|
+
if (frame.event === "notice") showNotice(frame.data.text);
|
|
232
|
+
if (frame.event === "delta") write(frame.data.text);
|
|
233
|
+
if (frame.event === "error") console.error(frame.data.code, frame.data.reason);
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
The frames come in order: `run`, then any `notice` and `reads` before the
|
|
238
|
+
first `delta`, the `delta`s, `events`, and last `done` or `error`. A frame
|
|
239
|
+
this version does not know arrives as `other`, with its `name`.
|
|
240
|
+
|
|
241
|
+
| Method | Route | Answers |
|
|
242
|
+
| --- | --- | --- |
|
|
243
|
+
| `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` |
|
|
244
|
+
| `profiles.get(name)` | `GET /v1/profiles/{name}` | The live version, the `runtime`, limits, safeguards, the connection, `etag` |
|
|
245
|
+
| `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 |
|
|
246
|
+
| `conversations.start(profile, { conversation, user, runtime?, opening?, seed? })` | `POST /v1/profiles/{name}/conversations` | `runId`, `sessionId`, `record` |
|
|
247
|
+
| `turns.send(profile, { conversation, message, resume? })` | `POST /v1/profiles/{name}/turns`, JSON | `reply`, `notices`, `events`, `turnIndex` |
|
|
248
|
+
| `turns.stream(profile, { conversation, message, resume? })` | The same route, server-sent events | The frames, as an async iterator |
|
|
249
|
+
| `sessions.get(id)` | `GET /v1/sessions/{id}` | The session and its turns: each turn's `message`, then the `reply` it prompted |
|
|
250
|
+
|
|
251
|
+
Every method takes an optional `signal` (an `AbortSignal`). The client sets
|
|
252
|
+
no timeout of its own; the Field bounds a reply at 90 seconds.
|
|
253
|
+
|
|
254
|
+
### The runtime record
|
|
192
255
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
256
|
+
What the reply call is sent. A profile sets it; a conversation can
|
|
257
|
+
override it.
|
|
258
|
+
|
|
259
|
+
| Setting | What it does | Default |
|
|
260
|
+
| --- | --- | --- |
|
|
261
|
+
| `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. |
|
|
262
|
+
| `temperature` | Sampling temperature, 0 to 2. Left out of the request where the model's route takes none. | 0.7 |
|
|
263
|
+
| `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 |
|
|
264
|
+
| `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 |
|
|
265
|
+
|
|
266
|
+
- On a profile: write them in the `SOUL.md` frontmatter, or pass them to
|
|
267
|
+
`profiles.put` (the options override the file for that put). A changed
|
|
268
|
+
`reasoningEffort` or `maxOutputTokens` saves a new version.
|
|
269
|
+
`maxOutputTokens` in the frontmatter and as a put option.
|
|
270
|
+
- `profiles.get` answers what the replies are sent with, under `runtime`.
|
|
271
|
+
`maxOutputTokens` and `reasoningEffort` (`null` when nothing is
|
|
272
|
+
asked), each with its source, `maxOutputTokensSource` and
|
|
273
|
+
`reasoningEffortSource`: `profile` when the live version names it,
|
|
274
|
+
`default` for the house default.
|
|
275
|
+
- Each turn's `run` frame, and each turn of `sessions.get` under `sent`,
|
|
276
|
+
say what the call actually sent.
|
|
277
|
+
|
|
278
|
+
Every model the Field serves reasons by default, so a setting you leave
|
|
279
|
+
out is not "off": it is the house default above, per model.
|
|
280
|
+
|
|
281
|
+
Reasoning tokens count inside `maxOutputTokens`. A reasoning model at a
|
|
282
|
+
high effort with a small limit can spend the whole limit reasoning and
|
|
283
|
+
write no reply; that turn fails with `empty_completion_length` (below).
|
|
284
|
+
Reasoning before the first visible token also counts against the
|
|
285
|
+
15-second first-token deadline.
|
|
286
|
+
|
|
287
|
+
### Choosing a model per conversation
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
await field.conversations.start("listener", {
|
|
291
|
+
conversation: "conv-002",
|
|
292
|
+
user: "user-481",
|
|
293
|
+
runtime: { model: "anthropic/claude-opus-5", reasoningEffort: "none", maxOutputTokens: 1024 },
|
|
294
|
+
});
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
- `runtime` overrides the profile's settings for that one conversation;
|
|
298
|
+
a key left out keeps the profile's value.
|
|
299
|
+
- Only a key holding `profiles:write` (the App key) may send it; any
|
|
300
|
+
other key is refused with `runtime_forbidden`.
|
|
301
|
+
- `model` must have an active route in the catalogue (`model_unavailable`
|
|
302
|
+
otherwise); `maxOutputTokens` must be in that model's range and
|
|
303
|
+
`reasoningEffort` one of the efforts (`invalid_max_output_tokens`,
|
|
304
|
+
`invalid_reasoning_effort`). A refused start starts nothing.
|
|
305
|
+
- It is stored with the conversation and every turn uses it. A repeated
|
|
306
|
+
start of the same conversation must send the same `runtime`
|
|
307
|
+
(`opening_conflict` otherwise). Each turn's `run` frame names it as
|
|
308
|
+
`override`.
|
|
309
|
+
- The profile's file, its `## When` sentences and its safeguards are the
|
|
310
|
+
same for every conversation; only the runtime record changes.
|
|
311
|
+
|
|
312
|
+
### Handling `empty_completion`
|
|
313
|
+
|
|
314
|
+
A model that finishes a turn with no reply text is a `provider_error`
|
|
315
|
+
(`502`) with a `reason`:
|
|
316
|
+
|
|
317
|
+
| `reason` | What happened | What to do |
|
|
318
|
+
| --- | --- | --- |
|
|
319
|
+
| `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`. |
|
|
320
|
+
| `empty_completion_length` | The output limit ended the call before any reply text: a reasoning model spent `maxOutputTokens` reasoning | Raise `maxOutputTokens`, or lower `reasoningEffort` |
|
|
321
|
+
|
|
322
|
+
A profile with a `fallback` model has that model answer such a turn
|
|
323
|
+
first. The turn index has moved; do not resend the same message as a new
|
|
324
|
+
turn without deciding to.
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
import { FieldRefusal } from "@cultured_computer/sight";
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
const { reply } = await field.turns.send("listener", { conversation, message });
|
|
331
|
+
} catch (error) {
|
|
332
|
+
if (error instanceof FieldRefusal && error.code === "provider_error" && error.reason === "empty_completion_length") {
|
|
333
|
+
// The limit was spent reasoning: start the next conversation with a larger maxOutputTokens.
|
|
334
|
+
}
|
|
335
|
+
throw error;
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
In a stream the same failure is the `error` frame, with `code` and
|
|
340
|
+
`reason`; it ends the stream.
|
|
341
|
+
|
|
342
|
+
### Refusals
|
|
343
|
+
|
|
344
|
+
Every answer that is not a `2xx` throws a `FieldRefusal`:
|
|
345
|
+
|
|
346
|
+
| Property | What it is |
|
|
347
|
+
| --- | --- |
|
|
348
|
+
| `status` | The HTTP status |
|
|
349
|
+
| `code` | The stable code (below), or `null` when the answer has none (`401`, a `403` for a missing permission, `413`) |
|
|
350
|
+
| `reason` | The `conversation_ended` reason (`idle`, `turn_cap`, `floor`, `failed`, `ended`), or the `provider_error` reason, or `null` |
|
|
351
|
+
| `retryAfter` | `Retry-After` in seconds, or `null` |
|
|
352
|
+
| `notices`, `events`, `turnIndex` | A failed turn's notices (show them), frames and index |
|
|
353
|
+
| `body` | The answer as sent |
|
|
354
|
+
|
|
355
|
+
Branch on `code`, never on the message. `FIELD_REFUSAL_CODES` lists every
|
|
356
|
+
code this version knows; a newer API may answer one it does not list.
|
|
357
|
+
|
|
358
|
+
| Code | Status | What to do |
|
|
359
|
+
| --- | --- | --- |
|
|
360
|
+
| `invalid_body` | `400` | Fix the body; `body.detail` names the fields |
|
|
361
|
+
| `no_owner` | `400` | The project has no owner. Ask us. |
|
|
362
|
+
| `forbidden` | `403` | A rehearsal link was used at a profile address. Use the App key. |
|
|
363
|
+
| `opening_forbidden` | `403` | An `opening` needs a key with `profiles:write` |
|
|
364
|
+
| `runtime_forbidden` | `403` | A `runtime` override needs a key with `profiles:write` |
|
|
365
|
+
| `no_such_profile`, `no_such_endpoint` | `404` | Check the name; put the profile first |
|
|
366
|
+
| `no_such_conversation` | `404` | Start the conversation before sending a turn |
|
|
367
|
+
| `conversation_unknown` | `409` | The conversation has not started |
|
|
368
|
+
| `conversation_conflict` | `409` | This conversation id was started with another `user`. Use a new id. |
|
|
369
|
+
| `opening_conflict` | `409` | This id was started with another `opening`, `seed` or `runtime`. Send the same ones, or use a new id. |
|
|
370
|
+
| `conversation_ended` | `409` | The id is spent; `reason` says why. Start a new conversation under a new id. |
|
|
371
|
+
| `turn_cap` | `409` | The conversation reached its turn cap. Start a new one. |
|
|
372
|
+
| `stale_turn_index` | `409` | `resume.turnIndex` is not the next turn; use the `turnIndex` in the answer |
|
|
373
|
+
| `busy` | `409` | A reply is in progress on this conversation. Wait, then send. |
|
|
374
|
+
| `interrupted`, `record_gap` | `409` | The conversation cannot continue. Start a new one. |
|
|
375
|
+
| `no_live_version` | `409` | Put the file |
|
|
376
|
+
| `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. |
|
|
377
|
+
| `not_connected` | `409` | Connect the project's OpenRouter key |
|
|
378
|
+
| `budget` | `409` | The monthly budget is reached. Connect again with a larger budget. |
|
|
379
|
+
| `put_in_progress` | `409` | Another put of this profile is running. Retry after `retryAfter`. |
|
|
380
|
+
| `scene_live` | `409` | The profile serves a stepped scene. Put with `force: true` to replace it. |
|
|
381
|
+
| `request_conflict`, `request_pending`, `request_interrupted` | `409` | Logical turn requests only; not sent by this client |
|
|
382
|
+
| `not_a_soul_md`, `not_a_scene` | `406` | Profile read in another format; not sent by this client |
|
|
383
|
+
| `archived`, `revoked`, `link_inactive` | `410` | It does not come back |
|
|
384
|
+
| `request_unknown`, `replay_expired` | `404`, `410` | Logical turn requests only; not sent by this client |
|
|
385
|
+
| `precondition_failed` | `412` | `ifMatch` no longer names the live version. Read the profile, then put. |
|
|
386
|
+
| `invalid_consent`, `invalid_safeguards`, `invalid_scrub`, `invalid_fallback`, `invalid_scene`, `invalid_reasoning_effort`, `invalid_reply_check` | `422` | Fix that setting (on a put, or a start's `runtime`); `body.accepted` lists the words. Nothing was stored. |
|
|
387
|
+
| `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. |
|
|
388
|
+
| `daily_cap` | `429` | The day's conversations are used up (UTC) |
|
|
389
|
+
| `link_session_cap` | `429` | A rehearsal link's session limit; not sent by this client |
|
|
390
|
+
| `rate_limited` | `429` | Wait `retryAfter` seconds, then retry |
|
|
391
|
+
| `turn_failed` | `500` | The turn broke and the conversation is closed. Start a new one. |
|
|
392
|
+
| `provider_error` | `502` | The provider or the model failed; see `reason` above |
|
|
393
|
+
| `provider_timeout` | `504` | A reply deadline passed. The next turn can be sent at once. |
|
|
394
|
+
| `not_enabled` | `503` | Serving is not enabled for the project. Ask us. |
|
|
395
|
+
|
|
396
|
+
Every route, body and refusal:
|
|
397
|
+
[Profile reference](https://sight.cultured.computer/docs/serve-a-profile-reference)
|
|
398
|
+
and [SDK reference](https://sight.cultured.computer/docs/sdk-reference#serve-a-profile).
|
|
196
399
|
|
|
197
400
|
## Troubleshooting
|
|
198
401
|
|