-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Integrate ai sdk #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nainglinnkhant
wants to merge
42
commits into
main
Choose a base branch
from
integrate-ai-sdk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 9e03daf
fix: update gitignore file
nainglinnkhant 915a436
style: use space indent for code formatting
nainglinnkhant 33338f8
refactor: simplify constants to union types
nainglinnkhant 2449616
refactor: add adjustments
nainglinnkhant 218638b
refactor: add discriminated union types for file metadata
nainglinnkhant 4346c7d
refactor: simplify UI codebase and fix chat history loading
nainglinnkhant a469360
fix: restore autoscroll during message streaming
nainglinnkhant e2f9d59
refactor: rename files to kebab-case and use named exports
nainglinnkhant 746441b
refactor: standardize error handling and action naming across UI
nainglinnkhant 5cc0067
refactor: migrate notes to URL-based routing
nainglinnkhant eb349ff
refactor: persist chat history panel across routes via layout
nainglinnkhant 546178f
refactor: use AI SDK's useChat directly and render message parts nati…
nainglinnkhant 7bf37dd
refactor: remove dead code and deduplicate shared logic across UI
nainglinnkhant 444e427
chore: improve streaming config
nainglinnkhant 4606f73
refactor: improve image attachment + add cn utils
nainglinnkhant 2bb9440
refactor: remove redundant comments and unused API client layer
nainglinnkhant 2a5bde8
refactor: use React 19 useOptimistic for instant UI updates
nainglinnkhant 89349cb
feat: sync todo filter and sort state to URL
nainglinnkhant 692e711
refactor: scope disabled states to individual actions in files and todos
nainglinnkhant 44a866f
feat: add URL-based routing for files browser
nainglinnkhant 789d0e0
feat: add auto-focus to form inputs on non-mobile screens
nainglinnkhant 7608a66
chore: remove barrel files and update imports
nainglinnkhant 566d81a
style: format code
nainglinnkhant 816d888
feat: add loading pages
nainglinnkhant bd21206
feat: persist files toolbar during navigation
nainglinnkhant c5ac978
fix: improve accessibility and web interface guidelines compliance
nainglinnkhant 2cdc65e
chore: minor optimizations and improvements
nainglinnkhant 130ddd2
chore: format code + restructure file
nainglinnkhant ecc12e1
refactor: extract schemas and deduplicate across ui/
nainglinnkhant 8d30350
fix: address PR review comments
nainglinnkhant eff6526
feat: upgrade chat model, encrypt google tokens, and harden tool erro…
nainglinnkhant fb0b096
fix: resolve comment
nainglinnkhant c3c1cd4
feat: improve chat image handling and add loading states
nainglinnkhant 5ccdc47
fix: resolve comment
nainglinnkhant bba2f1d
fix: resolve image URLs at render layer to prevent corruption on re-save
nainglinnkhant 11a8a83
fix: add path validation, prevent folder deletion over-matching, and …
nainglinnkhant 601c8a8
revert: remove unintended notes.ts change
nainglinnkhant 176d98d
fix: revalidate chat history after creation and title generation
nainglinnkhant 5d93d81
fix: prevent pending message from being consumed by wrong chat
nainglinnkhant 6750c2d
fix: resolve image URLs at render layer to prevent corruption on re-save
nainglinnkhant 4e64da6
fix: omit empty text part from pending message in new chat flow
nainglinnkhant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ wheels/ | |
| # Virtual environments | ||
| .venv | ||
| slack_stuff/ | ||
| data/ | ||
| secret/ | ||
| .env | ||
| .bernd_history | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
| } | ||
| } | ||
nainglinnkhant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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", | ||
| }; | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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"); | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export async function deleteNoteAction(id: string) { | ||
| const fs = await getFS(); | ||
|
|
||
| await fs.delete(`${PATHS.NOTES}/${id}.md`); | ||
|
|
||
| revalidatePath("/notes"); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.