@cultured_computer/sight 0.6.0 → 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 +482 -88
- package/dist/cli.js +242 -27
- package/dist/index.cjs +1470 -224
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1034 -112
- package/dist/index.d.ts +1034 -112
- package/dist/index.js +1459 -226
- package/dist/index.js.map +1 -1
- package/package.json +17 -14
package/dist/index.d.ts
CHANGED
|
@@ -196,7 +196,49 @@ declare const EnvironmentEventsBatchSchema: z.ZodObject<{
|
|
|
196
196
|
};
|
|
197
197
|
}>;
|
|
198
198
|
type EnvironmentEventsBatch = z.infer<typeof EnvironmentEventsBatchSchema>;
|
|
199
|
-
declare const
|
|
199
|
+
declare const SPAN_TYPES: readonly ["agent_call", "llm_call", "tool_call", "framework_step", "custom"];
|
|
200
|
+
type SpanType = (typeof SPAN_TYPES)[number];
|
|
201
|
+
declare const SPAN_STATUSES: readonly ["unset", "ok", "error"];
|
|
202
|
+
type SpanStatus = (typeof SPAN_STATUSES)[number];
|
|
203
|
+
declare const SPAN_V2_STATUSES: readonly ["ok", "error"];
|
|
204
|
+
declare const SPAN_PAYLOAD_STATES: readonly ["captured", "empty", "not_captured", "redacted", "unavailable"];
|
|
205
|
+
type SpanPayloadState = (typeof SPAN_PAYLOAD_STATES)[number];
|
|
206
|
+
interface SpanPayload {
|
|
207
|
+
state: SpanPayloadState;
|
|
208
|
+
value: unknown;
|
|
209
|
+
}
|
|
210
|
+
declare const SPAN_INTERVAL_KINDS: readonly ["active", "waiting", "retry", "error"];
|
|
211
|
+
type SpanIntervalKind = (typeof SPAN_INTERVAL_KINDS)[number];
|
|
212
|
+
interface SpanInterval {
|
|
213
|
+
kind: SpanIntervalKind;
|
|
214
|
+
startedAt: string;
|
|
215
|
+
endedAt: string;
|
|
216
|
+
}
|
|
217
|
+
declare const SpanIntervalSchema: z.ZodEffects<z.ZodObject<{
|
|
218
|
+
kind: z.ZodEnum<["active", "waiting", "retry", "error"]>;
|
|
219
|
+
startedAt: z.ZodString;
|
|
220
|
+
endedAt: z.ZodString;
|
|
221
|
+
}, "strip", z.ZodTypeAny, {
|
|
222
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
223
|
+
startedAt: string;
|
|
224
|
+
endedAt: string;
|
|
225
|
+
}, {
|
|
226
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
227
|
+
startedAt: string;
|
|
228
|
+
endedAt: string;
|
|
229
|
+
}>, {
|
|
230
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
231
|
+
startedAt: string;
|
|
232
|
+
endedAt: string;
|
|
233
|
+
}, {
|
|
234
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
235
|
+
startedAt: string;
|
|
236
|
+
endedAt: string;
|
|
237
|
+
}>;
|
|
238
|
+
declare const SpanPayloadSchema: z.ZodType<SpanPayload>;
|
|
239
|
+
/** Legacy span wire shape. Kept as an explicit compatibility lane while SDK
|
|
240
|
+
* callers migrate to the versioned v2 telemetry contract. */
|
|
241
|
+
declare const SpanInputV1Schema: z.ZodObject<{
|
|
200
242
|
deploymentSlug: z.ZodString;
|
|
201
243
|
sessionExternalId: z.ZodString;
|
|
202
244
|
/**
|
|
@@ -207,7 +249,9 @@ declare const SpanInputSchema: z.ZodObject<{
|
|
|
207
249
|
* worker (logged, batch still processed): spans never land unattributed.
|
|
208
250
|
*/
|
|
209
251
|
turnIndex: z.ZodOptional<z.ZodNumber>;
|
|
210
|
-
spanType: z.ZodEnum<["llm_call", "tool_call", "framework_step", "custom"]>;
|
|
252
|
+
spanType: z.ZodEnum<["agent_call", "llm_call", "tool_call", "framework_step", "custom"]>;
|
|
253
|
+
} & {
|
|
254
|
+
contractVersion: z.ZodOptional<z.ZodLiteral<1>>;
|
|
211
255
|
/** Human/otel-style span name (tool name, model call label). */
|
|
212
256
|
name: z.ZodOptional<z.ZodString>;
|
|
213
257
|
/**
|
|
@@ -226,7 +270,7 @@ declare const SpanInputSchema: z.ZodObject<{
|
|
|
226
270
|
error: z.ZodOptional<z.ZodString>;
|
|
227
271
|
/**
|
|
228
272
|
* OpenInference / OpenTelemetry gen_ai.*-style attributes. String values
|
|
229
|
-
* are
|
|
273
|
+
* are scrubbed of personal data by the worker before storage (see the PII rule
|
|
230
274
|
* above). Capped at 16k JSON chars per span.
|
|
231
275
|
*/
|
|
232
276
|
attributes: z.ZodEffects<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>, Record<string, unknown> | undefined, Record<string, unknown> | undefined>;
|
|
@@ -245,44 +289,462 @@ declare const SpanInputSchema: z.ZodObject<{
|
|
|
245
289
|
}, "strip", z.ZodTypeAny, {
|
|
246
290
|
deploymentSlug: string;
|
|
247
291
|
sessionExternalId: string;
|
|
248
|
-
spanType: "tool_call" | "custom" | "llm_call" | "framework_step";
|
|
292
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
293
|
+
error?: string | undefined;
|
|
249
294
|
name?: string | undefined;
|
|
250
295
|
turnIndex?: number | undefined;
|
|
251
296
|
startedAt?: string | undefined;
|
|
252
297
|
endedAt?: string | undefined;
|
|
298
|
+
contractVersion?: 1 | undefined;
|
|
253
299
|
durationMs?: number | undefined;
|
|
254
300
|
model?: string | undefined;
|
|
255
301
|
provider?: string | undefined;
|
|
256
302
|
tokensInput?: number | undefined;
|
|
257
303
|
tokensOutput?: number | undefined;
|
|
258
304
|
costUsd?: number | undefined;
|
|
305
|
+
attributes?: Record<string, unknown> | undefined;
|
|
306
|
+
spanId?: string | undefined;
|
|
307
|
+
parentSpanId?: string | undefined;
|
|
308
|
+
}, {
|
|
309
|
+
deploymentSlug: string;
|
|
310
|
+
sessionExternalId: string;
|
|
311
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
259
312
|
error?: string | undefined;
|
|
313
|
+
name?: string | undefined;
|
|
314
|
+
turnIndex?: number | undefined;
|
|
315
|
+
startedAt?: string | undefined;
|
|
316
|
+
endedAt?: string | undefined;
|
|
317
|
+
contractVersion?: 1 | undefined;
|
|
318
|
+
durationMs?: number | undefined;
|
|
319
|
+
model?: string | undefined;
|
|
320
|
+
provider?: string | undefined;
|
|
321
|
+
tokensInput?: number | undefined;
|
|
322
|
+
tokensOutput?: number | undefined;
|
|
323
|
+
costUsd?: number | undefined;
|
|
260
324
|
attributes?: Record<string, unknown> | undefined;
|
|
261
325
|
spanId?: string | undefined;
|
|
262
326
|
parentSpanId?: string | undefined;
|
|
327
|
+
}>;
|
|
328
|
+
/** First-class span telemetry. Every operational key exists on every agent,
|
|
329
|
+
* tool and model span; null means unknown rather than a fabricated zero. */
|
|
330
|
+
declare const SpanInputV2Schema: z.ZodEffects<z.ZodObject<{
|
|
331
|
+
deploymentSlug: z.ZodString;
|
|
332
|
+
sessionExternalId: z.ZodString;
|
|
333
|
+
/**
|
|
334
|
+
* Turn the span belongs to. Optional: when omitted the worker resolves the
|
|
335
|
+
* session's latest turn at/under the span's startedAt (falling back to the
|
|
336
|
+
* session's most recent turn when startedAt is also absent — the outcome
|
|
337
|
+
* events' rule). A span whose turn cannot be resolved is SKIPPED by the
|
|
338
|
+
* worker (logged, batch still processed): spans never land unattributed.
|
|
339
|
+
*/
|
|
340
|
+
turnIndex: z.ZodOptional<z.ZodNumber>;
|
|
341
|
+
spanType: z.ZodEnum<["agent_call", "llm_call", "tool_call", "framework_step", "custom"]>;
|
|
342
|
+
} & {
|
|
343
|
+
contractVersion: z.ZodLiteral<2>;
|
|
344
|
+
/** Stable within a deployment/session across batches and retries. */
|
|
345
|
+
spanId: z.ZodString;
|
|
346
|
+
parentSpanId: z.ZodNullable<z.ZodString>;
|
|
347
|
+
name: z.ZodString;
|
|
348
|
+
status: z.ZodEnum<["ok", "error"]>;
|
|
349
|
+
startedAt: z.ZodString;
|
|
350
|
+
endedAt: z.ZodNullable<z.ZodString>;
|
|
351
|
+
durationMs: z.ZodNullable<z.ZodNumber>;
|
|
352
|
+
model: z.ZodNullable<z.ZodString>;
|
|
353
|
+
provider: z.ZodNullable<z.ZodString>;
|
|
354
|
+
tokensInput: z.ZodNullable<z.ZodNumber>;
|
|
355
|
+
tokensOutput: z.ZodNullable<z.ZodNumber>;
|
|
356
|
+
costUsd: z.ZodNullable<z.ZodNumber>;
|
|
357
|
+
error: z.ZodNullable<z.ZodString>;
|
|
358
|
+
input: z.ZodType<SpanPayload, z.ZodTypeDef, SpanPayload>;
|
|
359
|
+
output: z.ZodType<SpanPayload, z.ZodTypeDef, SpanPayload>;
|
|
360
|
+
/** Optional first-class internal timing. An omitted list means the source
|
|
361
|
+
* did not capture interval telemetry; readers must not infer segments. */
|
|
362
|
+
intervals: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
363
|
+
kind: z.ZodEnum<["active", "waiting", "retry", "error"]>;
|
|
364
|
+
startedAt: z.ZodString;
|
|
365
|
+
endedAt: z.ZodString;
|
|
366
|
+
}, "strip", z.ZodTypeAny, {
|
|
367
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
368
|
+
startedAt: string;
|
|
369
|
+
endedAt: string;
|
|
370
|
+
}, {
|
|
371
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
372
|
+
startedAt: string;
|
|
373
|
+
endedAt: string;
|
|
374
|
+
}>, {
|
|
375
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
376
|
+
startedAt: string;
|
|
377
|
+
endedAt: string;
|
|
378
|
+
}, {
|
|
379
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
380
|
+
startedAt: string;
|
|
381
|
+
endedAt: string;
|
|
382
|
+
}>, "many">>;
|
|
383
|
+
attributes: z.ZodEffects<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>, Record<string, unknown> | null, Record<string, unknown> | null>;
|
|
384
|
+
}, "strip", z.ZodTypeAny, {
|
|
385
|
+
error: string | null;
|
|
386
|
+
status: "ok" | "error";
|
|
387
|
+
name: string;
|
|
388
|
+
deploymentSlug: string;
|
|
389
|
+
sessionExternalId: string;
|
|
390
|
+
startedAt: string;
|
|
391
|
+
endedAt: string | null;
|
|
392
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
393
|
+
contractVersion: 2;
|
|
394
|
+
durationMs: number | null;
|
|
395
|
+
model: string | null;
|
|
396
|
+
provider: string | null;
|
|
397
|
+
tokensInput: number | null;
|
|
398
|
+
tokensOutput: number | null;
|
|
399
|
+
costUsd: number | null;
|
|
400
|
+
attributes: Record<string, unknown> | null;
|
|
401
|
+
spanId: string;
|
|
402
|
+
parentSpanId: string | null;
|
|
403
|
+
input: SpanPayload;
|
|
404
|
+
output: SpanPayload;
|
|
405
|
+
turnIndex?: number | undefined;
|
|
406
|
+
intervals?: {
|
|
407
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
408
|
+
startedAt: string;
|
|
409
|
+
endedAt: string;
|
|
410
|
+
}[] | undefined;
|
|
411
|
+
}, {
|
|
412
|
+
error: string | null;
|
|
413
|
+
status: "ok" | "error";
|
|
414
|
+
name: string;
|
|
415
|
+
deploymentSlug: string;
|
|
416
|
+
sessionExternalId: string;
|
|
417
|
+
startedAt: string;
|
|
418
|
+
endedAt: string | null;
|
|
419
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
420
|
+
contractVersion: 2;
|
|
421
|
+
durationMs: number | null;
|
|
422
|
+
model: string | null;
|
|
423
|
+
provider: string | null;
|
|
424
|
+
tokensInput: number | null;
|
|
425
|
+
tokensOutput: number | null;
|
|
426
|
+
costUsd: number | null;
|
|
427
|
+
attributes: Record<string, unknown> | null;
|
|
428
|
+
spanId: string;
|
|
429
|
+
parentSpanId: string | null;
|
|
430
|
+
input: SpanPayload;
|
|
431
|
+
output: SpanPayload;
|
|
432
|
+
turnIndex?: number | undefined;
|
|
433
|
+
intervals?: {
|
|
434
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
435
|
+
startedAt: string;
|
|
436
|
+
endedAt: string;
|
|
437
|
+
}[] | undefined;
|
|
438
|
+
}>, {
|
|
439
|
+
error: string | null;
|
|
440
|
+
status: "ok" | "error";
|
|
441
|
+
name: string;
|
|
442
|
+
deploymentSlug: string;
|
|
443
|
+
sessionExternalId: string;
|
|
444
|
+
startedAt: string;
|
|
445
|
+
endedAt: string | null;
|
|
446
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
447
|
+
contractVersion: 2;
|
|
448
|
+
durationMs: number | null;
|
|
449
|
+
model: string | null;
|
|
450
|
+
provider: string | null;
|
|
451
|
+
tokensInput: number | null;
|
|
452
|
+
tokensOutput: number | null;
|
|
453
|
+
costUsd: number | null;
|
|
454
|
+
attributes: Record<string, unknown> | null;
|
|
455
|
+
spanId: string;
|
|
456
|
+
parentSpanId: string | null;
|
|
457
|
+
input: SpanPayload;
|
|
458
|
+
output: SpanPayload;
|
|
459
|
+
turnIndex?: number | undefined;
|
|
460
|
+
intervals?: {
|
|
461
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
462
|
+
startedAt: string;
|
|
463
|
+
endedAt: string;
|
|
464
|
+
}[] | undefined;
|
|
465
|
+
}, {
|
|
466
|
+
error: string | null;
|
|
467
|
+
status: "ok" | "error";
|
|
468
|
+
name: string;
|
|
469
|
+
deploymentSlug: string;
|
|
470
|
+
sessionExternalId: string;
|
|
471
|
+
startedAt: string;
|
|
472
|
+
endedAt: string | null;
|
|
473
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
474
|
+
contractVersion: 2;
|
|
475
|
+
durationMs: number | null;
|
|
476
|
+
model: string | null;
|
|
477
|
+
provider: string | null;
|
|
478
|
+
tokensInput: number | null;
|
|
479
|
+
tokensOutput: number | null;
|
|
480
|
+
costUsd: number | null;
|
|
481
|
+
attributes: Record<string, unknown> | null;
|
|
482
|
+
spanId: string;
|
|
483
|
+
parentSpanId: string | null;
|
|
484
|
+
input: SpanPayload;
|
|
485
|
+
output: SpanPayload;
|
|
486
|
+
turnIndex?: number | undefined;
|
|
487
|
+
intervals?: {
|
|
488
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
489
|
+
startedAt: string;
|
|
490
|
+
endedAt: string;
|
|
491
|
+
}[] | undefined;
|
|
492
|
+
}>;
|
|
493
|
+
declare const SpanInputSchema: z.ZodUnion<[z.ZodEffects<z.ZodObject<{
|
|
494
|
+
deploymentSlug: z.ZodString;
|
|
495
|
+
sessionExternalId: z.ZodString;
|
|
496
|
+
/**
|
|
497
|
+
* Turn the span belongs to. Optional: when omitted the worker resolves the
|
|
498
|
+
* session's latest turn at/under the span's startedAt (falling back to the
|
|
499
|
+
* session's most recent turn when startedAt is also absent — the outcome
|
|
500
|
+
* events' rule). A span whose turn cannot be resolved is SKIPPED by the
|
|
501
|
+
* worker (logged, batch still processed): spans never land unattributed.
|
|
502
|
+
*/
|
|
503
|
+
turnIndex: z.ZodOptional<z.ZodNumber>;
|
|
504
|
+
spanType: z.ZodEnum<["agent_call", "llm_call", "tool_call", "framework_step", "custom"]>;
|
|
505
|
+
} & {
|
|
506
|
+
contractVersion: z.ZodLiteral<2>;
|
|
507
|
+
/** Stable within a deployment/session across batches and retries. */
|
|
508
|
+
spanId: z.ZodString;
|
|
509
|
+
parentSpanId: z.ZodNullable<z.ZodString>;
|
|
510
|
+
name: z.ZodString;
|
|
511
|
+
status: z.ZodEnum<["ok", "error"]>;
|
|
512
|
+
startedAt: z.ZodString;
|
|
513
|
+
endedAt: z.ZodNullable<z.ZodString>;
|
|
514
|
+
durationMs: z.ZodNullable<z.ZodNumber>;
|
|
515
|
+
model: z.ZodNullable<z.ZodString>;
|
|
516
|
+
provider: z.ZodNullable<z.ZodString>;
|
|
517
|
+
tokensInput: z.ZodNullable<z.ZodNumber>;
|
|
518
|
+
tokensOutput: z.ZodNullable<z.ZodNumber>;
|
|
519
|
+
costUsd: z.ZodNullable<z.ZodNumber>;
|
|
520
|
+
error: z.ZodNullable<z.ZodString>;
|
|
521
|
+
input: z.ZodType<SpanPayload, z.ZodTypeDef, SpanPayload>;
|
|
522
|
+
output: z.ZodType<SpanPayload, z.ZodTypeDef, SpanPayload>;
|
|
523
|
+
/** Optional first-class internal timing. An omitted list means the source
|
|
524
|
+
* did not capture interval telemetry; readers must not infer segments. */
|
|
525
|
+
intervals: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
526
|
+
kind: z.ZodEnum<["active", "waiting", "retry", "error"]>;
|
|
527
|
+
startedAt: z.ZodString;
|
|
528
|
+
endedAt: z.ZodString;
|
|
529
|
+
}, "strip", z.ZodTypeAny, {
|
|
530
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
531
|
+
startedAt: string;
|
|
532
|
+
endedAt: string;
|
|
533
|
+
}, {
|
|
534
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
535
|
+
startedAt: string;
|
|
536
|
+
endedAt: string;
|
|
537
|
+
}>, {
|
|
538
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
539
|
+
startedAt: string;
|
|
540
|
+
endedAt: string;
|
|
541
|
+
}, {
|
|
542
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
543
|
+
startedAt: string;
|
|
544
|
+
endedAt: string;
|
|
545
|
+
}>, "many">>;
|
|
546
|
+
attributes: z.ZodEffects<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>, Record<string, unknown> | null, Record<string, unknown> | null>;
|
|
547
|
+
}, "strip", z.ZodTypeAny, {
|
|
548
|
+
error: string | null;
|
|
549
|
+
status: "ok" | "error";
|
|
550
|
+
name: string;
|
|
551
|
+
deploymentSlug: string;
|
|
552
|
+
sessionExternalId: string;
|
|
553
|
+
startedAt: string;
|
|
554
|
+
endedAt: string | null;
|
|
555
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
556
|
+
contractVersion: 2;
|
|
557
|
+
durationMs: number | null;
|
|
558
|
+
model: string | null;
|
|
559
|
+
provider: string | null;
|
|
560
|
+
tokensInput: number | null;
|
|
561
|
+
tokensOutput: number | null;
|
|
562
|
+
costUsd: number | null;
|
|
563
|
+
attributes: Record<string, unknown> | null;
|
|
564
|
+
spanId: string;
|
|
565
|
+
parentSpanId: string | null;
|
|
566
|
+
input: SpanPayload;
|
|
567
|
+
output: SpanPayload;
|
|
568
|
+
turnIndex?: number | undefined;
|
|
569
|
+
intervals?: {
|
|
570
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
571
|
+
startedAt: string;
|
|
572
|
+
endedAt: string;
|
|
573
|
+
}[] | undefined;
|
|
574
|
+
}, {
|
|
575
|
+
error: string | null;
|
|
576
|
+
status: "ok" | "error";
|
|
577
|
+
name: string;
|
|
578
|
+
deploymentSlug: string;
|
|
579
|
+
sessionExternalId: string;
|
|
580
|
+
startedAt: string;
|
|
581
|
+
endedAt: string | null;
|
|
582
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
583
|
+
contractVersion: 2;
|
|
584
|
+
durationMs: number | null;
|
|
585
|
+
model: string | null;
|
|
586
|
+
provider: string | null;
|
|
587
|
+
tokensInput: number | null;
|
|
588
|
+
tokensOutput: number | null;
|
|
589
|
+
costUsd: number | null;
|
|
590
|
+
attributes: Record<string, unknown> | null;
|
|
591
|
+
spanId: string;
|
|
592
|
+
parentSpanId: string | null;
|
|
593
|
+
input: SpanPayload;
|
|
594
|
+
output: SpanPayload;
|
|
595
|
+
turnIndex?: number | undefined;
|
|
596
|
+
intervals?: {
|
|
597
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
598
|
+
startedAt: string;
|
|
599
|
+
endedAt: string;
|
|
600
|
+
}[] | undefined;
|
|
601
|
+
}>, {
|
|
602
|
+
error: string | null;
|
|
603
|
+
status: "ok" | "error";
|
|
604
|
+
name: string;
|
|
605
|
+
deploymentSlug: string;
|
|
606
|
+
sessionExternalId: string;
|
|
607
|
+
startedAt: string;
|
|
608
|
+
endedAt: string | null;
|
|
609
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
610
|
+
contractVersion: 2;
|
|
611
|
+
durationMs: number | null;
|
|
612
|
+
model: string | null;
|
|
613
|
+
provider: string | null;
|
|
614
|
+
tokensInput: number | null;
|
|
615
|
+
tokensOutput: number | null;
|
|
616
|
+
costUsd: number | null;
|
|
617
|
+
attributes: Record<string, unknown> | null;
|
|
618
|
+
spanId: string;
|
|
619
|
+
parentSpanId: string | null;
|
|
620
|
+
input: SpanPayload;
|
|
621
|
+
output: SpanPayload;
|
|
622
|
+
turnIndex?: number | undefined;
|
|
623
|
+
intervals?: {
|
|
624
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
625
|
+
startedAt: string;
|
|
626
|
+
endedAt: string;
|
|
627
|
+
}[] | undefined;
|
|
263
628
|
}, {
|
|
629
|
+
error: string | null;
|
|
630
|
+
status: "ok" | "error";
|
|
631
|
+
name: string;
|
|
264
632
|
deploymentSlug: string;
|
|
265
633
|
sessionExternalId: string;
|
|
266
|
-
|
|
634
|
+
startedAt: string;
|
|
635
|
+
endedAt: string | null;
|
|
636
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
637
|
+
contractVersion: 2;
|
|
638
|
+
durationMs: number | null;
|
|
639
|
+
model: string | null;
|
|
640
|
+
provider: string | null;
|
|
641
|
+
tokensInput: number | null;
|
|
642
|
+
tokensOutput: number | null;
|
|
643
|
+
costUsd: number | null;
|
|
644
|
+
attributes: Record<string, unknown> | null;
|
|
645
|
+
spanId: string;
|
|
646
|
+
parentSpanId: string | null;
|
|
647
|
+
input: SpanPayload;
|
|
648
|
+
output: SpanPayload;
|
|
649
|
+
turnIndex?: number | undefined;
|
|
650
|
+
intervals?: {
|
|
651
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
652
|
+
startedAt: string;
|
|
653
|
+
endedAt: string;
|
|
654
|
+
}[] | undefined;
|
|
655
|
+
}>, z.ZodObject<{
|
|
656
|
+
deploymentSlug: z.ZodString;
|
|
657
|
+
sessionExternalId: z.ZodString;
|
|
658
|
+
/**
|
|
659
|
+
* Turn the span belongs to. Optional: when omitted the worker resolves the
|
|
660
|
+
* session's latest turn at/under the span's startedAt (falling back to the
|
|
661
|
+
* session's most recent turn when startedAt is also absent — the outcome
|
|
662
|
+
* events' rule). A span whose turn cannot be resolved is SKIPPED by the
|
|
663
|
+
* worker (logged, batch still processed): spans never land unattributed.
|
|
664
|
+
*/
|
|
665
|
+
turnIndex: z.ZodOptional<z.ZodNumber>;
|
|
666
|
+
spanType: z.ZodEnum<["agent_call", "llm_call", "tool_call", "framework_step", "custom"]>;
|
|
667
|
+
} & {
|
|
668
|
+
contractVersion: z.ZodOptional<z.ZodLiteral<1>>;
|
|
669
|
+
/** Human/otel-style span name (tool name, model call label). */
|
|
670
|
+
name: z.ZodOptional<z.ZodString>;
|
|
671
|
+
/**
|
|
672
|
+
* Caller-asserted span start (ISO). OPTIONAL and honored like
|
|
673
|
+
* TurnInput.startedAt: provenance, not verification — when absent the
|
|
674
|
+
* worker stamps processing time.
|
|
675
|
+
*/
|
|
676
|
+
startedAt: z.ZodOptional<z.ZodString>;
|
|
677
|
+
endedAt: z.ZodOptional<z.ZodString>;
|
|
678
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
679
|
+
model: z.ZodOptional<z.ZodString>;
|
|
680
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
681
|
+
tokensInput: z.ZodOptional<z.ZodNumber>;
|
|
682
|
+
tokensOutput: z.ZodOptional<z.ZodNumber>;
|
|
683
|
+
costUsd: z.ZodOptional<z.ZodNumber>;
|
|
684
|
+
error: z.ZodOptional<z.ZodString>;
|
|
685
|
+
/**
|
|
686
|
+
* OpenInference / OpenTelemetry gen_ai.*-style attributes. String values
|
|
687
|
+
* are scrubbed of personal data by the worker before storage (see the PII rule
|
|
688
|
+
* above). Capped at 16k JSON chars per span.
|
|
689
|
+
*/
|
|
690
|
+
attributes: z.ZodEffects<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>, Record<string, unknown> | undefined, Record<string, unknown> | undefined>;
|
|
691
|
+
/**
|
|
692
|
+
* Caller-local span id, unique within the batch. Exists only so sibling
|
|
693
|
+
* spans can name this span as their parentSpanId; never stored (the DB
|
|
694
|
+
* assigns the real uuid).
|
|
695
|
+
*/
|
|
696
|
+
spanId: z.ZodOptional<z.ZodString>;
|
|
697
|
+
/**
|
|
698
|
+
* Caller-local reference to another span's `spanId` IN THE SAME BATCH (NOT
|
|
699
|
+
* a database uuid). The worker wires spans.parent_span_id when the parent
|
|
700
|
+
* resolves within the batch, stores null otherwise.
|
|
701
|
+
*/
|
|
702
|
+
parentSpanId: z.ZodOptional<z.ZodString>;
|
|
703
|
+
}, "strip", z.ZodTypeAny, {
|
|
704
|
+
deploymentSlug: string;
|
|
705
|
+
sessionExternalId: string;
|
|
706
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
707
|
+
error?: string | undefined;
|
|
267
708
|
name?: string | undefined;
|
|
268
709
|
turnIndex?: number | undefined;
|
|
269
710
|
startedAt?: string | undefined;
|
|
270
711
|
endedAt?: string | undefined;
|
|
712
|
+
contractVersion?: 1 | undefined;
|
|
271
713
|
durationMs?: number | undefined;
|
|
272
714
|
model?: string | undefined;
|
|
273
715
|
provider?: string | undefined;
|
|
274
716
|
tokensInput?: number | undefined;
|
|
275
717
|
tokensOutput?: number | undefined;
|
|
276
718
|
costUsd?: number | undefined;
|
|
719
|
+
attributes?: Record<string, unknown> | undefined;
|
|
720
|
+
spanId?: string | undefined;
|
|
721
|
+
parentSpanId?: string | undefined;
|
|
722
|
+
}, {
|
|
723
|
+
deploymentSlug: string;
|
|
724
|
+
sessionExternalId: string;
|
|
725
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
277
726
|
error?: string | undefined;
|
|
727
|
+
name?: string | undefined;
|
|
728
|
+
turnIndex?: number | undefined;
|
|
729
|
+
startedAt?: string | undefined;
|
|
730
|
+
endedAt?: string | undefined;
|
|
731
|
+
contractVersion?: 1 | undefined;
|
|
732
|
+
durationMs?: number | undefined;
|
|
733
|
+
model?: string | undefined;
|
|
734
|
+
provider?: string | undefined;
|
|
735
|
+
tokensInput?: number | undefined;
|
|
736
|
+
tokensOutput?: number | undefined;
|
|
737
|
+
costUsd?: number | undefined;
|
|
278
738
|
attributes?: Record<string, unknown> | undefined;
|
|
279
739
|
spanId?: string | undefined;
|
|
280
740
|
parentSpanId?: string | undefined;
|
|
281
|
-
}>;
|
|
741
|
+
}>]>;
|
|
282
742
|
type SpanInput = z.infer<typeof SpanInputSchema>;
|
|
283
|
-
|
|
743
|
+
type SpanInputV1 = z.infer<typeof SpanInputV1Schema>;
|
|
744
|
+
type SpanInputV2 = z.infer<typeof SpanInputV2Schema>;
|
|
745
|
+
declare const SpansBatchSchema: z.ZodEffects<z.ZodObject<{
|
|
284
746
|
/** Spans are self-addressed: a batch may span sessions/deployments. */
|
|
285
|
-
spans: z.ZodArray<z.ZodObject<{
|
|
747
|
+
spans: z.ZodArray<z.ZodUnion<[z.ZodEffects<z.ZodObject<{
|
|
286
748
|
deploymentSlug: z.ZodString;
|
|
287
749
|
sessionExternalId: z.ZodString;
|
|
288
750
|
/**
|
|
@@ -293,7 +755,171 @@ declare const SpansBatchSchema: z.ZodObject<{
|
|
|
293
755
|
* worker (logged, batch still processed): spans never land unattributed.
|
|
294
756
|
*/
|
|
295
757
|
turnIndex: z.ZodOptional<z.ZodNumber>;
|
|
296
|
-
spanType: z.ZodEnum<["llm_call", "tool_call", "framework_step", "custom"]>;
|
|
758
|
+
spanType: z.ZodEnum<["agent_call", "llm_call", "tool_call", "framework_step", "custom"]>;
|
|
759
|
+
} & {
|
|
760
|
+
contractVersion: z.ZodLiteral<2>;
|
|
761
|
+
/** Stable within a deployment/session across batches and retries. */
|
|
762
|
+
spanId: z.ZodString;
|
|
763
|
+
parentSpanId: z.ZodNullable<z.ZodString>;
|
|
764
|
+
name: z.ZodString;
|
|
765
|
+
status: z.ZodEnum<["ok", "error"]>;
|
|
766
|
+
startedAt: z.ZodString;
|
|
767
|
+
endedAt: z.ZodNullable<z.ZodString>;
|
|
768
|
+
durationMs: z.ZodNullable<z.ZodNumber>;
|
|
769
|
+
model: z.ZodNullable<z.ZodString>;
|
|
770
|
+
provider: z.ZodNullable<z.ZodString>;
|
|
771
|
+
tokensInput: z.ZodNullable<z.ZodNumber>;
|
|
772
|
+
tokensOutput: z.ZodNullable<z.ZodNumber>;
|
|
773
|
+
costUsd: z.ZodNullable<z.ZodNumber>;
|
|
774
|
+
error: z.ZodNullable<z.ZodString>;
|
|
775
|
+
input: z.ZodType<SpanPayload, z.ZodTypeDef, SpanPayload>;
|
|
776
|
+
output: z.ZodType<SpanPayload, z.ZodTypeDef, SpanPayload>;
|
|
777
|
+
/** Optional first-class internal timing. An omitted list means the source
|
|
778
|
+
* did not capture interval telemetry; readers must not infer segments. */
|
|
779
|
+
intervals: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
780
|
+
kind: z.ZodEnum<["active", "waiting", "retry", "error"]>;
|
|
781
|
+
startedAt: z.ZodString;
|
|
782
|
+
endedAt: z.ZodString;
|
|
783
|
+
}, "strip", z.ZodTypeAny, {
|
|
784
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
785
|
+
startedAt: string;
|
|
786
|
+
endedAt: string;
|
|
787
|
+
}, {
|
|
788
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
789
|
+
startedAt: string;
|
|
790
|
+
endedAt: string;
|
|
791
|
+
}>, {
|
|
792
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
793
|
+
startedAt: string;
|
|
794
|
+
endedAt: string;
|
|
795
|
+
}, {
|
|
796
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
797
|
+
startedAt: string;
|
|
798
|
+
endedAt: string;
|
|
799
|
+
}>, "many">>;
|
|
800
|
+
attributes: z.ZodEffects<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>, Record<string, unknown> | null, Record<string, unknown> | null>;
|
|
801
|
+
}, "strip", z.ZodTypeAny, {
|
|
802
|
+
error: string | null;
|
|
803
|
+
status: "ok" | "error";
|
|
804
|
+
name: string;
|
|
805
|
+
deploymentSlug: string;
|
|
806
|
+
sessionExternalId: string;
|
|
807
|
+
startedAt: string;
|
|
808
|
+
endedAt: string | null;
|
|
809
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
810
|
+
contractVersion: 2;
|
|
811
|
+
durationMs: number | null;
|
|
812
|
+
model: string | null;
|
|
813
|
+
provider: string | null;
|
|
814
|
+
tokensInput: number | null;
|
|
815
|
+
tokensOutput: number | null;
|
|
816
|
+
costUsd: number | null;
|
|
817
|
+
attributes: Record<string, unknown> | null;
|
|
818
|
+
spanId: string;
|
|
819
|
+
parentSpanId: string | null;
|
|
820
|
+
input: SpanPayload;
|
|
821
|
+
output: SpanPayload;
|
|
822
|
+
turnIndex?: number | undefined;
|
|
823
|
+
intervals?: {
|
|
824
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
825
|
+
startedAt: string;
|
|
826
|
+
endedAt: string;
|
|
827
|
+
}[] | undefined;
|
|
828
|
+
}, {
|
|
829
|
+
error: string | null;
|
|
830
|
+
status: "ok" | "error";
|
|
831
|
+
name: string;
|
|
832
|
+
deploymentSlug: string;
|
|
833
|
+
sessionExternalId: string;
|
|
834
|
+
startedAt: string;
|
|
835
|
+
endedAt: string | null;
|
|
836
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
837
|
+
contractVersion: 2;
|
|
838
|
+
durationMs: number | null;
|
|
839
|
+
model: string | null;
|
|
840
|
+
provider: string | null;
|
|
841
|
+
tokensInput: number | null;
|
|
842
|
+
tokensOutput: number | null;
|
|
843
|
+
costUsd: number | null;
|
|
844
|
+
attributes: Record<string, unknown> | null;
|
|
845
|
+
spanId: string;
|
|
846
|
+
parentSpanId: string | null;
|
|
847
|
+
input: SpanPayload;
|
|
848
|
+
output: SpanPayload;
|
|
849
|
+
turnIndex?: number | undefined;
|
|
850
|
+
intervals?: {
|
|
851
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
852
|
+
startedAt: string;
|
|
853
|
+
endedAt: string;
|
|
854
|
+
}[] | undefined;
|
|
855
|
+
}>, {
|
|
856
|
+
error: string | null;
|
|
857
|
+
status: "ok" | "error";
|
|
858
|
+
name: string;
|
|
859
|
+
deploymentSlug: string;
|
|
860
|
+
sessionExternalId: string;
|
|
861
|
+
startedAt: string;
|
|
862
|
+
endedAt: string | null;
|
|
863
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
864
|
+
contractVersion: 2;
|
|
865
|
+
durationMs: number | null;
|
|
866
|
+
model: string | null;
|
|
867
|
+
provider: string | null;
|
|
868
|
+
tokensInput: number | null;
|
|
869
|
+
tokensOutput: number | null;
|
|
870
|
+
costUsd: number | null;
|
|
871
|
+
attributes: Record<string, unknown> | null;
|
|
872
|
+
spanId: string;
|
|
873
|
+
parentSpanId: string | null;
|
|
874
|
+
input: SpanPayload;
|
|
875
|
+
output: SpanPayload;
|
|
876
|
+
turnIndex?: number | undefined;
|
|
877
|
+
intervals?: {
|
|
878
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
879
|
+
startedAt: string;
|
|
880
|
+
endedAt: string;
|
|
881
|
+
}[] | undefined;
|
|
882
|
+
}, {
|
|
883
|
+
error: string | null;
|
|
884
|
+
status: "ok" | "error";
|
|
885
|
+
name: string;
|
|
886
|
+
deploymentSlug: string;
|
|
887
|
+
sessionExternalId: string;
|
|
888
|
+
startedAt: string;
|
|
889
|
+
endedAt: string | null;
|
|
890
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
891
|
+
contractVersion: 2;
|
|
892
|
+
durationMs: number | null;
|
|
893
|
+
model: string | null;
|
|
894
|
+
provider: string | null;
|
|
895
|
+
tokensInput: number | null;
|
|
896
|
+
tokensOutput: number | null;
|
|
897
|
+
costUsd: number | null;
|
|
898
|
+
attributes: Record<string, unknown> | null;
|
|
899
|
+
spanId: string;
|
|
900
|
+
parentSpanId: string | null;
|
|
901
|
+
input: SpanPayload;
|
|
902
|
+
output: SpanPayload;
|
|
903
|
+
turnIndex?: number | undefined;
|
|
904
|
+
intervals?: {
|
|
905
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
906
|
+
startedAt: string;
|
|
907
|
+
endedAt: string;
|
|
908
|
+
}[] | undefined;
|
|
909
|
+
}>, z.ZodObject<{
|
|
910
|
+
deploymentSlug: z.ZodString;
|
|
911
|
+
sessionExternalId: z.ZodString;
|
|
912
|
+
/**
|
|
913
|
+
* Turn the span belongs to. Optional: when omitted the worker resolves the
|
|
914
|
+
* session's latest turn at/under the span's startedAt (falling back to the
|
|
915
|
+
* session's most recent turn when startedAt is also absent — the outcome
|
|
916
|
+
* events' rule). A span whose turn cannot be resolved is SKIPPED by the
|
|
917
|
+
* worker (logged, batch still processed): spans never land unattributed.
|
|
918
|
+
*/
|
|
919
|
+
turnIndex: z.ZodOptional<z.ZodNumber>;
|
|
920
|
+
spanType: z.ZodEnum<["agent_call", "llm_call", "tool_call", "framework_step", "custom"]>;
|
|
921
|
+
} & {
|
|
922
|
+
contractVersion: z.ZodOptional<z.ZodLiteral<1>>;
|
|
297
923
|
/** Human/otel-style span name (tool name, model call label). */
|
|
298
924
|
name: z.ZodOptional<z.ZodString>;
|
|
299
925
|
/**
|
|
@@ -312,7 +938,7 @@ declare const SpansBatchSchema: z.ZodObject<{
|
|
|
312
938
|
error: z.ZodOptional<z.ZodString>;
|
|
313
939
|
/**
|
|
314
940
|
* OpenInference / OpenTelemetry gen_ai.*-style attributes. String values
|
|
315
|
-
* are
|
|
941
|
+
* are scrubbed of personal data by the worker before storage (see the PII rule
|
|
316
942
|
* above). Capped at 16k JSON chars per span.
|
|
317
943
|
*/
|
|
318
944
|
attributes: z.ZodEffects<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>, Record<string, unknown> | undefined, Record<string, unknown> | undefined>;
|
|
@@ -331,40 +957,42 @@ declare const SpansBatchSchema: z.ZodObject<{
|
|
|
331
957
|
}, "strip", z.ZodTypeAny, {
|
|
332
958
|
deploymentSlug: string;
|
|
333
959
|
sessionExternalId: string;
|
|
334
|
-
spanType: "tool_call" | "custom" | "llm_call" | "framework_step";
|
|
960
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
961
|
+
error?: string | undefined;
|
|
335
962
|
name?: string | undefined;
|
|
336
963
|
turnIndex?: number | undefined;
|
|
337
964
|
startedAt?: string | undefined;
|
|
338
965
|
endedAt?: string | undefined;
|
|
966
|
+
contractVersion?: 1 | undefined;
|
|
339
967
|
durationMs?: number | undefined;
|
|
340
968
|
model?: string | undefined;
|
|
341
969
|
provider?: string | undefined;
|
|
342
970
|
tokensInput?: number | undefined;
|
|
343
971
|
tokensOutput?: number | undefined;
|
|
344
972
|
costUsd?: number | undefined;
|
|
345
|
-
error?: string | undefined;
|
|
346
973
|
attributes?: Record<string, unknown> | undefined;
|
|
347
974
|
spanId?: string | undefined;
|
|
348
975
|
parentSpanId?: string | undefined;
|
|
349
976
|
}, {
|
|
350
977
|
deploymentSlug: string;
|
|
351
978
|
sessionExternalId: string;
|
|
352
|
-
spanType: "tool_call" | "custom" | "llm_call" | "framework_step";
|
|
979
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
980
|
+
error?: string | undefined;
|
|
353
981
|
name?: string | undefined;
|
|
354
982
|
turnIndex?: number | undefined;
|
|
355
983
|
startedAt?: string | undefined;
|
|
356
984
|
endedAt?: string | undefined;
|
|
985
|
+
contractVersion?: 1 | undefined;
|
|
357
986
|
durationMs?: number | undefined;
|
|
358
987
|
model?: string | undefined;
|
|
359
988
|
provider?: string | undefined;
|
|
360
989
|
tokensInput?: number | undefined;
|
|
361
990
|
tokensOutput?: number | undefined;
|
|
362
991
|
costUsd?: number | undefined;
|
|
363
|
-
error?: string | undefined;
|
|
364
992
|
attributes?: Record<string, unknown> | undefined;
|
|
365
993
|
spanId?: string | undefined;
|
|
366
994
|
parentSpanId?: string | undefined;
|
|
367
|
-
}>, "many">;
|
|
995
|
+
}>]>, "many">;
|
|
368
996
|
alignment: z.ZodObject<{
|
|
369
997
|
clock_source: z.ZodString;
|
|
370
998
|
skew_bound_ms: z.ZodOptional<z.ZodNumber>;
|
|
@@ -384,55 +1012,217 @@ declare const SpansBatchSchema: z.ZodObject<{
|
|
|
384
1012
|
rule_version: string;
|
|
385
1013
|
skew_bound_ms?: number | undefined;
|
|
386
1014
|
};
|
|
387
|
-
spans: {
|
|
1015
|
+
spans: ({
|
|
388
1016
|
deploymentSlug: string;
|
|
389
1017
|
sessionExternalId: string;
|
|
390
|
-
spanType: "tool_call" | "custom" | "llm_call" | "framework_step";
|
|
1018
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
1019
|
+
error?: string | undefined;
|
|
391
1020
|
name?: string | undefined;
|
|
392
1021
|
turnIndex?: number | undefined;
|
|
393
1022
|
startedAt?: string | undefined;
|
|
394
1023
|
endedAt?: string | undefined;
|
|
1024
|
+
contractVersion?: 1 | undefined;
|
|
395
1025
|
durationMs?: number | undefined;
|
|
396
1026
|
model?: string | undefined;
|
|
397
1027
|
provider?: string | undefined;
|
|
398
1028
|
tokensInput?: number | undefined;
|
|
399
1029
|
tokensOutput?: number | undefined;
|
|
400
1030
|
costUsd?: number | undefined;
|
|
401
|
-
error?: string | undefined;
|
|
402
1031
|
attributes?: Record<string, unknown> | undefined;
|
|
403
1032
|
spanId?: string | undefined;
|
|
404
1033
|
parentSpanId?: string | undefined;
|
|
405
|
-
}
|
|
1034
|
+
} | {
|
|
1035
|
+
error: string | null;
|
|
1036
|
+
status: "ok" | "error";
|
|
1037
|
+
name: string;
|
|
1038
|
+
deploymentSlug: string;
|
|
1039
|
+
sessionExternalId: string;
|
|
1040
|
+
startedAt: string;
|
|
1041
|
+
endedAt: string | null;
|
|
1042
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
1043
|
+
contractVersion: 2;
|
|
1044
|
+
durationMs: number | null;
|
|
1045
|
+
model: string | null;
|
|
1046
|
+
provider: string | null;
|
|
1047
|
+
tokensInput: number | null;
|
|
1048
|
+
tokensOutput: number | null;
|
|
1049
|
+
costUsd: number | null;
|
|
1050
|
+
attributes: Record<string, unknown> | null;
|
|
1051
|
+
spanId: string;
|
|
1052
|
+
parentSpanId: string | null;
|
|
1053
|
+
input: SpanPayload;
|
|
1054
|
+
output: SpanPayload;
|
|
1055
|
+
turnIndex?: number | undefined;
|
|
1056
|
+
intervals?: {
|
|
1057
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
1058
|
+
startedAt: string;
|
|
1059
|
+
endedAt: string;
|
|
1060
|
+
}[] | undefined;
|
|
1061
|
+
})[];
|
|
406
1062
|
}, {
|
|
407
1063
|
alignment: {
|
|
408
1064
|
clock_source: string;
|
|
409
1065
|
rule_version: string;
|
|
410
1066
|
skew_bound_ms?: number | undefined;
|
|
411
1067
|
};
|
|
412
|
-
spans: {
|
|
1068
|
+
spans: ({
|
|
1069
|
+
deploymentSlug: string;
|
|
1070
|
+
sessionExternalId: string;
|
|
1071
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
1072
|
+
error?: string | undefined;
|
|
1073
|
+
name?: string | undefined;
|
|
1074
|
+
turnIndex?: number | undefined;
|
|
1075
|
+
startedAt?: string | undefined;
|
|
1076
|
+
endedAt?: string | undefined;
|
|
1077
|
+
contractVersion?: 1 | undefined;
|
|
1078
|
+
durationMs?: number | undefined;
|
|
1079
|
+
model?: string | undefined;
|
|
1080
|
+
provider?: string | undefined;
|
|
1081
|
+
tokensInput?: number | undefined;
|
|
1082
|
+
tokensOutput?: number | undefined;
|
|
1083
|
+
costUsd?: number | undefined;
|
|
1084
|
+
attributes?: Record<string, unknown> | undefined;
|
|
1085
|
+
spanId?: string | undefined;
|
|
1086
|
+
parentSpanId?: string | undefined;
|
|
1087
|
+
} | {
|
|
1088
|
+
error: string | null;
|
|
1089
|
+
status: "ok" | "error";
|
|
1090
|
+
name: string;
|
|
1091
|
+
deploymentSlug: string;
|
|
1092
|
+
sessionExternalId: string;
|
|
1093
|
+
startedAt: string;
|
|
1094
|
+
endedAt: string | null;
|
|
1095
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
1096
|
+
contractVersion: 2;
|
|
1097
|
+
durationMs: number | null;
|
|
1098
|
+
model: string | null;
|
|
1099
|
+
provider: string | null;
|
|
1100
|
+
tokensInput: number | null;
|
|
1101
|
+
tokensOutput: number | null;
|
|
1102
|
+
costUsd: number | null;
|
|
1103
|
+
attributes: Record<string, unknown> | null;
|
|
1104
|
+
spanId: string;
|
|
1105
|
+
parentSpanId: string | null;
|
|
1106
|
+
input: SpanPayload;
|
|
1107
|
+
output: SpanPayload;
|
|
1108
|
+
turnIndex?: number | undefined;
|
|
1109
|
+
intervals?: {
|
|
1110
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
1111
|
+
startedAt: string;
|
|
1112
|
+
endedAt: string;
|
|
1113
|
+
}[] | undefined;
|
|
1114
|
+
})[];
|
|
1115
|
+
}>, {
|
|
1116
|
+
alignment: {
|
|
1117
|
+
clock_source: string;
|
|
1118
|
+
rule_version: string;
|
|
1119
|
+
skew_bound_ms?: number | undefined;
|
|
1120
|
+
};
|
|
1121
|
+
spans: ({
|
|
413
1122
|
deploymentSlug: string;
|
|
414
1123
|
sessionExternalId: string;
|
|
415
|
-
spanType: "tool_call" | "custom" | "llm_call" | "framework_step";
|
|
1124
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
1125
|
+
error?: string | undefined;
|
|
416
1126
|
name?: string | undefined;
|
|
417
1127
|
turnIndex?: number | undefined;
|
|
418
1128
|
startedAt?: string | undefined;
|
|
419
1129
|
endedAt?: string | undefined;
|
|
1130
|
+
contractVersion?: 1 | undefined;
|
|
420
1131
|
durationMs?: number | undefined;
|
|
421
1132
|
model?: string | undefined;
|
|
422
1133
|
provider?: string | undefined;
|
|
423
1134
|
tokensInput?: number | undefined;
|
|
424
1135
|
tokensOutput?: number | undefined;
|
|
425
1136
|
costUsd?: number | undefined;
|
|
1137
|
+
attributes?: Record<string, unknown> | undefined;
|
|
1138
|
+
spanId?: string | undefined;
|
|
1139
|
+
parentSpanId?: string | undefined;
|
|
1140
|
+
} | {
|
|
1141
|
+
error: string | null;
|
|
1142
|
+
status: "ok" | "error";
|
|
1143
|
+
name: string;
|
|
1144
|
+
deploymentSlug: string;
|
|
1145
|
+
sessionExternalId: string;
|
|
1146
|
+
startedAt: string;
|
|
1147
|
+
endedAt: string | null;
|
|
1148
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
1149
|
+
contractVersion: 2;
|
|
1150
|
+
durationMs: number | null;
|
|
1151
|
+
model: string | null;
|
|
1152
|
+
provider: string | null;
|
|
1153
|
+
tokensInput: number | null;
|
|
1154
|
+
tokensOutput: number | null;
|
|
1155
|
+
costUsd: number | null;
|
|
1156
|
+
attributes: Record<string, unknown> | null;
|
|
1157
|
+
spanId: string;
|
|
1158
|
+
parentSpanId: string | null;
|
|
1159
|
+
input: SpanPayload;
|
|
1160
|
+
output: SpanPayload;
|
|
1161
|
+
turnIndex?: number | undefined;
|
|
1162
|
+
intervals?: {
|
|
1163
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
1164
|
+
startedAt: string;
|
|
1165
|
+
endedAt: string;
|
|
1166
|
+
}[] | undefined;
|
|
1167
|
+
})[];
|
|
1168
|
+
}, {
|
|
1169
|
+
alignment: {
|
|
1170
|
+
clock_source: string;
|
|
1171
|
+
rule_version: string;
|
|
1172
|
+
skew_bound_ms?: number | undefined;
|
|
1173
|
+
};
|
|
1174
|
+
spans: ({
|
|
1175
|
+
deploymentSlug: string;
|
|
1176
|
+
sessionExternalId: string;
|
|
1177
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
426
1178
|
error?: string | undefined;
|
|
1179
|
+
name?: string | undefined;
|
|
1180
|
+
turnIndex?: number | undefined;
|
|
1181
|
+
startedAt?: string | undefined;
|
|
1182
|
+
endedAt?: string | undefined;
|
|
1183
|
+
contractVersion?: 1 | undefined;
|
|
1184
|
+
durationMs?: number | undefined;
|
|
1185
|
+
model?: string | undefined;
|
|
1186
|
+
provider?: string | undefined;
|
|
1187
|
+
tokensInput?: number | undefined;
|
|
1188
|
+
tokensOutput?: number | undefined;
|
|
1189
|
+
costUsd?: number | undefined;
|
|
427
1190
|
attributes?: Record<string, unknown> | undefined;
|
|
428
1191
|
spanId?: string | undefined;
|
|
429
1192
|
parentSpanId?: string | undefined;
|
|
430
|
-
}
|
|
1193
|
+
} | {
|
|
1194
|
+
error: string | null;
|
|
1195
|
+
status: "ok" | "error";
|
|
1196
|
+
name: string;
|
|
1197
|
+
deploymentSlug: string;
|
|
1198
|
+
sessionExternalId: string;
|
|
1199
|
+
startedAt: string;
|
|
1200
|
+
endedAt: string | null;
|
|
1201
|
+
spanType: "tool_call" | "custom" | "agent_call" | "llm_call" | "framework_step";
|
|
1202
|
+
contractVersion: 2;
|
|
1203
|
+
durationMs: number | null;
|
|
1204
|
+
model: string | null;
|
|
1205
|
+
provider: string | null;
|
|
1206
|
+
tokensInput: number | null;
|
|
1207
|
+
tokensOutput: number | null;
|
|
1208
|
+
costUsd: number | null;
|
|
1209
|
+
attributes: Record<string, unknown> | null;
|
|
1210
|
+
spanId: string;
|
|
1211
|
+
parentSpanId: string | null;
|
|
1212
|
+
input: SpanPayload;
|
|
1213
|
+
output: SpanPayload;
|
|
1214
|
+
turnIndex?: number | undefined;
|
|
1215
|
+
intervals?: {
|
|
1216
|
+
kind: "error" | "active" | "waiting" | "retry";
|
|
1217
|
+
startedAt: string;
|
|
1218
|
+
endedAt: string;
|
|
1219
|
+
}[] | undefined;
|
|
1220
|
+
})[];
|
|
431
1221
|
}>;
|
|
432
1222
|
type SpansBatch = z.infer<typeof SpansBatchSchema>;
|
|
433
1223
|
|
|
434
1224
|
/**
|
|
435
|
-
* Sight SDK (@
|
|
1225
|
+
* Sight SDK (@cultured_computer/sight) shared types.
|
|
436
1226
|
*/
|
|
437
1227
|
|
|
438
1228
|
declare const PersonaConfigSchema: z.ZodObject<{
|
|
@@ -509,7 +1299,7 @@ declare const OutcomeHookSchema: z.ZodObject<{
|
|
|
509
1299
|
type: z.ZodEnum<["numeric", "categorical", "boolean", "duration"]>;
|
|
510
1300
|
/**
|
|
511
1301
|
* Callback that resolves the outcome for a completed session. Invoked by
|
|
512
|
-
*
|
|
1302
|
+
* Sight.endSession() with the session's externalId; a non-null result
|
|
513
1303
|
* lands as an outcome event on the session. Not invoked for sessions
|
|
514
1304
|
* swept server-side (no explicit endSession) — use emitOutcomeEvent()
|
|
515
1305
|
* for outcomes that become known out of band.
|
|
@@ -525,15 +1315,16 @@ declare const OutcomeHookSchema: z.ZodObject<{
|
|
|
525
1315
|
type OutcomeHook = z.infer<typeof OutcomeHookSchema>;
|
|
526
1316
|
type OutcomeResult = {
|
|
527
1317
|
outcome: string;
|
|
528
|
-
type:
|
|
1318
|
+
type: "numeric" | "categorical" | "boolean" | "duration";
|
|
529
1319
|
value: string;
|
|
530
1320
|
};
|
|
531
1321
|
declare const ProbeConfigSchema: z.ZodObject<{
|
|
532
|
-
/**
|
|
1322
|
+
/** The project's API key (an ingest key from the dashboard). Required. */
|
|
533
1323
|
apiKey: z.ZodString;
|
|
534
|
-
/** Deployment slug
|
|
1324
|
+
/** Deployment slug: the configuration this traffic belongs to. Required. */
|
|
535
1325
|
deployment: z.ZodString;
|
|
536
|
-
/** Ingest endpoint. Defaults to the production ingest service
|
|
1326
|
+
/** Ingest endpoint. Defaults to the production ingest service,
|
|
1327
|
+
`https://fieldwork-ingest.fly.dev`. */
|
|
537
1328
|
endpoint: z.ZodDefault<z.ZodString>;
|
|
538
1329
|
/**
|
|
539
1330
|
* Dashboard base URL used by the one-time first-capture announcement
|
|
@@ -617,7 +1408,7 @@ declare const ProbeConfigSchema: z.ZodObject<{
|
|
|
617
1408
|
type: z.ZodEnum<["numeric", "categorical", "boolean", "duration"]>;
|
|
618
1409
|
/**
|
|
619
1410
|
* Callback that resolves the outcome for a completed session. Invoked by
|
|
620
|
-
*
|
|
1411
|
+
* Sight.endSession() with the session's externalId; a non-null result
|
|
621
1412
|
* lands as an outcome event on the session. Not invoked for sessions
|
|
622
1413
|
* swept server-side (no explicit endSession) — use emitOutcomeEvent()
|
|
623
1414
|
* for outcomes that become known out of band.
|
|
@@ -693,7 +1484,7 @@ declare const ProbeConfigSchema: z.ZodObject<{
|
|
|
693
1484
|
}>;
|
|
694
1485
|
type ProbeConfig = z.infer<typeof ProbeConfigSchema>;
|
|
695
1486
|
/**
|
|
696
|
-
* The shape callers pass to
|
|
1487
|
+
* The shape callers pass to Sight.init(). This is the schema's INPUT type, so
|
|
697
1488
|
* fields with a `.default()` (endpoint, sampleRate, debug) are optional here —
|
|
698
1489
|
* the defaults are applied by ProbeConfigSchema.parse() inside init(). Use this
|
|
699
1490
|
* for the init argument; `ProbeConfig` is the resolved (post-parse) type held
|
|
@@ -725,14 +1516,14 @@ declare const SessionStartSchema: z.ZodObject<{
|
|
|
725
1516
|
*/
|
|
726
1517
|
openedVia: z.ZodOptional<z.ZodEnum<["link", "notification", "resume", "direct", "share"]>>;
|
|
727
1518
|
/**
|
|
728
|
-
* Environmental context
|
|
729
|
-
*
|
|
1519
|
+
* Environmental context: browser / device / locale / tz. You choose
|
|
1520
|
+
* which fields to include. See the collectClientContext helper.
|
|
730
1521
|
*/
|
|
731
1522
|
clientContext: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
732
1523
|
/**
|
|
733
1524
|
* Optional customer metadata attached to the session. Forwarded with the
|
|
734
1525
|
* first captured turn merged into `clientContext` under the `metadata`
|
|
735
|
-
* key, so it
|
|
1526
|
+
* key, so it is stored with the session.
|
|
736
1527
|
*/
|
|
737
1528
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
738
1529
|
/**
|
|
@@ -772,7 +1563,7 @@ declare const SessionStartSchema: z.ZodObject<{
|
|
|
772
1563
|
}>;
|
|
773
1564
|
type SessionStart = z.infer<typeof SessionStartSchema>;
|
|
774
1565
|
/**
|
|
775
|
-
* Session end input
|
|
1566
|
+
* Session end input. Sent by Sight.endSession() so the worker records
|
|
776
1567
|
* why a session ended. `outcome` + `outcomeDetail` are the one-call
|
|
777
1568
|
* outcome helper: when the deployer knows the outcome at close (a
|
|
778
1569
|
* resolved ticket, an escalation, an abandonment), the SDK emits it as an
|
|
@@ -799,14 +1590,30 @@ type SessionEndInput = z.infer<typeof SessionEndSchema>;
|
|
|
799
1590
|
type CapturedTurn = {
|
|
800
1591
|
deploymentSlug: string;
|
|
801
1592
|
sessionExternalId: string;
|
|
1593
|
+
/**
|
|
1594
|
+
* The SDK payload contract version:
|
|
1595
|
+
* stamped on EVERY captured turn by this SDK; absent on payloads from
|
|
1596
|
+
* older SDKs (read as 'envelope-v0-unstamped' downstream). Data lineage
|
|
1597
|
+
* across SDK upgrades — additive-only, tolerated-absent.
|
|
1598
|
+
*/
|
|
1599
|
+
envelopeVersion?: string;
|
|
802
1600
|
/**
|
|
803
1601
|
* Customer's user identity. Forwarded by captureTurn from the session
|
|
804
|
-
* state (
|
|
1602
|
+
* state (Sight.startSession({ externalUserId })); the worker persists it
|
|
805
1603
|
* on sessions.external_user_id at first-turn session create. Never
|
|
806
1604
|
* defaulted to sessionExternalId — that key identifies the session.
|
|
807
1605
|
*/
|
|
808
1606
|
externalUserId?: string;
|
|
809
1607
|
turnIndex: number;
|
|
1608
|
+
/**
|
|
1609
|
+
* The identity of one logical turn: a UUID. The SDK stamps a fresh one
|
|
1610
|
+
* on every captured turn and re-sends the same value when it retries
|
|
1611
|
+
* the send, so the server can tell a re-sent turn (same turnId) from a
|
|
1612
|
+
* different turn that reached the same turnIndex (another process, a
|
|
1613
|
+
* restart). Supply your own only when you already hold a stable UUID for
|
|
1614
|
+
* the turn; a supplied value is sent as given.
|
|
1615
|
+
*/
|
|
1616
|
+
turnId?: string;
|
|
810
1617
|
/**
|
|
811
1618
|
* Persona slug active for this turn. Resolved by the SDK from (in order):
|
|
812
1619
|
* turn-level override, session-level from startSession(), init-level default.
|
|
@@ -831,9 +1638,9 @@ type CapturedTurn = {
|
|
|
831
1638
|
reactionNextTurn?: string;
|
|
832
1639
|
};
|
|
833
1640
|
/**
|
|
834
|
-
*
|
|
835
|
-
*
|
|
836
|
-
* server-side before
|
|
1641
|
+
* The person's input for this turn: the message that prompted this
|
|
1642
|
+
* reply, plus UI-level interactivity signals. The text is scrubbed of
|
|
1643
|
+
* personal data server-side before it is stored.
|
|
837
1644
|
*/
|
|
838
1645
|
userInput?: {
|
|
839
1646
|
text?: string;
|
|
@@ -859,14 +1666,14 @@ type CapturedTurn = {
|
|
|
859
1666
|
* User outcome signals:
|
|
860
1667
|
* flagged break, explicit rating (1-5), thumbs.
|
|
861
1668
|
*
|
|
862
|
-
* `flaggedBreak` is DEPRECATED in favor of
|
|
1669
|
+
* `flaggedBreak` is DEPRECATED in favor of Sight.flagPersonaBreak(),
|
|
863
1670
|
* which carries user attribution and emits a 'break' outcome event;
|
|
864
1671
|
* the turn-level boolean remains accepted for wire compat only.
|
|
865
1672
|
*/
|
|
866
1673
|
userOutcome?: {
|
|
867
1674
|
flaggedBreak?: boolean;
|
|
868
1675
|
explicitRating?: number;
|
|
869
|
-
thumbs?:
|
|
1676
|
+
thumbs?: "up" | "down";
|
|
870
1677
|
};
|
|
871
1678
|
/**
|
|
872
1679
|
* Propensity + candidate set (harness-supplied).
|
|
@@ -888,10 +1695,10 @@ type CapturedTurn = {
|
|
|
888
1695
|
};
|
|
889
1696
|
/**
|
|
890
1697
|
* Session context forwarded on the FIRST captured turn of a session
|
|
891
|
-
* (populated by captureTurn from
|
|
1698
|
+
* (populated by captureTurn from Sight.startSession state; the worker
|
|
892
1699
|
* persists both at session find-or-create). Omitted on later turns.
|
|
893
1700
|
*/
|
|
894
|
-
openedVia?:
|
|
1701
|
+
openedVia?: "link" | "notification" | "resume" | "direct" | "share";
|
|
895
1702
|
clientContext?: Record<string, unknown>;
|
|
896
1703
|
/**
|
|
897
1704
|
* RLDS episode-level provenance. Forwarded from the session
|
|
@@ -906,6 +1713,14 @@ type CapturedTurn = {
|
|
|
906
1713
|
environmentConfigLabel?: string;
|
|
907
1714
|
payload: Record<string, unknown>;
|
|
908
1715
|
};
|
|
1716
|
+
/**
|
|
1717
|
+
* What `captureTurn` accepts: a captured turn whose `deploymentSlug` may be
|
|
1718
|
+
* omitted. When it is, the `deployment` given to `init` is used; an
|
|
1719
|
+
* explicit value wins.
|
|
1720
|
+
*/
|
|
1721
|
+
type CaptureTurnInput = Omit<CapturedTurn, "deploymentSlug"> & {
|
|
1722
|
+
deploymentSlug?: string;
|
|
1723
|
+
};
|
|
909
1724
|
declare const FlagPersonaBreakSchema: z.ZodObject<{
|
|
910
1725
|
sessionExternalId: z.ZodString;
|
|
911
1726
|
note: z.ZodOptional<z.ZodString>;
|
|
@@ -942,7 +1757,7 @@ declare const OutcomeEventEmitSchema: z.ZodObject<{
|
|
|
942
1757
|
type OutcomeEventEmit = z.infer<typeof OutcomeEventEmitSchema>;
|
|
943
1758
|
|
|
944
1759
|
/**
|
|
945
|
-
* HTTP client for the
|
|
1760
|
+
* HTTP client for the Sight ingest API.
|
|
946
1761
|
*
|
|
947
1762
|
* Sends captured turns to POST /v1/turns with a Bearer token. Async, fire-and-log:
|
|
948
1763
|
* SDK never blocks the customer's LLM path on ingest. Rate-limited sends (429)
|
|
@@ -984,23 +1799,24 @@ declare class IngestClient {
|
|
|
984
1799
|
private shedAnnounced;
|
|
985
1800
|
/**
|
|
986
1801
|
* Every network send goes through here: adds the per-send timeout and
|
|
987
|
-
* the in-flight cap
|
|
988
|
-
*
|
|
1802
|
+
* the in-flight cap. At the cap, the send is SHED (thrown into the
|
|
1803
|
+
* caller's existing fire-and-log catch) rather than queued;
|
|
989
1804
|
* the first shed per process warns on stderr, the rest debug-log.
|
|
990
1805
|
*/
|
|
991
1806
|
private guardedFetch;
|
|
992
1807
|
/**
|
|
993
|
-
* Await all in-flight sends (bounded). Called by
|
|
1808
|
+
* Await all in-flight sends (bounded). Called by Sight.shutdown() so
|
|
994
1809
|
* short-lived processes (serverless, CLI scripts) can actually exit after
|
|
995
1810
|
* it — the documented "in-flight sends finish within 15s" only holds while
|
|
996
1811
|
* the process lives. Polling is coarse on purpose: sends report through
|
|
997
|
-
* guardedFetch's counter, never awaited individually.
|
|
1812
|
+
* guardedFetch's counter and scheduled retries, never awaited individually.
|
|
1813
|
+
* Retries beyond the drain budget remain best-effort, not durable delivery.
|
|
998
1814
|
*/
|
|
999
1815
|
drainInFlight(timeoutMs?: number): Promise<void>;
|
|
1000
1816
|
constructor(opts: IngestClientOptions);
|
|
1001
1817
|
/**
|
|
1002
1818
|
* Send a turn to the ingest API. Fire-and-log: errors are logged but never
|
|
1003
|
-
* thrown. The customer's LLM path never blocks on
|
|
1819
|
+
* thrown. The customer's LLM path never blocks on capture.
|
|
1004
1820
|
*/
|
|
1005
1821
|
sendTurn(turn: CapturedTurn): Promise<void>;
|
|
1006
1822
|
/**
|
|
@@ -1010,7 +1826,7 @@ declare class IngestClient {
|
|
|
1010
1826
|
sendFlag(deploymentSlug: string, flag: FlagPersonaBreakInput): Promise<void>;
|
|
1011
1827
|
/**
|
|
1012
1828
|
* Send a session-end event to the ingest API. Records why a session ended
|
|
1013
|
-
* on the
|
|
1829
|
+
* on the session. Fire-and-log.
|
|
1014
1830
|
*/
|
|
1015
1831
|
sendSessionEnd(deploymentSlug: string, end: SessionEndInput): Promise<void>;
|
|
1016
1832
|
/**
|
|
@@ -1046,11 +1862,11 @@ declare class IngestClient {
|
|
|
1046
1862
|
}
|
|
1047
1863
|
|
|
1048
1864
|
/**
|
|
1049
|
-
* Client-context capture helper
|
|
1865
|
+
* Client-context capture helper.
|
|
1050
1866
|
*
|
|
1051
1867
|
* At session start the SDK optionally collects browser/device/locale/tz
|
|
1052
1868
|
* metadata to send as SessionStart.clientContext. Customers control which
|
|
1053
|
-
* fields land via
|
|
1869
|
+
* fields land via the `includes` argument; the default is
|
|
1054
1870
|
* conservative (locale + timezone + agent kind, no fingerprinting fields).
|
|
1055
1871
|
*
|
|
1056
1872
|
* Node-side calls receive process metadata; browser-side calls receive
|
|
@@ -1075,7 +1891,7 @@ type ClientContextIncludes = {
|
|
|
1075
1891
|
/**
|
|
1076
1892
|
* Signature-phrase matcher.
|
|
1077
1893
|
*
|
|
1078
|
-
* Per-persona regex matching for voice consistency
|
|
1894
|
+
* Per-persona regex matching for voice consistency.
|
|
1079
1895
|
* Customer authors signature phrases at Probe.init({ persona: { signaturePhrases: [...] } }).
|
|
1080
1896
|
* The SDK edge or a worker computes matches per turn and includes the list
|
|
1081
1897
|
* of matched slugs in the turn payload.
|
|
@@ -1085,9 +1901,7 @@ type ClientContextIncludes = {
|
|
|
1085
1901
|
* source string with optional flags. Slug is what appears in the matches
|
|
1086
1902
|
* array; it is not the pattern.
|
|
1087
1903
|
*
|
|
1088
|
-
* Trivial by design
|
|
1089
|
-
* Chapter 5 Dream column (PSV representation with per-deployment STEL
|
|
1090
|
-
* calibration); this is the Day-1 heuristic that ships from ingest data alone.
|
|
1904
|
+
* Trivial by design: a heuristic computed from the captured text alone.
|
|
1091
1905
|
*/
|
|
1092
1906
|
type SignaturePhrase = {
|
|
1093
1907
|
/** Slug that appears in the matches array. Unique per persona. */
|
|
@@ -1117,18 +1931,18 @@ type CompiledPhrase = {
|
|
|
1117
1931
|
declare function compileSignaturePhrases(phrases: SignaturePhrase[]): CompiledPhrase[];
|
|
1118
1932
|
|
|
1119
1933
|
/**
|
|
1120
|
-
* The
|
|
1934
|
+
* The Sight SDK class. Exported as `Sight`, and as `Probe` (its earlier
|
|
1935
|
+
* name) for compatibility.
|
|
1121
1936
|
*
|
|
1122
1937
|
* Usage:
|
|
1123
|
-
* import { Sight } from '@
|
|
1938
|
+
* import { Sight } from '@cultured_computer/sight';
|
|
1124
1939
|
*
|
|
1125
|
-
*
|
|
1126
|
-
* apiKey: process.env.
|
|
1940
|
+
* Sight.init({
|
|
1941
|
+
* apiKey: process.env.SIGHT_API_KEY!,
|
|
1127
1942
|
* deployment: 'support-agent',
|
|
1128
|
-
* persona: { slug: 'casey' },
|
|
1129
1943
|
* });
|
|
1130
1944
|
*
|
|
1131
|
-
* //
|
|
1945
|
+
* // Calls made inside Sight.withSession(id, fn) are captured as turns.
|
|
1132
1946
|
*/
|
|
1133
1947
|
|
|
1134
1948
|
type ProbeState = {
|
|
@@ -1153,8 +1967,8 @@ type ProbeState = {
|
|
|
1153
1967
|
preSessionBuffer: Map<string, PreSessionSignals>;
|
|
1154
1968
|
};
|
|
1155
1969
|
type PreSessionSignals = {
|
|
1156
|
-
pendingUserInput: SessionState[
|
|
1157
|
-
pendingUserOutcome: SessionState[
|
|
1970
|
+
pendingUserInput: SessionState["pendingUserInput"];
|
|
1971
|
+
pendingUserOutcome: SessionState["pendingUserOutcome"];
|
|
1158
1972
|
lastUserSubmitAt: number | null;
|
|
1159
1973
|
};
|
|
1160
1974
|
|
|
@@ -1200,24 +2014,28 @@ type SessionState = {
|
|
|
1200
2014
|
} | null;
|
|
1201
2015
|
/** Per-turn user outcome pending on the SDK edge (thumbs / rating). */
|
|
1202
2016
|
pendingUserOutcome: {
|
|
1203
|
-
thumbs?:
|
|
2017
|
+
thumbs?: "up" | "down";
|
|
1204
2018
|
explicitRating?: number;
|
|
1205
2019
|
} | null;
|
|
1206
2020
|
};
|
|
1207
2021
|
declare class Probe {
|
|
1208
2022
|
/**
|
|
1209
|
-
* Initialize the
|
|
2023
|
+
* Initialize the SDK. Call once at process start. Subsequent calls are
|
|
1210
2024
|
* no-ops with a warning; re-init requires a shutdown() first.
|
|
1211
2025
|
*/
|
|
1212
2026
|
static init(config: ProbeConfigInput): void;
|
|
1213
2027
|
/**
|
|
1214
|
-
* Run a callback inside a session
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
1217
|
-
* a turn on that session.
|
|
2028
|
+
* Run a callback inside a session scope. Every LLM call made inside `fn`
|
|
2029
|
+
* through a wrapped OpenAI client or an instrumented library is captured
|
|
2030
|
+
* as a turn on the session `sessionId`.
|
|
1218
2031
|
*
|
|
1219
|
-
*
|
|
1220
|
-
*
|
|
2032
|
+
* Autocapture needs this scope: a call made outside any session scope is
|
|
2033
|
+
* not captured. The first such call in a process prints one warning;
|
|
2034
|
+
* later ones log only with `debug: true`. (Spans that carry
|
|
2035
|
+
* `gen_ai.conversation.id` are the one exception: with no scope, that id
|
|
2036
|
+
* is used as the session id. An explicit scope always wins.)
|
|
2037
|
+
*
|
|
2038
|
+
* The scope is carried in OpenTelemetry baggage across awaits.
|
|
1221
2039
|
*/
|
|
1222
2040
|
static withSession<T>(sessionId: string, fn: () => T | Promise<T>): Promise<T>;
|
|
1223
2041
|
/**
|
|
@@ -1252,7 +2070,7 @@ declare class Probe {
|
|
|
1252
2070
|
private static preSessionEntry;
|
|
1253
2071
|
/**
|
|
1254
2072
|
* Compute a stable SHA-256 hex hash of prompt/config text for use as
|
|
1255
|
-
* `environmentConfigHash` on
|
|
2073
|
+
* `environmentConfigHash` on Sight.startSession(). Hash is *identity*:
|
|
1256
2074
|
* pass the human-readable version alongside as `environmentConfigLabel`
|
|
1257
2075
|
* for the diff table axis (a card keyed by a3f9c2… is unreadable).
|
|
1258
2076
|
*
|
|
@@ -1285,28 +2103,30 @@ declare class Probe {
|
|
|
1285
2103
|
*/
|
|
1286
2104
|
static endSession(externalId: string | SessionEndInput): Promise<void>;
|
|
1287
2105
|
/**
|
|
1288
|
-
*
|
|
1289
|
-
*
|
|
2106
|
+
* The person started typing. Records the first-keystroke time, sent as
|
|
2107
|
+
* `userInput.firstKeystrokeMs` with the next captured turn. Derivable
|
|
1290
2108
|
* only once a previous agent turn exists; a pre-session typing start
|
|
1291
2109
|
* buffers the pending-input entry without a firstKeystrokeMs value.
|
|
1292
2110
|
*/
|
|
1293
2111
|
static userInputStart(externalId: string): void;
|
|
1294
2112
|
/**
|
|
1295
|
-
*
|
|
1296
|
-
*
|
|
2113
|
+
* The person pressed backspace or edited. Increments the edit count,
|
|
2114
|
+
* sent as `userInput.editCount` with the next captured turn.
|
|
1297
2115
|
*/
|
|
1298
2116
|
static userInputEdit(externalId: string): void;
|
|
1299
2117
|
/**
|
|
1300
|
-
*
|
|
1301
|
-
* server-side before
|
|
1302
|
-
* timestamp
|
|
1303
|
-
*
|
|
1304
|
-
* agent turn → submit).
|
|
2118
|
+
* The person submitted their message. Records the text (scrubbed of
|
|
2119
|
+
* personal data server-side before it is stored) plus the submit
|
|
2120
|
+
* timestamp. The text and timings are sent with the NEXT captured turn:
|
|
2121
|
+
* a turn's person text is the message that prompted its reply.
|
|
1305
2122
|
*/
|
|
1306
2123
|
static userInputSubmit(externalId: string, text: string): void;
|
|
1307
2124
|
/** Attach a thumbs-up/down to the current turn. */
|
|
1308
|
-
static userThumbs(externalId: string, thumbs:
|
|
1309
|
-
/**
|
|
2125
|
+
static userThumbs(externalId: string, thumbs: "up" | "down"): void;
|
|
2126
|
+
/**
|
|
2127
|
+
* Attach an explicit rating to the current turn: an integer from 1 to 5.
|
|
2128
|
+
* Any other value logs one warning line and is dropped.
|
|
2129
|
+
*/
|
|
1310
2130
|
static userRating(externalId: string, rating: number): void;
|
|
1311
2131
|
/**
|
|
1312
2132
|
* Helper: collect client context and pass it to startSession in one call.
|
|
@@ -1324,22 +2144,35 @@ declare class Probe {
|
|
|
1324
2144
|
*/
|
|
1325
2145
|
static wireOutcomeHook(hook: OutcomeHook): void;
|
|
1326
2146
|
/**
|
|
1327
|
-
* Manually capture a turn.
|
|
1328
|
-
*
|
|
2147
|
+
* Manually capture a turn. For callers that do not use autocapture.
|
|
2148
|
+
*
|
|
2149
|
+
* - `deploymentSlug` may be omitted: the `deployment` given to `init` is
|
|
2150
|
+
* used. An explicit value wins.
|
|
2151
|
+
* - Every turn is sent with a `turnId` (a fresh UUID unless you supply
|
|
2152
|
+
* one). A retried send carries the same `turnId`.
|
|
2153
|
+
* - The turn is validated before it is sent. An invalid turn logs one
|
|
2154
|
+
* warning line naming the first invalid field and is dropped; nothing
|
|
2155
|
+
* is sent.
|
|
1329
2156
|
*
|
|
1330
2157
|
* Persona resolution order for the outgoing turn payload:
|
|
1331
2158
|
* 1. turn.personaSlug (turn-level override)
|
|
1332
|
-
* 2.
|
|
1333
|
-
* 3.
|
|
2159
|
+
* 2. the session's persona (from startSession)
|
|
2160
|
+
* 3. the init-level default
|
|
1334
2161
|
*
|
|
1335
|
-
* Signature-phrase matching runs
|
|
2162
|
+
* Signature-phrase matching runs in the SDK when the resolved persona
|
|
1336
2163
|
* has signature phrases registered. The matched slug list is attached to
|
|
1337
2164
|
* `turn.signaturePhraseMatches` before send.
|
|
1338
2165
|
*/
|
|
1339
|
-
static captureTurn(turn:
|
|
2166
|
+
static captureTurn(turn: CaptureTurnInput): Promise<void>;
|
|
1340
2167
|
/**
|
|
1341
|
-
*
|
|
1342
|
-
*
|
|
2168
|
+
* The one capture path. Manual captureTurn calls and autocapture both
|
|
2169
|
+
* land here; autocapture also passes what it observed on the request
|
|
2170
|
+
* (`hints`), applied below under the explicit-input-wins rule.
|
|
2171
|
+
*/
|
|
2172
|
+
private static captureWithHints;
|
|
2173
|
+
/**
|
|
2174
|
+
* Emit a custom outcome event on a session, stored with the `kind`
|
|
2175
|
+
* string you supply. Use for
|
|
1343
2176
|
* customer-defined kinds like "purchase_complete", "handoff_to_human",
|
|
1344
2177
|
* "character_break_severe". Universal seed kinds (break, escalation,
|
|
1345
2178
|
* resolution, thumbs_*, rating_*) are also emitted by worker-side
|
|
@@ -1423,39 +2256,128 @@ declare class Probe {
|
|
|
1423
2256
|
}
|
|
1424
2257
|
|
|
1425
2258
|
/**
|
|
1426
|
-
* Explicit OpenAI client wrapping
|
|
2259
|
+
* Explicit OpenAI client wrapping: the autocapture path that does not
|
|
2260
|
+
* depend on module format, load order, or the openai version.
|
|
1427
2261
|
*
|
|
1428
|
-
* Module patching (
|
|
1429
|
-
*
|
|
1430
|
-
*
|
|
1431
|
-
* A modern ESM app on openai v5+ therefore captures nothing through the
|
|
1432
|
-
* patch path, and did so silently until registerOpenAI grew its post-enable
|
|
1433
|
-
* verification. wrapOpenAI() is the documented default instead: it wraps
|
|
1434
|
-
* the client INSTANCE the customer already holds, which is immune to module
|
|
1435
|
-
* format, load order, and library version.
|
|
2262
|
+
* Module patching (the other path) attaches only under CommonJS, only when
|
|
2263
|
+
* `openai` is loaded after Sight.init(), and only for openai <5. wrapOpenAI()
|
|
2264
|
+
* wraps the client instance the caller already holds instead.
|
|
1436
2265
|
*
|
|
1437
2266
|
* import OpenAI from 'openai';
|
|
1438
|
-
* import {
|
|
2267
|
+
* import { Sight, wrapOpenAI } from '@cultured_computer/sight';
|
|
1439
2268
|
* const openai = wrapOpenAI(new OpenAI());
|
|
2269
|
+
* await Sight.withSession(conversationId, () =>
|
|
2270
|
+
* openai.chat.completions.create({ ... }),
|
|
2271
|
+
* );
|
|
1440
2272
|
*
|
|
1441
2273
|
* Covers chat.completions.create and responses.create, streaming included:
|
|
1442
2274
|
* the stream is teed, chunks reach the caller unchanged, and the turn is
|
|
1443
|
-
* emitted when the stream completes.
|
|
1444
|
-
*
|
|
1445
|
-
*
|
|
2275
|
+
* emitted when the stream completes. A call is captured only inside a
|
|
2276
|
+
* Sight.withSession() scope; the first call outside one prints one warning.
|
|
2277
|
+
*
|
|
2278
|
+
* A streamed call also records the time to the first token: request start
|
|
2279
|
+
* to the first chunk that carries reply text, a refusal, or a tool call.
|
|
2280
|
+
* A non-streamed call has no first-token time and sends none. A cost is
|
|
2281
|
+
* sent only when the response reports one (`usage.cost`).
|
|
1446
2282
|
*
|
|
1447
|
-
*
|
|
1448
|
-
*
|
|
1449
|
-
*
|
|
1450
|
-
* call happens while unbound so a missing init is never silent.
|
|
2283
|
+
* wrapOpenAI() may be called before Sight.init(): the wrap passes calls
|
|
2284
|
+
* through untouched until init runs, and warns once if a call happens
|
|
2285
|
+
* before it.
|
|
1451
2286
|
*/
|
|
1452
2287
|
|
|
1453
2288
|
/**
|
|
1454
2289
|
* Wrap an OpenAI client instance so every chat.completions.create and
|
|
1455
|
-
* responses.create call
|
|
1456
|
-
* client. Idempotent; safe to call before
|
|
1457
|
-
* once init
|
|
2290
|
+
* responses.create call made inside a Sight.withSession() scope is captured
|
|
2291
|
+
* as a turn. Returns the same client. Idempotent; safe to call before
|
|
2292
|
+
* Sight.init() (capture starts once init has run). A call outside any
|
|
2293
|
+
* session scope is not captured; the first one prints one warning.
|
|
1458
2294
|
*/
|
|
1459
2295
|
declare function wrapOpenAI<T extends object>(client: T): T;
|
|
1460
2296
|
|
|
1461
|
-
|
|
2297
|
+
/**
|
|
2298
|
+
* Vercel AI SDK (`ai`) autocapture.
|
|
2299
|
+
*
|
|
2300
|
+
* `ai` 7 creates no OpenTelemetry spans itself. It calls the telemetry
|
|
2301
|
+
* integrations registered with `registerTelemetry()` (kept on the global
|
|
2302
|
+
* `AI_SDK_TELEMETRY_INTEGRATIONS`), and once one integration is registered
|
|
2303
|
+
* every call emits events with no per-call flag. This file is that
|
|
2304
|
+
* integration: Sight.init() registers it when `ai` 7 is resolvable, and
|
|
2305
|
+
* `sightTelemetry()` exports it for hosts that register it themselves.
|
|
2306
|
+
*
|
|
2307
|
+
* The turn unit is ONE MODEL CALL (one step of `generateText` / `streamText`,
|
|
2308
|
+
* or the single call of `generateObject` / `streamObject`), the same unit
|
|
2309
|
+
* wrapOpenAI and the span processor use. A tool loop of N model calls is N
|
|
2310
|
+
* turns: each carries the text of that reply (which may be empty when the
|
|
2311
|
+
* model only requested tools) and the tool names it requested. The outer
|
|
2312
|
+
* `generateText` operation is never a turn.
|
|
2313
|
+
*
|
|
2314
|
+
* Events used (interface `Telemetry` of `ai` 7):
|
|
2315
|
+
* onStart session scope and runtimeContext of the call
|
|
2316
|
+
* onStepStart runtimeContext of the step
|
|
2317
|
+
* onLanguageModelCallStart request instructions and messages
|
|
2318
|
+
* executeLanguageModelCall marks the provider call (see ai-dedupe.ts)
|
|
2319
|
+
* onLanguageModelCallEnd provider response id (see ai-dedupe.ts)
|
|
2320
|
+
* onStepEnd the turn: reply, model, usage, finish, timing
|
|
2321
|
+
* onObjectStepStart / End the same for generateObject / streamObject
|
|
2322
|
+
* onError / onAbort a model call that failed or was aborted
|
|
2323
|
+
* onEnd releases the per-call state
|
|
2324
|
+
* `onStepFinish` is deliberately not implemented: `ai` 7 sends every step
|
|
2325
|
+
* end to both names, and `ai` 6 (which has no `onStepEnd`) is captured
|
|
2326
|
+
* through its OpenTelemetry spans instead (see otel-processor.ts).
|
|
2327
|
+
*
|
|
2328
|
+
* `ai` 3 to 6 are not handled here. `ai` 6 emits `ai.*` OpenTelemetry spans
|
|
2329
|
+
* when a call sets `experimental_telemetry: { isEnabled: true }`; the span
|
|
2330
|
+
* processor maps those.
|
|
2331
|
+
*/
|
|
2332
|
+
|
|
2333
|
+
/** Options for `sightTelemetry()`. */
|
|
2334
|
+
type SightAiTelemetryOptions = {
|
|
2335
|
+
/**
|
|
2336
|
+
* The session the calls this integration sees belong to, for a call made
|
|
2337
|
+
* outside any Sight.withSession() scope. An explicit scope wins.
|
|
2338
|
+
*/
|
|
2339
|
+
sessionId?: string;
|
|
2340
|
+
};
|
|
2341
|
+
/**
|
|
2342
|
+
* The Sight telemetry integration for the Vercel AI SDK (`ai` 7). It is
|
|
2343
|
+
* structurally a `Telemetry` from `ai`: pass it to `registerTelemetry()` or
|
|
2344
|
+
* to a call's `telemetry.integrations`.
|
|
2345
|
+
*/
|
|
2346
|
+
type SightAiTelemetry = {
|
|
2347
|
+
readonly name: 'sight';
|
|
2348
|
+
onStart(event: unknown): void;
|
|
2349
|
+
onStepStart(event: unknown): void;
|
|
2350
|
+
onLanguageModelCallStart(event: unknown): void;
|
|
2351
|
+
onLanguageModelCallEnd(event: unknown): void;
|
|
2352
|
+
onStepEnd(event: unknown): void;
|
|
2353
|
+
onObjectStepStart(event: unknown): void;
|
|
2354
|
+
onObjectStepEnd(event: unknown): void;
|
|
2355
|
+
onEnd(event: unknown): void;
|
|
2356
|
+
onAbort(event: unknown): void;
|
|
2357
|
+
onError(event: unknown): void;
|
|
2358
|
+
executeLanguageModelCall<T>(options: {
|
|
2359
|
+
execute: () => PromiseLike<T>;
|
|
2360
|
+
}): PromiseLike<T>;
|
|
2361
|
+
};
|
|
2362
|
+
/**
|
|
2363
|
+
* The Sight telemetry integration for the Vercel AI SDK (`ai` 7).
|
|
2364
|
+
*
|
|
2365
|
+
* Sight.init() registers it when `ai` is resolvable. Call this yourself when
|
|
2366
|
+
* that cannot work (a bundle where the SDK cannot resolve the host's `ai`):
|
|
2367
|
+
*
|
|
2368
|
+
* import { registerTelemetry } from 'ai';
|
|
2369
|
+
* import { sightTelemetry } from '@cultured_computer/sight';
|
|
2370
|
+
* registerTelemetry(sightTelemetry());
|
|
2371
|
+
*
|
|
2372
|
+
* or per call, with the session the call belongs to:
|
|
2373
|
+
*
|
|
2374
|
+
* generateText({ model, prompt,
|
|
2375
|
+
* telemetry: { integrations: sightTelemetry({ sessionId }) } });
|
|
2376
|
+
*
|
|
2377
|
+
* With no options it returns one shared instance, so Sight.init() does not
|
|
2378
|
+
* register it a second time. Safe to call before Sight.init(): nothing is
|
|
2379
|
+
* captured until init runs.
|
|
2380
|
+
*/
|
|
2381
|
+
declare function sightTelemetry(options?: SightAiTelemetryOptions): SightAiTelemetry;
|
|
2382
|
+
|
|
2383
|
+
export { type AlignmentProvenance, type CaptureTurnInput, type CapturedTurn, type EnvironmentEventInput, type OutcomeEventEmit, type OutcomeHook, type OutcomeResult, type PersonaConfig, Probe, type ProbeConfig, type ProbeConfigInput, SPAN_INTERVAL_KINDS, SPAN_PAYLOAD_STATES, SPAN_STATUSES, SPAN_TYPES, SPAN_V2_STATUSES, Probe as Sight, type SightAiTelemetry, type SightAiTelemetryOptions, type AlignmentProvenance as SightAlignmentProvenance, type CaptureTurnInput as SightCaptureTurnInput, type CapturedTurn as SightCapturedTurn, type ProbeConfig as SightConfig, type ProbeConfigInput as SightConfigInput, type EnvironmentEventInput as SightEnvironmentEventInput, type OutcomeEventEmit as SightOutcomeEventEmit, type OutcomeHook as SightOutcomeHook, type OutcomeResult as SightOutcomeResult, type PersonaConfig as SightPersonaConfig, type SpanInput as SightSpanInput, type SpanInputV2 as SightSpanInputV2, type SpansBatch as SightSpansBatch, type SpanInput, SpanInputSchema, type SpanInputV1, SpanInputV1Schema, type SpanInputV2, SpanInputV2Schema, type SpanInterval, type SpanIntervalKind, SpanIntervalSchema, type SpanPayload, SpanPayloadSchema, type SpanPayloadState, type SpanStatus, type SpanType, type SpansBatch, SpansBatchSchema, sightTelemetry, wrapOpenAI };
|