From 74a3220e9fa18a13fd1b28f55b2079059d2ec266 Mon Sep 17 00:00:00 2001 From: Boris Date: Thu, 11 Sep 2025 16:16:03 +0200 Subject: [PATCH] fix: graph view with search (#1368) ## Description ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin. --- .../45957f0a9849_add_notebook_table.py | 46 ++++++++ .../src/app/dashboard/AddDataToCognee.tsx | 3 +- .../src/app/dashboard/Dashboard.tsx | 24 +++- .../dashboard/InstanceDatasetsAccordion.tsx | 29 +++-- cognee-frontend/src/app/dashboard/page.tsx | 12 +- cognee-frontend/src/app/page.tsx | 4 +- cognee-frontend/src/modules/auth/getUser.ts | 6 + cognee-frontend/src/modules/auth/index.ts | 2 +- cognee-frontend/src/modules/auth/types.ts | 2 +- .../src/modules/auth/useAuthenticatedUser.ts | 2 +- .../src/modules/cloud/checkCloudConnection.ts | 5 +- .../src/modules/notebooks/useNotebooks.ts | 67 +++++------ cognee-frontend/src/ui/Layout/Header.tsx | 15 ++- .../src/ui/elements/Notebook/Notebook.tsx | 109 ++++++++++-------- .../elements/Notebook/NotebookCellHeader.tsx | 24 ++-- cognee-frontend/src/utils/fetch.ts | 13 ++- cognee-frontend/src/utils/index.ts | 1 + .../src/utils/isCloudEnvironment.ts | 4 + .../notebooks/routers/get_notebooks_router.py | 3 +- cognee/infrastructure/utils/run_sync.py | 9 +- .../operations/run_in_local_sandbox.py | 14 --- .../utils/brute_force_triplet_search.py | 3 +- cognee/modules/search/methods/search.py | 8 +- .../search/utils/prepare_search_result.py | 4 +- 24 files changed, 268 insertions(+), 141 deletions(-) create mode 100644 alembic/versions/45957f0a9849_add_notebook_table.py create mode 100644 cognee-frontend/src/modules/auth/getUser.ts create mode 100644 cognee-frontend/src/utils/isCloudEnvironment.ts diff --git a/alembic/versions/45957f0a9849_add_notebook_table.py b/alembic/versions/45957f0a9849_add_notebook_table.py new file mode 100644 index 000000000..ded7ccd9c --- /dev/null +++ b/alembic/versions/45957f0a9849_add_notebook_table.py @@ -0,0 +1,46 @@ +"""Add notebook table + +Revision ID: 45957f0a9849 +Revises: 9e7a3cb85175 +Create Date: 2025-09-10 17:47:58.201319 + +""" + +from datetime import datetime, timezone +from uuid import uuid4 +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "45957f0a9849" +down_revision: Union[str, None] = "9e7a3cb85175" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + bind = op.get_bind() + inspector = sa.inspect(bind) + + if "notebooks" not in inspector.get_table_names(): + # Define table with all necessary columns including primary key + op.create_table( + "notebooks", + sa.Column("id", sa.UUID, primary_key=True, default=uuid4), # Critical for SQLite + sa.Column("owner_id", sa.UUID, index=True), + sa.Column("name", sa.String(), nullable=False), + sa.Column("cells", sa.JSON(), nullable=False), + sa.Column("deletable", sa.Boolean(), default=True), + sa.Column("created_at", sa.DateTime(), default=lambda: datetime.now(timezone.utc)), + ) + + +def downgrade() -> None: + bind = op.get_bind() + inspector = sa.inspect(bind) + + if "notebooks" in inspector.get_table_names(): + op.drop_table("notebooks") diff --git a/cognee-frontend/src/app/dashboard/AddDataToCognee.tsx b/cognee-frontend/src/app/dashboard/AddDataToCognee.tsx index a74547b5e..4f9a3179e 100644 --- a/cognee-frontend/src/app/dashboard/AddDataToCognee.tsx +++ b/cognee-frontend/src/app/dashboard/AddDataToCognee.tsx @@ -39,7 +39,8 @@ export default function AddDataToCognee({ datasets, refreshDatasets, useCloud = } : { name: "main_dataset", }, - Array.from(filesForUpload) + Array.from(filesForUpload), + useCloud ) .then(({ dataset_id, dataset_name }) => { refreshDatasets(); diff --git a/cognee-frontend/src/app/dashboard/Dashboard.tsx b/cognee-frontend/src/app/dashboard/Dashboard.tsx index a785f8e00..97576f3b4 100644 --- a/cognee-frontend/src/app/dashboard/Dashboard.tsx +++ b/cognee-frontend/src/app/dashboard/Dashboard.tsx @@ -5,16 +5,31 @@ import { useCallback, useEffect, useRef, useState } from "react"; import { Header } from "@/ui/Layout"; import { SearchIcon } from "@/ui/Icons"; import { Notebook } from "@/ui/elements"; +import { fetch, isCloudEnvironment } from "@/utils"; import { Notebook as NotebookType } from "@/ui/elements/Notebook/types"; +import { useAuthenticatedUser } from "@/modules/auth"; import { Dataset } from "@/modules/ingestion/useDatasets"; import useNotebooks from "@/modules/notebooks/useNotebooks"; +import AddDataToCognee from "./AddDataToCognee"; import NotebooksAccordion from "./NotebooksAccordion"; import CogneeInstancesAccordion from "./CogneeInstancesAccordion"; -import AddDataToCognee from "./AddDataToCognee"; import InstanceDatasetsAccordion from "./InstanceDatasetsAccordion"; -export default function Dashboard() { +interface DashboardProps { + user?: { + id: string; + name: string; + email: string; + picture: string; + }; + accessToken: string; +} + +export default function Dashboard({ accessToken }: DashboardProps) { + fetch.setAccessToken(accessToken); + const { user } = useAuthenticatedUser(); + const { notebooks, refreshNotebooks, @@ -91,6 +106,8 @@ export default function Dashboard() { setDatasets(datasets); }, []); + const isCloudEnv = isCloudEnvironment(); + return (