Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ebd1c76
feat: add ai sdk
nainglinnkhant Jan 27, 2026
9e03daf
fix: update gitignore file
nainglinnkhant Jan 27, 2026
915a436
style: use space indent for code formatting
nainglinnkhant Jan 27, 2026
33338f8
refactor: simplify constants to union types
nainglinnkhant Jan 27, 2026
2449616
refactor: add adjustments
nainglinnkhant Jan 28, 2026
218638b
refactor: add discriminated union types for file metadata
nainglinnkhant Jan 28, 2026
4346c7d
refactor: simplify UI codebase and fix chat history loading
nainglinnkhant Jan 28, 2026
a469360
fix: restore autoscroll during message streaming
nainglinnkhant Jan 28, 2026
e2f9d59
refactor: rename files to kebab-case and use named exports
nainglinnkhant Jan 28, 2026
746441b
refactor: standardize error handling and action naming across UI
nainglinnkhant Jan 29, 2026
5cc0067
refactor: migrate notes to URL-based routing
nainglinnkhant Jan 29, 2026
eb349ff
refactor: persist chat history panel across routes via layout
nainglinnkhant Jan 29, 2026
546178f
refactor: use AI SDK's useChat directly and render message parts nati…
nainglinnkhant Jan 30, 2026
7bf37dd
refactor: remove dead code and deduplicate shared logic across UI
nainglinnkhant Jan 30, 2026
444e427
chore: improve streaming config
nainglinnkhant Jan 30, 2026
4606f73
refactor: improve image attachment + add cn utils
nainglinnkhant Jan 31, 2026
2bb9440
refactor: remove redundant comments and unused API client layer
nainglinnkhant Jan 31, 2026
2a5bde8
refactor: use React 19 useOptimistic for instant UI updates
nainglinnkhant Feb 2, 2026
89349cb
feat: sync todo filter and sort state to URL
nainglinnkhant Feb 2, 2026
692e711
refactor: scope disabled states to individual actions in files and todos
nainglinnkhant Feb 2, 2026
44a866f
feat: add URL-based routing for files browser
nainglinnkhant Feb 3, 2026
789d0e0
feat: add auto-focus to form inputs on non-mobile screens
nainglinnkhant Feb 3, 2026
7608a66
chore: remove barrel files and update imports
nainglinnkhant Feb 3, 2026
566d81a
style: format code
nainglinnkhant Feb 3, 2026
816d888
feat: add loading pages
nainglinnkhant Feb 3, 2026
bd21206
feat: persist files toolbar during navigation
nainglinnkhant Feb 3, 2026
c5ac978
fix: improve accessibility and web interface guidelines compliance
nainglinnkhant Feb 6, 2026
2cdc65e
chore: minor optimizations and improvements
nainglinnkhant Feb 6, 2026
130ddd2
chore: format code + restructure file
nainglinnkhant Feb 6, 2026
ecc12e1
refactor: extract schemas and deduplicate across ui/
nainglinnkhant Feb 6, 2026
8d30350
fix: address PR review comments
nainglinnkhant Feb 6, 2026
eff6526
feat: upgrade chat model, encrypt google tokens, and harden tool erro…
nainglinnkhant Feb 20, 2026
fb0b096
fix: resolve comment
nainglinnkhant Feb 20, 2026
c3c1cd4
feat: improve chat image handling and add loading states
nainglinnkhant Feb 21, 2026
5ccdc47
fix: resolve comment
nainglinnkhant Feb 21, 2026
bba2f1d
fix: resolve image URLs at render layer to prevent corruption on re-save
nainglinnkhant Feb 22, 2026
11a8a83
fix: add path validation, prevent folder deletion over-matching, and …
nainglinnkhant Feb 22, 2026
601c8a8
revert: remove unintended notes.ts change
nainglinnkhant Feb 22, 2026
176d98d
fix: revalidate chat history after creation and title generation
nainglinnkhant Feb 22, 2026
5d93d81
fix: prevent pending message from being consumed by wrong chat
nainglinnkhant Feb 22, 2026
6750c2d
fix: resolve image URLs at render layer to prevent corruption on re-save
nainglinnkhant Feb 22, 2026
4e64da6
fix: omit empty text part from pending message in new chat flow
nainglinnkhant Feb 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ wheels/
# Virtual environments
.venv
slack_stuff/
data/
secret/
.env
.bernd_history
Expand Down
27 changes: 27 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"biome.lsp.bin": "./ui/node_modules/@biomejs/biome/bin/biome",
"biome.configurationPath": "./ui/biome.json",
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[jsonc]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"editor.codeActionsOnSave": {
"source.fixAll.biome": "explicit"
},
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"typescript.tsdk": "ui/node_modules/typescript/lib",
"prettier.enable": false
}
21 changes: 21 additions & 0 deletions ui/actions/chats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use server";

import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { PATHS } from "@/lib/constants";
import { getFS } from "@/lib/context";

export async function deleteChatAction(id: string, isActive?: boolean) {
const fs = await getFS();

await Promise.all([
fs.delete(`${PATHS.CHATS}/${id}.json`),
fs.clearPrefix(`${PATHS.CHAT_ASSETS}/${id}/`),
]);

revalidatePath("/chat");

if (isActive) {
redirect("/chat");
}
}
203 changes: 203 additions & 0 deletions ui/actions/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
"use server";

import { revalidatePath } from "next/cache";
import { PATHS } from "@/lib/constants";
import { getFS } from "@/lib/context";
import type { FileItem } from "@/types";
import {
type FileUploadMetadata,
type FolderMarkerMetadata,
isFileUploadMetadata,
} from "@/types";

export async function listFilesAction(path: string): Promise<FileItem[]> {
const fs = await getFS();
const files = await fs.list(path, 100);
const basePath = path.endsWith("/") ? path : `${path}/`;

const seen = new Set<string>();
const items: FileItem[] = [];

for (const file of files) {
const relativePath = file.path.replace(basePath, "").replace(/^\//, "");
const parts = relativePath.split("/");
const name = parts[0];
const isFolder = parts.length > 1;

// Skip folder marker files
if (name === "folder_meta.json") continue;

if (isFolder) {
if (seen.has(name)) continue;
seen.add(name);
items.push({
name,
path: `${path}/${name}`,
type: "folder",
});
} else {
const meta = file.metadata;
items.push({
name,
path: file.path,
type: "file",
size: isFileUploadMetadata(meta) ? meta.size : undefined,
mime_type: isFileUploadMetadata(meta) ? meta.mime_type : undefined,
created_at: meta.created_at ?? undefined,
});
}
}

items.sort((a, b) => {
if (a.type !== b.type) {
return a.type === "folder" ? -1 : 1;
}
return a.name.localeCompare(b.name);
});

return items;
}

export async function downloadFileAction(
path: string,
): Promise<{ content: string; mimeType: string }> {
if (!path.startsWith(PATHS.FILES)) {
throw new Error("Can only download files under /files/");
}
const fs = await getFS();
const result = await fs.read(path);

const meta = result.metadata;
return {
content: result.content,
mimeType: isFileUploadMetadata(meta) ? meta.mime_type : "text/plain",
};
}

export async function downloadBinaryFileAction(
path: string,
): Promise<{ data: number[]; mimeType: string }> {
if (!path.startsWith(PATHS.FILES)) {
throw new Error("Can only download files under /files/");
}
const fs = await getFS();
const result = await fs.readBinary(path);

// Convert ArrayBuffer to array of numbers for serialization
const data = Array.from(new Uint8Array(result.data));

const meta = result.metadata;
return {
data,
mimeType: isFileUploadMetadata(meta)
? meta.mime_type
: "application/octet-stream",
};
}

export async function uploadFileAction(
path: string,
content: string,
metadata?: Record<string, unknown>,
) {
const fs = await getFS();

// Ensure path starts with /files/
const fullPath = path.startsWith(PATHS.FILES)
? path
: `${PATHS.FILES}${path}`;
const filename = fullPath.split("/").pop() ?? "unnamed";

const fileMetadata: Omit<
FileUploadMetadata,
"path" | "created_at" | "updated_at"
> = {
type: "file",
mime_type: (metadata?.mime_type as string) ?? "text/plain",
size: (metadata?.size as number) ?? content.length,
is_base64: false,
original_name: (metadata?.original_name as string) ?? filename,
};
await fs.write(fullPath, content, fileMetadata);

revalidatePath("/files");
}

export async function uploadBinaryFileAction(
path: string,
data: ArrayBuffer,
mimeType: string,
metadata?: Record<string, unknown>,
) {
const fs = await getFS();

// Ensure path starts with /files/
const fullPath = path.startsWith(PATHS.FILES)
? path
: `${PATHS.FILES}${path}`;
const filename = fullPath.split("/").pop() ?? "unnamed";

const fileMetadata: Omit<
FileUploadMetadata,
"path" | "created_at" | "updated_at"
> = {
type: "file",
mime_type: mimeType,
size: (metadata?.size as number) ?? data.byteLength,
is_base64: true,
original_name: (metadata?.original_name as string) ?? filename,
};
await fs.writeBinary(fullPath, data, mimeType, fileMetadata);

revalidatePath("/files");
}

export async function createFolderAction(path: string) {
const fs = await getFS();

// Ensure path starts with /files/
const fullPath = path.startsWith(PATHS.FILES)
? path
: `${PATHS.FILES}${path}`;
const folderName = fullPath.split("/").pop() ?? "folder";
const createdAt = new Date().toISOString();

const content = JSON.stringify({
type: "folder",
name: folderName,
created_at: createdAt,
});

const folderMetadata: Omit<
FolderMarkerMetadata,
"path" | "created_at" | "updated_at"
> = {
type: "folder_marker",
};
await fs.write(`${fullPath}/folder_meta.json`, content, folderMetadata);

revalidatePath("/files");
}

export async function deleteFileAction(path: string) {
if (!path.startsWith(PATHS.FILES)) {
throw new Error("Can only delete files under /files/");
}
const fs = await getFS();

await fs.delete(path);

revalidatePath("/files");
}

export async function deleteFolderAction(path: string) {
if (!path.startsWith(PATHS.FILES)) {
throw new Error("Can only delete folders under /files/");
}
const fs = await getFS();

const prefix = path.endsWith("/") ? path : `${path}/`;
await fs.clearPrefix(prefix);

revalidatePath("/files");
}
52 changes: 52 additions & 0 deletions ui/actions/google-auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"use server";

import { revalidatePath } from "next/cache";
import { PATHS } from "@/lib/constants";
import { getFS } from "@/lib/context";
import { encrypt } from "@/lib/crypto";

export async function getGoogleStatusAction(): Promise<{
connected: boolean;
connected_at?: string;
}> {
try {
const fs = await getFS();
const result = await fs.read(PATHS.GOOGLE_AUTH);
const tokens = JSON.parse(result.content);
const connected = !!(tokens?.access_token && tokens?.refresh_token);
return {
connected,
connected_at: connected ? result.metadata.created_at : undefined,
};
} catch {
return { connected: false };
}
}

export async function disconnectGoogleAction() {
const fs = await getFS();

await fs.delete(PATHS.GOOGLE_AUTH);

revalidatePath("/settings");
}

export async function saveGoogleTokensAction(tokens: {
access_token: string;
refresh_token: string;
expiry?: string;
}) {
const fs = await getFS();

const encryptedTokens = {
...tokens,
access_token: encrypt(tokens.access_token),
refresh_token: encrypt(tokens.refresh_token),
};

await fs.write(PATHS.GOOGLE_AUTH, JSON.stringify(encryptedTokens, null, 2), {
type: "auth",
});

revalidatePath("/settings");
}
51 changes: 51 additions & 0 deletions ui/actions/notes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use server";

import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { PATHS } from "@/lib/constants";
import { getFS } from "@/lib/context";
import { generateTimestamp } from "@/lib/utils";
import type { NoteCreate, NoteMetadata, NoteUpdate } from "@/types";

function generateNoteId(): string {
const ts = generateTimestamp();
return `${ts.slice(0, 8)}_${ts.slice(8)}`;
}

export async function createNoteAction(data: NoteCreate) {
const fs = await getFS();

const noteId = generateNoteId();
const content = data.content || " ";

const metadata: Omit<NoteMetadata, "path" | "created_at" | "updated_at"> = {
type: "note",
title: data.title,
};
await fs.write(`${PATHS.NOTES}/${noteId}.md`, content, metadata);

revalidatePath("/notes");
redirect(`/notes/${noteId}`);
}

export async function updateNoteAction(id: string, data: NoteUpdate) {
const fs = await getFS();

const content = data.content || " ";

const metadata: Omit<NoteMetadata, "path" | "created_at" | "updated_at"> = {
type: "note",
title: data.title ?? "",
};
await fs.write(`${PATHS.NOTES}/${id}.md`, content, metadata);

revalidatePath("/notes");
}

export async function deleteNoteAction(id: string) {
const fs = await getFS();

await fs.delete(`${PATHS.NOTES}/${id}.md`);

revalidatePath("/notes");
}
16 changes: 16 additions & 0 deletions ui/actions/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use server";

import { getFS } from "@/lib/context";
import { type SearchAllResult, searchAll } from "@/lib/data/search";

export async function searchAction(
query: string,
topK = 20,
): Promise<SearchAllResult[]> {
if (!query.trim()) {
return [];
}

const fs = await getFS();
return searchAll(fs, query, topK);
}
Loading