ai-code-writer
Version:
An AI code writer application using OpenAI APIs for audio transcription and chat completion.
54 lines (53 loc) • 2.48 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ActionEntity_1 = __importDefault(require("../../../../Core/ActionEntity"));
const FileActionType_1 = __importDefault(require("../../../../Core/FileActionType"));
const CommandActionType_1 = __importDefault(require("../../../../Core/CommandActionType"));
class ToolCallConverter {
constructor(logger) {
this.logger = logger;
this.fileActionMap = {
readFile: FileActionType_1.default.READ,
writeFile: FileActionType_1.default.WRITE,
deleteFile: FileActionType_1.default.DELETE,
moveFile: FileActionType_1.default.MOVE,
readAllFiles: FileActionType_1.default.READ_ALL_FILES
};
this.commandActionMap = {
pauseCommand: CommandActionType_1.default.PAUSE,
suspendCommand: CommandActionType_1.default.SUSPEND,
resumeCommand: CommandActionType_1.default.RESUME,
exitCommand: CommandActionType_1.default.EXIT_PROGRAMM
};
}
convert(toolCalls) {
return toolCalls.map(call => this.convertToFile(call));
}
convertToFile(call) {
var _a, _b, _c;
const action = new ActionEntity_1.default();
action.id = call.id || '';
const functionName = ((_a = call.function) === null || _a === void 0 ? void 0 : _a.name) || '';
action.name = functionName;
let callArguments = {};
try {
callArguments = JSON.parse(((_b = call.function) === null || _b === void 0 ? void 0 : _b.arguments) || '{}');
}
catch (_d) {
this.logger.logError('Unable to parse argument :' + ((_c = call.function) === null || _c === void 0 ? void 0 : _c.arguments));
}
action.filePath =
callArguments.filePath ||
callArguments.sourcePath ||
'';
action.targetFilePath = callArguments.destinationPath || '';
action.actionType = this.fileActionMap[functionName] !== undefined ? 'file' : 'command';
action.type = action.actionType == 'file' ? this.fileActionMap[functionName] : this.commandActionMap[functionName];
action.content = callArguments.content || callArguments.command || '';
return action;
}
}
exports.default = ToolCallConverter;
;