SPB Git

Repository Public

QuickChat.swift 5.6 KB 90 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: SPChat/Features/Chat/QuickChat.swift3// Description: Quick chat (floating panel) and menu bar extra: ask a question from anywhere, then continue in a full window.4import SwiftUI5import SPChatCore67struct QuickChatView: View {8    let close: () -> Void9    @Environment(AppEnvironment.self) private var env10    @State private var key = UUID().uuidString11    @State private var focus = 01213    var body: some View {14        let chat = env.chat(conversationId: nil, draftKey: "quick:" + key)15        VStack(spacing: 0) {16            HStack {17                BrandMark(size: 20); Text("Chat rapide").font(.headline)18                Spacer()19                if let id = chat.conversationId {20                    Button("Ouvrir dans SP Chat") { env.open(conversationId: id); NewWindowOpener.shared.open?(id); close() }.controlSize(.small)21                }22                Button { key = UUID().uuidString; focus += 1 } label: { Image(systemName: "square.and.pencil") }.buttonStyle(.borderless).help("Nouvelle question").accessibilityLabel("Nouvelle question")23                Button { close() } label: { Image(systemName: "xmark") }.buttonStyle(.borderless).keyboardShortcut(.cancelAction).accessibilityLabel("Fermer")24            }25            .padding(.horizontal, 14).padding(.top, 12).padding(.bottom, 8)26            if env.session.phase != .signedIn {27                EmptyStateView(systemImage: "lock", title: "Connexion requise", message: "Ouvre SP Chat et connecte-toi avec ta clé d'accès.").frame(maxHeight: .infinity)28            } else {29                if chat.isEmpty { Text("Pose une question. Modèle : \(env.catalog.displayName(forModel: chat.settings.modelId))").font(.callout).foregroundStyle(.secondary).frame(maxWidth: .infinity, maxHeight: .infinity) }30                else { TranscriptView(chat: chat, actions: MessageActions(regenerate: { m, model in chat.regenerate(m, modelId: model) })) }31                if let e = chat.errorBanner { Banner(kind: .error, text: e, onDismiss: { chat.errorBanner = nil }).padding(.horizontal, 12) }32                ComposerView(chat: chat, focusToken: focus, compact: true).padding(12)33            }34        }35        .environment(\.transcriptFontSize, 13 * env.preferences.textScale)36        .background(.regularMaterial)37        .task(id: key) { await chat.loadIfNeeded() }38    }39}4041struct MenuBarContent: View {42    @Environment(AppEnvironment.self) private var env43    @Environment(\.openWindow) private var openWindow44    var body: some View {45        VStack(alignment: .leading, spacing: 8) {46            HStack { BrandMark(size: 18); Text("SP Chat").font(.headline); Spacer(); if !env.streamingConversationIds.isEmpty { ProgressView().controlSize(.mini) } }47            Divider()48            Button { open(nil) } label: { Label("Nouvelle conversation", systemImage: "square.and.pencil") }49            Button { (NSApp.delegate as? AppDelegate)?.toggleQuickChat() } label: { Label("Chat rapide", systemImage: "bolt.horizontal") }50            if env.session.phase == .signedIn, !env.conversations.items.isEmpty {51                Divider()52                Text("Récentes").font(.caption).foregroundStyle(.secondary)53                ForEach(env.conversations.items.prefix(6)) { c in54                    Button { open(c.id) } label: { Text(c.title).lineLimit(1).frame(maxWidth: .infinity, alignment: .leading) }55                }56            }57            Divider()58            SettingsLink { Label("Réglages…", systemImage: "gearshape") }59            Button { NSApp.terminate(nil) } label: { Label("Quitter SP Chat", systemImage: "power") }60        }61        .buttonStyle(.plain).padding(12).frame(width: 260)62        .task { if env.session.phase == .signedIn, env.conversations.items.isEmpty { await env.conversations.refresh() } }63    }64    private func open(_ id: String?) {65        NSApp.activate(ignoringOtherApps: true)66        if let id { openWindow(id: "conversation", value: id) } else { openWindow(id: "main") }67    }68}6970struct ShortcutsSheet: View {71    @Environment(\.dismiss) private var dismiss72    private let rows: [(String, String)] = [73        ("⌘N", "Nouvelle conversation"), ("⇧⌘N", "Nouvelle fenêtre"), ("⌘F", "Rechercher"), ("⌘K", "Centre de commandes"), ("⌘,", "Réglages"),74        ("⏎ / ⌘⏎", "Envoyer (selon le réglage)"), ("⇧⏎", "Saut de ligne"), ("⌘.", "Arrêter la génération"), ("⇧⌘R", "Régénérer la dernière réponse"),75        ("⇧⌘C", "Copier la dernière réponse"), ("⇧⌘M", "Choisir le modèle"), ("⇧⌘I", "Recherche web"), ("/ et @", "Commandes et modèles dans le message"), ("⇧⌘A", "Joindre des fichiers"), ("⌘L", "Curseur dans le message"),76        ("⌥⌘I / T / L / B", "Panneau : contexte, chronologie, Lens, branches"), ("⌥⌘E / A / G", "Explorateur, Arena, Constellation"), ("⇧⌘E / ⇧⌘P", "Exporter en Markdown / PDF"), ("⇧⌘O", "Ouvrir dans une nouvelle fenêtre"), ("⇧⌘Espace", "Chat rapide"),77        ("⌘+ / ⌘- / ⌘0", "Taille du texte"), ("⌥⌘1…9", "Sections de l'espace de travail"), ("⌃⌘F", "Plein écran"),78    ]79    var body: some View {80        VStack(alignment: .leading, spacing: 12) {81            Text("Raccourcis clavier").font(.title3.weight(.semibold))82            Grid(alignment: .leading, horizontalSpacing: 18, verticalSpacing: 6) {83                ForEach(rows, id: \.0) { k, v in GridRow { Text(k).font(.callout.monospaced()).foregroundStyle(Palette.iris); Text(v).font(.callout) } }84            }85            HStack { Spacer(); Button("Fermer") { dismiss() }.keyboardShortcut(.defaultAction) }86        }87        .padding(22).frame(width: 440)88    }89}90
Files main
Menu

Theme