Skip to content

Commit 988664d

Browse files
committed
Style fixes
1 parent 07e842a commit 988664d

File tree

8 files changed

+291
-178
lines changed

8 files changed

+291
-178
lines changed

app/products/agents/actions/remote/bots.ts

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,9 @@ import NetworkManager from '@managers/network_manager';
55
import {getFullErrorMessage} from '@utils/errors';
66
import {logError} from '@utils/log';
77

8-
export enum ChannelAccessLevel {
9-
All = 0,
10-
Allow = 1,
11-
Block = 2,
12-
}
13-
14-
export enum UserAccessLevel {
15-
All = 0,
16-
Allow = 1,
17-
Block = 2,
18-
}
8+
import type {LLMBot} from '@agents/types';
199

20-
export interface LLMBot {
21-
id: string;
22-
displayName: string;
23-
username: string;
24-
lastIconUpdate: number;
25-
dmChannelID: string;
26-
channelAccessLevel: ChannelAccessLevel;
27-
channelIDs: string[];
28-
userAccessLevel: UserAccessLevel;
29-
userIDs: string[];
30-
teamIDs: string[];
31-
}
32-
33-
interface AIBotsResponse {
34-
bots: LLMBot[];
35-
searchEnabled: boolean;
36-
allowUnsafeLinks: boolean;
37-
}
10+
export type {LLMBot};
3811

3912
/**
4013
* Fetch all AI bots from the server
@@ -46,17 +19,15 @@ export async function fetchAIBots(
4619
): Promise<{bots?: LLMBot[]; searchEnabled?: boolean; allowUnsafeLinks?: boolean; error?: unknown}> {
4720
try {
4821
const client = NetworkManager.getClient(serverUrl);
49-
const url = '/plugins/mattermost-ai/ai_bots';
50-
51-
const response = await client.doFetch(url, {method: 'GET'}) as unknown as AIBotsResponse;
22+
const response = await client.getAIBots();
5223

5324
return {
5425
bots: response.bots,
5526
searchEnabled: response.searchEnabled,
5627
allowUnsafeLinks: response.allowUnsafeLinks,
5728
};
5829
} catch (error) {
59-
logError('Failed to fetch AI bots', error);
30+
logError('[fetchAIBots] Failed to fetch AI bots', error);
6031
return {error: getFullErrorMessage(error)};
6132
}
6233
}
@@ -81,7 +52,7 @@ export async function getBotDirectChannel(
8152

8253
return {channelId: channel.id};
8354
} catch (error) {
84-
logError('Failed to get bot direct channel', error);
55+
logError('[getBotDirectChannel] Failed to get bot direct channel', error);
8556
return {error: getFullErrorMessage(error)};
8657
}
8758
}

app/products/agents/actions/remote/threads.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ export async function fetchAIThreads(
1717
): Promise<{threads?: AIThread[]; error?: unknown}> {
1818
try {
1919
const client = NetworkManager.getClient(serverUrl);
20-
const url = '/plugins/mattermost-ai/ai_threads';
20+
const threads = await client.getAIThreads();
2121

22-
const response = await client.doFetch(url, {method: 'GET'}) as unknown as AIThread[];
23-
24-
return {threads: response};
22+
return {threads};
2523
} catch (error) {
26-
logError('Failed to fetch AI threads', error);
24+
logError('[fetchAIThreads] Failed to fetch AI threads', error);
2725
return {error: getFullErrorMessage(error)};
2826
}
2927
}

app/products/agents/client/rest.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
22
// See LICENSE.txt for license information.
33

4+
import type {AIBotsResponse, AIThread} from '@agents/types';
5+
46
export interface ClientAgentsMix {
57
getAgentsRoute: () => string;
8+
getAIBots: () => Promise<AIBotsResponse>;
9+
getAIThreads: () => Promise<AIThread[]>;
610
stopGeneration: (postId: string) => Promise<void>;
711
regenerateResponse: (postId: string) => Promise<void>;
812
submitToolApproval: (postId: string, acceptedToolIds: string[]) => Promise<void>;
@@ -13,6 +17,20 @@ const ClientAgents = (superclass: any) => class extends superclass {
1317
return '/plugins/mattermost-ai';
1418
};
1519

20+
getAIBots = async () => {
21+
return this.doFetch(
22+
`${this.getAgentsRoute()}/ai_bots`,
23+
{method: 'get'},
24+
);
25+
};
26+
27+
getAIThreads = async () => {
28+
return this.doFetch(
29+
`${this.getAgentsRoute()}/ai_threads`,
30+
{method: 'get'},
31+
);
32+
};
33+
1634
stopGeneration = async (postId: string) => {
1735
return this.doFetch(
1836
`${this.getAgentsRoute()}/post/${postId}/stop`,

app/products/agents/screens/agent_chat/agent_chat.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33

44
import {fetchAIBots, getBotDirectChannel, type LLMBot} from '@agents/actions/remote/bots';
55
import {AgentsIntro} from '@agents/components/illustrations';
6+
import BotSelectorItem from '@agents/screens/agent_chat/bot_selector_item';
67
import {goToAgentThreadsList} from '@agents/screens/navigation';
78
import React, {useCallback, useEffect, useState} from 'react';
89
import {useIntl} from 'react-intl';
9-
import {type LayoutChangeEvent, View, Text, TouchableOpacity, ActivityIndicator} from 'react-native';
10+
import {type LayoutChangeEvent, View, Text, TouchableOpacity} from 'react-native';
1011
import {useSafeAreaInsets} from 'react-native-safe-area-context';
1112

1213
import {buildAbsoluteUrl} from '@actions/remote/file';
1314
import {fetchAndSwitchToThread} from '@actions/remote/thread';
1415
import {buildProfileImageUrl} from '@actions/remote/user';
1516
import CompassIcon from '@components/compass_icon';
17+
import Loading from '@components/loading';
1618
import PostDraft from '@components/post_draft';
17-
import SlideUpPanelItem, {ITEM_HEIGHT} from '@components/slide_up_panel_item';
19+
import {ITEM_HEIGHT} from '@components/slide_up_panel_item';
1820
import {Screens} from '@constants';
1921
import {ExtraKeyboardProvider} from '@context/extra_keyboard';
2022
import {useServerUrl} from '@context/server';
@@ -231,15 +233,13 @@ const AgentChat = ({
231233
);
232234

233235
return (
234-
<SlideUpPanelItem
236+
<BotSelectorItem
235237
key={bot.id}
236-
leftIcon={{uri: avatarUrl}}
237-
leftImageStyles={{borderRadius: 12}}
238-
onPress={() => handleBotSelect(bot)}
239-
testID={`agent_chat.bot_selector.bot_item.${bot.id}`}
240-
text={bot.displayName}
241-
rightIcon={selectedBot?.id === bot.id ? 'check' : undefined}
242-
rightIconStyles={{color: theme.linkColor}}
238+
bot={bot}
239+
avatarUrl={avatarUrl}
240+
isSelected={selectedBot?.id === bot.id}
241+
onSelect={handleBotSelect}
242+
theme={theme}
243243
/>
244244
);
245245
})}
@@ -271,12 +271,11 @@ const AgentChat = ({
271271
if (loading) {
272272
return (
273273
<View style={[styles.container, {paddingTop: insets.top}]}>
274-
<View style={styles.loadingContainer}>
275-
<ActivityIndicator
276-
size='large'
277-
color={theme.buttonBg}
278-
/>
279-
</View>
274+
<Loading
275+
containerStyle={styles.loadingContainer}
276+
size='large'
277+
color={theme.buttonBg}
278+
/>
280279
</View>
281280
);
282281
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
2+
// See LICENSE.txt for license information.
3+
4+
import React, {useCallback} from 'react';
5+
6+
import SlideUpPanelItem from '@components/slide_up_panel_item';
7+
8+
import type {LLMBot} from '@agents/types';
9+
10+
type Props = {
11+
bot: LLMBot;
12+
avatarUrl?: string;
13+
isSelected: boolean;
14+
onSelect: (bot: LLMBot) => void;
15+
theme: Theme;
16+
};
17+
18+
const BotSelectorItem = ({bot, avatarUrl, isSelected, onSelect, theme}: Props) => {
19+
const handlePress = useCallback(() => {
20+
onSelect(bot);
21+
}, [bot, onSelect]);
22+
23+
return (
24+
<SlideUpPanelItem
25+
leftIcon={avatarUrl ? {uri: avatarUrl} : 'account-outline'}
26+
leftImageStyles={{borderRadius: 12}}
27+
onPress={handlePress}
28+
testID={`agent_chat.bot_selector.bot_item.${bot.id}`}
29+
text={bot.displayName}
30+
rightIcon={isSelected ? 'check' : undefined}
31+
rightIconStyles={{color: theme.linkColor}}
32+
/>
33+
);
34+
};
35+
36+
export default BotSelectorItem;

0 commit comments

Comments
 (0)