Compare commits
154 Commits
438c52e4d5
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 4749dd078a | |||
| 94bf310540 | |||
| a3250c54a8 | |||
| 41f123c355 | |||
| 5913bc4832 | |||
| fa8a19a020 | |||
| 41e6b8e20f | |||
| f64947ef79 | |||
| 8f9d8472de | |||
| 003ec21c42 | |||
| bbf5844e0e | |||
| 5b80b22b60 | |||
| f2bbabc25e | |||
| 27e51424b0 | |||
| 6ec917b3cc | |||
| 978919b410 | |||
| e4028f58a8 | |||
| 603f9389b7 | |||
| 187522518f | |||
| 6a4e57ccff | |||
| 05d6a536b5 | |||
| f8549fd6f3 | |||
| 02b8bc8a3f | |||
| 2a1a3e3b30 | |||
| ebb845516e | |||
| 099ef92187 | |||
| 9a378b1fda | |||
| 444ca83955 | |||
| f88545f689 | |||
| ac4855a70e | |||
| 45513692d3 | |||
| 9fe466a144 | |||
| 7aa91f7c59 | |||
| 88cb9ef487 | |||
| a80fdf5529 | |||
| 227f82a718 | |||
| f3d028b85d | |||
| 51d77b2f7a | |||
| 8c4b3eeadc | |||
| 23fb120bb2 | |||
| a6033a523e | |||
| 298433ed30 | |||
| 407064158b | |||
| 520891c50d | |||
| 0317a2d577 | |||
| 52a8bb8222 | |||
| 3691151bd4 | |||
| 69438bd976 | |||
| 0efab8e254 | |||
| b20cacee25 | |||
| 4356630fc6 | |||
| 6edb3208aa | |||
| 28c56b6e62 | |||
| 0fadba71e6 | |||
| 17ebfd99dd | |||
| fe2a15afca | |||
| 56f6613537 | |||
| 85ecda1a24 | |||
| 287c94b4e0 | |||
| f33cec7658 | |||
| 392f3c3540 | |||
| 959d68a864 | |||
| 56e8f38cde | |||
| 859ae4bc66 | |||
| d88d9df957 | |||
| ca2a71b82a | |||
| 95944b5b0d | |||
| e1e49d776e | |||
| 1d639e61ce | |||
| 4c7755dfcf | |||
| 99a2bf64ea | |||
| ffc8bc129a | |||
| c42dd79dfe | |||
| 11e31ce6fa | |||
| 040650e1c3 | |||
| a39b043f1b | |||
| 622df54436 | |||
| 50f9c79445 | |||
| d0d79150e7 | |||
| 8e6d868954 | |||
| 6e7daafb83 | |||
| dcf03fbf2a | |||
| d398dcb8ea | |||
| 302adba66c | |||
| 7f68bb47cf | |||
| fe0621fb53 | |||
| e0c26518c3 | |||
| b1f8fb2338 | |||
| 78879d7c14 | |||
| 9d61ffc3d3 | |||
| 889908a240 | |||
| 31048654b6 | |||
| 2fab5e6d1d | |||
| c544538bc1 | |||
| df5dfcbf30 | |||
| a97927a29a | |||
| 39fb777ae6 | |||
| 23bc477319 | |||
| c59f7ab429 | |||
| b520f53ae5 | |||
| 1fdd3194ab | |||
| b30e07282e | |||
| 11f507fe13 | |||
| 43cb2b6cd7 | |||
| 52e229bc6f | |||
| 37333b5b27 | |||
| 1e6993b03f | |||
| d4f51f013b | |||
| 0d39215a1c | |||
| 598a1ebc51 | |||
| d3ce23d9b0 | |||
| e346d6df7e | |||
| 1fac38dbe0 | |||
| 9695382070 | |||
| 35d1d97856 | |||
| c922f8cd93 | |||
| 53de314cf6 | |||
| 3fe1e5247e | |||
| 3aac36b116 | |||
| b07c989af2 | |||
| 6c86a717ff | |||
| 58fafc677e | |||
| dc93adf52a | |||
| b109203f4f | |||
| 5340bf9844 | |||
| 0bd23bdfec | |||
| 1a65e7943d | |||
| fa55771fff | |||
| a53ff29dba | |||
| 904e6b253a | |||
| 399e4efdad | |||
| e2210f8b66 | |||
| 66ae5397de | |||
|
|
5c47ff6fad | ||
|
|
d756489a5c | ||
|
|
ae88eade67 | ||
|
|
c015795c01 | ||
|
|
51502a1e9f | ||
|
|
6f422f2085 | ||
|
|
1e5d543480 | ||
|
|
becbe8ef4d | ||
|
|
c510f7985a | ||
|
|
30ad6dcc03 | ||
|
|
bd1220281a | ||
|
|
acbf889b96 | ||
|
|
e5714a8581 | ||
|
|
1d3c919214 | ||
|
|
e17f47cefe | ||
|
|
6ba208852e | ||
|
|
2a0b4da479 | ||
|
|
fcebf043cc | ||
|
|
93086ed32e | ||
|
|
e098e69977 | ||
|
|
b69d23d57f |
16
.gitignore
vendored
@@ -5,3 +5,19 @@ __pycache__
|
||||
.zipignore
|
||||
.gitignore
|
||||
.DS_Store
|
||||
node_modules
|
||||
dist
|
||||
src-tauri/target
|
||||
src-tauri/binaries
|
||||
scripts/.sidecar-build
|
||||
.sidecar-build
|
||||
src-tauri/gen
|
||||
package-lock.json
|
||||
Cargo.lock
|
||||
*.lock
|
||||
*.o
|
||||
*.dylib
|
||||
out
|
||||
build
|
||||
*.tmp
|
||||
*.app
|
||||
|
||||
153
README.md
@@ -1,94 +1,95 @@
|
||||
# Concept Maker GUI
|
||||
# Concept Maker
|
||||
|
||||
A desktop tool to turn raw ideas, notes, and files into a clear, actionable project concept. Drag in files, jot notes, use automated websearch to find prior art, build a compact knowledge base, generate an editable Markdown concept using a local LLM, convert it to pdf and push your concept to a Git repo.
|
||||
A Tauri desktop app that turns raw ideas, notes, URLs, and files into a clear project concept. The UI is React/Vite, the desktop shell is Tauri, and the Python backend is exposed through `concept_api.py`.
|
||||
|
||||
## Features
|
||||
- Drag and drop files/folders into a table (falls back to add buttons).
|
||||
- Freeform notes area for thoughts and fragments.
|
||||
- Builds a JSONL knowledge base from your files (uses `corpus_builder.py` when present; includes a simple fallback).
|
||||
- Generates a polished Concept (Markdown) via a local Ollama model.
|
||||
- Prior-art search via SearXNG: generates smart queries, fetches pages, embeds + reranks, and shows a results window.
|
||||
- Edit the result in‑app, then save it into a local Git repo and optionally push to a remote.
|
||||
- Remembers sessions; re‑open and continue later.
|
||||
- Uses `icon.png` for the window/taskbar/dock icon.
|
||||
|
||||
- Add files, folders, and URLs as source material.
|
||||
- Write freeform notes and ask a local Ollama model to rephrase, extend, or generate a concept.
|
||||
- Build a JSONL knowledge base from selected files using `corpus_builder.py` when available, with a lightweight fallback in the backend.
|
||||
- Search for prior art through SearXNG and Ollama embeddings.
|
||||
- Preview concepts as Markdown/PDF.
|
||||
- Generate an image prompt and optional image asset for a concept.
|
||||
- Save and reopen local sessions.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Node.js and npm
|
||||
- Rust toolchain
|
||||
- Python 3.9+
|
||||
- Ollama running locally (default `http://localhost:11434`)
|
||||
- Suggested default model: `mistral3.2-small:24b` (configurable in the UI)
|
||||
- OS packages as needed for Tk:
|
||||
- macOS: included with the official Python.org installer
|
||||
- Ubuntu/Debian: `sudo apt-get install python3-tk`
|
||||
- Windows: included with the official Python.org installer
|
||||
- Ollama running locally, defaulting to `http://localhost:11434`
|
||||
- Optional local SearXNG instance for prior-art search, defaulting to `http://localhost:8888`
|
||||
|
||||
Optional Python packages improve file ingestion:
|
||||
- `tkinterdnd2` (native drag & drop)
|
||||
- `pymupdf` (PDF text extraction)
|
||||
- `beautifulsoup4` (better HTML text extraction)
|
||||
Python packages are listed in `requirements.txt`. Some features also depend on external command-line tools:
|
||||
|
||||
Prior‑art search requires API access to a SearXNG instance:
|
||||
- Recommended: run SearXNG locally via Docker (installation/compose details are out of scope for this repo).
|
||||
- Project site: https://searxng.org
|
||||
- `pandoc` or `wkhtmltopdf` for higher-quality Markdown to PDF export
|
||||
- `tesseract` and `ocrmypdf` for OCR-heavy ingestion
|
||||
- `ffmpeg`/`ffprobe` for media handling
|
||||
|
||||
Note: `requirements.txt` also lists some optional extras and system tools. If installation fails on entries that are not Python packages (e.g., system binaries), install them via your OS package manager or comment those lines out.
|
||||
## Setup
|
||||
|
||||
## Quick Start
|
||||
- With the convenience script:
|
||||
- `bash run.sh`
|
||||
- Manual steps:
|
||||
- `python3 -m venv .venv`
|
||||
- `source .venv/bin/activate` (Windows: `.\\.venv\\Scripts\\activate`)
|
||||
- `python -m pip install --upgrade pip`
|
||||
- `pip install -r requirements.txt`
|
||||
- `python concept-maker_gui.py`
|
||||
Install JavaScript dependencies:
|
||||
|
||||
Ensure Ollama is running before generating concepts:
|
||||
- Install: https://ollama.com
|
||||
- Pull a model: `ollama pull mistral3.2-small:24b`
|
||||
- Start service (if not auto-started): `ollama serve`
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
## Usage
|
||||
- Add files/folders via drag & drop or the Add buttons.
|
||||
- Write or paste notes in the Notes panel.
|
||||
- Choose the Ollama model (or keep your default).
|
||||
- Click to generate the Concept; edit as needed.
|
||||
- Save: the app can save to a local repo and push to a remote.
|
||||
Install Python backend dependencies:
|
||||
|
||||
### Prior‑Art Search (SearXNG)
|
||||
- In the Notes section, click "Find Prior Art".
|
||||
- Configure the SearXNG endpoint in the bottom bar (default `http://localhost:8888`).
|
||||
- The app will:
|
||||
- Use the selected Ollama model to generate exactly three search queries (based on your Notes, Knowledge Base, and asset filenames).
|
||||
- Query SearXNG, fetch promising pages, embed them with Ollama embeddings (`bge-m3:latest` by default), and rerank by relevance.
|
||||
- Open a results window showing URLs, scores, and content snippets; double‑click a row to open in your browser.
|
||||
```bash
|
||||
python3 -m venv .venv
|
||||
source .venv/bin/activate
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Configuration
|
||||
Environment variables (optional):
|
||||
- `OLLAMA_HOST`: override Ollama URL (default `http://localhost:11434`).
|
||||
- `IDEA_HOLE_MODEL`: default model name shown in the UI.
|
||||
- `IDEA_HOLE_REMOTE`: default Git remote URL.
|
||||
- `SEARX_URL`: default SearXNG base URL for prior‑art search (default `http://localhost:8888`).
|
||||
Ensure Ollama is running before using model-backed actions:
|
||||
|
||||
## Data & Storage
|
||||
- Working data lives under `./.idea-hole/`:
|
||||
- `files/`: symlinks/copies of added files
|
||||
- `corpus.jsonl`: unified knowledge base
|
||||
- `sessions.jsonl`: saved sessions metadata
|
||||
|
||||
## Platform Notes
|
||||
- macOS dock icon: if you install PyObjC (`pip install pyobjc`), the app also sets the dock icon from `icon.png`.
|
||||
- Drag & drop requires `tkinterdnd2`; otherwise, the app uses the add buttons.
|
||||
- PDF extraction works best with `pymupdf` installed.
|
||||
|
||||
## Troubleshooting
|
||||
- Tk import errors on Linux: install `python3-tk` via your package manager.
|
||||
- Ollama connection errors: ensure `ollama serve` is running and the model is pulled.
|
||||
- Prior‑art search returns nothing: ensure your SearXNG instance is reachable at the configured URL and supports `/search?format=json`.
|
||||
- Pip fails on non-Python entries in `requirements.txt`: install those tools via your OS, or comment out the offending lines and rerun the install.
|
||||
```bash
|
||||
ollama serve
|
||||
```
|
||||
|
||||
## Development
|
||||
- Code entry point: `concept-maker_gui.py`
|
||||
- Launcher script: `run.sh`
|
||||
- Optional corpus builder: `corpus_builder.py` (if present) is invoked for richer ingestion; otherwise, a simple built‑in fallback is used.
|
||||
|
||||
Prior‑art module: `websearch.py`
|
||||
Run the desktop app:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Run the web UI in a browser:
|
||||
|
||||
```bash
|
||||
npm run dev:web
|
||||
```
|
||||
|
||||
Build the frontend:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
Build the desktop bundle:
|
||||
|
||||
```bash
|
||||
npm run tauri build
|
||||
```
|
||||
|
||||
## Project Layout
|
||||
|
||||
- `src/`: React frontend
|
||||
- `src-tauri/`: Tauri desktop shell and Rust commands
|
||||
- `concept_api.py`: JSON action backend invoked by Tauri
|
||||
- `corpus_builder.py`: optional richer file ingestion pipeline
|
||||
- `websearch.py`: prior-art search helpers
|
||||
- `requirements.txt`: Python backend dependencies
|
||||
|
||||
## Configuration
|
||||
|
||||
Environment variables:
|
||||
|
||||
- `OLLAMA_HOST`: override the Ollama URL
|
||||
- `IDEA_HOLE_MODEL`: default model name
|
||||
- `SEARX_URL`: default SearXNG base URL
|
||||
|
||||
Runtime data is stored in `.idea-hole/`.
|
||||
|
||||
3167
concept-maker_gui.py
1436
concept_api.py
Normal file
BIN
icon.png
|
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 946 KiB |
12
index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Idea -> Concept</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
34
package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "concept-maker-tauri",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "tauri dev",
|
||||
"icons": "tauri icon icon.png",
|
||||
"prepare:tauri-dev": "npm run icons && npm run build:backend && npm run dev:vite",
|
||||
"prepare:tauri-build": "npm run icons && npm run build:backend && npm run build:web",
|
||||
"build:backend": "node scripts/build-python-sidecar.mjs",
|
||||
"dev:vite": "vite --host 127.0.0.1",
|
||||
"dev:web": "vite --host 127.0.0.1 --open",
|
||||
"build": "npm run build:web",
|
||||
"build:web": "tsc && vite build",
|
||||
"preview": "vite preview",
|
||||
"tauri": "tauri"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.0.0",
|
||||
"@tauri-apps/plugin-dialog": "^2.0.0",
|
||||
"markdown-it": "14.1.1",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tauri-apps/cli": "^2.0.0",
|
||||
"@types/react": "^18.3.18",
|
||||
"@types/react-dom": "^18.3.5",
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"typescript": "^5.6.3",
|
||||
"vite": "^5.4.8"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
# Core libraries used by the GUI (concept_gui.py) and corpus builder
|
||||
# Core libraries used by the Tauri Python backend and corpus builder
|
||||
pymupdf
|
||||
beautifulsoup4
|
||||
requests
|
||||
@@ -8,7 +8,6 @@ numpy
|
||||
tqdm
|
||||
ebooklib
|
||||
markdown
|
||||
tkinterdnd2
|
||||
pdflatex
|
||||
|
||||
# Optional: language detection and image text-likeness improvements
|
||||
@@ -18,6 +17,7 @@ opencv-python-headless
|
||||
# Optional (ASR for audio/video in corpus_builder.py)
|
||||
openai-whisper
|
||||
torch
|
||||
transformers
|
||||
|
||||
# Notes (external binaries, install via system package manager):
|
||||
# - pandoc (for high‑quality Markdown→PDF)
|
||||
|
||||
32
run.sh
@@ -1,32 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Resolve to repo root (directory of this script)
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# Pick a Python executable
|
||||
if command -v python3 >/dev/null 2>&1; then
|
||||
PY=python3
|
||||
else
|
||||
PY=python
|
||||
fi
|
||||
|
||||
echo "[setup] Creating virtual environment in .venv"
|
||||
"$PY" -m venv .venv
|
||||
|
||||
# Activate venv
|
||||
echo "[setup] Activating virtual environment"
|
||||
source .venv/bin/activate
|
||||
|
||||
# Upgrade pip (optional but helpful)
|
||||
python -m pip install --upgrade pip >/dev/null 2>&1 || true
|
||||
|
||||
# Install requirements
|
||||
echo "[deps] Installing requirements from requirements.txt"
|
||||
python -m pip install -r requirements.txt
|
||||
|
||||
# Launch the app
|
||||
echo "[run] Starting Concept Maker GUI"
|
||||
exec python concept-maker_gui.py
|
||||
|
||||
110
scripts/build-python-sidecar.mjs
Normal file
@@ -0,0 +1,110 @@
|
||||
import { existsSync, mkdirSync, statSync } from "node:fs";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { execFileSync, spawnSync } from "node:child_process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const python = existsSync(join(root, ".venv", "bin", "python"))
|
||||
? join(root, ".venv", "bin", "python")
|
||||
: "python3";
|
||||
|
||||
function run(command, args, options = {}) {
|
||||
const result = spawnSync(command, args, {
|
||||
cwd: root,
|
||||
stdio: "inherit",
|
||||
env: process.env,
|
||||
...options,
|
||||
});
|
||||
if (result.status !== 0) {
|
||||
process.exit(result.status ?? 1);
|
||||
}
|
||||
}
|
||||
|
||||
function read(command, args) {
|
||||
return execFileSync(command, args, { cwd: root, encoding: "utf8" }).trim();
|
||||
}
|
||||
|
||||
function targetTriple() {
|
||||
const explicit =
|
||||
process.env.TAURI_ENV_TARGET_TRIPLE ||
|
||||
process.env.CARGO_BUILD_TARGET ||
|
||||
process.env.TARGET;
|
||||
if (explicit) return explicit;
|
||||
|
||||
const rustc = read("rustc", ["-vV"]);
|
||||
const host = rustc
|
||||
.split(/\r?\n/)
|
||||
.find((line) => line.startsWith("host:"))
|
||||
?.replace("host:", "")
|
||||
.trim();
|
||||
if (!host) {
|
||||
throw new Error("Could not determine Rust target triple.");
|
||||
}
|
||||
return host;
|
||||
}
|
||||
|
||||
function newestMtime(paths) {
|
||||
return Math.max(...paths.map((path) => statSync(path).mtimeMs));
|
||||
}
|
||||
|
||||
const target = targetTriple();
|
||||
const binariesDir = join(root, "src-tauri", "binaries");
|
||||
const sidecar = join(binariesDir, `concept-api-${target}${target.includes("windows") ? ".exe" : ""}`);
|
||||
const sources = [
|
||||
join(root, "concept_api.py"),
|
||||
join(root, "websearch.py"),
|
||||
];
|
||||
|
||||
mkdirSync(binariesDir, { recursive: true });
|
||||
|
||||
if (
|
||||
existsSync(sidecar) &&
|
||||
statSync(sidecar).mtimeMs >= newestMtime(sources) &&
|
||||
process.argv.includes("--force") === false
|
||||
) {
|
||||
console.log(`Python sidecar is up to date: ${sidecar}`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const pyinstallerCheck = spawnSync(python, ["-m", "PyInstaller", "--version"], {
|
||||
cwd: root,
|
||||
stdio: "ignore",
|
||||
});
|
||||
if (pyinstallerCheck.status !== 0) {
|
||||
run(python, ["-m", "pip", "install", "pyinstaller"]);
|
||||
}
|
||||
|
||||
run(python, [
|
||||
"-m",
|
||||
"PyInstaller",
|
||||
"--noconfirm",
|
||||
"--clean",
|
||||
"--onefile",
|
||||
"--name",
|
||||
`concept-api-${target}`,
|
||||
"--distpath",
|
||||
binariesDir,
|
||||
"--workpath",
|
||||
join(root, ".sidecar-build", "work"),
|
||||
"--specpath",
|
||||
join(root, ".sidecar-build"),
|
||||
"--paths",
|
||||
root,
|
||||
"--hidden-import",
|
||||
"fitz",
|
||||
"--hidden-import",
|
||||
"bs4",
|
||||
"--hidden-import",
|
||||
"PIL",
|
||||
"--hidden-import",
|
||||
"PIL.Image",
|
||||
"--exclude-module",
|
||||
"torch",
|
||||
"--exclude-module",
|
||||
"transformers",
|
||||
"--exclude-module",
|
||||
"whisper",
|
||||
"--exclude-module",
|
||||
"cv2",
|
||||
join(root, "concept_api.py"),
|
||||
]);
|
||||
14
src-tauri/Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "concept-maker"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = [] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
tauri-plugin-dialog = "2"
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
16
src-tauri/build.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
fn main() {
|
||||
for path in [
|
||||
"../icon.png",
|
||||
"icons/icon.png",
|
||||
"icons/32x32.png",
|
||||
"icons/64x64.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico",
|
||||
] {
|
||||
println!("cargo:rerun-if-changed={path}");
|
||||
}
|
||||
|
||||
tauri_build::build()
|
||||
}
|
||||
10
src-tauri/capabilities/default.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"identifier": "default",
|
||||
"description": "Default capabilities",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"dialog:default",
|
||||
"run-python-action"
|
||||
]
|
||||
}
|
||||
BIN
src-tauri/icons/128x128.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
src-tauri/icons/128x128@2x.png
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
src-tauri/icons/32x32.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
src-tauri/icons/64x64.png
Normal file
|
After Width: | Height: | Size: 5.6 KiB |
BIN
src-tauri/icons/Square107x107Logo.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
src-tauri/icons/Square142x142Logo.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
src-tauri/icons/Square150x150Logo.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
src-tauri/icons/Square284x284Logo.png
Normal file
|
After Width: | Height: | Size: 63 KiB |
BIN
src-tauri/icons/Square30x30Logo.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src-tauri/icons/Square310x310Logo.png
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
src-tauri/icons/Square44x44Logo.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
src-tauri/icons/Square71x71Logo.png
Normal file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
src-tauri/icons/Square89x89Logo.png
Normal file
|
After Width: | Height: | Size: 8.9 KiB |
BIN
src-tauri/icons/StoreLogo.png
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
</adaptive-icon>
|
||||
BIN
src-tauri/icons/android/mipmap-hdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
src-tauri/icons/android/mipmap-hdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
src-tauri/icons/android/mipmap-hdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
src-tauri/icons/android/mipmap-mdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
src-tauri/icons/android/mipmap-mdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
src-tauri/icons/android/mipmap-mdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
src-tauri/icons/android/mipmap-xhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 8.8 KiB |
BIN
src-tauri/icons/android/mipmap-xhdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
src-tauri/icons/android/mipmap-xhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
src-tauri/icons/android/mipmap-xxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
src-tauri/icons/android/mipmap-xxhdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
src-tauri/icons/android/mipmap-xxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
src-tauri/icons/android/mipmap-xxxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 140 KiB |
BIN
src-tauri/icons/android/mipmap-xxxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="ic_launcher_background">#fff</color>
|
||||
</resources>
|
||||
BIN
src-tauri/icons/icon.icns
Normal file
BIN
src-tauri/icons/icon.ico
Normal file
|
After Width: | Height: | Size: 67 KiB |
BIN
src-tauri/icons/icon.png
Normal file
|
After Width: | Height: | Size: 189 KiB |
BIN
src-tauri/icons/ios/AppIcon-20x20@1x.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
src-tauri/icons/ios/AppIcon-20x20@2x-1.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src-tauri/icons/ios/AppIcon-20x20@2x.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src-tauri/icons/ios/AppIcon-20x20@3x.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
src-tauri/icons/ios/AppIcon-29x29@1x.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
src-tauri/icons/ios/AppIcon-29x29@2x-1.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
src-tauri/icons/ios/AppIcon-29x29@2x.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
src-tauri/icons/ios/AppIcon-29x29@3x.png
Normal file
|
After Width: | Height: | Size: 8.2 KiB |
BIN
src-tauri/icons/ios/AppIcon-40x40@1x.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src-tauri/icons/ios/AppIcon-40x40@2x-1.png
Normal file
|
After Width: | Height: | Size: 7.3 KiB |
BIN
src-tauri/icons/ios/AppIcon-40x40@2x.png
Normal file
|
After Width: | Height: | Size: 7.3 KiB |
BIN
src-tauri/icons/ios/AppIcon-40x40@3x.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
src-tauri/icons/ios/AppIcon-512@2x.png
Normal file
|
After Width: | Height: | Size: 604 KiB |
BIN
src-tauri/icons/ios/AppIcon-60x60@2x.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
src-tauri/icons/ios/AppIcon-60x60@3x.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
src-tauri/icons/ios/AppIcon-76x76@1x.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
src-tauri/icons/ios/AppIcon-76x76@2x.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
src-tauri/icons/ios/AppIcon-83.5x83.5@2x.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
4
src-tauri/permissions/run-python-action.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[[permission]]
|
||||
identifier = "run-python-action"
|
||||
description = "Allow the UI to invoke the Python backend"
|
||||
commands.allow = ["run_python_action", "open_path"]
|
||||
250
src-tauri/src/lib.rs
Normal file
@@ -0,0 +1,250 @@
|
||||
use serde_json::Value;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command as ProcessCommand, Stdio};
|
||||
use tauri::{
|
||||
menu::{Menu, MenuItem, Submenu},
|
||||
AppHandle, Emitter, Manager,
|
||||
};
|
||||
|
||||
fn repo_root() -> PathBuf {
|
||||
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
manifest_dir.parent().unwrap_or(&manifest_dir).to_path_buf()
|
||||
}
|
||||
|
||||
enum Backend {
|
||||
Sidecar(PathBuf),
|
||||
Source { python: String, script: PathBuf },
|
||||
}
|
||||
|
||||
fn sidecar_names() -> Vec<&'static str> {
|
||||
if cfg!(target_os = "windows") {
|
||||
vec![
|
||||
"concept-api.exe",
|
||||
"concept-api-x86_64-pc-windows-msvc.exe",
|
||||
"concept-api-aarch64-pc-windows-msvc.exe",
|
||||
]
|
||||
} else if cfg!(target_os = "macos") {
|
||||
vec![
|
||||
"concept-api",
|
||||
"concept-api-aarch64-apple-darwin",
|
||||
"concept-api-x86_64-apple-darwin",
|
||||
]
|
||||
} else {
|
||||
vec![
|
||||
"concept-api",
|
||||
"concept-api-x86_64-unknown-linux-gnu",
|
||||
"concept-api-aarch64-unknown-linux-gnu",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
fn push_sidecar_candidates(candidates: &mut Vec<PathBuf>, dir: &Path) {
|
||||
for name in sidecar_names() {
|
||||
candidates.push(dir.join(name));
|
||||
}
|
||||
}
|
||||
|
||||
fn sidecar_candidates(app: &AppHandle) -> Vec<PathBuf> {
|
||||
let mut candidates = Vec::new();
|
||||
let root = repo_root();
|
||||
push_sidecar_candidates(&mut candidates, &root.join("src-tauri").join("binaries"));
|
||||
|
||||
if let Ok(exe) = std::env::current_exe() {
|
||||
if let Some(exe_dir) = exe.parent() {
|
||||
push_sidecar_candidates(&mut candidates, exe_dir);
|
||||
if let Some(contents_dir) = exe_dir.parent() {
|
||||
push_sidecar_candidates(&mut candidates, &contents_dir.join("Resources"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(resource_dir) = app.path().resource_dir() {
|
||||
push_sidecar_candidates(&mut candidates, &resource_dir);
|
||||
push_sidecar_candidates(&mut candidates, &resource_dir.join("binaries"));
|
||||
}
|
||||
|
||||
candidates
|
||||
}
|
||||
|
||||
fn bundled_sidecar(app: &AppHandle) -> Option<PathBuf> {
|
||||
sidecar_candidates(app)
|
||||
.into_iter()
|
||||
.find(|candidate| candidate.is_file())
|
||||
}
|
||||
|
||||
fn source_backend_script() -> PathBuf {
|
||||
repo_root().join("concept_api.py")
|
||||
}
|
||||
|
||||
fn backend(app: &AppHandle) -> Result<Backend, String> {
|
||||
let script = source_backend_script();
|
||||
if cfg!(debug_assertions) && script.exists() {
|
||||
return Ok(Backend::Source {
|
||||
python: "python3".to_string(),
|
||||
script,
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(sidecar) = bundled_sidecar(app) {
|
||||
return Ok(Backend::Sidecar(sidecar));
|
||||
}
|
||||
|
||||
if script.exists() {
|
||||
return Ok(Backend::Source {
|
||||
python: "python3".to_string(),
|
||||
script,
|
||||
});
|
||||
}
|
||||
|
||||
Err("Python backend not found. Rebuild the app to package the backend sidecar.".to_string())
|
||||
}
|
||||
|
||||
fn backend_data_dir(app: &AppHandle, backend: &Backend) -> PathBuf {
|
||||
match backend {
|
||||
Backend::Source { .. } => repo_root().join(".idea-hole"),
|
||||
Backend::Sidecar(_) => app
|
||||
.path()
|
||||
.app_data_dir()
|
||||
.unwrap_or_else(|_| repo_root().join(".idea-hole")),
|
||||
}
|
||||
}
|
||||
|
||||
fn command_for_backend(backend: &Backend) -> ProcessCommand {
|
||||
match backend {
|
||||
Backend::Sidecar(path) => ProcessCommand::new(path),
|
||||
Backend::Source { python, script } => {
|
||||
let mut command = ProcessCommand::new(python);
|
||||
command.arg(script);
|
||||
command
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_backend(app: &AppHandle, backend: &Backend, input: &str) -> Result<Vec<u8>, String> {
|
||||
let data_dir = backend_data_dir(app, backend);
|
||||
if let Err(err) = std::fs::create_dir_all(&data_dir) {
|
||||
return Err(format!("Failed to create backend data directory: {err}"));
|
||||
}
|
||||
let cwd = match backend {
|
||||
Backend::Source { .. } => repo_root(),
|
||||
Backend::Sidecar(_) => data_dir.clone(),
|
||||
};
|
||||
|
||||
let mut child = match command_for_backend(backend)
|
||||
.current_dir(cwd)
|
||||
.env("CONCEPT_MAKER_DATA_DIR", &data_dir)
|
||||
.env(
|
||||
"PATH",
|
||||
"/opt/homebrew/bin:/usr/local/bin:/opt/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
|
||||
)
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
{
|
||||
Ok(child) => child,
|
||||
Err(err) => {
|
||||
return Err(format!("Failed to start Python backend: {err}"));
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(mut stdin) = child.stdin.take() {
|
||||
if let Err(err) = stdin.write_all(input.as_bytes()) {
|
||||
return Err(format!("Failed to write to Python stdin: {err}"));
|
||||
}
|
||||
}
|
||||
|
||||
let output = child
|
||||
.wait_with_output()
|
||||
.map_err(|err| format!("Python backend failed to finish: {err}"))?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
return Err(format!("Python backend failed: {stderr}"));
|
||||
}
|
||||
|
||||
Ok(output.stdout)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn run_python_action(app: AppHandle, action: String, payload: Value) -> Result<Value, String> {
|
||||
let req = serde_json::json!({
|
||||
"action": action,
|
||||
"payload": payload,
|
||||
});
|
||||
let input = serde_json::to_string(&req).map_err(|e| e.to_string())?;
|
||||
let backend = backend(&app)?;
|
||||
let stdout = run_backend(&app, &backend, &input)?;
|
||||
let resp: Value = serde_json::from_slice(&stdout).map_err(|e| e.to_string())?;
|
||||
if resp.get("ok") == Some(&Value::Bool(true)) {
|
||||
Ok(resp.get("data").cloned().unwrap_or(Value::Null))
|
||||
} else {
|
||||
let error = resp
|
||||
.get("error")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("Unknown backend error");
|
||||
Err(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn open_path(path: String) -> Result<(), String> {
|
||||
let path = PathBuf::from(path);
|
||||
if !path.exists() {
|
||||
return Err(format!("Path does not exist: {}", path.display()));
|
||||
}
|
||||
|
||||
let mut command = if cfg!(target_os = "macos") {
|
||||
let mut command = ProcessCommand::new("open");
|
||||
command.arg(&path);
|
||||
command
|
||||
} else if cfg!(target_os = "windows") {
|
||||
let mut command = ProcessCommand::new("cmd");
|
||||
command.arg("/C").arg("start").arg("").arg(&path);
|
||||
command
|
||||
} else {
|
||||
let mut command = ProcessCommand::new("xdg-open");
|
||||
command.arg(&path);
|
||||
command
|
||||
};
|
||||
|
||||
command
|
||||
.spawn()
|
||||
.map(|_| ())
|
||||
.map_err(|err| format!("Failed to open {}: {err}", path.display()))
|
||||
}
|
||||
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.menu(|handle| {
|
||||
let quit_item =
|
||||
MenuItem::with_id(handle, "app-quit", "Quit", true, Some("CmdOrCtrl+Q"))?;
|
||||
let app_menu = Submenu::with_items(handle, "Concept Maker", true, &[&quit_item])?;
|
||||
|
||||
let new_item = MenuItem::with_id(handle, "file-new", "New", true, None::<&str>)?;
|
||||
let open_item = MenuItem::with_id(handle, "file-open", "Open", true, None::<&str>)?;
|
||||
let save_item = MenuItem::with_id(handle, "file-save", "Save", true, None::<&str>)?;
|
||||
let file_menu =
|
||||
Submenu::with_items(handle, "File", true, &[&new_item, &open_item, &save_item])?;
|
||||
|
||||
let settings_item =
|
||||
MenuItem::with_id(handle, "settings-open", "Settings", true, None::<&str>)?;
|
||||
let settings_menu = Submenu::with_items(handle, "Settings", true, &[&settings_item])?;
|
||||
|
||||
Menu::with_items(handle, &[&app_menu, &file_menu, &settings_menu])
|
||||
})
|
||||
.on_menu_event(|app, event| match event.id().as_ref() {
|
||||
"app-quit" => {
|
||||
app.exit(0);
|
||||
}
|
||||
"file-new" | "file-open" | "file-save" | "settings-open" => {
|
||||
let _ = app.emit("app-menu-action", event.id().as_ref());
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![run_python_action, open_path])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
3
src-tauri/src/main.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
concept_maker::run();
|
||||
}
|
||||
39
src-tauri/tauri.conf.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/tauri-apps/tauri/dev/tooling/cli/schema.json",
|
||||
"productName": "Concept Maker",
|
||||
"version": "0.1.0",
|
||||
"identifier": "com.giers.conceptmaker",
|
||||
"build": {
|
||||
"beforeDevCommand": "npm run prepare:tauri-dev",
|
||||
"beforeBuildCommand": "npm run prepare:tauri-build",
|
||||
"devUrl": "http://127.0.0.1:5173",
|
||||
"frontendDist": "../dist"
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"label": "main",
|
||||
"title": "Idea -> Concept",
|
||||
"width": 1200,
|
||||
"height": 820,
|
||||
"minWidth": 900,
|
||||
"minHeight": 640
|
||||
}
|
||||
]
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"externalBin": [
|
||||
"binaries/concept-api"
|
||||
],
|
||||
"icon": [
|
||||
"icons/icon.png",
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
}
|
||||
}
|
||||
966
src/App.tsx
Normal file
@@ -0,0 +1,966 @@
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { open, save } from "@tauri-apps/plugin-dialog";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { getCurrentWebview } from "@tauri-apps/api/webview";
|
||||
import { markdownToHTML } from "./markdown/markdown";
|
||||
import "./markdown/markdown-render.css";
|
||||
|
||||
type FileEntry = {
|
||||
kind: "file";
|
||||
path: string;
|
||||
name: string;
|
||||
type: string;
|
||||
size: string;
|
||||
};
|
||||
|
||||
type UrlEntry = {
|
||||
kind: "url";
|
||||
url: string;
|
||||
name: string;
|
||||
type: "url";
|
||||
size: string;
|
||||
};
|
||||
|
||||
type RowEntry = FileEntry | UrlEntry;
|
||||
|
||||
type RephraseVariant = {
|
||||
key: string;
|
||||
label: string;
|
||||
text: string;
|
||||
};
|
||||
|
||||
type SessionSummary = {
|
||||
title: string;
|
||||
description: string;
|
||||
saved_at: number;
|
||||
};
|
||||
|
||||
type PriorArtResult = {
|
||||
url: string;
|
||||
title?: string;
|
||||
score?: number;
|
||||
snippet?: string;
|
||||
};
|
||||
|
||||
type PriorArtResponse = {
|
||||
queries: string[];
|
||||
lang?: string;
|
||||
results: PriorArtResult[];
|
||||
};
|
||||
|
||||
async function runBackend<T>(action: string, payload: Record<string, unknown>): Promise<T> {
|
||||
return (await invoke("run_python_action", { action, payload })) as T;
|
||||
}
|
||||
|
||||
async function openPath(path: string): Promise<void> {
|
||||
await invoke("open_path", { path });
|
||||
}
|
||||
|
||||
function formatTime(ts: number): string {
|
||||
if (!ts) return "";
|
||||
const d = new Date(ts * 1000);
|
||||
return d.toLocaleString();
|
||||
}
|
||||
|
||||
function rowId(row: RowEntry): string {
|
||||
return row.kind === "file" ? `file:${row.path}` : `url:${row.url}`;
|
||||
}
|
||||
|
||||
function pdfFileNameFromTitle(title: string, conceptText: string): string {
|
||||
const heading = conceptText.match(/^#\s+(.+)$/m)?.[1] ?? "";
|
||||
const rawName = (title || heading || "concept").trim();
|
||||
const safeName = rawName
|
||||
.replace(/\s+/g, "-")
|
||||
.replace(/[^a-zA-Z0-9._-]/g, "-")
|
||||
.replace(/-+/g, "-")
|
||||
.replace(/^[-_.]+|[-_.]+$/g, "");
|
||||
|
||||
return `${safeName || "concept"}.pdf`;
|
||||
}
|
||||
|
||||
function ensurePdfExtension(path: string): string {
|
||||
return /\.pdf$/i.test(path) ? path : `${path}.pdf`;
|
||||
}
|
||||
|
||||
function fallbackIdeaText(title: string, description: string, concept: string): string {
|
||||
return [
|
||||
title.trim() ? `Title: ${title.trim()}` : "",
|
||||
description.trim() ? `Description: ${description.trim()}` : "",
|
||||
concept.trim(),
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n\n");
|
||||
}
|
||||
|
||||
function currentIdeaText(notes: string, title: string, description: string, concept: string): string {
|
||||
return notes.trim() ? notes : fallbackIdeaText(title, description, concept);
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [status, setStatusMessage] = useState("");
|
||||
const [statusVersion, setStatusVersion] = useState(0);
|
||||
const [statusVisible, setStatusVisible] = useState(false);
|
||||
const [files, setFiles] = useState<FileEntry[]>([]);
|
||||
const [websites, setWebsites] = useState<UrlEntry[]>([]);
|
||||
const [notes, setNotes] = useState("");
|
||||
const [rephraseVariants, setRephraseVariants] = useState<RephraseVariant[]>([]);
|
||||
const [rephraseSelected, setRephraseSelected] = useState<string | null>(null);
|
||||
const [concept, setConcept] = useState("");
|
||||
const [markdownPreview, setMarkdownPreview] = useState(false);
|
||||
const [title, setTitle] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [ollamaHost, setOllamaHost] = useState("http://localhost:11434");
|
||||
const [ollamaModel, setOllamaModel] = useState("Select model...");
|
||||
const [searxUrl, setSearxUrl] = useState("http://localhost:8888");
|
||||
const [models, setModels] = useState<string[]>([]);
|
||||
const [busy, setBusy] = useState<Record<string, boolean>>({});
|
||||
|
||||
const [sessionModalOpen, setSessionModalOpen] = useState(false);
|
||||
const [sessions, setSessions] = useState<SessionSummary[]>([]);
|
||||
const [sessionsLoading, setSessionsLoading] = useState(false);
|
||||
|
||||
const [priorModalOpen, setPriorModalOpen] = useState(false);
|
||||
const [priorData, setPriorData] = useState<PriorArtResponse | null>(null);
|
||||
const [websiteModalOpen, setWebsiteModalOpen] = useState(false);
|
||||
const [websiteInput, setWebsiteInput] = useState("");
|
||||
const [websiteError, setWebsiteError] = useState("");
|
||||
const [settingsModalOpen, setSettingsModalOpen] = useState(false);
|
||||
const menuActionRef = useRef<(action: string) => void>(() => undefined);
|
||||
|
||||
const rows = useMemo<RowEntry[]>(() => [...files, ...websites], [files, websites]);
|
||||
const markdownPreviewHtml = useMemo(
|
||||
() => (markdownPreview ? markdownToHTML(concept) : ""),
|
||||
[concept, markdownPreview]
|
||||
);
|
||||
|
||||
const setStatus = (message: string) => {
|
||||
setStatusMessage(message);
|
||||
setStatusVersion((value) => value + 1);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!status) {
|
||||
setStatusVisible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setStatusVisible(true);
|
||||
const timer = window.setTimeout(() => {
|
||||
setStatusVisible(false);
|
||||
}, 5000);
|
||||
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [status, statusVersion]);
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
const bootstrap = async () => {
|
||||
try {
|
||||
const settings = await runBackend<Record<string, string>>("load_settings", {});
|
||||
if (!mounted) return;
|
||||
if (settings.ollama_host) setOllamaHost(settings.ollama_host);
|
||||
if (settings.ollama_model) setOllamaModel(settings.ollama_model);
|
||||
if (settings.searx_url) setSearxUrl(settings.searx_url);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
const list = await runBackend<string[]>("list_models", {});
|
||||
if (!mounted) return;
|
||||
setModels(list);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
};
|
||||
void bootstrap();
|
||||
return () => {
|
||||
mounted = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
runBackend("save_settings", {
|
||||
settings: {
|
||||
ollama_host: ollamaHost,
|
||||
ollama_model: ollamaModel,
|
||||
searx_url: searxUrl,
|
||||
},
|
||||
}).catch(() => undefined);
|
||||
}, 400);
|
||||
return () => clearTimeout(timer);
|
||||
}, [ollamaHost, ollamaModel, searxUrl]);
|
||||
|
||||
useEffect(() => {
|
||||
let unlisten: (() => void) | undefined;
|
||||
const attach = async () => {
|
||||
try {
|
||||
const current = getCurrentWebview() as any;
|
||||
unlisten = await current.onDragDropEvent((event: any) => {
|
||||
if (event.payload?.type === "drop") {
|
||||
const paths = event.payload.paths ?? [];
|
||||
if (paths.length) {
|
||||
void addFilesByPath(paths, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
// optional
|
||||
}
|
||||
};
|
||||
void attach();
|
||||
return () => {
|
||||
if (unlisten) unlisten();
|
||||
};
|
||||
}, [files]);
|
||||
|
||||
const addFilesByPath = async (paths: string[], expandDirs: boolean) => {
|
||||
if (!paths.length) return;
|
||||
setStatus("Indexing files...");
|
||||
try {
|
||||
const stats = await runBackend<{ name: string; path: string; type: string; size: string }[]>(
|
||||
"stat_paths",
|
||||
{ paths, expand_dirs: expandDirs }
|
||||
);
|
||||
setFiles((prev) => {
|
||||
const existing = new Map(prev.map((f) => [f.path, f]));
|
||||
stats.forEach((item) => {
|
||||
if (!existing.has(item.path)) {
|
||||
existing.set(item.path, {
|
||||
kind: "file",
|
||||
path: item.path,
|
||||
name: item.name,
|
||||
type: item.type,
|
||||
size: item.size,
|
||||
});
|
||||
}
|
||||
});
|
||||
return Array.from(existing.values());
|
||||
});
|
||||
setStatus(`Added ${stats.length} item(s)`);
|
||||
} catch (err) {
|
||||
setStatus("Failed to add files");
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
const onAddFiles = async () => {
|
||||
const selection = await open({ multiple: true, title: "Select files" });
|
||||
if (!selection) return;
|
||||
const paths = Array.isArray(selection) ? selection : [selection];
|
||||
await addFilesByPath(paths as string[], false);
|
||||
};
|
||||
|
||||
const onAddWebsite = () => {
|
||||
setWebsiteInput("");
|
||||
setWebsiteError("");
|
||||
setWebsiteModalOpen(true);
|
||||
};
|
||||
|
||||
const onSubmitWebsite = () => {
|
||||
const trimmed = websiteInput.trim();
|
||||
if (!/^https?:\/\//i.test(trimmed)) {
|
||||
setWebsiteError("Enter a valid http(s) URL.");
|
||||
return;
|
||||
}
|
||||
if (websites.some((w) => w.url === trimmed)) {
|
||||
setWebsiteError("This website is already in the table.");
|
||||
return;
|
||||
}
|
||||
|
||||
const name = trimmed.replace(/^https?:\/\//, "").slice(0, 60);
|
||||
setWebsites((prev) => [
|
||||
...prev,
|
||||
{
|
||||
kind: "url",
|
||||
url: trimmed,
|
||||
name,
|
||||
type: "url",
|
||||
size: "web",
|
||||
},
|
||||
]);
|
||||
setWebsiteModalOpen(false);
|
||||
setWebsiteInput("");
|
||||
setWebsiteError("");
|
||||
setStatus(`Added ${name}`);
|
||||
};
|
||||
|
||||
const closeWebsiteModal = () => {
|
||||
setWebsiteModalOpen(false);
|
||||
setWebsiteInput("");
|
||||
setWebsiteError("");
|
||||
};
|
||||
|
||||
const onRemoveRow = (row: RowEntry) => {
|
||||
const label = row.kind === "file" ? row.path : row.url;
|
||||
if (!window.confirm(`Remove "${row.name}" from Files & Websites?\n\n${label}`)) return;
|
||||
if (row.kind === "file") {
|
||||
setFiles((prev) => prev.filter((file) => file.path !== row.path));
|
||||
} else {
|
||||
setWebsites((prev) => prev.filter((website) => website.url !== row.url));
|
||||
}
|
||||
setStatus(`Removed ${row.name}`);
|
||||
};
|
||||
|
||||
const onRephrase = async () => {
|
||||
if (!ollamaModel || ollamaModel === "Select model...") {
|
||||
window.alert("Please select a model first.");
|
||||
return;
|
||||
}
|
||||
const ideaText = currentIdeaText(notes, title, description, concept);
|
||||
if (!ideaText.trim()) {
|
||||
window.alert("Add notes or a concept to rephrase.");
|
||||
return;
|
||||
}
|
||||
setBusy((prev) => ({ ...prev, rephrase: true }));
|
||||
setStatus("Rephrasing...");
|
||||
try {
|
||||
const variants = await runBackend<RephraseVariant[]>("rephrase", {
|
||||
note: ideaText,
|
||||
ollama_host: ollamaHost,
|
||||
model: ollamaModel,
|
||||
});
|
||||
setRephraseVariants(variants);
|
||||
setRephraseSelected(variants[0]?.key ?? null);
|
||||
setStatus("Rephrase complete");
|
||||
} catch (err) {
|
||||
setStatus("Rephrase failed");
|
||||
console.error(err);
|
||||
window.alert("Rephrase failed. Check console for details.");
|
||||
} finally {
|
||||
setBusy((prev) => ({ ...prev, rephrase: false }));
|
||||
}
|
||||
};
|
||||
|
||||
const onExtend = async () => {
|
||||
if (!ollamaModel || ollamaModel === "Select model...") {
|
||||
window.alert("Please select a model first.");
|
||||
return;
|
||||
}
|
||||
const ideaText = currentIdeaText(notes, title, description, concept);
|
||||
if (!ideaText.trim()) {
|
||||
window.alert("Add notes or a concept to extend.");
|
||||
return;
|
||||
}
|
||||
setBusy((prev) => ({ ...prev, extend: true }));
|
||||
setStatus("Extending...");
|
||||
try {
|
||||
const extension = await runBackend<string>("extend", {
|
||||
note: ideaText,
|
||||
ollama_host: ollamaHost,
|
||||
model: ollamaModel,
|
||||
});
|
||||
setNotes((prev) => (prev.trim() ? `${prev}\n${extension}` : extension));
|
||||
setStatus("Extension ready");
|
||||
} catch (err) {
|
||||
setStatus("Extend failed");
|
||||
console.error(err);
|
||||
window.alert("Extend failed. Check console for details.");
|
||||
} finally {
|
||||
setBusy((prev) => ({ ...prev, extend: false }));
|
||||
}
|
||||
};
|
||||
|
||||
const onGenerateConcept = async () => {
|
||||
if (!ollamaModel || ollamaModel === "Select model...") {
|
||||
window.alert("Please select a model first.");
|
||||
return;
|
||||
}
|
||||
if (!notes.trim() && !files.length && !websites.length) {
|
||||
window.alert("Add files, websites, or notes first.");
|
||||
return;
|
||||
}
|
||||
setBusy((prev) => ({ ...prev, generate: true }));
|
||||
setStatus("Generating concept...");
|
||||
try {
|
||||
const result = await runBackend<{ concept: string; title: string; description: string }>(
|
||||
"generate_concept",
|
||||
{
|
||||
notes,
|
||||
files: files.map((f) => f.path),
|
||||
websites: websites.map((w) => w.url),
|
||||
ollama_host: ollamaHost,
|
||||
model: ollamaModel,
|
||||
}
|
||||
);
|
||||
setConcept(result.concept);
|
||||
setTitle(result.title);
|
||||
setDescription(result.description);
|
||||
setStatus("Concept generated");
|
||||
} catch (err) {
|
||||
setStatus("Generation failed");
|
||||
console.error(err);
|
||||
window.alert("Generation failed. Check console for details.");
|
||||
} finally {
|
||||
setBusy((prev) => ({ ...prev, generate: false }));
|
||||
}
|
||||
};
|
||||
|
||||
const onPriorArt = async () => {
|
||||
if (!ollamaModel || ollamaModel === "Select model...") {
|
||||
window.alert("Please select a model first.");
|
||||
return;
|
||||
}
|
||||
const priorArtNotes = currentIdeaText(notes, title, description, concept);
|
||||
setBusy((prev) => ({ ...prev, prior: true }));
|
||||
setStatus("Searching prior art...");
|
||||
try {
|
||||
const data = await runBackend<PriorArtResponse>("prior_art", {
|
||||
notes: priorArtNotes,
|
||||
concept,
|
||||
title,
|
||||
description,
|
||||
files: files.map((f) => f.path),
|
||||
websites: websites.map((w) => w.url),
|
||||
ollama_host: ollamaHost,
|
||||
model: ollamaModel,
|
||||
searx_url: searxUrl,
|
||||
});
|
||||
setPriorData(data);
|
||||
setPriorModalOpen(true);
|
||||
setStatus("Prior art ready");
|
||||
} catch (err) {
|
||||
setStatus("Prior art failed");
|
||||
console.error(err);
|
||||
window.alert("Prior art search failed. Check console for details.");
|
||||
} finally {
|
||||
setBusy((prev) => ({ ...prev, prior: false }));
|
||||
}
|
||||
};
|
||||
|
||||
const onExportPdf = async () => {
|
||||
if (!concept.trim()) {
|
||||
window.alert("Generate or paste concept text first.");
|
||||
return;
|
||||
}
|
||||
setBusy((prev) => ({ ...prev, preview: true }));
|
||||
setStatus("Choose where to save the PDF...");
|
||||
try {
|
||||
const selectedPath = await save({
|
||||
title: "Export PDF",
|
||||
defaultPath: pdfFileNameFromTitle(title, concept),
|
||||
filters: [{ name: "PDF", extensions: ["pdf"] }],
|
||||
canCreateDirectories: true,
|
||||
});
|
||||
if (!selectedPath) {
|
||||
setStatus("PDF export cancelled");
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus("Exporting PDF...");
|
||||
const result = await runBackend<{ ok: boolean; pdf_path: string; log_path: string }>("preview_pdf", {
|
||||
concept,
|
||||
title,
|
||||
files: files.map((f) => f.path),
|
||||
output_path: ensurePdfExtension(selectedPath),
|
||||
});
|
||||
if (result.ok) {
|
||||
setStatus("Opening exported PDF...");
|
||||
try {
|
||||
await openPath(result.pdf_path);
|
||||
setStatus("PDF exported and opened");
|
||||
} catch (openErr) {
|
||||
setStatus("PDF exported");
|
||||
console.error(openErr);
|
||||
window.alert(`PDF exported to:\n${result.pdf_path}\n\nCould not open it automatically.`);
|
||||
}
|
||||
} else {
|
||||
setStatus("Export failed");
|
||||
window.alert(`Export failed. Log: ${result.log_path}`);
|
||||
}
|
||||
} catch (err) {
|
||||
setStatus("Export failed");
|
||||
console.error(err);
|
||||
window.alert("Export failed. Check console for details.");
|
||||
} finally {
|
||||
setBusy((prev) => ({ ...prev, preview: false }));
|
||||
}
|
||||
};
|
||||
|
||||
const onNewSession = () => {
|
||||
if (notes || concept || files.length || websites.length) {
|
||||
const ok = window.confirm("Clear the current session?");
|
||||
if (!ok) return;
|
||||
}
|
||||
setFiles([]);
|
||||
setWebsites([]);
|
||||
setNotes("");
|
||||
setRephraseVariants([]);
|
||||
setRephraseSelected(null);
|
||||
setConcept("");
|
||||
setTitle("");
|
||||
setDescription("");
|
||||
};
|
||||
|
||||
const onSaveSession = async () => {
|
||||
if (!title.trim()) {
|
||||
window.alert("Please enter a Title before saving.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const existing = await runBackend<SessionSummary[]>("list_sessions", {});
|
||||
const exists = existing.some((s) => s.title === title.trim());
|
||||
if (exists) {
|
||||
const ok = window.confirm(`A session titled "${title}" exists. Overwrite it?`);
|
||||
if (!ok) return;
|
||||
}
|
||||
await runBackend("save_session", {
|
||||
payload: {
|
||||
title,
|
||||
description,
|
||||
notes,
|
||||
concept,
|
||||
files: files.map((f) => ({ path: f.path })),
|
||||
websites: websites.map((w) => ({ url: w.url })),
|
||||
rephrase_variants: rephraseVariants,
|
||||
rephrase_selected_key: rephraseSelected,
|
||||
},
|
||||
allow_overwrite: true,
|
||||
});
|
||||
setStatus("Session saved");
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
window.alert("Failed to save session.");
|
||||
}
|
||||
};
|
||||
|
||||
const onOpenSession = async () => {
|
||||
setSessionModalOpen(true);
|
||||
setSessionsLoading(true);
|
||||
setSessions([]);
|
||||
try {
|
||||
const list = await runBackend<SessionSummary[]>("list_sessions", {});
|
||||
setSessions(list.sort((a, b) => (b.saved_at || 0) - (a.saved_at || 0)));
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
setSessionModalOpen(false);
|
||||
window.alert("Failed to load sessions.");
|
||||
} finally {
|
||||
setSessionsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const applySession = async (sessionTitle: string) => {
|
||||
try {
|
||||
const data = await runBackend<any>("load_session", { title: sessionTitle });
|
||||
if (!data) return;
|
||||
setTitle(data.title || "");
|
||||
setDescription(data.description || "");
|
||||
setNotes(data.notes || "");
|
||||
setConcept(data.concept || "");
|
||||
setFiles(
|
||||
(data.files || []).map((f: any) => ({
|
||||
kind: "file",
|
||||
path: f.path,
|
||||
name: f.path.split(/[\\/]/).pop() || f.path,
|
||||
type: (f.path.split(".").pop() || "file").toLowerCase(),
|
||||
size: "?",
|
||||
}))
|
||||
);
|
||||
setWebsites(
|
||||
(data.websites || []).map((w: any) => ({
|
||||
kind: "url",
|
||||
url: w.url,
|
||||
name: w.url.replace(/^https?:\/\//, "").slice(0, 60),
|
||||
type: "url",
|
||||
size: "web",
|
||||
}))
|
||||
);
|
||||
setRephraseVariants(data.rephrase_variants || []);
|
||||
setRephraseSelected(data.rephrase_selected_key || null);
|
||||
setSessionModalOpen(false);
|
||||
setStatus("Session loaded");
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
window.alert("Failed to open session.");
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
menuActionRef.current = (action: string) => {
|
||||
switch (action) {
|
||||
case "file-new":
|
||||
onNewSession();
|
||||
break;
|
||||
case "file-open":
|
||||
void onOpenSession();
|
||||
break;
|
||||
case "file-save":
|
||||
void onSaveSession();
|
||||
break;
|
||||
case "settings-open":
|
||||
setSettingsModalOpen(true);
|
||||
break;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
let unlisten: (() => void) | undefined;
|
||||
let disposed = false;
|
||||
|
||||
listen<string>("app-menu-action", (event) => {
|
||||
menuActionRef.current(event.payload);
|
||||
})
|
||||
.then((cleanup) => {
|
||||
if (disposed) {
|
||||
cleanup();
|
||||
} else {
|
||||
unlisten = cleanup;
|
||||
}
|
||||
})
|
||||
.catch(() => undefined);
|
||||
|
||||
return () => {
|
||||
disposed = true;
|
||||
if (unlisten) unlisten();
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<div className="panes">
|
||||
<div className="column">
|
||||
<section className="panel notes-panel">
|
||||
<div className="panel-title">
|
||||
<h2>Notes / Thoughts</h2>
|
||||
<span>Scratchpad for raw ideas</span>
|
||||
</div>
|
||||
<textarea
|
||||
className="notes-area"
|
||||
value={notes}
|
||||
onChange={(e) => setNotes(e.target.value)}
|
||||
placeholder="Drop in fragments, problem statements, or constraints..."
|
||||
/>
|
||||
|
||||
{rephraseVariants.length > 0 && (
|
||||
<div className="rephrase-panel">
|
||||
<strong style={{ fontSize: "12px", color: "var(--accent)" }}>Rephrase variants</strong>
|
||||
<div className="rephrase-list">
|
||||
{rephraseVariants.map((variant) => (
|
||||
<div
|
||||
key={variant.key}
|
||||
className={`rephrase-item ${rephraseSelected === variant.key ? "active" : ""}`}
|
||||
onClick={() => {
|
||||
setRephraseSelected(variant.key);
|
||||
setNotes(variant.text);
|
||||
}}
|
||||
>
|
||||
<div style={{ fontWeight: 600 }}>{variant.label}</div>
|
||||
<div style={{ fontSize: "11px", color: "var(--subtle)" }}>
|
||||
{variant.text.slice(0, 120)}{variant.text.length > 120 ? "..." : ""}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="controls">
|
||||
<button onClick={onRephrase} disabled={busy.rephrase}>Rephrase</button>
|
||||
<button onClick={onExtend} disabled={busy.extend}>Extend</button>
|
||||
<button onClick={onPriorArt} disabled={busy.prior}>Find Prior Art</button>
|
||||
<button className="primary" onClick={onGenerateConcept} disabled={busy.generate}>Generate Concept</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="panel files-panel">
|
||||
<div className="panel-title">
|
||||
<h2>Files & Websites</h2>
|
||||
<div className="panel-title-actions">
|
||||
<button onClick={onAddFiles}>Add Files</button>
|
||||
<button onClick={onAddWebsite}>Add URL</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="table">
|
||||
<div className="table-header">
|
||||
<div>Name</div>
|
||||
<div>Path</div>
|
||||
<div>Type</div>
|
||||
<div>Size</div>
|
||||
<div>Remove</div>
|
||||
</div>
|
||||
<div className="table-body">
|
||||
{rows.length === 0 && (
|
||||
<div className="table-row" style={{ gridTemplateColumns: "1fr" }}>
|
||||
<div style={{ color: "var(--muted)" }}>Drop files here or use Add Files / Add URL.</div>
|
||||
</div>
|
||||
)}
|
||||
{rows.map((row) => (
|
||||
<div key={rowId(row)} className="table-row">
|
||||
<div>{row.name}</div>
|
||||
<div>{row.kind === "file" ? row.path : row.url}</div>
|
||||
<div>{row.type}</div>
|
||||
<div>{row.size}</div>
|
||||
<div>
|
||||
<button
|
||||
className="remove-row-button danger"
|
||||
type="button"
|
||||
onClick={() => onRemoveRow(row)}
|
||||
aria-label={`Remove ${row.name}`}
|
||||
title={`Remove ${row.name}`}
|
||||
>
|
||||
X
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div className="column">
|
||||
<section className="panel" style={{ flex: 1 }}>
|
||||
<div className="panel-title">
|
||||
<h2>{markdownPreview ? "Concept (Preview)" : "Concept (Editable)"}</h2>
|
||||
<span>{markdownPreview ? "Rendered Markdown" : "Refine and publish"}</span>
|
||||
</div>
|
||||
{markdownPreview ? (
|
||||
<div
|
||||
className="markdown-preview md-root"
|
||||
role="textbox"
|
||||
aria-readonly="true"
|
||||
tabIndex={0}
|
||||
dangerouslySetInnerHTML={{
|
||||
__html:
|
||||
markdownPreviewHtml ||
|
||||
'<p class="md-paragraph markdown-preview__empty">No concept markdown to preview.</p>',
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<div className="concept-meta">
|
||||
<input value={title} onChange={(e) => setTitle(e.target.value)} placeholder="Title" />
|
||||
<input value={description} onChange={(e) => setDescription(e.target.value)} placeholder="Description" />
|
||||
</div>
|
||||
<textarea
|
||||
className="concept-editor"
|
||||
value={concept}
|
||||
onChange={(e) => setConcept(e.target.value)}
|
||||
placeholder="Generated concept markdown appears here..."
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<div className="controls concept-actions">
|
||||
<button onClick={() => setMarkdownPreview((value) => !value)}>
|
||||
{markdownPreview ? "Edit Markdown" : "Preview Markdown"}
|
||||
</button>
|
||||
<button onClick={onExportPdf} disabled={busy.preview}>Export PDF</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{websiteModalOpen && (
|
||||
<div
|
||||
className="modal-backdrop"
|
||||
role="presentation"
|
||||
onMouseDown={(event) => {
|
||||
if (event.target === event.currentTarget) {
|
||||
closeWebsiteModal();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<form
|
||||
className="settings-window website-window"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="website-title"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
onSubmitWebsite();
|
||||
}}
|
||||
>
|
||||
<div className="settings-header">
|
||||
<h3 id="website-title">Add URL</h3>
|
||||
<button className="ghost" type="button" onClick={closeWebsiteModal}>
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
<div className="website-form">
|
||||
<label htmlFor="website-url">URL</label>
|
||||
<input
|
||||
id="website-url"
|
||||
autoFocus
|
||||
value={websiteInput}
|
||||
onChange={(event) => {
|
||||
setWebsiteInput(event.target.value);
|
||||
if (websiteError) setWebsiteError("");
|
||||
}}
|
||||
placeholder="https://example.com"
|
||||
type="url"
|
||||
/>
|
||||
{websiteError && <div className="form-error">{websiteError}</div>}
|
||||
<div className="form-actions">
|
||||
<button type="button" onClick={closeWebsiteModal}>Cancel</button>
|
||||
<button className="primary" type="submit">Add URL</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{sessionModalOpen && (
|
||||
<div
|
||||
className="modal-backdrop"
|
||||
role="presentation"
|
||||
onMouseDown={(event) => {
|
||||
if (event.target === event.currentTarget) {
|
||||
setSessionModalOpen(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="settings-window session-window"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="session-title"
|
||||
>
|
||||
<div className="settings-header">
|
||||
<h3 id="session-title">Open Session</h3>
|
||||
<button className="ghost" onClick={() => setSessionModalOpen(false)}>
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
{sessionsLoading && <p>Loading sessions...</p>}
|
||||
{!sessionsLoading && sessions.length === 0 && <p>No saved sessions yet.</p>}
|
||||
<div className="session-list">
|
||||
{!sessionsLoading &&
|
||||
sessions.map((s) => (
|
||||
<button
|
||||
key={s.title}
|
||||
className="ghost session-item"
|
||||
onClick={() => applySession(s.title)}
|
||||
>
|
||||
<strong>{s.title}</strong>
|
||||
<div className="session-description">{s.description}</div>
|
||||
<div className="session-time">{formatTime(s.saved_at)}</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{settingsModalOpen && (
|
||||
<div
|
||||
className="modal-backdrop"
|
||||
role="presentation"
|
||||
onMouseDown={(event) => {
|
||||
if (event.target === event.currentTarget) {
|
||||
setSettingsModalOpen(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="settings-window"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="settings-title"
|
||||
>
|
||||
<div className="settings-header">
|
||||
<h3 id="settings-title">Settings</h3>
|
||||
<button className="ghost" onClick={() => setSettingsModalOpen(false)}>
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="settings-grid">
|
||||
<label htmlFor="settings-ollama-host">Ollama host</label>
|
||||
<input
|
||||
id="settings-ollama-host"
|
||||
value={ollamaHost}
|
||||
onChange={(e) => setOllamaHost(e.target.value)}
|
||||
/>
|
||||
|
||||
<label htmlFor="settings-model">Model</label>
|
||||
<select
|
||||
id="settings-model"
|
||||
value={ollamaModel}
|
||||
onChange={(e) => setOllamaModel(e.target.value)}
|
||||
>
|
||||
<option value="Select model...">Select model...</option>
|
||||
{models.map((m) => (
|
||||
<option key={m} value={m}>
|
||||
{m}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
<label htmlFor="settings-searx-url">SearXNG URL</label>
|
||||
<input
|
||||
id="settings-searx-url"
|
||||
value={searxUrl}
|
||||
onChange={(e) => setSearxUrl(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{priorModalOpen && priorData && (
|
||||
<div
|
||||
style={{
|
||||
position: "fixed",
|
||||
inset: 0,
|
||||
background: "rgba(69, 10, 10, 0.28)",
|
||||
display: "grid",
|
||||
placeItems: "center",
|
||||
zIndex: 10,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
background: "var(--panel)",
|
||||
border: "1px solid var(--line)",
|
||||
padding: "20px",
|
||||
borderRadius: "6px",
|
||||
width: "min(680px, 92vw)",
|
||||
maxHeight: "85vh",
|
||||
overflow: "auto",
|
||||
boxShadow: "var(--dialog-shadow)",
|
||||
}}
|
||||
>
|
||||
<h3 style={{ marginTop: 0 }}>Prior Art Results</h3>
|
||||
<div style={{ marginBottom: "12px" }}>
|
||||
<strong>Queries</strong>
|
||||
<ul style={{ marginTop: "6px" }}>
|
||||
{priorData.queries.map((q) => (
|
||||
<li key={q} style={{ fontSize: "12px", color: "var(--ink)" }}>
|
||||
{q}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
{priorData.results.length === 0 && <p>No results found.</p>}
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: "12px" }}>
|
||||
{priorData.results.map((r) => (
|
||||
<div key={r.url} style={{ border: "1px solid var(--line)", padding: "12px", borderRadius: "4px", background: "var(--surface)" }}>
|
||||
<div style={{ fontWeight: 600, marginBottom: "4px" }}>{r.title || r.url}</div>
|
||||
<div style={{ fontSize: "12px", color: "var(--muted)" }}>{r.url}</div>
|
||||
{r.snippet && (
|
||||
<div style={{ marginTop: "6px", fontSize: "12px", color: "var(--ink)" }}>{r.snippet}</div>
|
||||
)}
|
||||
{typeof r.score === "number" && (
|
||||
<div style={{ marginTop: "4px", fontSize: "11px", color: "var(--subtle)" }}>Score: {r.score.toFixed(3)}</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div style={{ marginTop: "16px", textAlign: "right" }}>
|
||||
<button onClick={() => setPriorModalOpen(false)}>Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{statusVisible && status && (
|
||||
<div className="status-toast" role="status" aria-live="polite">
|
||||
{status}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
10
src/main.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import App from "./App";
|
||||
import "./styles.css";
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
169
src/markdown/markdown-render.css
Normal file
@@ -0,0 +1,169 @@
|
||||
.md-root {
|
||||
--md-border-color: var(--line);
|
||||
--md-surface: rgba(255, 255, 255, 0.68);
|
||||
--md-surface-strong: var(--surface);
|
||||
--md-text-color: var(--ink);
|
||||
--md-muted-color: var(--muted);
|
||||
--md-link-color: var(--accent);
|
||||
--md-link-hover-color: var(--accent-strong);
|
||||
--md-code-bg: #fff7f8;
|
||||
--md-code-inline-bg: rgba(159, 18, 57, 0.08);
|
||||
--md-code-font: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
|
||||
"Liberation Mono", "Courier New", monospace;
|
||||
|
||||
color: var(--md-text-color);
|
||||
font-size: 14px;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
.md-heading {
|
||||
margin: 1.35rem 0 0.65rem;
|
||||
font-weight: 650;
|
||||
line-height: 1.25;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.md-root > .md-heading:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.md-heading--1 {
|
||||
font-size: 1.7rem;
|
||||
}
|
||||
|
||||
.md-heading--2 {
|
||||
font-size: 1.35rem;
|
||||
}
|
||||
|
||||
.md-heading--3 {
|
||||
font-size: 1.15rem;
|
||||
}
|
||||
|
||||
.md-heading--4,
|
||||
.md-heading--5,
|
||||
.md-heading--6 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.md-paragraph {
|
||||
margin: 0 0 0.85rem;
|
||||
}
|
||||
|
||||
.md-paragraph:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.md-hr {
|
||||
border: 0;
|
||||
border-top: 1px solid var(--md-border-color);
|
||||
margin: 1.4rem 0;
|
||||
}
|
||||
|
||||
.md-list {
|
||||
margin: 0.45rem 0 0.95rem;
|
||||
padding-left: 1.35rem;
|
||||
}
|
||||
|
||||
.md-list--unordered {
|
||||
list-style: disc;
|
||||
}
|
||||
|
||||
.md-list--ordered {
|
||||
list-style: decimal;
|
||||
}
|
||||
|
||||
.md-list__item {
|
||||
margin: 0.18rem 0;
|
||||
}
|
||||
|
||||
.md-blockquote {
|
||||
margin: 1rem 0;
|
||||
padding: 0.7rem 0.9rem;
|
||||
border-left: 3px solid var(--accent);
|
||||
background: var(--md-surface);
|
||||
color: var(--md-muted-color);
|
||||
}
|
||||
|
||||
.md-table {
|
||||
width: 100%;
|
||||
margin: 1rem 0;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
border: 1px solid var(--md-border-color);
|
||||
border-radius: var(--radius);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.md-table thead {
|
||||
background: var(--bg-main);
|
||||
}
|
||||
|
||||
.md-table__head-cell,
|
||||
.md-table__cell {
|
||||
padding: 0.58rem 0.7rem;
|
||||
vertical-align: top;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--md-border-color);
|
||||
}
|
||||
|
||||
.md-table__row:last-child .md-table__cell {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.md-align-left {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.md-align-center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.md-align-right {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.md-codeblock {
|
||||
margin: 1rem 0 0.35rem;
|
||||
padding: 0.75rem;
|
||||
overflow: auto;
|
||||
max-width: 100%;
|
||||
border: 1px solid var(--md-border-color);
|
||||
border-radius: var(--radius);
|
||||
background: var(--md-code-bg);
|
||||
}
|
||||
|
||||
.md-codeblock code {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
font-family: var(--md-code-font);
|
||||
font-size: 0.94em;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.md-inline-code {
|
||||
padding: 0.1em 0.24em;
|
||||
border-radius: 4px;
|
||||
background: var(--md-code-inline-bg);
|
||||
font-family: var(--md-code-font);
|
||||
font-size: 0.94em;
|
||||
}
|
||||
|
||||
.md-link {
|
||||
color: var(--md-link-color);
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 2px;
|
||||
}
|
||||
|
||||
.md-link:hover,
|
||||
.md-link:focus-visible {
|
||||
color: var(--md-link-hover-color);
|
||||
}
|
||||
|
||||
.md-image {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
margin: 1rem 0;
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
320
src/markdown/markdown.ts
Normal file
@@ -0,0 +1,320 @@
|
||||
import MarkdownIt from "markdown-it";
|
||||
|
||||
const EXTRA_BLANK_LINE_MARKER = "\uE000CONCEPT_MAKER_EXTRA_BLANK_LINE\uE000";
|
||||
|
||||
const escapeHtml = (value = "") =>
|
||||
value
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">");
|
||||
|
||||
const escapeRegExp = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
|
||||
const appendClass = (token: any, className: string) => {
|
||||
const existing = token.attrGet("class");
|
||||
token.attrSet("class", existing ? `${existing} ${className}` : className);
|
||||
};
|
||||
|
||||
const removeAttr = (token: any, attrName: string) => {
|
||||
const index = token.attrIndex(attrName);
|
||||
if (index >= 0) token.attrs.splice(index, 1);
|
||||
};
|
||||
|
||||
const alignmentClassFromToken = (token: any) => {
|
||||
const style = token.attrGet("style") || "";
|
||||
const match = style.match(/text-align:\s*(left|right|center)/i);
|
||||
return `md-align-${match?.[1]?.toLowerCase() || "left"}`;
|
||||
};
|
||||
|
||||
const safeLink = (hrefRaw: string) => {
|
||||
const href = (hrefRaw || "").trim();
|
||||
if (!href) return "";
|
||||
if (href.startsWith("//")) return "";
|
||||
if (/^(https?|mailto|tel):/i.test(href)) return href;
|
||||
if (/^[./#]/.test(href)) return href;
|
||||
if (!/^[a-z][a-z0-9+.-]*:/i.test(href)) return href;
|
||||
return "";
|
||||
};
|
||||
|
||||
const preserveExtraBlankLines = (source: string) =>
|
||||
source.replace(/([^\n])(\n{3,})([^\n])/g, (_match, before, newlines, after) => {
|
||||
const markers = Array.from(
|
||||
{ length: newlines.length - 2 },
|
||||
() => EXTRA_BLANK_LINE_MARKER
|
||||
).join("\n\n");
|
||||
return `${before}\n\n${markers}\n\n${after}`;
|
||||
});
|
||||
|
||||
const restoreExtraBlankLines = (html: string) => {
|
||||
const markerParagraph = new RegExp(
|
||||
`<p class="md-paragraph">${escapeRegExp(EXTRA_BLANK_LINE_MARKER)}</p>\\n?`,
|
||||
"g"
|
||||
);
|
||||
return html.replace(markerParagraph, "<br />");
|
||||
};
|
||||
|
||||
const cleanMarkdownForPreview = (source: string) =>
|
||||
source
|
||||
.replace(/<think(?:ing)?>[\s\S]*?(?:<\/think(?:ing)?>|$)/gi, "")
|
||||
.replace(/[\u00a0\u202f\u2007]/g, " ");
|
||||
|
||||
function balanceStreamingCodeFence(markdownSource: string) {
|
||||
const lines = markdownSource.split(/\r?\n/);
|
||||
let open: { fenceChar: string; fenceLen: number } | null = null;
|
||||
|
||||
for (const line of lines) {
|
||||
if (!open) {
|
||||
const match = line.match(/^\s*([`~]{3,})([^\s]*)?.*$/);
|
||||
if (match) {
|
||||
open = { fenceChar: match[1][0], fenceLen: match[1].length };
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const closeFence = new RegExp(`^\\s*(${open.fenceChar}{${open.fenceLen},})\\s*$`);
|
||||
if (closeFence.test(line)) {
|
||||
open = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!open) return markdownSource;
|
||||
|
||||
const virtualFence = open.fenceChar.repeat(open.fenceLen);
|
||||
return markdownSource.endsWith("\n")
|
||||
? markdownSource + virtualFence
|
||||
: `${markdownSource}\n${virtualFence}`;
|
||||
}
|
||||
|
||||
const markdown = new MarkdownIt({
|
||||
html: false,
|
||||
linkify: true,
|
||||
breaks: true,
|
||||
typographer: false
|
||||
});
|
||||
|
||||
markdown.linkify.set({ fuzzyEmail: false, fuzzyIP: false });
|
||||
markdown.validateLink = (href: string) => Boolean(safeLink(href));
|
||||
|
||||
markdown.renderer.rules.paragraph_open = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
_env: any,
|
||||
self: any
|
||||
) => {
|
||||
appendClass(tokens[idx], "md-paragraph");
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.heading_open = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
_env: any,
|
||||
self: any
|
||||
) => {
|
||||
const level = tokens[idx].tag.replace(/^h/i, "") || "1";
|
||||
appendClass(tokens[idx], `md-heading md-heading--${level}`);
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.hr = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
_env: any,
|
||||
self: any
|
||||
) => {
|
||||
appendClass(tokens[idx], "md-hr");
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.bullet_list_open = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
_env: any,
|
||||
self: any
|
||||
) => {
|
||||
appendClass(tokens[idx], "md-list md-list--unordered");
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.ordered_list_open = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
_env: any,
|
||||
self: any
|
||||
) => {
|
||||
appendClass(tokens[idx], "md-list md-list--ordered");
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.list_item_open = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
_env: any,
|
||||
self: any
|
||||
) => {
|
||||
appendClass(tokens[idx], "md-list__item");
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.blockquote_open = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
_env: any,
|
||||
self: any
|
||||
) => {
|
||||
appendClass(tokens[idx], "md-blockquote");
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.table_open = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
_env: any,
|
||||
self: any
|
||||
) => {
|
||||
appendClass(tokens[idx], "md-table");
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.thead_open = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
env: any,
|
||||
self: any
|
||||
) => {
|
||||
env.inTableHead = true;
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.thead_close = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
env: any,
|
||||
self: any
|
||||
) => {
|
||||
env.inTableHead = false;
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.tr_open = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
env: any,
|
||||
self: any
|
||||
) => {
|
||||
appendClass(
|
||||
tokens[idx],
|
||||
env.inTableHead ? "md-table__row md-table__row--head" : "md-table__row"
|
||||
);
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.th_open = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
_env: any,
|
||||
self: any
|
||||
) => {
|
||||
appendClass(tokens[idx], `md-table__head-cell ${alignmentClassFromToken(tokens[idx])}`);
|
||||
removeAttr(tokens[idx], "style");
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.td_open = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
_env: any,
|
||||
self: any
|
||||
) => {
|
||||
appendClass(tokens[idx], `md-table__cell ${alignmentClassFromToken(tokens[idx])}`);
|
||||
removeAttr(tokens[idx], "style");
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.strong_open = () => "<b>";
|
||||
markdown.renderer.rules.strong_close = () => "</b>";
|
||||
markdown.renderer.rules.em_open = () => "<i>";
|
||||
markdown.renderer.rules.em_close = () => "</i>";
|
||||
markdown.renderer.rules.softbreak = () => "<br />";
|
||||
markdown.renderer.rules.hardbreak = () => "<br />";
|
||||
|
||||
markdown.renderer.rules.code_inline = (tokens: any[], idx: number) =>
|
||||
`<code class="md-inline-code">${escapeHtml(tokens[idx].content)}</code>`;
|
||||
|
||||
markdown.renderer.rules.fence = (tokens: any[], idx: number) => {
|
||||
const info = tokens[idx].info.trim();
|
||||
const languageClass = info.toLowerCase().replace(/[^a-z0-9_-]/g, "") || "code";
|
||||
return `<pre class="md-codeblock"><code class="language-${languageClass}">${escapeHtml(tokens[idx].content).replace(
|
||||
/\n$/,
|
||||
""
|
||||
)}</code></pre>`;
|
||||
};
|
||||
|
||||
markdown.renderer.rules.code_block = (tokens: any[], idx: number) =>
|
||||
`<pre class="md-codeblock"><code>${escapeHtml(tokens[idx].content).replace(
|
||||
/\n$/,
|
||||
""
|
||||
)}</code></pre>`;
|
||||
|
||||
markdown.renderer.rules.link_open = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
_env: any,
|
||||
self: any
|
||||
) => {
|
||||
const href = safeLink(tokens[idx].attrGet("href") || "");
|
||||
|
||||
if (!href) return "";
|
||||
|
||||
tokens[idx].attrSet("href", href);
|
||||
tokens[idx].attrSet("class", "md-link");
|
||||
|
||||
if (/^https?:\/\//i.test(href)) {
|
||||
tokens[idx].attrSet("target", "_blank");
|
||||
tokens[idx].attrSet("rel", "noreferrer noopener");
|
||||
}
|
||||
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.image = (
|
||||
tokens: any[],
|
||||
idx: number,
|
||||
options: any,
|
||||
env: any,
|
||||
self: any
|
||||
) => {
|
||||
const token = tokens[idx];
|
||||
const src = safeLink(token.attrGet("src") || "");
|
||||
if (!src) return escapeHtml(token.content || "");
|
||||
|
||||
token.attrSet("src", src);
|
||||
token.attrSet("alt", self.renderInlineAsText(token.children, options, env));
|
||||
token.attrSet("loading", "lazy");
|
||||
appendClass(token, "md-image");
|
||||
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
export function markdownToHTML(text: string) {
|
||||
let source = cleanMarkdownForPreview(String(text ?? ""));
|
||||
source = balanceStreamingCodeFence(source);
|
||||
source = preserveExtraBlankLines(source);
|
||||
|
||||
const html = markdown.render(source, {});
|
||||
return restoreExtraBlankLines(html).replace(/\n+$/g, "");
|
||||
}
|
||||
497
src/styles.css
Normal file
@@ -0,0 +1,497 @@
|
||||
:root {
|
||||
color-scheme: light;
|
||||
--bg-main: #ffe4e6;
|
||||
--bg-sidebar: #fff1f2;
|
||||
--accent: #9f1239;
|
||||
--accent-strong: #7c0e2e;
|
||||
--border: #fff;
|
||||
--line: #fecdd3;
|
||||
--field-border: #fda4af;
|
||||
--ink: #7f1d1d;
|
||||
--muted: #9f1239;
|
||||
--subtle: #be5d75;
|
||||
--danger: #e11d48;
|
||||
--surface: #fff;
|
||||
--shadow: 0 1px 3px rgba(159, 18, 57, 0.08);
|
||||
--dialog-shadow: 0 16px 40px rgba(159, 18, 57, 0.18);
|
||||
--radius: 5px;
|
||||
--control-radius: 4px;
|
||||
|
||||
--bg: var(--bg-main);
|
||||
--panel: var(--bg-sidebar);
|
||||
--panel-edge: var(--border);
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html,
|
||||
body,
|
||||
#root {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
color: var(--ink);
|
||||
background: var(--bg);
|
||||
}
|
||||
|
||||
.app {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
padding: 20px 24px 16px;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.status-toast {
|
||||
position: absolute;
|
||||
right: 24px;
|
||||
bottom: 18px;
|
||||
z-index: 9;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
max-width: min(420px, calc(100vw - 48px));
|
||||
padding: 8px 14px;
|
||||
border: 1px solid var(--panel-edge);
|
||||
border-radius: var(--radius);
|
||||
background: var(--panel);
|
||||
color: var(--accent);
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
overflow-wrap: anywhere;
|
||||
box-shadow: var(--dialog-shadow);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.panes {
|
||||
flex: 1;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 16px;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.panel {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--panel-edge);
|
||||
border-radius: var(--radius);
|
||||
padding: 14px 16px 16px;
|
||||
box-shadow: var(--shadow);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.notes-panel {
|
||||
flex: 1 1 67%;
|
||||
}
|
||||
|
||||
.files-panel {
|
||||
flex: 0 1 33%;
|
||||
max-height: 33%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.files-panel .table {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.files-panel .table-body {
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.panel-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.panel-title h2 {
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
line-height: 1.2;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.panel-title span {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.panel-title-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.table {
|
||||
display: grid;
|
||||
grid-template-rows: auto 1fr;
|
||||
gap: 6px;
|
||||
border: 1px solid var(--panel-edge);
|
||||
border-radius: var(--radius);
|
||||
overflow: hidden;
|
||||
background: var(--surface);
|
||||
min-height: 180px;
|
||||
}
|
||||
|
||||
.table-header,
|
||||
.table-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1.2fr 2fr 0.6fr 0.6fr 0.5fr;
|
||||
align-items: center;
|
||||
padding: 10px 12px;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.table-header {
|
||||
background: var(--bg-main);
|
||||
color: var(--accent);
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.table-body {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.table-row {
|
||||
border-top: 1px solid var(--bg-main);
|
||||
color: var(--ink);
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
|
||||
.table-row > div {
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.table-row:hover {
|
||||
background: var(--bg-main);
|
||||
}
|
||||
|
||||
button.remove-row-button {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
min-width: 24px;
|
||||
padding: 0;
|
||||
border-radius: var(--control-radius);
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.controls {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.concept-actions {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
button {
|
||||
border: 1px solid var(--accent);
|
||||
border-radius: var(--control-radius);
|
||||
padding: 8px 14px;
|
||||
font-family: inherit;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
background: var(--panel);
|
||||
color: var(--accent);
|
||||
transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
}
|
||||
|
||||
button.primary {
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
button.primary:hover {
|
||||
background: var(--accent-strong);
|
||||
border-color: var(--accent-strong);
|
||||
}
|
||||
|
||||
button.ghost {
|
||||
background: transparent;
|
||||
color: var(--accent);
|
||||
border-color: var(--field-border);
|
||||
}
|
||||
|
||||
button.ghost:hover {
|
||||
background: var(--bg-main);
|
||||
color: var(--accent-strong);
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
button.danger {
|
||||
background: var(--panel);
|
||||
color: var(--danger);
|
||||
border-color: var(--danger);
|
||||
}
|
||||
|
||||
button.danger:hover {
|
||||
background: var(--danger);
|
||||
color: white;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
textarea,
|
||||
input,
|
||||
select {
|
||||
border-radius: var(--control-radius);
|
||||
border: 1px solid var(--field-border);
|
||||
padding: 10px 12px;
|
||||
font-family: inherit;
|
||||
font-size: 14px;
|
||||
background: var(--surface);
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
textarea::placeholder,
|
||||
input::placeholder {
|
||||
color: var(--subtle);
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
min-height: 120px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
input:focus,
|
||||
textarea:focus,
|
||||
select:focus {
|
||||
outline: 2px solid rgba(159, 18, 57, 0.2);
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
select {
|
||||
accent-color: var(--accent);
|
||||
}
|
||||
|
||||
.notes-area {
|
||||
flex: 1;
|
||||
min-height: 180px;
|
||||
}
|
||||
|
||||
.rephrase-panel {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
padding: 8px;
|
||||
background: rgba(255, 255, 255, 0.7);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
max-height: 160px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.rephrase-list {
|
||||
overflow: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.rephrase-item {
|
||||
padding: 8px 10px;
|
||||
border-radius: var(--control-radius);
|
||||
border: 1px solid var(--line);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
background: var(--surface);
|
||||
}
|
||||
|
||||
.rephrase-item:hover,
|
||||
.rephrase-item.active {
|
||||
background: var(--bg-main);
|
||||
border-color: var(--field-border);
|
||||
}
|
||||
|
||||
.concept-meta {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.concept-editor {
|
||||
flex: 1;
|
||||
min-height: 240px;
|
||||
}
|
||||
|
||||
.markdown-preview {
|
||||
flex: 1;
|
||||
min-height: 314px;
|
||||
padding: 16px 18px;
|
||||
overflow: auto;
|
||||
border: 1px solid var(--field-border);
|
||||
border-radius: var(--control-radius);
|
||||
background: var(--surface);
|
||||
box-shadow: inset 0 1px 2px rgba(159, 18, 57, 0.04);
|
||||
}
|
||||
|
||||
.markdown-preview:focus {
|
||||
outline: 2px solid rgba(159, 18, 57, 0.2);
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.markdown-preview__empty {
|
||||
color: var(--subtle);
|
||||
}
|
||||
|
||||
.modal-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: rgba(69, 10, 10, 0.28);
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.settings-window {
|
||||
width: min(560px, 92vw);
|
||||
padding: 20px;
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 6px;
|
||||
box-shadow: var(--dialog-shadow);
|
||||
}
|
||||
|
||||
.settings-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.settings-header h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.website-window {
|
||||
width: min(460px, 92vw);
|
||||
}
|
||||
|
||||
.session-window {
|
||||
max-height: 80vh;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.session-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.session-item {
|
||||
display: block;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.session-description {
|
||||
margin-top: 2px;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.session-time {
|
||||
margin-top: 2px;
|
||||
color: var(--subtle);
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.website-form {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.form-error {
|
||||
color: var(--danger);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.settings-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 130px minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: 12px 14px;
|
||||
}
|
||||
|
||||
.settings-grid label {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.settings-grid input,
|
||||
.settings-grid select {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.panes {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.table-header,
|
||||
.table-row {
|
||||
grid-template-columns: 1.2fr 1.8fr 0.6fr 0.6fr 0.5fr;
|
||||
}
|
||||
|
||||
.settings-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
4
src/types/markdown-it.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
declare module "markdown-it" {
|
||||
const MarkdownIt: any;
|
||||
export default MarkdownIt;
|
||||
}
|
||||
1
src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
20
tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
10
tsconfig.node.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
27
vite.config.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
|
||||
export default defineConfig(() => {
|
||||
const host = process.env.TAURI_DEV_HOST;
|
||||
return {
|
||||
plugins: [react()],
|
||||
clearScreen: false,
|
||||
server: {
|
||||
port: 5173,
|
||||
strictPort: true,
|
||||
host: host || false,
|
||||
hmr: host
|
||||
? {
|
||||
protocol: "ws",
|
||||
host,
|
||||
port: 5173,
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
build: {
|
||||
target: "esnext",
|
||||
minify: !process.env.TAURI_DEBUG ? "esbuild" : false,
|
||||
sourcemap: !!process.env.TAURI_DEBUG,
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -2,13 +2,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Prior-art web search utilities for the Idea → Concept GUI.
|
||||
Prior-art web search utilities for the Concept Maker backend.
|
||||
|
||||
Design goals
|
||||
- Pure stdlib networking (urllib) to avoid new dependencies.
|
||||
- Works with a local SearXNG instance.
|
||||
- Uses Ollama for both query generation and embeddings.
|
||||
- Small, robust, and callable from the GUI with status callbacks.
|
||||
- Small, robust, and callable from the Python backend.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||