@han_zzpw/chatbot 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 (40) hide show
  1. package/README.md +154 -0
  2. package/dist/chat-library.es.js +25120 -0
  3. package/dist/chat-library.umd.js +41 -0
  4. package/dist/components/ChatBot.d.ts +7 -0
  5. package/dist/components/ChatInput.d.ts +17 -0
  6. package/dist/components/ChatStreaming.d.ts +8 -0
  7. package/dist/components/ChatTyping.d.ts +1 -0
  8. package/dist/components/Icons/CameraIcon.d.ts +6 -0
  9. package/dist/components/Icons/CancelIcon.d.ts +7 -0
  10. package/dist/components/Icons/CheckIcon.d.ts +7 -0
  11. package/dist/components/Icons/CloseIcon.d.ts +7 -0
  12. package/dist/components/Icons/ImageUploadIcon.d.ts +1 -0
  13. package/dist/components/Icons/LeftArrowIcon.d.ts +6 -0
  14. package/dist/components/Icons/RightArrowIcon.d.ts +6 -0
  15. package/dist/components/Icons/SendIcon.d.ts +7 -0
  16. package/dist/components/Icons/ShoppingIcon.d.ts +6 -0
  17. package/dist/components/Icons/SpinnerIcon.d.ts +6 -0
  18. package/dist/components/Icons/TrashIcon.d.ts +6 -0
  19. package/dist/components/Icons/UploadIcon.d.ts +6 -0
  20. package/dist/components/Icons/VoiceIcon.d.ts +6 -0
  21. package/dist/components/MessageBubble.d.ts +11 -0
  22. package/dist/components/ThinkingBlock.d.ts +6 -0
  23. package/dist/components/ToolBlock/ExpandableHeader.d.ts +8 -0
  24. package/dist/components/ToolBlock/ImageGrid.d.ts +16 -0
  25. package/dist/components/ToolBlock/ImageTool.d.ts +13 -0
  26. package/dist/components/ToolBlock/ProcessingSpinner.d.ts +6 -0
  27. package/dist/components/ToolBlock/index.d.ts +4 -0
  28. package/dist/components/ToolBlock.d.ts +9 -0
  29. package/dist/components/WavelensConfigModal.d.ts +12 -0
  30. package/dist/components/atoms/ImageModal.d.ts +9 -0
  31. package/dist/components/atoms/InputUnderline.d.ts +5 -0
  32. package/dist/components/atoms/LoadingSpinner.d.ts +1 -0
  33. package/dist/components/atoms/MultimediaInput.d.ts +10 -0
  34. package/dist/components/atoms/TextInput.d.ts +10 -0
  35. package/dist/hooks/useSpeechRecognition.d.ts +11 -0
  36. package/dist/index.d.ts +15 -0
  37. package/dist/types/index.d.ts +97 -0
  38. package/dist/utils/api-helper.d.ts +2 -0
  39. package/dist/utils/stream-parser.d.ts +8 -0
  40. package/package.json +57 -0
@@ -0,0 +1,7 @@
1
+ import type { ChatConfig } from "../types";
2
+ interface ChatBotProps extends ChatConfig {
3
+ title?: string;
4
+ className?: string;
5
+ }
6
+ export declare const ChatBot: ({ token, apiEndpoint: _apiEndpoint, headers, title, className, }: ChatBotProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { Answer } from "../types";
2
+ interface ChatInputProps {
3
+ input: string;
4
+ setInput: (input: string) => void;
5
+ files: File[];
6
+ setFiles: (files: File[]) => void;
7
+ onSendMessage: (message: string, files?: File[], wavelensConfig?: {
8
+ biomarkers: string[];
9
+ bodyPart: string;
10
+ language: string;
11
+ }) => void;
12
+ onCancelMessage: () => void;
13
+ disabled: boolean;
14
+ lastAnswer?: Answer | null;
15
+ }
16
+ export declare const ChatInput: ({ input, setInput, files, setFiles, onSendMessage, onCancelMessage, disabled, lastAnswer, }: ChatInputProps) => import("react/jsx-runtime").JSX.Element;
17
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { StreamingEvent } from "../types";
2
+ interface ChatStreamingProps {
3
+ events: StreamingEvent[];
4
+ isStreaming?: boolean;
5
+ token?: string;
6
+ }
7
+ export declare const ChatStreaming: ({ events, isStreaming, token, }: ChatStreamingProps) => import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1 @@
1
+ export declare const ChatTyping: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,6 @@
1
+ interface CameraIconProps {
2
+ size?: number;
3
+ color?: string;
4
+ }
5
+ export declare const CameraIcon: ({ size, color, }: CameraIconProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,7 @@
1
+ interface Props {
2
+ color?: string;
3
+ size?: number;
4
+ fillOpacity?: string;
5
+ }
6
+ export default function CancelIcon({ color, size, fillOpacity, }: Props): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,7 @@
1
+ interface CheckIconProps {
2
+ size?: number;
3
+ color?: string;
4
+ opacity?: string;
5
+ }
6
+ export declare const CheckIcon: ({ size, color, opacity, }: CheckIconProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,7 @@
1
+ interface CloseIconProps {
2
+ size?: number;
3
+ color?: string;
4
+ fillOpacity?: string;
5
+ }
6
+ export declare const CloseIcon: ({ size, color, fillOpacity, }: CloseIconProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1 @@
1
+ export declare const ImageUploadIcon: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,6 @@
1
+ interface LeftArrowIconProps {
2
+ size?: number;
3
+ color?: string;
4
+ }
5
+ export declare const LeftArrowIcon: ({ size, color, }: LeftArrowIconProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,6 @@
1
+ interface RightArrowIconProps {
2
+ size?: number;
3
+ color?: string;
4
+ }
5
+ export declare const RightArrowIcon: ({ size, color, }: RightArrowIconProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,7 @@
1
+ interface Props {
2
+ color?: string;
3
+ size?: number;
4
+ fillOpacity?: string;
5
+ }
6
+ export default function SendIcon({ color, size, fillOpacity, }: Props): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,6 @@
1
+ interface ShoppingIconProps {
2
+ size?: number;
3
+ color?: string;
4
+ }
5
+ export declare const ShoppingIcon: ({ size, color, }: ShoppingIconProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,6 @@
1
+ interface SpinnerIconProps {
2
+ size?: number;
3
+ color?: "slate" | "amber";
4
+ }
5
+ export declare const SpinnerIcon: ({ size, color, }: SpinnerIconProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,6 @@
1
+ interface TrashIconProps {
2
+ size?: number;
3
+ color?: string;
4
+ }
5
+ export declare const TrashIcon: ({ size, color }: TrashIconProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,6 @@
1
+ interface UploadIconProps {
2
+ size?: number;
3
+ color?: string;
4
+ }
5
+ export declare const UploadIcon: ({ size, color, }: UploadIconProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,6 @@
1
+ interface VoiceIconProps {
2
+ size?: number;
3
+ color?: string;
4
+ }
5
+ export declare const VoiceIcon: ({ size, color }: VoiceIconProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { Question, Answer } from "../types";
2
+ interface ChatQuestionProps {
3
+ question: Question;
4
+ }
5
+ export declare const ChatQuestion: ({ question }: ChatQuestionProps) => import("react/jsx-runtime").JSX.Element;
6
+ interface ChatAnswerProps {
7
+ answer: Answer;
8
+ token?: string;
9
+ }
10
+ export declare const ChatAnswer: ({ answer, token }: ChatAnswerProps) => import("react/jsx-runtime").JSX.Element;
11
+ export { ChatQuestion as MessageQuestion, ChatAnswer as MessageAnswer };
@@ -0,0 +1,6 @@
1
+ import type { ThinkingBlockData } from "../types";
2
+ interface ThinkingBlockProps {
3
+ block: ThinkingBlockData;
4
+ }
5
+ export declare const ThinkingBlock: ({ block }: ThinkingBlockProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,8 @@
1
+ interface ExpandableHeaderProps {
2
+ isExpanded: boolean;
3
+ onClick: () => void;
4
+ children: React.ReactNode;
5
+ showArrow?: boolean;
6
+ }
7
+ export declare const ExpandableHeader: ({ isExpanded, onClick, children, showArrow, }: ExpandableHeaderProps) => import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,16 @@
1
+ interface ImageData {
2
+ url: string;
3
+ name: string;
4
+ }
5
+ interface ImageGridProps {
6
+ inputImage: ImageData;
7
+ outputImage?: ImageData;
8
+ isProcessing: boolean;
9
+ inputImageLoaded: boolean;
10
+ outputImageLoaded: boolean;
11
+ onInputLoad: () => void;
12
+ onOutputLoad: () => void;
13
+ onImageClick: (url: string) => void;
14
+ }
15
+ export declare const ImageGrid: ({ inputImage, outputImage, isProcessing, inputImageLoaded, outputImageLoaded, onInputLoad, onOutputLoad, onImageClick, }: ImageGridProps) => import("react/jsx-runtime").JSX.Element;
16
+ export {};
@@ -0,0 +1,13 @@
1
+ interface ImageData {
2
+ url: string;
3
+ name: string;
4
+ }
5
+ interface ImageToolProps {
6
+ image: ImageData;
7
+ title: string;
8
+ onClick: (url: string) => void;
9
+ isLoaded: boolean;
10
+ onLoad: () => void;
11
+ }
12
+ export declare const ImageTool: ({ image, title, onClick, isLoaded, onLoad, }: ImageToolProps) => import("react/jsx-runtime").JSX.Element;
13
+ export {};
@@ -0,0 +1,6 @@
1
+ interface ProcessingSpinnerProps {
2
+ title: string;
3
+ subtitle: string;
4
+ }
5
+ export declare const ProcessingSpinner: ({ title, subtitle, }: ProcessingSpinnerProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,4 @@
1
+ export { ExpandableHeader } from "./ExpandableHeader";
2
+ export { ImageGrid } from "./ImageGrid";
3
+ export { ImageTool } from "./ImageTool";
4
+ export { ProcessingSpinner } from "./ProcessingSpinner";
@@ -0,0 +1,9 @@
1
+ import type { ToolBlockData } from "../types";
2
+ interface ToolBlockProps {
3
+ tool: ToolBlockData;
4
+ token?: string;
5
+ /** API base URL for tool integrations */
6
+ toolApiBaseUrl?: string;
7
+ }
8
+ export declare const ToolBlock: ({ tool, token, toolApiBaseUrl }: ToolBlockProps) => import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,12 @@
1
+ interface WavelensConfigModalProps {
2
+ isOpen: boolean;
3
+ onClose: () => void;
4
+ onConfirm: (config: {
5
+ biomarkers: string[];
6
+ bodyPart: string;
7
+ language: string;
8
+ }) => void;
9
+ imagePreview?: string;
10
+ }
11
+ export declare const WavelensConfigModal: ({ isOpen, onClose, onConfirm, imagePreview, }: WavelensConfigModalProps) => import("react").ReactPortal | null;
12
+ export {};
@@ -0,0 +1,9 @@
1
+ interface ImageModalProps {
2
+ isOpen: boolean;
3
+ imageUrl: string;
4
+ imageUrls?: string[];
5
+ initialIndex?: number;
6
+ onClose: () => void;
7
+ }
8
+ export declare const ImageModal: ({ isOpen, imageUrl, imageUrls, initialIndex, onClose, }: ImageModalProps) => import("react").ReactPortal | null;
9
+ export {};
@@ -0,0 +1,5 @@
1
+ interface InputUnderlineProps {
2
+ isInvalid?: boolean;
3
+ }
4
+ export declare const InputUnderline: ({ isInvalid }: InputUnderlineProps) => import("react/jsx-runtime").JSX.Element;
5
+ export {};
@@ -0,0 +1 @@
1
+ export declare const LoadingSpinner: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { DeviceInputType } from "../../types";
2
+ interface MultimediaInputProps {
3
+ files: File[];
4
+ setFiles: (files: File[]) => void;
5
+ disabled: boolean;
6
+ onSkip: () => void;
7
+ type: DeviceInputType;
8
+ }
9
+ export declare const MultimediaInput: ({ files, setFiles, disabled, onSkip, type, }: MultimediaInputProps) => import("react/jsx-runtime").JSX.Element;
10
+ export { DeviceInputType };
@@ -0,0 +1,10 @@
1
+ interface TextInputProps {
2
+ input: string;
3
+ setInput: (input: string) => void;
4
+ handleSend: () => void;
5
+ disabled: boolean;
6
+ isListening?: boolean;
7
+ onImageUpload?: (file: File) => void;
8
+ }
9
+ export declare const TextInput: ({ input, setInput, handleSend, disabled, isListening, onImageUpload, }: TextInputProps) => import("react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1,11 @@
1
+ interface UseSpeechRecognitionReturn {
2
+ transcript: string;
3
+ isListening: boolean;
4
+ startListening: () => Promise<void>;
5
+ stopListening: () => void;
6
+ resetTranscript: () => void;
7
+ isSupported: boolean;
8
+ error: string | null;
9
+ }
10
+ export declare const useSpeechRecognition: () => UseSpeechRecognitionReturn;
11
+ export {};
@@ -0,0 +1,15 @@
1
+ export * from "./types";
2
+ export * from "./hooks/useSpeechRecognition";
3
+ export * from "./utils/stream-parser";
4
+ export * from "./components/ThinkingBlock";
5
+ export * from "./components/ToolBlock";
6
+ export * from "./components/ChatInput";
7
+ export * from "./components/MessageBubble";
8
+ export * from "./components/ChatBot";
9
+ export * from "./components/ChatTyping";
10
+ export * from "./components/ChatStreaming";
11
+ export * from "./components/WavelensConfigModal";
12
+ export * from "./components/atoms/ImageModal";
13
+ export * from "./components/atoms/TextInput";
14
+ export * from "./components/atoms/MultimediaInput";
15
+ export * from "./components/atoms/InputUnderline";
@@ -0,0 +1,97 @@
1
+ export interface ThinkingBlockData {
2
+ id: string;
3
+ state: "thinking" | "completed";
4
+ content?: string;
5
+ duration?: number;
6
+ }
7
+ export interface ToolBlockData {
8
+ id: string;
9
+ toolName: string;
10
+ state: "executing" | "completed" | "preparing" | "waiting_user";
11
+ content?: string;
12
+ parameters?: {
13
+ biomarkers?: string[];
14
+ instructions?: string;
15
+ };
16
+ results?: {
17
+ documents_found?: number;
18
+ chunks_found?: number;
19
+ query?: string;
20
+ input?: {
21
+ url: string;
22
+ name: string;
23
+ };
24
+ output?: {
25
+ url: string;
26
+ name: string;
27
+ };
28
+ };
29
+ }
30
+ export type StreamingEvent = {
31
+ type: "data";
32
+ content: string;
33
+ } | {
34
+ type: "thinking";
35
+ data: ThinkingBlockData;
36
+ } | {
37
+ type: "tool";
38
+ data: ToolBlockData;
39
+ };
40
+ export declare enum DeviceFamily {
41
+ BINAH_AI = "binah",
42
+ EXTERNAL = "use_devices",
43
+ CAMERA = "camera_checkups",
44
+ UPLOAD_MEDICAL_CONTENT = "upload_content"
45
+ }
46
+ export declare enum DeviceInputType {
47
+ SENSOR = "sensor",
48
+ FILE_UPLOAD = "file-upload",
49
+ CAMERA = "camera",
50
+ TEXT = "text",
51
+ IMAGE = "image",
52
+ VIDEO = "video",
53
+ PDF = "pdf",
54
+ JSON = "json",
55
+ CSV = "csv",
56
+ COMPRESSED_FILE = "compressed_file",
57
+ ANY = "any",
58
+ NONE = "none",
59
+ ZIP = "application/x-zip-compressed"
60
+ }
61
+ export interface Device {
62
+ id: string;
63
+ title: string;
64
+ description: string;
65
+ inputType: DeviceInputType;
66
+ family: DeviceFamily;
67
+ buttonText: string;
68
+ imageUrl: string;
69
+ }
70
+ export interface Question {
71
+ id: string;
72
+ question: string;
73
+ files?: File[];
74
+ }
75
+ export interface Answer {
76
+ prev_answer: string;
77
+ prev_question: string;
78
+ answer: string;
79
+ use_device: boolean;
80
+ device?: Device;
81
+ files?: {
82
+ name: string;
83
+ url: string;
84
+ }[];
85
+ streamingEvents?: StreamingEvent[];
86
+ }
87
+ export interface ChatConfig {
88
+ token: string;
89
+ /**
90
+ * Kept for backward-compatibility.
91
+ * The library now uses the original chatbot behavior and calls the hardcoded endpoint `/v1/chatbot/chat`.
92
+ */
93
+ apiEndpoint?: string;
94
+ headers?: Record<string, string>;
95
+ /** Optional API base URL for tool integrations (e.g., hyperspectral analysis) */
96
+ toolApiBaseUrl?: string;
97
+ }
@@ -0,0 +1,2 @@
1
+ export declare const getApiUrl: () => string;
2
+ export declare const verifyApiKey: (apiKey: string, baseUrl?: string) => Promise<any>;
@@ -0,0 +1,8 @@
1
+ export interface StreamCallbacks {
2
+ onData?: (content: string, isFinal: boolean) => void;
3
+ onThinking?: (thinkingId: string, state: "started" | "completed", content?: string, duration?: number) => void;
4
+ onTool?: (toolId: string, toolName: string, state: "executing" | "completed" | "preparing" | "waiting_user", content?: string, results?: any, parameters?: any) => void;
5
+ onConversationId?: (conversationId: string) => void;
6
+ onError?: (error: any) => void;
7
+ }
8
+ export declare function parseChatStream(response: Response, callbacks: StreamCallbacks): Promise<void>;
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "scripts": {
3
+ "dev": "vite",
4
+ "build:app": "tsc && vite build",
5
+ "build:lib": "vite build --mode library && tsc -p tsconfig.lib.json",
6
+ "build": "npm run build:app && npm run build:lib",
7
+ "preview": "vite preview"
8
+ },
9
+ "name": "@han_zzpw/chatbot",
10
+ "version": "1.0.0",
11
+ "description": "A standalone React chatbot component library with streaming support, speech recognition, and markdown rendering",
12
+ "type": "module",
13
+ "main": "./dist/chat-library.umd.js",
14
+ "module": "./dist/chat-library.es.js",
15
+ "types": "./dist/index.d.ts",
16
+ "license": "MIT",
17
+ "keywords": [
18
+ "react",
19
+ "chatbot",
20
+ "streaming",
21
+ "speech-recognition",
22
+ "markdown",
23
+ "ai",
24
+ "chat"
25
+ ],
26
+ "peerDependencies": {
27
+ "react": ">=18.0.0",
28
+ "react-dom": ">=18.0.0"
29
+ },
30
+ "dependencies": {
31
+ "react-markdown": "^10.1.0",
32
+ "rehype-highlight": "^7.0.2",
33
+ "remark-gfm": "^4.0.1"
34
+ },
35
+ "devDependencies": {
36
+ "@tailwindcss/postcss": "^4.1.18",
37
+ "@types/react": "^18.2.14",
38
+ "@types/react-dom": "^18.2.7",
39
+ "@vitejs/plugin-react": "^5.1.2",
40
+ "autoprefixer": "^10.4.23",
41
+ "postcss": "^8.5.6",
42
+ "tailwindcss": "^4.1.18",
43
+ "typescript": "^5",
44
+ "vite": "^7.3.0"
45
+ },
46
+ "exports": {
47
+ ".": {
48
+ "types": "./dist/index.d.ts",
49
+ "import": "./dist/chat-library.es.js",
50
+ "require": "./dist/chat-library.umd.js"
51
+ },
52
+ "./style.css": "./dist/chatbot.css"
53
+ },
54
+ "files": [
55
+ "dist"
56
+ ]
57
+ }