@aiqa/sdk 2.1.0-develop.3 → 2.1.0-develop.5
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 +302 -202
- package/dist/browser/browser.d.ts +114 -97
- package/dist/browser/browser.js +17 -1
- package/dist/browser/browser.js.map +1 -1
- package/dist/node/node.d.ts +114 -97
- package/dist/node/node.js +17 -1
- package/dist/node/node.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,16 +1,72 @@
|
|
|
1
1
|
import { Socket } from 'socket.io-client';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Overall result for the call: `critical_errors` if a fact you sent with
|
|
5
|
+
* `critical: true` failed, `errors` if any other fact failed, else
|
|
6
|
+
* `no_errors`.
|
|
7
|
+
*
|
|
8
|
+
* Only answers count. A question that was never asked never raises it, so a
|
|
9
|
+
* call where nothing was asked reads `no_errors`.
|
|
10
|
+
*
|
|
11
|
+
* Not the same as `VerificationStatus`, which describes a single fact.
|
|
12
|
+
*/
|
|
13
|
+
type ApplicationVerificationStatus = "no_errors" | "errors" | "critical_errors";
|
|
14
|
+
/**
|
|
15
|
+
* How the facts on one application are counted up. None of these is a count of
|
|
16
|
+
* facts that passed, and they overlap — to show a pass count, count the facts
|
|
17
|
+
* whose `verification_status` is `matched` in `getFacts()`.
|
|
18
|
+
*/
|
|
19
|
+
type ApplicationVerificationSummary = {
|
|
20
|
+
status: ApplicationVerificationStatus;
|
|
21
|
+
/** Facts whose answer did not match the expected one. */
|
|
22
|
+
count_errors: number;
|
|
23
|
+
/** The facts in `count_errors` that you sent with `critical: true`. */
|
|
24
|
+
count_critical_errors: number;
|
|
25
|
+
/**
|
|
26
|
+
* Every fact on the application, checked or not. The other counters are
|
|
27
|
+
* subsets of it and can overlap each other, so no subtraction from
|
|
28
|
+
* `count_total` yields a pass count.
|
|
29
|
+
*/
|
|
30
|
+
count_total: number;
|
|
31
|
+
/**
|
|
32
|
+
* Facts whose question was never asked. Excludes the still-pending ones, but
|
|
33
|
+
* overlaps `count_errors`: a fact never asked that came back wrong is in both.
|
|
34
|
+
*/
|
|
35
|
+
count_not_asked: number;
|
|
36
|
+
/** The facts in `count_not_asked` that you sent with `critical: true`. */
|
|
37
|
+
count_critical_not_asked: number;
|
|
38
|
+
/**
|
|
39
|
+
* Facts added but not resolved yet. During a live call most facts sit here
|
|
40
|
+
* and move into the other counters as their results arrive.
|
|
41
|
+
*/
|
|
42
|
+
count_pending: number;
|
|
43
|
+
/**
|
|
44
|
+
* Facts flagged as suspicious when the call is reviewed — for instance the
|
|
45
|
+
* agent leading the customer to the expected answer. Independent of the
|
|
46
|
+
* answer: a matched fact can be flagged. Reads 0 while the call is running.
|
|
47
|
+
*/
|
|
48
|
+
count_suspicious: number;
|
|
49
|
+
};
|
|
3
50
|
type Application = {
|
|
4
51
|
application_id: string;
|
|
5
52
|
client_name: string;
|
|
6
53
|
client_phone_number: string;
|
|
7
54
|
agent_id: string;
|
|
55
|
+
/** Comes back empty. Set an agent name with `updateConversation()`. */
|
|
8
56
|
agent_first_name: string;
|
|
57
|
+
/** Comes back empty. Set an agent name with `updateConversation()`. */
|
|
9
58
|
agent_last_name: string;
|
|
59
|
+
/**
|
|
60
|
+
* How the call is going so far. When it is missing there is no summary —
|
|
61
|
+
* which is not the same as all zeros — and the fields above may then be the
|
|
62
|
+
* ones from authentication, without an `updateConversation()` you made since.
|
|
63
|
+
*/
|
|
64
|
+
verification?: ApplicationVerificationSummary;
|
|
10
65
|
};
|
|
11
66
|
declare enum Methods {
|
|
12
67
|
AUTHENTICATE = "AUTHENTICATE",
|
|
13
68
|
GET_FACTS = "GET_FACTS",
|
|
69
|
+
GET_APPLICATION = "GET_APPLICATION",
|
|
14
70
|
START_RECORDING = "START_RECORDING",
|
|
15
71
|
STOP_RECORDING = "STOP_RECORDING",
|
|
16
72
|
IS_RECORDING = "IS_RECORDING",
|
|
@@ -41,7 +97,7 @@ type UpdateConversationInput = {
|
|
|
41
97
|
advisorName?: string;
|
|
42
98
|
agentGroups?: string[];
|
|
43
99
|
};
|
|
44
|
-
/**
|
|
100
|
+
/** Only the fields you sent come back in `conversation`. */
|
|
45
101
|
type UpdateConversationResult = {
|
|
46
102
|
success: boolean;
|
|
47
103
|
conversation: {
|
|
@@ -86,11 +142,10 @@ type ApplicationFactAnswerFormat = {
|
|
|
86
142
|
type ApplicationFactInput = {
|
|
87
143
|
id: string;
|
|
88
144
|
/**
|
|
89
|
-
* Stable identifier for the underlying question, shared across applications
|
|
90
|
-
* conversations. When provided it
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* dashboard are scoped per `questionId`.
|
|
145
|
+
* Stable identifier for the underlying question, shared across applications
|
|
146
|
+
* and conversations. When provided it identifies the question instead of
|
|
147
|
+
* `id`. Keep it consistent across calls: whatever AIQA has tuned for a
|
|
148
|
+
* question is attached to this identity.
|
|
94
149
|
*/
|
|
95
150
|
questionId?: string;
|
|
96
151
|
question: string;
|
|
@@ -99,35 +154,41 @@ type ApplicationFactInput = {
|
|
|
99
154
|
category_id?: string;
|
|
100
155
|
category_name?: string;
|
|
101
156
|
language?: string;
|
|
157
|
+
/**
|
|
158
|
+
* Mark the question critical: its failures land in `count_critical_errors`,
|
|
159
|
+
* and one of them sets the call's `status` to `critical_errors`.
|
|
160
|
+
*/
|
|
102
161
|
critical?: boolean;
|
|
103
162
|
is_skipped?: boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Your own identifiers for this fact — a form field ID, a section name,
|
|
165
|
+
* anything that lets your UI map the result back to the right place.
|
|
166
|
+
* `getFacts()` returns it unchanged — `{}` for a fact you added without
|
|
167
|
+
* one — and it plays no part in verification.
|
|
168
|
+
*
|
|
169
|
+
* Keys and values must all be strings, and each value is limited to 1024
|
|
170
|
+
* characters. A payload that breaks either rule is rejected.
|
|
171
|
+
*/
|
|
104
172
|
metadata?: Record<string, string>;
|
|
105
173
|
};
|
|
106
174
|
type QuestionStatus = "searching" | "asked" | "not_asked";
|
|
107
175
|
/**
|
|
108
|
-
* Per-fact verification state.
|
|
176
|
+
* Per-fact verification state. Handle any value you don't recognize as
|
|
177
|
+
* `processing`.
|
|
109
178
|
*
|
|
110
|
-
*
|
|
111
|
-
* the
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* - `
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* - `
|
|
122
|
-
*
|
|
123
|
-
* clarifications (e.g. spellings, "I mean…");
|
|
124
|
-
* resolves to `matched`/`unmatched`
|
|
125
|
-
* - `pending_confirmation_unmatched` same as above but the held verdict is
|
|
126
|
-
* `unmatched`; UI can show "we heard X but it
|
|
127
|
-
* doesn't match, waiting to confirm" instead
|
|
128
|
-
* of a hard red verdict
|
|
129
|
-
* - `matched` terminal: answer matched expected
|
|
130
|
-
* - `unmatched` terminal: budget exhausted with no match
|
|
179
|
+
* - `processing` queued, or nothing to go on yet
|
|
180
|
+
* - `awaiting_question` the agent hasn't asked the question yet
|
|
181
|
+
* - `awaiting_answer` asked, the customer hasn't answered yet
|
|
182
|
+
* - `partial` partial evidence so far (e.g. "305" of "30521")
|
|
183
|
+
* - `pending_confirmation_matched` a matching answer is held briefly in case
|
|
184
|
+
* the customer corrects it mid-answer
|
|
185
|
+
* (spellings, "I mean…"); resolves to
|
|
186
|
+
* `matched`/`unmatched`
|
|
187
|
+
* - `pending_confirmation_unmatched` same, with an unmatched answer held; show
|
|
188
|
+
* "we heard X but it doesn't match, waiting
|
|
189
|
+
* to confirm" rather than a hard result
|
|
190
|
+
* - `matched` final: the answer matched
|
|
191
|
+
* - `unmatched` final: the answer did not match
|
|
131
192
|
*/
|
|
132
193
|
type VerificationStatus = "processing" | "awaiting_question" | "awaiting_answer" | "partial" | "pending_confirmation_matched" | "pending_confirmation_unmatched" | "matched" | "unmatched";
|
|
133
194
|
type ApplicationFact = ApplicationFactInput & {
|
|
@@ -138,7 +199,7 @@ type ApplicationFact = ApplicationFactInput & {
|
|
|
138
199
|
flagged: boolean;
|
|
139
200
|
};
|
|
140
201
|
interface AddFactResult {
|
|
141
|
-
/** Conversation the fact was attached to.
|
|
202
|
+
/** Conversation the fact was attached to. */
|
|
142
203
|
conversation_id?: string;
|
|
143
204
|
/** Echo of the original question text from the fact input. */
|
|
144
205
|
question?: string;
|
|
@@ -149,48 +210,33 @@ interface AddFactResult {
|
|
|
149
210
|
is_valid_answer: boolean;
|
|
150
211
|
question_asked?: boolean;
|
|
151
212
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* Renamed from `match_score` to disambiguate from the answer-side score.
|
|
213
|
+
* How closely the agent's utterance matched the expected question, on a 0–1
|
|
214
|
+
* or a 0–100 scale. Higher is closer.
|
|
155
215
|
*/
|
|
156
216
|
question_match_score?: number;
|
|
157
217
|
/**
|
|
158
|
-
* 0–1 score
|
|
159
|
-
*
|
|
160
|
-
* (numeric-prefix ratio, matched-components ratio). Undefined when no
|
|
161
|
-
* partial signal exists or for terminal results before this rolls out.
|
|
218
|
+
* 0–1 score for how closely the customer's answer matched the expected one.
|
|
219
|
+
* Undefined when there is no partial signal to score.
|
|
162
220
|
*/
|
|
163
221
|
answer_match_score?: number;
|
|
164
222
|
metadata?: Record<string, string>;
|
|
165
223
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* resolves on terminals. Optional during the rollout window for
|
|
169
|
-
* backwards compatibility with older backends.
|
|
224
|
+
* The final state: `matched` or `unmatched` whenever it is present. Fall
|
|
225
|
+
* back to `is_valid_answer` when it is missing.
|
|
170
226
|
*/
|
|
171
227
|
verification_status?: VerificationStatus;
|
|
172
228
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* generalise to addresses, names, dates, etc.
|
|
229
|
+
* Component labels describing which parts of the expected answer
|
|
230
|
+
* matched. Currently `["prefix"]` / `["suffix"]` for numeric facts;
|
|
231
|
+
* treat the set as open-ended.
|
|
177
232
|
*/
|
|
178
233
|
matched_components?: string[];
|
|
179
234
|
missing_components?: string[];
|
|
180
235
|
}
|
|
181
236
|
/**
|
|
182
|
-
* Payload of the `FACT_VERIFIED`
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
* non-terminal (`partial`, `awaiting_question`, `awaiting_answer`,
|
|
186
|
-
* `pending_confirmation_matched`, `pending_confirmation_unmatched`,
|
|
187
|
-
* `processing`) AND terminal (`matched`, `unmatched`).
|
|
188
|
-
*
|
|
189
|
-
* Subscribe with:
|
|
190
|
-
* sdk.on("FACT_VERIFIED", (payload: FactVerifiedPayload) => {...});
|
|
191
|
-
*
|
|
192
|
-
* `addFact()`'s Promise resolves only on terminals; this event stream
|
|
193
|
-
* is the channel for rendering live progress in the agent UI.
|
|
237
|
+
* Payload of the `FACT_VERIFIED` event, which fires on every state change —
|
|
238
|
+
* see `VerificationStatus`. Use it to show progress; `addFact()` resolves
|
|
239
|
+
* only once a fact is done.
|
|
194
240
|
*/
|
|
195
241
|
interface FactVerifiedPayload {
|
|
196
242
|
factId: string;
|
|
@@ -200,12 +246,7 @@ interface FactVerifiedPayload {
|
|
|
200
246
|
answer_match_score?: number;
|
|
201
247
|
matched_components?: string[];
|
|
202
248
|
missing_components?: string[];
|
|
203
|
-
/**
|
|
204
|
-
* Inner data payload. Shape matches `AddFactResult` (minus the
|
|
205
|
-
* top-level envelope fields) so consumers can reuse the same
|
|
206
|
-
* rendering code for the terminal addFact() resolution and the
|
|
207
|
-
* broadcast event.
|
|
208
|
-
*/
|
|
249
|
+
/** Inner payload, shaped like `AddFactResult`. */
|
|
209
250
|
data?: AddFactResult;
|
|
210
251
|
error?: string;
|
|
211
252
|
}
|
|
@@ -213,47 +254,26 @@ type FlagFactResult = {
|
|
|
213
254
|
success: boolean;
|
|
214
255
|
};
|
|
215
256
|
/**
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* `dialog_act_confidence` band.
|
|
220
|
-
*
|
|
221
|
-
* Mirrors `DialogAct` in
|
|
222
|
-
* `libs/types/src/utterance-enrichment.ts` on the backend.
|
|
257
|
+
* What the utterance appears to be doing in the conversation. A best-effort
|
|
258
|
+
* guess: display it if it helps, but do not gate behaviour on it. Its
|
|
259
|
+
* confidence band is `dialog_act_confidence`.
|
|
223
260
|
*/
|
|
224
261
|
type DialogAct = "question" | "answer" | "acknowledgement" | "filler" | "other";
|
|
225
262
|
/**
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
* two are unrelated and conflating them is a documented drift hazard on
|
|
229
|
-
* the backend.
|
|
230
|
-
*
|
|
231
|
-
* Mirrors `DialogActConfidence` in
|
|
232
|
-
* `libs/types/src/utterance-enrichment.ts` on the backend.
|
|
263
|
+
* Confidence band for `dialog_act` only. Unrelated to the numeric
|
|
264
|
+
* `confidence` field on the same utterance — do not compare the two.
|
|
233
265
|
*/
|
|
234
266
|
type DialogActConfidence = "high" | "medium" | "low";
|
|
235
267
|
/**
|
|
236
|
-
*
|
|
237
|
-
* gateway (`apps/realtime-verification/src/socket/realtimeVerification.gateway.output.dto.ts`)
|
|
238
|
-
* and the `Utterance` interface in `libs/types/src/common.ts` field for
|
|
239
|
-
* field. Sent over the wire by the `TRANSCRIPTION_UPDATED` broadcast.
|
|
268
|
+
* An utterance from the `TRANSCRIPTION_UPDATED` event.
|
|
240
269
|
*
|
|
241
|
-
*
|
|
242
|
-
* pre-cutover utterances (persisted before backend PR #234) lack them.
|
|
243
|
-
* Treat any missing or nullish value as "unknown" — NOT as a deliberate
|
|
244
|
-
* negative signal. `is_ivr_filler_candidate === false` in particular
|
|
245
|
-
* does NOT round-trip through `undefined`, so consumer logic that wants
|
|
246
|
-
* "definitely not a filler" must check `=== false` after confirming the
|
|
247
|
-
* field is present.
|
|
270
|
+
* A missing optional field means "unknown", not "no".
|
|
248
271
|
*/
|
|
249
272
|
type Utterance = {
|
|
250
|
-
/**
|
|
273
|
+
/** Sort utterances by this: ids sort in chronological order. */
|
|
251
274
|
id: string;
|
|
252
275
|
call_id: number;
|
|
253
|
-
/**
|
|
254
|
-
* NOT YET IMPLEMENTED — currently hardcoded to 0 at write sites on
|
|
255
|
-
* the backend. Do not use for sorting; sort by `id` (UUIDv7) instead.
|
|
256
|
-
*/
|
|
276
|
+
/** Always 0. Sort by `id`, not this. */
|
|
257
277
|
order: number;
|
|
258
278
|
is_agent: boolean | null;
|
|
259
279
|
speaker: number;
|
|
@@ -269,10 +289,7 @@ type Utterance = {
|
|
|
269
289
|
spoken_digits_normalized?: string | null;
|
|
270
290
|
vendor?: string | null;
|
|
271
291
|
};
|
|
272
|
-
/**
|
|
273
|
-
* Payload of the `TRANSCRIPTION_UPDATED` broadcast event. Mirrors
|
|
274
|
-
* `TranscriptionUpdateResponseDto` on the gateway.
|
|
275
|
-
*/
|
|
292
|
+
/** Payload of the `TRANSCRIPTION_UPDATED` broadcast event. */
|
|
276
293
|
type TranscriptionUpdate = {
|
|
277
294
|
policyNumber: string;
|
|
278
295
|
conversationId: string;
|
|
@@ -328,4 +345,4 @@ declare class AiQaSdk implements IAiqaSdk {
|
|
|
328
345
|
private isManagerEvent;
|
|
329
346
|
}
|
|
330
347
|
|
|
331
|
-
export { type AddFactResult, AiQaSdk, type Application, type ApplicationFact, type ApplicationFactAnswerChoice, type ApplicationFactAnswerFormat, type ApplicationFactInput, ConversationLanguage, type DialogAct, type DialogActConfidence, FactAnswerFormatType, type FactVerifiedPayload, type FlagFactResult, IAiqaSdk, Methods, type QuestionStatus, type SdkError, type SdkEvent, type SetConversationLanguageResult, type SetConversationProductResult, type TranscriptionUpdate, type UpdateConversationInput, type UpdateConversationResult, type Utterance, type VerificationStatus };
|
|
348
|
+
export { type AddFactResult, AiQaSdk, type Application, type ApplicationFact, type ApplicationFactAnswerChoice, type ApplicationFactAnswerFormat, type ApplicationFactInput, type ApplicationVerificationStatus, type ApplicationVerificationSummary, ConversationLanguage, type DialogAct, type DialogActConfidence, FactAnswerFormatType, type FactVerifiedPayload, type FlagFactResult, IAiqaSdk, Methods, type QuestionStatus, type SdkError, type SdkEvent, type SetConversationLanguageResult, type SetConversationProductResult, type TranscriptionUpdate, type UpdateConversationInput, type UpdateConversationResult, type Utterance, type VerificationStatus };
|
package/dist/browser/browser.js
CHANGED
|
@@ -3341,6 +3341,7 @@ Object.assign(lookup2, {
|
|
|
3341
3341
|
var Methods = /* @__PURE__ */ ((Methods2) => {
|
|
3342
3342
|
Methods2["AUTHENTICATE"] = "AUTHENTICATE";
|
|
3343
3343
|
Methods2["GET_FACTS"] = "GET_FACTS";
|
|
3344
|
+
Methods2["GET_APPLICATION"] = "GET_APPLICATION";
|
|
3344
3345
|
Methods2["START_RECORDING"] = "START_RECORDING";
|
|
3345
3346
|
Methods2["STOP_RECORDING"] = "STOP_RECORDING";
|
|
3346
3347
|
Methods2["IS_RECORDING"] = "IS_RECORDING";
|
|
@@ -3397,7 +3398,7 @@ var compareVersions = (left, right) => {
|
|
|
3397
3398
|
// package.json
|
|
3398
3399
|
var package_default = {
|
|
3399
3400
|
name: "@aiqa/sdk",
|
|
3400
|
-
version: "2.1.0-develop.
|
|
3401
|
+
version: "2.1.0-develop.4",
|
|
3401
3402
|
main: "dist/node/node.js",
|
|
3402
3403
|
module: "dist/node/node.js",
|
|
3403
3404
|
types: "dist/node/node.d.ts",
|
|
@@ -3481,6 +3482,9 @@ var DEFAULT_URL = "ws://localhost:3025/ws";
|
|
|
3481
3482
|
var DEFAULT_TIMEOUT_MS = 6e4;
|
|
3482
3483
|
var RUNTIME = typeof window !== "undefined" && typeof window.document !== "undefined" ? "browser" : "node";
|
|
3483
3484
|
var USER_AGENT = RUNTIME === "browser" ? typeof navigator !== "undefined" ? navigator.userAgent : "browser/unknown" : typeof process !== "undefined" ? `node ${process.version} ${process.platform}` : "node/unknown";
|
|
3485
|
+
function isRequestTimeout(error, method) {
|
|
3486
|
+
return error instanceof Error && error.message === `Request timed out for ${method}`;
|
|
3487
|
+
}
|
|
3484
3488
|
function isThenable(value2) {
|
|
3485
3489
|
return value2 !== null && typeof value2 === "object" && typeof value2.then === "function";
|
|
3486
3490
|
}
|
|
@@ -3688,6 +3692,18 @@ var AiQaSdk = class {
|
|
|
3688
3692
|
});
|
|
3689
3693
|
}
|
|
3690
3694
|
async getApplication() {
|
|
3695
|
+
try {
|
|
3696
|
+
const result = await this.sendMessage("GET_APPLICATION" /* GET_APPLICATION */);
|
|
3697
|
+
const application = result && result.data !== void 0 ? result.data : result;
|
|
3698
|
+
if (application && application.application_id !== void 0) {
|
|
3699
|
+
return application;
|
|
3700
|
+
}
|
|
3701
|
+
throw new Error("GET_APPLICATION returned no application");
|
|
3702
|
+
} catch (error) {
|
|
3703
|
+
if (!isRequestTimeout(error, "GET_APPLICATION" /* GET_APPLICATION */)) {
|
|
3704
|
+
throw error;
|
|
3705
|
+
}
|
|
3706
|
+
}
|
|
3691
3707
|
if (this.cachedApplication) {
|
|
3692
3708
|
return this.cachedApplication;
|
|
3693
3709
|
}
|