@aiqa/sdk 1.2.0 → 1.4.0-develop.1

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
  - [Fact Management](#fact-management)
15
15
  - [Event Handling](#event-handling)
16
16
  - [Types](#types)
17
+ - [FlagFactResult](#flagfactresult)
17
18
  - [Examples](#examples)
18
19
  - [Error Handling](#error-handling)
19
20
  - [Semantic Versioning](#semantic-versioning)
@@ -137,6 +138,16 @@ Adds a fact to the active application (Promise-based).
137
138
  ```typescript
138
139
  {
139
140
  id: string;
141
+ /**
142
+ * Optional. Stable identifier for the underlying question, shared across
143
+ * applications and conversations. When provided it is used to look up (or
144
+ * create) the matching question row in the database instead of `id`. When
145
+ * omitted, `id` is used (legacy behavior).
146
+ *
147
+ * Keep this consistent across calls for the "same" question — see
148
+ * "Question identity and questionId" below.
149
+ */
150
+ questionId?: string;
140
151
  question: string;
141
152
  expected_answer: any;
142
153
  answer_format: { type: "STRING" }
@@ -157,6 +168,7 @@ Adds a fact to the active application (Promise-based).
157
168
  ```typescript
158
169
  const isMatched = await sdk.addFact({
159
170
  id: "fact-123",
171
+ questionId: "agreement-q",
160
172
  question: "Do you agree?",
161
173
  expected_answer: "Yes",
162
174
  answer_format: { type: "STRING" },
@@ -164,6 +176,37 @@ const isMatched = await sdk.addFact({
164
176
  });
165
177
  ```
166
178
 
179
+ ##### Question identity and `questionId`
180
+
181
+ `id` identifies an instance of a fact within a single conversation. `questionId`
182
+ is an optional field that identifies the underlying question across every
183
+ application and conversation that asks it. They're separated so you can give
184
+ each fact instance its own `id` (e.g. a per-call uuid) while still pointing at a
185
+ stable question identity.
186
+
187
+ Two server-side features are scoped per question identity:
188
+
189
+ - **Accuracy improvements.** Per-question signals (flags, model tweaks, fuzzy
190
+ matches) accumulate against the question row. Splitting the same logical
191
+ question across multiple identities splits these signals and resets the
192
+ accuracy gains you've already earned.
193
+ - **Remaps from the management dashboard.** When an operator remaps a question
194
+ in the dashboard, the remap is stored on the question row. A subsequent call
195
+ with a different identity won't pick up the remap.
196
+
197
+ The "question identity" the server uses is `questionId` if you sent one,
198
+ otherwise `id`. So:
199
+
200
+ - If your `id` is already stable across calls for the same logical question,
201
+ omitting `questionId` is fine — both features above still work, just keyed off
202
+ `id`.
203
+ - If your `id` varies per call (per-call uuid, ephemeral instance id, etc.),
204
+ send a stable `questionId`. Otherwise each call looks like a new question and
205
+ you lose the features above.
206
+ - Once you've picked an identity for a question, don't change it. If you must
207
+ rename, coordinate with the team owning the dashboard so remaps and
208
+ historical signals can be migrated.
209
+
167
210
  #### `getFacts()`
168
211
 
169
212
  Retrieves all facts for the application (Promise-based). Each fact includes a `metadata` field containing whatever was passed to `addFact()`. Facts added without `metadata` return `{}`.
@@ -175,6 +218,23 @@ facts.forEach((fact) => {
175
218
  });
176
219
  ```
177
220
 
221
+ #### `flagFact(factId)`
222
+
223
+ Flags a fact for human review. Creates a signal that allow AIQA to improve review quality.
224
+
225
+ **Parameters:**
226
+
227
+ - `factId: string` - the `id` of the fact to flag (must match the `id` used in `addFact()`)
228
+
229
+ **Returns:**
230
+
231
+ - `Promise<FlagFactResult>` — `{ success: boolean }`
232
+
233
+ ```typescript
234
+ const result = await sdk.flagFact("fact-123");
235
+ console.log(result.success); // true
236
+ ```
237
+
178
238
  ### Recording Management
179
239
 
180
240
  #### `startRecording()`
@@ -271,6 +331,16 @@ type ApplicationFact = ApplicationFactInput & {
271
331
  ```typescript
272
332
  type ApplicationFactInput = {
273
333
  id: string;
334
+ /**
335
+ * Optional. Stable identifier for the underlying question, shared across
336
+ * applications and conversations. Used to look up (or create) the matching
337
+ * question row in the database when provided. When omitted, `id` is used.
338
+ *
339
+ * Keep this consistent across calls — accuracy improvements and remaps
340
+ * configured in the management dashboard are scoped per `questionId`. See
341
+ * "Question identity and questionId" under `addFact()`.
342
+ */
343
+ questionId?: string;
274
344
  question: string;
275
345
  expected_answer: any;
276
346
  answer_format: {
@@ -309,6 +379,16 @@ type ApplicationFactInput = {
309
379
  };
310
380
  ```
311
381
 
382
+ ### FlagFactResult
383
+
384
+ Returned by `flagFact()`.
385
+
386
+ ```typescript
387
+ type FlagFactResult = {
388
+ success: boolean;
389
+ };
390
+ ```
391
+
312
392
  ### ConversationLanguage
313
393
 
314
394
  ```typescript
@@ -15,6 +15,7 @@ declare enum Methods {
15
15
  STOP_RECORDING = "STOP_RECORDING",
16
16
  IS_RECORDING = "IS_RECORDING",
17
17
  ADD_FACT = "ADD_FACT",
18
+ FLAG_FACT = "FLAG_FACT",
18
19
  SET_CONVERSATION_PRODUCT = "SET_CONVERSATION_PRODUCT",
19
20
  SET_CONVERSATION_LANGUAGE = "SET_CONVERSATION_LANGUAGE"
20
21
  }
@@ -53,6 +54,14 @@ type ApplicationFactAnswerFormat = {
53
54
  };
54
55
  type ApplicationFactInput = {
55
56
  id: string;
57
+ /**
58
+ * Stable identifier for the underlying question, shared across applications and
59
+ * conversations. When provided it is used to look up (or create) the matching
60
+ * question row in the database instead of `id`. Keep this consistent across
61
+ * calls — accuracy improvements and remaps configured in the management
62
+ * dashboard are scoped per `questionId`.
63
+ */
64
+ questionId?: string;
56
65
  question: string;
57
66
  expected_answer: any;
58
67
  answer_format: ApplicationFactAnswerFormat;
@@ -75,7 +84,11 @@ interface AddFactResult {
75
84
  ai_answer?: string;
76
85
  is_valid_answer: boolean;
77
86
  question_asked?: boolean;
87
+ metadata?: Record<string, string>;
78
88
  }
89
+ type FlagFactResult = {
90
+ success: boolean;
91
+ };
79
92
  type SdkError = {
80
93
  code: "INVALID_CONFIG" | "CONNECTION_ERROR" | "TIMEOUT" | "SERVER_ERROR" | "UNEXPECTED_RESPONSE";
81
94
  message: string;
@@ -88,6 +101,7 @@ declare abstract class IAiqaSdk {
88
101
  abstract off(eventName: string): void;
89
102
  abstract getApplication(): Promise<Application>;
90
103
  abstract addFact(fact: ApplicationFactInput): Promise<AddFactResult>;
104
+ abstract flagFact(factId: string): Promise<FlagFactResult>;
91
105
  abstract getFacts(): Promise<ApplicationFact[]>;
92
106
  abstract setConversationProduct(product: string): Promise<SetConversationProductResult>;
93
107
  abstract setConversationLanguage(language: ConversationLanguage): Promise<SetConversationLanguageResult>;
@@ -110,6 +124,7 @@ declare class AiQaSdk implements IAiqaSdk {
110
124
  getApplication(): Promise<Application>;
111
125
  getFacts(): Promise<ApplicationFact[]>;
112
126
  addFact(fact: ApplicationFactInput): Promise<AddFactResult>;
127
+ flagFact(factId: string): Promise<FlagFactResult>;
113
128
  setConversationProduct(product: string): Promise<SetConversationProductResult>;
114
129
  setConversationLanguage(language: ConversationLanguage): Promise<SetConversationLanguageResult>;
115
130
  authenticate(): Promise<void>;
@@ -121,4 +136,4 @@ declare class AiQaSdk implements IAiqaSdk {
121
136
  private isManagerEvent;
122
137
  }
123
138
 
124
- export { type AddFactResult, AiQaSdk, type Application, type ApplicationFact, type ApplicationFactAnswerChoice, type ApplicationFactAnswerFormat, type ApplicationFactInput, ConversationLanguage, FactAnswerFormatType, IAiqaSdk, Methods, type QuestionStatus, type SdkError, type SdkEvent, type SetConversationLanguageResult, type SetConversationProductResult, type VerificationStatus };
139
+ export { type AddFactResult, AiQaSdk, type Application, type ApplicationFact, type ApplicationFactAnswerChoice, type ApplicationFactAnswerFormat, type ApplicationFactInput, ConversationLanguage, FactAnswerFormatType, type FlagFactResult, IAiqaSdk, Methods, type QuestionStatus, type SdkError, type SdkEvent, type SetConversationLanguageResult, type SetConversationProductResult, type VerificationStatus };
@@ -3345,6 +3345,7 @@ var Methods = /* @__PURE__ */ ((Methods2) => {
3345
3345
  Methods2["STOP_RECORDING"] = "STOP_RECORDING";
3346
3346
  Methods2["IS_RECORDING"] = "IS_RECORDING";
3347
3347
  Methods2["ADD_FACT"] = "ADD_FACT";
3348
+ Methods2["FLAG_FACT"] = "FLAG_FACT";
3348
3349
  Methods2["SET_CONVERSATION_PRODUCT"] = "SET_CONVERSATION_PRODUCT";
3349
3350
  Methods2["SET_CONVERSATION_LANGUAGE"] = "SET_CONVERSATION_LANGUAGE";
3350
3351
  return Methods2;
@@ -3395,7 +3396,7 @@ var compareVersions = (left, right) => {
3395
3396
  // package.json
3396
3397
  var package_default = {
3397
3398
  name: "@aiqa/sdk",
3398
- version: "1.1.0-develop.1",
3399
+ version: "1.3.0",
3399
3400
  main: "dist/node/node.js",
3400
3401
  module: "dist/node/node.js",
3401
3402
  types: "dist/node/node.d.ts",
@@ -3630,6 +3631,12 @@ var AiQaSdk = class {
3630
3631
  const result = await this.sendMessage("ADD_FACT" /* ADD_FACT */, payload);
3631
3632
  return result && result.data !== void 0 ? result.data : result;
3632
3633
  }
3634
+ async flagFact(factId) {
3635
+ const result = await this.sendMessage("FLAG_FACT" /* FLAG_FACT */, {
3636
+ factId
3637
+ });
3638
+ return result && result.data !== void 0 ? result.data : result;
3639
+ }
3633
3640
  async setConversationProduct(product) {
3634
3641
  const result = await this.sendMessage("SET_CONVERSATION_PRODUCT" /* SET_CONVERSATION_PRODUCT */, {
3635
3642
  product