@aiqa/sdk 2.2.0 → 2.3.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
@@ -27,6 +27,7 @@ A TypeScript/JavaScript SDK for interacting with the AIQA WebSocket service. Thi
27
27
  - [ConversationLanguage](#conversationlanguage)
28
28
  - [UpdateConversationInput](#updateconversationinput)
29
29
  - [UpdateConversationResult](#updateconversationresult)
30
+ - [ConversationWarning](#conversationwarning)
30
31
  - [Examples](#examples)
31
32
  - [Error Handling](#error-handling)
32
33
  - [Version Requirements](#version-requirements)
@@ -129,6 +130,7 @@ going so far.
129
130
  agent_id: string;
130
131
  agent_first_name: string;
131
132
  agent_last_name: string;
133
+ external_status?: string;
132
134
  verification?: ApplicationVerificationSummary;
133
135
  }
134
136
  ```
@@ -140,6 +142,12 @@ going so far.
140
142
  [Reading `verification`](#reading-verification) for the exception.
141
143
  `agent_first_name` and `agent_last_name` come back empty; use
142
144
  `updateConversation({ agentName })` if you need to record an agent's name.
145
+ `external_status` is the value you last sent with
146
+ `updateConversation({ externalStatus })`, lowercased — one of
147
+ [`ExternalStatus`](#externalstatus) — and is **missing** until you send one.
148
+ Read it to recover the status after a reconnect instead of keeping your own
149
+ copy. It is the one field here that never comes from the authentication
150
+ snapshot, so on the fallback path it is absent rather than stale.
143
151
 
144
152
  ```typescript
145
153
  const application = await sdk.getApplication();
@@ -219,36 +227,56 @@ change.
219
227
 
220
228
  - `input: UpdateConversationInput` - partial set of conversation fields to update
221
229
 
222
- | field | type | max | notes |
223
- | --------------------------- | ---------- | -------- | ------------------------------------------- |
224
- | `policyNumber` | `string` | 128 | |
225
- | `insuredPhone` | `string` | 32 | the insured, who may differ from the caller |
226
- | `clientName` | `string` | 128 | |
227
- | `clientPhone` | `string` | 32 | |
228
- | `clientEmail` | `string` | 254 | must be a valid email address |
229
- | `clientId` | `string` | 64 | your own CRM identifier |
230
- | `agentId` / `agentName` | `string` | 64/128 | |
231
- | `advisorId` / `advisorName` | `string` | 64/128 | |
232
- | `agentGroups` | `string[]` | 32 × 128 | entries cannot contain a comma |
233
- | `externalStatus` | `string` | — | see [`ExternalStatus`](#externalstatus) |
230
+ | field | type | max | notes |
231
+ | --------------------------- | ---------- | -------- | ----------------------------------------------------------------------- |
232
+ | `policyNumber` | `string` | 128 | |
233
+ | `insuredPhone` | `string` | 32 | the insured, who may differ from the caller |
234
+ | `clientName` | `string` | 128 | |
235
+ | `clientPhone` | `string` | 32 | |
236
+ | `clientEmail` | `string` | 254 | must be a valid email address |
237
+ | `clientId` | `string` | 64 | your own CRM identifier |
238
+ | `agentId` | `string` | 64 | the agent's AIQA user id; used instead of `agentEmail` if both are sent |
239
+ | `agentEmail` | `string` | 254 | valid email; alternative to `agentId` |
240
+ | `agentName` | `string` | 128 | |
241
+ | `advisorId` / `advisorName` | `string` | 64/128 | |
242
+ | `agentGroups` | `string[]` | 32 × 128 | entries cannot contain a comma |
243
+ | `externalStatus` | `string` | — | see [`ExternalStatus`](#externalstatus) |
234
244
 
235
245
  Every string (including each `agentGroups` entry) must be non-empty;
236
246
  surrounding whitespace is trimmed first, so a value of only spaces is
237
247
  rejected. `null` is rejected — omit the field instead. At least one field is
238
248
  required, and any field not in the table is rejected.
239
249
 
250
+ **Agent identification**
251
+
252
+ | sent | conversation's agent | `conversation.agent_id` | `warnings` |
253
+ | ------------------------------------- | -------------------- | --------------------------------------------------------------------------------------------- | -------------------------- |
254
+ | `agentId` | set to `agentId` | `agentId` | — |
255
+ | `agentId` + `agentEmail` | set to `agentId` | `agentId` (`agentEmail` is ignored) | — |
256
+ | `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) | — |
257
+ | `agentEmail`, no user matches | unchanged | absent | `agent_not_found` |
258
+ | `agentEmail`, temporarily not checked | unchanged | absent | `agent_lookup_unavailable` |
259
+ - `conversation` never contains `agentEmail`.
260
+ - With a warning, `success` is `true` and every other field you sent is saved.
261
+ - After `agent_lookup_unavailable`, call `updateConversation({ agentEmail })` again later. You do not need to resend the other fields.
262
+
240
263
  **Returns:**
241
264
 
242
- - `Promise<UpdateConversationResult>` - `conversation` echoes only the fields
243
- you sent.
265
+ - `Promise<UpdateConversationResult>`
266
+ - `conversation`: only the fields you sent; a matched `agentEmail` comes back as `agent_id`.
267
+ - `warnings`: present only when part of the update was not applied.
244
268
 
245
269
  ```typescript
246
270
  const result = await sdk.updateConversation({
247
271
  policyNumber: "POL-123",
248
272
  clientEmail: "jane@example.com",
273
+ agentEmail: "vio.agent@example.com",
249
274
  externalStatus: ExternalStatus.COMPLETED,
250
275
  });
251
276
  console.log(result.success, result.conversation.policy_number);
277
+ for (const warning of result.warnings ?? []) {
278
+ console.warn(warning.code, warning.message);
279
+ }
252
280
  ```
253
281
 
254
282
  ##### `ExternalStatus`
@@ -296,6 +324,8 @@ a timeout, a rejected payload.
296
324
  question: string;
297
325
  expected_answer: any;
298
326
  answer_format: { type: "STRING" }
327
+ /** Optional (default: `false`). Use `true` when the fact was collected before the conversation started. It is stored, not verified. */
328
+ prefilled?: boolean
299
329
  /**
300
330
  * Optional. Your own identifiers for this fact — a form field ID, a
301
331
  * section name, anything that lets your UI map the result back to the
@@ -506,6 +536,8 @@ Rules:
506
536
  `unmatched`). Show progress from the `FACT_VERIFIED` event, show the final
507
537
  result from the Promise.
508
538
  - **Handle a `verification_status` you don't recognize as `processing`.**
539
+ - **A fact sent with `prefilled: true` is never verified**, so it gets no
540
+ `verification_status` and no `FACT_VERIFIED` event.
509
541
  - **`pending_confirmation_*` is never final.** The answer can still change,
510
542
  so don't show it as a decision.
511
543
  - **A fact can be revised after `addFact()` has resolved.** If you keep its
@@ -527,6 +559,10 @@ type Application = {
527
559
  agent_id: string;
528
560
  agent_first_name: string; // comes back empty
529
561
  agent_last_name: string; // comes back empty
562
+ // The externalStatus you last sent, lowercased. Missing until you send one
563
+ // — not the same as "draft". Never in the authentication snapshot, so on the
564
+ // fallback path below it is absent, not stale.
565
+ external_status?: ExternalStatus | (string & {});
530
566
  // Missing when there is no summary for the call — not the same as zeros.
531
567
  // See "Reading verification" above.
532
568
  verification?: ApplicationVerificationSummary;
@@ -725,6 +761,8 @@ type ApplicationFactInput = {
725
761
  // and one of them sets status to "critical_errors".
726
762
  critical?: boolean;
727
763
  is_skipped?: boolean;
764
+ /** Optional (default: `false`). Use `true` when the fact was collected before the conversation started. It is stored, not verified. */
765
+ prefilled?: boolean;
728
766
  /**
729
767
  * Optional. Your own identifiers for this fact — a form field ID, a section
730
768
  * name, anything that lets your UI map the result back to the right place.
@@ -770,7 +808,8 @@ type UpdateConversationInput = {
770
808
  clientPhone?: string;
771
809
  clientEmail?: string;
772
810
  clientId?: string;
773
- agentId?: string;
811
+ agentId?: string; // or agentEmail
812
+ agentEmail?: string; // or agentId
774
813
  agentName?: string;
775
814
  advisorId?: string;
776
815
  advisorName?: string;
@@ -781,8 +820,10 @@ type UpdateConversationInput = {
781
820
 
782
821
  ### UpdateConversationResult
783
822
 
784
- Returned by `updateConversation()`. `conversation` echoes only the fields you
785
- sent.
823
+ Returned by `updateConversation()`.
824
+
825
+ - `conversation`: only the fields you sent; a matched `agentEmail` comes back as `agent_id`.
826
+ - `warnings`: present only when part of the update was not applied.
786
827
 
787
828
  ```typescript
788
829
  type UpdateConversationResult = {
@@ -801,9 +842,34 @@ type UpdateConversationResult = {
801
842
  agent_groups?: string[];
802
843
  external_status?: string;
803
844
  };
845
+ // Present only when part of the update was not applied.
846
+ warnings?: ConversationWarning[];
804
847
  };
805
848
  ```
806
849
 
850
+ ### ConversationWarning
851
+
852
+ ```typescript
853
+ interface ConversationWarning {
854
+ code: ConversationWarningCode;
855
+ message: string;
856
+ }
857
+
858
+ type ConversationWarningCode =
859
+ | "agent_not_found"
860
+ | "agent_lookup_unavailable"
861
+ | (string & {});
862
+ ```
863
+
864
+ | `code` | meaning | conversation's agent | what to do |
865
+ | -------------------------- | --------------------------------------------------------------- | -------------------- | ------------------------------------------------ |
866
+ | `agent_not_found` | no AIQA user in your organization has the `agentEmail` | unchanged | check the email |
867
+ | `agent_lookup_unavailable` | the `agentEmail` could not be checked at the moment (temporary) | unchanged | retry `updateConversation({ agentEmail })` later |
868
+ | any other | added in a later version | — | log `message` and continue |
869
+
870
+ - Use `code` to choose what to do; do not parse `message`. `message` is human-readable, includes the email you sent, and may change.
871
+ - `success` is `true` and every other field you sent is saved.
872
+
807
873
  ## Examples
808
874
 
809
875
  ### Complete Example: Recording Session
@@ -56,6 +56,17 @@ type Application = {
56
56
  agent_first_name: string;
57
57
  /** Comes back empty. Set an agent name with `updateConversation()`. */
58
58
  agent_last_name: string;
59
+ /**
60
+ * The status you last reported with `updateConversation({ externalStatus })`,
61
+ * folded to lowercase by the server. Missing when you never reported one —
62
+ * which is not the same as `"draft"`. Unlike the fields above it is never in
63
+ * the authentication snapshot, so on the fallback path described under
64
+ * `verification` it is absent rather than stale.
65
+ *
66
+ * Same open union as the input side: the members autocomplete, and a status
67
+ * the server learns before this package does still type-checks.
68
+ */
69
+ external_status?: ExternalStatus | (string & {});
59
70
  /**
60
71
  * How the call is going so far. When it is missing there is no summary —
61
72
  * which is not the same as all zeros — and the fields above may then be the
@@ -99,14 +110,24 @@ type UpdateConversationInput = {
99
110
  clientPhone?: string;
100
111
  clientEmail?: string;
101
112
  clientId?: string;
113
+ /** The agent's AIQA user id. Takes precedence over `agentEmail`. */
102
114
  agentId?: string;
115
+ /** Email of the agent's AIQA user. Results: README, Agent identification. */
116
+ agentEmail?: string;
103
117
  agentName?: string;
104
118
  advisorId?: string;
105
119
  advisorName?: string;
106
120
  agentGroups?: string[];
107
121
  externalStatus?: ExternalStatus | (string & {});
108
122
  };
109
- /** 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. */
110
131
  type UpdateConversationResult = {
111
132
  success: boolean;
112
133
  conversation: {
@@ -123,6 +144,7 @@ type UpdateConversationResult = {
123
144
  agent_groups?: string[];
124
145
  external_status?: string;
125
146
  };
147
+ warnings?: ConversationWarning[];
126
148
  };
127
149
  declare enum ConversationLanguage {
128
150
  EN = "en",
@@ -170,6 +192,8 @@ type ApplicationFactInput = {
170
192
  */
171
193
  critical?: boolean;
172
194
  is_skipped?: boolean;
195
+ /** Optional (default: `false`). Use `true` when the fact was collected before the conversation started. It is stored, not verified. */
196
+ prefilled?: boolean;
173
197
  /**
174
198
  * Your own identifiers for this fact — a form field ID, a section name,
175
199
  * anything that lets your UI map the result back to the right place.
@@ -217,6 +241,7 @@ interface AddFactResult {
217
241
  answer_type?: string;
218
242
  agent_answer?: string;
219
243
  ai_answer?: string;
244
+ /** `false` for a fact that was never verified, such as a prefilled one. */
220
245
  is_valid_answer: boolean;
221
246
  question_asked?: boolean;
222
247
  /**
@@ -355,4 +380,4 @@ declare class AiQaSdk implements IAiqaSdk {
355
380
  private isManagerEvent;
356
381
  }
357
382
 
358
- 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 };
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 };
@@ -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.2.0-develop.1",
3409
+ version: "2.3.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",