| 1 | <template> |
| 2 | <div class="active-response-actions flex justify-end gap-2"> |
| 3 | <n-button type="success" secondary :size :loading="loadingInvoke" @click="showInvokeForm = true"> |
| 4 | <template #icon> |
| 5 | <Icon :name="InvokeIcon" /> |
| 6 | </template> |
| 7 | Invoke Action |
| 8 | </n-button> |
| 9 | |
| 10 | <n-modal |
| 11 | v-model:show="showInvokeForm" |
| 12 | display-directive="show" |
| 13 | preset="card" |
| 14 | :style="{ maxWidth: 'min(600px, 90vw)', minHeight: 'min(300px, 90vh)', overflow: 'hidden' }" |
| 15 | :title="activeResponse.name" |
| 16 | :bordered="false" |
| 17 | content-class="flex flex-col" |
| 18 | segmented |
| 19 | > |
| 20 | <ActiveResponseInvokeForm |
| 21 | :active-response |
| 22 | :agent-id |
| 23 | @mounted="activeResponseInvokeFormCTX = $event" |
| 24 | @submitted="close()" |
| 25 | @start-loading="loadingInvoke = true" |
| 26 | @stop-loading="loadingInvoke = false" |
| 27 | > |
| 28 | <template #additionalActions> |
| 29 | <n-button secondary @click="close()">Close</n-button> |
| 30 | </template> |
| 31 | </ActiveResponseInvokeForm> |
| 32 | </n-modal> |
| 33 | </div> |
| 34 | </template> |
| 35 | |
| 36 | <script setup lang="ts"> |
| 37 | import type { ButtonSize } from "naive-ui" |
| 38 | import type { SupportedActiveResponse } from "@/types/activeResponse.d" |
| 39 | import { NButton, NModal } from "naive-ui" |
| 40 | import { computed, ref, watch } from "vue" |
| 41 | import Icon from "@/components/common/Icon.vue" |
| 42 | import ActiveResponseInvokeForm from "./ActiveResponseInvokeForm.vue" |
| 43 | |
| 44 | const { activeResponse, size, agentId } = defineProps<{ |
| 45 | activeResponse: SupportedActiveResponse |
| 46 | agentId?: string | number |
| 47 | size?: ButtonSize |
| 48 | }>() |
| 49 | |
| 50 | const emit = defineEmits<{ |
| 51 | (e: "startLoading"): void |
| 52 | (e: "stopLoading"): void |
| 53 | }>() |
| 54 | |
| 55 | const InvokeIcon = "solar:playback-speed-outline" |
| 56 | const showInvokeForm = ref(false) |
| 57 | const loadingInvoke = ref(false) |
| 58 | const loading = computed(() => loadingInvoke.value) |
| 59 | const activeResponseInvokeFormCTX = ref<{ reset: () => void } | null>(null) |
| 60 | |
| 61 | watch(loading, val => { |
| 62 | if (val) { |
| 63 | emit("startLoading") |
| 64 | } else { |
| 65 | emit("stopLoading") |
| 66 | } |
| 67 | }) |
| 68 | |
| 69 | function close() { |
| 70 | activeResponseInvokeFormCTX.value?.reset() |
| 71 | showInvokeForm.value = false |
| 72 | } |
| 73 | </script> |