llama-cpp-capacitor 0.0.13 → 0.0.22

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 (34) hide show
  1. package/LlamaCpp.podspec +17 -17
  2. package/Package.swift +27 -27
  3. package/README.md +717 -574
  4. package/android/build.gradle +88 -69
  5. package/android/src/main/AndroidManifest.xml +2 -2
  6. package/android/src/main/CMakeLists-arm64.txt +131 -0
  7. package/android/src/main/CMakeLists-x86_64.txt +135 -0
  8. package/android/src/main/CMakeLists.txt +35 -52
  9. package/android/src/main/java/ai/annadata/plugin/capacitor/LlamaCpp.java +1112 -717
  10. package/android/src/main/java/ai/annadata/plugin/capacitor/LlamaCppPlugin.java +773 -590
  11. package/android/src/main/jni-utils.h +7 -7
  12. package/android/src/main/jni.cpp +868 -127
  13. package/cpp/{rn-completion.cpp → cap-completion.cpp} +202 -24
  14. package/cpp/{rn-completion.h → cap-completion.h} +22 -11
  15. package/cpp/{rn-llama.cpp → cap-llama.cpp} +81 -27
  16. package/cpp/{rn-llama.h → cap-llama.h} +32 -20
  17. package/cpp/{rn-mtmd.hpp → cap-mtmd.hpp} +15 -15
  18. package/cpp/{rn-tts.cpp → cap-tts.cpp} +12 -12
  19. package/cpp/{rn-tts.h → cap-tts.h} +14 -14
  20. package/cpp/ggml-cpu/ggml-cpu-impl.h +30 -0
  21. package/dist/docs.json +268 -3
  22. package/dist/esm/definitions.d.ts +63 -2
  23. package/dist/esm/definitions.js.map +1 -1
  24. package/dist/esm/index.d.ts +22 -0
  25. package/dist/esm/index.js +66 -3
  26. package/dist/esm/index.js.map +1 -1
  27. package/dist/plugin.cjs.js +71 -3
  28. package/dist/plugin.cjs.js.map +1 -1
  29. package/dist/plugin.js +71 -3
  30. package/dist/plugin.js.map +1 -1
  31. package/ios/Sources/LlamaCppPlugin/LlamaCpp.swift +674 -596
  32. package/ios/Sources/LlamaCppPlugin/LlamaCppPlugin.swift +646 -514
  33. package/ios/Tests/LlamaCppPluginTests/LlamaCppPluginTests.swift +15 -15
  34. package/package.json +111 -110
package/dist/docs.json CHANGED
@@ -137,6 +137,67 @@
137
137
  ],
138
138
  "slug": "completion"
139
139
  },
140
+ {
141
+ "name": "chat",
142
+ "signature": "(options: { contextId: number; messages: LlamaCppOAICompatibleMessage[]; system?: string; chatTemplate?: string; params?: Omit<NativeCompletionParams, 'prompt' | 'messages'>; }) => Promise<NativeCompletionResult>",
143
+ "parameters": [
144
+ {
145
+ "name": "options",
146
+ "docs": "",
147
+ "type": "{ contextId: number; messages: LlamaCppOAICompatibleMessage[]; system?: string | undefined; chatTemplate?: string | undefined; params?: Omit<NativeCompletionParams, 'prompt' | 'messages'> | undefined; }"
148
+ }
149
+ ],
150
+ "returns": "Promise<NativeCompletionResult>",
151
+ "tags": [],
152
+ "docs": "",
153
+ "complexTypes": [
154
+ "NativeCompletionResult",
155
+ "LlamaCppOAICompatibleMessage",
156
+ "Omit",
157
+ "NativeCompletionParams"
158
+ ],
159
+ "slug": "chat"
160
+ },
161
+ {
162
+ "name": "chatWithSystem",
163
+ "signature": "(options: { contextId: number; system: string; message: string; params?: Omit<NativeCompletionParams, 'prompt' | 'messages'>; }) => Promise<NativeCompletionResult>",
164
+ "parameters": [
165
+ {
166
+ "name": "options",
167
+ "docs": "",
168
+ "type": "{ contextId: number; system: string; message: string; params?: Omit<NativeCompletionParams, 'prompt' | 'messages'> | undefined; }"
169
+ }
170
+ ],
171
+ "returns": "Promise<NativeCompletionResult>",
172
+ "tags": [],
173
+ "docs": "",
174
+ "complexTypes": [
175
+ "NativeCompletionResult",
176
+ "Omit",
177
+ "NativeCompletionParams"
178
+ ],
179
+ "slug": "chatwithsystem"
180
+ },
181
+ {
182
+ "name": "generateText",
183
+ "signature": "(options: { contextId: number; prompt: string; params?: Omit<NativeCompletionParams, 'prompt' | 'messages'>; }) => Promise<NativeCompletionResult>",
184
+ "parameters": [
185
+ {
186
+ "name": "options",
187
+ "docs": "",
188
+ "type": "{ contextId: number; prompt: string; params?: Omit<NativeCompletionParams, 'prompt' | 'messages'> | undefined; }"
189
+ }
190
+ ],
191
+ "returns": "Promise<NativeCompletionResult>",
192
+ "tags": [],
193
+ "docs": "",
194
+ "complexTypes": [
195
+ "NativeCompletionResult",
196
+ "Omit",
197
+ "NativeCompletionParams"
198
+ ],
199
+ "slug": "generatetext"
200
+ },
140
201
  {
141
202
  "name": "stopCompletion",
142
203
  "signature": "(options: { contextId: number; }) => Promise<void>",
@@ -493,6 +554,82 @@
493
554
  "complexTypes": [],
494
555
  "slug": "releasevocoder"
495
556
  },
557
+ {
558
+ "name": "downloadModel",
559
+ "signature": "(options: { url: string; filename: string; }) => Promise<string>",
560
+ "parameters": [
561
+ {
562
+ "name": "options",
563
+ "docs": "",
564
+ "type": "{ url: string; filename: string; }"
565
+ }
566
+ ],
567
+ "returns": "Promise<string>",
568
+ "tags": [],
569
+ "docs": "",
570
+ "complexTypes": [],
571
+ "slug": "downloadmodel"
572
+ },
573
+ {
574
+ "name": "getDownloadProgress",
575
+ "signature": "(options: { url: string; }) => Promise<{ progress: number; completed: boolean; failed: boolean; errorMessage?: string; localPath?: string; downloadedBytes: number; totalBytes: number; }>",
576
+ "parameters": [
577
+ {
578
+ "name": "options",
579
+ "docs": "",
580
+ "type": "{ url: string; }"
581
+ }
582
+ ],
583
+ "returns": "Promise<{ progress: number; completed: boolean; failed: boolean; errorMessage?: string | undefined; localPath?: string | undefined; downloadedBytes: number; totalBytes: number; }>",
584
+ "tags": [],
585
+ "docs": "",
586
+ "complexTypes": [],
587
+ "slug": "getdownloadprogress"
588
+ },
589
+ {
590
+ "name": "cancelDownload",
591
+ "signature": "(options: { url: string; }) => Promise<boolean>",
592
+ "parameters": [
593
+ {
594
+ "name": "options",
595
+ "docs": "",
596
+ "type": "{ url: string; }"
597
+ }
598
+ ],
599
+ "returns": "Promise<boolean>",
600
+ "tags": [],
601
+ "docs": "",
602
+ "complexTypes": [],
603
+ "slug": "canceldownload"
604
+ },
605
+ {
606
+ "name": "getAvailableModels",
607
+ "signature": "() => Promise<Array<{ name: string; path: string; size: number; }>>",
608
+ "parameters": [],
609
+ "returns": "Promise<{ name: string; path: string; size: number; }[]>",
610
+ "tags": [],
611
+ "docs": "",
612
+ "complexTypes": [
613
+ "Array"
614
+ ],
615
+ "slug": "getavailablemodels"
616
+ },
617
+ {
618
+ "name": "convertJsonSchemaToGrammar",
619
+ "signature": "(options: { schema: string; }) => Promise<string>",
620
+ "parameters": [
621
+ {
622
+ "name": "options",
623
+ "docs": "",
624
+ "type": "{ schema: string; }"
625
+ }
626
+ ],
627
+ "returns": "Promise<string>",
628
+ "tags": [],
629
+ "docs": "",
630
+ "complexTypes": [],
631
+ "slug": "convertjsonschematogrammar"
632
+ },
496
633
  {
497
634
  "name": "addListener",
498
635
  "signature": "(eventName: string, listenerFunc: (data: any) => void) => Promise<void>",
@@ -4031,6 +4168,27 @@
4031
4168
  "complexTypes": [],
4032
4169
  "type": "number | undefined"
4033
4170
  },
4171
+ {
4172
+ "name": "draft_model",
4173
+ "tags": [],
4174
+ "docs": "Path to draft model for speculative decoding (mobile optimization)",
4175
+ "complexTypes": [],
4176
+ "type": "string | undefined"
4177
+ },
4178
+ {
4179
+ "name": "speculative_samples",
4180
+ "tags": [],
4181
+ "docs": "Number of tokens to predict speculatively (default: 3 for mobile)",
4182
+ "complexTypes": [],
4183
+ "type": "number | undefined"
4184
+ },
4185
+ {
4186
+ "name": "mobile_speculative",
4187
+ "tags": [],
4188
+ "docs": "Enable mobile-optimized speculative decoding",
4189
+ "complexTypes": [],
4190
+ "type": "boolean | undefined"
4191
+ },
4034
4192
  {
4035
4193
  "name": "n_gpu_layers",
4036
4194
  "tags": [],
@@ -4263,11 +4421,11 @@
4263
4421
  {
4264
4422
  "name": "tool_calls",
4265
4423
  "tags": [],
4266
- "docs": "Tool calls",
4424
+ "docs": "Tool calls (parsed from response)",
4267
4425
  "complexTypes": [
4268
4426
  "Array"
4269
4427
  ],
4270
- "type": "Array<{\r\n type: 'function';\r\n function: {\r\n name: string;\r\n arguments: string;\r\n };\r\n id?: string;\r\n }>"
4428
+ "type": "Array<{\r\n type: 'function';\r\n function: {\r\n name: string;\r\n arguments: string; // JSON string of arguments\r\n };\r\n id?: string;\r\n }>"
4271
4429
  },
4272
4430
  {
4273
4431
  "name": "content",
@@ -4535,7 +4693,7 @@
4535
4693
  {
4536
4694
  "name": "grammar",
4537
4695
  "tags": [],
4538
- "docs": "Set grammar for grammar-based sampling. Default: no grammar",
4696
+ "docs": "Set grammar for grammar-based sampling (GBNF format). Default: no grammar\r\nThis will override json_schema if both are provided.",
4539
4697
  "complexTypes": [],
4540
4698
  "type": "string | undefined"
4541
4699
  },
@@ -4807,6 +4965,68 @@
4807
4965
  }
4808
4966
  ]
4809
4967
  },
4968
+ {
4969
+ "name": "LlamaCppOAICompatibleMessage",
4970
+ "slug": "llamacppoaicompatiblemessage",
4971
+ "docs": "",
4972
+ "tags": [],
4973
+ "methods": [],
4974
+ "properties": [
4975
+ {
4976
+ "name": "role",
4977
+ "tags": [],
4978
+ "docs": "",
4979
+ "complexTypes": [],
4980
+ "type": "string"
4981
+ },
4982
+ {
4983
+ "name": "content",
4984
+ "tags": [],
4985
+ "docs": "",
4986
+ "complexTypes": [
4987
+ "LlamaCppMessagePart"
4988
+ ],
4989
+ "type": "string | LlamaCppMessagePart[] | undefined"
4990
+ }
4991
+ ]
4992
+ },
4993
+ {
4994
+ "name": "LlamaCppMessagePart",
4995
+ "slug": "llamacppmessagepart",
4996
+ "docs": "",
4997
+ "tags": [],
4998
+ "methods": [],
4999
+ "properties": [
5000
+ {
5001
+ "name": "type",
5002
+ "tags": [],
5003
+ "docs": "",
5004
+ "complexTypes": [],
5005
+ "type": "string"
5006
+ },
5007
+ {
5008
+ "name": "text",
5009
+ "tags": [],
5010
+ "docs": "",
5011
+ "complexTypes": [],
5012
+ "type": "string | undefined"
5013
+ },
5014
+ {
5015
+ "name": "image_url",
5016
+ "tags": [],
5017
+ "docs": "",
5018
+ "complexTypes": [],
5019
+ "type": "{ url?: string | undefined; } | undefined"
5020
+ },
5021
+ {
5022
+ "name": "input_audio",
5023
+ "tags": [],
5024
+ "docs": "",
5025
+ "complexTypes": [],
5026
+ "type": "{ format: string; data?: string | undefined; url?: string | undefined; } | undefined"
5027
+ }
5028
+ ]
5029
+ },
4810
5030
  {
4811
5031
  "name": "NativeSessionLoadResult",
4812
5032
  "slug": "nativesessionloadresult",
@@ -5507,6 +5727,51 @@
5507
5727
  ]
5508
5728
  }
5509
5729
  ]
5730
+ },
5731
+ {
5732
+ "name": "Omit",
5733
+ "slug": "omit",
5734
+ "docs": "Construct a type with the properties of T except for those in type K.",
5735
+ "types": [
5736
+ {
5737
+ "text": "Pick<T, Exclude<keyof T, K>>",
5738
+ "complexTypes": [
5739
+ "Pick",
5740
+ "T",
5741
+ "Exclude",
5742
+ "K"
5743
+ ]
5744
+ }
5745
+ ]
5746
+ },
5747
+ {
5748
+ "name": "Pick",
5749
+ "slug": "pick",
5750
+ "docs": "From T, pick a set of properties whose keys are in the union K",
5751
+ "types": [
5752
+ {
5753
+ "text": "{\r\n [P in K]: T[P];\r\n}",
5754
+ "complexTypes": [
5755
+ "K",
5756
+ "T",
5757
+ "P"
5758
+ ]
5759
+ }
5760
+ ]
5761
+ },
5762
+ {
5763
+ "name": "Exclude",
5764
+ "slug": "exclude",
5765
+ "docs": "Exclude from T those types that are assignable to U",
5766
+ "types": [
5767
+ {
5768
+ "text": "T extends U ? never : T",
5769
+ "complexTypes": [
5770
+ "T",
5771
+ "U"
5772
+ ]
5773
+ }
5774
+ ]
5510
5775
  }
5511
5776
  ],
5512
5777
  "pluginConfigs": []
@@ -13,6 +13,18 @@ export interface NativeContextParams {
13
13
  n_batch?: number;
14
14
  n_ubatch?: number;
15
15
  n_threads?: number;
16
+ /**
17
+ * Path to draft model for speculative decoding (mobile optimization)
18
+ */
19
+ draft_model?: string;
20
+ /**
21
+ * Number of tokens to predict speculatively (default: 3 for mobile)
22
+ */
23
+ speculative_samples?: number;
24
+ /**
25
+ * Enable mobile-optimized speculative decoding
26
+ */
27
+ mobile_speculative?: boolean;
16
28
  /**
17
29
  * Number of layers to store in VRAM (Currently only for iOS)
18
30
  */
@@ -87,7 +99,8 @@ export interface NativeCompletionParams {
87
99
  */
88
100
  json_schema?: string;
89
101
  /**
90
- * Set grammar for grammar-based sampling. Default: no grammar
102
+ * Set grammar for grammar-based sampling (GBNF format). Default: no grammar
103
+ * This will override json_schema if both are provided.
91
104
  */
92
105
  grammar?: string;
93
106
  /**
@@ -268,7 +281,7 @@ export interface NativeCompletionResult {
268
281
  */
269
282
  reasoning_content: string;
270
283
  /**
271
- * Tool calls
284
+ * Tool calls (parsed from response)
272
285
  */
273
286
  tool_calls: Array<{
274
287
  type: 'function';
@@ -483,6 +496,10 @@ export interface CompletionParams extends Omit<NativeCompletionParams, 'emit_par
483
496
  chatTemplate?: string;
484
497
  chat_template?: string;
485
498
  jinja?: boolean;
499
+ /**
500
+ * GBNF grammar for structured output. Takes precedence over json_schema.
501
+ */
502
+ grammar?: string;
486
503
  tools?: object;
487
504
  parallel_tool_calls?: object;
488
505
  tool_choice?: string;
@@ -545,6 +562,24 @@ export interface LlamaCppPlugin {
545
562
  contextId: number;
546
563
  params: NativeCompletionParams;
547
564
  }): Promise<NativeCompletionResult>;
565
+ chat(options: {
566
+ contextId: number;
567
+ messages: LlamaCppOAICompatibleMessage[];
568
+ system?: string;
569
+ chatTemplate?: string;
570
+ params?: Omit<NativeCompletionParams, 'prompt' | 'messages'>;
571
+ }): Promise<NativeCompletionResult>;
572
+ chatWithSystem(options: {
573
+ contextId: number;
574
+ system: string;
575
+ message: string;
576
+ params?: Omit<NativeCompletionParams, 'prompt' | 'messages'>;
577
+ }): Promise<NativeCompletionResult>;
578
+ generateText(options: {
579
+ contextId: number;
580
+ prompt: string;
581
+ params?: Omit<NativeCompletionParams, 'prompt' | 'messages'>;
582
+ }): Promise<NativeCompletionResult>;
548
583
  stopCompletion(options: {
549
584
  contextId: number;
550
585
  }): Promise<void>;
@@ -648,6 +683,32 @@ export interface LlamaCppPlugin {
648
683
  releaseVocoder(options: {
649
684
  contextId: number;
650
685
  }): Promise<void>;
686
+ downloadModel(options: {
687
+ url: string;
688
+ filename: string;
689
+ }): Promise<string>;
690
+ getDownloadProgress(options: {
691
+ url: string;
692
+ }): Promise<{
693
+ progress: number;
694
+ completed: boolean;
695
+ failed: boolean;
696
+ errorMessage?: string;
697
+ localPath?: string;
698
+ downloadedBytes: number;
699
+ totalBytes: number;
700
+ }>;
701
+ cancelDownload(options: {
702
+ url: string;
703
+ }): Promise<boolean>;
704
+ getAvailableModels(): Promise<Array<{
705
+ name: string;
706
+ path: string;
707
+ size: number;
708
+ }>>;
709
+ convertJsonSchemaToGrammar(options: {
710
+ schema: string;
711
+ }): Promise<string>;
651
712
  addListener(eventName: string, listenerFunc: (data: any) => void): Promise<void>;
652
713
  removeAllListeners(eventName: string): Promise<void>;
653
714
  }
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["// Native parameter types that match llama.rn exactly\r\nexport interface NativeEmbeddingParams {\r\n embd_normalize?: number;\r\n}\r\n\r\nexport interface NativeContextParams {\r\n model: string;\r\n /**\r\n * Chat template to override the default one from the model.\r\n */\r\n chat_template?: string;\r\n\r\n is_model_asset?: boolean;\r\n use_progress_callback?: boolean;\r\n\r\n n_ctx?: number;\r\n n_batch?: number;\r\n n_ubatch?: number;\r\n\r\n n_threads?: number;\r\n\r\n /**\r\n * Number of layers to store in VRAM (Currently only for iOS)\r\n */\r\n n_gpu_layers?: number;\r\n /**\r\n * Skip GPU devices (iOS only)\r\n */\r\n no_gpu_devices?: boolean;\r\n\r\n /**\r\n * Enable flash attention, only recommended in GPU device (Experimental in llama.cpp)\r\n */\r\n flash_attn?: boolean;\r\n\r\n /**\r\n * KV cache data type for the K (Experimental in llama.cpp)\r\n */\r\n cache_type_k?: string;\r\n /**\r\n * KV cache data type for the V (Experimental in llama.cpp)\r\n */\r\n cache_type_v?: string;\r\n\r\n use_mlock?: boolean;\r\n use_mmap?: boolean;\r\n vocab_only?: boolean;\r\n\r\n /**\r\n * Single LoRA adapter path\r\n */\r\n lora?: string;\r\n /**\r\n * Single LoRA adapter scale\r\n */\r\n lora_scaled?: number;\r\n /**\r\n * LoRA adapter list\r\n */\r\n lora_list?: Array<{ path: string; scaled?: number }>;\r\n\r\n rope_freq_base?: number;\r\n rope_freq_scale?: number;\r\n\r\n pooling_type?: number;\r\n\r\n /**\r\n * Enable context shifting to handle prompts larger than context size\r\n */\r\n ctx_shift?: boolean;\r\n\r\n /**\r\n * Use a unified buffer across the input sequences when computing the attention.\r\n * Try to disable when n_seq_max > 1 for improved performance when the sequences do not share a large prefix.\r\n */\r\n kv_unified?: boolean;\r\n\r\n /**\r\n * Use full-size SWA cache (https://github.com/ggml-org/llama.cpp/pull/13194#issuecomment-2868343055)\r\n */\r\n swa_full?: boolean;\r\n\r\n /**\r\n * Number of layers to keep MoE weights on CPU\r\n */\r\n n_cpu_moe?: number;\r\n\r\n // Embedding params\r\n embedding?: boolean;\r\n embd_normalize?: number;\r\n}\r\n\r\nexport interface NativeCompletionParams {\r\n prompt: string;\r\n n_threads?: number;\r\n /**\r\n * Enable Jinja. Default: true if supported by the model\r\n */\r\n jinja?: boolean;\r\n /**\r\n * JSON schema for convert to grammar for structured JSON output.\r\n * It will be override by grammar if both are set.\r\n */\r\n json_schema?: string;\r\n /**\r\n * Set grammar for grammar-based sampling. Default: no grammar\r\n */\r\n grammar?: string;\r\n /**\r\n * Lazy grammar sampling, trigger by grammar_triggers. Default: false\r\n */\r\n grammar_lazy?: boolean;\r\n /**\r\n * Enable thinking if jinja is enabled. Default: true\r\n */\r\n enable_thinking?: boolean;\r\n /**\r\n * Force thinking to be open. Default: false\r\n */\r\n thinking_forced_open?: boolean;\r\n /**\r\n * Lazy grammar triggers. Default: []\r\n */\r\n grammar_triggers?: Array<{\r\n type: number;\r\n value: string;\r\n token: number;\r\n }>;\r\n preserved_tokens?: Array<string>;\r\n chat_format?: number;\r\n reasoning_format?: string;\r\n /**\r\n * Path to an image file to process before generating text.\r\n * When provided, the image will be processed and added to the context.\r\n * Requires multimodal support to be enabled via initMultimodal.\r\n */\r\n media_paths?: Array<string>;\r\n /**\r\n * Specify a JSON array of stopping strings.\r\n * These words will not be included in the completion, so make sure to add them to the prompt for the next iteration. Default: `[]`\r\n */\r\n stop?: Array<string>;\r\n /**\r\n * Set the maximum number of tokens to predict when generating text.\r\n * **Note:** May exceed the set limit slightly if the last token is a partial multibyte character.\r\n * When 0,no tokens will be generated but the prompt is evaluated into the cache. Default: `-1`, where `-1` is infinity.\r\n */\r\n n_predict?: number;\r\n /**\r\n * If greater than 0, the response also contains the probabilities of top N tokens for each generated token given the sampling settings.\r\n * Note that for temperature < 0 the tokens are sampled greedily but token probabilities are still being calculated via a simple softmax of the logits without considering any other sampler settings.\r\n * Default: `0`\r\n */\r\n n_probs?: number;\r\n /**\r\n * Limit the next token selection to the K most probable tokens. Default: `40`\r\n */\r\n top_k?: number;\r\n /**\r\n * Limit the next token selection to a subset of tokens with a cumulative probability above a threshold P. Default: `0.95`\r\n */\r\n top_p?: number;\r\n /**\r\n * The minimum probability for a token to be considered, relative to the probability of the most likely token. Default: `0.05`\r\n */\r\n min_p?: number;\r\n /**\r\n * Set the chance for token removal via XTC sampler. Default: `0.0`, which is disabled.\r\n */\r\n xtc_probability?: number;\r\n /**\r\n * Set a minimum probability threshold for tokens to be removed via XTC sampler. Default: `0.1` (> `0.5` disables XTC)\r\n */\r\n xtc_threshold?: number;\r\n /**\r\n * Enable locally typical sampling with parameter p. Default: `1.0`, which is disabled.\r\n */\r\n typical_p?: number;\r\n /**\r\n * Adjust the randomness of the generated text. Default: `0.8`\r\n */\r\n temperature?: number;\r\n /**\r\n * Last n tokens to consider for penalizing repetition. Default: `64`, where `0` is disabled and `-1` is ctx-size.\r\n */\r\n penalty_last_n?: number;\r\n /**\r\n * Control the repetition of token sequences in the generated text. Default: `1.0`\r\n */\r\n penalty_repeat?: number;\r\n /**\r\n * Repeat alpha frequency penalty. Default: `0.0`, which is disabled.\r\n */\r\n penalty_freq?: number;\r\n /**\r\n * Repeat alpha presence penalty. Default: `0.0`, which is disabled.\r\n */\r\n penalty_present?: number;\r\n /**\r\n * Enable Mirostat sampling, controlling perplexity during text generation. Default: `0`, where `0` is disabled, `1` is Mirostat, and `2` is Mirostat 2.0.\r\n */\r\n mirostat?: number;\r\n /**\r\n * Set the Mirostat target entropy, parameter tau. Default: `5.0`\r\n */\r\n mirostat_tau?: number;\r\n /**\r\n * Set the Mirostat learning rate, parameter eta. Default: `0.1`\r\n */\r\n mirostat_eta?: number;\r\n /**\r\n * Set the DRY (Don't Repeat Yourself) repetition penalty multiplier. Default: `0.0`, which is disabled.\r\n */\r\n dry_multiplier?: number;\r\n /**\r\n * Set the DRY repetition penalty base value. Default: `1.75`\r\n */\r\n dry_base?: number;\r\n /**\r\n * Tokens that extend repetition beyond this receive exponentially increasing penalty: multiplier * base ^ (length of repeating sequence before token - allowed length). Default: `2`\r\n */\r\n dry_allowed_length?: number;\r\n /**\r\n * How many tokens to scan for repetitions. Default: `-1`, where `0` is disabled and `-1` is context size.\r\n */\r\n dry_penalty_last_n?: number;\r\n /**\r\n * Specify an array of sequence breakers for DRY sampling. Only a JSON array of strings is accepted. Default: `['\\n', ':', '\"', '*']`\r\n */\r\n dry_sequence_breakers?: Array<string>;\r\n /**\r\n * Top n sigma sampling as described in academic paper \"Top-nσ: Not All Logits Are You Need\" https://arxiv.org/pdf/2411.07641. Default: `-1.0` (Disabled)\r\n */\r\n top_n_sigma?: number;\r\n\r\n /**\r\n * Ignore end of stream token and continue generating. Default: `false`\r\n */\r\n ignore_eos?: boolean;\r\n /**\r\n * Modify the likelihood of a token appearing in the generated text completion.\r\n * For example, use `\"logit_bias\": [[15043,1.0]]` to increase the likelihood of the token 'Hello', or `\"logit_bias\": [[15043,-1.0]]` to decrease its likelihood.\r\n * Setting the value to false, `\"logit_bias\": [[15043,false]]` ensures that the token `Hello` is never produced. The tokens can also be represented as strings,\r\n * e.g.`[[\"Hello, World!\",-0.5]]` will reduce the likelihood of all the individual tokens that represent the string `Hello, World!`, just like the `presence_penalty` does.\r\n * Default: `[]`\r\n */\r\n logit_bias?: Array<Array<number>>;\r\n /**\r\n * Set the random number generator (RNG) seed. Default: `-1`, which is a random seed.\r\n */\r\n seed?: number;\r\n\r\n /**\r\n * Guide tokens for the completion.\r\n * Help prevent hallucinations by forcing the TTS to use the correct words.\r\n * Default: `[]`\r\n */\r\n guide_tokens?: Array<number>;\r\n\r\n emit_partial_completion: boolean;\r\n}\r\n\r\nexport interface NativeCompletionTokenProbItem {\r\n tok_str: string;\r\n prob: number;\r\n}\r\n\r\nexport interface NativeCompletionTokenProb {\r\n content: string;\r\n probs: Array<NativeCompletionTokenProbItem>;\r\n}\r\n\r\nexport interface NativeCompletionResultTimings {\r\n prompt_n: number;\r\n prompt_ms: number;\r\n prompt_per_token_ms: number;\r\n prompt_per_second: number;\r\n predicted_n: number;\r\n predicted_ms: number;\r\n predicted_per_token_ms: number;\r\n predicted_per_second: number;\r\n}\r\n\r\nexport interface NativeCompletionResult {\r\n /**\r\n * Original text (Ignored reasoning_content / tool_calls)\r\n */\r\n text: string;\r\n /**\r\n * Reasoning content (parsed for reasoning model)\r\n */\r\n reasoning_content: string;\r\n /**\r\n * Tool calls\r\n */\r\n tool_calls: Array<{\r\n type: 'function';\r\n function: {\r\n name: string;\r\n arguments: string;\r\n };\r\n id?: string;\r\n }>;\r\n /**\r\n * Content text (Filtered text by reasoning_content / tool_calls)\r\n */\r\n content: string;\r\n\r\n chat_format: number;\r\n\r\n tokens_predicted: number;\r\n tokens_evaluated: number;\r\n truncated: boolean;\r\n stopped_eos: boolean;\r\n stopped_word: string;\r\n stopped_limit: number;\r\n stopping_word: string;\r\n context_full: boolean;\r\n interrupted: boolean;\r\n tokens_cached: number;\r\n timings: NativeCompletionResultTimings;\r\n\r\n completion_probabilities?: Array<NativeCompletionTokenProb>;\r\n audio_tokens?: Array<number>;\r\n}\r\n\r\nexport interface NativeTokenizeResult {\r\n tokens: Array<number>;\r\n /**\r\n * Whether the tokenization contains images\r\n */\r\n has_images: boolean;\r\n /**\r\n * Bitmap hashes of the images\r\n */\r\n bitmap_hashes: Array<number>;\r\n /**\r\n * Chunk positions of the text and images\r\n */\r\n chunk_pos: Array<number>;\r\n /**\r\n * Chunk positions of the images\r\n */\r\n chunk_pos_images: Array<number>;\r\n}\r\n\r\nexport interface NativeEmbeddingResult {\r\n embedding: Array<number>;\r\n}\r\n\r\nexport interface NativeLlamaContext {\r\n contextId: number;\r\n model: {\r\n desc: string;\r\n size: number;\r\n nEmbd: number;\r\n nParams: number;\r\n chatTemplates: {\r\n llamaChat: boolean; // Chat template in llama-chat.cpp\r\n minja: {\r\n // Chat template supported by minja.hpp\r\n default: boolean;\r\n defaultCaps: {\r\n tools: boolean;\r\n toolCalls: boolean;\r\n toolResponses: boolean;\r\n systemRole: boolean;\r\n parallelToolCalls: boolean;\r\n toolCallId: boolean;\r\n };\r\n toolUse: boolean;\r\n toolUseCaps: {\r\n tools: boolean;\r\n toolCalls: boolean;\r\n toolResponses: boolean;\r\n systemRole: boolean;\r\n parallelToolCalls: boolean;\r\n toolCallId: boolean;\r\n };\r\n };\r\n };\r\n metadata: Object;\r\n isChatTemplateSupported: boolean; // Deprecated\r\n };\r\n /**\r\n * Loaded library name for Android\r\n */\r\n androidLib?: string;\r\n gpu: boolean;\r\n reasonNoGPU: string;\r\n}\r\n\r\nexport interface NativeSessionLoadResult {\r\n tokens_loaded: number;\r\n prompt: string;\r\n}\r\n\r\nexport interface NativeLlamaMessagePart {\r\n type: 'text';\r\n text: string;\r\n}\r\n\r\nexport interface NativeLlamaChatMessage {\r\n role: string;\r\n content: string | Array<NativeLlamaMessagePart>;\r\n}\r\n\r\nexport interface FormattedChatResult {\r\n type: 'jinja' | 'llama-chat';\r\n prompt: string;\r\n has_media: boolean;\r\n media_paths?: Array<string>;\r\n}\r\n\r\nexport interface JinjaFormattedChatResult extends FormattedChatResult {\r\n chat_format?: number;\r\n grammar?: string;\r\n grammar_lazy?: boolean;\r\n grammar_triggers?: Array<{\r\n type: number;\r\n value: string;\r\n token: number;\r\n }>;\r\n thinking_forced_open?: boolean;\r\n preserved_tokens?: Array<string>;\r\n additional_stops?: Array<string>;\r\n}\r\n\r\nexport interface NativeImageProcessingResult {\r\n success: boolean;\r\n prompt: string;\r\n error?: string;\r\n}\r\n\r\nexport interface NativeRerankParams {\r\n normalize?: number;\r\n}\r\n\r\nexport interface NativeRerankResult {\r\n score: number;\r\n index: number;\r\n}\r\n\r\n// High-level types for the plugin interface\r\nexport interface LlamaCppMessagePart {\r\n type: string;\r\n text?: string;\r\n image_url?: {\r\n url?: string;\r\n };\r\n input_audio?: {\r\n format: string;\r\n data?: string;\r\n url?: string;\r\n };\r\n}\r\n\r\nexport interface LlamaCppOAICompatibleMessage {\r\n role: string;\r\n content?: string | LlamaCppMessagePart[];\r\n}\r\n\r\nexport interface ToolCall {\r\n type: 'function';\r\n id?: string;\r\n function: {\r\n name: string;\r\n arguments: string; // JSON string\r\n };\r\n}\r\n\r\nexport interface TokenData {\r\n token: string;\r\n completion_probabilities?: Array<NativeCompletionTokenProb>;\r\n // Parsed content from accumulated text\r\n content?: string;\r\n reasoning_content?: string;\r\n tool_calls?: Array<ToolCall>;\r\n accumulated_text?: string;\r\n}\r\n\r\nexport interface ContextParams extends Omit<\r\n NativeContextParams,\r\n 'cache_type_k' | 'cache_type_v' | 'pooling_type'\r\n> {\r\n cache_type_k?:\r\n | 'f16'\r\n | 'f32'\r\n | 'q8_0'\r\n | 'q4_0'\r\n | 'q4_1'\r\n | 'iq4_nl'\r\n | 'q5_0'\r\n | 'q5_1';\r\n cache_type_v?:\r\n | 'f16'\r\n | 'f32'\r\n | 'q8_0'\r\n | 'q4_0'\r\n | 'q4_1'\r\n | 'iq4_nl'\r\n | 'q5_0'\r\n | 'q5_1';\r\n pooling_type?: 'none' | 'mean' | 'cls' | 'last' | 'rank';\r\n}\r\n\r\nexport interface EmbeddingParams extends NativeEmbeddingParams {}\r\n\r\nexport interface RerankParams {\r\n normalize?: number;\r\n}\r\n\r\nexport interface RerankResult {\r\n score: number;\r\n index: number;\r\n document?: string;\r\n}\r\n\r\nexport interface CompletionResponseFormat {\r\n type: 'text' | 'json_object' | 'json_schema';\r\n json_schema?: {\r\n strict?: boolean;\r\n schema: object;\r\n };\r\n schema?: object; // for json_object type\r\n}\r\n\r\nexport interface CompletionBaseParams {\r\n prompt?: string;\r\n messages?: LlamaCppOAICompatibleMessage[];\r\n chatTemplate?: string; // deprecated\r\n chat_template?: string;\r\n jinja?: boolean;\r\n tools?: object;\r\n parallel_tool_calls?: object;\r\n tool_choice?: string;\r\n response_format?: CompletionResponseFormat;\r\n media_paths?: string[];\r\n add_generation_prompt?: boolean;\r\n /*\r\n * Timestamp in seconds since epoch to apply to chat template's strftime_now\r\n */\r\n now?: string | number;\r\n chat_template_kwargs?: Record<string, string>;\r\n /**\r\n * Prefill text to be used for chat parsing (Generation Prompt + Content)\r\n * Used for if last assistant message is for prefill purpose\r\n */\r\n prefill_text?: string;\r\n}\r\n\r\nexport interface CompletionParams extends Omit<\r\n NativeCompletionParams,\r\n 'emit_partial_completion' | 'prompt'\r\n> {\r\n prompt?: string;\r\n messages?: LlamaCppOAICompatibleMessage[];\r\n chatTemplate?: string; // deprecated\r\n chat_template?: string;\r\n jinja?: boolean;\r\n tools?: object;\r\n parallel_tool_calls?: object;\r\n tool_choice?: string;\r\n response_format?: CompletionResponseFormat;\r\n media_paths?: string[];\r\n add_generation_prompt?: boolean;\r\n /*\r\n * Timestamp in seconds since epoch to apply to chat template's strftime_now\r\n */\r\n now?: string | number;\r\n chat_template_kwargs?: Record<string, string>;\r\n /**\r\n * Prefill text to be used for chat parsing (Generation Prompt + Content)\r\n * Used for if last assistant message is for prefill purpose\r\n */\r\n prefill_text?: string;\r\n}\r\n\r\nexport interface BenchResult {\r\n modelDesc: string;\r\n modelSize: number;\r\n modelNParams: number;\r\n ppAvg: number;\r\n ppStd: number;\r\n tgAvg: number;\r\n tgStd: number;\r\n}\r\n\r\n// Main plugin interface\r\nexport interface LlamaCppPlugin {\r\n // Core initialization and management\r\n toggleNativeLog(options: { enabled: boolean }): Promise<void>;\r\n setContextLimit(options: { limit: number }): Promise<void>;\r\n modelInfo(options: { path: string; skip?: string[] }): Promise<Object>;\r\n initContext(options: { contextId: number; params: NativeContextParams }): Promise<NativeLlamaContext>;\r\n releaseContext(options: { contextId: number }): Promise<void>;\r\n releaseAllContexts(): Promise<void>;\r\n\r\n // Chat and completion\r\n getFormattedChat(options: {\r\n contextId: number;\r\n messages: string;\r\n chatTemplate?: string;\r\n params?: {\r\n jinja?: boolean;\r\n json_schema?: string;\r\n tools?: string;\r\n parallel_tool_calls?: string;\r\n tool_choice?: string;\r\n enable_thinking?: boolean;\r\n add_generation_prompt?: boolean;\r\n now?: string;\r\n chat_template_kwargs?: string;\r\n };\r\n }): Promise<JinjaFormattedChatResult | string>;\r\n\r\n completion(options: {\r\n contextId: number;\r\n params: NativeCompletionParams;\r\n }): Promise<NativeCompletionResult>;\r\n\r\n stopCompletion(options: { contextId: number }): Promise<void>;\r\n\r\n // Session management\r\n loadSession(options: {\r\n contextId: number;\r\n filepath: string;\r\n }): Promise<NativeSessionLoadResult>;\r\n\r\n saveSession(options: {\r\n contextId: number;\r\n filepath: string;\r\n size: number;\r\n }): Promise<number>;\r\n\r\n // Tokenization\r\n tokenize(options: {\r\n contextId: number;\r\n text: string;\r\n imagePaths?: Array<string>;\r\n }): Promise<NativeTokenizeResult>;\r\n\r\n detokenize(options: {\r\n contextId: number;\r\n tokens: number[];\r\n }): Promise<string>;\r\n\r\n // Embeddings and reranking\r\n embedding(options: {\r\n contextId: number;\r\n text: string;\r\n params: NativeEmbeddingParams;\r\n }): Promise<NativeEmbeddingResult>;\r\n\r\n rerank(options: {\r\n contextId: number;\r\n query: string;\r\n documents: Array<string>;\r\n params?: NativeRerankParams;\r\n }): Promise<Array<NativeRerankResult>>;\r\n\r\n // Benchmarking\r\n bench(options: {\r\n contextId: number;\r\n pp: number;\r\n tg: number;\r\n pl: number;\r\n nr: number;\r\n }): Promise<string>;\r\n\r\n // LoRA adapters\r\n applyLoraAdapters(options: {\r\n contextId: number;\r\n loraAdapters: Array<{ path: string; scaled?: number }>;\r\n }): Promise<void>;\r\n\r\n removeLoraAdapters(options: { contextId: number }): Promise<void>;\r\n\r\n getLoadedLoraAdapters(options: {\r\n contextId: number;\r\n }): Promise<Array<{ path: string; scaled?: number }>>;\r\n\r\n // Multimodal methods\r\n initMultimodal(options: {\r\n contextId: number;\r\n params: {\r\n path: string;\r\n use_gpu: boolean;\r\n };\r\n }): Promise<boolean>;\r\n\r\n isMultimodalEnabled(options: {\r\n contextId: number;\r\n }): Promise<boolean>;\r\n\r\n getMultimodalSupport(options: {\r\n contextId: number;\r\n }): Promise<{\r\n vision: boolean;\r\n audio: boolean;\r\n }>;\r\n\r\n releaseMultimodal(options: {\r\n contextId: number;\r\n }): Promise<void>;\r\n\r\n // TTS methods\r\n initVocoder(options: {\r\n contextId: number;\r\n params: {\r\n path: string;\r\n n_batch?: number;\r\n };\r\n }): Promise<boolean>;\r\n\r\n isVocoderEnabled(options: { contextId: number }): Promise<boolean>;\r\n\r\n getFormattedAudioCompletion(options: {\r\n contextId: number;\r\n speakerJsonStr: string;\r\n textToSpeak: string;\r\n }): Promise<{\r\n prompt: string;\r\n grammar?: string;\r\n }>;\r\n\r\n getAudioCompletionGuideTokens(options: {\r\n contextId: number;\r\n textToSpeak: string;\r\n }): Promise<Array<number>>;\r\n\r\n decodeAudioTokens(options: {\r\n contextId: number;\r\n tokens: number[];\r\n }): Promise<Array<number>>;\r\n\r\n releaseVocoder(options: { contextId: number }): Promise<void>;\r\n\r\n // Events\r\n addListener(eventName: string, listenerFunc: (data: any) => void): Promise<void>;\r\n removeAllListeners(eventName: string): Promise<void>;\r\n}\r\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["// Native parameter types that match llama.rn exactly\r\nexport interface NativeEmbeddingParams {\r\n embd_normalize?: number;\r\n}\r\n\r\nexport interface NativeContextParams {\r\n model: string;\r\n /**\r\n * Chat template to override the default one from the model.\r\n */\r\n chat_template?: string;\r\n\r\n is_model_asset?: boolean;\r\n use_progress_callback?: boolean;\r\n\r\n n_ctx?: number;\r\n n_batch?: number;\r\n n_ubatch?: number;\r\n\r\n n_threads?: number;\r\n\r\n /**\r\n * Path to draft model for speculative decoding (mobile optimization)\r\n */\r\n draft_model?: string;\r\n /**\r\n * Number of tokens to predict speculatively (default: 3 for mobile)\r\n */\r\n speculative_samples?: number;\r\n /**\r\n * Enable mobile-optimized speculative decoding\r\n */\r\n mobile_speculative?: boolean;\r\n\r\n /**\r\n * Number of layers to store in VRAM (Currently only for iOS)\r\n */\r\n n_gpu_layers?: number;\r\n /**\r\n * Skip GPU devices (iOS only)\r\n */\r\n no_gpu_devices?: boolean;\r\n\r\n /**\r\n * Enable flash attention, only recommended in GPU device (Experimental in llama.cpp)\r\n */\r\n flash_attn?: boolean;\r\n\r\n /**\r\n * KV cache data type for the K (Experimental in llama.cpp)\r\n */\r\n cache_type_k?: string;\r\n /**\r\n * KV cache data type for the V (Experimental in llama.cpp)\r\n */\r\n cache_type_v?: string;\r\n\r\n use_mlock?: boolean;\r\n use_mmap?: boolean;\r\n vocab_only?: boolean;\r\n\r\n /**\r\n * Single LoRA adapter path\r\n */\r\n lora?: string;\r\n /**\r\n * Single LoRA adapter scale\r\n */\r\n lora_scaled?: number;\r\n /**\r\n * LoRA adapter list\r\n */\r\n lora_list?: Array<{ path: string; scaled?: number }>;\r\n\r\n rope_freq_base?: number;\r\n rope_freq_scale?: number;\r\n\r\n pooling_type?: number;\r\n\r\n /**\r\n * Enable context shifting to handle prompts larger than context size\r\n */\r\n ctx_shift?: boolean;\r\n\r\n /**\r\n * Use a unified buffer across the input sequences when computing the attention.\r\n * Try to disable when n_seq_max > 1 for improved performance when the sequences do not share a large prefix.\r\n */\r\n kv_unified?: boolean;\r\n\r\n /**\r\n * Use full-size SWA cache (https://github.com/ggml-org/llama.cpp/pull/13194#issuecomment-2868343055)\r\n */\r\n swa_full?: boolean;\r\n\r\n /**\r\n * Number of layers to keep MoE weights on CPU\r\n */\r\n n_cpu_moe?: number;\r\n\r\n // Embedding params\r\n embedding?: boolean;\r\n embd_normalize?: number;\r\n}\r\n\r\nexport interface NativeCompletionParams {\r\n prompt: string;\r\n n_threads?: number;\r\n /**\r\n * Enable Jinja. Default: true if supported by the model\r\n */\r\n jinja?: boolean;\r\n /**\r\n * JSON schema for convert to grammar for structured JSON output.\r\n * It will be override by grammar if both are set.\r\n */\r\n json_schema?: string;\r\n /**\r\n * Set grammar for grammar-based sampling (GBNF format). Default: no grammar\r\n * This will override json_schema if both are provided.\r\n */\r\n grammar?: string;\r\n /**\r\n * Lazy grammar sampling, trigger by grammar_triggers. Default: false\r\n */\r\n grammar_lazy?: boolean;\r\n /**\r\n * Enable thinking if jinja is enabled. Default: true\r\n */\r\n enable_thinking?: boolean;\r\n /**\r\n * Force thinking to be open. Default: false\r\n */\r\n thinking_forced_open?: boolean;\r\n /**\r\n * Lazy grammar triggers. Default: []\r\n */\r\n grammar_triggers?: Array<{\r\n type: number;\r\n value: string;\r\n token: number;\r\n }>;\r\n preserved_tokens?: Array<string>;\r\n chat_format?: number;\r\n reasoning_format?: string;\r\n /**\r\n * Path to an image file to process before generating text.\r\n * When provided, the image will be processed and added to the context.\r\n * Requires multimodal support to be enabled via initMultimodal.\r\n */\r\n media_paths?: Array<string>;\r\n /**\r\n * Specify a JSON array of stopping strings.\r\n * These words will not be included in the completion, so make sure to add them to the prompt for the next iteration. Default: `[]`\r\n */\r\n stop?: Array<string>;\r\n /**\r\n * Set the maximum number of tokens to predict when generating text.\r\n * **Note:** May exceed the set limit slightly if the last token is a partial multibyte character.\r\n * When 0,no tokens will be generated but the prompt is evaluated into the cache. Default: `-1`, where `-1` is infinity.\r\n */\r\n n_predict?: number;\r\n /**\r\n * If greater than 0, the response also contains the probabilities of top N tokens for each generated token given the sampling settings.\r\n * Note that for temperature < 0 the tokens are sampled greedily but token probabilities are still being calculated via a simple softmax of the logits without considering any other sampler settings.\r\n * Default: `0`\r\n */\r\n n_probs?: number;\r\n /**\r\n * Limit the next token selection to the K most probable tokens. Default: `40`\r\n */\r\n top_k?: number;\r\n /**\r\n * Limit the next token selection to a subset of tokens with a cumulative probability above a threshold P. Default: `0.95`\r\n */\r\n top_p?: number;\r\n /**\r\n * The minimum probability for a token to be considered, relative to the probability of the most likely token. Default: `0.05`\r\n */\r\n min_p?: number;\r\n /**\r\n * Set the chance for token removal via XTC sampler. Default: `0.0`, which is disabled.\r\n */\r\n xtc_probability?: number;\r\n /**\r\n * Set a minimum probability threshold for tokens to be removed via XTC sampler. Default: `0.1` (> `0.5` disables XTC)\r\n */\r\n xtc_threshold?: number;\r\n /**\r\n * Enable locally typical sampling with parameter p. Default: `1.0`, which is disabled.\r\n */\r\n typical_p?: number;\r\n /**\r\n * Adjust the randomness of the generated text. Default: `0.8`\r\n */\r\n temperature?: number;\r\n /**\r\n * Last n tokens to consider for penalizing repetition. Default: `64`, where `0` is disabled and `-1` is ctx-size.\r\n */\r\n penalty_last_n?: number;\r\n /**\r\n * Control the repetition of token sequences in the generated text. Default: `1.0`\r\n */\r\n penalty_repeat?: number;\r\n /**\r\n * Repeat alpha frequency penalty. Default: `0.0`, which is disabled.\r\n */\r\n penalty_freq?: number;\r\n /**\r\n * Repeat alpha presence penalty. Default: `0.0`, which is disabled.\r\n */\r\n penalty_present?: number;\r\n /**\r\n * Enable Mirostat sampling, controlling perplexity during text generation. Default: `0`, where `0` is disabled, `1` is Mirostat, and `2` is Mirostat 2.0.\r\n */\r\n mirostat?: number;\r\n /**\r\n * Set the Mirostat target entropy, parameter tau. Default: `5.0`\r\n */\r\n mirostat_tau?: number;\r\n /**\r\n * Set the Mirostat learning rate, parameter eta. Default: `0.1`\r\n */\r\n mirostat_eta?: number;\r\n /**\r\n * Set the DRY (Don't Repeat Yourself) repetition penalty multiplier. Default: `0.0`, which is disabled.\r\n */\r\n dry_multiplier?: number;\r\n /**\r\n * Set the DRY repetition penalty base value. Default: `1.75`\r\n */\r\n dry_base?: number;\r\n /**\r\n * Tokens that extend repetition beyond this receive exponentially increasing penalty: multiplier * base ^ (length of repeating sequence before token - allowed length). Default: `2`\r\n */\r\n dry_allowed_length?: number;\r\n /**\r\n * How many tokens to scan for repetitions. Default: `-1`, where `0` is disabled and `-1` is context size.\r\n */\r\n dry_penalty_last_n?: number;\r\n /**\r\n * Specify an array of sequence breakers for DRY sampling. Only a JSON array of strings is accepted. Default: `['\\n', ':', '\"', '*']`\r\n */\r\n dry_sequence_breakers?: Array<string>;\r\n /**\r\n * Top n sigma sampling as described in academic paper \"Top-nσ: Not All Logits Are You Need\" https://arxiv.org/pdf/2411.07641. Default: `-1.0` (Disabled)\r\n */\r\n top_n_sigma?: number;\r\n\r\n /**\r\n * Ignore end of stream token and continue generating. Default: `false`\r\n */\r\n ignore_eos?: boolean;\r\n /**\r\n * Modify the likelihood of a token appearing in the generated text completion.\r\n * For example, use `\"logit_bias\": [[15043,1.0]]` to increase the likelihood of the token 'Hello', or `\"logit_bias\": [[15043,-1.0]]` to decrease its likelihood.\r\n * Setting the value to false, `\"logit_bias\": [[15043,false]]` ensures that the token `Hello` is never produced. The tokens can also be represented as strings,\r\n * e.g.`[[\"Hello, World!\",-0.5]]` will reduce the likelihood of all the individual tokens that represent the string `Hello, World!`, just like the `presence_penalty` does.\r\n * Default: `[]`\r\n */\r\n logit_bias?: Array<Array<number>>;\r\n /**\r\n * Set the random number generator (RNG) seed. Default: `-1`, which is a random seed.\r\n */\r\n seed?: number;\r\n\r\n /**\r\n * Guide tokens for the completion.\r\n * Help prevent hallucinations by forcing the TTS to use the correct words.\r\n * Default: `[]`\r\n */\r\n guide_tokens?: Array<number>;\r\n\r\n emit_partial_completion: boolean;\r\n}\r\n\r\nexport interface NativeCompletionTokenProbItem {\r\n tok_str: string;\r\n prob: number;\r\n}\r\n\r\nexport interface NativeCompletionTokenProb {\r\n content: string;\r\n probs: Array<NativeCompletionTokenProbItem>;\r\n}\r\n\r\nexport interface NativeCompletionResultTimings {\r\n prompt_n: number;\r\n prompt_ms: number;\r\n prompt_per_token_ms: number;\r\n prompt_per_second: number;\r\n predicted_n: number;\r\n predicted_ms: number;\r\n predicted_per_token_ms: number;\r\n predicted_per_second: number;\r\n}\r\n\r\nexport interface NativeCompletionResult {\r\n /**\r\n * Original text (Ignored reasoning_content / tool_calls)\r\n */\r\n text: string;\r\n /**\r\n * Reasoning content (parsed for reasoning model)\r\n */\r\n reasoning_content: string;\r\n /**\r\n * Tool calls (parsed from response)\r\n */\r\n tool_calls: Array<{\r\n type: 'function';\r\n function: {\r\n name: string;\r\n arguments: string; // JSON string of arguments\r\n };\r\n id?: string;\r\n }>;\r\n /**\r\n * Content text (Filtered text by reasoning_content / tool_calls)\r\n */\r\n content: string;\r\n\r\n chat_format: number;\r\n\r\n tokens_predicted: number;\r\n tokens_evaluated: number;\r\n truncated: boolean;\r\n stopped_eos: boolean;\r\n stopped_word: string;\r\n stopped_limit: number;\r\n stopping_word: string;\r\n context_full: boolean;\r\n interrupted: boolean;\r\n tokens_cached: number;\r\n timings: NativeCompletionResultTimings;\r\n\r\n completion_probabilities?: Array<NativeCompletionTokenProb>;\r\n audio_tokens?: Array<number>;\r\n}\r\n\r\nexport interface NativeTokenizeResult {\r\n tokens: Array<number>;\r\n /**\r\n * Whether the tokenization contains images\r\n */\r\n has_images: boolean;\r\n /**\r\n * Bitmap hashes of the images\r\n */\r\n bitmap_hashes: Array<number>;\r\n /**\r\n * Chunk positions of the text and images\r\n */\r\n chunk_pos: Array<number>;\r\n /**\r\n * Chunk positions of the images\r\n */\r\n chunk_pos_images: Array<number>;\r\n}\r\n\r\nexport interface NativeEmbeddingResult {\r\n embedding: Array<number>;\r\n}\r\n\r\nexport interface NativeLlamaContext {\r\n contextId: number;\r\n model: {\r\n desc: string;\r\n size: number;\r\n nEmbd: number;\r\n nParams: number;\r\n chatTemplates: {\r\n llamaChat: boolean; // Chat template in llama-chat.cpp\r\n minja: {\r\n // Chat template supported by minja.hpp\r\n default: boolean;\r\n defaultCaps: {\r\n tools: boolean;\r\n toolCalls: boolean;\r\n toolResponses: boolean;\r\n systemRole: boolean;\r\n parallelToolCalls: boolean;\r\n toolCallId: boolean;\r\n };\r\n toolUse: boolean;\r\n toolUseCaps: {\r\n tools: boolean;\r\n toolCalls: boolean;\r\n toolResponses: boolean;\r\n systemRole: boolean;\r\n parallelToolCalls: boolean;\r\n toolCallId: boolean;\r\n };\r\n };\r\n };\r\n metadata: Object;\r\n isChatTemplateSupported: boolean; // Deprecated\r\n };\r\n /**\r\n * Loaded library name for Android\r\n */\r\n androidLib?: string;\r\n gpu: boolean;\r\n reasonNoGPU: string;\r\n}\r\n\r\nexport interface NativeSessionLoadResult {\r\n tokens_loaded: number;\r\n prompt: string;\r\n}\r\n\r\nexport interface NativeLlamaMessagePart {\r\n type: 'text';\r\n text: string;\r\n}\r\n\r\nexport interface NativeLlamaChatMessage {\r\n role: string;\r\n content: string | Array<NativeLlamaMessagePart>;\r\n}\r\n\r\nexport interface FormattedChatResult {\r\n type: 'jinja' | 'llama-chat';\r\n prompt: string;\r\n has_media: boolean;\r\n media_paths?: Array<string>;\r\n}\r\n\r\nexport interface JinjaFormattedChatResult extends FormattedChatResult {\r\n chat_format?: number;\r\n grammar?: string;\r\n grammar_lazy?: boolean;\r\n grammar_triggers?: Array<{\r\n type: number;\r\n value: string;\r\n token: number;\r\n }>;\r\n thinking_forced_open?: boolean;\r\n preserved_tokens?: Array<string>;\r\n additional_stops?: Array<string>;\r\n}\r\n\r\nexport interface NativeImageProcessingResult {\r\n success: boolean;\r\n prompt: string;\r\n error?: string;\r\n}\r\n\r\nexport interface NativeRerankParams {\r\n normalize?: number;\r\n}\r\n\r\nexport interface NativeRerankResult {\r\n score: number;\r\n index: number;\r\n}\r\n\r\n// High-level types for the plugin interface\r\nexport interface LlamaCppMessagePart {\r\n type: string;\r\n text?: string;\r\n image_url?: {\r\n url?: string;\r\n };\r\n input_audio?: {\r\n format: string;\r\n data?: string;\r\n url?: string;\r\n };\r\n}\r\n\r\nexport interface LlamaCppOAICompatibleMessage {\r\n role: string;\r\n content?: string | LlamaCppMessagePart[];\r\n}\r\n\r\nexport interface ToolCall {\r\n type: 'function';\r\n id?: string;\r\n function: {\r\n name: string;\r\n arguments: string; // JSON string\r\n };\r\n}\r\n\r\nexport interface TokenData {\r\n token: string;\r\n completion_probabilities?: Array<NativeCompletionTokenProb>;\r\n // Parsed content from accumulated text\r\n content?: string;\r\n reasoning_content?: string;\r\n tool_calls?: Array<ToolCall>;\r\n accumulated_text?: string;\r\n}\r\n\r\nexport interface ContextParams extends Omit<\r\n NativeContextParams,\r\n 'cache_type_k' | 'cache_type_v' | 'pooling_type'\r\n> {\r\n cache_type_k?:\r\n | 'f16'\r\n | 'f32'\r\n | 'q8_0'\r\n | 'q4_0'\r\n | 'q4_1'\r\n | 'iq4_nl'\r\n | 'q5_0'\r\n | 'q5_1';\r\n cache_type_v?:\r\n | 'f16'\r\n | 'f32'\r\n | 'q8_0'\r\n | 'q4_0'\r\n | 'q4_1'\r\n | 'iq4_nl'\r\n | 'q5_0'\r\n | 'q5_1';\r\n pooling_type?: 'none' | 'mean' | 'cls' | 'last' | 'rank';\r\n}\r\n\r\nexport interface EmbeddingParams extends NativeEmbeddingParams {}\r\n\r\nexport interface RerankParams {\r\n normalize?: number;\r\n}\r\n\r\nexport interface RerankResult {\r\n score: number;\r\n index: number;\r\n document?: string;\r\n}\r\n\r\nexport interface CompletionResponseFormat {\r\n type: 'text' | 'json_object' | 'json_schema';\r\n json_schema?: {\r\n strict?: boolean;\r\n schema: object;\r\n };\r\n schema?: object; // for json_object type\r\n}\r\n\r\nexport interface CompletionBaseParams {\r\n prompt?: string;\r\n messages?: LlamaCppOAICompatibleMessage[];\r\n chatTemplate?: string; // deprecated\r\n chat_template?: string;\r\n jinja?: boolean;\r\n tools?: object;\r\n parallel_tool_calls?: object;\r\n tool_choice?: string;\r\n response_format?: CompletionResponseFormat;\r\n media_paths?: string[];\r\n add_generation_prompt?: boolean;\r\n /*\r\n * Timestamp in seconds since epoch to apply to chat template's strftime_now\r\n */\r\n now?: string | number;\r\n chat_template_kwargs?: Record<string, string>;\r\n /**\r\n * Prefill text to be used for chat parsing (Generation Prompt + Content)\r\n * Used for if last assistant message is for prefill purpose\r\n */\r\n prefill_text?: string;\r\n}\r\n\r\nexport interface CompletionParams extends Omit<\r\n NativeCompletionParams,\r\n 'emit_partial_completion' | 'prompt'\r\n> {\r\n prompt?: string;\r\n messages?: LlamaCppOAICompatibleMessage[];\r\n chatTemplate?: string; // deprecated\r\n chat_template?: string;\r\n jinja?: boolean;\r\n /**\r\n * GBNF grammar for structured output. Takes precedence over json_schema.\r\n */\r\n grammar?: string;\r\n tools?: object;\r\n parallel_tool_calls?: object;\r\n tool_choice?: string;\r\n response_format?: CompletionResponseFormat;\r\n media_paths?: string[];\r\n add_generation_prompt?: boolean;\r\n /*\r\n * Timestamp in seconds since epoch to apply to chat template's strftime_now\r\n */\r\n now?: string | number;\r\n chat_template_kwargs?: Record<string, string>;\r\n /**\r\n * Prefill text to be used for chat parsing (Generation Prompt + Content)\r\n * Used for if last assistant message is for prefill purpose\r\n */\r\n prefill_text?: string;\r\n}\r\n\r\nexport interface BenchResult {\r\n modelDesc: string;\r\n modelSize: number;\r\n modelNParams: number;\r\n ppAvg: number;\r\n ppStd: number;\r\n tgAvg: number;\r\n tgStd: number;\r\n}\r\n\r\n// Main plugin interface\r\nexport interface LlamaCppPlugin {\r\n // Core initialization and management\r\n toggleNativeLog(options: { enabled: boolean }): Promise<void>;\r\n setContextLimit(options: { limit: number }): Promise<void>;\r\n modelInfo(options: { path: string; skip?: string[] }): Promise<Object>;\r\n initContext(options: { contextId: number; params: NativeContextParams }): Promise<NativeLlamaContext>;\r\n releaseContext(options: { contextId: number }): Promise<void>;\r\n releaseAllContexts(): Promise<void>;\r\n\r\n // Chat and completion\r\n getFormattedChat(options: {\r\n contextId: number;\r\n messages: string;\r\n chatTemplate?: string;\r\n params?: {\r\n jinja?: boolean;\r\n json_schema?: string;\r\n tools?: string;\r\n parallel_tool_calls?: string;\r\n tool_choice?: string;\r\n enable_thinking?: boolean;\r\n add_generation_prompt?: boolean;\r\n now?: string;\r\n chat_template_kwargs?: string;\r\n };\r\n }): Promise<JinjaFormattedChatResult | string>;\r\n\r\n completion(options: {\r\n contextId: number;\r\n params: NativeCompletionParams;\r\n }): Promise<NativeCompletionResult>;\r\n\r\n // Chat-first methods (like llama-cli -sys)\r\n chat(options: {\r\n contextId: number;\r\n messages: LlamaCppOAICompatibleMessage[];\r\n system?: string; // Simple system prompt like llama-cli -sys\r\n chatTemplate?: string;\r\n params?: Omit<NativeCompletionParams, 'prompt' | 'messages'>;\r\n }): Promise<NativeCompletionResult>;\r\n\r\n // Simple chat with system prompt (like llama-cli -sys \"You are a helpful assistant\")\r\n chatWithSystem(options: {\r\n contextId: number;\r\n system: string;\r\n message: string;\r\n params?: Omit<NativeCompletionParams, 'prompt' | 'messages'>;\r\n }): Promise<NativeCompletionResult>;\r\n\r\n // Simple text generation (like llama-cli -p \"prompt\")\r\n generateText(options: {\r\n contextId: number;\r\n prompt: string;\r\n params?: Omit<NativeCompletionParams, 'prompt' | 'messages'>;\r\n }): Promise<NativeCompletionResult>;\r\n\r\n stopCompletion(options: { contextId: number }): Promise<void>;\r\n\r\n // Session management\r\n loadSession(options: {\r\n contextId: number;\r\n filepath: string;\r\n }): Promise<NativeSessionLoadResult>;\r\n\r\n saveSession(options: {\r\n contextId: number;\r\n filepath: string;\r\n size: number;\r\n }): Promise<number>;\r\n\r\n // Tokenization\r\n tokenize(options: {\r\n contextId: number;\r\n text: string;\r\n imagePaths?: Array<string>;\r\n }): Promise<NativeTokenizeResult>;\r\n\r\n detokenize(options: {\r\n contextId: number;\r\n tokens: number[];\r\n }): Promise<string>;\r\n\r\n // Embeddings and reranking\r\n embedding(options: {\r\n contextId: number;\r\n text: string;\r\n params: NativeEmbeddingParams;\r\n }): Promise<NativeEmbeddingResult>;\r\n\r\n rerank(options: {\r\n contextId: number;\r\n query: string;\r\n documents: Array<string>;\r\n params?: NativeRerankParams;\r\n }): Promise<Array<NativeRerankResult>>;\r\n\r\n // Benchmarking\r\n bench(options: {\r\n contextId: number;\r\n pp: number;\r\n tg: number;\r\n pl: number;\r\n nr: number;\r\n }): Promise<string>;\r\n\r\n // LoRA adapters\r\n applyLoraAdapters(options: {\r\n contextId: number;\r\n loraAdapters: Array<{ path: string; scaled?: number }>;\r\n }): Promise<void>;\r\n\r\n removeLoraAdapters(options: { contextId: number }): Promise<void>;\r\n\r\n getLoadedLoraAdapters(options: {\r\n contextId: number;\r\n }): Promise<Array<{ path: string; scaled?: number }>>;\r\n\r\n // Multimodal methods\r\n initMultimodal(options: {\r\n contextId: number;\r\n params: {\r\n path: string;\r\n use_gpu: boolean;\r\n };\r\n }): Promise<boolean>;\r\n\r\n isMultimodalEnabled(options: {\r\n contextId: number;\r\n }): Promise<boolean>;\r\n\r\n getMultimodalSupport(options: {\r\n contextId: number;\r\n }): Promise<{\r\n vision: boolean;\r\n audio: boolean;\r\n }>;\r\n\r\n releaseMultimodal(options: {\r\n contextId: number;\r\n }): Promise<void>;\r\n\r\n // TTS methods\r\n initVocoder(options: {\r\n contextId: number;\r\n params: {\r\n path: string;\r\n n_batch?: number;\r\n };\r\n }): Promise<boolean>;\r\n\r\n isVocoderEnabled(options: { contextId: number }): Promise<boolean>;\r\n\r\n getFormattedAudioCompletion(options: {\r\n contextId: number;\r\n speakerJsonStr: string;\r\n textToSpeak: string;\r\n }): Promise<{\r\n prompt: string;\r\n grammar?: string;\r\n }>;\r\n\r\n getAudioCompletionGuideTokens(options: {\r\n contextId: number;\r\n textToSpeak: string;\r\n }): Promise<Array<number>>;\r\n\r\n decodeAudioTokens(options: {\r\n contextId: number;\r\n tokens: number[];\r\n }): Promise<Array<number>>;\r\n\r\n releaseVocoder(options: { contextId: number }): Promise<void>;\r\n\r\n // Model download and management\r\n downloadModel(options: {\r\n url: string;\r\n filename: string;\r\n }): Promise<string>;\r\n\r\n getDownloadProgress(options: {\r\n url: string;\r\n }): Promise<{\r\n progress: number;\r\n completed: boolean;\r\n failed: boolean;\r\n errorMessage?: string;\r\n localPath?: string;\r\n downloadedBytes: number;\r\n totalBytes: number;\r\n }>;\r\n\r\n cancelDownload(options: {\r\n url: string;\r\n }): Promise<boolean>;\r\n\r\n getAvailableModels(): Promise<Array<{\r\n name: string;\r\n path: string;\r\n size: number;\r\n }>>;\r\n\r\n // Grammar utilities\r\n convertJsonSchemaToGrammar(options: {\r\n schema: string;\r\n }): Promise<string>;\r\n\r\n // Events\r\n addListener(eventName: string, listenerFunc: (data: any) => void): Promise<void>;\r\n removeAllListeners(eventName: string): Promise<void>;\r\n}\r\n"]}
@@ -173,6 +173,28 @@ export declare function setContextLimit(limit: number): Promise<void>;
173
173
  export declare function loadLlamaModelInfo(model: string): Promise<Object>;
174
174
  export declare function initLlama({ model, is_model_asset: isModelAsset, pooling_type: poolingType, lora, lora_list: loraList, ...rest }: ContextParams, onProgress?: (progress: number) => void): Promise<LlamaContext>;
175
175
  export declare function releaseAllLlama(): Promise<void>;
176
+ export declare function downloadModel(url: string, filename: string): Promise<string>;
177
+ export declare function getDownloadProgress(url: string): Promise<{
178
+ progress: number;
179
+ completed: boolean;
180
+ failed: boolean;
181
+ errorMessage?: string;
182
+ localPath?: string;
183
+ downloadedBytes: number;
184
+ totalBytes: number;
185
+ }>;
186
+ export declare function cancelDownload(url: string): Promise<boolean>;
187
+ export declare function getAvailableModels(): Promise<Array<{
188
+ name: string;
189
+ path: string;
190
+ size: number;
191
+ }>>;
192
+ /**
193
+ * Convert a JSON schema to GBNF grammar format
194
+ * @param schema JSON schema object
195
+ * @returns Promise resolving to GBNF grammar string
196
+ */
197
+ export declare function convertJsonSchemaToGrammar(schema: object): Promise<string>;
176
198
  export declare const BuildInfo: {
177
199
  number: string;
178
200
  commit: string;
package/dist/esm/index.js CHANGED
@@ -39,6 +39,27 @@ const getJsonSchema = (responseFormat) => {
39
39
  }
40
40
  return null;
41
41
  };
42
+ // Utility function to convert JSON schema to GBNF grammar
43
+ const jsonSchemaToGrammar = async (schema) => {
44
+ // This will call the native method to convert JSON schema to GBNF
45
+ // For now, we'll return a basic implementation
46
+ try {
47
+ const result = await LlamaCpp.convertJsonSchemaToGrammar({ schema: JSON.stringify(schema) });
48
+ return result;
49
+ }
50
+ catch (error) {
51
+ console.warn('Failed to convert JSON schema to GBNF, using fallback:', error);
52
+ // Fallback for basic object structure
53
+ return `root ::= "{" ws object_content ws "}"
54
+ object_content ::= string_field ("," ws string_field)*
55
+ string_field ::= "\\"" [a-zA-Z_][a-zA-Z0-9_]* "\\"" ws ":" ws value
56
+ value ::= string | number | boolean | "null"
57
+ string ::= "\\"" [^"]* "\\""
58
+ number ::= "-"? [0-9]+ ("." [0-9]+)?
59
+ boolean ::= "true" | "false"
60
+ ws ::= [ \\t\\n]*`;
61
+ }
62
+ };
42
63
  export class LlamaContext {
43
64
  constructor({ contextId, gpu, reasonNoGPU, model }) {
44
65
  this.gpu = false;
@@ -217,10 +238,23 @@ export class LlamaContext {
217
238
  if (!nativeParams.media_paths && params.media_paths) {
218
239
  nativeParams.media_paths = params.media_paths;
219
240
  }
220
- if (nativeParams.response_format && !nativeParams.grammar) {
241
+ // Handle structured output and grammar
242
+ if (params.grammar) {
243
+ // Direct GBNF grammar takes precedence
244
+ nativeParams.grammar = params.grammar;
245
+ }
246
+ else if (nativeParams.response_format && !nativeParams.grammar) {
221
247
  const jsonSchema = getJsonSchema(params.response_format);
222
- if (jsonSchema)
223
- nativeParams.json_schema = JSON.stringify(jsonSchema);
248
+ if (jsonSchema) {
249
+ // Try to convert JSON schema to GBNF grammar
250
+ try {
251
+ nativeParams.grammar = await jsonSchemaToGrammar(jsonSchema);
252
+ }
253
+ catch (error) {
254
+ console.warn('Failed to convert JSON schema to grammar, falling back to json_schema parameter:', error);
255
+ nativeParams.json_schema = JSON.stringify(jsonSchema);
256
+ }
257
+ }
224
258
  }
225
259
  let tokenListener = callback &&
226
260
  LlamaCpp.addListener(EVENT_ON_TOKEN, (evt) => {
@@ -480,6 +514,14 @@ export async function initLlama(_a, onProgress) {
480
514
  console.warn(`[LlamaCpp] initLlama: Invalid cache V type: ${rest.cache_type_v}, falling back to f16`);
481
515
  delete rest.cache_type_v;
482
516
  }
517
+ // Log speculative decoding configuration if enabled
518
+ if (rest.draft_model) {
519
+ console.log(`🚀 Initializing with speculative decoding:
520
+ - Main model: ${path}
521
+ - Draft model: ${rest.draft_model}
522
+ - Speculative samples: ${rest.speculative_samples || 3}
523
+ - Mobile optimization: ${rest.mobile_speculative !== false ? 'enabled' : 'disabled'}`);
524
+ }
483
525
  const { gpu, reasonNoGPU, model: modelDetails, androidLib, } = await LlamaCpp.initContext({
484
526
  contextId,
485
527
  params: Object.assign({ model: path, is_model_asset: !!isModelAsset, use_progress_callback: !!onProgress, pooling_type: poolType, lora: loraPath, lora_list: loraAdapters }, rest),
@@ -499,6 +541,27 @@ export async function initLlama(_a, onProgress) {
499
541
  export async function releaseAllLlama() {
500
542
  return LlamaCpp.releaseAllContexts();
501
543
  }
544
+ // Model download and management functions
545
+ export async function downloadModel(url, filename) {
546
+ return LlamaCpp.downloadModel({ url, filename });
547
+ }
548
+ export async function getDownloadProgress(url) {
549
+ return LlamaCpp.getDownloadProgress({ url });
550
+ }
551
+ export async function cancelDownload(url) {
552
+ return LlamaCpp.cancelDownload({ url });
553
+ }
554
+ export async function getAvailableModels() {
555
+ return LlamaCpp.getAvailableModels();
556
+ }
557
+ /**
558
+ * Convert a JSON schema to GBNF grammar format
559
+ * @param schema JSON schema object
560
+ * @returns Promise resolving to GBNF grammar string
561
+ */
562
+ export async function convertJsonSchemaToGrammar(schema) {
563
+ return jsonSchemaToGrammar(schema);
564
+ }
502
565
  export const BuildInfo = {
503
566
  number: '1.0.0',
504
567
  commit: 'capacitor-llama-cpp',