@cultured_computer/sight 0.8.0 → 0.8.1
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 +33 -0
- package/README.md +182 -584
- package/dist/cli.js +42 -74
- package/dist/index.cjs +301 -275
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +286 -313
- package/dist/index.d.ts +286 -313
- package/dist/index.js +301 -275
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
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
|
-
/**
|
|
1229
|
+
/** The persona's slug. */
|
|
1230
1230
|
slug: z.ZodString;
|
|
1231
1231
|
/**
|
|
1232
|
-
*
|
|
1233
|
-
*
|
|
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
|
-
*
|
|
1238
|
-
*
|
|
1239
|
-
*
|
|
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
|
-
*
|
|
1302
|
-
* Sight.endSession() with the session's externalId; a non-null result
|
|
1303
|
-
*
|
|
1304
|
-
*
|
|
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
|
|
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
|
-
/**
|
|
1327
|
-
`https://
|
|
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
|
|
1331
|
-
*
|
|
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
|
-
/**
|
|
1336
|
+
/** The persona's slug. */
|
|
1339
1337
|
slug: z.ZodString;
|
|
1340
1338
|
/**
|
|
1341
|
-
*
|
|
1342
|
-
*
|
|
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
|
-
*
|
|
1347
|
-
*
|
|
1348
|
-
*
|
|
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
|
-
*
|
|
1411
|
-
* Sight.endSession() with the session's externalId; a non-null result
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
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,13 +1420,14 @@ declare const ProbeConfigSchema: z.ZodObject<{
|
|
|
1422
1420
|
resolve: (sessionId: string) => Promise<OutcomeResult | null>;
|
|
1423
1421
|
}>>;
|
|
1424
1422
|
/**
|
|
1425
|
-
*
|
|
1426
|
-
*
|
|
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
|
|
1431
|
-
* the
|
|
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, {
|
|
@@ -1484,23 +1483,19 @@ declare const ProbeConfigSchema: z.ZodObject<{
|
|
|
1484
1483
|
}>;
|
|
1485
1484
|
type ProbeConfig = z.infer<typeof ProbeConfigSchema>;
|
|
1486
1485
|
/**
|
|
1487
|
-
* The
|
|
1488
|
-
*
|
|
1489
|
-
*
|
|
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
|
-
/**
|
|
1492
|
+
/** Your id for the session: one conversation. Any non-empty string. */
|
|
1496
1493
|
externalId: z.ZodString;
|
|
1497
1494
|
/**
|
|
1498
|
-
*
|
|
1499
|
-
* externalId
|
|
1500
|
-
*
|
|
1501
|
-
*
|
|
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
|
-
*
|
|
1520
|
-
*
|
|
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
|
-
*
|
|
1525
|
-
*
|
|
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
|
-
*
|
|
1531
|
-
*
|
|
1532
|
-
* agentId
|
|
1533
|
-
* experimentId
|
|
1534
|
-
* environmentConfigHash
|
|
1535
|
-
*
|
|
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
|
-
*
|
|
1567
|
-
*
|
|
1568
|
-
*
|
|
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
|
|
1595
|
-
*
|
|
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
|
-
*
|
|
1602
|
-
*
|
|
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
|
|
1619
|
-
*
|
|
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
|
-
*
|
|
1624
|
-
*
|
|
1625
|
-
*
|
|
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
|
-
*
|
|
1630
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
1670
|
-
*
|
|
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
|
-
*
|
|
1680
|
-
*
|
|
1681
|
-
*
|
|
1682
|
-
*
|
|
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
|
-
*
|
|
1688
|
-
* Derived by
|
|
1689
|
-
*
|
|
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
|
|
1698
|
-
*
|
|
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
|
-
*
|
|
1705
|
-
*
|
|
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
|
-
/**
|
|
1718
|
+
/** The turn that caused the outcome. Omit to attach to the latest turn. */
|
|
1743
1719
|
causingTurnIndex: z.ZodOptional<z.ZodNumber>;
|
|
1744
|
-
/**
|
|
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
|
|
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.
|
|
1763
|
-
*
|
|
1764
|
-
*
|
|
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
|
|
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
|
-
*
|
|
1781
|
-
*
|
|
1782
|
-
*
|
|
1783
|
-
*
|
|
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
|
|
1791
|
-
*
|
|
1792
|
-
*
|
|
1793
|
-
*
|
|
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
|
|
1802
|
-
*
|
|
1803
|
-
*
|
|
1804
|
-
*
|
|
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
|
-
*
|
|
1809
|
-
*
|
|
1810
|
-
*
|
|
1811
|
-
* the
|
|
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
|
|
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
|
|
1824
|
-
*
|
|
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
|
|
1829
|
-
*
|
|
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
|
|
1834
|
-
*
|
|
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
|
|
1839
|
-
*
|
|
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
|
|
1845
|
-
*
|
|
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
|
-
*
|
|
1852
|
-
*
|
|
1853
|
-
*
|
|
1854
|
-
*
|
|
1855
|
-
*
|
|
1856
|
-
*
|
|
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.
|
|
1869
|
-
*
|
|
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
|
|
1858
|
+
/** window.navigator.userAgent. Off by default (fingerprinting risk). */
|
|
1878
1859
|
userAgent?: boolean;
|
|
1879
|
-
/** window.navigator.language / process.env.LANG
|
|
1860
|
+
/** window.navigator.language / process.env.LANG. On by default. */
|
|
1880
1861
|
locale?: boolean;
|
|
1881
|
-
/** Intl timezone / process TZ
|
|
1862
|
+
/** Intl timezone / process TZ. On by default. */
|
|
1882
1863
|
timezone?: boolean;
|
|
1883
|
-
/** window.screen dimensions
|
|
1864
|
+
/** window.screen dimensions. Off by default (fingerprinting risk). */
|
|
1884
1865
|
screen?: boolean;
|
|
1885
|
-
/** Node process metadata (platform, node version)
|
|
1866
|
+
/** Node process metadata (platform, node version). On by default in Node. */
|
|
1886
1867
|
runtime?: boolean;
|
|
1887
|
-
/**
|
|
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: '
|
|
1923
|
+
* deployment: 'my-assistant',
|
|
1943
1924
|
* });
|
|
1944
1925
|
*
|
|
1945
|
-
* //
|
|
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
|
-
*
|
|
1963
|
-
*
|
|
1964
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
1991
|
-
*
|
|
1992
|
-
*
|
|
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
|
-
*
|
|
1997
|
-
* agentReflectMs (
|
|
1998
|
-
*
|
|
1999
|
-
*
|
|
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
|
|
2005
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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.
|
|
2024
|
-
* no
|
|
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
|
|
2029
|
-
* through a wrapped OpenAI client
|
|
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
|
-
*
|
|
2033
|
-
*
|
|
2034
|
-
*
|
|
2035
|
-
* `gen_ai.conversation.id
|
|
2036
|
-
*
|
|
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
|
|
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
|
-
*
|
|
2043
|
-
*
|
|
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
|
|
2049
|
-
*
|
|
2050
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
2073
|
-
* `environmentConfigHash` on Sight.startSession().
|
|
2074
|
-
* pass
|
|
2075
|
-
* for the diff table axis (a card keyed by a3f9c2… is unreadable).
|
|
2076
|
-
*
|
|
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.
|
|
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`.
|
|
2080
2056
|
*
|
|
2081
|
-
*
|
|
2082
|
-
*
|
|
2083
|
-
*
|
|
2084
|
-
*
|
|
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
|
|
2090
|
-
*
|
|
2091
|
-
*
|
|
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
|
-
*
|
|
2095
|
-
*
|
|
2096
|
-
*
|
|
2097
|
-
*
|
|
2098
|
-
*
|
|
2099
|
-
*
|
|
2100
|
-
*
|
|
2101
|
-
*
|
|
2102
|
-
*
|
|
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
|
|
2107
|
-
* `userInput.firstKeystrokeMs` with the next captured turn.
|
|
2108
|
-
*
|
|
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)
|
|
2120
|
-
*
|
|
2121
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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:
|
|
2137
|
-
*
|
|
2138
|
-
*
|
|
2139
|
-
*
|
|
2140
|
-
*
|
|
2141
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
2158
|
-
* 1. turn.personaSlug
|
|
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
|
|
2136
|
+
* 3. the default from init or identifyPersona
|
|
2161
2137
|
*
|
|
2162
|
-
*
|
|
2163
|
-
*
|
|
2164
|
-
* `
|
|
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
|
-
*
|
|
2175
|
-
*
|
|
2176
|
-
*
|
|
2177
|
-
*
|
|
2178
|
-
*
|
|
2179
|
-
*
|
|
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
|
-
*
|
|
2185
|
-
*
|
|
2186
|
-
*
|
|
2187
|
-
*
|
|
2188
|
-
*
|
|
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
|
-
*
|
|
2193
|
-
*
|
|
2194
|
-
*
|
|
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
|
-
*
|
|
2199
|
-
* (clock_source, skew_bound_ms, rule_version)
|
|
2200
|
-
* events
|
|
2201
|
-
*
|
|
2202
|
-
*
|
|
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
|
-
*
|
|
2207
|
-
*
|
|
2208
|
-
*
|
|
2209
|
-
*
|
|
2210
|
-
*
|
|
2211
|
-
*
|
|
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)
|
|
2215
|
-
*
|
|
2216
|
-
*
|
|
2217
|
-
*
|
|
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
|
-
*
|
|
2222
|
-
*
|
|
2223
|
-
*
|
|
2224
|
-
*
|
|
2225
|
-
*
|
|
2226
|
-
*
|
|
2227
|
-
*
|
|
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
|
-
*
|
|
2232
|
-
*
|
|
2233
|
-
*
|
|
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:
|
|
2247
|
-
*
|
|
2248
|
-
*
|
|
2249
|
-
*
|
|
2250
|
-
*
|
|
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
|
-
/**
|
|
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)
|
|
2263
|
-
*
|
|
2264
|
-
*
|
|
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.
|