new features
This commit is contained in:
+179
-14
@@ -312,6 +312,7 @@ struct ChatView: View {
|
||||
studio.activeStack = nil
|
||||
studio.activeRemoteStack = .automatic
|
||||
studio.activeSkill = nil
|
||||
studio.activePrompt = nil
|
||||
studio.activeContext = nil
|
||||
studio.activeWebClip = nil
|
||||
}
|
||||
@@ -644,7 +645,7 @@ private struct ChatResourcesMenu: View {
|
||||
let openWorkspace: () -> Void
|
||||
|
||||
private var count: Int {
|
||||
let local = [target.activeStack, target.activeSkill, target.activeContext, target.activeWebClip].compactMap { $0 }.count
|
||||
let local = [target.activeStack, target.activeSkill, target.activeContext, target.activeWebClip, target.activePrompt].compactMap { $0 }.count
|
||||
if case .server = target.activeRemoteStack { return local + 1 }
|
||||
return local
|
||||
}
|
||||
@@ -660,7 +661,8 @@ private struct ChatResourcesMenu: View {
|
||||
Menu("Remote Stacks") { RemoteStackPicker(studio: target, label: "Remote Stack") }
|
||||
snippetMenu("Skills", kind: .skill, selection: $target.activeSkill)
|
||||
snippetMenu("Contexts", kind: .context, selection: $target.activeContext)
|
||||
Menu("Prompt Library") {
|
||||
snippetMenu("Prompt Templates", kind: .prompt, selection: $target.activePrompt)
|
||||
Menu("Insert Saved Prompt") {
|
||||
let prompts = snippets.filter { $0.kind == .prompt }
|
||||
if prompts.isEmpty { Text("No saved prompts") }
|
||||
ForEach(prompts) { prompt in
|
||||
@@ -881,6 +883,18 @@ struct MessageView: View {
|
||||
.foregroundStyle(.secondary)
|
||||
.accessibilityLabel("Attached document: " + name)
|
||||
}
|
||||
if !message.documentCitations.isEmpty {
|
||||
DisclosureGroup("Document sources") {
|
||||
ForEach(message.documentCitations) { source in
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("[D\(source.number)] \(source.title)").font(.caption.weight(.semibold))
|
||||
Text(source.excerpt).font(.caption).textSelection(.enabled)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !message.webSources.isEmpty {
|
||||
DisclosureGroup(isExpanded: $webSourcesExpanded) {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
@@ -1033,7 +1047,15 @@ struct BackendSettings: View {
|
||||
}
|
||||
}
|
||||
|
||||
private enum SettingsPane {
|
||||
static let storageKey = "studioSettingsPane"
|
||||
static let models = "Models"
|
||||
static let modelLibrary = "Model Library"
|
||||
}
|
||||
|
||||
struct StudioWelcome: View {
|
||||
@Environment(\.openSettings) private var openSettings
|
||||
@AppStorage(SettingsPane.storageKey) private var settingsPane = SettingsPane.models
|
||||
let loading: Bool
|
||||
|
||||
var body: some View {
|
||||
@@ -1052,9 +1074,12 @@ struct StudioWelcome: View {
|
||||
Text("Choose a model in Settings or start with a message below.")
|
||||
.foregroundStyle(.secondary)
|
||||
.multilineTextAlignment(.center)
|
||||
SettingsLink { Label("Model Settings", systemImage: "slider.horizontal.3") }
|
||||
.buttonStyle(.bordered)
|
||||
.padding(.top, 4)
|
||||
Button("Model Settings", systemImage: "slider.horizontal.3") {
|
||||
settingsPane = SettingsPane.modelLibrary
|
||||
openSettings()
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.padding(.top, 4)
|
||||
}
|
||||
}
|
||||
.padding(32)
|
||||
@@ -1355,6 +1380,9 @@ struct GenerationSettingsView: View {
|
||||
}
|
||||
field("Temperature", $draft.temperature)
|
||||
field("Maximum output tokens", $draft.maxTokens)
|
||||
field("Prompt context budget", Binding(
|
||||
get: { draft.promptBudget ?? "" }, set: { draft.promptBudget = $0 }))
|
||||
.help("Estimated input tokens plus the reserved output tokens.")
|
||||
field("Top P", $draft.topP)
|
||||
field("Repeat penalty", $draft.repeatPenalty)
|
||||
field("Repeat window", $draft.repeatLastN)
|
||||
@@ -1839,7 +1867,7 @@ struct WorkspaceResourcesView: View {
|
||||
case stacks = "Knowledge Stacks"
|
||||
case skills = "Skills"
|
||||
case contexts = "Contexts"
|
||||
case prompts = "Prompt Library"
|
||||
case prompts = "Prompt Studio"
|
||||
case clips = "Web Clips"
|
||||
|
||||
var id: Self { self }
|
||||
@@ -2058,6 +2086,9 @@ struct WorkspaceSnippetsView: View {
|
||||
@State private var title = ""
|
||||
@State private var notes = ""
|
||||
@State private var tags = ""
|
||||
@State private var examples: [PromptExample] = []
|
||||
@State private var editingExamples = false
|
||||
@State private var evaluating = false
|
||||
@State private var versions: [PromptVersion] = []
|
||||
@State private var content = ""
|
||||
@State private var address = ""
|
||||
@@ -2101,6 +2132,19 @@ struct WorkspaceSnippetsView: View {
|
||||
if kind == .prompt {
|
||||
TextField("Notes", text: $notes)
|
||||
TextField("Tags (comma-separated)", text: $tags)
|
||||
HStack {
|
||||
Button("Examples (\(examples.count))") { editingExamples = true }
|
||||
Button("Evaluate…") { evaluating = true }
|
||||
.disabled(content.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
|
||||
if let id {
|
||||
Button(isActive ? "Deactivate Template" : "Use as Template") {
|
||||
studio.activePrompt = isActive ? nil : id
|
||||
}
|
||||
.disabled(studio.running)
|
||||
.help("Apply the latest saved version to future chat turns.")
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
if !versions.isEmpty {
|
||||
Menu("Version History") {
|
||||
ForEach(versions) { version in
|
||||
@@ -2109,6 +2153,7 @@ struct WorkspaceSnippetsView: View {
|
||||
content = version.content
|
||||
notes = version.notes
|
||||
tags = version.tags
|
||||
examples = version.examples
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2172,6 +2217,7 @@ struct WorkspaceSnippetsView: View {
|
||||
title = item.title
|
||||
notes = item.notes
|
||||
tags = item.tags
|
||||
examples = item.examples
|
||||
versions = kind == .prompt ? studio.promptVersions(item.id) : []
|
||||
if kind == .webClip {
|
||||
let parts = item.content.components(separatedBy: "\n\n")
|
||||
@@ -2182,6 +2228,12 @@ struct WorkspaceSnippetsView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $editingExamples) {
|
||||
PromptExamplesEditor(examples: examples) { examples = $0 }
|
||||
}
|
||||
.sheet(isPresented: $evaluating) {
|
||||
PromptEvaluationView(studio: studio, template: PromptTemplate(body: content, examples: examples))
|
||||
}
|
||||
.sheet(item: $renderedPage) { page in
|
||||
RenderedClipView(url: page.url) { finalURL, pageTitle, text in
|
||||
address = finalURL.absoluteString
|
||||
@@ -2214,7 +2266,7 @@ struct WorkspaceSnippetsView: View {
|
||||
case .skill: studio.activeSkill == id
|
||||
case .context: studio.activeContext == id
|
||||
case .webClip: studio.activeWebClip == id
|
||||
case .prompt: false
|
||||
case .prompt: studio.activePrompt == id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2236,7 +2288,7 @@ struct WorkspaceSnippetsView: View {
|
||||
let key = id ?? UUID()
|
||||
let stored = kind == .webClip ? "Source: \(address)\n\n\(content)" : content
|
||||
guard studio.saveSnippet(id: key, kind: kind, title: title.trimmingCharacters(in: .whitespacesAndNewlines),
|
||||
content: stored, notes: notes, tags: tags) else {
|
||||
content: stored, notes: notes, tags: tags, examples: examples) else {
|
||||
error = studio.workspaceStatus
|
||||
notice = ""
|
||||
return
|
||||
@@ -2252,7 +2304,7 @@ struct WorkspaceSnippetsView: View {
|
||||
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 .prompt: "Write a prompt template. Use {{input}} to place the input."
|
||||
case .webClip: "Enter a URL and use Capture & Save, or paste an excerpt here."
|
||||
}
|
||||
}
|
||||
@@ -2278,6 +2330,97 @@ struct WorkspaceSnippetsView: View {
|
||||
notes = ""
|
||||
tags = ""
|
||||
versions = []
|
||||
examples = []
|
||||
}
|
||||
}
|
||||
|
||||
private struct PromptExamplesEditor: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@State var examples: [PromptExample]
|
||||
let save: ([PromptExample]) -> Void
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
Form {
|
||||
ForEach(examples.indices, id: \.self) { index in
|
||||
Section {
|
||||
TextField("Input", text: $examples[index].input, axis: .vertical)
|
||||
TextField("Expected assistant response", text: $examples[index].output, axis: .vertical)
|
||||
Button("Remove Example", role: .destructive) { examples.remove(at: index) }
|
||||
}
|
||||
}
|
||||
Button("Add Example", systemImage: "plus") {
|
||||
examples.append(PromptExample(input: "", output: ""))
|
||||
}.disabled(examples.count >= 8)
|
||||
}.formStyle(.grouped)
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Cancel") { dismiss() }.keyboardShortcut(.cancelAction)
|
||||
Button("Apply to Draft") {
|
||||
save(examples)
|
||||
dismiss()
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.disabled(!examples.allSatisfy { $0.isComplete && $0.input.count <= 4_000 && $0.output.count <= 4_000 })
|
||||
}.padding()
|
||||
}.frame(width: 500, height: 420)
|
||||
}
|
||||
}
|
||||
|
||||
private struct PromptEvaluationView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
let studio: StudioModel
|
||||
let template: PromptTemplate
|
||||
@State private var input = ""
|
||||
@State private var expected = ""
|
||||
@State private var output = ""
|
||||
@State private var status = ""
|
||||
@State private var evaluation: Task<Void, Never>?
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
Form {
|
||||
Section("Test Case") {
|
||||
TextField("Input", text: $input, axis: .vertical)
|
||||
TextField("Expected output (optional)", text: $expected, axis: .vertical)
|
||||
LabeledContent("Rendered input") {
|
||||
Text(template.render(input)).textSelection(.enabled)
|
||||
}
|
||||
}
|
||||
if !output.isEmpty || !status.isEmpty {
|
||||
Section("Result") {
|
||||
Text(status)
|
||||
if !output.isEmpty { Text(output).textSelection(.enabled) }
|
||||
}
|
||||
}
|
||||
}.formStyle(.grouped)
|
||||
HStack {
|
||||
Spacer()
|
||||
if evaluation != nil { Button("Stop") { evaluation?.cancel() } }
|
||||
Button("Close") { dismiss() }.keyboardShortcut(.cancelAction)
|
||||
Button("Run Evaluation", action: run)
|
||||
.buttonStyle(.borderedProminent).disabled(evaluation != nil)
|
||||
}.padding()
|
||||
}
|
||||
.frame(width: 580, height: 460)
|
||||
.onDisappear { evaluation?.cancel() }
|
||||
}
|
||||
|
||||
private func run() {
|
||||
let testInput = input
|
||||
let expectedOutput = expected.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
output = ""
|
||||
status = "Running…"
|
||||
evaluation = Task {
|
||||
defer { evaluation = nil }
|
||||
do {
|
||||
output = try await studio.evaluatePrompt(template, input: testInput)
|
||||
status = expectedOutput.isEmpty ? "Completed" :
|
||||
(PromptEvaluation.matches(output, expected: expectedOutput) ? "Passed" : "Output differed")
|
||||
} catch {
|
||||
status = Task.isCancelled ? "Evaluation stopped." : error.localizedDescription
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2383,9 +2526,9 @@ enum StudioFont: String, CaseIterable, Identifiable {
|
||||
|
||||
struct StudioSettingsView: View {
|
||||
@ObservedObject var studio: StudioModel
|
||||
@AppStorage("studioSettingsPane") private var page = "Models"
|
||||
@AppStorage(SettingsPane.storageKey) private var page = SettingsPane.models
|
||||
private let pages = [
|
||||
("Models", "cpu"), ("Model Library", "square.stack"), ("Generation", "slider.horizontal.3"),
|
||||
(SettingsPane.models, "cpu"), (SettingsPane.modelLibrary, "square.stack"), ("Generation", "slider.horizontal.3"),
|
||||
("Knowledge Base", "books.vertical"), ("Toolbox", "wrench.and.screwdriver"), ("Local Tools", "terminal"), ("Runtime", "waveform.path"),
|
||||
("Agents", "person.2"), ("Appearance", "paintpalette"), ("Workspace Data", "externaldrive")
|
||||
]
|
||||
@@ -2405,7 +2548,7 @@ struct StudioSettingsView: View {
|
||||
|
||||
@ViewBuilder private func pane(_ name: String) -> some View {
|
||||
switch name {
|
||||
case "Model Library": ModelCatalogView(studio: studio)
|
||||
case SettingsPane.modelLibrary: ModelCatalogView(studio: studio)
|
||||
case "Agents": AgentSettings(studio: studio)
|
||||
case "Generation": GenerationSettingsView()
|
||||
case "Knowledge Base": PegasusKnowledgeSettings(studio: studio)
|
||||
@@ -3009,6 +3152,8 @@ private struct AgentSettings: View {
|
||||
.sheet(item: $editing) { selection in
|
||||
AgentProfileEditor(
|
||||
profile: selection.profile,
|
||||
promptSettings: selection.profile.promptSettings ?? .init(),
|
||||
templates: studio.snippets.filter { $0.kind == .prompt },
|
||||
save: { updated in
|
||||
if let role = selection.role { saveOverride(updated, for: role) }
|
||||
else { save(updated) }
|
||||
@@ -3071,12 +3216,21 @@ private struct AgentSettings: View {
|
||||
|
||||
private struct AgentProfileEditor: View {
|
||||
@State var profile: AgentProfile
|
||||
@State var promptSettings: AgentPromptSettings
|
||||
let templates: [WorkspaceSnippet]
|
||||
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) }
|
||||
private var validSettings: Bool {
|
||||
do {
|
||||
_ = try PromptBudget.limit(promptSettings.contextBudget)
|
||||
_ = try promptSettings.outputLimit()
|
||||
return true
|
||||
} catch { return false }
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
@@ -3089,6 +3243,16 @@ private struct AgentProfileEditor: View {
|
||||
.border(.quaternary)
|
||||
Text("Describe the work, the evidence to use, and the output to pass to the next agent.")
|
||||
.foregroundStyle(.secondary)
|
||||
Picker("Prompt template", selection: $promptSettings.templateID) {
|
||||
Text("Inherit chat template").tag(nil as UUID?)
|
||||
ForEach(templates) { Text($0.title).tag(Optional($0.id)) }
|
||||
if let id = promptSettings.templateID, !templates.contains(where: { $0.id == id }) {
|
||||
Text("Unavailable template").tag(Optional(id))
|
||||
}
|
||||
}
|
||||
TextField("Context budget (64–1,048,576)", text: $promptSettings.contextBudget)
|
||||
TextField("Maximum output tokens", text: $promptSettings.outputTokens)
|
||||
Toggle("Use local document excerpts", isOn: $promptSettings.useDocuments)
|
||||
HStack {
|
||||
Spacer()
|
||||
if let reset { Button("Restore Default", action: reset) }
|
||||
@@ -3096,14 +3260,15 @@ private struct AgentProfileEditor: View {
|
||||
Button("Save Agent") {
|
||||
profile.name = name
|
||||
profile.instructions = instructions
|
||||
profile.promptSettings = promptSettings
|
||||
save(profile)
|
||||
}
|
||||
.disabled(name.isEmpty || name.count > 60 || instructions.isEmpty || instructions.count > 4_000)
|
||||
.disabled(name.isEmpty || name.count > 60 || instructions.isEmpty || instructions.count > 4_000 || !validSettings)
|
||||
.help("Enter a name of up to 60 characters and instructions of up to 4,000 characters.")
|
||||
}
|
||||
}
|
||||
.padding(18)
|
||||
.frame(width: 510, height: 340)
|
||||
.frame(width: 510, height: 460)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user