Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
725 changes: 712 additions & 13 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ members = [
"crates/sequins-cold-tier",
"crates/sequins-storage",
"crates/sequins-datafusion-backend",
"crates/sequins-metadata",
"crates/sequins-view",
"crates/sequins-client",
"crates/sequins-server",
"crates/sequins-assistant",
"crates/sequins-ffi",
"crates/sequins-cli",
"apps/linux",
Expand Down Expand Up @@ -60,9 +62,11 @@ sequins-hot-tier = { path = "crates/sequins-hot-tier" }
sequins-cold-tier = { path = "crates/sequins-cold-tier" }
sequins-storage = { path = "crates/sequins-storage" }
sequins-datafusion-backend = { path = "crates/sequins-datafusion-backend" }
sequins-metadata = { path = "crates/sequins-metadata" }
sequins-view = { path = "crates/sequins-view" }
sequins-client = { path = "crates/sequins-client" }
sequins-server = { path = "crates/sequins-server" }
sequins-assistant = { path = "crates/sequins-assistant" }
sequins-ffi = { path = "crates/sequins-ffi" }

# OpenTelemetry
Expand Down Expand Up @@ -150,6 +154,14 @@ tracing-appender = "0.2"
winnow = "0.6"
indexmap = { version = "2", features = ["serde"] }

# AI assistant — Rig agent framework + Model Context Protocol.
# Imported as `rig` (rig-core's lib name is `rig_core`) to match Rig's docs.
# rmcp/schemars versions are pinned to what `rig-core`'s `rmcp` feature resolves,
# so MCP tool types line up across the Rig ↔ rmcp boundary.
rig = { version = "0.39", package = "rig-core", features = ["rmcp"] }
rmcp = { version = "1.8", features = ["client", "server", "macros", "transport-streamable-http-server", "transport-streamable-http-client-reqwest"] }
schemars = "1"

# CLI
clap = { version = "4", features = ["derive"] }

Expand Down
2 changes: 2 additions & 0 deletions apps/macos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Local xcodebuild output (derivedDataPath used by the build scripts)
build/
14 changes: 13 additions & 1 deletion apps/macos/Sequins/Models/ConnectionEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ final class ConnectionEnvironment {
var remoteQueryURL: String?
var remoteManagementURL: String?

// Assistant (AI) settings — the API key / bearer token is stored in the Keychain
// (keyed by this environment's id), NOT here.
/// Local: the OpenAI-compatible provider base URL (nil = api.openai.com).
/// Remote: the daemon's assistant `/v1` base URL (e.g. `http://host:8082/v1`).
var assistantBaseURL: String?
/// The model id to use (required for local; optional for remote).
var assistantModel: String?

init(
id: UUID = UUID(),
name: String,
Expand All @@ -27,7 +35,9 @@ final class ConnectionEnvironment {
grpcPort: Int? = nil,
httpPort: Int? = nil,
remoteQueryURL: String? = nil,
remoteManagementURL: String? = nil
remoteManagementURL: String? = nil,
assistantBaseURL: String? = nil,
assistantModel: String? = nil
) {
self.id = id
self.name = name
Expand All @@ -39,6 +49,8 @@ final class ConnectionEnvironment {
self.httpPort = httpPort
self.remoteQueryURL = remoteQueryURL
self.remoteManagementURL = remoteManagementURL
self.assistantBaseURL = assistantBaseURL
self.assistantModel = assistantModel
}

/// The fixed UUID for the local environment - never changes
Expand Down
11 changes: 11 additions & 0 deletions apps/macos/Sequins/SequinsApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ struct SequinsApp: App {

// Set up notification service
setupNotifications(appState: state)

// Demo/QA hook: auto-open the main window on launch when requested, so the
// menu-bar app can be driven headlessly. No-op unless the env var is set.
if let tabName = ProcessInfo.processInfo.environment["SEQUINS_AUTO_OPEN_WINDOW"] {
let tab = NavigationItem(rawValue: tabName) ?? .assistant
let launchState = state
DispatchQueue.main.async {
MainWindowController.shared.showWindow(appState: launchState, selectedTab: tab)
NSApp.activate(ignoringOtherApps: true)
}
}
}

private func setupNotifications(appState: AppStateViewModel) {
Expand Down
66 changes: 66 additions & 0 deletions apps/macos/Sequins/Services/KeychainStore.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import Foundation
import Security

/// Minimal macOS Keychain wrapper for the assistant's per-environment secret (the LLM
/// API key for local, or the bearer token for remote). Secrets are keyed by the
/// environment's UUID so each environment has its own credential.
struct KeychainStore {
static let shared = KeychainStore()

private let service = "com.sequins.assistant"

private init() {}

private func account(for environmentId: UUID) -> String {
"assistant-secret-\(environmentId.uuidString)"
}

/// Read the assistant secret for an environment, or `nil` if unset.
func assistantSecret(environmentId: UUID) -> String? {
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: service,
kSecAttrAccount as String: account(for: environmentId),
kSecReturnData as String: true,
kSecMatchLimit as String: kSecMatchLimitOne,
]
var item: CFTypeRef?
let status = SecItemCopyMatching(query as CFDictionary, &item)
guard status == errSecSuccess,
let data = item as? Data,
let value = String(data: data, encoding: .utf8),
!value.isEmpty
else { return nil }
return value
}

/// Store (or clear, when `secret` is nil/empty) the assistant secret for an environment.
@discardableResult
func setAssistantSecret(_ secret: String?, environmentId: UUID) -> Bool {
let account = account(for: environmentId)
let base: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: service,
kSecAttrAccount as String: account,
]

// Clearing.
guard let secret, !secret.isEmpty else {
let status = SecItemDelete(base as CFDictionary)
return status == errSecSuccess || status == errSecItemNotFound
}

let data = Data(secret.utf8)
// Update if present, else add.
let attributes: [String: Any] = [kSecValueData as String: data]
let updateStatus = SecItemUpdate(base as CFDictionary, attributes as CFDictionary)
if updateStatus == errSecSuccess { return true }
if updateStatus == errSecItemNotFound {
var addQuery = base
addQuery[kSecValueData as String] = data
addQuery[kSecAttrAccessible as String] = kSecAttrAccessibleAfterFirstUnlock
return SecItemAdd(addQuery as CFDictionary, nil) == errSecSuccess
}
return false
}
}
30 changes: 29 additions & 1 deletion apps/macos/Sequins/ViewModels/AppStateViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ final class AppStateViewModel {
// UI State
var selectedService: Service?
var selectedView: NavigationItem = .traces
var showSettings = false
var showServerInfo = false
var isServiceAttributesExpanded = false

Expand Down Expand Up @@ -63,6 +62,31 @@ final class AppStateViewModel {
timeRangeState.setCustomRange(start: start, end: end)
}

/// Build the assistant's LLM/daemon config from the selected environment plus the
/// Keychain-stored secret. Returns `nil` when the assistant is not configured for
/// the current environment (so the UI can prompt the user to set it up).
///
/// The model is chosen at runtime in the Assistant tab (from the provider's model
/// list), so it isn't required here — only enough to reach the provider/daemon:
/// - Local: an API key (base URL optional → api.openai.com).
/// - Remote: the daemon `/v1` base URL + a bearer token.
func assistantConfig() -> AssistantConfig? {
if let env = environmentManager.selectedEnvironment {
let secret = KeychainStore.shared.assistantSecret(environmentId: env.id)
let base = env.assistantBaseURL?.isEmpty == false ? env.assistantBaseURL : nil
let model = env.assistantModel?.isEmpty == false ? env.assistantModel : nil
if let secret, !secret.isEmpty {
if env.isLocal {
return AssistantConfig(baseURL: base, model: model, apiKey: secret)
} else if let base {
return AssistantConfig(baseURL: base, model: model, apiKey: secret)
}
}
}
// Dev/CI fallback: OPENAI_* environment variables (mirrors the daemon).
return AssistantConfig.fromProcessEnvironment()
}

init() {
// Don't initialize data source in init - let it happen lazily
// This prevents crashes during app startup
Expand Down Expand Up @@ -204,6 +228,8 @@ enum NavigationItem: String, CaseIterable, Identifiable {
case logs = "Logs"
case profiles = "Profiles"
case explore = "Explore"
case assistant = "Assistant"
case dashboards = "Dashboards"

var id: String { rawValue }

Expand All @@ -215,6 +241,8 @@ enum NavigationItem: String, CaseIterable, Identifiable {
case .logs: return "doc.text"
case .profiles: return "flame"
case .explore: return "terminal"
case .assistant: return "bubble.left.and.text.bubble.right"
case .dashboards: return "square.grid.2x2"
}
}
}
Expand Down
Loading
Loading