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