@aiqa/sdk 3.1.0-develop.1 → 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
 
@@ -363,6 +368,18 @@ a timeout, a rejected payload.
363
368
  answer_format: { type: "STRING" }
364
369
  /** Optional (default: `false`). Use `true` when the fact was collected before the conversation started. It is stored, not verified. */
365
370
  prefilled?: boolean
371
+ /**
372
+ * Optional. Use `true` for a value you already know is correct, such as data
373
+ * from your own records. Unlike `prefilled`, it is about trusting the value, not
374
+ * when it was collected. It is stored and visible to whoever reviews the call,
375
+ * never verified, and left out of the verification summary counts.
376
+ */
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"
366
383
  /**
367
384
  * Optional. Your own identifiers for this fact — a form field ID, a
368
385
  * section name, anything that lets your UI map the result back to the
@@ -520,7 +537,8 @@ Registers an event listener. Call `connect()` before `on()`.
520
537
  - `FACT_VERIFIED` - fires on **every** verification state change, progress and
521
538
  final result alike, for **every** fact in the conversation. Payload:
522
539
  [`FactVerifiedPayload`](#factverifiedpayload). Use it to show live progress;
523
- `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).
524
542
 
525
543
  ```typescript
526
544
  sdk.connect();
@@ -571,20 +589,80 @@ processing
571
589
  matched | unmatched ← final
572
590
  ```
573
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
+
574
595
  Rules:
575
596
 
576
597
  - **`addFact()` resolves only on a final state** (`matched`,
577
- `unmatched`). Show progress from the `FACT_VERIFIED` event, show the final
578
- 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.
579
600
  - **Handle a `verification_status` you don't recognize as `processing`.**
580
601
  - **A fact sent with `prefilled: true` is never verified**, so it gets no
581
602
  `verification_status` and no `FACT_VERIFIED` event.
603
+ - **A fact sent with `reference: true` is never verified either.** Use it for
604
+ a value you already know is correct, such as the plan name from your own
605
+ records. It is stored, visible to whoever reviews the call, and left out of
606
+ the verification summary counts. `addFact()` still resolves, with
607
+ `is_valid_answer: false` and no `verification_status`, and no `FACT_VERIFIED`
608
+ event is emitted for it.
582
609
  - **`pending_confirmation_*` is never final.** The answer can still change,
583
610
  so don't show it as a decision.
584
611
  - **A fact can be revised after `addFact()` has resolved.** If you keep its
585
612
  result on screen for the rest of the call, leave your `FACT_VERIFIED`
586
613
  listener attached and always show the latest state for that `factId`.
587
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
+
588
666
  ## Types
589
667
 
590
668
  ### Application
@@ -678,7 +756,8 @@ type ApplicationFact = ApplicationFactInput & {
678
756
  ### AddFactResult
679
757
 
680
758
  Resolved value of `addFact()`. Only sent once the fact reaches its final
681
- state — see [Verification lifecycle](#verification-lifecycle).
759
+ state, except for a [watched fact](#watched-facts) — see
760
+ [Verification lifecycle](#verification-lifecycle).
682
761
 
683
762
  ```typescript
684
763
  interface AddFactResult {
@@ -707,8 +786,9 @@ interface AddFactResult {
707
786
  answer_match_score?: number;
708
787
 
709
788
  /**
710
- * The final state: `matched` or `unmatched` whenever it is present.
711
- * 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`.
712
792
  */
713
793
  verification_status?: VerificationStatus;
714
794
 
@@ -829,6 +909,18 @@ type ApplicationFactInput = {
829
909
  is_skipped?: boolean;
830
910
  /** Optional (default: `false`). Use `true` when the fact was collected before the conversation started. It is stored, not verified. */
831
911
  prefilled?: boolean;
912
+ /**
913
+ * Optional. Use `true` for a value you already know is correct, such as data
914
+ * from your own records. Unlike `prefilled`, it is about trusting the value, not
915
+ * when it was collected. It is stored and visible to whoever reviews the call,
916
+ * never verified, and left out of the verification summary counts.
917
+ */
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";
832
924
  /**
833
925
  * Optional. Your own identifiers for this fact — a form field ID, a section
834
926
  * name, anything that lets your UI map the result back to the right place.
@@ -208,6 +208,18 @@ type ApplicationFactInput = {
208
208
  is_skipped?: boolean;
209
209
  /** Optional (default: `false`). Use `true` when the fact was collected before the conversation started. It is stored, not verified. */
210
210
  prefilled?: boolean;
211
+ /**
212
+ * Optional. Use `true` for a value you already know is correct, such as data
213
+ * from your own records. Unlike `prefilled`, it is about trusting the value, not
214
+ * when it was collected. It is stored and visible to whoever reviews the call,
215
+ * never verified, and left out of the verification summary counts.
216
+ */
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";
211
223
  /**
212
224
  * Your own identifiers for this fact — a form field ID, a section name,
213
225
  * anything that lets your UI map the result back to the right place.
@@ -225,7 +237,9 @@ type QuestionStatus = "searching" | "asked" | "not_asked";
225
237
  * `processing`.
226
238
  *
227
239
  * - `processing` queued, or nothing to go on yet
228
- * - `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
229
243
  * - `awaiting_answer` asked, the customer hasn't answered yet
230
244
  * - `partial` partial evidence so far (e.g. "305" of "30521")
231
245
  * - `pending_confirmation_matched` a matching answer is held briefly in case
@@ -266,7 +280,7 @@ interface AddFactResult {
266
280
  answer_type?: string;
267
281
  agent_answer?: string;
268
282
  ai_answer?: string;
269
- /** `false` for a fact that was never verified, such as a prefilled 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`. */
270
284
  is_valid_answer: boolean;
271
285
  question_asked?: boolean;
272
286
  /**
@@ -281,8 +295,9 @@ interface AddFactResult {
281
295
  answer_match_score?: number;
282
296
  metadata?: Record<string, string>;
283
297
  /**
284
- * The final state: `matched` or `unmatched` whenever it is present. Fall
285
- * 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`.
286
301
  */
287
302
  verification_status?: VerificationStatus;
288
303
  /**
@@ -298,7 +313,8 @@ interface AddFactResult {
298
313
  /**
299
314
  * Payload of the `FACT_VERIFIED` event, which fires on every state change —
300
315
  * see `VerificationStatus`. Use it to show progress; `addFact()` resolves
301
- * only once a fact is done.
316
+ * only once a fact is done, except for a watched fact, whose result arrives only
317
+ * here.
302
318
  */
303
319
  interface FactVerifiedPayload {
304
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.0.0-develop.2",
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",