Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions site/src/pages/AgentsPage/AgentChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import {
} from "./AgentChatPageView";
import type { AgentsOutletContext } from "./AgentsPage";
import type { ChatMessageInputRef } from "./components/AgentChatInput";
import { AgentSetupNotice } from "./components/AgentSetupNotice";
import { getAgentSetupNoticeConfig } from "./components/AgentSetupNoticeBanner";
import { normalizeChatErrorPayload } from "./components/ChatConversation/chatError";
import {
getParentChatID,
Expand Down Expand Up @@ -1129,31 +1129,11 @@ const AgentChatPage: FC = () => {
hasConfiguredModels,
hasUserFixableModelProviders,
});
const isAdmin = permissions.editDeploymentConfig;
const agentSetupNotice = (() => {
// Admin: show when providers or models are missing
if (
isAdmin &&
providerCount !== undefined &&
modelCount !== undefined &&
(providerCount === 0 || modelCount === 0)
) {
return (
<AgentSetupNotice
isAdmin
providerCount={providerCount}
modelCount={modelCount}
/>
);
}
// Member: show when no models are available
if (!isAdmin && modelCount !== undefined && modelCount === 0) {
return (
<AgentSetupNotice isAdmin={false} providerCount={0} modelCount={0} />
);
}
return undefined;
})();
const agentSetupNotice = getAgentSetupNoticeConfig({
canConfigureAgentSetup: permissions.editDeploymentConfig,
providerCount: providerCount ?? 0,
modelCount: modelCount ?? 0,
});
const isSubmissionPending =
isSendPending || isEditPending || isInterruptPending;
const isChatSettingsPending =
Expand Down
33 changes: 20 additions & 13 deletions site/src/pages/AgentsPage/AgentChatPageView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
AgentChatPageNotFoundView,
AgentChatPageView,
} from "./AgentChatPageView";
import { AgentSetupNotice } from "./components/AgentSetupNotice";
import {
createChatStore,
useChatSelector,
Expand Down Expand Up @@ -526,9 +525,11 @@ export const NoModelOptions: Story = {
export const MissingProviderAndModelSetup: Story = {
render: () => (
<StoryAgentChatPageView
agentSetupNotice={
<AgentSetupNotice isAdmin providerCount={0} modelCount={0} />
}
agentSetupNotice={{
canConfigureAgentSetup: true,
providerCount: 0,
modelCount: 0,
}}
hasModelOptions={false}
modelOptions={[]}
isInputDisabled
Expand Down Expand Up @@ -561,9 +562,11 @@ export const MissingProviderAndModelSetup: Story = {
export const MissingModelSetup: Story = {
render: () => (
<StoryAgentChatPageView
agentSetupNotice={
<AgentSetupNotice isAdmin providerCount={1} modelCount={0} />
}
agentSetupNotice={{
canConfigureAgentSetup: true,
providerCount: 1,
modelCount: 0,
}}
hasModelOptions={false}
modelOptions={[]}
isInputDisabled
Expand Down Expand Up @@ -592,9 +595,11 @@ export const MissingModelSetup: Story = {
export const MissingProviderSetup: Story = {
render: () => (
<StoryAgentChatPageView
agentSetupNotice={
<AgentSetupNotice isAdmin providerCount={0} modelCount={1} />
}
agentSetupNotice={{
canConfigureAgentSetup: true,
providerCount: 0,
modelCount: 1,
}}
/>
),
play: async ({ canvasElement }) => {
Expand All @@ -620,9 +625,11 @@ export const MissingProviderSetup: Story = {
export const MemberNoModelsAvailable: Story = {
render: () => (
<StoryAgentChatPageView
agentSetupNotice={
<AgentSetupNotice isAdmin={false} providerCount={0} modelCount={0} />
}
agentSetupNotice={{
canConfigureAgentSetup: false,
providerCount: 0,
modelCount: 0,
}}
hasModelOptions={false}
modelOptions={[]}
isInputDisabled
Expand Down
3 changes: 2 additions & 1 deletion site/src/pages/AgentsPage/AgentChatPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
AgentChatInput,
type ChatMessageInputRef,
} from "./components/AgentChatInput";
import type { AgentSetupNoticeConfig } from "./components/AgentSetupNoticeBanner";
import {
ChatConversationSkeleton,
RightPanelSkeleton,
Expand Down Expand Up @@ -116,7 +117,7 @@ interface AgentChatPageViewProps {
modelOptions: readonly ModelSelectorOption[];
modelSelectorPlaceholder: string;
modelSelectorHelp?: ReactNode;
agentSetupNotice?: ReactNode;
agentSetupNotice?: AgentSetupNoticeConfig;
hasModelOptions: boolean;
isModelCatalogLoading?: boolean;
planModeEnabled?: boolean;
Expand Down
30 changes: 6 additions & 24 deletions site/src/pages/AgentsPage/AgentCreatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
type CreateChatOptions,
} from "./components/AgentCreateForm";
import { AgentPageHeader } from "./components/AgentPageHeader";
import { AgentSetupNotice } from "./components/AgentSetupNotice";
import { getAgentSetupNoticeConfig } from "./components/AgentSetupNoticeBanner";
import { ChimeButton } from "./components/ChimeButton";
import { WebPushButton } from "./components/WebPushButton";
import { getAgentChatSendShortcut } from "./utils/agentChatSendShortcut";
Expand Down Expand Up @@ -72,29 +72,11 @@ const AgentCreatePage: FC = () => {
chatModelConfigsQuery.isSuccess && chatModelsQuery.isSuccess
? catalogModelOptions.length
: undefined;
const isAdmin = permissions.editDeploymentConfig;
const agentSetupNotice = (() => {
if (
isAdmin &&
providerCount !== undefined &&
modelCount !== undefined &&
(providerCount === 0 || modelCount === 0)
) {
return (
<AgentSetupNotice
isAdmin
providerCount={providerCount}
modelCount={modelCount}
/>
);
}
if (!isAdmin && modelCount !== undefined && modelCount === 0) {
return (
<AgentSetupNotice isAdmin={false} providerCount={0} modelCount={0} />
);
}
return undefined;
})();
const agentSetupNotice = getAgentSetupNoticeConfig({
canConfigureAgentSetup: permissions.editDeploymentConfig,
providerCount: providerCount ?? 0,
modelCount: modelCount ?? 0,
});

const handleCreateChat = async ({
message,
Expand Down
10 changes: 8 additions & 2 deletions site/src/pages/AgentsPage/components/AgentChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ import {
isChatAttachmentFile,
} from "../utils/chatAttachments";
import { formatProviderLabel } from "../utils/modelOptions";
import {
AgentSetupNoticeBanner,
type AgentSetupNoticeConfig,
} from "./AgentSetupNoticeBanner";
import {
AttachmentPreview,
isUploadInProgress,
Expand Down Expand Up @@ -183,7 +187,7 @@ interface AgentChatInputProps {
sshCommand?: string;
attachedWorkspace?: AttachedWorkspaceInfo;
folder?: string;
agentSetupNotice?: React.ReactNode;
agentSetupNotice?: AgentSetupNoticeConfig;
}

export interface AttachedWorkspaceInfo {
Expand Down Expand Up @@ -1045,7 +1049,9 @@ export const AgentChatInput: FC<AgentChatInputProps> = ({
/>
)}
{agentSetupNotice && (
<div className="relative z-0 mb-[-2.5rem]">{agentSetupNotice}</div>
<div className="relative z-0 mb-[-2.5rem]">
<AgentSetupNoticeBanner {...agentSetupNotice} />
</div>
)}
<div
ref={setComposerElement}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
} from "#/testHelpers/entities";
import { withDashboardProvider } from "#/testHelpers/storybook";
import { AgentCreateForm } from "./AgentCreateForm";
import { AgentSetupNotice } from "./AgentSetupNotice";

// Query key used by permittedOrganizations() in the form.
const permittedOrgsKey = [
Expand Down Expand Up @@ -471,9 +470,11 @@ export const NoModelsConfigured: Story = {
export const MissingProviderAndModelSetup: Story = {
args: {
...defaultArgs,
agentSetupNotice: (
<AgentSetupNotice isAdmin providerCount={0} modelCount={0} />
),
agentSetupNotice: {
canConfigureAgentSetup: true,
providerCount: 0,
modelCount: 0,
},
modelCatalog: { providers: [] },
modelOptions: [],
isModelCatalogLoading: false,
Expand Down
12 changes: 3 additions & 9 deletions site/src/pages/AgentsPage/components/AgentCreateForm.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
type FC,
type ReactNode,
useEffect,
useEffectEvent,
useRef,
useState,
} from "react";
import { type FC, useEffect, useEffectEvent, useRef, useState } from "react";
import { useQuery } from "react-query";
import { Link } from "react-router";
import { toast } from "sonner";
Expand All @@ -32,6 +25,7 @@ import {
isChatUsageLimitExceededResponse,
} from "../utils/usageLimitMessage";
import { AgentChatInput } from "./AgentChatInput";
import type { AgentSetupNoticeConfig } from "./AgentSetupNoticeBanner";
import { ChatAccessDeniedAlert } from "./ChatAccessDeniedAlert";
import type { ModelSelectorOption } from "./ChatElements";
import { CompactOrgSelector } from "./ChatElements";
Expand Down Expand Up @@ -132,7 +126,7 @@ interface AgentCreateFormProps {
canCreateChat: boolean;
modelCatalog: TypesGen.ChatModelsResponse | null | undefined;
modelOptions: readonly ChatModelOption[];
agentSetupNotice?: ReactNode;
agentSetupNotice?: AgentSetupNoticeConfig;
isModelCatalogLoading: boolean;
modelConfigs: readonly TypesGen.ChatModelConfig[];
isModelConfigsLoading: boolean;
Expand Down
55 changes: 55 additions & 0 deletions site/src/pages/AgentsPage/components/AgentSetupNoticeBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { AgentSetupNotice } from "./AgentSetupNotice";

export interface AgentSetupNoticeConfig {
canConfigureAgentSetup: boolean;
providerCount: number;
modelCount: number;
}

const shouldRenderAgentSetupNotice = ({
canConfigureAgentSetup,
providerCount,
modelCount,
}: AgentSetupNoticeConfig) => {
if (!canConfigureAgentSetup) {
return modelCount === 0;
}

return providerCount === 0 || modelCount === 0;
};

export const getAgentSetupNoticeConfig = (
config: AgentSetupNoticeConfig,
): AgentSetupNoticeConfig | undefined => {
return shouldRenderAgentSetupNotice(config) ? config : undefined;
};

export const AgentSetupNoticeBanner = ({
canConfigureAgentSetup,
providerCount,
modelCount,
}: AgentSetupNoticeConfig) => {
if (
!shouldRenderAgentSetupNotice({
canConfigureAgentSetup,
providerCount,
modelCount,
})
) {
return null;
}

if (!canConfigureAgentSetup) {
return (
<AgentSetupNotice isAdmin={false} providerCount={0} modelCount={0} />
);
}

return (
<AgentSetupNotice
isAdmin
providerCount={providerCount}
modelCount={modelCount}
/>
);
};
3 changes: 2 additions & 1 deletion site/src/pages/AgentsPage/components/ChatPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
isUploadInProgress,
type UploadState,
} from "./AgentChatInput";
import type { AgentSetupNoticeConfig } from "./AgentSetupNoticeBanner";
import { ConversationTimeline } from "./ChatConversation/ConversationTimeline";
import { getLatestContextUsage } from "./ChatConversation/chatHelpers";
import {
Expand Down Expand Up @@ -169,7 +170,7 @@ interface ChatPageInputProps {
modelOptions: readonly ModelSelectorOption[];
modelSelectorPlaceholder: string;
modelSelectorHelp?: ReactNode;
agentSetupNotice?: ReactNode;
agentSetupNotice?: AgentSetupNoticeConfig;
planModeEnabled?: boolean;
onPlanModeToggle?: (enabled: boolean) => void;
isModelCatalogLoading?: boolean;
Expand Down
Loading