Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project summary #220

Merged
merged 7 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
17 changes: 13 additions & 4 deletions src/__fixtures__/chat_links_response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ export const STUB_LINKS_FOR_CHAT_RESPONSE: LinksForChatResponse = {
text: "Save and return",
action: "patch-all",
goto: "SETTINGS:/path/to/config/file.yaml",
link_tooltip: "",
},
{
text: "Can you fix it?",
action: "follow-up",
link_tooltip: "a nice tool tip message",
},
{ text: 'git commit -m "message"', action: "commit", link_tooltip: "" },
{ text: "Save and return", goto: "SETTINGS:postgres", link_tooltip: "" },
{
text: "Investigate Project",
action: "summarize-project",
link_tooltip: "",
},
{ text: "Can you fix it?", action: "follow-up" },
{ text: 'git commit -m "message"', action: "commit" },
{ text: "Save and return", goto: "SETTINGS:postgres" },
{ text: "Investigate Project", action: "summarize-project" },
],
};
39 changes: 1 addition & 38 deletions src/components/ChatContent/ChatContent.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { useCallback, useRef, useMemo } from "react";
import React, { useCallback, useRef } from "react";
import {
ChatMessages,
diffApi,
isAssistantMessage,
isChatContextFileMessage,
isDiffMessage,
isToolMessage,
Expand Down Expand Up @@ -122,20 +120,6 @@ export const ChatContent: React.FC<ChatContentProps> = ({
const thread = useAppSelector(selectThread);
const isConfig = !!thread.integration;
const isWaiting = useAppSelector(selectIsWaiting);
const [applyAll, applyAllResult] =
diffApi.useApplyAllPatchesInMessagesMutation();

const hasPins = useMemo(
() =>
messages.some((message) => {
if (!isAssistantMessage(message)) return false;
if (!message.content) return false;
return message.content
.split("\n")
.some((line) => line.startsWith("📍"));
}),
[messages],
);

const {
handleScroll,
Expand Down Expand Up @@ -170,13 +154,6 @@ export const ChatContent: React.FC<ChatContentProps> = ({
thread.integration?.path,
]);

const handleSaveAndReturn = useCallback(async () => {
const result = await applyAll(messages);
if (!result.error) {
handleReturnToConfigurationClick();
}
}, [applyAll, handleReturnToConfigurationClick, messages]);

return (
<ScrollArea
ref={scrollRef}
Expand Down Expand Up @@ -221,20 +198,6 @@ export const ChatContent: React.FC<ChatContentProps> = ({
Return
</Button>
)}

{isConfig && hasPins && (
<Button
ml="auto"
color="green"
title="Save and return"
disabled={isStreaming || applyAllResult.isLoading}
onClick={() => {
void handleSaveAndReturn();
}}
>
Save
</Button>
)}
</Flex>
</ScrollArea>
);
Expand Down
52 changes: 36 additions & 16 deletions src/components/ChatLinks/ChatLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
setIntegrationData,
} from "../../features/Chat";
import { popBackTo } from "../../features/Pages/pagesSlice";
import { Spinner } from "@radix-ui/themes";

function maybeConcatActionAndGoToStrings(link: ChatLink): string | undefined {
const hasAction = "action" in link;
Expand Down Expand Up @@ -176,32 +177,51 @@ export const ChatLinks: React.FC = () => {

// TODO: waiting, errors, maybe add a title

if (!linksResult.data || isStreaming || isWaiting || unCalledTools) {
if (isStreaming || isWaiting || unCalledTools) {
return null;
}

const Wrapper = messages.length === 0 ? Box : Container;
return (
<Wrapper position="relative" mt="6">
<Heading as="h4" size="2" mb="2">
Available Actions:{" "}
</Heading>

<Flex gap="2" wrap="wrap" direction="column" align="start">
{linksResult.data.links.map((link, index) => {
const key = `chat-link-${index}`;
return <ChatLinkButton key={key} link={link} onClick={handleClick} />;
})}
</Flex>
</Wrapper>
);

if (linksResult.isLoading) {
return (
<Wrapper position="relative" mt="6">
<Heading as="h4" size="2" mb="2">
<Button variant="surface" disabled>
<Spinner loading />
Checking for actions
</Button>
</Heading>
</Wrapper>
);
}

if (linksResult.data && linksResult.data.links.length > 0)
return (
<Wrapper position="relative" mt="6">
<Heading as="h4" size="2" mb="2">
Available Actions:{" "}
</Heading>

<Flex gap="2" wrap="wrap" direction="column" align="start">
{linksResult.data.links.map((link, index) => {
const key = `chat-link-${index}`;
return (
<ChatLinkButton key={key} link={link} onClick={handleClick} />
);
})}
</Flex>
</Wrapper>
);

return null;
};

const ChatLinkButton: React.FC<{
link: ChatLink;
onClick: (link: ChatLink) => void;
}> = ({ link, onClick }) => {
const title = maybeConcatActionAndGoToStrings(link);
const title = link.link_tooltip || maybeConcatActionAndGoToStrings(link);
const handleClick = React.useCallback(() => onClick(link), [link, onClick]);

return (
Expand Down
19 changes: 14 additions & 5 deletions src/services/refact/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ import { CHAT_LINKS_URL } from "./consts";

// goto: can be an integration file to open in settings, a file to open in an idea or a global integration.
export type ChatLink =
| { text: string; goto: string; action: string }
| { text: string; goto: string /* action: undefined */ }
| { text: string; /* goto: undefined; */ action: string }
| { text: string; goto: string; action: "go-to" }
| { text: string; action: "summarize-project"; current_config_file?: string };
| { text: string; goto: string; action: string; link_tooltip: string }
| { text: string; goto: string; link_tooltip: string /* action: undefined */ }
| {
text: string;
/* goto: undefined; */ action: string;
link_tooltip: string;
}
| { text: string; goto: string; action: "go-to"; link_tooltip: string }
| {
text: string;
action: "summarize-project";
current_config_file?: string;
link_tooltip: string;
};

function isChatLink(json: unknown): json is ChatLink {
if (!json || typeof json !== "object") return false;
Expand Down
Loading