755bf80858
新增 Godot 项目选择、校验、导入和项目上下文切换入口。 只在所选项目根保留 .agent 元数据,并让总控使用标准运行档。 修复发布版原生 API 访问和 React runtime 重复加载问题。 收紧 Provider 工具 Schema 子集并增加回归门禁。 补充 Rust、前端测试及 PRD、技术方案和共享决策记录。
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { fetch as tauriHttpFetch } from '@tauri-apps/plugin-http';
|
|
|
|
export const AGC_DEVELOPMENT_API_BASE_URL = 'https://dev.genarrative.world';
|
|
|
|
type ClientHttpContext = {
|
|
isDevelopment: boolean;
|
|
isTauri: boolean;
|
|
pageProtocol: string;
|
|
};
|
|
|
|
type ClientHttpTarget = {
|
|
transport: 'web' | 'tauri-http';
|
|
url: string;
|
|
};
|
|
|
|
function currentClientHttpContext(): ClientHttpContext {
|
|
return {
|
|
isDevelopment: import.meta.env.DEV,
|
|
isTauri: typeof window !== 'undefined' && Boolean(window.__TAURI__),
|
|
pageProtocol: typeof window === 'undefined' ? '' : window.location.protocol,
|
|
};
|
|
}
|
|
|
|
export function resolveClientHttpTarget(
|
|
url: string,
|
|
context: ClientHttpContext = currentClientHttpContext(),
|
|
): ClientHttpTarget {
|
|
if (context.isDevelopment) {
|
|
return { transport: 'web', url };
|
|
}
|
|
|
|
const isHttpPage =
|
|
context.pageProtocol === 'http:' || context.pageProtocol === 'https:';
|
|
if (!context.isTauri && isHttpPage) {
|
|
return { transport: 'web', url };
|
|
}
|
|
|
|
if (!context.isTauri) {
|
|
return { transport: 'web', url };
|
|
}
|
|
|
|
const target = new URL(url, `${AGC_DEVELOPMENT_API_BASE_URL}/`);
|
|
if (target.origin !== AGC_DEVELOPMENT_API_BASE_URL) {
|
|
throw new Error('AGC release API 请求目标不在允许的开发服务器范围内');
|
|
}
|
|
return { transport: 'tauri-http', url: target.toString() };
|
|
}
|
|
|
|
export async function fetchClientHttp(
|
|
url: string,
|
|
init: RequestInit,
|
|
): Promise<Response> {
|
|
const target = resolveClientHttpTarget(url);
|
|
if (target.transport === 'tauri-http') {
|
|
return tauriHttpFetch(target.url, init);
|
|
}
|
|
return fetch(target.url, init);
|
|
}
|