fix: install nvm and node for -ui cli command (#1836)
<!-- .github/pull_request_template.md -->
## Description
<!--
Please provide a clear, human-generated description of the changes in
this PR.
DO NOT use AI-generated descriptions. We want to understand your thought
process and reasoning.
-->
## Type of Change
<!-- Please check the relevant option -->
- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Code refactoring
- [ ] Performance improvement
- [ ] Other (please specify):
## Screenshots/Videos (if applicable)
<!-- Add screenshots or videos to help explain your changes -->
## Pre-submission Checklist
<!-- Please check all boxes that apply before submitting your PR -->
- [ ] **I have tested my changes thoroughly before submitting this PR**
- [ ] **This PR contains minimal changes necessary to address the
issue/feature**
- [ ] My code follows the project's coding standards and style
guidelines
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added necessary documentation (if applicable)
- [ ] All new and existing tests pass
- [ ] I have searched existing PRs to ensure this change hasn't been
submitted already
- [ ] I have linked any relevant issues in the description
- [ ] My commits have clear and descriptive messages
## 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.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Enhanced Node.js and npm environment management for improved system
compatibility on Unix-like platforms.
* **Chores**
* Updated Next.js to v16, React to v19.2, and Auth0 SDK to v4.13.1 for
compatibility and performance improvements.
* Removed CrewAI workflow trigger component.
* Removed user feedback submission form.
<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
commit
40bbdd1ac7
18 changed files with 2141 additions and 1118 deletions
2475
cognee-frontend/package-lock.json
generated
2475
cognee-frontend/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -9,13 +9,13 @@
|
|||
"lint": "next lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@auth0/nextjs-auth0": "^4.6.0",
|
||||
"@auth0/nextjs-auth0": "^4.13.1",
|
||||
"classnames": "^2.5.1",
|
||||
"culori": "^4.0.1",
|
||||
"d3-force-3d": "^3.0.6",
|
||||
"next": "15.3.3",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"next": "16.0.4",
|
||||
"react": "^19.2.0",
|
||||
"react-dom": "^19.2.0",
|
||||
"react-force-graph-2d": "^1.27.1",
|
||||
"uuid": "^9.0.1"
|
||||
},
|
||||
|
|
@ -24,11 +24,11 @@
|
|||
"@tailwindcss/postcss": "^4.1.7",
|
||||
"@types/culori": "^4.0.0",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"@types/uuid": "^9.0.8",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "^15.3.3",
|
||||
"eslint-config-next": "^16.0.4",
|
||||
"eslint-config-prettier": "^10.1.5",
|
||||
"tailwindcss": "^4.1.7",
|
||||
"typescript": "^5"
|
||||
|
|
|
|||
|
|
@ -1,119 +0,0 @@
|
|||
import { useState } from "react";
|
||||
import { fetch } from "@/utils";
|
||||
import { v4 as uuid4 } from "uuid";
|
||||
import { LoadingIndicator } from "@/ui/App";
|
||||
import { CTAButton, Input } from "@/ui/elements";
|
||||
|
||||
interface CrewAIFormPayload extends HTMLFormElement {
|
||||
username1: HTMLInputElement;
|
||||
username2: HTMLInputElement;
|
||||
}
|
||||
|
||||
interface CrewAITriggerProps {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
onData: (data: any) => void;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
onActivity: (activities: any) => void;
|
||||
}
|
||||
|
||||
export default function CrewAITrigger({ onData, onActivity }: CrewAITriggerProps) {
|
||||
const [isCrewAIRunning, setIsCrewAIRunning] = useState(false);
|
||||
|
||||
const handleRunCrewAI = (event: React.FormEvent<CrewAIFormPayload>) => {
|
||||
event.preventDefault();
|
||||
const formElements = event.currentTarget;
|
||||
|
||||
const crewAIConfig = {
|
||||
username1: formElements.username1.value,
|
||||
username2: formElements.username2.value,
|
||||
};
|
||||
|
||||
const backendApiUrl = process.env.NEXT_PUBLIC_BACKEND_API_URL;
|
||||
const wsUrl = backendApiUrl.replace(/^http(s)?/, "ws");
|
||||
|
||||
const websocket = new WebSocket(`${wsUrl}/v1/crewai/subscribe`);
|
||||
|
||||
onActivity([{ id: uuid4(), timestamp: Date.now(), activity: "Dispatching hiring crew agents" }]);
|
||||
|
||||
websocket.onmessage = (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
|
||||
if (data.status === "PipelineRunActivity") {
|
||||
onActivity([data.payload]);
|
||||
return;
|
||||
}
|
||||
|
||||
onData({
|
||||
nodes: data.payload.nodes,
|
||||
links: data.payload.edges,
|
||||
});
|
||||
|
||||
const nodes_type_map: { [key: string]: number } = {};
|
||||
|
||||
for (let i = 0; i < data.payload.nodes.length; i++) {
|
||||
const node = data.payload.nodes[i];
|
||||
if (!nodes_type_map[node.type]) {
|
||||
nodes_type_map[node.type] = 0;
|
||||
}
|
||||
nodes_type_map[node.type] += 1;
|
||||
}
|
||||
|
||||
const activityMessage = Object.entries(nodes_type_map).reduce((message, [type, count]) => {
|
||||
return `${message}\n | ${type}: ${count}`;
|
||||
}, "Graph updated:");
|
||||
|
||||
onActivity([{
|
||||
id: uuid4(),
|
||||
timestamp: Date.now(),
|
||||
activity: activityMessage,
|
||||
}]);
|
||||
|
||||
if (data.status === "PipelineRunCompleted") {
|
||||
websocket.close();
|
||||
}
|
||||
};
|
||||
|
||||
onData(null);
|
||||
setIsCrewAIRunning(true);
|
||||
|
||||
return fetch("/v1/crewai/run", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(crewAIConfig),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(() => {
|
||||
onActivity([{ id: uuid4(), timestamp: Date.now(), activity: "Hiring crew agents made a decision" }]);
|
||||
})
|
||||
.catch(() => {
|
||||
onActivity([{ id: uuid4(), timestamp: Date.now(), activity: "Hiring crew agents had problems while executing" }]);
|
||||
})
|
||||
.finally(() => {
|
||||
websocket.close();
|
||||
setIsCrewAIRunning(false);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<form className="w-full flex flex-col gap-2" onSubmit={handleRunCrewAI}>
|
||||
<h1 className="text-2xl text-white">Cognee Dev Mexican Standoff</h1>
|
||||
<span className="text-white">Agents compare GitHub profiles, and make a decision who is a better developer</span>
|
||||
<div className="flex flex-row gap-2">
|
||||
<div className="flex flex-col w-full flex-1/2">
|
||||
<label className="block mb-1 text-white" htmlFor="username1">GitHub username</label>
|
||||
<Input name="username1" type="text" placeholder="Github Username" required defaultValue="hajdul88" />
|
||||
</div>
|
||||
<div className="flex flex-col w-full flex-1/2">
|
||||
<label className="block mb-1 text-white" htmlFor="username2">GitHub username</label>
|
||||
<Input name="username2" type="text" placeholder="Github Username" required defaultValue="lxobr" />
|
||||
</div>
|
||||
</div>
|
||||
<CTAButton type="submit" disabled={isCrewAIRunning} className="whitespace-nowrap">
|
||||
Start Mexican Standoff
|
||||
{isCrewAIRunning && <LoadingIndicator />}
|
||||
</CTAButton>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@ import { NodeObject, LinkObject } from "react-force-graph-2d";
|
|||
import { ChangeEvent, useEffect, useImperativeHandle, useRef, useState } from "react";
|
||||
|
||||
import { DeleteIcon } from "@/ui/Icons";
|
||||
// import { FeedbackForm } from "@/ui/Partials";
|
||||
import { CTAButton, Input, NeutralButton, Select } from "@/ui/elements";
|
||||
|
||||
interface GraphControlsProps {
|
||||
|
|
@ -111,7 +110,7 @@ export default function GraphControls({ data, isAddNodeFormOpen, onGraphShapeCha
|
|||
};
|
||||
|
||||
const [isAuthShapeChangeEnabled, setIsAuthShapeChangeEnabled] = useState(true);
|
||||
const shapeChangeTimeout = useRef<number | null>();
|
||||
const shapeChangeTimeout = useRef<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
onGraphShapeChange(DEFAULT_GRAPH_SHAPE);
|
||||
|
|
@ -230,12 +229,6 @@ export default function GraphControls({ data, isAddNodeFormOpen, onGraphShapeCha
|
|||
)}
|
||||
</>
|
||||
{/* )} */}
|
||||
|
||||
{/* {selectedTab === "feedback" && (
|
||||
<div className="flex flex-col gap-2">
|
||||
<FeedbackForm onSuccess={() => {}} />
|
||||
</div>
|
||||
)} */}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use client";
|
||||
|
||||
import { useCallback, useRef, useState, MutableRefObject } from "react";
|
||||
import { useCallback, useRef, useState, RefObject } from "react";
|
||||
|
||||
import Link from "next/link";
|
||||
import { TextLogo } from "@/ui/App";
|
||||
|
|
@ -47,11 +47,11 @@ export default function GraphView() {
|
|||
updateData(newData);
|
||||
}, []);
|
||||
|
||||
const graphRef = useRef<GraphVisualizationAPI>();
|
||||
const graphRef = useRef<GraphVisualizationAPI>(null);
|
||||
|
||||
const graphControls = useRef<GraphControlsAPI>();
|
||||
const graphControls = useRef<GraphControlsAPI>(null);
|
||||
|
||||
const activityLog = useRef<ActivityLogAPI>();
|
||||
const activityLog = useRef<ActivityLogAPI>(null);
|
||||
|
||||
return (
|
||||
<main className="flex flex-col h-full">
|
||||
|
|
@ -74,21 +74,18 @@ export default function GraphView() {
|
|||
<div className="w-full h-full relative overflow-hidden">
|
||||
<GraphVisualization
|
||||
key={data?.nodes.length}
|
||||
ref={graphRef as MutableRefObject<GraphVisualizationAPI>}
|
||||
ref={graphRef as RefObject<GraphVisualizationAPI>}
|
||||
data={data}
|
||||
graphControls={graphControls as MutableRefObject<GraphControlsAPI>}
|
||||
graphControls={graphControls as RefObject<GraphControlsAPI>}
|
||||
/>
|
||||
|
||||
<div className="absolute top-2 left-2 flex flex-col gap-2">
|
||||
<div className="bg-gray-500 pt-4 pr-4 pb-4 pl-4 rounded-md w-sm">
|
||||
<CogneeAddWidget onData={onDataChange} />
|
||||
</div>
|
||||
{/* <div className="bg-gray-500 pt-4 pr-4 pb-4 pl-4 rounded-md w-sm">
|
||||
<CrewAITrigger onData={onDataChange} onActivity={(activities) => activityLog.current?.updateActivityLog(activities)} />
|
||||
</div> */}
|
||||
<div className="bg-gray-500 pt-4 pr-4 pb-4 pl-4 rounded-md w-sm">
|
||||
<h2 className="text-xl text-white mb-4">Activity Log</h2>
|
||||
<ActivityLog ref={activityLog as MutableRefObject<ActivityLogAPI>} />
|
||||
<ActivityLog ref={activityLog as RefObject<ActivityLogAPI>} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -96,7 +93,7 @@ export default function GraphView() {
|
|||
<div className="bg-gray-500 pt-4 pr-4 pb-4 pl-4 rounded-md w-110">
|
||||
<GraphControls
|
||||
data={data}
|
||||
ref={graphControls as MutableRefObject<GraphControlsAPI>}
|
||||
ref={graphControls as RefObject<GraphControlsAPI>}
|
||||
isAddNodeFormOpen={isAddNodeFormOpen}
|
||||
onFitIntoView={() => graphRef.current!.zoomToFit(1000, 50)}
|
||||
onGraphShapeChange={(shape) => graphRef.current!.setGraphShape(shape)}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"use client";
|
||||
|
||||
import classNames from "classnames";
|
||||
import { MutableRefObject, useEffect, useImperativeHandle, useRef, useState, useCallback } from "react";
|
||||
import { RefObject, useEffect, useImperativeHandle, useRef, useState, useCallback } from "react";
|
||||
import { forceCollide, forceManyBody } from "d3-force-3d";
|
||||
import dynamic from "next/dynamic";
|
||||
import { GraphControlsAPI } from "./GraphControls";
|
||||
|
|
@ -16,9 +16,9 @@ const ForceGraph = dynamic(() => import("react-force-graph-2d"), {
|
|||
import type { ForceGraphMethods, GraphData, LinkObject, NodeObject } from "react-force-graph-2d";
|
||||
|
||||
interface GraphVisuzaliationProps {
|
||||
ref: MutableRefObject<GraphVisualizationAPI>;
|
||||
ref: RefObject<GraphVisualizationAPI>;
|
||||
data?: GraphData<NodeObject, LinkObject>;
|
||||
graphControls: MutableRefObject<GraphControlsAPI>;
|
||||
graphControls: RefObject<GraphControlsAPI>;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
|
|
@ -205,7 +205,7 @@ export default function GraphVisualization({ ref, data, graphControls, className
|
|||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function handleDagError(loopNodeIds: (string | number)[]) {}
|
||||
|
||||
const graphRef = useRef<ForceGraphMethods>();
|
||||
const graphRef = useRef<ForceGraphMethods>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (data && graphRef.current) {
|
||||
|
|
@ -224,6 +224,7 @@ export default function GraphVisualization({ ref, data, graphControls, className
|
|||
) => {
|
||||
if (!graphRef.current) {
|
||||
console.warn("GraphVisualization: graphRef not ready yet");
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return undefined as any;
|
||||
}
|
||||
|
||||
|
|
@ -239,7 +240,7 @@ export default function GraphVisualization({ ref, data, graphControls, className
|
|||
return (
|
||||
<div ref={containerRef} className={classNames("w-full h-full", className)} id="graph-container">
|
||||
<ForceGraph
|
||||
ref={graphRef}
|
||||
ref={graphRef as RefObject<ForceGraphMethods>}
|
||||
width={dimensions.width}
|
||||
height={dimensions.height}
|
||||
dagMode={graphShape as unknown as undefined}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
"use server";
|
||||
"use client";
|
||||
|
||||
import Dashboard from "./Dashboard";
|
||||
|
||||
export default async function Page() {
|
||||
export default function Page() {
|
||||
const accessToken = "";
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
export { default } from "./dashboard/page";
|
||||
|
||||
// export const dynamic = "force-dynamic";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ export interface Dataset {
|
|||
|
||||
function useDatasets(useCloud = false) {
|
||||
const [datasets, setDatasets] = useState<Dataset[]>([]);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
// const statusTimeout = useRef<any>(null);
|
||||
|
||||
// const fetchDatasetStatuses = useCallback((datasets: Dataset[]) => {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { NextResponse, type NextRequest } from "next/server";
|
|||
// import { auth0 } from "./modules/auth/auth0";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function middleware(request: NextRequest) {
|
||||
export async function proxy(request: NextRequest) {
|
||||
// if (process.env.USE_AUTH0_AUTHORIZATION?.toLowerCase() === "true") {
|
||||
// if (request.nextUrl.pathname === "/auth/token") {
|
||||
// return NextResponse.next();
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { LoadingIndicator } from "@/ui/App";
|
||||
import { fetch, useBoolean } from "@/utils";
|
||||
import { CTAButton, TextArea } from "@/ui/elements";
|
||||
|
||||
interface SignInFormPayload extends HTMLFormElement {
|
||||
feedback: HTMLTextAreaElement;
|
||||
}
|
||||
|
||||
interface FeedbackFormProps {
|
||||
onSuccess: () => void;
|
||||
}
|
||||
|
||||
export default function FeedbackForm({ onSuccess }: FeedbackFormProps) {
|
||||
const {
|
||||
value: isSubmittingFeedback,
|
||||
setTrue: disableFeedbackSubmit,
|
||||
setFalse: enableFeedbackSubmit,
|
||||
} = useBoolean(false);
|
||||
|
||||
const [feedbackError, setFeedbackError] = useState<string | null>(null);
|
||||
|
||||
const signIn = (event: React.FormEvent<SignInFormPayload>) => {
|
||||
event.preventDefault();
|
||||
const formElements = event.currentTarget;
|
||||
|
||||
setFeedbackError(null);
|
||||
disableFeedbackSubmit();
|
||||
|
||||
fetch("/v1/crewai/feedback", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
feedback: formElements.feedback.value,
|
||||
}),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(() => {
|
||||
onSuccess();
|
||||
formElements.feedback.value = "";
|
||||
})
|
||||
.catch(error => setFeedbackError(error.detail))
|
||||
.finally(() => enableFeedbackSubmit());
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={signIn} className="flex flex-col gap-2">
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="mb-4">
|
||||
<label className="block text-white" htmlFor="feedback">Feedback on agent's reasoning</label>
|
||||
<TextArea id="feedback" name="feedback" type="text" placeholder="Your feedback" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<CTAButton type="submit">
|
||||
<span>Submit feedback</span>
|
||||
{isSubmittingFeedback && <LoadingIndicator />}
|
||||
</CTAButton>
|
||||
|
||||
{feedbackError && (
|
||||
<span className="text-s text-white">{feedbackError}</span>
|
||||
)}
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
|
@ -3,4 +3,3 @@ export { default as Footer } from "./Footer/Footer";
|
|||
export { default as SearchView } from "./SearchView/SearchView";
|
||||
export { default as IFrameView } from "./IFrameView/IFrameView";
|
||||
// export { default as Explorer } from "./Explorer/Explorer";
|
||||
export { default as FeedbackForm } from "./FeedbackForm";
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import { v4 as uuid4 } from "uuid";
|
||||
import classNames from "classnames";
|
||||
import { Fragment, MouseEvent, MutableRefObject, useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Fragment, MouseEvent, RefObject, useCallback, useEffect, useRef, useState } from "react";
|
||||
|
||||
import { useModal } from "@/ui/elements/Modal";
|
||||
import { CaretIcon, CloseIcon, PlusIcon } from "@/ui/Icons";
|
||||
|
|
@ -282,7 +282,7 @@ export default function Notebook({ notebook, updateNotebook, runCell }: Notebook
|
|||
function CellResult({ content }: { content: [] }) {
|
||||
const parsedContent = [];
|
||||
|
||||
const graphRef = useRef<GraphVisualizationAPI>();
|
||||
const graphRef = useRef<GraphVisualizationAPI>(null);
|
||||
const graphControls = useRef<GraphControlsAPI>({
|
||||
setSelectedNode: () => {},
|
||||
getSelectedNode: () => null,
|
||||
|
|
@ -298,7 +298,7 @@ function CellResult({ content }: { content: [] }) {
|
|||
<span className="text-sm pl-2 mb-4">reasoning graph</span>
|
||||
<GraphVisualization
|
||||
data={transformInsightsGraphData(line)}
|
||||
ref={graphRef as MutableRefObject<GraphVisualizationAPI>}
|
||||
ref={graphRef as RefObject<GraphVisualizationAPI>}
|
||||
graphControls={graphControls}
|
||||
className="min-h-80"
|
||||
/>
|
||||
|
|
@ -346,7 +346,7 @@ function CellResult({ content }: { content: [] }) {
|
|||
<span className="text-sm pl-2 mb-4">reasoning graph (datasets: {datasetName})</span>
|
||||
<GraphVisualization
|
||||
data={transformToVisualizationData(graph)}
|
||||
ref={graphRef as MutableRefObject<GraphVisualizationAPI>}
|
||||
ref={graphRef as RefObject<GraphVisualizationAPI>}
|
||||
graphControls={graphControls}
|
||||
className="min-h-80"
|
||||
/>
|
||||
|
|
@ -377,7 +377,7 @@ function CellResult({ content }: { content: [] }) {
|
|||
<span className="text-sm pl-2 mb-4">reasoning graph (datasets: {datasetName})</span>
|
||||
<GraphVisualization
|
||||
data={transformToVisualizationData(graph)}
|
||||
ref={graphRef as MutableRefObject<GraphVisualizationAPI>}
|
||||
ref={graphRef as RefObject<GraphVisualizationAPI>}
|
||||
graphControls={graphControls}
|
||||
className="min-h-80"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ export default function NotebookCellHeader({
|
|||
setFalse: setIsNotRunningCell,
|
||||
} = useBoolean(false);
|
||||
|
||||
const [runInstance, setRunInstance] = useState<string>(isCloudEnvironment() ? "cloud" : "local");
|
||||
const [runInstance] = useState<string>(isCloudEnvironment() ? "cloud" : "local");
|
||||
|
||||
const handleCellRun = () => {
|
||||
if (runCell) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"jsx": "react-jsx",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
|
|
@ -32,7 +32,8 @@
|
|||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts"
|
||||
".next/types/**/*.ts",
|
||||
".next/dev/types/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
|
|
|
|||
360
cognee/api/v1/ui/node_setup.py
Normal file
360
cognee/api/v1/ui/node_setup.py
Normal file
|
|
@ -0,0 +1,360 @@
|
|||
import os
|
||||
import platform
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
|
||||
from cognee.shared.logging_utils import get_logger
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
||||
def get_nvm_dir() -> Path:
|
||||
"""
|
||||
Get the nvm directory path following standard nvm installation logic.
|
||||
Uses XDG_CONFIG_HOME if set, otherwise falls back to ~/.nvm.
|
||||
"""
|
||||
xdg_config_home = os.environ.get("XDG_CONFIG_HOME")
|
||||
if xdg_config_home:
|
||||
return Path(xdg_config_home) / "nvm"
|
||||
return Path.home() / ".nvm"
|
||||
|
||||
|
||||
def get_nvm_sh_path() -> Path:
|
||||
"""
|
||||
Get the path to nvm.sh following standard nvm installation logic.
|
||||
"""
|
||||
return get_nvm_dir() / "nvm.sh"
|
||||
|
||||
|
||||
def check_nvm_installed() -> bool:
|
||||
"""
|
||||
Check if nvm (Node Version Manager) is installed.
|
||||
"""
|
||||
try:
|
||||
# Check if nvm is available in the shell
|
||||
# nvm is typically sourced in shell config files, so we need to check via shell
|
||||
if platform.system() == "Windows":
|
||||
# On Windows, nvm-windows uses a different approach
|
||||
result = subprocess.run(
|
||||
["nvm", "version"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10,
|
||||
shell=True,
|
||||
)
|
||||
else:
|
||||
# On Unix-like systems, nvm is a shell function, so we need to source it
|
||||
# First check if nvm.sh exists
|
||||
nvm_path = get_nvm_sh_path()
|
||||
if not nvm_path.exists():
|
||||
logger.debug(f"nvm.sh not found at {nvm_path}")
|
||||
return False
|
||||
|
||||
# Try to source nvm and check version, capturing errors
|
||||
result = subprocess.run(
|
||||
["bash", "-c", f"source {nvm_path} && nvm --version"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
# Log the error to help diagnose configuration issues
|
||||
if result.stderr:
|
||||
logger.debug(f"nvm check failed: {result.stderr.strip()}")
|
||||
return False
|
||||
|
||||
return result.returncode == 0
|
||||
except Exception as e:
|
||||
logger.debug(f"Exception checking nvm: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def install_nvm() -> bool:
|
||||
"""
|
||||
Install nvm (Node Version Manager) on Unix-like systems.
|
||||
"""
|
||||
if platform.system() == "Windows":
|
||||
logger.error("nvm installation on Windows requires nvm-windows.")
|
||||
logger.error(
|
||||
"Please install nvm-windows manually from: https://github.com/coreybutler/nvm-windows"
|
||||
)
|
||||
return False
|
||||
|
||||
logger.info("Installing nvm (Node Version Manager)...")
|
||||
|
||||
try:
|
||||
# Download and install nvm
|
||||
nvm_install_script = "https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh"
|
||||
logger.info(f"Downloading nvm installer from {nvm_install_script}...")
|
||||
|
||||
response = requests.get(nvm_install_script, timeout=60)
|
||||
response.raise_for_status()
|
||||
|
||||
# Create a temporary script file
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".sh", delete=False) as f:
|
||||
f.write(response.text)
|
||||
install_script_path = f.name
|
||||
|
||||
try:
|
||||
# Make the script executable and run it
|
||||
os.chmod(install_script_path, 0o755)
|
||||
result = subprocess.run(
|
||||
["bash", install_script_path],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=120,
|
||||
)
|
||||
|
||||
if result.returncode == 0:
|
||||
logger.info("✓ nvm installed successfully")
|
||||
# Source nvm in current shell session
|
||||
nvm_dir = get_nvm_dir()
|
||||
if nvm_dir.exists():
|
||||
return True
|
||||
else:
|
||||
logger.warning(
|
||||
f"nvm installation completed but nvm directory not found at {nvm_dir}"
|
||||
)
|
||||
return False
|
||||
else:
|
||||
logger.error(f"nvm installation failed: {result.stderr}")
|
||||
return False
|
||||
finally:
|
||||
# Clean up temporary script
|
||||
try:
|
||||
os.unlink(install_script_path)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error(f"Failed to download nvm installer: {str(e)}")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to install nvm: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def install_node_with_nvm() -> bool:
|
||||
"""
|
||||
Install the latest Node.js version using nvm.
|
||||
Returns True if installation succeeds, False otherwise.
|
||||
"""
|
||||
if platform.system() == "Windows":
|
||||
logger.error("Node.js installation via nvm on Windows requires nvm-windows.")
|
||||
logger.error("Please install Node.js manually from: https://nodejs.org/")
|
||||
return False
|
||||
|
||||
logger.info("Installing latest Node.js version using nvm...")
|
||||
|
||||
try:
|
||||
# Source nvm and install latest Node.js
|
||||
nvm_path = get_nvm_sh_path()
|
||||
if not nvm_path.exists():
|
||||
logger.error(f"nvm.sh not found at {nvm_path}. nvm may not be properly installed.")
|
||||
return False
|
||||
|
||||
nvm_source_cmd = f"source {nvm_path}"
|
||||
install_cmd = f"{nvm_source_cmd} && nvm install node"
|
||||
|
||||
result = subprocess.run(
|
||||
["bash", "-c", install_cmd],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=300, # 5 minutes timeout for Node.js installation
|
||||
)
|
||||
|
||||
if result.returncode == 0:
|
||||
logger.info("✓ Node.js installed successfully via nvm")
|
||||
|
||||
# Set as default version
|
||||
use_cmd = f"{nvm_source_cmd} && nvm alias default node"
|
||||
subprocess.run(
|
||||
["bash", "-c", use_cmd],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30,
|
||||
)
|
||||
|
||||
# Add nvm to PATH for current session
|
||||
# This ensures node/npm are available in subsequent commands
|
||||
nvm_dir = get_nvm_dir()
|
||||
if nvm_dir.exists():
|
||||
# Update PATH for current process
|
||||
nvm_bin = nvm_dir / "versions" / "node"
|
||||
# Find the latest installed version
|
||||
if nvm_bin.exists():
|
||||
versions = sorted(nvm_bin.iterdir(), reverse=True)
|
||||
if versions:
|
||||
latest_node_bin = versions[0] / "bin"
|
||||
if latest_node_bin.exists():
|
||||
current_path = os.environ.get("PATH", "")
|
||||
os.environ["PATH"] = f"{latest_node_bin}:{current_path}"
|
||||
|
||||
return True
|
||||
else:
|
||||
logger.error(f"Failed to install Node.js: {result.stderr}")
|
||||
return False
|
||||
|
||||
except subprocess.TimeoutExpired:
|
||||
logger.error("Timeout installing Node.js (this can take several minutes)")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"Error installing Node.js: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def check_node_npm() -> tuple[bool, str]: # (is_available, error_message)
|
||||
"""
|
||||
Check if Node.js and npm are available.
|
||||
If not available, attempts to install nvm and Node.js automatically.
|
||||
"""
|
||||
|
||||
try:
|
||||
# Check Node.js - try direct command first, then with nvm if needed
|
||||
result = subprocess.run(["node", "--version"], capture_output=True, text=True, timeout=10)
|
||||
if result.returncode != 0:
|
||||
# If direct command fails, try with nvm sourced (in case nvm is installed but not in PATH)
|
||||
nvm_path = get_nvm_sh_path()
|
||||
if nvm_path.exists():
|
||||
result = subprocess.run(
|
||||
["bash", "-c", f"source {nvm_path} && node --version"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10,
|
||||
)
|
||||
if result.returncode != 0 and result.stderr:
|
||||
logger.debug(f"Failed to source nvm or run node: {result.stderr.strip()}")
|
||||
if result.returncode != 0:
|
||||
# Node.js is not installed, try to install it
|
||||
logger.info("Node.js is not installed. Attempting to install automatically...")
|
||||
|
||||
# Check if nvm is installed
|
||||
if not check_nvm_installed():
|
||||
logger.info("nvm is not installed. Installing nvm first...")
|
||||
if not install_nvm():
|
||||
return (
|
||||
False,
|
||||
"Failed to install nvm. Please install Node.js manually from https://nodejs.org/",
|
||||
)
|
||||
|
||||
# Install Node.js using nvm
|
||||
if not install_node_with_nvm():
|
||||
return (
|
||||
False,
|
||||
"Failed to install Node.js. Please install Node.js manually from https://nodejs.org/",
|
||||
)
|
||||
|
||||
# Verify installation after automatic setup
|
||||
# Try with nvm sourced first
|
||||
nvm_path = get_nvm_sh_path()
|
||||
if nvm_path.exists():
|
||||
result = subprocess.run(
|
||||
["bash", "-c", f"source {nvm_path} && node --version"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10,
|
||||
)
|
||||
if result.returncode != 0 and result.stderr:
|
||||
logger.debug(
|
||||
f"Failed to verify node after installation: {result.stderr.strip()}"
|
||||
)
|
||||
else:
|
||||
result = subprocess.run(
|
||||
["node", "--version"], capture_output=True, text=True, timeout=10
|
||||
)
|
||||
if result.returncode != 0:
|
||||
nvm_path = get_nvm_sh_path()
|
||||
return (
|
||||
False,
|
||||
f"Node.js installation completed but node command is not available. Please restart your terminal or source {nvm_path}",
|
||||
)
|
||||
|
||||
node_version = result.stdout.strip()
|
||||
logger.debug(f"Found Node.js version: {node_version}")
|
||||
|
||||
# Check npm - handle Windows PowerShell scripts
|
||||
if platform.system() == "Windows":
|
||||
# On Windows, npm might be a PowerShell script, so we need to use shell=True
|
||||
result = subprocess.run(
|
||||
["npm", "--version"], capture_output=True, text=True, timeout=10, shell=True
|
||||
)
|
||||
else:
|
||||
# On Unix-like systems, if we just installed via nvm, we may need to source nvm
|
||||
# Try direct command first
|
||||
result = subprocess.run(
|
||||
["npm", "--version"], capture_output=True, text=True, timeout=10
|
||||
)
|
||||
if result.returncode != 0:
|
||||
# Try with nvm sourced
|
||||
nvm_path = get_nvm_sh_path()
|
||||
if nvm_path.exists():
|
||||
result = subprocess.run(
|
||||
["bash", "-c", f"source {nvm_path} && npm --version"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10,
|
||||
)
|
||||
if result.returncode != 0 and result.stderr:
|
||||
logger.debug(f"Failed to source nvm or run npm: {result.stderr.strip()}")
|
||||
|
||||
if result.returncode != 0:
|
||||
return False, "npm is not installed or not in PATH"
|
||||
|
||||
npm_version = result.stdout.strip()
|
||||
logger.debug(f"Found npm version: {npm_version}")
|
||||
|
||||
return True, f"Node.js {node_version}, npm {npm_version}"
|
||||
|
||||
except subprocess.TimeoutExpired:
|
||||
return False, "Timeout checking Node.js/npm installation"
|
||||
except FileNotFoundError:
|
||||
# Node.js is not installed, try to install it
|
||||
logger.info("Node.js is not found. Attempting to install automatically...")
|
||||
|
||||
# Check if nvm is installed
|
||||
if not check_nvm_installed():
|
||||
logger.info("nvm is not installed. Installing nvm first...")
|
||||
if not install_nvm():
|
||||
return (
|
||||
False,
|
||||
"Failed to install nvm. Please install Node.js manually from https://nodejs.org/",
|
||||
)
|
||||
|
||||
# Install Node.js using nvm
|
||||
if not install_node_with_nvm():
|
||||
return (
|
||||
False,
|
||||
"Failed to install Node.js. Please install Node.js manually from https://nodejs.org/",
|
||||
)
|
||||
|
||||
# Retry checking Node.js after installation
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["node", "--version"], capture_output=True, text=True, timeout=10
|
||||
)
|
||||
if result.returncode == 0:
|
||||
node_version = result.stdout.strip()
|
||||
# Check npm
|
||||
nvm_path = get_nvm_sh_path()
|
||||
if nvm_path.exists():
|
||||
result = subprocess.run(
|
||||
["bash", "-c", f"source {nvm_path} && npm --version"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10,
|
||||
)
|
||||
if result.returncode == 0:
|
||||
npm_version = result.stdout.strip()
|
||||
return True, f"Node.js {node_version}, npm {npm_version}"
|
||||
elif result.stderr:
|
||||
logger.debug(f"Failed to source nvm or run npm: {result.stderr.strip()}")
|
||||
except Exception as e:
|
||||
logger.debug(f"Exception retrying node/npm check: {str(e)}")
|
||||
|
||||
return False, "Node.js/npm not found. Please install Node.js from https://nodejs.org/"
|
||||
except Exception as e:
|
||||
return False, f"Error checking Node.js/npm: {str(e)}"
|
||||
50
cognee/api/v1/ui/npm_utils.py
Normal file
50
cognee/api/v1/ui/npm_utils.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import platform
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from cognee.shared.logging_utils import get_logger
|
||||
from .node_setup import get_nvm_sh_path
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
||||
def run_npm_command(cmd: List[str], cwd: Path, timeout: int = 300) -> subprocess.CompletedProcess:
|
||||
"""
|
||||
Run an npm command, ensuring nvm is sourced if needed (Unix-like systems only).
|
||||
Returns the CompletedProcess result.
|
||||
"""
|
||||
if platform.system() == "Windows":
|
||||
# On Windows, use shell=True for npm commands
|
||||
return subprocess.run(
|
||||
cmd,
|
||||
cwd=cwd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=timeout,
|
||||
shell=True,
|
||||
)
|
||||
else:
|
||||
# On Unix-like systems, try direct command first
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
cwd=cwd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=timeout,
|
||||
)
|
||||
# If it fails and nvm might be installed, try with nvm sourced
|
||||
if result.returncode != 0:
|
||||
nvm_path = get_nvm_sh_path()
|
||||
if nvm_path.exists():
|
||||
nvm_cmd = f"source {nvm_path} && {' '.join(cmd)}"
|
||||
result = subprocess.run(
|
||||
["bash", "-c", nvm_cmd],
|
||||
cwd=cwd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=timeout,
|
||||
)
|
||||
if result.returncode != 0 and result.stderr:
|
||||
logger.debug(f"npm command failed with nvm: {result.stderr.strip()}")
|
||||
return result
|
||||
|
|
@ -15,6 +15,8 @@ import shutil
|
|||
|
||||
from cognee.shared.logging_utils import get_logger
|
||||
from cognee.version import get_cognee_version
|
||||
from .node_setup import check_node_npm, get_nvm_dir, get_nvm_sh_path
|
||||
from .npm_utils import run_npm_command
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
|
@ -285,48 +287,6 @@ def find_frontend_path() -> Optional[Path]:
|
|||
return None
|
||||
|
||||
|
||||
def check_node_npm() -> tuple[bool, str]:
|
||||
"""
|
||||
Check if Node.js and npm are available.
|
||||
Returns (is_available, error_message)
|
||||
"""
|
||||
|
||||
try:
|
||||
# Check Node.js
|
||||
result = subprocess.run(["node", "--version"], capture_output=True, text=True, timeout=10)
|
||||
if result.returncode != 0:
|
||||
return False, "Node.js is not installed or not in PATH"
|
||||
|
||||
node_version = result.stdout.strip()
|
||||
logger.debug(f"Found Node.js version: {node_version}")
|
||||
|
||||
# Check npm - handle Windows PowerShell scripts
|
||||
if platform.system() == "Windows":
|
||||
# On Windows, npm might be a PowerShell script, so we need to use shell=True
|
||||
result = subprocess.run(
|
||||
["npm", "--version"], capture_output=True, text=True, timeout=10, shell=True
|
||||
)
|
||||
else:
|
||||
result = subprocess.run(
|
||||
["npm", "--version"], capture_output=True, text=True, timeout=10
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
return False, "npm is not installed or not in PATH"
|
||||
|
||||
npm_version = result.stdout.strip()
|
||||
logger.debug(f"Found npm version: {npm_version}")
|
||||
|
||||
return True, f"Node.js {node_version}, npm {npm_version}"
|
||||
|
||||
except subprocess.TimeoutExpired:
|
||||
return False, "Timeout checking Node.js/npm installation"
|
||||
except FileNotFoundError:
|
||||
return False, "Node.js/npm not found. Please install Node.js from https://nodejs.org/"
|
||||
except Exception as e:
|
||||
return False, f"Error checking Node.js/npm: {str(e)}"
|
||||
|
||||
|
||||
def install_frontend_dependencies(frontend_path: Path) -> bool:
|
||||
"""
|
||||
Install frontend dependencies if node_modules doesn't exist.
|
||||
|
|
@ -341,24 +301,7 @@ def install_frontend_dependencies(frontend_path: Path) -> bool:
|
|||
logger.info("Installing frontend dependencies (this may take a few minutes)...")
|
||||
|
||||
try:
|
||||
# Use shell=True on Windows for npm commands
|
||||
if platform.system() == "Windows":
|
||||
result = subprocess.run(
|
||||
["npm", "install"],
|
||||
cwd=frontend_path,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=300, # 5 minutes timeout
|
||||
shell=True,
|
||||
)
|
||||
else:
|
||||
result = subprocess.run(
|
||||
["npm", "install"],
|
||||
cwd=frontend_path,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=300, # 5 minutes timeout
|
||||
)
|
||||
result = run_npm_command(["npm", "install"], frontend_path, timeout=300)
|
||||
|
||||
if result.returncode == 0:
|
||||
logger.info("Frontend dependencies installed successfully")
|
||||
|
|
@ -642,6 +585,21 @@ def start_ui(
|
|||
env["HOST"] = "localhost"
|
||||
env["PORT"] = str(port)
|
||||
|
||||
# If nvm is installed, ensure it's available in the environment
|
||||
nvm_path = get_nvm_sh_path()
|
||||
if platform.system() != "Windows" and nvm_path.exists():
|
||||
# Add nvm to PATH for the subprocess
|
||||
nvm_dir = get_nvm_dir()
|
||||
# Find the latest Node.js version installed via nvm
|
||||
nvm_versions = nvm_dir / "versions" / "node"
|
||||
if nvm_versions.exists():
|
||||
versions = sorted(nvm_versions.iterdir(), reverse=True)
|
||||
if versions:
|
||||
latest_node_bin = versions[0] / "bin"
|
||||
if latest_node_bin.exists():
|
||||
current_path = env.get("PATH", "")
|
||||
env["PATH"] = f"{latest_node_bin}:{current_path}"
|
||||
|
||||
# Start the development server
|
||||
logger.info(f"Starting frontend server at http://localhost:{port}")
|
||||
logger.info("This may take a moment to compile and start...")
|
||||
|
|
@ -659,14 +617,26 @@ def start_ui(
|
|||
shell=True,
|
||||
)
|
||||
else:
|
||||
process = subprocess.Popen(
|
||||
["npm", "run", "dev"],
|
||||
cwd=frontend_path,
|
||||
env=env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
preexec_fn=os.setsid if hasattr(os, "setsid") else None,
|
||||
)
|
||||
# On Unix-like systems, use bash with nvm sourced if available
|
||||
if nvm_path.exists():
|
||||
# Use bash to source nvm and run npm
|
||||
process = subprocess.Popen(
|
||||
["bash", "-c", f"source {nvm_path} && npm run dev"],
|
||||
cwd=frontend_path,
|
||||
env=env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
preexec_fn=os.setsid if hasattr(os, "setsid") else None,
|
||||
)
|
||||
else:
|
||||
process = subprocess.Popen(
|
||||
["npm", "run", "dev"],
|
||||
cwd=frontend_path,
|
||||
env=env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
preexec_fn=os.setsid if hasattr(os, "setsid") else None,
|
||||
)
|
||||
|
||||
# Start threads to stream frontend output with prefix
|
||||
_stream_process_output(process, "stdout", "[FRONTEND]", "\033[33m") # Yellow
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue