Skip to content

Commit

Permalink
Fix Problems
Browse files Browse the repository at this point in the history
  • Loading branch information
ali00209 committed Oct 24, 2024
1 parent 6a5f6fd commit 01bef34
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 102 deletions.
73 changes: 73 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Version control
.git
.gitignore

# Node.js dependencies
node_modules

# Build outputs
dist
build
.cache

# Development and IDE files
.vscode
.idea
*.swp
*.swo

# Logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Testing
coverage

# Miscellaneous
.DS_Store
Thumbs.db

# Project specific
README.md
CONTRIBUTING.md
LICENSE
*.md

# Docker related
Dockerfile
docker-compose.yml
.dockerignore

# Temporary files
*.tmp
*.temp

# ESLint cache
.eslintcache

# TypeScript cache
*.tsbuildinfo

# Prettier cache
.prettier*

# Vitest coverage
coverage

# Remix specific
.cache
public/build

# Any other build artifacts or temporary files
*.bak
*.swp
*.swo
18 changes: 9 additions & 9 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"printWidth": 100,
"printWidth": 80,
"singleQuote": true,
"useTabs": false,
"tabWidth": 2,
"semi": true,
"bracketSpacing": true,
"trailingComma": "all",
"arrowParens": "always",
"trailingComma": "es5",
"arrowParens": "avoid",
"endOfLine": "lf",
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"jsxBracketSameLine": false,
"htmlWhitespaceSensitivity": "css",
"vueIndentScriptAndStyle": false,
"embeddedLanguageFormatting": "auto"
"quoteProps": "consistent",
"jsxSingleQuote": true,
"jsxBracketSameLine": true,
"htmlWhitespaceSensitivity": "strict",
"vueIndentScriptAndStyle": true,
"embeddedLanguageFormatting": "off"
}
1 change: 0 additions & 1 deletion app/components/sidebar/Menu.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { motion, type Variants } from 'framer-motion';
import { useCallback, useEffect, useRef, useState } from 'react';
import { toast } from 'react-toastify';
import { Dialog, DialogButton, DialogDescription, DialogRoot, DialogTitle } from '~/components/ui/Dialog';
import { IconButton } from '~/components/ui/IconButton';
import { ThemeSwitch } from '~/components/ui/ThemeSwitch';
import { db, deleteById, getAll, chatId, type ChatHistoryItem } from '~/lib/persistence';
import { cubicEasingFn } from '~/utils/easings';
Expand Down
3 changes: 2 additions & 1 deletion app/lib/stores/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ export class EditorStore {
}

const previousDocument = previousDocuments?.[filePath];
const fileContent = this.#filesStore.getFile(filePath)?.content;

return [
filePath,
{
value: dirent.content,
value: fileContent ?? dirent.content,
filePath,
scroll: previousDocument?.scroll,
},
Expand Down
9 changes: 9 additions & 0 deletions app/lib/stores/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,15 @@ export class FilesStore {
debounceFn.cancel();
}
}

async saveFile(filePath: string, content: string) {
const file = this.getFile(filePath);
if (!file || file.type !== 'file') {
throw new FileNotFoundError(filePath);
}

await this.setFileContent(filePath, content);
}
}

function isBinaryFile(buffer: Uint8Array | undefined): boolean {
Expand Down
72 changes: 32 additions & 40 deletions app/lib/stores/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,24 +336,21 @@ export class WorkbenchStore {
}

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
let repoData;
try {
repo = await octokit.repos.get({ owner: owner, repo: repoName });
const { data } = await octokit.repos.get({ owner, repo: repoName });
repoData = data;
} catch (error) {
if (error instanceof Error && 'status' in error && error.status === 404) {
// Repository doesn't exist, so create a new one
Expand All @@ -362,52 +359,49 @@ export class WorkbenchStore {
private: false,
auto_init: true,
});
repo = newRepo;
repoData = newRepo;
} else {
console.log('cannot create repo!');
throw error; // Some other error occurred
throw error;
}
}

// 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,
owner: repoData.owner.login,
repo: repoData.name,
content: Buffer.from(dirent.content).toString('base64'),
encoding: 'base64',
});
return { path: filePath.replace(/^\/home\/project\//, ''), sha: blob.sha };
}
return null;
})
);
const validBlobs = blobs.filter(Boolean); // Filter out any undefined blobs

const validBlobs = blobs.filter(Boolean);

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
owner: repoData.owner.login,
repo: repoData.name,
ref: `heads/${repoData.default_branch || 'main'}`,
});
const latestCommitSha = ref.object.sha;

// Create a new tree

const { data: newTree } = await octokit.git.createTree({
owner: repo.owner.login,
repo: repo.name,
owner: repoData.owner.login,
repo: repoData.name,
base_tree: latestCommitSha,
tree: validBlobs.map((blob) => ({
path: blob!.path,
Expand All @@ -416,25 +410,23 @@ export class WorkbenchStore {
sha: blob!.sha,
})),
});

// Create a new commit

const { data: newCommit } = await octokit.git.createCommit({
owner: repo.owner.login,
repo: repo.name,
owner: repoData.owner.login,
repo: repoData.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
owner: repoData.owner.login,
repo: repoData.name,
ref: `heads/${repoData.default_branch || 'main'}`,
sha: newCommit.sha,
});
alert(`Repository created and code pushed: ${repo.html_url}`);

alert(`Repository created and code pushed: ${repoData.html_url}`);
} catch (error) {
console.error('Error pushing to GitHub:', error instanceof Error ? error.message : String(error));
}
Expand Down
11 changes: 10 additions & 1 deletion app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ export const meta: MetaFunction = () => {
export const loader = () => json({});

export default function Index() {
// Define the model and setModel properties
const model = "defaultModel"; // Replace with your actual model
const setModel = (newModel: string) => {
console.log("Model set to:", newModel);
// Implement your logic to update the model
};

return (
<div className="flex flex-col h-full w-full">
<Header />
<ClientOnly fallback={<BaseChat />}>{() => <Chat />}</ClientOnly>
<ClientOnly fallback={<BaseChat model={model} setModel={setModel} />}>
{() => <Chat />}
</ClientOnly>
</div>
);
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"dependencies": {
"@ai-sdk/anthropic": "^0.0.39",
"@ai-sdk/google": "^0.0.52",
"@ai-sdk/openai": "^0.0.66",
"@ai-sdk/mistral": "^0.0.43",
"@ai-sdk/openai": "^0.0.66",
"@codemirror/autocomplete": "^6.17.0",
"@codemirror/commands": "^6.6.0",
"@codemirror/lang-cpp": "^6.0.2",
Expand Down Expand Up @@ -94,6 +94,7 @@
"@types/diff": "^5.2.1",
"@types/file-saver": "^2.0.7",
"@types/lodash": "^4.17.12",
"@types/node": "^22.7.9",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"fast-glob": "^3.3.2",
Expand Down
Loading

0 comments on commit 01bef34

Please sign in to comment.