@aiqa/sdk 2.3.0 → 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)
@@ -27,6 +28,7 @@ A TypeScript/JavaScript SDK for interacting with the AIQA WebSocket service. Thi
27
28
  - [ConversationLanguage](#conversationlanguage)
28
29
  - [UpdateConversationInput](#updateconversationinput)
29
30
  - [UpdateConversationResult](#updateconversationresult)
31
+ - [ConversationWarning](#conversationwarning)
30
32
  - [Examples](#examples)
31
33
  - [Error Handling](#error-handling)
32
34
  - [Version Requirements](#version-requirements)
@@ -226,36 +228,56 @@ change.
226
228
 
227
229
  - `input: UpdateConversationInput` - partial set of conversation fields to update
228
230
 
229
- | field | type | max | notes |
230
- | --------------------------- | ---------- | -------- | ------------------------------------------- |
231
- | `policyNumber` | `string` | 128 | |
232
- | `insuredPhone` | `string` | 32 | the insured, who may differ from the caller |
233
- | `clientName` | `string` | 128 | |
234
- | `clientPhone` | `string` | 32 | |
235
- | `clientEmail` | `string` | 254 | must be a valid email address |
236
- | `clientId` | `string` | 64 | your own CRM identifier |
237
- | `agentId` / `agentName` | `string` | 64/128 | |
238
- | `advisorId` / `advisorName` | `string` | 64/128 | |
239
- | `agentGroups` | `string[]` | 32 × 128 | entries cannot contain a comma |
240
- | `externalStatus` | `string` | — | see [`ExternalStatus`](#externalstatus) |
231
+ | field | type | max | notes |
232
+ | --------------------------- | ---------- | -------- | ----------------------------------------------------------------------- |
233
+ | `policyNumber` | `string` | 128 | |
234
+ | `insuredPhone` | `string` | 32 | the insured, who may differ from the caller |
235
+ | `clientName` | `string` | 128 | |
236
+ | `clientPhone` | `string` | 32 | |
237
+ | `clientEmail` | `string` | 254 | must be a valid email address |
238
+ | `clientId` | `string` | 64 | your own CRM identifier |
239
+ | `agentId` | `string` | 64 | the agent's AIQA user id; used instead of `agentEmail` if both are sent |
240
+ | `agentEmail` | `string` | 254 | valid email; alternative to `agentId` |
241
+ | `agentName` | `string` | 128 | |
242
+ | `advisorId` / `advisorName` | `string` | 64/128 | |
243
+ | `agentGroups` | `string[]` | 32 × 128 | entries cannot contain a comma |
244
+ | `externalStatus` | `string` | — | see [`ExternalStatus`](#externalstatus) |
241
245
 
242
246
  Every string (including each `agentGroups` entry) must be non-empty;
243
247
  surrounding whitespace is trimmed first, so a value of only spaces is
244
248
  rejected. `null` is rejected — omit the field instead. At least one field is
245
249
  required, and any field not in the table is rejected.
246
250
 
251
+ **Agent identification**
252
+
253
+ | sent | conversation's agent | `conversation.agent_id` | `warnings` |
254
+ | ------------------------------------- | -------------------- | --------------------------------------------------------------------------------------------- | -------------------------- |
255
+ | `agentId` | set to `agentId` | `agentId` | — |
256
+ | `agentId` + `agentEmail` | set to `agentId` | `agentId` (`agentEmail` is ignored) | — |
257
+ | `agentEmail`, a user matches | set to that user | the user's AIQA user id: their email in lowercase (compare it to what you sent ignoring case) | — |
258
+ | `agentEmail`, no user matches | unchanged | absent | `agent_not_found` |
259
+ | `agentEmail`, temporarily not checked | unchanged | absent | `agent_lookup_unavailable` |
260
+ - `conversation` never contains `agentEmail`.
261
+ - With a warning, `success` is `true` and every other field you sent is saved.
262
+ - After `agent_lookup_unavailable`, call `updateConversation({ agentEmail })` again later. You do not need to resend the other fields.
263
+
247
264
  **Returns:**
248
265
 
249
- - `Promise<UpdateConversationResult>` - `conversation` echoes only the fields
250
- you sent.
266
+ - `Promise<UpdateConversationResult>`
267
+ - `conversation`: only the fields you sent; a matched `agentEmail` comes back as `agent_id`.
268
+ - `warnings`: present only when part of the update was not applied.
251
269
 
252
270
  ```typescript
253
271
  const result = await sdk.updateConversation({
254
272
  policyNumber: "POL-123",
255
273
  clientEmail: "jane@example.com",
274
+ agentEmail: "vio.agent@example.com",
256
275
  externalStatus: ExternalStatus.COMPLETED,
257
276
  });
258
277
  console.log(result.success, result.conversation.policy_number);
278
+ for (const warning of result.warnings ?? []) {
279
+ console.warn(warning.code, warning.message);
280
+ }
259
281
  ```
260
282
 
261
283
  ##### `ExternalStatus`
@@ -284,6 +306,8 @@ a timeout, a rejected payload.
284
306
 
285
307
  - `Promise<`[`AddFactResult`](#addfactresult)`>` — resolves once the fact
286
308
  reaches a final `verification_status`.
309
+ - `warnings`: present only when part of this `addFact()` was not applied.
310
+ See [`FactWarning`](#factwarning).
287
311
 
288
312
  **Parameters:**
289
313
 
@@ -327,6 +351,10 @@ const result = await sdk.addFact({
327
351
  metadata: { uiFieldId: "policy-agreement", section: "consent" },
328
352
  });
329
353
 
354
+ for (const warning of result.warnings ?? []) {
355
+ console.warn(warning.code, warning.message);
356
+ }
357
+
330
358
  if (result.is_valid_answer) {
331
359
  // verification_status, when present, is "matched".
332
360
  console.log("matched:", result.ai_answer);
@@ -660,10 +688,36 @@ interface AddFactResult {
660
688
  matched_components?: string[];
661
689
  missing_components?: string[];
662
690
 
691
+ // Present only when part of this addFact() was not applied.
692
+ warnings?: FactWarning[];
693
+
663
694
  metadata?: Record<string, string>;
664
695
  }
665
696
  ```
666
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
+
667
721
  ### VerificationStatus
668
722
 
669
723
  ```typescript
@@ -686,7 +740,8 @@ which states are final.
686
740
  ### FactVerifiedPayload
687
741
 
688
742
  Payload of the `FACT_VERIFIED` event: which fact the update is about, its
689
- current state, and the full [`AddFactResult`](#addfactresult) shape in `data`.
743
+ current state, and the [`AddFactResult`](#addfactresult) shape in `data`,
744
+ without `warnings`.
690
745
 
691
746
  ```typescript
692
747
  interface FactVerifiedPayload {
@@ -697,8 +752,8 @@ interface FactVerifiedPayload {
697
752
  answer_match_score?: number;
698
753
  matched_components?: string[];
699
754
  missing_components?: string[];
700
- /** Inner payload, same shape as AddFactResult. */
701
- data?: AddFactResult;
755
+ /** Inner payload, same shape as AddFactResult without warnings. */
756
+ data?: Omit<AddFactResult, "warnings">;
702
757
  error?: string;
703
758
  }
704
759
  ```
@@ -787,7 +842,8 @@ type UpdateConversationInput = {
787
842
  clientPhone?: string;
788
843
  clientEmail?: string;
789
844
  clientId?: string;
790
- agentId?: string;
845
+ agentId?: string; // or agentEmail
846
+ agentEmail?: string; // or agentId
791
847
  agentName?: string;
792
848
  advisorId?: string;
793
849
  advisorName?: string;
@@ -798,8 +854,10 @@ type UpdateConversationInput = {
798
854
 
799
855
  ### UpdateConversationResult
800
856
 
801
- Returned by `updateConversation()`. `conversation` echoes only the fields you
802
- sent.
857
+ Returned by `updateConversation()`.
858
+
859
+ - `conversation`: only the fields you sent; a matched `agentEmail` comes back as `agent_id`.
860
+ - `warnings`: present only when part of the update was not applied.
803
861
 
804
862
  ```typescript
805
863
  type UpdateConversationResult = {
@@ -818,9 +876,34 @@ type UpdateConversationResult = {
818
876
  agent_groups?: string[];
819
877
  external_status?: string;
820
878
  };
879
+ // Present only when part of the update was not applied.
880
+ warnings?: ConversationWarning[];
821
881
  };
822
882
  ```
823
883
 
884
+ ### ConversationWarning
885
+
886
+ ```typescript
887
+ interface ConversationWarning {
888
+ code: ConversationWarningCode;
889
+ message: string;
890
+ }
891
+
892
+ type ConversationWarningCode =
893
+ | "agent_not_found"
894
+ | "agent_lookup_unavailable"
895
+ | (string & {});
896
+ ```
897
+
898
+ | `code` | meaning | conversation's agent | what to do |
899
+ | -------------------------- | --------------------------------------------------------------- | -------------------- | ------------------------------------------------ |
900
+ | `agent_not_found` | no AIQA user in your organization has the `agentEmail` | unchanged | check the email |
901
+ | `agent_lookup_unavailable` | the `agentEmail` could not be checked at the moment (temporary) | unchanged | retry `updateConversation({ agentEmail })` later |
902
+ | any other | added in a later version | — | log `message` and continue |
903
+
904
+ - Use `code` to choose what to do; do not parse `message`. `message` is human-readable, includes the email you sent, and may change.
905
+ - `success` is `true` and every other field you sent is saved.
906
+
824
907
  ## Examples
825
908
 
826
909
  ### Complete Example: Recording Session
@@ -110,14 +110,24 @@ type UpdateConversationInput = {
110
110
  clientPhone?: string;
111
111
  clientEmail?: string;
112
112
  clientId?: string;
113
+ /** The agent's AIQA user id. Takes precedence over `agentEmail`. */
113
114
  agentId?: string;
115
+ /** Email of the agent's AIQA user. Results: README, Agent identification. */
116
+ agentEmail?: string;
114
117
  agentName?: string;
115
118
  advisorId?: string;
116
119
  advisorName?: string;
117
120
  agentGroups?: string[];
118
121
  externalStatus?: ExternalStatus | (string & {});
119
122
  };
120
- /** Only the fields you sent come back in `conversation`. */
123
+ /** Decide with `code`, not `message`. Codes: README, ConversationWarning. */
124
+ type ConversationWarningCode = "agent_not_found" | "agent_lookup_unavailable" | (string & {});
125
+ /** Part of an `updateConversation()` that was not applied; the rest was saved. */
126
+ interface ConversationWarning {
127
+ code: ConversationWarningCode;
128
+ message: string;
129
+ }
130
+ /** `conversation` holds the fields you sent; `warnings` only when part was not applied. */
121
131
  type UpdateConversationResult = {
122
132
  success: boolean;
123
133
  conversation: {
@@ -134,6 +144,7 @@ type UpdateConversationResult = {
134
144
  agent_groups?: string[];
135
145
  external_status?: string;
136
146
  };
147
+ warnings?: ConversationWarning[];
137
148
  };
138
149
  declare enum ConversationLanguage {
139
150
  EN = "en",
@@ -221,6 +232,17 @@ type ApplicationFact = ApplicationFactInput & {
221
232
  /** True once `flagFact(factId)` has been called for this fact. */
222
233
  flagged: boolean;
223
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
+ }
224
246
  interface AddFactResult {
225
247
  /** Conversation the fact was attached to. */
226
248
  conversation_id?: string;
@@ -256,6 +278,8 @@ interface AddFactResult {
256
278
  */
257
279
  matched_components?: string[];
258
280
  missing_components?: string[];
281
+ /** Present only when part of this `addFact()` was not applied. */
282
+ warnings?: FactWarning[];
259
283
  }
260
284
  /**
261
285
  * Payload of the `FACT_VERIFIED` event, which fires on every state change —
@@ -270,8 +294,8 @@ interface FactVerifiedPayload {
270
294
  answer_match_score?: number;
271
295
  matched_components?: string[];
272
296
  missing_components?: string[];
273
- /** Inner payload, shaped like `AddFactResult`. */
274
- data?: AddFactResult;
297
+ /** Inner payload, shaped like `AddFactResult` without `warnings`. */
298
+ data?: Omit<AddFactResult, "warnings">;
275
299
  error?: string;
276
300
  }
277
301
  type FlagFactResult = {
@@ -369,4 +393,4 @@ declare class AiQaSdk implements IAiqaSdk {
369
393
  private isManagerEvent;
370
394
  }
371
395
 
372
- export { type AddFactResult, AiQaSdk, type Application, type ApplicationFact, type ApplicationFactAnswerChoice, type ApplicationFactAnswerFormat, type ApplicationFactInput, type ApplicationVerificationStatus, type ApplicationVerificationSummary, ConversationLanguage, 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.1",
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) {