fix(dev-server): 修复开发服务器和前端兼容性问题
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

修复内容:
1. 修复 dev_server.rs 编译错误 - 使用 Vec::new() 替代数组转换
2. 修复 pipeline-client.ts - 添加 Tauri 运行时检测和开发服务器 fallback
3. 更新 troubleshooting.md - 添加开发服务器使用说明

测试结果:
- 所有前端模块正常加载
- 开发服务器 API 响应正确
- 类型检查通过
This commit is contained in:
iven
2026-03-26 18:10:55 +08:00
parent 85bf47bebb
commit 9ee23e444c
8 changed files with 394 additions and 381 deletions

View File

@@ -11,6 +11,30 @@ import { listen, type UnlistenFn } from '@tauri-apps/api/event';
// Re-export UnlistenFn for external use
export type { UnlistenFn };
// === Tauri Runtime Detection ===
function isTauriRuntime(): boolean {
return typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;
}
const DEV_SERVER_URL = 'http://localhost:50051';
async function devServerFetch<T>(endpoint: string, options?: RequestInit): Promise<T> {
const response = await fetch(`${DEV_SERVER_URL}${endpoint}`, {
...options,
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
});
if (!response.ok) {
throw new Error(`Dev server error: ${response.status}`);
}
return response.json();
}
// === Types ===
export interface PipelineInputInfo {
@@ -78,6 +102,10 @@ export class PipelineClient {
category?: string;
industry?: string;
}): Promise<PipelineInfo[]> {
if (!isTauriRuntime()) {
return devServerFetch<PipelineInfo[]>('/api/pipelines');
}
try {
const pipelines = await invoke<PipelineInfo[]>('pipeline_list', {
category: options?.category || null,
@@ -94,6 +122,10 @@ export class PipelineClient {
* Get a specific pipeline by ID
*/
static async getPipeline(pipelineId: string): Promise<PipelineInfo> {
if (!isTauriRuntime()) {
return devServerFetch<PipelineInfo>(`/api/pipelines/${pipelineId}`);
}
try {
const pipeline = await invoke<PipelineInfo>('pipeline_get', {
pipelineId,
@@ -109,6 +141,13 @@ export class PipelineClient {
* Run a pipeline with the given inputs
*/
static async runPipeline(request: RunPipelineRequest): Promise<RunPipelineResponse> {
if (!isTauriRuntime()) {
return devServerFetch<RunPipelineResponse>('/api/pipelines/run', {
method: 'POST',
body: JSON.stringify({ request }),
});
}
try {
const response = await invoke<RunPipelineResponse>('pipeline_run', {
request,
@@ -124,6 +163,10 @@ export class PipelineClient {
* Get the progress of a running pipeline
*/
static async getProgress(runId: string): Promise<PipelineRunResponse> {
if (!isTauriRuntime()) {
return devServerFetch<PipelineRunResponse>(`/api/pipelines/${runId}/progress`);
}
try {
const progress = await invoke<PipelineRunResponse>('pipeline_progress', {
runId,
@@ -139,6 +182,10 @@ export class PipelineClient {
* Get the result of a completed pipeline run
*/
static async getResult(runId: string): Promise<PipelineRunResponse> {
if (!isTauriRuntime()) {
return devServerFetch<PipelineRunResponse>(`/api/pipelines/${runId}/result`);
}
try {
const result = await invoke<PipelineRunResponse>('pipeline_result', {
runId,
@@ -154,6 +201,11 @@ export class PipelineClient {
* Cancel a running pipeline
*/
static async cancel(runId: string): Promise<void> {
if (!isTauriRuntime()) {
await devServerFetch<void>(`/api/pipelines/${runId}/cancel`, { method: 'POST' });
return;
}
try {
await invoke('pipeline_cancel', { runId });
} catch (error) {
@@ -166,6 +218,10 @@ export class PipelineClient {
* List all runs
*/
static async listRuns(): Promise<PipelineRunResponse[]> {
if (!isTauriRuntime()) {
return devServerFetch<PipelineRunResponse[]>('/api/pipelines/runs');
}
try {
const runs = await invoke<PipelineRunResponse[]>('pipeline_runs');
return runs;
@@ -179,6 +235,10 @@ export class PipelineClient {
* Refresh pipeline discovery (rescan filesystem)
*/
static async refresh(): Promise<PipelineInfo[]> {
if (!isTauriRuntime()) {
return devServerFetch<PipelineInfo[]>('/api/pipelines/refresh', { method: 'POST' });
}
try {
const pipelines = await invoke<PipelineInfo[]>('pipeline_refresh');
return pipelines;