expo-syrup-ai-kit 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -9
- package/package.json +1 -1
- package/plugin/build/index.js +1 -1
- package/plugin/build/siriTools/declaration.d.ts +4 -0
- package/plugin/build/siriTools/declaration.js +7 -1
- package/plugin/build/siriTools/swift.d.ts +4 -1
- package/plugin/build/siriTools/swift.js +17 -3
- package/plugin/build/withSiriAIPreview.d.ts +10 -1
- package/plugin/build/withSiriAIPreview.js +15 -3
- package/skills/expo-syrup-ai-kit/SKILL.md +17 -6
- package/skills/siri-ai-discover/SKILL.md +5 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# expo-syrup-ai-kit
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/expo-syrup-ai-kit)
|
|
4
|
+
|
|
3
5
|
The Expo plugin for Syrup AI Kit: Siri AI tools for Expo and React Native apps. Formerly `expo-siri-ai-kit`.
|
|
4
6
|
|
|
5
7
|
Make your Expo or React Native app work with Siri AI. This Expo config plugin for [Syrup AI Kit](https://github.com/airowe/syrup-ai-kit) lets the Swift tools in your app use SyrupAIKit, and turns on the Siri AI Developer Preview code (iOS 27.3 beta).
|
|
@@ -13,6 +15,7 @@ Not affiliated with or endorsed by Apple.
|
|
|
13
15
|
- **Adds SyrupAIKit** as a Swift package and links it to your app target. That's where [`expo-app-intents`](https://docs.expo.dev/versions/latest/sdk/app-intents) compiles the Swift in `app-intents/`, so your tools can `import SyrupAIKit`.
|
|
14
16
|
- **With the preview on, it also:**
|
|
15
17
|
- adds the `SIRI_AI_PREVIEW` Swift compilation condition, so `#if SIRI_AI_PREVIEW` code builds only with the 27.3 SDK;
|
|
18
|
+
- lets `xcodebuild` add the `SIRI_AI_EVAL_SWITCHES` condition when you pass `SIRI_AI_EVAL_SWITCHES=YES`, for [negative controls](#negative-controls-in-an-expo-app);
|
|
16
19
|
- sets the app target's deployment target to iOS 27.3, which `@Property(title:description:)` requires. Pods keep their own targets.
|
|
17
20
|
- **With `evals` set, adds a UI test target for Siri Evaluations** (see [Evaluation target](#evaluation-target)), so it survives `prebuild --clean`.
|
|
18
21
|
- **With `skills` set, checks your Apple App Skills and adds them to the app as `Skills.skillsbundle`** (see [App Skills](#app-skills)).
|
|
@@ -25,8 +28,11 @@ The full setup, including the Mac, the iPhone and a checklist for coding agents,
|
|
|
25
28
|
|
|
26
29
|
```bash
|
|
27
30
|
npx expo install expo-syrup-ai-kit expo-app-intents
|
|
31
|
+
npx expo-app-intents init --examples minimal
|
|
28
32
|
```
|
|
29
33
|
|
|
34
|
+
`init` creates `app-intents/AppIntentsSetup.swift`, the inline module used in [Showing the tool's outcome](#showing-the-tools-outcome-in-your-app), and turns on inline modules in `app.json`. `npx expo install` adds both plugins; list them in this order:
|
|
35
|
+
|
|
30
36
|
```json
|
|
31
37
|
{
|
|
32
38
|
"expo": {
|
|
@@ -38,13 +44,15 @@ npx expo install expo-syrup-ai-kit expo-app-intents
|
|
|
38
44
|
Then prebuild with the preview on:
|
|
39
45
|
|
|
40
46
|
```bash
|
|
41
|
-
SIRI_AI_PREVIEW=1 npx expo prebuild -p ios
|
|
47
|
+
SIRI_AI_PREVIEW=1 CP_CACHE_DIR="$PWD/.cp-cache" LANG=en_US.UTF-8 npx expo prebuild -p ios
|
|
42
48
|
```
|
|
43
49
|
|
|
50
|
+
`CP_CACHE_DIR` gives CocoaPods a cache of its own, which avoids a missing-`Info.plist` failure from a broken shared cache. `LANG` avoids a CocoaPods encoding error.
|
|
51
|
+
|
|
44
52
|
## Options
|
|
45
53
|
|
|
46
54
|
```json
|
|
47
|
-
["expo-syrup-ai-kit", { "version": "0.
|
|
55
|
+
["expo-syrup-ai-kit", { "version": "0.4.0", "preview": true }]
|
|
48
56
|
```
|
|
49
57
|
|
|
50
58
|
| Option | Default | What it does |
|
|
@@ -74,11 +82,37 @@ On every prebuild the plugin adds a `<AppName>Evals` UI test target that:
|
|
|
74
82
|
Run the evaluations on an iPhone on iOS 27.3 with Siri AI on:
|
|
75
83
|
|
|
76
84
|
```bash
|
|
77
|
-
xcodebuild test -workspace ios/MyApp.xcworkspace -scheme MyAppEvals -
|
|
85
|
+
xcodebuild test -workspace ios/MyApp.xcworkspace -scheme MyAppEvals -configuration Release \
|
|
86
|
+
-destination 'platform=iOS,name=My iPhone' -resultBundlePath evals.xcresult
|
|
78
87
|
```
|
|
79
88
|
|
|
89
|
+
Use Release so the JavaScript is in the app. A Debug build loads it from the dev server, so it only starts while `npx expo start` is running.
|
|
90
|
+
|
|
80
91
|
Prebuild fails with a clear message if `sourceDir` doesn't exist or has no `.swift` files. The file list is read at prebuild, so prebuild again after adding or removing a test file.
|
|
81
92
|
|
|
93
|
+
### Negative controls in an Expo app
|
|
94
|
+
|
|
95
|
+
A negative control launches the app with an `EvalSwitch` that breaks the tool, and checks that the reply check fails (see the [SyrupAIKit README](https://github.com/airowe/syrup-ai-kit#prove-the-checks-can-fail-and-measure-without-the-apps-name)). The usual `#if DEBUG` guard around the switch doesn't work here: the evaluations run a Release build, which compiles that code out, so the tool never breaks and the control fails.
|
|
96
|
+
|
|
97
|
+
With the preview on, the plugin lets you add a `SIRI_AI_EVAL_SWITCHES` condition to one `xcodebuild` run. Guard the switch with it:
|
|
98
|
+
|
|
99
|
+
```swift
|
|
100
|
+
#if DEBUG || SIRI_AI_EVAL_SWITCHES
|
|
101
|
+
if EvalSwitch.badHost.isOn() { return URL(string: "https://unreachable.invalid")! }
|
|
102
|
+
#endif
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
and pass `SIRI_AI_EVAL_SWITCHES=YES` when you run the evaluations:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
xcodebuild test -workspace ios/MyApp.xcworkspace -scheme MyAppEvals -configuration Release \
|
|
109
|
+
-destination 'platform=iOS,name=My iPhone' -resultBundlePath evals.xcresult SIRI_AI_EVAL_SWITCHES=YES
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Only a build given `SIRI_AI_EVAL_SWITCHES=YES` compiles the check. `eas build`, an Xcode archive and any other build leave it out, so no copy of the app a person installs can be broken by a launch argument. Forgetting the setting is safe too: the switch does nothing, and the negative control fails, which tells you.
|
|
113
|
+
|
|
114
|
+
Tools from the [`tools` option](#generating-tools-from-a-declaration-experimental) honour the switch named `bad-host`: with it on, every generated tool calls `https://siri-ai-eval-bad-host.invalid`, which never resolves, and Siri says it couldn't reach the app. Define `static let badHost: EvalSwitch = "bad-host"` in your evaluation tests and use it in `ToolEvaluation.negativeControl(turningOn: .badHost, …)` with the same scenario as the tool's required evaluation.
|
|
115
|
+
|
|
82
116
|
## App Skills
|
|
83
117
|
|
|
84
118
|
An App Skill is a short Markdown guide that tells Siri how to use several of your tools together, such as "search, add to the cart, then check out". Keep them in a folder at the project root:
|
|
@@ -111,6 +145,8 @@ Prebuild stops, listing every problem, if a skill breaks Apple's rules. Xcode it
|
|
|
111
145
|
- The body is at most 10,000 characters.
|
|
112
146
|
- Each skill folder holds only its `SKILL.md`.
|
|
113
147
|
|
|
148
|
+
**A skill only helps if Siri can chain your tools, and today it can't chain a tool that returns a dialog.** Such a tool returns `.result(value:dialog:)`, as in [A first tool](#a-first-tool), and so does every tool the `tools` option generates unless it sets `"returns": "value"`. On a phone, Siri speaks a dialog and ends the turn. Tools that return only `.result(value:)` let Siri call one after another, and in the same test Siri chained them with or without a skill. The skill changed only how Siri worded the answer. So every tool a skill names should return only `.result(value:)`: in Swift, drop `ProvidesDialog` and the `dialog:` argument; in a declaration, set `"returns": "value"`. See [docs/spikes/app-skills-bundle.md](https://github.com/airowe/syrup-ai-kit/blob/main/docs/spikes/app-skills-bundle.md#device-runs) and [#31](https://github.com/airowe/syrup-ai-kit/issues/31).
|
|
149
|
+
|
|
114
150
|
Skills guide Siri; they don't guarantee it follows the steps in order. Nothing checks that a skill names tools your app has, so test the flow with a Siri evaluation. App Skills are part of the Siri AI Developer Preview, with the same limits on who can use them (see the [SyrupAIKit README](https://github.com/airowe/syrup-ai-kit#readme)).
|
|
115
151
|
|
|
116
152
|
## A first tool
|
|
@@ -121,7 +157,7 @@ import AppIntents
|
|
|
121
157
|
import Foundation
|
|
122
158
|
import SyrupAIKit
|
|
123
159
|
|
|
124
|
-
private let tool = SiriTool(appName: "
|
|
160
|
+
private let tool = SiriTool(appName: "Sample App")
|
|
125
161
|
|
|
126
162
|
#if SIRI_AI_PREVIEW
|
|
127
163
|
@AppIntent(.tool)
|
|
@@ -176,7 +212,12 @@ Instead of writing Swift, list tools that call your HTTP API in a JSON file and
|
|
|
176
212
|
|
|
177
213
|
A parameter's optional `description` is one line saying what the person gives, with an example. Siri reads it to fill the value.
|
|
178
214
|
|
|
179
|
-
|
|
215
|
+
A tool's optional `returns` says what Siri gets back:
|
|
216
|
+
|
|
217
|
+
- `"dialog"` (the default): Siri says the reply word for word and ends its turn.
|
|
218
|
+
- `"value"`: Siri gets the reply to use, words the answer itself, and can call another tool first. Use it for tools an [App Skill](#app-skills) names, or any tool Siri should combine with others.
|
|
219
|
+
|
|
220
|
+
At prebuild the plugin writes one Swift tool per entry, plus a shared `SiriToolsGenerated.swift`, to `ios/<App>/SiriTools/` and compiles that folder into the app target. A bad declaration stops prebuild with every problem listed. Each generated tool breaks when an evaluation turns on the `bad-host` switch, for a [negative control](#negative-controls-in-an-expo-app). The format, what it supports and what's still open are in [docs/spikes/tool-codegen.md](../docs/spikes/tool-codegen.md).
|
|
180
221
|
|
|
181
222
|
## Implementing the tools discovery proposes
|
|
182
223
|
|
|
@@ -188,15 +229,45 @@ The `siri-ai-discover` skill writes each tool's interface to `siri-tools.json`,
|
|
|
188
229
|
|
|
189
230
|
## Showing the tool's outcome in your app
|
|
190
231
|
|
|
191
|
-
Siri Evaluations read the
|
|
232
|
+
Siri Evaluations read the tool calls from the screen: every call since the evaluation launched the app, oldest first. Expose it from your `AppIntentsSetup` inline module, the one `npx expo-app-intents init` created:
|
|
192
233
|
|
|
193
234
|
```swift
|
|
194
|
-
|
|
195
|
-
|
|
235
|
+
// app-intents/AppIntentsSetup.swift
|
|
236
|
+
internal import ExpoAppIntents
|
|
237
|
+
internal import ExpoModulesCore
|
|
238
|
+
import SyrupAIKit
|
|
239
|
+
|
|
240
|
+
final class AppIntentsSetup: Module {
|
|
241
|
+
public func definition() -> ExpoModulesCore.ModuleDefinition {
|
|
242
|
+
Name("AppIntentsSetup")
|
|
243
|
+
|
|
244
|
+
Function("siriToolOutcome") { () -> String in
|
|
245
|
+
ToolOutcomeLog.standard.summary
|
|
246
|
+
}
|
|
247
|
+
}
|
|
196
248
|
}
|
|
197
249
|
```
|
|
198
250
|
|
|
199
|
-
|
|
251
|
+
Import `SyrupAIKit` the same way in every file in `app-intents/`. Here it's a plain `import`, as in [A first tool](#a-first-tool). If one file says `internal import SyrupAIKit` and another `import SyrupAIKit`, the build fails with "ambiguous implicit access level".
|
|
252
|
+
|
|
253
|
+
Then show it on a screen that's always visible, with `testID="siri-ai-tool-outcome"`:
|
|
254
|
+
|
|
255
|
+
```tsx
|
|
256
|
+
import { requireNativeModule } from 'expo';
|
|
257
|
+
import { useEffect, useState } from 'react';
|
|
258
|
+
import { Text } from 'react-native';
|
|
259
|
+
|
|
260
|
+
const Setup = requireNativeModule<{ siriToolOutcome(): string }>('AppIntentsSetup');
|
|
261
|
+
|
|
262
|
+
export function SiriToolOutcome() {
|
|
263
|
+
const [outcome, setOutcome] = useState(Setup.siriToolOutcome());
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
const poll = setInterval(() => setOutcome(Setup.siriToolOutcome()), 1000);
|
|
266
|
+
return () => clearInterval(poll);
|
|
267
|
+
}, []);
|
|
268
|
+
return <Text testID="siri-ai-tool-outcome">{outcome}</Text>;
|
|
269
|
+
}
|
|
270
|
+
```
|
|
200
271
|
|
|
201
272
|
## Agent skills
|
|
202
273
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-syrup-ai-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Make your Expo or React Native app work with Siri AI: the Expo config plugin for Syrup AI Kit and Apple's Siri AI Developer Preview, with agent skills.",
|
|
5
5
|
"main": "app.plugin.js",
|
|
6
6
|
"types": "plugin/build/index.d.ts",
|
package/plugin/build/index.js
CHANGED
|
@@ -12,7 +12,7 @@ const withSiriSkills_1 = require("./withSiriSkills");
|
|
|
12
12
|
const withSiriTools_1 = require("./withSiriTools");
|
|
13
13
|
const pkg = require('../../package.json');
|
|
14
14
|
/** The SyrupAIKit release this plugin version was tested with. */
|
|
15
|
-
const DEFAULT_VERSION = '0.
|
|
15
|
+
const DEFAULT_VERSION = '0.4.0';
|
|
16
16
|
function requirementFrom(props) {
|
|
17
17
|
if (props.version && props.branch) {
|
|
18
18
|
throw new Error('expo-syrup-ai-kit: pass either `version` or `branch`, not both');
|
|
@@ -19,6 +19,9 @@ export type ToolRequest = {
|
|
|
19
19
|
url: string;
|
|
20
20
|
body: string[];
|
|
21
21
|
};
|
|
22
|
+
/** `dialog`: Siri speaks the reply and ends the turn. `value`: Siri gets the reply to use, so it can chain tools. */
|
|
23
|
+
declare const RETURNS: readonly ["dialog", "value"];
|
|
24
|
+
export type ToolReturns = (typeof RETURNS)[number];
|
|
22
25
|
export type ToolDeclaration = {
|
|
23
26
|
name: string;
|
|
24
27
|
title: string;
|
|
@@ -26,6 +29,7 @@ export type ToolDeclaration = {
|
|
|
26
29
|
parameters: ToolParameter[];
|
|
27
30
|
request: ToolRequest;
|
|
28
31
|
reply: string;
|
|
32
|
+
returns: ToolReturns;
|
|
29
33
|
};
|
|
30
34
|
export type SiriToolsDeclaration = {
|
|
31
35
|
appName?: string;
|
|
@@ -8,6 +8,8 @@ exports.parseSiriTools = parseSiriTools;
|
|
|
8
8
|
exports.SCALAR_TYPES = ['string', 'int', 'double', 'bool', 'date'];
|
|
9
9
|
const PARAMETER_TYPES = [...exports.SCALAR_TYPES, 'enum'];
|
|
10
10
|
const METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
|
11
|
+
/** `dialog`: Siri speaks the reply and ends the turn. `value`: Siri gets the reply to use, so it can chain tools. */
|
|
12
|
+
const RETURNS = ['dialog', 'value'];
|
|
11
13
|
const TYPE_NAME = /^[A-Z][A-Za-z0-9]*$/;
|
|
12
14
|
const PROPERTY_NAME = /^[a-z][A-Za-z0-9]*$/;
|
|
13
15
|
const FIELD_PATH = /^[A-Za-z0-9_]+(\.[A-Za-z0-9_]+)*$/;
|
|
@@ -17,7 +19,7 @@ const RESERVED = new Set(('associatedtype class deinit enum extension fileprivat
|
|
|
17
19
|
'private precedencegroup protocol public rethrows static struct subscript typealias var break case catch ' +
|
|
18
20
|
'continue default defer do else fallthrough for guard if in repeat return throw switch where while as Any ' +
|
|
19
21
|
'await false is nil self Self super throws true try title description perform').split(' '));
|
|
20
|
-
const TOOL_FIELDS = ['name', 'title', 'description', 'parameters', 'request', 'reply'];
|
|
22
|
+
const TOOL_FIELDS = ['name', 'title', 'description', 'parameters', 'request', 'reply', 'returns'];
|
|
21
23
|
const PARAMETER_FIELDS = ['name', 'type', 'title', 'description', 'cases'];
|
|
22
24
|
const REQUEST_FIELDS = ['method', 'url', 'body'];
|
|
23
25
|
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
@@ -161,6 +163,9 @@ function toolProblems(tool, path) {
|
|
|
161
163
|
...requestProblems(tool.request, names.filter((name) => typeof name === 'string'), `${path}.request`),
|
|
162
164
|
...unusedParameterProblems(tool, parameters, path),
|
|
163
165
|
...replyProblems(tool.reply, `${path}.reply`),
|
|
166
|
+
...(tool.returns === undefined || RETURNS.includes(tool.returns)
|
|
167
|
+
? []
|
|
168
|
+
: [`${path}.returns: must be "dialog" or "value"`]),
|
|
164
169
|
];
|
|
165
170
|
}
|
|
166
171
|
/** Every problem with a declaration, in a form a person can fix from; empty when it's valid. */
|
|
@@ -192,6 +197,7 @@ function withDefaults(tool) {
|
|
|
192
197
|
body: (request.body ?? []),
|
|
193
198
|
},
|
|
194
199
|
reply: tool.reply,
|
|
200
|
+
returns: (tool.returns ?? 'dialog'),
|
|
195
201
|
};
|
|
196
202
|
}
|
|
197
203
|
/** The declaration with defaults filled in, or an error listing every problem in `source`. */
|
|
@@ -6,7 +6,10 @@ export type GeneratedFile = {
|
|
|
6
6
|
export declare const SUPPORT_FILE = "SiriToolsGenerated.swift";
|
|
7
7
|
/** A Swift string literal that reads exactly as `value`, with nothing interpolated. */
|
|
8
8
|
export declare function swiftString(value: string): string;
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* One tool intent: Siri fills the parameters, the intent calls the API, and the reply template becomes the answer.
|
|
11
|
+
* A `dialog` tool has Siri speak the answer and end the turn; a `value` tool hands it to Siri, which can chain tools.
|
|
12
|
+
*/
|
|
10
13
|
export declare function toolSwift(tool: ToolDeclaration): string;
|
|
11
14
|
/** Code every generated tool shares: the `SiriTool`, the HTTP request and the reply template. */
|
|
12
15
|
export declare function supportSwift(appName: string): string;
|
|
@@ -60,7 +60,10 @@ ${displays.join('')} ]
|
|
|
60
60
|
}
|
|
61
61
|
`;
|
|
62
62
|
}
|
|
63
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* One tool intent: Siri fills the parameters, the intent calls the API, and the reply template becomes the answer.
|
|
65
|
+
* A `dialog` tool has Siri speak the answer and end the turn; a `value` tool hands it to Siri, which can chain tools.
|
|
66
|
+
*/
|
|
64
67
|
function toolSwift(tool) {
|
|
65
68
|
const enums = tool.parameters.flatMap((parameter) => (parameter.type === 'enum' ? [enumSwift(tool, parameter)] : []));
|
|
66
69
|
return `${HEADER}
|
|
@@ -74,7 +77,7 @@ struct ${intentName(tool)}: AppIntent {
|
|
|
74
77
|
static let title: LocalizedStringResource = ${swiftString(tool.title)}
|
|
75
78
|
static let description = IntentDescription(${swiftString(tool.description)})
|
|
76
79
|
${tool.parameters.map((parameter) => parameterSwift(tool, parameter)).join('')}
|
|
77
|
-
func perform() async throws -> some IntentResult & ReturnsValue<String
|
|
80
|
+
func perform() async throws -> some IntentResult & ReturnsValue<String>${tool.returns === 'dialog' ? ' & ProvidesDialog' : ''} {
|
|
78
81
|
let request = SiriToolsGenerated.Request(
|
|
79
82
|
method: ${swiftString(tool.request.method)},
|
|
80
83
|
url: ${swiftString(tool.request.url)},
|
|
@@ -84,7 +87,7 @@ ${tool.parameters.map((parameter) => parameterSwift(tool, parameter)).join('')}
|
|
|
84
87
|
let answer = await SiriToolsGenerated.tool.answer {
|
|
85
88
|
try SiriToolsGenerated.reply(${swiftString(tool.reply)}, from: try await request.send())
|
|
86
89
|
}
|
|
87
|
-
return .result(value: answer, dialog: "\\(answer)")
|
|
90
|
+
return .result(value: answer${tool.returns === 'dialog' ? ', dialog: "\\(answer)"' : ''})
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
93
|
${enums.join('')}#endif
|
|
@@ -100,6 +103,14 @@ import SyrupAIKit
|
|
|
100
103
|
enum SiriToolsGenerated {
|
|
101
104
|
static let tool = SiriTool(appName: ${swiftString(appName)})
|
|
102
105
|
|
|
106
|
+
#if DEBUG || SIRI_AI_EVAL_SWITCHES
|
|
107
|
+
/// An evaluation's negative control turns this on at launch: every generated tool then calls a host that never
|
|
108
|
+
/// resolves, so Siri must say it couldn't reach the app. Builds without either condition, such as an App Store
|
|
109
|
+
/// archive, don't read it.
|
|
110
|
+
static let badHost: EvalSwitch = "bad-host"
|
|
111
|
+
static let unreachableURL = URL(string: "https://siri-ai-eval-bad-host.invalid")!
|
|
112
|
+
#endif
|
|
113
|
+
|
|
103
114
|
/// A parameter value as Siri filled it in.
|
|
104
115
|
enum Value: Sendable {
|
|
105
116
|
case string(String)
|
|
@@ -153,6 +164,9 @@ enum SiriToolsGenerated {
|
|
|
153
164
|
}
|
|
154
165
|
|
|
155
166
|
func resolvedURL() throws -> URL {
|
|
167
|
+
#if DEBUG || SIRI_AI_EVAL_SWITCHES
|
|
168
|
+
if SiriToolsGenerated.badHost.isOn() { return SiriToolsGenerated.unreachableURL }
|
|
169
|
+
#endif
|
|
156
170
|
var text = url
|
|
157
171
|
for (name, value) in values {
|
|
158
172
|
let encoded = value.text.addingPercentEncoding(withAllowedCharacters: .siriToolValueAllowed) ?? value.text
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { XcodeProject } from 'expo/config-plugins';
|
|
2
2
|
export declare const PREVIEW_FLAG = "SIRI_AI_PREVIEW";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Evaluations of an Expo app run a Release build, where `#if DEBUG` code is compiled out. Passing
|
|
5
|
+
* `SIRI_AI_EVAL_SWITCHES=YES` to `xcodebuild` adds this condition, so `#if DEBUG || SIRI_AI_EVAL_SWITCHES` code reads
|
|
6
|
+
* `EvalSwitch` in that build only. No other build, including an App Store archive, compiles it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const EVAL_SWITCHES_FLAG = "SIRI_AI_EVAL_SWITCHES";
|
|
9
|
+
/**
|
|
10
|
+
* Turns on the `SIRI_AI_PREVIEW` Swift condition and iOS 27.3 for the app target, and lets an evaluation build add
|
|
11
|
+
* `SIRI_AI_EVAL_SWITCHES`.
|
|
12
|
+
*/
|
|
4
13
|
export declare function enableSiriAIPreview(project: XcodeProject): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PREVIEW_FLAG = void 0;
|
|
3
|
+
exports.EVAL_SWITCHES_FLAG = exports.PREVIEW_FLAG = void 0;
|
|
4
4
|
exports.enableSiriAIPreview = enableSiriAIPreview;
|
|
5
5
|
exports.PREVIEW_FLAG = 'SIRI_AI_PREVIEW';
|
|
6
6
|
/**
|
|
@@ -8,13 +8,25 @@ exports.PREVIEW_FLAG = 'SIRI_AI_PREVIEW';
|
|
|
8
8
|
* runtime. Only the app target is raised, so prebuilt pods keep their own deployment targets.
|
|
9
9
|
*/
|
|
10
10
|
const PREVIEW_DEPLOYMENT_TARGET = '27.3';
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Evaluations of an Expo app run a Release build, where `#if DEBUG` code is compiled out. Passing
|
|
13
|
+
* `SIRI_AI_EVAL_SWITCHES=YES` to `xcodebuild` adds this condition, so `#if DEBUG || SIRI_AI_EVAL_SWITCHES` code reads
|
|
14
|
+
* `EvalSwitch` in that build only. No other build, including an App Store archive, compiles it.
|
|
15
|
+
*/
|
|
16
|
+
exports.EVAL_SWITCHES_FLAG = 'SIRI_AI_EVAL_SWITCHES';
|
|
17
|
+
/** Expands to the condition when `SIRI_AI_EVAL_SWITCHES` is `YES`, and to nothing when it is unset or anything else. */
|
|
18
|
+
const EVAL_SWITCHES_CONDITION = `$(${exports.EVAL_SWITCHES_FLAG}_CONDITION_$(${exports.EVAL_SWITCHES_FLAG}))`;
|
|
19
|
+
/**
|
|
20
|
+
* Turns on the `SIRI_AI_PREVIEW` Swift condition and iOS 27.3 for the app target, and lets an evaluation build add
|
|
21
|
+
* `SIRI_AI_EVAL_SWITCHES`.
|
|
22
|
+
*/
|
|
12
23
|
function enableSiriAIPreview(project) {
|
|
13
24
|
const configurations = project.pbxXCBuildConfigurationSection();
|
|
14
25
|
for (const [key, entry] of Object.entries(configurations)) {
|
|
15
26
|
if (key.endsWith('_comment') || !entry?.buildSettings?.PRODUCT_NAME)
|
|
16
27
|
continue;
|
|
17
|
-
entry.buildSettings.SWIFT_ACTIVE_COMPILATION_CONDITIONS = `"$(inherited) ${exports.PREVIEW_FLAG}"`;
|
|
28
|
+
entry.buildSettings.SWIFT_ACTIVE_COMPILATION_CONDITIONS = `"$(inherited) ${exports.PREVIEW_FLAG} ${EVAL_SWITCHES_CONDITION}"`;
|
|
29
|
+
entry.buildSettings[`${exports.EVAL_SWITCHES_FLAG}_CONDITION_YES`] = exports.EVAL_SWITCHES_FLAG;
|
|
18
30
|
entry.buildSettings.IPHONEOS_DEPLOYMENT_TARGET = PREVIEW_DEPLOYMENT_TARGET;
|
|
19
31
|
}
|
|
20
32
|
}
|
|
@@ -25,9 +25,12 @@ npx expo install expo-syrup-ai-kit expo-app-intents
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
|
|
28
|
+
npx expo-app-intents init --examples minimal # unless app-intents/AppIntentsSetup.swift exists
|
|
29
|
+
SIRI_AI_PREVIEW=1 CP_CACHE_DIR="$PWD/.cp-cache" LANG=en_US.UTF-8 npx expo prebuild -p ios
|
|
29
30
|
```
|
|
30
31
|
|
|
32
|
+
`init` creates the `AppIntentsSetup` inline module and turns on inline modules in `app.json`. `npx expo install` adds both plugins; keep `expo-app-intents` first, as above.
|
|
33
|
+
|
|
31
34
|
With the preview on, the plugin adds the `SIRI_AI_PREVIEW` Swift condition and sets the **app target** to iOS 27.3. Without `SIRI_AI_PREVIEW=1` (or `["expo-syrup-ai-kit", { "preview": true }]`), tool code inside `#if SIRI_AI_PREVIEW` doesn't compile in, and Siri never sees the tool.
|
|
32
35
|
|
|
33
36
|
Options: `version` (SyrupAIKit release, up to next minor; defaults to the tested one), `branch` (unreleased SyrupAIKit; not with `version`), `preview`, `evals`, `skills` (`{ "sourceDir": "siri-skills" }`: a folder of Apple App Skills, one folder per skill with only a `SKILL.md`; checked at prebuild and compiled into the app as `Skills.skillsbundle`).
|
|
@@ -40,7 +43,7 @@ Don't add the Siri Evaluations UI test target in Xcode: `prebuild --clean` drops
|
|
|
40
43
|
["expo-syrup-ai-kit", { "preview": true, "evals": { "sourceDir": "siri-evals" } }]
|
|
41
44
|
```
|
|
42
45
|
|
|
43
|
-
Prebuild then adds a `<AppName>Evals` UI test target (rename with `targetName`) that compiles every `.swift` file under `siri-evals/`, tests the app, builds for iOS 27.3, links `SyrupAIEvalKit` from the same package, and has a shared scheme of the same name: `xcodebuild test -workspace ios/<App>.xcworkspace -scheme <App>Evals -destination 'platform=iOS,name=<device>'`. Prebuild again after adding or removing a test file.
|
|
46
|
+
Prebuild then adds a `<AppName>Evals` UI test target (rename with `targetName`) that compiles every `.swift` file under `siri-evals/`, tests the app, builds for iOS 27.3, links `SyrupAIEvalKit` from the same package, and has a shared scheme of the same name: `xcodebuild test -workspace ios/<App>.xcworkspace -scheme <App>Evals -configuration Release -destination 'platform=iOS,name=<device>'`. Use Release: a Debug build loads its JavaScript from the dev server and won't start without `npx expo start`. Prebuild again after adding or removing a test file.
|
|
44
47
|
|
|
45
48
|
## The tool lives in `app-intents/`
|
|
46
49
|
|
|
@@ -66,6 +69,8 @@ struct GetOrderStatusIntent: AppIntent {
|
|
|
66
69
|
|
|
67
70
|
The Swift tool can't call your JavaScript API client or read JS memory. It needs its own Swift request code.
|
|
68
71
|
|
|
72
|
+
The dialog makes Siri say the answer word for word and end its turn. If an App Skill names the tool, or Siri should combine it with others, return `some IntentResult & ReturnsValue<String>` and `.result(value: answer)` instead; a generated tool does this with `"returns": "value"`.
|
|
73
|
+
|
|
69
74
|
## Implementing tools from `siri-tools.json`
|
|
70
75
|
|
|
71
76
|
A `siri-tools.json` from the siri-ai-discover skill is the tools' interface. Each entry has `name`, `title`, `description` and `parameters`, and usually `"javascript": "<handler>"`. Implement every entry with that interface unchanged: evaluations check `name`, and Siri chooses tools by `description`.
|
|
@@ -73,6 +78,7 @@ A `siri-tools.json` from the siri-ai-discover skill is the tools' interface. Eac
|
|
|
73
78
|
| The entry has | Do this today |
|
|
74
79
|
|---|---|
|
|
75
80
|
| `javascript` | Not supported yet: the plugin rejects it as an unknown field. Write a Swift tool in `app-intents/` named `<name>Intent`, copy `title` and `description` word for word, and add one `@Parameter(title:description:)` per declared parameter, with its `title` and `description`. Keep the entry as the tool's spec, but leave it out of the `tools` file until the `javascript` kind ships. |
|
|
81
|
+
| `returns: "value"` | In Swift, return `.result(value: answer)` without `ProvidesDialog`. A generated tool does it for you. |
|
|
76
82
|
| `request` and `reply` | Generated at prebuild by the `tools` option (experimental). Use it only when the host is fixed and `https`, the API needs no credentials, and every reply field is always present. Generated tools send plain requests, and any non-2xx response is a failure. Otherwise write Swift. |
|
|
77
83
|
|
|
78
84
|
Discovery also writes a handler stub and a failing test per tool in `src/siri-tools/<handler>.ts` (or `siri-tools/` without `src/`). Discovery offers to implement it, and to write the Swift tool; if the owner declined, implement the handler against the test now: it's plain TypeScript that calls the app's own functions, never hooks. It answers Siri once the `javascript` kind ships; until then the Swift tool is what answers.
|
|
@@ -84,13 +90,14 @@ Whatever the kind, the answer is one sentence (the count and at most three names
|
|
|
84
90
|
The screen is React Native, so use a JS `<Text>` instead of SyrupAIKit's SwiftUI `ToolOutcomeView`. Expose the outcome from the `AppIntentsSetup` inline module that expo-app-intents uses (`app-intents/AppIntentsSetup.swift`; keep the class name):
|
|
85
91
|
|
|
86
92
|
```swift
|
|
93
|
+
internal import ExpoAppIntents
|
|
87
94
|
internal import ExpoModulesCore
|
|
88
95
|
import SyrupAIKit
|
|
89
96
|
|
|
90
97
|
final class AppIntentsSetup: Module {
|
|
91
98
|
public func definition() -> ExpoModulesCore.ModuleDefinition {
|
|
92
99
|
Name("AppIntentsSetup")
|
|
93
|
-
Function("siriToolOutcome") { () -> String in ToolOutcomeLog.standard.
|
|
100
|
+
Function("siriToolOutcome") { () -> String in ToolOutcomeLog.standard.summary }
|
|
94
101
|
}
|
|
95
102
|
}
|
|
96
103
|
```
|
|
@@ -106,18 +113,22 @@ export function SiriToolOutcome() {
|
|
|
106
113
|
const poll = setInterval(() => setOutcome(Setup.siriToolOutcome()), 1000);
|
|
107
114
|
return () => clearInterval(poll);
|
|
108
115
|
}, []);
|
|
109
|
-
return
|
|
116
|
+
return <Text testID="siri-ai-tool-outcome">{outcome}</Text>;
|
|
110
117
|
}
|
|
111
118
|
```
|
|
112
119
|
|
|
113
|
-
Render `<SiriToolOutcome />` on a screen that's always visible. The testID `siri-ai-tool-outcome` is what SyrupAIEvalKit reads. If the module already exists, add the `Function` to it rather than creating a second one.
|
|
120
|
+
Render `<SiriToolOutcome />` on a screen that's always visible. The testID `siri-ai-tool-outcome` is what SyrupAIEvalKit reads. Use `summary`, not `last`: `last` is only the newest call, so a run where Siri chains tools would hide an earlier failure. Don't hide it behind `__DEV__`: evaluations run a Release build, so the outcome would never show. If the module already exists, add the `Function` to it rather than creating a second one. Import `SyrupAIKit` the same way in every file in `app-intents/`: plain `import SyrupAIKit` here and in the tools.
|
|
114
121
|
|
|
115
122
|
## Prebuild and build traps
|
|
116
123
|
|
|
117
124
|
| Symptom | Fix |
|
|
118
125
|
|---|---|
|
|
119
126
|
| CocoaPods: `Unicode Normalization not appropriate for ASCII-8BIT` | Run with `LANG=en_US.UTF-8` |
|
|
120
|
-
| `
|
|
127
|
+
| `pod install`: `Info.plist` missing in `hermesvm.xcframework` or `React-Core-prebuilt/React.xcframework` | A broken CocoaPods cache, unrelated to SyrupAIKit: `cd ios && CP_CACHE_DIR="$PWD/../.cp-cache" LANG=en_US.UTF-8 pod install` |
|
|
128
|
+
| `ambiguous implicit access level for import of 'SyrupAIKit'` | One file in `app-intents/` has `internal import SyrupAIKit` and another plain `import SyrupAIKit`. Use one form in every file |
|
|
129
|
+
| No `app-intents/AppIntentsSetup.swift` to add the outcome function to | Run `npx expo-app-intents init --examples minimal`, then prebuild again |
|
|
130
|
+
| Evaluations run a Debug build | Debug loads JavaScript from the dev server, so the app needs `npx expo start` running. Use `-configuration Release` |
|
|
131
|
+
| Negative control's reply check passes: the `EvalSwitch` did nothing | Release compiles `#if DEBUG` out. Guard the switch with `#if DEBUG \|\| SIRI_AI_EVAL_SWITCHES` and pass `SIRI_AI_EVAL_SWITCHES=YES` to `xcodebuild test`. Generated tools already honour `bad-host` |
|
|
121
132
|
| `No such module 'SyrupAIKit'` in `app-intents/` | Plugin missing from `app.json`, or prebuild not re-run after adding it |
|
|
122
133
|
| Siri never calls the tool, no build error | Prebuilt without `SIRI_AI_PREVIEW=1`, so `@AppIntent(.tool)` compiled out |
|
|
123
134
|
| Evaluation UI test target gone | Set the plugin's `evals: { "sourceDir": "siri-evals" }` option instead of adding the target in Xcode, then prebuild again |
|
|
@@ -83,6 +83,8 @@ Propose an App Skill only when all of these hold:
|
|
|
83
83
|
- **Every step is a tool on the shortlist.** If a step needs a tool the app lacks, or a tool's answer leaves out what the next step needs (a spoken answer that says "and 9 more"), don't draft the skill. List it as a gap with the tool change it would need; that change is the owner's call.
|
|
84
84
|
- **A single tool doesn't already answer it.** One question or one action needs no skill.
|
|
85
85
|
|
|
86
|
+
Every tool a kept skill names gets `"returns": "value"` in `siri-tools.json`. A tool that returns a spoken dialog ends Siri's turn, so Siri can't chain it.
|
|
87
|
+
|
|
86
88
|
Draft at most two or three. A skill for every pair of tools is noise Siri has to read.
|
|
87
89
|
|
|
88
90
|
|
|
@@ -118,6 +120,7 @@ One entry per kept tool, in the owner's order:
|
|
|
118
120
|
- `name` is PascalCase, unique, and doesn't end in `Intent`. Evaluations use it to check which tool Siri called.
|
|
119
121
|
- `description` says what the tool returns, in the user's own words. Siri reads it to choose the tool.
|
|
120
122
|
- Each parameter has `name`, `type`, `title` and `description`. The type is one of `string`, `int`, `double`, `bool`, `date` or `enum` (with `cases`). The `description` is one line saying what the person gives, with an example value: "The product to add, as the person names it, like 'oat milk'." Siri reads it to fill the parameter from what was said.
|
|
123
|
+
- `returns` is `"value"` for a tool any App Skill names, or that people combine with other tools in one request. Leave it out otherwise: Siri then says the tool's answer word for word.
|
|
121
124
|
- `javascript` is the handler's name and its file name: `name` in kebab-case, dropping a leading `Get` (`GetUnreadNotifications` → `unread-notifications`, `PostMessage` → `post-message`). The handler function is the camelCase of the same words (`unreadNotifications`).
|
|
122
125
|
|
|
123
126
|
### One handler file per tool
|
|
@@ -224,7 +227,8 @@ These hold at the end of step 4, before you offer step 5.
|
|
|
224
227
|
- Every `javascript` value matches its file name.
|
|
225
228
|
- Every parameter appears in the spoken prompt, and nothing the prompt needs is missing.
|
|
226
229
|
- Every parameter has a one-line `description` with an example value.
|
|
227
|
-
- Two descriptions aren't easy to confuse.
|
|
230
|
+
- Two descriptions aren't easy to confuse, and no enum case title repeats words another tool's description is built on (a "Phones" case drew "search for phones" away from a search tool on a phone).
|
|
231
|
+
- Every tool an App Skill names has `"returns": "value"`.
|
|
228
232
|
- Every App Skill's steps name only tools in `siri-tools.json`, its `name` matches its folder, and its frontmatter has only `name` and `description`.
|
|
229
233
|
- No existing app file changed, `app.json` included.
|
|
230
234
|
- You ran the new tests with the app's own test command. Each test fails on the stub's "not implemented" error, not on loading the test. If the tests can't run (no `node_modules`, wrong Node version), say so in the report; never install anything to make them run.
|