feat: refactor HomePage to integrate agents store and update related components
feat: add runtime event handling for providers in ProvidersSection feat: update routing to include Channels and Agents pages feat: extend route types and navigation items for Channels and Agents feat: implement agents store for managing agent data and interactions fix: update chat store to utilize agents store for agent-related functionality chore: export agents store from index fix: enhance runtime types for better event handling fix: update Vite config to handle dev server URL correctly
This commit is contained in:
@@ -13,30 +13,39 @@ import axios from 'axios';
|
||||
import { onProviderChange } from '@electron/service/provider-api-service';
|
||||
import { gatewayManager } from '@electron/gateway/manager';
|
||||
import { dispatchLocalHostApi } from '@electron/api/router';
|
||||
import { syncProviderRuntimeSnapshot } from '@electron/service/provider-runtime-sync';
|
||||
|
||||
// 初始化 updater,确保在 app ready 之前或者之中注册好 IPC
|
||||
appUpdater.init();
|
||||
|
||||
// 注册 hostapi:fetch IPC 代理
|
||||
// 模型管理相关接口在本地处理(对齐 ClawX),其余接口代理到远端后端
|
||||
const HOST_API_BASE_URL = process.env.VITE_SERVICE_URL || 'http://8.138.234.141/ingress';
|
||||
const HOST_API_BASE_URL = process.env['ZN_AI_HOST_API_BASE_URL']
|
||||
|| process.env['VITE_SERVICE_URL']
|
||||
|| 'http://8.138.234.141/ingress';
|
||||
|
||||
ipcMain.handle('hostapi:fetch', async (_event, { path, method, headers, body }) => {
|
||||
// 1. 优先本地处理 Host API 路由(逐步对齐 ClawX)
|
||||
const localResult = await dispatchLocalHostApi({
|
||||
path,
|
||||
method: method || 'GET',
|
||||
headers,
|
||||
body,
|
||||
});
|
||||
if (localResult) return localResult;
|
||||
function refreshProviderRuntime(): { warnings: string[] } {
|
||||
try {
|
||||
return syncProviderRuntimeSnapshot();
|
||||
} catch (error) {
|
||||
log.error('provider runtime sync failed', error);
|
||||
return {
|
||||
warnings: [error instanceof Error ? error.message : String(error)],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 其余接口代理到远端后端
|
||||
function shouldPreferUpstreamHostApi(path: string, method: string): boolean {
|
||||
const pathname = new URL(path, 'http://127.0.0.1').pathname;
|
||||
return method.toUpperCase() === 'GET' && pathname === '/api/channels/targets';
|
||||
}
|
||||
|
||||
async function requestUpstreamHostApi(path: string, method: string, headers: Record<string, string> | undefined, body: unknown) {
|
||||
const url = `${HOST_API_BASE_URL}${path}`;
|
||||
try {
|
||||
const response = await axios({
|
||||
url,
|
||||
method: method || 'GET',
|
||||
method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...headers,
|
||||
@@ -67,6 +76,29 @@ ipcMain.handle('hostapi:fetch', async (_event, { path, method, headers, body })
|
||||
error: error.message || 'Unknown error',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
ipcMain.handle('hostapi:fetch', async (_event, { path, method, headers, body }) => {
|
||||
const normalizedMethod = method || 'GET';
|
||||
|
||||
if (shouldPreferUpstreamHostApi(path, normalizedMethod)) {
|
||||
const upstreamPreferred = await requestUpstreamHostApi(path, normalizedMethod, headers, body);
|
||||
if (upstreamPreferred.success !== false && upstreamPreferred.ok !== false) {
|
||||
return upstreamPreferred;
|
||||
}
|
||||
}
|
||||
|
||||
// 1. 优先本地处理 Host API 路由(逐步对齐 ClawX)
|
||||
const localResult = await dispatchLocalHostApi({
|
||||
path,
|
||||
method: normalizedMethod,
|
||||
headers,
|
||||
body,
|
||||
});
|
||||
if (localResult) return localResult;
|
||||
|
||||
// 2. 其余接口代理到远端后端
|
||||
return await requestUpstreamHostApi(path, normalizedMethod, headers, body);
|
||||
});
|
||||
|
||||
// Gateway RPC IPC handler
|
||||
@@ -95,9 +127,15 @@ app.whenReady().then(async () => {
|
||||
await themeManager.init();
|
||||
|
||||
gatewayManager.init();
|
||||
refreshProviderRuntime();
|
||||
|
||||
onProviderChange(() => {
|
||||
gatewayManager.reloadProviders();
|
||||
const runtimeSync = refreshProviderRuntime();
|
||||
gatewayManager.reloadProviders({
|
||||
topics: ['providers', 'models', 'agents'],
|
||||
reason: 'providers:changed',
|
||||
warnings: runtimeSync.warnings,
|
||||
});
|
||||
});
|
||||
|
||||
setupMainWindow();
|
||||
|
||||
Reference in New Issue
Block a user