|
| 1 | +<template> |
| 2 | + <q-card |
| 3 | + :class="[$q.dark.isActive ? ' tw-border-white/40' : ' tw-border-black/10']" |
| 4 | + class="tw-w-fit tw-shadow-none tw-rounded-2xl tw-border" |
| 5 | + > |
| 6 | + <q-card-section> |
| 7 | + <img alt="Agent" class="tw-mx-auto tw-w-44 tw-h-44" src="/assets/agent.png" /> |
| 8 | + </q-card-section> |
| 9 | + <q-card-section class="tw-font-bold tw-text-lg tw-py-0 tw-text-center">Agent</q-card-section> |
| 10 | + <q-card-section class="tw-space-y-2"> |
| 11 | + <q-input v-model="agentIdRef" borderless class="tw-min-w-[22.5rem]" label="Public ID" outlined readonly> |
| 12 | + <template #append> |
| 13 | + <q-icon class="tw-cursor-pointer" name="content_copy" @click="copyText(agent.id, 'Public ID')" /> |
| 14 | + </template> |
| 15 | + </q-input> |
| 16 | + <q-input |
| 17 | + v-if="agent.secret" |
| 18 | + :model-value="agent.secret" |
| 19 | + borderless |
| 20 | + class="tw-min-w-[22.5rem]" |
| 21 | + label="Secret key" |
| 22 | + outlined |
| 23 | + readonly |
| 24 | + > |
| 25 | + <template #append> |
| 26 | + <q-icon class="tw-cursor-pointer" name="content_copy" @click="copyText(agent.secret, 'Secret key')" /> |
| 27 | + </template> |
| 28 | + </q-input> |
| 29 | + |
| 30 | + <div class="tw-flex tw-justify-center"> |
| 31 | + <q-btn |
| 32 | + v-if="!agent.secret" |
| 33 | + :loading="isLoadingSecret" |
| 34 | + class="border-primary-highlight" |
| 35 | + no-caps |
| 36 | + rounded |
| 37 | + text-color="dark-mode-text" |
| 38 | + unelevated |
| 39 | + @click="getAgentSecret" |
| 40 | + > |
| 41 | + Show secret key |
| 42 | + </q-btn> |
| 43 | + </div> |
| 44 | + |
| 45 | + <div v-if="agent.vm_hash" class="tw-flex tw-justify-center"> |
| 46 | + <q-btn |
| 47 | + :href="`https://aleph.sh/vm/${agent.vm_hash}`" |
| 48 | + color="primary" |
| 49 | + label="Access the VM" |
| 50 | + no-caps |
| 51 | + outline |
| 52 | + target="_blank" |
| 53 | + unelevated |
| 54 | + /> |
| 55 | + </div> |
| 56 | + <p v-else>Not yet deployed</p> |
| 57 | + |
| 58 | + <p>Last updated {{ dayjs().to(dayjs.unix(agent.last_update)) }}</p> |
| 59 | + </q-card-section> |
| 60 | + </q-card> |
| 61 | +</template> |
| 62 | + |
| 63 | +<script lang="ts" setup> |
| 64 | +import dayjs from 'dayjs'; |
| 65 | +import { copyToClipboard, useQuasar } from 'quasar'; |
| 66 | +import { UIAgent } from 'src/types/agent'; |
| 67 | +import { useAgentStore } from 'stores/agent'; |
| 68 | +import { ref } from 'vue'; |
| 69 | +
|
| 70 | +const { agent } = defineProps<{ agent: UIAgent }>(); |
| 71 | +
|
| 72 | +const agentIdRef = ref(agent.id); |
| 73 | +const isLoadingSecret = ref(false); |
| 74 | +
|
| 75 | +const $q = useQuasar(); |
| 76 | +const agentStore = useAgentStore(); |
| 77 | +
|
| 78 | +const getAgentSecret = async () => { |
| 79 | + isLoadingSecret.value = true; |
| 80 | + try { |
| 81 | + await agentStore.getAgentSecret(agent.id); |
| 82 | + } catch (error) { |
| 83 | + $q.notify({ |
| 84 | + message: (error as Error)?.message ?? 'Unable to get the agent secret', |
| 85 | + color: 'negative', |
| 86 | + }); |
| 87 | + } finally { |
| 88 | + isLoadingSecret.value = false; |
| 89 | + } |
| 90 | +}; |
| 91 | +
|
| 92 | +const copyText = async (content: string, name: string) => { |
| 93 | + await copyToClipboard(content); |
| 94 | + $q.notify({ |
| 95 | + message: `${name} copied to clipboard`, |
| 96 | + color: 'positive', |
| 97 | + }); |
| 98 | +}; |
| 99 | +</script> |
0 commit comments