@cultured_computer/sight 0.1.0 → 0.2.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/dist/index.d.cts CHANGED
@@ -135,7 +135,13 @@ type PersonaConfig = z.infer<typeof PersonaConfigSchema>;
135
135
  declare const OutcomeHookSchema: z.ZodObject<{
136
136
  /** Type of outcome the deployment tracks. */
137
137
  type: z.ZodEnum<["numeric", "categorical", "boolean", "duration"]>;
138
- /** Callback that resolves the outcome for a completed session. */
138
+ /**
139
+ * Callback that resolves the outcome for a completed session. Invoked by
140
+ * Probe.endSession() with the session's externalId; a non-null result
141
+ * lands as an outcome event on the session. Not invoked for sessions
142
+ * swept server-side (no explicit endSession) — use emitOutcomeEvent()
143
+ * for outcomes that become known out of band.
144
+ */
139
145
  resolve: z.ZodType<(sessionId: string) => Promise<OutcomeResult | null>, z.ZodTypeDef, (sessionId: string) => Promise<OutcomeResult | null>>;
140
146
  }, "strip", z.ZodTypeAny, {
141
147
  type: "boolean" | "numeric" | "categorical" | "duration";
@@ -157,6 +163,13 @@ declare const ProbeConfigSchema: z.ZodObject<{
157
163
  deployment: z.ZodString;
158
164
  /** Ingest endpoint. Defaults to https://ingest.probe.io. */
159
165
  endpoint: z.ZodDefault<z.ZodString>;
166
+ /**
167
+ * Dashboard base URL used by the one-time first-capture announcement
168
+ * (the stderr permalink printed after the first successful send).
169
+ * Self-hosted or staging dashboards override it the same way `endpoint`
170
+ * is overridden.
171
+ */
172
+ dashboardUrl: z.ZodDefault<z.ZodString>;
160
173
  /** Persona identification. Optional at init; can be set later via identifyPersona(). */
161
174
  persona: z.ZodOptional<z.ZodObject<{
162
175
  /** Persona slug matching the deployment's registered persona. */
@@ -230,7 +243,13 @@ declare const ProbeConfigSchema: z.ZodObject<{
230
243
  outcomeHook: z.ZodOptional<z.ZodObject<{
231
244
  /** Type of outcome the deployment tracks. */
232
245
  type: z.ZodEnum<["numeric", "categorical", "boolean", "duration"]>;
233
- /** Callback that resolves the outcome for a completed session. */
246
+ /**
247
+ * Callback that resolves the outcome for a completed session. Invoked by
248
+ * Probe.endSession() with the session's externalId; a non-null result
249
+ * lands as an outcome event on the session. Not invoked for sessions
250
+ * swept server-side (no explicit endSession) — use emitOutcomeEvent()
251
+ * for outcomes that become known out of band.
252
+ */
234
253
  resolve: z.ZodType<(sessionId: string) => Promise<OutcomeResult | null>, z.ZodTypeDef, (sessionId: string) => Promise<OutcomeResult | null>>;
235
254
  }, "strip", z.ZodTypeAny, {
236
255
  type: "boolean" | "numeric" | "categorical" | "duration";
@@ -253,6 +272,7 @@ declare const ProbeConfigSchema: z.ZodObject<{
253
272
  apiKey: string;
254
273
  deployment: string;
255
274
  endpoint: string;
275
+ dashboardUrl: string;
256
276
  sampleRate: number;
257
277
  debug: boolean;
258
278
  persona?: {
@@ -277,6 +297,7 @@ declare const ProbeConfigSchema: z.ZodObject<{
277
297
  apiKey: string;
278
298
  deployment: string;
279
299
  endpoint?: string | undefined;
300
+ dashboardUrl?: string | undefined;
280
301
  persona?: {
281
302
  slug: string;
282
303
  rice?: string | Record<string, unknown> | undefined;
@@ -542,18 +563,41 @@ type OutcomeEventEmit = z.infer<typeof OutcomeEventEmitSchema>;
542
563
  * HTTP client for the Probe ingest API.
543
564
  *
544
565
  * Sends captured turns to POST /v1/turns with a Bearer token. Async, fire-and-log:
545
- * SDK never blocks the customer's LLM path on ingest.
566
+ * SDK never blocks the customer's LLM path on ingest. Rate-limited sends (429)
567
+ * are retried exactly once after Retry-After; sustained limiting drops captures.
546
568
  */
547
569
 
548
570
  type IngestClientOptions = {
549
571
  apiKey: string;
550
572
  endpoint: string;
551
573
  debug: boolean;
574
+ /** Dashboard base URL for the one-time first-capture announcement. */
575
+ dashboardUrl?: string;
552
576
  };
553
577
  declare class IngestClient {
554
578
  private apiKey;
555
579
  private endpoint;
556
580
  private debug;
581
+ private dashboardUrl;
582
+ /**
583
+ * First-trace permalink ritual (PLAN-2026-07-14-adoptions A1): the first
584
+ * SUCCESSFUL sendTurn prints one stderr line with a dashboard permalink,
585
+ * then never again for the life of this client (one IngestClient per
586
+ * process — one `init` per process; a restart prints once more, accepted).
587
+ * Failed sends do not consume the announcement. Only sendTurn announces:
588
+ * flags, outcome events, and session-end sends never trigger it (a flag
589
+ * arriving before any turn is not a captured session).
590
+ */
591
+ private firstCaptureAnnounced;
592
+ /**
593
+ * Rate-limit (429) handling: the first 429 per process prints one stderr
594
+ * warning (not debug-gated, same channel and lifetime as the first-capture
595
+ * announce); subsequent 429s only debug-log. Each rate-limited request is
596
+ * retried exactly once after Retry-After; pendingRetries counts retries
597
+ * waiting on their timers so the cap can shed load.
598
+ */
599
+ private rateLimitAnnounced;
600
+ private pendingRetries;
557
601
  constructor(opts: IngestClientOptions);
558
602
  /**
559
603
  * Send a turn to the ingest API. Fire-and-log: errors are logged but never
@@ -575,6 +619,17 @@ declare class IngestClient {
575
619
  * probe_outcome_events per Amendment I Method D.
576
620
  */
577
621
  sendOutcomeEvent(deploymentSlug: string, event: OutcomeEventEmit): Promise<void>;
622
+ /**
623
+ * Route a send response through the 429 retry policy. Non-429 responses
624
+ * pass through untouched. A 429 is re-sent exactly once after Retry-After
625
+ * seconds (default 1s when the header is missing or unparseable; clamped
626
+ * to [1, 60]s); the retry's response is returned as-is, so a second 429 is
627
+ * never retried again — callers log and drop it like any other failed
628
+ * send. Returns null when the retry was dropped at the pending-retry cap.
629
+ * The timer is unref'd (where supported) so a pending retry never holds
630
+ * the process open.
631
+ */
632
+ private retryIfRateLimited;
578
633
  private log;
579
634
  }
580
635
 
@@ -792,8 +847,11 @@ declare class Probe {
792
847
  * Chapter 8e′ Card 3 (version behavioral diff) — every customer would
793
848
  * hash their own way and version-diff would become noise.
794
849
  *
795
- * Node runtime; use dynamic import so the SDK stays browser-friendly
796
- * for callers that never touch this helper.
850
+ * The same hashing (src/hash.ts) backs the OTel processor's automatic
851
+ * version stamping: when autocapture sees a system message and the
852
+ * deployer set no environmentConfigHash, the session is stamped with
853
+ * the system prompt's hash and an 'auto:xxxxxxxx' label. Explicit
854
+ * startSession values always win over the auto stamp.
797
855
  */
798
856
  static hashEnvironmentConfig(input: string): Promise<string>;
799
857
  /**
@@ -801,6 +859,16 @@ declare class Probe {
801
859
  * eventually), but recommended for long-running processes with many distinct
802
860
  * conversations. If `input.endedReason` is provided the SDK sends an end
803
861
  * event to ingest so the worker records the reason server-side.
862
+ *
863
+ * Resolve-on-close: if an outcome hook is registered (init `outcomeHook`
864
+ * or wireOutcomeHook()), endSession invokes `hook.resolve(externalId)`
865
+ * and, when it returns a non-null OutcomeResult, lands it as an outcome
866
+ * event (kind = result.outcome, detail carries type/value). This is the
867
+ * ONLY place the SDK invokes the hook — there are no client-side timers,
868
+ * so sessions that are never ended explicitly are swept server-side as
869
+ * `timeout` and receive no hook-resolved outcome; land those via
870
+ * emitOutcomeEvent() from wherever the outcome becomes known. Error-safe:
871
+ * a throwing or rejecting hook never breaks endSession.
804
872
  */
805
873
  static endSession(externalId: string | SessionEndInput): Promise<void>;
806
874
  /**
@@ -833,9 +901,11 @@ declare class Probe {
833
901
  static startSessionWithContext(input: SessionStart, includes?: ClientContextIncludes): void;
834
902
  /**
835
903
  * Register the outcome hook: declares the deployment's outcome type and
836
- * the resolver for it. NOTE: automatic invocation on session close is
837
- * not wired in the current build — the hook is stored but nothing calls
838
- * `resolve` yet. To land a downstream outcome on a session today, call
904
+ * the resolver for it. The hook's `resolve(sessionExternalId)` is invoked
905
+ * by endSession() — explicit close is the only trigger; the SDK runs no
906
+ * client-side timers. A non-null OutcomeResult lands as an outcome event
907
+ * on the session. Sessions that are never ended explicitly are swept
908
+ * server-side and never resolve through the hook; land those outcomes via
839
909
  * emitOutcomeEvent() from the place where the outcome becomes known
840
910
  * (webhook, CRM callback); it joins back by sessionExternalId.
841
911
  */
package/dist/index.d.ts CHANGED
@@ -135,7 +135,13 @@ type PersonaConfig = z.infer<typeof PersonaConfigSchema>;
135
135
  declare const OutcomeHookSchema: z.ZodObject<{
136
136
  /** Type of outcome the deployment tracks. */
137
137
  type: z.ZodEnum<["numeric", "categorical", "boolean", "duration"]>;
138
- /** Callback that resolves the outcome for a completed session. */
138
+ /**
139
+ * Callback that resolves the outcome for a completed session. Invoked by
140
+ * Probe.endSession() with the session's externalId; a non-null result
141
+ * lands as an outcome event on the session. Not invoked for sessions
142
+ * swept server-side (no explicit endSession) — use emitOutcomeEvent()
143
+ * for outcomes that become known out of band.
144
+ */
139
145
  resolve: z.ZodType<(sessionId: string) => Promise<OutcomeResult | null>, z.ZodTypeDef, (sessionId: string) => Promise<OutcomeResult | null>>;
140
146
  }, "strip", z.ZodTypeAny, {
141
147
  type: "boolean" | "numeric" | "categorical" | "duration";
@@ -157,6 +163,13 @@ declare const ProbeConfigSchema: z.ZodObject<{
157
163
  deployment: z.ZodString;
158
164
  /** Ingest endpoint. Defaults to https://ingest.probe.io. */
159
165
  endpoint: z.ZodDefault<z.ZodString>;
166
+ /**
167
+ * Dashboard base URL used by the one-time first-capture announcement
168
+ * (the stderr permalink printed after the first successful send).
169
+ * Self-hosted or staging dashboards override it the same way `endpoint`
170
+ * is overridden.
171
+ */
172
+ dashboardUrl: z.ZodDefault<z.ZodString>;
160
173
  /** Persona identification. Optional at init; can be set later via identifyPersona(). */
161
174
  persona: z.ZodOptional<z.ZodObject<{
162
175
  /** Persona slug matching the deployment's registered persona. */
@@ -230,7 +243,13 @@ declare const ProbeConfigSchema: z.ZodObject<{
230
243
  outcomeHook: z.ZodOptional<z.ZodObject<{
231
244
  /** Type of outcome the deployment tracks. */
232
245
  type: z.ZodEnum<["numeric", "categorical", "boolean", "duration"]>;
233
- /** Callback that resolves the outcome for a completed session. */
246
+ /**
247
+ * Callback that resolves the outcome for a completed session. Invoked by
248
+ * Probe.endSession() with the session's externalId; a non-null result
249
+ * lands as an outcome event on the session. Not invoked for sessions
250
+ * swept server-side (no explicit endSession) — use emitOutcomeEvent()
251
+ * for outcomes that become known out of band.
252
+ */
234
253
  resolve: z.ZodType<(sessionId: string) => Promise<OutcomeResult | null>, z.ZodTypeDef, (sessionId: string) => Promise<OutcomeResult | null>>;
235
254
  }, "strip", z.ZodTypeAny, {
236
255
  type: "boolean" | "numeric" | "categorical" | "duration";
@@ -253,6 +272,7 @@ declare const ProbeConfigSchema: z.ZodObject<{
253
272
  apiKey: string;
254
273
  deployment: string;
255
274
  endpoint: string;
275
+ dashboardUrl: string;
256
276
  sampleRate: number;
257
277
  debug: boolean;
258
278
  persona?: {
@@ -277,6 +297,7 @@ declare const ProbeConfigSchema: z.ZodObject<{
277
297
  apiKey: string;
278
298
  deployment: string;
279
299
  endpoint?: string | undefined;
300
+ dashboardUrl?: string | undefined;
280
301
  persona?: {
281
302
  slug: string;
282
303
  rice?: string | Record<string, unknown> | undefined;
@@ -542,18 +563,41 @@ type OutcomeEventEmit = z.infer<typeof OutcomeEventEmitSchema>;
542
563
  * HTTP client for the Probe ingest API.
543
564
  *
544
565
  * Sends captured turns to POST /v1/turns with a Bearer token. Async, fire-and-log:
545
- * SDK never blocks the customer's LLM path on ingest.
566
+ * SDK never blocks the customer's LLM path on ingest. Rate-limited sends (429)
567
+ * are retried exactly once after Retry-After; sustained limiting drops captures.
546
568
  */
547
569
 
548
570
  type IngestClientOptions = {
549
571
  apiKey: string;
550
572
  endpoint: string;
551
573
  debug: boolean;
574
+ /** Dashboard base URL for the one-time first-capture announcement. */
575
+ dashboardUrl?: string;
552
576
  };
553
577
  declare class IngestClient {
554
578
  private apiKey;
555
579
  private endpoint;
556
580
  private debug;
581
+ private dashboardUrl;
582
+ /**
583
+ * First-trace permalink ritual (PLAN-2026-07-14-adoptions A1): the first
584
+ * SUCCESSFUL sendTurn prints one stderr line with a dashboard permalink,
585
+ * then never again for the life of this client (one IngestClient per
586
+ * process — one `init` per process; a restart prints once more, accepted).
587
+ * Failed sends do not consume the announcement. Only sendTurn announces:
588
+ * flags, outcome events, and session-end sends never trigger it (a flag
589
+ * arriving before any turn is not a captured session).
590
+ */
591
+ private firstCaptureAnnounced;
592
+ /**
593
+ * Rate-limit (429) handling: the first 429 per process prints one stderr
594
+ * warning (not debug-gated, same channel and lifetime as the first-capture
595
+ * announce); subsequent 429s only debug-log. Each rate-limited request is
596
+ * retried exactly once after Retry-After; pendingRetries counts retries
597
+ * waiting on their timers so the cap can shed load.
598
+ */
599
+ private rateLimitAnnounced;
600
+ private pendingRetries;
557
601
  constructor(opts: IngestClientOptions);
558
602
  /**
559
603
  * Send a turn to the ingest API. Fire-and-log: errors are logged but never
@@ -575,6 +619,17 @@ declare class IngestClient {
575
619
  * probe_outcome_events per Amendment I Method D.
576
620
  */
577
621
  sendOutcomeEvent(deploymentSlug: string, event: OutcomeEventEmit): Promise<void>;
622
+ /**
623
+ * Route a send response through the 429 retry policy. Non-429 responses
624
+ * pass through untouched. A 429 is re-sent exactly once after Retry-After
625
+ * seconds (default 1s when the header is missing or unparseable; clamped
626
+ * to [1, 60]s); the retry's response is returned as-is, so a second 429 is
627
+ * never retried again — callers log and drop it like any other failed
628
+ * send. Returns null when the retry was dropped at the pending-retry cap.
629
+ * The timer is unref'd (where supported) so a pending retry never holds
630
+ * the process open.
631
+ */
632
+ private retryIfRateLimited;
578
633
  private log;
579
634
  }
580
635
 
@@ -792,8 +847,11 @@ declare class Probe {
792
847
  * Chapter 8e′ Card 3 (version behavioral diff) — every customer would
793
848
  * hash their own way and version-diff would become noise.
794
849
  *
795
- * Node runtime; use dynamic import so the SDK stays browser-friendly
796
- * for callers that never touch this helper.
850
+ * The same hashing (src/hash.ts) backs the OTel processor's automatic
851
+ * version stamping: when autocapture sees a system message and the
852
+ * deployer set no environmentConfigHash, the session is stamped with
853
+ * the system prompt's hash and an 'auto:xxxxxxxx' label. Explicit
854
+ * startSession values always win over the auto stamp.
797
855
  */
798
856
  static hashEnvironmentConfig(input: string): Promise<string>;
799
857
  /**
@@ -801,6 +859,16 @@ declare class Probe {
801
859
  * eventually), but recommended for long-running processes with many distinct
802
860
  * conversations. If `input.endedReason` is provided the SDK sends an end
803
861
  * event to ingest so the worker records the reason server-side.
862
+ *
863
+ * Resolve-on-close: if an outcome hook is registered (init `outcomeHook`
864
+ * or wireOutcomeHook()), endSession invokes `hook.resolve(externalId)`
865
+ * and, when it returns a non-null OutcomeResult, lands it as an outcome
866
+ * event (kind = result.outcome, detail carries type/value). This is the
867
+ * ONLY place the SDK invokes the hook — there are no client-side timers,
868
+ * so sessions that are never ended explicitly are swept server-side as
869
+ * `timeout` and receive no hook-resolved outcome; land those via
870
+ * emitOutcomeEvent() from wherever the outcome becomes known. Error-safe:
871
+ * a throwing or rejecting hook never breaks endSession.
804
872
  */
805
873
  static endSession(externalId: string | SessionEndInput): Promise<void>;
806
874
  /**
@@ -833,9 +901,11 @@ declare class Probe {
833
901
  static startSessionWithContext(input: SessionStart, includes?: ClientContextIncludes): void;
834
902
  /**
835
903
  * Register the outcome hook: declares the deployment's outcome type and
836
- * the resolver for it. NOTE: automatic invocation on session close is
837
- * not wired in the current build — the hook is stored but nothing calls
838
- * `resolve` yet. To land a downstream outcome on a session today, call
904
+ * the resolver for it. The hook's `resolve(sessionExternalId)` is invoked
905
+ * by endSession() — explicit close is the only trigger; the SDK runs no
906
+ * client-side timers. A non-null OutcomeResult lands as an outcome event
907
+ * on the session. Sessions that are never ended explicitly are swept
908
+ * server-side and never resolve through the hook; land those outcomes via
839
909
  * emitOutcomeEvent() from the place where the outcome becomes known
840
910
  * (webhook, CRM callback); it joins back by sessionExternalId.
841
911
  */