@capgo/capacitor-llm 8.1.1 → 8.1.2
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
CHANGED
|
@@ -11,7 +11,7 @@ On-device LLM support for Capacitor.
|
|
|
11
11
|
|
|
12
12
|
Current platform strategy:
|
|
13
13
|
|
|
14
|
-
- iOS: Apple Intelligence by default, plus LiteRT-LM `.litertlm` custom models when the
|
|
14
|
+
- iOS: Apple Intelligence by default, plus LiteRT-LM `.litertlm` custom models in SwiftPM integrations when the path ends in `.litertlm` or `modelType: 'litertlm'` is passed
|
|
15
15
|
- Android: Gemini Nano system model on supported devices where it is already available, LiteRT-LM for `.litertlm` bundles, and a compatibility fallback for legacy MediaPipe `.task` models
|
|
16
16
|
- Web: Gemma 4 web models through `@mediapipe/tasks-genai`
|
|
17
17
|
|
|
@@ -56,7 +56,9 @@ Custom iOS LiteRT-LM path:
|
|
|
56
56
|
|
|
57
57
|
- Available only when the plugin is integrated into the iOS app through Swift Package Manager
|
|
58
58
|
- Uses the official LiteRT-LM Swift API and prebuilt iOS xcframework for `.litertlm` models
|
|
59
|
+
- Selected only when the path ends in `.litertlm` or `modelType: 'litertlm'` is passed
|
|
59
60
|
- CocoaPods builds keep Apple Intelligence and the legacy MediaPipe `.task` compatibility path
|
|
61
|
+
- Other custom iOS model types keep the legacy MediaPipe compatibility path for backward compatibility
|
|
60
62
|
|
|
61
63
|
Example:
|
|
62
64
|
|
|
@@ -158,11 +160,10 @@ await CapgoLLM.sendMessage({
|
|
|
158
160
|
message: 'Explain why local inference is useful on mobile.',
|
|
159
161
|
});
|
|
160
162
|
```
|
|
161
|
-
|
|
162
163
|
## Notes
|
|
163
164
|
|
|
164
165
|
- Android now prefers LiteRT-LM and Gemma 4 style `.litertlm` bundles.
|
|
165
|
-
- iOS LiteRT-LM custom-model support now uses the official LiteRT-LM Swift API and prebuilt iOS binaries,
|
|
166
|
+
- iOS LiteRT-LM custom-model support now uses the official LiteRT-LM Swift API and prebuilt iOS binaries, is available only in SwiftPM integrations of this plugin, and is selected only for explicit `.litertlm` models.
|
|
166
167
|
- CocoaPods builds on iOS should use Apple Intelligence or the legacy MediaPipe `.task` compatibility path.
|
|
167
168
|
- Web uses Gemma 4 `*-web.task` artifacts through `@mediapipe/tasks-genai`.
|
|
168
169
|
- Apple Intelligence remains the preferred default on iOS where available.
|
|
@@ -237,7 +238,7 @@ setModel(options: ModelOptions) => Promise<void>
|
|
|
237
238
|
```
|
|
238
239
|
|
|
239
240
|
Sets the model configuration
|
|
240
|
-
- iOS: Use "Apple Intelligence" as path for the system model. Custom LiteRT-LM `.litertlm` models are supported on iOS only when this plugin is integrated through Swift Package Manager
|
|
241
|
+
- iOS: Use "Apple Intelligence" as path for the system model. Custom LiteRT-LM `.litertlm` models are supported on iOS only when this plugin is integrated through Swift Package Manager, and are selected only when `modelType: 'litertlm'` is passed or the path ends in `.litertlm`.
|
|
241
242
|
- Android: Use "Gemini Nano" for the AICore system model on supported devices where it is already available. Prefer LiteRT-LM `.litertlm` bundles for custom models; legacy MediaPipe `.task` models are still supported
|
|
242
243
|
- Web: Provide a web-ready model asset for `@mediapipe/tasks-genai` such as Gemma 4 `*-web.task`
|
|
243
244
|
|
|
@@ -383,7 +384,7 @@ Only `path` is required. All other properties are optional overrides.
|
|
|
383
384
|
| Prop | Type | Description | Since |
|
|
384
385
|
| ----------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
385
386
|
| **`path`** | <code>string</code> | Model path, "Apple Intelligence" for the Apple system model on iOS, or "Gemini Nano" for the Android AICore system model when already available on the device. On iOS, custom `.litertlm` models require the plugin to be integrated through Swift Package Manager. Gemma 4 examples use `.litertlm` on mobile and `*-web.task` on web. | |
|
|
386
|
-
| **`modelType`** | <code>string</code> | Optional. Model file type/extension (for example `task`, `bin`, `litertlm`, or `gemini-nano`). If not provided, it is extracted from the path.
|
|
387
|
+
| **`modelType`** | <code>string</code> | Optional. Model file type/extension (for example `task`, `bin`, `litertlm`, or `gemini-nano`). If not provided, it is extracted from the path. On iOS, LiteRT-LM is selected only when this resolves to `litertlm`; all other custom types keep the legacy MediaPipe compatibility path. | |
|
|
387
388
|
| **`maxTokens`** | <code>number</code> | Maximum number of tokens the model handles | |
|
|
388
389
|
| **`topk`** | <code>number</code> | Number of tokens the model considers at each step | |
|
|
389
390
|
| **`temperature`** | <code>number</code> | Amount of randomness in generation (0.0-1.0) | |
|
package/dist/docs.json
CHANGED
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"text": "Promise that resolves when model is loaded"
|
|
82
82
|
}
|
|
83
83
|
],
|
|
84
|
-
"docs": "Sets the model configuration\n- iOS: Use \"Apple Intelligence\" as path for the system model. Custom LiteRT-LM `.litertlm` models are supported on iOS only when this plugin is integrated through Swift Package Manager
|
|
84
|
+
"docs": "Sets the model configuration\n- iOS: Use \"Apple Intelligence\" as path for the system model. Custom LiteRT-LM `.litertlm` models are supported on iOS only when this plugin is integrated through Swift Package Manager, and are selected only when `modelType: 'litertlm'` is passed or the path ends in `.litertlm`.\n- Android: Use \"Gemini Nano\" for the AICore system model on supported devices where it is already available. Prefer LiteRT-LM `.litertlm` bundles for custom models; legacy MediaPipe `.task` models are still supported\n- Web: Provide a web-ready model asset for `@mediapipe/tasks-genai` such as Gemma 4 `*-web.task`",
|
|
85
85
|
"complexTypes": [
|
|
86
86
|
"ModelOptions"
|
|
87
87
|
],
|
|
@@ -343,7 +343,7 @@
|
|
|
343
343
|
{
|
|
344
344
|
"name": "modelType",
|
|
345
345
|
"tags": [],
|
|
346
|
-
"docs": "Optional. Model file type/extension (for example `task`, `bin`, `litertlm`, or `gemini-nano`). If not provided, it is extracted from the path.
|
|
346
|
+
"docs": "Optional. Model file type/extension (for example `task`, `bin`, `litertlm`, or `gemini-nano`). If not provided, it is extracted from the path. On iOS, LiteRT-LM is selected only when this resolves to `litertlm`; all other custom types keep the legacy MediaPipe compatibility path.",
|
|
347
347
|
"complexTypes": [],
|
|
348
348
|
"type": "string | undefined"
|
|
349
349
|
},
|
|
@@ -28,7 +28,7 @@ export interface LLMPlugin {
|
|
|
28
28
|
}>;
|
|
29
29
|
/**
|
|
30
30
|
* Sets the model configuration
|
|
31
|
-
* - iOS: Use "Apple Intelligence" as path for the system model. Custom LiteRT-LM `.litertlm` models are supported on iOS only when this plugin is integrated through Swift Package Manager
|
|
31
|
+
* - iOS: Use "Apple Intelligence" as path for the system model. Custom LiteRT-LM `.litertlm` models are supported on iOS only when this plugin is integrated through Swift Package Manager, and are selected only when `modelType: 'litertlm'` is passed or the path ends in `.litertlm`.
|
|
32
32
|
* - Android: Use "Gemini Nano" for the AICore system model on supported devices where it is already available. Prefer LiteRT-LM `.litertlm` bundles for custom models; legacy MediaPipe `.task` models are still supported
|
|
33
33
|
* - Web: Provide a web-ready model asset for `@mediapipe/tasks-genai` such as Gemma 4 `*-web.task`
|
|
34
34
|
* @param options - The model configuration
|
|
@@ -178,7 +178,7 @@ export interface ReadinessChangeEvent {
|
|
|
178
178
|
export interface ModelOptions {
|
|
179
179
|
/** Model path, "Apple Intelligence" for the Apple system model on iOS, or "Gemini Nano" for the Android AICore system model when already available on the device. On iOS, custom `.litertlm` models require the plugin to be integrated through Swift Package Manager. Gemma 4 examples use `.litertlm` on mobile and `*-web.task` on web. */
|
|
180
180
|
path: string;
|
|
181
|
-
/** Optional. Model file type/extension (for example `task`, `bin`, `litertlm`, or `gemini-nano`). If not provided, it is extracted from the path.
|
|
181
|
+
/** Optional. Model file type/extension (for example `task`, `bin`, `litertlm`, or `gemini-nano`). If not provided, it is extracted from the path. On iOS, LiteRT-LM is selected only when this resolves to `litertlm`; all other custom types keep the legacy MediaPipe compatibility path. */
|
|
182
182
|
modelType?: string;
|
|
183
183
|
/** Maximum number of tokens the model handles */
|
|
184
184
|
maxTokens?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * LLM Plugin interface for interacting with on-device language models\n */\nexport interface LLMPlugin {\n /**\n * Creates a new chat session\n * @returns Promise with chat id and optional instructions\n */\n createChat(): Promise<{ id: string; instructions?: string }>;\n\n /**\n * Sends a message to the AI in a specific chat session\n * @param options - The chat id and message to send\n * @returns Promise that resolves when message is sent\n */\n sendMessage(options: { chatId: string; message: string }): Promise<void>;\n\n /**\n * Gets the readiness status of the LLM\n * @returns Promise with readiness status string\n */\n getReadiness(): Promise<{ readiness: string }>;\n\n /**\n * Sets the model configuration\n * - iOS: Use \"Apple Intelligence\" as path for the system model. Custom LiteRT-LM `.litertlm` models are supported on iOS only when this plugin is integrated through Swift Package Manager
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * LLM Plugin interface for interacting with on-device language models\n */\nexport interface LLMPlugin {\n /**\n * Creates a new chat session\n * @returns Promise with chat id and optional instructions\n */\n createChat(): Promise<{ id: string; instructions?: string }>;\n\n /**\n * Sends a message to the AI in a specific chat session\n * @param options - The chat id and message to send\n * @returns Promise that resolves when message is sent\n */\n sendMessage(options: { chatId: string; message: string }): Promise<void>;\n\n /**\n * Gets the readiness status of the LLM\n * @returns Promise with readiness status string\n */\n getReadiness(): Promise<{ readiness: string }>;\n\n /**\n * Sets the model configuration\n * - iOS: Use \"Apple Intelligence\" as path for the system model. Custom LiteRT-LM `.litertlm` models are supported on iOS only when this plugin is integrated through Swift Package Manager, and are selected only when `modelType: 'litertlm'` is passed or the path ends in `.litertlm`.\n * - Android: Use \"Gemini Nano\" for the AICore system model on supported devices where it is already available. Prefer LiteRT-LM `.litertlm` bundles for custom models; legacy MediaPipe `.task` models are still supported\n * - Web: Provide a web-ready model asset for `@mediapipe/tasks-genai` such as Gemma 4 `*-web.task`\n * @param options - The model configuration\n * @returns Promise that resolves when model is loaded\n */\n setModel(options: ModelOptions): Promise<void>;\n\n /**\n * Downloads a model from a URL and saves it to the appropriate location\n * - iOS: Downloads to the app's documents directory\n * - Android: Downloads to the app's files directory\n * @param options - The download configuration\n * @returns Promise with download result including the saved path\n */\n downloadModel(options: DownloadModelOptions): Promise<DownloadModelResult>;\n\n /**\n * Adds a listener for text received from AI\n * @param eventName - Event name 'textFromAi'\n * @param listenerFunc - Callback function for text events\n * @returns Promise with remove function to unsubscribe\n */\n addListener(\n eventName: 'textFromAi',\n listenerFunc: (event: TextFromAiEvent) => void,\n ): Promise<{ remove: () => Promise<void> }>;\n\n /**\n * Adds a listener for AI completion events\n * @param eventName - Event name 'aiFinished'\n * @param listenerFunc - Callback function for finish events\n * @returns Promise with remove function to unsubscribe\n */\n addListener(\n eventName: 'aiFinished',\n listenerFunc: (event: AiFinishedEvent) => void,\n ): Promise<{ remove: () => Promise<void> }>;\n\n /**\n * Adds a listener for generation failures that happen after streaming starts\n * @param eventName - Event name 'generationError'\n * @param listenerFunc - Callback function for generation errors\n * @returns Promise with remove function to unsubscribe\n */\n addListener(\n eventName: 'generationError',\n listenerFunc: (event: GenerationErrorEvent) => void,\n ): Promise<{ remove: () => Promise<void> }>;\n\n /**\n * Adds a listener for model download progress events\n * @param eventName - Event name 'downloadProgress'\n * @param listenerFunc - Callback function for progress events\n * @returns Promise with remove function to unsubscribe\n */\n addListener(\n eventName: 'downloadProgress',\n listenerFunc: (event: DownloadProgressEvent) => void,\n ): Promise<{ remove: () => Promise<void> }>;\n\n /**\n * Adds a listener for readiness status changes\n * @param eventName - Event name 'readinessChange'\n * @param listenerFunc - Callback function for readiness events\n * @returns Promise with remove function to unsubscribe\n */\n addListener(\n eventName: 'readinessChange',\n listenerFunc: (event: ReadinessChangeEvent) => void,\n ): Promise<{ remove: () => Promise<void> }>;\n\n /**\n * Get the native Capacitor plugin version.\n *\n * @returns Promise that resolves with the plugin version\n * @throws Error if getting the version fails\n * @since 1.0.0\n * @example\n * ```typescript\n * const { version } = await CapgoLLM.getPluginVersion();\n * console.log('Plugin version:', version);\n * ```\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n\n/**\n * Event data for text received from AI\n */\nexport interface TextFromAiEvent {\n /** The text content from AI - this is an incremental chunk, not the full text */\n text: string;\n /** The chat session ID */\n chatId: string;\n /** Whether this is a complete chunk (true) or partial streaming data (false) */\n isChunk?: boolean;\n}\n\n/**\n * Event data for AI completion\n */\nexport interface AiFinishedEvent {\n /** The chat session ID that finished */\n chatId: string;\n}\n\n/**\n * Event data for generation failures\n * `chatId` is optional and may be omitted when the failure is not tied to a specific chat.\n */\nexport interface GenerationErrorEvent {\n /** Optional. The chat session ID that failed, when available. */\n chatId?: string;\n /** Error message describing the failure */\n error: string;\n}\n\n/**\n * Options for downloading a model\n * Only `url` is required. `companionUrl` and `filename` are optional.\n */\nexport interface DownloadModelOptions {\n /** URL of the model file to download */\n url: string;\n /** Optional: URL of a companion file for legacy model formats */\n companionUrl?: string;\n /** Optional: Custom filename (defaults to filename from URL) */\n filename?: string;\n}\n\n/**\n * Result of model download\n */\nexport interface DownloadModelResult {\n /** Path where the model was saved */\n path: string;\n /** Path where the companion file was saved (if applicable) */\n companionPath?: string;\n}\n\n/**\n * Event data for download progress\n */\nexport interface DownloadProgressEvent {\n /** Percentage of download completed (0-100) */\n progress: number;\n /** Total bytes to download */\n totalBytes?: number;\n /** Bytes downloaded so far */\n downloadedBytes?: number;\n}\n\n/**\n * Event data for readiness status changes\n */\nexport interface ReadinessChangeEvent {\n /** The readiness status */\n readiness: string;\n}\n\n/**\n * Model configuration options\n * Only `path` is required. All other properties are optional overrides.\n */\nexport interface ModelOptions {\n /** Model path, \"Apple Intelligence\" for the Apple system model on iOS, or \"Gemini Nano\" for the Android AICore system model when already available on the device. On iOS, custom `.litertlm` models require the plugin to be integrated through Swift Package Manager. Gemma 4 examples use `.litertlm` on mobile and `*-web.task` on web. */\n path: string;\n /** Optional. Model file type/extension (for example `task`, `bin`, `litertlm`, or `gemini-nano`). If not provided, it is extracted from the path. On iOS, LiteRT-LM is selected only when this resolves to `litertlm`; all other custom types keep the legacy MediaPipe compatibility path. */\n modelType?: string;\n /** Maximum number of tokens the model handles */\n maxTokens?: number;\n /** Number of tokens the model considers at each step */\n topk?: number;\n /** Amount of randomness in generation (0.0-1.0) */\n temperature?: number;\n /** Optional. Random seed for generation. */\n randomSeed?: number;\n /**\n * Optional. LiteRT-LM engine backend for iOS (SwiftPM) and Android.\n * Use `cpu` for stable long generations. When omitted, iOS prefers CPU then falls back to GPU; Android uses CPU.\n * @since 8.2.0\n */\n backend?: 'gpu' | 'cpu';\n}\n"]}
|
|
@@ -17,7 +17,7 @@ import MediaPipeTasksGenAI
|
|
|
17
17
|
|
|
18
18
|
@objc(LLMPlugin)
|
|
19
19
|
public class LLMPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
20
|
-
private let pluginVersion: String = "8.1.
|
|
20
|
+
private let pluginVersion: String = "8.1.2"
|
|
21
21
|
private let liteRtTopP: Float = 0.95
|
|
22
22
|
|
|
23
23
|
public let identifier = "LLMPlugin"
|
|
@@ -412,11 +412,7 @@ public class LLMPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
412
412
|
case "task":
|
|
413
413
|
return .mediaPipe
|
|
414
414
|
default:
|
|
415
|
-
#if canImport(LiteRTLM)
|
|
416
|
-
return .liteRtLm
|
|
417
|
-
#else
|
|
418
415
|
return .mediaPipe
|
|
419
|
-
#endif
|
|
420
416
|
}
|
|
421
417
|
}
|
|
422
418
|
|