@chosengeneration/light-code 0.35.0 → 0.37.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 +1109 -281
- package/dist/client/client.js +50 -50
- package/dist/client/guide/appearance-dark.svg +1 -1
- package/dist/client/guide/appearance-light.svg +1 -1
- package/dist/client/guide/approvals-dark.svg +1 -1
- package/dist/client/guide/approvals-light.svg +1 -1
- package/dist/client/guide/customData-dark.svg +1 -0
- package/dist/client/guide/customData-light.svg +1 -0
- package/dist/client/guide/expert-dark.svg +1 -1
- package/dist/client/guide/expert-light.svg +1 -1
- package/dist/client/guide/mcp-dark.svg +1 -1
- package/dist/client/guide/mcp-light.svg +1 -1
- package/dist/client/guide/network-dark.svg +1 -1
- package/dist/client/guide/network-light.svg +1 -1
- package/dist/client/guide/providers-dark.svg +1 -1
- package/dist/client/guide/providers-light.svg +1 -1
- package/dist/client/guide/python-dark.svg +1 -1
- package/dist/client/guide/python-light.svg +1 -1
- package/dist/client/guide/schedules-dark.svg +1 -1
- package/dist/client/guide/schedules-light.svg +1 -1
- package/dist/client/guide/search-dark.svg +1 -1
- package/dist/client/guide/search-light.svg +1 -1
- package/dist/client/guide/skills-dark.svg +1 -1
- package/dist/client/guide/skills-light.svg +1 -1
- package/dist/client/guide/tools-dark.svg +1 -1
- package/dist/client/guide/tools-light.svg +1 -1
- package/dist/server.js +1061 -265
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -499,14 +499,14 @@ var require_util = __commonJS({
|
|
|
499
499
|
}
|
|
500
500
|
const port = url2.port != null ? url2.port : url2.protocol === "https:" ? 443 : 80;
|
|
501
501
|
let origin = url2.origin != null ? url2.origin : `${url2.protocol}//${url2.hostname}:${port}`;
|
|
502
|
-
let
|
|
502
|
+
let path31 = url2.path != null ? url2.path : `${url2.pathname || ""}${url2.search || ""}`;
|
|
503
503
|
if (origin.endsWith("/")) {
|
|
504
504
|
origin = origin.substring(0, origin.length - 1);
|
|
505
505
|
}
|
|
506
|
-
if (
|
|
507
|
-
|
|
506
|
+
if (path31 && !path31.startsWith("/")) {
|
|
507
|
+
path31 = `/${path31}`;
|
|
508
508
|
}
|
|
509
|
-
url2 = new URL(origin +
|
|
509
|
+
url2 = new URL(origin + path31);
|
|
510
510
|
}
|
|
511
511
|
return url2;
|
|
512
512
|
}
|
|
@@ -2120,20 +2120,20 @@ var require_parseParams = __commonJS({
|
|
|
2120
2120
|
var require_basename = __commonJS({
|
|
2121
2121
|
"../../node_modules/.pnpm/@fastify+busboy@2.1.1/node_modules/@fastify/busboy/lib/utils/basename.js"(exports, module) {
|
|
2122
2122
|
"use strict";
|
|
2123
|
-
module.exports = function basename(
|
|
2124
|
-
if (typeof
|
|
2123
|
+
module.exports = function basename(path31) {
|
|
2124
|
+
if (typeof path31 !== "string") {
|
|
2125
2125
|
return "";
|
|
2126
2126
|
}
|
|
2127
|
-
for (var i =
|
|
2128
|
-
switch (
|
|
2127
|
+
for (var i = path31.length - 1; i >= 0; --i) {
|
|
2128
|
+
switch (path31.charCodeAt(i)) {
|
|
2129
2129
|
case 47:
|
|
2130
2130
|
// '/'
|
|
2131
2131
|
case 92:
|
|
2132
|
-
|
|
2133
|
-
return
|
|
2132
|
+
path31 = path31.slice(i + 1);
|
|
2133
|
+
return path31 === ".." || path31 === "." ? "" : path31;
|
|
2134
2134
|
}
|
|
2135
2135
|
}
|
|
2136
|
-
return
|
|
2136
|
+
return path31 === ".." || path31 === "." ? "" : path31;
|
|
2137
2137
|
};
|
|
2138
2138
|
}
|
|
2139
2139
|
});
|
|
@@ -5163,7 +5163,7 @@ var require_request = __commonJS({
|
|
|
5163
5163
|
}
|
|
5164
5164
|
var Request = class _Request {
|
|
5165
5165
|
constructor(origin, {
|
|
5166
|
-
path:
|
|
5166
|
+
path: path31,
|
|
5167
5167
|
method,
|
|
5168
5168
|
body,
|
|
5169
5169
|
headers,
|
|
@@ -5177,11 +5177,11 @@ var require_request = __commonJS({
|
|
|
5177
5177
|
throwOnError,
|
|
5178
5178
|
expectContinue
|
|
5179
5179
|
}, handler) {
|
|
5180
|
-
if (typeof
|
|
5180
|
+
if (typeof path31 !== "string") {
|
|
5181
5181
|
throw new InvalidArgumentError("path must be a string");
|
|
5182
|
-
} else if (
|
|
5182
|
+
} else if (path31[0] !== "/" && !(path31.startsWith("http://") || path31.startsWith("https://")) && method !== "CONNECT") {
|
|
5183
5183
|
throw new InvalidArgumentError("path must be an absolute URL or start with a slash");
|
|
5184
|
-
} else if (invalidPathRegex.exec(
|
|
5184
|
+
} else if (invalidPathRegex.exec(path31) !== null) {
|
|
5185
5185
|
throw new InvalidArgumentError("invalid request path");
|
|
5186
5186
|
}
|
|
5187
5187
|
if (typeof method !== "string") {
|
|
@@ -5244,7 +5244,7 @@ var require_request = __commonJS({
|
|
|
5244
5244
|
this.completed = false;
|
|
5245
5245
|
this.aborted = false;
|
|
5246
5246
|
this.upgrade = upgrade || null;
|
|
5247
|
-
this.path = query ? util.buildURL(
|
|
5247
|
+
this.path = query ? util.buildURL(path31, query) : path31;
|
|
5248
5248
|
this.origin = origin;
|
|
5249
5249
|
this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent;
|
|
5250
5250
|
this.blocking = blocking == null ? false : blocking;
|
|
@@ -6252,9 +6252,9 @@ var require_RedirectHandler = __commonJS({
|
|
|
6252
6252
|
return this.handler.onHeaders(statusCode, headers, resume, statusText);
|
|
6253
6253
|
}
|
|
6254
6254
|
const { origin, pathname, search } = util.parseURL(new URL(this.location, this.opts.origin && new URL(this.opts.path, this.opts.origin)));
|
|
6255
|
-
const
|
|
6255
|
+
const path31 = search ? `${pathname}${search}` : pathname;
|
|
6256
6256
|
this.opts.headers = cleanRequestHeaders(this.opts.headers, statusCode === 303, this.opts.origin !== origin);
|
|
6257
|
-
this.opts.path =
|
|
6257
|
+
this.opts.path = path31;
|
|
6258
6258
|
this.opts.origin = origin;
|
|
6259
6259
|
this.opts.maxRedirections = 0;
|
|
6260
6260
|
this.opts.query = null;
|
|
@@ -7494,7 +7494,7 @@ var require_client = __commonJS({
|
|
|
7494
7494
|
writeH2(client, client[kHTTP2Session], request);
|
|
7495
7495
|
return;
|
|
7496
7496
|
}
|
|
7497
|
-
const { body, method, path:
|
|
7497
|
+
const { body, method, path: path31, host, upgrade, headers, blocking, reset } = request;
|
|
7498
7498
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH";
|
|
7499
7499
|
if (body && typeof body.read === "function") {
|
|
7500
7500
|
body.read(0);
|
|
@@ -7544,7 +7544,7 @@ var require_client = __commonJS({
|
|
|
7544
7544
|
if (blocking) {
|
|
7545
7545
|
socket[kBlocking] = true;
|
|
7546
7546
|
}
|
|
7547
|
-
let header = `${method} ${
|
|
7547
|
+
let header = `${method} ${path31} HTTP/1.1\r
|
|
7548
7548
|
`;
|
|
7549
7549
|
if (typeof host === "string") {
|
|
7550
7550
|
header += `host: ${host}\r
|
|
@@ -7607,7 +7607,7 @@ upgrade: ${upgrade}\r
|
|
|
7607
7607
|
return true;
|
|
7608
7608
|
}
|
|
7609
7609
|
function writeH2(client, session, request) {
|
|
7610
|
-
const { body, method, path:
|
|
7610
|
+
const { body, method, path: path31, host, upgrade, expectContinue, signal, headers: reqHeaders } = request;
|
|
7611
7611
|
let headers;
|
|
7612
7612
|
if (typeof reqHeaders === "string") headers = Request[kHTTP2CopyHeaders](reqHeaders.trim());
|
|
7613
7613
|
else headers = reqHeaders;
|
|
@@ -7650,7 +7650,7 @@ upgrade: ${upgrade}\r
|
|
|
7650
7650
|
});
|
|
7651
7651
|
return true;
|
|
7652
7652
|
}
|
|
7653
|
-
headers[HTTP2_HEADER_PATH] =
|
|
7653
|
+
headers[HTTP2_HEADER_PATH] = path31;
|
|
7654
7654
|
headers[HTTP2_HEADER_SCHEME] = "https";
|
|
7655
7655
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH";
|
|
7656
7656
|
if (body && typeof body.read === "function") {
|
|
@@ -9890,20 +9890,20 @@ var require_mock_utils = __commonJS({
|
|
|
9890
9890
|
}
|
|
9891
9891
|
return true;
|
|
9892
9892
|
}
|
|
9893
|
-
function safeUrl(
|
|
9894
|
-
if (typeof
|
|
9895
|
-
return
|
|
9893
|
+
function safeUrl(path31) {
|
|
9894
|
+
if (typeof path31 !== "string") {
|
|
9895
|
+
return path31;
|
|
9896
9896
|
}
|
|
9897
|
-
const pathSegments =
|
|
9897
|
+
const pathSegments = path31.split("?");
|
|
9898
9898
|
if (pathSegments.length !== 2) {
|
|
9899
|
-
return
|
|
9899
|
+
return path31;
|
|
9900
9900
|
}
|
|
9901
9901
|
const qp = new URLSearchParams(pathSegments.pop());
|
|
9902
9902
|
qp.sort();
|
|
9903
9903
|
return [...pathSegments, qp.toString()].join("?");
|
|
9904
9904
|
}
|
|
9905
|
-
function matchKey(mockDispatch2, { path:
|
|
9906
|
-
const pathMatch = matchValue(mockDispatch2.path,
|
|
9905
|
+
function matchKey(mockDispatch2, { path: path31, method, body, headers }) {
|
|
9906
|
+
const pathMatch = matchValue(mockDispatch2.path, path31);
|
|
9907
9907
|
const methodMatch = matchValue(mockDispatch2.method, method);
|
|
9908
9908
|
const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true;
|
|
9909
9909
|
const headersMatch = matchHeaders(mockDispatch2, headers);
|
|
@@ -9921,7 +9921,7 @@ var require_mock_utils = __commonJS({
|
|
|
9921
9921
|
function getMockDispatch(mockDispatches, key) {
|
|
9922
9922
|
const basePath = key.query ? buildURL(key.path, key.query) : key.path;
|
|
9923
9923
|
const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath;
|
|
9924
|
-
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path:
|
|
9924
|
+
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path31 }) => matchValue(safeUrl(path31), resolvedPath));
|
|
9925
9925
|
if (matchedMockDispatches.length === 0) {
|
|
9926
9926
|
throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`);
|
|
9927
9927
|
}
|
|
@@ -9958,9 +9958,9 @@ var require_mock_utils = __commonJS({
|
|
|
9958
9958
|
}
|
|
9959
9959
|
}
|
|
9960
9960
|
function buildKey(opts) {
|
|
9961
|
-
const { path:
|
|
9961
|
+
const { path: path31, method, body, headers, query } = opts;
|
|
9962
9962
|
return {
|
|
9963
|
-
path:
|
|
9963
|
+
path: path31,
|
|
9964
9964
|
method,
|
|
9965
9965
|
body,
|
|
9966
9966
|
headers,
|
|
@@ -10409,10 +10409,10 @@ var require_pending_interceptors_formatter = __commonJS({
|
|
|
10409
10409
|
}
|
|
10410
10410
|
format(pendingInterceptors) {
|
|
10411
10411
|
const withPrettyHeaders = pendingInterceptors.map(
|
|
10412
|
-
({ method, path:
|
|
10412
|
+
({ method, path: path31, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
|
|
10413
10413
|
Method: method,
|
|
10414
10414
|
Origin: origin,
|
|
10415
|
-
Path:
|
|
10415
|
+
Path: path31,
|
|
10416
10416
|
"Status code": statusCode,
|
|
10417
10417
|
Persistent: persist ? "\u2705" : "\u274C",
|
|
10418
10418
|
Invocations: timesInvoked,
|
|
@@ -15032,8 +15032,8 @@ var require_util6 = __commonJS({
|
|
|
15032
15032
|
}
|
|
15033
15033
|
}
|
|
15034
15034
|
}
|
|
15035
|
-
function validateCookiePath(
|
|
15036
|
-
for (const char of
|
|
15035
|
+
function validateCookiePath(path31) {
|
|
15036
|
+
for (const char of path31) {
|
|
15037
15037
|
const code = char.charCodeAt(0);
|
|
15038
15038
|
if (code < 33 || char === ";") {
|
|
15039
15039
|
throw new Error("Invalid cookie path");
|
|
@@ -16713,11 +16713,11 @@ var require_undici = __commonJS({
|
|
|
16713
16713
|
if (typeof opts.path !== "string") {
|
|
16714
16714
|
throw new InvalidArgumentError("invalid opts.path");
|
|
16715
16715
|
}
|
|
16716
|
-
let
|
|
16716
|
+
let path31 = opts.path;
|
|
16717
16717
|
if (!opts.path.startsWith("/")) {
|
|
16718
|
-
|
|
16718
|
+
path31 = `/${path31}`;
|
|
16719
16719
|
}
|
|
16720
|
-
url2 = new URL(util.parseOrigin(url2).origin +
|
|
16720
|
+
url2 = new URL(util.parseOrigin(url2).origin + path31);
|
|
16721
16721
|
} else {
|
|
16722
16722
|
if (!opts) {
|
|
16723
16723
|
opts = typeof url2 === "object" ? url2 : {};
|
|
@@ -19988,8 +19988,8 @@ var require_utils2 = __commonJS({
|
|
|
19988
19988
|
}
|
|
19989
19989
|
return ind;
|
|
19990
19990
|
}
|
|
19991
|
-
function removeDotSegments(
|
|
19992
|
-
let input =
|
|
19991
|
+
function removeDotSegments(path31) {
|
|
19992
|
+
let input = path31;
|
|
19993
19993
|
const output = [];
|
|
19994
19994
|
let nextSlash = -1;
|
|
19995
19995
|
let len = 0;
|
|
@@ -20241,8 +20241,8 @@ var require_schemes = __commonJS({
|
|
|
20241
20241
|
wsComponent.secure = void 0;
|
|
20242
20242
|
}
|
|
20243
20243
|
if (wsComponent.resourceName) {
|
|
20244
|
-
const [
|
|
20245
|
-
wsComponent.path =
|
|
20244
|
+
const [path31, query] = wsComponent.resourceName.split("?");
|
|
20245
|
+
wsComponent.path = path31 && path31 !== "/" ? path31 : void 0;
|
|
20246
20246
|
wsComponent.query = query;
|
|
20247
20247
|
wsComponent.resourceName = void 0;
|
|
20248
20248
|
}
|
|
@@ -23641,12 +23641,12 @@ var require_dist = __commonJS({
|
|
|
23641
23641
|
throw new Error(`Unknown format "${name}"`);
|
|
23642
23642
|
return f;
|
|
23643
23643
|
};
|
|
23644
|
-
function addFormats(ajv, list,
|
|
23644
|
+
function addFormats(ajv, list, fs25, exportName) {
|
|
23645
23645
|
var _a3;
|
|
23646
23646
|
var _b;
|
|
23647
23647
|
(_a3 = (_b = ajv.opts.code).formats) !== null && _a3 !== void 0 ? _a3 : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
|
|
23648
23648
|
for (const f of list)
|
|
23649
|
-
ajv.addFormat(f,
|
|
23649
|
+
ajv.addFormat(f, fs25[f]);
|
|
23650
23650
|
}
|
|
23651
23651
|
module.exports = exports = formatsPlugin;
|
|
23652
23652
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -23659,8 +23659,8 @@ var require_windows = __commonJS({
|
|
|
23659
23659
|
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js"(exports, module) {
|
|
23660
23660
|
module.exports = isexe;
|
|
23661
23661
|
isexe.sync = sync;
|
|
23662
|
-
var
|
|
23663
|
-
function checkPathExt(
|
|
23662
|
+
var fs25 = __require("fs");
|
|
23663
|
+
function checkPathExt(path31, options) {
|
|
23664
23664
|
var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
|
|
23665
23665
|
if (!pathext) {
|
|
23666
23666
|
return true;
|
|
@@ -23671,25 +23671,25 @@ var require_windows = __commonJS({
|
|
|
23671
23671
|
}
|
|
23672
23672
|
for (var i = 0; i < pathext.length; i++) {
|
|
23673
23673
|
var p = pathext[i].toLowerCase();
|
|
23674
|
-
if (p &&
|
|
23674
|
+
if (p && path31.substr(-p.length).toLowerCase() === p) {
|
|
23675
23675
|
return true;
|
|
23676
23676
|
}
|
|
23677
23677
|
}
|
|
23678
23678
|
return false;
|
|
23679
23679
|
}
|
|
23680
|
-
function checkStat(stat,
|
|
23680
|
+
function checkStat(stat, path31, options) {
|
|
23681
23681
|
if (!stat.isSymbolicLink() && !stat.isFile()) {
|
|
23682
23682
|
return false;
|
|
23683
23683
|
}
|
|
23684
|
-
return checkPathExt(
|
|
23684
|
+
return checkPathExt(path31, options);
|
|
23685
23685
|
}
|
|
23686
|
-
function isexe(
|
|
23687
|
-
|
|
23688
|
-
cb(er, er ? false : checkStat(stat,
|
|
23686
|
+
function isexe(path31, options, cb) {
|
|
23687
|
+
fs25.stat(path31, function(er, stat) {
|
|
23688
|
+
cb(er, er ? false : checkStat(stat, path31, options));
|
|
23689
23689
|
});
|
|
23690
23690
|
}
|
|
23691
|
-
function sync(
|
|
23692
|
-
return checkStat(
|
|
23691
|
+
function sync(path31, options) {
|
|
23692
|
+
return checkStat(fs25.statSync(path31), path31, options);
|
|
23693
23693
|
}
|
|
23694
23694
|
}
|
|
23695
23695
|
});
|
|
@@ -23699,14 +23699,14 @@ var require_mode = __commonJS({
|
|
|
23699
23699
|
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js"(exports, module) {
|
|
23700
23700
|
module.exports = isexe;
|
|
23701
23701
|
isexe.sync = sync;
|
|
23702
|
-
var
|
|
23703
|
-
function isexe(
|
|
23704
|
-
|
|
23702
|
+
var fs25 = __require("fs");
|
|
23703
|
+
function isexe(path31, options, cb) {
|
|
23704
|
+
fs25.stat(path31, function(er, stat) {
|
|
23705
23705
|
cb(er, er ? false : checkStat(stat, options));
|
|
23706
23706
|
});
|
|
23707
23707
|
}
|
|
23708
|
-
function sync(
|
|
23709
|
-
return checkStat(
|
|
23708
|
+
function sync(path31, options) {
|
|
23709
|
+
return checkStat(fs25.statSync(path31), options);
|
|
23710
23710
|
}
|
|
23711
23711
|
function checkStat(stat, options) {
|
|
23712
23712
|
return stat.isFile() && checkMode(stat, options);
|
|
@@ -23730,7 +23730,7 @@ var require_mode = __commonJS({
|
|
|
23730
23730
|
// ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js
|
|
23731
23731
|
var require_isexe = __commonJS({
|
|
23732
23732
|
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js"(exports, module) {
|
|
23733
|
-
var
|
|
23733
|
+
var fs25 = __require("fs");
|
|
23734
23734
|
var core;
|
|
23735
23735
|
if (process.platform === "win32" || global.TESTING_WINDOWS) {
|
|
23736
23736
|
core = require_windows();
|
|
@@ -23739,7 +23739,7 @@ var require_isexe = __commonJS({
|
|
|
23739
23739
|
}
|
|
23740
23740
|
module.exports = isexe;
|
|
23741
23741
|
isexe.sync = sync;
|
|
23742
|
-
function isexe(
|
|
23742
|
+
function isexe(path31, options, cb) {
|
|
23743
23743
|
if (typeof options === "function") {
|
|
23744
23744
|
cb = options;
|
|
23745
23745
|
options = {};
|
|
@@ -23749,7 +23749,7 @@ var require_isexe = __commonJS({
|
|
|
23749
23749
|
throw new TypeError("callback not provided");
|
|
23750
23750
|
}
|
|
23751
23751
|
return new Promise(function(resolve, reject2) {
|
|
23752
|
-
isexe(
|
|
23752
|
+
isexe(path31, options || {}, function(er, is) {
|
|
23753
23753
|
if (er) {
|
|
23754
23754
|
reject2(er);
|
|
23755
23755
|
} else {
|
|
@@ -23758,7 +23758,7 @@ var require_isexe = __commonJS({
|
|
|
23758
23758
|
});
|
|
23759
23759
|
});
|
|
23760
23760
|
}
|
|
23761
|
-
core(
|
|
23761
|
+
core(path31, options || {}, function(er, is) {
|
|
23762
23762
|
if (er) {
|
|
23763
23763
|
if (er.code === "EACCES" || options && options.ignoreErrors) {
|
|
23764
23764
|
er = null;
|
|
@@ -23768,9 +23768,9 @@ var require_isexe = __commonJS({
|
|
|
23768
23768
|
cb(er, is);
|
|
23769
23769
|
});
|
|
23770
23770
|
}
|
|
23771
|
-
function sync(
|
|
23771
|
+
function sync(path31, options) {
|
|
23772
23772
|
try {
|
|
23773
|
-
return core.sync(
|
|
23773
|
+
return core.sync(path31, options || {});
|
|
23774
23774
|
} catch (er) {
|
|
23775
23775
|
if (options && options.ignoreErrors || er.code === "EACCES") {
|
|
23776
23776
|
return false;
|
|
@@ -23786,7 +23786,7 @@ var require_isexe = __commonJS({
|
|
|
23786
23786
|
var require_which = __commonJS({
|
|
23787
23787
|
"../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js"(exports, module) {
|
|
23788
23788
|
var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
|
|
23789
|
-
var
|
|
23789
|
+
var path31 = __require("path");
|
|
23790
23790
|
var COLON = isWindows ? ";" : ":";
|
|
23791
23791
|
var isexe = require_isexe();
|
|
23792
23792
|
var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
|
|
@@ -23824,7 +23824,7 @@ var require_which = __commonJS({
|
|
|
23824
23824
|
return opt.all && found.length ? resolve(found) : reject2(getNotFoundError(cmd));
|
|
23825
23825
|
const ppRaw = pathEnv[i];
|
|
23826
23826
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
23827
|
-
const pCmd =
|
|
23827
|
+
const pCmd = path31.join(pathPart, cmd);
|
|
23828
23828
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
23829
23829
|
resolve(subStep(p, i, 0));
|
|
23830
23830
|
});
|
|
@@ -23851,7 +23851,7 @@ var require_which = __commonJS({
|
|
|
23851
23851
|
for (let i = 0; i < pathEnv.length; i++) {
|
|
23852
23852
|
const ppRaw = pathEnv[i];
|
|
23853
23853
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
23854
|
-
const pCmd =
|
|
23854
|
+
const pCmd = path31.join(pathPart, cmd);
|
|
23855
23855
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
23856
23856
|
for (let j = 0; j < pathExt.length; j++) {
|
|
23857
23857
|
const cur = p + pathExt[j];
|
|
@@ -23899,7 +23899,7 @@ var require_path_key = __commonJS({
|
|
|
23899
23899
|
var require_resolveCommand = __commonJS({
|
|
23900
23900
|
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module) {
|
|
23901
23901
|
"use strict";
|
|
23902
|
-
var
|
|
23902
|
+
var path31 = __require("path");
|
|
23903
23903
|
var which = require_which();
|
|
23904
23904
|
var getPathKey = require_path_key();
|
|
23905
23905
|
function resolveCommandAttempt(parsed, withoutPathExt) {
|
|
@@ -23917,7 +23917,7 @@ var require_resolveCommand = __commonJS({
|
|
|
23917
23917
|
try {
|
|
23918
23918
|
resolved = which.sync(parsed.command, {
|
|
23919
23919
|
path: env2[getPathKey({ env: env2 })],
|
|
23920
|
-
pathExt: withoutPathExt ?
|
|
23920
|
+
pathExt: withoutPathExt ? path31.delimiter : void 0
|
|
23921
23921
|
});
|
|
23922
23922
|
} catch (e) {
|
|
23923
23923
|
} finally {
|
|
@@ -23926,7 +23926,7 @@ var require_resolveCommand = __commonJS({
|
|
|
23926
23926
|
}
|
|
23927
23927
|
}
|
|
23928
23928
|
if (resolved) {
|
|
23929
|
-
resolved =
|
|
23929
|
+
resolved = path31.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
|
|
23930
23930
|
}
|
|
23931
23931
|
return resolved;
|
|
23932
23932
|
}
|
|
@@ -23980,8 +23980,8 @@ var require_shebang_command = __commonJS({
|
|
|
23980
23980
|
if (!match) {
|
|
23981
23981
|
return null;
|
|
23982
23982
|
}
|
|
23983
|
-
const [
|
|
23984
|
-
const binary =
|
|
23983
|
+
const [path31, argument] = match[0].replace(/#! ?/, "").split(" ");
|
|
23984
|
+
const binary = path31.split("/").pop();
|
|
23985
23985
|
if (binary === "env") {
|
|
23986
23986
|
return argument;
|
|
23987
23987
|
}
|
|
@@ -23994,16 +23994,16 @@ var require_shebang_command = __commonJS({
|
|
|
23994
23994
|
var require_readShebang = __commonJS({
|
|
23995
23995
|
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module) {
|
|
23996
23996
|
"use strict";
|
|
23997
|
-
var
|
|
23997
|
+
var fs25 = __require("fs");
|
|
23998
23998
|
var shebangCommand = require_shebang_command();
|
|
23999
23999
|
function readShebang(command) {
|
|
24000
24000
|
const size = 150;
|
|
24001
24001
|
const buffer = Buffer.alloc(size);
|
|
24002
24002
|
let fd;
|
|
24003
24003
|
try {
|
|
24004
|
-
fd =
|
|
24005
|
-
|
|
24006
|
-
|
|
24004
|
+
fd = fs25.openSync(command, "r");
|
|
24005
|
+
fs25.readSync(fd, buffer, 0, size, 0);
|
|
24006
|
+
fs25.closeSync(fd);
|
|
24007
24007
|
} catch (e) {
|
|
24008
24008
|
}
|
|
24009
24009
|
return shebangCommand(buffer.toString());
|
|
@@ -24016,7 +24016,7 @@ var require_readShebang = __commonJS({
|
|
|
24016
24016
|
var require_parse2 = __commonJS({
|
|
24017
24017
|
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js"(exports, module) {
|
|
24018
24018
|
"use strict";
|
|
24019
|
-
var
|
|
24019
|
+
var path31 = __require("path");
|
|
24020
24020
|
var resolveCommand = require_resolveCommand();
|
|
24021
24021
|
var escape2 = require_escape();
|
|
24022
24022
|
var readShebang = require_readShebang();
|
|
@@ -24041,7 +24041,7 @@ var require_parse2 = __commonJS({
|
|
|
24041
24041
|
const needsShell = !isExecutableRegExp.test(commandFile);
|
|
24042
24042
|
if (parsed.options.forceShell || needsShell) {
|
|
24043
24043
|
const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
|
|
24044
|
-
parsed.command =
|
|
24044
|
+
parsed.command = path31.normalize(parsed.command);
|
|
24045
24045
|
parsed.command = escape2.command(parsed.command);
|
|
24046
24046
|
parsed.args = parsed.args.map((arg) => escape2.argument(arg, needsDoubleEscapeMetaChars));
|
|
24047
24047
|
const shellCommand = [parsed.command].concat(parsed.args).join(" ");
|
|
@@ -24256,11 +24256,11 @@ var require_content_type = __commonJS({
|
|
|
24256
24256
|
});
|
|
24257
24257
|
|
|
24258
24258
|
// src/server.ts
|
|
24259
|
-
import
|
|
24259
|
+
import fs24 from "node:fs/promises";
|
|
24260
24260
|
import {
|
|
24261
24261
|
createServer
|
|
24262
24262
|
} from "node:http";
|
|
24263
|
-
import
|
|
24263
|
+
import path30 from "node:path";
|
|
24264
24264
|
|
|
24265
24265
|
// ../../packages/core/dist/platform/http.js
|
|
24266
24266
|
var import_undici = __toESM(require_undici(), 1);
|
|
@@ -25194,10 +25194,10 @@ function mergeDefs(...defs) {
|
|
|
25194
25194
|
function cloneDef(schema) {
|
|
25195
25195
|
return mergeDefs(schema._zod.def);
|
|
25196
25196
|
}
|
|
25197
|
-
function getElementAtPath(obj,
|
|
25198
|
-
if (!
|
|
25197
|
+
function getElementAtPath(obj, path31) {
|
|
25198
|
+
if (!path31)
|
|
25199
25199
|
return obj;
|
|
25200
|
-
return
|
|
25200
|
+
return path31.reduce((acc, key) => acc?.[key], obj);
|
|
25201
25201
|
}
|
|
25202
25202
|
function promiseAllObject(promisesObj) {
|
|
25203
25203
|
const keys = Object.keys(promisesObj);
|
|
@@ -25606,11 +25606,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
25606
25606
|
}
|
|
25607
25607
|
return false;
|
|
25608
25608
|
}
|
|
25609
|
-
function prefixIssues(
|
|
25609
|
+
function prefixIssues(path31, issues) {
|
|
25610
25610
|
return issues.map((iss) => {
|
|
25611
25611
|
var _a3;
|
|
25612
25612
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
25613
|
-
iss.path.unshift(
|
|
25613
|
+
iss.path.unshift(path31);
|
|
25614
25614
|
return iss;
|
|
25615
25615
|
});
|
|
25616
25616
|
}
|
|
@@ -25757,16 +25757,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
25757
25757
|
}
|
|
25758
25758
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
25759
25759
|
const fieldErrors = { _errors: [] };
|
|
25760
|
-
const processError = (error52,
|
|
25760
|
+
const processError = (error52, path31 = []) => {
|
|
25761
25761
|
for (const issue2 of error52.issues) {
|
|
25762
25762
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
25763
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
25763
|
+
issue2.errors.map((issues) => processError({ issues }, [...path31, ...issue2.path]));
|
|
25764
25764
|
} else if (issue2.code === "invalid_key") {
|
|
25765
|
-
processError({ issues: issue2.issues }, [...
|
|
25765
|
+
processError({ issues: issue2.issues }, [...path31, ...issue2.path]);
|
|
25766
25766
|
} else if (issue2.code === "invalid_element") {
|
|
25767
|
-
processError({ issues: issue2.issues }, [...
|
|
25767
|
+
processError({ issues: issue2.issues }, [...path31, ...issue2.path]);
|
|
25768
25768
|
} else {
|
|
25769
|
-
const fullpath = [...
|
|
25769
|
+
const fullpath = [...path31, ...issue2.path];
|
|
25770
25770
|
if (fullpath.length === 0) {
|
|
25771
25771
|
fieldErrors._errors.push(mapper(issue2));
|
|
25772
25772
|
} else {
|
|
@@ -25793,17 +25793,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
25793
25793
|
}
|
|
25794
25794
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
25795
25795
|
const result = { errors: [] };
|
|
25796
|
-
const processError = (error52,
|
|
25796
|
+
const processError = (error52, path31 = []) => {
|
|
25797
25797
|
var _a3, _b;
|
|
25798
25798
|
for (const issue2 of error52.issues) {
|
|
25799
25799
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
25800
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
25800
|
+
issue2.errors.map((issues) => processError({ issues }, [...path31, ...issue2.path]));
|
|
25801
25801
|
} else if (issue2.code === "invalid_key") {
|
|
25802
|
-
processError({ issues: issue2.issues }, [...
|
|
25802
|
+
processError({ issues: issue2.issues }, [...path31, ...issue2.path]);
|
|
25803
25803
|
} else if (issue2.code === "invalid_element") {
|
|
25804
|
-
processError({ issues: issue2.issues }, [...
|
|
25804
|
+
processError({ issues: issue2.issues }, [...path31, ...issue2.path]);
|
|
25805
25805
|
} else {
|
|
25806
|
-
const fullpath = [...
|
|
25806
|
+
const fullpath = [...path31, ...issue2.path];
|
|
25807
25807
|
if (fullpath.length === 0) {
|
|
25808
25808
|
result.errors.push(mapper(issue2));
|
|
25809
25809
|
continue;
|
|
@@ -25835,8 +25835,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
25835
25835
|
}
|
|
25836
25836
|
function toDotPath(_path) {
|
|
25837
25837
|
const segs = [];
|
|
25838
|
-
const
|
|
25839
|
-
for (const seg of
|
|
25838
|
+
const path31 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
25839
|
+
for (const seg of path31) {
|
|
25840
25840
|
if (typeof seg === "number")
|
|
25841
25841
|
segs.push(`[${seg}]`);
|
|
25842
25842
|
else if (typeof seg === "symbol")
|
|
@@ -38528,13 +38528,13 @@ function resolveRef(ref, ctx) {
|
|
|
38528
38528
|
if (!ref.startsWith("#")) {
|
|
38529
38529
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
38530
38530
|
}
|
|
38531
|
-
const
|
|
38532
|
-
if (
|
|
38531
|
+
const path31 = ref.slice(1).split("/").filter(Boolean);
|
|
38532
|
+
if (path31.length === 0) {
|
|
38533
38533
|
return ctx.rootSchema;
|
|
38534
38534
|
}
|
|
38535
38535
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
38536
|
-
if (
|
|
38537
|
-
const key =
|
|
38536
|
+
if (path31[0] === defsKey) {
|
|
38537
|
+
const key = path31[1];
|
|
38538
38538
|
if (!key || !ctx.defs[key]) {
|
|
38539
38539
|
throw new Error(`Reference not found: ${ref}`);
|
|
38540
38540
|
}
|
|
@@ -38942,6 +38942,79 @@ function date4(params) {
|
|
|
38942
38942
|
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js
|
|
38943
38943
|
config(en_default());
|
|
38944
38944
|
|
|
38945
|
+
// ../../packages/core/dist/dataset/types.js
|
|
38946
|
+
var datasetRecordSchema = external_exports.object({
|
|
38947
|
+
/**
|
|
38948
|
+
* Stable across syncs. The same record from the source must come back with the same id, or a
|
|
38949
|
+
* re-sync duplicates it rather than replacing it — which is the failure that turns a useful
|
|
38950
|
+
* corpus into noise a few runs in.
|
|
38951
|
+
*/
|
|
38952
|
+
id: external_exports.string().min(1),
|
|
38953
|
+
/** What gets embedded and what a search returns. */
|
|
38954
|
+
text: external_exports.string().min(1),
|
|
38955
|
+
/** A heading for the search result. Falls back to the opening of `text`. */
|
|
38956
|
+
title: external_exports.string().optional(),
|
|
38957
|
+
/** Where it came from — a ticket URL, a file path. Shown so a hit can be followed up. */
|
|
38958
|
+
url: external_exports.string().optional(),
|
|
38959
|
+
/**
|
|
38960
|
+
* Epoch milliseconds. Retention and "what changed this week" both need it.
|
|
38961
|
+
*
|
|
38962
|
+
* Absent is allowed and means "no age", which retention then cannot remove. Defaulting it to
|
|
38963
|
+
* *now* would be worse: every record would age from whenever it was last synced, so nothing
|
|
38964
|
+
* would ever look old and retention would silently never fire.
|
|
38965
|
+
*/
|
|
38966
|
+
timestamp: external_exports.number().optional(),
|
|
38967
|
+
/** Anything else the tool wants to keep. Filterable exactly, never embedded. */
|
|
38968
|
+
tags: external_exports.record(external_exports.string(), external_exports.string()).optional()
|
|
38969
|
+
});
|
|
38970
|
+
var datasetPayloadSchema = external_exports.union([
|
|
38971
|
+
external_exports.object({ records: external_exports.array(datasetRecordSchema) }),
|
|
38972
|
+
external_exports.array(datasetRecordSchema)
|
|
38973
|
+
]);
|
|
38974
|
+
function parseDatasetPayload(value) {
|
|
38975
|
+
const parsed = datasetPayloadSchema.safeParse(value);
|
|
38976
|
+
if (parsed.success) {
|
|
38977
|
+
return { records: Array.isArray(parsed.data) ? parsed.data : parsed.data.records };
|
|
38978
|
+
}
|
|
38979
|
+
return {
|
|
38980
|
+
error: 'The collector tool did not return records in the expected shape. Return a list of {"id": ..., "text": ...} objects, or {"records": [...]}. Each id must be stable across runs so a re-sync updates rather than duplicates. ' + parsed.error.issues.slice(0, 5).map((issue2) => `${issue2.path.join(".")}: ${issue2.message}`).join("; ")
|
|
38981
|
+
};
|
|
38982
|
+
}
|
|
38983
|
+
var datasetConfigSchema = external_exports.object({
|
|
38984
|
+
id: external_exports.string().min(1),
|
|
38985
|
+
name: external_exports.string().min(1, "Give it a name"),
|
|
38986
|
+
/** The Python tool that produces the records, by its bare name. */
|
|
38987
|
+
toolName: external_exports.string().min(1, "Choose a collector tool"),
|
|
38988
|
+
/** Passed to the tool as its arguments, so one tool can serve several datasets. */
|
|
38989
|
+
arguments: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
|
|
38990
|
+
enabled: external_exports.boolean().optional(),
|
|
38991
|
+
/** How often to re-run the collector. Zero or absent means only when asked. */
|
|
38992
|
+
syncMinutes: external_exports.number().int().min(0).optional(),
|
|
38993
|
+
/** Drop records older than this. Absent means keep everything. */
|
|
38994
|
+
retentionDays: external_exports.number().int().positive().optional(),
|
|
38995
|
+
/** Which vector store to write to. Falls back to the one named for `data`, then the active one. */
|
|
38996
|
+
storeId: external_exports.string().optional()
|
|
38997
|
+
});
|
|
38998
|
+
var COLLECTOR_TOOL_GUIDANCE = [
|
|
38999
|
+
"Writing a collector for a custom dataset:",
|
|
39000
|
+
"- A collector is an ordinary Python tool. Its `run` returns a list of records, each a dict",
|
|
39001
|
+
" with `id` and `text`, and optionally `title`, `url`, `timestamp` (epoch milliseconds) and",
|
|
39002
|
+
" `tags` (a flat dict of strings).",
|
|
39003
|
+
"- **`id` must be stable across runs.** Use the source's own identifier \u2014 a ticket key, a row",
|
|
39004
|
+
" id, a file path. A generated or time-based id makes every sync duplicate the whole corpus",
|
|
39005
|
+
" instead of updating it, which is not obvious until the results are full of near-copies.",
|
|
39006
|
+
"- **`text` is what gets embedded and what a search shows.** Put the meaning in it: a subject",
|
|
39007
|
+
" and a body, not an id and a status code. Roughly a paragraph to a page each works best.",
|
|
39008
|
+
'- Set `timestamp` wherever the source has one. Retention and any "what changed recently"',
|
|
39009
|
+
" question both need it, and it cannot be recovered later.",
|
|
39010
|
+
"- The tool is called with whatever arguments the dataset configures, plus `since` \u2014 epoch",
|
|
39011
|
+
" milliseconds of the last successful sync, or absent on the first. Use it to fetch only what",
|
|
39012
|
+
" changed if the source allows; returning everything each time is correct but slower.",
|
|
39013
|
+
"- Return `[]` when there is nothing new. That is a successful sync, not an error.",
|
|
39014
|
+
"- Keep credentials out of the tool: read them from the environment or from a file the user",
|
|
39015
|
+
" already has. A tool file lives in the workspace and lands in git."
|
|
39016
|
+
].join("\n");
|
|
39017
|
+
|
|
38945
39018
|
// ../../packages/core/dist/mcp/types.js
|
|
38946
39019
|
var stdioServerSchema = external_exports.object({
|
|
38947
39020
|
command: external_exports.string().min(1),
|
|
@@ -39213,6 +39286,20 @@ var authSchema = external_exports.discriminatedUnion("type", [
|
|
|
39213
39286
|
*/
|
|
39214
39287
|
external_exports.object({ type: external_exports.literal("apiKey"), apiKeyRef: external_exports.string().min(1) }),
|
|
39215
39288
|
external_exports.object({ type: external_exports.literal("tokenCommand"), tokenCommand: tokenCommandSchema }),
|
|
39289
|
+
/**
|
|
39290
|
+
* A fixed header the gateway expects, with no API key involved.
|
|
39291
|
+
*
|
|
39292
|
+
* Each value is a *reference* — a secret-store key, or `env:NAME` — never a literal, because
|
|
39293
|
+
* the profile lives in the config file and §15 is explicit that a credential never does.
|
|
39294
|
+
*/
|
|
39295
|
+
external_exports.object({
|
|
39296
|
+
type: external_exports.literal("header"),
|
|
39297
|
+
headers: external_exports.array(external_exports.object({
|
|
39298
|
+
name: external_exports.string().min(1, "Give the header name"),
|
|
39299
|
+
valueRef: external_exports.string().min(1, "Give the value, or env:NAME"),
|
|
39300
|
+
prefix: external_exports.string().optional()
|
|
39301
|
+
})).min(1, "Add at least one header")
|
|
39302
|
+
}),
|
|
39216
39303
|
external_exports.object({
|
|
39217
39304
|
type: external_exports.literal("apigeeMtls"),
|
|
39218
39305
|
certs: certConfigSchema,
|
|
@@ -39256,6 +39343,7 @@ var providerProfileSchema = external_exports.object({
|
|
|
39256
39343
|
});
|
|
39257
39344
|
|
|
39258
39345
|
// ../../packages/core/dist/config/schema.js
|
|
39346
|
+
var datasetsConfigSchema = external_exports.array(datasetConfigSchema);
|
|
39259
39347
|
var pythonConfigSchema = external_exports.object({
|
|
39260
39348
|
/**
|
|
39261
39349
|
* Off by default and explicitly three-state. This is the sharpest surface in the
|
|
@@ -39545,7 +39633,15 @@ var retrievalConfigSchema = external_exports.object({
|
|
|
39545
39633
|
/** Indexed mail. Usually local, and deliberately easy to keep separate. */
|
|
39546
39634
|
mail: external_exports.string().min(1),
|
|
39547
39635
|
/** The team's shared skills. Often the same cluster as the code. */
|
|
39548
|
-
skills: external_exports.string().min(1)
|
|
39636
|
+
skills: external_exports.string().min(1),
|
|
39637
|
+
/**
|
|
39638
|
+
* Corpora the user collects themselves.
|
|
39639
|
+
*
|
|
39640
|
+
* Routed separately for the same reason mail is: somebody's own collected data —
|
|
39641
|
+
* tickets, extracts from an internal system — is frequently the thing they most want
|
|
39642
|
+
* kept off a cluster their team shares.
|
|
39643
|
+
*/
|
|
39644
|
+
data: external_exports.string().min(1)
|
|
39549
39645
|
}).partial()
|
|
39550
39646
|
}).partial();
|
|
39551
39647
|
function storeIdFor(purpose, config2) {
|
|
@@ -39733,6 +39829,7 @@ var configSchema = external_exports.object({
|
|
|
39733
39829
|
programmingProfileId: external_exports.string(),
|
|
39734
39830
|
certDir: external_exports.string(),
|
|
39735
39831
|
python: pythonConfigSchema,
|
|
39832
|
+
datasets: datasetsConfigSchema,
|
|
39736
39833
|
/**
|
|
39737
39834
|
* Keyed by workspace path. Per-workspace in *behaviour* (§8) but stored user-side and
|
|
39738
39835
|
* user-scope-only (invariant 5) — a repo must not be able to ship its own
|
|
@@ -40204,6 +40301,19 @@ var GUIDE_STEPS = [
|
|
|
40204
40301
|
"You get a writable folder plus any number of read-only ones, such as a shared team folder, with PATH-style precedence and shadowing reported rather than silently applied. Writing a skill needs approval too: it is prose that steers every future turn."
|
|
40205
40302
|
]
|
|
40206
40303
|
},
|
|
40304
|
+
{
|
|
40305
|
+
id: "customData",
|
|
40306
|
+
title: "Custom data - bring your own corpus",
|
|
40307
|
+
tab: "customData",
|
|
40308
|
+
completionEvents: ["onStepSelected"],
|
|
40309
|
+
altText: "The Custom data tab, showing a dataset with its collector tool, record count, schedule and last sync, alongside buttons for syncing, rebuilding and clearing it.",
|
|
40310
|
+
body: [
|
|
40311
|
+
"The data you most want the assistant to know is rarely on disk. It is in a ticketing system, a wiki, a database, an internal API - reachable, but only through something that knows how your organisation authenticates.",
|
|
40312
|
+
"So you point at a tool that returns records, and Light Code does the rest: embedding them, keeping them current, and searching them with `search_data`. The collector is an ordinary Python tool or an MCP tool you already have - one function signature rather than a connector per system.",
|
|
40313
|
+
"You do not have to write it. Tell the assistant where the data lives and ask for a collector; it already has the contract and will offer one for you to approve.",
|
|
40314
|
+
"Each dataset has its own schedule - including **only when I ask**, which is the right answer for a source that is expensive or that only changes when somebody does something. Clear, rebuild and a retention window are all here, and a progress bar with a Stop for the first sync of something large."
|
|
40315
|
+
]
|
|
40316
|
+
},
|
|
40207
40317
|
{
|
|
40208
40318
|
id: "search",
|
|
40209
40319
|
title: "Search - find things by meaning",
|
|
@@ -40306,6 +40416,9 @@ var USER_SCOPE_ONLY_KEYS = [
|
|
|
40306
40416
|
// Added for Phase 8b, and the sharpest entries on this list. A workspace able to name a
|
|
40307
40417
|
// cluster, or repoint the embedder at a profile of its choosing, would exfiltrate
|
|
40308
40418
|
// whatever gets indexed — and what gets indexed is the source code.
|
|
40419
|
+
// A dataset names a program to run *and* a store to write what it produced into — the `python`
|
|
40420
|
+
// threat and the `embedder` threat in one key, on a timer.
|
|
40421
|
+
"datasets",
|
|
40309
40422
|
"vectorStores",
|
|
40310
40423
|
"activeVectorStoreId",
|
|
40311
40424
|
"embedder",
|
|
@@ -40868,6 +40981,27 @@ var NoAuthStrategy = class {
|
|
|
40868
40981
|
}
|
|
40869
40982
|
};
|
|
40870
40983
|
|
|
40984
|
+
// ../../packages/core/dist/providers/auth/header.js
|
|
40985
|
+
var HeaderAuthStrategy = class {
|
|
40986
|
+
secrets;
|
|
40987
|
+
credentials;
|
|
40988
|
+
constructor(secrets, credentials) {
|
|
40989
|
+
this.secrets = secrets;
|
|
40990
|
+
this.credentials = credentials;
|
|
40991
|
+
}
|
|
40992
|
+
async resolveHeaders() {
|
|
40993
|
+
const headers = {};
|
|
40994
|
+
for (const credential of this.credentials) {
|
|
40995
|
+
const value = await resolveSecretRef(credential.valueRef, { secrets: this.secrets });
|
|
40996
|
+
if (value === void 0) {
|
|
40997
|
+
throw new Error(`${describeMissingSecret(credential.valueRef, `the value for header "${credential.name}"`)}`);
|
|
40998
|
+
}
|
|
40999
|
+
headers[credential.name] = `${credential.prefix ?? ""}${value}`;
|
|
41000
|
+
}
|
|
41001
|
+
return headers;
|
|
41002
|
+
}
|
|
41003
|
+
};
|
|
41004
|
+
|
|
40871
41005
|
// ../../packages/core/dist/providers/auth/tokenCommand.js
|
|
40872
41006
|
import { spawn } from "node:child_process";
|
|
40873
41007
|
function readPath(source, dotted) {
|
|
@@ -41413,6 +41547,8 @@ function createBaseAuthStrategy(auth2, context) {
|
|
|
41413
41547
|
headerPrefix: auth2.tokenCommand.headerPrefix ?? context.apiKeyHeaderPrefix ?? derived.prefix
|
|
41414
41548
|
});
|
|
41415
41549
|
}
|
|
41550
|
+
case "header":
|
|
41551
|
+
return new HeaderAuthStrategy(context.secrets, auth2.headers);
|
|
41416
41552
|
case "none":
|
|
41417
41553
|
return new NoAuthStrategy();
|
|
41418
41554
|
case "apigeeMtls": {
|
|
@@ -42391,8 +42527,8 @@ var SUPERSEDED_MARKER = "[Superseded: this file was read again later in the conv
|
|
|
42391
42527
|
function readFilePath(argumentsJson) {
|
|
42392
42528
|
try {
|
|
42393
42529
|
const parsed = JSON.parse(argumentsJson.length > 0 ? argumentsJson : "{}");
|
|
42394
|
-
const
|
|
42395
|
-
return typeof
|
|
42530
|
+
const path31 = parsed.path;
|
|
42531
|
+
return typeof path31 === "string" && path31.length > 0 ? path31 : void 0;
|
|
42396
42532
|
} catch {
|
|
42397
42533
|
return void 0;
|
|
42398
42534
|
}
|
|
@@ -42405,8 +42541,8 @@ function dropSupersededReads(messages) {
|
|
|
42405
42541
|
for (const toolCall of message3.toolCalls ?? []) {
|
|
42406
42542
|
if (toolCall.name !== "read_file")
|
|
42407
42543
|
continue;
|
|
42408
|
-
const
|
|
42409
|
-
if (
|
|
42544
|
+
const path31 = readFilePath(toolCall.arguments);
|
|
42545
|
+
if (path31 === void 0)
|
|
42410
42546
|
continue;
|
|
42411
42547
|
keyByCallId.set(toolCall.id, toolCall.arguments);
|
|
42412
42548
|
}
|
|
@@ -42841,6 +42977,15 @@ function buildSystemPrompt(workspaceRoot, options = {}) {
|
|
|
42841
42977
|
lines.push("", "Recording what you learn:", "- When the user explains something durable about their environment \u2014 an internal", " library and how to use it, a house convention, the shape of an in-house API, a", " gotcha specific to this codebase \u2014 offer to record it with write_skill. Ask first;", " do not write one unprompted.", '- "Durable" means it would be true again next week and useful to a future', " conversation. A one-off instruction for the current task is not a skill.", options.skillsSearchable === true ? "- Before writing a new skill, search for one with search_docs: if a note already covers the subject, read it and update that instead of creating a near-duplicate." : "- Before writing a new skill, check the list above: if one already covers the subject, read it and update that instead of creating a near-duplicate.", "- When you learn something *corrects* an existing skill, say so and offer to update", " it. A stale skill is worse than a missing one, because it is trusted.", "- Write for a reader who has none of this conversation: name the package, the import", ' path, the function, and show a short example. Avoid "as discussed" and "the usual".', options.skillsSearchable === true ? "- The description line is what search matches on, so make it say what subject the skill covers in the words someone would search for \u2014 it is a trigger, not a summary." : "- The description line is the only part always in context, so make it say what subject the skill covers \u2014 it is a trigger for reading, not a summary.");
|
|
42842
42978
|
}
|
|
42843
42979
|
lines.push("", "Charts:", "- **Draw one whenever numbers are easier seen than read** \u2014 a count per folder or per day, a", " value trending over time, a breakdown of a total. Use show_chart; do not print a table of", " figures where a chart would answer the question faster.", "- **Always fill in `detail`** when the numbers count things that can be named \u2014 the subjects,", ' the files, the ids. A bar reading 14 is only useful if "which fourteen?" has an answer, and', " the detail is what lets the user open the bar instead of asking you to search again.", "- Say in `note` where the numbers came from and what they exclude. A chart is believed", " without being checked, so its limits have to travel with it.", "- Series must have exactly one value per category. A mismatch is refused rather than padded,", " because a chart drawn from misaligned data looks correct and is not.", "- After drawing, describe what it shows. Do not recite the numbers again \u2014 they are on screen.", "- **A Python tool can produce the data.** Have it return JSON shaped", ' `{"categories": [...], "series": [{"name": ..., "values": [...], "detail": [[...], ...]}]}`', " and pass that straight to show_chart. That is the intended way to chart anything you have", " analysed in Python \u2014 the tool does the arithmetic, show_chart draws it, and the numbers are", " never retyped by you in between.");
|
|
42980
|
+
if (options.datasets !== void 0 && options.datasets.length > 0) {
|
|
42981
|
+
lines.push("", "Custom datasets:", `- The user collects these themselves: ${options.datasets.map((dataset) => `${dataset.name} (${String(dataset.records)} records)`).join(", ")}.`, "- **Use search_data for anything about data the organisation collects itself** \u2014 tickets,", " wiki pages, rows from an internal system. It is the only way to reach these; they are not", " in the codebase and not in the mail index.", "- It searches what has been **synced**, not the live source. If the answer turns on", " something very recent, say when the dataset was last synced rather than implying it is", " current. Do not offer to refresh it yourself \u2014 syncing is triggered by the user.", ...options.canWriteCollectors === true ? [
|
|
42982
|
+
"- If they want a dataset you cannot find, you can write the collector: it is an",
|
|
42983
|
+
" ordinary Python tool returning records. Offer, do not assume \u2014 then they configure",
|
|
42984
|
+
" it in Settings, Custom data. The contract is below.",
|
|
42985
|
+
"",
|
|
42986
|
+
COLLECTOR_TOOL_GUIDANCE
|
|
42987
|
+
] : []);
|
|
42988
|
+
}
|
|
42844
42989
|
if (options.mailIndexed === true) {
|
|
42845
42990
|
lines.push("", "Email:", "- **Always answer questions about email from the index, using search_mail and", " mail_patterns.** That is what it is for. It is fast, it answers questions about time", " and recurrence that a live search cannot, and it does not disturb the running Outlook.", '- **Only search Outlook itself when the user asks you to.** "Check Outlook", "look at my', ' actual mailbox", "is it there now" and anything similar are the instruction to use', " outlook_search. Do not reach for it on your own initiative.", "- If the index has nothing, say so plainly and say when it was last synced. Do not", " quietly fall back to scanning Outlook - a slow live scan that nobody asked for reads", " as the assistant having hung.", "- One exception worth naming: if the user is asking about something that arrived in the", " last few minutes, the index may not have it yet. Say that, and offer to check Outlook", " rather than doing it unasked.", "- **The index holds plain text.** Colours, highlighting and images are not in it. When", " those could carry meaning \u2014 a red line marking a failure, a highlighted cell \u2014 use", " outlook_read_email on the id, which reads the live message and reports the colours.", " Never conclude a message looks fine from indexed text alone.", "- mail_coverage says which folders are indexed and how far back. Check it before saying", " something is not in the mail: an empty search over an unindexed folder looks exactly", " like an empty search over an indexed one.", "- **Use mail_stats for any question with a number in the answer** \u2014 how many alerts per", " folder, per day, per hour, which senders, whether a figure inside the alerts is climbing.", " It counts everything the filters matched. Never count search results by eye: search", " returns a page, so counting what you were shown reports a sample as if it were the total.", "- mail_stats already returns categories, values and detail in the shape show_chart wants.", " Pass it through rather than retyping the numbers, and keep the detail.");
|
|
42846
42991
|
}
|
|
@@ -43480,13 +43625,13 @@ var OpenSearchClient = class {
|
|
|
43480
43625
|
* `_bulk`, `_delete_by_query`, index creation — is refused here rather than merely
|
|
43481
43626
|
* unused, so no future edit or crafted argument can turn a read client into a writer.
|
|
43482
43627
|
*/
|
|
43483
|
-
async request(
|
|
43628
|
+
async request(path31, options = {}) {
|
|
43484
43629
|
const method = options.method ?? "GET";
|
|
43485
|
-
const isSearchPost = method === "POST" && /\/_search(\?|$)/.test(
|
|
43630
|
+
const isSearchPost = method === "POST" && /\/_search(\?|$)/.test(path31);
|
|
43486
43631
|
if (method !== "GET" && !isSearchPost) {
|
|
43487
|
-
throw new OpenSearchError(`Refusing ${method} ${
|
|
43632
|
+
throw new OpenSearchError(`Refusing ${method} ${path31}: this client is read-only. Indexing goes through the indexer, which the user starts from Settings.`);
|
|
43488
43633
|
}
|
|
43489
|
-
const url2 = `${this.base}${
|
|
43634
|
+
const url2 = `${this.base}${path31}`;
|
|
43490
43635
|
const request = {
|
|
43491
43636
|
method,
|
|
43492
43637
|
headers: this.headers()
|
|
@@ -43649,11 +43794,11 @@ function collectFields(properties, prefix, out) {
|
|
|
43649
43794
|
return;
|
|
43650
43795
|
for (const [name, raw] of Object.entries(properties)) {
|
|
43651
43796
|
const field = raw;
|
|
43652
|
-
const
|
|
43797
|
+
const path31 = prefix.length > 0 ? `${prefix}.${name}` : name;
|
|
43653
43798
|
if (typeof field.type === "string")
|
|
43654
|
-
out[
|
|
43799
|
+
out[path31] = field.type;
|
|
43655
43800
|
if (field.properties !== void 0)
|
|
43656
|
-
collectFields(field.properties,
|
|
43801
|
+
collectFields(field.properties, path31, out);
|
|
43657
43802
|
}
|
|
43658
43803
|
}
|
|
43659
43804
|
function describeStatus(status, url2, body) {
|
|
@@ -43672,23 +43817,23 @@ function describeStatus(status, url2, body) {
|
|
|
43672
43817
|
var TEXT_TYPES = /* @__PURE__ */ new Set(["text", "match_only_text", "search_as_you_type", "wildcard"]);
|
|
43673
43818
|
var KEYWORD_TYPES = /* @__PURE__ */ new Set(["keyword", "constant_keyword"]);
|
|
43674
43819
|
var NOISE_FIELDS = /* @__PURE__ */ new Set(["@version", "ecs", "tags", "stream", "input", "agent", "host", "event"]);
|
|
43675
|
-
function leafName(
|
|
43676
|
-
const parts =
|
|
43677
|
-
return parts[parts.length - 1] ??
|
|
43820
|
+
function leafName(path31) {
|
|
43821
|
+
const parts = path31.split(".");
|
|
43822
|
+
return parts[parts.length - 1] ?? path31;
|
|
43678
43823
|
}
|
|
43679
43824
|
function selectQueryFields(mapping, limit = 25) {
|
|
43680
43825
|
const text = [];
|
|
43681
43826
|
const keyword = [];
|
|
43682
|
-
for (const [
|
|
43683
|
-
if (NOISE_FIELDS.has(leafName(
|
|
43827
|
+
for (const [path31, type] of Object.entries(mapping)) {
|
|
43828
|
+
if (NOISE_FIELDS.has(leafName(path31)) || NOISE_FIELDS.has(path31.split(".")[0] ?? ""))
|
|
43684
43829
|
continue;
|
|
43685
43830
|
if (TEXT_TYPES.has(type)) {
|
|
43686
|
-
text.push(
|
|
43831
|
+
text.push(path31);
|
|
43687
43832
|
} else if (KEYWORD_TYPES.has(type)) {
|
|
43688
|
-
const parent =
|
|
43689
|
-
if (
|
|
43833
|
+
const parent = path31.replace(/\.keyword$/, "");
|
|
43834
|
+
if (path31.endsWith(".keyword") && TEXT_TYPES.has(mapping[parent] ?? ""))
|
|
43690
43835
|
continue;
|
|
43691
|
-
keyword.push(
|
|
43836
|
+
keyword.push(path31);
|
|
43692
43837
|
}
|
|
43693
43838
|
}
|
|
43694
43839
|
const byDepth = (a, b) => a.split(".").length - b.split(".").length || a.localeCompare(b);
|
|
@@ -43830,8 +43975,8 @@ var OpenSearchIndexWriter = class {
|
|
|
43830
43975
|
}
|
|
43831
43976
|
return headers;
|
|
43832
43977
|
}
|
|
43833
|
-
async request(
|
|
43834
|
-
const url2 = `${this.connection.url.replace(/\/+$/, "")}${
|
|
43978
|
+
async request(path31, method, body, signal) {
|
|
43979
|
+
const url2 = `${this.connection.url.replace(/\/+$/, "")}${path31}`;
|
|
43835
43980
|
const request = { method, headers: this.headers() };
|
|
43836
43981
|
if (body !== void 0) {
|
|
43837
43982
|
if (typeof body === "string") {
|
|
@@ -44045,13 +44190,13 @@ var OpenSearchIndexWriter = class {
|
|
|
44045
44190
|
for (const hit of hits) {
|
|
44046
44191
|
const source = hit._source ?? {};
|
|
44047
44192
|
const vector = source.vector;
|
|
44048
|
-
const
|
|
44049
|
-
if (typeof
|
|
44193
|
+
const path31 = source.path;
|
|
44194
|
+
if (typeof path31 !== "string" || !Array.isArray(vector))
|
|
44050
44195
|
continue;
|
|
44051
44196
|
documents.push({
|
|
44052
44197
|
id: hit._id ?? "",
|
|
44053
44198
|
text: typeof source.text === "string" ? source.text : "",
|
|
44054
|
-
path:
|
|
44199
|
+
path: path31,
|
|
44055
44200
|
startLine: typeof source.startLine === "number" ? source.startLine : 1,
|
|
44056
44201
|
endLine: typeof source.endLine === "number" ? source.endLine : 1,
|
|
44057
44202
|
vector
|
|
@@ -44125,8 +44270,8 @@ var RestTransport = class {
|
|
|
44125
44270
|
* threw would push every caller into catching and re-inspecting an error to find out
|
|
44126
44271
|
* whether it was really an error. `expectOk` is there for the cases that are.
|
|
44127
44272
|
*/
|
|
44128
|
-
async send(
|
|
44129
|
-
const url2 = `${this.connection.url.replace(/\/+$/, "")}${
|
|
44273
|
+
async send(path31, method, body, signal) {
|
|
44274
|
+
const url2 = `${this.connection.url.replace(/\/+$/, "")}${path31}`;
|
|
44130
44275
|
const request = { method, headers: this.headers() };
|
|
44131
44276
|
if (body !== void 0)
|
|
44132
44277
|
request.body = JSON.stringify(body);
|
|
@@ -44152,11 +44297,11 @@ var RestTransport = class {
|
|
|
44152
44297
|
return { status: response.status, body: parsed };
|
|
44153
44298
|
}
|
|
44154
44299
|
/** Sends, and throws unless the status is 2xx. */
|
|
44155
|
-
async expectOk(
|
|
44156
|
-
const result = await this.send(
|
|
44300
|
+
async expectOk(path31, method, body, signal) {
|
|
44301
|
+
const result = await this.send(path31, method, body, signal);
|
|
44157
44302
|
if (result.status < 200 || result.status >= 300) {
|
|
44158
44303
|
const detail = typeof result.body === "string" ? result.body : JSON.stringify(result.body ?? "");
|
|
44159
|
-
throw new VectorStoreError(`${method} ${
|
|
44304
|
+
throw new VectorStoreError(`${method} ${path31} on ${this.label} returned HTTP ${String(result.status)}. ${detail.slice(0, 300)}`, result.status);
|
|
44160
44305
|
}
|
|
44161
44306
|
return result.body;
|
|
44162
44307
|
}
|
|
@@ -44257,10 +44402,10 @@ var ChromaSearcher = class extends ChromaBase {
|
|
|
44257
44402
|
const matches = [];
|
|
44258
44403
|
for (let index = 0; index < ids.length; index++) {
|
|
44259
44404
|
const metadata = metadatas[index] ?? {};
|
|
44260
|
-
const
|
|
44261
|
-
if (
|
|
44405
|
+
const path31 = typeof metadata.path === "string" ? metadata.path : void 0;
|
|
44406
|
+
if (path31 === void 0)
|
|
44262
44407
|
continue;
|
|
44263
|
-
if (filtering && !
|
|
44408
|
+
if (filtering && !path31.startsWith(prefix))
|
|
44264
44409
|
continue;
|
|
44265
44410
|
const distance = distances[index];
|
|
44266
44411
|
const match = {
|
|
@@ -44272,7 +44417,7 @@ var ChromaSearcher = class extends ChromaBase {
|
|
|
44272
44417
|
*/
|
|
44273
44418
|
score: typeof distance === "number" ? 1 / (1 + Math.max(0, distance)) : 0,
|
|
44274
44419
|
text: documents[index] ?? (typeof metadata.text === "string" ? metadata.text : ""),
|
|
44275
|
-
path:
|
|
44420
|
+
path: path31
|
|
44276
44421
|
};
|
|
44277
44422
|
if (typeof metadata.startLine === "number")
|
|
44278
44423
|
match.startLine = metadata.startLine;
|
|
@@ -44383,13 +44528,13 @@ var ChromaIndexWriter = class extends ChromaBase {
|
|
|
44383
44528
|
for (let index = 0; index < ids.length; index++) {
|
|
44384
44529
|
const metadata = result.metadatas?.[index] ?? {};
|
|
44385
44530
|
const vector = result.embeddings?.[index];
|
|
44386
|
-
const
|
|
44387
|
-
if (
|
|
44531
|
+
const path31 = typeof metadata.path === "string" ? metadata.path : void 0;
|
|
44532
|
+
if (path31 === void 0 || !Array.isArray(vector))
|
|
44388
44533
|
continue;
|
|
44389
44534
|
documents.push({
|
|
44390
44535
|
id: ids[index] ?? "",
|
|
44391
44536
|
text: result.documents?.[index] ?? "",
|
|
44392
|
-
path:
|
|
44537
|
+
path: path31,
|
|
44393
44538
|
startLine: typeof metadata.startLine === "number" ? metadata.startLine : 1,
|
|
44394
44539
|
endLine: typeof metadata.endLine === "number" ? metadata.endLine : 1,
|
|
44395
44540
|
vector
|
|
@@ -44406,9 +44551,9 @@ var ChromaIndexWriter = class extends ChromaBase {
|
|
|
44406
44551
|
const result = await this.rest.expectOk(`${this.base}/collections/${found.id}/get`, "POST", { include: ["metadatas"], limit }, options.signal);
|
|
44407
44552
|
const paths = /* @__PURE__ */ new Set();
|
|
44408
44553
|
for (const metadata of result.metadatas ?? []) {
|
|
44409
|
-
const
|
|
44410
|
-
if (typeof
|
|
44411
|
-
paths.add(
|
|
44554
|
+
const path31 = metadata?.path;
|
|
44555
|
+
if (typeof path31 === "string")
|
|
44556
|
+
paths.add(path31);
|
|
44412
44557
|
}
|
|
44413
44558
|
return [...paths];
|
|
44414
44559
|
}
|
|
@@ -44435,14 +44580,14 @@ var MARKER_ID = "5f6d2a41-0000-5000-8000-6c69676874c0";
|
|
|
44435
44580
|
var MARKER_MARK = "light-code";
|
|
44436
44581
|
function toMatch(point) {
|
|
44437
44582
|
const payload = point.payload ?? {};
|
|
44438
|
-
const
|
|
44439
|
-
if (
|
|
44583
|
+
const path31 = typeof payload.path === "string" ? payload.path : void 0;
|
|
44584
|
+
if (path31 === void 0)
|
|
44440
44585
|
return void 0;
|
|
44441
44586
|
const match = {
|
|
44442
44587
|
id: typeof payload.chunkId === "string" ? payload.chunkId : point.id,
|
|
44443
44588
|
score: typeof point.score === "number" ? point.score : 0,
|
|
44444
44589
|
text: typeof payload.text === "string" ? payload.text : "",
|
|
44445
|
-
path:
|
|
44590
|
+
path: path31
|
|
44446
44591
|
};
|
|
44447
44592
|
if (typeof payload.startLine === "number")
|
|
44448
44593
|
match.startLine = payload.startLine;
|
|
@@ -44620,13 +44765,13 @@ var QdrantIndexWriter = class extends QdrantBase {
|
|
|
44620
44765
|
const documents = [];
|
|
44621
44766
|
for (const point of result.body.result?.points ?? []) {
|
|
44622
44767
|
const payload = point.payload ?? {};
|
|
44623
|
-
const
|
|
44624
|
-
if (
|
|
44768
|
+
const path31 = typeof payload.path === "string" ? payload.path : void 0;
|
|
44769
|
+
if (path31 === void 0 || !Array.isArray(point.vector))
|
|
44625
44770
|
continue;
|
|
44626
44771
|
documents.push({
|
|
44627
44772
|
id: typeof payload.chunkId === "string" ? payload.chunkId : point.id,
|
|
44628
44773
|
text: typeof payload.text === "string" ? payload.text : "",
|
|
44629
|
-
path:
|
|
44774
|
+
path: path31,
|
|
44630
44775
|
startLine: typeof payload.startLine === "number" ? payload.startLine : 1,
|
|
44631
44776
|
endLine: typeof payload.endLine === "number" ? payload.endLine : 1,
|
|
44632
44777
|
vector: point.vector
|
|
@@ -44653,9 +44798,9 @@ var QdrantIndexWriter = class extends QdrantBase {
|
|
|
44653
44798
|
throw new VectorStoreError(`Could not list "${collection}" (HTTP ${String(result.status)}).`, result.status);
|
|
44654
44799
|
}
|
|
44655
44800
|
for (const point of result.body.result?.points ?? []) {
|
|
44656
|
-
const
|
|
44657
|
-
if (typeof
|
|
44658
|
-
paths.add(
|
|
44801
|
+
const path31 = point.payload?.path;
|
|
44802
|
+
if (typeof path31 === "string")
|
|
44803
|
+
paths.add(path31);
|
|
44659
44804
|
}
|
|
44660
44805
|
offset = result.body.result?.next_page_offset;
|
|
44661
44806
|
if (offset === void 0 || offset === null)
|
|
@@ -45069,8 +45214,8 @@ function teamSkillDocument(skill, body, vector, attribution) {
|
|
|
45069
45214
|
vector
|
|
45070
45215
|
};
|
|
45071
45216
|
}
|
|
45072
|
-
function nameFromPath(
|
|
45073
|
-
return
|
|
45217
|
+
function nameFromPath(path31) {
|
|
45218
|
+
return path31.startsWith("skill:") ? path31.slice("skill:".length) : path31;
|
|
45074
45219
|
}
|
|
45075
45220
|
function toHit(match, self) {
|
|
45076
45221
|
return {
|
|
@@ -46456,8 +46601,8 @@ function createMailCoverageTool(options) {
|
|
|
46456
46601
|
}
|
|
46457
46602
|
};
|
|
46458
46603
|
}
|
|
46459
|
-
function normaliseFolder(
|
|
46460
|
-
return
|
|
46604
|
+
function normaliseFolder(path31) {
|
|
46605
|
+
return path31.toLowerCase().replace(/[\\/]+/g, "\\");
|
|
46461
46606
|
}
|
|
46462
46607
|
function haystackOf(record2) {
|
|
46463
46608
|
return `${record2.subject}
|
|
@@ -46915,7 +47060,7 @@ async function refreshMail(options) {
|
|
|
46915
47060
|
const limit = options.batchLimit ?? 2e3;
|
|
46916
47061
|
const previewChars = options.previewChars ?? 400;
|
|
46917
47062
|
const sinceMs = Date.now() - options.days * 24 * 60 * 60 * 1e3;
|
|
46918
|
-
const harvested = await options.harvest(options.folders.map((
|
|
47063
|
+
const harvested = await options.harvest(options.folders.map((path31) => ({ path: path31, sinceMs })), { limit, previewChars });
|
|
46919
47064
|
const fetched = harvested.messages.map(toRecord);
|
|
46920
47065
|
if (fetched.length === 0) {
|
|
46921
47066
|
return { added: 0, more: false, total: known.length, embedded: 0, backfilled: 0, complete: [] };
|
|
@@ -46956,9 +47101,9 @@ async function syncMail(options) {
|
|
|
46956
47101
|
const backfillDone = await options.store.loadBackfillState();
|
|
46957
47102
|
const limit = options.batchLimit ?? 500;
|
|
46958
47103
|
const previewChars = options.previewChars ?? 400;
|
|
46959
|
-
const forwardRequests = options.folders.map((
|
|
46960
|
-
const mark = marks.get(
|
|
46961
|
-
return mark === void 0 ? { path:
|
|
47104
|
+
const forwardRequests = options.folders.map((path31) => {
|
|
47105
|
+
const mark = marks.get(path31);
|
|
47106
|
+
return mark === void 0 ? { path: path31 } : { path: path31, sinceMs: mark.newest - 1e3 };
|
|
46962
47107
|
});
|
|
46963
47108
|
const forward = await options.harvest(forwardRequests, { limit, previewChars });
|
|
46964
47109
|
let candidates = forward.messages.map(toRecord);
|
|
@@ -46967,15 +47112,15 @@ async function syncMail(options) {
|
|
|
46967
47112
|
let more = forward.truncated;
|
|
46968
47113
|
const remaining = limit - candidates.length;
|
|
46969
47114
|
const floor = options.retentionMonths === void 0 ? void 0 : monthsBefore(options.now ?? Date.now(), options.retentionMonths);
|
|
46970
|
-
const outstanding = options.folders.filter((
|
|
46971
|
-
const atFloor = floor === void 0 ? [] : outstanding.filter((
|
|
46972
|
-
const behind = outstanding.filter((
|
|
47115
|
+
const outstanding = options.folders.filter((path31) => marks.has(path31) && backfillDone[path31] !== true);
|
|
47116
|
+
const atFloor = floor === void 0 ? [] : outstanding.filter((path31) => marks.get(path31).oldest <= floor);
|
|
47117
|
+
const behind = outstanding.filter((path31) => !atFloor.includes(path31));
|
|
46973
47118
|
completed.push(...atFloor);
|
|
46974
47119
|
if (remaining > 0 && behind.length > 0 && options.signal?.aborted !== true) {
|
|
46975
|
-
const backRequests = behind.map((
|
|
46976
|
-
path:
|
|
47120
|
+
const backRequests = behind.map((path31) => ({
|
|
47121
|
+
path: path31,
|
|
46977
47122
|
// Strictly older, so the oldest held message is not fetched again every pass.
|
|
46978
|
-
beforeMs: marks.get(
|
|
47123
|
+
beforeMs: marks.get(path31).oldest,
|
|
46979
47124
|
// And no older than retention wants. The harvest ANDs the two into one window.
|
|
46980
47125
|
...floor === void 0 ? {} : { sinceMs: floor }
|
|
46981
47126
|
}));
|
|
@@ -46983,9 +47128,9 @@ async function syncMail(options) {
|
|
|
46983
47128
|
backfilled = backward.messages.length;
|
|
46984
47129
|
candidates = [...candidates, ...backward.messages.map(toRecord)];
|
|
46985
47130
|
const returnedFor = new Set(backward.messages.map((message3) => message3.folder));
|
|
46986
|
-
for (const
|
|
46987
|
-
if (!returnedFor.has(
|
|
46988
|
-
completed.push(
|
|
47131
|
+
for (const path31 of behind) {
|
|
47132
|
+
if (!returnedFor.has(path31))
|
|
47133
|
+
completed.push(path31);
|
|
46989
47134
|
}
|
|
46990
47135
|
if (backward.truncated || backfilled > 0)
|
|
46991
47136
|
more = true;
|
|
@@ -46993,7 +47138,7 @@ async function syncMail(options) {
|
|
|
46993
47138
|
if (completed.length > 0) {
|
|
46994
47139
|
await options.store.saveBackfillState({
|
|
46995
47140
|
...backfillDone,
|
|
46996
|
-
...Object.fromEntries(completed.map((
|
|
47141
|
+
...Object.fromEntries(completed.map((path31) => [path31, true]))
|
|
46997
47142
|
});
|
|
46998
47143
|
}
|
|
46999
47144
|
const fresh = withoutKnown(candidates, known);
|
|
@@ -47911,14 +48056,14 @@ function formatBytes(size) {
|
|
|
47911
48056
|
return `${(size / (1 << 10)).toFixed(1)}KB`;
|
|
47912
48057
|
return `${String(size)}B`;
|
|
47913
48058
|
}
|
|
47914
|
-
async function readTail(
|
|
48059
|
+
async function readTail(fs25, path31, size, count) {
|
|
47915
48060
|
let span = Math.min(size, CHUNK);
|
|
47916
48061
|
let text;
|
|
47917
48062
|
let start;
|
|
47918
48063
|
for (; ; ) {
|
|
47919
48064
|
start = Math.max(0, size - span);
|
|
47920
48065
|
const decoder = new StringDecoder("utf8");
|
|
47921
|
-
text = decoder.write(await
|
|
48066
|
+
text = decoder.write(await fs25.readBytesSlice(path31, start, size)) + decoder.end();
|
|
47922
48067
|
const enough = text.split("\n").length > count;
|
|
47923
48068
|
if (enough || start === 0 || span >= size)
|
|
47924
48069
|
break;
|
|
@@ -47936,7 +48081,7 @@ async function readTail(fs24, path30, size, count) {
|
|
|
47936
48081
|
hasMoreAfter: false
|
|
47937
48082
|
};
|
|
47938
48083
|
}
|
|
47939
|
-
async function readLineWindow(
|
|
48084
|
+
async function readLineWindow(fs25, path31, size, from, count) {
|
|
47940
48085
|
const decoder = new StringDecoder("utf8");
|
|
47941
48086
|
const lines = [];
|
|
47942
48087
|
let pending = "";
|
|
@@ -47951,7 +48096,7 @@ async function readLineWindow(fs24, path30, size, from, count) {
|
|
|
47951
48096
|
};
|
|
47952
48097
|
scan: while (position < size) {
|
|
47953
48098
|
const end = Math.min(size, position + CHUNK);
|
|
47954
|
-
pending += decoder.write(await
|
|
48099
|
+
pending += decoder.write(await fs25.readBytesSlice(path31, position, end));
|
|
47955
48100
|
position = end;
|
|
47956
48101
|
const parts = pending.split(/\r\n|\r|\n/);
|
|
47957
48102
|
pending = parts.pop() ?? "";
|
|
@@ -47974,13 +48119,13 @@ async function readLineWindow(fs24, path30, size, from, count) {
|
|
|
47974
48119
|
hasMoreAfter: !reachedEnd || lineNumber > from + lines.length
|
|
47975
48120
|
};
|
|
47976
48121
|
}
|
|
47977
|
-
async function countLines(
|
|
48122
|
+
async function countLines(fs25, path31, size) {
|
|
47978
48123
|
let newlines = 0;
|
|
47979
48124
|
let position = 0;
|
|
47980
48125
|
let lastByte = -1;
|
|
47981
48126
|
while (position < size) {
|
|
47982
48127
|
const end = Math.min(size, position + CHUNK);
|
|
47983
|
-
const buffer = await
|
|
48128
|
+
const buffer = await fs25.readBytesSlice(path31, position, end);
|
|
47984
48129
|
for (const byte of buffer)
|
|
47985
48130
|
if (byte === 10)
|
|
47986
48131
|
newlines += 1;
|
|
@@ -58488,17 +58633,17 @@ var WebviewApprovalGate = class {
|
|
|
58488
58633
|
// ../../packages/core/dist/platform/node/filesystem.js
|
|
58489
58634
|
import fs16 from "node:fs/promises";
|
|
58490
58635
|
var NodeFileSystem = class {
|
|
58491
|
-
async readFile(
|
|
58492
|
-
return fs16.readFile(
|
|
58636
|
+
async readFile(path31) {
|
|
58637
|
+
return fs16.readFile(path31, "utf8");
|
|
58493
58638
|
}
|
|
58494
|
-
async readBytes(
|
|
58495
|
-
return fs16.readFile(
|
|
58639
|
+
async readBytes(path31) {
|
|
58640
|
+
return fs16.readFile(path31);
|
|
58496
58641
|
}
|
|
58497
|
-
async readBytesSlice(
|
|
58642
|
+
async readBytesSlice(path31, start, end) {
|
|
58498
58643
|
const length = Math.max(0, end - start);
|
|
58499
58644
|
if (length === 0)
|
|
58500
58645
|
return Buffer.alloc(0);
|
|
58501
|
-
const handle = await fs16.open(
|
|
58646
|
+
const handle = await fs16.open(path31, "r");
|
|
58502
58647
|
try {
|
|
58503
58648
|
const buffer = Buffer.alloc(length);
|
|
58504
58649
|
const { bytesRead } = await handle.read(buffer, 0, length, start);
|
|
@@ -58507,11 +58652,11 @@ var NodeFileSystem = class {
|
|
|
58507
58652
|
await handle.close();
|
|
58508
58653
|
}
|
|
58509
58654
|
}
|
|
58510
|
-
async writeFile(
|
|
58511
|
-
await fs16.writeFile(
|
|
58655
|
+
async writeFile(path31, contents) {
|
|
58656
|
+
await fs16.writeFile(path31, contents, "utf8");
|
|
58512
58657
|
}
|
|
58513
|
-
async stat(
|
|
58514
|
-
const stat = await fs16.lstat(
|
|
58658
|
+
async stat(path31) {
|
|
58659
|
+
const stat = await fs16.lstat(path31);
|
|
58515
58660
|
return {
|
|
58516
58661
|
size: stat.size,
|
|
58517
58662
|
mtimeMs: stat.mtimeMs,
|
|
@@ -58520,8 +58665,8 @@ var NodeFileSystem = class {
|
|
|
58520
58665
|
isSymbolicLink: stat.isSymbolicLink()
|
|
58521
58666
|
};
|
|
58522
58667
|
}
|
|
58523
|
-
async readdir(
|
|
58524
|
-
const entries = await fs16.readdir(
|
|
58668
|
+
async readdir(path31) {
|
|
58669
|
+
const entries = await fs16.readdir(path31, { withFileTypes: true });
|
|
58525
58670
|
return entries.map((entry) => ({
|
|
58526
58671
|
name: entry.name,
|
|
58527
58672
|
isFile: entry.isFile(),
|
|
@@ -58529,16 +58674,16 @@ var NodeFileSystem = class {
|
|
|
58529
58674
|
isSymbolicLink: entry.isSymbolicLink()
|
|
58530
58675
|
}));
|
|
58531
58676
|
}
|
|
58532
|
-
async exists(
|
|
58677
|
+
async exists(path31) {
|
|
58533
58678
|
try {
|
|
58534
|
-
await fs16.access(
|
|
58679
|
+
await fs16.access(path31);
|
|
58535
58680
|
return true;
|
|
58536
58681
|
} catch {
|
|
58537
58682
|
return false;
|
|
58538
58683
|
}
|
|
58539
58684
|
}
|
|
58540
|
-
async mkdir(
|
|
58541
|
-
await fs16.mkdir(
|
|
58685
|
+
async mkdir(path31) {
|
|
58686
|
+
await fs16.mkdir(path31, { recursive: true });
|
|
58542
58687
|
}
|
|
58543
58688
|
};
|
|
58544
58689
|
|
|
@@ -58783,6 +58928,8 @@ async function toSummary(profile, secrets) {
|
|
|
58783
58928
|
...profile.auth.type === "apiKey" && describeSecretRef(profile.auth.apiKeyRef).kind === "env" ? { apiKeyEnvVar: describeSecretRef(profile.auth.apiKeyRef).envVar } : {},
|
|
58784
58929
|
// Not a secret: a command describes how to *get* a credential. The token it produces never
|
|
58785
58930
|
// crosses the bridge, and a form cannot edit what it is never shown.
|
|
58931
|
+
// References only — a store key or a variable name, never the credential (invariant 7).
|
|
58932
|
+
...profile.auth.type === "header" ? { authHeaders: profile.auth.headers } : {},
|
|
58786
58933
|
...profile.auth.type === "tokenCommand" ? {
|
|
58787
58934
|
/*
|
|
58788
58935
|
* `env` is dropped on the way out, deliberately.
|
|
@@ -59310,6 +59457,9 @@ function wireChatBridge(services) {
|
|
|
59310
59457
|
let cachedProgrammingProfileId;
|
|
59311
59458
|
let cachedOffice = {};
|
|
59312
59459
|
let cachedMail = {};
|
|
59460
|
+
let cachedDatasets = [];
|
|
59461
|
+
let datasetSummaryForPrompt = [];
|
|
59462
|
+
let cachedPythonEnabled = false;
|
|
59313
59463
|
const mailStore = new MailStore(storageDir);
|
|
59314
59464
|
let mailBusy = false;
|
|
59315
59465
|
let mailTimer;
|
|
@@ -59342,6 +59492,12 @@ function wireChatBridge(services) {
|
|
|
59342
59492
|
cachedProgrammingProfileId = config2.programmingProfileId;
|
|
59343
59493
|
cachedOffice = config2.office ?? {};
|
|
59344
59494
|
cachedMail = config2.mail ?? {};
|
|
59495
|
+
cachedDatasets = config2.datasets ?? [];
|
|
59496
|
+
cachedPythonEnabled = config2.python?.dynamicTools === "on";
|
|
59497
|
+
datasetSummaryForPrompt = await Promise.all(cachedDatasets.map(async (dataset) => ({
|
|
59498
|
+
name: dataset.name,
|
|
59499
|
+
records: (await new DatasetStore(storageDir, dataset.id).load()).length
|
|
59500
|
+
})));
|
|
59345
59501
|
cachedModeId = config2.modeId;
|
|
59346
59502
|
cachedMaxIterations = config2.maxIterations ?? 25;
|
|
59347
59503
|
cachedAccentColor = config2.ui?.accentColor ?? "#22C55E";
|
|
@@ -59442,7 +59598,7 @@ function wireChatBridge(services) {
|
|
|
59442
59598
|
platform: process.platform === "win32" ? "win32" : "posix"
|
|
59443
59599
|
});
|
|
59444
59600
|
}
|
|
59445
|
-
function currentToolRegistry(expert, search, codebase, docs, dispatcher = false, hideSkills = false, teamSkills, mailSemantic) {
|
|
59601
|
+
function currentToolRegistry(expert, search, codebase, docs, dispatcher = false, hideSkills = false, teamSkills, mailSemantic, datasetSemanticForTools) {
|
|
59446
59602
|
const combined = new ToolRegistry();
|
|
59447
59603
|
for (const tool of builtinTools.list())
|
|
59448
59604
|
combined.register(tool);
|
|
@@ -59529,6 +59685,16 @@ function wireChatBridge(services) {
|
|
|
59529
59685
|
if (codebase !== void 0) {
|
|
59530
59686
|
combined.register(createSearchCodebaseTool({ ...codebase, observer: searchLog }));
|
|
59531
59687
|
}
|
|
59688
|
+
if (cachedDatasets.length > 0) {
|
|
59689
|
+
combined.register(createSearchDataTool({
|
|
59690
|
+
load: async () => Promise.all(cachedDatasets.map(async (dataset) => ({
|
|
59691
|
+
id: dataset.id,
|
|
59692
|
+
name: dataset.name,
|
|
59693
|
+
records: await new DatasetStore(storageDir, dataset.id).load()
|
|
59694
|
+
}))),
|
|
59695
|
+
...datasetSemanticForTools !== void 0 ? { semantic: datasetSemanticForTools } : {}
|
|
59696
|
+
}));
|
|
59697
|
+
}
|
|
59532
59698
|
if (officeSupported() && (cachedOffice.excel === true || cachedOffice.outlook === true)) {
|
|
59533
59699
|
const officeOptions = { bridge: office() };
|
|
59534
59700
|
if (cachedOffice.excel === true) {
|
|
@@ -59804,6 +59970,9 @@ function wireChatBridge(services) {
|
|
|
59804
59970
|
expertAvailable: expertCliInfo !== void 0,
|
|
59805
59971
|
// Named only when there is an index to prefer.
|
|
59806
59972
|
mailIndexed: cachedMail.enabled === true && cachedOffice.outlook === true,
|
|
59973
|
+
// Counted here rather than in the prompt builder, which has no filesystem.
|
|
59974
|
+
datasets: datasetSummaryForPrompt,
|
|
59975
|
+
canWriteCollectors: cachedPythonEnabled,
|
|
59807
59976
|
/*
|
|
59808
59977
|
* Either the whole list or a count and an instruction to search — never both, and
|
|
59809
59978
|
* never neither. `renderSkillsHintForPrompt` explains why the count stays.
|
|
@@ -59954,7 +60123,17 @@ function wireChatBridge(services) {
|
|
|
59954
60123
|
* is frequently a local Qdrant while the code goes to a shared cluster — mail is the
|
|
59955
60124
|
* corpus people most want kept off a team's infrastructure.
|
|
59956
60125
|
*/
|
|
59957
|
-
mailCollection !== void 0 && mailSearch !== void 0 && embedder !== void 0 ? { searcher: mailSearch.searcher, embedder, collection: mailCollection } : void 0
|
|
60126
|
+
mailCollection !== void 0 && mailSearch !== void 0 && embedder !== void 0 ? { searcher: mailSearch.searcher, embedder, collection: mailCollection } : void 0,
|
|
60127
|
+
/*
|
|
60128
|
+
* Datasets share one collection, resolved against whichever store `retrieval.stores.data`
|
|
60129
|
+
* names — the same per-corpus routing §12e added, for the same reason: somebody's own
|
|
60130
|
+
* collected data is frequently the corpus they most want kept off a shared cluster.
|
|
60131
|
+
*/
|
|
60132
|
+
await (async () => {
|
|
60133
|
+
const collection = datasetCollectionName(config2);
|
|
60134
|
+
const search2 = await resolveDatasetSearch(config2);
|
|
60135
|
+
return collection !== void 0 && search2 !== void 0 && embedder !== void 0 ? { searcher: search2.searcher, embedder, collection } : void 0;
|
|
60136
|
+
})()
|
|
59958
60137
|
);
|
|
59959
60138
|
const turnRegistry = schedule !== void 0 ? registryForSchedule(fullRegistry.list(), schedule) : fullRegistry;
|
|
59960
60139
|
turnOptions.timeoutForTool = toolTimeout;
|
|
@@ -60074,6 +60253,21 @@ function wireChatBridge(services) {
|
|
|
60074
60253
|
}
|
|
60075
60254
|
};
|
|
60076
60255
|
}
|
|
60256
|
+
if (input.authType === "header") {
|
|
60257
|
+
const headers = (input.authHeaders ?? []).map((header) => ({
|
|
60258
|
+
name: header.name.trim(),
|
|
60259
|
+
valueRef: header.valueRef.trim(),
|
|
60260
|
+
...header.prefix !== void 0 && header.prefix.length > 0 ? { prefix: header.prefix } : {}
|
|
60261
|
+
})).filter((header) => header.name.length > 0 && header.valueRef.length > 0);
|
|
60262
|
+
const stored = await Promise.all(headers.map(async (header, index) => {
|
|
60263
|
+
if (describeSecretRef(header.valueRef).kind === "env")
|
|
60264
|
+
return header;
|
|
60265
|
+
const ref = `profile:${id}:header:${String(index)}`;
|
|
60266
|
+
await secrets.set(ref, header.valueRef);
|
|
60267
|
+
return { ...header, valueRef: ref };
|
|
60268
|
+
}));
|
|
60269
|
+
return stored.length > 0 ? { type: "header", headers: stored } : { type: "none" };
|
|
60270
|
+
}
|
|
60077
60271
|
if (input.authType === "tokenCommand") {
|
|
60078
60272
|
if (services.executableAuthRefusal !== void 0)
|
|
60079
60273
|
throw new Error(services.executableAuthRefusal);
|
|
@@ -60699,8 +60893,8 @@ function wireChatBridge(services) {
|
|
|
60699
60893
|
limit: limits.limit,
|
|
60700
60894
|
previewChars: limits.previewChars
|
|
60701
60895
|
});
|
|
60702
|
-
for (const
|
|
60703
|
-
skipped.add(
|
|
60896
|
+
for (const path31 of answer.skipped ?? [])
|
|
60897
|
+
skipped.add(path31);
|
|
60704
60898
|
return { messages: answer.messages, truncated: answer.truncated };
|
|
60705
60899
|
},
|
|
60706
60900
|
...embedder !== void 0 && search !== void 0 && collection !== void 0 ? {
|
|
@@ -60732,6 +60926,206 @@ function wireChatBridge(services) {
|
|
|
60732
60926
|
endIndexing("mail");
|
|
60733
60927
|
}
|
|
60734
60928
|
}
|
|
60929
|
+
const datasetTimers = /* @__PURE__ */ new Map();
|
|
60930
|
+
const datasetBusy = /* @__PURE__ */ new Set();
|
|
60931
|
+
const datasetResults = /* @__PURE__ */ new Map();
|
|
60932
|
+
function datasetStoreFor(id) {
|
|
60933
|
+
return new DatasetStore(storageDir, id);
|
|
60934
|
+
}
|
|
60935
|
+
function datasetCollectionName(config2) {
|
|
60936
|
+
const base = codebaseIndexName(config2);
|
|
60937
|
+
return base === void 0 ? void 0 : `${base}-data`;
|
|
60938
|
+
}
|
|
60939
|
+
async function resolveDatasetSearch(config2, dataset) {
|
|
60940
|
+
const wanted = dataset?.storeId ?? storeIdFor("data", config2);
|
|
60941
|
+
return resolveSearch(config2, wanted);
|
|
60942
|
+
}
|
|
60943
|
+
async function datasetSemantic(config2, dataset) {
|
|
60944
|
+
const collection = datasetCollectionName(config2);
|
|
60945
|
+
const search = await resolveDatasetSearch(config2, dataset);
|
|
60946
|
+
const embedder = await resolveEmbedder(config2);
|
|
60947
|
+
if (collection === void 0 || search === void 0 || embedder === void 0)
|
|
60948
|
+
return void 0;
|
|
60949
|
+
return {
|
|
60950
|
+
embedder,
|
|
60951
|
+
collection,
|
|
60952
|
+
writer: createVectorIndexWriter(httpClient, search.store, await vectorStoreConnectionFor(search.store, search.id)),
|
|
60953
|
+
searcher: search.searcher
|
|
60954
|
+
};
|
|
60955
|
+
}
|
|
60956
|
+
async function runDatasetSync(id, reason) {
|
|
60957
|
+
if (datasetBusy.has(id))
|
|
60958
|
+
return;
|
|
60959
|
+
const config2 = await loadSettings();
|
|
60960
|
+
const dataset = (config2.datasets ?? []).find((entry) => entry.id === id);
|
|
60961
|
+
if (dataset === void 0)
|
|
60962
|
+
return;
|
|
60963
|
+
datasetBusy.add(id);
|
|
60964
|
+
const signal = beginIndexing(`dataset:${id}`);
|
|
60965
|
+
reportIndexing("dataset", `Syncing ${dataset.name}`, { detail: `via ${dataset.toolName}` });
|
|
60966
|
+
try {
|
|
60967
|
+
const semantic = await datasetSemantic(config2, dataset);
|
|
60968
|
+
const result = await syncDataset({
|
|
60969
|
+
datasetId: id,
|
|
60970
|
+
store: datasetStoreFor(id),
|
|
60971
|
+
signal,
|
|
60972
|
+
onProgress: (done, total, phase) => reportIndexing("dataset", phase, { done, total }),
|
|
60973
|
+
...dataset.retentionDays !== void 0 ? { retentionDays: dataset.retentionDays } : {},
|
|
60974
|
+
...semantic !== void 0 ? { semantic: { embedder: semantic.embedder, writer: semantic.writer, collection: semantic.collection } } : {},
|
|
60975
|
+
/*
|
|
60976
|
+
* The collector runs through the ordinary Python tool path, so it is the same code that
|
|
60977
|
+
* validated it, the same worker, the same timeout. A second execution path would be a
|
|
60978
|
+
* second thing to keep in step with tool approval.
|
|
60979
|
+
*/
|
|
60980
|
+
collect: async (since2) => {
|
|
60981
|
+
const registry2 = currentToolRegistry();
|
|
60982
|
+
const tool = registry2.get(dataset.toolName) ?? registry2.get(`py__${dataset.toolName}`);
|
|
60983
|
+
if (tool === void 0) {
|
|
60984
|
+
throw new Error(`The collector tool "${dataset.toolName}" is not registered. A Python tool may have been deleted or Python switched off; an MCP tool may be from a server that is disconnected or disabled. Settings \u2192 Tools lists everything callable.`);
|
|
60985
|
+
}
|
|
60986
|
+
const args = { ...dataset.arguments ?? {}, ...since2 === void 0 ? {} : { since: since2 } };
|
|
60987
|
+
const output = await tool.execute(args, { signal });
|
|
60988
|
+
if (output.isError === true)
|
|
60989
|
+
throw new Error(String(output.content));
|
|
60990
|
+
try {
|
|
60991
|
+
return JSON.parse(typeof output.content === "string" ? output.content : JSON.stringify(output.content));
|
|
60992
|
+
} catch {
|
|
60993
|
+
throw new Error("The collector tool did not return JSON. It must return a list of records \u2014 see the guidance in Settings \u2192 Custom data.");
|
|
60994
|
+
}
|
|
60995
|
+
}
|
|
60996
|
+
});
|
|
60997
|
+
const detail = result.updated === 0 ? `No changes (${reason}). ${String(result.total)} record(s) held.` : `${String(result.updated)} record(s) updated, ${String(result.embedded)} embedded${result.removed > 0 ? `, ${String(result.removed)} removed by retention` : ""}. ${String(result.total)} held.`;
|
|
60998
|
+
datasetResults.set(id, { detail, failed: false, at: Date.now() });
|
|
60999
|
+
reportIndexing("dataset", "Finished", { detail, running: false });
|
|
61000
|
+
} catch (error51) {
|
|
61001
|
+
const stopped = signal.aborted;
|
|
61002
|
+
const detail = stopped ? "Stopped." : error51 instanceof Error ? error51.message : String(error51);
|
|
61003
|
+
datasetResults.set(id, { detail, failed: !stopped, at: Date.now() });
|
|
61004
|
+
if (!stopped)
|
|
61005
|
+
logger.warn(`dataset "${dataset.name}" sync failed: ${detail}`);
|
|
61006
|
+
reportIndexing("dataset", stopped ? "Stopped" : "Failed", { detail, running: false });
|
|
61007
|
+
} finally {
|
|
61008
|
+
datasetBusy.delete(id);
|
|
61009
|
+
endIndexing(`dataset:${id}`);
|
|
61010
|
+
await postDatasetStatus();
|
|
61011
|
+
}
|
|
61012
|
+
}
|
|
61013
|
+
async function handleClearDataset(id, resync) {
|
|
61014
|
+
if (datasetBusy.has(id))
|
|
61015
|
+
return;
|
|
61016
|
+
const config2 = await loadSettings();
|
|
61017
|
+
const dataset = (config2.datasets ?? []).find((entry) => entry.id === id);
|
|
61018
|
+
if (dataset === void 0)
|
|
61019
|
+
return;
|
|
61020
|
+
datasetBusy.add(id);
|
|
61021
|
+
const signal = beginIndexing(`dataset:${id}`);
|
|
61022
|
+
reportIndexing("dataset", `Clearing ${dataset.name}`);
|
|
61023
|
+
try {
|
|
61024
|
+
const semantic = await datasetSemantic(config2, dataset);
|
|
61025
|
+
const { removed } = await clearDataset({
|
|
61026
|
+
datasetId: id,
|
|
61027
|
+
store: datasetStoreFor(id),
|
|
61028
|
+
signal,
|
|
61029
|
+
onProgress: (done, total, phase) => reportIndexing("dataset", phase, { done, total }),
|
|
61030
|
+
...semantic !== void 0 ? { semantic: { writer: semantic.writer, collection: semantic.collection } } : {}
|
|
61031
|
+
});
|
|
61032
|
+
const detail = `Cleared ${String(removed)} record(s).`;
|
|
61033
|
+
datasetResults.set(id, { detail, failed: false, at: Date.now() });
|
|
61034
|
+
reportIndexing("dataset", "Finished", { detail, running: false });
|
|
61035
|
+
} catch (error51) {
|
|
61036
|
+
const detail = error51 instanceof Error ? error51.message : String(error51);
|
|
61037
|
+
datasetResults.set(id, { detail, failed: true, at: Date.now() });
|
|
61038
|
+
logger.warn(`dataset clear failed: ${detail}`);
|
|
61039
|
+
reportIndexing("dataset", "Failed", { detail, running: false });
|
|
61040
|
+
} finally {
|
|
61041
|
+
datasetBusy.delete(id);
|
|
61042
|
+
endIndexing(`dataset:${id}`);
|
|
61043
|
+
await postDatasetStatus();
|
|
61044
|
+
}
|
|
61045
|
+
if (resync)
|
|
61046
|
+
await runDatasetSync(id, "rebuild");
|
|
61047
|
+
}
|
|
61048
|
+
function reconcileDatasetTimers(config2) {
|
|
61049
|
+
for (const timer of datasetTimers.values())
|
|
61050
|
+
clearInterval(timer);
|
|
61051
|
+
datasetTimers.clear();
|
|
61052
|
+
for (const dataset of config2.datasets ?? []) {
|
|
61053
|
+
const minutes = dataset.syncMinutes ?? 0;
|
|
61054
|
+
if (dataset.enabled === false || minutes <= 0)
|
|
61055
|
+
continue;
|
|
61056
|
+
const timer = setInterval(() => void runDatasetSync(dataset.id, "scheduled"), minutes * 60 * 1e3);
|
|
61057
|
+
timer.unref?.();
|
|
61058
|
+
datasetTimers.set(dataset.id, timer);
|
|
61059
|
+
}
|
|
61060
|
+
}
|
|
61061
|
+
async function postDatasetStatus() {
|
|
61062
|
+
const config2 = (await configManager.load()).config;
|
|
61063
|
+
const datasets = config2.datasets ?? [];
|
|
61064
|
+
const collection = datasetCollectionName(config2);
|
|
61065
|
+
const embedder = await resolveEmbedder(config2).catch(() => void 0);
|
|
61066
|
+
const entries = await Promise.all(datasets.map(async (dataset) => {
|
|
61067
|
+
const store = datasetStoreFor(dataset.id);
|
|
61068
|
+
const records = await store.load();
|
|
61069
|
+
const times = records.map((record2) => record2.timestamp).filter((at) => at !== void 0);
|
|
61070
|
+
const search = await resolveDatasetSearch(config2, dataset).catch(() => void 0);
|
|
61071
|
+
return {
|
|
61072
|
+
...dataset,
|
|
61073
|
+
records: records.length,
|
|
61074
|
+
sizeBytes: await store.sizeBytes(),
|
|
61075
|
+
...times.length > 0 ? { oldest: Math.min(...times), newest: Math.max(...times) } : {},
|
|
61076
|
+
...await store.lastSyncedAt() !== void 0 ? { lastSyncedAt: await store.lastSyncedAt() } : {},
|
|
61077
|
+
busy: datasetBusy.has(dataset.id),
|
|
61078
|
+
...datasetResults.get(dataset.id) !== void 0 ? {
|
|
61079
|
+
lastResult: datasetResults.get(dataset.id).detail,
|
|
61080
|
+
lastFailed: datasetResults.get(dataset.id).failed,
|
|
61081
|
+
lastAttemptAt: datasetResults.get(dataset.id).at
|
|
61082
|
+
} : {},
|
|
61083
|
+
storeLabel: search?.store.label ?? "none"
|
|
61084
|
+
};
|
|
61085
|
+
}));
|
|
61086
|
+
post({
|
|
61087
|
+
type: "datasetStatus",
|
|
61088
|
+
datasets: entries,
|
|
61089
|
+
// Said plainly, because a dataset with no embedder still syncs and still searches — on words
|
|
61090
|
+
// rather than meaning — and someone seeing results would otherwise assume it is semantic.
|
|
61091
|
+
semantic: collection !== void 0 && embedder !== void 0,
|
|
61092
|
+
/*
|
|
61093
|
+
* Python tools and MCP tools, selected by what they *are* rather than by group.
|
|
61094
|
+
*
|
|
61095
|
+
* Filtering on `group` was wrong and showed only the built-ins: a Python tool is registered
|
|
61096
|
+
* as `command`, because it runs code, and an MCP tool as `mcp`. Those two groups also hold
|
|
61097
|
+
* `execute_command` and the tool-authoring tools, which are not data sources — so the test
|
|
61098
|
+
* is the `py__` prefix and the mcp group, not a permission category. Reported as the picker
|
|
61099
|
+
* listing only built-in tools.
|
|
61100
|
+
*/
|
|
61101
|
+
tools: currentToolRegistry().list().filter((tool) => tool.name.startsWith("py__") || tool.group === "mcp").map((tool) => ({
|
|
61102
|
+
name: tool.name,
|
|
61103
|
+
description: tool.description,
|
|
61104
|
+
// Grouped in the picker, because "which of these is mine?" is the first question with
|
|
61105
|
+
// forty MCP tools in the list.
|
|
61106
|
+
kind: tool.name.startsWith("py__") ? "python" : "mcp"
|
|
61107
|
+
})),
|
|
61108
|
+
guidance: COLLECTOR_TOOL_GUIDANCE
|
|
61109
|
+
});
|
|
61110
|
+
}
|
|
61111
|
+
async function handleSaveDataset(dataset) {
|
|
61112
|
+
const { config: config2 } = await configManager.load();
|
|
61113
|
+
const existing = config2.datasets ?? [];
|
|
61114
|
+
const next = existing.some((entry) => entry.id === dataset.id) ? existing.map((entry) => entry.id === dataset.id ? dataset : entry) : [...existing, dataset];
|
|
61115
|
+
await configManager.save("user", { datasets: next });
|
|
61116
|
+
reconcileDatasetTimers((await configManager.load()).config);
|
|
61117
|
+
await postDatasetStatus();
|
|
61118
|
+
}
|
|
61119
|
+
async function handleDeleteDataset(id) {
|
|
61120
|
+
const { config: config2 } = await configManager.load();
|
|
61121
|
+
await handleClearDataset(id, false);
|
|
61122
|
+
await configManager.save("user", {
|
|
61123
|
+
datasets: (config2.datasets ?? []).filter((entry) => entry.id !== id)
|
|
61124
|
+
});
|
|
61125
|
+
datasetResults.delete(id);
|
|
61126
|
+
reconcileDatasetTimers((await configManager.load()).config);
|
|
61127
|
+
await postDatasetStatus();
|
|
61128
|
+
}
|
|
60735
61129
|
function reconcileMailTimer(config2) {
|
|
60736
61130
|
if (mailTimer !== void 0) {
|
|
60737
61131
|
clearInterval(mailTimer);
|
|
@@ -60781,9 +61175,9 @@ function wireChatBridge(services) {
|
|
|
60781
61175
|
});
|
|
60782
61176
|
const all = result.folders.map((entry) => entry.path);
|
|
60783
61177
|
const wanted = new Set(chosen);
|
|
60784
|
-
for (const
|
|
60785
|
-
if (chosen.some((root) =>
|
|
60786
|
-
wanted.add(
|
|
61178
|
+
for (const path31 of all) {
|
|
61179
|
+
if (chosen.some((root) => path31 === root || path31.startsWith(`${root}\\`)))
|
|
61180
|
+
wanted.add(path31);
|
|
60787
61181
|
}
|
|
60788
61182
|
return [...wanted];
|
|
60789
61183
|
} catch {
|
|
@@ -61000,6 +61394,7 @@ function wireChatBridge(services) {
|
|
|
61000
61394
|
});
|
|
61001
61395
|
const config2 = await loadSettings();
|
|
61002
61396
|
reconcileMailTimer(config2);
|
|
61397
|
+
reconcileDatasetTimers(config2);
|
|
61003
61398
|
await postMailStatus();
|
|
61004
61399
|
if (config2.mail?.enabled === true)
|
|
61005
61400
|
void runMailSync("just enabled");
|
|
@@ -61278,6 +61673,28 @@ function wireChatBridge(services) {
|
|
|
61278
61673
|
const { config: config2 } = await configManager.load();
|
|
61279
61674
|
const search = await resolveSearch(config2);
|
|
61280
61675
|
const embedder = await resolveEmbedder(config2);
|
|
61676
|
+
if (target === "data") {
|
|
61677
|
+
const datasets = config2.datasets ?? [];
|
|
61678
|
+
const collection = datasetCollectionName(config2);
|
|
61679
|
+
const dataSearch = await resolveDatasetSearch(config2);
|
|
61680
|
+
const tool2 = createSearchDataTool({
|
|
61681
|
+
load: async () => Promise.all(datasets.map(async (dataset) => ({
|
|
61682
|
+
id: dataset.id,
|
|
61683
|
+
name: dataset.name,
|
|
61684
|
+
records: await new DatasetStore(storageDir, dataset.id).load()
|
|
61685
|
+
}))),
|
|
61686
|
+
...collection !== void 0 && dataSearch !== void 0 && embedder !== void 0 ? { semantic: { searcher: dataSearch.searcher, embedder, collection } } : {}
|
|
61687
|
+
});
|
|
61688
|
+
const result2 = await tool2.execute({ query, limit: 25 }, {});
|
|
61689
|
+
post({
|
|
61690
|
+
type: "searchProbe",
|
|
61691
|
+
target,
|
|
61692
|
+
query,
|
|
61693
|
+
text: result2.content,
|
|
61694
|
+
...result2.isError === true ? { error: "The search failed." } : {}
|
|
61695
|
+
});
|
|
61696
|
+
return;
|
|
61697
|
+
}
|
|
61281
61698
|
if (target === "mail") {
|
|
61282
61699
|
const collection = mailCollectionName(config2);
|
|
61283
61700
|
const mailSearch = await resolveMailSearch(config2);
|
|
@@ -62469,6 +62886,7 @@ function wireChatBridge(services) {
|
|
|
62469
62886
|
} else if (message3.type === "requestMailStatus") {
|
|
62470
62887
|
void loadSettings().then((config2) => {
|
|
62471
62888
|
reconcileMailTimer(config2);
|
|
62889
|
+
reconcileDatasetTimers(config2);
|
|
62472
62890
|
return postMailStatus();
|
|
62473
62891
|
});
|
|
62474
62892
|
} else if (message3.type === "saveMailSettings") {
|
|
@@ -62484,6 +62902,16 @@ function wireChatBridge(services) {
|
|
|
62484
62902
|
void handleClearTeamSkills();
|
|
62485
62903
|
} else if (message3.type === "refreshMail") {
|
|
62486
62904
|
void handleRefreshMail(message3.days);
|
|
62905
|
+
} else if (message3.type === "requestDatasetStatus") {
|
|
62906
|
+
void postDatasetStatus();
|
|
62907
|
+
} else if (message3.type === "saveDataset") {
|
|
62908
|
+
void handleSaveDataset(message3.dataset);
|
|
62909
|
+
} else if (message3.type === "deleteDataset") {
|
|
62910
|
+
void handleDeleteDataset(message3.id);
|
|
62911
|
+
} else if (message3.type === "syncDataset") {
|
|
62912
|
+
void runDatasetSync(message3.id, "manual");
|
|
62913
|
+
} else if (message3.type === "clearDataset") {
|
|
62914
|
+
void handleClearDataset(message3.id, message3.resync === true);
|
|
62487
62915
|
} else if (message3.type === "clearMailIndex") {
|
|
62488
62916
|
void handleClearMailIndex(message3.resync === true);
|
|
62489
62917
|
} else if (message3.type === "saveSkillsAlias") {
|
|
@@ -63888,10 +64316,10 @@ function readSmall(raw, params) {
|
|
|
63888
64316
|
const end = params.limit !== void 0 ? start + params.limit : lines.length;
|
|
63889
64317
|
return number4(lines.slice(start, end), start + 1);
|
|
63890
64318
|
}
|
|
63891
|
-
async function readLarge(
|
|
64319
|
+
async function readLarge(fs25, realPath, params, size) {
|
|
63892
64320
|
const human = formatBytes(size);
|
|
63893
64321
|
if (params.tail !== void 0) {
|
|
63894
|
-
const part = await readTail(
|
|
64322
|
+
const part = await readTail(fs25, realPath, size, params.tail);
|
|
63895
64323
|
return [
|
|
63896
64324
|
`${human} file \u2014 last ${String(part.lines.length)} lines.`,
|
|
63897
64325
|
/*
|
|
@@ -63906,7 +64334,7 @@ async function readLarge(fs24, realPath, params, size) {
|
|
|
63906
64334
|
}
|
|
63907
64335
|
if (params.offset !== void 0) {
|
|
63908
64336
|
const limit = params.limit ?? DEFAULT_LARGE_LIMIT;
|
|
63909
|
-
const part = await readLineWindow(
|
|
64337
|
+
const part = await readLineWindow(fs25, realPath, size, params.offset, limit);
|
|
63910
64338
|
const shown = part.lines.length;
|
|
63911
64339
|
return [
|
|
63912
64340
|
`${human} file \u2014 lines ${String(params.offset)}\u2013${String(params.offset + shown - 1)}${part.hasMoreAfter ? ", more follows" : " (end of file)"}.`,
|
|
@@ -63914,7 +64342,7 @@ async function readLarge(fs24, realPath, params, size) {
|
|
|
63914
64342
|
number4(part.lines, params.offset)
|
|
63915
64343
|
].join("\n");
|
|
63916
64344
|
}
|
|
63917
|
-
const total = await countLines(
|
|
64345
|
+
const total = await countLines(fs25, realPath, size);
|
|
63918
64346
|
return [
|
|
63919
64347
|
`${realPathName(realPath)} is ${human} (${total.toLocaleString()} lines) \u2014 too large to read at once.`,
|
|
63920
64348
|
"",
|
|
@@ -64113,6 +64541,334 @@ function createDefaultToolRegistry() {
|
|
|
64113
64541
|
return registry2;
|
|
64114
64542
|
}
|
|
64115
64543
|
|
|
64544
|
+
// ../../packages/core/dist/dataset/store.js
|
|
64545
|
+
import fs19 from "node:fs/promises";
|
|
64546
|
+
import path25 from "node:path";
|
|
64547
|
+
var DatasetStore = class {
|
|
64548
|
+
filePath;
|
|
64549
|
+
statePath;
|
|
64550
|
+
constructor(storageDir, datasetId) {
|
|
64551
|
+
const safe = datasetId.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
64552
|
+
this.filePath = path25.join(storageDir, "datasets", `${safe}.jsonl`);
|
|
64553
|
+
this.statePath = path25.join(storageDir, "datasets", `${safe}.state.json`);
|
|
64554
|
+
}
|
|
64555
|
+
/** Every record. A malformed line is skipped — one bad line costs one record, not the corpus. */
|
|
64556
|
+
async load() {
|
|
64557
|
+
let raw;
|
|
64558
|
+
try {
|
|
64559
|
+
raw = await fs19.readFile(this.filePath, "utf8");
|
|
64560
|
+
} catch {
|
|
64561
|
+
return [];
|
|
64562
|
+
}
|
|
64563
|
+
const byId = /* @__PURE__ */ new Map();
|
|
64564
|
+
for (const line of raw.split("\n")) {
|
|
64565
|
+
const trimmed = line.trim();
|
|
64566
|
+
if (trimmed.length === 0)
|
|
64567
|
+
continue;
|
|
64568
|
+
try {
|
|
64569
|
+
const parsed = JSON.parse(trimmed);
|
|
64570
|
+
if (typeof parsed.id === "string" && typeof parsed.text === "string")
|
|
64571
|
+
byId.set(parsed.id, parsed);
|
|
64572
|
+
} catch {
|
|
64573
|
+
}
|
|
64574
|
+
}
|
|
64575
|
+
return [...byId.values()];
|
|
64576
|
+
}
|
|
64577
|
+
/** Appends. Re-appending an existing id is how an update is recorded — see `load`. */
|
|
64578
|
+
async append(records) {
|
|
64579
|
+
if (records.length === 0)
|
|
64580
|
+
return;
|
|
64581
|
+
await fs19.mkdir(path25.dirname(this.filePath), { recursive: true });
|
|
64582
|
+
await fs19.writeFile(this.filePath, "", { flag: "a" });
|
|
64583
|
+
const lines = records.map((record2) => JSON.stringify(record2)).join("\n");
|
|
64584
|
+
await fs19.appendFile(this.filePath, `${lines}
|
|
64585
|
+
`, "utf8");
|
|
64586
|
+
}
|
|
64587
|
+
/** Rewrites with exactly these. Temp-and-rename, so an interrupted prune leaves the old file. */
|
|
64588
|
+
async replace(records) {
|
|
64589
|
+
await fs19.mkdir(path25.dirname(this.filePath), { recursive: true });
|
|
64590
|
+
const temporary = `${this.filePath}.tmp`;
|
|
64591
|
+
const body = records.map((record2) => JSON.stringify(record2)).join("\n");
|
|
64592
|
+
await fs19.writeFile(temporary, records.length === 0 ? "" : `${body}
|
|
64593
|
+
`, "utf8");
|
|
64594
|
+
await fs19.rename(temporary, this.filePath);
|
|
64595
|
+
}
|
|
64596
|
+
/**
|
|
64597
|
+
* Rewrites the file with the duplicates collapsed.
|
|
64598
|
+
*
|
|
64599
|
+
* Append-as-upsert means a record updated every hour adds a line every hour, so the file grows
|
|
64600
|
+
* with the *number of syncs* rather than the size of the corpus. Compaction is cheap and only
|
|
64601
|
+
* worth doing when it would actually shrink anything, which the caller decides.
|
|
64602
|
+
*/
|
|
64603
|
+
async compact() {
|
|
64604
|
+
let before;
|
|
64605
|
+
try {
|
|
64606
|
+
before = (await fs19.readFile(this.filePath, "utf8")).split("\n").filter((line) => line.trim().length > 0).length;
|
|
64607
|
+
} catch {
|
|
64608
|
+
return { before: 0, after: 0 };
|
|
64609
|
+
}
|
|
64610
|
+
const records = await this.load();
|
|
64611
|
+
if (records.length === before)
|
|
64612
|
+
return { before, after: before };
|
|
64613
|
+
await this.replace(records);
|
|
64614
|
+
return { before, after: records.length };
|
|
64615
|
+
}
|
|
64616
|
+
async clear() {
|
|
64617
|
+
await fs19.rm(this.filePath, { force: true });
|
|
64618
|
+
await fs19.rm(this.statePath, { force: true });
|
|
64619
|
+
}
|
|
64620
|
+
async sizeBytes() {
|
|
64621
|
+
try {
|
|
64622
|
+
return (await fs19.stat(this.filePath)).size;
|
|
64623
|
+
} catch {
|
|
64624
|
+
return 0;
|
|
64625
|
+
}
|
|
64626
|
+
}
|
|
64627
|
+
/**
|
|
64628
|
+
* When the last successful sync finished, passed to the collector as `since`.
|
|
64629
|
+
*
|
|
64630
|
+
* Written only on success, deliberately: after a failed run the next one must ask for the same
|
|
64631
|
+
* window again, or whatever the source produced while it was broken is skipped for ever with
|
|
64632
|
+
* nothing anywhere recording the gap.
|
|
64633
|
+
*/
|
|
64634
|
+
async lastSyncedAt() {
|
|
64635
|
+
try {
|
|
64636
|
+
const parsed = JSON.parse(await fs19.readFile(this.statePath, "utf8"));
|
|
64637
|
+
return typeof parsed.lastSyncedAt === "number" ? parsed.lastSyncedAt : void 0;
|
|
64638
|
+
} catch {
|
|
64639
|
+
return void 0;
|
|
64640
|
+
}
|
|
64641
|
+
}
|
|
64642
|
+
async recordSync(at) {
|
|
64643
|
+
await fs19.mkdir(path25.dirname(this.statePath), { recursive: true });
|
|
64644
|
+
const temporary = `${this.statePath}.tmp`;
|
|
64645
|
+
await fs19.writeFile(temporary, JSON.stringify({ lastSyncedAt: at }), "utf8");
|
|
64646
|
+
await fs19.rename(temporary, this.statePath);
|
|
64647
|
+
}
|
|
64648
|
+
};
|
|
64649
|
+
function partitionByAge(records, cutoff) {
|
|
64650
|
+
const kept = [];
|
|
64651
|
+
const removed = [];
|
|
64652
|
+
for (const record2 of records) {
|
|
64653
|
+
if (record2.timestamp !== void 0 && record2.timestamp < cutoff)
|
|
64654
|
+
removed.push(record2);
|
|
64655
|
+
else
|
|
64656
|
+
kept.push(record2);
|
|
64657
|
+
}
|
|
64658
|
+
return { kept, removed };
|
|
64659
|
+
}
|
|
64660
|
+
|
|
64661
|
+
// ../../packages/core/dist/dataset/sync.js
|
|
64662
|
+
function datasetEmbedText(record2) {
|
|
64663
|
+
return [record2.title, record2.text].filter((part) => part !== void 0 && part.length > 0).join("\n");
|
|
64664
|
+
}
|
|
64665
|
+
function datasetVectorId(datasetId, recordId) {
|
|
64666
|
+
return `data:${datasetId}:${recordId}`;
|
|
64667
|
+
}
|
|
64668
|
+
async function syncDataset(options) {
|
|
64669
|
+
const now = options.now ?? Date.now();
|
|
64670
|
+
const held = await options.store.load();
|
|
64671
|
+
const heldById = new Map(held.map((record2) => [record2.id, record2]));
|
|
64672
|
+
options.onProgress?.(0, 0, "Running the collector");
|
|
64673
|
+
const since2 = await options.store.lastSyncedAt();
|
|
64674
|
+
const payload = await options.collect(since2);
|
|
64675
|
+
const parsed = parseDatasetPayload(payload);
|
|
64676
|
+
if ("error" in parsed)
|
|
64677
|
+
throw new Error(parsed.error);
|
|
64678
|
+
const collected = parsed.records;
|
|
64679
|
+
const changed = collected.filter((record2) => {
|
|
64680
|
+
const existing = heldById.get(record2.id);
|
|
64681
|
+
return existing === void 0 || JSON.stringify(existing) !== JSON.stringify(record2);
|
|
64682
|
+
});
|
|
64683
|
+
let embedded = 0;
|
|
64684
|
+
if (options.semantic !== void 0 && changed.length > 0) {
|
|
64685
|
+
const { embedder, writer, collection } = options.semantic;
|
|
64686
|
+
await writer.ensureCollection(collection, embedder.dimensions, options.signal);
|
|
64687
|
+
const documents = [];
|
|
64688
|
+
for (const record2 of changed) {
|
|
64689
|
+
if (options.signal?.aborted === true)
|
|
64690
|
+
throw new Error("Stopped.");
|
|
64691
|
+
options.onProgress?.(documents.length, changed.length, "Embedding new and changed records");
|
|
64692
|
+
const existing = heldById.get(record2.id);
|
|
64693
|
+
if (existing !== void 0 && datasetEmbedText(existing) === datasetEmbedText(record2))
|
|
64694
|
+
continue;
|
|
64695
|
+
const text = datasetEmbedText(record2);
|
|
64696
|
+
if (text.trim().length === 0)
|
|
64697
|
+
continue;
|
|
64698
|
+
documents.push({
|
|
64699
|
+
id: datasetVectorId(options.datasetId, record2.id),
|
|
64700
|
+
text,
|
|
64701
|
+
// The id travels in `path`, which is how a hit is joined back to its record.
|
|
64702
|
+
path: datasetVectorId(options.datasetId, record2.id),
|
|
64703
|
+
startLine: 1,
|
|
64704
|
+
endLine: 1,
|
|
64705
|
+
vector: await embedder.embed(text)
|
|
64706
|
+
});
|
|
64707
|
+
}
|
|
64708
|
+
if (documents.length > 0) {
|
|
64709
|
+
await writer.upsert(collection, documents, options.signal);
|
|
64710
|
+
embedded = documents.length;
|
|
64711
|
+
}
|
|
64712
|
+
}
|
|
64713
|
+
if (changed.length > 0)
|
|
64714
|
+
await options.store.append(changed);
|
|
64715
|
+
let removed = 0;
|
|
64716
|
+
if (options.retentionDays !== void 0) {
|
|
64717
|
+
const cutoff = now - options.retentionDays * 24 * 60 * 60 * 1e3;
|
|
64718
|
+
const after = await options.store.load();
|
|
64719
|
+
const { kept, removed: old } = partitionByAge(after, cutoff);
|
|
64720
|
+
if (old.length > 0) {
|
|
64721
|
+
options.onProgress?.(0, old.length, "Removing records past retention");
|
|
64722
|
+
if (options.semantic !== void 0) {
|
|
64723
|
+
await options.semantic.writer.deleteByPaths(options.semantic.collection, old.map((record2) => datasetVectorId(options.datasetId, record2.id)), options.signal);
|
|
64724
|
+
}
|
|
64725
|
+
await options.store.replace(kept);
|
|
64726
|
+
removed = old.length;
|
|
64727
|
+
}
|
|
64728
|
+
}
|
|
64729
|
+
await options.store.compact();
|
|
64730
|
+
await options.store.recordSync(now);
|
|
64731
|
+
const total = (await options.store.load()).length;
|
|
64732
|
+
return { collected: collected.length, updated: changed.length, embedded, removed, total };
|
|
64733
|
+
}
|
|
64734
|
+
async function clearDataset(options) {
|
|
64735
|
+
const held = await options.store.load();
|
|
64736
|
+
if (options.semantic !== void 0 && held.length > 0) {
|
|
64737
|
+
const size = 500;
|
|
64738
|
+
const paths = held.map((record2) => datasetVectorId(options.datasetId, record2.id));
|
|
64739
|
+
for (let start = 0; start < paths.length; start += size) {
|
|
64740
|
+
if (options.signal?.aborted === true)
|
|
64741
|
+
throw new Error("Stopped.");
|
|
64742
|
+
options.onProgress?.(Math.min(start + size, paths.length), paths.length, "Removing vectors");
|
|
64743
|
+
await options.semantic.writer.deleteByPaths(options.semantic.collection, paths.slice(start, start + size), options.signal);
|
|
64744
|
+
}
|
|
64745
|
+
}
|
|
64746
|
+
await options.store.clear();
|
|
64747
|
+
return { removed: held.length };
|
|
64748
|
+
}
|
|
64749
|
+
|
|
64750
|
+
// ../../packages/core/dist/tools/searchData.js
|
|
64751
|
+
var searchSchema3 = external_exports.object({
|
|
64752
|
+
dataset: external_exports.string().optional().describe("Which dataset to search, by name. Omit to search all of them."),
|
|
64753
|
+
query: external_exports.string().optional().describe("Rank by meaning. Omit to get the most recent records in the window."),
|
|
64754
|
+
withinDays: external_exports.number().min(0.01).optional().describe("Only records with a timestamp this recent. Records with no timestamp are excluded."),
|
|
64755
|
+
contains: external_exports.string().optional().describe("Only records whose title or text contains this text. Exact, case-insensitive."),
|
|
64756
|
+
tag: external_exports.string().optional().describe("Filter on a tag, as `name=value`. Exact."),
|
|
64757
|
+
limit: external_exports.number().int().min(1).max(50).optional().describe("How many to return. Default 15.")
|
|
64758
|
+
});
|
|
64759
|
+
function describe4(record2, dataset) {
|
|
64760
|
+
const when = record2.timestamp === void 0 ? "" : `${new Date(record2.timestamp).toLocaleString()} `;
|
|
64761
|
+
const heading = record2.title ?? record2.text.trim().split("\n")[0]?.slice(0, 100) ?? record2.id;
|
|
64762
|
+
const body = record2.text.trim().slice(0, 400);
|
|
64763
|
+
return `${when}[${dataset}] ${heading}
|
|
64764
|
+
id: ${record2.id}${record2.url === void 0 ? "" : ` ${record2.url}`}
|
|
64765
|
+
${body}`;
|
|
64766
|
+
}
|
|
64767
|
+
function createSearchDataTool(options) {
|
|
64768
|
+
return {
|
|
64769
|
+
name: "search_data",
|
|
64770
|
+
group: "read",
|
|
64771
|
+
description: "Searches the custom datasets the user collects with their own Python tools \u2014 tickets, wiki pages, rows from an internal system, whatever they have set up. Use it whenever a question is about the organisation's own data rather than about this codebase. `dataset` picks one by name, `withinDays` and `tag` are exact filters applied before any ranking, and `query` ranks what is left by meaning. Call it with no arguments to see what is there. These are exact counts over what has been synced, not a live query against the source \u2014 so the answer is only as current as the last sync, which is reported.",
|
|
64772
|
+
parametersSchema: searchSchema3,
|
|
64773
|
+
execute: async (params) => {
|
|
64774
|
+
try {
|
|
64775
|
+
const datasets = await options.load();
|
|
64776
|
+
if (datasets.length === 0) {
|
|
64777
|
+
return {
|
|
64778
|
+
content: "No custom datasets are configured, so there is nothing to search. The user sets these up in Settings \u2192 Custom data, by pointing at a Python tool that returns records. Say that rather than reporting that nothing was found."
|
|
64779
|
+
};
|
|
64780
|
+
}
|
|
64781
|
+
const wanted = params.dataset === void 0 ? datasets : datasets.filter((entry) => entry.name.toLowerCase() === params.dataset?.toLowerCase());
|
|
64782
|
+
if (wanted.length === 0) {
|
|
64783
|
+
return {
|
|
64784
|
+
content: `There is no dataset called "${params.dataset ?? ""}". Configured: ${datasets.map((entry) => entry.name).join(", ")}.`,
|
|
64785
|
+
isError: true
|
|
64786
|
+
};
|
|
64787
|
+
}
|
|
64788
|
+
let candidates = wanted.flatMap((entry) => entry.records.map((record2) => ({ dataset: entry.name, datasetId: entry.id, record: record2 })));
|
|
64789
|
+
const narrowed = [];
|
|
64790
|
+
if (params.withinDays !== void 0) {
|
|
64791
|
+
const cutoff = Date.now() - params.withinDays * 24 * 60 * 60 * 1e3;
|
|
64792
|
+
candidates = candidates.filter((entry) => entry.record.timestamp !== void 0 && entry.record.timestamp >= cutoff);
|
|
64793
|
+
narrowed.push(`in the last ${String(params.withinDays)} day(s)`);
|
|
64794
|
+
}
|
|
64795
|
+
if (params.tag !== void 0) {
|
|
64796
|
+
const [name, value] = params.tag.split("=");
|
|
64797
|
+
candidates = candidates.filter((entry) => value === void 0 ? entry.record.tags?.[name ?? ""] !== void 0 : entry.record.tags?.[name ?? ""] === value);
|
|
64798
|
+
narrowed.push(`tagged ${params.tag}`);
|
|
64799
|
+
}
|
|
64800
|
+
if (params.contains !== void 0) {
|
|
64801
|
+
const needle = params.contains.toLowerCase();
|
|
64802
|
+
candidates = candidates.filter((entry) => `${entry.record.title ?? ""}
|
|
64803
|
+
${entry.record.text}`.toLowerCase().includes(needle));
|
|
64804
|
+
narrowed.push(`containing "${params.contains}"`);
|
|
64805
|
+
}
|
|
64806
|
+
const criteria = narrowed.length === 0 ? "" : `, ${narrowed.join(", ")}`;
|
|
64807
|
+
if (candidates.length === 0) {
|
|
64808
|
+
return {
|
|
64809
|
+
content: `Nothing in ${wanted.map((entry) => entry.name).join(", ")}${criteria}. This is an exact answer over what has been synced \u2014 but it is only as current as the last sync.`
|
|
64810
|
+
};
|
|
64811
|
+
}
|
|
64812
|
+
const limit = params.limit ?? 15;
|
|
64813
|
+
let ordered = candidates.sort((a, b) => (b.record.timestamp ?? 0) - (a.record.timestamp ?? 0));
|
|
64814
|
+
let how = "";
|
|
64815
|
+
const asked = params.query?.trim() ?? "";
|
|
64816
|
+
if (asked.length > 0 && options.semantic === void 0) {
|
|
64817
|
+
const words = asked.toLowerCase().split(/\s+/).filter((word) => word.length > 2);
|
|
64818
|
+
const needle = asked.toLowerCase();
|
|
64819
|
+
candidates = candidates.filter((entry) => {
|
|
64820
|
+
const haystack = `${entry.record.title ?? ""}
|
|
64821
|
+
${entry.record.text}`.toLowerCase();
|
|
64822
|
+
return words.length === 0 ? haystack.includes(needle) : words.some((word) => haystack.includes(word));
|
|
64823
|
+
});
|
|
64824
|
+
if (candidates.length === 0) {
|
|
64825
|
+
return {
|
|
64826
|
+
content: `Nothing in ${wanted.map((entry) => entry.name).join(", ")}${criteria} mentions "${asked}". No embedding model is configured, so this was matched on words rather than meaning \u2014 something saying the same thing differently would not be found.`
|
|
64827
|
+
};
|
|
64828
|
+
}
|
|
64829
|
+
ordered = candidates;
|
|
64830
|
+
how = " matched on words, not meaning \u2014 no embedding model is configured";
|
|
64831
|
+
}
|
|
64832
|
+
if (asked.length > 0 && options.semantic !== void 0) {
|
|
64833
|
+
const vector = await options.semantic.embedder.embed(asked);
|
|
64834
|
+
const hits = await options.semantic.searcher.searchByVector(options.semantic.collection, vector, {
|
|
64835
|
+
size: Math.min(100, Math.max(limit * 4, 40))
|
|
64836
|
+
});
|
|
64837
|
+
const rank2 = /* @__PURE__ */ new Map();
|
|
64838
|
+
hits.forEach((hit, position) => {
|
|
64839
|
+
if (!rank2.has(hit.path))
|
|
64840
|
+
rank2.set(hit.path, position);
|
|
64841
|
+
});
|
|
64842
|
+
ordered = [...candidates].sort((a, b) => {
|
|
64843
|
+
const left = rank2.get(`data:${a.datasetId}:${a.record.id}`);
|
|
64844
|
+
const right = rank2.get(`data:${b.datasetId}:${b.record.id}`);
|
|
64845
|
+
if (left !== void 0 && right !== void 0)
|
|
64846
|
+
return left - right;
|
|
64847
|
+
if (left !== void 0)
|
|
64848
|
+
return -1;
|
|
64849
|
+
if (right !== void 0)
|
|
64850
|
+
return 1;
|
|
64851
|
+
return (b.record.timestamp ?? 0) - (a.record.timestamp ?? 0);
|
|
64852
|
+
});
|
|
64853
|
+
how = " ranked by meaning";
|
|
64854
|
+
}
|
|
64855
|
+
const shown = ordered.slice(0, limit);
|
|
64856
|
+
return {
|
|
64857
|
+
content: [
|
|
64858
|
+
`${String(candidates.length)} record(s) in ${wanted.map((entry) => entry.name).join(", ")}${criteria}${how}${candidates.length > shown.length ? `, showing ${String(shown.length)}` : ""}:`,
|
|
64859
|
+
"",
|
|
64860
|
+
...shown.map((entry) => describe4(entry.record, entry.dataset)),
|
|
64861
|
+
"",
|
|
64862
|
+
"This is what has been synced, not a live query against the source. If the answer depends on something very recent, say when the dataset was last synced rather than implying it is current."
|
|
64863
|
+
].join("\n")
|
|
64864
|
+
};
|
|
64865
|
+
} catch (error51) {
|
|
64866
|
+
return { content: error51 instanceof Error ? error51.message : String(error51), isError: true };
|
|
64867
|
+
}
|
|
64868
|
+
}
|
|
64869
|
+
};
|
|
64870
|
+
}
|
|
64871
|
+
|
|
64116
64872
|
// src/identity.ts
|
|
64117
64873
|
import crypto5 from "node:crypto";
|
|
64118
64874
|
var SingleUserIdentity = class _SingleUserIdentity {
|
|
@@ -64123,13 +64879,36 @@ var SingleUserIdentity = class _SingleUserIdentity {
|
|
|
64123
64879
|
/**
|
|
64124
64880
|
* Single-use and short-lived, because it travels in the launch URL's fragment where it
|
|
64125
64881
|
* can end up in shell history or a terminal scrollback (§14).
|
|
64882
|
+
*
|
|
64883
|
+
* Ten seconds is right when the browser opens itself, and far too short when a person has to
|
|
64884
|
+
* move the URL by hand — into another application, a remote session, a phone. `--handoff-seconds`
|
|
64885
|
+
* raises it, and what that costs is stated where it is set: a longer window is a longer time in
|
|
64886
|
+
* which somebody reading that scrollback can use it before you do.
|
|
64126
64887
|
*/
|
|
64127
64888
|
handoffToken = crypto5.randomBytes(32).toString("base64url");
|
|
64128
|
-
handoffExpiresAt
|
|
64889
|
+
handoffExpiresAt;
|
|
64890
|
+
handoffSeconds;
|
|
64891
|
+
constructor(handoffSeconds = 10) {
|
|
64892
|
+
this.handoffSeconds = handoffSeconds;
|
|
64893
|
+
this.handoffExpiresAt = Date.now() + handoffSeconds * 1e3;
|
|
64894
|
+
}
|
|
64129
64895
|
get launchToken() {
|
|
64130
64896
|
if (this.handoffToken === void 0) throw new Error("handoff token already consumed");
|
|
64131
64897
|
return this.handoffToken;
|
|
64132
64898
|
}
|
|
64899
|
+
/**
|
|
64900
|
+
* Mints a fresh handoff token, replacing any outstanding one.
|
|
64901
|
+
*
|
|
64902
|
+
* For the case the old design had no answer to: the token expired unused, and the only way back
|
|
64903
|
+
* was to stop the server and start it again — losing the session, the conversation and anything
|
|
64904
|
+
* running. A new token grants exactly what the first one did, to whoever can read the terminal,
|
|
64905
|
+
* which is the same person it was printed to in the first place.
|
|
64906
|
+
*/
|
|
64907
|
+
remintHandoff() {
|
|
64908
|
+
this.handoffToken = crypto5.randomBytes(32).toString("base64url");
|
|
64909
|
+
this.handoffExpiresAt = Date.now() + this.handoffSeconds * 1e3;
|
|
64910
|
+
return this.handoffToken;
|
|
64911
|
+
}
|
|
64133
64912
|
/**
|
|
64134
64913
|
* Exchanges the handoff token for the session token, once.
|
|
64135
64914
|
*
|
|
@@ -64137,11 +64916,23 @@ var SingleUserIdentity = class _SingleUserIdentity {
|
|
|
64137
64916
|
* or an attack, and in both cases the right answer is that this token is now spent.
|
|
64138
64917
|
*/
|
|
64139
64918
|
redeemHandoff(presented) {
|
|
64919
|
+
return this.redeem(presented).token;
|
|
64920
|
+
}
|
|
64921
|
+
/**
|
|
64922
|
+
* The same exchange, saying *why* it failed.
|
|
64923
|
+
*
|
|
64924
|
+
* The reasons need different handling and only one of them is anybody's fault. An expired token
|
|
64925
|
+
* is an ordinary mishap — the browser was slow, the URL was pasted late — and the right response
|
|
64926
|
+
* is to offer another. A token that does not match is either a bug or an attack, and the right
|
|
64927
|
+
* response there is nothing at all.
|
|
64928
|
+
*/
|
|
64929
|
+
redeem(presented) {
|
|
64140
64930
|
const expected = this.handoffToken;
|
|
64141
64931
|
const expiresAt = this.handoffExpiresAt;
|
|
64142
64932
|
this.handoffToken = void 0;
|
|
64143
|
-
if (expected === void 0
|
|
64144
|
-
|
|
64933
|
+
if (expected === void 0) return { reason: "spent" };
|
|
64934
|
+
if (Date.now() > expiresAt) return { reason: "expired" };
|
|
64935
|
+
return timingSafeEquals(presented, expected) ? { token: this.sessionToken } : { reason: "mismatch" };
|
|
64145
64936
|
}
|
|
64146
64937
|
async authenticate(request) {
|
|
64147
64938
|
const header = request.headers.authorization;
|
|
@@ -64353,8 +65144,8 @@ async function readJsonBody(request, maxBytes = 32 * 1024 * 1024) {
|
|
|
64353
65144
|
}
|
|
64354
65145
|
|
|
64355
65146
|
// src/fileSecretStore.ts
|
|
64356
|
-
import
|
|
64357
|
-
import
|
|
65147
|
+
import fs20 from "node:fs/promises";
|
|
65148
|
+
import path26 from "node:path";
|
|
64358
65149
|
var FileSecretStore = class {
|
|
64359
65150
|
constructor(filePath) {
|
|
64360
65151
|
this.filePath = filePath;
|
|
@@ -64366,7 +65157,7 @@ var FileSecretStore = class {
|
|
|
64366
65157
|
async load() {
|
|
64367
65158
|
if (this.cache !== void 0) return this.cache;
|
|
64368
65159
|
try {
|
|
64369
|
-
const raw = await
|
|
65160
|
+
const raw = await fs20.readFile(this.filePath, "utf8");
|
|
64370
65161
|
const parsed = JSON.parse(raw);
|
|
64371
65162
|
this.cache = typeof parsed === "object" && parsed !== null ? parsed : {};
|
|
64372
65163
|
} catch {
|
|
@@ -64378,10 +65169,10 @@ var FileSecretStore = class {
|
|
|
64378
65169
|
this.queue = this.queue.then(async () => {
|
|
64379
65170
|
const secrets = await this.load();
|
|
64380
65171
|
mutate(secrets);
|
|
64381
|
-
await
|
|
65172
|
+
await fs20.mkdir(path26.dirname(this.filePath), { recursive: true });
|
|
64382
65173
|
const temp = `${this.filePath}.${process.pid}.tmp`;
|
|
64383
|
-
await
|
|
64384
|
-
await
|
|
65174
|
+
await fs20.writeFile(temp, JSON.stringify(secrets, null, 2), { encoding: "utf8", mode: 384 });
|
|
65175
|
+
await fs20.rename(temp, this.filePath);
|
|
64385
65176
|
});
|
|
64386
65177
|
return this.queue;
|
|
64387
65178
|
}
|
|
@@ -64412,8 +65203,8 @@ var FileSecretStore = class {
|
|
|
64412
65203
|
|
|
64413
65204
|
// src/reviewQueue.ts
|
|
64414
65205
|
import crypto6 from "node:crypto";
|
|
64415
|
-
import
|
|
64416
|
-
import
|
|
65206
|
+
import fs21 from "node:fs/promises";
|
|
65207
|
+
import path27 from "node:path";
|
|
64417
65208
|
var ReviewQueue = class {
|
|
64418
65209
|
constructor(filePath) {
|
|
64419
65210
|
this.filePath = filePath;
|
|
@@ -64423,7 +65214,7 @@ var ReviewQueue = class {
|
|
|
64423
65214
|
async load() {
|
|
64424
65215
|
if (this.cache !== void 0) return this.cache;
|
|
64425
65216
|
try {
|
|
64426
|
-
const parsed = JSON.parse(await
|
|
65217
|
+
const parsed = JSON.parse(await fs21.readFile(this.filePath, "utf8"));
|
|
64427
65218
|
this.cache = Array.isArray(parsed) ? parsed : [];
|
|
64428
65219
|
} catch {
|
|
64429
65220
|
this.cache = [];
|
|
@@ -64432,10 +65223,10 @@ var ReviewQueue = class {
|
|
|
64432
65223
|
}
|
|
64433
65224
|
async persist(items) {
|
|
64434
65225
|
this.cache = items;
|
|
64435
|
-
await
|
|
65226
|
+
await fs21.mkdir(path27.dirname(this.filePath), { recursive: true });
|
|
64436
65227
|
const temporary = `${this.filePath}.tmp`;
|
|
64437
|
-
await
|
|
64438
|
-
await
|
|
65228
|
+
await fs21.writeFile(temporary, JSON.stringify(items, null, 2), { encoding: "utf8", mode: 384 });
|
|
65229
|
+
await fs21.rename(temporary, this.filePath);
|
|
64439
65230
|
}
|
|
64440
65231
|
async list() {
|
|
64441
65232
|
return [...await this.load()];
|
|
@@ -64590,9 +65381,9 @@ var RoutedSecretStore = class {
|
|
|
64590
65381
|
};
|
|
64591
65382
|
|
|
64592
65383
|
// src/userVariables.ts
|
|
64593
|
-
import
|
|
65384
|
+
import fs22 from "node:fs/promises";
|
|
64594
65385
|
import { readFileSync } from "node:fs";
|
|
64595
|
-
import
|
|
65386
|
+
import path28 from "node:path";
|
|
64596
65387
|
var UserVariableStore = class {
|
|
64597
65388
|
constructor(filePath) {
|
|
64598
65389
|
this.filePath = filePath;
|
|
@@ -64607,21 +65398,21 @@ var UserVariableStore = class {
|
|
|
64607
65398
|
}
|
|
64608
65399
|
async save(variables) {
|
|
64609
65400
|
const parsed = sessionVariablesSchema.parse(variables);
|
|
64610
|
-
await
|
|
65401
|
+
await fs22.mkdir(path28.dirname(this.filePath), { recursive: true });
|
|
64611
65402
|
const temporary = `${this.filePath}.tmp`;
|
|
64612
|
-
await
|
|
65403
|
+
await fs22.writeFile(temporary, JSON.stringify({ variables: parsed }, null, 2), {
|
|
64613
65404
|
encoding: "utf8",
|
|
64614
65405
|
mode: 384
|
|
64615
65406
|
});
|
|
64616
|
-
await
|
|
65407
|
+
await fs22.rename(temporary, this.filePath);
|
|
64617
65408
|
return parsed;
|
|
64618
65409
|
}
|
|
64619
65410
|
};
|
|
64620
65411
|
function userVariableStoreFor(dataDir, principal) {
|
|
64621
|
-
return new UserVariableStore(userVariablesPath(
|
|
65412
|
+
return new UserVariableStore(userVariablesPath(path28.join(dataDir, "users", storageKeyFor(principal))));
|
|
64622
65413
|
}
|
|
64623
65414
|
function userVariablesPath(userDir) {
|
|
64624
|
-
return
|
|
65415
|
+
return path28.join(userDir, "variables.json");
|
|
64625
65416
|
}
|
|
64626
65417
|
function readVariablesFile(filePath) {
|
|
64627
65418
|
try {
|
|
@@ -64635,8 +65426,8 @@ function readVariablesFile(filePath) {
|
|
|
64635
65426
|
|
|
64636
65427
|
// src/session.ts
|
|
64637
65428
|
import { watch as fsWatch } from "node:fs";
|
|
64638
|
-
import
|
|
64639
|
-
import
|
|
65429
|
+
import fs23 from "node:fs/promises";
|
|
65430
|
+
import path29 from "node:path";
|
|
64640
65431
|
var FileConfigStore = class {
|
|
64641
65432
|
constructor(userConfigPath, workspaceRoot) {
|
|
64642
65433
|
this.userConfigPath = userConfigPath;
|
|
@@ -64652,7 +65443,7 @@ var FileConfigStore = class {
|
|
|
64652
65443
|
const filePath = this.pathFor(scope);
|
|
64653
65444
|
if (filePath === void 0) return void 0;
|
|
64654
65445
|
try {
|
|
64655
|
-
return await
|
|
65446
|
+
return await fs23.readFile(filePath, "utf8");
|
|
64656
65447
|
} catch (error51) {
|
|
64657
65448
|
if (error51.code === "ENOENT") return void 0;
|
|
64658
65449
|
throw error51;
|
|
@@ -64662,14 +65453,14 @@ var FileConfigStore = class {
|
|
|
64662
65453
|
async write(scope, contents) {
|
|
64663
65454
|
const filePath = this.pathFor(scope);
|
|
64664
65455
|
if (filePath === void 0) throw new Error(`Cannot write ${scope} config: no workspace is open`);
|
|
64665
|
-
await
|
|
65456
|
+
await fs23.mkdir(path29.dirname(filePath), { recursive: true });
|
|
64666
65457
|
const temporary = `${filePath}.${process.pid.toString(36)}.tmp`;
|
|
64667
|
-
await
|
|
64668
|
-
await
|
|
65458
|
+
await fs23.writeFile(temporary, contents, { encoding: "utf8", mode: 384 });
|
|
65459
|
+
await fs23.rename(temporary, filePath);
|
|
64669
65460
|
try {
|
|
64670
65461
|
const backupTemp = `${configBackupPath(filePath)}.tmp`;
|
|
64671
|
-
await
|
|
64672
|
-
await
|
|
65462
|
+
await fs23.writeFile(backupTemp, contents, { encoding: "utf8", mode: 384 });
|
|
65463
|
+
await fs23.rename(backupTemp, configBackupPath(filePath));
|
|
64673
65464
|
} catch {
|
|
64674
65465
|
}
|
|
64675
65466
|
}
|
|
@@ -64677,7 +65468,7 @@ var FileConfigStore = class {
|
|
|
64677
65468
|
const filePath = this.pathFor(scope);
|
|
64678
65469
|
if (filePath === void 0) return void 0;
|
|
64679
65470
|
try {
|
|
64680
|
-
return await
|
|
65471
|
+
return await fs23.readFile(configBackupPath(filePath), "utf8");
|
|
64681
65472
|
} catch {
|
|
64682
65473
|
return void 0;
|
|
64683
65474
|
}
|
|
@@ -64687,7 +65478,7 @@ var FileConfigStore = class {
|
|
|
64687
65478
|
if (filePath === void 0) return void 0;
|
|
64688
65479
|
const target = `${filePath}.corrupt-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}`;
|
|
64689
65480
|
try {
|
|
64690
|
-
await
|
|
65481
|
+
await fs23.rename(filePath, target);
|
|
64691
65482
|
return target;
|
|
64692
65483
|
} catch {
|
|
64693
65484
|
return void 0;
|
|
@@ -64699,8 +65490,8 @@ var FileConfigStore = class {
|
|
|
64699
65490
|
};
|
|
64700
65491
|
let watcher;
|
|
64701
65492
|
try {
|
|
64702
|
-
watcher = fsWatch(
|
|
64703
|
-
if (filename ===
|
|
65493
|
+
watcher = fsWatch(path29.dirname(filePath), (_event, filename) => {
|
|
65494
|
+
if (filename === path29.basename(filePath)) onChange();
|
|
64704
65495
|
});
|
|
64705
65496
|
} catch {
|
|
64706
65497
|
}
|
|
@@ -64715,7 +65506,7 @@ var FileWorkspaceState = class {
|
|
|
64715
65506
|
values = {};
|
|
64716
65507
|
async load() {
|
|
64717
65508
|
try {
|
|
64718
|
-
const parsed = JSON.parse(await
|
|
65509
|
+
const parsed = JSON.parse(await fs23.readFile(this.filePath, "utf8"));
|
|
64719
65510
|
if (typeof parsed === "object" && parsed !== null) this.values = parsed;
|
|
64720
65511
|
} catch {
|
|
64721
65512
|
this.values = {};
|
|
@@ -64727,8 +65518,8 @@ var FileWorkspaceState = class {
|
|
|
64727
65518
|
async set(key, value) {
|
|
64728
65519
|
if (value === void 0) delete this.values[key];
|
|
64729
65520
|
else this.values[key] = value;
|
|
64730
|
-
await
|
|
64731
|
-
await
|
|
65521
|
+
await fs23.mkdir(path29.dirname(this.filePath), { recursive: true });
|
|
65522
|
+
await fs23.writeFile(this.filePath, JSON.stringify(this.values, null, 2), { encoding: "utf8", mode: 384 });
|
|
64732
65523
|
}
|
|
64733
65524
|
};
|
|
64734
65525
|
function createBrowserUi(workspaceRoot, post) {
|
|
@@ -64766,7 +65557,7 @@ function createBrowserUi(workspaceRoot, post) {
|
|
|
64766
65557
|
*/
|
|
64767
65558
|
openFile: async (filePath) => {
|
|
64768
65559
|
try {
|
|
64769
|
-
post([`[info] ${
|
|
65560
|
+
post([`[info] ${path29.basename(filePath)}`, "", await fs23.readFile(filePath, "utf8")].join("\n"));
|
|
64770
65561
|
} catch (error51) {
|
|
64771
65562
|
post(`[warning] Could not read ${filePath}: ${String(error51)}`);
|
|
64772
65563
|
}
|
|
@@ -64784,14 +65575,14 @@ function createBrowserUi(workspaceRoot, post) {
|
|
|
64784
65575
|
if (found.length >= limit || depth > 12) return;
|
|
64785
65576
|
let entries;
|
|
64786
65577
|
try {
|
|
64787
|
-
entries = await
|
|
65578
|
+
entries = await fs23.readdir(dir, { withFileTypes: true });
|
|
64788
65579
|
} catch {
|
|
64789
65580
|
return;
|
|
64790
65581
|
}
|
|
64791
65582
|
for (const entry of entries) {
|
|
64792
65583
|
if (found.length >= limit) return;
|
|
64793
65584
|
if (entry.name.startsWith(".") && entry.name !== ".env") continue;
|
|
64794
|
-
const full =
|
|
65585
|
+
const full = path29.join(dir, entry.name);
|
|
64795
65586
|
if (entry.isDirectory()) {
|
|
64796
65587
|
if (!skip.has(entry.name)) await walk(full, depth + 1);
|
|
64797
65588
|
} else if (needle.length === 0 || entry.name.toLowerCase().includes(needle)) {
|
|
@@ -64805,11 +65596,11 @@ function createBrowserUi(workspaceRoot, post) {
|
|
|
64805
65596
|
};
|
|
64806
65597
|
}
|
|
64807
65598
|
async function createSession(options) {
|
|
64808
|
-
const userDir =
|
|
64809
|
-
await
|
|
65599
|
+
const userDir = path29.join(options.dataDir, "users", storageKeyFor(options.principal));
|
|
65600
|
+
await fs23.mkdir(userDir, { recursive: true, mode: 448 });
|
|
64810
65601
|
const variableStore = new UserVariableStore(userVariablesPath(userDir));
|
|
64811
65602
|
const userVariables = () => variableStore.read();
|
|
64812
|
-
const workspaceState = new FileWorkspaceState(
|
|
65603
|
+
const workspaceState = new FileWorkspaceState(path29.join(userDir, "workspace-state.json"));
|
|
64813
65604
|
await workspaceState.load();
|
|
64814
65605
|
const services = {
|
|
64815
65606
|
transport: options.transport,
|
|
@@ -64817,9 +65608,9 @@ async function createSession(options) {
|
|
|
64817
65608
|
* A shared profile's API key belongs to the administrator and lives beside the shared config;
|
|
64818
65609
|
* everything else is this user's. Routed by the reference, which is all a secret store gets.
|
|
64819
65610
|
*/
|
|
64820
|
-
secrets: options.sharedSecrets === void 0 ? new FileSecretStore(
|
|
64821
|
-
configStore: options.sharedProfiles === void 0 ? new FileConfigStore(
|
|
64822
|
-
new FileConfigStore(
|
|
65611
|
+
secrets: options.sharedSecrets === void 0 ? new FileSecretStore(path29.join(userDir, "secrets.json")) : new RoutedSecretStore(new FileSecretStore(path29.join(userDir, "secrets.json")), options.sharedSecrets),
|
|
65612
|
+
configStore: options.sharedProfiles === void 0 ? new FileConfigStore(path29.join(userDir, "config.json"), options.workspaceRoot) : new SharedProfileConfigStore(
|
|
65613
|
+
new FileConfigStore(path29.join(userDir, "config.json"), options.workspaceRoot),
|
|
64823
65614
|
options.sharedProfiles
|
|
64824
65615
|
),
|
|
64825
65616
|
workspaceState,
|
|
@@ -64904,11 +65695,11 @@ var CONTENT_TYPES = {
|
|
|
64904
65695
|
async function startServer(options) {
|
|
64905
65696
|
const log = options.logSink ?? ((line) => process.stderr.write(`${line}
|
|
64906
65697
|
`));
|
|
64907
|
-
const identity = options.identity ?? new SingleUserIdentity();
|
|
65698
|
+
const identity = options.identity ?? new SingleUserIdentity(options.handoffSeconds);
|
|
64908
65699
|
const roles = options.roles ?? SINGLE_USER_POLICY;
|
|
64909
65700
|
const sharedStore = options.sharedConfig;
|
|
64910
|
-
const sharedSecretStore = new FileSecretStore(
|
|
64911
|
-
const reviews = new ReviewQueue(
|
|
65701
|
+
const sharedSecretStore = new FileSecretStore(path30.join(options.dataDir, "shared-secrets.json"));
|
|
65702
|
+
const reviews = new ReviewQueue(path30.join(options.dataDir, "reviews.json"));
|
|
64912
65703
|
let sharedCache = { variables: [], adminIds: [], profiles: [] };
|
|
64913
65704
|
const bindAddress = options.bindAddress ?? "127.0.0.1";
|
|
64914
65705
|
if (sharedStore !== void 0) sharedCache = await sharedStore.load();
|
|
@@ -65021,12 +65812,16 @@ async function startServer(options) {
|
|
|
65021
65812
|
}
|
|
65022
65813
|
const body = await readJsonBody(request);
|
|
65023
65814
|
const handoff = typeof body?.handoff === "string" ? body.handoff : "";
|
|
65024
|
-
const
|
|
65025
|
-
if (token === void 0) {
|
|
65026
|
-
|
|
65815
|
+
const outcome = identity.redeem(handoff);
|
|
65816
|
+
if (outcome.token === void 0) {
|
|
65817
|
+
if (outcome.reason === "expired" || outcome.reason === "spent") options.onHandoffLapsed?.(outcome.reason);
|
|
65818
|
+
reject(response, {
|
|
65819
|
+
status: 401,
|
|
65820
|
+
reason: outcome.reason === "expired" ? "That link expired. A fresh one has been printed in the terminal running light-code." : outcome.reason === "spent" ? "That link has already been used. A fresh one has been printed in the terminal." : "Handoff token invalid."
|
|
65821
|
+
});
|
|
65027
65822
|
return;
|
|
65028
65823
|
}
|
|
65029
|
-
respondJson(response, 200, { token });
|
|
65824
|
+
respondJson(response, 200, { token: outcome.token });
|
|
65030
65825
|
return;
|
|
65031
65826
|
}
|
|
65032
65827
|
const principal = await identity.authenticate(request);
|
|
@@ -65119,14 +65914,14 @@ async function startServer(options) {
|
|
|
65119
65914
|
if (options.workspaceRoot === void 0) return "No workspace is open, so there is nowhere to write it.";
|
|
65120
65915
|
try {
|
|
65121
65916
|
if (item.kind === "skill") {
|
|
65122
|
-
const dir2 =
|
|
65123
|
-
await
|
|
65124
|
-
await
|
|
65917
|
+
const dir2 = path30.join(options.workspaceRoot, ".lightcode", "skills");
|
|
65918
|
+
await fs24.mkdir(dir2, { recursive: true });
|
|
65919
|
+
await fs24.writeFile(path30.join(dir2, `${item.name}.md`), item.content, "utf8");
|
|
65125
65920
|
return void 0;
|
|
65126
65921
|
}
|
|
65127
|
-
const dir =
|
|
65128
|
-
await
|
|
65129
|
-
await
|
|
65922
|
+
const dir = path30.join(options.workspaceRoot, ".lightcode", "tools");
|
|
65923
|
+
await fs24.mkdir(dir, { recursive: true });
|
|
65924
|
+
await fs24.writeFile(path30.join(dir, `${item.name}.py`), item.content, "utf8");
|
|
65130
65925
|
return void 0;
|
|
65131
65926
|
} catch (error51) {
|
|
65132
65927
|
return error51 instanceof Error ? error51.message : String(error51);
|
|
@@ -65227,9 +66022,9 @@ async function startServer(options) {
|
|
|
65227
66022
|
return;
|
|
65228
66023
|
}
|
|
65229
66024
|
try {
|
|
65230
|
-
const body = await
|
|
66025
|
+
const body = await fs24.readFile(path30.join(options.clientDir, asset));
|
|
65231
66026
|
response.writeHead(200, {
|
|
65232
|
-
"Content-Type": CONTENT_TYPES[
|
|
66027
|
+
"Content-Type": CONTENT_TYPES[path30.extname(asset)] ?? "application/octet-stream",
|
|
65233
66028
|
...securityHeaders()
|
|
65234
66029
|
});
|
|
65235
66030
|
response.end(body);
|
|
@@ -65245,6 +66040,7 @@ async function startServer(options) {
|
|
|
65245
66040
|
return {
|
|
65246
66041
|
url: `http://${authority}`,
|
|
65247
66042
|
launchToken: identity instanceof SingleUserIdentity ? identity.launchToken : void 0,
|
|
66043
|
+
newLaunchUrl: identity instanceof SingleUserIdentity ? () => `http://${authority}/#t=${identity.remintHandoff()}` : void 0,
|
|
65248
66044
|
close: () => new Promise((resolve) => {
|
|
65249
66045
|
for (const connection of connections.values()) connection.dispose();
|
|
65250
66046
|
connections.clear();
|