antfly-embedded-sys 0.3.0

Raw FFI declarations for libantfly, the embedded Antfly C ABI (hand-written, no bindgen)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
// Copyright 2026 Antfly, Inc.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Raw, hand-written FFI declarations for `libantfly`, the embedded Antfly
//! C ABI.
//!
//! This mirrors `zig/pkg/antfly-embedded/include/antfly.h` field-for-field and
//! function-for-function. There is no `bindgen`/`libclang` dependency: the
//! header is small and stable enough that a hand-written mirror is easier to
//! audit and does not require a C toolchain to build this crate.
//!
//! Nothing in this crate is safe to call directly: every function takes raw
//! pointers and untyped handles exactly as the C ABI defines them. Use the
//! `antfly-embedded` crate for a safe API.
//!
//! Linking against the actual `libantfly` dylib only happens when the
//! `libantfly` Cargo feature is enabled (see `build.rs`). Without it, this
//! crate compiles (and its types can be named) but must not be linked into
//! any binary that references these `extern "C"` items, or linking will
//! fail.
//!
//! Naming (mirrors the header's own convention): `antfly_*` functions are
//! library-level and take no database handle; `antfly_db_*` functions take
//! an `antfly_db` handle of any storage kind; `antfly_lite_*` functions
//! operate on the `.aflite` single-file format itself, plus shortcuts for
//! opening one.
#![allow(non_camel_case_types)]

use std::ffi::{c_char, c_void};

// ---------------------------------------------------------------------
// antfly_error_code
// ---------------------------------------------------------------------

/// A stable Antfly C ABI error code. Represented as `i32` to match a plain
/// C `enum`'s default underlying type on every target this crate supports.
pub type antfly_error_code = i32;

pub const ANTFLY_OK: antfly_error_code = 0;
pub const ANTFLY_INVALID_ARGUMENT: antfly_error_code = 1;
pub const ANTFLY_NOT_FOUND: antfly_error_code = 2;
pub const ANTFLY_VERSION_CONFLICT: antfly_error_code = 3;
pub const ANTFLY_INTENT_CONFLICT: antfly_error_code = 4;
pub const ANTFLY_TXN_NOT_FOUND: antfly_error_code = 5;
pub const ANTFLY_BUSY: antfly_error_code = 6;
pub const ANTFLY_OUTCOME_UNKNOWN: antfly_error_code = 7;
pub const ANTFLY_UNSUPPORTED: antfly_error_code = 8;
pub const ANTFLY_STALLED: antfly_error_code = 9;
/// The caller cancelled the call by returning `false` from its progress or
/// stream callback.
pub const ANTFLY_CANCELLED: antfly_error_code = 10;
pub const ANTFLY_INTERNAL: antfly_error_code = 255;

// ---------------------------------------------------------------------
// antfly_db (opaque handle)
// ---------------------------------------------------------------------

/// An open database. Opaque; see `antfly_db_open_with_options`. Every
/// handle-taking function in this crate takes `*mut antfly_db` /
/// `*mut *mut antfly_db`, matching the header's typed opaque pointer (ABI
/// version 2 replaced the untyped `void *` handle with this type).
#[repr(C)]
pub struct antfly_db {
    _private: [u8; 0],
}

// ---------------------------------------------------------------------
// antfly_inference (opaque handle) -- embedded inference without a database
// ---------------------------------------------------------------------

/// An open embedded inference runtime, with no database. Opaque; see
/// `antfly_inference_open`. Models load on first use and stay cached until
/// the handle closes. Handles have the same thread-safety guarantees as
/// `antfly_db` (see `zig/CAPI.md`'s "Thread Safety" section): any thread may
/// call concurrently, close waits for in-flight calls, and a closed or
/// foreign handle is rejected with `ANTFLY_INVALID_ARGUMENT`.
#[repr(C)]
pub struct antfly_inference {
    _private: [u8; 0],
}

/// Options for `antfly_inference_open`. `reserved`/`abi_size` layout must
/// mirror the header exactly -- `tests/abi_sizes.rs` checks
/// `size_of::<antfly_inference_options>()` against
/// `antfly_inference_options_size()`.
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct antfly_inference_options {
    pub abi_size: u32,
    /// No flags are defined yet; must be zero.
    pub flags: u32,
    /// Models directory. Empty uses `$ANTFLY_INFERENCE_MODELS_DIR`, else
    /// `~/.antfly/inference/models`.
    pub models_dir: antfly_slice,
    /// Resource budgets in MiB, 0 meaning automatic; the same knobs as the
    /// `inference_*_budget_mb` fields of `antfly_open_options`.
    pub host_budget_mb: u32,
    pub backend_budget_mb: u32,
    pub process_memory_budget_mb: u32,
    pub combined_budget_mb: u32,
    pub kv_budget_mb: u32,
    pub scratch_budget_mb: u32,
    /// Deadline for each call in milliseconds; 0 means none.
    pub call_timeout_ms: u64,
    pub reserved: [u64; 8],
}

/// One report to an `antfly_inference_pull_json` progress callback. The
/// slices are valid only during the callback. Check `abi_size` before
/// reading fields added in later versions.
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct antfly_inference_pull_progress {
    pub abi_size: u32,
    pub reserved0: u32,
    /// The model reference being pulled (one per requested variant).
    pub model: antfly_slice,
    pub file: antfly_slice,
    pub bytes_downloaded: u64,
    /// 0 when unknown.
    pub total_bytes: u64,
    pub files_done: u64,
    pub files_total: u64,
    /// The file was already present and verified; nothing was downloaded.
    pub cached: bool,
}

/// Progress callback for `antfly_inference_pull_json`. May be `None`
/// (a NULL function pointer). Called synchronously on the calling thread;
/// the `*const antfly_inference_pull_progress` it receives is only valid for
/// the duration of the call. Return `true` to continue, `false` to cancel
/// the pull (the call then returns `ANTFLY_CANCELLED`; completed files stay
/// staged, so a later pull of the same model resumes rather than restarts).
pub type antfly_inference_pull_progress_fn = Option<
    unsafe extern "C" fn(
        context: *mut c_void,
        progress: *const antfly_inference_pull_progress,
    ) -> bool,
>;

/// Streaming callback for `antfly_inference_generate_stream_json`. Receives
/// one streamed chunk -- the JSON of a `chat.completion.chunk` -- valid only
/// during the call, called on the calling thread as the model produces
/// tokens. Return `true` to continue, `false` to stop generating (the call
/// then returns `ANTFLY_CANCELLED`).
pub type antfly_inference_stream_fn =
    Option<unsafe extern "C" fn(context: *mut c_void, chunk_json: antfly_slice) -> bool>;

// ---------------------------------------------------------------------
// antfly_txn_status
// ---------------------------------------------------------------------

/// Transaction intent lifecycle state. Every C ABI function that carries a
/// transaction status uses a raw `uint8_t`, not this enum type, so this
/// alias exists only for documentation/parity with the header.
pub type antfly_txn_status = u8;

pub const ANTFLY_TXN_PENDING: antfly_txn_status = 0;
pub const ANTFLY_TXN_COMMITTED: antfly_txn_status = 1;
pub const ANTFLY_TXN_ABORTED: antfly_txn_status = 2;

/// `antfly_db_outcome_receipt_status` result: the uncertain write applied.
pub const ANTFLY_OUTCOME_RECEIPT_APPLIED: u8 = 1;
/// `antfly_db_outcome_receipt_status` result: the uncertain write did not apply.
pub const ANTFLY_OUTCOME_RECEIPT_NOT_APPLIED: u8 = 2;

// ---------------------------------------------------------------------
// Open mode / profile / storage kind / flag constants
// ---------------------------------------------------------------------

pub const ANTFLY_OPEN_MODE_WRITER: u32 = 0;
pub const ANTFLY_OPEN_MODE_READONLY: u32 = 1;
pub const ANTFLY_OPEN_MODE_STATUS_ONLY: u32 = 2;

pub const ANTFLY_STORAGE_KIND_DIRECTORY: u32 = 0;
pub const ANTFLY_STORAGE_KIND_LITE: u32 = 1;

pub const ANTFLY_PROFILE_NATIVE: u32 = 0;
pub const ANTFLY_PROFILE_HOSTED: u32 = 1;

pub const ANTFLY_OPEN_FLAG_NO_SYNC: u32 = 1 << 0;
pub const ANTFLY_OPEN_FLAG_TTL_CLEANUP: u32 = 1 << 1;
pub const ANTFLY_OPEN_FLAG_REMOTE_PROVIDER_CONFIGURED: u32 = 1 << 2;
pub const ANTFLY_OPEN_FLAG_LOCAL_RUNTIME_CONFIGURED: u32 = 1 << 3;
pub const ANTFLY_OPEN_FLAG_GENERATED_ENRICHMENT_REPLAY: u32 = 1 << 4;

/// `inference.mode` values reported by `antfly_db_status_json`.
pub const ANTFLY_INFERENCE_MODE_CALLER_SUPPLIED_OR_DISABLED: &str = "caller_supplied_or_disabled";
pub const ANTFLY_INFERENCE_MODE_CALLER_SUPPLIED_ARTIFACTS: &str = "caller_supplied_artifacts";
pub const ANTFLY_INFERENCE_MODE_REMOTE_PROVIDER: &str = "remote_provider";
pub const ANTFLY_INFERENCE_MODE_LOCAL_EMBEDDED: &str = "local_embedded";
pub const ANTFLY_INFERENCE_MODE_MANUAL_MAINTENANCE: &str = "manual_maintenance";
pub const ANTFLY_INFERENCE_MODE_DISABLED_DEFERRED: &str = "disabled_deferred";

/// Threading contract, like `sqlite3_threadsafe()`. See `antfly_threading_mode`.
pub const ANTFLY_THREADING_SERIALIZED: u32 = 1;

/// Minimum native stack, in bytes, for any thread that calls into libantfly.
/// See `ANTFLY_MIN_THREAD_STACK_SIZE` in antfly.h.
pub const ANTFLY_MIN_THREAD_STACK_SIZE: usize = 8 * 1024 * 1024;

/// `direction` values for `antfly_db_get_edges_json` and
/// `antfly_db_get_neighbors_json`.
pub const ANTFLY_GRAPH_DIRECTION_OUT: u8 = 0;
pub const ANTFLY_GRAPH_DIRECTION_IN: u8 = 1;
pub const ANTFLY_GRAPH_DIRECTION_BOTH: u8 = 2;

// ---------------------------------------------------------------------
// Plain-old-data structs (repr(C), field order matches antfly.h exactly)
// ---------------------------------------------------------------------

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct antfly_slice {
    pub ptr: *const u8,
    pub len: usize,
}

impl Default for antfly_slice {
    fn default() -> Self {
        antfly_slice {
            ptr: std::ptr::null(),
            len: 0,
        }
    }
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct antfly_buffer {
    pub ptr: *mut u8,
    pub len: usize,
}

impl Default for antfly_buffer {
    fn default() -> Self {
        antfly_buffer {
            ptr: std::ptr::null_mut(),
            len: 0,
        }
    }
}

/// One options struct for every storage kind. `storage_kind` (an
/// `ANTFLY_STORAGE_KIND_*` value) picks a `.aflite` file or a normal
/// directory; the inference budget fields, `busy_timeout_ms`, and
/// The reserved tail and models_dir layout must mirror the header exactly -- `tests/abi_sizes.rs`
/// checks `size_of::<antfly_open_options>()` against
/// `antfly_open_options_size()`.
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct antfly_open_options {
    pub abi_size: u32,
    pub storage_kind: u32,
    pub open_mode: u32,
    pub profile: u32,
    pub flags: u32,
    pub reserved0: u32,
    pub map_size: u64,
    pub ttl_cleanup_enabled: bool,
    pub ttl_cleanup_lease_owned: bool,
    pub ttl_cleanup_batch_size: u32,
    pub ttl_cleanup_owner_id: antfly_slice,
    pub ttl_cleanup_lease_ttl_ms: u64,
    pub ttl_cleanup_interval_ms: u64,
    pub ttl_cleanup_grace_period_ns: u64,
    /// Explicit embedded-inference resource-budget overrides in MiB, 0
    /// meaning automatic/host-detected sizing. Only consulted when `flags`
    /// carries `ANTFLY_OPEN_FLAG_LOCAL_RUNTIME_CONFIGURED`.
    pub inference_host_budget_mb: u32,
    pub inference_backend_budget_mb: u32,
    pub inference_process_memory_budget_mb: u32,
    pub inference_combined_budget_mb: u32,
    pub inference_kv_budget_mb: u32,
    pub inference_scratch_budget_mb: u32,
    /// Milliseconds to retry Lite admission while another process holds the
    /// writer lease or advances the allocator checkpoint (`ANTFLY_BUSY`), like
    /// `sqlite3_busy_timeout`. 0 fails immediately. Mutation bodies are never
    /// replayed by this admission retry.
    pub busy_timeout_ms: u64,
    pub reserved: [u64; 6],
    pub models_dir: antfly_slice,
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct antfly_write_intent {
    pub key: antfly_slice,
    pub value: antfly_slice,
    pub is_delete: bool,
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct antfly_version_predicate {
    pub key: antfly_slice,
    pub expected_version: u64,
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct antfly_dense_search_hit {
    pub id_ptr: *mut u8,
    pub id_len: usize,
    pub score: f32,
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct antfly_dense_search_result {
    pub hits_ptr: *mut antfly_dense_search_hit,
    pub hit_count: usize,
    pub total_hits: u32,
    pub identity_read_generation: u64,
}

impl Default for antfly_dense_search_result {
    fn default() -> Self {
        antfly_dense_search_result {
            hits_ptr: std::ptr::null_mut(),
            hit_count: 0,
            total_hits: 0,
            identity_read_generation: 0,
        }
    }
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct antfly_packed_dense_search_hit {
    pub id_offset: usize,
    pub id_len: usize,
    pub score: f32,
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct antfly_packed_dense_search_result {
    pub hits_ptr: *mut antfly_packed_dense_search_hit,
    pub hit_count: usize,
    pub total_hits: u32,
    pub ids_ptr: *mut u8,
    pub ids_len: usize,
    pub identity_read_generation: u64,
}

impl Default for antfly_packed_dense_search_result {
    fn default() -> Self {
        antfly_packed_dense_search_result {
            hits_ptr: std::ptr::null_mut(),
            hit_count: 0,
            total_hits: 0,
            ids_ptr: std::ptr::null_mut(),
            ids_len: 0,
            identity_read_generation: 0,
        }
    }
}

#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
pub struct antfly_dense_search_profile {
    pub total_ns: u64,
    pub index_lookup_ns: u64,
    pub search_ns: u64,
    pub hits_ns: u64,
    pub fallback_ns: u64,
    pub hbc_total_ns: u64,
    pub hbc_setup_ns: u64,
    pub hbc_root_load_ns: u64,
    pub hbc_node_cache_miss_ns: u64,
    pub hbc_node_cache_misses: u64,
    pub hbc_quantized_cache_miss_ns: u64,
    pub hbc_quantized_cache_misses: u64,
    pub hbc_child_expand_ns: u64,
    pub hbc_leaf_score_ns: u64,
    pub hbc_rerank_ns: u64,
    pub hbc_rerank_vector_load_ns: u64,
    pub hbc_rerank_distance_ns: u64,
    pub hbc_nodes_visited: u64,
    pub hbc_leaves_explored: u64,
    pub hbc_reranked_vectors: u64,
    pub hit_count: u32,
    pub total_hits: u32,
    pub used_fast_path: bool,
}

#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
pub struct antfly_dense_wire_search_profile {
    pub total_ns: u64,
    pub decode_ns: u64,
    pub search_ns: u64,
    pub resolve_ns: u64,
    pub encode_ns: u64,
    pub fallback_ns: u64,
    pub hbc_total_ns: u64,
    pub hbc_setup_ns: u64,
    pub hbc_root_load_ns: u64,
    pub hbc_node_cache_miss_ns: u64,
    pub hbc_node_cache_misses: u64,
    pub hbc_quantized_cache_miss_ns: u64,
    pub hbc_quantized_cache_misses: u64,
    pub hbc_child_expand_ns: u64,
    pub hbc_leaf_score_ns: u64,
    pub hbc_rerank_ns: u64,
    pub hbc_rerank_vector_load_ns: u64,
    pub hbc_rerank_distance_ns: u64,
    pub hbc_nodes_visited: u64,
    pub hbc_leaves_explored: u64,
    pub hbc_reranked_vectors: u64,
    pub hit_count: u32,
    pub total_hits: u32,
    pub used_fast_path: bool,
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct antfly_scan_hash_entry {
    pub id_ptr: *mut u8,
    pub id_len: usize,
    pub hash: u64,
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct antfly_scan_hash_result {
    pub entries_ptr: *mut antfly_scan_hash_entry,
    pub entry_count: usize,
}

impl Default for antfly_scan_hash_result {
    fn default() -> Self {
        antfly_scan_hash_result {
            entries_ptr: std::ptr::null_mut(),
            entry_count: 0,
        }
    }
}

// ---------------------------------------------------------------------
// extern "C" functions -- order matches antfly.h
// ---------------------------------------------------------------------

unsafe extern "C" {
    pub fn antfly_abi_version() -> u32;
    pub fn antfly_open_options_size() -> u32;
    pub fn antfly_last_error_detail() -> *const c_char;
    pub fn antfly_last_error_code() -> antfly_error_code;
    pub fn antfly_error_code_name(code: antfly_error_code) -> *const c_char;
    pub fn antfly_error_code_description(code: antfly_error_code) -> *const c_char;
    pub fn antfly_open_options_init(options: *mut antfly_open_options) -> antfly_error_code;

    pub fn antfly_threading_mode() -> u32;

    pub fn antfly_db_open(path: *const c_char, out_db: *mut *mut antfly_db) -> antfly_error_code;
    pub fn antfly_db_open_with_options(
        path: *const c_char,
        options: *const antfly_open_options,
        out_db: *mut *mut antfly_db,
    ) -> antfly_error_code;
    pub fn antfly_db_create_with_options(
        path: *const c_char,
        options: *const antfly_open_options,
        out_db: *mut *mut antfly_db,
    ) -> antfly_error_code;
    pub fn antfly_db_close(db: *mut antfly_db);

    pub fn antfly_lite_open(path: *const c_char, out_db: *mut *mut antfly_db) -> antfly_error_code;
    pub fn antfly_lite_create(
        path: *const c_char,
        out_db: *mut *mut antfly_db,
    ) -> antfly_error_code;
    pub fn antfly_lite_open_hosted(
        path: *const c_char,
        out_db: *mut *mut antfly_db,
    ) -> antfly_error_code;
    pub fn antfly_lite_create_hosted(
        path: *const c_char,
        out_db: *mut *mut antfly_db,
    ) -> antfly_error_code;
    pub fn antfly_lite_open_readonly(
        path: *const c_char,
        out_db: *mut *mut antfly_db,
    ) -> antfly_error_code;
    pub fn antfly_lite_open_status_only(
        path: *const c_char,
        out_db: *mut *mut antfly_db,
    ) -> antfly_error_code;

    pub fn antfly_db_status_json(db: *mut antfly_db, out: *mut antfly_buffer) -> antfly_error_code;
    pub fn antfly_db_capabilities_json(
        db: *mut antfly_db,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;

    pub fn antfly_db_backup(db: *mut antfly_db, out: *mut antfly_buffer) -> antfly_error_code;
    pub fn antfly_db_backup_json(
        db: *mut antfly_db,
        options: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_import_backup(db: *mut antfly_db, backup: antfly_slice) -> antfly_error_code;
    pub fn antfly_restore_backup_json(
        dest_path: *const c_char,
        options: *const antfly_open_options,
        backup: antfly_slice,
        replace: bool,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_restore_backup_file_json(
        dest_path: *const c_char,
        options: *const antfly_open_options,
        backup_path: *const c_char,
        replace: bool,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;

    pub fn antfly_lite_check_json(db: *mut antfly_db, out: *mut antfly_buffer)
    -> antfly_error_code;
    pub fn antfly_lite_check_file_json(
        path: *const c_char,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_lite_copy_stable_snapshot_json(
        db: *mut antfly_db,
        dest_path: *const c_char,
        replace: bool,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_lite_copy_stable_snapshot_file_json(
        src_path: *const c_char,
        dest_path: *const c_char,
        replace: bool,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_lite_compact_json(
        db: *mut antfly_db,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_lite_vacuum_json(
        db: *mut antfly_db,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;

    pub fn antfly_buffer_free(buffer: *mut antfly_buffer);
    pub fn antfly_buffer_free_zero(buffer: *mut antfly_buffer);
    pub fn antfly_dense_search_result_free(result: *mut antfly_dense_search_result);
    pub fn antfly_packed_dense_search_result_free(result: *mut antfly_packed_dense_search_result);
    pub fn antfly_scan_hash_result_free(result: *mut antfly_scan_hash_result);

    pub fn antfly_db_batch(
        db: *mut antfly_db,
        writes: *const antfly_write_intent,
        write_count: usize,
        predicates: *const antfly_version_predicate,
        predicate_count: usize,
        timestamp_ns: u64,
        sync_level: u8,
    ) -> antfly_error_code;
    pub fn antfly_db_batch_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    /// Receipt of this thread's most recent `ANTFLY_OUTCOME_UNKNOWN` from an
    /// autocommit SQL write or batch export; call on the same thread before
    /// any other Antfly call. `ANTFLY_NOT_FOUND` when that call issued none.
    pub fn antfly_last_error_outcome_receipt(out: *mut antfly_buffer) -> antfly_error_code;
    /// `antfly_db_batch_json` that also returns the receipt in `receipt_out`
    /// (only on `ANTFLY_OUTCOME_UNKNOWN`), for callers whose consecutive
    /// native calls may run on different threads.
    pub fn antfly_db_batch_with_receipt(
        db: *mut antfly_db,
        writes: *const antfly_write_intent,
        write_count: usize,
        predicates: *const antfly_version_predicate,
        predicate_count: usize,
        timestamp_ns: u64,
        sync_level: u8,
        receipt_out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_batch_json_with_receipt(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
        receipt_out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_outcome_receipt_status(
        db: *mut antfly_db,
        receipt: antfly_slice,
        out_status: *mut u8,
    ) -> antfly_error_code;
    pub fn antfly_db_outcome_receipt_forget(
        db: *mut antfly_db,
        receipt: antfly_slice,
    ) -> antfly_error_code;
    pub fn antfly_db_begin_transaction_with_id(
        db: *mut antfly_db,
        txn_id: *const [u8; 16],
        timestamp_ns: u64,
        participants: *const antfly_slice,
        participant_count: usize,
    ) -> antfly_error_code;
    pub fn antfly_db_write_transaction(
        db: *mut antfly_db,
        txn_id: *const [u8; 16],
        writes: *const antfly_write_intent,
        write_count: usize,
        predicates: *const antfly_version_predicate,
        predicate_count: usize,
    ) -> antfly_error_code;
    pub fn antfly_db_resolve_intents(
        db: *mut antfly_db,
        txn_id: *const [u8; 16],
        status: u8,
        commit_version: u64,
    ) -> antfly_error_code;
    pub fn antfly_db_get_transaction_status(
        db: *mut antfly_db,
        txn_id: *const [u8; 16],
        out_status: *mut u8,
    ) -> antfly_error_code;
    pub fn antfly_db_get_commit_version(
        db: *mut antfly_db,
        txn_id: *const [u8; 16],
        out_commit_version: *mut u64,
    ) -> antfly_error_code;
    pub fn antfly_db_get_timestamp(
        db: *mut antfly_db,
        key: antfly_slice,
        out_timestamp: *mut u64,
    ) -> antfly_error_code;
    pub fn antfly_db_lookup_json(
        db: *mut antfly_db,
        key: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_get_raw(
        db: *mut antfly_db,
        key: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_get_schema_json(
        db: *mut antfly_db,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_set_schema_json(
        db: *mut antfly_db,
        schema_json: antfly_slice,
    ) -> antfly_error_code;
    pub fn antfly_db_run_until_idle(db: *mut antfly_db) -> antfly_error_code;
    pub fn antfly_db_run_until_idle_json(
        db: *mut antfly_db,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_pending_work_stats_json(
        db: *mut antfly_db,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_replay_generated_enrichments_json(
        db: *mut antfly_db,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_list_indexes_json(
        db: *mut antfly_db,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_render_resolver_key_json(
        db: *mut antfly_db,
        resolver_name: antfly_slice,
        mention_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_memory_json(
        db: *mut antfly_db,
        space: antfly_slice,
        request_json: antfly_slice,
        out_json: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_resolve_query_json(
        db: *mut antfly_db,
        resolver_name: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_merge_resolver_keys_json(
        db: *mut antfly_db,
        resolver_name: antfly_slice,
        merge_json: antfly_slice,
    ) -> antfly_error_code;
    pub fn antfly_db_unmerge_resolver_key_json(
        db: *mut antfly_db,
        resolver_name: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_suppress_resolver_keys_json(
        db: *mut antfly_db,
        resolver_name: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_unsuppress_resolver_key_json(
        db: *mut antfly_db,
        resolver_name: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_resolver_reviews_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_propose_curation_json(
        db: *mut antfly_db,
        entity_table: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_list_curation_proposals_json(
        db: *mut antfly_db,
        entity_table: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_get_curation_proposal_json(
        db: *mut antfly_db,
        entity_table: antfly_slice,
        proposal_id: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_decide_curation_proposal_json(
        db: *mut antfly_db,
        entity_table: antfly_slice,
        proposal_id: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_curate_entity_json(
        db: *mut antfly_db,
        entity_table: antfly_slice,
        entity_key: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_entity_merge_json(
        db: *mut antfly_db,
        entity_table: antfly_slice,
        entity_key: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_entity_unmerge_json(
        db: *mut antfly_db,
        entity_table: antfly_slice,
        entity_key: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_entity_suppress_json(
        db: *mut antfly_db,
        entity_table: antfly_slice,
        entity_key: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_entity_unsuppress_json(
        db: *mut antfly_db,
        entity_table: antfly_slice,
        entity_key: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_entity_redirects_json(
        db: *mut antfly_db,
        entity_table: antfly_slice,
        entity_key: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_resolver_curation_json(
        db: *mut antfly_db,
        resolver_name: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_list_resolver_identities_json(
        db: *mut antfly_db,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_drop_resolver_identity(
        db: *mut antfly_db,
        name: antfly_slice,
        out_deleted: *mut bool,
    ) -> antfly_error_code;
    pub fn antfly_db_set_resolver_namespace_json(
        db: *mut antfly_db,
        resolver_name: antfly_slice,
        request_json: antfly_slice,
    ) -> antfly_error_code;
    pub fn antfly_db_add_index_json(
        db: *mut antfly_db,
        config_json: antfly_slice,
    ) -> antfly_error_code;
    pub fn antfly_db_delete_index(
        db: *mut antfly_db,
        name: antfly_slice,
        out_deleted: *mut bool,
    ) -> antfly_error_code;
    pub fn antfly_db_cancel_replacement(
        db: *mut antfly_db,
        name: antfly_slice,
        out_deleted: *mut bool,
    ) -> antfly_error_code;
    pub fn antfly_db_list_enrichments_json(
        db: *mut antfly_db,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_add_enrichment_json(
        db: *mut antfly_db,
        config_json: antfly_slice,
    ) -> antfly_error_code;
    pub fn antfly_db_delete_enrichment(
        db: *mut antfly_db,
        kind: antfly_slice,
        name: antfly_slice,
        out_deleted: *mut bool,
    ) -> antfly_error_code;
    pub fn antfly_db_scan_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_scan_hashes(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out_result: *mut antfly_scan_hash_result,
    ) -> antfly_error_code;
    pub fn antfly_db_stats_json(db: *mut antfly_db, out: *mut antfly_buffer) -> antfly_error_code;
    pub fn antfly_db_search_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_open_table(
        db: *mut antfly_db,
        name: antfly_slice,
        out: *mut *mut antfly_db,
    ) -> antfly_error_code;
    pub fn antfly_db_create_table_json(
        db: *mut antfly_db,
        name: antfly_slice,
        schema: antfly_slice,
    ) -> antfly_error_code;
    pub fn antfly_db_drop_table(db: *mut antfly_db, name: antfly_slice) -> antfly_error_code;
    pub fn antfly_db_list_tables_json(
        db: *mut antfly_db,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_sql_describe_json(
        db: *mut antfly_db,
        request: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_sql_session_open(db: *mut antfly_db, out: *mut u64) -> antfly_error_code;
    pub fn antfly_db_sql_session_close(db: *mut antfly_db, id: u64) -> antfly_error_code;
    pub fn antfly_db_sql_open_cursor_json(
        db: *mut antfly_db,
        request: antfly_slice,
        id: *mut u64,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_sql_fetch_cursor_json(
        db: *mut antfly_db,
        id: u64,
        rows: u32,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_sql_close_cursor(db: *mut antfly_db, id: u64) -> antfly_error_code;
    pub fn antfly_db_sql_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_graph_catalog_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_cypher_json(
        db: *mut antfly_db,
        graph_name: antfly_slice,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_graph_write_status_json(
        db: *mut antfly_db,
        transaction_id: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_search_dense(
        db: *mut antfly_db,
        index_name: antfly_slice,
        vector_ptr: *const f32,
        vector_len: usize,
        k: u32,
        limit: u32,
        offset: u32,
        out_result: *mut antfly_packed_dense_search_result,
    ) -> antfly_error_code;
    pub fn antfly_db_search_dense_profile(
        db: *mut antfly_db,
        index_name: antfly_slice,
        vector_ptr: *const f32,
        vector_len: usize,
        k: u32,
        limit: u32,
        offset: u32,
        out_profile: *mut antfly_dense_search_profile,
    ) -> antfly_error_code;
    pub fn antfly_db_search_dense_wire(
        db: *mut antfly_db,
        request_buf: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_search_dense_wire_profile(
        db: *mut antfly_db,
        request_buf: antfly_slice,
        out: *mut antfly_buffer,
        out_profile: *mut antfly_dense_wire_search_profile,
    ) -> antfly_error_code;
    pub fn antfly_db_search_text_match(
        db: *mut antfly_db,
        index_name: antfly_slice,
        field: antfly_slice,
        text: antfly_slice,
        limit: u32,
        offset: u32,
        out_result: *mut antfly_dense_search_result,
    ) -> antfly_error_code;
    pub fn antfly_db_search_text_match_wire(
        db: *mut antfly_db,
        request_buf: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_search_text_term_wire(
        db: *mut antfly_db,
        request_buf: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_search_text_match_phrase_wire(
        db: *mut antfly_db,
        request_buf: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_search_hits_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out_result: *mut antfly_dense_search_result,
    ) -> antfly_error_code;
    pub fn antfly_db_aggregate_hits_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_lookup_artifact_json(
        db: *mut antfly_db,
        artifact_id_b64: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_decode_artifact_id_json(
        artifact_id_b64: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_extract_enrichments_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_compute_enrichments_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;

    pub fn antfly_db_get_edges_json(
        db: *mut antfly_db,
        index_name: antfly_slice,
        key: antfly_slice,
        edge_type: antfly_slice,
        direction: u8,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_traverse_edges_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_execute_graph_queries_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_get_neighbors_json(
        db: *mut antfly_db,
        index_name: antfly_slice,
        key: antfly_slice,
        edge_type: antfly_slice,
        direction: u8,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_find_shortest_path_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_find_k_shortest_paths_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_db_match_pattern_json(
        db: *mut antfly_db,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;

    // -- Embedded inference without a database --------------------------

    pub fn antfly_inference_options_size() -> u32;
    pub fn antfly_inference_options_init(
        options: *mut antfly_inference_options,
    ) -> antfly_error_code;
    /// `options` may be NULL for defaults.
    pub fn antfly_inference_open(
        options: *const antfly_inference_options,
        out_inference: *mut *mut antfly_inference,
    ) -> antfly_error_code;
    pub fn antfly_inference_close(inference: *mut antfly_inference);

    pub fn antfly_inference_embed_json(
        inference: *mut antfly_inference,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_inference_rerank_json(
        inference: *mut antfly_inference,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_inference_chunk_json(
        inference: *mut antfly_inference,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_inference_generate_json(
        inference: *mut antfly_inference,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    /// Streams a generate request (the same body as
    /// `antfly_inference_generate_json`; `"stream"` is set for the caller).
    /// `on_chunk` is called on the calling thread for each chunk as the
    /// model produces tokens. Returns `ANTFLY_OK` once generation finishes,
    /// or `ANTFLY_CANCELLED` when `on_chunk` returned `false`. A request
    /// rejected before generation starts (such as a missing model) fails
    /// like `antfly_inference_generate_json`, with the JSON error in `out`;
    /// a failure mid-stream returns `ANTFLY_INTERNAL` with
    /// `{"error": "STREAM_FAILED", ...}`.
    pub fn antfly_inference_generate_stream_json(
        inference: *mut antfly_inference,
        request_json: antfly_slice,
        on_chunk: antfly_inference_stream_fn,
        chunk_context: *mut c_void,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    /// Up to 128 non-streaming generate requests in one call; per-item
    /// failures are reported in the response.
    pub fn antfly_inference_generate_batch_json(
        inference: *mut antfly_inference,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_inference_rewrite_json(
        inference: *mut antfly_inference,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    /// Model-independent typed decisions, matching `POST /ai/v1/decide`.
    pub fn antfly_inference_decide_json(
        inference: *mut antfly_inference,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_inference_extract_json(
        inference: *mut antfly_inference,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    pub fn antfly_inference_read_json(
        inference: *mut antfly_inference,
        request_json: antfly_slice,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
    /// The installed models, as returned by `GET /ai/v1/models`.
    pub fn antfly_inference_list_models_json(
        inference: *mut antfly_inference,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;

    /// Downloads a model from the Hugging Face Hub into the handle's models
    /// directory, like `antfly inference pull`. `progress` (may be NULL) is
    /// called on the calling thread as files download. The call cannot be
    /// cancelled, and `antfly_inference_close` waits for it.
    pub fn antfly_inference_pull_json(
        inference: *mut antfly_inference,
        request_json: antfly_slice,
        progress: antfly_inference_pull_progress_fn,
        progress_context: *mut c_void,
        out: *mut antfly_buffer,
    ) -> antfly_error_code;
}

pub const ANTFLY_REPLACEMENT_FAILED: antfly_error_code = 11;
pub const ANTFLY_REPLACEMENT_PENDING: antfly_error_code = 12;
pub const ANTFLY_REPLACEMENT_CONFIGURATION_MISMATCH: antfly_error_code = 13;