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

WIP: command completion #2

Merged
merged 168 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
168 commits
Select commit Hold shift + click to select a range
74e0735
wip(command completion): add event bus and state for the combobox
MarcMcIntosh Feb 1, 2024
6558f2e
wip(command completion): get the next commands
MarcMcIntosh Feb 1, 2024
de9f6f5
wip(command completion): rough implementation of completion box
MarcMcIntosh Feb 2, 2024
3b0abbd
ui(combobox): handle item clicks better
MarcMcIntosh Feb 2, 2024
b4dcb8d
refactor(combo-box): add tests, stories and clean up the code
MarcMcIntosh Feb 5, 2024
cc9ef15
refactor(combobox): execute command and handle submit
MarcMcIntosh Feb 5, 2024
01960d0
test(combobox): remove only flag
MarcMcIntosh Feb 5, 2024
6796434
refactor(combobox): move popover and item to separate files
MarcMcIntosh Feb 5, 2024
f28df81
refactor(command box): hoist selected command and try to get the preview
MarcMcIntosh Feb 5, 2024
dc03c91
fix(combobox): add new line before command
MarcMcIntosh Feb 5, 2024
8da870a
fix: update chat form story
MarcMcIntosh Feb 6, 2024
d77a06a
feat(commands): receive and execute commands
MarcMcIntosh Feb 6, 2024
54f7a98
refactor: combobox story
MarcMcIntosh Feb 6, 2024
02f6c73
fix(refact service): remove last user message on response
MarcMcIntosh Feb 6, 2024
64b66be
test(combobox): update tests
MarcMcIntosh Feb 6, 2024
60c3b66
fix(combobox): query while typing
MarcMcIntosh Feb 6, 2024
80aec0b
fix(combobox): too many request for completions, and add context_file…
MarcMcIntosh Feb 7, 2024
0cc71d7
fix(eslint): remove unused disable-next-line
MarcMcIntosh Feb 7, 2024
7901d75
feat(combobox): handle deleting arguments
MarcMcIntosh Feb 7, 2024
ba40b90
fix(chat response): handle user and context file being in response
MarcMcIntosh Feb 7, 2024
97fafd3
fix(chat): remove duplicate context files
MarcMcIntosh Feb 7, 2024
9261ac4
fix(combobox): when deleting set selected command and reopen the box …
MarcMcIntosh Feb 7, 2024
90ae4fa
chore: update todo list
MarcMcIntosh Feb 7, 2024
5be511b
ui(file name): wrap long file names
MarcMcIntosh Feb 7, 2024
55bef2e
fix(chat messages): remove user and context messages that will be ret…
MarcMcIntosh Feb 7, 2024
ba75cae
chore: update TODO's
MarcMcIntosh Feb 7, 2024
dc1298e
Merge branch 'main' into vecdb
MarcMcIntosh Feb 7, 2024
9cd3129
chore: remove console.log staments
MarcMcIntosh Feb 7, 2024
10faccf
test(multiple. commands): seems to be flaky will investigate later
MarcMcIntosh Feb 7, 2024
a9cebfc
test(ci): recreate combobox replaceValue issue in ci
MarcMcIntosh Feb 7, 2024
00a5c97
test(ci): recreate replace value bug
MarcMcIntosh Feb 7, 2024
63fd099
test(ci): debbug in ci
MarcMcIntosh Feb 7, 2024
74dce3f
test(ci) recreate combobox issue locally
MarcMcIntosh Feb 7, 2024
ea55ba0
test(combobox): fix broken test
MarcMcIntosh Feb 8, 2024
aa67c41
refactor(chat content): move file display component to it's own file
MarcMcIntosh Feb 8, 2024
4407e3b
feat(chat form): add files in preivew
MarcMcIntosh Feb 8, 2024
05f22d1
test: update chat form test with files in preview prop
MarcMcIntosh Feb 8, 2024
0407856
ui(sidebar): add flex grow to chat history list
MarcMcIntosh Feb 8, 2024
477da53
fix(combobox): add save start position when pressing @ so it's easier…
MarcMcIntosh Feb 8, 2024
a6a7f39
fix: add new line after executable command
MarcMcIntosh Feb 8, 2024
9edd127
fix(combobox): adding new line after the command
MarcMcIntosh Feb 9, 2024
28cc8fb
fix(lint): remove console.log
MarcMcIntosh Feb 9, 2024
3c07b38
fix(type guards): handle detail error messages
MarcMcIntosh Feb 9, 2024
6928cfb
fix(combobox): bug adding new line after deletion
MarcMcIntosh Feb 9, 2024
2398f5c
fix(combobox): add new line to file command when argument is filled
MarcMcIntosh Feb 9, 2024
64ae547
ui(file preview): replace /home/user with ~
MarcMcIntosh Feb 9, 2024
1fb95d5
refactor(file preview file names): use a regular expression to remove…
MarcMcIntosh Feb 9, 2024
6f2d36a
fix(command preview): send all user input for command preview and rep…
MarcMcIntosh Feb 12, 2024
c0b8142
feat(chat): save last used model
MarcMcIntosh Feb 12, 2024
6bdda38
feat(commands): send @workspace and argument to lsp
MarcMcIntosh Feb 12, 2024
edfd0b1
ui(chat): increase textarea size with user input
MarcMcIntosh Feb 12, 2024
4040cca
fix(ide): add selected text to user input
MarcMcIntosh Feb 12, 2024
1b5d789
ui(code): use the same size of text in the code as the rest of the chat
MarcMcIntosh Feb 12, 2024
6ac7118
wip(combobox): remove adding a new line when executing a command
MarcMcIntosh Feb 12, 2024
9ef3fb1
fix(command completion): allow the user to type a new line after the …
MarcMcIntosh Feb 12, 2024
1282ee6
ui(chat content): add min-height to user input
MarcMcIntosh Feb 12, 2024
b5bdadc
feat(snippet): add syntax highlighting to code snippet in user message
MarcMcIntosh Feb 13, 2024
ac9e218
ui(retry form): adjust button distance from top to accommodate markdown
MarcMcIntosh Feb 13, 2024
9be386c
fix(combobox): shift plus enter should only add a new line
MarcMcIntosh Feb 13, 2024
cbf18d6
fix(combobox): re-open combobox when deleting a command
MarcMcIntosh Feb 13, 2024
6b27bae
fix(test): combobox deleting and pressing enter over an @command with…
MarcMcIntosh Feb 13, 2024
a66b56c
chore: update usehooks-ts
MarcMcIntosh Feb 13, 2024
29ac20d
fix(combobox): debounce calls to command completion
MarcMcIntosh Feb 13, 2024
ddfb84d
fix(combobox): when the user types command and deletes the first part…
MarcMcIntosh Feb 13, 2024
5b35dfd
chore(command completion): increase debounce delay
MarcMcIntosh Feb 13, 2024
78a5e07
feat(combobox): remove file preview when deleting the file name
MarcMcIntosh Feb 13, 2024
f420c6f
tests: update default props in test for chat form and combobox
MarcMcIntosh Feb 13, 2024
b308246
fix(combobox): trimming the start of the command off when typing an a…
MarcMcIntosh Feb 13, 2024
3faed01
fix(combobox): don't filter out non-matches from the selection
MarcMcIntosh Feb 13, 2024
109dfe9
test(combobox): update broken test
MarcMcIntosh Feb 14, 2024
924d5a1
refactor(command preview): add 500ms debounce to command preview calls
MarcMcIntosh Feb 14, 2024
393ae12
fix(chat): set previous message length when retrying a question
MarcMcIntosh Feb 14, 2024
67439f0
fix(combobox): box remaining open after asking using box and asking q…
MarcMcIntosh Feb 14, 2024
db4eb61
ui(chat content): fix empty context file taking up spoace
MarcMcIntosh Feb 14, 2024
ef395e2
feat(file preview): allow the user to manually remove files
MarcMcIntosh Feb 14, 2024
dbcc67a
refactor(remove file button): style using css classname rather than i…
MarcMcIntosh Feb 14, 2024
0337f5e
refactor(file preview): use radix button with some styles unset
MarcMcIntosh Feb 14, 2024
860c291
refactor: update type definitions for new chat event, and chat config
MarcMcIntosh Feb 14, 2024
d63d1b0
chore: update readme with instructions on how to integrate chat with …
MarcMcIntosh Feb 14, 2024
bb0effb
chore: update todos
MarcMcIntosh Feb 14, 2024
d446610
chore(readme): add strings to the the event names
MarcMcIntosh Feb 14, 2024
b1c308b
fix(command completion): send the whole input to completion and preview
MarcMcIntosh Feb 15, 2024
4b412e3
fix(commands completion): remove preview and commands when receiving …
MarcMcIntosh Feb 15, 2024
a4ee23f
fix(commandbox): auto select first element so @ enter enter works
MarcMcIntosh Feb 15, 2024
7909199
wip: scroll with in chat input from
MarcMcIntosh Feb 15, 2024
6868605
test(command box): type a command then some text then go back and rep…
MarcMcIntosh Feb 15, 2024
e4fb11e
fix(command box): end text was being replaced when command was update…
MarcMcIntosh Feb 15, 2024
48734dd
test(combox): use keyboard events to move cursor back
MarcMcIntosh Feb 15, 2024
95a9e35
fix: use custom-scroll bar for large user inputs and render combobox …
MarcMcIntosh Feb 19, 2024
29ff20e
fix(combobox): clicking on an item shouldn't result the starting posi…
MarcMcIntosh Feb 19, 2024
ff76a3f
test(watchMedia): mock watch media
MarcMcIntosh Feb 19, 2024
7b1480b
fix(combobox): when adding a command between text the cursor should m…
MarcMcIntosh Feb 19, 2024
647073e
refactor: clean up chat form test, replace to be depricated useEffect…
MarcMcIntosh Feb 19, 2024
27c9602
refactor: rename Response from command preview to command preview res…
MarcMcIntosh Feb 19, 2024
30f22c0
chore(source maps): add source maps for browser build
MarcMcIntosh Feb 19, 2024
49ab2a9
refactor: export CommandPreviewContent type
MarcMcIntosh Feb 19, 2024
91f549f
wip(chat content): auto scroll to bottom when the text area increases…
MarcMcIntosh Feb 19, 2024
75dfb2d
fix(chat form): update tests and stories
MarcMcIntosh Feb 19, 2024
d531dbd
chore(todos): update todos
MarcMcIntosh Feb 19, 2024
8bbe44f
fix(test chat): conditionally call scrollInToView if it's in the dom
MarcMcIntosh Feb 19, 2024
63bb66d
test: find and fix flaky tests
MarcMcIntosh Feb 19, 2024
b1650b2
fix(test-utils): unused parameter in repeat funciton
MarcMcIntosh Feb 19, 2024
4bec136
test(combobox): fix another. flak test
MarcMcIntosh Feb 19, 2024
8ff6f2a
test: add retry parameter
MarcMcIntosh Feb 19, 2024
6fb9152
chore(vite): silence sourcemap warning messages until issue 15012 is …
MarcMcIntosh Feb 19, 2024
ee0ebf5
ui(markdown): change the left padding on ol and ul elements
MarcMcIntosh Feb 20, 2024
c68cb51
fix(combobox): selecting and deleting tricks the combobox to block pr…
MarcMcIntosh Feb 20, 2024
8e8bb0c
fix(combobox): replacing text before the command
MarcMcIntosh Feb 20, 2024
9f9b10e
workaround(command completion): completion only works if the @ is on …
MarcMcIntosh Feb 20, 2024
b37637e
fix(combobox): add a new line when selecting a command
MarcMcIntosh Feb 20, 2024
811edc6
fix(command completion): edge case where a user types then presses @
MarcMcIntosh Feb 20, 2024
0f80d4c
chore: update readme and todos
MarcMcIntosh Feb 20, 2024
4e03a3e
test(commandbox): update the expected calls to the request spy
MarcMcIntosh Feb 20, 2024
31f6e0b
test(combobox utils): add test for the detect command and replace val…
MarcMcIntosh Feb 20, 2024
17fc5f0
feat(combobox): add undo / redo
MarcMcIntosh Feb 20, 2024
d563dbc
feat(combobox undo redo): open combobox during undo / redo
MarcMcIntosh Feb 20, 2024
3fa0760
test(command box): select and execute command, prevent the combobox f…
MarcMcIntosh Feb 20, 2024
a48e3c5
test(command box): submit the form when pressing enter
MarcMcIntosh Feb 20, 2024
b3be188
fix(combobox): prevent enter being blocked after deletion
MarcMcIntosh Feb 20, 2024
7c99e88
test(command box): delete part of the command
MarcMcIntosh Feb 20, 2024
943f200
fix(command box): clear. input when submitting
MarcMcIntosh Feb 20, 2024
54e09b4
fix(combobox): undo / redo reset the value after sumbitting
MarcMcIntosh Feb 20, 2024
608af99
refactor(undo/redo): clear the input cache after posting a question.
MarcMcIntosh Feb 21, 2024
e00a5fb
refactor(undo / redo): fix type for reset
MarcMcIntosh Feb 21, 2024
99de7be
ui(chat content): adjust padding on user message
MarcMcIntosh Feb 21, 2024
6ee943d
fix(state): set done streaming when the user clicks stop
MarcMcIntosh Feb 21, 2024
322cbdc
refactor(remove last user message): use a smarter way to remove the l…
MarcMcIntosh Feb 21, 2024
2466862
lint: remove debug with console.log
MarcMcIntosh Feb 21, 2024
eba5536
fix(vscode): stop retry appending the same context files
MarcMcIntosh Feb 21, 2024
3d00d52
chore: update readme after removing one event
MarcMcIntosh Feb 21, 2024
0fde4f6
refactor(markdown): make some visual improvements and tidy up the code
MarcMcIntosh Feb 21, 2024
2acc704
fix(codeblock): import the correct element type.
MarcMcIntosh Feb 21, 2024
601c20d
refactor(undo / redo): block native handlers and set selected command…
MarcMcIntosh Feb 22, 2024
9f53a8a
chore(sidebar): remove commented out code
MarcMcIntosh Feb 22, 2024
85d039a
test(combobx): onSumbit is called with keyboard event not a value
MarcMcIntosh Feb 22, 2024
819f2da
fix(textarea/combobox): prevent insterting a new line when submitting
MarcMcIntosh Feb 22, 2024
4363b9e
fix(combobox file preview): run preview even when there is no trigger
MarcMcIntosh Feb 22, 2024
59c4a1e
ui(command-preview): add left ellipses to long file names
MarcMcIntosh Feb 22, 2024
d4eb93c
ui(command-preview): add a space before the dots
MarcMcIntosh Feb 22, 2024
38d23c6
feat(snippet): add snippet when opening a chat
MarcMcIntosh Feb 23, 2024
bf2f27f
refactor(snippet): update selected snippet payload
MarcMcIntosh Feb 23, 2024
3322fd6
fix(web): payload is conditional when creating a new chat
MarcMcIntosh Feb 23, 2024
73ba8f7
fix: undo redo, bug due to snippet comment
MarcMcIntosh Feb 23, 2024
a9c17b0
wip: refactor combobox and textarea, move undo/redo hook to textarea
MarcMcIntosh Feb 23, 2024
e77e305
wip: refactor undo/redo textarea handles undo redo and preventDefault…
MarcMcIntosh Feb 23, 2024
cc08f9f
refactor(combobox): simplify undo/redo
MarcMcIntosh Feb 23, 2024
e4bf0e1
refactor(textarea): comabobox and texta area should be able to receiv…
MarcMcIntosh Feb 23, 2024
6ff274b
refactor(combobox): handle deletions better
MarcMcIntosh Feb 23, 2024
53c8497
fix: update types after refactoring
MarcMcIntosh Feb 23, 2024
c7ad078
Merge branch 'main' into vecdb
MarcMcIntosh Feb 23, 2024
325c497
chore(types): add usefullness property to chat context file
MarcMcIntosh Feb 23, 2024
d251166
chore: run prettier
MarcMcIntosh Feb 23, 2024
89f1a15
chore: remove console.log
MarcMcIntosh Feb 23, 2024
45c7790
feat(attach file): attach file using @ command
MarcMcIntosh Feb 24, 2024
c249d66
ui(markdown): add text variants from radix
MarcMcIntosh Feb 25, 2024
c0cf019
ui(sidebar): left-align footer buttons with history list and add some…
MarcMcIntosh Feb 25, 2024
258d667
fix(undo/redo): send on change event when undoing / redoing
MarcMcIntosh Feb 25, 2024
a5300d2
test(detectCommand): add broken test for detecting before a new line
MarcMcIntosh Feb 25, 2024
68ff3c7
fix(textarea + combobox): setting the cursor position when appending …
MarcMcIntosh Feb 25, 2024
b800015
fix(file preview messages): there's no need to attach them
MarcMcIntosh Feb 25, 2024
e229cb0
fix(combobox): use the sorting from the lsp
MarcMcIntosh Feb 25, 2024
24b9b38
fix(events): keep toggle active file event
MarcMcIntosh Feb 26, 2024
8ab9a41
Merge branch 'vecdb' of https://github.com/smallcloudai/refact-chat-j…
MarcMcIntosh Feb 26, 2024
08545ee
test(combobox): update tests after removing match-sorter
MarcMcIntosh Feb 26, 2024
0fa0fbf
refactor(truncate left text): move text to it's own component
MarcMcIntosh Feb 26, 2024
6f226f6
feat: update Active file info, change layout for snippet button and a…
MarcMcIntosh Feb 26, 2024
c159fa7
feat(chat): add model and balance information
MarcMcIntosh Feb 27, 2024
9120a7e
Merge branch 'main' into vecdb
MarcMcIntosh Feb 28, 2024
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
296 changes: 293 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,34 @@ when `host` is `web` the chat will be rendered in the browser and the events to
when `host` is `ide`, `vscode` or `jetbrains` events to and from the chat will be handled by the corresponding IDE or code editor via the `postMessage` API.
when ``

`tabbed` is true or false, default `false`
`tabbed` is true or false, default `false` used in vscode for when the chat is rendered in a tab

`dev` if dev is true then the component works as it would when `host` is set to web but can display the chat as it would in another host setting.

`lspUrl` is the url of the refact-lsp server. If not set, the component will try to connect to the server using the default url `/`.

`themeProps`?: object containing some styles for the chat component.

```ts
interface ThemeProps = {

hasBackground: boolean = true;

appearance: "inherit" | "light" | "dark" = "inherit";

accentColor: "tomato" | "red" | "ruby" | "crimson" | "pink"| "plum" | "purple" | "violet" | "iris" | "indigo" | "blue" | "cyan" | "teal" | "jade" | "green" | "grass" | "brown" | "orange" | "sky" | "mint" | "lime" | "yellow" | "amber" | "gold" | "bronze" | "gray" = "indigo";

grayColor: "gray" | "mauve" | "slate" | "sage" | "olive" | "sand" | "auto" = "auto";

panelBackground: "solid" | "translucent" = "translucent";

radius: "none" | "small" | "medium" | "large" | "full" = "medium";

scaling: "90%" | "95%" | "100%" | "105%" | "110%" = "100%";

}
```

#### Events

type definitions for events that chat component emits and receives from the host are in `src/events/index.ts` and exported from `dist/events/index.js`
Expand All @@ -63,5 +87,271 @@ run `REFACT_LSP_URL="http://localhost:8001 npm dev` and go to localhost:5173

## How to build for docker

`VITE_REFACT_LSP_URL="/lsp" npm run build -- --base=chat`
and copy the files over to `refact/self_hosting_machinery/webgui/static` renaming "dist/index.html" to "chat.html"
`VITE_REFACT_LSP_URL="/lsp" npm run build`
and copy the files `dist/chat/styles.css` and `dist/index.umd.cjs` over to `refact/self_hosting_machinery/webgui/static/assets`

## Integrating with IDE's

### Message sent between chat and host.

Events types are loosely guarded by using `type branding` on the events `type` property

```ts
/**
* This message is sent from the chat component to the host when the chat is mounted and ready to receive messages.
*/
interface ReadyMessage extends ActionFromChat {
type: EVENT_NAMES_FROM_CHAT.READY; // "chat_ready"
payload: { id: string };
}

/**
* This messages is sent from the host to the chat component to restore a previously saved chat.
*/
interface RestoreChat extends ActionToChat {
type: EVENT_NAMES_TO_CHAT.RESTORE_CHAT; // = "restore_chat_from_history"
payload: ChatThread;
}

/**
* The host sends this message to start a new chat thread.
*/
interface CreateNewChatThread extends ActionToChat {
type: EVENT_NAMES_TO_CHAT.NEW_CHAT; // = "create_new_chat"
payload?: { id: string; snippet: string };
}

/**
* Chat sends this to the host when asking a question.
*/
interface QuestionFromChat extends ActionFromChat {
type: EVENT_NAMES_FROM_CHAT.ASK_QUESTION; // = "chat_question"
payload: ChatThread;
}
/**
* Response from the host to the question
*/
interface ResponseToChat extends ActionToChat {
type: EVENT_NAMES_TO_CHAT.CHAT_RESPONSE; // = "chat_response",
payload: ChatResponse;
}

/**
* This message is sent from the host to the chat when the lsp is done streaming it's response
*/
interface ChatDoneStreaming extends ActionToChat {
type: EVENT_NAMES_TO_CHAT.DONE_STREAMING; // = "chat_done_streaming"
payload: { id: string };
}

/**
* Sent from the host to the chat when an error has happened while streaming the response
*/
interface ChatErrorStreaming extends ActionToChat {
type: EVENT_NAMES_TO_CHAT.ERROR_STREAMING; // = "chat_error_streaming"
payload: { id: string; message: string };
}
/**
* Request for command completion from the lsp
* trigger will be null if the user has selected a command at that point it should be fine to send the query to the lsp
*/
interface RequestAtCommandCompletion extends ActionFromChat {
type: EVENT_NAMES_FROM_CHAT.REQUEST_AT_COMMAND_COMPLETION; // = "chat_request_at_command_completion"
payload: {
id: string;
query: string;
cursor: number;
trigger: string | null;
number?: number;
};
}

/**
* This message is sent from the host to the chat contains the result of command completion request
*/
interface ReceiveAtCommandCompletion extends ActionToChat {
type: EVENT_NAMES_TO_CHAT.RECEIVE_AT_COMMAND_COMPLETION; // = "chat_receive_at_command_completion"
payload: { id: string } & CommandCompletionResponse;
}

/**
* This message is sent from the chat component to the host to request for command preview
*/
interface RequestAtCommandPreview extends ActionFromChat {
type: EVENT_NAMES_FROM_CHAT.REQUEST_AT_COMMAND_PREVIEW; // = "chat_request_at_command_preview"
payload: { id: string; query: string; cursor: number };
}

/**
* This message is sent from the chat component to the host when the response to the question is received.
*/
interface SaveChatFromChat extends ActionFromChat {
type: EVENT_NAMES_FROM_CHAT.SAVE_CHAT; // = "save_chat_to_history"
payload: ChatThread;
}

/**
* Tells chat to replace the current message list, this is done before sending a question to the lsp.
*/
interface BackUpMessages extends ActionToChat {
type: EVENT_NAMES_TO_CHAT.BACKUP_MESSAGES; // = "back_up_messages"
payload: { id: string; messages: ChatMessages };
}

/**
* This message is sent from the chat component to the host when the user clicks stop while the response is streaming.
*/
interface StopStreamingFromChat extends ActionFromChat {
type: EVENT_NAMES_FROM_CHAT.STOP_STREAMING; // = "chat_stop_streaming"
payload: { id: string };
}

/**
* chat requesting caps from the server.
*/
interface RequestCapsFromChat extends ActionFromChat {
type: EVENT_NAMES_FROM_CHAT.REQUEST_CAPS; // = "chat_request_caps"
payload: { id: string };
}

/**
* This message is sent from the host to the chat when the server responds with caps.
*/
interface ChatReceiveCaps extends ActionToChat {
type: EVENT_NAMES_TO_CHAT.RECEIVE_CAPS; // = "receive_caps"
payload: { id: string; caps: CapsResponse };
}

/**
* This message is sent from the host to the chat when the server responds with an error.
*/
interface ChatReceiveCapsError extends ActionToChat {
type: EVENT_NAMES_TO_CHAT.RECEIVE_CAPS_ERROR; // = "receive_caps_error"
payload: { id: string; message: string };
}

/**
* This message is sent from the host to the chat with information about the current active file
*/
interface ActiveFileInfo extends ActionToChat {
type: EVENT_NAMES_TO_CHAT.ACTIVE_FILE_INFO; // = "chat_active_file_info"
payload: { id: string; name: string; can_paste: boolean };
}

/**
* This message is sent from the host to the chat to set the selected snippet.
*/
interface ChatSetSelectedSnippet extends ActionToChat {
type: EVENT_NAMES_TO_CHAT.SET_SELECTED_SNIPPET; // = "chat_set_selected_command"
payload: { id: string; snippet: { code: string; language: string } };
}

/**
* This message is sent from the host telling chat to enable of disable the chat input.
*/
interface SetChatDisable extends ActionToChat {
type: EVENT_NAMES_TO_CHAT.SET_DISABLE_CHAT; // = "set_disable_chat"
payload: { id: string; disable: boolean };
}

/**
* Sets the default chat model for the chat.
*/
interface SetChatModel extends ActionToChat {
type: EVENT_NAMES_TO_CHAT.SET_CHAT_MODEL; // = "chat_set_chat_model"
payload: { id: string; model: string };
}

/**
* This message is sent from the chat when the user clicks the `new file` button in a code example.
*/
interface NewFileFromChat extends ActionFromChat {
type: EVENT_NAMES_FROM_CHAT.NEW_FILE; // = "chat_create_new_file"
payload: { id: string; content: string };
}

/**
* This message is sent from the chat when the user clicks the `paste` button in a code example.
*/
interface PasteDiffFromChat extends ActionFromChat {
type: EVENT_NAMES_FROM_CHAT.PASTE_DIFF; // = "chat_paste_diff"
payload: { id: string; content: string };
}
```

### Data types in the events

```ts
type ChatContextFile = {
file_name: string;
file_content: string;
line1: number;
line2: number;
};

interface ChatContextFileMessage extends BaseMessage {
0: "context_file";
1: ChatContextFile[];
}

interface UserMessage extends BaseMessage {
0: "user";
1: string;
}

interface AssistantMessage extends BaseMessage {
0: "assistant";
1: string;
}

type ChatMessage = UserMessage | AssistantMessage | ChatContextFileMessage;

type ChatMessages = ChatMessage[];

type ChatThread = {
id: string;
messages: ChatMessages;
title?: string | undefined;
model: string;
attach_file?: boolean | undefined;
};

type ChatResponse =
| { choices: ChatChoice[]; created: number; model: string; id: string }
| ChatUserMessageResponse;

type ChatChoice = {
delta: Delta;
finish_reason: "stop" | "abort" | null;
index: number;
};

type ChatUserMessageResponse = {
id: string;
role: "user" | "context_file";
content: string;
};

type CapsResponse = {
code_chat_default_model: string;
code_chat_models: Record<string, CodeChatModel>;
};

type CodeCompletionModel = {
default_scratchpad: string;
n_ctx: number;
similar_models: string[];
supports_scratchpads: Record<string, Record<string, unknown>>;
};

type CommandCompletionResponse = {
completions: string[];
replace: Replace;
is_cmd_executable: false;
};

interface Replace {
0: number;
1: number;
}
```
56 changes: 52 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,57 @@
[ ] canceling chat doesn't seems to work (the spinner keeps spinning) :/
[x] build the events (+ types) as a dedicated file
[ ] automate publishing the main branch
[ ] export the chat history component
[ ] add vscode specific button for opening the history in a tab
[x] export the chat history component
[x] add vscode specific button for opening the history in a tab
[ ] should be monotype font on tooltip (will require adding a custom tooltip)
[ ] update readme with the new features/options

[x] command completion combobox interactions
[ ] maybe add optimistic cache for queries to lsp?
[x] remove context latest context files from chat when sending a message
[x] small but in command deletion, type @fi tab delete delete then tab
[x] workspace being run twice ? or adding extra files
[x] update readme with the new features/options
[x] uninstall react-cookie and delete code comments
[x] fix flaky test for multiple commands
[x] figure out why the combobox is sometimes not removing the input trigger
[x] add temp file storage when the user uses @ commands
[x] set the model when using @ commands
[x] prevent the user from changing the model when there are temp files
[x] add new line after command
[x] add flex grow to history list
[x] save last used model
[x] increase textarea height with user input
[x] send whole user input when previewing a command
[x] replace file preview when receiving command preview
[x] don't add a new line if command is executable but has no arguments
[x] use syntax highlighting in the users message
[x] bug when running retry, user message isn't removed
[x] bug with the combobox being open after asking a question
[x] file preview should scroll with textarea
[x] chat content should stay at end when textarea grows
[ ] should the scrolling be disabled if the user has scrolled away from the bottom?

[x] combobox only needs one function for completion and preview
[x] check clicking on the combobox the second click on @@file doesn't seem to work.
[x] place the cursor at the right place when adding a command between text
[x] use repeat to find flaky tests
[x] combobox undo / redo
[x] list display in response has a large margin/padding
[ ] tidy up combobox
[x] bug @ast_definition blocks sending requests
[ ] TBD: response cache for undo / redo, use a hashmap
[x] limit the size of undo / redo history
[x] fix re-attaching files on retry
[x] undo redo, holding ctrl keeps the box open until the user releases it
[x] attach file with @ command,
[x] bug: add text, add file go back and edit the text fixed by prepending the command to the value
[x] ctrl-z then enter, cursor is at wrong position
[x] @, enter, enter, ctrl-z, enter
[x] allow paste when no code is selected (A convenient way to insert code from the chat into the active tab (where the cursor is) is needed.)
[ ] combobox theme not working in vscode
[x] use a different way to disable attach than if context file is there
[ ] remove snippet
[x] add metering_balance (coins) and model used in chat

### EVENTS TODO FOR IDEs

Expand All @@ -97,4 +143,6 @@
[x] create lib directory for code that becomes a lib
[x] configure vite to output multiple entry files (one for web and one for the ide's)
[x] export events in package.json or from lib
[ ] remove inline styles
[ ] remove inline styles?
[x] vscode select text, click new chat the selected code should be in the chat
[ ] add debug? https://www.npmjs.com/package/debug
Loading
Loading