Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions agent/app/service/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -1071,14 +1071,14 @@ func normalizeAllowedOrigin(origin string) (string, error) {
if pathValue := strings.TrimSpace(parsed.EscapedPath()); pathValue != "" && pathValue != "/" {
return "", fmt.Errorf("invalid allowed origin: %s", origin)
}
if parsed.Port() == "" {
return "", fmt.Errorf("invalid allowed origin: %s", origin)
}
host := parsed.Hostname()
if strings.Contains(host, ":") {
host = "[" + host + "]"
}
normalized := "https://" + host + ":" + parsed.Port()
normalized := parsed.Scheme + "://" + host
if parsed.Port() != "" {
normalized += ":" + parsed.Port()
}
return normalized, nil
}

Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,10 @@ const message = {
webuiPort: 'WebUI Port',
allowedOrigins: 'Access Addresses',
allowedOriginsHelper:
'Enter one full HTTPS access address per line, for example https://192.168.1.2:18789. Fill it manually if the default access address is not configured.',
'Enter one full access address per line. HTTPS is recommended, for example https://192.168.1.2:18789. Fill it manually if the default access address is not configured.',
allowedOriginsPlaceholder: 'https://192.168.1.2:18789',
allowedOriginsRequired: 'Enter at least one access address',
allowedOriginsInvalid: 'Use the format http(s)://host-or-ip:port',
allowedOriginsHttpsOnly: 'Access addresses must start with https://',
allowedOriginsInvalid: 'Use the format http(s)://host-or-ip[:port]',
provider: 'Provider',
apiKey: 'API Key',
baseUrl: 'Base URL',
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/es-es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,10 @@ const message = {
webuiPort: 'Puerto WebUI',
allowedOrigins: 'Direcciones de acceso',
allowedOriginsHelper:
'Introduce una dirección de acceso HTTPS completa por línea, por ejemplo https://192.168.1.2:18789. Si no hay una dirección predeterminada configurada, rellénala manualmente.',
'Introduce una dirección de acceso completa por línea. Se recomienda usar HTTPS, por ejemplo https://192.168.1.2:18789. Si no hay una dirección predeterminada configurada, rellénala manualmente.',
allowedOriginsPlaceholder: 'https://192.168.1.2:18789',
allowedOriginsRequired: 'Introduce al menos una dirección de acceso',
allowedOriginsInvalid: 'Usa el formato http(s)://host-o-ip:puerto',
allowedOriginsHttpsOnly: 'Las direcciones de acceso deben comenzar con https://',
allowedOriginsInvalid: 'Usa el formato http(s)://host-o-ip[:puerto]',
provider: 'Proveedor de modelos',
apiKey: 'Clave API',
baseUrl: 'URL base',
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,11 +682,10 @@ const message = {
webuiPort: 'WebUI ポート',
allowedOrigins: 'アクセスアドレス',
allowedOriginsHelper:
'1 行に 1 つずつ完全な HTTPS アクセスアドレスを入力してください。例: https://192.168.1.2:18789。デフォルトのアクセスアドレスが未設定の場合は手動で入力してください。',
'1 行に 1 つずつ完全なアクセスアドレスを入力してください。HTTPS を推奨します。例: https://192.168.1.2:18789。デフォルトのアクセスアドレスが未設定の場合は手動で入力してください。',
allowedOriginsPlaceholder: 'https://192.168.1.2:18789',
allowedOriginsRequired: '少なくとも 1 つのアクセスアドレスを入力してください',
allowedOriginsInvalid: 'http(s)://host-or-ip:port の形式で入力してください',
allowedOriginsHttpsOnly: 'アクセスアドレスは https:// で始めてください',
allowedOriginsInvalid: 'http(s)://host-or-ip[:port] の形式で入力してください',
provider: 'モデルプロバイダー',
apiKey: 'API キー',
baseUrl: 'ベースURL',
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,11 +674,10 @@ const message = {
webuiPort: 'WebUI 포트',
allowedOrigins: '접속 주소',
allowedOriginsHelper:
'한 줄에 하나의 전체 HTTPS 접속 주소를 입력하세요. 예: https://192.168.1.2:18789. 기본 접속 주소가 설정되지 않은 경우 수동으로 입력하세요.',
'한 줄에 하나의 전체 접속 주소를 입력하세요. HTTPS 사용을 권장합니다. 예: https://192.168.1.2:18789. 기본 접속 주소가 설정되지 않은 경우 수동으로 입력하세요.',
allowedOriginsPlaceholder: 'https://192.168.1.2:18789',
allowedOriginsRequired: '접속 주소를 하나 이상 입력하세요',
allowedOriginsInvalid: 'http(s)://host-or-ip:port 형식으로 입력하세요',
allowedOriginsHttpsOnly: '접속 주소는 https:// 로 시작해야 합니다',
allowedOriginsInvalid: 'http(s)://host-or-ip[:port] 형식으로 입력하세요',
provider: '모델 제공자',
apiKey: 'API 키',
baseUrl: '기본 URL',
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/ms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,10 @@ const message = {
webuiPort: 'Port WebUI',
allowedOrigins: 'Alamat akses',
allowedOriginsHelper:
'Masukkan satu alamat akses HTTPS penuh bagi setiap baris, contohnya https://192.168.1.2:18789. Isikan secara manual jika alamat akses lalai belum dikonfigurasi.',
'Masukkan satu alamat akses penuh bagi setiap baris. HTTPS disyorkan, contohnya https://192.168.1.2:18789. Isikan secara manual jika alamat akses lalai belum dikonfigurasi.',
allowedOriginsPlaceholder: 'https://192.168.1.2:18789',
allowedOriginsRequired: 'Masukkan sekurang-kurangnya satu alamat akses',
allowedOriginsInvalid: 'Gunakan format http(s)://hos-atau-ip:port',
allowedOriginsHttpsOnly: 'Alamat akses mesti bermula dengan https://',
allowedOriginsInvalid: 'Gunakan format http(s)://hos-atau-ip[:port]',
provider: 'Penyedia model',
apiKey: 'Kunci API',
baseUrl: 'URL asas',
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/pt-br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,10 @@ const message = {
webuiPort: 'Porta WebUI',
allowedOrigins: 'Endereços de acesso',
allowedOriginsHelper:
'Informe um endereço de acesso HTTPS completo por linha, por exemplo https://192.168.1.2:18789. Preencha manualmente se o endereço padrão não estiver configurado.',
'Informe um endereço de acesso completo por linha. O uso de HTTPS é recomendado, por exemplo https://192.168.1.2:18789. Preencha manualmente se o endereço padrão não estiver configurado.',
allowedOriginsPlaceholder: 'https://192.168.1.2:18789',
allowedOriginsRequired: 'Informe pelo menos um endereço de acesso',
allowedOriginsInvalid: 'Use o formato http(s)://host-ou-ip:porta',
allowedOriginsHttpsOnly: 'Os endereços de acesso devem começar com https://',
allowedOriginsInvalid: 'Use o formato http(s)://host-ou-ip[:porta]',
provider: 'Provedor de modelos',
apiKey: 'Chave API',
baseUrl: 'URL base',
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,10 @@ const message = {
webuiPort: 'Порт WebUI',
allowedOrigins: 'Адреса доступа',
allowedOriginsHelper:
'Указывайте по одному полному HTTPS-адресу доступа в строке, например https://192.168.1.2:18789. Если адрес по умолчанию не настроен, введите его вручную.',
'Указывайте по одному полному адресу доступа в строке. Рекомендуется использовать HTTPS, например https://192.168.1.2:18789. Если адрес по умолчанию не настроен, введите его вручную.',
allowedOriginsPlaceholder: 'https://192.168.1.2:18789',
allowedOriginsRequired: 'Укажите хотя бы один адрес доступа',
allowedOriginsInvalid: 'Используйте формат http(s)://host-or-ip:port',
allowedOriginsHttpsOnly: 'Адреса доступа должны начинаться с https://',
allowedOriginsInvalid: 'Используйте формат http(s)://host-or-ip[:port]',
provider: 'Поставщик моделей',
apiKey: 'API ключ',
baseUrl: 'Базовый URL',
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,10 @@ const message = {
webuiPort: 'WebUI portu',
allowedOrigins: 'Erişim adresleri',
allowedOriginsHelper:
'Her satıra bir tam HTTPS erişim adresi girin. Örnek: https://192.168.1.2:18789. Varsayılan erişim adresi yapılandırılmamışsa elle girin.',
'Her satıra bir tam erişim adresi girin. HTTPS kullanmanız önerilir. Örnek: https://192.168.1.2:18789. Varsayılan erişim adresi yapılandırılmamışsa elle girin.',
allowedOriginsPlaceholder: 'https://192.168.1.2:18789',
allowedOriginsRequired: 'En az bir erişim adresi girin',
allowedOriginsInvalid: 'http(s)://host-veya-ip:port biçimini kullanın',
allowedOriginsHttpsOnly: 'Erişim adresleri https:// ile başlamalıdır',
allowedOriginsInvalid: 'http(s)://host-veya-ip[:port] biçimini kullanın',
provider: 'Model sağlayıcı',
apiKey: 'API anahtarı',
baseUrl: 'Temel URL',
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,10 @@ const message = {
webuiPort: 'WebUI 埠',
allowedOrigins: '訪問地址',
allowedOriginsHelper:
'一行一個完整 HTTPS 訪問地址,例如 https://192.168.1.2:18789;未設定預設訪問地址時請手動填寫',
'一行一個完整訪問地址,建議優先使用 HTTPS,例如 https://192.168.1.2:18789;未設定預設訪問地址時請手動填寫',
allowedOriginsPlaceholder: 'https://192.168.1.2:18789',
allowedOriginsRequired: '請至少填寫一個訪問地址',
allowedOriginsInvalid: '訪問地址格式錯誤,請輸入 http(s)://網域或IP:埠',
allowedOriginsHttpsOnly: '訪問地址必須以 https:// 開頭',
allowedOriginsInvalid: '訪問地址格式錯誤,請輸入 http(s)://網域或IP[:埠]',
provider: '模型供應商',
apiKey: 'API Key',
baseUrl: 'Base URL',
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,11 +648,10 @@ const message = {
webuiPort: 'WebUI 端口',
allowedOrigins: '访问地址',
allowedOriginsHelper:
'一行一个完整 HTTPS 访问地址,例如 https://192.168.1.2:18789;未配置默认访问地址时请手动填写',
'一行一个完整访问地址,建议优先使用 HTTPS,例如 https://192.168.1.2:18789;未配置默认访问地址时请手动填写',
allowedOriginsPlaceholder: 'https://192.168.1.2:18789',
allowedOriginsRequired: '请至少填写一个访问地址',
allowedOriginsInvalid: '访问地址格式错误,请输入 http(s)://域名或IP:端口',
allowedOriginsHttpsOnly: '访问地址必须以 https:// 开头',
allowedOriginsInvalid: '访问地址格式错误,请输入 http(s)://域名或IP[:端口]',
provider: '模型供应商',
apiKey: 'API Key',
baseUrl: 'Base URL',
Expand Down
21 changes: 7 additions & 14 deletions frontend/src/utils/agent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import i18n from '@/lang';

interface AllowedOriginOptions {
httpsOnly?: boolean;
}

export const getAgentProviderDisplayName = (provider: string, displayName?: string): string => {
if (provider === 'custom' || displayName === 'Custom') {
return i18n.global.t('container.custom');
Expand All @@ -23,7 +19,7 @@ export const buildDefaultAllowedOrigin = (systemIP: string, port?: number | stri
return `https://${host}:${port}`;
};

export const normalizeAllowedOrigin = (value: string, options: AllowedOriginOptions = {}): string => {
export const normalizeAllowedOrigin = (value: string): string => {
const target = String(value || '').trim();
if (!target) {
throw new Error(i18n.global.t('aiTools.agents.allowedOriginsInvalid'));
Expand All @@ -34,9 +30,6 @@ export const normalizeAllowedOrigin = (value: string, options: AllowedOriginOpti
} catch (error) {
throw new Error(i18n.global.t('aiTools.agents.allowedOriginsInvalid'));
}
if (options.httpsOnly && parsed.protocol !== 'https:') {
throw new Error(i18n.global.t('aiTools.agents.allowedOriginsHttpsOnly'));
}
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
throw new Error(i18n.global.t('aiTools.agents.allowedOriginsInvalid'));
}
Expand All @@ -46,21 +39,21 @@ export const normalizeAllowedOrigin = (value: string, options: AllowedOriginOpti
if (parsed.pathname && parsed.pathname !== '/') {
throw new Error(i18n.global.t('aiTools.agents.allowedOriginsInvalid'));
}
if (!parsed.host || !parsed.port) {
if (!parsed.host) {
throw new Error(i18n.global.t('aiTools.agents.allowedOriginsInvalid'));
}
return `https://${parsed.host}`;
return `${parsed.protocol}//${parsed.host}`;
};

export const parseAllowedOriginsInput = (value: string, options: AllowedOriginOptions = {}): string[] => {
export const parseAllowedOriginsInput = (value: string): string[] => {
const result: string[] = [];
const seen = new Set<string>();
for (const line of String(value || '').split(/\r?\n/)) {
const target = line.trim();
if (!target) {
continue;
}
const normalized = normalizeAllowedOrigin(target, options);
const normalized = normalizeAllowedOrigin(target);
if (seen.has(normalized)) {
continue;
}
Expand All @@ -70,9 +63,9 @@ export const parseAllowedOriginsInput = (value: string, options: AllowedOriginOp
return result;
};

export const validateAllowedOriginsInput = (value: string, options: AllowedOriginOptions = {}): string => {
export const validateAllowedOriginsInput = (value: string): string => {
try {
const parsed = parseAllowedOriginsInput(value, options);
const parsed = parseAllowedOriginsInput(value);
if (parsed.length === 0) {
return i18n.global.t('aiTools.agents.allowedOriginsRequired');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const rules = reactive({
allowedOrigins: [
{
validator: (_rule: any, value: any, callback: (error?: Error) => void) => {
const message = validateAllowedOriginsInput(String(value || ''), { httpsOnly: true });
const message = validateAllowedOriginsInput(String(value || ''));
if (message) {
callback(new Error(message));
return;
Expand Down Expand Up @@ -73,7 +73,7 @@ const saveConfig = async () => {
try {
await updateAgentSecurityConfig({
agentId: agentId.value,
allowedOrigins: parseAllowedOriginsInput(form.allowedOrigins, { httpsOnly: true }),
allowedOrigins: parseAllowedOriginsInput(form.allowedOrigins),
});
MsgSuccess(t('aiTools.agents.saveSuccess'));
} finally {
Expand Down
Loading