@aiqa/sdk 3.1.0-develop.2 → 3.1.0-develop.3

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 CHANGED
@@ -14,6 +14,7 @@ A TypeScript/JavaScript SDK for interacting with the AIQA WebSocket service. Thi
14
14
  - [Recording Management](#recording-management)
15
15
  - [Event Handling](#event-handling)
16
16
  - [Verification lifecycle](#verification-lifecycle)
17
+ - [Watched facts](#watched-facts)
17
18
  - [Types](#types)
18
19
  - [Application](#application)
19
20
  - [ApplicationVerificationSummary](#applicationverificationsummary)
@@ -331,6 +332,10 @@ verification result. The Promise resolves with an
331
332
  `pending_confirmation_matched`, `pending_confirmation_unmatched`)
332
333
  while you wait.
333
334
 
335
+ A [watched fact](#watched-facts) is the exception: its Promise resolves right
336
+ away with `verification_status: "awaiting_question"`, and the result arrives
337
+ later on `FACT_VERIFIED`.
338
+
334
339
  A failed verification is not an error: an unmatched fact resolves with
335
340
  `is_valid_answer: false` and, where present, `verification_status: "unmatched"`.
336
341
  The Promise rejects only when the request itself fails — a dropped connection,
@@ -339,7 +344,7 @@ a timeout, a rejected payload.
339
344
  **Returns:**
340
345
 
341
346
  - `Promise<`[`AddFactResult`](#addfactresult)`>` — resolves once the fact
342
- reaches a final `verification_status`.
347
+ reaches a final `verification_status`, or right away for a watched fact.
343
348
  - `warnings`: present only when part of this `addFact()` was not applied.
344
349
  See [`FactWarning`](#factwarning).
345
350
 
@@ -370,6 +375,11 @@ a timeout, a rejected payload.
370
375
  * never verified, and left out of the verification summary counts.
371
376
  */
372
377
  reference?: boolean
378
+ /**
379
+ * Optional. Use "watch" to check the fact over the whole call instead of
380
+ * at one moment. See Watched facts below.
381
+ */
382
+ evaluation?: "watch"
373
383
  /**
374
384
  * Optional. Your own identifiers for this fact — a form field ID, a
375
385
  * section name, anything that lets your UI map the result back to the
@@ -527,7 +537,8 @@ Registers an event listener. Call `connect()` before `on()`.
527
537
  - `FACT_VERIFIED` - fires on **every** verification state change, progress and
528
538
  final result alike, for **every** fact in the conversation. Payload:
529
539
  [`FactVerifiedPayload`](#factverifiedpayload). Use it to show live progress;
530
- `addFact()`'s Promise resolves only on the final result.
540
+ `addFact()`'s Promise resolves only on the final result, except for a
541
+ [watched fact](#watched-facts).
531
542
 
532
543
  ```typescript
533
544
  sdk.connect();
@@ -578,11 +589,14 @@ processing
578
589
  matched | unmatched ← final
579
590
  ```
580
591
 
592
+ A [watched fact](#watched-facts) does not follow this sequence: it stays at
593
+ `awaiting_question` until it goes straight to `matched` or `unmatched`.
594
+
581
595
  Rules:
582
596
 
583
597
  - **`addFact()` resolves only on a final state** (`matched`,
584
- `unmatched`). Show progress from the `FACT_VERIFIED` event, show the final
585
- result from the Promise.
598
+ `unmatched`), except for a [watched fact](#watched-facts). Show progress from the
599
+ `FACT_VERIFIED` event, show the final result from the Promise.
586
600
  - **Handle a `verification_status` you don't recognize as `processing`.**
587
601
  - **A fact sent with `prefilled: true` is never verified**, so it gets no
588
602
  `verification_status` and no `FACT_VERIFIED` event.
@@ -598,6 +612,57 @@ Rules:
598
612
  result on screen for the rest of the call, leave your `FACT_VERIFIED`
599
613
  listener attached and always show the latest state for that `factId`.
600
614
 
615
+ ### Watched facts
616
+
617
+ Send `evaluation: "watch"` for a fact you want checked over the whole call
618
+ rather than at one moment: from the moment you send it until it is `matched`
619
+ or the call ends.
620
+
621
+ ```typescript
622
+ const result = await sdk.addFact({
623
+ id: "my_fact",
624
+ question: "What you want checked in the call",
625
+ expected_answer: "the value it has to match",
626
+ answer_format: { type: FactAnswerFormatType.string },
627
+ evaluation: "watch",
628
+ });
629
+ ```
630
+
631
+ - **`question`:** describe, in plain words, what has to happen in the call for
632
+ this fact to be `matched`.
633
+ - **`expected_answer`:** the value it has to match.
634
+ - **Send `evaluation: "watch"` every time** you send the fact. Without it, the
635
+ fact goes through the regular
636
+ [Verification lifecycle](#verification-lifecycle): it is checked against one
637
+ moment of the call, and `addFact()` waits for the final result.
638
+ - **Send the fact before that part of the call starts.** Only the part of the
639
+ call shortly before you send the fact is checked; anything earlier is
640
+ missed.
641
+ - **`addFact()` resolves right away** with
642
+ `verification_status: "awaiting_question"` and `is_valid_answer: false`.
643
+ This is not a result: don't show it as one.
644
+ - **The result arrives on `FACT_VERIFIED`** for that `factId`. A watched fact
645
+ goes from `awaiting_question` straight to `matched` or `unmatched`. Read
646
+ `payload.verification_status` and `payload.error`:
647
+ - `matched`: it happened in the call, matching `expected_answer` when you
648
+ sent one.
649
+ - `unmatched` with `error: "question-not-detected"`: it never happened.
650
+ - `unmatched` with `error: "answer-not-found"`: it happened, but could not
651
+ be confirmed against `expected_answer`.
652
+ - `unmatched` with no `error`: it happened, but with a different value. This
653
+ result is final.
654
+ - **If it never happens**, the result is `unmatched` and arrives only when the
655
+ call ends. To get it as an event, keep the SDK connected and your
656
+ `FACT_VERIFIED` listener attached until then. Otherwise, call `getFacts()`
657
+ after the call: its `verification_status` shows `matched` or `unmatched`,
658
+ but not the reason (`error`) for an `unmatched` result.
659
+ - **Sending a watched fact again** with the same `id` and `expected_answer`:
660
+ if it already matched, `addFact()` resolves with `matched`. Otherwise it
661
+ resolves with `awaiting_question` and the result arrives on `FACT_VERIFIED`
662
+ as before. With a different `expected_answer`, the earlier result no longer
663
+ applies: `addFact()` resolves with `awaiting_question` again, and the new
664
+ result arrives on `FACT_VERIFIED`.
665
+
601
666
  ## Types
602
667
 
603
668
  ### Application
@@ -691,7 +756,8 @@ type ApplicationFact = ApplicationFactInput & {
691
756
  ### AddFactResult
692
757
 
693
758
  Resolved value of `addFact()`. Only sent once the fact reaches its final
694
- state — see [Verification lifecycle](#verification-lifecycle).
759
+ state, except for a [watched fact](#watched-facts) — see
760
+ [Verification lifecycle](#verification-lifecycle).
695
761
 
696
762
  ```typescript
697
763
  interface AddFactResult {
@@ -720,8 +786,9 @@ interface AddFactResult {
720
786
  answer_match_score?: number;
721
787
 
722
788
  /**
723
- * The final state: `matched` or `unmatched` whenever it is present.
724
- * Fall back to `is_valid_answer` when it is missing.
789
+ * `matched` or `unmatched`: the final result. For a watched fact it is
790
+ * `awaiting_question`, which is not a result; the result arrives on
791
+ * `FACT_VERIFIED`. If this field is missing, use `is_valid_answer`.
725
792
  */
726
793
  verification_status?: VerificationStatus;
727
794
 
@@ -849,6 +916,11 @@ type ApplicationFactInput = {
849
916
  * never verified, and left out of the verification summary counts.
850
917
  */
851
918
  reference?: boolean;
919
+ /**
920
+ * Optional. Use `"watch"` to check the fact over the whole call instead of
921
+ * at one moment. See [Watched facts](#watched-facts).
922
+ */
923
+ evaluation?: "watch";
852
924
  /**
853
925
  * Optional. Your own identifiers for this fact — a form field ID, a section
854
926
  * name, anything that lets your UI map the result back to the right place.
@@ -215,6 +215,11 @@ type ApplicationFactInput = {
215
215
  * never verified, and left out of the verification summary counts.
216
216
  */
217
217
  reference?: boolean;
218
+ /**
219
+ * Optional. Use `"watch"` to check the fact over the whole call instead of
220
+ * at one moment. See "Watched facts" in the README.
221
+ */
222
+ evaluation?: "watch";
218
223
  /**
219
224
  * Your own identifiers for this fact — a form field ID, a section name,
220
225
  * anything that lets your UI map the result back to the right place.
@@ -232,7 +237,9 @@ type QuestionStatus = "searching" | "asked" | "not_asked";
232
237
  * `processing`.
233
238
  *
234
239
  * - `processing` queued, or nothing to go on yet
235
- * - `awaiting_question` the advisor hasn't asked the question yet
240
+ * - `awaiting_question` the advisor hasn't asked the question yet;
241
+ * for a watched fact, its state until the
242
+ * result arrives
236
243
  * - `awaiting_answer` asked, the customer hasn't answered yet
237
244
  * - `partial` partial evidence so far (e.g. "305" of "30521")
238
245
  * - `pending_confirmation_matched` a matching answer is held briefly in case
@@ -273,7 +280,7 @@ interface AddFactResult {
273
280
  answer_type?: string;
274
281
  agent_answer?: string;
275
282
  ai_answer?: string;
276
- /** `false` for a fact that was never verified, such as a prefilled or reference one. */
283
+ /** `false` for a fact that was never verified, such as a prefilled or reference one. Also `false` when `addFact()` resolves for a watched fact; its result arrives on `FACT_VERIFIED`. */
277
284
  is_valid_answer: boolean;
278
285
  question_asked?: boolean;
279
286
  /**
@@ -288,8 +295,9 @@ interface AddFactResult {
288
295
  answer_match_score?: number;
289
296
  metadata?: Record<string, string>;
290
297
  /**
291
- * The final state: `matched` or `unmatched` whenever it is present. Fall
292
- * back to `is_valid_answer` when it is missing.
298
+ * `matched` or `unmatched`: the final result. For a watched fact it is
299
+ * `awaiting_question`, which is not a result; the result arrives on
300
+ * `FACT_VERIFIED`. If this field is missing, use `is_valid_answer`.
293
301
  */
294
302
  verification_status?: VerificationStatus;
295
303
  /**
@@ -305,7 +313,8 @@ interface AddFactResult {
305
313
  /**
306
314
  * Payload of the `FACT_VERIFIED` event, which fires on every state change —
307
315
  * see `VerificationStatus`. Use it to show progress; `addFact()` resolves
308
- * only once a fact is done.
316
+ * only once a fact is done, except for a watched fact, whose result arrives only
317
+ * here.
309
318
  */
310
319
  interface FactVerifiedPayload {
311
320
  factId: string;
@@ -3407,7 +3407,7 @@ var compareVersions = (left, right) => {
3407
3407
  // package.json
3408
3408
  var package_default = {
3409
3409
  name: "@aiqa/sdk",
3410
- version: "3.1.0-develop.1",
3410
+ version: "3.1.0-develop.2",
3411
3411
  main: "dist/node/node.js",
3412
3412
  module: "dist/node/node.js",
3413
3413
  types: "dist/node/node.d.ts",