@smart-cloud/ai-kit-ui 1.5.5 → 1.5.7
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/dist/errorHandling.d.ts +3 -0
- package/dist/index.cjs +9 -9
- package/dist/index.js +9 -9
- package/package.json +2 -2
- package/src/errorHandling.ts +43 -1
- package/src/withAiKitShell.tsx +5 -5
- package/tests/error-handling.test.ts +47 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smart-cloud/ai-kit-ui",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@emotion/cache": "^11.14.0",
|
|
23
23
|
"@emotion/react": "^11.14.0",
|
|
24
24
|
"@mantine/colors-generator": "^8.3.18",
|
|
25
|
-
"@smart-cloud/ai-kit-core": "^1.5.
|
|
25
|
+
"@smart-cloud/ai-kit-core": "^1.5.4",
|
|
26
26
|
"@smart-cloud/wpsuite-core": "^2.3.2",
|
|
27
27
|
"@tabler/icons-react": "^3.46.0",
|
|
28
28
|
"chroma-js": "^3.2.0",
|
package/src/errorHandling.ts
CHANGED
|
@@ -8,12 +8,20 @@ export type AiRunErrorKind =
|
|
|
8
8
|
| "server"
|
|
9
9
|
| "general";
|
|
10
10
|
|
|
11
|
+
export type HumanVerificationClassification =
|
|
12
|
+
| "TOKEN_REJECTED"
|
|
13
|
+
| "ACTION_REJECTED"
|
|
14
|
+
| "RISK_REJECTED"
|
|
15
|
+
| "PROVIDER_UNAVAILABLE";
|
|
16
|
+
|
|
11
17
|
export type AiRunErrorDetails = {
|
|
12
18
|
kind: AiRunErrorKind;
|
|
13
19
|
status?: number;
|
|
14
20
|
code?: string;
|
|
15
21
|
safeMessage?: string;
|
|
16
22
|
requestId?: string;
|
|
23
|
+
classification?: HumanVerificationClassification;
|
|
24
|
+
retryable?: boolean;
|
|
17
25
|
};
|
|
18
26
|
|
|
19
27
|
export type AiRunErrorFeedback = {
|
|
@@ -47,6 +55,17 @@ function asStatus(value: unknown): number | undefined {
|
|
|
47
55
|
: undefined;
|
|
48
56
|
}
|
|
49
57
|
|
|
58
|
+
function asHumanVerificationClassification(
|
|
59
|
+
value: unknown,
|
|
60
|
+
): HumanVerificationClassification | undefined {
|
|
61
|
+
return value === "TOKEN_REJECTED" ||
|
|
62
|
+
value === "ACTION_REJECTED" ||
|
|
63
|
+
value === "RISK_REJECTED" ||
|
|
64
|
+
value === "PROVIDER_UNAVAILABLE"
|
|
65
|
+
? value
|
|
66
|
+
: undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
50
69
|
function parsePayload(value: unknown): UnknownRecord | null {
|
|
51
70
|
const record = asRecord(value);
|
|
52
71
|
if (record) return record;
|
|
@@ -169,6 +188,16 @@ export function normalizeAiRunError(error: unknown): AiRunErrorDetails {
|
|
|
169
188
|
headerValue(record.headers ?? asRecord(record.response)?.headers, "x-request-id"),
|
|
170
189
|
)
|
|
171
190
|
.find(Boolean);
|
|
191
|
+
const classification = records
|
|
192
|
+
.map((record) =>
|
|
193
|
+
asHumanVerificationClassification(record.classification),
|
|
194
|
+
)
|
|
195
|
+
.find((value) => value !== undefined);
|
|
196
|
+
const retryable = records
|
|
197
|
+
.map((record) =>
|
|
198
|
+
typeof record.retryable === "boolean" ? record.retryable : undefined,
|
|
199
|
+
)
|
|
200
|
+
.find((value) => value !== undefined);
|
|
172
201
|
|
|
173
202
|
const normalizedCode = (code ?? "").toUpperCase();
|
|
174
203
|
const combined = `${normalizedCode} ${safeMessage ?? ""}`;
|
|
@@ -201,13 +230,26 @@ export function normalizeAiRunError(error: unknown): AiRunErrorDetails {
|
|
|
201
230
|
kind = "server";
|
|
202
231
|
}
|
|
203
232
|
|
|
204
|
-
return {
|
|
233
|
+
return {
|
|
234
|
+
kind,
|
|
235
|
+
status,
|
|
236
|
+
code,
|
|
237
|
+
safeMessage,
|
|
238
|
+
requestId,
|
|
239
|
+
...(classification ? { classification } : {}),
|
|
240
|
+
...(retryable === undefined ? {} : { retryable }),
|
|
241
|
+
};
|
|
205
242
|
}
|
|
206
243
|
|
|
207
244
|
export function getAiRunErrorMessage(
|
|
208
245
|
details: AiRunErrorDetails,
|
|
209
246
|
translate: (message: string) => string = (message) => message,
|
|
210
247
|
): string {
|
|
248
|
+
if (details.classification === "PROVIDER_UNAVAILABLE") {
|
|
249
|
+
return translate(
|
|
250
|
+
"Human verification is temporarily unavailable. Please try again.",
|
|
251
|
+
);
|
|
252
|
+
}
|
|
211
253
|
const messages: Record<AiRunErrorKind, string> = {
|
|
212
254
|
cancelled: "",
|
|
213
255
|
"human-verification":
|
package/src/withAiKitShell.tsx
CHANGED
|
@@ -49,7 +49,6 @@ export function withAiKitShell<P extends object>(
|
|
|
49
49
|
const {
|
|
50
50
|
store,
|
|
51
51
|
variation,
|
|
52
|
-
showOpenButton,
|
|
53
52
|
colors,
|
|
54
53
|
colorMode,
|
|
55
54
|
primaryColor,
|
|
@@ -257,15 +256,16 @@ export function withAiKitShell<P extends object>(
|
|
|
257
256
|
|
|
258
257
|
return (
|
|
259
258
|
<ShadowBoundary
|
|
260
|
-
|
|
259
|
+
// A header button still opens a viewport modal. Mount every modal in
|
|
260
|
+
// the singleton top-level overlay so a sticky/mobile header cannot
|
|
261
|
+
// clip its backdrop to header height.
|
|
262
|
+
mode={variation === "modal" ? "overlay" : "local"}
|
|
261
263
|
variation={variation}
|
|
262
264
|
overlayRootId="ai-kit-overlay-root"
|
|
263
265
|
stylesheets={stylesheets}
|
|
264
266
|
setHost={setHost}
|
|
265
267
|
rootElementId={
|
|
266
|
-
variation === "modal"
|
|
267
|
-
? "ai-kit-portal-root"
|
|
268
|
-
: "ai-kit-inline-root"
|
|
268
|
+
variation === "modal" ? "ai-kit-portal-root" : "ai-kit-inline-root"
|
|
269
269
|
}
|
|
270
270
|
>
|
|
271
271
|
{({ rootElement }) => {
|
|
@@ -23,19 +23,25 @@ function backendError(status: number, body: Record<string, unknown>) {
|
|
|
23
23
|
test("normalizes reCAPTCHA rejection without exposing request data", () => {
|
|
24
24
|
const details = normalizeAiRunError(
|
|
25
25
|
backendError(403, {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
error: {
|
|
27
|
+
code: "HUMAN_VERIFICATION_FAILED",
|
|
28
|
+
classification: "RISK_REJECTED",
|
|
29
|
+
message: "reCAPTCHA verification failed",
|
|
30
|
+
retryable: true,
|
|
31
|
+
requestId: "req-human-1",
|
|
32
|
+
token: "must-not-leak",
|
|
33
|
+
},
|
|
30
34
|
}),
|
|
31
35
|
);
|
|
32
36
|
|
|
33
37
|
assert.deepEqual(details, {
|
|
34
38
|
kind: "human-verification",
|
|
35
39
|
status: 403,
|
|
36
|
-
code: "
|
|
37
|
-
safeMessage: "
|
|
40
|
+
code: "HUMAN_VERIFICATION_FAILED",
|
|
41
|
+
safeMessage: "reCAPTCHA verification failed",
|
|
38
42
|
requestId: "req-human-1",
|
|
43
|
+
classification: "RISK_REJECTED",
|
|
44
|
+
retryable: true,
|
|
39
45
|
});
|
|
40
46
|
assert.equal(
|
|
41
47
|
getAiRunErrorMessage(details),
|
|
@@ -44,6 +50,41 @@ test("normalizes reCAPTCHA rejection without exposing request data", () => {
|
|
|
44
50
|
assert.doesNotMatch(JSON.stringify(details), /must-not-leak/);
|
|
45
51
|
});
|
|
46
52
|
|
|
53
|
+
test("normalizes a reCAPTCHA provider outage as retryable human verification", () => {
|
|
54
|
+
const details = normalizeAiRunError(
|
|
55
|
+
backendError(503, {
|
|
56
|
+
error: {
|
|
57
|
+
code: "HUMAN_VERIFICATION_UNAVAILABLE",
|
|
58
|
+
classification: "PROVIDER_UNAVAILABLE",
|
|
59
|
+
message: "reCAPTCHA verification is temporarily unavailable",
|
|
60
|
+
retryable: true,
|
|
61
|
+
requestId: "req-human-503",
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
assert.equal(details.kind, "human-verification");
|
|
67
|
+
assert.equal(details.classification, "PROVIDER_UNAVAILABLE");
|
|
68
|
+
assert.equal(details.retryable, true);
|
|
69
|
+
assert.equal(
|
|
70
|
+
getAiRunErrorMessage(details),
|
|
71
|
+
"Human verification is temporarily unavailable. Please try again.",
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("continues to recognize the legacy AI Kit reCAPTCHA response during rollout", () => {
|
|
76
|
+
const details = normalizeAiRunError(
|
|
77
|
+
backendError(403, {
|
|
78
|
+
code: "HUMAN_VERIFICATION_ERROR",
|
|
79
|
+
message: "Assessment rejected",
|
|
80
|
+
requestId: "req-human-legacy",
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
assert.equal(details.kind, "human-verification");
|
|
85
|
+
assert.equal(details.classification, undefined);
|
|
86
|
+
});
|
|
87
|
+
|
|
47
88
|
test("distinguishes authorization, throttling, network, and backend failures", () => {
|
|
48
89
|
assert.equal(
|
|
49
90
|
normalizeAiRunError(backendError(401, { code: "UNAUTHORIZED" })).kind,
|