xonecas.io
53129
Pa

PAT / commit 14b407d

chore: npm run format

xonecas2025-12-16 14b407d7e348182955cfa7c7ebb6e5614a3eabfa parent a9e5702

15 files changed

.prettierrc+0−1
@@ -7,4 +7,3 @@
77 "useTabs": false,
88 "plugins": ["prettier-plugin-tailwindcss"]
99 }
10-
AGENTS.md+2−2
@@ -1,6 +1,6 @@
11 # AGENTS.md
22
3-This is a personal assistant project, that renders a simple assistant chat layout as a web page, and provides access to an agentic model running locally via ollama. The project uses Next.js for it's typescript framework TailwindCSS for it's styling, and Ollama's typescript/javascript library itself for querying the model. This project is also responsible for augmenting the model's prompt with search results from DuckDuckGo.
3+This is a personal assistant project, that renders a simple assistant chat layout as a web page, and provides access to an agentic model running locally via ollama. The project uses Next.js for it's typescript framework TailwindCSS for it's styling, and Ollama's typescript/javascript library itself for querying the model. This project is also responsible for augmenting the model's prompt with search results from DuckDuckGo.
44
55 ## Project Commands
66
@@ -218,4 +218,4 @@ Agents MUST use only these existing dependencies. Do NOT add new dependencies wi
218218 - **DO NOT** Commit secrets or API keys, edit `node_modules/` or `vendor/`
219219 - **DO** maintain existing code style and patterns
220220 - **DO** use existing utility functions from `src/lib/`
221-- **DO** follow the App Router conventions for Next.js 16
221+- **DO** follow the App Router conventions for Next.js 16
TODO.md+1−1
@@ -3,7 +3,7 @@
33 ## BUGS:
44
55 - use the chat() function of the ollama library instead of generate, so we can send the history of messages.
6-- Improve websearch, currently not working at all. Use this as a template: https://github.com/meirm/ollama-tools/blob/main/sample_functions.py#L5
6+- Improve websearch, currently not working at all. Use this as a template: https://github.com/meirm/ollama-tools/blob/main/sample_functions.py#L5
77
88 ## New features:
99
app/api/chat/route.ts+2−5
@@ -13,16 +13,13 @@ export async function POST(request: Request) {
1313
1414 // 2. Build prompt
1515 const prompt = `${message}\n\nRelevant info from DuckDuckGo: ${JSON.stringify(
16- searchResults,
16+ searchResults
1717 )}\n\nAssistant:`;
1818
1919 const answer = await fetchOllamaResponse(prompt);
2020 return NextResponse.json({ answer });
2121 } catch (error) {
2222 console.error("Chat API error", error);
23- return NextResponse.json(
24- { answer: "Sorry, something went wrong." },
25- { status: 500 },
26- );
23+ return NextResponse.json({ answer: "Sorry, something went wrong." }, { status: 500 });
2724 }
2825 }
app/globals.css+7−7
@@ -12,7 +12,7 @@
1212 .markdown-content h4,
1313 .markdown-content h5,
1414 .markdown-content h6 {
15- @apply font-bold mt-4 mb-2;
15+ @apply mb-2 mt-4 font-bold;
1616 }
1717
1818 .markdown-content h1 {
@@ -49,27 +49,27 @@
4949 }
5050
5151 .markdown-content blockquote {
52- @apply border-l-4 border-slate-500 dark:border-slate-400 pl-4 italic my-2;
52+ @apply my-2 border-l-4 border-slate-500 pl-4 italic dark:border-slate-400;
5353 }
5454
5555 .markdown-content a {
56- @apply text-emerald-700 dark:text-emerald-400 underline;
56+ @apply text-emerald-700 underline dark:text-emerald-400;
5757 }
5858
5959 .markdown-content table {
60- @apply border-collapse border border-slate-500 dark:border-slate-400 mb-2;
60+ @apply mb-2 border-collapse border border-slate-500 dark:border-slate-400;
6161 }
6262
6363 .markdown-content th,
6464 .markdown-content td {
65- @apply border border-slate-500 dark:border-slate-400 px-2 py-1;
65+ @apply border border-slate-500 px-2 py-1 dark:border-slate-400;
6666 }
6767
6868 .markdown-content th {
69- @apply bg-slate-400 dark:bg-slate-800 font-bold;
69+ @apply bg-slate-400 font-bold dark:bg-slate-800;
7070 }
7171
7272 /* Code block styling */
7373 .markdown-content pre {
74- @apply p-3 mb-2 overflow-x-auto;
74+ @apply mb-2 overflow-x-auto p-3;
7575 }
app/layout.tsx+2−7
@@ -2,15 +2,10 @@ import "./globals.css";
22
33 export const metadata = {
44 title: "Personal Assistant",
5- description:
6- "A simple personal assistant app built with Next.js, Tailwind, and Ollama.",
5+ description: "A simple personal assistant app built with Next.js, Tailwind, and Ollama.",
76 };
87
9-export default function RootLayout({
10- children,
11-}: {
12- children: React.ReactNode;
13-}) {
8+export default function RootLayout({ children }: { children: React.ReactNode }) {
149 return (
1510 <html lang="en">
1611 <body>{children}</body>
app/page.tsx+31−40
@@ -39,7 +39,9 @@ export default function Home() {
3939 let permissionState = "unknown";
4040 if (navigator.permissions) {
4141 try {
42- const permission = await navigator.permissions.query({ name: "geolocation" as PermissionName });
42+ const permission = await navigator.permissions.query({
43+ name: "geolocation" as PermissionName,
44+ });
4345 permissionState = permission.state;
4446 } catch (e) {
4547 // Permissions API might not support geolocation query
@@ -48,22 +50,19 @@ export default function Home() {
4850
4951 try {
5052 const position = await new Promise<GeolocationPosition>((resolve, reject) => {
51- navigator.geolocation.getCurrentPosition(
52- resolve,
53- reject,
54- {
55- timeout: 10000,
56- enableHighAccuracy: false,
57- maximumAge: 60000
58- }
59- );
53+ navigator.geolocation.getCurrentPosition(resolve, reject, {
54+ timeout: 10000,
55+ enableHighAccuracy: false,
56+ maximumAge: 60000,
57+ });
6058 });
6159 const { latitude, longitude } = position.coords;
6260 parts.push(`**Location:** ${latitude.toFixed(4)}, ${longitude.toFixed(4)}`);
6361 } catch (error: any) {
6462 let errorMsg = "Unable to retrieve";
6563 if (error?.code === 1) {
66- errorMsg = permissionState === "prompt" ? "Permission prompt shown" : "Permission denied";
64+ errorMsg =
65+ permissionState === "prompt" ? "Permission prompt shown" : "Permission denied";
6766 } else if (error?.code === 2) {
6867 errorMsg = "Position unavailable";
6968 } else if (error?.code === 3) {
@@ -80,18 +79,18 @@ export default function Home() {
8079 // Local time
8180 const now = new Date();
8281 const timeString = now.toLocaleString(undefined, {
83- weekday: 'long',
84- year: 'numeric',
85- month: 'long',
86- day: 'numeric',
87- hour: '2-digit',
88- minute: '2-digit',
89- second: '2-digit',
90- timeZoneName: 'short'
82+ weekday: "long",
83+ year: "numeric",
84+ month: "long",
85+ day: "numeric",
86+ hour: "2-digit",
87+ minute: "2-digit",
88+ second: "2-digit",
89+ timeZoneName: "short",
9190 });
9291 parts.push(`**Local Time:** ${timeString}`);
9392
94- const message = parts.join('\n\n');
93+ const message = parts.join("\n\n");
9594 setMessages([{ role: "assistant", content: message }]);
9695 };
9796
@@ -170,26 +169,18 @@ export default function Home() {
170169 };
171170
172171 return (
173- <div className="h-screen flex bg-slate-200 dark:bg-slate-900 text-slate-800 dark:text-slate-200">
174- <div className="flex-1 flex flex-col min-w-0">
175- <div
172+ <div className="flex h-screen bg-slate-200 text-slate-800 dark:bg-slate-900 dark:text-slate-200">
173+ <div className="flex min-w-0 flex-1 flex-col">
174+ <div
176175 ref={messagesContainerRef}
177176 className="flex-1 overflow-y-auto overflow-x-hidden bg-slate-200 dark:bg-slate-900"
178177 >
179- <div className="flex flex-col justify-end min-h-full">
178+ <div className="flex min-h-full flex-col justify-end">
180179 {messages.map((msg, i) => (
181- <div
182- key={i}
183- className="min-w-0"
184- >
185- <div
186- className="p-2 m-2 bg-slate-300 dark:bg-slate-950 text-slate-800 dark:text-slate-200 markdown-content"
187- >
180+ <div key={i} className="min-w-0">
181+ <div className="markdown-content m-2 bg-slate-300 p-2 text-slate-800 dark:bg-slate-950 dark:text-slate-200">
188182 {msg.role === "assistant" ? (
189- <ReactMarkdown
190- remarkPlugins={[remarkGfm]}
191- rehypePlugins={[rehypeHighlight]}
192- >
183+ <ReactMarkdown remarkPlugins={[remarkGfm]} rehypePlugins={[rehypeHighlight]}>
193184 {msg.content}
194185 </ReactMarkdown>
195186 ) : (
@@ -208,17 +199,17 @@ export default function Home() {
208199 onChange={(e) => setInput(e.target.value)}
209200 onKeyDown={handleKeyDown}
210201 placeholder="Type a message..."
211- className="flex-1 px-3 py-2 bg-slate-300 dark:bg-slate-950 placeholder:italic placeholder:text-slate-600 dark:placeholder:text-slate-400 focus:outline-none"
202+ className="flex-1 bg-slate-300 px-3 py-2 placeholder:italic placeholder:text-slate-600 focus:outline-none dark:bg-slate-950 dark:placeholder:text-slate-400"
212203 />
213204 <button
214205 type="submit"
215- className="px-4 py-2 bg-emerald-900 dark:bg-emerald-500 text-slate-100 dark:text-slate-900 hover:bg-emerald-800 dark:hover:bg-emerald-600"
206+ className="bg-emerald-900 px-4 py-2 text-slate-100 hover:bg-emerald-800 dark:bg-emerald-500 dark:text-slate-900 dark:hover:bg-emerald-600"
216207 >
217- <PaperPlaneIcon className="w-5 h-5" />
208+ <PaperPlaneIcon className="h-5 w-5" />
218209 </button>
219210 </form>
220211 </div>
221- <div className="w-64 bg-slate-300 dark:bg-slate-950 p-4">
212+ <div className="w-64 bg-slate-300 p-4 dark:bg-slate-950">
222213 <div className="flex items-center justify-between">
223214 <span>Dark Mode</span>
224215 <button
@@ -228,7 +219,7 @@ export default function Home() {
228219 }`}
229220 >
230221 <span
231- className={`inline-block h-4 w-4 transform bg-slate-200 dark:bg-slate-100 transition-transform ${
222+ className={`inline-block h-4 w-4 transform bg-slate-200 transition-transform dark:bg-slate-100 ${
232223 isDark ? "translate-x-6" : "translate-x-1"
233224 }`}
234225 />
drizzle.config.ts+0−1
@@ -16,4 +16,3 @@ export default {
1616 url: "./data/database.db",
1717 },
1818 } satisfies Config;
19-
src/components/icons/PaperPlaneIcon.tsx+0−1
@@ -15,4 +15,3 @@ export default function PaperPlaneIcon({ className }: { className?: string }) {
1515 </svg>
1616 );
1717 }
18-
src/lib/db/index.ts+0−2
@@ -25,5 +25,3 @@ export const db = drizzle(sqlite, { schema });
2525 export function closeDatabase() {
2626 sqlite.close();
2727 }
28-
29-
src/lib/db/schema.ts+12−6
@@ -5,16 +5,24 @@ import { relations } from "drizzle-orm";
55 export const threads = sqliteTable("threads", {
66 id: integer("id").primaryKey({ autoIncrement: true }),
77 title: text("title"),
8- createdAt: integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => new Date()),
9- updatedAt: integer("updated_at", { mode: "timestamp" }).notNull().$defaultFn(() => new Date()),
8+ createdAt: integer("created_at", { mode: "timestamp" })
9+ .notNull()
10+ .$defaultFn(() => new Date()),
11+ updatedAt: integer("updated_at", { mode: "timestamp" })
12+ .notNull()
13+ .$defaultFn(() => new Date()),
1014 });
1115
1216 export const messages = sqliteTable("messages", {
1317 id: integer("id").primaryKey({ autoIncrement: true }),
14- threadId: integer("thread_id").notNull().references(() => threads.id, { onDelete: "cascade" }),
18+ threadId: integer("thread_id")
19+ .notNull()
20+ .references(() => threads.id, { onDelete: "cascade" }),
1521 role: text("role").notNull(), // "user" or "assistant"
1622 content: text("content").notNull(),
17- createdAt: integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => new Date()),
23+ createdAt: integer("created_at", { mode: "timestamp" })
24+ .notNull()
25+ .$defaultFn(() => new Date()),
1826 });
1927
2028 // Define relations
@@ -33,5 +41,3 @@ export type Thread = typeof threads.$inferSelect;
3341 export type NewThread = typeof threads.$inferInsert;
3442 export type Message = typeof messages.$inferSelect;
3543 export type NewMessage = typeof messages.$inferInsert;
36-
37-
src/lib/duckduckgo.ts+7−8
@@ -4,19 +4,19 @@ export interface DuckDuckGoResult {
44 url: string;
55 }
66
7-const DDG_ENDPOINT = 'https://api.duckduckgo.com/';
7+const DDG_ENDPOINT = "https://api.duckduckgo.com/";
88
99 export async function fetchDuckDuckGo(query: string): Promise<DuckDuckGoResult[]> {
1010 const params = new URLSearchParams({
1111 q: query,
12- format: 'json',
13- no_html: '1',
14- skip_disambig: '1',
12+ format: "json",
13+ no_html: "1",
14+ skip_disambig: "1",
1515 });
1616
1717 const url = `${DDG_ENDPOINT}?${params.toString()}`;
1818
19- const res = await fetch(url, { headers: { Accept: 'application/json' } });
19+ const res = await fetch(url, { headers: { Accept: "application/json" } });
2020 if (!res.ok) {
2121 throw new Error(`DuckDuckGo API error: ${res.status} ${res.statusText}`);
2222 }
@@ -31,10 +31,9 @@ export async function fetchDuckDuckGo(query: string): Promise<DuckDuckGoResult[]
3131 for (const item of topics) {
3232 if (item.Text && item.FirstURL) {
3333 // Use the first line of the text as a title
34- const title = item.Text.split('\n')[0];
34+ const title = item.Text.split("\n")[0];
3535 // Limit snippet to 70 characters
36- const snippet =
37- item.Text.length > 70 ? item.Text.slice(0, 70) + '…' : item.Text;
36+ const snippet = item.Text.length > 70 ? item.Text.slice(0, 70) + "…" : item.Text;
3837 results.push({
3938 title,
4039 snippet,
src/lib/ollama.ts+1−4
@@ -11,10 +11,7 @@ import ollama from "ollama";
1111 * @returns The text generated by the model.
1212 * @throws If the request fails.
1313 */
14-export async function fetchOllamaResponse(
15- prompt: string,
16- model = "gpt-oss",
17-): Promise<string> {
14+export async function fetchOllamaResponse(prompt: string, model = "gpt-oss"): Promise<string> {
1815 const result = await ollama.generate({ model, prompt });
1916 // The official package returns an object with a `response` field.
2017 // Adjust if the shape differs.
tailwind.config.js+1−4
@@ -1,8 +1,5 @@
11 module.exports = {
2- content: [
3- "./app/**/*.{js,ts,jsx,tsx}",
4- "./src/**/*.{js,ts,jsx,tsx}",
5- ],
2+ content: ["./app/**/*.{js,ts,jsx,tsx}", "./src/**/*.{js,ts,jsx,tsx}"],
63 darkMode: "class",
74 theme: {
85 extend: {},
tsconfig.json+2−8
@@ -1,11 +1,7 @@
11 {
22 "compilerOptions": {
33 "target": "ES2017",
4- "lib": [
5- "dom",
6- "dom.iterable",
7- "esnext"
8- ],
4+ "lib": ["dom", "dom.iterable", "esnext"],
95 "allowJs": true,
106 "skipLibCheck": true,
117 "strict": false,
@@ -31,7 +27,5 @@
3127 "**/*.ts",
3228 "**/*.tsx"
3329 ],
34- "exclude": [
35- "node_modules"
36- ]
30+ "exclude": ["node_modules"]
3731 }