You can access search results via JSON API by adding format=json
to your query:
https://codesearch.val.run/$%7BsvgDataUrl%7D?q=fetch&page=7&format=json
For typeahead suggestions, use the /typeahead
endpoint:
https://codesearch.val.run/typeahead?q=fetch
Returns an array of strings in format "username" or "username/projectName"
Found 14090 results for "fetch"(843ms)
682683Â Â try {Â
684Â Â Â const res = await fetch(\`\${API_URL}?action=chat\`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ messages: conversationHistory.slice(0, -1), tasks, projects }) });Â
685Â Â Â const data = await res.json();Â
686Â Â Â if (!res.ok || data.error) throw new Error(data.error || 'Server error');Â
786Â Â toggleLoading(btn, true);Â
787Â Â try {Â
788Â Â Â const res = await fetch(\`\${API_URL}?action=synthesizeProject\`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ goal }) });Â
789Â Â Â const data = await res.json();Â
790Â Â Â if (!res.ok || data.error) throw new Error(data.error || "Server error");Â
804Â Â toggleLoading(btn, true);Â
805Â Â try {Â
806Â Â Â const res = await fetch(\`\${API_URL}?action=dailyRebalance\`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ tasks: todayTasks }) });Â
807Â Â Â const data = await res.json();Â
808Â Â Â if (!res.ok || data.error) throw new Error(data.error || "Server error");Â
2import { Hono, Context } from 'npm:hono';
3import { SSETransport } from 'npm:hono-mcp-server-sse-transport';
4import { toFetchResponse, toReqRes } from "npm:fetch-to-node";
5import { z } from "npm:zod";
6import lunr from "https://cdn.skypack.dev/lunr";
181{ limit: z.number().optional() },
182async ({ limit }) => {
183console.log(`${new Date().toISOString()} Fetching proverbs data`);
184const proverbs = await fetch("https://www.joshbeckman.org/assets/js/proverbs.json").then((res) => res.json());
185const results = proverbs
186.sort(() => Math.random() - 0.5)
187.slice(0, limit || 100);
188console.log(`${new Date().toISOString()} Proverbs data fetched`);
189const data = results.join("\n");
190return {
198{ limit: z.number().optional(), tag: z.string() },
199async ({ limit, tag }) => {
200console.log(`${new Date().toISOString()} Fetching sequences data for tag: ${tag}`);
201const sequences = await fetch("https://www.joshbeckman.org/assets/js/sequences.json").then((res) => res.json());
202const results = sequences
203.filter((seq: any) => seq.topic == tag)
204.slice(0, limit || 100);
205console.log(`${new Date().toISOString()} Sequences data fetched`);
206if (results.length == 0) {
207return {
222{ id: z.string() },
223async ({ id }) => {
224console.log(`${new Date().toISOString()} Fetching sequence data for ID: ${id}`);
225const sequences = await fetch("https://www.joshbeckman.org/assets/js/sequences.json").then((res) => res.json());
226const sequence = sequences.find((seq: any) => seq.id == id);
227console.log(`${new Date().toISOString()} Sequence data fetched`);
228if (!sequence) {
229return {
242{ query: z.string(), limit: z.number().optional() },
243async ({ query, limit }) => {
244console.log(`${new Date().toISOString()} Fetching tags data for search`);
245const tags = await fetch("https://www.joshbeckman.org/assets/js/tags.json").then((res) => res.json());
246const tagsIndex = buildTagsIndex(tags);
247console.log(`${new Date().toISOString()} Tags search index built`);
268{ tags: z.array(z.string()) },
269async ({ tags }) => {
270console.log(`${new Date().toISOString()} Fetching tags data`);
271const sourceTags = await fetch("https://www.joshbeckman.org/assets/js/tags.json")
272.then((res) => res.json());
273console.log(`${new Date().toISOString()} Tags data fetched`);
274const data = sourceTags.filter((tag) => tags.includes(tag.name)).map((tag) => {
275return `[${tag.name}](${SITE_URL}${tag.url})`;
285{},
286async () => {
287console.log(`${new Date().toISOString()} Fetching tags data`);
288const tags = await fetch("https://www.joshbeckman.org/assets/js/tags.json")
289.then((res) => res.json());
290const data = tags.sort((a, b) => a.name.localeCompare(b.name)).map((tag) => {
291return tag.name;
292}).join("\n");
293console.log(`${new Date().toISOString()} Tags data fetched`);
294return {
295content: [{ type: "text", text: data }]
299server.tool(
300"get_post",
301"Get the full content and metadata of a specific post by its URL. This tool fetches the post data from the site and returns it in a structured format, including title, content, date, tags, author, and more.",
302{ url: z.string() },
303async ({ url }) => {
304console.log(`${new Date().toISOString()} Fetching post data for URL: ${url}`);
305const searchData = await fetch("https://www.joshbeckman.org/assets/js/SearchData.json").then((res) => res.json());
306const db: Array<Post> = Object.values(searchData).filter(postFilter).map((post) => {
307post.author_id = post.author_id || "joshbeckman";
310});
311const post = db.find((post) => post.url == url || `${SITE_URL}${post.url}` == url);
312console.log(`${new Date().toISOString()} Post data fetched`);
313if (!post) {
314return {
348console.log(`${new Date().toISOString()} loading search data`);
349const [searchData, indexCache] = await Promise.all([
350fetch("https://www.joshbeckman.org/assets/js/SearchData.json").then((res) => res.json()),
351fetch("https://www.joshbeckman.org/assets/js/lunr-index.json").then((res) => res.json()),
352]);
353console.log(`${new Date().toISOString()} search data loaded`);
461});
462463return toFetchResponse(res);
464} catch (e) {
465console.error(e);
512* This will be exposed as a Val.town HTTP endpoint
513*/
514export default app.fetch;
515