@cultured_computer/sight 0.8.0 → 0.8.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/dist/index.d.ts CHANGED
@@ -1226,17 +1226,18 @@ type SpansBatch = z.infer<typeof SpansBatchSchema>;
1226
1226
  */
1227
1227
 
1228
1228
  declare const PersonaConfigSchema: z.ZodObject<{
1229
- /** Persona slug matching the deployment's registered persona. */
1229
+ /** The persona's slug. */
1230
1230
  slug: z.ZodString;
1231
1231
  /**
1232
- * RICE authorship artifact (Role, Identity, Communication, Engagement).
1233
- * Either inline object or a path/URL to a JSON file loaded at init time.
1232
+ * The persona's description (role, identity, communication, engagement):
1233
+ * an object, or a string reference to one. Optional. This SDK does not
1234
+ * read or send it.
1234
1235
  */
1235
1236
  rice: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodString]>>;
1236
1237
  /**
1237
- * Customer-authored signature phrases for this persona. Compiled once at
1238
- * init and matched per turn at the SDK edge; matched slugs appear on the
1239
- * outgoing turn as `signaturePhraseMatches`.
1238
+ * Signature phrases for this persona. Compiled once and matched against
1239
+ * each reply in the SDK; matched slugs are sent with the turn as
1240
+ * `signaturePhraseMatches`.
1240
1241
  */
1241
1242
  signaturePhrases: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodObject<{
1242
1243
  slug: z.ZodString;
@@ -1298,11 +1299,10 @@ declare const OutcomeHookSchema: z.ZodObject<{
1298
1299
  /** Type of outcome the deployment tracks. */
1299
1300
  type: z.ZodEnum<["numeric", "categorical", "boolean", "duration"]>;
1300
1301
  /**
1301
- * Callback that resolves the outcome for a completed session. Invoked by
1302
- * Sight.endSession() with the session's externalId; a non-null result
1303
- * lands as an outcome event on the session. Not invoked for sessions
1304
- * swept server-side (no explicit endSession) — use emitOutcomeEvent()
1305
- * for outcomes that become known out of band.
1302
+ * Resolves the outcome of a finished session. Called by
1303
+ * Sight.endSession() with the session's externalId; a non-null result is
1304
+ * sent as an outcome event on the session. Not called for a session you
1305
+ * never end; use emitOutcomeEvent() for an outcome known later.
1306
1306
  */
1307
1307
  resolve: z.ZodType<(sessionId: string) => Promise<OutcomeResult | null>, z.ZodTypeDef, (sessionId: string) => Promise<OutcomeResult | null>>;
1308
1308
  }, "strip", z.ZodTypeAny, {
@@ -1319,33 +1319,32 @@ type OutcomeResult = {
1319
1319
  value: string;
1320
1320
  };
1321
1321
  declare const ProbeConfigSchema: z.ZodObject<{
1322
- /** The project's API key (an ingest key from the dashboard). Required. */
1322
+ /** The project's API key: a key with the `ingest` capability. Required. */
1323
1323
  apiKey: z.ZodString;
1324
1324
  /** Deployment slug: the configuration this traffic belongs to. Required. */
1325
1325
  deployment: z.ZodString;
1326
- /** Ingest endpoint. Defaults to the production ingest service,
1327
- `https://fieldwork-ingest.fly.dev`. */
1326
+ /** The API host the captures are sent to. Defaults to
1327
+ `https://api.cultured.computer`. */
1328
1328
  endpoint: z.ZodDefault<z.ZodString>;
1329
1329
  /**
1330
- * Dashboard base URL used by the one-time first-capture announcement
1331
- * (the stderr permalink printed after the first successful send).
1332
- * Self-hosted or staging dashboards override it the same way `endpoint`
1333
- * is overridden.
1330
+ * Dashboard base URL for the link printed on stderr after the first
1331
+ * accepted turn. Set it only for a self-hosted or staging dashboard.
1334
1332
  */
1335
1333
  dashboardUrl: z.ZodDefault<z.ZodString>;
1336
1334
  /** Persona identification. Optional at init; can be set later via identifyPersona(). */
1337
1335
  persona: z.ZodOptional<z.ZodObject<{
1338
- /** Persona slug matching the deployment's registered persona. */
1336
+ /** The persona's slug. */
1339
1337
  slug: z.ZodString;
1340
1338
  /**
1341
- * RICE authorship artifact (Role, Identity, Communication, Engagement).
1342
- * Either inline object or a path/URL to a JSON file loaded at init time.
1339
+ * The persona's description (role, identity, communication, engagement):
1340
+ * an object, or a string reference to one. Optional. This SDK does not
1341
+ * read or send it.
1343
1342
  */
1344
1343
  rice: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodString]>>;
1345
1344
  /**
1346
- * Customer-authored signature phrases for this persona. Compiled once at
1347
- * init and matched per turn at the SDK edge; matched slugs appear on the
1348
- * outgoing turn as `signaturePhraseMatches`.
1345
+ * Signature phrases for this persona. Compiled once and matched against
1346
+ * each reply in the SDK; matched slugs are sent with the turn as
1347
+ * `signaturePhraseMatches`.
1349
1348
  */
1350
1349
  signaturePhrases: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodObject<{
1351
1350
  slug: z.ZodString;
@@ -1407,11 +1406,10 @@ declare const ProbeConfigSchema: z.ZodObject<{
1407
1406
  /** Type of outcome the deployment tracks. */
1408
1407
  type: z.ZodEnum<["numeric", "categorical", "boolean", "duration"]>;
1409
1408
  /**
1410
- * Callback that resolves the outcome for a completed session. Invoked by
1411
- * Sight.endSession() with the session's externalId; a non-null result
1412
- * lands as an outcome event on the session. Not invoked for sessions
1413
- * swept server-side (no explicit endSession) — use emitOutcomeEvent()
1414
- * for outcomes that become known out of band.
1409
+ * Resolves the outcome of a finished session. Called by
1410
+ * Sight.endSession() with the session's externalId; a non-null result is
1411
+ * sent as an outcome event on the session. Not called for a session you
1412
+ * never end; use emitOutcomeEvent() for an outcome known later.
1415
1413
  */
1416
1414
  resolve: z.ZodType<(sessionId: string) => Promise<OutcomeResult | null>, z.ZodTypeDef, (sessionId: string) => Promise<OutcomeResult | null>>;
1417
1415
  }, "strip", z.ZodTypeAny, {
@@ -1422,19 +1420,20 @@ declare const ProbeConfigSchema: z.ZodObject<{
1422
1420
  resolve: (sessionId: string) => Promise<OutcomeResult | null>;
1423
1421
  }>>;
1424
1422
  /**
1425
- * Sample rate for autocapture. 1.0 = 100% of calls captured. Lower values
1426
- * sample deterministically so a given (turnId) always resolves identically.
1423
+ * Share of turns sent, from 0 to 1. Default 1.0: every turn. Below 1.0
1424
+ * the choice is deterministic per (session id, turn index). Applies to
1425
+ * autocapture and to captureTurn.
1427
1426
  */
1428
1427
  sampleRate: z.ZodDefault<z.ZodNumber>;
1429
1428
  /**
1430
- * Debug mode: log every captured turn to stderr with a prefix. Never logs
1431
- * the Bearer token or PII.
1429
+ * Debug mode: log every send and every failed send to stderr, prefixed
1430
+ * `[sight]`. Never logs the API key or conversation text.
1432
1431
  */
1433
1432
  debug: z.ZodDefault<z.ZodBoolean>;
1434
1433
  }, "strip", z.ZodTypeAny, {
1434
+ endpoint: string;
1435
1435
  apiKey: string;
1436
1436
  deployment: string;
1437
- endpoint: string;
1438
1437
  dashboardUrl: string;
1439
1438
  sampleRate: number;
1440
1439
  debug: boolean;
@@ -1484,23 +1483,19 @@ declare const ProbeConfigSchema: z.ZodObject<{
1484
1483
  }>;
1485
1484
  type ProbeConfig = z.infer<typeof ProbeConfigSchema>;
1486
1485
  /**
1487
- * The shape callers pass to Sight.init(). This is the schema's INPUT type, so
1488
- * fields with a `.default()` (endpoint, sampleRate, debug) are optional here —
1489
- * the defaults are applied by ProbeConfigSchema.parse() inside init(). Use this
1490
- * for the init argument; `ProbeConfig` is the resolved (post-parse) type held
1491
- * internally, where those fields are always present.
1486
+ * The argument of Sight.init(). Fields with a default (endpoint,
1487
+ * dashboardUrl, sampleRate, debug) are optional here. `ProbeConfig` is the
1488
+ * same configuration after init has applied the defaults.
1492
1489
  */
1493
1490
  type ProbeConfigInput = z.input<typeof ProbeConfigSchema>;
1494
1491
  declare const SessionStartSchema: z.ZodObject<{
1495
- /** Customer's session identity (opaque string; used as the correlation key). */
1492
+ /** Your id for the session: one conversation. Any non-empty string. */
1496
1493
  externalId: z.ZodString;
1497
1494
  /**
1498
- * Customer's USER identity (opaque string), distinct from externalId:
1499
- * externalId keys the session; externalUserId ties sessions to a
1500
- * returning user. Forwarded on every captured turn so the worker can
1501
- * persist it on the session row — return-with-persona-consistency and
1502
- * prior-session metrics require it. Optional; deployments that do not
1503
- * identify users simply skip the user-level return metrics.
1495
+ * Your id for the person: a stable, pseudonymous string, distinct from
1496
+ * externalId. It ties one person's sessions together and is sent with
1497
+ * every captured turn. Optional; without it, sessions are still captured
1498
+ * and nothing links them to a returning person.
1504
1499
  */
1505
1500
  externalUserId: z.ZodOptional<z.ZodString>;
1506
1501
  /**
@@ -1509,30 +1504,26 @@ declare const SessionStartSchema: z.ZodObject<{
1509
1504
  * deployments where init already carries the persona.
1510
1505
  */
1511
1506
  persona: z.ZodOptional<z.ZodString>;
1512
- /**
1513
- * How the user got into this session.
1514
- * Retention semantics differ radically between a resume and a fresh
1515
- * notification landing.
1516
- */
1507
+ /** How the person arrived in this session. */
1517
1508
  openedVia: z.ZodOptional<z.ZodEnum<["link", "notification", "resume", "direct", "share"]>>;
1518
1509
  /**
1519
- * Environmental context: browser / device / locale / tz. You choose
1520
- * which fields to include. See the collectClientContext helper.
1510
+ * Client context: locale, timezone, runtime, and anything else you
1511
+ * choose to include. Stored as sent. See startSessionWithContext.
1521
1512
  */
1522
1513
  clientContext: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1523
1514
  /**
1524
- * Optional customer metadata attached to the session. Forwarded with the
1525
- * first captured turn merged into `clientContext` under the `metadata`
1526
- * key, so it is stored with the session.
1515
+ * Your own metadata for the session. Sent with the first captured turn,
1516
+ * inside `clientContext` under the `metadata` key, and stored as sent.
1527
1517
  */
1528
1518
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1529
1519
  /**
1530
- * RLDS episode-level provenance. Powers the version behavioral diff
1531
- * on the dashboard. All optional.
1532
- * agentId — model/policy version
1533
- * experimentId — A/B arm or feature flag
1534
- * environmentConfigHash — SHA of prompt/config file(s)
1535
- * environmentConfigLabel — human-readable version label
1520
+ * Version tags for the session, used to compare versions on the
1521
+ * dashboard. All optional.
1522
+ * agentId model or policy version
1523
+ * experimentId A/B arm or feature flag
1524
+ * environmentConfigHash hash of the prompt or configuration
1525
+ * (see Sight.hashEnvironmentConfig)
1526
+ * environmentConfigLabel readable name for that version
1536
1527
  */
1537
1528
  agentId: z.ZodOptional<z.ZodString>;
1538
1529
  experimentId: z.ZodOptional<z.ZodString>;
@@ -1563,12 +1554,9 @@ declare const SessionStartSchema: z.ZodObject<{
1563
1554
  }>;
1564
1555
  type SessionStart = z.infer<typeof SessionStartSchema>;
1565
1556
  /**
1566
- * Session end input. Sent by Sight.endSession() so the worker records
1567
- * why a session ended. `outcome` + `outcomeDetail` are the one-call
1568
- * outcome helper: when the deployer knows the outcome at close (a
1569
- * resolved ticket, an escalation, an abandonment), the SDK emits it as an
1570
- * outcome event alongside the session end — it never rides the
1571
- * session-end wire itself.
1557
+ * The argument of Sight.endSession(): why the session ended. When you know
1558
+ * the outcome at close (a resolved ticket, an escalation), pass `outcome`
1559
+ * and optional `outcomeDetail`; the SDK sends it as an outcome event.
1572
1560
  */
1573
1561
  declare const SessionEndSchema: z.ZodObject<{
1574
1562
  externalId: z.ZodString;
@@ -1591,17 +1579,13 @@ type CapturedTurn = {
1591
1579
  deploymentSlug: string;
1592
1580
  sessionExternalId: string;
1593
1581
  /**
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.
1582
+ * The version of the turn format this SDK sends. Set by the SDK on every
1583
+ * captured turn; a value you supply is replaced.
1598
1584
  */
1599
1585
  envelopeVersion?: string;
1600
1586
  /**
1601
- * Customer's user identity. Forwarded by captureTurn from the session
1602
- * state (Sight.startSession({ externalUserId })); the worker persists it
1603
- * on sessions.external_user_id at first-turn session create. Never
1604
- * defaulted to sessionExternalId — that key identifies the session.
1587
+ * Your id for the person. Filled from Sight.startSession({
1588
+ * externalUserId }) when omitted. Never defaults to sessionExternalId.
1605
1589
  */
1606
1590
  externalUserId?: string;
1607
1591
  turnIndex: number;
@@ -1615,20 +1599,19 @@ type CapturedTurn = {
1615
1599
  */
1616
1600
  turnId?: string;
1617
1601
  /**
1618
- * Persona slug active for this turn. Resolved by the SDK from (in order):
1619
- * turn-level override, session-level from startSession(), init-level default.
1602
+ * Persona slug for this turn. When omitted: the session's persona from
1603
+ * startSession(), then the default from init.
1620
1604
  */
1621
1605
  personaSlug?: string;
1622
1606
  /**
1623
- * Signature-phrase slugs matched at the SDK edge (computed from the
1624
- * customer's signaturePhrases config at init). Empty array or omitted when
1625
- * no signatures matched or none were registered.
1607
+ * Slugs of the persona's signature phrases found in the reply. Computed
1608
+ * by the SDK when omitted. Empty or absent when none matched or none are
1609
+ * registered.
1626
1610
  */
1627
1611
  signaturePhraseMatches?: string[];
1628
1612
  /**
1629
- * Interpretive record fields passed through from a customer harness
1630
- * (read hook wired). Populated only if the customer
1631
- * runs the Cultured Computer harness pattern; null for non-harness deployments.
1613
+ * Optional fields from your own decision layer, sent as given: how it
1614
+ * classified the situation and what it chose. Autocapture never sets it.
1632
1615
  */
1633
1616
  interpretive?: {
1634
1617
  situationType?: string[];
@@ -1651,7 +1634,8 @@ type CapturedTurn = {
1651
1634
  submittedAt?: string;
1652
1635
  };
1653
1636
  /**
1654
- * Interactivity: agent reflect time, stream completion, multimodal events.
1637
+ * Timing of the reply: time from the person's submit to the captured
1638
+ * turn, whether the stream completed, multimodal events.
1655
1639
  */
1656
1640
  interactivity?: {
1657
1641
  agentReflectMs?: number;
@@ -1663,12 +1647,10 @@ type CapturedTurn = {
1663
1647
  }>;
1664
1648
  };
1665
1649
  /**
1666
- * User outcome signals:
1667
- * flagged break, explicit rating (1-5), thumbs.
1650
+ * The person's feedback on the turn: rating (1 to 5), thumbs.
1668
1651
  *
1669
- * `flaggedBreak` is DEPRECATED in favor of Sight.flagPersonaBreak(),
1670
- * which carries user attribution and emits a 'break' outcome event;
1671
- * the turn-level boolean remains accepted for wire compat only.
1652
+ * `flaggedBreak` is deprecated: use Sight.flagPersonaBreak(), which
1653
+ * records an outcome event. The boolean is still accepted.
1672
1654
  */
1673
1655
  userOutcome?: {
1674
1656
  flaggedBreak?: boolean;
@@ -1676,36 +1658,30 @@ type CapturedTurn = {
1676
1658
  thumbs?: "up" | "down";
1677
1659
  };
1678
1660
  /**
1679
- * Propensity + candidate set (harness-supplied).
1680
- * Manual-capture callers put this in payload.propensity; captureTurn
1681
- * validates the contract and hoists the valid object to
1682
- * this top-level field so the worker projection lands it on the
1683
- * read_candidates / read_propensities / selection_meta columns.
1661
+ * The candidate replies and the probability of each, when your system
1662
+ * chooses among candidates. Supply it here or in payload.propensity;
1663
+ * captureTurn checks it and sends a valid one. An invalid one logs one
1664
+ * warning and is removed; the turn is still sent.
1684
1665
  */
1685
1666
  propensity?: PropensityInput;
1686
1667
  /**
1687
- * Transition signals (the human's response to the previous reply).
1688
- * Derived by captureTurn when the previous turn's capture time and this
1689
- * turn's user submit time are both known; may also be supplied directly
1690
- * by manual-capture callers.
1668
+ * The person's response to the previous reply: the time from that reply
1669
+ * to this turn's submit. Derived by the SDK when both times are known;
1670
+ * you may also supply it.
1691
1671
  */
1692
1672
  transition?: {
1693
1673
  timeMs?: number;
1694
1674
  lengthDelta?: number;
1695
1675
  };
1696
1676
  /**
1697
- * Session context forwarded on the FIRST captured turn of a session
1698
- * (populated by captureTurn from Sight.startSession state; the worker
1699
- * persists both at session find-or-create). Omitted on later turns.
1677
+ * Session context from Sight.startSession, sent on the first captured
1678
+ * turn of a session and omitted on later turns.
1700
1679
  */
1701
1680
  openedVia?: "link" | "notification" | "resume" | "direct" | "share";
1702
1681
  clientContext?: Record<string, unknown>;
1703
1682
  /**
1704
- * RLDS episode-level provenance. Forwarded from the session
1705
- * state on every turn so downstream storage can attribute each turn to the
1706
- * arm/version that produced it. Populated by startSession() from either
1707
- * the customer-provided value or the init-time default; null when neither
1708
- * is set.
1683
+ * Version tags from Sight.startSession, sent on every turn so each turn
1684
+ * is attributed to the version that produced it. Absent when not set.
1709
1685
  */
1710
1686
  agentId?: string;
1711
1687
  experimentId?: string;
@@ -1739,9 +1715,9 @@ type FlagPersonaBreakInput = z.infer<typeof FlagPersonaBreakSchema>;
1739
1715
  declare const OutcomeEventEmitSchema: z.ZodObject<{
1740
1716
  sessionExternalId: z.ZodString;
1741
1717
  kind: z.ZodString;
1742
- /** Optional turn index this event is caused by. Omit to attach to latest turn. */
1718
+ /** The turn that caused the outcome. Omit to attach to the latest turn. */
1743
1719
  causingTurnIndex: z.ZodOptional<z.ZodNumber>;
1744
- /** Optional detail payload (customer-defined). */
1720
+ /** Your own detail for the outcome. Optional. */
1745
1721
  detail: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1746
1722
  }, "strip", z.ZodTypeAny, {
1747
1723
  kind: string;
@@ -1757,18 +1733,21 @@ declare const OutcomeEventEmitSchema: z.ZodObject<{
1757
1733
  type OutcomeEventEmit = z.infer<typeof OutcomeEventEmitSchema>;
1758
1734
 
1759
1735
  /**
1760
- * HTTP client for the Sight ingest API.
1736
+ * HTTP client for the Sight API. Internal; use the `Sight` methods.
1761
1737
  *
1762
- * Sends captured turns to POST /v1/turns with a Bearer token. Async, fire-and-log:
1763
- * SDK never blocks the customer's LLM path on ingest. Rate-limited sends (429)
1764
- * are retried exactly once after Retry-After; sustained limiting drops captures.
1738
+ * Sends captured turns to POST /v1/turns with a Bearer token. A failed send
1739
+ * is logged with `debug: true` and never thrown. The first send the API
1740
+ * rejects (a 4xx other than 429) prints one warning without `debug`, once
1741
+ * per process for each of: 401, 403, any other status. A rate-limited send
1742
+ * (429) is retried once after Retry-After; if the retry is limited too,
1743
+ * that capture is dropped.
1765
1744
  */
1766
1745
 
1767
1746
  type IngestClientOptions = {
1768
1747
  apiKey: string;
1769
1748
  endpoint: string;
1770
1749
  debug: boolean;
1771
- /** Dashboard base URL for the one-time first-capture announcement. */
1750
+ /** Dashboard base URL for the link printed after the first accepted turn. */
1772
1751
  dashboardUrl?: string;
1773
1752
  };
1774
1753
  declare class IngestClient {
@@ -1777,87 +1756,89 @@ declare class IngestClient {
1777
1756
  private debug;
1778
1757
  private dashboardUrl;
1779
1758
  /**
1780
- * First-trace permalink: the first
1781
- * SUCCESSFUL sendTurn prints one stderr line with a dashboard permalink,
1782
- * then never again for the life of this client (one IngestClient per
1783
- * process — one `init` per process; a restart prints once more, accepted).
1784
- * Failed sends do not consume the announcement. Only sendTurn announces:
1785
- * flags, outcome events, and session-end sends never trigger it (a flag
1786
- * arriving before any turn is not a captured session).
1759
+ * The first accepted turn prints one stderr line with a link to the
1760
+ * session on the dashboard, once per client (one client per init). A
1761
+ * failed send does not use it up. Only turns print it; flags, outcome
1762
+ * events and session ends do not.
1787
1763
  */
1788
1764
  private firstCaptureAnnounced;
1789
1765
  /**
1790
- * Rate-limit (429) handling: the first 429 per process prints one stderr
1791
- * warning (not debug-gated, same channel and lifetime as the first-capture
1792
- * announce); subsequent 429s only debug-log. Each rate-limited request is
1793
- * retried exactly once after Retry-After; pendingRetries counts retries
1794
- * waiting on their timers so the cap can shed load.
1766
+ * Rate limiting (429): the first 429 prints one stderr warning, with or
1767
+ * without `debug`; later ones log only with `debug: true`. Each
1768
+ * rate-limited request is retried once after Retry-After. At most 50
1769
+ * retries wait at a time; past that, a rate-limited request is dropped.
1795
1770
  */
1796
1771
  private rateLimitAnnounced;
1797
1772
  private pendingRetries;
1773
+ /**
1774
+ * Rejected sends (a 4xx other than 429): the first one of each class
1775
+ * (401, 403, any other status) prints one stderr warning, with or
1776
+ * without `debug`. A rejected send is never retried: the same key and
1777
+ * the same body get the same answer.
1778
+ */
1779
+ private rejectionAnnounced;
1798
1780
  private inFlight;
1799
1781
  private shedAnnounced;
1800
1782
  /**
1801
- * Every network send goes through here: adds the per-send timeout and
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;
1804
- * the first shed per process warns on stderr, the rest debug-log.
1783
+ * Every send goes through here: a 15 second timeout per send and at most
1784
+ * 64 sends in flight. Past that, a new send is dropped, not queued; the
1785
+ * first drop prints one stderr warning, later ones log only with
1786
+ * `debug: true`.
1805
1787
  */
1806
1788
  private guardedFetch;
1807
1789
  /**
1808
- * Await all in-flight sends (bounded). Called by Sight.shutdown() so
1809
- * short-lived processes (serverless, CLI scripts) can actually exit after
1810
- * it — the documented "in-flight sends finish within 15s" only holds while
1811
- * the process lives. Polling is coarse on purpose: sends report through
1812
- * guardedFetch's counter and scheduled retries, never awaited individually.
1813
- * Retries beyond the drain budget remain best-effort, not durable delivery.
1790
+ * Wait for sends in flight and pending retries, for at most `timeoutMs`
1791
+ * (default 15 seconds). Called by Sight.shutdown() so a short-lived
1792
+ * process can exit without losing a send. A retry still waiting when
1793
+ * the time is up is not guaranteed to be sent.
1814
1794
  */
1815
1795
  drainInFlight(timeoutMs?: number): Promise<void>;
1816
1796
  constructor(opts: IngestClientOptions);
1817
1797
  /**
1818
- * Send a turn to the ingest API. Fire-and-log: errors are logged but never
1819
- * thrown. The customer's LLM path never blocks on capture.
1798
+ * Send a turn. Errors are logged with `debug: true`, never thrown.
1820
1799
  */
1821
1800
  sendTurn(turn: CapturedTurn): Promise<void>;
1822
1801
  /**
1823
- * Send a persona-break flag to the ingest API. Fire-and-log, same as sendTurn.
1824
- * Populates the `user_flagged_break` outcome column on the dashboard.
1802
+ * Send a persona-break flag. Errors are logged with `debug: true`, never
1803
+ * thrown.
1825
1804
  */
1826
1805
  sendFlag(deploymentSlug: string, flag: FlagPersonaBreakInput): Promise<void>;
1827
1806
  /**
1828
- * Send a session-end event to the ingest API. Records why a session ended
1829
- * on the session. Fire-and-log.
1807
+ * Send a session end: why the session ended. Errors are logged with
1808
+ * `debug: true`, never thrown.
1830
1809
  */
1831
1810
  sendSessionEnd(deploymentSlug: string, end: SessionEndInput): Promise<void>;
1832
1811
  /**
1833
- * Send an outcome event to the ingest API. Fire-and-log. Populates
1834
- * the outcome-events store.
1812
+ * Send an outcome event. Errors are logged with `debug: true`, never
1813
+ * thrown.
1835
1814
  */
1836
1815
  sendOutcomeEvent(deploymentSlug: string, event: OutcomeEventEmit): Promise<void>;
1837
1816
  /**
1838
- * Send an environment-event batch to the ingest API. Fire-and-log, same as
1839
- * sendTurn. The envelope is generalized: the worker attaches each event to
1840
- * its session's record by time; meaning is per-deployment.
1817
+ * Send a batch of environment events. Errors are logged with
1818
+ * `debug: true`, never thrown.
1841
1819
  */
1842
1820
  sendEnvironmentEvents(batch: EnvironmentEventsBatch): Promise<void>;
1843
1821
  /**
1844
- * Send a span batch to the ingest API. Fire-and-log, same as sendTurn.
1845
- * Spans carry sub-turn structure (llm_call / tool_call / framework_step /
1846
- * custom); the worker resolves each span's session/turn and wires in-batch
1847
- * parent references.
1822
+ * Send a batch of spans. Errors are logged with `debug: true`, never
1823
+ * thrown.
1848
1824
  */
1849
1825
  sendSpans(batch: SpansBatch): Promise<void>;
1850
1826
  /**
1851
- * Route a send response through the 429 retry policy. Non-429 responses
1852
- * pass through untouched. A 429 is re-sent exactly once after Retry-After
1853
- * seconds (default 1s when the header is missing or unparseable; clamped
1854
- * to [1, 60]s); the retry's response is returned as-is, so a second 429 is
1855
- * never retried again — callers log and drop it like any other failed
1856
- * send. Returns null when the retry was dropped at the pending-retry cap.
1857
- * The timer is unref'd (where supported) so a pending retry never holds
1858
- * the process open.
1827
+ * The 429 retry rule. Any other response passes through. A 429 is sent
1828
+ * again once after Retry-After seconds (1 second when the header is
1829
+ * missing or unreadable; kept between 1 and 60 seconds). The retry's
1830
+ * response is returned as is, so a second 429 is not retried. Returns
1831
+ * null when the retry was dropped because 50 retries were already
1832
+ * waiting. A waiting retry does not keep the process alive.
1859
1833
  */
1860
1834
  private retryIfRateLimited;
1835
+ /**
1836
+ * The once-per-class warning for a send the API rejected. Not gated on
1837
+ * debug: a rejected key drops every capture, so the host is told once.
1838
+ * 429 has its own warning (see retryIfRateLimited); a 5xx is the API's
1839
+ * failure, not the host's, and stays a debug line.
1840
+ */
1841
+ private announceRejection;
1861
1842
  private log;
1862
1843
  }
1863
1844
 
@@ -1865,8 +1846,8 @@ declare class IngestClient {
1865
1846
  * Client-context capture helper.
1866
1847
  *
1867
1848
  * At session start the SDK optionally collects browser/device/locale/tz
1868
- * metadata to send as SessionStart.clientContext. Customers control which
1869
- * fields land via the `includes` argument; the default is
1849
+ * metadata to send as SessionStart.clientContext. You choose which fields
1850
+ * are sent with the `includes` argument; the default is
1870
1851
  * conservative (locale + timezone + agent kind, no fingerprinting fields).
1871
1852
  *
1872
1853
  * Node-side calls receive process metadata; browser-side calls receive
@@ -1874,17 +1855,17 @@ declare class IngestClient {
1874
1855
  * fingerprint the user is opt-in.
1875
1856
  */
1876
1857
  type ClientContextIncludes = {
1877
- /** window.navigator.userAgent — off by default (fingerprinting risk). */
1858
+ /** window.navigator.userAgent. Off by default (fingerprinting risk). */
1878
1859
  userAgent?: boolean;
1879
- /** window.navigator.language / process.env.LANG — on by default. */
1860
+ /** window.navigator.language / process.env.LANG. On by default. */
1880
1861
  locale?: boolean;
1881
- /** Intl timezone / process TZ — on by default. */
1862
+ /** Intl timezone / process TZ. On by default. */
1882
1863
  timezone?: boolean;
1883
- /** window.screen dimensions — off by default (fingerprinting risk). */
1864
+ /** window.screen dimensions. Off by default (fingerprinting risk). */
1884
1865
  screen?: boolean;
1885
- /** Node process metadata (platform, node version) — on by default in Node. */
1866
+ /** Node process metadata (platform, node version). On by default in Node. */
1886
1867
  runtime?: boolean;
1887
- /** Custom key/value pairs the customer wants to attach. */
1868
+ /** Your own key/value pairs to attach. */
1888
1869
  custom?: Record<string, string | number | boolean | null>;
1889
1870
  };
1890
1871
 
@@ -1939,10 +1920,10 @@ declare function compileSignaturePhrases(phrases: SignaturePhrase[]): CompiledPh
1939
1920
  *
1940
1921
  * Sight.init({
1941
1922
  * apiKey: process.env.SIGHT_API_KEY!,
1942
- * deployment: 'support-agent',
1923
+ * deployment: 'my-assistant',
1943
1924
  * });
1944
1925
  *
1945
- * // Calls made inside Sight.withSession(id, fn) are captured as turns.
1926
+ * // Model calls made inside Sight.withSession(id, fn) are captured as turns.
1946
1927
  */
1947
1928
 
1948
1929
  type ProbeState = {
@@ -1959,10 +1940,9 @@ type ProbeState = {
1959
1940
  signatureMatchers: Map<string, ReturnType<typeof compileSignaturePhrases>>;
1960
1941
  /**
1961
1942
  * Interaction signals (userInputStart/Edit/Submit, userThumbs/userRating)
1962
- * that arrived BEFORE any session entry existed for their externalId.
1963
- * Flushed into the session entry when it is created (startSession or
1964
- * lazy-create at captureTurn). FIFO-capped at PRE_SESSION_BUFFER_MAX ids
1965
- * so signals for sessions that never capture a turn cannot leak memory.
1943
+ * recorded before any session entry existed for their externalId. Moved
1944
+ * into the session entry when it is created (startSession, or the first
1945
+ * captured turn). Holds at most 100 session ids; the oldest is dropped.
1966
1946
  */
1967
1947
  preSessionBuffer: Map<string, PreSessionSignals>;
1968
1948
  };
@@ -1974,7 +1954,7 @@ type PreSessionSignals = {
1974
1954
 
1975
1955
  type SessionState = {
1976
1956
  externalId: string;
1977
- /** Customer's user identity from startSession; forwarded on every turn. */
1957
+ /** Your user id from startSession; sent with every turn. */
1978
1958
  externalUserId: string | null;
1979
1959
  turnIndex: number;
1980
1960
  startedAt: number;
@@ -1987,32 +1967,32 @@ type SessionState = {
1987
1967
  environmentConfigHash: string | null;
1988
1968
  environmentConfigLabel: string | null;
1989
1969
  /**
1990
- * Timestamp of the last captured agent turn. Used on the NEXT turn to
1991
- * derive transition.timeMs (previous agent reply → this turn's user
1992
- * submit) and firstKeystrokeMs (previous agent reply → typing start).
1970
+ * Time of the last captured turn. Used on the next turn to derive
1971
+ * transition.timeMs (previous reply to this turn's submit) and
1972
+ * firstKeystrokeMs (previous reply to typing start).
1993
1973
  */
1994
1974
  lastAgentTurnAt: number | null;
1995
1975
  /**
1996
- * Timestamp of the last userInputSubmit. Used at captureTurn to derive
1997
- * agentReflectMs (user submit → agent turn capture). transition.timeMs
1998
- * derives from the per-turn pendingUserInput.submittedAt instead, which
1999
- * resets on every capture, so stale submits are never reused for it.
1976
+ * Time of the last userInputSubmit. Used when a turn is captured to
1977
+ * derive agentReflectMs (submit to capture). transition.timeMs uses the
1978
+ * per-turn pendingUserInput.submittedAt instead, which resets on every
1979
+ * capture, so an earlier submit is never reused for it.
2000
1980
  */
2001
1981
  lastUserSubmitAt: number | null;
2002
1982
  /**
2003
1983
  * True once openedVia/clientContext have been sent with a captured turn.
2004
- * The worker persists session context at session find-or-create (first
2005
- * turn that arrives), so the SDK forwards it exactly once.
1984
+ * The server stores session context from the first turn of a session, so
1985
+ * the SDK sends it once.
2006
1986
  */
2007
1987
  sessionContextForwarded: boolean;
2008
- /** Per-turn user input pending on the SDK edge (unified capture helper). */
1988
+ /** The person's input held for the next captured turn. */
2009
1989
  pendingUserInput: {
2010
1990
  text?: string;
2011
1991
  firstKeystrokeMs?: number;
2012
1992
  editCount: number;
2013
1993
  submittedAt?: number;
2014
1994
  } | null;
2015
- /** Per-turn user outcome pending on the SDK edge (thumbs / rating). */
1995
+ /** Thumbs or rating held for the next captured turn. */
2016
1996
  pendingUserOutcome: {
2017
1997
  thumbs?: "up" | "down";
2018
1998
  explicitRating?: number;
@@ -2020,39 +2000,40 @@ type SessionState = {
2020
2000
  };
2021
2001
  declare class Probe {
2022
2002
  /**
2023
- * Initialize the SDK. Call once at process start. Subsequent calls are
2024
- * no-ops with a warning; re-init requires a shutdown() first.
2003
+ * Initialize the SDK. Call once at process start. Throws on an invalid
2004
+ * configuration; no other method throws on bad input. A second call
2005
+ * prints one warning and is ignored; call shutdown() first to
2006
+ * re-initialize.
2025
2007
  */
2026
2008
  static init(config: ProbeConfigInput): void;
2027
2009
  /**
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`.
2010
+ * Run a callback inside a session scope. Every model call made inside
2011
+ * `fn` through a wrapped OpenAI client, the Vercel AI SDK or an
2012
+ * instrumented library is captured as a turn on the session `sessionId`
2013
+ * (your conversation id).
2031
2014
  *
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.)
2015
+ * Required for autocapture: a call made outside any session scope is not
2016
+ * captured. The first such call in a process prints one warning; later
2017
+ * ones log only with `debug: true`. Exceptions, used only when there is
2018
+ * no scope: a span that carries `gen_ai.conversation.id`, and an `ai`
2019
+ * call that names its session (see `sightTelemetry`). An explicit scope
2020
+ * always wins.
2037
2021
  *
2038
- * The scope is carried in OpenTelemetry baggage across awaits.
2022
+ * The scope is carried across awaits. Returns what `fn` returns.
2039
2023
  */
2040
2024
  static withSession<T>(sessionId: string, fn: () => T | Promise<T>): Promise<T>;
2041
2025
  /**
2042
- * Identify the process-level default persona. Overwrites any previously-set
2043
- * default. For per-session persona identification (multi-persona products),
2044
- * use startSession({ externalId, persona }) instead.
2026
+ * Set the default persona for the process. Replaces the previous default.
2027
+ * To set a persona per session, use startSession({ externalId, persona }).
2045
2028
  */
2046
2029
  static identifyPersona(persona: PersonaConfig): void;
2047
2030
  /**
2048
- * Start (or update) a session with an active persona.
2049
- *
2050
- * Single-persona deployments can skip this if the init-level default is
2051
- * enough; the SDK will still create a session entry lazily on first turn.
2052
- * Multi-persona products call this at conversation start so every turn in
2053
- * the session inherits the selected persona.
2031
+ * Start (or update) a session. Optional: a session is created on its
2032
+ * first captured turn. Call it to attach `externalUserId` (your stable,
2033
+ * pseudonymous user id), a persona, version tags or client context.
2054
2034
  *
2055
- * Idempotent: calling with the same externalId updates the entry.
2035
+ * Calling it again with the same externalId updates the entry. Invalid
2036
+ * input logs one warning and is ignored.
2056
2037
  */
2057
2038
  static startSession(input: SessionStart): void;
2058
2039
  /**
@@ -2069,44 +2050,36 @@ declare class Probe {
2069
2050
  */
2070
2051
  private static preSessionEntry;
2071
2052
  /**
2072
- * Compute a stable SHA-256 hex hash of prompt/config text for use as
2073
- * `environmentConfigHash` on Sight.startSession(). Hash is *identity*:
2074
- * pass the human-readable version alongside as `environmentConfigLabel`
2075
- * for the diff table axis (a card keyed by a3f9c2… is unreadable).
2053
+ * SHA-256 hex hash of prompt or configuration text, for
2054
+ * `environmentConfigHash` on Sight.startSession(). The hash identifies a
2055
+ * version; pass a readable name alongside as `environmentConfigLabel`.
2076
2056
  *
2077
- * Ships as a helper because inconsistent hashing across restarts breaks
2078
- * The version behavioral diff — every customer would
2079
- * hash their own way and version-diff would become noise.
2080
- *
2081
- * The same hashing (src/hash.ts) backs the OTel processor's automatic
2082
- * version stamping: when autocapture sees a system message and the
2083
- * deployer set no environmentConfigHash, the session is stamped with
2084
- * the system prompt's hash and an 'auto:xxxxxxxx' label. Explicit
2085
- * startSession values always win over the auto stamp.
2057
+ * Autocapture uses the same hash: when it sees a system prompt and the
2058
+ * session has no environmentConfigHash, the session gets the system
2059
+ * prompt's hash and the label 'auto:' plus its first 8 characters.
2060
+ * Values you pass to startSession always win.
2086
2061
  */
2087
2062
  static hashEnvironmentConfig(input: string): Promise<string>;
2088
2063
  /**
2089
- * End a session and release its in-memory entry. Optional (sessions time out
2090
- * eventually), but recommended for long-running processes with many distinct
2091
- * conversations. If `input.endedReason` is provided the SDK sends an end
2092
- * event to ingest so the worker records the reason server-side.
2064
+ * End a session: sends the end reason (`natural` when none is given) and
2065
+ * releases the session's in-memory entry. Optional; a session you never
2066
+ * end times out on the server.
2093
2067
  *
2094
- * Resolve-on-close: if an outcome hook is registered (init `outcomeHook`
2095
- * or wireOutcomeHook()), endSession invokes `hook.resolve(externalId)`
2096
- * and, when it returns a non-null OutcomeResult, lands it as an outcome
2097
- * event (kind = result.outcome, detail carries type/value). This is the
2098
- * ONLY place the SDK invokes the hook — there are no client-side timers,
2099
- * so sessions that are never ended explicitly are swept server-side as
2100
- * `timeout` and receive no hook-resolved outcome; land those via
2101
- * emitOutcomeEvent() from wherever the outcome becomes known. Error-safe:
2102
- * a throwing or rejecting hook never breaks endSession.
2068
+ * - `outcome` (with optional `outcomeDetail`) is sent as an outcome
2069
+ * event before the session end.
2070
+ * - With no `outcome` and an outcome hook registered (init `outcomeHook`
2071
+ * or wireOutcomeHook()), `hook.resolve(externalId)` runs; a non-null
2072
+ * result is sent as an outcome event. This is the only place the hook
2073
+ * runs. A hook that throws logs one warning and does not break
2074
+ * endSession.
2075
+ * - For an outcome known later, or for a session you never end, call
2076
+ * emitOutcomeEvent().
2103
2077
  */
2104
2078
  static endSession(externalId: string | SessionEndInput): Promise<void>;
2105
2079
  /**
2106
- * The person started typing. Records the first-keystroke time, sent as
2107
- * `userInput.firstKeystrokeMs` with the next captured turn. Derivable
2108
- * only once a previous agent turn exists; a pre-session typing start
2109
- * buffers the pending-input entry without a firstKeystrokeMs value.
2080
+ * The person started typing. Records the time since the previous reply,
2081
+ * sent as `userInput.firstKeystrokeMs` with the next captured turn. No
2082
+ * value is sent before the session's first captured turn.
2110
2083
  */
2111
2084
  static userInputStart(externalId: string): void;
2112
2085
  /**
@@ -2116,52 +2089,55 @@ declare class Probe {
2116
2089
  static userInputEdit(externalId: string): void;
2117
2090
  /**
2118
2091
  * 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.
2092
+ * personal data server-side before it is stored) and the submit time.
2093
+ * Both are sent with the next captured turn: a turn's person text is the
2094
+ * message that prompted its reply. Call it before the model call.
2122
2095
  */
2123
2096
  static userInputSubmit(externalId: string, text: string): void;
2124
- /** Attach a thumbs-up/down to the current turn. */
2097
+ /** Record a thumbs-up or thumbs-down. Sent with the next captured turn. */
2125
2098
  static userThumbs(externalId: string, thumbs: "up" | "down"): void;
2126
2099
  /**
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.
2100
+ * Record a rating: an integer from 1 to 5. Sent with the next captured
2101
+ * turn. Any other value logs one warning line and is dropped.
2129
2102
  */
2130
2103
  static userRating(externalId: string, rating: number): void;
2131
2104
  /**
2132
- * Helper: collect client context and pass it to startSession in one call.
2105
+ * startSession, with client context (locale, timezone, runtime) collected
2106
+ * for you unless `input.clientContext` is given.
2133
2107
  */
2134
2108
  static startSessionWithContext(input: SessionStart, includes?: ClientContextIncludes): void;
2135
2109
  /**
2136
- * Register the outcome hook: declares the deployment's outcome type and
2137
- * the resolver for it. The hook's `resolve(sessionExternalId)` is invoked
2138
- * by endSession() — explicit close is the only trigger; the SDK runs no
2139
- * client-side timers. A non-null OutcomeResult lands as an outcome event
2140
- * on the session. Sessions that are never ended explicitly are swept
2141
- * server-side and never resolve through the hook; land those outcomes via
2142
- * emitOutcomeEvent() from the place where the outcome becomes known
2143
- * (webhook, CRM callback); it joins back by sessionExternalId.
2110
+ * Register the outcome hook: the deployment's outcome type and a
2111
+ * resolver for it. `resolve(sessionExternalId)` runs only when you call
2112
+ * endSession() without an `outcome`; the SDK runs no timers. A non-null
2113
+ * result is sent as an outcome event on the session. For a session you
2114
+ * never end, or an outcome known later (webhook, CRM callback), call
2115
+ * emitOutcomeEvent(); it joins to the session by sessionExternalId.
2144
2116
  */
2145
2117
  static wireOutcomeHook(hook: OutcomeHook): void;
2146
2118
  /**
2147
- * Manually capture a turn. For callers that do not use autocapture.
2119
+ * Capture a turn yourself, for a model call autocapture does not see.
2148
2120
  *
2121
+ * - `turnIndex` is the turn's position in the session, starting at 0.
2149
2122
  * - `deploymentSlug` may be omitted: the `deployment` given to `init` is
2150
2123
  * used. An explicit value wins.
2151
2124
  * - Every turn is sent with a `turnId` (a fresh UUID unless you supply
2152
2125
  * one). A retried send carries the same `turnId`.
2153
- * - The turn is validated before it is sent. An invalid turn logs one
2126
+ * - The turn is checked before it is sent. An invalid turn logs one
2154
2127
  * warning line naming the first invalid field and is dropped; nothing
2155
2128
  * is sent.
2129
+ * - A failed send never throws; it logs with `debug: true`. The first
2130
+ * send the API rejects (401, 403, another 4xx) prints one warning
2131
+ * without it.
2156
2132
  *
2157
- * Persona resolution order for the outgoing turn payload:
2158
- * 1. turn.personaSlug (turn-level override)
2133
+ * Persona used for the turn, in this order:
2134
+ * 1. turn.personaSlug
2159
2135
  * 2. the session's persona (from startSession)
2160
- * 3. the init-level default
2136
+ * 3. the default from init or identifyPersona
2161
2137
  *
2162
- * Signature-phrase matching runs in the SDK when the resolved persona
2163
- * has signature phrases registered. The matched slug list is attached to
2164
- * `turn.signaturePhraseMatches` before send.
2138
+ * When that persona has signature phrases, the SDK matches them against
2139
+ * the reply text and sends the matched slugs as
2140
+ * `signaturePhraseMatches`.
2165
2141
  */
2166
2142
  static captureTurn(turn: CaptureTurnInput): Promise<void>;
2167
2143
  /**
@@ -2171,69 +2147,62 @@ declare class Probe {
2171
2147
  */
2172
2148
  private static captureWithHints;
2173
2149
  /**
2174
- * Emit a custom outcome event on a session, stored with the `kind`
2175
- * string you supply. Use for
2176
- * customer-defined kinds like "purchase_complete", "handoff_to_human",
2177
- * "character_break_severe". Universal seed kinds (break, escalation,
2178
- * resolution, thumbs_*, rating_*) are also emitted by worker-side
2179
- * detectors automatically — call this only when the customer has a
2180
- * signal the worker cannot infer.
2150
+ * Record an outcome on a session, stored with the `kind` string you
2151
+ * supply: for example "ticket_resolved", "purchase_complete",
2152
+ * "handoff_to_human". Call it wherever the outcome becomes known, at any
2153
+ * time after the session; it joins to the session by sessionExternalId.
2154
+ * Invalid input logs one warning and is dropped. A failed send never
2155
+ * throws.
2181
2156
  */
2182
2157
  static emitOutcomeEvent(input: OutcomeEventEmit): Promise<void>;
2183
2158
  /**
2184
- * Capture one environment event against a session. The
2185
- * envelope is generalized: `source_type` and `event` are free strings whose
2186
- * meaning is defined per deployment — the instrument stores the event and
2187
- * attaches it to the session's record by time (the next turn's state
2188
- * corner, plus the causing turn's outcome corner when `causeProvenance`
2189
- * names a turn index), and never interprets it. Fire-and-log, like
2190
- * captureTurn: errors are debug-logged, never thrown.
2159
+ * Record one event from a channel beside the conversation (a feed, a
2160
+ * game state, an editor buffer) against a session. `source_type` and
2161
+ * `event` are free strings; you define their meaning. The event is
2162
+ * stored and attached to the session's turns by time, and is not
2163
+ * interpreted. Errors are logged with `debug: true`, never thrown.
2191
2164
  *
2192
- * Alignment defaults to the SDK's own clock claim; deployments with a
2193
- * stricter clock contract (or batches) should call
2194
- * captureEnvironmentEvents with explicit alignment provenance.
2165
+ * `alignment` describes the clock the event's time comes from. It
2166
+ * defaults to this process's clock; to state your own clock, or to send
2167
+ * a batch, call captureEnvironmentEvents.
2195
2168
  */
2196
2169
  static captureEnvironmentEvent(event: EnvironmentEventInput, alignment?: AlignmentProvenance): Promise<void>;
2197
2170
  /**
2198
- * Capture a batch of environment events with explicit alignment provenance
2199
- * (clock_source, skew_bound_ms, rule_version). Batches are capped at 100
2200
- * events and may span sessions — every event is self-addressed. Same
2201
- * generalized envelope and fire-and-log discipline as the single-event
2202
- * capture above.
2171
+ * Record a batch of environment events, with an optional `alignment`
2172
+ * (clock_source, skew_bound_ms, rule_version) describing their clock. At
2173
+ * most 100 events per call. Events in one batch may belong to different
2174
+ * sessions; each names its own. Errors are logged with `debug: true`,
2175
+ * never thrown.
2203
2176
  */
2204
2177
  static captureEnvironmentEvents(events: EnvironmentEventInput[], alignment?: AlignmentProvenance): Promise<void>;
2205
2178
  /**
2206
- * Capture one sub-turn span against a session: one LLM call, one tool
2207
- * call, one framework step, or a custom unit inside a turn. The span lands
2208
- * on the turn named by `turnIndex`, or — when omitted — on the session's
2209
- * latest turn at/under the span's `startedAt` (most recent turn when
2210
- * `startedAt` is also absent). A span whose turn cannot be resolved is
2211
- * dropped server-side; spans never land unattributed. Fire-and-log, like
2212
- * captureTurn: errors are debug-logged, never thrown.
2179
+ * Record one span: a step inside a turn (a model call, a tool call, a
2180
+ * framework step, or a custom unit). The span attaches to the turn named
2181
+ * by `turnIndex`; when omitted, to the session's latest turn at or
2182
+ * before the span's `startedAt` (the most recent turn when `startedAt`
2183
+ * is absent too). A span whose turn cannot be found is dropped by the
2184
+ * server. Errors are logged with `debug: true`, never thrown.
2213
2185
  *
2214
- * `attributes` are metadata only (tool names, argument shapes) — never
2215
- * free-text conversation content. Alignment defaults to the SDK's own
2216
- * clock claim; deployments with a stricter clock contract (or batches, or
2217
- * parent references between spans) should call captureSpans.
2186
+ * `attributes` are metadata only (tool names, argument shapes), never
2187
+ * conversation text. `alignment` defaults to this process's clock; to
2188
+ * state your own clock, send a batch, or link parent and child spans,
2189
+ * call captureSpans.
2218
2190
  */
2219
2191
  static captureSpan(span: SpanInput, alignment?: AlignmentProvenance): Promise<void>;
2220
2192
  /**
2221
- * Capture a batch of spans with explicit alignment provenance
2222
- * (clock_source, skew_bound_ms, rule_version). Batches are capped at 50
2223
- * spans and may span sessions — every span is self-addressed. Parent
2224
- * structure rides the batch: a span's `parentSpanId` names another span's
2225
- * caller-local `spanId` within the same batch and is wired server-side
2226
- * (unresolvable references land null). Same fire-and-log discipline as the
2227
- * single-span capture above.
2193
+ * Record a batch of spans, with an optional `alignment` (clock_source,
2194
+ * skew_bound_ms, rule_version) describing their clock. At most 50 spans
2195
+ * per call. Spans in one batch may belong to different sessions; each
2196
+ * names its own. To link parent and child, give a span a `spanId` and
2197
+ * name it in another span's `parentSpanId` within the same batch; a
2198
+ * reference that matches no span is stored as null. Errors are logged
2199
+ * with `debug: true`, never thrown.
2228
2200
  */
2229
2201
  static captureSpans(spans: SpanInput[], alignment?: AlignmentProvenance): Promise<void>;
2230
2202
  /**
2231
- * Flag a persona break for a session. Wire this to the customer's in-product
2232
- * "that didn't sound like you" UX. Populates the `user_flagged_break`
2233
- * outcome column on the dashboard.
2234
- *
2235
- * If `turnIndex` is omitted, the flag attaches to the session's most
2236
- * recent turn.
2203
+ * Record a person's report that a reply was out of character. Connect it
2204
+ * to your product's report control. With no `turnIndex`, the flag
2205
+ * attaches to the session's most recent turn.
2237
2206
  */
2238
2207
  static flagPersonaBreak(input: FlagPersonaBreakInput): Promise<void>;
2239
2208
  /**
@@ -2243,14 +2212,14 @@ declare class Probe {
2243
2212
  */
2244
2213
  private static extractTextForMatching;
2245
2214
  /**
2246
- * Shut down the SDK: discards the singleton state (sessions, pending
2247
- * user-side signals, the pre-session buffer) so init() can be called
2248
- * again. There is no send queue to flush — every capture awaits its own
2249
- * HTTP send — and instrumentation stays registered for the life of the
2250
- * process. Idempotent.
2215
+ * Shut down the SDK: waits for sends in flight (at most 15 seconds),
2216
+ * then clears the in-memory state (sessions, pending input) so init()
2217
+ * can be called again. Model calls made after shutdown are not captured
2218
+ * until the next init. Await it before a short-lived process exits; a
2219
+ * send still in flight at exit is lost. Safe to call more than once.
2251
2220
  */
2252
2221
  static shutdown(): Promise<void>;
2253
- /** Package-internal: instrumentation adapters read this to build turns. */
2222
+ /** Internal. Not part of the public API. */
2254
2223
  static _getState(): ProbeState | null;
2255
2224
  private static shouldSample;
2256
2225
  }
@@ -2259,9 +2228,9 @@ declare class Probe {
2259
2228
  * Explicit OpenAI client wrapping: the autocapture path that does not
2260
2229
  * depend on module format, load order, or the openai version.
2261
2230
  *
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.
2231
+ * Module patching (the other path) needs CommonJS and an openai version the
2232
+ * bundled instrumentation supports. wrapOpenAI() wraps the client instance
2233
+ * the caller already holds instead.
2265
2234
  *
2266
2235
  * import OpenAI from 'openai';
2267
2236
  * import { Sight, wrapOpenAI } from '@cultured_computer/sight';
@@ -2280,6 +2249,10 @@ declare class Probe {
2280
2249
  * A non-streamed call has no first-token time and sends none. A cost is
2281
2250
  * sent only when the response reports one (`usage.cost`).
2282
2251
  *
2252
+ * A wrapped client that is also module-patched (CommonJS, `openai` loaded
2253
+ * after init) sends one turn per call, the wrap's: the span the patch
2254
+ * emits for the call is skipped (see ai-dedupe.ts).
2255
+ *
2283
2256
  * wrapOpenAI() may be called before Sight.init(): the wrap passes calls
2284
2257
  * through untouched until init runs, and warns once if a call happens
2285
2258
  * before it.