Tentang
It’s my portfolio, reimagined as a chat conversation, answered by AI.
AI dan pembelajaran mesinYang dapat Anda lakukan
- Streaming chat with markdown rendering and shadcn/typeset
- Web search via OpenRouter's web search server tool
- Web fetch via the AI SDK's first-party web fetch tool, with HTML-to-markdown conversion and SSRF protections
- Human-in-the-loop questionnaire. The model can ask clarifying questions, answered with the shadcn questionnaire component
Pertumbuhan bintang terukur
- dalam 24 jam
- 0
- dalam 7 hari
- Mengumpulkan riwayat
- dalam 15 hari
- Mengumpulkan riwayat
- dalam 1 bulan
- Mengumpulkan riwayat
Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.
README.md
AsliNathan's AI
It’s my portfolio, reimagined as a chat conversation, answered by AI.
Features
- Streaming chat with markdown rendering and shadcn/typeset
- Tool calling
- Web search via OpenRouter's web search server tool
- Web fetch via the AI SDK's first-party web fetch tool, with HTML-to-markdown conversion and SSRF protections
- Human-in-the-loop questionnaire. The model can ask clarifying questions, answered with the shadcn questionnaire component
- Per-IP rate limiting on
/api/chatwith Upstash Redis +@upstash/ratelimit - Drizzle ORM + Neon PostgreSQL chat persistence
- Server-rendered SEO surface: JSON-LD, canonical metadata, sitemap, robots,
llms.txt, manifest, and dynamic OG images - Title animation from @jh3yy
Deploy
The vite config uses Nitro by default, which supports many deployment presets like Netlify, Vercel, Node.js, and more. Refer to the TanStack Start hosting docs for more information.
Set the following in your hosting provider's environment variables:
OPENROUTER_API_KEY, create one at openrouter.ai/keys.UPSTASH_REDIS_REST_URLandUPSTASH_REDIS_REST_TOKEN, create a Redis database at console.upstash.com, then copy the REST URL and REST token from the database details (or use the Vercel Upstash integration, which sets them automatically).DATABASE_URLandGITHUB_API_TOKEN— see.env.schema, which is the source of truth for every variable. Use your Neon project's pooled connection string forDATABASE_URL.
After the first deploy, verify the domain in Google Search Console and Bing Webmaster Tools, then submit https://chat.brodin.dev/sitemap.xml.
Local development
Prerequisites
Setup
vp install
Create a Neon project, then create a .env.local file with your values based on .env.schema. Copy the pooled connection string into DATABASE_URL, then validate the environment:
vpr env:load
Create an OpenRouter key at openrouter.ai/keys and a Redis database at console.upstash.com.
Generate the initial migration with drizzle-kit, then apply it to your Neon database:
vpr db generate
vpr db migrate
https://orm.drizzle.team/docs/migrations
Start the dev server:
vpr dev
The development server should now be running at http://localhost:3000.
That's it, you are all set! If you run into any problems or have any questions, please hesitate to ask me.
Configuration
Varlock keeps the environment-variable contract in .env.schema and generates types from it. Put local values, including secrets, in the uncommitted .env.local, then run vpr env:load to validate them.
In application code, import { ENV } from "varlock/env" instead of reading process.env directly.
The model is defined in src/lib/chat/model.ts, together with its context window and output limit.
Rate limit
/api/chat is rate-limited per client IP with @upstash/ratelimit backed by Upstash Redis (Redis.fromEnv()).
Current windows, in src/routes/api/chat/route.ts:
Ratelimit.slidingWindow(5, "30s") // burst: 5 requests per 30 seconds
Ratelimit.slidingWindow(50, "24h") // daily: 50 requests per day
Both limits are keyed by the first IP in the x-forwarded-for header (requests without the header share a single fallback bucket). Exceeding either returns 429 with { "error": "Ratelimited" }. Tune the numbers there to match your budget — see the Security section below.
Security
The /api/chat route is public: every allowed request spends your OpenRouter credits. It is rate-limited (see Configuration above).
- Rate limit is per-IP, not global. One IP is capped at 50 requests/day with the default windows, but N IPs (botnet, rotating proxies) get N× the budget.
- Cap spend. Keep an OpenRouter spend limit as a backstop.
- Add a WAF if abuse appears: add firewall rules from your hosting provider in front of
/api/chat. - Requests without an
x-forwarded-forheader share one fallback bucket, so they throttle each other — expected on local dev, suspicious in production logs. - Web fetch can request any public URL. It blocks localhost, private, reserved, and cloud metadata addresses, including redirects and DNS-resolved addresses, and caps response size. Fetched content is untrusted and can contain prompt injections; set
requireUrlInUserMessage: truein src/lib/chat/tools/web_fetch.ts so the model can only fetch URLs that appear in user messages.
The route already validates the request body, caps output tokens and step count, and aborts generation on client disconnect — but those bound a single request, not overall volume.
How it works
- src/routes/api/chat/route.ts rate-limits by IP with Upstash, then streams responses with
streamTextbehind a TanStack Start API route (server handlers) - src/components/chat/ renders the conversation with
useChatand coss chat primitives, entry at src/components/chat/index.tsx, served by the/route. - src/lib/chat/agent/nathan.ts defines the
ToolLoopAgent— model, instructions, and step limit — and wires in the tools. - src/lib/chat/tools/ defines the tools — one file per tool (the filename is the model-facing tool name), composed in src/lib/chat/tools/index.ts: a server-executed GitHub repo lookup, web fetch, the interactive
ask_userquestionnaire, and provider-native web search.
Tool parts
Assistant messages are a list of typed parts. src/components/chat/chat-message.tsx switches on part.type and delegates each one to a component in src/components/chat/parts/:
| Part type | Component | Renders |
|---|---|---|
text |
text-part.tsx | Markdown via react-markdown and coss typeset. |
tool-github_repo |
github-repo-part.tsx | A spinner while the lookup runs, then a linked stat line (stars, forks, language). |
tool-web_search |
web-search-part.tsx | A "Searching the web…" status while the search runs, then a persistent "Searched the web" line per search. |
tool-web_fetch |
web-fetch-part.tsx | A "Reading…" status while the page loads, then a collapsible summary with a markdown preview and an external link. |
tool-ask_user |
ask-user-part.tsx | The answered questions inline. Pending questions render in question-card.tsx, pinned to the scroller bottom. |
source-url |
sources-part.tsx | Web search citations, deduped into a "Searched N websites" drawer once the message finishes streaming. |
Tool parts move through states as the stream progresses — input-streaming → input-available → output-available (or output-error) — and each component switches on part.state to show progress, results, and failures.
Adding your own tool
- Create
src/lib/chat/tools/<name>.ts(the filename is the model-facing tool name) exporting atool()with adescription, aninputSchema, and anexecutefunction (omitexecutefor tools the user answers in the UI, likeask_user), then register it in src/lib/chat/tools/index.ts. - Add a part component in src/components/chat/parts/ and a
case "tool-<name>"in chat-message.tsx.
Message types are inferred from the tool definitions via InferUITools, so part.input and part.output are fully typed in your part component — renaming a tool field is a build error, not a silent undefined.
Logging
evlog is wired into the app through Nitro and emits one structured event per request. Chat requests also emit a correlated chat.ai event when the stream ends, because Nitro v3 logs the request before streamed AI usage is known. Add a drain when production needs logs sent to your chosen provider.
SEO & GEO
The indexable pages are /, /about, and /privacy. Conversation routes are noindex and excluded from the sitemap.
Machine-readable endpoints:
/robots.txt— crawl rules and sitemap/sitemap.xml— the three indexable pages/llms.txtand/llms-full.txt— AI-readable site index and app reference/llms.md— markdown version of the site index/about.mdand/privacy.md— markdown versions of the content pages/manifest.webmanifest— install metadata and icons/og— dynamic 1200×630 social card
The public pages (/, /about, /privacy) also negotiate content. Requests that include Accept: text/markdown receive markdown — the homepage returns the site index — while browsers asking for HTML get the app. Both variants send Vary: Accept so shared caches keep them separate.
The canonical Person entity lives on brodin.dev. Chat's JSON-LD references https://brodin.dev/#person rather than defining a competing profile.
When page content changes, update lastModified in src/lib/seo.ts. If the logo changes, run vpr icons to regenerate the favicon and PWA icon set.
Scripts
Check package.json for the full list of available scripts.
db- Run drizzle-kit commands. (e.g.vpr db generate,vpr db studio)ui- The shadcn/ui CLI. (e.g.vpr ui add button)icons- Regenerate the favicon, Apple touch icon, and PWA icons withscripts/generate-icons.mjs.format,lint- Run Oxfmt and Oxlint, or both viavpr check.deps- Selectively upgrade dependencies via taze. Dependency versions are pinned, so runvpr depsto selectively upgrade packages.
Utilities
theme-toggle.tsx,theme-provider.tsx- A theme toggle and provider for toggling between light and dark mode (presstanywhere outside a text field to toggle).
Issue watchlist
- Devtools releases - TanStack Devtools is in alpha and may still have breaking changes.
- Nitro v3 beta - The app is configured with Nitro v3 beta by default.
- evlog Nitro v3 streaming - Nitro v3 emits request events at response headers, so stream-end AI usage is logged as a separate correlated
chat.aievent. - Drizzle ORM v1 RC - Drizzle ORM v1 is in RC with relations v2.
License
MIT, see LICENSE.
Jelajahi proyek terkait
Memuat…