diff --git a/app/components/chat/Chat.client.tsx b/app/components/chat/Chat.client.tsx index 458bd8364..ee5554135 100644 --- a/app/components/chat/Chat.client.tsx +++ b/app/components/chat/Chat.client.tsx @@ -96,6 +96,65 @@ export const ChatImpl = memo(({ initialMessages, storeMessageHistory }: ChatProp const TEXTAREA_MAX_HEIGHT = chatStarted ? 400 : 200; + const addCustomFile = async () => { + const input = document.createElement('input'); + input.type = 'file'; + + input.onchange = async (e) => { + const file = e.target.files[0]; + const randomID = Math.random().toString(36).substring(2, 15); + const fileName = file.name; + + const content = await file.text(); + + const newMessage = { + id: randomID, + role: 'assistant', + content: `File Added: ${fileName} \n \n ${content}\n \n`, + createdAt: Date.now(), + }; + + messages.push(newMessage); + await storeMessageHistory(messages); + parseMessages(messages, false); + }; + + input.click(); + }; + workbenchStore.addCustomFile = addCustomFile; + + const addCustomFolder = async () => { + const input = document.createElement('input'); + input.type = 'file'; + input.webkitdirectory = true; + input.multiple = true; + + input.onchange = async (e) => { + const files = Array.from(e.target.files); + + for (const file of files) { + const randomID = Math.random().toString(36).substring(2, 15); + const fileName = file.name; + + const content = await file.text(); + + const newMessage = { + id: randomID, + role: 'assistant', + content: `File Added: ${fileName} \n \n ${content}\n \n`, + createdAt: Date.now(), + }; + + messages.push(newMessage); + await storeMessageHistory(messages); + parseMessages(messages, false); + } + }; + + input.click(); + }; + workbenchStore.addCustomFolder = addCustomFolder; + useEffect(() => { chatStore.setKey('started', initialMessages.length > 0); }, []); diff --git a/app/components/workbench/EditorPanel.tsx b/app/components/workbench/EditorPanel.tsx index d1a265a66..480301a4b 100644 --- a/app/components/workbench/EditorPanel.tsx +++ b/app/components/workbench/EditorPanel.tsx @@ -132,6 +132,24 @@ export const EditorPanel = memo(
Files + + + + + + { @@ -389,13 +389,13 @@ export class WorkbenchStore { } }) ); - + const validBlobs = blobs.filter(Boolean); // Filter out any undefined blobs - + if (validBlobs.length === 0) { throw new Error('No valid files to push'); } - + // Get the latest commit SHA (assuming main branch, update dynamically if needed) const { data: ref } = await octokit.git.getRef({ owner: repo.owner.login, @@ -403,7 +403,7 @@ export class WorkbenchStore { ref: `heads/${repo.default_branch || 'main'}`, // Handle dynamic branch }); const latestCommitSha = ref.object.sha; - + // Create a new tree const { data: newTree } = await octokit.git.createTree({ owner: repo.owner.login, @@ -416,7 +416,7 @@ export class WorkbenchStore { sha: blob!.sha, })), }); - + // Create a new commit const { data: newCommit } = await octokit.git.createCommit({ owner: repo.owner.login, @@ -425,7 +425,7 @@ export class WorkbenchStore { tree: newTree.sha, parents: [latestCommitSha], }); - + // Update the reference await octokit.git.updateRef({ owner: repo.owner.login, @@ -433,12 +433,20 @@ export class WorkbenchStore { ref: `heads/${repo.default_branch || 'main'}`, // Handle dynamic branch sha: newCommit.sha, }); - + alert(`Repository created and code pushed: ${repo.html_url}`); } catch (error) { console.error('Error pushing to GitHub:', error instanceof Error ? error.message : String(error)); } } + + addCustomFile: () => void = () => { + return; + }; + + addCustomFolder: () => void = () => { + return; + }; } export const workbenchStore = new WorkbenchStore();