-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathAIAgentPage.tsx
More file actions
137 lines (128 loc) · 3.32 KB
/
Copy pathAIAgentPage.tsx
File metadata and controls
137 lines (128 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import Flex from '../components/Flex';
import { FluentEmojiIcon } from '../components/FluentEmojiIcon';
import { useWebUINavigate } from '../hooks';
import { AIAgent, useAIAgent } from '../hooks/useAIAgent';
import { Card, List, Skeleton, Tag, theme } from 'antd';
import { createStyles } from 'antd-style';
import React, { Suspense } from 'react';
const useStyles = createStyles(({ css, token }) => {
return {
cardList: css`
.and-col {
height: calc(100% - ${token.marginMD});
}
.ant-tag {
margin-inline-end: 0;
}
`,
meta: css`
.ant-card-meta-description {
max-height: 6.4em; // Adjusted for 4 lines
overflow: hidden;
text-overflow: ellipsis;
}
.ant-card-meta-title {
white-space: normal;
}
`,
};
});
const { Meta } = Card;
const AIAgentCard = ({ agent }: { agent: AIAgent }) => {
const tags = agent.meta.tags || [];
const { styles } = useStyles();
const avatar =
agent.type === 'external' ? (
<img
src={agent.meta.avatar}
alt={agent.meta.title}
height={150}
width={150}
style={{ borderRadius: '50%' }}
/>
) : (
<FluentEmojiIcon name={agent.meta.avatar} height={150} width={150} />
);
return (
<Card hoverable>
<Flex
direction="column"
align="stretch"
gap="xs"
justify="between"
style={{ minHeight: '200px' }}
>
<Meta
title={agent.meta.title}
avatar={avatar}
description={agent.meta.descriptions}
className={styles.meta}
/>
<Flex
direction="row"
justify="start"
style={{ width: '100%', flexShrink: 1 }}
gap={6}
wrap="wrap"
>
<Tag key={agent.endpoint} color={'orange-inverse'}>
{agent.endpoint}
</Tag>
{tags.map((tag, index) => (
<Tag key={index}>{tag}</Tag>
))}
</Flex>
</Flex>
</Card>
);
};
const AIAgentCardList = ({
agents,
onClickAgent,
}: {
agents: AIAgent[];
onClickAgent: (agent: AIAgent) => void;
}) => {
const { styles } = useStyles();
return (
<List
className={styles.cardList}
grid={{ gutter: 16, xs: 1, sm: 1, md: 2, lg: 2, xl: 3, xxl: 4 }}
dataSource={agents}
renderItem={(agent) => (
<List.Item
style={{ height: '100%' }}
onClick={() => onClickAgent(agent)}
>
<AIAgentCard agent={agent} />
</List.Item>
)}
></List>
);
};
const AIAgentPage: React.FC = () => {
const { token } = theme.useToken();
const { agents } = useAIAgent();
const webuiNavigate = useWebUINavigate();
return (
<Suspense
fallback={<Skeleton active style={{ padding: token.paddingMD }} />}
>
<Flex direction="column" align="stretch" justify="center" gap="lg">
<AIAgentCardList
agents={agents}
onClickAgent={(agent) => {
if (agent.type === 'external') {
webuiNavigate(`/ai-agent/external?url=${agent.config.url}`);
} else {
webuiNavigate(
`/chat?endpointId=${agent.endpoint_id}&agentId=${agent.id}`,
);
}
}}
/>
</Flex>
</Suspense>
);
};
export default AIAgentPage;