PluginProbe
Extendify / 2.2.0
Extendify v2.2.0
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Agent / workflows / extermal / tools / search-wp-docs.js

search-wp-docs.js in Extendify 2.2.0, at src/Agent/workflows/extermal/tools/search-wp-docs.js

22 lines 808 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { KB_HOST } from '@constants';
2
3 export default async ({ query }) => {
4 const fallback = { documentation: 'No relevant documentation found' };
5 const urlParams = new URLSearchParams({ search: query });
6 const r = await fetch(`${KB_HOST}/api/posts?${urlParams.toString()}`, {
7 method: 'POST',
8 headers: { 'Content-Type': 'application/json' },
9 }).catch(() => ({ ok: false }));
10 if (!r.ok) return fallback;
11
12 const articles = await r.json();
13 if (!articles?.[0]?.slug) return fallback;
14 const r2 = await fetch(`${KB_HOST}/api/posts/${articles?.[0]?.slug}`, {
15 method: 'GET',
16 headers: { 'Content-Type': 'application/json' },
17 }).catch(() => ({ ok: false }));
18 if (!r2.ok) return fallback;
19 const article = await r2.json();
20 return article?.content ? { documentation: article.content } : fallback;
21 };
22