diff --git a/src/lib/helpers/http.js b/src/lib/helpers/http.js index 4d5c467b..7f53127e 100644 --- a/src/lib/helpers/http.js +++ b/src/lib/helpers/http.js @@ -61,6 +61,7 @@ function skipLoader(config) { new RegExp('http(s*)://(.*?)/knowledge/(.*?)/search', 'g'), new RegExp('http(s*)://(.*?)/knowledge/vector/(.*?)/create', 'g'), new RegExp('http(s*)://(.*?)/knowledge/document/(.*?)/page', 'g'), + new RegExp('http(s*)://(.*?)/users', 'g') ]; const putRegexes = [ @@ -84,8 +85,7 @@ function skipLoader(config) { new RegExp('http(s*)://(.*?)/conversation/(.*?)/files/(.*?)', 'g'), new RegExp('http(s*)://(.*?)/llm-provider/(.*?)/models', 'g'), new RegExp('http(s*)://(.*?)/knowledge/vector/collections', 'g'), - new RegExp('http(s*)://(.*?)/knowledge/vector/(.*?)/exist', 'g'), - new RegExp('http(s*)://(.*?)/users', 'g') + new RegExp('http(s*)://(.*?)/knowledge/vector/(.*?)/exist', 'g') ]; if (config.method === 'post' && postRegexes.some(regex => regex.test(config.url || ''))) { diff --git a/src/lib/services/agent-service.js b/src/lib/services/agent-service.js index 970ab721..73193cae 100644 --- a/src/lib/services/agent-service.js +++ b/src/lib/services/agent-service.js @@ -14,13 +14,15 @@ export async function getSettings() { /** * Get agent list * @param {import('$agentTypes').AgentFilter} filter + * @param {boolean} checkAuth * @returns {Promise>} */ -export async function getAgents(filter) { +export async function getAgents(filter, checkAuth = false) { let url = endpoints.agentListUrl; const response = await axios.get(url, { params: { - ...filter + ...filter, + checkAuth : checkAuth }, paramsSerializer: { dots: true, diff --git a/src/routes/chat/+page.svelte b/src/routes/chat/+page.svelte index 63777ae7..30f02cc0 100644 --- a/src/routes/chat/+page.svelte +++ b/src/routes/chat/+page.svelte @@ -16,7 +16,7 @@ let agentId = 'undefined'; onMount(async () => { - const response = await getAgents(filter); + const response = await getAgents(filter, true); agents = response?.items?.map(t => { return { ...t }; }) || []; const agentSettings = await getSettingDetail("Agent"); // @ts-ignore diff --git a/src/routes/page/agent/+page.svelte b/src/routes/page/agent/+page.svelte index 7249d3b8..516bbe66 100644 --- a/src/routes/page/agent/+page.svelte +++ b/src/routes/page/agent/+page.svelte @@ -45,7 +45,7 @@ function getPagedAgents() { isLoading = true; - getAgents(filter).then(data => { + getAgents(filter, true).then(data => { agents = data; }).catch(() => { agents = { items: [], count: 0 }; diff --git a/src/routes/page/users/+page.svelte b/src/routes/page/users/+page.svelte index 506006d2..86212624 100644 --- a/src/routes/page/users/+page.svelte +++ b/src/routes/page/users/+page.svelte @@ -12,7 +12,6 @@ Table } from '@sveltestrap/sveltestrap'; import { _ } from 'svelte-i18n'; - import lodash from "lodash"; import HeadTitle from "$lib/common/HeadTitle.svelte"; import Breadcrumb from '$lib/common/Breadcrumb.svelte'; import TablePagination from '$lib/common/TablePagination.svelte'; @@ -39,8 +38,8 @@ /** @type {import('$userTypes').UserFilter} */ let filter = { ... initPager }; - /** @type {import('$commonTypes').PagedItems} */ - let users = { count: 0, items: [] }; + /** @type {import('$userTypes').UserModel[]} */ + let userItems = []; /** @type {import('$commonTypes').IdName[]} */ let agents = []; @@ -53,45 +52,50 @@ }; onMount(async () => { - await getPagedAgents(); - await getPagedUsers(); + isLoading = true; + getPagedAgents().then(() => { + getPagedUsers().then(() => { + isLoading = false; + }); + }); }); - async function getPagedUsers() { + function getPagedUsers() { + userItems = []; isLoading = true; return new Promise((resolve, reject) => { getUsers(filter).then(res => { - users = res; - refresh(); + refresh(res); resolve(res); }).finally(() => { - setTimeout(() => { - isLoading = false; - }, 200); + isLoading = false; }); }); } - async function getPagedAgents() { - const response = await getAgents({ pager: { page: 1, size: 100, count: 0 } }); - agents = response?.items?.map(x => { + function getPagedAgents() { + return new Promise((resolve, reject) => { + getAgents({ pager: { page: 1, size: 100, count: 0 } }).then(res => { + agents = res?.items?.map(x => { return { id: x.id, name: x.name }; })?.sort((a, b) => a.name.localeCompare(b.name)) || []; + resolve(agents); + }); + }); } - function refresh() { - refreshUsers(); + /** @param {import('$commonTypes').PagedItems} users */ + function refresh(users) { + refreshUsers(users); refreshPager(users.count, filter.page, filter.size); } - function refreshUsers() { - users = { - items: users?.items?.map(t => ({ ...t, open_detail: false })) || [], - count: users?.count || 0 - }; + /** @param {import('$commonTypes').PagedItems} users */ + function refreshUsers(users) { + userItems = [ ...users.items ]; } /** @param {number} totalItemsCount */ @@ -157,16 +161,12 @@ /** @param {import('$userTypes').UserModel} data */ function postUpdateUser(data) { - const newItems = users?.items?.map(x => { + userItems = userItems?.map(x => { if (x.id === data.id) { return { ...data, open_detail: true }; } return x; }) || []; - users = { - ...users, - items: newItems - }; } @@ -239,7 +239,7 @@ - {#each users.items as item, idx (idx)} + {#each userItems as item, idx (idx)}