From 39de4f3b44f8fb7ea0fdb97ee89f1f46121fc188 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 23 Jan 2024 11:29:04 -0600 Subject: [PATCH] use get --- src/lib/services/agent-service.js | 12 +++--- src/lib/services/conversation-service.js | 6 ++- src/lib/services/plugin-service.js | 6 ++- src/routes/page/agent/+page.svelte | 24 +++++------ src/routes/page/agent/router/+page.svelte | 18 +++++++-- .../page/agent/router/routing-flow.svelte | 40 +++++++++++-------- 6 files changed, 64 insertions(+), 42 deletions(-) diff --git a/src/lib/services/agent-service.js b/src/lib/services/agent-service.js index 953d5d8c..5999da0c 100644 --- a/src/lib/services/agent-service.js +++ b/src/lib/services/agent-service.js @@ -11,12 +11,6 @@ export async function getSettings() { return response.data; } -/** - * Get conversation list - * @param {import('$types').ConversationFilter} filter - * @returns {Promise>} - */ - /** * Get agent list * @param {import('$types').AgentFilter} filter @@ -24,7 +18,11 @@ export async function getSettings() { */ export async function getAgents(filter) { let url = endpoints.agentListUrl; - const response = await axios.post(url, { ...filter }); + const response = await axios.get(url, { params: filter, + paramsSerializer: { + dots: true + } + }); return response.data; } diff --git a/src/lib/services/conversation-service.js b/src/lib/services/conversation-service.js index dfffb481..c8e49bd0 100644 --- a/src/lib/services/conversation-service.js +++ b/src/lib/services/conversation-service.js @@ -31,7 +31,11 @@ export async function getConversation(id) { */ export async function getConversations(filter) { let url = endpoints.conversationsUrl; - const response = await axios.post(url, { ...filter }); + const response = await axios.get(url, { params: filter, + paramsSerializer: { + dots: true + } + }); return response.data; } diff --git a/src/lib/services/plugin-service.js b/src/lib/services/plugin-service.js index 7ab71227..aa387f84 100644 --- a/src/lib/services/plugin-service.js +++ b/src/lib/services/plugin-service.js @@ -9,7 +9,11 @@ import axios from 'axios'; */ export async function getPlugins(filter) { let url = endpoints.pluginListUrl; - const response = await axios.post(url, { ...filter }); + const response = await axios.get(url, { params: filter, + paramsSerializer: { + dots: true + } + }); return response.data; } diff --git a/src/routes/page/agent/+page.svelte b/src/routes/page/agent/+page.svelte index 94bbe007..cee3fd9d 100644 --- a/src/routes/page/agent/+page.svelte +++ b/src/routes/page/agent/+page.svelte @@ -3,34 +3,34 @@ import Breadcrumb from '$lib/common/Breadcrumb.svelte'; import HeadTitle from '$lib/common/HeadTitle.svelte'; import CardAgent from './card-agent.svelte'; - import { getAgents } from '$lib/services/agent-service.js'; - import { onMount } from 'svelte'; + import { getAgents } from '$lib/services/agent-service.js'; + import { onMount } from 'svelte'; import PlainPagination from '$lib/common/PlainPagination.svelte'; - const firstPage = 1; + const firstPage = 1; const pageSize = 12; /** @type {import('$types').PagedItems} */ - let agents = { items: [], count: 0 }; + let agents = { items: [], count: 0 }; /** @type {import('$types').AgentFilter} */ const initFilter = { pager: { page: firstPage, size: pageSize, count: 0 }, - isEvaluator: false + isEvaluator: false }; - /** @type {import('$types').AgentFilter} */ - let filter = { ... initFilter }; + /** @type {import('$types').AgentFilter} */ + let filter = { ... initFilter }; /** @type {import('$types').Pagination} */ let pager = filter.pager; - onMount(async () => { - await getPagedAgents(); - }); + onMount(async () => { + await getPagedAgents(); + }); - async function getPagedAgents() { - agents = await getAgents(filter); + async function getPagedAgents() { + agents = await getAgents(filter); refresh(); } diff --git a/src/routes/page/agent/router/+page.svelte b/src/routes/page/agent/router/+page.svelte index 02c086ec..78ce53f0 100644 --- a/src/routes/page/agent/router/+page.svelte +++ b/src/routes/page/agent/router/+page.svelte @@ -13,13 +13,23 @@ let isRouterNodeSelected = false; let isAgentNodeSelected = false; + /** @type {import('$types').AgentFilter} */ + const filter = { + pager: { page: 1, size: 10, count: 0 }, + isRouter: true + }; + onMount(async () => { - let list = await getAgents({ - isRouter: true - }); - router = list[0]; + await getRouter(); }); + async function getRouter() { + const response = await getAgents(filter); + if (response.items?.length > 0) { + router = response.items[0]; + } + }; + function handleUserNodeSelected() { isRouterNodeSelected = false; isAgentNodeSelected = false; diff --git a/src/routes/page/agent/router/routing-flow.svelte b/src/routes/page/agent/router/routing-flow.svelte index 6c2ba53e..77580f56 100644 --- a/src/routes/page/agent/router/routing-flow.svelte +++ b/src/routes/page/agent/router/routing-flow.svelte @@ -5,35 +5,41 @@ import { getAgents } from '$lib/services/agent-service.js'; import { onMount, createEventDispatcher } from 'svelte'; - /** @type {import('$types').AgentModel[]} */ + /** @type any[]} */ let agents = []; + /** @type {import('$types').AgentFilter} */ + const filter = { + pager: { page: 1, size: 20, count: 0 }, + isRouter: false, + isEvaluator: false, + disabled: false, + allowRouting: false + }; + /** @type {import('$types').AgentModel} */ export let router; + const dispatch = createEventDispatcher(); onMount(async () => { - agents = await getAgents({ - isRouter: false, - isEvaluator: false, - disabled: false, - allowRouting: true - }); + const response = await getAgents(filter); + agents = response?.items || []; // add a "New Agent" button agents.push({ - name: "New Agent", - allowRouting: true - }); + name: "New Agent", + allow_routing: true + }); const container = document.getElementById("drawflow"); - const editor = new Drawflow(container); - editor.reroute = true; - editor.reroute_fix_curvature = true; - - editor.start(); - - renderRoutingFlow(editor); + if (!!container) { + const editor = new Drawflow(container); + editor.reroute = true; + editor.reroute_fix_curvature = true; + editor.start(); + renderRoutingFlow(editor); + } }); /** @param {Drawflow} editor*/