@fluxhub/fluxhub-lib 19.0.182 → 19.0.184

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35481,6 +35481,831 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImpo
35481
35481
  /** Estensioni con icona dedicata (set "square-o"). */
35482
35482
  const KNOWN_EXT = "3G2|3GA|3GP|7Z|AA|AAC|AC|ACCDB|ACCDT|ADN|AI|AIF|AIFC|AIFF|AIT|AMR|ANI|APK|APP|APPLESCRIPT|ASAX|ASC|ASCX|ASF|ASH|ASHX|ASMX|ASP|ASPX|ASX|AU|AUP|AVI|AXD|AZE|BAK|BASH|BAT|BIN|BLANK|BMP|BOWERRC|BPG|BROWSER|BZ2|C|CAB|CAD|CAF|CAL|CD|CER|CFG|CFM|CFML|CGI|CLASS|CMD|CODEKIT|COFFEE|COFFEELINTIGNORE|COM|COMPILE|CONF|CONFIG|CPP|CPTX|CR2|CRDOWNLOAD|CRT|CRYPT|CS|CSH|CSON|CSPROJ|CSS|CSV|CUE|DAT|DB|DBF|DEB|DGN|DIST|DIZ|DLL|DMG|DNG|DOC|DOCB|DOCM|DOCX|DOT|DOTM|DOTX|DOWNLOAD|DPJ|DS_STORE|DTD|DWG|DXF|EDITORCONFIG|EL|ENC|EOT|EPS|EPUB|ESLINTIGNORE|EXE|F4V|FAX|FB2|FLA|FLAC|FLV|FOLDER|GADGET|GDP|GEM|GIF|GITATTRIBUTES|GITIGNORE|GO|GPG|GZ|H|HANDLEBARS|HBS|HEIC|HS|HSL|HTM|HTML|IBOOKS|ICNS|ICO|ICS|IDX|IFF|IFO|IMAGE|IMG|IN|INDD|INF|INI|ISO|J2|JAR|JAVA|JPE|JPEG|JPG|JS|JSON|JSP|JSX|KEY|KF8|KMK|KSH|KUP|LESS|LEX|LICX|LISP|LIT|LNK|LOCK|LOG|LUA|M|M2V|M3U|M3U8|M4|M4A|M4R|M4V|MAP|MASTER|MC|MD|MDB|MDF|ME|MI|MID|MIDI|MK|MKV|MM|MO|MOBI|MOD|MOV|MP2|MP3|MP4|MPA|MPD|MPE|MPEG|MPG|MPGA|MPP|MPT|MSI|MSU|NEF|NES|NFO|NIX|NPMIGNORE|ODB|ODS|ODT|OGG|OGV|OST|OTF|OTT|OVA|OVF|P12|P7B|PAGES|PART|PCD|PDB|PDF|PEM|PFX|PGP|PH|PHAR|PHP|PKG|PL|PLIST|PM|PNG|PO|POM|POT|POTX|PPS|PPSX|PPT|PPTM|PPTX|PROP|PS|PS1|PSD|PSP|PST|PUB|PY|PYC|QT|RA|RAM|RAR|RAW|RB|RDF|RESX|RETRY|RM|ROM|RPM|RSA|RSS|RTF|RU|RUB|SASS|SCSS|SDF|SED|SH|SITEMAP|SKIN|SLDM|SLDX|SLN|SOL|SQL|SQLITE|STEP|STL|SVG|SWD|SWF|SWIFT|SYS|TAR|TCSH|TEX|TFIGNORE|TGA|TGZ|TIF|TIFF|TMP|TORRENT|TS|TSV|TTF|TWIG|TXT|UDF|VB|VBPROJ|VBS|VCD|VCS|VDI|VDX|VMDK|VOB|VSCODEIGNORE|VSD|VSS|VST|VSX|VTX|WAR|WAV|WBK|WEBINFO|WEBM|WEBP|WMA|WMF|WMV|WOFF|WOFF2|WPS|WSF|XAML|XCF|XLM|XLS|XLSM|XLSX|XLT|XLTM|XLTX|XML|XPI|XPS|XRB|XSD|XSL|XSPF|XZ|YAML|YML|Z|ZIP|ZSH";
35483
35483
 
35484
+ /**
35485
+ * Client del layer AI di FluxHub.
35486
+ *
35487
+ * Parla con un backend OpenAI-compatible (/v1/chat/completions o una route FluxHub
35488
+ * che fa da proxy verso il Cheshire Cat / Gemma). Supporta streaming SSE e risposta
35489
+ * singola. L'identita' utente viene inoltrata col JWT FluxHub: scoping e retrieval
35490
+ * sono enforced server-side (vedi architettura, sez. 10-11).
35491
+ *
35492
+ * Usa fetch() invece di HttpClient per gestire nativamente lo streaming SSE e per
35493
+ * avere pieno controllo sugli header (la chiamata AI puo' usare una chiave dedicata).
35494
+ */
35495
+ class FHAiService {
35496
+ appService;
35497
+ /** Path di default (relativo ad API_ENDPOINT) della route AI sul backend FluxHub. */
35498
+ defaultPath = "ai/chat";
35499
+ constructor(appService) {
35500
+ this.appService = appService;
35501
+ }
35502
+ /** Costruisce l'URL effettivo dell'endpoint. */
35503
+ resolveUrl(opts) {
35504
+ if (opts?.endpoint)
35505
+ return opts.endpoint;
35506
+ const base = this.appService.API_ENDPOINT || "";
35507
+ const path = opts?.path ?? this.defaultPath;
35508
+ return base + path;
35509
+ }
35510
+ /** Costruisce gli header (Content-Type, JWT FluxHub, API key AI, custom). */
35511
+ buildHeaders(opts) {
35512
+ const headers = { "Content-Type": "application/json" };
35513
+ if (opts?.forwardAuth !== false) {
35514
+ const token = localStorage.getItem(this.appService.COMPANY_KEY + "token");
35515
+ if (token && token !== "ZZ")
35516
+ headers["Authorization"] = `Bearer ${token}`;
35517
+ }
35518
+ if (opts?.apiKey)
35519
+ headers["x-api-key"] = opts.apiKey;
35520
+ if (opts?.headers)
35521
+ Object.assign(headers, opts.headers);
35522
+ return headers;
35523
+ }
35524
+ /** Corpo della richiesta (OpenAI-compatible). */
35525
+ buildBody(messages, stream, opts) {
35526
+ const body = {
35527
+ messages: messages
35528
+ .filter((m) => !m.loading)
35529
+ .map((m) => ({ role: m.role, content: m.content })),
35530
+ stream,
35531
+ };
35532
+ if (opts?.model)
35533
+ body.model = opts.model;
35534
+ // Contesto di scoping: inviato come metadata (il backend lo valida vs identita').
35535
+ if (opts?.context)
35536
+ body.metadata = { ...opts.context };
35537
+ return JSON.stringify(body);
35538
+ }
35539
+ /**
35540
+ * Conversazione in streaming. Emette un FHAiChunk per ogni delta di testo;
35541
+ * l'ultimo ha done=true ed eventuali sources.
35542
+ */
35543
+ chatStream(messages, opts) {
35544
+ const url = this.resolveUrl(opts);
35545
+ const headers = this.buildHeaders(opts);
35546
+ const body = this.buildBody(messages, true, opts);
35547
+ return new Observable((observer) => {
35548
+ const controller = new AbortController();
35549
+ let text = "";
35550
+ fetch(url, { method: "POST", headers, body, signal: controller.signal })
35551
+ .then(async (resp) => {
35552
+ if (!resp.ok || !resp.body) {
35553
+ throw new Error(`AI endpoint ${resp.status} ${resp.statusText}`);
35554
+ }
35555
+ const reader = resp.body.getReader();
35556
+ const decoder = new TextDecoder();
35557
+ let buffer = "";
35558
+ // eslint-disable-next-line no-constant-condition
35559
+ while (true) {
35560
+ const { done, value } = await reader.read();
35561
+ if (done)
35562
+ break;
35563
+ buffer += decoder.decode(value, { stream: true });
35564
+ // Le SSE sono separate da newline; ogni evento e' una riga "data: ..."
35565
+ const lines = buffer.split("\n");
35566
+ buffer = lines.pop() ?? "";
35567
+ for (const raw of lines) {
35568
+ const line = raw.trim();
35569
+ if (!line || !line.startsWith("data:"))
35570
+ continue;
35571
+ const payload = line.slice(5).trim();
35572
+ if (payload === "[DONE]") {
35573
+ observer.next({ delta: "", text, done: true });
35574
+ observer.complete();
35575
+ return;
35576
+ }
35577
+ const delta = this.extractDelta(payload);
35578
+ if (delta) {
35579
+ text += delta;
35580
+ observer.next({ delta, text, done: false });
35581
+ }
35582
+ }
35583
+ }
35584
+ // Stream chiuso senza [DONE]
35585
+ observer.next({ delta: "", text, done: true });
35586
+ observer.complete();
35587
+ })
35588
+ .catch((err) => {
35589
+ if (controller.signal.aborted)
35590
+ return;
35591
+ observer.error(err);
35592
+ });
35593
+ return () => controller.abort();
35594
+ });
35595
+ }
35596
+ /**
35597
+ * Conversazione non-streaming: risolve con il testo completo e le sorgenti.
35598
+ */
35599
+ chatOnce(messages, opts) {
35600
+ const url = this.resolveUrl(opts);
35601
+ const headers = this.buildHeaders(opts);
35602
+ const body = this.buildBody(messages, false, opts);
35603
+ return new Observable((observer) => {
35604
+ const controller = new AbortController();
35605
+ fetch(url, { method: "POST", headers, body, signal: controller.signal })
35606
+ .then(async (resp) => {
35607
+ if (!resp.ok)
35608
+ throw new Error(`AI endpoint ${resp.status} ${resp.statusText}`);
35609
+ const data = await resp.json();
35610
+ observer.next({
35611
+ content: this.extractContent(data),
35612
+ sources: this.extractSources(data),
35613
+ });
35614
+ observer.complete();
35615
+ })
35616
+ .catch((err) => {
35617
+ if (controller.signal.aborted)
35618
+ return;
35619
+ observer.error(err);
35620
+ });
35621
+ return () => controller.abort();
35622
+ });
35623
+ }
35624
+ // ---- Parsing flessibile (OpenAI / Cheshire Cat / shape semplice) ----
35625
+ /** Estrae il delta di testo da un evento SSE (OpenAI: choices[].delta.content). */
35626
+ extractDelta(payload) {
35627
+ try {
35628
+ const json = JSON.parse(payload);
35629
+ return (json?.choices?.[0]?.delta?.content ??
35630
+ json?.choices?.[0]?.text ??
35631
+ json?.delta ??
35632
+ json?.content ??
35633
+ "");
35634
+ }
35635
+ catch {
35636
+ // Backend che streamma testo grezzo riga per riga
35637
+ return payload;
35638
+ }
35639
+ }
35640
+ /** Estrae il testo completo dalla risposta non-streaming. */
35641
+ extractContent(data) {
35642
+ return (data?.choices?.[0]?.message?.content ??
35643
+ data?.choices?.[0]?.text ??
35644
+ data?.content ??
35645
+ data?.text ??
35646
+ data?.message ??
35647
+ "");
35648
+ }
35649
+ /** Estrae le sorgenti RAG (Cheshire Cat: why.memory.declarative; o sources/citations). */
35650
+ extractSources(data) {
35651
+ const declarative = data?.why?.memory?.declarative;
35652
+ if (Array.isArray(declarative) && declarative.length) {
35653
+ return declarative.map((d) => ({
35654
+ title: d?.metadata?.source ?? d?.metadata?.title ?? "Documento",
35655
+ snippet: d?.page_content ?? d?.content,
35656
+ score: d?.score,
35657
+ }));
35658
+ }
35659
+ const raw = data?.sources ?? data?.citations;
35660
+ if (Array.isArray(raw) && raw.length) {
35661
+ return raw.map((s) => ({
35662
+ title: s?.title ?? s?.source ?? "Documento",
35663
+ snippet: s?.snippet ?? s?.content,
35664
+ score: s?.score,
35665
+ url: s?.url,
35666
+ }));
35667
+ }
35668
+ return undefined;
35669
+ }
35670
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: FHAiService, deps: [{ token: AppService }], target: i0.ɵɵFactoryTarget.Injectable });
35671
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: FHAiService, providedIn: "root" });
35672
+ }
35673
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: FHAiService, decorators: [{
35674
+ type: Injectable,
35675
+ args: [{ providedIn: "root" }]
35676
+ }], ctorParameters: () => [{ type: AppService }] });
35677
+
35678
+ /**
35679
+ * Pannello chat AI riusabile di FluxHub.
35680
+ *
35681
+ * Conversazione con un backend OpenAI-compatible (proxy Prologika -> Cheshire Cat ->
35682
+ * Gemma) via FHAiService. Renderizza testo markdown, citazioni RAG, ha schermata di
35683
+ * benvenuto con suggerimenti e supporta streaming token-by-token.
35684
+ *
35685
+ * Tutto configurabile via @Input (endpoint, contesto azienda/ruolo, testi, tema) per
35686
+ * riuso cross-cliente, in linea con gli altri componenti standard della libreria.
35687
+ *
35688
+ * Esempio:
35689
+ * <FHAiChat [context]="{azienda:'Bormioli', ruolo:'sales'}"
35690
+ * [accent]="'#16afc7'"
35691
+ * welcomeTitle="Assistente Bormioli"></FHAiChat>
35692
+ */
35693
+ class FHAiChatComponent {
35694
+ ai;
35695
+ sanitizer;
35696
+ // ---- Tema ----
35697
+ accent = "#16afc7";
35698
+ accentDark = "#0e8ba0";
35699
+ get _a() { return this.accent; }
35700
+ get _ad() { return this.accentDark; }
35701
+ // ---- Header / testi ----
35702
+ showHeader = true;
35703
+ title = "Assistente AI";
35704
+ subtitle = "";
35705
+ tagLabel = "";
35706
+ welcomeTitle = "Come posso aiutarti?";
35707
+ welcomeSubtitle = "Fammi una domanda sui tuoi dati.";
35708
+ suggestions = [];
35709
+ placeholder = "Scrivi un messaggio...";
35710
+ showHint = true;
35711
+ // ---- Backend ----
35712
+ /** URL completo dell'endpoint AI. Se vuoto: AppService.API_ENDPOINT + path. */
35713
+ endpoint = "";
35714
+ /** Path relativo all'API_ENDPOINT (default route AI sul backend FluxHub). */
35715
+ path = "ai/chat";
35716
+ /** Modello da richiedere (di norma deciso lato server). */
35717
+ model = "";
35718
+ /** Abilita lo streaming token-by-token (SSE). */
35719
+ stream = true;
35720
+ /** API key del servizio AI (di norma NON serve lato browser). */
35721
+ apiKey = "";
35722
+ /** Inoltra il JWT FluxHub come Authorization Bearer. */
35723
+ forwardAuth = true;
35724
+ /** Contesto di scoping {azienda, ruolo, persona} (informativo + metadata). */
35725
+ context = null;
35726
+ /** Messaggio di sistema iniziale opzionale (di norma lo costruisce il backend). */
35727
+ systemPrompt = "";
35728
+ // ---- Output ----
35729
+ messageSent = new EventEmitter();
35730
+ responseReceived = new EventEmitter();
35731
+ errored = new EventEmitter();
35732
+ scroller;
35733
+ messages = [];
35734
+ userInput = "";
35735
+ busy = false;
35736
+ errorMsg = "";
35737
+ sub;
35738
+ constructor(ai, sanitizer) {
35739
+ this.ai = ai;
35740
+ this.sanitizer = sanitizer;
35741
+ }
35742
+ ngOnDestroy() {
35743
+ this.sub?.unsubscribe();
35744
+ }
35745
+ onKeyDown(ev) {
35746
+ if (ev.key === "Enter" && !ev.shiftKey) {
35747
+ ev.preventDefault();
35748
+ this.send();
35749
+ }
35750
+ }
35751
+ autoGrow(ta) {
35752
+ ta.style.height = "auto";
35753
+ ta.style.height = Math.min(ta.scrollHeight, 140) + "px";
35754
+ }
35755
+ sendSuggestion(text) {
35756
+ this.userInput = text;
35757
+ this.send();
35758
+ }
35759
+ send() {
35760
+ const text = this.userInput.trim();
35761
+ if (!text || this.busy)
35762
+ return;
35763
+ this.errorMsg = "";
35764
+ this.userInput = "";
35765
+ this.messageSent.emit(text);
35766
+ this.messages.push({ role: "user", content: text, ts: Date.now() });
35767
+ const botMsg = { role: "assistant", content: "", loading: true, ts: Date.now() };
35768
+ this.messages.push(botMsg);
35769
+ this.busy = true;
35770
+ this.scrollSoon();
35771
+ // Messaggi inviati: system (se presente) + storico (senza i placeholder)
35772
+ const payload = [];
35773
+ if (this.systemPrompt)
35774
+ payload.push({ role: "system", content: this.systemPrompt });
35775
+ payload.push(...this.messages.filter((m) => !m.loading));
35776
+ const opts = {
35777
+ endpoint: this.endpoint || undefined,
35778
+ path: this.path,
35779
+ model: this.model || undefined,
35780
+ stream: this.stream,
35781
+ apiKey: this.apiKey || undefined,
35782
+ forwardAuth: this.forwardAuth,
35783
+ context: this.context || undefined,
35784
+ };
35785
+ if (this.stream) {
35786
+ this.sub = this.ai.chatStream(payload, opts).subscribe({
35787
+ next: (chunk) => {
35788
+ botMsg.content = chunk.text;
35789
+ botMsg.loading = !chunk.done;
35790
+ if (chunk.sources)
35791
+ botMsg.sources = chunk.sources;
35792
+ this.scrollSoon();
35793
+ },
35794
+ error: (err) => this.fail(botMsg, err),
35795
+ complete: () => this.finish(botMsg),
35796
+ });
35797
+ }
35798
+ else {
35799
+ this.sub = this.ai.chatOnce(payload, opts).subscribe({
35800
+ next: (res) => {
35801
+ botMsg.content = res.content;
35802
+ botMsg.sources = res.sources;
35803
+ },
35804
+ error: (err) => this.fail(botMsg, err),
35805
+ complete: () => this.finish(botMsg),
35806
+ });
35807
+ }
35808
+ }
35809
+ stop() {
35810
+ this.sub?.unsubscribe();
35811
+ const last = this.messages[this.messages.length - 1];
35812
+ if (last && last.role === "assistant") {
35813
+ last.loading = false;
35814
+ if (!last.content)
35815
+ last.content = "_(interrotto)_";
35816
+ }
35817
+ this.busy = false;
35818
+ }
35819
+ clear() {
35820
+ this.sub?.unsubscribe();
35821
+ this.messages = [];
35822
+ this.busy = false;
35823
+ this.errorMsg = "";
35824
+ }
35825
+ finish(botMsg) {
35826
+ botMsg.loading = false;
35827
+ this.busy = false;
35828
+ this.responseReceived.emit(botMsg);
35829
+ this.scrollSoon();
35830
+ }
35831
+ fail(botMsg, err) {
35832
+ const msg = err?.message || "Errore di comunicazione con il servizio AI.";
35833
+ botMsg.loading = false;
35834
+ if (!botMsg.content) {
35835
+ // rimuovo il placeholder vuoto, mostro l'errore nella barra
35836
+ this.messages = this.messages.filter((m) => m !== botMsg);
35837
+ }
35838
+ this.errorMsg = msg;
35839
+ this.busy = false;
35840
+ this.errored.emit(msg);
35841
+ }
35842
+ scrollSoon() {
35843
+ setTimeout(() => {
35844
+ const el = this.scroller?.nativeElement;
35845
+ if (el)
35846
+ el.scrollTop = el.scrollHeight;
35847
+ }, 30);
35848
+ }
35849
+ /** Rende il markdown (sottoinsieme) in HTML sicuro: escape -> formattazione. */
35850
+ render(content) {
35851
+ return this.sanitizer.bypassSecurityTrustHtml(formatMarkdown(content));
35852
+ }
35853
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: FHAiChatComponent, deps: [{ token: FHAiService }, { token: i1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Component });
35854
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.17", type: FHAiChatComponent, isStandalone: true, selector: "FHAiChat", inputs: { accent: "accent", accentDark: "accentDark", showHeader: "showHeader", title: "title", subtitle: "subtitle", tagLabel: "tagLabel", welcomeTitle: "welcomeTitle", welcomeSubtitle: "welcomeSubtitle", suggestions: "suggestions", placeholder: "placeholder", showHint: "showHint", endpoint: "endpoint", path: "path", model: "model", stream: "stream", apiKey: "apiKey", forwardAuth: "forwardAuth", context: "context", systemPrompt: "systemPrompt" }, outputs: { messageSent: "messageSent", responseReceived: "responseReceived", errored: "errored" }, host: { properties: { "style.--fh-ai-accent": "this._a", "style.--fh-ai-accent-dark": "this._ad" } }, viewQueries: [{ propertyName: "scroller", first: true, predicate: ["scroller"], descendants: true }], ngImport: i0, template: `
35855
+ <div class="ai-chat">
35856
+ <!-- Header -->
35857
+ <div class="ai-head" *ngIf="showHeader">
35858
+ <div class="ai-head-left">
35859
+ <i class="material-symbols-outlined ai-head-icon">smart_toy</i>
35860
+ <div>
35861
+ <div class="ai-head-title">{{ title }}</div>
35862
+ <div class="ai-head-sub" *ngIf="subtitle">{{ subtitle }}</div>
35863
+ </div>
35864
+ </div>
35865
+ <div class="ai-head-right">
35866
+ <span class="ai-tag" *ngIf="tagLabel">{{ tagLabel }}</span>
35867
+ <button type="button" class="ai-icon-btn" *ngIf="messages.length > 0"
35868
+ title="Nuova conversazione" (click)="clear()">
35869
+ <i class="material-symbols-outlined">add</i>
35870
+ </button>
35871
+ </div>
35872
+ </div>
35873
+
35874
+ <!-- Messaggi -->
35875
+ <div class="ai-messages" #scroller>
35876
+ <!-- Welcome -->
35877
+ <div class="ai-welcome" *ngIf="messages.length === 0">
35878
+ <i class="material-symbols-outlined ai-welcome-icon">smart_toy</i>
35879
+ <div class="ai-welcome-title">{{ welcomeTitle }}</div>
35880
+ <div class="ai-welcome-sub">{{ welcomeSubtitle }}</div>
35881
+ <div class="ai-suggestions" *ngIf="suggestions?.length">
35882
+ <button type="button" class="ai-suggestion" *ngFor="let s of suggestions"
35883
+ (click)="sendSuggestion(s)">{{ s }}</button>
35884
+ </div>
35885
+ </div>
35886
+
35887
+ <div class="ai-msg" *ngFor="let m of messages"
35888
+ [class.ai-msg-user]="m.role === 'user'"
35889
+ [class.ai-msg-bot]="m.role === 'assistant'">
35890
+ <div class="ai-avatar">
35891
+ <i class="material-symbols-outlined">{{ m.role === 'user' ? 'person' : 'smart_toy' }}</i>
35892
+ </div>
35893
+ <div class="ai-bubble">
35894
+ <div class="ai-typing" *ngIf="m.loading && !m.content">
35895
+ <span></span><span></span><span></span>
35896
+ </div>
35897
+ <div class="ai-text" *ngIf="m.content" [innerHTML]="render(m.content)"></div>
35898
+
35899
+ <!-- Sorgenti RAG -->
35900
+ <div class="ai-sources" *ngIf="m.sources?.length">
35901
+ <div class="ai-sources-head">
35902
+ <i class="material-symbols-outlined">menu_book</i> Fonti
35903
+ </div>
35904
+ <div class="ai-source" *ngFor="let src of m.sources"
35905
+ [title]="src.snippet || ''">
35906
+ <i class="material-symbols-outlined">description</i>
35907
+ <span class="ai-source-title">{{ src.title }}</span>
35908
+ <span class="ai-source-score" *ngIf="src.score != null">{{ (src.score * 100) | number:'1.0-0' }}%</span>
35909
+ </div>
35910
+ </div>
35911
+ </div>
35912
+ </div>
35913
+ </div>
35914
+
35915
+ <!-- Errore -->
35916
+ <div class="ai-error" *ngIf="errorMsg">{{ errorMsg }}</div>
35917
+
35918
+ <!-- Input -->
35919
+ <div class="ai-input-area">
35920
+ <div class="ai-input-box" [class.focused]="false">
35921
+ <textarea #ta class="ai-input" rows="1"
35922
+ [(ngModel)]="userInput"
35923
+ [disabled]="busy"
35924
+ [placeholder]="placeholder"
35925
+ (keydown)="onKeyDown($event)"
35926
+ (input)="autoGrow(ta)"></textarea>
35927
+ <button type="button" class="ai-send" *ngIf="!busy"
35928
+ [disabled]="!userInput.trim()" (click)="send()" title="Invia">
35929
+ <i class="material-symbols-outlined">send</i>
35930
+ </button>
35931
+ <button type="button" class="ai-send ai-stop" *ngIf="busy" (click)="stop()" title="Interrompi">
35932
+ <i class="material-symbols-outlined">stop</i>
35933
+ </button>
35934
+ </div>
35935
+ <div class="ai-hint" *ngIf="showHint">Invio per inviare · Shift+Invio per andare a capo</div>
35936
+ </div>
35937
+ </div>
35938
+ `, isInline: true, styles: [":host{display:block;height:100%}.ai-chat{height:100%;box-sizing:border-box;display:flex;flex-direction:column;background:#fff;border:1px solid rgba(22,18,18,.1);border-radius:10px;overflow:hidden}.ai-head{flex:0 0 auto;display:flex;align-items:center;justify-content:space-between;padding:12px 16px;border-top:3px solid var(--fh-ai-accent, #16afc7);border-bottom:1px solid rgba(22,18,18,.07)}.ai-head-left{display:flex;align-items:center;gap:10px}.ai-head-icon{font-size:22px;color:var(--fh-ai-accent, #16afc7)}.ai-head-title{font-family:Plus Jakarta Sans,sans-serif;font-size:14px;font-weight:800;color:#161212}.ai-head-sub{font-family:Inter,sans-serif;font-size:11px;color:#8c8585;margin-top:1px}.ai-head-right{display:flex;align-items:center;gap:8px}.ai-tag{display:inline-block;padding:3px 10px;border-radius:999px;font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:.03em;background:#1612120f;color:#443d3d}.ai-icon-btn{display:flex;border:1px solid rgba(22,18,18,.12);background:transparent;border-radius:8px;width:30px;height:30px;align-items:center;justify-content:center;cursor:pointer;color:#5c5454}.ai-icon-btn:hover{background:#1612120d}.ai-icon-btn i{font-size:18px}.ai-messages{flex:1 1 auto;min-height:0;overflow-y:auto;overflow-x:hidden;padding:18px;display:flex;flex-direction:column;gap:14px;background:#f8fafc}.ai-welcome{margin:auto;display:flex;flex-direction:column;align-items:center;text-align:center;padding:20px;gap:6px}.ai-welcome-icon{font-size:40px;color:var(--fh-ai-accent, #16afc7)}.ai-welcome-title{font-family:Plus Jakarta Sans,sans-serif;font-size:16px;font-weight:700;color:#161212}.ai-welcome-sub{font-family:Inter,sans-serif;font-size:13px;color:#6b6363;margin-bottom:8px}.ai-suggestions{display:flex;flex-wrap:wrap;gap:8px;justify-content:center;max-width:560px}.ai-suggestion{padding:9px 14px;background:#fff;color:#443d3d;border:1px solid rgba(22,18,18,.12);border-radius:999px;font-family:Inter,sans-serif;font-size:12.5px;cursor:pointer;transition:all .15s ease}.ai-suggestion:hover{border-color:var(--fh-ai-accent, #16afc7);color:var(--fh-ai-accent-dark, #0e8ba0);background:#16afc70f}.ai-msg{display:flex;gap:10px;max-width:88%}.ai-msg-user{align-self:flex-end;flex-direction:row-reverse}.ai-msg-bot{align-self:flex-start}.ai-avatar{flex:0 0 auto;width:30px;height:30px;border-radius:8px;display:flex;align-items:center;justify-content:center}.ai-msg-user .ai-avatar{background:var(--fh-ai-accent, #16afc7);color:#fff}.ai-msg-bot .ai-avatar{background:#fff;color:var(--fh-ai-accent, #16afc7);border:1px solid rgba(22,175,199,.35)}.ai-avatar i{font-size:18px}.ai-bubble{padding:10px 14px;border-radius:12px;font-family:Inter,sans-serif;font-size:13.5px;line-height:1.6}.ai-msg-user .ai-bubble{background:var(--fh-ai-accent, #16afc7);color:#fff;border-bottom-right-radius:4px}.ai-msg-bot .ai-bubble{background:#fff;color:#1e293b;border:1px solid rgba(22,18,18,.1);border-bottom-left-radius:4px}.ai-text{word-wrap:break-word}.ai-text ::ng-deep p{margin:0 0 8px}.ai-text ::ng-deep p:last-child{margin-bottom:0}.ai-text ::ng-deep ul,.ai-text ::ng-deep ol{margin:4px 0 8px;padding-left:20px}.ai-text ::ng-deep li{margin-bottom:3px}.ai-text ::ng-deep code{background:#1612120f;padding:1px 5px;border-radius:4px;font-family:Cascadia Code,Fira Code,monospace;font-size:.85em}.ai-text ::ng-deep pre{background:#1e293b;color:#7dd3fc;padding:10px 12px;border-radius:8px;overflow-x:auto;margin:6px 0}.ai-text ::ng-deep pre code{background:transparent;padding:0;color:inherit}.ai-text ::ng-deep strong{font-weight:700}.ai-text ::ng-deep a{color:var(--fh-ai-accent-dark, #0e8ba0);text-decoration:underline}.ai-msg-user .ai-text ::ng-deep a{color:#fff}.ai-text ::ng-deep table{border-collapse:collapse;width:100%;margin:6px 0;font-size:.92em}.ai-text ::ng-deep th,.ai-text ::ng-deep td{border:1px solid rgba(22,18,18,.12);padding:5px 8px;text-align:left}.ai-text ::ng-deep th{background:#1612120a;font-weight:600}.ai-sources{margin-top:10px;border-top:1px dashed rgba(22,18,18,.12);padding-top:8px}.ai-sources-head{display:flex;align-items:center;gap:5px;font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.05em;color:#8c8585;margin-bottom:5px}.ai-sources-head i{font-size:14px}.ai-source{display:flex;align-items:center;gap:6px;font-size:12px;color:#5c5454;padding:2px 0}.ai-source i{font-size:15px;color:var(--fh-ai-accent, #16afc7);flex:0 0 auto}.ai-source-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ai-source-score{flex:0 0 auto;font-size:11px;font-weight:600;color:#a39b9b}.ai-typing{display:flex;gap:4px;padding:3px 0}.ai-typing span{width:7px;height:7px;border-radius:50%;background:#b9c2cc;animation:ai-typing 1.4s infinite}.ai-typing span:nth-child(2){animation-delay:.2s}.ai-typing span:nth-child(3){animation-delay:.4s}@keyframes ai-typing{0%,60%,to{transform:translateY(0);opacity:.4}30%{transform:translateY(-5px);opacity:1}}.ai-error{flex:0 0 auto;margin:0 18px;padding:8px 12px;background:#fef2f2;border:1px solid #fecaca;color:#dc2626;border-radius:8px;font-size:12.5px}.ai-input-area{flex:0 0 auto;padding:14px 16px;border-top:1px solid rgba(22,18,18,.07);background:#fff}.ai-input-box{display:flex;align-items:flex-end;gap:8px;background:#f1f5f9;border:1px solid rgba(22,18,18,.12);border-radius:12px;padding:4px;transition:border-color .15s ease,box-shadow .15s ease}.ai-input-box:focus-within{border-color:var(--fh-ai-accent, #16afc7);box-shadow:0 0 0 3px #16afc71f}.ai-input{flex:1 1 auto;background:transparent;border:none;outline:none;resize:none;font-family:Inter,sans-serif;font-size:13.5px;color:#1e293b;padding:9px 10px;max-height:140px;min-height:22px}.ai-input::placeholder{color:#a39b9b}.ai-send{flex:0 0 auto;width:38px;height:38px;display:flex;align-items:center;justify-content:center;border:none;border-radius:8px;cursor:pointer;color:#fff;background:linear-gradient(135deg,var(--fh-ai-accent, #16afc7) 0%,var(--fh-ai-accent-dark, #0e8ba0) 130%);transition:filter .15s ease}.ai-send:hover:not(:disabled){filter:brightness(1.07)}.ai-send:disabled{background:#cbd5e1;cursor:not-allowed}.ai-send i{font-size:19px}.ai-stop{background:#64748b}.ai-hint{text-align:center;font-size:10.5px;color:#a39b9b;margin-top:6px}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i5.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i5.DecimalPipe, name: "number" }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i5$1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i5$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i5$1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] });
35939
+ }
35940
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: FHAiChatComponent, decorators: [{
35941
+ type: Component,
35942
+ args: [{ selector: "FHAiChat", standalone: true, imports: [CommonModule, FormsModule], template: `
35943
+ <div class="ai-chat">
35944
+ <!-- Header -->
35945
+ <div class="ai-head" *ngIf="showHeader">
35946
+ <div class="ai-head-left">
35947
+ <i class="material-symbols-outlined ai-head-icon">smart_toy</i>
35948
+ <div>
35949
+ <div class="ai-head-title">{{ title }}</div>
35950
+ <div class="ai-head-sub" *ngIf="subtitle">{{ subtitle }}</div>
35951
+ </div>
35952
+ </div>
35953
+ <div class="ai-head-right">
35954
+ <span class="ai-tag" *ngIf="tagLabel">{{ tagLabel }}</span>
35955
+ <button type="button" class="ai-icon-btn" *ngIf="messages.length > 0"
35956
+ title="Nuova conversazione" (click)="clear()">
35957
+ <i class="material-symbols-outlined">add</i>
35958
+ </button>
35959
+ </div>
35960
+ </div>
35961
+
35962
+ <!-- Messaggi -->
35963
+ <div class="ai-messages" #scroller>
35964
+ <!-- Welcome -->
35965
+ <div class="ai-welcome" *ngIf="messages.length === 0">
35966
+ <i class="material-symbols-outlined ai-welcome-icon">smart_toy</i>
35967
+ <div class="ai-welcome-title">{{ welcomeTitle }}</div>
35968
+ <div class="ai-welcome-sub">{{ welcomeSubtitle }}</div>
35969
+ <div class="ai-suggestions" *ngIf="suggestions?.length">
35970
+ <button type="button" class="ai-suggestion" *ngFor="let s of suggestions"
35971
+ (click)="sendSuggestion(s)">{{ s }}</button>
35972
+ </div>
35973
+ </div>
35974
+
35975
+ <div class="ai-msg" *ngFor="let m of messages"
35976
+ [class.ai-msg-user]="m.role === 'user'"
35977
+ [class.ai-msg-bot]="m.role === 'assistant'">
35978
+ <div class="ai-avatar">
35979
+ <i class="material-symbols-outlined">{{ m.role === 'user' ? 'person' : 'smart_toy' }}</i>
35980
+ </div>
35981
+ <div class="ai-bubble">
35982
+ <div class="ai-typing" *ngIf="m.loading && !m.content">
35983
+ <span></span><span></span><span></span>
35984
+ </div>
35985
+ <div class="ai-text" *ngIf="m.content" [innerHTML]="render(m.content)"></div>
35986
+
35987
+ <!-- Sorgenti RAG -->
35988
+ <div class="ai-sources" *ngIf="m.sources?.length">
35989
+ <div class="ai-sources-head">
35990
+ <i class="material-symbols-outlined">menu_book</i> Fonti
35991
+ </div>
35992
+ <div class="ai-source" *ngFor="let src of m.sources"
35993
+ [title]="src.snippet || ''">
35994
+ <i class="material-symbols-outlined">description</i>
35995
+ <span class="ai-source-title">{{ src.title }}</span>
35996
+ <span class="ai-source-score" *ngIf="src.score != null">{{ (src.score * 100) | number:'1.0-0' }}%</span>
35997
+ </div>
35998
+ </div>
35999
+ </div>
36000
+ </div>
36001
+ </div>
36002
+
36003
+ <!-- Errore -->
36004
+ <div class="ai-error" *ngIf="errorMsg">{{ errorMsg }}</div>
36005
+
36006
+ <!-- Input -->
36007
+ <div class="ai-input-area">
36008
+ <div class="ai-input-box" [class.focused]="false">
36009
+ <textarea #ta class="ai-input" rows="1"
36010
+ [(ngModel)]="userInput"
36011
+ [disabled]="busy"
36012
+ [placeholder]="placeholder"
36013
+ (keydown)="onKeyDown($event)"
36014
+ (input)="autoGrow(ta)"></textarea>
36015
+ <button type="button" class="ai-send" *ngIf="!busy"
36016
+ [disabled]="!userInput.trim()" (click)="send()" title="Invia">
36017
+ <i class="material-symbols-outlined">send</i>
36018
+ </button>
36019
+ <button type="button" class="ai-send ai-stop" *ngIf="busy" (click)="stop()" title="Interrompi">
36020
+ <i class="material-symbols-outlined">stop</i>
36021
+ </button>
36022
+ </div>
36023
+ <div class="ai-hint" *ngIf="showHint">Invio per inviare · Shift+Invio per andare a capo</div>
36024
+ </div>
36025
+ </div>
36026
+ `, styles: [":host{display:block;height:100%}.ai-chat{height:100%;box-sizing:border-box;display:flex;flex-direction:column;background:#fff;border:1px solid rgba(22,18,18,.1);border-radius:10px;overflow:hidden}.ai-head{flex:0 0 auto;display:flex;align-items:center;justify-content:space-between;padding:12px 16px;border-top:3px solid var(--fh-ai-accent, #16afc7);border-bottom:1px solid rgba(22,18,18,.07)}.ai-head-left{display:flex;align-items:center;gap:10px}.ai-head-icon{font-size:22px;color:var(--fh-ai-accent, #16afc7)}.ai-head-title{font-family:Plus Jakarta Sans,sans-serif;font-size:14px;font-weight:800;color:#161212}.ai-head-sub{font-family:Inter,sans-serif;font-size:11px;color:#8c8585;margin-top:1px}.ai-head-right{display:flex;align-items:center;gap:8px}.ai-tag{display:inline-block;padding:3px 10px;border-radius:999px;font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:.03em;background:#1612120f;color:#443d3d}.ai-icon-btn{display:flex;border:1px solid rgba(22,18,18,.12);background:transparent;border-radius:8px;width:30px;height:30px;align-items:center;justify-content:center;cursor:pointer;color:#5c5454}.ai-icon-btn:hover{background:#1612120d}.ai-icon-btn i{font-size:18px}.ai-messages{flex:1 1 auto;min-height:0;overflow-y:auto;overflow-x:hidden;padding:18px;display:flex;flex-direction:column;gap:14px;background:#f8fafc}.ai-welcome{margin:auto;display:flex;flex-direction:column;align-items:center;text-align:center;padding:20px;gap:6px}.ai-welcome-icon{font-size:40px;color:var(--fh-ai-accent, #16afc7)}.ai-welcome-title{font-family:Plus Jakarta Sans,sans-serif;font-size:16px;font-weight:700;color:#161212}.ai-welcome-sub{font-family:Inter,sans-serif;font-size:13px;color:#6b6363;margin-bottom:8px}.ai-suggestions{display:flex;flex-wrap:wrap;gap:8px;justify-content:center;max-width:560px}.ai-suggestion{padding:9px 14px;background:#fff;color:#443d3d;border:1px solid rgba(22,18,18,.12);border-radius:999px;font-family:Inter,sans-serif;font-size:12.5px;cursor:pointer;transition:all .15s ease}.ai-suggestion:hover{border-color:var(--fh-ai-accent, #16afc7);color:var(--fh-ai-accent-dark, #0e8ba0);background:#16afc70f}.ai-msg{display:flex;gap:10px;max-width:88%}.ai-msg-user{align-self:flex-end;flex-direction:row-reverse}.ai-msg-bot{align-self:flex-start}.ai-avatar{flex:0 0 auto;width:30px;height:30px;border-radius:8px;display:flex;align-items:center;justify-content:center}.ai-msg-user .ai-avatar{background:var(--fh-ai-accent, #16afc7);color:#fff}.ai-msg-bot .ai-avatar{background:#fff;color:var(--fh-ai-accent, #16afc7);border:1px solid rgba(22,175,199,.35)}.ai-avatar i{font-size:18px}.ai-bubble{padding:10px 14px;border-radius:12px;font-family:Inter,sans-serif;font-size:13.5px;line-height:1.6}.ai-msg-user .ai-bubble{background:var(--fh-ai-accent, #16afc7);color:#fff;border-bottom-right-radius:4px}.ai-msg-bot .ai-bubble{background:#fff;color:#1e293b;border:1px solid rgba(22,18,18,.1);border-bottom-left-radius:4px}.ai-text{word-wrap:break-word}.ai-text ::ng-deep p{margin:0 0 8px}.ai-text ::ng-deep p:last-child{margin-bottom:0}.ai-text ::ng-deep ul,.ai-text ::ng-deep ol{margin:4px 0 8px;padding-left:20px}.ai-text ::ng-deep li{margin-bottom:3px}.ai-text ::ng-deep code{background:#1612120f;padding:1px 5px;border-radius:4px;font-family:Cascadia Code,Fira Code,monospace;font-size:.85em}.ai-text ::ng-deep pre{background:#1e293b;color:#7dd3fc;padding:10px 12px;border-radius:8px;overflow-x:auto;margin:6px 0}.ai-text ::ng-deep pre code{background:transparent;padding:0;color:inherit}.ai-text ::ng-deep strong{font-weight:700}.ai-text ::ng-deep a{color:var(--fh-ai-accent-dark, #0e8ba0);text-decoration:underline}.ai-msg-user .ai-text ::ng-deep a{color:#fff}.ai-text ::ng-deep table{border-collapse:collapse;width:100%;margin:6px 0;font-size:.92em}.ai-text ::ng-deep th,.ai-text ::ng-deep td{border:1px solid rgba(22,18,18,.12);padding:5px 8px;text-align:left}.ai-text ::ng-deep th{background:#1612120a;font-weight:600}.ai-sources{margin-top:10px;border-top:1px dashed rgba(22,18,18,.12);padding-top:8px}.ai-sources-head{display:flex;align-items:center;gap:5px;font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.05em;color:#8c8585;margin-bottom:5px}.ai-sources-head i{font-size:14px}.ai-source{display:flex;align-items:center;gap:6px;font-size:12px;color:#5c5454;padding:2px 0}.ai-source i{font-size:15px;color:var(--fh-ai-accent, #16afc7);flex:0 0 auto}.ai-source-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ai-source-score{flex:0 0 auto;font-size:11px;font-weight:600;color:#a39b9b}.ai-typing{display:flex;gap:4px;padding:3px 0}.ai-typing span{width:7px;height:7px;border-radius:50%;background:#b9c2cc;animation:ai-typing 1.4s infinite}.ai-typing span:nth-child(2){animation-delay:.2s}.ai-typing span:nth-child(3){animation-delay:.4s}@keyframes ai-typing{0%,60%,to{transform:translateY(0);opacity:.4}30%{transform:translateY(-5px);opacity:1}}.ai-error{flex:0 0 auto;margin:0 18px;padding:8px 12px;background:#fef2f2;border:1px solid #fecaca;color:#dc2626;border-radius:8px;font-size:12.5px}.ai-input-area{flex:0 0 auto;padding:14px 16px;border-top:1px solid rgba(22,18,18,.07);background:#fff}.ai-input-box{display:flex;align-items:flex-end;gap:8px;background:#f1f5f9;border:1px solid rgba(22,18,18,.12);border-radius:12px;padding:4px;transition:border-color .15s ease,box-shadow .15s ease}.ai-input-box:focus-within{border-color:var(--fh-ai-accent, #16afc7);box-shadow:0 0 0 3px #16afc71f}.ai-input{flex:1 1 auto;background:transparent;border:none;outline:none;resize:none;font-family:Inter,sans-serif;font-size:13.5px;color:#1e293b;padding:9px 10px;max-height:140px;min-height:22px}.ai-input::placeholder{color:#a39b9b}.ai-send{flex:0 0 auto;width:38px;height:38px;display:flex;align-items:center;justify-content:center;border:none;border-radius:8px;cursor:pointer;color:#fff;background:linear-gradient(135deg,var(--fh-ai-accent, #16afc7) 0%,var(--fh-ai-accent-dark, #0e8ba0) 130%);transition:filter .15s ease}.ai-send:hover:not(:disabled){filter:brightness(1.07)}.ai-send:disabled{background:#cbd5e1;cursor:not-allowed}.ai-send i{font-size:19px}.ai-stop{background:#64748b}.ai-hint{text-align:center;font-size:10.5px;color:#a39b9b;margin-top:6px}\n"] }]
36027
+ }], ctorParameters: () => [{ type: FHAiService }, { type: i1.DomSanitizer }], propDecorators: { accent: [{
36028
+ type: Input
36029
+ }], accentDark: [{
36030
+ type: Input
36031
+ }], _a: [{
36032
+ type: HostBinding,
36033
+ args: ["style.--fh-ai-accent"]
36034
+ }], _ad: [{
36035
+ type: HostBinding,
36036
+ args: ["style.--fh-ai-accent-dark"]
36037
+ }], showHeader: [{
36038
+ type: Input
36039
+ }], title: [{
36040
+ type: Input
36041
+ }], subtitle: [{
36042
+ type: Input
36043
+ }], tagLabel: [{
36044
+ type: Input
36045
+ }], welcomeTitle: [{
36046
+ type: Input
36047
+ }], welcomeSubtitle: [{
36048
+ type: Input
36049
+ }], suggestions: [{
36050
+ type: Input
36051
+ }], placeholder: [{
36052
+ type: Input
36053
+ }], showHint: [{
36054
+ type: Input
36055
+ }], endpoint: [{
36056
+ type: Input
36057
+ }], path: [{
36058
+ type: Input
36059
+ }], model: [{
36060
+ type: Input
36061
+ }], stream: [{
36062
+ type: Input
36063
+ }], apiKey: [{
36064
+ type: Input
36065
+ }], forwardAuth: [{
36066
+ type: Input
36067
+ }], context: [{
36068
+ type: Input
36069
+ }], systemPrompt: [{
36070
+ type: Input
36071
+ }], messageSent: [{
36072
+ type: Output
36073
+ }], responseReceived: [{
36074
+ type: Output
36075
+ }], errored: [{
36076
+ type: Output
36077
+ }], scroller: [{
36078
+ type: ViewChild,
36079
+ args: ["scroller"]
36080
+ }] } });
36081
+ /**
36082
+ * Formattatore markdown minimale e dependency-free.
36083
+ * Esegue PRIMA l'escape di &,<,> (anti-XSS), poi applica la formattazione su testo sicuro.
36084
+ */
36085
+ function formatMarkdown(input) {
36086
+ if (!input)
36087
+ return "";
36088
+ let s = input.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
36089
+ // Code block ```...```
36090
+ const blocks = [];
36091
+ s = s.replace(/```(?:[a-zA-Z]+)?\n?([\s\S]*?)```/g, (_m, code) => {
36092
+ blocks.push(`<pre><code>${code.replace(/\n$/, "")}</code></pre>`);
36093
+ return `BLOCK${blocks.length - 1}`;
36094
+ });
36095
+ // Inline code `...`
36096
+ s = s.replace(/`([^`]+)`/g, "<code>$1</code>");
36097
+ // Bold **...**
36098
+ s = s.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
36099
+ // Italic *...*
36100
+ s = s.replace(/(^|[^*])\*([^*\n]+)\*/g, "$1<em>$2</em>");
36101
+ // Link [testo](url)
36102
+ s = s.replace(/\[([^\]]+)\]\((https?:[^)\s]+)\)/g, '<a href="$2" target="_blank" rel="noopener">$1</a>');
36103
+ // Liste: righe che iniziano con "- " o "* " o "N. "
36104
+ const lines = s.split("\n");
36105
+ const out = [];
36106
+ let inUl = false;
36107
+ let inOl = false;
36108
+ const closeLists = () => {
36109
+ if (inUl) {
36110
+ out.push("</ul>");
36111
+ inUl = false;
36112
+ }
36113
+ if (inOl) {
36114
+ out.push("</ol>");
36115
+ inOl = false;
36116
+ }
36117
+ };
36118
+ for (const line of lines) {
36119
+ const ul = line.match(/^\s*[-*]\s+(.*)$/);
36120
+ const ol = line.match(/^\s*\d+\.\s+(.*)$/);
36121
+ if (ul) {
36122
+ if (inOl) {
36123
+ out.push("</ol>");
36124
+ inOl = false;
36125
+ }
36126
+ if (!inUl) {
36127
+ out.push("<ul>");
36128
+ inUl = true;
36129
+ }
36130
+ out.push(`<li>${ul[1]}</li>`);
36131
+ }
36132
+ else if (ol) {
36133
+ if (inUl) {
36134
+ out.push("</ul>");
36135
+ inUl = false;
36136
+ }
36137
+ if (!inOl) {
36138
+ out.push("<ol>");
36139
+ inOl = true;
36140
+ }
36141
+ out.push(`<li>${ol[1]}</li>`);
36142
+ }
36143
+ else {
36144
+ closeLists();
36145
+ out.push(line);
36146
+ }
36147
+ }
36148
+ closeLists();
36149
+ s = out.join("\n");
36150
+ // Paragrafi / a-capo: doppia newline -> blocco, singola -> <br>
36151
+ s = s
36152
+ .split(/\n{2,}/)
36153
+ .map((blk) => {
36154
+ if (/^<(ul|ol|pre|h\d|table)/.test(blk.trim()))
36155
+ return blk;
36156
+ return `<p>${blk.replace(/\n/g, "<br>")}</p>`;
36157
+ })
36158
+ .join("");
36159
+ // Ripristino i code block
36160
+ s = s.replace(/BLOCK(\d+)/g, (_m, i) => blocks[+i]);
36161
+ return s;
36162
+ }
36163
+
36164
+ /**
36165
+ * Launcher AI flottante ("drop-anywhere") di FluxHub: un FAB in basso a destra che
36166
+ * apre/chiude un pannello con dentro <FHAiChat>. Si inserisce in qualunque pagina
36167
+ * del portale per dare accesso all'assistente senza occupare layout.
36168
+ *
36169
+ * Inoltra al chat gli @Input principali (endpoint, contesto, tema, testi).
36170
+ *
36171
+ * Esempio:
36172
+ * <FHAiAssistant [context]="{azienda:'COEM', ruolo:'manager'}"
36173
+ * [accent]="'#16afc7'"
36174
+ * welcomeTitle="Assistente COEM"></FHAiAssistant>
36175
+ */
36176
+ class FHAiAssistantComponent {
36177
+ // ---- Tema ----
36178
+ accent = "#16afc7";
36179
+ accentDark = "#0e8ba0";
36180
+ get _a() { return this.accent; }
36181
+ get _ad() { return this.accentDark; }
36182
+ // ---- FAB ----
36183
+ icon = "smart_toy";
36184
+ openLabel = "Assistente AI";
36185
+ showLabel = true;
36186
+ /** 'floating' = popover ancorato al FAB; 'right' = drawer a tutta altezza. */
36187
+ dock = "floating";
36188
+ /** Apre il pannello all'avvio. */
36189
+ startOpen = false;
36190
+ // ---- Pass-through al chat ----
36191
+ title = "Assistente AI";
36192
+ subtitle = "";
36193
+ tagLabel = "";
36194
+ welcomeTitle = "Come posso aiutarti?";
36195
+ welcomeSubtitle = "Fammi una domanda sui tuoi dati.";
36196
+ suggestions = [];
36197
+ placeholder = "Scrivi un messaggio...";
36198
+ endpoint = "";
36199
+ path = "ai/chat";
36200
+ model = "";
36201
+ stream = true;
36202
+ apiKey = "";
36203
+ forwardAuth = true;
36204
+ context = null;
36205
+ systemPrompt = "";
36206
+ open = false;
36207
+ ngOnInit() {
36208
+ this.open = this.startOpen;
36209
+ }
36210
+ toggle() {
36211
+ this.open = !this.open;
36212
+ }
36213
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: FHAiAssistantComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
36214
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.17", type: FHAiAssistantComponent, isStandalone: true, selector: "FHAiAssistant", inputs: { accent: "accent", accentDark: "accentDark", icon: "icon", openLabel: "openLabel", showLabel: "showLabel", dock: "dock", startOpen: "startOpen", title: "title", subtitle: "subtitle", tagLabel: "tagLabel", welcomeTitle: "welcomeTitle", welcomeSubtitle: "welcomeSubtitle", suggestions: "suggestions", placeholder: "placeholder", endpoint: "endpoint", path: "path", model: "model", stream: "stream", apiKey: "apiKey", forwardAuth: "forwardAuth", context: "context", systemPrompt: "systemPrompt" }, host: { properties: { "style.--fh-ai-accent": "this._a", "style.--fh-ai-accent-dark": "this._ad" } }, ngImport: i0, template: `
36215
+ <!-- Pannello -->
36216
+ <div class="ai-fab-panel" *ngIf="open" [class.docked]="dock !== 'floating'">
36217
+ <FHAiChat
36218
+ [accent]="accent" [accentDark]="accentDark"
36219
+ [title]="title" [subtitle]="subtitle" [tagLabel]="tagLabel"
36220
+ [welcomeTitle]="welcomeTitle" [welcomeSubtitle]="welcomeSubtitle"
36221
+ [suggestions]="suggestions" [placeholder]="placeholder"
36222
+ [endpoint]="endpoint" [path]="path" [model]="model" [stream]="stream"
36223
+ [apiKey]="apiKey" [forwardAuth]="forwardAuth" [context]="context"
36224
+ [systemPrompt]="systemPrompt">
36225
+ </FHAiChat>
36226
+ </div>
36227
+
36228
+ <!-- FAB -->
36229
+ <button type="button" class="ai-fab" (click)="toggle()" [title]="open ? 'Chiudi assistente' : openLabel">
36230
+ <i class="material-symbols-outlined">{{ open ? 'close' : icon }}</i>
36231
+ <span class="ai-fab-label" *ngIf="!open && showLabel">{{ openLabel }}</span>
36232
+ </button>
36233
+ `, isInline: true, styles: [":host{position:fixed;right:24px;bottom:24px;z-index:1200}.ai-fab{display:flex;align-items:center;gap:8px;height:54px;min-width:54px;padding:0 18px;border:none;border-radius:999px;cursor:pointer;color:#fff;background:linear-gradient(135deg,var(--fh-ai-accent, #16afc7) 0%,var(--fh-ai-accent-dark, #0e8ba0) 130%);box-shadow:0 8px 24px #0e233c47;transition:filter .15s ease,transform .15s ease;margin-left:auto}.ai-fab:hover{filter:brightness(1.07);transform:translateY(-1px)}.ai-fab i{font-size:24px}.ai-fab-label{font-family:Plus Jakarta Sans,sans-serif;font-size:14px;font-weight:700;white-space:nowrap}.ai-fab-panel{position:absolute;right:0;bottom:70px;width:400px;max-width:calc(100vw - 48px);height:600px;max-height:calc(100vh - 130px);border-radius:12px;overflow:hidden;box-shadow:0 18px 50px #0e233c52;animation:ai-fab-in .18s ease}.ai-fab-panel.docked{position:fixed;top:0;right:0;bottom:0;width:420px;max-width:100vw;height:100vh;max-height:100vh;border-radius:0}@keyframes ai-fab-in{0%{opacity:0;transform:translateY(10px)}to{opacity:1;transform:translateY(0)}}@media (max-width: 520px){.ai-fab-panel{width:calc(100vw - 48px);height:calc(100vh - 130px)}}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: FHAiChatComponent, selector: "FHAiChat", inputs: ["accent", "accentDark", "showHeader", "title", "subtitle", "tagLabel", "welcomeTitle", "welcomeSubtitle", "suggestions", "placeholder", "showHint", "endpoint", "path", "model", "stream", "apiKey", "forwardAuth", "context", "systemPrompt"], outputs: ["messageSent", "responseReceived", "errored"] }] });
36234
+ }
36235
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: FHAiAssistantComponent, decorators: [{
36236
+ type: Component,
36237
+ args: [{ selector: "FHAiAssistant", standalone: true, imports: [CommonModule, FHAiChatComponent], template: `
36238
+ <!-- Pannello -->
36239
+ <div class="ai-fab-panel" *ngIf="open" [class.docked]="dock !== 'floating'">
36240
+ <FHAiChat
36241
+ [accent]="accent" [accentDark]="accentDark"
36242
+ [title]="title" [subtitle]="subtitle" [tagLabel]="tagLabel"
36243
+ [welcomeTitle]="welcomeTitle" [welcomeSubtitle]="welcomeSubtitle"
36244
+ [suggestions]="suggestions" [placeholder]="placeholder"
36245
+ [endpoint]="endpoint" [path]="path" [model]="model" [stream]="stream"
36246
+ [apiKey]="apiKey" [forwardAuth]="forwardAuth" [context]="context"
36247
+ [systemPrompt]="systemPrompt">
36248
+ </FHAiChat>
36249
+ </div>
36250
+
36251
+ <!-- FAB -->
36252
+ <button type="button" class="ai-fab" (click)="toggle()" [title]="open ? 'Chiudi assistente' : openLabel">
36253
+ <i class="material-symbols-outlined">{{ open ? 'close' : icon }}</i>
36254
+ <span class="ai-fab-label" *ngIf="!open && showLabel">{{ openLabel }}</span>
36255
+ </button>
36256
+ `, styles: [":host{position:fixed;right:24px;bottom:24px;z-index:1200}.ai-fab{display:flex;align-items:center;gap:8px;height:54px;min-width:54px;padding:0 18px;border:none;border-radius:999px;cursor:pointer;color:#fff;background:linear-gradient(135deg,var(--fh-ai-accent, #16afc7) 0%,var(--fh-ai-accent-dark, #0e8ba0) 130%);box-shadow:0 8px 24px #0e233c47;transition:filter .15s ease,transform .15s ease;margin-left:auto}.ai-fab:hover{filter:brightness(1.07);transform:translateY(-1px)}.ai-fab i{font-size:24px}.ai-fab-label{font-family:Plus Jakarta Sans,sans-serif;font-size:14px;font-weight:700;white-space:nowrap}.ai-fab-panel{position:absolute;right:0;bottom:70px;width:400px;max-width:calc(100vw - 48px);height:600px;max-height:calc(100vh - 130px);border-radius:12px;overflow:hidden;box-shadow:0 18px 50px #0e233c52;animation:ai-fab-in .18s ease}.ai-fab-panel.docked{position:fixed;top:0;right:0;bottom:0;width:420px;max-width:100vw;height:100vh;max-height:100vh;border-radius:0}@keyframes ai-fab-in{0%{opacity:0;transform:translateY(10px)}to{opacity:1;transform:translateY(0)}}@media (max-width: 520px){.ai-fab-panel{width:calc(100vw - 48px);height:calc(100vh - 130px)}}\n"] }]
36257
+ }], propDecorators: { accent: [{
36258
+ type: Input
36259
+ }], accentDark: [{
36260
+ type: Input
36261
+ }], _a: [{
36262
+ type: HostBinding,
36263
+ args: ["style.--fh-ai-accent"]
36264
+ }], _ad: [{
36265
+ type: HostBinding,
36266
+ args: ["style.--fh-ai-accent-dark"]
36267
+ }], icon: [{
36268
+ type: Input
36269
+ }], openLabel: [{
36270
+ type: Input
36271
+ }], showLabel: [{
36272
+ type: Input
36273
+ }], dock: [{
36274
+ type: Input
36275
+ }], startOpen: [{
36276
+ type: Input
36277
+ }], title: [{
36278
+ type: Input
36279
+ }], subtitle: [{
36280
+ type: Input
36281
+ }], tagLabel: [{
36282
+ type: Input
36283
+ }], welcomeTitle: [{
36284
+ type: Input
36285
+ }], welcomeSubtitle: [{
36286
+ type: Input
36287
+ }], suggestions: [{
36288
+ type: Input
36289
+ }], placeholder: [{
36290
+ type: Input
36291
+ }], endpoint: [{
36292
+ type: Input
36293
+ }], path: [{
36294
+ type: Input
36295
+ }], model: [{
36296
+ type: Input
36297
+ }], stream: [{
36298
+ type: Input
36299
+ }], apiKey: [{
36300
+ type: Input
36301
+ }], forwardAuth: [{
36302
+ type: Input
36303
+ }], context: [{
36304
+ type: Input
36305
+ }], systemPrompt: [{
36306
+ type: Input
36307
+ }] } });
36308
+
35484
36309
  /*
35485
36310
  * Public API Surface of fluxhublib
35486
36311
  */
@@ -35489,5 +36314,5 @@ const KNOWN_EXT = "3G2|3GA|3GP|7Z|AA|AAC|AC|ACCDB|ACCDT|ADN|AI|AIF|AIFC|AIFF|AIT
35489
36314
  * Generated bundle index. Do not edit.
35490
36315
  */
35491
36316
 
35492
- export { AppMakerService, AppService, ApprovaGridComponent, AuthHttpRequestInterceptor, AuthenticationService, BpmnEditorComponent, CheckboxEditorComponent, ComboBoxEditorComponent, CurrencyComponent, DialogBaseComponent, FHAutoCompleteComponent, FHCheckBoxComponent, FHColorPickerComponent, FHComboboxComponent, FHConfirmValues, FHCurrencyFormatterDirective, FHCurrencyPipe, FHDatePickerComponent, FHDateRangePickerComponent, FHFieldPickListComponent, FHFilterComboboxComponent, FHFormBuilderComponent, FHFormExecuterComponent, FHFormToolBarComponent, FHGridComponent, FHGridJSONComponent, FHGridToolBarComponent, FHGuard, FHHelpButtonComponent, FHHomeDocsComponent, FHHomeLauncherComponent, FHHomeStatsComponent, FHHomeTodoComponent, FHImageViewerComponent, FHListComponent, FHLogPanelComponent, FHMultiComboboxComponent, FHNotesPanelComponent, FHNumericFieldComponent, FHPickFieldComponent, FHPickUsersComponent, FHRichTextComponent, FHRoleManagerComponent, FHTableManagerComponent, FHTextAreaComponent, FHTextInputComponent, FHTimePickerComponent, FHToolBarCustomAction, FHToolbarCommandType, FHUploadComponent, FHUploadPanelComponent, FHUploadPanelS3Component, FHUploadS3Component, FHUserFieldComponent, FHWinAppLogsComponent, FHWinAskBigTextComponent, FHWinAskButtonsComponent, FHWinAskNumberComponent, FHWinAskRichTextComponent, FHWinAskTextComponent, FHWinAutoComplete, FHWinComboComponent, FHWinConfirmComponent, FHWinErrorComponent, FHWinGridSelection, FHWinInfoComponent, FHWinListComponent, FHWinMappaComponent, FHWinOutputComponent, FHWinPicklistComponent, FHWinSalvaAnnulla, FHWinSelectByGridComponent, FHWinShowEmail, FHWinShowEmailS3, FHWinShowImage, FHWinShowLog, FHWinShowLogDett, FHWinTimeSlider, FHWinUploadComponent, FHWinUserInfo, FHWinUserPickerComponent, FHWinWaitComponent, FHWorkflowForm, FHWorkflowHeaderBar, FHWorkflowView, FSInput, FSResult, FileService, GridService, LocalDBService, MonthYearPickerComponent, NumericEditorComponent, OdbcService, OfficeAutomatorService, OfficeOperation, OfficeResult, QGParam, QGResult, QParam, QResult, QueryOpenService, QueryService, RegistrationService, ReplaceLineBreaks, SafePipe, TextAreaEditorComponent, UtilityService, WkfService, YearPickerComponent, createButtonCommand, createCheckboxCommand, createSpacerCommand, createTableManagerCommand, fh_win_translate };
36317
+ export { AppMakerService, AppService, ApprovaGridComponent, AuthHttpRequestInterceptor, AuthenticationService, BpmnEditorComponent, CheckboxEditorComponent, ComboBoxEditorComponent, CurrencyComponent, DialogBaseComponent, FHAiAssistantComponent, FHAiChatComponent, FHAiService, FHAutoCompleteComponent, FHCheckBoxComponent, FHColorPickerComponent, FHComboboxComponent, FHConfirmValues, FHCurrencyFormatterDirective, FHCurrencyPipe, FHDatePickerComponent, FHDateRangePickerComponent, FHFieldPickListComponent, FHFilterComboboxComponent, FHFormBuilderComponent, FHFormExecuterComponent, FHFormToolBarComponent, FHGridComponent, FHGridJSONComponent, FHGridToolBarComponent, FHGuard, FHHelpButtonComponent, FHHomeDocsComponent, FHHomeLauncherComponent, FHHomeStatsComponent, FHHomeTodoComponent, FHImageViewerComponent, FHListComponent, FHLogPanelComponent, FHMultiComboboxComponent, FHNotesPanelComponent, FHNumericFieldComponent, FHPickFieldComponent, FHPickUsersComponent, FHRichTextComponent, FHRoleManagerComponent, FHTableManagerComponent, FHTextAreaComponent, FHTextInputComponent, FHTimePickerComponent, FHToolBarCustomAction, FHToolbarCommandType, FHUploadComponent, FHUploadPanelComponent, FHUploadPanelS3Component, FHUploadS3Component, FHUserFieldComponent, FHWinAppLogsComponent, FHWinAskBigTextComponent, FHWinAskButtonsComponent, FHWinAskNumberComponent, FHWinAskRichTextComponent, FHWinAskTextComponent, FHWinAutoComplete, FHWinComboComponent, FHWinConfirmComponent, FHWinErrorComponent, FHWinGridSelection, FHWinInfoComponent, FHWinListComponent, FHWinMappaComponent, FHWinOutputComponent, FHWinPicklistComponent, FHWinSalvaAnnulla, FHWinSelectByGridComponent, FHWinShowEmail, FHWinShowEmailS3, FHWinShowImage, FHWinShowLog, FHWinShowLogDett, FHWinTimeSlider, FHWinUploadComponent, FHWinUserInfo, FHWinUserPickerComponent, FHWinWaitComponent, FHWorkflowForm, FHWorkflowHeaderBar, FHWorkflowView, FSInput, FSResult, FileService, GridService, LocalDBService, MonthYearPickerComponent, NumericEditorComponent, OdbcService, OfficeAutomatorService, OfficeOperation, OfficeResult, QGParam, QGResult, QParam, QResult, QueryOpenService, QueryService, RegistrationService, ReplaceLineBreaks, SafePipe, TextAreaEditorComponent, UtilityService, WkfService, YearPickerComponent, createButtonCommand, createCheckboxCommand, createSpacerCommand, createTableManagerCommand, fh_win_translate };
35493
36318
  //# sourceMappingURL=fluxhub-fluxhub-lib.mjs.map