@l7mp/tivadar-ai-chat-widget 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.
package/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ Copyright (c) 2025 L7mp.io
2
+
3
+ All rights reserved. No warranty, explicit or implicit, provided.
package/README.md ADDED
@@ -0,0 +1,253 @@
1
+ # @l7mp/ai-chat-widget
2
+
3
+ AI-powered chat widget for websites. Works with React, Angular, Vue, Next.js, and vanilla HTML.
4
+
5
+ Integrates with Azure OpenAI and Azure AI Search for intelligent, context-aware responses powered by Retrieval-Augmented Generation (RAG).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @l7mp/tivadar-ai-chat-widget
11
+ ```
12
+
13
+ Or with yarn:
14
+
15
+ ```bash
16
+ yarn add @l7mp/tivadar-ai-chat-widget
17
+ ```
18
+
19
+ Or via CDN:
20
+
21
+ ```html
22
+ <script src="https://unpkg.com/@l7mp/tivadar-ai-chat-widget@latest/widget-webcomponent.js"></script>
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ### Vanilla HTML
28
+
29
+ ```html
30
+ <!DOCTYPE html>
31
+ <html>
32
+ <head>
33
+ <script src="https://unpkg.com/@l7mp/tivadar-ai-chat-widget@latest/widget-webcomponent.js"></script>
34
+ </head>
35
+ <body>
36
+ <h1>My Website</h1>
37
+
38
+ <tivadar-ai-chat-widget
39
+ api-key="your-api-key"
40
+ api-endpoint="https://api.yourdomain.com/chat"
41
+ position="bottom-right"
42
+ title="Chat with AI"
43
+ ></tivadar-ai-chat-widget>
44
+ </body>
45
+ </html>
46
+ ```
47
+
48
+ ### React / Next.js
49
+
50
+ ```jsx
51
+ // Import once in your app (e.g., _app.tsx or layout.tsx)
52
+ import '@l7mp/tivadar-ai-chat-widget'
53
+
54
+ export default function Page() {
55
+ return (
56
+ <div>
57
+ <h1>My Website</h1>
58
+
59
+ <tivadar-ai-chat-widget
60
+ api-key="your-api-key"
61
+ api-endpoint="https://api.yourdomain.com/chat"
62
+ position="bottom-right"
63
+ title="Chat with AI"
64
+ />
65
+ </div>
66
+ )
67
+ }
68
+ ```
69
+
70
+ #### React wrapper component (with TypeScript support)
71
+
72
+ ```jsx
73
+ import AIChatWidget from '@l7mp/ai-chat-widget/react'
74
+
75
+ export default function Page() {
76
+ return (
77
+ <div>
78
+ <h1>My Website</h1>
79
+
80
+ <AIChatWidget
81
+ apiKey="your-api-key"
82
+ apiEndpoint="https://api.yourdomain.com/chat"
83
+ position="bottom-right"
84
+ title="Chat with AI"
85
+ />
86
+ </div>
87
+ )
88
+ }
89
+ ```
90
+
91
+ ### Angular
92
+
93
+ ```typescript
94
+ // app.module.ts
95
+ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
96
+ import '@l7mp/tivadar-ai-chat-widget'
97
+
98
+ @NgModule({
99
+ schemas: [CUSTOM_ELEMENTS_SCHEMA]
100
+ })
101
+ export class AppModule { }
102
+ ```
103
+
104
+ ```html
105
+ <!-- app.component.html -->
106
+ <h1>My Website</h1>
107
+
108
+ <tivadar-ai-chat-widget
109
+ api-key="your-api-key"
110
+ api-endpoint="https://api.yourdomain.com/chat"
111
+ position="bottom-right"
112
+ title="Chat with AI"
113
+ ></tivadar-ai-chat-widget>
114
+ ```
115
+
116
+ ### Vue
117
+
118
+ ```vue
119
+ <script setup>
120
+ import '@l7mp/tivadar-ai-chat-widget'
121
+ </script>
122
+
123
+ <template>
124
+ <div>
125
+ <h1>My Website</h1>
126
+
127
+ <tivadar-ai-chat-widget
128
+ api-key="your-api-key"
129
+ api-endpoint="https://api.yourdomain.com/chat"
130
+ position="bottom-right"
131
+ title="Chat with AI"
132
+ />
133
+ </div>
134
+ </template>
135
+ ```
136
+
137
+ ### Svelte
138
+
139
+ ```svelte
140
+ <script>
141
+ import '@l7mp/tivadar-ai-chat-widget'
142
+ </script>
143
+
144
+ <h1>My Website</h1>
145
+
146
+ <tivadar-ai-chat-widget
147
+ api-key="your-api-key"
148
+ api-endpoint="https://api.yourdomain.com/chat"
149
+ position="bottom-right"
150
+ title="Chat with AI"
151
+ />
152
+ ```
153
+
154
+ ## Configuration
155
+
156
+ The widget accepts the following HTML attributes:
157
+
158
+ | Attribute | Type | Required | Default | Description |
159
+ |-----------|------|----------|---------|-------------|
160
+ | `api-key` | string | Yes | - | Your customer API key |
161
+ | `api-endpoint` | string | Yes | - | Chat API endpoint URL |
162
+ | `position` | string | No | `"bottom-right"` | Widget position: `"bottom-right"`, `"bottom-left"`, `"top-right"`, `"top-left"` |
163
+ | `title` | string | No | `"Chat with AI"` | Widget header title |
164
+ | `theme` | string | No | `"light"` | Theme (currently only `"light"` supported) |
165
+ | `placeholder` | string | No | `"Type your message..."` | Input field placeholder |
166
+ | `welcome-message` | string | No | `"Hello! How can I help you today?"` | Initial greeting message |
167
+
168
+ ### Example with All Options
169
+
170
+ ```html
171
+ <tivadar-ai-chat-widget
172
+ api-key="your-api-key"
173
+ api-endpoint="https://api.yourdomain.com/chat"
174
+ position="bottom-left"
175
+ theme="light"
176
+ title="Support Chat"
177
+ placeholder="Ask me anything..."
178
+ welcome-message="Hi! How can I assist you today?"
179
+ ></tivadar-ai-chat-widget>
180
+ ```
181
+
182
+ ## Classic Version (Legacy)
183
+
184
+ For compatibility with older browsers or if you prefer the imperative API, you can use the classic version:
185
+
186
+ ```html
187
+ <script src="https://unpkg.com/@l7mp/tivadar-ai-chat-widget@latest/widget.js"></script>
188
+ <script>
189
+ AIChatWidget.init({
190
+ apiKey: 'your-api-key',
191
+ apiEndpoint: 'https://api.yourdomain.com/chat',
192
+ position: 'bottom-right',
193
+ title: 'Chat with AI'
194
+ });
195
+ </script>
196
+ ```
197
+
198
+ ## Browser Support
199
+
200
+ - Chrome/Edge 88+
201
+ - Firefox 85+
202
+ - Safari 14.1+
203
+ - Opera 74+
204
+
205
+ (Supports all modern browsers with Web Components API)
206
+
207
+ ## TypeScript
208
+
209
+ TypeScript definitions will be included in future releases. For now, you can declare the module:
210
+
211
+ ```typescript
212
+ // global.d.ts
213
+ declare namespace JSX {
214
+ interface IntrinsicElements {
215
+ 'tivadar-ai-chat-widget': {
216
+ 'api-key': string
217
+ 'api-endpoint': string
218
+ position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
219
+ title?: string
220
+ theme?: 'light' | 'dark'
221
+ placeholder?: string
222
+ 'welcome-message'?: string
223
+ }
224
+ }
225
+ }
226
+ ```
227
+
228
+ ## Development
229
+
230
+ ### Files
231
+
232
+ | File | Description |
233
+ |------|-------------|
234
+ | `widget-webcomponent.js` | Web Component version (recommended) |
235
+ | `widget.js` | Classic vanilla JS version (legacy) |
236
+
237
+ ### Publish to npm
238
+
239
+ ```bash
240
+ cd js/
241
+
242
+ # Bump version
243
+ npm version patch # or minor/major
244
+
245
+ # Publish (requires npm login)
246
+ npm publish --access public
247
+ ```
248
+
249
+ ## License
250
+
251
+ Copyright (c) 2025 L7mp.io
252
+
253
+ See LICENSE file for details.
package/index.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ declare namespace JSX {
2
+ interface IntrinsicElements {
3
+ 'ai-chat-widget': AIChatWidgetAttributes
4
+ }
5
+ }
6
+
7
+ type AIChatWidgetAttributes = {
8
+ 'api-key'?: string
9
+ 'api-endpoint'?: string
10
+ position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
11
+ theme?: 'light' | 'dark'
12
+ icon?: string
13
+ title?: string
14
+ placeholder?: string
15
+ 'welcome-message'?: string
16
+ }
17
+
18
+ declare module '@l7mp/ai-chat-widget' {
19
+ const widgetModule: unknown
20
+ export default widgetModule
21
+ }
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@l7mp/tivadar-ai-chat-widget",
3
+ "version": "1.0.0",
4
+ "description": "AI-powered chat widget for websites. Works with React, Angular, Vue, Next.js, and vanilla HTML. Integrates with Azure OpenAI and Azure AI Search for RAG-based responses.",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "main": "widget-webcomponent.js",
9
+ "module": "widget-webcomponent.js",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./index.d.ts",
13
+ "default": "./widget-webcomponent.js"
14
+ },
15
+ "./react": {
16
+ "types": "./react.d.ts",
17
+ "default": "./react.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "widget-webcomponent.js",
22
+ "widget.js",
23
+ "react.js",
24
+ "react.d.ts",
25
+ "index.d.ts",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
29
+ "types": "index.d.ts",
30
+ "peerDependencies": {
31
+ "react": ">=16.8"
32
+ },
33
+ "scripts": {
34
+ "prepublishOnly": "echo 'Ready to publish'"
35
+ },
36
+ "keywords": [
37
+ "chat",
38
+ "chatbot",
39
+ "ai",
40
+ "azure",
41
+ "openai",
42
+ "widget",
43
+ "web-component",
44
+ "react",
45
+ "angular",
46
+ "vue",
47
+ "nextjs",
48
+ "rag",
49
+ "azure-search",
50
+ "l7mp"
51
+ ],
52
+ "author": "L7mp.io <info@l7mp.io>",
53
+ "license": "SEE LICENSE IN LICENSE",
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "https://github.com/l7mp/tivadar-ai-chat-widget.git"
57
+ },
58
+ "bugs": {
59
+ "url": "https://github.com/l7mp/tivadar-ai-chat-widget/issues"
60
+ },
61
+ "homepage": "https://github.com/l7mp/tivadar-ai-chat-widget#readme",
62
+ "engines": {
63
+ "node": ">=14.0.0"
64
+ },
65
+ "browserslist": [
66
+ "defaults",
67
+ "not IE 11",
68
+ "maintained node versions"
69
+ ]
70
+ }
package/react.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import * as React from 'react'
2
+
3
+ type AIChatWidgetProps = {
4
+ apiKey?: string
5
+ apiEndpoint?: string
6
+ position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
7
+ theme?: 'light' | 'dark'
8
+ icon?: string
9
+ title?: string
10
+ placeholder?: string
11
+ welcomeMessage?: string
12
+ }
13
+
14
+ declare const AIChatWidget: React.ForwardRefExoticComponent<
15
+ AIChatWidgetProps & React.RefAttributes<HTMLElement>
16
+ >
17
+
18
+ export default AIChatWidget
19
+ export { AIChatWidget }
package/react.js ADDED
@@ -0,0 +1,48 @@
1
+ import React, { forwardRef, useImperativeHandle, useMemo, useRef } from 'react'
2
+ import './widget-webcomponent.js'
3
+
4
+ const attributeProps = [
5
+ 'apiKey',
6
+ 'apiEndpoint',
7
+ 'position',
8
+ 'theme',
9
+ 'icon',
10
+ 'title',
11
+ 'placeholder',
12
+ 'welcomeMessage'
13
+ ]
14
+
15
+ const toAttributeName = (propName) =>
16
+ propName.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`)
17
+
18
+ const toAttributeMap = (props) =>
19
+ attributeProps.reduce((acc, propName) => {
20
+ const value = props[propName]
21
+ if (value === undefined || value === null || value === '') {
22
+ return acc
23
+ }
24
+ acc[toAttributeName(propName)] = value
25
+ return acc
26
+ }, {})
27
+
28
+ const AIChatWidget = forwardRef(function AIChatWidget(props, ref) {
29
+ const internalRef = useRef(null)
30
+ const instanceKey = useMemo(
31
+ () => `${props.apiKey ?? ''}-${props.apiEndpoint ?? ''}`,
32
+ [props.apiKey, props.apiEndpoint]
33
+ )
34
+ const elementProps = useMemo(() => toAttributeMap(props), [props])
35
+
36
+ useImperativeHandle(ref, () => internalRef.current)
37
+
38
+ return React.createElement('ai-chat-widget', {
39
+ key: instanceKey,
40
+ ref: internalRef,
41
+ ...elementProps
42
+ })
43
+ })
44
+
45
+ AIChatWidget.displayName = 'AIChatWidget'
46
+
47
+ export default AIChatWidget
48
+ export { AIChatWidget }