@grepai/cli 0.6.8 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2522 -37
- package/index.js.map +23 -7
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -13603,7 +13603,7 @@ var require_process = __commonJS((exports, module2) => {
|
|
|
13603
13603
|
var require_filesystem = __commonJS((exports, module2) => {
|
|
13604
13604
|
var fs2 = __require("fs");
|
|
13605
13605
|
var LDD_PATH = "/usr/bin/ldd";
|
|
13606
|
-
var
|
|
13606
|
+
var readFileSync2 = (path4) => fs2.readFileSync(path4, "utf-8");
|
|
13607
13607
|
var readFile3 = (path4) => new Promise((resolve4, reject) => {
|
|
13608
13608
|
fs2.readFile(path4, "utf-8", (err2, data) => {
|
|
13609
13609
|
if (err2) {
|
|
@@ -13615,7 +13615,7 @@ var require_filesystem = __commonJS((exports, module2) => {
|
|
|
13615
13615
|
});
|
|
13616
13616
|
module2.exports = {
|
|
13617
13617
|
LDD_PATH,
|
|
13618
|
-
readFileSync,
|
|
13618
|
+
readFileSync: readFileSync2,
|
|
13619
13619
|
readFile: readFile3
|
|
13620
13620
|
};
|
|
13621
13621
|
});
|
|
@@ -13624,7 +13624,7 @@ var require_filesystem = __commonJS((exports, module2) => {
|
|
|
13624
13624
|
var require_detect_libc = __commonJS((exports, module2) => {
|
|
13625
13625
|
var childProcess = __require("child_process");
|
|
13626
13626
|
var { isLinux, getReport } = require_process();
|
|
13627
|
-
var { LDD_PATH, readFile: readFile3, readFileSync } = require_filesystem();
|
|
13627
|
+
var { LDD_PATH, readFile: readFile3, readFileSync: readFileSync2 } = require_filesystem();
|
|
13628
13628
|
var cachedFamilyFilesystem;
|
|
13629
13629
|
var cachedVersionFilesystem;
|
|
13630
13630
|
var command = "getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true";
|
|
@@ -13655,14 +13655,14 @@ var require_detect_libc = __commonJS((exports, module2) => {
|
|
|
13655
13655
|
var MUSL = "musl";
|
|
13656
13656
|
var GLIBC_ON_LDD = GLIBC.toUpperCase();
|
|
13657
13657
|
var MUSL_ON_LDD = MUSL.toLowerCase();
|
|
13658
|
-
var
|
|
13658
|
+
var isFileMusl2 = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
|
|
13659
13659
|
var familyFromReport = () => {
|
|
13660
13660
|
const report = getReport();
|
|
13661
13661
|
if (report.header && report.header.glibcVersionRuntime) {
|
|
13662
13662
|
return GLIBC;
|
|
13663
13663
|
}
|
|
13664
13664
|
if (Array.isArray(report.sharedObjects)) {
|
|
13665
|
-
if (report.sharedObjects.some(
|
|
13665
|
+
if (report.sharedObjects.some(isFileMusl2)) {
|
|
13666
13666
|
return MUSL;
|
|
13667
13667
|
}
|
|
13668
13668
|
}
|
|
@@ -13704,7 +13704,7 @@ var require_detect_libc = __commonJS((exports, module2) => {
|
|
|
13704
13704
|
}
|
|
13705
13705
|
cachedFamilyFilesystem = null;
|
|
13706
13706
|
try {
|
|
13707
|
-
const lddContent =
|
|
13707
|
+
const lddContent = readFileSync2(LDD_PATH);
|
|
13708
13708
|
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
|
|
13709
13709
|
} catch (e) {}
|
|
13710
13710
|
return cachedFamilyFilesystem;
|
|
@@ -13759,7 +13759,7 @@ var require_detect_libc = __commonJS((exports, module2) => {
|
|
|
13759
13759
|
}
|
|
13760
13760
|
cachedVersionFilesystem = null;
|
|
13761
13761
|
try {
|
|
13762
|
-
const lddContent =
|
|
13762
|
+
const lddContent = readFileSync2(LDD_PATH);
|
|
13763
13763
|
const versionMatch = lddContent.match(RE_GLIBC_VERSION);
|
|
13764
13764
|
if (versionMatch) {
|
|
13765
13765
|
cachedVersionFilesystem = versionMatch[1];
|
|
@@ -13828,9 +13828,9 @@ var require_detect_libc = __commonJS((exports, module2) => {
|
|
|
13828
13828
|
// ../../node_modules/.bun/libsql@0.4.7/node_modules/libsql/sqlite-error.js
|
|
13829
13829
|
var require_sqlite_error = __commonJS((exports, module2) => {
|
|
13830
13830
|
var descriptor2 = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
|
|
13831
|
-
function
|
|
13832
|
-
if (new.target !==
|
|
13833
|
-
return new
|
|
13831
|
+
function SqliteError2(message, code2, rawCode) {
|
|
13832
|
+
if (new.target !== SqliteError2) {
|
|
13833
|
+
return new SqliteError2(message, code2);
|
|
13834
13834
|
}
|
|
13835
13835
|
if (typeof code2 !== "string") {
|
|
13836
13836
|
throw new TypeError("Expected second argument to be a string");
|
|
@@ -13838,21 +13838,21 @@ var require_sqlite_error = __commonJS((exports, module2) => {
|
|
|
13838
13838
|
Error.call(this, message);
|
|
13839
13839
|
descriptor2.value = "" + message;
|
|
13840
13840
|
Object.defineProperty(this, "message", descriptor2);
|
|
13841
|
-
Error.captureStackTrace(this,
|
|
13841
|
+
Error.captureStackTrace(this, SqliteError2);
|
|
13842
13842
|
this.code = code2;
|
|
13843
13843
|
this.rawCode = rawCode;
|
|
13844
13844
|
}
|
|
13845
|
-
Object.setPrototypeOf(
|
|
13846
|
-
Object.setPrototypeOf(
|
|
13847
|
-
Object.defineProperty(
|
|
13848
|
-
module2.exports =
|
|
13845
|
+
Object.setPrototypeOf(SqliteError2, Error);
|
|
13846
|
+
Object.setPrototypeOf(SqliteError2.prototype, Error.prototype);
|
|
13847
|
+
Object.defineProperty(SqliteError2.prototype, "name", descriptor2);
|
|
13848
|
+
module2.exports = SqliteError2;
|
|
13849
13849
|
});
|
|
13850
13850
|
|
|
13851
13851
|
// ../../node_modules/.bun/libsql@0.4.7/node_modules/libsql/index.js
|
|
13852
13852
|
var require_libsql = __commonJS((exports, module2) => {
|
|
13853
13853
|
var { currentTarget } = require_dist2();
|
|
13854
13854
|
var { familySync, GLIBC } = require_detect_libc();
|
|
13855
|
-
function
|
|
13855
|
+
function requireNative2() {
|
|
13856
13856
|
let target = currentTarget();
|
|
13857
13857
|
if (familySync() == GLIBC) {
|
|
13858
13858
|
switch (target) {
|
|
@@ -13886,16 +13886,16 @@ var require_libsql = __commonJS((exports, module2) => {
|
|
|
13886
13886
|
statementColumns,
|
|
13887
13887
|
statementSafeIntegers,
|
|
13888
13888
|
rowsNext
|
|
13889
|
-
} =
|
|
13890
|
-
var
|
|
13891
|
-
function
|
|
13889
|
+
} = requireNative2();
|
|
13890
|
+
var SqliteError2 = require_sqlite_error();
|
|
13891
|
+
function convertError2(err2) {
|
|
13892
13892
|
if (err2.libsqlError) {
|
|
13893
|
-
return new
|
|
13893
|
+
return new SqliteError2(err2.message, err2.code, err2.rawCode);
|
|
13894
13894
|
}
|
|
13895
13895
|
return err2;
|
|
13896
13896
|
}
|
|
13897
13897
|
|
|
13898
|
-
class
|
|
13898
|
+
class Database5 {
|
|
13899
13899
|
constructor(path4, opts) {
|
|
13900
13900
|
const encryptionCipher = opts?.encryptionCipher ?? "aes256cbc";
|
|
13901
13901
|
if (opts && opts.syncUrl) {
|
|
@@ -13937,9 +13937,9 @@ var require_libsql = __commonJS((exports, module2) => {
|
|
|
13937
13937
|
prepare(sql) {
|
|
13938
13938
|
try {
|
|
13939
13939
|
const stmt = databasePrepareSync.call(this.db, sql);
|
|
13940
|
-
return new
|
|
13940
|
+
return new Statement4(stmt);
|
|
13941
13941
|
} catch (err2) {
|
|
13942
|
-
throw
|
|
13942
|
+
throw convertError2(err2);
|
|
13943
13943
|
}
|
|
13944
13944
|
}
|
|
13945
13945
|
transaction(fn) {
|
|
@@ -14032,7 +14032,7 @@ var require_libsql = __commonJS((exports, module2) => {
|
|
|
14032
14032
|
try {
|
|
14033
14033
|
databaseExecSync.call(this.db, sql);
|
|
14034
14034
|
} catch (err2) {
|
|
14035
|
-
throw
|
|
14035
|
+
throw convertError2(err2);
|
|
14036
14036
|
}
|
|
14037
14037
|
}
|
|
14038
14038
|
close() {
|
|
@@ -14048,7 +14048,7 @@ var require_libsql = __commonJS((exports, module2) => {
|
|
|
14048
14048
|
}
|
|
14049
14049
|
}
|
|
14050
14050
|
|
|
14051
|
-
class
|
|
14051
|
+
class Statement4 {
|
|
14052
14052
|
constructor(stmt) {
|
|
14053
14053
|
this.stmt = stmt;
|
|
14054
14054
|
}
|
|
@@ -14067,7 +14067,7 @@ var require_libsql = __commonJS((exports, module2) => {
|
|
|
14067
14067
|
return statementRun.call(this.stmt, bindParameters.flat());
|
|
14068
14068
|
}
|
|
14069
14069
|
} catch (err2) {
|
|
14070
|
-
throw
|
|
14070
|
+
throw convertError2(err2);
|
|
14071
14071
|
}
|
|
14072
14072
|
}
|
|
14073
14073
|
get(...bindParameters) {
|
|
@@ -14121,8 +14121,8 @@ var require_libsql = __commonJS((exports, module2) => {
|
|
|
14121
14121
|
return this;
|
|
14122
14122
|
}
|
|
14123
14123
|
}
|
|
14124
|
-
module2.exports =
|
|
14125
|
-
module2.exports.SqliteError =
|
|
14124
|
+
module2.exports = Database5;
|
|
14125
|
+
module2.exports.SqliteError = SqliteError2;
|
|
14126
14126
|
});
|
|
14127
14127
|
|
|
14128
14128
|
// ../../node_modules/.bun/promise-limit@2.7.0/node_modules/promise-limit/index.js
|
|
@@ -17467,10 +17467,10 @@ var require_helper = __commonJS((exports, module2) => {
|
|
|
17467
17467
|
var warnStream = process.stderr;
|
|
17468
17468
|
var S_IRWXG = 56;
|
|
17469
17469
|
var S_IRWXO = 7;
|
|
17470
|
-
var
|
|
17471
|
-
var
|
|
17470
|
+
var S_IFMT2 = 61440;
|
|
17471
|
+
var S_IFREG2 = 32768;
|
|
17472
17472
|
function isRegFile(mode) {
|
|
17473
|
-
return (mode &
|
|
17473
|
+
return (mode & S_IFMT2) == S_IFREG2;
|
|
17474
17474
|
}
|
|
17475
17475
|
var fieldNames = ["host", "port", "database", "user", "password"];
|
|
17476
17476
|
var nrOfFields = fieldNames.length;
|
|
@@ -86746,7 +86746,12 @@ var GrepAiConfig = Struct({
|
|
|
86746
86746
|
}), optional, withDecodingDefault(() => [])),
|
|
86747
86747
|
storage: Storage.pipe(annotations2({
|
|
86748
86748
|
description: "Database backend for storing chunks and embeddings"
|
|
86749
|
-
}))
|
|
86749
|
+
})),
|
|
86750
|
+
experimental__agentFs: Struct({
|
|
86751
|
+
syncMode: Literal2("push", "pull").pipe(optional, withDecodingDefault(() => "pull")),
|
|
86752
|
+
url: String$,
|
|
86753
|
+
authToken: String$
|
|
86754
|
+
}).pipe(optional)
|
|
86750
86755
|
});
|
|
86751
86756
|
|
|
86752
86757
|
// ../core/src/domain/errors.ts
|
|
@@ -101779,8 +101784,2358 @@ function mergeWithinBudgetOrFlush(current, next, config3) {
|
|
|
101779
101784
|
return { current: next, outputToAppend: current };
|
|
101780
101785
|
}
|
|
101781
101786
|
|
|
101782
|
-
// ../core/src/internal/services/codebase-scanner-
|
|
101787
|
+
// ../core/src/internal/services/codebase-scanner-agentfs.ts
|
|
101783
101788
|
import { globSync } from "fs";
|
|
101789
|
+
import { connect as connect2 } from "@tursodatabase/sync";
|
|
101790
|
+
|
|
101791
|
+
// ../../node_modules/.bun/@tursodatabase+database-common@0.4.4/node_modules/@tursodatabase/database-common/dist/bind.js
|
|
101792
|
+
function bindParams(stmt, params) {
|
|
101793
|
+
const len = params?.length;
|
|
101794
|
+
if (len === 0) {
|
|
101795
|
+
return;
|
|
101796
|
+
}
|
|
101797
|
+
if (len === 1) {
|
|
101798
|
+
const param = params[0];
|
|
101799
|
+
if (isPlainObject2(param)) {
|
|
101800
|
+
bindNamedParams(stmt, param);
|
|
101801
|
+
return;
|
|
101802
|
+
}
|
|
101803
|
+
if (Array.isArray(param)) {
|
|
101804
|
+
bindPositionalParams(stmt, [param]);
|
|
101805
|
+
return;
|
|
101806
|
+
}
|
|
101807
|
+
bindValue(stmt, 1, param);
|
|
101808
|
+
return;
|
|
101809
|
+
}
|
|
101810
|
+
bindPositionalParams(stmt, params);
|
|
101811
|
+
}
|
|
101812
|
+
function isPlainObject2(obj) {
|
|
101813
|
+
if (!obj || typeof obj !== "object")
|
|
101814
|
+
return false;
|
|
101815
|
+
const proto25 = Object.getPrototypeOf(obj);
|
|
101816
|
+
return proto25 === Object.prototype || proto25 === null;
|
|
101817
|
+
}
|
|
101818
|
+
function bindNamedParams(stmt, paramObj) {
|
|
101819
|
+
const paramCount = stmt.parameterCount();
|
|
101820
|
+
for (let i2 = 1;i2 <= paramCount; i2++) {
|
|
101821
|
+
const paramName = stmt.parameterName(i2);
|
|
101822
|
+
if (paramName) {
|
|
101823
|
+
const key = paramName.substring(1);
|
|
101824
|
+
const value6 = paramObj[key];
|
|
101825
|
+
if (value6 !== undefined) {
|
|
101826
|
+
bindValue(stmt, i2, value6);
|
|
101827
|
+
}
|
|
101828
|
+
}
|
|
101829
|
+
}
|
|
101830
|
+
}
|
|
101831
|
+
function bindPositionalParams(stmt, params) {
|
|
101832
|
+
let bindIndex = 1;
|
|
101833
|
+
for (let i2 = 0;i2 < params.length; i2++) {
|
|
101834
|
+
const param = params[i2];
|
|
101835
|
+
if (Array.isArray(param)) {
|
|
101836
|
+
for (let j = 0;j < param.length; j++) {
|
|
101837
|
+
bindValue(stmt, bindIndex++, param[j]);
|
|
101838
|
+
}
|
|
101839
|
+
} else {
|
|
101840
|
+
bindValue(stmt, bindIndex++, param);
|
|
101841
|
+
}
|
|
101842
|
+
}
|
|
101843
|
+
}
|
|
101844
|
+
function bindValue(stmt, index, value6) {
|
|
101845
|
+
stmt.bindAt(index, value6);
|
|
101846
|
+
}
|
|
101847
|
+
|
|
101848
|
+
// ../../node_modules/.bun/@tursodatabase+database-common@0.4.4/node_modules/@tursodatabase/database-common/dist/sqlite-error.js
|
|
101849
|
+
class SqliteError extends Error {
|
|
101850
|
+
name;
|
|
101851
|
+
code;
|
|
101852
|
+
rawCode;
|
|
101853
|
+
constructor(message, code2, rawCode) {
|
|
101854
|
+
super(message);
|
|
101855
|
+
this.name = "SqliteError";
|
|
101856
|
+
this.code = code2;
|
|
101857
|
+
this.rawCode = rawCode;
|
|
101858
|
+
Error.captureStackTrace(this, SqliteError);
|
|
101859
|
+
}
|
|
101860
|
+
}
|
|
101861
|
+
|
|
101862
|
+
// ../../node_modules/.bun/@tursodatabase+database-common@0.4.4/node_modules/@tursodatabase/database-common/dist/types.js
|
|
101863
|
+
var STEP_ROW = 1;
|
|
101864
|
+
var STEP_DONE = 2;
|
|
101865
|
+
var STEP_IO = 3;
|
|
101866
|
+
|
|
101867
|
+
// ../../node_modules/.bun/@tursodatabase+database-common@0.4.4/node_modules/@tursodatabase/database-common/dist/async-lock.js
|
|
101868
|
+
class AsyncLock {
|
|
101869
|
+
locked;
|
|
101870
|
+
queue;
|
|
101871
|
+
constructor() {
|
|
101872
|
+
this.locked = false;
|
|
101873
|
+
this.queue = [];
|
|
101874
|
+
}
|
|
101875
|
+
async acquire() {
|
|
101876
|
+
if (!this.locked) {
|
|
101877
|
+
this.locked = true;
|
|
101878
|
+
return Promise.resolve();
|
|
101879
|
+
} else {
|
|
101880
|
+
const block = new Promise((resolve4) => {
|
|
101881
|
+
this.queue.push(resolve4);
|
|
101882
|
+
});
|
|
101883
|
+
return block;
|
|
101884
|
+
}
|
|
101885
|
+
}
|
|
101886
|
+
release() {
|
|
101887
|
+
if (this.locked == false) {
|
|
101888
|
+
throw new Error("invalid state: lock was already unlocked");
|
|
101889
|
+
}
|
|
101890
|
+
const item = this.queue.shift();
|
|
101891
|
+
if (item != null) {
|
|
101892
|
+
this.locked = true;
|
|
101893
|
+
item();
|
|
101894
|
+
} else {
|
|
101895
|
+
this.locked = false;
|
|
101896
|
+
}
|
|
101897
|
+
}
|
|
101898
|
+
}
|
|
101899
|
+
|
|
101900
|
+
// ../../node_modules/.bun/@tursodatabase+database-common@0.4.4/node_modules/@tursodatabase/database-common/dist/promise.js
|
|
101901
|
+
var convertibleErrorTypes = { TypeError };
|
|
101902
|
+
var CONVERTIBLE_ERROR_PREFIX = "[TURSO_CONVERT_TYPE]";
|
|
101903
|
+
function convertError(err2) {
|
|
101904
|
+
if ((err2.code ?? "").startsWith(CONVERTIBLE_ERROR_PREFIX)) {
|
|
101905
|
+
return createErrorByName(err2.code.substring(CONVERTIBLE_ERROR_PREFIX.length), err2.message);
|
|
101906
|
+
}
|
|
101907
|
+
return new SqliteError(err2.message, err2.code, err2.rawCode);
|
|
101908
|
+
}
|
|
101909
|
+
function createErrorByName(name21, message) {
|
|
101910
|
+
const ErrorConstructor = convertibleErrorTypes[name21];
|
|
101911
|
+
if (!ErrorConstructor) {
|
|
101912
|
+
throw new Error(`unknown error type ${name21} from Turso`);
|
|
101913
|
+
}
|
|
101914
|
+
return new ErrorConstructor(message);
|
|
101915
|
+
}
|
|
101916
|
+
|
|
101917
|
+
class Database {
|
|
101918
|
+
name;
|
|
101919
|
+
readonly;
|
|
101920
|
+
open;
|
|
101921
|
+
memory;
|
|
101922
|
+
inTransaction;
|
|
101923
|
+
db;
|
|
101924
|
+
ioStep;
|
|
101925
|
+
execLock;
|
|
101926
|
+
_inTransaction = false;
|
|
101927
|
+
connected = false;
|
|
101928
|
+
constructor(db, ioStep) {
|
|
101929
|
+
this.db = db;
|
|
101930
|
+
this.execLock = new AsyncLock;
|
|
101931
|
+
this.ioStep = ioStep ?? (async () => {});
|
|
101932
|
+
Object.defineProperties(this, {
|
|
101933
|
+
name: { get: () => this.db.path },
|
|
101934
|
+
readonly: { get: () => this.db.readonly },
|
|
101935
|
+
open: { get: () => this.db.open },
|
|
101936
|
+
memory: { get: () => this.db.memory },
|
|
101937
|
+
inTransaction: { get: () => this._inTransaction }
|
|
101938
|
+
});
|
|
101939
|
+
}
|
|
101940
|
+
async connect() {
|
|
101941
|
+
if (this.connected) {
|
|
101942
|
+
return;
|
|
101943
|
+
}
|
|
101944
|
+
await this.db.connectAsync();
|
|
101945
|
+
this.connected = true;
|
|
101946
|
+
}
|
|
101947
|
+
prepare(sql) {
|
|
101948
|
+
if (!sql) {
|
|
101949
|
+
throw new RangeError("The supplied SQL string contains no statements");
|
|
101950
|
+
}
|
|
101951
|
+
try {
|
|
101952
|
+
if (this.connected) {
|
|
101953
|
+
return new Statement(maybeValue(this.db.prepare(sql)), this.db, this.execLock, this.ioStep);
|
|
101954
|
+
} else {
|
|
101955
|
+
return new Statement(maybePromise(() => this.connect().then(() => this.db.prepare(sql))), this.db, this.execLock, this.ioStep);
|
|
101956
|
+
}
|
|
101957
|
+
} catch (err2) {
|
|
101958
|
+
throw convertError(err2);
|
|
101959
|
+
}
|
|
101960
|
+
}
|
|
101961
|
+
transaction(fn) {
|
|
101962
|
+
if (typeof fn !== "function")
|
|
101963
|
+
throw new TypeError("Expected first argument to be a function");
|
|
101964
|
+
const db = this;
|
|
101965
|
+
const wrapTxn = (mode) => {
|
|
101966
|
+
return async (...bindParameters) => {
|
|
101967
|
+
await db.exec("BEGIN " + mode);
|
|
101968
|
+
db._inTransaction = true;
|
|
101969
|
+
try {
|
|
101970
|
+
const result = await fn(...bindParameters);
|
|
101971
|
+
await db.exec("COMMIT");
|
|
101972
|
+
db._inTransaction = false;
|
|
101973
|
+
return result;
|
|
101974
|
+
} catch (err2) {
|
|
101975
|
+
await db.exec("ROLLBACK");
|
|
101976
|
+
db._inTransaction = false;
|
|
101977
|
+
throw err2;
|
|
101978
|
+
}
|
|
101979
|
+
};
|
|
101980
|
+
};
|
|
101981
|
+
const properties = {
|
|
101982
|
+
default: { value: wrapTxn("") },
|
|
101983
|
+
deferred: { value: wrapTxn("DEFERRED") },
|
|
101984
|
+
immediate: { value: wrapTxn("IMMEDIATE") },
|
|
101985
|
+
exclusive: { value: wrapTxn("EXCLUSIVE") },
|
|
101986
|
+
database: { value: this, enumerable: true }
|
|
101987
|
+
};
|
|
101988
|
+
Object.defineProperties(properties.default.value, properties);
|
|
101989
|
+
Object.defineProperties(properties.deferred.value, properties);
|
|
101990
|
+
Object.defineProperties(properties.immediate.value, properties);
|
|
101991
|
+
Object.defineProperties(properties.exclusive.value, properties);
|
|
101992
|
+
return properties.default.value;
|
|
101993
|
+
}
|
|
101994
|
+
async pragma(source, options7) {
|
|
101995
|
+
if (options7 == null)
|
|
101996
|
+
options7 = {};
|
|
101997
|
+
if (typeof source !== "string")
|
|
101998
|
+
throw new TypeError("Expected first argument to be a string");
|
|
101999
|
+
if (typeof options7 !== "object")
|
|
102000
|
+
throw new TypeError("Expected second argument to be an options object");
|
|
102001
|
+
const pragma = `PRAGMA ${source}`;
|
|
102002
|
+
const stmt = this.prepare(pragma);
|
|
102003
|
+
try {
|
|
102004
|
+
const results = await stmt.all();
|
|
102005
|
+
return results;
|
|
102006
|
+
} finally {
|
|
102007
|
+
await stmt.close();
|
|
102008
|
+
}
|
|
102009
|
+
}
|
|
102010
|
+
backup(filename, options7) {
|
|
102011
|
+
throw new Error("not implemented");
|
|
102012
|
+
}
|
|
102013
|
+
serialize(options7) {
|
|
102014
|
+
throw new Error("not implemented");
|
|
102015
|
+
}
|
|
102016
|
+
function(name21, options7, fn) {
|
|
102017
|
+
throw new Error("not implemented");
|
|
102018
|
+
}
|
|
102019
|
+
aggregate(name21, options7) {
|
|
102020
|
+
throw new Error("not implemented");
|
|
102021
|
+
}
|
|
102022
|
+
table(name21, factory) {
|
|
102023
|
+
throw new Error("not implemented");
|
|
102024
|
+
}
|
|
102025
|
+
loadExtension(path4) {
|
|
102026
|
+
throw new Error("not implemented");
|
|
102027
|
+
}
|
|
102028
|
+
maxWriteReplicationIndex() {
|
|
102029
|
+
throw new Error("not implemented");
|
|
102030
|
+
}
|
|
102031
|
+
async exec(sql) {
|
|
102032
|
+
await this.execLock.acquire();
|
|
102033
|
+
const exec2 = this.db.executor(sql);
|
|
102034
|
+
try {
|
|
102035
|
+
while (true) {
|
|
102036
|
+
const stepResult = exec2.stepSync();
|
|
102037
|
+
if (stepResult === STEP_IO) {
|
|
102038
|
+
await this.db.ioLoopAsync();
|
|
102039
|
+
await this.ioStep();
|
|
102040
|
+
continue;
|
|
102041
|
+
}
|
|
102042
|
+
if (stepResult === STEP_DONE) {
|
|
102043
|
+
break;
|
|
102044
|
+
}
|
|
102045
|
+
if (stepResult === STEP_ROW) {
|
|
102046
|
+
continue;
|
|
102047
|
+
}
|
|
102048
|
+
}
|
|
102049
|
+
} finally {
|
|
102050
|
+
exec2.reset();
|
|
102051
|
+
this.execLock.release();
|
|
102052
|
+
}
|
|
102053
|
+
}
|
|
102054
|
+
interrupt() {
|
|
102055
|
+
throw new Error("not implemented");
|
|
102056
|
+
}
|
|
102057
|
+
defaultSafeIntegers(toggle3) {
|
|
102058
|
+
this.db.defaultSafeIntegers(toggle3);
|
|
102059
|
+
}
|
|
102060
|
+
async close() {
|
|
102061
|
+
this.db.close();
|
|
102062
|
+
}
|
|
102063
|
+
}
|
|
102064
|
+
function maybePromise(arg) {
|
|
102065
|
+
let lazy2 = arg;
|
|
102066
|
+
let promise4 = null;
|
|
102067
|
+
let value6 = null;
|
|
102068
|
+
return {
|
|
102069
|
+
apply(fn) {
|
|
102070
|
+
let previous = lazy2;
|
|
102071
|
+
lazy2 = async () => {
|
|
102072
|
+
const result = await previous();
|
|
102073
|
+
fn(result);
|
|
102074
|
+
return result;
|
|
102075
|
+
};
|
|
102076
|
+
},
|
|
102077
|
+
async resolve() {
|
|
102078
|
+
if (promise4 != null) {
|
|
102079
|
+
return await promise4;
|
|
102080
|
+
}
|
|
102081
|
+
let valueResolve, valueReject;
|
|
102082
|
+
promise4 = new Promise((resolve4, reject) => {
|
|
102083
|
+
valueResolve = (x) => {
|
|
102084
|
+
resolve4(x);
|
|
102085
|
+
value6 = x;
|
|
102086
|
+
};
|
|
102087
|
+
valueReject = reject;
|
|
102088
|
+
});
|
|
102089
|
+
await lazy2().then(valueResolve, valueReject);
|
|
102090
|
+
return await promise4;
|
|
102091
|
+
},
|
|
102092
|
+
must() {
|
|
102093
|
+
if (value6 == null) {
|
|
102094
|
+
throw new Error(`database must be connected before execution the function`);
|
|
102095
|
+
}
|
|
102096
|
+
return value6;
|
|
102097
|
+
}
|
|
102098
|
+
};
|
|
102099
|
+
}
|
|
102100
|
+
function maybeValue(value6) {
|
|
102101
|
+
return {
|
|
102102
|
+
apply(fn) {
|
|
102103
|
+
fn(value6);
|
|
102104
|
+
},
|
|
102105
|
+
resolve() {
|
|
102106
|
+
return Promise.resolve(value6);
|
|
102107
|
+
},
|
|
102108
|
+
must() {
|
|
102109
|
+
return value6;
|
|
102110
|
+
}
|
|
102111
|
+
};
|
|
102112
|
+
}
|
|
102113
|
+
|
|
102114
|
+
class Statement {
|
|
102115
|
+
stmt;
|
|
102116
|
+
db;
|
|
102117
|
+
execLock;
|
|
102118
|
+
ioStep;
|
|
102119
|
+
constructor(stmt, db, execLock, ioStep) {
|
|
102120
|
+
this.stmt = stmt;
|
|
102121
|
+
this.db = db;
|
|
102122
|
+
this.execLock = execLock;
|
|
102123
|
+
this.ioStep = ioStep;
|
|
102124
|
+
}
|
|
102125
|
+
raw(raw) {
|
|
102126
|
+
this.stmt.apply((s) => s.raw(raw));
|
|
102127
|
+
return this;
|
|
102128
|
+
}
|
|
102129
|
+
pluck(pluckMode) {
|
|
102130
|
+
this.stmt.apply((s) => s.pluck(pluckMode));
|
|
102131
|
+
return this;
|
|
102132
|
+
}
|
|
102133
|
+
safeIntegers(toggle3) {
|
|
102134
|
+
this.stmt.apply((s) => s.safeIntegers(toggle3));
|
|
102135
|
+
return this;
|
|
102136
|
+
}
|
|
102137
|
+
columns() {
|
|
102138
|
+
return this.stmt.must().columns();
|
|
102139
|
+
}
|
|
102140
|
+
get source() {
|
|
102141
|
+
throw new Error("not implemented");
|
|
102142
|
+
}
|
|
102143
|
+
get reader() {
|
|
102144
|
+
throw new Error("not implemented");
|
|
102145
|
+
}
|
|
102146
|
+
get database() {
|
|
102147
|
+
return this.db;
|
|
102148
|
+
}
|
|
102149
|
+
async run(...bindParameters) {
|
|
102150
|
+
let stmt = await this.stmt.resolve();
|
|
102151
|
+
bindParams(stmt, bindParameters);
|
|
102152
|
+
const totalChangesBefore = this.db.totalChanges();
|
|
102153
|
+
await this.execLock.acquire();
|
|
102154
|
+
try {
|
|
102155
|
+
while (true) {
|
|
102156
|
+
const stepResult = await stmt.stepSync();
|
|
102157
|
+
if (stepResult === STEP_IO) {
|
|
102158
|
+
await this.io();
|
|
102159
|
+
continue;
|
|
102160
|
+
}
|
|
102161
|
+
if (stepResult === STEP_DONE) {
|
|
102162
|
+
break;
|
|
102163
|
+
}
|
|
102164
|
+
if (stepResult === STEP_ROW) {
|
|
102165
|
+
continue;
|
|
102166
|
+
}
|
|
102167
|
+
}
|
|
102168
|
+
const lastInsertRowid = this.db.lastInsertRowid();
|
|
102169
|
+
const changes2 = this.db.totalChanges() === totalChangesBefore ? 0 : this.db.changes();
|
|
102170
|
+
return { changes: changes2, lastInsertRowid };
|
|
102171
|
+
} finally {
|
|
102172
|
+
stmt.reset();
|
|
102173
|
+
this.execLock.release();
|
|
102174
|
+
}
|
|
102175
|
+
}
|
|
102176
|
+
async get(...bindParameters) {
|
|
102177
|
+
let stmt = await this.stmt.resolve();
|
|
102178
|
+
bindParams(stmt, bindParameters);
|
|
102179
|
+
await this.execLock.acquire();
|
|
102180
|
+
let row = undefined;
|
|
102181
|
+
try {
|
|
102182
|
+
while (true) {
|
|
102183
|
+
const stepResult = await stmt.stepSync();
|
|
102184
|
+
if (stepResult === STEP_IO) {
|
|
102185
|
+
await this.io();
|
|
102186
|
+
continue;
|
|
102187
|
+
}
|
|
102188
|
+
if (stepResult === STEP_DONE) {
|
|
102189
|
+
break;
|
|
102190
|
+
}
|
|
102191
|
+
if (stepResult === STEP_ROW && row === undefined) {
|
|
102192
|
+
row = stmt.row();
|
|
102193
|
+
continue;
|
|
102194
|
+
}
|
|
102195
|
+
}
|
|
102196
|
+
return row;
|
|
102197
|
+
} finally {
|
|
102198
|
+
stmt.reset();
|
|
102199
|
+
this.execLock.release();
|
|
102200
|
+
}
|
|
102201
|
+
}
|
|
102202
|
+
async* iterate(...bindParameters) {
|
|
102203
|
+
let stmt = await this.stmt.resolve();
|
|
102204
|
+
bindParams(stmt, bindParameters);
|
|
102205
|
+
await this.execLock.acquire();
|
|
102206
|
+
try {
|
|
102207
|
+
while (true) {
|
|
102208
|
+
const stepResult = await stmt.stepSync();
|
|
102209
|
+
if (stepResult === STEP_IO) {
|
|
102210
|
+
await this.db.ioLoopAsync();
|
|
102211
|
+
continue;
|
|
102212
|
+
}
|
|
102213
|
+
if (stepResult === STEP_DONE) {
|
|
102214
|
+
break;
|
|
102215
|
+
}
|
|
102216
|
+
if (stepResult === STEP_ROW) {
|
|
102217
|
+
yield stmt.row();
|
|
102218
|
+
}
|
|
102219
|
+
}
|
|
102220
|
+
} finally {
|
|
102221
|
+
stmt.reset();
|
|
102222
|
+
this.execLock.release();
|
|
102223
|
+
}
|
|
102224
|
+
}
|
|
102225
|
+
async all(...bindParameters) {
|
|
102226
|
+
let stmt = await this.stmt.resolve();
|
|
102227
|
+
bindParams(stmt, bindParameters);
|
|
102228
|
+
const rows = [];
|
|
102229
|
+
await this.execLock.acquire();
|
|
102230
|
+
try {
|
|
102231
|
+
while (true) {
|
|
102232
|
+
const stepResult = await stmt.stepSync();
|
|
102233
|
+
if (stepResult === STEP_IO) {
|
|
102234
|
+
await this.io();
|
|
102235
|
+
continue;
|
|
102236
|
+
}
|
|
102237
|
+
if (stepResult === STEP_DONE) {
|
|
102238
|
+
break;
|
|
102239
|
+
}
|
|
102240
|
+
if (stepResult === STEP_ROW) {
|
|
102241
|
+
rows.push(stmt.row());
|
|
102242
|
+
}
|
|
102243
|
+
}
|
|
102244
|
+
return rows;
|
|
102245
|
+
} finally {
|
|
102246
|
+
stmt.reset();
|
|
102247
|
+
this.execLock.release();
|
|
102248
|
+
}
|
|
102249
|
+
}
|
|
102250
|
+
async io() {
|
|
102251
|
+
await this.db.ioLoopAsync();
|
|
102252
|
+
await this.ioStep();
|
|
102253
|
+
}
|
|
102254
|
+
interrupt() {
|
|
102255
|
+
throw new Error("not implemented");
|
|
102256
|
+
}
|
|
102257
|
+
bind(...bindParameters) {
|
|
102258
|
+
try {
|
|
102259
|
+
bindParams(this.stmt, bindParameters);
|
|
102260
|
+
return this;
|
|
102261
|
+
} catch (err2) {
|
|
102262
|
+
throw convertError(err2);
|
|
102263
|
+
}
|
|
102264
|
+
}
|
|
102265
|
+
close() {
|
|
102266
|
+
let stmt;
|
|
102267
|
+
try {
|
|
102268
|
+
stmt = this.stmt.must();
|
|
102269
|
+
} catch (e) {
|
|
102270
|
+
return;
|
|
102271
|
+
}
|
|
102272
|
+
stmt.finalize();
|
|
102273
|
+
}
|
|
102274
|
+
}
|
|
102275
|
+
|
|
102276
|
+
// ../../node_modules/.bun/@tursodatabase+database@0.4.4/node_modules/@tursodatabase/database/index.js
|
|
102277
|
+
import { createRequire } from "module";
|
|
102278
|
+
var require2 = createRequire(import.meta.url);
|
|
102279
|
+
var __dirname2 = new URL(".", import.meta.url).pathname;
|
|
102280
|
+
var { readFileSync } = require2("node:fs");
|
|
102281
|
+
var nativeBinding = null;
|
|
102282
|
+
var loadErrors = [];
|
|
102283
|
+
var isMusl = () => {
|
|
102284
|
+
let musl = false;
|
|
102285
|
+
if (process.platform === "linux") {
|
|
102286
|
+
musl = isMuslFromFilesystem();
|
|
102287
|
+
if (musl === null) {
|
|
102288
|
+
musl = isMuslFromReport();
|
|
102289
|
+
}
|
|
102290
|
+
if (musl === null) {
|
|
102291
|
+
musl = isMuslFromChildProcess();
|
|
102292
|
+
}
|
|
102293
|
+
}
|
|
102294
|
+
return musl;
|
|
102295
|
+
};
|
|
102296
|
+
var isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
|
|
102297
|
+
var isMuslFromFilesystem = () => {
|
|
102298
|
+
try {
|
|
102299
|
+
return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
|
|
102300
|
+
} catch {
|
|
102301
|
+
return null;
|
|
102302
|
+
}
|
|
102303
|
+
};
|
|
102304
|
+
var isMuslFromReport = () => {
|
|
102305
|
+
let report = null;
|
|
102306
|
+
if (typeof process.report?.getReport === "function") {
|
|
102307
|
+
process.report.excludeNetwork = true;
|
|
102308
|
+
report = process.report.getReport();
|
|
102309
|
+
}
|
|
102310
|
+
if (!report) {
|
|
102311
|
+
return null;
|
|
102312
|
+
}
|
|
102313
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
102314
|
+
return false;
|
|
102315
|
+
}
|
|
102316
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
102317
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
102318
|
+
return true;
|
|
102319
|
+
}
|
|
102320
|
+
}
|
|
102321
|
+
return false;
|
|
102322
|
+
};
|
|
102323
|
+
var isMuslFromChildProcess = () => {
|
|
102324
|
+
try {
|
|
102325
|
+
return require2("child_process").execSync("ldd --version", { encoding: "utf8" }).includes("musl");
|
|
102326
|
+
} catch (e) {
|
|
102327
|
+
return false;
|
|
102328
|
+
}
|
|
102329
|
+
};
|
|
102330
|
+
function requireNative() {
|
|
102331
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
102332
|
+
try {
|
|
102333
|
+
nativeBinding = require2(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
102334
|
+
} catch (err2) {
|
|
102335
|
+
loadErrors.push(err2);
|
|
102336
|
+
}
|
|
102337
|
+
} else if (process.platform === "android") {
|
|
102338
|
+
if (process.arch === "arm64") {
|
|
102339
|
+
try {
|
|
102340
|
+
return require2("./turso.android-arm64.node");
|
|
102341
|
+
} catch (e) {
|
|
102342
|
+
loadErrors.push(e);
|
|
102343
|
+
}
|
|
102344
|
+
try {
|
|
102345
|
+
const binding = require2("@tursodatabase/database-android-arm64");
|
|
102346
|
+
const bindingPackageVersion = require2("@tursodatabase/database-android-arm64/package.json").version;
|
|
102347
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102348
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102349
|
+
}
|
|
102350
|
+
return binding;
|
|
102351
|
+
} catch (e) {
|
|
102352
|
+
loadErrors.push(e);
|
|
102353
|
+
}
|
|
102354
|
+
} else if (process.arch === "arm") {
|
|
102355
|
+
try {
|
|
102356
|
+
return require2("./turso.android-arm-eabi.node");
|
|
102357
|
+
} catch (e) {
|
|
102358
|
+
loadErrors.push(e);
|
|
102359
|
+
}
|
|
102360
|
+
try {
|
|
102361
|
+
const binding = require2("@tursodatabase/database-android-arm-eabi");
|
|
102362
|
+
const bindingPackageVersion = require2("@tursodatabase/database-android-arm-eabi/package.json").version;
|
|
102363
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102364
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102365
|
+
}
|
|
102366
|
+
return binding;
|
|
102367
|
+
} catch (e) {
|
|
102368
|
+
loadErrors.push(e);
|
|
102369
|
+
}
|
|
102370
|
+
} else {
|
|
102371
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`));
|
|
102372
|
+
}
|
|
102373
|
+
} else if (process.platform === "win32") {
|
|
102374
|
+
if (process.arch === "x64") {
|
|
102375
|
+
try {
|
|
102376
|
+
return require2("./turso.win32-x64-msvc.node");
|
|
102377
|
+
} catch (e) {
|
|
102378
|
+
loadErrors.push(e);
|
|
102379
|
+
}
|
|
102380
|
+
try {
|
|
102381
|
+
const binding = require2("@tursodatabase/database-win32-x64-msvc");
|
|
102382
|
+
const bindingPackageVersion = require2("@tursodatabase/database-win32-x64-msvc/package.json").version;
|
|
102383
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102384
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102385
|
+
}
|
|
102386
|
+
return binding;
|
|
102387
|
+
} catch (e) {
|
|
102388
|
+
loadErrors.push(e);
|
|
102389
|
+
}
|
|
102390
|
+
} else if (process.arch === "ia32") {
|
|
102391
|
+
try {
|
|
102392
|
+
return require2("./turso.win32-ia32-msvc.node");
|
|
102393
|
+
} catch (e) {
|
|
102394
|
+
loadErrors.push(e);
|
|
102395
|
+
}
|
|
102396
|
+
try {
|
|
102397
|
+
const binding = require2("@tursodatabase/database-win32-ia32-msvc");
|
|
102398
|
+
const bindingPackageVersion = require2("@tursodatabase/database-win32-ia32-msvc/package.json").version;
|
|
102399
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102400
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102401
|
+
}
|
|
102402
|
+
return binding;
|
|
102403
|
+
} catch (e) {
|
|
102404
|
+
loadErrors.push(e);
|
|
102405
|
+
}
|
|
102406
|
+
} else if (process.arch === "arm64") {
|
|
102407
|
+
try {
|
|
102408
|
+
return require2("./turso.win32-arm64-msvc.node");
|
|
102409
|
+
} catch (e) {
|
|
102410
|
+
loadErrors.push(e);
|
|
102411
|
+
}
|
|
102412
|
+
try {
|
|
102413
|
+
const binding = require2("@tursodatabase/database-win32-arm64-msvc");
|
|
102414
|
+
const bindingPackageVersion = require2("@tursodatabase/database-win32-arm64-msvc/package.json").version;
|
|
102415
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102416
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102417
|
+
}
|
|
102418
|
+
return binding;
|
|
102419
|
+
} catch (e) {
|
|
102420
|
+
loadErrors.push(e);
|
|
102421
|
+
}
|
|
102422
|
+
} else {
|
|
102423
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`));
|
|
102424
|
+
}
|
|
102425
|
+
} else if (process.platform === "darwin") {
|
|
102426
|
+
try {
|
|
102427
|
+
return require2("./turso.darwin-universal.node");
|
|
102428
|
+
} catch (e) {
|
|
102429
|
+
loadErrors.push(e);
|
|
102430
|
+
}
|
|
102431
|
+
try {
|
|
102432
|
+
const binding = require2("@tursodatabase/database-darwin-universal");
|
|
102433
|
+
const bindingPackageVersion = require2("@tursodatabase/database-darwin-universal/package.json").version;
|
|
102434
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102435
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102436
|
+
}
|
|
102437
|
+
return binding;
|
|
102438
|
+
} catch (e) {
|
|
102439
|
+
loadErrors.push(e);
|
|
102440
|
+
}
|
|
102441
|
+
if (process.arch === "x64") {
|
|
102442
|
+
try {
|
|
102443
|
+
return require2("./turso.darwin-x64.node");
|
|
102444
|
+
} catch (e) {
|
|
102445
|
+
loadErrors.push(e);
|
|
102446
|
+
}
|
|
102447
|
+
try {
|
|
102448
|
+
const binding = require2("@tursodatabase/database-darwin-x64");
|
|
102449
|
+
const bindingPackageVersion = require2("@tursodatabase/database-darwin-x64/package.json").version;
|
|
102450
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102451
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102452
|
+
}
|
|
102453
|
+
return binding;
|
|
102454
|
+
} catch (e) {
|
|
102455
|
+
loadErrors.push(e);
|
|
102456
|
+
}
|
|
102457
|
+
} else if (process.arch === "arm64") {
|
|
102458
|
+
try {
|
|
102459
|
+
return require2("./turso.darwin-arm64.node");
|
|
102460
|
+
} catch (e) {
|
|
102461
|
+
loadErrors.push(e);
|
|
102462
|
+
}
|
|
102463
|
+
try {
|
|
102464
|
+
const binding = require2("@tursodatabase/database-darwin-arm64");
|
|
102465
|
+
const bindingPackageVersion = require2("@tursodatabase/database-darwin-arm64/package.json").version;
|
|
102466
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102467
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102468
|
+
}
|
|
102469
|
+
return binding;
|
|
102470
|
+
} catch (e) {
|
|
102471
|
+
loadErrors.push(e);
|
|
102472
|
+
}
|
|
102473
|
+
} else {
|
|
102474
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`));
|
|
102475
|
+
}
|
|
102476
|
+
} else if (process.platform === "freebsd") {
|
|
102477
|
+
if (process.arch === "x64") {
|
|
102478
|
+
try {
|
|
102479
|
+
return require2("./turso.freebsd-x64.node");
|
|
102480
|
+
} catch (e) {
|
|
102481
|
+
loadErrors.push(e);
|
|
102482
|
+
}
|
|
102483
|
+
try {
|
|
102484
|
+
const binding = require2("@tursodatabase/database-freebsd-x64");
|
|
102485
|
+
const bindingPackageVersion = require2("@tursodatabase/database-freebsd-x64/package.json").version;
|
|
102486
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102487
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102488
|
+
}
|
|
102489
|
+
return binding;
|
|
102490
|
+
} catch (e) {
|
|
102491
|
+
loadErrors.push(e);
|
|
102492
|
+
}
|
|
102493
|
+
} else if (process.arch === "arm64") {
|
|
102494
|
+
try {
|
|
102495
|
+
return require2("./turso.freebsd-arm64.node");
|
|
102496
|
+
} catch (e) {
|
|
102497
|
+
loadErrors.push(e);
|
|
102498
|
+
}
|
|
102499
|
+
try {
|
|
102500
|
+
const binding = require2("@tursodatabase/database-freebsd-arm64");
|
|
102501
|
+
const bindingPackageVersion = require2("@tursodatabase/database-freebsd-arm64/package.json").version;
|
|
102502
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102503
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102504
|
+
}
|
|
102505
|
+
return binding;
|
|
102506
|
+
} catch (e) {
|
|
102507
|
+
loadErrors.push(e);
|
|
102508
|
+
}
|
|
102509
|
+
} else {
|
|
102510
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`));
|
|
102511
|
+
}
|
|
102512
|
+
} else if (process.platform === "linux") {
|
|
102513
|
+
if (process.arch === "x64") {
|
|
102514
|
+
if (isMusl()) {
|
|
102515
|
+
try {
|
|
102516
|
+
return require2("./turso.linux-x64-musl.node");
|
|
102517
|
+
} catch (e) {
|
|
102518
|
+
loadErrors.push(e);
|
|
102519
|
+
}
|
|
102520
|
+
try {
|
|
102521
|
+
const binding = require2("@tursodatabase/database-linux-x64-musl");
|
|
102522
|
+
const bindingPackageVersion = require2("@tursodatabase/database-linux-x64-musl/package.json").version;
|
|
102523
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102524
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102525
|
+
}
|
|
102526
|
+
return binding;
|
|
102527
|
+
} catch (e) {
|
|
102528
|
+
loadErrors.push(e);
|
|
102529
|
+
}
|
|
102530
|
+
} else {
|
|
102531
|
+
try {
|
|
102532
|
+
return require2("./turso.linux-x64-gnu.node");
|
|
102533
|
+
} catch (e) {
|
|
102534
|
+
loadErrors.push(e);
|
|
102535
|
+
}
|
|
102536
|
+
try {
|
|
102537
|
+
const binding = require2("@tursodatabase/database-linux-x64-gnu");
|
|
102538
|
+
const bindingPackageVersion = require2("@tursodatabase/database-linux-x64-gnu/package.json").version;
|
|
102539
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102540
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102541
|
+
}
|
|
102542
|
+
return binding;
|
|
102543
|
+
} catch (e) {
|
|
102544
|
+
loadErrors.push(e);
|
|
102545
|
+
}
|
|
102546
|
+
}
|
|
102547
|
+
} else if (process.arch === "arm64") {
|
|
102548
|
+
if (isMusl()) {
|
|
102549
|
+
try {
|
|
102550
|
+
return require2("./turso.linux-arm64-musl.node");
|
|
102551
|
+
} catch (e) {
|
|
102552
|
+
loadErrors.push(e);
|
|
102553
|
+
}
|
|
102554
|
+
try {
|
|
102555
|
+
const binding = require2("@tursodatabase/database-linux-arm64-musl");
|
|
102556
|
+
const bindingPackageVersion = require2("@tursodatabase/database-linux-arm64-musl/package.json").version;
|
|
102557
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102558
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102559
|
+
}
|
|
102560
|
+
return binding;
|
|
102561
|
+
} catch (e) {
|
|
102562
|
+
loadErrors.push(e);
|
|
102563
|
+
}
|
|
102564
|
+
} else {
|
|
102565
|
+
try {
|
|
102566
|
+
return require2("./turso.linux-arm64-gnu.node");
|
|
102567
|
+
} catch (e) {
|
|
102568
|
+
loadErrors.push(e);
|
|
102569
|
+
}
|
|
102570
|
+
try {
|
|
102571
|
+
const binding = require2("@tursodatabase/database-linux-arm64-gnu");
|
|
102572
|
+
const bindingPackageVersion = require2("@tursodatabase/database-linux-arm64-gnu/package.json").version;
|
|
102573
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102574
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102575
|
+
}
|
|
102576
|
+
return binding;
|
|
102577
|
+
} catch (e) {
|
|
102578
|
+
loadErrors.push(e);
|
|
102579
|
+
}
|
|
102580
|
+
}
|
|
102581
|
+
} else if (process.arch === "arm") {
|
|
102582
|
+
if (isMusl()) {
|
|
102583
|
+
try {
|
|
102584
|
+
return require2("./turso.linux-arm-musleabihf.node");
|
|
102585
|
+
} catch (e) {
|
|
102586
|
+
loadErrors.push(e);
|
|
102587
|
+
}
|
|
102588
|
+
try {
|
|
102589
|
+
const binding = require2("@tursodatabase/database-linux-arm-musleabihf");
|
|
102590
|
+
const bindingPackageVersion = require2("@tursodatabase/database-linux-arm-musleabihf/package.json").version;
|
|
102591
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102592
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102593
|
+
}
|
|
102594
|
+
return binding;
|
|
102595
|
+
} catch (e) {
|
|
102596
|
+
loadErrors.push(e);
|
|
102597
|
+
}
|
|
102598
|
+
} else {
|
|
102599
|
+
try {
|
|
102600
|
+
return require2("./turso.linux-arm-gnueabihf.node");
|
|
102601
|
+
} catch (e) {
|
|
102602
|
+
loadErrors.push(e);
|
|
102603
|
+
}
|
|
102604
|
+
try {
|
|
102605
|
+
const binding = require2("@tursodatabase/database-linux-arm-gnueabihf");
|
|
102606
|
+
const bindingPackageVersion = require2("@tursodatabase/database-linux-arm-gnueabihf/package.json").version;
|
|
102607
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102608
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102609
|
+
}
|
|
102610
|
+
return binding;
|
|
102611
|
+
} catch (e) {
|
|
102612
|
+
loadErrors.push(e);
|
|
102613
|
+
}
|
|
102614
|
+
}
|
|
102615
|
+
} else if (process.arch === "riscv64") {
|
|
102616
|
+
if (isMusl()) {
|
|
102617
|
+
try {
|
|
102618
|
+
return require2("./turso.linux-riscv64-musl.node");
|
|
102619
|
+
} catch (e) {
|
|
102620
|
+
loadErrors.push(e);
|
|
102621
|
+
}
|
|
102622
|
+
try {
|
|
102623
|
+
const binding = require2("@tursodatabase/database-linux-riscv64-musl");
|
|
102624
|
+
const bindingPackageVersion = require2("@tursodatabase/database-linux-riscv64-musl/package.json").version;
|
|
102625
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102626
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102627
|
+
}
|
|
102628
|
+
return binding;
|
|
102629
|
+
} catch (e) {
|
|
102630
|
+
loadErrors.push(e);
|
|
102631
|
+
}
|
|
102632
|
+
} else {
|
|
102633
|
+
try {
|
|
102634
|
+
return require2("./turso.linux-riscv64-gnu.node");
|
|
102635
|
+
} catch (e) {
|
|
102636
|
+
loadErrors.push(e);
|
|
102637
|
+
}
|
|
102638
|
+
try {
|
|
102639
|
+
const binding = require2("@tursodatabase/database-linux-riscv64-gnu");
|
|
102640
|
+
const bindingPackageVersion = require2("@tursodatabase/database-linux-riscv64-gnu/package.json").version;
|
|
102641
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102642
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102643
|
+
}
|
|
102644
|
+
return binding;
|
|
102645
|
+
} catch (e) {
|
|
102646
|
+
loadErrors.push(e);
|
|
102647
|
+
}
|
|
102648
|
+
}
|
|
102649
|
+
} else if (process.arch === "ppc64") {
|
|
102650
|
+
try {
|
|
102651
|
+
return require2("./turso.linux-ppc64-gnu.node");
|
|
102652
|
+
} catch (e) {
|
|
102653
|
+
loadErrors.push(e);
|
|
102654
|
+
}
|
|
102655
|
+
try {
|
|
102656
|
+
const binding = require2("@tursodatabase/database-linux-ppc64-gnu");
|
|
102657
|
+
const bindingPackageVersion = require2("@tursodatabase/database-linux-ppc64-gnu/package.json").version;
|
|
102658
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102659
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102660
|
+
}
|
|
102661
|
+
return binding;
|
|
102662
|
+
} catch (e) {
|
|
102663
|
+
loadErrors.push(e);
|
|
102664
|
+
}
|
|
102665
|
+
} else if (process.arch === "s390x") {
|
|
102666
|
+
try {
|
|
102667
|
+
return require2("./turso.linux-s390x-gnu.node");
|
|
102668
|
+
} catch (e) {
|
|
102669
|
+
loadErrors.push(e);
|
|
102670
|
+
}
|
|
102671
|
+
try {
|
|
102672
|
+
const binding = require2("@tursodatabase/database-linux-s390x-gnu");
|
|
102673
|
+
const bindingPackageVersion = require2("@tursodatabase/database-linux-s390x-gnu/package.json").version;
|
|
102674
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102675
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102676
|
+
}
|
|
102677
|
+
return binding;
|
|
102678
|
+
} catch (e) {
|
|
102679
|
+
loadErrors.push(e);
|
|
102680
|
+
}
|
|
102681
|
+
} else {
|
|
102682
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`));
|
|
102683
|
+
}
|
|
102684
|
+
} else if (process.platform === "openharmony") {
|
|
102685
|
+
if (process.arch === "arm64") {
|
|
102686
|
+
try {
|
|
102687
|
+
return require2("./turso.openharmony-arm64.node");
|
|
102688
|
+
} catch (e) {
|
|
102689
|
+
loadErrors.push(e);
|
|
102690
|
+
}
|
|
102691
|
+
try {
|
|
102692
|
+
const binding = require2("@tursodatabase/database-openharmony-arm64");
|
|
102693
|
+
const bindingPackageVersion = require2("@tursodatabase/database-openharmony-arm64/package.json").version;
|
|
102694
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102695
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102696
|
+
}
|
|
102697
|
+
return binding;
|
|
102698
|
+
} catch (e) {
|
|
102699
|
+
loadErrors.push(e);
|
|
102700
|
+
}
|
|
102701
|
+
} else if (process.arch === "x64") {
|
|
102702
|
+
try {
|
|
102703
|
+
return require2("./turso.openharmony-x64.node");
|
|
102704
|
+
} catch (e) {
|
|
102705
|
+
loadErrors.push(e);
|
|
102706
|
+
}
|
|
102707
|
+
try {
|
|
102708
|
+
const binding = require2("@tursodatabase/database-openharmony-x64");
|
|
102709
|
+
const bindingPackageVersion = require2("@tursodatabase/database-openharmony-x64/package.json").version;
|
|
102710
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102711
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102712
|
+
}
|
|
102713
|
+
return binding;
|
|
102714
|
+
} catch (e) {
|
|
102715
|
+
loadErrors.push(e);
|
|
102716
|
+
}
|
|
102717
|
+
} else if (process.arch === "arm") {
|
|
102718
|
+
try {
|
|
102719
|
+
return require2("./turso.openharmony-arm.node");
|
|
102720
|
+
} catch (e) {
|
|
102721
|
+
loadErrors.push(e);
|
|
102722
|
+
}
|
|
102723
|
+
try {
|
|
102724
|
+
const binding = require2("@tursodatabase/database-openharmony-arm");
|
|
102725
|
+
const bindingPackageVersion = require2("@tursodatabase/database-openharmony-arm/package.json").version;
|
|
102726
|
+
if (bindingPackageVersion !== "0.3.0-pre.4" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
102727
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.0-pre.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
102728
|
+
}
|
|
102729
|
+
return binding;
|
|
102730
|
+
} catch (e) {
|
|
102731
|
+
loadErrors.push(e);
|
|
102732
|
+
}
|
|
102733
|
+
} else {
|
|
102734
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`));
|
|
102735
|
+
}
|
|
102736
|
+
} else {
|
|
102737
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`));
|
|
102738
|
+
}
|
|
102739
|
+
}
|
|
102740
|
+
nativeBinding = requireNative();
|
|
102741
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
102742
|
+
try {
|
|
102743
|
+
nativeBinding = require2("./turso.wasi.cjs");
|
|
102744
|
+
} catch (err2) {
|
|
102745
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
102746
|
+
loadErrors.push(err2);
|
|
102747
|
+
}
|
|
102748
|
+
}
|
|
102749
|
+
if (!nativeBinding) {
|
|
102750
|
+
try {
|
|
102751
|
+
nativeBinding = require2("@tursodatabase/database-wasm32-wasi");
|
|
102752
|
+
} catch (err2) {
|
|
102753
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
102754
|
+
loadErrors.push(err2);
|
|
102755
|
+
}
|
|
102756
|
+
}
|
|
102757
|
+
}
|
|
102758
|
+
}
|
|
102759
|
+
if (!nativeBinding) {
|
|
102760
|
+
if (loadErrors.length > 0) {
|
|
102761
|
+
throw new Error(`Cannot find native binding. ` + `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` + "Please try `npm i` again after removing both package-lock.json and node_modules directory.", { cause: loadErrors });
|
|
102762
|
+
}
|
|
102763
|
+
throw new Error(`Failed to load native binding`);
|
|
102764
|
+
}
|
|
102765
|
+
var { BatchExecutor, Database: Database3, Statement: Statement3 } = nativeBinding;
|
|
102766
|
+
|
|
102767
|
+
// ../../node_modules/.bun/@tursodatabase+database@0.4.4/node_modules/@tursodatabase/database/dist/promise.js
|
|
102768
|
+
class Database4 extends Database {
|
|
102769
|
+
constructor(path4, opts = {}) {
|
|
102770
|
+
super(new Database3(path4, opts));
|
|
102771
|
+
}
|
|
102772
|
+
}
|
|
102773
|
+
|
|
102774
|
+
// ../../node_modules/.bun/agentfs-sdk@0.6.2/node_modules/agentfs-sdk/dist/index_node.js
|
|
102775
|
+
import { existsSync, mkdirSync } from "fs";
|
|
102776
|
+
|
|
102777
|
+
// ../../node_modules/.bun/agentfs-sdk@0.6.2/node_modules/agentfs-sdk/dist/agentfs.js
|
|
102778
|
+
class AgentFSCore {
|
|
102779
|
+
db;
|
|
102780
|
+
kv;
|
|
102781
|
+
fs;
|
|
102782
|
+
tools;
|
|
102783
|
+
constructor(db, kv, fs2, tools) {
|
|
102784
|
+
this.db = db;
|
|
102785
|
+
this.kv = kv;
|
|
102786
|
+
this.fs = fs2;
|
|
102787
|
+
this.tools = tools;
|
|
102788
|
+
}
|
|
102789
|
+
getDatabase() {
|
|
102790
|
+
return this.db;
|
|
102791
|
+
}
|
|
102792
|
+
async close() {
|
|
102793
|
+
await this.db.close();
|
|
102794
|
+
}
|
|
102795
|
+
}
|
|
102796
|
+
|
|
102797
|
+
// ../../node_modules/.bun/agentfs-sdk@0.6.2/node_modules/agentfs-sdk/dist/kvstore.js
|
|
102798
|
+
class KvStore {
|
|
102799
|
+
db;
|
|
102800
|
+
constructor(db) {
|
|
102801
|
+
this.db = db;
|
|
102802
|
+
}
|
|
102803
|
+
static async fromDatabase(db) {
|
|
102804
|
+
const kv = new KvStore(db);
|
|
102805
|
+
await kv.initialize();
|
|
102806
|
+
return kv;
|
|
102807
|
+
}
|
|
102808
|
+
async initialize() {
|
|
102809
|
+
await this.db.exec(`
|
|
102810
|
+
CREATE TABLE IF NOT EXISTS kv_store (
|
|
102811
|
+
key TEXT PRIMARY KEY,
|
|
102812
|
+
value TEXT NOT NULL,
|
|
102813
|
+
created_at INTEGER DEFAULT (unixepoch()),
|
|
102814
|
+
updated_at INTEGER DEFAULT (unixepoch())
|
|
102815
|
+
)
|
|
102816
|
+
`);
|
|
102817
|
+
await this.db.exec(`
|
|
102818
|
+
CREATE INDEX IF NOT EXISTS idx_kv_store_created_at
|
|
102819
|
+
ON kv_store(created_at)
|
|
102820
|
+
`);
|
|
102821
|
+
}
|
|
102822
|
+
async set(key, value6) {
|
|
102823
|
+
const serializedValue = JSON.stringify(value6);
|
|
102824
|
+
const stmt = this.db.prepare(`
|
|
102825
|
+
INSERT INTO kv_store (key, value, updated_at)
|
|
102826
|
+
VALUES (?, ?, unixepoch())
|
|
102827
|
+
ON CONFLICT(key) DO UPDATE SET
|
|
102828
|
+
value = excluded.value,
|
|
102829
|
+
updated_at = unixepoch()
|
|
102830
|
+
`);
|
|
102831
|
+
await stmt.run(key, serializedValue);
|
|
102832
|
+
}
|
|
102833
|
+
async get(key) {
|
|
102834
|
+
const stmt = this.db.prepare(`SELECT value FROM kv_store WHERE key = ?`);
|
|
102835
|
+
const row = await stmt.get(key);
|
|
102836
|
+
if (!row) {
|
|
102837
|
+
return;
|
|
102838
|
+
}
|
|
102839
|
+
return JSON.parse(row.value);
|
|
102840
|
+
}
|
|
102841
|
+
async list(prefix) {
|
|
102842
|
+
const stmt = this.db.prepare(`SELECT key, value FROM kv_store WHERE key LIKE ? ESCAPE '\\'`);
|
|
102843
|
+
const escaped = prefix.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_");
|
|
102844
|
+
const rows = await stmt.all(escaped + "%");
|
|
102845
|
+
return rows.map((r) => ({ key: r.key, value: JSON.parse(r.value) }));
|
|
102846
|
+
}
|
|
102847
|
+
async delete(key) {
|
|
102848
|
+
const stmt = this.db.prepare(`DELETE FROM kv_store WHERE key = ?`);
|
|
102849
|
+
await stmt.run(key);
|
|
102850
|
+
}
|
|
102851
|
+
}
|
|
102852
|
+
|
|
102853
|
+
// ../../node_modules/.bun/agentfs-sdk@0.6.2/node_modules/agentfs-sdk/dist/filesystem/interface.js
|
|
102854
|
+
var S_IFMT = 61440;
|
|
102855
|
+
var S_IFREG = 32768;
|
|
102856
|
+
var S_IFDIR = 16384;
|
|
102857
|
+
var S_IFLNK = 40960;
|
|
102858
|
+
var DEFAULT_FILE_MODE = S_IFREG | 420;
|
|
102859
|
+
var DEFAULT_DIR_MODE = S_IFDIR | 493;
|
|
102860
|
+
function createStats(data) {
|
|
102861
|
+
return {
|
|
102862
|
+
...data,
|
|
102863
|
+
isFile: () => (data.mode & S_IFMT) === S_IFREG,
|
|
102864
|
+
isDirectory: () => (data.mode & S_IFMT) === S_IFDIR,
|
|
102865
|
+
isSymbolicLink: () => (data.mode & S_IFMT) === S_IFLNK
|
|
102866
|
+
};
|
|
102867
|
+
}
|
|
102868
|
+
// ../../node_modules/.bun/agentfs-sdk@0.6.2/node_modules/agentfs-sdk/dist/errors.js
|
|
102869
|
+
function createFsError(params) {
|
|
102870
|
+
const { code: code2, syscall, path: path4, message } = params;
|
|
102871
|
+
const base = message ?? code2;
|
|
102872
|
+
const suffix = path4 !== undefined ? ` '${path4}'` : "";
|
|
102873
|
+
const err2 = new Error(`${code2}: ${base}, ${syscall}${suffix}`);
|
|
102874
|
+
err2.code = code2;
|
|
102875
|
+
err2.syscall = syscall;
|
|
102876
|
+
if (path4 !== undefined)
|
|
102877
|
+
err2.path = path4;
|
|
102878
|
+
return err2;
|
|
102879
|
+
}
|
|
102880
|
+
|
|
102881
|
+
// ../../node_modules/.bun/agentfs-sdk@0.6.2/node_modules/agentfs-sdk/dist/guards.js
|
|
102882
|
+
async function getInodeMode(db, ino) {
|
|
102883
|
+
const stmt = db.prepare("SELECT mode FROM fs_inode WHERE ino = ?");
|
|
102884
|
+
const row = await stmt.get(ino);
|
|
102885
|
+
return row?.mode ?? null;
|
|
102886
|
+
}
|
|
102887
|
+
function isDirMode(mode) {
|
|
102888
|
+
return (mode & S_IFMT) === S_IFDIR;
|
|
102889
|
+
}
|
|
102890
|
+
async function getInodeModeOrThrow(db, ino, syscall, path4) {
|
|
102891
|
+
const mode = await getInodeMode(db, ino);
|
|
102892
|
+
if (mode === null) {
|
|
102893
|
+
throw createFsError({
|
|
102894
|
+
code: "ENOENT",
|
|
102895
|
+
syscall,
|
|
102896
|
+
path: path4,
|
|
102897
|
+
message: "no such file or directory"
|
|
102898
|
+
});
|
|
102899
|
+
}
|
|
102900
|
+
return mode;
|
|
102901
|
+
}
|
|
102902
|
+
function assertNotRoot(path4, syscall) {
|
|
102903
|
+
if (path4 === "/") {
|
|
102904
|
+
throw createFsError({
|
|
102905
|
+
code: "EPERM",
|
|
102906
|
+
syscall,
|
|
102907
|
+
path: path4,
|
|
102908
|
+
message: "operation not permitted on root directory"
|
|
102909
|
+
});
|
|
102910
|
+
}
|
|
102911
|
+
}
|
|
102912
|
+
function normalizeRmOptions(options7) {
|
|
102913
|
+
return {
|
|
102914
|
+
force: options7?.force === true,
|
|
102915
|
+
recursive: options7?.recursive === true
|
|
102916
|
+
};
|
|
102917
|
+
}
|
|
102918
|
+
function throwENOENTUnlessForce(path4, syscall, force) {
|
|
102919
|
+
if (force)
|
|
102920
|
+
return;
|
|
102921
|
+
throw createFsError({
|
|
102922
|
+
code: "ENOENT",
|
|
102923
|
+
syscall,
|
|
102924
|
+
path: path4,
|
|
102925
|
+
message: "no such file or directory"
|
|
102926
|
+
});
|
|
102927
|
+
}
|
|
102928
|
+
function assertNotSymlinkMode(mode, syscall, path4) {
|
|
102929
|
+
if ((mode & S_IFMT) === S_IFLNK) {
|
|
102930
|
+
throw createFsError({
|
|
102931
|
+
code: "ENOSYS",
|
|
102932
|
+
syscall,
|
|
102933
|
+
path: path4,
|
|
102934
|
+
message: "symbolic links not supported yet"
|
|
102935
|
+
});
|
|
102936
|
+
}
|
|
102937
|
+
}
|
|
102938
|
+
async function assertExistingNonDirNonSymlinkInode(db, ino, syscall, fullPathForError) {
|
|
102939
|
+
const mode = await getInodeMode(db, ino);
|
|
102940
|
+
if (mode === null) {
|
|
102941
|
+
throw createFsError({
|
|
102942
|
+
code: "ENOENT",
|
|
102943
|
+
syscall,
|
|
102944
|
+
path: fullPathForError,
|
|
102945
|
+
message: "no such file or directory"
|
|
102946
|
+
});
|
|
102947
|
+
}
|
|
102948
|
+
if (isDirMode(mode)) {
|
|
102949
|
+
throw createFsError({
|
|
102950
|
+
code: "EISDIR",
|
|
102951
|
+
syscall,
|
|
102952
|
+
path: fullPathForError,
|
|
102953
|
+
message: "illegal operation on a directory"
|
|
102954
|
+
});
|
|
102955
|
+
}
|
|
102956
|
+
assertNotSymlinkMode(mode, syscall, fullPathForError);
|
|
102957
|
+
}
|
|
102958
|
+
async function assertInodeIsDirectory(db, ino, syscall, fullPathForError) {
|
|
102959
|
+
const mode = await getInodeMode(db, ino);
|
|
102960
|
+
if (mode === null) {
|
|
102961
|
+
throw createFsError({
|
|
102962
|
+
code: "ENOENT",
|
|
102963
|
+
syscall,
|
|
102964
|
+
path: fullPathForError,
|
|
102965
|
+
message: "no such file or directory"
|
|
102966
|
+
});
|
|
102967
|
+
}
|
|
102968
|
+
if (!isDirMode(mode)) {
|
|
102969
|
+
throw createFsError({
|
|
102970
|
+
code: "ENOTDIR",
|
|
102971
|
+
syscall,
|
|
102972
|
+
path: fullPathForError,
|
|
102973
|
+
message: "not a directory"
|
|
102974
|
+
});
|
|
102975
|
+
}
|
|
102976
|
+
}
|
|
102977
|
+
async function assertWritableExistingInode(db, ino, syscall, fullPathForError) {
|
|
102978
|
+
await assertExistingNonDirNonSymlinkInode(db, ino, syscall, fullPathForError);
|
|
102979
|
+
}
|
|
102980
|
+
async function assertReadableExistingInode(db, ino, syscall, fullPathForError) {
|
|
102981
|
+
await assertExistingNonDirNonSymlinkInode(db, ino, syscall, fullPathForError);
|
|
102982
|
+
}
|
|
102983
|
+
async function assertReaddirTargetInode(db, ino, fullPathForError) {
|
|
102984
|
+
const syscall = "scandir";
|
|
102985
|
+
const mode = await getInodeMode(db, ino);
|
|
102986
|
+
if (mode === null) {
|
|
102987
|
+
throw createFsError({
|
|
102988
|
+
code: "ENOENT",
|
|
102989
|
+
syscall,
|
|
102990
|
+
path: fullPathForError,
|
|
102991
|
+
message: "no such file or directory"
|
|
102992
|
+
});
|
|
102993
|
+
}
|
|
102994
|
+
assertNotSymlinkMode(mode, syscall, fullPathForError);
|
|
102995
|
+
if (!isDirMode(mode)) {
|
|
102996
|
+
throw createFsError({
|
|
102997
|
+
code: "ENOTDIR",
|
|
102998
|
+
syscall,
|
|
102999
|
+
path: fullPathForError,
|
|
103000
|
+
message: "not a directory"
|
|
103001
|
+
});
|
|
103002
|
+
}
|
|
103003
|
+
}
|
|
103004
|
+
async function assertUnlinkTargetInode(db, ino, fullPathForError) {
|
|
103005
|
+
const syscall = "unlink";
|
|
103006
|
+
const mode = await getInodeMode(db, ino);
|
|
103007
|
+
if (mode === null) {
|
|
103008
|
+
throw createFsError({
|
|
103009
|
+
code: "ENOENT",
|
|
103010
|
+
syscall,
|
|
103011
|
+
path: fullPathForError,
|
|
103012
|
+
message: "no such file or directory"
|
|
103013
|
+
});
|
|
103014
|
+
}
|
|
103015
|
+
if (isDirMode(mode)) {
|
|
103016
|
+
throw createFsError({
|
|
103017
|
+
code: "EISDIR",
|
|
103018
|
+
syscall,
|
|
103019
|
+
path: fullPathForError,
|
|
103020
|
+
message: "illegal operation on a directory"
|
|
103021
|
+
});
|
|
103022
|
+
}
|
|
103023
|
+
assertNotSymlinkMode(mode, syscall, fullPathForError);
|
|
103024
|
+
}
|
|
103025
|
+
|
|
103026
|
+
// ../../node_modules/.bun/agentfs-sdk@0.6.2/node_modules/agentfs-sdk/dist/filesystem/agentfs.js
|
|
103027
|
+
var DEFAULT_CHUNK_SIZE = 4096;
|
|
103028
|
+
|
|
103029
|
+
class AgentFSFile {
|
|
103030
|
+
db;
|
|
103031
|
+
bufferCtor;
|
|
103032
|
+
ino;
|
|
103033
|
+
chunkSize;
|
|
103034
|
+
constructor(db, bufferCtor, ino, chunkSize) {
|
|
103035
|
+
this.db = db;
|
|
103036
|
+
this.bufferCtor = bufferCtor;
|
|
103037
|
+
this.ino = ino;
|
|
103038
|
+
this.chunkSize = chunkSize;
|
|
103039
|
+
}
|
|
103040
|
+
async pread(offset, size11) {
|
|
103041
|
+
const startChunk = Math.floor(offset / this.chunkSize);
|
|
103042
|
+
const endChunk = Math.floor((offset + size11 - 1) / this.chunkSize);
|
|
103043
|
+
const stmt = this.db.prepare(`
|
|
103044
|
+
SELECT chunk_index, data FROM fs_data
|
|
103045
|
+
WHERE ino = ? AND chunk_index >= ? AND chunk_index <= ?
|
|
103046
|
+
ORDER BY chunk_index ASC
|
|
103047
|
+
`);
|
|
103048
|
+
const rows = await stmt.all(this.ino, startChunk, endChunk);
|
|
103049
|
+
const buffers = [];
|
|
103050
|
+
let bytesCollected = 0;
|
|
103051
|
+
const startOffsetInChunk = offset % this.chunkSize;
|
|
103052
|
+
for (const row of rows) {
|
|
103053
|
+
const skip = buffers.length === 0 ? startOffsetInChunk : 0;
|
|
103054
|
+
if (skip >= row.data.length) {
|
|
103055
|
+
continue;
|
|
103056
|
+
}
|
|
103057
|
+
const remaining = size11 - bytesCollected;
|
|
103058
|
+
const take7 = Math.min(row.data.length - skip, remaining);
|
|
103059
|
+
buffers.push(row.data.subarray(skip, skip + take7));
|
|
103060
|
+
bytesCollected += take7;
|
|
103061
|
+
}
|
|
103062
|
+
if (buffers.length === 0) {
|
|
103063
|
+
return this.bufferCtor.alloc(0);
|
|
103064
|
+
}
|
|
103065
|
+
return this.bufferCtor.concat(buffers);
|
|
103066
|
+
}
|
|
103067
|
+
async pwrite(offset, data) {
|
|
103068
|
+
if (data.length === 0) {
|
|
103069
|
+
return;
|
|
103070
|
+
}
|
|
103071
|
+
const sizeStmt = this.db.prepare("SELECT size FROM fs_inode WHERE ino = ?");
|
|
103072
|
+
const sizeRow = await sizeStmt.get(this.ino);
|
|
103073
|
+
const currentSize = sizeRow?.size ?? 0;
|
|
103074
|
+
if (offset > currentSize) {
|
|
103075
|
+
const zeros = this.bufferCtor.alloc(offset - currentSize);
|
|
103076
|
+
await this.writeDataAtOffset(currentSize, zeros);
|
|
103077
|
+
}
|
|
103078
|
+
await this.writeDataAtOffset(offset, data);
|
|
103079
|
+
const newSize = Math.max(currentSize, offset + data.length);
|
|
103080
|
+
const now = Math.floor(Date.now() / 1000);
|
|
103081
|
+
const updateStmt = this.db.prepare("UPDATE fs_inode SET size = ?, mtime = ? WHERE ino = ?");
|
|
103082
|
+
await updateStmt.run(newSize, now, this.ino);
|
|
103083
|
+
}
|
|
103084
|
+
async writeDataAtOffset(offset, data) {
|
|
103085
|
+
const startChunk = Math.floor(offset / this.chunkSize);
|
|
103086
|
+
const endChunk = Math.floor((offset + data.length - 1) / this.chunkSize);
|
|
103087
|
+
for (let chunkIdx = startChunk;chunkIdx <= endChunk; chunkIdx++) {
|
|
103088
|
+
const chunkStart = chunkIdx * this.chunkSize;
|
|
103089
|
+
const chunkEnd = chunkStart + this.chunkSize;
|
|
103090
|
+
const dataStart = Math.max(0, chunkStart - offset);
|
|
103091
|
+
const dataEnd = Math.min(data.length, chunkEnd - offset);
|
|
103092
|
+
const writeOffset = Math.max(0, offset - chunkStart);
|
|
103093
|
+
const selectStmt = this.db.prepare("SELECT data FROM fs_data WHERE ino = ? AND chunk_index = ?");
|
|
103094
|
+
const existingRow = await selectStmt.get(this.ino, chunkIdx);
|
|
103095
|
+
let chunkData;
|
|
103096
|
+
if (existingRow) {
|
|
103097
|
+
chunkData = this.bufferCtor.from(existingRow.data);
|
|
103098
|
+
if (writeOffset + (dataEnd - dataStart) > chunkData.length) {
|
|
103099
|
+
const newChunk = this.bufferCtor.alloc(writeOffset + (dataEnd - dataStart));
|
|
103100
|
+
chunkData.copy(newChunk);
|
|
103101
|
+
chunkData = newChunk;
|
|
103102
|
+
}
|
|
103103
|
+
} else {
|
|
103104
|
+
chunkData = this.bufferCtor.alloc(writeOffset + (dataEnd - dataStart));
|
|
103105
|
+
}
|
|
103106
|
+
data.copy(chunkData, writeOffset, dataStart, dataEnd);
|
|
103107
|
+
const upsertStmt = this.db.prepare(`
|
|
103108
|
+
INSERT INTO fs_data (ino, chunk_index, data) VALUES (?, ?, ?)
|
|
103109
|
+
ON CONFLICT(ino, chunk_index) DO UPDATE SET data = excluded.data
|
|
103110
|
+
`);
|
|
103111
|
+
await upsertStmt.run(this.ino, chunkIdx, chunkData);
|
|
103112
|
+
}
|
|
103113
|
+
}
|
|
103114
|
+
async truncate(newSize) {
|
|
103115
|
+
const sizeStmt = this.db.prepare("SELECT size FROM fs_inode WHERE ino = ?");
|
|
103116
|
+
const sizeRow = await sizeStmt.get(this.ino);
|
|
103117
|
+
const currentSize = sizeRow?.size ?? 0;
|
|
103118
|
+
await this.db.exec("BEGIN");
|
|
103119
|
+
try {
|
|
103120
|
+
if (newSize === 0) {
|
|
103121
|
+
const deleteStmt = this.db.prepare("DELETE FROM fs_data WHERE ino = ?");
|
|
103122
|
+
await deleteStmt.run(this.ino);
|
|
103123
|
+
} else if (newSize < currentSize) {
|
|
103124
|
+
const lastChunkIdx = Math.floor((newSize - 1) / this.chunkSize);
|
|
103125
|
+
const deleteStmt = this.db.prepare("DELETE FROM fs_data WHERE ino = ? AND chunk_index > ?");
|
|
103126
|
+
await deleteStmt.run(this.ino, lastChunkIdx);
|
|
103127
|
+
const offsetInChunk = newSize % this.chunkSize;
|
|
103128
|
+
if (offsetInChunk > 0) {
|
|
103129
|
+
const selectStmt = this.db.prepare("SELECT data FROM fs_data WHERE ino = ? AND chunk_index = ?");
|
|
103130
|
+
const row = await selectStmt.get(this.ino, lastChunkIdx);
|
|
103131
|
+
if (row && row.data.length > offsetInChunk) {
|
|
103132
|
+
const truncatedChunk = row.data.subarray(0, offsetInChunk);
|
|
103133
|
+
const updateStmt2 = this.db.prepare("UPDATE fs_data SET data = ? WHERE ino = ? AND chunk_index = ?");
|
|
103134
|
+
await updateStmt2.run(truncatedChunk, this.ino, lastChunkIdx);
|
|
103135
|
+
}
|
|
103136
|
+
}
|
|
103137
|
+
}
|
|
103138
|
+
const now = Math.floor(Date.now() / 1000);
|
|
103139
|
+
const updateStmt = this.db.prepare("UPDATE fs_inode SET size = ?, mtime = ? WHERE ino = ?");
|
|
103140
|
+
await updateStmt.run(newSize, now, this.ino);
|
|
103141
|
+
await this.db.exec("COMMIT");
|
|
103142
|
+
} catch (e) {
|
|
103143
|
+
await this.db.exec("ROLLBACK");
|
|
103144
|
+
throw e;
|
|
103145
|
+
}
|
|
103146
|
+
}
|
|
103147
|
+
async fsync() {
|
|
103148
|
+
await this.db.exec("PRAGMA synchronous = FULL");
|
|
103149
|
+
await this.db.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
103150
|
+
}
|
|
103151
|
+
async fstat() {
|
|
103152
|
+
const stmt = this.db.prepare(`
|
|
103153
|
+
SELECT ino, mode, nlink, uid, gid, size, atime, mtime, ctime
|
|
103154
|
+
FROM fs_inode WHERE ino = ?
|
|
103155
|
+
`);
|
|
103156
|
+
const row = await stmt.get(this.ino);
|
|
103157
|
+
if (!row) {
|
|
103158
|
+
throw new Error("File handle refers to deleted inode");
|
|
103159
|
+
}
|
|
103160
|
+
return createStats(row);
|
|
103161
|
+
}
|
|
103162
|
+
}
|
|
103163
|
+
|
|
103164
|
+
class AgentFS {
|
|
103165
|
+
db;
|
|
103166
|
+
bufferCtor;
|
|
103167
|
+
rootIno = 1;
|
|
103168
|
+
chunkSize = DEFAULT_CHUNK_SIZE;
|
|
103169
|
+
constructor(db, b) {
|
|
103170
|
+
this.db = db;
|
|
103171
|
+
this.bufferCtor = b;
|
|
103172
|
+
}
|
|
103173
|
+
static async fromDatabase(db, b) {
|
|
103174
|
+
const fs2 = new AgentFS(db, b ?? Buffer);
|
|
103175
|
+
await fs2.initialize();
|
|
103176
|
+
return fs2;
|
|
103177
|
+
}
|
|
103178
|
+
getChunkSize() {
|
|
103179
|
+
return this.chunkSize;
|
|
103180
|
+
}
|
|
103181
|
+
async initialize() {
|
|
103182
|
+
await this.db.exec(`
|
|
103183
|
+
CREATE TABLE IF NOT EXISTS fs_config (
|
|
103184
|
+
key TEXT PRIMARY KEY,
|
|
103185
|
+
value TEXT NOT NULL
|
|
103186
|
+
)
|
|
103187
|
+
`);
|
|
103188
|
+
await this.db.exec(`
|
|
103189
|
+
CREATE TABLE IF NOT EXISTS fs_inode (
|
|
103190
|
+
ino INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
103191
|
+
mode INTEGER NOT NULL,
|
|
103192
|
+
nlink INTEGER NOT NULL DEFAULT 0,
|
|
103193
|
+
uid INTEGER NOT NULL DEFAULT 0,
|
|
103194
|
+
gid INTEGER NOT NULL DEFAULT 0,
|
|
103195
|
+
size INTEGER NOT NULL DEFAULT 0,
|
|
103196
|
+
atime INTEGER NOT NULL,
|
|
103197
|
+
mtime INTEGER NOT NULL,
|
|
103198
|
+
ctime INTEGER NOT NULL,
|
|
103199
|
+
rdev INTEGER NOT NULL DEFAULT 0,
|
|
103200
|
+
atime_nsec INTEGER NOT NULL DEFAULT 0,
|
|
103201
|
+
mtime_nsec INTEGER NOT NULL DEFAULT 0,
|
|
103202
|
+
ctime_nsec INTEGER NOT NULL DEFAULT 0
|
|
103203
|
+
)
|
|
103204
|
+
`);
|
|
103205
|
+
await this.db.exec(`
|
|
103206
|
+
CREATE TABLE IF NOT EXISTS fs_dentry (
|
|
103207
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
103208
|
+
name TEXT NOT NULL,
|
|
103209
|
+
parent_ino INTEGER NOT NULL,
|
|
103210
|
+
ino INTEGER NOT NULL,
|
|
103211
|
+
UNIQUE(parent_ino, name)
|
|
103212
|
+
)
|
|
103213
|
+
`);
|
|
103214
|
+
await this.db.exec(`
|
|
103215
|
+
CREATE INDEX IF NOT EXISTS idx_fs_dentry_parent
|
|
103216
|
+
ON fs_dentry(parent_ino, name)
|
|
103217
|
+
`);
|
|
103218
|
+
await this.db.exec(`
|
|
103219
|
+
CREATE TABLE IF NOT EXISTS fs_data (
|
|
103220
|
+
ino INTEGER NOT NULL,
|
|
103221
|
+
chunk_index INTEGER NOT NULL,
|
|
103222
|
+
data BLOB NOT NULL,
|
|
103223
|
+
PRIMARY KEY (ino, chunk_index)
|
|
103224
|
+
)
|
|
103225
|
+
`);
|
|
103226
|
+
await this.db.exec(`
|
|
103227
|
+
CREATE TABLE IF NOT EXISTS fs_symlink (
|
|
103228
|
+
ino INTEGER PRIMARY KEY,
|
|
103229
|
+
target TEXT NOT NULL
|
|
103230
|
+
)
|
|
103231
|
+
`);
|
|
103232
|
+
this.chunkSize = await this.ensureRoot();
|
|
103233
|
+
}
|
|
103234
|
+
async ensureRoot() {
|
|
103235
|
+
const configStmt = this.db.prepare("SELECT value FROM fs_config WHERE key = 'chunk_size'");
|
|
103236
|
+
const config3 = await configStmt.get();
|
|
103237
|
+
let chunkSize;
|
|
103238
|
+
if (!config3) {
|
|
103239
|
+
const insertConfigStmt = this.db.prepare(`
|
|
103240
|
+
INSERT INTO fs_config (key, value) VALUES ('chunk_size', ?)
|
|
103241
|
+
`);
|
|
103242
|
+
await insertConfigStmt.run(DEFAULT_CHUNK_SIZE.toString());
|
|
103243
|
+
chunkSize = DEFAULT_CHUNK_SIZE;
|
|
103244
|
+
} else {
|
|
103245
|
+
chunkSize = parseInt(config3.value, 10) || DEFAULT_CHUNK_SIZE;
|
|
103246
|
+
}
|
|
103247
|
+
const schemaVersionStmt = this.db.prepare(`
|
|
103248
|
+
INSERT OR REPLACE INTO fs_config (key, value) VALUES ('schema_version', '0.4')
|
|
103249
|
+
`);
|
|
103250
|
+
await schemaVersionStmt.run();
|
|
103251
|
+
const stmt = this.db.prepare("SELECT ino FROM fs_inode WHERE ino = ?");
|
|
103252
|
+
const root = await stmt.get(this.rootIno);
|
|
103253
|
+
if (!root) {
|
|
103254
|
+
const now = Math.floor(Date.now() / 1000);
|
|
103255
|
+
const insertStmt = this.db.prepare(`
|
|
103256
|
+
INSERT INTO fs_inode (ino, mode, nlink, uid, gid, size, atime, mtime, ctime)
|
|
103257
|
+
VALUES (?, ?, 1, 0, 0, 0, ?, ?, ?)
|
|
103258
|
+
`);
|
|
103259
|
+
await insertStmt.run(this.rootIno, DEFAULT_DIR_MODE, now, now, now);
|
|
103260
|
+
}
|
|
103261
|
+
return chunkSize;
|
|
103262
|
+
}
|
|
103263
|
+
normalizePath(path4) {
|
|
103264
|
+
const normalized = path4.replace(/\/+$/, "") || "/";
|
|
103265
|
+
return normalized.startsWith("/") ? normalized : "/" + normalized;
|
|
103266
|
+
}
|
|
103267
|
+
splitPath(path4) {
|
|
103268
|
+
const normalized = this.normalizePath(path4);
|
|
103269
|
+
if (normalized === "/")
|
|
103270
|
+
return [];
|
|
103271
|
+
return normalized.split("/").filter((p3) => p3);
|
|
103272
|
+
}
|
|
103273
|
+
async resolvePathOrThrow(path4, syscall) {
|
|
103274
|
+
const normalizedPath = this.normalizePath(path4);
|
|
103275
|
+
const ino = await this.resolvePath(normalizedPath);
|
|
103276
|
+
if (ino === null) {
|
|
103277
|
+
throw createFsError({
|
|
103278
|
+
code: "ENOENT",
|
|
103279
|
+
syscall,
|
|
103280
|
+
path: normalizedPath,
|
|
103281
|
+
message: "no such file or directory"
|
|
103282
|
+
});
|
|
103283
|
+
}
|
|
103284
|
+
return { normalizedPath, ino };
|
|
103285
|
+
}
|
|
103286
|
+
async resolvePath(path4) {
|
|
103287
|
+
const normalized = this.normalizePath(path4);
|
|
103288
|
+
if (normalized === "/") {
|
|
103289
|
+
return this.rootIno;
|
|
103290
|
+
}
|
|
103291
|
+
const parts3 = this.splitPath(normalized);
|
|
103292
|
+
let currentIno = this.rootIno;
|
|
103293
|
+
for (const name21 of parts3) {
|
|
103294
|
+
const stmt = this.db.prepare(`
|
|
103295
|
+
SELECT ino FROM fs_dentry
|
|
103296
|
+
WHERE parent_ino = ? AND name = ?
|
|
103297
|
+
`);
|
|
103298
|
+
const result = await stmt.get(currentIno, name21);
|
|
103299
|
+
if (!result) {
|
|
103300
|
+
return null;
|
|
103301
|
+
}
|
|
103302
|
+
currentIno = result.ino;
|
|
103303
|
+
}
|
|
103304
|
+
return currentIno;
|
|
103305
|
+
}
|
|
103306
|
+
async resolveParent(path4) {
|
|
103307
|
+
const normalized = this.normalizePath(path4);
|
|
103308
|
+
if (normalized === "/") {
|
|
103309
|
+
return null;
|
|
103310
|
+
}
|
|
103311
|
+
const parts3 = this.splitPath(normalized);
|
|
103312
|
+
const name21 = parts3[parts3.length - 1];
|
|
103313
|
+
const parentPath = parts3.length === 1 ? "/" : "/" + parts3.slice(0, -1).join("/");
|
|
103314
|
+
const parentIno = await this.resolvePath(parentPath);
|
|
103315
|
+
if (parentIno === null) {
|
|
103316
|
+
return null;
|
|
103317
|
+
}
|
|
103318
|
+
return { parentIno, name: name21 };
|
|
103319
|
+
}
|
|
103320
|
+
async createInode(mode, uid = 0, gid = 0) {
|
|
103321
|
+
const now = Math.floor(Date.now() / 1000);
|
|
103322
|
+
const stmt = this.db.prepare(`
|
|
103323
|
+
INSERT INTO fs_inode (mode, uid, gid, size, atime, mtime, ctime)
|
|
103324
|
+
VALUES (?, ?, ?, 0, ?, ?, ?)
|
|
103325
|
+
RETURNING ino
|
|
103326
|
+
`);
|
|
103327
|
+
const { ino } = await stmt.get(mode, uid, gid, now, now, now);
|
|
103328
|
+
return Number(ino);
|
|
103329
|
+
}
|
|
103330
|
+
async createDentry(parentIno, name21, ino) {
|
|
103331
|
+
const stmt = this.db.prepare(`
|
|
103332
|
+
INSERT INTO fs_dentry (name, parent_ino, ino)
|
|
103333
|
+
VALUES (?, ?, ?)
|
|
103334
|
+
`);
|
|
103335
|
+
await stmt.run(name21, parentIno, ino);
|
|
103336
|
+
const updateStmt = this.db.prepare("UPDATE fs_inode SET nlink = nlink + 1 WHERE ino = ?");
|
|
103337
|
+
await updateStmt.run(ino);
|
|
103338
|
+
}
|
|
103339
|
+
async ensureParentDirs(path4) {
|
|
103340
|
+
const parts3 = this.splitPath(path4);
|
|
103341
|
+
parts3.pop();
|
|
103342
|
+
let currentIno = this.rootIno;
|
|
103343
|
+
for (const name21 of parts3) {
|
|
103344
|
+
const stmt = this.db.prepare(`
|
|
103345
|
+
SELECT ino FROM fs_dentry
|
|
103346
|
+
WHERE parent_ino = ? AND name = ?
|
|
103347
|
+
`);
|
|
103348
|
+
const result = await stmt.get(currentIno, name21);
|
|
103349
|
+
if (!result) {
|
|
103350
|
+
const dirIno = await this.createInode(DEFAULT_DIR_MODE);
|
|
103351
|
+
await this.createDentry(currentIno, name21, dirIno);
|
|
103352
|
+
currentIno = dirIno;
|
|
103353
|
+
} else {
|
|
103354
|
+
await assertInodeIsDirectory(this.db, result.ino, "open", this.normalizePath(path4));
|
|
103355
|
+
currentIno = result.ino;
|
|
103356
|
+
}
|
|
103357
|
+
}
|
|
103358
|
+
}
|
|
103359
|
+
async getLinkCount(ino) {
|
|
103360
|
+
const stmt = this.db.prepare("SELECT nlink FROM fs_inode WHERE ino = ?");
|
|
103361
|
+
const result = await stmt.get(ino);
|
|
103362
|
+
return result?.nlink ?? 0;
|
|
103363
|
+
}
|
|
103364
|
+
async getInodeMode(ino) {
|
|
103365
|
+
const stmt = this.db.prepare("SELECT mode FROM fs_inode WHERE ino = ?");
|
|
103366
|
+
const row = await stmt.get(ino);
|
|
103367
|
+
return row?.mode ?? null;
|
|
103368
|
+
}
|
|
103369
|
+
async writeFile(path4, content, options7) {
|
|
103370
|
+
await this.ensureParentDirs(path4);
|
|
103371
|
+
const ino = await this.resolvePath(path4);
|
|
103372
|
+
const encoding = typeof options7 === "string" ? options7 : options7?.encoding;
|
|
103373
|
+
const normalizedPath = this.normalizePath(path4);
|
|
103374
|
+
if (ino !== null) {
|
|
103375
|
+
await assertWritableExistingInode(this.db, ino, "open", normalizedPath);
|
|
103376
|
+
await this.updateFileContent(ino, content, encoding);
|
|
103377
|
+
} else {
|
|
103378
|
+
const parent = await this.resolveParent(path4);
|
|
103379
|
+
if (!parent) {
|
|
103380
|
+
throw createFsError({
|
|
103381
|
+
code: "ENOENT",
|
|
103382
|
+
syscall: "open",
|
|
103383
|
+
path: normalizedPath,
|
|
103384
|
+
message: "no such file or directory"
|
|
103385
|
+
});
|
|
103386
|
+
}
|
|
103387
|
+
await assertInodeIsDirectory(this.db, parent.parentIno, "open", normalizedPath);
|
|
103388
|
+
const fileIno = await this.createInode(DEFAULT_FILE_MODE);
|
|
103389
|
+
await this.createDentry(parent.parentIno, parent.name, fileIno);
|
|
103390
|
+
await this.updateFileContent(fileIno, content, encoding);
|
|
103391
|
+
}
|
|
103392
|
+
}
|
|
103393
|
+
async updateFileContent(ino, content, encoding) {
|
|
103394
|
+
const buffer3 = typeof content === "string" ? this.bufferCtor.from(content, encoding ?? "utf8") : content;
|
|
103395
|
+
const now = Math.floor(Date.now() / 1000);
|
|
103396
|
+
const deleteStmt = this.db.prepare("DELETE FROM fs_data WHERE ino = ?");
|
|
103397
|
+
await deleteStmt.run(ino);
|
|
103398
|
+
if (buffer3.length > 0) {
|
|
103399
|
+
const stmt = this.db.prepare(`
|
|
103400
|
+
INSERT INTO fs_data (ino, chunk_index, data)
|
|
103401
|
+
VALUES (?, ?, ?)
|
|
103402
|
+
`);
|
|
103403
|
+
let chunkIndex = 0;
|
|
103404
|
+
for (let offset = 0;offset < buffer3.length; offset += this.chunkSize) {
|
|
103405
|
+
const chunk4 = buffer3.subarray(offset, Math.min(offset + this.chunkSize, buffer3.length));
|
|
103406
|
+
await stmt.run(ino, chunkIndex, chunk4);
|
|
103407
|
+
chunkIndex++;
|
|
103408
|
+
}
|
|
103409
|
+
}
|
|
103410
|
+
const updateStmt = this.db.prepare(`
|
|
103411
|
+
UPDATE fs_inode
|
|
103412
|
+
SET size = ?, mtime = ?
|
|
103413
|
+
WHERE ino = ?
|
|
103414
|
+
`);
|
|
103415
|
+
await updateStmt.run(buffer3.length, now, ino);
|
|
103416
|
+
}
|
|
103417
|
+
async readFile(path4, options7) {
|
|
103418
|
+
const encoding = typeof options7 === "string" ? options7 : options7?.encoding;
|
|
103419
|
+
const { normalizedPath, ino } = await this.resolvePathOrThrow(path4, "open");
|
|
103420
|
+
await assertReadableExistingInode(this.db, ino, "open", normalizedPath);
|
|
103421
|
+
const stmt = this.db.prepare(`
|
|
103422
|
+
SELECT data FROM fs_data
|
|
103423
|
+
WHERE ino = ?
|
|
103424
|
+
ORDER BY chunk_index ASC
|
|
103425
|
+
`);
|
|
103426
|
+
const rows = await stmt.all(ino);
|
|
103427
|
+
let combined;
|
|
103428
|
+
if (rows.length === 0) {
|
|
103429
|
+
combined = this.bufferCtor.alloc(0);
|
|
103430
|
+
} else {
|
|
103431
|
+
const buffers = rows.map((row) => row.data);
|
|
103432
|
+
combined = this.bufferCtor.concat(buffers);
|
|
103433
|
+
}
|
|
103434
|
+
const now = Math.floor(Date.now() / 1000);
|
|
103435
|
+
const updateStmt = this.db.prepare("UPDATE fs_inode SET atime = ? WHERE ino = ?");
|
|
103436
|
+
await updateStmt.run(now, ino);
|
|
103437
|
+
if (encoding) {
|
|
103438
|
+
return combined.toString(encoding);
|
|
103439
|
+
}
|
|
103440
|
+
return combined;
|
|
103441
|
+
}
|
|
103442
|
+
async readdir(path4) {
|
|
103443
|
+
const { normalizedPath, ino } = await this.resolvePathOrThrow(path4, "scandir");
|
|
103444
|
+
await assertReaddirTargetInode(this.db, ino, normalizedPath);
|
|
103445
|
+
const stmt = this.db.prepare(`
|
|
103446
|
+
SELECT name FROM fs_dentry
|
|
103447
|
+
WHERE parent_ino = ?
|
|
103448
|
+
ORDER BY name ASC
|
|
103449
|
+
`);
|
|
103450
|
+
const rows = await stmt.all(ino);
|
|
103451
|
+
return rows.map((row) => row.name);
|
|
103452
|
+
}
|
|
103453
|
+
async readdirPlus(path4) {
|
|
103454
|
+
const { normalizedPath, ino } = await this.resolvePathOrThrow(path4, "scandir");
|
|
103455
|
+
await assertReaddirTargetInode(this.db, ino, normalizedPath);
|
|
103456
|
+
const stmt = this.db.prepare(`
|
|
103457
|
+
SELECT d.name, i.ino, i.mode, i.nlink, i.uid, i.gid, i.size, i.atime, i.mtime, i.ctime
|
|
103458
|
+
FROM fs_dentry d
|
|
103459
|
+
JOIN fs_inode i ON d.ino = i.ino
|
|
103460
|
+
WHERE d.parent_ino = ?
|
|
103461
|
+
ORDER BY d.name ASC
|
|
103462
|
+
`);
|
|
103463
|
+
const rows = await stmt.all(ino);
|
|
103464
|
+
return rows.map((row) => ({
|
|
103465
|
+
name: row.name,
|
|
103466
|
+
stats: createStats({
|
|
103467
|
+
ino: row.ino,
|
|
103468
|
+
mode: row.mode,
|
|
103469
|
+
nlink: row.nlink,
|
|
103470
|
+
uid: row.uid,
|
|
103471
|
+
gid: row.gid,
|
|
103472
|
+
size: row.size,
|
|
103473
|
+
atime: row.atime,
|
|
103474
|
+
mtime: row.mtime,
|
|
103475
|
+
ctime: row.ctime
|
|
103476
|
+
})
|
|
103477
|
+
}));
|
|
103478
|
+
}
|
|
103479
|
+
async stat(path4) {
|
|
103480
|
+
const { normalizedPath, ino } = await this.resolvePathOrThrow(path4, "stat");
|
|
103481
|
+
const stmt = this.db.prepare(`
|
|
103482
|
+
SELECT ino, mode, nlink, uid, gid, size, atime, mtime, ctime
|
|
103483
|
+
FROM fs_inode
|
|
103484
|
+
WHERE ino = ?
|
|
103485
|
+
`);
|
|
103486
|
+
const row = await stmt.get(ino);
|
|
103487
|
+
if (!row) {
|
|
103488
|
+
throw createFsError({
|
|
103489
|
+
code: "ENOENT",
|
|
103490
|
+
syscall: "stat",
|
|
103491
|
+
path: normalizedPath,
|
|
103492
|
+
message: "no such file or directory"
|
|
103493
|
+
});
|
|
103494
|
+
}
|
|
103495
|
+
return createStats(row);
|
|
103496
|
+
}
|
|
103497
|
+
async lstat(path4) {
|
|
103498
|
+
return this.stat(path4);
|
|
103499
|
+
}
|
|
103500
|
+
async mkdir(path4) {
|
|
103501
|
+
const normalizedPath = this.normalizePath(path4);
|
|
103502
|
+
const existing = await this.resolvePath(normalizedPath);
|
|
103503
|
+
if (existing !== null) {
|
|
103504
|
+
throw createFsError({
|
|
103505
|
+
code: "EEXIST",
|
|
103506
|
+
syscall: "mkdir",
|
|
103507
|
+
path: normalizedPath,
|
|
103508
|
+
message: "file already exists"
|
|
103509
|
+
});
|
|
103510
|
+
}
|
|
103511
|
+
const parent = await this.resolveParent(normalizedPath);
|
|
103512
|
+
if (!parent) {
|
|
103513
|
+
throw createFsError({
|
|
103514
|
+
code: "ENOENT",
|
|
103515
|
+
syscall: "mkdir",
|
|
103516
|
+
path: normalizedPath,
|
|
103517
|
+
message: "no such file or directory"
|
|
103518
|
+
});
|
|
103519
|
+
}
|
|
103520
|
+
await assertInodeIsDirectory(this.db, parent.parentIno, "mkdir", normalizedPath);
|
|
103521
|
+
const dirIno = await this.createInode(DEFAULT_DIR_MODE);
|
|
103522
|
+
try {
|
|
103523
|
+
await this.createDentry(parent.parentIno, parent.name, dirIno);
|
|
103524
|
+
} catch {
|
|
103525
|
+
throw createFsError({
|
|
103526
|
+
code: "EEXIST",
|
|
103527
|
+
syscall: "mkdir",
|
|
103528
|
+
path: normalizedPath,
|
|
103529
|
+
message: "file already exists"
|
|
103530
|
+
});
|
|
103531
|
+
}
|
|
103532
|
+
}
|
|
103533
|
+
async rmdir(path4) {
|
|
103534
|
+
const normalizedPath = this.normalizePath(path4);
|
|
103535
|
+
assertNotRoot(normalizedPath, "rmdir");
|
|
103536
|
+
const { ino } = await this.resolvePathOrThrow(normalizedPath, "rmdir");
|
|
103537
|
+
const mode = await getInodeModeOrThrow(this.db, ino, "rmdir", normalizedPath);
|
|
103538
|
+
assertNotSymlinkMode(mode, "rmdir", normalizedPath);
|
|
103539
|
+
if ((mode & S_IFMT) !== S_IFDIR) {
|
|
103540
|
+
throw createFsError({
|
|
103541
|
+
code: "ENOTDIR",
|
|
103542
|
+
syscall: "rmdir",
|
|
103543
|
+
path: normalizedPath,
|
|
103544
|
+
message: "not a directory"
|
|
103545
|
+
});
|
|
103546
|
+
}
|
|
103547
|
+
const stmt = this.db.prepare(`
|
|
103548
|
+
SELECT 1 as one FROM fs_dentry
|
|
103549
|
+
WHERE parent_ino = ?
|
|
103550
|
+
LIMIT 1
|
|
103551
|
+
`);
|
|
103552
|
+
const child = await stmt.get(ino);
|
|
103553
|
+
if (child) {
|
|
103554
|
+
throw createFsError({
|
|
103555
|
+
code: "ENOTEMPTY",
|
|
103556
|
+
syscall: "rmdir",
|
|
103557
|
+
path: normalizedPath,
|
|
103558
|
+
message: "directory not empty"
|
|
103559
|
+
});
|
|
103560
|
+
}
|
|
103561
|
+
const parent = await this.resolveParent(normalizedPath);
|
|
103562
|
+
if (!parent) {
|
|
103563
|
+
throw createFsError({
|
|
103564
|
+
code: "EPERM",
|
|
103565
|
+
syscall: "rmdir",
|
|
103566
|
+
path: normalizedPath,
|
|
103567
|
+
message: "operation not permitted"
|
|
103568
|
+
});
|
|
103569
|
+
}
|
|
103570
|
+
await this.removeDentryAndMaybeInode(parent.parentIno, parent.name, ino);
|
|
103571
|
+
}
|
|
103572
|
+
async unlink(path4) {
|
|
103573
|
+
const normalizedPath = this.normalizePath(path4);
|
|
103574
|
+
assertNotRoot(normalizedPath, "unlink");
|
|
103575
|
+
const { ino } = await this.resolvePathOrThrow(normalizedPath, "unlink");
|
|
103576
|
+
await assertUnlinkTargetInode(this.db, ino, normalizedPath);
|
|
103577
|
+
const parent = await this.resolveParent(normalizedPath);
|
|
103578
|
+
const stmt = this.db.prepare(`
|
|
103579
|
+
DELETE FROM fs_dentry
|
|
103580
|
+
WHERE parent_ino = ? AND name = ?
|
|
103581
|
+
`);
|
|
103582
|
+
await stmt.run(parent.parentIno, parent.name);
|
|
103583
|
+
const decrementStmt = this.db.prepare("UPDATE fs_inode SET nlink = nlink - 1 WHERE ino = ?");
|
|
103584
|
+
await decrementStmt.run(ino);
|
|
103585
|
+
const linkCount = await this.getLinkCount(ino);
|
|
103586
|
+
if (linkCount === 0) {
|
|
103587
|
+
const deleteInodeStmt = this.db.prepare("DELETE FROM fs_inode WHERE ino = ?");
|
|
103588
|
+
await deleteInodeStmt.run(ino);
|
|
103589
|
+
const deleteDataStmt = this.db.prepare("DELETE FROM fs_data WHERE ino = ?");
|
|
103590
|
+
await deleteDataStmt.run(ino);
|
|
103591
|
+
}
|
|
103592
|
+
}
|
|
103593
|
+
async rm(path4, options7) {
|
|
103594
|
+
const normalizedPath = this.normalizePath(path4);
|
|
103595
|
+
const { force, recursive } = normalizeRmOptions(options7);
|
|
103596
|
+
assertNotRoot(normalizedPath, "rm");
|
|
103597
|
+
const ino = await this.resolvePath(normalizedPath);
|
|
103598
|
+
if (ino === null) {
|
|
103599
|
+
throwENOENTUnlessForce(normalizedPath, "rm", force);
|
|
103600
|
+
return;
|
|
103601
|
+
}
|
|
103602
|
+
const mode = await getInodeModeOrThrow(this.db, ino, "rm", normalizedPath);
|
|
103603
|
+
assertNotSymlinkMode(mode, "rm", normalizedPath);
|
|
103604
|
+
const parent = await this.resolveParent(normalizedPath);
|
|
103605
|
+
if (!parent) {
|
|
103606
|
+
throw createFsError({
|
|
103607
|
+
code: "EPERM",
|
|
103608
|
+
syscall: "rm",
|
|
103609
|
+
path: normalizedPath,
|
|
103610
|
+
message: "operation not permitted"
|
|
103611
|
+
});
|
|
103612
|
+
}
|
|
103613
|
+
if ((mode & S_IFMT) === S_IFDIR) {
|
|
103614
|
+
if (!recursive) {
|
|
103615
|
+
throw createFsError({
|
|
103616
|
+
code: "EISDIR",
|
|
103617
|
+
syscall: "rm",
|
|
103618
|
+
path: normalizedPath,
|
|
103619
|
+
message: "illegal operation on a directory"
|
|
103620
|
+
});
|
|
103621
|
+
}
|
|
103622
|
+
await this.rmDirContentsRecursive(ino);
|
|
103623
|
+
await this.removeDentryAndMaybeInode(parent.parentIno, parent.name, ino);
|
|
103624
|
+
return;
|
|
103625
|
+
}
|
|
103626
|
+
await this.removeDentryAndMaybeInode(parent.parentIno, parent.name, ino);
|
|
103627
|
+
}
|
|
103628
|
+
async rmDirContentsRecursive(dirIno) {
|
|
103629
|
+
const stmt = this.db.prepare(`
|
|
103630
|
+
SELECT name, ino FROM fs_dentry
|
|
103631
|
+
WHERE parent_ino = ?
|
|
103632
|
+
ORDER BY name ASC
|
|
103633
|
+
`);
|
|
103634
|
+
const children2 = await stmt.all(dirIno);
|
|
103635
|
+
for (const child of children2) {
|
|
103636
|
+
const mode = await this.getInodeMode(child.ino);
|
|
103637
|
+
if (mode === null) {
|
|
103638
|
+
continue;
|
|
103639
|
+
}
|
|
103640
|
+
if ((mode & S_IFMT) === S_IFDIR) {
|
|
103641
|
+
await this.rmDirContentsRecursive(child.ino);
|
|
103642
|
+
await this.removeDentryAndMaybeInode(dirIno, child.name, child.ino);
|
|
103643
|
+
} else {
|
|
103644
|
+
assertNotSymlinkMode(mode, "rm", "<symlink>");
|
|
103645
|
+
await this.removeDentryAndMaybeInode(dirIno, child.name, child.ino);
|
|
103646
|
+
}
|
|
103647
|
+
}
|
|
103648
|
+
}
|
|
103649
|
+
async removeDentryAndMaybeInode(parentIno, name21, ino) {
|
|
103650
|
+
const stmt = this.db.prepare(`
|
|
103651
|
+
DELETE FROM fs_dentry
|
|
103652
|
+
WHERE parent_ino = ? AND name = ?
|
|
103653
|
+
`);
|
|
103654
|
+
await stmt.run(parentIno, name21);
|
|
103655
|
+
const decrementStmt = this.db.prepare("UPDATE fs_inode SET nlink = nlink - 1 WHERE ino = ?");
|
|
103656
|
+
await decrementStmt.run(ino);
|
|
103657
|
+
const linkCount = await this.getLinkCount(ino);
|
|
103658
|
+
if (linkCount === 0) {
|
|
103659
|
+
const deleteInodeStmt = this.db.prepare("DELETE FROM fs_inode WHERE ino = ?");
|
|
103660
|
+
await deleteInodeStmt.run(ino);
|
|
103661
|
+
const deleteDataStmt = this.db.prepare("DELETE FROM fs_data WHERE ino = ?");
|
|
103662
|
+
await deleteDataStmt.run(ino);
|
|
103663
|
+
const deleteSymlinkStmt = this.db.prepare("DELETE FROM fs_symlink WHERE ino = ?");
|
|
103664
|
+
await deleteSymlinkStmt.run(ino);
|
|
103665
|
+
}
|
|
103666
|
+
}
|
|
103667
|
+
async rename(oldPath, newPath) {
|
|
103668
|
+
const oldNormalized = this.normalizePath(oldPath);
|
|
103669
|
+
const newNormalized = this.normalizePath(newPath);
|
|
103670
|
+
if (oldNormalized === newNormalized)
|
|
103671
|
+
return;
|
|
103672
|
+
assertNotRoot(oldNormalized, "rename");
|
|
103673
|
+
assertNotRoot(newNormalized, "rename");
|
|
103674
|
+
const oldParent = await this.resolveParent(oldNormalized);
|
|
103675
|
+
if (!oldParent) {
|
|
103676
|
+
throw createFsError({
|
|
103677
|
+
code: "EPERM",
|
|
103678
|
+
syscall: "rename",
|
|
103679
|
+
path: oldNormalized,
|
|
103680
|
+
message: "operation not permitted"
|
|
103681
|
+
});
|
|
103682
|
+
}
|
|
103683
|
+
const newParent = await this.resolveParent(newNormalized);
|
|
103684
|
+
if (!newParent) {
|
|
103685
|
+
throw createFsError({
|
|
103686
|
+
code: "ENOENT",
|
|
103687
|
+
syscall: "rename",
|
|
103688
|
+
path: newNormalized,
|
|
103689
|
+
message: "no such file or directory"
|
|
103690
|
+
});
|
|
103691
|
+
}
|
|
103692
|
+
await assertInodeIsDirectory(this.db, newParent.parentIno, "rename", newNormalized);
|
|
103693
|
+
await this.db.exec("BEGIN");
|
|
103694
|
+
try {
|
|
103695
|
+
const oldResolved = await this.resolvePathOrThrow(oldNormalized, "rename");
|
|
103696
|
+
const oldIno = oldResolved.ino;
|
|
103697
|
+
const oldMode = await getInodeModeOrThrow(this.db, oldIno, "rename", oldNormalized);
|
|
103698
|
+
assertNotSymlinkMode(oldMode, "rename", oldNormalized);
|
|
103699
|
+
const oldIsDir = (oldMode & S_IFMT) === S_IFDIR;
|
|
103700
|
+
if (oldIsDir && newNormalized.startsWith(oldNormalized + "/")) {
|
|
103701
|
+
throw createFsError({
|
|
103702
|
+
code: "EINVAL",
|
|
103703
|
+
syscall: "rename",
|
|
103704
|
+
path: newNormalized,
|
|
103705
|
+
message: "invalid argument"
|
|
103706
|
+
});
|
|
103707
|
+
}
|
|
103708
|
+
const newIno = await this.resolvePath(newNormalized);
|
|
103709
|
+
if (newIno !== null) {
|
|
103710
|
+
const newMode = await getInodeModeOrThrow(this.db, newIno, "rename", newNormalized);
|
|
103711
|
+
assertNotSymlinkMode(newMode, "rename", newNormalized);
|
|
103712
|
+
const newIsDir = (newMode & S_IFMT) === S_IFDIR;
|
|
103713
|
+
if (newIsDir && !oldIsDir) {
|
|
103714
|
+
throw createFsError({
|
|
103715
|
+
code: "EISDIR",
|
|
103716
|
+
syscall: "rename",
|
|
103717
|
+
path: newNormalized,
|
|
103718
|
+
message: "illegal operation on a directory"
|
|
103719
|
+
});
|
|
103720
|
+
}
|
|
103721
|
+
if (!newIsDir && oldIsDir) {
|
|
103722
|
+
throw createFsError({
|
|
103723
|
+
code: "ENOTDIR",
|
|
103724
|
+
syscall: "rename",
|
|
103725
|
+
path: newNormalized,
|
|
103726
|
+
message: "not a directory"
|
|
103727
|
+
});
|
|
103728
|
+
}
|
|
103729
|
+
if (newIsDir) {
|
|
103730
|
+
const stmt2 = this.db.prepare(`
|
|
103731
|
+
SELECT 1 as one FROM fs_dentry
|
|
103732
|
+
WHERE parent_ino = ?
|
|
103733
|
+
LIMIT 1
|
|
103734
|
+
`);
|
|
103735
|
+
const child = await stmt2.get(newIno);
|
|
103736
|
+
if (child) {
|
|
103737
|
+
throw createFsError({
|
|
103738
|
+
code: "ENOTEMPTY",
|
|
103739
|
+
syscall: "rename",
|
|
103740
|
+
path: newNormalized,
|
|
103741
|
+
message: "directory not empty"
|
|
103742
|
+
});
|
|
103743
|
+
}
|
|
103744
|
+
}
|
|
103745
|
+
await this.removeDentryAndMaybeInode(newParent.parentIno, newParent.name, newIno);
|
|
103746
|
+
}
|
|
103747
|
+
const stmt = this.db.prepare(`
|
|
103748
|
+
UPDATE fs_dentry
|
|
103749
|
+
SET parent_ino = ?, name = ?
|
|
103750
|
+
WHERE parent_ino = ? AND name = ?
|
|
103751
|
+
`);
|
|
103752
|
+
await stmt.run(newParent.parentIno, newParent.name, oldParent.parentIno, oldParent.name);
|
|
103753
|
+
const now = Math.floor(Date.now() / 1000);
|
|
103754
|
+
const updateInodeCtimeStmt = this.db.prepare(`
|
|
103755
|
+
UPDATE fs_inode
|
|
103756
|
+
SET ctime = ?
|
|
103757
|
+
WHERE ino = ?
|
|
103758
|
+
`);
|
|
103759
|
+
await updateInodeCtimeStmt.run(now, oldIno);
|
|
103760
|
+
const updateDirTimesStmt = this.db.prepare(`
|
|
103761
|
+
UPDATE fs_inode
|
|
103762
|
+
SET mtime = ?, ctime = ?
|
|
103763
|
+
WHERE ino = ?
|
|
103764
|
+
`);
|
|
103765
|
+
await updateDirTimesStmt.run(now, now, oldParent.parentIno);
|
|
103766
|
+
if (newParent.parentIno !== oldParent.parentIno) {
|
|
103767
|
+
await updateDirTimesStmt.run(now, now, newParent.parentIno);
|
|
103768
|
+
}
|
|
103769
|
+
await this.db.exec("COMMIT");
|
|
103770
|
+
} catch (e) {
|
|
103771
|
+
await this.db.exec("ROLLBACK");
|
|
103772
|
+
throw e;
|
|
103773
|
+
}
|
|
103774
|
+
}
|
|
103775
|
+
async copyFile(src, dest) {
|
|
103776
|
+
const srcNormalized = this.normalizePath(src);
|
|
103777
|
+
const destNormalized = this.normalizePath(dest);
|
|
103778
|
+
if (srcNormalized === destNormalized) {
|
|
103779
|
+
throw createFsError({
|
|
103780
|
+
code: "EINVAL",
|
|
103781
|
+
syscall: "copyfile",
|
|
103782
|
+
path: destNormalized,
|
|
103783
|
+
message: "invalid argument"
|
|
103784
|
+
});
|
|
103785
|
+
}
|
|
103786
|
+
const { ino: srcIno } = await this.resolvePathOrThrow(srcNormalized, "copyfile");
|
|
103787
|
+
await assertReadableExistingInode(this.db, srcIno, "copyfile", srcNormalized);
|
|
103788
|
+
const stmt = this.db.prepare(`
|
|
103789
|
+
SELECT mode, uid, gid, size FROM fs_inode WHERE ino = ?
|
|
103790
|
+
`);
|
|
103791
|
+
const srcRow = await stmt.get(srcIno);
|
|
103792
|
+
if (!srcRow) {
|
|
103793
|
+
throw createFsError({
|
|
103794
|
+
code: "ENOENT",
|
|
103795
|
+
syscall: "copyfile",
|
|
103796
|
+
path: srcNormalized,
|
|
103797
|
+
message: "no such file or directory"
|
|
103798
|
+
});
|
|
103799
|
+
}
|
|
103800
|
+
const destParent = await this.resolveParent(destNormalized);
|
|
103801
|
+
if (!destParent) {
|
|
103802
|
+
throw createFsError({
|
|
103803
|
+
code: "ENOENT",
|
|
103804
|
+
syscall: "copyfile",
|
|
103805
|
+
path: destNormalized,
|
|
103806
|
+
message: "no such file or directory"
|
|
103807
|
+
});
|
|
103808
|
+
}
|
|
103809
|
+
await assertInodeIsDirectory(this.db, destParent.parentIno, "copyfile", destNormalized);
|
|
103810
|
+
await this.db.exec("BEGIN");
|
|
103811
|
+
try {
|
|
103812
|
+
const now = Math.floor(Date.now() / 1000);
|
|
103813
|
+
const destIno = await this.resolvePath(destNormalized);
|
|
103814
|
+
if (destIno !== null) {
|
|
103815
|
+
const destMode = await getInodeModeOrThrow(this.db, destIno, "copyfile", destNormalized);
|
|
103816
|
+
assertNotSymlinkMode(destMode, "copyfile", destNormalized);
|
|
103817
|
+
if ((destMode & S_IFMT) === S_IFDIR) {
|
|
103818
|
+
throw createFsError({
|
|
103819
|
+
code: "EISDIR",
|
|
103820
|
+
syscall: "copyfile",
|
|
103821
|
+
path: destNormalized,
|
|
103822
|
+
message: "illegal operation on a directory"
|
|
103823
|
+
});
|
|
103824
|
+
}
|
|
103825
|
+
const deleteStmt = this.db.prepare("DELETE FROM fs_data WHERE ino = ?");
|
|
103826
|
+
await deleteStmt.run(destIno);
|
|
103827
|
+
const copyStmt = this.db.prepare(`
|
|
103828
|
+
INSERT INTO fs_data (ino, chunk_index, data)
|
|
103829
|
+
SELECT ?, chunk_index, data
|
|
103830
|
+
FROM fs_data
|
|
103831
|
+
WHERE ino = ?
|
|
103832
|
+
ORDER BY chunk_index ASC
|
|
103833
|
+
`);
|
|
103834
|
+
await copyStmt.run(destIno, srcIno);
|
|
103835
|
+
const updateStmt = this.db.prepare(`
|
|
103836
|
+
UPDATE fs_inode
|
|
103837
|
+
SET mode = ?, uid = ?, gid = ?, size = ?, mtime = ?, ctime = ?
|
|
103838
|
+
WHERE ino = ?
|
|
103839
|
+
`);
|
|
103840
|
+
await updateStmt.run(srcRow.mode, srcRow.uid, srcRow.gid, srcRow.size, now, now, destIno);
|
|
103841
|
+
} else {
|
|
103842
|
+
const destInoCreated = await this.createInode(srcRow.mode, srcRow.uid, srcRow.gid);
|
|
103843
|
+
await this.createDentry(destParent.parentIno, destParent.name, destInoCreated);
|
|
103844
|
+
const copyStmt = this.db.prepare(`
|
|
103845
|
+
INSERT INTO fs_data (ino, chunk_index, data)
|
|
103846
|
+
SELECT ?, chunk_index, data
|
|
103847
|
+
FROM fs_data
|
|
103848
|
+
WHERE ino = ?
|
|
103849
|
+
ORDER BY chunk_index ASC
|
|
103850
|
+
`);
|
|
103851
|
+
await copyStmt.run(destInoCreated, srcIno);
|
|
103852
|
+
const updateStmt = this.db.prepare(`
|
|
103853
|
+
UPDATE fs_inode
|
|
103854
|
+
SET size = ?, mtime = ?, ctime = ?
|
|
103855
|
+
WHERE ino = ?
|
|
103856
|
+
`);
|
|
103857
|
+
await updateStmt.run(srcRow.size, now, now, destInoCreated);
|
|
103858
|
+
}
|
|
103859
|
+
await this.db.exec("COMMIT");
|
|
103860
|
+
} catch (e) {
|
|
103861
|
+
await this.db.exec("ROLLBACK");
|
|
103862
|
+
throw e;
|
|
103863
|
+
}
|
|
103864
|
+
}
|
|
103865
|
+
async symlink(target, linkpath) {
|
|
103866
|
+
const normalizedLinkpath = this.normalizePath(linkpath);
|
|
103867
|
+
const existing = await this.resolvePath(normalizedLinkpath);
|
|
103868
|
+
if (existing !== null) {
|
|
103869
|
+
throw createFsError({
|
|
103870
|
+
code: "EEXIST",
|
|
103871
|
+
syscall: "open",
|
|
103872
|
+
path: normalizedLinkpath,
|
|
103873
|
+
message: "file already exists"
|
|
103874
|
+
});
|
|
103875
|
+
}
|
|
103876
|
+
const parent = await this.resolveParent(normalizedLinkpath);
|
|
103877
|
+
if (!parent) {
|
|
103878
|
+
throw createFsError({
|
|
103879
|
+
code: "ENOENT",
|
|
103880
|
+
syscall: "open",
|
|
103881
|
+
path: normalizedLinkpath,
|
|
103882
|
+
message: "no such file or directory"
|
|
103883
|
+
});
|
|
103884
|
+
}
|
|
103885
|
+
await assertInodeIsDirectory(this.db, parent.parentIno, "open", normalizedLinkpath);
|
|
103886
|
+
const mode = S_IFLNK | 511;
|
|
103887
|
+
const symlinkIno = await this.createInode(mode);
|
|
103888
|
+
await this.createDentry(parent.parentIno, parent.name, symlinkIno);
|
|
103889
|
+
const stmt = this.db.prepare("INSERT INTO fs_symlink (ino, target) VALUES (?, ?)");
|
|
103890
|
+
await stmt.run(symlinkIno, target);
|
|
103891
|
+
const updateStmt = this.db.prepare("UPDATE fs_inode SET size = ? WHERE ino = ?");
|
|
103892
|
+
await updateStmt.run(target.length, symlinkIno);
|
|
103893
|
+
}
|
|
103894
|
+
async readlink(path4) {
|
|
103895
|
+
const { normalizedPath, ino } = await this.resolvePathOrThrow(path4, "open");
|
|
103896
|
+
const mode = await this.getInodeMode(ino);
|
|
103897
|
+
if (mode === null || (mode & S_IFMT) !== S_IFLNK) {
|
|
103898
|
+
throw createFsError({
|
|
103899
|
+
code: "EINVAL",
|
|
103900
|
+
syscall: "open",
|
|
103901
|
+
path: normalizedPath,
|
|
103902
|
+
message: "invalid argument"
|
|
103903
|
+
});
|
|
103904
|
+
}
|
|
103905
|
+
const stmt = this.db.prepare("SELECT target FROM fs_symlink WHERE ino = ?");
|
|
103906
|
+
const row = await stmt.get(ino);
|
|
103907
|
+
if (!row) {
|
|
103908
|
+
throw createFsError({
|
|
103909
|
+
code: "ENOENT",
|
|
103910
|
+
syscall: "open",
|
|
103911
|
+
path: normalizedPath,
|
|
103912
|
+
message: "no such file or directory"
|
|
103913
|
+
});
|
|
103914
|
+
}
|
|
103915
|
+
return row.target;
|
|
103916
|
+
}
|
|
103917
|
+
async access(path4) {
|
|
103918
|
+
const normalizedPath = this.normalizePath(path4);
|
|
103919
|
+
const ino = await this.resolvePath(normalizedPath);
|
|
103920
|
+
if (ino === null) {
|
|
103921
|
+
throw createFsError({
|
|
103922
|
+
code: "ENOENT",
|
|
103923
|
+
syscall: "access",
|
|
103924
|
+
path: normalizedPath,
|
|
103925
|
+
message: "no such file or directory"
|
|
103926
|
+
});
|
|
103927
|
+
}
|
|
103928
|
+
}
|
|
103929
|
+
async statfs() {
|
|
103930
|
+
const inodeStmt = this.db.prepare("SELECT COUNT(*) as count FROM fs_inode");
|
|
103931
|
+
const inodeRow = await inodeStmt.get();
|
|
103932
|
+
const bytesStmt = this.db.prepare("SELECT COALESCE(SUM(LENGTH(data)), 0) as total FROM fs_data");
|
|
103933
|
+
const bytesRow = await bytesStmt.get();
|
|
103934
|
+
return {
|
|
103935
|
+
inodes: inodeRow.count,
|
|
103936
|
+
bytesUsed: bytesRow.total
|
|
103937
|
+
};
|
|
103938
|
+
}
|
|
103939
|
+
async open(path4) {
|
|
103940
|
+
const { normalizedPath, ino } = await this.resolvePathOrThrow(path4, "open");
|
|
103941
|
+
await assertReadableExistingInode(this.db, ino, "open", normalizedPath);
|
|
103942
|
+
return new AgentFSFile(this.db, this.bufferCtor, ino, this.chunkSize);
|
|
103943
|
+
}
|
|
103944
|
+
async deleteFile(path4) {
|
|
103945
|
+
return await this.unlink(path4);
|
|
103946
|
+
}
|
|
103947
|
+
}
|
|
103948
|
+
// ../../node_modules/.bun/agentfs-sdk@0.6.2/node_modules/agentfs-sdk/dist/toolcalls.js
|
|
103949
|
+
class ToolCalls {
|
|
103950
|
+
db;
|
|
103951
|
+
constructor(db) {
|
|
103952
|
+
this.db = db;
|
|
103953
|
+
}
|
|
103954
|
+
static async fromDatabase(db) {
|
|
103955
|
+
const tools = new ToolCalls(db);
|
|
103956
|
+
await tools.initialize();
|
|
103957
|
+
return tools;
|
|
103958
|
+
}
|
|
103959
|
+
async initialize() {
|
|
103960
|
+
await this.db.exec(`
|
|
103961
|
+
CREATE TABLE IF NOT EXISTS tool_calls (
|
|
103962
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
103963
|
+
name TEXT NOT NULL,
|
|
103964
|
+
parameters TEXT,
|
|
103965
|
+
result TEXT,
|
|
103966
|
+
error TEXT,
|
|
103967
|
+
status TEXT NOT NULL DEFAULT 'pending',
|
|
103968
|
+
started_at INTEGER NOT NULL,
|
|
103969
|
+
completed_at INTEGER,
|
|
103970
|
+
duration_ms INTEGER
|
|
103971
|
+
)
|
|
103972
|
+
`);
|
|
103973
|
+
await this.db.exec(`
|
|
103974
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_name
|
|
103975
|
+
ON tool_calls(name)
|
|
103976
|
+
`);
|
|
103977
|
+
await this.db.exec(`
|
|
103978
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_started_at
|
|
103979
|
+
ON tool_calls(started_at)
|
|
103980
|
+
`);
|
|
103981
|
+
}
|
|
103982
|
+
async start(name21, parameters) {
|
|
103983
|
+
const serializedParams = parameters !== undefined ? JSON.stringify(parameters) : null;
|
|
103984
|
+
const started_at = Math.floor(Date.now() / 1000);
|
|
103985
|
+
const stmt = this.db.prepare(`
|
|
103986
|
+
INSERT INTO tool_calls (name, parameters, status, started_at)
|
|
103987
|
+
VALUES (?, ?, 'pending', ?)
|
|
103988
|
+
RETURNING id
|
|
103989
|
+
`);
|
|
103990
|
+
const { id: id2 } = await stmt.get(name21, serializedParams, started_at);
|
|
103991
|
+
return Number(id2);
|
|
103992
|
+
}
|
|
103993
|
+
async success(id2, result) {
|
|
103994
|
+
const serializedResult = result !== undefined ? JSON.stringify(result) : null;
|
|
103995
|
+
const completed_at = Math.floor(Date.now() / 1000);
|
|
103996
|
+
const getStmt = this.db.prepare("SELECT started_at FROM tool_calls WHERE id = ?");
|
|
103997
|
+
const row = await getStmt.get(id2);
|
|
103998
|
+
if (!row) {
|
|
103999
|
+
throw new Error(`Tool call with ID ${id2} not found`);
|
|
104000
|
+
}
|
|
104001
|
+
const duration_ms = (completed_at - row.started_at) * 1000;
|
|
104002
|
+
const updateStmt = this.db.prepare(`
|
|
104003
|
+
UPDATE tool_calls
|
|
104004
|
+
SET status = 'success', result = ?, completed_at = ?, duration_ms = ?
|
|
104005
|
+
WHERE id = ?
|
|
104006
|
+
`);
|
|
104007
|
+
await updateStmt.run(serializedResult, completed_at, duration_ms, id2);
|
|
104008
|
+
}
|
|
104009
|
+
async error(id2, error51) {
|
|
104010
|
+
const completed_at = Math.floor(Date.now() / 1000);
|
|
104011
|
+
const getStmt = this.db.prepare("SELECT started_at FROM tool_calls WHERE id = ?");
|
|
104012
|
+
const row = await getStmt.get(id2);
|
|
104013
|
+
if (!row) {
|
|
104014
|
+
throw new Error(`Tool call with ID ${id2} not found`);
|
|
104015
|
+
}
|
|
104016
|
+
const duration_ms = (completed_at - row.started_at) * 1000;
|
|
104017
|
+
const updateStmt = this.db.prepare(`
|
|
104018
|
+
UPDATE tool_calls
|
|
104019
|
+
SET status = 'error', error = ?, completed_at = ?, duration_ms = ?
|
|
104020
|
+
WHERE id = ?
|
|
104021
|
+
`);
|
|
104022
|
+
await updateStmt.run(error51, completed_at, duration_ms, id2);
|
|
104023
|
+
}
|
|
104024
|
+
async record(name21, started_at, completed_at, parameters, result, error51) {
|
|
104025
|
+
const serializedParams = parameters !== undefined ? JSON.stringify(parameters) : null;
|
|
104026
|
+
const serializedResult = result !== undefined ? JSON.stringify(result) : null;
|
|
104027
|
+
const duration_ms = (completed_at - started_at) * 1000;
|
|
104028
|
+
const status2 = error51 ? "error" : "success";
|
|
104029
|
+
const stmt = this.db.prepare(`
|
|
104030
|
+
INSERT INTO tool_calls (name, parameters, result, error, status, started_at, completed_at, duration_ms)
|
|
104031
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
104032
|
+
RETURNING id
|
|
104033
|
+
`);
|
|
104034
|
+
const { id: id2 } = await stmt.get(name21, serializedParams, serializedResult, error51 || null, status2, started_at, completed_at, duration_ms);
|
|
104035
|
+
return Number(id2);
|
|
104036
|
+
}
|
|
104037
|
+
async get(id2) {
|
|
104038
|
+
const stmt = this.db.prepare(`
|
|
104039
|
+
SELECT * FROM tool_calls WHERE id = ?
|
|
104040
|
+
`);
|
|
104041
|
+
const row = await stmt.get(id2);
|
|
104042
|
+
if (!row) {
|
|
104043
|
+
return;
|
|
104044
|
+
}
|
|
104045
|
+
return this.rowToToolCall(row);
|
|
104046
|
+
}
|
|
104047
|
+
async getByName(name21, limit) {
|
|
104048
|
+
const limitClause = limit !== undefined ? `LIMIT ${limit}` : "";
|
|
104049
|
+
const stmt = this.db.prepare(`
|
|
104050
|
+
SELECT * FROM tool_calls
|
|
104051
|
+
WHERE name = ?
|
|
104052
|
+
ORDER BY started_at DESC
|
|
104053
|
+
${limitClause}
|
|
104054
|
+
`);
|
|
104055
|
+
const rows = await stmt.all(name21);
|
|
104056
|
+
return rows.map((row) => this.rowToToolCall(row));
|
|
104057
|
+
}
|
|
104058
|
+
async getRecent(since, limit) {
|
|
104059
|
+
const limitClause = limit !== undefined ? `LIMIT ${limit}` : "";
|
|
104060
|
+
const stmt = this.db.prepare(`
|
|
104061
|
+
SELECT * FROM tool_calls
|
|
104062
|
+
WHERE started_at > ?
|
|
104063
|
+
ORDER BY started_at DESC
|
|
104064
|
+
${limitClause}
|
|
104065
|
+
`);
|
|
104066
|
+
const rows = await stmt.all(since);
|
|
104067
|
+
return rows.map((row) => this.rowToToolCall(row));
|
|
104068
|
+
}
|
|
104069
|
+
async getStats() {
|
|
104070
|
+
const stmt = this.db.prepare(`
|
|
104071
|
+
SELECT
|
|
104072
|
+
name,
|
|
104073
|
+
COUNT(*) as total_calls,
|
|
104074
|
+
SUM(CASE WHEN status = 'success' THEN 1 ELSE 0 END) as successful,
|
|
104075
|
+
SUM(CASE WHEN status = 'error' THEN 1 ELSE 0 END) as failed,
|
|
104076
|
+
AVG(duration_ms) as avg_duration_ms
|
|
104077
|
+
FROM tool_calls
|
|
104078
|
+
WHERE status != 'pending'
|
|
104079
|
+
GROUP BY name
|
|
104080
|
+
ORDER BY total_calls DESC
|
|
104081
|
+
`);
|
|
104082
|
+
const rows = await stmt.all();
|
|
104083
|
+
return rows.map((row) => ({
|
|
104084
|
+
name: row.name,
|
|
104085
|
+
total_calls: row.total_calls,
|
|
104086
|
+
successful: row.successful,
|
|
104087
|
+
failed: row.failed,
|
|
104088
|
+
avg_duration_ms: row.avg_duration_ms || 0
|
|
104089
|
+
}));
|
|
104090
|
+
}
|
|
104091
|
+
rowToToolCall(row) {
|
|
104092
|
+
return {
|
|
104093
|
+
id: row.id,
|
|
104094
|
+
name: row.name,
|
|
104095
|
+
parameters: row.parameters !== null ? JSON.parse(row.parameters) : undefined,
|
|
104096
|
+
result: row.result !== null ? JSON.parse(row.result) : undefined,
|
|
104097
|
+
error: row.error !== null ? row.error : undefined,
|
|
104098
|
+
status: row.status,
|
|
104099
|
+
started_at: row.started_at,
|
|
104100
|
+
completed_at: row.completed_at !== null ? row.completed_at : undefined,
|
|
104101
|
+
duration_ms: row.duration_ms !== null ? row.duration_ms : undefined
|
|
104102
|
+
};
|
|
104103
|
+
}
|
|
104104
|
+
}
|
|
104105
|
+
|
|
104106
|
+
// ../../node_modules/.bun/agentfs-sdk@0.6.2/node_modules/agentfs-sdk/dist/index_node.js
|
|
104107
|
+
class AgentFS2 extends AgentFSCore {
|
|
104108
|
+
static async open(options7) {
|
|
104109
|
+
const { id: id2, path: path4 } = options7;
|
|
104110
|
+
if (!id2 && !path4) {
|
|
104111
|
+
throw new Error("AgentFS.open() requires at least 'id' or 'path'.");
|
|
104112
|
+
}
|
|
104113
|
+
if (id2 && !/^[a-zA-Z0-9_-]+$/.test(id2)) {
|
|
104114
|
+
throw new Error("Agent ID must contain only alphanumeric characters, hyphens, and underscores");
|
|
104115
|
+
}
|
|
104116
|
+
let dbPath;
|
|
104117
|
+
if (path4) {
|
|
104118
|
+
dbPath = path4;
|
|
104119
|
+
} else {
|
|
104120
|
+
const dir2 = ".agentfs";
|
|
104121
|
+
if (!existsSync(dir2)) {
|
|
104122
|
+
mkdirSync(dir2, { recursive: true });
|
|
104123
|
+
}
|
|
104124
|
+
dbPath = `${dir2}/${id2}.db`;
|
|
104125
|
+
}
|
|
104126
|
+
const db = new Database4(dbPath);
|
|
104127
|
+
await db.connect();
|
|
104128
|
+
return await this.openWith(db);
|
|
104129
|
+
}
|
|
104130
|
+
static async openWith(db) {
|
|
104131
|
+
const [kv, fs2, tools] = await Promise.all([
|
|
104132
|
+
KvStore.fromDatabase(db),
|
|
104133
|
+
AgentFS.fromDatabase(db),
|
|
104134
|
+
ToolCalls.fromDatabase(db)
|
|
104135
|
+
]);
|
|
104136
|
+
return new AgentFS2(db, kv, fs2, tools);
|
|
104137
|
+
}
|
|
104138
|
+
}
|
|
101784
104139
|
|
|
101785
104140
|
// ../core/src/domain/codebase-scanner.ts
|
|
101786
104141
|
class CodebaseScanner extends Tag2("@grepai/core/domain/codebase-scanner/CodebaseScanner")() {
|
|
@@ -101790,14 +104145,143 @@ class CodebaseScanner extends Tag2("@grepai/core/domain/codebase-scanner/Codebas
|
|
|
101790
104145
|
class DocumentStorage extends Tag2("@grepai/core/domain/document-storage/DocumentStorage")() {
|
|
101791
104146
|
}
|
|
101792
104147
|
|
|
104148
|
+
// ../core/src/internal/services/codebase-scanner-agentfs.ts
|
|
104149
|
+
var CodebaseScannerAgentFs = scoped3(CodebaseScanner, gen2(function* () {
|
|
104150
|
+
const fs2 = yield* exports_FileSystem.FileSystem;
|
|
104151
|
+
const path4 = yield* exports_Path.Path;
|
|
104152
|
+
const config3 = yield* Config;
|
|
104153
|
+
const documentStorage = yield* DocumentStorage;
|
|
104154
|
+
if (!config3.experimental__agentFs) {
|
|
104155
|
+
return yield* new CodebaseScannerError({
|
|
104156
|
+
cause: "`experimental__agentFs` is not enabled."
|
|
104157
|
+
});
|
|
104158
|
+
}
|
|
104159
|
+
const { authToken, url: url3, syncMode } = config3.experimental__agentFs;
|
|
104160
|
+
const baseAgentFsLocalPath = path4.resolve(config3.cwd, "./.grepai/agentfs");
|
|
104161
|
+
yield* fs2.makeDirectory(baseAgentFsLocalPath, { recursive: true });
|
|
104162
|
+
const db = yield* tryPromise2({
|
|
104163
|
+
try: async () => {
|
|
104164
|
+
const db2 = await connect2({
|
|
104165
|
+
path: path4.join(baseAgentFsLocalPath, "local.db"),
|
|
104166
|
+
url: url3,
|
|
104167
|
+
authToken,
|
|
104168
|
+
clientName: "grepai"
|
|
104169
|
+
});
|
|
104170
|
+
if (syncMode === "pull") {
|
|
104171
|
+
await db2.pull();
|
|
104172
|
+
}
|
|
104173
|
+
return db2;
|
|
104174
|
+
},
|
|
104175
|
+
catch: (cause2) => new CodebaseScannerError({ cause: cause2 })
|
|
104176
|
+
});
|
|
104177
|
+
const agentFs = yield* tryPromise2({
|
|
104178
|
+
try: () => AgentFS2.openWith(db),
|
|
104179
|
+
catch: (cause2) => new CodebaseScannerError({ cause: cause2 })
|
|
104180
|
+
});
|
|
104181
|
+
yield* addFinalizer3(() => promise2(() => agentFs.close()));
|
|
104182
|
+
const useAgentFs = (f) => tryPromise2({
|
|
104183
|
+
try: () => f(agentFs),
|
|
104184
|
+
catch: (cause2) => new CodebaseScannerError({ cause: cause2 })
|
|
104185
|
+
});
|
|
104186
|
+
function withLanguageOption(filePath) {
|
|
104187
|
+
return value5(filePath.split(".").at(-1) ?? "").pipe(when5("ts", () => ({
|
|
104188
|
+
filePath,
|
|
104189
|
+
language: "typescript"
|
|
104190
|
+
})), when5("tsx", () => ({
|
|
104191
|
+
filePath,
|
|
104192
|
+
language: "tsx"
|
|
104193
|
+
})), option4);
|
|
104194
|
+
}
|
|
104195
|
+
const toScanResults = fnUntraced2(function* (files) {
|
|
104196
|
+
const fileMap = fromIterableBy(files, ({ filePath }) => filePath);
|
|
104197
|
+
const documents = yield* documentStorage.getAll();
|
|
104198
|
+
const documentMap = fromIterableBy(documents, ({ filePath }) => filePath);
|
|
104199
|
+
const newFiles = filter3(files, ({ filePath }) => !documentMap[filePath]);
|
|
104200
|
+
const modified = filter3(files, ({ filePath, hash: hash3 }) => !!documentMap[filePath] && documentMap[filePath].hash !== hash3);
|
|
104201
|
+
const unchanged = filter3(files, ({ filePath, hash: hash3 }) => !!documentMap[filePath] && documentMap[filePath].hash === hash3);
|
|
104202
|
+
const deleted = filter3(documents, ({ filePath }) => !fileMap[filePath]);
|
|
104203
|
+
return {
|
|
104204
|
+
new: newFiles,
|
|
104205
|
+
unchanged,
|
|
104206
|
+
modified,
|
|
104207
|
+
deleted
|
|
104208
|
+
};
|
|
104209
|
+
});
|
|
104210
|
+
const scanFs = fnUntraced2(function* () {
|
|
104211
|
+
const files = yield* try_3({
|
|
104212
|
+
try: () => globSync(config3.include, {
|
|
104213
|
+
cwd: config3.cwd,
|
|
104214
|
+
exclude: config3.exclude.map((pattern2) => {
|
|
104215
|
+
const hasPathSep = pattern2.includes("/") || pattern2.includes("\\");
|
|
104216
|
+
if (!hasPathSep) {
|
|
104217
|
+
return `**/${pattern2}`;
|
|
104218
|
+
}
|
|
104219
|
+
return pattern2;
|
|
104220
|
+
})
|
|
104221
|
+
}),
|
|
104222
|
+
catch: (cause2) => new CodebaseScannerError({ cause: cause2 })
|
|
104223
|
+
}).pipe(map16(filterMap2(withLanguageOption)), flatMap10(forEach5(({ filePath, language }) => fs2.readFileString(filePath).pipe(map16((content) => ({
|
|
104224
|
+
filePath,
|
|
104225
|
+
language,
|
|
104226
|
+
hash: string(content).toString(),
|
|
104227
|
+
content
|
|
104228
|
+
}))))));
|
|
104229
|
+
return yield* toScanResults(files);
|
|
104230
|
+
}, catchTags2({
|
|
104231
|
+
BadArgument: (cause2) => new CodebaseScannerError({ cause: cause2 }),
|
|
104232
|
+
SystemError: (cause2) => new CodebaseScannerError({ cause: cause2 })
|
|
104233
|
+
}));
|
|
104234
|
+
const readDirRecursiveAgentFs = fnUntraced2(function* (path5 = "/") {
|
|
104235
|
+
const results = [];
|
|
104236
|
+
const entries2 = yield* useAgentFs((a) => a.fs.readdir(path5));
|
|
104237
|
+
yield* forEach5(entries2, (entry) => gen2(function* () {
|
|
104238
|
+
const normalizedPath = path5 === "/" ? "" : path5.replace(/\/$/, "");
|
|
104239
|
+
const normalizedEntry = entry.replace(/^\//, "");
|
|
104240
|
+
const fullPath = normalizedPath + normalizedEntry;
|
|
104241
|
+
const stats = yield* useAgentFs((a) => a.fs.stat(fullPath));
|
|
104242
|
+
if (stats.isDirectory()) {
|
|
104243
|
+
const subFiles = yield* readDirRecursiveAgentFs(fullPath);
|
|
104244
|
+
results.push(...subFiles);
|
|
104245
|
+
} else {
|
|
104246
|
+
results.push(fullPath);
|
|
104247
|
+
}
|
|
104248
|
+
}));
|
|
104249
|
+
return results;
|
|
104250
|
+
});
|
|
104251
|
+
const scanAgentFs = fnUntraced2(function* () {
|
|
104252
|
+
if (syncMode === "push") {
|
|
104253
|
+
const results = yield* scanFs();
|
|
104254
|
+
const { new: newFiles, modified, deleted } = results;
|
|
104255
|
+
yield* forEach5([...newFiles, ...modified], ({ filePath, content }) => useAgentFs((a) => a.fs.writeFile(filePath, content)));
|
|
104256
|
+
yield* forEach5(deleted, ({ filePath }) => useAgentFs((a) => a.fs.deleteFile(filePath)));
|
|
104257
|
+
yield* tryPromise2({
|
|
104258
|
+
try: () => db.push(),
|
|
104259
|
+
catch: (cause2) => new CodebaseScannerError({ cause: cause2 })
|
|
104260
|
+
});
|
|
104261
|
+
return results;
|
|
104262
|
+
}
|
|
104263
|
+
const files = yield* readDirRecursiveAgentFs().pipe(map16(filterMap2(withLanguageOption)), flatMap10(forEach5(({ filePath, language }) => useAgentFs((a) => a.fs.readFile(filePath, { encoding: "utf-8" })).pipe(map16((content) => ({
|
|
104264
|
+
filePath,
|
|
104265
|
+
language,
|
|
104266
|
+
hash: string(content).toString(),
|
|
104267
|
+
content
|
|
104268
|
+
}))))));
|
|
104269
|
+
return yield* toScanResults(files);
|
|
104270
|
+
});
|
|
104271
|
+
return CodebaseScanner.of({
|
|
104272
|
+
scan: scanAgentFs
|
|
104273
|
+
});
|
|
104274
|
+
}));
|
|
104275
|
+
|
|
101793
104276
|
// ../core/src/internal/services/codebase-scanner-fs.ts
|
|
104277
|
+
import { globSync as globSync2 } from "fs";
|
|
101794
104278
|
var CodebaseScannerFs = effect(CodebaseScanner, gen2(function* () {
|
|
101795
104279
|
const fs2 = yield* exports_FileSystem.FileSystem;
|
|
101796
104280
|
const config3 = yield* Config;
|
|
101797
104281
|
const documentStorage = yield* DocumentStorage;
|
|
101798
104282
|
const scan2 = fnUntraced2(function* () {
|
|
101799
104283
|
const files = yield* try_3({
|
|
101800
|
-
try: () =>
|
|
104284
|
+
try: () => globSync2(config3.include, {
|
|
101801
104285
|
cwd: config3.cwd,
|
|
101802
104286
|
exclude: config3.exclude.map((pattern2) => {
|
|
101803
104287
|
const hasPathSep = pattern2.includes("/") || pattern2.includes("\\");
|
|
@@ -107820,7 +110304,8 @@ var GrepAiLive = unwrapEffect2(gen2(function* () {
|
|
|
107820
110304
|
const DocumentStorageLive = value5(config3.storage.type).pipe(when5("turso", () => DocumentStorageSql.pipe(provide3(StorageSqlLiveLazy()))), when5("postgres", () => DocumentStorageSql.pipe(provide3(StorageSqlLiveLazy()))), when5("lancedb", () => DocumentStorageLanceDb.pipe(provide3(StorageLanceDbLiveLazy()))), exhaustive2);
|
|
107821
110305
|
const ChunkStorageLive = value5(config3.storage.type).pipe(when5("turso", () => ChunkStorageSql.pipe(provide3(StorageSqlLiveLazy()))), when5("postgres", () => ChunkStorageSql.pipe(provide3(StorageSqlLiveLazy()))), when5("lancedb", () => ChunkStorageLanceDb.pipe(provide3(StorageLanceDbLiveLazy()))), exhaustive2);
|
|
107822
110306
|
const FileIndexerLive = value5(config3.storage.type).pipe(when5("turso", () => FileIndexer.Default.pipe(provide3(StorageSqlLiveLazy()))), when5("postgres", () => FileIndexer.Default.pipe(provide3(StorageSqlLiveLazy()))), when5("lancedb", () => FileIndexer.Default), exhaustive2);
|
|
107823
|
-
|
|
110307
|
+
const CodebaseScannerLive = value5(config3.experimental__agentFs).pipe(when5((val) => !!val, () => CodebaseScannerAgentFs), orElse12(() => CodebaseScannerFs));
|
|
110308
|
+
return Indexer.Default.pipe(provide3(FileIndexerLive), provideMerge2(ChunkStorageLive), provide3(CodebaseScannerLive), provide3(ChunkerAst), provide3(TokenCounterLive.pipe(provide3(exports_FetchHttpClient.layer))), provide3(EmbedderLive.pipe(provide3(EmbeddingNormalizer.Default), provide3(VercelAi.Default))), provide3(DocumentStorageLive));
|
|
107824
110309
|
})).pipe(provideMerge2(ConfigJson));
|
|
107825
110310
|
|
|
107826
110311
|
class GrepAi extends Service()("@grepai/core/internal/services/grep-ai/GrepAi", {
|
|
@@ -109649,11 +112134,11 @@ var program = gen2(function* () {
|
|
|
109649
112134
|
const command = exports_Command.make("grepai").pipe(exports_Command.withSubcommands([indexCommand, searchCommand]));
|
|
109650
112135
|
const cli = exports_Command.run(command, {
|
|
109651
112136
|
name: "GREP AI",
|
|
109652
|
-
version: "v0.
|
|
112137
|
+
version: "v0.7.0"
|
|
109653
112138
|
});
|
|
109654
112139
|
yield* cli(process.argv);
|
|
109655
112140
|
});
|
|
109656
112141
|
program.pipe(provide2(mergeAll5(GrepAi.Default).pipe(provideMerge2(Clack.Default), provideMerge2(exports_BunContext.layer))), exports_BunRuntime.runMain);
|
|
109657
112142
|
|
|
109658
|
-
//# debugId=
|
|
112143
|
+
//# debugId=039C99EDE759421464756E2164756E21
|
|
109659
112144
|
//# sourceMappingURL=index.js.map
|