@cultured_computer/sight 0.1.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/LICENSE +21 -0
- package/README.md +99 -0
- package/dist/index.cjs +1481 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +895 -0
- package/dist/index.d.ts +895 -0
- package/dist/index.js +1478 -0
- package/dist/index.js.map +1 -0
- package/package.json +92 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,895 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared types and constants across ingest, dashboard, and future SDK.
|
|
5
|
+
* Keep this package small; anything domain-specific belongs in @fieldwork/db
|
|
6
|
+
* or its own package.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare const PropensitySchema: z.ZodObject<{
|
|
10
|
+
candidates: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
11
|
+
label: z.ZodString;
|
|
12
|
+
text: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
label: string;
|
|
15
|
+
text?: string | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
label: string;
|
|
18
|
+
text?: string | undefined;
|
|
19
|
+
}>, "many">>;
|
|
20
|
+
/**
|
|
21
|
+
* Raw model confidence / logprobs / ensemble scores per candidate.
|
|
22
|
+
* Diagnostic only; NOT a propensity unless the harness confirms it is
|
|
23
|
+
* the exact sampling distribution used and passes it also as
|
|
24
|
+
* `propensities`.
|
|
25
|
+
*/
|
|
26
|
+
scores: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
27
|
+
/**
|
|
28
|
+
* Behavior-policy sampling distribution at selection time. Must sum
|
|
29
|
+
* to 1.0 (within float tolerance) if present. Load-bearing for OPE
|
|
30
|
+
* (Dudík, Langford & Li 2011 for per-turn / Jiang & Li 2016 for
|
|
31
|
+
* trajectory). When omitted, OPE is not possible on this turn.
|
|
32
|
+
*/
|
|
33
|
+
propensities: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
34
|
+
selectedIndex: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
/**
|
|
36
|
+
* Sampling-policy metadata: temperature, top_p, top_k, seed, sampler
|
|
37
|
+
* name, ensemble weights. Required for reviewers to verify that
|
|
38
|
+
* `propensities` is the actual behavior distribution.
|
|
39
|
+
*/
|
|
40
|
+
selectionMeta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
candidates?: {
|
|
43
|
+
label: string;
|
|
44
|
+
text?: string | undefined;
|
|
45
|
+
}[] | undefined;
|
|
46
|
+
scores?: number[] | undefined;
|
|
47
|
+
propensities?: number[] | undefined;
|
|
48
|
+
selectedIndex?: number | undefined;
|
|
49
|
+
selectionMeta?: Record<string, unknown> | undefined;
|
|
50
|
+
}, {
|
|
51
|
+
candidates?: {
|
|
52
|
+
label: string;
|
|
53
|
+
text?: string | undefined;
|
|
54
|
+
}[] | undefined;
|
|
55
|
+
scores?: number[] | undefined;
|
|
56
|
+
propensities?: number[] | undefined;
|
|
57
|
+
selectedIndex?: number | undefined;
|
|
58
|
+
selectionMeta?: Record<string, unknown> | undefined;
|
|
59
|
+
}>;
|
|
60
|
+
type PropensityInput = z.infer<typeof PropensitySchema>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Sight SDK (@cultured-computer/sight) shared types.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
declare const PersonaConfigSchema: z.ZodObject<{
|
|
67
|
+
/** Persona slug matching the deployment's registered persona. */
|
|
68
|
+
slug: z.ZodString;
|
|
69
|
+
/**
|
|
70
|
+
* RICE authorship artifact (Role, Identity, Communication, Engagement).
|
|
71
|
+
* Either inline object or a path/URL to a JSON file loaded at init time.
|
|
72
|
+
*/
|
|
73
|
+
rice: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodString]>>;
|
|
74
|
+
/**
|
|
75
|
+
* Customer-authored signature phrases for this persona. Compiled once at
|
|
76
|
+
* init and matched per turn at the SDK edge; matched slugs appear on the
|
|
77
|
+
* outgoing turn as `signaturePhraseMatches`.
|
|
78
|
+
*/
|
|
79
|
+
signaturePhrases: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodObject<{
|
|
80
|
+
slug: z.ZodString;
|
|
81
|
+
phrase: z.ZodString;
|
|
82
|
+
description: z.ZodOptional<z.ZodString>;
|
|
83
|
+
}, "strip", z.ZodTypeAny, {
|
|
84
|
+
slug: string;
|
|
85
|
+
phrase: string;
|
|
86
|
+
description?: string | undefined;
|
|
87
|
+
}, {
|
|
88
|
+
slug: string;
|
|
89
|
+
phrase: string;
|
|
90
|
+
description?: string | undefined;
|
|
91
|
+
}>, z.ZodObject<{
|
|
92
|
+
slug: z.ZodString;
|
|
93
|
+
regex: z.ZodString;
|
|
94
|
+
flags: z.ZodOptional<z.ZodString>;
|
|
95
|
+
description: z.ZodOptional<z.ZodString>;
|
|
96
|
+
}, "strip", z.ZodTypeAny, {
|
|
97
|
+
slug: string;
|
|
98
|
+
regex: string;
|
|
99
|
+
description?: string | undefined;
|
|
100
|
+
flags?: string | undefined;
|
|
101
|
+
}, {
|
|
102
|
+
slug: string;
|
|
103
|
+
regex: string;
|
|
104
|
+
description?: string | undefined;
|
|
105
|
+
flags?: string | undefined;
|
|
106
|
+
}>]>, "many">>;
|
|
107
|
+
}, "strip", z.ZodTypeAny, {
|
|
108
|
+
slug: string;
|
|
109
|
+
rice?: string | Record<string, unknown> | undefined;
|
|
110
|
+
signaturePhrases?: ({
|
|
111
|
+
slug: string;
|
|
112
|
+
phrase: string;
|
|
113
|
+
description?: string | undefined;
|
|
114
|
+
} | {
|
|
115
|
+
slug: string;
|
|
116
|
+
regex: string;
|
|
117
|
+
description?: string | undefined;
|
|
118
|
+
flags?: string | undefined;
|
|
119
|
+
})[] | undefined;
|
|
120
|
+
}, {
|
|
121
|
+
slug: string;
|
|
122
|
+
rice?: string | Record<string, unknown> | undefined;
|
|
123
|
+
signaturePhrases?: ({
|
|
124
|
+
slug: string;
|
|
125
|
+
phrase: string;
|
|
126
|
+
description?: string | undefined;
|
|
127
|
+
} | {
|
|
128
|
+
slug: string;
|
|
129
|
+
regex: string;
|
|
130
|
+
description?: string | undefined;
|
|
131
|
+
flags?: string | undefined;
|
|
132
|
+
})[] | undefined;
|
|
133
|
+
}>;
|
|
134
|
+
type PersonaConfig = z.infer<typeof PersonaConfigSchema>;
|
|
135
|
+
declare const OutcomeHookSchema: z.ZodObject<{
|
|
136
|
+
/** Type of outcome the deployment tracks. */
|
|
137
|
+
type: z.ZodEnum<["numeric", "categorical", "boolean", "duration"]>;
|
|
138
|
+
/** Callback that resolves the outcome for a completed session. */
|
|
139
|
+
resolve: z.ZodType<(sessionId: string) => Promise<OutcomeResult | null>, z.ZodTypeDef, (sessionId: string) => Promise<OutcomeResult | null>>;
|
|
140
|
+
}, "strip", z.ZodTypeAny, {
|
|
141
|
+
type: "boolean" | "numeric" | "categorical" | "duration";
|
|
142
|
+
resolve: (sessionId: string) => Promise<OutcomeResult | null>;
|
|
143
|
+
}, {
|
|
144
|
+
type: "boolean" | "numeric" | "categorical" | "duration";
|
|
145
|
+
resolve: (sessionId: string) => Promise<OutcomeResult | null>;
|
|
146
|
+
}>;
|
|
147
|
+
type OutcomeHook = z.infer<typeof OutcomeHookSchema>;
|
|
148
|
+
type OutcomeResult = {
|
|
149
|
+
outcome: string;
|
|
150
|
+
type: 'numeric' | 'categorical' | 'boolean' | 'duration';
|
|
151
|
+
value: string;
|
|
152
|
+
};
|
|
153
|
+
declare const ProbeConfigSchema: z.ZodObject<{
|
|
154
|
+
/** Unkey ingest key. Required. */
|
|
155
|
+
apiKey: z.ZodString;
|
|
156
|
+
/** Deployment slug registered in the Probe backend. Required. */
|
|
157
|
+
deployment: z.ZodString;
|
|
158
|
+
/** Ingest endpoint. Defaults to https://ingest.probe.io. */
|
|
159
|
+
endpoint: z.ZodDefault<z.ZodString>;
|
|
160
|
+
/** Persona identification. Optional at init; can be set later via identifyPersona(). */
|
|
161
|
+
persona: z.ZodOptional<z.ZodObject<{
|
|
162
|
+
/** Persona slug matching the deployment's registered persona. */
|
|
163
|
+
slug: z.ZodString;
|
|
164
|
+
/**
|
|
165
|
+
* RICE authorship artifact (Role, Identity, Communication, Engagement).
|
|
166
|
+
* Either inline object or a path/URL to a JSON file loaded at init time.
|
|
167
|
+
*/
|
|
168
|
+
rice: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodString]>>;
|
|
169
|
+
/**
|
|
170
|
+
* Customer-authored signature phrases for this persona. Compiled once at
|
|
171
|
+
* init and matched per turn at the SDK edge; matched slugs appear on the
|
|
172
|
+
* outgoing turn as `signaturePhraseMatches`.
|
|
173
|
+
*/
|
|
174
|
+
signaturePhrases: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodObject<{
|
|
175
|
+
slug: z.ZodString;
|
|
176
|
+
phrase: z.ZodString;
|
|
177
|
+
description: z.ZodOptional<z.ZodString>;
|
|
178
|
+
}, "strip", z.ZodTypeAny, {
|
|
179
|
+
slug: string;
|
|
180
|
+
phrase: string;
|
|
181
|
+
description?: string | undefined;
|
|
182
|
+
}, {
|
|
183
|
+
slug: string;
|
|
184
|
+
phrase: string;
|
|
185
|
+
description?: string | undefined;
|
|
186
|
+
}>, z.ZodObject<{
|
|
187
|
+
slug: z.ZodString;
|
|
188
|
+
regex: z.ZodString;
|
|
189
|
+
flags: z.ZodOptional<z.ZodString>;
|
|
190
|
+
description: z.ZodOptional<z.ZodString>;
|
|
191
|
+
}, "strip", z.ZodTypeAny, {
|
|
192
|
+
slug: string;
|
|
193
|
+
regex: string;
|
|
194
|
+
description?: string | undefined;
|
|
195
|
+
flags?: string | undefined;
|
|
196
|
+
}, {
|
|
197
|
+
slug: string;
|
|
198
|
+
regex: string;
|
|
199
|
+
description?: string | undefined;
|
|
200
|
+
flags?: string | undefined;
|
|
201
|
+
}>]>, "many">>;
|
|
202
|
+
}, "strip", z.ZodTypeAny, {
|
|
203
|
+
slug: string;
|
|
204
|
+
rice?: string | Record<string, unknown> | undefined;
|
|
205
|
+
signaturePhrases?: ({
|
|
206
|
+
slug: string;
|
|
207
|
+
phrase: string;
|
|
208
|
+
description?: string | undefined;
|
|
209
|
+
} | {
|
|
210
|
+
slug: string;
|
|
211
|
+
regex: string;
|
|
212
|
+
description?: string | undefined;
|
|
213
|
+
flags?: string | undefined;
|
|
214
|
+
})[] | undefined;
|
|
215
|
+
}, {
|
|
216
|
+
slug: string;
|
|
217
|
+
rice?: string | Record<string, unknown> | undefined;
|
|
218
|
+
signaturePhrases?: ({
|
|
219
|
+
slug: string;
|
|
220
|
+
phrase: string;
|
|
221
|
+
description?: string | undefined;
|
|
222
|
+
} | {
|
|
223
|
+
slug: string;
|
|
224
|
+
regex: string;
|
|
225
|
+
description?: string | undefined;
|
|
226
|
+
flags?: string | undefined;
|
|
227
|
+
})[] | undefined;
|
|
228
|
+
}>>;
|
|
229
|
+
/** Outcome hook. Optional at init; can be set later via wireOutcomeHook(). */
|
|
230
|
+
outcomeHook: z.ZodOptional<z.ZodObject<{
|
|
231
|
+
/** Type of outcome the deployment tracks. */
|
|
232
|
+
type: z.ZodEnum<["numeric", "categorical", "boolean", "duration"]>;
|
|
233
|
+
/** Callback that resolves the outcome for a completed session. */
|
|
234
|
+
resolve: z.ZodType<(sessionId: string) => Promise<OutcomeResult | null>, z.ZodTypeDef, (sessionId: string) => Promise<OutcomeResult | null>>;
|
|
235
|
+
}, "strip", z.ZodTypeAny, {
|
|
236
|
+
type: "boolean" | "numeric" | "categorical" | "duration";
|
|
237
|
+
resolve: (sessionId: string) => Promise<OutcomeResult | null>;
|
|
238
|
+
}, {
|
|
239
|
+
type: "boolean" | "numeric" | "categorical" | "duration";
|
|
240
|
+
resolve: (sessionId: string) => Promise<OutcomeResult | null>;
|
|
241
|
+
}>>;
|
|
242
|
+
/**
|
|
243
|
+
* Sample rate for autocapture. 1.0 = 100% of calls captured. Lower values
|
|
244
|
+
* sample deterministically so a given (turnId) always resolves identically.
|
|
245
|
+
*/
|
|
246
|
+
sampleRate: z.ZodDefault<z.ZodNumber>;
|
|
247
|
+
/**
|
|
248
|
+
* Debug mode: log every captured turn to stderr with a prefix. Never logs
|
|
249
|
+
* the Bearer token or PII.
|
|
250
|
+
*/
|
|
251
|
+
debug: z.ZodDefault<z.ZodBoolean>;
|
|
252
|
+
}, "strip", z.ZodTypeAny, {
|
|
253
|
+
apiKey: string;
|
|
254
|
+
deployment: string;
|
|
255
|
+
endpoint: string;
|
|
256
|
+
sampleRate: number;
|
|
257
|
+
debug: boolean;
|
|
258
|
+
persona?: {
|
|
259
|
+
slug: string;
|
|
260
|
+
rice?: string | Record<string, unknown> | undefined;
|
|
261
|
+
signaturePhrases?: ({
|
|
262
|
+
slug: string;
|
|
263
|
+
phrase: string;
|
|
264
|
+
description?: string | undefined;
|
|
265
|
+
} | {
|
|
266
|
+
slug: string;
|
|
267
|
+
regex: string;
|
|
268
|
+
description?: string | undefined;
|
|
269
|
+
flags?: string | undefined;
|
|
270
|
+
})[] | undefined;
|
|
271
|
+
} | undefined;
|
|
272
|
+
outcomeHook?: {
|
|
273
|
+
type: "boolean" | "numeric" | "categorical" | "duration";
|
|
274
|
+
resolve: (sessionId: string) => Promise<OutcomeResult | null>;
|
|
275
|
+
} | undefined;
|
|
276
|
+
}, {
|
|
277
|
+
apiKey: string;
|
|
278
|
+
deployment: string;
|
|
279
|
+
endpoint?: string | undefined;
|
|
280
|
+
persona?: {
|
|
281
|
+
slug: string;
|
|
282
|
+
rice?: string | Record<string, unknown> | undefined;
|
|
283
|
+
signaturePhrases?: ({
|
|
284
|
+
slug: string;
|
|
285
|
+
phrase: string;
|
|
286
|
+
description?: string | undefined;
|
|
287
|
+
} | {
|
|
288
|
+
slug: string;
|
|
289
|
+
regex: string;
|
|
290
|
+
description?: string | undefined;
|
|
291
|
+
flags?: string | undefined;
|
|
292
|
+
})[] | undefined;
|
|
293
|
+
} | undefined;
|
|
294
|
+
outcomeHook?: {
|
|
295
|
+
type: "boolean" | "numeric" | "categorical" | "duration";
|
|
296
|
+
resolve: (sessionId: string) => Promise<OutcomeResult | null>;
|
|
297
|
+
} | undefined;
|
|
298
|
+
sampleRate?: number | undefined;
|
|
299
|
+
debug?: boolean | undefined;
|
|
300
|
+
}>;
|
|
301
|
+
type ProbeConfig = z.infer<typeof ProbeConfigSchema>;
|
|
302
|
+
/**
|
|
303
|
+
* The shape callers pass to Probe.init(). This is the schema's INPUT type, so
|
|
304
|
+
* fields with a `.default()` (endpoint, sampleRate, debug) are optional here —
|
|
305
|
+
* the defaults are applied by ProbeConfigSchema.parse() inside init(). Use this
|
|
306
|
+
* for the init argument; `ProbeConfig` is the resolved (post-parse) type held
|
|
307
|
+
* internally, where those fields are always present.
|
|
308
|
+
*/
|
|
309
|
+
type ProbeConfigInput = z.input<typeof ProbeConfigSchema>;
|
|
310
|
+
declare const SessionStartSchema: z.ZodObject<{
|
|
311
|
+
/** Customer's session identity (opaque string; used as the correlation key). */
|
|
312
|
+
externalId: z.ZodString;
|
|
313
|
+
/**
|
|
314
|
+
* Customer's USER identity (opaque string), distinct from externalId:
|
|
315
|
+
* externalId keys the session; externalUserId ties sessions to a
|
|
316
|
+
* returning user. Forwarded on every captured turn so the worker can
|
|
317
|
+
* persist it on the session row — return-with-persona-consistency and
|
|
318
|
+
* prior-session metrics require it. Optional; deployments that do not
|
|
319
|
+
* identify users simply skip the user-level return metrics.
|
|
320
|
+
*/
|
|
321
|
+
externalUserId: z.ZodOptional<z.ZodString>;
|
|
322
|
+
/**
|
|
323
|
+
* Persona slug active for this session. Overrides the init-level default.
|
|
324
|
+
* Required for multi-persona deployments; optional for single-persona
|
|
325
|
+
* deployments where init already carries the persona.
|
|
326
|
+
*/
|
|
327
|
+
persona: z.ZodOptional<z.ZodString>;
|
|
328
|
+
/**
|
|
329
|
+
* How the user got into this session (P2 per PLAN-2026-07-11).
|
|
330
|
+
* Retention semantics differ radically between a resume and a fresh
|
|
331
|
+
* notification landing.
|
|
332
|
+
*/
|
|
333
|
+
openedVia: z.ZodOptional<z.ZodEnum<["link", "notification", "resume", "direct", "share"]>>;
|
|
334
|
+
/**
|
|
335
|
+
* Environmental context — browser / device / locale / tz (P2). Customer-
|
|
336
|
+
* configurable which fields to include. See collectClientContext helper.
|
|
337
|
+
*/
|
|
338
|
+
clientContext: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
339
|
+
/**
|
|
340
|
+
* Optional customer metadata attached to the session. Forwarded with the
|
|
341
|
+
* first captured turn merged into `clientContext` under the `metadata`
|
|
342
|
+
* key, so it lands on sessions.probe_session_client_context.
|
|
343
|
+
*/
|
|
344
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
345
|
+
/**
|
|
346
|
+
* RLDS episode-level provenance (Amendment R populater 2026-07-11).
|
|
347
|
+
* Powers Chapter 8e′ Card 3 version behavioral diff. All optional.
|
|
348
|
+
* agentId — model/policy version
|
|
349
|
+
* experimentId — A/B arm or feature flag
|
|
350
|
+
* environmentConfigHash — SHA of prompt/config file(s)
|
|
351
|
+
* environmentConfigLabel — human-readable version label
|
|
352
|
+
*/
|
|
353
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
354
|
+
experimentId: z.ZodOptional<z.ZodString>;
|
|
355
|
+
environmentConfigHash: z.ZodOptional<z.ZodString>;
|
|
356
|
+
environmentConfigLabel: z.ZodOptional<z.ZodString>;
|
|
357
|
+
}, "strip", z.ZodTypeAny, {
|
|
358
|
+
externalId: string;
|
|
359
|
+
externalUserId?: string | undefined;
|
|
360
|
+
agentId?: string | undefined;
|
|
361
|
+
experimentId?: string | undefined;
|
|
362
|
+
environmentConfigHash?: string | undefined;
|
|
363
|
+
environmentConfigLabel?: string | undefined;
|
|
364
|
+
openedVia?: "link" | "notification" | "resume" | "direct" | "share" | undefined;
|
|
365
|
+
clientContext?: Record<string, unknown> | undefined;
|
|
366
|
+
persona?: string | undefined;
|
|
367
|
+
metadata?: Record<string, unknown> | undefined;
|
|
368
|
+
}, {
|
|
369
|
+
externalId: string;
|
|
370
|
+
externalUserId?: string | undefined;
|
|
371
|
+
agentId?: string | undefined;
|
|
372
|
+
experimentId?: string | undefined;
|
|
373
|
+
environmentConfigHash?: string | undefined;
|
|
374
|
+
environmentConfigLabel?: string | undefined;
|
|
375
|
+
openedVia?: "link" | "notification" | "resume" | "direct" | "share" | undefined;
|
|
376
|
+
clientContext?: Record<string, unknown> | undefined;
|
|
377
|
+
persona?: string | undefined;
|
|
378
|
+
metadata?: Record<string, unknown> | undefined;
|
|
379
|
+
}>;
|
|
380
|
+
type SessionStart = z.infer<typeof SessionStartSchema>;
|
|
381
|
+
/**
|
|
382
|
+
* Session end input (P2). Sent by Probe.endSession() so the worker records
|
|
383
|
+
* why a session ended.
|
|
384
|
+
*/
|
|
385
|
+
declare const SessionEndSchema: z.ZodObject<{
|
|
386
|
+
externalId: z.ZodString;
|
|
387
|
+
endedReason: z.ZodOptional<z.ZodEnum<["natural", "user_closed", "timeout", "agent_error", "user_flagged", "crashed"]>>;
|
|
388
|
+
}, "strip", z.ZodTypeAny, {
|
|
389
|
+
externalId: string;
|
|
390
|
+
endedReason?: "natural" | "user_closed" | "timeout" | "agent_error" | "user_flagged" | "crashed" | undefined;
|
|
391
|
+
}, {
|
|
392
|
+
externalId: string;
|
|
393
|
+
endedReason?: "natural" | "user_closed" | "timeout" | "agent_error" | "user_flagged" | "crashed" | undefined;
|
|
394
|
+
}>;
|
|
395
|
+
type SessionEndInput = z.infer<typeof SessionEndSchema>;
|
|
396
|
+
type CapturedTurn = {
|
|
397
|
+
deploymentSlug: string;
|
|
398
|
+
sessionExternalId: string;
|
|
399
|
+
/**
|
|
400
|
+
* Customer's user identity. Forwarded by captureTurn from the session
|
|
401
|
+
* state (Probe.startSession({ externalUserId })); the worker persists it
|
|
402
|
+
* on sessions.external_user_id at first-turn session create. Never
|
|
403
|
+
* defaulted to sessionExternalId — that key identifies the session.
|
|
404
|
+
*/
|
|
405
|
+
externalUserId?: string;
|
|
406
|
+
turnIndex: number;
|
|
407
|
+
/**
|
|
408
|
+
* Persona slug active for this turn. Resolved by the SDK from (in order):
|
|
409
|
+
* turn-level override, session-level from startSession(), init-level default.
|
|
410
|
+
*/
|
|
411
|
+
personaSlug?: string;
|
|
412
|
+
/**
|
|
413
|
+
* Signature-phrase slugs matched at the SDK edge (computed from the
|
|
414
|
+
* customer's signaturePhrases config at init). Empty array or omitted when
|
|
415
|
+
* no signatures matched or none were registered.
|
|
416
|
+
*/
|
|
417
|
+
signaturePhraseMatches?: string[];
|
|
418
|
+
/**
|
|
419
|
+
* Interpretive record fields passed through from a customer harness
|
|
420
|
+
* (Oracle read hook wired). See PROBE.md §2. Populated only if the customer
|
|
421
|
+
* runs the Cultured Computer harness pattern; null for non-harness deployments.
|
|
422
|
+
*/
|
|
423
|
+
interpretive?: {
|
|
424
|
+
situationType?: string[];
|
|
425
|
+
read?: string;
|
|
426
|
+
lensChosen?: string;
|
|
427
|
+
reactionRegister?: string;
|
|
428
|
+
reactionNextTurn?: string;
|
|
429
|
+
};
|
|
430
|
+
/**
|
|
431
|
+
* User-side input for this turn (P1 per PLAN-2026-07-11). What the human
|
|
432
|
+
* said + UI-level interactivity signals. Text is Presidio-scrubbed
|
|
433
|
+
* server-side before landing on probe_user_reply_text.
|
|
434
|
+
*/
|
|
435
|
+
userInput?: {
|
|
436
|
+
text?: string;
|
|
437
|
+
firstKeystrokeMs?: number;
|
|
438
|
+
editCount?: number;
|
|
439
|
+
interruptedStream?: boolean;
|
|
440
|
+
cancelledResponse?: boolean;
|
|
441
|
+
submittedAt?: string;
|
|
442
|
+
};
|
|
443
|
+
/**
|
|
444
|
+
* Interactivity: agent reflect time, stream completion, multimodal events.
|
|
445
|
+
*/
|
|
446
|
+
interactivity?: {
|
|
447
|
+
agentReflectMs?: number;
|
|
448
|
+
agentStreamCompleted?: boolean;
|
|
449
|
+
multimodalEvents?: Array<{
|
|
450
|
+
kind: string;
|
|
451
|
+
at?: string;
|
|
452
|
+
meta?: Record<string, unknown>;
|
|
453
|
+
}>;
|
|
454
|
+
};
|
|
455
|
+
/**
|
|
456
|
+
* User outcome signals (Ch9-promoted first-class per PLAN-2026-07-11):
|
|
457
|
+
* flagged break, explicit rating (1-5), thumbs.
|
|
458
|
+
*
|
|
459
|
+
* `flaggedBreak` is DEPRECATED in favor of Probe.flagPersonaBreak(),
|
|
460
|
+
* which carries user attribution and emits a 'break' outcome event;
|
|
461
|
+
* the turn-level boolean remains accepted for wire compat only.
|
|
462
|
+
*/
|
|
463
|
+
userOutcome?: {
|
|
464
|
+
flaggedBreak?: boolean;
|
|
465
|
+
explicitRating?: number;
|
|
466
|
+
thumbs?: 'up' | 'down';
|
|
467
|
+
};
|
|
468
|
+
/**
|
|
469
|
+
* Propensity + candidate set (harness-supplied; see PROBE.md §2).
|
|
470
|
+
* Manual-capture callers put this in payload.propensity; captureTurn
|
|
471
|
+
* validates the Amendment S contract and hoists the valid object to
|
|
472
|
+
* this top-level field so the worker projection lands it on the
|
|
473
|
+
* read_candidates / read_propensities / selection_meta columns.
|
|
474
|
+
*/
|
|
475
|
+
propensity?: PropensityInput;
|
|
476
|
+
/**
|
|
477
|
+
* Transition signals (the human's response to the previous reply).
|
|
478
|
+
* Derived by captureTurn when the previous turn's capture time and this
|
|
479
|
+
* turn's user submit time are both known; may also be supplied directly
|
|
480
|
+
* by manual-capture callers.
|
|
481
|
+
*/
|
|
482
|
+
transition?: {
|
|
483
|
+
timeMs?: number;
|
|
484
|
+
lengthDelta?: number;
|
|
485
|
+
};
|
|
486
|
+
/**
|
|
487
|
+
* Session context forwarded on the FIRST captured turn of a session
|
|
488
|
+
* (populated by captureTurn from Probe.startSession state; the worker
|
|
489
|
+
* persists both at session find-or-create). Omitted on later turns.
|
|
490
|
+
*/
|
|
491
|
+
openedVia?: 'link' | 'notification' | 'resume' | 'direct' | 'share';
|
|
492
|
+
clientContext?: Record<string, unknown>;
|
|
493
|
+
/**
|
|
494
|
+
* RLDS episode-level provenance (Amendment R). Forwarded from the session
|
|
495
|
+
* state on every turn so downstream storage can attribute each turn to the
|
|
496
|
+
* arm/version that produced it. Populated by startSession() from either
|
|
497
|
+
* the customer-provided value or the init-time default; null when neither
|
|
498
|
+
* is set.
|
|
499
|
+
*/
|
|
500
|
+
agentId?: string;
|
|
501
|
+
experimentId?: string;
|
|
502
|
+
environmentConfigHash?: string;
|
|
503
|
+
environmentConfigLabel?: string;
|
|
504
|
+
payload: Record<string, unknown>;
|
|
505
|
+
};
|
|
506
|
+
declare const FlagPersonaBreakSchema: z.ZodObject<{
|
|
507
|
+
sessionExternalId: z.ZodString;
|
|
508
|
+
note: z.ZodOptional<z.ZodString>;
|
|
509
|
+
/** Turn index the flag refers to. Omit to attach to the session's latest turn. */
|
|
510
|
+
turnIndex: z.ZodOptional<z.ZodNumber>;
|
|
511
|
+
}, "strip", z.ZodTypeAny, {
|
|
512
|
+
sessionExternalId: string;
|
|
513
|
+
turnIndex?: number | undefined;
|
|
514
|
+
note?: string | undefined;
|
|
515
|
+
}, {
|
|
516
|
+
sessionExternalId: string;
|
|
517
|
+
turnIndex?: number | undefined;
|
|
518
|
+
note?: string | undefined;
|
|
519
|
+
}>;
|
|
520
|
+
type FlagPersonaBreakInput = z.infer<typeof FlagPersonaBreakSchema>;
|
|
521
|
+
declare const OutcomeEventEmitSchema: z.ZodObject<{
|
|
522
|
+
sessionExternalId: z.ZodString;
|
|
523
|
+
kind: z.ZodString;
|
|
524
|
+
/** Optional turn index this event is caused by. Omit to attach to latest turn. */
|
|
525
|
+
causingTurnIndex: z.ZodOptional<z.ZodNumber>;
|
|
526
|
+
/** Optional detail payload (customer-defined). */
|
|
527
|
+
detail: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
528
|
+
}, "strip", z.ZodTypeAny, {
|
|
529
|
+
kind: string;
|
|
530
|
+
sessionExternalId: string;
|
|
531
|
+
causingTurnIndex?: number | undefined;
|
|
532
|
+
detail?: Record<string, unknown> | undefined;
|
|
533
|
+
}, {
|
|
534
|
+
kind: string;
|
|
535
|
+
sessionExternalId: string;
|
|
536
|
+
causingTurnIndex?: number | undefined;
|
|
537
|
+
detail?: Record<string, unknown> | undefined;
|
|
538
|
+
}>;
|
|
539
|
+
type OutcomeEventEmit = z.infer<typeof OutcomeEventEmitSchema>;
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* HTTP client for the Probe ingest API.
|
|
543
|
+
*
|
|
544
|
+
* 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.
|
|
546
|
+
*/
|
|
547
|
+
|
|
548
|
+
type IngestClientOptions = {
|
|
549
|
+
apiKey: string;
|
|
550
|
+
endpoint: string;
|
|
551
|
+
debug: boolean;
|
|
552
|
+
};
|
|
553
|
+
declare class IngestClient {
|
|
554
|
+
private apiKey;
|
|
555
|
+
private endpoint;
|
|
556
|
+
private debug;
|
|
557
|
+
constructor(opts: IngestClientOptions);
|
|
558
|
+
/**
|
|
559
|
+
* Send a turn to the ingest API. Fire-and-log: errors are logged but never
|
|
560
|
+
* thrown. The customer's LLM path never blocks on the Probe.
|
|
561
|
+
*/
|
|
562
|
+
sendTurn(turn: CapturedTurn): Promise<void>;
|
|
563
|
+
/**
|
|
564
|
+
* Send a persona-break flag to the ingest API. Fire-and-log, same as sendTurn.
|
|
565
|
+
* Populates the `user_flagged_break` outcome column in Chapter 9c.
|
|
566
|
+
*/
|
|
567
|
+
sendFlag(deploymentSlug: string, flag: FlagPersonaBreakInput): Promise<void>;
|
|
568
|
+
/**
|
|
569
|
+
* Send a session-end event to the ingest API. Records why a session ended
|
|
570
|
+
* on the sessions.probe_session_ended_reason column. Fire-and-log.
|
|
571
|
+
*/
|
|
572
|
+
sendSessionEnd(deploymentSlug: string, end: SessionEndInput): Promise<void>;
|
|
573
|
+
/**
|
|
574
|
+
* Send an outcome event to the ingest API. Fire-and-log. Populates
|
|
575
|
+
* probe_outcome_events per Amendment I Method D.
|
|
576
|
+
*/
|
|
577
|
+
sendOutcomeEvent(deploymentSlug: string, event: OutcomeEventEmit): Promise<void>;
|
|
578
|
+
private log;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Client-context capture helper (P2 per PLAN-2026-07-11).
|
|
583
|
+
*
|
|
584
|
+
* At session start the SDK optionally collects browser/device/locale/tz
|
|
585
|
+
* metadata to send as SessionStart.clientContext. Customers control which
|
|
586
|
+
* fields land via ProbeConfig.clientContextIncludes; the default is
|
|
587
|
+
* conservative (locale + timezone + agent kind, no fingerprinting fields).
|
|
588
|
+
*
|
|
589
|
+
* Node-side calls receive process metadata; browser-side calls receive
|
|
590
|
+
* navigator + Intl.DateTimeFormat. Never leaks PII; anything that could
|
|
591
|
+
* fingerprint the user is opt-in.
|
|
592
|
+
*/
|
|
593
|
+
type ClientContextIncludes = {
|
|
594
|
+
/** window.navigator.userAgent — off by default (fingerprinting risk). */
|
|
595
|
+
userAgent?: boolean;
|
|
596
|
+
/** window.navigator.language / process.env.LANG — on by default. */
|
|
597
|
+
locale?: boolean;
|
|
598
|
+
/** Intl timezone / process TZ — on by default. */
|
|
599
|
+
timezone?: boolean;
|
|
600
|
+
/** window.screen dimensions — off by default (fingerprinting risk). */
|
|
601
|
+
screen?: boolean;
|
|
602
|
+
/** Node process metadata (platform, node version) — on by default in Node. */
|
|
603
|
+
runtime?: boolean;
|
|
604
|
+
/** Custom key/value pairs the customer wants to attach. */
|
|
605
|
+
custom?: Record<string, string | number | boolean | null>;
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Signature-phrase matcher.
|
|
610
|
+
*
|
|
611
|
+
* Per-persona regex matching for voice consistency (Day 1 per PROBE.md §2).
|
|
612
|
+
* Customer authors signature phrases at Probe.init({ persona: { signaturePhrases: [...] } }).
|
|
613
|
+
* The SDK edge or a worker computes matches per turn and includes the list
|
|
614
|
+
* of matched slugs in the turn payload.
|
|
615
|
+
*
|
|
616
|
+
* Signature phrase shape: { slug, pattern, description? }. The pattern is
|
|
617
|
+
* either a plain string (case-insensitive whole-token match) or a regex
|
|
618
|
+
* source string with optional flags. Slug is what appears in the matches
|
|
619
|
+
* array; it is not the pattern.
|
|
620
|
+
*
|
|
621
|
+
* Trivial by design. Voice consistency at the embedding level lives in the
|
|
622
|
+
* Chapter 5 Dream column (PSV representation with per-deployment STEL
|
|
623
|
+
* calibration); this is the Day-1 heuristic that ships from ingest data alone.
|
|
624
|
+
*/
|
|
625
|
+
type SignaturePhrase = {
|
|
626
|
+
/** Slug that appears in the matches array. Unique per persona. */
|
|
627
|
+
slug: string;
|
|
628
|
+
/** Plain-text phrase; matched case-insensitive with word boundaries. */
|
|
629
|
+
phrase: string;
|
|
630
|
+
description?: string;
|
|
631
|
+
} | {
|
|
632
|
+
slug: string;
|
|
633
|
+
/** Regex source string. Compiled once per matcher construction. */
|
|
634
|
+
regex: string;
|
|
635
|
+
/** Regex flags (default: 'i'). */
|
|
636
|
+
flags?: string;
|
|
637
|
+
description?: string;
|
|
638
|
+
};
|
|
639
|
+
type CompiledPhrase = {
|
|
640
|
+
slug: string;
|
|
641
|
+
pattern: RegExp;
|
|
642
|
+
};
|
|
643
|
+
/**
|
|
644
|
+
* Compile a set of signature phrases into a matcher. Compile once at
|
|
645
|
+
* Probe.init() and reuse per turn to avoid regex construction on every call.
|
|
646
|
+
*
|
|
647
|
+
* Invalid regex patterns are dropped with a stderr warning; other phrases
|
|
648
|
+
* continue to match.
|
|
649
|
+
*/
|
|
650
|
+
declare function compileSignaturePhrases(phrases: SignaturePhrase[]): CompiledPhrase[];
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* The Probe SDK main entry point.
|
|
654
|
+
*
|
|
655
|
+
* Usage:
|
|
656
|
+
* import { Sight } from '@cultured-computer/sight';
|
|
657
|
+
*
|
|
658
|
+
* Probe.init({
|
|
659
|
+
* apiKey: process.env.PROBE_API_KEY!,
|
|
660
|
+
* deployment: 'alyssa-v2',
|
|
661
|
+
* persona: { slug: 'alyssa' },
|
|
662
|
+
* });
|
|
663
|
+
*
|
|
664
|
+
* // Autocapture is now on for any subsequent OpenAI / Anthropic / etc. call.
|
|
665
|
+
*/
|
|
666
|
+
|
|
667
|
+
type ProbeState = {
|
|
668
|
+
config: ProbeConfig;
|
|
669
|
+
client: IngestClient;
|
|
670
|
+
persona: PersonaConfig | null;
|
|
671
|
+
outcomeHook: OutcomeHook | null;
|
|
672
|
+
sessions: Map<string, SessionState>;
|
|
673
|
+
/**
|
|
674
|
+
* Signature phrases compiled once per persona at init/identify time.
|
|
675
|
+
* Keyed by persona slug so per-session persona switches use the right
|
|
676
|
+
* matcher without recompiling.
|
|
677
|
+
*/
|
|
678
|
+
signatureMatchers: Map<string, ReturnType<typeof compileSignaturePhrases>>;
|
|
679
|
+
/**
|
|
680
|
+
* Interaction signals (userInputStart/Edit/Submit, userThumbs/userRating)
|
|
681
|
+
* that arrived BEFORE any session entry existed for their externalId.
|
|
682
|
+
* Flushed into the session entry when it is created (startSession or
|
|
683
|
+
* lazy-create at captureTurn). FIFO-capped at PRE_SESSION_BUFFER_MAX ids
|
|
684
|
+
* so signals for sessions that never capture a turn cannot leak memory.
|
|
685
|
+
*/
|
|
686
|
+
preSessionBuffer: Map<string, PreSessionSignals>;
|
|
687
|
+
};
|
|
688
|
+
type PreSessionSignals = {
|
|
689
|
+
pendingUserInput: SessionState['pendingUserInput'];
|
|
690
|
+
pendingUserOutcome: SessionState['pendingUserOutcome'];
|
|
691
|
+
lastUserSubmitAt: number | null;
|
|
692
|
+
};
|
|
693
|
+
type SessionState = {
|
|
694
|
+
externalId: string;
|
|
695
|
+
/** Customer's user identity from startSession; forwarded on every turn. */
|
|
696
|
+
externalUserId: string | null;
|
|
697
|
+
turnIndex: number;
|
|
698
|
+
startedAt: number;
|
|
699
|
+
personaSlug: string | null;
|
|
700
|
+
metadata: Record<string, unknown> | null;
|
|
701
|
+
openedVia: string | null;
|
|
702
|
+
clientContext: Record<string, unknown> | null;
|
|
703
|
+
agentId: string | null;
|
|
704
|
+
experimentId: string | null;
|
|
705
|
+
environmentConfigHash: string | null;
|
|
706
|
+
environmentConfigLabel: string | null;
|
|
707
|
+
/**
|
|
708
|
+
* Timestamp of the last captured agent turn. Used on the NEXT turn to
|
|
709
|
+
* derive transition.timeMs (previous agent reply → this turn's user
|
|
710
|
+
* submit) and firstKeystrokeMs (previous agent reply → typing start).
|
|
711
|
+
*/
|
|
712
|
+
lastAgentTurnAt: number | null;
|
|
713
|
+
/**
|
|
714
|
+
* Timestamp of the last userInputSubmit. Used at captureTurn to derive
|
|
715
|
+
* agentReflectMs (user submit → agent turn capture). transition.timeMs
|
|
716
|
+
* derives from the per-turn pendingUserInput.submittedAt instead, which
|
|
717
|
+
* resets on every capture, so stale submits are never reused for it.
|
|
718
|
+
*/
|
|
719
|
+
lastUserSubmitAt: number | null;
|
|
720
|
+
/**
|
|
721
|
+
* True once openedVia/clientContext have been sent with a captured turn.
|
|
722
|
+
* The worker persists session context at session find-or-create (first
|
|
723
|
+
* turn that arrives), so the SDK forwards it exactly once.
|
|
724
|
+
*/
|
|
725
|
+
sessionContextForwarded: boolean;
|
|
726
|
+
/** Per-turn user input pending on the SDK edge (unified capture helper). */
|
|
727
|
+
pendingUserInput: {
|
|
728
|
+
text?: string;
|
|
729
|
+
firstKeystrokeMs?: number;
|
|
730
|
+
editCount: number;
|
|
731
|
+
submittedAt?: number;
|
|
732
|
+
} | null;
|
|
733
|
+
/** Per-turn user outcome pending on the SDK edge (thumbs / rating). */
|
|
734
|
+
pendingUserOutcome: {
|
|
735
|
+
thumbs?: 'up' | 'down';
|
|
736
|
+
explicitRating?: number;
|
|
737
|
+
} | null;
|
|
738
|
+
};
|
|
739
|
+
declare class Probe {
|
|
740
|
+
/**
|
|
741
|
+
* Initialize the Probe SDK. Call once at process start. Subsequent calls are
|
|
742
|
+
* no-ops with a warning; re-init requires a shutdown() first.
|
|
743
|
+
*/
|
|
744
|
+
static init(config: ProbeConfigInput): void;
|
|
745
|
+
/**
|
|
746
|
+
* Run a callback inside a session context. Every LLM call made inside `fn`
|
|
747
|
+
* (through any instrumented library: OpenAI, Anthropic, LangChain, Vercel
|
|
748
|
+
* AI SDK, etc.) is automatically tagged with `sessionId` and captured as
|
|
749
|
+
* a turn on that session.
|
|
750
|
+
*
|
|
751
|
+
* Under the hood, this uses OTel Baggage propagation; the shared span
|
|
752
|
+
* processor reads the session ID from baggage when each LLM span ends.
|
|
753
|
+
*/
|
|
754
|
+
static withSession<T>(sessionId: string, fn: () => T | Promise<T>): Promise<T>;
|
|
755
|
+
/**
|
|
756
|
+
* Identify the process-level default persona. Overwrites any previously-set
|
|
757
|
+
* default. For per-session persona identification (multi-persona products),
|
|
758
|
+
* use startSession({ externalId, persona }) instead.
|
|
759
|
+
*/
|
|
760
|
+
static identifyPersona(persona: PersonaConfig): void;
|
|
761
|
+
/**
|
|
762
|
+
* Start (or update) a session with an active persona.
|
|
763
|
+
*
|
|
764
|
+
* Single-persona deployments can skip this if the init-level default is
|
|
765
|
+
* enough; the SDK will still create a session entry lazily on first turn.
|
|
766
|
+
* Multi-persona products call this at conversation start so every turn in
|
|
767
|
+
* the session inherits the selected persona.
|
|
768
|
+
*
|
|
769
|
+
* Idempotent: calling with the same externalId updates the entry.
|
|
770
|
+
*/
|
|
771
|
+
static startSession(input: SessionStart): void;
|
|
772
|
+
/**
|
|
773
|
+
* Move buffered pre-session interaction signals (recorded before any
|
|
774
|
+
* session entry existed for this externalId) onto the session entry.
|
|
775
|
+
* Session-held values win: buffered signals predate anything recorded
|
|
776
|
+
* after the entry existed.
|
|
777
|
+
*/
|
|
778
|
+
private static flushPreSessionSignals;
|
|
779
|
+
/**
|
|
780
|
+
* Get or create the pre-session signal buffer entry for an externalId.
|
|
781
|
+
* FIFO-capped: when a new id would exceed PRE_SESSION_BUFFER_MAX, the
|
|
782
|
+
* oldest id is dropped (Map preserves insertion order).
|
|
783
|
+
*/
|
|
784
|
+
private static preSessionEntry;
|
|
785
|
+
/**
|
|
786
|
+
* Compute a stable SHA-256 hex hash of prompt/config text for use as
|
|
787
|
+
* `environmentConfigHash` on Probe.startSession(). Hash is *identity* —
|
|
788
|
+
* pass the human-readable version alongside as `environmentConfigLabel`
|
|
789
|
+
* for the diff table axis (a card keyed by a3f9c2… is unreadable).
|
|
790
|
+
*
|
|
791
|
+
* Ships as a helper because inconsistent hashing across restarts breaks
|
|
792
|
+
* Chapter 8e′ Card 3 (version behavioral diff) — every customer would
|
|
793
|
+
* hash their own way and version-diff would become noise.
|
|
794
|
+
*
|
|
795
|
+
* Node runtime; use dynamic import so the SDK stays browser-friendly
|
|
796
|
+
* for callers that never touch this helper.
|
|
797
|
+
*/
|
|
798
|
+
static hashEnvironmentConfig(input: string): Promise<string>;
|
|
799
|
+
/**
|
|
800
|
+
* End a session and release its in-memory entry. Optional (sessions time out
|
|
801
|
+
* eventually), but recommended for long-running processes with many distinct
|
|
802
|
+
* conversations. If `input.endedReason` is provided the SDK sends an end
|
|
803
|
+
* event to ingest so the worker records the reason server-side.
|
|
804
|
+
*/
|
|
805
|
+
static endSession(externalId: string | SessionEndInput): Promise<void>;
|
|
806
|
+
/**
|
|
807
|
+
* User started typing — records the first-keystroke timestamp for
|
|
808
|
+
* probe_user_first_keystroke_ms derivation on captureTurn. Derivable
|
|
809
|
+
* only once a previous agent turn exists; a pre-session typing start
|
|
810
|
+
* buffers the pending-input entry without a firstKeystrokeMs value.
|
|
811
|
+
*/
|
|
812
|
+
static userInputStart(externalId: string): void;
|
|
813
|
+
/**
|
|
814
|
+
* User pressed backspace / edited — increments edit_count for
|
|
815
|
+
* probe_user_reply_edit_count.
|
|
816
|
+
*/
|
|
817
|
+
static userInputEdit(externalId: string): void;
|
|
818
|
+
/**
|
|
819
|
+
* User submitted their reply. Records the text (Presidio-scrubbed
|
|
820
|
+
* server-side before landing on probe_user_reply_text) plus the submit
|
|
821
|
+
* timestamp, which captureTurn uses to derive probe_agent_reflect_ms
|
|
822
|
+
* (submit → next agent turn) and probe_transition_time_ms (previous
|
|
823
|
+
* agent turn → submit).
|
|
824
|
+
*/
|
|
825
|
+
static userInputSubmit(externalId: string, text: string): void;
|
|
826
|
+
/** Attach a thumbs-up/down to the current turn. */
|
|
827
|
+
static userThumbs(externalId: string, thumbs: 'up' | 'down'): void;
|
|
828
|
+
/** Attach an explicit 1-5 rating to the current turn. */
|
|
829
|
+
static userRating(externalId: string, rating: number): void;
|
|
830
|
+
/**
|
|
831
|
+
* Helper: collect client context and pass it to startSession in one call.
|
|
832
|
+
*/
|
|
833
|
+
static startSessionWithContext(input: SessionStart, includes?: ClientContextIncludes): void;
|
|
834
|
+
/**
|
|
835
|
+
* 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
|
|
839
|
+
* emitOutcomeEvent() from the place where the outcome becomes known
|
|
840
|
+
* (webhook, CRM callback); it joins back by sessionExternalId.
|
|
841
|
+
*/
|
|
842
|
+
static wireOutcomeHook(hook: OutcomeHook): void;
|
|
843
|
+
/**
|
|
844
|
+
* Manually capture a turn. Instrumentation adapters call this internally;
|
|
845
|
+
* exposed for advanced customers who want to bypass autocapture.
|
|
846
|
+
*
|
|
847
|
+
* Persona resolution order for the outgoing turn payload:
|
|
848
|
+
* 1. turn.personaSlug (turn-level override)
|
|
849
|
+
* 2. sessions[externalId].personaSlug (from startSession)
|
|
850
|
+
* 3. state.persona.slug (init-level default)
|
|
851
|
+
*
|
|
852
|
+
* Signature-phrase matching runs at the SDK edge when the resolved persona
|
|
853
|
+
* has signature phrases registered. The matched slug list is attached to
|
|
854
|
+
* `turn.signaturePhraseMatches` before send.
|
|
855
|
+
*/
|
|
856
|
+
static captureTurn(turn: CapturedTurn): Promise<void>;
|
|
857
|
+
/**
|
|
858
|
+
* Emit a custom outcome event on a session. Populates probe_outcome_events
|
|
859
|
+
* with the customer-supplied `kind` string (Amendment I Method D). Use for
|
|
860
|
+
* customer-defined kinds like "purchase_complete", "handoff_to_human",
|
|
861
|
+
* "character_break_severe". Universal seed kinds (break, escalation,
|
|
862
|
+
* resolution, thumbs_*, rating_*) are also emitted by worker-side
|
|
863
|
+
* detectors automatically — call this only when the customer has a
|
|
864
|
+
* signal the worker cannot infer.
|
|
865
|
+
*/
|
|
866
|
+
static emitOutcomeEvent(input: OutcomeEventEmit): Promise<void>;
|
|
867
|
+
/**
|
|
868
|
+
* Flag a persona break for a session. Wire this to the customer's in-product
|
|
869
|
+
* "that didn't sound like you" UX. Populates the `user_flagged_break`
|
|
870
|
+
* outcome column in Chapter 9c.
|
|
871
|
+
*
|
|
872
|
+
* If `turnIndex` is omitted, the flag attaches to the session's most
|
|
873
|
+
* recent turn.
|
|
874
|
+
*/
|
|
875
|
+
static flagPersonaBreak(input: FlagPersonaBreakInput): Promise<void>;
|
|
876
|
+
/**
|
|
877
|
+
* Best-effort extraction of the response text from a captured turn's payload
|
|
878
|
+
* for signature-phrase matching. Adapters populate `payload.response.text`
|
|
879
|
+
* or `payload.text` by convention; this method looks for both.
|
|
880
|
+
*/
|
|
881
|
+
private static extractTextForMatching;
|
|
882
|
+
/**
|
|
883
|
+
* Shut down the SDK: discards the singleton state (sessions, pending
|
|
884
|
+
* user-side signals, the pre-session buffer) so init() can be called
|
|
885
|
+
* again. There is no send queue to flush — every capture awaits its own
|
|
886
|
+
* HTTP send — and instrumentation stays registered for the life of the
|
|
887
|
+
* process. Idempotent.
|
|
888
|
+
*/
|
|
889
|
+
static shutdown(): Promise<void>;
|
|
890
|
+
/** Package-internal: instrumentation adapters read this to build turns. */
|
|
891
|
+
static _getState(): ProbeState | null;
|
|
892
|
+
private static shouldSample;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
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 };
|