@antfly/embedded 0.0.0 → 0.3.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +452 -4
- package/dist/chunk-ELM44XQ4.js +168 -0
- package/dist/database-BY3WSLgt.d.cts +558 -0
- package/dist/database-BY3WSLgt.d.ts +558 -0
- package/dist/index.cjs +2302 -0
- package/dist/index.d.cts +322 -0
- package/dist/index.d.ts +322 -0
- package/dist/index.js +2057 -0
- package/dist/kysely.cjs +346 -0
- package/dist/kysely.d.cts +28 -0
- package/dist/kysely.d.ts +28 -0
- package/dist/kysely.js +169 -0
- package/package.json +81 -10
package/dist/index.js
ADDED
|
@@ -0,0 +1,2057 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Connection,
|
|
3
|
+
SqlError,
|
|
4
|
+
__filename
|
|
5
|
+
} from "./chunk-ELM44XQ4.js";
|
|
6
|
+
|
|
7
|
+
// src/abi.ts
|
|
8
|
+
import koffi2 from "koffi";
|
|
9
|
+
|
|
10
|
+
// src/native.ts
|
|
11
|
+
import koffi from "koffi";
|
|
12
|
+
|
|
13
|
+
// src/discovery.ts
|
|
14
|
+
import { existsSync as nodeExistsSync } from "fs";
|
|
15
|
+
import { createRequire } from "module";
|
|
16
|
+
import { dirname, join } from "path";
|
|
17
|
+
import { fileURLToPath } from "url";
|
|
18
|
+
var LibraryNotFoundError = class extends Error {
|
|
19
|
+
constructor(message) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = "LibraryNotFoundError";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var UnsupportedPlatformError = class extends Error {
|
|
25
|
+
constructor(platform) {
|
|
26
|
+
super(`@antfly/embedded does not support platform ${platform}`);
|
|
27
|
+
this.name = "UnsupportedPlatformError";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
function platformLibraryFileName(platform) {
|
|
31
|
+
switch (platform) {
|
|
32
|
+
case "darwin":
|
|
33
|
+
return "libantfly.dylib";
|
|
34
|
+
case "linux":
|
|
35
|
+
return "libantfly.so";
|
|
36
|
+
case "win32":
|
|
37
|
+
return "antfly.dll";
|
|
38
|
+
default:
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function embeddedPlatformPackageName(platform, arch) {
|
|
43
|
+
if (platform === "darwin" && arch === "arm64") {
|
|
44
|
+
return "@antfly/embedded-darwin-arm64";
|
|
45
|
+
}
|
|
46
|
+
if (platform === "linux" && (arch === "arm64" || arch === "x64")) {
|
|
47
|
+
return `@antfly/embedded-linux-${arch}`;
|
|
48
|
+
}
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
function moduleFilename() {
|
|
52
|
+
return typeof __filename === "string" ? __filename : fileURLToPath(import.meta.url);
|
|
53
|
+
}
|
|
54
|
+
function defaultStartDir() {
|
|
55
|
+
return dirname(moduleFilename());
|
|
56
|
+
}
|
|
57
|
+
function findUp(startDir, relative, existsSync) {
|
|
58
|
+
let dir = startDir;
|
|
59
|
+
for (let i = 0; i < 16; i++) {
|
|
60
|
+
const candidate = join(dir, relative);
|
|
61
|
+
if (existsSync(candidate)) {
|
|
62
|
+
return candidate;
|
|
63
|
+
}
|
|
64
|
+
if (existsSync(join(dir, ".git"))) {
|
|
65
|
+
return void 0;
|
|
66
|
+
}
|
|
67
|
+
const parent = dirname(dir);
|
|
68
|
+
if (parent === dir) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
dir = parent;
|
|
72
|
+
}
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
function resolveLibrary(options = {}) {
|
|
76
|
+
const platform = options.platform ?? process.platform;
|
|
77
|
+
const arch = options.arch ?? process.arch;
|
|
78
|
+
const env = options.env ?? process.env;
|
|
79
|
+
const existsSync = options.existsSync ?? nodeExistsSync;
|
|
80
|
+
const fileName = platformLibraryFileName(platform);
|
|
81
|
+
if (!fileName) {
|
|
82
|
+
throw new UnsupportedPlatformError(platform);
|
|
83
|
+
}
|
|
84
|
+
const explicitLibrary = env.ANTFLY_LIBRARY;
|
|
85
|
+
if (explicitLibrary) {
|
|
86
|
+
if (!existsSync(explicitLibrary)) {
|
|
87
|
+
throw new LibraryNotFoundError(`ANTFLY_LIBRARY=${explicitLibrary} does not exist`);
|
|
88
|
+
}
|
|
89
|
+
return { path: explicitLibrary, source: "ANTFLY_LIBRARY" };
|
|
90
|
+
}
|
|
91
|
+
const libDir = env.ANTFLY_LIB_DIR;
|
|
92
|
+
if (libDir) {
|
|
93
|
+
const candidate = join(libDir, fileName);
|
|
94
|
+
if (!existsSync(candidate)) {
|
|
95
|
+
throw new LibraryNotFoundError(`ANTFLY_LIB_DIR=${libDir} does not contain ${fileName}`);
|
|
96
|
+
}
|
|
97
|
+
return { path: candidate, source: "ANTFLY_LIB_DIR" };
|
|
98
|
+
}
|
|
99
|
+
const packageName = embeddedPlatformPackageName(platform, arch);
|
|
100
|
+
if (packageName) {
|
|
101
|
+
try {
|
|
102
|
+
const resolve = options.resolve ?? createRequire(moduleFilename()).resolve;
|
|
103
|
+
const packageJsonPath = resolve(`${packageName}/package.json`);
|
|
104
|
+
const candidate = join(dirname(packageJsonPath), "lib", fileName);
|
|
105
|
+
if (existsSync(candidate)) {
|
|
106
|
+
return { path: candidate, source: "embedded-package" };
|
|
107
|
+
}
|
|
108
|
+
} catch {
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const startDir = options.startDir ?? defaultStartDir();
|
|
112
|
+
const sourceTreeLibrary = findUp(startDir, join("zig", "zig-out", "lib", fileName), existsSync);
|
|
113
|
+
if (sourceTreeLibrary) {
|
|
114
|
+
return { path: sourceTreeLibrary, source: "source-tree" };
|
|
115
|
+
}
|
|
116
|
+
return { path: fileName, source: "system" };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/errors.ts
|
|
120
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
121
|
+
ErrorCode2[ErrorCode2["OK"] = 0] = "OK";
|
|
122
|
+
ErrorCode2[ErrorCode2["InvalidArgument"] = 1] = "InvalidArgument";
|
|
123
|
+
ErrorCode2[ErrorCode2["NotFound"] = 2] = "NotFound";
|
|
124
|
+
ErrorCode2[ErrorCode2["VersionConflict"] = 3] = "VersionConflict";
|
|
125
|
+
ErrorCode2[ErrorCode2["IntentConflict"] = 4] = "IntentConflict";
|
|
126
|
+
ErrorCode2[ErrorCode2["TxnNotFound"] = 5] = "TxnNotFound";
|
|
127
|
+
ErrorCode2[ErrorCode2["Busy"] = 6] = "Busy";
|
|
128
|
+
ErrorCode2[ErrorCode2["OutcomeUnknown"] = 7] = "OutcomeUnknown";
|
|
129
|
+
ErrorCode2[ErrorCode2["Unsupported"] = 8] = "Unsupported";
|
|
130
|
+
ErrorCode2[ErrorCode2["Stalled"] = 9] = "Stalled";
|
|
131
|
+
ErrorCode2[ErrorCode2["Cancelled"] = 10] = "Cancelled";
|
|
132
|
+
ErrorCode2[ErrorCode2["Internal"] = 255] = "Internal";
|
|
133
|
+
return ErrorCode2;
|
|
134
|
+
})(ErrorCode || {});
|
|
135
|
+
var ERROR_CODE_NAMES = {
|
|
136
|
+
[0 /* OK */]: "ANTFLY_OK",
|
|
137
|
+
[1 /* InvalidArgument */]: "ANTFLY_INVALID_ARGUMENT",
|
|
138
|
+
[2 /* NotFound */]: "ANTFLY_NOT_FOUND",
|
|
139
|
+
[3 /* VersionConflict */]: "ANTFLY_VERSION_CONFLICT",
|
|
140
|
+
[4 /* IntentConflict */]: "ANTFLY_INTENT_CONFLICT",
|
|
141
|
+
[5 /* TxnNotFound */]: "ANTFLY_TXN_NOT_FOUND",
|
|
142
|
+
[6 /* Busy */]: "ANTFLY_BUSY",
|
|
143
|
+
[7 /* OutcomeUnknown */]: "ANTFLY_OUTCOME_UNKNOWN",
|
|
144
|
+
[8 /* Unsupported */]: "ANTFLY_UNSUPPORTED",
|
|
145
|
+
[9 /* Stalled */]: "ANTFLY_STALLED",
|
|
146
|
+
[10 /* Cancelled */]: "ANTFLY_CANCELLED",
|
|
147
|
+
[255 /* Internal */]: "ANTFLY_INTERNAL"
|
|
148
|
+
};
|
|
149
|
+
var ERROR_CODE_DESCRIPTIONS = {
|
|
150
|
+
[0 /* OK */]: "operation completed successfully",
|
|
151
|
+
[1 /* InvalidArgument */]: "an argument, request, path, or open mode is invalid",
|
|
152
|
+
[2 /* NotFound */]: "the requested database object was not found",
|
|
153
|
+
[3 /* VersionConflict */]: "a version predicate did not match the current document version",
|
|
154
|
+
[4 /* IntentConflict */]: "a transaction intent conflicts with the requested operation",
|
|
155
|
+
[5 /* TxnNotFound */]: "the requested transaction was not found",
|
|
156
|
+
[6 /* Busy */]: "the requested resource is temporarily busy or changed during streaming; stabilize it and retry",
|
|
157
|
+
[7 /* OutcomeUnknown */]: "the operation was published, but crash durability could not be confirmed; inspect the destination and do not retry automatically",
|
|
158
|
+
[8 /* Unsupported */]: "the operation requires a capability that is not supported by this platform or filesystem",
|
|
159
|
+
[9 /* Stalled */]: "derived work stalled or failed; inspect pending-work diagnostics and repair or reopen the database",
|
|
160
|
+
[10 /* Cancelled */]: "the caller cancelled the operation",
|
|
161
|
+
[255 /* Internal */]: "an internal error occurred"
|
|
162
|
+
};
|
|
163
|
+
function errorCodeName(code) {
|
|
164
|
+
return ERROR_CODE_NAMES[code] ?? "ANTFLY_UNKNOWN_ERROR";
|
|
165
|
+
}
|
|
166
|
+
function errorCodeDescription(code) {
|
|
167
|
+
return ERROR_CODE_DESCRIPTIONS[code] ?? "unknown Antfly error code";
|
|
168
|
+
}
|
|
169
|
+
var AntflyError = class extends Error {
|
|
170
|
+
code;
|
|
171
|
+
codeName;
|
|
172
|
+
/**
|
|
173
|
+
* Parsed JSON error body, when the failing call returned one. Currently
|
|
174
|
+
* only Inference calls populate this (embed/rerank/.../pull): libantfly
|
|
175
|
+
* always fills their antfly_buffer output with {"error": ..., "message":
|
|
176
|
+
* ...} on failure, even though the call also returns a non-OK error code.
|
|
177
|
+
*/
|
|
178
|
+
body;
|
|
179
|
+
constructor(code, message) {
|
|
180
|
+
const codeName = errorCodeName(code);
|
|
181
|
+
super(message ?? `${codeName}: ${errorCodeDescription(code)}`);
|
|
182
|
+
this.name = "AntflyError";
|
|
183
|
+
this.code = code;
|
|
184
|
+
this.codeName = codeName;
|
|
185
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
var InvalidArgumentError = class extends AntflyError {
|
|
189
|
+
constructor(message) {
|
|
190
|
+
super(1 /* InvalidArgument */, message);
|
|
191
|
+
this.name = "InvalidArgumentError";
|
|
192
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var NotFoundError = class extends AntflyError {
|
|
196
|
+
constructor(message) {
|
|
197
|
+
super(2 /* NotFound */, message);
|
|
198
|
+
this.name = "NotFoundError";
|
|
199
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
var VersionConflictError = class extends AntflyError {
|
|
203
|
+
constructor(message) {
|
|
204
|
+
super(3 /* VersionConflict */, message);
|
|
205
|
+
this.name = "VersionConflictError";
|
|
206
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
var IntentConflictError = class extends AntflyError {
|
|
210
|
+
constructor(message) {
|
|
211
|
+
super(4 /* IntentConflict */, message);
|
|
212
|
+
this.name = "IntentConflictError";
|
|
213
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var TxnNotFoundError = class extends AntflyError {
|
|
217
|
+
constructor(message) {
|
|
218
|
+
super(5 /* TxnNotFound */, message);
|
|
219
|
+
this.name = "TxnNotFoundError";
|
|
220
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
var BusyError = class extends AntflyError {
|
|
224
|
+
constructor(message) {
|
|
225
|
+
super(6 /* Busy */, message);
|
|
226
|
+
this.name = "BusyError";
|
|
227
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var OutcomeUnknownError = class extends AntflyError {
|
|
231
|
+
constructor(message) {
|
|
232
|
+
super(7 /* OutcomeUnknown */, message);
|
|
233
|
+
this.name = "OutcomeUnknownError";
|
|
234
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var UnsupportedError = class extends AntflyError {
|
|
238
|
+
constructor(message) {
|
|
239
|
+
super(8 /* Unsupported */, message);
|
|
240
|
+
this.name = "UnsupportedError";
|
|
241
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
var StalledError = class extends AntflyError {
|
|
245
|
+
constructor(message) {
|
|
246
|
+
super(9 /* Stalled */, message);
|
|
247
|
+
this.name = "StalledError";
|
|
248
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
var CancelledError = class extends AntflyError {
|
|
252
|
+
constructor(message) {
|
|
253
|
+
super(10 /* Cancelled */, message);
|
|
254
|
+
this.name = "CancelledError";
|
|
255
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
var InternalError = class extends AntflyError {
|
|
259
|
+
constructor(message) {
|
|
260
|
+
super(255 /* Internal */, message);
|
|
261
|
+
this.name = "InternalError";
|
|
262
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
var ERROR_CLASSES = {
|
|
266
|
+
[1 /* InvalidArgument */]: InvalidArgumentError,
|
|
267
|
+
[2 /* NotFound */]: NotFoundError,
|
|
268
|
+
[3 /* VersionConflict */]: VersionConflictError,
|
|
269
|
+
[4 /* IntentConflict */]: IntentConflictError,
|
|
270
|
+
[5 /* TxnNotFound */]: TxnNotFoundError,
|
|
271
|
+
[6 /* Busy */]: BusyError,
|
|
272
|
+
[7 /* OutcomeUnknown */]: OutcomeUnknownError,
|
|
273
|
+
[8 /* Unsupported */]: UnsupportedError,
|
|
274
|
+
[9 /* Stalled */]: StalledError,
|
|
275
|
+
[10 /* Cancelled */]: CancelledError,
|
|
276
|
+
[255 /* Internal */]: InternalError
|
|
277
|
+
};
|
|
278
|
+
function errorFromCode(code, message) {
|
|
279
|
+
const Ctor = ERROR_CLASSES[code];
|
|
280
|
+
if (Ctor) {
|
|
281
|
+
return new Ctor(message);
|
|
282
|
+
}
|
|
283
|
+
return new AntflyError(code, message);
|
|
284
|
+
}
|
|
285
|
+
function checkCode(code) {
|
|
286
|
+
if (code !== 0 /* OK */) {
|
|
287
|
+
throw errorFromCode(code);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// src/types.ts
|
|
292
|
+
var OpenMode = /* @__PURE__ */ ((OpenMode2) => {
|
|
293
|
+
OpenMode2[OpenMode2["Writer"] = 0] = "Writer";
|
|
294
|
+
OpenMode2[OpenMode2["Readonly"] = 1] = "Readonly";
|
|
295
|
+
OpenMode2[OpenMode2["StatusOnly"] = 2] = "StatusOnly";
|
|
296
|
+
return OpenMode2;
|
|
297
|
+
})(OpenMode || {});
|
|
298
|
+
var Storage = /* @__PURE__ */ ((Storage2) => {
|
|
299
|
+
Storage2[Storage2["Lite"] = 0] = "Lite";
|
|
300
|
+
Storage2[Storage2["Directory"] = 1] = "Directory";
|
|
301
|
+
return Storage2;
|
|
302
|
+
})(Storage || {});
|
|
303
|
+
var Profile = /* @__PURE__ */ ((Profile2) => {
|
|
304
|
+
Profile2[Profile2["Native"] = 0] = "Native";
|
|
305
|
+
Profile2[Profile2["Hosted"] = 1] = "Hosted";
|
|
306
|
+
return Profile2;
|
|
307
|
+
})(Profile || {});
|
|
308
|
+
var GraphDirection = /* @__PURE__ */ ((GraphDirection2) => {
|
|
309
|
+
GraphDirection2[GraphDirection2["Out"] = 0] = "Out";
|
|
310
|
+
GraphDirection2[GraphDirection2["In"] = 1] = "In";
|
|
311
|
+
GraphDirection2[GraphDirection2["Both"] = 2] = "Both";
|
|
312
|
+
return GraphDirection2;
|
|
313
|
+
})(GraphDirection || {});
|
|
314
|
+
var TxnStatus = /* @__PURE__ */ ((TxnStatus2) => {
|
|
315
|
+
TxnStatus2[TxnStatus2["Pending"] = 0] = "Pending";
|
|
316
|
+
TxnStatus2[TxnStatus2["Committed"] = 1] = "Committed";
|
|
317
|
+
TxnStatus2[TxnStatus2["Aborted"] = 2] = "Aborted";
|
|
318
|
+
return TxnStatus2;
|
|
319
|
+
})(TxnStatus || {});
|
|
320
|
+
var InferenceMode = {
|
|
321
|
+
CallerSuppliedOrDisabled: "caller_supplied_or_disabled",
|
|
322
|
+
CallerSuppliedArtifacts: "caller_supplied_artifacts",
|
|
323
|
+
RemoteProvider: "remote_provider",
|
|
324
|
+
LocalEmbedded: "local_embedded",
|
|
325
|
+
ManualMaintenance: "manual_maintenance",
|
|
326
|
+
DisabledDeferred: "disabled_deferred"
|
|
327
|
+
};
|
|
328
|
+
var THREADING_SERIALIZED = 1;
|
|
329
|
+
var SUPPORTED_ABI_VERSION = 3;
|
|
330
|
+
|
|
331
|
+
// src/native.ts
|
|
332
|
+
var ANTFLY_STORAGE_KIND_DIRECTORY = 0;
|
|
333
|
+
var ANTFLY_STORAGE_KIND_LITE = 1;
|
|
334
|
+
function storageKind(storage) {
|
|
335
|
+
switch (storage ?? 0 /* Lite */) {
|
|
336
|
+
case 0 /* Lite */:
|
|
337
|
+
return ANTFLY_STORAGE_KIND_LITE;
|
|
338
|
+
case 1 /* Directory */:
|
|
339
|
+
return ANTFLY_STORAGE_KIND_DIRECTORY;
|
|
340
|
+
default:
|
|
341
|
+
throw new InvalidArgumentError(`invalid Storage value: ${storage}`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
var AntflySlice = koffi.struct("antfly_slice", {
|
|
345
|
+
ptr: "const uint8_t *",
|
|
346
|
+
len: "size_t"
|
|
347
|
+
});
|
|
348
|
+
var AntflyBuffer = koffi.struct("antfly_buffer", {
|
|
349
|
+
ptr: "uint8_t *",
|
|
350
|
+
len: "size_t"
|
|
351
|
+
});
|
|
352
|
+
var AntflyWriteIntent = koffi.struct("antfly_write_intent", {
|
|
353
|
+
key: AntflySlice,
|
|
354
|
+
value: AntflySlice,
|
|
355
|
+
is_delete: "bool"
|
|
356
|
+
});
|
|
357
|
+
var AntflyVersionPredicate = koffi.struct("antfly_version_predicate", {
|
|
358
|
+
key: AntflySlice,
|
|
359
|
+
expected_version: "uint64_t"
|
|
360
|
+
});
|
|
361
|
+
var AntflyDbOpaque = koffi.opaque("antfly_db");
|
|
362
|
+
var PAntflyDb = koffi.pointer(AntflyDbOpaque);
|
|
363
|
+
var PAntflyDbOut = koffi.out(koffi.pointer(AntflyDbOpaque, 2));
|
|
364
|
+
var AntflyOpenOptions = koffi.struct("antfly_open_options", {
|
|
365
|
+
abi_size: "uint32_t",
|
|
366
|
+
storage_kind: "uint32_t",
|
|
367
|
+
open_mode: "uint32_t",
|
|
368
|
+
profile: "uint32_t",
|
|
369
|
+
flags: "uint32_t",
|
|
370
|
+
reserved0: "uint32_t",
|
|
371
|
+
map_size: "uint64_t",
|
|
372
|
+
ttl_cleanup_enabled: "bool",
|
|
373
|
+
ttl_cleanup_lease_owned: "bool",
|
|
374
|
+
ttl_cleanup_batch_size: "uint32_t",
|
|
375
|
+
ttl_cleanup_owner_id: AntflySlice,
|
|
376
|
+
ttl_cleanup_lease_ttl_ms: "uint64_t",
|
|
377
|
+
ttl_cleanup_interval_ms: "uint64_t",
|
|
378
|
+
ttl_cleanup_grace_period_ns: "uint64_t",
|
|
379
|
+
inference_host_budget_mb: "uint32_t",
|
|
380
|
+
inference_backend_budget_mb: "uint32_t",
|
|
381
|
+
inference_process_memory_budget_mb: "uint32_t",
|
|
382
|
+
inference_combined_budget_mb: "uint32_t",
|
|
383
|
+
inference_kv_budget_mb: "uint32_t",
|
|
384
|
+
inference_scratch_budget_mb: "uint32_t",
|
|
385
|
+
busy_timeout_ms: "uint64_t",
|
|
386
|
+
reserved: koffi.array("uint64_t", 8)
|
|
387
|
+
});
|
|
388
|
+
var PAntflyOpenOptions = koffi.pointer(AntflyOpenOptions);
|
|
389
|
+
var PAntflyOpenOptionsOut = koffi.out(PAntflyOpenOptions);
|
|
390
|
+
var PAntflyBufferOut = koffi.out(koffi.pointer(AntflyBuffer));
|
|
391
|
+
var PAntflyWriteIntentArray = koffi.pointer(AntflyWriteIntent);
|
|
392
|
+
var PAntflyVersionPredicateArray = koffi.pointer(AntflyVersionPredicate);
|
|
393
|
+
var PAntflySliceArray = koffi.pointer(AntflySlice);
|
|
394
|
+
var PUint8Out = koffi.out(koffi.pointer("uint8_t"));
|
|
395
|
+
var PUint64Out = koffi.out(koffi.pointer("uint64_t"));
|
|
396
|
+
var PBoolOut = koffi.out(koffi.pointer("bool"));
|
|
397
|
+
var AntflyInferenceOpaque = koffi.opaque("antfly_inference");
|
|
398
|
+
var PAntflyInference = koffi.pointer(AntflyInferenceOpaque);
|
|
399
|
+
var PAntflyInferenceOut = koffi.out(koffi.pointer(AntflyInferenceOpaque, 2));
|
|
400
|
+
var AntflyInferenceOptions = koffi.struct("antfly_inference_options", {
|
|
401
|
+
abi_size: "uint32_t",
|
|
402
|
+
flags: "uint32_t",
|
|
403
|
+
models_dir: AntflySlice,
|
|
404
|
+
host_budget_mb: "uint32_t",
|
|
405
|
+
backend_budget_mb: "uint32_t",
|
|
406
|
+
process_memory_budget_mb: "uint32_t",
|
|
407
|
+
combined_budget_mb: "uint32_t",
|
|
408
|
+
kv_budget_mb: "uint32_t",
|
|
409
|
+
scratch_budget_mb: "uint32_t",
|
|
410
|
+
call_timeout_ms: "uint64_t",
|
|
411
|
+
reserved: koffi.array("uint64_t", 8)
|
|
412
|
+
});
|
|
413
|
+
var PAntflyInferenceOptions = koffi.pointer(AntflyInferenceOptions);
|
|
414
|
+
var PAntflyInferenceOptionsOut = koffi.out(PAntflyInferenceOptions);
|
|
415
|
+
var AntflyInferencePullProgress = koffi.struct("antfly_inference_pull_progress", {
|
|
416
|
+
abi_size: "uint32_t",
|
|
417
|
+
reserved0: "uint32_t",
|
|
418
|
+
model: AntflySlice,
|
|
419
|
+
file: AntflySlice,
|
|
420
|
+
bytes_downloaded: "uint64_t",
|
|
421
|
+
total_bytes: "uint64_t",
|
|
422
|
+
files_done: "uint64_t",
|
|
423
|
+
files_total: "uint64_t",
|
|
424
|
+
cached: "bool"
|
|
425
|
+
});
|
|
426
|
+
var AntflyInferencePullProgressFnProto = koffi.proto(
|
|
427
|
+
"antfly_inference_pull_progress_fn",
|
|
428
|
+
"bool",
|
|
429
|
+
["void *", koffi.pointer(AntflyInferencePullProgress)]
|
|
430
|
+
);
|
|
431
|
+
var PAntflyInferencePullProgressFn = koffi.pointer(AntflyInferencePullProgressFnProto);
|
|
432
|
+
var AntflyInferenceStreamFnProto = koffi.proto("antfly_inference_stream_fn", "bool", [
|
|
433
|
+
"void *",
|
|
434
|
+
AntflySlice
|
|
435
|
+
]);
|
|
436
|
+
var PAntflyInferenceStreamFn = koffi.pointer(AntflyInferenceStreamFnProto);
|
|
437
|
+
var cached;
|
|
438
|
+
var cachedError;
|
|
439
|
+
function loadNative() {
|
|
440
|
+
if (cached) {
|
|
441
|
+
return cached;
|
|
442
|
+
}
|
|
443
|
+
if (cachedError) {
|
|
444
|
+
throw cachedError;
|
|
445
|
+
}
|
|
446
|
+
try {
|
|
447
|
+
cached = buildNative();
|
|
448
|
+
return cached;
|
|
449
|
+
} catch (err) {
|
|
450
|
+
cachedError = err;
|
|
451
|
+
throw err;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
var NATIVE_STACK_SIZE = 8 * 1024 * 1024;
|
|
455
|
+
function configureKoffiStacks() {
|
|
456
|
+
const current = koffi.config();
|
|
457
|
+
if ((current.sync_stack_size ?? 0) >= NATIVE_STACK_SIZE && (current.async_stack_size ?? 0) >= NATIVE_STACK_SIZE) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
koffi.config({
|
|
461
|
+
...current,
|
|
462
|
+
sync_stack_size: Math.max(current.sync_stack_size ?? 0, NATIVE_STACK_SIZE),
|
|
463
|
+
async_stack_size: Math.max(current.async_stack_size ?? 0, NATIVE_STACK_SIZE)
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
function buildNative() {
|
|
467
|
+
const resolved = resolveLibrary();
|
|
468
|
+
configureKoffiStacks();
|
|
469
|
+
const handle = koffi.load(resolved.path);
|
|
470
|
+
const f = handle.func.bind(handle);
|
|
471
|
+
return {
|
|
472
|
+
handle,
|
|
473
|
+
resolved,
|
|
474
|
+
abiVersion: f("antfly_abi_version", "uint32_t", []),
|
|
475
|
+
threadingMode: f("antfly_threading_mode", "uint32_t", []),
|
|
476
|
+
openOptionsSize: f("antfly_open_options_size", "uint32_t", []),
|
|
477
|
+
errorCodeName: f("antfly_error_code_name", "str", ["uint32_t"]),
|
|
478
|
+
errorCodeDescription: f("antfly_error_code_description", "str", ["uint32_t"]),
|
|
479
|
+
openOptionsInit: f("antfly_open_options_init", "uint32_t", [PAntflyOpenOptionsOut]),
|
|
480
|
+
dbOpenWithOptions: f("antfly_db_open_with_options", "uint32_t", [
|
|
481
|
+
"str",
|
|
482
|
+
PAntflyOpenOptions,
|
|
483
|
+
PAntflyDbOut
|
|
484
|
+
]),
|
|
485
|
+
dbCreateWithOptions: f("antfly_db_create_with_options", "uint32_t", [
|
|
486
|
+
"str",
|
|
487
|
+
PAntflyOpenOptions,
|
|
488
|
+
PAntflyDbOut
|
|
489
|
+
]),
|
|
490
|
+
liteOpenHosted: f("antfly_lite_open_hosted", "uint32_t", ["str", PAntflyDbOut]),
|
|
491
|
+
liteCreateHosted: f("antfly_lite_create_hosted", "uint32_t", ["str", PAntflyDbOut]),
|
|
492
|
+
dbClose: f("antfly_db_close", "void", [PAntflyDb]),
|
|
493
|
+
bufferFree: f("antfly_buffer_free", "void", [koffi.pointer(AntflyBuffer)]),
|
|
494
|
+
dbSqlJson: f("antfly_db_sql_json", "uint32_t", [PAntflyDb, AntflySlice, PAntflyBufferOut]),
|
|
495
|
+
dbOpenTable: f("antfly_db_open_table", "uint32_t", [PAntflyDb, AntflySlice, PAntflyDbOut]),
|
|
496
|
+
dbCreateTableJson: f("antfly_db_create_table_json", "uint32_t", [
|
|
497
|
+
PAntflyDb,
|
|
498
|
+
AntflySlice,
|
|
499
|
+
AntflySlice
|
|
500
|
+
]),
|
|
501
|
+
dbDropTable: f("antfly_db_drop_table", "uint32_t", [PAntflyDb, AntflySlice]),
|
|
502
|
+
dbListTablesJson: f("antfly_db_list_tables_json", "uint32_t", [PAntflyDb, PAntflyBufferOut]),
|
|
503
|
+
dbSqlSessionOpen: f("antfly_db_sql_session_open", "uint32_t", [
|
|
504
|
+
PAntflyDb,
|
|
505
|
+
koffi.out(koffi.pointer("uint64_t"))
|
|
506
|
+
]),
|
|
507
|
+
dbSqlSessionClose: f("antfly_db_sql_session_close", "uint32_t", [PAntflyDb, "uint64_t"]),
|
|
508
|
+
dbSqlOpenCursorJson: f("antfly_db_sql_open_cursor_json", "uint32_t", [
|
|
509
|
+
PAntflyDb,
|
|
510
|
+
AntflySlice,
|
|
511
|
+
koffi.out(koffi.pointer("uint64_t")),
|
|
512
|
+
PAntflyBufferOut
|
|
513
|
+
]),
|
|
514
|
+
dbSqlFetchCursorJson: f("antfly_db_sql_fetch_cursor_json", "uint32_t", [
|
|
515
|
+
PAntflyDb,
|
|
516
|
+
"uint64_t",
|
|
517
|
+
"uint32_t",
|
|
518
|
+
PAntflyBufferOut
|
|
519
|
+
]),
|
|
520
|
+
dbSqlCloseCursor: f("antfly_db_sql_close_cursor", "uint32_t", [PAntflyDb, "uint64_t"]),
|
|
521
|
+
dbStatusJson: f("antfly_db_status_json", "uint32_t", [PAntflyDb, PAntflyBufferOut]),
|
|
522
|
+
dbCapabilitiesJson: f("antfly_db_capabilities_json", "uint32_t", [PAntflyDb, PAntflyBufferOut]),
|
|
523
|
+
dbBackup: f("antfly_db_backup", "uint32_t", [PAntflyDb, PAntflyBufferOut]),
|
|
524
|
+
dbImportBackup: f("antfly_db_import_backup", "uint32_t", [PAntflyDb, AntflySlice]),
|
|
525
|
+
restoreBackupJson: f("antfly_restore_backup_json", "uint32_t", [
|
|
526
|
+
"str",
|
|
527
|
+
PAntflyOpenOptions,
|
|
528
|
+
AntflySlice,
|
|
529
|
+
"bool",
|
|
530
|
+
PAntflyBufferOut
|
|
531
|
+
]),
|
|
532
|
+
restoreBackupFileJson: f("antfly_restore_backup_file_json", "uint32_t", [
|
|
533
|
+
"str",
|
|
534
|
+
PAntflyOpenOptions,
|
|
535
|
+
"str",
|
|
536
|
+
"bool",
|
|
537
|
+
PAntflyBufferOut
|
|
538
|
+
]),
|
|
539
|
+
liteCheckJson: f("antfly_lite_check_json", "uint32_t", [PAntflyDb, PAntflyBufferOut]),
|
|
540
|
+
liteCheckFileJson: f("antfly_lite_check_file_json", "uint32_t", ["str", PAntflyBufferOut]),
|
|
541
|
+
liteCopyStableSnapshotJson: f("antfly_lite_copy_stable_snapshot_json", "uint32_t", [
|
|
542
|
+
PAntflyDb,
|
|
543
|
+
"str",
|
|
544
|
+
"bool",
|
|
545
|
+
PAntflyBufferOut
|
|
546
|
+
]),
|
|
547
|
+
liteCopyStableSnapshotFileJson: f("antfly_lite_copy_stable_snapshot_file_json", "uint32_t", [
|
|
548
|
+
"str",
|
|
549
|
+
"str",
|
|
550
|
+
"bool",
|
|
551
|
+
PAntflyBufferOut
|
|
552
|
+
]),
|
|
553
|
+
liteCompactJson: f("antfly_lite_compact_json", "uint32_t", [PAntflyDb, PAntflyBufferOut]),
|
|
554
|
+
liteVacuumJson: f("antfly_lite_vacuum_json", "uint32_t", [PAntflyDb, PAntflyBufferOut]),
|
|
555
|
+
dbRunUntilIdle: f("antfly_db_run_until_idle", "uint32_t", [PAntflyDb]),
|
|
556
|
+
dbRunUntilIdleJson: f("antfly_db_run_until_idle_json", "uint32_t", [
|
|
557
|
+
PAntflyDb,
|
|
558
|
+
PAntflyBufferOut
|
|
559
|
+
]),
|
|
560
|
+
dbReplayGeneratedEnrichmentsJson: f("antfly_db_replay_generated_enrichments_json", "uint32_t", [
|
|
561
|
+
PAntflyDb,
|
|
562
|
+
PAntflyBufferOut
|
|
563
|
+
]),
|
|
564
|
+
dbPendingWorkStatsJson: f("antfly_db_pending_work_stats_json", "uint32_t", [
|
|
565
|
+
PAntflyDb,
|
|
566
|
+
PAntflyBufferOut
|
|
567
|
+
]),
|
|
568
|
+
dbBatch: f("antfly_db_batch", "uint32_t", [
|
|
569
|
+
PAntflyDb,
|
|
570
|
+
PAntflyWriteIntentArray,
|
|
571
|
+
"size_t",
|
|
572
|
+
PAntflyVersionPredicateArray,
|
|
573
|
+
"size_t",
|
|
574
|
+
"uint64_t",
|
|
575
|
+
"uint8_t"
|
|
576
|
+
]),
|
|
577
|
+
dbBatchJson: f("antfly_db_batch_json", "uint32_t", [PAntflyDb, AntflySlice, PAntflyBufferOut]),
|
|
578
|
+
dbBeginTransactionWithId: f("antfly_db_begin_transaction_with_id", "uint32_t", [
|
|
579
|
+
PAntflyDb,
|
|
580
|
+
"const uint8_t *",
|
|
581
|
+
"uint64_t",
|
|
582
|
+
PAntflySliceArray,
|
|
583
|
+
"size_t"
|
|
584
|
+
]),
|
|
585
|
+
dbWriteTransaction: f("antfly_db_write_transaction", "uint32_t", [
|
|
586
|
+
PAntflyDb,
|
|
587
|
+
"const uint8_t *",
|
|
588
|
+
PAntflyWriteIntentArray,
|
|
589
|
+
"size_t",
|
|
590
|
+
PAntflyVersionPredicateArray,
|
|
591
|
+
"size_t"
|
|
592
|
+
]),
|
|
593
|
+
dbResolveIntents: f("antfly_db_resolve_intents", "uint32_t", [
|
|
594
|
+
PAntflyDb,
|
|
595
|
+
"const uint8_t *",
|
|
596
|
+
"uint8_t",
|
|
597
|
+
"uint64_t"
|
|
598
|
+
]),
|
|
599
|
+
dbGetTransactionStatus: f("antfly_db_get_transaction_status", "uint32_t", [
|
|
600
|
+
PAntflyDb,
|
|
601
|
+
"const uint8_t *",
|
|
602
|
+
PUint8Out
|
|
603
|
+
]),
|
|
604
|
+
dbGetCommitVersion: f("antfly_db_get_commit_version", "uint32_t", [
|
|
605
|
+
PAntflyDb,
|
|
606
|
+
"const uint8_t *",
|
|
607
|
+
PUint64Out
|
|
608
|
+
]),
|
|
609
|
+
dbLookupJson: f("antfly_db_lookup_json", "uint32_t", [
|
|
610
|
+
PAntflyDb,
|
|
611
|
+
AntflySlice,
|
|
612
|
+
PAntflyBufferOut
|
|
613
|
+
]),
|
|
614
|
+
dbGetRaw: f("antfly_db_get_raw", "uint32_t", [PAntflyDb, AntflySlice, PAntflyBufferOut]),
|
|
615
|
+
dbGetSchemaJson: f("antfly_db_get_schema_json", "uint32_t", [PAntflyDb, PAntflyBufferOut]),
|
|
616
|
+
dbSetSchemaJson: f("antfly_db_set_schema_json", "uint32_t", [PAntflyDb, AntflySlice]),
|
|
617
|
+
dbListIndexesJson: f("antfly_db_list_indexes_json", "uint32_t", [PAntflyDb, PAntflyBufferOut]),
|
|
618
|
+
dbAddIndexJson: f("antfly_db_add_index_json", "uint32_t", [PAntflyDb, AntflySlice]),
|
|
619
|
+
dbDeleteIndex: f("antfly_db_delete_index", "uint32_t", [PAntflyDb, AntflySlice, PBoolOut]),
|
|
620
|
+
dbListEnrichmentsJson: f("antfly_db_list_enrichments_json", "uint32_t", [
|
|
621
|
+
PAntflyDb,
|
|
622
|
+
PAntflyBufferOut
|
|
623
|
+
]),
|
|
624
|
+
dbAddEnrichmentJson: f("antfly_db_add_enrichment_json", "uint32_t", [PAntflyDb, AntflySlice]),
|
|
625
|
+
dbDeleteEnrichment: f("antfly_db_delete_enrichment", "uint32_t", [
|
|
626
|
+
PAntflyDb,
|
|
627
|
+
AntflySlice,
|
|
628
|
+
AntflySlice,
|
|
629
|
+
PBoolOut
|
|
630
|
+
]),
|
|
631
|
+
dbScanJson: f("antfly_db_scan_json", "uint32_t", [PAntflyDb, AntflySlice, PAntflyBufferOut]),
|
|
632
|
+
dbStatsJson: f("antfly_db_stats_json", "uint32_t", [PAntflyDb, PAntflyBufferOut]),
|
|
633
|
+
dbSearchJson: f("antfly_db_search_json", "uint32_t", [
|
|
634
|
+
PAntflyDb,
|
|
635
|
+
AntflySlice,
|
|
636
|
+
PAntflyBufferOut
|
|
637
|
+
]),
|
|
638
|
+
dbSearchDenseWire: f("antfly_db_search_dense_wire", "uint32_t", [
|
|
639
|
+
PAntflyDb,
|
|
640
|
+
AntflySlice,
|
|
641
|
+
PAntflyBufferOut
|
|
642
|
+
]),
|
|
643
|
+
dbSearchTextMatchWire: f("antfly_db_search_text_match_wire", "uint32_t", [
|
|
644
|
+
PAntflyDb,
|
|
645
|
+
AntflySlice,
|
|
646
|
+
PAntflyBufferOut
|
|
647
|
+
]),
|
|
648
|
+
dbSearchTextTermWire: f("antfly_db_search_text_term_wire", "uint32_t", [
|
|
649
|
+
PAntflyDb,
|
|
650
|
+
AntflySlice,
|
|
651
|
+
PAntflyBufferOut
|
|
652
|
+
]),
|
|
653
|
+
dbSearchTextMatchPhraseWire: f("antfly_db_search_text_match_phrase_wire", "uint32_t", [
|
|
654
|
+
PAntflyDb,
|
|
655
|
+
AntflySlice,
|
|
656
|
+
PAntflyBufferOut
|
|
657
|
+
]),
|
|
658
|
+
dbAggregateHitsJson: f("antfly_db_aggregate_hits_json", "uint32_t", [
|
|
659
|
+
PAntflyDb,
|
|
660
|
+
AntflySlice,
|
|
661
|
+
PAntflyBufferOut
|
|
662
|
+
]),
|
|
663
|
+
dbLookupArtifactJson: f("antfly_db_lookup_artifact_json", "uint32_t", [
|
|
664
|
+
PAntflyDb,
|
|
665
|
+
AntflySlice,
|
|
666
|
+
PAntflyBufferOut
|
|
667
|
+
]),
|
|
668
|
+
decodeArtifactIdJson: f("antfly_decode_artifact_id_json", "uint32_t", [
|
|
669
|
+
AntflySlice,
|
|
670
|
+
PAntflyBufferOut
|
|
671
|
+
]),
|
|
672
|
+
dbExtractEnrichmentsJson: f("antfly_db_extract_enrichments_json", "uint32_t", [
|
|
673
|
+
PAntflyDb,
|
|
674
|
+
AntflySlice,
|
|
675
|
+
PAntflyBufferOut
|
|
676
|
+
]),
|
|
677
|
+
dbComputeEnrichmentsJson: f("antfly_db_compute_enrichments_json", "uint32_t", [
|
|
678
|
+
PAntflyDb,
|
|
679
|
+
AntflySlice,
|
|
680
|
+
PAntflyBufferOut
|
|
681
|
+
]),
|
|
682
|
+
dbGetEdgesJson: f("antfly_db_get_edges_json", "uint32_t", [
|
|
683
|
+
PAntflyDb,
|
|
684
|
+
AntflySlice,
|
|
685
|
+
AntflySlice,
|
|
686
|
+
AntflySlice,
|
|
687
|
+
"uint8_t",
|
|
688
|
+
PAntflyBufferOut
|
|
689
|
+
]),
|
|
690
|
+
dbTraverseEdgesJson: f("antfly_db_traverse_edges_json", "uint32_t", [
|
|
691
|
+
PAntflyDb,
|
|
692
|
+
AntflySlice,
|
|
693
|
+
PAntflyBufferOut
|
|
694
|
+
]),
|
|
695
|
+
dbExecuteGraphQueriesJson: f("antfly_db_execute_graph_queries_json", "uint32_t", [
|
|
696
|
+
PAntflyDb,
|
|
697
|
+
AntflySlice,
|
|
698
|
+
PAntflyBufferOut
|
|
699
|
+
]),
|
|
700
|
+
dbGetNeighborsJson: f("antfly_db_get_neighbors_json", "uint32_t", [
|
|
701
|
+
PAntflyDb,
|
|
702
|
+
AntflySlice,
|
|
703
|
+
AntflySlice,
|
|
704
|
+
AntflySlice,
|
|
705
|
+
"uint8_t",
|
|
706
|
+
PAntflyBufferOut
|
|
707
|
+
]),
|
|
708
|
+
dbFindShortestPathJson: f("antfly_db_find_shortest_path_json", "uint32_t", [
|
|
709
|
+
PAntflyDb,
|
|
710
|
+
AntflySlice,
|
|
711
|
+
PAntflyBufferOut
|
|
712
|
+
]),
|
|
713
|
+
dbFindKShortestPathsJson: f("antfly_db_find_k_shortest_paths_json", "uint32_t", [
|
|
714
|
+
PAntflyDb,
|
|
715
|
+
AntflySlice,
|
|
716
|
+
PAntflyBufferOut
|
|
717
|
+
]),
|
|
718
|
+
dbMatchPatternJson: f("antfly_db_match_pattern_json", "uint32_t", [
|
|
719
|
+
PAntflyDb,
|
|
720
|
+
AntflySlice,
|
|
721
|
+
PAntflyBufferOut
|
|
722
|
+
]),
|
|
723
|
+
// --- Embedded inference (antfly_inference_*) ---
|
|
724
|
+
inferenceOptionsSize: f("antfly_inference_options_size", "uint32_t", []),
|
|
725
|
+
inferenceOptionsInit: f("antfly_inference_options_init", "uint32_t", [
|
|
726
|
+
PAntflyInferenceOptionsOut
|
|
727
|
+
]),
|
|
728
|
+
inferenceOpen: f("antfly_inference_open", "uint32_t", [
|
|
729
|
+
PAntflyInferenceOptions,
|
|
730
|
+
PAntflyInferenceOut
|
|
731
|
+
]),
|
|
732
|
+
inferenceClose: f("antfly_inference_close", "void", [PAntflyInference]),
|
|
733
|
+
inferenceEmbedJson: f("antfly_inference_embed_json", "uint32_t", [
|
|
734
|
+
PAntflyInference,
|
|
735
|
+
AntflySlice,
|
|
736
|
+
PAntflyBufferOut
|
|
737
|
+
]),
|
|
738
|
+
inferenceRerankJson: f("antfly_inference_rerank_json", "uint32_t", [
|
|
739
|
+
PAntflyInference,
|
|
740
|
+
AntflySlice,
|
|
741
|
+
PAntflyBufferOut
|
|
742
|
+
]),
|
|
743
|
+
inferenceChunkJson: f("antfly_inference_chunk_json", "uint32_t", [
|
|
744
|
+
PAntflyInference,
|
|
745
|
+
AntflySlice,
|
|
746
|
+
PAntflyBufferOut
|
|
747
|
+
]),
|
|
748
|
+
inferenceGenerateJson: f("antfly_inference_generate_json", "uint32_t", [
|
|
749
|
+
PAntflyInference,
|
|
750
|
+
AntflySlice,
|
|
751
|
+
PAntflyBufferOut
|
|
752
|
+
]),
|
|
753
|
+
inferenceGenerateStreamJson: f("antfly_inference_generate_stream_json", "uint32_t", [
|
|
754
|
+
PAntflyInference,
|
|
755
|
+
AntflySlice,
|
|
756
|
+
PAntflyInferenceStreamFn,
|
|
757
|
+
"void *",
|
|
758
|
+
PAntflyBufferOut
|
|
759
|
+
]),
|
|
760
|
+
inferenceGenerateBatchJson: f("antfly_inference_generate_batch_json", "uint32_t", [
|
|
761
|
+
PAntflyInference,
|
|
762
|
+
AntflySlice,
|
|
763
|
+
PAntflyBufferOut
|
|
764
|
+
]),
|
|
765
|
+
inferenceRewriteJson: f("antfly_inference_rewrite_json", "uint32_t", [
|
|
766
|
+
PAntflyInference,
|
|
767
|
+
AntflySlice,
|
|
768
|
+
PAntflyBufferOut
|
|
769
|
+
]),
|
|
770
|
+
inferenceDecideJson: f("antfly_inference_decide_json", "uint32_t", [
|
|
771
|
+
PAntflyInference,
|
|
772
|
+
AntflySlice,
|
|
773
|
+
PAntflyBufferOut
|
|
774
|
+
]),
|
|
775
|
+
inferenceExtractJson: f("antfly_inference_extract_json", "uint32_t", [
|
|
776
|
+
PAntflyInference,
|
|
777
|
+
AntflySlice,
|
|
778
|
+
PAntflyBufferOut
|
|
779
|
+
]),
|
|
780
|
+
inferenceReadJson: f("antfly_inference_read_json", "uint32_t", [
|
|
781
|
+
PAntflyInference,
|
|
782
|
+
AntflySlice,
|
|
783
|
+
PAntflyBufferOut
|
|
784
|
+
]),
|
|
785
|
+
inferenceTranscribeJson: f("antfly_inference_transcribe_json", "uint32_t", [
|
|
786
|
+
PAntflyInference,
|
|
787
|
+
AntflySlice,
|
|
788
|
+
PAntflyBufferOut
|
|
789
|
+
]),
|
|
790
|
+
inferenceListModelsJson: f("antfly_inference_list_models_json", "uint32_t", [
|
|
791
|
+
PAntflyInference,
|
|
792
|
+
PAntflyBufferOut
|
|
793
|
+
]),
|
|
794
|
+
inferencePullJson: f("antfly_inference_pull_json", "uint32_t", [
|
|
795
|
+
PAntflyInference,
|
|
796
|
+
AntflySlice,
|
|
797
|
+
PAntflyInferencePullProgressFn,
|
|
798
|
+
"void *",
|
|
799
|
+
PAntflyBufferOut
|
|
800
|
+
])
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// src/abi.ts
|
|
805
|
+
var AbiMismatchError = class extends Error {
|
|
806
|
+
constructor(message) {
|
|
807
|
+
super(message);
|
|
808
|
+
this.name = "AbiMismatchError";
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
function abiVersion() {
|
|
812
|
+
return loadNative().abiVersion();
|
|
813
|
+
}
|
|
814
|
+
function threadingMode() {
|
|
815
|
+
return loadNative().threadingMode();
|
|
816
|
+
}
|
|
817
|
+
function validateAbi() {
|
|
818
|
+
const native = loadNative();
|
|
819
|
+
const gotVersion = native.abiVersion();
|
|
820
|
+
if (gotVersion !== SUPPORTED_ABI_VERSION) {
|
|
821
|
+
throw new AbiMismatchError(
|
|
822
|
+
`lite: unsupported C ABI version ${gotVersion}, want ${SUPPORTED_ABI_VERSION}`
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
const gotSize = native.openOptionsSize();
|
|
826
|
+
const wantSize = koffi2.sizeof(AntflyOpenOptions);
|
|
827
|
+
if (gotSize !== wantSize) {
|
|
828
|
+
throw new AbiMismatchError(
|
|
829
|
+
`lite: C ABI open options size ${gotSize}, compiled header size ${wantSize}`
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
function validateInferenceAbi() {
|
|
834
|
+
const native = loadNative();
|
|
835
|
+
const gotSize = native.inferenceOptionsSize();
|
|
836
|
+
const wantSize = koffi2.sizeof(AntflyInferenceOptions);
|
|
837
|
+
if (gotSize !== wantSize) {
|
|
838
|
+
throw new AbiMismatchError(
|
|
839
|
+
`lite: C ABI inference options size ${gotSize}, compiled header size ${wantSize}`
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// src/database.ts
|
|
845
|
+
import * as fsp from "fs/promises";
|
|
846
|
+
import { basename, dirname as dirname2, join as join2 } from "path";
|
|
847
|
+
|
|
848
|
+
// src/marshal.ts
|
|
849
|
+
import { promisify } from "util";
|
|
850
|
+
import koffi3 from "koffi";
|
|
851
|
+
function toRawBytes(input) {
|
|
852
|
+
if (Buffer.isBuffer(input)) {
|
|
853
|
+
return input;
|
|
854
|
+
}
|
|
855
|
+
if (input instanceof Uint8Array) {
|
|
856
|
+
return Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
|
857
|
+
}
|
|
858
|
+
throw new InvalidArgumentError(`expected Buffer or Uint8Array, got ${typeof input}`);
|
|
859
|
+
}
|
|
860
|
+
function toJsonBytes(input) {
|
|
861
|
+
if (typeof input === "string") {
|
|
862
|
+
return Buffer.from(input, "utf8");
|
|
863
|
+
}
|
|
864
|
+
if (Buffer.isBuffer(input) || input instanceof Uint8Array) {
|
|
865
|
+
return toRawBytes(input);
|
|
866
|
+
}
|
|
867
|
+
return Buffer.from(JSON.stringify(input), "utf8");
|
|
868
|
+
}
|
|
869
|
+
function sliceOf(bytes) {
|
|
870
|
+
return bytes.length === 0 ? { ptr: null, len: 0 } : { ptr: bytes, len: bytes.length };
|
|
871
|
+
}
|
|
872
|
+
function jsonSlice(input) {
|
|
873
|
+
return sliceOf(toJsonBytes(input));
|
|
874
|
+
}
|
|
875
|
+
function stringSlice(input) {
|
|
876
|
+
return sliceOf(Buffer.from(input, "utf8"));
|
|
877
|
+
}
|
|
878
|
+
function parseJson(buf) {
|
|
879
|
+
if (buf.length === 0) {
|
|
880
|
+
return null;
|
|
881
|
+
}
|
|
882
|
+
return JSON.parse(buf.toString("utf8"));
|
|
883
|
+
}
|
|
884
|
+
function newBufferOut() {
|
|
885
|
+
return { ptr: null, len: 0 };
|
|
886
|
+
}
|
|
887
|
+
function takeBuffer(native, out) {
|
|
888
|
+
try {
|
|
889
|
+
const len = Number(out.len ?? 0);
|
|
890
|
+
if (!out.ptr || len === 0) {
|
|
891
|
+
return Buffer.alloc(0);
|
|
892
|
+
}
|
|
893
|
+
const view = koffi3.decode(out.ptr, "uint8_t", len);
|
|
894
|
+
return Buffer.from(view);
|
|
895
|
+
} finally {
|
|
896
|
+
native.bufferFree(out);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
function callAsync(fn, ...args) {
|
|
900
|
+
const bound = promisify(fn.async.bind(fn));
|
|
901
|
+
return withNativeSlot(() => bound(...args));
|
|
902
|
+
}
|
|
903
|
+
var nativeSlots = Math.max(1, Number.parseInt(process.env.UV_THREADPOOL_SIZE ?? "", 10) || 4);
|
|
904
|
+
var nativeActive = 0;
|
|
905
|
+
var nativeWaiters = [];
|
|
906
|
+
async function withNativeSlot(run) {
|
|
907
|
+
if (nativeActive >= nativeSlots) {
|
|
908
|
+
await new Promise((resolve) => nativeWaiters.push(resolve));
|
|
909
|
+
} else {
|
|
910
|
+
nativeActive++;
|
|
911
|
+
}
|
|
912
|
+
try {
|
|
913
|
+
return await run();
|
|
914
|
+
} finally {
|
|
915
|
+
const next = nativeWaiters.shift();
|
|
916
|
+
if (next) {
|
|
917
|
+
next();
|
|
918
|
+
} else {
|
|
919
|
+
nativeActive--;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
function txnIdBytes(id) {
|
|
924
|
+
if (typeof id === "string") {
|
|
925
|
+
if (!/^[0-9a-fA-F]{32}$/.test(id)) {
|
|
926
|
+
throw new InvalidArgumentError(`txnId must be 32 hex characters, got ${JSON.stringify(id)}`);
|
|
927
|
+
}
|
|
928
|
+
return Buffer.from(id, "hex");
|
|
929
|
+
}
|
|
930
|
+
const buf = toRawBytes(id);
|
|
931
|
+
if (buf.length !== 16) {
|
|
932
|
+
throw new InvalidArgumentError(`txnId must be 16 bytes, got ${buf.length}`);
|
|
933
|
+
}
|
|
934
|
+
return buf;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
// src/database.ts
|
|
938
|
+
var OPEN_FLAG_NO_SYNC = 1 << 0;
|
|
939
|
+
var OPEN_FLAG_TTL_CLEANUP = 1 << 1;
|
|
940
|
+
var OPEN_FLAG_REMOTE_PROVIDER_CONFIGURED = 1 << 2;
|
|
941
|
+
var OPEN_FLAG_LOCAL_RUNTIME_CONFIGURED = 1 << 3;
|
|
942
|
+
var OPEN_FLAG_GENERATED_ENRICHMENT_REPLAY = 1 << 4;
|
|
943
|
+
function buildOpenOptionsStruct(native, opts) {
|
|
944
|
+
const options = {};
|
|
945
|
+
checkCode(native.openOptionsInit(options));
|
|
946
|
+
options.storage_kind = storageKind(opts.storage);
|
|
947
|
+
options.open_mode = opts.mode ?? 0 /* Writer */;
|
|
948
|
+
options.profile = opts.profile ?? 0 /* Native */;
|
|
949
|
+
let flags = 0;
|
|
950
|
+
if (opts.noSync) flags |= OPEN_FLAG_NO_SYNC;
|
|
951
|
+
if (opts.remoteProviderConfigured) flags |= OPEN_FLAG_REMOTE_PROVIDER_CONFIGURED;
|
|
952
|
+
if (opts.localRuntimeConfigured) flags |= OPEN_FLAG_LOCAL_RUNTIME_CONFIGURED;
|
|
953
|
+
if (opts.generatedEnrichmentReplay) flags |= OPEN_FLAG_GENERATED_ENRICHMENT_REPLAY;
|
|
954
|
+
if (opts.ttlCleanup) flags |= OPEN_FLAG_TTL_CLEANUP;
|
|
955
|
+
options.flags = flags;
|
|
956
|
+
options.map_size = opts.mapSize ?? 0;
|
|
957
|
+
options.inference_host_budget_mb = opts.inferenceHostBudgetMb ?? 0;
|
|
958
|
+
options.inference_backend_budget_mb = opts.inferenceBackendBudgetMb ?? 0;
|
|
959
|
+
options.inference_combined_budget_mb = opts.inferenceCombinedBudgetMb ?? 0;
|
|
960
|
+
options.inference_kv_budget_mb = opts.inferenceKvBudgetMb ?? 0;
|
|
961
|
+
options.inference_scratch_budget_mb = opts.inferenceScratchBudgetMb ?? 0;
|
|
962
|
+
options.inference_process_memory_budget_mb = opts.inferenceProcessMemoryBudgetMb ?? 0;
|
|
963
|
+
options.busy_timeout_ms = opts.busyTimeoutMs ?? 0;
|
|
964
|
+
if (opts.ttlCleanup) {
|
|
965
|
+
const ttl = opts.ttlCleanup;
|
|
966
|
+
options.ttl_cleanup_enabled = ttl.enabled;
|
|
967
|
+
options.ttl_cleanup_lease_owned = ttl.leaseOwned;
|
|
968
|
+
options.ttl_cleanup_batch_size = ttl.batchSize ?? 0;
|
|
969
|
+
options.ttl_cleanup_owner_id = stringSlice(ttl.ownerId ?? "");
|
|
970
|
+
options.ttl_cleanup_lease_ttl_ms = ttl.leaseTtlMs ?? 0;
|
|
971
|
+
options.ttl_cleanup_interval_ms = ttl.intervalMs ?? 0;
|
|
972
|
+
options.ttl_cleanup_grace_period_ns = ttl.gracePeriodNs ?? 0;
|
|
973
|
+
}
|
|
974
|
+
return options;
|
|
975
|
+
}
|
|
976
|
+
function keySlice(key) {
|
|
977
|
+
return typeof key === "string" ? stringSlice(key) : sliceOf(toRawBytes(key));
|
|
978
|
+
}
|
|
979
|
+
function writeIntentValueBytes(w) {
|
|
980
|
+
if (w.delete || w.value == null) {
|
|
981
|
+
return Buffer.alloc(0);
|
|
982
|
+
}
|
|
983
|
+
if (w.value instanceof Uint8Array) {
|
|
984
|
+
return toRawBytes(w.value);
|
|
985
|
+
}
|
|
986
|
+
return Buffer.from(JSON.stringify(w.value), "utf8");
|
|
987
|
+
}
|
|
988
|
+
function toNativeWriteIntent(w) {
|
|
989
|
+
return {
|
|
990
|
+
key: stringSlice(w.key),
|
|
991
|
+
value: sliceOf(writeIntentValueBytes(w)),
|
|
992
|
+
is_delete: Boolean(w.delete)
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
var Database = class _Database {
|
|
996
|
+
/** @internal use open()/create()/openHosted()/etc. instead of the constructor. */
|
|
997
|
+
constructor(native, handle, owner) {
|
|
998
|
+
this.owner = owner;
|
|
999
|
+
this.#native = native;
|
|
1000
|
+
this.#handle = handle;
|
|
1001
|
+
finalizationRegistry.register(this, { native, handle }, this.#finalizerToken);
|
|
1002
|
+
}
|
|
1003
|
+
owner;
|
|
1004
|
+
#native;
|
|
1005
|
+
#handle;
|
|
1006
|
+
#state = "open";
|
|
1007
|
+
#pending = /* @__PURE__ */ new Set();
|
|
1008
|
+
#closeTask;
|
|
1009
|
+
#finalizerToken = {};
|
|
1010
|
+
#run(op) {
|
|
1011
|
+
if (this.#state !== "open") {
|
|
1012
|
+
return Promise.reject(new InvalidArgumentError("database handle is closed"));
|
|
1013
|
+
}
|
|
1014
|
+
const handle = this.#handle;
|
|
1015
|
+
const promise = op(handle);
|
|
1016
|
+
this.#pending.add(promise);
|
|
1017
|
+
const cleanup = () => this.#pending.delete(promise);
|
|
1018
|
+
promise.then(cleanup, cleanup);
|
|
1019
|
+
return promise;
|
|
1020
|
+
}
|
|
1021
|
+
// biome-ignore lint/suspicious/noExplicitAny: koffi function signatures vary per call site
|
|
1022
|
+
#invokeCode(fn, ...args) {
|
|
1023
|
+
return this.#run(async (handle) => {
|
|
1024
|
+
const code = await callAsync(fn, handle, ...args);
|
|
1025
|
+
checkCode(code);
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
// biome-ignore lint/suspicious/noExplicitAny: koffi function signatures vary per call site
|
|
1029
|
+
#invokeBuffer(fn, ...args) {
|
|
1030
|
+
return this.#run(async (handle) => {
|
|
1031
|
+
const out = newBufferOut();
|
|
1032
|
+
const code = await callAsync(fn, handle, ...args, out);
|
|
1033
|
+
checkCode(code);
|
|
1034
|
+
return takeBuffer(this.#native, out);
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
// SQL buffers must be released on failures as well as successful calls.
|
|
1038
|
+
// biome-ignore lint/suspicious/noExplicitAny: native signatures vary
|
|
1039
|
+
#invokeSql(fn, ...args) {
|
|
1040
|
+
return this.#run(async (handle) => {
|
|
1041
|
+
const out = newBufferOut();
|
|
1042
|
+
const code = await callAsync(fn, handle, ...args, out);
|
|
1043
|
+
const body = takeBuffer(this.#native, out);
|
|
1044
|
+
const value = body.length ? JSON.parse(body.toString("utf8")) : void 0;
|
|
1045
|
+
if (code && value?.error) throw new SqlError(value.error, value.transaction_id);
|
|
1046
|
+
checkCode(code);
|
|
1047
|
+
return value;
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
sqlJson(request) {
|
|
1051
|
+
return this.#invokeSql(this.#native.dbSqlJson, jsonSlice(request));
|
|
1052
|
+
}
|
|
1053
|
+
createTable(name, schema) {
|
|
1054
|
+
return this.#invokeCode(this.#native.dbCreateTableJson, stringSlice(name), jsonSlice(schema));
|
|
1055
|
+
}
|
|
1056
|
+
dropTable(name) {
|
|
1057
|
+
return this.#invokeCode(this.#native.dbDropTable, stringSlice(name));
|
|
1058
|
+
}
|
|
1059
|
+
async listTables() {
|
|
1060
|
+
return parseJson(await this.#invokeBuffer(this.#native.dbListTablesJson));
|
|
1061
|
+
}
|
|
1062
|
+
async openSqlSession() {
|
|
1063
|
+
return this.#run(async (handle) => {
|
|
1064
|
+
const out = [0];
|
|
1065
|
+
checkCode(await callAsync(this.#native.dbSqlSessionOpen, handle, out));
|
|
1066
|
+
return out[0];
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
closeSqlSession(id) {
|
|
1070
|
+
return this.#invokeCode(this.#native.dbSqlSessionClose, id);
|
|
1071
|
+
}
|
|
1072
|
+
async openSqlCursor(request) {
|
|
1073
|
+
const out = [0];
|
|
1074
|
+
await this.#invokeSql(this.#native.dbSqlOpenCursorJson, jsonSlice(request), out);
|
|
1075
|
+
return out[0];
|
|
1076
|
+
}
|
|
1077
|
+
fetchSqlCursor(id, rows = 128) {
|
|
1078
|
+
return this.#invokeSql(this.#native.dbSqlFetchCursorJson, id, rows);
|
|
1079
|
+
}
|
|
1080
|
+
closeSqlCursor(id) {
|
|
1081
|
+
return this.#invokeCode(this.#native.dbSqlCloseCursor, id);
|
|
1082
|
+
}
|
|
1083
|
+
// --- Lifecycle ---
|
|
1084
|
+
/** Idempotent; waits for in-flight calls before freeing the native handle. Calls made after close() rejects with InvalidArgumentError. */
|
|
1085
|
+
async close() {
|
|
1086
|
+
if (this.#state === "closed") return;
|
|
1087
|
+
if (this.#state === "closing") {
|
|
1088
|
+
await this.#closeTask;
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
this.#state = "closing";
|
|
1092
|
+
finalizationRegistry.unregister(this.#finalizerToken);
|
|
1093
|
+
const handle = this.#handle;
|
|
1094
|
+
this.#closeTask = (async () => {
|
|
1095
|
+
while (this.#pending.size > 0) {
|
|
1096
|
+
await Promise.allSettled([...this.#pending]);
|
|
1097
|
+
}
|
|
1098
|
+
if (handle != null) {
|
|
1099
|
+
await callAsync(this.#native.dbClose, handle);
|
|
1100
|
+
}
|
|
1101
|
+
this.#handle = null;
|
|
1102
|
+
this.#state = "closed";
|
|
1103
|
+
})();
|
|
1104
|
+
await this.#closeTask;
|
|
1105
|
+
}
|
|
1106
|
+
async [Symbol.asyncDispose]() {
|
|
1107
|
+
await this.close();
|
|
1108
|
+
}
|
|
1109
|
+
/** Open a table-scoped document/schema/index/enrichment handle. */
|
|
1110
|
+
async openTable(name) {
|
|
1111
|
+
const out = [null];
|
|
1112
|
+
await this.#invokeCode(this.#native.dbOpenTable, stringSlice(name), out);
|
|
1113
|
+
return new _Database(this.#native, out[0], this);
|
|
1114
|
+
}
|
|
1115
|
+
// --- Status / capabilities / maintenance ---
|
|
1116
|
+
statusRaw() {
|
|
1117
|
+
return this.#invokeBuffer(this.#native.dbStatusJson);
|
|
1118
|
+
}
|
|
1119
|
+
async status() {
|
|
1120
|
+
return parseJson(await this.statusRaw());
|
|
1121
|
+
}
|
|
1122
|
+
capabilitiesRaw() {
|
|
1123
|
+
return this.#invokeBuffer(this.#native.dbCapabilitiesJson);
|
|
1124
|
+
}
|
|
1125
|
+
async capabilities() {
|
|
1126
|
+
return parseJson(await this.capabilitiesRaw());
|
|
1127
|
+
}
|
|
1128
|
+
checkRaw() {
|
|
1129
|
+
return this.#invokeBuffer(this.#native.liteCheckJson);
|
|
1130
|
+
}
|
|
1131
|
+
async check() {
|
|
1132
|
+
return parseJson(await this.checkRaw());
|
|
1133
|
+
}
|
|
1134
|
+
vacuumRaw() {
|
|
1135
|
+
return this.#invokeBuffer(this.#native.liteVacuumJson);
|
|
1136
|
+
}
|
|
1137
|
+
async vacuum() {
|
|
1138
|
+
return parseJson(await this.vacuumRaw());
|
|
1139
|
+
}
|
|
1140
|
+
compactRaw() {
|
|
1141
|
+
return this.#invokeBuffer(this.#native.liteCompactJson);
|
|
1142
|
+
}
|
|
1143
|
+
async compact() {
|
|
1144
|
+
return parseJson(await this.compactRaw());
|
|
1145
|
+
}
|
|
1146
|
+
copyStableSnapshotRaw(destPath, replace) {
|
|
1147
|
+
if (!destPath.endsWith(".aflite")) {
|
|
1148
|
+
return Promise.reject(new InvalidArgumentError("destPath must end with .aflite"));
|
|
1149
|
+
}
|
|
1150
|
+
return this.#invokeBuffer(this.#native.liteCopyStableSnapshotJson, destPath, replace);
|
|
1151
|
+
}
|
|
1152
|
+
async copyStableSnapshot(destPath, replace) {
|
|
1153
|
+
return parseJson(await this.copyStableSnapshotRaw(destPath, replace));
|
|
1154
|
+
}
|
|
1155
|
+
pendingWorkStatsRaw() {
|
|
1156
|
+
return this.#invokeBuffer(this.#native.dbPendingWorkStatsJson);
|
|
1157
|
+
}
|
|
1158
|
+
async pendingWorkStats() {
|
|
1159
|
+
return parseJson(await this.pendingWorkStatsRaw());
|
|
1160
|
+
}
|
|
1161
|
+
/** Drains pending enrichment and index work; returns no result (see runUntilIdleStatus for the post-drain report). */
|
|
1162
|
+
runUntilIdle() {
|
|
1163
|
+
return this.#invokeCode(this.#native.dbRunUntilIdle);
|
|
1164
|
+
}
|
|
1165
|
+
runUntilIdleStatusRaw() {
|
|
1166
|
+
return this.#invokeBuffer(this.#native.dbRunUntilIdleJson);
|
|
1167
|
+
}
|
|
1168
|
+
async runUntilIdleStatus() {
|
|
1169
|
+
return parseJson(await this.runUntilIdleStatusRaw());
|
|
1170
|
+
}
|
|
1171
|
+
replayGeneratedEnrichmentsRaw() {
|
|
1172
|
+
return this.#invokeBuffer(this.#native.dbReplayGeneratedEnrichmentsJson);
|
|
1173
|
+
}
|
|
1174
|
+
async replayGeneratedEnrichments() {
|
|
1175
|
+
return parseJson(
|
|
1176
|
+
await this.replayGeneratedEnrichmentsRaw()
|
|
1177
|
+
);
|
|
1178
|
+
}
|
|
1179
|
+
// --- Backup / import ---
|
|
1180
|
+
/** Returns a portable Antfly backup archive (.afb) of this database, which restores or imports into either storage kind. */
|
|
1181
|
+
backup() {
|
|
1182
|
+
return this.#invokeBuffer(this.#native.dbBackup);
|
|
1183
|
+
}
|
|
1184
|
+
/** Imports a portable Antfly backup archive into this empty database. OutcomeUnknown means the live handle adopted the imported generation, but crash durability could not be confirmed; inspect the handle and do not retry automatically. */
|
|
1185
|
+
importBackup(backup) {
|
|
1186
|
+
return this.#invokeCode(this.#native.dbImportBackup, sliceOf(toRawBytes(backup)));
|
|
1187
|
+
}
|
|
1188
|
+
async backupToFile(path) {
|
|
1189
|
+
if (!path.endsWith(".afb")) throw new InvalidArgumentError("path must end with .afb");
|
|
1190
|
+
await writeFileAtomically(path, await this.backup());
|
|
1191
|
+
}
|
|
1192
|
+
// --- Documents ---
|
|
1193
|
+
batch(writes, timestampNs) {
|
|
1194
|
+
return this.#run(async (handle) => {
|
|
1195
|
+
const cWrites = writes.length ? writes.map(toNativeWriteIntent) : null;
|
|
1196
|
+
const code = await callAsync(
|
|
1197
|
+
this.#native.dbBatch,
|
|
1198
|
+
handle,
|
|
1199
|
+
cWrites,
|
|
1200
|
+
writes.length,
|
|
1201
|
+
null,
|
|
1202
|
+
0,
|
|
1203
|
+
timestampNs,
|
|
1204
|
+
0
|
|
1205
|
+
);
|
|
1206
|
+
checkCode(code);
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
batchJsonRaw(request) {
|
|
1210
|
+
return this.#invokeBuffer(this.#native.dbBatchJson, jsonSlice(request));
|
|
1211
|
+
}
|
|
1212
|
+
async batchJson(request) {
|
|
1213
|
+
return parseJson(await this.batchJsonRaw(request));
|
|
1214
|
+
}
|
|
1215
|
+
lookupRaw(key) {
|
|
1216
|
+
return this.#invokeBuffer(this.#native.dbLookupJson, keySlice(key));
|
|
1217
|
+
}
|
|
1218
|
+
async lookup(key) {
|
|
1219
|
+
return parseJson(await this.lookupRaw(key));
|
|
1220
|
+
}
|
|
1221
|
+
/** Raw stored bytes for key (antfly_db_get_raw), not JSON. */
|
|
1222
|
+
getRaw(key) {
|
|
1223
|
+
return this.#invokeBuffer(this.#native.dbGetRaw, keySlice(key));
|
|
1224
|
+
}
|
|
1225
|
+
getSchemaRaw() {
|
|
1226
|
+
return this.#invokeBuffer(this.#native.dbGetSchemaJson);
|
|
1227
|
+
}
|
|
1228
|
+
async getSchema() {
|
|
1229
|
+
return parseJson(await this.getSchemaRaw());
|
|
1230
|
+
}
|
|
1231
|
+
setSchema(schema) {
|
|
1232
|
+
return this.#invokeCode(this.#native.dbSetSchemaJson, jsonSlice(schema));
|
|
1233
|
+
}
|
|
1234
|
+
listIndexesRaw() {
|
|
1235
|
+
return this.#invokeBuffer(this.#native.dbListIndexesJson);
|
|
1236
|
+
}
|
|
1237
|
+
async listIndexes() {
|
|
1238
|
+
return parseJson(await this.listIndexesRaw());
|
|
1239
|
+
}
|
|
1240
|
+
addIndex(config) {
|
|
1241
|
+
return this.#invokeCode(this.#native.dbAddIndexJson, jsonSlice(config));
|
|
1242
|
+
}
|
|
1243
|
+
deleteIndex(name) {
|
|
1244
|
+
return this.#run(async (handle) => {
|
|
1245
|
+
const out = [false];
|
|
1246
|
+
const code = await callAsync(this.#native.dbDeleteIndex, handle, stringSlice(name), out);
|
|
1247
|
+
checkCode(code);
|
|
1248
|
+
return Boolean(out[0]);
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
listEnrichmentsRaw() {
|
|
1252
|
+
return this.#invokeBuffer(this.#native.dbListEnrichmentsJson);
|
|
1253
|
+
}
|
|
1254
|
+
async listEnrichments() {
|
|
1255
|
+
return parseJson(await this.listEnrichmentsRaw());
|
|
1256
|
+
}
|
|
1257
|
+
addEnrichment(config) {
|
|
1258
|
+
return this.#invokeCode(this.#native.dbAddEnrichmentJson, jsonSlice(config));
|
|
1259
|
+
}
|
|
1260
|
+
deleteEnrichment(kind, name) {
|
|
1261
|
+
return this.#run(async (handle) => {
|
|
1262
|
+
const out = [false];
|
|
1263
|
+
const code = await callAsync(
|
|
1264
|
+
this.#native.dbDeleteEnrichment,
|
|
1265
|
+
handle,
|
|
1266
|
+
stringSlice(kind),
|
|
1267
|
+
stringSlice(name),
|
|
1268
|
+
out
|
|
1269
|
+
);
|
|
1270
|
+
checkCode(code);
|
|
1271
|
+
return Boolean(out[0]);
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
scanRaw(request) {
|
|
1275
|
+
return this.#invokeBuffer(this.#native.dbScanJson, jsonSlice(request));
|
|
1276
|
+
}
|
|
1277
|
+
async scan(request) {
|
|
1278
|
+
return parseJson(await this.scanRaw(request));
|
|
1279
|
+
}
|
|
1280
|
+
statsRaw() {
|
|
1281
|
+
return this.#invokeBuffer(this.#native.dbStatsJson);
|
|
1282
|
+
}
|
|
1283
|
+
async stats() {
|
|
1284
|
+
return parseJson(await this.statsRaw());
|
|
1285
|
+
}
|
|
1286
|
+
searchRaw(request) {
|
|
1287
|
+
return this.#invokeBuffer(this.#native.dbSearchJson, jsonSlice(request));
|
|
1288
|
+
}
|
|
1289
|
+
async search(request) {
|
|
1290
|
+
return parseJson(await this.searchRaw(request));
|
|
1291
|
+
}
|
|
1292
|
+
// --- Packed wire searches (binary wire format, never JSON: request/response are raw bytes) ---
|
|
1293
|
+
denseSearchWire(request) {
|
|
1294
|
+
return this.#invokeBuffer(this.#native.dbSearchDenseWire, sliceOf(toRawBytes(request)));
|
|
1295
|
+
}
|
|
1296
|
+
textMatchWire(request) {
|
|
1297
|
+
return this.#invokeBuffer(this.#native.dbSearchTextMatchWire, sliceOf(toRawBytes(request)));
|
|
1298
|
+
}
|
|
1299
|
+
textTermWire(request) {
|
|
1300
|
+
return this.#invokeBuffer(this.#native.dbSearchTextTermWire, sliceOf(toRawBytes(request)));
|
|
1301
|
+
}
|
|
1302
|
+
textMatchPhraseWire(request) {
|
|
1303
|
+
return this.#invokeBuffer(
|
|
1304
|
+
this.#native.dbSearchTextMatchPhraseWire,
|
|
1305
|
+
sliceOf(toRawBytes(request))
|
|
1306
|
+
);
|
|
1307
|
+
}
|
|
1308
|
+
aggregateHitsRaw(request) {
|
|
1309
|
+
return this.#invokeBuffer(this.#native.dbAggregateHitsJson, jsonSlice(request));
|
|
1310
|
+
}
|
|
1311
|
+
async aggregateHits(request) {
|
|
1312
|
+
return parseJson(await this.aggregateHitsRaw(request));
|
|
1313
|
+
}
|
|
1314
|
+
lookupArtifactRaw(artifactIdBase64) {
|
|
1315
|
+
return this.#invokeBuffer(this.#native.dbLookupArtifactJson, stringSlice(artifactIdBase64));
|
|
1316
|
+
}
|
|
1317
|
+
async lookupArtifact(artifactIdBase64) {
|
|
1318
|
+
return parseJson(await this.lookupArtifactRaw(artifactIdBase64));
|
|
1319
|
+
}
|
|
1320
|
+
extractEnrichmentsRaw(request) {
|
|
1321
|
+
return this.#invokeBuffer(this.#native.dbExtractEnrichmentsJson, jsonSlice(request));
|
|
1322
|
+
}
|
|
1323
|
+
async extractEnrichments(request) {
|
|
1324
|
+
return parseJson(await this.extractEnrichmentsRaw(request));
|
|
1325
|
+
}
|
|
1326
|
+
computeEnrichmentsRaw(request) {
|
|
1327
|
+
return this.#invokeBuffer(this.#native.dbComputeEnrichmentsJson, jsonSlice(request));
|
|
1328
|
+
}
|
|
1329
|
+
async computeEnrichments(request) {
|
|
1330
|
+
return parseJson(await this.computeEnrichmentsRaw(request));
|
|
1331
|
+
}
|
|
1332
|
+
// --- Graph ---
|
|
1333
|
+
edgesRaw(indexName, key, edgeType, direction) {
|
|
1334
|
+
return this.#invokeBuffer(
|
|
1335
|
+
this.#native.dbGetEdgesJson,
|
|
1336
|
+
stringSlice(indexName),
|
|
1337
|
+
stringSlice(key),
|
|
1338
|
+
stringSlice(edgeType),
|
|
1339
|
+
direction
|
|
1340
|
+
);
|
|
1341
|
+
}
|
|
1342
|
+
async edges(indexName, key, edgeType, direction) {
|
|
1343
|
+
return parseJson(await this.edgesRaw(indexName, key, edgeType, direction));
|
|
1344
|
+
}
|
|
1345
|
+
neighborsRaw(indexName, key, edgeType, direction) {
|
|
1346
|
+
return this.#invokeBuffer(
|
|
1347
|
+
this.#native.dbGetNeighborsJson,
|
|
1348
|
+
stringSlice(indexName),
|
|
1349
|
+
stringSlice(key),
|
|
1350
|
+
stringSlice(edgeType),
|
|
1351
|
+
direction
|
|
1352
|
+
);
|
|
1353
|
+
}
|
|
1354
|
+
async neighbors(indexName, key, edgeType, direction) {
|
|
1355
|
+
return parseJson(await this.neighborsRaw(indexName, key, edgeType, direction));
|
|
1356
|
+
}
|
|
1357
|
+
traverseEdgesRaw(request) {
|
|
1358
|
+
return this.#invokeBuffer(this.#native.dbTraverseEdgesJson, jsonSlice(request));
|
|
1359
|
+
}
|
|
1360
|
+
async traverseEdges(request) {
|
|
1361
|
+
return parseJson(await this.traverseEdgesRaw(request));
|
|
1362
|
+
}
|
|
1363
|
+
executeGraphQueriesRaw(request) {
|
|
1364
|
+
return this.#invokeBuffer(this.#native.dbExecuteGraphQueriesJson, jsonSlice(request));
|
|
1365
|
+
}
|
|
1366
|
+
async executeGraphQueries(request) {
|
|
1367
|
+
return parseJson(await this.executeGraphQueriesRaw(request));
|
|
1368
|
+
}
|
|
1369
|
+
findShortestPathRaw(request) {
|
|
1370
|
+
return this.#invokeBuffer(this.#native.dbFindShortestPathJson, jsonSlice(request));
|
|
1371
|
+
}
|
|
1372
|
+
async findShortestPath(request) {
|
|
1373
|
+
return parseJson(await this.findShortestPathRaw(request));
|
|
1374
|
+
}
|
|
1375
|
+
findKShortestPathsRaw(request) {
|
|
1376
|
+
return this.#invokeBuffer(this.#native.dbFindKShortestPathsJson, jsonSlice(request));
|
|
1377
|
+
}
|
|
1378
|
+
async findKShortestPaths(request) {
|
|
1379
|
+
return parseJson(await this.findKShortestPathsRaw(request));
|
|
1380
|
+
}
|
|
1381
|
+
matchPatternRaw(request) {
|
|
1382
|
+
return this.#invokeBuffer(this.#native.dbMatchPatternJson, jsonSlice(request));
|
|
1383
|
+
}
|
|
1384
|
+
async matchPattern(request) {
|
|
1385
|
+
return parseJson(await this.matchPatternRaw(request));
|
|
1386
|
+
}
|
|
1387
|
+
// --- Transactions ---
|
|
1388
|
+
beginTransaction(txnId, timestampNs, participants = []) {
|
|
1389
|
+
return this.#run(async (handle) => {
|
|
1390
|
+
const id = txnIdBytes(txnId);
|
|
1391
|
+
const cParticipants = participants.length ? participants.map(stringSlice) : null;
|
|
1392
|
+
const code = await callAsync(
|
|
1393
|
+
this.#native.dbBeginTransactionWithId,
|
|
1394
|
+
handle,
|
|
1395
|
+
id,
|
|
1396
|
+
timestampNs,
|
|
1397
|
+
cParticipants,
|
|
1398
|
+
participants.length
|
|
1399
|
+
);
|
|
1400
|
+
checkCode(code);
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
writeTransaction(txnId, writes) {
|
|
1404
|
+
return this.#run(async (handle) => {
|
|
1405
|
+
const id = txnIdBytes(txnId);
|
|
1406
|
+
const cWrites = writes.length ? writes.map(toNativeWriteIntent) : null;
|
|
1407
|
+
const code = await callAsync(
|
|
1408
|
+
this.#native.dbWriteTransaction,
|
|
1409
|
+
handle,
|
|
1410
|
+
id,
|
|
1411
|
+
cWrites,
|
|
1412
|
+
writes.length,
|
|
1413
|
+
null,
|
|
1414
|
+
0
|
|
1415
|
+
);
|
|
1416
|
+
checkCode(code);
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
resolveTransaction(txnId, status, commitVersion = 0) {
|
|
1420
|
+
return this.#invokeCode(
|
|
1421
|
+
this.#native.dbResolveIntents,
|
|
1422
|
+
txnIdBytes(txnId),
|
|
1423
|
+
status,
|
|
1424
|
+
commitVersion
|
|
1425
|
+
);
|
|
1426
|
+
}
|
|
1427
|
+
transactionStatus(txnId) {
|
|
1428
|
+
return this.#run(async (handle) => {
|
|
1429
|
+
const id = txnIdBytes(txnId);
|
|
1430
|
+
const out = [0];
|
|
1431
|
+
const code = await callAsync(this.#native.dbGetTransactionStatus, handle, id, out);
|
|
1432
|
+
checkCode(code);
|
|
1433
|
+
return out[0];
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
commitVersion(txnId) {
|
|
1437
|
+
return this.#run(async (handle) => {
|
|
1438
|
+
const id = txnIdBytes(txnId);
|
|
1439
|
+
const out = [0];
|
|
1440
|
+
const code = await callAsync(this.#native.dbGetCommitVersion, handle, id, out);
|
|
1441
|
+
checkCode(code);
|
|
1442
|
+
return BigInt(out[0] ?? 0);
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
};
|
|
1446
|
+
var finalizationRegistry = new FinalizationRegistry(
|
|
1447
|
+
({ native, handle }) => {
|
|
1448
|
+
if (handle != null) {
|
|
1449
|
+
try {
|
|
1450
|
+
native.dbClose(handle);
|
|
1451
|
+
} catch {
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
);
|
|
1456
|
+
async function writeFileAtomically(path, data, mode = 384) {
|
|
1457
|
+
const dir = dirname2(path);
|
|
1458
|
+
const tmpPath = join2(
|
|
1459
|
+
dir,
|
|
1460
|
+
`.${basename(path)}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`
|
|
1461
|
+
);
|
|
1462
|
+
const handle = await fsp.open(tmpPath, "w", mode);
|
|
1463
|
+
try {
|
|
1464
|
+
await handle.writeFile(data);
|
|
1465
|
+
await handle.sync();
|
|
1466
|
+
} finally {
|
|
1467
|
+
await handle.close();
|
|
1468
|
+
}
|
|
1469
|
+
await fsp.rename(tmpPath, path);
|
|
1470
|
+
}
|
|
1471
|
+
async function openOrCreate(path, opts, create2) {
|
|
1472
|
+
validateAbi();
|
|
1473
|
+
const native = loadNative();
|
|
1474
|
+
const options = buildOpenOptionsStruct(native, opts);
|
|
1475
|
+
const outHandle = [null];
|
|
1476
|
+
const fn = create2 ? native.dbCreateWithOptions : native.dbOpenWithOptions;
|
|
1477
|
+
const code = await callAsync(fn, path, options, outHandle);
|
|
1478
|
+
checkCode(code);
|
|
1479
|
+
return new Database(native, outHandle[0]);
|
|
1480
|
+
}
|
|
1481
|
+
function open2(path) {
|
|
1482
|
+
return openWithOptions(path, { mode: 0 /* Writer */, profile: 0 /* Native */ });
|
|
1483
|
+
}
|
|
1484
|
+
function create(path) {
|
|
1485
|
+
return createWithOptions(path, { mode: 0 /* Writer */, profile: 0 /* Native */ });
|
|
1486
|
+
}
|
|
1487
|
+
function openReadonly(path) {
|
|
1488
|
+
return openWithOptions(path, { mode: 1 /* Readonly */, profile: 0 /* Native */ });
|
|
1489
|
+
}
|
|
1490
|
+
function openStatusOnly(path) {
|
|
1491
|
+
return openWithOptions(path, { mode: 2 /* StatusOnly */, profile: 0 /* Native */ });
|
|
1492
|
+
}
|
|
1493
|
+
function openWithOptions(path, options = {}) {
|
|
1494
|
+
return openOrCreate(path, options, false);
|
|
1495
|
+
}
|
|
1496
|
+
function createWithOptions(path, options = {}) {
|
|
1497
|
+
return openOrCreate(path, options, true);
|
|
1498
|
+
}
|
|
1499
|
+
async function openHosted(path) {
|
|
1500
|
+
validateAbi();
|
|
1501
|
+
const native = loadNative();
|
|
1502
|
+
const outHandle = [null];
|
|
1503
|
+
const code = await callAsync(native.liteOpenHosted, path, outHandle);
|
|
1504
|
+
checkCode(code);
|
|
1505
|
+
return new Database(native, outHandle[0]);
|
|
1506
|
+
}
|
|
1507
|
+
async function createHosted(path) {
|
|
1508
|
+
validateAbi();
|
|
1509
|
+
const native = loadNative();
|
|
1510
|
+
const outHandle = [null];
|
|
1511
|
+
const code = await callAsync(native.liteCreateHosted, path, outHandle);
|
|
1512
|
+
checkCode(code);
|
|
1513
|
+
return new Database(native, outHandle[0]);
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
// src/files.ts
|
|
1517
|
+
function restoreOpenOptions(native, storage) {
|
|
1518
|
+
const options = {};
|
|
1519
|
+
checkCode(native.openOptionsInit(options));
|
|
1520
|
+
options.storage_kind = storageKind(storage);
|
|
1521
|
+
return options;
|
|
1522
|
+
}
|
|
1523
|
+
async function checkFileRaw(path) {
|
|
1524
|
+
validateAbi();
|
|
1525
|
+
const native = loadNative();
|
|
1526
|
+
const out = newBufferOut();
|
|
1527
|
+
const code = await callAsync(native.liteCheckFileJson, path, out);
|
|
1528
|
+
checkCode(code);
|
|
1529
|
+
return takeBuffer(native, out);
|
|
1530
|
+
}
|
|
1531
|
+
async function checkFile(path) {
|
|
1532
|
+
return parseJson(await checkFileRaw(path));
|
|
1533
|
+
}
|
|
1534
|
+
async function copyStableSnapshotFileRaw(srcPath, destPath, replace) {
|
|
1535
|
+
if (!srcPath.endsWith(".aflite") || !destPath.endsWith(".aflite")) {
|
|
1536
|
+
throw new InvalidArgumentError("srcPath and destPath must end with .aflite");
|
|
1537
|
+
}
|
|
1538
|
+
const native = loadNative();
|
|
1539
|
+
const out = newBufferOut();
|
|
1540
|
+
const code = await callAsync(
|
|
1541
|
+
native.liteCopyStableSnapshotFileJson,
|
|
1542
|
+
srcPath,
|
|
1543
|
+
destPath,
|
|
1544
|
+
replace,
|
|
1545
|
+
out
|
|
1546
|
+
);
|
|
1547
|
+
checkCode(code);
|
|
1548
|
+
return takeBuffer(native, out);
|
|
1549
|
+
}
|
|
1550
|
+
async function copyStableSnapshotFile(srcPath, destPath, replace) {
|
|
1551
|
+
return parseJson(
|
|
1552
|
+
await copyStableSnapshotFileRaw(srcPath, destPath, replace)
|
|
1553
|
+
);
|
|
1554
|
+
}
|
|
1555
|
+
async function restore(path, backup, opts = {}) {
|
|
1556
|
+
if ((opts.storage ?? 0 /* Lite */) === 0 /* Lite */ && !path.endsWith(".aflite")) {
|
|
1557
|
+
throw new InvalidArgumentError("path must end with .aflite for Storage.Lite");
|
|
1558
|
+
}
|
|
1559
|
+
if (backup.length === 0) {
|
|
1560
|
+
throw new InvalidArgumentError("backup must be non-empty");
|
|
1561
|
+
}
|
|
1562
|
+
const native = loadNative();
|
|
1563
|
+
const options = restoreOpenOptions(native, opts.storage);
|
|
1564
|
+
const out = newBufferOut();
|
|
1565
|
+
const code = await callAsync(
|
|
1566
|
+
native.restoreBackupJson,
|
|
1567
|
+
path,
|
|
1568
|
+
options,
|
|
1569
|
+
sliceOf(toRawBytes(backup)),
|
|
1570
|
+
Boolean(opts.replace),
|
|
1571
|
+
out
|
|
1572
|
+
);
|
|
1573
|
+
checkCode(code);
|
|
1574
|
+
takeBuffer(native, out);
|
|
1575
|
+
}
|
|
1576
|
+
async function restoreFile(path, backupPath, opts = {}) {
|
|
1577
|
+
if (!backupPath.endsWith(".afb")) {
|
|
1578
|
+
throw new InvalidArgumentError("backupPath must end with .afb");
|
|
1579
|
+
}
|
|
1580
|
+
if ((opts.storage ?? 0 /* Lite */) === 0 /* Lite */ && !path.endsWith(".aflite")) {
|
|
1581
|
+
throw new InvalidArgumentError("path must end with .aflite for Storage.Lite");
|
|
1582
|
+
}
|
|
1583
|
+
const native = loadNative();
|
|
1584
|
+
const options = restoreOpenOptions(native, opts.storage);
|
|
1585
|
+
const out = newBufferOut();
|
|
1586
|
+
const code = await callAsync(
|
|
1587
|
+
native.restoreBackupFileJson,
|
|
1588
|
+
path,
|
|
1589
|
+
options,
|
|
1590
|
+
backupPath,
|
|
1591
|
+
Boolean(opts.replace),
|
|
1592
|
+
out
|
|
1593
|
+
);
|
|
1594
|
+
checkCode(code);
|
|
1595
|
+
takeBuffer(native, out);
|
|
1596
|
+
}
|
|
1597
|
+
async function decodeArtifactIdRaw(artifactIdBase64) {
|
|
1598
|
+
const native = loadNative();
|
|
1599
|
+
const out = newBufferOut();
|
|
1600
|
+
const code = await callAsync(native.decodeArtifactIdJson, stringSlice(artifactIdBase64), out);
|
|
1601
|
+
checkCode(code);
|
|
1602
|
+
return takeBuffer(native, out);
|
|
1603
|
+
}
|
|
1604
|
+
async function decodeArtifactId(artifactIdBase64) {
|
|
1605
|
+
return parseJson(await decodeArtifactIdRaw(artifactIdBase64));
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
// src/inference.ts
|
|
1609
|
+
import koffi4 from "koffi";
|
|
1610
|
+
function buildInferenceOptionsStruct(native, opts) {
|
|
1611
|
+
const options = {};
|
|
1612
|
+
checkCode(native.inferenceOptionsInit(options));
|
|
1613
|
+
options.models_dir = stringSlice(opts.modelsDir ?? "");
|
|
1614
|
+
options.host_budget_mb = opts.hostBudgetMb ?? 0;
|
|
1615
|
+
options.backend_budget_mb = opts.backendBudgetMb ?? 0;
|
|
1616
|
+
options.process_memory_budget_mb = opts.processMemoryBudgetMb ?? 0;
|
|
1617
|
+
options.combined_budget_mb = opts.combinedBudgetMb ?? 0;
|
|
1618
|
+
options.kv_budget_mb = opts.kvBudgetMb ?? 0;
|
|
1619
|
+
options.scratch_budget_mb = opts.scratchBudgetMb ?? 0;
|
|
1620
|
+
options.call_timeout_ms = opts.callTimeoutMs ?? 0;
|
|
1621
|
+
return options;
|
|
1622
|
+
}
|
|
1623
|
+
function errorFromResponseBody(code, body) {
|
|
1624
|
+
let parsed;
|
|
1625
|
+
if (body.length > 0) {
|
|
1626
|
+
try {
|
|
1627
|
+
parsed = JSON.parse(body.toString("utf8"));
|
|
1628
|
+
} catch {
|
|
1629
|
+
parsed = void 0;
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
let message;
|
|
1633
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1634
|
+
const b = parsed;
|
|
1635
|
+
const errPart = typeof b.error === "string" ? b.error : void 0;
|
|
1636
|
+
const msgPart = typeof b.message === "string" ? b.message : void 0;
|
|
1637
|
+
message = [errPart, msgPart].filter((s) => Boolean(s)).join(": ") || void 0;
|
|
1638
|
+
}
|
|
1639
|
+
const err = errorFromCode(code, message);
|
|
1640
|
+
err.body = parsed;
|
|
1641
|
+
return err;
|
|
1642
|
+
}
|
|
1643
|
+
function decodeSliceBytes(slice) {
|
|
1644
|
+
if (!slice || slice.ptr == null) {
|
|
1645
|
+
return Buffer.alloc(0);
|
|
1646
|
+
}
|
|
1647
|
+
const len = Number(slice.len ?? 0);
|
|
1648
|
+
if (len === 0) {
|
|
1649
|
+
return Buffer.alloc(0);
|
|
1650
|
+
}
|
|
1651
|
+
const view = koffi4.decode(slice.ptr, "uint8_t", len);
|
|
1652
|
+
return Buffer.from(view);
|
|
1653
|
+
}
|
|
1654
|
+
function decodeSliceUtf8(slice) {
|
|
1655
|
+
return decodeSliceBytes(slice).toString("utf8");
|
|
1656
|
+
}
|
|
1657
|
+
function toPullProgress(decoded) {
|
|
1658
|
+
return {
|
|
1659
|
+
model: decodeSliceUtf8(decoded.model),
|
|
1660
|
+
file: decodeSliceUtf8(decoded.file),
|
|
1661
|
+
bytesDownloaded: BigInt(decoded.bytes_downloaded ?? 0),
|
|
1662
|
+
totalBytes: BigInt(decoded.total_bytes ?? 0),
|
|
1663
|
+
filesDone: BigInt(decoded.files_done ?? 0),
|
|
1664
|
+
filesTotal: BigInt(decoded.files_total ?? 0),
|
|
1665
|
+
cached: Boolean(decoded.cached)
|
|
1666
|
+
};
|
|
1667
|
+
}
|
|
1668
|
+
var Inference = class _Inference {
|
|
1669
|
+
#native;
|
|
1670
|
+
#handle;
|
|
1671
|
+
#state = "open";
|
|
1672
|
+
#pending = /* @__PURE__ */ new Set();
|
|
1673
|
+
#closeTask;
|
|
1674
|
+
#finalizerToken = {};
|
|
1675
|
+
/** @internal use Inference.open() instead of the constructor. */
|
|
1676
|
+
constructor(native, handle) {
|
|
1677
|
+
this.#native = native;
|
|
1678
|
+
this.#handle = handle;
|
|
1679
|
+
inferenceFinalizationRegistry.register(this, { native, handle }, this.#finalizerToken);
|
|
1680
|
+
}
|
|
1681
|
+
/** Starts the embedded inference runtime with no database. Returns UnsupportedError if this build does not link the inference runtime or it cannot start. */
|
|
1682
|
+
static async open(options = {}) {
|
|
1683
|
+
validateAbi();
|
|
1684
|
+
validateInferenceAbi();
|
|
1685
|
+
const native = loadNative();
|
|
1686
|
+
const optsStruct = buildInferenceOptionsStruct(native, options);
|
|
1687
|
+
const outHandle = [null];
|
|
1688
|
+
const code = await callAsync(native.inferenceOpen, optsStruct, outHandle);
|
|
1689
|
+
checkCode(code);
|
|
1690
|
+
return new _Inference(native, outHandle[0]);
|
|
1691
|
+
}
|
|
1692
|
+
#run(op) {
|
|
1693
|
+
if (this.#state !== "open") {
|
|
1694
|
+
return Promise.reject(new InvalidArgumentError("inference handle is closed"));
|
|
1695
|
+
}
|
|
1696
|
+
const handle = this.#handle;
|
|
1697
|
+
const promise = op(handle);
|
|
1698
|
+
this.#pending.add(promise);
|
|
1699
|
+
const cleanup = () => this.#pending.delete(promise);
|
|
1700
|
+
promise.then(cleanup, cleanup);
|
|
1701
|
+
return promise;
|
|
1702
|
+
}
|
|
1703
|
+
#track(promise) {
|
|
1704
|
+
this.#pending.add(promise);
|
|
1705
|
+
const cleanup = () => this.#pending.delete(promise);
|
|
1706
|
+
promise.then(cleanup, cleanup);
|
|
1707
|
+
return promise;
|
|
1708
|
+
}
|
|
1709
|
+
// biome-ignore lint/suspicious/noExplicitAny: koffi function signatures vary per call site
|
|
1710
|
+
#invokeJson(fn, request) {
|
|
1711
|
+
return this.#run(async (handle) => {
|
|
1712
|
+
const out = newBufferOut();
|
|
1713
|
+
const code = await callAsync(fn, handle, jsonSlice(request), out);
|
|
1714
|
+
const body = takeBuffer(this.#native, out);
|
|
1715
|
+
if (code !== 0 /* OK */) {
|
|
1716
|
+
throw errorFromResponseBody(code, body);
|
|
1717
|
+
}
|
|
1718
|
+
return body;
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
/** Idempotent; waits for in-flight calls before freeing the native handle. Calls made after close() rejects with InvalidArgumentError. */
|
|
1722
|
+
async close() {
|
|
1723
|
+
if (this.#state === "closed") return;
|
|
1724
|
+
if (this.#state === "closing") {
|
|
1725
|
+
await this.#closeTask;
|
|
1726
|
+
return;
|
|
1727
|
+
}
|
|
1728
|
+
this.#state = "closing";
|
|
1729
|
+
inferenceFinalizationRegistry.unregister(this.#finalizerToken);
|
|
1730
|
+
const handle = this.#handle;
|
|
1731
|
+
this.#closeTask = (async () => {
|
|
1732
|
+
while (this.#pending.size > 0) {
|
|
1733
|
+
await Promise.allSettled([...this.#pending]);
|
|
1734
|
+
}
|
|
1735
|
+
if (handle != null) {
|
|
1736
|
+
await callAsync(this.#native.inferenceClose, handle);
|
|
1737
|
+
}
|
|
1738
|
+
this.#handle = null;
|
|
1739
|
+
this.#state = "closed";
|
|
1740
|
+
})();
|
|
1741
|
+
await this.#closeTask;
|
|
1742
|
+
}
|
|
1743
|
+
async [Symbol.asyncDispose]() {
|
|
1744
|
+
await this.close();
|
|
1745
|
+
}
|
|
1746
|
+
// --- JSON calls (POST /ai/v1/<route>) ---
|
|
1747
|
+
embedRaw(request) {
|
|
1748
|
+
return this.#invokeJson(this.#native.inferenceEmbedJson, request);
|
|
1749
|
+
}
|
|
1750
|
+
async embed(request) {
|
|
1751
|
+
return parseJson(await this.embedRaw(request));
|
|
1752
|
+
}
|
|
1753
|
+
rerankRaw(request) {
|
|
1754
|
+
return this.#invokeJson(this.#native.inferenceRerankJson, request);
|
|
1755
|
+
}
|
|
1756
|
+
async rerank(request) {
|
|
1757
|
+
return parseJson(await this.rerankRaw(request));
|
|
1758
|
+
}
|
|
1759
|
+
chunkRaw(request) {
|
|
1760
|
+
return this.#invokeJson(this.#native.inferenceChunkJson, request);
|
|
1761
|
+
}
|
|
1762
|
+
async chunk(request) {
|
|
1763
|
+
return parseJson(await this.chunkRaw(request));
|
|
1764
|
+
}
|
|
1765
|
+
/** A generate request with "stream": true fails with InvalidArgumentError; responses are always complete. Use generateStream() to stream. */
|
|
1766
|
+
generateRaw(request) {
|
|
1767
|
+
return this.#invokeJson(this.#native.inferenceGenerateJson, request);
|
|
1768
|
+
}
|
|
1769
|
+
async generate(request) {
|
|
1770
|
+
return parseJson(await this.generateRaw(request));
|
|
1771
|
+
}
|
|
1772
|
+
/**
|
|
1773
|
+
* Streams a generate request (antfly_inference_generate_stream_json): the
|
|
1774
|
+
* same request body as generate(), with "stream" set for you. onChunk is
|
|
1775
|
+
* called synchronously, on the calling thread, once per streamed chunk
|
|
1776
|
+
* (a parsed "chat.completion.chunk" JSON object), as the model produces
|
|
1777
|
+
* tokens.
|
|
1778
|
+
*
|
|
1779
|
+
* Returning `false` from onChunk stops generation early; the call then
|
|
1780
|
+
* rejects with CancelledError. A thrown error also stops generation and
|
|
1781
|
+
* is rethrown from this call (generation does not continue in the
|
|
1782
|
+
* background). generateStream() runs synchronously on the JS thread and
|
|
1783
|
+
* blocks the event loop for its duration -- see the class docstring for
|
|
1784
|
+
* why (the same koffi callback-threading constraint as pull()); this is
|
|
1785
|
+
* the reason this binding offers a callback, not an async iterator.
|
|
1786
|
+
*
|
|
1787
|
+
* A request rejected before generation starts (e.g. a missing model)
|
|
1788
|
+
* rejects the same way generate() does, with the JSON error body on
|
|
1789
|
+
* `.body`. A failure mid-stream rejects InternalError with
|
|
1790
|
+
* `.body.error === "STREAM_FAILED"`.
|
|
1791
|
+
*/
|
|
1792
|
+
generateStreamRaw(request, onChunk) {
|
|
1793
|
+
if (this.#state !== "open") {
|
|
1794
|
+
return Promise.reject(new InvalidArgumentError("inference handle is closed"));
|
|
1795
|
+
}
|
|
1796
|
+
const handle = this.#handle;
|
|
1797
|
+
const native = this.#native;
|
|
1798
|
+
const run = () => {
|
|
1799
|
+
let callbackError;
|
|
1800
|
+
let callbackThrew = false;
|
|
1801
|
+
const callbackPtr = koffi4.register(
|
|
1802
|
+
(_context, chunk) => {
|
|
1803
|
+
try {
|
|
1804
|
+
return onChunk(decodeSliceBytes(chunk)) !== false;
|
|
1805
|
+
} catch (err) {
|
|
1806
|
+
callbackThrew = true;
|
|
1807
|
+
callbackError = err;
|
|
1808
|
+
return false;
|
|
1809
|
+
}
|
|
1810
|
+
},
|
|
1811
|
+
PAntflyInferenceStreamFn
|
|
1812
|
+
);
|
|
1813
|
+
try {
|
|
1814
|
+
const out = newBufferOut();
|
|
1815
|
+
const code = native.inferenceGenerateStreamJson(
|
|
1816
|
+
handle,
|
|
1817
|
+
jsonSlice(request),
|
|
1818
|
+
callbackPtr,
|
|
1819
|
+
null,
|
|
1820
|
+
out
|
|
1821
|
+
);
|
|
1822
|
+
const body = takeBuffer(native, out);
|
|
1823
|
+
if (callbackThrew) {
|
|
1824
|
+
throw callbackError;
|
|
1825
|
+
}
|
|
1826
|
+
if (code !== 0 /* OK */) {
|
|
1827
|
+
throw errorFromResponseBody(code, body);
|
|
1828
|
+
}
|
|
1829
|
+
return body;
|
|
1830
|
+
} finally {
|
|
1831
|
+
koffi4.unregister(callbackPtr);
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1834
|
+
return this.#track(Promise.resolve().then(run));
|
|
1835
|
+
}
|
|
1836
|
+
async generateStream(request, onChunk) {
|
|
1837
|
+
return parseJson(
|
|
1838
|
+
await this.generateStreamRaw(request, (chunkJson) => onChunk(parseJson(chunkJson)))
|
|
1839
|
+
);
|
|
1840
|
+
}
|
|
1841
|
+
/** Up to 128 non-streaming generate requests in one call; per-item failures are reported in the response. */
|
|
1842
|
+
generateBatchRaw(request) {
|
|
1843
|
+
return this.#invokeJson(this.#native.inferenceGenerateBatchJson, request);
|
|
1844
|
+
}
|
|
1845
|
+
async generateBatch(request) {
|
|
1846
|
+
return parseJson(await this.generateBatchRaw(request));
|
|
1847
|
+
}
|
|
1848
|
+
rewriteRaw(request) {
|
|
1849
|
+
return this.#invokeJson(this.#native.inferenceRewriteJson, request);
|
|
1850
|
+
}
|
|
1851
|
+
async rewrite(request) {
|
|
1852
|
+
return parseJson(await this.rewriteRaw(request));
|
|
1853
|
+
}
|
|
1854
|
+
/** Named choice, ordinal score, and Boolean questions using DecideRequest JSON. */
|
|
1855
|
+
decideRaw(request) {
|
|
1856
|
+
return this.#invokeJson(this.#native.inferenceDecideJson, request);
|
|
1857
|
+
}
|
|
1858
|
+
/** Parsed DecideResponse from the same contract as POST /ai/v1/decisions. */
|
|
1859
|
+
async decide(request) {
|
|
1860
|
+
return parseJson(await this.decideRaw(request));
|
|
1861
|
+
}
|
|
1862
|
+
extractRaw(request) {
|
|
1863
|
+
return this.#invokeJson(this.#native.inferenceExtractJson, request);
|
|
1864
|
+
}
|
|
1865
|
+
async extract(request) {
|
|
1866
|
+
return parseJson(await this.extractRaw(request));
|
|
1867
|
+
}
|
|
1868
|
+
/** OCR. */
|
|
1869
|
+
readRaw(request) {
|
|
1870
|
+
return this.#invokeJson(this.#native.inferenceReadJson, request);
|
|
1871
|
+
}
|
|
1872
|
+
async read(request) {
|
|
1873
|
+
return parseJson(await this.readRaw(request));
|
|
1874
|
+
}
|
|
1875
|
+
transcribeRaw(request) {
|
|
1876
|
+
return this.#invokeJson(this.#native.inferenceTranscribeJson, request);
|
|
1877
|
+
}
|
|
1878
|
+
async transcribe(request) {
|
|
1879
|
+
return parseJson(await this.transcribeRaw(request));
|
|
1880
|
+
}
|
|
1881
|
+
/** The installed models, as returned by GET /ai/v1/models. */
|
|
1882
|
+
listModelsRaw() {
|
|
1883
|
+
return this.#run(async (handle) => {
|
|
1884
|
+
const out = newBufferOut();
|
|
1885
|
+
const code = await callAsync(this.#native.inferenceListModelsJson, handle, out);
|
|
1886
|
+
const body = takeBuffer(this.#native, out);
|
|
1887
|
+
if (code !== 0 /* OK */) {
|
|
1888
|
+
throw errorFromResponseBody(code, body);
|
|
1889
|
+
}
|
|
1890
|
+
return body;
|
|
1891
|
+
});
|
|
1892
|
+
}
|
|
1893
|
+
async listModels() {
|
|
1894
|
+
return parseJson(await this.listModelsRaw());
|
|
1895
|
+
}
|
|
1896
|
+
/**
|
|
1897
|
+
* Downloads a model from the Hugging Face Hub into the handle's models
|
|
1898
|
+
* directory, like `antfly inference pull`. request: {"model": "owner/name[:variant]",
|
|
1899
|
+
* required; "variants": [...]; "token": "..." (default $HF_TOKEN);
|
|
1900
|
+
* "tasks"/"capabilities" to override the model manifest; "projector":
|
|
1901
|
+
* "auto" | "none" | "match"; "max_artifact_bytes"/"max_model_bytes"}.
|
|
1902
|
+
*
|
|
1903
|
+
* onProgress (optional) is called synchronously, on the calling thread,
|
|
1904
|
+
* as each file starts, every 16 MiB, and as it completes; see the class
|
|
1905
|
+
* docstring for why pull() itself runs synchronously (blocking the event
|
|
1906
|
+
* loop) rather than on koffi's async worker pool. Returning `false` from
|
|
1907
|
+
* onProgress cancels the pull -- the call then rejects with
|
|
1908
|
+
* CancelledError, and completed files stay staged, so a later pull()
|
|
1909
|
+
* for the same model resumes rather than restarts. A thrown error also
|
|
1910
|
+
* cancels the pull and is rethrown from this call.
|
|
1911
|
+
*
|
|
1912
|
+
* `signal` (optional) is a best-effort, honestly-limited cancellation
|
|
1913
|
+
* knob: because pull() blocks the JS thread for its whole duration,
|
|
1914
|
+
* there is no way to interrupt it asynchronously from the outside the
|
|
1915
|
+
* way `fetch(url, { signal })` can. An already-aborted signal rejects
|
|
1916
|
+
* immediately without starting the pull; otherwise the signal is polled
|
|
1917
|
+
* only at the same report points as onProgress (each file start, every
|
|
1918
|
+
* 16 MiB, file end) -- an abort in between those points is not observed
|
|
1919
|
+
* until the next one. Prefer returning `false` from onProgress when you
|
|
1920
|
+
* need precise control.
|
|
1921
|
+
*
|
|
1922
|
+
* A model missing from the hub rejects with NotFoundError, a bad request
|
|
1923
|
+
* or a model over the size limits with InvalidArgumentError, and a
|
|
1924
|
+
* network or hub failure with BusyError. close() waits for a pull in
|
|
1925
|
+
* progress.
|
|
1926
|
+
*/
|
|
1927
|
+
pullRaw(request, onProgress, signal) {
|
|
1928
|
+
if (this.#state !== "open") {
|
|
1929
|
+
return Promise.reject(new InvalidArgumentError("inference handle is closed"));
|
|
1930
|
+
}
|
|
1931
|
+
if (signal?.aborted) {
|
|
1932
|
+
return Promise.reject(cancelledBySignal(signal));
|
|
1933
|
+
}
|
|
1934
|
+
const handle = this.#handle;
|
|
1935
|
+
const native = this.#native;
|
|
1936
|
+
const run = () => {
|
|
1937
|
+
let callbackPtr;
|
|
1938
|
+
let callbackError;
|
|
1939
|
+
let callbackThrew = false;
|
|
1940
|
+
if (onProgress || signal) {
|
|
1941
|
+
callbackPtr = koffi4.register((_context, progressPtr) => {
|
|
1942
|
+
try {
|
|
1943
|
+
if (signal?.aborted) {
|
|
1944
|
+
return false;
|
|
1945
|
+
}
|
|
1946
|
+
const decoded = koffi4.decode(
|
|
1947
|
+
progressPtr,
|
|
1948
|
+
AntflyInferencePullProgress
|
|
1949
|
+
);
|
|
1950
|
+
return onProgress?.(toPullProgress(decoded)) !== false;
|
|
1951
|
+
} catch (err) {
|
|
1952
|
+
callbackThrew = true;
|
|
1953
|
+
callbackError = err;
|
|
1954
|
+
return false;
|
|
1955
|
+
}
|
|
1956
|
+
}, PAntflyInferencePullProgressFn);
|
|
1957
|
+
}
|
|
1958
|
+
try {
|
|
1959
|
+
const out = newBufferOut();
|
|
1960
|
+
const code = native.inferencePullJson(
|
|
1961
|
+
handle,
|
|
1962
|
+
jsonSlice(request),
|
|
1963
|
+
callbackPtr ?? null,
|
|
1964
|
+
null,
|
|
1965
|
+
out
|
|
1966
|
+
);
|
|
1967
|
+
const body = takeBuffer(native, out);
|
|
1968
|
+
if (callbackThrew) {
|
|
1969
|
+
throw callbackError;
|
|
1970
|
+
}
|
|
1971
|
+
if (code !== 0 /* OK */) {
|
|
1972
|
+
throw errorFromResponseBody(code, body);
|
|
1973
|
+
}
|
|
1974
|
+
return body;
|
|
1975
|
+
} finally {
|
|
1976
|
+
if (callbackPtr !== void 0) {
|
|
1977
|
+
koffi4.unregister(callbackPtr);
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
};
|
|
1981
|
+
return this.#track(Promise.resolve().then(run));
|
|
1982
|
+
}
|
|
1983
|
+
async pull(request, onProgress, signal) {
|
|
1984
|
+
return parseJson(await this.pullRaw(request, onProgress, signal));
|
|
1985
|
+
}
|
|
1986
|
+
};
|
|
1987
|
+
function cancelledBySignal(signal) {
|
|
1988
|
+
const reason = signal.reason;
|
|
1989
|
+
const detail = reason instanceof Error ? reason.message : reason !== void 0 ? String(reason) : void 0;
|
|
1990
|
+
return new CancelledError(
|
|
1991
|
+
detail ? `pull cancelled before it started: ${detail}` : "pull cancelled before it started"
|
|
1992
|
+
);
|
|
1993
|
+
}
|
|
1994
|
+
var inferenceFinalizationRegistry = new FinalizationRegistry(({ native, handle }) => {
|
|
1995
|
+
if (handle != null) {
|
|
1996
|
+
try {
|
|
1997
|
+
native.inferenceClose(handle);
|
|
1998
|
+
} catch {
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
});
|
|
2002
|
+
export {
|
|
2003
|
+
AbiMismatchError,
|
|
2004
|
+
AntflyError,
|
|
2005
|
+
BusyError,
|
|
2006
|
+
CancelledError,
|
|
2007
|
+
Connection,
|
|
2008
|
+
Database,
|
|
2009
|
+
ErrorCode,
|
|
2010
|
+
GraphDirection,
|
|
2011
|
+
Inference,
|
|
2012
|
+
InferenceMode,
|
|
2013
|
+
IntentConflictError,
|
|
2014
|
+
InternalError,
|
|
2015
|
+
InvalidArgumentError,
|
|
2016
|
+
LibraryNotFoundError,
|
|
2017
|
+
NATIVE_STACK_SIZE as MIN_THREAD_STACK_SIZE,
|
|
2018
|
+
NotFoundError,
|
|
2019
|
+
OpenMode,
|
|
2020
|
+
OutcomeUnknownError,
|
|
2021
|
+
Profile,
|
|
2022
|
+
SUPPORTED_ABI_VERSION,
|
|
2023
|
+
SqlError,
|
|
2024
|
+
StalledError,
|
|
2025
|
+
Storage,
|
|
2026
|
+
THREADING_SERIALIZED,
|
|
2027
|
+
TxnNotFoundError,
|
|
2028
|
+
TxnStatus,
|
|
2029
|
+
UnsupportedError,
|
|
2030
|
+
UnsupportedPlatformError,
|
|
2031
|
+
VersionConflictError,
|
|
2032
|
+
abiVersion,
|
|
2033
|
+
checkFile,
|
|
2034
|
+
checkFileRaw,
|
|
2035
|
+
copyStableSnapshotFile,
|
|
2036
|
+
copyStableSnapshotFileRaw,
|
|
2037
|
+
create,
|
|
2038
|
+
createHosted,
|
|
2039
|
+
createWithOptions,
|
|
2040
|
+
decodeArtifactId,
|
|
2041
|
+
decodeArtifactIdRaw,
|
|
2042
|
+
embeddedPlatformPackageName,
|
|
2043
|
+
errorCodeDescription,
|
|
2044
|
+
errorCodeName,
|
|
2045
|
+
open2 as open,
|
|
2046
|
+
openHosted,
|
|
2047
|
+
openReadonly,
|
|
2048
|
+
openStatusOnly,
|
|
2049
|
+
openWithOptions,
|
|
2050
|
+
platformLibraryFileName,
|
|
2051
|
+
resolveLibrary,
|
|
2052
|
+
restore,
|
|
2053
|
+
restoreFile,
|
|
2054
|
+
threadingMode,
|
|
2055
|
+
validateAbi,
|
|
2056
|
+
validateInferenceAbi
|
|
2057
|
+
};
|