Skip to content

Commit b07e31c

Browse files
committed
feat(agent): Card to see data
1 parent e2f1f06 commit b07e31c

File tree

3 files changed

+101
-22
lines changed

3 files changed

+101
-22
lines changed

public/assets/agent.png

29 KB
Loading

src/components/card/AgentCard.vue

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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>

src/pages/Agents.vue

+2-22
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,19 @@
2828

2929
<div v-else class="tw-mt-5 tw-space-y-4">
3030
<div v-for="agent of agentStore.agents" :key="agent.id">
31-
<p>Agent {{ agent.id }}</p>
32-
<a v-if="agent.vm_hash" :href="`https://aleph.sh/vm/${agent.vm_hash}`"
33-
>https://aleph.sh/vm/{{ agent.vm_hash }}</a
34-
>
35-
<p v-else>Not yet deployed</p>
36-
<p>Last update: {{ dayjs().to(dayjs.unix(agent.last_update)) }}</p>
37-
<p v-if="agent.secret">Secret: {{ agent.secret }}</p>
38-
<q-btn no-caps rounded @click="getAgentSecret(agent.id)">Get secret</q-btn>
31+
<AgentCard :agent="agent" />
3932
</div>
4033
</div>
4134
</section>
4235
</authenticated-page>
4336
</template>
4437

4538
<script lang="ts" setup>
39+
import AgentCard from 'components/card/AgentCard.vue';
4640
import EmptyState from 'components/EmptyState.vue';
4741
import LtaiIcon from 'components/libertai/LtaiIcon.vue';
48-
import dayjs from 'dayjs';
4942
import AuthenticatedPage from 'layouts/AuthenticatedPage.vue';
50-
import { useQuasar } from 'quasar';
5143
import { useAgentStore } from 'stores/agent';
5244
53-
const $q = useQuasar();
5445
const agentStore = useAgentStore();
55-
56-
const getAgentSecret = async (agentId: string) => {
57-
try {
58-
await agentStore.getAgentSecret(agentId);
59-
} catch (error) {
60-
$q.notify({
61-
message: (error as Error)?.message ?? 'Unable to get the agent secret',
62-
color: 'negative',
63-
});
64-
}
65-
};
6646
</script>

0 commit comments

Comments
 (0)