copilot-chat-widget 0.1.0 → 0.1.1
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 +94 -94
- package/dist/chat-widget.min.js +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +187 -219
- package/package.json +41 -40
- package/src/index.js +371 -425
- package/src/standalone.js +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,230 +1,198 @@
|
|
|
1
|
-
|
|
2
|
-
if (
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
(function() {
|
|
2
|
+
if (typeof window > "u" || window.__copilotWidgetLoaded)
|
|
3
|
+
return;
|
|
4
|
+
window.__copilotWidgetLoaded = !0;
|
|
5
|
+
const b = 64, C = 720, E = document.currentScript, v = "http://localhost:3000", k = (e) => {
|
|
6
|
+
if (!e?.src) return {};
|
|
7
|
+
try {
|
|
8
|
+
const n = new URL(e.src, window.location.href), r = {};
|
|
9
|
+
return n.searchParams.forEach((a, h) => {
|
|
10
|
+
r[h] = a;
|
|
11
|
+
}), r;
|
|
12
|
+
} catch (n) {
|
|
13
|
+
return console.warn("[CopilotChat] Failed to parse script query params:", n), {};
|
|
14
|
+
}
|
|
15
|
+
}, I = (e) => {
|
|
16
|
+
document.readyState === "complete" || document.readyState === "interactive" ? setTimeout(e, 0) : document.addEventListener("DOMContentLoaded", e);
|
|
17
|
+
}, S = (e) => e.endsWith("/") ? e.slice(0, -1) : e, A = ({ iframeUrl: e, launcherIcon: n, theme: r = {} }) => {
|
|
18
|
+
const a = document.querySelector("[data-copilot-widget-root]");
|
|
18
19
|
a && a.remove();
|
|
19
|
-
const h = document.createElement("div");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
padding: "12px 16px",
|
|
26
|
-
background: "#0f172a",
|
|
27
|
-
color: "white",
|
|
28
|
-
borderRadius: "12px",
|
|
29
|
-
boxShadow: "0 8px 24px rgba(0,0,0,0.25)",
|
|
30
|
-
zIndex: 2147483647,
|
|
31
|
-
fontSize: "14px",
|
|
32
|
-
fontWeight: "600",
|
|
33
|
-
maxWidth: "420px",
|
|
34
|
-
lineHeight: "1.4",
|
|
35
|
-
textAlign: "center"
|
|
36
|
-
}), document.body.appendChild(h), setTimeout(() => {
|
|
37
|
-
h.remove();
|
|
38
|
-
}, 4500);
|
|
39
|
-
}, s = document.createElement("div");
|
|
40
|
-
s.setAttribute("data-copilot-widget-root", "true");
|
|
41
|
-
const f = s.attachShadow({ mode: "open" });
|
|
42
|
-
document.body.appendChild(s);
|
|
43
|
-
const o = document.createElement("button");
|
|
44
|
-
o.type = "button", o.setAttribute("aria-label", "Open Copilot chat"), o.innerHTML = `
|
|
20
|
+
const { accent: h = "linear-gradient(135deg, #0078ff, #00c6ff)" } = r, m = document.createElement("div");
|
|
21
|
+
m.setAttribute("data-copilot-widget-root", "true");
|
|
22
|
+
const u = m.attachShadow({ mode: "open" });
|
|
23
|
+
document.body.appendChild(m);
|
|
24
|
+
const t = document.createElement("button");
|
|
25
|
+
t.type = "button", t.setAttribute("aria-label", "Open Copilot chat"), t.innerHTML = `
|
|
45
26
|
<img
|
|
46
27
|
src="${n}"
|
|
47
28
|
alt="Copilot chat launcher"
|
|
48
29
|
style="width: 38px; height: 38px; object-fit: contain; border-radius: 50%; pointer-events: none;"
|
|
49
30
|
/>
|
|
50
|
-
`, Object.assign(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
31
|
+
`, Object.assign(t.style, {
|
|
32
|
+
position: "fixed",
|
|
33
|
+
bottom: "24px",
|
|
34
|
+
right: "24px",
|
|
35
|
+
width: `${b}px`,
|
|
36
|
+
height: `${b}px`,
|
|
37
|
+
borderRadius: "50%",
|
|
38
|
+
border: "none",
|
|
39
|
+
background: h,
|
|
40
|
+
color: "white",
|
|
41
|
+
cursor: "pointer",
|
|
42
|
+
zIndex: 999998,
|
|
43
|
+
display: "flex",
|
|
44
|
+
alignItems: "center",
|
|
45
|
+
justifyContent: "center",
|
|
46
|
+
boxShadow: "0 6px 14px rgba(0,0,0,0.25)",
|
|
47
|
+
transition: "all 0.25s ease"
|
|
48
|
+
}), t.onmouseover = () => {
|
|
49
|
+
t.style.transform = "scale(1.12)", t.style.boxShadow = "0 10px 25px rgba(0,0,0,0.3)";
|
|
50
|
+
}, t.onmouseout = () => {
|
|
51
|
+
t.style.transform = "scale(1)", t.style.boxShadow = "0 6px 14px rgba(0,0,0,0.25)";
|
|
52
|
+
};
|
|
53
|
+
const o = document.createElement("div");
|
|
54
|
+
o.setAttribute("data-copilot-widget-root", "true"), Object.assign(o.style, {
|
|
55
|
+
display: "none",
|
|
56
|
+
position: "fixed",
|
|
57
|
+
bottom: `${b + 36}px`,
|
|
58
|
+
right: "24px",
|
|
59
|
+
zIndex: "999999",
|
|
60
|
+
transformOrigin: "bottom right",
|
|
61
|
+
transform: "scale(0.8) translateY(20px)",
|
|
62
|
+
opacity: "0",
|
|
63
|
+
transition: "all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55)"
|
|
64
|
+
});
|
|
65
|
+
const i = document.createElement("div"), c = document.createElement("div"), g = document.createElement("div");
|
|
66
|
+
Object.assign(i.style, {
|
|
67
|
+
position: "absolute",
|
|
68
|
+
bottom: "-14px",
|
|
69
|
+
right: "28px",
|
|
70
|
+
width: "30px",
|
|
71
|
+
height: "20px",
|
|
72
|
+
pointerEvents: "none",
|
|
73
|
+
display: "none",
|
|
74
|
+
zIndex: "1"
|
|
75
|
+
}), Object.assign(c.style, {
|
|
76
|
+
position: "absolute",
|
|
77
|
+
bottom: "0",
|
|
78
|
+
left: "0",
|
|
79
|
+
right: "0",
|
|
80
|
+
margin: "0 auto",
|
|
81
|
+
width: "0",
|
|
82
|
+
height: "0",
|
|
83
|
+
borderLeft: "15px solid transparent",
|
|
84
|
+
borderRight: "15px solid transparent",
|
|
85
|
+
borderTop: "15px solid rgba(15,23,42,0.1)"
|
|
86
|
+
}), Object.assign(g.style, {
|
|
87
|
+
position: "absolute",
|
|
88
|
+
bottom: "2px",
|
|
89
|
+
left: "0",
|
|
90
|
+
right: "0",
|
|
91
|
+
margin: "0 auto",
|
|
92
|
+
width: "0",
|
|
93
|
+
height: "0",
|
|
94
|
+
borderLeft: "13px solid transparent",
|
|
95
|
+
borderRight: "13px solid transparent",
|
|
96
|
+
borderTop: "13px solid white",
|
|
97
|
+
boxShadow: "0 6px 16px rgba(15,23,42,0.12)",
|
|
98
|
+
borderRadius: "2px"
|
|
99
|
+
}), i.appendChild(c), i.appendChild(g);
|
|
100
|
+
const s = document.createElement("div");
|
|
101
|
+
Object.assign(s.style, {
|
|
102
|
+
width: `${C}px`,
|
|
103
|
+
maxWidth: "calc(100vw - 48px)",
|
|
104
|
+
// keep height responsive to viewport to avoid outer scrollbars
|
|
105
|
+
height: `${Math.min(C, Math.max(320, window.innerHeight - 140))}px`,
|
|
106
|
+
maxHeight: "calc(100vh - 150px)",
|
|
107
|
+
borderRadius: "20px",
|
|
108
|
+
background: "white",
|
|
109
|
+
border: "1px solid rgba(15,23,42,0.12)",
|
|
110
|
+
boxShadow: "0 18px 45px rgba(15,23,42,0.16)",
|
|
111
|
+
overflow: "hidden"
|
|
112
|
+
}), u.appendChild(s);
|
|
113
|
+
const d = document.createElement("iframe");
|
|
114
|
+
d.src = e, d.title = "Copilot chat widget", d.allow = "clipboard-read; clipboard-write; microphone; camera; display-capture", d.setAttribute("scrolling", "no"), Object.assign(d.style, {
|
|
115
|
+
width: "100%",
|
|
116
|
+
height: "100%",
|
|
117
|
+
border: "none",
|
|
118
|
+
display: "block",
|
|
119
|
+
background: "transparent",
|
|
120
|
+
overflow: "hidden"
|
|
121
|
+
}), u.appendChild(s), s.appendChild(d), o.appendChild(i), o.appendChild(s), document.body.appendChild(t), document.body.appendChild(o), window.addEventListener("message", (p) => {
|
|
122
|
+
p.data?.type === "WIDGET_READY" && d.contentWindow.postMessage(
|
|
123
|
+
{ type: "INIT_WIDGET" },
|
|
124
|
+
"*"
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
let l = !1;
|
|
128
|
+
const w = () => {
|
|
129
|
+
l && (l = !1, o.style.opacity = "0", o.style.transform = "scale(0.8) translateY(20px)", i.style.display = "none", setTimeout(() => {
|
|
130
|
+
o.style.display = "none";
|
|
131
|
+
}, 250), t.style.transform = "scale(1)");
|
|
132
|
+
};
|
|
133
|
+
t.onclick = (p) => {
|
|
134
|
+
p.stopPropagation(), l = !l, l ? (o.style.display = "block", i.style.display = "block", requestAnimationFrame(() => {
|
|
135
|
+
o.style.opacity = "1", o.style.transform = "scale(1) translateY(0)";
|
|
136
|
+
})) : w();
|
|
137
|
+
}, window.addEventListener("message", (p) => {
|
|
138
|
+
p?.data?.type === "CHAT_CLOSED" && w();
|
|
139
|
+
}), document.addEventListener("click", (p) => {
|
|
140
|
+
const x = p.target;
|
|
141
|
+
x && l && !o.contains(x) && x !== t && w();
|
|
142
|
+
});
|
|
143
|
+
const y = {
|
|
144
|
+
close: w,
|
|
145
|
+
open: () => {
|
|
146
|
+
l || t.click();
|
|
152
147
|
}
|
|
153
|
-
|
|
148
|
+
};
|
|
149
|
+
return window.CopilotChat = window.CopilotChat || {}, window.CopilotChat.close = y.close, window.CopilotChat.open = y.open, y;
|
|
150
|
+
}, f = (e) => {
|
|
151
|
+
console.error(`[CopilotChat] ${e}`);
|
|
152
|
+
}, U = () => E || Array.from(document.querySelectorAll("script")).reverse().find((r) => r.dataset?.token || r.src.includes("chat-widget")) || null;
|
|
153
|
+
I(async () => {
|
|
154
|
+
const e = U();
|
|
155
|
+
if (!e) {
|
|
156
|
+
f("Unable to locate the embedding script tag on the page.");
|
|
157
|
+
return;
|
|
154
158
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
})) : w();
|
|
160
|
-
}, document.addEventListener("click", (u) => {
|
|
161
|
-
const a = u.target;
|
|
162
|
-
a && p && !e.contains(a) && a !== o && w();
|
|
163
|
-
});
|
|
164
|
-
const g = {
|
|
165
|
-
close: w,
|
|
166
|
-
open: () => {
|
|
167
|
-
p || o.click();
|
|
159
|
+
const n = window.CopilotChatConfig || {}, r = e.dataset || {}, a = k(e), h = n.token || r.token || a.token;
|
|
160
|
+
if (!h) {
|
|
161
|
+
f("Missing token (provide via window.CopilotChatConfig.token or data-token attribute).");
|
|
162
|
+
return;
|
|
168
163
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return b("Missing token (provide via init config, window.CopilotChatConfig.token, or data-token attribute)."), null;
|
|
189
|
-
const o = S();
|
|
190
|
-
if (!o)
|
|
191
|
-
return b("Unable to resolve base URL from embedding script or window.location."), null;
|
|
192
|
-
try {
|
|
193
|
-
const e = await fetch(`${o}/api/chat-widget/config?token=${encodeURIComponent(f)}`, {
|
|
194
|
-
credentials: "omit",
|
|
195
|
-
mode: "cors"
|
|
196
|
-
});
|
|
197
|
-
if (!e.ok)
|
|
198
|
-
throw new Error(`Server responded with ${e.status}`);
|
|
199
|
-
const r = await e.json();
|
|
200
|
-
if (!r?.iframeUrl || !r?.launcherIcon)
|
|
201
|
-
throw new Error("Received incomplete widget configuration from server.");
|
|
202
|
-
const m = {
|
|
203
|
-
iframeUrl: r.iframeUrl,
|
|
204
|
-
launcherIcon: r.launcherIcon
|
|
205
|
-
};
|
|
206
|
-
return window.CopilotChat = window.CopilotChat || {}, window.CopilotChat.init = (c = {}) => {
|
|
207
|
-
const d = {
|
|
208
|
-
iframeUrl: c.iframeUrl || m.iframeUrl,
|
|
209
|
-
launcherIcon: c.launcherIcon || m.launcherIcon
|
|
164
|
+
const m = S(
|
|
165
|
+
v
|
|
166
|
+
), u = n.theme && n.theme.accent || n.accent || r.themeAccent || a.themeAccent;
|
|
167
|
+
try {
|
|
168
|
+
const t = await fetch(`${m}/api/chat-widget/config?token=${encodeURIComponent(h)}`, {
|
|
169
|
+
credentials: "omit",
|
|
170
|
+
mode: "cors"
|
|
171
|
+
});
|
|
172
|
+
if (!t.ok)
|
|
173
|
+
throw new Error(`Server responded with ${t.status}`);
|
|
174
|
+
const o = await t.json();
|
|
175
|
+
if (!o?.iframeUrl || !o?.launcherIcon)
|
|
176
|
+
throw new Error("Received incomplete widget configuration from server.");
|
|
177
|
+
const i = {
|
|
178
|
+
iframeUrl: o.iframeUrl,
|
|
179
|
+
launcherIcon: o.launcherIcon,
|
|
180
|
+
theme: {
|
|
181
|
+
accent: u || o.theme?.accent || void 0
|
|
182
|
+
}
|
|
210
183
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
184
|
+
window.CopilotChat = window.CopilotChat || {}, window.CopilotChat.init = (c = {}) => {
|
|
185
|
+
const g = {
|
|
186
|
+
accent: c.theme?.accent || c.accent || i.theme.accent || (typeof n.theme == "object" ? n.theme.accent : void 0) || n.accent
|
|
187
|
+
}, s = {
|
|
188
|
+
iframeUrl: c.iframeUrl || i.iframeUrl,
|
|
189
|
+
launcherIcon: c.launcherIcon || i.launcherIcon,
|
|
190
|
+
theme: g
|
|
191
|
+
};
|
|
192
|
+
return A(s);
|
|
193
|
+
}, window.CopilotChat.init(n);
|
|
194
|
+
} catch (t) {
|
|
195
|
+
f(t instanceof Error ? t.message : "Unknown error during widget bootstrap.");
|
|
196
|
+
}
|
|
223
197
|
});
|
|
224
|
-
});
|
|
225
|
-
I() && U();
|
|
226
|
-
export {
|
|
227
|
-
O as initCopilotChatWidget,
|
|
228
|
-
U as loadCopilotChatWidget,
|
|
229
|
-
E as resolveEmbeddingScript
|
|
230
|
-
};
|
|
198
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "copilot-chat-widget",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Embeddable Copilot chat widget that can be loaded via NPM or a script tag.",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "copilot-chat-widget",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Embeddable Copilot chat widget that can be loaded via NPM or a script tag.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"browser": "./dist/chat-widget.min.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"browser": "./dist/chat-widget.min.js",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./dist/chat-widget.min.js": "./dist/chat-widget.min.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "vite build --config ./vite.config.mjs",
|
|
23
|
+
"prepare": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"chat",
|
|
27
|
+
"widget",
|
|
28
|
+
"copilot",
|
|
29
|
+
"agentic",
|
|
30
|
+
"embed"
|
|
31
|
+
],
|
|
32
|
+
"author": "",
|
|
33
|
+
"license": "UNLICENSED",
|
|
34
|
+
"sideEffects": true,
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"vite": "^7.1.12"
|
|
40
|
+
}
|
|
41
|
+
}
|