7// but in the meantime, we can cache user info in memory
8const userIdCache: { [key: string]: any } = {};
9export async function getUser(bearerToken: string) {
10 if (userIdCache[bearerToken]) return userIdCache[bearerToken];
11
16}
17
18async function last24Hours(userId: string) {
19 const usage = await sqlite.execute(
20 `SELECT
40 "devto": 100, // hardcoded limit of $100 per day for dev.to, billed later
41};
42export async function overLimit(bearerToken: string) {
43 const user = await getUser(bearerToken);
44 const last24HourUsage = await last24Hours(user.id);
49}
50
51export async function insertInferenceCall({
52 usage_id,
53 input_tokens,
103}
104
105export async function startTrackingUsage({
106 bearerToken,
107 val_id,
145}
146
147export async function finishTrackingUsage({
148 rowid,
149 input_tokens,
4import { Loading } from "./Loading.tsx";
5
6export function ProjectsRoute () {
7 const projects = useProjects();
8
41}
42
43function ProjectCard ({
44 user,
45 project,
80}
81
82function Privacy ({ privacy }: {
83 privacy: "public"|"unlisted"|"private";
84}) {
10}
11
12export function Preview({ projectFiles, messages, running }: PreviewProps) {
13 const [selectedEndpointIndex, setSelectedEndpointIndex] = useState<number>(0);
14 const [customPath, setCustomPath] = useState<string>("/");
9}
10
11export function PreviewFrame(props: PreviewProps) {
12 const previewKey = useRef<string>("new-chat");
13 const [count, setCount] = useState<number>(0);
73const TSRE = /\/$/;
74
75function URLInput({ url, pathname, setPathname }) {
76 const prefix = url.replace(TSRE, "");
77 return (
90}
91
92function PreviewSelect({ index, setIndex, files }) {
93 return (
94 <div>
116}
117
118function usePreviewURL({ files }) {
119 const [index, setIndex] = useState<number>(0);
120 const htmlVals = files?.filter(file => file.links?.endpoint !== undefined);
21 * Parse pagination parameters from URL
22 */
23export function getPaginationParams(url: URL): { page: number; pageSize: number } {
24 const page = parseInt(url.searchParams.get("page") || "1", 10);
25 const pageSize = parseInt(url.searchParams.get("pageSize") || "50", 10);
35 * Calculate pagination metadata
36 */
37export function calculatePagination(params: PaginationParams): PaginationResult {
38 const totalPages = Math.ceil(params.totalItems / params.pageSize);
39
51 * Generate SQL LIMIT and OFFSET clauses for pagination
52 */
53export function getPaginationSQL(page: number, pageSize: number): string {
54 const offset = (page - 1) * pageSize;
55 return `LIMIT ${pageSize} OFFSET ${offset}`;
59 * Generate HTML for pagination controls
60 */
61export function renderPaginationControls(pagination: PaginationResult, baseUrl: string): string {
62 const url = new URL(baseUrl);
63
64 // Function to generate page URL
65 const getPageUrl = (page: number) => {
66 url.searchParams.set("page", page.toString());
1/** @jsxImportSource https://esm.sh/react@18.2.0?dev */
2
3export function NotFoundRoute () {
4 return (
5 <div className="container">Page not found</div>
4import { useCreateProject } from "../hooks/useCreateProject.tsx";
5
6export function NewProjectRoute () {
7 const [name, setName] = useState("");
8 const [privacy, setPrivacy] = useState("public");
65]
66
67function PrivacyRadios ({
68 value,
69 onChange,
14};
15
16export function Messages ({
17 messages,
18 messageEndTimes,
40}
41
42function Message ({
43 message,
44 messageEndTimes,
60}
61
62function AssistantMessage ({ message, messageEndTimes, running }: {
63 message: Message;
64 messageEndTimes: Record<string, number>;
85}
86
87function Part ({ part }) {
88 switch (part.type) {
89 case "text":
100}
101
102function TextPart ({ part }) {
103 return (
104 <ReactMarkdown>
108}
109
110function ToolPart ({ part }) {
111 const {
112 toolName,
167}
168
169function EditorToolPart ({ part }) {
170 const {
171 toolName,
233}
234
235function UserMessage ({ message }: {
236 message: Message;
237}) {
4import { useAuth } from "../hooks/useAuth.tsx";
5
6export function LoginRoute() {
7 const navigate = useNavigate();
8 const { isAuthenticated, authenticate, error } = useAuth();
1/** @jsxImportSource https://esm.sh/react@18.2.0?dev */
2
3export function Loading () {
4 return (
5 <div className="muted">