copilot-chat-widget 0.1.11 → 0.1.13
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/README.md +29 -32
- package/dist/chat-widget.min.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
# Copilot Chat Widget
|
|
1
|
+
# Copilot Chat Widget
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
1. Qua NPM (khuyến nghị cho SPA/Next.js/React/Vue).
|
|
5
|
-
2. Qua thẻ `<script>` (tương thích ngược, không cần build).
|
|
3
|
+
Embeddable chat widget ready for CDN drop-in or npm import.
|
|
6
4
|
|
|
7
|
-
##
|
|
5
|
+
## Install
|
|
8
6
|
```bash
|
|
9
7
|
npm install copilot-chat-widget
|
|
10
|
-
#
|
|
8
|
+
# or
|
|
11
9
|
yarn add copilot-chat-widget
|
|
12
10
|
```
|
|
13
11
|
|
|
14
|
-
##
|
|
12
|
+
## Quick start (npm / bundler)
|
|
15
13
|
```js
|
|
16
14
|
import { loadCopilotChatWidget } from "copilot-chat-widget";
|
|
17
15
|
|
|
18
|
-
loadCopilotChatWidget({
|
|
16
|
+
loadCopilotChatWidget({
|
|
17
|
+
token: "YOUR_WIDGET_TOKEN",
|
|
18
|
+
// optional when backend is another origin:
|
|
19
|
+
// baseUrl: "https://your-backend-domain"
|
|
20
|
+
});
|
|
19
21
|
```
|
|
20
|
-
|
|
21
|
-
Hàm này sẽ gắn script `chat-widget.min.js` (IIFE) vào trang, đọc `token` từ options (hoặc `window.CopilotChatConfig` nếu bạn set trước).
|
|
22
|
-
- Nếu backend widget không cùng origin với web hiện tại, truyền thêm `baseUrl: "https://your-backend-domain"` để gọi đúng API. Nếu không truyền, widget sẽ dùng giá trị build-time `WIDGET_BASE_URL` (đọc từ `.env` khi build), sau đó mới fallback sang origin của script/trang.
|
|
22
|
+
`loadCopilotChatWidget` injects the standalone bundle (`chat-widget.min.js`) and boots the widget with the given token.
|
|
23
23
|
|
|
24
24
|
### React/Next.js
|
|
25
25
|
```jsx
|
|
@@ -30,7 +30,7 @@ export default function Page() {
|
|
|
30
30
|
useEffect(() => {
|
|
31
31
|
loadCopilotChatWidget({
|
|
32
32
|
token: process.env.NEXT_PUBLIC_CHAT_WIDGET_TOKEN,
|
|
33
|
-
baseUrl: process.env.NEXT_PUBLIC_WIDGET_BASE_URL //
|
|
33
|
+
baseUrl: process.env.NEXT_PUBLIC_WIDGET_BASE_URL // optional override
|
|
34
34
|
});
|
|
35
35
|
}, []);
|
|
36
36
|
|
|
@@ -38,38 +38,35 @@ export default function Page() {
|
|
|
38
38
|
}
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
##
|
|
41
|
+
## Quick start (script tag)
|
|
42
42
|
```html
|
|
43
43
|
<script
|
|
44
|
-
src="https://
|
|
44
|
+
src="https://unpkg.com/copilot-chat-widget/dist/chat-widget.min.js"
|
|
45
45
|
data-token="YOUR_WIDGET_TOKEN"
|
|
46
|
-
data-base-url="https://your-backend-domain" <!--
|
|
46
|
+
data-base-url="https://your-backend-domain" <!-- optional if backend is another origin -->
|
|
47
47
|
></script>
|
|
48
48
|
```
|
|
49
|
-
- `data-token`:
|
|
50
|
-
- `data-
|
|
51
|
-
- `data-
|
|
49
|
+
- `data-token`: required.
|
|
50
|
+
- `data-base-url`: optional override; if omitted, the widget uses the build-time `WIDGET_BASE_URL`, then falls back to the script/page origin.
|
|
51
|
+
- `data-autoload="false"`: insert script but call `window.CopilotChat.init()` yourself.
|
|
52
52
|
|
|
53
|
-
##
|
|
54
|
-
- `token` (string,
|
|
55
|
-
- `
|
|
56
|
-
- `
|
|
53
|
+
## Configuration
|
|
54
|
+
- `token` (string, required): widget token.
|
|
55
|
+
- `baseUrl` (string): backend host serving `/api/chat-widget/config`. Needed when the embedding page is on a different origin. Fallback order: `baseUrl` option/data attribute → `WIDGET_BASE_URL` (build-time) → script/page origin.
|
|
56
|
+
- `autoload` (boolean): set `false` to defer bootstrap and call `window.CopilotChat.load()` manually.
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
Runtime controls:
|
|
59
59
|
```js
|
|
60
|
-
window.CopilotChat.open(); //
|
|
61
|
-
window.CopilotChat.close(); //
|
|
62
|
-
window.CopilotChat.load(); //
|
|
60
|
+
window.CopilotChat.open(); // open widget
|
|
61
|
+
window.CopilotChat.close(); // close widget
|
|
62
|
+
window.CopilotChat.load(); // initialize if autoload=false
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
## Build
|
|
65
|
+
## Build & publish (for maintainers)
|
|
66
66
|
```bash
|
|
67
67
|
cd webui/widget
|
|
68
68
|
npm install
|
|
69
|
-
WIDGET_BASE_URL=https://your-backend-domain npm run build #
|
|
70
|
-
```
|
|
71
|
-
Sau khi kiểm tra output trong `webui/widget/dist`, có thể publish lên NPM:
|
|
72
|
-
```bash
|
|
69
|
+
WIDGET_BASE_URL=https://your-backend-domain npm run build # embed default baseUrl into bundle
|
|
73
70
|
npm publish --access public
|
|
74
71
|
```
|
|
75
|
-
|
|
72
|
+
To use a different package name, update `name` in `webui/widget/package.json` before publishing.
|
package/dist/chat-widget.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){"use strict";(()=>{if(typeof window>"u"||typeof document>"u"||window.__copilotWidgetLoaded)return;window.__copilotWidgetLoaded=!0;const v="http://localhost:
|
|
1
|
+
(function(){"use strict";(()=>{if(typeof window>"u"||typeof document>"u"||window.__copilotWidgetLoaded)return;window.__copilotWidgetLoaded=!0;const v="http://localhost:3000",m=64,f=720,C=document.currentScript,y=t=>{if(!t?.src)return{};try{const i=new URL(t.src,window.location.href),o={};return i.searchParams.forEach((a,s)=>{o[s]=a}),o}catch(i){return console.warn("[CopilotChat] Failed to parse script query params:",i),{}}},S=t=>{document.readyState==="complete"||document.readyState==="interactive"?setTimeout(t,0):document.addEventListener("DOMContentLoaded",t)},x=()=>C||Array.from(document.querySelectorAll("script")).reverse().find(o=>o.dataset?.token||o.src&&o.src.includes("chat-widget"))||null,U=({iframeUrl:t,launcherIcon:i})=>{const o=document.querySelector("[data-copilot-widget-root]");o&&o.remove();const a=document.createElement("div");a.setAttribute("data-copilot-widget-root","true");const s=a.attachShadow({mode:"open"});document.body.appendChild(a);const e=document.createElement("button");e.type="button",e.setAttribute("aria-label","Open Copilot chat"),e.innerHTML=`
|
|
2
2
|
<img
|
|
3
3
|
src="${i}"
|
|
4
4
|
alt="Copilot chat launcher"
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var n=typeof document<"u"?document.currentScript:null;const r="http://localhost:
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var n=typeof document<"u"?document.currentScript:null;const r="http://localhost:3000";function l(d={}){if(typeof window>"u"||typeof document>"u")return null;const{token:a,autoload:i,baseUrl:t=r}=d;window.CopilotChatConfig={...window.CopilotChatConfig,...d,baseUrl:t||window.CopilotChatConfig?.baseUrl||void 0};const o=document.getElementById("copilot-chat-widget-loader");if(o)return a&&(o.dataset.token=a),t&&(o.dataset.baseUrl=t),i===!1&&(o.dataset.autoload="false"),o;const e=document.createElement("script");return e.id="copilot-chat-widget-loader",e.src=new URL("./chat-widget.min.js",typeof document>"u"?require("url").pathToFileURL(__filename).href:n&&n.tagName.toUpperCase()==="SCRIPT"&&n.src||new URL("index.cjs",document.baseURI).href).href,e.async=!0,a&&(e.dataset.token=a),t&&(e.dataset.baseUrl=t),i===!1&&(e.dataset.autoload="false"),document.body.appendChild(e),e}exports.default=l;exports.loadCopilotChatWidget=l;
|
package/dist/index.mjs
CHANGED