From a29684aeef87909883d1810ca39c80d04cfc6caa Mon Sep 17 00:00:00 2001 From: Ariel Scarpinelli Date: Thu, 11 Sep 2025 15:31:42 -0300 Subject: [PATCH 1/2] feat: support system-wide assistants --- app/[locale]/[workspaceid]/layout.tsx | 11 +- components/chat/chat-files-display.tsx | 2 +- .../chat/chat-hooks/use-chat-handler.tsx | 6 +- .../chat-hooks/use-prompt-and-command.tsx | 6 +- components/chat/chat-ui.tsx | 3 +- components/chat/quick-settings.tsx | 5 +- components/messages/message.tsx | 8 +- db/assistants.ts | 13 + db/collection-files.ts | 2 +- .../20251109105000_system_assistants.sql | 42 + supabase/types.ts | 822 +++++++++++------- types/chat-file.tsx | 2 + 12 files changed, 600 insertions(+), 322 deletions(-) create mode 100644 supabase/migrations/20251109105000_system_assistants.sql diff --git a/app/[locale]/[workspaceid]/layout.tsx b/app/[locale]/[workspaceid]/layout.tsx index 227a6e7903..5d8d744878 100644 --- a/app/[locale]/[workspaceid]/layout.tsx +++ b/app/[locale]/[workspaceid]/layout.tsx @@ -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" @@ -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) { diff --git a/components/chat/chat-files-display.tsx b/components/chat/chat-files-display.tsx index a0675053c8..9b630c465c 100644 --- a/components/chat/chat-files-display.tsx +++ b/components/chat/chat-files-display.tsx @@ -58,7 +58,7 @@ export const ChatFilesDisplay: FC = ({}) => { ...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] diff --git a/components/chat/chat-hooks/use-chat-handler.tsx b/components/chat/chat-hooks/use-chat-handler.tsx index f5ab04a25a..c318685bc3 100644 --- a/components/chat/chat-hooks/use-chat-handler.tsx +++ b/components/chat/chat-hooks/use-chat-handler.tsx @@ -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, diff --git a/components/chat/chat-hooks/use-prompt-and-command.tsx b/components/chat/chat-hooks/use-prompt-and-command.tsx index aaa19250e5..e584199bff 100644 --- a/components/chat/chat-hooks/use-prompt-and-command.tsx +++ b/components/chat/chat-hooks/use-prompt-and-command.tsx @@ -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 { diff --git a/components/chat/chat-ui.tsx b/components/chat/chat-ui.tsx index ac9f13d3c2..518b2ed890 100644 --- a/components/chat/chat-ui.tsx +++ b/components/chat/chat-ui.tsx @@ -129,7 +129,8 @@ export const ChatUI: FC = ({}) => { id: file.id, name: file.name, type: file.type, - file: null + file: null, + description: file.description })) ) diff --git a/components/chat/quick-settings.tsx b/components/chat/quick-settings.tsx index 6eb5cabef4..f7952dff25 100644 --- a/components/chat/quick-settings.tsx +++ b/components/chat/quick-settings.tsx @@ -88,10 +88,11 @@ export const QuickSettings: FC = ({}) => { 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) { diff --git a/components/messages/message.tsx b/components/messages/message.tsx index d0867d68ab..f41bec7340 100644 --- a/components/messages/message.tsx +++ b/components/messages/message.tsx @@ -58,7 +58,7 @@ export const Message: FC = ({ chatImages, assistantImages, toolInUse, - files, + chatFiles, models } = useContext(ChatbotUIContext) @@ -162,7 +162,7 @@ export const Message: FC = ({ > = {} 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] = { @@ -170,7 +170,7 @@ export const Message: FC = ({ name: parentFile.name, count: 1, type: parentFile.type, - description: parentFile.description + description: parentFile.description || "" } } else { acc[parentFile.id].count += 1 @@ -348,7 +348,7 @@ export const Message: FC = ({ {fileItems .filter(fileItem => { - const parentFile = files.find( + const parentFile = chatFiles.find( parentFile => parentFile.id === fileItem.file_id ) return parentFile?.id === file.id diff --git a/db/assistants.ts b/db/assistants.ts index 74284dc9b6..aee57d07e0 100644 --- a/db/assistants.ts +++ b/db/assistants.ts @@ -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 ) => { diff --git a/db/collection-files.ts b/db/collection-files.ts index f802cd2257..4a167fce42 100644 --- a/db/collection-files.ts +++ b/db/collection-files.ts @@ -10,7 +10,7 @@ export const getCollectionFilesByCollectionId = async ( ` id, name, - files ( id, name, type ) + files ( id, name, type, description ) ` ) .eq("id", collectionId) diff --git a/supabase/migrations/20251109105000_system_assistants.sql b/supabase/migrations/20251109105000_system_assistants.sql new file mode 100644 index 0000000000..e396205a71 --- /dev/null +++ b/supabase/migrations/20251109105000_system_assistants.sql @@ -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); \ No newline at end of file diff --git a/supabase/types.ts b/supabase/types.ts index e54950274a..83764cb3ed 100644 --- a/supabase/types.ts +++ b/supabase/types.ts @@ -17,10 +17,10 @@ export type Database = { Functions: { graphql: { Args: { + extensions?: Json operationName?: string query?: string variables?: Json - extensions?: Json } Returns: Json } @@ -40,21 +40,21 @@ export type Database = { collection_id: string created_at: string updated_at: string | null - user_id: string + user_id: string | null } Insert: { assistant_id: string collection_id: string created_at?: string updated_at?: string | null - user_id: string + user_id?: string | null } Update: { assistant_id?: string collection_id?: string created_at?: string updated_at?: string | null - user_id?: string + user_id?: string | null } Relationships: [ { @@ -71,13 +71,6 @@ export type Database = { referencedRelation: "collections" referencedColumns: ["id"] }, - { - foreignKeyName: "assistant_collections_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } assistant_files: { @@ -86,21 +79,21 @@ export type Database = { created_at: string file_id: string updated_at: string | null - user_id: string + user_id: string | null } Insert: { assistant_id: string created_at?: string file_id: string updated_at?: string | null - user_id: string + user_id?: string | null } Update: { assistant_id?: string created_at?: string file_id?: string updated_at?: string | null - user_id?: string + user_id?: string | null } Relationships: [ { @@ -117,13 +110,6 @@ export type Database = { referencedRelation: "files" referencedColumns: ["id"] }, - { - foreignKeyName: "assistant_files_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } assistant_tools: { @@ -132,21 +118,21 @@ export type Database = { created_at: string tool_id: string updated_at: string | null - user_id: string + user_id: string | null } Insert: { assistant_id: string created_at?: string tool_id: string updated_at?: string | null - user_id: string + user_id?: string | null } Update: { assistant_id?: string created_at?: string tool_id?: string updated_at?: string | null - user_id?: string + user_id?: string | null } Relationships: [ { @@ -163,13 +149,6 @@ export type Database = { referencedRelation: "tools" referencedColumns: ["id"] }, - { - foreignKeyName: "assistant_tools_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } assistant_workspaces: { @@ -202,13 +181,6 @@ export type Database = { referencedRelation: "assistants" referencedColumns: ["id"] }, - { - foreignKeyName: "assistant_workspaces_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, { foreignKeyName: "assistant_workspaces_workspace_id_fkey" columns: ["workspace_id"] @@ -235,7 +207,7 @@ export type Database = { sharing: string temperature: number updated_at: string | null - user_id: string + user_id: string | null } Insert: { context_length: number @@ -253,7 +225,7 @@ export type Database = { sharing?: string temperature: number updated_at?: string | null - user_id: string + user_id?: string | null } Update: { context_length?: number @@ -271,7 +243,7 @@ export type Database = { sharing?: string temperature?: number updated_at?: string | null - user_id?: string + user_id?: string | null } Relationships: [ { @@ -281,13 +253,6 @@ export type Database = { referencedRelation: "folders" referencedColumns: ["id"] }, - { - foreignKeyName: "assistants_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } chat_files: { @@ -327,13 +292,6 @@ export type Database = { referencedRelation: "files" referencedColumns: ["id"] }, - { - foreignKeyName: "chat_files_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } chats: { @@ -406,13 +364,6 @@ export type Database = { referencedRelation: "folders" referencedColumns: ["id"] }, - { - foreignKeyName: "chats_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, { foreignKeyName: "chats_workspace_id_fkey" columns: ["workspace_id"] @@ -459,13 +410,6 @@ export type Database = { referencedRelation: "files" referencedColumns: ["id"] }, - { - foreignKeyName: "collection_files_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } collection_workspaces: { @@ -498,13 +442,6 @@ export type Database = { referencedRelation: "collections" referencedColumns: ["id"] }, - { - foreignKeyName: "collection_workspaces_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, { foreignKeyName: "collection_workspaces_workspace_id_fkey" columns: ["workspace_id"] @@ -523,7 +460,7 @@ export type Database = { name: string sharing: string updated_at: string | null - user_id: string + user_id: string | null } Insert: { created_at?: string @@ -533,7 +470,7 @@ export type Database = { name: string sharing?: string updated_at?: string | null - user_id: string + user_id?: string | null } Update: { created_at?: string @@ -543,7 +480,7 @@ export type Database = { name?: string sharing?: string updated_at?: string | null - user_id?: string + user_id?: string | null } Relationships: [ { @@ -553,15 +490,29 @@ export type Database = { referencedRelation: "folders" referencedColumns: ["id"] }, - { - foreignKeyName: "collections_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } + documents: { + Row: { + content: string + embedding: string + langchain_id: string + langchain_metadata: Json | null + } + Insert: { + content: string + embedding: string + langchain_id: string + langchain_metadata?: Json | null + } + Update: { + content?: string + embedding?: string + langchain_id?: string + langchain_metadata?: Json | null + } + Relationships: [] + } file_items: { Row: { content: string @@ -569,11 +520,12 @@ export type Database = { file_id: string id: string local_embedding: string | null + metadata: Json | null openai_embedding: string | null sharing: string tokens: number updated_at: string | null - user_id: string + user_id: string | null } Insert: { content: string @@ -581,11 +533,12 @@ export type Database = { file_id: string id?: string local_embedding?: string | null + metadata?: Json | null openai_embedding?: string | null sharing?: string tokens: number updated_at?: string | null - user_id: string + user_id?: string | null } Update: { content?: string @@ -593,11 +546,12 @@ export type Database = { file_id?: string id?: string local_embedding?: string | null + metadata?: Json | null openai_embedding?: string | null sharing?: string tokens?: number updated_at?: string | null - user_id?: string + user_id?: string | null } Relationships: [ { @@ -607,13 +561,6 @@ export type Database = { referencedRelation: "files" referencedColumns: ["id"] }, - { - foreignKeyName: "file_items_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } file_workspaces: { @@ -646,13 +593,6 @@ export type Database = { referencedRelation: "files" referencedColumns: ["id"] }, - { - foreignKeyName: "file_workspaces_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, { foreignKeyName: "file_workspaces_workspace_id_fkey" columns: ["workspace_id"] @@ -675,7 +615,7 @@ export type Database = { tokens: number type: string updated_at: string | null - user_id: string + user_id: string | null } Insert: { created_at?: string @@ -689,7 +629,7 @@ export type Database = { tokens: number type: string updated_at?: string | null - user_id: string + user_id?: string | null } Update: { created_at?: string @@ -703,7 +643,7 @@ export type Database = { tokens?: number type?: string updated_at?: string | null - user_id?: string + user_id?: string | null } Relationships: [ { @@ -713,13 +653,6 @@ export type Database = { referencedRelation: "folders" referencedColumns: ["id"] }, - { - foreignKeyName: "files_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } folders: { @@ -754,13 +687,6 @@ export type Database = { workspace_id?: string } Relationships: [ - { - foreignKeyName: "folders_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, { foreignKeyName: "folders_workspace_id_fkey" columns: ["workspace_id"] @@ -807,13 +733,6 @@ export type Database = { referencedRelation: "messages" referencedColumns: ["id"] }, - { - foreignKeyName: "message_file_items_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } messages: { @@ -871,13 +790,6 @@ export type Database = { referencedRelation: "chats" referencedColumns: ["id"] }, - { - foreignKeyName: "messages_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } model_workspaces: { @@ -910,13 +822,6 @@ export type Database = { referencedRelation: "models" referencedColumns: ["id"] }, - { - foreignKeyName: "model_workspaces_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, { foreignKeyName: "model_workspaces_workspace_id_fkey" columns: ["workspace_id"] @@ -977,13 +882,6 @@ export type Database = { referencedRelation: "folders" referencedColumns: ["id"] }, - { - foreignKeyName: "models_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } preset_workspaces: { @@ -1016,13 +914,6 @@ export type Database = { referencedRelation: "presets" referencedColumns: ["id"] }, - { - foreignKeyName: "preset_workspaces_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, { foreignKeyName: "preset_workspaces_workspace_id_fkey" columns: ["workspace_id"] @@ -1092,13 +983,6 @@ export type Database = { referencedRelation: "folders" referencedColumns: ["id"] }, - { - foreignKeyName: "presets_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } profiles: { @@ -1186,15 +1070,7 @@ export type Database = { user_id?: string username?: string } - Relationships: [ - { - foreignKeyName: "profiles_user_id_fkey" - columns: ["user_id"] - isOneToOne: true - referencedRelation: "users" - referencedColumns: ["id"] - }, - ] + Relationships: [] } prompt_workspaces: { Row: { @@ -1226,13 +1102,6 @@ export type Database = { referencedRelation: "prompts" referencedColumns: ["id"] }, - { - foreignKeyName: "prompt_workspaces_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, { foreignKeyName: "prompt_workspaces_workspace_id_fkey" columns: ["workspace_id"] @@ -1281,13 +1150,6 @@ export type Database = { referencedRelation: "folders" referencedColumns: ["id"] }, - { - foreignKeyName: "prompts_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } tool_workspaces: { @@ -1320,13 +1182,6 @@ export type Database = { referencedRelation: "tools" referencedColumns: ["id"] }, - { - foreignKeyName: "tool_workspaces_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, { foreignKeyName: "tool_workspaces_workspace_id_fkey" columns: ["workspace_id"] @@ -1348,7 +1203,7 @@ export type Database = { sharing: string updated_at: string | null url: string - user_id: string + user_id: string | null } Insert: { created_at?: string @@ -1361,7 +1216,7 @@ export type Database = { sharing?: string updated_at?: string | null url: string - user_id: string + user_id?: string | null } Update: { created_at?: string @@ -1374,7 +1229,7 @@ export type Database = { sharing?: string updated_at?: string | null url?: string - user_id?: string + user_id?: string | null } Relationships: [ { @@ -1384,13 +1239,6 @@ export type Database = { referencedRelation: "folders" referencedColumns: ["id"] }, - { - foreignKeyName: "tools_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, ] } workspaces: { @@ -1451,15 +1299,7 @@ export type Database = { updated_at?: string | null user_id?: string } - Relationships: [ - { - foreignKeyName: "workspaces_user_id_fkey" - columns: ["user_id"] - isOneToOne: false - referencedRelation: "users" - referencedColumns: ["id"] - }, - ] + Relationships: [] } } Views: { @@ -1467,87 +1307,71 @@ export type Database = { } Functions: { create_duplicate_messages_for_new_chat: { - Args: { - old_chat_id: string - new_chat_id: string - new_user_id: string - } + Args: { new_chat_id: string; new_user_id: string; old_chat_id: string } Returns: undefined } delete_message_including_and_after: { Args: { - p_user_id: string p_chat_id: string p_sequence_number: number + p_user_id: string } Returns: undefined } delete_messages_including_and_after: { Args: { - p_user_id: string p_chat_id: string p_sequence_number: number + p_user_id: string } Returns: undefined } delete_storage_object: { - Args: { - bucket: string - object: string - } + Args: { bucket: string; object: string } Returns: Record } delete_storage_object_from_bucket: { - Args: { - bucket_name: string - object_path: string - } + Args: { bucket_name: string; object_path: string } Returns: Record } match_file_items_local: { Args: { - query_embedding: string - match_count?: number file_ids?: string[] + match_count?: number + query_embedding: string } Returns: { - id: string - file_id: string content: string - tokens: number + file_id: string + id: string similarity: number + tokens: number }[] } match_file_items_openai: { Args: { - query_embedding: string - match_count?: number file_ids?: string[] + match_count?: number + query_embedding: string } Returns: { - id: string - file_id: string content: string - tokens: number + file_id: string + id: string similarity: number + tokens: number }[] } non_private_assistant_exists: { - Args: { - p_name: string - } + Args: { p_name: string } Returns: boolean } non_private_file_exists: { - Args: { - p_name: string - } + Args: { p_name: string } Returns: boolean } non_private_workspace_exists: { - Args: { - p_name: string - } + Args: { p_name: string } Returns: boolean } } @@ -1571,6 +1395,7 @@ export type Database = { owner: string | null owner_id: string | null public: boolean | null + type: Database["storage"]["Enums"]["buckettype"] updated_at: string | null } Insert: { @@ -1583,6 +1408,7 @@ export type Database = { owner?: string | null owner_id?: string | null public?: boolean | null + type?: Database["storage"]["Enums"]["buckettype"] updated_at?: string | null } Update: { @@ -1595,10 +1421,112 @@ export type Database = { owner?: string | null owner_id?: string | null public?: boolean | null + type?: Database["storage"]["Enums"]["buckettype"] updated_at?: string | null } Relationships: [] } + buckets_analytics: { + Row: { + created_at: string + format: string + id: string + type: Database["storage"]["Enums"]["buckettype"] + updated_at: string + } + Insert: { + created_at?: string + format?: string + id: string + type?: Database["storage"]["Enums"]["buckettype"] + updated_at?: string + } + Update: { + created_at?: string + format?: string + id?: string + type?: Database["storage"]["Enums"]["buckettype"] + updated_at?: string + } + Relationships: [] + } + iceberg_namespaces: { + Row: { + bucket_id: string + created_at: string + id: string + name: string + updated_at: string + } + Insert: { + bucket_id: string + created_at?: string + id?: string + name: string + updated_at?: string + } + Update: { + bucket_id?: string + created_at?: string + id?: string + name?: string + updated_at?: string + } + Relationships: [ + { + foreignKeyName: "iceberg_namespaces_bucket_id_fkey" + columns: ["bucket_id"] + isOneToOne: false + referencedRelation: "buckets_analytics" + referencedColumns: ["id"] + }, + ] + } + iceberg_tables: { + Row: { + bucket_id: string + created_at: string + id: string + location: string + name: string + namespace_id: string + updated_at: string + } + Insert: { + bucket_id: string + created_at?: string + id?: string + location: string + name: string + namespace_id: string + updated_at?: string + } + Update: { + bucket_id?: string + created_at?: string + id?: string + location?: string + name?: string + namespace_id?: string + updated_at?: string + } + Relationships: [ + { + foreignKeyName: "iceberg_tables_bucket_id_fkey" + columns: ["bucket_id"] + isOneToOne: false + referencedRelation: "buckets_analytics" + referencedColumns: ["id"] + }, + { + foreignKeyName: "iceberg_tables_namespace_id_fkey" + columns: ["namespace_id"] + isOneToOne: false + referencedRelation: "iceberg_namespaces" + referencedColumns: ["id"] + }, + ] + } migrations: { Row: { executed_at: string | null @@ -1626,12 +1554,14 @@ export type Database = { created_at: string | null id: string last_accessed_at: string | null + level: number | null metadata: Json | null name: string | null owner: string | null owner_id: string | null path_tokens: string[] | null updated_at: string | null + user_metadata: Json | null version: string | null } Insert: { @@ -1639,12 +1569,14 @@ export type Database = { created_at?: string | null id?: string last_accessed_at?: string | null + level?: number | null metadata?: Json | null name?: string | null owner?: string | null owner_id?: string | null path_tokens?: string[] | null updated_at?: string | null + user_metadata?: Json | null version?: string | null } Update: { @@ -1652,12 +1584,14 @@ export type Database = { created_at?: string | null id?: string last_accessed_at?: string | null + level?: number | null metadata?: Json | null name?: string | null owner?: string | null owner_id?: string | null path_tokens?: string[] | null updated_at?: string | null + user_metadata?: Json | null version?: string | null } Relationships: [ @@ -1670,68 +1604,299 @@ export type Database = { }, ] } + prefixes: { + Row: { + bucket_id: string + created_at: string | null + level: number + name: string + updated_at: string | null + } + Insert: { + bucket_id: string + created_at?: string | null + level?: number + name: string + updated_at?: string | null + } + Update: { + bucket_id?: string + created_at?: string | null + level?: number + name?: string + updated_at?: string | null + } + Relationships: [ + { + foreignKeyName: "prefixes_bucketId_fkey" + columns: ["bucket_id"] + isOneToOne: false + referencedRelation: "buckets" + referencedColumns: ["id"] + }, + ] + } + s3_multipart_uploads: { + Row: { + bucket_id: string + created_at: string + id: string + in_progress_size: number + key: string + owner_id: string | null + upload_signature: string + user_metadata: Json | null + version: string + } + Insert: { + bucket_id: string + created_at?: string + id: string + in_progress_size?: number + key: string + owner_id?: string | null + upload_signature: string + user_metadata?: Json | null + version: string + } + Update: { + bucket_id?: string + created_at?: string + id?: string + in_progress_size?: number + key?: string + owner_id?: string | null + upload_signature?: string + user_metadata?: Json | null + version?: string + } + Relationships: [ + { + foreignKeyName: "s3_multipart_uploads_bucket_id_fkey" + columns: ["bucket_id"] + isOneToOne: false + referencedRelation: "buckets" + referencedColumns: ["id"] + }, + ] + } + s3_multipart_uploads_parts: { + Row: { + bucket_id: string + created_at: string + etag: string + id: string + key: string + owner_id: string | null + part_number: number + size: number + upload_id: string + version: string + } + Insert: { + bucket_id: string + created_at?: string + etag: string + id?: string + key: string + owner_id?: string | null + part_number: number + size?: number + upload_id: string + version: string + } + Update: { + bucket_id?: string + created_at?: string + etag?: string + id?: string + key?: string + owner_id?: string | null + part_number?: number + size?: number + upload_id?: string + version?: string + } + Relationships: [ + { + foreignKeyName: "s3_multipart_uploads_parts_bucket_id_fkey" + columns: ["bucket_id"] + isOneToOne: false + referencedRelation: "buckets" + referencedColumns: ["id"] + }, + { + foreignKeyName: "s3_multipart_uploads_parts_upload_id_fkey" + columns: ["upload_id"] + isOneToOne: false + referencedRelation: "s3_multipart_uploads" + referencedColumns: ["id"] + }, + ] + } } Views: { [_ in never]: never } Functions: { + add_prefixes: { + Args: { _bucket_id: string; _name: string } + Returns: undefined + } can_insert_object: { - Args: { - bucketid: string - name: string - owner: string - metadata: Json - } + Args: { bucketid: string; metadata: Json; name: string; owner: string } Returns: undefined } + delete_prefix: { + Args: { _bucket_id: string; _name: string } + Returns: boolean + } extension: { - Args: { - name: string - } + Args: { name: string } Returns: string } filename: { - Args: { - name: string - } + Args: { name: string } Returns: string } foldername: { - Args: { - name: string - } + Args: { name: string } + Returns: string[] + } + get_level: { + Args: { name: string } + Returns: number + } + get_prefix: { + Args: { name: string } + Returns: string + } + get_prefixes: { + Args: { name: string } Returns: string[] } get_size_by_bucket: { Args: Record Returns: { + bucket_id: string size: number + }[] + } + list_multipart_uploads_with_delimiter: { + Args: { + bucket_id: string + delimiter_param: string + max_keys?: number + next_key_token?: string + next_upload_token?: string + prefix_param: string + } + Returns: { + created_at: string + id: string + key: string + }[] + } + list_objects_with_delimiter: { + Args: { bucket_id: string + delimiter_param: string + max_keys?: number + next_token?: string + prefix_param: string + start_after?: string + } + Returns: { + id: string + metadata: Json + name: string + updated_at: string }[] } + operation: { + Args: Record + Returns: string + } search: { Args: { - prefix: string bucketname: string - limits?: number levels?: number + limits?: number offsets?: number + prefix: string search?: string sortcolumn?: string sortorder?: string } Returns: { + created_at: string + id: string + last_accessed_at: string + metadata: Json name: string + updated_at: string + }[] + } + search_legacy_v1: { + Args: { + bucketname: string + levels?: number + limits?: number + offsets?: number + prefix: string + search?: string + sortcolumn?: string + sortorder?: string + } + Returns: { + created_at: string id: string + last_accessed_at: string + metadata: Json + name: string updated_at: string + }[] + } + search_v1_optimised: { + Args: { + bucketname: string + levels?: number + limits?: number + offsets?: number + prefix: string + search?: string + sortcolumn?: string + sortorder?: string + } + Returns: { created_at: string + id: string last_accessed_at: string metadata: Json + name: string + updated_at: string + }[] + } + search_v2: { + Args: { + bucket_name: string + levels?: number + limits?: number + prefix: string + start_after?: string + } + Returns: { + created_at: string + id: string + key: string + metadata: Json + name: string + updated_at: string }[] } } Enums: { - [_ in never]: never + buckettype: "STANDARD" | "ANALYTICS" } CompositeTypes: { [_ in never]: never @@ -1739,27 +1904,33 @@ export type Database = { } } -type PublicSchema = Database[Extract] +type DatabaseWithoutInternals = Omit + +type DefaultSchema = DatabaseWithoutInternals[Extract] export type Tables< - PublicTableNameOrOptions extends - | keyof (PublicSchema["Tables"] & PublicSchema["Views"]) - | { schema: keyof Database }, - TableName extends PublicTableNameOrOptions extends { schema: keyof Database } - ? keyof (Database[PublicTableNameOrOptions["schema"]]["Tables"] & - Database[PublicTableNameOrOptions["schema"]]["Views"]) + DefaultSchemaTableNameOrOptions extends + | keyof (DefaultSchema["Tables"] & DefaultSchema["Views"]) + | { schema: keyof DatabaseWithoutInternals }, + TableName extends DefaultSchemaTableNameOrOptions extends { + schema: keyof DatabaseWithoutInternals + } + ? keyof (DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] & + DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Views"]) : never = never, -> = PublicTableNameOrOptions extends { schema: keyof Database } - ? (Database[PublicTableNameOrOptions["schema"]]["Tables"] & - Database[PublicTableNameOrOptions["schema"]]["Views"])[TableName] extends { +> = DefaultSchemaTableNameOrOptions extends { + schema: keyof DatabaseWithoutInternals +} + ? (DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] & + DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Views"])[TableName] extends { Row: infer R } ? R : never - : PublicTableNameOrOptions extends keyof (PublicSchema["Tables"] & - PublicSchema["Views"]) - ? (PublicSchema["Tables"] & - PublicSchema["Views"])[PublicTableNameOrOptions] extends { + : DefaultSchemaTableNameOrOptions extends keyof (DefaultSchema["Tables"] & + DefaultSchema["Views"]) + ? (DefaultSchema["Tables"] & + DefaultSchema["Views"])[DefaultSchemaTableNameOrOptions] extends { Row: infer R } ? R @@ -1767,20 +1938,24 @@ export type Tables< : never export type TablesInsert< - PublicTableNameOrOptions extends - | keyof PublicSchema["Tables"] - | { schema: keyof Database }, - TableName extends PublicTableNameOrOptions extends { schema: keyof Database } - ? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"] + DefaultSchemaTableNameOrOptions extends + | keyof DefaultSchema["Tables"] + | { schema: keyof DatabaseWithoutInternals }, + TableName extends DefaultSchemaTableNameOrOptions extends { + schema: keyof DatabaseWithoutInternals + } + ? keyof DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] : never = never, -> = PublicTableNameOrOptions extends { schema: keyof Database } - ? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends { +> = DefaultSchemaTableNameOrOptions extends { + schema: keyof DatabaseWithoutInternals +} + ? DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Tables"][TableName] extends { Insert: infer I } ? I : never - : PublicTableNameOrOptions extends keyof PublicSchema["Tables"] - ? PublicSchema["Tables"][PublicTableNameOrOptions] extends { + : DefaultSchemaTableNameOrOptions extends keyof DefaultSchema["Tables"] + ? DefaultSchema["Tables"][DefaultSchemaTableNameOrOptions] extends { Insert: infer I } ? I @@ -1788,20 +1963,24 @@ export type TablesInsert< : never export type TablesUpdate< - PublicTableNameOrOptions extends - | keyof PublicSchema["Tables"] - | { schema: keyof Database }, - TableName extends PublicTableNameOrOptions extends { schema: keyof Database } - ? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"] + DefaultSchemaTableNameOrOptions extends + | keyof DefaultSchema["Tables"] + | { schema: keyof DatabaseWithoutInternals }, + TableName extends DefaultSchemaTableNameOrOptions extends { + schema: keyof DatabaseWithoutInternals + } + ? keyof DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Tables"] : never = never, -> = PublicTableNameOrOptions extends { schema: keyof Database } - ? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends { +> = DefaultSchemaTableNameOrOptions extends { + schema: keyof DatabaseWithoutInternals +} + ? DatabaseWithoutInternals[DefaultSchemaTableNameOrOptions["schema"]]["Tables"][TableName] extends { Update: infer U } ? U : never - : PublicTableNameOrOptions extends keyof PublicSchema["Tables"] - ? PublicSchema["Tables"][PublicTableNameOrOptions] extends { + : DefaultSchemaTableNameOrOptions extends keyof DefaultSchema["Tables"] + ? DefaultSchema["Tables"][DefaultSchemaTableNameOrOptions] extends { Update: infer U } ? U @@ -1809,15 +1988,50 @@ export type TablesUpdate< : never export type Enums< - PublicEnumNameOrOptions extends - | keyof PublicSchema["Enums"] - | { schema: keyof Database }, - EnumName extends PublicEnumNameOrOptions extends { schema: keyof Database } - ? keyof Database[PublicEnumNameOrOptions["schema"]]["Enums"] + DefaultSchemaEnumNameOrOptions extends + | keyof DefaultSchema["Enums"] + | { schema: keyof DatabaseWithoutInternals }, + EnumName extends DefaultSchemaEnumNameOrOptions extends { + schema: keyof DatabaseWithoutInternals + } + ? keyof DatabaseWithoutInternals[DefaultSchemaEnumNameOrOptions["schema"]]["Enums"] + : never = never, +> = DefaultSchemaEnumNameOrOptions extends { + schema: keyof DatabaseWithoutInternals +} + ? DatabaseWithoutInternals[DefaultSchemaEnumNameOrOptions["schema"]]["Enums"][EnumName] + : DefaultSchemaEnumNameOrOptions extends keyof DefaultSchema["Enums"] + ? DefaultSchema["Enums"][DefaultSchemaEnumNameOrOptions] + : never + +export type CompositeTypes< + PublicCompositeTypeNameOrOptions extends + | keyof DefaultSchema["CompositeTypes"] + | { schema: keyof DatabaseWithoutInternals }, + CompositeTypeName extends PublicCompositeTypeNameOrOptions extends { + schema: keyof DatabaseWithoutInternals + } + ? keyof DatabaseWithoutInternals[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"] : never = never, -> = PublicEnumNameOrOptions extends { schema: keyof Database } - ? Database[PublicEnumNameOrOptions["schema"]]["Enums"][EnumName] - : PublicEnumNameOrOptions extends keyof PublicSchema["Enums"] - ? PublicSchema["Enums"][PublicEnumNameOrOptions] +> = PublicCompositeTypeNameOrOptions extends { + schema: keyof DatabaseWithoutInternals +} + ? DatabaseWithoutInternals[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"][CompositeTypeName] + : PublicCompositeTypeNameOrOptions extends keyof DefaultSchema["CompositeTypes"] + ? DefaultSchema["CompositeTypes"][PublicCompositeTypeNameOrOptions] : never +export const Constants = { + graphql_public: { + Enums: {}, + }, + public: { + Enums: {}, + }, + storage: { + Enums: { + buckettype: ["STANDARD", "ANALYTICS"], + }, + }, +} as const + diff --git a/types/chat-file.tsx b/types/chat-file.tsx index 9dc4e24dfa..e11f568566 100644 --- a/types/chat-file.tsx +++ b/types/chat-file.tsx @@ -3,4 +3,6 @@ export interface ChatFile { name: string type: string file: File | null + description?: string + hidden?: boolean } From 74025e61f16598e0713389878158882c3346b8a0 Mon Sep 17 00:00:00 2001 From: Ariel Scarpinelli Date: Mon, 22 Sep 2025 09:13:01 -0300 Subject: [PATCH 2/2] fix: system assistant --- components/sidebar/items/all/sidebar-display-item.tsx | 4 ++-- components/sidebar/items/all/sidebar-update-item.tsx | 3 ++- db/assistants.ts | 4 ++-- db/collections.ts | 4 ++-- db/files.ts | 10 +++++----- db/tools.ts | 4 ++-- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/components/sidebar/items/all/sidebar-display-item.tsx b/components/sidebar/items/all/sidebar-display-item.tsx index d8f0864036..da9597b3a8 100644 --- a/components/sidebar/items/all/sidebar-display-item.tsx +++ b/components/sidebar/items/all/sidebar-display-item.tsx @@ -24,7 +24,7 @@ export const SidebarItem: FC = ({ icon, isTyping }) => { - const { selectedWorkspace, setChats, setSelectedAssistant } = + const { selectedWorkspace, setChats, setSelectedAssistant, profile } = useContext(ChatbotUIContext) const router = useRouter() @@ -43,7 +43,7 @@ export const SidebarItem: FC = ({ 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, diff --git a/components/sidebar/items/all/sidebar-update-item.tsx b/components/sidebar/items/all/sidebar-update-item.tsx index 1f8b346107..84f65607f4 100644 --- a/components/sidebar/items/all/sidebar-update-item.tsx +++ b/components/sidebar/items/all/sidebar-update-item.tsx @@ -105,6 +105,7 @@ export const SidebarUpdateItem: FC = ({ const { workspaces, selectedWorkspace, + profile, setChats, setPresets, setPrompts, @@ -392,7 +393,7 @@ export const SidebarUpdateItem: FC = ({ for (const file of filesToAdd) { await createCollectionFile({ - user_id: item.user_id, + user_id: profile.user_id, collection_id: collectionId, file_id: file.id }) diff --git a/db/assistants.ts b/db/assistants.ts index aee57d07e0..5f4f66c289 100644 --- a/db/assistants.ts +++ b/db/assistants.ts @@ -87,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 }) @@ -110,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 })) diff --git a/db/collections.ts b/db/collections.ts index 3d3a6c760f..459ef5cf8e 100644 --- a/db/collections.ts +++ b/db/collections.ts @@ -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 }) @@ -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 })) diff --git a/db/files.ts b/db/files.ts index 68ad01e343..38d96b34e3 100644 --- a/db/files.ts +++ b/db/files.ts @@ -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 }) @@ -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 }) @@ -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 })) diff --git a/db/tools.ts b/db/tools.ts index 0b6e38443a..e9db79f776 100644 --- a/db/tools.ts +++ b/db/tools.ts @@ -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 }) @@ -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 }))