feat: cài đặt tính năng AI cho để prompt

This commit is contained in:
2026-07-21 19:48:35 +07:00
parent 9de9ae965f
commit bbc42c630e
6 changed files with 853 additions and 12 deletions
+55 -1
View File
@@ -129,6 +129,32 @@ const AIGateway = (function() {
];
}
function buildAIPromptContext(dawState) {
const tracks = (dawState.tracks || []).map(t => ({
id: t.id,
name: t.name,
type: t.buffer ? 'audio' : 'empty',
hasBuffer: !!t.buffer,
clipsCount: t.clips ? t.clips.length : (t.buffer ? 1 : 0),
muted: t.muted,
solo: t.solo,
volumeDb: t.volumeDb ?? 0,
pan: t.pan ?? 0
}));
return {
tempo: dawState.bpm || 120,
timeSignature: '4/4',
selectedTrackId: dawState.selectedTrackId || null,
playheadPosition: dawState.currentTime || 0,
selection: (dawState.selLeft !== null && dawState.selRight !== null && dawState.selRight > dawState.selLeft) ? {
start: parseFloat(dawState.selLeft.toFixed(3)),
end: parseFloat(dawState.selRight.toFixed(3)),
length: parseFloat((dawState.selRight - dawState.selLeft).toFixed(3))
} : null,
tracks
};
}
async function executePrompt({ prompt, provider, model, apiKey, baseUrl, dawContext, tools }) {
const messages = buildUserMessage(prompt, dawContext);
const toolList = tools || DEFAULT_TOOLS;
@@ -155,12 +181,40 @@ const AIGateway = (function() {
};
}
async function createMidiItem(args) {
return fetch('/api/audio_editor', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'add_midi', ...args })
}).then(r => r.json());
}
async function modifyMidiNotes(args) {
return fetch('/api/audio_editor', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'modify_midi_notes', ...args })
}).then(r => r.json());
}
async function processAIDSP(args) {
return fetch('/api/ai_dsp_engine', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'process_ai_dsp', ...args })
}).then(r => r.json());
}
return {
DEFAULT_TOOLS,
callLLM,
extractFunctionCalls,
buildUserMessage,
executePrompt
buildAIPromptContext,
executePrompt,
createMidiItem,
modifyMidiNotes,
processAIDSP
};
})();