From 30282adaccab766baa10132277962435b0f4b002 Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 04:10:39 +0100 Subject: [PATCH 01/39] feat: add JAIWord component for fetching word definitions using jAI --- src/components/islands/jai-word.jsx | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/components/islands/jai-word.jsx diff --git a/src/components/islands/jai-word.jsx b/src/components/islands/jai-word.jsx new file mode 100644 index 0000000..a9b7651 --- /dev/null +++ b/src/components/islands/jai-word.jsx @@ -0,0 +1,31 @@ +import { useEffect } from "react"; +import Markdown from "react-markdown"; +import { useChat } from "@ai-sdk/react"; + +export default function JAIWord({ word }) { + /** + * Initialize useChat hook + */ + const { messages, status, append } = useChat({ + api: "/api/jai/ask", + onError: (e) => { + console.error(e); + }, + }); + + /** + * Handle Asking jAI for the word definition + */ + useEffect(() => { + append({ + role: "user", + content: `define ${word}`, + }); + }, [word]); + + return messages.map((msg, index) => ( + + { msg.role !== "user" && msg.content } + + )) +} \ No newline at end of file From f484f0e2184871da0dc6286961d1eb3b0e21262c Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 04:13:45 +0100 Subject: [PATCH 02/39] feat: introduce a new prompt for Ask-JAI --- apps/jai/lib/jai-prompt.js | 42 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/apps/jai/lib/jai-prompt.js b/apps/jai/lib/jai-prompt.js index c888855..db858c7 100644 --- a/apps/jai/lib/jai-prompt.js +++ b/apps/jai/lib/jai-prompt.js @@ -1,6 +1,6 @@ import { PromptTemplate } from "@langchain/core/prompts"; -const TEMPLATE = `You are jAI, an AI-powered assistant for jargons.dev, a dictionary for developers and tech enthusiasts. +const PERSONALITY = `You are jAI, an AI-powered assistant for jargons.dev, a dictionary for developers and tech enthusiasts. Your job is to explain technical jargon in a clear, concise, and engaging way. You have a friendly, slightly witty personality, and you relate to developers by using analogies, code examples, and real-world comparisons. @@ -33,4 +33,42 @@ Current conversation: {chat_history} User: {question} jAI:`; -export const jAIPrompt = PromptTemplate.fromTemplate(TEMPLATE); +const ASK = `You are jAI, an AI-powered assistant for jargons.dev, a dictionary of technical terms for developers, software engineers, and technology professionals. Your task is to write definitions for technical words or jargons I provide, following these rules: + +- **Style & Tone:** + - Keep the meaning **formal, clear, and simplified**. + - Write in a way that is beginner-friendly but precise, avoiding overly technical jargon or complex language that might confuse beginners. + - Ensure content is **SEO-friendly** (natural use of keywords, clarity, and directness). + - Ensure the definition is **accurate and up-to-date** with current industry standards. + - Use **simple language** and short sentences for clarity. + - If the term has multiple meanings, focus on the one most relevant to software, programming, or technology. + - If the term is an acronym, always include the **full form or origin of the term** first if it exists and adds value. + - If the term is a programming language or framework, include its primary use case, purpose or/and code snippet. + - If the term is a concept (like "Agile" or "DevOps"), briefly mention its significance in the tech industry. + - No fluff, just professional and useful content. + +- **Structure (always in this order):** + 1. **Meaning** → A clear, concise definition of the term. + 2. **Further Explanation** → A short expansion with more detail or context (keep it brief). + 3. **Example** → Only include this if it is absolutely necessary (such as code snippets or practical use cases). + +- **Formatting Rules:** + - Do **not** repeat the keyword as a heading — the webpage already has it as the H1 title. + - Write directly into the sections (Meaning → Explanation → Example if needed). + - Do **not** title the specific sections: "Meaning", "Explanation". + - If you include an example, label it clearly (e.g., "Example:") and format the title in bold. + +- **Out-of-scope words:** + - If the word is not technical or relevant to software, programming, or technology, respond with a short, polite statement that it is out of scope for jargons.dev. + - Do **not** ask the user for clarification or another word. + - Instead, suggest that they try searching again if they meant something different. + +------------------------------ + +User: {question} +jAI:`; + +export const jAIPrompt = { + PERSONALITY: PromptTemplate.fromTemplate(PERSONALITY), + ASK: PromptTemplate.fromTemplate(ASK), +} From b3b6d03a68ba5d46b5120e0f98242ed463e4bd3f Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 04:14:46 +0100 Subject: [PATCH 03/39] feat: implement ask-jai endpoint --- src/pages/api/jai/ask.js | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/pages/api/jai/ask.js diff --git a/src/pages/api/jai/ask.js b/src/pages/api/jai/ask.js new file mode 100644 index 0000000..1f82c7f --- /dev/null +++ b/src/pages/api/jai/ask.js @@ -0,0 +1,65 @@ +import { LangChainAdapter } from "ai"; +import { RunnableSequence } from "@langchain/core/runnables"; +import { jAIPrompt, model } from "../../../../apps/jai/index.js"; +import { HttpResponseOutputParser } from "langchain/output_parsers"; + +export async function POST({ request }) { + const corsHeaders = { + "Access-Control-Allow-Origin": "same-origin", + "Access-Control-Allow-Methods": "POST, OPTIONS", + "Access-Control-Allow-Headers": "Content-Type, Authorization", + }; + + try { + // Extract the `messages` from the body of the request + const { messages } = await request.json(); + + const currentMessageContent = messages[messages.length - 1].content; + + // Create the parser - parses the response from the model into http-friendly format + const parser = new HttpResponseOutputParser(); + + // Create a chain of runnables - this is the core of the LangChain API + const chain = RunnableSequence.from([ + { + question: (input) => input.question, + }, + jAIPrompt.ASK, + model, + parser, + ]); + + // Convert the response into a friendly text-stream + const stream = await chain.stream({ + question: currentMessageContent, + }); + + // Convert Uint8Array stream to string stream before returning + const textStream = new ReadableStream({ + async start(controller) { + const decoder = new TextDecoder(); + for await (const chunk of stream) { + controller.enqueue(decoder.decode(chunk)); + } + controller.close(); + }, + }); + + const response = LangChainAdapter.toDataStreamResponse(textStream); + + // Add CORS headers to the response + Object.entries(corsHeaders).forEach(([key, value]) => { + response.headers.set(key, value); + }); + + return response; + } catch (e) { + return Response.json( + { error: e.message }, + { + status: e.status ?? 500, + headers: corsHeaders, + }, + ); + } +} \ No newline at end of file From b11c1ba57259ae79e2d2b7d1272c43bd0cce8c18 Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 04:16:23 +0100 Subject: [PATCH 04/39] feat: create Ask-JAI page for displaying ai-generate word meanings --- src/pages/browse/ask-jai/index.astro | 77 ++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/pages/browse/ask-jai/index.astro diff --git a/src/pages/browse/ask-jai/index.astro b/src/pages/browse/ask-jai/index.astro new file mode 100644 index 0000000..1ac5737 --- /dev/null +++ b/src/pages/browse/ask-jai/index.astro @@ -0,0 +1,77 @@ +--- +import { getCollection } from "astro:content"; +import BaseLayout from "../../../layouts/base.astro"; +import Navbar from "../../../components/navbar.astro"; +import JAIWord from "../../../components/islands/jai-word"; +import Search from "../../../components/islands/search.jsx"; +import { capitalizeText } from "../../../lib/utils/index.js"; + +const dictionary = await getCollection("dictionary"); + +const word = Astro.url.searchParams.get("word"); +if (!word) return Astro.redirect("/"); + +const title = capitalizeText(word); +--- + + + + + + +
+
+

+ {title} +

+ +
+ + + + +
+ +
+ + +
+
From 02f6156f79ba3fe86556c9bde3645b5ed7f7fa89 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 19 Mar 2025 16:47:07 +0100 Subject: [PATCH 05/39] feat: add JAI logo SVG and Astro component for consistent branding --- public/jAI.svg | 27 +++++++++++++++++++++++++++ src/components/jai-logo.astro | 28 ++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 public/jAI.svg create mode 100644 src/components/jai-logo.astro diff --git a/public/jAI.svg b/public/jAI.svg new file mode 100644 index 0000000..53017ff --- /dev/null +++ b/public/jAI.svg @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/components/jai-logo.astro b/src/components/jai-logo.astro new file mode 100644 index 0000000..dfa807a --- /dev/null +++ b/src/components/jai-logo.astro @@ -0,0 +1,28 @@ +--- +const { class:list } = Astro.props; +--- + + + + + + + + + + + + + \ No newline at end of file From 02e7c350a7d256afbf2f8a4af0e86726909877d1 Mon Sep 17 00:00:00 2001 From: babblebey Date: Fri, 5 Sep 2025 04:35:47 +0100 Subject: [PATCH 06/39] Refactor SVG logo component: improve formatting and update class names for consistency --- .prettierignore | 3 -- src/components/jai-logo.astro | 48 +++++++++++++++------------- src/components/jargonsdev-logo.astro | 47 ++++++++++++++------------- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/.prettierignore b/.prettierignore index c21b790..d562540 100644 --- a/.prettierignore +++ b/.prettierignore @@ -31,9 +31,6 @@ package-lock.json .DS_Store Thumbs.db -# SVG files with CDATA that cause parsing issues -src/components/jargonsdev-logo.astro - # Files with parsing issues in inline scripts src/layouts/base.astro diff --git a/src/components/jai-logo.astro b/src/components/jai-logo.astro index dfa807a..d65a21c 100644 --- a/src/components/jai-logo.astro +++ b/src/components/jai-logo.astro @@ -1,28 +1,30 @@ --- -const { class:list } = Astro.props; +const { class: list } = Astro.props; --- - - - - - - - - - - + + + + + + + - \ No newline at end of file + + diff --git a/src/components/jargonsdev-logo.astro b/src/components/jargonsdev-logo.astro index fa45e5e..40f3374 100644 --- a/src/components/jargonsdev-logo.astro +++ b/src/components/jargonsdev-logo.astro @@ -1,28 +1,29 @@ --- -const { class:list } = Astro.props; +const { class: list } = Astro.props; --- - - - - - - - - - - + + + + + + + - \ No newline at end of file + + From cf2907ff9173adeb62284cdce3636c35ced51947 Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 04:36:52 +0100 Subject: [PATCH 07/39] feat: add reference to JAI to Ask-JAI page --- src/pages/browse/ask-jai/index.astro | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/browse/ask-jai/index.astro b/src/pages/browse/ask-jai/index.astro index 1ac5737..d8d24ff 100644 --- a/src/pages/browse/ask-jai/index.astro +++ b/src/pages/browse/ask-jai/index.astro @@ -2,6 +2,7 @@ import { getCollection } from "astro:content"; import BaseLayout from "../../../layouts/base.astro"; import Navbar from "../../../components/navbar.astro"; +import JAILogo from "../../../components/jai-logo.astro"; import JAIWord from "../../../components/islands/jai-word"; import Search from "../../../components/islands/search.jsx"; import { capitalizeText } from "../../../lib/utils/index.js"; @@ -28,8 +29,8 @@ const title = capitalizeText(word);
-
-
+ Generated by +
From c0e8f2cfc3be12861ad90c2d201fe10dca6fe4aa Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 05:04:00 +0100 Subject: [PATCH 08/39] feat: add loading state to JAIWord component for better user experience --- src/components/islands/jai-word.jsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/components/islands/jai-word.jsx b/src/components/islands/jai-word.jsx index a9b7651..a4ebfde 100644 --- a/src/components/islands/jai-word.jsx +++ b/src/components/islands/jai-word.jsx @@ -23,6 +23,18 @@ export default function JAIWord({ word }) { }); }, [word]); + /** + * Loading State + */ + if (status === "submitted" || status === "ready" && messages.length === 0) return ( +
+
+
+
+
+
+ ); + return messages.map((msg, index) => ( { msg.role !== "user" && msg.content } From 74dbf8d9f12d511819d5060c9d23b40be401bf91 Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 05:05:09 +0100 Subject: [PATCH 09/39] format:fix --- apps/jai/lib/jai-prompt.js | 2 +- src/components/islands/jai-word.jsx | 39 ++++++++++++++-------------- src/pages/api/jai/ask.js | 2 +- src/pages/browse/ask-jai/index.astro | 2 +- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/apps/jai/lib/jai-prompt.js b/apps/jai/lib/jai-prompt.js index db858c7..e92a231 100644 --- a/apps/jai/lib/jai-prompt.js +++ b/apps/jai/lib/jai-prompt.js @@ -71,4 +71,4 @@ jAI:`; export const jAIPrompt = { PERSONALITY: PromptTemplate.fromTemplate(PERSONALITY), ASK: PromptTemplate.fromTemplate(ASK), -} +}; diff --git a/src/components/islands/jai-word.jsx b/src/components/islands/jai-word.jsx index a4ebfde..ac445bb 100644 --- a/src/components/islands/jai-word.jsx +++ b/src/components/islands/jai-word.jsx @@ -1,17 +1,17 @@ import { useEffect } from "react"; import Markdown from "react-markdown"; -import { useChat } from "@ai-sdk/react"; +import { useChat } from "@ai-sdk/react"; -export default function JAIWord({ word }) { +export default function JAIWord({ word }) { /** * Initialize useChat hook */ const { messages, status, append } = useChat({ - api: "/api/jai/ask", - onError: (e) => { - console.error(e); - }, - }); + api: "/api/jai/ask", + onError: (e) => { + console.error(e); + }, + }); /** * Handle Asking jAI for the word definition @@ -26,18 +26,17 @@ export default function JAIWord({ word }) { /** * Loading State */ - if (status === "submitted" || status === "ready" && messages.length === 0) return ( -
-
-
-
-
-
- ); + if (status === "submitted" || (status === "ready" && messages.length === 0)) + return ( +
+
+
+
+
+
+ ); return messages.map((msg, index) => ( - - { msg.role !== "user" && msg.content } - - )) -} \ No newline at end of file + {msg.role !== "user" && msg.content} + )); +} diff --git a/src/pages/api/jai/ask.js b/src/pages/api/jai/ask.js index 1f82c7f..42e1c8e 100644 --- a/src/pages/api/jai/ask.js +++ b/src/pages/api/jai/ask.js @@ -62,4 +62,4 @@ export async function POST({ request }) { }, ); } -} \ No newline at end of file +} diff --git a/src/pages/browse/ask-jai/index.astro b/src/pages/browse/ask-jai/index.astro index d8d24ff..3a60cd0 100644 --- a/src/pages/browse/ask-jai/index.astro +++ b/src/pages/browse/ask-jai/index.astro @@ -29,7 +29,7 @@ const title = capitalizeText(word);
- Generated by + Generated by
From 68cebaacea64fcae79ffddb549134ec369040a4f Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 14:40:46 +0100 Subject: [PATCH 10/39] fix: adjust z-index for meta features and ensure consistent JAI logo size --- src/pages/browse/ask-jai/index.astro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/browse/ask-jai/index.astro b/src/pages/browse/ask-jai/index.astro index 3a60cd0..b3a25fa 100644 --- a/src/pages/browse/ask-jai/index.astro +++ b/src/pages/browse/ask-jai/index.astro @@ -28,9 +28,9 @@ const title = capitalizeText(word);
-
+
Generated by - +
From 38cee948be6704e2136e64ec6265b462030f7edf Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 14:58:55 +0100 Subject: [PATCH 11/39] doc: document next imporvement that can be made --- src/pages/browse/ask-jai/index.astro | 45 +++++++--------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/src/pages/browse/ask-jai/index.astro b/src/pages/browse/ask-jai/index.astro index b3a25fa..082e027 100644 --- a/src/pages/browse/ask-jai/index.astro +++ b/src/pages/browse/ask-jai/index.astro @@ -27,38 +27,15 @@ const title = capitalizeText(word);
@@ -67,12 +44,12 @@ const title = capitalizeText(word); - + From d34afa65b78c780f7025816c57e1ea643dc17b79 Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 15:00:18 +0100 Subject: [PATCH 12/39] feat: update page title to include 'jAI Generated Meaning' for better clarity --- src/pages/browse/ask-jai/index.astro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/browse/ask-jai/index.astro b/src/pages/browse/ask-jai/index.astro index 082e027..6244a66 100644 --- a/src/pages/browse/ask-jai/index.astro +++ b/src/pages/browse/ask-jai/index.astro @@ -15,7 +15,7 @@ if (!word) return Astro.redirect("/"); const title = capitalizeText(word); --- - + From 67251822913ba99b5af0d146341151bef633f45f Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 15:11:34 +0100 Subject: [PATCH 13/39] feat: add JAILogo jsx component with SVG rendering for enhanced branding --- src/components/islands/jai-logo.jsx | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/components/islands/jai-logo.jsx diff --git a/src/components/islands/jai-logo.jsx b/src/components/islands/jai-logo.jsx new file mode 100644 index 0000000..6e3a3c2 --- /dev/null +++ b/src/components/islands/jai-logo.jsx @@ -0,0 +1,40 @@ +export default function JAILogo({ className }) { + return ( + + + + + + + + + + + + + + ); +} \ No newline at end of file From 862a08bad09e8d19f5a398bcbf89e6fb5feb0423 Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 15:25:09 +0100 Subject: [PATCH 14/39] =?UTF-8?q?feat:=20add=20SearchWithAskJAI=20componen?= =?UTF-8?q?t=20for=20enhanced=20search=20functionality=20with=20=E2=9C=A8j?= =?UTF-8?q?AI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/islands/search.jsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/components/islands/search.jsx b/src/components/islands/search.jsx index ab69bc4..d2c3226 100644 --- a/src/components/islands/search.jsx +++ b/src/components/islands/search.jsx @@ -279,6 +279,18 @@ const SearchInfo = () => (

); +/** + * Search Using AskJAI + */ +const SearchWithAskJAI = ({ word }) => ( + + Search with ✨jAI + +); + /** * Search result * @param {{ result: Array<{ id: number, doc: { title: string, slug: string }, searchTerm: string }> }} props From dbf622551820a7b8504bba240ded122b00e6bfbc Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 15:41:22 +0100 Subject: [PATCH 15/39] feat: integrate JAILogo into SearchWithAskJAI for enhanced branding and update search result display --- src/components/islands/search.jsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/islands/search.jsx b/src/components/islands/search.jsx index d2c3226..f209072 100644 --- a/src/components/islands/search.jsx +++ b/src/components/islands/search.jsx @@ -1,4 +1,5 @@ import Flexsearch from "flexsearch"; +import JAILogo from "./jai-logo.jsx"; import { useEffect, useState } from "react"; import { useStore } from "@nanostores/react"; import useRouter from "../../lib/hooks/use-router.js"; @@ -285,9 +286,15 @@ const SearchInfo = () => ( const SearchWithAskJAI = ({ word }) => ( - Search with ✨jAI + + {word} + + + Search with + + ); @@ -304,7 +311,7 @@ function SearchResult({ result = [], cursor, searchTerm }) { /** * @todo add message suggesting adding/contributing the word to dictionary */ -

No Result found

+ ) : ( result.map(({ doc }, i) => ( Date: Sun, 21 Sep 2025 15:43:20 +0100 Subject: [PATCH 16/39] feat: capitalize search term in SearchWithAskJAI for improved readability --- src/components/islands/search.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/islands/search.jsx b/src/components/islands/search.jsx index f209072..33d27a2 100644 --- a/src/components/islands/search.jsx +++ b/src/components/islands/search.jsx @@ -3,10 +3,10 @@ import JAILogo from "./jai-logo.jsx"; import { useEffect, useState } from "react"; import { useStore } from "@nanostores/react"; import useRouter from "../../lib/hooks/use-router.js"; -import { buildWordPathname, buildWordSlug } from "../../lib/utils/index.js"; import useIsMacOS from "../../lib/hooks/use-is-mac-os.js"; import useLockBody from "../../lib/hooks/use-lock-body.js"; import { $isSearchOpen } from "../../lib/stores/search.js"; +import { buildWordPathname, buildWordSlug, capitalizeText } from "../../lib/utils/index.js"; // Create Search Index const searchIndex = new Flexsearch.Document({ @@ -289,7 +289,7 @@ const SearchWithAskJAI = ({ word }) => ( className="relative flex items-center justify-between no-underline w-full p-2 md:p-4 hover:bg-gray-100" > - {word} + {capitalizeText(word)} Search with From b2dd60ef260d42c591af96296db69a2126775ddf Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 16:07:09 +0100 Subject: [PATCH 17/39] feat: implement cursor support for SearchWithAskJAI component --- src/components/islands/search.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/islands/search.jsx b/src/components/islands/search.jsx index 33d27a2..b8f50cc 100644 --- a/src/components/islands/search.jsx +++ b/src/components/islands/search.jsx @@ -283,10 +283,10 @@ const SearchInfo = () => ( /** * Search Using AskJAI */ -const SearchWithAskJAI = ({ word }) => ( +const SearchWithAskJAI = ({ word, cursor }) => ( {capitalizeText(word)} @@ -311,7 +311,7 @@ function SearchResult({ result = [], cursor, searchTerm }) { /** * @todo add message suggesting adding/contributing the word to dictionary */ - + ) : ( result.map(({ doc }, i) => ( Date: Sun, 21 Sep 2025 16:16:44 +0100 Subject: [PATCH 18/39] feat: update search term handling in SearchDialog to reset cursor on input change --- src/components/islands/search.jsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/islands/search.jsx b/src/components/islands/search.jsx index b8f50cc..b75820e 100644 --- a/src/components/islands/search.jsx +++ b/src/components/islands/search.jsx @@ -206,6 +206,14 @@ function SearchDialog() { } } + // Update search term state on input change and reset cursor + function handleSearchTermChange(e) { + setSearchTerm(e.target.value); + setCursor(-1); + } + + console.log(cursor); + return (
{/* Blur */} @@ -242,7 +250,7 @@ function SearchDialog() { type="text" value={searchTerm} onKeyDown={handleKeyboardCtrl} - onChange={(e) => setSearchTerm(e.target.value)} + onChange={handleSearchTermChange} className="block w-full bg-transparent text-gray-600 focus:outline-none text-base md:text-lg" /> Date: Sun, 21 Sep 2025 16:22:56 +0100 Subject: [PATCH 19/39] feat: allow cursor navigation for AskJAI search option when no results are found --- src/components/islands/search.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/islands/search.jsx b/src/components/islands/search.jsx index b75820e..f96af28 100644 --- a/src/components/islands/search.jsx +++ b/src/components/islands/search.jsx @@ -184,7 +184,8 @@ function SearchDialog() { // Arrow Up/Down & Enter - keybind function handleKeyboardCtrl(e) { - const resultsCount = searchResult?.length || 0; + // Results count - if no results, but search term exists, allow AskJAI search option cursor navigation + const resultsCount = searchResult?.length || (searchTerm.length >= 1 ? 1 : 0); if (resultsCount && e.key === "ArrowUp") { e.preventDefault(); setCursor( From debba7136e2c71f5c51bcb4a26101a0d967ed512 Mon Sep 17 00:00:00 2001 From: babblebey Date: Sun, 21 Sep 2025 20:06:47 +0100 Subject: [PATCH 20/39] refactor: rename all parts to unify name as `SearchWithJAI` --- apps/jai/lib/jai-prompt.js | 4 ++-- .../islands/{jai-word.jsx => jai-word-search.jsx} | 4 ++-- src/components/islands/search.jsx | 8 ++++---- src/pages/api/jai/{ask.js => search.js} | 2 +- src/pages/browse/{ask-jai => with-jai}/index.astro | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) rename src/components/islands/{jai-word.jsx => jai-word-search.jsx} (92%) rename src/pages/api/jai/{ask.js => search.js} (98%) rename src/pages/browse/{ask-jai => with-jai}/index.astro (94%) diff --git a/apps/jai/lib/jai-prompt.js b/apps/jai/lib/jai-prompt.js index e92a231..417576f 100644 --- a/apps/jai/lib/jai-prompt.js +++ b/apps/jai/lib/jai-prompt.js @@ -33,7 +33,7 @@ Current conversation: {chat_history} User: {question} jAI:`; -const ASK = `You are jAI, an AI-powered assistant for jargons.dev, a dictionary of technical terms for developers, software engineers, and technology professionals. Your task is to write definitions for technical words or jargons I provide, following these rules: +const SEARCH_WORD = `You are jAI, an AI-powered assistant for jargons.dev, a dictionary of technical terms for developers, software engineers, and technology professionals. Your task is to write definitions for technical words or jargons I provide, following these rules: - **Style & Tone:** - Keep the meaning **formal, clear, and simplified**. @@ -70,5 +70,5 @@ jAI:`; export const jAIPrompt = { PERSONALITY: PromptTemplate.fromTemplate(PERSONALITY), - ASK: PromptTemplate.fromTemplate(ASK), + SEARCH_WORD: PromptTemplate.fromTemplate(SEARCH_WORD), }; diff --git a/src/components/islands/jai-word.jsx b/src/components/islands/jai-word-search.jsx similarity index 92% rename from src/components/islands/jai-word.jsx rename to src/components/islands/jai-word-search.jsx index ac445bb..a6d3213 100644 --- a/src/components/islands/jai-word.jsx +++ b/src/components/islands/jai-word-search.jsx @@ -2,12 +2,12 @@ import { useEffect } from "react"; import Markdown from "react-markdown"; import { useChat } from "@ai-sdk/react"; -export default function JAIWord({ word }) { +export default function JAIWordSearch({ word }) { /** * Initialize useChat hook */ const { messages, status, append } = useChat({ - api: "/api/jai/ask", + api: "/api/jai/search", onError: (e) => { console.error(e); }, diff --git a/src/components/islands/search.jsx b/src/components/islands/search.jsx index f96af28..674dcaa 100644 --- a/src/components/islands/search.jsx +++ b/src/components/islands/search.jsx @@ -290,11 +290,11 @@ const SearchInfo = () => ( ); /** - * Search Using AskJAI + * Search Using JAI */ -const SearchWithAskJAI = ({ word, cursor }) => ( +const SearchWithJAI = ({ word, cursor }) => ( @@ -320,7 +320,7 @@ function SearchResult({ result = [], cursor, searchTerm }) { /** * @todo add message suggesting adding/contributing the word to dictionary */ - + ) : ( result.map(({ doc }, i) => ( input.question, }, - jAIPrompt.ASK, + jAIPrompt.SEARCH_WORD, model, parser, ]); diff --git a/src/pages/browse/ask-jai/index.astro b/src/pages/browse/with-jai/index.astro similarity index 94% rename from src/pages/browse/ask-jai/index.astro rename to src/pages/browse/with-jai/index.astro index 6244a66..3ae2bbe 100644 --- a/src/pages/browse/ask-jai/index.astro +++ b/src/pages/browse/with-jai/index.astro @@ -3,9 +3,9 @@ import { getCollection } from "astro:content"; import BaseLayout from "../../../layouts/base.astro"; import Navbar from "../../../components/navbar.astro"; import JAILogo from "../../../components/jai-logo.astro"; -import JAIWord from "../../../components/islands/jai-word"; import Search from "../../../components/islands/search.jsx"; import { capitalizeText } from "../../../lib/utils/index.js"; +import JAIWordSearch from "../../../components/islands/jai-word-search.jsx"; const dictionary = await getCollection("dictionary"); @@ -41,7 +41,7 @@ const title = capitalizeText(word);
- +
+ ### Integration Flow 1. **Data Preparation**: `seed-vector-store.js` populates the vector database with dictionary content From aa0c9875020d8395b8cc86458a97381fbd50faee Mon Sep 17 00:00:00 2001 From: Olabode Lawal-Shittabey Date: Wed, 24 Sep 2025 01:05:33 +0100 Subject: [PATCH 37/39] Update apps/jai/components/word-search.jsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- apps/jai/components/word-search.jsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/jai/components/word-search.jsx b/apps/jai/components/word-search.jsx index 5ee8fe3..c33e6a8 100644 --- a/apps/jai/components/word-search.jsx +++ b/apps/jai/components/word-search.jsx @@ -76,13 +76,11 @@ export default function JAIWordSearch({ word }) {
); - return messages.map((msg, index) => - msg.role !== "user" ? ( + return messages + .filter((msg) => msg.role !== "user") + .map((msg, index) => ( {msg.content} - ) : ( - <> - ), - ); + )); } /** From 55e961366e8e577a376d32c6310a1c8ca4d77c9f Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 24 Sep 2025 01:08:30 +0100 Subject: [PATCH 38/39] fix:code format --- apps/jai/components/word-search.jsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/jai/components/word-search.jsx b/apps/jai/components/word-search.jsx index c33e6a8..60f1c51 100644 --- a/apps/jai/components/word-search.jsx +++ b/apps/jai/components/word-search.jsx @@ -78,9 +78,7 @@ export default function JAIWordSearch({ word }) { return messages .filter((msg) => msg.role !== "user") - .map((msg, index) => ( - {msg.content} - )); + .map((msg, index) => {msg.content}); } /** From ff3aa09c4e46babfc251d4b4217817bd33bf7529 Mon Sep 17 00:00:00 2001 From: babblebey Date: Wed, 24 Sep 2025 01:15:46 +0100 Subject: [PATCH 39/39] fix: add missing documentation for JAI Word Search components --- apps/jai/components/word-search.jsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/jai/components/word-search.jsx b/apps/jai/components/word-search.jsx index 60f1c51..08379ce 100644 --- a/apps/jai/components/word-search.jsx +++ b/apps/jai/components/word-search.jsx @@ -1,3 +1,9 @@ +/** + * JAI Word Search Feature Components + * @exports JAIWordSearch - Fetches and displays AI-generated word definitions with loading and error states + * @exports JAIWordSearchTrigger - Link component to initiate a word search with jAI + */ + import { useEffect, useState } from "react"; import Markdown from "react-markdown"; import { useChat } from "@ai-sdk/react";