ai-code-writer
Version:
An AI code writer application using OpenAI APIs for audio transcription and chat completion.
57 lines (56 loc) • 1.67 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
class MessageEncoder {
constructor() {
this.argumentConverter = {
readFile: this.convertFilePathArguments.bind(this),
writeFile: this.convertPathAndContentArguments.bind(this),
deleteFile: this.convertFilePathArguments.bind(this),
moveFile: this.convertMoveArguments.bind(this)
};
}
encode(messages) {
return messages.map(m => this.encodeMessage(m));
}
encodeMessage(message) {
const result = {
role: message.role,
content: message.content
};
if (message.callId) {
result.tool_call_id = message.callId;
}
if (message.toolCalls.length > 0) {
result.tool_calls = message.toolCalls.map(tc => this.convertToolCall(tc));
}
return result;
}
convertToolCall(call) {
return {
type: 'function',
id: call.id,
function: {
name: call.name,
arguments: JSON.stringify((this.argumentConverter[call.name] || this.argumentConverter.readFile)(call))
}
};
}
convertPathAndContentArguments(call) {
return {
filePath: call.filePath,
content: call.content
};
}
convertFilePathArguments(call) {
return {
filePath: call.filePath
};
}
convertMoveArguments(call) {
return {
sourcePath: call.filePath,
destinationPath: call.targetFilePath
};
}
}
exports.default = MessageEncoder;
;