Skip to content

Commit

Permalink
Merge branch 'alpha' into add_integrations
Browse files Browse the repository at this point in the history
 Conflicts:
	src/components/IntegrationsView/IntegrationDocker/IntegrationDocker.tsx
	src/components/IntegrationsView/IntegrationForm/IntegrationForm.tsx
	src/components/IntegrationsView/IntegrationsView.tsx
	src/features/Integrations/renderIntegrationFormField.tsx
	src/services/refact/integrations.ts

 Changes to be committed:
	modified:   .gitignore
	modified:   package-lock.json
	modified:   package.json
	modified:   src/__fixtures__/chat_config_thread.ts
	modified:   src/__fixtures__/chat_links_response.ts
	modified:   src/__fixtures__/integrations.ts
	modified:   src/__fixtures__/msw.ts
	modified:   src/__tests__/PinMessages.test.tsx
	new file:   src/__tests__/isAbsolutePath.test.ts
	modified:   src/app/middleware.ts
	modified:   src/app/store.ts
	modified:   src/components/Buttons/Buttons.tsx
	modified:   src/components/Buttons/index.tsx
	modified:   src/components/Callout/Callout.module.css
	modified:   src/components/Callout/Callout.tsx
	modified:   src/components/Chat/Chat.stories.tsx
	modified:   src/components/Chat/Chat.tsx
	modified:   src/components/ChatContent/AssistantInput.tsx
	modified:   src/components/ChatContent/ChatContent.stories.tsx
	modified:   src/components/ChatContent/ChatContent.tsx
	modified:   src/components/ChatContent/ContextFiles.tsx
	modified:   src/components/ChatContent/PlaceHolderText.tsx
	modified:   src/components/ChatContent/useAutoScroll.ts
	modified:   src/components/ChatForm/ChatControls.tsx
	modified:   src/components/ChatForm/ChatForm.stories.tsx
	modified:   src/components/ChatForm/ChatForm.test.tsx
	modified:   src/components/ChatForm/ChatForm.tsx
	modified:   src/components/ChatForm/PromptSelect.tsx
	modified:   src/components/ChatForm/RetryForm.tsx
	modified:   src/components/ChatForm/ToolConfirmation.module.css
	modified:   src/components/ChatForm/ToolConfirmation.tsx
	modified:   src/components/ChatForm/ToolUseSwitch.tsx
	modified:   src/components/ChatForm/actions.ts
	modified:   src/components/ChatForm/useCheckBoxes.ts
	modified:   src/components/ChatForm/useInputValue.ts
	modified:   src/components/ChatForm/utils.ts
	modified:   src/components/ChatLinks/ChatLinks.module.css
	modified:   src/components/ChatLinks/ChatLinks.tsx
	new file:   src/components/ChatLinks/UncommittedChangesWarning.tsx
	modified:   src/components/ChatLinks/index.ts
	new file:   src/components/IntegrationsView/Confirmation/Confirmation.tsx
	new file:   src/components/IntegrationsView/Confirmation/index.ts
	modified:   src/components/IntegrationsView/IntegrationDeletePopover.tsx
	new file:   src/components/IntegrationsView/IntegrationDocker/IntegrationDocker.module.css
	modified:   src/components/IntegrationsView/IntegrationDocker/IntegrationDocker.tsx
	modified:   src/components/IntegrationsView/IntegrationForm/IntegrationAvailability.tsx
	modified:   src/components/IntegrationsView/IntegrationForm/IntegrationForm.module.css
	modified:   src/components/IntegrationsView/IntegrationForm/IntegrationForm.tsx
	modified:   src/components/IntegrationsView/IntegrationsHeader.module.css
	modified:   src/components/IntegrationsView/IntegrationsHeader.tsx
	new file:   src/components/IntegrationsView/IntegrationsTable/ConfirmationTable.module.css
	new file:   src/components/IntegrationsView/IntegrationsTable/ConfirmationTable.tsx
	new file:   src/components/IntegrationsView/IntegrationsTable/DefaultCell.tsx
	new file:   src/components/IntegrationsView/IntegrationsTable/ParametersTable.tsx
	modified:   src/components/IntegrationsView/IntegrationsView.tsx
	modified:   src/components/IntegrationsView/IntermediateIntegration/IntermediateIntegration.tsx
	modified:   src/components/Markdown/CodeBlock.tsx
	modified:   src/components/Markdown/Markdown.module.css
	modified:   src/components/Markdown/Markdown.tsx
	modified:   src/components/Select/Select.stories.tsx
	modified:   src/components/Select/Select.tsx
	modified:   src/components/SmartLink/SmartLink.tsx
	modified:   src/components/Toolbar/Dropdown.tsx
	modified:   src/components/Toolbar/Toolbar.tsx
	modified:   src/debugConfig.ts
	new file:   src/features/AgentUsage/AgentUsage.module.css
	new file:   src/features/AgentUsage/AgentUsage.stories.tsx
	new file:   src/features/AgentUsage/AgentUsage.tsx
	new file:   src/features/AgentUsage/agentUsageSlice.ts
	new file:   src/features/AgentUsage/index.ts
	modified:   src/features/Chat/Chat.test.tsx
	modified:   src/features/Chat/Chat.tsx
	modified:   src/features/Chat/Thread/actions.ts
	modified:   src/features/Chat/Thread/reducer.ts
	modified:   src/features/Chat/Thread/selectors.ts
	modified:   src/features/Chat/Thread/types.ts
	modified:   src/features/Chat/Thread/utils.ts
	modified:   src/features/Config/configSlice.ts
	modified:   src/features/History/historySlice.ts
	modified:   src/features/Integrations/Integrations.tsx
	new file:   src/features/Integrations/convertRawIntegrationFormValues.ts
	modified:   src/features/Integrations/renderIntegrationFormField.tsx
	modified:   src/features/Pages/pagesSlice.ts
	modified:   src/features/ToolConfirmation/confirmationSlice.ts
	modified:   src/hooks/index.ts
	new file:   src/hooks/useAgentUsage.ts
	modified:   src/hooks/useCanUseTools.ts
	new file:   src/hooks/useCapsForToolUse.ts
	modified:   src/hooks/useGetCapsQuery.ts
	modified:   src/hooks/useGoToLink.ts
	modified:   src/hooks/useLinksFromLsp.ts
	modified:   src/hooks/useSendChatRequest.ts
	modified:   src/hooks/useSmartLinks.ts
	modified:   src/services/refact/caps.ts
	modified:   src/services/refact/chat.ts
	modified:   src/services/refact/integrations.ts
	modified:   src/services/refact/links.ts
	modified:   src/services/refact/prompts.ts
	modified:   src/services/refact/tools.ts
	modified:   src/services/refact/types.ts
	new file:   src/utils/extractLinkFromPuzzle.ts
	modified:   src/utils/fencedBackticks.ts
	new file:   src/utils/validateSnakeCase.ts
	modified:   src/vite-env.d.ts
	modified:   vite.config.ts
  • Loading branch information
MarcMcIntosh committed Jan 14, 2025
2 parents 44a7240 + 5c1676a commit d35d901
Show file tree
Hide file tree
Showing 105 changed files with 3,019 additions and 1,301 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
_help

# Logs
logs
*.log
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "refact-chat-js",
"version": "2.0.3-alpha.5",
"version": "2.0.3-alpha.17",
"type": "module",
"license": "BSD-3-Clause",
"files": [
Expand Down
1 change: 1 addition & 0 deletions src/__fixtures__/chat_config_thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ export const CHAT_CONFIG_THREAD: Chat = {
error: null,
prevent_send: true,
waiting_for_response: false,
max_new_tokens: 4096,
cache: {},
system_prompt: {},
tool_use: "agent",
Expand Down
51 changes: 40 additions & 11 deletions src/__fixtures__/chat_links_response.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,64 @@
import { LinksForChatResponse } from "../services/refact/links";

export const STUB_LINKS_FOR_CHAT_RESPONSE: LinksForChatResponse = {
uncommited_changes_warning:
"You have uncommitted changes:\n```\nIn project refact-lsp: A tests/emergency_frog_situation/.refact/project_summary.yaml, M tests/emergency_frog_situation/frog.py, M tests/emergency_frog_situation/jump_to_conclusions.py, ...\n```\n⚠️ You might have a problem rolling back agent's changes.",

links: [
{
text: "Save and return",
action: "patch-all",
goto: "SETTINGS:/path/to/config/file.yaml",
link_text: "Save and return",
link_action: "patch-all",
link_goto: "SETTINGS:/path/to/config/file.yaml",
link_tooltip: "",
},
{
link_text: "Save and Continue",
link_action: "patch-all",
link_goto: "NEWCHAT",
link_tooltip: "",
},
{
text: "Can you fix it?",
action: "follow-up",
link_text: "Can you fix it?",
link_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_text: "Investigate Project",
link_action: "summarize-project",
link_tooltip: "",
},

{
link_action: "post-chat",
link_text: "Stop recommending integrations",
link_tooltip: "",
link_payload: {
chat_meta: {
chat_id: "",
chat_remote: false,
chat_mode: "CONFIGURE",
current_config_file:
"/Users/kot/code_aprojects/demotest/.refact/project_summary.yaml",
},
messages: [
{
role: "user",
content:
"Make recommended_integrations an empty list, follow the system prompt.",
},
],
},
},
// {
// text: "long long long long long long long long long long long long long long long long long long ",
// action: "summarize-project",
// link_tooltip: "",
// },
{
action: "commit",
text: "Commit 4 files in `refact-lsp`",
goto: "LINKS_AGAIN",
link_action: "commit",
link_text: "Commit 4 files in `refact-lsp`",
link_goto: "LINKS_AGAIN",
link_tooltip:
'git commmit -m "Add build script and test files for Docker image deployment and output generation..."\nA build-remote.sh\nA long-array.py\nA long-output.py\nA test.py',
link_payload: {
Expand Down
4 changes: 4 additions & 0 deletions src/__fixtures__/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export const INTEGRATIONS_RESPONSE: Integration = {
f_placeholder: "marketing_db",
},
},
confirmation: {
ask_user_default: [],
deny_default: [],
},
available: {
on_your_laptop_possible: true,
when_isolated_possible: true,
Expand Down
14 changes: 14 additions & 0 deletions src/__fixtures__/msw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ export const goodUser: HttpHandler = http.get(
},
);

export const nonProUser: HttpHandler = http.get(
"https://www.smallcloud.ai/v1/login",
() => {
return HttpResponse.json({
retcode: "OK",
account: "[email protected]",
inference_url: "https://www.smallcloud.ai/v1",
inference: "FREE",
metering_balance: -100000,
questionnaire: {},
});
},
);

export const chatLinks: HttpHandler = http.post(
`http://127.0.0.1:8001${CHAT_LINKS_URL}`,
() => {
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/PinMessages.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe("Pin messages", () => {
streaming: false,
error: null,
waiting_for_response: false,
max_new_tokens: 4096,
cache: {},
system_prompt: {},
tool_use: "explore",
Expand Down
38 changes: 38 additions & 0 deletions src/__tests__/isAbsolutePath.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, it, expect } from "vitest";
import { isAbsolutePath } from "../utils/isAbsolutePath";

describe("isAbsolutePath", () => {
it("should return true for Windows absolute paths", () => {
expect(
isAbsolutePath(
"\\\\?\\C:\\Users\\andre\\.config\\integrations.d\\cmdline_example.yaml",
),
).toBe(true);
expect(isAbsolutePath("D:\\Folder\\Subfolder")).toBe(true);
});

it("should return true for Unix absolute paths", () => {
expect(isAbsolutePath("/usr/local/bin")).toBe(true);
expect(
isAbsolutePath(
"/Users/andre/.config/integrations.d/cmdline_example.yaml",
),
).toBe(true);
});

it("should return true for UNC paths", () => {
expect(isAbsolutePath("\\\\Server\\Share")).toBe(true);
expect(isAbsolutePath("//Server/Share")).toBe(true);
});

it("should return false for relative paths", () => {
expect(isAbsolutePath("relative/path")).toBe(false);
expect(isAbsolutePath("folder\\subfolder")).toBe(false);
expect(isAbsolutePath("./relative")).toBe(false);
expect(isAbsolutePath("../relative")).toBe(false);
});

it("should return false for empty string", () => {
expect(isAbsolutePath("")).toBe(false);
});
});
21 changes: 18 additions & 3 deletions src/app/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { resetAttachedImagesSlice } from "../features/AttachedImages";
import { nextTip } from "../features/TipOfTheDay";
import { telemetryApi } from "../services/refact/telemetry";
import { CONFIG_PATH_URL, FULL_PATH_URL } from "../services/refact/consts";
import { resetConfirmationInteractedState } from "../features/ToolConfirmation/confirmationSlice";

export const listenerMiddleware = createListenerMiddleware();
const startListening = listenerMiddleware.startListening.withTypes<
Expand All @@ -43,20 +44,34 @@ startListening({
),
effect: (_action, listenerApi) => {
[
pingApi.util.resetApiState(),
// pingApi.util.resetApiState(),
statisticsApi.util.resetApiState(),
capsApi.util.resetApiState(),
promptsApi.util.resetApiState(),
// capsApi.util.resetApiState(),
// promptsApi.util.resetApiState(),
toolsApi.util.resetApiState(),
commandsApi.util.resetApiState(),
diffApi.util.resetApiState(),
resetAttachedImagesSlice(),
resetConfirmationInteractedState(),
].forEach((api) => listenerApi.dispatch(api));

listenerApi.dispatch(clearError());
},
});

// TODO: think about better cache invalidation approach instead of listening for an action dispatching globally
startListening({
matcher: isAnyOf((d: unknown): d is ReturnType<typeof newIntegrationChat> =>
newIntegrationChat.match(d),
),
effect: (_action, listenerApi) => {
[integrationsApi.util.resetApiState()].forEach((api) =>
listenerApi.dispatch(api),
);
listenerApi.dispatch(clearError());
},
});

startListening({
// TODO: figure out why this breaks the tests when it's not a function :/
matcher: isAnyOf(isRejected),
Expand Down
9 changes: 8 additions & 1 deletion src/app/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { attachedImagesSlice } from "../features/AttachedImages";
import { userSurveySlice } from "../features/UserSurvey/userSurveySlice";
import { linksApi } from "../services/refact/links";
import { integrationsSlice } from "../features/Integrations";
import { agentUsageSlice } from "../features/AgentUsage/agentUsageSlice";

const tipOfTheDayPersistConfig = {
key: "totd",
Expand Down Expand Up @@ -92,12 +93,18 @@ const rootReducer = combineSlices(
attachedImagesSlice,
userSurveySlice,
integrationsSlice,
agentUsageSlice,
);

const rootPersistConfig = {
key: "root",
storage: storage(),
whitelist: [historySlice.reducerPath, "tour", userSurveySlice.reducerPath],
whitelist: [
historySlice.reducerPath,
"tour",
userSurveySlice.reducerPath,
agentUsageSlice.reducerPath,
],
stateReconciler: mergeInitialState,
};

Expand Down
24 changes: 23 additions & 1 deletion src/components/Buttons/Buttons.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useCallback } from "react";
import { IconButton, Button, Flex } from "@radix-ui/themes";
import {
PaperPlaneIcon,
Expand All @@ -8,6 +8,7 @@ import {
} from "@radix-ui/react-icons";
import classNames from "classnames";
import styles from "./button.module.css";
import { useOpenUrl } from "../../hooks/useOpenUrl";

type IconButtonProps = React.ComponentProps<typeof IconButton>;
type ButtonProps = React.ComponentProps<typeof Button>;
Expand Down Expand Up @@ -64,3 +65,24 @@ export const RightButtonGroup: React.FC<React.PropsWithChildren & FlexProps> = (
/>
);
};

export const LinkButton: React.FC<
ButtonProps & {
href?: string;
target?: HTMLFormElement["target"];
onClick?: () => void;
}
> = ({ href, target, onClick, ...rest }) => {
const openUrl = useOpenUrl();
const handleClick = useCallback(() => {
if (onClick) onClick();
if (href) openUrl(href);
}, [href, onClick, openUrl]);
return (
<form action={href} target={target} onSubmit={handleClick}>
<Button type="submit" {...rest}>
Upgrade to our pro plan
</Button>
</form>
);
};
1 change: 1 addition & 0 deletions src/components/Buttons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export {
BackToSideBarButton,
RightButton,
RightButtonGroup,
LinkButton,
} from "./Buttons";
16 changes: 16 additions & 0 deletions src/components/Callout/Callout.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,19 @@
visibility 0.3s ease-in-out,
opacity 0.3s ease-in-out;
}

.callout_from_top {
overflow-wrap: anywhere;
position: absolute;
animation: rollin_from_top 0.2s ease-out;
z-index: 1;
}

@keyframes rollin_from_top {
0% {
transform: translateY(-100%);
}
100% {
transform: translateY(0);
}
}
22 changes: 21 additions & 1 deletion src/components/Callout/Callout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from "react";
import { Flex, Callout as RadixCallout } from "@radix-ui/themes";
import { Flex, Callout as RadixCallout, Card } from "@radix-ui/themes";
import {
ExclamationTriangleIcon,
InfoCircledIcon,
Expand Down Expand Up @@ -145,3 +145,23 @@ export const DiffWarningCallout: React.FC<Omit<CalloutProps, "type">> = ({
</Callout>
);
};

export const CalloutFromTop: React.FC<
RadixCalloutProps & {
children?: React.ReactNode;
}
> = ({ children }) => {
return (
<Card asChild>
<RadixCallout.Root color="amber" className={styles.changes_warning}>
<Flex direction="row" align="center" gap="4" position="relative">
<RadixCallout.Icon>
<InfoCircledIcon />
</RadixCallout.Icon>

{children}
</Flex>
</RadixCallout.Root>
</Card>
);
};
Loading

0 comments on commit d35d901

Please sign in to comment.