Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Astra9// File : Packages/AstraUI/Sources/Shared/ProviderLogo.swift10// Module : Shared11// Repository : https://git.spboucher.ai/orix-astra12// Created : 2026-11-2113// Last Modified : 2026-11-2114//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author : Simon-Pierre Boucher20// Position : Professor of Finance21// Institution : Université du Québec en Outaouais (UQO)22// Department : Département des sciences administratives23// Organization : SP Boucher24//25// Website : https://spboucher.ai26// Git : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General : info@spboucher.ai33// Professional : contact@spboucher.ai34// Direct : simon@spboucher.ai35// Research : research@spboucher.ai36// Development : dev@spboucher.ai37// Support : support@spboucher.ai38// Security/Admin : admin@spboucher.ai39// Notifications : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification : Public66// Distribution : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License : Proprietary, all rights reserved (see license file)80// License File : LICENSE81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import SwiftUI89import AstraCore90import AstraDesign91#if canImport(UIKit)92import UIKit93#endif9495/// Resolves which vector logo identifies a provider or a model's vendor. Logos are trademarks of their owners and are used96/// only to identify the service a model comes from; the name is always present as text or as an accessibility label.97public enum LogoCatalog {98 /// Asset names inside the app's `Logos` namespace, with the hint on how to draw them (template = takes the text colour).99 public struct Mark: Sendable, Hashable { public var asset: String; public var template: Bool; public var name: String }100101 public static func mark(for provider: ProviderKind) -> Mark? {102 switch provider {103 case .openAI: Mark(asset: "openai", template: true, name: "OpenAI")104 case .anthropic: Mark(asset: "anthropic", template: true, name: "Anthropic")105 case .google: Mark(asset: "google-color", template: false, name: "Google")106 case .xAI: Mark(asset: "xai", template: true, name: "xAI")107 case .openRouter: Mark(asset: "openrouter", template: true, name: "OpenRouter")108 case .custom, .mlx, .appleFoundation: nil109 }110 }111112 private static let vendors: [(keys: [String], mark: Mark)] = [113 (["openai", "gpt-", "o1", "o3", "o4"], Mark(asset: "openai", template: true, name: "OpenAI")),114 (["anthropic", "claude"], Mark(asset: "anthropic", template: true, name: "Anthropic")),115 (["google", "gemini", "gemma"], Mark(asset: "google-color", template: false, name: "Google")),116 (["x-ai", "xai", "grok"], Mark(asset: "xai", template: true, name: "xAI")),117 (["meta", "llama"], Mark(asset: "meta-color", template: false, name: "Meta")),118 (["mistral", "mixtral", "codestral", "ministral", "pixtral"], Mark(asset: "mistral-color", template: false, name: "Mistral AI")),119 (["qwen", "alibaba"], Mark(asset: "qwen-color", template: false, name: "Qwen")),120 (["deepseek"], Mark(asset: "deepseek-color", template: false, name: "DeepSeek")),121 (["microsoft", "phi-"], Mark(asset: "microsoft-color", template: false, name: "Microsoft")),122 (["cohere", "command-"], Mark(asset: "cohere-color", template: false, name: "Cohere")),123 (["perplexity", "sonar"], Mark(asset: "perplexity-color", template: false, name: "Perplexity")),124 (["nvidia", "nemotron"], Mark(asset: "nvidia-color", template: false, name: "NVIDIA")),125 (["amazon", "nova-"], Mark(asset: "amazon-color", template: false, name: "Amazon")),126 (["huggingface", "smollm"], Mark(asset: "huggingface-color", template: false, name: "Hugging Face")),127 (["moonshot", "kimi"], Mark(asset: "moonshot", template: true, name: "Moonshot AI")),128 (["minimax"], Mark(asset: "minimax-color", template: false, name: "MiniMax")),129 (["baidu", "ernie"], Mark(asset: "baidu-color", template: false, name: "Baidu")),130 (["bytedance", "doubao"], Mark(asset: "bytedance-color", template: false, name: "ByteDance")),131 (["tencent", "hunyuan"], Mark(asset: "tencent-color", template: false, name: "Tencent")),132 (["z-ai", "zai", "glm"], Mark(asset: "zai", template: true, name: "Z.ai")),133 (["ai21", "jamba"], Mark(asset: "ai21", template: true, name: "AI21")),134 (["inflection"], Mark(asset: "inflection", template: true, name: "Inflection")),135 (["liquid", "lfm"], Mark(asset: "liquid", template: true, name: "Liquid AI")),136 (["nousresearch", "hermes"], Mark(asset: "nousresearch", template: true, name: "Nous Research")),137 (["ibm", "granite"], Mark(asset: "ibm", template: true, name: "IBM")),138 (["fireworks"], Mark(asset: "fireworks-color", template: false, name: "Fireworks")),139 (["upstage", "solar"], Mark(asset: "upstage-color", template: false, name: "Upstage")),140 (["stepfun"], Mark(asset: "stepfun-color", template: false, name: "StepFun")),141 (["arcee"], Mark(asset: "arcee-color", template: false, name: "Arcee")),142 (["inception", "mercury"], Mark(asset: "inception", template: true, name: "Inception")),143 ]144145 /// The mark of a model's vendor, from the vendor field when the provider reports one, otherwise from the model id's146 /// owner segment ("meta-llama/…") and finally from well-known family names.147 public static func mark(vendor: String?, modelID: String) -> Mark? {148 let owner = modelID.split(separator: "/").first.map(String.init)?.lowercased()149 let candidates = [vendor?.lowercased(), modelID.contains("/") ? owner : nil].compactMap { $0 }150 for c in candidates { if let hit = vendors.first(where: { $0.keys.contains { c.hasPrefix($0) || c == $0 } }) { return hit.mark } }151 let name = (modelID.split(separator: "/").last.map(String.init) ?? modelID).lowercased()152 return vendors.first(where: { $0.keys.contains { name.hasPrefix($0) || name.contains("-" + $0) || name.contains($0 + "-") } })?.mark153 }154155 public static func mark(for model: ModelInfo) -> Mark? {156 switch model.ref.provider {157 case .openRouter, .custom, .mlx: mark(vendor: model.vendor, modelID: model.ref.modelID) ?? mark(for: model.ref.provider)158 default: mark(for: model.ref.provider)159 }160 }161}162163/// The logo shown to the left of a model or provider name. Falls back to an SF Symbol tile when no vector logo applies164/// (on-device runtimes, custom endpoints) or when the asset is missing.165public struct ProviderLogo: View {166 var mark: LogoCatalog.Mark?167 var provider: ProviderKind168 var size: CGFloat169170 public init(model: ModelInfo, size: CGFloat = 34) { mark = LogoCatalog.mark(for: model); provider = model.ref.provider; self.size = size }171 public init(provider: ProviderKind, size: CGFloat = 34) { mark = LogoCatalog.mark(for: provider); self.provider = provider; self.size = size }172 public init(ref: ModelRef, vendor: String? = nil, size: CGFloat = 34) {173 provider = ref.provider; self.size = size174 mark = ref.provider == .openRouter || ref.provider == .custom || ref.provider == .mlx175 ? (LogoCatalog.mark(vendor: vendor, modelID: ref.modelID) ?? LogoCatalog.mark(for: ref.provider)) : LogoCatalog.mark(for: ref.provider)176 }177178 public var body: some View {179 ZStack {180 RoundedRectangle(cornerRadius: size * 0.28, style: .continuous).fill(AstraColor.surfaceRaised)181 RoundedRectangle(cornerRadius: size * 0.28, style: .continuous).strokeBorder(AstraColor.stroke, lineWidth: 1)182 if let mark, Self.exists(mark.asset) {183 Image("Logos/" + mark.asset, bundle: .main)184 .renderingMode(mark.template ? .template : .original)185 .resizable().scaledToFit()186 .foregroundStyle(AstraColor.textPrimary)187 .padding(size * 0.2)188 } else {189 Image(systemName: fallbackSymbol).font(.system(size: size * 0.44, weight: .semibold)).foregroundStyle(AstraColor.signature)190 }191 }192 .frame(width: size, height: size)193 .accessibilityHidden(true)194 }195196 private var fallbackSymbol: String {197 switch provider {198 case .mlx: "cpu"199 case .appleFoundation: "apple.intelligence"200 case .custom: "server.rack"201 default: "sparkle"202 }203 }204205 private static func exists(_ asset: String) -> Bool {206 #if canImport(UIKit)207 UIImage(named: "Logos/" + asset, in: .main, compatibleWith: nil) != nil208 #else209 false210 #endif211 }212}213