@duvandroid/react-blind-agents 0.1.0 → 0.2.0

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.d.mts CHANGED
@@ -1,30 +1,70 @@
1
- interface BlindAgentsWidgetProps {
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ /** Common props shared by all widget types. */
4
+ interface BaseWidgetProps {
2
5
  /** Your Blind Agents public API key (ba_...) */
3
6
  apiKey: string;
7
+ /** Pre-filled WhatsApp number to skip identity verification */
8
+ userWhatsapp?: string;
9
+ /** Override the CDN base URL (useful for self-hosting) */
10
+ cdnBase?: string;
11
+ /** Script loading strategy @default "afterInteractive" */
12
+ strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';
13
+ /** Called once the script finishes loading */
14
+ onLoad?: () => void;
15
+ /** Called if the script fails to load */
16
+ onError?: (error: Error) => void;
17
+ }
18
+ /** Report / bug-reporter widget */
19
+ interface ReportWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
4
20
  /** Accent color for the widget UI — any valid CSS color */
5
21
  primaryColor?: string;
6
22
  /** Title displayed in the widget panel header @default "Help Center" */
7
23
  title?: string;
8
24
  /** Label for the report button @default "Report an issue" */
9
25
  reportBtnText?: string;
10
- /** Emoji on the launcher floating button */
26
+ /** Emoji on the launcher floating button @default "🐛" */
11
27
  btnEmoji?: string;
12
28
  /** Tooltip on the launcher button */
13
29
  btnTooltip?: string;
14
30
  /** Text shown when there are no reports @default "No issues reported yet." */
15
31
  emptyText?: string;
16
- /** Pre-fill the user's WhatsApp number or email to skip identity verification */
17
- userWhatsapp?: string;
18
- /** Script loading strategy @default "afterInteractive" */
19
- strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';
20
- /** Override the CDN URL (useful for self-hosting) @default "https://cdn.blindagents.com/report.js" */
32
+ }
33
+ /** Webchat widget */
34
+ interface ChatWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
35
+ /** The agent UUID to connect this chat to */
36
+ agentId?: string;
37
+ /** Accent color for the chat bubble and header */
38
+ primaryColor?: string;
39
+ }
40
+ /** Product guides widget */
41
+ interface GuideWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
42
+ }
43
+ /** Root provider props — all children share this apiKey */
44
+ interface BlindAgentsProps extends BaseWidgetProps {
45
+ children: React.ReactNode;
46
+ }
47
+ /** @deprecated Use <BlindAgents apiKey="..."><BlindAgents.Report /></BlindAgents> instead */
48
+ interface BlindAgentsWidgetProps extends BaseWidgetProps {
49
+ primaryColor?: string;
50
+ title?: string;
51
+ reportBtnText?: string;
52
+ btnEmoji?: string;
53
+ btnTooltip?: string;
54
+ emptyText?: string;
55
+ /** @deprecated Prefer userWhatsapp */
21
56
  src?: string;
22
- /** Called once the script finishes loading */
23
- onLoad?: () => void;
24
- /** Called if the script fails to load */
25
- onError?: (error: Error) => void;
26
57
  }
27
58
 
28
- declare function BlindAgentsWidget({ apiKey, primaryColor, title, reportBtnText, btnEmoji, btnTooltip, emptyText, userWhatsapp, strategy, src, onLoad, onError, }: BlindAgentsWidgetProps): null;
59
+ declare function BlindAgents({ apiKey, userWhatsapp, cdnBase, strategy, children, }: BlindAgentsProps): react_jsx_runtime.JSX.Element;
60
+ declare namespace BlindAgents {
61
+ var Report: ({ primaryColor, title, reportBtnText, btnEmoji, btnTooltip, emptyText, userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: ReportWidgetProps) => null;
62
+ var Chat: ({ agentId, primaryColor, userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: ChatWidgetProps) => null;
63
+ var Guide: ({ userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: GuideWidgetProps) => null;
64
+ }
65
+ /** @deprecated Use <BlindAgents><BlindAgents.Report /></BlindAgents> */
66
+ declare function BlindAgentsWidget(props: ReportWidgetProps & {
67
+ apiKey: string;
68
+ }): react_jsx_runtime.JSX.Element;
29
69
 
30
- export { BlindAgentsWidget, type BlindAgentsWidgetProps };
70
+ export { BlindAgents, type BlindAgentsProps, BlindAgentsWidget, type BlindAgentsWidgetProps, type ChatWidgetProps, type GuideWidgetProps, type ReportWidgetProps };
package/dist/index.d.ts CHANGED
@@ -1,30 +1,70 @@
1
- interface BlindAgentsWidgetProps {
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ /** Common props shared by all widget types. */
4
+ interface BaseWidgetProps {
2
5
  /** Your Blind Agents public API key (ba_...) */
3
6
  apiKey: string;
7
+ /** Pre-filled WhatsApp number to skip identity verification */
8
+ userWhatsapp?: string;
9
+ /** Override the CDN base URL (useful for self-hosting) */
10
+ cdnBase?: string;
11
+ /** Script loading strategy @default "afterInteractive" */
12
+ strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';
13
+ /** Called once the script finishes loading */
14
+ onLoad?: () => void;
15
+ /** Called if the script fails to load */
16
+ onError?: (error: Error) => void;
17
+ }
18
+ /** Report / bug-reporter widget */
19
+ interface ReportWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
4
20
  /** Accent color for the widget UI — any valid CSS color */
5
21
  primaryColor?: string;
6
22
  /** Title displayed in the widget panel header @default "Help Center" */
7
23
  title?: string;
8
24
  /** Label for the report button @default "Report an issue" */
9
25
  reportBtnText?: string;
10
- /** Emoji on the launcher floating button */
26
+ /** Emoji on the launcher floating button @default "🐛" */
11
27
  btnEmoji?: string;
12
28
  /** Tooltip on the launcher button */
13
29
  btnTooltip?: string;
14
30
  /** Text shown when there are no reports @default "No issues reported yet." */
15
31
  emptyText?: string;
16
- /** Pre-fill the user's WhatsApp number or email to skip identity verification */
17
- userWhatsapp?: string;
18
- /** Script loading strategy @default "afterInteractive" */
19
- strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';
20
- /** Override the CDN URL (useful for self-hosting) @default "https://cdn.blindagents.com/report.js" */
32
+ }
33
+ /** Webchat widget */
34
+ interface ChatWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
35
+ /** The agent UUID to connect this chat to */
36
+ agentId?: string;
37
+ /** Accent color for the chat bubble and header */
38
+ primaryColor?: string;
39
+ }
40
+ /** Product guides widget */
41
+ interface GuideWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
42
+ }
43
+ /** Root provider props — all children share this apiKey */
44
+ interface BlindAgentsProps extends BaseWidgetProps {
45
+ children: React.ReactNode;
46
+ }
47
+ /** @deprecated Use <BlindAgents apiKey="..."><BlindAgents.Report /></BlindAgents> instead */
48
+ interface BlindAgentsWidgetProps extends BaseWidgetProps {
49
+ primaryColor?: string;
50
+ title?: string;
51
+ reportBtnText?: string;
52
+ btnEmoji?: string;
53
+ btnTooltip?: string;
54
+ emptyText?: string;
55
+ /** @deprecated Prefer userWhatsapp */
21
56
  src?: string;
22
- /** Called once the script finishes loading */
23
- onLoad?: () => void;
24
- /** Called if the script fails to load */
25
- onError?: (error: Error) => void;
26
57
  }
27
58
 
28
- declare function BlindAgentsWidget({ apiKey, primaryColor, title, reportBtnText, btnEmoji, btnTooltip, emptyText, userWhatsapp, strategy, src, onLoad, onError, }: BlindAgentsWidgetProps): null;
59
+ declare function BlindAgents({ apiKey, userWhatsapp, cdnBase, strategy, children, }: BlindAgentsProps): react_jsx_runtime.JSX.Element;
60
+ declare namespace BlindAgents {
61
+ var Report: ({ primaryColor, title, reportBtnText, btnEmoji, btnTooltip, emptyText, userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: ReportWidgetProps) => null;
62
+ var Chat: ({ agentId, primaryColor, userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: ChatWidgetProps) => null;
63
+ var Guide: ({ userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: GuideWidgetProps) => null;
64
+ }
65
+ /** @deprecated Use <BlindAgents><BlindAgents.Report /></BlindAgents> */
66
+ declare function BlindAgentsWidget(props: ReportWidgetProps & {
67
+ apiKey: string;
68
+ }): react_jsx_runtime.JSX.Element;
29
69
 
30
- export { BlindAgentsWidget, type BlindAgentsWidgetProps };
70
+ export { BlindAgents, type BlindAgentsProps, BlindAgentsWidget, type BlindAgentsWidgetProps, type ChatWidgetProps, type GuideWidgetProps, type ReportWidgetProps };
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,51 +17,54 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
21
31
  var src_exports = {};
22
32
  __export(src_exports, {
33
+ BlindAgents: () => BlindAgents,
23
34
  BlindAgentsWidget: () => BlindAgentsWidget
24
35
  });
25
36
  module.exports = __toCommonJS(src_exports);
26
37
 
27
- // src/ReactBlindAgentsWidget.tsx
38
+ // src/ReactBlindAgents.tsx
39
+ var import_react2 = __toESM(require("react"));
40
+
41
+ // src/context.ts
28
42
  var import_react = require("react");
29
- var CDN_DEFAULT = "https://cdn.blindagents.com/report.js";
30
- function BlindAgentsWidget({
31
- apiKey,
32
- primaryColor,
33
- title,
34
- reportBtnText,
35
- btnEmoji,
36
- btnTooltip,
37
- emptyText,
38
- userWhatsapp,
39
- strategy = "afterInteractive",
40
- src = CDN_DEFAULT,
41
- onLoad,
42
- onError
43
- }) {
44
- const injected = (0, import_react.useRef)(false);
45
- (0, import_react.useEffect)(() => {
43
+
44
+ // src/types.ts
45
+ var CDN_BASE = "https://cdn.blindagents.com";
46
+
47
+ // src/context.ts
48
+ var BlindAgentsContext = (0, import_react.createContext)({
49
+ apiKey: "",
50
+ cdnBase: CDN_BASE,
51
+ strategy: "afterInteractive"
52
+ });
53
+
54
+ // src/ReactBlindAgents.tsx
55
+ var import_jsx_runtime = require("react/jsx-runtime");
56
+ function useScript(src, attrs, strategy, onLoad, onError) {
57
+ const injected = (0, import_react2.useRef)(false);
58
+ (0, import_react2.useEffect)(() => {
46
59
  if (injected.current) return;
47
60
  injected.current = true;
48
- const existing = document.querySelector(
49
- `script[src="${src}"][data-ba-managed]`
50
- );
51
- if (existing) return;
61
+ if (document.querySelector(`script[src="${src}"][data-ba-managed]`)) return;
52
62
  const el = document.createElement("script");
53
63
  el.src = src;
54
64
  el.setAttribute("data-ba-managed", "true");
55
- el.setAttribute("data-api-key", apiKey);
56
- if (primaryColor) el.setAttribute("data-primary-color", primaryColor);
57
- if (title) el.setAttribute("data-title", title);
58
- if (reportBtnText) el.setAttribute("data-report-btn-text", reportBtnText);
59
- if (btnEmoji) el.setAttribute("data-btn-emoji", btnEmoji);
60
- if (btnTooltip) el.setAttribute("data-btn-tooltip", btnTooltip);
61
- if (emptyText) el.setAttribute("data-empty-text", emptyText);
62
- if (userWhatsapp) el.setAttribute("data-user-whatsapp", userWhatsapp);
65
+ Object.entries(attrs).forEach(([k, v]) => {
66
+ if (v != null && v !== "") el.setAttribute(k, v);
67
+ });
63
68
  if (onLoad) el.addEventListener("load", () => onLoad());
64
69
  if (onError) el.addEventListener("error", () => onError(new Error(`Failed to load ${src}`)));
65
70
  const inject = () => {
@@ -67,7 +72,7 @@ function BlindAgentsWidget({
67
72
  if (strategy === "lazyOnload") el.async = true;
68
73
  document.head.appendChild(el);
69
74
  };
70
- if (strategy === "lazyOnload" && typeof window !== "undefined" && "requestIdleCallback" in window) {
75
+ if (strategy === "lazyOnload" && "requestIdleCallback" in window) {
71
76
  window.requestIdleCallback(inject);
72
77
  } else {
73
78
  inject();
@@ -76,11 +81,90 @@ function BlindAgentsWidget({
76
81
  el.parentNode?.removeChild(el);
77
82
  injected.current = false;
78
83
  };
79
- }, [apiKey, src]);
84
+ }, [src]);
85
+ }
86
+ function Report({
87
+ primaryColor,
88
+ title,
89
+ reportBtnText,
90
+ btnEmoji,
91
+ btnTooltip,
92
+ emptyText,
93
+ userWhatsapp: localWhatsapp,
94
+ cdnBase: localCdn,
95
+ strategy: localStrategy,
96
+ onLoad,
97
+ onError
98
+ }) {
99
+ const ctx = import_react2.default.useContext(BlindAgentsContext);
100
+ const src = `${localCdn ?? ctx.cdnBase}/report.js`;
101
+ const wa = localWhatsapp ?? ctx.userWhatsapp;
102
+ useScript(src, {
103
+ "data-api-key": ctx.apiKey,
104
+ "data-primary-color": primaryColor,
105
+ "data-title": title,
106
+ "data-report-btn-text": reportBtnText,
107
+ "data-btn-emoji": btnEmoji,
108
+ "data-btn-tooltip": btnTooltip,
109
+ "data-empty-text": emptyText,
110
+ "data-user-whatsapp": wa
111
+ }, localStrategy ?? ctx.strategy, onLoad, onError);
112
+ return null;
113
+ }
114
+ function Chat({
115
+ agentId,
116
+ primaryColor,
117
+ userWhatsapp: localWhatsapp,
118
+ cdnBase: localCdn,
119
+ strategy: localStrategy,
120
+ onLoad,
121
+ onError
122
+ }) {
123
+ const ctx = import_react2.default.useContext(BlindAgentsContext);
124
+ const src = `${localCdn ?? ctx.cdnBase}/chat.js`;
125
+ const wa = localWhatsapp ?? ctx.userWhatsapp;
126
+ useScript(src, {
127
+ "data-api-key": ctx.apiKey,
128
+ "data-agent-id": agentId,
129
+ "data-primary-color": primaryColor,
130
+ "data-user-whatsapp": wa
131
+ }, localStrategy ?? ctx.strategy, onLoad, onError);
80
132
  return null;
81
133
  }
134
+ function Guide({
135
+ userWhatsapp: localWhatsapp,
136
+ cdnBase: localCdn,
137
+ strategy: localStrategy,
138
+ onLoad,
139
+ onError
140
+ }) {
141
+ const ctx = import_react2.default.useContext(BlindAgentsContext);
142
+ const src = `${localCdn ?? ctx.cdnBase}/guide.js`;
143
+ const wa = localWhatsapp ?? ctx.userWhatsapp;
144
+ useScript(src, {
145
+ "data-api-key": ctx.apiKey,
146
+ "data-user-whatsapp": wa
147
+ }, localStrategy ?? ctx.strategy, onLoad, onError);
148
+ return null;
149
+ }
150
+ function BlindAgents({
151
+ apiKey,
152
+ userWhatsapp,
153
+ cdnBase = CDN_BASE,
154
+ strategy = "afterInteractive",
155
+ children
156
+ }) {
157
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlindAgentsContext.Provider, { value: { apiKey, userWhatsapp, cdnBase, strategy }, children });
158
+ }
159
+ BlindAgents.Report = Report;
160
+ BlindAgents.Chat = Chat;
161
+ BlindAgents.Guide = Guide;
162
+ function BlindAgentsWidget(props) {
163
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlindAgents, { apiKey: props.apiKey, userWhatsapp: props.userWhatsapp, strategy: props.strategy, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Report, { ...props }) });
164
+ }
82
165
  // Annotate the CommonJS export names for ESM import in node:
83
166
  0 && (module.exports = {
167
+ BlindAgents,
84
168
  BlindAgentsWidget
85
169
  });
86
170
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/ReactBlindAgentsWidget.tsx"],"sourcesContent":["// Plain React entry — Vite, CRA, etc.\n// For Next.js use: import { BlindAgentsWidget } from 'react-blind-agents/next'\nexport { BlindAgentsWidget } from './ReactBlindAgentsWidget';\nexport type { BlindAgentsWidgetProps } from './types';\n","'use client';\n\nimport { useEffect, useRef } from 'react';\nimport type { BlindAgentsWidgetProps } from './types';\n\nconst CDN_DEFAULT = 'https://cdn.blindagents.com/report.js';\n\nexport function BlindAgentsWidget({\n apiKey,\n primaryColor,\n title,\n reportBtnText,\n btnEmoji,\n btnTooltip,\n emptyText,\n userWhatsapp,\n strategy = 'afterInteractive',\n src = CDN_DEFAULT,\n onLoad,\n onError,\n}: BlindAgentsWidgetProps) {\n const injected = useRef(false);\n\n useEffect(() => {\n if (injected.current) return;\n injected.current = true;\n\n // Deduplicate across multiple widget instances\n const existing = document.querySelector<HTMLScriptElement>(\n `script[src=\"${src}\"][data-ba-managed]`\n );\n if (existing) return;\n\n const el = document.createElement('script');\n el.src = src;\n el.setAttribute('data-ba-managed', 'true');\n el.setAttribute('data-api-key', apiKey);\n if (primaryColor) el.setAttribute('data-primary-color', primaryColor);\n if (title) el.setAttribute('data-title', title);\n if (reportBtnText) el.setAttribute('data-report-btn-text', reportBtnText);\n if (btnEmoji) el.setAttribute('data-btn-emoji', btnEmoji);\n if (btnTooltip) el.setAttribute('data-btn-tooltip', btnTooltip);\n if (emptyText) el.setAttribute('data-empty-text', emptyText);\n if (userWhatsapp) el.setAttribute('data-user-whatsapp', userWhatsapp);\n\n if (onLoad) el.addEventListener('load', () => onLoad());\n if (onError) el.addEventListener('error', () => onError(new Error(`Failed to load ${src}`)));\n\n const inject = () => {\n if (strategy === 'afterInteractive') el.defer = true;\n if (strategy === 'lazyOnload') el.async = true;\n document.head.appendChild(el);\n };\n\n if (strategy === 'lazyOnload' && typeof window !== 'undefined' && 'requestIdleCallback' in window) {\n (window as Window & { requestIdleCallback: (cb: () => void) => void }).requestIdleCallback(inject);\n } else {\n inject();\n }\n\n return () => {\n el.parentNode?.removeChild(el);\n injected.current = false;\n };\n }, [apiKey, src]); // eslint-disable-line react-hooks/exhaustive-deps\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA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AA,IACnG,OAAO;AACL,aAAO;AAAA,IACT;AAEA,WAAO,MAAM;AACX,SAAG,YAAY,YAAY,EAAE;AAC7B,eAAS,UAAU;AAAA,IACrB;AAAA,EACF,GAAG,CAAC,QAAQ,GAAG,CAAC;AAEhB,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/ReactBlindAgents.tsx","../src/context.ts","../src/types.ts"],"sourcesContent":["// Plain React entry — Vite, CRA, Remix, etc.\n// For Next.js use: import { BlindAgents } from '@duvandroid/react-blind-agents/next'\nexport { BlindAgents, BlindAgentsWidget } from './ReactBlindAgents';\nexport type {\n BlindAgentsProps,\n ReportWidgetProps,\n ChatWidgetProps,\n GuideWidgetProps,\n BlindAgentsWidgetProps,\n} from './types';\n","'use client';\n\nimport React, { useEffect, useRef } from 'react';\nimport { BlindAgentsContext } from './context';\nimport type {\n BlindAgentsProps,\n ReportWidgetProps,\n ChatWidgetProps,\n GuideWidgetProps,\n} from './types';\nimport { CDN_BASE } from './types';\n\n// ── Script injection helper ───────────────────────────────────────────────────\n\nfunction useScript(\n src: string,\n attrs: Record<string, string | undefined>,\n strategy: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive',\n onLoad?: () => void,\n onError?: (e: Error) => void,\n) {\n const injected = useRef(false);\n\n useEffect(() => {\n if (injected.current) return;\n injected.current = true;\n\n // Deduplicate — only one script per src\n if (document.querySelector(`script[src=\"${src}\"][data-ba-managed]`)) return;\n\n const el = document.createElement('script');\n el.src = src;\n el.setAttribute('data-ba-managed', 'true');\n Object.entries(attrs).forEach(([k, v]) => {\n if (v != null && v !== '') el.setAttribute(k, v);\n });\n\n if (onLoad) el.addEventListener('load', () => onLoad());\n if (onError) el.addEventListener('error', () => onError(new Error(`Failed to load ${src}`)));\n\n const inject = () => {\n if (strategy === 'afterInteractive') el.defer = true;\n if (strategy === 'lazyOnload') el.async = true;\n document.head.appendChild(el);\n };\n\n if (strategy === 'lazyOnload' && 'requestIdleCallback' in window) {\n (window as any).requestIdleCallback(inject);\n } else {\n inject();\n }\n\n return () => { el.parentNode?.removeChild(el); injected.current = false; };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [src]);\n}\n\n// ── Widget sub-components ─────────────────────────────────────────────────────\n\nfunction Report({\n primaryColor,\n title,\n reportBtnText,\n btnEmoji,\n btnTooltip,\n emptyText,\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: ReportWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/report.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp;\n\n useScript(src, {\n 'data-api-key': ctx.apiKey,\n 'data-primary-color': primaryColor,\n 'data-title': title,\n 'data-report-btn-text': reportBtnText,\n 'data-btn-emoji': btnEmoji,\n 'data-btn-tooltip': btnTooltip,\n 'data-empty-text': emptyText,\n 'data-user-whatsapp': wa,\n }, localStrategy ?? ctx.strategy, onLoad, onError);\n\n return null;\n}\n\nfunction Chat({\n agentId,\n primaryColor,\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: ChatWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/chat.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp;\n\n useScript(src, {\n 'data-api-key': ctx.apiKey,\n 'data-agent-id': agentId,\n 'data-primary-color': primaryColor,\n 'data-user-whatsapp': wa,\n }, localStrategy ?? ctx.strategy, onLoad, onError);\n\n return null;\n}\n\nfunction Guide({\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: GuideWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/guide.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp;\n\n useScript(src, {\n 'data-api-key': ctx.apiKey,\n 'data-user-whatsapp': wa,\n }, localStrategy ?? ctx.strategy, onLoad, onError);\n\n return null;\n}\n\n// ── Root provider ─────────────────────────────────────────────────────────────\n\nexport function BlindAgents({\n apiKey,\n userWhatsapp,\n cdnBase = CDN_BASE,\n strategy = 'afterInteractive',\n children,\n}: BlindAgentsProps) {\n return (\n <BlindAgentsContext.Provider value={{ apiKey, userWhatsapp, cdnBase, strategy }}>\n {children}\n </BlindAgentsContext.Provider>\n );\n}\n\nBlindAgents.Report = Report;\nBlindAgents.Chat = Chat;\nBlindAgents.Guide = Guide;\n\n// ── Legacy single-widget export (backwards compat) ───────────────────────────\n/** @deprecated Use <BlindAgents><BlindAgents.Report /></BlindAgents> */\nexport function BlindAgentsWidget(props: ReportWidgetProps & { apiKey: string }) {\n return (\n <BlindAgents apiKey={props.apiKey} userWhatsapp={props.userWhatsapp} strategy={props.strategy}>\n <Report {...props} />\n </BlindAgents>\n );\n}\n","import { createContext, useContext } from 'react';\nimport { CDN_BASE } from './types';\n\nexport interface BlindAgentsContextValue {\n apiKey: string;\n userWhatsapp?: string;\n cdnBase: string;\n strategy: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';\n}\n\nexport const BlindAgentsContext = createContext<BlindAgentsContextValue>({\n apiKey: '',\n cdnBase: CDN_BASE,\n strategy: 'afterInteractive',\n});\n\nexport function useBlindAgents(): BlindAgentsContextValue {\n return useContext(BlindAgentsContext);\n}\n","const CDN_BASE = 'https://cdn.blindagents.com';\n\nexport { CDN_BASE };\n\n/** Common props shared by all widget types. */\nexport interface BaseWidgetProps {\n /** Your Blind Agents public API key (ba_...) */\n apiKey: string;\n /** Pre-filled WhatsApp number to skip identity verification */\n userWhatsapp?: string;\n /** Override the CDN base URL (useful for self-hosting) */\n cdnBase?: string;\n /** Script loading strategy @default \"afterInteractive\" */\n strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';\n /** Called once the script finishes loading */\n onLoad?: () => void;\n /** Called if the script fails to load */\n onError?: (error: Error) => void;\n}\n\n/** Report / bug-reporter widget */\nexport interface ReportWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n /** Accent color for the widget UI — any valid CSS color */\n primaryColor?: string;\n /** Title displayed in the widget panel header @default \"Help Center\" */\n title?: string;\n /** Label for the report button @default \"Report an issue\" */\n reportBtnText?: string;\n /** Emoji on the launcher floating button @default \"🐛\" */\n btnEmoji?: string;\n /** Tooltip on the launcher button */\n btnTooltip?: string;\n /** Text shown when there are no reports @default \"No issues reported yet.\" */\n emptyText?: string;\n}\n\n/** Webchat widget */\nexport interface ChatWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n /** The agent UUID to connect this chat to */\n agentId?: string;\n /** Accent color for the chat bubble and header */\n primaryColor?: string;\n}\n\n/** Product guides widget */\nexport interface GuideWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n // No additional props yet — the guide SDK reads config from the dashboard\n}\n\n/** Root provider props — all children share this apiKey */\nexport interface BlindAgentsProps extends BaseWidgetProps {\n children: React.ReactNode;\n}\n\n// ── Legacy single-widget props (kept for backwards compatibility) ──────────────\n/** @deprecated Use <BlindAgents apiKey=\"...\"><BlindAgents.Report /></BlindAgents> instead */\nexport interface BlindAgentsWidgetProps extends BaseWidgetProps {\n primaryColor?: string;\n title?: string;\n reportBtnText?: string;\n btnEmoji?: string;\n btnTooltip?: string;\n emptyText?: string;\n /** @deprecated Prefer userWhatsapp */\n src?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAAA,gBAAyC;;;ACFzC,mBAA0C;;;ACA1C,IAAM,WAAW;;;ADUV,IAAM,yBAAqB,4BAAuC;AAAA,EACvE,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AACZ,CAAC;;;ADgIG;AAhIJ,SAAS,UACP,KACA,OACA,UACA,QACA,SACA;AACA,QAAM,eAAW,sBAAO,KAAK;AAE7B,+BAAU,MAAM;AACd,QAAI,SAAS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,4CAAC,eAAY,QAAQ,MAAM,QAAQ,cAAc,MAAM,cAAc,UAAU,MAAM,UACnF,sDAAC,UAAQ,GAAG,OAAO,GACrB;AAEJ;","names":["import_react","React"]}
package/dist/index.mjs CHANGED
@@ -1,39 +1,33 @@
1
- // src/ReactBlindAgentsWidget.tsx
2
- import { useEffect, useRef } from "react";
3
- var CDN_DEFAULT = "https://cdn.blindagents.com/report.js";
4
- function BlindAgentsWidget({
5
- apiKey,
6
- primaryColor,
7
- title,
8
- reportBtnText,
9
- btnEmoji,
10
- btnTooltip,
11
- emptyText,
12
- userWhatsapp,
13
- strategy = "afterInteractive",
14
- src = CDN_DEFAULT,
15
- onLoad,
16
- onError
17
- }) {
1
+ // src/ReactBlindAgents.tsx
2
+ import React, { useEffect, useRef } from "react";
3
+
4
+ // src/context.ts
5
+ import { createContext, useContext } from "react";
6
+
7
+ // src/types.ts
8
+ var CDN_BASE = "https://cdn.blindagents.com";
9
+
10
+ // src/context.ts
11
+ var BlindAgentsContext = createContext({
12
+ apiKey: "",
13
+ cdnBase: CDN_BASE,
14
+ strategy: "afterInteractive"
15
+ });
16
+
17
+ // src/ReactBlindAgents.tsx
18
+ import { jsx } from "react/jsx-runtime";
19
+ function useScript(src, attrs, strategy, onLoad, onError) {
18
20
  const injected = useRef(false);
19
21
  useEffect(() => {
20
22
  if (injected.current) return;
21
23
  injected.current = true;
22
- const existing = document.querySelector(
23
- `script[src="${src}"][data-ba-managed]`
24
- );
25
- if (existing) return;
24
+ if (document.querySelector(`script[src="${src}"][data-ba-managed]`)) return;
26
25
  const el = document.createElement("script");
27
26
  el.src = src;
28
27
  el.setAttribute("data-ba-managed", "true");
29
- el.setAttribute("data-api-key", apiKey);
30
- if (primaryColor) el.setAttribute("data-primary-color", primaryColor);
31
- if (title) el.setAttribute("data-title", title);
32
- if (reportBtnText) el.setAttribute("data-report-btn-text", reportBtnText);
33
- if (btnEmoji) el.setAttribute("data-btn-emoji", btnEmoji);
34
- if (btnTooltip) el.setAttribute("data-btn-tooltip", btnTooltip);
35
- if (emptyText) el.setAttribute("data-empty-text", emptyText);
36
- if (userWhatsapp) el.setAttribute("data-user-whatsapp", userWhatsapp);
28
+ Object.entries(attrs).forEach(([k, v]) => {
29
+ if (v != null && v !== "") el.setAttribute(k, v);
30
+ });
37
31
  if (onLoad) el.addEventListener("load", () => onLoad());
38
32
  if (onError) el.addEventListener("error", () => onError(new Error(`Failed to load ${src}`)));
39
33
  const inject = () => {
@@ -41,7 +35,7 @@ function BlindAgentsWidget({
41
35
  if (strategy === "lazyOnload") el.async = true;
42
36
  document.head.appendChild(el);
43
37
  };
44
- if (strategy === "lazyOnload" && typeof window !== "undefined" && "requestIdleCallback" in window) {
38
+ if (strategy === "lazyOnload" && "requestIdleCallback" in window) {
45
39
  window.requestIdleCallback(inject);
46
40
  } else {
47
41
  inject();
@@ -50,10 +44,89 @@ function BlindAgentsWidget({
50
44
  el.parentNode?.removeChild(el);
51
45
  injected.current = false;
52
46
  };
53
- }, [apiKey, src]);
47
+ }, [src]);
48
+ }
49
+ function Report({
50
+ primaryColor,
51
+ title,
52
+ reportBtnText,
53
+ btnEmoji,
54
+ btnTooltip,
55
+ emptyText,
56
+ userWhatsapp: localWhatsapp,
57
+ cdnBase: localCdn,
58
+ strategy: localStrategy,
59
+ onLoad,
60
+ onError
61
+ }) {
62
+ const ctx = React.useContext(BlindAgentsContext);
63
+ const src = `${localCdn ?? ctx.cdnBase}/report.js`;
64
+ const wa = localWhatsapp ?? ctx.userWhatsapp;
65
+ useScript(src, {
66
+ "data-api-key": ctx.apiKey,
67
+ "data-primary-color": primaryColor,
68
+ "data-title": title,
69
+ "data-report-btn-text": reportBtnText,
70
+ "data-btn-emoji": btnEmoji,
71
+ "data-btn-tooltip": btnTooltip,
72
+ "data-empty-text": emptyText,
73
+ "data-user-whatsapp": wa
74
+ }, localStrategy ?? ctx.strategy, onLoad, onError);
75
+ return null;
76
+ }
77
+ function Chat({
78
+ agentId,
79
+ primaryColor,
80
+ userWhatsapp: localWhatsapp,
81
+ cdnBase: localCdn,
82
+ strategy: localStrategy,
83
+ onLoad,
84
+ onError
85
+ }) {
86
+ const ctx = React.useContext(BlindAgentsContext);
87
+ const src = `${localCdn ?? ctx.cdnBase}/chat.js`;
88
+ const wa = localWhatsapp ?? ctx.userWhatsapp;
89
+ useScript(src, {
90
+ "data-api-key": ctx.apiKey,
91
+ "data-agent-id": agentId,
92
+ "data-primary-color": primaryColor,
93
+ "data-user-whatsapp": wa
94
+ }, localStrategy ?? ctx.strategy, onLoad, onError);
54
95
  return null;
55
96
  }
97
+ function Guide({
98
+ userWhatsapp: localWhatsapp,
99
+ cdnBase: localCdn,
100
+ strategy: localStrategy,
101
+ onLoad,
102
+ onError
103
+ }) {
104
+ const ctx = React.useContext(BlindAgentsContext);
105
+ const src = `${localCdn ?? ctx.cdnBase}/guide.js`;
106
+ const wa = localWhatsapp ?? ctx.userWhatsapp;
107
+ useScript(src, {
108
+ "data-api-key": ctx.apiKey,
109
+ "data-user-whatsapp": wa
110
+ }, localStrategy ?? ctx.strategy, onLoad, onError);
111
+ return null;
112
+ }
113
+ function BlindAgents({
114
+ apiKey,
115
+ userWhatsapp,
116
+ cdnBase = CDN_BASE,
117
+ strategy = "afterInteractive",
118
+ children
119
+ }) {
120
+ return /* @__PURE__ */ jsx(BlindAgentsContext.Provider, { value: { apiKey, userWhatsapp, cdnBase, strategy }, children });
121
+ }
122
+ BlindAgents.Report = Report;
123
+ BlindAgents.Chat = Chat;
124
+ BlindAgents.Guide = Guide;
125
+ function BlindAgentsWidget(props) {
126
+ return /* @__PURE__ */ jsx(BlindAgents, { apiKey: props.apiKey, userWhatsapp: props.userWhatsapp, strategy: props.strategy, children: /* @__PURE__ */ jsx(Report, { ...props }) });
127
+ }
56
128
  export {
129
+ BlindAgents,
57
130
  BlindAgentsWidget
58
131
  };
59
132
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ReactBlindAgentsWidget.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport type { BlindAgentsWidgetProps } from './types';\n\nconst CDN_DEFAULT = 'https://cdn.blindagents.com/report.js';\n\nexport function BlindAgentsWidget({\n apiKey,\n primaryColor,\n title,\n reportBtnText,\n btnEmoji,\n btnTooltip,\n emptyText,\n userWhatsapp,\n strategy = 'afterInteractive',\n src = CDN_DEFAULT,\n onLoad,\n onError,\n}: BlindAgentsWidgetProps) {\n const injected = useRef(false);\n\n useEffect(() => {\n if (injected.current) return;\n injected.current = true;\n\n // Deduplicate across multiple widget instances\n const existing = document.querySelector<HTMLScriptElement>(\n `script[src=\"${src}\"][data-ba-managed]`\n );\n if (existing) return;\n\n const el = document.createElement('script');\n el.src = src;\n el.setAttribute('data-ba-managed', 'true');\n el.setAttribute('data-api-key', apiKey);\n if (primaryColor) el.setAttribute('data-primary-color', primaryColor);\n if (title) el.setAttribute('data-title', title);\n if (reportBtnText) el.setAttribute('data-report-btn-text', reportBtnText);\n if (btnEmoji) el.setAttribute('data-btn-emoji', btnEmoji);\n if (btnTooltip) el.setAttribute('data-btn-tooltip', btnTooltip);\n if (emptyText) el.setAttribute('data-empty-text', emptyText);\n if (userWhatsapp) el.setAttribute('data-user-whatsapp', userWhatsapp);\n\n if (onLoad) el.addEventListener('load', () => onLoad());\n if (onError) el.addEventListener('error', () => onError(new Error(`Failed to load ${src}`)));\n\n const inject = () => {\n if (strategy === 'afterInteractive') el.defer = true;\n if (strategy === 'lazyOnload') el.async = true;\n document.head.appendChild(el);\n };\n\n if (strategy === 'lazyOnload' && typeof window !== 'undefined' && 'requestIdleCallback' in window) {\n (window as Window & { requestIdleCallback: (cb: () => void) => void }).requestIdleCallback(inject);\n } else {\n inject();\n }\n\n return () => {\n el.parentNode?.removeChild(el);\n injected.current = false;\n };\n }, [apiKey, src]); // eslint-disable-line react-hooks/exhaustive-deps\n\n return null;\n}\n"],"mappings":";AAEA,SAAS,WAAW,cAAc;AAGlC,IAAM,cAAc;AA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SAAG,YAAY,YAAY,EAAE;AAC7B,eAAS,UAAU;AAAA,IACrB;AAAA,EACF,GAAG,CAAC,QAAQ,GAAG,CAAC;AAEhB,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/ReactBlindAgents.tsx","../src/context.ts","../src/types.ts"],"sourcesContent":["'use client';\n\nimport React, { useEffect, useRef } from 'react';\nimport { BlindAgentsContext } from './context';\nimport type {\n BlindAgentsProps,\n ReportWidgetProps,\n ChatWidgetProps,\n GuideWidgetProps,\n} from './types';\nimport { CDN_BASE } from './types';\n\n// ── Script injection helper ───────────────────────────────────────────────────\n\nfunction useScript(\n src: string,\n attrs: Record<string, string | undefined>,\n strategy: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive',\n onLoad?: () => void,\n onError?: (e: Error) => void,\n) {\n const injected = useRef(false);\n\n useEffect(() => {\n if (injected.current) return;\n injected.current = true;\n\n // Deduplicate — only one script per src\n if (document.querySelector(`script[src=\"${src}\"][data-ba-managed]`)) return;\n\n const el = document.createElement('script');\n el.src = src;\n el.setAttribute('data-ba-managed', 'true');\n Object.entries(attrs).forEach(([k, v]) => {\n if (v != null && v !== '') el.setAttribute(k, v);\n });\n\n if (onLoad) el.addEventListener('load', () => onLoad());\n if (onError) el.addEventListener('error', () => onError(new Error(`Failed to load ${src}`)));\n\n const inject = () => {\n if (strategy === 'afterInteractive') el.defer = true;\n if (strategy === 'lazyOnload') el.async = true;\n document.head.appendChild(el);\n };\n\n if (strategy === 'lazyOnload' && 'requestIdleCallback' in window) {\n (window as any).requestIdleCallback(inject);\n } else {\n inject();\n }\n\n return () => { el.parentNode?.removeChild(el); injected.current = false; };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [src]);\n}\n\n// ── Widget sub-components ─────────────────────────────────────────────────────\n\nfunction Report({\n primaryColor,\n title,\n reportBtnText,\n btnEmoji,\n btnTooltip,\n emptyText,\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: ReportWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/report.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp;\n\n useScript(src, {\n 'data-api-key': ctx.apiKey,\n 'data-primary-color': primaryColor,\n 'data-title': title,\n 'data-report-btn-text': reportBtnText,\n 'data-btn-emoji': btnEmoji,\n 'data-btn-tooltip': btnTooltip,\n 'data-empty-text': emptyText,\n 'data-user-whatsapp': wa,\n }, localStrategy ?? ctx.strategy, onLoad, onError);\n\n return null;\n}\n\nfunction Chat({\n agentId,\n primaryColor,\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: ChatWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/chat.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp;\n\n useScript(src, {\n 'data-api-key': ctx.apiKey,\n 'data-agent-id': agentId,\n 'data-primary-color': primaryColor,\n 'data-user-whatsapp': wa,\n }, localStrategy ?? ctx.strategy, onLoad, onError);\n\n return null;\n}\n\nfunction Guide({\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: GuideWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/guide.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp;\n\n useScript(src, {\n 'data-api-key': ctx.apiKey,\n 'data-user-whatsapp': wa,\n }, localStrategy ?? ctx.strategy, onLoad, onError);\n\n return null;\n}\n\n// ── Root provider ─────────────────────────────────────────────────────────────\n\nexport function BlindAgents({\n apiKey,\n userWhatsapp,\n cdnBase = CDN_BASE,\n strategy = 'afterInteractive',\n children,\n}: BlindAgentsProps) {\n return (\n <BlindAgentsContext.Provider value={{ apiKey, userWhatsapp, cdnBase, strategy }}>\n {children}\n </BlindAgentsContext.Provider>\n );\n}\n\nBlindAgents.Report = Report;\nBlindAgents.Chat = Chat;\nBlindAgents.Guide = Guide;\n\n// ── Legacy single-widget export (backwards compat) ───────────────────────────\n/** @deprecated Use <BlindAgents><BlindAgents.Report /></BlindAgents> */\nexport function BlindAgentsWidget(props: ReportWidgetProps & { apiKey: string }) {\n return (\n <BlindAgents apiKey={props.apiKey} userWhatsapp={props.userWhatsapp} strategy={props.strategy}>\n <Report {...props} />\n </BlindAgents>\n );\n}\n","import { createContext, useContext } from 'react';\nimport { CDN_BASE } from './types';\n\nexport interface BlindAgentsContextValue {\n apiKey: string;\n userWhatsapp?: string;\n cdnBase: string;\n strategy: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';\n}\n\nexport const BlindAgentsContext = createContext<BlindAgentsContextValue>({\n apiKey: '',\n cdnBase: CDN_BASE,\n strategy: 'afterInteractive',\n});\n\nexport function useBlindAgents(): BlindAgentsContextValue {\n return useContext(BlindAgentsContext);\n}\n","const CDN_BASE = 'https://cdn.blindagents.com';\n\nexport { CDN_BASE };\n\n/** Common props shared by all widget types. */\nexport interface BaseWidgetProps {\n /** Your Blind Agents public API key (ba_...) */\n apiKey: string;\n /** Pre-filled WhatsApp number to skip identity verification */\n userWhatsapp?: string;\n /** Override the CDN base URL (useful for self-hosting) */\n cdnBase?: string;\n /** Script loading strategy @default \"afterInteractive\" */\n strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';\n /** Called once the script finishes loading */\n onLoad?: () => void;\n /** Called if the script fails to load */\n onError?: (error: Error) => void;\n}\n\n/** Report / bug-reporter widget */\nexport interface ReportWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n /** Accent color for the widget UI — any valid CSS color */\n primaryColor?: string;\n /** Title displayed in the widget panel header @default \"Help Center\" */\n title?: string;\n /** Label for the report button @default \"Report an issue\" */\n reportBtnText?: string;\n /** Emoji on the launcher floating button @default \"🐛\" */\n btnEmoji?: string;\n /** Tooltip on the launcher button */\n btnTooltip?: string;\n /** Text shown when there are no reports @default \"No issues reported yet.\" */\n emptyText?: string;\n}\n\n/** Webchat widget */\nexport interface ChatWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n /** The agent UUID to connect this chat to */\n agentId?: string;\n /** Accent color for the chat bubble and header */\n primaryColor?: string;\n}\n\n/** Product guides widget */\nexport interface GuideWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n // No additional props yet — the guide SDK reads config from the dashboard\n}\n\n/** Root provider props — all children share this apiKey */\nexport interface BlindAgentsProps extends BaseWidgetProps {\n children: React.ReactNode;\n}\n\n// ── Legacy single-widget props (kept for backwards compatibility) ──────────────\n/** @deprecated Use <BlindAgents apiKey=\"...\"><BlindAgents.Report /></BlindAgents> instead */\nexport interface BlindAgentsWidgetProps extends BaseWidgetProps {\n primaryColor?: string;\n title?: string;\n reportBtnText?: string;\n btnEmoji?: string;\n btnTooltip?: string;\n emptyText?: string;\n /** @deprecated Prefer userWhatsapp */\n src?: string;\n}\n"],"mappings":";AAEA,OAAO,SAAS,WAAW,cAAc;;;ACFzC,SAAS,eAAe,kBAAkB;;;ACA1C,IAAM,WAAW;;;ADUV,IAAM,qBAAqB,cAAuC;AAAA,EACvE,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AACZ,CAAC;;;ADgIG;AAhIJ,SAAS,UACP,KACA,OACA,UACA,QACA,SACA;AACA,QAAM,WAAW,OAAO,KAAK;AAE7B,YAAU,MAAM;AACd,QAAI,SAAS,QAAS;AACtB,aAAS,UAAU;AAGnB,QAAI,SAAS,cAAc,eAAe,GAAG,qBAAqB,EAAG;AAErE,UAAM,KAAK,SAAS,cAAc,QAAQ;AAC1C,OAAG,MAAM;AACT,OAAG,aAAa,mBAAmB,MAAM;AACzC,WAAO,QAAQ,KAAK,EAAE,QAAQ,CAAC,CAAC,GAAG,CAAC,MAAM;AACxC,UAAI,KAAK,QAAQ,MAAM,GAAI,IAAG,aAAa,GAAG,CAAC;AAAA,IACjD,CAAC;AAED,QAAI,OAAS,IAAG,iB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