@cloudflare/ai-search-snippet 0.0.21 → 0.0.22
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.
|
@@ -87,15 +87,18 @@ class N {
|
|
|
87
87
|
}
|
|
88
88
|
class P extends N {
|
|
89
89
|
request(i = {}, e, t) {
|
|
90
|
+
const s = e === "search" ? "snippet-search" : "snippet-chat-completions";
|
|
90
91
|
return fetch(`${this.baseUrl}/${e}`, {
|
|
91
92
|
method: "POST",
|
|
92
93
|
body: JSON.stringify({
|
|
93
94
|
messages: [{ role: "user", content: i.query }],
|
|
94
95
|
stream: i.streaming,
|
|
95
|
-
max_results: i.maxResults
|
|
96
|
+
max_results: i.maxResults,
|
|
97
|
+
...e === "search" && { retrieval_options: { metadata_only: !0 } }
|
|
96
98
|
}),
|
|
97
99
|
headers: {
|
|
98
|
-
"Content-Type": "application/json"
|
|
100
|
+
"Content-Type": "application/json",
|
|
101
|
+
"cf-ai-search-source": s
|
|
99
102
|
},
|
|
100
103
|
signal: t
|
|
101
104
|
});
|
|
@@ -234,7 +237,10 @@ class P extends N {
|
|
|
234
237
|
return `req-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
235
238
|
}
|
|
236
239
|
}
|
|
237
|
-
const
|
|
240
|
+
const _ = `<svg width="32" height="10" viewBox="0 0 412 186" xmlns="http://www.w3.org/2000/svg" aria-label="Cloudflare" role="img">
|
|
241
|
+
<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"/>
|
|
242
|
+
<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"/>
|
|
243
|
+
</svg>`, j = "https://search.ai.cloudflare.com", y = `Powered by <a href="${j}" target="_blank" rel="noopener noreferrer">Cloudflare AI Search ${_}</a>`, $ = `
|
|
238
244
|
/* Chat container */
|
|
239
245
|
.chat-container {
|
|
240
246
|
display: flex;
|
|
@@ -547,7 +553,7 @@ const $ = `
|
|
|
547
553
|
.chat-message-bubble a:hover {
|
|
548
554
|
text-decoration: none;
|
|
549
555
|
}
|
|
550
|
-
`,
|
|
556
|
+
`, x = `
|
|
551
557
|
:host {
|
|
552
558
|
/* Colors - Light Mode */
|
|
553
559
|
--search-snippet-primary-color: #2563eb;
|
|
@@ -960,13 +966,10 @@ const $ = `
|
|
|
960
966
|
padding: var(--search-snippet-spacing-xs) 0;
|
|
961
967
|
text-align: center;
|
|
962
968
|
}
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
<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"/>
|
|
966
|
-
</svg>`, K = "https://search.ai.cloudflare.com", x = `Powered by <a href="${K}" target="_blank" rel="noopener noreferrer">Cloudflare AI Search ${j}</a>`;
|
|
967
|
-
function V(o) {
|
|
969
|
+
`;
|
|
970
|
+
function K(o) {
|
|
968
971
|
let i = o;
|
|
969
|
-
i =
|
|
972
|
+
i = V(i), i = i.replace(/```([\s\S]*?)```/g, (n, c) => `<pre><code>${c.trim()}</code></pre>`);
|
|
970
973
|
const e = i.split(`
|
|
971
974
|
`), t = [];
|
|
972
975
|
let s = !1, a = "";
|
|
@@ -1012,7 +1015,7 @@ function b(o) {
|
|
|
1012
1015
|
'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'
|
|
1013
1016
|
), i;
|
|
1014
1017
|
}
|
|
1015
|
-
function
|
|
1018
|
+
function V(o) {
|
|
1016
1019
|
const i = {
|
|
1017
1020
|
"&": "&",
|
|
1018
1021
|
"<": "<",
|
|
@@ -1191,7 +1194,7 @@ class q {
|
|
|
1191
1194
|
<div class="chat-message-avatar">${s}</div>
|
|
1192
1195
|
<div class="chat-message-content">
|
|
1193
1196
|
<div class="chat-message-bubble">
|
|
1194
|
-
${i.content ? `<div class="chat-message-text">${
|
|
1197
|
+
${i.content ? `<div class="chat-message-text">${K(i.content)}</div>` : ""}
|
|
1195
1198
|
${e ? '<div class="chat-streaming"><span class="chat-streaming-dot"></span><span class="chat-streaming-dot"></span><span class="chat-streaming-dot"></span></div>' : ""}
|
|
1196
1199
|
</div>
|
|
1197
1200
|
<div class="chat-message-metadata">
|
|
@@ -1291,7 +1294,7 @@ class O extends HTMLElement {
|
|
|
1291
1294
|
}
|
|
1292
1295
|
render() {
|
|
1293
1296
|
const e = document.createElement("style");
|
|
1294
|
-
e.textContent = `${
|
|
1297
|
+
e.textContent = `${x}
|
|
1295
1298
|
${$}
|
|
1296
1299
|
${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();
|
|
1297
1300
|
}
|
|
@@ -1472,7 +1475,7 @@ ${this.getBubbleStyles()}`, this.container = document.createElement("div"), this
|
|
|
1472
1475
|
</div>
|
|
1473
1476
|
</div>
|
|
1474
1477
|
<div class="chat-content"></div>
|
|
1475
|
-
${this.getProps().hideBranding ? "" : `<div class="powered-by">${
|
|
1478
|
+
${this.getProps().hideBranding ? "" : `<div class="powered-by">${y}</div>`}
|
|
1476
1479
|
</div>
|
|
1477
1480
|
`;
|
|
1478
1481
|
}
|
|
@@ -1577,7 +1580,7 @@ class D extends HTMLElement {
|
|
|
1577
1580
|
}
|
|
1578
1581
|
render() {
|
|
1579
1582
|
const e = document.createElement("style");
|
|
1580
|
-
e.textContent = `${
|
|
1583
|
+
e.textContent = `${x}
|
|
1581
1584
|
${$}
|
|
1582
1585
|
${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();
|
|
1583
1586
|
}
|
|
@@ -1870,7 +1873,7 @@ ${this.getPageStyles()}`, this.container = document.createElement("div"), this.c
|
|
|
1870
1873
|
New Chat
|
|
1871
1874
|
</button>
|
|
1872
1875
|
<div class="chat-list"></div>
|
|
1873
|
-
${this.getProps().hideBranding ? "" : `<div class="powered-by">${
|
|
1876
|
+
${this.getProps().hideBranding ? "" : `<div class="powered-by">${y}</div>`}
|
|
1874
1877
|
</div>
|
|
1875
1878
|
<div class="chat-main">
|
|
1876
1879
|
<div class="chat-page-header">
|
|
@@ -2458,7 +2461,7 @@ class F extends HTMLElement {
|
|
|
2458
2461
|
e.debounceMs || 400
|
|
2459
2462
|
);
|
|
2460
2463
|
const s = document.createElement("style");
|
|
2461
|
-
s.textContent = `${
|
|
2464
|
+
s.textContent = `${x}
|
|
2462
2465
|
${U}`, this.container = document.createElement("div"), this.container.className = "container", this.container.innerHTML = `
|
|
2463
2466
|
<div class="search-view">
|
|
2464
2467
|
<div class="search-input-wrapper">
|
|
@@ -2523,7 +2526,7 @@ ${U}`, this.container = document.createElement("div"), this.container.className
|
|
|
2523
2526
|
this.showNoResultsState(t);
|
|
2524
2527
|
return;
|
|
2525
2528
|
}
|
|
2526
|
-
const a = this.getProps().hideBranding ? "" : `<div class="powered-by-inline">${
|
|
2529
|
+
const a = this.getProps().hideBranding ? "" : `<div class="powered-by-inline">${y}</div>`, n = `
|
|
2527
2530
|
<div class="search-header">
|
|
2528
2531
|
<div class="search-count">
|
|
2529
2532
|
Found ${e.length} result${e.length === 1 ? "" : "s"}
|
|
@@ -3123,9 +3126,9 @@ class Y extends HTMLElement {
|
|
|
3123
3126
|
e.debounceMs || 300
|
|
3124
3127
|
);
|
|
3125
3128
|
const s = document.createElement("style");
|
|
3126
|
-
s.textContent = `${
|
|
3129
|
+
s.textContent = `${x}
|
|
3127
3130
|
${G}`;
|
|
3128
|
-
const a = e.hideBranding ? "" : `<div class="powered-by-inline">${
|
|
3131
|
+
const a = e.hideBranding ? "" : `<div class="powered-by-inline">${y}</div>`, n = document.createElement("div");
|
|
3129
3132
|
n.innerHTML = `
|
|
3130
3133
|
<div class="modal-backdrop" role="presentation"></div>
|
|
3131
3134
|
<div class="modal-container" role="dialog" aria-modal="true" aria-labelledby="modal-title">
|