Skip to content

Commit a0e9e86

Browse files
authored
Merge pull request #123 from rudrankriyam/codex/stack-4-9-shared-capabilities
Share FoundationLabCore capabilities across app, App Intents, and CLI
2 parents 3dd0e5e + 70aec2d commit a0e9e86

File tree

215 files changed

+10543
-2563
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+10543
-2563
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import AppIntents
2+
import Foundation
3+
import FoundationLabCore
4+
5+
struct AnalyzeNutritionIntent: AppIntent {
6+
static let title: LocalizedStringResource = "Analyze Nutrition"
7+
static let description = IntentDescription(
8+
"Analyzes meal nutrition using Foundation Lab's shared nutrition capability."
9+
)
10+
static let openAppWhenRun = false
11+
12+
@Parameter(
13+
title: "Meal Description",
14+
requestValueDialog: IntentDialog("What meal should I analyze?")
15+
)
16+
var mealDescription: String
17+
18+
@Parameter(title: "Response Language")
19+
var responseLanguage: String?
20+
21+
func perform() async throws -> some IntentResult & ReturnsValue<String> {
22+
let trimmedResponseLanguage = responseLanguage?.trimmingCharacters(in: .whitespacesAndNewlines)
23+
let response = try await AnalyzeNutritionUseCase().execute(
24+
AnalyzeNutritionRequest(
25+
foodDescription: mealDescription,
26+
responseLanguage: trimmedResponseLanguage?.isEmpty == false ? trimmedResponseLanguage! : "English",
27+
context: CapabilityInvocationContext(
28+
source: .appIntent,
29+
localeIdentifier: Locale.current.identifier
30+
)
31+
)
32+
)
33+
34+
return .result(value: response.analysis.insights)
35+
}
36+
}

Foundation Lab/AppIntents/FoundationLabAppShortcuts.swift

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,94 @@ import AppIntents
1010
nonisolated struct FoundationLabAppShortcuts: AppShortcutsProvider {
1111
static var appShortcuts: [AppShortcut] {
1212
AppShortcut(
13-
intent: OpenChatIntent(),
13+
intent: GenerateBookRecommendationIntent(),
1414
phrases: [
15-
"Open \(.applicationName) chat",
16-
"Start chatting in \(.applicationName)",
17-
"Open chat in \(.applicationName)"
15+
"Recommend a book in \(.applicationName)",
16+
"Get a book recommendation from \(.applicationName)"
1817
],
19-
shortTitle: "Open Chat",
20-
systemImageName: "message.fill"
18+
shortTitle: "Recommend Book",
19+
systemImageName: "book.closed.fill"
2120
)
2221
AppShortcut(
23-
intent: OpenExampleIntent(),
22+
intent: GetWeatherIntent(),
2423
phrases: [
25-
"Open \(\.$example) in \(.applicationName)",
26-
"Show \(\.$example) in \(.applicationName)"
24+
"Get the weather in \(.applicationName)",
25+
"Check weather with \(.applicationName)"
2726
],
28-
shortTitle: "Open Example",
29-
systemImageName: "sparkles"
27+
shortTitle: "Get Weather",
28+
systemImageName: "cloud.sun.fill"
3029
)
3130
AppShortcut(
32-
intent: OpenToolIntent(),
31+
intent: AnalyzeNutritionIntent(),
3332
phrases: [
34-
"Open \(\.$tool) tool in \(.applicationName)",
35-
"Show \(\.$tool) in \(.applicationName)"
33+
"Analyze nutrition in \(.applicationName)",
34+
"Check calories with \(.applicationName)"
3635
],
37-
shortTitle: "Open Tool",
38-
systemImageName: "wrench.and.screwdriver"
36+
shortTitle: "Analyze Nutrition",
37+
systemImageName: "fork.knife"
3938
)
4039
AppShortcut(
41-
intent: OpenSchemaIntent(),
40+
intent: SearchWebIntent(),
4241
phrases: [
43-
"Open \(\.$schema) in \(.applicationName)",
44-
"Show \(\.$schema) in \(.applicationName)"
42+
"Search the web in \(.applicationName)",
43+
"Look something up with \(.applicationName)"
4544
],
46-
shortTitle: "Open Schema",
47-
systemImageName: "doc.text"
45+
shortTitle: "Search Web",
46+
systemImageName: "magnifyingglass"
4847
)
4948
AppShortcut(
50-
intent: OpenLanguageIntent(),
49+
intent: SearchContactsIntent(),
5150
phrases: [
52-
"Open \(\.$language) in \(.applicationName)",
53-
"Show \(\.$language) in \(.applicationName)"
51+
"Search contacts in \(.applicationName)",
52+
"Find someone with \(.applicationName)"
5453
],
55-
shortTitle: "Open Language",
56-
systemImageName: "globe"
54+
shortTitle: "Search Contacts",
55+
systemImageName: "person.crop.circle"
56+
)
57+
AppShortcut(
58+
intent: QueryCalendarIntent(),
59+
phrases: [
60+
"Check my calendar in \(.applicationName)",
61+
"Ask calendar with \(.applicationName)"
62+
],
63+
shortTitle: "Query Calendar",
64+
systemImageName: "calendar"
65+
)
66+
AppShortcut(
67+
intent: ManageRemindersIntent(),
68+
phrases: [
69+
"Manage reminders in \(.applicationName)",
70+
"Create a reminder with \(.applicationName)"
71+
],
72+
shortTitle: "Manage Reminders",
73+
systemImageName: "checklist"
74+
)
75+
AppShortcut(
76+
intent: GetCurrentLocationIntent(),
77+
phrases: [
78+
"Get my location in \(.applicationName)",
79+
"Check location with \(.applicationName)"
80+
],
81+
shortTitle: "Get Location",
82+
systemImageName: "location"
83+
)
84+
AppShortcut(
85+
intent: SearchMusicCatalogIntent(),
86+
phrases: [
87+
"Search music in \(.applicationName)",
88+
"Find music with \(.applicationName)"
89+
],
90+
shortTitle: "Search Music",
91+
systemImageName: "music.note"
92+
)
93+
AppShortcut(
94+
intent: QueryHealthDataIntent(),
95+
phrases: [
96+
"Check health data in \(.applicationName)",
97+
"Ask health data with \(.applicationName)"
98+
],
99+
shortTitle: "Query Health",
100+
systemImageName: "heart.text.square"
57101
)
58102
}
59103
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// GenerateBookRecommendationIntent.swift
3+
// FoundationLab
4+
//
5+
// Created by Codex on 3/15/26.
6+
//
7+
8+
import AppIntents
9+
import Foundation
10+
import FoundationLabCore
11+
12+
struct GenerateBookRecommendationIntent: AppIntent {
13+
static let title: LocalizedStringResource = "Generate Book Recommendation"
14+
static let description = IntentDescription(
15+
"Generates a book recommendation using Foundation Lab's shared capability."
16+
)
17+
static let openAppWhenRun = false
18+
19+
@Parameter(
20+
title: "Prompt",
21+
requestValueDialog: IntentDialog("What kind of book recommendation would you like?")
22+
)
23+
var prompt: String
24+
25+
@Parameter(title: "Instructions")
26+
var systemPrompt: String?
27+
28+
static var parameterSummary: some ParameterSummary {
29+
Summary("Generate a book recommendation for \(\.$prompt)")
30+
}
31+
32+
func perform() async throws -> some IntentResult & ReturnsValue<String> {
33+
let response = try await GenerateBookRecommendationUseCase().execute(
34+
GenerateBookRecommendationRequest(
35+
prompt: prompt,
36+
systemPrompt: systemPrompt,
37+
context: CapabilityInvocationContext(
38+
source: .appIntent,
39+
localeIdentifier: Locale.current.identifier
40+
)
41+
)
42+
)
43+
44+
return .result(value: response.recommendation.plainTextSummary)
45+
}
46+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import AppIntents
2+
import Foundation
3+
import FoundationLabCore
4+
5+
struct GenerateLocalizedResponseIntent: AppIntent {
6+
static let title: LocalizedStringResource = "Generate Localized Response"
7+
static let description = IntentDescription(
8+
"Generates a response in one of the languages supported by Foundation Lab."
9+
)
10+
static let openAppWhenRun = false
11+
12+
@Parameter(
13+
title: "Language",
14+
requestValueDialog: IntentDialog("Which supported language should I use?")
15+
)
16+
var language: SupportedLanguageEntity
17+
18+
@Parameter(
19+
title: "Prompt",
20+
requestValueDialog: IntentDialog("What should I respond to?")
21+
)
22+
var prompt: String
23+
24+
@Parameter(title: "Instructions")
25+
var systemPrompt: String?
26+
27+
static var parameterSummary: some ParameterSummary {
28+
Summary("Respond to \(\.$prompt) in \(\.$language)")
29+
}
30+
31+
func perform() async throws -> some IntentResult & ReturnsValue<String> {
32+
let localeInstruction = "Respond in \(language.displayName). Prefer natural wording for that locale."
33+
let trimmedSystemPrompt = systemPrompt?.trimmingCharacters(in: .whitespacesAndNewlines)
34+
let mergedSystemPrompt = [trimmedSystemPrompt, localeInstruction]
35+
.compactMap { value in
36+
guard let value, !value.isEmpty else { return nil }
37+
return value
38+
}
39+
.joined(separator: "\n\n")
40+
41+
let result = try await GenerateTextUseCase().execute(
42+
TextGenerationRequest(
43+
prompt: prompt,
44+
systemPrompt: mergedSystemPrompt.isEmpty ? nil : mergedSystemPrompt,
45+
context: CapabilityInvocationContext(
46+
source: .appIntent,
47+
localeIdentifier: Locale.current.identifier
48+
)
49+
)
50+
)
51+
52+
return .result(value: result.content)
53+
}
54+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import AppIntents
2+
import Foundation
3+
import FoundationLabCore
4+
5+
struct GenerateWebPageSummaryIntent: AppIntent {
6+
static let title: LocalizedStringResource = "Generate Web Page Summary"
7+
static let description = IntentDescription(
8+
"Summarizes a web page using Foundation Lab's shared web metadata capability."
9+
)
10+
static let openAppWhenRun = false
11+
12+
@Parameter(
13+
title: "URL",
14+
requestValueDialog: IntentDialog("Which web page do you want to summarize?")
15+
)
16+
var url: String
17+
18+
func perform() async throws -> some IntentResult & ReturnsValue<String> {
19+
let response = try await GenerateWebPageSummaryUseCase().execute(
20+
GenerateWebPageSummaryRequest(
21+
url: url,
22+
context: CapabilityInvocationContext(
23+
source: .appIntent,
24+
localeIdentifier: Locale.current.identifier
25+
)
26+
)
27+
)
28+
29+
return .result(value: response.content)
30+
}
31+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import AppIntents
2+
import Foundation
3+
import FoundationLabCore
4+
5+
struct GetCurrentLocationIntent: AppIntent {
6+
static let title: LocalizedStringResource = "Get Current Location"
7+
static let description = IntentDescription(
8+
"Gets your current location using Foundation Lab's shared location capability."
9+
)
10+
static let openAppWhenRun = true
11+
12+
func perform() async throws -> some IntentResult & ReturnsValue<String> {
13+
let response = try await GetCurrentLocationUseCase().execute(
14+
GetCurrentLocationRequest(
15+
context: CapabilityInvocationContext(
16+
source: .appIntent,
17+
localeIdentifier: Locale.current.identifier
18+
)
19+
)
20+
)
21+
22+
return .result(value: response.content)
23+
}
24+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import AppIntents
2+
import Foundation
3+
import FoundationLabCore
4+
5+
struct GetWeatherIntent: AppIntent {
6+
static let title: LocalizedStringResource = "Get Weather"
7+
static let description = IntentDescription(
8+
"Gets the latest weather information using Foundation Lab's shared weather capability."
9+
)
10+
static let openAppWhenRun = false
11+
12+
@Parameter(
13+
title: "Location",
14+
requestValueDialog: IntentDialog("Which location do you want weather information for?")
15+
)
16+
var location: String
17+
18+
func perform() async throws -> some IntentResult & ReturnsValue<String> {
19+
let response = try await GetWeatherUseCase().execute(
20+
GetWeatherRequest(
21+
location: location,
22+
context: CapabilityInvocationContext(
23+
source: .appIntent,
24+
localeIdentifier: Locale.current.identifier
25+
)
26+
)
27+
)
28+
29+
return .result(value: response.content)
30+
}
31+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import AppIntents
2+
import Foundation
3+
import FoundationLabCore
4+
5+
struct ManageRemindersIntent: AppIntent {
6+
static let title: LocalizedStringResource = "Manage Reminders"
7+
static let description = IntentDescription(
8+
"Creates or manages reminders using Foundation Lab's shared reminders capability."
9+
)
10+
static let openAppWhenRun = true
11+
12+
@Parameter(
13+
title: "Request",
14+
requestValueDialog: IntentDialog("What would you like to do with reminders?")
15+
)
16+
var prompt: String
17+
18+
func perform() async throws -> some IntentResult & ReturnsValue<String> {
19+
let response = try await ManageRemindersUseCase().execute(
20+
ManageRemindersRequest(
21+
mode: .customPrompt,
22+
customPrompt: prompt,
23+
referenceDate: .now,
24+
timeZoneIdentifier: TimeZone.current.identifier,
25+
context: CapabilityInvocationContext(
26+
source: .appIntent,
27+
localeIdentifier: Locale.current.identifier
28+
)
29+
)
30+
)
31+
32+
return .result(value: response.content)
33+
}
34+
}

0 commit comments

Comments
 (0)