ales27pm's picture
Add autonomous on-device iOS assistant
7b2dfc5 verified
Raw
History Blame Contribute Delete
3.87 kB
import AppIntents
/// Opens Dolphin with an inert, sanitized request in the composer.
///
/// Execution intentionally stops at handoff: it does not send the request,
/// load the Core ML model, invoke tools, or request permissions.
struct AskDolphinIntent: AppIntent {
static let title: LocalizedStringResource = "Ask Dolphin"
static let description = IntentDescription(
"Open Dolphin with a request ready to review before sending."
)
// Compatibility path for iOS 18 and 19.
static let openAppWhenRun = true
// On iOS 26, foreground before `perform()` so the handoff remains an
// explicitly visible, user-reviewed action.
@available(iOS 26.0, *)
static var supportedModes: IntentModes { [.foreground(.immediate)] }
@Parameter(
title: "Request",
description: "The question or request to place in Dolphin's composer.",
inputConnectionBehavior: .connectToPreviousIntentResult
)
var request: String
static var parameterSummary: some ParameterSummary {
Summary("Ask Dolphin \(\.$request)")
}
func perform() async throws -> some IntentResult {
// A wrapper-only value is intentionally ignored. `openAppWhenRun` still
// opens Dolphin, but no unsafe text is handed to the conversation.
IntentHandoffStore.store(request)
return .result()
}
}
/// Opens the active local continuity context for review. Like Ask Dolphin, this
/// only prepares inert composer text and never restores or executes by itself.
struct ContinueDolphinIntent: AppIntent {
static let title: LocalizedStringResource = "Continue with Dolphin"
static let description = IntentDescription(
"Open Dolphin with a project-context request ready to review."
)
static let openAppWhenRun = true
@available(iOS 26.0, *)
static var supportedModes: IntentModes { [.foreground(.immediate)] }
func perform() async throws -> some IntentResult {
IntentHandoffStore.store("Show project context")
return .result()
}
}
/// Prepares an explicit structured-capture command. The user still reviews,
/// sends, and approves the exact local write in Dolphin.
struct CaptureDolphinContextIntent: AppIntent {
static let title: LocalizedStringResource = "Capture Dolphin Context"
static let description = IntentDescription(
"Open Dolphin with a local context note ready to review and save."
)
static let openAppWhenRun = true
@available(iOS 26.0, *)
static var supportedModes: IntentModes { [.foreground(.immediate)] }
@Parameter(
title: "Context",
description: "The context note to prepare for capture.",
inputConnectionBehavior: .connectToPreviousIntentResult
)
var context: String
static var parameterSummary: some ParameterSummary {
Summary("Capture \(\.$context) in Dolphin")
}
func perform() async throws -> some IntentResult {
IntentHandoffStore.store("Capture context: \(context)")
return .result()
}
}
struct DolphinShortcutsProvider: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: AskDolphinIntent(),
phrases: [
"Ask \(.applicationName)",
"Start a request in \(.applicationName)",
],
shortTitle: "Ask Dolphin",
systemImageName: "bubble.left.and.text.bubble.right"
)
AppShortcut(
intent: ContinueDolphinIntent(),
phrases: [
"Continue with \(.applicationName)",
"Show context in \(.applicationName)",
],
shortTitle: "Continue Dolphin",
systemImageName: "arrow.triangle.branch"
)
AppShortcut(
intent: CaptureDolphinContextIntent(),
phrases: [
"Capture context in \(.applicationName)",
"Save context with \(.applicationName)",
],
shortTitle: "Capture Context",
systemImageName: "square.and.pencil"
)
}
static let shortcutTileColor: ShortcutTileColor = .blue
}