-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: server actions search with supabase text search #218
Conversation
WalkthroughThe updates to the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
@coderabbitai review |
Actions PerformedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 13
Out of diff range and nitpick comments (12)
apps/masterbots.ai/hooks/use-chatbot.tsx (1)
Line range hint
7-12
: Ensure proper handling of undefined chatbot.Add a check to handle cases where the chatbot is not found to avoid potential runtime errors.
- const initialMessages = chatbot?.prompts?.map(prompt => ({ - id: prompt.promptId.toString(), - role: 'system' as const, - content: prompt.content, - createdAt: new Date() - })) + const initialMessages = chatbot?.prompts?.map(prompt => ({ + id: prompt.promptId.toString(), + role: 'system' as const, + content: prompt.content, + createdAt: new Date() + })) || [];apps/supabase/src/mb.types.ts (1)
6-6
: Consider creating a GitHub issue to track the TODO for moving the types topackages/mb-types
.apps/masterbots.ai/app/(browse)/[category]/page.tsx (3)
4-6
: Ensure all imports are necessary and used.Consider removing unused imports to keep the code clean and maintainable.
17-22
: Remove commented-out code.Commented-out code can clutter the codebase. If these lines are no longer needed, consider removing them.
41-41
: Remove commented-out code.Commented-out code can clutter the codebase. If these lines are no longer needed, consider removing them.
apps/masterbots.ai/components/shared/thread-list-accordion.tsx (2)
12-12
: Ensure all imports are necessary and used.Consider removing unused imports to keep the code clean and maintainable.
22-22
: Remove commented-out code.Commented-out code can clutter the codebase. If these lines are no longer needed, consider removing them.
apps/masterbots.ai/components/shared/search-input.tsx (2)
3-8
: Ensure all imports are necessary and used.Consider removing unused imports to keep the code clean and maintainable.
23-23
: Removeconsole.log
statement.
console.log
statements should be removed in production code to avoid unnecessary logging.apps/masterbots.ai/components/shared/thread-message.tsx (1)
8-8
: Ensure all imports are necessary and used.Consider removing unused imports to keep the code clean and maintainable.
apps/masterbots.ai/services/supabase/middleware.ts (1)
1-1
: Ensure all imports are necessary and used.Consider removing unused imports to keep the code clean and maintainable.
apps/masterbots.ai/app/settings/layout.tsx (1)
Line range hint
1-1
: Ensure all imports are necessary and used.Consider removing unused imports to keep the code clean and maintainable.
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
bun.lockb
is excluded by!bun.lockb
Files selected for processing (51)
- apps/masterbots.ai/.env.example (1 hunks)
- apps/masterbots.ai/.env.local (1 hunks)
- apps/masterbots.ai/app/(browse)/[category]/[threadId]/page.tsx (1 hunks)
- apps/masterbots.ai/app/(browse)/[category]/page.tsx (3 hunks)
- apps/masterbots.ai/app/(browse)/page.tsx (1 hunks)
- apps/masterbots.ai/app/actions.ts (1 hunks)
- apps/masterbots.ai/app/auth/callback/route.ts (2 hunks)
- apps/masterbots.ai/app/b/[id]/page.tsx (1 hunks)
- apps/masterbots.ai/app/layout.tsx (4 hunks)
- apps/masterbots.ai/app/og/route.tsx (3 hunks)
- apps/masterbots.ai/app/oss/layout.tsx (2 hunks)
- apps/masterbots.ai/app/settings/layout.tsx (3 hunks)
- apps/masterbots.ai/app/u/[username]/page.tsx (1 hunks)
- apps/masterbots.ai/components/layout/cmdk.tsx (4 hunks)
- apps/masterbots.ai/components/layout/header.tsx (1 hunks)
- apps/masterbots.ai/components/layout/providers.tsx (2 hunks)
- apps/masterbots.ai/components/shared/category-tabs/category-link.tsx (3 hunks)
- apps/masterbots.ai/components/shared/category-tabs/category-tabs.tsx (1 hunks)
- apps/masterbots.ai/components/shared/copy-shortlink.tsx (1 hunks)
- apps/masterbots.ai/components/shared/search-input.tsx (1 hunks)
- apps/masterbots.ai/components/shared/thread-accordion.tsx (6 hunks)
- apps/masterbots.ai/components/shared/thread-dialog.tsx (2 hunks)
- apps/masterbots.ai/components/shared/thread-heading.tsx (5 hunks)
- apps/masterbots.ai/components/shared/thread-list-accordion.tsx (4 hunks)
- apps/masterbots.ai/components/shared/thread-list-chat-item.tsx (2 hunks)
- apps/masterbots.ai/components/shared/thread-list.tsx (2 hunks)
- apps/masterbots.ai/components/shared/thread-message.tsx (2 hunks)
- apps/masterbots.ai/hooks/use-chatbot.tsx (1 hunks)
- apps/masterbots.ai/hooks/use-global-store.tsx (2 hunks)
- apps/masterbots.ai/lib/config.ts (1 hunks)
- apps/masterbots.ai/lib/metadata.ts (1 hunks)
- apps/masterbots.ai/lib/threads.ts (3 hunks)
- apps/masterbots.ai/package.json (2 hunks)
- apps/masterbots.ai/services/dub/index.ts (1 hunks)
- apps/masterbots.ai/services/supabase/client.ts (1 hunks)
- apps/masterbots.ai/services/supabase/middleware.ts (2 hunks)
- apps/masterbots.ai/services/supabase/server.ts (1 hunks)
- apps/supabase/migrations/20240422204025_remote_schema.sql (1 hunks)
- apps/supabase/migrations/20240422205728_remote_schema.sql (1 hunks)
- apps/supabase/package.json (1 hunks)
- apps/supabase/src/index.ts (1 hunks)
- apps/supabase/src/mb.types.ts (1 hunks)
- apps/supabase/src/supa.schemas.ts (1 hunks)
- apps/supabase/src/supa.types.ts (2 hunks)
- package.json (1 hunks)
- packages/mb-env/src/env.type.ts (1 hunks)
- packages/mb-env/src/index.ts (1 hunks)
- packages/mb-env/src/supabase.env.ts (1 hunks)
- packages/mb-lib/package.json (1 hunks)
- packages/mb-lib/src/index.ts (1 hunks)
- packages/mb-lib/src/platform/platform.ts (1 hunks)
Files skipped from review due to trivial changes (14)
- apps/masterbots.ai/.env.example
- apps/masterbots.ai/.env.local
- apps/masterbots.ai/app/oss/layout.tsx
- apps/masterbots.ai/components/layout/cmdk.tsx
- apps/masterbots.ai/components/layout/providers.tsx
- apps/masterbots.ai/package.json
- apps/supabase/src/index.ts
- package.json
- packages/mb-env/src/env.type.ts
- packages/mb-env/src/index.ts
- packages/mb-env/src/supabase.env.ts
- packages/mb-lib/package.json
- packages/mb-lib/src/index.ts
- packages/mb-lib/src/platform/platform.ts
Additional comments not posted (72)
apps/masterbots.ai/lib/config.ts (1)
5-8
: LGTM! The configuration object is correctly structured.apps/supabase/migrations/20240422205728_remote_schema.sql (2)
1-1
: Ensure the impact of dropping the unique constraint.Dropping the unique constraint on the
slug
column might affect data integrity. Verify that this change won't introduce duplicate slugs in theuser
table.
9-9
: LGTM! Adding theavatar
column is straightforward.apps/masterbots.ai/services/supabase/client.ts (2)
4-4
: Ensure the configuration object is correctly imported.Verify that the
appConfig
object from@/lib/config
contains the correct Supabase URL and key values.
8-9
: LGTM! The Supabase client is correctly configured.apps/masterbots.ai/hooks/use-chatbot.tsx (1)
Line range hint
7-12
: LGTM! The hook correctly maps initial messages.apps/supabase/package.json (2)
10-10
: Ensure the Supabase project ID is correct.Verify that the Supabase project ID
bypmbisnogyndsqcztay
is correct and matches the intended project.
16-16
: LGTM! The dependencycamelize-ts
is correctly added.apps/masterbots.ai/components/shared/category-tabs/category-tabs.tsx (1)
18-21
: LGTM! The component correctly maps categories to links.apps/masterbots.ai/components/shared/thread-list-chat-item.tsx (2)
5-5
: Import statement forMB
looks good.
16-17
: Changes inThreadListChatItem
component look good.Also applies to: 25-25
apps/masterbots.ai/services/supabase/server.ts (1)
Line range hint
6-18
: ThecreateSupabaseServerClient
function implementation looks good.apps/supabase/migrations/20240422204025_remote_schema.sql (1)
1-19
: The SQL commands for altering themessage
table look good.apps/masterbots.ai/app/(browse)/[category]/[threadId]/page.tsx (2)
8-12
: Verify if the commented-out async calls are intentional or if there is a plan to replace them.
16-21
: Verify if theThreadAccordion
component being commented out is intentional or if there is a plan to replace it.apps/masterbots.ai/app/b/[id]/page.tsx (2)
17-25
: Verify if theAccountDetails
component being commented out is intentional or if there is a plan to replace it.
15-27
: Updates to the components look good.apps/masterbots.ai/components/shared/category-tabs/category-link.tsx (1)
3-3
: LGTM! The import statement and usage oftoSlug
are correct.apps/supabase/src/mb.types.ts (1)
1-32
: LGTM! The type definitions are correct and follow the project's conventions.apps/masterbots.ai/hooks/use-global-store.tsx (1)
5-5
: LGTM! The import statement and usage ofMB
types are correct.apps/masterbots.ai/components/shared/thread-dialog.tsx (2)
9-9
: Import statement forMB
looks good.
46-46
: The update to useMB.ThreadFull
inThreadDialogProps
is appropriate.apps/masterbots.ai/app/(browse)/page.tsx (2)
5-5
: Import statement fordecodeQuery
looks good.
6-6
: Import statement forgetThreads
andgetThreadsLike
looks good.apps/masterbots.ai/components/layout/header.tsx (2)
7-11
: The logic for fetching user data using Supabase looks good.
24-27
: The conditional rendering ofUserMenu
or login button based on the user's authentication status is correctly implemented.apps/masterbots.ai/app/u/[username]/page.tsx (3)
1-7
: Import statements for various components and functions look good.
9-23
: ThegetUserWithThreads
function is well-implemented and handles data fetching and conversion appropriately.
25-43
: TheBotThreadsPage
function is well-implemented and correctly handles the rendering of page content based on user data.apps/masterbots.ai/components/shared/thread-heading.tsx (2)
6-6
: Import statement forMB
looks good.
60-60
: The update to useMB.ThreadFull
inThreadHeadingProps
is appropriate.apps/masterbots.ai/app/auth/callback/route.ts (2)
5-7
: Import statements for various functions and libraries look good.
27-39
: TheGET
function is well-implemented and correctly handles the auth code exchange, user data insertion, and cookie setting.apps/masterbots.ai/components/shared/search-input.tsx (1)
33-55
: LGTM!apps/masterbots.ai/components/shared/thread-message.tsx (1)
12-12
: LGTM!apps/masterbots.ai/services/supabase/middleware.ts (1)
17-18
: LGTM!apps/masterbots.ai/app/settings/layout.tsx (1)
Line range hint
28-63
: LGTM!apps/masterbots.ai/lib/threads.ts (4)
35-42
: LGTM!
Line range hint
45-53
: LGTM!
73-86
: LGTM!
91-101
: LGTM!apps/masterbots.ai/app/layout.tsx (3)
16-23
: LGTM!
Line range hint
30-65
: LGTM!
67-74
: LGTM!apps/masterbots.ai/app/og/route.tsx (1)
Line range hint
9-75
: LGTM!apps/masterbots.ai/app/actions.ts (4)
21-34
: LGTM!
37-46
: LGTM!
64-97
: LGTM!
99-131
: LGTM!apps/supabase/src/supa.schemas.ts (10)
5-15
: LGTM!
17-20
: LGTM!
32-37
: LGTM!
53-63
: LGTM!
89-92
: LGTM!
128-134
: LGTM!
164-173
: LGTM!
197-201
: LGTM!
260-267
: LGTM!
311-320
: LGTM!apps/supabase/src/supa.types.ts (13)
186-186
: Ensureid
field is correctly typed asstring
.
193-193
: Ensureid
field is correctly typed asstring
and is optional inInsert
type.
200-200
: Ensureid
field is correctly typed asstring
and is optional inUpdate
type.
193-193
: Ensurerole
field is correctly typed asstring
.
200-200
: Ensurerole
field is correctly typed asstring
.
478-478
: Ensureavatar
field is correctly typed asstring | null
.
482-482
: Ensurename
field is correctly typed asstring | null
.
488-488
: Ensureavatar
field is correctly typed asstring | null
and is optional inInsert
type.
492-492
: Ensurename
field is correctly typed asstring | null
and is optional inInsert
type.
498-498
: Ensureavatar
field is correctly typed asstring | null
and is optional inUpdate
type.
502-502
: Ensurename
field is correctly typed asstring | null
and is optional inUpdate
type.
Line range hint
526-526
: EnsurePublicTableNameOrOptions
andTableName
generic parameters are correctly typed.
Line range hint
546-546
: EnsurePublicTableNameOrOptions
andTableName
generic parameters are correctly typed.
export async function shorten(_prevState: any, formData: any) { | ||
try { | ||
const url = formData.get('url') | ||
// Validate form data | ||
if (!url || typeof url !== 'string') { | ||
return { | ||
shortLink: 'Invalid URL' | ||
} | ||
} | ||
|
||
const resp = await dub.links.create({ | ||
url, | ||
domain: 'mbots.to' | ||
}) | ||
|
||
console.log('🤌🏻 dub response', resp) | ||
return { | ||
shortLink: '' | ||
} | ||
} catch (error) { | ||
console.log('ERROR', error) | ||
|
||
return { | ||
shortLink: 'Invalid data provided' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the return value for a successful response in the shorten
function.
- return {
- shortLink: ''
- }
+ return {
+ shortLink: resp.shortLink
+ }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
export async function shorten(_prevState: any, formData: any) { | |
try { | |
const url = formData.get('url') | |
// Validate form data | |
if (!url || typeof url !== 'string') { | |
return { | |
shortLink: 'Invalid URL' | |
} | |
} | |
const resp = await dub.links.create({ | |
url, | |
domain: 'mbots.to' | |
}) | |
console.log('🤌🏻 dub response', resp) | |
return { | |
shortLink: '' | |
} | |
} catch (error) { | |
console.log('ERROR', error) | |
return { | |
shortLink: 'Invalid data provided' | |
} | |
export async function shorten(_prevState: any, formData: any) { | |
try { | |
const url = formData.get('url') | |
// Validate form data | |
if (!url || typeof url !== 'string') { | |
return { | |
shortLink: 'Invalid URL' | |
} | |
} | |
const resp = await dub.links.create({ | |
url, | |
domain: 'mbots.to' | |
}) | |
console.log('🤌🏻 dub response', resp) | |
return { | |
shortLink: resp.shortLink | |
} | |
} catch (error) { | |
console.log('ERROR', error) | |
return { | |
shortLink: 'Invalid data provided' | |
} |
import { useAsyncFn } from 'react-use' | ||
import { cn } from '@/lib/utils' | ||
import { shorten } from '@/services/dub' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for the asynchronous operation.
- const { shortLink } = await shorten({}, formData)
+ const { shortLink } = await shorten({}, formData).catch(error => {
+ console.error('Error shortening the URL:', error)
+ return { shortLink: '' }
+ })
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
import { shorten } from '@/services/dub' | |
import { shorten } from '@/services/dub' | |
const { shortLink } = await shorten({}, formData).catch(error => { | |
console.error('Error shortening the URL:', error) | |
return { shortLink: '' } | |
}) |
@@ -0,0 +1,8 @@ | |||
import { validateMbEnv, supabase } from '@repo/mb-env' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure proper error handling for environment validation.
Consider adding error handling for the validateMbEnv
function to manage invalid environment values gracefully.
- const env = validateMbEnv(process.env.NEXT_PUBLIC_APP_ENV || 'test')
+ let env;
+ try {
+ env = validateMbEnv(process.env.NEXT_PUBLIC_APP_ENV || 'test');
+ } catch (error) {
+ console.error('Invalid environment configuration:', error);
+ env = 'test'; // Fallback to a default environment
+ }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
import { validateMbEnv, supabase } from '@repo/mb-env' | |
import { validateMbEnv, supabase } from '@repo/mb-env' | |
let env; | |
try { | |
env = validateMbEnv(process.env.NEXT_PUBLIC_APP_ENV || 'test'); | |
} catch (error) { | |
console.error('Invalid environment configuration:', error); | |
env = 'test'; // Fallback to a default environment | |
} |
threads.map((thread: Thread) => ( | ||
<div className="flex flex-col w-full gap-8 py-5"> | ||
{!initialThreads.length ? ( | ||
<div>No threads founds</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the typo in the "No threads found" message.
- <div>No threads founds</div>
+ <div>No threads found</div>
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
<div>No threads founds</div> | |
<div>No threads found</div> |
}): Promise<Metadata | undefined> { | ||
const thread = await getThread({threadId: params.threadId}) | ||
const thread = await getThread({ threadId: params.threadId }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for the asynchronous operation.
- const thread = await getThread({ threadId: params.threadId })
+ const thread = await getThread({ threadId: params.threadId }).catch(error => {
+ console.error('Error fetching the thread:', error)
+ return null
+ })
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
const thread = await getThread({ threadId: params.threadId }) | |
const thread = await getThread({ threadId: params.threadId }).catch(error => { | |
console.error('Error fetching the thread:', error) | |
return null | |
}) |
query | ||
}) | ||
|
||
console.log(' ============== THREADS ============== ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider removing the console.log
statement for production code.
- console.log(' ============== THREADS ============== ')
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
console.log(' ============== THREADS ============== ') |
// messagePairs.push({ | ||
// userMessage, | ||
// chatGptMessage: [] //chatGptMessages | ||
// }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented-out code or uncomment and fix it.
Commented-out code can lead to confusion and should be either removed or uncommented and fixed.
}) { | ||
return chat | ||
? `/c/${toSlug(thread.chatbot.name)}/${thread.threadId}` | ||
: `/${toSlug(thread.chatbot.categories[0]?.category.name)}/${thread.threadId}}` | ||
: `/${toSlug(thread.chatbot.categories[0].name)}/${thread.threadId}}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the typo in the URL generation.
- : `/${toSlug(thread.chatbot.categories[0].name)}/${thread.threadId}}`
+ : `/${toSlug(thread.chatbot.categories[0].name)}/${thread.threadId}`
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
: `/${toSlug(thread.chatbot.categories[0].name)}/${thread.threadId}}` | |
: `/${toSlug(thread.chatbot.categories[0].name)}/${thread.threadId}` |
{/* {p.chatGptMessage.map(message => ( | ||
<BrowseChatMessage | ||
chatbot={thread.chatbot} | ||
key={`message-${message.messageId}`} | ||
message={convertMessage(message)} | ||
/> | ||
))} | ||
))} */} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented-out code or uncomment and fix it.
Commented-out code can lead to confusion and should be either removed or uncommented and fixed.
export async function getMessagePairs(threadId: string) { | ||
console.log('get message pairs for', threadId) | ||
return [] as MB.MessagePair[] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement the getMessagePairs
function or remove it if not needed.
Placeholder functions should be implemented or removed to avoid confusion.
Summary by CodeRabbit
New Features
Bug Fixes
SearchInput
to update on change instead of form submission.Refactor
Chores
Style
OssLayout
for improved styling consistency.