@cultured_computer/sight 0.2.1 → 0.3.0

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.
@@ -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.
@@ -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
@@ -1156,6 +1185,35 @@ 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
+ });
1159
1217
  z.object({
1160
1218
  deploymentSlug: z.string().min(1),
1161
1219
  sessionExternalId: z.string().min(1),
@@ -1173,6 +1231,10 @@ z.object({
1173
1231
 
1174
1232
  // src/probe.ts
1175
1233
  var PRE_SESSION_BUFFER_MAX = 100;
1234
+ var DEFAULT_ENVIRONMENT_ALIGNMENT = {
1235
+ clock_source: "sdk",
1236
+ rule_version: "v1"
1237
+ };
1176
1238
  var state = null;
1177
1239
  var Probe = class {
1178
1240
  /**
@@ -1633,6 +1695,43 @@ var Probe = class {
1633
1695
  const validated = OutcomeEventEmitSchema.parse(input);
1634
1696
  await state.client.sendOutcomeEvent(state.config.deployment, validated);
1635
1697
  }
1698
+ /**
1699
+ * Capture one environment event against a session (Arc D-rail). The
1700
+ * envelope is generalized: `source_type` and `event` are free strings whose
1701
+ * meaning is defined per deployment — the instrument stores the event and
1702
+ * attaches it to the session's record by time (the next turn's state
1703
+ * corner, plus the causing turn's outcome corner when `causeProvenance`
1704
+ * names a turn index), and never interprets it. Fire-and-log, like
1705
+ * captureTurn: errors are debug-logged, never thrown.
1706
+ *
1707
+ * Alignment defaults to the SDK's own clock claim; deployments with a
1708
+ * stricter clock contract (or batches) should call
1709
+ * captureEnvironmentEvents with explicit alignment provenance.
1710
+ */
1711
+ static async captureEnvironmentEvent(event, alignment) {
1712
+ if (state === null) {
1713
+ console.warn("[probe] captureEnvironmentEvent called before init");
1714
+ return;
1715
+ }
1716
+ const validated = EnvironmentEventInputSchema.parse(event);
1717
+ const align = alignment ? AlignmentProvenanceSchema.parse(alignment) : DEFAULT_ENVIRONMENT_ALIGNMENT;
1718
+ await state.client.sendEnvironmentEvents({ events: [validated], alignment: align });
1719
+ }
1720
+ /**
1721
+ * Capture a batch of environment events with explicit alignment provenance
1722
+ * (clock_source, skew_bound_ms, rule_version). Batches are capped at 100
1723
+ * events and may span sessions — every event is self-addressed. Same
1724
+ * generalized envelope and fire-and-log discipline as the single-event
1725
+ * capture above.
1726
+ */
1727
+ static async captureEnvironmentEvents(events, alignment) {
1728
+ if (state === null) {
1729
+ console.warn("[probe] captureEnvironmentEvents called before init");
1730
+ return;
1731
+ }
1732
+ const batch = EnvironmentEventsBatchSchema.parse({ events, alignment });
1733
+ await state.client.sendEnvironmentEvents(batch);
1734
+ }
1636
1735
  /**
1637
1736
  * Flag a persona break for a session. Wire this to the customer's in-product
1638
1737
  * "that didn't sound like you" UX. Populates the `user_flagged_break`