@aiqa/sdk 2.4.0-develop.1 → 2.4.0-develop.2

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
@@ -20,6 +20,7 @@ A TypeScript/JavaScript SDK for interacting with the AIQA WebSocket service. Thi
20
20
  - [ApplicationVerificationStatus](#applicationverificationstatus)
21
21
  - [ApplicationFact](#applicationfact)
22
22
  - [AddFactResult](#addfactresult)
23
+ - [FactWarning](#factwarning)
23
24
  - [VerificationStatus](#verificationstatus)
24
25
  - [FactVerifiedPayload](#factverifiedpayload)
25
26
  - [ApplicationFactInput](#applicationfactinput)
@@ -305,6 +306,8 @@ a timeout, a rejected payload.
305
306
 
306
307
  - `Promise<`[`AddFactResult`](#addfactresult)`>` — resolves once the fact
307
308
  reaches a final `verification_status`.
309
+ - `warnings`: present only when part of this `addFact()` was not applied.
310
+ See [`FactWarning`](#factwarning).
308
311
 
309
312
  **Parameters:**
310
313
 
@@ -348,6 +351,10 @@ const result = await sdk.addFact({
348
351
  metadata: { uiFieldId: "policy-agreement", section: "consent" },
349
352
  });
350
353
 
354
+ for (const warning of result.warnings ?? []) {
355
+ console.warn(warning.code, warning.message);
356
+ }
357
+
351
358
  if (result.is_valid_answer) {
352
359
  // verification_status, when present, is "matched".
353
360
  console.log("matched:", result.ai_answer);
@@ -681,10 +688,36 @@ interface AddFactResult {
681
688
  matched_components?: string[];
682
689
  missing_components?: string[];
683
690
 
691
+ // Present only when part of this addFact() was not applied.
692
+ warnings?: FactWarning[];
693
+
684
694
  metadata?: Record<string, string>;
685
695
  }
686
696
  ```
687
697
 
698
+ ### FactWarning
699
+
700
+ Listed in `warnings` on the [`AddFactResult`](#addfactresult) returned by the
701
+ `addFact()` call that caused them. `FACT_VERIFIED` events never include
702
+ warnings, so read them from the `addFact()` result.
703
+
704
+ ```typescript
705
+ interface FactWarning {
706
+ code: FactWarningCode;
707
+ message: string;
708
+ }
709
+
710
+ type FactWarningCode = "category_not_found" | (string & {});
711
+ ```
712
+
713
+ | `code` | meaning | question's category | what to do |
714
+ | -------------------- | ---------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------- |
715
+ | `category_not_found` | there is no category with the `category_id` you sent | unchanged | check the `category_id` and send it again with the next `addFact()` for this question |
716
+ | any other | added in a later version | — | log `message` and continue |
717
+
718
+ - Use `code` to choose what to do; do not parse `message`. `message` is human-readable, includes the `category_id` you sent, and may change.
719
+ - The rest of the fact is saved, and `addFact()` resolves as usual with its result.
720
+
688
721
  ### VerificationStatus
689
722
 
690
723
  ```typescript
@@ -707,7 +740,8 @@ which states are final.
707
740
  ### FactVerifiedPayload
708
741
 
709
742
  Payload of the `FACT_VERIFIED` event: which fact the update is about, its
710
- current state, and the full [`AddFactResult`](#addfactresult) shape in `data`.
743
+ current state, and the [`AddFactResult`](#addfactresult) shape in `data`,
744
+ without `warnings`.
711
745
 
712
746
  ```typescript
713
747
  interface FactVerifiedPayload {
@@ -718,8 +752,8 @@ interface FactVerifiedPayload {
718
752
  answer_match_score?: number;
719
753
  matched_components?: string[];
720
754
  missing_components?: string[];
721
- /** Inner payload, same shape as AddFactResult. */
722
- data?: AddFactResult;
755
+ /** Inner payload, same shape as AddFactResult without warnings. */
756
+ data?: Omit<AddFactResult, "warnings">;
723
757
  error?: string;
724
758
  }
725
759
  ```
@@ -232,6 +232,17 @@ type ApplicationFact = ApplicationFactInput & {
232
232
  /** True once `flagFact(factId)` has been called for this fact. */
233
233
  flagged: boolean;
234
234
  };
235
+ /**
236
+ * Why part of an `addFact()` was not applied. Use it to choose what to do; do
237
+ * not parse `message`. Later versions may add codes: log `message` and
238
+ * continue. See "FactWarning" in the README.
239
+ */
240
+ type FactWarningCode = "category_not_found" | (string & {});
241
+ /** Part of an `addFact()` that was not applied. The rest of the fact is saved. */
242
+ interface FactWarning {
243
+ code: FactWarningCode;
244
+ message: string;
245
+ }
235
246
  interface AddFactResult {
236
247
  /** Conversation the fact was attached to. */
237
248
  conversation_id?: string;
@@ -267,6 +278,8 @@ interface AddFactResult {
267
278
  */
268
279
  matched_components?: string[];
269
280
  missing_components?: string[];
281
+ /** Present only when part of this `addFact()` was not applied. */
282
+ warnings?: FactWarning[];
270
283
  }
271
284
  /**
272
285
  * Payload of the `FACT_VERIFIED` event, which fires on every state change —
@@ -281,8 +294,8 @@ interface FactVerifiedPayload {
281
294
  answer_match_score?: number;
282
295
  matched_components?: string[];
283
296
  missing_components?: string[];
284
- /** Inner payload, shaped like `AddFactResult`. */
285
- data?: AddFactResult;
297
+ /** Inner payload, shaped like `AddFactResult` without `warnings`. */
298
+ data?: Omit<AddFactResult, "warnings">;
286
299
  error?: string;
287
300
  }
288
301
  type FlagFactResult = {
@@ -380,4 +393,4 @@ declare class AiQaSdk implements IAiqaSdk {
380
393
  private isManagerEvent;
381
394
  }
382
395
 
383
- export { type AddFactResult, AiQaSdk, type Application, type ApplicationFact, type ApplicationFactAnswerChoice, type ApplicationFactAnswerFormat, type ApplicationFactInput, type ApplicationVerificationStatus, type ApplicationVerificationSummary, ConversationLanguage, type ConversationWarning, type ConversationWarningCode, type DialogAct, type DialogActConfidence, ExternalStatus, 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 };
396
+ export { type AddFactResult, AiQaSdk, type Application, type ApplicationFact, type ApplicationFactAnswerChoice, type ApplicationFactAnswerFormat, type ApplicationFactInput, type ApplicationVerificationStatus, type ApplicationVerificationSummary, ConversationLanguage, type ConversationWarning, type ConversationWarningCode, type DialogAct, type DialogActConfidence, ExternalStatus, FactAnswerFormatType, type FactVerifiedPayload, type FactWarning, type FactWarningCode, type FlagFactResult, IAiqaSdk, Methods, type QuestionStatus, type SdkError, type SdkEvent, type SetConversationLanguageResult, type SetConversationProductResult, type TranscriptionUpdate, type UpdateConversationInput, type UpdateConversationResult, type Utterance, type VerificationStatus };
@@ -3406,7 +3406,7 @@ var compareVersions = (left, right) => {
3406
3406
  // package.json
3407
3407
  var package_default = {
3408
3408
  name: "@aiqa/sdk",
3409
- version: "2.3.0-develop.2",
3409
+ version: "2.4.0-develop.1",
3410
3410
  main: "dist/node/node.js",
3411
3411
  module: "dist/node/node.js",
3412
3412
  types: "dist/node/node.d.ts",
@@ -3732,7 +3732,7 @@ var AiQaSdk = class {
3732
3732
  const result = await this.sendMessage("ADD_FACT" /* ADD_FACT */, payload);
3733
3733
  if (!result) return result;
3734
3734
  const inner = result.data !== void 0 ? result.data : result;
3735
- const hasEnvelope = result.verification_status !== void 0 || result.matched_components !== void 0 || result.missing_components !== void 0;
3735
+ const hasEnvelope = result.verification_status !== void 0 || result.matched_components !== void 0 || result.missing_components !== void 0 || result.warnings !== void 0;
3736
3736
  if (!hasEnvelope || typeof inner !== "object" || inner === null) {
3737
3737
  return inner;
3738
3738
  }
@@ -3746,6 +3746,9 @@ var AiQaSdk = class {
3746
3746
  if (result.missing_components !== void 0) {
3747
3747
  merged.missing_components = result.missing_components;
3748
3748
  }
3749
+ if (result.warnings !== void 0) {
3750
+ merged.warnings = result.warnings;
3751
+ }
3749
3752
  return merged;
3750
3753
  }
3751
3754
  async flagFact(factId) {