Skip to content
Open
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
11 changes: 8 additions & 3 deletions app/[locale]/[workspaceid]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import { Dashboard } from "@/components/ui/dashboard"
import { ChatbotUIContext } from "@/context/context"
import { getAssistantWorkspacesByWorkspaceId } from "@/db/assistants"
import {
getAssistantWorkspacesByWorkspaceId,
getPublicAsistants
} from "@/db/assistants"
import { getChatsByWorkspaceId } from "@/db/chats"
import { getCollectionWorkspacesByWorkspaceId } from "@/db/collections"
import { getFileWorkspacesByWorkspaceId } from "@/db/files"
Expand Down Expand Up @@ -95,9 +98,11 @@ export default function WorkspaceLayout({ children }: WorkspaceLayoutProps) {
setSelectedWorkspace(workspace)

const assistantData = await getAssistantWorkspacesByWorkspaceId(workspaceId)
setAssistants(assistantData.assistants)
const publicAssistants = await getPublicAsistants()
const assistants = [...assistantData.assistants, ...publicAssistants]
setAssistants(assistants)

for (const assistant of assistantData.assistants) {
for (const assistant of assistants) {
let url = ""

if (assistant.image_path) {
Expand Down
2 changes: 1 addition & 1 deletion components/chat/chat-files-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const ChatFilesDisplay: FC<ChatFilesDisplayProps> = ({}) => {
...newMessageFiles.filter(
file => !chatFiles.some(chatFile => chatFile.id === file.id)
),
...chatFiles
...chatFiles.filter(file => !file.hidden) // Only show user files from chatFiles
]

const combinedMessageFiles = [...messageImages, ...combinedChatFiles]
Expand Down
6 changes: 3 additions & 3 deletions components/chat/chat-hooks/use-chat-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ export const useChatHandler = () => {
id: file.id,
name: file.name,
type: file.type,
file: null
file: null,
description: file.description,
hidden: selectedAssistant.sharing === "public"
}))
)

if (allFiles.length > 0) setShowFilesDisplay(true)
} else if (selectedPreset) {
setChatSettings({
model: selectedPreset.model as LLMID,
Expand Down
6 changes: 3 additions & 3 deletions components/chat/chat-hooks/use-prompt-and-command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ export const usePromptAndCommand = () => {
id: file.id,
name: file.name,
type: file.type,
file: null
file: null,
description: file.description,
hidden: assistant.sharing === "public"
}))
)

if (allFiles.length > 0) setShowFilesDisplay(true)
}

return {
Expand Down
3 changes: 2 additions & 1 deletion components/chat/chat-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export const ChatUI: FC<ChatUIProps> = ({}) => {
id: file.id,
name: file.name,
type: file.type,
file: null
file: null,
description: file.description
}))
)

Expand Down
5 changes: 3 additions & 2 deletions components/chat/quick-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ export const QuickSettings: FC<QuickSettingsProps> = ({}) => {
id: file.id,
name: file.name,
type: file.type,
file: null
file: null,
description: file.description,
hidden: item.sharing === "public"
}))
)
if (allFiles.length > 0) setShowFilesDisplay(true)
setLoading(false)
setSelectedPreset(null)
} else if (contentType === "presets" && item) {
Expand Down
8 changes: 4 additions & 4 deletions components/messages/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const Message: FC<MessageProps> = ({
chatImages,
assistantImages,
toolInUse,
files,
chatFiles,
models
} = useContext(ChatbotUIContext)

Expand Down Expand Up @@ -162,15 +162,15 @@ export const Message: FC<MessageProps> = ({
> = {}

const fileSummary = fileItems.reduce((acc, fileItem) => {
const parentFile = files.find(file => file.id === fileItem.file_id)
const parentFile = chatFiles.find(file => file.id === fileItem.file_id)
if (parentFile) {
if (!acc[parentFile.id]) {
acc[parentFile.id] = {
id: parentFile.id,
name: parentFile.name,
count: 1,
type: parentFile.type,
description: parentFile.description
description: parentFile.description || ""
}
} else {
acc[parentFile.id].count += 1
Expand Down Expand Up @@ -348,7 +348,7 @@ export const Message: FC<MessageProps> = ({

{fileItems
.filter(fileItem => {
const parentFile = files.find(
const parentFile = chatFiles.find(
parentFile => parentFile.id === fileItem.file_id
)
return parentFile?.id === file.id
Expand Down
4 changes: 2 additions & 2 deletions components/sidebar/items/all/sidebar-display-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const SidebarItem: FC<SidebarItemProps> = ({
icon,
isTyping
}) => {
const { selectedWorkspace, setChats, setSelectedAssistant } =
const { selectedWorkspace, setChats, setSelectedAssistant, profile } =
useContext(ChatbotUIContext)

const router = useRouter()
Expand All @@ -43,7 +43,7 @@ export const SidebarItem: FC<SidebarItemProps> = ({
if (!selectedWorkspace) return

const createdChat = await createChat({
user_id: assistant.user_id,
user_id: profile!.user_id,
workspace_id: selectedWorkspace.id,
assistant_id: assistant.id,
context_length: assistant.context_length,
Expand Down
3 changes: 2 additions & 1 deletion components/sidebar/items/all/sidebar-update-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const SidebarUpdateItem: FC<SidebarUpdateItemProps> = ({
const {
workspaces,
selectedWorkspace,
profile,
setChats,
setPresets,
setPrompts,
Expand Down Expand Up @@ -392,7 +393,7 @@ export const SidebarUpdateItem: FC<SidebarUpdateItemProps> = ({

for (const file of filesToAdd) {
await createCollectionFile({
user_id: item.user_id,
user_id: profile.user_id,
collection_id: collectionId,
file_id: file.id
})
Expand Down
17 changes: 15 additions & 2 deletions db/assistants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ export const getAssistantById = async (assistantId: string) => {
return assistant
}

export const getPublicAsistants = async () => {
const { data: assistants, error } = await supabase
.from("assistants")
.select("*")
.eq("sharing", "public")

if (!assistants) {
throw new Error(error.message)
}

return assistants
}

export const getAssistantWorkspacesByWorkspaceId = async (
workspaceId: string
) => {
Expand Down Expand Up @@ -74,7 +87,7 @@ export const createAssistant = async (
}

await createAssistantWorkspace({
user_id: createdAssistant.user_id,
user_id: createdAssistant.user_id!,
assistant_id: createdAssistant.id,
workspace_id
})
Expand All @@ -97,7 +110,7 @@ export const createAssistants = async (

await createAssistantWorkspaces(
createdAssistants.map(assistant => ({
user_id: assistant.user_id,
user_id: assistant.user_id!,
assistant_id: assistant.id,
workspace_id
}))
Expand Down
2 changes: 1 addition & 1 deletion db/collection-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getCollectionFilesByCollectionId = async (
`
id,
name,
files ( id, name, type )
files ( id, name, type, description )
`
)
.eq("id", collectionId)
Expand Down
4 changes: 2 additions & 2 deletions db/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const createCollection = async (
}

await createCollectionWorkspace({
user_id: createdCollection.user_id,
user_id: createdCollection.user_id!,
collection_id: createdCollection.id,
workspace_id
})
Expand All @@ -97,7 +97,7 @@ export const createCollections = async (

await createCollectionWorkspaces(
createdCollections.map(collection => ({
user_id: collection.user_id,
user_id: collection.user_id!,
collection_id: collection.id,
workspace_id
}))
Expand Down
10 changes: 5 additions & 5 deletions db/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ export const createFile = async (
}

await createFileWorkspace({
user_id: createdFile.user_id,
user_id: createdFile.user_id!,
file_id: createdFile.id,
workspace_id
})

const filePath = await uploadFile(file, {
name: createdFile.name,
user_id: createdFile.user_id,
user_id: createdFile.user_id!,
file_id: createdFile.name
})

Expand Down Expand Up @@ -172,14 +172,14 @@ export const createDocXFile = async (
}

await createFileWorkspace({
user_id: createdFile.user_id,
user_id: createdFile.user_id!,
file_id: createdFile.id,
workspace_id
})

const filePath = await uploadFile(file, {
name: createdFile.name,
user_id: createdFile.user_id,
user_id: createdFile.user_id!,
file_id: createdFile.name
})

Expand Down Expand Up @@ -232,7 +232,7 @@ export const createFiles = async (

await createFileWorkspaces(
createdFiles.map(file => ({
user_id: file.user_id,
user_id: file.user_id!,
file_id: file.id,
workspace_id
}))
Expand Down
4 changes: 2 additions & 2 deletions db/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const createTool = async (
}

await createToolWorkspace({
user_id: createdTool.user_id,
user_id: createdTool.user_id!,
tool_id: createdTool.id,
workspace_id
})
Expand All @@ -93,7 +93,7 @@ export const createTools = async (

await createToolWorkspaces(
createdTools.map(tool => ({
user_id: tool.user_id,
user_id: tool.user_id!,
tool_id: tool.id,
workspace_id
}))
Expand Down
42 changes: 42 additions & 0 deletions supabase/migrations/20251109105000_system_assistants.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
ALTER TABLE file_items
ALTER COLUMN user_id DROP NOT NULL,
ADD COLUMN metadata JSON;

ALTER TABLE files
ALTER COLUMN user_id DROP NOT NULL;

ALTER TABLE collections
ALTER COLUMN user_id DROP NOT NULL;

ALTER TABLE collection_files
ALTER COLUMN user_id DROP NOT NULL;

ALTER TABLE assistants
ALTER COLUMN user_id DROP NOT NULL;

ALTER TABLE assistant_files
ALTER COLUMN user_id DROP NOT NULL;

ALTER TABLE assistant_collections
ALTER COLUMN user_id DROP NOT NULL;

ALTER TABLE assistant_tools
ALTER COLUMN user_id DROP NOT NULL;

ALTER TABLE tools
ALTER COLUMN user_id DROP NOT NULL;

CREATE POLICY "Allow read access to public assistant_files"
ON assistant_files
FOR SELECT
USING (user_id IS NULL);

CREATE POLICY "Allow read access to public assistant_collections"
ON assistant_collections
FOR SELECT
USING (user_id IS NULL);

CREATE POLICY "Allow read access to public assistant_tools"
ON assistant_tools
FOR SELECT
USING (user_id IS NULL);
Loading