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

fix(chat links): handle go to actions. #222

Merged
merged 1 commit into from
Dec 9, 2024
Merged
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
62 changes: 38 additions & 24 deletions src/components/ChatLinks/ChatLinks.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from "react";
import { Flex, Button, Heading, Container, Box } from "@radix-ui/themes";
import { Flex, Button, Container, Box } from "@radix-ui/themes";
import { linksApi, type ChatLink } from "../../services/refact/links";
import { diffApi, isUserMessage } from "../../services/refact";
import {
Expand All @@ -20,6 +20,7 @@ import {
setIntegrationData,
} from "../../features/Chat";
import { popBackTo } from "../../features/Pages/pagesSlice";
import { TruncateRight } from "../Text/TruncateRight";

function maybeConcatActionAndGoToStrings(link: ChatLink): string | undefined {
const hasAction = "action" in link;
Expand Down Expand Up @@ -82,8 +83,12 @@ export const ChatLinks: React.FC = () => {
popBackTo({
name: "integrations page",
// projectPath: isFile ? payload : "",
integrationName: !isFile ? payload : "",
integrationPath: isFile ? payload : "",
integrationName:
!isFile && payload !== "DEFAULT"
? payload
: maybeIntegration?.name,
integrationPath: isFile ? payload : maybeIntegration?.path,
projectPath: maybeIntegration?.project,
}),
);
// TODO: open in the integrations
Expand All @@ -99,8 +104,17 @@ export const ChatLinks: React.FC = () => {
const handleLinkAction = (link: ChatLink) => {
if (!("action" in link)) return;

if (link.action === "goto" && "goto" in link) {
handleGoTo(link.goto);
return;
}

if (link.action === "patch-all") {
void applyPatches(messages);
void applyPatches(messages).then(() => {
if ("goto" in link) {
handleGoTo(link.goto);
}
});
return;
}

Expand All @@ -118,26 +132,22 @@ export const ChatLinks: React.FC = () => {
return;
}

if (link.action === "commit") {
// TODO: there should be an endpoint for this
void applyPatches(messages).then(() => {
if ("goto" in link && link.goto) {
handleGoTo(link.goto);
}
});
// if (link.action === "commit") {
// // TODO: there should be an endpoint for this
// void applyPatches(messages).then(() => {
// if ("goto" in link && link.goto) {
// handleGoTo(link.goto);
// }
// });

return;
}
// return;
// }

// eslint-disable-next-line no-console
console.warn(`unknown action: ${JSON.stringify(link)}`);
};
const handleClick = (link: ChatLink) => {
if (!("action" in link) && "goto" in link) {
handleGoTo(link.goto);
} else {
handleLinkAction(link);
}
handleLinkAction(link);
};

const [linksRequest, linksResult] = linksApi.useGetLinksForChatMutation();
Expand Down Expand Up @@ -176,17 +186,19 @@ export const ChatLinks: React.FC = () => {

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

if (!linksResult.data || isStreaming || isWaiting || unCalledTools) {
if (
!linksResult.data ||
isStreaming ||
isWaiting ||
unCalledTools ||
linksResult.data.links.length === 0
) {
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}`;
Expand All @@ -211,11 +223,13 @@ const ChatLinkButton: React.FC<{
// variant="outline"
// variant="soft"
// variant="ghost"

variant="surface"
title={title}
onClick={handleClick}
style={{ maxWidth: "100%" }}
>
{link.text}
<TruncateRight>{link.text}</TruncateRight>
</Button>
);
};
Loading