Files
beaver_project/app-instance/frontend/lib/i18n/core.ts
steven_li cdfc222c9f feat: 添加swarms团队编排功能并优化agent委派系统
- 引入AgentTeamOrchestrator支持多agent协同任务执行
- 增加第三方swarms库依赖并配置git协议替换以改善包管理
- 扩展DelegationManager支持团队任务调度和进度跟踪
- 实现中文bigram分词算法提升中文任务检索准确性
- 调整A2AClient和DelegationManager超时时间从30秒增至600秒
- 优化AgentRunResult状态判断逻辑增加有意义摘要检测
- 修改Dockerfile配置npm仓库镜像地址和git协议映射
- 更新CLI命令行接口支持网关端口配置传递
- 调整提供者超时配置机制增强请求稳定性
- 移除过时的support_group字段简化agent描述符结构
- 增强错误处理和进度事件报告机制改进用户体验
2026-04-14 14:34:23 +08:00

77 lines
2.0 KiB
TypeScript

export const APP_LOCALE_COOKIE = 'nanobot_locale';
export const APP_LOCALE_STORAGE_KEY = 'nanobot_locale';
export const APP_LOCALES = ['zh-CN', 'en-US'] as const;
export type AppLocale = (typeof APP_LOCALES)[number];
export function isAppLocale(value: string | null | undefined): value is AppLocale {
return value === 'zh-CN' || value === 'en-US';
}
export function normalizeAppLocale(value?: string | null): AppLocale {
const probe = value?.trim().toLowerCase() || '';
if (probe.startsWith('en')) {
return 'en-US';
}
return 'zh-CN';
}
function readCookieLocale(): string | null {
if (typeof document === 'undefined') {
return null;
}
const match = document.cookie
.split('; ')
.find((item) => item.startsWith(`${APP_LOCALE_COOKIE}=`));
if (!match) {
return null;
}
return decodeURIComponent(match.slice(APP_LOCALE_COOKIE.length + 1));
}
export function readBrowserAppLocale(): AppLocale {
if (typeof window === 'undefined') {
return 'zh-CN';
}
const fromDocument = document.documentElement.lang;
if (fromDocument) {
return normalizeAppLocale(fromDocument);
}
const fromStorage = window.localStorage.getItem(APP_LOCALE_STORAGE_KEY);
if (fromStorage) {
return normalizeAppLocale(fromStorage);
}
const fromCookie = readCookieLocale();
if (fromCookie) {
return normalizeAppLocale(fromCookie);
}
return normalizeAppLocale(window.navigator.language);
}
export function persistAppLocale(locale: AppLocale): void {
if (typeof window === 'undefined') {
return;
}
document.documentElement.lang = locale;
window.localStorage.setItem(APP_LOCALE_STORAGE_KEY, locale);
document.cookie = `${APP_LOCALE_COOKIE}=${encodeURIComponent(locale)}; path=/; max-age=31536000; samesite=lax`;
}
export function getCurrentAppLocale(): AppLocale {
if (typeof window === 'undefined') {
return 'zh-CN';
}
return readBrowserAppLocale();
}
export function pickAppText<T>(locale: AppLocale, zhValue: T, enValue: T): T {
return locale === 'en-US' ? enValue : zhValue;
}