@cognicatch/react 1.1.1 → 1.1.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/dist/index.js CHANGED
@@ -1,27 +1,63 @@
1
1
  import { jsx as r, jsxs as u } from "react/jsx-runtime";
2
- import { useState as R, useEffect as D, createContext as S, useCallback as P, useMemo as T, useContext as M, Component as I } from "react";
3
- import { AlertCircle as y, AlertTriangle as C, AlertOctagon as F, RefreshCcw as L, ExternalLink as j, CheckCircle2 as U, Info as O } from "lucide-react";
4
- import { clsx as B } from "clsx";
5
- import { twMerge as Z } from "tailwind-merge";
6
- import * as k from "@radix-ui/react-dialog";
7
- import { Toaster as $, toast as h } from "sonner";
8
- const J = [
9
- { name: "email", pattern: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g, replacement: "[EMAIL_REDACTED]" },
10
- { name: "bearer_token", pattern: /Bearer\s+[A-Za-z0-9\-._~+/]+=*/gi, replacement: "Bearer [TOKEN_REDACTED]" },
11
- { name: "jwt", pattern: /eyJ[A-Za-z0-9\-_]+\.eyJ[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+/g, replacement: "[JWT_REDACTED]" },
12
- { name: "api_key", pattern: /\b(?:sk|pk|key|api|sec)_[a-zA-Z0-9]{20,}\b|\b[A-Za-z0-9]{32,48}\b/g, replacement: "[KEY_REDACTED]" },
13
- { name: "phone", pattern: /(?:\+?\d{1,3}[-.\s]?)?\(?\d{2,4}\)?[-.\s]?\d{3,5}[-.\s]?\d{4}\b/g, replacement: "[PHONE_REDACTED]" },
14
- { name: "ipv4", pattern: /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/g, replacement: "[IP_REDACTED]" },
15
- { name: "url_query_params", pattern: /([?&](?:token|key|secret|auth|email|user|access_token|refresh_token|api_key|apikey|password|passwd|pwd)=[^&\s]+)/gi, replacement: "[PARAM_REDACTED]" },
16
- { name: "ssn", pattern: /\b\d{3}[-\s]?\d{2}[-\s]?\d{4}\b/g, replacement: "[SSN_REDACTED]" },
17
- { name: "credit_card", pattern: /\b(?:\d[ -]?){12,18}\d\b/g, replacement: "[CC_REDACTED]" }
2
+ import { useState as P, useEffect as T, createContext as M, useCallback as I, useMemo as F, useContext as L, Component as j } from "react";
3
+ import { AlertCircle as y, AlertTriangle as C, AlertOctagon as U, RefreshCcw as B, ExternalLink as O, CheckCircle2 as $, Info as Z } from "lucide-react";
4
+ import { clsx as J } from "clsx";
5
+ import { twMerge as K } from "tailwind-merge";
6
+ import * as g from "@radix-ui/react-dialog";
7
+ import { toast as h, Toaster as W } from "sonner";
8
+ const Y = [
9
+ {
10
+ name: "email",
11
+ pattern: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,
12
+ replacement: "[EMAIL_REDACTED]"
13
+ },
14
+ {
15
+ name: "bearer_token",
16
+ pattern: /Bearer\s+[A-Za-z0-9\-._~+/]+=*/gi,
17
+ replacement: "Bearer [TOKEN_REDACTED]"
18
+ },
19
+ {
20
+ name: "jwt",
21
+ pattern: /eyJ[A-Za-z0-9\-_]+\.eyJ[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+/g,
22
+ replacement: "[JWT_REDACTED]"
23
+ },
24
+ {
25
+ name: "api_key",
26
+ pattern: /\b(?:sk|pk|key|api|sec)_[a-zA-Z0-9]{20,}\b|\b[A-Za-z0-9]{32,48}\b/g,
27
+ replacement: "[KEY_REDACTED]"
28
+ },
29
+ {
30
+ name: "phone",
31
+ pattern: /(?:\+?\d{1,3}[-.\s]?)?\(?\d{2,4}\)?[-.\s]?\d{3,5}[-.\s]?\d{4}\b/g,
32
+ replacement: "[PHONE_REDACTED]"
33
+ },
34
+ {
35
+ name: "ipv4",
36
+ pattern: /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/g,
37
+ replacement: "[IP_REDACTED]"
38
+ },
39
+ {
40
+ name: "url_query_params",
41
+ pattern: /([?&](?:token|key|secret|auth|email|user|access_token|refresh_token|api_key|apikey|password|passwd|pwd)=[^&\s]+)/gi,
42
+ replacement: "[PARAM_REDACTED]"
43
+ },
44
+ {
45
+ name: "ssn",
46
+ pattern: /\b\d{3}[-\s]?\d{2}[-\s]?\d{4}\b/g,
47
+ replacement: "[SSN_REDACTED]"
48
+ },
49
+ {
50
+ name: "credit_card",
51
+ pattern: /\b(?:\d[ -]?){12,18}\d\b/g,
52
+ replacement: "[CC_REDACTED]"
53
+ }
18
54
  ];
19
- function z(t, e = 1e3) {
55
+ function A(t, e = 1e3) {
20
56
  if (!t) return "";
21
57
  let o = String(t);
22
- return o.length > e && (o = o.slice(0, e) + "... [TRUNCATED]"), J.reduce((a, { pattern: s, replacement: n }) => a.replace(s, n), o);
58
+ return o.length > e && (o = `${o.slice(0, e)}... [TRUNCATED]`), Y.reduce((a, { pattern: i, replacement: n }) => a.replace(i, n), o);
23
59
  }
24
- function _(t) {
60
+ function R(t) {
25
61
  let e;
26
62
  if (t.url)
27
63
  try {
@@ -36,26 +72,26 @@ function _(t) {
36
72
  o = /at (\w+)/.exec(a)?.[1];
37
73
  }
38
74
  return {
39
- message: z(t.message, 500),
75
+ message: A(t.message, 500),
40
76
  httpStatus: t.httpStatus,
41
- errorCode: t.errorCode ? z(t.errorCode, 100) : void 0,
77
+ errorCode: t.errorCode ? A(t.errorCode, 100) : void 0,
42
78
  routePath: e,
43
79
  componentName: o
44
80
  };
45
81
  }
46
82
  function f(...t) {
47
- return Z(B(t));
83
+ return K(J(t));
48
84
  }
49
- function A({
85
+ function N({
50
86
  title: t,
51
87
  description: e,
52
88
  severity: o = "medium",
53
89
  primaryAction: a,
54
- secondaryAction: s,
90
+ secondaryAction: i,
55
91
  theme: n,
56
- className: i
92
+ className: s
57
93
  }) {
58
- const d = o === "high";
94
+ const l = o === "high";
59
95
  return /* @__PURE__ */ r(
60
96
  "div",
61
97
  {
@@ -65,7 +101,7 @@ function A({
65
101
  "rounded-xl border p-4 transition-all shadow-sm",
66
102
  !n?.backgroundColor && "bg-amber-50 border-amber-200/60 dark:bg-amber-950/20 dark:border-amber-900/40",
67
103
  n?.fontFamily,
68
- i
104
+ s
69
105
  ),
70
106
  style: {
71
107
  backgroundColor: n?.backgroundColor,
@@ -73,7 +109,7 @@ function A({
73
109
  borderColor: n?.primaryColor ? `${n.primaryColor}40` : void 0
74
110
  },
75
111
  children: /* @__PURE__ */ u("div", { className: "flex gap-3", children: [
76
- /* @__PURE__ */ r("div", { className: "shrink-0 mt-0.5", children: d ? /* @__PURE__ */ r(y, { className: "h-5 w-5 text-red-500" }) : /* @__PURE__ */ r(C, { className: "h-5 w-5 text-amber-500" }) }),
112
+ /* @__PURE__ */ r("div", { className: "shrink-0 mt-0.5", children: l ? /* @__PURE__ */ r(y, { className: "h-5 w-5 text-red-500" }) : /* @__PURE__ */ r(C, { className: "h-5 w-5 text-amber-500" }) }),
77
113
  /* @__PURE__ */ u("div", { className: "flex-1 min-w-0", children: [
78
114
  /* @__PURE__ */ r(
79
115
  "h3",
@@ -91,11 +127,12 @@ function A({
91
127
  children: e
92
128
  }
93
129
  ),
94
- (a || s) && /* @__PURE__ */ u("div", { className: "mt-4 flex flex-wrap items-center gap-3", children: [
130
+ (a || i) && /* @__PURE__ */ u("div", { className: "mt-4 flex flex-wrap items-center gap-3", children: [
95
131
  a && /* @__PURE__ */ r(
96
132
  "button",
97
133
  {
98
134
  onClick: a.onClick,
135
+ type: "button",
99
136
  style: n?.primaryColor ? { backgroundColor: n.primaryColor, color: "#fff" } : {},
100
137
  className: f(
101
138
  "text-xs font-medium px-3 py-1.5 rounded-lg transition-all active:scale-95",
@@ -105,13 +142,14 @@ function A({
105
142
  children: a.label
106
143
  }
107
144
  ),
108
- s && /* @__PURE__ */ r(
145
+ i && /* @__PURE__ */ r(
109
146
  "button",
110
147
  {
111
- onClick: s.onClick,
148
+ type: "button",
149
+ onClick: i.onClick,
112
150
  className: "text-xs font-medium opacity-70 hover:opacity-100 transition-opacity underline-offset-4 hover:underline",
113
151
  style: { color: n?.textColor },
114
- children: s.label
152
+ children: i.label
115
153
  }
116
154
  )
117
155
  ] })
@@ -120,92 +158,177 @@ function A({
120
158
  }
121
159
  );
122
160
  }
123
- function N({
161
+ function E({
124
162
  title: t,
125
163
  description: e,
126
164
  statusUrl: o,
127
165
  showRefresh: a = !0,
128
- isOpen: s,
166
+ isOpen: i,
129
167
  onOpenChange: n,
130
- theme: i,
131
- onPrimaryAction: d,
132
- primaryActionLabel: c = "Refresh the page"
168
+ theme: s,
169
+ onPrimaryAction: l,
170
+ primaryActionLabel: m = "Refresh the page"
133
171
  }) {
134
- const [l, m] = R(!1);
135
- D(() => {
136
- m(!0);
172
+ const [d, p] = P(!1);
173
+ T(() => {
174
+ p(!0);
137
175
  }, []);
138
- const b = i === "dark" || typeof i == "object" && i?.backgroundColor === "dark", p = typeof i == "object" ? i.primaryColor : void 0, v = typeof i == "object" ? i.fontFamily : void 0;
139
- return l ? /* @__PURE__ */ r(k.Root, { open: s, onOpenChange: n, children: /* @__PURE__ */ r(k.Portal, { children: /* @__PURE__ */ u("div", { className: `cognicatch-ui-wrapper ${b ? "dark" : ""} ${v || ""}`, children: [
140
- /* @__PURE__ */ r(
141
- k.Overlay,
142
- {
143
- className: "radix-overlay fixed inset-0 z-[99999] bg-zinc-900/20 dark:bg-black/80 backdrop-blur-sm"
144
- }
145
- ),
146
- /* @__PURE__ */ r("div", { className: "fixed inset-0 z-[999999] flex items-end md:items-center justify-center pointer-events-none md:p-4", children: /* @__PURE__ */ u(
147
- k.Content,
148
- {
149
- onInteractOutside: (g) => g.preventDefault(),
150
- onEscapeKeyDown: (g) => g.preventDefault(),
151
- className: f(
152
- "pointer-events-auto w-full flex flex-col items-center text-center shadow-2xl transition-all",
153
- "bg-white dark:bg-zinc-950",
154
- "rounded-t-3xl border-t border-zinc-200 dark:border-zinc-800 p-8 pb-10",
155
- "md:max-w-md md:rounded-2xl md:border md:border-zinc-200 md:dark:border-zinc-800"
156
- ),
157
- style: { boxSizing: "border-box" },
158
- children: [
159
- /* @__PURE__ */ r("div", { className: "mx-auto w-12 h-1.5 rounded-full bg-zinc-200 dark:bg-zinc-800 mb-6 md:hidden" }),
160
- /* @__PURE__ */ r("div", { className: "w-16 h-16 rounded-full flex items-center justify-center mb-6 border bg-red-50 border-red-100 dark:bg-red-500/10 dark:border-red-500/20", children: /* @__PURE__ */ r(F, { className: "w-8 h-8 text-red-600 dark:text-red-500" }) }),
161
- /* @__PURE__ */ r(k.Title, { className: "text-xl font-semibold text-zinc-900 dark:text-zinc-50 mb-3 tracking-tight", children: t }),
162
- /* @__PURE__ */ r(k.Description, { className: "text-sm leading-relaxed mb-8 max-w-[280px] md:max-w-none text-zinc-600 dark:text-zinc-400", children: e }),
163
- /* @__PURE__ */ u("div", { className: "flex flex-col w-full gap-3", children: [
164
- a && /* @__PURE__ */ u(
165
- "button",
166
- {
167
- onClick: () => d ? d() : window.location.reload(),
168
- style: p ? { backgroundColor: p, borderColor: p } : {},
169
- className: f(
170
- "flex items-center justify-center gap-2 w-full py-3 px-4 rounded-xl font-medium transition-all shadow-sm",
171
- p ? "text-white hover:opacity-90 hover:scale-[1.02] active:scale-95" : "bg-zinc-900 text-white hover:bg-zinc-800 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white hover:scale-[1.02] active:scale-95"
172
- ),
173
- children: [
174
- /* @__PURE__ */ r(L, { className: "w-4 h-4" }),
175
- c
176
- ]
177
- }
176
+ const b = s === "dark" || typeof s == "object" && s?.backgroundColor === "dark", c = typeof s == "object" ? s.primaryColor : void 0, v = typeof s == "object" ? s.fontFamily : void 0;
177
+ return d ? /* @__PURE__ */ r(g.Root, { open: i, onOpenChange: n, children: /* @__PURE__ */ r(g.Portal, { children: /* @__PURE__ */ u(
178
+ "div",
179
+ {
180
+ className: `cognicatch-ui-wrapper ${b ? "dark" : ""} ${v || ""}`,
181
+ children: [
182
+ /* @__PURE__ */ r(g.Overlay, { className: "radix-overlay fixed inset-0 z-[99999] bg-zinc-900/20 dark:bg-black/80 backdrop-blur-sm" }),
183
+ /* @__PURE__ */ r("div", { className: "fixed inset-0 z-[999999] flex items-end md:items-center justify-center pointer-events-none md:p-4", children: /* @__PURE__ */ u(
184
+ g.Content,
185
+ {
186
+ onInteractOutside: (k) => k.preventDefault(),
187
+ onEscapeKeyDown: (k) => k.preventDefault(),
188
+ className: f(
189
+ "pointer-events-auto w-full flex flex-col items-center text-center shadow-2xl transition-all",
190
+ "bg-white dark:bg-zinc-950",
191
+ "rounded-t-3xl border-t border-zinc-200 dark:border-zinc-800 p-8 pb-10",
192
+ "md:max-w-md md:rounded-2xl md:border md:border-zinc-200 md:dark:border-zinc-800"
178
193
  ),
179
- o && /* @__PURE__ */ u(
180
- "a",
181
- {
182
- href: o,
183
- target: "_blank",
184
- rel: "noopener noreferrer",
185
- className: f(
186
- "flex items-center justify-center gap-2 w-full py-3 px-4 rounded-xl font-medium transition-colors border border-transparent",
187
- "text-zinc-500 hover:text-zinc-900 hover:bg-zinc-100 dark:text-zinc-400 dark:hover:text-zinc-200 dark:hover:bg-zinc-900 dark:hover:border-zinc-800"
194
+ style: { boxSizing: "border-box" },
195
+ children: [
196
+ /* @__PURE__ */ r("div", { className: "mx-auto w-12 h-1.5 rounded-full bg-zinc-200 dark:bg-zinc-800 mb-6 md:hidden" }),
197
+ /* @__PURE__ */ r("div", { className: "w-16 h-16 rounded-full flex items-center justify-center mb-6 border bg-red-50 border-red-100 dark:bg-red-500/10 dark:border-red-500/20", children: /* @__PURE__ */ r(U, { className: "w-8 h-8 text-red-600 dark:text-red-500" }) }),
198
+ /* @__PURE__ */ r(g.Title, { className: "text-xl font-semibold text-zinc-900 dark:text-zinc-50 mb-3 tracking-tight", children: t }),
199
+ /* @__PURE__ */ r(g.Description, { className: "text-sm leading-relaxed mb-8 max-w-[280px] md:max-w-none text-zinc-600 dark:text-zinc-400", children: e }),
200
+ /* @__PURE__ */ u("div", { className: "flex flex-col w-full gap-3", children: [
201
+ a && /* @__PURE__ */ u(
202
+ "button",
203
+ {
204
+ onClick: () => l ? l() : window.location.reload(),
205
+ type: "button",
206
+ style: c ? {
207
+ backgroundColor: c,
208
+ borderColor: c
209
+ } : {},
210
+ className: f(
211
+ "flex items-center justify-center gap-2 w-full py-3 px-4 rounded-xl font-medium transition-all shadow-sm",
212
+ c ? "text-white hover:opacity-90 hover:scale-[1.02] active:scale-95" : "bg-zinc-900 text-white hover:bg-zinc-800 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white hover:scale-[1.02] active:scale-95"
213
+ ),
214
+ children: [
215
+ /* @__PURE__ */ r(B, { className: "w-4 h-4" }),
216
+ m
217
+ ]
218
+ }
188
219
  ),
189
- children: [
190
- "Check system status",
191
- /* @__PURE__ */ r(j, { className: "w-4 h-4 opacity-70" })
192
- ]
193
- }
194
- )
195
- ] })
196
- ]
220
+ o && /* @__PURE__ */ u(
221
+ "a",
222
+ {
223
+ href: o,
224
+ target: "_blank",
225
+ rel: "noopener noreferrer",
226
+ className: f(
227
+ "flex items-center justify-center gap-2 w-full py-3 px-4 rounded-xl font-medium transition-colors border border-transparent",
228
+ "text-zinc-500 hover:text-zinc-900 hover:bg-zinc-100 dark:text-zinc-400 dark:hover:text-zinc-200 dark:hover:bg-zinc-900 dark:hover:border-zinc-800"
229
+ ),
230
+ children: [
231
+ "Check system status",
232
+ /* @__PURE__ */ r(O, { className: "w-4 h-4 opacity-70" })
233
+ ]
234
+ }
235
+ )
236
+ ] })
237
+ ]
238
+ }
239
+ ) })
240
+ ]
241
+ }
242
+ ) }) }) : null;
243
+ }
244
+ const w = M(
245
+ void 0
246
+ );
247
+ function re({
248
+ apiKey: t,
249
+ apiUrl: e,
250
+ language: o,
251
+ handleUserBilling: a = !1,
252
+ children: i
253
+ }) {
254
+ const n = I(
255
+ async (l, m) => {
256
+ const d = l instanceof Error ? l : new Error(String(l)), p = h.loading("Analyzing error context...", {
257
+ description: "Applying AI recovery heuristics..."
258
+ });
259
+ if (t === "sk_test_mock") {
260
+ setTimeout(() => {
261
+ h.info("Mock Mode Analysis", {
262
+ id: p,
263
+ description: "This is a mocked async recovery because sk_test_mock was used."
264
+ });
265
+ }, 1500);
266
+ return;
267
+ }
268
+ try {
269
+ const b = {
270
+ message: d.message,
271
+ componentStack: d.stack,
272
+ url: typeof window < "u" ? window.location.href : void 0
273
+ }, c = R(b), v = e || "https://api.cognicatch.dev/v1/analyze-error", k = typeof navigator < "u" ? navigator.language : "en-US", D = o || k, S = m?.handleUserBilling !== void 0 ? m.handleUserBilling : a, z = await fetch(v, {
274
+ method: "POST",
275
+ headers: {
276
+ Authorization: `Bearer ${t}`,
277
+ "Content-Type": "application/json"
278
+ },
279
+ body: JSON.stringify({
280
+ error: c.message,
281
+ stack: c.componentName ? `Component: ${c.componentName}` : c.errorCode || "Async Error",
282
+ routePath: c.routePath,
283
+ language: D,
284
+ handleUserBilling: S
285
+ })
286
+ });
287
+ if (!z.ok) throw new Error("SaaS API Error");
288
+ const x = await z.json();
289
+ x && ((x.severity || x.level) === "low" ? h.info(x.title, {
290
+ id: p,
291
+ description: x.description
292
+ }) : h.error(x.title, {
293
+ id: p,
294
+ description: x.description
295
+ }));
296
+ } catch (b) {
297
+ console.error("AdaptiveUI API Request failed:", b), h.error("Analysis Failed", {
298
+ id: p,
299
+ description: "We couldn't reach the AI servers. Please try again later."
300
+ });
197
301
  }
198
- ) })
199
- ] }) }) }) : null;
302
+ },
303
+ [t, e, o, a]
304
+ ), s = F(
305
+ () => ({
306
+ apiKey: t,
307
+ apiUrl: e,
308
+ language: o,
309
+ handleUserBilling: a,
310
+ captureAsyncError: n
311
+ }),
312
+ [t, e, o, a, n]
313
+ );
314
+ return /* @__PURE__ */ r(w.Provider, { value: s, children: i });
315
+ }
316
+ function oe() {
317
+ const t = L(w);
318
+ if (!t)
319
+ throw new Error(
320
+ "❌ AdaptiveUI Developer Error: You tried to use the 'useAdaptive' hook outside of an <AdaptiveProvider>. Please wrap the root of your application (e.g., App.tsx or layout.tsx) with <AdaptiveProvider apiKey='YOUR_KEY'>"
321
+ );
322
+ return t;
200
323
  }
201
- function X({
324
+ function ae({
202
325
  customTheme: t,
203
326
  toastOptions: e,
204
327
  position: o = "top-right",
205
328
  ...a
206
329
  }) {
207
330
  return /* @__PURE__ */ r(
208
- $,
331
+ W,
209
332
  {
210
333
  position: o,
211
334
  containerAriaLabel: "Notifications",
@@ -220,8 +343,14 @@ function X({
220
343
  t?.fontFamily,
221
344
  e?.classNames?.toast
222
345
  ),
223
- title: f("font-medium text-sm text-zinc-900 dark:text-zinc-50", e?.classNames?.title),
224
- description: f("mt-0.5 text-xs text-zinc-500 dark:text-zinc-400 line-clamp-2", e?.classNames?.description),
346
+ title: f(
347
+ "font-medium text-sm text-zinc-900 dark:text-zinc-50",
348
+ e?.classNames?.title
349
+ ),
350
+ description: f(
351
+ "mt-0.5 text-xs text-zinc-500 dark:text-zinc-400 line-clamp-2",
352
+ e?.classNames?.description
353
+ ),
225
354
  actionButton: f(
226
355
  "font-medium rounded-lg transition-all px-3 py-1.5 border text-xs",
227
356
  "bg-zinc-900 text-white border-transparent hover:scale-[1.02] active:scale-95",
@@ -240,25 +369,25 @@ function X({
240
369
  }
241
370
  );
242
371
  }
243
- function E(t, e, o, a, s = "medium") {
372
+ function _(t, e, o, a, i = "medium") {
244
373
  return h(t, {
245
374
  description: e,
246
375
  icon: {
247
- low: /* @__PURE__ */ r(O, { className: "w-5 h-5 text-blue-500" }),
376
+ low: /* @__PURE__ */ r(Z, { className: "w-5 h-5 text-blue-500" }),
248
377
  medium: /* @__PURE__ */ r(C, { className: "w-5 h-5 text-amber-500" }),
249
378
  high: /* @__PURE__ */ r(y, { className: "w-5 h-5 text-red-500" })
250
- }[s],
251
- duration: s === "high" ? 8e3 : 5e3,
379
+ }[i],
380
+ duration: i === "high" ? 8e3 : 5e3,
252
381
  action: o ? {
253
382
  label: o,
254
383
  onClick: () => a?.()
255
384
  } : void 0
256
385
  });
257
386
  }
258
- const ee = {
387
+ const ne = {
259
388
  success: (t, e) => h(t, {
260
389
  description: e,
261
- icon: /* @__PURE__ */ r(U, { className: "w-5 h-5 text-emerald-500" })
390
+ icon: /* @__PURE__ */ r($, { className: "w-5 h-5 text-emerald-500" })
262
391
  }),
263
392
  error: (t, e) => h(t, {
264
393
  description: e,
@@ -270,7 +399,7 @@ const ee = {
270
399
  }),
271
400
  loading: (t, e) => h.loading(t, { description: e }),
272
401
  custom: (t, e, o) => {
273
- h.custom((a) => /* @__PURE__ */ r(
402
+ h.custom(() => /* @__PURE__ */ r(
274
403
  "div",
275
404
  {
276
405
  className: f("flex gap-3 p-4 shadow-2xl border", o.fontFamily),
@@ -287,88 +416,51 @@ const ee = {
287
416
  }
288
417
  ));
289
418
  }
290
- }, w = S(void 0);
291
- function te({
292
- apiKey: t,
293
- apiUrl: e,
294
- language: o,
295
- children: a
296
- }) {
297
- const s = P(async (i) => {
298
- const d = i instanceof Error ? i : new Error(String(i)), c = h.loading("Analyzing error context...", {
299
- description: "Applying AI recovery heuristics..."
300
- });
301
- if (t === "sk_test_mock") {
302
- setTimeout(() => {
303
- h.info("Mock Mode Analysis", {
304
- id: c,
305
- description: "This is a mocked async recovery because sk_test_mock was used."
306
- });
307
- }, 1500);
308
- return;
309
- }
310
- try {
311
- const l = {
312
- message: d.message,
313
- componentStack: d.stack,
314
- url: typeof window < "u" ? window.location.href : void 0
315
- }, m = _(l), b = e || "https://api.cognicatch.dev/v1/analyze-error", p = typeof navigator < "u" ? navigator.language : "en-US", v = o || p, g = await fetch(b, {
316
- method: "POST",
317
- headers: {
318
- Authorization: `Bearer ${t}`,
319
- "Content-Type": "application/json"
320
- },
321
- body: JSON.stringify({
322
- error: m.message,
323
- stack: m.componentName ? `Component: ${m.componentName}` : m.errorCode || "Async Error",
324
- routePath: m.routePath,
325
- language: v
326
- })
327
- });
328
- if (!g.ok) throw new Error("SaaS API Error");
329
- const x = await g.json();
330
- x && ((x.severity || x.level) === "low" ? h.info(x.title, { id: c, description: x.description }) : h.error(x.title, { id: c, description: x.description }));
331
- } catch (l) {
332
- console.error("AdaptiveUI API Request failed:", l), h.error("Analysis Failed", {
333
- id: c,
334
- description: "We couldn't reach the AI servers. Please try again later."
335
- });
336
- }
337
- }, [t, e, o]), n = T(() => ({
338
- apiKey: t,
339
- apiUrl: e,
340
- language: o,
341
- captureAsyncError: s
342
- }), [t, e, o, s]);
343
- return /* @__PURE__ */ r(w.Provider, { value: n, children: a });
344
- }
345
- function re() {
346
- const t = M(w);
347
- if (!t)
348
- throw new Error(
349
- "❌ AdaptiveUI Developer Error: You tried to use the 'useAdaptive' hook outside of an <AdaptiveProvider>. Please wrap the root of your application (e.g., App.tsx or layout.tsx) with <AdaptiveProvider apiKey='YOUR_KEY'>"
350
- );
351
- return t;
352
- }
353
- const K = ({ onRecover: t, theme: e }) => /* @__PURE__ */ r("div", { className: `p-6 rounded-xl border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 shadow-sm ${e === "dark" ? "dark" : ""}`, children: /* @__PURE__ */ u("div", { className: "flex flex-col items-center text-center gap-4", children: [
354
- /* @__PURE__ */ r("div", { className: "p-3 rounded-full bg-red-50 dark:bg-red-900/20", children: /* @__PURE__ */ r("svg", { className: "w-6 h-6 text-red-600 dark:text-red-400", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ r("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) }) }),
355
- /* @__PURE__ */ u("div", { children: [
356
- /* @__PURE__ */ r("h3", { className: "text-sm font-semibold text-zinc-900 dark:text-zinc-100", children: "Component Unavailable" }),
357
- /* @__PURE__ */ r("p", { className: "text-xs text-zinc-500 dark:text-zinc-400 mt-1", children: "An unexpected error occurred in the interface." })
358
- ] }),
359
- /* @__PURE__ */ r(
360
- "button",
361
- {
362
- onClick: t,
363
- style: {
364
- backgroundColor: e?.primaryColor || void 0
365
- },
366
- className: "px-4 py-2 text-xs font-medium bg-zinc-900 dark:bg-zinc-100 text-white dark:text-zinc-900 rounded-lg hover:opacity-90 transition-opacity",
367
- children: "Try Reloading"
368
- }
369
- )
370
- ] }) });
371
- class oe extends I {
419
+ }, q = ({ onRecover: t, theme: e }) => /* @__PURE__ */ r(
420
+ "div",
421
+ {
422
+ className: `p-6 rounded-xl border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 shadow-sm ${e === "dark" ? "dark" : ""}`,
423
+ children: /* @__PURE__ */ u("div", { className: "flex flex-col items-center text-center gap-4", children: [
424
+ /* @__PURE__ */ r("div", { className: "p-3 rounded-full bg-red-50 dark:bg-red-900/20", children: /* @__PURE__ */ r(
425
+ "svg",
426
+ {
427
+ className: "w-6 h-6 text-red-600 dark:text-red-400",
428
+ fill: "none",
429
+ viewBox: "0 0 24 24",
430
+ stroke: "currentColor",
431
+ role: "img",
432
+ "aria-label": "error icon",
433
+ children: /* @__PURE__ */ r(
434
+ "path",
435
+ {
436
+ strokeLinecap: "round",
437
+ strokeLinejoin: "round",
438
+ strokeWidth: 2,
439
+ d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
440
+ }
441
+ )
442
+ }
443
+ ) }),
444
+ /* @__PURE__ */ u("div", { children: [
445
+ /* @__PURE__ */ r("h3", { className: "text-sm font-semibold text-zinc-900 dark:text-zinc-100", children: "Component Unavailable" }),
446
+ /* @__PURE__ */ r("p", { className: "text-xs text-zinc-500 dark:text-zinc-400 mt-1", children: "An unexpected error occurred in the interface." })
447
+ ] }),
448
+ /* @__PURE__ */ r(
449
+ "button",
450
+ {
451
+ onClick: t,
452
+ type: "button",
453
+ style: {
454
+ backgroundColor: e?.primaryColor || void 0
455
+ },
456
+ className: "px-4 py-2 text-xs font-medium bg-zinc-900 dark:bg-zinc-100 text-white dark:text-zinc-900 rounded-lg hover:opacity-90 transition-opacity",
457
+ children: "Try Reloading"
458
+ }
459
+ )
460
+ ] })
461
+ }
462
+ );
463
+ class ie extends j {
372
464
  static contextType = w;
373
465
  _isMounted = !1;
374
466
  constructor(e) {
@@ -392,7 +484,7 @@ class oe extends I {
392
484
  componentDidCatch(e, o) {
393
485
  if (this.state.hasCrashedFallback) return;
394
486
  const { mode: a } = this.props;
395
- a === "manual" && this.props.severity === "low" && E(
487
+ a === "manual" && this.props.severity === "low" && _(
396
488
  this.props.title,
397
489
  this.props.description,
398
490
  this.props.actionLabel ?? void 0,
@@ -400,12 +492,14 @@ class oe extends I {
400
492
  ), a === "auto" && this._isMounted && (this.setState({ isProcessingAuto: !0 }), this.processAutoMode(e, o));
401
493
  }
402
494
  processAutoMode = async (e, o) => {
403
- const a = this.props, s = a.apiKey || this.context?.apiKey, n = a.apiUrl || this.context?.apiUrl, i = typeof navigator < "u" ? navigator.language : "en-US", d = a.language || this.context?.language || i;
404
- if (!s) {
405
- console.error("AdaptiveUI: Missing API Key for auto mode. Provide it via props or <AdaptiveProvider>."), this._isMounted && this.setState({ isProcessingAuto: !1 });
495
+ const a = this.props, i = a.apiKey || this.context?.apiKey, n = a.apiUrl || this.context?.apiUrl, s = typeof navigator < "u" ? navigator.language : "en-US", l = a.language || this.context?.language || s;
496
+ if (!i) {
497
+ console.error(
498
+ "AdaptiveUI: Missing API Key for auto mode. Provide it via props or <AdaptiveProvider>."
499
+ ), this._isMounted && this.setState({ isProcessingAuto: !1 });
406
500
  return;
407
501
  }
408
- if (s === "sk_test_mock") {
502
+ if (i === "sk_test_mock") {
409
503
  setTimeout(() => {
410
504
  this._isMounted && this.setState({
411
505
  isProcessingAuto: !1,
@@ -420,34 +514,34 @@ class oe extends I {
420
514
  return;
421
515
  }
422
516
  try {
423
- const c = {
517
+ const m = {
424
518
  message: e.message,
425
519
  componentStack: o.componentStack || void 0,
426
520
  url: typeof window < "u" ? window.location.href : void 0
427
- }, l = _(c), b = await fetch(n || "https://api.cognicatch.dev/v1/analyze-error", {
521
+ }, d = R(m), b = await fetch(n || "https://api.cognicatch.dev/v1/analyze-error", {
428
522
  method: "POST",
429
523
  headers: {
430
- Authorization: `Bearer ${s}`,
524
+ Authorization: `Bearer ${i}`,
431
525
  "Content-Type": "application/json"
432
526
  },
433
527
  body: JSON.stringify({
434
- error: l.message,
435
- stack: l.componentName ? `Component: ${l.componentName}` : "No stack",
436
- routePath: l.routePath,
437
- language: d
528
+ error: d.message,
529
+ stack: d.componentName ? `Component: ${d.componentName}` : "No stack",
530
+ routePath: d.routePath,
531
+ language: l
438
532
  })
439
533
  });
440
534
  if (!b.ok)
441
535
  throw new Error(`SaaS API returned ${b.status}`);
442
- const p = await b.json();
443
- p && this._isMounted && (p.severity === "low" ? (E(
444
- p.title,
445
- p.description,
446
- p.actionLabel ?? void 0,
536
+ const c = await b.json();
537
+ c && this._isMounted && (c.severity === "low" ? (_(
538
+ c.title,
539
+ c.description,
540
+ c.actionLabel ?? void 0,
447
541
  this.handleRecover
448
- ), this.setState({ isProcessingAuto: !1, aiData: p })) : this.setState({ isProcessingAuto: !1, aiData: p }));
449
- } catch (c) {
450
- console.error("AdaptiveUI AI Request failed:", c), this._isMounted && this.setState({
542
+ ), this.setState({ isProcessingAuto: !1, aiData: c })) : this.setState({ isProcessingAuto: !1, aiData: c }));
543
+ } catch (m) {
544
+ console.error("AdaptiveUI AI Request failed:", m), this._isMounted && this.setState({
451
545
  isProcessingAuto: !1,
452
546
  aiData: {
453
547
  severity: "medium",
@@ -459,12 +553,17 @@ class oe extends I {
459
553
  }
460
554
  };
461
555
  handleRecover = () => {
462
- this._isMounted && this.setState({ hasError: !1, error: null, aiData: null, hasCrashedFallback: !1 }), this.props.onRecover && this.props.onRecover();
556
+ this._isMounted && this.setState({
557
+ hasError: !1,
558
+ error: null,
559
+ aiData: null,
560
+ hasCrashedFallback: !1
561
+ }), this.props.onRecover && this.props.onRecover();
463
562
  };
464
563
  render() {
465
564
  if (this.state.hasCrashedFallback)
466
565
  return /* @__PURE__ */ r(
467
- K,
566
+ q,
468
567
  {
469
568
  onRecover: this.handleRecover,
470
569
  theme: this.props.theme
@@ -472,27 +571,37 @@ class oe extends I {
472
571
  );
473
572
  if (!this.state.hasError)
474
573
  return this.props.children;
475
- const { mode: e, theme: o, className: a, showRefresh: s, statusUrl: n } = this.props;
574
+ const { mode: e, theme: o, className: a, showRefresh: i, statusUrl: n } = this.props;
476
575
  if (e === "manual") {
477
- const { severity: i, title: d, description: c, actionLabel: l } = this.props;
576
+ const { severity: s, title: l, description: m, actionLabel: d } = this.props;
478
577
  try {
479
- if (i === "high")
578
+ if (s === "high")
480
579
  return /* @__PURE__ */ r(
481
- N,
580
+ E,
482
581
  {
483
582
  isOpen: !0,
484
- onOpenChange: (m) => {
485
- m || this.handleRecover();
583
+ onOpenChange: (p) => {
584
+ p || this.handleRecover();
486
585
  },
487
- title: d,
488
- description: c,
586
+ title: l,
587
+ description: m,
489
588
  theme: o,
490
- showRefresh: s,
589
+ showRefresh: i,
491
590
  statusUrl: n
492
591
  }
493
592
  );
494
- if (i === "medium") return /* @__PURE__ */ r(A, { title: d, description: c, primaryAction: l ? { label: l, onClick: this.handleRecover } : void 0, theme: o, className: a });
495
- if (i === "low") return null;
593
+ if (s === "medium")
594
+ return /* @__PURE__ */ r(
595
+ N,
596
+ {
597
+ title: l,
598
+ description: m,
599
+ primaryAction: d ? { label: d, onClick: this.handleRecover } : void 0,
600
+ theme: o,
601
+ className: a
602
+ }
603
+ );
604
+ if (s === "low") return null;
496
605
  } catch {
497
606
  return this.setState({ hasCrashedFallback: !0 }), null;
498
607
  }
@@ -504,26 +613,35 @@ class oe extends I {
504
613
  /* @__PURE__ */ r("p", { className: "text-xs font-medium text-zinc-500 dark:text-zinc-400", children: "Analyzing error context..." })
505
614
  ] });
506
615
  if (this.state.aiData) {
507
- const { severity: i, title: d, description: c, actionLabel: l } = this.state.aiData;
616
+ const { severity: s, title: l, description: m, actionLabel: d } = this.state.aiData;
508
617
  try {
509
- if (i === "high")
618
+ if (s === "high")
510
619
  return /* @__PURE__ */ r(
511
- N,
620
+ E,
512
621
  {
513
622
  isOpen: !0,
514
- onOpenChange: (m) => {
515
- m || this.handleRecover();
623
+ onOpenChange: (p) => {
624
+ p || this.handleRecover();
516
625
  },
517
- title: d,
518
- description: c,
626
+ title: l,
627
+ description: m,
519
628
  theme: o,
520
- showRefresh: s,
629
+ showRefresh: i,
521
630
  statusUrl: n
522
631
  }
523
632
  );
524
- if (i === "medium")
525
- return /* @__PURE__ */ r(A, { title: d, description: c, primaryAction: l ? { label: l, onClick: this.handleRecover } : void 0, theme: o, className: a });
526
- if (i === "low")
633
+ if (s === "medium")
634
+ return /* @__PURE__ */ r(
635
+ N,
636
+ {
637
+ title: l,
638
+ description: m,
639
+ primaryAction: d ? { label: d, onClick: this.handleRecover } : void 0,
640
+ theme: o,
641
+ className: a
642
+ }
643
+ );
644
+ if (s === "low")
527
645
  return null;
528
646
  } catch {
529
647
  return this.setState({ hasCrashedFallback: !0 }), null;
@@ -534,9 +652,9 @@ class oe extends I {
534
652
  }
535
653
  }
536
654
  export {
537
- oe as AdaptiveErrorBoundary,
538
- te as AdaptiveProvider,
539
- X as AdaptiveToastProvider,
540
- ee as adaptiveToast,
541
- re as useAdaptive
655
+ ie as AdaptiveErrorBoundary,
656
+ re as AdaptiveProvider,
657
+ ae as AdaptiveToastProvider,
658
+ ne as adaptiveToast,
659
+ oe as useAdaptive
542
660
  };