@prosdevlab/dev-agent 0.8.5 → 0.9.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/dist/cli.js +1849 -497
- package/dist/cli.js.map +1 -1
- package/dist/mcp.js +1515 -445
- package/dist/mcp.js.map +1 -1
- package/dist/vendor/web-tree-sitter/lib/tree-sitter.wasm +0 -0
- package/dist/vendor/web-tree-sitter/tree-sitter.wasm +0 -0
- package/dist/wasm/tree-sitter-go.wasm +0 -0
- package/dist/wasm/tree-sitter.wasm +0 -0
- package/package.json +9 -12
package/dist/mcp.js
CHANGED
|
@@ -1048,11 +1048,11 @@ var init_change_frequency = __esm({
|
|
|
1048
1048
|
|
|
1049
1049
|
// ../core/src/metrics/collector.ts
|
|
1050
1050
|
async function countFileLines(repositoryPath2, filePath) {
|
|
1051
|
-
const
|
|
1051
|
+
const fs12 = await import("fs/promises");
|
|
1052
1052
|
const path16 = await import("path");
|
|
1053
1053
|
try {
|
|
1054
1054
|
const fullPath = path16.join(repositoryPath2, filePath);
|
|
1055
|
-
const content3 = await
|
|
1055
|
+
const content3 = await fs12.readFile(fullPath, "utf-8");
|
|
1056
1056
|
return content3.split("\n").length;
|
|
1057
1057
|
} catch {
|
|
1058
1058
|
return 0;
|
|
@@ -9585,8 +9585,8 @@ var init_is_plain_obj = __esm({
|
|
|
9585
9585
|
// ../../node_modules/.pnpm/trough@2.2.0/node_modules/trough/lib/index.js
|
|
9586
9586
|
function trough() {
|
|
9587
9587
|
const fns = [];
|
|
9588
|
-
const
|
|
9589
|
-
return
|
|
9588
|
+
const pipeline = { run, use };
|
|
9589
|
+
return pipeline;
|
|
9590
9590
|
function run(...values) {
|
|
9591
9591
|
let middlewareIndex = -1;
|
|
9592
9592
|
const callback = values.pop();
|
|
@@ -9621,7 +9621,7 @@ function trough() {
|
|
|
9621
9621
|
);
|
|
9622
9622
|
}
|
|
9623
9623
|
fns.push(middelware);
|
|
9624
|
-
return
|
|
9624
|
+
return pipeline;
|
|
9625
9625
|
}
|
|
9626
9626
|
}
|
|
9627
9627
|
function wrap(middleware, callback) {
|
|
@@ -14758,8 +14758,8 @@ var require_utils3 = __commonJS({
|
|
|
14758
14758
|
exports2.array = array2;
|
|
14759
14759
|
var errno = require_errno();
|
|
14760
14760
|
exports2.errno = errno;
|
|
14761
|
-
var
|
|
14762
|
-
exports2.fs =
|
|
14761
|
+
var fs12 = require_fs();
|
|
14762
|
+
exports2.fs = fs12;
|
|
14763
14763
|
var path16 = require_path();
|
|
14764
14764
|
exports2.path = path16;
|
|
14765
14765
|
var pattern = require_pattern();
|
|
@@ -14883,7 +14883,7 @@ var require_async = __commonJS({
|
|
|
14883
14883
|
callSuccessCallback(callback, lstat);
|
|
14884
14884
|
return;
|
|
14885
14885
|
}
|
|
14886
|
-
settings.fs.stat(path16, (statError,
|
|
14886
|
+
settings.fs.stat(path16, (statError, stat3) => {
|
|
14887
14887
|
if (statError !== null) {
|
|
14888
14888
|
if (settings.throwErrorOnBrokenSymbolicLink) {
|
|
14889
14889
|
callFailureCallback(callback, statError);
|
|
@@ -14893,9 +14893,9 @@ var require_async = __commonJS({
|
|
|
14893
14893
|
return;
|
|
14894
14894
|
}
|
|
14895
14895
|
if (settings.markSymbolicLink) {
|
|
14896
|
-
|
|
14896
|
+
stat3.isSymbolicLink = () => true;
|
|
14897
14897
|
}
|
|
14898
|
-
callSuccessCallback(callback,
|
|
14898
|
+
callSuccessCallback(callback, stat3);
|
|
14899
14899
|
});
|
|
14900
14900
|
});
|
|
14901
14901
|
}
|
|
@@ -14921,11 +14921,11 @@ var require_sync = __commonJS({
|
|
|
14921
14921
|
return lstat;
|
|
14922
14922
|
}
|
|
14923
14923
|
try {
|
|
14924
|
-
const
|
|
14924
|
+
const stat3 = settings.fs.statSync(path16);
|
|
14925
14925
|
if (settings.markSymbolicLink) {
|
|
14926
|
-
|
|
14926
|
+
stat3.isSymbolicLink = () => true;
|
|
14927
14927
|
}
|
|
14928
|
-
return
|
|
14928
|
+
return stat3;
|
|
14929
14929
|
} catch (error46) {
|
|
14930
14930
|
if (!settings.throwErrorOnBrokenSymbolicLink) {
|
|
14931
14931
|
return lstat;
|
|
@@ -14943,12 +14943,12 @@ var require_fs2 = __commonJS({
|
|
|
14943
14943
|
"use strict";
|
|
14944
14944
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
14945
14945
|
exports2.createFileSystemAdapter = exports2.FILE_SYSTEM_ADAPTER = void 0;
|
|
14946
|
-
var
|
|
14946
|
+
var fs12 = require("fs");
|
|
14947
14947
|
exports2.FILE_SYSTEM_ADAPTER = {
|
|
14948
|
-
lstat:
|
|
14949
|
-
stat:
|
|
14950
|
-
lstatSync:
|
|
14951
|
-
statSync:
|
|
14948
|
+
lstat: fs12.lstat,
|
|
14949
|
+
stat: fs12.stat,
|
|
14950
|
+
lstatSync: fs12.lstatSync,
|
|
14951
|
+
statSync: fs12.statSync
|
|
14952
14952
|
};
|
|
14953
14953
|
function createFileSystemAdapter(fsMethods) {
|
|
14954
14954
|
if (fsMethods === void 0) {
|
|
@@ -14965,12 +14965,12 @@ var require_settings = __commonJS({
|
|
|
14965
14965
|
"../../node_modules/.pnpm/@nodelib+fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/settings.js"(exports2) {
|
|
14966
14966
|
"use strict";
|
|
14967
14967
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
14968
|
-
var
|
|
14968
|
+
var fs12 = require_fs2();
|
|
14969
14969
|
var Settings = class {
|
|
14970
14970
|
constructor(_options = {}) {
|
|
14971
14971
|
this._options = _options;
|
|
14972
14972
|
this.followSymbolicLink = this._getValue(this._options.followSymbolicLink, true);
|
|
14973
|
-
this.fs =
|
|
14973
|
+
this.fs = fs12.createFileSystemAdapter(this._options.fs);
|
|
14974
14974
|
this.markSymbolicLink = this._getValue(this._options.markSymbolicLink, false);
|
|
14975
14975
|
this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
|
|
14976
14976
|
}
|
|
@@ -14992,14 +14992,14 @@ var require_out = __commonJS({
|
|
|
14992
14992
|
var sync = require_sync();
|
|
14993
14993
|
var settings_1 = require_settings();
|
|
14994
14994
|
exports2.Settings = settings_1.default;
|
|
14995
|
-
function
|
|
14995
|
+
function stat3(path16, optionsOrSettingsOrCallback, callback) {
|
|
14996
14996
|
if (typeof optionsOrSettingsOrCallback === "function") {
|
|
14997
14997
|
async.read(path16, getSettings(), optionsOrSettingsOrCallback);
|
|
14998
14998
|
return;
|
|
14999
14999
|
}
|
|
15000
15000
|
async.read(path16, getSettings(optionsOrSettingsOrCallback), callback);
|
|
15001
15001
|
}
|
|
15002
|
-
exports2.stat =
|
|
15002
|
+
exports2.stat = stat3;
|
|
15003
15003
|
function statSync(path16, optionsOrSettings) {
|
|
15004
15004
|
const settings = getSettings(optionsOrSettings);
|
|
15005
15005
|
return sync.read(path16, settings);
|
|
@@ -15127,8 +15127,8 @@ var require_utils4 = __commonJS({
|
|
|
15127
15127
|
"use strict";
|
|
15128
15128
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15129
15129
|
exports2.fs = void 0;
|
|
15130
|
-
var
|
|
15131
|
-
exports2.fs =
|
|
15130
|
+
var fs12 = require_fs3();
|
|
15131
|
+
exports2.fs = fs12;
|
|
15132
15132
|
}
|
|
15133
15133
|
});
|
|
15134
15134
|
|
|
@@ -15323,14 +15323,14 @@ var require_fs4 = __commonJS({
|
|
|
15323
15323
|
"use strict";
|
|
15324
15324
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15325
15325
|
exports2.createFileSystemAdapter = exports2.FILE_SYSTEM_ADAPTER = void 0;
|
|
15326
|
-
var
|
|
15326
|
+
var fs12 = require("fs");
|
|
15327
15327
|
exports2.FILE_SYSTEM_ADAPTER = {
|
|
15328
|
-
lstat:
|
|
15329
|
-
stat:
|
|
15330
|
-
lstatSync:
|
|
15331
|
-
statSync:
|
|
15332
|
-
readdir:
|
|
15333
|
-
readdirSync:
|
|
15328
|
+
lstat: fs12.lstat,
|
|
15329
|
+
stat: fs12.stat,
|
|
15330
|
+
lstatSync: fs12.lstatSync,
|
|
15331
|
+
statSync: fs12.statSync,
|
|
15332
|
+
readdir: fs12.readdir,
|
|
15333
|
+
readdirSync: fs12.readdirSync
|
|
15334
15334
|
};
|
|
15335
15335
|
function createFileSystemAdapter(fsMethods) {
|
|
15336
15336
|
if (fsMethods === void 0) {
|
|
@@ -15349,12 +15349,12 @@ var require_settings2 = __commonJS({
|
|
|
15349
15349
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15350
15350
|
var path16 = require("path");
|
|
15351
15351
|
var fsStat = require_out();
|
|
15352
|
-
var
|
|
15352
|
+
var fs12 = require_fs4();
|
|
15353
15353
|
var Settings = class {
|
|
15354
15354
|
constructor(_options = {}) {
|
|
15355
15355
|
this._options = _options;
|
|
15356
15356
|
this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, false);
|
|
15357
|
-
this.fs =
|
|
15357
|
+
this.fs = fs12.createFileSystemAdapter(this._options.fs);
|
|
15358
15358
|
this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path16.sep);
|
|
15359
15359
|
this.stats = this._getValue(this._options.stats, false);
|
|
15360
15360
|
this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
|
|
@@ -16712,16 +16712,16 @@ var require_settings4 = __commonJS({
|
|
|
16712
16712
|
"use strict";
|
|
16713
16713
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
16714
16714
|
exports2.DEFAULT_FILE_SYSTEM_ADAPTER = void 0;
|
|
16715
|
-
var
|
|
16715
|
+
var fs12 = require("fs");
|
|
16716
16716
|
var os2 = require("os");
|
|
16717
16717
|
var CPU_COUNT = Math.max(os2.cpus().length, 1);
|
|
16718
16718
|
exports2.DEFAULT_FILE_SYSTEM_ADAPTER = {
|
|
16719
|
-
lstat:
|
|
16720
|
-
lstatSync:
|
|
16721
|
-
stat:
|
|
16722
|
-
statSync:
|
|
16723
|
-
readdir:
|
|
16724
|
-
readdirSync:
|
|
16719
|
+
lstat: fs12.lstat,
|
|
16720
|
+
lstatSync: fs12.lstatSync,
|
|
16721
|
+
stat: fs12.stat,
|
|
16722
|
+
statSync: fs12.statSync,
|
|
16723
|
+
readdir: fs12.readdir,
|
|
16724
|
+
readdirSync: fs12.readdirSync
|
|
16725
16725
|
};
|
|
16726
16726
|
var Settings = class {
|
|
16727
16727
|
constructor(_options = {}) {
|
|
@@ -19153,363 +19153,1472 @@ var init_scanner = __esm({
|
|
|
19153
19153
|
}
|
|
19154
19154
|
});
|
|
19155
19155
|
|
|
19156
|
-
//
|
|
19157
|
-
|
|
19158
|
-
|
|
19159
|
-
|
|
19160
|
-
|
|
19161
|
-
|
|
19162
|
-
|
|
19163
|
-
|
|
19164
|
-
|
|
19165
|
-
|
|
19166
|
-
|
|
19167
|
-
|
|
19168
|
-
|
|
19169
|
-
|
|
19156
|
+
// ../../node_modules/.pnpm/openapi-fetch@0.17.0/node_modules/openapi-fetch/dist/index.mjs
|
|
19157
|
+
function randomID() {
|
|
19158
|
+
return Math.random().toString(36).slice(2, 11);
|
|
19159
|
+
}
|
|
19160
|
+
function createClient(clientOptions) {
|
|
19161
|
+
let {
|
|
19162
|
+
baseUrl = "",
|
|
19163
|
+
Request: CustomRequest = globalThis.Request,
|
|
19164
|
+
fetch: baseFetch = globalThis.fetch,
|
|
19165
|
+
querySerializer: globalQuerySerializer,
|
|
19166
|
+
bodySerializer: globalBodySerializer,
|
|
19167
|
+
pathSerializer: globalPathSerializer,
|
|
19168
|
+
headers: baseHeaders,
|
|
19169
|
+
requestInitExt = void 0,
|
|
19170
|
+
...baseOptions
|
|
19171
|
+
} = { ...clientOptions };
|
|
19172
|
+
requestInitExt = supportsRequestInitExt() ? requestInitExt : void 0;
|
|
19173
|
+
baseUrl = removeTrailingSlash(baseUrl);
|
|
19174
|
+
const globalMiddlewares = [];
|
|
19175
|
+
async function coreFetch(schemaPath, fetchOptions) {
|
|
19176
|
+
const {
|
|
19177
|
+
baseUrl: localBaseUrl,
|
|
19178
|
+
fetch: fetch2 = baseFetch,
|
|
19179
|
+
Request = CustomRequest,
|
|
19180
|
+
headers,
|
|
19181
|
+
params = {},
|
|
19182
|
+
parseAs = "json",
|
|
19183
|
+
querySerializer: requestQuerySerializer,
|
|
19184
|
+
bodySerializer = globalBodySerializer ?? defaultBodySerializer,
|
|
19185
|
+
pathSerializer: requestPathSerializer,
|
|
19186
|
+
body,
|
|
19187
|
+
middleware: requestMiddlewares = [],
|
|
19188
|
+
...init
|
|
19189
|
+
} = fetchOptions || {};
|
|
19190
|
+
let finalBaseUrl = baseUrl;
|
|
19191
|
+
if (localBaseUrl) {
|
|
19192
|
+
finalBaseUrl = removeTrailingSlash(localBaseUrl) ?? baseUrl;
|
|
19193
|
+
}
|
|
19194
|
+
let querySerializer = typeof globalQuerySerializer === "function" ? globalQuerySerializer : createQuerySerializer(globalQuerySerializer);
|
|
19195
|
+
if (requestQuerySerializer) {
|
|
19196
|
+
querySerializer = typeof requestQuerySerializer === "function" ? requestQuerySerializer : createQuerySerializer({
|
|
19197
|
+
...typeof globalQuerySerializer === "object" ? globalQuerySerializer : {},
|
|
19198
|
+
...requestQuerySerializer
|
|
19199
|
+
});
|
|
19200
|
+
}
|
|
19201
|
+
const pathSerializer = requestPathSerializer || globalPathSerializer || defaultPathSerializer;
|
|
19202
|
+
const serializedBody = body === void 0 ? void 0 : bodySerializer(
|
|
19203
|
+
body,
|
|
19204
|
+
// Note: we declare mergeHeaders() both here and below because it’s a bit of a chicken-or-egg situation:
|
|
19205
|
+
// bodySerializer() needs all headers so we aren’t dropping ones set by the user, however,
|
|
19206
|
+
// the result of this ALSO sets the lowest-priority content-type header. So we re-merge below,
|
|
19207
|
+
// setting the content-type at the very beginning to be overwritten.
|
|
19208
|
+
// Lastly, based on the way headers work, it’s not a simple “present-or-not” check becauase null intentionally un-sets headers.
|
|
19209
|
+
mergeHeaders(baseHeaders, headers, params.header)
|
|
19210
|
+
);
|
|
19211
|
+
const finalHeaders = mergeHeaders(
|
|
19212
|
+
// with no body, we should not to set Content-Type
|
|
19213
|
+
serializedBody === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
|
|
19214
|
+
serializedBody instanceof FormData ? {} : {
|
|
19215
|
+
"Content-Type": "application/json"
|
|
19216
|
+
},
|
|
19217
|
+
baseHeaders,
|
|
19218
|
+
headers,
|
|
19219
|
+
params.header
|
|
19220
|
+
);
|
|
19221
|
+
const finalMiddlewares = [...globalMiddlewares, ...requestMiddlewares];
|
|
19222
|
+
const requestInit = {
|
|
19223
|
+
redirect: "follow",
|
|
19224
|
+
...baseOptions,
|
|
19225
|
+
...init,
|
|
19226
|
+
body: serializedBody,
|
|
19227
|
+
headers: finalHeaders
|
|
19228
|
+
};
|
|
19229
|
+
let id;
|
|
19230
|
+
let options;
|
|
19231
|
+
let request = new Request(
|
|
19232
|
+
createFinalURL(schemaPath, { baseUrl: finalBaseUrl, params, querySerializer, pathSerializer }),
|
|
19233
|
+
requestInit
|
|
19234
|
+
);
|
|
19235
|
+
let response;
|
|
19236
|
+
for (const key in init) {
|
|
19237
|
+
if (!(key in request)) {
|
|
19238
|
+
request[key] = init[key];
|
|
19239
|
+
}
|
|
19240
|
+
}
|
|
19241
|
+
if (finalMiddlewares.length) {
|
|
19242
|
+
id = randomID();
|
|
19243
|
+
options = Object.freeze({
|
|
19244
|
+
baseUrl: finalBaseUrl,
|
|
19245
|
+
fetch: fetch2,
|
|
19246
|
+
parseAs,
|
|
19247
|
+
querySerializer,
|
|
19248
|
+
bodySerializer,
|
|
19249
|
+
pathSerializer
|
|
19250
|
+
});
|
|
19251
|
+
for (const m of finalMiddlewares) {
|
|
19252
|
+
if (m && typeof m === "object" && typeof m.onRequest === "function") {
|
|
19253
|
+
const result = await m.onRequest({
|
|
19254
|
+
request,
|
|
19255
|
+
schemaPath,
|
|
19256
|
+
params,
|
|
19257
|
+
options,
|
|
19258
|
+
id
|
|
19259
|
+
});
|
|
19260
|
+
if (result) {
|
|
19261
|
+
if (result instanceof Request) {
|
|
19262
|
+
request = result;
|
|
19263
|
+
} else if (result instanceof Response) {
|
|
19264
|
+
response = result;
|
|
19265
|
+
break;
|
|
19266
|
+
} else {
|
|
19267
|
+
throw new Error("onRequest: must return new Request() or Response() when modifying the request");
|
|
19268
|
+
}
|
|
19269
|
+
}
|
|
19270
|
+
}
|
|
19170
19271
|
}
|
|
19171
|
-
|
|
19172
|
-
|
|
19173
|
-
|
|
19174
|
-
|
|
19175
|
-
|
|
19176
|
-
|
|
19177
|
-
|
|
19272
|
+
}
|
|
19273
|
+
if (!response) {
|
|
19274
|
+
try {
|
|
19275
|
+
response = await fetch2(request, requestInitExt);
|
|
19276
|
+
} catch (error210) {
|
|
19277
|
+
let errorAfterMiddleware = error210;
|
|
19278
|
+
if (finalMiddlewares.length) {
|
|
19279
|
+
for (let i = finalMiddlewares.length - 1; i >= 0; i--) {
|
|
19280
|
+
const m = finalMiddlewares[i];
|
|
19281
|
+
if (m && typeof m === "object" && typeof m.onError === "function") {
|
|
19282
|
+
const result = await m.onError({
|
|
19283
|
+
request,
|
|
19284
|
+
error: errorAfterMiddleware,
|
|
19285
|
+
schemaPath,
|
|
19286
|
+
params,
|
|
19287
|
+
options,
|
|
19288
|
+
id
|
|
19289
|
+
});
|
|
19290
|
+
if (result) {
|
|
19291
|
+
if (result instanceof Response) {
|
|
19292
|
+
errorAfterMiddleware = void 0;
|
|
19293
|
+
response = result;
|
|
19294
|
+
break;
|
|
19295
|
+
}
|
|
19296
|
+
if (result instanceof Error) {
|
|
19297
|
+
errorAfterMiddleware = result;
|
|
19298
|
+
continue;
|
|
19299
|
+
}
|
|
19300
|
+
throw new Error("onError: must return new Response() or instance of Error");
|
|
19301
|
+
}
|
|
19302
|
+
}
|
|
19303
|
+
}
|
|
19178
19304
|
}
|
|
19179
|
-
|
|
19180
|
-
|
|
19181
|
-
|
|
19182
|
-
|
|
19305
|
+
if (errorAfterMiddleware) {
|
|
19306
|
+
throw errorAfterMiddleware;
|
|
19307
|
+
}
|
|
19308
|
+
}
|
|
19309
|
+
if (finalMiddlewares.length) {
|
|
19310
|
+
for (let i = finalMiddlewares.length - 1; i >= 0; i--) {
|
|
19311
|
+
const m = finalMiddlewares[i];
|
|
19312
|
+
if (m && typeof m === "object" && typeof m.onResponse === "function") {
|
|
19313
|
+
const result = await m.onResponse({
|
|
19314
|
+
request,
|
|
19315
|
+
response,
|
|
19316
|
+
schemaPath,
|
|
19317
|
+
params,
|
|
19318
|
+
options,
|
|
19319
|
+
id
|
|
19320
|
+
});
|
|
19321
|
+
if (result) {
|
|
19322
|
+
if (!(result instanceof Response)) {
|
|
19323
|
+
throw new Error("onResponse: must return new Response() when modifying the response");
|
|
19324
|
+
}
|
|
19325
|
+
response = result;
|
|
19326
|
+
}
|
|
19327
|
+
}
|
|
19328
|
+
}
|
|
19329
|
+
}
|
|
19330
|
+
}
|
|
19331
|
+
const contentLength = response.headers.get("Content-Length");
|
|
19332
|
+
if (response.status === 204 || request.method === "HEAD" || contentLength === "0" && !response.headers.get("Transfer-Encoding")?.includes("chunked")) {
|
|
19333
|
+
return response.ok ? { data: void 0, response } : { error: void 0, response };
|
|
19334
|
+
}
|
|
19335
|
+
if (response.ok) {
|
|
19336
|
+
const getResponseData = async () => {
|
|
19337
|
+
if (parseAs === "stream") {
|
|
19338
|
+
return response.body;
|
|
19339
|
+
}
|
|
19340
|
+
if (parseAs === "json" && !contentLength) {
|
|
19341
|
+
const raw = await response.text();
|
|
19342
|
+
return raw ? JSON.parse(raw) : void 0;
|
|
19343
|
+
}
|
|
19344
|
+
return await response[parseAs]();
|
|
19345
|
+
};
|
|
19346
|
+
return { data: await getResponseData(), response };
|
|
19347
|
+
}
|
|
19348
|
+
let error46 = await response.text();
|
|
19349
|
+
try {
|
|
19350
|
+
error46 = JSON.parse(error46);
|
|
19351
|
+
} catch {
|
|
19352
|
+
}
|
|
19353
|
+
return { error: error46, response };
|
|
19354
|
+
}
|
|
19355
|
+
return {
|
|
19356
|
+
request(method, url2, init) {
|
|
19357
|
+
return coreFetch(url2, { ...init, method: method.toUpperCase() });
|
|
19358
|
+
},
|
|
19359
|
+
/** Call a GET endpoint */
|
|
19360
|
+
GET(url2, init) {
|
|
19361
|
+
return coreFetch(url2, { ...init, method: "GET" });
|
|
19362
|
+
},
|
|
19363
|
+
/** Call a PUT endpoint */
|
|
19364
|
+
PUT(url2, init) {
|
|
19365
|
+
return coreFetch(url2, { ...init, method: "PUT" });
|
|
19366
|
+
},
|
|
19367
|
+
/** Call a POST endpoint */
|
|
19368
|
+
POST(url2, init) {
|
|
19369
|
+
return coreFetch(url2, { ...init, method: "POST" });
|
|
19370
|
+
},
|
|
19371
|
+
/** Call a DELETE endpoint */
|
|
19372
|
+
DELETE(url2, init) {
|
|
19373
|
+
return coreFetch(url2, { ...init, method: "DELETE" });
|
|
19374
|
+
},
|
|
19375
|
+
/** Call a OPTIONS endpoint */
|
|
19376
|
+
OPTIONS(url2, init) {
|
|
19377
|
+
return coreFetch(url2, { ...init, method: "OPTIONS" });
|
|
19378
|
+
},
|
|
19379
|
+
/** Call a HEAD endpoint */
|
|
19380
|
+
HEAD(url2, init) {
|
|
19381
|
+
return coreFetch(url2, { ...init, method: "HEAD" });
|
|
19382
|
+
},
|
|
19383
|
+
/** Call a PATCH endpoint */
|
|
19384
|
+
PATCH(url2, init) {
|
|
19385
|
+
return coreFetch(url2, { ...init, method: "PATCH" });
|
|
19386
|
+
},
|
|
19387
|
+
/** Call a TRACE endpoint */
|
|
19388
|
+
TRACE(url2, init) {
|
|
19389
|
+
return coreFetch(url2, { ...init, method: "TRACE" });
|
|
19390
|
+
},
|
|
19391
|
+
/** Register middleware */
|
|
19392
|
+
use(...middleware) {
|
|
19393
|
+
for (const m of middleware) {
|
|
19394
|
+
if (!m) {
|
|
19395
|
+
continue;
|
|
19396
|
+
}
|
|
19397
|
+
if (typeof m !== "object" || !("onRequest" in m || "onResponse" in m || "onError" in m)) {
|
|
19398
|
+
throw new Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");
|
|
19399
|
+
}
|
|
19400
|
+
globalMiddlewares.push(m);
|
|
19401
|
+
}
|
|
19402
|
+
},
|
|
19403
|
+
/** Unregister middleware */
|
|
19404
|
+
eject(...middleware) {
|
|
19405
|
+
for (const m of middleware) {
|
|
19406
|
+
const i = globalMiddlewares.indexOf(m);
|
|
19407
|
+
if (i !== -1) {
|
|
19408
|
+
globalMiddlewares.splice(i, 1);
|
|
19409
|
+
}
|
|
19410
|
+
}
|
|
19411
|
+
}
|
|
19412
|
+
};
|
|
19413
|
+
}
|
|
19414
|
+
function serializePrimitiveParam(name, value, options) {
|
|
19415
|
+
if (value === void 0 || value === null) {
|
|
19416
|
+
return "";
|
|
19417
|
+
}
|
|
19418
|
+
if (typeof value === "object") {
|
|
19419
|
+
throw new Error(
|
|
19420
|
+
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
19421
|
+
);
|
|
19422
|
+
}
|
|
19423
|
+
return `${name}=${options?.allowReserved === true ? value : encodeURIComponent(value)}`;
|
|
19424
|
+
}
|
|
19425
|
+
function serializeObjectParam(name, value, options) {
|
|
19426
|
+
if (!value || typeof value !== "object") {
|
|
19427
|
+
return "";
|
|
19428
|
+
}
|
|
19429
|
+
const values = [];
|
|
19430
|
+
const joiner = {
|
|
19431
|
+
simple: ",",
|
|
19432
|
+
label: ".",
|
|
19433
|
+
matrix: ";"
|
|
19434
|
+
}[options.style] || "&";
|
|
19435
|
+
if (options.style !== "deepObject" && options.explode === false) {
|
|
19436
|
+
for (const k in value) {
|
|
19437
|
+
values.push(k, options.allowReserved === true ? value[k] : encodeURIComponent(value[k]));
|
|
19438
|
+
}
|
|
19439
|
+
const final2 = values.join(",");
|
|
19440
|
+
switch (options.style) {
|
|
19441
|
+
case "form": {
|
|
19442
|
+
return `${name}=${final2}`;
|
|
19443
|
+
}
|
|
19444
|
+
case "label": {
|
|
19445
|
+
return `.${final2}`;
|
|
19446
|
+
}
|
|
19447
|
+
case "matrix": {
|
|
19448
|
+
return `;${name}=${final2}`;
|
|
19449
|
+
}
|
|
19450
|
+
default: {
|
|
19451
|
+
return final2;
|
|
19452
|
+
}
|
|
19453
|
+
}
|
|
19454
|
+
}
|
|
19455
|
+
for (const k in value) {
|
|
19456
|
+
const finalName = options.style === "deepObject" ? `${name}[${k}]` : k;
|
|
19457
|
+
values.push(serializePrimitiveParam(finalName, value[k], options));
|
|
19458
|
+
}
|
|
19459
|
+
const final = values.join(joiner);
|
|
19460
|
+
return options.style === "label" || options.style === "matrix" ? `${joiner}${final}` : final;
|
|
19461
|
+
}
|
|
19462
|
+
function serializeArrayParam(name, value, options) {
|
|
19463
|
+
if (!Array.isArray(value)) {
|
|
19464
|
+
return "";
|
|
19465
|
+
}
|
|
19466
|
+
if (options.explode === false) {
|
|
19467
|
+
const joiner2 = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[options.style] || ",";
|
|
19468
|
+
const final = (options.allowReserved === true ? value : value.map((v) => encodeURIComponent(v))).join(joiner2);
|
|
19469
|
+
switch (options.style) {
|
|
19470
|
+
case "simple": {
|
|
19471
|
+
return final;
|
|
19472
|
+
}
|
|
19473
|
+
case "label": {
|
|
19474
|
+
return `.${final}`;
|
|
19475
|
+
}
|
|
19476
|
+
case "matrix": {
|
|
19477
|
+
return `;${name}=${final}`;
|
|
19478
|
+
}
|
|
19479
|
+
// case "spaceDelimited":
|
|
19480
|
+
// case "pipeDelimited":
|
|
19481
|
+
default: {
|
|
19482
|
+
return `${name}=${final}`;
|
|
19483
|
+
}
|
|
19484
|
+
}
|
|
19485
|
+
}
|
|
19486
|
+
const joiner = { simple: ",", label: ".", matrix: ";" }[options.style] || "&";
|
|
19487
|
+
const values = [];
|
|
19488
|
+
for (const v of value) {
|
|
19489
|
+
if (options.style === "simple" || options.style === "label") {
|
|
19490
|
+
values.push(options.allowReserved === true ? v : encodeURIComponent(v));
|
|
19491
|
+
} else {
|
|
19492
|
+
values.push(serializePrimitiveParam(name, v, options));
|
|
19493
|
+
}
|
|
19494
|
+
}
|
|
19495
|
+
return options.style === "label" || options.style === "matrix" ? `${joiner}${values.join(joiner)}` : values.join(joiner);
|
|
19496
|
+
}
|
|
19497
|
+
function createQuerySerializer(options) {
|
|
19498
|
+
return function querySerializer(queryParams) {
|
|
19499
|
+
const search2 = [];
|
|
19500
|
+
if (queryParams && typeof queryParams === "object") {
|
|
19501
|
+
for (const name in queryParams) {
|
|
19502
|
+
const value = queryParams[name];
|
|
19503
|
+
if (value === void 0 || value === null) {
|
|
19504
|
+
continue;
|
|
19505
|
+
}
|
|
19506
|
+
if (Array.isArray(value)) {
|
|
19507
|
+
if (value.length === 0) {
|
|
19508
|
+
continue;
|
|
19509
|
+
}
|
|
19510
|
+
search2.push(
|
|
19511
|
+
serializeArrayParam(name, value, {
|
|
19512
|
+
style: "form",
|
|
19513
|
+
explode: true,
|
|
19514
|
+
...options?.array,
|
|
19515
|
+
allowReserved: options?.allowReserved || false
|
|
19516
|
+
})
|
|
19183
19517
|
);
|
|
19184
|
-
|
|
19185
|
-
|
|
19186
|
-
|
|
19518
|
+
continue;
|
|
19519
|
+
}
|
|
19520
|
+
if (typeof value === "object") {
|
|
19521
|
+
search2.push(
|
|
19522
|
+
serializeObjectParam(name, value, {
|
|
19523
|
+
style: "deepObject",
|
|
19524
|
+
explode: true,
|
|
19525
|
+
...options?.object,
|
|
19526
|
+
allowReserved: options?.allowReserved || false
|
|
19527
|
+
})
|
|
19187
19528
|
);
|
|
19529
|
+
continue;
|
|
19530
|
+
}
|
|
19531
|
+
search2.push(serializePrimitiveParam(name, value, options));
|
|
19532
|
+
}
|
|
19533
|
+
}
|
|
19534
|
+
return search2.join("&");
|
|
19535
|
+
};
|
|
19536
|
+
}
|
|
19537
|
+
function defaultPathSerializer(pathname, pathParams) {
|
|
19538
|
+
let nextURL = pathname;
|
|
19539
|
+
for (const match of pathname.match(PATH_PARAM_RE) ?? []) {
|
|
19540
|
+
let name = match.substring(1, match.length - 1);
|
|
19541
|
+
let explode = false;
|
|
19542
|
+
let style = "simple";
|
|
19543
|
+
if (name.endsWith("*")) {
|
|
19544
|
+
explode = true;
|
|
19545
|
+
name = name.substring(0, name.length - 1);
|
|
19546
|
+
}
|
|
19547
|
+
if (name.startsWith(".")) {
|
|
19548
|
+
style = "label";
|
|
19549
|
+
name = name.substring(1);
|
|
19550
|
+
} else if (name.startsWith(";")) {
|
|
19551
|
+
style = "matrix";
|
|
19552
|
+
name = name.substring(1);
|
|
19553
|
+
}
|
|
19554
|
+
if (!pathParams || pathParams[name] === void 0 || pathParams[name] === null) {
|
|
19555
|
+
continue;
|
|
19556
|
+
}
|
|
19557
|
+
const value = pathParams[name];
|
|
19558
|
+
if (Array.isArray(value)) {
|
|
19559
|
+
nextURL = nextURL.replace(match, serializeArrayParam(name, value, { style, explode }));
|
|
19560
|
+
continue;
|
|
19561
|
+
}
|
|
19562
|
+
if (typeof value === "object") {
|
|
19563
|
+
nextURL = nextURL.replace(match, serializeObjectParam(name, value, { style, explode }));
|
|
19564
|
+
continue;
|
|
19565
|
+
}
|
|
19566
|
+
if (style === "matrix") {
|
|
19567
|
+
nextURL = nextURL.replace(match, `;${serializePrimitiveParam(name, value)}`);
|
|
19568
|
+
continue;
|
|
19569
|
+
}
|
|
19570
|
+
nextURL = nextURL.replace(match, style === "label" ? `.${encodeURIComponent(value)}` : encodeURIComponent(value));
|
|
19571
|
+
}
|
|
19572
|
+
return nextURL;
|
|
19573
|
+
}
|
|
19574
|
+
function defaultBodySerializer(body, headers) {
|
|
19575
|
+
if (body instanceof FormData) {
|
|
19576
|
+
return body;
|
|
19577
|
+
}
|
|
19578
|
+
if (headers) {
|
|
19579
|
+
const contentType = headers.get instanceof Function ? headers.get("Content-Type") ?? headers.get("content-type") : headers["Content-Type"] ?? headers["content-type"];
|
|
19580
|
+
if (contentType === "application/x-www-form-urlencoded") {
|
|
19581
|
+
return new URLSearchParams(body).toString();
|
|
19582
|
+
}
|
|
19583
|
+
}
|
|
19584
|
+
return JSON.stringify(body);
|
|
19585
|
+
}
|
|
19586
|
+
function createFinalURL(pathname, options) {
|
|
19587
|
+
let finalURL = `${options.baseUrl}${pathname}`;
|
|
19588
|
+
if (options.params?.path) {
|
|
19589
|
+
finalURL = options.pathSerializer(finalURL, options.params.path);
|
|
19590
|
+
}
|
|
19591
|
+
let search2 = options.querySerializer(options.params.query ?? {});
|
|
19592
|
+
if (search2.startsWith("?")) {
|
|
19593
|
+
search2 = search2.substring(1);
|
|
19594
|
+
}
|
|
19595
|
+
if (search2) {
|
|
19596
|
+
finalURL += `?${search2}`;
|
|
19597
|
+
}
|
|
19598
|
+
return finalURL;
|
|
19599
|
+
}
|
|
19600
|
+
function mergeHeaders(...allHeaders) {
|
|
19601
|
+
const finalHeaders = new Headers();
|
|
19602
|
+
for (const h of allHeaders) {
|
|
19603
|
+
if (!h || typeof h !== "object") {
|
|
19604
|
+
continue;
|
|
19605
|
+
}
|
|
19606
|
+
const iterator = h instanceof Headers ? h.entries() : Object.entries(h);
|
|
19607
|
+
for (const [k, v] of iterator) {
|
|
19608
|
+
if (v === null) {
|
|
19609
|
+
finalHeaders.delete(k);
|
|
19610
|
+
} else if (Array.isArray(v)) {
|
|
19611
|
+
for (const v2 of v) {
|
|
19612
|
+
finalHeaders.append(k, v2);
|
|
19188
19613
|
}
|
|
19614
|
+
} else if (v !== void 0) {
|
|
19615
|
+
finalHeaders.set(k, v);
|
|
19616
|
+
}
|
|
19617
|
+
}
|
|
19618
|
+
}
|
|
19619
|
+
return finalHeaders;
|
|
19620
|
+
}
|
|
19621
|
+
function removeTrailingSlash(url2) {
|
|
19622
|
+
if (url2.endsWith("/")) {
|
|
19623
|
+
return url2.substring(0, url2.length - 1);
|
|
19624
|
+
}
|
|
19625
|
+
return url2;
|
|
19626
|
+
}
|
|
19627
|
+
var PATH_PARAM_RE, supportsRequestInitExt;
|
|
19628
|
+
var init_dist = __esm({
|
|
19629
|
+
"../../node_modules/.pnpm/openapi-fetch@0.17.0/node_modules/openapi-fetch/dist/index.mjs"() {
|
|
19630
|
+
"use strict";
|
|
19631
|
+
PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
19632
|
+
supportsRequestInitExt = () => {
|
|
19633
|
+
return typeof process === "object" && Number.parseInt(process?.versions?.node?.substring(0, 2)) >= 18 && process.versions.undici;
|
|
19634
|
+
};
|
|
19635
|
+
}
|
|
19636
|
+
});
|
|
19637
|
+
|
|
19638
|
+
// ../../node_modules/.pnpm/@antfly+sdk@0.0.14/node_modules/@antfly/sdk/dist/index.js
|
|
19639
|
+
var AntflyClient;
|
|
19640
|
+
var init_dist2 = __esm({
|
|
19641
|
+
"../../node_modules/.pnpm/@antfly+sdk@0.0.14/node_modules/@antfly/sdk/dist/index.js"() {
|
|
19642
|
+
"use strict";
|
|
19643
|
+
init_dist();
|
|
19644
|
+
AntflyClient = class {
|
|
19645
|
+
constructor(config2) {
|
|
19646
|
+
this.tables = {
|
|
19647
|
+
/**
|
|
19648
|
+
* List all tables
|
|
19649
|
+
*/
|
|
19650
|
+
list: async (params) => {
|
|
19651
|
+
const { data, error: error46 } = await this.client.GET("/tables", {
|
|
19652
|
+
params: params ? { query: params } : void 0
|
|
19653
|
+
});
|
|
19654
|
+
if (error46) throw new Error(`Failed to list tables: ${error46.error}`);
|
|
19655
|
+
return data;
|
|
19656
|
+
},
|
|
19657
|
+
/**
|
|
19658
|
+
* Get table details and status
|
|
19659
|
+
*/
|
|
19660
|
+
get: async (tableName) => {
|
|
19661
|
+
const { data, error: error46 } = await this.client.GET("/tables/{tableName}", {
|
|
19662
|
+
params: { path: { tableName } }
|
|
19663
|
+
});
|
|
19664
|
+
if (error46) throw new Error(`Failed to get table: ${error46.error}`);
|
|
19665
|
+
return data;
|
|
19666
|
+
},
|
|
19667
|
+
/**
|
|
19668
|
+
* Create a new table
|
|
19669
|
+
*/
|
|
19670
|
+
create: async (tableName, config3 = {}) => {
|
|
19671
|
+
const { data, error: error46 } = await this.client.POST("/tables/{tableName}", {
|
|
19672
|
+
params: { path: { tableName } },
|
|
19673
|
+
body: config3
|
|
19674
|
+
});
|
|
19675
|
+
if (error46) throw new Error(`Failed to create table: ${error46.error}`);
|
|
19676
|
+
return data;
|
|
19677
|
+
},
|
|
19678
|
+
/**
|
|
19679
|
+
* Drop a table
|
|
19680
|
+
*/
|
|
19681
|
+
drop: async (tableName) => {
|
|
19682
|
+
const { error: error46 } = await this.client.DELETE("/tables/{tableName}", {
|
|
19683
|
+
params: { path: { tableName } }
|
|
19684
|
+
});
|
|
19685
|
+
if (error46) throw new Error(`Failed to drop table: ${error46.error}`);
|
|
19686
|
+
return true;
|
|
19687
|
+
},
|
|
19688
|
+
/**
|
|
19689
|
+
* Update schema for a table
|
|
19690
|
+
*/
|
|
19691
|
+
updateSchema: async (tableName, config3) => {
|
|
19692
|
+
const { data, error: error46 } = await this.client.PUT("/tables/{tableName}/schema", {
|
|
19693
|
+
params: { path: { tableName } },
|
|
19694
|
+
body: config3
|
|
19695
|
+
});
|
|
19696
|
+
if (error46) throw new Error(`Failed to update table schema: ${error46.error}`);
|
|
19697
|
+
return data;
|
|
19698
|
+
},
|
|
19699
|
+
/**
|
|
19700
|
+
* Query a specific table
|
|
19701
|
+
*/
|
|
19702
|
+
query: async (tableName, request) => {
|
|
19703
|
+
return this.performQuery("/tables/{tableName}/query", request, tableName);
|
|
19704
|
+
},
|
|
19705
|
+
/**
|
|
19706
|
+
* Execute multiple queries on a specific table
|
|
19707
|
+
*/
|
|
19708
|
+
multiquery: async (tableName, requests) => {
|
|
19709
|
+
return this.performMultiquery("/tables/{tableName}/query", requests, tableName);
|
|
19710
|
+
},
|
|
19711
|
+
/**
|
|
19712
|
+
* Perform batch operations on a table
|
|
19713
|
+
*/
|
|
19714
|
+
batch: async (tableName, request) => {
|
|
19715
|
+
const { data, error: error46 } = await this.client.POST("/tables/{tableName}/batch", {
|
|
19716
|
+
params: { path: { tableName } },
|
|
19717
|
+
// @ts-expect-error Our BatchRequest type allows any object shape for inserts
|
|
19718
|
+
body: request
|
|
19719
|
+
});
|
|
19720
|
+
if (error46) throw new Error(`Batch operation failed: ${error46.error}`);
|
|
19721
|
+
return data;
|
|
19722
|
+
},
|
|
19723
|
+
/**
|
|
19724
|
+
* Backup a table
|
|
19725
|
+
*/
|
|
19726
|
+
backup: async (tableName, request) => {
|
|
19727
|
+
const { data, error: error46 } = await this.client.POST("/tables/{tableName}/backup", {
|
|
19728
|
+
params: { path: { tableName } },
|
|
19729
|
+
body: request
|
|
19730
|
+
});
|
|
19731
|
+
if (error46) throw new Error(`Backup failed: ${error46.error}`);
|
|
19732
|
+
return data;
|
|
19733
|
+
},
|
|
19734
|
+
/**
|
|
19735
|
+
* Restore a table from backup
|
|
19736
|
+
*/
|
|
19737
|
+
restore: async (tableName, request) => {
|
|
19738
|
+
const { data, error: error46 } = await this.client.POST("/tables/{tableName}/restore", {
|
|
19739
|
+
params: { path: { tableName } },
|
|
19740
|
+
body: request
|
|
19741
|
+
});
|
|
19742
|
+
if (error46) throw new Error(`Restore failed: ${error46.error}`);
|
|
19743
|
+
return data;
|
|
19744
|
+
},
|
|
19745
|
+
/**
|
|
19746
|
+
* Lookup a specific key in a table
|
|
19747
|
+
* @param tableName - Name of the table
|
|
19748
|
+
* @param key - Key of the record to lookup
|
|
19749
|
+
* @param options - Optional parameters
|
|
19750
|
+
* @param options.fields - Comma-separated list of fields to include (e.g., "title,author,metadata.tags")
|
|
19751
|
+
*/
|
|
19752
|
+
lookup: async (tableName, key, options) => {
|
|
19753
|
+
const { data, error: error46 } = await this.client.GET("/tables/{tableName}/lookup/{key}", {
|
|
19754
|
+
params: {
|
|
19755
|
+
path: { tableName, key },
|
|
19756
|
+
query: options?.fields ? { fields: options.fields } : void 0
|
|
19757
|
+
}
|
|
19758
|
+
});
|
|
19759
|
+
if (error46) throw new Error(`Key lookup failed: ${error46.error}`);
|
|
19760
|
+
return data;
|
|
19761
|
+
},
|
|
19762
|
+
/**
|
|
19763
|
+
* Scan keys in a table within a key range
|
|
19764
|
+
* Returns documents as an async iterable, streaming results as NDJSON.
|
|
19765
|
+
* @param tableName - Name of the table
|
|
19766
|
+
* @param request - Scan request with optional key range, field projection, and filtering
|
|
19767
|
+
* @returns AsyncGenerator yielding documents with their keys
|
|
19768
|
+
*/
|
|
19769
|
+
scan: (tableName, request) => {
|
|
19770
|
+
const config3 = this.config;
|
|
19771
|
+
const authHeader = this.getAuthHeader();
|
|
19772
|
+
async function* scanGenerator() {
|
|
19773
|
+
const headers = {
|
|
19774
|
+
"Content-Type": "application/json",
|
|
19775
|
+
Accept: "application/x-ndjson"
|
|
19776
|
+
};
|
|
19777
|
+
if (authHeader) {
|
|
19778
|
+
headers.Authorization = authHeader;
|
|
19779
|
+
}
|
|
19780
|
+
Object.assign(headers, config3.headers);
|
|
19781
|
+
const response = await fetch(`${config3.baseUrl}/tables/${tableName}/lookup`, {
|
|
19782
|
+
method: "POST",
|
|
19783
|
+
headers,
|
|
19784
|
+
body: JSON.stringify(request || {})
|
|
19785
|
+
});
|
|
19786
|
+
if (!response.ok) {
|
|
19787
|
+
const errorText = await response.text();
|
|
19788
|
+
throw new Error(`Scan failed: ${response.status} ${errorText}`);
|
|
19789
|
+
}
|
|
19790
|
+
if (!response.body) {
|
|
19791
|
+
throw new Error("Response body is null");
|
|
19792
|
+
}
|
|
19793
|
+
const reader = response.body.getReader();
|
|
19794
|
+
const decoder = new TextDecoder();
|
|
19795
|
+
let buffer = "";
|
|
19796
|
+
while (true) {
|
|
19797
|
+
const { done, value } = await reader.read();
|
|
19798
|
+
if (done) break;
|
|
19799
|
+
buffer += decoder.decode(value, { stream: true });
|
|
19800
|
+
const lines = buffer.split("\n");
|
|
19801
|
+
buffer = lines.pop() || "";
|
|
19802
|
+
for (const line of lines) {
|
|
19803
|
+
if (line.trim()) {
|
|
19804
|
+
yield JSON.parse(line);
|
|
19805
|
+
}
|
|
19806
|
+
}
|
|
19807
|
+
}
|
|
19808
|
+
if (buffer.trim()) {
|
|
19809
|
+
yield JSON.parse(buffer);
|
|
19810
|
+
}
|
|
19811
|
+
}
|
|
19812
|
+
return scanGenerator();
|
|
19813
|
+
},
|
|
19814
|
+
/**
|
|
19815
|
+
* Scan keys in a table and collect all results into an array
|
|
19816
|
+
* Convenience method that consumes the scan AsyncGenerator
|
|
19817
|
+
* @param tableName - Name of the table
|
|
19818
|
+
* @param request - Scan request with optional key range, field projection, and filtering
|
|
19819
|
+
* @returns Promise with array of all matching documents
|
|
19820
|
+
*/
|
|
19821
|
+
scanAll: async (tableName, request) => {
|
|
19822
|
+
const results = [];
|
|
19823
|
+
for await (const doc of this.tables.scan(tableName, request)) {
|
|
19824
|
+
results.push(doc);
|
|
19825
|
+
}
|
|
19826
|
+
return results;
|
|
19827
|
+
}
|
|
19828
|
+
};
|
|
19829
|
+
this.indexes = {
|
|
19830
|
+
/**
|
|
19831
|
+
* List all indexes for a table
|
|
19832
|
+
*/
|
|
19833
|
+
list: async (tableName) => {
|
|
19834
|
+
const { data, error: error46 } = await this.client.GET("/tables/{tableName}/indexes", {
|
|
19835
|
+
params: { path: { tableName } }
|
|
19836
|
+
});
|
|
19837
|
+
if (error46) throw new Error(`Failed to list indexes: ${error46.error}`);
|
|
19838
|
+
return data;
|
|
19839
|
+
},
|
|
19840
|
+
/**
|
|
19841
|
+
* Get index details
|
|
19842
|
+
*/
|
|
19843
|
+
get: async (tableName, indexName) => {
|
|
19844
|
+
const { data, error: error46 } = await this.client.GET("/tables/{tableName}/indexes/{indexName}", {
|
|
19845
|
+
params: { path: { tableName, indexName } }
|
|
19846
|
+
});
|
|
19847
|
+
if (error46) throw new Error(`Failed to get index: ${error46.error}`);
|
|
19848
|
+
return data;
|
|
19849
|
+
},
|
|
19850
|
+
/**
|
|
19851
|
+
* Create a new index
|
|
19852
|
+
*/
|
|
19853
|
+
create: async (tableName, config3) => {
|
|
19854
|
+
const { error: error46 } = await this.client.POST("/tables/{tableName}/indexes/{indexName}", {
|
|
19855
|
+
params: { path: { tableName, indexName: config3.name } },
|
|
19856
|
+
body: config3
|
|
19857
|
+
});
|
|
19858
|
+
if (error46) throw new Error(`Failed to create index: ${error46.error}`);
|
|
19859
|
+
return true;
|
|
19860
|
+
},
|
|
19861
|
+
/**
|
|
19862
|
+
* Drop an index
|
|
19863
|
+
*/
|
|
19864
|
+
drop: async (tableName, indexName) => {
|
|
19865
|
+
const { error: error46 } = await this.client.DELETE("/tables/{tableName}/indexes/{indexName}", {
|
|
19866
|
+
params: { path: { tableName, indexName } }
|
|
19867
|
+
});
|
|
19868
|
+
if (error46) throw new Error(`Failed to drop index: ${error46.error}`);
|
|
19869
|
+
return true;
|
|
19870
|
+
}
|
|
19871
|
+
};
|
|
19872
|
+
this.users = {
|
|
19873
|
+
/**
|
|
19874
|
+
* Get current authenticated user
|
|
19875
|
+
*/
|
|
19876
|
+
getCurrentUser: async () => {
|
|
19877
|
+
const { data, error: error46 } = await this.client.GET("/users/me");
|
|
19878
|
+
if (error46) throw new Error(`Failed to get current user: ${error46.error}`);
|
|
19879
|
+
return data;
|
|
19880
|
+
},
|
|
19881
|
+
/**
|
|
19882
|
+
* List all users
|
|
19883
|
+
*/
|
|
19884
|
+
list: async () => {
|
|
19885
|
+
const { data, error: error46 } = await this.client.GET("/users");
|
|
19886
|
+
if (error46) throw new Error(`Failed to list users: ${error46.error}`);
|
|
19887
|
+
return data;
|
|
19888
|
+
},
|
|
19889
|
+
/**
|
|
19890
|
+
* Get user details
|
|
19891
|
+
*/
|
|
19892
|
+
get: async (userName) => {
|
|
19893
|
+
const { data, error: error46 } = await this.client.GET("/users/{userName}", {
|
|
19894
|
+
params: { path: { userName } }
|
|
19895
|
+
});
|
|
19896
|
+
if (error46) throw new Error(`Failed to get user: ${error46.error}`);
|
|
19897
|
+
return data;
|
|
19898
|
+
},
|
|
19899
|
+
/**
|
|
19900
|
+
* Create a new user
|
|
19901
|
+
*/
|
|
19902
|
+
create: async (userName, request) => {
|
|
19903
|
+
const { data, error: error46 } = await this.client.POST("/users/{userName}", {
|
|
19904
|
+
params: { path: { userName } },
|
|
19905
|
+
body: request
|
|
19906
|
+
});
|
|
19907
|
+
if (error46) throw new Error(`Failed to create user: ${error46.error}`);
|
|
19908
|
+
return data;
|
|
19909
|
+
},
|
|
19910
|
+
/**
|
|
19911
|
+
* Delete a user
|
|
19912
|
+
*/
|
|
19913
|
+
delete: async (userName) => {
|
|
19914
|
+
const { error: error46 } = await this.client.DELETE("/users/{userName}", {
|
|
19915
|
+
params: { path: { userName } }
|
|
19916
|
+
});
|
|
19917
|
+
if (error46) throw new Error(`Failed to delete user: ${error46.error}`);
|
|
19918
|
+
return true;
|
|
19919
|
+
},
|
|
19920
|
+
/**
|
|
19921
|
+
* Update user password
|
|
19922
|
+
*/
|
|
19923
|
+
updatePassword: async (userName, newPassword) => {
|
|
19924
|
+
const { data, error: error46 } = await this.client.PUT("/users/{userName}/password", {
|
|
19925
|
+
params: { path: { userName } },
|
|
19926
|
+
body: { new_password: newPassword }
|
|
19927
|
+
});
|
|
19928
|
+
if (error46) throw new Error(`Failed to update password: ${error46.error}`);
|
|
19929
|
+
return data;
|
|
19930
|
+
},
|
|
19931
|
+
/**
|
|
19932
|
+
* Get user permissions
|
|
19933
|
+
*/
|
|
19934
|
+
getPermissions: async (userName) => {
|
|
19935
|
+
const { data, error: error46 } = await this.client.GET("/users/{userName}/permissions", {
|
|
19936
|
+
params: { path: { userName } }
|
|
19937
|
+
});
|
|
19938
|
+
if (error46) throw new Error(`Failed to get permissions: ${error46.error}`);
|
|
19939
|
+
return data;
|
|
19940
|
+
},
|
|
19941
|
+
/**
|
|
19942
|
+
* Add permission to user
|
|
19943
|
+
*/
|
|
19944
|
+
addPermission: async (userName, permission) => {
|
|
19945
|
+
const { data, error: error46 } = await this.client.POST("/users/{userName}/permissions", {
|
|
19946
|
+
params: { path: { userName } },
|
|
19947
|
+
body: permission
|
|
19948
|
+
});
|
|
19949
|
+
if (error46) throw new Error(`Failed to add permission: ${error46.error}`);
|
|
19950
|
+
return data;
|
|
19951
|
+
},
|
|
19952
|
+
/**
|
|
19953
|
+
* Remove permission from user
|
|
19954
|
+
*/
|
|
19955
|
+
removePermission: async (userName, resource, resourceType) => {
|
|
19956
|
+
const { error: error46 } = await this.client.DELETE("/users/{userName}/permissions", {
|
|
19957
|
+
params: {
|
|
19958
|
+
path: { userName },
|
|
19959
|
+
query: { resource, resourceType }
|
|
19960
|
+
}
|
|
19961
|
+
});
|
|
19962
|
+
if (error46) throw new Error(`Failed to remove permission: ${error46.error}`);
|
|
19963
|
+
return true;
|
|
19964
|
+
}
|
|
19965
|
+
};
|
|
19966
|
+
this.config = config2;
|
|
19967
|
+
this.client = this.buildClient();
|
|
19189
19968
|
}
|
|
19190
19969
|
/**
|
|
19191
|
-
*
|
|
19970
|
+
* Build the Authorization header value from the auth config.
|
|
19971
|
+
* Returns undefined if no auth is configured.
|
|
19192
19972
|
*/
|
|
19193
|
-
|
|
19194
|
-
|
|
19195
|
-
|
|
19196
|
-
|
|
19197
|
-
|
|
19198
|
-
|
|
19199
|
-
|
|
19200
|
-
|
|
19201
|
-
|
|
19202
|
-
|
|
19203
|
-
|
|
19204
|
-
const output = await this.pipeline(text3, options);
|
|
19205
|
-
const tensorOutput = output;
|
|
19206
|
-
if (tensorOutput?.data) {
|
|
19207
|
-
return Array.from(tensorOutput.data);
|
|
19973
|
+
getAuthHeader() {
|
|
19974
|
+
const auth = this.config.auth;
|
|
19975
|
+
if (!auth) return void 0;
|
|
19976
|
+
if ("type" in auth) {
|
|
19977
|
+
switch (auth.type) {
|
|
19978
|
+
case "basic":
|
|
19979
|
+
return `Basic ${btoa(`${auth.username}:${auth.password}`)}`;
|
|
19980
|
+
case "apiKey":
|
|
19981
|
+
return `ApiKey ${btoa(`${auth.keyId}:${auth.keySecret}`)}`;
|
|
19982
|
+
case "bearer":
|
|
19983
|
+
return `Bearer ${auth.token}`;
|
|
19208
19984
|
}
|
|
19209
|
-
throw new Error("Unexpected output format from embedding model");
|
|
19210
|
-
} catch (error46) {
|
|
19211
|
-
throw new Error(
|
|
19212
|
-
`Failed to generate embedding: ${error46 instanceof Error ? error46.message : String(error46)}`
|
|
19213
|
-
);
|
|
19214
19985
|
}
|
|
19986
|
+
return `Basic ${btoa(`${auth.username}:${auth.password}`)}`;
|
|
19215
19987
|
}
|
|
19216
19988
|
/**
|
|
19217
|
-
*
|
|
19989
|
+
* Build the openapi-fetch client with current config.
|
|
19218
19990
|
*/
|
|
19219
|
-
|
|
19220
|
-
|
|
19221
|
-
|
|
19222
|
-
|
|
19223
|
-
|
|
19224
|
-
|
|
19991
|
+
buildClient() {
|
|
19992
|
+
const headers = {
|
|
19993
|
+
"Content-Type": "application/json",
|
|
19994
|
+
...this.config.headers
|
|
19995
|
+
};
|
|
19996
|
+
const authHeader = this.getAuthHeader();
|
|
19997
|
+
if (authHeader) {
|
|
19998
|
+
headers.Authorization = authHeader;
|
|
19225
19999
|
}
|
|
19226
|
-
|
|
19227
|
-
|
|
19228
|
-
|
|
19229
|
-
|
|
19230
|
-
|
|
19231
|
-
|
|
20000
|
+
return createClient({
|
|
20001
|
+
baseUrl: this.config.baseUrl,
|
|
20002
|
+
headers,
|
|
20003
|
+
bodySerializer: (body) => {
|
|
20004
|
+
if (typeof body === "string") {
|
|
20005
|
+
return body;
|
|
20006
|
+
}
|
|
20007
|
+
return JSON.stringify(body);
|
|
19232
20008
|
}
|
|
19233
|
-
|
|
19234
|
-
|
|
19235
|
-
|
|
19236
|
-
|
|
19237
|
-
|
|
20009
|
+
});
|
|
20010
|
+
}
|
|
20011
|
+
setAuth(authOrUsername, password) {
|
|
20012
|
+
if (typeof authOrUsername === "string" && password !== void 0) {
|
|
20013
|
+
this.config.auth = { username: authOrUsername, password };
|
|
20014
|
+
} else {
|
|
20015
|
+
this.config.auth = authOrUsername;
|
|
19238
20016
|
}
|
|
20017
|
+
this.client = this.buildClient();
|
|
20018
|
+
}
|
|
20019
|
+
/**
|
|
20020
|
+
* Get cluster status
|
|
20021
|
+
*/
|
|
20022
|
+
async getStatus() {
|
|
20023
|
+
const { data, error: error46 } = await this.client.GET("/status");
|
|
20024
|
+
if (error46) throw new Error(`Failed to get status: ${error46.error}`);
|
|
20025
|
+
return data;
|
|
19239
20026
|
}
|
|
19240
20027
|
/**
|
|
19241
|
-
*
|
|
20028
|
+
* Private helper for query requests to avoid code duplication
|
|
19242
20029
|
*/
|
|
19243
|
-
|
|
19244
|
-
if (
|
|
19245
|
-
|
|
20030
|
+
async performQuery(path16, request, tableName) {
|
|
20031
|
+
if (path16 === "/tables/{tableName}/query" && tableName) {
|
|
20032
|
+
const { data, error: error46 } = await this.client.POST("/tables/{tableName}/query", {
|
|
20033
|
+
params: { path: { tableName } },
|
|
20034
|
+
body: request
|
|
20035
|
+
});
|
|
20036
|
+
if (error46) throw new Error(`Table query failed: ${error46.error}`);
|
|
20037
|
+
return data;
|
|
20038
|
+
} else {
|
|
20039
|
+
const { data, error: error46 } = await this.client.POST("/query", {
|
|
20040
|
+
body: request
|
|
20041
|
+
});
|
|
20042
|
+
if (error46) throw new Error(`Query failed: ${error46.error}`);
|
|
20043
|
+
return data;
|
|
19246
20044
|
}
|
|
19247
|
-
this.batchSize = size;
|
|
19248
20045
|
}
|
|
19249
20046
|
/**
|
|
19250
|
-
*
|
|
20047
|
+
* Private helper for multiquery requests to avoid code duplication
|
|
19251
20048
|
*/
|
|
19252
|
-
|
|
19253
|
-
|
|
20049
|
+
async performMultiquery(path16, requests, tableName) {
|
|
20050
|
+
const ndjson = `${requests.map((request) => JSON.stringify(request)).join("\n")}
|
|
20051
|
+
`;
|
|
20052
|
+
if (path16 === "/tables/{tableName}/query" && tableName) {
|
|
20053
|
+
const { data, error: error46 } = await this.client.POST("/tables/{tableName}/query", {
|
|
20054
|
+
params: { path: { tableName } },
|
|
20055
|
+
body: ndjson,
|
|
20056
|
+
headers: {
|
|
20057
|
+
"Content-Type": "application/x-ndjson"
|
|
20058
|
+
}
|
|
20059
|
+
});
|
|
20060
|
+
if (error46) throw new Error(`Table multi-query failed: ${error46.error}`);
|
|
20061
|
+
return data;
|
|
20062
|
+
} else {
|
|
20063
|
+
const { data, error: error46 } = await this.client.POST("/query", {
|
|
20064
|
+
body: ndjson,
|
|
20065
|
+
headers: {
|
|
20066
|
+
"Content-Type": "application/x-ndjson"
|
|
20067
|
+
}
|
|
20068
|
+
});
|
|
20069
|
+
if (error46) throw new Error(`Multi-query failed: ${error46.error}`);
|
|
20070
|
+
return data;
|
|
20071
|
+
}
|
|
19254
20072
|
}
|
|
19255
|
-
|
|
19256
|
-
|
|
19257
|
-
|
|
19258
|
-
|
|
19259
|
-
|
|
19260
|
-
|
|
19261
|
-
var init_store = __esm({
|
|
19262
|
-
"../core/src/vector/store.ts"() {
|
|
19263
|
-
"use strict";
|
|
19264
|
-
lancedb = __toESM(require("@lancedb/lancedb"));
|
|
19265
|
-
LanceDBVectorStore = class {
|
|
19266
|
-
path;
|
|
19267
|
-
tableName = "documents";
|
|
19268
|
-
connection = null;
|
|
19269
|
-
table = null;
|
|
19270
|
-
constructor(path16, _dimension = 384) {
|
|
19271
|
-
this.path = path16;
|
|
20073
|
+
/**
|
|
20074
|
+
* Global query operations
|
|
20075
|
+
*/
|
|
20076
|
+
async query(request) {
|
|
20077
|
+
const data = await this.performQuery("/query", request);
|
|
20078
|
+
return data?.responses?.[0];
|
|
19272
20079
|
}
|
|
19273
20080
|
/**
|
|
19274
|
-
*
|
|
20081
|
+
* Execute multiple queries in a single request
|
|
19275
20082
|
*/
|
|
19276
|
-
async
|
|
19277
|
-
|
|
19278
|
-
return;
|
|
19279
|
-
}
|
|
19280
|
-
try {
|
|
19281
|
-
this.connection = await lancedb.connect(this.path);
|
|
19282
|
-
const tableNames = await this.connection.tableNames();
|
|
19283
|
-
if (tableNames.includes(this.tableName)) {
|
|
19284
|
-
this.table = await this.connection.openTable(this.tableName);
|
|
19285
|
-
}
|
|
19286
|
-
} catch (error46) {
|
|
19287
|
-
throw new Error(
|
|
19288
|
-
`Failed to initialize LanceDB at ${this.path}: ${error46 instanceof Error ? error46.message : String(error46)}`
|
|
19289
|
-
);
|
|
19290
|
-
}
|
|
20083
|
+
async multiquery(requests) {
|
|
20084
|
+
return this.performMultiquery("/query", requests);
|
|
19291
20085
|
}
|
|
19292
20086
|
/**
|
|
19293
|
-
*
|
|
20087
|
+
* Private helper for Retrieval Agent requests to handle streaming and non-streaming responses
|
|
19294
20088
|
*/
|
|
19295
|
-
async
|
|
19296
|
-
|
|
19297
|
-
|
|
20089
|
+
async performRetrievalAgent(request, callbacks) {
|
|
20090
|
+
const headers = {
|
|
20091
|
+
"Content-Type": "application/json",
|
|
20092
|
+
Accept: "text/event-stream, application/json"
|
|
20093
|
+
};
|
|
20094
|
+
const authHeader = this.getAuthHeader();
|
|
20095
|
+
if (authHeader) {
|
|
20096
|
+
headers.Authorization = authHeader;
|
|
20097
|
+
}
|
|
20098
|
+
Object.assign(headers, this.config.headers);
|
|
20099
|
+
const abortController = new AbortController();
|
|
20100
|
+
const response = await fetch(`${this.config.baseUrl}/agents/retrieval`, {
|
|
20101
|
+
method: "POST",
|
|
20102
|
+
headers,
|
|
20103
|
+
body: JSON.stringify(request),
|
|
20104
|
+
signal: abortController.signal
|
|
20105
|
+
});
|
|
20106
|
+
if (!response.ok) {
|
|
20107
|
+
const errorText = await response.text();
|
|
20108
|
+
throw new Error(`Retrieval agent request failed: ${response.status} ${errorText}`);
|
|
19298
20109
|
}
|
|
19299
|
-
if (
|
|
19300
|
-
throw new Error("
|
|
20110
|
+
if (!response.body) {
|
|
20111
|
+
throw new Error("Response body is null");
|
|
19301
20112
|
}
|
|
19302
|
-
|
|
19303
|
-
|
|
20113
|
+
const contentType = response.headers.get("content-type") || "";
|
|
20114
|
+
const isJSON = contentType.includes("application/json");
|
|
20115
|
+
if (isJSON) {
|
|
20116
|
+
const result = await response.json();
|
|
20117
|
+
return result;
|
|
19304
20118
|
}
|
|
19305
|
-
|
|
19306
|
-
const
|
|
19307
|
-
|
|
19308
|
-
|
|
19309
|
-
|
|
19310
|
-
|
|
19311
|
-
}));
|
|
19312
|
-
if (!this.table) {
|
|
20119
|
+
if (callbacks) {
|
|
20120
|
+
const reader = response.body.getReader();
|
|
20121
|
+
const decoder = new TextDecoder();
|
|
20122
|
+
let buffer = "";
|
|
20123
|
+
let currentEvent = "";
|
|
20124
|
+
(async () => {
|
|
19313
20125
|
try {
|
|
19314
|
-
|
|
19315
|
-
|
|
19316
|
-
|
|
19317
|
-
|
|
19318
|
-
|
|
19319
|
-
|
|
19320
|
-
|
|
19321
|
-
|
|
20126
|
+
while (true) {
|
|
20127
|
+
const { done, value } = await reader.read();
|
|
20128
|
+
if (done) break;
|
|
20129
|
+
buffer += decoder.decode(value, { stream: true });
|
|
20130
|
+
const lines = buffer.split("\n");
|
|
20131
|
+
buffer = lines.pop() || "";
|
|
20132
|
+
for (const line of lines) {
|
|
20133
|
+
if (!line.trim()) {
|
|
20134
|
+
currentEvent = "";
|
|
20135
|
+
continue;
|
|
20136
|
+
}
|
|
20137
|
+
if (line.startsWith("event: ")) {
|
|
20138
|
+
currentEvent = line.slice(7).trim();
|
|
20139
|
+
} else if (line.startsWith("data: ")) {
|
|
20140
|
+
const data = line.slice(6).trim();
|
|
20141
|
+
try {
|
|
20142
|
+
switch (currentEvent) {
|
|
20143
|
+
case "classification":
|
|
20144
|
+
if (callbacks.onClassification) {
|
|
20145
|
+
callbacks.onClassification(JSON.parse(data));
|
|
20146
|
+
}
|
|
20147
|
+
break;
|
|
20148
|
+
case "reasoning":
|
|
20149
|
+
if (callbacks.onReasoning) {
|
|
20150
|
+
callbacks.onReasoning(JSON.parse(data));
|
|
20151
|
+
}
|
|
20152
|
+
break;
|
|
20153
|
+
case "clarification_required":
|
|
20154
|
+
if (callbacks.onClarificationRequired) {
|
|
20155
|
+
callbacks.onClarificationRequired(JSON.parse(data));
|
|
20156
|
+
}
|
|
20157
|
+
break;
|
|
20158
|
+
case "filter_applied":
|
|
20159
|
+
if (callbacks.onFilterApplied) {
|
|
20160
|
+
callbacks.onFilterApplied(JSON.parse(data));
|
|
20161
|
+
}
|
|
20162
|
+
break;
|
|
20163
|
+
case "search_executed":
|
|
20164
|
+
if (callbacks.onSearchExecuted) {
|
|
20165
|
+
callbacks.onSearchExecuted(JSON.parse(data));
|
|
20166
|
+
}
|
|
20167
|
+
break;
|
|
20168
|
+
case "hit":
|
|
20169
|
+
if (callbacks.onHit) {
|
|
20170
|
+
callbacks.onHit(JSON.parse(data));
|
|
20171
|
+
}
|
|
20172
|
+
break;
|
|
20173
|
+
case "generation":
|
|
20174
|
+
if (callbacks.onGeneration) {
|
|
20175
|
+
callbacks.onGeneration(JSON.parse(data));
|
|
20176
|
+
}
|
|
20177
|
+
break;
|
|
20178
|
+
case "step_started":
|
|
20179
|
+
if (callbacks.onStepStarted) {
|
|
20180
|
+
callbacks.onStepStarted(JSON.parse(data));
|
|
20181
|
+
}
|
|
20182
|
+
break;
|
|
20183
|
+
case "step_progress":
|
|
20184
|
+
if (callbacks.onStepProgress) {
|
|
20185
|
+
callbacks.onStepProgress(JSON.parse(data));
|
|
20186
|
+
}
|
|
20187
|
+
break;
|
|
20188
|
+
case "step_completed":
|
|
20189
|
+
if (callbacks.onStepCompleted) {
|
|
20190
|
+
callbacks.onStepCompleted(JSON.parse(data));
|
|
20191
|
+
}
|
|
20192
|
+
break;
|
|
20193
|
+
case "confidence":
|
|
20194
|
+
if (callbacks.onConfidence) {
|
|
20195
|
+
callbacks.onConfidence(JSON.parse(data));
|
|
20196
|
+
}
|
|
20197
|
+
break;
|
|
20198
|
+
case "followup":
|
|
20199
|
+
if (callbacks.onFollowup) {
|
|
20200
|
+
callbacks.onFollowup(JSON.parse(data));
|
|
20201
|
+
}
|
|
20202
|
+
break;
|
|
20203
|
+
case "eval":
|
|
20204
|
+
if (callbacks.onEvalResult) {
|
|
20205
|
+
callbacks.onEvalResult(JSON.parse(data));
|
|
20206
|
+
}
|
|
20207
|
+
break;
|
|
20208
|
+
case "done":
|
|
20209
|
+
if (callbacks.onDone) {
|
|
20210
|
+
callbacks.onDone(JSON.parse(data));
|
|
20211
|
+
}
|
|
20212
|
+
return;
|
|
20213
|
+
case "error":
|
|
20214
|
+
if (callbacks.onError) {
|
|
20215
|
+
callbacks.onError(JSON.parse(data));
|
|
20216
|
+
}
|
|
20217
|
+
throw new Error(data);
|
|
20218
|
+
}
|
|
20219
|
+
} catch (e) {
|
|
20220
|
+
console.warn("Failed to parse SSE data:", currentEvent, data, e);
|
|
20221
|
+
}
|
|
20222
|
+
}
|
|
20223
|
+
}
|
|
20224
|
+
}
|
|
20225
|
+
} catch (error46) {
|
|
20226
|
+
if (error46.name !== "AbortError") {
|
|
20227
|
+
console.error("Retrieval agent streaming error:", error46);
|
|
19322
20228
|
}
|
|
19323
20229
|
}
|
|
19324
|
-
}
|
|
19325
|
-
await this.table.mergeInsert("id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(data);
|
|
19326
|
-
}
|
|
19327
|
-
} catch (error46) {
|
|
19328
|
-
throw new Error(
|
|
19329
|
-
`Failed to add documents: ${error46 instanceof Error ? error46.message : String(error46)}`
|
|
19330
|
-
);
|
|
20230
|
+
})();
|
|
19331
20231
|
}
|
|
20232
|
+
return abortController;
|
|
19332
20233
|
}
|
|
19333
20234
|
/**
|
|
19334
|
-
*
|
|
20235
|
+
* Retrieval Agent - Unified retrieval pipeline with optional classification, generation, and eval
|
|
20236
|
+
* Supports pipeline mode (structured queries) and agentic mode (tool-calling with LLM)
|
|
20237
|
+
* Configure steps.classification, steps.answer, steps.eval to enable additional pipeline stages
|
|
20238
|
+
* @param request - Retrieval agent request with query, mode, and optional step configs
|
|
20239
|
+
* @param callbacks - Optional callbacks for SSE events (classification, reasoning, hit, answer, citation, confidence, followup_question, eval, done, error)
|
|
20240
|
+
* @returns Promise with RetrievalAgentResult (JSON) or AbortController (when streaming)
|
|
19335
20241
|
*/
|
|
19336
|
-
async
|
|
19337
|
-
|
|
19338
|
-
|
|
19339
|
-
|
|
19340
|
-
|
|
19341
|
-
|
|
19342
|
-
|
|
19343
|
-
|
|
19344
|
-
|
|
19345
|
-
|
|
19346
|
-
|
|
19347
|
-
|
|
19348
|
-
|
|
19349
|
-
|
|
19350
|
-
|
|
19351
|
-
|
|
19352
|
-
|
|
19353
|
-
|
|
19354
|
-
|
|
20242
|
+
async retrievalAgent(request, callbacks) {
|
|
20243
|
+
return this.performRetrievalAgent(request, callbacks);
|
|
20244
|
+
}
|
|
20245
|
+
/**
|
|
20246
|
+
* Chat Agent - Multi-turn conversational retrieval with message history management.
|
|
20247
|
+
* Wraps the retrieval agent with automatic message accumulation.
|
|
20248
|
+
* @param userMessage - The user's message for this turn
|
|
20249
|
+
* @param config - Chat configuration (generator, table, indexes, etc.)
|
|
20250
|
+
* @param history - Previous conversation messages (pass result.messages from prior turns)
|
|
20251
|
+
* @param callbacks - Optional streaming callbacks including chat-specific events
|
|
20252
|
+
* @returns For streaming: { abortController, messages } where messages is a Promise.
|
|
20253
|
+
* For non-streaming: { result, messages }
|
|
20254
|
+
*/
|
|
20255
|
+
async chatAgent(userMessage, config2, history = [], callbacks) {
|
|
20256
|
+
const request = {
|
|
20257
|
+
query: userMessage,
|
|
20258
|
+
queries: [
|
|
20259
|
+
{
|
|
20260
|
+
table: config2.table,
|
|
20261
|
+
semantic_search: userMessage,
|
|
20262
|
+
indexes: config2.semanticIndexes,
|
|
20263
|
+
limit: config2.limit ?? 10
|
|
20264
|
+
}
|
|
20265
|
+
],
|
|
20266
|
+
generator: config2.generator,
|
|
20267
|
+
messages: [...history, { role: "user", content: userMessage }],
|
|
20268
|
+
max_iterations: config2.maxIterations ?? 5,
|
|
20269
|
+
stream: !!callbacks,
|
|
20270
|
+
agent_knowledge: config2.agentKnowledge
|
|
20271
|
+
};
|
|
20272
|
+
if (config2.steps) {
|
|
20273
|
+
request.steps = config2.steps;
|
|
20274
|
+
}
|
|
20275
|
+
if (callbacks) {
|
|
20276
|
+
let answerText = "";
|
|
20277
|
+
let resolveMessages;
|
|
20278
|
+
const messagesPromise = new Promise((resolve4) => {
|
|
20279
|
+
resolveMessages = resolve4;
|
|
20280
|
+
});
|
|
20281
|
+
const wrappedCallbacks = {
|
|
20282
|
+
...callbacks,
|
|
20283
|
+
onGeneration: (chunk) => {
|
|
20284
|
+
answerText += chunk;
|
|
20285
|
+
callbacks.onGeneration?.(chunk);
|
|
20286
|
+
},
|
|
20287
|
+
onDone: (data) => {
|
|
20288
|
+
const updatedMessages2 = [
|
|
20289
|
+
...history,
|
|
20290
|
+
{ role: "user", content: userMessage },
|
|
20291
|
+
{ role: "assistant", content: answerText }
|
|
20292
|
+
];
|
|
20293
|
+
callbacks.onAssistantMessage?.(answerText);
|
|
20294
|
+
callbacks.onMessagesUpdated?.(updatedMessages2);
|
|
20295
|
+
callbacks.onDone?.(data);
|
|
20296
|
+
resolveMessages(updatedMessages2);
|
|
20297
|
+
}
|
|
20298
|
+
};
|
|
20299
|
+
const abortController = await this.performRetrievalAgent(
|
|
20300
|
+
request,
|
|
20301
|
+
wrappedCallbacks
|
|
19355
20302
|
);
|
|
20303
|
+
return { abortController, messages: messagesPromise };
|
|
19356
20304
|
}
|
|
20305
|
+
const result = await this.performRetrievalAgent(request);
|
|
20306
|
+
const updatedMessages = result.messages?.length ? result.messages : [
|
|
20307
|
+
...history,
|
|
20308
|
+
{ role: "user", content: userMessage },
|
|
20309
|
+
...result.generation ? [{ role: "assistant", content: result.generation }] : []
|
|
20310
|
+
];
|
|
20311
|
+
return { result, messages: updatedMessages };
|
|
19357
20312
|
}
|
|
19358
20313
|
/**
|
|
19359
|
-
*
|
|
19360
|
-
*
|
|
20314
|
+
* Query Builder Agent - Translates natural language into structured search queries
|
|
20315
|
+
* Uses an LLM to generate optimized Bleve queries from user intent
|
|
20316
|
+
* @param request - Query builder request with intent and optional table/schema context
|
|
20317
|
+
* @returns Promise with QueryBuilderResult containing the generated query, explanation, and confidence
|
|
19361
20318
|
*/
|
|
19362
|
-
async
|
|
19363
|
-
|
|
19364
|
-
|
|
19365
|
-
}
|
|
19366
|
-
|
|
20319
|
+
async queryBuilderAgent(request) {
|
|
20320
|
+
const { data, error: error46 } = await this.client.POST("/agents/query-builder", {
|
|
20321
|
+
body: request
|
|
20322
|
+
});
|
|
20323
|
+
if (error46) throw new Error(`Query builder agent failed: ${error46.error}`);
|
|
20324
|
+
return data;
|
|
20325
|
+
}
|
|
20326
|
+
/**
|
|
20327
|
+
* Standalone evaluation for testing evaluators without running a query.
|
|
20328
|
+
* Evaluates a generated output against ground truth using LLM-as-judge metrics.
|
|
20329
|
+
* @param request - Eval request with evaluators, judge config, query, output, and ground truth
|
|
20330
|
+
* @returns Evaluation result with scores for each evaluator
|
|
20331
|
+
*/
|
|
20332
|
+
async evaluate(request) {
|
|
20333
|
+
const { data, error: error46 } = await this.client.POST("/eval", {
|
|
20334
|
+
body: request
|
|
20335
|
+
});
|
|
20336
|
+
if (error46) throw new Error(`Evaluation failed: ${error46.error}`);
|
|
20337
|
+
return data;
|
|
20338
|
+
}
|
|
20339
|
+
/**
|
|
20340
|
+
* Get the underlying OpenAPI client for advanced use cases
|
|
20341
|
+
*/
|
|
20342
|
+
getRawClient() {
|
|
20343
|
+
return this.client;
|
|
20344
|
+
}
|
|
20345
|
+
};
|
|
20346
|
+
}
|
|
20347
|
+
});
|
|
20348
|
+
|
|
20349
|
+
// ../core/src/vector/antfly-store.ts
|
|
20350
|
+
var MODEL_DIMENSIONS, DEFAULT_MODEL, DEFAULT_BASE_URL, BATCH_SIZE, AntflyVectorStore;
|
|
20351
|
+
var init_antfly_store = __esm({
|
|
20352
|
+
"../core/src/vector/antfly-store.ts"() {
|
|
20353
|
+
"use strict";
|
|
20354
|
+
init_dist2();
|
|
20355
|
+
MODEL_DIMENSIONS = {
|
|
20356
|
+
"BAAI/bge-small-en-v1.5": 384,
|
|
20357
|
+
"mxbai-embed-large-v1": 1024,
|
|
20358
|
+
"nomic-ai/nomic-embed-text-v1.5": 768,
|
|
20359
|
+
"openai/clip-vit-base-patch32": 512
|
|
20360
|
+
};
|
|
20361
|
+
DEFAULT_MODEL = "BAAI/bge-small-en-v1.5";
|
|
20362
|
+
DEFAULT_BASE_URL = process.env.ANTFLY_URL ?? "http://localhost:18080/api/v1";
|
|
20363
|
+
BATCH_SIZE = 500;
|
|
20364
|
+
AntflyVectorStore = class {
|
|
20365
|
+
path;
|
|
20366
|
+
cfg;
|
|
20367
|
+
client;
|
|
20368
|
+
initialized = false;
|
|
20369
|
+
constructor(config2) {
|
|
20370
|
+
this.cfg = {
|
|
20371
|
+
baseUrl: config2.baseUrl ?? DEFAULT_BASE_URL,
|
|
20372
|
+
table: config2.table,
|
|
20373
|
+
indexName: config2.indexName ?? "content",
|
|
20374
|
+
template: config2.template ?? "{{text}}",
|
|
20375
|
+
model: config2.model ?? DEFAULT_MODEL
|
|
20376
|
+
};
|
|
20377
|
+
this.path = `${this.cfg.baseUrl}/${this.cfg.table}`;
|
|
20378
|
+
this.client = new AntflyClient({ baseUrl: this.cfg.baseUrl });
|
|
20379
|
+
}
|
|
20380
|
+
async initialize() {
|
|
20381
|
+
if (this.initialized) return;
|
|
19367
20382
|
try {
|
|
19368
|
-
const
|
|
19369
|
-
|
|
19370
|
-
|
|
19371
|
-
|
|
19372
|
-
|
|
19373
|
-
|
|
19374
|
-
|
|
20383
|
+
const tableNames = await this.listTableNames();
|
|
20384
|
+
if (tableNames.includes(this.cfg.table)) {
|
|
20385
|
+
await this.checkModelMismatch();
|
|
20386
|
+
} else {
|
|
20387
|
+
await this.createTableWithIndex();
|
|
20388
|
+
}
|
|
20389
|
+
this.initialized = true;
|
|
19375
20390
|
} catch (error46) {
|
|
20391
|
+
if (error46 instanceof Error && error46.message.includes("Model mismatch")) throw error46;
|
|
19376
20392
|
throw new Error(
|
|
19377
|
-
`Failed to
|
|
20393
|
+
`Failed to initialize Antfly store (${this.cfg.table}): ${error46 instanceof Error ? error46.message : String(error46)}`
|
|
19378
20394
|
);
|
|
19379
20395
|
}
|
|
19380
20396
|
}
|
|
19381
20397
|
/**
|
|
19382
|
-
*
|
|
19383
|
-
* Uses the document's existing embedding for efficient similarity search
|
|
20398
|
+
* Add documents. Embeddings param is ignored — Antfly auto-embeds via Termite.
|
|
19384
20399
|
*/
|
|
19385
|
-
async
|
|
19386
|
-
if (
|
|
19387
|
-
|
|
20400
|
+
async add(documents, _embeddings) {
|
|
20401
|
+
if (documents.length === 0) return;
|
|
20402
|
+
this.assertReady();
|
|
20403
|
+
for (let i = 0; i < documents.length; i += BATCH_SIZE) {
|
|
20404
|
+
const batch = documents.slice(i, i + BATCH_SIZE);
|
|
20405
|
+
const inserts = {};
|
|
20406
|
+
for (const doc of batch) {
|
|
20407
|
+
inserts[doc.id] = { text: doc.text, metadata: JSON.stringify(doc.metadata) };
|
|
20408
|
+
}
|
|
20409
|
+
try {
|
|
20410
|
+
await this.batchOp({ inserts });
|
|
20411
|
+
} catch (error46) {
|
|
20412
|
+
throw new Error(
|
|
20413
|
+
`Failed to add documents (batch ${Math.floor(i / BATCH_SIZE) + 1}): ${error46 instanceof Error ? error46.message : String(error46)}`
|
|
20414
|
+
);
|
|
20415
|
+
}
|
|
19388
20416
|
}
|
|
20417
|
+
}
|
|
20418
|
+
/**
|
|
20419
|
+
* VectorStore interface method — throws. Use searchText() instead.
|
|
20420
|
+
*/
|
|
20421
|
+
async search(_queryEmbedding, _options) {
|
|
20422
|
+
throw new Error(
|
|
20423
|
+
"AntflyVectorStore.search() does not accept pre-computed embeddings. Use searchText(query, options) instead \u2014 Antfly handles embedding internally."
|
|
20424
|
+
);
|
|
20425
|
+
}
|
|
20426
|
+
/**
|
|
20427
|
+
* Search by text using Antfly's hybrid search (BM25 + vector + RRF).
|
|
20428
|
+
*/
|
|
20429
|
+
async searchText(query, options = {}) {
|
|
20430
|
+
this.assertReady();
|
|
20431
|
+
const { limit = 10, scoreThreshold = 0 } = options;
|
|
19389
20432
|
try {
|
|
19390
|
-
const
|
|
19391
|
-
|
|
19392
|
-
|
|
19393
|
-
|
|
19394
|
-
|
|
19395
|
-
return this.
|
|
20433
|
+
const resp = await this.queryTable({
|
|
20434
|
+
semantic_search: query,
|
|
20435
|
+
indexes: [this.cfg.indexName],
|
|
20436
|
+
limit
|
|
20437
|
+
});
|
|
20438
|
+
return this.extractHits(resp).map((hit) => ({
|
|
20439
|
+
id: hit._id,
|
|
20440
|
+
score: hit._score,
|
|
20441
|
+
metadata: this.parseMetadata(hit._source)
|
|
20442
|
+
})).filter((r) => r.score >= scoreThreshold);
|
|
19396
20443
|
} catch (error46) {
|
|
19397
20444
|
throw new Error(
|
|
19398
|
-
`Failed to search
|
|
20445
|
+
`Failed to search: ${error46 instanceof Error ? error46.message : String(error46)}`
|
|
19399
20446
|
);
|
|
19400
20447
|
}
|
|
19401
20448
|
}
|
|
19402
|
-
/**
|
|
19403
|
-
* Get a document by ID
|
|
19404
|
-
*/
|
|
19405
20449
|
async get(id) {
|
|
19406
|
-
|
|
19407
|
-
return null;
|
|
19408
|
-
}
|
|
20450
|
+
this.assertReady();
|
|
19409
20451
|
try {
|
|
19410
|
-
const
|
|
19411
|
-
|
|
19412
|
-
const result = results.find((r) => r.id === id);
|
|
19413
|
-
if (!result) {
|
|
19414
|
-
return null;
|
|
19415
|
-
}
|
|
20452
|
+
const result = await this.client.tables.lookup(this.cfg.table, id);
|
|
20453
|
+
if (!result) return null;
|
|
19416
20454
|
return {
|
|
19417
|
-
id
|
|
19418
|
-
text: result.text,
|
|
19419
|
-
metadata:
|
|
20455
|
+
id,
|
|
20456
|
+
text: result.text ?? "",
|
|
20457
|
+
metadata: this.parseRawMetadata(result.metadata)
|
|
19420
20458
|
};
|
|
19421
20459
|
} catch (error46) {
|
|
20460
|
+
if (String(error46).includes("404") || String(error46).includes("not found")) return null;
|
|
19422
20461
|
throw new Error(
|
|
19423
20462
|
`Failed to get document: ${error46 instanceof Error ? error46.message : String(error46)}`
|
|
19424
20463
|
);
|
|
19425
20464
|
}
|
|
19426
20465
|
}
|
|
19427
|
-
/**
|
|
19428
|
-
* Delete documents by ID
|
|
19429
|
-
*/
|
|
19430
20466
|
async delete(ids) {
|
|
19431
|
-
|
|
19432
|
-
|
|
19433
|
-
}
|
|
20467
|
+
this.assertReady();
|
|
20468
|
+
if (ids.length === 0) return;
|
|
19434
20469
|
try {
|
|
19435
|
-
|
|
19436
|
-
const predicate = `id IN ('${escapedIds.join("', '")}')`;
|
|
19437
|
-
await this.table.delete(predicate);
|
|
20470
|
+
await this.batchOp({ deletes: ids });
|
|
19438
20471
|
} catch (error46) {
|
|
19439
20472
|
throw new Error(
|
|
19440
20473
|
`Failed to delete documents: ${error46 instanceof Error ? error46.message : String(error46)}`
|
|
19441
20474
|
);
|
|
19442
20475
|
}
|
|
19443
20476
|
}
|
|
19444
|
-
|
|
19445
|
-
|
|
19446
|
-
|
|
19447
|
-
|
|
19448
|
-
|
|
19449
|
-
|
|
20477
|
+
async count() {
|
|
20478
|
+
this.assertReady();
|
|
20479
|
+
try {
|
|
20480
|
+
const resp = await this.queryTable({ limit: 1 });
|
|
20481
|
+
return resp?.hits?.total ?? 0;
|
|
20482
|
+
} catch {
|
|
20483
|
+
return 0;
|
|
19450
20484
|
}
|
|
20485
|
+
}
|
|
20486
|
+
async getAll(options = {}) {
|
|
20487
|
+
this.assertReady();
|
|
20488
|
+
const { limit = 1e4 } = options;
|
|
19451
20489
|
try {
|
|
19452
|
-
|
|
19453
|
-
|
|
19454
|
-
|
|
19455
|
-
|
|
20490
|
+
const resp = await this.queryTable({ limit });
|
|
20491
|
+
return this.extractHits(resp).map((hit) => ({
|
|
20492
|
+
id: hit._id,
|
|
20493
|
+
score: 1,
|
|
20494
|
+
metadata: this.parseMetadata(hit._source)
|
|
20495
|
+
}));
|
|
19456
20496
|
} catch (error46) {
|
|
19457
20497
|
throw new Error(
|
|
19458
|
-
`Failed to
|
|
20498
|
+
`Failed to get all documents: ${error46 instanceof Error ? error46.message : String(error46)}`
|
|
19459
20499
|
);
|
|
19460
20500
|
}
|
|
19461
20501
|
}
|
|
19462
|
-
|
|
19463
|
-
|
|
19464
|
-
|
|
19465
|
-
|
|
19466
|
-
|
|
19467
|
-
|
|
19468
|
-
|
|
20502
|
+
async searchByDocumentId(documentId, options = {}) {
|
|
20503
|
+
this.assertReady();
|
|
20504
|
+
const doc = await this.get(documentId);
|
|
20505
|
+
if (!doc) return [];
|
|
20506
|
+
return this.searchText(doc.text, options);
|
|
20507
|
+
}
|
|
20508
|
+
async clear() {
|
|
20509
|
+
this.assertReady();
|
|
19469
20510
|
try {
|
|
19470
|
-
|
|
20511
|
+
await this.client.tables.drop(this.cfg.table);
|
|
20512
|
+
await this.createTableWithIndex();
|
|
19471
20513
|
} catch (error46) {
|
|
19472
20514
|
throw new Error(
|
|
19473
|
-
`Failed to
|
|
20515
|
+
`Failed to clear store: ${error46 instanceof Error ? error46.message : String(error46)}`
|
|
19474
20516
|
);
|
|
19475
20517
|
}
|
|
19476
20518
|
}
|
|
19477
|
-
/**
|
|
19478
|
-
* Optimize the vector store (compact fragments, update indices)
|
|
19479
|
-
*/
|
|
19480
20519
|
async optimize() {
|
|
19481
|
-
|
|
19482
|
-
|
|
19483
|
-
|
|
20520
|
+
}
|
|
20521
|
+
async close() {
|
|
20522
|
+
this.initialized = false;
|
|
20523
|
+
}
|
|
20524
|
+
getModelInfo() {
|
|
20525
|
+
return {
|
|
20526
|
+
dimension: MODEL_DIMENSIONS[this.cfg.model] ?? 384,
|
|
20527
|
+
modelName: this.cfg.model
|
|
20528
|
+
};
|
|
20529
|
+
}
|
|
20530
|
+
async getStorageSize() {
|
|
19484
20531
|
try {
|
|
19485
|
-
await this.
|
|
19486
|
-
|
|
19487
|
-
|
|
19488
|
-
|
|
19489
|
-
);
|
|
20532
|
+
const info = await this.getTableInfo();
|
|
20533
|
+
return info?.storage_status?.disk_usage ?? 0;
|
|
20534
|
+
} catch {
|
|
20535
|
+
return 0;
|
|
19490
20536
|
}
|
|
19491
20537
|
}
|
|
19492
|
-
|
|
19493
|
-
|
|
19494
|
-
|
|
19495
|
-
|
|
19496
|
-
|
|
19497
|
-
|
|
20538
|
+
// ── SDK boundary layer ──
|
|
20539
|
+
// These methods isolate the SDK's loosely-typed API behind our own types.
|
|
20540
|
+
async listTableNames() {
|
|
20541
|
+
const raw = await this.client.tables.list();
|
|
20542
|
+
const tables = raw;
|
|
20543
|
+
if (!Array.isArray(tables)) return [];
|
|
20544
|
+
return tables.map((t) => typeof t === "string" ? t : t.name);
|
|
20545
|
+
}
|
|
20546
|
+
async createTableWithIndex() {
|
|
20547
|
+
const body = {
|
|
20548
|
+
indexes: {
|
|
20549
|
+
[this.cfg.indexName]: {
|
|
20550
|
+
type: "embeddings",
|
|
20551
|
+
template: this.cfg.template,
|
|
20552
|
+
embedder: { provider: "termite", model: this.cfg.model }
|
|
20553
|
+
}
|
|
20554
|
+
}
|
|
20555
|
+
};
|
|
20556
|
+
await this.client.tables.create(this.cfg.table, body);
|
|
20557
|
+
}
|
|
20558
|
+
async getTableInfo() {
|
|
20559
|
+
const raw = await this.client.tables.get(this.cfg.table);
|
|
20560
|
+
return raw ?? null;
|
|
20561
|
+
}
|
|
20562
|
+
async queryTable(params) {
|
|
20563
|
+
const raw = await this.client.query({
|
|
20564
|
+
table: this.cfg.table,
|
|
20565
|
+
...params
|
|
20566
|
+
});
|
|
20567
|
+
return raw;
|
|
20568
|
+
}
|
|
20569
|
+
async batchOp(body) {
|
|
20570
|
+
await this.client.tables.batch(this.cfg.table, body);
|
|
20571
|
+
}
|
|
20572
|
+
// ── Helpers ──
|
|
20573
|
+
assertReady() {
|
|
20574
|
+
if (!this.initialized) {
|
|
20575
|
+
throw new Error("Store not initialized. Call initialize() first.");
|
|
19498
20576
|
}
|
|
20577
|
+
}
|
|
20578
|
+
async checkModelMismatch() {
|
|
19499
20579
|
try {
|
|
19500
|
-
await this.
|
|
20580
|
+
const info = await this.getTableInfo();
|
|
20581
|
+
const embeddingIndex = info?.indexes?.[this.cfg.indexName];
|
|
20582
|
+
if (embeddingIndex?.embedder?.model && embeddingIndex.embedder.model !== this.cfg.model) {
|
|
20583
|
+
throw new Error(
|
|
20584
|
+
`Model mismatch: table "${this.cfg.table}" uses "${embeddingIndex.embedder.model}" but config specifies "${this.cfg.model}". Run \`dev index . --force\` to re-index with the new model.`
|
|
20585
|
+
);
|
|
20586
|
+
}
|
|
19501
20587
|
} catch (error46) {
|
|
19502
|
-
|
|
19503
|
-
`Could not create index on 'id' column: ${error46 instanceof Error ? error46.message : String(error46)}`
|
|
19504
|
-
);
|
|
20588
|
+
if (error46 instanceof Error && error46.message.includes("Model mismatch")) throw error46;
|
|
19505
20589
|
}
|
|
19506
20590
|
}
|
|
19507
|
-
|
|
19508
|
-
|
|
19509
|
-
|
|
19510
|
-
|
|
19511
|
-
|
|
19512
|
-
|
|
20591
|
+
extractHits(resp) {
|
|
20592
|
+
return resp?.hits?.hits ?? [];
|
|
20593
|
+
}
|
|
20594
|
+
parseMetadata(source) {
|
|
20595
|
+
if (!source) return {};
|
|
20596
|
+
const metadataField = source.metadata;
|
|
20597
|
+
if (typeof metadataField === "string") {
|
|
20598
|
+
try {
|
|
20599
|
+
return JSON.parse(metadataField);
|
|
20600
|
+
} catch {
|
|
20601
|
+
return {};
|
|
20602
|
+
}
|
|
20603
|
+
}
|
|
20604
|
+
if (metadataField && typeof metadataField === "object") {
|
|
20605
|
+
return metadataField;
|
|
20606
|
+
}
|
|
20607
|
+
const { text: _, metadata: __, _timestamp: ___, ...rest } = source;
|
|
20608
|
+
return rest;
|
|
20609
|
+
}
|
|
20610
|
+
parseRawMetadata(metadata) {
|
|
20611
|
+
if (typeof metadata === "string") {
|
|
20612
|
+
try {
|
|
20613
|
+
return JSON.parse(metadata);
|
|
20614
|
+
} catch {
|
|
20615
|
+
return {};
|
|
20616
|
+
}
|
|
20617
|
+
}
|
|
20618
|
+
if (metadata && typeof metadata === "object") {
|
|
20619
|
+
return metadata;
|
|
20620
|
+
}
|
|
20621
|
+
return {};
|
|
19513
20622
|
}
|
|
19514
20623
|
};
|
|
19515
20624
|
}
|
|
@@ -19525,160 +20634,117 @@ var init_types2 = __esm({
|
|
|
19525
20634
|
// ../core/src/vector/index.ts
|
|
19526
20635
|
var vector_exports = {};
|
|
19527
20636
|
__export(vector_exports, {
|
|
19528
|
-
|
|
19529
|
-
TransformersEmbedder: () => TransformersEmbedder,
|
|
20637
|
+
AntflyVectorStore: () => AntflyVectorStore,
|
|
19530
20638
|
VectorStorage: () => VectorStorage
|
|
19531
20639
|
});
|
|
19532
|
-
|
|
20640
|
+
function deriveTableName(storePath) {
|
|
20641
|
+
const parts = storePath.replace(/\/$/, "").split("/");
|
|
20642
|
+
const last = parts.at(-1) ?? "code";
|
|
20643
|
+
const projectDir = parts.at(-2) ?? "default";
|
|
20644
|
+
const project = projectDir.replace(/[^a-zA-Z0-9-]/g, "-").toLowerCase();
|
|
20645
|
+
if (last === "vectors") return `dev-agent-${project}-code`;
|
|
20646
|
+
if (last === "vectors-git") return `dev-agent-${project}-git`;
|
|
20647
|
+
if (last === "vectors-github") return `dev-agent-${project}-github`;
|
|
20648
|
+
return `dev-agent-${project}-${last.replace(/[^a-zA-Z0-9-]/g, "-")}`;
|
|
20649
|
+
}
|
|
20650
|
+
var VectorStorage;
|
|
19533
20651
|
var init_vector = __esm({
|
|
19534
20652
|
"../core/src/vector/index.ts"() {
|
|
19535
20653
|
"use strict";
|
|
19536
|
-
|
|
19537
|
-
init_store();
|
|
20654
|
+
init_antfly_store();
|
|
19538
20655
|
init_types2();
|
|
19539
|
-
|
|
19540
|
-
init_embedder();
|
|
19541
|
-
init_store();
|
|
20656
|
+
init_antfly_store();
|
|
19542
20657
|
VectorStorage = class {
|
|
19543
|
-
embedder;
|
|
19544
20658
|
store;
|
|
19545
20659
|
initialized = false;
|
|
19546
20660
|
constructor(config2) {
|
|
19547
|
-
const
|
|
19548
|
-
|
|
19549
|
-
|
|
20661
|
+
const antflyConfig = {
|
|
20662
|
+
table: deriveTableName(config2.storePath),
|
|
20663
|
+
model: config2.embeddingModel
|
|
20664
|
+
};
|
|
20665
|
+
this.store = new AntflyVectorStore(antflyConfig);
|
|
19550
20666
|
}
|
|
19551
20667
|
/**
|
|
19552
|
-
* Initialize
|
|
19553
|
-
*
|
|
19554
|
-
*
|
|
20668
|
+
* Initialize the storage.
|
|
20669
|
+
*
|
|
20670
|
+
* The skipEmbedder option is accepted for backward compatibility but
|
|
20671
|
+
* has no effect — Antfly handles embeddings internally.
|
|
19555
20672
|
*/
|
|
19556
|
-
async initialize(
|
|
19557
|
-
if (this.initialized)
|
|
19558
|
-
|
|
19559
|
-
}
|
|
19560
|
-
const { skipEmbedder = false } = options || {};
|
|
19561
|
-
if (skipEmbedder) {
|
|
19562
|
-
await this.store.initialize();
|
|
19563
|
-
} else {
|
|
19564
|
-
await Promise.all([this.embedder.initialize(), this.store.initialize()]);
|
|
19565
|
-
}
|
|
20673
|
+
async initialize(_options) {
|
|
20674
|
+
if (this.initialized) return;
|
|
20675
|
+
await this.store.initialize();
|
|
19566
20676
|
this.initialized = true;
|
|
19567
20677
|
}
|
|
19568
20678
|
/**
|
|
19569
|
-
*
|
|
19570
|
-
*/
|
|
19571
|
-
async ensureEmbedder() {
|
|
19572
|
-
if (!this.embedder) {
|
|
19573
|
-
throw new Error("Embedder not available");
|
|
19574
|
-
}
|
|
19575
|
-
await this.embedder.initialize();
|
|
19576
|
-
}
|
|
19577
|
-
/**
|
|
19578
|
-
* Add documents to the store (automatically generates embeddings)
|
|
20679
|
+
* Add documents (Antfly generates embeddings automatically via Termite)
|
|
19579
20680
|
*/
|
|
19580
20681
|
async addDocuments(documents) {
|
|
19581
|
-
|
|
19582
|
-
|
|
19583
|
-
|
|
19584
|
-
if (documents.length === 0) {
|
|
19585
|
-
return;
|
|
19586
|
-
}
|
|
19587
|
-
const texts = documents.map((doc) => doc.text);
|
|
19588
|
-
const embeddings = await this.embedder.embedBatch(texts);
|
|
19589
|
-
await this.store.add(documents, embeddings);
|
|
20682
|
+
this.assertReady();
|
|
20683
|
+
if (documents.length === 0) return;
|
|
20684
|
+
await this.store.add(documents);
|
|
19590
20685
|
}
|
|
19591
20686
|
/**
|
|
19592
|
-
* Search
|
|
20687
|
+
* Search using hybrid search (BM25 + vector + RRF)
|
|
19593
20688
|
*/
|
|
19594
20689
|
async search(query, options) {
|
|
19595
|
-
|
|
19596
|
-
|
|
19597
|
-
}
|
|
19598
|
-
await this.ensureEmbedder();
|
|
19599
|
-
const queryEmbedding = await this.embedder.embed(query);
|
|
19600
|
-
return this.store.search(queryEmbedding, options);
|
|
20690
|
+
this.assertReady();
|
|
20691
|
+
return this.store.searchText(query, options);
|
|
19601
20692
|
}
|
|
19602
20693
|
/**
|
|
19603
|
-
* Find similar
|
|
19604
|
-
* More efficient than search() as it reuses the document's existing embedding
|
|
20694
|
+
* Find documents similar to a given document by ID
|
|
19605
20695
|
*/
|
|
19606
20696
|
async searchByDocumentId(documentId, options) {
|
|
19607
|
-
|
|
19608
|
-
throw new Error("VectorStorage not initialized. Call initialize() first.");
|
|
19609
|
-
}
|
|
20697
|
+
this.assertReady();
|
|
19610
20698
|
return this.store.searchByDocumentId(documentId, options);
|
|
19611
20699
|
}
|
|
19612
20700
|
/**
|
|
19613
|
-
* Get all documents without semantic search (
|
|
19614
|
-
* Use this when you need all documents and don't need relevance ranking
|
|
19615
|
-
* This is 10-20x faster than search() as it skips embedding generation
|
|
20701
|
+
* Get all documents without semantic search (full scan)
|
|
19616
20702
|
*/
|
|
19617
20703
|
async getAll(options) {
|
|
19618
|
-
|
|
19619
|
-
throw new Error("VectorStorage not initialized. Call initialize() first.");
|
|
19620
|
-
}
|
|
20704
|
+
this.assertReady();
|
|
19621
20705
|
return this.store.getAll(options);
|
|
19622
20706
|
}
|
|
19623
20707
|
/**
|
|
19624
20708
|
* Get a document by ID
|
|
19625
20709
|
*/
|
|
19626
20710
|
async getDocument(id) {
|
|
19627
|
-
|
|
19628
|
-
throw new Error("VectorStorage not initialized. Call initialize() first.");
|
|
19629
|
-
}
|
|
20711
|
+
this.assertReady();
|
|
19630
20712
|
return this.store.get(id);
|
|
19631
20713
|
}
|
|
19632
20714
|
/**
|
|
19633
20715
|
* Delete documents by ID
|
|
19634
20716
|
*/
|
|
19635
20717
|
async deleteDocuments(ids) {
|
|
19636
|
-
|
|
19637
|
-
throw new Error("VectorStorage not initialized. Call initialize() first.");
|
|
19638
|
-
}
|
|
20718
|
+
this.assertReady();
|
|
19639
20719
|
await this.store.delete(ids);
|
|
19640
20720
|
}
|
|
19641
20721
|
/**
|
|
19642
|
-
* Clear all documents
|
|
19643
|
-
* Used for force re-indexing
|
|
20722
|
+
* Clear all documents (destructive — used for force re-indexing)
|
|
19644
20723
|
*/
|
|
19645
20724
|
async clear() {
|
|
19646
|
-
|
|
19647
|
-
throw new Error("VectorStorage not initialized. Call initialize() first.");
|
|
19648
|
-
}
|
|
20725
|
+
this.assertReady();
|
|
19649
20726
|
await this.store.clear();
|
|
19650
20727
|
}
|
|
19651
20728
|
/**
|
|
19652
20729
|
* Get statistics about the vector store
|
|
19653
20730
|
*/
|
|
19654
20731
|
async getStats() {
|
|
19655
|
-
|
|
19656
|
-
|
|
19657
|
-
}
|
|
20732
|
+
this.assertReady();
|
|
20733
|
+
const modelInfo = this.store.getModelInfo();
|
|
19658
20734
|
const totalDocuments = await this.store.count();
|
|
19659
|
-
|
|
19660
|
-
try {
|
|
19661
|
-
const storePath = this.store.path;
|
|
19662
|
-
const stats = await fs6.stat(storePath);
|
|
19663
|
-
storageSize = stats.size;
|
|
19664
|
-
} catch {
|
|
19665
|
-
storageSize = 0;
|
|
19666
|
-
}
|
|
20735
|
+
const storageSize = await this.store.getStorageSize();
|
|
19667
20736
|
return {
|
|
19668
20737
|
totalDocuments,
|
|
19669
20738
|
storageSize,
|
|
19670
|
-
dimension:
|
|
19671
|
-
modelName:
|
|
20739
|
+
dimension: modelInfo.dimension,
|
|
20740
|
+
modelName: modelInfo.modelName
|
|
19672
20741
|
};
|
|
19673
20742
|
}
|
|
19674
20743
|
/**
|
|
19675
|
-
* Optimize the
|
|
19676
|
-
* Call this after bulk indexing operations for better performance
|
|
20744
|
+
* Optimize the store (no-op for Antfly — manages compaction internally)
|
|
19677
20745
|
*/
|
|
19678
20746
|
async optimize() {
|
|
19679
|
-
|
|
19680
|
-
throw new Error("VectorStorage not initialized. Call initialize() first.");
|
|
19681
|
-
}
|
|
20747
|
+
this.assertReady();
|
|
19682
20748
|
await this.store.optimize();
|
|
19683
20749
|
}
|
|
19684
20750
|
/**
|
|
@@ -19688,6 +20754,11 @@ var init_vector = __esm({
|
|
|
19688
20754
|
await this.store.close();
|
|
19689
20755
|
this.initialized = false;
|
|
19690
20756
|
}
|
|
20757
|
+
assertReady() {
|
|
20758
|
+
if (!this.initialized) {
|
|
20759
|
+
throw new Error("VectorStorage not initialized. Call initialize() first.");
|
|
20760
|
+
}
|
|
20761
|
+
}
|
|
19691
20762
|
};
|
|
19692
20763
|
}
|
|
19693
20764
|
});
|
|
@@ -33755,12 +34826,12 @@ var indexer_exports = {};
|
|
|
33755
34826
|
__export(indexer_exports, {
|
|
33756
34827
|
RepositoryIndexer: () => RepositoryIndexer
|
|
33757
34828
|
});
|
|
33758
|
-
var crypto,
|
|
34829
|
+
var crypto, fs6, path9, INDEXER_VERSION, DEFAULT_STATE_PATH, RepositoryIndexer;
|
|
33759
34830
|
var init_indexer2 = __esm({
|
|
33760
34831
|
"../core/src/indexer/index.ts"() {
|
|
33761
34832
|
"use strict";
|
|
33762
34833
|
crypto = __toESM(require("crypto"));
|
|
33763
|
-
|
|
34834
|
+
fs6 = __toESM(require("fs/promises"));
|
|
33764
34835
|
path9 = __toESM(require("path"));
|
|
33765
34836
|
init_collector();
|
|
33766
34837
|
init_scanner();
|
|
@@ -34379,7 +35450,7 @@ var init_indexer2 = __esm({
|
|
|
34379
35450
|
*/
|
|
34380
35451
|
async loadState() {
|
|
34381
35452
|
try {
|
|
34382
|
-
const stateContent = await
|
|
35453
|
+
const stateContent = await fs6.readFile(this.config.statePath, "utf-8");
|
|
34383
35454
|
const data = JSON.parse(stateContent);
|
|
34384
35455
|
const validation = validateIndexerState(data);
|
|
34385
35456
|
if (!validation.success) {
|
|
@@ -34408,8 +35479,8 @@ var init_indexer2 = __esm({
|
|
|
34408
35479
|
if (!validation.success) {
|
|
34409
35480
|
console.warn(`Indexer state validation warning: ${validation.error}`);
|
|
34410
35481
|
}
|
|
34411
|
-
await
|
|
34412
|
-
await
|
|
35482
|
+
await fs6.mkdir(path9.dirname(this.config.statePath), { recursive: true });
|
|
35483
|
+
await fs6.writeFile(this.config.statePath, JSON.stringify(this.state, null, 2), "utf-8");
|
|
34413
35484
|
}
|
|
34414
35485
|
/**
|
|
34415
35486
|
* Update state with newly indexed documents
|
|
@@ -34439,11 +35510,11 @@ var init_indexer2 = __esm({
|
|
|
34439
35510
|
}
|
|
34440
35511
|
for (const [filePath, docs] of fileMap) {
|
|
34441
35512
|
const fullPath = path9.join(this.config.repositoryPath, filePath);
|
|
34442
|
-
let
|
|
35513
|
+
let stat3;
|
|
34443
35514
|
let hash2 = "";
|
|
34444
35515
|
try {
|
|
34445
|
-
|
|
34446
|
-
const content3 = await
|
|
35516
|
+
stat3 = await fs6.stat(fullPath);
|
|
35517
|
+
const content3 = await fs6.readFile(fullPath, "utf-8");
|
|
34447
35518
|
hash2 = crypto.createHash("sha256").update(content3).digest("hex");
|
|
34448
35519
|
} catch {
|
|
34449
35520
|
continue;
|
|
@@ -34451,10 +35522,10 @@ var init_indexer2 = __esm({
|
|
|
34451
35522
|
const metadata = {
|
|
34452
35523
|
path: filePath,
|
|
34453
35524
|
hash: hash2,
|
|
34454
|
-
lastModified:
|
|
35525
|
+
lastModified: stat3.mtime,
|
|
34455
35526
|
lastIndexed: /* @__PURE__ */ new Date(),
|
|
34456
35527
|
documentIds: docs.map((d) => d.id),
|
|
34457
|
-
size:
|
|
35528
|
+
size: stat3.size,
|
|
34458
35529
|
language: docs[0]?.language || "unknown"
|
|
34459
35530
|
};
|
|
34460
35531
|
this.state.files[filePath] = metadata;
|
|
@@ -34489,11 +35560,11 @@ var init_indexer2 = __esm({
|
|
|
34489
35560
|
for (const [filePath, metadata] of Object.entries(this.state.files)) {
|
|
34490
35561
|
const fullPath = path9.join(this.config.repositoryPath, filePath);
|
|
34491
35562
|
try {
|
|
34492
|
-
const
|
|
34493
|
-
if (since &&
|
|
35563
|
+
const stat3 = await fs6.stat(fullPath);
|
|
35564
|
+
if (since && stat3.mtime <= since) {
|
|
34494
35565
|
continue;
|
|
34495
35566
|
}
|
|
34496
|
-
const content3 = await
|
|
35567
|
+
const content3 = await fs6.readFile(fullPath, "utf-8");
|
|
34497
35568
|
const currentHash = crypto.createHash("sha256").update(content3).digest("hex");
|
|
34498
35569
|
if (currentHash !== metadata.hash) {
|
|
34499
35570
|
changed.push(filePath);
|
|
@@ -35169,7 +36240,7 @@ __export(store_exports, {
|
|
|
35169
36240
|
MetricsStore: () => MetricsStore
|
|
35170
36241
|
});
|
|
35171
36242
|
var crypto2, import_better_sqlite3, MetricsStore;
|
|
35172
|
-
var
|
|
36243
|
+
var init_store = __esm({
|
|
35173
36244
|
"../core/src/metrics/store.ts"() {
|
|
35174
36245
|
"use strict";
|
|
35175
36246
|
crypto2 = __toESM(require("crypto"));
|
|
@@ -35494,7 +36565,7 @@ var init_metrics = __esm({
|
|
|
35494
36565
|
init_analytics();
|
|
35495
36566
|
init_collector();
|
|
35496
36567
|
init_schema();
|
|
35497
|
-
|
|
36568
|
+
init_store();
|
|
35498
36569
|
init_types5();
|
|
35499
36570
|
}
|
|
35500
36571
|
});
|
|
@@ -38142,11 +39213,11 @@ var init_utils3 = __esm({
|
|
|
38142
39213
|
});
|
|
38143
39214
|
|
|
38144
39215
|
// ../subagents/src/github/indexer.ts
|
|
38145
|
-
var
|
|
39216
|
+
var fs7, path11, INDEXER_VERSION2, DEFAULT_STATE_PATH2, DEFAULT_STALE_THRESHOLD, GitHubIndexer;
|
|
38146
39217
|
var init_indexer4 = __esm({
|
|
38147
39218
|
"../subagents/src/github/indexer.ts"() {
|
|
38148
39219
|
"use strict";
|
|
38149
|
-
|
|
39220
|
+
fs7 = __toESM(require("fs/promises"));
|
|
38150
39221
|
path11 = __toESM(require("path"));
|
|
38151
39222
|
init_src3();
|
|
38152
39223
|
init_utils3();
|
|
@@ -38454,7 +39525,7 @@ ${doc.body}`,
|
|
|
38454
39525
|
*/
|
|
38455
39526
|
async loadState() {
|
|
38456
39527
|
try {
|
|
38457
|
-
const stateContent = await
|
|
39528
|
+
const stateContent = await fs7.readFile(this.statePath, "utf-8");
|
|
38458
39529
|
this.state = JSON.parse(stateContent);
|
|
38459
39530
|
if (this.state?.version !== INDEXER_VERSION2) {
|
|
38460
39531
|
console.warn(`State version mismatch: ${this.state?.version} !== ${INDEXER_VERSION2}`);
|
|
@@ -38471,8 +39542,8 @@ ${doc.body}`,
|
|
|
38471
39542
|
if (!this.state) {
|
|
38472
39543
|
return;
|
|
38473
39544
|
}
|
|
38474
|
-
await
|
|
38475
|
-
await
|
|
39545
|
+
await fs7.mkdir(path11.dirname(this.statePath), { recursive: true });
|
|
39546
|
+
await fs7.writeFile(this.statePath, JSON.stringify(this.state, null, 2), "utf-8");
|
|
38476
39547
|
}
|
|
38477
39548
|
};
|
|
38478
39549
|
}
|
|
@@ -39853,7 +40924,7 @@ async function getStoragePath(repositoryPath2) {
|
|
|
39853
40924
|
return path12.join(baseStorageDir, pathHash);
|
|
39854
40925
|
}
|
|
39855
40926
|
async function ensureStorageDirectory(storagePath) {
|
|
39856
|
-
await
|
|
40927
|
+
await fs8.mkdir(storagePath, { recursive: true });
|
|
39857
40928
|
}
|
|
39858
40929
|
function getStorageFilePaths(storagePath) {
|
|
39859
40930
|
return {
|
|
@@ -39864,13 +40935,13 @@ function getStorageFilePaths(storagePath) {
|
|
|
39864
40935
|
metrics: path12.join(storagePath, "metrics.db")
|
|
39865
40936
|
};
|
|
39866
40937
|
}
|
|
39867
|
-
var import_node_child_process6, crypto3,
|
|
40938
|
+
var import_node_child_process6, crypto3, fs8, os, path12;
|
|
39868
40939
|
var init_path = __esm({
|
|
39869
40940
|
"../core/src/storage/path.ts"() {
|
|
39870
40941
|
"use strict";
|
|
39871
40942
|
import_node_child_process6 = require("child_process");
|
|
39872
40943
|
crypto3 = __toESM(require("crypto"));
|
|
39873
|
-
|
|
40944
|
+
fs8 = __toESM(require("fs/promises"));
|
|
39874
40945
|
os = __toESM(require("os"));
|
|
39875
40946
|
path12 = __toESM(require("path"));
|
|
39876
40947
|
}
|
|
@@ -40145,7 +41216,7 @@ var init_health_service = __esm({
|
|
|
40145
41216
|
});
|
|
40146
41217
|
}
|
|
40147
41218
|
defaultMetricsStoreFactory(path16, logger) {
|
|
40148
|
-
const { MetricsStore: Store } = (
|
|
41219
|
+
const { MetricsStore: Store } = (init_store(), __toCommonJS(store_exports));
|
|
40149
41220
|
return new Store(path16, logger);
|
|
40150
41221
|
}
|
|
40151
41222
|
/**
|
|
@@ -40269,7 +41340,7 @@ var init_metrics_service = __esm({
|
|
|
40269
41340
|
* Default factory that creates a real MetricsStore
|
|
40270
41341
|
*/
|
|
40271
41342
|
defaultStoreFactory(path16, logger) {
|
|
40272
|
-
const { MetricsStore: Store } = (
|
|
41343
|
+
const { MetricsStore: Store } = (init_store(), __toCommonJS(store_exports));
|
|
40273
41344
|
return new Store(path16, logger);
|
|
40274
41345
|
}
|
|
40275
41346
|
/**
|
|
@@ -40397,28 +41468,28 @@ async function findTestFile(sourcePath, repositoryPath2) {
|
|
|
40397
41468
|
for (const testPath of patterns) {
|
|
40398
41469
|
const fullPath = path13.join(repositoryPath2, testPath);
|
|
40399
41470
|
try {
|
|
40400
|
-
await
|
|
41471
|
+
await fs9.access(fullPath);
|
|
40401
41472
|
return testPath;
|
|
40402
41473
|
} catch {
|
|
40403
41474
|
}
|
|
40404
41475
|
}
|
|
40405
41476
|
return null;
|
|
40406
41477
|
}
|
|
40407
|
-
var
|
|
41478
|
+
var fs9, path13;
|
|
40408
41479
|
var init_test_utils = __esm({
|
|
40409
41480
|
"../core/src/utils/test-utils.ts"() {
|
|
40410
41481
|
"use strict";
|
|
40411
|
-
|
|
41482
|
+
fs9 = __toESM(require("fs/promises"));
|
|
40412
41483
|
path13 = __toESM(require("path"));
|
|
40413
41484
|
}
|
|
40414
41485
|
});
|
|
40415
41486
|
|
|
40416
41487
|
// ../core/src/services/pattern-analysis-service.ts
|
|
40417
|
-
var
|
|
41488
|
+
var fs10, path14, PatternAnalysisService;
|
|
40418
41489
|
var init_pattern_analysis_service = __esm({
|
|
40419
41490
|
"../core/src/services/pattern-analysis-service.ts"() {
|
|
40420
41491
|
"use strict";
|
|
40421
|
-
|
|
41492
|
+
fs10 = __toESM(require("fs/promises"));
|
|
40422
41493
|
path14 = __toESM(require("path"));
|
|
40423
41494
|
init_scanner();
|
|
40424
41495
|
init_test_utils();
|
|
@@ -40505,12 +41576,12 @@ var init_pattern_analysis_service = __esm({
|
|
|
40505
41576
|
*/
|
|
40506
41577
|
async analyzeFileWithDocs(filePath, documents) {
|
|
40507
41578
|
const fullPath = path14.join(this.config.repositoryPath, filePath);
|
|
40508
|
-
const [
|
|
41579
|
+
const [stat3, content3] = await Promise.all([fs10.stat(fullPath), fs10.readFile(fullPath, "utf-8")]);
|
|
40509
41580
|
const lines = content3.split("\n").length;
|
|
40510
41581
|
return {
|
|
40511
41582
|
fileSize: {
|
|
40512
41583
|
lines,
|
|
40513
|
-
bytes:
|
|
41584
|
+
bytes: stat3.size
|
|
40514
41585
|
},
|
|
40515
41586
|
testing: await this.analyzeTesting(filePath),
|
|
40516
41587
|
importStyle: await this.analyzeImportsFromFile(filePath, documents),
|
|
@@ -40543,7 +41614,7 @@ var init_pattern_analysis_service = __esm({
|
|
|
40543
41614
|
*/
|
|
40544
41615
|
async analyzeImportsFromFile(filePath, _documents) {
|
|
40545
41616
|
const fullPath = path14.join(this.config.repositoryPath, filePath);
|
|
40546
|
-
const content3 = await
|
|
41617
|
+
const content3 = await fs10.readFile(fullPath, "utf-8");
|
|
40547
41618
|
return this.analyzeImportsFromContent(content3);
|
|
40548
41619
|
}
|
|
40549
41620
|
/**
|
|
@@ -41101,7 +42172,7 @@ function getLastCommit(repositoryPath2) {
|
|
|
41101
42172
|
async function loadMetadata(storagePath) {
|
|
41102
42173
|
const metadataPath = path15.join(storagePath, "metadata.json");
|
|
41103
42174
|
try {
|
|
41104
|
-
const content3 = await
|
|
42175
|
+
const content3 = await fs11.readFile(metadataPath, "utf-8");
|
|
41105
42176
|
const data = JSON.parse(content3);
|
|
41106
42177
|
const validated = validateRepositoryMetadata(data);
|
|
41107
42178
|
return validated;
|
|
@@ -41128,8 +42199,8 @@ async function saveMetadata(storagePath, repositoryPath2, updates) {
|
|
|
41128
42199
|
...updates?.repository
|
|
41129
42200
|
}
|
|
41130
42201
|
};
|
|
41131
|
-
await
|
|
41132
|
-
await
|
|
42202
|
+
await fs11.mkdir(storagePath, { recursive: true });
|
|
42203
|
+
await fs11.writeFile(metadataPath, JSON.stringify(metadata, null, 2), "utf-8");
|
|
41133
42204
|
return metadata;
|
|
41134
42205
|
}
|
|
41135
42206
|
async function updateIndexedStats(storagePath, stats) {
|
|
@@ -41141,12 +42212,12 @@ async function updateIndexedStats(storagePath, stats) {
|
|
|
41141
42212
|
}
|
|
41142
42213
|
});
|
|
41143
42214
|
}
|
|
41144
|
-
var import_node_child_process7,
|
|
42215
|
+
var import_node_child_process7, fs11, path15, METADATA_VERSION;
|
|
41145
42216
|
var init_metadata2 = __esm({
|
|
41146
42217
|
"../core/src/storage/metadata.ts"() {
|
|
41147
42218
|
"use strict";
|
|
41148
42219
|
import_node_child_process7 = require("child_process");
|
|
41149
|
-
|
|
42220
|
+
fs11 = __toESM(require("fs/promises"));
|
|
41150
42221
|
path15 = __toESM(require("path"));
|
|
41151
42222
|
init_path();
|
|
41152
42223
|
init_validation2();
|
|
@@ -41290,6 +42361,7 @@ var init_utils5 = __esm({
|
|
|
41290
42361
|
// ../core/src/index.ts
|
|
41291
42362
|
var src_exports3 = {};
|
|
41292
42363
|
__export(src_exports3, {
|
|
42364
|
+
AntflyVectorStore: () => AntflyVectorStore,
|
|
41293
42365
|
ApiServer: () => ApiServer,
|
|
41294
42366
|
AsyncEventBus: () => AsyncEventBus,
|
|
41295
42367
|
CodeMetadataSchema: () => CodeMetadataSchema,
|
|
@@ -41304,7 +42376,6 @@ __export(src_exports3, {
|
|
|
41304
42376
|
GoScanner: () => GoScanner,
|
|
41305
42377
|
HealthService: () => HealthService,
|
|
41306
42378
|
HotspotSchema: () => HotspotSchema,
|
|
41307
|
-
LanceDBVectorStore: () => LanceDBVectorStore,
|
|
41308
42379
|
LocalGitExtractor: () => LocalGitExtractor,
|
|
41309
42380
|
METRICS_SCHEMA_V1: () => METRICS_SCHEMA_V1,
|
|
41310
42381
|
MarkdownScanner: () => MarkdownScanner,
|
|
@@ -41323,7 +42394,6 @@ __export(src_exports3, {
|
|
|
41323
42394
|
SnapshotQuerySchema: () => SnapshotQuerySchema,
|
|
41324
42395
|
StatsAggregator: () => StatsAggregator,
|
|
41325
42396
|
StatsService: () => StatsService,
|
|
41326
|
-
TransformersEmbedder: () => TransformersEmbedder,
|
|
41327
42397
|
TypeScriptScanner: () => TypeScriptScanner,
|
|
41328
42398
|
VectorStorage: () => VectorStorage,
|
|
41329
42399
|
aggregateChangeFrequency: () => aggregateChangeFrequency,
|
|
@@ -57279,7 +58349,7 @@ var require_health_adapter = __commonJS({
|
|
|
57279
58349
|
})();
|
|
57280
58350
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
57281
58351
|
exports2.HealthAdapter = void 0;
|
|
57282
|
-
var
|
|
58352
|
+
var fs12 = __importStar(require("fs/promises"));
|
|
57283
58353
|
var index_js_1 = require_schemas3();
|
|
57284
58354
|
var tool_adapter_1 = require_tool_adapter();
|
|
57285
58355
|
var validation_js_1 = require_validation();
|
|
@@ -57370,14 +58440,14 @@ ${content3}`
|
|
|
57370
58440
|
}
|
|
57371
58441
|
async checkVectorStorage(verbose) {
|
|
57372
58442
|
try {
|
|
57373
|
-
const stats = await
|
|
58443
|
+
const stats = await fs12.stat(this.config.vectorStorePath);
|
|
57374
58444
|
if (!stats.isDirectory()) {
|
|
57375
58445
|
return {
|
|
57376
58446
|
status: "fail",
|
|
57377
58447
|
message: "Vector storage path is not a directory"
|
|
57378
58448
|
};
|
|
57379
58449
|
}
|
|
57380
|
-
const files = await
|
|
58450
|
+
const files = await fs12.readdir(this.config.vectorStorePath);
|
|
57381
58451
|
const hasData = files.length > 0;
|
|
57382
58452
|
if (!hasData) {
|
|
57383
58453
|
return {
|
|
@@ -57401,7 +58471,7 @@ ${content3}`
|
|
|
57401
58471
|
}
|
|
57402
58472
|
async checkRepository(verbose) {
|
|
57403
58473
|
try {
|
|
57404
|
-
const stats = await
|
|
58474
|
+
const stats = await fs12.stat(this.config.repositoryPath);
|
|
57405
58475
|
if (!stats.isDirectory()) {
|
|
57406
58476
|
return {
|
|
57407
58477
|
status: "fail",
|
|
@@ -57409,7 +58479,7 @@ ${content3}`
|
|
|
57409
58479
|
};
|
|
57410
58480
|
}
|
|
57411
58481
|
try {
|
|
57412
|
-
await
|
|
58482
|
+
await fs12.stat(`${this.config.repositoryPath}/.git`);
|
|
57413
58483
|
return {
|
|
57414
58484
|
status: "pass",
|
|
57415
58485
|
message: "Repository accessible and is a Git repository",
|
|
@@ -57438,7 +58508,7 @@ ${content3}`
|
|
|
57438
58508
|
};
|
|
57439
58509
|
}
|
|
57440
58510
|
try {
|
|
57441
|
-
const content3 = await
|
|
58511
|
+
const content3 = await fs12.readFile(this.config.githubStatePath, "utf-8");
|
|
57442
58512
|
const state = JSON.parse(content3);
|
|
57443
58513
|
const lastIndexed = state.lastIndexed ? new Date(state.lastIndexed) : null;
|
|
57444
58514
|
const itemCount = state.items?.length ?? 0;
|
|
@@ -59118,7 +60188,7 @@ var require_related_files = __commonJS({
|
|
|
59118
60188
|
exports2.findTestFile = findTestFile2;
|
|
59119
60189
|
exports2.findRelatedTestFiles = findRelatedTestFiles;
|
|
59120
60190
|
exports2.formatRelatedFiles = formatRelatedFiles;
|
|
59121
|
-
var
|
|
60191
|
+
var fs12 = __importStar(require("fs/promises"));
|
|
59122
60192
|
var path16 = __importStar(require("path"));
|
|
59123
60193
|
exports2.DEFAULT_TEST_PATTERNS = [
|
|
59124
60194
|
// Same directory: foo.ts -> foo.test.ts, foo.spec.ts
|
|
@@ -59127,7 +60197,7 @@ var require_related_files = __commonJS({
|
|
|
59127
60197
|
];
|
|
59128
60198
|
async function fileExists(filePath) {
|
|
59129
60199
|
try {
|
|
59130
|
-
await
|
|
60200
|
+
await fs12.access(filePath);
|
|
59131
60201
|
return true;
|
|
59132
60202
|
} catch {
|
|
59133
60203
|
return false;
|
|
@@ -59392,7 +60462,7 @@ var require_status_adapter = __commonJS({
|
|
|
59392
60462
|
})();
|
|
59393
60463
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
59394
60464
|
exports2.StatusAdapter = void 0;
|
|
59395
|
-
var
|
|
60465
|
+
var fs12 = __importStar(require("fs"));
|
|
59396
60466
|
var path16 = __importStar(require("path"));
|
|
59397
60467
|
var utils_1 = require_utils5();
|
|
59398
60468
|
var index_js_1 = require_schemas3();
|
|
@@ -59431,7 +60501,7 @@ var require_status_adapter = __commonJS({
|
|
|
59431
60501
|
if (this.githubService) {
|
|
59432
60502
|
this.githubStatePath = path16.join(this.repositoryPath, ".dev-agent/github-state.json");
|
|
59433
60503
|
try {
|
|
59434
|
-
const stats = await
|
|
60504
|
+
const stats = await fs12.promises.stat(this.githubStatePath);
|
|
59435
60505
|
this.lastStateFileModTime = stats.mtimeMs;
|
|
59436
60506
|
} catch {
|
|
59437
60507
|
}
|
|
@@ -59446,7 +60516,7 @@ var require_status_adapter = __commonJS({
|
|
|
59446
60516
|
return false;
|
|
59447
60517
|
}
|
|
59448
60518
|
try {
|
|
59449
|
-
const stats = await
|
|
60519
|
+
const stats = await fs12.promises.stat(this.githubStatePath);
|
|
59450
60520
|
const currentModTime = stats.mtimeMs;
|
|
59451
60521
|
return currentModTime > this.lastStateFileModTime;
|
|
59452
60522
|
} catch {
|
|
@@ -59462,7 +60532,7 @@ var require_status_adapter = __commonJS({
|
|
|
59462
60532
|
return;
|
|
59463
60533
|
}
|
|
59464
60534
|
try {
|
|
59465
|
-
const stats = await
|
|
60535
|
+
const stats = await fs12.promises.stat(this.githubStatePath);
|
|
59466
60536
|
this.lastStateFileModTime = stats.mtimeMs;
|
|
59467
60537
|
} catch {
|
|
59468
60538
|
}
|
|
@@ -59760,7 +60830,7 @@ var require_status_adapter = __commonJS({
|
|
|
59760
60830
|
async checkHealth() {
|
|
59761
60831
|
const checks = [];
|
|
59762
60832
|
try {
|
|
59763
|
-
await
|
|
60833
|
+
await fs12.promises.access(this.repositoryPath, fs12.constants.R_OK);
|
|
59764
60834
|
checks.push({
|
|
59765
60835
|
name: "Repository Access",
|
|
59766
60836
|
status: "ok",
|
|
@@ -59838,14 +60908,14 @@ var require_status_adapter = __commonJS({
|
|
|
59838
60908
|
checkHealthSync() {
|
|
59839
60909
|
const checks = [];
|
|
59840
60910
|
try {
|
|
59841
|
-
|
|
60911
|
+
fs12.accessSync(this.repositoryPath, fs12.constants.R_OK);
|
|
59842
60912
|
checks.push({ name: "Repository", status: "ok", message: "Accessible" });
|
|
59843
60913
|
} catch {
|
|
59844
60914
|
checks.push({ name: "Repository", status: "error", message: "Not accessible" });
|
|
59845
60915
|
}
|
|
59846
60916
|
try {
|
|
59847
60917
|
const vectorDir = path16.dirname(this.vectorStorePath);
|
|
59848
|
-
|
|
60918
|
+
fs12.accessSync(vectorDir, fs12.constants.R_OK);
|
|
59849
60919
|
checks.push({ name: "Vector Storage", status: "ok", message: "Available" });
|
|
59850
60920
|
} catch {
|
|
59851
60921
|
checks.push({ name: "Vector Storage", status: "warning", message: "Not initialized" });
|
|
@@ -59859,11 +60929,11 @@ var require_status_adapter = __commonJS({
|
|
|
59859
60929
|
try {
|
|
59860
60930
|
const getDirectorySize = async (dirPath) => {
|
|
59861
60931
|
try {
|
|
59862
|
-
const stats = await
|
|
60932
|
+
const stats = await fs12.promises.stat(dirPath);
|
|
59863
60933
|
if (!stats.isDirectory()) {
|
|
59864
60934
|
return stats.size;
|
|
59865
60935
|
}
|
|
59866
|
-
const files = await
|
|
60936
|
+
const files = await fs12.promises.readdir(dirPath);
|
|
59867
60937
|
const sizes = await Promise.all(files.map((file2) => getDirectorySize(path16.join(dirPath, file2))));
|
|
59868
60938
|
return sizes.reduce((acc, size) => acc + size, 0);
|
|
59869
60939
|
} catch {
|