Merge branch 'main' into diff-view-v2

This commit is contained in:
Toddyclipsgg
2025-02-25 19:29:59 -03:00
committed by GitHub
19 changed files with 1580 additions and 658 deletions

View File

@@ -5,6 +5,7 @@ import type { ChatHistoryItem } from './useChatHistory';
export interface IChatMetadata {
gitUrl: string;
gitBranch?: string;
netlifySiteId?: string;
}
const logger = createScopedLogger('ChatHistory');

View File

@@ -70,6 +70,7 @@ export class ActionRunner {
runnerId = atom<string>(`${Date.now()}`);
actions: ActionsMap = map({});
onAlert?: (alert: ActionAlert) => void;
buildOutput?: { path: string; exitCode: number; output: string };
constructor(
webcontainerPromise: Promise<WebContainer>,
@@ -156,6 +157,13 @@ export class ActionRunner {
await this.#runFileAction(action);
break;
}
case 'build': {
const buildOutput = await this.#runBuildAction(action);
// Store build output for deployment
this.buildOutput = buildOutput;
break;
}
case 'start': {
// making the start app non blocking
@@ -299,6 +307,7 @@ export class ActionRunner {
logger.error('Failed to write file\n\n', error);
}
}
#updateAction(id: string, newState: ActionStateUpdate) {
const actions = this.actions.get();
@@ -331,4 +340,39 @@ export class ActionRunner {
#getHistoryPath(filePath: string) {
return nodePath.join('.history', filePath);
}
}
async #runBuildAction(action: ActionState) {
if (action.type !== 'build') {
unreachable('Expected build action');
}
const webcontainer = await this.#webcontainer;
// Create a new terminal specifically for the build
const buildProcess = await webcontainer.spawn('npm', ['run', 'build']);
let output = '';
buildProcess.output.pipeTo(
new WritableStream({
write(data) {
output += data;
},
}),
);
const exitCode = await buildProcess.exit;
if (exitCode !== 0) {
throw new ActionCommandError('Build Failed', output || 'No Output Available');
}
// Get the build output directory path
const buildDir = nodePath.join(webcontainer.workdir, 'dist');
return {
path: buildDir,
exitCode,
output,
};
}
}

63
app/lib/stores/netlify.ts Normal file
View File

@@ -0,0 +1,63 @@
import { atom } from 'nanostores';
import type { NetlifyConnection } from '~/types/netlify';
import { logStore } from './logs';
import { toast } from 'react-toastify';
// Initialize with stored connection or defaults
const storedConnection = typeof window !== 'undefined' ? localStorage.getItem('netlify_connection') : null;
const initialConnection: NetlifyConnection = storedConnection
? JSON.parse(storedConnection)
: {
user: null,
token: '',
stats: undefined,
};
export const netlifyConnection = atom<NetlifyConnection>(initialConnection);
export const isConnecting = atom<boolean>(false);
export const isFetchingStats = atom<boolean>(false);
export const updateNetlifyConnection = (updates: Partial<NetlifyConnection>) => {
const currentState = netlifyConnection.get();
const newState = { ...currentState, ...updates };
netlifyConnection.set(newState);
// Persist to localStorage
if (typeof window !== 'undefined') {
localStorage.setItem('netlify_connection', JSON.stringify(newState));
}
};
export async function fetchNetlifyStats(token: string) {
try {
isFetchingStats.set(true);
const sitesResponse = await fetch('https://api.netlify.com/api/v1/sites', {
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
});
if (!sitesResponse.ok) {
throw new Error(`Failed to fetch sites: ${sitesResponse.status}`);
}
const sites = (await sitesResponse.json()) as any;
const currentState = netlifyConnection.get();
updateNetlifyConnection({
...currentState,
stats: {
sites,
totalSites: sites.length,
},
});
} catch (error) {
console.error('Netlify API Error:', error);
logStore.logError('Failed to fetch Netlify stats', { error });
toast.error('Failed to fetch Netlify statistics');
} finally {
isFetchingStats.set(false);
}
}

View File

@@ -0,0 +1,3 @@
import { atom } from 'nanostores';
export const streamingState = atom<boolean>(false);