SPB Git

Repository Public MIT

AIDescriptorSupport.swift 4.1 KB 118 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Apps/GlassStudio/Kit/Descriptors/AIDescriptorSupport.swift8// Module           : GlassStudio9// Repository       : https://git.spboucher.ai/sp-glasskit10// Project Website  : https://glass.spboucher.ai11// Created          : 2026-12-0212// Last Modified    : 2026-12-0213//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import SPGlassKit4344// Preview support of the AI descriptors.4546/// Holds a value the previewed component edits through a binding.47struct AIPreviewState<Value, Content: View>: View {48    @State private var value: Value49    private let content: (Binding<Value>) -> Content5051    init(_ initialValue: Value, @ViewBuilder content: @escaping (Binding<Value>) -> Content) {52        _value = State(initialValue: initialValue)53        self.content = content54    }5556    var body: some View { content($value) }57}5859/// Marks the previewed content as fictitious: no model, provider or agent is involved.60struct AISampleLabelled<Content: View>: View {61    @ViewBuilder let content: Content6263    var body: some View {64        VStack(alignment: .leading, spacing: 8) {65            content66            Text(verbatim: L("Sample data · fictitious content, no model is involved"))67                .font(.caption)68                .foregroundStyle(.secondary)69        }70        .frame(maxWidth: 520)71    }72}7374/// The prompt bar with a local draft: sending and attaching go nowhere.75struct AIPromptBarPreview: View {76    let placeholder: String77    let isResponding: Bool78    let showsAttachButton: Bool79    let maxLines: Int80    @State private var draft: String81    @State private var attachments: [GlassPromptAttachment]8283    init(draft: String, placeholder: String, isResponding: Bool, attachments: [GlassPromptAttachment], showsAttachButton: Bool, maxLines: Int) {84        self.placeholder = placeholder85        self.isResponding = isResponding86        self.showsAttachButton = showsAttachButton87        self.maxLines = maxLines88        _draft = State(initialValue: draft)89        _attachments = State(initialValue: attachments)90    }9192    var body: some View {93        GlassPromptBar(94            text: $draft,95            placeholder: placeholder.isEmpty ? nil : LocalizedStringKey(placeholder),96            isResponding: isResponding,97            attachments: attachments,98            lineLimit: 1...max(maxLines, 1),99            onSend: { _ in },100            onStop: {},101            onAttach: attachAction,102            onRemoveAttachment: removeAction103        )104    }105106    private var attachAction: (@MainActor () -> Void)? {107        guard showsAttachButton else { return nil }108        return {}109    }110111    private var removeAction: (@MainActor (GlassPromptAttachment) -> Void)? {112        guard !attachments.isEmpty else { return nil }113        return { attachment in114            attachments.removeAll { $0.id == attachment.id }115        }116    }117}118
Files main
Menu

Theme