@cultured_computer/sight 0.3.1 → 0.3.2
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 +62 -6
- package/dist/index.cjs +201 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +294 -18
- package/dist/index.d.ts +294 -18
- package/dist/index.js +201 -43
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var IngestClient = class {
|
|
|
10
10
|
debug;
|
|
11
11
|
dashboardUrl;
|
|
12
12
|
/**
|
|
13
|
-
* First-trace permalink
|
|
13
|
+
* First-trace permalink: the first
|
|
14
14
|
* SUCCESSFUL sendTurn prints one stderr line with a dashboard permalink,
|
|
15
15
|
* then never again for the life of this client (one IngestClient per
|
|
16
16
|
* process — one `init` per process; a restart prints once more, accepted).
|
|
@@ -51,7 +51,7 @@ var IngestClient = class {
|
|
|
51
51
|
const response = await this.retryIfRateLimited(await send(), send);
|
|
52
52
|
if (response === null) return;
|
|
53
53
|
if (!response.ok) {
|
|
54
|
-
this.log(`[
|
|
54
|
+
this.log(`[sight] ingest failed status=${response.status}`);
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
if (!this.firstCaptureAnnounced) {
|
|
@@ -62,16 +62,16 @@ var IngestClient = class {
|
|
|
62
62
|
}
|
|
63
63
|
if (this.debug) {
|
|
64
64
|
const body = await response.json();
|
|
65
|
-
this.log(`[
|
|
65
|
+
this.log(`[sight] ingest ok id=${body.pendingId ?? "?"}`);
|
|
66
66
|
}
|
|
67
67
|
} catch (err) {
|
|
68
68
|
const msg = err instanceof Error ? err.message : String(err);
|
|
69
|
-
this.log(`[
|
|
69
|
+
this.log(`[sight] ingest error: ${msg}`);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* Send a persona-break flag to the ingest API. Fire-and-log, same as sendTurn.
|
|
74
|
-
* Populates the `user_flagged_break` outcome column
|
|
74
|
+
* Populates the `user_flagged_break` outcome column on the dashboard.
|
|
75
75
|
*/
|
|
76
76
|
async sendFlag(deploymentSlug, flag) {
|
|
77
77
|
try {
|
|
@@ -92,15 +92,15 @@ var IngestClient = class {
|
|
|
92
92
|
const response = await this.retryIfRateLimited(await send(), send);
|
|
93
93
|
if (response === null) return;
|
|
94
94
|
if (!response.ok) {
|
|
95
|
-
this.log(`[
|
|
95
|
+
this.log(`[sight] flag ingest failed status=${response.status}`);
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
98
|
if (this.debug) {
|
|
99
|
-
this.log(`[
|
|
99
|
+
this.log(`[sight] flag ingest ok session=${flag.sessionExternalId}`);
|
|
100
100
|
}
|
|
101
101
|
} catch (err) {
|
|
102
102
|
const msg = err instanceof Error ? err.message : String(err);
|
|
103
|
-
this.log(`[
|
|
103
|
+
this.log(`[sight] flag ingest error: ${msg}`);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
@@ -124,20 +124,20 @@ var IngestClient = class {
|
|
|
124
124
|
const response = await this.retryIfRateLimited(await send(), send);
|
|
125
125
|
if (response === null) return;
|
|
126
126
|
if (!response.ok) {
|
|
127
|
-
this.log(`[
|
|
127
|
+
this.log(`[sight] session-end ingest failed status=${response.status}`);
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
130
|
if (this.debug) {
|
|
131
|
-
this.log(`[
|
|
131
|
+
this.log(`[sight] session-end ingest ok session=${end.externalId}`);
|
|
132
132
|
}
|
|
133
133
|
} catch (err) {
|
|
134
134
|
const msg = err instanceof Error ? err.message : String(err);
|
|
135
|
-
this.log(`[
|
|
135
|
+
this.log(`[sight] session-end ingest error: ${msg}`);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* Send an outcome event to the ingest API. Fire-and-log. Populates
|
|
140
|
-
*
|
|
140
|
+
* the outcome-events store.
|
|
141
141
|
*/
|
|
142
142
|
async sendOutcomeEvent(deploymentSlug, event) {
|
|
143
143
|
try {
|
|
@@ -159,17 +159,17 @@ var IngestClient = class {
|
|
|
159
159
|
const response = await this.retryIfRateLimited(await send(), send);
|
|
160
160
|
if (response === null) return;
|
|
161
161
|
if (!response.ok) {
|
|
162
|
-
this.log(`[
|
|
162
|
+
this.log(`[sight] outcome-event ingest failed status=${response.status}`);
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
165
|
if (this.debug) {
|
|
166
166
|
this.log(
|
|
167
|
-
`[
|
|
167
|
+
`[sight] outcome-event ingest ok session=${event.sessionExternalId} kind=${event.kind}`
|
|
168
168
|
);
|
|
169
169
|
}
|
|
170
170
|
} catch (err) {
|
|
171
171
|
const msg = err instanceof Error ? err.message : String(err);
|
|
172
|
-
this.log(`[
|
|
172
|
+
this.log(`[sight] outcome-event ingest error: ${msg}`);
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
/**
|
|
@@ -190,15 +190,45 @@ var IngestClient = class {
|
|
|
190
190
|
const response = await this.retryIfRateLimited(await send(), send);
|
|
191
191
|
if (response === null) return;
|
|
192
192
|
if (!response.ok) {
|
|
193
|
-
this.log(`[
|
|
193
|
+
this.log(`[sight] environment-events ingest failed status=${response.status}`);
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
196
|
if (this.debug) {
|
|
197
|
-
this.log(`[
|
|
197
|
+
this.log(`[sight] environment-events ingest ok events=${batch.events.length}`);
|
|
198
198
|
}
|
|
199
199
|
} catch (err) {
|
|
200
200
|
const msg = err instanceof Error ? err.message : String(err);
|
|
201
|
-
this.log(`[
|
|
201
|
+
this.log(`[sight] environment-events ingest error: ${msg}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Send a span batch to the ingest API. Fire-and-log, same as sendTurn.
|
|
206
|
+
* Spans carry sub-turn structure (llm_call / tool_call / framework_step /
|
|
207
|
+
* custom); the worker resolves each span's session/turn and wires in-batch
|
|
208
|
+
* parent references.
|
|
209
|
+
*/
|
|
210
|
+
async sendSpans(batch) {
|
|
211
|
+
try {
|
|
212
|
+
const send = () => fetch(`${this.endpoint}/v1/spans`, {
|
|
213
|
+
method: "POST",
|
|
214
|
+
headers: {
|
|
215
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
216
|
+
"content-type": "application/json"
|
|
217
|
+
},
|
|
218
|
+
body: JSON.stringify(batch)
|
|
219
|
+
});
|
|
220
|
+
const response = await this.retryIfRateLimited(await send(), send);
|
|
221
|
+
if (response === null) return;
|
|
222
|
+
if (!response.ok) {
|
|
223
|
+
this.log(`[sight] spans ingest failed status=${response.status}`);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (this.debug) {
|
|
227
|
+
this.log(`[sight] spans ingest ok spans=${batch.spans.length}`);
|
|
228
|
+
}
|
|
229
|
+
} catch (err) {
|
|
230
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
231
|
+
this.log(`[sight] spans ingest error: ${msg}`);
|
|
202
232
|
}
|
|
203
233
|
}
|
|
204
234
|
/**
|
|
@@ -219,10 +249,10 @@ var IngestClient = class {
|
|
|
219
249
|
"Sight: ingest rate limit (429) \u2014 retrying once per Retry-After; sustained limiting drops captures. See https://field.cultured.computer/sight/sdk-reference#rate-limits"
|
|
220
250
|
);
|
|
221
251
|
} else {
|
|
222
|
-
this.log("[
|
|
252
|
+
this.log("[sight] ingest rate limited (429), retrying once");
|
|
223
253
|
}
|
|
224
254
|
if (this.pendingRetries >= MAX_PENDING_RETRIES) {
|
|
225
|
-
this.log("[
|
|
255
|
+
this.log("[sight] retry buffer full, dropped");
|
|
226
256
|
return null;
|
|
227
257
|
}
|
|
228
258
|
const raw = response.headers.get("retry-after");
|
|
@@ -333,7 +363,7 @@ var SessionStartSchema = z.object({
|
|
|
333
363
|
*/
|
|
334
364
|
persona: z.string().min(1).optional(),
|
|
335
365
|
/**
|
|
336
|
-
* How the user got into this session
|
|
366
|
+
* How the user got into this session.
|
|
337
367
|
* Retention semantics differ radically between a resume and a fresh
|
|
338
368
|
* notification landing.
|
|
339
369
|
*/
|
|
@@ -350,8 +380,8 @@ var SessionStartSchema = z.object({
|
|
|
350
380
|
*/
|
|
351
381
|
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
352
382
|
/**
|
|
353
|
-
* RLDS episode-level provenance
|
|
354
|
-
*
|
|
383
|
+
* RLDS episode-level provenance. Powers the version behavioral diff
|
|
384
|
+
* on the dashboard. All optional.
|
|
355
385
|
* agentId — model/policy version
|
|
356
386
|
* experimentId — A/B arm or feature flag
|
|
357
387
|
* environmentConfigHash — SHA of prompt/config file(s)
|
|
@@ -364,7 +394,9 @@ var SessionStartSchema = z.object({
|
|
|
364
394
|
});
|
|
365
395
|
z.object({
|
|
366
396
|
externalId: z.string().min(1),
|
|
367
|
-
endedReason: z.enum(["natural", "user_closed", "timeout", "agent_error", "user_flagged", "crashed"]).optional()
|
|
397
|
+
endedReason: z.enum(["natural", "user_closed", "timeout", "agent_error", "user_flagged", "crashed"]).optional(),
|
|
398
|
+
outcome: z.string().min(1).max(64).optional(),
|
|
399
|
+
outcomeDetail: z.record(z.string(), z.unknown()).optional()
|
|
368
400
|
});
|
|
369
401
|
var FlagPersonaBreakSchema = z.object({
|
|
370
402
|
sessionExternalId: z.string().min(1),
|
|
@@ -901,7 +933,7 @@ function registerAllInstrumentations(state2, captureFn) {
|
|
|
901
933
|
if (!state2.config.debug) return;
|
|
902
934
|
for (const result of results) {
|
|
903
935
|
if (result.status === "rejected") {
|
|
904
|
-
console.error(`[
|
|
936
|
+
console.error(`[sight] adapter register rejected: ${result.reason}`);
|
|
905
937
|
}
|
|
906
938
|
}
|
|
907
939
|
});
|
|
@@ -941,6 +973,13 @@ function matchSignaturePhrases(text, compiled) {
|
|
|
941
973
|
}
|
|
942
974
|
return matches;
|
|
943
975
|
}
|
|
976
|
+
|
|
977
|
+
// ../shared/src/effectiveness-gap.ts
|
|
978
|
+
new Set(
|
|
979
|
+
"the a an to of and or is are was were do does did how what where when who why which can could should would may might i you your my me it its this that these those in on for with at by from as be been being am not no yes okay ok um uh hi hello please thanks thank".split(" ")
|
|
980
|
+
);
|
|
981
|
+
|
|
982
|
+
// ../shared/src/index.ts
|
|
944
983
|
var REACTION_REGISTERS = ["heavy", "comic", "edge"];
|
|
945
984
|
var InterpretiveRecordSchema = z.object({
|
|
946
985
|
// Open vocabulary: any string tag. Seeds live in GENERAL_SITUATION_TAGS /
|
|
@@ -1070,6 +1109,15 @@ z.object({
|
|
|
1070
1109
|
*/
|
|
1071
1110
|
externalUserId: z.string().min(1).optional(),
|
|
1072
1111
|
turnIndex: z.number().int().nonnegative(),
|
|
1112
|
+
/**
|
|
1113
|
+
* Caller-asserted turn timestamp (ISO). OPTIONAL and honored by the
|
|
1114
|
+
* worker: when present it becomes turns.started_at; when absent the
|
|
1115
|
+
* insert defaults to processing time. This is PROVENANCE, not
|
|
1116
|
+
* verification — intended for historical imports (ZVA telemetry, log
|
|
1117
|
+
* backfills, the datadump importer); live SDK traffic leaves it unset
|
|
1118
|
+
* (arrival time is the honest clock there).
|
|
1119
|
+
*/
|
|
1120
|
+
startedAt: z.string().datetime().optional(),
|
|
1073
1121
|
/**
|
|
1074
1122
|
* Persona slug active for this turn. Customer-supplied (from SDK persona
|
|
1075
1123
|
* resolution: turn override / session / init default). Optional; deployments
|
|
@@ -1214,6 +1262,61 @@ var EnvironmentEventsBatchSchema = z.object({
|
|
|
1214
1262
|
events: z.array(EnvironmentEventInputSchema).min(1).max(100),
|
|
1215
1263
|
alignment: AlignmentProvenanceSchema
|
|
1216
1264
|
});
|
|
1265
|
+
var SPAN_TYPES = ["llm_call", "tool_call", "framework_step", "custom"];
|
|
1266
|
+
var SpanInputSchema = z.object({
|
|
1267
|
+
deploymentSlug: z.string().min(1),
|
|
1268
|
+
sessionExternalId: z.string().min(1),
|
|
1269
|
+
/**
|
|
1270
|
+
* Turn the span belongs to. Optional: when omitted the worker resolves the
|
|
1271
|
+
* session's latest turn at/under the span's startedAt (falling back to the
|
|
1272
|
+
* session's most recent turn when startedAt is also absent — the outcome
|
|
1273
|
+
* events' rule). A span whose turn cannot be resolved is SKIPPED by the
|
|
1274
|
+
* worker (logged, batch still processed): spans never land unattributed.
|
|
1275
|
+
*/
|
|
1276
|
+
turnIndex: z.number().int().nonnegative().optional(),
|
|
1277
|
+
spanType: z.enum(SPAN_TYPES),
|
|
1278
|
+
/** Human/otel-style span name (tool name, model call label). */
|
|
1279
|
+
name: z.string().optional(),
|
|
1280
|
+
/**
|
|
1281
|
+
* Caller-asserted span start (ISO). OPTIONAL and honored like
|
|
1282
|
+
* TurnInput.startedAt: provenance, not verification — when absent the
|
|
1283
|
+
* worker stamps processing time.
|
|
1284
|
+
*/
|
|
1285
|
+
startedAt: z.string().datetime().optional(),
|
|
1286
|
+
endedAt: z.string().datetime().optional(),
|
|
1287
|
+
durationMs: z.number().int().nonnegative().optional(),
|
|
1288
|
+
model: z.string().optional(),
|
|
1289
|
+
provider: z.string().optional(),
|
|
1290
|
+
tokensInput: z.number().int().nonnegative().optional(),
|
|
1291
|
+
tokensOutput: z.number().int().nonnegative().optional(),
|
|
1292
|
+
costUsd: z.number().nonnegative().optional(),
|
|
1293
|
+
error: z.string().optional(),
|
|
1294
|
+
/**
|
|
1295
|
+
* OpenInference / OpenTelemetry gen_ai.*-style attributes. String values
|
|
1296
|
+
* are Presidio-scrubbed by the worker before storage (see the PII rule
|
|
1297
|
+
* above). Capped at 16k JSON chars per span.
|
|
1298
|
+
*/
|
|
1299
|
+
attributes: z.record(z.string(), z.unknown()).optional().refine((v) => v === void 0 || JSON.stringify(v).length <= 16e3, {
|
|
1300
|
+
message: "attributes exceed 16k JSON chars \u2014 spans are telemetry, not blob storage"
|
|
1301
|
+
}),
|
|
1302
|
+
/**
|
|
1303
|
+
* Caller-local span id, unique within the batch. Exists only so sibling
|
|
1304
|
+
* spans can name this span as their parentSpanId; never stored (the DB
|
|
1305
|
+
* assigns the real uuid).
|
|
1306
|
+
*/
|
|
1307
|
+
spanId: z.string().min(1).optional(),
|
|
1308
|
+
/**
|
|
1309
|
+
* Caller-local reference to another span's `spanId` IN THE SAME BATCH (NOT
|
|
1310
|
+
* a database uuid). The worker wires spans.parent_span_id when the parent
|
|
1311
|
+
* resolves within the batch, stores null otherwise.
|
|
1312
|
+
*/
|
|
1313
|
+
parentSpanId: z.string().min(1).optional()
|
|
1314
|
+
});
|
|
1315
|
+
var SpansBatchSchema = z.object({
|
|
1316
|
+
/** Spans are self-addressed: a batch may span sessions/deployments. */
|
|
1317
|
+
spans: z.array(SpanInputSchema).min(1).max(50),
|
|
1318
|
+
alignment: AlignmentProvenanceSchema
|
|
1319
|
+
});
|
|
1217
1320
|
var DEFINITION_SLUG = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
1218
1321
|
var DEFINITION_VALUE = z.string().trim().min(1).max(64);
|
|
1219
1322
|
z.object({
|
|
@@ -1274,6 +1377,10 @@ var DEFAULT_ENVIRONMENT_ALIGNMENT = {
|
|
|
1274
1377
|
clock_source: "sdk",
|
|
1275
1378
|
rule_version: "v1"
|
|
1276
1379
|
};
|
|
1380
|
+
var DEFAULT_SPAN_ALIGNMENT = {
|
|
1381
|
+
clock_source: "sdk",
|
|
1382
|
+
rule_version: "v1"
|
|
1383
|
+
};
|
|
1277
1384
|
var state = null;
|
|
1278
1385
|
var Probe = class {
|
|
1279
1386
|
/**
|
|
@@ -1282,7 +1389,7 @@ var Probe = class {
|
|
|
1282
1389
|
*/
|
|
1283
1390
|
static init(config) {
|
|
1284
1391
|
if (state !== null) {
|
|
1285
|
-
console.warn("[
|
|
1392
|
+
console.warn("[sight] already initialized; call shutdown() first");
|
|
1286
1393
|
return;
|
|
1287
1394
|
}
|
|
1288
1395
|
const validated = ProbeConfigSchema.parse(config);
|
|
@@ -1320,7 +1427,7 @@ var Probe = class {
|
|
|
1320
1427
|
*/
|
|
1321
1428
|
static async withSession(sessionId, fn) {
|
|
1322
1429
|
if (state === null) {
|
|
1323
|
-
console.warn("[
|
|
1430
|
+
console.warn("[sight] withSession called before init");
|
|
1324
1431
|
return fn();
|
|
1325
1432
|
}
|
|
1326
1433
|
return withSession(sessionId, fn);
|
|
@@ -1332,7 +1439,7 @@ var Probe = class {
|
|
|
1332
1439
|
*/
|
|
1333
1440
|
static identifyPersona(persona) {
|
|
1334
1441
|
if (state === null) {
|
|
1335
|
-
console.warn("[
|
|
1442
|
+
console.warn("[sight] identifyPersona called before init");
|
|
1336
1443
|
return;
|
|
1337
1444
|
}
|
|
1338
1445
|
state.persona = persona;
|
|
@@ -1355,7 +1462,7 @@ var Probe = class {
|
|
|
1355
1462
|
*/
|
|
1356
1463
|
static startSession(input) {
|
|
1357
1464
|
if (state === null) {
|
|
1358
|
-
console.warn("[
|
|
1465
|
+
console.warn("[sight] startSession called before init");
|
|
1359
1466
|
return;
|
|
1360
1467
|
}
|
|
1361
1468
|
const validated = SessionStartSchema.parse(input);
|
|
@@ -1426,7 +1533,7 @@ var Probe = class {
|
|
|
1426
1533
|
* for the diff table axis (a card keyed by a3f9c2… is unreadable).
|
|
1427
1534
|
*
|
|
1428
1535
|
* Ships as a helper because inconsistent hashing across restarts breaks
|
|
1429
|
-
*
|
|
1536
|
+
* The version behavioral diff — every customer would
|
|
1430
1537
|
* hash their own way and version-diff would become noise.
|
|
1431
1538
|
*
|
|
1432
1539
|
* The same hashing (src/hash.ts) backs the OTel processor's automatic
|
|
@@ -1458,7 +1565,18 @@ var Probe = class {
|
|
|
1458
1565
|
if (state === null) return;
|
|
1459
1566
|
const externalIdStr = typeof externalId === "string" ? externalId : externalId.externalId;
|
|
1460
1567
|
const endedReason = typeof externalId === "string" ? void 0 : externalId.endedReason;
|
|
1461
|
-
|
|
1568
|
+
const declared = typeof externalId === "string" ? void 0 : externalId.outcome;
|
|
1569
|
+
if (declared) {
|
|
1570
|
+
await this.emitOutcomeEvent({
|
|
1571
|
+
sessionExternalId: externalIdStr,
|
|
1572
|
+
kind: declared,
|
|
1573
|
+
detail: {
|
|
1574
|
+
declaredAt: "endSession",
|
|
1575
|
+
...typeof externalId === "object" && externalId.outcomeDetail ? externalId.outcomeDetail : {}
|
|
1576
|
+
}
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
if (!declared && state.outcomeHook) {
|
|
1462
1580
|
try {
|
|
1463
1581
|
const result = await state.outcomeHook.resolve(externalIdStr);
|
|
1464
1582
|
if (result && state !== null) {
|
|
@@ -1474,7 +1592,7 @@ var Probe = class {
|
|
|
1474
1592
|
}
|
|
1475
1593
|
} catch (err) {
|
|
1476
1594
|
console.warn(
|
|
1477
|
-
"[
|
|
1595
|
+
"[sight] outcome hook resolve failed:",
|
|
1478
1596
|
err instanceof Error ? err.message : err
|
|
1479
1597
|
);
|
|
1480
1598
|
}
|
|
@@ -1482,12 +1600,12 @@ var Probe = class {
|
|
|
1482
1600
|
if (state === null) return;
|
|
1483
1601
|
if (endedReason) {
|
|
1484
1602
|
await state.client.sendSessionEnd(state.config.deployment, { externalId: externalIdStr, endedReason }).catch((err) => {
|
|
1485
|
-
console.warn("[
|
|
1603
|
+
console.warn("[sight] sendSessionEnd failed:", err instanceof Error ? err.message : err);
|
|
1486
1604
|
});
|
|
1487
1605
|
}
|
|
1488
1606
|
state.sessions.delete(externalIdStr);
|
|
1489
1607
|
}
|
|
1490
|
-
// ── User-side helpers
|
|
1608
|
+
// ── User-side helpers ──────────────────────────────────────────────────
|
|
1491
1609
|
// These accumulate user-side signals during a turn; captureTurn folds the
|
|
1492
1610
|
// accumulated state into TurnInput.userInput / userOutcome before send.
|
|
1493
1611
|
// Signals that arrive before any session entry exists (typing starts
|
|
@@ -1580,7 +1698,7 @@ var Probe = class {
|
|
|
1580
1698
|
*/
|
|
1581
1699
|
static wireOutcomeHook(hook) {
|
|
1582
1700
|
if (state === null) {
|
|
1583
|
-
console.warn("[
|
|
1701
|
+
console.warn("[sight] wireOutcomeHook called before init");
|
|
1584
1702
|
return;
|
|
1585
1703
|
}
|
|
1586
1704
|
state.outcomeHook = hook;
|
|
@@ -1710,7 +1828,7 @@ var Probe = class {
|
|
|
1710
1828
|
propensity: validPropensity,
|
|
1711
1829
|
// Forward RLDS provenance from the local session entry (populated
|
|
1712
1830
|
// by Probe.startSession). Worker persists at first-turn session
|
|
1713
|
-
// create; nulls stay null.
|
|
1831
|
+
// create; nulls stay null.
|
|
1714
1832
|
agentId: session.agentId ?? void 0,
|
|
1715
1833
|
experimentId: session.experimentId ?? void 0,
|
|
1716
1834
|
environmentConfigHash: session.environmentConfigHash ?? void 0,
|
|
@@ -1719,7 +1837,7 @@ var Probe = class {
|
|
|
1719
1837
|
}
|
|
1720
1838
|
/**
|
|
1721
1839
|
* Emit a custom outcome event on a session. Populates probe_outcome_events
|
|
1722
|
-
* with the customer-supplied `kind` string
|
|
1840
|
+
* with the customer-supplied `kind` string. Use for
|
|
1723
1841
|
* customer-defined kinds like "purchase_complete", "handoff_to_human",
|
|
1724
1842
|
* "character_break_severe". Universal seed kinds (break, escalation,
|
|
1725
1843
|
* resolution, thumbs_*, rating_*) are also emitted by worker-side
|
|
@@ -1728,14 +1846,14 @@ var Probe = class {
|
|
|
1728
1846
|
*/
|
|
1729
1847
|
static async emitOutcomeEvent(input) {
|
|
1730
1848
|
if (state === null) {
|
|
1731
|
-
console.warn("[
|
|
1849
|
+
console.warn("[sight] emitOutcomeEvent called before init");
|
|
1732
1850
|
return;
|
|
1733
1851
|
}
|
|
1734
1852
|
const validated = OutcomeEventEmitSchema.parse(input);
|
|
1735
1853
|
await state.client.sendOutcomeEvent(state.config.deployment, validated);
|
|
1736
1854
|
}
|
|
1737
1855
|
/**
|
|
1738
|
-
* Capture one environment event against a session
|
|
1856
|
+
* Capture one environment event against a session. The
|
|
1739
1857
|
* envelope is generalized: `source_type` and `event` are free strings whose
|
|
1740
1858
|
* meaning is defined per deployment — the instrument stores the event and
|
|
1741
1859
|
* attaches it to the session's record by time (the next turn's state
|
|
@@ -1749,7 +1867,7 @@ var Probe = class {
|
|
|
1749
1867
|
*/
|
|
1750
1868
|
static async captureEnvironmentEvent(event, alignment) {
|
|
1751
1869
|
if (state === null) {
|
|
1752
|
-
console.warn("[
|
|
1870
|
+
console.warn("[sight] captureEnvironmentEvent called before init");
|
|
1753
1871
|
return;
|
|
1754
1872
|
}
|
|
1755
1873
|
const validated = EnvironmentEventInputSchema.parse(event);
|
|
@@ -1765,23 +1883,63 @@ var Probe = class {
|
|
|
1765
1883
|
*/
|
|
1766
1884
|
static async captureEnvironmentEvents(events, alignment) {
|
|
1767
1885
|
if (state === null) {
|
|
1768
|
-
console.warn("[
|
|
1886
|
+
console.warn("[sight] captureEnvironmentEvents called before init");
|
|
1769
1887
|
return;
|
|
1770
1888
|
}
|
|
1771
1889
|
const batch = EnvironmentEventsBatchSchema.parse({ events, alignment });
|
|
1772
1890
|
await state.client.sendEnvironmentEvents(batch);
|
|
1773
1891
|
}
|
|
1892
|
+
/**
|
|
1893
|
+
* Capture one sub-turn span against a session: one LLM call, one tool
|
|
1894
|
+
* call, one framework step, or a custom unit inside a turn. The span lands
|
|
1895
|
+
* on the turn named by `turnIndex`, or — when omitted — on the session's
|
|
1896
|
+
* latest turn at/under the span's `startedAt` (most recent turn when
|
|
1897
|
+
* `startedAt` is also absent). A span whose turn cannot be resolved is
|
|
1898
|
+
* dropped server-side; spans never land unattributed. Fire-and-log, like
|
|
1899
|
+
* captureTurn: errors are debug-logged, never thrown.
|
|
1900
|
+
*
|
|
1901
|
+
* `attributes` are metadata only (tool names, argument shapes) — never
|
|
1902
|
+
* free-text conversation content. Alignment defaults to the SDK's own
|
|
1903
|
+
* clock claim; deployments with a stricter clock contract (or batches, or
|
|
1904
|
+
* parent references between spans) should call captureSpans.
|
|
1905
|
+
*/
|
|
1906
|
+
static async captureSpan(span, alignment) {
|
|
1907
|
+
if (state === null) {
|
|
1908
|
+
console.warn("[sight] captureSpan called before init");
|
|
1909
|
+
return;
|
|
1910
|
+
}
|
|
1911
|
+
const validated = SpanInputSchema.parse(span);
|
|
1912
|
+
const align = alignment ? AlignmentProvenanceSchema.parse(alignment) : DEFAULT_SPAN_ALIGNMENT;
|
|
1913
|
+
await state.client.sendSpans({ spans: [validated], alignment: align });
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1916
|
+
* Capture a batch of spans with explicit alignment provenance
|
|
1917
|
+
* (clock_source, skew_bound_ms, rule_version). Batches are capped at 50
|
|
1918
|
+
* spans and may span sessions — every span is self-addressed. Parent
|
|
1919
|
+
* structure rides the batch: a span's `parentSpanId` names another span's
|
|
1920
|
+
* caller-local `spanId` within the same batch and is wired server-side
|
|
1921
|
+
* (unresolvable references land null). Same fire-and-log discipline as the
|
|
1922
|
+
* single-span capture above.
|
|
1923
|
+
*/
|
|
1924
|
+
static async captureSpans(spans, alignment) {
|
|
1925
|
+
if (state === null) {
|
|
1926
|
+
console.warn("[sight] captureSpans called before init");
|
|
1927
|
+
return;
|
|
1928
|
+
}
|
|
1929
|
+
const batch = SpansBatchSchema.parse({ spans, alignment });
|
|
1930
|
+
await state.client.sendSpans(batch);
|
|
1931
|
+
}
|
|
1774
1932
|
/**
|
|
1775
1933
|
* Flag a persona break for a session. Wire this to the customer's in-product
|
|
1776
1934
|
* "that didn't sound like you" UX. Populates the `user_flagged_break`
|
|
1777
|
-
* outcome column
|
|
1935
|
+
* outcome column on the dashboard.
|
|
1778
1936
|
*
|
|
1779
1937
|
* If `turnIndex` is omitted, the flag attaches to the session's most
|
|
1780
1938
|
* recent turn.
|
|
1781
1939
|
*/
|
|
1782
1940
|
static async flagPersonaBreak(input) {
|
|
1783
1941
|
if (state === null) {
|
|
1784
|
-
console.warn("[
|
|
1942
|
+
console.warn("[sight] flagPersonaBreak called before init");
|
|
1785
1943
|
return;
|
|
1786
1944
|
}
|
|
1787
1945
|
const validated = FlagPersonaBreakSchema.parse(input);
|