@aiqa/sdk 1.3.0 → 1.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 +52 -0
- package/dist/browser/browser.d.ts +87 -3
- package/dist/browser/browser.js +19 -3
- package/dist/browser/browser.js.map +1 -1
- package/dist/node/node.d.ts +87 -3
- package/dist/node/node.js +19 -3
- package/dist/node/node.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -138,6 +138,16 @@ Adds a fact to the active application (Promise-based).
|
|
|
138
138
|
```typescript
|
|
139
139
|
{
|
|
140
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;
|
|
141
151
|
question: string;
|
|
142
152
|
expected_answer: any;
|
|
143
153
|
answer_format: { type: "STRING" }
|
|
@@ -158,6 +168,7 @@ Adds a fact to the active application (Promise-based).
|
|
|
158
168
|
```typescript
|
|
159
169
|
const isMatched = await sdk.addFact({
|
|
160
170
|
id: "fact-123",
|
|
171
|
+
questionId: "agreement-q",
|
|
161
172
|
question: "Do you agree?",
|
|
162
173
|
expected_answer: "Yes",
|
|
163
174
|
answer_format: { type: "STRING" },
|
|
@@ -165,6 +176,37 @@ const isMatched = await sdk.addFact({
|
|
|
165
176
|
});
|
|
166
177
|
```
|
|
167
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
|
+
|
|
168
210
|
#### `getFacts()`
|
|
169
211
|
|
|
170
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 `{}`.
|
|
@@ -289,6 +331,16 @@ type ApplicationFact = ApplicationFactInput & {
|
|
|
289
331
|
```typescript
|
|
290
332
|
type ApplicationFactInput = {
|
|
291
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;
|
|
292
344
|
question: string;
|
|
293
345
|
expected_answer: any;
|
|
294
346
|
answer_format: {
|
|
@@ -32,7 +32,7 @@ declare enum ConversationLanguage {
|
|
|
32
32
|
ES = "es",
|
|
33
33
|
FR = "fr"
|
|
34
34
|
}
|
|
35
|
-
type SdkEvent = Methods | "connect" | "disconnect" | "close" | "error" | "reconnect_attempt" | "reconnect_error" | "reconnect_failed" | "authenticated" | "app_version";
|
|
35
|
+
type SdkEvent = Methods | "connect" | "disconnect" | "close" | "error" | "reconnect_attempt" | "reconnect_error" | "reconnect_failed" | "authenticated" | "app_version" | "fact_verified";
|
|
36
36
|
declare enum FactAnswerFormatType {
|
|
37
37
|
string = "STRING",
|
|
38
38
|
number = "NUMBER",
|
|
@@ -54,6 +54,14 @@ type ApplicationFactAnswerFormat = {
|
|
|
54
54
|
};
|
|
55
55
|
type ApplicationFactInput = {
|
|
56
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;
|
|
57
65
|
question: string;
|
|
58
66
|
expected_answer: any;
|
|
59
67
|
answer_format: ApplicationFactAnswerFormat;
|
|
@@ -65,7 +73,25 @@ type ApplicationFactInput = {
|
|
|
65
73
|
metadata?: Record<string, string>;
|
|
66
74
|
};
|
|
67
75
|
type QuestionStatus = "searching" | "asked" | "not_asked";
|
|
68
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Per-fact verification state.
|
|
78
|
+
*
|
|
79
|
+
* Extended from the original three-state shape to carry progress signals
|
|
80
|
+
* the backend already detects but previously could not express. Consumers
|
|
81
|
+
* that switch on this value MUST treat unknown strings as "processing"
|
|
82
|
+
* (default fall-through) so older SDK builds keep working after the
|
|
83
|
+
* backend starts emitting the additive states.
|
|
84
|
+
*
|
|
85
|
+
* Semantics:
|
|
86
|
+
* - `processing` generic, just queued or transcription not ready
|
|
87
|
+
* - `awaiting_question` agent hasn't asked the question yet
|
|
88
|
+
* - `awaiting_answer` question asked, customer hasn't answered yet
|
|
89
|
+
* - `partial` partial evidence; backend still working on it
|
|
90
|
+
* - `matched` terminal: answer matched expected
|
|
91
|
+
* - `unmatched` terminal: budget exhausted with no match
|
|
92
|
+
* - `contradicted` terminal (future): customer contradicted expected
|
|
93
|
+
*/
|
|
94
|
+
type VerificationStatus = "processing" | "awaiting_question" | "awaiting_answer" | "partial" | "matched" | "unmatched" | "contradicted";
|
|
69
95
|
type ApplicationFact = ApplicationFactInput & {
|
|
70
96
|
ai_answer?: any;
|
|
71
97
|
question_status: QuestionStatus;
|
|
@@ -76,7 +102,65 @@ interface AddFactResult {
|
|
|
76
102
|
ai_answer?: string;
|
|
77
103
|
is_valid_answer: boolean;
|
|
78
104
|
question_asked?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* 0–1 (or 0–100 — scale matches the configured similarity method).
|
|
107
|
+
* Similarity between the agent's utterance and the expected question.
|
|
108
|
+
* Renamed from `match_score` to disambiguate from the answer-side score.
|
|
109
|
+
*/
|
|
110
|
+
question_match_score?: number;
|
|
111
|
+
/**
|
|
112
|
+
* 0–1 score derived from how well the customer's answer matched expected.
|
|
113
|
+
* Populated by the verification queue from partial-match heuristics
|
|
114
|
+
* (numeric-prefix ratio, matched-components ratio). Undefined when no
|
|
115
|
+
* partial signal exists or for terminal results before this rolls out.
|
|
116
|
+
*/
|
|
117
|
+
answer_match_score?: number;
|
|
79
118
|
metadata?: Record<string, string>;
|
|
119
|
+
/**
|
|
120
|
+
* Top-level state at terminal resolution. Always one of `matched`,
|
|
121
|
+
* `unmatched`, or `contradicted` because the `addFact()` Promise only
|
|
122
|
+
* resolves on terminals. Optional during the rollout window for
|
|
123
|
+
* backwards compatibility with older backends.
|
|
124
|
+
*/
|
|
125
|
+
verification_status?: VerificationStatus;
|
|
126
|
+
/**
|
|
127
|
+
* Per-fact partial-match breakdown carried through from the
|
|
128
|
+
* verification queue's component-wise comparators. For numeric-prefix
|
|
129
|
+
* facts these are `["prefix"]` / `["suffix"]`; future work will
|
|
130
|
+
* generalise to addresses, names, dates, etc.
|
|
131
|
+
*/
|
|
132
|
+
matched_components?: string[];
|
|
133
|
+
missing_components?: string[];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Payload of the `fact_verified` broadcast event.
|
|
137
|
+
*
|
|
138
|
+
* Fires on EVERY state transition the verification queue produces —
|
|
139
|
+
* partial (`partial`, `awaiting_question`, `awaiting_answer`,
|
|
140
|
+
* `processing`) AND terminal (`matched`, `unmatched`, `contradicted`).
|
|
141
|
+
*
|
|
142
|
+
* Subscribe with:
|
|
143
|
+
* sdk.on("fact_verified", (payload: FactVerifiedPayload) => {...});
|
|
144
|
+
*
|
|
145
|
+
* `addFact()`'s Promise resolves only on terminals; this event stream
|
|
146
|
+
* is the channel for rendering live progress in the agent UI.
|
|
147
|
+
*/
|
|
148
|
+
interface FactVerifiedPayload {
|
|
149
|
+
factId: string;
|
|
150
|
+
success: boolean;
|
|
151
|
+
verification_status?: VerificationStatus;
|
|
152
|
+
question_match_score?: number;
|
|
153
|
+
answer_match_score?: number;
|
|
154
|
+
matched_components?: string[];
|
|
155
|
+
missing_components?: string[];
|
|
156
|
+
/**
|
|
157
|
+
* Inner data payload. Shape matches `AddFactResult` (minus the
|
|
158
|
+
* top-level envelope fields) so consumers can reuse the same
|
|
159
|
+
* rendering code for the terminal addFact() resolution and the
|
|
160
|
+
* broadcast event.
|
|
161
|
+
*/
|
|
162
|
+
data?: AddFactResult;
|
|
163
|
+
error?: string;
|
|
80
164
|
}
|
|
81
165
|
type FlagFactResult = {
|
|
82
166
|
success: boolean;
|
|
@@ -128,4 +212,4 @@ declare class AiQaSdk implements IAiqaSdk {
|
|
|
128
212
|
private isManagerEvent;
|
|
129
213
|
}
|
|
130
214
|
|
|
131
|
-
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 };
|
|
215
|
+
export { type AddFactResult, AiQaSdk, type Application, type ApplicationFact, type ApplicationFactAnswerChoice, type ApplicationFactAnswerFormat, type ApplicationFactInput, ConversationLanguage, FactAnswerFormatType, type FactVerifiedPayload, type FlagFactResult, IAiqaSdk, Methods, type QuestionStatus, type SdkError, type SdkEvent, type SetConversationLanguageResult, type SetConversationProductResult, type VerificationStatus };
|
package/dist/browser/browser.js
CHANGED
|
@@ -3396,7 +3396,7 @@ var compareVersions = (left, right) => {
|
|
|
3396
3396
|
// package.json
|
|
3397
3397
|
var package_default = {
|
|
3398
3398
|
name: "@aiqa/sdk",
|
|
3399
|
-
version: "1.
|
|
3399
|
+
version: "1.4.0-develop.1",
|
|
3400
3400
|
main: "dist/node/node.js",
|
|
3401
3401
|
module: "dist/node/node.js",
|
|
3402
3402
|
types: "dist/node/node.d.ts",
|
|
@@ -3599,7 +3599,7 @@ var AiQaSdk = class {
|
|
|
3599
3599
|
reject(parsed.error);
|
|
3600
3600
|
return;
|
|
3601
3601
|
}
|
|
3602
|
-
resolve(parsed
|
|
3602
|
+
resolve(parsed);
|
|
3603
3603
|
};
|
|
3604
3604
|
this.socket.on(requestId, handler);
|
|
3605
3605
|
const payload = data && typeof data === "object" ? { ...data, requestId } : { requestId, data };
|
|
@@ -3629,7 +3629,23 @@ var AiQaSdk = class {
|
|
|
3629
3629
|
is_skipped: fact.is_skipped ?? false
|
|
3630
3630
|
};
|
|
3631
3631
|
const result = await this.sendMessage("ADD_FACT" /* ADD_FACT */, payload);
|
|
3632
|
-
|
|
3632
|
+
if (!result) return result;
|
|
3633
|
+
const inner = result.data !== void 0 ? result.data : result;
|
|
3634
|
+
const hasEnvelope = result.verification_status !== void 0 || result.matched_components !== void 0 || result.missing_components !== void 0;
|
|
3635
|
+
if (!hasEnvelope || typeof inner !== "object" || inner === null) {
|
|
3636
|
+
return inner;
|
|
3637
|
+
}
|
|
3638
|
+
const merged = { ...inner };
|
|
3639
|
+
if (result.verification_status !== void 0) {
|
|
3640
|
+
merged.verification_status = result.verification_status;
|
|
3641
|
+
}
|
|
3642
|
+
if (result.matched_components !== void 0) {
|
|
3643
|
+
merged.matched_components = result.matched_components;
|
|
3644
|
+
}
|
|
3645
|
+
if (result.missing_components !== void 0) {
|
|
3646
|
+
merged.missing_components = result.missing_components;
|
|
3647
|
+
}
|
|
3648
|
+
return merged;
|
|
3633
3649
|
}
|
|
3634
3650
|
async flagFact(factId) {
|
|
3635
3651
|
const result = await this.sendMessage("FLAG_FACT" /* FLAG_FACT */, {
|