@pluno/product-agent-web 0.1.8 → 0.1.9

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.
@@ -1,16 +1,16 @@
1
- import { PlunoProductAgent as K } from "./product-agent-sdk.js";
2
- const L = {
1
+ import { PlunoProductAgent as I } from "./product-agent-sdk.js";
2
+ const S = {
3
3
  launcherLabel: "Ask for anything...",
4
4
  accentColor: "#18181b",
5
5
  colorScheme: "light",
6
6
  position: "bottom-right"
7
7
  };
8
- async function G(e = {}) {
8
+ async function K(e = {}) {
9
9
  const t = {
10
- launcherLabel: e.launcherLabel ?? L.launcherLabel,
11
- accentColor: e.accentColor ?? L.accentColor,
12
- colorScheme: e.colorScheme ?? L.colorScheme,
13
- position: e.position ?? L.position,
10
+ launcherLabel: e.launcherLabel ?? S.launcherLabel,
11
+ accentColor: e.accentColor ?? S.accentColor,
12
+ colorScheme: e.colorScheme ?? S.colorScheme,
13
+ position: e.position ?? S.position,
14
14
  token: e.token,
15
15
  tokenProvider: e.tokenProvider,
16
16
  tokenEndpoint: e.tokenEndpoint,
@@ -21,7 +21,7 @@ async function G(e = {}) {
21
21
  const n = o.attachShadow({ mode: "open" }), a = document.createElement("div");
22
22
  a.className = `pluno-pa-widget pluno-pa-widget--${t.position}`, a.innerHTML = `
23
23
  <form class="pluno-pa-widget__launcher">
24
- <input class="pluno-pa-widget__launcher-input" type="text" placeholder="${W(t.launcherLabel)}" aria-label="${W(t.launcherLabel)}" />
24
+ <input class="pluno-pa-widget__launcher-input" type="text" placeholder="${B(t.launcherLabel)}" aria-label="${B(t.launcherLabel)}" />
25
25
  </form>
26
26
  <button type="button" class="pluno-pa-widget__close" aria-label="Close" hidden>
27
27
  <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
@@ -53,12 +53,12 @@ async function G(e = {}) {
53
53
  </form>
54
54
  </section>
55
55
  `, n.appendChild(a);
56
- const w = await R(), s = w.ownerDocument;
57
- w.appendChild(o), a.classList.add(`pluno-pa-widget--${t.colorScheme}`), F(n, t.accentColor);
58
- const l = a.querySelector(".pluno-pa-widget__launcher"), d = a.querySelector(".pluno-pa-widget__launcher-input"), r = a.querySelector(".pluno-pa-widget__panel"), u = a.querySelector(".pluno-pa-widget__close"), h = a.querySelector(".pluno-pa-widget__composer"), i = a.querySelector(".pluno-pa-widget__input"), p = a.querySelector(".pluno-pa-widget__send"), g = a.querySelector(".pluno-pa-widget__new-chat"), _ = a.querySelector(".pluno-pa-widget__timeline");
59
- if (!l || !d || !r || !u || !h || !i || !p || !g || !_)
56
+ const w = await J(), s = w.ownerDocument;
57
+ w.appendChild(o), a.classList.add(`pluno-pa-widget--${t.colorScheme}`), U(n, t.accentColor);
58
+ const l = a.querySelector(".pluno-pa-widget__launcher"), d = a.querySelector(".pluno-pa-widget__launcher-input"), i = a.querySelector(".pluno-pa-widget__panel"), u = a.querySelector(".pluno-pa-widget__close"), h = a.querySelector(".pluno-pa-widget__composer"), r = a.querySelector(".pluno-pa-widget__input"), p = a.querySelector(".pluno-pa-widget__send"), g = a.querySelector(".pluno-pa-widget__new-chat"), f = a.querySelector(".pluno-pa-widget__timeline");
59
+ if (!l || !d || !i || !u || !h || !r || !p || !g || !f)
60
60
  throw new Error("Failed to mount Product Agent widget");
61
- const b = t.token || t.webSocketFactory ? void 0 : t.tokenProvider ?? (async () => {
61
+ const _ = t.token || t.webSocketFactory ? void 0 : t.tokenProvider ?? (async () => {
62
62
  if (!t.tokenEndpoint)
63
63
  throw new Error("Product Agent widget requires token or tokenEndpoint");
64
64
  const c = await fetch(t.tokenEndpoint, {
@@ -69,99 +69,99 @@ async function G(e = {}) {
69
69
  });
70
70
  if (!c.ok)
71
71
  throw new Error("Failed to load Product Agent token");
72
- const y = await c.json();
73
- if (!y.token)
72
+ const v = await c.json();
73
+ if (!v.token)
74
74
  throw new Error("Product Agent token endpoint did not return a token");
75
- return y.token;
76
- }), m = await K.init({
75
+ return v.token;
76
+ }), m = await I.init({
77
77
  token: t.token,
78
- tokenProvider: b,
78
+ tokenProvider: _,
79
79
  backendUrl: t.backendUrl,
80
80
  webSocketFactory: t.webSocketFactory
81
- }), E = J(t), S = new Set(E.openToolGroupKeys);
82
- let x = null, N = !1;
81
+ }), C = Z(t), E = new Set(C.openToolGroupKeys);
82
+ let b = null, z = !1;
83
83
  const q = () => {
84
- N || typeof document > "u" || (F(n, t.accentColor), o.isConnected || s.body?.appendChild(o));
85
- }, P = new MutationObserver(q);
86
- P.observe(s.documentElement, { childList: !0, subtree: !0 });
87
- const v = () => {
88
- Z(t, {
84
+ z || typeof document > "u" || (U(n, t.accentColor), o.isConnected || s.body?.appendChild(o));
85
+ }, M = new MutationObserver(q);
86
+ M.observe(s.documentElement, { childList: !0, subtree: !0 });
87
+ const x = () => {
88
+ Q(t, {
89
89
  isOpen: a.classList.contains("pluno-pa-widget--open"),
90
- composerValue: i.value,
91
- openToolGroupKeys: [...S]
90
+ composerValue: r.value,
91
+ openToolGroupKeys: [...E]
92
92
  });
93
- }, k = (c = "", y = !0) => {
94
- if (x !== null && (window.clearTimeout(x), x = null), r.hidden = !1, u.hidden = !1, a.classList.remove("pluno-pa-widget--closing"), !y) {
95
- a.classList.add("pluno-pa-widget--open"), l.hidden = !0, c && (i.value = c, C(i)), i.focus(), i.setSelectionRange(i.value.length, i.value.length), v();
93
+ }, y = (c = "", v = !0) => {
94
+ if (b !== null && (window.clearTimeout(b), b = null), i.hidden = !1, u.hidden = !1, a.classList.remove("pluno-pa-widget--closing"), !v) {
95
+ a.classList.add("pluno-pa-widget--open"), l.hidden = !0, c && (r.value = c, k(r)), r.focus(), r.setSelectionRange(r.value.length, r.value.length), x();
96
96
  return;
97
97
  }
98
98
  window.requestAnimationFrame(() => {
99
- a.classList.add("pluno-pa-widget--open"), c && (i.value = c, C(i)), i.focus(), i.setSelectionRange(i.value.length, i.value.length), v(), x = window.setTimeout(() => {
99
+ a.classList.add("pluno-pa-widget--open"), c && (r.value = c, k(r)), r.focus(), r.setSelectionRange(r.value.length, r.value.length), x(), b = window.setTimeout(() => {
100
100
  l.hidden = !0;
101
101
  }, 220);
102
102
  });
103
- }, A = () => {
104
- x !== null && (window.clearTimeout(x), x = null), l.hidden = !1, a.classList.add("pluno-pa-widget--closing"), a.classList.remove("pluno-pa-widget--open"), v(), x = window.setTimeout(() => {
105
- r.hidden = !0, u.hidden = !0, a.classList.remove("pluno-pa-widget--closing");
103
+ }, N = () => {
104
+ b !== null && (window.clearTimeout(b), b = null), l.hidden = !1, a.classList.add("pluno-pa-widget--closing"), a.classList.remove("pluno-pa-widget--open"), x(), b = window.setTimeout(() => {
105
+ i.hidden = !0, u.hidden = !0, a.classList.remove("pluno-pa-widget--closing");
106
106
  }, 220);
107
107
  };
108
108
  l.addEventListener("submit", (c) => {
109
- c.preventDefault(), k(d.value), d.value = "";
109
+ c.preventDefault(), y(d.value), d.value = "";
110
110
  }), d.addEventListener("focus", () => {
111
- k(d.value), d.value = "";
111
+ y(d.value), d.value = "";
112
112
  }), d.addEventListener("input", () => {
113
113
  if (!d.value)
114
114
  return;
115
115
  const c = d.value;
116
- k(c), d.value = "";
117
- }), u.addEventListener("click", A);
118
- const M = (c) => {
116
+ y(c), d.value = "";
117
+ }), u.addEventListener("click", N);
118
+ const P = (c) => {
119
119
  if (!(!c.metaKey || c.key.toLowerCase() !== "k")) {
120
- if (c.preventDefault(), r.hidden || !a.classList.contains("pluno-pa-widget--open")) {
121
- k();
120
+ if (c.preventDefault(), i.hidden || !a.classList.contains("pluno-pa-widget--open")) {
121
+ y();
122
122
  return;
123
123
  }
124
- A();
124
+ N();
125
125
  }
126
126
  };
127
- return s.addEventListener("keydown", M), h.addEventListener("submit", (c) => {
128
- c.preventDefault(), z(m, i);
127
+ return s.addEventListener("keydown", P), h.addEventListener("submit", (c) => {
128
+ c.preventDefault(), T(m, r);
129
129
  }), p.addEventListener("click", () => {
130
130
  if (m.getState().isThinking) {
131
131
  m.stop();
132
132
  return;
133
133
  }
134
- z(m, i);
134
+ T(m, r);
135
135
  }), g.addEventListener("click", () => {
136
- m.startNewSession(), S.clear(), i.value = "", C(i), v(), i.focus();
137
- }), i.addEventListener("input", () => {
138
- C(i), v();
139
- }), i.addEventListener("keydown", (c) => {
140
- c.key !== "Enter" || c.shiftKey || (c.preventDefault(), z(m, i));
141
- }), E.composerValue && (i.value = E.composerValue, C(i)), E.isOpen && k(i.value, !1), m.on(
136
+ m.startNewSession(), E.clear(), r.value = "", k(r), x(), r.focus();
137
+ }), r.addEventListener("input", () => {
138
+ k(r), x();
139
+ }), r.addEventListener("keydown", (c) => {
140
+ c.key !== "Enter" || c.shiftKey || (c.preventDefault(), T(m, r));
141
+ }), C.composerValue && (r.value = C.composerValue, k(r)), C.isOpen && y(r.value, !1), m.on(
142
142
  "state",
143
- (c) => $(_, p, g, c, S, v, (y) => {
144
- m.sendMessage(y);
143
+ (c) => A(f, p, g, c, E, x, (v) => {
144
+ m.sendMessage(v);
145
145
  })
146
- ), $(_, p, g, m.getState(), S, v, (c) => {
146
+ ), A(f, p, g, m.getState(), E, x, (c) => {
147
147
  m.sendMessage(c);
148
148
  }), {
149
149
  agent: m,
150
150
  destroy: () => {
151
- N = !0, P.disconnect(), m.destroy(), s.removeEventListener("keydown", M), o.remove();
151
+ z = !0, M.disconnect(), m.destroy(), s.removeEventListener("keydown", P), o.remove();
152
152
  }
153
153
  };
154
154
  }
155
- function z(e, t) {
155
+ function T(e, t) {
156
156
  const o = t.value.trim();
157
157
  o && (t.value = "", t.style.height = "22px", t.style.overflowY = "hidden", e.sendMessage(o), t.dispatchEvent(new Event("input", { bubbles: !0 })));
158
158
  }
159
- function C(e) {
159
+ function k(e) {
160
160
  e.style.height = "0px";
161
161
  const t = Math.max(22, Math.min(e.scrollHeight, 140));
162
162
  e.style.height = `${t}px`, e.style.overflowY = e.scrollHeight > 140 ? "auto" : "hidden";
163
163
  }
164
- function $(e, t, o, n, a, w, s) {
164
+ function A(e, t, o, n, a, w, s) {
165
165
  const l = [...n.messages];
166
166
  e.innerHTML = "", V(t, n.isThinking);
167
167
  const d = l.length > 0 || !!n.assistantDraft;
@@ -170,25 +170,25 @@ function $(e, t, o, n, a, w, s) {
170
170
  p.className = n.starterPrompts.length > 0 ? "pluno-pa-widget__empty-state pluno-pa-widget__empty-state--starter" : "pluno-pa-widget__empty-state";
171
171
  const g = document.createElement("div");
172
172
  if (g.className = "pluno-pa-widget__empty", g.textContent = "What do you want to do today?", p.appendChild(g), n.starterPrompts.length > 0) {
173
- const _ = document.createElement("div");
174
- _.className = "pluno-pa-widget__starter-prompts";
175
- for (const b of n.starterPrompts) {
173
+ const f = document.createElement("div");
174
+ f.className = "pluno-pa-widget__starter-prompts";
175
+ for (const _ of n.starterPrompts) {
176
176
  const m = document.createElement("button");
177
- m.type = "button", m.className = "pluno-pa-widget__starter-prompt", m.textContent = `"${b}"`, m.addEventListener("click", () => {
178
- s(b);
179
- }), _.appendChild(m);
177
+ m.type = "button", m.className = "pluno-pa-widget__starter-prompt", m.textContent = `"${_}"`, m.addEventListener("click", () => {
178
+ s(_);
179
+ }), f.appendChild(m);
180
180
  }
181
- p.appendChild(_);
181
+ p.appendChild(f);
182
182
  }
183
183
  e.appendChild(p);
184
184
  return;
185
185
  }
186
- let r = null, u = null, h = [];
187
- const i = () => {
186
+ let i = null, u = null, h = [];
187
+ const r = () => {
188
188
  if (h.length === 0)
189
189
  return;
190
- const p = I(h, a, w);
191
- e.appendChild(p), r = null, u = p, h = [];
190
+ const p = R(h, a, w);
191
+ e.appendChild(p), i = null, u = p, h = [];
192
192
  };
193
193
  for (let p = 0; p < l.length; p += 1) {
194
194
  const g = l[p];
@@ -198,67 +198,67 @@ function $(e, t, o, n, a, w, s) {
198
198
  }
199
199
  if (g.role === "system")
200
200
  continue;
201
- i();
202
- const _ = O(g.content), b = document.createElement("div");
203
- b.className = `pluno-pa-widget__message pluno-pa-widget__message--${g.role}`, g.role === "assistant" ? B(b, _) : b.textContent = _, b.appendChild(D(_)), e.appendChild(b), r = b, u = null;
201
+ r();
202
+ const f = D(g.content), _ = document.createElement("div");
203
+ _.className = `pluno-pa-widget__message pluno-pa-widget__message--${g.role}`, g.role === "assistant" ? j(_, f) : _.textContent = f, _.appendChild($(f)), e.appendChild(_), i = _, u = null;
204
204
  }
205
- if (i(), n.assistantDraft) {
206
- const p = O(n.assistantDraft), g = document.createElement("div");
207
- g.className = "pluno-pa-widget__message pluno-pa-widget__message--assistant", B(g, p), g.appendChild(D(p)), e.appendChild(g), r = g, u = null;
205
+ if (r(), n.assistantDraft) {
206
+ const p = D(n.assistantDraft), g = document.createElement("div");
207
+ g.className = "pluno-pa-widget__message pluno-pa-widget__message--assistant", j(g, p), g.appendChild($(p)), e.appendChild(g), i = g, u = null;
208
208
  }
209
209
  if (n.isThinking && !n.assistantDraft) {
210
210
  const p = document.createElement("div");
211
- p.className = "pluno-pa-widget__status", p.textContent = "Thinking...", e.appendChild(p), r = null, u = p;
211
+ p.className = "pluno-pa-widget__status", p.textContent = "Thinking...", e.appendChild(p), i = null, u = p;
212
212
  }
213
213
  if (n.lastError) {
214
214
  const p = document.createElement("div");
215
- p.className = "pluno-pa-widget__error", p.textContent = n.lastError, e.appendChild(p), r = p, u = null;
215
+ p.className = "pluno-pa-widget__error", p.textContent = n.lastError, e.appendChild(p), i = p, u = null;
216
216
  }
217
- r?.classList.add("pluno-pa-widget__message--bottom-reserve"), u?.classList.add("pluno-pa-widget__bottom-reserve-compact"), e.scrollTop = e.scrollHeight;
217
+ i?.classList.add("pluno-pa-widget__message--bottom-reserve"), u?.classList.add("pluno-pa-widget__bottom-reserve-compact"), e.scrollTop = e.scrollHeight;
218
218
  }
219
- function D(e) {
219
+ function $(e) {
220
220
  const t = document.createElement("button");
221
221
  return t.type = "button", t.className = "pluno-pa-widget__message-copy", t.setAttribute("aria-label", "Copy message"), t.title = "Copy message", t.innerHTML = '<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"></rect><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"></path></svg>', t.addEventListener("click", (o) => {
222
222
  o.preventDefault(), o.stopPropagation(), navigator.clipboard.writeText(e);
223
223
  }), t;
224
224
  }
225
- function O(e) {
225
+ function D(e) {
226
226
  return e.replace(/\uE200[^\uE201]*(?:\uE201|$)/g, "");
227
227
  }
228
- function I(e, t, o) {
228
+ function R(e, t, o) {
229
229
  const n = document.createElement("article");
230
230
  n.className = "pluno-pa-widget__tool-group", n.title = new Date(e[e.length - 1].createdAt).toLocaleString();
231
- const a = document.createElement("details"), w = U(e);
231
+ const a = document.createElement("details"), w = G(e);
232
232
  a.open = t.has(w), a.addEventListener("toggle", () => {
233
233
  a.open ? t.add(w) : t.delete(w), o();
234
234
  });
235
235
  const s = document.createElement("summary");
236
- s.className = "pluno-pa-widget__tool-summary", e.some((r) => r.loading) && s.appendChild(j());
236
+ s.className = "pluno-pa-widget__tool-summary", e.some((i) => i.loading) && s.appendChild(O());
237
237
  const d = document.createElement("span");
238
238
  if (d.textContent = e[e.length - 1].content || "Run tool", s.appendChild(d), a.appendChild(s), e.length > 0) {
239
- const r = document.createElement("div");
240
- r.className = "pluno-pa-widget__tool-lines";
239
+ const i = document.createElement("div");
240
+ i.className = "pluno-pa-widget__tool-lines";
241
241
  for (const u of e) {
242
242
  const h = document.createElement("div");
243
- h.className = "pluno-pa-widget__tool-line", u.loading && h.appendChild(j());
244
- const i = document.createElement("span");
245
- i.textContent = u.content || "Run tool", h.appendChild(i), r.appendChild(h);
243
+ h.className = "pluno-pa-widget__tool-line", u.loading && h.appendChild(O());
244
+ const r = document.createElement("span");
245
+ r.textContent = u.content || "Run tool", h.appendChild(r), i.appendChild(h);
246
246
  }
247
- a.appendChild(r);
247
+ a.appendChild(i);
248
248
  }
249
249
  return n.appendChild(a), n;
250
250
  }
251
- function U(e) {
251
+ function G(e) {
252
252
  return `tools:${e.map((t) => t.id).join("|")}`;
253
253
  }
254
- function j() {
254
+ function O() {
255
255
  const e = document.createElement("span");
256
256
  return e.className = "pluno-pa-widget__spinner", e.setAttribute("aria-hidden", "true"), e;
257
257
  }
258
258
  function V(e, t) {
259
259
  e.setAttribute("aria-label", t ? "Stop" : "Send"), e.classList.toggle("pluno-pa-widget__send--stop", t), e.innerHTML = t ? '<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor" aria-hidden="true"><rect x="6" y="6" width="12" height="12" rx="2" /></svg>' : '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="12" y1="19" x2="12" y2="5" /><polyline points="5 12 12 5 19 12" /></svg>';
260
260
  }
261
- function B(e, t) {
261
+ function j(e, t) {
262
262
  const o = t.replace(/\r\n/g, `
263
263
  `).split(`
264
264
  `);
@@ -270,49 +270,49 @@ function B(e, t) {
270
270
  continue;
271
271
  }
272
272
  if (a.match(/^```(\w+)?\s*$/)) {
273
- const r = [];
273
+ const i = [];
274
274
  for (n += 1; n < o.length && !/^```\s*$/.test(o[n]); )
275
- r.push(o[n]), n += 1;
275
+ i.push(o[n]), n += 1;
276
276
  n += n < o.length ? 1 : 0;
277
277
  const u = document.createElement("pre"), h = document.createElement("code");
278
- h.textContent = r.join(`
278
+ h.textContent = i.join(`
279
279
  `), u.appendChild(h), e.appendChild(u);
280
280
  continue;
281
281
  }
282
282
  const s = a.match(/^(#{1,3})\s+(.+)$/);
283
283
  if (s) {
284
- const r = document.createElement(`h${s[1].length + 2}`);
285
- T(r, s[2]), e.appendChild(r), n += 1;
284
+ const i = document.createElement(`h${s[1].length + 2}`);
285
+ L(i, s[2]), e.appendChild(i), n += 1;
286
286
  continue;
287
287
  }
288
288
  if (/^\s*[-*+]\s+/.test(a)) {
289
- const r = document.createElement("ul");
289
+ const i = document.createElement("ul");
290
290
  for (; n < o.length && /^\s*[-*+]\s+/.test(o[n]); ) {
291
291
  const u = document.createElement("li");
292
- T(u, o[n].replace(/^\s*[-*+]\s+/, "")), r.appendChild(u), n += 1;
292
+ L(u, o[n].replace(/^\s*[-*+]\s+/, "")), i.appendChild(u), n += 1;
293
293
  }
294
- e.appendChild(r);
294
+ e.appendChild(i);
295
295
  continue;
296
296
  }
297
297
  if (/^\s*\d+\.\s+/.test(a)) {
298
- const r = document.createElement("ol");
298
+ const i = document.createElement("ol");
299
299
  for (; n < o.length && /^\s*\d+\.\s+/.test(o[n]); ) {
300
300
  const u = document.createElement("li");
301
- T(u, o[n].replace(/^\s*\d+\.\s+/, "")), r.appendChild(u), n += 1;
301
+ L(u, o[n].replace(/^\s*\d+\.\s+/, "")), i.appendChild(u), n += 1;
302
302
  }
303
- e.appendChild(r);
303
+ e.appendChild(i);
304
304
  continue;
305
305
  }
306
306
  const l = [a];
307
307
  for (n += 1; n < o.length && o[n].trim() && !/^```/.test(o[n]) && !/^(#{1,3})\s+/.test(o[n]) && !/^\s*[-*+]\s+/.test(o[n]) && !/^\s*\d+\.\s+/.test(o[n]); )
308
308
  l.push(o[n]), n += 1;
309
309
  const d = document.createElement("p");
310
- l.forEach((r, u) => {
311
- u > 0 && d.appendChild(document.createElement("br")), T(d, r);
310
+ l.forEach((i, u) => {
311
+ u > 0 && d.appendChild(document.createElement("br")), L(d, i);
312
312
  }), e.appendChild(d);
313
313
  }
314
314
  }
315
- function T(e, t) {
315
+ function L(e, t) {
316
316
  const o = /(`[^`]+`|\*\*[^*]+\*\*|\*[^*]+\*|\[[^\]]+\]\(([^)\s]+)\))/g;
317
317
  let n = 0;
318
318
  for (const a of t.matchAll(o)) {
@@ -350,7 +350,7 @@ function Y(e) {
350
350
  return !1;
351
351
  }
352
352
  }
353
- function F(e, t) {
353
+ function U(e, t) {
354
354
  if (e.getElementById("pluno-pa-widget-styles"))
355
355
  return;
356
356
  const o = e.ownerDocument.createElement("style");
@@ -1023,7 +1023,7 @@ function F(e, t) {
1023
1023
  }
1024
1024
  `, e.appendChild(o);
1025
1025
  }
1026
- async function R() {
1026
+ async function J() {
1027
1027
  return document.body ? document.body : await new Promise((e) => {
1028
1028
  const t = new MutationObserver(() => {
1029
1029
  document.body && (t.disconnect(), e(document.body));
@@ -1031,16 +1031,16 @@ async function R() {
1031
1031
  t.observe(document.documentElement, { childList: !0 });
1032
1032
  });
1033
1033
  }
1034
- function W(e) {
1034
+ function B(e) {
1035
1035
  const t = document.createElement("span");
1036
1036
  return t.textContent = e, t.innerHTML;
1037
1037
  }
1038
- function H(e) {
1038
+ function F(e) {
1039
1039
  return `pluno.productAgent.widgetState.${location.origin}.${e.backendUrl ?? ""}.${e.tokenEndpoint ?? ""}.${e.position ?? ""}`;
1040
1040
  }
1041
- function J(e) {
1041
+ function Z(e) {
1042
1042
  try {
1043
- const t = window.localStorage.getItem(H(e));
1043
+ const t = window.localStorage.getItem(F(e));
1044
1044
  if (!t)
1045
1045
  return { isOpen: !1, composerValue: "", openToolGroupKeys: [] };
1046
1046
  const o = JSON.parse(t);
@@ -1053,25 +1053,49 @@ function J(e) {
1053
1053
  return { isOpen: !1, composerValue: "", openToolGroupKeys: [] };
1054
1054
  }
1055
1055
  }
1056
- function Z(e, t) {
1056
+ function Q(e, t) {
1057
1057
  try {
1058
- window.localStorage.setItem(H(e), JSON.stringify(t));
1058
+ window.localStorage.setItem(F(e), JSON.stringify(t));
1059
1059
  } catch {
1060
1060
  return;
1061
1061
  }
1062
1062
  }
1063
- const f = document.currentScript;
1064
- f && f.dataset.plunoAutoMount !== "false" && G({
1065
- token: f?.dataset.plunoToken,
1066
- tokenEndpoint: f?.dataset.plunoTokenEndpoint,
1067
- backendUrl: f?.dataset.plunoBackendUrl,
1068
- launcherLabel: f?.dataset.plunoLauncherLabel,
1069
- accentColor: f?.dataset.plunoAccentColor,
1070
- colorScheme: f?.dataset.plunoColorScheme === "dark" ? "dark" : "light",
1071
- position: f?.dataset.plunoPosition === "bottom-left" ? "bottom-left" : "bottom-right"
1072
- }).catch((e) => {
1073
- console.error("Failed to mount Pluno Product Agent widget", e);
1074
- });
1063
+ const W = /* @__PURE__ */ new WeakSet();
1064
+ function X(e) {
1065
+ return Object.keys(e.dataset).some((t) => t.startsWith("pluno"));
1066
+ }
1067
+ function H(e) {
1068
+ const t = e.pathname.split("/");
1069
+ return t[t.length - 1] ?? "";
1070
+ }
1071
+ function ee(e, t) {
1072
+ const o = new URL(e.src, document.baseURI);
1073
+ return o.href === t.href || o.pathname === t.pathname ? !0 : H(o) === H(t);
1074
+ }
1075
+ function te(e) {
1076
+ const t = document.currentScript;
1077
+ if (t instanceof HTMLScriptElement)
1078
+ return [t];
1079
+ const o = new URL(e, document.baseURI).href, n = new URL(o);
1080
+ return [...document.querySelectorAll("script[type='module'][src]")].filter(
1081
+ (a) => a instanceof HTMLScriptElement && X(a) && ee(a, n)
1082
+ );
1083
+ }
1084
+ function ne(e) {
1085
+ for (const t of te(e))
1086
+ W.has(t) || t.dataset.plunoAutoMount === "false" || (W.add(t), K({
1087
+ token: t.dataset.plunoToken,
1088
+ tokenEndpoint: t.dataset.plunoTokenEndpoint,
1089
+ backendUrl: t.dataset.plunoBackendUrl,
1090
+ launcherLabel: t.dataset.plunoLauncherLabel,
1091
+ accentColor: t.dataset.plunoAccentColor,
1092
+ colorScheme: t.dataset.plunoColorScheme === "dark" ? "dark" : "light",
1093
+ position: t.dataset.plunoPosition === "bottom-left" ? "bottom-left" : "bottom-right"
1094
+ }).catch((o) => {
1095
+ console.error("Failed to mount Pluno Product Agent widget", o);
1096
+ }));
1097
+ }
1098
+ ne(import.meta.url);
1075
1099
  export {
1076
- G as mountPlunoProductAgentWidget
1100
+ K as mountPlunoProductAgentWidget
1077
1101
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluno/product-agent-web",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Browser SDK and default widget for embedding Pluno Product Agent into customer web apps.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",