import * as Bun from "bun"; import { Suspense } from "react"; import { TwitterApiService, TwitterBookmark } from "../lib/twitter-api"; import { userCategories, type CategorizationResponse, } from "../lib/categorization"; import { LLMService } from "../lib/llm-service"; import ProcessedBookmark from "../components/cat/Entry"; interface CategorizePageProps { bookmarks: Awaited>; currentBookmarkIndex: number; categorization?: CategorizationResponse; error?: string; } async function CategorizationFetcher({ bookmarks, currentIndex, }: { bookmarks: TwitterBookmark[]; currentIndex: number; }) { if (currentIndex >= bookmarks.length) { return (

All Bookmarks Categorized!

You've successfully categorized all your bookmarks.

Back to Bookmarks
); } const bookmark = bookmarks[currentIndex]; const llmRes = await callLLM(bookmark!); if ("error" in llmRes) return (
Error categorizing bookmark: {llmRes.error}
); return (
); } function LoadingSpinner() { return (
Loading your Twitter bookmarks...
); } export default async function CategorizePage(props: any) { // console.log({ props }); const params = new URLSearchParams(props.query); const currentIndex = Number(params.get("idx") || "0"); const cookie = Bun.env.TWATTER_COKI; if (!cookie) { return (
Missing Twitter cookie configuration
); } const twbookmarks = await getTwData(cookie); if ("error" in twbookmarks) { return (
Error fetching Twatter bookmarks
); } // const currentIndex = parseInt(searchParams.index || '0', 10); const totalCount = twbookmarks.ok.length; return (
Categorize Bookmarks - SORMARK

Categorize Bookmarks

Review and categorize your Twitter bookmarks one by one

}> <>

Bookmark {currentIndex + 1} of {totalCount}

); } import bmarks from "../lib/testData.json"; async function getTwData(cookie: string) { try { // const twitterService = new TwitterApiService(cookie); // const bookmarks = await twitterService.fetchAllBookmarks(); // return { ok: bookmarks }; return { ok: bmarks } as any; } catch (error) { return { error: `${error}` }; } } async function callLLM(bookmark: TwitterBookmark) { const apiKey = Bun.env.GEMINI_API_KEY!; try { const llmService = new LLMService(apiKey); const categorization = await llmService.categorizeBookmark({ bookmark, userCategories, }); return { ok: categorization }; } catch (error) { return { error: `${error}` }; } } export const getConfig = async () => { return { render: "dynamic", } as const; };