@cultured_computer/sight 0.2.1 → 0.3.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
@@ -58,6 +58,144 @@ declare const PropensitySchema: z.ZodObject<{
58
58
  selectionMeta?: Record<string, unknown> | undefined;
59
59
  }>;
60
60
  type PropensityInput = z.infer<typeof PropensitySchema>;
61
+ declare const EnvironmentEventInputSchema: z.ZodObject<{
62
+ /** Free-form channel label (e.g. a stimulus feed, a game state stream). Open vocabulary — NOT an enum. */
63
+ source_type: z.ZodString;
64
+ /** Free-form event name. Open vocabulary — NOT an enum. */
65
+ event: z.ZodString;
66
+ /** ISO timestamp of the event on the deployer's clock (see alignment). */
67
+ at: z.ZodString;
68
+ /** Optional detail payload (deployer-defined). */
69
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
70
+ sessionExternalId: z.ZodString;
71
+ deploymentSlug: z.ZodString;
72
+ /**
73
+ * Optional reference to the causing turn. v1 resolves a turn index within
74
+ * the same session (string-encoded integer); any other value is stored
75
+ * verbatim on the event record without an outcome-corner link. The
76
+ * instrument records the reference only — no causal inference.
77
+ */
78
+ causeProvenance: z.ZodOptional<z.ZodString>;
79
+ }, "strip", z.ZodTypeAny, {
80
+ at: string;
81
+ deploymentSlug: string;
82
+ sessionExternalId: string;
83
+ source_type: string;
84
+ event: string;
85
+ meta?: Record<string, unknown> | undefined;
86
+ causeProvenance?: string | undefined;
87
+ }, {
88
+ at: string;
89
+ deploymentSlug: string;
90
+ sessionExternalId: string;
91
+ source_type: string;
92
+ event: string;
93
+ meta?: Record<string, unknown> | undefined;
94
+ causeProvenance?: string | undefined;
95
+ }>;
96
+ type EnvironmentEventInput = z.infer<typeof EnvironmentEventInputSchema>;
97
+ /**
98
+ * Clock contract for a batch: whose clock produced the events' `at`, the
99
+ * deployer's bound on skew against the instrument's clock, and the version
100
+ * of the attach rule the deployer aligned to. Free-form strings — the
101
+ * instrument stores the claim, it does not verify clocks.
102
+ */
103
+ declare const AlignmentProvenanceSchema: z.ZodObject<{
104
+ clock_source: z.ZodString;
105
+ skew_bound_ms: z.ZodOptional<z.ZodNumber>;
106
+ rule_version: z.ZodString;
107
+ }, "strip", z.ZodTypeAny, {
108
+ clock_source: string;
109
+ rule_version: string;
110
+ skew_bound_ms?: number | undefined;
111
+ }, {
112
+ clock_source: string;
113
+ rule_version: string;
114
+ skew_bound_ms?: number | undefined;
115
+ }>;
116
+ type AlignmentProvenance = z.infer<typeof AlignmentProvenanceSchema>;
117
+ declare const EnvironmentEventsBatchSchema: z.ZodObject<{
118
+ /** Events are self-addressed: a batch may span sessions/deployments. */
119
+ events: z.ZodArray<z.ZodObject<{
120
+ /** Free-form channel label (e.g. a stimulus feed, a game state stream). Open vocabulary — NOT an enum. */
121
+ source_type: z.ZodString;
122
+ /** Free-form event name. Open vocabulary — NOT an enum. */
123
+ event: z.ZodString;
124
+ /** ISO timestamp of the event on the deployer's clock (see alignment). */
125
+ at: z.ZodString;
126
+ /** Optional detail payload (deployer-defined). */
127
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
128
+ sessionExternalId: z.ZodString;
129
+ deploymentSlug: z.ZodString;
130
+ /**
131
+ * Optional reference to the causing turn. v1 resolves a turn index within
132
+ * the same session (string-encoded integer); any other value is stored
133
+ * verbatim on the event record without an outcome-corner link. The
134
+ * instrument records the reference only — no causal inference.
135
+ */
136
+ causeProvenance: z.ZodOptional<z.ZodString>;
137
+ }, "strip", z.ZodTypeAny, {
138
+ at: string;
139
+ deploymentSlug: string;
140
+ sessionExternalId: string;
141
+ source_type: string;
142
+ event: string;
143
+ meta?: Record<string, unknown> | undefined;
144
+ causeProvenance?: string | undefined;
145
+ }, {
146
+ at: string;
147
+ deploymentSlug: string;
148
+ sessionExternalId: string;
149
+ source_type: string;
150
+ event: string;
151
+ meta?: Record<string, unknown> | undefined;
152
+ causeProvenance?: string | undefined;
153
+ }>, "many">;
154
+ alignment: z.ZodObject<{
155
+ clock_source: z.ZodString;
156
+ skew_bound_ms: z.ZodOptional<z.ZodNumber>;
157
+ rule_version: z.ZodString;
158
+ }, "strip", z.ZodTypeAny, {
159
+ clock_source: string;
160
+ rule_version: string;
161
+ skew_bound_ms?: number | undefined;
162
+ }, {
163
+ clock_source: string;
164
+ rule_version: string;
165
+ skew_bound_ms?: number | undefined;
166
+ }>;
167
+ }, "strip", z.ZodTypeAny, {
168
+ events: {
169
+ at: string;
170
+ deploymentSlug: string;
171
+ sessionExternalId: string;
172
+ source_type: string;
173
+ event: string;
174
+ meta?: Record<string, unknown> | undefined;
175
+ causeProvenance?: string | undefined;
176
+ }[];
177
+ alignment: {
178
+ clock_source: string;
179
+ rule_version: string;
180
+ skew_bound_ms?: number | undefined;
181
+ };
182
+ }, {
183
+ events: {
184
+ at: string;
185
+ deploymentSlug: string;
186
+ sessionExternalId: string;
187
+ source_type: string;
188
+ event: string;
189
+ meta?: Record<string, unknown> | undefined;
190
+ causeProvenance?: string | undefined;
191
+ }[];
192
+ alignment: {
193
+ clock_source: string;
194
+ rule_version: string;
195
+ skew_bound_ms?: number | undefined;
196
+ };
197
+ }>;
198
+ type EnvironmentEventsBatch = z.infer<typeof EnvironmentEventsBatchSchema>;
61
199
 
62
200
  /**
63
201
  * Sight SDK (@cultured-computer/sight) shared types.
@@ -161,7 +299,7 @@ declare const ProbeConfigSchema: z.ZodObject<{
161
299
  apiKey: z.ZodString;
162
300
  /** Deployment slug registered in the Probe backend. Required. */
163
301
  deployment: z.ZodString;
164
- /** Ingest endpoint. Defaults to https://ingest.probe.io. */
302
+ /** Ingest endpoint. Defaults to the production ingest service. */
165
303
  endpoint: z.ZodDefault<z.ZodString>;
166
304
  /**
167
305
  * Dashboard base URL used by the one-time first-capture announcement
@@ -619,6 +757,12 @@ declare class IngestClient {
619
757
  * probe_outcome_events per Amendment I Method D.
620
758
  */
621
759
  sendOutcomeEvent(deploymentSlug: string, event: OutcomeEventEmit): Promise<void>;
760
+ /**
761
+ * Send an environment-event batch to the ingest API. Fire-and-log, same as
762
+ * sendTurn. The envelope is generalized: the worker attaches each event to
763
+ * its session's record by time; meaning is per-deployment.
764
+ */
765
+ sendEnvironmentEvents(batch: EnvironmentEventsBatch): Promise<void>;
622
766
  /**
623
767
  * Route a send response through the 429 retry policy. Non-429 responses
624
768
  * pass through untouched. A 429 is re-sent exactly once after Retry-After
@@ -712,8 +856,8 @@ declare function compileSignaturePhrases(phrases: SignaturePhrase[]): CompiledPh
712
856
  *
713
857
  * Probe.init({
714
858
  * apiKey: process.env.PROBE_API_KEY!,
715
- * deployment: 'alyssa-v2',
716
- * persona: { slug: 'alyssa' },
859
+ * deployment: 'support-agent',
860
+ * persona: { slug: 'casey' },
717
861
  * });
718
862
  *
719
863
  * // Autocapture is now on for any subsequent OpenAI / Anthropic / etc. call.
@@ -934,6 +1078,28 @@ declare class Probe {
934
1078
  * signal the worker cannot infer.
935
1079
  */
936
1080
  static emitOutcomeEvent(input: OutcomeEventEmit): Promise<void>;
1081
+ /**
1082
+ * Capture one environment event against a session (Arc D-rail). The
1083
+ * envelope is generalized: `source_type` and `event` are free strings whose
1084
+ * meaning is defined per deployment — the instrument stores the event and
1085
+ * attaches it to the session's record by time (the next turn's state
1086
+ * corner, plus the causing turn's outcome corner when `causeProvenance`
1087
+ * names a turn index), and never interprets it. Fire-and-log, like
1088
+ * captureTurn: errors are debug-logged, never thrown.
1089
+ *
1090
+ * Alignment defaults to the SDK's own clock claim; deployments with a
1091
+ * stricter clock contract (or batches) should call
1092
+ * captureEnvironmentEvents with explicit alignment provenance.
1093
+ */
1094
+ static captureEnvironmentEvent(event: EnvironmentEventInput, alignment?: AlignmentProvenance): Promise<void>;
1095
+ /**
1096
+ * Capture a batch of environment events with explicit alignment provenance
1097
+ * (clock_source, skew_bound_ms, rule_version). Batches are capped at 100
1098
+ * events and may span sessions — every event is self-addressed. Same
1099
+ * generalized envelope and fire-and-log discipline as the single-event
1100
+ * capture above.
1101
+ */
1102
+ static captureEnvironmentEvents(events: EnvironmentEventInput[], alignment: AlignmentProvenance): Promise<void>;
937
1103
  /**
938
1104
  * Flag a persona break for a session. Wire this to the customer's in-product
939
1105
  * "that didn't sound like you" UX. Populates the `user_flagged_break`
@@ -962,4 +1128,4 @@ declare class Probe {
962
1128
  private static shouldSample;
963
1129
  }
964
1130
 
965
- export { type CapturedTurn, type OutcomeEventEmit, type OutcomeHook, type OutcomeResult, type PersonaConfig, Probe, type ProbeConfig, type ProbeConfigInput, Probe as Sight, type CapturedTurn as SightCapturedTurn, type ProbeConfig as SightConfig, type ProbeConfigInput as SightConfigInput, type OutcomeEventEmit as SightOutcomeEventEmit, type OutcomeHook as SightOutcomeHook, type OutcomeResult as SightOutcomeResult, type PersonaConfig as SightPersonaConfig };
1131
+ export { type AlignmentProvenance, type CapturedTurn, type EnvironmentEventInput, type OutcomeEventEmit, type OutcomeHook, type OutcomeResult, type PersonaConfig, Probe, type ProbeConfig, type ProbeConfigInput, Probe as Sight, type AlignmentProvenance as SightAlignmentProvenance, type CapturedTurn as SightCapturedTurn, type ProbeConfig as SightConfig, type ProbeConfigInput as SightConfigInput, type EnvironmentEventInput as SightEnvironmentEventInput, type OutcomeEventEmit as SightOutcomeEventEmit, type OutcomeHook as SightOutcomeHook, type OutcomeResult as SightOutcomeResult, type PersonaConfig as SightPersonaConfig };
package/dist/index.d.ts CHANGED
@@ -58,6 +58,144 @@ declare const PropensitySchema: z.ZodObject<{
58
58
  selectionMeta?: Record<string, unknown> | undefined;
59
59
  }>;
60
60
  type PropensityInput = z.infer<typeof PropensitySchema>;
61
+ declare const EnvironmentEventInputSchema: z.ZodObject<{
62
+ /** Free-form channel label (e.g. a stimulus feed, a game state stream). Open vocabulary — NOT an enum. */
63
+ source_type: z.ZodString;
64
+ /** Free-form event name. Open vocabulary — NOT an enum. */
65
+ event: z.ZodString;
66
+ /** ISO timestamp of the event on the deployer's clock (see alignment). */
67
+ at: z.ZodString;
68
+ /** Optional detail payload (deployer-defined). */
69
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
70
+ sessionExternalId: z.ZodString;
71
+ deploymentSlug: z.ZodString;
72
+ /**
73
+ * Optional reference to the causing turn. v1 resolves a turn index within
74
+ * the same session (string-encoded integer); any other value is stored
75
+ * verbatim on the event record without an outcome-corner link. The
76
+ * instrument records the reference only — no causal inference.
77
+ */
78
+ causeProvenance: z.ZodOptional<z.ZodString>;
79
+ }, "strip", z.ZodTypeAny, {
80
+ at: string;
81
+ deploymentSlug: string;
82
+ sessionExternalId: string;
83
+ source_type: string;
84
+ event: string;
85
+ meta?: Record<string, unknown> | undefined;
86
+ causeProvenance?: string | undefined;
87
+ }, {
88
+ at: string;
89
+ deploymentSlug: string;
90
+ sessionExternalId: string;
91
+ source_type: string;
92
+ event: string;
93
+ meta?: Record<string, unknown> | undefined;
94
+ causeProvenance?: string | undefined;
95
+ }>;
96
+ type EnvironmentEventInput = z.infer<typeof EnvironmentEventInputSchema>;
97
+ /**
98
+ * Clock contract for a batch: whose clock produced the events' `at`, the
99
+ * deployer's bound on skew against the instrument's clock, and the version
100
+ * of the attach rule the deployer aligned to. Free-form strings — the
101
+ * instrument stores the claim, it does not verify clocks.
102
+ */
103
+ declare const AlignmentProvenanceSchema: z.ZodObject<{
104
+ clock_source: z.ZodString;
105
+ skew_bound_ms: z.ZodOptional<z.ZodNumber>;
106
+ rule_version: z.ZodString;
107
+ }, "strip", z.ZodTypeAny, {
108
+ clock_source: string;
109
+ rule_version: string;
110
+ skew_bound_ms?: number | undefined;
111
+ }, {
112
+ clock_source: string;
113
+ rule_version: string;
114
+ skew_bound_ms?: number | undefined;
115
+ }>;
116
+ type AlignmentProvenance = z.infer<typeof AlignmentProvenanceSchema>;
117
+ declare const EnvironmentEventsBatchSchema: z.ZodObject<{
118
+ /** Events are self-addressed: a batch may span sessions/deployments. */
119
+ events: z.ZodArray<z.ZodObject<{
120
+ /** Free-form channel label (e.g. a stimulus feed, a game state stream). Open vocabulary — NOT an enum. */
121
+ source_type: z.ZodString;
122
+ /** Free-form event name. Open vocabulary — NOT an enum. */
123
+ event: z.ZodString;
124
+ /** ISO timestamp of the event on the deployer's clock (see alignment). */
125
+ at: z.ZodString;
126
+ /** Optional detail payload (deployer-defined). */
127
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
128
+ sessionExternalId: z.ZodString;
129
+ deploymentSlug: z.ZodString;
130
+ /**
131
+ * Optional reference to the causing turn. v1 resolves a turn index within
132
+ * the same session (string-encoded integer); any other value is stored
133
+ * verbatim on the event record without an outcome-corner link. The
134
+ * instrument records the reference only — no causal inference.
135
+ */
136
+ causeProvenance: z.ZodOptional<z.ZodString>;
137
+ }, "strip", z.ZodTypeAny, {
138
+ at: string;
139
+ deploymentSlug: string;
140
+ sessionExternalId: string;
141
+ source_type: string;
142
+ event: string;
143
+ meta?: Record<string, unknown> | undefined;
144
+ causeProvenance?: string | undefined;
145
+ }, {
146
+ at: string;
147
+ deploymentSlug: string;
148
+ sessionExternalId: string;
149
+ source_type: string;
150
+ event: string;
151
+ meta?: Record<string, unknown> | undefined;
152
+ causeProvenance?: string | undefined;
153
+ }>, "many">;
154
+ alignment: z.ZodObject<{
155
+ clock_source: z.ZodString;
156
+ skew_bound_ms: z.ZodOptional<z.ZodNumber>;
157
+ rule_version: z.ZodString;
158
+ }, "strip", z.ZodTypeAny, {
159
+ clock_source: string;
160
+ rule_version: string;
161
+ skew_bound_ms?: number | undefined;
162
+ }, {
163
+ clock_source: string;
164
+ rule_version: string;
165
+ skew_bound_ms?: number | undefined;
166
+ }>;
167
+ }, "strip", z.ZodTypeAny, {
168
+ events: {
169
+ at: string;
170
+ deploymentSlug: string;
171
+ sessionExternalId: string;
172
+ source_type: string;
173
+ event: string;
174
+ meta?: Record<string, unknown> | undefined;
175
+ causeProvenance?: string | undefined;
176
+ }[];
177
+ alignment: {
178
+ clock_source: string;
179
+ rule_version: string;
180
+ skew_bound_ms?: number | undefined;
181
+ };
182
+ }, {
183
+ events: {
184
+ at: string;
185
+ deploymentSlug: string;
186
+ sessionExternalId: string;
187
+ source_type: string;
188
+ event: string;
189
+ meta?: Record<string, unknown> | undefined;
190
+ causeProvenance?: string | undefined;
191
+ }[];
192
+ alignment: {
193
+ clock_source: string;
194
+ rule_version: string;
195
+ skew_bound_ms?: number | undefined;
196
+ };
197
+ }>;
198
+ type EnvironmentEventsBatch = z.infer<typeof EnvironmentEventsBatchSchema>;
61
199
 
62
200
  /**
63
201
  * Sight SDK (@cultured-computer/sight) shared types.
@@ -161,7 +299,7 @@ declare const ProbeConfigSchema: z.ZodObject<{
161
299
  apiKey: z.ZodString;
162
300
  /** Deployment slug registered in the Probe backend. Required. */
163
301
  deployment: z.ZodString;
164
- /** Ingest endpoint. Defaults to https://ingest.probe.io. */
302
+ /** Ingest endpoint. Defaults to the production ingest service. */
165
303
  endpoint: z.ZodDefault<z.ZodString>;
166
304
  /**
167
305
  * Dashboard base URL used by the one-time first-capture announcement
@@ -619,6 +757,12 @@ declare class IngestClient {
619
757
  * probe_outcome_events per Amendment I Method D.
620
758
  */
621
759
  sendOutcomeEvent(deploymentSlug: string, event: OutcomeEventEmit): Promise<void>;
760
+ /**
761
+ * Send an environment-event batch to the ingest API. Fire-and-log, same as
762
+ * sendTurn. The envelope is generalized: the worker attaches each event to
763
+ * its session's record by time; meaning is per-deployment.
764
+ */
765
+ sendEnvironmentEvents(batch: EnvironmentEventsBatch): Promise<void>;
622
766
  /**
623
767
  * Route a send response through the 429 retry policy. Non-429 responses
624
768
  * pass through untouched. A 429 is re-sent exactly once after Retry-After
@@ -712,8 +856,8 @@ declare function compileSignaturePhrases(phrases: SignaturePhrase[]): CompiledPh
712
856
  *
713
857
  * Probe.init({
714
858
  * apiKey: process.env.PROBE_API_KEY!,
715
- * deployment: 'alyssa-v2',
716
- * persona: { slug: 'alyssa' },
859
+ * deployment: 'support-agent',
860
+ * persona: { slug: 'casey' },
717
861
  * });
718
862
  *
719
863
  * // Autocapture is now on for any subsequent OpenAI / Anthropic / etc. call.
@@ -934,6 +1078,28 @@ declare class Probe {
934
1078
  * signal the worker cannot infer.
935
1079
  */
936
1080
  static emitOutcomeEvent(input: OutcomeEventEmit): Promise<void>;
1081
+ /**
1082
+ * Capture one environment event against a session (Arc D-rail). The
1083
+ * envelope is generalized: `source_type` and `event` are free strings whose
1084
+ * meaning is defined per deployment — the instrument stores the event and
1085
+ * attaches it to the session's record by time (the next turn's state
1086
+ * corner, plus the causing turn's outcome corner when `causeProvenance`
1087
+ * names a turn index), and never interprets it. Fire-and-log, like
1088
+ * captureTurn: errors are debug-logged, never thrown.
1089
+ *
1090
+ * Alignment defaults to the SDK's own clock claim; deployments with a
1091
+ * stricter clock contract (or batches) should call
1092
+ * captureEnvironmentEvents with explicit alignment provenance.
1093
+ */
1094
+ static captureEnvironmentEvent(event: EnvironmentEventInput, alignment?: AlignmentProvenance): Promise<void>;
1095
+ /**
1096
+ * Capture a batch of environment events with explicit alignment provenance
1097
+ * (clock_source, skew_bound_ms, rule_version). Batches are capped at 100
1098
+ * events and may span sessions — every event is self-addressed. Same
1099
+ * generalized envelope and fire-and-log discipline as the single-event
1100
+ * capture above.
1101
+ */
1102
+ static captureEnvironmentEvents(events: EnvironmentEventInput[], alignment: AlignmentProvenance): Promise<void>;
937
1103
  /**
938
1104
  * Flag a persona break for a session. Wire this to the customer's in-product
939
1105
  * "that didn't sound like you" UX. Populates the `user_flagged_break`
@@ -962,4 +1128,4 @@ declare class Probe {
962
1128
  private static shouldSample;
963
1129
  }
964
1130
 
965
- export { type CapturedTurn, type OutcomeEventEmit, type OutcomeHook, type OutcomeResult, type PersonaConfig, Probe, type ProbeConfig, type ProbeConfigInput, Probe as Sight, type CapturedTurn as SightCapturedTurn, type ProbeConfig as SightConfig, type ProbeConfigInput as SightConfigInput, type OutcomeEventEmit as SightOutcomeEventEmit, type OutcomeHook as SightOutcomeHook, type OutcomeResult as SightOutcomeResult, type PersonaConfig as SightPersonaConfig };
1131
+ export { type AlignmentProvenance, type CapturedTurn, type EnvironmentEventInput, type OutcomeEventEmit, type OutcomeHook, type OutcomeResult, type PersonaConfig, Probe, type ProbeConfig, type ProbeConfigInput, Probe as Sight, type AlignmentProvenance as SightAlignmentProvenance, type CapturedTurn as SightCapturedTurn, type ProbeConfig as SightConfig, type ProbeConfigInput as SightConfigInput, type EnvironmentEventInput as SightEnvironmentEventInput, type OutcomeEventEmit as SightOutcomeEventEmit, type OutcomeHook as SightOutcomeHook, type OutcomeResult as SightOutcomeResult, type PersonaConfig as SightPersonaConfig };
package/dist/index.js CHANGED
@@ -172,6 +172,35 @@ var IngestClient = class {
172
172
  this.log(`[probe] outcome-event ingest error: ${msg}`);
173
173
  }
174
174
  }
175
+ /**
176
+ * Send an environment-event batch to the ingest API. Fire-and-log, same as
177
+ * sendTurn. The envelope is generalized: the worker attaches each event to
178
+ * its session's record by time; meaning is per-deployment.
179
+ */
180
+ async sendEnvironmentEvents(batch) {
181
+ try {
182
+ const send = () => fetch(`${this.endpoint}/v1/environment-events`, {
183
+ method: "POST",
184
+ headers: {
185
+ Authorization: `Bearer ${this.apiKey}`,
186
+ "content-type": "application/json"
187
+ },
188
+ body: JSON.stringify(batch)
189
+ });
190
+ const response = await this.retryIfRateLimited(await send(), send);
191
+ if (response === null) return;
192
+ if (!response.ok) {
193
+ this.log(`[probe] environment-events ingest failed status=${response.status}`);
194
+ return;
195
+ }
196
+ if (this.debug) {
197
+ this.log(`[probe] environment-events ingest ok events=${batch.events.length}`);
198
+ }
199
+ } catch (err) {
200
+ const msg = err instanceof Error ? err.message : String(err);
201
+ this.log(`[probe] environment-events ingest error: ${msg}`);
202
+ }
203
+ }
175
204
  /**
176
205
  * Route a send response through the 429 retry policy. Non-429 responses
177
206
  * pass through untouched. A 429 is re-sent exactly once after Retry-After
@@ -261,8 +290,8 @@ var ProbeConfigSchema = z.object({
261
290
  apiKey: z.string().min(1),
262
291
  /** Deployment slug registered in the Probe backend. Required. */
263
292
  deployment: z.string().min(1),
264
- /** Ingest endpoint. Defaults to https://ingest.probe.io. */
265
- endpoint: z.string().url().default("https://ingest.probe.io"),
293
+ /** Ingest endpoint. Defaults to the production ingest service. */
294
+ endpoint: z.string().url().default("https://fieldwork-ingest.fly.dev"),
266
295
  /**
267
296
  * Dashboard base URL used by the one-time first-capture announcement
268
297
  * (the stderr permalink printed after the first successful send).
@@ -1156,6 +1185,74 @@ z.object({
1156
1185
  seed: z.number().int(),
1157
1186
  startDate: z.string()
1158
1187
  });
1188
+ var EnvironmentEventInputSchema = z.object({
1189
+ /** Free-form channel label (e.g. a stimulus feed, a game state stream). Open vocabulary — NOT an enum. */
1190
+ source_type: z.string().min(1),
1191
+ /** Free-form event name. Open vocabulary — NOT an enum. */
1192
+ event: z.string().min(1),
1193
+ /** ISO timestamp of the event on the deployer's clock (see alignment). */
1194
+ at: z.string().datetime(),
1195
+ /** Optional detail payload (deployer-defined). */
1196
+ meta: z.record(z.string(), z.unknown()).optional(),
1197
+ sessionExternalId: z.string().min(1),
1198
+ deploymentSlug: z.string().min(1),
1199
+ /**
1200
+ * Optional reference to the causing turn. v1 resolves a turn index within
1201
+ * the same session (string-encoded integer); any other value is stored
1202
+ * verbatim on the event record without an outcome-corner link. The
1203
+ * instrument records the reference only — no causal inference.
1204
+ */
1205
+ causeProvenance: z.string().min(1).optional()
1206
+ });
1207
+ var AlignmentProvenanceSchema = z.object({
1208
+ clock_source: z.string().min(1),
1209
+ skew_bound_ms: z.number().nonnegative().optional(),
1210
+ rule_version: z.string().min(1)
1211
+ });
1212
+ var EnvironmentEventsBatchSchema = z.object({
1213
+ /** Events are self-addressed: a batch may span sessions/deployments. */
1214
+ events: z.array(EnvironmentEventInputSchema).min(1).max(100),
1215
+ alignment: AlignmentProvenanceSchema
1216
+ });
1217
+ var DEFINITION_SLUG = /^[a-z][a-z0-9_-]{0,63}$/;
1218
+ var DEFINITION_VALUE = z.string().trim().min(1).max(64);
1219
+ z.object({
1220
+ /** Measurement family the definition belongs to (e.g. 'voice-conformance'). */
1221
+ family: z.string().regex(DEFINITION_SLUG, "family must be a lowercase slug (a-z, 0-9, _-)."),
1222
+ /** Slug within the family. family+name identifies the definition across versions. */
1223
+ name: z.string().regex(DEFINITION_SLUG, "name must be a lowercase slug (a-z, 0-9, _-)."),
1224
+ /** The elicitation prompt — the queue row's plain-language question. */
1225
+ question: z.string().trim().min(1).max(280),
1226
+ /** Difference metric for α (Krippendorff). Elicit v1: nominal | ordinal. */
1227
+ metric: z.enum(["nominal", "ordinal"]),
1228
+ /** The chips (closed vocabulary the rater chooses from). */
1229
+ values: z.array(DEFINITION_VALUE).min(2, "A rubric needs at least two chips.").max(9, "The queue is keyboard-first \u2014 at most 9 chips."),
1230
+ /** Rank order (lowest first) — required iff metric is 'ordinal'. */
1231
+ ordinalScale: z.array(DEFINITION_VALUE).min(2).max(9).optional()
1232
+ }).refine((input) => new Set(input.values).size === input.values.length, {
1233
+ message: "Chips must be unique.",
1234
+ path: ["values"]
1235
+ }).superRefine((input, ctx) => {
1236
+ if (input.metric === "ordinal") {
1237
+ const scale = input.ordinalScale;
1238
+ if (!scale) {
1239
+ ctx.addIssue({
1240
+ code: z.ZodIssueCode.custom,
1241
+ message: "ordinalScale is required when metric is ordinal.",
1242
+ path: ["ordinalScale"]
1243
+ });
1244
+ return;
1245
+ }
1246
+ const same = scale.length === input.values.length && [...scale].sort().join("") === [...input.values].sort().join("");
1247
+ if (!same) {
1248
+ ctx.addIssue({
1249
+ code: z.ZodIssueCode.custom,
1250
+ message: "ordinalScale must be exactly the chips in rank order (lowest first).",
1251
+ path: ["ordinalScale"]
1252
+ });
1253
+ }
1254
+ }
1255
+ });
1159
1256
  z.object({
1160
1257
  deploymentSlug: z.string().min(1),
1161
1258
  sessionExternalId: z.string().min(1),
@@ -1173,6 +1270,10 @@ z.object({
1173
1270
 
1174
1271
  // src/probe.ts
1175
1272
  var PRE_SESSION_BUFFER_MAX = 100;
1273
+ var DEFAULT_ENVIRONMENT_ALIGNMENT = {
1274
+ clock_source: "sdk",
1275
+ rule_version: "v1"
1276
+ };
1176
1277
  var state = null;
1177
1278
  var Probe = class {
1178
1279
  /**
@@ -1510,7 +1611,7 @@ var Probe = class {
1510
1611
  const contract = validatePropensityContract(propensity);
1511
1612
  if (!contract.ok) {
1512
1613
  console.warn(
1513
- `[probe] Amendment S contract violation (${contract.class}): ${contract.reason}`
1614
+ `[sight] propensity contract violation (${contract.class}): ${contract.reason}`
1514
1615
  );
1515
1616
  turn.payload.propensity = void 0;
1516
1617
  validPropensity = void 0;
@@ -1633,6 +1734,43 @@ var Probe = class {
1633
1734
  const validated = OutcomeEventEmitSchema.parse(input);
1634
1735
  await state.client.sendOutcomeEvent(state.config.deployment, validated);
1635
1736
  }
1737
+ /**
1738
+ * Capture one environment event against a session (Arc D-rail). The
1739
+ * envelope is generalized: `source_type` and `event` are free strings whose
1740
+ * meaning is defined per deployment — the instrument stores the event and
1741
+ * attaches it to the session's record by time (the next turn's state
1742
+ * corner, plus the causing turn's outcome corner when `causeProvenance`
1743
+ * names a turn index), and never interprets it. Fire-and-log, like
1744
+ * captureTurn: errors are debug-logged, never thrown.
1745
+ *
1746
+ * Alignment defaults to the SDK's own clock claim; deployments with a
1747
+ * stricter clock contract (or batches) should call
1748
+ * captureEnvironmentEvents with explicit alignment provenance.
1749
+ */
1750
+ static async captureEnvironmentEvent(event, alignment) {
1751
+ if (state === null) {
1752
+ console.warn("[probe] captureEnvironmentEvent called before init");
1753
+ return;
1754
+ }
1755
+ const validated = EnvironmentEventInputSchema.parse(event);
1756
+ const align = alignment ? AlignmentProvenanceSchema.parse(alignment) : DEFAULT_ENVIRONMENT_ALIGNMENT;
1757
+ await state.client.sendEnvironmentEvents({ events: [validated], alignment: align });
1758
+ }
1759
+ /**
1760
+ * Capture a batch of environment events with explicit alignment provenance
1761
+ * (clock_source, skew_bound_ms, rule_version). Batches are capped at 100
1762
+ * events and may span sessions — every event is self-addressed. Same
1763
+ * generalized envelope and fire-and-log discipline as the single-event
1764
+ * capture above.
1765
+ */
1766
+ static async captureEnvironmentEvents(events, alignment) {
1767
+ if (state === null) {
1768
+ console.warn("[probe] captureEnvironmentEvents called before init");
1769
+ return;
1770
+ }
1771
+ const batch = EnvironmentEventsBatchSchema.parse({ events, alignment });
1772
+ await state.client.sendEnvironmentEvents(batch);
1773
+ }
1636
1774
  /**
1637
1775
  * Flag a persona break for a session. Wire this to the customer's in-product
1638
1776
  * "that didn't sound like you" UX. Populates the `user_flagged_break`