mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
Fix naming conventions
This commit is contained in:
parent
3d7c885584
commit
9993bf1640
@ -1,6 +1,6 @@
|
||||
import { stripIndents } from '~/utils/stripIndent';
|
||||
|
||||
export const DeveloperSystemPrompt = `
|
||||
export const developerSystemPrompt = `
|
||||
You are Nut, an expert AI assistant and exceptional senior software developer with vast knowledge across multiple programming languages, frameworks, and best practices.
|
||||
|
||||
For all designs you produce, make them beautiful and modern.
|
||||
|
@ -24,10 +24,10 @@ export class ChatMessageTelemetry {
|
||||
constructor(numMessages: number) {
|
||||
this.id = Math.random().toString(36).substring(2, 15);
|
||||
this.numMessages = numMessages;
|
||||
this.ping('StartMessage');
|
||||
this._ping('StartMessage');
|
||||
}
|
||||
|
||||
private ping(event: string, data: any = {}) {
|
||||
private _ping(event: string, data: any = {}) {
|
||||
pingTelemetry(event, {
|
||||
...data,
|
||||
loginKey: getNutLoginKey(),
|
||||
@ -37,22 +37,22 @@ export class ChatMessageTelemetry {
|
||||
}
|
||||
|
||||
finish() {
|
||||
this.ping('FinishMessage');
|
||||
this._ping('FinishMessage');
|
||||
}
|
||||
|
||||
abort(reason: string) {
|
||||
this.ping('AbortMessage', { reason });
|
||||
this._ping('AbortMessage', { reason });
|
||||
}
|
||||
|
||||
startSimulation() {
|
||||
this.ping('StartSimulation');
|
||||
this._ping('StartSimulation');
|
||||
}
|
||||
|
||||
endSimulation(status: string) {
|
||||
this.ping('EndSimulation', { status });
|
||||
this._ping('EndSimulation', { status });
|
||||
}
|
||||
|
||||
sendPrompt(simulationStatus: string) {
|
||||
this.ping('SendPrompt', { simulationStatus });
|
||||
this._ping('SendPrompt', { simulationStatus });
|
||||
}
|
||||
}
|
||||
|
@ -366,22 +366,22 @@ function addRecordingMessageHandler(messageHandlerId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
const IDBFactoryMethods = {
|
||||
const idbFactoryMethods = {
|
||||
_name: 'IDBFactory',
|
||||
open: (v: any) => createFunctionProxy(v, 'open'),
|
||||
};
|
||||
|
||||
const IDBOpenDBRequestMethods = {
|
||||
const idbOpenDBRequestMethods = {
|
||||
_name: 'IDBOpenDBRequest',
|
||||
result: createProxy,
|
||||
};
|
||||
|
||||
const IDBDatabaseMethods = {
|
||||
const idbDatabaseMethods = {
|
||||
_name: 'IDBDatabase',
|
||||
transaction: (v: any) => createFunctionProxy(v, 'transaction'),
|
||||
};
|
||||
|
||||
const IDBTransactionMethods = {
|
||||
const idbTransactionMethods = {
|
||||
_name: 'IDBTransaction',
|
||||
objectStore: (v: any) => createFunctionProxy(v, 'objectStore'),
|
||||
};
|
||||
@ -400,7 +400,7 @@ function addRecordingMessageHandler(messageHandlerId: string) {
|
||||
// Map "get" requests to their keys.
|
||||
const getRequestKeys: Map<IDBRequest, any> = new Map();
|
||||
|
||||
const IDBObjectStoreMethods = {
|
||||
const idbObjectStoreMethods = {
|
||||
_name: 'IDBObjectStore',
|
||||
get: (v: any) =>
|
||||
createFunctionProxy(v, 'get', (request, key) => {
|
||||
@ -420,7 +420,7 @@ function addRecordingMessageHandler(messageHandlerId: string) {
|
||||
}),
|
||||
};
|
||||
|
||||
const IDBRequestMethods = {
|
||||
const idbRequestMethods = {
|
||||
_name: 'IDBRequest',
|
||||
result: (value: any, target: any) => {
|
||||
const key = getRequestKeys.get(target);
|
||||
@ -437,7 +437,7 @@ function addRecordingMessageHandler(messageHandlerId: string) {
|
||||
addLocalStorageAccess({ kind, key, value });
|
||||
}
|
||||
|
||||
const StorageMethods = {
|
||||
const storageMethods = {
|
||||
_name: 'Storage',
|
||||
getItem: (v: any) =>
|
||||
createFunctionProxy(v, 'getItem', (value: string, key: string) => {
|
||||
@ -462,7 +462,7 @@ function addRecordingMessageHandler(messageHandlerId: string) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const ResponseMethods = {
|
||||
const responseMethods = {
|
||||
_name: 'Response',
|
||||
json: (v: any, response: Response) =>
|
||||
createFunctionProxy(v, 'json', async (promise: Promise<any>) => {
|
||||
@ -492,21 +492,21 @@ function addRecordingMessageHandler(messageHandlerId: string) {
|
||||
let methods;
|
||||
|
||||
if (obj instanceof IDBFactory) {
|
||||
methods = IDBFactoryMethods;
|
||||
methods = idbFactoryMethods;
|
||||
} else if (obj instanceof IDBOpenDBRequest) {
|
||||
methods = IDBOpenDBRequestMethods;
|
||||
methods = idbOpenDBRequestMethods;
|
||||
} else if (obj instanceof IDBDatabase) {
|
||||
methods = IDBDatabaseMethods;
|
||||
methods = idbDatabaseMethods;
|
||||
} else if (obj instanceof IDBTransaction) {
|
||||
methods = IDBTransactionMethods;
|
||||
methods = idbTransactionMethods;
|
||||
} else if (obj instanceof IDBObjectStore) {
|
||||
methods = IDBObjectStoreMethods;
|
||||
methods = idbObjectStoreMethods;
|
||||
} else if (obj instanceof IDBRequest) {
|
||||
methods = IDBRequestMethods;
|
||||
methods = idbRequestMethods;
|
||||
} else if (obj instanceof Storage) {
|
||||
methods = StorageMethods;
|
||||
methods = storageMethods;
|
||||
} else if (obj instanceof Response) {
|
||||
methods = ResponseMethods;
|
||||
methods = responseMethods;
|
||||
}
|
||||
|
||||
assert(methods, 'Unknown object for createProxy');
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Data structures for simulation.
|
||||
|
||||
export const SimulationDataVersion = '0.1';
|
||||
export const simulationDataVersion = '0.1';
|
||||
|
||||
// Simulation data specifying the server URL to connect to for static resources.
|
||||
interface SimulationPacketServerURL {
|
||||
|
@ -5,12 +5,12 @@
|
||||
|
||||
import type { Message } from 'ai';
|
||||
import type { SimulationData, SimulationPacket } from './SimulationData';
|
||||
import { SimulationDataVersion } from './SimulationData';
|
||||
import { simulationDataVersion } from './SimulationData';
|
||||
import { assert, generateRandomId, ProtocolClient } from './ReplayProtocolClient';
|
||||
import type { MouseData } from './Recording';
|
||||
import type { FileMap } from '~/lib/stores/files';
|
||||
import { shouldIncludeFile } from '~/utils/fileUtils';
|
||||
import { DeveloperSystemPrompt } from '~/lib/common/prompts/prompts';
|
||||
import { developerSystemPrompt } from '~/lib/common/prompts/prompts';
|
||||
import { detectProjectCommands } from '~/utils/projectCommands';
|
||||
|
||||
function createRepositoryContentsPacket(contents: string): SimulationPacket {
|
||||
@ -105,7 +105,7 @@ class ChatManager {
|
||||
method: 'Nut.addSimulation',
|
||||
params: {
|
||||
chatId,
|
||||
version: SimulationDataVersion,
|
||||
version: simulationDataVersion,
|
||||
simulationData: [packet],
|
||||
completeData: false,
|
||||
saveRecording: true,
|
||||
@ -315,7 +315,7 @@ export function getLastSimulationChatMessages(): ProtocolMessage[] | undefined {
|
||||
return gLastSimulationChatMessages;
|
||||
}
|
||||
|
||||
const SimulationSystemPrompt = `
|
||||
const simulationSystemPrompt = `
|
||||
The following user message describes a bug or other problem on the page which needs to be fixed.
|
||||
You must respond with a useful explanation that will help the user understand the source of the problem.
|
||||
Do not describe the specific fix needed.
|
||||
@ -329,7 +329,7 @@ export async function getSimulationEnhancedPrompt(
|
||||
assert(gChatManager, 'Chat not started');
|
||||
assert(gChatManager.simulationFinished, 'Simulation not finished');
|
||||
|
||||
let system = SimulationSystemPrompt;
|
||||
let system = simulationSystemPrompt;
|
||||
|
||||
if (mouseData) {
|
||||
system += `The user pointed to an element on the page <element selector=${JSON.stringify(mouseData.selector)} height=${mouseData.height} width=${mouseData.width} x=${mouseData.x} y=${mouseData.y} />`;
|
||||
@ -413,24 +413,24 @@ function getProtocolRule(message: Message): 'user' | 'assistant' | 'system' {
|
||||
}
|
||||
|
||||
function removeBoltArtifacts(text: string): string {
|
||||
const OpenTag = '<boltArtifact';
|
||||
const CloseTag = '</boltArtifact>';
|
||||
const openTag = '<boltArtifact';
|
||||
const closeTag = '</boltArtifact>';
|
||||
|
||||
while (true) {
|
||||
const openTag = text.indexOf(OpenTag);
|
||||
const openTagIndex = text.indexOf(openTag);
|
||||
|
||||
if (openTag === -1) {
|
||||
if (openTagIndex === -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
const prefix = text.substring(0, openTag);
|
||||
const prefix = text.substring(0, openTagIndex);
|
||||
|
||||
const closeTag = text.indexOf(CloseTag, openTag + OpenTag.length);
|
||||
const closeTagIndex = text.indexOf(closeTag, openTagIndex + openTag.length);
|
||||
|
||||
if (closeTag === -1) {
|
||||
if (closeTagIndex === -1) {
|
||||
text = prefix;
|
||||
} else {
|
||||
text = prefix + text.substring(closeTag + CloseTag.length);
|
||||
text = prefix + text.substring(closeTagIndex + closeTag.length);
|
||||
}
|
||||
}
|
||||
|
||||
@ -500,7 +500,7 @@ export async function sendDeveloperChatMessage(
|
||||
protocolMessages.unshift({
|
||||
role: 'system',
|
||||
type: 'text',
|
||||
content: DeveloperSystemPrompt,
|
||||
content: developerSystemPrompt,
|
||||
});
|
||||
|
||||
return gChatManager.sendChatMessage(protocolMessages, { chatOnly: true, developerFiles, onResponsePart });
|
||||
|
@ -54,7 +54,7 @@ export class WorkbenchStore {
|
||||
artifactIdList: string[] = [];
|
||||
#globalExecutionQueue = Promise.resolve();
|
||||
|
||||
private fileMap: FileMap = {};
|
||||
private _fileMap: FileMap = {};
|
||||
|
||||
constructor() {
|
||||
if (import.meta.hot) {
|
||||
@ -342,7 +342,7 @@ export class WorkbenchStore {
|
||||
const wc = await webcontainer;
|
||||
const fullPath = nodePath.join(wc.workdir, data.action.filePath);
|
||||
|
||||
this.fileMap[fullPath] = {
|
||||
this._fileMap[fullPath] = {
|
||||
type: 'file',
|
||||
content: data.action.content,
|
||||
isBinary: false,
|
||||
@ -382,9 +382,9 @@ export class WorkbenchStore {
|
||||
return artifacts[id];
|
||||
}
|
||||
|
||||
private async generateZip() {
|
||||
private async _generateZip() {
|
||||
const zip = new JSZip();
|
||||
const files = this.fileMap;
|
||||
const files = this._fileMap;
|
||||
|
||||
// Get the project name from the description input, or use a default name
|
||||
const projectName = (description.value ?? 'project').toLocaleLowerCase().split(' ').join('_');
|
||||
@ -423,12 +423,12 @@ export class WorkbenchStore {
|
||||
}
|
||||
|
||||
async downloadZip() {
|
||||
const { content, uniqueProjectName } = await this.generateZip();
|
||||
const { content, uniqueProjectName } = await this._generateZip();
|
||||
saveAs(content, `${uniqueProjectName}.zip`);
|
||||
}
|
||||
|
||||
async generateZipBase64() {
|
||||
const { content, uniqueProjectName } = await this.generateZip();
|
||||
const { content, uniqueProjectName } = await this._generateZip();
|
||||
const buf = await content.arrayBuffer();
|
||||
const contentBase64 = uint8ArrayToBase64(new Uint8Array(buf));
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
export const anthropicApiKeyCookieName = 'anthropicApiKey';
|
||||
export const anthropicNumFreeUsesCookieName = 'anthropicNumFreeUses';
|
||||
export const MaxFreeUses = 5;
|
||||
export const maxFreeUses = 5;
|
||||
|
Loading…
Reference in New Issue
Block a user