Skip to content
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 #217

Closed
wants to merge 9 commits into from

Conversation

gaboesquivel
Copy link
Member

@gaboesquivel gaboesquivel commented May 15, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new environment variable DUB_API_KEY for enhanced API integrations.
    • Added a new BotThreadsPage for displaying user-specific threads.
  • Bug Fixes

    • Improved URL update performance in the SearchInput component with debouncing.
    • Fixed issues with thread and message retrieval in various components.
  • Refactor

    • Updated various components to use new data fetching methods and type definitions.
    • Removed and replaced several import statements for better code maintainability.
  • Chores

    • Updated environment configurations and removed unused imports across multiple files.
  • Style

    • Adjusted class names and styling in thread-heading.tsx and settings/layout.tsx.
  • Documentation

    • Added type definitions and Zod schemas for various entities in the supabase directory.

Copy link

vercel bot commented May 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
masterbots ❌ Failed (Inspect) May 15, 2024 5:24pm

Copy link
Contributor

coderabbitai bot commented May 15, 2024

Walkthrough

This update primarily refactors the apps/masterbots.ai application by modifying environment configurations, optimizing thread and category fetching mechanisms, and enhancing data handling through Supabase. It also introduces new utility functions, updates component imports, and adjusts type definitions to streamline data processing and improve performance.

Changes

File Path Change Summary
apps/masterbots.ai/.env.example Updated .env.example to include a new value for DUB_API_KEY.
apps/masterbots.ai/.env.local Changed the value of NEXT_PUBLIC_APP_ENV from test to search.
apps/masterbots.ai/app/(browse)/[category]/[threadId]/page.tsx Commented out category and thread retrieval, passing empty arrays to components.
apps/masterbots.ai/app/(browse)/[category]/page.tsx Updated import statements, fetching logic, and component props for threads and categories.
apps/masterbots.ai/app/(browse)/page.tsx Refactored to use different thread fetching functions, removed getCategories, added logging.
apps/masterbots.ai/app/actions.ts Introduced new functions for fetching and processing threads and messages using Supabase.
apps/masterbots.ai/app/auth/callback/route.ts Replaced user authentication and data insertion functions, updated cookie handling.
apps/masterbots.ai/app/b/[id]/page.tsx Updated import statements, removed API calls, and adjusted component props.
apps/masterbots.ai/app/layout.tsx Removed hasuraJwt from getCookieData, replaced getChatbots with getGlobalData.
apps/masterbots.ai/app/og/route.tsx Modified import statement for getThread, adjusted GET function logic.
apps/masterbots.ai/app/oss/layout.tsx Removed various imports and reordered CSS classes in OssLayout function.
apps/masterbots.ai/app/settings/layout.tsx Removed imports for getBrowseThreads and getUserInfoFromBrowse, adjusted layout styling.
apps/masterbots.ai/app/u/[username]/page.tsx Introduced BotThreadsPage function for fetching and displaying user data and threads.
apps/masterbots.ai/components/layout/cmdk.tsx Removed dependencies and logic related to chat threads and chatbot services.
apps/masterbots.ai/components/layout/header.tsx Removed usage of isTokenExpired, cookies, and SidebarToggle component.
apps/masterbots.ai/components/layout/providers.tsx Removed SidebarProvider from component hierarchy in Providers function.
apps/masterbots.ai/components/shared/category-tabs/category-link.tsx Updated category prop type to string and adjusted toSlug function usage.
apps/masterbots.ai/components/shared/category-tabs/category-tabs.tsx Updated imports and modified category parameter to a string in CategoryTabs function.
apps/masterbots.ai/components/shared/copy-shortlink.tsx Updated import statement for shorten function.
apps/masterbots.ai/components/shared/search-input.tsx Refactored to use useSearchParams and debounced URL updates.
apps/masterbots.ai/components/shared/thread-accordion.tsx Updated imports and modified ThreadAccordionProps interface structure.
apps/masterbots.ai/components/shared/thread-dialog.tsx Directly accessed messages from thread object, replaced ThreadAccordion with placeholder.
apps/masterbots.ai/components/shared/thread-heading.tsx Updated imports, adjusted class names, and modified thread parameter type.
apps/masterbots.ai/components/shared/thread-list-chat-item.tsx Directly accessed messages from thread object, updated thread type.
apps/masterbots.ai/components/shared/thread-list.tsx Refactored data fetching mechanism, adjusted ThreadListProps interface.
apps/supabase/src/mb.types.ts Introduced type definitions for various entities related to messaging and chatbots.
apps/supabase/src/supa.schemas.ts Introduced Zod schemas for various data entities.
package.json Updated dependencies and scripts as necessary.

In the code where bots reside,
Threads and data now abide.
Supabase lends a helping hand,
Making queries swift and grand.
Categories and threads align,
In a structure so divine.
Here's to changes, big and small,
For a smoother app for all! 🐰✨


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gaboesquivel gaboesquivel marked this pull request as ready for review May 15, 2024 17:24
@gaboesquivel
Copy link
Member Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented May 15, 2024

Actions Performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@gaboesquivel gaboesquivel deleted the full-ssr-search-supabase branch May 15, 2024 17:35
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 15

Out of diff range and nitpick comments (13)
apps/masterbots.ai/services/supabase/middleware.ts (2)

1-1: Consider adding a comment to explain the purpose of the appConfig import for better code clarity.


Line range hint 35-42: The function findNextAssistantMessage could be simplified by directly returning the cleaned message if the role is 'assistant'.

const findNextAssistantMessage = (
  messages: AI.Message[],
  startIndex: number
) => {
  if (messages[startIndex].role === 'assistant') {
    return {
      ...messages[startIndex],
      content: cleanPrompt(messages[startIndex].content)
    } as AI.Message
  }
  return null
}
apps/masterbots.ai/lib/threads.ts (1)

Line range hint 47-54: Add a comment explaining the purpose of the cleanPrompt function for better code clarity.

+ // Extracts the part of the string after the specified marker.
export function cleanPrompt(str: string) {
  const marker = '].  Then answer this question:'
  const index = str.indexOf(marker)
  let extracted = ''

  if (index !== -1) {
    extracted = str.substring(index + marker.length)
  }
  // console.log('cleanPrompt', str, extracted, index)
  return extracted || str
}
apps/masterbots.ai/app/og/route.tsx (1)

Line range hint 7-16: Add error handling for the case where threadId is not provided or getThread fails to fetch the thread.

export async function GET(req: NextRequest) {
  try {
    const { searchParams } = req.nextUrl
    const threadId = searchParams.get('threadId')
    if (!threadId) {
      throw new Error('Missing threadId')
    }
    const thread = await getThread({ threadId })
    if (!thread) {
      throw new Error('Thread not found')
    }
apps/masterbots.ai/app/actions.ts (9)

29-29: Remove console.log statement.

Replace console.log('🤌🏻', count); with a proper logging mechanism or remove it before deploying to production.


44-44: Remove console.log statement.

Replace console.log('🤌🏻', error, count, data?.length); with a proper logging mechanism or remove it before deploying to production.


65-65: Remove console.log statement.

Replace console.log('🧑🏻‍💻 get threads like', query); with a proper logging mechanism or remove it before deploying to production.


81-81: Remove console.log statement.

Replace console.log('🙌🏻 threadIds', threadIds.length); with a proper logging mechanism or remove it before deploying to production.


92-92: Remove console.log statement.

Replace console.log('🤌🏻', error, count, data?.length); with a proper logging mechanism or remove it before deploying to production.


100-100: Remove console.log statement.

Replace console.log('🧑🏻‍💻 search threads for', query); with a proper logging mechanism or remove it before deploying to production.


113-113: Remove console.log statement.

Replace console.log(threadIds.data?.length, threadIds?.data); with a proper logging mechanism or remove it before deploying to production.


127-127: Remove console.log statement.

Replace console.log('🤌🏻', error, count, data?.length); with a proper logging mechanism or remove it before deploying to production.


135-135: Remove console.log statement.

Replace console.log('get message pairs for', threadId); with a proper logging mechanism or remove it before deploying to production.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between c5eeabf and d55903f.
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 (12)
  • apps/masterbots.ai/.env.example
  • apps/masterbots.ai/.env.local
  • apps/masterbots.ai/app/b/[id]/page.tsx
  • apps/masterbots.ai/app/settings/layout.tsx
  • apps/supabase/package.json
  • apps/supabase/src/index.ts
  • package.json
  • 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 (92)
apps/masterbots.ai/lib/config.ts (2)

1-1: Imports look good.


3-8: Environment validation and configuration setup look good.

apps/supabase/migrations/20240422205728_remote_schema.sql (3)

1-1: Dropping the unique constraint on the slug column might affect data integrity. Ensure this change is intentional and that the application logic accounts for non-unique slugs.


3-3: Dropping the index on the slug column might impact query performance. Ensure this change is intentional and that the application logic accounts for the potential performance impact.


5-9: Schema update commands look good. Ensure that the application logic is updated to reflect these changes.

packages/mb-env/src/env.type.ts (2)

1-1: Definition of valid environments looks good.


Line range hint 3-10: The validateMbEnv function looks good and correctly validates the environment.

apps/masterbots.ai/services/supabase/client.ts (3)

1-4: Imports look good.


6-9: The getSupabaseBrowserClient function looks good and correctly sets up the Supabase client for the browser.


Line range hint 11-13: The useSupabaseClient hook looks good and correctly memoizes the Supabase client.

apps/masterbots.ai/hooks/use-chatbot.tsx (2)

Line range hint 1-1: Import looks good.


Line range hint 3-14: The useChatbot hook looks good and correctly retrieves the chatbot data and initial messages.

apps/masterbots.ai/components/layout/providers.tsx (2)

Line range hint 3-10: Imports look good.


12-18: The Providers component looks good and correctly sets up the providers.

apps/masterbots.ai/components/shared/category-tabs/category-tabs.tsx (2)

3-3: Import statement looks good.


10-18: Changes to the CategoryTabs component look good.

apps/masterbots.ai/components/shared/thread-list-chat-item.tsx (2)

5-5: Import statement looks good.


16-25: Changes to the ThreadListChatItem component look good.

apps/masterbots.ai/services/dub/index.ts (1)

1-4: Import statement looks good.

apps/masterbots.ai/services/supabase/server.ts (2)

6-6: Import statement looks good.


Line range hint 12-23: Function implementation looks good.

apps/supabase/migrations/20240422204025_remote_schema.sql (1)

1-21: SQL commands look good.

apps/masterbots.ai/app/(browse)/[category]/[threadId]/page.tsx (1)

8-21: Verify if the commented-out code is intentional.

Is the commented-out data fetching logic intentional, or should it be removed or replaced with new logic?

apps/masterbots.ai/components/shared/copy-shortlink.tsx (1)

6-6: Ensure that the shorten function from @/services/dub is correctly implemented and handles errors appropriately.

Verification successful

The shorten function from @/services/dub is correctly implemented and handles errors appropriately.

  • The function validates the URL from the form data.
  • It attempts to create a short link using dub.links.create.
  • It handles errors by logging them and returning an appropriate message.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of the `shorten` function.

# Test: Search for the function implementation. Expect: Correct implementation with error handling.
rg --type ts --pattern 'export async function shorten'

Length of output: 468



Script:

#!/bin/bash
# Description: Verify the implementation of the `shorten` function.

# Test: Search for the function implementation. Expect: Correct implementation with error handling.
rg 'export async function shorten' --type ts

Length of output: 151



Script:

#!/bin/bash
# Description: Extract the full implementation of the `shorten` function.

# Test: Extract the function implementation. Expect: Full function code for review.
rg -A 20 'export async function shorten' apps/masterbots.ai/services/dub/index.ts

Length of output: 543



Script:

#!/bin/bash
# Description: Extract the full implementation of the `shorten` function.

# Test: Extract the function implementation. Expect: Full function code for review.
rg -A 40 'export async function shorten' apps/masterbots.ai/services/dub/index.ts

Length of output: 610

apps/masterbots.ai/components/shared/category-tabs/category-link.tsx (2)

3-3: Ensure that the toSlug function from @/lib/url-params is correctly implemented and handles edge cases appropriately.


9-9: The change in the category prop type to string | 'all' is appropriate and simplifies the component logic.

apps/masterbots.ai/components/shared/thread-list.tsx (2)

1-1: Ensure that the MB namespace from @repo/supabase is correctly implemented and includes the ThreadFull type.

Verification successful

Verification of MB Namespace and ThreadFull Type

The MB namespace is correctly implemented in apps/supabase/src/mb.types.ts, and the ThreadFull type is used extensively across multiple files in the codebase.

  • apps/supabase/src/mb.types.ts: export namespace MB
  • apps/masterbots.ai/lib/threads.ts: thread: MB.ThreadFull
  • apps/masterbots.ai/components/shared/thread-accordion.tsx: thread: MB.ThreadFull
  • apps/masterbots.ai/components/shared/thread-list-chat-item.tsx: thread: MB.ThreadFull
  • apps/masterbots.ai/components/shared/thread-list-accordion.tsx: thread: MB.ThreadFull
  • apps/masterbots.ai/components/shared/thread-dialog.tsx: thread: MB.ThreadFull
  • apps/masterbots.ai/components/shared/thread-heading.tsx: thread: MB.ThreadFull
  • apps/masterbots.ai/components/shared/thread-list.tsx: initialThreads: MB.ThreadFull[]
  • apps/masterbots.ai/app/actions.ts: Promise<MB.ThreadFull[]>, Promise<MB.ThreadFull | null>, as unknown as MB.ThreadFull

The import statement and the prop type change in thread-list.tsx are appropriate and correctly implemented.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of the `MB` namespace.

# Test: Search for the `MB` namespace implementation. Expect: Correct implementation with `ThreadFull` type.
rg --type ts --pattern 'export namespace MB'

Length of output: 458



Script:

#!/bin/bash
# Description: Verify the implementation of the `MB` namespace and the `ThreadFull` type.

# Test: Search for the `MB` namespace implementation.
rg 'export namespace MB'

# Test: Search for the `ThreadFull` type within the `MB` namespace.
rg 'MB.ThreadFull'

Length of output: 1022


40-43: The change in the ThreadListProps interface to use MB.ThreadFull[] for initialThreads is appropriate and aligns with the updated data structure.

apps/supabase/src/mb.types.ts (1)

8-31: The new and updated type definitions in the MB namespace are well-structured and align with the overall data structure.

apps/masterbots.ai/lib/metadata.ts (2)

3-3: Ensure that the getThread function from @/app/actions is correctly implemented and handles errors appropriately.


6-43: The metadata generation logic in the generateMbMetadata function is well-structured and correctly uses properties from the thread object.

apps/masterbots.ai/hooks/use-global-store.tsx (3)

5-5: Ensure that the MB namespace from @repo/supabase is correctly implemented and includes the ChatbotWithPrompts and Category types.

Verification successful

Verification of MB Namespace and Types

The MB namespace is correctly implemented in apps/supabase/src/mb.types.ts. Additionally, the ChatbotWithPrompts and Category types are used in the apps/masterbots.ai/hooks/use-global-store.tsx file, confirming their presence and usage.

  • MB namespace found in: apps/supabase/src/mb.types.ts
  • MB.ChatbotWithPrompts type used in: apps/masterbots.ai/hooks/use-global-store.tsx
  • MB.Category type used in: apps/masterbots.ai/hooks/use-global-store.tsx, apps/masterbots.ai/components/shared/category-tabs/category-tabs.tsx
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of the `MB` namespace.

# Test: Search for the `MB` namespace implementation. Expect: Correct implementation with `ChatbotWithPrompts` and `Category` types.
rg --type ts --pattern 'export namespace MB'

Length of output: 458



Script:

#!/bin/bash
# Description: Verify the implementation of the `MB` namespace.

# Test: Search for the `MB` namespace implementation. Expect: Correct implementation with `ChatbotWithPrompts` and `Category` types.
rg 'export namespace MB' --type ts

# Test: Search for the `ChatbotWithPrompts` type within the `MB` namespace.
rg 'MB\.ChatbotWithPrompts' --type ts

# Test: Search for the `Category` type within the `MB` namespace.
rg 'MB\.Category' --type ts

Length of output: 567


21-27: The GlobalStoreProvider component correctly initializes the state with the provided user, chatbots, and categories props.


40-41: The change in the GlobalStoreProviderProps and GlobalStoreContextValue types to use MB.ChatbotWithPrompts[] and MB.Category[] is appropriate and aligns with the updated data structure.

apps/masterbots.ai/components/shared/thread-dialog.tsx (3)

9-10: Import statement for MB namespace.

The import statement for the MB namespace from @repo/supabase is correctly added.


22-23: Ensure firstUserMessage and firstAssistantMessage are defined.

Please verify that thread.firstUserMessage and thread.firstAssistantMessage are always defined in the MB.ThreadFull type to avoid potential runtime errors.


46-48: ThreadDialogProps interface definition.

The ThreadDialogProps interface correctly extends DialogProps and includes the thread prop of type MB.ThreadFull.

apps/masterbots.ai/app/(browse)/page.tsx (2)

5-6: Import statements for decodeQuery, getThreads, and getThreadsLike.

The import statements for decodeQuery from @/lib/url-params and getThreads, getThreadsLike from ../actions are correctly added.


28-30: Thread rendering logic.

The logic for rendering threads using the ThreadList component and displaying a Card component when no threads are found is correct.

apps/masterbots.ai/app/oss/layout.tsx (1)

5-6: Layout structure.

The layout structure for the OssLayout component is correctly defined, with a sidebar for navigation links and a main content area for children components.

apps/masterbots.ai/components/layout/header.tsx (2)

24-27: User authentication logic.

The user authentication logic correctly checks if the user is authenticated and renders the UserMenu component if authenticated, or a login button if not.


Line range hint 38-42: HeaderLink component.

The HeaderLink component is correctly defined and used to render navigation links in the header.

apps/masterbots.ai/components/layout/cmdk.tsx (2)

3-3: Import statement for useState.

The import statement for useState is correctly added.


45-48: Command items.

The command items for Search, Profile, Billing, and Settings are correctly defined and used within the CommandGroup.

apps/masterbots.ai/app/u/[username]/page.tsx (4)

1-8: Import statements.

The import statements for various components and utilities are correctly added.


9-23: getUserWithThreads function.

The getUserWithThreads function is correctly defined, fetching user data and threads from Supabase and converting the data to camel case.


25-43: BotThreadsPage component.

The BotThreadsPage component is correctly defined, fetching user data and threads based on the username and rendering them using various components.


46-48: BotPageParams type.

The BotPageParams type correctly defines the structure for the params prop.

apps/masterbots.ai/components/shared/thread-heading.tsx (3)

5-6: Imports look good and are necessary for the new functionality.


22-22: The changes to the ThreadHeading component are consistent with the new type definitions and maintain the component structure.


60-60: The ThreadHeadingProps interface changes align with the new type definitions and ensure type safety.

apps/masterbots.ai/app/auth/callback/route.ts (4)

5-7: Imports look good and are necessary for the new functionality.


27-35: The changes to the user data insertion logic ensure that user data is correctly inserted into the database.


39-40: The error handling for database insertion is appropriate and ensures that any errors are correctly managed.


46-52: The changes to cookie handling ensure that user profile information is correctly set in cookies.

apps/masterbots.ai/app/(browse)/[category]/page.tsx (4)

4-6: Imports look good and are necessary for the new functionality.


28-28: The data fetching logic for threads is correctly implemented.


41-43: The changes to component props ensure that the correct data is passed to the ThreadList component.


Line range hint 53-53: The changes to the CategoryPageProps interface ensure that the searchParams property is correctly typed.

apps/masterbots.ai/components/shared/thread-list-accordion.tsx (4)

12-12: Imports look good and are necessary for the new functionality.


18-18: The changes to the ThreadListAccordion component are consistent with the new type definitions and maintain the component structure.


49-49: The initialMessagePairs prop is correctly set to an empty array.


59-59: The ThreadListAccordionProps interface changes align with the new type definitions and ensure type safety.

apps/masterbots.ai/components/shared/search-input.tsx (4)

3-8: Imports look good and are necessary for the new functionality.


17-30: The updateUrl function correctly handles URL updates and debouncing.


46-47: The event handling for the search input is correctly implemented.


51-51: The input field properties are correctly set.

apps/masterbots.ai/components/shared/thread-message.tsx (3)

8-8: Imports look good and are necessary for the new functionality.


12-12: The ChatMessageProps interface changes align with the new type definitions and ensure type safety.


24-24: The changes to the BrowseChatMessage component are consistent with the new type definitions and maintain the component structure.

apps/masterbots.ai/lib/threads.ts (1)

35-42: Duplicate review comment for findNextAssistantMessage.

apps/masterbots.ai/package.json (2)

Line range hint 42-72: Ensure that the new dependencies camelize-ts, ts-case-convert, use-debounce, and @repo/supabase are necessary and correctly versioned.


Line range hint 5-15: The scripts section looks good and follows best practices.

apps/masterbots.ai/app/layout.tsx (1)

Line range hint 30-65: The RootLayout component is well-structured and follows best practices.

apps/supabase/src/supa.schemas.ts (12)

5-15: LGTM!


17-20: LGTM!


22-25: LGTM!


27-30: LGTM!


32-37: LGTM!


39-44: LGTM!


46-51: LGTM!


53-63: LGTM!


65-75: LGTM!


77-87: LGTM!


89-92: LGTM!


94-97: LGTM!

apps/supabase/src/supa.types.ts (6)

Line range hint 1-5: LGTM!


Line range hint 7-10: LGTM!


Line range hint 12-14: LGTM!


Line range hint 16-18: LGTM!


Line range hint 20-22: LGTM!


Line range hint 24-26: LGTM!

Comment on lines +10 to +35
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'
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the short link to the return value for successful creation.

-    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.

Suggested change
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'
}
}

Comment on lines +12 to +13
// console.log({ query, limit, page })
const threads = await (query? getThreadsLike({ query }) : getThreads())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented-out console log.

Consider removing the commented-out console log statement to keep the code clean.

-  // console.log({ query, limit, page })

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.

Suggested change
// console.log({ query, limit, page })
const threads = await (query? getThreadsLike({ query }) : getThreads())
const threads = await (query? getThreadsLike({ query }) : getThreads())

query
})

console.log(' ============== THREADS ============== ')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console log statement.

Consider removing the console log statement to avoid unnecessary logging in production.

-  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.

Suggested change
console.log(' ============== THREADS ============== ')

Comment on lines +17 to +22
// const categories = await getCategories()
// console.log(params.category)
// const categoryId = categories.find(
// c => toSlug(c.name) === params.category
// )?.categoryId
// if (!categoryId) throw new Error('Category not foud')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented-out code should be removed if it is no longer needed to keep the codebase clean.

-  // const categories = await getCategories()
-  // console.log(params.category)
-  // const categoryId = categories.find(
-  //   c => toSlug(c.name) === params.category
-  // )?.categoryId
-  // if (!categoryId) throw new Error('Category not foud')

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.

Suggested change
// const categories = await getCategories()
// console.log(params.category)
// const categoryId = categories.find(
// c => toSlug(c.name) === params.category
// )?.categoryId
// if (!categoryId) throw new Error('Category not foud')

...getFirstMessages(threadData.message),
chatbot: {
...omit(threadData.chatbot, 'chatbot_category'),
catogories: threadData.chatbot.chatbot_category.category
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix typo in property name.

- catogories: threadData.chatbot.chatbot_category.category
+ categories: threadData.chatbot.chatbot_category.category

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.

Suggested change
catogories: threadData.chatbot.chatbot_category.category
categories: threadData.chatbot.chatbot_category.category

@@ -33,7 +33,7 @@ export function ThreadAccordion({
const { data: pairs, error } = useQuery({
queryKey: [`messages-${thread.threadId}`],
queryFn: () => getMessagePairs(thread.threadId),
initialData: initialMessagePairs,
initialData: [], //initialMessagePairs,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using initialMessagePairs instead of an empty array for initialData to leverage server-side fetched data.

const { data: pairs, error } = useQuery({
  queryKey: [`messages-${thread.threadId}`],
  queryFn: () => getMessagePairs(thread.threadId),
- initialData: [], //initialMessagePairs,
+ initialData: initialMessagePairs,
  networkMode: 'always',
  refetchOnMount: true,
  enabled: clientFetch
})

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.

Suggested change
initialData: [], //initialMessagePairs,
const { data: pairs, error } = useQuery({
queryKey: [`messages-${thread.threadId}`],
queryFn: () => getMessagePairs(thread.threadId),
initialData: initialMessagePairs,
networkMode: 'always',
refetchOnMount: true,
enabled: clientFetch
})

<div className="pl-12 md:text-lg">
{p.userMessage.content}
</div>
<div className="pl-12 md:text-lg">{p.question.content}</div>
Copy link
Contributor

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 class name pl-12 to pl-2 for better alignment.

<div className="pl-2 md:text-lg">{p.question.content}</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.

Suggested change
<div className="pl-12 md:text-lg">{p.question.content}</div>
<div className="pl-2 md:text-lg">{p.question.content}</div>

Comment on lines +127 to +134
<div>content</div>
{/* {p.chatGptMessage.map(message => (
<BrowseChatMessage
chatbot={thread.chatbot}
key={`message-${message.messageId}`}
message={convertMessage(message)}
/>
))}
))} */}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncomment the code to display the chat messages if it is intended to be used.

Do you want me to uncomment the code to display the chat messages or open a GitHub issue to track this task?

Comment on lines +22 to +34
<div className="flex flex-col w-full gap-8 py-5">
{!initialThreads.length ? (
<div>No threads founds</div>
) : (
initialThreads.map(thread => (
<ThreadComponent
chat={chat}
defaultOpen={false} // we can have one open by default
key={thread.threadId}
thread={thread}
/>
))}
<div ref={loadMoreRef}>
{isFetchingNextPage ? 'loading more results ...' : ''}
</div>
))
)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ThreadList component correctly handles the display of threads based on the context. However, there is a minor typo in the message displayed when no threads are found.

-        <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.

Suggested change
<div className="flex flex-col w-full gap-8 py-5">
{!initialThreads.length ? (
<div>No threads founds</div>
) : (
initialThreads.map(thread => (
<ThreadComponent
chat={chat}
defaultOpen={false} // we can have one open by default
key={thread.threadId}
thread={thread}
/>
))}
<div ref={loadMoreRef}>
{isFetchingNextPage ? 'loading more results ...' : ''}
</div>
))
)}
<div className="flex flex-col w-full gap-8 py-5">
{!initialThreads.length ? (
<div>No threads found</div>
) : (
initialThreads.map(thread => (
<ThreadComponent
chat={chat}
defaultOpen={false} // we can have one open by default
key={thread.threadId}
thread={thread}
/>
))
)}

import { Tables } from './supa.types';
import type * as AI from 'ai'

// TODO: move this to packages/mb-types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving the type definitions to packages/mb-types as indicated by the TODO comment for better modularity and maintainability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant