@pyai/sdk 0.1.2 → 0.2.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/README.md +122 -5
- package/dist/cli.d.ts +3 -2
- package/dist/cli.js +107 -2
- package/dist/index.d.ts +619 -5
- package/dist/index.js +368 -0
- package/package.json +1 -1
- package/src/cli.ts +115 -2
- package/src/index.ts +835 -5
package/dist/index.d.ts
CHANGED
|
@@ -46,18 +46,70 @@ export interface TranscriptionJob {
|
|
|
46
46
|
result_url?: string;
|
|
47
47
|
error?: string;
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Output container/codec for `audio.speech`. This is the **exact** set the
|
|
51
|
+
* server accepts on `POST /v1/audio/speech` — any other value is rejected with
|
|
52
|
+
* `400 unsupported_format`. The default (when `response_format` is omitted) is
|
|
53
|
+
* `mp3`. Omit `sample_rate` for the engine's native 24 kHz (`g711_*` is always
|
|
54
|
+
* 8 kHz).
|
|
55
|
+
*
|
|
56
|
+
* | format | rates (Hz) | Content-Type |
|
|
57
|
+
* |---|---|---|
|
|
58
|
+
* | `mp3` (default) | 8000/16000/24000/48000 | `audio/mpeg` |
|
|
59
|
+
* | `wav` | 8000/16000/24000/48000 | `audio/wav` |
|
|
60
|
+
* | `opus` | 8000/16000/24000/48000 | `audio/ogg` |
|
|
61
|
+
* | `aac` | 8000/16000/24000/48000 | `audio/aac` |
|
|
62
|
+
* | `flac` | 8000/16000/24000/48000 | `audio/flac` |
|
|
63
|
+
* | `pcm` | 8000/16000/24000/48000 | `audio/pcm` (raw int16 LE mono, no header) |
|
|
64
|
+
* | `g711_ulaw` | 8000 (forced) | `audio/basic` |
|
|
65
|
+
* | `g711_alaw` | 8000 (forced) | `audio/basic` |
|
|
66
|
+
*/
|
|
67
|
+
export type SpeechFormat = "wav" | "mp3" | "opus" | "aac" | "flac" | "pcm" | "g711_ulaw" | "g711_alaw";
|
|
68
|
+
/**
|
|
69
|
+
* The runtime list of accepted `audio.speech` formats (mirrors {@link SpeechFormat}),
|
|
70
|
+
* for building dropdowns / validating input before a request. Branch on the
|
|
71
|
+
* named values; the order matches the contract doc.
|
|
72
|
+
*/
|
|
73
|
+
export declare const SPEECH_FORMATS: readonly ["wav", "mp3", "opus", "aac", "flac", "pcm", "g711_ulaw", "g711_alaw"];
|
|
74
|
+
/** Sample rates (Hz) the server accepts for `audio.speech` (`g711_*` is always 8 kHz). */
|
|
75
|
+
export declare const SPEECH_SAMPLE_RATES: readonly [8000, 16000, 24000, 48000];
|
|
76
|
+
export type SpeechSampleRate = (typeof SPEECH_SAMPLE_RATES)[number];
|
|
49
77
|
export interface SpeechParams {
|
|
50
78
|
input: string;
|
|
51
79
|
voice?: string;
|
|
52
80
|
model?: string;
|
|
53
|
-
response_format?: "wav" | "mp3" | "opus" | "aac" | "flac" | "pcm";
|
|
54
81
|
/**
|
|
55
|
-
* Output
|
|
56
|
-
*
|
|
57
|
-
*
|
|
82
|
+
* Output container/codec, resampled+encoded server-side. One of
|
|
83
|
+
* {@link SpeechFormat} — anything else is a `400 unsupported_format`. Omit for
|
|
84
|
+
* the default of `mp3`.
|
|
85
|
+
*
|
|
86
|
+
* `g711_ulaw`/`g711_alaw` return raw 8 kHz mono G.711 — the bytes Twilio/SIP
|
|
87
|
+
* media streams expect, so you can hand the response straight to a telephony
|
|
88
|
+
* frame without a client-side resampler or μ-law encoder. `sample_rate` is
|
|
89
|
+
* forced to 8000 for those (omit it, or set exactly 8000). `pcm` is raw,
|
|
90
|
+
* headerless int16 LE mono at `sample_rate`. `mp3`/`opus` are buffered (not
|
|
91
|
+
* chunk-streamed) — use them with `speech`, not `speechStream`.
|
|
58
92
|
*/
|
|
59
|
-
|
|
93
|
+
response_format?: SpeechFormat;
|
|
94
|
+
/**
|
|
95
|
+
* Output sample rate in Hz. One of {@link SpeechSampleRate}
|
|
96
|
+
* (8000/16000/24000/48000) — anything else is a `400`. Omit for the engine's
|
|
97
|
+
* native 24 kHz; `g711_*` is always 8000 (forced). Set `8000`/`16000` for
|
|
98
|
+
* telephony pipelines, most often with `response_format: "pcm"`.
|
|
99
|
+
*/
|
|
100
|
+
sample_rate?: SpeechSampleRate;
|
|
60
101
|
speed?: number;
|
|
102
|
+
/**
|
|
103
|
+
* Deterministic sampling seed for reproducible eval runs. Forward-compatible:
|
|
104
|
+
* honored once the engine supports it (otherwise ignored server-side), so it's
|
|
105
|
+
* always safe to send.
|
|
106
|
+
*/
|
|
107
|
+
seed?: number;
|
|
108
|
+
/**
|
|
109
|
+
* Sampling temperature (lower = more deterministic). Forward-compatible —
|
|
110
|
+
* honored once the engine supports it, otherwise ignored.
|
|
111
|
+
*/
|
|
112
|
+
temperature?: number;
|
|
61
113
|
}
|
|
62
114
|
export interface CreateJobParams {
|
|
63
115
|
audio_url: string;
|
|
@@ -76,6 +128,429 @@ export interface RealtimeOptions {
|
|
|
76
128
|
/** Extra query params (e.g. format, rate). */
|
|
77
129
|
query?: Record<string, string>;
|
|
78
130
|
}
|
|
131
|
+
/** Frame `type`s emitted by the Hear streaming-STT WebSocket. */
|
|
132
|
+
export declare const HearFrameType: {
|
|
133
|
+
/** Eager live hypothesis for the current utterance. */
|
|
134
|
+
readonly Partial: "partial";
|
|
135
|
+
/** Partial whose prefix has stabilized (won't be revised). */
|
|
136
|
+
readonly PartialStable: "partial_stable";
|
|
137
|
+
/** Stable transcript at end-of-utterance (endpoint or commit). */
|
|
138
|
+
readonly SpeechFinal: "speech_final";
|
|
139
|
+
/** Corrected, full-context transcript following `speech_final`. */
|
|
140
|
+
readonly Final: "final";
|
|
141
|
+
/** Server-side fault frame. */
|
|
142
|
+
readonly Error: "error";
|
|
143
|
+
};
|
|
144
|
+
export type HearFrameType = (typeof HearFrameType)[keyof typeof HearFrameType];
|
|
145
|
+
/** WebSocket close codes used across the PyAI realtime/streaming surfaces. */
|
|
146
|
+
export declare const WSCloseCode: {
|
|
147
|
+
/** Normal closure. */
|
|
148
|
+
readonly Normal: 1000;
|
|
149
|
+
/** Auth/policy: bad key, missing scope, or revoked token. */
|
|
150
|
+
readonly PolicyViolation: 1008;
|
|
151
|
+
/** Engine/internal error. */
|
|
152
|
+
readonly InternalError: 1011;
|
|
153
|
+
/** Over the concurrency cap (PyAI-specific; mirrors HTTP 429). */
|
|
154
|
+
readonly OverCapacity: 4429;
|
|
155
|
+
};
|
|
156
|
+
export type WSCloseCode = (typeof WSCloseCode)[keyof typeof WSCloseCode];
|
|
157
|
+
/**
|
|
158
|
+
* Stable, machine-readable error `code`s (the documented contract). Branch on
|
|
159
|
+
* these. The set is treated as open — `PyAIError.code` stays `string` — so a
|
|
160
|
+
* new server code never breaks the build, but the known ones are named here.
|
|
161
|
+
*/
|
|
162
|
+
export declare const ErrorCode: {
|
|
163
|
+
readonly Unauthorized: "unauthorized";
|
|
164
|
+
readonly Forbidden: "forbidden";
|
|
165
|
+
readonly OriginNotAllowed: "origin_not_allowed";
|
|
166
|
+
readonly InvalidAgentId: "invalid_agent_id";
|
|
167
|
+
readonly CreditExhausted: "credit_exhausted";
|
|
168
|
+
readonly KeyBudgetExceeded: "key_budget_exceeded";
|
|
169
|
+
readonly InsufficientQuota: "insufficient_quota";
|
|
170
|
+
readonly RateLimitExceeded: "rate_limit_exceeded";
|
|
171
|
+
readonly ConcurrencyLimitExceeded: "concurrency_limit_exceeded";
|
|
172
|
+
readonly DailyCapExceeded: "daily_cap_exceeded";
|
|
173
|
+
readonly IdempotencyConflict: "idempotency_conflict";
|
|
174
|
+
readonly NotFound: "not_found";
|
|
175
|
+
readonly NumberInUse: "number_in_use";
|
|
176
|
+
};
|
|
177
|
+
export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
178
|
+
/** A top-3 knowledge-base passage attached to Cue (grounded) finals. */
|
|
179
|
+
export interface HearGroundingPassage {
|
|
180
|
+
content: string;
|
|
181
|
+
score: number;
|
|
182
|
+
}
|
|
183
|
+
/** Live hypothesis frame (`partial` / `partial_stable`). */
|
|
184
|
+
export interface HearPartialFrame {
|
|
185
|
+
type: "partial" | "partial_stable";
|
|
186
|
+
text: string;
|
|
187
|
+
/** Prefix that has stabilized (won't change). */
|
|
188
|
+
stable_text?: string;
|
|
189
|
+
/** The still-changing tail. */
|
|
190
|
+
active_text?: string;
|
|
191
|
+
utterance_id: string;
|
|
192
|
+
/** Audio-timeline position of the hypothesis, ms. */
|
|
193
|
+
t_ms: number;
|
|
194
|
+
}
|
|
195
|
+
/** Finalized-utterance frame (`speech_final` / `final`). */
|
|
196
|
+
export interface HearFinalFrame {
|
|
197
|
+
type: "speech_final" | "final";
|
|
198
|
+
text: string;
|
|
199
|
+
utterance_id: string;
|
|
200
|
+
t_ms: number;
|
|
201
|
+
/** Active-speech length of the utterance (the billed signal), ms. */
|
|
202
|
+
audio_ms: number;
|
|
203
|
+
/** Present only with Cue grounding enabled (top KB passages). */
|
|
204
|
+
grounding?: HearGroundingPassage[];
|
|
205
|
+
}
|
|
206
|
+
/** Server fault frame (`error`). */
|
|
207
|
+
export interface HearErrorFrame {
|
|
208
|
+
type: "error";
|
|
209
|
+
code?: string;
|
|
210
|
+
message: string;
|
|
211
|
+
}
|
|
212
|
+
export type HearFrame = HearPartialFrame | HearFinalFrame | HearErrorFrame;
|
|
213
|
+
/**
|
|
214
|
+
* Minimal structural WebSocket — matches both the browser/Node global
|
|
215
|
+
* `WebSocket` and the `ws` package, and lets tests inject a mock.
|
|
216
|
+
*/
|
|
217
|
+
export interface WebSocketLike {
|
|
218
|
+
send(data: string | ArrayBufferLike | ArrayBufferView | Blob): void;
|
|
219
|
+
close(code?: number, reason?: string): void;
|
|
220
|
+
readonly readyState: number;
|
|
221
|
+
onopen: ((ev: unknown) => void) | null;
|
|
222
|
+
onmessage: ((ev: {
|
|
223
|
+
data: unknown;
|
|
224
|
+
}) => void) | null;
|
|
225
|
+
onerror: ((ev: unknown) => void) | null;
|
|
226
|
+
onclose: ((ev: {
|
|
227
|
+
code: number;
|
|
228
|
+
reason: string;
|
|
229
|
+
}) => void) | null;
|
|
230
|
+
}
|
|
231
|
+
export type WebSocketCtor = new (url: string, protocols?: string | string[]) => WebSocketLike;
|
|
232
|
+
export interface HearStreamOptions {
|
|
233
|
+
/** Streaming STT model. Server default `pyai-hear`. */
|
|
234
|
+
model?: string;
|
|
235
|
+
/** ISO-639-1 hint, e.g. "en". */
|
|
236
|
+
language?: string;
|
|
237
|
+
/** Input PCM sample rate in Hz. Default 16000 server-side. */
|
|
238
|
+
sampleRate?: number;
|
|
239
|
+
/** Audio frame encoding. Default "pcm16". */
|
|
240
|
+
encoding?: "pcm16" | "opus";
|
|
241
|
+
/** Emit eager partial hypotheses. Default true server-side. */
|
|
242
|
+
interimResults?: boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Enable Cue knowledge-base grounding: sends `{type:"config",grounding:true}`
|
|
245
|
+
* on open, after which `speech_final`/`final` frames carry a `grounding`
|
|
246
|
+
* array. Bills a single `cue.minutes` line instead of the Hear rate.
|
|
247
|
+
*/
|
|
248
|
+
grounding?: boolean;
|
|
249
|
+
/** Extra query params merged onto the connect URL. */
|
|
250
|
+
query?: Record<string, string>;
|
|
251
|
+
/** Fired once the socket opens (after the optional grounding config). */
|
|
252
|
+
onOpen?: () => void;
|
|
253
|
+
/** Fired on `partial` / `partial_stable`. */
|
|
254
|
+
onPartial?: (frame: HearPartialFrame) => void;
|
|
255
|
+
/** Fired on `speech_final` / `final`. */
|
|
256
|
+
onFinal?: (frame: HearFinalFrame) => void;
|
|
257
|
+
/** Fired on an `error` frame or a transport-level error. */
|
|
258
|
+
onError?: (err: HearErrorFrame | Error) => void;
|
|
259
|
+
/** Fired when the socket closes (code per `WSCloseCode`). */
|
|
260
|
+
onClose?: (code: number, reason: string) => void;
|
|
261
|
+
/** Injectable WebSocket constructor (defaults to the global). */
|
|
262
|
+
webSocket?: WebSocketCtor;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* A live Hear streaming-STT session. Hides the frame protocol: stream audio
|
|
266
|
+
* with {@link HearStream.sendAudio}, get `onPartial`/`onFinal`/`onError`
|
|
267
|
+
* callbacks, force-finalize with {@link HearStream.commit}, and flush+close
|
|
268
|
+
* with {@link HearStream.close}. Construct via `pyai.audio.transcriptions.stream()`.
|
|
269
|
+
*/
|
|
270
|
+
export declare class HearStream {
|
|
271
|
+
private readonly ws;
|
|
272
|
+
private readonly opts;
|
|
273
|
+
private closed;
|
|
274
|
+
constructor(url: string, subprotocol: string, opts: HearStreamOptions);
|
|
275
|
+
private handleMessage;
|
|
276
|
+
/** Send a chunk of audio (PCM16 or opus per `encoding`). */
|
|
277
|
+
sendAudio(chunk: ArrayBufferLike | ArrayBufferView | Blob): void;
|
|
278
|
+
/** Force-finalize the current utterance (e.g. on VAD end-of-turn). */
|
|
279
|
+
commit(): void;
|
|
280
|
+
/** Close the socket; the server flushes a final for any buffered audio. */
|
|
281
|
+
close(code?: number, reason?: string): void;
|
|
282
|
+
/** The underlying socket (escape hatch for advanced use). */
|
|
283
|
+
get socket(): WebSocketLike;
|
|
284
|
+
/** Current WebSocket readyState. */
|
|
285
|
+
get readyState(): number;
|
|
286
|
+
}
|
|
287
|
+
/** Shape of `GET /v1/me`. Fields are best-effort / forward-compatible. */
|
|
288
|
+
export interface MeResponse {
|
|
289
|
+
object?: string;
|
|
290
|
+
key_id?: string;
|
|
291
|
+
org_id?: string;
|
|
292
|
+
/** "live" | "test" (a.k.a. environment). */
|
|
293
|
+
environment?: string;
|
|
294
|
+
env?: string;
|
|
295
|
+
scopes?: string[];
|
|
296
|
+
limits?: Record<string, unknown>;
|
|
297
|
+
[k: string]: unknown;
|
|
298
|
+
}
|
|
299
|
+
export interface TelephonyCapabilities {
|
|
300
|
+
voice?: boolean;
|
|
301
|
+
sms?: boolean;
|
|
302
|
+
}
|
|
303
|
+
export interface TelephonyAvailableNumber {
|
|
304
|
+
object?: "telephony.available_number";
|
|
305
|
+
/** E.164. */
|
|
306
|
+
phone_number: string;
|
|
307
|
+
country?: string;
|
|
308
|
+
area_code?: string | null;
|
|
309
|
+
locality?: string | null;
|
|
310
|
+
region?: string | null;
|
|
311
|
+
capabilities?: TelephonyCapabilities;
|
|
312
|
+
monthly_cost_cents?: number;
|
|
313
|
+
}
|
|
314
|
+
export interface TelephonyNumber {
|
|
315
|
+
object?: "telephony.number";
|
|
316
|
+
id: string;
|
|
317
|
+
/** E.164. */
|
|
318
|
+
phone_number: string;
|
|
319
|
+
country?: string;
|
|
320
|
+
area_code?: string | null;
|
|
321
|
+
capabilities?: TelephonyCapabilities;
|
|
322
|
+
/** Agent that answers inbound calls to this number. */
|
|
323
|
+
agent_id?: string | null;
|
|
324
|
+
recording?: boolean;
|
|
325
|
+
monthly_cost_cents?: number;
|
|
326
|
+
status?: "active" | "released";
|
|
327
|
+
created_at?: number;
|
|
328
|
+
released_at?: number | null;
|
|
329
|
+
}
|
|
330
|
+
export type TraceVerdict = "PASS" | "WARN" | "FAIL";
|
|
331
|
+
export type TraceSeverity = "low" | "medium" | "high" | "critical";
|
|
332
|
+
export interface TraceInteraction {
|
|
333
|
+
object?: "trace.interaction";
|
|
334
|
+
/** call_id */
|
|
335
|
+
id: string;
|
|
336
|
+
agent_id?: string | null;
|
|
337
|
+
product?: string | null;
|
|
338
|
+
verdict: TraceVerdict;
|
|
339
|
+
findings?: number;
|
|
340
|
+
blocked_turns?: number;
|
|
341
|
+
modified_turns?: number;
|
|
342
|
+
packs_enforced?: string;
|
|
343
|
+
scored_at?: number;
|
|
344
|
+
}
|
|
345
|
+
export interface TraceFinding {
|
|
346
|
+
object?: "trace.finding";
|
|
347
|
+
id: string;
|
|
348
|
+
/** call_id */
|
|
349
|
+
interaction_id: string;
|
|
350
|
+
agent_id?: string | null;
|
|
351
|
+
check_id: string;
|
|
352
|
+
severity: TraceSeverity;
|
|
353
|
+
verdict?: string;
|
|
354
|
+
confidence?: number;
|
|
355
|
+
action?: "flag" | "preempt_next" | "escalate";
|
|
356
|
+
speaker?: "agent" | "caller" | "any" | null;
|
|
357
|
+
reason?: string;
|
|
358
|
+
preempt_instruction?: string | null;
|
|
359
|
+
at_t?: number | null;
|
|
360
|
+
tier?: number;
|
|
361
|
+
}
|
|
362
|
+
/** A tool invocation recorded on a timeline turn. */
|
|
363
|
+
export interface TraceToolCall {
|
|
364
|
+
name: string;
|
|
365
|
+
/** Arguments the agent passed (engine-shaped JSON). */
|
|
366
|
+
args?: unknown;
|
|
367
|
+
/** Tool result returned to the agent (engine-shaped JSON). */
|
|
368
|
+
result?: unknown;
|
|
369
|
+
/** Audio-timeline position of the call, ms. */
|
|
370
|
+
t_ms?: number;
|
|
371
|
+
}
|
|
372
|
+
/** Barge-in timing for a timeline turn. */
|
|
373
|
+
export interface TraceBargeMetrics {
|
|
374
|
+
/** Time from caller speech onset to barge-in detection, ms. */
|
|
375
|
+
detect_ms?: number;
|
|
376
|
+
/** Whether the agent cleanly recovered after the barge-in. */
|
|
377
|
+
recovered?: boolean;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Known timeline-turn roles. Left open (see {@link TraceTimelineTurn.role}) so a
|
|
381
|
+
* new server-side role never breaks the build — branch defensively.
|
|
382
|
+
*/
|
|
383
|
+
export type TraceTimelineRole = "agent" | "caller" | "system" | "tool";
|
|
384
|
+
/** One turn of a per-call operational timeline (eval scorecard-v1). */
|
|
385
|
+
export interface TraceTimelineTurn {
|
|
386
|
+
/** Monotonic turn index within the call. */
|
|
387
|
+
seq: number;
|
|
388
|
+
/** Audio-timeline position of the turn, ms. */
|
|
389
|
+
t_ms: number;
|
|
390
|
+
/** Who spoke/acted this turn. Open-ended for forward-compat. */
|
|
391
|
+
role: TraceTimelineRole | (string & {});
|
|
392
|
+
/** Transcript/text for the turn, when available. */
|
|
393
|
+
text?: string;
|
|
394
|
+
/** Time-to-first-audio for the turn (latency scoring), ms. */
|
|
395
|
+
ttfb_ms?: number;
|
|
396
|
+
/** Turn-detection (endpointing) latency, ms. */
|
|
397
|
+
endpointing_ms?: number;
|
|
398
|
+
/** Barge-in detect/recovery timing for the turn. */
|
|
399
|
+
barge?: TraceBargeMetrics;
|
|
400
|
+
/** Tool calls made during the turn (tool-use scoring). */
|
|
401
|
+
tool_calls?: TraceToolCall[];
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Aggregate per-call quality metrics (eval scorecard-v1). All optional and
|
|
405
|
+
* forward-compatible — present once the engine emits them.
|
|
406
|
+
*/
|
|
407
|
+
export interface QualityMetrics {
|
|
408
|
+
/** Word error rate vs. reference transcript, 0–1 (lower is better). */
|
|
409
|
+
wer?: number;
|
|
410
|
+
/** Representative time-to-first-audio across turns, ms. */
|
|
411
|
+
ttfb_ms?: number;
|
|
412
|
+
/** 95th-percentile end-to-end turn latency, ms. */
|
|
413
|
+
turn_p95_ms?: number;
|
|
414
|
+
/** Barge-in recovery rate, 0–1. */
|
|
415
|
+
barge_recovery?: number;
|
|
416
|
+
/** Task-success score, 0–1. */
|
|
417
|
+
task_success?: number;
|
|
418
|
+
/** Composite voice-agent quality index (engine-defined scale). */
|
|
419
|
+
vaqi?: number;
|
|
420
|
+
[k: string]: unknown;
|
|
421
|
+
}
|
|
422
|
+
export interface TraceInteractionDetail extends TraceInteraction {
|
|
423
|
+
/** Hash-chain link proving the record is unaltered. */
|
|
424
|
+
audit_hash?: string;
|
|
425
|
+
scorecard?: Record<string, unknown>;
|
|
426
|
+
tier2_findings?: TraceFinding[];
|
|
427
|
+
/**
|
|
428
|
+
* Scorecard schema version, e.g. `"trace-scorecard-v1"`. Present once the
|
|
429
|
+
* engine emits the eval block below.
|
|
430
|
+
*/
|
|
431
|
+
scorecard_version?: string;
|
|
432
|
+
/**
|
|
433
|
+
* Per-call operational timeline. Forward-compatible: empty/undefined until
|
|
434
|
+
* the engine emits per-turn timing (Ask 1 of the evals engine plan).
|
|
435
|
+
*/
|
|
436
|
+
timeline?: TraceTimelineTurn[];
|
|
437
|
+
/** Aggregate per-call quality metrics. Forward-compatible (see above). */
|
|
438
|
+
quality_metrics?: QualityMetrics;
|
|
439
|
+
}
|
|
440
|
+
export interface TraceViolation {
|
|
441
|
+
object?: "trace.violation";
|
|
442
|
+
id: string;
|
|
443
|
+
/** call_id */
|
|
444
|
+
interaction_id: string;
|
|
445
|
+
agent_id?: string | null;
|
|
446
|
+
rule_id: string;
|
|
447
|
+
pack_id?: string | null;
|
|
448
|
+
severity: TraceSeverity;
|
|
449
|
+
action_taken?: "pass" | "flag" | "modify" | "block";
|
|
450
|
+
citation?: string;
|
|
451
|
+
reason?: string;
|
|
452
|
+
at_t?: number | null;
|
|
453
|
+
}
|
|
454
|
+
export interface TraceConfigInput {
|
|
455
|
+
agent_id?: string;
|
|
456
|
+
enabled?: boolean;
|
|
457
|
+
channels?: Array<"voice" | "text">;
|
|
458
|
+
/** Map of pack_id → { enabled, version }. */
|
|
459
|
+
rule_packs?: Record<string, {
|
|
460
|
+
enabled?: boolean;
|
|
461
|
+
version?: string | null;
|
|
462
|
+
}>;
|
|
463
|
+
guardrails?: Record<string, unknown>;
|
|
464
|
+
[k: string]: unknown;
|
|
465
|
+
}
|
|
466
|
+
export interface TraceConfig {
|
|
467
|
+
object?: "trace.config";
|
|
468
|
+
agent_id?: string | null;
|
|
469
|
+
enabled?: boolean;
|
|
470
|
+
mode?: "warn" | "modify" | "block" | "human_handoff";
|
|
471
|
+
etag?: string;
|
|
472
|
+
updated_at?: number;
|
|
473
|
+
config?: TraceConfigInput;
|
|
474
|
+
}
|
|
475
|
+
export interface TraceRulePackSpec {
|
|
476
|
+
pack_id: string;
|
|
477
|
+
version: string;
|
|
478
|
+
jurisdiction?: string;
|
|
479
|
+
legal_status?: string;
|
|
480
|
+
rules: Array<Record<string, unknown>>;
|
|
481
|
+
}
|
|
482
|
+
export interface TraceRulePack {
|
|
483
|
+
object?: "trace.rule_pack";
|
|
484
|
+
id?: string;
|
|
485
|
+
pack_id: string;
|
|
486
|
+
version?: string;
|
|
487
|
+
builtin?: boolean;
|
|
488
|
+
jurisdiction?: string | null;
|
|
489
|
+
legal_status?: string | null;
|
|
490
|
+
etag?: string;
|
|
491
|
+
status?: "active" | "deprecated";
|
|
492
|
+
created_at?: number;
|
|
493
|
+
/** The authored DSL (only on the single-pack GET). */
|
|
494
|
+
spec?: Record<string, unknown>;
|
|
495
|
+
}
|
|
496
|
+
export interface TraceExposure {
|
|
497
|
+
object?: "trace.exposure";
|
|
498
|
+
window_days?: number;
|
|
499
|
+
interactions_scanned?: number;
|
|
500
|
+
with_a_gap?: number;
|
|
501
|
+
gap_rate?: number;
|
|
502
|
+
by_rule?: Array<{
|
|
503
|
+
rule_id: string;
|
|
504
|
+
pack_id?: string | null;
|
|
505
|
+
count: number;
|
|
506
|
+
rate: number;
|
|
507
|
+
}>;
|
|
508
|
+
by_verdict?: {
|
|
509
|
+
PASS?: number;
|
|
510
|
+
WARN?: number;
|
|
511
|
+
FAIL?: number;
|
|
512
|
+
};
|
|
513
|
+
top_exposure?: string | null;
|
|
514
|
+
}
|
|
515
|
+
export interface RecapConfigInput {
|
|
516
|
+
enabled?: boolean;
|
|
517
|
+
webhook_url?: string | null;
|
|
518
|
+
default_pack_id?: string;
|
|
519
|
+
}
|
|
520
|
+
export interface RecapConfig {
|
|
521
|
+
object?: "recap.config";
|
|
522
|
+
enabled?: boolean;
|
|
523
|
+
webhook_url?: string | null;
|
|
524
|
+
default_pack_id?: string;
|
|
525
|
+
updated_at?: number;
|
|
526
|
+
}
|
|
527
|
+
export interface RecapCallSummary {
|
|
528
|
+
object?: "recap.call";
|
|
529
|
+
call_id: string;
|
|
530
|
+
pack_id?: string;
|
|
531
|
+
status?: "pending" | "processing" | "complete" | "failed";
|
|
532
|
+
call_duration_s?: number | null;
|
|
533
|
+
created_at?: number;
|
|
534
|
+
completed_at?: number | null;
|
|
535
|
+
}
|
|
536
|
+
export interface RecapCall extends RecapCallSummary {
|
|
537
|
+
record?: unknown;
|
|
538
|
+
error?: string | null;
|
|
539
|
+
crm_write_status?: string | null;
|
|
540
|
+
}
|
|
541
|
+
export interface RecapCallTriggerInput {
|
|
542
|
+
utterances: Array<{
|
|
543
|
+
speaker_role?: "agent" | "customer";
|
|
544
|
+
text: string;
|
|
545
|
+
offset_s?: number;
|
|
546
|
+
duration_s?: number;
|
|
547
|
+
}>;
|
|
548
|
+
pack_id?: string;
|
|
549
|
+
call_duration_s?: number;
|
|
550
|
+
call_direction?: "inbound" | "outbound";
|
|
551
|
+
customer_name?: string;
|
|
552
|
+
crm_fields?: Record<string, unknown>;
|
|
553
|
+
}
|
|
79
554
|
export declare class PyAI {
|
|
80
555
|
private readonly apiKey;
|
|
81
556
|
private readonly baseURL;
|
|
@@ -86,6 +561,9 @@ export declare class PyAI {
|
|
|
86
561
|
private request;
|
|
87
562
|
private toError;
|
|
88
563
|
private getJson;
|
|
564
|
+
private postJson;
|
|
565
|
+
private putJson;
|
|
566
|
+
private deleteReq;
|
|
89
567
|
models: {
|
|
90
568
|
list: () => Promise<ListResponse<{
|
|
91
569
|
id: string;
|
|
@@ -116,10 +594,26 @@ export declare class PyAI {
|
|
|
116
594
|
file: Blob;
|
|
117
595
|
filename?: string;
|
|
118
596
|
model?: string;
|
|
597
|
+
language?: string;
|
|
598
|
+
response_format?: "json" | "text" | "verbose_json";
|
|
599
|
+
/**
|
|
600
|
+
* Deterministic seed for reproducible eval runs. Forward-compatible:
|
|
601
|
+
* honored once the engine supports it, otherwise ignored.
|
|
602
|
+
*/
|
|
603
|
+
seed?: number;
|
|
604
|
+
/** Sampling temperature. Forward-compatible (honored when supported). */
|
|
605
|
+
temperature?: number;
|
|
119
606
|
}) => Promise<{
|
|
120
607
|
text: string;
|
|
121
608
|
[k: string]: unknown;
|
|
122
609
|
}>;
|
|
610
|
+
/**
|
|
611
|
+
* Open a live streaming-STT WebSocket (Hear). Hides the frame protocol
|
|
612
|
+
* behind `onPartial`/`onFinal`/`onError`; stream audio with `sendAudio`,
|
|
613
|
+
* force-finalize with `commit()`, flush+close with `close()`. Set
|
|
614
|
+
* `grounding: true` for Cue (turn detection + KB context).
|
|
615
|
+
*/
|
|
616
|
+
stream: (opts?: HearStreamOptions) => HearStream;
|
|
123
617
|
};
|
|
124
618
|
};
|
|
125
619
|
transcriptionJobs: {
|
|
@@ -132,10 +626,130 @@ export declare class PyAI {
|
|
|
132
626
|
cursor?: string;
|
|
133
627
|
}) => Promise<ListResponse<TranscriptionJob>>;
|
|
134
628
|
};
|
|
629
|
+
/**
|
|
630
|
+
* Introspect the calling key: scopes, environment, and limits. Useful for a
|
|
631
|
+
* preflight/doctor check. (New route; older deployments may 404 — handle it.)
|
|
632
|
+
*/
|
|
633
|
+
me: () => Promise<MeResponse>;
|
|
634
|
+
clones: {
|
|
635
|
+
/** List the org's cloned voices. */
|
|
636
|
+
list: () => Promise<ListResponse<Voice>>;
|
|
637
|
+
/** Enroll a custom voice from reference audio (>= ~10s). Scope `voice:clone`. */
|
|
638
|
+
create: (params: {
|
|
639
|
+
name: string;
|
|
640
|
+
file: Blob;
|
|
641
|
+
filename?: string;
|
|
642
|
+
}) => Promise<Voice>;
|
|
643
|
+
/**
|
|
644
|
+
* Fetch a single cloned voice by id. The API exposes no GET-by-id for
|
|
645
|
+
* clones, so this filters `list()` client-side and throws a 404 `PyAIError`
|
|
646
|
+
* when the id isn't found.
|
|
647
|
+
*/
|
|
648
|
+
get: (id: string) => Promise<Voice>;
|
|
649
|
+
/** Delete a cloned voice (tenant-isolated). Scope `voice:clone`. */
|
|
650
|
+
delete: (id: string) => Promise<void>;
|
|
651
|
+
};
|
|
652
|
+
telephony: {
|
|
653
|
+
numbers: {
|
|
654
|
+
/** Search the carrier's available US local numbers. */
|
|
655
|
+
available: (params?: {
|
|
656
|
+
areaCode?: string;
|
|
657
|
+
contains?: string;
|
|
658
|
+
limit?: number;
|
|
659
|
+
}) => Promise<ListResponse<TelephonyAvailableNumber>>;
|
|
660
|
+
/** List the org's managed numbers (active only unless `includeReleased`). */
|
|
661
|
+
list: (params?: {
|
|
662
|
+
includeReleased?: boolean;
|
|
663
|
+
}) => Promise<ListResponse<TelephonyNumber>>;
|
|
664
|
+
/** Provision (buy) a specific available number, optionally bound to an agent. */
|
|
665
|
+
buy: (params: {
|
|
666
|
+
phone_number: string;
|
|
667
|
+
agent_id?: string | null;
|
|
668
|
+
}) => Promise<TelephonyNumber>;
|
|
669
|
+
/** Route a number to an agent (`agentId: null` to unassign). */
|
|
670
|
+
assign: (id: string, agentId: string | null) => Promise<TelephonyNumber>;
|
|
671
|
+
/** Release a number back to the carrier (idempotent). */
|
|
672
|
+
release: (id: string) => Promise<TelephonyNumber>;
|
|
673
|
+
};
|
|
674
|
+
};
|
|
675
|
+
trace: {
|
|
676
|
+
interactions: {
|
|
677
|
+
/** List scanned interactions (scorecards), newest first. Scope `trace:read`. */
|
|
678
|
+
list: (params?: {
|
|
679
|
+
verdict?: TraceVerdict;
|
|
680
|
+
agentId?: string;
|
|
681
|
+
limit?: number;
|
|
682
|
+
cursor?: string;
|
|
683
|
+
}) => Promise<ListResponse<TraceInteraction>>;
|
|
684
|
+
/** The full per-call evidence view (findings, redactions, audit hash). */
|
|
685
|
+
get: (id: string) => Promise<TraceInteractionDetail>;
|
|
686
|
+
};
|
|
687
|
+
violations: {
|
|
688
|
+
/** Drill-down of every fired Tier-0 rule across scorecards. Scope `trace:read`. */
|
|
689
|
+
list: (params?: {
|
|
690
|
+
ruleId?: string;
|
|
691
|
+
severity?: TraceSeverity;
|
|
692
|
+
interactionId?: string;
|
|
693
|
+
limit?: number;
|
|
694
|
+
cursor?: string;
|
|
695
|
+
}) => Promise<ListResponse<TraceViolation>>;
|
|
696
|
+
};
|
|
697
|
+
findings: {
|
|
698
|
+
/** List Tier-2 (async semantic) findings — advisory, non-blocking. Scope `trace:read`. */
|
|
699
|
+
list: (params?: {
|
|
700
|
+
checkId?: string;
|
|
701
|
+
action?: "flag" | "preempt_next" | "escalate";
|
|
702
|
+
severity?: TraceSeverity;
|
|
703
|
+
interactionId?: string;
|
|
704
|
+
limit?: number;
|
|
705
|
+
cursor?: string;
|
|
706
|
+
}) => Promise<ListResponse<TraceFinding>>;
|
|
707
|
+
};
|
|
708
|
+
config: {
|
|
709
|
+
/** Read per-agent Trace config (omit `agentId` for the org default). Scope `trace:configure`. */
|
|
710
|
+
get: (agentId?: string) => Promise<TraceConfig>;
|
|
711
|
+
/** Upsert per-agent Trace config. Scope `trace:configure`. */
|
|
712
|
+
set: (input: TraceConfigInput) => Promise<TraceConfig>;
|
|
713
|
+
};
|
|
714
|
+
rulePacks: {
|
|
715
|
+
/** List built-in + custom rule packs. Scope `trace:configure`. */
|
|
716
|
+
list: () => Promise<ListResponse<TraceRulePack>>;
|
|
717
|
+
/** Upload a custom rule pack (Trace DSL). Scope `trace:configure`. */
|
|
718
|
+
create: (spec: TraceRulePackSpec) => Promise<TraceRulePack>;
|
|
719
|
+
/** Resolve a rule pack by id (latest active, or pin `version`). */
|
|
720
|
+
get: (id: string, version?: string) => Promise<TraceRulePack>;
|
|
721
|
+
};
|
|
722
|
+
/** Compliance exposure summary over a trailing window. Scope `trace:read`. */
|
|
723
|
+
exposure: (windowDays?: number) => Promise<TraceExposure>;
|
|
724
|
+
/**
|
|
725
|
+
* Convenience: the per-call operational timeline (eval scorecard-v1). A thin
|
|
726
|
+
* wrapper over `interactions.get(id)` that returns the `timeline` array, or
|
|
727
|
+
* `[]` when the engine hasn't emitted one yet (forward-compatible). Scope
|
|
728
|
+
* `trace:read`.
|
|
729
|
+
*/
|
|
730
|
+
callTimeline: (id: string) => Promise<TraceTimelineTurn[]>;
|
|
731
|
+
};
|
|
732
|
+
recap: {
|
|
733
|
+
config: {
|
|
734
|
+
get: () => Promise<RecapConfig>;
|
|
735
|
+
set: (input: RecapConfigInput) => Promise<RecapConfig>;
|
|
736
|
+
};
|
|
737
|
+
calls: {
|
|
738
|
+
list: (params?: {
|
|
739
|
+
limit?: number;
|
|
740
|
+
cursor?: string;
|
|
741
|
+
status?: string;
|
|
742
|
+
}) => Promise<ListResponse<RecapCallSummary>>;
|
|
743
|
+
get: (callId: string) => Promise<RecapCall>;
|
|
744
|
+
trigger: (callId: string, input: RecapCallTriggerInput) => Promise<RecapCallSummary>;
|
|
745
|
+
};
|
|
746
|
+
};
|
|
135
747
|
/** Build the realtime WebSocket URL for the chosen product. */
|
|
136
748
|
realtimeURL(opts?: RealtimeOptions): string;
|
|
137
749
|
/** The subprotocol that carries the key on a WS upgrade (browser-safe auth). */
|
|
138
750
|
realtimeSubprotocol(): string;
|
|
751
|
+
/** Build the Hear streaming-STT WebSocket URL (`/v1/audio/transcriptions/stream`). */
|
|
752
|
+
hearStreamURL(opts?: HearStreamOptions): string;
|
|
139
753
|
/**
|
|
140
754
|
* Open a realtime WebSocket. Uses the global WebSocket (browser, Node 22+).
|
|
141
755
|
* The key travels as a subprotocol so it works from the browser without
|