Skip to content

Commit ff87df2

Browse files
authored
Merge pull request #116 from PytorchConnectomics/improve-chatbot
Improve chatbot
2 parents 3caf784 + b426f06 commit ff87df2

51 files changed

Lines changed: 852 additions & 978 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

client/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ function createMenu() {
5454
label: "Electron",
5555
submenu: [{ role: "toggleDevTools" }, { role: "quit" }],
5656
},
57+
{
58+
label: "Edit",
59+
submenu: [
60+
{ role: "undo" },
61+
{ role: "redo" },
62+
{ type: "separator" },
63+
{ role: "cut" },
64+
{ role: "copy" },
65+
{ role: "paste" },
66+
{ role: "selectAll" },
67+
],
68+
},
5769
{
5870
label: "Views",
5971
submenu: [

client/src/components/FilePickerModal.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ const FilePickerModal = ({
3636
const [loading, setLoading] = useState(false);
3737
const [previewStatus, setPreviewStatus] = useState({});
3838
const [onlyImages, setOnlyImages] = useState(false);
39-
const previewBaseUrl =
40-
apiClient.defaults.baseURL || "http://localhost:4242";
39+
const previewBaseUrl = apiClient.defaults.baseURL || "http://localhost:4242";
4140

4241
// Refactored fetch to get all files once
4342
const [allData, setAllData] = useState([]);
@@ -46,6 +45,7 @@ const FilePickerModal = ({
4645
if (visible) {
4746
setCurrentPath("root");
4847
setOnlyImages(false);
48+
setPreviewStatus({});
4949
loadAllData();
5050
}
5151
}, [visible]);
@@ -180,12 +180,13 @@ const FilePickerModal = ({
180180
const isImageFile = (item) => {
181181
if (!item || item.is_folder) return false;
182182
if (item.type && item.type.startsWith("image/")) return true;
183-
const ext = `.${String(item.name || "").split(".").pop()}`.toLowerCase();
183+
const ext = `.${String(item.name || "")
184+
.split(".")
185+
.pop()}`.toLowerCase();
184186
return IMAGE_EXTENSIONS.has(ext);
185187
};
186188

187-
const getPreviewUrl = (item) =>
188-
`${previewBaseUrl}/files/preview/${item.id}`;
189+
const getPreviewUrl = (item) => `${previewBaseUrl}/files/preview/${item.id}`;
189190

190191
const markPreviewLoaded = (id) => {
191192
setPreviewStatus((prev) => ({ ...prev, [id]: "loaded" }));

client/src/views/FilesManager.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ function FilesManager() {
9595
const containerRef = useRef(null);
9696
const itemRefs = useRef({});
9797
const isDragSelecting = useRef(false);
98-
const previewBaseUrl =
99-
apiClient.defaults.baseURL || "http://localhost:4242";
98+
const previewBaseUrl = apiClient.defaults.baseURL || "http://localhost:4242";
10099

101100
// Sidebar Resize Logic
102101
const [sidebarWidth, setSidebarWidth] = useState(250);
@@ -215,7 +214,9 @@ function FilesManager() {
215214
const isImageFile = (file) => {
216215
if (!file || file.is_folder) return false;
217216
if (file.type && file.type.startsWith("image/")) return true;
218-
const ext = `.${String(file.name || "").split(".").pop()}`.toLowerCase();
217+
const ext = `.${String(file.name || "")
218+
.split(".")
219+
.pop()}`.toLowerCase();
219220
return IMAGE_EXTENSIONS.has(ext);
220221
};
221222

scripts/dev.sh

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@ DEFAULT_OLLAMA_BASE_URL="http://localhost:11434"
88
DEFAULT_OLLAMA_MODEL="llama3.1:8b"
99

1010
if ! command -v uv >/dev/null 2>&1; then
11-
echo "uv is required. Run scripts/bootstrap.sh first." >&2
12-
exit 1
11+
echo "uv is required. Run scripts/bootstrap.sh first." >&2
12+
exit 1
1313
fi
1414

1515
if ! command -v npm >/dev/null 2>&1; then
16-
echo "npm is required to launch the Electron client." >&2
17-
exit 1
16+
echo "npm is required to launch the Electron client." >&2
17+
exit 1
1818
fi
1919

2020
cleanup() {
21-
local exit_code=$?
22-
if [[ -n "${API_PID:-}" ]] && ps -p "${API_PID}" >/dev/null 2>&1; then
23-
kill "${API_PID}" >/dev/null 2>&1 || true
24-
fi
25-
if [[ -n "${PYTC_PID:-}" ]] && ps -p "${PYTC_PID}" >/dev/null 2>&1; then
26-
kill "${PYTC_PID}" >/dev/null 2>&1 || true
27-
fi
28-
if [[ -n "${DATA_SERVER_PID:-}" ]] && ps -p "${DATA_SERVER_PID}" >/dev/null 2>&1; then
29-
kill "${DATA_SERVER_PID}" >/dev/null 2>&1 || true
30-
fi
31-
if [[ -n "${REACT_PID:-}" ]] && ps -p "${REACT_PID}" >/dev/null 2>&1; then
32-
kill "${REACT_PID}" >/dev/null 2>&1 || true
33-
fi
34-
wait || true
35-
exit "${exit_code}"
21+
local exit_code=$?
22+
if [[ -n "${API_PID:-}" ]] && ps -p "${API_PID}" >/dev/null 2>&1; then
23+
kill "${API_PID}" >/dev/null 2>&1 || true
24+
fi
25+
if [[ -n "${PYTC_PID:-}" ]] && ps -p "${PYTC_PID}" >/dev/null 2>&1; then
26+
kill "${PYTC_PID}" >/dev/null 2>&1 || true
27+
fi
28+
if [[ -n "${DATA_SERVER_PID:-}" ]] && ps -p "${DATA_SERVER_PID}" >/dev/null 2>&1; then
29+
kill "${DATA_SERVER_PID}" >/dev/null 2>&1 || true
30+
fi
31+
if [[ -n "${REACT_PID:-}" ]] && ps -p "${REACT_PID}" >/dev/null 2>&1; then
32+
kill "${REACT_PID}" >/dev/null 2>&1 || true
33+
fi
34+
wait || true
35+
exit "${exit_code}"
3636
}
3737

3838
trap cleanup EXIT INT TERM
@@ -43,8 +43,8 @@ DATA_SERVER_PID=$!
4343

4444
echo "Starting API server (port 4242)..."
4545
OLLAMA_BASE_URL="${OLLAMA_BASE_URL:-${DEFAULT_OLLAMA_BASE_URL}}" \
46-
OLLAMA_MODEL="${OLLAMA_MODEL:-${DEFAULT_OLLAMA_MODEL}}" \
47-
PYTHONDONTWRITEBYTECODE=1 uv run --directory "${ROOT_DIR}" python -m server_api.main &
46+
OLLAMA_MODEL="${OLLAMA_MODEL:-${DEFAULT_OLLAMA_MODEL}}" \
47+
PYTHONDONTWRITEBYTECODE=1 uv run --directory "${ROOT_DIR}" python -m server_api.main &
4848
API_PID=$!
4949

5050
echo "Starting PyTC server (port 4243)..."
@@ -53,33 +53,33 @@ PYTC_PID=$!
5353

5454
echo "Starting React dev server (port 3000)..."
5555
pushd "${CLIENT_DIR}" >/dev/null
56-
PORT=3000 BROWSER=none npm start > react.log 2>&1 &
56+
PORT=3000 BROWSER=none npm start >react.log 2>&1 &
5757
REACT_PID=$!
5858

5959
# Robust readiness check with progress feedback
6060
wait_for_react() {
61-
local max_attempts=60
62-
local attempt=1
63-
while [[ ${attempt} -le ${max_attempts} ]]; do
64-
if curl -sf http://localhost:3000 >/dev/null 2>&1; then
65-
echo "React dev server is ready!"
66-
return 0
67-
fi
68-
echo "Waiting for React (attempt ${attempt}/${max_attempts})..."
69-
attempt=$((attempt + 1))
70-
sleep 1
71-
done
72-
echo "ERROR: React dev server failed to start within ${max_attempts} seconds" >&2
73-
echo "Check client/react.log for details." >&2
74-
return 1
61+
local max_attempts=60
62+
local attempt=1
63+
while [[ ${attempt} -le ${max_attempts} ]]; do
64+
if curl -sf http://localhost:3000 >/dev/null 2>&1; then
65+
echo "React dev server is ready!"
66+
return 0
67+
fi
68+
echo "Waiting for React (attempt ${attempt}/${max_attempts})..."
69+
attempt=$((attempt + 1))
70+
sleep 1
71+
done
72+
echo "ERROR: React dev server failed to start within ${max_attempts} seconds" >&2
73+
echo "Check client/react.log for details." >&2
74+
return 1
7575
}
7676

7777
if wait_for_react; then
78-
echo "Launching Electron client..."
79-
ENVIRONMENT=development npm run electron
78+
echo "Launching Electron client..."
79+
ENVIRONMENT=development npm run electron
8080
else
81-
echo "Failed to start React dev server" >&2
82-
exit 1
81+
echo "Failed to start React dev server" >&2
82+
exit 1
8383
fi
8484

8585
popd >/dev/null

0 commit comments

Comments
 (0)