@kaifusion/widget 1.0.6 → 1.0.8

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/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@kaifusion/widget",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "type": "module",
5
- "main": "./dist/index.es.js",
5
+ "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.es.js",
7
+ "style": "./dist/style.css",
7
8
  "types": "./dist/index.d.ts",
8
9
  "files": [
9
10
  "dist",
@@ -11,10 +12,12 @@
11
12
  ],
12
13
  "exports": {
13
14
  ".": {
15
+ "style": "./dist/style.css",
14
16
  "types": "./dist/index.d.ts",
15
17
  "import": "./dist/index.es.js",
16
- "require": "./dist/index.es.js"
17
- }
18
+ "require": "./dist/index.cjs"
19
+ },
20
+ "./dist/style.css": "./dist/style.css"
18
21
  },
19
22
  "scripts": {
20
23
  "dev": "vite",
@@ -50,6 +53,7 @@
50
53
  "tailwindcss": "^4.1.4",
51
54
  "typescript": "^5.8.3",
52
55
  "vite": "^6.3.3",
53
- "vite-plugin-dts": "^3.7.0"
56
+ "vite-plugin-dts": "^3.7.0",
57
+ "vite-plugin-lib-inject-css": "^2.2.2"
54
58
  }
55
59
  }
@@ -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}/api/v1/auth/me`, {
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}/api/v1/workflows/execute`, {
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
- position === "left" ? "left-5" : "right-5"
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
- isMaximized
287
- ? "fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 m-0"
288
- : "relative"
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 ? "justify-start" : "justify-end"
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.isBot
335
- ? msg.isError
336
- ? "bg-red-50 text-red-600 border border-red-100"
337
- : "bg-white text-gray-800 border border-gray-100"
338
- : "text-white"
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
- !msg.isBot ? "text-white" : "text-gray-700"
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
- !msg.isBot ? "text-white" : "text-gray-700"
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
- !msg.isBot ? "text-white" : "text-gray-700"
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
- !msg.isBot ? "text-white" : "text-gray-900"
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
- !msg.isBot ? "text-white/90" : "text-gray-600"
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 className="flex gap-2 items-center bg-gray-50 rounded-full px-4 py-2 border border-gray-200 focus-within:border-blue-500 focus-within:ring-1 focus-within:ring-blue-500 transition-all">
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
- input.trim() && !isLoading
708
- ? "text-blue-600 hover:bg-blue-50"
709
- : "text-gray-400"
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
- tokenError ? "border-red-500" : "border-gray-300"
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();
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
+ import "./index.css";
1
2
  export { default as KaiChatWidget } from "./KaiChatWidget";
2
3
  export type { KaiChatWidgetProps } from "./KaiChatWidget";