@cultured_computer/sight 0.7.1 → 0.8.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 +257 -0
- package/README.md +380 -78
- package/dist/cli.js +57 -33
- package/dist/index.cjs +1148 -194
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +210 -86
- package/dist/index.d.ts +210 -86
- package/dist/index.js +1148 -196
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
# Sight
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 one turn per model call made
|
|
4
|
+
inside a session scope: the person's message, the reply it prompted, the
|
|
5
|
+
plumbing (model, tokens, latency, tool names, finish reason, cost when
|
|
6
|
+
reported). Capture is out of band; responses are never modified or
|
|
7
|
+
delayed. The record is one published, versioned shape. Docs:
|
|
8
|
+
https://sight.cultured.computer/docs
|
|
24
9
|
|
|
25
10
|
## Install
|
|
26
11
|
|
|
@@ -28,36 +13,71 @@ around it are still moving.
|
|
|
28
13
|
npm install @cultured_computer/sight
|
|
29
14
|
```
|
|
30
15
|
|
|
31
|
-
|
|
16
|
+
Requirements:
|
|
17
|
+
|
|
18
|
+
- Node 20.6 or later.
|
|
19
|
+
- Server-side Node only; never ship the key to a browser.
|
|
20
|
+
- TypeScript types ship with the package. ESM and CommonJS builds are both
|
|
21
|
+
included.
|
|
32
22
|
|
|
33
23
|
## Quickstart
|
|
34
24
|
|
|
25
|
+
A complete example that captures one turn per model call:
|
|
26
|
+
|
|
35
27
|
```ts
|
|
36
|
-
import
|
|
28
|
+
import OpenAI from "openai";
|
|
29
|
+
import { Sight, wrapOpenAI } from "@cultured_computer/sight";
|
|
37
30
|
|
|
38
31
|
Sight.init({
|
|
39
32
|
apiKey: process.env.SIGHT_API_KEY!,
|
|
40
33
|
deployment: "my-assistant",
|
|
41
34
|
});
|
|
42
35
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
const openai = wrapOpenAI(new OpenAI());
|
|
37
|
+
|
|
38
|
+
export async function reply(
|
|
39
|
+
conversationId: string,
|
|
40
|
+
userId: string,
|
|
41
|
+
userMessage: string,
|
|
42
|
+
): Promise<string> {
|
|
43
|
+
Sight.startSession({ externalId: conversationId, externalUserId: userId });
|
|
44
|
+
// The person's message. It is sent with the turn captured next.
|
|
45
|
+
Sight.userInputSubmit(conversationId, userMessage);
|
|
46
|
+
|
|
47
|
+
// A model call is captured only inside a session scope.
|
|
48
|
+
return Sight.withSession(conversationId, async () => {
|
|
49
|
+
const res = await openai.chat.completions.create({
|
|
50
|
+
model: "gpt-4.1",
|
|
51
|
+
messages: [{ role: "user", content: userMessage }],
|
|
52
|
+
});
|
|
53
|
+
return res.choices[0]?.message.content ?? "";
|
|
54
|
+
});
|
|
55
|
+
}
|
|
47
56
|
```
|
|
48
57
|
|
|
58
|
+
On the first accepted turn the SDK prints one line on stderr with a link to
|
|
59
|
+
the session in the dashboard.
|
|
60
|
+
|
|
49
61
|
Notes:
|
|
50
62
|
|
|
51
|
-
- `apiKey` is a
|
|
52
|
-
|
|
53
|
-
(shown once)
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
- `apiKey` is a key with the `ingest` capability (access word `ingest`,
|
|
64
|
+
`both` or `app`), minted by an owner on the dashboard's API Keys page
|
|
65
|
+
(shown once) and set as `SIGHT_API_KEY`. Sign-in is allowlisted; without
|
|
66
|
+
a dashboard, redeem a provisioning token with `sight account create`.
|
|
67
|
+
The endpoint defaults to `https://fieldwork-ingest.fly.dev`; override it
|
|
68
|
+
with `endpoint` only for self-hosting or staging.
|
|
56
69
|
- `init` runs once at startup. `deployment` identifies the configuration this
|
|
57
70
|
traffic belongs to; all measurement is per deployment.
|
|
58
|
-
- `
|
|
59
|
-
|
|
71
|
+
- `Sight.withSession(id, fn)` is required for autocapture. `id` is the
|
|
72
|
+
session's external id (one conversation). A model call made outside any
|
|
73
|
+
session scope is not captured. The first such call in a process prints one
|
|
74
|
+
warning naming `Sight.withSession(id, fn)`; later ones log only with
|
|
75
|
+
`debug: true`.
|
|
76
|
+
- `startSession` is optional. Use it to attach `externalUserId`, a stable,
|
|
77
|
+
pseudonymous user id you supply. Return metrics key on the user id;
|
|
60
78
|
sessions without it still capture, but return behaviour is not computable.
|
|
79
|
+
- `wrapOpenAI` does not read the person's message from the request. Record
|
|
80
|
+
it with `Sight.userInputSubmit(sessionId, text)` before the model call.
|
|
61
81
|
|
|
62
82
|
## Headless project setup
|
|
63
83
|
|
|
@@ -76,8 +96,8 @@ npx @cultured_computer/sight account create --openrouter --budget 25
|
|
|
76
96
|
The provisioning token and OpenRouter key are read only from the environment,
|
|
77
97
|
not command-line arguments. The Sight key is returned once and saved to
|
|
78
98
|
`~/.config/sight/machine.json` with mode `0600`; it is never printed. Sight
|
|
79
|
-
|
|
80
|
-
|
|
99
|
+
checks the OpenRouter key against OpenRouter, seals it before database storage,
|
|
100
|
+
and records the monthly budget. Check the safe, redacted state later with:
|
|
81
101
|
|
|
82
102
|
```bash
|
|
83
103
|
npx @cultured_computer/sight openrouter status
|
|
@@ -144,54 +164,304 @@ npx @cultured_computer/sight auth logout
|
|
|
144
164
|
|
|
145
165
|
One more CLI door, for a different shape: `sight connect` attaches Sight to a
|
|
146
166
|
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
|
|
167
|
+
authorization, no account needed up front). A side lane, not the install:
|
|
148
168
|
the walkthrough lives at
|
|
149
169
|
[Connect your buzz community](https://sight.cultured.computer/docs/connect-your-room).
|
|
150
170
|
|
|
151
|
-
## What
|
|
171
|
+
## What autocapture records
|
|
172
|
+
|
|
173
|
+
Autocapture turns each model call made inside `Sight.withSession(id, fn)`
|
|
174
|
+
into one turn. There are three paths. A model call seen by more than one
|
|
175
|
+
path is one turn.
|
|
152
176
|
|
|
153
|
-
|
|
154
|
-
|
|
177
|
+
### OpenAI: wrap the client
|
|
178
|
+
|
|
179
|
+
The path to use for OpenAI. It does not depend on module format, load
|
|
180
|
+
order, or the `openai` version.
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
const openai = wrapOpenAI(new OpenAI());
|
|
184
|
+
// Wrap before or after Sight.init(); order does not matter.
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Covers `chat.completions.create` and `responses.create`, streaming included.
|
|
188
|
+
|
|
189
|
+
Provider is read from the client's `baseURL`:
|
|
190
|
+
|
|
191
|
+
| `baseURL` host | Provider |
|
|
192
|
+
|---|---|
|
|
193
|
+
| none, or `api.openai.com` | `openai` |
|
|
194
|
+
| `openrouter.ai` | `openrouter` |
|
|
195
|
+
| `*.openai.azure.com` | `azure` |
|
|
196
|
+
| `*.inceptionlabs.ai`, or a model name starting with `mercury` | `inception` |
|
|
197
|
+
| any other host | not sent |
|
|
198
|
+
|
|
199
|
+
A streamed call through a wrapped client also records:
|
|
200
|
+
|
|
201
|
+
- First-token time: milliseconds from the start of the request to the first
|
|
202
|
+
chunk that carries output. Chat Completions: a non-empty
|
|
203
|
+
`delta.content`, a non-empty `delta.refusal`, or a `delta.tool_calls`
|
|
204
|
+
entry. The opening chunk that carries only the role is not a token.
|
|
205
|
+
Responses API: the first `response.output_text.delta`,
|
|
206
|
+
`response.refusal.delta` or `response.function_call_arguments.delta`, or
|
|
207
|
+
a `response.output_item.added` whose item is a `function_call`.
|
|
208
|
+
- Tool names and count of streamed tool calls.
|
|
209
|
+
|
|
210
|
+
A call that is not streamed has no first-token time; the field is not sent.
|
|
211
|
+
A stream that ends before any output has none either.
|
|
212
|
+
|
|
213
|
+
### Vercel AI SDK (`ai`)
|
|
214
|
+
|
|
215
|
+
Verified with `ai` 7.0.17 (telemetry integration) and `ai` 6.0.300
|
|
216
|
+
(OpenTelemetry spans). `ai` 3 to 5 are not verified.
|
|
217
|
+
|
|
218
|
+
`ai` 7: nothing to add. `init` registers a telemetry integration with `ai`,
|
|
219
|
+
and `ai` 7 sends every call to a registered integration; no per-call flag.
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
import { generateText } from "ai";
|
|
223
|
+
|
|
224
|
+
Sight.init({ apiKey: process.env.SIGHT_API_KEY!, deployment: "my-assistant" });
|
|
225
|
+
|
|
226
|
+
await Sight.withSession(conversationId, () =>
|
|
227
|
+
generateText({ model, system, messages }),
|
|
228
|
+
);
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Covers `generateText`, `streamText`, `generateObject`, `streamObject` and
|
|
232
|
+
`ToolLoopAgent`.
|
|
233
|
+
|
|
234
|
+
- Turn unit: one model call. A tool loop of N model calls is N turns. Each
|
|
235
|
+
carries the text of that reply (none when the model only requested tools)
|
|
236
|
+
and the names of the tools it requested. The outer `generateText` call is
|
|
237
|
+
not a turn.
|
|
238
|
+
- Streaming: one turn when the model call's stream ends, with the full text
|
|
239
|
+
and the time to the first output. A stream nobody reads captures nothing.
|
|
240
|
+
- A model call that throws is one turn with the error message and no reply.
|
|
241
|
+
An aborted stream is one turn with error `aborted` and no reply. A stream
|
|
242
|
+
that fails part way is one turn with the partial text, finish reason
|
|
243
|
+
`error` and an error field.
|
|
244
|
+
- `generateObject` and `streamObject`: the reply is the JSON text the model
|
|
245
|
+
produced.
|
|
246
|
+
- Session: the `Sight.withSession` scope the call started in. Outside any
|
|
247
|
+
scope, name the session on the call, either way:
|
|
155
248
|
|
|
156
249
|
```ts
|
|
157
|
-
import
|
|
158
|
-
import { Sight, wrapOpenAI } from "@cultured_computer/sight";
|
|
250
|
+
import { sightTelemetry } from "@cultured_computer/sight";
|
|
159
251
|
|
|
160
|
-
|
|
161
|
-
|
|
252
|
+
// 1. On the integration, for this call.
|
|
253
|
+
generateText({
|
|
254
|
+
model,
|
|
255
|
+
prompt,
|
|
256
|
+
telemetry: { integrations: sightTelemetry({ sessionId: conversationId }) },
|
|
257
|
+
});
|
|
162
258
|
|
|
163
|
-
//
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
259
|
+
// 2. In runtimeContext. `ai` passes a runtimeContext key to telemetry only
|
|
260
|
+
// when includeRuntimeContext names it. Keys read: sightSessionId, then
|
|
261
|
+
// sessionId.
|
|
262
|
+
generateText({
|
|
263
|
+
model,
|
|
264
|
+
prompt,
|
|
265
|
+
runtimeContext: { sightSessionId: conversationId },
|
|
266
|
+
telemetry: { includeRuntimeContext: { sightSessionId: true } },
|
|
171
267
|
});
|
|
172
|
-
// A call made outside any session scope is skipped — with a one-line
|
|
173
|
-
// warning naming withSession, never a silent drop.
|
|
174
268
|
```
|
|
175
269
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
270
|
+
An explicit scope wins over both. `telemetry.integrations` on a call
|
|
271
|
+
replaces the registered integrations for that call (an `ai` rule): to keep
|
|
272
|
+
another integration on that call, list it next to `sightTelemetry(...)`.
|
|
273
|
+
With no scope and no session id the call is skipped and the one
|
|
274
|
+
no-session warning prints.
|
|
275
|
+
- `telemetry: { isEnabled: false }` on a call turns capture off for it.
|
|
276
|
+
`recordOutputs: false` drops the reply text. `recordInputs: false` drops
|
|
277
|
+
the person's message and the system prompt hash.
|
|
278
|
+
- Registration: `init` loads `ai` and calls its `registerTelemetry()`.
|
|
279
|
+
On Node 22.13 or later (`ai` 7 itself needs Node 22) this is done before
|
|
280
|
+
`init` returns. On older Node it completes a moment later and a call made
|
|
281
|
+
in the same tick as `init` is missed. If the SDK cannot resolve your `ai` (some bundles), register it
|
|
282
|
+
yourself, once:
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
import { registerTelemetry } from "ai";
|
|
286
|
+
import { sightTelemetry } from "@cultured_computer/sight";
|
|
287
|
+
|
|
288
|
+
registerTelemetry(sightTelemetry());
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Registering both ways is safe: it is registered once.
|
|
292
|
+
- With `@ai-sdk/otel` also registered, the span it emits for a model call
|
|
293
|
+
and the Sight integration's turn are one turn (matched on the provider
|
|
294
|
+
response id).
|
|
295
|
+
|
|
296
|
+
What an `ai` 7 turn carries: reply text (text parts only; reasoning, tool
|
|
297
|
+
input and tool output are never part of it), the model id the provider
|
|
298
|
+
returned, the provider id as `ai` names it (for example `openai.responses`),
|
|
299
|
+
input and output tokens, cache read and cache write tokens, tool names and
|
|
300
|
+
count, finish reason, the model call's response time, time to first output
|
|
301
|
+
for streams, the person's message (same rule as below), a `turnId`.
|
|
302
|
+
Not carried: cost; the error message of a stream that fails part way (the
|
|
303
|
+
events do not include it); the partial text of an aborted stream.
|
|
304
|
+
|
|
305
|
+
`ai` 6: it sends no events to the integration's model-call hooks. It emits
|
|
306
|
+
OpenTelemetry spans, and only for calls that set the flag:
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
await Sight.withSession(conversationId, () =>
|
|
310
|
+
generateText({ model, prompt, experimental_telemetry: { isEnabled: true } }),
|
|
311
|
+
);
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
The span processor (next section) captures its model-call spans:
|
|
315
|
+
`ai.generateText.doGenerate`, `ai.streamText.doStream`,
|
|
316
|
+
`ai.generateObject.doGenerate`, `ai.streamObject.doStream`. Same turn unit.
|
|
317
|
+
The outer `ai.generateText` span and `ai.toolCall` spans are not turns.
|
|
318
|
+
Outside a scope, the session id is read from
|
|
319
|
+
`experimental_telemetry.metadata.sightSessionId`, then `.sessionId`.
|
|
320
|
+
|
|
321
|
+
### Instrumented libraries: OpenTelemetry spans
|
|
322
|
+
|
|
323
|
+
From `init`, the SDK enables module instrumentation for the OpenAI SDK, the
|
|
324
|
+
Anthropic SDK and LangChain (LangGraph runs through the LangChain
|
|
325
|
+
instrumentation), and captures the model-call spans they emit. Each adapter
|
|
326
|
+
does nothing if its library is not installed.
|
|
327
|
+
|
|
328
|
+
Limits:
|
|
329
|
+
|
|
330
|
+
- OpenAI module patching attaches only under CommonJS, only when `openai`
|
|
331
|
+
loads after `init`, and only for openai v4. If it did not attach and no
|
|
332
|
+
client has been wrapped, the SDK prints one warning at startup. Under ESM
|
|
333
|
+
or openai v5 and later, wrap the client.
|
|
334
|
+
- Anthropic module patching has the same CommonJS and load-order limits and
|
|
335
|
+
no startup check. Confirm capture with `debug: true`.
|
|
336
|
+
- LiteLLM (Python) is not captured.
|
|
337
|
+
|
|
338
|
+
Any OpenTelemetry instrumentation that emits GenAI spans through the global
|
|
339
|
+
tracer provider is captured the same way. A span becomes a turn when
|
|
340
|
+
`gen_ai.operation.name` is `chat`, `generate_content` or `text_completion`,
|
|
341
|
+
or when it is one of the `ai` 6 model-call spans named above (identified by
|
|
342
|
+
`ai.operationId`). Spans for `embeddings`, `invoke_agent`, `create_agent`,
|
|
343
|
+
workflows and `execute_tool` are not turns.
|
|
344
|
+
|
|
345
|
+
Attributes read from a span (the current name first, then the fallbacks):
|
|
346
|
+
|
|
347
|
+
| Field | Attributes |
|
|
348
|
+
|---|---|
|
|
349
|
+
| Provider | `gen_ai.provider.name`, `gen_ai.system`, `gen_ai.provider`, `ai.model.provider` |
|
|
350
|
+
| Model | `gen_ai.response.model`, `ai.response.model`, `gen_ai.request.model`, `ai.model.id` |
|
|
351
|
+
| Requested model | `gen_ai.request.model`, `ai.model.id` |
|
|
352
|
+
| Cost | `gen_ai.usage.cost` |
|
|
353
|
+
| Reply text | `ai.response.text` when present; otherwise the text parts of `gen_ai.output.messages`; otherwise `ai.response.object` |
|
|
354
|
+
| The person's message | last user message of `gen_ai.input.messages`, or of `ai.prompt.messages` |
|
|
355
|
+
| Input tokens | `gen_ai.usage.input_tokens`, `gen_ai.usage.prompt_tokens`, `ai.usage.inputTokens`, `ai.usage.promptTokens` |
|
|
356
|
+
| Output tokens | `gen_ai.usage.output_tokens`, `gen_ai.usage.completion_tokens`, `ai.usage.outputTokens`, `ai.usage.completionTokens` |
|
|
357
|
+
| Cache read tokens | `gen_ai.usage.cache_read.input_tokens`, `gen_ai.usage.cache_read_input_tokens`, `ai.usage.inputTokenDetails.cacheReadTokens`, `ai.usage.cachedInputTokens` |
|
|
358
|
+
| Cache creation tokens | `gen_ai.usage.cache_creation.input_tokens`, `gen_ai.usage.cache_creation_input_tokens`, `ai.usage.inputTokenDetails.cacheWriteTokens` |
|
|
359
|
+
| Tool names and count | `tool_call` parts of `gen_ai.output.messages`; `toolName` of each entry in `ai.response.toolCalls`; child `execute_tool` spans (`gen_ai.tool.name`); `gen_ai.response.tool_names`, `gen_ai.response.tool_calls_count` |
|
|
360
|
+
| Finish reason | first of `gen_ai.response.finish_reasons`, `ai.response.finishReason` |
|
|
361
|
+
| Time to first token | `ai.response.msToFirstChunk`, `ai.stream.msToFirstChunk` |
|
|
362
|
+
| Session (fallback) | `gen_ai.conversation.id`, `ai.telemetry.metadata.sightSessionId`, `ai.telemetry.metadata.sessionId` |
|
|
363
|
+
|
|
364
|
+
Rules:
|
|
365
|
+
|
|
366
|
+
- Session: the `Sight.withSession` scope first. With no scope, the first
|
|
367
|
+
session attribute in the table that the span carries is the session id.
|
|
368
|
+
- A span is not a second turn for a model call another path captures: a
|
|
369
|
+
span started inside an `ai` 7 model call that the Sight integration
|
|
370
|
+
handles is skipped, and so is a span whose `gen_ai.response.id` (or
|
|
371
|
+
`ai.response.id`) the integration reported for the same call. A wrapped
|
|
372
|
+
OpenAI client called inside such a model call passes through uncaptured.
|
|
373
|
+
Not covered: two instrumentations that both emit a span for one call
|
|
374
|
+
outside `ai` (for example a patched and a wrapped OpenAI client used
|
|
375
|
+
together); those are two turns.
|
|
376
|
+
- The person's message is sent as `userInput.text` only when the request's
|
|
377
|
+
last message is the person's and carries text, and only when no text
|
|
378
|
+
recorded with `userInputSubmit` is pending for that turn. Explicit input
|
|
379
|
+
wins. A turn's person text is the message that prompted its reply.
|
|
380
|
+
- The reply is stored as plain text. A structured message array is parsed;
|
|
381
|
+
reasoning and tool parts are not part of the reply text.
|
|
382
|
+
|
|
383
|
+
### Fields on every autocaptured turn
|
|
384
|
+
|
|
385
|
+
Model, provider, input and output tokens, latency, tool names and count,
|
|
386
|
+
finish reason, error message, cache read tokens when the provider reports
|
|
387
|
+
them, the reply text, the requested model, a `turnId`.
|
|
388
|
+
|
|
389
|
+
First-token time: sent for a streamed call through a wrapped OpenAI client
|
|
390
|
+
and for an `ai` stream. Not sent for a call that is not streamed, and not
|
|
391
|
+
sent by the bundled OpenAI, Anthropic and LangChain instrumentations, which
|
|
392
|
+
do not report it on the span.
|
|
393
|
+
|
|
394
|
+
Cost, in this order:
|
|
395
|
+
|
|
396
|
+
1. Reported by the provider. When the response usage carries a cost
|
|
397
|
+
(OpenRouter's `usage.cost`; `gen_ai.usage.cost` on a span), the SDK sends
|
|
398
|
+
it and the turn stores it as reported. A reported cost of 0 is stored
|
|
399
|
+
as 0. On an OpenRouter bring-your-own-key call the cost is sent only
|
|
400
|
+
when `cost_details.upstream_inference_cost` is reported too, as the sum
|
|
401
|
+
of the two. The `ai` 7 integration sends no cost.
|
|
402
|
+
2. Estimated from the price catalogue. With no reported cost, the server
|
|
403
|
+
computes the cost from the turn's token counts when the turn's provider
|
|
404
|
+
and model name exactly one catalogue price in effect at the turn's time.
|
|
405
|
+
The match is exact string equality on provider and model: the response
|
|
406
|
+
model first, then the requested model (OpenRouter turns: the response
|
|
407
|
+
model only). Cached tokens are priced at the catalogue's cached rate.
|
|
408
|
+
The estimate is a list price, not a billed amount.
|
|
409
|
+
3. Unavailable. In every other case the turn has no cost: no token counts,
|
|
410
|
+
an unknown provider or model, more than one matching catalogue entry,
|
|
411
|
+
no price in effect at the turn's time, or cached tokens with no cached
|
|
412
|
+
rate in the catalogue or no known counting convention. An unavailable
|
|
413
|
+
cost is empty, never 0.
|
|
414
|
+
|
|
415
|
+
Each turn records which of the three applied on its `probe_meta`:
|
|
416
|
+
`costSource` is `provider` or `catalogue:<price version id>`, or absent
|
|
417
|
+
with `costUnavailable` naming the reason.
|
|
418
|
+
|
|
419
|
+
Not sent by autocapture: reasoning tokens.
|
|
420
|
+
|
|
421
|
+
### Delivery
|
|
422
|
+
|
|
423
|
+
- Capture never blocks your LLM path. Send failures log in debug mode and
|
|
424
|
+
are otherwise swallowed.
|
|
425
|
+
- Invalid input to any capture method logs one warning line naming the
|
|
426
|
+
first invalid field and is dropped.
|
|
427
|
+
- A rate-limited send (429) is retried once after `Retry-After`.
|
|
428
|
+
- Sessions are created lazily on the first captured turn.
|
|
429
|
+
|
|
430
|
+
## Capture a turn manually
|
|
431
|
+
|
|
432
|
+
For calls autocapture does not see:
|
|
433
|
+
|
|
434
|
+
```ts
|
|
435
|
+
await Sight.captureTurn({
|
|
436
|
+
sessionExternalId: conversationId,
|
|
437
|
+
turnIndex: 0,
|
|
438
|
+
userInput: { text: userMessage },
|
|
439
|
+
payload: {
|
|
440
|
+
response: { text: replyText },
|
|
441
|
+
probe_model: "my-model",
|
|
442
|
+
probe_provider: "my-provider",
|
|
443
|
+
probe_tokens_input: 412,
|
|
444
|
+
probe_tokens_output: 96,
|
|
445
|
+
probe_latency_ms: 840,
|
|
446
|
+
},
|
|
447
|
+
});
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
- `deploymentSlug` is optional. It defaults to the `deployment` given to
|
|
451
|
+
`init`; an explicit value wins.
|
|
452
|
+
- `turnIndex` is the turn's position in the session, starting at 0. You
|
|
453
|
+
supply it. (Autocapture counts per session inside the process.)
|
|
454
|
+
- The turn is checked against the wire schema before it is sent. An invalid turn logs one warning
|
|
455
|
+
line and is not sent.
|
|
456
|
+
|
|
457
|
+
## Turn identity
|
|
458
|
+
|
|
459
|
+
Every captured turn is sent with a `turnId`: a fresh UUID per logical turn.
|
|
460
|
+
The SDK's own retry of a send re-sends the same `turnId`. Autocapture's
|
|
461
|
+
`turnIndex` is a counter held in the process, so two processes capturing
|
|
462
|
+
one session, or one process restarted, send the same `turnIndex` with
|
|
463
|
+
different `turnId`s. To supply your own identity on a manual capture, pass
|
|
464
|
+
`turnId` (a UUID) to `captureTurn`.
|
|
195
465
|
|
|
196
466
|
## Attach outcomes
|
|
197
467
|
|
|
@@ -297,6 +567,29 @@ is reserved for contract-v1 rows. The unversioned v1 shape remains accepted for
|
|
|
297
567
|
read through a legacy adapter. `Sight.captureSpan(span)` is the single-span
|
|
298
568
|
form.
|
|
299
569
|
|
|
570
|
+
Run and Session trace views render recorded `tool_call` and `llm_call` spans
|
|
571
|
+
with their explicit status and payload states. To display a provider-exposed
|
|
572
|
+
reasoning **summary** and a caller-measured context budget, attach these
|
|
573
|
+
optional attributes to the relevant span:
|
|
574
|
+
|
|
575
|
+
```ts
|
|
576
|
+
attributes: {
|
|
577
|
+
"sight.reasoning.summary": "The recorded provider summary",
|
|
578
|
+
"sight.reasoning.duration_ms": 7000,
|
|
579
|
+
"gen_ai.usage.cache_read_input_tokens": 31500,
|
|
580
|
+
"sight.context.used_tokens": 40372,
|
|
581
|
+
"sight.context.limit_tokens": 100000,
|
|
582
|
+
}
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
Do not supply hidden reasoning or manufacture a summary from the reply.
|
|
586
|
+
Summary strings pass through the same span PII scrub; they are dropped when
|
|
587
|
+
redaction is unavailable. Budget values are recorded per call, not accumulated
|
|
588
|
+
Run spend, and both values are required for the gauge. Missing cached-token
|
|
589
|
+
usage is not zero usage. Tool arguments/results belong in the versioned
|
|
590
|
+
`input`/`output` payloads, not attributes; completion of a model call never
|
|
591
|
+
establishes that a requested tool ran successfully.
|
|
592
|
+
|
|
300
593
|
## Scope
|
|
301
594
|
|
|
302
595
|
Sight is a measurement system: it reports what a deployment did. It does not
|
|
@@ -320,13 +613,22 @@ consequences. See [Data format](https://sight.cultured.computer/docs/data-format
|
|
|
320
613
|
## Docs
|
|
321
614
|
|
|
322
615
|
- [Get started](https://sight.cultured.computer/docs/get-started):
|
|
323
|
-
install, initialise, verify capture.
|
|
324
|
-
- [
|
|
325
|
-
|
|
616
|
+
install, initialise, verify capture, the turn identity contract.
|
|
617
|
+
- [Keys and access](https://sight.cultured.computer/docs/keys-and-access):
|
|
618
|
+
the seven access words and which host takes which key.
|
|
619
|
+
- [Integration paths](https://sight.cultured.computer/docs/integration-paths):
|
|
620
|
+
what each capture path sends.
|
|
326
621
|
- [SDK reference](https://sight.cultured.computer/docs/sdk-reference):
|
|
327
622
|
the full method surface.
|
|
328
|
-
- [
|
|
329
|
-
|
|
623
|
+
- [CLI](https://sight.cultured.computer/docs/cli): every verb.
|
|
624
|
+
- [HTTP API](https://sight.cultured.computer/docs/http-api): every route
|
|
625
|
+
on the capture host and the Field API.
|
|
626
|
+
- [Privacy & retention](https://sight.cultured.computer/docs/data-and-privacy):
|
|
627
|
+
what is scrubbed, by what, and what is kept.
|
|
628
|
+
- [Serve a SOUL.md](https://sight.cultured.computer/docs/serve-a-soul-md):
|
|
629
|
+
the Field API, which this package has no client or CLI verbs for.
|
|
630
|
+
- [Status](https://sight.cultured.computer/docs/where-it-stands): built,
|
|
631
|
+
operator-run, not built.
|
|
330
632
|
|
|
331
633
|
## Legal
|
|
332
634
|
|
package/dist/cli.js
CHANGED
|
@@ -13,48 +13,70 @@ function flag(args, name) {
|
|
|
13
13
|
function usage() {
|
|
14
14
|
console.log(
|
|
15
15
|
[
|
|
16
|
-
"sight: the
|
|
16
|
+
"sight: the command line for Sight. Sign a terminal in, export your data, read detector checks, set up a project.",
|
|
17
17
|
"",
|
|
18
18
|
"Usage:",
|
|
19
|
-
" sight connect <relay-url> --invite <code> [--pulse] [--api <base>]",
|
|
20
19
|
" sight auth login [--base <dashboard-url>]",
|
|
21
20
|
" sight auth logout",
|
|
21
|
+
" sight export --project <slug> --deployment <slug> [--readings|--conditions] [--out file.jsonl]",
|
|
22
|
+
" sight conditions --session <id-or-external-id> [--deployment <slug>] [--run <id>] [--since <iso>] [--until <iso>] [--base <dashboard-url>]",
|
|
22
23
|
" sight account create [--openrouter --budget <usd>] [--api <base>]",
|
|
23
24
|
" sight openrouter connect --budget <usd> [--api <base>]",
|
|
24
25
|
" sight openrouter status [--api <base>]",
|
|
25
|
-
" sight
|
|
26
|
-
"
|
|
26
|
+
" sight connect <relay-url> --invite <code> [--pulse] [--api <base>]",
|
|
27
|
+
"",
|
|
28
|
+
"Commands:",
|
|
29
|
+
" auth login sign this terminal in with your browser session: a code",
|
|
30
|
+
" prints, you approve it on the dashboard. The token is",
|
|
31
|
+
" stored at ~/.config/sight/credentials.json (0600).",
|
|
32
|
+
" auth logout delete the stored login token.",
|
|
33
|
+
" export pull a deployment\u2019s full record (RLDS JSONL) with the",
|
|
34
|
+
" login token. Owner role on the project required.",
|
|
35
|
+
" --readings pull the per-turn judge labels instead.",
|
|
36
|
+
" --conditions pull the detector checks instead: each",
|
|
37
|
+
" checked sentence, flagged / not flagged /",
|
|
38
|
+
" not checked.",
|
|
39
|
+
" --out <file> write to a file (default: stdout).",
|
|
40
|
+
" conditions pull one session\u2019s (or one run\u2019s) detector checks with",
|
|
41
|
+
" the machine key: NDJSON to stdout, errors to stderr.",
|
|
42
|
+
" account create redeem SIGHT_PROVISION_TOKEN without a browser and save",
|
|
43
|
+
" the scoped Sight key at ~/.config/sight/machine.json",
|
|
44
|
+
" (0600). Add --openrouter --budget <usd> to also",
|
|
45
|
+
" validate and store OPENROUTER_API_KEY.",
|
|
46
|
+
" openrouter connect attach or rotate your own OpenRouter key; requires a",
|
|
47
|
+
" positive monthly --budget and a Sight key with",
|
|
48
|
+
" providers:write.",
|
|
49
|
+
" openrouter status print the stored provider connection: status, last",
|
|
50
|
+
" four characters of the key, monthly budget.",
|
|
51
|
+
" connect attach Sight to a buzz community as a read-only",
|
|
52
|
+
" observer. No account needed.",
|
|
53
|
+
" --invite one single-use invite code, minted by you on",
|
|
54
|
+
" your relay (its admin surface, or",
|
|
55
|
+
" POST /api/invites as the community owner).",
|
|
56
|
+
" Sight can never enter a community you did",
|
|
57
|
+
" not invite it into.",
|
|
58
|
+
" --pulse opt into the daily readout (off by default;",
|
|
59
|
+
" counts, times, and links only).",
|
|
27
60
|
"",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
61
|
+
"Environment:",
|
|
62
|
+
" SIGHT_API ingest API base used by connect, account create and",
|
|
63
|
+
" openrouter. Default https://fieldwork-ingest.fly.dev",
|
|
64
|
+
" (openrouter: the base saved by account create, when",
|
|
65
|
+
" there is one). --api overrides it.",
|
|
66
|
+
" SIGHT_BASE dashboard base used by auth login and conditions.",
|
|
67
|
+
" Default https://sight.cultured.computer. --base",
|
|
68
|
+
" overrides it. export uses the base stored at login.",
|
|
69
|
+
" SIGHT_API_KEY Sight key for openrouter and conditions; overrides",
|
|
70
|
+
" the key stored in machine.json.",
|
|
71
|
+
" SIGHT_PROVISION_TOKEN one-time token redeemed by account create.",
|
|
72
|
+
" OPENROUTER_API_KEY your OpenRouter key, read by account create",
|
|
73
|
+
" --openrouter and openrouter connect. Never printed.",
|
|
36
74
|
"",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
" token lives at ~/.config/sight/credentials.json (0600).",
|
|
40
|
-
" account create redeem SIGHT_PROVISION_TOKEN without a browser and",
|
|
41
|
-
" save the scoped Sight key in machine.json (0600). Add",
|
|
42
|
-
" --openrouter to validate + seal OPENROUTER_API_KEY.",
|
|
43
|
-
" openrouter connect attach/rotate your BYOK key; requires a positive",
|
|
44
|
-
" local monthly --budget and a providers:write Sight key.",
|
|
45
|
-
" export pull a deployment\u2019s full record (RLDS JSONL) with that",
|
|
46
|
-
" token. Owner role on the project required.",
|
|
47
|
-
" --readings pull the per-turn judge labels (the graded",
|
|
48
|
-
" reads: closure, backward-pass, and the rest)",
|
|
49
|
-
" instead of the record.",
|
|
50
|
-
" --conditions pull the detector checks: each checked",
|
|
51
|
-
" sentence, flagged / not flagged / not checked.",
|
|
52
|
-
" conditions pull one session\u2019s (or one run\u2019s) detector checks with",
|
|
53
|
-
" the machine key from ~/.config/sight/machine.json \u2014",
|
|
54
|
-
" NDJSON to stdout, errors to stderr.",
|
|
75
|
+
"The Field API (serving a profile) has no CLI verbs. Its docs:",
|
|
76
|
+
"https://sight.cultured.computer/docs/serve-a-soul-md",
|
|
55
77
|
"",
|
|
56
|
-
"The SDK
|
|
57
|
-
"https://sight.cultured.computer/docs
|
|
78
|
+
"The capture SDK in this package (server-side Node >=20.6) is documented at",
|
|
79
|
+
"https://sight.cultured.computer/docs"
|
|
58
80
|
].join("\n")
|
|
59
81
|
);
|
|
60
82
|
}
|
|
@@ -401,7 +423,7 @@ async function conditions(args) {
|
|
|
401
423
|
const session = flag(args, "--session");
|
|
402
424
|
const run = flag(args, "--run");
|
|
403
425
|
if (!session && !run) {
|
|
404
|
-
console.error("usage: sight conditions --session <id-or-external-id> [--run <id>] [--since <iso>] [--until <iso>] [--base <dashboard-url>]");
|
|
426
|
+
console.error("usage: sight conditions --session <id-or-external-id> [--deployment <slug>] [--run <id>] [--since <iso>] [--until <iso>] [--base <dashboard-url>]");
|
|
405
427
|
return 1;
|
|
406
428
|
}
|
|
407
429
|
const stored = readMachineCredentials();
|
|
@@ -413,6 +435,8 @@ async function conditions(args) {
|
|
|
413
435
|
}
|
|
414
436
|
const params = new URLSearchParams();
|
|
415
437
|
if (session) params.set("session", session);
|
|
438
|
+
const deployment = flag(args, "--deployment");
|
|
439
|
+
if (deployment) params.set("deployment", deployment);
|
|
416
440
|
if (run) params.set("run", run);
|
|
417
441
|
const since = flag(args, "--since");
|
|
418
442
|
if (since) params.set("since", since);
|