MCPcopy Create free account
hub / github.com/SillyTavern/Extension-WebSearch / doExtrasApiQuery

Function doExtrasApiQuery

index.js:932–960  ·  view source on GitHub ↗

* Performs a search query via Extras API. * @param {string} query Search query * @returns {Promise<{textBits: string[], links: string[], images: string[]}>} Lines of search results.

(query)

Source from the content-addressed store, hash-verified

930 * @returns {Promise<{textBits: string[], links: string[], images: string[]}>} Lines of search results.
931 */
932async function doExtrasApiQuery(query) {
933 const url = new URL(getApiUrl());
934 url.pathname = '/api/websearch';
935 const result = await doExtrasFetch(url, {
936 method: 'POST',
937 headers: {
938 'Content-Type': 'application/json',
939 'Bypass-Tunnel-Reminder': 'bypass',
940 },
941 body: JSON.stringify({
942 query: query,
943 engine: extension_settings.websearch.extras_engine,
944 }),
945 });
946
947 if (!result.ok) {
948 const text = await result.text();
949 console.debug('WebSearch: search request failed', result.statusText, text);
950 return;
951 }
952
953 const data = await result.json();
954 console.debug('WebSearch: search response', data);
955
956 const textBits = data.results.split('\n');
957 const links = Array.isArray(data.links) ? data.links : [];
958 const images = Array.isArray(data.images) ? data.images : [];
959 return { textBits, links, images };
960}
961
962/**
963 * Performs a search query via the Selenium search plugin.

Callers 1

callSearchSourceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected