mirror of
https://github.com/stackblitz/bolt.new
synced 2025-02-06 04:48:04 +00:00
added setup command
This commit is contained in:
parent
6c1ff871c4
commit
15ab5ba479
@ -7,6 +7,7 @@ import { BaseChat } from '~/components/chat/BaseChat';
|
|||||||
import { Chat } from '~/components/chat/Chat.client';
|
import { Chat } from '~/components/chat/Chat.client';
|
||||||
import { useGit } from '~/lib/hooks/useGit';
|
import { useGit } from '~/lib/hooks/useGit';
|
||||||
import { useChatHistory } from '~/lib/persistence';
|
import { useChatHistory } from '~/lib/persistence';
|
||||||
|
import { createCommandsMessage, detectProjectCommands } from '~/utils/projectCommands';
|
||||||
|
|
||||||
const IGNORE_PATTERNS = [
|
const IGNORE_PATTERNS = [
|
||||||
'node_modules/**',
|
'node_modules/**',
|
||||||
@ -49,39 +50,49 @@ export function GitUrlImport() {
|
|||||||
|
|
||||||
if (importChat) {
|
if (importChat) {
|
||||||
const filePaths = Object.keys(data).filter((filePath) => !ig.ignores(filePath));
|
const filePaths = Object.keys(data).filter((filePath) => !ig.ignores(filePath));
|
||||||
console.log(filePaths);
|
|
||||||
|
|
||||||
const textDecoder = new TextDecoder('utf-8');
|
const textDecoder = new TextDecoder('utf-8');
|
||||||
const message: Message = {
|
|
||||||
role: 'assistant',
|
// Convert files to common format for command detection
|
||||||
content: `Cloning the repo ${repoUrl} into ${workdir}
|
const fileContents = filePaths
|
||||||
<boltArtifact id="imported-files" title="Git Cloned Files" type="bundled" >
|
|
||||||
${filePaths
|
|
||||||
.map((filePath) => {
|
.map((filePath) => {
|
||||||
const { data: content, encoding } = data[filePath];
|
const { data: content, encoding } = data[filePath];
|
||||||
|
return {
|
||||||
if (encoding === 'utf8') {
|
path: filePath,
|
||||||
return `<boltAction type="file" filePath="${filePath}">
|
content: encoding === 'utf8' ? content : content instanceof Uint8Array ? textDecoder.decode(content) : '',
|
||||||
${content}
|
};
|
||||||
</boltAction>`;
|
|
||||||
} else if (content instanceof Uint8Array) {
|
|
||||||
return `<boltAction type="file" filePath="${filePath}">
|
|
||||||
${textDecoder.decode(content)}
|
|
||||||
</boltAction>`;
|
|
||||||
} else {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
.filter((f) => f.content);
|
||||||
|
|
||||||
|
// Detect and create commands message
|
||||||
|
const commands = await detectProjectCommands(fileContents);
|
||||||
|
const commandsMessage = createCommandsMessage(commands);
|
||||||
|
|
||||||
|
// Create files message
|
||||||
|
const filesMessage: Message = {
|
||||||
|
role: 'assistant',
|
||||||
|
content: `Cloning the repo ${repoUrl} into ${workdir}
|
||||||
|
<boltArtifact id="imported-files" title="Git Cloned Files" type="bundled">
|
||||||
|
${fileContents
|
||||||
|
.map(
|
||||||
|
(file) =>
|
||||||
|
`<boltAction type="file" filePath="${file.path}">
|
||||||
|
${file.content}
|
||||||
|
</boltAction>`,
|
||||||
|
)
|
||||||
.join('\n')}
|
.join('\n')}
|
||||||
</boltArtifact>`,
|
</boltArtifact>`,
|
||||||
id: generateId(),
|
id: generateId(),
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
};
|
};
|
||||||
console.log(JSON.stringify(message));
|
|
||||||
|
|
||||||
importChat(`Git Project:${repoUrl.split('/').slice(-1)[0]}`, [message]);
|
const messages = [filesMessage];
|
||||||
|
|
||||||
// console.log(files);
|
if (commandsMessage) {
|
||||||
|
messages.push(commandsMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
await importChat(`Git Project:${repoUrl.split('/').slice(-1)[0]}`, messages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user