@smart-cloud/ai-kit-ui 1.5.4 → 1.5.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-cloud/ai-kit-ui",
3
- "version": "1.5.4",
3
+ "version": "1.5.6",
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.2",
25
+ "@smart-cloud/ai-kit-core": "^1.5.3",
26
26
  "@smart-cloud/wpsuite-core": "^2.3.2",
27
27
  "@tabler/icons-react": "^3.46.0",
28
28
  "chroma-js": "^3.2.0",
@@ -44,8 +44,8 @@
44
44
  "@mantine/core": "^8.3.18",
45
45
  "@mantine/hooks": "^8.3.18",
46
46
  "@mantine/modals": "^8.3.18",
47
- "@smart-cloud/aws-amplify-ui": "^6.16.0",
48
- "@smart-cloud/aws-amplify-ui-react": "^6.16.0",
47
+ "@smart-cloud/aws-amplify-ui": "6.15.5",
48
+ "@smart-cloud/aws-amplify-ui-react": "6.15.5",
49
49
  "@wordpress/data": "^10.52.0",
50
50
  "@wordpress/i18n": "^6.25.0",
51
51
  "aws-amplify": "^6.20.0",
@@ -59,8 +59,8 @@
59
59
  "@mantine/core": "^8.3.18",
60
60
  "@mantine/hooks": "^8.3.18",
61
61
  "@mantine/modals": "^8.3.18",
62
- "@smart-cloud/aws-amplify-ui": "^6.16.0",
63
- "@smart-cloud/aws-amplify-ui-react": "^6.16.0",
62
+ "@smart-cloud/aws-amplify-ui": "6.15.5",
63
+ "@smart-cloud/aws-amplify-ui-react": "6.15.5",
64
64
  "@types/dom-chromium-ai": "^0.0.17",
65
65
  "@types/jquery": "^4.0.1",
66
66
  "@types/react": "^18.3.31",
@@ -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 { kind, status, code, safeMessage, requestId };
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":
@@ -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
- code: "HUMAN_VERIFICATION_ERROR",
27
- message: "Assessment rejected",
28
- requestId: "req-human-1",
29
- token: "must-not-leak",
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: "HUMAN_VERIFICATION_ERROR",
37
- safeMessage: "Assessment rejected",
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,