feat: OpenAPI YAML support for frontend toolserver

This commit is contained in:
Thomas Rehn
2025-04-09 09:46:44 +02:00
parent 81af20aa9b
commit 17ea20d3ad
3 changed files with 32 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
import { convertOpenApiToToolPayload } from '$lib/utils';
import { getOpenAIModelsDirect } from './openai';
import { parse } from 'yaml';
import { toast } from 'svelte-sonner';
export const getModels = async (
@@ -271,8 +272,15 @@ export const getToolServerData = async (token: string, url: string) => {
}
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
// Check if URL ends with .yaml or .yml to determine format
if (url.toLowerCase().endsWith('.yaml') || url.toLowerCase().endsWith('.yml')) {
if (!res.ok) throw await res.text();
const text = await res.text();
return parse(text);
} else {
if (!res.ok) throw await res.json();
return res.json();
}
})
.catch((err) => {
console.log(err);