@clikvn/agent-widget-embedded 1.0.30-dev → 1.0.32-dev

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.
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
@@ -0,0 +1,59 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <code_scheme name="Project" version="173">
3
+ <HTMLCodeStyleSettings>
4
+ <option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
5
+ </HTMLCodeStyleSettings>
6
+ <JSCodeStyleSettings version="0">
7
+ <option name="FORCE_SEMICOLON_STYLE" value="true" />
8
+ <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
9
+ <option name="USE_DOUBLE_QUOTES" value="false" />
10
+ <option name="FORCE_QUOTE_STYlE" value="true" />
11
+ <option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
12
+ <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
13
+ <option name="SPACES_WITHIN_IMPORTS" value="true" />
14
+ </JSCodeStyleSettings>
15
+ <TypeScriptCodeStyleSettings version="0">
16
+ <option name="FORCE_SEMICOLON_STYLE" value="true" />
17
+ <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
18
+ <option name="USE_DOUBLE_QUOTES" value="false" />
19
+ <option name="FORCE_QUOTE_STYlE" value="true" />
20
+ <option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
21
+ <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
22
+ <option name="SPACES_WITHIN_IMPORTS" value="true" />
23
+ </TypeScriptCodeStyleSettings>
24
+ <VueCodeStyleSettings>
25
+ <option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
26
+ <option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
27
+ </VueCodeStyleSettings>
28
+ <codeStyleSettings language="HTML">
29
+ <option name="SOFT_MARGINS" value="80" />
30
+ <indentOptions>
31
+ <option name="INDENT_SIZE" value="2" />
32
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
33
+ <option name="TAB_SIZE" value="2" />
34
+ </indentOptions>
35
+ </codeStyleSettings>
36
+ <codeStyleSettings language="JavaScript">
37
+ <option name="SOFT_MARGINS" value="80" />
38
+ <indentOptions>
39
+ <option name="INDENT_SIZE" value="2" />
40
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
41
+ <option name="TAB_SIZE" value="2" />
42
+ </indentOptions>
43
+ </codeStyleSettings>
44
+ <codeStyleSettings language="TypeScript">
45
+ <option name="SOFT_MARGINS" value="80" />
46
+ <indentOptions>
47
+ <option name="INDENT_SIZE" value="2" />
48
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
49
+ <option name="TAB_SIZE" value="2" />
50
+ </indentOptions>
51
+ </codeStyleSettings>
52
+ <codeStyleSettings language="Vue">
53
+ <option name="SOFT_MARGINS" value="80" />
54
+ <indentOptions>
55
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
56
+ </indentOptions>
57
+ </codeStyleSettings>
58
+ </code_scheme>
59
+ </component>
@@ -0,0 +1,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="USE_PER_PROJECT_SETTINGS" value="true" />
4
+ </state>
5
+ </component>
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
5
+ </profile>
6
+ </component>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="EslintConfiguration">
4
+ <custom-configuration-file used="true" path="$PROJECT_DIR$/.eslintrc" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/clik-ai-chatbot-embedded.iml" filepath="$PROJECT_DIR$/.idea/clik-ai-chatbot-embedded.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="PrettierConfiguration">
4
+ <option name="myConfigurationMode" value="AUTOMATIC" />
5
+ </component>
6
+ </project>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
package/CLAUDE.md ADDED
@@ -0,0 +1,150 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ This is `@clikvn/agent-widget-embedded`, a React-based TypeScript library that creates an embeddable AI chatbot widget. The project builds a JavaScript library that can be imported and embedded into any website as a custom web component `<clik-agent-widget>`.
8
+
9
+ ## Development Commands
10
+
11
+ - `yarn dev` - Start development build with file watching using Rollup
12
+ - `yarn build` - Create production build
13
+ - `yarn lint` - Run ESLint on src directory
14
+ - `yarn lint:fix` - Run ESLint with auto-fix
15
+ - `yarn prettier` - Format all files with Prettier
16
+ - `yarn deploy` - Build and publish to npm with public access
17
+
18
+ ## Build System
19
+
20
+ The project uses **Rollup** as the primary build tool (not Webpack or Vite). Key configuration:
21
+ - Entry point: `src/web.ts` → outputs to `dist/web.js` as ESM module
22
+ - Custom web component registration system using `customElements.define()`
23
+ - Supports TypeScript, PostCSS with Tailwind, and React JSX
24
+ - Uses Terser for minification and production optimizations
25
+
26
+ ## Architecture
27
+
28
+ ### Core Entry Points
29
+ - `src/web.ts` - Main library entry point that exports the widget API
30
+ - `src/window.ts` - Contains `initWidget()` function and window object injection
31
+ - `src/register.tsx` - Web component registration and custom element definition
32
+ - `src/features/AgentWidget/index.tsx` - Main React component with providers
33
+
34
+ ### Component Structure
35
+ - **Custom Web Component**: `AgentWidgetComponent` class extends `HTMLElement`
36
+ - **React Integration**: Uses ReactDOM.render to mount React app inside web component
37
+ - **Provider Pattern**: Multiple context providers wrap the main Agent component:
38
+ - `ConfigurationProvider` - API host, agent ID, theme configuration
39
+ - `ChatDataProvider` - Chat state, suggested actions, event listeners
40
+ - `AudioMessagePlayerProvider` - Audio message playback functionality
41
+
42
+ ### Key Features
43
+ - **Voice Integration**: Built-in audio recording and playback with LiveKit support
44
+ - **Theming System**: Comprehensive theme configuration for messages, buttons, input placeholders
45
+ - **Event System**: Custom event listeners using `EVENT_TYPE` enum
46
+ - **Suggestion System**: Configurable suggested actions with grid/scroll layout modes
47
+
48
+ ## Code Conventions
49
+
50
+ ### TypeScript Configuration
51
+ - Strict mode enabled with comprehensive type checking
52
+ - Base configuration in `base.json`, extended by `tsconfig.json`
53
+ - Target: ES2015, Module: ESNext with React JSX transform
54
+
55
+ ### Code Style (enforced by ESLint + Prettier)
56
+ - Single quotes, semicolons required
57
+ - 2-space indentation, 80 character line width
58
+ - Trailing commas in ES5 contexts
59
+ - React hooks dependency warnings enabled
60
+ - Console usage limited to info/warn/error methods
61
+
62
+ ### File Organization
63
+ - `src/components/` - Reusable UI components (Agent/, Chat/)
64
+ - `src/hooks/` - Custom React hooks (useChat, useAudioRecording, etc.)
65
+ - `src/services/` - API layer and external service integrations
66
+ - `src/utils/` - Pure utility functions (audio, file handling, requests)
67
+ - `src/types/` - TypeScript type definitions
68
+ - `src/assets/` - Static assets and CSS
69
+
70
+ ## Styling
71
+
72
+ Uses **TailwindCSS** with custom configuration:
73
+ - Font family: "Be Vietnam Pro" for both sans and mono
74
+ - Custom rem-to-px conversion function for precise sizing
75
+ - Dark mode support via class strategy
76
+ - Includes Tailwind Typography and Animate plugins
77
+
78
+ ## Testing
79
+
80
+ This project does not appear to have a configured test framework. When adding tests, check the existing setup or ask the user for the preferred testing approach.
81
+
82
+ ## Package Management
83
+
84
+ Uses **Yarn** as the package manager (yarn.lock present). Always use `yarn` instead of `npm` for consistency.
85
+
86
+ ## Browser Support
87
+
88
+ Configured for modern browsers:
89
+ - Production: >0.2% usage, not dead, not Opera Mini
90
+ - Development: Latest Chrome, Firefox, Safari versions
91
+ - Minimum Node.js version: 18.18.0
92
+
93
+ ## Development Guidelines
94
+
95
+ ### Component Development
96
+ - Follow the existing provider pattern for state management
97
+ - Use TypeScript interfaces for all props and component types
98
+ - Implement proper error boundaries for chat components
99
+ - Components should be responsive and work within the widget constraints
100
+
101
+ ### Tool Integration
102
+ - **Command Tools**: Tools that trigger UI actions should be added to `isCommandTool()` in `src/components/Chat/Message.tsx`
103
+ - **Display Tools**: Tools that render content should be added to the custom tool results logic
104
+ - **Event System**: Use the `EVENT_TYPE` enum and listeners pattern for component communication
105
+
106
+ ### State Management Patterns
107
+ - Use React Context providers for shared state (Configuration, ChatData, AudioPlayer)
108
+ - Implement custom hooks for complex state logic (useChat, useAudioRecording)
109
+ - Keep component state minimal and lift state up when needed
110
+
111
+ ### API Integration
112
+ - All API calls should go through the services layer (`src/services/`)
113
+ - Use proper error handling and loading states
114
+ - Implement request utilities for consistent API interaction patterns
115
+
116
+ ### Styling Guidelines
117
+ - Use TailwindCSS classes for all styling
118
+ - Follow the existing color and spacing conventions
119
+ - Implement responsive design using Tailwind's responsive prefixes
120
+ - Use CSS-in-JS only when dynamic styling based on theme props is required
121
+
122
+ ### Audio/Voice Features
123
+ - Audio recording utilities are in `src/utils/audioRecording.ts`
124
+ - Use the AudioMessagePlayerProvider for playback functionality
125
+ - Implement proper permissions handling for microphone access
126
+ - Follow the existing patterns for LiveKit integration
127
+
128
+ ### Theme System
129
+ - Theme configuration is handled through the ConfigurationProvider
130
+ - Support both light and dark themes via CSS classes
131
+ - Use theme props for customizable colors, fonts, and layouts
132
+ - Maintain backward compatibility when adding new theme options
133
+
134
+ ### Testing Practices
135
+ - Since no test framework is configured, prefer manual testing during development
136
+ - Test widget integration in different environments (various websites)
137
+ - Verify responsive behavior across different screen sizes
138
+ - Test audio features with different browser permissions
139
+
140
+ ### Performance Considerations
141
+ - The widget is embedded in external websites, so bundle size matters
142
+ - Use dynamic imports for heavy features when possible
143
+ - Implement proper loading states for async operations
144
+ - Optimize images and assets for web delivery
145
+
146
+ ### Error Handling
147
+ - Implement graceful degradation for failed API calls
148
+ - Provide meaningful error messages to users
149
+ - Log errors appropriately for debugging (console.error/warn allowed)
150
+ - Handle network connectivity issues gracefully
@@ -1 +1 @@
1
- {"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../../src/components/Chat/Message.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAsB,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EACL,eAAe,EAGhB,MAAM,0BAA0B,CAAC;AAalC,KAAK,SAAS,GAAG;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,eAAe,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAUF,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,SAAS,CA0QxC,CAAC;AAEF,eAAO,MAAM,eAAe,YAAa;IAAE,GAAG,EAAE,OAAO,GAAG,IAAI,CAAA;CAAE,4CAyC/D,CAAC"}
1
+ {"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../../src/components/Chat/Message.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAsB,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EACL,eAAe,EAGhB,MAAM,0BAA0B,CAAC;AAalC,KAAK,SAAS,GAAG;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,eAAe,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAUF,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,SAAS,CAwRxC,CAAC;AAEF,eAAO,MAAM,eAAe,YAAa;IAAE,GAAG,EAAE,OAAO,GAAG,IAAI,CAAA;CAAE,4CAyC/D,CAAC"}
package/dist/index.html CHANGED
@@ -1,46 +1,40 @@
1
- <!doctype html>
1
+ <!DOCTYPE html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <!-- <meta charset="UTF-8" /> -->
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Clik Agent Widget - Dev</title>
8
- <script type="module">
9
- import Agent from 'http://localhost:3000/web.js'; // Change to from './web.js' to 'https://localhost:5678/web.js'
10
- Agent.initWidget({
11
- apiHost: 'https://ci-api.clik.vn/chatbot',
12
- agentId: 'fe4cf6a9-fa43-4986-bc6f-df67092568c6',
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title></title>
6
+ <style>
7
+ clik-agent-widget {
8
+ display: block;
9
+ height: 100vh;
10
+ }
11
+ </style>
12
+ <script type="module">
13
+ import Agent from 'http://localhost:3000/web.js'; // Change to from './web.js' to 'https://localhost:5678/web.js'
14
+ Agent.initWidget({
15
+ apiHost: 'https://ci-api.clik.vn/chatbot',
16
+ agentId: '697a9f37-2ed6-4d90-b540-6682eabdc5eb',
17
+ overrideConfig: {
18
+ chatId: 'e13e4df8-4e30-41e0-9df3-b0337feec6ee',
13
19
  overrideConfig: {
14
- chatId: 'f6a855d2-7edc-4fb8-9dd3-74204aa1e2a2',
15
- skipSuggestion: true,
16
- overrideConfig: {
17
- vars: {
18
- TOUR_CODE: 'TOUR_K9EK76KTX7K4',
19
- LANGUAGE: 'VN',
20
- CLIK_GRAPHQL_API: 'https://api.clik.vn/graphql',
21
- CLIK_VIRTUALTOUR_API: 'https://api.clik.vn/vt360',
22
- },
23
- },
20
+ vars: {
21
+ SHOWROOM_CODE: 'SHOWROOM_5Z7G1H9X1X1X4',
22
+ TOUR_CODE: 'TOUR_K9EK76KTX7K4',
23
+ LANGUAGE: 'VN',
24
+ CLIK_GRAPHQL_API: 'https://ci-api.clik.vn/graphql',
25
+ CLIK_VIRTUALTOUR_API: 'https://ci-api.clik.vn/vt360',
26
+ BRAND_API: 'https://ci-api.clik.vn/showroom',
27
+ }
24
28
  },
25
- listeners: {
26
- ON_LINK_CLICK: console.log,
27
- },
28
- theme: {
29
- // simplified: true,
30
- autoCloseAudioPlayer: true,
31
- hideAudioMetadata: true,
32
- modeButtonChat: true,
33
- gapInput: 30,
34
- },
35
- onLoaded: (tool) => {
36
- window.tool = tool;
37
- },
38
- });
39
- </script>
40
- </head>
41
- <body>
42
- <div style="width: 100vw; height: 100vh">
43
- <clik-agent-widget></clik-agent-widget>
44
- </div>
45
- </body>
46
- </html>
29
+ },
30
+ listeners: {
31
+ ON_LINK_CLICK: console.log
32
+ }
33
+ });
34
+ </script>
35
+
36
+ </head>
37
+ <body>
38
+ <clik-agent-widget></clik-agent-widget>
39
+ </body>
40
+ </html>