@hexabot-ai/widget 3.0.0-alpha.3 → 3.1.1-alpha.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.
- package/AGENTS.md +197 -0
- package/README.md +8 -3
- package/dist/hexabot-widget.es.js +6893 -4852
- package/dist/hexabot-widget.umd.js +169 -11
- package/dist/style.css +1 -1
- package/package.json +10 -3
package/AGENTS.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Project Overview
|
|
2
|
+
`@hexabot-ai/widget` is the embeddable live chat widget for Hexabot. It is a React + TypeScript package bundled with Vite as a library (`dist/hexabot-widget.umd.js` + `dist/style.css`), intended to be dropped into external websites.
|
|
3
|
+
|
|
4
|
+
Typical agent work in this package includes:
|
|
5
|
+
- Updating chat UI components and styles.
|
|
6
|
+
- Extending message rendering/types.
|
|
7
|
+
- Adjusting provider logic (config, socket, settings, translation, widget state).
|
|
8
|
+
- Maintaining the token-based theme system (`ThemeProvider`, CSS vars, light/dark palettes).
|
|
9
|
+
- Maintaining build/lint/typecheck configuration.
|
|
10
|
+
- Preparing package-level release/version changes.
|
|
11
|
+
|
|
12
|
+
## Repository Structure
|
|
13
|
+
Key paths in `packages/widget`:
|
|
14
|
+
- `src/ChatWidget.tsx`: Main exported widget entry (also Vite library entry).
|
|
15
|
+
- `src/UiChatWidget.tsx`: Alternate/customizable widget composition entry.
|
|
16
|
+
- `src/main.tsx`: Local dev/demo app entry for Vite.
|
|
17
|
+
- `src/components/`: UI building blocks (chat window, header, messages, launcher, buttons, icons).
|
|
18
|
+
- `src/providers/`: Context/state providers (`ConfigProvider`, `SocketProvider`, `ChatProvider`, `ThemeProvider`, etc.).
|
|
19
|
+
- `src/hooks/`: Reusable hooks (`useTranslation`, socket/broadcast hooks).
|
|
20
|
+
- `src/theme/`: Theme contracts, resolver logic, and CSS variable defaults.
|
|
21
|
+
- `src/test/`: Test setup files (Vitest/jsdom).
|
|
22
|
+
- `src/types/`: Core TS models (`config.types.ts`, `message.types.ts`, `state.types.ts`, etc.).
|
|
23
|
+
- `src/constants/`: Default config, color palettes, emoji data.
|
|
24
|
+
- `src/translations/`: Localized strings (`en`, `fr`).
|
|
25
|
+
- `src/utils/`: Utilities (socket client, storage helpers, file/text helpers).
|
|
26
|
+
- `public/`: Static files used by local/demo hosting (`public/index.html` includes a UMD embed example).
|
|
27
|
+
- `dist/`: Generated build artifacts. Do not edit manually.
|
|
28
|
+
- `package.json`: Scripts, dependencies, package metadata.
|
|
29
|
+
- `eslint.config.cjs` / `eslint.config-staged.cjs`: Lint rules.
|
|
30
|
+
- `.prettierrc`: Formatting defaults.
|
|
31
|
+
- `tsconfig*.json`: TypeScript config.
|
|
32
|
+
- `vite.config.ts`: Library bundling and externals config.
|
|
33
|
+
- `Dockerfile`: Containerized build/dev/serve flow.
|
|
34
|
+
|
|
35
|
+
## Setup & Dev Environment
|
|
36
|
+
Prerequisites:
|
|
37
|
+
- Node.js `^20.18.1` (see `engines`).
|
|
38
|
+
- PNPM workspace (`pnpm@9.12.0` at repo root).
|
|
39
|
+
|
|
40
|
+
Recommended setup from repo root:
|
|
41
|
+
```bash
|
|
42
|
+
pnpm install --frozen-lockfile
|
|
43
|
+
pnpm --filter @hexabot-ai/widget run dev
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Alternative (inside package):
|
|
47
|
+
```bash
|
|
48
|
+
cd packages/widget
|
|
49
|
+
pnpm run dev
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Local dev server runs on Vite default port `5173`.
|
|
53
|
+
|
|
54
|
+
## Build, Test & Run Commands
|
|
55
|
+
Run from repo root:
|
|
56
|
+
```bash
|
|
57
|
+
# Build distributable bundle
|
|
58
|
+
pnpm --filter @hexabot-ai/widget run build
|
|
59
|
+
|
|
60
|
+
# Type safety
|
|
61
|
+
pnpm --filter @hexabot-ai/widget run typecheck
|
|
62
|
+
|
|
63
|
+
# Lint
|
|
64
|
+
pnpm --filter @hexabot-ai/widget run lint
|
|
65
|
+
pnpm --filter @hexabot-ai/widget run lint:fix
|
|
66
|
+
|
|
67
|
+
# Unit tests
|
|
68
|
+
pnpm --filter @hexabot-ai/widget run test
|
|
69
|
+
|
|
70
|
+
# Preview / static serve
|
|
71
|
+
pnpm --filter @hexabot-ai/widget run preview
|
|
72
|
+
pnpm --filter @hexabot-ai/widget run serve
|
|
73
|
+
|
|
74
|
+
# Clean generated build
|
|
75
|
+
pnpm --filter @hexabot-ai/widget run clean
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Critical local gate before PR:
|
|
79
|
+
```bash
|
|
80
|
+
pnpm --filter @hexabot-ai/widget run typecheck && \
|
|
81
|
+
pnpm --filter @hexabot-ai/widget run lint && \
|
|
82
|
+
pnpm --filter @hexabot-ai/widget run test && \
|
|
83
|
+
pnpm --filter @hexabot-ai/widget run build
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Unit tests:
|
|
87
|
+
- Vitest is configured in `vite.config.ts` under `test`.
|
|
88
|
+
- Current widget tests live in:
|
|
89
|
+
- `src/theme/theme.utils.test.ts`
|
|
90
|
+
- `src/providers/ThemeProvider.test.tsx`
|
|
91
|
+
- Test setup is initialized in `src/test/setup.ts`.
|
|
92
|
+
|
|
93
|
+
## Coding Style & Conventions
|
|
94
|
+
- Language/tooling: TypeScript + React function components + hooks.
|
|
95
|
+
- Formatting (`.prettierrc`):
|
|
96
|
+
- Double quotes (`singleQuote: false`).
|
|
97
|
+
- Trailing commas enabled (`trailingComma: "all"`).
|
|
98
|
+
- TypeScript strictness (`tsconfig.app.json`): `strict`, `noUnusedLocals`, `noUnusedParameters`, `noFallthroughCasesInSwitch`.
|
|
99
|
+
- ESLint highlights (`eslint.config.cjs`):
|
|
100
|
+
- Keep import order grouped and alphabetized.
|
|
101
|
+
- No duplicate imports.
|
|
102
|
+
- `no-console` is enforced (existing exceptions are explicitly lint-disabled in code).
|
|
103
|
+
- Unused vars must be removed unless intentionally prefixed with `_`.
|
|
104
|
+
- React hooks rules are enabled with selected relaxations already configured.
|
|
105
|
+
- License header is required in TS/TSX/JS/JSX files. Preserve/add this block:
|
|
106
|
+
```ts
|
|
107
|
+
/*
|
|
108
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
109
|
+
* Copyright (c) 20XX Hexastack.
|
|
110
|
+
* Full terms: see LICENSE.md.
|
|
111
|
+
*/
|
|
112
|
+
```
|
|
113
|
+
- Naming patterns used in this package:
|
|
114
|
+
- Components/providers: `PascalCase` files (e.g., `ChatWindow.tsx`).
|
|
115
|
+
- Hooks: `useXxx` (e.g., `useTranslation.tsx`).
|
|
116
|
+
- Types: `*.types.ts`.
|
|
117
|
+
- Co-located styles: `ComponentName.scss` next to the component.
|
|
118
|
+
|
|
119
|
+
## Testing Strategy
|
|
120
|
+
Current state:
|
|
121
|
+
- This package includes a Vitest + jsdom setup for widget-level unit tests.
|
|
122
|
+
- CI on `dev` branch runs workspace checks (`pnpm typecheck`, `pnpm lint`, `pnpm test`, `pnpm build` via Turbo). For widget-specific quality, treat `typecheck + lint + test + build` as the effective gate.
|
|
123
|
+
- Git hooks (`.husky/pre-commit`) run widget checks when widget files are staged: `pnpm typecheck` + `npx lint-staged` from `packages/widget`.
|
|
124
|
+
|
|
125
|
+
Recommended local validation:
|
|
126
|
+
1. Run `typecheck`, `lint`, `test`, and `build`.
|
|
127
|
+
2. Run `dev` and verify core chat flows manually (connect, receive/send messages, pre-chat form, launcher open/close).
|
|
128
|
+
3. Smoke-check UMD embed via `public/index.html` or `dist` preview.
|
|
129
|
+
|
|
130
|
+
> TODO: Define coverage thresholds and CI enforcement for this package.
|
|
131
|
+
|
|
132
|
+
## Common Tasks & Workflows
|
|
133
|
+
Add a new message type:
|
|
134
|
+
1. Extend message type definitions in `src/types/message.types.ts`.
|
|
135
|
+
2. Add renderer component under `src/components/messages/` with matching `.scss`.
|
|
136
|
+
3. Register rendering branch in `src/components/Message.tsx`.
|
|
137
|
+
4. If needed, adjust message preprocessing/state behavior in `src/providers/ChatProvider.tsx`.
|
|
138
|
+
5. Run `typecheck`, `lint`, and `build`.
|
|
139
|
+
|
|
140
|
+
Add/modify translations:
|
|
141
|
+
1. Update `src/translations/en/translation.json` and `src/translations/fr/translation.json`.
|
|
142
|
+
2. Access keys via `useTranslation` (`src/hooks/useTranslation.tsx`).
|
|
143
|
+
3. Keep translation key parity across languages.
|
|
144
|
+
|
|
145
|
+
Update widget config defaults:
|
|
146
|
+
1. Update `src/types/config.types.ts` (contract) and `src/constants/defaultConfig.ts` (defaults).
|
|
147
|
+
2. Verify propagation through `src/providers/ConfigProvider.tsx`.
|
|
148
|
+
3. Validate local demo behavior in `src/main.tsx`.
|
|
149
|
+
|
|
150
|
+
Update widget theming:
|
|
151
|
+
1. Update contracts in `src/theme/theme.types.ts` and resolver behavior in `src/theme/theme.utils.ts`.
|
|
152
|
+
2. Keep priority and compatibility behavior aligned:
|
|
153
|
+
- config override > server settings > system prefers-color-scheme > safe defaults
|
|
154
|
+
- support both `theme` and legacy `theme_color` / `themeColor`
|
|
155
|
+
3. Keep `useTheme()` for TS logic and CSS custom properties on `.sc-theme-root` for styles.
|
|
156
|
+
4. Preserve `useColors()` compatibility exports for existing components/integrations.
|
|
157
|
+
|
|
158
|
+
Update dependencies:
|
|
159
|
+
```bash
|
|
160
|
+
# Example (runtime dependency)
|
|
161
|
+
pnpm add <package> --filter @hexabot-ai/widget
|
|
162
|
+
|
|
163
|
+
# Example (dev dependency)
|
|
164
|
+
pnpm add -D <package> --filter @hexabot-ai/widget
|
|
165
|
+
```
|
|
166
|
+
Then run:
|
|
167
|
+
```bash
|
|
168
|
+
pnpm --filter @hexabot-ai/widget run typecheck
|
|
169
|
+
pnpm --filter @hexabot-ai/widget run lint
|
|
170
|
+
pnpm --filter @hexabot-ai/widget run build
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Release (v3 alpha train, `dev` branch):
|
|
174
|
+
```bash
|
|
175
|
+
./bump-version-v3.sh preminor
|
|
176
|
+
```
|
|
177
|
+
> TODO: Confirm with maintainers whether a given release should use `prepatch`, `preminor`, or `prerelease`.
|
|
178
|
+
|
|
179
|
+
## Guardrails & Agent Instructions
|
|
180
|
+
- Do not hand-edit generated or vendored paths:
|
|
181
|
+
- `packages/widget/dist/**`
|
|
182
|
+
- `packages/widget/node_modules/**`
|
|
183
|
+
- `packages/widget/.turbo/**`
|
|
184
|
+
- Keep the public widget entry contract stable unless explicitly requested:
|
|
185
|
+
- `src/ChatWidget.tsx` default export.
|
|
186
|
+
- Vite library build target in `vite.config.ts` (`name: "HexabotWidget"`).
|
|
187
|
+
- Keep theme backward compatibility unless explicitly requested otherwise:
|
|
188
|
+
- `theme_color` / `themeColor` support must remain functional.
|
|
189
|
+
- `src/providers/ColorProvider.tsx` currently re-exports theme-backed compatibility hooks.
|
|
190
|
+
- Settings persistence is now instance-scoped (`hexabot:widget:settings:<scope>`); avoid changes that re-introduce cross-widget leakage.
|
|
191
|
+
- Any protocol-level changes (socket payloads, webhook behavior) must stay compatible with the backend expectations used in `src/providers/ChatProvider.tsx` and `src/utils/SocketIoClient.ts`.
|
|
192
|
+
- Preserve license headers and do not remove licensing notices.
|
|
193
|
+
- Avoid unrelated monorepo edits when the task is widget-scoped.
|
|
194
|
+
- Some CI workflows still reference legacy scope `@hexabot/widget` while this package is `@hexabot-ai/widget`.
|
|
195
|
+
> TODO: Align workflow scopes in a dedicated maintenance change.
|
|
196
|
+
- Code ownership:
|
|
197
|
+
> TODO: No `CODEOWNERS` file found in this repository; confirm reviewer/approver group with maintainers.
|
package/README.md
CHANGED
|
@@ -75,15 +75,18 @@ Once the widget is built, you can easily embed it into any webpage. Here's an ex
|
|
|
75
75
|
ReactDOM.render(
|
|
76
76
|
el(HexabotWidget, {
|
|
77
77
|
apiUrl: 'https://api.yourdomain.com',
|
|
78
|
-
channel: 'web
|
|
78
|
+
channel: 'web',
|
|
79
|
+
transport: 'ws', // or "polling"
|
|
79
80
|
token: 'token123',
|
|
81
|
+
primaryColor: '#1ba089',
|
|
80
82
|
}),
|
|
81
83
|
domContainer,
|
|
82
84
|
);
|
|
83
85
|
</script>
|
|
84
86
|
```
|
|
85
87
|
|
|
86
|
-
Replace the values in apiUrl and
|
|
88
|
+
Replace the values in `apiUrl`, `token`, and `primaryColor` with your configuration details.
|
|
89
|
+
`transport` is optional and accepts `ws` (default) or `polling`.
|
|
87
90
|
|
|
88
91
|
To prevent the website css from conflicting with the chat widget css, we can leverage the shadow dom:
|
|
89
92
|
|
|
@@ -112,8 +115,10 @@ To prevent the website css from conflicting with the chat widget css, we can lev
|
|
|
112
115
|
ReactDOM.render(
|
|
113
116
|
React.createElement(HexabotWidget, {
|
|
114
117
|
apiUrl: 'https://api.yourdomain.com',
|
|
115
|
-
channel: 'web
|
|
118
|
+
channel: 'web',
|
|
119
|
+
transport: 'ws', // or "polling"
|
|
116
120
|
token: 'token123',
|
|
121
|
+
primaryColor: '#1ba089',
|
|
117
122
|
}),
|
|
118
123
|
shadowContainer,
|
|
119
124
|
);
|