| 1 | <template> |
| 2 | <div class="active-response-list"> |
| 3 | <n-spin :show="loadingActiveResponse"> |
| 4 | <div class="min-h-52"> |
| 5 | <template v-if="activeResponseList.length"> |
| 6 | <ActiveResponseItem |
| 7 | v-for="activeResponse of activeResponseList" |
| 8 | :key="activeResponse.name" |
| 9 | :active-response |
| 10 | :embedded |
| 11 | :agent-id="agent.agent_id" |
| 12 | class="item-appear item-appear-bottom item-appear-005 mb-2" |
| 13 | /> |
| 14 | </template> |
| 15 | <template v-else> |
| 16 | <n-empty v-if="!loadingActiveResponse" description="No items found" class="h-48 justify-center" /> |
| 17 | </template> |
| 18 | </div> |
| 19 | </n-spin> |
| 20 | </div> |
| 21 | </template> |
| 22 | |
| 23 | <script setup lang="ts"> |
| 24 | import type { SupportedActiveResponse } from "@/types/activeResponse.d" |
| 25 | import type { Agent } from "@/types/agents.d" |
| 26 | import { NEmpty, NSpin, useMessage } from "naive-ui" |
| 27 | import { onBeforeMount, ref } from "vue" |
| 28 | import Api from "@/api" |
| 29 | import ActiveResponseItem from "./ActiveResponseItem.vue" |
| 30 | |
| 31 | const { embedded, agent } = defineProps<{ |
| 32 | embedded?: boolean |
| 33 | agent: Agent |
| 34 | }>() |
| 35 | |
| 36 | const message = useMessage() |
| 37 | const loadingActiveResponse = ref(false) |
| 38 | const activeResponseList = ref<SupportedActiveResponse[]>([]) |
| 39 | |
| 40 | function getAvailableIntegrations() { |
| 41 | loadingActiveResponse.value = true |
| 42 | |
| 43 | Api.activeResponse |
| 44 | .getSupported(agent.agent_id) |
| 45 | .then(res => { |
| 46 | if (res.data.success) { |
| 47 | activeResponseList.value = res.data?.supported_active_responses || [] |
| 48 | } else { |
| 49 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 50 | } |
| 51 | // MOCK |
| 52 | /* |
| 53 | activeResponseList.value = supported_active_response |
| 54 | */ |
| 55 | }) |
| 56 | .catch(err => { |
| 57 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 58 | }) |
| 59 | .finally(() => { |
| 60 | loadingActiveResponse.value = false |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | onBeforeMount(() => { |
| 65 | getAvailableIntegrations() |
| 66 | }) |
| 67 | </script> |