A modern, React-based in-app support widget for Marketrix that provides Show, Tell, and Do modes with AI-powered assistance. Designed for easy integration into any website using a simple script tag.
npm install @marketrix.ai/widgetA modern, React-based in-app support widget for Marketrix that provides Show,
Tell, and Do modes with AI-powered assistance. Designed for easy integration
into any website using a simple script tag.
- šÆ Three Interaction Modes: Show, Tell, and Do
- šØ Modern UI: Built with React 19 and Tailwind CSS v4
- š Theme Support: Customizable colors and appearance
- š± Responsive Design: Works on desktop, tablet, and mobile
- āļø API-Driven Configuration: Dynamic settings from integration service
- š Easy Integration: Simple script tag integration
- š TypeScript: Full TypeScript support with comprehensive type definitions
- š¦ Standalone: Single file bundle with no external dependencies
- š„ Session Recording: Built-in RRWeb session recording capabilities
- š Shadow DOM Isolation: CSS isolation prevents conflicts with host app
- šļø Widget Chips: Quick action chips for common tasks
- š WebSocket Communication: Real-time AI agent communication
Add the widget to your HTML page using a script tag:
``html`
src="https://cdn.marketrix.io/widget/index.mjs"
mtx-ai-host="https://agent.marketrix.ai"
mtx-api-host="https://api.marketrix.ai"
mtx-id="your-marketrix-id"
mtx-key="your-marketrix-key"
>
For development/testing with direct agent and connection IDs:
`html`
src="https://cdn.marketrix.io/widget/dev/index.mjs"
mtx-ai-host="https://agent.marketrix.ai"
mtx-api-host="https://api.marketrix.ai"
mtx-app="YOUR_CONNECTION_ID"
mtx-agent="YOUR_AGENT_ID"
>
| Attribute | Type | Required | Description |
| -------------- | ------ | -------- | ----------------------------------------------- |
| mtx-id | string | ā
\* | Your Marketrix ID (production mode) |mtx-key
| | string | ā
\* | Your Marketrix API key (production mode) |mtx-app
| | number | ā
\* | Connection/App ID (dev mode) |mtx-agent
| | number | ā
\* | Agent ID (dev mode) |mtx-api-host
| | string | ā
| API server URL (e.g., https://api.marketrix.ai) |mtx-ai-host
| | string | ā
| AI/Agent server URL for WebSocket connection |
\*Either mtx-id + mtx-key (production) OR mtx-app + mtx-agent (dev) must
be provided.
Widget appearance and behavior are configured through the API. Settings include:
- Appearance: Position, colors, border radius, shadows, dimensions
- Features: Enable/disable Tell, Show, Do modes, human handoff
- Device Visibility: Desktop, mobile, or both
- Text: Header, body, greeting messages
- Chips: Quick action buttons with predefined questions
The agent explains concepts, provides information, or answers questions with
detailed explanations.
The agent demonstrates how to perform a task with step-by-step guidance and
visual highlighting of UI elements.
The agent performs actions on your behalf using browser automation tools,
including clicking, typing, scrolling, and navigating.
`typescript
import { initWidget, unmountWidget, mountWidget, MarketrixWidget, getCurrentConfig } from '@marketrix.ai/widget';
// Initialize with production credentials
await initWidget({
mtxId: 'your-marketrix-id',
mtxKey: 'your-marketrix-key',
mtxApiHost: 'https://api.marketrix.ai',
mtxAiHost: 'https://agent.marketrix.ai',
});
// Or initialize with dev credentials
await initWidget({
mtxApp: 123,
mtxAgent: 456,
mtxApiHost: 'https://api.marketrix.ai',
mtxAiHost: 'https://agent.marketrix.ai',
});
// Destroy widget
unmountWidget();
`
`tsx
import { MarketrixWidget } from '@marketrix.ai/widget';
function App() {
return (
widget_enabled: true,
widget_appearance: 'default',
widget_position: 'bottom_right',
widget_device: 'desktop_mobile',
widget_header: 'AI Assistant',
widget_body: 'How can I help you today?',
widget_greeting: 'Hello! Ask me anything.',
widget_feature_tell: true,
widget_feature_show: true,
widget_feature_do: true,
widget_feature_human: false,
widget_background_color: '#ffffff',
widget_text_color: '#1f2937',
widget_border_color: '#e5e7eb',
widget_accent_color: '#3b82f6',
widget_secondary_color: '#6b7280',
widget_border_radius: '16px',
widget_font_size: '14px',
widget_width: '400px',
widget_height: '600px',
widget_shadow: '0 25px 50px -12px rgba(0, 0, 0, 0.25)',
widget_animation_duration: '300ms',
widget_fade_duration: '200ms',
widget_bounce_effect: true,
widget_chips: [],
}}
mtxApiHost='https://api.marketrix.ai'
mtxAiHost='https://agent.marketrix.ai'
/>
);
}
`
`typescript
import { mountWidget } from '@marketrix.ai/widget';
// Production mode
await mountWidget({
mtxId: 'your-id',
mtxKey: 'your-key',
mtxApiHost: 'https://api.marketrix.ai',
mtxAiHost: 'https://agent.marketrix.ai',
});
// Dev mode
await mountWidget({
mtxApp: 123,
mtxAgent: 456,
mtxApiHost: 'https://api.marketrix.ai',
mtxAiHost: 'https://agent.marketrix.ai',
});
// Preview mode (with settings directly)
await mountWidget({
settings: widgetSettings,
mtxApiHost: 'https://api.marketrix.ai',
mtxAiHost: 'https://agent.marketrix.ai',
});
`
- Node.js 18+
- npm
1. Clone the repository:
`bash`
git clone
cd widget
2. Install dependencies (git hooks auto-installed via lefthook):
`bash`
npm install
3. Start development server:
`bash`
npm start
4. Build for production:
`bash`
npm run build
#### Option 1: Bookmarklet (Quick Testing)
Build and serve the widget locally:
`bash`
npm run build
npx serve dist -l 5174 --cors
Create a bookmark with this URL:
`javascript`
javascript: (function () {
var s = document.createElement('script');
s.src = 'http://localhost:5174/index.mjs';
s.setAttribute('mtx-ai-host', 'https://agent.marketrix.ai');
s.setAttribute('mtx-api-host', 'https://api.marketrix.ai');
s.setAttribute('mtx-app', 'YOUR_CONNECTION_ID');
s.setAttribute('mtx-agent', 'YOUR_AGENT_ID');
document.head.appendChild(s);
})();
#### Option 2: HTTPS Dev Server
`bash`
npm start
First visit https://localhost:5173 and accept the certificate, then use:
`javascript`
javascript: (function () {
var s = document.createElement('script');
s.src = 'https://localhost:5173/index.mjs';
s.setAttribute('mtx-ai-host', 'https://agent.marketrix.ai');
s.setAttribute('mtx-api-host', 'https://api.marketrix.ai');
s.setAttribute('mtx-app', 'YOUR_CONNECTION_ID');
s.setAttribute('mtx-agent', 'YOUR_AGENT_ID');
document.head.appendChild(s);
})();
#### Option 3: Chrome Extension
See chrome-extension/README.md for persistent
widget injection across page navigations.
Build and run debug tool for testing browser tools:
`bash`
npm run build:debug
npx serve dist -l 5174 --cors
Then use this bookmarklet on any website:
`javascript`
javascript: (function () {
var s = document.createElement('script');
s.src = 'http://localhost:5174/debug.js';
document.body.appendChild(s);
})();
Press Ctrl+Shift+D to toggle the debug panel.
See docs/DEBUG_PANEL_USAGE.md for detailed debug
panel documentation.
``
widget/
āāā src/
ā āāā components/ # React components
ā ā āāā chat/ # Chat UI components
ā ā ā āāā ChatWindow.tsx
ā ā ā āāā MessageContent.tsx
ā ā ā āāā MessageItem.tsx
ā ā ā āāā MessageList.tsx
ā ā ā āāā ProgressLine.tsx
ā ā ā āāā SuggestedActions.tsx
ā ā ā āāā TaskStatusIcon.tsx
ā ā ā āāā ThinkingIndicator.tsx
ā ā ā āāā VideoStreamDisplay.tsx
ā ā ā āāā WelcomeMessage.tsx
ā ā āāā debug/ # Debug panel (dev only)
ā ā ā āāā DebugPanel.tsx
ā ā āāā dev/ # Dev testing components
ā ā ā āāā DomTestPanel.tsx
ā ā āāā input/ # Input components
ā ā ā āāā MessageInput.tsx
ā ā ā āāā ModeSelector.tsx
ā ā āāā layout/ # Layout components
ā ā ā āāā WidgetButton.tsx
ā ā āāā ui/ # UI utility components
ā ā ā āāā DiagnosticModal.tsx
ā ā ā āāā ErrorDisplay.tsx
ā ā ā āāā ScreenAccessModal.tsx
ā ā ā āāā WidgetSettingsLoader.tsx
ā ā āāā BrowserTools.tsx
ā ā āāā MarketrixWidget.tsx
ā āāā context/ # React context
ā ā āāā WidgetContext.tsx
ā āāā hooks/ # Custom React hooks
ā ā āāā usePageLifecycle.ts
ā ā āāā useTaskState.ts
ā ā āāā useWidget.ts
ā āāā services/ # Core services
ā ā āāā ApiService.ts
ā ā āāā ChatService.ts
ā ā āāā ConfigManager.ts
ā ā āāā DevTestService.ts
ā ā āāā DomService.ts
ā ā āāā IntegrationService.ts
ā ā āāā ScreenShareService.ts
ā ā āāā SessionManager.ts
ā ā āāā SessionRecorder.ts
ā ā āāā ShowModeService.ts
ā ā āāā StorageService.ts
ā ā āāā ToolService.ts
ā ā āāā ValidationService.ts
ā ā āāā WebSocketClient.ts
ā āāā sdk/ # API SDK
ā ā āāā index.ts
ā ā āāā routes.ts
ā ā āāā schema.ts
ā āāā types/ # TypeScript types
ā ā āāā assets.d.ts
ā ā āāā browserTools.ts
ā ā āāā global.d.ts
ā ā āāā index.ts
ā ā āāā toolMessages.ts
ā āāā utils/ # Utility functions
ā ā āāā apiUtils.ts
ā ā āāā bootstrap.tsx
ā ā āāā chat.ts
ā ā āāā cleanupUtils.ts
ā ā āāā common.ts
ā ā āāā devTools.ts
ā ā āāā dom.ts
ā ā āāā format.ts
ā ā āāā persistence.ts
ā ā āāā stateUtils.ts
ā ā āāā validation.ts
ā ā āāā widgetPositioning.ts
ā āāā constants/ # Configuration constants
ā ā āāā config.ts
ā āāā assets/ # Static assets
ā āāā debug.tsx # Debug entry point
ā āāā index.css # Global styles
ā āāā index.tsx # Main entry point
āāā chrome-extension/ # Chrome extension for persistent injection
āāā docs/ # Documentation
āāā vite.config.ts # Vite configuration
āāā vite.config.debug.ts # Debug build configuration
āāā tailwind.config.js # Tailwind configuration
āāā tsconfig.json # TypeScript configuration
āāā package.json
#### initWidget(config: MarketrixConfig): Promise
Initializes the widget with the provided configuration. Validates credentials,
fetches settings from the API, and mounts the widget to the DOM.
#### unmountWidget(): void
Destroys the widget and removes it from the DOM. Also stops session recording.
#### mountWidget(config: AddWidgetConfig): Promise
Auto-detects mode (preview, production, or dev) and initializes the widget.
#### getCurrentConfig(): MarketrixConfig | null
Returns the current widget configuration.
`typescript
// Core configuration
interface MarketrixConfig {
// Production mode credentials
mtxId?: string;
mtxKey?: string;
// Dev mode credentials
mtxApp?: number;
mtxAgent?: number;
// API configuration
mtxApiHost?: string;
mtxAiHost?: string;
// Optional user ID
userId?: number;
// Widget position overrides
widget_position_offset?: { x?: number; y?: number };
widget_position_z_index?: number;
// Preview mode flag
isPreviewMode?: boolean;
// All WidgetSettingsData fields (optional)
// ...
}
// Chat message
interface ChatMessage {
id: string;
content: string;
sender: 'user' | 'agent';
timestamp: Date;
mode?: 'tell' | 'show' | 'do';
parts?: MessagePart[];
taskStatus?: 'ongoing' | 'done' | 'failed' | 'stopped';
}
// Widget state
interface WidgetState {
isOpen: boolean;
isMinimized: boolean;
isLoading: boolean;
messages: ChatMessage[];
currentMode: 'tell' | 'show' | 'do';
agentAvailable: boolean;
error?: string;
activeTaskId: string | null;
isTaskRunning: boolean;
taskProgress: TaskProgress[];
}
// Instruction types
type InstructionType = 'tell' | 'show' | 'do';
`
The widget uses Vite with:
- CSS injection plugin for single-file bundles
- Shadow DOM isolation for CSS
- IIFE format for script tag usage
- ESM format for module imports
- Source maps for debugging
Output files:
- dist/index.mjs - Main widget bundledist/debug.js
- - Debug panel bundle
- Chrome 90+
- Firefox 88+
- Safari 14+
- Edge 90+
- react / react-dom v19 (peer dependency)@rrweb/record
- - Session recording@ts-rest/core
- - Type-safe API clientaxios
- - HTTP clientreact-icons
- - Iconszod` - Schema validation
-
- Vite 6
- Tailwind CSS v4
- TypeScript 5
- ESLint + Prettier
- Lefthook for git hooks
MIT License - see LICENSE file for details.
For support and questions, please contact the Marketrix team or create an issue
in the repository.