@cultured_computer/sight 0.8.3 → 0.8.4

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,17 @@ 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.8.4 (2026-10-13)
9
+
10
+ - Capture slots and drain now include consuming or cancelling the HTTP
11
+ response body, not just receiving its headers. Unused response bodies
12
+ are cancelled, and debug acknowledgements are capped at 64 KiB under
13
+ the existing request timeout.
14
+ - Drain uses elapsed time rather than the system clock. An incomplete
15
+ accepted acknowledgement never retries capture; only the existing
16
+ single rate-limit retry remains. Public exports and capture payloads
17
+ are unchanged.
18
+
8
19
  ## 0.8.3 (2026-10-06)
9
20
 
10
21
  - `sight openrouter connect --house-trial`: marks the connection as the
package/README.md CHANGED
@@ -196,6 +196,15 @@ Every flag: [CLI](https://sight.cultured.computer/docs/cli).
196
196
 
197
197
  ## Troubleshooting
198
198
 
199
+ Capture sends have a 15-second deadline and at most 64 requests in flight.
200
+ That slot covers the response body as well as headers: unused bodies are
201
+ cancelled, and debug turn acknowledgements are read up to 64 KiB. Await
202
+ `Sight.shutdown()` before a short-lived process exits; its bounded drain also
203
+ waits for pending rate-limit retries. A successful HTTP status means ingest
204
+ accepted the turn, not that worker redaction has finished. An acknowledgement
205
+ body failure never retries an accepted capture; only a `429` permits the
206
+ existing single retry after `Retry-After`.
207
+
199
208
  Failed sends never throw. The first send the API rejects prints one
200
209
  warning on stderr without `debug`: once per process for `401`, once for
201
210
  `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}` }
package/dist/index.cjs CHANGED
@@ -13,6 +13,34 @@ var MAX_PENDING_RETRIES = 50;
13
13
  var SEND_TIMEOUT_MS = 15e3;
14
14
  var MAX_INFLIGHT = 64;
15
15
  var MAX_TURN_BODY_BYTES = 9e5;
16
+ var MAX_ACK_BODY_BYTES = 65536;
17
+ async function readAcknowledgement(response) {
18
+ if (!response.body) return {};
19
+ const reader = response.body.getReader();
20
+ const chunks = [];
21
+ let size = 0;
22
+ try {
23
+ while (true) {
24
+ const { done, value } = await reader.read();
25
+ if (done) break;
26
+ size += value.byteLength;
27
+ if (size > MAX_ACK_BODY_BYTES) throw new Error("acknowledgement exceeds 65536 bytes");
28
+ chunks.push(value);
29
+ }
30
+ const bytes = new Uint8Array(size);
31
+ let offset = 0;
32
+ for (const chunk of chunks) {
33
+ bytes.set(chunk, offset);
34
+ offset += chunk.byteLength;
35
+ }
36
+ const body = JSON.parse(new TextDecoder().decode(bytes));
37
+ return body !== null && typeof body === "object" && "pendingId" in body && typeof body.pendingId === "string" ? { pendingId: body.pendingId } : {};
38
+ } finally {
39
+ await reader.cancel().catch(() => {
40
+ });
41
+ reader.releaseLock();
42
+ }
43
+ }
16
44
  var IngestClient = class {
17
45
  apiKey;
18
46
  endpoint;
@@ -48,7 +76,7 @@ var IngestClient = class {
48
76
  * first drop prints one stderr warning, later ones log only with
49
77
  * `debug: true`.
50
78
  */
51
- async guardedFetch(url, init) {
79
+ async guardedFetch(url, init, consume) {
52
80
  if (this.inFlight >= MAX_INFLIGHT) {
53
81
  if (!this.shedAnnounced) {
54
82
  this.shedAnnounced = true;
@@ -59,9 +87,14 @@ var IngestClient = class {
59
87
  throw new Error(`${MAX_INFLIGHT} sends already in flight; this send was dropped`);
60
88
  }
61
89
  this.inFlight++;
90
+ let response;
62
91
  try {
63
- return await fetch(url, { ...init, signal: AbortSignal.timeout(SEND_TIMEOUT_MS) });
92
+ response = await fetch(url, { ...init, signal: AbortSignal.timeout(SEND_TIMEOUT_MS) });
93
+ await consume?.(response);
94
+ return response;
64
95
  } finally {
96
+ if (response?.body && !response.body.locked) await response.body.cancel().catch(() => {
97
+ });
65
98
  this.inFlight--;
66
99
  }
67
100
  }
@@ -72,8 +105,8 @@ var IngestClient = class {
72
105
  * the time is up is not guaranteed to be sent.
73
106
  */
74
107
  async drainInFlight(timeoutMs = SEND_TIMEOUT_MS) {
75
- const deadline = Date.now() + timeoutMs;
76
- while ((this.inFlight > 0 || this.pendingRetries > 0) && Date.now() < deadline) {
108
+ const deadline = performance.now() + timeoutMs;
109
+ while ((this.inFlight > 0 || this.pendingRetries > 0) && performance.now() < deadline) {
77
110
  await new Promise((r) => setTimeout(r, 50));
78
111
  }
79
112
  }
@@ -103,6 +136,18 @@ var IngestClient = class {
103
136
  "content-type": "application/json"
104
137
  },
105
138
  body
139
+ }, async (response2) => {
140
+ if (!response2.ok) return;
141
+ if (!this.firstCaptureAnnounced) {
142
+ this.firstCaptureAnnounced = true;
143
+ console.error(
144
+ `Sight: first session captured -> ${this.dashboardUrl}/sessions/${encodeURIComponent(turn.sessionExternalId)}`
145
+ );
146
+ }
147
+ if (this.debug) {
148
+ const ack = await readAcknowledgement(response2);
149
+ this.log(`[sight] ingest ok id=${ack.pendingId ?? "?"}`);
150
+ }
106
151
  });
107
152
  const response = await this.retryIfRateLimited(await send(), send);
108
153
  if (response === null) return;
@@ -111,16 +156,6 @@ var IngestClient = class {
111
156
  this.log(`[sight] ingest failed status=${response.status}`);
112
157
  return;
113
158
  }
114
- if (!this.firstCaptureAnnounced) {
115
- this.firstCaptureAnnounced = true;
116
- console.error(
117
- `Sight: first session captured -> ${this.dashboardUrl}/sessions/${encodeURIComponent(turn.sessionExternalId)}`
118
- );
119
- }
120
- if (this.debug) {
121
- const body2 = await response.json();
122
- this.log(`[sight] ingest ok id=${body2.pendingId ?? "?"}`);
123
- }
124
159
  } catch (err) {
125
160
  const msg = err instanceof Error ? err.message : String(err);
126
161
  this.log(`[sight] ingest error: ${msg}`);
@@ -1901,7 +1936,7 @@ function createIntegration(options) {
1901
1936
  call.contextSession = sessionFromContext(e["runtimeContext"]) ?? call.contextSession;
1902
1937
  const model = rec(e["model"]);
1903
1938
  const response = rec(e["response"]);
1904
- const performance = rec(e["performance"]);
1939
+ const performance2 = rec(e["performance"]);
1905
1940
  const content = Array.isArray(e["content"]) ? e["content"] : [];
1906
1941
  const toolNames = [];
1907
1942
  for (const part of content) {
@@ -1927,8 +1962,8 @@ function createIntegration(options) {
1927
1962
  finishReason,
1928
1963
  rawFinishReason: str(e["rawFinishReason"]),
1929
1964
  toolNames,
1930
- latencyMs: ms(performance?.["responseTimeMs"]) ?? (open ? Math.max(0, Date.now() - open.startedAt) : void 0),
1931
- firstTokenMs: ms(performance?.["timeToFirstOutputMs"]),
1965
+ latencyMs: ms(performance2?.["responseTimeMs"]) ?? (open ? Math.max(0, Date.now() - open.startedAt) : void 0),
1966
+ firstTokenMs: ms(performance2?.["timeToFirstOutputMs"]),
1932
1967
  // A stream that failed part way ends its step with this finish
1933
1968
  // reason; the events carry no error message for it.
1934
1969
  error: finishReason === "error" ? 'model call ended with finish reason "error"' : void 0,