mirror of
https://github.com/reconurge/flowsint.git
synced 2026-11-18 06:35:56 -06:00
feat: mistral ai sdk
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import StreamingResponse
|
||||
from pydantic import BaseModel
|
||||
import os
|
||||
from mistralai import Mistral
|
||||
from mistralai.models import UserMessage
|
||||
import json
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class ChatRequest(BaseModel):
|
||||
prompt: str
|
||||
|
||||
@router.post("/stream")
|
||||
async def stream_chat(request: ChatRequest):
|
||||
try:
|
||||
api_key = os.environ.get("MISTRAL_API_KEY")
|
||||
if not api_key:
|
||||
raise HTTPException(status_code=500, detail="Mistral API key not configured")
|
||||
|
||||
client = Mistral(api_key=api_key)
|
||||
model = "mistral-small-latest"
|
||||
|
||||
async def generate():
|
||||
response = await client.chat.stream_async(
|
||||
model=model,
|
||||
messages=[
|
||||
UserMessage(content=request.prompt)
|
||||
]
|
||||
)
|
||||
|
||||
async for chunk in response:
|
||||
if chunk.data.choices[0].delta.content is not None:
|
||||
yield f"data: {json.dumps({'content': chunk.data.choices[0].delta.content})}\n\n"
|
||||
|
||||
yield "data: [DONE]\n\n"
|
||||
|
||||
return StreamingResponse(
|
||||
generate(),
|
||||
media_type="text/event-stream"
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
@@ -12,6 +12,7 @@ from app.api.routes import sketches
|
||||
from app.api.routes import transforms
|
||||
from app.api.routes import logs
|
||||
from app.api.routes import analysis
|
||||
from app.api.routes import chat
|
||||
|
||||
load_dotenv()
|
||||
|
||||
@@ -54,3 +55,4 @@ app.include_router(investigations.router, prefix="/api/investigations", tags=["i
|
||||
app.include_router(transforms.router, prefix="/api/transforms", tags=["transforms"])
|
||||
app.include_router(logs.router, prefix="/api/logs", tags=["logs"])
|
||||
app.include_router(analysis.router, prefix="/api/analyses", tags=["analyses"])
|
||||
app.include_router(chat.router, prefix="/api/chat", tags=["chat"])
|
||||
|
||||
@@ -26,4 +26,5 @@ alembic
|
||||
passlib[bcrypt]
|
||||
sse-starlette
|
||||
networkx
|
||||
pydantic_neo4j
|
||||
pydantic_neo4j
|
||||
mistralai
|
||||
@@ -42,4 +42,4 @@ publish:
|
||||
provider: generic
|
||||
url: https://example.com/auto-updates
|
||||
electronDownload:
|
||||
mirror: https://npmmirror.com/mirrors/electron/
|
||||
mirror: https://npmmirror.com/mirrors/electron/
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
|
||||
import { tanstackRouter } from '@tanstack/router-plugin/vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import tailwindcss from "@tailwindcss/vite"
|
||||
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
|
||||
@@ -12,6 +12,23 @@ export default defineConfig({
|
||||
plugins: [externalizeDepsPlugin()]
|
||||
},
|
||||
renderer: {
|
||||
plugins: [
|
||||
{
|
||||
...tanstackRouter({
|
||||
target: 'react',
|
||||
routesDirectory: "src/renderer/src/routes",
|
||||
generatedRouteTree: "src/renderer/src/routeTree.gen.ts",
|
||||
routeFileIgnorePrefix: "_",
|
||||
autoCodeSplitting: true,
|
||||
verboseFileRoutes: false,
|
||||
quoteStyle: "double",
|
||||
semicolons: true
|
||||
}),
|
||||
enforce: 'pre'
|
||||
},
|
||||
react(),
|
||||
tailwindcss()
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve('src/renderer/src')
|
||||
@@ -26,6 +43,5 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [react(), TanStackRouterVite(), tailwindcss()]
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -56,6 +56,7 @@
|
||||
"@tailwindcss/vite": "^3.4.1",
|
||||
"@tanstack/react-query": "^5.79.0",
|
||||
"@tanstack/react-virtual": "^3.13.9",
|
||||
"@tanstack/router-plugin": "^1.121.7",
|
||||
"@tiptap/extension-code-block-lowlight": "^2.12.0",
|
||||
"@tiptap/extension-color": "^2.12.0",
|
||||
"@tiptap/extension-heading": "^2.12.0",
|
||||
@@ -72,6 +73,7 @@
|
||||
"@tiptap/extension-text-style": "^2.12.0",
|
||||
"@tiptap/extension-typography": "^2.12.0",
|
||||
"@tiptap/extension-underline": "^2.12.0",
|
||||
"@tiptap/html": "^2.14.0",
|
||||
"@tiptap/pm": "^2.12.0",
|
||||
"@tiptap/react": "^2.12.0",
|
||||
"@tiptap/starter-kit": "^2.12.0",
|
||||
@@ -90,6 +92,7 @@
|
||||
"input-otp": "^1.4.2",
|
||||
"lowlight": "^3.3.0",
|
||||
"lucide-react": "^0.511.0",
|
||||
"marked": "^15.0.12",
|
||||
"next-themes": "^0.4.6",
|
||||
"react-day-picker": "8.10.1",
|
||||
"react-force-graph-2d": "^1.27.1",
|
||||
@@ -114,7 +117,6 @@
|
||||
"@electron-toolkit/tsconfig": "^1.0.1",
|
||||
"@tanstack/react-router": "^1.98.0",
|
||||
"@tanstack/router-devtools": "^1.98.0",
|
||||
"@tanstack/router-vite-plugin": "^1.98.5",
|
||||
"@types/node": "^22.15.29",
|
||||
"@types/react": "^18.3.3",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" theme="dark">
|
||||
<head>
|
||||
<!-- <script
|
||||
<script
|
||||
crossOrigin="anonymous"
|
||||
src="//unpkg.com/react-scan/dist/auto.global.js"
|
||||
>
|
||||
</script> -->
|
||||
</script>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import { toast } from "sonner";
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL;
|
||||
|
||||
export interface ChatResponse {
|
||||
content: string
|
||||
}
|
||||
|
||||
export class ChatService {
|
||||
private static instance: ChatService
|
||||
private baseUrl: string
|
||||
|
||||
private constructor() {
|
||||
this.baseUrl = `${API_URL}/api/chat`
|
||||
}
|
||||
|
||||
public static getInstance(): ChatService {
|
||||
if (!ChatService.instance) {
|
||||
ChatService.instance = new ChatService()
|
||||
}
|
||||
return ChatService.instance
|
||||
}
|
||||
|
||||
async streamChat(prompt: string, onChunk: (content: string) => void, context?: any): Promise<string> {
|
||||
const response = await fetch(`${this.baseUrl}/stream`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
prompt,
|
||||
context
|
||||
}),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
console.error("Response not OK:", response.status, response.statusText)
|
||||
throw new Error('Failed to get AI completion')
|
||||
}
|
||||
|
||||
const reader = response.body?.getReader()
|
||||
if (!reader) {
|
||||
console.error("No reader available")
|
||||
throw new Error('No reader available')
|
||||
}
|
||||
|
||||
let accumulatedContent = ''
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) {
|
||||
console.log("Stream complete")
|
||||
break
|
||||
}
|
||||
|
||||
const text = new TextDecoder().decode(value)
|
||||
const lines = text.split('\n')
|
||||
|
||||
for (const line of lines) {
|
||||
if (line.startsWith('data: ')) {
|
||||
const data = line.slice(6)
|
||||
if (data === '[DONE]') {
|
||||
return accumulatedContent
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(data)
|
||||
if (parsed.content) {
|
||||
accumulatedContent += parsed.content
|
||||
onChunk(accumulatedContent)
|
||||
}
|
||||
} catch (e) {
|
||||
toast.error("Error parsing SSE data.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return accumulatedContent
|
||||
}
|
||||
}
|
||||
|
||||
export const chatService = ChatService.getInstance()
|
||||
@@ -114,8 +114,8 @@ const GraphPanel = ({ graphData, isLoading }: GraphPanelProps) => {
|
||||
</div>
|
||||
</div>
|
||||
}>
|
||||
{/* {nodes?.length > 2000 ? <Graph /> : <GraphReactForce />} */}
|
||||
<GraphReactForce />
|
||||
{nodes?.length > 500 ? <Graph /> : <GraphReactForce />}
|
||||
{/* <GraphReactForce /> */}
|
||||
</Suspense>
|
||||
{/* <Graph /> */}
|
||||
{/* <GraphSigma /> */}
|
||||
|
||||
@@ -6,13 +6,20 @@ import type { Analysis } from "@/types"
|
||||
import { useParams } from "@tanstack/react-router"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger } from "@/components/ui/select"
|
||||
import { PlusIcon, Trash2, Save, ChevronsRight } from "lucide-react"
|
||||
import { PlusIcon, Trash2, Save, ChevronsRight, Sparkles, ChevronDown, XIcon } from "lucide-react"
|
||||
import { useAnalysisPanelStore } from "@/stores/analysis-panel-store"
|
||||
import { toast } from "sonner"
|
||||
import { useKeyboardShortcut } from "@/hooks/use-keyboard-shortcut"
|
||||
import { useConfirm } from "../use-confirm-dialog"
|
||||
import { useLayoutStore } from "@/stores/layout-store"
|
||||
import { useChat } from "@/hooks/use-chat"
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import { Editor } from "@tiptap/core"
|
||||
|
||||
export const AnalysisPanel = () => {
|
||||
const { investigationId } = useParams({ strict: false }) as { investigationId: string }
|
||||
@@ -20,7 +27,25 @@ export const AnalysisPanel = () => {
|
||||
const currentAnalysisId = useAnalysisPanelStore(s => s.currentAnalysisId)
|
||||
const setCurrentAnalysisId = useAnalysisPanelStore(s => s.setCurrentAnalysisId)
|
||||
const { confirm } = useConfirm()
|
||||
|
||||
// State for editor
|
||||
const [editorValue, setEditorValue] = useState<any>("")
|
||||
const [titleValue, setTitleValue] = useState("")
|
||||
const [editor, setEditor] = useState<Editor | undefined>(undefined)
|
||||
const [isEditingTitle, setIsEditingTitle] = useState(false)
|
||||
const [includeContext, setIncludeContext] = useState(false)
|
||||
// Chat hook
|
||||
const {
|
||||
isAiLoading,
|
||||
promptOpen,
|
||||
setPromptOpen,
|
||||
customPrompt,
|
||||
setCustomPrompt,
|
||||
handleCustomPrompt
|
||||
} = useChat({
|
||||
onContentUpdate: setEditorValue,
|
||||
onSuccess: () => saveMutation.mutate({}),
|
||||
editor: editor
|
||||
})
|
||||
|
||||
// Fetch all analyses for this investigation
|
||||
const { data: analyses, isLoading: isLoadingAnalyses, isError, refetch } = useQuery<Analysis[]>({
|
||||
@@ -41,35 +66,30 @@ export const AnalysisPanel = () => {
|
||||
}
|
||||
}, [analyses, currentAnalysisId, setCurrentAnalysisId])
|
||||
|
||||
// State for editor
|
||||
const [editorValue, setEditorValue] = useState<any>("")
|
||||
const [titleValue, setTitleValue] = useState("")
|
||||
|
||||
useEffect(() => {
|
||||
if (currentAnalysis) {
|
||||
// Handle both string content and object content
|
||||
const content = currentAnalysis.content
|
||||
if (typeof content === 'string') {
|
||||
try {
|
||||
// Try to parse if it's a JSON string
|
||||
setEditorValue(JSON.parse(content))
|
||||
} catch {
|
||||
// If parsing fails, treat as plain text and convert to editor format
|
||||
setEditorValue(content || "")
|
||||
}
|
||||
} else {
|
||||
// If it's already an object, use it directly
|
||||
setEditorValue(content || "")
|
||||
}
|
||||
console.log("Setting editorValue:", content)
|
||||
setTitleValue(currentAnalysis.title || "")
|
||||
} else {
|
||||
// Reset when no analysis is selected
|
||||
setEditorValue("")
|
||||
setTitleValue("")
|
||||
console.log("Resetting editorValue")
|
||||
// Add title update mutation
|
||||
const updateTitleMutation = useMutation({
|
||||
mutationFn: async (newTitle: string) => {
|
||||
if (!currentAnalysis) return
|
||||
return analysisService.update(currentAnalysis.id, JSON.stringify({
|
||||
...currentAnalysis,
|
||||
title: newTitle
|
||||
}))
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await refetch()
|
||||
toast.success("Title updated")
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error("Failed to update title: " + (error instanceof Error ? error.message : "Unknown error"))
|
||||
}
|
||||
}, [currentAnalysisId, currentAnalysis?.id, currentAnalysis?.content, currentAnalysis?.title])
|
||||
})
|
||||
|
||||
// Handle title update
|
||||
const handleTitleUpdate = (newTitle: string) => {
|
||||
setTitleValue(newTitle)
|
||||
updateTitleMutation.mutate(newTitle)
|
||||
setIsEditingTitle(false)
|
||||
}
|
||||
|
||||
// Mutations
|
||||
const createMutation = useMutation({
|
||||
@@ -80,7 +100,6 @@ export const AnalysisPanel = () => {
|
||||
content: {},
|
||||
}
|
||||
const res = await analysisService.create(JSON.stringify(newAnalysis))
|
||||
|
||||
return res
|
||||
},
|
||||
onSuccess: async (data) => {
|
||||
@@ -142,6 +161,43 @@ export const AnalysisPanel = () => {
|
||||
deleteMutation.mutate(currentAnalysisId)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (currentAnalysis) {
|
||||
// Handle both string content and object content
|
||||
const content = currentAnalysis.content
|
||||
if (typeof content === 'string') {
|
||||
try {
|
||||
// Try to parse if it's a JSON string
|
||||
const parsedContent = JSON.parse(content)
|
||||
setEditorValue(parsedContent)
|
||||
if (editor) {
|
||||
editor.commands.setContent(parsedContent)
|
||||
}
|
||||
} catch {
|
||||
// If parsing fails, treat as plain text and convert to editor format
|
||||
setEditorValue(content || "")
|
||||
if (editor) {
|
||||
editor.commands.setContent(content || "")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If it's already an object, use it directly
|
||||
setEditorValue(content || "")
|
||||
if (editor) {
|
||||
editor.commands.setContent(content || "")
|
||||
}
|
||||
}
|
||||
setTitleValue(currentAnalysis.title || "")
|
||||
} else {
|
||||
// Reset when no analysis is selected
|
||||
setEditorValue("")
|
||||
setTitleValue("")
|
||||
if (editor) {
|
||||
editor.commands.setContent("")
|
||||
}
|
||||
}
|
||||
}, [currentAnalysisId, currentAnalysis?.id, currentAnalysis?.content, currentAnalysis?.title, editor])
|
||||
|
||||
useKeyboardShortcut({
|
||||
key: "s",
|
||||
ctrlOrCmd: true,
|
||||
@@ -150,12 +206,18 @@ export const AnalysisPanel = () => {
|
||||
},
|
||||
})
|
||||
|
||||
useKeyboardShortcut({
|
||||
key: "e",
|
||||
ctrlOrCmd: true,
|
||||
callback: () => setPromptOpen(!promptOpen),
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full w-full">
|
||||
{/* Header with unified title/analysis selector and controls */}
|
||||
<div className="border-b bg-background">
|
||||
<div className="flex items-center justify-between p-3">
|
||||
{/* Unified title and analysis selector */}
|
||||
{/* Left section with navigation and title */}
|
||||
<div className="flex items-center gap-3 flex-1 min-w-0">
|
||||
<Button className="h-8 w-8" variant="ghost" onClick={toggleChat}>
|
||||
<ChevronsRight />
|
||||
@@ -165,36 +227,75 @@ export const AnalysisPanel = () => {
|
||||
) : isError ? (
|
||||
<div className="text-sm text-destructive">Error loading analyses</div>
|
||||
) : analyses && analyses.length > 0 ? (
|
||||
<div className="flex items-center gap-2 flex-1 min-w-0">
|
||||
<Select
|
||||
value={currentAnalysisId || ""}
|
||||
onValueChange={(value) => setCurrentAnalysisId(value)}
|
||||
>
|
||||
<SelectTrigger className="border-none shadow-none bg-transparent hover:bg-muted/20 focus:bg-muted/30 p-2 h-auto min-w-0 flex-1">
|
||||
<div className="flex flex-col items-start min-w-0 flex-1">
|
||||
<input
|
||||
className="text-xl font-bold bg-transparent outline-none border-none p-0 m-0 w-full placeholder:text-muted-foreground/60"
|
||||
value={titleValue}
|
||||
onChange={e => setTitleValue(e.target.value)}
|
||||
placeholder="Untitled Analysis"
|
||||
disabled={!currentAnalysis}
|
||||
onClick={e => e.stopPropagation()}
|
||||
/>
|
||||
<div className="flex items-center gap-3 flex-1 min-w-0">
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<div>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8">
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</SelectTrigger>
|
||||
<SelectContent className="shadow-none border-muted">
|
||||
{analyses.map((analysis) => (
|
||||
<SelectItem key={analysis.id} value={analysis.id}>
|
||||
<div className="flex flex-col items-start">
|
||||
<span className="font-medium">{analysis.title || "Untitled"}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{analysis.id === currentAnalysisId ? "Current" : "Switch to this analysis"}
|
||||
</span>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-[200px] p-0" align="start">
|
||||
<div className="flex flex-col">
|
||||
{analyses.map((analysis) => (
|
||||
<Button
|
||||
key={analysis.id}
|
||||
variant="ghost"
|
||||
className="justify-start px-2 py-1.5 h-auto"
|
||||
onClick={() => setCurrentAnalysisId(analysis.id)}
|
||||
>
|
||||
<div className="flex flex-col items-start">
|
||||
<span className="font-medium">{analysis.title || "Untitled"}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{analysis.id === currentAnalysisId ? "Current" : "Switch to this analysis"}
|
||||
</span>
|
||||
</div>
|
||||
</Button>
|
||||
))}
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="justify-start px-2 py-1.5 h-auto text-primary"
|
||||
onClick={() => createMutation.mutate()}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<PlusIcon className="w-4 h-4" />
|
||||
<span>Create new analysis</span>
|
||||
</div>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</Button>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<div className="flex items-center gap-2 flex-1 min-w-0">
|
||||
{isEditingTitle ? (
|
||||
<input
|
||||
className="text-lg font-medium bg-transparent outline-none border-none p-0 m-0 w-full"
|
||||
value={titleValue}
|
||||
onChange={e => setTitleValue(e.target.value)}
|
||||
onBlur={() => {
|
||||
handleTitleUpdate(titleValue)
|
||||
setIsEditingTitle(false)
|
||||
}}
|
||||
onKeyDown={e => {
|
||||
if (e.key === 'Enter') {
|
||||
handleTitleUpdate(titleValue)
|
||||
setIsEditingTitle(false)
|
||||
} else if (e.key === 'Escape') {
|
||||
setIsEditingTitle(false)
|
||||
setTitleValue(currentAnalysis?.title || "")
|
||||
}
|
||||
}}
|
||||
autoFocus
|
||||
/>
|
||||
) : (
|
||||
<span
|
||||
className="text-lg font-medium cursor-pointer hover:text-primary truncate min-w-0 flex-1"
|
||||
onClick={() => setIsEditingTitle(true)}
|
||||
>
|
||||
{titleValue || "Untitled Analysis"}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center gap-2 flex-1 min-w-0">
|
||||
@@ -205,6 +306,16 @@ export const AnalysisPanel = () => {
|
||||
|
||||
{/* Action buttons */}
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
disabled={!currentAnalysis || isAiLoading}
|
||||
title="AI Prompt"
|
||||
className="h-8 w-8"
|
||||
onClick={() => setPromptOpen(!promptOpen)}
|
||||
>
|
||||
<Sparkles className="w-4 h-4" strokeWidth={1.5} />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
@@ -240,21 +351,83 @@ export const AnalysisPanel = () => {
|
||||
</div>
|
||||
|
||||
{/* Editor */}
|
||||
<div className="flex-1 min-h-0">
|
||||
<div className="flex-1 min-h-0 flex flex-col">
|
||||
{currentAnalysis ? (
|
||||
<MinimalTiptapEditor
|
||||
key={currentAnalysisId}
|
||||
immediatelyRender={false}
|
||||
value={editorValue}
|
||||
onChange={setEditorValue}
|
||||
className="w-full h-full"
|
||||
editorContentClassName="p-5 min-h-[300px]"
|
||||
output="json"
|
||||
placeholder="Enter your analysis..."
|
||||
autofocus={true}
|
||||
editable={true}
|
||||
editorClassName="focus:outline-hidden"
|
||||
/>
|
||||
<>
|
||||
<MinimalTiptapEditor
|
||||
key={currentAnalysisId}
|
||||
immediatelyRender={true}
|
||||
value={editorValue}
|
||||
onChange={setEditorValue}
|
||||
className="w-full flex-1"
|
||||
editorContentClassName="p-5 min-h-[300px]"
|
||||
output="json"
|
||||
placeholder="Enter your analysis..."
|
||||
autofocus={true}
|
||||
editable={true}
|
||||
editorClassName="focus:outline-hidden"
|
||||
onEditorReady={setEditor}
|
||||
/>
|
||||
{/* Prompt Panel */}
|
||||
<div className={`border-t bg-background transition-all duration-200 ${promptOpen ? 'h-[300px]' : 'h-0'}`}>
|
||||
<div className="flex flex-col h-full">
|
||||
<div className="flex items-center justify-between p-2 border-b">
|
||||
<div className="flex items-center gap-2">
|
||||
<Sparkles className="w-4 h-4" strokeWidth={1.5} />
|
||||
<span className="text-sm font-medium">AI Prompt</span>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => setPromptOpen(false)}
|
||||
className="h-6 w-6 px-2"
|
||||
>
|
||||
<XIcon />
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex-1 p-2 flex flex-col gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setIncludeContext(!includeContext)}
|
||||
className="h-6 px-2"
|
||||
>
|
||||
{includeContext ? "Hide Context" : "Show Context"}
|
||||
</Button>
|
||||
{includeContext && (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Current analysis content will be included as context
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{includeContext && (
|
||||
<Textarea
|
||||
autoFocus
|
||||
value={JSON.stringify(editorValue, null, 2)}
|
||||
readOnly
|
||||
className="h-[100px] text-xs font-mono resize-none"
|
||||
/>
|
||||
)}
|
||||
<Textarea
|
||||
placeholder="Enter your prompt..."
|
||||
value={customPrompt}
|
||||
onChange={(e) => setCustomPrompt(e.target.value)}
|
||||
className="flex-1 resize-none"
|
||||
/>
|
||||
</div>
|
||||
<div className="p-2 border-t">
|
||||
<Button
|
||||
onClick={() => handleCustomPrompt(editorValue)}
|
||||
disabled={!customPrompt.trim() || isAiLoading}
|
||||
className="w-full"
|
||||
>
|
||||
{isAiLoading ? "Generating..." : "Generate"}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="flex flex-col items-center justify-center h-full text-muted-foreground space-y-3">
|
||||
<div>No analysis selected.</div>
|
||||
|
||||
@@ -12,6 +12,7 @@ import { SectionFive } from "./components/section/five"
|
||||
import { LinkBubbleMenu } from "./components/bubble-menu/link-bubble-menu"
|
||||
import { useMinimalTiptapEditor } from "./hooks/use-minimal-tiptap"
|
||||
import { MeasuredContainer } from "./components/measured-container"
|
||||
// import "./styles/index.css"
|
||||
|
||||
export interface MinimalTiptapProps
|
||||
extends Omit<UseMinimalTiptapEditorProps, "onUpdate"> {
|
||||
@@ -19,6 +20,7 @@ export interface MinimalTiptapProps
|
||||
onChange?: (value: Content) => void
|
||||
className?: string
|
||||
editorContentClassName?: string
|
||||
onEditorReady?: (editor: Editor) => void
|
||||
}
|
||||
//@ts-ignore
|
||||
const Toolbar = ({ editor }: { editor: Editor }) => (
|
||||
@@ -67,13 +69,19 @@ const Toolbar = ({ editor }: { editor: Editor }) => (
|
||||
export const MinimalTiptapEditor = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
MinimalTiptapProps
|
||||
>(({ value, onChange, className, editorContentClassName, ...props }, ref) => {
|
||||
>(({ value, onChange, className, editorContentClassName, onEditorReady, ...props }, ref) => {
|
||||
const editor = useMinimalTiptapEditor({
|
||||
value,
|
||||
onUpdate: onChange,
|
||||
...props,
|
||||
})
|
||||
|
||||
React.useEffect(() => {
|
||||
if (editor && onEditorReady) {
|
||||
onEditorReady(editor)
|
||||
}
|
||||
}, [editor, onEditorReady])
|
||||
|
||||
if (!editor) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@import "./partials/code.css";
|
||||
@import "./partials/placeholder.css";
|
||||
@import "./partials/lists.css";
|
||||
@import "./partials/typography.css";
|
||||
@import "./partials/zoom.css";
|
||||
|
||||
:root {
|
||||
--mt-overlay: rgba(251, 251, 251, 0.75);
|
||||
--mt-transparent-foreground: rgba(0, 0, 0, 0.4);
|
||||
--mt-bg-secondary: rgba(251, 251, 251, 0.8);
|
||||
--mt-code-background: #082b781f;
|
||||
--mt-code-color: #d4d4d4;
|
||||
--mt-secondary: #9d9d9f;
|
||||
--mt-pre-background: #ececec;
|
||||
--mt-pre-border: #e0e0e0;
|
||||
--mt-pre-color: #2f2f31;
|
||||
--mt-hr: #dcdcdc;
|
||||
--mt-drag-handle-hover: #5c5c5e;
|
||||
|
||||
--mt-accent-bold-blue: #05c;
|
||||
--mt-accent-bold-teal: #206a83;
|
||||
--mt-accent-bold-green: #216e4e;
|
||||
--mt-accent-bold-orange: #a54800;
|
||||
--mt-accent-bold-red: #ae2e24;
|
||||
--mt-accent-bold-purple: #5e4db2;
|
||||
|
||||
--mt-accent-gray: #758195;
|
||||
--mt-accent-blue: #1d7afc;
|
||||
--mt-accent-teal: #2898bd;
|
||||
--mt-accent-green: #22a06b;
|
||||
--mt-accent-orange: #fea362;
|
||||
--mt-accent-red: #c9372c;
|
||||
--mt-accent-purple: #8270db;
|
||||
|
||||
--mt-accent-blue-subtler: #cce0ff;
|
||||
--mt-accent-teal-subtler: #c6edfb;
|
||||
--mt-accent-green-subtler: #baf3db;
|
||||
--mt-accent-yellow-subtler: #f8e6a0;
|
||||
--mt-accent-red-subtler: #ffd5d2;
|
||||
--mt-accent-purple-subtler: #dfd8fd;
|
||||
|
||||
--hljs-string: #aa430f;
|
||||
--hljs-title: #b08836;
|
||||
--hljs-comment: #999999;
|
||||
--hljs-keyword: #0c5eb1;
|
||||
--hljs-attr: #3a92bc;
|
||||
--hljs-literal: #c82b0f;
|
||||
--hljs-name: #259792;
|
||||
--hljs-selector-tag: #c8500f;
|
||||
--hljs-number: #3da067;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--mt-overlay: rgba(31, 32, 35, 0.75);
|
||||
--mt-transparent-foreground: rgba(255, 255, 255, 0.4);
|
||||
--mt-bg-secondary: rgba(31, 32, 35, 0.8);
|
||||
--mt-code-background: #ffffff13;
|
||||
--mt-code-color: #2c2e33;
|
||||
--mt-secondary: #595a5c;
|
||||
--mt-pre-background: #080808;
|
||||
--mt-pre-border: #23252a;
|
||||
--mt-pre-color: #e3e4e6;
|
||||
--mt-hr: #26282d;
|
||||
--mt-drag-handle-hover: #969799;
|
||||
|
||||
--mt-accent-bold-blue: #85b8ff;
|
||||
--mt-accent-bold-teal: #9dd9ee;
|
||||
--mt-accent-bold-green: #7ee2b8;
|
||||
--mt-accent-bold-orange: #fec195;
|
||||
--mt-accent-bold-red: #fd9891;
|
||||
--mt-accent-bold-purple: #b8acf6;
|
||||
|
||||
--mt-accent-gray: #738496;
|
||||
--mt-accent-blue: #388bff;
|
||||
--mt-accent-teal: #42b2d7;
|
||||
--mt-accent-green: #2abb7f;
|
||||
--mt-accent-orange: #a54800;
|
||||
--mt-accent-red: #e2483d;
|
||||
--mt-accent-purple: #8f7ee7;
|
||||
|
||||
--mt-accent-blue-subtler: #09326c;
|
||||
--mt-accent-teal-subtler: #164555;
|
||||
--mt-accent-green-subtler: #164b35;
|
||||
--mt-accent-yellow-subtler: #533f04;
|
||||
--mt-accent-red-subtler: #5d1f1a;
|
||||
--mt-accent-purple-subtler: #352c63;
|
||||
|
||||
--hljs-string: #da936b;
|
||||
--hljs-title: #f1d59d;
|
||||
--hljs-comment: #aaaaaa;
|
||||
--hljs-keyword: #6699cc;
|
||||
--hljs-attr: #90cae8;
|
||||
--hljs-literal: #f2777a;
|
||||
--hljs-name: #5fc0a0;
|
||||
--hljs-selector-tag: #e8c785;
|
||||
--hljs-number: #b6e7b6;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror {
|
||||
@apply flex max-w-full cursor-text flex-col;
|
||||
@apply z-0 outline-0;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror > div.editor {
|
||||
@apply block flex-1 whitespace-pre-wrap;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror .block-node:not(:last-child),
|
||||
.minimal-tiptap-editor .ProseMirror .list-node:not(:last-child),
|
||||
.minimal-tiptap-editor .ProseMirror .text-node:not(:last-child) {
|
||||
@apply mb-2.5;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror ol,
|
||||
.minimal-tiptap-editor .ProseMirror ul {
|
||||
@apply pl-6;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror blockquote,
|
||||
.minimal-tiptap-editor .ProseMirror dl,
|
||||
.minimal-tiptap-editor .ProseMirror ol,
|
||||
.minimal-tiptap-editor .ProseMirror p,
|
||||
.minimal-tiptap-editor .ProseMirror pre,
|
||||
.minimal-tiptap-editor .ProseMirror ul {
|
||||
@apply m-0;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror li {
|
||||
@apply leading-7;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror p {
|
||||
@apply break-words;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror li .text-node:has(+ .list-node),
|
||||
.minimal-tiptap-editor .ProseMirror li > .list-node,
|
||||
.minimal-tiptap-editor .ProseMirror li > .text-node,
|
||||
.minimal-tiptap-editor .ProseMirror li p {
|
||||
@apply mb-0;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror blockquote {
|
||||
@apply relative pl-3.5;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror blockquote::before,
|
||||
.minimal-tiptap-editor .ProseMirror blockquote.is-empty::before {
|
||||
@apply absolute bottom-0 left-0 top-0 h-full w-1 rounded-sm bg-accent-foreground/15 content-[''];
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror hr {
|
||||
@apply my-3 h-0.5 w-full border-none bg-[var(--mt-hr)];
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror-focused hr.ProseMirror-selectednode {
|
||||
@apply rounded-full outline outline-2 outline-offset-1 outline-muted-foreground;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror .ProseMirror-gapcursor {
|
||||
@apply pointer-events-none absolute hidden;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror .ProseMirror-hideselection {
|
||||
@apply caret-transparent;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror.resize-cursor {
|
||||
@apply cursor-col-resize;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror .selection {
|
||||
@apply inline-block;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror s span {
|
||||
@apply line-through;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror .selection,
|
||||
.minimal-tiptap-editor .ProseMirror *::selection {
|
||||
@apply bg-primary/25;
|
||||
}
|
||||
|
||||
/* Override native selection when custom selection is present */
|
||||
.minimal-tiptap-editor .ProseMirror .selection::selection {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror code.inline {
|
||||
@apply rounded border border-[var(--mt-code-color)] bg-[var(--mt-code-background)] px-1 py-0.5 text-sm;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror pre {
|
||||
@apply relative overflow-auto rounded border font-mono text-sm;
|
||||
@apply border-[var(--mt-pre-border)] bg-[var(--mt-pre-background)] text-[var(--mt-pre-color)];
|
||||
@apply hyphens-none whitespace-pre text-left;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror code {
|
||||
@apply break-words leading-[1.7em];
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror pre code {
|
||||
@apply block overflow-x-auto p-3.5;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror pre {
|
||||
.hljs-keyword,
|
||||
.hljs-operator,
|
||||
.hljs-function,
|
||||
.hljs-built_in,
|
||||
.hljs-builtin-name {
|
||||
color: var(--hljs-keyword);
|
||||
}
|
||||
|
||||
.hljs-attr,
|
||||
.hljs-symbol,
|
||||
.hljs-property,
|
||||
.hljs-attribute,
|
||||
.hljs-variable,
|
||||
.hljs-template-variable,
|
||||
.hljs-params {
|
||||
color: var(--hljs-attr);
|
||||
}
|
||||
|
||||
.hljs-name,
|
||||
.hljs-regexp,
|
||||
.hljs-link,
|
||||
.hljs-type,
|
||||
.hljs-addition {
|
||||
color: var(--hljs-name);
|
||||
}
|
||||
|
||||
.hljs-string,
|
||||
.hljs-bullet {
|
||||
color: var(--hljs-string);
|
||||
}
|
||||
|
||||
.hljs-title,
|
||||
.hljs-subst,
|
||||
.hljs-section {
|
||||
color: var(--hljs-title);
|
||||
}
|
||||
|
||||
.hljs-literal,
|
||||
.hljs-type,
|
||||
.hljs-deletion {
|
||||
color: var(--hljs-literal);
|
||||
}
|
||||
|
||||
.hljs-selector-tag,
|
||||
.hljs-selector-id,
|
||||
.hljs-selector-class {
|
||||
color: var(--hljs-selector-tag);
|
||||
}
|
||||
|
||||
.hljs-number {
|
||||
color: var(--hljs-number);
|
||||
}
|
||||
|
||||
.hljs-comment,
|
||||
.hljs-meta,
|
||||
.hljs-quote {
|
||||
color: var(--hljs-comment);
|
||||
}
|
||||
|
||||
.hljs-emphasis {
|
||||
@apply italic;
|
||||
}
|
||||
|
||||
.hljs-strong {
|
||||
@apply font-bold;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
.minimal-tiptap-editor .ProseMirror ol {
|
||||
@apply list-decimal;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror ol ol {
|
||||
list-style: lower-alpha;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror ol ol ol {
|
||||
list-style: lower-roman;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror ul {
|
||||
list-style: disc;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror ul ul {
|
||||
list-style: circle;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror ul ul ul {
|
||||
list-style: square;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror > p.is-editor-empty::before {
|
||||
content: attr(data-placeholder);
|
||||
@apply pointer-events-none float-left h-0 text-[var(--mt-secondary)];
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror .heading-node {
|
||||
@apply relative font-semibold;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror .heading-node:first-child {
|
||||
@apply mt-0;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror h1 {
|
||||
@apply mb-4 mt-[46px] text-[1.375rem] leading-7 tracking-[-0.004375rem];
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror h2 {
|
||||
@apply mb-3.5 mt-8 text-[1.1875rem] leading-7 tracking-[0.003125rem];
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror h3 {
|
||||
@apply mb-3 mt-6 text-[1.0625rem] leading-6 tracking-[0.00625rem];
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror h4 {
|
||||
@apply mb-2 mt-4 text-[0.9375rem] leading-6;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror h5 {
|
||||
@apply mb-2 mt-4 text-sm;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror h5 {
|
||||
@apply mb-2 mt-4 text-sm;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror a.link {
|
||||
@apply cursor-pointer text-primary;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror a.link:hover {
|
||||
@apply underline;
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
[data-rmiz-ghost] {
|
||||
position: absolute;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
[data-rmiz-btn-zoom],
|
||||
[data-rmiz-btn-unzoom] {
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
border-radius: 50%;
|
||||
border: none;
|
||||
box-shadow: 0 0 1px rgba(255, 255, 255, 0.5);
|
||||
color: #fff;
|
||||
height: 40px;
|
||||
margin: 0;
|
||||
outline-offset: 2px;
|
||||
padding: 9px;
|
||||
touch-action: manipulation;
|
||||
width: 40px;
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
appearance: none;
|
||||
}
|
||||
|
||||
[data-rmiz-btn-zoom]:not(:focus):not(:active) {
|
||||
position: absolute;
|
||||
clip: rect(0 0 0 0);
|
||||
clip-path: inset(50%);
|
||||
height: 1px;
|
||||
overflow: hidden;
|
||||
pointer-events: none;
|
||||
white-space: nowrap;
|
||||
width: 1px;
|
||||
}
|
||||
|
||||
[data-rmiz-btn-zoom] {
|
||||
position: absolute;
|
||||
inset: 10px 10px auto auto;
|
||||
cursor: zoom-in;
|
||||
}
|
||||
|
||||
[data-rmiz-btn-unzoom] {
|
||||
position: absolute;
|
||||
inset: 20px 20px auto auto;
|
||||
cursor: zoom-out;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
[data-rmiz-content="found"] img,
|
||||
[data-rmiz-content="found"] svg,
|
||||
[data-rmiz-content="found"] [role="img"],
|
||||
[data-rmiz-content="found"] [data-zoom] {
|
||||
cursor: inherit;
|
||||
}
|
||||
|
||||
[data-rmiz-modal]::backdrop {
|
||||
display: none;
|
||||
}
|
||||
|
||||
[data-rmiz-modal][open] {
|
||||
position: fixed;
|
||||
width: 100vw;
|
||||
width: 100dvw;
|
||||
height: 100vh;
|
||||
height: 100dvh;
|
||||
max-width: none;
|
||||
max-height: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
[data-rmiz-modal-overlay] {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
[data-rmiz-modal-overlay="hidden"] {
|
||||
background-color: rgba(255, 255, 255, 0);
|
||||
}
|
||||
|
||||
[data-rmiz-modal-overlay="visible"] {
|
||||
background-color: rgba(255, 255, 255, 1);
|
||||
}
|
||||
|
||||
[data-rmiz-modal-content] {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
[data-rmiz-modal-img] {
|
||||
position: absolute;
|
||||
cursor: zoom-out;
|
||||
image-rendering: high-quality;
|
||||
transform-origin: top left;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
|
||||
[data-rmiz-modal-overlay],
|
||||
[data-rmiz-modal-img] {
|
||||
transition-duration: 0.01ms !important;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ const GraphReactForce: React.FC<GraphReactForceProps> = () => {
|
||||
const colors = useNodesDisplaySettings(s => s.colors) as Record<ItemType, string>;
|
||||
const toggleNodeSelection = useSketchStore(s => s.toggleNodeSelection);
|
||||
const clearSelectedNodes = useSketchStore(s => s.clearSelectedNodes);
|
||||
const currentNode = useSketchStore(s => s.currentNode);
|
||||
// const currentNode = useSketchStore(s => s.currentNode);
|
||||
const setActions = useGraphControls(s => s.setActions);
|
||||
|
||||
const shouldUseSimpleRendering = useMemo(() => nodes.length > NODE_COUNT_THRESHOLD, [nodes.length]);
|
||||
@@ -117,9 +117,9 @@ const GraphReactForce: React.FC<GraphReactForceProps> = () => {
|
||||
ctx.fillStyle = node.nodeColor;
|
||||
ctx.fill();
|
||||
|
||||
const img = new Image();
|
||||
img.src = `./icons/${node.type}.svg` as any;
|
||||
ctx.drawImage(img, node.x - size / 2, node.y - size / 2, size, size);
|
||||
// const img = new Image();
|
||||
// img.src = `./icons/${node.type}.svg` as any;
|
||||
// ctx.drawImage(img, node.x - size / 2, node.y - size / 2, size, size);
|
||||
|
||||
if (globalScale > 3) {
|
||||
const label = node.nodeLabel || node.label || node.id;
|
||||
@@ -209,9 +209,9 @@ const GraphReactForce: React.FC<GraphReactForceProps> = () => {
|
||||
linkDirectionalParticleSpeed={0.005}
|
||||
linkWidth={link => link.__highlighted ? 2 : link.__dimmed ? 0.5 : 1}
|
||||
linkColor={link => {
|
||||
if (link.__highlighted) return '#000';
|
||||
if (link.__dimmed) return '#ccc';
|
||||
return '#666';
|
||||
if (link.__highlighted) return 'rgba(171, 171, 171, 0.23)';
|
||||
if (link.__dimmed) return 'rgba(146, 146, 146, 0.33)';
|
||||
return 'rgba(166, 166, 166, 0.32)';
|
||||
}}
|
||||
d3AlphaDecay={0.02}
|
||||
d3VelocityDecay={0.3}
|
||||
|
||||
@@ -3,14 +3,10 @@ import { Cosmograph, CosmographProvider, useCosmograph } from '@cosmograph/react
|
||||
import { useSketchStore } from "@/stores/sketch-store"
|
||||
import { useNodesDisplaySettings } from "@/stores/node-display-settings"
|
||||
import Loader from "@/components/shared/loader"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import NewActions from "@/components/sketches/new-actions"
|
||||
import { PlusIcon } from "lucide-react"
|
||||
import { useGraphControls } from "@/stores/graph-controls-store"
|
||||
// @ts-ignore
|
||||
import { type CosmosInputNode } from "@cosmograph/cosmos"
|
||||
import { ResizablePanel, ResizablePanelGroup } from "../ui/resizable"
|
||||
import Legend from "./legend"
|
||||
import EmptyState from "./empty-state"
|
||||
|
||||
// Lazy loading du timeline
|
||||
@@ -60,7 +56,7 @@ const useCosmographLoader = (nodes: any[], edges: any[]) => {
|
||||
|
||||
// Composant de loader personnalisé pour Cosmograph
|
||||
const CosmographLoader = memo(({ stage }: { stage: string }) => (
|
||||
<div className="absolute inset-0 bg-background/80 backdrop-blur-sm flex flex-col items-center justify-center z-50">
|
||||
<div className="absolute inset-0 bg-background/80 backdrop-blur-sm flex flex-col items-center justify-center z-50">
|
||||
<Loader />
|
||||
<div className="mt-4 text-sm text-muted-foreground">
|
||||
{stage === 'importing' && 'Importing graph data...'}
|
||||
@@ -82,8 +78,7 @@ const GRAPH_CONFIG = {
|
||||
// simulationRepulsionTheta: 1.15,
|
||||
linkStrength: 1,
|
||||
simulationLinkDistance: .1,
|
||||
nodeSizeScale: 0.1,
|
||||
|
||||
nodeSizeScale: 0.2,
|
||||
// simulationLinkDistance: 6,
|
||||
backgroundColor: "transparent" as const,
|
||||
}
|
||||
@@ -103,9 +98,7 @@ const GraphContent = memo(() => {
|
||||
const cosmograph = useCosmograph()
|
||||
const actionsSetRef = useRef(false)
|
||||
|
||||
// Callbacks stables - créés une seule fois
|
||||
const handleLabelClick = useCallback((node: any, event: MouseEvent) => {
|
||||
|
||||
const multiSelect = event.ctrlKey || event.shiftKey || event.altKey
|
||||
toggleNodeSelection(node, multiSelect)
|
||||
cosmograph?.cosmograph?.zoomToNode(node)
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
import { useState } from 'react'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
import { chatService } from '@/api/chat.service'
|
||||
import { marked } from 'marked';
|
||||
import { generateJSON } from '@tiptap/core'
|
||||
import { StarterKit } from '@tiptap/starter-kit'
|
||||
import { Typography } from '@tiptap/extension-typography'
|
||||
import { Placeholder } from '@tiptap/extension-placeholder'
|
||||
import { Underline } from '@tiptap/extension-underline'
|
||||
import { TextStyle } from '@tiptap/extension-text-style'
|
||||
import { Link } from '@tiptap/extension-link'
|
||||
import { Image } from '@tiptap/extension-image'
|
||||
import { HorizontalRule } from '@tiptap/extension-horizontal-rule'
|
||||
import { CodeBlockLowlight } from '@tiptap/extension-code-block-lowlight'
|
||||
import { Color } from '@tiptap/extension-color'
|
||||
import type { Editor } from '@tiptap/react'
|
||||
import { useSketchStore } from '@/stores/sketch-store';
|
||||
|
||||
const markdownToHtml = (markdown: string) => {
|
||||
return marked(markdown, {
|
||||
breaks: true, // Convert \n to <br>
|
||||
gfm: true, // Enable GitHub Flavored Markdown
|
||||
async: false
|
||||
});
|
||||
};
|
||||
|
||||
interface UseChatOptions {
|
||||
onContentUpdate: (content: any) => void
|
||||
onSuccess?: () => void
|
||||
editor?: Editor
|
||||
}
|
||||
|
||||
export const useChat = ({ onContentUpdate, onSuccess, editor }: UseChatOptions) => {
|
||||
const [isAiLoading, setIsAiLoading] = useState(false)
|
||||
const [promptOpen, setPromptOpen] = useState(true)
|
||||
const [customPrompt, setCustomPrompt] = useState("")
|
||||
const selectedNodes = useSketchStore(s => s.selectedNodes)
|
||||
|
||||
const aiCompletionMutation = useMutation({
|
||||
mutationFn: async (prompt: string) => {
|
||||
setIsAiLoading(true)
|
||||
try {
|
||||
return await chatService.streamChat(prompt, (content) => {
|
||||
const htmlContent = markdownToHtml(content);
|
||||
const extensions = [
|
||||
StarterKit.configure({
|
||||
horizontalRule: false,
|
||||
codeBlock: false,
|
||||
paragraph: { HTMLAttributes: { class: "text-node" } },
|
||||
heading: { HTMLAttributes: { class: "heading-node" } },
|
||||
blockquote: { HTMLAttributes: { class: "block-node" } },
|
||||
bulletList: { HTMLAttributes: { class: "list-node" } },
|
||||
orderedList: { HTMLAttributes: { class: "list-node" } },
|
||||
code: { HTMLAttributes: { class: "inline", spellcheck: "false" } },
|
||||
dropcursor: { width: 2, class: "ProseMirror-dropcursor border" },
|
||||
}),
|
||||
Link,
|
||||
Underline,
|
||||
Image,
|
||||
Color,
|
||||
TextStyle,
|
||||
HorizontalRule,
|
||||
CodeBlockLowlight,
|
||||
Typography,
|
||||
Placeholder.configure({ placeholder: 'Enter your analysis...' })
|
||||
]
|
||||
const jsonContent = generateJSON(htmlContent, extensions)
|
||||
|
||||
if (editor) {
|
||||
// If we have an editor instance, use its commands
|
||||
editor.commands.setContent(jsonContent)
|
||||
onContentUpdate(jsonContent)
|
||||
} else {
|
||||
// Otherwise, use the callback
|
||||
onContentUpdate(jsonContent)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("Error in chat stream:", error)
|
||||
throw error
|
||||
} finally {
|
||||
setIsAiLoading(false)
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
onSuccess?.()
|
||||
toast.success("AI completion added!")
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error("Chat error:", error)
|
||||
toast.error("Failed to get AI completion: " + (error instanceof Error ? error.message : "Unknown error"))
|
||||
}
|
||||
})
|
||||
|
||||
const handleCustomPrompt = async (currentContent: any) => {
|
||||
if (!customPrompt.trim()) {
|
||||
toast.error("Please enter a prompt")
|
||||
return
|
||||
}
|
||||
const content = typeof currentContent === 'string' ? currentContent : JSON.stringify(currentContent)
|
||||
const context = selectedNodes ? `entities:${JSON.stringify(selectedNodes)}}\n\nContext:\n${content}` : content
|
||||
const fullPrompt = `${customPrompt}\n\nContext:\n${context}`
|
||||
setPromptOpen(false)
|
||||
setCustomPrompt("")
|
||||
aiCompletionMutation.mutate(fullPrompt)
|
||||
}
|
||||
|
||||
return {
|
||||
isAiLoading,
|
||||
promptOpen,
|
||||
setPromptOpen,
|
||||
customPrompt,
|
||||
setCustomPrompt,
|
||||
handleCustomPrompt
|
||||
}
|
||||
}
|
||||
@@ -51,62 +51,16 @@ body {
|
||||
border-radius: 6px !important;
|
||||
}
|
||||
|
||||
.react-sigma {
|
||||
background-color: var(--background) !important;
|
||||
}
|
||||
|
||||
.cytoscape-navigator {
|
||||
position: relative;
|
||||
background: var(--card);
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.cytoscape-navigator>img {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.cytoscape-navigator>canvas {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 101;
|
||||
}
|
||||
|
||||
.cytoscape-navigatorView {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
cursor: move;
|
||||
background: #B7E1ED;
|
||||
-moz-opacity: 0.50;
|
||||
opacity: 0.50;
|
||||
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha"(Opacity=50);
|
||||
z-index: 102;
|
||||
}
|
||||
|
||||
.cytoscape-navigatorOverlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 103;
|
||||
}
|
||||
|
||||
.style_module_watermark__6b4371ae {
|
||||
display: none !important;
|
||||
opacity: 0 !important;
|
||||
}
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror code.inline {
|
||||
@apply rounded border-[var(--mt-code-color)] bg-[var(--mt-code-background)] px-1 py-0.5 text-sm;
|
||||
@apply rounded border border-border bg-[var(--muted)] px-1 py-0.5 text-sm;
|
||||
}
|
||||
|
||||
|
||||
.minimal-tiptap-editor .ProseMirror pre {
|
||||
@apply relative overflow-auto rounded font-mono text-sm;
|
||||
@apply border-[var(--mt-pre-border)] bg-[var(--mt-pre-background)] text-[var(--mt-pre-color)];
|
||||
@@ -601,4 +555,77 @@ body {
|
||||
/* Override native selection when custom selection is present */
|
||||
.minimal-tiptap-editor .ProseMirror .selection::selection {
|
||||
background: transparent;
|
||||
}
|
||||
}
|
||||
|
||||
/* Basic editor styles */
|
||||
.tiptap > :first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.tiptap pre {
|
||||
background: var(--black);
|
||||
border-radius: 0.5rem;
|
||||
color: var(--white);
|
||||
font-family: 'JetBrainsMono', monospace;
|
||||
margin: 1.5rem 0;
|
||||
padding: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
.tiptap pre code {
|
||||
background: none;
|
||||
color: inherit;
|
||||
font-size: 0.8rem;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* Code styling */
|
||||
.tiptap pre .hljs-comment,
|
||||
.tiptap pre .hljs-quote {
|
||||
color: #616161;
|
||||
}
|
||||
|
||||
.tiptap pre .hljs-variable,
|
||||
.tiptap pre .hljs-template-variable,
|
||||
.tiptap pre .hljs-attribute,
|
||||
.tiptap pre .hljs-tag,
|
||||
.tiptap pre .hljs-regexp,
|
||||
.tiptap pre .hljs-link,
|
||||
.tiptap pre .hljs-name,
|
||||
.tiptap pre .hljs-selector-id,
|
||||
.tiptap pre .hljs-selector-class {
|
||||
color: #f98181;
|
||||
}
|
||||
|
||||
.tiptap pre .hljs-number,
|
||||
.tiptap pre .hljs-meta,
|
||||
.tiptap pre .hljs-built_in,
|
||||
.tiptap pre .hljs-builtin-name,
|
||||
.tiptap pre .hljs-literal,
|
||||
.tiptap pre .hljs-type,
|
||||
.tiptap pre .hljs-params {
|
||||
color: #fbbc88;
|
||||
}
|
||||
|
||||
.tiptap pre .hljs-string,
|
||||
.tiptap pre .hljs-symbol,
|
||||
.tiptap pre .hljs-bullet {
|
||||
color: #b9f18d;
|
||||
}
|
||||
|
||||
.tiptap pre .hljs-title,
|
||||
.tiptap pre .hljs-section {
|
||||
color: #faf594;
|
||||
}
|
||||
|
||||
.tiptap pre .hljs-keyword,
|
||||
.tiptap pre .hljs-selector-tag {
|
||||
color: #70cff8;
|
||||
}
|
||||
|
||||
.tiptap pre .hljs-emphasis {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.tiptap pre .hljs-strong {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
@@ -16,4 +16,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+747
-619
File diff suppressed because it is too large
Load Diff
+1
-8
@@ -9,12 +9,5 @@
|
||||
"scripts": {
|
||||
"dev": "docker compose up -d",
|
||||
"compose:start": "docker compose -f docker-compose.yml up -d"
|
||||
},
|
||||
"dependencies": {
|
||||
"@testing-library/react": "^16.3.0",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"cytoscape-fcose": "^2.2.0",
|
||||
"graphology-layout-forceatlas2": "^0.10.1",
|
||||
"vitest": "^3.1.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user