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 CHANGED
@@ -1,25 +1,25 @@
1
- # Copilot Chat Widget (NPM)
1
+ # Copilot Chat Widget
2
2
 
3
- Widget chat Copilot thể nhúng theo hai cách:
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
- ## Cài đặt
5
+ ## Install
8
6
  ```bash
9
7
  npm install copilot-chat-widget
10
- # hoặc
8
+ # or
11
9
  yarn add copilot-chat-widget
12
10
  ```
13
11
 
14
- ## Sử dụng với NPM (import)
12
+ ## Quick start (npm / bundler)
15
13
  ```js
16
14
  import { loadCopilotChatWidget } from "copilot-chat-widget";
17
15
 
18
- loadCopilotChatWidget({ token: "YOUR_WIDGET_TOKEN" });
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 // nếu backend khác origin; nếu không, sẽ dùng giá trị build-time hoặc origin hiện tại
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
- ## Sử dụng qua thẻ `<script>` (giữ hành vi cũ)
41
+ ## Quick start (script tag)
42
42
  ```html
43
43
  <script
44
- src="https://cdn.example.com/chat-widget.min.js"
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" <!-- tùy chọn nếu khác origin -->
46
+ data-base-url="https://your-backend-domain" <!-- optional if backend is another origin -->
47
47
  ></script>
48
48
  ```
49
- - `data-token`: bắt buộc.
50
- - `data-autoload="false"`: nếu muốn chèn script nhưng tự gọi `window.CopilotChat.init()` sau.
51
- - `data-base-url`: override host backend nếu khác origin hoặc bạn không build sẵn `WIDGET_BASE_URL`.
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
- ## API cấu hình
54
- - `token` (string, bắt buộc): token widget.
55
- - `autoload` (boolean): đặt `false` nếu muốn tự gọi `window.CopilotChat.load()`.
56
- - `baseUrl` (string): host/backend cung cấp API `/api/chat-widget/config`. Cần khi web embed khác origin; nếu không truyền sẽ dùng `WIDGET_BASE_URL` build-time rồi fallback origin.
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
- Khi script đã load, có thể gọi:
58
+ Runtime controls:
59
59
  ```js
60
- window.CopilotChat.open(); // mở widget
61
- window.CopilotChat.close(); // đóng widget
62
- window.CopilotChat.load(); // khởi tạo lại nếu autoload=false
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 publish package
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 # gắn default baseUrl vào bundle
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
- Nếu muốn đổi tên package cho phù hợp scope công ty, sửa trường `name` trong `webui/widget/package.json` trước khi publish.
72
+ To use a different package name, update `name` in `webui/widget/package.json` before publishing.
@@ -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:3009",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=`
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:3009";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;
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
@@ -1,4 +1,4 @@
1
- const n = "http://localhost:3009";
1
+ const n = "http://localhost:3000";
2
2
  function l(i = {}) {
3
3
  if (typeof window > "u" || typeof document > "u")
4
4
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copilot-chat-widget",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Embeddable Copilot chat widget that can be loaded via NPM or a script tag.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",