@capacitor-mlkit/genai-rewriting 8.1.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.
Files changed (36) hide show
  1. package/CapacitorMlkitGenaiRewriting.podspec +17 -0
  2. package/LICENSE +201 -0
  3. package/README.md +429 -0
  4. package/android/build.gradle +60 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genairewriting/GenAiRewriting.java +159 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genairewriting/GenAiRewritingPlugin.java +145 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genairewriting/classes/events/DownloadProgressEvent.java +22 -0
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genairewriting/classes/events/InferenceProgressEvent.java +23 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genairewriting/classes/options/FeatureOptions.java +72 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genairewriting/classes/options/RewriteOptions.java +30 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genairewriting/classes/results/CheckFeatureStatusResult.java +37 -0
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genairewriting/classes/results/RewriteResult.java +29 -0
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genairewriting/interfaces/Callback.java +5 -0
  15. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genairewriting/interfaces/EmptyCallback.java +5 -0
  16. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genairewriting/interfaces/NonEmptyResultCallback.java +7 -0
  17. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mlkit/genairewriting/interfaces/Result.java +7 -0
  18. package/android/src/main/res/.gitkeep +0 -0
  19. package/dist/docs.json +589 -0
  20. package/dist/esm/definitions.d.ts +251 -0
  21. package/dist/esm/definitions.js +107 -0
  22. package/dist/esm/definitions.js.map +1 -0
  23. package/dist/esm/index.d.ts +4 -0
  24. package/dist/esm/index.js +7 -0
  25. package/dist/esm/index.js.map +1 -0
  26. package/dist/esm/web.d.ts +8 -0
  27. package/dist/esm/web.js +16 -0
  28. package/dist/esm/web.js.map +1 -0
  29. package/dist/plugin.cjs.js +137 -0
  30. package/dist/plugin.cjs.js.map +1 -0
  31. package/dist/plugin.js +140 -0
  32. package/dist/plugin.js.map +1 -0
  33. package/ios/Plugin/GenAiRewritingPlugin.m +10 -0
  34. package/ios/Plugin/GenAiRewritingPlugin.swift +21 -0
  35. package/ios/Plugin/Info.plist +24 -0
  36. package/package.json +99 -0
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CapacitorMlkitGenaiRewriting'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '15.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023 Robin Genz
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,429 @@
1
+ # Capacitor ML Kit GenAI Rewriting Plugin
2
+
3
+ Unofficial Capacitor plugin for [ML Kit GenAI Rewriting](https://developers.google.com/ml-kit/genai/rewriting).[^1]
4
+
5
+ > [!WARNING]
6
+ > The ML Kit GenAI APIs are currently in **beta**. The API surface and behavior may change in future releases.
7
+
8
+ <div class="capawesome-z29o10a">
9
+ <a href="https://cloud.capawesome.io/" target="_blank">
10
+ <img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
11
+ </a>
12
+ </div>
13
+
14
+ ## Use Cases
15
+
16
+ The GenAI Rewriting plugin is typically used to reword short messages in different tones and styles on-device using Gemini Nano, for example:
17
+
18
+ - **Tone adjustments**: Rewrite a message to sound more friendly or more professional before sending it.
19
+ - **Length adjustments**: Shorten or elaborate a draft to fit the situation.
20
+ - **Expressive messaging**: Add emojis or rephrase text to give it a fresh look.
21
+
22
+ ## Requirements
23
+
24
+ This plugin uses [Gemini Nano](https://developers.google.com/ml-kit/genai), which runs entirely on-device. It is only available on Android and has the following device requirements:
25
+
26
+ - The device must support Gemini Nano (see [supported devices](https://developers.google.com/ml-kit/genai#supported_devices)).
27
+ - The device must run Android API level 26 or higher.
28
+ - The device must not have an unlocked bootloader.
29
+
30
+ Use the `checkFeatureStatus(...)` method to check whether the feature is available on the device.
31
+
32
+ ## Compatibility
33
+
34
+ | Plugin Version | Capacitor Version | Status |
35
+ | -------------- | ----------------- | -------------- |
36
+ | 8.x.x | >=8.x.x | Active support |
37
+
38
+ ## Installation
39
+
40
+ You can use our **AI-Assisted Setup** to install the plugin.
41
+ Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
42
+
43
+ ```bash
44
+ npx skills add capawesome-team/skills --skill capacitor-plugins
45
+ ```
46
+
47
+ Then use the following prompt:
48
+
49
+ ```
50
+ Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capacitor-mlkit/genai-rewriting` plugin in my project.
51
+ ```
52
+
53
+ If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
54
+
55
+ ```bash
56
+ npm install @capacitor-mlkit/genai-rewriting
57
+ npx cap sync
58
+ ```
59
+
60
+ ### Android
61
+
62
+ #### API level
63
+
64
+ This plugin requires a minimum API level of 26. Make sure to set the `minSdkVersion` in your `variables.gradle` file to at least `26`.
65
+
66
+ #### Variables
67
+
68
+ This plugin will use the following project variables (defined in your app’s `variables.gradle` file):
69
+
70
+ - `$mlkitGenaiRewritingVersion` version of `com.google.mlkit:genai-rewriting` (default: `1.0.0-beta1`)
71
+
72
+ ## Usage
73
+
74
+ The following example shows how to check the feature status, download the feature and rewrite a text.
75
+
76
+ ### Check the feature status
77
+
78
+ Before using the rewriting feature, check whether it is available on the device. The feature availability depends on the configured output type and language:
79
+
80
+ ```typescript
81
+ import {
82
+ FeatureStatus,
83
+ GenAiRewriting,
84
+ Language,
85
+ OutputType,
86
+ } from '@capacitor-mlkit/genai-rewriting';
87
+
88
+ const checkFeatureStatus = async () => {
89
+ const { featureStatus } = await GenAiRewriting.checkFeatureStatus({
90
+ language: Language.English,
91
+ outputType: OutputType.Elaborate,
92
+ });
93
+ return featureStatus === FeatureStatus.Available;
94
+ };
95
+ ```
96
+
97
+ ### Download the feature
98
+
99
+ If the feature status is `DOWNLOADABLE`, download the feature before using it. Add a listener for the `downloadProgress` event to get notified about the download progress:
100
+
101
+ ```typescript
102
+ import { GenAiRewriting, Language, OutputType } from '@capacitor-mlkit/genai-rewriting';
103
+
104
+ const downloadFeature = async () => {
105
+ await GenAiRewriting.addListener('downloadProgress', event => {
106
+ console.log('Total bytes downloaded:', event.totalBytesDownloaded);
107
+ });
108
+ await GenAiRewriting.downloadFeature({
109
+ language: Language.English,
110
+ outputType: OutputType.Elaborate,
111
+ });
112
+ };
113
+ ```
114
+
115
+ ### Rewrite a text
116
+
117
+ Pass the text to `rewrite(...)` to generate the rewritten suggestions. Add a listener for the `inferenceProgress` event to receive partial results as they are generated:
118
+
119
+ ```typescript
120
+ import { GenAiRewriting, Language, OutputType } from '@capacitor-mlkit/genai-rewriting';
121
+
122
+ const rewrite = async () => {
123
+ await GenAiRewriting.addListener('inferenceProgress', event => {
124
+ console.log('Partial result:', event.text);
125
+ });
126
+ const { results } = await GenAiRewriting.rewrite({
127
+ text: 'Capacitor is an open source native runtime for building Web Native apps.',
128
+ language: Language.English,
129
+ outputType: OutputType.Elaborate,
130
+ });
131
+ return results;
132
+ };
133
+ ```
134
+
135
+ ## API
136
+
137
+ <docgen-index>
138
+
139
+ * [`checkFeatureStatus(...)`](#checkfeaturestatus)
140
+ * [`downloadFeature(...)`](#downloadfeature)
141
+ * [`rewrite(...)`](#rewrite)
142
+ * [`addListener('downloadProgress', ...)`](#addlistenerdownloadprogress-)
143
+ * [`addListener('inferenceProgress', ...)`](#addlistenerinferenceprogress-)
144
+ * [`removeAllListeners()`](#removealllisteners)
145
+ * [Interfaces](#interfaces)
146
+ * [Enums](#enums)
147
+
148
+ </docgen-index>
149
+
150
+ <docgen-api>
151
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
152
+
153
+ ### checkFeatureStatus(...)
154
+
155
+ ```typescript
156
+ checkFeatureStatus(options?: FeatureOptions | undefined) => Promise<CheckFeatureStatusResult>
157
+ ```
158
+
159
+ Check the current availability status of the rewriting feature.
160
+
161
+ If the status is `DOWNLOADABLE`, you can download the feature
162
+ using `downloadFeature(...)`.
163
+
164
+ Only available on Android.
165
+
166
+ | Param | Type |
167
+ | ------------- | --------------------------------------------------------- |
168
+ | **`options`** | <code><a href="#featureoptions">FeatureOptions</a></code> |
169
+
170
+ **Returns:** <code>Promise&lt;<a href="#checkfeaturestatusresult">CheckFeatureStatusResult</a>&gt;</code>
171
+
172
+ **Since:** 8.2.0
173
+
174
+ --------------------
175
+
176
+
177
+ ### downloadFeature(...)
178
+
179
+ ```typescript
180
+ downloadFeature(options?: FeatureOptions | undefined) => Promise<void>
181
+ ```
182
+
183
+ Download the rewriting feature.
184
+
185
+ The `downloadProgress` event listener will notify you about
186
+ the download progress. The returned promise resolves when
187
+ the download is complete or the feature is already available.
188
+
189
+ Only available on Android.
190
+
191
+ | Param | Type |
192
+ | ------------- | --------------------------------------------------------- |
193
+ | **`options`** | <code><a href="#featureoptions">FeatureOptions</a></code> |
194
+
195
+ **Since:** 8.2.0
196
+
197
+ --------------------
198
+
199
+
200
+ ### rewrite(...)
201
+
202
+ ```typescript
203
+ rewrite(options: RewriteOptions) => Promise<RewriteResult>
204
+ ```
205
+
206
+ Rewrite the given text in the configured style.
207
+
208
+ The `inferenceProgress` event listener will notify you about
209
+ partial results as they are generated. The returned promise
210
+ resolves with the full result.
211
+
212
+ Only available on Android.
213
+
214
+ | Param | Type |
215
+ | ------------- | --------------------------------------------------------- |
216
+ | **`options`** | <code><a href="#rewriteoptions">RewriteOptions</a></code> |
217
+
218
+ **Returns:** <code>Promise&lt;<a href="#rewriteresult">RewriteResult</a>&gt;</code>
219
+
220
+ **Since:** 8.2.0
221
+
222
+ --------------------
223
+
224
+
225
+ ### addListener('downloadProgress', ...)
226
+
227
+ ```typescript
228
+ addListener(eventName: 'downloadProgress', listenerFunc: (event: DownloadProgressEvent) => void) => Promise<PluginListenerHandle>
229
+ ```
230
+
231
+ Called while the rewriting feature is being downloaded.
232
+
233
+ Only available on Android.
234
+
235
+ | Param | Type |
236
+ | ------------------ | ------------------------------------------------------------------------------------------- |
237
+ | **`eventName`** | <code>'downloadProgress'</code> |
238
+ | **`listenerFunc`** | <code>(event: <a href="#downloadprogressevent">DownloadProgressEvent</a>) =&gt; void</code> |
239
+
240
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
241
+
242
+ **Since:** 8.2.0
243
+
244
+ --------------------
245
+
246
+
247
+ ### addListener('inferenceProgress', ...)
248
+
249
+ ```typescript
250
+ addListener(eventName: 'inferenceProgress', listenerFunc: (event: InferenceProgressEvent) => void) => Promise<PluginListenerHandle>
251
+ ```
252
+
253
+ Called when a new partial result is available during inference.
254
+
255
+ Only available on Android.
256
+
257
+ | Param | Type |
258
+ | ------------------ | --------------------------------------------------------------------------------------------- |
259
+ | **`eventName`** | <code>'inferenceProgress'</code> |
260
+ | **`listenerFunc`** | <code>(event: <a href="#inferenceprogressevent">InferenceProgressEvent</a>) =&gt; void</code> |
261
+
262
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
263
+
264
+ **Since:** 8.2.0
265
+
266
+ --------------------
267
+
268
+
269
+ ### removeAllListeners()
270
+
271
+ ```typescript
272
+ removeAllListeners() => Promise<void>
273
+ ```
274
+
275
+ Remove all listeners for this plugin.
276
+
277
+ **Since:** 8.2.0
278
+
279
+ --------------------
280
+
281
+
282
+ ### Interfaces
283
+
284
+
285
+ #### CheckFeatureStatusResult
286
+
287
+ | Prop | Type | Description | Since |
288
+ | ------------------- | ------------------------------------------------------- | --------------------------------------------------------- | ----- |
289
+ | **`featureStatus`** | <code><a href="#featurestatus">FeatureStatus</a></code> | The current availability status of the rewriting feature. | 8.2.0 |
290
+
291
+
292
+ #### FeatureOptions
293
+
294
+ The feature availability depends on the configured output type
295
+ and language. Therefore, `checkFeatureStatus(...)` and
296
+ `downloadFeature(...)` take the same base options as `rewrite(...)`.
297
+
298
+ | Prop | Type | Description | Default | Since |
299
+ | ---------------- | ------------------------------------------------- | ------------------------------------------------------ | --------------------------------- | ----- |
300
+ | **`language`** | <code><a href="#language">Language</a></code> | The language of the input text. | <code>Language.English</code> | 8.2.0 |
301
+ | **`outputType`** | <code><a href="#outputtype">OutputType</a></code> | The style in which the input text should be rewritten. | <code>OutputType.Elaborate</code> | 8.2.0 |
302
+
303
+
304
+ #### RewriteResult
305
+
306
+ | Prop | Type | Description | Since |
307
+ | ------------- | --------------------- | ------------------------------------------------------------------------- | ----- |
308
+ | **`results`** | <code>string[]</code> | The rewritten text suggestions, sorted in descending order of confidence. | 8.2.0 |
309
+
310
+
311
+ #### RewriteOptions
312
+
313
+ | Prop | Type | Description | Since |
314
+ | ---------- | ------------------- | -------------------------------------------------------- | ----- |
315
+ | **`text`** | <code>string</code> | The text to rewrite. The input must be under 256 tokens. | 8.2.0 |
316
+
317
+
318
+ #### PluginListenerHandle
319
+
320
+ | Prop | Type |
321
+ | ------------ | ----------------------------------------- |
322
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
323
+
324
+
325
+ #### DownloadProgressEvent
326
+
327
+ | Prop | Type | Description | Since |
328
+ | -------------------------- | ------------------- | -------------------------------------------- | ----- |
329
+ | **`totalBytesDownloaded`** | <code>number</code> | The total number of bytes downloaded so far. | 8.2.0 |
330
+
331
+
332
+ #### InferenceProgressEvent
333
+
334
+ | Prop | Type | Description | Since |
335
+ | ---------- | ------------------- | ----------------------------------- | ----- |
336
+ | **`text`** | <code>string</code> | The new text of the partial result. | 8.2.0 |
337
+
338
+
339
+ ### Enums
340
+
341
+
342
+ #### FeatureStatus
343
+
344
+ | Members | Value | Description | Since |
345
+ | ------------------ | --------------------------- | ----------------------------------------------------------- | ----- |
346
+ | **`Available`** | <code>'AVAILABLE'</code> | The feature is available to use. | 8.2.0 |
347
+ | **`Downloadable`** | <code>'DOWNLOADABLE'</code> | The feature can be downloaded using `downloadFeature(...)`. | 8.2.0 |
348
+ | **`Downloading`** | <code>'DOWNLOADING'</code> | The feature is currently being downloaded. | 8.2.0 |
349
+ | **`Unavailable`** | <code>'UNAVAILABLE'</code> | The feature is not available on this device. | 8.2.0 |
350
+
351
+
352
+ #### Language
353
+
354
+ | Members | Value | Since |
355
+ | -------------- | ----------------------- | ----- |
356
+ | **`English`** | <code>'ENGLISH'</code> | 8.2.0 |
357
+ | **`French`** | <code>'FRENCH'</code> | 8.2.0 |
358
+ | **`German`** | <code>'GERMAN'</code> | 8.2.0 |
359
+ | **`Italian`** | <code>'ITALIAN'</code> | 8.2.0 |
360
+ | **`Japanese`** | <code>'JAPANESE'</code> | 8.2.0 |
361
+ | **`Korean`** | <code>'KOREAN'</code> | 8.2.0 |
362
+ | **`Spanish`** | <code>'SPANISH'</code> | 8.2.0 |
363
+
364
+
365
+ #### OutputType
366
+
367
+ | Members | Value | Description | Since |
368
+ | ------------------ | --------------------------- | ---------------------------------------------- | ----- |
369
+ | **`Elaborate`** | <code>'ELABORATE'</code> | Elaborate the input text. | 8.2.0 |
370
+ | **`Emojify`** | <code>'EMOJIFY'</code> | Insert appropriate emojis into the input text. | 8.2.0 |
371
+ | **`Shorten`** | <code>'SHORTEN'</code> | Shorten the input text. | 8.2.0 |
372
+ | **`Friendly`** | <code>'FRIENDLY'</code> | Make the input text more friendly. | 8.2.0 |
373
+ | **`Professional`** | <code>'PROFESSIONAL'</code> | Make the input text more professional. | 8.2.0 |
374
+ | **`Rephrase`** | <code>'REPHRASE'</code> | Rephrase the input text. | 8.2.0 |
375
+
376
+ </docgen-api>
377
+
378
+ ## FAQ
379
+
380
+ ### What are the requirements to use this plugin?
381
+
382
+ The rewriting is performed on-device by Gemini Nano. This requires a device that supports Gemini Nano, Android API level 26 or higher and a locked bootloader (see [Requirements](#requirements)). Use the `checkFeatureStatus(...)` method to check whether the feature is available on the device.
383
+
384
+ ### Why is this plugin only available on Android?
385
+
386
+ The ML Kit GenAI APIs are based on Gemini Nano and AICore, which are currently only available on Android. On iOS and Web, all methods reject with an appropriate error.
387
+
388
+ ### How large can the input text be?
389
+
390
+ The input must be under 256 tokens.
391
+
392
+ ### Why does `rewrite(...)` return multiple results?
393
+
394
+ The model may return more than one suggestion. The suggestions are sorted in descending order of confidence, so the first result is the most confident one.
395
+
396
+ ### How do I get the rewritten text as a stream?
397
+
398
+ Add a listener for the `inferenceProgress` event before calling `rewrite(...)`. The listener is called with each partial result as it is generated. The promise returned by `rewrite(...)` resolves with the full result.
399
+
400
+ ### Can I use this plugin with Ionic, React, Vue or Angular?
401
+
402
+ Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.
403
+
404
+ ## Related Plugins
405
+
406
+ - [Translation](https://capawesome.io/docs/sdks/capacitor/mlkit/translation/): Unofficial Capacitor plugin for ML Kit Translation.
407
+ - [Smart Reply](https://capawesome.io/docs/sdks/capacitor/mlkit/smart-reply/): Unofficial Capacitor plugin for ML Kit Smart Reply.
408
+
409
+ ## Terms & Privacy
410
+
411
+ This plugin uses the [Google ML Kit](https://developers.google.com/ml-kit):
412
+
413
+ - [Terms & Privacy](https://developers.google.com/ml-kit/terms)
414
+ - [Android Data Disclosure](https://developers.google.com/ml-kit/android-data-disclosure)
415
+ - [iOS Data Disclosure](https://developers.google.com/ml-kit/ios-data-disclosure)
416
+
417
+ ## Newsletter
418
+
419
+ Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
420
+
421
+ ## Changelog
422
+
423
+ See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-mlkit/blob/main/packages/genai-rewriting/CHANGELOG.md).
424
+
425
+ ## License
426
+
427
+ See [LICENSE](https://github.com/capawesome-team/capacitor-mlkit/blob/main/packages/genai-rewriting/LICENSE).
428
+
429
+ [^1]: This project is not affiliated with, endorsed by, sponsored by, or approved by Google LLC or any of their affiliates or subsidiaries.