new features
This commit is contained in:
+336
-24
@@ -59,6 +59,22 @@ struct ChatView: View {
|
||||
@ObservedObject var studio: StudioModel
|
||||
@AppStorage("endpoint") private var endpoint = "http://127.0.0.1:11434"
|
||||
@AppStorage("ollamaModel") private var model = ""
|
||||
@AppStorage("agentWorkflowEnabled") private var agentWorkflowEnabled = false
|
||||
@AppStorage("agentMCPEnabled") private var agentMCPEnabled = false
|
||||
@AppStorage("agentPlannerEnabled") private var agentPlannerEnabled = true
|
||||
@AppStorage("agentSpecialistEnabled") private var agentSpecialistEnabled = true
|
||||
|
||||
@AppStorage(AgentProfile.storageKey) private var agentProfiles = Data()
|
||||
@AppStorage(AgentProfile.overridesKey) private var builtInAgents = Data()
|
||||
|
||||
private var selectedAgents: [AgentRole] {
|
||||
guard agentWorkflowEnabled else { return [] }
|
||||
let custom = AgentProfile.read(agentProfiles).filter(\.enabled).prefix(AgentProfile.limit).map(AgentRole.custom)
|
||||
let builtIns: [AgentRole] = (agentPlannerEnabled ? [.planner] : []) + (agentSpecialistEnabled ? [.specialist] : [])
|
||||
return builtIns.map { $0.applyingOverrides(builtInAgents) } + custom +
|
||||
[AgentRole.reviewer.applyingOverrides(builtInAgents)]
|
||||
}
|
||||
|
||||
@AppStorage("mlxPath") private var mlxPath = ""
|
||||
@AppStorage("thinking") private var thinking = Thinking.automatic
|
||||
@AppStorage("failover") private var failover = true
|
||||
@@ -180,6 +196,16 @@ struct ChatView: View {
|
||||
}
|
||||
.toolbar(mode == .zen ? .hidden : .visible, for: .windowToolbar)
|
||||
.onChange(of: mode, initial: true) { _, value in columns = value == .normal ? .all : .detailOnly }
|
||||
.sheet(item: Binding(
|
||||
get: { studio.agentToolApproval },
|
||||
set: { approval in
|
||||
if approval == nil, let current = studio.agentToolApproval {
|
||||
studio.resolveAgentTool(current.id, approved: false)
|
||||
}
|
||||
}
|
||||
)) { approval in
|
||||
AgentToolApprovalView(approval: approval) { studio.resolveAgentTool(approval.id, approved: $0) }
|
||||
}
|
||||
.sheet(isPresented: $showingLibrary) { DocumentLibraryView(studio: studio) }
|
||||
.sheet(isPresented: $showingPerformance) { PerformanceDashboard(studio: studio) }
|
||||
.sheet(isPresented: $showingWorkspace) { WorkspaceResourcesView(studio: studio) }
|
||||
@@ -292,13 +318,16 @@ struct ChatView: View {
|
||||
.font(chatFont.font(size: chatSize))
|
||||
Divider()
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
let feedback = [splitStudio.knowledgeStatus, splitStudio.webStatus, splitStudio.status]
|
||||
let feedback = [showDebugOutput ? splitStudio.knowledgeStatus : "", splitStudio.webStatus, splitStudio.status]
|
||||
.filter { !$0.isEmpty }.joined(separator: " · ")
|
||||
if !feedback.isEmpty { Text(feedback).font(.caption).foregroundStyle(.secondary) }
|
||||
ChatComposerInput(text: $splitStudio.prompt, canSend: !splitStudio.running, spellCheck: spellCheck,
|
||||
autoCorrect: autoCorrect, font: chatFont.appKit(size: chatSize), send: sendSplitMessage)
|
||||
.frame(height: 54)
|
||||
HStack {
|
||||
if let role = splitStudio.agentStage {
|
||||
Label(role.name, systemImage: "person.2").font(.caption)
|
||||
}
|
||||
Spacer()
|
||||
if splitStudio.running {
|
||||
Button("Stop", systemImage: "stop.fill") { splitStudio.stop() }
|
||||
@@ -355,12 +384,12 @@ struct ChatView: View {
|
||||
}
|
||||
.font(.caption)
|
||||
}
|
||||
let activity = [fileError, studio.knowledgeStatus, studio.webStatus, studio.status].filter { !$0.isEmpty }
|
||||
let activity = [fileError, showDebugOutput ? studio.knowledgeStatus : "", studio.webStatus, studio.status].filter { !$0.isEmpty }
|
||||
if !activity.isEmpty {
|
||||
Text(activity.joined(separator: " · "))
|
||||
.font(.caption).foregroundStyle(.secondary).lineLimit(2).textSelection(.enabled)
|
||||
}
|
||||
if !studio.knowledgeSources.isEmpty {
|
||||
if showDebugOutput, !studio.knowledgeSources.isEmpty {
|
||||
DisclosureGroup("Knowledge Sources (\(studio.knowledgeSources.count))") {
|
||||
ScrollView {
|
||||
Text(studio.knowledgeSources.joined(separator: "\n"))
|
||||
@@ -443,6 +472,15 @@ struct ChatView: View {
|
||||
}
|
||||
.fixedSize().disabled(studio.running)
|
||||
}
|
||||
Toggle("Agents", isOn: $agentWorkflowEnabled)
|
||||
.toggleStyle(.checkbox)
|
||||
.fixedSize()
|
||||
.disabled(studio.running)
|
||||
if let role = studio.agentStage {
|
||||
Label(role.name, systemImage: "person.2")
|
||||
.font(.caption)
|
||||
.help(studio.agentSteps.joined(separator: "\n"))
|
||||
}
|
||||
if studio.running {
|
||||
Button("Stop", systemImage: "stop.fill") { studio.stop() }
|
||||
} else {
|
||||
@@ -478,7 +516,7 @@ struct ChatView: View {
|
||||
splitStudio.send(endpoint: activeEndpoint, model: activeModel, mlxPath: mlxPath, thinking: thinking,
|
||||
failover: failover, mlxOnly: mlxOnly, compatible: compatibleEnabled, recall: recall, useDocuments: false,
|
||||
instructions: promptMode.instructions(custom: customPrompt),
|
||||
settings: GenerationSettings.read(generationSettings))
|
||||
settings: GenerationSettings.read(generationSettings), agents: selectedAgents)
|
||||
}
|
||||
|
||||
private func sendMessage() {
|
||||
@@ -499,7 +537,7 @@ struct ChatView: View {
|
||||
studio.send(endpoint: activeEndpoint, model: activeModel, mlxPath: mlxPath, thinking: thinking,
|
||||
failover: failover, mlxOnly: mlxOnly, compatible: compatibleEnabled, recall: recall, useDocuments: useDocuments,
|
||||
instructions: promptMode.instructions(custom: customPrompt),
|
||||
settings: GenerationSettings.read(generationSettings))
|
||||
settings: GenerationSettings.read(generationSettings), agents: selectedAgents, agentTools: agentMCPEnabled)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -535,10 +573,17 @@ struct MessageView: View {
|
||||
}
|
||||
}
|
||||
if !message.thinking.isEmpty {
|
||||
DisclosureGroup("Thinking", isExpanded: $thinkingExpanded) {
|
||||
DisclosureGroup(isExpanded: $thinkingExpanded) {
|
||||
Text(message.thinking).foregroundStyle(.secondary).textSelection(.enabled)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.vertical, 6)
|
||||
} label: {
|
||||
Label(streaming && message.content.isEmpty ? "Thinking…" : "Thinking",
|
||||
systemImage: "brain.head.profile")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.padding(8)
|
||||
.background(.quaternary.opacity(0.45), in: RoundedRectangle(cornerRadius: 8))
|
||||
}
|
||||
if !message.content.isEmpty {
|
||||
if message.role == .assistant && renderMarkdown {
|
||||
@@ -552,6 +597,9 @@ struct MessageView: View {
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(compactMessages ? 8 : 14)
|
||||
.onChange(of: expandThinking, initial: true) { _, expanded in thinkingExpanded = expanded }
|
||||
.onChange(of: streaming && !message.thinking.isEmpty, initial: true) { _, beganThinking in
|
||||
if beganThinking { thinkingExpanded = true }
|
||||
}
|
||||
.background(StudioCustomTheme.selected(customThemeID, in: customThemesData)?.message(dark: colorScheme == .dark, user: message.role == .user) ?? palette.message(dark: colorScheme == .dark, user: message.role == .user),
|
||||
in: RoundedRectangle(cornerRadius: 12))
|
||||
}
|
||||
@@ -615,10 +663,8 @@ struct BackendSettings: View {
|
||||
HStack {
|
||||
Label(entry.name, systemImage: "cube")
|
||||
Spacer()
|
||||
if let size = entry.size {
|
||||
Text(ByteCountFormatter.string(fromByteCount: size, countStyle: .file))
|
||||
.foregroundStyle(.secondary).font(.caption)
|
||||
}
|
||||
Text(ModelLibrarySize.label(entry.size))
|
||||
.foregroundStyle(.secondary).font(.caption)
|
||||
Button(model == entry.name && !mlxOnly && !compatibleEnabled ? "Selected" : "Use Model") {
|
||||
model = entry.name
|
||||
mlxOnly = false
|
||||
@@ -1634,6 +1680,10 @@ struct WorkspaceSnippetsView: View {
|
||||
@State private var renderedPage: RenderedClipPage?
|
||||
@State private var deleting = false
|
||||
@State private var error = ""
|
||||
@State private var notice = ""
|
||||
@FocusState private var draftFocus: DraftField?
|
||||
|
||||
private enum DraftField: Hashable { case title, address, content }
|
||||
|
||||
private var items: [WorkspaceSnippet] {
|
||||
studio.snippets.filter {
|
||||
@@ -1645,13 +1695,23 @@ struct WorkspaceSnippetsView: View {
|
||||
HSplitView {
|
||||
VStack(spacing: 8) {
|
||||
TextField("Search \(kind.rawValue)s", text: $search)
|
||||
List(items, selection: $id) { item in Text(item.title).tag(item.id) }
|
||||
Button("New \(kind.rawValue)") { clear() }
|
||||
if items.isEmpty {
|
||||
ContentUnavailableView(
|
||||
search.isEmpty ? "No saved \(kind.rawValue.lowercased())s" : "No matches",
|
||||
systemImage: "tray"
|
||||
)
|
||||
.frame(maxHeight: .infinity)
|
||||
} else {
|
||||
List(items, selection: $id) { item in Text(item.title).tag(item.id) }
|
||||
.disabled(capturing)
|
||||
}
|
||||
Button("New \(kind.rawValue)", systemImage: "plus") { beginDraft() }
|
||||
.disabled(capturing)
|
||||
}
|
||||
.padding(12)
|
||||
.frame(minWidth: 180, idealWidth: 220)
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
TextField("Title", text: $title)
|
||||
TextField("Title", text: $title).focused($draftFocus, equals: .title).disabled(capturing)
|
||||
if kind == .prompt {
|
||||
TextField("Notes", text: $notes)
|
||||
TextField("Tags (comma-separated)", text: $tags)
|
||||
@@ -1670,19 +1730,22 @@ struct WorkspaceSnippetsView: View {
|
||||
}
|
||||
if kind == .webClip {
|
||||
HStack {
|
||||
TextField("Source URL", text: $address)
|
||||
Button("Capture Text") {
|
||||
TextField("Source URL", text: $address).focused($draftFocus, equals: .address).disabled(capturing)
|
||||
Button("Capture & Save") {
|
||||
capturing = true
|
||||
let source = address
|
||||
Task {
|
||||
defer { capturing = false }
|
||||
do {
|
||||
content = try await WebClipCapture.text(from: source)
|
||||
if title.isEmpty { title = URL(string: source)?.host ?? "Web Clip" }
|
||||
error = ""
|
||||
let page = try await WebClipCapture.page(from: source)
|
||||
address = page.url.absoluteString
|
||||
content = String(page.text.prefix(12_000))
|
||||
if title.isEmpty { title = page.title }
|
||||
save()
|
||||
} catch { self.error = error.localizedDescription }
|
||||
}
|
||||
}.disabled(capturing || address.isEmpty)
|
||||
if capturing { ProgressView().controlSize(.small) }
|
||||
Button("Open Rendered Page…") {
|
||||
do { renderedPage = RenderedClipPage(url: try WebClipCapture.pageURL(address)) }
|
||||
catch { self.error = error.localizedDescription }
|
||||
@@ -1691,8 +1754,16 @@ struct WorkspaceSnippetsView: View {
|
||||
}
|
||||
}
|
||||
TextEditor(text: $content).accessibilityLabel("\(kind.rawValue) text")
|
||||
.focused($draftFocus, equals: .content)
|
||||
.border(.quaternary)
|
||||
.overlay(alignment: .topLeading) {
|
||||
if content.isEmpty {
|
||||
Text(editorHint).foregroundStyle(.secondary).padding(8)
|
||||
.allowsHitTesting(false).accessibilityHidden(true)
|
||||
}
|
||||
}
|
||||
if !error.isEmpty { Text(error).foregroundStyle(.red).textSelection(.enabled) }
|
||||
if !notice.isEmpty { Label(notice, systemImage: "checkmark.circle").foregroundStyle(.secondary) }
|
||||
HStack {
|
||||
if kind != .webClip { Button("Import Text…") { importing = true } }
|
||||
if id != nil { Button("Delete…", role: .destructive) { deleting = true } }
|
||||
@@ -1702,7 +1773,7 @@ struct WorkspaceSnippetsView: View {
|
||||
apply()
|
||||
}.disabled(studio.running)
|
||||
}
|
||||
Button("Save", action: save).buttonStyle(.borderedProminent)
|
||||
Button(id == nil ? "Save \(kind.rawValue)" : "Save Changes", action: save).buttonStyle(.borderedProminent)
|
||||
.disabled(title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ||
|
||||
content.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || capturing)
|
||||
}
|
||||
@@ -1730,7 +1801,7 @@ struct WorkspaceSnippetsView: View {
|
||||
address = finalURL.absoluteString
|
||||
if title.isEmpty { title = pageTitle }
|
||||
content = text
|
||||
error = ""
|
||||
save()
|
||||
}
|
||||
}
|
||||
.fileImporter(isPresented: $importing, allowedContentTypes: [
|
||||
@@ -1778,13 +1849,50 @@ struct WorkspaceSnippetsView: View {
|
||||
}
|
||||
let key = id ?? UUID()
|
||||
let stored = kind == .webClip ? "Source: \(address)\n\n\(content)" : content
|
||||
studio.saveSnippet(id: key, kind: kind, title: title.trimmingCharacters(in: .whitespacesAndNewlines), content: stored, notes: notes, tags: tags)
|
||||
guard studio.saveSnippet(id: key, kind: kind, title: title.trimmingCharacters(in: .whitespacesAndNewlines),
|
||||
content: stored, notes: notes, tags: tags) else {
|
||||
error = studio.workspaceStatus
|
||||
notice = ""
|
||||
return
|
||||
}
|
||||
search = ""
|
||||
id = key
|
||||
notice = "Saved \(kind.rawValue.lowercased())."
|
||||
if kind == .prompt { versions = studio.promptVersions(key) }
|
||||
error = ""
|
||||
}
|
||||
|
||||
private func clear() { id = nil; title = ""; content = ""; address = ""; error = ""; notes = ""; tags = ""; versions = [] }
|
||||
private var editorHint: String {
|
||||
switch kind {
|
||||
case .skill: "Describe what AI Studio should do when this skill is active."
|
||||
case .context: "Add reference text to use in chat."
|
||||
case .prompt: "Write a reusable prompt."
|
||||
case .webClip: "Enter a URL and use Capture & Save, or paste an excerpt here."
|
||||
}
|
||||
}
|
||||
|
||||
private func beginDraft() {
|
||||
clear()
|
||||
search = ""
|
||||
if kind == .webClip {
|
||||
draftFocus = .address
|
||||
} else {
|
||||
title = "Untitled \(kind.rawValue)"
|
||||
draftFocus = .title
|
||||
}
|
||||
}
|
||||
|
||||
private func clear() {
|
||||
id = nil
|
||||
title = ""
|
||||
content = ""
|
||||
address = ""
|
||||
error = ""
|
||||
notice = ""
|
||||
notes = ""
|
||||
tags = ""
|
||||
versions = []
|
||||
}
|
||||
}
|
||||
|
||||
private struct RenderedClipPage: Identifiable {
|
||||
@@ -1892,8 +2000,8 @@ struct StudioSettingsView: View {
|
||||
@AppStorage("studioSettingsPane") private var page = "Models"
|
||||
private let pages = [
|
||||
("Models", "cpu"), ("Model Library", "square.stack"), ("Generation", "slider.horizontal.3"),
|
||||
("Toolbox", "wrench.and.screwdriver"), ("Local Tools", "terminal"), ("Runtime", "waveform.path"),
|
||||
("Appearance", "paintpalette"), ("Workspace Data", "externaldrive")
|
||||
("Knowledge Base", "books.vertical"), ("Toolbox", "wrench.and.screwdriver"), ("Local Tools", "terminal"), ("Runtime", "waveform.path"),
|
||||
("Agents", "person.2"), ("Appearance", "paintpalette"), ("Workspace Data", "externaldrive")
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
@@ -1912,7 +2020,9 @@ struct StudioSettingsView: View {
|
||||
@ViewBuilder private func pane(_ name: String) -> some View {
|
||||
switch name {
|
||||
case "Model Library": ModelCatalogView(studio: studio)
|
||||
case "Agents": AgentSettings(studio: studio)
|
||||
case "Generation": GenerationSettingsView()
|
||||
case "Knowledge Base": PegasusKnowledgeSettings(studio: studio)
|
||||
case "Toolbox": MCPSettings(studio: studio)
|
||||
case "Local Tools": LocalToolsView(studio: studio)
|
||||
case "Runtime": RuntimeSettingsView(studio: studio)
|
||||
@@ -2433,3 +2543,205 @@ private struct StudioThemeEditor: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private struct AgentSettings: View {
|
||||
@ObservedObject var studio: StudioModel
|
||||
@AppStorage("agentWorkflowEnabled") private var enabled = false
|
||||
@AppStorage("agentPlannerEnabled") private var planner = true
|
||||
@AppStorage("agentSpecialistEnabled") private var specialist = true
|
||||
@AppStorage("agentMCPEnabled") private var mcpEnabled = false
|
||||
@AppStorage(AgentProfile.storageKey) private var profileData = Data()
|
||||
@AppStorage(AgentProfile.overridesKey) private var overridesData = Data()
|
||||
private struct Editing: Identifiable {
|
||||
let profile: AgentProfile
|
||||
var role: AgentRole?
|
||||
var id: UUID { profile.id }
|
||||
}
|
||||
|
||||
@State private var editing: Editing?
|
||||
|
||||
private var overrides: [String: AgentProfile] {
|
||||
(try? JSONDecoder().decode([String: AgentProfile].self, from: overridesData)) ?? [:]
|
||||
}
|
||||
@State private var removing: AgentProfile?
|
||||
|
||||
private var profiles: [AgentProfile] { AgentProfile.read(profileData) }
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section("Chat Agents") {
|
||||
Toggle("Run agents when sending messages", isOn: $enabled)
|
||||
builtInRow(.planner, enabled: $planner)
|
||||
builtInRow(.specialist, enabled: $specialist)
|
||||
builtInRow(.reviewer)
|
||||
Toggle("Let the specialist request an MCP tool", isOn: $mcpEnabled)
|
||||
.disabled(!specialist)
|
||||
Text("Enable Agents in chat, describe a task, and send it. The planner outlines the work, the specialist drafts a response, and the reviewer checks and delivers it. They share the model selected in Models.")
|
||||
.foregroundStyle(.secondary)
|
||||
Text("Connect tools in Toolbox. The specialist can ask for one tool call per run in the main chat. Review the tool, server, and arguments before allowing it. Toolbox results can also be attached before sending.")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.disabled(studio.running)
|
||||
Section("Custom Agents") {
|
||||
Text("Give each agent a name, a task, and instructions for what it should hand off. Enabled agents run in the order shown, before the reviewer.")
|
||||
.foregroundStyle(.secondary)
|
||||
Button("New Agent", systemImage: "plus") {
|
||||
editing = Editing(profile: AgentProfile(name: "", instructions: ""))
|
||||
}
|
||||
.disabled(profiles.count >= AgentProfile.limit)
|
||||
ForEach(profiles) { profile in
|
||||
HStack {
|
||||
Toggle(profile.name, isOn: Binding(get: { profile.enabled }, set: { enabled in
|
||||
var updated = profile
|
||||
updated.enabled = enabled
|
||||
save(updated)
|
||||
}))
|
||||
Spacer()
|
||||
Button("Edit") { editing = Editing(profile: profile) }
|
||||
Button("Remove…", role: .destructive) { removing = profile }
|
||||
}
|
||||
}
|
||||
}
|
||||
.disabled(studio.running)
|
||||
if studio.agentStage != nil || !studio.agentSteps.isEmpty {
|
||||
Section("Latest Run") {
|
||||
ForEach(studio.agentSteps.indices, id: \.self) { index in
|
||||
Label(studio.agentSteps[index], systemImage: "circle")
|
||||
}
|
||||
if let role = studio.agentStage {
|
||||
LabeledContent("Current stage", value: role.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.sheet(item: $editing) { selection in
|
||||
AgentProfileEditor(
|
||||
profile: selection.profile,
|
||||
save: { updated in
|
||||
if let role = selection.role { saveOverride(updated, for: role) }
|
||||
else { save(updated) }
|
||||
editing = nil
|
||||
},
|
||||
cancel: { editing = nil },
|
||||
reset: selection.role.map { role in
|
||||
{
|
||||
saveOverride(nil, for: role)
|
||||
editing = nil
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
.confirmationDialog("Remove this agent?", isPresented: Binding(
|
||||
get: { removing != nil }, set: { if !$0 { removing = nil } }
|
||||
), presenting: removing) { profile in
|
||||
Button("Remove Agent", role: .destructive) {
|
||||
if let data = try? JSONEncoder().encode(profiles.filter { $0.id != profile.id }) {
|
||||
profileData = data
|
||||
}
|
||||
removing = nil
|
||||
}
|
||||
} message: { profile in Text(profile.name) }
|
||||
}
|
||||
|
||||
private func builtInRow(_ role: AgentRole, enabled: Binding<Bool>? = nil) -> some View {
|
||||
let profile = overrides[role.name] ?? AgentProfile(name: role.name, instructions: role.instructions)
|
||||
return HStack {
|
||||
if let enabled {
|
||||
Toggle(profile.name, isOn: enabled)
|
||||
} else {
|
||||
Text(profile.name)
|
||||
Text("Final response").foregroundStyle(.secondary)
|
||||
}
|
||||
Spacer()
|
||||
Button("Edit") {
|
||||
editing = Editing(profile: profile, role: role)
|
||||
}
|
||||
.accessibilityLabel("Edit " + profile.name)
|
||||
}
|
||||
}
|
||||
|
||||
private func saveOverride(_ profile: AgentProfile?, for role: AgentRole) {
|
||||
var saved = overrides
|
||||
saved[role.name] = profile
|
||||
if let data = try? JSONEncoder().encode(saved) { overridesData = data }
|
||||
}
|
||||
|
||||
private func save(_ profile: AgentProfile) {
|
||||
var updated = profiles
|
||||
if let index = updated.firstIndex(where: { $0.id == profile.id }) {
|
||||
updated[index] = profile
|
||||
} else if updated.count < AgentProfile.limit {
|
||||
updated.append(profile)
|
||||
}
|
||||
if let data = try? JSONEncoder().encode(updated) { profileData = data }
|
||||
}
|
||||
}
|
||||
|
||||
private struct AgentProfileEditor: View {
|
||||
@State var profile: AgentProfile
|
||||
let save: (AgentProfile) -> Void
|
||||
let cancel: () -> Void
|
||||
var reset: (() -> Void)? = nil
|
||||
|
||||
private var name: String { profile.name.trimmingCharacters(in: .whitespacesAndNewlines) }
|
||||
private var instructions: String { profile.instructions.trimmingCharacters(in: .whitespacesAndNewlines) }
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Agent Profile").font(.headline)
|
||||
TextField("Name", text: $profile.name, prompt: Text("Technical Editor"))
|
||||
Text("Instructions").font(.subheadline)
|
||||
TextEditor(text: $profile.instructions)
|
||||
.font(.body)
|
||||
.accessibilityLabel("Agent instructions")
|
||||
.border(.quaternary)
|
||||
Text("Describe the work, the evidence to use, and the output to pass to the next agent.")
|
||||
.foregroundStyle(.secondary)
|
||||
HStack {
|
||||
Spacer()
|
||||
if let reset { Button("Restore Default", action: reset) }
|
||||
Button("Cancel", action: cancel).keyboardShortcut(.cancelAction)
|
||||
Button("Save Agent") {
|
||||
profile.name = name
|
||||
profile.instructions = instructions
|
||||
save(profile)
|
||||
}
|
||||
.disabled(name.isEmpty || name.count > 60 || instructions.isEmpty || instructions.count > 4_000)
|
||||
.help("Enter a name of up to 60 characters and instructions of up to 4,000 characters.")
|
||||
}
|
||||
}
|
||||
.padding(18)
|
||||
.frame(width: 510, height: 340)
|
||||
}
|
||||
}
|
||||
|
||||
private struct AgentToolApprovalView: View {
|
||||
let approval: StudioModel.AgentToolApproval
|
||||
let resolve: (Bool) -> Void
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Allow this MCP tool call?").font(.headline)
|
||||
LabeledContent("Server", value: approval.server)
|
||||
LabeledContent("Tool", value: approval.tool)
|
||||
ScrollView {
|
||||
Text(String(decoding: approval.arguments, as: UTF8.self))
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.textSelection(.enabled)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(8)
|
||||
}
|
||||
.background(.quaternary, in: RoundedRectangle(cornerRadius: 6))
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Decline") { resolve(false) }.keyboardShortcut(.cancelAction)
|
||||
Button("Allow Once") { resolve(true) }
|
||||
}
|
||||
}
|
||||
.padding(18)
|
||||
.frame(width: 500, height: 340)
|
||||
.interactiveDismissDisabled()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user