Files
LangBot/web/src/app/infra/http
Junyan Chin 2317392ee5 refactor(web): migrate from Next.js to Vite + React Router (#2102)
* 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.
2026-04-03 17:09:17 +08:00
..
2026-02-09 10:48:22 +08:00
2025-08-16 18:05:33 +08:00

HTTP Client 架构说明

概述

HTTP Client 已经重构为更清晰的架构,将通用方法与业务逻辑分离,并为不同的服务创建了独立的客户端。

文件结构

  • BaseHttpClient.ts - 基础 HTTP 客户端类,包含所有通用的 HTTP 方法和拦截器配置
  • BackendClient.ts - 后端服务客户端,处理与后端 API 的所有交互
  • CloudServiceClient.ts - 云服务客户端,处理与 cloud service 的交互(如插件市场)
  • index.ts - 主入口文件,管理客户端实例的创建和导出
  • HttpClient.ts - 仅用于向后兼容的文件(已废弃)

使用方法

新的推荐用法

// 使用后端客户端
import { backendClient } from '@/app/infra/http';

// 获取模型列表
const models = await backendClient.getProviderLLMModels();

// 使用云服务客户端(异步方式,确保 URL 已初始化)
import { getCloudServiceClient } from '@/app/infra/http';

const cloudClient = await getCloudServiceClient();
const marketPlugins = await cloudClient.getMarketPlugins(1, 10, 'search term');

// 使用云服务客户端(同步方式,可能使用默认 URL
import { cloudServiceClient } from '@/app/infra/http';

const marketPlugins = await cloudServiceClient.getMarketPlugins(
  1,
  10,
  'search term',
);

向后兼容(不推荐)

// 旧的用法仍然可以工作
import { httpClient, spaceClient } from '@/app/infra/http/HttpClient';

// httpClient 现在指向 backendClient
const models = await httpClient.getProviderLLMModels();

// spaceClient 现在指向 cloudServiceClient
const marketPlugins = await spaceClient.getMarketPlugins(1, 10, 'search term');

特点

  1. 清晰的职责分离

    • BaseHttpClient通用 HTTP 功能
    • BackendClient后端 API 业务逻辑
    • CloudServiceClient云服务 API 业务逻辑
  2. 自动初始化

    • 应用启动时自动从后端获取 cloud service URL
    • 云服务客户端会自动更新 baseURL
  3. 类型安全

    • 所有方法都有完整的 TypeScript 类型定义
    • 请求和响应类型都从 @/app/infra/entities/api 导入
  4. 向后兼容

    • 旧代码无需修改即可继续工作
    • 逐步迁移到新的 API