ai-code-writer
Version:
An AI code writer application using OpenAI APIs for audio transcription and chat completion.
46 lines (45 loc) • 2.03 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
class FileActionUseCase {
constructor(actionHandler) {
this.actionHandler = actionHandler;
}
executeActions(actions) {
return __awaiter(this, void 0, void 0, function* () {
for (const action of actions) {
yield this.processAction(action);
}
});
}
processAction(action) {
return __awaiter(this, void 0, void 0, function* () {
const lines = action.split('\n');
const command = lines.shift();
if (!command)
return;
if (command.startsWith('<<<')) {
const filePath = command.slice(3).trim();
const content = lines.join('\n');
yield this.actionHandler.handleWriteFile(filePath, content);
}
else if (command.startsWith('>>>')) {
const [source, destination] = command.slice(3).trim().split(/\s+/);
yield this.actionHandler.handleMoveFile(source, destination);
}
else if (command.startsWith('---')) {
const filePath = command.slice(3).trim();
yield this.actionHandler.handleDeleteFile(filePath);
}
});
}
}
exports.default = FileActionUseCase;
;