@kaifusion/widget 1.0.6 → 1.0.7
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/README.md +2 -2
- package/dist/index.cjs +12 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.es.js +15200 -0
- package/dist/index.es.js.map +1 -0
- package/package.json +3 -3
- package/src/KaiChatWidget.tsx +47 -47
- package/src/config.ts +27 -0
- package/dist/widget.iife.js +0 -452
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaifusion/widget",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "./dist/index.
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
".": {
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"import": "./dist/index.es.js",
|
|
16
|
-
"require": "./dist/index.
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
package/src/KaiChatWidget.tsx
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
} from "lucide-react";
|
|
25
25
|
import { motion, AnimatePresence } from "motion/react";
|
|
26
26
|
import { v4 as uuidv4 } from "uuid";
|
|
27
|
+
import { config } from "./config";
|
|
27
28
|
|
|
28
29
|
interface Message {
|
|
29
30
|
id: string;
|
|
@@ -69,9 +70,9 @@ export default function KaiChatWidget({
|
|
|
69
70
|
);
|
|
70
71
|
const [isTokenValidating, setIsTokenValidating] = useState(false);
|
|
71
72
|
const [tokenError, setTokenError] = useState<string | null>(null);
|
|
73
|
+
const [isInputFocused, setIsInputFocused] = useState(false);
|
|
72
74
|
|
|
73
75
|
const effectiveToken = authToken || userProvidedToken;
|
|
74
|
-
|
|
75
76
|
const handleTokenSubmit = async (token: string) => {
|
|
76
77
|
if (!token.trim() || isTokenValidating) return;
|
|
77
78
|
|
|
@@ -79,7 +80,7 @@ export default function KaiChatWidget({
|
|
|
79
80
|
setTokenError(null);
|
|
80
81
|
|
|
81
82
|
try {
|
|
82
|
-
const response = await fetch(`${targetUrl}/
|
|
83
|
+
const response = await fetch(`${targetUrl}/${config.API_START}/${config.API_VERSION_ONLY}/auth/me`, {
|
|
83
84
|
headers: {
|
|
84
85
|
Authorization: `Bearer ${token}`,
|
|
85
86
|
},
|
|
@@ -156,7 +157,7 @@ export default function KaiChatWidget({
|
|
|
156
157
|
headers["X-API-Key"] = token;
|
|
157
158
|
}
|
|
158
159
|
|
|
159
|
-
const response = await fetch(`${targetUrl}/
|
|
160
|
+
const response = await fetch(`${targetUrl}/${config.API_START}/${config.API_VERSION_ONLY}/workflows/execute`, {
|
|
160
161
|
method: "POST",
|
|
161
162
|
headers,
|
|
162
163
|
body: JSON.stringify({
|
|
@@ -251,9 +252,8 @@ export default function KaiChatWidget({
|
|
|
251
252
|
|
|
252
253
|
return (
|
|
253
254
|
<div
|
|
254
|
-
className={`fixed bottom-5 z-50 flex flex-col items-end gap-4 font-sans ${
|
|
255
|
-
|
|
256
|
-
}`}
|
|
255
|
+
className={`fixed bottom-5 z-50 flex flex-col items-end gap-4 font-sans ${position === "left" ? "left-5" : "right-5"
|
|
256
|
+
}`}
|
|
257
257
|
style={{ fontFamily: "system-ui, -apple-system, sans-serif" }}
|
|
258
258
|
>
|
|
259
259
|
{/* Overlay - Tam Ekran Modu İçin */}
|
|
@@ -282,11 +282,10 @@ export default function KaiChatWidget({
|
|
|
282
282
|
height: isMaximized ? "85vh" : "600px",
|
|
283
283
|
}}
|
|
284
284
|
exit={{ opacity: 0, y: 20, scale: 0.95 }}
|
|
285
|
-
className={`rounded-2xl shadow-2xl flex flex-col overflow-hidden z-50 transition-all duration-300 ${
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}`}
|
|
285
|
+
className={`rounded-2xl shadow-2xl flex flex-col overflow-hidden z-50 transition-all duration-300 ${isMaximized
|
|
286
|
+
? "fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 m-0"
|
|
287
|
+
: "relative"
|
|
288
|
+
}`}
|
|
290
289
|
>
|
|
291
290
|
{/* Header */}
|
|
292
291
|
<div
|
|
@@ -323,20 +322,17 @@ export default function KaiChatWidget({
|
|
|
323
322
|
{messages.map((msg) => (
|
|
324
323
|
<div
|
|
325
324
|
key={msg.id}
|
|
326
|
-
className={`flex ${
|
|
327
|
-
msg.isBot ? "
|
|
328
|
-
|
|
329
|
-
msg.isBot && !msg.content && !msg.isError ? "hidden" : ""
|
|
330
|
-
}`}
|
|
325
|
+
className={`flex ${msg.isBot ? "justify-start" : "justify-end"
|
|
326
|
+
} ${msg.isBot && !msg.content && !msg.isError ? "hidden" : ""
|
|
327
|
+
}`}
|
|
331
328
|
>
|
|
332
329
|
<div
|
|
333
|
-
className={`max-w-[85%] rounded-2xl px-4 py-3 shadow-sm ${
|
|
334
|
-
msg.
|
|
335
|
-
?
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}`}
|
|
330
|
+
className={`max-w-[85%] rounded-2xl px-4 py-3 shadow-sm ${msg.isBot
|
|
331
|
+
? msg.isError
|
|
332
|
+
? "bg-red-50 text-red-600 border border-red-100"
|
|
333
|
+
: "bg-white text-gray-800 border border-gray-100"
|
|
334
|
+
: "text-white"
|
|
335
|
+
}`}
|
|
340
336
|
style={!msg.isBot ? { backgroundColor: color } : {}}
|
|
341
337
|
>
|
|
342
338
|
<div className="max-w-none break-words">
|
|
@@ -483,9 +479,8 @@ export default function KaiChatWidget({
|
|
|
483
479
|
|
|
484
480
|
return isOrderedList ? (
|
|
485
481
|
<li
|
|
486
|
-
className={`flex items-start gap-2 pl-1 leading-relaxed ${
|
|
487
|
-
|
|
488
|
-
}`}
|
|
482
|
+
className={`flex items-start gap-2 pl-1 leading-relaxed ${!msg.isBot ? "text-white" : "text-gray-700"
|
|
483
|
+
}`}
|
|
489
484
|
>
|
|
490
485
|
<span className="flex-shrink-0 w-5 h-5 bg-gradient-to-r from-blue-500 to-purple-600 text-white rounded-full flex items-center justify-center text-[10px] font-bold mt-0.5 shadow-sm counter-increment">
|
|
491
486
|
•
|
|
@@ -496,9 +491,8 @@ export default function KaiChatWidget({
|
|
|
496
491
|
</li>
|
|
497
492
|
) : (
|
|
498
493
|
<li
|
|
499
|
-
className={`flex items-start gap-2 pl-1 leading-relaxed ${
|
|
500
|
-
|
|
501
|
-
}`}
|
|
494
|
+
className={`flex items-start gap-2 pl-1 leading-relaxed ${!msg.isBot ? "text-white" : "text-gray-700"
|
|
495
|
+
}`}
|
|
502
496
|
>
|
|
503
497
|
<span className="flex-shrink-0 w-1.5 h-1.5 bg-gradient-to-r from-blue-500 to-purple-600 rounded-full mt-2 shadow-sm"></span>
|
|
504
498
|
<div className="flex-1 text-left">
|
|
@@ -588,9 +582,8 @@ export default function KaiChatWidget({
|
|
|
588
582
|
// Paragraflar - daha iyi spacing
|
|
589
583
|
p: ({ children }: any) => (
|
|
590
584
|
<p
|
|
591
|
-
className={`m-0! last:mb-0 leading-relaxed break-words overflow-wrap-anywhere text-sm ${
|
|
592
|
-
|
|
593
|
-
}`}
|
|
585
|
+
className={`m-0! last:mb-0 leading-relaxed break-words overflow-wrap-anywhere text-sm ${!msg.isBot ? "text-white" : "text-gray-700"
|
|
586
|
+
}`}
|
|
594
587
|
>
|
|
595
588
|
{children}
|
|
596
589
|
</p>
|
|
@@ -599,18 +592,16 @@ export default function KaiChatWidget({
|
|
|
599
592
|
// Vurgu metinleri
|
|
600
593
|
strong: ({ children }: any) => (
|
|
601
594
|
<strong
|
|
602
|
-
className={`font-bold inline ${
|
|
603
|
-
|
|
604
|
-
}`}
|
|
595
|
+
className={`font-bold inline ${!msg.isBot ? "text-white" : "text-gray-900"
|
|
596
|
+
}`}
|
|
605
597
|
>
|
|
606
598
|
{children}
|
|
607
599
|
</strong>
|
|
608
600
|
),
|
|
609
601
|
em: ({ children }: any) => (
|
|
610
602
|
<em
|
|
611
|
-
className={`italic ${
|
|
612
|
-
|
|
613
|
-
}`}
|
|
603
|
+
className={`italic ${!msg.isBot ? "text-white/90" : "text-gray-600"
|
|
604
|
+
}`}
|
|
614
605
|
>
|
|
615
606
|
{children}
|
|
616
607
|
</em>
|
|
@@ -690,12 +681,20 @@ export default function KaiChatWidget({
|
|
|
690
681
|
{/* Input Alanı */}
|
|
691
682
|
{effectiveToken ? (
|
|
692
683
|
<div className="p-4 bg-white border-t border-gray-100">
|
|
693
|
-
<div
|
|
684
|
+
<div
|
|
685
|
+
className="flex gap-2 items-center bg-gray-50 rounded-full px-4 py-2 border border-gray-200 transition-all"
|
|
686
|
+
style={{
|
|
687
|
+
borderColor: isInputFocused ? color : undefined,
|
|
688
|
+
boxShadow: isInputFocused ? `0 0 0 1px ${color}` : undefined,
|
|
689
|
+
}}
|
|
690
|
+
>
|
|
694
691
|
<input
|
|
695
692
|
type="text"
|
|
696
693
|
value={input}
|
|
697
694
|
onChange={(e) => setInput(e.target.value)}
|
|
698
695
|
onKeyDown={(e) => e.key === "Enter" && sendMessage()}
|
|
696
|
+
onFocus={() => setIsInputFocused(true)}
|
|
697
|
+
onBlur={() => setIsInputFocused(false)}
|
|
699
698
|
placeholder="Mesajınızı yazın..."
|
|
700
699
|
className="flex-1 bg-transparent border-none focus:ring-0 outline-none text-sm py-1 text-black"
|
|
701
700
|
disabled={isLoading}
|
|
@@ -703,11 +702,13 @@ export default function KaiChatWidget({
|
|
|
703
702
|
<button
|
|
704
703
|
onClick={sendMessage}
|
|
705
704
|
disabled={isLoading || !input.trim()}
|
|
706
|
-
className={`p-2 rounded-full transition-all ${
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
705
|
+
className={`p-2 rounded-full transition-all ${input.trim() && !isLoading
|
|
706
|
+
? "hover:bg-gray-100"
|
|
707
|
+
: "text-gray-400"
|
|
708
|
+
}`}
|
|
709
|
+
style={{
|
|
710
|
+
color: input.trim() && !isLoading ? color : undefined,
|
|
711
|
+
}}
|
|
711
712
|
>
|
|
712
713
|
{isLoading ? (
|
|
713
714
|
<Loader2 className="w-5 h-5 animate-spin" />
|
|
@@ -732,9 +733,8 @@ export default function KaiChatWidget({
|
|
|
732
733
|
<input
|
|
733
734
|
type="password"
|
|
734
735
|
placeholder="Access Token"
|
|
735
|
-
className={`flex-1 px-4 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm text-gray-800 ${
|
|
736
|
-
|
|
737
|
-
}`}
|
|
736
|
+
className={`flex-1 px-4 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm text-gray-800 ${tokenError ? "border-red-500" : "border-gray-300"
|
|
737
|
+
}`}
|
|
738
738
|
disabled={isTokenValidating}
|
|
739
739
|
onKeyDown={(e) => {
|
|
740
740
|
if (e.key === "Enter") {
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Widget-specific configuration
|
|
2
|
+
// This is a standalone config for the widget package to avoid
|
|
3
|
+
// dependencies on the client package during Docker builds
|
|
4
|
+
|
|
5
|
+
export interface WidgetConfig {
|
|
6
|
+
API_START: string;
|
|
7
|
+
API_VERSION_ONLY: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Default values that can be overridden via props or window globals
|
|
11
|
+
const getWidgetConfig = (): WidgetConfig => {
|
|
12
|
+
// Check for window globals (for runtime configuration)
|
|
13
|
+
if (typeof window !== 'undefined') {
|
|
14
|
+
return {
|
|
15
|
+
API_START: (window as any).VITE_API_START || 'api',
|
|
16
|
+
API_VERSION_ONLY: (window as any).VITE_API_VERSION_ONLY || 'v1',
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Fallback defaults
|
|
21
|
+
return {
|
|
22
|
+
API_START: 'api',
|
|
23
|
+
API_VERSION_ONLY: 'v1',
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const config = getWidgetConfig();
|