Skip to content

Commit d91b6c3

Browse files
authored
Merge pull request #12 from SongY123/main
support electron build
2 parents 08759ff + e0ceb0e commit d91b6c3

36 files changed

Lines changed: 2236 additions & 111 deletions
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Package Electron Desktop
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
workflow_dispatch:
9+
10+
jobs:
11+
package-desktop:
12+
runs-on: macos-latest
13+
14+
steps:
15+
- name: Checkout backend repository
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: "20"
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: "3.11"
27+
cache: "pip"
28+
cache-dependency-path: requirements.txt
29+
30+
- name: Install backend dependencies
31+
run: python -m pip install -r requirements.txt
32+
33+
- name: Package Electron app
34+
env:
35+
DATAFACTORY_FRONTEND_DIR: ${{ github.workspace }}/../DataFactory-Frontend
36+
DATAFACTORY_FRONTEND_REPO: https://github.com/${{ github.repository_owner }}/DataFactory-Frontend.git
37+
DATAFACTORY_FRONTEND_UPDATE: "0"
38+
run: bash scripts/package_desktop_app.sh
39+
40+
- name: Prepare artifact directory
41+
run: |
42+
rm -rf desktop_artifacts
43+
mkdir -p desktop_artifacts
44+
cp -R ../DataFactory-Frontend/dist_electron/. desktop_artifacts/
45+
46+
- name: Upload desktop artifact
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: datafactory-desktop-mac
50+
path: desktop_artifacts/**
51+
if-no-files-found: error

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ outputs/
1616

1717
uploads/
1818

19-
output/
19+
output/
20+
workspace/

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# DataFactory
22

3-
This project is a trimmed migration of the main `SpatialText2SQL` web architecture, preserving the layered structure: `api/service/dao/entity/resources`.
3+
This project preserves a layered web architecture with `api/service/dao/entity/resources`.
44

55
Currently retained:
66
- Local SQLite initialization (SQL migrations run automatically at startup)
77
- User authentication and session flow (`/api/auth/login`, `/api/auth/logout`, `/api/auth/session`)
88
- User management APIs (`/api/users`)
99

1010
Removed:
11-
- Map/spatial-related features
1211
- Multi-agent features
1312
- Other business features such as chat, admin, and database probing/execution
1413

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ ollama>=0.6,<1.0
1212
dashscope>=1.25,<2.0
1313
python-docx>=1.1,<2.0
1414
huggingface_hub>=0.34,<1.0
15+
statistics
16+
numpy
17+
pyarrow

runtime/sandbox_environments.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
{
55
"id": "env-default",
66
"name": "Default Python",
7-
"python_path": "C:\\Users\\86138\\.conda\\envs\\DataFactory-Backend\\python.exe",
7+
"python_path": "/opt/anaconda3/envs/DataFactory/bin/python3.10",
88
"created_at": "2026-03-22T01:02:59.073077+00:00",
9-
"updated_at": "2026-03-22T01:02:59.073077+00:00"
9+
"updated_at": "2026-03-24T15:46:56.188560+00:00"
1010
},
1111
{
1212
"id": "env-d3934326cd",
1313
"name": "DataFactory",
14-
"python_path": "D:\\Anaconda\\envs\\DataFactory\\python.exe",
14+
"python_path": "/opt/anaconda3/envs/DataFactory/bin/python3.10",
1515
"created_at": "2026-03-23T13:38:55.175962+00:00",
1616
"updated_at": "2026-03-23T13:38:55.175962+00:00"
1717
}
1818
]
19-
}
19+
}

scripts/package_desktop_app.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
BACKEND_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
6+
WORKSPACE_ROOT="$(cd "${BACKEND_ROOT}/.." && pwd)"
7+
FRONTEND_DIR="${DATAFACTORY_FRONTEND_DIR:-${WORKSPACE_ROOT}/DataFactory-Frontend}"
8+
FRONTEND_REPO="${DATAFACTORY_FRONTEND_REPO:-https://github.com/SongY123/DataFactory-Frontend.git}"
9+
FRONTEND_UPDATE="${DATAFACTORY_FRONTEND_UPDATE:-0}"
10+
11+
echo "[package] backend root: ${BACKEND_ROOT}"
12+
echo "[package] frontend dir: ${FRONTEND_DIR}"
13+
14+
if [[ -d "${FRONTEND_DIR}/.git" ]]; then
15+
if [[ "${FRONTEND_UPDATE}" == "1" ]]; then
16+
if ! git -C "${FRONTEND_DIR}" diff --quiet || ! git -C "${FRONTEND_DIR}" diff --cached --quiet; then
17+
echo "[package] frontend repo has local changes; refusing to pull with DATAFACTORY_FRONTEND_UPDATE=1" >&2
18+
exit 1
19+
fi
20+
echo "[package] updating existing frontend checkout"
21+
git -C "${FRONTEND_DIR}" pull --ff-only
22+
else
23+
echo "[package] using existing frontend checkout without pulling"
24+
fi
25+
else
26+
echo "[package] cloning frontend repo: ${FRONTEND_REPO}"
27+
git clone "${FRONTEND_REPO}" "${FRONTEND_DIR}"
28+
fi
29+
30+
pushd "${FRONTEND_DIR}" >/dev/null
31+
32+
echo "[package] installing frontend dependencies"
33+
npm ci
34+
35+
echo "[package] packaging Electron desktop app"
36+
npm run desktop:package
37+
38+
echo "[package] build outputs"
39+
find "${FRONTEND_DIR}/dist_electron" -maxdepth 3 -print | sed -n '1,120p'
40+
41+
popd >/dev/null
42+

src/utils/auth_guard.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def _get_session_service():
2020
return get_global_session_service()
2121

2222

23-
def _is_auto_login_as_admin_enabled() -> bool:
23+
def _is_auto_login_as_user_enabled() -> bool:
2424
try:
25-
raw = get_config("auth.auto_login_as_admin", False)
25+
raw = get_config("auth.auto_login_as_user", False)
2626
except Exception:
2727
return False
2828

@@ -73,7 +73,7 @@ def _resolve_auto_login_payload() -> Dict[str, Any]:
7373
# Delay import to avoid unnecessary dependency initialization at module import time.
7474
from web.service.user_service import UserService
7575

76-
login_data = UserService().login(username="admin", password="admin")
76+
login_data = UserService().login(username="user", password="user")
7777
session_id = str(login_data.get("session_id") or "").strip()
7878
if not session_id:
7979
raise RuntimeError("auto login failed to create a session id")
@@ -95,7 +95,7 @@ def _get_auto_login_user() -> Dict[str, Any]:
9595
except Exception as exc:
9696
raise HTTPException(
9797
status_code=500,
98-
detail=f"Auto login as admin failed: {exc}",
98+
detail=f"Auto login as user failed: {exc}",
9999
)
100100

101101

@@ -107,7 +107,7 @@ def get_login_user(request: Request) -> Dict[str, Any]:
107107
if payload:
108108
return _normalize_login_user(payload, session_id)
109109

110-
if _is_auto_login_as_admin_enabled():
110+
if _is_auto_login_as_user_enabled():
111111
return _get_auto_login_user()
112112

113113
raise HTTPException(status_code=401, detail="Not logged in.")

src/web/api/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from .agentic_synthesis_api import router as agentic_synthesis_router
66
from .reasoning_distillation_api import router as reasoning_distillation_router
77
from .sandbox_environment_api import router as sandbox_environment_router
8+
from .user_preference_api import router as user_preference_router
9+
from .workflow_assistant_api import router as workflow_assistant_router
810

911
__all__ = [
1012
"user_router",
@@ -15,4 +17,6 @@
1517
"agentic_synthesis_router",
1618
"reasoning_distillation_router",
1719
"sandbox_environment_router",
20+
"user_preference_router",
21+
"workflow_assistant_router",
1822
]

src/web/api/chat_api.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,25 @@ def delete_file(request: Request, path: str = Query(...)):
372372
}
373373

374374

375+
@router.get("/files/preview")
376+
def preview_file(
377+
request: Request,
378+
path: str = Query(...),
379+
page: int = Query(1, ge=1),
380+
page_size: int = Query(200, ge=1, le=200),
381+
):
382+
user = get_login_user(request)
383+
try:
384+
payload = _asset_service.preview_file_page(int(user["id"]), path, page=page, page_size=page_size)
385+
except ValueError as exc:
386+
raise HTTPException(status_code=400, detail=str(exc)) from exc
387+
388+
return {
389+
"ok": True,
390+
**payload,
391+
}
392+
393+
375394
@router.post("/upload")
376395
async def upload_file(request: Request, file: UploadFile = File(...), folder_path: str = Form("")):
377396
user = get_login_user(request)

src/web/api/reasoning_distillation_api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ def start_reasoning_distillation_task(request: Request, body: ReasoningDistillat
2929
source_type=body.source_type,
3030
source_dataset_id=body.source_dataset_id,
3131
source_task_id=body.source_task_id,
32+
selected_file_paths=body.selected_file_paths,
33+
file_mappings=[item.model_dump() for item in body.file_mappings],
34+
prompt_field=body.prompt_field,
35+
completion_field=body.completion_field,
3236
prompt=body.prompt,
37+
evaluation_enabled=body.evaluation_enabled,
38+
evaluation_prompt=body.evaluation_prompt,
3339
strategy=body.strategy,
3440
target_max_tokens=body.target_max_tokens,
3541
compression_ratio=body.compression_ratio,

0 commit comments

Comments
 (0)