@cultured_computer/sight 0.7.1 → 0.8.1

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,17 @@
1
1
  # Sight
2
2
 
3
- Sight records what your production assistant is being. Not traces of what
4
- the model produced: the interaction itself, captured as a coupled record.
5
- Each turn holds what the situation was, what your agent did, how the user
6
- responded, and what it led to. Both actors, one record. Behavior lives in
7
- the coupling, not in the transcript: a reply only means something next to
8
- what happened after it.
9
-
10
- The record also carries an environment channel: tool outcomes, world
11
- signals, stimulus events with their timing. Behavior reads against what
12
- the world actually did, not just against text.
13
-
14
- The SDK captures out of band; responses are never modified or delayed.
15
- From the record, the dashboard shows the worst conversations first (opened
16
- on the transcript), joins outcomes back to the conversation that caused
17
- them even when they arrive days later, and computes behavioural
18
- measurements on top: the situations your deployment handles, voice
19
- consistency, uptake, breaks, return behaviour. Every interpreted number
20
- stays preliminary until it agrees with your own labels on your own traffic.
21
-
22
- The SDK is in beta. The record format is versioned and stable; the surfaces
23
- around it are still moving.
3
+ The capture SDK and CLI for Sight. It records each model call your assistant
4
+ makes inside a session as one turn (the person's message, the reply, model,
5
+ tokens, latency) and sends it to the Sight API without changing or delaying
6
+ the response.
7
+
8
+ Full documentation: https://sight.cultured.computer/docs
9
+
10
+ ## Requirements
11
+
12
+ - Node 20.6 or later. Server-side only; never ship the key to a browser.
13
+ - A Sight API key with the `ingest` capability, set as `SIGHT_API_KEY`.
14
+ - TypeScript types, an ESM build and a CommonJS build are included.
24
15
 
25
16
  ## Install
26
17
 
@@ -28,305 +19,214 @@ around it are still moving.
28
19
  npm install @cultured_computer/sight
29
20
  ```
30
21
 
31
- Node 20.6 or later. TypeScript types ship with the package.
32
-
33
22
  ## Quickstart
34
23
 
35
24
  ```ts
36
- import { Sight } from "@cultured_computer/sight";
37
-
38
- Sight.init({
39
- apiKey: process.env.SIGHT_API_KEY!,
40
- deployment: "my-assistant",
41
- });
42
-
43
- Sight.startSession({
44
- externalId: conversationId,
45
- externalUserId: userId,
46
- });
47
- ```
48
-
49
- Notes:
50
-
51
- - `apiKey` is a project ingest key. Create a project in the
52
- [dashboard](https://sight.cultured.computer/dashboard) and copy its key
53
- (shown once) into `SIGHT_API_KEY`. That is the only required setup; the
54
- ingest endpoint defaults to production; override it with `endpoint` only for
55
- self-hosting or staging.
56
- - `init` runs once at startup. `deployment` identifies the configuration this
57
- traffic belongs to; all measurement is per deployment.
58
- - `externalId` keys the session (one conversation). `externalUserId` is a
59
- stable, pseudonymous user id you supply. Return metrics key on the user id;
60
- sessions without it still capture, but return behaviour is not computable.
61
-
62
- ## Headless project setup
63
-
64
- Provider setup requires an explicitly issued **management** provisioning token
65
- (`--access manage`), not an ordinary ingest, Studio, or combined token. It grants
66
- only `providers:write`, allowing provider-key replacement and budget changes.
67
- With that administrative token, connect your own OpenRouter key without a browser:
68
-
69
- ```bash
70
- export SIGHT_PROVISION_TOKEN='<one-time management token from Sight>'
71
- export OPENROUTER_API_KEY='<your OpenRouter API key>'
72
-
73
- npx @cultured_computer/sight account create --openrouter --budget 25
74
- ```
75
-
76
- The provisioning token and OpenRouter key are read only from the environment,
77
- not command-line arguments. The Sight key is returned once and saved to
78
- `~/.config/sight/machine.json` with mode `0600`; it is never printed. Sight
79
- validates the OpenRouter key, seals it before database storage, and records the
80
- explicit local monthly budget. Check the safe, redacted state later with:
81
-
82
- ```bash
83
- npx @cultured_computer/sight openrouter status
84
- ```
85
-
86
- If OpenRouter setup fails after account creation, the Sight credential remains
87
- saved. Fix the key or budget and retry only that step:
88
-
89
- ```bash
90
- export OPENROUTER_API_KEY='<your OpenRouter API key>'
91
- npx @cultured_computer/sight openrouter connect --budget 25
92
- ```
93
-
94
- For an existing project, ask its owner for a separate **Provider administration
95
- only** key, or have the operator mint one with `scripts/mint-key.mjs --access manage`.
96
- Set it as `SIGHT_API_KEY` for `openrouter connect`. Use a separate `studio` or
97
- `both` key for execution; management keys do not authorize runs or ingest.
98
- Existing tokens and keys are never upgraded. An ordinary provisioning token
99
- can still be redeemed with `account create` without `--openrouter`.
100
- Redemption is one-time for the project, so a second provisioning token cannot
101
- add an execution key after admin provisioning. The owner must mint the separate
102
- ingest/Studio key in API Keys after claiming the project, or the operator must
103
- mint it with `scripts/mint-key.mjs --access ingest`, `studio`, or `both`.
104
-
105
- Use `SIGHT_API_KEY` from your secret manager in the application process. The
106
- local `machine.json` is a CLI credential store, not a project `.env` file and
107
- is never copied into your repository automatically.
108
-
109
- ## Pull your own data out: the CLI, from your terminal
110
-
111
- The `sight` CLI also carries out data from projects you **own**, with no
112
- dashboard click-through and no session cookie to juggle. Sign the terminal in
113
- once against the browser session you already hold, then export any deployment
114
- you own as RLDS JSONL:
25
+ import OpenAI from "openai";
26
+ import { Sight, wrapOpenAI } from "@cultured_computer/sight";
115
27
 
116
- ```bash
117
- # one-time: sign this terminal in (prints a code, opens your browser to approve)
118
- npx @cultured_computer/sight auth login
119
-
120
- # then pull a deployment's full record
121
- npx @cultured_computer/sight export --project <slug> --deployment <slug> --out data.jsonl
122
-
123
- # or pull the readings: the per-turn judge labels (closure, backward-pass, ...)
124
- npx @cultured_computer/sight export --project <slug> --deployment <slug> --readings --out readings.jsonl
28
+ Sight.init({ apiKey: process.env.SIGHT_API_KEY!, deployment: "my-assistant" });
29
+ const openai = wrapOpenAI(new OpenAI());
125
30
 
126
- # sign out when you're done
127
- npx @cultured_computer/sight auth logout
128
- ```
129
-
130
- - `auth login` prints a short code and opens your browser to the `/device`
131
- approval page (RFC 8628 device authorization). You approve as yourself on a
132
- browser you are already signed into: same identity, same role, same rules as
133
- your dashboard session. The token is stored at
134
- `~/.config/sight/credentials.json` (mode `0600`).
135
- - `export` streams the deployment's sessions and turns as RLDS JSONL, the same
136
- Tier-2 redacted shape the dashboard produces. It is owner-only: the token is
137
- your session, so the carry-out gate is exactly the dashboard's. Members read
138
- in-product; owners carry the dataset out.
139
- - `--readings` pulls the graded reads instead of the record: one line per
140
- per-turn judge label (closure, backward-pass, and the rest), with the rubric
141
- version and judge-model pin. These are the re-computable evidence layer over
142
- the record, not part of the versioned record schema.
143
- - `--out <file>` writes to a file; omit it to stream to stdout.
144
-
145
- One more CLI door, for a different shape: `sight connect` attaches Sight to a
146
- buzz community you don't serve as a read-only observer (invite-code
147
- authorization, no account needed up front). A side lane, not the install —
148
- the walkthrough lives at
149
- [Connect your buzz community](https://sight.cultured.computer/docs/connect-your-room).
150
-
151
- ## What lands automatically
152
-
153
- - **OpenAI: wrap your client.** This is the reliable autocapture path and
154
- the one to use in every new integration:
155
-
156
- ```ts
157
- import OpenAI from "openai";
158
- import { Sight, wrapOpenAI } from "@cultured_computer/sight";
159
-
160
- const openai = wrapOpenAI(new OpenAI());
161
- // Wrap before or after Sight.init(); order does not matter.
162
-
163
- // Calls are captured within a session scope: wrapOpenAI reads the session
164
- // from withSession's async context. Every chat.completions.create and
165
- // responses.create made inside the scope is captured, streaming included.
166
- await Sight.withSession(conversationId, async () => {
31
+ export async function reply(conversationId: string, userMessage: string) {
32
+ // The person's message. It is sent with the turn captured next.
33
+ Sight.userInputSubmit(conversationId, userMessage);
34
+ // A model call is captured only inside a session scope.
35
+ return Sight.withSession(conversationId, async () => {
167
36
  const res = await openai.chat.completions.create({
168
37
  model: "gpt-4.1",
169
38
  messages: [{ role: "user", content: userMessage }],
170
39
  });
40
+ return res.choices[0]?.message.content ?? "";
171
41
  });
172
- // A call made outside any session scope is skipped — with a one-line
173
- // warning naming withSession, never a silent drop.
174
- ```
175
-
176
- Module-level autocapture (no wrap call) also exists but has hard limits:
177
- it attaches only under CommonJS, only when `openai` loads after `init`,
178
- and only for openai v4 (the underlying instrumentation does not support
179
- v5+). When it cannot attach, the SDK now prints a warning naming
180
- `wrapOpenAI` instead of failing silently. If you run ESM or openai v5+,
181
- wrap the client.
182
-
183
- - Module-level autocapture is on from `init` for calls made through the
184
- Anthropic SDK, Vercel AI SDK, LangChain, and LangGraph in the process,
185
- with the same CommonJS and load-order caveats. Each adapter no-ops if
186
- its target library is not installed. Mercury-2 reached through the
187
- OpenAI SDK with a baseURL override is captured and tagged by provider;
188
- `wrapOpenAI` applies there too.
189
- - Plumbing fields populate with no further configuration: model, tokens,
190
- latency, cost, tool calls, finish reason.
191
- - Turns are grouped into sessions by the ids you supply; sessions are created
192
- lazily on first capture.
193
- - Capture never blocks your LLM path. Send failures log in debug mode and are
194
- otherwise swallowed.
195
-
196
- ## Attach outcomes
197
-
198
- Call these wherever the outcome becomes known; they join back by session id,
199
- even hours later, from a webhook or CRM callback.
200
-
201
- ```ts
202
- // A user reporting a persona break.
203
- await Sight.flagPersonaBreak({
204
- sessionExternalId: sessionId,
205
- note: "sounded robotic",
206
- });
207
-
208
- // Your own downstream outcome: a resolved ticket, a rating, a conversion.
209
- await Sight.emitOutcomeEvent({
210
- sessionExternalId: sessionId,
211
- kind: "ticket_resolved",
212
- detail: { ticketId: "ZD-88213" },
213
- });
42
+ }
214
43
  ```
215
44
 
216
- ## Capture environment events
217
-
218
- Deployments that run alongside a non-dialogue channel (a stimulus feed, a
219
- game state stream, an editor buffer) can record that channel's events
220
- against the conversation:
45
+ After the first accepted turn, stderr prints one line with a link to the
46
+ session: `Sight: first session captured -> <url>`.
47
+ Walkthrough: [Get started](https://sight.cultured.computer/docs/get-started).
48
+
49
+ ## What you must do for a turn to be captured
50
+
51
+ | Step | Call | Without it |
52
+ | --- | --- | --- |
53
+ | Initialise once at startup | `Sight.init({ apiKey, deployment })` | Nothing is captured. `init` throws on an invalid configuration; no other Sight call throws on bad input. |
54
+ | Scope each conversation | `Sight.withSession(id, fn)` around the model call; `id` is your conversation id | The call is not captured. The first such call in a process prints one warning. |
55
+ | Record the person's message | `Sight.userInputSubmit(id, text)` before the model call | A wrapped OpenAI client's turn has no person's message. The span and `ai` paths read the last user message of the request. |
56
+ | Use a key that may send | A key with the `ingest` capability (access `ingest`, `both` or `app`) | The API answers `403` and the turn is dropped. One warning prints. |
57
+
58
+ - `Sight.withSession(id, fn)` is required for autocapture.
59
+ - `deployment` names the configuration the traffic belongs to. The API host
60
+ defaults to `https://api.cultured.computer`; set `endpoint` only for a
61
+ self-hosted or staging API.
62
+ - Keys are created by a project owner on the dashboard's API Keys page and
63
+ shown once. No dashboard access: ask the project owner for a key. See
64
+ [Keys and access](https://sight.cultured.computer/docs/keys-and-access).
65
+ - Optional: `Sight.startSession({ externalId, externalUserId })` attaches a
66
+ stable, pseudonymous user id, which ties one person's sessions together.
67
+
68
+ ## Capture paths
69
+
70
+ | Path | What you add | Verified with | What it sends that others do not |
71
+ | --- | --- | --- | --- |
72
+ | OpenAI client | `wrapOpenAI(new OpenAI())`, before or after `init` | Tests use stand-in clients for `chat.completions.create` and `responses.create`, streaming included; type-checked against `openai` 6.45.0 | First-token time on streams; cost when the response reports one (`usage.cost`); provider read from the client's `baseURL` |
73
+ | Vercel AI SDK, `ai` 7 | Nothing; `init` registers a telemetry integration | `ai` 7.0.17 | One turn per model call in a tool loop; cache write tokens; time to first output on streams. No cost is sent. |
74
+ | Vercel AI SDK, `ai` 6 | `experimental_telemetry: { isEnabled: true }` on each call | `ai` 6.0.300 | Time to first chunk on streams |
75
+ | OpenTelemetry GenAI spans | Any instrumentation that emits spans with `gen_ai.operation.name` of `chat`, `generate_content` or `text_completion` | Span fixtures in this package's tests | Cost from `gen_ai.usage.cost`; with no scope, the session id from `gen_ai.conversation.id` |
76
+ | OpenAI, Anthropic, LangChain module instrumentation | Nothing; `init` enables it. CommonJS only. | Not covered by this package's tests; confirm with `debug: true` | No first-token time |
77
+ | Anything else (LiteLLM, raw HTTP) | `Sight.captureTurn`, below | | |
78
+
79
+ - For OpenAI, wrap the client: it works under ESM and CommonJS, in any load
80
+ order.
81
+ - `ai` 3 to 5 are not verified.
82
+ - `ai` 7 outside a scope: pass `telemetry: { integrations: sightTelemetry({ sessionId }) }` on the call.
83
+ - An `ai` 7 model call that is also seen as a span or by a wrapped client is
84
+ one turn. A client that is both wrapped and module-patched sends one turn
85
+ per call, the wrapped client's: it has the first-token time and the
86
+ reported cost.
87
+ - Span capture uses the tracer provider `init` registers. If your process
88
+ registered a global tracer provider first, span capture may not attach;
89
+ the wrapped client and the `ai` 7 integration do not depend on it.
90
+
91
+ Details per path: [Integration paths](https://sight.cultured.computer/docs/integration-paths).
92
+
93
+ ## What every captured turn carries
94
+
95
+ | Field | Payload key | Sent when |
96
+ | --- | --- | --- |
97
+ | Reply text | `response.text` | The model returned text. Reasoning and tool arguments are not part of it. |
98
+ | The person's message | `userInput.text` | Recorded with `userInputSubmit`, or read from the request's last user message (span and `ai` paths). Explicit input wins. |
99
+ | Model, requested model | `probe_model`, `probe_request_model` | The path reports them (`ai` 7: model only) |
100
+ | Provider | `probe_provider` | Known. A wrapped client with an unrecognised `baseURL` sends none. |
101
+ | Input and output tokens | `probe_tokens_input`, `probe_tokens_output` | The provider reports usage |
102
+ | Cache read tokens | `probe_cache_read_input_tokens` | The provider reports them |
103
+ | Latency | `probe_latency_ms` | Autocapture measures it |
104
+ | First-token time | `probe_first_token_ms` | Wrapped OpenAI streams and `ai` streams only |
105
+ | Tool names and count | `probe_tool_names`, `probe_tool_calls` | The model requested tools |
106
+ | Finish reason, error | `probe_finish_reason`, `probe_error` | Reported, or the call failed |
107
+ | Cost | `probe_cost_usd` | The provider reports one. Otherwise the server estimates it from its price catalogue when the provider and model match one price; otherwise the turn has no cost (empty, never 0). |
108
+ | Turn identity | `turnId`, `turnIndex` | Always |
109
+
110
+ Every captured turn is sent with a `turnId`: a fresh UUID per turn. A retried
111
+ send carries the same `turnId`. `turnIndex` is a per-session counter held in
112
+ the process.
113
+
114
+ The exported record has a published JSON Schema, shipped in this package as
115
+ `@cultured_computer/sight/schema/record-v1`. See
116
+ [The record](https://sight.cultured.computer/docs/what-it-captures) and
117
+ [Data format](https://sight.cultured.computer/docs/data-format).
118
+
119
+ ## What is not sent
120
+
121
+ Autocapture does not send:
122
+
123
+ - Anything from a model call made outside a session scope.
124
+ - The system prompt text. Autocapture sends its SHA-256 hash as the session's
125
+ version tag, unless you set `environmentConfigHash` yourself.
126
+ - Earlier messages of the request. At most the last user message is read.
127
+ - Reasoning text, tool arguments and tool results. Tool names and a count are sent.
128
+ - Your provider API key and request headers.
129
+ - Turns excluded by `sampleRate` (default 1.0, every turn).
130
+
131
+ Text is sent as your process holds it. Personal data is scrubbed on the
132
+ server before storage: [Privacy & retention](https://sight.cultured.computer/docs/data-and-privacy).
133
+
134
+ ## Manual capture
135
+
136
+ For calls autocapture does not see:
221
137
 
222
138
  ```ts
223
- await Sight.captureEnvironmentEvents(events, {
224
- clock_source: "my-event-clock",
225
- skew_bound_ms: 25,
226
- rule_version: "v1",
139
+ await Sight.captureTurn({
140
+ sessionExternalId: conversationId,
141
+ turnIndex: 0, // position in the session, starting at 0
142
+ userInput: { text: userMessage },
143
+ payload: {
144
+ response: { text: replyText },
145
+ probe_model: "my-model",
146
+ probe_tokens_input: 412,
147
+ probe_tokens_output: 96,
148
+ probe_latency_ms: 840,
149
+ },
227
150
  });
228
151
  ```
229
152
 
230
- The envelope is generalized: `source_type` and `event` are free strings whose
231
- meaning is defined per deployment. The instrument attaches events to turns by
232
- time (the next turn's state corner, plus the causing turn's outcome corner
233
- when the event carries a `causeProvenance` turn reference) and never
234
- interprets them.
235
-
236
- ## Capture spans
237
-
238
- Deployments that keep their own sub-turn structure (tool calls, retrieval
239
- steps, per-call model usage inside a single turn) can ship it as spans:
240
-
241
- ```ts
242
- await Sight.captureSpans(
243
- [
244
- {
245
- contractVersion: 2,
246
- deploymentSlug: "my-agent",
247
- sessionExternalId: sessionId,
248
- turnIndex: 3,
249
- spanType: "tool_call",
250
- spanId: "lookup-3",
251
- parentSpanId: null,
252
- name: "lookup_order",
253
- status: "ok",
254
- startedAt: "2026-07-22T00:00:01.200Z",
255
- endedAt: "2026-07-22T00:00:01.380Z",
256
- durationMs: 180,
257
- model: null,
258
- provider: null,
259
- tokensInput: null,
260
- tokensOutput: null,
261
- costUsd: null,
262
- error: null,
263
- input: { state: "captured", value: { orderId: "ord_123" } },
264
- output: { state: "captured", value: { status: "shipped" } },
265
- intervals: [
266
- {
267
- kind: "active",
268
- startedAt: "2026-07-22T00:00:01.200Z",
269
- endedAt: "2026-07-22T00:00:01.280Z",
270
- },
271
- {
272
- kind: "waiting",
273
- startedAt: "2026-07-22T00:00:01.280Z",
274
- endedAt: "2026-07-22T00:00:01.380Z",
275
- },
276
- ],
277
- attributes: { toolName: "lookup_order", argKeys: ["orderId"] },
278
- },
279
- ],
280
- { clock_source: "my-agent-clock", skew_bound_ms: 25, rule_version: "v1" },
281
- );
282
- ```
283
-
284
- A span lands on the turn you name, or on the session's latest turn at/under
285
- its `startedAt` when `turnIndex` is omitted. Parent structure rides the
286
- batch: give a span a caller-local `spanId` and reference it from a sibling's
287
- `parentSpanId`. In contract v2 every operational key is present; use `null`
288
- for an unknown model, token count, cost, end time, or parent. Input and output
289
- use explicit `captured`, `empty`, `not_captured`, `redacted`, or `unavailable`
290
- states, so absence is never guessed from attributes. `attributes` are metadata
291
- only. Optional `intervals` record internal `active`, `waiting`, `retry`, and
292
- `error` windows. Every interval requires its own `startedAt` and `endedAt` and
293
- must stay within the span; when intervals are omitted, the waterfall does not
294
- invent them from status, names, or retry counters. Status is always explicit
295
- `ok` or `error`; the historical `unset` state
296
- is reserved for contract-v1 rows. The unversioned v1 shape remains accepted for older SDK callers and is
297
- read through a legacy adapter. `Sight.captureSpan(span)` is the single-span
298
- form.
299
-
300
- ## Scope
301
-
302
- Sight is a measurement system: it reports what a deployment did. It does not
303
- modify responses, and it does not estimate what a different response would
304
- have produced. Counterfactual evaluation requires logged propensities or a
305
- live experiment.
306
-
307
- ## The record schema
308
-
309
- Everything Sight captures exports in one published, versioned shape:
310
- `schema/sight-record-v1.schema.json`, shipped in this package
311
- (`@cultured_computer/sight/schema/record-v1`). One JSON line per
312
- session; each turn carries the fixed four-field envelope: the
313
- situation, the assistant's move, how the person took it, and what
314
- followed, on both sides of the exchange, with provenance and
315
- redaction built into the shape. A CI test keeps the schema and the
316
- export bytes in lockstep. Formats that standardize the agent log stop
317
- at the assistant's half; this one records the exchange and its
318
- consequences. See [Data format](https://sight.cultured.computer/docs/data-format).
319
-
320
- ## Docs
321
-
322
- - [Get started](https://sight.cultured.computer/docs/get-started):
323
- install, initialise, verify capture.
324
- - [Cookbook](https://sight.cultured.computer/docs/examples):
325
- runnable snippets, each with what it lands in the record.
326
- - [SDK reference](https://sight.cultured.computer/docs/sdk-reference):
327
- the full method surface.
328
- - [Status](https://sight.cultured.computer/docs/where-it-stands): what
329
- is available now versus in beta.
153
+ An invalid turn logs one warning naming the first invalid field and is not
154
+ sent. Pass `turnId` (a UUID) to supply your own identity.
155
+ Reference: [SDK reference](https://sight.cultured.computer/docs/sdk-reference).
156
+
157
+ ## Outcomes, events, spans
158
+
159
+ All of these join to a session by its id and can be called later, from a
160
+ webhook or a callback.
161
+
162
+ | Method | Records | Docs |
163
+ | --- | --- | --- |
164
+ | `Sight.emitOutcomeEvent({ sessionExternalId, kind, detail? })` | Your own outcome: a resolved ticket, a conversion | [Outcome helpers](https://sight.cultured.computer/docs/sdk-reference#outcome-helpers) |
165
+ | `Sight.flagPersonaBreak({ sessionExternalId, note?, turnIndex? })` | A person's report that a reply was out of character | [Outcome helpers](https://sight.cultured.computer/docs/sdk-reference#outcome-helpers) |
166
+ | `Sight.userThumbs(id, "up" \| "down")`, `Sight.userRating(id, 1..5)` | Feedback, sent with the next captured turn | [Outcome helpers](https://sight.cultured.computer/docs/sdk-reference#outcome-helpers) |
167
+ | `Sight.endSession({ externalId, endedReason?, outcome? })` | Why the session ended, and an outcome known at close | [Sessions](https://sight.cultured.computer/docs/sdk-reference#sessions) |
168
+ | `Sight.captureSpans(spans, alignment?)` | Steps inside a turn: tool calls, model calls. At most 50 per call. | [Spans](https://sight.cultured.computer/docs/sdk-reference#spans) |
169
+ | `Sight.captureEnvironmentEvents(events, alignment?)` | Events from a channel beside the conversation. At most 100 per call. | [Environment events](https://sight.cultured.computer/docs/sdk-reference#environment-events) |
170
+ | `Sight.shutdown()` | Nothing; waits for sends in flight. Await it before a short-lived process exits. | [SDK reference](https://sight.cultured.computer/docs/sdk-reference) |
171
+
172
+ ## The CLI
173
+
174
+ `npx @cultured_computer/sight <verb>`. `sight --help` lists flags and
175
+ environment variables. Secrets are read from the environment, never from a flag.
176
+
177
+ | Verb | What it does | Key or login needed |
178
+ | --- | --- | --- |
179
+ | `sight auth login` | Signs this terminal in: prints a link, you approve it in your browser | Your dashboard sign-in |
180
+ | `sight auth logout` | Deletes the stored login token | None |
181
+ | `sight export --project <slug> --deployment <slug>` | Writes a deployment's record as JSONL (`--out <file>`, default stdout) | `auth login`; owner role on the project |
182
+ | `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` |
183
+ | `sight account create` | Redeems a one-time token and saves the key to `~/.config/sight/machine.json` (mode `0600`) | `SIGHT_PROVISION_TOKEN` |
184
+ | `sight openrouter connect --budget <usd>` | Connects your OpenRouter key (`OPENROUTER_API_KEY`) to the project | A key with `providers:write` |
185
+ | `sight openrouter status` | Prints the stored connection: status, last four characters, budget | A key with `studio:run` or `providers:write` |
186
+ | `sight connect <relay-url> --invite <code>` | See [Connect your room](https://sight.cultured.computer/docs/connect-your-room) | An invite code |
187
+
188
+ Every flag: [CLI](https://sight.cultured.computer/docs/cli).
189
+
190
+ ## Serving a profile
191
+
192
+ - The Field API serves a profile on the same host, `https://api.cultured.computer`, with keys from the same API Keys page.
193
+ - This package has no client and no CLI verbs for it.
194
+ - Docs: [Serve a SOUL.md](https://sight.cultured.computer/docs/serve-a-soul-md).
195
+
196
+ ## Troubleshooting
197
+
198
+ Failed sends never throw. The first send the API rejects prints one
199
+ warning on stderr without `debug`: once per process for `401`, once for
200
+ `403`, once for any other `4xx` except `429`. Set `debug: true` on `init`
201
+ to log every failed send as `[sight] ingest failed status=<code>`.
202
+
203
+ | Symptom | Cause | Fix |
204
+ | --- | --- | --- |
205
+ | Nothing captured; stderr shows `[sight] call not captured (...): no session scope.` | The model call ran outside a session scope | Wrap it in `Sight.withSession(id, fn)` |
206
+ | Nothing captured, no warning | The send failed with a server or network error, or the client is not on a capture path | Set `debug: true` and read the status it logs |
207
+ | `[sight] the API rejected the key (401). Nothing is being captured.` | The key is missing, mistyped or revoked | Set `SIGHT_API_KEY` to a current key |
208
+ | `[sight] this key cannot capture (403): it lacks the ingest capability.` | The key lacks the `ingest` capability | Use a key with access `ingest`, `both` or `app` |
209
+ | `[sight] the API rejected a turn (400) and it was dropped.` (or `413`) | The API refused that request body | Set `debug: true` to log every failed send; check the turn's fields and size |
210
+ | `status=429`, or one `[sight] rate limited (429)` line | Over the project's request limit (600 per minute by default). Each limited send is retried once after `Retry-After`, then dropped. | Send fewer requests per minute, or ask for a higher limit |
211
+ | The first-session line is not printed | No turn has been accepted yet. The line prints once per process, on stderr. | Fix the rows above |
212
+ | `ai` 6 calls are not captured | `ai` 6 emits telemetry only for calls that opt in | Add `experimental_telemetry: { isEnabled: true }` to the call |
213
+ | An `ai` 7 call made right after `init` is missed | On Node below 22.13 the integration registers a moment after `init` returns | Call `registerTelemetry(sightTelemetry())` yourself, once (`registerTelemetry` is from `ai`) |
214
+ | `[sight] OpenAI module patching did not attach` | The client is not wrapped | `wrapOpenAI(new OpenAI())` |
215
+
216
+ ## Versions and compatibility
217
+
218
+ | Library | `peerDependencies` range (all optional) | Verified by this package's tests |
219
+ | --- | --- | --- |
220
+ | Node | `engines`: `>=20.6.0` | `ai` 7 itself requires Node 22 |
221
+ | `openai` | `>=4.0.0` | `wrapOpenAI` against stand-in clients; type-checked against 6.45.0 |
222
+ | `ai` | `>=3.0.0` | 7.0.17 and 6.0.300. Versions 3 to 5 are not verified. |
223
+ | `@anthropic-ai/sdk` | `>=0.30.0` | Not covered |
224
+ | `langchain` | `>=1.0.0 <2.0.0` | Not covered |
225
+
226
+ ## Changelog
227
+
228
+ `CHANGELOG.md` ships in the package:
229
+ [browse it on npm](https://www.npmjs.com/package/@cultured_computer/sight?activeTab=code).
330
230
 
331
231
  ## Legal
332
232