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

fix: pre launch merge conflict #347

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 apps/masterbots.ai/app/(browse)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import BrowseList from '@/components/routes/browse/browse-list'
import { BrowseSearchInput } from '@/components/routes/browse/browse-search-input'
// export { generateMbMetadata as generateMetadata } from '@/lib/metadata'

export default async function HomePage() {
return (
Expand Down
34 changes: 24 additions & 10 deletions apps/masterbots.ai/app/actions/ai-executers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,33 @@ export async function getWebSearchTool({
throw new Error('Web Search could not be completed.')
}

if (
!response.outputs['web search']?.output &&
!response.outputs['web search']?.logs
) {
if (!response.outputs['web search']?.output) {
throw new Error('No output given. Web search could not be completed')
}

return `## INPUT:

${response.outputs['web search']?.output ?? response.outputs['web search']?.logs}`
return `${response.outputs['web search'].output}

## EXAMPLE:

**Resume:**
Brewers: 9
Dodgers: 2

**Summary**
Yelich, Perkins power Brewers to 9-2 victory over Dodgers and avoid being swept in weekend series. — Christian Yelich and Blake Perkins both homered, had three hits and drove in three runs as the Milwaukee Brewers beat the Los Angeles Dodgers 9-2 Sunday to snap a seven-game losing streak at Dodger Stadium.

**Homeruns:**
Yelich

**Winning Pitcher:**
J. Junis

**Sources**:

1. [https://website1.com/](https://website1.com/)
2. [https://website2.com/](https://website2.com/)`
} catch (error) {
return `Something went wrong with web search that failed to provide results. Please try again later.

[ERROR LOG]: ${JSON.stringify(error, null, 2)}`
console.error('Error fetching app data: ', error)
throw error
}
}
6 changes: 3 additions & 3 deletions apps/masterbots.ai/app/actions/ai-main-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export async function createResponseStream(
temperature: 0.4,
tools,
maxRetries: 2,
maxToolRoundtrips: 2
maxToolRoundtrips: 1
})
responseStream = response.toDataStreamResponse().body as ReadableStream
break
Expand All @@ -242,7 +242,7 @@ export async function createResponseStream(
maxTokens: 300,
tools,
maxRetries: 2,
maxToolRoundtrips: 2
maxToolRoundtrips: 1
})
responseStream = response.toDataStreamResponse().body as ReadableStream
break
Expand All @@ -262,7 +262,7 @@ export async function createResponseStream(
maxTokens: 1000,
tools,
maxRetries: 2,
maxToolRoundtrips: 2
maxToolRoundtrips: 1
})
responseStream = response.toDataStreamResponse().body as ReadableStream
break
Expand Down
75 changes: 23 additions & 52 deletions apps/masterbots.ai/app/api/og/route.tsx
Original file line number Diff line number Diff line change
@@ -1,71 +1,39 @@
//import { ImageResponse } from '@vercel/og'
// generates the image with error ↑
import { ImageResponse } from 'next/og'
import { NextRequest } from 'next/server'
import { getThreadForOG } from './edge-client'
import { getThread } from '@/services/hasura'
import '@/app/globals.css'
import OGImage from '@/components/shared/og-image'
import { UUID } from '@/types/types'
export const runtime = 'edge'

const defaultContent = {
thread: {
chatbot: {
name: 'Masterbots',
avatar: process.env.NEXT_PUBLIC_BASE_URL + '/images/masterbots.png',
categories: [{ category: { name: 'AI' } }]
}
},
question:
'Elevating AI Beyond ChatGPT: Specialized Chatbots, Social Sharing and User-Friendly Innovation',
answer:
'Elevating AI Beyond ChatGPT: Specialized Chatbots, Social Sharing and User-Friendly Innovation',
username: 'Masterbots',
user_avatar: process.env.NEXT_PUBLIC_BASE_URL + '/images/masterbots.png',
isLightTheme: false
}
// export const runtime = 'edge'

export async function GET(req: NextRequest) {
try {
const { searchParams } = req.nextUrl
const rawThreadId = searchParams.get('threadId')
const threadId = rawThreadId?.match(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)
? (rawThreadId as UUID)
: null

if (!threadId) {
return new ImageResponse(<OGImage {...defaultContent} />, {
width: 1200,
height: 627
})
}
const thread = await getThreadForOG(threadId)

if (!thread?.thread?.length) {
// Use metadata when thread not found
return new ImageResponse(<OGImage {...defaultContent} />, {
width: 1200,
height: 627
})
}

const threadData = thread.thread[0]
const threadId = searchParams.get('threadId')
const thread = await getThread({ threadId, jwt: '' })
Comment on lines +14 to +15
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Validate threadId before using it

The threadId retrieved from searchParams.get('threadId') might be null or invalid. Consider adding validation to ensure threadId is present and correctly formatted before using it in getThread. This will prevent potential runtime errors or security issues.

Apply this diff to add validation:

 const threadId = searchParams.get('threadId')
+if (!threadId) {
+  return new Response(`Invalid thread ID`, {
+    status: 400
+  })
+}
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const threadId = searchParams.get('threadId')
const thread = await getThread({ threadId, jwt: '' })
const threadId = searchParams.get('threadId')
if (!threadId) {
return new Response(`Invalid thread ID`, {
status: 400
})
}
const thread = await getThread({ threadId, jwt: '' })

const question =
threadData?.messages?.find((m: { role: string }) => m.role === 'user')
?.content || 'not found'
thread.messages.find(m => m.role === 'user')?.content || 'not found'
const answer =
threadData?.messages?.find(
(m: { role: string }) => m.role === 'assistant'
)?.content || 'not found'
const username = threadData?.user?.username || 'Anonymous'
const user_avatar = threadData?.user?.profilePicture || ''
thread.messages.find(m => m.role === 'assistant')?.content || 'not found'
const username = thread.user?.username
const user_avatar = thread.user?.profilePicture || ''

let theme = 'dark'
if (typeof window !== 'undefined') {
theme = localStorage.getItem('theme') || 'dark'
}
Comment on lines +24 to +26
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid using window and localStorage in server-side code

window and localStorage are only available in the browser environment. Since this API route runs on the server, accessing them will result in errors. Consider passing the theme as a parameter or setting a default theme.

Apply this diff to remove browser-specific code:

 let theme = 'dark'
-if (typeof window !== 'undefined') {
-  theme = localStorage.getItem('theme') || 'dark'
-}
 const isLightTheme = theme === 'light'

If you need to determine the theme based on the request, consider passing it as a query parameter:

 const threadId = searchParams.get('threadId')
+const theme = searchParams.get('theme') || 'dark'
 const thread = await getThread({ threadId, jwt: '' })
 // ...
 const isLightTheme = theme === 'light'
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (typeof window !== 'undefined') {
theme = localStorage.getItem('theme') || 'dark'
}
let theme = 'dark'
const isLightTheme = theme === 'light'

const isLightTheme = theme === 'light'
return new ImageResponse(
(
<OGImage
thread={threadData}
thread={thread}
question={question}
answer={answer}
username={username}
user_avatar={user_avatar}
isLightTheme={false}
isLightTheme={isLightTheme}
/>
),
{
Expand All @@ -74,9 +42,12 @@ export async function GET(req: NextRequest) {
}
)
} catch (e: any) {
console.error('OG Image generation error:', e)
return new Response(`Failed to generate the image: ${e.message}`, {
console.log(`${e.message}`)
return new Response(`Failed to generate the image`, {
status: 500
})
}
}
function useTheme() {
throw new Error('Function not implemented.')
}
Comment on lines +51 to +53
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove unused useTheme function

The useTheme function is not implemented and currently throws an error. If it's not required in this file, consider removing it to clean up the code.

Apply this diff to remove the unused function:

-function useTheme() {
-  throw new Error('Function not implemented.')
-}

4 changes: 1 addition & 3 deletions apps/masterbots.ai/app/b/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ export async function generateMetadata({
title: chatbot?.name || '',
description: chatbot?.description || '',
ogType: 'website',
ogImageUrl: chatbot?.threads?.[0]?.threadId
? `${process.env.BASE_URL || ''}/api/og?threadId=${chatbot.threads[0].threadId}`
: `${process.env.BASE_URL || ''}/api/og`,
ogImageUrl: chatbot?.avatar || '',
twitterCard: 'summary_large_image'
}

Expand Down
2 changes: 1 addition & 1 deletion apps/masterbots.ai/app/c/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function generateMetadata(): Promise<Metadata> {
description:
'Welcome to the chatbot page. Interact with our AI-powered chatbot and get answers to your questions.',
ogType: 'website',
ogImageUrl: `${process.env.BASE_URL || ''}/api/og`,
ogImageUrl: '',
twitterCard: 'summary'
}

Expand Down
19 changes: 10 additions & 9 deletions apps/masterbots.ai/app/globals.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
:root {
--background: 0 0% 100%;
Expand Down Expand Up @@ -49,17 +50,17 @@
--tertiary-foreground: 0 0% 98%;
--font-size-base: 1rem;

--background-chat-gradient: linear-gradient(180deg, rgba(115, 201, 97, 0.2) 0%, rgba(122, 214, 104, 0.4) 100%);
--background-chat-hover-gradient: linear-gradient(-180deg, rgba(113, 199, 96, 0.1) 0%, rgba(117, 205, 99, 0.3) 100%);
--background-public-gradient: linear-gradient(180deg, rgba(115, 201, 97, 0.2) 0%, rgba(122, 214, 104, 0.4) 100%);
--background-public-hover-gradient: linear-gradient(-180deg, rgba(113, 199, 96, 0.1) 0%, rgba(117, 205, 99, 0.3) 100%);

/* Public route gradients */
--background-public-gradient: linear-gradient(180deg, rgba(155, 22, 232, 0.2) 0%, rgba(190, 22, 232, 0.53) 100%);
--background-public-hover-gradient: linear-gradient(-180deg, rgba(166, 22, 232, 0.1) 0%, rgba(190, 22, 232, 0.3) 100%);
--background-chat-gradient: linear-gradient(180deg, rgba(155, 22, 232, 0.2) 0%, rgba(190, 22, 232, 0.53) 100%);
--background-chat-hover-gradient: linear-gradient(-180deg, rgba(166, 22, 232, 0.1) 0%, rgba(190, 22, 232, 0.3) 100%);
}

.dark {
--background: 240 10% 3.9%;
--foreground: 0 0% 98%;
--foreground: 0 0% 100%;

--muted: 240 3.7% 15.9%;
--muted-foreground: 240 5% 79%;
Expand Down Expand Up @@ -101,12 +102,12 @@
--tertiary: 120, 100%, 65%;
--tertiary-foreground: 0 0% 98%;

--background-chat-gradient: linear-gradient(180deg, rgba(115, 201, 97, 0.2) 0%, rgba(122, 214, 104, 0.4) 100%);
--background-chat-hover-gradient: linear-gradient(-180deg, rgba(113, 199, 96, 0.1) 0%, rgba(117, 205, 99, 0.3) 100%);
--background-public-gradient: linear-gradient(180deg, rgba(115, 201, 97, 0.2) 0%, rgba(122, 214, 104, 0.4) 100%);
--background-public-hover-gradient: linear-gradient(-180deg, rgba(113, 199, 96, 0.1) 0%, rgba(117, 205, 99, 0.3) 100%);

/* Public route gradients */
--background-public-gradient: linear-gradient(180deg, rgba(155, 22, 232, 0.2) 0%, rgba(190, 22, 232, 0.53) 100%);
--background-public-hover-gradient: linear-gradient(-180deg, rgba(166, 22, 232, 0.1) 0%, rgba(190, 22, 232, 0.3) 100%);
--background-chat-gradient: linear-gradient(180deg, rgba(155, 22, 232, 0.2) 0%, rgba(190, 22, 232, 0.53) 100%);
--background-chat-hover-gradient: linear-gradient(-180deg, rgba(166, 22, 232, 0.1) 0%, rgba(190, 22, 232, 0.3) 100%);
}
}

Expand Down
7 changes: 4 additions & 3 deletions apps/masterbots.ai/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { GeistMono } from 'geist/font/mono'
import { GeistSans } from 'geist/font/sans'
import { Toaster } from 'react-hot-toast'

import '@/app/globals.css'
import { Header } from '@/components/layout/header/header'
import { Providers } from '@/components/layout/providers'
import { cn } from '@/lib/utils'
import { GoogleAnalytics } from '@next/third-parties/google'
import { Metadata } from 'next'
import NextTopLoader from 'nextjs-toploader'
import { Toaster } from '@/components/ui/sonner'

export default function RootLayout({ children }: RootLayoutProps) {
return (
Expand Down Expand Up @@ -56,7 +57,7 @@ export const metadata: Metadata = {
siteName: 'Masterbots',
images: [
{
url: `${process.env.BASE_URL || ''}/api/og`,
url: 'https://masterbots.ai/images/masterbots.png',
width: 1232,
height: 928,
alt: 'Masterbots'
Expand All @@ -71,7 +72,7 @@ export const metadata: Metadata = {
card: 'summary_large_image',
images: [
{
url: `${process.env.BASE_URL || ''}/api/og`,
url: 'https://masterbots.ai/images/masterbots.png',
width: 1232,
height: 928,
alt: 'Masterbots'
Expand Down
9 changes: 4 additions & 5 deletions apps/masterbots.ai/components/auth/forgot-password-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { useSonner } from '@/lib/hooks/useSonner'
import { validateEmail } from '@/lib/utils'
import type React from 'react'
import { useState } from 'react'
import { toast } from 'react-hot-toast'

export default function ForgotPasswordForm() {
const [email, setEmail] = useState('')
const [isLoading, setIsLoading] = useState(false)
const [emailError, setEmailError] = useState('')
const { customSonner } = useSonner()

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
Expand All @@ -35,14 +34,14 @@ export default function ForgotPasswordForm() {
const data = await response.json()

if (response.ok) {
customSonner({ type: 'success', text: data.message })
toast.success(data.message)
setEmail('')
} else {
customSonner({ type: 'error', text: data.error || 'An error occurred' })
toast.error(data.error || 'An error occurred')
}
} catch (error) {
console.error('Error:', error)
customSonner({ type: 'error', text: 'An unexpected error occurred' })
toast.error('An unexpected error occurred')
} finally {
setIsLoading(false)
}
Expand Down
13 changes: 6 additions & 7 deletions apps/masterbots.ai/components/auth/reset-password-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { isPasswordStrong } from '@/lib/password'
import { Eye, EyeOff } from 'lucide-react'
import { useRouter } from 'next/navigation'
import type React from 'react'
import { toast } from 'react-hot-toast'
import { useSetState } from 'react-use'
import { useSonner } from '@/lib/hooks/useSonner'

interface FormState {
password: string
Expand All @@ -29,7 +29,6 @@ export default function ResetPasswordForm({ token }: { token: string }) {
showPassword: false,
showConfirmPassword: false
})
const { customSonner } = useSonner()

const router = useRouter()

Expand All @@ -49,13 +48,13 @@ export default function ResetPasswordForm({ token }: { token: string }) {
setState({ isLoading: true })

if (!isPasswordStrong(state.password)) {
customSonner({ type: 'error', text: 'Please choose a stronger password' })
toast.error('Please choose a stronger password')
setState({ isLoading: false })
return
}

if (state.password !== state.confirmPassword) {
customSonner({ type: 'error', text: 'Passwords do not match' })
toast.error('Passwords do not match')
setState({ isLoading: false })
return
}
Expand All @@ -70,14 +69,14 @@ export default function ResetPasswordForm({ token }: { token: string }) {
const data = await response.json()

if (response.ok) {
customSonner({ type: 'success', text: data.message })
toast.success(data.message)
router.push('/auth/signin')
} else {
customSonner({ type: 'error', text: data.error || 'An error occurred' })
toast.error(data.error || 'An error occurred')
}
} catch (error) {
console.error('Error:', error)
customSonner({ type: 'error', text: 'An unexpected error occurred' })
toast.error('An unexpected error occurred')
} finally {
setState({ isLoading: false })
}
Expand Down
Loading