feat(agent): v4.11.1 - branche entrées IA sur le FlowDeck Agent (Ask AI, AI meeting note, bouton flottant)
This commit is contained in:
@@ -135,6 +135,17 @@
|
||||
});
|
||||
this.fetchProviders();
|
||||
this.fetchAgents();
|
||||
|
||||
// Programmatic entry point used by the page editor ("Ask AI",
|
||||
// "AI meeting note") and any global UI: open the panel and run a prompt.
|
||||
window.fdAgent = window.fdAgent || {};
|
||||
window.fdAgent.ask = function(text){
|
||||
var t = (text || '').trim();
|
||||
if(!t) return;
|
||||
self.openAgent();
|
||||
self.input = t;
|
||||
setTimeout(function(){ self.send(); }, 60);
|
||||
};
|
||||
},
|
||||
|
||||
fetchProviders(){
|
||||
@@ -202,6 +213,30 @@
|
||||
self.messages = []; self.errorMsg=''; self.tab='chat';
|
||||
}).catch(function(){});
|
||||
},
|
||||
ensureConversation(){
|
||||
// Make the chat usable immediately: reuse the open conversation or
|
||||
// create one lazily so sending never silently no-ops (empty state).
|
||||
var self = this;
|
||||
if(self.currentConv && self.currentConv.id) return Promise.resolve(self.currentConv);
|
||||
if(self._ensuring) return self._ensuring;
|
||||
var body = {title:'New conversation'};
|
||||
if(self.llmProvider) body.provider = self.llmProvider;
|
||||
if(self.llmModel) body.model = self.llmModel;
|
||||
self._ensuring = fetch('/api/agent/conversations', {
|
||||
method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(body)
|
||||
}).then(function(r){return r.json()}).then(function(d){
|
||||
var conv = {id:d.id, title:d.title, updated_at:new Date().toISOString()};
|
||||
self.conversations.unshift(conv); self.currentConv = conv;
|
||||
self.messages = []; self.errorMsg=''; self.tab='chat';
|
||||
self._ensuring = null;
|
||||
return conv;
|
||||
}).catch(function(err){
|
||||
self._ensuring = null;
|
||||
self.errorMsg = (err && err.message) ? err.message : 'Impossible de créer la conversation';
|
||||
throw err;
|
||||
});
|
||||
return self._ensuring;
|
||||
},
|
||||
openAgent(){ this.open=true; this.loadConversations(); },
|
||||
close(){ this.open=false; },
|
||||
get commandOpen(){ return /^\s*\//.test(this.input) && !this.streaming; },
|
||||
@@ -292,12 +327,13 @@
|
||||
}
|
||||
return false;
|
||||
},
|
||||
send(){
|
||||
async send(){
|
||||
var self = this;
|
||||
if(!self.currentConv || self.streaming) return;
|
||||
var text = self.input.trim();
|
||||
if(self.streaming) return;
|
||||
var text = (self.input || '').trim();
|
||||
if(!text) return;
|
||||
if(self.commandOpen && self.handleCommand(text)){ self.input=''; return; }
|
||||
try { await self.ensureConversation(); } catch(e){ return; }
|
||||
self.input = '';
|
||||
self.errorMsg = '';
|
||||
self.streaming = true;
|
||||
@@ -340,6 +376,9 @@
|
||||
}
|
||||
else if(ev.type==='final'){
|
||||
self.messages.push({id:'f-'+Date.now(), role:'assistant', content: ev.content});
|
||||
// "Ask AI" / "AI meeting note" (page editor) register this hook
|
||||
// so the generated text is inserted directly into the page.
|
||||
if(window.__fdInsertAI){ try{ var h=window.__fdInsertAI; window.__fdInsertAI=null; h(ev.content||''); }catch(e){} }
|
||||
}
|
||||
else if(ev.type==='error'){ self.errorMsg = ev.message; }
|
||||
}catch(e){}
|
||||
|
||||
Reference in New Issue
Block a user