mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 12:05:54 +00:00
* refactor(web): migrate from Next.js to Vite + React Router
* fix: update build pipelines for Vite migration (out → dist)
- Dockerfile: npm run build → npx vite build, web/out → web/dist
- pyproject.toml: package-data web/out/** → web/dist/**
- paths.py: support both web/dist (Vite) and web/out (legacy) with fallback
* fix: remove .next from git tracking, add to .gitignore
1334 cached files from web/.next/ were accidentally committed.
Added .next/ to both root and web/.gitignore.
* fix: update build process to use Vite and correct output directory
* fix: update pnpm-lock.yaml and eslint config for Vite migration
* style: fix prettier formatting issues
* fix: add eslint-plugin-react-hooks for Vite migration
* fix: remove undefined eslint rule reference, downgrade react-hooks plugin to v5
* fix(web): clean up remaining Next.js artifacts in Vite migration
- Add vite-env.d.ts for import.meta.env and asset type declarations
- Remove dead layout.tsx (providers already in main.tsx)
- Fix useSearchParams destructuring to [searchParams] tuple (11 locations)
- Replace process.env.NEXT_PUBLIC_* with import.meta.env.VITE_*
- Fix langbotIcon.src to langbotIcon (Vite returns URL string)
- Fix Link href to Link to for react-router-dom
- Fix navigate({ scroll: false }) to { preventScrollReset: true }
- Fix [router] dependency arrays to [navigate]
- Remove Next.js plugin from tsconfig, set rsc: false in components.json
- Replace next lint with eslint in lint-staged
* feat: add tools API endpoint and tools-selector form type
Backend:
- Add GET /api/v1/tools — list all available tools (plugin + MCP)
- Add GET /api/v1/tools/<tool_name> — get specific tool details
Frontend:
- Add TOOLS_SELECTOR form type for plugin config forms
- Multi-select dialog with tool name and description
- Add PluginTool entity type and API client methods
* Revert "feat: add tools API endpoint and tools-selector form type"
This reverts commit 3c637fc563.
96 lines
2.9 KiB
Python
96 lines
2.9 KiB
Python
"""Utility functions for finding package resources"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
_is_source_install = None
|
|
|
|
|
|
def _check_if_source_install() -> bool:
|
|
"""
|
|
Check if we're running from source directory or an installed package.
|
|
Cached to avoid repeated file I/O.
|
|
"""
|
|
global _is_source_install
|
|
|
|
if _is_source_install is not None:
|
|
return _is_source_install
|
|
|
|
# Check if main.py exists in current directory with LangBot marker
|
|
if os.path.exists('main.py'):
|
|
try:
|
|
with open('main.py', 'r', encoding='utf-8') as f:
|
|
# Only read first 500 chars to check for marker
|
|
content = f.read(500)
|
|
if 'LangBot/main.py' in content:
|
|
_is_source_install = True
|
|
return True
|
|
except (IOError, OSError, UnicodeDecodeError):
|
|
# If we can't read the file, assume not a source install
|
|
pass
|
|
|
|
_is_source_install = False
|
|
return False
|
|
|
|
|
|
def get_frontend_path() -> str:
|
|
"""
|
|
Get the path to the frontend build files.
|
|
|
|
Returns the path to web/dist directory (Vite build output), handling both:
|
|
- Development mode: running from source directory
|
|
- Package mode: installed via pip/uvx
|
|
- Legacy mode: web/out (Next.js, for backward compatibility)
|
|
"""
|
|
# Check both dist (Vite) and out (legacy Next.js) paths
|
|
for dirname in ('dist', 'out'):
|
|
web_dir = f'web/{dirname}'
|
|
|
|
# First, check if we're running from source directory
|
|
if _check_if_source_install() and os.path.exists(web_dir):
|
|
return web_dir
|
|
|
|
# Second, check current directory
|
|
if os.path.exists(web_dir):
|
|
return web_dir
|
|
|
|
# Third, find it relative to the package installation
|
|
pkg_dir = Path(__file__).parent.parent.parent
|
|
frontend_path = pkg_dir / 'web' / dirname
|
|
if frontend_path.exists():
|
|
return str(frontend_path)
|
|
|
|
# Return the default path (will be checked by caller)
|
|
return 'web/dist'
|
|
|
|
|
|
def get_resource_path(resource: str) -> str:
|
|
"""
|
|
Get the path to a resource file.
|
|
|
|
Args:
|
|
resource: Relative path to resource (e.g., 'templates/config.yaml')
|
|
|
|
Returns:
|
|
Absolute path to the resource
|
|
"""
|
|
# First, check if resource exists in current directory (source install)
|
|
if _check_if_source_install() and os.path.exists(resource):
|
|
return resource
|
|
|
|
# Second, check current directory anyway
|
|
if os.path.exists(resource):
|
|
return resource
|
|
|
|
# Third, find it relative to package directory
|
|
# Get the directory where this file is located
|
|
# paths.py is in pkg/utils/, so parent.parent goes up to pkg/, then parent again goes up to the package root
|
|
pkg_dir = Path(__file__).parent.parent.parent
|
|
resource_path = pkg_dir / resource
|
|
if resource_path.exists():
|
|
return str(resource_path)
|
|
|
|
# Return the original path
|
|
return resource
|