@chrischall/hellofresh-mcp 0.3.0 → 0.5.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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +18 -1
- package/dist/bundle.js +1057 -168
- package/dist/client.js +6 -0
- package/dist/index.js +4 -1
- package/dist/normalize.js +50 -0
- package/dist/session-cache.js +33 -0
- package/dist/session.js +115 -10
- package/dist/support.js +256 -0
- package/dist/tools/index.js +2 -0
- package/dist/tools/reads.js +28 -4
- package/dist/tools/support.js +290 -0
- package/dist/tools/writes/shared.js +1 -1
- package/dist/version.js +1 -1
- package/manifest.json +28 -2
- package/mint.yaml +15 -1
- package/package.json +1 -1
- package/server.json +14 -2
- package/skills/hellofresh/SKILL.md +27 -2
package/dist/bundle.js
CHANGED
|
@@ -199,8 +199,8 @@ var require_util = __commonJS({
|
|
|
199
199
|
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
200
200
|
return source.slice(start, end);
|
|
201
201
|
}
|
|
202
|
-
function floatSafeRemainder2(val,
|
|
203
|
-
const ratio = val /
|
|
202
|
+
function floatSafeRemainder2(val, step2) {
|
|
203
|
+
const ratio = val / step2;
|
|
204
204
|
const roundedRatio = Math.round(ratio);
|
|
205
205
|
const tolerance = 4 * Number.EPSILON * Math.max(Math.abs(ratio), 1);
|
|
206
206
|
if (Math.abs(ratio - roundedRatio) < tolerance)
|
|
@@ -320,14 +320,14 @@ var require_util = __commonJS({
|
|
|
320
320
|
}
|
|
321
321
|
function randomString2(length = 10) {
|
|
322
322
|
const chars = "abcdefghijklmnopqrstuvwxyz";
|
|
323
|
-
let
|
|
323
|
+
let str2 = "";
|
|
324
324
|
for (let i = 0; i < length; i++) {
|
|
325
|
-
|
|
325
|
+
str2 += chars[Math.floor(Math.random() * chars.length)];
|
|
326
326
|
}
|
|
327
|
-
return
|
|
327
|
+
return str2;
|
|
328
328
|
}
|
|
329
|
-
function esc2(
|
|
330
|
-
return JSON.stringify(
|
|
329
|
+
function esc2(str2) {
|
|
330
|
+
return JSON.stringify(str2);
|
|
331
331
|
}
|
|
332
332
|
function slugify2(input2) {
|
|
333
333
|
return input2.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -442,8 +442,8 @@ var require_util = __commonJS({
|
|
|
442
442
|
"symbol",
|
|
443
443
|
"undefined"
|
|
444
444
|
]);
|
|
445
|
-
function escapeRegex2(
|
|
446
|
-
return
|
|
445
|
+
function escapeRegex2(str2) {
|
|
446
|
+
return str2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
447
447
|
}
|
|
448
448
|
function clone2(inst, def, params) {
|
|
449
449
|
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
@@ -709,13 +709,13 @@ var require_util = __commonJS({
|
|
|
709
709
|
return "unknown";
|
|
710
710
|
}
|
|
711
711
|
var highSurrogate2 = /[\uD800-\uDBFF]/;
|
|
712
|
-
function codePointLength2(
|
|
713
|
-
const units =
|
|
714
|
-
if (!highSurrogate2.test(
|
|
712
|
+
function codePointLength2(str2) {
|
|
713
|
+
const units = str2.length;
|
|
714
|
+
if (!highSurrogate2.test(str2))
|
|
715
715
|
return units;
|
|
716
716
|
let count = units;
|
|
717
717
|
for (let i = 0; i < units - 1; i++) {
|
|
718
|
-
if ((
|
|
718
|
+
if ((str2.charCodeAt(i) & 64512) === 55296 && (str2.charCodeAt(i + 1) & 64512) === 56320) {
|
|
719
719
|
count--;
|
|
720
720
|
i++;
|
|
721
721
|
}
|
|
@@ -3741,9 +3741,9 @@ var require_schemas = __commonJS({
|
|
|
3741
3741
|
return payload;
|
|
3742
3742
|
}
|
|
3743
3743
|
const value = input2?.[def.discriminator];
|
|
3744
|
-
const
|
|
3745
|
-
if (
|
|
3746
|
-
return
|
|
3744
|
+
const opt2 = disc.value.get(value);
|
|
3745
|
+
if (opt2 && (value !== void 0 || ctx.direction !== "backward")) {
|
|
3746
|
+
return opt2._zod.run(payload, ctx);
|
|
3747
3747
|
}
|
|
3748
3748
|
if (def.unionFallback || ctx.direction === "backward") {
|
|
3749
3749
|
return _super(payload, ctx);
|
|
@@ -4930,7 +4930,7 @@ var require_memoizer = __commonJS({
|
|
|
4930
4930
|
var NONE2 = 0;
|
|
4931
4931
|
var ASSUMED2 = 1;
|
|
4932
4932
|
var PROVEN2 = 2;
|
|
4933
|
-
function isRecursive2(inst, stack,
|
|
4933
|
+
function isRecursive2(inst, stack, resolve3) {
|
|
4934
4934
|
const cached2 = recursive2.get(inst);
|
|
4935
4935
|
if (cached2 !== void 0)
|
|
4936
4936
|
return cached2 ? PROVEN2 : NONE2;
|
|
@@ -4940,7 +4940,7 @@ var require_memoizer = __commonJS({
|
|
|
4940
4940
|
let result = NONE2;
|
|
4941
4941
|
const check2 = (child) => {
|
|
4942
4942
|
if (result !== PROVEN2 && child?._zod) {
|
|
4943
|
-
const answer = isRecursive2(child, stack,
|
|
4943
|
+
const answer = isRecursive2(child, stack, resolve3);
|
|
4944
4944
|
if (answer > result)
|
|
4945
4945
|
result = answer;
|
|
4946
4946
|
}
|
|
@@ -4951,7 +4951,7 @@ var require_memoizer = __commonJS({
|
|
|
4951
4951
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
4952
4952
|
if (spread && !desc.enumerable)
|
|
4953
4953
|
continue;
|
|
4954
|
-
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack,
|
|
4954
|
+
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack, resolve3) : NONE2;
|
|
4955
4955
|
if (child > answer)
|
|
4956
4956
|
answer = child;
|
|
4957
4957
|
}
|
|
@@ -5015,7 +5015,7 @@ var require_memoizer = __commonJS({
|
|
|
5015
5015
|
break;
|
|
5016
5016
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
5017
5017
|
case "lazy": {
|
|
5018
|
-
const inner = def._cachedInner ?? (
|
|
5018
|
+
const inner = def._cachedInner ?? (resolve3 ? inst._zod.innerType : void 0);
|
|
5019
5019
|
merge2(inner ? isRecursive2(inner, stack, false) : ASSUMED2);
|
|
5020
5020
|
break;
|
|
5021
5021
|
}
|
|
@@ -16569,9 +16569,9 @@ ${code2}
|
|
|
16569
16569
|
if (options.length === 1) {
|
|
16570
16570
|
return generateCheck2(doc, ctx, options[0], accessor);
|
|
16571
16571
|
}
|
|
16572
|
-
const allLiterals = options.every((
|
|
16572
|
+
const allLiterals = options.every((opt2) => opt2._zod.def.type === "literal" && !opt2._zod.def.checks?.length);
|
|
16573
16573
|
if (allLiterals) {
|
|
16574
|
-
const values = new Set(options.flatMap((
|
|
16574
|
+
const values = new Set(options.flatMap((opt2) => opt2._zod.def.values));
|
|
16575
16575
|
const valuesConst = addConstant2(ctx, values);
|
|
16576
16576
|
doc.write(`if (!${valuesConst}.has(${accessor})) return INVALID;`);
|
|
16577
16577
|
return accessor;
|
|
@@ -16579,14 +16579,14 @@ ${code2}
|
|
|
16579
16579
|
const outputVar = newVar2(ctx);
|
|
16580
16580
|
doc.write(`let ${outputVar};`);
|
|
16581
16581
|
for (let i = 0; i < options.length; i++) {
|
|
16582
|
-
const
|
|
16582
|
+
const opt2 = options[i];
|
|
16583
16583
|
if (i === 0) {
|
|
16584
16584
|
doc.write(`${outputVar} = (() => {`);
|
|
16585
16585
|
} else {
|
|
16586
16586
|
doc.write(`if (${outputVar} === INVALID) ${outputVar} = (() => {`);
|
|
16587
16587
|
}
|
|
16588
16588
|
doc.indented((d) => {
|
|
16589
|
-
const branchOutput = generateCheck2(d, ctx,
|
|
16589
|
+
const branchOutput = generateCheck2(d, ctx, opt2, accessor);
|
|
16590
16590
|
d.write(`return ${branchOutput};`);
|
|
16591
16591
|
});
|
|
16592
16592
|
doc.write(`})();`);
|
|
@@ -22795,9 +22795,9 @@ var require_visit = __commonJS({
|
|
|
22795
22795
|
const oldOptions = def.options;
|
|
22796
22796
|
let changed = false;
|
|
22797
22797
|
const newOptions = [];
|
|
22798
|
-
for (const
|
|
22799
|
-
const mapped = run(
|
|
22800
|
-
if (mapped !==
|
|
22798
|
+
for (const opt2 of oldOptions) {
|
|
22799
|
+
const mapped = run(opt2);
|
|
22800
|
+
if (mapped !== opt2)
|
|
22801
22801
|
changed = true;
|
|
22802
22802
|
newOptions.push(mapped);
|
|
22803
22803
|
}
|
|
@@ -23450,9 +23450,9 @@ function redactValues(text, values, opts = {}) {
|
|
|
23450
23450
|
return out;
|
|
23451
23451
|
}
|
|
23452
23452
|
function truncateErrorMessage(text, max = DEFAULT_ERROR_MESSAGE_MAX, opts = {}) {
|
|
23453
|
-
const
|
|
23453
|
+
const str2 = text === null || text === void 0 ? "" : String(text);
|
|
23454
23454
|
const cap = Math.max(ERROR_REDACTION_INPUT_MAX, max);
|
|
23455
|
-
const capped =
|
|
23455
|
+
const capped = str2.length > cap ? str2.slice(0, cap) : str2;
|
|
23456
23456
|
const scrubbed = opts.values !== void 0 ? redactValues(capped, opts.values, opts.placeholder !== void 0 ? { placeholder: opts.placeholder } : {}) : capped;
|
|
23457
23457
|
const redacted = redactSecrets(scrubbed);
|
|
23458
23458
|
if (redacted.length <= max)
|
|
@@ -23746,8 +23746,8 @@ function cleanRegex(source) {
|
|
|
23746
23746
|
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
23747
23747
|
return source.slice(start, end);
|
|
23748
23748
|
}
|
|
23749
|
-
function floatSafeRemainder(val,
|
|
23750
|
-
const ratio = val /
|
|
23749
|
+
function floatSafeRemainder(val, step2) {
|
|
23750
|
+
const ratio = val / step2;
|
|
23751
23751
|
const roundedRatio = Math.round(ratio);
|
|
23752
23752
|
const tolerance = 4 * Number.EPSILON * Math.max(Math.abs(ratio), 1);
|
|
23753
23753
|
if (Math.abs(ratio - roundedRatio) < tolerance)
|
|
@@ -23866,14 +23866,14 @@ function promiseAllObject(promisesObj) {
|
|
|
23866
23866
|
}
|
|
23867
23867
|
function randomString(length = 10) {
|
|
23868
23868
|
const chars = "abcdefghijklmnopqrstuvwxyz";
|
|
23869
|
-
let
|
|
23869
|
+
let str2 = "";
|
|
23870
23870
|
for (let i = 0; i < length; i++) {
|
|
23871
|
-
|
|
23871
|
+
str2 += chars[Math.floor(Math.random() * chars.length)];
|
|
23872
23872
|
}
|
|
23873
|
-
return
|
|
23873
|
+
return str2;
|
|
23874
23874
|
}
|
|
23875
|
-
function esc(
|
|
23876
|
-
return JSON.stringify(
|
|
23875
|
+
function esc(str2) {
|
|
23876
|
+
return JSON.stringify(str2);
|
|
23877
23877
|
}
|
|
23878
23878
|
function slugify(input2) {
|
|
23879
23879
|
return input2.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -23917,8 +23917,8 @@ function numKeys(data) {
|
|
|
23917
23917
|
}
|
|
23918
23918
|
return keyCount;
|
|
23919
23919
|
}
|
|
23920
|
-
function escapeRegex(
|
|
23921
|
-
return
|
|
23920
|
+
function escapeRegex(str2) {
|
|
23921
|
+
return str2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
23922
23922
|
}
|
|
23923
23923
|
function clone(inst, def, params) {
|
|
23924
23924
|
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
@@ -24172,13 +24172,13 @@ function getSizableOrigin(input2) {
|
|
|
24172
24172
|
return "file";
|
|
24173
24173
|
return "unknown";
|
|
24174
24174
|
}
|
|
24175
|
-
function codePointLength(
|
|
24176
|
-
const units =
|
|
24177
|
-
if (!highSurrogate.test(
|
|
24175
|
+
function codePointLength(str2) {
|
|
24176
|
+
const units = str2.length;
|
|
24177
|
+
if (!highSurrogate.test(str2))
|
|
24178
24178
|
return units;
|
|
24179
24179
|
let count = units;
|
|
24180
24180
|
for (let i = 0; i < units - 1; i++) {
|
|
24181
|
-
if ((
|
|
24181
|
+
if ((str2.charCodeAt(i) & 64512) === 55296 && (str2.charCodeAt(i + 1) & 64512) === 56320) {
|
|
24182
24182
|
count--;
|
|
24183
24183
|
i++;
|
|
24184
24184
|
}
|
|
@@ -27354,9 +27354,9 @@ var init_schemas = __esm({
|
|
|
27354
27354
|
return payload;
|
|
27355
27355
|
}
|
|
27356
27356
|
const value = input2?.[def.discriminator];
|
|
27357
|
-
const
|
|
27358
|
-
if (
|
|
27359
|
-
return
|
|
27357
|
+
const opt2 = disc.value.get(value);
|
|
27358
|
+
if (opt2 && (value !== void 0 || ctx.direction !== "backward")) {
|
|
27359
|
+
return opt2._zod.run(payload, ctx);
|
|
27360
27360
|
}
|
|
27361
27361
|
if (def.unionFallback || ctx.direction === "backward") {
|
|
27362
27362
|
return _super(payload, ctx);
|
|
@@ -28163,7 +28163,7 @@ function isRef(value) {
|
|
|
28163
28163
|
function cloneIssues(issues) {
|
|
28164
28164
|
return issues.map((iss) => iss.path ? { ...iss, path: iss.path.slice() } : { ...iss });
|
|
28165
28165
|
}
|
|
28166
|
-
function isRecursive(inst, stack,
|
|
28166
|
+
function isRecursive(inst, stack, resolve3) {
|
|
28167
28167
|
const cached2 = recursive.get(inst);
|
|
28168
28168
|
if (cached2 !== void 0)
|
|
28169
28169
|
return cached2 ? PROVEN : NONE;
|
|
@@ -28173,7 +28173,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
28173
28173
|
let result = NONE;
|
|
28174
28174
|
const check2 = (child) => {
|
|
28175
28175
|
if (result !== PROVEN && child?._zod) {
|
|
28176
|
-
const answer = isRecursive(child, stack,
|
|
28176
|
+
const answer = isRecursive(child, stack, resolve3);
|
|
28177
28177
|
if (answer > result)
|
|
28178
28178
|
result = answer;
|
|
28179
28179
|
}
|
|
@@ -28184,7 +28184,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
28184
28184
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
28185
28185
|
if (spread && !desc.enumerable)
|
|
28186
28186
|
continue;
|
|
28187
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
28187
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve3) : NONE;
|
|
28188
28188
|
if (child > answer)
|
|
28189
28189
|
answer = child;
|
|
28190
28190
|
}
|
|
@@ -28248,7 +28248,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
28248
28248
|
break;
|
|
28249
28249
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
28250
28250
|
case "lazy": {
|
|
28251
|
-
const inner = def._cachedInner ?? (
|
|
28251
|
+
const inner = def._cachedInner ?? (resolve3 ? inst._zod.innerType : void 0);
|
|
28252
28252
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
28253
28253
|
break;
|
|
28254
28254
|
}
|
|
@@ -37698,9 +37698,9 @@ function generateUnionCheck(doc, ctx, schema, accessor) {
|
|
|
37698
37698
|
if (options.length === 1) {
|
|
37699
37699
|
return generateCheck(doc, ctx, options[0], accessor);
|
|
37700
37700
|
}
|
|
37701
|
-
const allLiterals = options.every((
|
|
37701
|
+
const allLiterals = options.every((opt2) => opt2._zod.def.type === "literal" && !opt2._zod.def.checks?.length);
|
|
37702
37702
|
if (allLiterals) {
|
|
37703
|
-
const values = new Set(options.flatMap((
|
|
37703
|
+
const values = new Set(options.flatMap((opt2) => opt2._zod.def.values));
|
|
37704
37704
|
const valuesConst = addConstant(ctx, values);
|
|
37705
37705
|
doc.write(`if (!${valuesConst}.has(${accessor})) return INVALID;`);
|
|
37706
37706
|
return accessor;
|
|
@@ -37708,14 +37708,14 @@ function generateUnionCheck(doc, ctx, schema, accessor) {
|
|
|
37708
37708
|
const outputVar = newVar(ctx);
|
|
37709
37709
|
doc.write(`let ${outputVar};`);
|
|
37710
37710
|
for (let i = 0; i < options.length; i++) {
|
|
37711
|
-
const
|
|
37711
|
+
const opt2 = options[i];
|
|
37712
37712
|
if (i === 0) {
|
|
37713
37713
|
doc.write(`${outputVar} = (() => {`);
|
|
37714
37714
|
} else {
|
|
37715
37715
|
doc.write(`if (${outputVar} === INVALID) ${outputVar} = (() => {`);
|
|
37716
37716
|
}
|
|
37717
37717
|
doc.indented((d) => {
|
|
37718
|
-
const branchOutput = generateCheck(d, ctx,
|
|
37718
|
+
const branchOutput = generateCheck(d, ctx, opt2, accessor);
|
|
37719
37719
|
d.write(`return ${branchOutput};`);
|
|
37720
37720
|
});
|
|
37721
37721
|
doc.write(`})();`);
|
|
@@ -43578,9 +43578,9 @@ function visit(schema, fnOrHandlers) {
|
|
|
43578
43578
|
const oldOptions = def.options;
|
|
43579
43579
|
let changed = false;
|
|
43580
43580
|
const newOptions = [];
|
|
43581
|
-
for (const
|
|
43582
|
-
const mapped = run(
|
|
43583
|
-
if (mapped !==
|
|
43581
|
+
for (const opt2 of oldOptions) {
|
|
43582
|
+
const mapped = run(opt2);
|
|
43583
|
+
if (mapped !== opt2)
|
|
43584
43584
|
changed = true;
|
|
43585
43585
|
newOptions.push(mapped);
|
|
43586
43586
|
}
|
|
@@ -44048,6 +44048,18 @@ function readEnvVar(key, opts = {}) {
|
|
|
44048
44048
|
}
|
|
44049
44049
|
return opts.default;
|
|
44050
44050
|
}
|
|
44051
|
+
function parseBoolEnv(key, opts = {}) {
|
|
44052
|
+
const fallback = opts.default ?? false;
|
|
44053
|
+
const raw = readEnvVar(key, { env: opts.env });
|
|
44054
|
+
if (raw === void 0)
|
|
44055
|
+
return fallback;
|
|
44056
|
+
const token = raw.toLowerCase();
|
|
44057
|
+
if (TRUE_TOKENS.has(token))
|
|
44058
|
+
return true;
|
|
44059
|
+
if (FALSE_TOKENS.has(token))
|
|
44060
|
+
return false;
|
|
44061
|
+
return fallback;
|
|
44062
|
+
}
|
|
44051
44063
|
function expandPath(p) {
|
|
44052
44064
|
let expanded = p;
|
|
44053
44065
|
if (p === "~") {
|
|
@@ -44068,10 +44080,12 @@ function readPortEnv(key, fallback, opts = {}) {
|
|
|
44068
44080
|
return fallback;
|
|
44069
44081
|
return port;
|
|
44070
44082
|
}
|
|
44071
|
-
var PLACEHOLDER_RE;
|
|
44083
|
+
var PLACEHOLDER_RE, TRUE_TOKENS, FALSE_TOKENS;
|
|
44072
44084
|
var init_config = __esm({
|
|
44073
44085
|
"node_modules/@chrischall/mcp-utils/dist/config/index.js"() {
|
|
44074
44086
|
PLACEHOLDER_RE = /^\$\{[^}]*\}$/;
|
|
44087
|
+
TRUE_TOKENS = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
|
|
44088
|
+
FALSE_TOKENS = /* @__PURE__ */ new Set(["0", "false", "no", "off"]);
|
|
44075
44089
|
}
|
|
44076
44090
|
});
|
|
44077
44091
|
|
|
@@ -46739,7 +46753,7 @@ import { createServer, Server as HttpServer } from "node:http";
|
|
|
46739
46753
|
async function electRole(opts) {
|
|
46740
46754
|
const server = createServer();
|
|
46741
46755
|
const bindTimeoutMs = opts.bindTimeoutMs ?? DEFAULT_BIND_TIMEOUT_MS;
|
|
46742
|
-
return new Promise((
|
|
46756
|
+
return new Promise((resolve3, reject) => {
|
|
46743
46757
|
let timer;
|
|
46744
46758
|
const clearBindTimer = () => {
|
|
46745
46759
|
if (timer) {
|
|
@@ -46755,7 +46769,7 @@ async function electRole(opts) {
|
|
|
46755
46769
|
server.close();
|
|
46756
46770
|
} catch {
|
|
46757
46771
|
}
|
|
46758
|
-
|
|
46772
|
+
resolve3({ role: "peer" });
|
|
46759
46773
|
} else {
|
|
46760
46774
|
reject(e);
|
|
46761
46775
|
}
|
|
@@ -46763,7 +46777,7 @@ async function electRole(opts) {
|
|
|
46763
46777
|
const onListening = () => {
|
|
46764
46778
|
clearBindTimer();
|
|
46765
46779
|
server.removeListener("error", onError);
|
|
46766
|
-
|
|
46780
|
+
resolve3({ role: "host", server });
|
|
46767
46781
|
};
|
|
46768
46782
|
server.once("error", onError);
|
|
46769
46783
|
server.once("listening", onListening);
|
|
@@ -49044,7 +49058,7 @@ var require_websocket = __commonJS({
|
|
|
49044
49058
|
var net = __require("net");
|
|
49045
49059
|
var querystring = __require("querystring");
|
|
49046
49060
|
var tls = __require("tls");
|
|
49047
|
-
var { randomBytes:
|
|
49061
|
+
var { randomBytes: randomBytes7, createHash: createHash4 } = __require("crypto");
|
|
49048
49062
|
var { Duplex, Readable } = __require("stream");
|
|
49049
49063
|
var { URL: URL2 } = __require("url");
|
|
49050
49064
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -49594,7 +49608,7 @@ var require_websocket = __commonJS({
|
|
|
49594
49608
|
}
|
|
49595
49609
|
}
|
|
49596
49610
|
const defaultPort = isSecure ? 443 : 80;
|
|
49597
|
-
const key =
|
|
49611
|
+
const key = randomBytes7(16).toString("base64");
|
|
49598
49612
|
const request = isSecure ? https.request : http.request;
|
|
49599
49613
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
49600
49614
|
let perMessageDeflate;
|
|
@@ -51407,10 +51421,10 @@ async function startHost(opts) {
|
|
|
51407
51421
|
function resetSessionPromise() {
|
|
51408
51422
|
ownRetryableRefusal = false;
|
|
51409
51423
|
ownSessionSettled = false;
|
|
51410
|
-
ownSessionReady = new Promise((
|
|
51424
|
+
ownSessionReady = new Promise((resolve3, reject) => {
|
|
51411
51425
|
resolveOwnSession = (st) => {
|
|
51412
51426
|
ownSessionSettled = true;
|
|
51413
|
-
|
|
51427
|
+
resolve3(st);
|
|
51414
51428
|
};
|
|
51415
51429
|
rejectOwnSession = (e) => {
|
|
51416
51430
|
ownSessionSettled = true;
|
|
@@ -51844,7 +51858,7 @@ async function startHost(opts) {
|
|
|
51844
51858
|
});
|
|
51845
51859
|
});
|
|
51846
51860
|
return {
|
|
51847
|
-
close: () => new Promise((
|
|
51861
|
+
close: () => new Promise((resolve3) => {
|
|
51848
51862
|
for (const client of wss.clients) {
|
|
51849
51863
|
try {
|
|
51850
51864
|
client.terminate();
|
|
@@ -51852,7 +51866,7 @@ async function startHost(opts) {
|
|
|
51852
51866
|
}
|
|
51853
51867
|
}
|
|
51854
51868
|
wss.close(() => {
|
|
51855
|
-
opts.httpServer.close(() =>
|
|
51869
|
+
opts.httpServer.close(() => resolve3());
|
|
51856
51870
|
});
|
|
51857
51871
|
}),
|
|
51858
51872
|
sendOwnInner: async (inner) => {
|
|
@@ -51915,11 +51929,11 @@ async function startPeer(opts) {
|
|
|
51915
51929
|
maxPayload: opts.maxPayloadBytes ?? MAX_PAYLOAD_BYTES
|
|
51916
51930
|
});
|
|
51917
51931
|
const dialTimeoutMs = opts.dialTimeoutMs ?? PEER_DIAL_TIMEOUT_MS;
|
|
51918
|
-
await new Promise((
|
|
51932
|
+
await new Promise((resolve3, reject) => {
|
|
51919
51933
|
let timer;
|
|
51920
51934
|
const onOpen = () => {
|
|
51921
51935
|
cleanup();
|
|
51922
|
-
|
|
51936
|
+
resolve3();
|
|
51923
51937
|
};
|
|
51924
51938
|
const onError = (e) => {
|
|
51925
51939
|
cleanup();
|
|
@@ -52011,10 +52025,10 @@ async function startPeer(opts) {
|
|
|
52011
52025
|
function resetSessionPromise() {
|
|
52012
52026
|
retryableRefusal = false;
|
|
52013
52027
|
sessionPromiseSettled = false;
|
|
52014
|
-
sessionPromise = new Promise((
|
|
52028
|
+
sessionPromise = new Promise((resolve3, reject) => {
|
|
52015
52029
|
resolveFirstReady = (st) => {
|
|
52016
52030
|
sessionPromiseSettled = true;
|
|
52017
|
-
|
|
52031
|
+
resolve3(st);
|
|
52018
52032
|
};
|
|
52019
52033
|
rejectFirstReady = (e) => {
|
|
52020
52034
|
sessionPromiseSettled = true;
|
|
@@ -53331,8 +53345,8 @@ var init_ws_server = __esm({
|
|
|
53331
53345
|
async _fetchOnceWithTimeout(init, fetchOpts = {}) {
|
|
53332
53346
|
const id = this.nextRequestId++;
|
|
53333
53347
|
const inner = { type: "request", id, op: "fetch", init };
|
|
53334
|
-
const pending = this.guardPending(new Promise((
|
|
53335
|
-
this.pending.set(id,
|
|
53348
|
+
const pending = this.guardPending(new Promise((resolve3) => {
|
|
53349
|
+
this.pending.set(id, resolve3);
|
|
53336
53350
|
}));
|
|
53337
53351
|
try {
|
|
53338
53352
|
await this.sendInnerFrame(inner, {
|
|
@@ -53373,13 +53387,13 @@ var init_ws_server = __esm({
|
|
|
53373
53387
|
try {
|
|
53374
53388
|
return await Promise.race([
|
|
53375
53389
|
pending,
|
|
53376
|
-
new Promise((
|
|
53390
|
+
new Promise((resolve3) => {
|
|
53377
53391
|
timer = setTimeout(() => {
|
|
53378
53392
|
this.pending.delete(id);
|
|
53379
53393
|
const elapsedMs = Date.now() - start;
|
|
53380
53394
|
const base = `fetchproxy: ${init.url} did not respond within ${timeoutMs}ms`;
|
|
53381
53395
|
const error62 = isRetrySafeOnTimeout(init.method, fetchOpts.retryOnTimeout) ? base : withNotResentNote(base);
|
|
53382
|
-
|
|
53396
|
+
resolve3({
|
|
53383
53397
|
ok: false,
|
|
53384
53398
|
error: error62,
|
|
53385
53399
|
kind: "timeout",
|
|
@@ -53879,8 +53893,8 @@ var init_ws_server = __esm({
|
|
|
53879
53893
|
const tabUrl = `https://${host}/`;
|
|
53880
53894
|
inner = { type: "request", id, op: "read_cookies", init: { tabUrl } };
|
|
53881
53895
|
}
|
|
53882
|
-
const pending = this.guardPending(new Promise((
|
|
53883
|
-
this.pendingReadCookies.set(id,
|
|
53896
|
+
const pending = this.guardPending(new Promise((resolve3) => {
|
|
53897
|
+
this.pendingReadCookies.set(id, resolve3);
|
|
53884
53898
|
}));
|
|
53885
53899
|
await this.sendInnerFrame(inner);
|
|
53886
53900
|
const result = await this._withVerbTimeout(pending, this.pendingReadCookies, id, `https://${host}`);
|
|
@@ -53938,8 +53952,8 @@ var init_ws_server = __esm({
|
|
|
53938
53952
|
...cookiePath !== void 0 ? { path: cookiePath } : {}
|
|
53939
53953
|
}
|
|
53940
53954
|
};
|
|
53941
|
-
const pending = this.guardPending(new Promise((
|
|
53942
|
-
this.pendingWriteCookies.set(id, { resolve:
|
|
53955
|
+
const pending = this.guardPending(new Promise((resolve3, reject) => {
|
|
53956
|
+
this.pendingWriteCookies.set(id, { resolve: resolve3, reject });
|
|
53943
53957
|
}));
|
|
53944
53958
|
await this.sendInnerFrame(inner);
|
|
53945
53959
|
return this._withVerbTimeout(
|
|
@@ -54009,8 +54023,8 @@ var init_ws_server = __esm({
|
|
|
54009
54023
|
...opts.pointers ? { pointers: { ...opts.pointers } } : {}
|
|
54010
54024
|
}
|
|
54011
54025
|
};
|
|
54012
|
-
const pending = this.guardPending(new Promise((
|
|
54013
|
-
this.pendingStorage.set(id, { resolve:
|
|
54026
|
+
const pending = this.guardPending(new Promise((resolve3, reject) => {
|
|
54027
|
+
this.pendingStorage.set(id, { resolve: resolve3, reject });
|
|
54014
54028
|
}));
|
|
54015
54029
|
await this.sendInnerFrame(inner);
|
|
54016
54030
|
return this._withVerbTimeout(pending, this.pendingStorage, id, `https://${host}`);
|
|
@@ -54068,8 +54082,8 @@ var init_ws_server = __esm({
|
|
|
54068
54082
|
...opts.timeoutMs !== void 0 ? { timeoutMs: opts.timeoutMs } : {}
|
|
54069
54083
|
}
|
|
54070
54084
|
};
|
|
54071
|
-
const pending = this.guardPending(new Promise((
|
|
54072
|
-
this.pendingCapture.set(id, { resolve:
|
|
54085
|
+
const pending = this.guardPending(new Promise((resolve3, reject) => {
|
|
54086
|
+
this.pendingCapture.set(id, { resolve: resolve3, reject });
|
|
54073
54087
|
}));
|
|
54074
54088
|
await this.sendInnerFrame(inner);
|
|
54075
54089
|
return this._withVerbTimeout(
|
|
@@ -54116,8 +54130,8 @@ var init_ws_server = __esm({
|
|
|
54116
54130
|
...opts.timeoutMs !== void 0 ? { timeoutMs: opts.timeoutMs } : {}
|
|
54117
54131
|
}
|
|
54118
54132
|
};
|
|
54119
|
-
const pending = this.guardPending(new Promise((
|
|
54120
|
-
this.pendingRedirect.set(id, { resolve:
|
|
54133
|
+
const pending = this.guardPending(new Promise((resolve3, reject) => {
|
|
54134
|
+
this.pendingRedirect.set(id, { resolve: resolve3, reject });
|
|
54121
54135
|
}));
|
|
54122
54136
|
await this.sendInnerFrame(inner);
|
|
54123
54137
|
return this._withVerbTimeout(
|
|
@@ -54212,8 +54226,8 @@ var init_ws_server = __esm({
|
|
|
54212
54226
|
...opts.timeoutMs !== void 0 ? { timeoutMs: opts.timeoutMs } : {}
|
|
54213
54227
|
}
|
|
54214
54228
|
};
|
|
54215
|
-
const pending = this.guardPending(new Promise((
|
|
54216
|
-
this.pendingDownload.set(id, { resolve:
|
|
54229
|
+
const pending = this.guardPending(new Promise((resolve3, reject) => {
|
|
54230
|
+
this.pendingDownload.set(id, { resolve: resolve3, reject });
|
|
54217
54231
|
}));
|
|
54218
54232
|
await this.sendInnerFrame(inner);
|
|
54219
54233
|
return this._withVerbTimeout(
|
|
@@ -54273,8 +54287,8 @@ var init_ws_server = __esm({
|
|
|
54273
54287
|
keys: [...opts.keys]
|
|
54274
54288
|
}
|
|
54275
54289
|
};
|
|
54276
|
-
const pending = this.guardPending(new Promise((
|
|
54277
|
-
this.pendingIdb.set(id, { resolve:
|
|
54290
|
+
const pending = this.guardPending(new Promise((resolve3, reject) => {
|
|
54291
|
+
this.pendingIdb.set(id, { resolve: resolve3, reject });
|
|
54278
54292
|
}));
|
|
54279
54293
|
await this.sendInnerFrame(inner);
|
|
54280
54294
|
return this._withVerbTimeout(pending, this.pendingIdb, id, origin);
|
|
@@ -54313,8 +54327,8 @@ var init_ws_server = __esm({
|
|
|
54313
54327
|
op: "read_dom",
|
|
54314
54328
|
init: { origin, names: [...opts.names] }
|
|
54315
54329
|
};
|
|
54316
|
-
const pending = this.guardPending(new Promise((
|
|
54317
|
-
this.pendingStorage.set(id, { resolve:
|
|
54330
|
+
const pending = this.guardPending(new Promise((resolve3, reject) => {
|
|
54331
|
+
this.pendingStorage.set(id, { resolve: resolve3, reject });
|
|
54318
54332
|
}));
|
|
54319
54333
|
await this.sendInnerFrame(inner);
|
|
54320
54334
|
return this._withVerbTimeout(pending, this.pendingStorage, id, origin);
|
|
@@ -54359,8 +54373,8 @@ var init_ws_server = __esm({
|
|
|
54359
54373
|
op: "read_dom_list",
|
|
54360
54374
|
init: { origin, name: opts.name }
|
|
54361
54375
|
};
|
|
54362
|
-
const pending = this.guardPending(new Promise((
|
|
54363
|
-
this.pendingDomList.set(id, { resolve:
|
|
54376
|
+
const pending = this.guardPending(new Promise((resolve3, reject) => {
|
|
54377
|
+
this.pendingDomList.set(id, { resolve: resolve3, reject });
|
|
54364
54378
|
}));
|
|
54365
54379
|
await this.sendInnerFrame(inner);
|
|
54366
54380
|
return this._withVerbTimeout(pending, this.pendingDomList, id, origin);
|
|
@@ -54405,8 +54419,8 @@ var init_ws_server = __esm({
|
|
|
54405
54419
|
...opts.tabUrl !== void 0 ? { tabUrl: opts.tabUrl } : {}
|
|
54406
54420
|
}
|
|
54407
54421
|
};
|
|
54408
|
-
const pending = this.guardPending(new Promise((
|
|
54409
|
-
this.pendingGraphql.set(id, { resolve:
|
|
54422
|
+
const pending = this.guardPending(new Promise((resolve3, reject) => {
|
|
54423
|
+
this.pendingGraphql.set(id, { resolve: resolve3, reject });
|
|
54410
54424
|
}));
|
|
54411
54425
|
const retrySafe = opts.retryOnTimeout === true;
|
|
54412
54426
|
await this.sendInnerFrame(inner, { resendable: retrySafe });
|
|
@@ -55002,7 +55016,7 @@ var init_throttle2 = __esm({
|
|
|
55002
55016
|
}
|
|
55003
55017
|
const deficit = 1 - this.tokens;
|
|
55004
55018
|
const waitMs = Math.ceil(deficit / this.ratePerMs);
|
|
55005
|
-
await new Promise((
|
|
55019
|
+
await new Promise((resolve3) => setTimeout(resolve3, waitMs));
|
|
55006
55020
|
}
|
|
55007
55021
|
}
|
|
55008
55022
|
};
|
|
@@ -55024,13 +55038,13 @@ var init_backoff = __esm({
|
|
|
55024
55038
|
|
|
55025
55039
|
// node_modules/@fetchproxy/server/dist/deadline.js
|
|
55026
55040
|
function withDeadline(inner, ms) {
|
|
55027
|
-
return new Promise((
|
|
55041
|
+
return new Promise((resolve3, reject) => {
|
|
55028
55042
|
let settled = false;
|
|
55029
55043
|
const timer = setTimeout(() => {
|
|
55030
55044
|
if (settled)
|
|
55031
55045
|
return;
|
|
55032
55046
|
settled = true;
|
|
55033
|
-
|
|
55047
|
+
resolve3({ timedOut: true });
|
|
55034
55048
|
}, ms);
|
|
55035
55049
|
if (typeof timer === "object" && typeof timer.unref === "function") {
|
|
55036
55050
|
timer.unref();
|
|
@@ -55040,7 +55054,7 @@ function withDeadline(inner, ms) {
|
|
|
55040
55054
|
if (settled)
|
|
55041
55055
|
return;
|
|
55042
55056
|
settled = true;
|
|
55043
|
-
|
|
55057
|
+
resolve3({ timedOut: false, value });
|
|
55044
55058
|
}, (err) => {
|
|
55045
55059
|
clearTimeout(timer);
|
|
55046
55060
|
if (settled)
|
|
@@ -55145,7 +55159,7 @@ function chunk(items, size) {
|
|
|
55145
55159
|
return pages;
|
|
55146
55160
|
}
|
|
55147
55161
|
function sleep2(ms) {
|
|
55148
|
-
return new Promise((
|
|
55162
|
+
return new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
55149
55163
|
}
|
|
55150
55164
|
var init_batch = __esm({
|
|
55151
55165
|
"node_modules/@fetchproxy/server/dist/batch.js"() {
|
|
@@ -60681,14 +60695,14 @@ function inputRequiredRoundsExceededMessage(method, maxRounds) {
|
|
|
60681
60695
|
return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
|
|
60682
60696
|
}
|
|
60683
60697
|
function sleep(ms, signal) {
|
|
60684
|
-
return new Promise((
|
|
60698
|
+
return new Promise((resolve3, reject) => {
|
|
60685
60699
|
if (signal?.aborted) {
|
|
60686
60700
|
reject(signal.reason instanceof SdkError ? signal.reason : new SdkError(SdkErrorCode.RequestTimeout, String(signal.reason)));
|
|
60687
60701
|
return;
|
|
60688
60702
|
}
|
|
60689
60703
|
const timer = setTimeout(() => {
|
|
60690
60704
|
signal?.removeEventListener("abort", onAbort);
|
|
60691
|
-
|
|
60705
|
+
resolve3();
|
|
60692
60706
|
}, ms);
|
|
60693
60707
|
const onAbort = () => {
|
|
60694
60708
|
clearTimeout(timer);
|
|
@@ -61487,7 +61501,7 @@ var Protocol = class {
|
|
|
61487
61501
|
const flowStartedAt = Date.now();
|
|
61488
61502
|
let onAbort;
|
|
61489
61503
|
let cleanupMessageId;
|
|
61490
|
-
return new Promise((
|
|
61504
|
+
return new Promise((resolve3, reject) => {
|
|
61491
61505
|
const earlyReject = (error62) => {
|
|
61492
61506
|
reject(error62);
|
|
61493
61507
|
};
|
|
@@ -61556,7 +61570,7 @@ var Protocol = class {
|
|
|
61556
61570
|
}
|
|
61557
61571
|
if (decoded.kind === "invalid") return reject(decoded.error);
|
|
61558
61572
|
if (decoded.kind === "input_required") {
|
|
61559
|
-
if (options?.allowInputRequired === true) return
|
|
61573
|
+
if (options?.allowInputRequired === true) return resolve3(manualInputRequiredValue(decoded));
|
|
61560
61574
|
const flow = {
|
|
61561
61575
|
codec: codec2,
|
|
61562
61576
|
request,
|
|
@@ -61568,11 +61582,11 @@ var Protocol = class {
|
|
|
61568
61582
|
params
|
|
61569
61583
|
}, resultSchema, legOptions)
|
|
61570
61584
|
};
|
|
61571
|
-
return
|
|
61585
|
+
return resolve3(this._resolveNonCompleteResult(decoded, flow));
|
|
61572
61586
|
}
|
|
61573
61587
|
const result = decoded.result;
|
|
61574
61588
|
validateStandardSchema(resultSchema, result).then((parseResult) => {
|
|
61575
|
-
if (parseResult.success)
|
|
61589
|
+
if (parseResult.success) resolve3(parseResult.data);
|
|
61576
61590
|
else reject(new SdkError(SdkErrorCode.InvalidResult, `Invalid result for ${request.method}: ${parseResult.error}`));
|
|
61577
61591
|
}, reject);
|
|
61578
61592
|
});
|
|
@@ -61978,7 +61992,7 @@ var require_code$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
61978
61992
|
}
|
|
61979
61993
|
exports._ = _;
|
|
61980
61994
|
const plus = new _Code("+");
|
|
61981
|
-
function
|
|
61995
|
+
function str2(strs, ...args) {
|
|
61982
61996
|
const expr = [safeStringify(strs[0])];
|
|
61983
61997
|
let i = 0;
|
|
61984
61998
|
while (i < args.length) {
|
|
@@ -61989,7 +62003,7 @@ var require_code$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
61989
62003
|
optimize(expr);
|
|
61990
62004
|
return new _Code(expr);
|
|
61991
62005
|
}
|
|
61992
|
-
exports.str =
|
|
62006
|
+
exports.str = str2;
|
|
61993
62007
|
function addCodeArg(code2, arg) {
|
|
61994
62008
|
if (arg instanceof _Code) code2.push(...arg._items);
|
|
61995
62009
|
else if (arg instanceof Name) code2.push(arg);
|
|
@@ -62022,7 +62036,7 @@ var require_code$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
62022
62036
|
if (typeof b == "string" && b[0] === '"' && !(a instanceof Name)) return `"${a}${b.slice(1)}`;
|
|
62023
62037
|
}
|
|
62024
62038
|
function strConcat(c1, c2) {
|
|
62025
|
-
return c2.emptyStr() ? c1 : c1.emptyStr() ? c2 :
|
|
62039
|
+
return c2.emptyStr() ? c1 : c1.emptyStr() ? c2 : str2`${c1}${c2}`;
|
|
62026
62040
|
}
|
|
62027
62041
|
exports.strConcat = strConcat;
|
|
62028
62042
|
function interpolate(x) {
|
|
@@ -62901,21 +62915,21 @@ var require_util2 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
62901
62915
|
return (0, codegen_1._)`${topSchemaRef}${schemaPath}${(0, codegen_1.getProperty)(keyword)}`;
|
|
62902
62916
|
}
|
|
62903
62917
|
exports.schemaRefOrVal = schemaRefOrVal;
|
|
62904
|
-
function unescapeFragment(
|
|
62905
|
-
return unescapeJsonPointer(decodeURIComponent(
|
|
62918
|
+
function unescapeFragment(str2) {
|
|
62919
|
+
return unescapeJsonPointer(decodeURIComponent(str2));
|
|
62906
62920
|
}
|
|
62907
62921
|
exports.unescapeFragment = unescapeFragment;
|
|
62908
|
-
function escapeFragment(
|
|
62909
|
-
return encodeURIComponent(escapeJsonPointer(
|
|
62922
|
+
function escapeFragment(str2) {
|
|
62923
|
+
return encodeURIComponent(escapeJsonPointer(str2));
|
|
62910
62924
|
}
|
|
62911
62925
|
exports.escapeFragment = escapeFragment;
|
|
62912
|
-
function escapeJsonPointer(
|
|
62913
|
-
if (typeof
|
|
62914
|
-
return
|
|
62926
|
+
function escapeJsonPointer(str2) {
|
|
62927
|
+
if (typeof str2 == "number") return `${str2}`;
|
|
62928
|
+
return str2.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
62915
62929
|
}
|
|
62916
62930
|
exports.escapeJsonPointer = escapeJsonPointer;
|
|
62917
|
-
function unescapeJsonPointer(
|
|
62918
|
-
return
|
|
62931
|
+
function unescapeJsonPointer(str2) {
|
|
62932
|
+
return str2.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
62919
62933
|
}
|
|
62920
62934
|
exports.unescapeJsonPointer = unescapeJsonPointer;
|
|
62921
62935
|
function eachItem(xs, f) {
|
|
@@ -63801,8 +63815,8 @@ var require_json_schema_traverse = /* @__PURE__ */ __commonJSMin(((exports, modu
|
|
|
63801
63815
|
post(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
|
|
63802
63816
|
}
|
|
63803
63817
|
}
|
|
63804
|
-
function escapeJsonPtr(
|
|
63805
|
-
return
|
|
63818
|
+
function escapeJsonPtr(str2) {
|
|
63819
|
+
return str2.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
63806
63820
|
}
|
|
63807
63821
|
}));
|
|
63808
63822
|
var require_resolve = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
@@ -64488,7 +64502,7 @@ var require_compile2 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
64488
64502
|
ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, ref);
|
|
64489
64503
|
const schOrFunc = root.refs[ref];
|
|
64490
64504
|
if (schOrFunc) return schOrFunc;
|
|
64491
|
-
let _sch =
|
|
64505
|
+
let _sch = resolve3.call(this, root, ref);
|
|
64492
64506
|
if (_sch === void 0) {
|
|
64493
64507
|
const schema = (_a3 = root.localRefs) === null || _a3 === void 0 ? void 0 : _a3[ref];
|
|
64494
64508
|
const { schemaId } = this.opts;
|
|
@@ -64514,7 +64528,7 @@ var require_compile2 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
64514
64528
|
function sameSchemaEnv(s1, s2) {
|
|
64515
64529
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
64516
64530
|
}
|
|
64517
|
-
function
|
|
64531
|
+
function resolve3(root, ref) {
|
|
64518
64532
|
let sch;
|
|
64519
64533
|
while (typeof (sch = this.refs[ref]) == "string") ref = sch;
|
|
64520
64534
|
return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
|
|
@@ -64747,9 +64761,9 @@ var require_utils = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
64747
64761
|
isIPV6: true
|
|
64748
64762
|
};
|
|
64749
64763
|
}
|
|
64750
|
-
function findToken(
|
|
64764
|
+
function findToken(str2, token) {
|
|
64751
64765
|
let ind = 0;
|
|
64752
|
-
for (let i = 0; i <
|
|
64766
|
+
for (let i = 0; i < str2.length; i++) if (str2[i] === token) ind++;
|
|
64753
64767
|
return ind;
|
|
64754
64768
|
}
|
|
64755
64769
|
function removeDotSegments(path) {
|
|
@@ -65209,7 +65223,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
65209
65223
|
else if (typeof uri === "object") uri = parse4(serialize(uri, options), options);
|
|
65210
65224
|
return uri;
|
|
65211
65225
|
}
|
|
65212
|
-
function
|
|
65226
|
+
function resolve3(baseURI, relativeURI, options) {
|
|
65213
65227
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
65214
65228
|
const { parsed: baseParsed, malformedAuthorityOrPort: baseMalformed, malformedPercentEncoding: baseMalformedPercentEncoding, malformedSchemeSpecific: baseMalformedSchemeSpecific, malformedHost: baseMalformedHost, malformedScheme: baseMalformedScheme } = parseWithStatus(baseURI, schemelessOptions);
|
|
65215
65229
|
const { parsed: relativeParsed, malformedAuthorityOrPort: relativeMalformed, malformedPercentEncoding: relativeMalformedPercentEncoding, malformedSchemeSpecific: relativeMalformedSchemeSpecific, malformedHost: relativeMalformedHost, malformedScheme: relativeMalformedScheme } = parseWithStatus(relativeURI, schemelessOptions);
|
|
@@ -65491,7 +65505,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
65491
65505
|
const fastUri = {
|
|
65492
65506
|
SCHEMES,
|
|
65493
65507
|
normalize,
|
|
65494
|
-
resolve:
|
|
65508
|
+
resolve: resolve3,
|
|
65495
65509
|
resolveComponent,
|
|
65496
65510
|
equal,
|
|
65497
65511
|
serialize,
|
|
@@ -65564,7 +65578,7 @@ var require_core$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
65564
65578
|
const util_1 = require_util2();
|
|
65565
65579
|
const $dataRefSchema = require_data();
|
|
65566
65580
|
const uri_1 = require_uri();
|
|
65567
|
-
const defaultRegExp = (
|
|
65581
|
+
const defaultRegExp = (str2, flags) => new RegExp(str2, flags);
|
|
65568
65582
|
defaultRegExp.code = "new RegExp";
|
|
65569
65583
|
const META_IGNORE_OPTIONS = [
|
|
65570
65584
|
"removeAdditional",
|
|
@@ -65969,8 +65983,8 @@ var require_core$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
65969
65983
|
exports.default = Ajv2;
|
|
65970
65984
|
function checkOptions(checkOpts, options, msg, log = "error") {
|
|
65971
65985
|
for (const key in checkOpts) {
|
|
65972
|
-
const
|
|
65973
|
-
if (
|
|
65986
|
+
const opt2 = key;
|
|
65987
|
+
if (opt2 in options) this.logger[log](`${msg}: option ${key}. ${checkOpts[opt2]}`);
|
|
65974
65988
|
}
|
|
65975
65989
|
}
|
|
65976
65990
|
function getSchEnv(keyRef) {
|
|
@@ -66003,7 +66017,7 @@ var require_core$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
66003
66017
|
}
|
|
66004
66018
|
function getMetaSchemaOptions() {
|
|
66005
66019
|
const metaOpts = { ...this.opts };
|
|
66006
|
-
for (const
|
|
66020
|
+
for (const opt2 of META_IGNORE_OPTIONS) delete metaOpts[opt2];
|
|
66007
66021
|
return metaOpts;
|
|
66008
66022
|
}
|
|
66009
66023
|
const noLogs = {
|
|
@@ -66270,16 +66284,16 @@ var require_multipleOf = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
66270
66284
|
}));
|
|
66271
66285
|
var require_ucs2length = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
66272
66286
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66273
|
-
function ucs2length(
|
|
66274
|
-
const len =
|
|
66287
|
+
function ucs2length(str2) {
|
|
66288
|
+
const len = str2.length;
|
|
66275
66289
|
let length = 0;
|
|
66276
66290
|
let pos = 0;
|
|
66277
66291
|
let value;
|
|
66278
66292
|
while (pos < len) {
|
|
66279
66293
|
length++;
|
|
66280
|
-
value =
|
|
66294
|
+
value = str2.charCodeAt(pos++);
|
|
66281
66295
|
if (value >= 55296 && value <= 56319 && pos < len) {
|
|
66282
|
-
value =
|
|
66296
|
+
value = str2.charCodeAt(pos);
|
|
66283
66297
|
if ((value & 64512) === 56320) pos++;
|
|
66284
66298
|
}
|
|
66285
66299
|
}
|
|
@@ -68990,8 +69004,8 @@ var require_formats = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
68990
69004
|
30,
|
|
68991
69005
|
31
|
|
68992
69006
|
];
|
|
68993
|
-
function date5(
|
|
68994
|
-
const matches = DATE.exec(
|
|
69007
|
+
function date5(str2) {
|
|
69008
|
+
const matches = DATE.exec(str2);
|
|
68995
69009
|
if (!matches) return false;
|
|
68996
69010
|
const year = +matches[1];
|
|
68997
69011
|
const month = +matches[2];
|
|
@@ -69006,8 +69020,8 @@ var require_formats = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
69006
69020
|
}
|
|
69007
69021
|
const TIME = /^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i;
|
|
69008
69022
|
function getTime(strictTimeZone) {
|
|
69009
|
-
return function time3(
|
|
69010
|
-
const matches = TIME.exec(
|
|
69023
|
+
return function time3(str2) {
|
|
69024
|
+
const matches = TIME.exec(str2);
|
|
69011
69025
|
if (!matches) return false;
|
|
69012
69026
|
const hr = +matches[1];
|
|
69013
69027
|
const min = +matches[2];
|
|
@@ -69044,8 +69058,8 @@ var require_formats = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
69044
69058
|
const DATE_TIME_SEPARATOR = /t|\s/i;
|
|
69045
69059
|
function getDateTime(strictTimeZone) {
|
|
69046
69060
|
const time3 = getTime(strictTimeZone);
|
|
69047
|
-
return function date_time(
|
|
69048
|
-
const dateTime =
|
|
69061
|
+
return function date_time(str2) {
|
|
69062
|
+
const dateTime = str2.split(DATE_TIME_SEPARATOR);
|
|
69049
69063
|
return dateTime.length === 2 && date5(dateTime[0]) && time3(dateTime[1]);
|
|
69050
69064
|
};
|
|
69051
69065
|
}
|
|
@@ -69066,13 +69080,13 @@ var require_formats = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
69066
69080
|
}
|
|
69067
69081
|
const NOT_URI_FRAGMENT = /\/|:/;
|
|
69068
69082
|
const URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
69069
|
-
function uri(
|
|
69070
|
-
return NOT_URI_FRAGMENT.test(
|
|
69083
|
+
function uri(str2) {
|
|
69084
|
+
return NOT_URI_FRAGMENT.test(str2) && URI.test(str2);
|
|
69071
69085
|
}
|
|
69072
69086
|
const BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;
|
|
69073
|
-
function byte(
|
|
69087
|
+
function byte(str2) {
|
|
69074
69088
|
BYTE.lastIndex = 0;
|
|
69075
|
-
return BYTE.test(
|
|
69089
|
+
return BYTE.test(str2);
|
|
69076
69090
|
}
|
|
69077
69091
|
const MIN_INT32 = -(2 ** 31);
|
|
69078
69092
|
const MAX_INT32 = 2 ** 31 - 1;
|
|
@@ -69086,10 +69100,10 @@ var require_formats = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
69086
69100
|
return true;
|
|
69087
69101
|
}
|
|
69088
69102
|
const Z_ANCHOR = /[^\\]\\Z/;
|
|
69089
|
-
function regex(
|
|
69090
|
-
if (Z_ANCHOR.test(
|
|
69103
|
+
function regex(str2) {
|
|
69104
|
+
if (Z_ANCHOR.test(str2)) return false;
|
|
69091
69105
|
try {
|
|
69092
|
-
new RegExp(
|
|
69106
|
+
new RegExp(str2);
|
|
69093
69107
|
return true;
|
|
69094
69108
|
} catch (e) {
|
|
69095
69109
|
return false;
|
|
@@ -69362,15 +69376,15 @@ var PerRequestHTTPServerTransport = class {
|
|
|
69362
69376
|
};
|
|
69363
69377
|
if (isJSONRPCRequest(message)) {
|
|
69364
69378
|
this._requestId = message.id;
|
|
69365
|
-
let
|
|
69379
|
+
let resolve3;
|
|
69366
69380
|
let reject;
|
|
69367
69381
|
const promise2 = new Promise((promiseResolve, promiseReject) => {
|
|
69368
|
-
|
|
69382
|
+
resolve3 = promiseResolve;
|
|
69369
69383
|
reject = promiseReject;
|
|
69370
69384
|
});
|
|
69371
69385
|
this._deferredResponse = {
|
|
69372
69386
|
promise: promise2,
|
|
69373
|
-
resolve:
|
|
69387
|
+
resolve: resolve3,
|
|
69374
69388
|
reject,
|
|
69375
69389
|
settled: false
|
|
69376
69390
|
};
|
|
@@ -71206,7 +71220,7 @@ var StdioServerTransport = class {
|
|
|
71206
71220
|
}
|
|
71207
71221
|
send(message) {
|
|
71208
71222
|
if (this._closed) return Promise.reject(/* @__PURE__ */ new Error("StdioServerTransport is closed"));
|
|
71209
|
-
return new Promise((
|
|
71223
|
+
return new Promise((resolve3, reject) => {
|
|
71210
71224
|
const json2 = serializeMessage(message);
|
|
71211
71225
|
let settled = false;
|
|
71212
71226
|
const onError = (error62) => {
|
|
@@ -71221,14 +71235,14 @@ var StdioServerTransport = class {
|
|
|
71221
71235
|
settled = true;
|
|
71222
71236
|
this._stdout.off("error", onError);
|
|
71223
71237
|
this._stdout.off("drain", onDrain);
|
|
71224
|
-
|
|
71238
|
+
resolve3();
|
|
71225
71239
|
};
|
|
71226
71240
|
this._stdout.once("error", onError);
|
|
71227
71241
|
if (this._stdout.write(json2)) {
|
|
71228
71242
|
if (settled) return;
|
|
71229
71243
|
settled = true;
|
|
71230
71244
|
this._stdout.off("error", onError);
|
|
71231
|
-
|
|
71245
|
+
resolve3();
|
|
71232
71246
|
} else if (!settled) this._stdout.once("drain", onDrain);
|
|
71233
71247
|
});
|
|
71234
71248
|
}
|
|
@@ -71282,14 +71296,14 @@ var StdioConnectionChannel = class {
|
|
|
71282
71296
|
*/
|
|
71283
71297
|
async whenRequestsAnswered(timeoutMs) {
|
|
71284
71298
|
if (this._closed || this._pendingRequests.size === 0) return true;
|
|
71285
|
-
return await new Promise((
|
|
71299
|
+
return await new Promise((resolve3) => {
|
|
71286
71300
|
const waiter = () => {
|
|
71287
71301
|
clearTimeout(timer);
|
|
71288
|
-
|
|
71302
|
+
resolve3(true);
|
|
71289
71303
|
};
|
|
71290
71304
|
const timer = setTimeout(() => {
|
|
71291
71305
|
this._drainWaiters = this._drainWaiters.filter((pending) => pending !== waiter);
|
|
71292
|
-
|
|
71306
|
+
resolve3(false);
|
|
71293
71307
|
}, timeoutMs);
|
|
71294
71308
|
this._drainWaiters.push(waiter);
|
|
71295
71309
|
});
|
|
@@ -72948,6 +72962,10 @@ function tokenExpiresAtMs(set2) {
|
|
|
72948
72962
|
const exp = decodeJwtClaim(set2.access_token, "exp");
|
|
72949
72963
|
return typeof exp === "number" ? exp * 1e3 : 0;
|
|
72950
72964
|
}
|
|
72965
|
+
function toPersistedSession(set2, from) {
|
|
72966
|
+
const { user_data: _userData, ...rest } = set2;
|
|
72967
|
+
return { set: rest, own: from.own, writtenBack: from.own && from.writtenBack };
|
|
72968
|
+
}
|
|
72951
72969
|
var REDACT_HISTORY = 8;
|
|
72952
72970
|
var HelloFreshSession = class {
|
|
72953
72971
|
constructor(opts) {
|
|
@@ -72980,6 +72998,10 @@ var HelloFreshSession = class {
|
|
|
72980
72998
|
/** Whether that refresh was written back to the browser (which may then rotate it on its own). */
|
|
72981
72999
|
ownWrittenBack = false;
|
|
72982
73000
|
seen = [];
|
|
73001
|
+
/** The stored record is read once, on the first lifecycle. */
|
|
73002
|
+
restored = false;
|
|
73003
|
+
/** Identity of what was last saved, to skip rewriting an unchanged record. */
|
|
73004
|
+
savedKey;
|
|
72983
73005
|
/** A valid access token (cached, the browser's, or freshly refreshed). */
|
|
72984
73006
|
getToken() {
|
|
72985
73007
|
return this.source.getToken();
|
|
@@ -73038,10 +73060,11 @@ var HelloFreshSession = class {
|
|
|
73038
73060
|
raw = await this.bridged(() => this.opts.bridge.readAuthCookie());
|
|
73039
73061
|
} catch (err) {
|
|
73040
73062
|
const ours2 = this.latest;
|
|
73041
|
-
if (!ours2
|
|
73042
|
-
|
|
73063
|
+
if (!ours2) throw err;
|
|
73064
|
+
const ownUnwritten = ours2.refresh_token === this.ownRefreshToken && !this.ownWrittenBack;
|
|
73065
|
+
if (ownUnwritten ? !this.refreshable(ours2) : !this.fresh(ours2)) throw err;
|
|
73043
73066
|
console.error(
|
|
73044
|
-
`[hellofresh-mcp] could not read the browser session (${truncateErrorMessage(this.redact(messageOf(err)), 200)}); using this
|
|
73067
|
+
`[hellofresh-mcp] could not read the browser session (${truncateErrorMessage(this.redact(messageOf(err)), 200)}); using the last session this server knew of`
|
|
73045
73068
|
);
|
|
73046
73069
|
return ours2;
|
|
73047
73070
|
}
|
|
@@ -73054,12 +73077,38 @@ var HelloFreshSession = class {
|
|
|
73054
73077
|
return browserIsNewest ? browser : ours;
|
|
73055
73078
|
}
|
|
73056
73079
|
async lifecycle() {
|
|
73080
|
+
if (!this.restored) {
|
|
73081
|
+
this.restored = true;
|
|
73082
|
+
const stored = await this.loadStored();
|
|
73083
|
+
if (stored) this.adopt(stored);
|
|
73084
|
+
}
|
|
73057
73085
|
const newest = await this.newestSet();
|
|
73058
73086
|
if (this.fresh(newest)) {
|
|
73059
|
-
this.latest
|
|
73087
|
+
if (newest !== this.latest) {
|
|
73088
|
+
this.latest = newest;
|
|
73089
|
+
this.ownRefreshToken = void 0;
|
|
73090
|
+
}
|
|
73091
|
+
await this.persist();
|
|
73060
73092
|
return newest;
|
|
73061
73093
|
}
|
|
73062
|
-
|
|
73094
|
+
return this.locked(() => this.refreshLocked(newest));
|
|
73095
|
+
}
|
|
73096
|
+
/** Step 3, holding the store's cross-process lock. */
|
|
73097
|
+
async refreshLocked(newest) {
|
|
73098
|
+
const stored = await this.loadStored();
|
|
73099
|
+
if (stored && stored.set.issued_at > newest.issued_at && this.fresh(stored.set)) {
|
|
73100
|
+
this.adopt(stored);
|
|
73101
|
+
return stored.set;
|
|
73102
|
+
}
|
|
73103
|
+
let next;
|
|
73104
|
+
try {
|
|
73105
|
+
next = await this.refresh(newest);
|
|
73106
|
+
} catch (err) {
|
|
73107
|
+
if (err instanceof HelloFreshSessionError && (!stored || stored.set.issued_at <= newest.issued_at)) {
|
|
73108
|
+
await this.store("clear", () => this.opts.persistence?.clear?.());
|
|
73109
|
+
}
|
|
73110
|
+
throw err;
|
|
73111
|
+
}
|
|
73063
73112
|
this.latest = next;
|
|
73064
73113
|
this.ownRefreshToken = next.refresh_token;
|
|
73065
73114
|
this.ownWrittenBack = false;
|
|
@@ -73074,8 +73123,56 @@ var HelloFreshSession = class {
|
|
|
73074
73123
|
`[hellofresh-mcp] could not write the refreshed session back to the browser: ${truncateErrorMessage(this.redact(messageOf(err)), 200)}`
|
|
73075
73124
|
);
|
|
73076
73125
|
}
|
|
73126
|
+
await this.persist();
|
|
73077
73127
|
return next;
|
|
73078
73128
|
}
|
|
73129
|
+
/** Take a stored record as this process's newest known set. */
|
|
73130
|
+
adopt(stored) {
|
|
73131
|
+
this.latest = stored.set;
|
|
73132
|
+
this.ownRefreshToken = stored.own ? stored.set.refresh_token : void 0;
|
|
73133
|
+
this.ownWrittenBack = stored.own && stored.writtenBack;
|
|
73134
|
+
this.savedKey = this.keyOf(stored.set);
|
|
73135
|
+
this.remember(stored.set);
|
|
73136
|
+
}
|
|
73137
|
+
keyOf(set2) {
|
|
73138
|
+
const own2 = set2.refresh_token === this.ownRefreshToken;
|
|
73139
|
+
return `${set2.access_token}\0${set2.refresh_token}\0${own2}\0${own2 && this.ownWrittenBack}`;
|
|
73140
|
+
}
|
|
73141
|
+
async persist() {
|
|
73142
|
+
const set2 = this.latest;
|
|
73143
|
+
if (!this.opts.persistence || !set2) return;
|
|
73144
|
+
const key = this.keyOf(set2);
|
|
73145
|
+
if (key === this.savedKey) return;
|
|
73146
|
+
const own2 = set2.refresh_token === this.ownRefreshToken;
|
|
73147
|
+
const ok = await this.store(
|
|
73148
|
+
"save",
|
|
73149
|
+
() => this.opts.persistence?.save(toPersistedSession(set2, { own: own2, writtenBack: this.ownWrittenBack }))
|
|
73150
|
+
);
|
|
73151
|
+
if (ok) this.savedKey = key;
|
|
73152
|
+
}
|
|
73153
|
+
async loadStored() {
|
|
73154
|
+
let stored = null;
|
|
73155
|
+
await this.store("load", async () => {
|
|
73156
|
+
stored = await this.opts.persistence?.load() ?? null;
|
|
73157
|
+
});
|
|
73158
|
+
return stored;
|
|
73159
|
+
}
|
|
73160
|
+
locked(fn) {
|
|
73161
|
+
const store = this.opts.persistence;
|
|
73162
|
+
return store?.withLock ? store.withLock(fn) : fn();
|
|
73163
|
+
}
|
|
73164
|
+
/** Run a store operation; a failure is logged (redacted), never thrown. */
|
|
73165
|
+
async store(op, fn) {
|
|
73166
|
+
try {
|
|
73167
|
+
await fn();
|
|
73168
|
+
return true;
|
|
73169
|
+
} catch (err) {
|
|
73170
|
+
console.error(
|
|
73171
|
+
`[hellofresh-mcp] could not ${op} the ${op === "load" ? "saved " : ""}HelloFresh session on disk (${truncateErrorMessage(this.redact(messageOf(err)), 200)}); continuing without it.`
|
|
73172
|
+
);
|
|
73173
|
+
return false;
|
|
73174
|
+
}
|
|
73175
|
+
}
|
|
73079
73176
|
async bridged(fn) {
|
|
73080
73177
|
try {
|
|
73081
73178
|
return await fn();
|
|
@@ -73170,6 +73267,12 @@ var HelloFreshClient = class {
|
|
|
73170
73267
|
route: `/api/subscriptions/{id}/delivery_dates/${week}`
|
|
73171
73268
|
});
|
|
73172
73269
|
}
|
|
73270
|
+
/** A box's carrier tracking, by the public id at the end of the delivery's `tracking.tracking_link`. */
|
|
73271
|
+
getTracking(publicId) {
|
|
73272
|
+
return this.request("GET", apiPath`/scm/tracking-ids/track/public-id/${publicId}`, {
|
|
73273
|
+
route: "/scm/tracking-ids/track/public-id/{id}"
|
|
73274
|
+
});
|
|
73275
|
+
}
|
|
73173
73276
|
getProductOptions(subscriptionId) {
|
|
73174
73277
|
return this.request("GET", apiPath`/api/subscriptions/${subscriptionId}/product_options`, {
|
|
73175
73278
|
route: "/api/subscriptions/{id}/product_options"
|
|
@@ -73553,6 +73656,47 @@ function projectDelivery(d) {
|
|
|
73553
73656
|
oneOffDaySlots: (d.availableOneOffOptions ?? []).map((o) => ({ handle: o.handle, deliveryDate: o.deliveryDate }))
|
|
73554
73657
|
};
|
|
73555
73658
|
}
|
|
73659
|
+
function trackingPublicId(t) {
|
|
73660
|
+
const m = /^https:\/\/www\.hellofresh\.com\/delivery-tracking\/([0-9a-f-]{8,64})\/?$/i.exec(t?.tracking_link ?? "");
|
|
73661
|
+
return m?.[1];
|
|
73662
|
+
}
|
|
73663
|
+
var opt = (key, value) => value === void 0 || value === null || value === "" ? {} : { [key]: value };
|
|
73664
|
+
var step = (s) => ({
|
|
73665
|
+
...opt("status", s.status),
|
|
73666
|
+
...opt("statusDetail", s.status_detail),
|
|
73667
|
+
...opt("at", s.datetime),
|
|
73668
|
+
...opt("message", s.message)
|
|
73669
|
+
});
|
|
73670
|
+
function projectTracking(raw) {
|
|
73671
|
+
const boxes = (raw.boxes ?? []).filter((b) => !!b && typeof b === "object");
|
|
73672
|
+
return {
|
|
73673
|
+
boxes: boxes.map((b) => {
|
|
73674
|
+
const last = b.last_status ?? {};
|
|
73675
|
+
const photos = Array.isArray(b.proof_of_delivery_photo_urls) ? b.proof_of_delivery_photo_urls.length : 0;
|
|
73676
|
+
const history = (b.statuses ?? []).filter((s) => !!s && typeof s === "object").map(step);
|
|
73677
|
+
const lastAt = Date.parse(last.datetime ?? "");
|
|
73678
|
+
const newer = history.filter((h) => Date.parse(h.at ?? "") > (Number.isNaN(lastAt) ? -Infinity : lastAt)).sort((a, z5) => Date.parse(z5.at) - Date.parse(a.at))[0];
|
|
73679
|
+
return {
|
|
73680
|
+
...opt("carrier", b.carrier),
|
|
73681
|
+
...opt("trackingCode", b.tracking_code),
|
|
73682
|
+
...opt("status", last.status),
|
|
73683
|
+
...opt("statusDetail", last.status_detail),
|
|
73684
|
+
...opt("internalStatus", b.internal_status ?? last.internal_status),
|
|
73685
|
+
...opt("internalStatusDetail", b.internal_status_detail ?? last.internal_status_detail),
|
|
73686
|
+
...opt("statusMessage", last.message),
|
|
73687
|
+
...opt("statusAt", last.datetime),
|
|
73688
|
+
...opt("estimatedDelivery", last.est_delivery_time),
|
|
73689
|
+
...opt("carrierTrackingUrl", b.carrier_tracking_url ?? b.public_url),
|
|
73690
|
+
...opt("trackingUrl", b.hf_tracking_url),
|
|
73691
|
+
...opt("deliveryDate", b.delivery_date),
|
|
73692
|
+
delivered: last.status === "delivered" || newer?.status === "delivered",
|
|
73693
|
+
...newer ? { latestEvent: newer } : {},
|
|
73694
|
+
...photos > 0 ? { proofOfDeliveryPhotos: photos } : {},
|
|
73695
|
+
history
|
|
73696
|
+
};
|
|
73697
|
+
})
|
|
73698
|
+
};
|
|
73699
|
+
}
|
|
73556
73700
|
var QUICK_TAGS = /* @__PURE__ */ new Set(["quick", "easy-prep"]);
|
|
73557
73701
|
var QUICK_MINUTES = 30;
|
|
73558
73702
|
function isSeafoodCategory(category) {
|
|
@@ -73889,7 +74033,7 @@ async function loadAccount(client) {
|
|
|
73889
74033
|
}
|
|
73890
74034
|
return { subscription, subscriptionId: subscription.id };
|
|
73891
74035
|
}
|
|
73892
|
-
var sleepMs = (ms) => new Promise((
|
|
74036
|
+
var sleepMs = (ms) => new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
73893
74037
|
function isUnresizableFirstBox(subscription, week) {
|
|
73894
74038
|
return subscription.firstBoxDelivered === false && subscription.firstDeliveryWeek === week;
|
|
73895
74039
|
}
|
|
@@ -74338,7 +74482,7 @@ function registerGated(server, def) {
|
|
|
74338
74482
|
def.name,
|
|
74339
74483
|
{
|
|
74340
74484
|
description: `${def.description} ${CONFIRM_FLOW_SENTENCE} ${CONFIRM_INJECTION_RULE}`,
|
|
74341
|
-
annotations: toolAnnotations({ title: def.title, readOnly: false, destructive: def.destructive, idempotent: true, openWorld: true }),
|
|
74485
|
+
annotations: toolAnnotations({ title: def.title, readOnly: false, destructive: def.destructive, idempotent: def.idempotent ?? true, openWorld: true }),
|
|
74342
74486
|
_meta: def.meta,
|
|
74343
74487
|
inputSchema: external_exports.object({ ...def.input, confirmToken: confirmTokenParam })
|
|
74344
74488
|
},
|
|
@@ -75434,6 +75578,20 @@ function applyFilters(meals, f) {
|
|
|
75434
75578
|
}
|
|
75435
75579
|
function registerReadTools(server, deps2) {
|
|
75436
75580
|
const { client } = deps2;
|
|
75581
|
+
const readTracking = async (raw, full) => {
|
|
75582
|
+
const publicId = trackingPublicId(raw.tracking);
|
|
75583
|
+
if (!publicId) return {};
|
|
75584
|
+
const read = await attempt(async () => projectTracking(await client.getTracking(publicId)));
|
|
75585
|
+
if (!read.ok || read.value.boxes.length === 0) {
|
|
75586
|
+
return {
|
|
75587
|
+
tracking: { trackingCode: raw.tracking?.tracking_code || void 0, trackingUrl: raw.tracking?.tracking_link },
|
|
75588
|
+
trackingError: read.ok ? "HelloFresh returned no tracked box for this delivery." : read.reason
|
|
75589
|
+
};
|
|
75590
|
+
}
|
|
75591
|
+
const [first, ...more] = read.value.boxes;
|
|
75592
|
+
const shape = (b) => full ? b : { ...b, history: void 0 };
|
|
75593
|
+
return { tracking: shape(first), ...more.length > 0 ? { moreBoxes: more.map(shape) } : {} };
|
|
75594
|
+
};
|
|
75437
75595
|
const now = deps2.now ?? Date.now;
|
|
75438
75596
|
server.registerTool(
|
|
75439
75597
|
"hf_get_subscription",
|
|
@@ -75531,7 +75689,7 @@ function registerReadTools(server, deps2) {
|
|
|
75531
75689
|
server.registerTool(
|
|
75532
75690
|
"hf_get_delivery",
|
|
75533
75691
|
{
|
|
75534
|
-
description: "Read one HelloFresh delivery week: delivery date and slot, meal-pick cutoff, status, box size, the meals currently picked (with any premium upcharge), allowed actions, alternative delivery days,
|
|
75692
|
+
description: "Read one HelloFresh delivery week: delivery date and slot, meal-pick cutoff, status, box size, the meals currently picked (with any premium upcharge), allowed actions, alternative delivery days, the box price \u2014 HelloFresh\u2019s own checkout total plus the picked meals\u2019 premium upcharge, or a labelled local estimate when that cannot be read \u2014 and, once the box is labelled, its carrier tracking: carrier, tracking code, live status (e.g. delayed / shortage, delivered) and, in the full view, the status history.",
|
|
75535
75693
|
annotations: readOnly4("HelloFresh: get delivery"),
|
|
75536
75694
|
_meta: LOOKUP,
|
|
75537
75695
|
inputSchema: external_exports.object({
|
|
@@ -75545,10 +75703,12 @@ function registerReadTools(server, deps2) {
|
|
|
75545
75703
|
},
|
|
75546
75704
|
async ({ week, box_number, next_box_number, view }) => {
|
|
75547
75705
|
const account = await loadAccount(client);
|
|
75548
|
-
const
|
|
75706
|
+
const raw = await client.getDelivery(account.subscriptionId, week);
|
|
75707
|
+
const delivery = projectDelivery(raw);
|
|
75549
75708
|
const menu = delivery.status === "skipped" ? void 0 : await attempt(() => readMenu(client, account, delivery, week));
|
|
75550
75709
|
const selected = menu?.ok ? menu.value.selected : void 0;
|
|
75551
75710
|
const full = resolveView(view, HF_VIEWS) === "full";
|
|
75711
|
+
const tracking = await readTracking(raw, full);
|
|
75552
75712
|
let boxNumberNote;
|
|
75553
75713
|
const fallbackBoxNumber = async () => {
|
|
75554
75714
|
if (box_number !== void 0) return box_number;
|
|
@@ -75570,7 +75730,8 @@ function registerReadTools(server, deps2) {
|
|
|
75570
75730
|
...selected ? { selection: selected.map(compactSelection) } : {},
|
|
75571
75731
|
...menu && !menu.ok ? { selectionError: menu.reason } : {},
|
|
75572
75732
|
...price ? { price } : {},
|
|
75573
|
-
...boxNumberNote ? { boxNumberNote } : {}
|
|
75733
|
+
...boxNumberNote ? { boxNumberNote } : {},
|
|
75734
|
+
...tracking
|
|
75574
75735
|
});
|
|
75575
75736
|
}
|
|
75576
75737
|
);
|
|
@@ -75673,6 +75834,459 @@ function registerReadTools(server, deps2) {
|
|
|
75673
75834
|
);
|
|
75674
75835
|
}
|
|
75675
75836
|
|
|
75837
|
+
// src/tools/support.ts
|
|
75838
|
+
init_zod();
|
|
75839
|
+
import { randomUUID } from "node:crypto";
|
|
75840
|
+
|
|
75841
|
+
// src/support.ts
|
|
75842
|
+
var SIERRA_API = "https://eu.sierra.chat/-/api";
|
|
75843
|
+
var SIERRA_AGENT_KEY = "rEVzK9YBnPzNiWEBnPzNic4p0Ya-JWIRjGNmiP8amMI";
|
|
75844
|
+
var SUPPORT_SERVICE = "HelloFresh support chat";
|
|
75845
|
+
var ENTRY_REASON = "unknown-from_chat_now_button";
|
|
75846
|
+
var CHAT_LOCALE = "en-US";
|
|
75847
|
+
var DEFAULT_TIME_ZONE = "America/New_York";
|
|
75848
|
+
var TURN_TIMEOUT_MS = 9e4;
|
|
75849
|
+
var WINDOW_TOKEN_QUERY = "query embedChatRefreshWindowTokenQuery($token:String!$userIdentityToken:String$windowId:String){embedBotByToken(token:$token fullscreen:false userIdentityToken:$userIdentityToken windowId:$windowId){__typename ...on EmbedBot{windowToken}...on Node{__isNode:__typename id}}}";
|
|
75850
|
+
function parseChatStream(text) {
|
|
75851
|
+
const frames2 = [];
|
|
75852
|
+
for (const m of text.matchAll(/BOT_CHAT_EVENT_BEGIN([\s\S]*?)BOT_CHAT_EVENT_END/g)) {
|
|
75853
|
+
try {
|
|
75854
|
+
const value = JSON.parse(m[1]);
|
|
75855
|
+
if (value && typeof value === "object" && !Array.isArray(value)) frames2.push(value);
|
|
75856
|
+
} catch {
|
|
75857
|
+
}
|
|
75858
|
+
}
|
|
75859
|
+
return frames2;
|
|
75860
|
+
}
|
|
75861
|
+
var META_KEYS = /* @__PURE__ */ new Set(["timestamp", "idempotencyKey", "tags", "encryptedFullRedactionMode", "eventId", "agentInvocationId"]);
|
|
75862
|
+
var SPEAKER = { USER: "user", AGENT: "bot", HUMAN_AGENT: "human_agent" };
|
|
75863
|
+
var str = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
75864
|
+
function linksOf(attachments) {
|
|
75865
|
+
if (!Array.isArray(attachments)) return void 0;
|
|
75866
|
+
const links = attachments.flatMap((a) => {
|
|
75867
|
+
const data = a?.data;
|
|
75868
|
+
const url4 = str(data?.path);
|
|
75869
|
+
return url4 && /^https:\/\//.test(url4) ? [{ ...str(data?.label) ? { label: str(data?.label) } : {}, url: url4 }] : [];
|
|
75870
|
+
});
|
|
75871
|
+
return links.length > 0 ? links : void 0;
|
|
75872
|
+
}
|
|
75873
|
+
function projectEvents(raw) {
|
|
75874
|
+
const out = [];
|
|
75875
|
+
for (const e of raw) {
|
|
75876
|
+
if (!e || typeof e !== "object" || Array.isArray(e)) continue;
|
|
75877
|
+
const ev = e;
|
|
75878
|
+
const kind = Object.keys(ev).find((k) => !META_KEYS.has(k));
|
|
75879
|
+
if (!kind) continue;
|
|
75880
|
+
const base = { ...str(ev.timestamp) ? { at: str(ev.timestamp) } : {}, ...str(ev.eventId) ? { id: str(ev.eventId) } : {} };
|
|
75881
|
+
if (kind === "message") {
|
|
75882
|
+
const m = ev.message;
|
|
75883
|
+
const text = str(m?.text);
|
|
75884
|
+
if (!m || !text || m.isProgressIndicator === true) continue;
|
|
75885
|
+
const from = SPEAKER[String(m.author)];
|
|
75886
|
+
const links = linksOf(m.attachments);
|
|
75887
|
+
out.push({
|
|
75888
|
+
kind,
|
|
75889
|
+
...from ? { from } : {},
|
|
75890
|
+
...from === "human_agent" && str(m.displayName) ? { name: str(m.displayName) } : {},
|
|
75891
|
+
text,
|
|
75892
|
+
...base,
|
|
75893
|
+
...links ? { links } : {}
|
|
75894
|
+
});
|
|
75895
|
+
continue;
|
|
75896
|
+
}
|
|
75897
|
+
if (kind === "humanAgentParticipation") {
|
|
75898
|
+
const type = ev.humanAgentParticipation?.type;
|
|
75899
|
+
out.push({ kind: type === "JOIN" ? "agentJoined" : type === "LEAVE" ? "agentLeft" : kind, ...base });
|
|
75900
|
+
continue;
|
|
75901
|
+
}
|
|
75902
|
+
if (kind === "humanAgentTyping") continue;
|
|
75903
|
+
const detail = kind === "queueInfo" ? ev.queueInfo : void 0;
|
|
75904
|
+
out.push({ kind, ...base, ...detail !== void 0 ? { detail } : {} });
|
|
75905
|
+
}
|
|
75906
|
+
return out;
|
|
75907
|
+
}
|
|
75908
|
+
var stateEvents = (frame) => {
|
|
75909
|
+
const events = frame.state?.events;
|
|
75910
|
+
return Array.isArray(events) ? events : void 0;
|
|
75911
|
+
};
|
|
75912
|
+
function readTurn(frames2) {
|
|
75913
|
+
const turn = {};
|
|
75914
|
+
for (const f of frames2) {
|
|
75915
|
+
if (typeof f.conversationID === "string") turn.conversationID = f.conversationID;
|
|
75916
|
+
if (typeof f.encryptionKey === "string") turn.encryptionKey = f.encryptionKey;
|
|
75917
|
+
if (f.type === "state") {
|
|
75918
|
+
const events = stateEvents(f);
|
|
75919
|
+
if (events) turn.events = projectEvents(events);
|
|
75920
|
+
}
|
|
75921
|
+
}
|
|
75922
|
+
return turn;
|
|
75923
|
+
}
|
|
75924
|
+
function chatRequestBody(r) {
|
|
75925
|
+
const clientEvent = r.event.type === "start" ? { type: "start", idempotencyKey: r.idempotencyKey } : { type: "message", message: { content: r.event.text }, idempotencyKey: r.idempotencyKey, idempotencyReplayResponse: true };
|
|
75926
|
+
return {
|
|
75927
|
+
token: SIERRA_AGENT_KEY,
|
|
75928
|
+
releaseHash: "production",
|
|
75929
|
+
...r.conversation ? { conversationID: r.conversation.conversationID, encryptionKey: r.conversation.encryptionKey } : {},
|
|
75930
|
+
clientEvent,
|
|
75931
|
+
userMessageText: r.event.type === "message" ? r.event.text : "",
|
|
75932
|
+
memory: r.memory,
|
|
75933
|
+
locale: CHAT_LOCALE,
|
|
75934
|
+
timeZone: r.timeZone ?? DEFAULT_TIME_ZONE,
|
|
75935
|
+
userMessageIndex: 0,
|
|
75936
|
+
windowId: r.windowId
|
|
75937
|
+
};
|
|
75938
|
+
}
|
|
75939
|
+
function livePollBody(r) {
|
|
75940
|
+
return {
|
|
75941
|
+
token: SIERRA_AGENT_KEY,
|
|
75942
|
+
releaseHash: "production",
|
|
75943
|
+
conversationID: r.conversation.conversationID,
|
|
75944
|
+
encryptionKey: r.conversation.encryptionKey,
|
|
75945
|
+
memory: r.memory,
|
|
75946
|
+
locale: CHAT_LOCALE,
|
|
75947
|
+
timeZone: r.timeZone ?? DEFAULT_TIME_ZONE,
|
|
75948
|
+
windowId: r.windowId
|
|
75949
|
+
};
|
|
75950
|
+
}
|
|
75951
|
+
var SierraChat = class {
|
|
75952
|
+
fetchImpl;
|
|
75953
|
+
redact;
|
|
75954
|
+
timeoutMs;
|
|
75955
|
+
constructor(opts) {
|
|
75956
|
+
this.fetchImpl = opts.fetchImpl;
|
|
75957
|
+
this.redact = opts.redact ?? ((t) => t);
|
|
75958
|
+
this.timeoutMs = opts.timeoutMs ?? TURN_TIMEOUT_MS;
|
|
75959
|
+
}
|
|
75960
|
+
/** A window token for `windowId` (the `x-window-token` every chat call carries). */
|
|
75961
|
+
async windowToken(windowId) {
|
|
75962
|
+
const res = await this.post("/graphql", "application/json", {
|
|
75963
|
+
query: WINDOW_TOKEN_QUERY,
|
|
75964
|
+
variables: { token: SIERRA_AGENT_KEY, userIdentityToken: null, windowId }
|
|
75965
|
+
});
|
|
75966
|
+
const text = await res.text();
|
|
75967
|
+
let token;
|
|
75968
|
+
try {
|
|
75969
|
+
token = JSON.parse(text).data?.embedBotByToken?.windowToken;
|
|
75970
|
+
} catch {
|
|
75971
|
+
}
|
|
75972
|
+
if (typeof token !== "string" || token === "") {
|
|
75973
|
+
throw new McpToolError(`${SUPPORT_SERVICE} did not issue a window token (HTTP ${res.status}).`, { kind: "http", status: res.status });
|
|
75974
|
+
}
|
|
75975
|
+
return token;
|
|
75976
|
+
}
|
|
75977
|
+
/** One client event; the reply streams back in the same response. */
|
|
75978
|
+
async turn(body, windowToken) {
|
|
75979
|
+
const res = await this.post("/chat", "text/plain", body, { "x-window-token": windowToken });
|
|
75980
|
+
const text = await res.text();
|
|
75981
|
+
const frames2 = parseChatStream(text);
|
|
75982
|
+
if (frames2.length === 0) {
|
|
75983
|
+
throw new McpToolError(`${SUPPORT_SERVICE} answered HTTP ${res.status} with no chat events.`, { kind: "http", status: res.status });
|
|
75984
|
+
}
|
|
75985
|
+
return readTurn(frames2);
|
|
75986
|
+
}
|
|
75987
|
+
/** Wait up to `waitMs` for new live-agent events. Running out of time is "nothing new". */
|
|
75988
|
+
async poll(body, windowToken, waitMs) {
|
|
75989
|
+
let res;
|
|
75990
|
+
try {
|
|
75991
|
+
res = await this.post("/chat/live/poll", "text/plain", body, { "x-window-token": windowToken }, waitMs, true);
|
|
75992
|
+
} catch (err) {
|
|
75993
|
+
if (err instanceof WaitElapsed) return { status: "nothing_new" };
|
|
75994
|
+
throw err;
|
|
75995
|
+
}
|
|
75996
|
+
if (res.status === 204) return { status: "nothing_new" };
|
|
75997
|
+
let parsed;
|
|
75998
|
+
try {
|
|
75999
|
+
parsed = JSON.parse(await res.text());
|
|
76000
|
+
} catch {
|
|
76001
|
+
throw new McpToolError(`${SUPPORT_SERVICE}'s live poll answered something that is not JSON.`, { kind: "http", status: res.status });
|
|
76002
|
+
}
|
|
76003
|
+
const se = parsed.streamEvent;
|
|
76004
|
+
const events = Array.isArray(se?.state?.events) ? projectEvents(se.state.events) : [];
|
|
76005
|
+
return {
|
|
76006
|
+
status: "events",
|
|
76007
|
+
events,
|
|
76008
|
+
isDelta: se?.isDelta === true,
|
|
76009
|
+
...typeof se?.stateCursor === "string" ? { stateCursor: se.stateCursor } : {}
|
|
76010
|
+
};
|
|
76011
|
+
}
|
|
76012
|
+
async post(path, contentType, body, extraHeaders = {}, timeoutMs = this.timeoutMs, waitIsNormal = false) {
|
|
76013
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
76014
|
+
let res;
|
|
76015
|
+
try {
|
|
76016
|
+
res = await this.fetchImpl(`${SIERRA_API}${path}`, {
|
|
76017
|
+
method: "POST",
|
|
76018
|
+
headers: { "content-type": contentType, accept: "*/*", ...extraHeaders },
|
|
76019
|
+
body: JSON.stringify(body),
|
|
76020
|
+
signal
|
|
76021
|
+
});
|
|
76022
|
+
} catch (err) {
|
|
76023
|
+
if (signal.aborted && waitIsNormal) throw new WaitElapsed();
|
|
76024
|
+
if (signal.aborted) {
|
|
76025
|
+
throw new McpToolError(`${SUPPORT_SERVICE} did not answer in time (${timeoutMs} ms).`, { kind: "timeout", cause: err });
|
|
76026
|
+
}
|
|
76027
|
+
throw new McpToolError(`Could not reach ${SUPPORT_SERVICE}: ${truncateErrorMessage(this.redact(messageOf(err)), 200)}`, {
|
|
76028
|
+
kind: "transport",
|
|
76029
|
+
cause: err
|
|
76030
|
+
});
|
|
76031
|
+
}
|
|
76032
|
+
if (!res.ok && res.status !== 204) {
|
|
76033
|
+
const text = await res.text();
|
|
76034
|
+
throw new McpToolError(`${SUPPORT_SERVICE} answered HTTP ${res.status} on ${path}: ${truncateErrorMessage(this.redact(text), 200)}`, {
|
|
76035
|
+
kind: res.status === 401 || res.status === 403 ? "credential_rejected" : "http",
|
|
76036
|
+
status: res.status
|
|
76037
|
+
});
|
|
76038
|
+
}
|
|
76039
|
+
return res;
|
|
76040
|
+
}
|
|
76041
|
+
};
|
|
76042
|
+
var WaitElapsed = class extends Error {
|
|
76043
|
+
};
|
|
76044
|
+
|
|
76045
|
+
// src/tools/support.ts
|
|
76046
|
+
var REPLY_NOTE = `Replies are written by HelloFresh's support AI (FreshBot) or its support staff \u2014 third-party content, not the user. ${UNTRUSTED_CONTENT_RULE}`;
|
|
76047
|
+
var fenced2 = (payload) => untrustedResult(payload, { note: REPLY_NOTE });
|
|
76048
|
+
var MAX_WAIT_SECONDS = 55;
|
|
76049
|
+
var MAX_TEXT = 2e3;
|
|
76050
|
+
var TOPICS = ["delivery_issue", "ingredient_issue", "billing", "other"];
|
|
76051
|
+
var conversationParam = external_exports.string().min(1).max(200).describe("The conversation_id hf_support_start returned.");
|
|
76052
|
+
function humanAgentIn(events) {
|
|
76053
|
+
let inIt = false;
|
|
76054
|
+
for (const e of events) {
|
|
76055
|
+
if (e.kind === "agentJoined" || e.kind === "agentTransfer" || e.from === "human_agent") inIt = true;
|
|
76056
|
+
if (e.kind === "agentLeft" || e.kind === "endConversation") inIt = false;
|
|
76057
|
+
}
|
|
76058
|
+
return inIt;
|
|
76059
|
+
}
|
|
76060
|
+
var ended = (events) => events.some((e) => e.kind === "endConversation");
|
|
76061
|
+
function draftFor(topic, c) {
|
|
76062
|
+
const box = c.meals && c.people ? `${c.meals} meals for ${c.people}` : "my box";
|
|
76063
|
+
const tracking = c.trackingCode ? `, tracking ${c.trackingCode}` : "";
|
|
76064
|
+
const which = `my HelloFresh box for ${c.deliveryDate ?? c.week} (${c.week}, ${box}${tracking})`;
|
|
76065
|
+
switch (topic) {
|
|
76066
|
+
case "delivery_issue":
|
|
76067
|
+
return `Hi, I have a delivery problem with ${which}. `;
|
|
76068
|
+
case "ingredient_issue":
|
|
76069
|
+
return `Hi, I have a problem with the ingredients in ${which}. `;
|
|
76070
|
+
case "billing":
|
|
76071
|
+
return `Hi, I have a billing question about ${which}. `;
|
|
76072
|
+
default:
|
|
76073
|
+
return `Hi, I have a question about ${which}. `;
|
|
76074
|
+
}
|
|
76075
|
+
}
|
|
76076
|
+
function defaultSupportDeps(deps2) {
|
|
76077
|
+
return {
|
|
76078
|
+
chat: new SierraChat({ fetchImpl: deps2.fetchImpl, redact: (t) => deps2.session.redact(t) }),
|
|
76079
|
+
token: () => deps2.session.getToken(),
|
|
76080
|
+
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
76081
|
+
};
|
|
76082
|
+
}
|
|
76083
|
+
function outcomeUnknown(err) {
|
|
76084
|
+
if (!(err instanceof McpToolError)) return false;
|
|
76085
|
+
if (err.kind === "timeout" || err.kind === "transport") return true;
|
|
76086
|
+
const status = err.status;
|
|
76087
|
+
return status !== void 0 && (status >= 500 || status >= 200 && status < 300);
|
|
76088
|
+
}
|
|
76089
|
+
function registerSupportTools(server, deps2) {
|
|
76090
|
+
const { client } = deps2;
|
|
76091
|
+
const support = deps2.support ?? defaultSupportDeps(deps2);
|
|
76092
|
+
const timeZone = support.timeZone ?? DEFAULT_TIME_ZONE;
|
|
76093
|
+
const conversations = /* @__PURE__ */ new Map();
|
|
76094
|
+
const memoryOf = async (customerId) => ({
|
|
76095
|
+
variables: { MARKET_CODE: "US", MARKET_LOCALE: "en-US", CUSTOMER_ID: customerId, ENTRY_REASON },
|
|
76096
|
+
secrets: { CUSTOMER_JWT: await support.token() }
|
|
76097
|
+
});
|
|
76098
|
+
const conversationOf = (id) => {
|
|
76099
|
+
const c = conversations.get(id);
|
|
76100
|
+
if (!c) {
|
|
76101
|
+
throw new McpToolError(`No open support conversation "${id}" in this session.`, {
|
|
76102
|
+
hint: "Conversations live only as long as this server process: start one with hf_support_start."
|
|
76103
|
+
});
|
|
76104
|
+
}
|
|
76105
|
+
return c;
|
|
76106
|
+
};
|
|
76107
|
+
const turn = async (c, event) => {
|
|
76108
|
+
const body = async () => chatRequestBody({ event, conversation: c.keys, memory: await memoryOf(c.customerId), windowId: c.windowId, idempotencyKey: randomUUID(), timeZone });
|
|
76109
|
+
const first = await body();
|
|
76110
|
+
try {
|
|
76111
|
+
return await support.chat.turn(first, c.windowToken);
|
|
76112
|
+
} catch (err) {
|
|
76113
|
+
if (!(err instanceof McpToolError) || err.status !== 401 && err.status !== 403) throw err;
|
|
76114
|
+
c.windowToken = await support.chat.windowToken(c.windowId);
|
|
76115
|
+
return support.chat.turn(await body(), c.windowToken);
|
|
76116
|
+
}
|
|
76117
|
+
};
|
|
76118
|
+
const describe3 = (text) => `${text} ${UNTRUSTED_DESCRIPTION_SUFFIX}`;
|
|
76119
|
+
server.registerTool(
|
|
76120
|
+
"hf_support_start",
|
|
76121
|
+
{
|
|
76122
|
+
description: describe3(
|
|
76123
|
+
"Open a HelloFresh customer-support chat about a delivery week (a box not delivered, late, damaged, wrong or missing ingredients, billing). It is HelloFresh\u2019s own website chat: an AI assistant (FreshBot) that can hand over to a person. Opening it sends NO message \u2014 it returns FreshBot\u2019s greeting, the week\u2019s delivery date, box size and carrier tracking, and a drafted first message. Show the user the draft, edit it with them, then send it with hf_support_send; read later replies with hf_support_read."
|
|
76124
|
+
),
|
|
76125
|
+
annotations: toolAnnotations({ title: "HelloFresh: start a support chat", readOnly: false, destructive: false, idempotent: false, openWorld: true }),
|
|
76126
|
+
_meta: foodMeta("send", { aliases: ["hellofresh support", "contact hellofresh", "hellofresh customer service", "box not delivered", "missing box"] }),
|
|
76127
|
+
inputSchema: external_exports.object({
|
|
76128
|
+
week: weekParam,
|
|
76129
|
+
topic: external_exports.enum(TOPICS).default("delivery_issue").describe("What it is about (shapes the drafted first message only).")
|
|
76130
|
+
})
|
|
76131
|
+
},
|
|
76132
|
+
async ({ week, topic }) => {
|
|
76133
|
+
const account = await loadAccount(client);
|
|
76134
|
+
const customerId = account.subscription.customer?.uuid;
|
|
76135
|
+
if (!customerId) throw new McpToolError("HelloFresh did not return the customer id the support chat needs.");
|
|
76136
|
+
const raw = await client.getDelivery(account.subscriptionId, week);
|
|
76137
|
+
const delivery = projectDelivery(raw);
|
|
76138
|
+
const publicId = trackingPublicId(raw.tracking);
|
|
76139
|
+
const tracked = publicId ? await attempt(async () => projectTracking(await client.getTracking(publicId)).boxes[0]) : void 0;
|
|
76140
|
+
const box = tracked?.ok ? tracked.value : void 0;
|
|
76141
|
+
const trackingCode = box?.trackingCode ?? (raw.tracking?.tracking_code || void 0);
|
|
76142
|
+
const windowId = randomUUID();
|
|
76143
|
+
const windowToken = await support.chat.windowToken(windowId);
|
|
76144
|
+
const memory = await memoryOf(customerId);
|
|
76145
|
+
const started = await support.chat.turn(
|
|
76146
|
+
chatRequestBody({ event: { type: "start" }, memory, windowId, idempotencyKey: randomUUID(), timeZone }),
|
|
76147
|
+
windowToken
|
|
76148
|
+
);
|
|
76149
|
+
if (!started.conversationID || !started.encryptionKey) {
|
|
76150
|
+
throw new McpToolError("The HelloFresh support chat did not open a conversation (no conversation id in its answer).");
|
|
76151
|
+
}
|
|
76152
|
+
const c = {
|
|
76153
|
+
keys: { conversationID: started.conversationID, encryptionKey: started.encryptionKey },
|
|
76154
|
+
customerId,
|
|
76155
|
+
windowId,
|
|
76156
|
+
windowToken,
|
|
76157
|
+
week,
|
|
76158
|
+
topic,
|
|
76159
|
+
events: started.events ?? []
|
|
76160
|
+
};
|
|
76161
|
+
conversations.set(started.conversationID, c);
|
|
76162
|
+
const context = {
|
|
76163
|
+
week,
|
|
76164
|
+
deliveryDate: dateOf(delivery.deliveryDate),
|
|
76165
|
+
deliverySlot: delivery.deliveryName,
|
|
76166
|
+
status: delivery.status,
|
|
76167
|
+
meals: delivery.meals,
|
|
76168
|
+
people: delivery.servings,
|
|
76169
|
+
...box?.carrier ? { carrier: box.carrier } : {},
|
|
76170
|
+
...trackingCode ? { trackingCode } : {},
|
|
76171
|
+
...box?.status ? { trackingStatus: box.statusDetail ? `${box.status} (${box.statusDetail})` : box.status } : {},
|
|
76172
|
+
...box?.statusAt ? { trackingStatusAt: box.statusAt } : {}
|
|
76173
|
+
};
|
|
76174
|
+
return fenced2({
|
|
76175
|
+
conversation_id: started.conversationID,
|
|
76176
|
+
sent: false,
|
|
76177
|
+
replies: c.events,
|
|
76178
|
+
context,
|
|
76179
|
+
draft: draftFor(topic, { deliveryDate: context.deliveryDate, week, meals: delivery.meals, people: delivery.servings, trackingCode }),
|
|
76180
|
+
next: "Nothing has been sent. Show the user the draft and finish it with them, then hf_support_send {conversation_id, text}."
|
|
76181
|
+
});
|
|
76182
|
+
}
|
|
76183
|
+
);
|
|
76184
|
+
registerGated(server, {
|
|
76185
|
+
name: "hf_support_send",
|
|
76186
|
+
title: "HelloFresh: send a support chat message",
|
|
76187
|
+
description: describe3(
|
|
76188
|
+
"Send one message in a HelloFresh support chat opened with hf_support_start. The preview shows the exact text; after confirmation it is sent, checked against the transcript HelloFresh streams back, and the reply (FreshBot, or a person once one has taken over) is returned. A message cannot be unsent."
|
|
76189
|
+
),
|
|
76190
|
+
destructive: false,
|
|
76191
|
+
idempotent: false,
|
|
76192
|
+
meta: foodMeta("send", { aliases: ["message hellofresh support", "reply to hellofresh", "tell hellofresh"] }),
|
|
76193
|
+
input: {
|
|
76194
|
+
conversation_id: conversationParam,
|
|
76195
|
+
text: external_exports.string().trim().min(1).max(MAX_TEXT).describe("The exact message to send (the user\u2019s words).")
|
|
76196
|
+
},
|
|
76197
|
+
async plan({ conversation_id, text }) {
|
|
76198
|
+
const c = conversationOf(conversation_id);
|
|
76199
|
+
if (ended(c.events)) throw new McpToolError("This support conversation has ended. Start a new one with hf_support_start.");
|
|
76200
|
+
return {
|
|
76201
|
+
gate: {
|
|
76202
|
+
action: "hellofresh.support.message",
|
|
76203
|
+
summary: `Send this message to HelloFresh support (${c.week} conversation)`,
|
|
76204
|
+
account: void 0,
|
|
76205
|
+
target: conversation_id,
|
|
76206
|
+
payload: { text },
|
|
76207
|
+
willSend: { to: "HelloFresh support chat (FreshBot AI; a person may take over)", text },
|
|
76208
|
+
preview: { endpoint: `POST ${SIERRA_API}/chat`, week: c.week }
|
|
76209
|
+
},
|
|
76210
|
+
state: { c, text }
|
|
76211
|
+
};
|
|
76212
|
+
},
|
|
76213
|
+
async execute({ c, text }) {
|
|
76214
|
+
const before = c.events.length;
|
|
76215
|
+
let got;
|
|
76216
|
+
try {
|
|
76217
|
+
got = await turn(c, { type: "message", text });
|
|
76218
|
+
} catch (err) {
|
|
76219
|
+
if (!outcomeUnknown(err)) throw err;
|
|
76220
|
+
return fenced2({
|
|
76221
|
+
status: "unknown",
|
|
76222
|
+
conversation_id: c.keys.conversationID,
|
|
76223
|
+
warning: `The support chat did not confirm the message (${messageOf(err)}), so it may have been delivered. Check with hf_support_read before sending it again; do not repeat it blindly.`
|
|
76224
|
+
});
|
|
76225
|
+
}
|
|
76226
|
+
if (got.events) c.events = got.events;
|
|
76227
|
+
let at = -1;
|
|
76228
|
+
for (let i = c.events.length - 1; i >= 0; i--) {
|
|
76229
|
+
if (c.events[i].from === "user" && c.events[i].text?.trim() === text.trim()) {
|
|
76230
|
+
at = i;
|
|
76231
|
+
break;
|
|
76232
|
+
}
|
|
76233
|
+
}
|
|
76234
|
+
const verified = at >= 0;
|
|
76235
|
+
const replies = verified ? c.events.slice(at + 1) : c.events.slice(before);
|
|
76236
|
+
return fenced2({
|
|
76237
|
+
status: verified ? "verified" : "unverified",
|
|
76238
|
+
conversation_id: c.keys.conversationID,
|
|
76239
|
+
sent: text,
|
|
76240
|
+
replies,
|
|
76241
|
+
humanAgent: humanAgentIn(c.events),
|
|
76242
|
+
...ended(c.events) ? { ended: true } : {},
|
|
76243
|
+
...verified ? {} : { warning: "HelloFresh answered, but its transcript does not show the message. Check with hf_support_read before sending it again." }
|
|
76244
|
+
});
|
|
76245
|
+
}
|
|
76246
|
+
});
|
|
76247
|
+
server.registerTool(
|
|
76248
|
+
"hf_support_read",
|
|
76249
|
+
{
|
|
76250
|
+
description: describe3(
|
|
76251
|
+
"Read a HelloFresh support chat opened with hf_support_start: each event labelled from user / bot (FreshBot, the AI) / human_agent (a person, with their display name), plus agent hand-over, queue and end events. `since` (an ISO time or event id) returns only what came after it. `wait_seconds` long-polls for new messages \u2014 that only helps once a person has taken over; FreshBot answers inside hf_support_send."
|
|
76252
|
+
),
|
|
76253
|
+
annotations: toolAnnotations({ title: "HelloFresh: read a support chat", readOnly: true, idempotent: true, openWorld: true }),
|
|
76254
|
+
_meta: foodMeta("lookup", { aliases: ["hellofresh support replies", "did hellofresh reply"] }),
|
|
76255
|
+
inputSchema: external_exports.object({
|
|
76256
|
+
conversation_id: conversationParam,
|
|
76257
|
+
since: external_exports.string().min(1).max(100).optional().describe("Only events after this ISO timestamp or event id."),
|
|
76258
|
+
wait_seconds: external_exports.number().int().min(0).max(MAX_WAIT_SECONDS).default(0).describe("Wait up to this long for new messages from a person.")
|
|
76259
|
+
})
|
|
76260
|
+
},
|
|
76261
|
+
async ({ conversation_id, since, wait_seconds }) => {
|
|
76262
|
+
const c = conversationOf(conversation_id);
|
|
76263
|
+
let polled;
|
|
76264
|
+
if (wait_seconds > 0) {
|
|
76265
|
+
const body = { ...livePollBody({ conversation: c.keys, memory: await memoryOf(c.customerId), windowId: c.windowId, timeZone }), ...c.stateCursor ? { stateCursor: c.stateCursor } : {} };
|
|
76266
|
+
const got = await support.chat.poll(body, c.windowToken, wait_seconds * 1e3);
|
|
76267
|
+
polled = got.status;
|
|
76268
|
+
if (got.status === "events") {
|
|
76269
|
+
c.events = got.isDelta ? [...c.events, ...got.events] : got.events;
|
|
76270
|
+
if (got.stateCursor) c.stateCursor = got.stateCursor;
|
|
76271
|
+
}
|
|
76272
|
+
}
|
|
76273
|
+
let events = c.events;
|
|
76274
|
+
if (since) {
|
|
76275
|
+
const byId = events.findIndex((e) => e.id === since);
|
|
76276
|
+
events = byId >= 0 ? events.slice(byId + 1) : events.filter((e) => (e.at ?? "") > since);
|
|
76277
|
+
}
|
|
76278
|
+
return fenced2({
|
|
76279
|
+
conversation_id,
|
|
76280
|
+
week: c.week,
|
|
76281
|
+
events,
|
|
76282
|
+
humanAgent: humanAgentIn(c.events),
|
|
76283
|
+
...ended(c.events) ? { ended: true } : {},
|
|
76284
|
+
...polled ? { polled } : {}
|
|
76285
|
+
});
|
|
76286
|
+
}
|
|
76287
|
+
);
|
|
76288
|
+
}
|
|
76289
|
+
|
|
75676
76290
|
// src/tools/writes/plan.ts
|
|
75677
76291
|
init_zod();
|
|
75678
76292
|
function registerPlanWrites(server, deps2) {
|
|
@@ -76082,18 +76696,293 @@ var TOOL_REGISTRARS = [
|
|
|
76082
76696
|
registerPlannerTools,
|
|
76083
76697
|
registerCookingTools,
|
|
76084
76698
|
registerFavoriteTools,
|
|
76085
|
-
registerPromoTools
|
|
76699
|
+
registerPromoTools,
|
|
76700
|
+
registerSupportTools
|
|
76086
76701
|
];
|
|
76087
76702
|
|
|
76703
|
+
// node_modules/@chrischall/mcp-utils/dist/session/index.js
|
|
76704
|
+
import { existsSync as existsSync3, readFileSync as readFileSync4, mkdirSync as mkdirSync4, chmodSync as chmodSync2, renameSync as renameSync2, unlinkSync as unlinkSync4 } from "node:fs";
|
|
76705
|
+
import { dirname as dirname2, join as join7, resolve as resolve2 } from "node:path";
|
|
76706
|
+
import { homedir as homedir3 } from "node:os";
|
|
76707
|
+
import { randomBytes as randomBytes6, createHmac as createHmac3 } from "node:crypto";
|
|
76708
|
+
init_config();
|
|
76709
|
+
init_errors();
|
|
76710
|
+
init_http();
|
|
76711
|
+
init_edge_block();
|
|
76712
|
+
|
|
76713
|
+
// node_modules/@chrischall/mcp-utils/dist/session/login-page.js
|
|
76714
|
+
var LOGIN_PAGE_SCAN_MAX = 512 * 1024;
|
|
76715
|
+
|
|
76716
|
+
// node_modules/@chrischall/mcp-utils/dist/session/file-lock.js
|
|
76717
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
76718
|
+
import { closeSync as closeSync2, existsSync, linkSync, mkdirSync as mkdirSync3, openSync as openSync2, readFileSync as readFileSync3, statSync as statSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2, writeSync as writeSync2 } from "node:fs";
|
|
76719
|
+
import { dirname } from "node:path";
|
|
76720
|
+
var DEFAULT_POLL_MS = 25;
|
|
76721
|
+
function holderAlive(lockPath) {
|
|
76722
|
+
let pid;
|
|
76723
|
+
try {
|
|
76724
|
+
pid = Number.parseInt(readFileSync3(lockPath, "utf8"), 10);
|
|
76725
|
+
} catch {
|
|
76726
|
+
return true;
|
|
76727
|
+
}
|
|
76728
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
76729
|
+
return true;
|
|
76730
|
+
try {
|
|
76731
|
+
process.kill(pid, 0);
|
|
76732
|
+
return true;
|
|
76733
|
+
} catch (err) {
|
|
76734
|
+
return err.code === "EPERM";
|
|
76735
|
+
}
|
|
76736
|
+
}
|
|
76737
|
+
function createLockFile(lockPath, owner) {
|
|
76738
|
+
const staging = `${lockPath}.${randomUUID2()}.tmp`;
|
|
76739
|
+
let linked = false;
|
|
76740
|
+
try {
|
|
76741
|
+
writeFileSync2(staging, owner, { mode: 384, flag: "wx" });
|
|
76742
|
+
linkSync(staging, lockPath);
|
|
76743
|
+
linked = true;
|
|
76744
|
+
} catch (err) {
|
|
76745
|
+
const code2 = err.code;
|
|
76746
|
+
if (code2 === "EEXIST" && existsSync(staging))
|
|
76747
|
+
throw err;
|
|
76748
|
+
if (code2 !== "EPERM" && code2 !== "ENOTSUP" && code2 !== "EOPNOTSUPP" && code2 !== "ENOSYS" && code2 !== "EXDEV") {
|
|
76749
|
+
throw err;
|
|
76750
|
+
}
|
|
76751
|
+
} finally {
|
|
76752
|
+
try {
|
|
76753
|
+
unlinkSync2(staging);
|
|
76754
|
+
} catch {
|
|
76755
|
+
}
|
|
76756
|
+
}
|
|
76757
|
+
if (linked)
|
|
76758
|
+
return;
|
|
76759
|
+
const fd = openSync2(lockPath, "wx", 384);
|
|
76760
|
+
try {
|
|
76761
|
+
writeSync2(fd, owner);
|
|
76762
|
+
} finally {
|
|
76763
|
+
closeSync2(fd);
|
|
76764
|
+
}
|
|
76765
|
+
}
|
|
76766
|
+
function tryAcquire(lockPath, owner, staleMs) {
|
|
76767
|
+
try {
|
|
76768
|
+
createLockFile(lockPath, owner);
|
|
76769
|
+
return "acquired";
|
|
76770
|
+
} catch (err) {
|
|
76771
|
+
if (err.code !== "EEXIST")
|
|
76772
|
+
return "unlockable";
|
|
76773
|
+
}
|
|
76774
|
+
let stale;
|
|
76775
|
+
try {
|
|
76776
|
+
stale = !holderAlive(lockPath) || Date.now() - statSync2(lockPath).mtimeMs > staleMs;
|
|
76777
|
+
} catch {
|
|
76778
|
+
return "busy";
|
|
76779
|
+
}
|
|
76780
|
+
if (stale) {
|
|
76781
|
+
try {
|
|
76782
|
+
unlinkSync2(lockPath);
|
|
76783
|
+
} catch {
|
|
76784
|
+
}
|
|
76785
|
+
}
|
|
76786
|
+
return "busy";
|
|
76787
|
+
}
|
|
76788
|
+
function release(lockPath, owner) {
|
|
76789
|
+
try {
|
|
76790
|
+
if (readFileSync3(lockPath, "utf8") === owner)
|
|
76791
|
+
unlinkSync2(lockPath);
|
|
76792
|
+
} catch {
|
|
76793
|
+
}
|
|
76794
|
+
}
|
|
76795
|
+
function prepare(lockPath) {
|
|
76796
|
+
try {
|
|
76797
|
+
mkdirSync3(dirname(lockPath), { recursive: true, mode: 448 });
|
|
76798
|
+
} catch {
|
|
76799
|
+
}
|
|
76800
|
+
return `${process.pid}:${randomUUID2()}`;
|
|
76801
|
+
}
|
|
76802
|
+
async function withFileLock(lockPath, fn, opts = {}) {
|
|
76803
|
+
const staleMs = opts.staleMs ?? 6e4;
|
|
76804
|
+
const pollMs = opts.pollMs ?? DEFAULT_POLL_MS;
|
|
76805
|
+
const { signal } = opts;
|
|
76806
|
+
const owner = prepare(lockPath);
|
|
76807
|
+
let held = false;
|
|
76808
|
+
for (; ; ) {
|
|
76809
|
+
signal?.throwIfAborted();
|
|
76810
|
+
const r = tryAcquire(lockPath, owner, staleMs);
|
|
76811
|
+
if (r === "acquired") {
|
|
76812
|
+
held = true;
|
|
76813
|
+
break;
|
|
76814
|
+
}
|
|
76815
|
+
if (r === "unlockable")
|
|
76816
|
+
break;
|
|
76817
|
+
await new Promise((resolve3) => {
|
|
76818
|
+
const done = () => {
|
|
76819
|
+
clearTimeout(timer);
|
|
76820
|
+
signal?.removeEventListener("abort", done);
|
|
76821
|
+
resolve3();
|
|
76822
|
+
};
|
|
76823
|
+
const timer = setTimeout(done, pollMs);
|
|
76824
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
76825
|
+
});
|
|
76826
|
+
}
|
|
76827
|
+
try {
|
|
76828
|
+
return await fn();
|
|
76829
|
+
} finally {
|
|
76830
|
+
if (held)
|
|
76831
|
+
release(lockPath, owner);
|
|
76832
|
+
}
|
|
76833
|
+
}
|
|
76834
|
+
|
|
76835
|
+
// node_modules/@chrischall/mcp-utils/dist/session/atomic-write.js
|
|
76836
|
+
import { randomBytes as randomBytes5 } from "node:crypto";
|
|
76837
|
+
import { chmodSync, closeSync as closeSync3, existsSync as existsSync2, fsyncSync, openSync as openSync3, renameSync, unlinkSync as unlinkSync3, writeSync as writeSync3 } from "node:fs";
|
|
76838
|
+
function writeFileAtomicSync(filePath, data) {
|
|
76839
|
+
const tmp = `${filePath}.tmp-${randomBytes5(6).toString("hex")}`;
|
|
76840
|
+
try {
|
|
76841
|
+
const fd = openSync3(tmp, "wx", 384);
|
|
76842
|
+
try {
|
|
76843
|
+
writeSync3(fd, data);
|
|
76844
|
+
fsyncSync(fd);
|
|
76845
|
+
} finally {
|
|
76846
|
+
closeSync3(fd);
|
|
76847
|
+
}
|
|
76848
|
+
chmodSync(tmp, 384);
|
|
76849
|
+
renameSync(tmp, filePath);
|
|
76850
|
+
} catch (err) {
|
|
76851
|
+
try {
|
|
76852
|
+
if (existsSync2(tmp))
|
|
76853
|
+
unlinkSync3(tmp);
|
|
76854
|
+
} catch {
|
|
76855
|
+
}
|
|
76856
|
+
throw err;
|
|
76857
|
+
}
|
|
76858
|
+
}
|
|
76859
|
+
|
|
76860
|
+
// node_modules/@chrischall/mcp-utils/dist/session/index.js
|
|
76861
|
+
function bindingDigest(secret, salt) {
|
|
76862
|
+
return createHmac3("sha256", salt).update(secret).digest("hex").slice(0, 32);
|
|
76863
|
+
}
|
|
76864
|
+
function isEnvelope(raw) {
|
|
76865
|
+
return raw !== null && typeof raw === "object" && raw.v === 1 && "state" in raw;
|
|
76866
|
+
}
|
|
76867
|
+
function createFileStatePersistence(opts) {
|
|
76868
|
+
const { filePath, validate: validate2 } = opts;
|
|
76869
|
+
const secret = opts.boundTo;
|
|
76870
|
+
return {
|
|
76871
|
+
load() {
|
|
76872
|
+
if (!existsSync3(filePath))
|
|
76873
|
+
return null;
|
|
76874
|
+
try {
|
|
76875
|
+
const raw = JSON.parse(readFileSync4(filePath, "utf8"));
|
|
76876
|
+
let state;
|
|
76877
|
+
if (isEnvelope(raw)) {
|
|
76878
|
+
const b = raw.boundTo;
|
|
76879
|
+
if (secret === void 0) {
|
|
76880
|
+
if (b !== void 0)
|
|
76881
|
+
return null;
|
|
76882
|
+
} else {
|
|
76883
|
+
if (b === void 0)
|
|
76884
|
+
return null;
|
|
76885
|
+
if (bindingDigest(secret, b.salt) !== b.digest)
|
|
76886
|
+
return null;
|
|
76887
|
+
}
|
|
76888
|
+
state = raw.state;
|
|
76889
|
+
} else {
|
|
76890
|
+
if (secret !== void 0)
|
|
76891
|
+
return null;
|
|
76892
|
+
state = raw;
|
|
76893
|
+
}
|
|
76894
|
+
if (validate2 !== void 0)
|
|
76895
|
+
return validate2(state);
|
|
76896
|
+
return state;
|
|
76897
|
+
} catch {
|
|
76898
|
+
return null;
|
|
76899
|
+
}
|
|
76900
|
+
},
|
|
76901
|
+
save(state) {
|
|
76902
|
+
const dir = dirname2(filePath);
|
|
76903
|
+
const dirExisted = existsSync3(dir);
|
|
76904
|
+
try {
|
|
76905
|
+
mkdirSync4(dir, { recursive: true, mode: 448 });
|
|
76906
|
+
if (!dirExisted)
|
|
76907
|
+
chmodSync2(dir, 448);
|
|
76908
|
+
let boundTo;
|
|
76909
|
+
if (secret !== void 0) {
|
|
76910
|
+
const salt = randomBytes6(16).toString("hex");
|
|
76911
|
+
boundTo = { salt, digest: bindingDigest(secret, salt) };
|
|
76912
|
+
}
|
|
76913
|
+
const envelope = { v: 1, ...boundTo !== void 0 ? { boundTo } : {}, state };
|
|
76914
|
+
writeFileAtomicSync(filePath, JSON.stringify(envelope, null, 2));
|
|
76915
|
+
chmodSync2(filePath, 384);
|
|
76916
|
+
} catch (err) {
|
|
76917
|
+
throw err;
|
|
76918
|
+
}
|
|
76919
|
+
},
|
|
76920
|
+
clear() {
|
|
76921
|
+
try {
|
|
76922
|
+
if (existsSync3(filePath))
|
|
76923
|
+
unlinkSync4(filePath);
|
|
76924
|
+
} catch {
|
|
76925
|
+
}
|
|
76926
|
+
},
|
|
76927
|
+
// `<filePath>.lock`: shared by every process that opens this file through
|
|
76928
|
+
// this helper, which is what makes TokenManager's reloadBeforeRefresh safe.
|
|
76929
|
+
withLock(fn) {
|
|
76930
|
+
return withFileLock(`${filePath}.lock`, fn);
|
|
76931
|
+
}
|
|
76932
|
+
};
|
|
76933
|
+
}
|
|
76934
|
+
function homeOf(env) {
|
|
76935
|
+
return readEnvVar("HOME", { env }) ?? homedir3();
|
|
76936
|
+
}
|
|
76937
|
+
function resolveStateDir(opts = {}) {
|
|
76938
|
+
const env = opts.env;
|
|
76939
|
+
return join7(readEnvVar("MCP_DATA_DIR", { env }) ?? homeOf(env), opts.subdir ?? "");
|
|
76940
|
+
}
|
|
76941
|
+
function resolveStateFile(opts) {
|
|
76942
|
+
const override = opts.envVar !== void 0 ? readEnvVar(opts.envVar, { env: opts.env }) : void 0;
|
|
76943
|
+
if (override !== void 0) {
|
|
76944
|
+
if (override === "~")
|
|
76945
|
+
return homeOf(opts.env);
|
|
76946
|
+
if (override.startsWith("~/"))
|
|
76947
|
+
return join7(homeOf(opts.env), override.slice(2));
|
|
76948
|
+
return resolve2(override);
|
|
76949
|
+
}
|
|
76950
|
+
const dirOpts = { env: opts.env };
|
|
76951
|
+
if (opts.subdir !== void 0)
|
|
76952
|
+
dirOpts.subdir = opts.subdir;
|
|
76953
|
+
return join7(resolveStateDir(dirOpts), opts.fileName);
|
|
76954
|
+
}
|
|
76955
|
+
var TOKEN_REFRESH_SKEW_MS = 5 * 60 * 1e3;
|
|
76956
|
+
var UNKNOWN_CAPTURED_TOKEN_TTL_MS = 10 * 60 * 1e3;
|
|
76957
|
+
|
|
76958
|
+
// src/session-cache.ts
|
|
76959
|
+
function sessionCachePath(env = process.env) {
|
|
76960
|
+
return resolveStateFile({ env, envVar: "HELLOFRESH_SESSION_FILE", subdir: ".hellofresh-mcp", fileName: "session.json" });
|
|
76961
|
+
}
|
|
76962
|
+
function asPersistedSession(raw) {
|
|
76963
|
+
if (typeof raw !== "object" || raw === null) return null;
|
|
76964
|
+
const r = raw;
|
|
76965
|
+
if (!isTokenSet(r["set"]) || typeof r["set"].issued_at !== "number") return null;
|
|
76966
|
+
if (typeof r["own"] !== "boolean" || typeof r["writtenBack"] !== "boolean") return null;
|
|
76967
|
+
return { set: r["set"], own: r["own"], writtenBack: r["writtenBack"] };
|
|
76968
|
+
}
|
|
76969
|
+
function createSessionCache(env = process.env) {
|
|
76970
|
+
if (!parseBoolEnv("HELLOFRESH_SESSION_CACHE", { env, default: true })) return null;
|
|
76971
|
+
return createFileStatePersistence({
|
|
76972
|
+
filePath: sessionCachePath(env),
|
|
76973
|
+
validate: asPersistedSession
|
|
76974
|
+
});
|
|
76975
|
+
}
|
|
76976
|
+
|
|
76088
76977
|
// src/version.ts
|
|
76089
|
-
var VERSION = "0.
|
|
76978
|
+
var VERSION = "0.5.0";
|
|
76090
76979
|
|
|
76091
76980
|
// src/index.ts
|
|
76092
76981
|
var bridge = createHelloFreshBridge({ port: readWsPort(), version: VERSION });
|
|
76093
76982
|
await bridge.start().catch(() => {
|
|
76094
76983
|
});
|
|
76095
76984
|
var fetchImpl = (input2, init) => fetch(input2, init);
|
|
76096
|
-
var session = new HelloFreshSession({ bridge, fetchImpl });
|
|
76985
|
+
var session = new HelloFreshSession({ bridge, fetchImpl, persistence: createSessionCache() });
|
|
76097
76986
|
var deps = {
|
|
76098
76987
|
bridge,
|
|
76099
76988
|
session,
|