@cultured_computer/sight 0.4.3 → 0.5.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/README.md +29 -0
- package/dist/cli.js +148 -0
- package/dist/index.cjs +16 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/schema/sight-record-v1.schema.json +523 -99
package/README.md
CHANGED
|
@@ -82,6 +82,35 @@ the whole thing before creating an account. Both lanes share one project.
|
|
|
82
82
|
The full walkthrough lives at
|
|
83
83
|
[Connect your buzz community](https://sight.cultured.computer/docs/connect-your-room).
|
|
84
84
|
|
|
85
|
+
## Pull your own data out: the CLI, from your terminal
|
|
86
|
+
|
|
87
|
+
The `sight` CLI also carries out data from projects you **own**, with no
|
|
88
|
+
dashboard click-through and no session cookie to juggle. Sign the terminal in
|
|
89
|
+
once against the browser session you already hold, then export any deployment
|
|
90
|
+
you own as RLDS JSONL:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# one-time: sign this terminal in (prints a code, opens your browser to approve)
|
|
94
|
+
npx @cultured_computer/sight auth login
|
|
95
|
+
|
|
96
|
+
# then pull a deployment's full record
|
|
97
|
+
npx @cultured_computer/sight export --project <slug> --deployment <slug> --out data.jsonl
|
|
98
|
+
|
|
99
|
+
# sign out when you're done
|
|
100
|
+
npx @cultured_computer/sight auth logout
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- `auth login` prints a short code and opens your browser to the `/device`
|
|
104
|
+
approval page (RFC 8628 device authorization). You approve as yourself on a
|
|
105
|
+
browser you are already signed into: same identity, same role, same rules as
|
|
106
|
+
your dashboard session. The token is stored at
|
|
107
|
+
`~/.config/sight/credentials.json` (mode `0600`).
|
|
108
|
+
- `export` streams the deployment's sessions and turns as RLDS JSONL, the same
|
|
109
|
+
Tier-2 redacted shape the dashboard produces. It is owner-only: the token is
|
|
110
|
+
your session, so the carry-out gate is exactly the dashboard's. Members read
|
|
111
|
+
in-product; owners carry the dataset out.
|
|
112
|
+
- `--out <file>` writes to a file; omit it to stream to stdout.
|
|
113
|
+
|
|
85
114
|
## What lands automatically
|
|
86
115
|
|
|
87
116
|
- Autocapture is on from `init` for calls made through the OpenAI SDK,
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
|
+
import { exec } from "child_process";
|
|
5
|
+
import { chmodSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
6
|
+
import { homedir } from "os";
|
|
7
|
+
import { dirname, join } from "path";
|
|
4
8
|
var DEFAULT_API = "https://fieldwork-ingest.fly.dev";
|
|
5
9
|
function flag(args, name) {
|
|
6
10
|
const i = args.indexOf(name);
|
|
@@ -13,6 +17,9 @@ function usage() {
|
|
|
13
17
|
"",
|
|
14
18
|
"Usage:",
|
|
15
19
|
" sight connect <relay-url> --invite <code> [--pulse] [--api <base>]",
|
|
20
|
+
" sight auth login [--base <dashboard-url>]",
|
|
21
|
+
" sight auth logout",
|
|
22
|
+
" sight export --project <slug> --deployment <slug> [--out file.jsonl]",
|
|
16
23
|
"",
|
|
17
24
|
" connect attach Sight to a buzz community as a read-only observer.",
|
|
18
25
|
" --invite one single-use invite code, minted by you on",
|
|
@@ -23,6 +30,12 @@ function usage() {
|
|
|
23
30
|
" --pulse opt into the daily readout (off by",
|
|
24
31
|
" default; counts, times, and links only).",
|
|
25
32
|
"",
|
|
33
|
+
" auth login sign this terminal in with your browser session \u2014 a",
|
|
34
|
+
" code prints, you approve on the dashboard, done. The",
|
|
35
|
+
" token lives at ~/.config/sight/credentials.json (0600).",
|
|
36
|
+
" export pull a deployment\u2019s full record (RLDS JSONL) with that",
|
|
37
|
+
" token. Owner role on the project required.",
|
|
38
|
+
"",
|
|
26
39
|
"The SDK half of this package (serving-path capture) is documented at",
|
|
27
40
|
"https://sight.cultured.computer/docs (the two lanes share one project)."
|
|
28
41
|
].join("\n")
|
|
@@ -81,7 +94,142 @@ async function connect(args) {
|
|
|
81
94
|
var [, , command, ...rest] = process.argv;
|
|
82
95
|
if (command === "connect") {
|
|
83
96
|
connect(rest).then((code) => process.exit(code));
|
|
97
|
+
} else if (command === "auth") {
|
|
98
|
+
auth(rest).then((code) => process.exit(code));
|
|
99
|
+
} else if (command === "export") {
|
|
100
|
+
exportRecord(rest).then((code) => process.exit(code));
|
|
84
101
|
} else {
|
|
85
102
|
usage();
|
|
86
103
|
process.exit(command && command !== "--help" && command !== "-h" ? 1 : 0);
|
|
87
104
|
}
|
|
105
|
+
var DEFAULT_DASHBOARD = "https://sight.cultured.computer";
|
|
106
|
+
var CLIENT_ID = "sight-cli";
|
|
107
|
+
function credentialsPath() {
|
|
108
|
+
return join(process.env["XDG_CONFIG_HOME"] ?? join(homedir(), ".config"), "sight", "credentials.json");
|
|
109
|
+
}
|
|
110
|
+
function readCredentials() {
|
|
111
|
+
try {
|
|
112
|
+
return JSON.parse(readFileSync(credentialsPath(), "utf8"));
|
|
113
|
+
} catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function writeCredentials(token, base) {
|
|
118
|
+
const p = credentialsPath();
|
|
119
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
120
|
+
writeFileSync(p, JSON.stringify({ token, base, savedAt: (/* @__PURE__ */ new Date()).toISOString() }, null, 2) + "\n", {
|
|
121
|
+
mode: 384
|
|
122
|
+
});
|
|
123
|
+
chmodSync(p, 384);
|
|
124
|
+
}
|
|
125
|
+
function openBrowser(url) {
|
|
126
|
+
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
127
|
+
exec(`${cmd} "${url}"`);
|
|
128
|
+
}
|
|
129
|
+
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
130
|
+
async function auth(args) {
|
|
131
|
+
const sub = args[0];
|
|
132
|
+
if (sub === "logout") {
|
|
133
|
+
try {
|
|
134
|
+
rmSync(credentialsPath());
|
|
135
|
+
console.log("signed out (the local token is gone; the session it held stays valid until it expires).");
|
|
136
|
+
} catch {
|
|
137
|
+
console.log("nothing to sign out of.");
|
|
138
|
+
}
|
|
139
|
+
return 0;
|
|
140
|
+
}
|
|
141
|
+
if (sub !== "login") {
|
|
142
|
+
console.error("usage: sight auth login [--base <dashboard-url>] \xB7 sight auth logout");
|
|
143
|
+
return 1;
|
|
144
|
+
}
|
|
145
|
+
const base = (flag(args, "--base") ?? process.env["SIGHT_BASE"] ?? DEFAULT_DASHBOARD).replace(/\/+$/, "");
|
|
146
|
+
const codeRes = await fetch(`${base}/api/auth/device/code`, {
|
|
147
|
+
method: "POST",
|
|
148
|
+
headers: { "content-type": "application/json" },
|
|
149
|
+
body: JSON.stringify({ client_id: CLIENT_ID })
|
|
150
|
+
}).catch((err) => ({ __err: err }));
|
|
151
|
+
if (!codeRes || !codeRes.ok) {
|
|
152
|
+
console.error(`could not start the login at ${base} \u2014 is the URL right?`);
|
|
153
|
+
return 1;
|
|
154
|
+
}
|
|
155
|
+
const grant = await codeRes.json();
|
|
156
|
+
const verifyUrl = grant.verification_uri_complete ?? `${grant.verification_uri ?? `${base}/device`}?user_code=${encodeURIComponent(grant.user_code)}`;
|
|
157
|
+
console.log(`
|
|
158
|
+
Open this on any signed-in browser and approve:
|
|
159
|
+
|
|
160
|
+
${verifyUrl}
|
|
161
|
+
`);
|
|
162
|
+
openBrowser(verifyUrl);
|
|
163
|
+
const intervalMs = Math.max(1, grant.interval ?? 3) * 1e3;
|
|
164
|
+
const deadline = Date.now() + (grant.expires_in ?? 300) * 1e3;
|
|
165
|
+
for (; ; ) {
|
|
166
|
+
if (Date.now() > deadline) {
|
|
167
|
+
console.error("the code expired \u2014 run sight auth login again.");
|
|
168
|
+
return 1;
|
|
169
|
+
}
|
|
170
|
+
await sleep(intervalMs);
|
|
171
|
+
const poll = await fetch(`${base}/api/auth/device/token`, {
|
|
172
|
+
method: "POST",
|
|
173
|
+
headers: { "content-type": "application/json" },
|
|
174
|
+
body: JSON.stringify({
|
|
175
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
176
|
+
device_code: grant.device_code,
|
|
177
|
+
client_id: CLIENT_ID
|
|
178
|
+
})
|
|
179
|
+
}).catch(() => null);
|
|
180
|
+
if (!poll) continue;
|
|
181
|
+
if (poll.ok) {
|
|
182
|
+
const body = await poll.json();
|
|
183
|
+
if (!body.access_token) {
|
|
184
|
+
console.error("the server answered without a token \u2014 unexpected; try again.");
|
|
185
|
+
return 1;
|
|
186
|
+
}
|
|
187
|
+
writeCredentials(body.access_token, base);
|
|
188
|
+
console.log(`signed in. token stored at ${credentialsPath()} (0600).`);
|
|
189
|
+
console.log(`try: sight export --project <slug> --deployment <slug> --out corpus.jsonl`);
|
|
190
|
+
return 0;
|
|
191
|
+
}
|
|
192
|
+
const err = await poll.json().catch(() => ({}));
|
|
193
|
+
if (err.error === "access_denied") {
|
|
194
|
+
console.error("denied on the browser side \u2014 nothing was granted.");
|
|
195
|
+
return 1;
|
|
196
|
+
}
|
|
197
|
+
if (err.error === "expired_token") {
|
|
198
|
+
console.error("the code expired \u2014 run sight auth login again.");
|
|
199
|
+
return 1;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async function exportRecord(args) {
|
|
204
|
+
const project = flag(args, "--project");
|
|
205
|
+
const deployment = flag(args, "--deployment");
|
|
206
|
+
const out = flag(args, "--out") ?? null;
|
|
207
|
+
if (!project || !deployment) {
|
|
208
|
+
console.error("usage: sight export --project <slug> --deployment <slug> [--out file.jsonl]");
|
|
209
|
+
return 1;
|
|
210
|
+
}
|
|
211
|
+
const creds = readCredentials();
|
|
212
|
+
if (!creds) {
|
|
213
|
+
console.error("no stored login \u2014 run sight auth login first.");
|
|
214
|
+
return 1;
|
|
215
|
+
}
|
|
216
|
+
const url = `${creds.base}/api/export?project=${encodeURIComponent(project)}&deployment=${encodeURIComponent(deployment)}`;
|
|
217
|
+
const res = await fetch(url, {
|
|
218
|
+
headers: { authorization: `Bearer ${creds.token}` }
|
|
219
|
+
}).catch((err) => ({ __err: err }));
|
|
220
|
+
if (!res.ok) {
|
|
221
|
+
const status = res.status ?? "unreachable";
|
|
222
|
+
console.error(
|
|
223
|
+
`export failed (${status}) \u2014 ${status === 401 || status === 403 ? "the token is expired or the role is not owner on that project; sight auth login refreshes it" : "check the project and deployment slugs"}.`
|
|
224
|
+
);
|
|
225
|
+
return 1;
|
|
226
|
+
}
|
|
227
|
+
const text = await res.text();
|
|
228
|
+
if (out) {
|
|
229
|
+
writeFileSync(out, text);
|
|
230
|
+
console.log(`exported to ${out} (${text.split("\n").filter(Boolean).length} episodes).`);
|
|
231
|
+
} else {
|
|
232
|
+
process.stdout.write(text);
|
|
233
|
+
}
|
|
234
|
+
return 0;
|
|
235
|
+
}
|
package/dist/index.cjs
CHANGED
|
@@ -58,6 +58,19 @@ var IngestClient = class {
|
|
|
58
58
|
this.inFlight--;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Await all in-flight sends (bounded). Called by Probe.shutdown() so
|
|
63
|
+
* short-lived processes (serverless, CLI scripts) can actually exit after
|
|
64
|
+
* it — the documented "in-flight sends finish within 15s" only holds while
|
|
65
|
+
* the process lives. Polling is coarse on purpose: sends report through
|
|
66
|
+
* guardedFetch's counter, never awaited individually.
|
|
67
|
+
*/
|
|
68
|
+
async drainInFlight(timeoutMs = SEND_TIMEOUT_MS) {
|
|
69
|
+
const deadline = Date.now() + timeoutMs;
|
|
70
|
+
while (this.inFlight > 0 && Date.now() < deadline) {
|
|
71
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
61
74
|
constructor(opts) {
|
|
62
75
|
this.apiKey = opts.apiKey;
|
|
63
76
|
this.endpoint = opts.endpoint.replace(/\/$/, "");
|
|
@@ -283,7 +296,7 @@ var IngestClient = class {
|
|
|
283
296
|
if (!this.rateLimitAnnounced) {
|
|
284
297
|
this.rateLimitAnnounced = true;
|
|
285
298
|
console.error(
|
|
286
|
-
"Sight: ingest rate limit (429) \u2014 retrying once per Retry-After; sustained limiting drops captures. See https://
|
|
299
|
+
"Sight: ingest rate limit (429) \u2014 retrying once per Retry-After; sustained limiting drops captures. See https://sight.cultured.computer/docs/sdk-reference#rate-limits"
|
|
287
300
|
);
|
|
288
301
|
} else {
|
|
289
302
|
this.log("[sight] ingest rate limited (429), retrying once");
|
|
@@ -2062,8 +2075,10 @@ var Probe = class {
|
|
|
2062
2075
|
if (state === null) {
|
|
2063
2076
|
return;
|
|
2064
2077
|
}
|
|
2078
|
+
const client = state.client;
|
|
2065
2079
|
detachOtelState();
|
|
2066
2080
|
state = null;
|
|
2081
|
+
await client.drainInFlight();
|
|
2067
2082
|
}
|
|
2068
2083
|
// ── Internal helpers ─────────────────────────────────────────────────────
|
|
2069
2084
|
/** Package-internal: instrumentation adapters read this to build turns. */
|