vpschatbotwidget 1.0.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.
Files changed (63) hide show
  1. package/Chatbot.svg +1 -0
  2. package/README.md +86 -0
  3. package/dist/assets/index-C0fUDi2s.css +1 -0
  4. package/dist/assets/index-foGq5_Av.js +159 -0
  5. package/dist/index.html +17 -0
  6. package/index.html +16 -0
  7. package/package.json +47 -0
  8. package/src/App.tsx +85 -0
  9. package/src/chatbot/api/chatbot-api.ts +258 -0
  10. package/src/chatbot/api/chatbot-types.ts +145 -0
  11. package/src/chatbot/chatbot.test.tsx +274 -0
  12. package/src/chatbot/config/colors.ts +166 -0
  13. package/src/chatbot/config/suggestions.ts +21 -0
  14. package/src/chatbot/core/ChatContext.tsx +43 -0
  15. package/src/chatbot/core/ChatEmptyState.tsx +21 -0
  16. package/src/chatbot/core/ChatError.tsx +26 -0
  17. package/src/chatbot/core/ChatHeader.tsx +108 -0
  18. package/src/chatbot/core/ChatInput.tsx +103 -0
  19. package/src/chatbot/core/ChatMarkdown.tsx +87 -0
  20. package/src/chatbot/core/ChatMessage.tsx +115 -0
  21. package/src/chatbot/core/ChatMessageList.tsx +47 -0
  22. package/src/chatbot/core/ChatPanel.tsx +66 -0
  23. package/src/chatbot/core/ChatProvider.tsx +185 -0
  24. package/src/chatbot/core/ChatSuggestions.tsx +71 -0
  25. package/src/chatbot/core/ChatTicketConfirmation.tsx +59 -0
  26. package/src/chatbot/core/ChatTypingIndicator.tsx +16 -0
  27. package/src/chatbot/core/ticket-intent.ts +12 -0
  28. package/src/chatbot/embedded/EmbeddedChatbot.tsx +47 -0
  29. package/src/chatbot/embedded/EmbeddedChatbotPanel.tsx +56 -0
  30. package/src/chatbot/embedded/EmbeddedChatbotTrigger.tsx +167 -0
  31. package/src/chatbot/hooks/useChatbot.ts +5 -0
  32. package/src/chatbot/index.ts +7 -0
  33. package/src/chatbot/widget/ChatbotWidget.tsx +43 -0
  34. package/src/chatbot/widget/ChatbotWidgetPanel.tsx +39 -0
  35. package/src/chatbot/widget/ChatbotWidgetTrigger.tsx +32 -0
  36. package/src/components/AgentSummaryCard.tsx +37 -0
  37. package/src/components/ChatHeader.tsx +142 -0
  38. package/src/components/ChatInput.tsx +123 -0
  39. package/src/components/ChatWidget.tsx +295 -0
  40. package/src/components/ConnectingStatus.tsx +16 -0
  41. package/src/components/EnvBadge.tsx +103 -0
  42. package/src/components/FeedbackRatingCard.tsx +123 -0
  43. package/src/components/MessageItem.tsx +157 -0
  44. package/src/components/MessageList.tsx +143 -0
  45. package/src/components/OrderTrackingCard.tsx +104 -0
  46. package/src/components/QuickPrompts.tsx +46 -0
  47. package/src/components/ResponseIconMapper.tsx +155 -0
  48. package/src/components/SourceCitations.tsx +46 -0
  49. package/src/components/ToolCallBadge.tsx +29 -0
  50. package/src/components/TypingProgressBar.tsx +113 -0
  51. package/src/components/ui/message-scroller.tsx +128 -0
  52. package/src/index.css +550 -0
  53. package/src/lib/cn.ts +5 -0
  54. package/src/lib/gibberishDetector.ts +159 -0
  55. package/src/lib/textHighlighter.tsx +206 -0
  56. package/src/main.tsx +10 -0
  57. package/src/services/api.ts +74 -0
  58. package/src/test/message-scroller-stub.tsx +60 -0
  59. package/src/test/setup.ts +8 -0
  60. package/src/types/chat.ts +66 -0
  61. package/src/vite-env.d.ts +14 -0
  62. package/tsconfig.json +21 -0
  63. package/vite.config.ts +28 -0
@@ -0,0 +1,157 @@
1
+ import React, { useState } from "react";
2
+ import { BotMessageSquare, Check, CornerUpLeft, Smile } from "lucide-react";
3
+ import { Message } from "../types/chat";
4
+ import { SourceCitations } from "./SourceCitations";
5
+ import { ToolCallBadge } from "./ToolCallBadge";
6
+ import { QuickPrompts, QuickOption } from "./QuickPrompts";
7
+ import { renderHighlightedText } from "../lib/textHighlighter";
8
+ import { ResponseIconMapper } from "./ResponseIconMapper";
9
+
10
+ interface MessageItemProps {
11
+ message: Message;
12
+ agentInitials?: string;
13
+ isBot?: boolean;
14
+ onSelectPrompt?: (prompt: string) => void;
15
+ quickOptions?: QuickOption[];
16
+ }
17
+
18
+ // ── Markdown block renderer ────────────────────────────────────────────────────
19
+ const formatMarkdown = (text: string) => {
20
+ if (!text) return null;
21
+
22
+ const blocks = text.split(/\n\n+/);
23
+
24
+ return blocks.map((block, bIdx) => {
25
+ // Bullet lists
26
+ if (block.trim().startsWith("- ") || block.trim().startsWith("* ")) {
27
+ const items = block
28
+ .split(/\n/)
29
+ .filter((line) => line.trim().startsWith("- ") || line.trim().startsWith("* "));
30
+ return (
31
+ <ul key={bIdx} className="msg-list">
32
+ {items.map((item, iIdx) => (
33
+ <li key={iIdx}>{renderHighlightedText(item.replace(/^[-*]\s+/, ""))}</li>
34
+ ))}
35
+ </ul>
36
+ );
37
+ }
38
+
39
+ // Numbered lists
40
+ if (/^\d+\.\s+/.test(block.trim())) {
41
+ const items = block
42
+ .split(/\n/)
43
+ .filter((line) => /^\d+\.\s+/.test(line.trim()));
44
+ return (
45
+ <ol key={bIdx} className="msg-ordered-list">
46
+ {items.map((item, iIdx) => (
47
+ <li key={iIdx}>{renderHighlightedText(item.replace(/^\d+\.\s+/, ""))}</li>
48
+ ))}
49
+ </ol>
50
+ );
51
+ }
52
+
53
+ return (
54
+ <p key={bIdx} className="msg-para">
55
+ {renderHighlightedText(block)}
56
+ </p>
57
+ );
58
+ });
59
+ };
60
+
61
+ // ── Component ──────────────────────────────────────────────────────────────────
62
+ export const MessageItem: React.FC<MessageItemProps> = ({
63
+ message,
64
+ agentInitials = "FIK",
65
+ isBot = false,
66
+ onSelectPrompt,
67
+ quickOptions,
68
+ }) => {
69
+ const isUser = message.role === "user";
70
+ const [reaction, setReaction] = useState<string | null>(null);
71
+
72
+ return (
73
+ <div className={`message-item-row ${isUser ? "row-user" : "row-assistant"}`}>
74
+ {/* Left Avatar for Bot/Agent */}
75
+ {!isUser && (
76
+ <div className="msg-avatar-assistant">
77
+ {isBot ? <BotMessageSquare size={15} /> : <span>{agentInitials}</span>}
78
+ </div>
79
+ )}
80
+
81
+ {/* Message Bubble + Actions */}
82
+ <div className="msg-content-wrapper">
83
+ <div
84
+ className={`msg-bubble ${
85
+ isUser ? "bubble-user" : message.error ? "bubble-error" : "bubble-assistant"
86
+ }`}
87
+ >
88
+ {isUser ? (
89
+ /* User messages: plain text, no extra highlighting */
90
+ <div className="user-text-row">
91
+ <span>{message.content}</span>
92
+ </div>
93
+ ) : (
94
+ /* Assistant messages: icon badge + rich highlighted markdown */
95
+ <div className="assistant-text-content">
96
+ <ResponseIconMapper content={message.content} />
97
+ {formatMarkdown(message.content)}
98
+ </div>
99
+ )}
100
+
101
+ {/* Quick option buttons */}
102
+ {quickOptions && quickOptions.length > 0 && onSelectPrompt && (
103
+ <QuickPrompts options={quickOptions} onSelectPrompt={onSelectPrompt} />
104
+ )}
105
+
106
+ {/* Tool call badges */}
107
+ {message.tool_calls && message.tool_calls.length > 0 && (
108
+ <ToolCallBadge toolCalls={message.tool_calls} />
109
+ )}
110
+
111
+ {/* Source citations */}
112
+ {message.sources && message.sources.length > 0 && (
113
+ <SourceCitations sources={message.sources} />
114
+ )}
115
+ </div>
116
+
117
+ {/* Action icons on hover for assistant messages */}
118
+ {!isUser && (
119
+ <div className="msg-action-bar">
120
+ <button
121
+ className="msg-action-btn"
122
+ title="React"
123
+ onClick={() => setReaction(reaction ? null : "😊")}
124
+ >
125
+ <Smile size={14} />
126
+ {reaction && <span className="active-reaction">{reaction}</span>}
127
+ </button>
128
+ <button className="msg-action-btn" title="Reply">
129
+ <CornerUpLeft size={14} />
130
+ </button>
131
+ </div>
132
+ )}
133
+
134
+ {/* Read checkmark for user messages */}
135
+ {isUser && (
136
+ <div className="user-status-row">
137
+ <Check size={13} className="user-check-icon" />
138
+ </div>
139
+ )}
140
+ </div>
141
+
142
+ {/* Right Avatar for User */}
143
+ {isUser && (
144
+ <div className="msg-avatar-user">
145
+ <img
146
+ src="https://images.unsplash.com/photo-1534528741775-53994a69daeb?w=100&auto=format&fit=crop&q=80"
147
+ alt="User"
148
+ className="user-avatar-img"
149
+ onError={(e) => {
150
+ e.currentTarget.style.display = "none";
151
+ }}
152
+ />
153
+ </div>
154
+ )}
155
+ </div>
156
+ );
157
+ };
@@ -0,0 +1,143 @@
1
+ import React, { useEffect, useRef } from "react";
2
+ import { Bot, BotMessageSquare } from "lucide-react";
3
+ import { Message } from "../types/chat";
4
+ import { MessageItem } from "./MessageItem";
5
+ import { ConnectingStatus } from "./ConnectingStatus";
6
+ import { AgentSummaryCard } from "./AgentSummaryCard";
7
+ import { FeedbackRatingCard } from "./FeedbackRatingCard";
8
+ import { QuickOption } from "./QuickPrompts";
9
+ import { TypingProgressBar } from "./TypingProgressBar";
10
+
11
+ interface MessageListProps {
12
+ messages: Message[];
13
+ isLoading: boolean;
14
+ isConnectingAgent?: boolean;
15
+ connectingLabel?: string;
16
+ isChatClosed?: boolean;
17
+ showFeedbackCard?: boolean;
18
+ agentName?: string;
19
+ agentInitials?: string;
20
+ chatDuration?: string;
21
+ isBot?: boolean;
22
+ onSelectPrompt?: (prompt: string) => void;
23
+ welcomeQuickOptions?: QuickOption[];
24
+ onSubmitFeedback?: (rating: string, reasons: string) => void;
25
+ onCancelFeedback?: () => void;
26
+ }
27
+
28
+ export const MessageList: React.FC<MessageListProps> = ({
29
+ messages,
30
+ isLoading,
31
+ isConnectingAgent = false,
32
+ connectingLabel = "Connecting with agent",
33
+ isChatClosed = false,
34
+ showFeedbackCard = false,
35
+ agentName = "Fikri Studio",
36
+ agentInitials = "FIK",
37
+ chatDuration = "12 Mins 23 Sec",
38
+ isBot = false,
39
+ onSelectPrompt,
40
+ welcomeQuickOptions,
41
+ onSubmitFeedback,
42
+ onCancelFeedback,
43
+ }) => {
44
+ const bottomRef = useRef<HTMLDivElement>(null);
45
+
46
+ useEffect(() => {
47
+ bottomRef.current?.scrollIntoView({ behavior: "smooth" });
48
+ }, [messages, isLoading, isConnectingAgent, isChatClosed, showFeedbackCard]);
49
+
50
+ return (
51
+ // Wrapper makes the scroll area + progress bar stack correctly
52
+ <div className="messages-scroll-outer">
53
+ <div className="messages-scroll-area">
54
+ {/* If no messages yet, display default bot greeting card */}
55
+ {messages.length === 0 && (
56
+ <div className="message-item-row row-assistant">
57
+ <div className="msg-avatar-assistant">
58
+ <BotMessageSquare size={15} />
59
+ </div>
60
+ <div className="msg-content-wrapper">
61
+ <div className="msg-bubble bubble-assistant">
62
+ <p className="msg-para">
63
+ Hey ! I'm a VPS Veritas AI Assistant. Ask me anything or share your feedback or select an option below.
64
+ </p>
65
+ {welcomeQuickOptions && welcomeQuickOptions.length > 0 && onSelectPrompt && (
66
+ <div style={{ marginTop: "12px" }}>
67
+ {welcomeQuickOptions.map((opt, idx) => (
68
+ <button
69
+ key={idx}
70
+ type="button"
71
+ className="quick-option-pill-btn"
72
+ onClick={() => onSelectPrompt(opt.query)}
73
+ >
74
+ <span>{opt.label}</span>
75
+ </button>
76
+ ))}
77
+ </div>
78
+ )}
79
+ </div>
80
+ </div>
81
+ </div>
82
+ )}
83
+
84
+ {/* Render Conversation Messages */}
85
+ {messages.map((msg, idx) => (
86
+ <MessageItem
87
+ key={msg.id || idx}
88
+ message={msg}
89
+ agentInitials={agentInitials}
90
+ isBot={isBot}
91
+ onSelectPrompt={onSelectPrompt}
92
+ quickOptions={idx === 0 && isBot ? welcomeQuickOptions : undefined}
93
+ />
94
+ ))}
95
+
96
+ {/* Animated Connecting Status Ring Spinner */}
97
+ {isConnectingAgent && <ConnectingStatus label={connectingLabel} />}
98
+
99
+ {/* Three-dot typing bubble (kept for backward compat but hidden when progress bar shows) */}
100
+ {isLoading && (
101
+ <div className="message-item-row row-assistant">
102
+ <div className="msg-avatar-assistant">
103
+ {isBot ? <BotMessageSquare size={15} /> : <span>{agentInitials}</span>}
104
+ </div>
105
+ <div className="msg-content-wrapper">
106
+ <div className="msg-bubble bubble-assistant typing-bubble-wrapper">
107
+ <span className="dot-pulse" />
108
+ <span className="dot-pulse" />
109
+ <span className="dot-pulse" />
110
+ </div>
111
+ </div>
112
+ </div>
113
+ )}
114
+
115
+ {/* Concluded Session Elements (Screen 3) */}
116
+ {isChatClosed && (
117
+ <div className="chat-closed-pill-wrapper">
118
+ <span className="chat-closed-pill">Chat Closed</span>
119
+ </div>
120
+ )}
121
+
122
+ {showFeedbackCard && (
123
+ <>
124
+ <AgentSummaryCard
125
+ agentName={agentName}
126
+ agentInitials={agentInitials}
127
+ duration={chatDuration}
128
+ />
129
+ <FeedbackRatingCard
130
+ onSubmitFeedback={onSubmitFeedback}
131
+ onCancel={onCancelFeedback}
132
+ />
133
+ </>
134
+ )}
135
+
136
+ <div ref={bottomRef} />
137
+ </div>
138
+
139
+ {/* ── Bottom-docked animated progress bar ── */}
140
+ <TypingProgressBar isVisible={isLoading} />
141
+ </div>
142
+ );
143
+ };
@@ -0,0 +1,104 @@
1
+ import React, { useState } from "react";
2
+ import { Check, Minus, Plus } from "lucide-react";
3
+
4
+ export interface StepperStep {
5
+ label: string;
6
+ status: "completed" | "active" | "pending";
7
+ }
8
+
9
+ interface OrderTrackingCardProps {
10
+ orderId?: string;
11
+ statusBadge?: string;
12
+ totalAmount?: string;
13
+ steps?: StepperStep[];
14
+ }
15
+
16
+ export const OrderTrackingCard: React.FC<OrderTrackingCardProps> = ({
17
+ orderId = "#SO-567",
18
+ statusBadge = "Paid",
19
+ totalAmount = "$256.00",
20
+ steps = [
21
+ { label: "Quoted", status: "completed" },
22
+ { label: "Packed", status: "active" },
23
+ { label: "Shipped", status: "pending" },
24
+ { label: "Delivered", status: "pending" },
25
+ ],
26
+ }) => {
27
+ const [isCollapsed, setIsCollapsed] = useState(false);
28
+
29
+ return (
30
+ <div className="tracking-card">
31
+ <div className="tracking-header">
32
+ <div className="tracking-title-row">
33
+ <span className="tracking-order-title">
34
+ Order <strong>{orderId}</strong>
35
+ </span>
36
+ <span className="tracking-paid-badge">{statusBadge}</span>
37
+ </div>
38
+ <button
39
+ className="tracking-toggle-btn"
40
+ onClick={() => setIsCollapsed(!isCollapsed)}
41
+ title={isCollapsed ? "Expand tracker" : "Collapse tracker"}
42
+ aria-label="Toggle tracker"
43
+ >
44
+ {isCollapsed ? <Plus size={14} /> : <Minus size={14} />}
45
+ </button>
46
+ </div>
47
+
48
+ {!isCollapsed && (
49
+ <div className="tracking-body">
50
+ <div className="tracking-total">
51
+ Total <strong>{totalAmount}</strong>
52
+ </div>
53
+
54
+ <div className="stepper-container">
55
+ {steps.map((step, idx) => {
56
+ const isFirst = idx === 0;
57
+ const isLast = idx === steps.length - 1;
58
+
59
+ return (
60
+ <div key={idx} className="stepper-item">
61
+ <div className="stepper-indicator-wrapper">
62
+ {/* Left connector line */}
63
+ {!isFirst && (
64
+ <div
65
+ className={`stepper-line ${
66
+ step.status === "completed" || step.status === "active"
67
+ ? "stepper-line-active"
68
+ : "stepper-line-dotted"
69
+ }`}
70
+ />
71
+ )}
72
+
73
+ {/* Step Node */}
74
+ <div className={`stepper-node stepper-node-${step.status}`}>
75
+ {step.status === "completed" ? (
76
+ <Check size={11} strokeWidth={3} />
77
+ ) : (
78
+ <span className="stepper-dot" />
79
+ )}
80
+ </div>
81
+
82
+ {/* Right connector line */}
83
+ {!isLast && (
84
+ <div
85
+ className={`stepper-line ${
86
+ step.status === "completed"
87
+ ? "stepper-line-active"
88
+ : "stepper-line-dotted"
89
+ }`}
90
+ />
91
+ )}
92
+ </div>
93
+ <span className={`stepper-label stepper-label-${step.status}`}>
94
+ {step.label}
95
+ </span>
96
+ </div>
97
+ );
98
+ })}
99
+ </div>
100
+ </div>
101
+ )}
102
+ </div>
103
+ );
104
+ };
@@ -0,0 +1,46 @@
1
+ import React from "react";
2
+
3
+ export interface QuickOption {
4
+ label: string;
5
+ query: string;
6
+ }
7
+
8
+ interface QuickPromptsProps {
9
+ onSelectPrompt: (prompt: string) => void;
10
+ options?: QuickOption[];
11
+ }
12
+
13
+ const DEFAULT_OPTIONS: QuickOption[] = [
14
+ {
15
+ label: "Get free training",
16
+ query: "What training and fuel quality testing guides are available?",
17
+ },
18
+ {
19
+ label: "Get Started free",
20
+ query: "How do I pre-register fuel samples and get started in the portal?",
21
+ },
22
+ {
23
+ label: "Chat with the sales team",
24
+ query: "I would like to chat with the support and sales team.",
25
+ },
26
+ ];
27
+
28
+ export const QuickPrompts: React.FC<QuickPromptsProps> = ({
29
+ onSelectPrompt,
30
+ options = DEFAULT_OPTIONS,
31
+ }) => {
32
+ return (
33
+ <div className="quick-options-list">
34
+ {options.map((opt, idx) => (
35
+ <button
36
+ key={idx}
37
+ type="button"
38
+ className="quick-option-pill-btn"
39
+ onClick={() => onSelectPrompt(opt.query)}
40
+ >
41
+ <span>{opt.label}</span>
42
+ </button>
43
+ ))}
44
+ </div>
45
+ );
46
+ };
@@ -0,0 +1,155 @@
1
+ /**
2
+ * ResponseIconMapper.tsx
3
+ *
4
+ * Analyses assistant message content and renders a context-aware status
5
+ * icon badge above/beside the bubble to give instant visual cues about
6
+ * the nature of the response.
7
+ *
8
+ * Mappings (first match wins):
9
+ * ─ Error / not-found keywords → AlertCircle (red)
10
+ * ─ Database / ticket keywords → Database (indigo)
11
+ * ─ LinkedIn URL present → Linkedin (blue)
12
+ * ─ YouTube URL present → Youtube (red)
13
+ * ─ Link / URL present → Link2 (orange)
14
+ * ─ Success / resolved → CheckCircle2 (green)
15
+ * ─ Warning / urgent → AlertTriangle (amber)
16
+ * ─ Info / help / guide → Info (sky)
17
+ * ─ Chemical / sample / bunker → FlaskConical (teal)
18
+ * ─ Vessel / ship → Anchor (slate)
19
+ * ─ Default → MessageSquare (muted)
20
+ */
21
+
22
+ import React from "react";
23
+ import {
24
+ AlertCircle,
25
+ AlertTriangle,
26
+ CheckCircle2,
27
+ Database,
28
+ Linkedin,
29
+ Youtube,
30
+ Link2,
31
+ Info,
32
+ FlaskConical,
33
+ Anchor,
34
+ MessageSquare,
35
+ } from "lucide-react";
36
+
37
+ // ── Rule definition ────────────────────────────────────────────────────────────
38
+ interface IconRule {
39
+ /** Test the lower-cased message content */
40
+ test: (content: string) => boolean;
41
+ Icon: React.ElementType;
42
+ label: string;
43
+ /** CSS class applied to the badge wrapper */
44
+ variant: "error" | "warning" | "success" | "info" | "linkedin" | "youtube" | "link" | "database" | "chem" | "vessel" | "muted";
45
+ }
46
+
47
+ const RULES: IconRule[] = [
48
+ // ── Error / not found ────────────────────────────────────────────────────────
49
+ {
50
+ test: (c) =>
51
+ /does not exist|not found|no record|unable to|failed|error|invalid|not in (the )?(vps )?database/i.test(c),
52
+ Icon: AlertCircle,
53
+ label: "Not found / Error",
54
+ variant: "error",
55
+ },
56
+ // ── Warning / urgent ─────────────────────────────────────────────────────────
57
+ {
58
+ test: (c) => /urgent|warning|caution|high priority|overdue|critical/i.test(c),
59
+ Icon: AlertTriangle,
60
+ label: "Warning",
61
+ variant: "warning",
62
+ },
63
+ // ── LinkedIn ─────────────────────────────────────────────────────────────────
64
+ {
65
+ test: (c) => /linkedin\.com/i.test(c),
66
+ Icon: Linkedin,
67
+ label: "LinkedIn",
68
+ variant: "linkedin",
69
+ },
70
+ // ── YouTube ──────────────────────────────────────────────────────────────────
71
+ {
72
+ test: (c) => /youtube\.com|youtu\.be/i.test(c),
73
+ Icon: Youtube,
74
+ label: "YouTube",
75
+ variant: "youtube",
76
+ },
77
+ // ── Generic link ─────────────────────────────────────────────────────────────
78
+ {
79
+ test: (c) => /https?:\/\//i.test(c),
80
+ Icon: Link2,
81
+ label: "Contains links",
82
+ variant: "link",
83
+ },
84
+ // ── Success / resolved ───────────────────────────────────────────────────────
85
+ {
86
+ test: (c) =>
87
+ /resolved|completed|done|success|confirmed|fixed|closed/i.test(c),
88
+ Icon: CheckCircle2,
89
+ label: "Resolved",
90
+ variant: "success",
91
+ },
92
+ // ── Database / ticket ────────────────────────────────────────────────────────
93
+ {
94
+ test: (c) =>
95
+ /ticket|database|record|customer id|session|query|tck-/i.test(c),
96
+ Icon: Database,
97
+ label: "Database / Ticket",
98
+ variant: "database",
99
+ },
100
+ // ── Chemical / sample / bunker ───────────────────────────────────────────────
101
+ {
102
+ test: (c) =>
103
+ /chemical|viscosity|bunker|sample|screening|kinematic/i.test(c),
104
+ Icon: FlaskConical,
105
+ label: "Chemical / Lab",
106
+ variant: "chem",
107
+ },
108
+ // ── Vessel / ship ────────────────────────────────────────────────────────────
109
+ {
110
+ test: (c) => /vessel|ship|northern star|mv |maritime/i.test(c),
111
+ Icon: Anchor,
112
+ label: "Vessel",
113
+ variant: "vessel",
114
+ },
115
+ // ── Info / help ──────────────────────────────────────────────────────────────
116
+ {
117
+ test: (c) => /help|guide|tip|information|learn more|here is/i.test(c),
118
+ Icon: Info,
119
+ label: "Information",
120
+ variant: "info",
121
+ },
122
+ ];
123
+
124
+ function resolveRule(content: string): IconRule {
125
+ for (const rule of RULES) {
126
+ if (rule.test(content)) return rule;
127
+ }
128
+ return {
129
+ test: () => true,
130
+ Icon: MessageSquare,
131
+ label: "Response",
132
+ variant: "muted",
133
+ };
134
+ }
135
+
136
+ // ── Component ──────────────────────────────────────────────────────────────────
137
+ interface ResponseIconMapperProps {
138
+ content: string;
139
+ }
140
+
141
+ export const ResponseIconMapper: React.FC<ResponseIconMapperProps> = ({
142
+ content,
143
+ }) => {
144
+ const { Icon, label, variant } = resolveRule(content);
145
+
146
+ return (
147
+ <span
148
+ className={`resp-icon-badge resp-icon-badge--${variant}`}
149
+ title={label}
150
+ aria-label={label}
151
+ >
152
+ <Icon size={12} />
153
+ </span>
154
+ );
155
+ };
@@ -0,0 +1,46 @@
1
+ import React, { useState } from "react";
2
+ import { ChevronDown, ChevronUp, FileText } from "lucide-react";
3
+ import { Source } from "../types/chat";
4
+
5
+ interface SourceCitationsProps {
6
+ sources?: Source[];
7
+ }
8
+
9
+ export const SourceCitations: React.FC<SourceCitationsProps> = ({ sources }) => {
10
+ const [isOpen, setIsOpen] = useState(false);
11
+
12
+ if (!sources || sources.length === 0) return null;
13
+
14
+ return (
15
+ <div className="sources-container">
16
+ <button
17
+ className="sources-btn"
18
+ onClick={() => setIsOpen(!isOpen)}
19
+ type="button"
20
+ >
21
+ <FileText size={12} />
22
+ <span>
23
+ {sources.length} Grounded Source{sources.length > 1 ? "s" : ""}
24
+ </span>
25
+ {isOpen ? <ChevronUp size={12} /> : <ChevronDown size={12} />}
26
+ </button>
27
+
28
+ {isOpen && (
29
+ <div className="sources-list">
30
+ {sources.map((src, idx) => {
31
+ const fileName = src.source.split(/[/\\]/).pop() || src.source;
32
+ const percentage = Math.round(src.score * 100);
33
+ return (
34
+ <div key={idx} className="source-item">
35
+ <span className="source-name" title={src.source}>
36
+ 📄 {fileName}
37
+ </span>
38
+ <span className="source-badge">{percentage}% match</span>
39
+ </div>
40
+ );
41
+ })}
42
+ </div>
43
+ )}
44
+ </div>
45
+ );
46
+ };
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import { CheckCircle2 } from "lucide-react";
3
+ import { ToolCall } from "../types/chat";
4
+
5
+ interface ToolCallBadgeProps {
6
+ toolCalls?: ToolCall[];
7
+ }
8
+
9
+ export const ToolCallBadge: React.FC<ToolCallBadgeProps> = ({ toolCalls }) => {
10
+ if (!toolCalls || toolCalls.length === 0) return null;
11
+
12
+ return (
13
+ <div className="tool-call-chips-group">
14
+ {toolCalls.map((tc, idx) => {
15
+ let label = "Information retrieved";
16
+ if (tc.tool_name === "create_ticket") label = "Support ticket processed";
17
+ if (tc.tool_name === "get_customer") label = "Account verified";
18
+ if (tc.tool_name === "get_ticket") label = "Ticket status loaded";
19
+
20
+ return (
21
+ <div key={idx} className="tool-call-chip">
22
+ <CheckCircle2 size={12} className="tool-call-icon" />
23
+ <span>{label}</span>
24
+ </div>
25
+ );
26
+ })}
27
+ </div>
28
+ );
29
+ };