@cultured_computer/sight 0.6.0 → 0.7.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/README.md +120 -28
- package/dist/cli.js +198 -7
- package/dist/index.cjs +332 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +827 -29
- package/dist/index.d.ts +827 -29
- package/dist/index.js +322 -41
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
package/dist/index.js
CHANGED
|
@@ -61,11 +61,12 @@ var IngestClient = class {
|
|
|
61
61
|
* short-lived processes (serverless, CLI scripts) can actually exit after
|
|
62
62
|
* it — the documented "in-flight sends finish within 15s" only holds while
|
|
63
63
|
* the process lives. Polling is coarse on purpose: sends report through
|
|
64
|
-
* guardedFetch's counter, never awaited individually.
|
|
64
|
+
* guardedFetch's counter and scheduled retries, never awaited individually.
|
|
65
|
+
* Retries beyond the drain budget remain best-effort, not durable delivery.
|
|
65
66
|
*/
|
|
66
67
|
async drainInFlight(timeoutMs = SEND_TIMEOUT_MS) {
|
|
67
68
|
const deadline = Date.now() + timeoutMs;
|
|
68
|
-
while (this.inFlight > 0 && Date.now() < deadline) {
|
|
69
|
+
while ((this.inFlight > 0 || this.pendingRetries > 0) && Date.now() < deadline) {
|
|
69
70
|
await new Promise((r) => setTimeout(r, 50));
|
|
70
71
|
}
|
|
71
72
|
}
|
|
@@ -82,9 +83,10 @@ var IngestClient = class {
|
|
|
82
83
|
async sendTurn(turn) {
|
|
83
84
|
try {
|
|
84
85
|
const body = JSON.stringify(turn);
|
|
85
|
-
|
|
86
|
+
const bodyBytes = new TextEncoder().encode(body).byteLength;
|
|
87
|
+
if (bodyBytes > MAX_TURN_BODY_BYTES) {
|
|
86
88
|
this.log(
|
|
87
|
-
`[sight] turn dropped: payload ${
|
|
89
|
+
`[sight] turn dropped: payload ${bodyBytes} bytes exceeds the ${MAX_TURN_BODY_BYTES}-byte cap (session=${turn.sessionExternalId} turn=${turn.turnIndex}) \u2014 trim the payload you attach`
|
|
88
90
|
);
|
|
89
91
|
return;
|
|
90
92
|
}
|
|
@@ -442,7 +444,14 @@ var SessionStartSchema = z.object({
|
|
|
442
444
|
});
|
|
443
445
|
z.object({
|
|
444
446
|
externalId: z.string().min(1),
|
|
445
|
-
endedReason: z.enum([
|
|
447
|
+
endedReason: z.enum([
|
|
448
|
+
"natural",
|
|
449
|
+
"user_closed",
|
|
450
|
+
"timeout",
|
|
451
|
+
"agent_error",
|
|
452
|
+
"user_flagged",
|
|
453
|
+
"crashed"
|
|
454
|
+
]).optional(),
|
|
446
455
|
outcome: z.string().min(1).max(64).optional(),
|
|
447
456
|
outcomeDetail: z.record(z.string(), z.unknown()).optional()
|
|
448
457
|
});
|
|
@@ -563,22 +572,7 @@ function getCurrentSessionId() {
|
|
|
563
572
|
}
|
|
564
573
|
|
|
565
574
|
// src/instrumentation/otel-processor.ts
|
|
566
|
-
var
|
|
567
|
-
var dedupCache = /* @__PURE__ */ new Map();
|
|
568
|
-
function shouldSkipAsDuplicate(traceId) {
|
|
569
|
-
const now = Date.now();
|
|
570
|
-
const seenAt = dedupCache.get(traceId);
|
|
571
|
-
if (seenAt !== void 0 && now - seenAt < DEDUP_TTL_MS) {
|
|
572
|
-
return true;
|
|
573
|
-
}
|
|
574
|
-
dedupCache.set(traceId, now);
|
|
575
|
-
if (dedupCache.size > 1e3) {
|
|
576
|
-
for (const [k, v] of dedupCache) {
|
|
577
|
-
if (now - v > DEDUP_TTL_MS) dedupCache.delete(k);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
return false;
|
|
581
|
-
}
|
|
575
|
+
var MAX_DEDUP_SPANS = 1e4;
|
|
582
576
|
function attr(attrs, key) {
|
|
583
577
|
return attrs[key];
|
|
584
578
|
}
|
|
@@ -770,6 +764,7 @@ var ProbeSpanProcessor = class {
|
|
|
770
764
|
}
|
|
771
765
|
state;
|
|
772
766
|
captureFn;
|
|
767
|
+
seenSpans = /* @__PURE__ */ new Set();
|
|
773
768
|
/**
|
|
774
769
|
* Re-point the processor at a new Probe state (or null after shutdown).
|
|
775
770
|
* A registered span processor cannot be removed from a provider, so
|
|
@@ -778,6 +773,7 @@ var ProbeSpanProcessor = class {
|
|
|
778
773
|
* stamping the old deployment slug (production-safety audit R1).
|
|
779
774
|
*/
|
|
780
775
|
rebind(state2, captureFn) {
|
|
776
|
+
if (this.state !== state2) this.seenSpans.clear();
|
|
781
777
|
this.state = state2;
|
|
782
778
|
if (captureFn) this.captureFn = captureFn;
|
|
783
779
|
}
|
|
@@ -790,8 +786,6 @@ var ProbeSpanProcessor = class {
|
|
|
790
786
|
const a = span.attributes;
|
|
791
787
|
if (isVercelAgentRollup(span.name, a)) return;
|
|
792
788
|
if (!isLLMCall(a)) return;
|
|
793
|
-
const traceId = span.spanContext().traceId;
|
|
794
|
-
if (shouldSkipAsDuplicate(traceId)) return;
|
|
795
789
|
const sessionId = getCurrentSessionId();
|
|
796
790
|
if (!sessionId) {
|
|
797
791
|
if (state2.config.debug) {
|
|
@@ -801,6 +795,13 @@ var ProbeSpanProcessor = class {
|
|
|
801
795
|
}
|
|
802
796
|
return;
|
|
803
797
|
}
|
|
798
|
+
const { traceId, spanId } = span.spanContext();
|
|
799
|
+
const identity = JSON.stringify([state2.config.deployment, sessionId, traceId, spanId]);
|
|
800
|
+
if (this.seenSpans.has(identity)) return;
|
|
801
|
+
this.seenSpans.add(identity);
|
|
802
|
+
if (this.seenSpans.size > MAX_DEDUP_SPANS) {
|
|
803
|
+
this.seenSpans.delete(this.seenSpans.values().next().value);
|
|
804
|
+
}
|
|
804
805
|
const { session, sessionExternalId, turnIndex, personaSlug } = resolveSessionAndTurn(
|
|
805
806
|
state2,
|
|
806
807
|
sessionId
|
|
@@ -831,7 +832,7 @@ var ProbeSpanProcessor = class {
|
|
|
831
832
|
}
|
|
832
833
|
}
|
|
833
834
|
shutdown() {
|
|
834
|
-
|
|
835
|
+
this.seenSpans.clear();
|
|
835
836
|
return Promise.resolve();
|
|
836
837
|
}
|
|
837
838
|
forceFlush() {
|
|
@@ -1532,6 +1533,12 @@ var UserOutcomeSchema = z.object({
|
|
|
1532
1533
|
z.object({
|
|
1533
1534
|
deploymentSlug: z.string().min(1),
|
|
1534
1535
|
sessionExternalId: z.string().min(1),
|
|
1536
|
+
/**
|
|
1537
|
+
* The SDK payload contract version (D2): optional, additive-only. Every
|
|
1538
|
+
* reader treats a missing stamp as 'envelope-v0-unstamped' — payloads
|
|
1539
|
+
* from older SDKs are valid by construction (tolerated-absent).
|
|
1540
|
+
*/
|
|
1541
|
+
envelopeVersion: z.string().max(40).optional(),
|
|
1535
1542
|
/**
|
|
1536
1543
|
* Customer's user identity (opaque string), forwarded by the SDK from
|
|
1537
1544
|
* Probe.startSession() state on every turn. Distinct from
|
|
@@ -1609,6 +1616,8 @@ z.object({
|
|
|
1609
1616
|
experimentId: z.string().optional(),
|
|
1610
1617
|
environmentConfigHash: z.string().optional(),
|
|
1611
1618
|
environmentConfigLabel: z.string().optional(),
|
|
1619
|
+
/** Internal Studio runner provenance. Customer SDKs never set this. */
|
|
1620
|
+
studioRunRequestId: z.string().uuid().optional(),
|
|
1612
1621
|
/**
|
|
1613
1622
|
* Session context riding the FIRST turn of a session (there is no
|
|
1614
1623
|
* session-start wire route; the session row is created lazily by the
|
|
@@ -1631,7 +1640,14 @@ z.object({
|
|
|
1631
1640
|
deploymentSlug: z.string().min(1),
|
|
1632
1641
|
sessionExternalId: z.string().min(1),
|
|
1633
1642
|
/** Why the session ended. */
|
|
1634
|
-
endedReason: z.enum([
|
|
1643
|
+
endedReason: z.enum([
|
|
1644
|
+
"natural",
|
|
1645
|
+
"user_closed",
|
|
1646
|
+
"timeout",
|
|
1647
|
+
"agent_error",
|
|
1648
|
+
"user_flagged",
|
|
1649
|
+
"crashed"
|
|
1650
|
+
]).optional(),
|
|
1635
1651
|
/** ISO timestamp of session end. */
|
|
1636
1652
|
endedAt: z.string().optional()
|
|
1637
1653
|
});
|
|
@@ -1698,8 +1714,113 @@ var EnvironmentEventsBatchSchema = z.object({
|
|
|
1698
1714
|
events: z.array(EnvironmentEventInputSchema).min(1).max(100),
|
|
1699
1715
|
alignment: AlignmentProvenanceSchema
|
|
1700
1716
|
});
|
|
1701
|
-
var SPAN_TYPES = [
|
|
1702
|
-
|
|
1717
|
+
var SPAN_TYPES = [
|
|
1718
|
+
"agent_call",
|
|
1719
|
+
"llm_call",
|
|
1720
|
+
"tool_call",
|
|
1721
|
+
"framework_step",
|
|
1722
|
+
"custom"
|
|
1723
|
+
];
|
|
1724
|
+
var SPAN_STATUSES = ["unset", "ok", "error"];
|
|
1725
|
+
var SPAN_V2_STATUSES = ["ok", "error"];
|
|
1726
|
+
var SPAN_PAYLOAD_STATES = [
|
|
1727
|
+
"captured",
|
|
1728
|
+
"empty",
|
|
1729
|
+
"not_captured",
|
|
1730
|
+
"redacted",
|
|
1731
|
+
"unavailable"
|
|
1732
|
+
];
|
|
1733
|
+
var SPAN_INTERVAL_KINDS = [
|
|
1734
|
+
"active",
|
|
1735
|
+
"waiting",
|
|
1736
|
+
"retry",
|
|
1737
|
+
"error"
|
|
1738
|
+
];
|
|
1739
|
+
var SpanIntervalSchema = z.object({
|
|
1740
|
+
kind: z.enum(SPAN_INTERVAL_KINDS),
|
|
1741
|
+
startedAt: z.string().datetime(),
|
|
1742
|
+
endedAt: z.string().datetime()
|
|
1743
|
+
}).superRefine((interval, ctx) => {
|
|
1744
|
+
if (new Date(interval.endedAt).getTime() <= new Date(interval.startedAt).getTime()) {
|
|
1745
|
+
ctx.addIssue({
|
|
1746
|
+
code: z.ZodIssueCode.custom,
|
|
1747
|
+
path: ["endedAt"],
|
|
1748
|
+
message: "interval endedAt must follow startedAt"
|
|
1749
|
+
});
|
|
1750
|
+
}
|
|
1751
|
+
});
|
|
1752
|
+
function serializedJsonLength(value) {
|
|
1753
|
+
try {
|
|
1754
|
+
return JSON.stringify(value)?.length ?? 0;
|
|
1755
|
+
} catch {
|
|
1756
|
+
return Number.POSITIVE_INFINITY;
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
function isJsonValue(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
1760
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
1761
|
+
return true;
|
|
1762
|
+
}
|
|
1763
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
1764
|
+
if (typeof value !== "object") return false;
|
|
1765
|
+
if (ancestors.has(value)) return false;
|
|
1766
|
+
const nextAncestors = new Set(ancestors).add(value);
|
|
1767
|
+
if (Array.isArray(value)) {
|
|
1768
|
+
return value.every((item) => isJsonValue(item, nextAncestors));
|
|
1769
|
+
}
|
|
1770
|
+
if (Object.getPrototypeOf(value) !== Object.prototype) return false;
|
|
1771
|
+
return Object.values(value).every(
|
|
1772
|
+
(item) => isJsonValue(item, nextAncestors)
|
|
1773
|
+
);
|
|
1774
|
+
}
|
|
1775
|
+
function isStructurallyEmptyPayload(value) {
|
|
1776
|
+
if (value === "") return true;
|
|
1777
|
+
if (Array.isArray(value)) return value.length === 0;
|
|
1778
|
+
return typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype && Object.keys(value).length === 0;
|
|
1779
|
+
}
|
|
1780
|
+
var SpanPayloadSchema = z.object({
|
|
1781
|
+
state: z.enum(SPAN_PAYLOAD_STATES),
|
|
1782
|
+
value: z.unknown().nullable()
|
|
1783
|
+
}).superRefine((payload, ctx) => {
|
|
1784
|
+
if (!("value" in payload)) {
|
|
1785
|
+
ctx.addIssue({
|
|
1786
|
+
code: z.ZodIssueCode.custom,
|
|
1787
|
+
path: ["value"],
|
|
1788
|
+
message: "payload value must be present; use null for non-captured states"
|
|
1789
|
+
});
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
if (payload.state === "captured" && !isJsonValue(payload.value)) {
|
|
1793
|
+
ctx.addIssue({
|
|
1794
|
+
code: z.ZodIssueCode.custom,
|
|
1795
|
+
path: ["value"],
|
|
1796
|
+
message: "captured payload must be JSON-compatible"
|
|
1797
|
+
});
|
|
1798
|
+
}
|
|
1799
|
+
if (payload.state === "captured" && payload.value === null) {
|
|
1800
|
+
ctx.addIssue({
|
|
1801
|
+
code: z.ZodIssueCode.custom,
|
|
1802
|
+
path: ["value"],
|
|
1803
|
+
message: "captured payload requires a non-null value"
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1806
|
+
if (payload.state === "captured" && isStructurallyEmptyPayload(payload.value)) {
|
|
1807
|
+
ctx.addIssue({
|
|
1808
|
+
code: z.ZodIssueCode.custom,
|
|
1809
|
+
path: ["value"],
|
|
1810
|
+
message: "genuinely empty payloads require state=empty"
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
if (payload.state !== "captured" && payload.value !== null) {
|
|
1814
|
+
ctx.addIssue({
|
|
1815
|
+
code: z.ZodIssueCode.custom,
|
|
1816
|
+
path: ["value"],
|
|
1817
|
+
message: `${payload.state} payload must carry a null value`
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
}).refine((payload) => serializedJsonLength(payload.value) <= 16e3, {
|
|
1821
|
+
message: "span payload exceeds 16k JSON chars"
|
|
1822
|
+
});
|
|
1823
|
+
var SpanAddressSchema = z.object({
|
|
1703
1824
|
deploymentSlug: z.string().min(1),
|
|
1704
1825
|
sessionExternalId: z.string().min(1),
|
|
1705
1826
|
/**
|
|
@@ -1710,7 +1831,10 @@ var SpanInputSchema = z.object({
|
|
|
1710
1831
|
* worker (logged, batch still processed): spans never land unattributed.
|
|
1711
1832
|
*/
|
|
1712
1833
|
turnIndex: z.number().int().nonnegative().optional(),
|
|
1713
|
-
spanType: z.enum(SPAN_TYPES)
|
|
1834
|
+
spanType: z.enum(SPAN_TYPES)
|
|
1835
|
+
});
|
|
1836
|
+
var SpanInputV1Schema = SpanAddressSchema.extend({
|
|
1837
|
+
contractVersion: z.literal(1).optional(),
|
|
1714
1838
|
/** Human/otel-style span name (tool name, model call label). */
|
|
1715
1839
|
name: z.string().optional(),
|
|
1716
1840
|
/**
|
|
@@ -1748,16 +1872,128 @@ var SpanInputSchema = z.object({
|
|
|
1748
1872
|
*/
|
|
1749
1873
|
parentSpanId: z.string().min(1).optional()
|
|
1750
1874
|
});
|
|
1875
|
+
var SpanInputV2Schema = SpanAddressSchema.extend({
|
|
1876
|
+
contractVersion: z.literal(2),
|
|
1877
|
+
/** Stable within a deployment/session across batches and retries. */
|
|
1878
|
+
spanId: z.string().min(1),
|
|
1879
|
+
parentSpanId: z.string().min(1).nullable(),
|
|
1880
|
+
name: z.string().min(1),
|
|
1881
|
+
status: z.enum(SPAN_V2_STATUSES),
|
|
1882
|
+
startedAt: z.string().datetime(),
|
|
1883
|
+
endedAt: z.string().datetime().nullable(),
|
|
1884
|
+
durationMs: z.number().int().nonnegative().nullable(),
|
|
1885
|
+
model: z.string().min(1).nullable(),
|
|
1886
|
+
provider: z.string().min(1).nullable(),
|
|
1887
|
+
tokensInput: z.number().int().nonnegative().nullable(),
|
|
1888
|
+
tokensOutput: z.number().int().nonnegative().nullable(),
|
|
1889
|
+
costUsd: z.number().nonnegative().nullable(),
|
|
1890
|
+
error: z.string().nullable(),
|
|
1891
|
+
input: SpanPayloadSchema,
|
|
1892
|
+
output: SpanPayloadSchema,
|
|
1893
|
+
/** Optional first-class internal timing. An omitted list means the source
|
|
1894
|
+
* did not capture interval telemetry; readers must not infer segments. */
|
|
1895
|
+
intervals: z.array(SpanIntervalSchema).max(128).optional(),
|
|
1896
|
+
attributes: z.record(z.string(), z.unknown()).nullable().refine(
|
|
1897
|
+
(value) => value === null || JSON.stringify(value).length <= 16e3,
|
|
1898
|
+
{
|
|
1899
|
+
message: "attributes exceed 16k JSON chars \u2014 spans are telemetry, not blob storage"
|
|
1900
|
+
}
|
|
1901
|
+
)
|
|
1902
|
+
}).superRefine((span, ctx) => {
|
|
1903
|
+
if (span.status !== "error" && span.error !== null) {
|
|
1904
|
+
ctx.addIssue({
|
|
1905
|
+
code: z.ZodIssueCode.custom,
|
|
1906
|
+
path: ["error"],
|
|
1907
|
+
message: "error detail requires status=error"
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
if (span.endedAt !== null && new Date(span.endedAt).getTime() < new Date(span.startedAt).getTime()) {
|
|
1911
|
+
ctx.addIssue({
|
|
1912
|
+
code: z.ZodIssueCode.custom,
|
|
1913
|
+
path: ["endedAt"],
|
|
1914
|
+
message: "endedAt must not precede startedAt"
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
const spanStart = new Date(span.startedAt).getTime();
|
|
1918
|
+
const spanEnd = span.endedAt !== null ? new Date(span.endedAt).getTime() : span.durationMs !== null ? spanStart + span.durationMs : null;
|
|
1919
|
+
span.intervals?.forEach((interval, index) => {
|
|
1920
|
+
const intervalStart = new Date(interval.startedAt).getTime();
|
|
1921
|
+
const intervalEnd = new Date(interval.endedAt).getTime();
|
|
1922
|
+
if (intervalStart < spanStart || spanEnd !== null && intervalEnd > spanEnd) {
|
|
1923
|
+
ctx.addIssue({
|
|
1924
|
+
code: z.ZodIssueCode.custom,
|
|
1925
|
+
path: ["intervals", index],
|
|
1926
|
+
message: "interval must stay within the measured span window"
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
});
|
|
1930
|
+
});
|
|
1931
|
+
var SpanInputSchema = z.union([SpanInputV2Schema, SpanInputV1Schema]);
|
|
1751
1932
|
var SpansBatchSchema = z.object({
|
|
1752
1933
|
/** Spans are self-addressed: a batch may span sessions/deployments. */
|
|
1753
1934
|
spans: z.array(SpanInputSchema).min(1).max(50),
|
|
1754
1935
|
alignment: AlignmentProvenanceSchema
|
|
1936
|
+
}).superRefine((batch, ctx) => {
|
|
1937
|
+
const spanIdCounts = /* @__PURE__ */ new Map();
|
|
1938
|
+
const spansById = /* @__PURE__ */ new Map();
|
|
1939
|
+
const parents = /* @__PURE__ */ new Map();
|
|
1940
|
+
for (const span of batch.spans) {
|
|
1941
|
+
if (span.spanId !== void 0) {
|
|
1942
|
+
spanIdCounts.set(span.spanId, (spanIdCounts.get(span.spanId) ?? 0) + 1);
|
|
1943
|
+
spansById.set(span.spanId, span);
|
|
1944
|
+
}
|
|
1945
|
+
if (span.parentSpanId !== void 0 && span.parentSpanId !== null && span.spanId) {
|
|
1946
|
+
parents.set(span.spanId, span.parentSpanId);
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
batch.spans.forEach((span, index) => {
|
|
1950
|
+
if (span.contractVersion !== 2) return;
|
|
1951
|
+
if ((spanIdCounts.get(span.spanId) ?? 0) !== 1) {
|
|
1952
|
+
ctx.addIssue({
|
|
1953
|
+
code: z.ZodIssueCode.custom,
|
|
1954
|
+
path: ["spans", index, "spanId"],
|
|
1955
|
+
message: "v2 spanId must be unique within the batch"
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
1958
|
+
if (span.parentSpanId !== null && (spanIdCounts.get(span.parentSpanId) ?? 0) !== 1) {
|
|
1959
|
+
ctx.addIssue({
|
|
1960
|
+
code: z.ZodIssueCode.custom,
|
|
1961
|
+
path: ["spans", index, "parentSpanId"],
|
|
1962
|
+
message: "v2 parentSpanId must resolve uniquely within the batch"
|
|
1963
|
+
});
|
|
1964
|
+
}
|
|
1965
|
+
const parent = span.parentSpanId === null ? void 0 : spansById.get(span.parentSpanId);
|
|
1966
|
+
if (parent && (parent.deploymentSlug !== span.deploymentSlug || parent.sessionExternalId !== span.sessionExternalId)) {
|
|
1967
|
+
ctx.addIssue({
|
|
1968
|
+
code: z.ZodIssueCode.custom,
|
|
1969
|
+
path: ["spans", index, "parentSpanId"],
|
|
1970
|
+
message: "v2 parentSpanId must belong to the same deployment and session"
|
|
1971
|
+
});
|
|
1972
|
+
}
|
|
1973
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1974
|
+
let cursor = span.spanId;
|
|
1975
|
+
while (cursor !== void 0) {
|
|
1976
|
+
if (seen.has(cursor)) {
|
|
1977
|
+
ctx.addIssue({
|
|
1978
|
+
code: z.ZodIssueCode.custom,
|
|
1979
|
+
path: ["spans", index, "parentSpanId"],
|
|
1980
|
+
message: "v2 parentSpanId graph must not contain a cycle"
|
|
1981
|
+
});
|
|
1982
|
+
break;
|
|
1983
|
+
}
|
|
1984
|
+
seen.add(cursor);
|
|
1985
|
+
cursor = parents.get(cursor);
|
|
1986
|
+
}
|
|
1987
|
+
});
|
|
1755
1988
|
});
|
|
1756
1989
|
var DEFINITION_SLUG = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
1757
1990
|
var DEFINITION_VALUE = z.string().trim().min(1).max(64);
|
|
1758
1991
|
z.object({
|
|
1759
1992
|
/** Measurement family the definition belongs to (e.g. 'voice-conformance'). */
|
|
1760
|
-
family: z.string().regex(
|
|
1993
|
+
family: z.string().regex(
|
|
1994
|
+
DEFINITION_SLUG,
|
|
1995
|
+
"family must be a lowercase slug (a-z, 0-9, _-)."
|
|
1996
|
+
),
|
|
1761
1997
|
/** Slug within the family. family+name identifies the definition across versions. */
|
|
1762
1998
|
name: z.string().regex(DEFINITION_SLUG, "name must be a lowercase slug (a-z, 0-9, _-)."),
|
|
1763
1999
|
/** The elicitation prompt — the queue row's plain-language question. */
|
|
@@ -1798,7 +2034,15 @@ z.object({
|
|
|
1798
2034
|
/** Open-vocab kind label. Seeds above; customers may register any string. */
|
|
1799
2035
|
kind: z.string().min(1),
|
|
1800
2036
|
/** How was this event detected? Seed values below; customer sources allowed. */
|
|
1801
|
-
detectedBy: z.enum([
|
|
2037
|
+
detectedBy: z.enum([
|
|
2038
|
+
"harness",
|
|
2039
|
+
"sdk_flag",
|
|
2040
|
+
"sdk_rating",
|
|
2041
|
+
"sdk_thumbs",
|
|
2042
|
+
"worker_detector",
|
|
2043
|
+
"webhook",
|
|
2044
|
+
"sdk_custom"
|
|
2045
|
+
]).or(z.string().min(1)),
|
|
1802
2046
|
/** Optional turn index the event was caused by. Omitted → attaches to session's most recent turn. */
|
|
1803
2047
|
causingTurnIndex: z.number().int().nonnegative().optional(),
|
|
1804
2048
|
/** Optional detail payload (customer-defined). */
|
|
@@ -1813,6 +2057,7 @@ var DEFAULT_ENVIRONMENT_ALIGNMENT = {
|
|
|
1813
2057
|
clock_source: "sdk",
|
|
1814
2058
|
rule_version: "v1"
|
|
1815
2059
|
};
|
|
2060
|
+
var SDK_ENVELOPE_VERSION = "sdk-envelope-v1";
|
|
1816
2061
|
var DEFAULT_SPAN_ALIGNMENT = {
|
|
1817
2062
|
clock_source: "sdk",
|
|
1818
2063
|
rule_version: "v1"
|
|
@@ -1858,7 +2103,9 @@ var Probe = class {
|
|
|
1858
2103
|
if (validated.persona?.signaturePhrases) {
|
|
1859
2104
|
state.signatureMatchers.set(
|
|
1860
2105
|
validated.persona.slug,
|
|
1861
|
-
compileSignaturePhrases(
|
|
2106
|
+
compileSignaturePhrases(
|
|
2107
|
+
validated.persona.signaturePhrases
|
|
2108
|
+
)
|
|
1862
2109
|
);
|
|
1863
2110
|
}
|
|
1864
2111
|
registerAllInstrumentations(state, (turn) => this.captureTurn(turn));
|
|
@@ -2047,8 +2294,14 @@ var Probe = class {
|
|
|
2047
2294
|
}
|
|
2048
2295
|
if (state === null) return;
|
|
2049
2296
|
if (endedReason) {
|
|
2050
|
-
await state.client.sendSessionEnd(state.config.deployment, {
|
|
2051
|
-
|
|
2297
|
+
await state.client.sendSessionEnd(state.config.deployment, {
|
|
2298
|
+
externalId: externalIdStr,
|
|
2299
|
+
endedReason
|
|
2300
|
+
}).catch((err) => {
|
|
2301
|
+
console.warn(
|
|
2302
|
+
"[sight] sendSessionEnd failed:",
|
|
2303
|
+
err instanceof Error ? err.message : err
|
|
2304
|
+
);
|
|
2052
2305
|
});
|
|
2053
2306
|
}
|
|
2054
2307
|
state.sessions.delete(externalIdStr);
|
|
@@ -2264,6 +2517,7 @@ var Probe = class {
|
|
|
2264
2517
|
session.lastAgentTurnAt = Date.now();
|
|
2265
2518
|
await state.client.sendTurn({
|
|
2266
2519
|
...turn,
|
|
2520
|
+
envelopeVersion: SDK_ENVELOPE_VERSION,
|
|
2267
2521
|
personaSlug: resolvedPersona,
|
|
2268
2522
|
signaturePhraseMatches: signatureMatches,
|
|
2269
2523
|
// User identity from the local session entry (Probe.startSession).
|
|
@@ -2304,7 +2558,11 @@ var Probe = class {
|
|
|
2304
2558
|
console.warn("[sight] emitOutcomeEvent called before init");
|
|
2305
2559
|
return;
|
|
2306
2560
|
}
|
|
2307
|
-
const validated = validateOrDrop(
|
|
2561
|
+
const validated = validateOrDrop(
|
|
2562
|
+
OutcomeEventEmitSchema,
|
|
2563
|
+
input,
|
|
2564
|
+
"emitOutcomeEvent"
|
|
2565
|
+
);
|
|
2308
2566
|
if (validated === null) return;
|
|
2309
2567
|
await state.client.sendOutcomeEvent(state.config.deployment, validated);
|
|
2310
2568
|
}
|
|
@@ -2326,10 +2584,21 @@ var Probe = class {
|
|
|
2326
2584
|
console.warn("[sight] captureEnvironmentEvent called before init");
|
|
2327
2585
|
return;
|
|
2328
2586
|
}
|
|
2329
|
-
const validated = validateOrDrop(
|
|
2587
|
+
const validated = validateOrDrop(
|
|
2588
|
+
EnvironmentEventInputSchema,
|
|
2589
|
+
event,
|
|
2590
|
+
"captureEnvironmentEvent"
|
|
2591
|
+
);
|
|
2330
2592
|
if (validated === null) return;
|
|
2331
|
-
const align = alignment ? validateOrDrop(
|
|
2332
|
-
|
|
2593
|
+
const align = alignment ? validateOrDrop(
|
|
2594
|
+
AlignmentProvenanceSchema,
|
|
2595
|
+
alignment,
|
|
2596
|
+
"captureEnvironmentEvent"
|
|
2597
|
+
) ?? DEFAULT_ENVIRONMENT_ALIGNMENT : DEFAULT_ENVIRONMENT_ALIGNMENT;
|
|
2598
|
+
await state.client.sendEnvironmentEvents({
|
|
2599
|
+
events: [validated],
|
|
2600
|
+
alignment: align
|
|
2601
|
+
});
|
|
2333
2602
|
}
|
|
2334
2603
|
/**
|
|
2335
2604
|
* Capture a batch of environment events with explicit alignment provenance
|
|
@@ -2343,7 +2612,11 @@ var Probe = class {
|
|
|
2343
2612
|
console.warn("[sight] captureEnvironmentEvents called before init");
|
|
2344
2613
|
return;
|
|
2345
2614
|
}
|
|
2346
|
-
const batch = validateOrDrop(
|
|
2615
|
+
const batch = validateOrDrop(
|
|
2616
|
+
EnvironmentEventsBatchSchema,
|
|
2617
|
+
{ events, alignment },
|
|
2618
|
+
"captureEnvironmentEvents"
|
|
2619
|
+
);
|
|
2347
2620
|
if (batch === null) return;
|
|
2348
2621
|
await state.client.sendEnvironmentEvents(batch);
|
|
2349
2622
|
}
|
|
@@ -2385,7 +2658,11 @@ var Probe = class {
|
|
|
2385
2658
|
console.warn("[sight] captureSpans called before init");
|
|
2386
2659
|
return;
|
|
2387
2660
|
}
|
|
2388
|
-
const batch = validateOrDrop(
|
|
2661
|
+
const batch = validateOrDrop(
|
|
2662
|
+
SpansBatchSchema,
|
|
2663
|
+
{ spans, alignment: alignment ?? DEFAULT_SPAN_ALIGNMENT },
|
|
2664
|
+
"captureSpans"
|
|
2665
|
+
);
|
|
2389
2666
|
if (batch === null) return;
|
|
2390
2667
|
await state.client.sendSpans(batch);
|
|
2391
2668
|
}
|
|
@@ -2402,7 +2679,11 @@ var Probe = class {
|
|
|
2402
2679
|
console.warn("[sight] flagPersonaBreak called before init");
|
|
2403
2680
|
return;
|
|
2404
2681
|
}
|
|
2405
|
-
const validated = validateOrDrop(
|
|
2682
|
+
const validated = validateOrDrop(
|
|
2683
|
+
FlagPersonaBreakSchema,
|
|
2684
|
+
input,
|
|
2685
|
+
"flagPersonaBreak"
|
|
2686
|
+
);
|
|
2406
2687
|
if (validated === null) return;
|
|
2407
2688
|
await state.client.sendFlag(state.config.deployment, validated);
|
|
2408
2689
|
}
|
|
@@ -2456,6 +2737,6 @@ var Probe = class {
|
|
|
2456
2737
|
}
|
|
2457
2738
|
};
|
|
2458
2739
|
|
|
2459
|
-
export { Probe, Probe as Sight, wrapOpenAI };
|
|
2740
|
+
export { Probe, SPAN_INTERVAL_KINDS, SPAN_PAYLOAD_STATES, SPAN_STATUSES, SPAN_TYPES, SPAN_V2_STATUSES, Probe as Sight, SpanInputSchema, SpanInputV1Schema, SpanInputV2Schema, SpanIntervalSchema, SpanPayloadSchema, SpansBatchSchema, wrapOpenAI };
|
|
2460
2741
|
//# sourceMappingURL=index.js.map
|
|
2461
2742
|
//# sourceMappingURL=index.js.map
|