Merge branch 'main' into main
This commit is contained in:
@@ -162,6 +162,31 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
|
||||
<div className="i-ph:terminal" />
|
||||
Toggle Terminal
|
||||
</PanelHeaderButton>
|
||||
<PanelHeaderButton
|
||||
className="mr-1 text-sm"
|
||||
onClick={() => {
|
||||
const repoName = prompt("Please enter a name for your new GitHub repository:", "bolt-generated-project");
|
||||
if (!repoName) {
|
||||
alert("Repository name is required. Push to GitHub cancelled.");
|
||||
return;
|
||||
}
|
||||
const githubUsername = prompt("Please enter your GitHub username:");
|
||||
if (!githubUsername) {
|
||||
alert("GitHub username is required. Push to GitHub cancelled.");
|
||||
return;
|
||||
}
|
||||
const githubToken = prompt("Please enter your GitHub personal access token:");
|
||||
if (!githubToken) {
|
||||
alert("GitHub token is required. Push to GitHub cancelled.");
|
||||
return;
|
||||
}
|
||||
|
||||
workbenchStore.pushToGitHub(repoName, githubUsername, githubToken);
|
||||
}}
|
||||
>
|
||||
<div className="i-ph:github-logo" />
|
||||
Push to GitHub
|
||||
</PanelHeaderButton>
|
||||
</>
|
||||
)}
|
||||
<IconButton
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// see https://docs.anthropic.com/en/docs/about-claude/models
|
||||
export const MAX_TOKENS = 8192;
|
||||
export const MAX_TOKENS = 8000;
|
||||
|
||||
// limits the number of model responses that can be returned in a single request
|
||||
export const MAX_RESPONSE_SEGMENTS = 2;
|
||||
|
||||
@@ -29,7 +29,32 @@ You are Bolt, an expert AI assistant and exceptional senior software developer w
|
||||
|
||||
IMPORTANT: When choosing databases or npm packages, prefer options that don't rely on native binaries. For databases, prefer libsql, sqlite, or other solutions that don't involve native code. WebContainer CANNOT execute arbitrary native binaries.
|
||||
|
||||
Available shell commands: cat, chmod, cp, echo, hostname, kill, ln, ls, mkdir, mv, ps, pwd, rm, rmdir, xxd, alias, cd, clear, curl, env, false, getconf, head, sort, tail, touch, true, uptime, which, code, jq, loadenv, node, python3, wasm, xdg-open, command, exit, export, source
|
||||
Available shell commands:
|
||||
File Operations:
|
||||
- cat: Display file contents
|
||||
- cp: Copy files/directories
|
||||
- ls: List directory contents
|
||||
- mkdir: Create directory
|
||||
- mv: Move/rename files
|
||||
- rm: Remove files
|
||||
- rmdir: Remove empty directories
|
||||
- touch: Create empty file/update timestamp
|
||||
|
||||
System Information:
|
||||
- hostname: Show system name
|
||||
- ps: Display running processes
|
||||
- pwd: Print working directory
|
||||
- uptime: Show system uptime
|
||||
- env: Environment variables
|
||||
|
||||
Development Tools:
|
||||
- node: Execute Node.js code
|
||||
- python3: Run Python scripts
|
||||
- code: VSCode operations
|
||||
- jq: Process JSON
|
||||
|
||||
Other Utilities:
|
||||
- curl, head, sort, tail, clear, which, export, chmod, scho, hostname, kill, ln, xxd, alias, false, getconf, true, loadenv, wasm, xdg-open, command, exit, source
|
||||
</system_constraints>
|
||||
|
||||
<code_formatting_info>
|
||||
@@ -84,6 +109,36 @@ You are Bolt, an expert AI assistant and exceptional senior software developer w
|
||||
</${MODIFICATIONS_TAG_NAME}>
|
||||
</diff_spec>
|
||||
|
||||
<chain_of_thought_instructions>
|
||||
Before providing a solution, BRIEFLY outline your implementation steps. This helps ensure systematic thinking and clear communication. Your planning should:
|
||||
- List concrete steps you'll take
|
||||
- Identify key components needed
|
||||
- Note potential challenges
|
||||
- Be concise (2-4 lines maximum)
|
||||
|
||||
Example responses:
|
||||
|
||||
User: "Create a todo list app with local storage"
|
||||
Assistant: "Sure. I'll start by:
|
||||
1. Set up Vite + React
|
||||
2. Create TodoList and TodoItem components
|
||||
3. Implement localStorage for persistence
|
||||
4. Add CRUD operations
|
||||
|
||||
Let's start now.
|
||||
|
||||
[Rest of response...]"
|
||||
|
||||
User: "Help debug why my API calls aren't working"
|
||||
Assistant: "Great. My first steps will be:
|
||||
1. Check network requests
|
||||
2. Verify API endpoint format
|
||||
3. Examine error handling
|
||||
|
||||
[Rest of response...]"
|
||||
|
||||
</chain_of_thought_instructions>
|
||||
|
||||
<artifact_info>
|
||||
Bolt creates a SINGLE, comprehensive artifact for each project. The artifact contains all necessary steps and components, including:
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import { PreviewsStore } from './previews';
|
||||
import { TerminalStore } from './terminal';
|
||||
import JSZip from 'jszip';
|
||||
import { saveAs } from 'file-saver';
|
||||
import { Octokit } from "@octokit/rest";
|
||||
|
||||
export interface ArtifactState {
|
||||
id: string;
|
||||
@@ -333,6 +334,111 @@ export class WorkbenchStore {
|
||||
|
||||
return syncedFiles;
|
||||
}
|
||||
|
||||
async pushToGitHub(repoName: string, githubUsername: string, ghToken: string) {
|
||||
|
||||
try {
|
||||
// Get the GitHub auth token from environment variables
|
||||
const githubToken = ghToken;
|
||||
|
||||
const owner = githubUsername;
|
||||
|
||||
if (!githubToken) {
|
||||
throw new Error('GitHub token is not set in environment variables');
|
||||
}
|
||||
|
||||
// Initialize Octokit with the auth token
|
||||
const octokit = new Octokit({ auth: githubToken });
|
||||
|
||||
// Check if the repository already exists before creating it
|
||||
let repo
|
||||
try {
|
||||
repo = await octokit.repos.get({ owner: owner, repo: repoName });
|
||||
} catch (error) {
|
||||
if (error instanceof Error && 'status' in error && error.status === 404) {
|
||||
// Repository doesn't exist, so create a new one
|
||||
const { data: newRepo } = await octokit.repos.createForAuthenticatedUser({
|
||||
name: repoName,
|
||||
private: false,
|
||||
auto_init: true,
|
||||
});
|
||||
repo = newRepo;
|
||||
} else {
|
||||
console.log('cannot create repo!');
|
||||
throw error; // Some other error occurred
|
||||
}
|
||||
}
|
||||
|
||||
// Get all files
|
||||
const files = this.files.get();
|
||||
if (!files || Object.keys(files).length === 0) {
|
||||
throw new Error('No files found to push');
|
||||
}
|
||||
|
||||
// Create blobs for each file
|
||||
const blobs = await Promise.all(
|
||||
Object.entries(files).map(async ([filePath, dirent]) => {
|
||||
if (dirent?.type === 'file' && dirent.content) {
|
||||
const { data: blob } = await octokit.git.createBlob({
|
||||
owner: repo.owner.login,
|
||||
repo: repo.name,
|
||||
content: Buffer.from(dirent.content).toString('base64'),
|
||||
encoding: 'base64',
|
||||
});
|
||||
return { path: filePath.replace(/^\/home\/project\//, ''), sha: blob.sha };
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
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,
|
||||
repo: repo.name,
|
||||
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,
|
||||
repo: repo.name,
|
||||
base_tree: latestCommitSha,
|
||||
tree: validBlobs.map((blob) => ({
|
||||
path: blob!.path,
|
||||
mode: '100644',
|
||||
type: 'blob',
|
||||
sha: blob!.sha,
|
||||
})),
|
||||
});
|
||||
|
||||
// Create a new commit
|
||||
const { data: newCommit } = await octokit.git.createCommit({
|
||||
owner: repo.owner.login,
|
||||
repo: repo.name,
|
||||
message: 'Initial commit from your app',
|
||||
tree: newTree.sha,
|
||||
parents: [latestCommitSha],
|
||||
});
|
||||
|
||||
// Update the reference
|
||||
await octokit.git.updateRef({
|
||||
owner: repo.owner.login,
|
||||
repo: repo.name,
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const workbenchStore = new WorkbenchStore();
|
||||
|
||||
Reference in New Issue
Block a user