Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : SP Mail8 * File : web/src/ui/next/AiParts.tsx9 * Module : ui10 * Repository : https://git.spboucher.ai/sp-mail11 * Project Website : https://mail.spboucher.ai12 * Created : 2026-11-2013 * Last Modified : 2026-11-2014 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// SP Mail Next — petites pièces communes des surfaces d'IA : mention « traité par » (fournisseur · modèle), ligne d'échec discrète.44import { t } from "../../i18n"45import type { MsgKey } from "../../i18n"46import type { AiBy, AiFailure, AiIssue } from "../../next/ai"47import { linkProps } from "../../state/session"48import { Icon } from "../kit"4950export const providerName = (provider: string): string =>51 provider === "local" ? t("nx.ai.provider.local") : provider === "anthropic" ? t("nx.ai.provider.anthropic") : provider.startsWith("embed:") ? t("nx.ai.provider.embed") : provider5253/** « MacLustr (local) · modèle » — chaque résultat dit qui l'a produit ; « depuis le cache » quand rien n'a été redemandé au modèle. */54export function AiByLine({ by }: { by: AiBy | null }) {55 if (!by || !by.provider) return null56 return (57 <span className="nx-ai-by" data-nx-ai="by" data-provider={by.provider} data-model={by.model} data-cached={by.cached ? "1" : undefined}>58 <span>{providerName(by.provider)}</span>59 {by.model ? (60 <>61 <span aria-hidden="true">·</span>62 <span className="nx-ai-model">{by.model}</span>63 </>64 ) : null}65 {by.cached ? (66 <>67 <span aria-hidden="true">·</span>68 <span>{t("nx.ai.cached")}</span>69 </>70 ) : null}71 </span>72 )73}7475const ISSUE: Record<AiIssue, MsgKey> = {76 offline: "nx.offline", disabled: "nx.ai.issue.disabled", consent: "nx.ai.issue.consent", unavailable: "nx.ai.issue.unavailable", rate_limited: "nx.ai.issue.rateLimited",77 timeout: "nx.ai.issue.timeout", invalid_output: "nx.ai.issue.invalidOutput", refused: "nx.ai.issue.refused", not_found: "nx.ai.issue.notFound", error: "nx.ai.issue.error",78}79export const issueText = (f: AiFailure): string => t(ISSUE[f.issue])8081/** Une ligne, précise, sans mur rouge ; « Réessayer » seulement quand cela a un sens, sinon le lien vers les réglages. */82export function AiProblem({ failure, onRetry }: { failure: AiFailure; onRetry?: () => void }) {83 const toSettings = failure.issue === "disabled" || failure.issue === "consent"84 return (85 <p className="nx-ai-problem" role="status" data-nx-ai="problem" data-issue={failure.issue}>86 <Icon name="warn" small />87 <span>{issueText(failure)}</span>88 {failure.retry && onRetry ? (89 <button type="button" className="btn small ghost" onClick={onRetry}>90 {t("nx.retry")}91 </button>92 ) : null}93 {toSettings ? (94 <a className="btn small ghost" {...linkProps("/settings/intelligence")}>95 {t("nx.ai.openSettings")}96 </a>97 ) : null}98 </p>99 )100}101