@cloudflare/ai-search-snippet 0.0.29 → 0.0.31

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,6 +1,6 @@
1
- var H = Object.defineProperty;
2
- var N = (o, i, e) => i in o ? H(o, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[i] = e;
3
- var a = (o, i, e) => N(o, typeof i != "symbol" ? i + "" : i, e);
1
+ var P = Object.defineProperty;
2
+ var O = (n, i, e) => i in n ? P(n, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[i] = e;
3
+ var a = (n, i, e) => O(n, typeof i != "symbol" ? i + "" : i, e);
4
4
  const u = [
5
5
  "Searching...",
6
6
  "Digging through results...",
@@ -13,24 +13,24 @@ const u = [
13
13
  "Rummaging through pages...",
14
14
  "Hunting down answers..."
15
15
  ];
16
- function A(o, i) {
16
+ function $(n, i) {
17
17
  let e;
18
- return function(...s) {
19
- const r = () => {
20
- clearTimeout(e), o(...s);
21
- };
22
- clearTimeout(e), e = setTimeout(r, i);
23
- };
18
+ function t(...s) {
19
+ clearTimeout(e), e = setTimeout(() => {
20
+ n(...s);
21
+ }, i);
22
+ }
23
+ return t.cancel = () => clearTimeout(e), t;
24
24
  }
25
- function h(o) {
25
+ function h(n) {
26
26
  const i = document.createElement("div");
27
- return i.textContent = o, i.innerHTML;
27
+ return i.textContent = n, i.innerHTML;
28
28
  }
29
- function S(o) {
30
- return new DOMParser().parseFromString(o, "text/html").documentElement.textContent || "";
29
+ function E(n) {
30
+ return new DOMParser().parseFromString(n, "text/html").documentElement.textContent || "";
31
31
  }
32
- function P(o) {
33
- const i = new Date(o), t = (/* @__PURE__ */ new Date()).getTime() - i.getTime();
32
+ function _(n) {
33
+ const i = new Date(n), t = (/* @__PURE__ */ new Date()).getTime() - i.getTime();
34
34
  if (t < 6e4)
35
35
  return "Just now";
36
36
  if (t < 36e5) {
@@ -48,60 +48,90 @@ function P(o) {
48
48
  minute: "2-digit"
49
49
  });
50
50
  }
51
- function $(o) {
52
- return new Date(o).toLocaleDateString(void 0, {
51
+ function q(n) {
52
+ return new Date(n).toLocaleDateString(void 0, {
53
53
  month: "short",
54
54
  day: "numeric"
55
55
  });
56
56
  }
57
- function E(o = "id") {
58
- return `${o}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
57
+ function M(n = "id") {
58
+ return `${n}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
59
59
  }
60
- function d(o, i) {
61
- return o !== null ? o : i;
60
+ function d(n, i) {
61
+ return n !== null ? n : i;
62
62
  }
63
- function g(o, i) {
64
- return o === null ? i : o === "true" || o === "";
63
+ function m(n, i) {
64
+ return n === null ? i : n === "true" || n === "";
65
65
  }
66
- function w(o, i) {
67
- if (o === null) return i;
68
- const e = Number.parseInt(o, 10);
66
+ function y(n, i) {
67
+ if (n === null) return i;
68
+ const e = Number.parseInt(n, 10);
69
69
  return Number.isNaN(e) ? i : e;
70
70
  }
71
- function m(o, i) {
72
- return new CustomEvent(o, {
71
+ function v(n, i) {
72
+ return new CustomEvent(n, {
73
73
  detail: i,
74
74
  bubbles: !0,
75
75
  composed: !0,
76
76
  cancelable: !0
77
77
  });
78
78
  }
79
- function x(o) {
80
- if (!o)
79
+ function x(n) {
80
+ if (!n)
81
81
  throw new Error("API URL is required");
82
- return new _(o);
83
- }
84
- class _ {
82
+ return new V(n);
83
+ }
84
+ function w(n) {
85
+ return n !== null && typeof n == "object" && !Array.isArray(n);
86
+ }
87
+ function B(...n) {
88
+ const i = {};
89
+ for (const e of n)
90
+ if (e)
91
+ for (const [t, s] of Object.entries(e)) {
92
+ const r = i[t];
93
+ w(r) && w(s) ? i[t] = B(r, s) : i[t] = s;
94
+ }
95
+ return i;
96
+ }
97
+ function U(n, i) {
98
+ if (!w(i))
99
+ return n;
100
+ const e = new URLSearchParams();
101
+ for (const [l, g] of Object.entries(i))
102
+ g != null && e.append(l, String(g));
103
+ const t = e.toString();
104
+ if (!t)
105
+ return n;
106
+ const s = n.indexOf("#"), r = s === -1 ? n : n.slice(0, s), o = s === -1 ? "" : n.slice(s), c = r.includes("?") ? "&" : "?";
107
+ return `${r}${c}${t}${o}`;
108
+ }
109
+ function D(n) {
110
+ if (!w(n))
111
+ return {};
112
+ const i = {};
113
+ for (const [e, t] of Object.entries(n))
114
+ t != null && (i[e] = String(t));
115
+ return i;
116
+ }
117
+ function j(n) {
118
+ return w(n) ? n : void 0;
119
+ }
120
+ class V {
85
121
  constructor(i) {
86
122
  a(this, "activeRequests", /* @__PURE__ */ new Map());
87
123
  a(this, "baseUrl");
88
124
  this.baseUrl = i.replace(/\/$/, "");
89
125
  }
90
- request(i = {}, e, t) {
91
- const s = e === "search" ? "snippet-search" : "snippet-chat-completions";
92
- return fetch(`${this.baseUrl}/${e}`, {
126
+ request(i, e, t, s) {
127
+ const r = e === "search" ? "snippet-search" : "snippet-chat-completions", o = U(`${this.baseUrl}/${e}`, s?.queryParams);
128
+ return fetch(o, {
93
129
  method: "POST",
94
- body: JSON.stringify({
95
- messages: [{ role: "user", content: i.query }],
96
- stream: i.streaming,
97
- max_results: i.maxResults,
98
- ...e === "search" && {
99
- ai_search_options: { retrieval: { metadata_only: !0 } }
100
- }
101
- }),
130
+ body: JSON.stringify(B(j(s?.body), i)),
102
131
  headers: {
132
+ ...D(s?.headers),
103
133
  "Content-Type": "application/json",
104
- "cf-ai-search-source": s
134
+ "cf-ai-search-source": r
105
135
  },
106
136
  signal: t
107
137
  });
@@ -113,27 +143,33 @@ class _ {
113
143
  const t = this.generateRequestId(), s = new AbortController(), r = e.signal || s.signal;
114
144
  this.registerRequest(t, s);
115
145
  try {
116
- const n = await this.request(
146
+ const o = await this.request(
117
147
  {
118
- query: i,
119
- streaming: !1,
120
- maxResults: e.maxResults || 30
148
+ messages: [{ role: "user", content: i }],
149
+ stream: !1,
150
+ max_results: e.maxResults ?? 30,
151
+ ai_search_options: {
152
+ retrieval: {
153
+ metadata_only: !0
154
+ }
155
+ }
121
156
  },
122
157
  "search",
123
- r
158
+ r,
159
+ e.request
124
160
  );
125
- if (!n.ok)
126
- throw new Error(`HTTP error! status: ${n.status}`);
127
- if (!n.body)
161
+ if (!o.ok)
162
+ throw new Error(`HTTP error! status: ${o.status}`);
163
+ if (!o.body)
128
164
  throw new Error("Response body is empty");
129
- const c = await n.json();
165
+ const c = await o.json();
130
166
  if (c.success && c.result)
131
167
  return c.result.chunks.map(
132
168
  (l) => ({
133
169
  type: "result",
134
170
  id: l.id,
135
- title: S(l.item.metadata?.title),
136
- description: l.item.metadata?.description ? S(l.item.metadata?.description) : "",
171
+ title: E(l.item.metadata?.title),
172
+ description: l.item.metadata?.description ? E(l.item.metadata?.description) : "",
137
173
  timestamp: l.item.timestamp ?? void 0,
138
174
  url: l.item.key,
139
175
  image: l.item.metadata?.image || void 0,
@@ -145,29 +181,33 @@ class _ {
145
181
  this.unregisterRequest(t);
146
182
  }
147
183
  }
148
- async *searchStream(i, e) {
149
- const t = this.generateRequestId(), s = new AbortController(), r = e?.signal || s.signal;
184
+ async *searchStream(i, e = {}) {
185
+ const t = this.generateRequestId(), s = new AbortController(), r = e.signal || s.signal;
150
186
  this.registerRequest(t, s);
151
- const n = await this.request(
187
+ const o = await this.request(
152
188
  {
153
- query: i,
154
- streaming: !0
189
+ messages: [{ role: "user", content: i }],
190
+ stream: !0,
191
+ ...e.maxResults !== void 0 && {
192
+ max_results: e.maxResults
193
+ }
155
194
  },
156
195
  "ai-search",
157
- r
196
+ r,
197
+ e.request
158
198
  );
159
- if (!n.ok)
160
- throw new Error(`HTTP error! status: ${n.status}`);
161
- if (!n.body)
199
+ if (!o.ok)
200
+ throw new Error(`HTTP error! status: ${o.status}`);
201
+ if (!o.body)
162
202
  throw new Error("Response body is empty");
163
203
  let c = "";
164
- const l = n.body.getReader(), v = new TextDecoder();
204
+ const l = o.body.getReader(), g = new TextDecoder();
165
205
  for (; ; ) {
166
- const { done: p, value: C } = await l.read();
206
+ const { done: p, value: S } = await l.read();
167
207
  if (p)
168
208
  break;
169
- const R = v.decode(C, { stream: !0 });
170
- c += R;
209
+ const N = g.decode(S, { stream: !0 });
210
+ c += N;
171
211
  }
172
212
  yield {
173
213
  type: "result",
@@ -183,8 +223,8 @@ class _ {
183
223
  async *chat(i, e) {
184
224
  const t = new AbortController(), s = e?.signal || t.signal, r = await this.request(
185
225
  {
186
- query: i,
187
- streaming: !1
226
+ messages: [{ role: "user", content: i }],
227
+ stream: !1
188
228
  },
189
229
  "chat/completions",
190
230
  s
@@ -235,10 +275,10 @@ class _ {
235
275
  return `req-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
236
276
  }
237
277
  }
238
- const D = `<svg width="32" height="10" viewBox="0 0 412 186" xmlns="http://www.w3.org/2000/svg" aria-label="Cloudflare" role="img">
278
+ const K = `<svg width="32" height="10" viewBox="0 0 412 186" xmlns="http://www.w3.org/2000/svg" aria-label="Cloudflare" role="img">
239
279
  <path fill="#f38020" d="m280.8395,183.31456c11,-26 -4,-38 -19,-38l-148,-2c-4,0 -4,-6 1,-7l150,-2c17,-1 37,-15 43,-33c0,0 10,-21 9,-24a97,97 0 0 0 -187,-11c-38,-25 -78,9 -69,46c-48,3 -65,46 -60,72c0,1 1,2 3,2l274,0c1,0 3,-1 3,-3z"/>
240
280
  <path fill="#faae40" d="m330.8395,81.31456c-4,0 -6,-1 -7,1l-5,21c-5,16 3,30 20,31l32,2c4,0 4,6 -1,7l-33,1c-36,4 -46,39 -46,39c0,2 0,3 2,3l113,0l3,-2a81,81 0 0 0 -78,-103"/>
241
- </svg>`, U = "https://workers.cloudflare.com/product/ai-search", y = `Powered by <a href="${U}" target="_blank" rel="noopener noreferrer">Cloudflare AI Search ${D}</a>`, q = `
281
+ </svg>`, G = "https://workers.cloudflare.com/product/ai-search", k = `Powered by <a href="${G}" target="_blank" rel="noopener noreferrer">Cloudflare AI Search ${K}</a>`, R = `
242
282
  /* Chat container */
243
283
  .chat-container {
244
284
  display: flex;
@@ -555,7 +595,7 @@ const D = `<svg width="32" height="10" viewBox="0 0 412 186" xmlns="http://www.w
555
595
  .chat-message-bubble a:hover {
556
596
  text-decoration: none;
557
597
  }
558
- `, k = `
598
+ `, C = `
559
599
  :host {
560
600
  /* Colors - Light Mode */
561
601
  --search-snippet-primary-color: #2563eb;
@@ -990,17 +1030,17 @@ const D = `<svg width="32" height="10" viewBox="0 0 412 186" xmlns="http://www.w
990
1030
  text-align: center;
991
1031
  }
992
1032
  `;
993
- function V(o) {
994
- let i = o;
995
- i = j(i), i = i.replace(/```([\s\S]*?)```/g, (n, c) => `<pre><code>${c.trim()}</code></pre>`);
1033
+ function F(n) {
1034
+ let i = n;
1035
+ i = Y(i), i = i.replace(/```([\s\S]*?)```/g, (o, c) => `<pre><code>${c.trim()}</code></pre>`);
996
1036
  const e = i.split(`
997
1037
  `), t = [];
998
1038
  let s = !1, r = "";
999
- for (let n = 0; n < e.length; n++) {
1000
- const c = e[n], l = c.match(/^(#{1,6})\s+(.+)$/);
1039
+ for (let o = 0; o < e.length; o++) {
1040
+ const c = e[o], l = c.match(/^(#{1,6})\s+(.+)$/);
1001
1041
  if (l) {
1002
- const p = l[1].length, C = l[2];
1003
- t.push(`<h${p}>${f(C)}</h${p}>`);
1042
+ const p = l[1].length, S = l[2];
1043
+ t.push(`<h${p}>${f(S)}</h${p}>`);
1004
1044
  continue;
1005
1045
  }
1006
1046
  if (c.match(/^---+$/)) {
@@ -1012,9 +1052,9 @@ function V(o) {
1012
1052
  t.push(`<blockquote>${f(p)}</blockquote>`);
1013
1053
  continue;
1014
1054
  }
1015
- const v = c.match(/^[-*]\s+(.+)$/);
1016
- if (v) {
1017
- (!s || r !== "ul") && (s && t.push(`</${r}>`), t.push("<ul>"), s = !0, r = "ul"), t.push(`<li>${f(v[1])}</li>`);
1055
+ const g = c.match(/^[-*]\s+(.+)$/);
1056
+ if (g) {
1057
+ (!s || r !== "ul") && (s && t.push(`</${r}>`), t.push("<ul>"), s = !0, r = "ul"), t.push(`<li>${f(g[1])}</li>`);
1018
1058
  continue;
1019
1059
  }
1020
1060
  const b = c.match(/^\d+\.\s+(.+)$/);
@@ -1031,14 +1071,14 @@ function V(o) {
1031
1071
  return s && t.push(`</${r}>`), t.join(`
1032
1072
  `);
1033
1073
  }
1034
- function f(o) {
1035
- let i = o;
1074
+ function f(n) {
1075
+ let i = n;
1036
1076
  return i = i.replace(/`([^`]+)`/g, "<code>$1</code>"), i = i.replace(/\*\*\*(.+?)\*\*\*/g, "<strong><em>$1</em></strong>"), i = i.replace(/___(.+?)___/g, "<strong><em>$1</em></strong>"), i = i.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>"), i = i.replace(/__(.+?)__/g, "<strong>$1</strong>"), i = i.replace(/\*(.+?)\*/g, "<em>$1</em>"), i = i.replace(/_(.+?)_/g, "<em>$1</em>"), i = i.replace(
1037
1077
  /\[([^\]]+)\]\(([^)]+)\)/g,
1038
1078
  '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'
1039
1079
  ), i;
1040
1080
  }
1041
- function j(o) {
1081
+ function Y(n) {
1042
1082
  const i = {
1043
1083
  "&": "&amp;",
1044
1084
  "<": "&lt;",
@@ -1046,9 +1086,9 @@ function j(o) {
1046
1086
  '"': "&quot;",
1047
1087
  "'": "&#39;"
1048
1088
  };
1049
- return o.replace(/[&<>"']/g, (e) => i[e] || e);
1089
+ return n.replace(/[&<>"']/g, (e) => i[e] || e);
1050
1090
  }
1051
- class B {
1091
+ class H {
1052
1092
  constructor(i, e, t) {
1053
1093
  a(this, "container");
1054
1094
  a(this, "client");
@@ -1127,13 +1167,13 @@ class B {
1127
1167
  */
1128
1168
  async sendMessage(i) {
1129
1169
  const e = {
1130
- id: E("msg"),
1170
+ id: M("msg"),
1131
1171
  role: "user",
1132
1172
  content: i,
1133
1173
  timestamp: Date.now()
1134
1174
  };
1135
1175
  this.addMessage(e), this.renderMessages(!0), this.setStreamingState(!0);
1136
- const t = E("msg"), s = {
1176
+ const t = M("msg"), s = {
1137
1177
  id: t,
1138
1178
  role: "assistant",
1139
1179
  content: "",
@@ -1142,19 +1182,19 @@ class B {
1142
1182
  this.addMessage(s), this.currentStreamingMessageId = t, this.renderMessages(!0);
1143
1183
  try {
1144
1184
  const r = this.client.chat(i);
1145
- let n = "";
1185
+ let o = "";
1146
1186
  for await (const l of r)
1147
1187
  if (l.type === "text" && l.message)
1148
- n += l.message, this.updateStreamingMessage(t, n);
1188
+ o += l.message, this.updateStreamingMessage(t, o);
1149
1189
  else if (l.type === "error") {
1150
1190
  this.showErrorInMessage(t, l.message || "Unknown error");
1151
1191
  break;
1152
1192
  }
1153
1193
  const c = this.messages.findIndex((l) => l.id === t);
1154
- c !== -1 && (this.messages[c].content = n), this.container.dispatchEvent(m("message", { message: s }));
1194
+ c !== -1 && (this.messages[c].content = o), this.container.dispatchEvent(v("message", { message: s }));
1155
1195
  } catch (r) {
1156
1196
  this.showErrorInMessage(t, r.message), this.container.dispatchEvent(
1157
- m("error", {
1197
+ v("error", {
1158
1198
  error: {
1159
1199
  message: r.message,
1160
1200
  code: "CHAT_ERROR"
@@ -1219,11 +1259,11 @@ class B {
1219
1259
  <div class="chat-message-avatar">${s}</div>
1220
1260
  <div class="chat-message-content">
1221
1261
  <div class="chat-message-bubble">
1222
- ${i.content ? `<div class="chat-message-text">${V(i.content)}</div>` : ""}
1262
+ ${i.content ? `<div class="chat-message-text">${F(i.content)}</div>` : ""}
1223
1263
  ${e ? `<div class="chat-streaming"><span class="chat-streaming-dot"></span><span class="chat-streaming-dot"></span><span class="chat-streaming-dot"></span><span class="loading-text">${u[this.loadingMessageIndex]}</span></div>` : ""}
1224
1264
  </div>
1225
1265
  <div class="chat-message-metadata">
1226
- <span class="chat-message-time">${P(i.timestamp)}</span>
1266
+ <span class="chat-message-time">${_(i.timestamp)}</span>
1227
1267
  </div>
1228
1268
  </div>
1229
1269
  </div>
@@ -1276,8 +1316,8 @@ class B {
1276
1316
  this.clearLoadingMessages(), this.isStreaming && this.client.cancelAllRequests(), this.inputElement && (this.handleInputResize && this.inputElement.removeEventListener("input", this.handleInputResize), this.handleInputKeydown && this.inputElement.removeEventListener("keydown", this.handleInputKeydown)), this.sendButton && this.handleSendClick && this.sendButton.removeEventListener("click", this.handleSendClick), this.handleInputResize = null, this.handleInputKeydown = null, this.handleSendClick = null;
1277
1317
  }
1278
1318
  }
1279
- const M = "chat-bubble-snippet";
1280
- class O extends HTMLElement {
1319
+ const L = "chat-bubble-snippet";
1320
+ class J extends HTMLElement {
1281
1321
  constructor() {
1282
1322
  super();
1283
1323
  a(this, "shadow");
@@ -1297,7 +1337,7 @@ class O extends HTMLElement {
1297
1337
  return ["api-url", "placeholder", "theme", "hide-branding"];
1298
1338
  }
1299
1339
  connectedCallback() {
1300
- this.render(), this.initializeClient(), this.dispatchEvent(m("ready", void 0));
1340
+ this.render(), this.initializeClient(), this.dispatchEvent(v("ready", void 0));
1301
1341
  }
1302
1342
  disconnectedCallback() {
1303
1343
  this.cleanup();
@@ -1310,7 +1350,7 @@ class O extends HTMLElement {
1310
1350
  apiUrl: d(this.getAttribute("api-url"), ""),
1311
1351
  placeholder: d(this.getAttribute("placeholder"), "Type a message..."),
1312
1352
  theme: d(this.getAttribute("theme"), "auto"),
1313
- hideBranding: g(this.getAttribute("hide-branding"), !1)
1353
+ hideBranding: m(this.getAttribute("hide-branding"), !1)
1314
1354
  };
1315
1355
  }
1316
1356
  initializeClient() {
@@ -1327,8 +1367,8 @@ class O extends HTMLElement {
1327
1367
  }
1328
1368
  render() {
1329
1369
  const e = document.createElement("style");
1330
- e.textContent = `${k}
1331
- ${q}
1370
+ e.textContent = `${C}
1371
+ ${R}
1332
1372
  ${this.getBubbleStyles()}`, this.container = document.createElement("div"), this.container.className = "chat-bubble-widget", this.container.innerHTML = this.getBaseHTML(), this.shadow.innerHTML = "", this.shadow.appendChild(e), this.shadow.appendChild(this.container), this.attachEventListeners();
1333
1373
  }
1334
1374
  getBubbleStyles() {
@@ -1508,7 +1548,7 @@ ${this.getBubbleStyles()}`, this.container = document.createElement("div"), this
1508
1548
  </div>
1509
1549
  </div>
1510
1550
  <div class="chat-content"></div>
1511
- ${this.getProps().hideBranding ? "" : `<div class="powered-by">${y}</div>`}
1551
+ ${this.getProps().hideBranding ? "" : `<div class="powered-by">${k}</div>`}
1512
1552
  </div>
1513
1553
  `;
1514
1554
  }
@@ -1548,7 +1588,7 @@ ${this.getBubbleStyles()}`, this.container = document.createElement("div"), this
1548
1588
  return;
1549
1589
  }
1550
1590
  const t = this.getProps();
1551
- this.chatView = new B(e, this.client, t);
1591
+ this.chatView = new H(e, this.client, t);
1552
1592
  }
1553
1593
  updateTheme(e) {
1554
1594
  (e === "light" || e === "dark" ? e : null) === null && this.hasAttribute("theme") && this.getAttribute("theme") !== "auto" && this.removeAttribute("theme");
@@ -1567,9 +1607,9 @@ ${this.getBubbleStyles()}`, this.container = document.createElement("div"), this
1567
1607
  return this.chatView?.getMessages() || [];
1568
1608
  }
1569
1609
  }
1570
- customElements.get(M) || customElements.define(M, O);
1571
- const L = "chat-page-snippet", I = "chat-page-sessions";
1572
- class K extends HTMLElement {
1610
+ customElements.get(L) || customElements.define(L, J);
1611
+ const I = "chat-page-snippet", z = "chat-page-sessions";
1612
+ class W extends HTMLElement {
1573
1613
  constructor() {
1574
1614
  super();
1575
1615
  a(this, "shadow");
@@ -1591,7 +1631,7 @@ class K extends HTMLElement {
1591
1631
  return ["api-url", "placeholder", "theme", "hide-branding"];
1592
1632
  }
1593
1633
  connectedCallback() {
1594
- this.render(), this.initializeClient(), this.setupView(), this.dispatchEvent(m("ready", void 0));
1634
+ this.render(), this.initializeClient(), this.setupView(), this.dispatchEvent(v("ready", void 0));
1595
1635
  }
1596
1636
  disconnectedCallback() {
1597
1637
  this.saveCurrentSession(), this.cleanup();
@@ -1604,7 +1644,7 @@ class K extends HTMLElement {
1604
1644
  apiUrl: d(this.getAttribute("api-url"), ""),
1605
1645
  placeholder: d(this.getAttribute("placeholder"), "Type a message..."),
1606
1646
  theme: d(this.getAttribute("theme"), "auto"),
1607
- hideBranding: g(this.getAttribute("hide-branding"), !1)
1647
+ hideBranding: m(this.getAttribute("hide-branding"), !1)
1608
1648
  };
1609
1649
  }
1610
1650
  initializeClient() {
@@ -1621,8 +1661,8 @@ class K extends HTMLElement {
1621
1661
  }
1622
1662
  render() {
1623
1663
  const e = document.createElement("style");
1624
- e.textContent = `${k}
1625
- ${q}
1664
+ e.textContent = `${C}
1665
+ ${R}
1626
1666
  ${this.getPageStyles()}`, this.container = document.createElement("div"), this.container.className = "chat-page-container", this.container.innerHTML = this.getBaseHTML(), this.shadow.innerHTML = "", this.shadow.appendChild(e), this.shadow.appendChild(this.container), this.attachEventListeners();
1627
1667
  }
1628
1668
  getPageStyles() {
@@ -1914,7 +1954,7 @@ ${this.getPageStyles()}`, this.container = document.createElement("div"), this.c
1914
1954
  New Chat
1915
1955
  </button>
1916
1956
  <div class="chat-list"></div>
1917
- ${this.getProps().hideBranding ? "" : `<div class="powered-by">${y}</div>`}
1957
+ ${this.getProps().hideBranding ? "" : `<div class="powered-by">${k}</div>`}
1918
1958
  </div>
1919
1959
  <div class="chat-main">
1920
1960
  <div class="chat-page-header">
@@ -1948,11 +1988,11 @@ ${this.getPageStyles()}`, this.container = document.createElement("div"), this.c
1948
1988
  }
1949
1989
  attachEventListeners() {
1950
1990
  const e = this.shadow.querySelector(".clear-button"), t = this.shadow.querySelector(".new-chat-button"), s = this.shadow.querySelector(".toggle-sidebar-button"), r = this.shadow.querySelector(".chat-list");
1951
- this.handleClearClick = () => this.clearCurrentChat(), this.handleNewChatClick = () => this.createNewChat(), this.handleToggleSidebarClick = () => this.toggleSidebar(), this.handleChatListClick = (n) => this.onChatListClick(n), e?.addEventListener("click", this.handleClearClick), t?.addEventListener("click", this.handleNewChatClick), s?.addEventListener("click", this.handleToggleSidebarClick), r?.addEventListener("click", this.handleChatListClick);
1991
+ this.handleClearClick = () => this.clearCurrentChat(), this.handleNewChatClick = () => this.createNewChat(), this.handleToggleSidebarClick = () => this.toggleSidebar(), this.handleChatListClick = (o) => this.onChatListClick(o), e?.addEventListener("click", this.handleClearClick), t?.addEventListener("click", this.handleNewChatClick), s?.addEventListener("click", this.handleToggleSidebarClick), r?.addEventListener("click", this.handleChatListClick);
1952
1992
  }
1953
1993
  removeEventListeners() {
1954
- const e = this.shadow.querySelector(".clear-button"), t = this.shadow.querySelector(".new-chat-button"), s = this.shadow.querySelector(".toggle-sidebar-button"), r = this.shadow.querySelector(".chat-list"), n = this.shadow.querySelector(".container");
1955
- this.handleClearClick && e?.removeEventListener("click", this.handleClearClick), this.handleNewChatClick && t?.removeEventListener("click", this.handleNewChatClick), this.handleToggleSidebarClick && s?.removeEventListener("click", this.handleToggleSidebarClick), this.handleChatListClick && r?.removeEventListener("click", this.handleChatListClick), this.handleMessageEvent && n && n.removeEventListener("message", this.handleMessageEvent), this.handleClearClick = null, this.handleNewChatClick = null, this.handleToggleSidebarClick = null, this.handleChatListClick = null, this.handleMessageEvent = null;
1994
+ const e = this.shadow.querySelector(".clear-button"), t = this.shadow.querySelector(".new-chat-button"), s = this.shadow.querySelector(".toggle-sidebar-button"), r = this.shadow.querySelector(".chat-list"), o = this.shadow.querySelector(".container");
1995
+ this.handleClearClick && e?.removeEventListener("click", this.handleClearClick), this.handleNewChatClick && t?.removeEventListener("click", this.handleNewChatClick), this.handleToggleSidebarClick && s?.removeEventListener("click", this.handleToggleSidebarClick), this.handleChatListClick && r?.removeEventListener("click", this.handleChatListClick), this.handleMessageEvent && o && o.removeEventListener("message", this.handleMessageEvent), this.handleClearClick = null, this.handleNewChatClick = null, this.handleToggleSidebarClick = null, this.handleChatListClick = null, this.handleMessageEvent = null;
1956
1996
  }
1957
1997
  setupView() {
1958
1998
  const e = this.shadow.querySelector(".container");
@@ -1966,7 +2006,7 @@ ${this.getPageStyles()}`, this.container = document.createElement("div"), this.c
1966
2006
  }
1967
2007
  if (!e) return;
1968
2008
  const t = this.getProps();
1969
- if (this.chatView = new B(e, this.client, t), this.sessions.length === 0)
2009
+ if (this.chatView = new H(e, this.client, t), this.sessions.length === 0)
1970
2010
  this.createNewChat();
1971
2011
  else {
1972
2012
  const s = this.sessions[0];
@@ -1981,7 +2021,7 @@ ${this.getPageStyles()}`, this.container = document.createElement("div"), this.c
1981
2021
  }
1982
2022
  loadSessions() {
1983
2023
  try {
1984
- const e = localStorage.getItem(I);
2024
+ const e = localStorage.getItem(z);
1985
2025
  e && (this.sessions = JSON.parse(e), this.sessions.sort((t, s) => s.updatedAt - t.updatedAt));
1986
2026
  } catch (e) {
1987
2027
  console.error("Failed to load chat sessions:", e);
@@ -1989,7 +2029,7 @@ ${this.getPageStyles()}`, this.container = document.createElement("div"), this.c
1989
2029
  }
1990
2030
  saveSessions() {
1991
2031
  try {
1992
- localStorage.setItem(I, JSON.stringify(this.sessions));
2032
+ localStorage.setItem(z, JSON.stringify(this.sessions));
1993
2033
  } catch (e) {
1994
2034
  console.error("Failed to save chat sessions:", e);
1995
2035
  }
@@ -2040,14 +2080,14 @@ ${this.getPageStyles()}`, this.container = document.createElement("div"), this.c
2040
2080
  const t = e.target, s = t.closest(".chat-list-item-delete");
2041
2081
  if (s) {
2042
2082
  e.stopPropagation();
2043
- const n = s.getAttribute("data-session-id");
2044
- n && this.deleteSession(n);
2083
+ const o = s.getAttribute("data-session-id");
2084
+ o && this.deleteSession(o);
2045
2085
  return;
2046
2086
  }
2047
2087
  const r = t.closest(".chat-list-item");
2048
2088
  if (r) {
2049
- const n = r.getAttribute("data-session-id");
2050
- n && this.switchToSession(n);
2089
+ const o = r.getAttribute("data-session-id");
2090
+ o && this.switchToSession(o);
2051
2091
  }
2052
2092
  }
2053
2093
  renderChatList() {
@@ -2077,8 +2117,8 @@ ${this.getPageStyles()}`, this.container = document.createElement("div"), this.c
2077
2117
  `;
2078
2118
  }
2079
2119
  formatDate(e) {
2080
- const t = new Date(e), r = (/* @__PURE__ */ new Date()).getTime() - t.getTime(), n = Math.floor(r / (1e3 * 60 * 60 * 24));
2081
- return n === 0 ? t.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" }) : n === 1 ? "Yesterday" : n < 7 ? t.toLocaleDateString(void 0, { weekday: "long" }) : t.toLocaleDateString(void 0, { month: "short", day: "numeric" });
2120
+ const t = new Date(e), r = (/* @__PURE__ */ new Date()).getTime() - t.getTime(), o = Math.floor(r / (1e3 * 60 * 60 * 24));
2121
+ return o === 0 ? t.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" }) : o === 1 ? "Yesterday" : o < 7 ? t.toLocaleDateString(void 0, { weekday: "long" }) : t.toLocaleDateString(void 0, { month: "short", day: "numeric" });
2082
2122
  }
2083
2123
  escapeHTML(e) {
2084
2124
  const t = document.createElement("div");
@@ -2107,8 +2147,8 @@ ${this.getPageStyles()}`, this.container = document.createElement("div"), this.c
2107
2147
  return this.sessions.find((e) => e.id === this.currentSessionId) || null;
2108
2148
  }
2109
2149
  }
2110
- customElements.get(L) || customElements.define(L, K);
2111
- const G = `
2150
+ customElements.get(I) || customElements.define(I, W);
2151
+ const X = `
2112
2152
  /* Search view states */
2113
2153
  .search-view {
2114
2154
  transition: var(--search-snippet-transition-slow);
@@ -2478,8 +2518,8 @@ a.search-result-item:focus-visible {
2478
2518
  border-radius: 2px;
2479
2519
  font-weight: var(--search-snippet-font-weight-medium);
2480
2520
  }
2481
- `, z = "search-bar-snippet", F = 10, Y = 100;
2482
- class W extends HTMLElement {
2521
+ `, A = "search-bar-snippet", Z = 10, Q = 100;
2522
+ class ee extends HTMLElement {
2483
2523
  constructor() {
2484
2524
  super();
2485
2525
  a(this, "shadow");
@@ -2510,11 +2550,12 @@ class W extends HTMLElement {
2510
2550
  "show-url",
2511
2551
  "show-date",
2512
2552
  "hide-thumbnails",
2513
- "see-more"
2553
+ "see-more",
2554
+ "request-options"
2514
2555
  ];
2515
2556
  }
2516
2557
  connectedCallback() {
2517
- this.initializeClient(), this.render(), this.dispatchEvent(m("ready", void 0));
2558
+ this.initializeClient(), this.render(), this.dispatchEvent(v("ready", void 0));
2518
2559
  }
2519
2560
  disconnectedCallback() {
2520
2561
  this.cleanup();
@@ -2526,16 +2567,29 @@ class W extends HTMLElement {
2526
2567
  return {
2527
2568
  apiUrl: d(this.getAttribute("api-url"), ""),
2528
2569
  placeholder: d(this.getAttribute("placeholder"), "Search..."),
2529
- maxResults: w(this.getAttribute("max-results"), 10),
2530
- debounceMs: w(this.getAttribute("debounce-ms"), 300),
2570
+ maxResults: y(this.getAttribute("max-results"), 10),
2571
+ debounceMs: y(this.getAttribute("debounce-ms"), 300),
2531
2572
  theme: d(this.getAttribute("theme"), "auto"),
2532
- hideBranding: g(this.getAttribute("hide-branding"), !1),
2533
- showUrl: g(this.getAttribute("show-url"), !1),
2534
- showDate: g(this.getAttribute("show-date"), !1),
2535
- hideThumbnails: g(this.getAttribute("hide-thumbnails"), !1),
2573
+ hideBranding: m(this.getAttribute("hide-branding"), !1),
2574
+ showUrl: m(this.getAttribute("show-url"), !1),
2575
+ showDate: m(this.getAttribute("show-date"), !1),
2576
+ hideThumbnails: m(this.getAttribute("hide-thumbnails"), !1),
2536
2577
  seeMore: d(this.getAttribute("see-more"), "")
2537
2578
  };
2538
2579
  }
2580
+ getRequestOptions() {
2581
+ const e = this.getAttribute("request-options");
2582
+ if (e)
2583
+ try {
2584
+ const t = JSON.parse(e);
2585
+ if (t === null || typeof t != "object" || Array.isArray(t))
2586
+ throw new Error("request-options must be a JSON object");
2587
+ return t;
2588
+ } catch (t) {
2589
+ console.error("SearchBarSnippet: invalid request-options attribute", t);
2590
+ return;
2591
+ }
2592
+ }
2539
2593
  initializeClient() {
2540
2594
  const e = this.getProps();
2541
2595
  if (!e.apiUrl) {
@@ -2550,13 +2604,13 @@ class W extends HTMLElement {
2550
2604
  }
2551
2605
  render() {
2552
2606
  const e = this.getProps(), t = (r) => this.performSearch(r);
2553
- this.debouncedSearch = A(
2607
+ this.debouncedSearch = $(
2554
2608
  t,
2555
2609
  e.debounceMs || 400
2556
2610
  );
2557
2611
  const s = document.createElement("style");
2558
- s.textContent = `${k}
2559
- ${G}`, this.container = document.createElement("div"), this.container.className = "container", this.container.innerHTML = `
2612
+ s.textContent = `${C}
2613
+ ${X}`, this.container = document.createElement("div"), this.container.className = "container", this.container.innerHTML = `
2560
2614
  <div class="search-view">
2561
2615
  <div class="search-input-wrapper">
2562
2616
  <svg xmlns="http://www.w3.org/2000/svg" class="search-icon" height="24px" viewBox="0 -960 960 960" width="24px" fill="currentColor"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Z"/></svg>
@@ -2604,10 +2658,10 @@ ${G}`, this.container = document.createElement("div"), this.container.className
2604
2658
  this.currentSearchController && (this.currentSearchController.abort(), this.currentSearchController = null), this.currentSearchController = new AbortController(), this.showLoadingState();
2605
2659
  try {
2606
2660
  const t = await this.client.search(e, {
2607
- streaming: !1,
2608
2661
  signal: this.currentSearchController.signal,
2609
- maxResults: Y
2610
- }), s = this.getProps(), r = t.slice(0, s.maxResults || F);
2662
+ maxResults: Q,
2663
+ request: this.getRequestOptions()
2664
+ }), s = this.getProps(), r = t.slice(0, s.maxResults || Z);
2611
2665
  this.displayResults(r, e, t.length);
2612
2666
  } catch (t) {
2613
2667
  if (t.name === "AbortError")
@@ -2623,7 +2677,7 @@ ${G}`, this.container = document.createElement("div"), this.container.className
2623
2677
  this.showNoResultsState(t);
2624
2678
  return;
2625
2679
  }
2626
- const r = this.getProps(), n = r.hideBranding ? "" : `<div class="powered-by-inline">${y}</div>`, c = s > e.length, l = c ? `Showing ${e.length} of ${s} results` : `Found ${s} result${s === 1 ? "" : "s"}`, v = r.seeMore && c ? `<div class="search-footer">
2680
+ const r = this.getProps(), o = r.hideBranding ? "" : `<div class="powered-by-inline">${k}</div>`, c = s > e.length, l = c ? `Showing ${e.length} of ${s} results` : `Found ${s} result${s === 1 ? "" : "s"}`, g = r.seeMore && c ? `<div class="search-footer">
2627
2681
  <a href="${h(r.seeMore + encodeURIComponent(t))}" class="search-see-more">
2628
2682
  <span>See more results</span>
2629
2683
  <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg>
@@ -2633,19 +2687,19 @@ ${G}`, this.container = document.createElement("div"), this.container.className
2633
2687
  <div class="search-count">
2634
2688
  ${l}
2635
2689
  </div>
2636
- ${n}
2690
+ ${o}
2637
2691
  </div>
2638
2692
  <div class="search-results">
2639
2693
  ${e.map((p) => this.renderResult(p)).join("")}
2640
2694
  </div>
2641
- ${v}
2695
+ ${g}
2642
2696
  `;
2643
2697
  this.resultsContainer.innerHTML = b, this.attachResultHandlers();
2644
2698
  }
2645
2699
  renderResult(e) {
2646
- const t = this.getProps(), s = t.hideThumbnails ? "" : this.renderResultImage(e.image, e.title), r = e.url ? h(e.url) : "#", n = t.showDate && e.timestamp !== void 0 ? `<div class="search-result-date">${h($(e.timestamp))}</div>` : "", c = t.showUrl && e.url || n ? `<div class="search-result-metadata">
2700
+ const t = this.getProps(), s = t.hideThumbnails ? "" : this.renderResultImage(e.image, e.title), r = e.url ? h(e.url) : "#", o = t.showDate && e.timestamp !== void 0 ? `<div class="search-result-date">${h(q(e.timestamp))}</div>` : "", c = t.showUrl && e.url || o ? `<div class="search-result-metadata">
2647
2701
  ${t.showUrl && e.url ? `<span class="search-result-url">${h(e.url)}</span>` : '<span class="search-result-url search-result-url-empty"></span>'}
2648
- ${n}
2702
+ ${o}
2649
2703
  </div>` : "";
2650
2704
  return `
2651
2705
  <a href="${r}" class="search-result-item" data-result-id="${h(e.url || "")}">
@@ -2681,8 +2735,8 @@ ${G}`, this.container = document.createElement("div"), this.container.className
2681
2735
  const e = this.container?.querySelectorAll(".search-result-item");
2682
2736
  if (!e) return;
2683
2737
  for (const s of e)
2684
- s.getAttribute("href") === "#" && s.addEventListener("click", (n) => {
2685
- n.preventDefault();
2738
+ s.getAttribute("href") === "#" && s.addEventListener("click", (o) => {
2739
+ o.preventDefault();
2686
2740
  });
2687
2741
  this.container?.querySelectorAll(".search-result-image")?.forEach((s) => {
2688
2742
  s.addEventListener("load", () => {
@@ -2690,10 +2744,10 @@ ${G}`, this.container = document.createElement("div"), this.container.className
2690
2744
  }), s.addEventListener("error", () => {
2691
2745
  const r = s.closest(".search-result-image-container");
2692
2746
  r?.querySelector(".search-result-image-loading")?.remove();
2693
- const n = r?.querySelector(
2747
+ const o = r?.querySelector(
2694
2748
  ".search-result-image-placeholder"
2695
2749
  );
2696
- n && (n.style.display = "flex"), s.style.display = "none";
2750
+ o && (o.style.display = "flex"), s.style.display = "none";
2697
2751
  });
2698
2752
  });
2699
2753
  }
@@ -2765,8 +2819,8 @@ ${G}`, this.container = document.createElement("div"), this.container.className
2765
2819
  await this.performSearch(e);
2766
2820
  }
2767
2821
  }
2768
- customElements.get(z) || customElements.define(z, W);
2769
- const X = `
2822
+ customElements.get(A) || customElements.define(A, ee);
2823
+ const te = `
2770
2824
  /* Modal backdrop */
2771
2825
  .modal-backdrop {
2772
2826
  position: fixed;
@@ -3203,8 +3257,8 @@ a.modal-result-item:focus-visible {
3203
3257
  .modal-container.open {
3204
3258
  animation: modal-slide-in var(--search-snippet-transition) ease-out;
3205
3259
  }
3206
- `, T = "search-modal-snippet", J = 10, Z = 100;
3207
- class Q extends HTMLElement {
3260
+ `, T = "search-modal-snippet", se = 10, ie = 100;
3261
+ class re extends HTMLElement {
3208
3262
  constructor() {
3209
3263
  super();
3210
3264
  a(this, "shadow");
@@ -3244,11 +3298,12 @@ class Q extends HTMLElement {
3244
3298
  "show-url",
3245
3299
  "show-date",
3246
3300
  "hide-thumbnails",
3247
- "see-more"
3301
+ "see-more",
3302
+ "request-options"
3248
3303
  ];
3249
3304
  }
3250
3305
  connectedCallback() {
3251
- this.initializeClient(), this.render(), this.attachGlobalKeyboardShortcut(), this.dispatchEvent(m("ready", void 0));
3306
+ this.initializeClient(), this.render(), this.attachGlobalKeyboardShortcut(), this.dispatchEvent(v("ready", void 0));
3252
3307
  }
3253
3308
  disconnectedCallback() {
3254
3309
  this.cleanup();
@@ -3260,18 +3315,31 @@ class Q extends HTMLElement {
3260
3315
  return {
3261
3316
  apiUrl: d(this.getAttribute("api-url"), ""),
3262
3317
  placeholder: d(this.getAttribute("placeholder"), "Search..."),
3263
- maxResults: w(this.getAttribute("max-results"), 10),
3264
- debounceMs: w(this.getAttribute("debounce-ms"), 300),
3318
+ maxResults: y(this.getAttribute("max-results"), 10),
3319
+ debounceMs: y(this.getAttribute("debounce-ms"), 300),
3265
3320
  theme: d(this.getAttribute("theme"), "auto"),
3266
3321
  shortcut: d(this.getAttribute("shortcut"), "k"),
3267
3322
  useMetaKey: this.getAttribute("use-meta-key") !== "false",
3268
- hideBranding: g(this.getAttribute("hide-branding"), !1),
3269
- showUrl: g(this.getAttribute("show-url"), !1),
3270
- showDate: g(this.getAttribute("show-date"), !1),
3271
- hideThumbnails: g(this.getAttribute("hide-thumbnails"), !1),
3323
+ hideBranding: m(this.getAttribute("hide-branding"), !1),
3324
+ showUrl: m(this.getAttribute("show-url"), !1),
3325
+ showDate: m(this.getAttribute("show-date"), !1),
3326
+ hideThumbnails: m(this.getAttribute("hide-thumbnails"), !1),
3272
3327
  seeMore: d(this.getAttribute("see-more"), "")
3273
3328
  };
3274
3329
  }
3330
+ getRequestOptions() {
3331
+ const e = this.getAttribute("request-options");
3332
+ if (e)
3333
+ try {
3334
+ const t = JSON.parse(e);
3335
+ if (t === null || typeof t != "object" || Array.isArray(t))
3336
+ throw new Error("request-options must be a JSON object");
3337
+ return t;
3338
+ } catch (t) {
3339
+ console.error("SearchModalSnippet: invalid request-options attribute", t);
3340
+ return;
3341
+ }
3342
+ }
3275
3343
  initializeClient() {
3276
3344
  const e = this.getProps();
3277
3345
  if (!e.apiUrl) {
@@ -3286,15 +3354,15 @@ class Q extends HTMLElement {
3286
3354
  }
3287
3355
  render() {
3288
3356
  const e = this.getProps(), t = (c) => this.performSearch(c);
3289
- this.debouncedSearch = A(
3357
+ this.debouncedSearch = $(
3290
3358
  t,
3291
3359
  e.debounceMs || 300
3292
3360
  );
3293
3361
  const s = document.createElement("style");
3294
- s.textContent = `${k}
3295
- ${X}`;
3296
- const r = e.hideBranding ? "" : `<div class="powered-by-inline">${y}</div>`, n = document.createElement("div");
3297
- n.innerHTML = `
3362
+ s.textContent = `${C}
3363
+ ${te}`;
3364
+ const r = e.hideBranding ? "" : `<div class="powered-by-inline">${k}</div>`, o = document.createElement("div");
3365
+ o.innerHTML = `
3298
3366
  <div class="modal-backdrop" role="presentation"></div>
3299
3367
  <div class="modal-container" role="dialog" aria-modal="true" aria-labelledby="modal-title">
3300
3368
  <div class="modal-header">
@@ -3337,7 +3405,7 @@ ${X}`;
3337
3405
  ${r}
3338
3406
  </div>
3339
3407
  </div>
3340
- `, this.shadow.innerHTML = "", this.shadow.appendChild(s), this.shadow.appendChild(n), this.backdrop = this.shadow.querySelector(".modal-backdrop"), this.modal = this.shadow.querySelector(".modal-container"), this.inputElement = this.shadow.querySelector(".modal-search-input"), this.resultsContainer = this.shadow.querySelector(".modal-results"), this.footerCount = this.shadow.querySelector(".modal-results-count"), this.attachEventListeners(), this.client || this.showMissingApiUrlError();
3408
+ `, this.shadow.innerHTML = "", this.shadow.appendChild(s), this.shadow.appendChild(o), this.backdrop = this.shadow.querySelector(".modal-backdrop"), this.modal = this.shadow.querySelector(".modal-container"), this.inputElement = this.shadow.querySelector(".modal-search-input"), this.resultsContainer = this.shadow.querySelector(".modal-results"), this.footerCount = this.shadow.querySelector(".modal-results-count"), this.attachEventListeners(), this.client || this.showMissingApiUrlError();
3341
3409
  }
3342
3410
  attachGlobalKeyboardShortcut() {
3343
3411
  const e = this.getProps(), t = e.shortcut?.toLowerCase() || "k";
@@ -3348,7 +3416,7 @@ ${X}`;
3348
3416
  attachEventListeners() {
3349
3417
  !this.inputElement || !this.backdrop || (this.handleInputChange = (e) => {
3350
3418
  const s = e.target.value.trim();
3351
- s.length > 0 && this.debouncedSearch ? this.debouncedSearch(s) : (this.results = [], this.activeIndex = -1, this.showEmptyState());
3419
+ s.length > 0 && this.debouncedSearch ? this.debouncedSearch(s) : (this.debouncedSearch?.cancel(), this.currentSearchController?.abort(), this.results = [], this.activeIndex = -1, this.showEmptyState());
3352
3420
  }, this.inputElement.addEventListener("input", this.handleInputChange), this.handleInputKeydown = (e) => {
3353
3421
  switch (e.key) {
3354
3422
  case "ArrowDown":
@@ -3387,7 +3455,7 @@ ${X}`;
3387
3455
  }
3388
3456
  const e = this.results[this.activeIndex];
3389
3457
  this.dispatchEvent(
3390
- m("result-select", {
3458
+ v("result-select", {
3391
3459
  result: e,
3392
3460
  index: this.activeIndex
3393
3461
  })
@@ -3405,11 +3473,11 @@ ${X}`;
3405
3473
  this.currentSearchController && (this.currentSearchController.abort(), this.currentSearchController = null), this.currentSearchController = new AbortController(), this.showLoadingState();
3406
3474
  try {
3407
3475
  const t = await this.client.search(e, {
3408
- streaming: !1,
3409
3476
  signal: this.currentSearchController.signal,
3410
- maxResults: Z
3477
+ maxResults: ie,
3478
+ request: this.getRequestOptions()
3411
3479
  }), s = this.getProps();
3412
- this.results = t.slice(0, s.maxResults || J), this.activeIndex = this.results.length > 0 ? 0 : -1, this.displayResults(this.results, e, t.length);
3480
+ this.results = t.slice(0, s.maxResults || se), this.activeIndex = this.results.length > 0 ? 0 : -1, this.displayResults(this.results, e, t.length);
3413
3481
  } catch (t) {
3414
3482
  if (t.name === "AbortError")
3415
3483
  return;
@@ -3419,25 +3487,25 @@ ${X}`;
3419
3487
  }
3420
3488
  }
3421
3489
  displayResults(e, t, s = e.length) {
3422
- if (console.log({ results: e, query: t, totalResults: s }), this.clearLoadingInterval(), !this.resultsContainer) return;
3490
+ if (this.clearLoadingInterval(), !this.resultsContainer) return;
3423
3491
  if (e.length === 0) {
3424
3492
  this.showNoResultsState(t);
3425
3493
  return;
3426
3494
  }
3427
- const r = this.getProps(), n = e.map((b, p) => this.renderResult(b, p)).join(""), c = s > e.length, l = c ? `Showing ${e.length} of ${s} results` : `${s} result${s === 1 ? "" : "s"}`, v = r.seeMore && c ? `<a href="${h(r.seeMore + encodeURIComponent(t))}" class="modal-see-more">
3495
+ const r = this.getProps(), o = e.map((b, p) => this.renderResult(b, p)).join(""), c = s > e.length, l = c ? `Showing ${e.length} of ${s} results` : `${s} result${s === 1 ? "" : "s"}`, g = r.seeMore && c ? `<a href="${h(r.seeMore + encodeURIComponent(t))}" class="modal-see-more">
3428
3496
  <span>See more results</span>
3429
3497
  <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg>
3430
3498
  </a>` : "";
3431
- this.resultsContainer.innerHTML = n + v, this.footerCount && (this.footerCount.textContent = l), this.inputElement && this.inputElement.setAttribute("aria-expanded", "true"), this.attachResultHandlers(), this.updateActiveResult();
3499
+ this.resultsContainer.innerHTML = o + g, this.footerCount && (this.footerCount.textContent = l), this.inputElement && this.inputElement.setAttribute("aria-expanded", "true"), this.attachResultHandlers(), this.updateActiveResult();
3432
3500
  }
3433
3501
  renderResult(e, t) {
3434
- const s = this.getProps(), r = s.hideThumbnails ? "" : this.renderResultImage(e.image, e.title), n = e.url ? h(e.url) : "#", c = s.showDate && e.timestamp !== void 0 ? `<div class="modal-result-date">${h($(e.timestamp))}</div>` : "", l = s.showUrl && e.url || c ? `<div class="modal-result-metadata">
3502
+ const s = this.getProps(), r = s.hideThumbnails ? "" : this.renderResultImage(e.image, e.title), o = e.url ? h(e.url) : "#", c = s.showDate && e.timestamp !== void 0 ? `<div class="modal-result-date">${h(q(e.timestamp))}</div>` : "", l = s.showUrl && e.url || c ? `<div class="modal-result-metadata">
3435
3503
  ${s.showUrl && e.url ? `<span class="modal-result-url">${h(e.url)}</span>` : '<span class="modal-result-url modal-result-url-empty"></span>'}
3436
3504
  ${c}
3437
3505
  </div>` : "";
3438
3506
  return `
3439
3507
  <a
3440
- href="${n}"
3508
+ href="${o}"
3441
3509
  class="modal-result-item${t === this.activeIndex ? " active" : ""}"
3442
3510
  role="option"
3443
3511
  id="result-${t}"
@@ -3489,10 +3557,10 @@ ${X}`;
3489
3557
  }), s.addEventListener("error", () => {
3490
3558
  const r = s.closest(".modal-result-image-container");
3491
3559
  r?.querySelector(".modal-result-image-loading")?.remove();
3492
- const n = r?.querySelector(
3560
+ const o = r?.querySelector(
3493
3561
  ".modal-result-image-placeholder"
3494
3562
  );
3495
- n && (n.style.display = "flex"), s.style.display = "none";
3563
+ o && (o.style.display = "flex"), s.style.display = "none";
3496
3564
  });
3497
3565
  });
3498
3566
  }
@@ -3580,13 +3648,13 @@ ${X}`;
3580
3648
  requestAnimationFrame(() => {
3581
3649
  this.inputElement?.focus();
3582
3650
  });
3583
- }), this.lockBodyScroll(), this.dispatchEvent(m("open", void 0)));
3651
+ }), this.lockBodyScroll(), this.dispatchEvent(v("open", void 0)));
3584
3652
  }
3585
3653
  /**
3586
3654
  * Close the search modal
3587
3655
  */
3588
3656
  close() {
3589
- this.isOpen && (this.isOpen = !1, this.backdrop?.classList.remove("open"), this.modal?.classList.remove("open"), this.inputElement && (this.inputElement.value = ""), this.results = [], this.activeIndex = -1, this.showEmptyState(), this.unlockBodyScroll(), this.dispatchEvent(m("close", void 0)));
3657
+ this.isOpen && (this.isOpen = !1, this.backdrop?.classList.remove("open"), this.modal?.classList.remove("open"), this.inputElement && (this.inputElement.value = ""), this.results = [], this.activeIndex = -1, this.showEmptyState(), this.unlockBodyScroll(), this.dispatchEvent(v("close", void 0)));
3590
3658
  }
3591
3659
  /**
3592
3660
  * Toggle the search modal open/closed
@@ -3613,13 +3681,13 @@ ${X}`;
3613
3681
  return this.isOpen;
3614
3682
  }
3615
3683
  }
3616
- customElements.get(T) || customElements.define(T, Q);
3684
+ customElements.get(T) || customElements.define(T, re);
3617
3685
  export {
3618
- _ as AISearchClient,
3619
- O as ChatBubbleSnippet,
3620
- K as ChatPageSnippet,
3621
- W as SearchBarSnippet,
3622
- Q as SearchModalSnippet,
3623
- W as default
3686
+ V as AISearchClient,
3687
+ J as ChatBubbleSnippet,
3688
+ W as ChatPageSnippet,
3689
+ ee as SearchBarSnippet,
3690
+ re as SearchModalSnippet,
3691
+ ee as default
3624
3692
  };
3625
3693
  //# sourceMappingURL=search-snippet.es.js.map