@aiqa/sdk 1.6.0-develop.1 → 2.0.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
@@ -19,6 +19,8 @@ A TypeScript/JavaScript SDK for interacting with the AIQA WebSocket service. Thi
19
19
  - [VerificationStatus](#verificationstatus)
20
20
  - [FactVerifiedPayload](#factverifiedpayload)
21
21
  - [FlagFactResult](#flagfactresult)
22
+ - [UpdateConversationInput](#updateconversationinput)
23
+ - [UpdateConversationResult](#updateconversationresult)
22
24
  - [Examples](#examples)
23
25
  - [Error Handling](#error-handling)
24
26
  - [Semantic Versioning](#semantic-versioning)
@@ -130,6 +132,25 @@ const result = await sdk.setConversationLanguage(ConversationLanguage.EN);
130
132
  console.log(result.success, result.language);
131
133
  ```
132
134
 
135
+ #### `updateConversation(input)`
136
+
137
+ Updates fields on the current conversation. Pass only the fields you want to
138
+ change.
139
+
140
+ **Parameters:**
141
+
142
+ - `input: UpdateConversationInput` - partial set of conversation fields to update
143
+ - `policyNumber?: string` - non-empty; surrounding whitespace is trimmed
144
+
145
+ **Returns:**
146
+
147
+ - `Promise<{ success: boolean; conversation: { policy_number?: string } }>`
148
+
149
+ ```typescript
150
+ const result = await sdk.updateConversation({ policyNumber: "POL-123" });
151
+ console.log(result.success, result.conversation.policy_number);
152
+ ```
153
+
133
154
  ### Fact Management
134
155
 
135
156
  #### `addFact(fact)`
@@ -566,6 +587,29 @@ enum ConversationLanguage {
566
587
  }
567
588
  ```
568
589
 
590
+ ### UpdateConversationInput
591
+
592
+ Partial set of conversation fields accepted by `updateConversation()`.
593
+
594
+ ```typescript
595
+ type UpdateConversationInput = {
596
+ policyNumber?: string;
597
+ };
598
+ ```
599
+
600
+ ### UpdateConversationResult
601
+
602
+ Returned by `updateConversation()`.
603
+
604
+ ```typescript
605
+ type UpdateConversationResult = {
606
+ success: boolean;
607
+ conversation: {
608
+ policy_number?: string;
609
+ };
610
+ };
611
+ ```
612
+
569
613
  ### FactUpdateEvent
570
614
 
571
615
  ```typescript
@@ -17,7 +17,8 @@ declare enum Methods {
17
17
  ADD_FACT = "ADD_FACT",
18
18
  FLAG_FACT = "FLAG_FACT",
19
19
  SET_CONVERSATION_PRODUCT = "SET_CONVERSATION_PRODUCT",
20
- SET_CONVERSATION_LANGUAGE = "SET_CONVERSATION_LANGUAGE"
20
+ SET_CONVERSATION_LANGUAGE = "SET_CONVERSATION_LANGUAGE",
21
+ UPDATE_CONVERSATION = "UPDATE_CONVERSATION"
21
22
  }
22
23
  type SetConversationProductResult = {
23
24
  success: boolean;
@@ -27,6 +28,15 @@ type SetConversationLanguageResult = {
27
28
  success: boolean;
28
29
  language: string;
29
30
  };
31
+ type UpdateConversationInput = {
32
+ policyNumber?: string;
33
+ };
34
+ type UpdateConversationResult = {
35
+ success: boolean;
36
+ conversation: {
37
+ policy_number?: string;
38
+ };
39
+ };
30
40
  declare enum ConversationLanguage {
31
41
  EN = "en",
32
42
  ES = "es",
@@ -264,6 +274,7 @@ declare abstract class IAiqaSdk {
264
274
  abstract getFacts(): Promise<ApplicationFact[]>;
265
275
  abstract setConversationProduct(product: string): Promise<SetConversationProductResult>;
266
276
  abstract setConversationLanguage(language: ConversationLanguage): Promise<SetConversationLanguageResult>;
277
+ abstract updateConversation(input: UpdateConversationInput): Promise<UpdateConversationResult>;
267
278
  }
268
279
 
269
280
  declare class AiQaSdk implements IAiqaSdk {
@@ -287,6 +298,7 @@ declare class AiQaSdk implements IAiqaSdk {
287
298
  flagFact(factId: string): Promise<FlagFactResult>;
288
299
  setConversationProduct(product: string): Promise<SetConversationProductResult>;
289
300
  setConversationLanguage(language: ConversationLanguage): Promise<SetConversationLanguageResult>;
301
+ updateConversation(input: UpdateConversationInput): Promise<UpdateConversationResult>;
290
302
  authenticate(): Promise<void>;
291
303
  startRecording(): Promise<boolean>;
292
304
  stopRecording(): Promise<boolean>;
@@ -296,4 +308,4 @@ declare class AiQaSdk implements IAiqaSdk {
296
308
  private isManagerEvent;
297
309
  }
298
310
 
299
- export { type AddFactResult, AiQaSdk, type Application, type ApplicationFact, type ApplicationFactAnswerChoice, type ApplicationFactAnswerFormat, type ApplicationFactInput, ConversationLanguage, type DialogAct, type DialogActConfidence, FactAnswerFormatType, type FactVerifiedPayload, type FlagFactResult, IAiqaSdk, Methods, type QuestionStatus, type SdkError, type SdkEvent, type SetConversationLanguageResult, type SetConversationProductResult, type TranscriptionUpdate, type Utterance, type VerificationStatus };
311
+ export { type AddFactResult, AiQaSdk, type Application, type ApplicationFact, type ApplicationFactAnswerChoice, type ApplicationFactAnswerFormat, type ApplicationFactInput, ConversationLanguage, type DialogAct, type DialogActConfidence, 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 };
@@ -3348,6 +3348,7 @@ var Methods = /* @__PURE__ */ ((Methods2) => {
3348
3348
  Methods2["FLAG_FACT"] = "FLAG_FACT";
3349
3349
  Methods2["SET_CONVERSATION_PRODUCT"] = "SET_CONVERSATION_PRODUCT";
3350
3350
  Methods2["SET_CONVERSATION_LANGUAGE"] = "SET_CONVERSATION_LANGUAGE";
3351
+ Methods2["UPDATE_CONVERSATION"] = "UPDATE_CONVERSATION";
3351
3352
  return Methods2;
3352
3353
  })(Methods || {});
3353
3354
  var ConversationLanguage = /* @__PURE__ */ ((ConversationLanguage3) => {
@@ -3396,7 +3397,7 @@ var compareVersions = (left, right) => {
3396
3397
  // package.json
3397
3398
  var package_default = {
3398
3399
  name: "@aiqa/sdk",
3399
- version: "1.5.0-develop.4",
3400
+ version: "2.0.0-develop.1",
3400
3401
  main: "dist/node/node.js",
3401
3402
  module: "dist/node/node.js",
3402
3403
  types: "dist/node/node.d.ts",
@@ -3483,11 +3484,19 @@ var USER_AGENT = RUNTIME === "browser" ? typeof navigator !== "undefined" ? navi
3483
3484
  function isThenable(value2) {
3484
3485
  return value2 !== null && typeof value2 === "object" && typeof value2.then === "function";
3485
3486
  }
3486
- function wrapAckHandler(callback) {
3487
+ function wrapEventHandler(callback) {
3487
3488
  return (...args) => {
3488
3489
  const last = args[args.length - 1];
3489
3490
  const hasAck = typeof last === "function";
3490
- const payload = hasAck ? args.slice(0, -1) : args;
3491
+ const rawPayload = hasAck ? args.slice(0, -1) : args;
3492
+ const payload = rawPayload.map((arg) => {
3493
+ if (typeof arg !== "string") return arg;
3494
+ try {
3495
+ return JSON.parse(arg);
3496
+ } catch {
3497
+ return arg;
3498
+ }
3499
+ });
3491
3500
  try {
3492
3501
  const handlerResult = callback(...payload);
3493
3502
  if (isThenable(handlerResult)) {
@@ -3539,7 +3548,7 @@ var AiQaSdk = class {
3539
3548
  if (this.isManagerEvent(name)) {
3540
3549
  this.socket.io.on(name, callback);
3541
3550
  } else {
3542
- const wrapped = wrapAckHandler(callback);
3551
+ const wrapped = wrapEventHandler(callback);
3543
3552
  let wrappersByCallback = this.wrappersByEvent.get(name);
3544
3553
  if (!wrappersByCallback) {
3545
3554
  wrappersByCallback = /* @__PURE__ */ new Map();
@@ -3612,17 +3621,9 @@ var AiQaSdk = class {
3612
3621
  });
3613
3622
  this.socket.on(
3614
3623
  "app_version",
3615
- wrapAckHandler((payload) => {
3616
- let versionRange = payload;
3617
- if (typeof payload === "string") {
3618
- try {
3619
- versionRange = JSON.parse(payload);
3620
- } catch (error) {
3621
- versionRange = payload;
3622
- }
3623
- }
3624
- const minVersion = versionRange?.min;
3625
- const maxVersion = versionRange?.max;
3624
+ wrapEventHandler((payload) => {
3625
+ const minVersion = payload?.min;
3626
+ const maxVersion = payload?.max;
3626
3627
  if (minVersion || maxVersion) {
3627
3628
  const tooLow = minVersion ? compareVersions(SDK_VERSION, minVersion) < 0 : false;
3628
3629
  const tooHigh = maxVersion ? compareVersions(SDK_VERSION, maxVersion) > 0 : false;
@@ -3734,6 +3735,10 @@ var AiQaSdk = class {
3734
3735
  });
3735
3736
  return result && result.data !== void 0 ? result.data : result;
3736
3737
  }
3738
+ async updateConversation(input) {
3739
+ const result = await this.sendMessage("UPDATE_CONVERSATION" /* UPDATE_CONVERSATION */, input);
3740
+ return result && result.data !== void 0 ? result.data : result;
3741
+ }
3737
3742
  async authenticate() {
3738
3743
  try {
3739
3744
  const result = await this.sendMessage("AUTHENTICATE" /* AUTHENTICATE */, {