@foundocs/foundocs-setup 0.5.0 → 0.5.4
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/README.md +1 -19
- package/dist/bridge.mjs +246 -641
- package/package.json +3 -3
- package/skills/foundocs/SKILL.md +6 -6
- package/skills/foundocs/references/dreaming.md +4 -3
- package/skills/foundocs/scripts/session-start.mjs +5 -15
- package/src/bridge.mjs +12 -27
- package/src/cli.mjs +1 -9
- package/src/global.mjs +1 -1
- package/src/runtime.mjs +7 -29
- package/src/setup.mjs +13 -6
- package/src/skill-assets.mjs +1 -1
- package/src/upload-image.mjs +48 -0
- package/skills/foundocs/references/effect-measurement.md +0 -55
- package/src/effect-automatic.mjs +0 -190
- package/src/effect-config.mjs +0 -31
- package/src/effect-host.mjs +0 -86
- package/src/effect-remote.mjs +0 -28
- package/src/effect.mjs +0 -209
package/dist/bridge.mjs
CHANGED
|
@@ -28,8 +28,8 @@ var __exportAll = (all, symbols) => {
|
|
|
28
28
|
};
|
|
29
29
|
var __copyProps = (to, from, except, desc) => {
|
|
30
30
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
-
for (var
|
|
32
|
-
key =
|
|
31
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
32
|
+
key = keys[i];
|
|
33
33
|
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
34
34
|
__defProp2(to, key, {
|
|
35
35
|
get: ((k) => from[k]).bind(null, key),
|
|
@@ -227,8 +227,8 @@ function defineLazy(object2, key, getter) {
|
|
|
227
227
|
configurable: true
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
|
-
function objectClone(
|
|
231
|
-
return Object.create(Object.getPrototypeOf(
|
|
230
|
+
function objectClone(obj) {
|
|
231
|
+
return Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
|
|
232
232
|
}
|
|
233
233
|
function assignProp(target, prop, value) {
|
|
234
234
|
Object.defineProperty(target, prop, {
|
|
@@ -262,9 +262,9 @@ function putProp(target, key, value) {
|
|
|
262
262
|
else
|
|
263
263
|
target[key] = value;
|
|
264
264
|
}
|
|
265
|
-
function mirrorShape(target, source,
|
|
265
|
+
function mirrorShape(target, source, keys, wrap) {
|
|
266
266
|
const raw = sourceShape(source);
|
|
267
|
-
for (const key of
|
|
267
|
+
for (const key of keys) {
|
|
268
268
|
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
269
269
|
if (!desc.enumerable)
|
|
270
270
|
continue;
|
|
@@ -299,18 +299,18 @@ function mergeDefs(...defs) {
|
|
|
299
299
|
function cloneDef(schema) {
|
|
300
300
|
return mergeDefs(schema._zod.def);
|
|
301
301
|
}
|
|
302
|
-
function getElementAtPath(
|
|
302
|
+
function getElementAtPath(obj, path) {
|
|
303
303
|
if (!path)
|
|
304
|
-
return
|
|
305
|
-
return path.reduce((acc, key) => acc?.[key],
|
|
304
|
+
return obj;
|
|
305
|
+
return path.reduce((acc, key) => acc?.[key], obj);
|
|
306
306
|
}
|
|
307
307
|
function promiseAllObject(promisesObj) {
|
|
308
|
-
const
|
|
309
|
-
const promises =
|
|
308
|
+
const keys = Object.keys(promisesObj);
|
|
309
|
+
const promises = keys.map((key) => promisesObj[key]);
|
|
310
310
|
return Promise.all(promises).then((results) => {
|
|
311
311
|
const resolvedObj = {};
|
|
312
|
-
for (let i = 0; i <
|
|
313
|
-
resolvedObj[
|
|
312
|
+
for (let i = 0; i < keys.length; i++) {
|
|
313
|
+
resolvedObj[keys[i]] = results[i];
|
|
314
314
|
}
|
|
315
315
|
return resolvedObj;
|
|
316
316
|
});
|
|
@@ -532,15 +532,15 @@ function pick(schema, mask) {
|
|
|
532
532
|
}
|
|
533
533
|
function maskedKeys(schema, mask) {
|
|
534
534
|
const raw = sourceShape(schema);
|
|
535
|
-
const
|
|
535
|
+
const keys = [];
|
|
536
536
|
for (const key of Reflect.ownKeys(mask)) {
|
|
537
537
|
if (!Object.getOwnPropertyDescriptor(raw, key)?.enumerable) {
|
|
538
538
|
throw new Error(`Unrecognized key: "${String(key)}"`);
|
|
539
539
|
}
|
|
540
540
|
if (mask[key])
|
|
541
|
-
|
|
541
|
+
keys.push(key);
|
|
542
542
|
}
|
|
543
|
-
return
|
|
543
|
+
return keys;
|
|
544
544
|
}
|
|
545
545
|
function omit(schema, mask) {
|
|
546
546
|
const currDef = schema._zod.def;
|
|
@@ -738,9 +738,9 @@ function parsedType(data) {
|
|
|
738
738
|
if (Array.isArray(data)) {
|
|
739
739
|
return "array";
|
|
740
740
|
}
|
|
741
|
-
const
|
|
742
|
-
if (
|
|
743
|
-
return
|
|
741
|
+
const obj = data;
|
|
742
|
+
if (obj && Object.getPrototypeOf(obj) !== Object.prototype && "constructor" in obj && obj.constructor) {
|
|
743
|
+
return obj.constructor.name;
|
|
744
744
|
}
|
|
745
745
|
}
|
|
746
746
|
}
|
|
@@ -758,8 +758,8 @@ function issue(...args) {
|
|
|
758
758
|
}
|
|
759
759
|
return { ...iss };
|
|
760
760
|
}
|
|
761
|
-
function cleanEnum(
|
|
762
|
-
return Object.entries(
|
|
761
|
+
function cleanEnum(obj) {
|
|
762
|
+
return Object.entries(obj).filter(([k, _]) => {
|
|
763
763
|
return Number.isNaN(Number.parseInt(k, 10));
|
|
764
764
|
}).map((el) => el[1]);
|
|
765
765
|
}
|
|
@@ -1083,15 +1083,15 @@ var $ZodError = $constructor("$ZodError", initializer);
|
|
|
1083
1083
|
var $ZodRealError = $constructor("$ZodError", initializer, void 0, {
|
|
1084
1084
|
Parent: Error
|
|
1085
1085
|
});
|
|
1086
|
-
function node(
|
|
1087
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
1086
|
+
function node(obj, key, make) {
|
|
1087
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
1088
1088
|
if (key === "__proto__") {
|
|
1089
|
-
Object.defineProperty(
|
|
1089
|
+
Object.defineProperty(obj, key, { value: make(), writable: true, enumerable: true, configurable: true });
|
|
1090
1090
|
} else {
|
|
1091
|
-
|
|
1091
|
+
obj[key] = make();
|
|
1092
1092
|
}
|
|
1093
1093
|
}
|
|
1094
|
-
return
|
|
1094
|
+
return obj[key];
|
|
1095
1095
|
}
|
|
1096
1096
|
function flattenError(error2, mapper = (issue2) => issue2.message) {
|
|
1097
1097
|
const fieldErrors = {};
|
|
@@ -2450,10 +2450,10 @@ function handlePropertyResult(result, final, key, input, optin, optout) {
|
|
|
2450
2450
|
}
|
|
2451
2451
|
var NO_SYMBOL_KEYS = [];
|
|
2452
2452
|
function normalizeDef(def) {
|
|
2453
|
-
const
|
|
2453
|
+
const keys = Object.keys(def.shape);
|
|
2454
2454
|
const ownSymbols = Object.getOwnPropertySymbols(def.shape);
|
|
2455
2455
|
const symbolKeys = ownSymbols.length ? ownSymbols : NO_SYMBOL_KEYS;
|
|
2456
|
-
const allKeys = symbolKeys.length ? [...
|
|
2456
|
+
const allKeys = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
|
|
2457
2457
|
for (const k of allKeys) {
|
|
2458
2458
|
if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
|
|
2459
2459
|
throw new Error(`Invalid element at key "${String(k)}": expected a Zod schema`);
|
|
@@ -2465,8 +2465,8 @@ function normalizeDef(def) {
|
|
|
2465
2465
|
allKeys,
|
|
2466
2466
|
symbolKeys,
|
|
2467
2467
|
// string-only: handleCatchall matches it against `for...in`, which never yields a symbol
|
|
2468
|
-
keySet: new Set(
|
|
2469
|
-
numKeys:
|
|
2468
|
+
keySet: new Set(keys),
|
|
2469
|
+
numKeys: keys.length,
|
|
2470
2470
|
optionalKeys: new Set(okeys)
|
|
2471
2471
|
};
|
|
2472
2472
|
}
|
|
@@ -2939,19 +2939,19 @@ function handleIntersectionResults(result, left, right) {
|
|
|
2939
2939
|
let unrecIssue;
|
|
2940
2940
|
const keyIssues = /* @__PURE__ */ new Map();
|
|
2941
2941
|
const collect = (iss, side) => {
|
|
2942
|
-
let
|
|
2942
|
+
let keys;
|
|
2943
2943
|
if (iss.code === "unrecognized_keys" && !iss.path?.length) {
|
|
2944
2944
|
unrecIssue ?? (unrecIssue = iss);
|
|
2945
|
-
|
|
2945
|
+
keys = iss.keys;
|
|
2946
2946
|
} else if (iss.code === "invalid_key" && iss.origin === "record" && iss.path?.length === 1) {
|
|
2947
2947
|
const k = String(iss.path[0]);
|
|
2948
2948
|
if (!keyIssues.has(k))
|
|
2949
2949
|
keyIssues.set(k, iss);
|
|
2950
|
-
|
|
2950
|
+
keys = [k];
|
|
2951
2951
|
} else {
|
|
2952
2952
|
return false;
|
|
2953
2953
|
}
|
|
2954
|
-
for (const k of
|
|
2954
|
+
for (const k of keys) {
|
|
2955
2955
|
if (!unrecKeys.has(k))
|
|
2956
2956
|
unrecKeys.set(k, {});
|
|
2957
2957
|
unrecKeys.get(k)[side] = true;
|
|
@@ -3481,7 +3481,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
3481
3481
|
var NONE = 0;
|
|
3482
3482
|
var ASSUMED = 1;
|
|
3483
3483
|
var PROVEN = 2;
|
|
3484
|
-
function isRecursive(inst, stack,
|
|
3484
|
+
function isRecursive(inst, stack, resolve4) {
|
|
3485
3485
|
const cached2 = recursive.get(inst);
|
|
3486
3486
|
if (cached2 !== void 0)
|
|
3487
3487
|
return cached2 ? PROVEN : NONE;
|
|
@@ -3491,7 +3491,7 @@ function isRecursive(inst, stack, resolve3) {
|
|
|
3491
3491
|
let result = NONE;
|
|
3492
3492
|
const check = (child) => {
|
|
3493
3493
|
if (result !== PROVEN && child?._zod) {
|
|
3494
|
-
const answer = isRecursive(child, stack,
|
|
3494
|
+
const answer = isRecursive(child, stack, resolve4);
|
|
3495
3495
|
if (answer > result)
|
|
3496
3496
|
result = answer;
|
|
3497
3497
|
}
|
|
@@ -3502,7 +3502,7 @@ function isRecursive(inst, stack, resolve3) {
|
|
|
3502
3502
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
3503
3503
|
if (spread && !desc.enumerable)
|
|
3504
3504
|
continue;
|
|
3505
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
3505
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve4) : NONE;
|
|
3506
3506
|
if (child > answer)
|
|
3507
3507
|
answer = child;
|
|
3508
3508
|
}
|
|
@@ -3566,7 +3566,7 @@ function isRecursive(inst, stack, resolve3) {
|
|
|
3566
3566
|
break;
|
|
3567
3567
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
3568
3568
|
case "lazy": {
|
|
3569
|
-
const inner = def._cachedInner ?? (
|
|
3569
|
+
const inner = def._cachedInner ?? (resolve4 ? inst._zod.innerType : void 0);
|
|
3570
3570
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
3571
3571
|
break;
|
|
3572
3572
|
}
|
|
@@ -4668,8 +4668,8 @@ function compactTypeUnion(schema) {
|
|
|
4668
4668
|
if (!option || typeof option !== "object")
|
|
4669
4669
|
return;
|
|
4670
4670
|
compactTypeUnion(option);
|
|
4671
|
-
const
|
|
4672
|
-
if (
|
|
4671
|
+
const keys = Object.keys(option);
|
|
4672
|
+
if (keys.length !== 1 || keys[0] !== "type")
|
|
4673
4673
|
return;
|
|
4674
4674
|
const type = option.type;
|
|
4675
4675
|
for (const member of Array.isArray(type) ? type : [type]) {
|
|
@@ -6576,11 +6576,11 @@ var ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
|
6576
6576
|
inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json, params);
|
|
6577
6577
|
inst.enum = def.entries;
|
|
6578
6578
|
inst.options = [...inst._zod.values];
|
|
6579
|
-
const
|
|
6579
|
+
const keys = new Set(Object.keys(def.entries));
|
|
6580
6580
|
inst.extract = (values, params) => {
|
|
6581
6581
|
const newEntries = {};
|
|
6582
6582
|
for (const value of values) {
|
|
6583
|
-
if (
|
|
6583
|
+
if (keys.has(value)) {
|
|
6584
6584
|
newEntries[value] = def.entries[value];
|
|
6585
6585
|
} else
|
|
6586
6586
|
throw new Error(`Key ${value} not found in enum`);
|
|
@@ -6595,7 +6595,7 @@ var ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
|
6595
6595
|
inst.exclude = (values, params) => {
|
|
6596
6596
|
const newEntries = { ...def.entries };
|
|
6597
6597
|
for (const value of values) {
|
|
6598
|
-
if (
|
|
6598
|
+
if (keys.has(value)) {
|
|
6599
6599
|
delete newEntries[value];
|
|
6600
6600
|
} else
|
|
6601
6601
|
throw new Error(`Key ${value} not found in enum`);
|
|
@@ -11266,14 +11266,14 @@ function inputRequiredRoundsExceededMessage(method, maxRounds) {
|
|
|
11266
11266
|
return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
|
|
11267
11267
|
}
|
|
11268
11268
|
function sleep(ms, signal) {
|
|
11269
|
-
return new Promise((
|
|
11269
|
+
return new Promise((resolve4, reject) => {
|
|
11270
11270
|
if (signal?.aborted) {
|
|
11271
11271
|
reject(signal.reason instanceof SdkError ? signal.reason : new SdkError(SdkErrorCode.RequestTimeout, String(signal.reason)));
|
|
11272
11272
|
return;
|
|
11273
11273
|
}
|
|
11274
11274
|
const timer = setTimeout(() => {
|
|
11275
11275
|
signal?.removeEventListener("abort", onAbort);
|
|
11276
|
-
|
|
11276
|
+
resolve4();
|
|
11277
11277
|
}, ms);
|
|
11278
11278
|
const onAbort = () => {
|
|
11279
11279
|
clearTimeout(timer);
|
|
@@ -12117,7 +12117,7 @@ var Protocol = class {
|
|
|
12117
12117
|
const flowStartedAt = Date.now();
|
|
12118
12118
|
let onAbort;
|
|
12119
12119
|
let cleanupMessageId;
|
|
12120
|
-
return new Promise((
|
|
12120
|
+
return new Promise((resolve4, reject) => {
|
|
12121
12121
|
const earlyReject = (error2) => {
|
|
12122
12122
|
reject(error2);
|
|
12123
12123
|
};
|
|
@@ -12186,7 +12186,7 @@ var Protocol = class {
|
|
|
12186
12186
|
}
|
|
12187
12187
|
if (decoded.kind === "invalid") return reject(decoded.error);
|
|
12188
12188
|
if (decoded.kind === "input_required") {
|
|
12189
|
-
if (options?.allowInputRequired === true) return
|
|
12189
|
+
if (options?.allowInputRequired === true) return resolve4(manualInputRequiredValue(decoded));
|
|
12190
12190
|
const flow = {
|
|
12191
12191
|
codec,
|
|
12192
12192
|
request,
|
|
@@ -12198,11 +12198,11 @@ var Protocol = class {
|
|
|
12198
12198
|
params
|
|
12199
12199
|
}, resultSchema, legOptions)
|
|
12200
12200
|
};
|
|
12201
|
-
return
|
|
12201
|
+
return resolve4(this._resolveNonCompleteResult(decoded, flow));
|
|
12202
12202
|
}
|
|
12203
12203
|
const result = decoded.result;
|
|
12204
12204
|
validateStandardSchema(resultSchema, result).then((parseResult) => {
|
|
12205
|
-
if (parseResult.success)
|
|
12205
|
+
if (parseResult.success) resolve4(parseResult.data);
|
|
12206
12206
|
else reject(new SdkError(SdkErrorCode.InvalidResult, `Invalid result for ${request.method}: ${parseResult.error}`));
|
|
12207
12207
|
}, reject);
|
|
12208
12208
|
});
|
|
@@ -12487,7 +12487,7 @@ var require_content_type = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
12487
12487
|
var index = header.indexOf(";");
|
|
12488
12488
|
var type = index !== -1 ? header.slice(0, index).trim() : header.trim();
|
|
12489
12489
|
if (!TYPE_REGEXP.test(type)) throw new TypeError("invalid media type");
|
|
12490
|
-
var
|
|
12490
|
+
var obj = new ContentType(type.toLowerCase());
|
|
12491
12491
|
if (index !== -1) {
|
|
12492
12492
|
var key;
|
|
12493
12493
|
var match;
|
|
@@ -12502,16 +12502,16 @@ var require_content_type = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
12502
12502
|
value = value.slice(1, -1);
|
|
12503
12503
|
if (value.indexOf("\\") !== -1) value = value.replace(QESC_REGEXP, "$1");
|
|
12504
12504
|
}
|
|
12505
|
-
|
|
12505
|
+
obj.parameters[key] = value;
|
|
12506
12506
|
}
|
|
12507
12507
|
if (index !== header.length) throw new TypeError("invalid parameter format");
|
|
12508
12508
|
}
|
|
12509
|
-
return
|
|
12509
|
+
return obj;
|
|
12510
12510
|
}
|
|
12511
|
-
function getcontenttype(
|
|
12511
|
+
function getcontenttype(obj) {
|
|
12512
12512
|
var header;
|
|
12513
|
-
if (typeof
|
|
12514
|
-
else if (typeof
|
|
12513
|
+
if (typeof obj.getHeader === "function") header = obj.getHeader("content-type");
|
|
12514
|
+
else if (typeof obj.headers === "object") header = obj.headers && obj.headers["content-type"];
|
|
12515
12515
|
if (typeof header !== "string") throw new TypeError("content-type header is missing from object");
|
|
12516
12516
|
return header;
|
|
12517
12517
|
}
|
|
@@ -13401,10 +13401,10 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
13401
13401
|
}
|
|
13402
13402
|
return this._for(new ForIter("of", varKind, name, iterable), () => forBody(name));
|
|
13403
13403
|
}
|
|
13404
|
-
forIn(nameOrPrefix,
|
|
13405
|
-
if (this.opts.ownProperties) return this.forOf(nameOrPrefix, (0, code_1._)`Object.keys(${
|
|
13404
|
+
forIn(nameOrPrefix, obj, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.const) {
|
|
13405
|
+
if (this.opts.ownProperties) return this.forOf(nameOrPrefix, (0, code_1._)`Object.keys(${obj})`, forBody);
|
|
13406
13406
|
const name = this._scope.toName(nameOrPrefix);
|
|
13407
|
-
return this._for(new ForIter("in", varKind, name,
|
|
13407
|
+
return this._for(new ForIter("in", varKind, name, obj), () => forBody(name));
|
|
13408
13408
|
}
|
|
13409
13409
|
endFor() {
|
|
13410
13410
|
return this._endBlockNode(For);
|
|
@@ -13559,9 +13559,9 @@ var require_util = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
13559
13559
|
const codegen_1 = require_codegen();
|
|
13560
13560
|
const code_1 = require_code$1();
|
|
13561
13561
|
function toHash(arr) {
|
|
13562
|
-
const
|
|
13563
|
-
for (const item of arr)
|
|
13564
|
-
return
|
|
13562
|
+
const hash2 = {};
|
|
13563
|
+
for (const item of arr) hash2[item] = true;
|
|
13564
|
+
return hash2;
|
|
13565
13565
|
}
|
|
13566
13566
|
exports.toHash = toHash;
|
|
13567
13567
|
function alwaysValidSchema(it, schema) {
|
|
@@ -14405,7 +14405,7 @@ var require_fast_deep_equal = /* @__PURE__ */ __commonJSMin(((exports, module) =
|
|
|
14405
14405
|
if (a === b) return true;
|
|
14406
14406
|
if (a && b && typeof a == "object" && typeof b == "object") {
|
|
14407
14407
|
if (a.constructor !== b.constructor) return false;
|
|
14408
|
-
var length, i,
|
|
14408
|
+
var length, i, keys;
|
|
14409
14409
|
if (Array.isArray(a)) {
|
|
14410
14410
|
length = a.length;
|
|
14411
14411
|
if (length != b.length) return false;
|
|
@@ -14415,12 +14415,12 @@ var require_fast_deep_equal = /* @__PURE__ */ __commonJSMin(((exports, module) =
|
|
|
14415
14415
|
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
|
14416
14416
|
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
|
14417
14417
|
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
|
14418
|
-
|
|
14419
|
-
length =
|
|
14418
|
+
keys = Object.keys(a);
|
|
14419
|
+
length = keys.length;
|
|
14420
14420
|
if (length !== Object.keys(b).length) return false;
|
|
14421
|
-
for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b,
|
|
14421
|
+
for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
14422
14422
|
for (i = length; i-- !== 0; ) {
|
|
14423
|
-
var key =
|
|
14423
|
+
var key = keys[i];
|
|
14424
14424
|
if (!equal(a[key], b[key])) return false;
|
|
14425
14425
|
}
|
|
14426
14426
|
return true;
|
|
@@ -14527,11 +14527,11 @@ var require_resolve = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
14527
14527
|
"enum",
|
|
14528
14528
|
"const"
|
|
14529
14529
|
]);
|
|
14530
|
-
function inlineRef(schema,
|
|
14530
|
+
function inlineRef(schema, limit2 = true) {
|
|
14531
14531
|
if (typeof schema == "boolean") return true;
|
|
14532
|
-
if (
|
|
14533
|
-
if (!
|
|
14534
|
-
return countKeys(schema) <=
|
|
14532
|
+
if (limit2 === true) return !hasRef(schema);
|
|
14533
|
+
if (!limit2) return false;
|
|
14534
|
+
return countKeys(schema) <= limit2;
|
|
14535
14535
|
}
|
|
14536
14536
|
exports.inlineRef = inlineRef;
|
|
14537
14537
|
const REF_KEYWORDS = /* @__PURE__ */ new Set([
|
|
@@ -14932,9 +14932,9 @@ var require_validate = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
14932
14932
|
ok(cond) {
|
|
14933
14933
|
if (!this.allErrors) this.gen.if(cond);
|
|
14934
14934
|
}
|
|
14935
|
-
setParams(
|
|
14936
|
-
if (assign) Object.assign(this.params,
|
|
14937
|
-
else this.params =
|
|
14935
|
+
setParams(obj, assign) {
|
|
14936
|
+
if (assign) Object.assign(this.params, obj);
|
|
14937
|
+
else this.params = obj;
|
|
14938
14938
|
}
|
|
14939
14939
|
block$data(valid, codeBlock, $dataValid = codegen_1.nil) {
|
|
14940
14940
|
this.gen.block(() => {
|
|
@@ -15186,7 +15186,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
15186
15186
|
ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, ref);
|
|
15187
15187
|
const schOrFunc = root.refs[ref];
|
|
15188
15188
|
if (schOrFunc) return schOrFunc;
|
|
15189
|
-
let _sch =
|
|
15189
|
+
let _sch = resolve4.call(this, root, ref);
|
|
15190
15190
|
if (_sch === void 0) {
|
|
15191
15191
|
const schema = (_a3 = root.localRefs) === null || _a3 === void 0 ? void 0 : _a3[ref];
|
|
15192
15192
|
const { schemaId } = this.opts;
|
|
@@ -15212,7 +15212,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
15212
15212
|
function sameSchemaEnv(s1, s2) {
|
|
15213
15213
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
15214
15214
|
}
|
|
15215
|
-
function
|
|
15215
|
+
function resolve4(root, ref) {
|
|
15216
15216
|
let sch;
|
|
15217
15217
|
while (typeof (sch = this.refs[ref]) == "string") ref = sch;
|
|
15218
15218
|
return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
|
|
@@ -15662,7 +15662,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
15662
15662
|
else if (typeof uri === "object") uri = parse2(serialize(uri, options), options);
|
|
15663
15663
|
return uri;
|
|
15664
15664
|
}
|
|
15665
|
-
function
|
|
15665
|
+
function resolve4(baseURI, relativeURI, options) {
|
|
15666
15666
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
15667
15667
|
const resolved = resolveComponent(parse2(baseURI, schemelessOptions), parse2(relativeURI, schemelessOptions), schemelessOptions, true);
|
|
15668
15668
|
schemelessOptions.skipEscape = true;
|
|
@@ -15836,7 +15836,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
15836
15836
|
const fastUri = {
|
|
15837
15837
|
SCHEMES,
|
|
15838
15838
|
normalize,
|
|
15839
|
-
resolve:
|
|
15839
|
+
resolve: resolve4,
|
|
15840
15840
|
resolveComponent,
|
|
15841
15841
|
equal,
|
|
15842
15842
|
serialize,
|
|
@@ -16234,7 +16234,7 @@ var require_core$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
16234
16234
|
}
|
|
16235
16235
|
errorsText(errors = this.errors, { separator = ", ", dataVar = "data" } = {}) {
|
|
16236
16236
|
if (!errors || errors.length === 0) return "No errors";
|
|
16237
|
-
return errors.map((e) => `${dataVar}${e.instancePath} ${e.message}`).reduce((
|
|
16237
|
+
return errors.map((e) => `${dataVar}${e.instancePath} ${e.message}`).reduce((text, msg) => text + separator + msg);
|
|
16238
16238
|
}
|
|
16239
16239
|
$dataMetaSchema(metaSchema, keywordsJsonPointers) {
|
|
16240
16240
|
const rules = this.RULES.all;
|
|
@@ -21404,14 +21404,14 @@ var ProbeWindow = class ProbeWindow2 {
|
|
|
21404
21404
|
*/
|
|
21405
21405
|
async exchange(buildRequest, timeoutMs) {
|
|
21406
21406
|
const id = `server-discover-probe-${++this._probeCounter}`;
|
|
21407
|
-
return new Promise((
|
|
21407
|
+
return new Promise((resolve4) => {
|
|
21408
21408
|
let settled = false;
|
|
21409
21409
|
const settle2 = (reply) => {
|
|
21410
21410
|
if (settled) return;
|
|
21411
21411
|
settled = true;
|
|
21412
21412
|
clearTimeout(timer);
|
|
21413
21413
|
if (this._pending?.id === id) this._pending = void 0;
|
|
21414
|
-
|
|
21414
|
+
resolve4(reply);
|
|
21415
21415
|
};
|
|
21416
21416
|
const timer = setTimeout(() => settle2({ kind: "timeout" }), timeoutMs);
|
|
21417
21417
|
this._pending = {
|
|
@@ -21501,11 +21501,11 @@ function normalizeReply(reply, timeoutMs) {
|
|
|
21501
21501
|
error: error2
|
|
21502
21502
|
};
|
|
21503
21503
|
if (error2 instanceof SdkHttpError) {
|
|
21504
|
-
const
|
|
21504
|
+
const text = error2.data?.text;
|
|
21505
21505
|
return {
|
|
21506
21506
|
kind: "http-error",
|
|
21507
21507
|
status: error2.data.status,
|
|
21508
|
-
body: typeof
|
|
21508
|
+
body: typeof text === "string" ? text : void 0,
|
|
21509
21509
|
statusText: error2.data.statusText
|
|
21510
21510
|
};
|
|
21511
21511
|
}
|
|
@@ -21643,12 +21643,12 @@ function serverInfoFromDiscover(discover) {
|
|
|
21643
21643
|
function applyElicitationDefaults(schema, data) {
|
|
21644
21644
|
if (!schema || data === null || typeof data !== "object") return;
|
|
21645
21645
|
if (schema.type === "object" && schema.properties && typeof schema.properties === "object") {
|
|
21646
|
-
const
|
|
21646
|
+
const obj = data;
|
|
21647
21647
|
const props = schema.properties;
|
|
21648
21648
|
for (const key of Object.keys(props)) {
|
|
21649
21649
|
const propSchema = props[key];
|
|
21650
|
-
if (
|
|
21651
|
-
if (
|
|
21650
|
+
if (obj[key] === void 0 && Object.prototype.hasOwnProperty.call(propSchema, "default")) obj[key] = propSchema.default;
|
|
21651
|
+
if (obj[key] !== void 0) applyElicitationDefaults(propSchema, obj[key]);
|
|
21652
21652
|
}
|
|
21653
21653
|
}
|
|
21654
21654
|
if (Array.isArray(schema.anyOf)) {
|
|
@@ -22625,13 +22625,13 @@ var Client = class extends Protocol {
|
|
|
22625
22625
|
let onCallerAbort;
|
|
22626
22626
|
let resolveOpening;
|
|
22627
22627
|
let rejectOpening;
|
|
22628
|
-
const opening = new Promise((
|
|
22629
|
-
resolveOpening =
|
|
22628
|
+
const opening = new Promise((resolve4, reject) => {
|
|
22629
|
+
resolveOpening = resolve4;
|
|
22630
22630
|
rejectOpening = reject;
|
|
22631
22631
|
});
|
|
22632
22632
|
let resolveClosed;
|
|
22633
|
-
const closed = new Promise((
|
|
22634
|
-
resolveClosed =
|
|
22633
|
+
const closed = new Promise((resolve4) => {
|
|
22634
|
+
resolveClosed = resolve4;
|
|
22635
22635
|
});
|
|
22636
22636
|
const settle2 = (outcome) => {
|
|
22637
22637
|
if (state === "closed") return;
|
|
@@ -23259,8 +23259,8 @@ var StreamableHTTPClientTransport = class {
|
|
|
23259
23259
|
}
|
|
23260
23260
|
/** Error text for a redirect `response` that was not followed, or `undefined` for any other response. */
|
|
23261
23261
|
_unfollowedRedirect(url2, response) {
|
|
23262
|
-
const
|
|
23263
|
-
return
|
|
23262
|
+
const text = this._redirectPolicy === "follow" ? void 0 : unfollowedRedirect(url2, response);
|
|
23263
|
+
return text && `${text} (redirectPolicy: 'same-origin')`;
|
|
23264
23264
|
}
|
|
23265
23265
|
async _commonHeaders() {
|
|
23266
23266
|
const headers = new Headers(this._requestInit?.headers || void 0);
|
|
@@ -23351,13 +23351,13 @@ var StreamableHTTPClientTransport = class {
|
|
|
23351
23351
|
if (response.status === 403) {
|
|
23352
23352
|
const { resourceMetadataUrl, scope, error: error2, errorDescription } = extractWWWAuthenticateParams(response);
|
|
23353
23353
|
if (error2 === "insufficient_scope") {
|
|
23354
|
-
const
|
|
23354
|
+
const text = await response.text?.().catch(() => null);
|
|
23355
23355
|
if (await this._stepUpAuthorize({
|
|
23356
23356
|
scope,
|
|
23357
23357
|
resourceMetadataUrl,
|
|
23358
23358
|
errorDescription,
|
|
23359
23359
|
statusText: response.statusText,
|
|
23360
|
-
text
|
|
23360
|
+
text
|
|
23361
23361
|
}, stepUpRetries) !== "AUTHORIZED") throw markAuthSeamEscape(new UnauthorizedError());
|
|
23362
23362
|
return this._startOrAuthSse(options, isAuthRetry, stepUpRetries + 1);
|
|
23363
23363
|
}
|
|
@@ -23589,7 +23589,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
23589
23589
|
}));
|
|
23590
23590
|
throw markAuthSeamEscape(new UnauthorizedError());
|
|
23591
23591
|
}
|
|
23592
|
-
const
|
|
23592
|
+
const text = await response.text?.().catch(() => null);
|
|
23593
23593
|
if (response.status === 403) {
|
|
23594
23594
|
const { resourceMetadataUrl, scope, error: error2, errorDescription } = extractWWWAuthenticateParams(response);
|
|
23595
23595
|
if (error2 === "insufficient_scope") {
|
|
@@ -23598,13 +23598,13 @@ var StreamableHTTPClientTransport = class {
|
|
|
23598
23598
|
resourceMetadataUrl,
|
|
23599
23599
|
errorDescription,
|
|
23600
23600
|
statusText: response.statusText,
|
|
23601
|
-
text
|
|
23601
|
+
text
|
|
23602
23602
|
}, stepUpRetries) !== "AUTHORIZED") throw markAuthSeamEscape(new UnauthorizedError());
|
|
23603
23603
|
return this._send(message, options, isAuthRetry, stepUpRetries + 1);
|
|
23604
23604
|
}
|
|
23605
23605
|
}
|
|
23606
|
-
if (response.status === 400 && typeof
|
|
23607
|
-
const parsed = JSONRPCMessageSchema.parse(JSON.parse(
|
|
23606
|
+
if (response.status === 400 && typeof text === "string" && this._isModernEnvelopedRequest(message)) try {
|
|
23607
|
+
const parsed = JSONRPCMessageSchema.parse(JSON.parse(text));
|
|
23608
23608
|
const requests = (Array.isArray(message) ? message : [message]).filter((m) => isJSONRPCRequest(m));
|
|
23609
23609
|
if (isJSONRPCErrorResponse(parsed) && requests.some((r) => r.id === parsed.id)) {
|
|
23610
23610
|
this.onmessage?.(parsed);
|
|
@@ -23612,11 +23612,11 @@ var StreamableHTTPClientTransport = class {
|
|
|
23612
23612
|
}
|
|
23613
23613
|
} catch {
|
|
23614
23614
|
}
|
|
23615
|
-
const reason = this._unfollowedRedirect(this._url, response) ??
|
|
23615
|
+
const reason = this._unfollowedRedirect(this._url, response) ?? text;
|
|
23616
23616
|
throw new SdkHttpError(SdkErrorCode.ClientHttpNotImplemented, `Error POSTing to endpoint: ${reason}`, {
|
|
23617
23617
|
status: response.status,
|
|
23618
23618
|
statusText: response.statusText,
|
|
23619
|
-
text
|
|
23619
|
+
text
|
|
23620
23620
|
});
|
|
23621
23621
|
}
|
|
23622
23622
|
if (response.status === 202) {
|
|
@@ -23730,8 +23730,8 @@ var __exportAll2 = (all, symbols) => {
|
|
|
23730
23730
|
};
|
|
23731
23731
|
var __copyProps2 = (to, from, except, desc) => {
|
|
23732
23732
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
23733
|
-
for (var
|
|
23734
|
-
key =
|
|
23733
|
+
for (var keys = __getOwnPropNames2(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
23734
|
+
key = keys[i];
|
|
23735
23735
|
if (!__hasOwnProp2.call(to, key) && key !== except) {
|
|
23736
23736
|
__defProp3(to, key, {
|
|
23737
23737
|
get: ((k) => from[k]).bind(null, key),
|
|
@@ -27030,14 +27030,14 @@ function inputRequiredRoundsExceededMessage2(method, maxRounds) {
|
|
|
27030
27030
|
return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
|
|
27031
27031
|
}
|
|
27032
27032
|
function sleep2(ms, signal) {
|
|
27033
|
-
return new Promise((
|
|
27033
|
+
return new Promise((resolve4, reject) => {
|
|
27034
27034
|
if (signal?.aborted) {
|
|
27035
27035
|
reject(signal.reason instanceof SdkError2 ? signal.reason : new SdkError2(SdkErrorCode2.RequestTimeout, String(signal.reason)));
|
|
27036
27036
|
return;
|
|
27037
27037
|
}
|
|
27038
27038
|
const timer = setTimeout(() => {
|
|
27039
27039
|
signal?.removeEventListener("abort", onAbort);
|
|
27040
|
-
|
|
27040
|
+
resolve4();
|
|
27041
27041
|
}, ms);
|
|
27042
27042
|
const onAbort = () => {
|
|
27043
27043
|
clearTimeout(timer);
|
|
@@ -27833,7 +27833,7 @@ var Protocol2 = class {
|
|
|
27833
27833
|
const flowStartedAt = Date.now();
|
|
27834
27834
|
let onAbort;
|
|
27835
27835
|
let cleanupMessageId;
|
|
27836
|
-
return new Promise((
|
|
27836
|
+
return new Promise((resolve4, reject) => {
|
|
27837
27837
|
const earlyReject = (error2) => {
|
|
27838
27838
|
reject(error2);
|
|
27839
27839
|
};
|
|
@@ -27902,7 +27902,7 @@ var Protocol2 = class {
|
|
|
27902
27902
|
}
|
|
27903
27903
|
if (decoded.kind === "invalid") return reject(decoded.error);
|
|
27904
27904
|
if (decoded.kind === "input_required") {
|
|
27905
|
-
if (options?.allowInputRequired === true) return
|
|
27905
|
+
if (options?.allowInputRequired === true) return resolve4(manualInputRequiredValue2(decoded));
|
|
27906
27906
|
const flow = {
|
|
27907
27907
|
codec,
|
|
27908
27908
|
request,
|
|
@@ -27914,11 +27914,11 @@ var Protocol2 = class {
|
|
|
27914
27914
|
params
|
|
27915
27915
|
}, resultSchema, legOptions)
|
|
27916
27916
|
};
|
|
27917
|
-
return
|
|
27917
|
+
return resolve4(this._resolveNonCompleteResult(decoded, flow));
|
|
27918
27918
|
}
|
|
27919
27919
|
const result = decoded.result;
|
|
27920
27920
|
validateStandardSchema2(resultSchema, result).then((parseResult) => {
|
|
27921
|
-
if (parseResult.success)
|
|
27921
|
+
if (parseResult.success) resolve4(parseResult.data);
|
|
27922
27922
|
else reject(new SdkError2(SdkErrorCode2.InvalidResult, `Invalid result for ${request.method}: ${parseResult.error}`));
|
|
27923
27923
|
}, reject);
|
|
27924
27924
|
});
|
|
@@ -28130,7 +28130,7 @@ var require_content_type2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28130
28130
|
var index = header.indexOf(";");
|
|
28131
28131
|
var type = index !== -1 ? header.slice(0, index).trim() : header.trim();
|
|
28132
28132
|
if (!TYPE_REGEXP.test(type)) throw new TypeError("invalid media type");
|
|
28133
|
-
var
|
|
28133
|
+
var obj = new ContentType(type.toLowerCase());
|
|
28134
28134
|
if (index !== -1) {
|
|
28135
28135
|
var key;
|
|
28136
28136
|
var match;
|
|
@@ -28145,16 +28145,16 @@ var require_content_type2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28145
28145
|
value = value.slice(1, -1);
|
|
28146
28146
|
if (value.indexOf("\\") !== -1) value = value.replace(QESC_REGEXP, "$1");
|
|
28147
28147
|
}
|
|
28148
|
-
|
|
28148
|
+
obj.parameters[key] = value;
|
|
28149
28149
|
}
|
|
28150
28150
|
if (index !== header.length) throw new TypeError("invalid parameter format");
|
|
28151
28151
|
}
|
|
28152
|
-
return
|
|
28152
|
+
return obj;
|
|
28153
28153
|
}
|
|
28154
|
-
function getcontenttype(
|
|
28154
|
+
function getcontenttype(obj) {
|
|
28155
28155
|
var header;
|
|
28156
|
-
if (typeof
|
|
28157
|
-
else if (typeof
|
|
28156
|
+
if (typeof obj.getHeader === "function") header = obj.getHeader("content-type");
|
|
28157
|
+
else if (typeof obj.headers === "object") header = obj.headers && obj.headers["content-type"];
|
|
28158
28158
|
if (typeof header !== "string") throw new TypeError("content-type header is missing from object");
|
|
28159
28159
|
return header;
|
|
28160
28160
|
}
|
|
@@ -28992,10 +28992,10 @@ var require_codegen2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
28992
28992
|
}
|
|
28993
28993
|
return this._for(new ForIter("of", varKind, name, iterable), () => forBody(name));
|
|
28994
28994
|
}
|
|
28995
|
-
forIn(nameOrPrefix,
|
|
28996
|
-
if (this.opts.ownProperties) return this.forOf(nameOrPrefix, (0, code_1._)`Object.keys(${
|
|
28995
|
+
forIn(nameOrPrefix, obj, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.const) {
|
|
28996
|
+
if (this.opts.ownProperties) return this.forOf(nameOrPrefix, (0, code_1._)`Object.keys(${obj})`, forBody);
|
|
28997
28997
|
const name = this._scope.toName(nameOrPrefix);
|
|
28998
|
-
return this._for(new ForIter("in", varKind, name,
|
|
28998
|
+
return this._for(new ForIter("in", varKind, name, obj), () => forBody(name));
|
|
28999
28999
|
}
|
|
29000
29000
|
endFor() {
|
|
29001
29001
|
return this._endBlockNode(For);
|
|
@@ -29150,9 +29150,9 @@ var require_util2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
29150
29150
|
const codegen_1 = require_codegen2();
|
|
29151
29151
|
const code_1 = require_code$12();
|
|
29152
29152
|
function toHash(arr) {
|
|
29153
|
-
const
|
|
29154
|
-
for (const item of arr)
|
|
29155
|
-
return
|
|
29153
|
+
const hash2 = {};
|
|
29154
|
+
for (const item of arr) hash2[item] = true;
|
|
29155
|
+
return hash2;
|
|
29156
29156
|
}
|
|
29157
29157
|
exports.toHash = toHash;
|
|
29158
29158
|
function alwaysValidSchema(it, schema) {
|
|
@@ -29996,7 +29996,7 @@ var require_fast_deep_equal2 = /* @__PURE__ */ __commonJSMin2(((exports, module)
|
|
|
29996
29996
|
if (a === b) return true;
|
|
29997
29997
|
if (a && b && typeof a == "object" && typeof b == "object") {
|
|
29998
29998
|
if (a.constructor !== b.constructor) return false;
|
|
29999
|
-
var length, i,
|
|
29999
|
+
var length, i, keys;
|
|
30000
30000
|
if (Array.isArray(a)) {
|
|
30001
30001
|
length = a.length;
|
|
30002
30002
|
if (length != b.length) return false;
|
|
@@ -30006,12 +30006,12 @@ var require_fast_deep_equal2 = /* @__PURE__ */ __commonJSMin2(((exports, module)
|
|
|
30006
30006
|
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
|
30007
30007
|
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
|
30008
30008
|
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
|
30009
|
-
|
|
30010
|
-
length =
|
|
30009
|
+
keys = Object.keys(a);
|
|
30010
|
+
length = keys.length;
|
|
30011
30011
|
if (length !== Object.keys(b).length) return false;
|
|
30012
|
-
for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b,
|
|
30012
|
+
for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
30013
30013
|
for (i = length; i-- !== 0; ) {
|
|
30014
|
-
var key =
|
|
30014
|
+
var key = keys[i];
|
|
30015
30015
|
if (!equal(a[key], b[key])) return false;
|
|
30016
30016
|
}
|
|
30017
30017
|
return true;
|
|
@@ -30118,11 +30118,11 @@ var require_resolve2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
30118
30118
|
"enum",
|
|
30119
30119
|
"const"
|
|
30120
30120
|
]);
|
|
30121
|
-
function inlineRef(schema,
|
|
30121
|
+
function inlineRef(schema, limit2 = true) {
|
|
30122
30122
|
if (typeof schema == "boolean") return true;
|
|
30123
|
-
if (
|
|
30124
|
-
if (!
|
|
30125
|
-
return countKeys(schema) <=
|
|
30123
|
+
if (limit2 === true) return !hasRef(schema);
|
|
30124
|
+
if (!limit2) return false;
|
|
30125
|
+
return countKeys(schema) <= limit2;
|
|
30126
30126
|
}
|
|
30127
30127
|
exports.inlineRef = inlineRef;
|
|
30128
30128
|
const REF_KEYWORDS = /* @__PURE__ */ new Set([
|
|
@@ -30523,9 +30523,9 @@ var require_validate2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
30523
30523
|
ok(cond) {
|
|
30524
30524
|
if (!this.allErrors) this.gen.if(cond);
|
|
30525
30525
|
}
|
|
30526
|
-
setParams(
|
|
30527
|
-
if (assign) Object.assign(this.params,
|
|
30528
|
-
else this.params =
|
|
30526
|
+
setParams(obj, assign) {
|
|
30527
|
+
if (assign) Object.assign(this.params, obj);
|
|
30528
|
+
else this.params = obj;
|
|
30529
30529
|
}
|
|
30530
30530
|
block$data(valid, codeBlock, $dataValid = codegen_1.nil) {
|
|
30531
30531
|
this.gen.block(() => {
|
|
@@ -30777,7 +30777,7 @@ var require_compile2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
30777
30777
|
ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, ref);
|
|
30778
30778
|
const schOrFunc = root.refs[ref];
|
|
30779
30779
|
if (schOrFunc) return schOrFunc;
|
|
30780
|
-
let _sch =
|
|
30780
|
+
let _sch = resolve4.call(this, root, ref);
|
|
30781
30781
|
if (_sch === void 0) {
|
|
30782
30782
|
const schema = (_a3 = root.localRefs) === null || _a3 === void 0 ? void 0 : _a3[ref];
|
|
30783
30783
|
const { schemaId } = this.opts;
|
|
@@ -30803,7 +30803,7 @@ var require_compile2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
30803
30803
|
function sameSchemaEnv(s1, s2) {
|
|
30804
30804
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
30805
30805
|
}
|
|
30806
|
-
function
|
|
30806
|
+
function resolve4(root, ref) {
|
|
30807
30807
|
let sch;
|
|
30808
30808
|
while (typeof (sch = this.refs[ref]) == "string") ref = sch;
|
|
30809
30809
|
return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
|
|
@@ -31253,7 +31253,7 @@ var require_fast_uri2 = /* @__PURE__ */ __commonJSMin2(((exports, module) => {
|
|
|
31253
31253
|
else if (typeof uri === "object") uri = parse2(serialize(uri, options), options);
|
|
31254
31254
|
return uri;
|
|
31255
31255
|
}
|
|
31256
|
-
function
|
|
31256
|
+
function resolve4(baseURI, relativeURI, options) {
|
|
31257
31257
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
31258
31258
|
const resolved = resolveComponent(parse2(baseURI, schemelessOptions), parse2(relativeURI, schemelessOptions), schemelessOptions, true);
|
|
31259
31259
|
schemelessOptions.skipEscape = true;
|
|
@@ -31427,7 +31427,7 @@ var require_fast_uri2 = /* @__PURE__ */ __commonJSMin2(((exports, module) => {
|
|
|
31427
31427
|
const fastUri = {
|
|
31428
31428
|
SCHEMES,
|
|
31429
31429
|
normalize,
|
|
31430
|
-
resolve:
|
|
31430
|
+
resolve: resolve4,
|
|
31431
31431
|
resolveComponent,
|
|
31432
31432
|
equal,
|
|
31433
31433
|
serialize,
|
|
@@ -31825,7 +31825,7 @@ var require_core$32 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
31825
31825
|
}
|
|
31826
31826
|
errorsText(errors = this.errors, { separator = ", ", dataVar = "data" } = {}) {
|
|
31827
31827
|
if (!errors || errors.length === 0) return "No errors";
|
|
31828
|
-
return errors.map((e) => `${dataVar}${e.instancePath} ${e.message}`).reduce((
|
|
31828
|
+
return errors.map((e) => `${dataVar}${e.instancePath} ${e.message}`).reduce((text, msg) => text + separator + msg);
|
|
31829
31829
|
}
|
|
31830
31830
|
$dataMetaSchema(metaSchema, keywordsJsonPointers) {
|
|
31831
31831
|
const rules = this.RULES.all;
|
|
@@ -36050,7 +36050,7 @@ var StdioServerTransport = class {
|
|
|
36050
36050
|
}
|
|
36051
36051
|
send(message) {
|
|
36052
36052
|
if (this._closed) return Promise.reject(/* @__PURE__ */ new Error("StdioServerTransport is closed"));
|
|
36053
|
-
return new Promise((
|
|
36053
|
+
return new Promise((resolve4, reject) => {
|
|
36054
36054
|
const json = serializeMessage2(message);
|
|
36055
36055
|
let settled = false;
|
|
36056
36056
|
const onError = (error2) => {
|
|
@@ -36065,23 +36065,82 @@ var StdioServerTransport = class {
|
|
|
36065
36065
|
settled = true;
|
|
36066
36066
|
this._stdout.off("error", onError);
|
|
36067
36067
|
this._stdout.off("drain", onDrain);
|
|
36068
|
-
|
|
36068
|
+
resolve4();
|
|
36069
36069
|
};
|
|
36070
36070
|
this._stdout.once("error", onError);
|
|
36071
36071
|
if (this._stdout.write(json)) {
|
|
36072
36072
|
if (settled) return;
|
|
36073
36073
|
settled = true;
|
|
36074
36074
|
this._stdout.off("error", onError);
|
|
36075
|
-
|
|
36075
|
+
resolve4();
|
|
36076
36076
|
} else if (!settled) this._stdout.once("drain", onDrain);
|
|
36077
36077
|
});
|
|
36078
36078
|
}
|
|
36079
36079
|
};
|
|
36080
36080
|
|
|
36081
|
+
// src/upload-image.mjs
|
|
36082
|
+
import { open as open2, realpath } from "node:fs/promises";
|
|
36083
|
+
import { constants } from "node:fs";
|
|
36084
|
+
import { resolve, relative, isAbsolute, sep } from "node:path";
|
|
36085
|
+
var limit = 4 * 1024 * 1024;
|
|
36086
|
+
var localImageTool = {
|
|
36087
|
+
name: "upload_local_image",
|
|
36088
|
+
description: "Upload a project image from disk (PNG, JPEG, GIF or WebP, up to 4 MiB). Paths are relative to the bound project or absolute within it. Returns the public URL and ready-to-insert Markdown. Anyone with that URL can see the file even if its document is private.",
|
|
36089
|
+
inputSchema: { type: "object", additionalProperties: false, required: ["project_id", "filePath"], properties: {
|
|
36090
|
+
project_id: { type: "string", format: "uuid" },
|
|
36091
|
+
filePath: { type: "string", minLength: 1 },
|
|
36092
|
+
alt: { type: "string", maxLength: 200 }
|
|
36093
|
+
} },
|
|
36094
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
36095
|
+
};
|
|
36096
|
+
async function uploadLocalImage({ root, args, endpoint, credential, send = fetch }) {
|
|
36097
|
+
const error2 = (message) => ({ isError: true, content: [{ type: "text", text: message }] });
|
|
36098
|
+
if (!root || typeof args.filePath !== "string" || !args.filePath || args.alt !== void 0 && (typeof args.alt !== "string" || args.alt.length > 200 || /[\r\n]/.test(args.alt))) return error2("Supply a project image path and optional one-line alt text.");
|
|
36099
|
+
let bytes;
|
|
36100
|
+
try {
|
|
36101
|
+
const directory = await realpath(root);
|
|
36102
|
+
const path = await realpath(resolve(directory, args.filePath));
|
|
36103
|
+
const subpath = relative(directory, path);
|
|
36104
|
+
if (!subpath || subpath.startsWith(".." + sep) || subpath === ".." || isAbsolute(subpath) || subpath.split(sep).some((part) => part.startsWith("."))) return error2("Choose an image inside the bound project, outside hidden directories.");
|
|
36105
|
+
if (!/\.(?:png|jpe?g|gif|webp)$/i.test(path)) return error2("Use a PNG, JPEG, GIF or WebP file.");
|
|
36106
|
+
const file = await open2(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
36107
|
+
try {
|
|
36108
|
+
const stat = await file.stat();
|
|
36109
|
+
if (!stat.isFile() || stat.size < 1 || stat.size > limit) return error2("Choose a regular image file up to 4 MiB.");
|
|
36110
|
+
const buffer = Buffer.alloc(stat.size + 1);
|
|
36111
|
+
let used = 0;
|
|
36112
|
+
while (used < buffer.length) {
|
|
36113
|
+
const { bytesRead } = await file.read(buffer, used, buffer.length - used);
|
|
36114
|
+
if (!bytesRead) break;
|
|
36115
|
+
used += bytesRead;
|
|
36116
|
+
}
|
|
36117
|
+
if (used !== stat.size) return error2("File changed during upload. Retry with the finished image.");
|
|
36118
|
+
bytes = buffer.subarray(0, used);
|
|
36119
|
+
} finally {
|
|
36120
|
+
await file.close();
|
|
36121
|
+
}
|
|
36122
|
+
} catch {
|
|
36123
|
+
return error2("Cannot read the selected project image.");
|
|
36124
|
+
}
|
|
36125
|
+
const target = new URL("/api/projects/" + encodeURIComponent(args.project_id) + "/images", endpoint);
|
|
36126
|
+
if (args.alt) target.searchParams.set("alt", args.alt);
|
|
36127
|
+
const response = await send(target, {
|
|
36128
|
+
method: "POST",
|
|
36129
|
+
redirect: "error",
|
|
36130
|
+
signal: AbortSignal.timeout(25e3),
|
|
36131
|
+
headers: { Authorization: "Bearer " + await credential(), "Content-Type": "application/octet-stream" },
|
|
36132
|
+
body: bytes
|
|
36133
|
+
});
|
|
36134
|
+
if (!response.ok) return error2("Image upload failed (HTTP " + response.status + "). Check the file, project write permission and storage availability.");
|
|
36135
|
+
const result = await response.json();
|
|
36136
|
+
if (!/^https:\/\/foundocs\.velodyusercontents\.com\/images\/[0-9a-f]{64}\.(?:png|jpeg|gif|webp)$/.test(result.url) || typeof result.markdown !== "string" || result.size !== bytes.length) return error2("Invalid image upload receipt.");
|
|
36137
|
+
return { content: [{ type: "text", text: JSON.stringify(result) }], structuredContent: result };
|
|
36138
|
+
}
|
|
36139
|
+
|
|
36081
36140
|
// src/auth.mjs
|
|
36082
36141
|
import { readFile, lstat } from "node:fs/promises";
|
|
36083
36142
|
import { pathToFileURL } from "node:url";
|
|
36084
|
-
import { resolve } from "node:path";
|
|
36143
|
+
import { resolve as resolve2 } from "node:path";
|
|
36085
36144
|
import { execFile } from "node:child_process";
|
|
36086
36145
|
import { promisify } from "node:util";
|
|
36087
36146
|
|
|
@@ -36119,7 +36178,7 @@ async function readCredential(path, projectId, workspaceId) {
|
|
|
36119
36178
|
if (/[\r\n]/.test(value)) throw new Error("Credential is invalid.");
|
|
36120
36179
|
return value;
|
|
36121
36180
|
}
|
|
36122
|
-
if (process.argv[1] && process.argv[2] === "--headers" && import.meta.url === pathToFileURL(
|
|
36181
|
+
if (process.argv[1] && process.argv[2] === "--headers" && import.meta.url === pathToFileURL(resolve2(process.argv[1])).href) {
|
|
36123
36182
|
try {
|
|
36124
36183
|
const [path, projectId, workspaceId] = process.argv.slice(3);
|
|
36125
36184
|
const key = await readCredential(path, projectId, workspaceId);
|
|
@@ -36132,445 +36191,17 @@ if (process.argv[1] && process.argv[2] === "--headers" && import.meta.url === pa
|
|
|
36132
36191
|
|
|
36133
36192
|
// src/bridge.mjs
|
|
36134
36193
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
36135
|
-
import { resolve as
|
|
36136
|
-
|
|
36137
|
-
// src/effect-automatic.mjs
|
|
36138
|
-
import { readdir as readdir2 } from "node:fs/promises";
|
|
36139
|
-
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
36140
|
-
import { join as join2 } from "node:path";
|
|
36141
|
-
|
|
36142
|
-
// src/effect-storage.mjs
|
|
36143
|
-
import { open as open2, mkdir, lstat as lstat2, readdir, readFile as readFile2, rename, rm, realpath } from "node:fs/promises";
|
|
36144
|
-
import { constants } from "node:fs";
|
|
36145
|
-
import { dirname, basename, join, isAbsolute, relative } from "node:path";
|
|
36146
|
-
import { randomUUID } from "node:crypto";
|
|
36147
|
-
|
|
36148
|
-
// src/effect-core.mjs
|
|
36149
|
-
import { createHash } from "node:crypto";
|
|
36150
|
-
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
36151
|
-
var sha256 = (value) => createHash("sha256").update(value).digest("hex");
|
|
36152
|
-
function canonical(value) {
|
|
36153
|
-
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
36154
|
-
if (value && typeof value === "object") return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`;
|
|
36155
|
-
return JSON.stringify(value);
|
|
36156
|
-
}
|
|
36157
|
-
var hash = (value) => sha256(canonical(value));
|
|
36158
|
-
var EffectError = class extends Error {
|
|
36159
|
-
constructor(code, message = code, uncertain = false) {
|
|
36160
|
-
super(message);
|
|
36161
|
-
this.code = code;
|
|
36162
|
-
this.uncertain = uncertain;
|
|
36163
|
-
}
|
|
36164
|
-
};
|
|
36165
|
-
var obj = (v) => v && typeof v === "object" && !Array.isArray(v);
|
|
36166
|
-
var text = (v, max) => typeof v === "string" && v.trim().length > 0 && v.length <= max;
|
|
36167
|
-
var keys = (v, expected) => obj(v) && Object.keys(v).length === expected.length && expected.every((k) => k in v);
|
|
36168
|
-
function validateBrief(v) {
|
|
36169
|
-
if (!keys(v, ["taskId", "question", "knownContext", "criteria"]) || !UUID.test(v.taskId) || !text(v.question, 2e3) || typeof v.knownContext !== "string" || v.knownContext.length > 4e3 || !Array.isArray(v.criteria) || v.criteria.length < 1 || v.criteria.length > 10 || new Set(v.criteria.map((c) => c.id)).size !== v.criteria.length || !v.criteria.every((c) => keys(c, ["id", "description"]) && text(c.id, 80) && text(c.description, 1e3))) throw new EffectError("invalid_brief");
|
|
36170
|
-
}
|
|
36171
|
-
|
|
36172
|
-
// src/effect-storage.mjs
|
|
36173
|
-
async function privateDir(path) {
|
|
36174
|
-
let current = path;
|
|
36175
|
-
while (dirname(current) !== current) {
|
|
36176
|
-
const st2 = await lstat2(current).catch((e) => {
|
|
36177
|
-
if (e.code !== "ENOENT") throw e;
|
|
36178
|
-
return null;
|
|
36179
|
-
});
|
|
36180
|
-
if (st2 && (!st2.isDirectory() || st2.isSymbolicLink())) throw new EffectError("unsafe_storage");
|
|
36181
|
-
current = dirname(current);
|
|
36182
|
-
}
|
|
36183
|
-
await mkdir(path, { recursive: true, mode: 448 });
|
|
36184
|
-
const st = await lstat2(path);
|
|
36185
|
-
if (st.mode & 63 || typeof process.getuid === "function" && st.uid !== process.getuid()) throw new EffectError("unsafe_storage");
|
|
36186
|
-
}
|
|
36187
|
-
async function readJson(path) {
|
|
36188
|
-
const f = await open2(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
36189
|
-
try {
|
|
36190
|
-
const st = await f.stat();
|
|
36191
|
-
if (!st.isFile() || st.nlink !== 1 || st.mode & 63) throw new EffectError("unsafe_storage");
|
|
36192
|
-
return JSON.parse(await f.readFile("utf8"));
|
|
36193
|
-
} finally {
|
|
36194
|
-
await f.close();
|
|
36195
|
-
}
|
|
36196
|
-
}
|
|
36197
|
-
async function writeJson(path, value, exclusive = false) {
|
|
36198
|
-
const temporary = exclusive ? path : `${path}.${randomUUID()}.tmp`;
|
|
36199
|
-
const f = await open2(temporary, "wx", 384);
|
|
36200
|
-
try {
|
|
36201
|
-
await f.writeFile(JSON.stringify(value));
|
|
36202
|
-
await f.sync();
|
|
36203
|
-
} finally {
|
|
36204
|
-
await f.close();
|
|
36205
|
-
}
|
|
36206
|
-
if (!exclusive) await rename(temporary, path);
|
|
36207
|
-
const dir = await open2(dirname(path), "r");
|
|
36208
|
-
try {
|
|
36209
|
-
await dir.sync();
|
|
36210
|
-
} finally {
|
|
36211
|
-
await dir.close();
|
|
36212
|
-
}
|
|
36213
|
-
}
|
|
36214
|
-
function stripRaw(state) {
|
|
36215
|
-
const value = { ...state, rawExpired: true };
|
|
36216
|
-
delete value.brief;
|
|
36217
|
-
delete value.prepareInput;
|
|
36218
|
-
delete value.snapshot;
|
|
36219
|
-
if (value.reservation) {
|
|
36220
|
-
value.reservation = { ...value.reservation };
|
|
36221
|
-
delete value.reservation.deliveredContext;
|
|
36222
|
-
}
|
|
36223
|
-
return value;
|
|
36224
|
-
}
|
|
36225
|
-
async function withStateLock(path, operation) {
|
|
36226
|
-
const lock = `${path}.write-lock`;
|
|
36227
|
-
let handle;
|
|
36228
|
-
for (let attempt = 0; !handle && attempt < 500; attempt++) {
|
|
36229
|
-
try {
|
|
36230
|
-
handle = await open2(lock, "wx", 384);
|
|
36231
|
-
await handle.writeFile(String(process.pid));
|
|
36232
|
-
} catch (error2) {
|
|
36233
|
-
if (error2.code !== "EEXIST") throw error2;
|
|
36234
|
-
const owner = await readFile2(lock, "utf8").catch(() => "");
|
|
36235
|
-
let dead = false;
|
|
36236
|
-
if (/^\d+$/.test(owner)) {
|
|
36237
|
-
try {
|
|
36238
|
-
process.kill(Number(owner), 0);
|
|
36239
|
-
} catch (e) {
|
|
36240
|
-
dead = e.code === "ESRCH";
|
|
36241
|
-
}
|
|
36242
|
-
} else {
|
|
36243
|
-
const st = await lstat2(lock).catch(() => null);
|
|
36244
|
-
dead = !!st && Date.now() - st.mtimeMs > 1e4;
|
|
36245
|
-
}
|
|
36246
|
-
if (dead) await rm(lock, { force: true });
|
|
36247
|
-
else await new Promise((resolve3) => setTimeout(resolve3, 20));
|
|
36248
|
-
}
|
|
36249
|
-
}
|
|
36250
|
-
if (!handle) throw new EffectError("journal_busy");
|
|
36251
|
-
try {
|
|
36252
|
-
return await operation();
|
|
36253
|
-
} finally {
|
|
36254
|
-
await handle.close();
|
|
36255
|
-
await rm(lock, { force: true });
|
|
36256
|
-
}
|
|
36257
|
-
}
|
|
36258
|
-
async function saveJson(path, value, exclusive = false) {
|
|
36259
|
-
if (basename(path) !== "state.json") return writeJson(path, value, exclusive);
|
|
36260
|
-
return withStateLock(path, async () => {
|
|
36261
|
-
const previous = await readJson(path).catch((e) => {
|
|
36262
|
-
if (e.code !== "ENOENT") throw e;
|
|
36263
|
-
return null;
|
|
36264
|
-
});
|
|
36265
|
-
const expired = previous?.rawExpired || value.rawExpired || Date.parse(value.expiresAt) <= Date.now();
|
|
36266
|
-
await writeJson(path, expired ? stripRaw(value) : value, exclusive);
|
|
36267
|
-
});
|
|
36268
|
-
}
|
|
36269
|
-
|
|
36270
|
-
// src/effect-automatic.mjs
|
|
36271
|
-
var effectReads = /* @__PURE__ */ new Set(["get_project_context", "search_docs", "explore_docs", "get_doc", "get_docs"]);
|
|
36272
|
-
var evaluationTools = /* @__PURE__ */ new Set(["report_retrieval_evaluation", "report_retrieval_evaluations"]);
|
|
36273
|
-
var reasons = /* @__PURE__ */ new Set(["consent_required", "missing_preparation", "late_preparation", "working_model_unavailable", "unsupported_runner", "runner_not_configured", "isolation_unavailable", "connection_unavailable", "permission_denied", "snapshot_unavailable", "context_unavailable", "budget_admission_denied", "concurrency_limit", "daily_run_limit", "not_sampled", "disabled", "no_beneficial_retrieval", "expired_preparation", "duplicate_task", "report_pending", "local_failure", "incomplete_evaluation"]);
|
|
36274
|
-
var safeReason = (e) => reasons.has(e?.reason ?? e?.code?.toLowerCase()) ? e.reason ?? e.code.toLowerCase() : ["EACCES", "EPERM"].includes(e?.code) ? "permission_denied" : "local_failure";
|
|
36275
|
-
var dataOf = (r) => r?.structuredContent ?? (() => {
|
|
36276
|
-
try {
|
|
36277
|
-
return JSON.parse(r?.content?.find((c) => c.type === "text")?.text);
|
|
36278
|
-
} catch {
|
|
36279
|
-
return null;
|
|
36280
|
-
}
|
|
36281
|
-
})();
|
|
36282
|
-
function retrievalIds(value, found = /* @__PURE__ */ new Set()) {
|
|
36283
|
-
if (!value || typeof value !== "object") return found;
|
|
36284
|
-
if (Array.isArray(value.retrievals)) {
|
|
36285
|
-
for (const r of value.retrievals) if (UUID.test(r?.retrievalId)) found.add(r.retrievalId);
|
|
36286
|
-
}
|
|
36287
|
-
for (const [key, child] of Object.entries(value)) if (key !== "retrievals" && child && typeof child === "object") retrievalIds(child, found);
|
|
36288
|
-
return found;
|
|
36289
|
-
}
|
|
36290
|
-
function automaticTool(tool) {
|
|
36291
|
-
if (!effectReads.has(tool.name) && !evaluationTools.has(tool.name)) return tool;
|
|
36292
|
-
const properties = { ...tool.inputSchema.properties };
|
|
36293
|
-
if (effectReads.has(tool.name)) properties.effectTask = {
|
|
36294
|
-
type: "object",
|
|
36295
|
-
additionalProperties: false,
|
|
36296
|
-
description: "Local automatic measurement. First read: pre-exposure brief and current trusted host identity; following reads: same taskId only. Never reconstruct a brief after exposure. Source allowlist and consent come from installation, not this call.",
|
|
36297
|
-
required: ["taskId"],
|
|
36298
|
-
properties: {
|
|
36299
|
-
taskId: { type: "string", format: "uuid" },
|
|
36300
|
-
question: { type: "string", minLength: 1, maxLength: 2e3 },
|
|
36301
|
-
knownContext: { type: "string", maxLength: 4e3 },
|
|
36302
|
-
criteria: { type: "array", minItems: 1, maxItems: 10, items: { type: "object", additionalProperties: false, required: ["id", "description"], properties: { id: { type: "string", maxLength: 80 }, description: { type: "string", maxLength: 500 } } } },
|
|
36303
|
-
host: { type: "object", additionalProperties: false, required: ["client", "sessionId"], properties: { client: { type: "string", enum: ["codex", "claude_code"] }, sessionId: { type: "string", format: "uuid" }, transcriptPath: { type: "string" } } }
|
|
36304
|
-
}
|
|
36305
|
-
};
|
|
36306
|
-
else {
|
|
36307
|
-
properties.effectTaskId = { type: "string", format: "uuid", description: "Same automatic information task identity." };
|
|
36308
|
-
properties.effectTaskComplete = { type: "boolean", description: "True only on the final evaluation after ALL information reads and evaluations for this question. The installer starts at most one comparison automatically, after saved consent. Do not issue measure run." };
|
|
36309
|
-
}
|
|
36310
|
-
return {
|
|
36311
|
-
...tool,
|
|
36312
|
-
description: tool.description + " Installed automatic measurement accepts local task metadata; no shell prepare/run is needed.",
|
|
36313
|
-
inputSchema: { ...tool.inputSchema, properties },
|
|
36314
|
-
annotations: { ...tool.annotations, readOnlyHint: false, openWorldHint: true }
|
|
36315
|
-
};
|
|
36316
|
-
}
|
|
36317
|
-
var AutomaticMeasurement = class {
|
|
36318
|
-
constructor({ projectId, remote, factory, store, warn = () => {
|
|
36319
|
-
} }) {
|
|
36320
|
-
Object.assign(this, { projectId, remote, factory, store, warn });
|
|
36321
|
-
this.queue = Promise.resolve();
|
|
36322
|
-
this.jobs = /* @__PURE__ */ new Set();
|
|
36323
|
-
}
|
|
36324
|
-
call(params) {
|
|
36325
|
-
const next = this.queue.then(() => this.handle(params));
|
|
36326
|
-
this.queue = next.catch(() => {
|
|
36327
|
-
});
|
|
36328
|
-
return next;
|
|
36329
|
-
}
|
|
36330
|
-
async recover() {
|
|
36331
|
-
for (const state of await this.store.list?.() ?? []) {
|
|
36332
|
-
if (state.diagnostic) {
|
|
36333
|
-
try {
|
|
36334
|
-
await this.remote("report_effect_diagnostic", state.diagnostic);
|
|
36335
|
-
state.diagnostic = null;
|
|
36336
|
-
await this.store.save(state);
|
|
36337
|
-
} catch {
|
|
36338
|
-
this.warn("Foundocs measurement status is pending; no inference was repeated.");
|
|
36339
|
-
}
|
|
36340
|
-
}
|
|
36341
|
-
if (!state.closed || state.settled || !state.preparationId) continue;
|
|
36342
|
-
try {
|
|
36343
|
-
const { coordinator } = await this.factory({ recovery: true });
|
|
36344
|
-
const result = await coordinator.flush(state.taskId);
|
|
36345
|
-
if (result.reason === "coordinator_active") continue;
|
|
36346
|
-
if (result.status === "report_pending") {
|
|
36347
|
-
await this.diagnostic(state, "failed", "report_pending");
|
|
36348
|
-
continue;
|
|
36349
|
-
}
|
|
36350
|
-
state.settled = true;
|
|
36351
|
-
if (["reported", "already_reported"].includes(result.status)) {
|
|
36352
|
-
const failed = result.result && result.result.status !== "completed";
|
|
36353
|
-
await this.diagnostic(state, failed ? "failed" : "completed", failed ? "local_failure" : null);
|
|
36354
|
-
} else await this.diagnostic(state, "failed", result.status === "nothing_pending" ? "local_failure" : safeReason(result));
|
|
36355
|
-
} catch {
|
|
36356
|
-
this.warn("Foundocs measurement recovery pending; no inference was repeated.");
|
|
36357
|
-
}
|
|
36358
|
-
}
|
|
36359
|
-
}
|
|
36360
|
-
async diagnostic(state, status, reason = null) {
|
|
36361
|
-
state.sequence = (state.sequence ?? 0) + 1;
|
|
36362
|
-
state.diagnostic = { requestId: randomUUID2(), taskId: state.taskId, sequence: state.sequence, status, reason };
|
|
36363
|
-
try {
|
|
36364
|
-
await this.store.save(state);
|
|
36365
|
-
} catch {
|
|
36366
|
-
this.warn("Foundocs measurement status could not be saved locally.");
|
|
36367
|
-
}
|
|
36368
|
-
try {
|
|
36369
|
-
await this.remote("report_effect_diagnostic", state.diagnostic);
|
|
36370
|
-
state.diagnostic = null;
|
|
36371
|
-
await this.store.save(state);
|
|
36372
|
-
} catch {
|
|
36373
|
-
this.warn("Foundocs measurement status could not be delivered; local status retained.");
|
|
36374
|
-
}
|
|
36375
|
-
}
|
|
36376
|
-
async handle(params) {
|
|
36377
|
-
const { effectTask, effectTaskId, effectTaskComplete, ...args } = params.arguments ?? {};
|
|
36378
|
-
const forward = () => this.remote(params.name, args, true);
|
|
36379
|
-
if (args.project_id !== this.projectId) {
|
|
36380
|
-
if (effectTask || effectTaskId || effectTaskComplete) throw new Error("Automatic measurement project mismatch");
|
|
36381
|
-
return forward();
|
|
36382
|
-
}
|
|
36383
|
-
if (effectReads.has(params.name)) {
|
|
36384
|
-
if (!effectTask) return forward();
|
|
36385
|
-
const taskId = effectTask?.taskId ?? (UUID.test(args.taskId ?? "") ? args.taskId : UUID.test(args.readId ?? "") ? args.readId : randomUUID2());
|
|
36386
|
-
if (!UUID.test(taskId) || args.taskId && args.taskId !== taskId || effectTask && args.effectPreparationId) throw new Error("Conflicting measurement task");
|
|
36387
|
-
let state2;
|
|
36388
|
-
try {
|
|
36389
|
-
state2 = await this.store.load(taskId);
|
|
36390
|
-
} catch (e) {
|
|
36391
|
-
args.taskId = taskId;
|
|
36392
|
-
try {
|
|
36393
|
-
await this.remote("report_effect_diagnostic", { requestId: randomUUID2(), taskId, sequence: 0, status: "skipped", reason: safeReason(e) });
|
|
36394
|
-
} catch {
|
|
36395
|
-
this.warn("Foundocs measurement storage unavailable.");
|
|
36396
|
-
}
|
|
36397
|
-
return forward();
|
|
36398
|
-
}
|
|
36399
|
-
if (!state2) {
|
|
36400
|
-
state2 = { taskId, retrievals: [], evaluated: [], exposed: false, closed: false, expiresAt: new Date(Date.now() + 864e5).toISOString() };
|
|
36401
|
-
try {
|
|
36402
|
-
await this.store.save(state2);
|
|
36403
|
-
} catch (e) {
|
|
36404
|
-
args.taskId = taskId;
|
|
36405
|
-
try {
|
|
36406
|
-
await this.remote("report_effect_diagnostic", { requestId: randomUUID2(), taskId, sequence: 0, status: "skipped", reason: safeReason(e) });
|
|
36407
|
-
} catch {
|
|
36408
|
-
this.warn("Foundocs measurement storage unavailable.");
|
|
36409
|
-
}
|
|
36410
|
-
return forward();
|
|
36411
|
-
}
|
|
36412
|
-
try {
|
|
36413
|
-
const policy = await this.remote("get_effect_measurement_policy", {});
|
|
36414
|
-
if (!policy.enabled) state2.skipped = "disabled";
|
|
36415
|
-
else if (!effectTask?.question || !effectTask?.criteria) state2.skipped = "missing_preparation";
|
|
36416
|
-
else {
|
|
36417
|
-
const brief = { taskId, question: effectTask.question, knownContext: effectTask.knownContext ?? "", criteria: effectTask.criteria };
|
|
36418
|
-
validateBrief(brief);
|
|
36419
|
-
state2.briefHash = hash(brief);
|
|
36420
|
-
const { coordinator, config: config2 } = await this.factory();
|
|
36421
|
-
if (!config2?.enabled) state2.skipped = "consent_required";
|
|
36422
|
-
else {
|
|
36423
|
-
const result3 = await coordinator.prepare({ policy, brief, allowlist: config2.allowlist, excludePaths: config2.excludePaths, host: effectTask.host });
|
|
36424
|
-
if (result3.status === "prepared") {
|
|
36425
|
-
state2.preparationId = result3.effectPreparationId;
|
|
36426
|
-
state2.consentHash = hash(config2);
|
|
36427
|
-
} else state2.skipped = safeReason(result3);
|
|
36428
|
-
}
|
|
36429
|
-
}
|
|
36430
|
-
} catch (e) {
|
|
36431
|
-
state2.skipped = safeReason(e);
|
|
36432
|
-
}
|
|
36433
|
-
await this.diagnostic(state2, state2.preparationId ? "prepared" : "skipped", state2.preparationId ? null : state2.skipped);
|
|
36434
|
-
} else if (effectTask?.question && state2.briefHash !== hash({ taskId, question: effectTask.question, knownContext: effectTask.knownContext ?? "", criteria: effectTask.criteria })) {
|
|
36435
|
-
throw new Error("Do not change a frozen information task");
|
|
36436
|
-
}
|
|
36437
|
-
if (!state2.preparationId && !state2.skipped) state2.skipped = "missing_preparation";
|
|
36438
|
-
if (state2.closed && effectTask) throw new Error("Information task is closed; never add later context or relabel the same question.");
|
|
36439
|
-
if (state2.closed || Date.parse(state2.expiresAt) <= Date.now()) {
|
|
36440
|
-
delete args.effectPreparationId;
|
|
36441
|
-
args.taskId = taskId;
|
|
36442
|
-
return forward();
|
|
36443
|
-
}
|
|
36444
|
-
args.taskId = taskId;
|
|
36445
|
-
if (state2.preparationId) args.effectPreparationId = state2.preparationId;
|
|
36446
|
-
state2.exposed = true;
|
|
36447
|
-
try {
|
|
36448
|
-
await this.store.save(state2);
|
|
36449
|
-
} catch (e) {
|
|
36450
|
-
delete args.effectPreparationId;
|
|
36451
|
-
await this.diagnostic(state2, "skipped", safeReason(e));
|
|
36452
|
-
return forward();
|
|
36453
|
-
}
|
|
36454
|
-
const result2 = await forward(), body = dataOf(result2);
|
|
36455
|
-
if (body?.ok) {
|
|
36456
|
-
state2.retrievals = [.../* @__PURE__ */ new Set([...state2.retrievals, ...retrievalIds(body.data)])];
|
|
36457
|
-
try {
|
|
36458
|
-
await this.store.save(state2);
|
|
36459
|
-
} catch {
|
|
36460
|
-
this.warn("Foundocs retrieval tracking could not be saved; no extra reads were requested.");
|
|
36461
|
-
}
|
|
36462
|
-
}
|
|
36463
|
-
return result2;
|
|
36464
|
-
}
|
|
36465
|
-
const isBatch = params.name === "report_retrieval_evaluations";
|
|
36466
|
-
if (isBatch && effectTaskId && args.taskId !== effectTaskId) throw new Error("Conflicting measurement task");
|
|
36467
|
-
const result = await forward();
|
|
36468
|
-
if (!evaluationTools.has(params.name) || !effectTaskId || !dataOf(result)?.ok) return result;
|
|
36469
|
-
if (!UUID.test(effectTaskId)) return result;
|
|
36470
|
-
let state;
|
|
36471
|
-
try {
|
|
36472
|
-
state = await this.store.load(effectTaskId);
|
|
36473
|
-
} catch {
|
|
36474
|
-
this.warn("Foundocs evaluation tracking unavailable.");
|
|
36475
|
-
return result;
|
|
36476
|
-
}
|
|
36477
|
-
if (!state || state.closed) return result;
|
|
36478
|
-
const submitted = isBatch ? args.items : [args];
|
|
36479
|
-
const tracked = submitted.filter((item) => state.retrievals.includes(item.retrievalId));
|
|
36480
|
-
if (!tracked.length) return result;
|
|
36481
|
-
state.evaluated = [.../* @__PURE__ */ new Set([...state.evaluated, ...tracked.map((item) => item.retrievalId)])];
|
|
36482
|
-
if (tracked.some((item) => item.verdict === "beneficial")) state.beneficial = true;
|
|
36483
|
-
try {
|
|
36484
|
-
await this.store.save(state);
|
|
36485
|
-
} catch {
|
|
36486
|
-
this.warn("Foundocs evaluation tracking could not be saved; no comparison started.");
|
|
36487
|
-
return result;
|
|
36488
|
-
}
|
|
36489
|
-
if (!effectTaskComplete) return result;
|
|
36490
|
-
if (state.retrievals.some((id) => !state.evaluated.includes(id))) {
|
|
36491
|
-
await this.diagnostic(state, "skipped", "incomplete_evaluation");
|
|
36492
|
-
return result;
|
|
36493
|
-
}
|
|
36494
|
-
state.closed = true;
|
|
36495
|
-
try {
|
|
36496
|
-
await this.store.save(state);
|
|
36497
|
-
} catch {
|
|
36498
|
-
this.warn("Foundocs task closure could not be saved; no comparison started.");
|
|
36499
|
-
return result;
|
|
36500
|
-
}
|
|
36501
|
-
if (!state.preparationId || !state.beneficial) {
|
|
36502
|
-
state.settled = true;
|
|
36503
|
-
await this.diagnostic(state, "skipped", state.skipped ?? "no_beneficial_retrieval");
|
|
36504
|
-
return result;
|
|
36505
|
-
}
|
|
36506
|
-
const job = this.run(state).catch(() => this.warn("Foundocs automatic measurement failed; ordinary work continues."));
|
|
36507
|
-
this.jobs.add(job);
|
|
36508
|
-
void job.finally(() => this.jobs.delete(job));
|
|
36509
|
-
return result;
|
|
36510
|
-
}
|
|
36511
|
-
async run(state) {
|
|
36512
|
-
try {
|
|
36513
|
-
const { coordinator, config: config2 } = await this.factory();
|
|
36514
|
-
if (!config2?.enabled || state.consentHash !== hash(config2)) {
|
|
36515
|
-
state.settled = true;
|
|
36516
|
-
await this.diagnostic(state, "skipped", "consent_required");
|
|
36517
|
-
return;
|
|
36518
|
-
}
|
|
36519
|
-
await this.diagnostic(state, "running");
|
|
36520
|
-
const result = await coordinator.run({ taskId: state.taskId, retrievalIds: state.retrievals });
|
|
36521
|
-
state.settled = !["report_pending"].includes(result.status);
|
|
36522
|
-
if (result.status === "reported" || result.status === "already_reported") {
|
|
36523
|
-
const failed = result.result && result.result.status !== "completed";
|
|
36524
|
-
await this.diagnostic(state, failed ? "failed" : "completed", failed ? "local_failure" : null);
|
|
36525
|
-
} else await this.diagnostic(state, result.status === "report_pending" ? "failed" : "skipped", result.status === "report_pending" ? "report_pending" : safeReason(result));
|
|
36526
|
-
} catch (e) {
|
|
36527
|
-
await this.diagnostic(state, "failed", safeReason(e));
|
|
36528
|
-
}
|
|
36529
|
-
}
|
|
36530
|
-
async drain() {
|
|
36531
|
-
await this.queue;
|
|
36532
|
-
await Promise.allSettled([...this.jobs]);
|
|
36533
|
-
}
|
|
36534
|
-
};
|
|
36535
|
-
function automaticStore(base) {
|
|
36536
|
-
const path = (taskId) => {
|
|
36537
|
-
if (!UUID.test(taskId)) throw new Error("Invalid task");
|
|
36538
|
-
return join2(base, taskId, "automatic.json");
|
|
36539
|
-
};
|
|
36540
|
-
return {
|
|
36541
|
-
async list() {
|
|
36542
|
-
await privateDir(base);
|
|
36543
|
-
const result = [];
|
|
36544
|
-
for (const id of await readdir2(base)) if (UUID.test(id)) {
|
|
36545
|
-
const state = await this.load(id);
|
|
36546
|
-
if (state) result.push(state);
|
|
36547
|
-
}
|
|
36548
|
-
return result;
|
|
36549
|
-
},
|
|
36550
|
-
async load(taskId) {
|
|
36551
|
-
try {
|
|
36552
|
-
return await readJson(path(taskId));
|
|
36553
|
-
} catch (e) {
|
|
36554
|
-
if (e.code === "ENOENT") return null;
|
|
36555
|
-
throw e;
|
|
36556
|
-
}
|
|
36557
|
-
},
|
|
36558
|
-
async save(state) {
|
|
36559
|
-
await privateDir(join2(base, state.taskId));
|
|
36560
|
-
await saveJson(path(state.taskId), state);
|
|
36561
|
-
}
|
|
36562
|
-
};
|
|
36563
|
-
}
|
|
36194
|
+
import { resolve as resolve3, dirname as dirname2 } from "node:path";
|
|
36564
36195
|
|
|
36565
36196
|
// skills/foundocs/scripts/episode-checkpoint.mjs
|
|
36566
36197
|
import { constants as constants2 } from "node:fs";
|
|
36567
|
-
import { open as open3, mkdir
|
|
36198
|
+
import { open as open3, mkdir, lstat as lstat2, readFile as readFile2, realpath as realpath2, rename, rm } from "node:fs/promises";
|
|
36568
36199
|
import { homedir } from "node:os";
|
|
36569
|
-
import { dirname
|
|
36570
|
-
import { createHash
|
|
36200
|
+
import { dirname, isAbsolute as isAbsolute2, join } from "node:path";
|
|
36201
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
36571
36202
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
36572
|
-
var
|
|
36573
|
-
var
|
|
36203
|
+
var hash = (value) => createHash("sha256").update(value).digest("hex");
|
|
36204
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
36574
36205
|
var TTL = 14 * 864e5;
|
|
36575
36206
|
var MAX_CHECKPOINTS = 128;
|
|
36576
36207
|
var MAX_OUTBOX = 32;
|
|
@@ -36582,16 +36213,16 @@ var unavailable = () => {
|
|
|
36582
36213
|
async function privateDirectory(path) {
|
|
36583
36214
|
if (process.platform === "win32") unavailable();
|
|
36584
36215
|
let ancestor = path;
|
|
36585
|
-
while (
|
|
36586
|
-
const st2 = await
|
|
36216
|
+
while (dirname(ancestor) !== ancestor) {
|
|
36217
|
+
const st2 = await lstat2(ancestor).catch((e) => {
|
|
36587
36218
|
if (e.code !== "ENOENT") throw e;
|
|
36588
36219
|
return null;
|
|
36589
36220
|
});
|
|
36590
36221
|
if (st2 && (!st2.isDirectory() || st2.isSymbolicLink())) unavailable();
|
|
36591
|
-
ancestor =
|
|
36222
|
+
ancestor = dirname(ancestor);
|
|
36592
36223
|
}
|
|
36593
|
-
await
|
|
36594
|
-
const st = await
|
|
36224
|
+
await mkdir(path, { recursive: true, mode: 448 });
|
|
36225
|
+
const st = await lstat2(path);
|
|
36595
36226
|
if (st.mode & 63 || st.uid !== process.getuid()) unavailable();
|
|
36596
36227
|
}
|
|
36597
36228
|
async function readState(path) {
|
|
@@ -36609,7 +36240,7 @@ async function readState(path) {
|
|
|
36609
36240
|
}
|
|
36610
36241
|
}
|
|
36611
36242
|
async function writeState(path, state) {
|
|
36612
|
-
const temporary = `${path}.${
|
|
36243
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
36613
36244
|
let file;
|
|
36614
36245
|
try {
|
|
36615
36246
|
file = await open3(temporary, "wx", 384);
|
|
@@ -36617,21 +36248,21 @@ async function writeState(path, state) {
|
|
|
36617
36248
|
await file.sync();
|
|
36618
36249
|
await file.close();
|
|
36619
36250
|
file = null;
|
|
36620
|
-
await
|
|
36251
|
+
await rename(temporary, path);
|
|
36621
36252
|
} finally {
|
|
36622
36253
|
await file?.close();
|
|
36623
|
-
await
|
|
36254
|
+
await rm(temporary, { force: true });
|
|
36624
36255
|
}
|
|
36625
36256
|
}
|
|
36626
36257
|
async function locked(directory, action) {
|
|
36627
|
-
const lock =
|
|
36258
|
+
const lock = join(directory, "checkpoint.lock");
|
|
36628
36259
|
const file = await open3(lock, "wx", 384);
|
|
36629
36260
|
try {
|
|
36630
36261
|
await file.writeFile(String(process.pid));
|
|
36631
36262
|
return await action();
|
|
36632
36263
|
} finally {
|
|
36633
36264
|
await file.close();
|
|
36634
|
-
await
|
|
36265
|
+
await rm(lock, { force: true });
|
|
36635
36266
|
}
|
|
36636
36267
|
}
|
|
36637
36268
|
function prune(state, now) {
|
|
@@ -36662,23 +36293,23 @@ function captureInput(input, checkpoint, slot, projectId, now) {
|
|
|
36662
36293
|
if (typeof capture.event.observation !== "string" || capture.event.observation.length > 3e3 || !Array.isArray(capture.event.evidence) || capture.event.evidence.length > 20 || !Array.isArray(capture.event.links) || capture.event.links.length > 20) unavailable();
|
|
36663
36294
|
if (capture.event.evidence.some((e) => typeof e.detail !== "string" || e.detail.length > 1e3)) unavailable();
|
|
36664
36295
|
}
|
|
36665
|
-
return { ...capture, project_id: projectId, requestId:
|
|
36296
|
+
return { ...capture, project_id: projectId, requestId: randomUUID() };
|
|
36666
36297
|
}
|
|
36667
36298
|
async function episodeCheckpoint(command, rootPath, input, options = {}) {
|
|
36668
36299
|
if (Buffer.byteLength(JSON.stringify(input)) > 1024 * 1024) unavailable();
|
|
36669
36300
|
const root = await realpath2(rootPath);
|
|
36670
36301
|
if (!isAbsolute2(rootPath)) unavailable();
|
|
36671
|
-
const config2 = JSON.parse(await
|
|
36672
|
-
if (!
|
|
36302
|
+
const config2 = JSON.parse(await readFile2(join(root, "foundocs.json"), "utf8"));
|
|
36303
|
+
if (!UUID.test(config2.project_id) || options.projectId && config2.project_id !== options.projectId) unavailable();
|
|
36673
36304
|
if (config2.episodes?.enabled === false || process.env.FOUNDOCS_EPISODES === "off") return { status: "disabled" };
|
|
36674
36305
|
const client = options.client;
|
|
36675
36306
|
if (!["codex", "claude"].includes(client)) return { status: "unsupported_host" };
|
|
36676
|
-
const base = options.storageDir ?? process.env.FOUNDOCS_SETUP_HOME ??
|
|
36307
|
+
const base = options.storageDir ?? process.env.FOUNDOCS_SETUP_HOME ?? join(homedir(), ".local/share/foundocs/setup");
|
|
36677
36308
|
if (!isAbsolute2(base)) unavailable();
|
|
36678
|
-
const directory =
|
|
36309
|
+
const directory = join(base, "episodes", hash(root));
|
|
36679
36310
|
await privateDirectory(directory);
|
|
36680
36311
|
return locked(directory, async () => {
|
|
36681
|
-
const path =
|
|
36312
|
+
const path = join(directory, "checkpoints.json"), state = await readState(path), now = options.now ?? Date.now();
|
|
36682
36313
|
if (!Array.isArray(state.checkpoints) || !Array.isArray(state.outbox)) unavailable();
|
|
36683
36314
|
const counts = [state.checkpoints.length, state.outbox.length];
|
|
36684
36315
|
prune(state, now);
|
|
@@ -36690,7 +36321,7 @@ async function episodeCheckpoint(command, rootPath, input, options = {}) {
|
|
|
36690
36321
|
let checkpoint = state.checkpoints.findLast((c) => c.sessionId === input.session_id);
|
|
36691
36322
|
if (input.hook_event_name === "UserPromptSubmit") {
|
|
36692
36323
|
if (checkpoint?.fallbackIssued && typeof input.prompt === "string" && input.prompt.startsWith("One bounded Foundocs checkpoint follow-up. ")) return null;
|
|
36693
|
-
const id = client === "codex" && safeId(input.turn_id) ?
|
|
36324
|
+
const id = client === "codex" && safeId(input.turn_id) ? hash(`${input.session_id}:${input.turn_id}`).slice(0, 40) : randomUUID();
|
|
36694
36325
|
checkpoint = state.checkpoints.find((c) => c.id === id);
|
|
36695
36326
|
if (!checkpoint) {
|
|
36696
36327
|
checkpoint = { id, sessionId: input.session_id, ...safeId(input.turn_id) ? { turnId: input.turn_id } : {}, client, createdAt: now, acknowledged: false, fallbackIssued: false };
|
|
@@ -36712,25 +36343,25 @@ async function episodeCheckpoint(command, rootPath, input, options = {}) {
|
|
|
36712
36343
|
} else if (command === "prepare") {
|
|
36713
36344
|
if (typeof input.slot !== "string" || !/^[a-z0-9_-]{1,40}$/.test(input.slot)) unavailable();
|
|
36714
36345
|
const settled = checkpoint.settled?.find((entry) => entry.slot === input.slot);
|
|
36715
|
-
if (settled) return { status: settled.inputHash ===
|
|
36346
|
+
if (settled) return { status: settled.inputHash === hash(JSON.stringify(input.capture)) ? "already_acknowledged" : "payload_conflict", requestId: settled.requestId, disposition: settled.disposition };
|
|
36716
36347
|
if ((checkpoint.settled ?? []).length >= 32) return { status: "checkpoint_full" };
|
|
36717
36348
|
const previous = state.outbox.find((e) => e.checkpoint === checkpoint.id && e.slot === input.slot);
|
|
36718
36349
|
if (previous) {
|
|
36719
|
-
if (previous.inputHash !==
|
|
36350
|
+
if (previous.inputHash !== hash(JSON.stringify(input.capture))) return { status: "payload_conflict", requestId: previous.payload.requestId };
|
|
36720
36351
|
output = { status: "prepared", payload: previous.payload };
|
|
36721
36352
|
} else {
|
|
36722
36353
|
if (checkpoint.createdAt + TTL <= now) return { status: "checkpoint_expired" };
|
|
36723
36354
|
if (state.outbox.length >= MAX_OUTBOX) return { status: "outbox_full" };
|
|
36724
36355
|
const payload = captureInput(input.capture, checkpoint, input.slot, config2.project_id, now);
|
|
36725
36356
|
if (Buffer.byteLength(JSON.stringify(payload)) > MAX_BYTES) unavailable();
|
|
36726
|
-
state.outbox.push({ checkpoint: checkpoint.id, slot: input.slot, inputHash:
|
|
36357
|
+
state.outbox.push({ checkpoint: checkpoint.id, slot: input.slot, inputHash: hash(JSON.stringify(input.capture)), payload, createdAt: now });
|
|
36727
36358
|
output = { status: "prepared", payload };
|
|
36728
36359
|
}
|
|
36729
36360
|
checkpoint.acknowledged = true;
|
|
36730
36361
|
} else if (command === "ack") {
|
|
36731
36362
|
const entry = state.outbox.find((e) => e.checkpoint === checkpoint.id && e.payload.requestId === input.requestId);
|
|
36732
36363
|
if (!entry) return { status: "request_unavailable" };
|
|
36733
|
-
if (!["created", "updated", "corrected", "deferred", "skipped", "unchanged"].includes(input.result?.disposition) || !
|
|
36364
|
+
if (!["created", "updated", "corrected", "deferred", "skipped", "unchanged"].includes(input.result?.disposition) || !UUID.test(input.result?.candidate?.id)) unavailable();
|
|
36734
36365
|
checkpoint.settled ??= [];
|
|
36735
36366
|
checkpoint.settled.push({ slot: entry.slot, inputHash: entry.inputHash, requestId: entry.payload.requestId, disposition: input.result.disposition });
|
|
36736
36367
|
state.outbox = state.outbox.filter((e) => e !== entry);
|
|
@@ -36754,14 +36385,14 @@ if (process.argv[1]?.endsWith("episode-checkpoint.mjs") && pathToFileURL2(proces
|
|
|
36754
36385
|
let output;
|
|
36755
36386
|
try {
|
|
36756
36387
|
if (flag !== "--root" || !isAbsolute2(root)) unavailable();
|
|
36757
|
-
const script = await realpath2(process.argv[1]),
|
|
36758
|
-
const client = ["codex", "claude"].find((c) => script ===
|
|
36759
|
-
let
|
|
36388
|
+
const script = await realpath2(process.argv[1]), canonical = await realpath2(root);
|
|
36389
|
+
const client = ["codex", "claude"].find((c) => script === join(canonical, c === "codex" ? ".agents" : ".claude", "skills/foundocs/scripts/episode-checkpoint.mjs"));
|
|
36390
|
+
let text = "";
|
|
36760
36391
|
for await (const chunk of process.stdin) {
|
|
36761
|
-
|
|
36762
|
-
if (Buffer.byteLength(
|
|
36392
|
+
text += chunk;
|
|
36393
|
+
if (Buffer.byteLength(text) > 1024 * 1024) unavailable();
|
|
36763
36394
|
}
|
|
36764
|
-
output = await episodeCheckpoint(command, root, JSON.parse(
|
|
36395
|
+
output = await episodeCheckpoint(command, root, JSON.parse(text), { client });
|
|
36765
36396
|
} catch {
|
|
36766
36397
|
output = command === "hook" ? null : { status: "unavailable" };
|
|
36767
36398
|
}
|
|
@@ -36831,8 +36462,7 @@ function requestError(error2, name) {
|
|
|
36831
36462
|
{ code, retryable, ...tool ? { tool } : {}, ...httpStatus !== void 0 ? { httpStatus } : {}, ...remoteCode !== void 0 ? { remoteCode } : {} }
|
|
36832
36463
|
);
|
|
36833
36464
|
}
|
|
36834
|
-
async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpoint, root, client,
|
|
36835
|
-
let automatic, automaticSupported = false, recovered = false;
|
|
36465
|
+
async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpoint, root, client, folderProject }) {
|
|
36836
36466
|
let remote, local, checkpointRoute = "remote", checkpointWasLocal = false;
|
|
36837
36467
|
let argumentDefaults, inventoryRequest;
|
|
36838
36468
|
const checkpointTool = {
|
|
@@ -36850,7 +36480,6 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36850
36480
|
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false, idempotentHint: false }
|
|
36851
36481
|
};
|
|
36852
36482
|
async function close() {
|
|
36853
|
-
await automatic?.drain();
|
|
36854
36483
|
await remote?.close().catch(() => {
|
|
36855
36484
|
});
|
|
36856
36485
|
await local?.close().catch(() => {
|
|
@@ -36859,8 +36488,7 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36859
36488
|
function refreshToolInventory() {
|
|
36860
36489
|
if (!inventoryRequest) {
|
|
36861
36490
|
argumentDefaults = void 0;
|
|
36862
|
-
|
|
36863
|
-
inventoryRequest = remote.listTools(void 0, { cacheMode: "refresh" }).then(async ({ tools }) => {
|
|
36491
|
+
inventoryRequest = remote.listTools(void 0, { cacheMode: "refresh" }).then(({ tools }) => {
|
|
36864
36492
|
if (tools.length > 2e3) throw new Error("tool inventory exceeds bound");
|
|
36865
36493
|
const defaults = /* @__PURE__ */ new Map();
|
|
36866
36494
|
for (const { name, inputSchema } of tools) {
|
|
@@ -36875,15 +36503,6 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36875
36503
|
if (name === "get_project_context" && advertisesRetrievalContext(inputSchema)) options.includeRetrievalContext = true;
|
|
36876
36504
|
defaults.set(name, options);
|
|
36877
36505
|
}
|
|
36878
|
-
automaticSupported = !!automatic && ["get_effect_measurement_policy", "prepare_effect_measurement", "report_effect_diagnostic", "report_retrieval_evaluation"].every((name) => defaults.has(name));
|
|
36879
|
-
if (automaticSupported && !recovered) {
|
|
36880
|
-
try {
|
|
36881
|
-
await automatic.recover();
|
|
36882
|
-
} catch {
|
|
36883
|
-
process.stderr.write("Foundocs measurement recovery unavailable; ordinary MCP continues.\n");
|
|
36884
|
-
}
|
|
36885
|
-
recovered = true;
|
|
36886
|
-
}
|
|
36887
36506
|
argumentDefaults = defaults;
|
|
36888
36507
|
return tools;
|
|
36889
36508
|
}).finally(() => {
|
|
@@ -36920,23 +36539,6 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36920
36539
|
connecting = void 0;
|
|
36921
36540
|
}));
|
|
36922
36541
|
if (!folderProject) await ensureConnected();
|
|
36923
|
-
if (automaticFactory && automaticBase) automatic = new AutomaticMeasurement({
|
|
36924
|
-
projectId,
|
|
36925
|
-
factory: automaticFactory,
|
|
36926
|
-
store: automaticStore(automaticBase),
|
|
36927
|
-
warn: (message) => process.stderr.write(message + "\n"),
|
|
36928
|
-
remote: async (name, args, raw = false) => {
|
|
36929
|
-
const result = await remote.callTool({ name, arguments: { ...args, project_id: args.project_id ?? projectId } });
|
|
36930
|
-
if (raw) return result;
|
|
36931
|
-
const body = result.structuredContent ?? JSON.parse(result.content.find((c) => c.type === "text").text);
|
|
36932
|
-
if (!body.ok || result.isError) {
|
|
36933
|
-
const error2 = new Error("Measurement request failed");
|
|
36934
|
-
error2.code = body.error?.code;
|
|
36935
|
-
throw error2;
|
|
36936
|
-
}
|
|
36937
|
-
return body.data;
|
|
36938
|
-
}
|
|
36939
|
-
});
|
|
36940
36542
|
local = new Server({ name: "foundocs", version: "0.2.0" }, { capabilities: { tools: {} }, instructions: remote?.getInstructions() });
|
|
36941
36543
|
local.setRequestHandler("tools/list", async () => {
|
|
36942
36544
|
try {
|
|
@@ -36950,15 +36552,18 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36950
36552
|
checkpointRoute = supported ? "local" : checkpointWasLocal ? "blocked" : "remote";
|
|
36951
36553
|
if (supported) checkpointWasLocal = true;
|
|
36952
36554
|
const visible = supported ? [...tools, checkpointTool] : checkpointRoute === "blocked" ? tools.filter((tool) => tool.name !== checkpointTool.name) : tools;
|
|
36953
|
-
|
|
36555
|
+
const available = visible.filter((tool) => tool.name !== localImageTool.name);
|
|
36556
|
+
if ((root || folderProject) && available.some((tool) => tool.name === "upload_image")) available.push(localImageTool);
|
|
36557
|
+
return { tools: available };
|
|
36954
36558
|
} catch (error2) {
|
|
36955
36559
|
throw requestError(error2, "tools_list");
|
|
36956
36560
|
}
|
|
36957
36561
|
});
|
|
36958
36562
|
local.setRequestHandler("tools/call", async (request) => {
|
|
36959
36563
|
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(request.params.arguments?.project_id)) throw new ProtocolError3(ProtocolErrorCode2.InvalidParams, "Read and pass the explicit project_id from the governing foundocs.json.");
|
|
36564
|
+
const binding = folderProject ? await folderProject(local) : null;
|
|
36960
36565
|
if (folderProject) {
|
|
36961
|
-
if (
|
|
36566
|
+
if (binding?.projectId !== request.params.arguments.project_id) {
|
|
36962
36567
|
throw new ProtocolError3(ProtocolErrorCode2.InvalidParams, "No matching Foundocs binding in this folder.");
|
|
36963
36568
|
}
|
|
36964
36569
|
await ensureConnected();
|
|
@@ -36969,7 +36574,7 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36969
36574
|
let data;
|
|
36970
36575
|
try {
|
|
36971
36576
|
if (checkpointRoute !== "local" || !["prepare", "ack", "skip", "pending", "discard"].includes(args.operation)) throw new Error();
|
|
36972
|
-
const storageDir =
|
|
36577
|
+
const storageDir = dirname2(dirname2(dirname2(dirname2(dirname2(credentialPath)))));
|
|
36973
36578
|
data = await episodeCheckpoint(args.operation, root, args, { client, storageDir, projectId });
|
|
36974
36579
|
} catch {
|
|
36975
36580
|
data = { status: "unavailable" };
|
|
@@ -36981,13 +36586,13 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36981
36586
|
const { name, arguments: args } = request.params;
|
|
36982
36587
|
if (!argumentDefaults) await refreshToolInventory().catch(() => {
|
|
36983
36588
|
});
|
|
36589
|
+
if (name === localImageTool.name) {
|
|
36590
|
+
if (!argumentDefaults?.has("upload_image") || !binding && (!root || args.project_id !== projectId)) throw new ProtocolError3(ProtocolErrorCode2.InvalidParams, "Image upload is unavailable for this project.");
|
|
36591
|
+
return await uploadLocalImage({ root: binding?.root ?? root, args, endpoint: url2, credential: () => readCredential(credentialPath, projectId, workspaceId) });
|
|
36592
|
+
}
|
|
36984
36593
|
const defaults = { ...argumentDefaults?.get(name) };
|
|
36985
36594
|
if (args?.view !== "index") delete defaults.includeRetrievalContext;
|
|
36986
36595
|
const params = Object.keys(defaults).length > 0 ? { ...request.params, arguments: { ...defaults, ...args } } : request.params;
|
|
36987
|
-
if (automaticSupported) return await automatic.call(params);
|
|
36988
|
-
if (args && ["effectTask", "effectTaskId", "effectTaskComplete"].some((key) => Object.hasOwn(args, key))) {
|
|
36989
|
-
throw new ProtocolError3(ProtocolErrorCode2.InvalidParams, "Automatic measurement metadata requires the current installer and server.");
|
|
36990
|
-
}
|
|
36991
36596
|
return await remote.callTool(params);
|
|
36992
36597
|
} catch (error2) {
|
|
36993
36598
|
throw requestError(error2, request.params.name);
|
|
@@ -37008,7 +36613,7 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
37008
36613
|
process.exitCode = 1;
|
|
37009
36614
|
}
|
|
37010
36615
|
}
|
|
37011
|
-
if (process.argv[1] && import.meta.url === pathToFileURL3(
|
|
36616
|
+
if (process.argv[1] && import.meta.url === pathToFileURL3(resolve3(process.argv[1])).href) {
|
|
37012
36617
|
const [credentialPath, projectId, workspaceId, mcpUrl] = process.argv.slice(2);
|
|
37013
36618
|
await runBridge({ credentialPath, projectId, workspaceId, mcpUrl });
|
|
37014
36619
|
}
|