@snf/qa-bot-core 0.2.30-rc.9 → 0.2.30

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.
@@ -2,7 +2,7 @@ import type { Settings, Flow } from 'react-chatbotify';
2
2
  /**
3
3
  * Analytics event types fired by qa-bot-core
4
4
  */
5
- export type QABotAnalyticsEventType = 'chatbot_open' | 'chatbot_close' | 'chatbot_new_chat' | 'chatbot_question_sent' | 'chatbot_answer_received' | 'chatbot_answer_error' | 'chatbot_rating_sent' | 'chatbot_login_prompt_shown' | 'chatbot_login_clicked' | 'chatbot_link_clicked';
5
+ export type QABotAnalyticsEventType = 'chatbot_open' | 'chatbot_close' | 'chatbot_new_chat' | 'chatbot_question_sent' | 'chatbot_answer_received' | 'chatbot_answer_error' | 'chatbot_rating_sent' | 'chatbot_login_prompt_shown' | 'chatbot_login_clicked' | 'chatbot_link_clicked' | 'chatbot_turnstile_shown' | 'chatbot_turnstile_completed' | 'chatbot_turnstile_error';
6
6
  /**
7
7
  * Analytics event payload
8
8
  *
@@ -50,6 +50,19 @@ export interface QABotProps {
50
50
  qaEndpoint: string;
51
51
  welcomeMessage: string;
52
52
  ratingEndpoint?: string;
53
+ /**
54
+ * Endpoint for the capabilities API (e.g., /api/v1/capabilities).
55
+ * The wrapper can use this to fetch dynamic capability buttons on load.
56
+ * Core does not fetch from this — it's a passthrough for wrappers.
57
+ */
58
+ capabilitiesEndpoint?: string;
59
+ /**
60
+ * Rating endpoint for agent-handled responses (non-RAG).
61
+ * When the response metadata includes `rating_target: "agent"`,
62
+ * ratings are POSTed here instead of `ratingEndpoint`.
63
+ * Payload: { query_id, rating: "helpful"|"not_helpful", feedback? }
64
+ */
65
+ agentRatingEndpoint?: string;
53
66
  primaryColor?: string;
54
67
  secondaryColor?: string;
55
68
  botName?: string;
@@ -83,6 +96,16 @@ export interface QABotProps {
83
96
  * - Optional: if not provided, requests will be anonymous
84
97
  */
85
98
  actingUser?: string;
99
+ /**
100
+ * Cloudflare Turnstile site key for bot protection.
101
+ * When provided, an invisible Turnstile widget is rendered on mount
102
+ * to silently verify the user. The token is attached to every query
103
+ * automatically. If silent verification fails, the backend's
104
+ * visible-challenge flow kicks in as a fallback.
105
+ *
106
+ * Omit or pass empty string to disable Turnstile entirely on the frontend.
107
+ */
108
+ turnstileSiteKey?: string;
86
109
  /**
87
110
  * Custom flow steps to merge with the built-in Q&A flow.
88
111
  * Use this to add ticket creation flows, feedback flows, etc.
@@ -0,0 +1,27 @@
1
+ /**
2
+ * useTurnstile — silent background Turnstile verification.
3
+ *
4
+ * Renders an invisible Cloudflare Turnstile widget on mount. Most legitimate
5
+ * users get a token automatically (no UI). The token is exposed so the
6
+ * qa-flow can attach it to every request.
7
+ *
8
+ * If silent verification fails (Cloudflare deems the visitor suspicious),
9
+ * `status` becomes 'failed' and the qa-flow falls back to the existing
10
+ * visible-challenge path (backend returns requires_turnstile, widget shown
11
+ * in chat).
12
+ *
13
+ * Turnstile tokens expire after ~300 s. The widget's built-in
14
+ * `refresh-expired: auto` handles re-issuing before expiry.
15
+ */
16
+ export type TurnstileStatus = 'idle' | 'loading' | 'verified' | 'failed';
17
+ export interface UseTurnstileResult {
18
+ /** Current Turnstile token, or null if not yet verified / failed. */
19
+ token: string | null;
20
+ /** Lifecycle status of the silent verification. */
21
+ status: TurnstileStatus;
22
+ }
23
+ /**
24
+ * @param siteKey Cloudflare Turnstile site key. Pass `undefined` or empty
25
+ * string to disable (hook becomes a no-op).
26
+ */
27
+ export declare function useTurnstile(siteKey: string | undefined): UseTurnstileResult;
@@ -22,10 +22,13 @@ interface QABotConfig {
22
22
  apiKey: string;
23
23
  qaEndpoint: string;
24
24
  ratingEndpoint?: string;
25
+ capabilitiesEndpoint?: string;
26
+ agentRatingEndpoint?: string;
25
27
  defaultOpen?: boolean;
26
28
  embedded?: boolean;
27
29
  isLoggedIn: boolean;
28
30
  allowAnonAccess?: boolean;
31
+ turnstileSiteKey?: string;
29
32
  welcomeMessage: string;
30
33
  primaryColor?: string;
31
34
  secondaryColor?: string;
@@ -6,8 +6,10 @@ import type { AnalyticsEventInput } from '../../contexts/AnalyticsContext';
6
6
  export interface CreateQAFlowParams {
7
7
  /** Q&A API endpoint (required) */
8
8
  endpoint: string;
9
- /** Rating API endpoint (optional) */
9
+ /** Rating API endpoint for RAG responses (optional) */
10
10
  ratingEndpoint?: string;
11
+ /** Rating API endpoint for agent responses (optional) */
12
+ agentRatingEndpoint?: string;
11
13
  /** API key for authentication (optional) */
12
14
  apiKey?: string;
13
15
  /** Function that returns current session ID */
@@ -28,12 +30,19 @@ export interface CreateQAFlowParams {
28
30
  actingUser?: string;
29
31
  /** Enriched analytics tracker (adds common fields automatically) */
30
32
  trackEvent?: (event: AnalyticsEventInput) => void;
33
+ /**
34
+ * Returns the current silent Turnstile token (from useTurnstile hook).
35
+ * When available, attached to every request so the backend can verify
36
+ * without prompting. When null, the backend's free-query allowance
37
+ * applies, and the visible challenge is the fallback.
38
+ */
39
+ getTurnstileToken?: () => string | null;
31
40
  }
32
41
  /**
33
42
  * Creates the basic Q&A conversation flow
34
43
  * Handles questions, responses, and optional ratings
35
44
  */
36
- export declare const createQAFlow: ({ endpoint, ratingEndpoint, apiKey, sessionId: getSessionId, isResetting, isLoggedIn, allowAnonAccess, loginUrl, actingUser, trackEvent }: CreateQAFlowParams) => {
45
+ export declare const createQAFlow: ({ endpoint, ratingEndpoint, agentRatingEndpoint, apiKey, sessionId: getSessionId, isResetting, isLoggedIn, allowAnonAccess, loginUrl, actingUser, trackEvent, getTurnstileToken, }: CreateQAFlowParams) => {
37
46
  qa_loop: {
38
47
  message: string;
39
48
  component: React.JSX.Element;
@@ -44,7 +53,7 @@ export declare const createQAFlow: ({ endpoint, ratingEndpoint, apiKey, sessionI
44
53
  };
45
54
  } | {
46
55
  qa_loop: {
47
- message: (chatState: any) => Promise<"Thanks for the feedback! Feel free to ask another question." | "Verification failed. Please try your question again." | "I had trouble processing your question after verification. Please try again." | "Please verify you're human to continue." | "I apologize, but I'm having trouble processing your question. Please try again later.">;
56
+ message: (chatState: any) => Promise<"Thanks for the feedback!" | "One moment verifying your session…" | "I apologize, but I'm having trouble processing your question. Please try again later.">;
48
57
  options: (chatState: any) => string[];
49
58
  renderMarkdown: string[];
50
59
  chatDisabled: boolean;
@@ -7,12 +7,14 @@
7
7
  * Usage for consumers:
8
8
  * localStorage.setItem('QA_BOT_DEBUG', 'true'); // Enable debug logs + version
9
9
  */
10
- export declare const LIB_VERSION = "0.2.30-rc.9";
10
+ export declare const LIB_VERSION = "0.2.30";
11
+ export declare function isDebugEnabled(): boolean;
11
12
  export declare const logger: {
12
13
  version: () => void;
13
14
  session: (action: string, ...args: unknown[]) => void;
14
15
  history: (action: string, ...args: unknown[]) => void;
15
16
  message: (action: string, data: Record<string, unknown>) => void;
17
+ turnstile: (action: string, ...args: unknown[]) => void;
16
18
  warn: (...args: unknown[]) => void;
17
19
  error: (...args: unknown[]) => void;
18
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snf/qa-bot-core",
3
- "version": "0.2.30-rc.9",
3
+ "version": "0.2.30",
4
4
  "description": "A configurable chatbot setup for quick integration of RAG-powered Q&A and rating system",
5
5
  "main": "./dist/qa-bot-core.umd.cjs",
6
6
  "module": "./dist/qa-bot-core.js",