ofw-mcp 2.20.6 → 2.22.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 +59 -0
- package/dist/bundle.js +700 -278
- package/dist/cache/store.js +8 -2
- package/dist/read-days.js +127 -0
- package/dist/sync.js +44 -5
- package/dist/tools/_confirm.js +17 -9
- package/dist/tools/expense-reimbursement.js +117 -0
- package/dist/tools/expenses.js +3 -0
- package/dist/tools/messages.js +79 -7
- package/dist/version.js +1 -1
- package/mint.yaml +12 -0
- package/package.json +1 -1
- package/server.json +15 -3
- package/skills/ofw/SKILL.md +23 -1
package/dist/bundle.js
CHANGED
|
@@ -7450,15 +7450,15 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
7450
7450
|
const syms = normalized.symbolKeys;
|
|
7451
7451
|
const doc = new Doc(["payload", "ctx"], { shape, inst, memo: memo3, syms });
|
|
7452
7452
|
const parseStr = (k) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
|
|
7453
|
-
const prefixStr = (
|
|
7454
|
-
let ${
|
|
7455
|
-
for (let i = 0; i < ${
|
|
7456
|
-
const iss = ${
|
|
7453
|
+
const prefixStr = (id2, k) => `
|
|
7454
|
+
let ${id2}_ab = false;
|
|
7455
|
+
for (let i = 0; i < ${id2}.issues.length; i++) {
|
|
7456
|
+
const iss = ${id2}.issues[i];
|
|
7457
7457
|
iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
|
|
7458
7458
|
payload.issues.push(iss);
|
|
7459
|
-
if (iss.continue !== true) ${
|
|
7459
|
+
if (iss.continue !== true) ${id2}_ab = true;
|
|
7460
7460
|
}
|
|
7461
|
-
if (${
|
|
7461
|
+
if (${id2}_ab && ctx && ctx.abortEarly) {
|
|
7462
7462
|
payload.value = newResult;
|
|
7463
7463
|
return payload;
|
|
7464
7464
|
}`;
|
|
@@ -7472,34 +7472,34 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
7472
7472
|
for (const key of normalized.allKeys) {
|
|
7473
7473
|
if (key === "__proto__")
|
|
7474
7474
|
continue;
|
|
7475
|
-
const
|
|
7475
|
+
const id2 = ids[key];
|
|
7476
7476
|
const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` : esc(key);
|
|
7477
7477
|
const isPresent = `${k} in input`;
|
|
7478
7478
|
const schema = shape[key];
|
|
7479
7479
|
const optin = schema?._zod?.optin;
|
|
7480
7480
|
const isOptionalIn = optin !== void 0;
|
|
7481
7481
|
const isOptionalOut = schema?._zod?.optout === "optional";
|
|
7482
|
-
doc.write(`const ${
|
|
7482
|
+
doc.write(`const ${id2} = ${parseStr(k)};`);
|
|
7483
7483
|
if (isOptionalIn && isOptionalOut) {
|
|
7484
|
-
const assign = optin === "optional" ? `${
|
|
7484
|
+
const assign = optin === "optional" ? `${id2}_present` : `${id2}.value !== undefined || ${id2}_present`;
|
|
7485
7485
|
doc.write(`
|
|
7486
|
-
const ${
|
|
7487
|
-
if (!${
|
|
7488
|
-
if (${
|
|
7486
|
+
const ${id2}_present = ${isPresent};
|
|
7487
|
+
if (!${id2}.issues.length || ${id2}_present) {
|
|
7488
|
+
if (${id2}.issues.length) {${prefixStr(id2, k)}
|
|
7489
7489
|
}
|
|
7490
7490
|
|
|
7491
7491
|
if (${assign}) {
|
|
7492
|
-
newResult[${k}] = ${
|
|
7492
|
+
newResult[${k}] = ${id2}.value;
|
|
7493
7493
|
}
|
|
7494
7494
|
}
|
|
7495
7495
|
|
|
7496
7496
|
`);
|
|
7497
7497
|
} else if (!isOptionalIn) {
|
|
7498
7498
|
doc.write(`
|
|
7499
|
-
const ${
|
|
7500
|
-
if (${
|
|
7499
|
+
const ${id2}_present = ${isPresent};
|
|
7500
|
+
if (${id2}.issues.length) {${prefixStr(id2, k)}
|
|
7501
7501
|
}
|
|
7502
|
-
if (!${
|
|
7502
|
+
if (!${id2}_present && !${id2}.issues.length) {
|
|
7503
7503
|
payload.issues.push({
|
|
7504
7504
|
code: "invalid_type",
|
|
7505
7505
|
expected: "nonoptional",
|
|
@@ -7512,22 +7512,22 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
7512
7512
|
}
|
|
7513
7513
|
}
|
|
7514
7514
|
|
|
7515
|
-
if (${
|
|
7516
|
-
newResult[${k}] = ${
|
|
7515
|
+
if (${id2}_present) {
|
|
7516
|
+
newResult[${k}] = ${id2}.value;
|
|
7517
7517
|
}
|
|
7518
7518
|
|
|
7519
7519
|
`);
|
|
7520
7520
|
} else {
|
|
7521
7521
|
doc.write(`
|
|
7522
|
-
if (${
|
|
7522
|
+
if (${id2}.issues.length) {${prefixStr(id2, k)}
|
|
7523
7523
|
}
|
|
7524
7524
|
`);
|
|
7525
7525
|
if (optin === "defaulted") {
|
|
7526
|
-
doc.write(`newResult[${k}] = ${
|
|
7526
|
+
doc.write(`newResult[${k}] = ${id2}.value;`);
|
|
7527
7527
|
} else {
|
|
7528
7528
|
doc.write(`
|
|
7529
|
-
if (${
|
|
7530
|
-
newResult[${k}] = ${
|
|
7529
|
+
if (${id2}.value !== undefined || ${isPresent}) {
|
|
7530
|
+
newResult[${k}] = ${id2}.value;
|
|
7531
7531
|
}
|
|
7532
7532
|
`);
|
|
7533
7533
|
}
|
|
@@ -19555,26 +19555,26 @@ function extractDefs(ctx, schema) {
|
|
|
19555
19555
|
return;
|
|
19556
19556
|
const idToSchema = /* @__PURE__ */ new Map();
|
|
19557
19557
|
for (const entry of ctx.seen.entries()) {
|
|
19558
|
-
const
|
|
19559
|
-
if (
|
|
19560
|
-
const existing = idToSchema.get(
|
|
19558
|
+
const id2 = ctx.metadataRegistry.get(entry[0])?.id;
|
|
19559
|
+
if (id2) {
|
|
19560
|
+
const existing = idToSchema.get(id2);
|
|
19561
19561
|
if (existing && existing !== entry[0]) {
|
|
19562
|
-
throw new Error(`Duplicate schema id "${
|
|
19562
|
+
throw new Error(`Duplicate schema id "${id2}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
|
|
19563
19563
|
}
|
|
19564
|
-
idToSchema.set(
|
|
19564
|
+
idToSchema.set(id2, entry[0]);
|
|
19565
19565
|
}
|
|
19566
19566
|
}
|
|
19567
19567
|
const makeURI = (entry) => {
|
|
19568
19568
|
const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
|
|
19569
19569
|
if (ctx.external) {
|
|
19570
19570
|
const externalId = ctx.external.registry.get(entry[0])?.id;
|
|
19571
|
-
const uriGenerator = ctx.external.uri ?? ((
|
|
19571
|
+
const uriGenerator = ctx.external.uri ?? ((id3) => id3);
|
|
19572
19572
|
if (externalId) {
|
|
19573
19573
|
return { ref: uriGenerator(externalId) };
|
|
19574
19574
|
}
|
|
19575
|
-
const
|
|
19576
|
-
entry[1].defId =
|
|
19577
|
-
return { defId:
|
|
19575
|
+
const id2 = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
|
|
19576
|
+
entry[1].defId = id2;
|
|
19577
|
+
return { defId: id2, ref: `${uriGenerator("__shared")}#/${defsSegment}/${encodeJSONPointerSegment(id2)}` };
|
|
19578
19578
|
}
|
|
19579
19579
|
const uriPrefix = `#`;
|
|
19580
19580
|
const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
|
|
@@ -19622,8 +19622,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19622
19622
|
continue;
|
|
19623
19623
|
}
|
|
19624
19624
|
}
|
|
19625
|
-
const
|
|
19626
|
-
if (
|
|
19625
|
+
const id2 = ctx.metadataRegistry.get(entry[0])?.id;
|
|
19626
|
+
if (id2) {
|
|
19627
19627
|
extractToDef(entry);
|
|
19628
19628
|
continue;
|
|
19629
19629
|
}
|
|
@@ -19856,10 +19856,10 @@ function finalize(ctx, schema) {
|
|
|
19856
19856
|
} else {
|
|
19857
19857
|
}
|
|
19858
19858
|
if (ctx.external?.uri) {
|
|
19859
|
-
const
|
|
19860
|
-
if (!
|
|
19859
|
+
const id2 = ctx.external.registry.get(schema)?.id;
|
|
19860
|
+
if (!id2)
|
|
19861
19861
|
throw new Error("Schema is missing an `id` property");
|
|
19862
|
-
result.$id = ctx.external.uri(
|
|
19862
|
+
result.$id = ctx.external.uri(id2);
|
|
19863
19863
|
}
|
|
19864
19864
|
assignProps(result, root.defId ? root.schema : root.def ?? root.schema);
|
|
19865
19865
|
const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
|
|
@@ -20465,7 +20465,7 @@ function stringifyKeyNames(bySchema, json2, visited) {
|
|
|
20465
20465
|
const values = json2.enum ?? (json2.const !== void 0 ? [json2.const] : void 0);
|
|
20466
20466
|
if (!numericType && !values?.some((v) => typeof v === "number"))
|
|
20467
20467
|
return json2;
|
|
20468
|
-
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, format, id, ...rest } = json2;
|
|
20468
|
+
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, format, id: id2, ...rest } = json2;
|
|
20469
20469
|
if (rest.enum)
|
|
20470
20470
|
rest.enum = rest.enum.map((v) => typeof v === "number" ? String(v) : v);
|
|
20471
20471
|
else if (typeof rest.const === "number")
|
|
@@ -25610,8 +25610,8 @@ var REF_REWRITE_NAME_MAP_KEYS = /* @__PURE__ */ new Set([
|
|
|
25610
25610
|
"dependentSchemas",
|
|
25611
25611
|
"dependencies"
|
|
25612
25612
|
]);
|
|
25613
|
-
function establishesNewBase(
|
|
25614
|
-
return
|
|
25613
|
+
function establishesNewBase(id2) {
|
|
25614
|
+
return id2 !== void 0 && !(typeof id2 === "string" && id2.startsWith("#"));
|
|
25615
25615
|
}
|
|
25616
25616
|
function wrapOutputSchemaForLegacy(natural) {
|
|
25617
25617
|
const $schema = typeof natural["$schema"] === "string" ? natural["$schema"] : void 0;
|
|
@@ -31128,9 +31128,9 @@ var require_resolve = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
31128
31128
|
}
|
|
31129
31129
|
return count;
|
|
31130
31130
|
}
|
|
31131
|
-
function getFullPath(resolver,
|
|
31132
|
-
if (normalize !== false)
|
|
31133
|
-
return _getFullPath(resolver, resolver.parse(
|
|
31131
|
+
function getFullPath(resolver, id2 = "", normalize) {
|
|
31132
|
+
if (normalize !== false) id2 = normalizeId(id2);
|
|
31133
|
+
return _getFullPath(resolver, resolver.parse(id2));
|
|
31134
31134
|
}
|
|
31135
31135
|
exports.getFullPath = getFullPath;
|
|
31136
31136
|
function _getFullPath(resolver, p) {
|
|
@@ -31138,13 +31138,13 @@ var require_resolve = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
31138
31138
|
}
|
|
31139
31139
|
exports._getFullPath = _getFullPath;
|
|
31140
31140
|
const TRAILING_SLASH_HASH = /#\/?$/;
|
|
31141
|
-
function normalizeId(
|
|
31142
|
-
return
|
|
31141
|
+
function normalizeId(id2) {
|
|
31142
|
+
return id2 ? id2.replace(TRAILING_SLASH_HASH, "") : "";
|
|
31143
31143
|
}
|
|
31144
31144
|
exports.normalizeId = normalizeId;
|
|
31145
|
-
function resolveUrl(resolver, baseId,
|
|
31146
|
-
|
|
31147
|
-
return resolver.resolve(baseId,
|
|
31145
|
+
function resolveUrl(resolver, baseId, id2) {
|
|
31146
|
+
id2 = normalizeId(id2);
|
|
31147
|
+
return resolver.resolve(baseId, id2);
|
|
31148
31148
|
}
|
|
31149
31149
|
exports.resolveUrl = resolveUrl;
|
|
31150
31150
|
const ANCHOR = /^[a-z_][-a-z0-9._]*$/i;
|
|
@@ -31789,8 +31789,8 @@ var require_compile = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
31789
31789
|
const refPath = (0, resolve_1._getFullPath)(this.opts.uriResolver, p);
|
|
31790
31790
|
let baseId = (0, resolve_1.getFullPath)(this.opts.uriResolver, root.baseId, void 0);
|
|
31791
31791
|
if (Object.keys(root.schema).length > 0 && refPath === baseId) return getJsonPointer.call(this, p, root);
|
|
31792
|
-
const
|
|
31793
|
-
const schOrRef = this.refs[
|
|
31792
|
+
const id2 = (0, resolve_1.normalizeId)(refPath);
|
|
31793
|
+
const schOrRef = this.refs[id2] || this.schemas[id2];
|
|
31794
31794
|
if (typeof schOrRef == "string") {
|
|
31795
31795
|
const sch = resolveSchema.call(this, root, schOrRef);
|
|
31796
31796
|
if (typeof (sch === null || sch === void 0 ? void 0 : sch.schema) !== "object") return;
|
|
@@ -31798,7 +31798,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
31798
31798
|
}
|
|
31799
31799
|
if (typeof (schOrRef === null || schOrRef === void 0 ? void 0 : schOrRef.schema) !== "object") return;
|
|
31800
31800
|
if (!schOrRef.validate) compileSchema.call(this, schOrRef);
|
|
31801
|
-
if (
|
|
31801
|
+
if (id2 === (0, resolve_1.normalizeId)(ref)) {
|
|
31802
31802
|
const { schema } = schOrRef;
|
|
31803
31803
|
const { schemaId } = this.opts;
|
|
31804
31804
|
const schId = schema[schemaId];
|
|
@@ -32666,13 +32666,13 @@ var require_core$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
32666
32666
|
for (const sch of schema) this.addSchema(sch, void 0, _meta, _validateSchema);
|
|
32667
32667
|
return this;
|
|
32668
32668
|
}
|
|
32669
|
-
let
|
|
32669
|
+
let id2;
|
|
32670
32670
|
if (typeof schema === "object") {
|
|
32671
32671
|
const { schemaId } = this.opts;
|
|
32672
|
-
|
|
32673
|
-
if (
|
|
32672
|
+
id2 = schema[schemaId];
|
|
32673
|
+
if (id2 !== void 0 && typeof id2 != "string") throw new Error(`schema ${schemaId} must be string`);
|
|
32674
32674
|
}
|
|
32675
|
-
key = (0, resolve_1.normalizeId)(key ||
|
|
32675
|
+
key = (0, resolve_1.normalizeId)(key || id2);
|
|
32676
32676
|
this._checkUnique(key);
|
|
32677
32677
|
this.schemas[key] = this._addSchema(schema, _meta, key, _validateSchema, true);
|
|
32678
32678
|
return this;
|
|
@@ -32737,11 +32737,11 @@ var require_core$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
32737
32737
|
case "object": {
|
|
32738
32738
|
const cacheKey = schemaKeyRef;
|
|
32739
32739
|
this._cache.delete(cacheKey);
|
|
32740
|
-
let
|
|
32741
|
-
if (
|
|
32742
|
-
|
|
32743
|
-
delete this.schemas[
|
|
32744
|
-
delete this.refs[
|
|
32740
|
+
let id2 = schemaKeyRef[this.opts.schemaId];
|
|
32741
|
+
if (id2) {
|
|
32742
|
+
id2 = (0, resolve_1.normalizeId)(id2);
|
|
32743
|
+
delete this.schemas[id2];
|
|
32744
|
+
delete this.refs[id2];
|
|
32745
32745
|
}
|
|
32746
32746
|
return this;
|
|
32747
32747
|
}
|
|
@@ -32833,14 +32833,14 @@ var require_core$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
32833
32833
|
}
|
|
32834
32834
|
}
|
|
32835
32835
|
_addSchema(schema, meta3, baseId, validateSchema = this.opts.validateSchema, addSchema = this.opts.addUsedSchema) {
|
|
32836
|
-
let
|
|
32836
|
+
let id2;
|
|
32837
32837
|
const { schemaId } = this.opts;
|
|
32838
|
-
if (typeof schema == "object")
|
|
32838
|
+
if (typeof schema == "object") id2 = schema[schemaId];
|
|
32839
32839
|
else if (this.opts.jtd) throw new Error("schema must be object");
|
|
32840
32840
|
else if (typeof schema != "boolean") throw new Error("schema must be object or boolean");
|
|
32841
32841
|
let sch = this._cache.get(schema);
|
|
32842
32842
|
if (sch !== void 0) return sch;
|
|
32843
|
-
baseId = (0, resolve_1.normalizeId)(
|
|
32843
|
+
baseId = (0, resolve_1.normalizeId)(id2 || baseId);
|
|
32844
32844
|
const localRefs = resolve_1.getSchemaRefs.call(this, schema, baseId);
|
|
32845
32845
|
sch = new compile_1.SchemaEnv({
|
|
32846
32846
|
schema,
|
|
@@ -32857,8 +32857,8 @@ var require_core$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
32857
32857
|
if (validateSchema) this.validateSchema(schema, true);
|
|
32858
32858
|
return sch;
|
|
32859
32859
|
}
|
|
32860
|
-
_checkUnique(
|
|
32861
|
-
if (this.schemas[
|
|
32860
|
+
_checkUnique(id2) {
|
|
32861
|
+
if (this.schemas[id2] || this.refs[id2]) throw new Error(`schema with key or id "${id2}" already exists`);
|
|
32862
32862
|
}
|
|
32863
32863
|
_compileSchemaEnv(sch) {
|
|
32864
32864
|
if (sch.meta) this._compileMetaSchema(sch);
|
|
@@ -36278,8 +36278,8 @@ var StdioListenRouter = class {
|
|
|
36278
36278
|
if (serverInfo !== void 0) this._serverInfo = serverInfo;
|
|
36279
36279
|
}
|
|
36280
36280
|
/** Whether `id` is an active listen subscription on this connection. */
|
|
36281
|
-
has(
|
|
36282
|
-
return this._subs.has(
|
|
36281
|
+
has(id2) {
|
|
36282
|
+
return this._subs.has(id2);
|
|
36283
36283
|
}
|
|
36284
36284
|
/**
|
|
36285
36285
|
* Serve one inbound `subscriptions/listen` request: registers the
|
|
@@ -36323,8 +36323,8 @@ var StdioListenRouter = class {
|
|
|
36323
36323
|
* `true` when a subscription was removed. After this call NOTHING further
|
|
36324
36324
|
* is delivered for that subscription id (the post-cancel hardening).
|
|
36325
36325
|
*/
|
|
36326
|
-
cancel(
|
|
36327
|
-
return this._subs.delete(
|
|
36326
|
+
cancel(id2) {
|
|
36327
|
+
return this._subs.delete(id2);
|
|
36328
36328
|
}
|
|
36329
36329
|
/**
|
|
36330
36330
|
* Route an outbound notification through the active subscriptions.
|
|
@@ -36356,13 +36356,13 @@ var StdioListenRouter = class {
|
|
|
36356
36356
|
*/
|
|
36357
36357
|
teardownAll() {
|
|
36358
36358
|
const out = [];
|
|
36359
|
-
for (const
|
|
36359
|
+
for (const id2 of this._subs.keys()) out.push({
|
|
36360
36360
|
jsonrpc: "2.0",
|
|
36361
|
-
id,
|
|
36361
|
+
id: id2,
|
|
36362
36362
|
result: {
|
|
36363
36363
|
resultType: "complete",
|
|
36364
36364
|
_meta: {
|
|
36365
|
-
[SUBSCRIPTION_ID_META_KEY]:
|
|
36365
|
+
[SUBSCRIPTION_ID_META_KEY]: id2,
|
|
36366
36366
|
...this._serverInfo !== void 0 && { [SERVER_INFO_META_KEY]: this._serverInfo }
|
|
36367
36367
|
}
|
|
36368
36368
|
}
|
|
@@ -37001,7 +37001,7 @@ var Server = class extends Protocol {
|
|
|
37001
37001
|
if (hasPreviousToolUse) {
|
|
37002
37002
|
const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
|
|
37003
37003
|
const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
|
|
37004
|
-
if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((
|
|
37004
|
+
if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id2) => toolResultIds.has(id2))) throw new ProtocolError(ProtocolErrorCode.InvalidParams, "ids of tool_result blocks and tool_use blocks from previous message do not match");
|
|
37005
37005
|
}
|
|
37006
37006
|
}
|
|
37007
37007
|
const hasTools = Boolean(params.tools || params.toolChoice);
|
|
@@ -37910,8 +37910,8 @@ var StdioConnectionChannel = class {
|
|
|
37910
37910
|
}
|
|
37911
37911
|
async send(message, options) {
|
|
37912
37912
|
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
|
37913
|
-
const { id } = message;
|
|
37914
|
-
if (
|
|
37913
|
+
const { id: id2 } = message;
|
|
37914
|
+
if (id2 !== void 0) this._settle(id2);
|
|
37915
37915
|
}
|
|
37916
37916
|
if (this._closed) return;
|
|
37917
37917
|
if (this._outboundIntercept?.(message) === "handled") return;
|
|
@@ -37964,8 +37964,8 @@ var StdioConnectionChannel = class {
|
|
|
37964
37964
|
this.onclose?.();
|
|
37965
37965
|
}
|
|
37966
37966
|
}
|
|
37967
|
-
_settle(
|
|
37968
|
-
this._pendingRequests.delete(
|
|
37967
|
+
_settle(id2) {
|
|
37968
|
+
this._pendingRequests.delete(id2);
|
|
37969
37969
|
if (this._pendingRequests.size === 0) this._releaseDrainWaiters();
|
|
37970
37970
|
}
|
|
37971
37971
|
_releaseDrainWaiters() {
|
|
@@ -38021,9 +38021,9 @@ function serveStdio(factory, options = {}) {
|
|
|
38021
38021
|
} catch {
|
|
38022
38022
|
}
|
|
38023
38023
|
};
|
|
38024
|
-
const writeErrorResponse = (
|
|
38024
|
+
const writeErrorResponse = (id2, code2, message, data) => wire.send({
|
|
38025
38025
|
jsonrpc: "2.0",
|
|
38026
|
-
id,
|
|
38026
|
+
id: id2,
|
|
38027
38027
|
error: {
|
|
38028
38028
|
code: code2,
|
|
38029
38029
|
message,
|
|
@@ -38380,7 +38380,8 @@ var FORM_PASSWORD_RE = /((?:^|[\s,;:"'(\[{])(?:password|passwd)=)[^&#\s"'<>`]+/g
|
|
|
38380
38380
|
var HEADER_SECRET_RE = new RegExp(`(\\b(?:x[-_]${HEADER_NAME_RUN}?(?:api[-_]?key|token|secret|auth)${HEADER_NAME_RUN}|api[-_]?key)\\s*:\\s*)[^\\s,;"'<>\`]+`, "gi");
|
|
38381
38381
|
var AWS_SIGV4_RE = /([?&]X-Amz-(?:Signature|Security-Token|Credential)=)[^&#\s"'<>`]+/gi;
|
|
38382
38382
|
var JSON_SECRET_KEYS = [
|
|
38383
|
-
"(?:access|refresh|id|auth|session|bearer|csrf|xsrf)[_-]?token",
|
|
38383
|
+
"(?:access|refresh|id|auth|session|bearer|csrf|xsrf|api)[_-]?token",
|
|
38384
|
+
// api: fleet-audit#1444 (Pipedrive/Todoist-style, as in QUERY_SECRET_RE)
|
|
38384
38385
|
"client[_-]?secret",
|
|
38385
38386
|
"api[_-]?secret",
|
|
38386
38387
|
"(?:x[_-])?api[_-]?key",
|
|
@@ -39726,6 +39727,88 @@ function parseContentDispositionFilename(header) {
|
|
|
39726
39727
|
return rawExt;
|
|
39727
39728
|
}
|
|
39728
39729
|
|
|
39730
|
+
// node_modules/@chrischall/mcp-utils/dist/netguard/address.js
|
|
39731
|
+
function parseIPv4(text) {
|
|
39732
|
+
if (!/^(?:0|[1-9]\d{0,2})(?:\.(?:0|[1-9]\d{0,2})){3}$/.test(text))
|
|
39733
|
+
return void 0;
|
|
39734
|
+
const octets = text.split(".").map(Number);
|
|
39735
|
+
return octets.every((o) => o <= 255) ? octets : void 0;
|
|
39736
|
+
}
|
|
39737
|
+
function parseIPv6(text) {
|
|
39738
|
+
if (!/^[0-9a-fA-F:.]+$/.test(text) || !text.includes(":"))
|
|
39739
|
+
return void 0;
|
|
39740
|
+
const halves = text.split("::");
|
|
39741
|
+
if (halves.length > 2)
|
|
39742
|
+
return void 0;
|
|
39743
|
+
const groups = (part) => {
|
|
39744
|
+
if (part === "")
|
|
39745
|
+
return [];
|
|
39746
|
+
const out = [];
|
|
39747
|
+
const pieces = part.split(":");
|
|
39748
|
+
for (const [i, piece] of pieces.entries()) {
|
|
39749
|
+
if (i === pieces.length - 1 && piece.includes(".")) {
|
|
39750
|
+
const v4 = parseIPv4(piece);
|
|
39751
|
+
if (!v4)
|
|
39752
|
+
return void 0;
|
|
39753
|
+
const [a = 0, b = 0, c = 0, d = 0] = v4;
|
|
39754
|
+
out.push(a << 8 | b, c << 8 | d);
|
|
39755
|
+
continue;
|
|
39756
|
+
}
|
|
39757
|
+
if (!/^[0-9a-fA-F]{1,4}$/.test(piece))
|
|
39758
|
+
return void 0;
|
|
39759
|
+
out.push(parseInt(piece, 16));
|
|
39760
|
+
}
|
|
39761
|
+
return out;
|
|
39762
|
+
};
|
|
39763
|
+
const head = groups(halves[0] ?? "");
|
|
39764
|
+
const tail = halves.length === 2 ? groups(halves[1] ?? "") : [];
|
|
39765
|
+
if (!head || !tail)
|
|
39766
|
+
return void 0;
|
|
39767
|
+
const fill = 8 - head.length - tail.length;
|
|
39768
|
+
if (halves.length === 2 ? fill < 1 : fill !== 0)
|
|
39769
|
+
return void 0;
|
|
39770
|
+
const words = [...head, ...new Array(fill).fill(0), ...tail];
|
|
39771
|
+
const bytes = [];
|
|
39772
|
+
for (const w of words)
|
|
39773
|
+
bytes.push(w >> 8, w & 255);
|
|
39774
|
+
return bytes;
|
|
39775
|
+
}
|
|
39776
|
+
var V6 = (hex3) => parseIPv6(hex3);
|
|
39777
|
+
var BLOCKED_V6 = [
|
|
39778
|
+
[V6("::"), 96],
|
|
39779
|
+
// ::, ::1 and the deprecated IPv4-compatible form, refused whole
|
|
39780
|
+
[V6("64:ff9b:1::"), 48],
|
|
39781
|
+
// local-use NAT64 (RFC 8215)
|
|
39782
|
+
[V6("100::"), 64],
|
|
39783
|
+
// discard-only
|
|
39784
|
+
[V6("2001::"), 32],
|
|
39785
|
+
// Teredo
|
|
39786
|
+
[V6("2001:2::"), 48],
|
|
39787
|
+
// benchmarking
|
|
39788
|
+
[V6("2001:10::"), 28],
|
|
39789
|
+
// ORCHID (deprecated)
|
|
39790
|
+
[V6("2001:20::"), 28],
|
|
39791
|
+
// ORCHIDv2
|
|
39792
|
+
[V6("2001:db8::"), 32],
|
|
39793
|
+
// documentation
|
|
39794
|
+
[V6("3fff::"), 20],
|
|
39795
|
+
// documentation (RFC 9637)
|
|
39796
|
+
[V6("5f00::"), 16],
|
|
39797
|
+
// SRv6 SIDs
|
|
39798
|
+
[V6("fc00::"), 7],
|
|
39799
|
+
// unique local
|
|
39800
|
+
[V6("fe80::"), 10],
|
|
39801
|
+
// link-local
|
|
39802
|
+
[V6("fec0::"), 10],
|
|
39803
|
+
// site-local (deprecated)
|
|
39804
|
+
[V6("ff00::"), 8]
|
|
39805
|
+
// multicast
|
|
39806
|
+
];
|
|
39807
|
+
var MAPPED_V4 = V6("::ffff:0:0");
|
|
39808
|
+
var SIIT_V4 = V6("::ffff:0:0:0");
|
|
39809
|
+
var NAT64 = V6("64:ff9b::");
|
|
39810
|
+
var SIX_TO_FOUR = V6("2002::");
|
|
39811
|
+
|
|
39729
39812
|
// node_modules/@chrischall/mcp-utils/dist/http/index.js
|
|
39730
39813
|
var RateLimitedError = class extends Error {
|
|
39731
39814
|
status = 429;
|
|
@@ -40642,12 +40725,12 @@ var PROTOCOL_VERSION = 4;
|
|
|
40642
40725
|
var HKDF_SESSION_INFO = "fetchproxy/4.0.0/session";
|
|
40643
40726
|
var enc = new TextEncoder();
|
|
40644
40727
|
function helloSignaturePayload(mcpId, sessionNonce, sessionPub, answersExtNonce) {
|
|
40645
|
-
const
|
|
40646
|
-
const out = new Uint8Array(
|
|
40647
|
-
out.set(
|
|
40648
|
-
out.set(sessionNonce,
|
|
40649
|
-
out.set(sessionPub,
|
|
40650
|
-
out.set(answersExtNonce,
|
|
40728
|
+
const id2 = enc.encode(mcpId);
|
|
40729
|
+
const out = new Uint8Array(id2.length + sessionNonce.length + sessionPub.length + answersExtNonce.length);
|
|
40730
|
+
out.set(id2, 0);
|
|
40731
|
+
out.set(sessionNonce, id2.length);
|
|
40732
|
+
out.set(sessionPub, id2.length + sessionNonce.length);
|
|
40733
|
+
out.set(answersExtNonce, id2.length + sessionNonce.length + sessionPub.length);
|
|
40651
40734
|
return out;
|
|
40652
40735
|
}
|
|
40653
40736
|
var ANSWERS_NO_EXT_SESSION = new Uint8Array(32);
|
|
@@ -40725,8 +40808,8 @@ function generateMcpId(serverName, version2) {
|
|
|
40725
40808
|
const rand = randomHex(8);
|
|
40726
40809
|
return `${serverName}:${version2}:${rand}`;
|
|
40727
40810
|
}
|
|
40728
|
-
function isValidMcpId(
|
|
40729
|
-
return typeof
|
|
40811
|
+
function isValidMcpId(id2) {
|
|
40812
|
+
return typeof id2 === "string" && ID_RE.test(id2);
|
|
40730
40813
|
}
|
|
40731
40814
|
function randomHex(bytes) {
|
|
40732
40815
|
const arr = new Uint8Array(bytes);
|
|
@@ -42722,13 +42805,13 @@ async function generateIdentity() {
|
|
|
42722
42805
|
createdAt: Date.now()
|
|
42723
42806
|
};
|
|
42724
42807
|
}
|
|
42725
|
-
function serializeIdentity(
|
|
42808
|
+
function serializeIdentity(id2) {
|
|
42726
42809
|
return JSON.stringify({
|
|
42727
|
-
x25519Priv: toB64(
|
|
42728
|
-
x25519Pub: toB64(
|
|
42729
|
-
ed25519Priv: toB64(
|
|
42730
|
-
ed25519Pub: toB64(
|
|
42731
|
-
createdAt:
|
|
42810
|
+
x25519Priv: toB64(id2.x25519Priv),
|
|
42811
|
+
x25519Pub: toB64(id2.x25519Pub),
|
|
42812
|
+
ed25519Priv: toB64(id2.ed25519Priv),
|
|
42813
|
+
ed25519Pub: toB64(id2.ed25519Pub),
|
|
42814
|
+
createdAt: id2.createdAt
|
|
42732
42815
|
}, null, 2);
|
|
42733
42816
|
}
|
|
42734
42817
|
function parseIdentity(text) {
|
|
@@ -42784,9 +42867,9 @@ async function loadOrCreateIdentity(serverName, dir = defaultIdentityDir()) {
|
|
|
42784
42867
|
let unreadable = null;
|
|
42785
42868
|
let recovered = false;
|
|
42786
42869
|
for (let attempt = 0; attempt < 5; attempt++) {
|
|
42787
|
-
const
|
|
42788
|
-
if (await publishIdentityIfAbsent(dir, serverName,
|
|
42789
|
-
return
|
|
42870
|
+
const id2 = await generateIdentity();
|
|
42871
|
+
if (await publishIdentityIfAbsent(dir, serverName, id2))
|
|
42872
|
+
return id2;
|
|
42790
42873
|
try {
|
|
42791
42874
|
return parseIdentity(await readFile(path, "utf8"));
|
|
42792
42875
|
} catch (e) {
|
|
@@ -42809,12 +42892,12 @@ async function loadOrCreateIdentity(serverName, dir = defaultIdentityDir()) {
|
|
|
42809
42892
|
throw new Error(`fetchproxy: could not create an identity for ${JSON.stringify(serverName)} in ${dir}`);
|
|
42810
42893
|
}
|
|
42811
42894
|
var NO_HARD_LINKS = /* @__PURE__ */ new Set(["EPERM", "ENOTSUP", "EOPNOTSUPP", "ENOSYS"]);
|
|
42812
|
-
async function publishIdentityIfAbsent(dir, serverName,
|
|
42895
|
+
async function publishIdentityIfAbsent(dir, serverName, id2) {
|
|
42813
42896
|
const path = identityFilePath(dir, serverName);
|
|
42814
42897
|
await sweepStagingFiles(dir, serverName, { olderThanMs: 6e4 });
|
|
42815
42898
|
const tmp = `${path}.${randomBytes5(STAGING_BYTES).toString("hex")}.tmp`;
|
|
42816
42899
|
try {
|
|
42817
|
-
await writeFile(tmp, serializeIdentity(
|
|
42900
|
+
await writeFile(tmp, serializeIdentity(id2), { mode: 384, flag: "wx" });
|
|
42818
42901
|
await chmod(tmp, 384);
|
|
42819
42902
|
try {
|
|
42820
42903
|
await link(tmp, path);
|
|
@@ -42823,7 +42906,7 @@ async function publishIdentityIfAbsent(dir, serverName, id) {
|
|
|
42823
42906
|
if (code2 === void 0 || !NO_HARD_LINKS.has(code2))
|
|
42824
42907
|
throw e;
|
|
42825
42908
|
try {
|
|
42826
|
-
await writeFile(path, serializeIdentity(
|
|
42909
|
+
await writeFile(path, serializeIdentity(id2), { mode: 384, flag: "wx" });
|
|
42827
42910
|
} catch (writeErr) {
|
|
42828
42911
|
if (writeErr.code !== "EEXIST") {
|
|
42829
42912
|
await rm(path, { force: true }).catch(() => void 0);
|
|
@@ -45057,17 +45140,17 @@ var FetchproxyServer = class {
|
|
|
45057
45140
|
}
|
|
45058
45141
|
} catch (err) {
|
|
45059
45142
|
if ("id" in inner && typeof inner.id === "number") {
|
|
45060
|
-
const { id } = inner;
|
|
45061
|
-
this.pending.delete(
|
|
45062
|
-
this.pendingReadCookies.delete(
|
|
45063
|
-
this.pendingStorage.delete(
|
|
45064
|
-
this.pendingWriteCookies.delete(
|
|
45065
|
-
this.pendingCapture.delete(
|
|
45066
|
-
this.pendingRedirect.delete(
|
|
45067
|
-
this.pendingDownload.delete(
|
|
45068
|
-
this.pendingIdb.delete(
|
|
45069
|
-
this.pendingDomList.delete(
|
|
45070
|
-
this.pendingGraphql.delete(
|
|
45143
|
+
const { id: id2 } = inner;
|
|
45144
|
+
this.pending.delete(id2);
|
|
45145
|
+
this.pendingReadCookies.delete(id2);
|
|
45146
|
+
this.pendingStorage.delete(id2);
|
|
45147
|
+
this.pendingWriteCookies.delete(id2);
|
|
45148
|
+
this.pendingCapture.delete(id2);
|
|
45149
|
+
this.pendingRedirect.delete(id2);
|
|
45150
|
+
this.pendingDownload.delete(id2);
|
|
45151
|
+
this.pendingIdb.delete(id2);
|
|
45152
|
+
this.pendingDomList.delete(id2);
|
|
45153
|
+
this.pendingGraphql.delete(id2);
|
|
45071
45154
|
}
|
|
45072
45155
|
throw err;
|
|
45073
45156
|
}
|
|
@@ -45078,10 +45161,10 @@ var FetchproxyServer = class {
|
|
|
45078
45161
|
* the throwing surface is the convenience methods.
|
|
45079
45162
|
*/
|
|
45080
45163
|
async _fetchOnceWithTimeout(init, fetchOpts = {}) {
|
|
45081
|
-
const
|
|
45082
|
-
const inner = { type: "request", id, op: "fetch", init };
|
|
45164
|
+
const id2 = this.nextRequestId++;
|
|
45165
|
+
const inner = { type: "request", id: id2, op: "fetch", init };
|
|
45083
45166
|
const pending = this.guardPending(new Promise((resolve7) => {
|
|
45084
|
-
this.pending.set(
|
|
45167
|
+
this.pending.set(id2, resolve7);
|
|
45085
45168
|
}));
|
|
45086
45169
|
try {
|
|
45087
45170
|
await this.sendInnerFrame(inner, {
|
|
@@ -45115,7 +45198,7 @@ var FetchproxyServer = class {
|
|
|
45115
45198
|
pending,
|
|
45116
45199
|
new Promise((resolve7) => {
|
|
45117
45200
|
timer = setTimeout(() => {
|
|
45118
|
-
this.pending.delete(
|
|
45201
|
+
this.pending.delete(id2);
|
|
45119
45202
|
const elapsedMs = Date.now() - start;
|
|
45120
45203
|
const base = `fetchproxy: ${init.url} did not respond within ${timeoutMs}ms`;
|
|
45121
45204
|
const error62 = isRetrySafeOnTimeout(init.method, fetchOpts.retryOnTimeout) ? base : withNotResentNote(base);
|
|
@@ -45179,7 +45262,7 @@ var FetchproxyServer = class {
|
|
|
45179
45262
|
});
|
|
45180
45263
|
return pending;
|
|
45181
45264
|
}
|
|
45182
|
-
async _withVerbTimeout(pending, pendingMap,
|
|
45265
|
+
async _withVerbTimeout(pending, pendingMap, id2, url2, requestedTimeoutMs, retrySafe = true) {
|
|
45183
45266
|
const transportMs = this.opts.fetchTimeoutMs;
|
|
45184
45267
|
if (transportMs === void 0 || transportMs <= 0)
|
|
45185
45268
|
return pending;
|
|
@@ -45192,7 +45275,7 @@ var FetchproxyServer = class {
|
|
|
45192
45275
|
pending,
|
|
45193
45276
|
new Promise((_resolve, reject) => {
|
|
45194
45277
|
timer = setTimeout(() => {
|
|
45195
|
-
pendingMap.delete(
|
|
45278
|
+
pendingMap.delete(id2);
|
|
45196
45279
|
reject(new FetchproxyTimeoutError({
|
|
45197
45280
|
url: url2,
|
|
45198
45281
|
timeoutMs,
|
|
@@ -45529,7 +45612,7 @@ var FetchproxyServer = class {
|
|
|
45529
45612
|
assertSubdomainLabel(opts.subdomain);
|
|
45530
45613
|
const baseDomain = this.resolveBaseDomain(opts.domain);
|
|
45531
45614
|
const host = opts.subdomain ? `${opts.subdomain}.${baseDomain}` : baseDomain;
|
|
45532
|
-
const
|
|
45615
|
+
const id2 = this.nextRequestId++;
|
|
45533
45616
|
let inner;
|
|
45534
45617
|
if (opts.keys !== void 0) {
|
|
45535
45618
|
this.assertScopeSubset(opts.keys, this.opts.cookieKeys, "cookieKeys");
|
|
@@ -45542,16 +45625,16 @@ var FetchproxyServer = class {
|
|
|
45542
45625
|
keys: [...opts.keys],
|
|
45543
45626
|
...cookiePath !== void 0 ? { path: cookiePath } : {}
|
|
45544
45627
|
};
|
|
45545
|
-
inner = { type: "request", id, op: "read_cookies", init: initV3 };
|
|
45628
|
+
inner = { type: "request", id: id2, op: "read_cookies", init: initV3 };
|
|
45546
45629
|
} else {
|
|
45547
45630
|
const tabUrl = `https://${host}/`;
|
|
45548
|
-
inner = { type: "request", id, op: "read_cookies", init: { tabUrl } };
|
|
45631
|
+
inner = { type: "request", id: id2, op: "read_cookies", init: { tabUrl } };
|
|
45549
45632
|
}
|
|
45550
45633
|
const pending = this.guardPending(new Promise((resolve7) => {
|
|
45551
|
-
this.pendingReadCookies.set(
|
|
45634
|
+
this.pendingReadCookies.set(id2, resolve7);
|
|
45552
45635
|
}));
|
|
45553
45636
|
await this.sendInnerFrame(inner);
|
|
45554
|
-
const result = await this._withVerbTimeout(pending, this.pendingReadCookies,
|
|
45637
|
+
const result = await this._withVerbTimeout(pending, this.pendingReadCookies, id2, `https://${host}`);
|
|
45555
45638
|
if (!result.ok) {
|
|
45556
45639
|
throw protocolErrorFrom(result.error);
|
|
45557
45640
|
}
|
|
@@ -45593,10 +45676,10 @@ var FetchproxyServer = class {
|
|
|
45593
45676
|
const host = opts.subdomain ? `${opts.subdomain}.${baseDomain}` : baseDomain;
|
|
45594
45677
|
this.assertScopeSubset(names, this.opts.cookieKeys, "cookieKeys");
|
|
45595
45678
|
const cookiePath = normalizeCookiePath(opts.path);
|
|
45596
|
-
const
|
|
45679
|
+
const id2 = this.nextRequestId++;
|
|
45597
45680
|
const inner = {
|
|
45598
45681
|
type: "request",
|
|
45599
|
-
id,
|
|
45682
|
+
id: id2,
|
|
45600
45683
|
op: "write_cookies",
|
|
45601
45684
|
init: {
|
|
45602
45685
|
// Bare origin, same invariant as the read path: a path must never be
|
|
@@ -45607,13 +45690,13 @@ var FetchproxyServer = class {
|
|
|
45607
45690
|
}
|
|
45608
45691
|
};
|
|
45609
45692
|
const pending = this.guardPending(new Promise((resolve7, reject) => {
|
|
45610
|
-
this.pendingWriteCookies.set(
|
|
45693
|
+
this.pendingWriteCookies.set(id2, { resolve: resolve7, reject });
|
|
45611
45694
|
}));
|
|
45612
45695
|
await this.sendInnerFrame(inner);
|
|
45613
45696
|
return this._withVerbTimeout(
|
|
45614
45697
|
pending,
|
|
45615
45698
|
this.pendingWriteCookies,
|
|
45616
|
-
|
|
45699
|
+
id2,
|
|
45617
45700
|
`https://${host}`,
|
|
45618
45701
|
void 0,
|
|
45619
45702
|
// A write: never re-sent after an ambiguous timeout.
|
|
@@ -45666,10 +45749,10 @@ var FetchproxyServer = class {
|
|
|
45666
45749
|
assertSubdomainLabel(opts.subdomain);
|
|
45667
45750
|
const baseDomain = this.resolveBaseDomain(opts.domain);
|
|
45668
45751
|
const host = opts.subdomain ? `${opts.subdomain}.${baseDomain}` : baseDomain;
|
|
45669
|
-
const
|
|
45752
|
+
const id2 = this.nextRequestId++;
|
|
45670
45753
|
const inner = {
|
|
45671
45754
|
type: "request",
|
|
45672
|
-
id,
|
|
45755
|
+
id: id2,
|
|
45673
45756
|
op,
|
|
45674
45757
|
init: {
|
|
45675
45758
|
origin: `https://${host}`,
|
|
@@ -45678,10 +45761,10 @@ var FetchproxyServer = class {
|
|
|
45678
45761
|
}
|
|
45679
45762
|
};
|
|
45680
45763
|
const pending = this.guardPending(new Promise((resolve7, reject) => {
|
|
45681
|
-
this.pendingStorage.set(
|
|
45764
|
+
this.pendingStorage.set(id2, { resolve: resolve7, reject });
|
|
45682
45765
|
}));
|
|
45683
45766
|
await this.sendInnerFrame(inner);
|
|
45684
|
-
return this._withVerbTimeout(pending, this.pendingStorage,
|
|
45767
|
+
return this._withVerbTimeout(pending, this.pendingStorage, id2, `https://${host}`);
|
|
45685
45768
|
}
|
|
45686
45769
|
/**
|
|
45687
45770
|
* 0.3.0+: snapshot the next outgoing request's named header. Single-
|
|
@@ -45724,10 +45807,10 @@ var FetchproxyServer = class {
|
|
|
45724
45807
|
return this.withLazyRevive("capture_request_header", `https://${resolved.host}${resolved.path ?? "/*"}`, () => this._captureRequestHeaderOnce(callOpts));
|
|
45725
45808
|
}
|
|
45726
45809
|
async _captureRequestHeaderOnce(opts) {
|
|
45727
|
-
const
|
|
45810
|
+
const id2 = this.nextRequestId++;
|
|
45728
45811
|
const inner = {
|
|
45729
45812
|
type: "request",
|
|
45730
|
-
id,
|
|
45813
|
+
id: id2,
|
|
45731
45814
|
op: "capture_request_header",
|
|
45732
45815
|
init: {
|
|
45733
45816
|
host: opts.host,
|
|
@@ -45737,13 +45820,13 @@ var FetchproxyServer = class {
|
|
|
45737
45820
|
}
|
|
45738
45821
|
};
|
|
45739
45822
|
const pending = this.guardPending(new Promise((resolve7, reject) => {
|
|
45740
|
-
this.pendingCapture.set(
|
|
45823
|
+
this.pendingCapture.set(id2, { resolve: resolve7, reject });
|
|
45741
45824
|
}));
|
|
45742
45825
|
await this.sendInnerFrame(inner);
|
|
45743
45826
|
return this._withVerbTimeout(
|
|
45744
45827
|
pending,
|
|
45745
45828
|
this.pendingCapture,
|
|
45746
|
-
|
|
45829
|
+
id2,
|
|
45747
45830
|
`https://${opts.host}${opts.path ?? "/*"}`,
|
|
45748
45831
|
// #237: this GOVERNS the deadline (window + reply grace, floored at the
|
|
45749
45832
|
// transport bound). Under #277 it did not, and was passed only so the
|
|
@@ -45773,10 +45856,10 @@ var FetchproxyServer = class {
|
|
|
45773
45856
|
return this.withLazyRevive("capture_redirect", `https://${opts.host}${opts.path ?? "/*"}`, () => this._captureRedirectOnce(opts));
|
|
45774
45857
|
}
|
|
45775
45858
|
async _captureRedirectOnce(opts) {
|
|
45776
|
-
const
|
|
45859
|
+
const id2 = this.nextRequestId++;
|
|
45777
45860
|
const inner = {
|
|
45778
45861
|
type: "request",
|
|
45779
|
-
id,
|
|
45862
|
+
id: id2,
|
|
45780
45863
|
op: "capture_redirect",
|
|
45781
45864
|
init: {
|
|
45782
45865
|
host: opts.host,
|
|
@@ -45785,13 +45868,13 @@ var FetchproxyServer = class {
|
|
|
45785
45868
|
}
|
|
45786
45869
|
};
|
|
45787
45870
|
const pending = this.guardPending(new Promise((resolve7, reject) => {
|
|
45788
|
-
this.pendingRedirect.set(
|
|
45871
|
+
this.pendingRedirect.set(id2, { resolve: resolve7, reject });
|
|
45789
45872
|
}));
|
|
45790
45873
|
await this.sendInnerFrame(inner);
|
|
45791
45874
|
return this._withVerbTimeout(
|
|
45792
45875
|
pending,
|
|
45793
45876
|
this.pendingRedirect,
|
|
45794
|
-
|
|
45877
|
+
id2,
|
|
45795
45878
|
`https://${opts.host}${opts.path ?? "/*"}`,
|
|
45796
45879
|
// #237: this GOVERNS the deadline (window + reply grace, floored at the
|
|
45797
45880
|
// transport bound). Under #277 it did not, and was passed only so the
|
|
@@ -45869,10 +45952,10 @@ var FetchproxyServer = class {
|
|
|
45869
45952
|
}
|
|
45870
45953
|
}
|
|
45871
45954
|
async _downloadOnce(opts) {
|
|
45872
|
-
const
|
|
45955
|
+
const id2 = this.nextRequestId++;
|
|
45873
45956
|
const inner = {
|
|
45874
45957
|
type: "request",
|
|
45875
|
-
id,
|
|
45958
|
+
id: id2,
|
|
45876
45959
|
op: "download",
|
|
45877
45960
|
init: {
|
|
45878
45961
|
url: opts.url,
|
|
@@ -45881,13 +45964,13 @@ var FetchproxyServer = class {
|
|
|
45881
45964
|
}
|
|
45882
45965
|
};
|
|
45883
45966
|
const pending = this.guardPending(new Promise((resolve7, reject) => {
|
|
45884
|
-
this.pendingDownload.set(
|
|
45967
|
+
this.pendingDownload.set(id2, { resolve: resolve7, reject });
|
|
45885
45968
|
}));
|
|
45886
45969
|
await this.sendInnerFrame(inner);
|
|
45887
45970
|
return this._withVerbTimeout(
|
|
45888
45971
|
pending,
|
|
45889
45972
|
this.pendingDownload,
|
|
45890
|
-
|
|
45973
|
+
id2,
|
|
45891
45974
|
opts.url,
|
|
45892
45975
|
// `download` takes a per-call timeoutMs like the two capture verbs, so
|
|
45893
45976
|
// it is governed by it like them (#237). It used to hit the identical
|
|
@@ -45929,10 +46012,10 @@ var FetchproxyServer = class {
|
|
|
45929
46012
|
throw new Error(`FetchproxyServer.readIndexedDb: (origin=${origin}, database=${JSON.stringify(opts.database)}, store=${JSON.stringify(opts.store)}) not declared in indexedDbScopes`);
|
|
45930
46013
|
}
|
|
45931
46014
|
this.assertScopeSubset(opts.keys, decl.keys, "indexedDbScopes.keys");
|
|
45932
|
-
const
|
|
46015
|
+
const id2 = this.nextRequestId++;
|
|
45933
46016
|
const inner = {
|
|
45934
46017
|
type: "request",
|
|
45935
|
-
id,
|
|
46018
|
+
id: id2,
|
|
45936
46019
|
op: "read_indexed_db",
|
|
45937
46020
|
init: {
|
|
45938
46021
|
origin,
|
|
@@ -45942,10 +46025,10 @@ var FetchproxyServer = class {
|
|
|
45942
46025
|
}
|
|
45943
46026
|
};
|
|
45944
46027
|
const pending = this.guardPending(new Promise((resolve7, reject) => {
|
|
45945
|
-
this.pendingIdb.set(
|
|
46028
|
+
this.pendingIdb.set(id2, { resolve: resolve7, reject });
|
|
45946
46029
|
}));
|
|
45947
46030
|
await this.sendInnerFrame(inner);
|
|
45948
|
-
return this._withVerbTimeout(pending, this.pendingIdb,
|
|
46031
|
+
return this._withVerbTimeout(pending, this.pendingIdb, id2, origin);
|
|
45949
46032
|
}
|
|
45950
46033
|
/**
|
|
45951
46034
|
* 1.4.0+: read declared DOM values from the user's signed-in tab.
|
|
@@ -45974,18 +46057,18 @@ var FetchproxyServer = class {
|
|
|
45974
46057
|
const baseDomain = this.resolveBaseDomain(opts.domain);
|
|
45975
46058
|
const host = opts.subdomain ? `${opts.subdomain}.${baseDomain}` : baseDomain;
|
|
45976
46059
|
const origin = `https://${host}`;
|
|
45977
|
-
const
|
|
46060
|
+
const id2 = this.nextRequestId++;
|
|
45978
46061
|
const inner = {
|
|
45979
46062
|
type: "request",
|
|
45980
|
-
id,
|
|
46063
|
+
id: id2,
|
|
45981
46064
|
op: "read_dom",
|
|
45982
46065
|
init: { origin, names: [...opts.names] }
|
|
45983
46066
|
};
|
|
45984
46067
|
const pending = this.guardPending(new Promise((resolve7, reject) => {
|
|
45985
|
-
this.pendingStorage.set(
|
|
46068
|
+
this.pendingStorage.set(id2, { resolve: resolve7, reject });
|
|
45986
46069
|
}));
|
|
45987
46070
|
await this.sendInnerFrame(inner);
|
|
45988
|
-
return this._withVerbTimeout(pending, this.pendingStorage,
|
|
46071
|
+
return this._withVerbTimeout(pending, this.pendingStorage, id2, origin);
|
|
45989
46072
|
}
|
|
45990
46073
|
/**
|
|
45991
46074
|
* 3.1.0+: read a declared REPEATED DOM structure from the user's
|
|
@@ -46020,18 +46103,18 @@ var FetchproxyServer = class {
|
|
|
46020
46103
|
const baseDomain = this.resolveBaseDomain(opts.domain);
|
|
46021
46104
|
const host = opts.subdomain ? `${opts.subdomain}.${baseDomain}` : baseDomain;
|
|
46022
46105
|
const origin = `https://${host}`;
|
|
46023
|
-
const
|
|
46106
|
+
const id2 = this.nextRequestId++;
|
|
46024
46107
|
const inner = {
|
|
46025
46108
|
type: "request",
|
|
46026
|
-
id,
|
|
46109
|
+
id: id2,
|
|
46027
46110
|
op: "read_dom_list",
|
|
46028
46111
|
init: { origin, name: opts.name }
|
|
46029
46112
|
};
|
|
46030
46113
|
const pending = this.guardPending(new Promise((resolve7, reject) => {
|
|
46031
|
-
this.pendingDomList.set(
|
|
46114
|
+
this.pendingDomList.set(id2, { resolve: resolve7, reject });
|
|
46032
46115
|
}));
|
|
46033
46116
|
await this.sendInnerFrame(inner);
|
|
46034
|
-
return this._withVerbTimeout(pending, this.pendingDomList,
|
|
46117
|
+
return this._withVerbTimeout(pending, this.pendingDomList, id2, origin);
|
|
46035
46118
|
}
|
|
46036
46119
|
/**
|
|
46037
46120
|
* 1.x+: run a declared GraphQL operation through the page's own Apollo
|
|
@@ -46062,10 +46145,10 @@ var FetchproxyServer = class {
|
|
|
46062
46145
|
}
|
|
46063
46146
|
await this.ensureConnected();
|
|
46064
46147
|
this.throwIfPendingPair();
|
|
46065
|
-
const
|
|
46148
|
+
const id2 = this.nextRequestId++;
|
|
46066
46149
|
const inner = {
|
|
46067
46150
|
type: "request",
|
|
46068
|
-
id,
|
|
46151
|
+
id: id2,
|
|
46069
46152
|
op: "graphql_query",
|
|
46070
46153
|
init: {
|
|
46071
46154
|
name: opts.name,
|
|
@@ -46074,11 +46157,11 @@ var FetchproxyServer = class {
|
|
|
46074
46157
|
}
|
|
46075
46158
|
};
|
|
46076
46159
|
const pending = this.guardPending(new Promise((resolve7, reject) => {
|
|
46077
|
-
this.pendingGraphql.set(
|
|
46160
|
+
this.pendingGraphql.set(id2, { resolve: resolve7, reject });
|
|
46078
46161
|
}));
|
|
46079
46162
|
const retrySafe = opts.retryOnTimeout === true;
|
|
46080
46163
|
await this.sendInnerFrame(inner, { resendable: retrySafe });
|
|
46081
|
-
return this._withVerbTimeout(pending, this.pendingGraphql,
|
|
46164
|
+
return this._withVerbTimeout(pending, this.pendingGraphql, id2, opts.name, void 0, retrySafe);
|
|
46082
46165
|
}
|
|
46083
46166
|
assertScopeSubset(requested, declared, label) {
|
|
46084
46167
|
const undeclared = undeclaredKeys(requested, declared);
|
|
@@ -46278,9 +46361,9 @@ var FetchproxyServer = class {
|
|
|
46278
46361
|
}
|
|
46279
46362
|
}
|
|
46280
46363
|
rejectAllPending(reason = "extension disconnected", keep = /* @__PURE__ */ new Set()) {
|
|
46281
|
-
for (const
|
|
46282
|
-
if (!keep.has(
|
|
46283
|
-
this.rejectPendingId(
|
|
46364
|
+
for (const id2 of this.allPendingIds()) {
|
|
46365
|
+
if (!keep.has(id2))
|
|
46366
|
+
this.rejectPendingId(id2, reason);
|
|
46284
46367
|
}
|
|
46285
46368
|
if (keep.size === 0)
|
|
46286
46369
|
this.resendable.clear();
|
|
@@ -46289,8 +46372,8 @@ var FetchproxyServer = class {
|
|
|
46289
46372
|
allPendingIds() {
|
|
46290
46373
|
const ids = [];
|
|
46291
46374
|
for (const map2 of this.pendingMaps())
|
|
46292
|
-
for (const
|
|
46293
|
-
ids.push(
|
|
46375
|
+
for (const id2 of map2.keys())
|
|
46376
|
+
ids.push(id2);
|
|
46294
46377
|
return ids;
|
|
46295
46378
|
}
|
|
46296
46379
|
pendingMaps() {
|
|
@@ -46307,16 +46390,16 @@ var FetchproxyServer = class {
|
|
|
46307
46390
|
this.pendingGraphql
|
|
46308
46391
|
];
|
|
46309
46392
|
}
|
|
46310
|
-
isPendingId(
|
|
46311
|
-
return this.pendingMaps().some((m) => m.has(
|
|
46393
|
+
isPendingId(id2) {
|
|
46394
|
+
return this.pendingMaps().some((m) => m.has(id2));
|
|
46312
46395
|
}
|
|
46313
46396
|
/** Fail the one awaiter registered under `id`, in its own map's shape. */
|
|
46314
|
-
rejectPendingId(
|
|
46397
|
+
rejectPendingId(id2, reason) {
|
|
46315
46398
|
const err = new FetchproxyProtocolError(reason);
|
|
46316
|
-
this.resendable.delete(
|
|
46317
|
-
const fetchCb = this.pending.get(
|
|
46399
|
+
this.resendable.delete(id2);
|
|
46400
|
+
const fetchCb = this.pending.get(id2);
|
|
46318
46401
|
if (fetchCb) {
|
|
46319
|
-
this.pending.delete(
|
|
46402
|
+
this.pending.delete(id2);
|
|
46320
46403
|
fetchCb({
|
|
46321
46404
|
ok: false,
|
|
46322
46405
|
error: err.message,
|
|
@@ -46325,9 +46408,9 @@ var FetchproxyServer = class {
|
|
|
46325
46408
|
});
|
|
46326
46409
|
return;
|
|
46327
46410
|
}
|
|
46328
|
-
const cookieCb = this.pendingReadCookies.get(
|
|
46411
|
+
const cookieCb = this.pendingReadCookies.get(id2);
|
|
46329
46412
|
if (cookieCb) {
|
|
46330
|
-
this.pendingReadCookies.delete(
|
|
46413
|
+
this.pendingReadCookies.delete(id2);
|
|
46331
46414
|
cookieCb({ ok: false, error: err.message });
|
|
46332
46415
|
return;
|
|
46333
46416
|
}
|
|
@@ -46341,9 +46424,9 @@ var FetchproxyServer = class {
|
|
|
46341
46424
|
this.pendingDownload,
|
|
46342
46425
|
this.pendingGraphql
|
|
46343
46426
|
]) {
|
|
46344
|
-
const entry = map2.get(
|
|
46427
|
+
const entry = map2.get(id2);
|
|
46345
46428
|
if (entry) {
|
|
46346
|
-
map2.delete(
|
|
46429
|
+
map2.delete(id2);
|
|
46347
46430
|
entry.reject(err);
|
|
46348
46431
|
return;
|
|
46349
46432
|
}
|
|
@@ -46352,9 +46435,9 @@ var FetchproxyServer = class {
|
|
|
46352
46435
|
noteResendable(inner) {
|
|
46353
46436
|
this.resendable.set(inner.id, inner);
|
|
46354
46437
|
if (this.resendable.size > 256) {
|
|
46355
|
-
for (const
|
|
46356
|
-
if (!this.isPendingId(
|
|
46357
|
-
this.resendable.delete(
|
|
46438
|
+
for (const id2 of [...this.resendable.keys()]) {
|
|
46439
|
+
if (!this.isPendingId(id2))
|
|
46440
|
+
this.resendable.delete(id2);
|
|
46358
46441
|
}
|
|
46359
46442
|
}
|
|
46360
46443
|
}
|
|
@@ -46369,29 +46452,29 @@ var FetchproxyServer = class {
|
|
|
46369
46452
|
*/
|
|
46370
46453
|
async recoverFromHostLoss() {
|
|
46371
46454
|
const toResend = /* @__PURE__ */ new Map();
|
|
46372
|
-
for (const [
|
|
46373
|
-
if (this.isPendingId(
|
|
46374
|
-
toResend.set(
|
|
46455
|
+
for (const [id2, inner] of this.resendable) {
|
|
46456
|
+
if (this.isPendingId(id2))
|
|
46457
|
+
toResend.set(id2, inner);
|
|
46375
46458
|
}
|
|
46376
46459
|
this.resendable.clear();
|
|
46377
46460
|
this.rejectAllPending("fetchproxy: the MCP process holding the bridge port exited while this request was in flight. It was not re-sent because it may already have run in the browser \u2014 check before retrying.", new Set(toResend.keys()));
|
|
46378
46461
|
if (toResend.size === 0)
|
|
46379
46462
|
return;
|
|
46380
|
-
const lost = (
|
|
46463
|
+
const lost = (id2, e) => this.rejectPendingId(id2, `fetchproxy: the bridge host exited and reconnecting failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
46381
46464
|
try {
|
|
46382
46465
|
await this.ensureConnected();
|
|
46383
46466
|
} catch (e) {
|
|
46384
|
-
for (const
|
|
46385
|
-
lost(
|
|
46467
|
+
for (const id2 of toResend.keys())
|
|
46468
|
+
lost(id2, e);
|
|
46386
46469
|
return;
|
|
46387
46470
|
}
|
|
46388
|
-
for (const [
|
|
46389
|
-
if (!this.isPendingId(
|
|
46471
|
+
for (const [id2, inner] of toResend) {
|
|
46472
|
+
if (!this.isPendingId(id2))
|
|
46390
46473
|
continue;
|
|
46391
46474
|
try {
|
|
46392
46475
|
await this.resendInnerFrame(inner);
|
|
46393
46476
|
} catch (e) {
|
|
46394
|
-
lost(
|
|
46477
|
+
lost(id2, e);
|
|
46395
46478
|
}
|
|
46396
46479
|
}
|
|
46397
46480
|
}
|
|
@@ -46980,7 +47063,7 @@ function describeTokenlessLogin(record2) {
|
|
|
46980
47063
|
|
|
46981
47064
|
// src/version.ts
|
|
46982
47065
|
var SERVER_NAME = "ofw-mcp";
|
|
46983
|
-
var VERSION = "2.
|
|
47066
|
+
var VERSION = "2.22.0";
|
|
46984
47067
|
|
|
46985
47068
|
// src/auth.ts
|
|
46986
47069
|
function fetchproxyDisabled() {
|
|
@@ -47677,7 +47760,7 @@ function unconfirmedWriteResponse(e, opts) {
|
|
|
47677
47760
|
remedy: `Do NOT retry blindly \u2014 a second attempt can put a duplicate on the co-parent-visible record. First check with ${opts.checkWith}${fallback}, and retry only once you have confirmed it did not land.`
|
|
47678
47761
|
});
|
|
47679
47762
|
}
|
|
47680
|
-
async function postMessageAndRefetch(client2, payload,
|
|
47763
|
+
async function postMessageAndRefetch(client2, payload, detailSchema2, ctx) {
|
|
47681
47764
|
let posted;
|
|
47682
47765
|
try {
|
|
47683
47766
|
posted = await client2.request("POST", "/pub/v3/messages", payload);
|
|
@@ -47689,20 +47772,20 @@ async function postMessageAndRefetch(client2, payload, detailSchema, ctx) {
|
|
|
47689
47772
|
posted,
|
|
47690
47773
|
{ label: "ofw-mcp", context: `POST /pub/v3/messages (${ctx})`, mode: "strict" }
|
|
47691
47774
|
);
|
|
47692
|
-
const
|
|
47693
|
-
if (
|
|
47775
|
+
const id2 = typeof raw?.id === "number" ? raw.id : typeof raw?.entityId === "number" ? raw.entityId : null;
|
|
47776
|
+
if (id2 === null) return { id: null, detail: null, raw };
|
|
47694
47777
|
let fetched;
|
|
47695
47778
|
try {
|
|
47696
|
-
fetched = await client2.request("GET", `/pub/v3/messages/${
|
|
47779
|
+
fetched = await client2.request("GET", `/pub/v3/messages/${id2}`);
|
|
47697
47780
|
} catch (e) {
|
|
47698
|
-
throw new UnconfirmedWriteError(
|
|
47781
|
+
throw new UnconfirmedWriteError(id2, e);
|
|
47699
47782
|
}
|
|
47700
47783
|
const detail = parseLenient(
|
|
47701
|
-
|
|
47784
|
+
detailSchema2,
|
|
47702
47785
|
fetched,
|
|
47703
47786
|
{ label: "ofw-mcp", context: `GET /pub/v3/messages/{id} (${ctx})`, mode: "strict" }
|
|
47704
47787
|
);
|
|
47705
|
-
return { id, detail, raw };
|
|
47788
|
+
return { id: id2, detail, raw };
|
|
47706
47789
|
}
|
|
47707
47790
|
|
|
47708
47791
|
// src/tools/user.ts
|
|
@@ -47774,6 +47857,91 @@ function registerHealthcheckTools(server, client2) {
|
|
|
47774
47857
|
});
|
|
47775
47858
|
}
|
|
47776
47859
|
|
|
47860
|
+
// src/read-days.ts
|
|
47861
|
+
var WEEKDAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
47862
|
+
var WEEKDAY_LABELS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
47863
|
+
var DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
47864
|
+
function isRealDate(s) {
|
|
47865
|
+
if (!DATE_RE.test(s)) return false;
|
|
47866
|
+
const [y, m, d] = s.split("-").map(Number);
|
|
47867
|
+
const dt = new Date(Date.UTC(y, m - 1, d));
|
|
47868
|
+
return dt.getUTCFullYear() === y && dt.getUTCMonth() === m - 1 && dt.getUTCDate() === d;
|
|
47869
|
+
}
|
|
47870
|
+
function parseList(raw) {
|
|
47871
|
+
const set2 = { weekdays: /* @__PURE__ */ new Set(), ranges: [] };
|
|
47872
|
+
const invalid = [];
|
|
47873
|
+
for (const token of raw.split(/[\s,;]+/).filter((t) => t.length > 0)) {
|
|
47874
|
+
const lower = token.toLowerCase();
|
|
47875
|
+
const weekday = WEEKDAYS.findIndex((w) => w === lower || lower.length >= 3 && w.startsWith(lower));
|
|
47876
|
+
if (weekday !== -1) {
|
|
47877
|
+
set2.weekdays.add(weekday);
|
|
47878
|
+
continue;
|
|
47879
|
+
}
|
|
47880
|
+
const [from, to, ...rest] = token.split("..");
|
|
47881
|
+
const end = to ?? from;
|
|
47882
|
+
if (rest.length === 0 && isRealDate(from) && isRealDate(end) && from <= end) {
|
|
47883
|
+
set2.ranges.push([from, end]);
|
|
47884
|
+
continue;
|
|
47885
|
+
}
|
|
47886
|
+
invalid.push(token);
|
|
47887
|
+
}
|
|
47888
|
+
return { set: set2, invalid };
|
|
47889
|
+
}
|
|
47890
|
+
function contains(set2, date5, weekday) {
|
|
47891
|
+
return set2.weekdays.has(weekday) || set2.ranges.some(([from, to]) => date5 >= from && date5 <= to);
|
|
47892
|
+
}
|
|
47893
|
+
function getReadDayPolicy() {
|
|
47894
|
+
const allowRaw = readEnvVar("OFW_READ_DAYS");
|
|
47895
|
+
const denyRaw = readEnvVar("OFW_NO_READ_DAYS");
|
|
47896
|
+
if (allowRaw === void 0 && denyRaw === void 0) return null;
|
|
47897
|
+
const allow = allowRaw === void 0 ? null : parseList(allowRaw);
|
|
47898
|
+
const deny = denyRaw === void 0 ? null : parseList(denyRaw);
|
|
47899
|
+
const invalid = [...allow?.invalid ?? [], ...deny?.invalid ?? []];
|
|
47900
|
+
if (invalid.length > 0) {
|
|
47901
|
+
console.error(
|
|
47902
|
+
`[ofw-mcp] Unrecognized OFW_READ_DAYS / OFW_NO_READ_DAYS token(s) ${invalid.map((t) => JSON.stringify(t)).join(", ")} \u2014 failing closed: message content is withheld on EVERY day until this is fixed. Valid tokens: weekday names (mon, monday, \u2026), YYYY-MM-DD, or YYYY-MM-DD..YYYY-MM-DD.`
|
|
47903
|
+
);
|
|
47904
|
+
}
|
|
47905
|
+
return { allow: allow?.set ?? null, deny: deny?.set ?? null, invalid };
|
|
47906
|
+
}
|
|
47907
|
+
function isReadable(policy, date5, weekday) {
|
|
47908
|
+
if (policy.invalid.length > 0) return false;
|
|
47909
|
+
if (policy.allow !== null && !contains(policy.allow, date5, weekday)) return false;
|
|
47910
|
+
return !(policy.deny !== null && contains(policy.deny, date5, weekday));
|
|
47911
|
+
}
|
|
47912
|
+
function localDate(instant, tz) {
|
|
47913
|
+
return new Intl.DateTimeFormat("en-CA", { timeZone: tz, year: "numeric", month: "2-digit", day: "2-digit" }).format(instant);
|
|
47914
|
+
}
|
|
47915
|
+
function addDays(date5, n) {
|
|
47916
|
+
const [y, m, d] = date5.split("-").map(Number);
|
|
47917
|
+
const dt = new Date(Date.UTC(y, m - 1, d + n));
|
|
47918
|
+
return { date: dt.toISOString().slice(0, 10), weekday: dt.getUTCDay() };
|
|
47919
|
+
}
|
|
47920
|
+
function readingBlockedToday(now = /* @__PURE__ */ new Date()) {
|
|
47921
|
+
const policy = getReadDayPolicy();
|
|
47922
|
+
if (policy === null) return null;
|
|
47923
|
+
const timeZone = displayTimeZone();
|
|
47924
|
+
const today = addDays(localDate(now, timeZone), 0);
|
|
47925
|
+
if (isReadable(policy, today.date, today.weekday)) return null;
|
|
47926
|
+
let nextReadableDay = null;
|
|
47927
|
+
for (let i = 1; i <= 366; i++) {
|
|
47928
|
+
const day = addDays(today.date, i);
|
|
47929
|
+
if (isReadable(policy, day.date, day.weekday)) {
|
|
47930
|
+
nextReadableDay = `${WEEKDAY_LABELS[day.weekday]} ${day.date}`;
|
|
47931
|
+
break;
|
|
47932
|
+
}
|
|
47933
|
+
}
|
|
47934
|
+
const reason = policy.invalid.length > 0 ? `OFW_READ_DAYS / OFW_NO_READ_DAYS contains unrecognized value(s) ${policy.invalid.map((t) => JSON.stringify(t)).join(", ")}, so reading is blocked on every day until the setting is fixed.` : `Today (${WEEKDAY_LABELS[today.weekday]} ${today.date}, ${timeZone}) is not a message-reading day under this server's OFW_READ_DAYS / OFW_NO_READ_DAYS setting.`;
|
|
47935
|
+
return {
|
|
47936
|
+
error: "READING_BLOCKED",
|
|
47937
|
+
today: today.date,
|
|
47938
|
+
weekday: WEEKDAY_LABELS[today.weekday],
|
|
47939
|
+
timeZone,
|
|
47940
|
+
reason: `${reason} You may see that messages arrived, who sent them, when, and their subjects \u2014 but message bodies and attachments are withheld, and nothing may be marked read on OurFamilyWizard. This is a deployment setting; no per-call argument can override it.`,
|
|
47941
|
+
nextReadableDay
|
|
47942
|
+
};
|
|
47943
|
+
}
|
|
47944
|
+
|
|
47777
47945
|
// src/sync.ts
|
|
47778
47946
|
var FileMetaSchema = external_exports.looseObject({
|
|
47779
47947
|
fileId: external_exports.number(),
|
|
@@ -47895,8 +48063,33 @@ async function walkPages(client2, folder, folderId, opts, store) {
|
|
|
47895
48063
|
for (const item of items) {
|
|
47896
48064
|
if (newestId === null || item.id > newestId) newestId = item.id;
|
|
47897
48065
|
const existing = existingById.get(item.id);
|
|
48066
|
+
const isInboxUnread = folder === "inbox" && item.showNeverViewed === true;
|
|
47898
48067
|
if (existing) {
|
|
47899
|
-
if (
|
|
48068
|
+
if (opts.fetchBodies && existing.body === null && !isInboxUnread) {
|
|
48069
|
+
if (!budget.take()) {
|
|
48070
|
+
pageBudgetHit = true;
|
|
48071
|
+
break;
|
|
48072
|
+
}
|
|
48073
|
+
const detail = parseLenient(
|
|
48074
|
+
DetailResponseSchema,
|
|
48075
|
+
await client2.request("GET", `/pub/v3/messages/${item.id}`),
|
|
48076
|
+
{ label: "ofw-mcp", context: "GET /pub/v3/messages/{id} (body backfill)" }
|
|
48077
|
+
);
|
|
48078
|
+
toUpsert.push({
|
|
48079
|
+
...existing,
|
|
48080
|
+
body: detail.body ?? "",
|
|
48081
|
+
fetchedBodyAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
48082
|
+
recipients: mapRecipients(detail.recipients ?? item.recipients),
|
|
48083
|
+
listData: item
|
|
48084
|
+
});
|
|
48085
|
+
synced++;
|
|
48086
|
+
pageHadNewItem = true;
|
|
48087
|
+
if (Array.isArray(detail.files) && detail.files.length > 0) {
|
|
48088
|
+
await fetchAttachmentMetaBudgeted(client2, item.id, detail.files, store, budget);
|
|
48089
|
+
}
|
|
48090
|
+
continue;
|
|
48091
|
+
}
|
|
48092
|
+
if (opts.fetchBodies && folder === "sent" && item.showNeverViewed === false && !hasRealView(existing.recipients)) {
|
|
47900
48093
|
if (!budget.take()) {
|
|
47901
48094
|
pageBudgetHit = true;
|
|
47902
48095
|
break;
|
|
@@ -47912,8 +48105,7 @@ async function walkPages(client2, folder, folderId, opts, store) {
|
|
|
47912
48105
|
continue;
|
|
47913
48106
|
}
|
|
47914
48107
|
pageHadNewItem = true;
|
|
47915
|
-
const
|
|
47916
|
-
const shouldFetchBody = !isInboxUnread || opts.fetchUnreadBodies;
|
|
48108
|
+
const shouldFetchBody = opts.fetchBodies && (!isInboxUnread || opts.fetchUnreadBodies);
|
|
47917
48109
|
let body = null;
|
|
47918
48110
|
let fetchedBodyAt = null;
|
|
47919
48111
|
let detailFileIds = [];
|
|
@@ -47934,7 +48126,7 @@ async function walkPages(client2, folder, folderId, opts, store) {
|
|
|
47934
48126
|
if (Array.isArray(detail.files) && detail.files.length > 0) {
|
|
47935
48127
|
detailFileIds = detail.files;
|
|
47936
48128
|
}
|
|
47937
|
-
} else {
|
|
48129
|
+
} else if (isInboxUnread) {
|
|
47938
48130
|
unread.push({
|
|
47939
48131
|
id: item.id,
|
|
47940
48132
|
subject: item.subject,
|
|
@@ -47972,6 +48164,7 @@ async function walkPages(client2, folder, folderId, opts, store) {
|
|
|
47972
48164
|
}
|
|
47973
48165
|
}
|
|
47974
48166
|
async function syncMessageFolder(client2, folder, folderId, opts, store) {
|
|
48167
|
+
const fetchBodies = opts.fetchBodies ?? true;
|
|
47975
48168
|
const budget = opts.budget ?? makeBudget(Number.POSITIVE_INFINITY);
|
|
47976
48169
|
const saved = await store.getSyncState(folder);
|
|
47977
48170
|
const savedResume = saved?.resumePage ?? null;
|
|
@@ -47979,6 +48172,7 @@ async function syncMessageFolder(client2, folder, folderId, opts, store) {
|
|
|
47979
48172
|
startPage: 1,
|
|
47980
48173
|
stopAtCachedPage: true,
|
|
47981
48174
|
fetchUnreadBodies: opts.fetchUnreadBodies,
|
|
48175
|
+
fetchBodies,
|
|
47982
48176
|
budget
|
|
47983
48177
|
}, store);
|
|
47984
48178
|
let synced = fwd.synced;
|
|
@@ -48004,6 +48198,7 @@ async function syncMessageFolder(client2, folder, folderId, opts, store) {
|
|
|
48004
48198
|
startPage: savedResume ?? fwd.nextPage,
|
|
48005
48199
|
stopAtCachedPage: false,
|
|
48006
48200
|
fetchUnreadBodies: opts.fetchUnreadBodies,
|
|
48201
|
+
fetchBodies,
|
|
48007
48202
|
budget
|
|
48008
48203
|
}, store);
|
|
48009
48204
|
synced += bf.synced;
|
|
@@ -48108,8 +48303,8 @@ async function syncDrafts(client2, draftsFolderId, store, budget) {
|
|
|
48108
48303
|
}
|
|
48109
48304
|
}
|
|
48110
48305
|
const seenIds = new Set(ids);
|
|
48111
|
-
for (const
|
|
48112
|
-
if (!seenIds.has(
|
|
48306
|
+
for (const id2 of await store.listDraftIds()) {
|
|
48307
|
+
if (!seenIds.has(id2)) await store.deleteDraft(id2);
|
|
48113
48308
|
}
|
|
48114
48309
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
48115
48310
|
await setDraftsCacheStatus(store, "fresh");
|
|
@@ -48124,6 +48319,7 @@ async function syncAll(client2, opts, store) {
|
|
|
48124
48319
|
...requested.filter((f) => f !== "drafts")
|
|
48125
48320
|
];
|
|
48126
48321
|
const budget = makeBudget(opts.maxRequests ?? Number.POSITIVE_INFINITY);
|
|
48322
|
+
const readingBlocked = readingBlockedToday() !== null;
|
|
48127
48323
|
budget.take();
|
|
48128
48324
|
const ids = await resolveFolderIds(client2, store);
|
|
48129
48325
|
const synced = {};
|
|
@@ -48143,7 +48339,8 @@ async function syncAll(client2, opts, store) {
|
|
|
48143
48339
|
for (const folder of folders) {
|
|
48144
48340
|
if (folder === "inbox") {
|
|
48145
48341
|
const r = await syncMessageFolder(client2, "inbox", ids.inbox, {
|
|
48146
|
-
fetchUnreadBodies: opts.fetchUnreadBodies ?? false,
|
|
48342
|
+
fetchUnreadBodies: !readingBlocked && (opts.fetchUnreadBodies ?? false),
|
|
48343
|
+
fetchBodies: !readingBlocked,
|
|
48147
48344
|
deep: opts.deep ?? false,
|
|
48148
48345
|
budget
|
|
48149
48346
|
}, store);
|
|
@@ -48153,6 +48350,7 @@ async function syncAll(client2, opts, store) {
|
|
|
48153
48350
|
} else if (folder === "sent") {
|
|
48154
48351
|
const r = await syncMessageFolder(client2, "sent", ids.sent, {
|
|
48155
48352
|
fetchUnreadBodies: false,
|
|
48353
|
+
fetchBodies: !readingBlocked,
|
|
48156
48354
|
deep: opts.deep ?? false,
|
|
48157
48355
|
budget
|
|
48158
48356
|
}, store);
|
|
@@ -48168,6 +48366,9 @@ async function syncAll(client2, opts, store) {
|
|
|
48168
48366
|
}
|
|
48169
48367
|
}
|
|
48170
48368
|
const notes = [];
|
|
48369
|
+
if (readingBlocked) {
|
|
48370
|
+
notes.push("Today is a no-read day (OFW_READ_DAYS / OFW_NO_READ_DAYS): new inbox and sent messages were cached from the list only \u2014 sender, date and subject \u2014 and no message body was downloaded. The first sync on a reading day fills in bodies that can be fetched without marking anything read.");
|
|
48371
|
+
}
|
|
48171
48372
|
if (draftsUnverified) {
|
|
48172
48373
|
notes.push('The drafts folder was NOT checked against OurFamilyWizard on this call (the request budget ran out first), so no drafts count is reported and the cached drafts are marked "unverified". Cached draft bodies may be behind the server. Call ofw_sync_messages again \u2014 or ofw_sync_messages with folders:["drafts"] \u2014 before editing or deleting a draft.');
|
|
48173
48374
|
}
|
|
@@ -48188,6 +48389,7 @@ async function syncAll(client2, opts, store) {
|
|
|
48188
48389
|
syncComplete: done,
|
|
48189
48390
|
refreshed,
|
|
48190
48391
|
notRefreshed,
|
|
48392
|
+
...readingBlocked ? { bodiesWithheld: true } : {},
|
|
48191
48393
|
...note ? { note } : {}
|
|
48192
48394
|
};
|
|
48193
48395
|
}
|
|
@@ -48447,14 +48649,14 @@ var ServerDraftSchema = external_exports.looseObject({
|
|
|
48447
48649
|
function isNotFound(e) {
|
|
48448
48650
|
return e instanceof Error && /OFW API error: 404\b/.test(e.message);
|
|
48449
48651
|
}
|
|
48450
|
-
async function fetchMessageSnapshot(client2,
|
|
48652
|
+
async function fetchMessageSnapshot(client2, id2) {
|
|
48451
48653
|
let raw;
|
|
48452
48654
|
try {
|
|
48453
|
-
raw = await client2.request("GET", `/pub/v3/messages/${
|
|
48655
|
+
raw = await client2.request("GET", `/pub/v3/messages/${id2}`);
|
|
48454
48656
|
} catch (e) {
|
|
48455
48657
|
if (isNotFound(e)) return null;
|
|
48456
48658
|
throw new DraftFreshnessError(
|
|
48457
|
-
`could not read the current state of draft ${
|
|
48659
|
+
`could not read the current state of draft ${id2} from OurFamilyWizard: ${e.message}`
|
|
48458
48660
|
);
|
|
48459
48661
|
}
|
|
48460
48662
|
if (raw === null || raw === void 0) return null;
|
|
@@ -48476,8 +48678,8 @@ async function fetchMessageSnapshot(client2, id) {
|
|
|
48476
48678
|
dateTime: detail.date?.dateTime ?? null
|
|
48477
48679
|
};
|
|
48478
48680
|
}
|
|
48479
|
-
async function fetchServerDraft(client2,
|
|
48480
|
-
return (await fetchMessageSnapshot(client2,
|
|
48681
|
+
async function fetchServerDraft(client2, id2) {
|
|
48682
|
+
return (await fetchMessageSnapshot(client2, id2))?.content ?? null;
|
|
48481
48683
|
}
|
|
48482
48684
|
var SUBSTANTIVE_FIELDS = ["subject", "body", "recipients"];
|
|
48483
48685
|
function substantiveChanges(changed) {
|
|
@@ -48644,11 +48846,11 @@ function stateNote(state, cachedAsDraft, folderName) {
|
|
|
48644
48846
|
async function probeIds(client2, store, ids, opts) {
|
|
48645
48847
|
const draftsById = new Map((await store.getDrafts(ids)).map((d) => [d.id, d]));
|
|
48646
48848
|
const messagesById = new Map((await store.getMessages(ids)).map((m) => [m.id, m]));
|
|
48647
|
-
const prepared = ids.map((
|
|
48648
|
-
const cachedDraft = draftsById.get(
|
|
48649
|
-
const cachedMessage = cachedDraft === null ? messagesById.get(
|
|
48849
|
+
const prepared = ids.map((id2) => {
|
|
48850
|
+
const cachedDraft = draftsById.get(id2) ?? null;
|
|
48851
|
+
const cachedMessage = cachedDraft === null ? messagesById.get(id2) ?? null : null;
|
|
48650
48852
|
return {
|
|
48651
|
-
id,
|
|
48853
|
+
id: id2,
|
|
48652
48854
|
cachedDraft,
|
|
48653
48855
|
cachedMessage,
|
|
48654
48856
|
skip: !opts.allowMarkRead && probeWouldStamp(cachedDraft, cachedMessage)
|
|
@@ -48677,15 +48879,15 @@ async function probeIds(client2, store, ids, opts) {
|
|
|
48677
48879
|
return { items, requests };
|
|
48678
48880
|
}
|
|
48679
48881
|
async function probeOne(client2, prepared, map2, draftKey) {
|
|
48680
|
-
const { id, cachedDraft } = prepared;
|
|
48882
|
+
const { id: id2, cachedDraft } = prepared;
|
|
48681
48883
|
let snapshot;
|
|
48682
48884
|
try {
|
|
48683
|
-
snapshot = await fetchMessageSnapshot(client2,
|
|
48885
|
+
snapshot = await fetchMessageSnapshot(client2, id2);
|
|
48684
48886
|
} catch (e) {
|
|
48685
48887
|
return {
|
|
48686
48888
|
requests: 1,
|
|
48687
48889
|
item: {
|
|
48688
|
-
id,
|
|
48890
|
+
id: id2,
|
|
48689
48891
|
error: "FRESHNESS_CHECK_FAILED",
|
|
48690
48892
|
message: e.message,
|
|
48691
48893
|
inSync: null,
|
|
@@ -48715,7 +48917,7 @@ async function probeOne(client2, prepared, map2, draftKey) {
|
|
|
48715
48917
|
return {
|
|
48716
48918
|
requests: 1,
|
|
48717
48919
|
item: {
|
|
48718
|
-
id,
|
|
48920
|
+
id: id2,
|
|
48719
48921
|
state,
|
|
48720
48922
|
folder: snapshot?.folderName ?? null,
|
|
48721
48923
|
sentAt: state === "sent" ? snapshot?.dateTime ?? null : null,
|
|
@@ -48741,6 +48943,13 @@ function newDraftKey() {
|
|
|
48741
48943
|
// src/tools/_confirm.ts
|
|
48742
48944
|
var CONFIRM_NOTE = "Asks the user to confirm first: a confirmation prompt where the client supports one; otherwise the first call performs NO write and returns a preview of exactly what would happen plus a confirmToken, and only a repeat call with that token proceeds (see MCP_CONFIRM_MODE).";
|
|
48743
48945
|
function confirmWrite2(ctx, opts) {
|
|
48946
|
+
const { confirmToken: _confirmToken, ...args } = opts.args;
|
|
48947
|
+
const subject = {
|
|
48948
|
+
target: opts.target,
|
|
48949
|
+
...opts.revision !== void 0 ? { revision: opts.revision } : {},
|
|
48950
|
+
payload: opts.payload,
|
|
48951
|
+
preview: opts.preview
|
|
48952
|
+
};
|
|
48744
48953
|
return requireConfirmationWithFallback(
|
|
48745
48954
|
ctx,
|
|
48746
48955
|
confirmationFromEnv({
|
|
@@ -48752,14 +48961,9 @@ function confirmWrite2(ctx, opts) {
|
|
|
48752
48961
|
// One OFW account per process (OFW_USERNAME / the captured session), so
|
|
48753
48962
|
// there is no principal to distinguish; mcp-utils 3 makes saying so explicit.
|
|
48754
48963
|
account: void 0,
|
|
48755
|
-
args: opts.args,
|
|
48964
|
+
args: { tool: opts.tool, action: opts.action, args, ...subject },
|
|
48756
48965
|
confirmToken: opts.confirmToken,
|
|
48757
|
-
subject: () =>
|
|
48758
|
-
target: opts.target,
|
|
48759
|
-
...opts.revision !== void 0 ? { revision: opts.revision } : {},
|
|
48760
|
-
payload: opts.payload,
|
|
48761
|
-
preview: opts.preview
|
|
48762
|
-
})
|
|
48966
|
+
subject: () => subject
|
|
48763
48967
|
})
|
|
48764
48968
|
);
|
|
48765
48969
|
}
|
|
@@ -48950,10 +49154,10 @@ async function readRels(zip, partPath) {
|
|
|
48950
49154
|
if (!xml) return [];
|
|
48951
49155
|
const rels = [];
|
|
48952
49156
|
for (const el of elements(xml, "Relationship")) {
|
|
48953
|
-
const
|
|
49157
|
+
const id2 = attr(el.attrs, "Id");
|
|
48954
49158
|
const target = attr(el.attrs, "Target");
|
|
48955
|
-
if (!
|
|
48956
|
-
rels.push({ id, target: resolvePartPath(dir, target), type: attr(el.attrs, "Type") ?? "" });
|
|
49159
|
+
if (!id2 || !target) continue;
|
|
49160
|
+
rels.push({ id: id2, target: resolvePartPath(dir, target), type: attr(el.attrs, "Type") ?? "" });
|
|
48957
49161
|
}
|
|
48958
49162
|
return rels;
|
|
48959
49163
|
}
|
|
@@ -49001,15 +49205,15 @@ async function readStyles(zip, dir) {
|
|
|
49001
49205
|
if (!xml) return { dateStyles: [] };
|
|
49002
49206
|
const custom2 = /* @__PURE__ */ new Map();
|
|
49003
49207
|
for (const el of elements(xml, "numFmt")) {
|
|
49004
|
-
const
|
|
49208
|
+
const id2 = Number(attr(el.attrs, "numFmtId"));
|
|
49005
49209
|
const code2 = attr(el.attrs, "formatCode");
|
|
49006
|
-
if (Number.isFinite(
|
|
49210
|
+
if (Number.isFinite(id2) && code2 !== null) custom2.set(id2, code2);
|
|
49007
49211
|
}
|
|
49008
49212
|
const dateStyles = [];
|
|
49009
49213
|
for (const block of elements(xml, "cellXfs")) {
|
|
49010
49214
|
for (const xf of elements(block.inner, "xf")) {
|
|
49011
|
-
const
|
|
49012
|
-
dateStyles.push(isDateFormat(
|
|
49215
|
+
const id2 = Number(attr(xf.attrs, "numFmtId") ?? "0");
|
|
49216
|
+
dateStyles.push(isDateFormat(id2, custom2.get(id2)));
|
|
49013
49217
|
}
|
|
49014
49218
|
}
|
|
49015
49219
|
return { dateStyles };
|
|
@@ -50125,6 +50329,17 @@ function unverifiedEmptyResponse(input2) {
|
|
|
50125
50329
|
...input2.extra
|
|
50126
50330
|
});
|
|
50127
50331
|
}
|
|
50332
|
+
function markReadPermitted() {
|
|
50333
|
+
return getAllowMarkRead() && readingBlockedToday() === null;
|
|
50334
|
+
}
|
|
50335
|
+
function withholdBody(row) {
|
|
50336
|
+
let listData = row.listData;
|
|
50337
|
+
if (listData !== null && typeof listData === "object" && !Array.isArray(listData)) {
|
|
50338
|
+
const { preview: _preview, body: _body, ...rest } = listData;
|
|
50339
|
+
listData = rest;
|
|
50340
|
+
}
|
|
50341
|
+
return { ...row, body: null, listData, bodyWithheld: true };
|
|
50342
|
+
}
|
|
50128
50343
|
function markReadVerdict(cached2, requested) {
|
|
50129
50344
|
const ceiling = getAllowMarkRead();
|
|
50130
50345
|
if (ceiling && (requested ?? true)) return null;
|
|
@@ -50147,7 +50362,7 @@ async function describeRecipients(cache, recipientIds, known) {
|
|
|
50147
50362
|
}
|
|
50148
50363
|
};
|
|
50149
50364
|
known.forEach(learn);
|
|
50150
|
-
if (recipientIds.some((
|
|
50365
|
+
if (recipientIds.some((id2) => !names.has(id2))) {
|
|
50151
50366
|
for (const row of await cache.listMessages({ page: 1, size: 200 })) learn(row.recipients);
|
|
50152
50367
|
}
|
|
50153
50368
|
return recipientIds.map((userId) => ({ userId, name: names.get(userId) ?? null }));
|
|
@@ -50219,7 +50434,8 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
50219
50434
|
}
|
|
50220
50435
|
const cache = cacheProvider();
|
|
50221
50436
|
const folders = folder === void 0 ? ["inbox", "sent"] : [folder];
|
|
50222
|
-
const
|
|
50437
|
+
const blocked = readingBlockedToday();
|
|
50438
|
+
const filter = { folder, since: bounds.since, until: bounds.until, q: args.q, qSubjectOnly: blocked !== null };
|
|
50223
50439
|
const { value, refreshed, unverifiedEmpty } = await guardedCacheRead({
|
|
50224
50440
|
client: client2,
|
|
50225
50441
|
cache,
|
|
@@ -50273,12 +50489,15 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
50273
50489
|
if (refreshed) {
|
|
50274
50490
|
payload.autoRefreshed = true;
|
|
50275
50491
|
}
|
|
50492
|
+
if (blocked !== null) {
|
|
50493
|
+
payload.readingBlocked = blocked;
|
|
50494
|
+
}
|
|
50276
50495
|
payload.freshness = freshness;
|
|
50277
|
-
payload.messages = viewMessages(view, messages);
|
|
50496
|
+
payload.messages = viewMessages(view, blocked === null ? messages : messages.map(withholdBody));
|
|
50278
50497
|
return jsonResponse(payload);
|
|
50279
50498
|
});
|
|
50280
50499
|
server.registerTool("ofw_get_message", {
|
|
50281
|
-
description: 'Get a single OurFamilyWizard message OR draft by ID. Reads from local cache when available; otherwise fetches from OFW \u2014 and for an UNREAD INBOX message that fetch marks it read and stamps a "First Viewed" time the co-parent can see, which is part of the record and cannot be undone. Pass allowMarkRead:false to refuse such a fetch instead (cached bodies, sent messages and already-read messages are unaffected, because none of them stamp anything). For ids that match a draft (in the drafts cache), the response carries folder="drafts" and the body/subject/recipients reflect the drafts cache (which ofw_sync_messages keeps fresh) \u2014 drafts have no `fromUser`, and `sentAt`/`fetchedBodyAt` mirror the draft\'s `modifiedAt`. For inbox/sent messages, folder is "inbox" or "sent" as before.',
|
|
50500
|
+
description: 'Get a single OurFamilyWizard message OR draft by ID. Reads from local cache when available; otherwise fetches from OFW \u2014 and for an UNREAD INBOX message that fetch marks it read and stamps a "First Viewed" time the co-parent can see, which is part of the record and cannot be undone. Pass allowMarkRead:false to refuse such a fetch instead (cached bodies, sent messages and already-read messages are unaffected, because none of them stamp anything). For ids that match a draft (in the drafts cache), the response carries folder="drafts" and the body/subject/recipients reflect the drafts cache (which ofw_sync_messages keeps fresh) \u2014 drafts have no `fromUser`, and `sentAt`/`fetchedBodyAt` mirror the draft\'s `modifiedAt`. For inbox/sent messages, folder is "inbox" or "sent" as before. On a server-configured no-read day (OFW_READ_DAYS / OFW_NO_READ_DAYS) inbox/sent bodies are withheld (body:null, bodyWithheld:true, readingBlocked says when reading resumes) and OFW is never contacted.',
|
|
50282
50501
|
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
50283
50502
|
inputSchema: external_exports.object({
|
|
50284
50503
|
messageId: external_exports.string().describe("Message ID (also accepts draft IDs \u2014 drafts are routed via the drafts cache)"),
|
|
@@ -50288,10 +50507,10 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
50288
50507
|
})
|
|
50289
50508
|
})
|
|
50290
50509
|
}, async (args) => {
|
|
50291
|
-
const
|
|
50510
|
+
const id2 = Number(args.messageId);
|
|
50292
50511
|
const view = resolveView(args.view, MESSAGE_VIEWS);
|
|
50293
50512
|
const cache = cacheProvider();
|
|
50294
|
-
const draftRow = await cache.getDraft(
|
|
50513
|
+
const draftRow = await cache.getDraft(id2);
|
|
50295
50514
|
if (draftRow !== null) {
|
|
50296
50515
|
const { freshness: freshness2, serverConfirmed, cacheStatus } = await draftsFreshness(cache);
|
|
50297
50516
|
return jsonResponse({
|
|
@@ -50336,14 +50555,32 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
50336
50555
|
freshness: freshness2
|
|
50337
50556
|
});
|
|
50338
50557
|
}
|
|
50339
|
-
const cached2 = await cache.getMessage(
|
|
50558
|
+
const cached2 = await cache.getMessage(id2);
|
|
50559
|
+
const blocked = readingBlockedToday();
|
|
50560
|
+
if (blocked !== null) {
|
|
50561
|
+
if (cached2 === null) {
|
|
50562
|
+
return jsonErrorResponse({
|
|
50563
|
+
...blocked,
|
|
50564
|
+
messageId: id2,
|
|
50565
|
+
hint: "This id is not in the cache. Run ofw_sync_messages (it walks list pages, not bodies, and marks nothing read) to see its subject, sender and date."
|
|
50566
|
+
});
|
|
50567
|
+
}
|
|
50568
|
+
const attachments2 = await cache.listAttachmentsForMessage(id2);
|
|
50569
|
+
const freshness2 = await buildFreshness(cache, { source: "cache", folders: [cached2.folder] });
|
|
50570
|
+
return jsonResponse({
|
|
50571
|
+
readingBlocked: blocked,
|
|
50572
|
+
...viewOne(view, withholdBody(withReadState(cached2))),
|
|
50573
|
+
attachments: attachments2,
|
|
50574
|
+
freshness: freshness2
|
|
50575
|
+
});
|
|
50576
|
+
}
|
|
50340
50577
|
if (cached2 && cached2.body !== null) {
|
|
50341
50578
|
let row2 = cached2;
|
|
50342
50579
|
if (cached2.folder === "sent" && !hasRealView(cached2.recipients)) {
|
|
50343
50580
|
try {
|
|
50344
50581
|
const detail2 = parseLenient(
|
|
50345
50582
|
MessageDetailSchema,
|
|
50346
|
-
await client2.request("GET", `/pub/v3/messages/${
|
|
50583
|
+
await client2.request("GET", `/pub/v3/messages/${id2}`),
|
|
50347
50584
|
{ label: "ofw-mcp", context: "GET /pub/v3/messages/{id} (view-status refresh)" }
|
|
50348
50585
|
);
|
|
50349
50586
|
const recipients = mapRecipients(detail2.recipients);
|
|
@@ -50356,17 +50593,17 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
50356
50593
|
} catch {
|
|
50357
50594
|
}
|
|
50358
50595
|
}
|
|
50359
|
-
let attachments2 = await cache.listAttachmentsForMessage(
|
|
50596
|
+
let attachments2 = await cache.listAttachmentsForMessage(id2);
|
|
50360
50597
|
if (attachments2.length === 0 && listDataHintsAtFiles(row2.listData)) {
|
|
50361
50598
|
try {
|
|
50362
50599
|
const detail2 = parseLenient(
|
|
50363
50600
|
DetailFilesSchema,
|
|
50364
|
-
await client2.request("GET", `/pub/v3/messages/${
|
|
50601
|
+
await client2.request("GET", `/pub/v3/messages/${id2}`),
|
|
50365
50602
|
{ label: "ofw-mcp", context: "GET /pub/v3/messages/{id} (attachment backfill)" }
|
|
50366
50603
|
);
|
|
50367
50604
|
if (Array.isArray(detail2.files) && detail2.files.length > 0) {
|
|
50368
|
-
await fetchAttachmentMetaForMessage(client2,
|
|
50369
|
-
attachments2 = await cache.listAttachmentsForMessage(
|
|
50605
|
+
await fetchAttachmentMetaForMessage(client2, id2, detail2.files, cache);
|
|
50606
|
+
attachments2 = await cache.listAttachmentsForMessage(id2);
|
|
50370
50607
|
}
|
|
50371
50608
|
} catch {
|
|
50372
50609
|
}
|
|
@@ -50465,7 +50702,7 @@ function registerMessageTools(server, client2, cacheProvider, attachmentIO) {
|
|
|
50465
50702
|
(s) => s !== null && s !== void 0 && s.recipients.some((r) => r.userId !== 0)
|
|
50466
50703
|
);
|
|
50467
50704
|
if (source != null) {
|
|
50468
|
-
recipientIds = [...new Set(source.recipients.map((r) => r.userId).filter((
|
|
50705
|
+
recipientIds = [...new Set(source.recipients.map((r) => r.userId).filter((id2) => id2 !== 0))];
|
|
50469
50706
|
}
|
|
50470
50707
|
}
|
|
50471
50708
|
}
|
|
@@ -50943,7 +51180,7 @@ ${jsonText(
|
|
|
50943
51180
|
}
|
|
50944
51181
|
if (myFileIDs.length > 0 && Array.isArray(detail.files)) {
|
|
50945
51182
|
const storedFiles = new Set(detail.files);
|
|
50946
|
-
const missing = myFileIDs.filter((
|
|
51183
|
+
const missing = myFileIDs.filter((id2) => !storedFiles.has(id2));
|
|
50947
51184
|
if (missing.length > 0) {
|
|
50948
51185
|
warnings.push(
|
|
50949
51186
|
`Attachment fileId(s) ${missing.join(", ")} were requested in myFileIDs but are not attached to the saved draft. Re-upload or re-attach if needed.`
|
|
@@ -51171,6 +51408,22 @@ ${jsonText(
|
|
|
51171
51408
|
const forcedInline = inline && !requestedInline;
|
|
51172
51409
|
const deliveryOptions = { extract: args.extract, maxChars: args.maxChars, parts: args.parts };
|
|
51173
51410
|
let cached2 = await cache.getAttachment(fileId);
|
|
51411
|
+
const blocked = readingBlockedToday();
|
|
51412
|
+
if (blocked !== null) {
|
|
51413
|
+
const linked = (cached2?.messageIds ?? []).filter((mid) => mid !== 0);
|
|
51414
|
+
let draftOnly = linked.length > 0;
|
|
51415
|
+
for (const mid of linked) {
|
|
51416
|
+
if (await cache.getDraft(mid) === null) draftOnly = false;
|
|
51417
|
+
}
|
|
51418
|
+
if (!draftOnly) {
|
|
51419
|
+
return jsonErrorResponse({
|
|
51420
|
+
...blocked,
|
|
51421
|
+
fileId,
|
|
51422
|
+
...cached2 ? { fileName: cached2.fileName } : {},
|
|
51423
|
+
hint: "Attachments on received or sent messages (or files this cache cannot place) are withheld on a no-read day. Download it on the next reading day."
|
|
51424
|
+
});
|
|
51425
|
+
}
|
|
51426
|
+
}
|
|
51174
51427
|
if (!cached2) {
|
|
51175
51428
|
await fetchAttachmentMeta(client2, fileId, 0, cache);
|
|
51176
51429
|
cached2 = await cache.getAttachment(fileId);
|
|
@@ -51246,7 +51499,7 @@ ${jsonText(
|
|
|
51246
51499
|
server.registerTool("ofw_sync_messages", {
|
|
51247
51500
|
// Destructive: fetchUnreadBodies:true stamps a co-parent-visible "First
|
|
51248
51501
|
// Viewed" time on every unread inbox message it touches — irreversible.
|
|
51249
|
-
description: "Sync messages from OurFamilyWizard into the local cache. Returns counts per folder and a list of unread inbox messages whose bodies were NOT fetched (to avoid mark-as-read on OFW). Call ofw_get_message(id) on those to read them. EVERY call re-checks the newest page first, so new messages are picked up promptly even while an old-history backfill is still running; only then does it spend what is left of its budget advancing that backfill. Pass deep:true to walk all OFW pages instead of stopping at the first all-cached page (use to backfill suspected gaps). Sync is BOUNDED and RESUMABLE: on hosted deployments a per-call OFW-request budget (env OFW_SYNC_MAX_REQUESTS, or the maxRequests argument) caps how far one call walks; when the budget is hit the response reports done:false with a note \u2014 call again with the SAME arguments to resume. done:false means older history is still being backfilled; it does NOT mean recent messages are missing. Local installs are unbounded by default (done is always true).",
|
|
51502
|
+
description: "Sync messages from OurFamilyWizard into the local cache. Returns counts per folder and a list of unread inbox messages whose bodies were NOT fetched (to avoid mark-as-read on OFW). Call ofw_get_message(id) on those to read them. EVERY call re-checks the newest page first, so new messages are picked up promptly even while an old-history backfill is still running; only then does it spend what is left of its budget advancing that backfill. Pass deep:true to walk all OFW pages instead of stopping at the first all-cached page (use to backfill suspected gaps). Sync is BOUNDED and RESUMABLE: on hosted deployments a per-call OFW-request budget (env OFW_SYNC_MAX_REQUESTS, or the maxRequests argument) caps how far one call walks; when the budget is hit the response reports done:false with a note \u2014 call again with the SAME arguments to resume. done:false means older history is still being backfilled; it does NOT mean recent messages are missing. Local installs are unbounded by default (done is always true). On a server-configured no-read day (OFW_READ_DAYS / OFW_NO_READ_DAYS) no inbox or sent message body is downloaded at all \u2014 new messages are cached from the list (sender, date, subject) and the response carries bodiesWithheld:true; the first sync on a reading day fills in those bodies, except unread inbox ones.",
|
|
51250
51503
|
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
51251
51504
|
inputSchema: external_exports.object({
|
|
51252
51505
|
folders: external_exports.array(external_exports.enum(["inbox", "sent", "drafts"])).min(1).describe("Folders to sync (default: all three). Must be non-empty if given \u2014 an empty list would sync nothing while reporting success.").optional(),
|
|
@@ -51261,7 +51514,7 @@ ${jsonText(
|
|
|
51261
51514
|
// Default from OFW_FETCH_UNREAD_BODIES (false unless set), and capped by
|
|
51262
51515
|
// the OFW_ALLOW_MARK_READ ceiling — fetching those bodies is exactly what
|
|
51263
51516
|
// stamps a First Viewed time on every unread message it touches.
|
|
51264
|
-
fetchUnreadBodies:
|
|
51517
|
+
fetchUnreadBodies: markReadPermitted() && (args.fetchUnreadBodies ?? getFetchUnreadBodies()),
|
|
51265
51518
|
deep: args.deep,
|
|
51266
51519
|
maxRequests: args.maxRequests ?? getSyncMaxRequests()
|
|
51267
51520
|
}, cache);
|
|
@@ -51283,7 +51536,7 @@ ${jsonText(
|
|
|
51283
51536
|
})
|
|
51284
51537
|
}, async (args) => {
|
|
51285
51538
|
const cache = cacheProvider();
|
|
51286
|
-
const allowMarkRead =
|
|
51539
|
+
const allowMarkRead = markReadPermitted() && (args.allowMarkRead ?? false);
|
|
51287
51540
|
const requestedIds = args.messageIds ?? [];
|
|
51288
51541
|
const ids = requestedIds.slice(0, MAX_FRESHNESS_IDS);
|
|
51289
51542
|
const wantFolders = args.folders ?? (requestedIds.length > 0 ? [] : ["inbox", "sent", "drafts"]);
|
|
@@ -51345,12 +51598,12 @@ ${jsonText(
|
|
|
51345
51598
|
})
|
|
51346
51599
|
}, async (args) => {
|
|
51347
51600
|
const cache = cacheProvider();
|
|
51348
|
-
const allowMarkRead =
|
|
51601
|
+
const allowMarkRead = markReadPermitted() && (args.allowMarkRead ?? false);
|
|
51349
51602
|
const requestedIds = args.ids ?? [];
|
|
51350
51603
|
const requestedKeys = args.draftKeys ?? [];
|
|
51351
51604
|
const wantInventory = args.includeDraftInventory ?? (requestedIds.length === 0 && requestedKeys.length === 0);
|
|
51352
51605
|
const allTargets = [
|
|
51353
|
-
...requestedIds.map((
|
|
51606
|
+
...requestedIds.map((id2) => ({ kind: "id", id: id2 })),
|
|
51354
51607
|
...requestedKeys.map((draftKey) => ({ kind: "draftKey", draftKey }))
|
|
51355
51608
|
];
|
|
51356
51609
|
const targets = allTargets.slice(0, MAX_FRESHNESS_IDS);
|
|
@@ -51463,7 +51716,7 @@ function decorate(item) {
|
|
|
51463
51716
|
}
|
|
51464
51717
|
async function deleteOFWMessages(client2, ids) {
|
|
51465
51718
|
const form = new FormData();
|
|
51466
|
-
for (const
|
|
51719
|
+
for (const id2 of ids) form.append("messageIds", String(id2));
|
|
51467
51720
|
return client2.request("DELETE", "/pub/v1/messages", form);
|
|
51468
51721
|
}
|
|
51469
51722
|
|
|
@@ -51550,7 +51803,7 @@ function detailToWriteArgs(d) {
|
|
|
51550
51803
|
var SHARED = "shared with co-parent";
|
|
51551
51804
|
var PRIVATE = "private (only you)";
|
|
51552
51805
|
function describeEvent(a, names = /* @__PURE__ */ new Map()) {
|
|
51553
|
-
const who = (
|
|
51806
|
+
const who = (id2) => ({ userId: id2, name: names.get(id2) ?? null });
|
|
51554
51807
|
const out = {
|
|
51555
51808
|
title: a.title,
|
|
51556
51809
|
startDate: a.startDate,
|
|
@@ -51560,7 +51813,7 @@ function describeEvent(a, names = /* @__PURE__ */ new Map()) {
|
|
|
51560
51813
|
};
|
|
51561
51814
|
if (a.location) out.location = a.location;
|
|
51562
51815
|
if (a.notes) out.notes = a.notes;
|
|
51563
|
-
if (a.children !== void 0) out.children = a.children.map((
|
|
51816
|
+
if (a.children !== void 0) out.children = a.children.map((id2) => who(id2));
|
|
51564
51817
|
if (a.eventParentId !== void 0) out.eventParent = who(a.eventParentId);
|
|
51565
51818
|
if (a.dropOffParentId !== void 0) out.dropOffParent = who(a.dropOffParentId);
|
|
51566
51819
|
if (a.pickUpParentId !== void 0) out.pickUpParent = who(a.pickUpParentId);
|
|
@@ -51663,8 +51916,8 @@ function registerCalendarTools(server, client2) {
|
|
|
51663
51916
|
})
|
|
51664
51917
|
}, async (args, ctx) => {
|
|
51665
51918
|
const { eventId, confirmToken, ...changes } = args;
|
|
51666
|
-
const
|
|
51667
|
-
const rawDetail = await client2.request("GET", `/pub/v3/events/${
|
|
51919
|
+
const id2 = encodeURIComponent(eventId);
|
|
51920
|
+
const rawDetail = await client2.request("GET", `/pub/v3/events/${id2}`);
|
|
51668
51921
|
const current = parseLenient(eventDetailSchema, rawDetail, { label: "ofw-mcp", context: `GET /pub/v3/events/${eventId}`, mode: "strict" });
|
|
51669
51922
|
const defined = Object.fromEntries(Object.entries(changes).filter(([, v]) => v !== void 0));
|
|
51670
51923
|
const base = detailToWriteArgs(current);
|
|
@@ -51692,7 +51945,7 @@ function registerCalendarTools(server, client2) {
|
|
|
51692
51945
|
if (gate) return gate;
|
|
51693
51946
|
}
|
|
51694
51947
|
try {
|
|
51695
|
-
await requestWrite(client2, "PUT", `/pub/v3/events/${
|
|
51948
|
+
await requestWrite(client2, "PUT", `/pub/v3/events/${id2}`, payload);
|
|
51696
51949
|
} catch (e) {
|
|
51697
51950
|
if (!(e instanceof UnconfirmedWriteError)) throw e;
|
|
51698
51951
|
return unconfirmedWriteResponse(e, {
|
|
@@ -51702,7 +51955,7 @@ function registerCalendarTools(server, client2) {
|
|
|
51702
51955
|
});
|
|
51703
51956
|
}
|
|
51704
51957
|
try {
|
|
51705
|
-
const rawAfter = await client2.request("GET", `/pub/v3/events/${
|
|
51958
|
+
const rawAfter = await client2.request("GET", `/pub/v3/events/${id2}`);
|
|
51706
51959
|
const event = parseLenient(eventDetailSchema, rawAfter, { label: "ofw-mcp", context: `GET /pub/v3/events/${eventId} (post-update)`, mode: "strict" });
|
|
51707
51960
|
return jsonResponse({ note: "Event updated; returning re-fetched event state.", event });
|
|
51708
51961
|
} catch (e) {
|
|
@@ -51723,8 +51976,8 @@ function registerCalendarTools(server, client2) {
|
|
|
51723
51976
|
})
|
|
51724
51977
|
}, async (args, ctx) => {
|
|
51725
51978
|
const includeFuture = args.includeFuture ?? false;
|
|
51726
|
-
const
|
|
51727
|
-
const rawDetail = await client2.request("GET", `/pub/v3/events/${
|
|
51979
|
+
const id2 = encodeURIComponent(args.eventId);
|
|
51980
|
+
const rawDetail = await client2.request("GET", `/pub/v3/events/${id2}`);
|
|
51728
51981
|
const current = parseLenient(eventDetailSchema, rawDetail, { label: "ofw-mcp", context: `GET /pub/v3/events/${args.eventId}`, mode: "strict" });
|
|
51729
51982
|
if (current.publicFlag) {
|
|
51730
51983
|
const base = detailToWriteArgs(current);
|
|
@@ -51749,7 +52002,7 @@ function registerCalendarTools(server, client2) {
|
|
|
51749
52002
|
if (gate) return gate;
|
|
51750
52003
|
}
|
|
51751
52004
|
try {
|
|
51752
|
-
await requestWrite(client2, "DELETE", `/pub/v3/events/${
|
|
52005
|
+
await requestWrite(client2, "DELETE", `/pub/v3/events/${id2}?includeFuture=${includeFuture}`);
|
|
51753
52006
|
} catch (e) {
|
|
51754
52007
|
if (!(e instanceof UnconfirmedWriteError)) throw e;
|
|
51755
52008
|
return unconfirmedWriteResponse(e, {
|
|
@@ -51762,6 +52015,169 @@ function registerCalendarTools(server, client2) {
|
|
|
51762
52015
|
});
|
|
51763
52016
|
}
|
|
51764
52017
|
|
|
52018
|
+
// src/tools/expense-reimbursement.ts
|
|
52019
|
+
var money = external_exports.number().nonnegative().refine((v) => Number.isSafeInteger(Math.round(v * 100)) && v === Math.round(v * 100) / 100, "Must be an exact, safe cent amount");
|
|
52020
|
+
var id = external_exports.number().int().positive();
|
|
52021
|
+
var detailSchema = external_exports.looseObject({
|
|
52022
|
+
id,
|
|
52023
|
+
title: external_exports.string().min(1).refine((v) => v.trim().length > 0),
|
|
52024
|
+
author: external_exports.looseObject({ userId: id }),
|
|
52025
|
+
payer: external_exports.looseObject({ userId: id }),
|
|
52026
|
+
private: external_exports.boolean(),
|
|
52027
|
+
paymentType: external_exports.string(),
|
|
52028
|
+
amount: external_exports.looseObject({ total: money.refine((v) => v > 0), totalOwed: money, leftToPay: money }),
|
|
52029
|
+
status: external_exports.string().min(1),
|
|
52030
|
+
statusInfo: external_exports.looseObject({ baseStatus: external_exports.string(), subStatus: external_exports.literal("NONE") }),
|
|
52031
|
+
category: external_exports.looseObject({ id, split: external_exports.looseObject({ parentSplit: external_exports.string(), coparentSplit: external_exports.string() }) }),
|
|
52032
|
+
children: external_exports.array(external_exports.looseObject({ userId: id })).min(1)
|
|
52033
|
+
}).refine(
|
|
52034
|
+
(d) => d.amount.leftToPay <= d.amount.totalOwed && d.amount.totalOwed <= d.amount.total,
|
|
52035
|
+
"Inconsistent expense balances"
|
|
52036
|
+
);
|
|
52037
|
+
function immutableRevision(d) {
|
|
52038
|
+
const { status: _status, statusInfo: _info, paymentType: _type, amount, ...rest } = d;
|
|
52039
|
+
const {
|
|
52040
|
+
leftToPay: _balance,
|
|
52041
|
+
leftToPayFmt: _balanceFmt,
|
|
52042
|
+
description: _description,
|
|
52043
|
+
color: _color,
|
|
52044
|
+
...amountRest
|
|
52045
|
+
} = amount;
|
|
52046
|
+
return stateRevision({ ...rest, amount: amountRest });
|
|
52047
|
+
}
|
|
52048
|
+
function registerExpenseReimbursementTool(server, client2) {
|
|
52049
|
+
server.registerTool("ofw_mark_expense_reimbursed", {
|
|
52050
|
+
description: "Irreversibly mark the FULL remaining expense balance reimbursed externally. Records an already completed outside-OFW reimbursement only: does NOT send money or use bank/payment endpoints; no partial amounts. Requires expectedRemainingAmount (currency units, positive exact cents) matching the current leftToPay, NOT the full expense total. Reads the current expense, binds the entire detail to confirmation, rechecks immediately before writing, then verifies paid status and unchanged fields. Cannot be undone. On EXPENSE_REIMBURSEMENT_UNCONFIRMED, mayHaveLanded=true: inspect the OFW Expenses log before any retry; never replay blindly. " + CONFIRM_NOTE,
|
|
52051
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true },
|
|
52052
|
+
inputSchema: external_exports.object({
|
|
52053
|
+
expenseId: id.describe("Existing expense entity id"),
|
|
52054
|
+
expectedRemainingAmount: money.refine((v) => v > 0, "Must be positive").describe("Full remaining external reimbursement in currency units (e.g. 48.50); must match leftToPay, not the expense total"),
|
|
52055
|
+
confirmToken: confirmTokenParam
|
|
52056
|
+
})
|
|
52057
|
+
}, async (args, ctx) => {
|
|
52058
|
+
const path = `/pub/v2/expense/expenses/${args.expenseId}`;
|
|
52059
|
+
const read = async () => {
|
|
52060
|
+
const d = parseLenient(
|
|
52061
|
+
detailSchema,
|
|
52062
|
+
await client2.request("GET", path),
|
|
52063
|
+
{ label: "ofw-mcp", context: `GET ${path} (mark reimbursed)`, mode: "strict" }
|
|
52064
|
+
);
|
|
52065
|
+
if (d.id !== args.expenseId) throw new Error("Expense id does not match the requested expense");
|
|
52066
|
+
return d;
|
|
52067
|
+
};
|
|
52068
|
+
let current;
|
|
52069
|
+
try {
|
|
52070
|
+
current = await read();
|
|
52071
|
+
} catch {
|
|
52072
|
+
return jsonErrorResponse({
|
|
52073
|
+
result: "EXPENSE_REIMBURSEMENT_REFUSED",
|
|
52074
|
+
expenseId: args.expenseId,
|
|
52075
|
+
reason: "Could not safely read the expense identity, status, parties and balances. Nothing was sent."
|
|
52076
|
+
});
|
|
52077
|
+
}
|
|
52078
|
+
const base = current.statusInfo.baseStatus;
|
|
52079
|
+
if (base === "PAID" && current.amount.leftToPay === 0) {
|
|
52080
|
+
return jsonResponse({
|
|
52081
|
+
result: "ALREADY_PAID",
|
|
52082
|
+
expenseId: args.expenseId,
|
|
52083
|
+
changed: false,
|
|
52084
|
+
note: "OFW already reports paid with zero remaining balance. No write or money transfer was performed."
|
|
52085
|
+
});
|
|
52086
|
+
}
|
|
52087
|
+
if (!["OPEN", "APPROVED", "PARTIAL"].includes(base) || current.amount.leftToPay <= 0) {
|
|
52088
|
+
return jsonErrorResponse({
|
|
52089
|
+
result: "EXPENSE_REIMBURSEMENT_REFUSED",
|
|
52090
|
+
expenseId: args.expenseId,
|
|
52091
|
+
reason: "Only OPEN, APPROVED or PARTIAL expenses with subStatus NONE and positive remaining balance are supported. Nothing was sent."
|
|
52092
|
+
});
|
|
52093
|
+
}
|
|
52094
|
+
if (Math.round(current.amount.leftToPay * 100) !== Math.round(args.expectedRemainingAmount * 100)) {
|
|
52095
|
+
return jsonErrorResponse({
|
|
52096
|
+
result: "EXPENSE_REMAINING_AMOUNT_MISMATCH",
|
|
52097
|
+
expenseId: args.expenseId,
|
|
52098
|
+
expectedRemainingAmount: args.expectedRemainingAmount,
|
|
52099
|
+
remainingAmount: current.amount.leftToPay,
|
|
52100
|
+
total: current.amount.total,
|
|
52101
|
+
reason: "Approve the full remaining balance, not the original expense total or a partial payment. Nothing was sent."
|
|
52102
|
+
});
|
|
52103
|
+
}
|
|
52104
|
+
const payload = { status: "MARKED_REIMBURSED" };
|
|
52105
|
+
const revision = stateRevision(current);
|
|
52106
|
+
const gate = await confirmWrite2(ctx, {
|
|
52107
|
+
args,
|
|
52108
|
+
tool: "ofw_mark_expense_reimbursed",
|
|
52109
|
+
action: "ofw.expense.mark-reimbursed",
|
|
52110
|
+
target: `expense:${args.expenseId}`,
|
|
52111
|
+
revision,
|
|
52112
|
+
payload,
|
|
52113
|
+
confirmToken: args.confirmToken,
|
|
52114
|
+
message: `Mark "${current.title}" fully reimbursed externally (${current.amount.leftToPay}). This cannot be undone and does not transfer money.`,
|
|
52115
|
+
preview: {
|
|
52116
|
+
expenseId: args.expenseId,
|
|
52117
|
+
title: current.title,
|
|
52118
|
+
authorUserId: current.author.userId,
|
|
52119
|
+
payerUserId: current.payer.userId,
|
|
52120
|
+
category: current.category,
|
|
52121
|
+
children: current.children,
|
|
52122
|
+
private: current.private,
|
|
52123
|
+
total: current.amount.total,
|
|
52124
|
+
totalOwed: current.amount.totalOwed,
|
|
52125
|
+
remainingAmount: current.amount.leftToPay,
|
|
52126
|
+
status: current.status,
|
|
52127
|
+
statusInfo: current.statusInfo,
|
|
52128
|
+
paymentType: current.paymentType,
|
|
52129
|
+
warning: "Mark the FULL remaining balance reimbursed outside OFW. This cannot be undone. No money is transferred; no bank/payment action is performed."
|
|
52130
|
+
}
|
|
52131
|
+
});
|
|
52132
|
+
if (gate) return gate;
|
|
52133
|
+
try {
|
|
52134
|
+
if (stateRevision(await read()) !== revision) {
|
|
52135
|
+
return jsonErrorResponse({
|
|
52136
|
+
result: "EXPENSE_CHANGED",
|
|
52137
|
+
expenseId: args.expenseId,
|
|
52138
|
+
reason: "The expense changed after confirmation. Nothing was sent. Review it again before confirming."
|
|
52139
|
+
});
|
|
52140
|
+
}
|
|
52141
|
+
} catch {
|
|
52142
|
+
return jsonErrorResponse({
|
|
52143
|
+
result: "EXPENSE_REIMBURSEMENT_REFUSED",
|
|
52144
|
+
expenseId: args.expenseId,
|
|
52145
|
+
reason: "The immediate pre-write check failed. Nothing was sent."
|
|
52146
|
+
});
|
|
52147
|
+
}
|
|
52148
|
+
try {
|
|
52149
|
+
await requestWrite(client2, "PUT", `${path}/status`, payload);
|
|
52150
|
+
} catch (e) {
|
|
52151
|
+
if (!(e instanceof UnconfirmedWriteError)) throw e;
|
|
52152
|
+
return unconfirmedWriteResponse(e, {
|
|
52153
|
+
result: "EXPENSE_REIMBURSEMENT_UNCONFIRMED",
|
|
52154
|
+
what: `mark expense ${args.expenseId} reimbursed`,
|
|
52155
|
+
checkWith: "the Expenses log on ourfamilywizard.com"
|
|
52156
|
+
});
|
|
52157
|
+
}
|
|
52158
|
+
try {
|
|
52159
|
+
const after = await read();
|
|
52160
|
+
if (after.statusInfo.baseStatus !== "PAID" || after.amount.leftToPay !== 0 || after.paymentType !== "Marked reimbursed" || immutableRevision(after) !== immutableRevision(current)) {
|
|
52161
|
+
throw new Error("Paid status, external reimbursement marker, zero balance or unchanged expense fields could not be verified");
|
|
52162
|
+
}
|
|
52163
|
+
return jsonResponse({
|
|
52164
|
+
result: "EXPENSE_MARKED_REIMBURSED",
|
|
52165
|
+
expenseId: args.expenseId,
|
|
52166
|
+
verified: true,
|
|
52167
|
+
reimbursedAmount: current.amount.leftToPay,
|
|
52168
|
+
remainingAmount: 0,
|
|
52169
|
+
moneyTransferred: false
|
|
52170
|
+
});
|
|
52171
|
+
} catch (e) {
|
|
52172
|
+
return unconfirmedWriteResponse(new UnconfirmedWriteError(args.expenseId, e), {
|
|
52173
|
+
result: "EXPENSE_REIMBURSEMENT_UNCONFIRMED",
|
|
52174
|
+
what: `verify reimbursement of expense ${args.expenseId}`,
|
|
52175
|
+
checkWith: "the Expenses log on ourfamilywizard.com"
|
|
52176
|
+
});
|
|
52177
|
+
}
|
|
52178
|
+
});
|
|
52179
|
+
}
|
|
52180
|
+
|
|
51765
52181
|
// src/tools/expenses.ts
|
|
51766
52182
|
var UploadedExpenseFileSchema = external_exports.looseObject({
|
|
51767
52183
|
fileId: external_exports.number(),
|
|
@@ -51880,7 +52296,7 @@ var refId = (v, key) => positiveInt(v) ?? (isRecord2(v) ? positiveInt(v[key]) ??
|
|
|
51880
52296
|
var idList = (v, key) => {
|
|
51881
52297
|
if (!Array.isArray(v)) return void 0;
|
|
51882
52298
|
const ids = v.map((x) => refId(x, key));
|
|
51883
|
-
return ids.every((
|
|
52299
|
+
return ids.every((id2) => id2 !== void 0) ? ids : void 0;
|
|
51884
52300
|
};
|
|
51885
52301
|
function readExpenseState(raw) {
|
|
51886
52302
|
const d = isRecord2(raw) && isRecord2(raw.data) ? raw.data : raw;
|
|
@@ -51916,6 +52332,7 @@ function registerExpenseTools(server, client2, attachmentIO) {
|
|
|
51916
52332
|
const uploadOnly = getExpenseUploadOnly();
|
|
51917
52333
|
const checkIn = uploadOnly ? "the Expenses log on ourfamilywizard.com (ofw_list_expenses is not available in this deployment)" : "ofw_list_expenses";
|
|
51918
52334
|
const allowWrites = writeMode === "all";
|
|
52335
|
+
if (allowWrites && !uploadOnly) registerExpenseReimbursementTool(server, client2);
|
|
51919
52336
|
const allowReceiptUploads = allowWrites && attachmentIO !== void 0;
|
|
51920
52337
|
if (!uploadOnly) server.registerTool("ofw_get_expense_totals", {
|
|
51921
52338
|
description: "Get OurFamilyWizard expense summary totals (owed/paid)",
|
|
@@ -52435,8 +52852,13 @@ function buildMessageFilter(opts) {
|
|
|
52435
52852
|
}
|
|
52436
52853
|
if (opts.q !== void 0 && opts.q.length > 0) {
|
|
52437
52854
|
const pattern = `%${opts.q}%`;
|
|
52438
|
-
|
|
52439
|
-
|
|
52855
|
+
if (opts.qSubjectOnly) {
|
|
52856
|
+
wheres.push("subject LIKE ?");
|
|
52857
|
+
params.push(pattern);
|
|
52858
|
+
} else {
|
|
52859
|
+
wheres.push("(subject LIKE ? OR body LIKE ?)");
|
|
52860
|
+
params.push(pattern, pattern);
|
|
52861
|
+
}
|
|
52440
52862
|
}
|
|
52441
52863
|
return {
|
|
52442
52864
|
where: wheres.length > 0 ? `WHERE ${wheres.join(" AND ")}` : "",
|
|
@@ -52504,8 +52926,8 @@ var OFWCacheCore = class {
|
|
|
52504
52926
|
for (const row of rows) this.upsertMessage(row);
|
|
52505
52927
|
});
|
|
52506
52928
|
}
|
|
52507
|
-
getMessage(
|
|
52508
|
-
const r = this.db.get("SELECT * FROM messages WHERE id = ?", [
|
|
52929
|
+
getMessage(id2) {
|
|
52930
|
+
const r = this.db.get("SELECT * FROM messages WHERE id = ?", [id2]);
|
|
52509
52931
|
return r ? rowFromDb(r) : null;
|
|
52510
52932
|
}
|
|
52511
52933
|
/**
|
|
@@ -52528,8 +52950,8 @@ var OFWCacheCore = class {
|
|
|
52528
52950
|
* `ofw_get_message` (which would have wrongly classified it as `inbox`)
|
|
52529
52951
|
* — the drafts table is the authoritative source for that id now.
|
|
52530
52952
|
*/
|
|
52531
|
-
deleteMessage(
|
|
52532
|
-
this.db.run("DELETE FROM messages WHERE id = ?", [
|
|
52953
|
+
deleteMessage(id2) {
|
|
52954
|
+
this.db.run("DELETE FROM messages WHERE id = ?", [id2]);
|
|
52533
52955
|
}
|
|
52534
52956
|
listMessages(opts) {
|
|
52535
52957
|
const { where, params } = buildMessageFilter(opts);
|
|
@@ -52577,8 +52999,8 @@ var OFWCacheCore = class {
|
|
|
52577
52999
|
for (const row of rows) this.upsertDraft(row);
|
|
52578
53000
|
});
|
|
52579
53001
|
}
|
|
52580
|
-
getDraft(
|
|
52581
|
-
const r = this.db.get("SELECT * FROM drafts WHERE id = ?", [
|
|
53002
|
+
getDraft(id2) {
|
|
53003
|
+
const r = this.db.get("SELECT * FROM drafts WHERE id = ?", [id2]);
|
|
52582
53004
|
return r ? draftFromDb(r) : null;
|
|
52583
53005
|
}
|
|
52584
53006
|
/**
|
|
@@ -52607,8 +53029,8 @@ var OFWCacheCore = class {
|
|
|
52607
53029
|
const r = this.db.get("SELECT COUNT(*) as n FROM drafts", []);
|
|
52608
53030
|
return r?.n ?? 0;
|
|
52609
53031
|
}
|
|
52610
|
-
deleteDraft(
|
|
52611
|
-
this.db.run("DELETE FROM drafts WHERE id = ?", [
|
|
53032
|
+
deleteDraft(id2) {
|
|
53033
|
+
this.db.run("DELETE FROM drafts WHERE id = ?", [id2]);
|
|
52612
53034
|
}
|
|
52613
53035
|
listDraftIds() {
|
|
52614
53036
|
const rows = this.db.all("SELECT id FROM drafts", []);
|
|
@@ -52634,8 +53056,8 @@ var OFWCacheCore = class {
|
|
|
52634
53056
|
]
|
|
52635
53057
|
);
|
|
52636
53058
|
}
|
|
52637
|
-
getDraftLineageById(
|
|
52638
|
-
const r = this.db.get("SELECT * FROM draft_lineage WHERE id = ?", [
|
|
53059
|
+
getDraftLineageById(id2) {
|
|
53060
|
+
const r = this.db.get("SELECT * FROM draft_lineage WHERE id = ?", [id2]);
|
|
52639
53061
|
return r ? lineageFromDb(r) : null;
|
|
52640
53062
|
}
|
|
52641
53063
|
/**
|
|
@@ -52770,14 +53192,14 @@ var LocalCacheStore = class {
|
|
|
52770
53192
|
async upsertMessages(rows) {
|
|
52771
53193
|
this.core.upsertMessages(rows);
|
|
52772
53194
|
}
|
|
52773
|
-
async getMessage(
|
|
52774
|
-
return this.core.getMessage(
|
|
53195
|
+
async getMessage(id2) {
|
|
53196
|
+
return this.core.getMessage(id2);
|
|
52775
53197
|
}
|
|
52776
53198
|
async getMessages(ids) {
|
|
52777
53199
|
return this.core.getMessages(ids);
|
|
52778
53200
|
}
|
|
52779
|
-
async deleteMessage(
|
|
52780
|
-
this.core.deleteMessage(
|
|
53201
|
+
async deleteMessage(id2) {
|
|
53202
|
+
this.core.deleteMessage(id2);
|
|
52781
53203
|
}
|
|
52782
53204
|
async listMessages(opts) {
|
|
52783
53205
|
return this.core.listMessages(opts);
|
|
@@ -52791,8 +53213,8 @@ var LocalCacheStore = class {
|
|
|
52791
53213
|
async upsertDrafts(rows) {
|
|
52792
53214
|
this.core.upsertDrafts(rows);
|
|
52793
53215
|
}
|
|
52794
|
-
async getDraft(
|
|
52795
|
-
return this.core.getDraft(
|
|
53216
|
+
async getDraft(id2) {
|
|
53217
|
+
return this.core.getDraft(id2);
|
|
52796
53218
|
}
|
|
52797
53219
|
async getDrafts(ids) {
|
|
52798
53220
|
return this.core.getDrafts(ids);
|
|
@@ -52803,8 +53225,8 @@ var LocalCacheStore = class {
|
|
|
52803
53225
|
async countDrafts() {
|
|
52804
53226
|
return this.core.countDrafts();
|
|
52805
53227
|
}
|
|
52806
|
-
async deleteDraft(
|
|
52807
|
-
this.core.deleteDraft(
|
|
53228
|
+
async deleteDraft(id2) {
|
|
53229
|
+
this.core.deleteDraft(id2);
|
|
52808
53230
|
}
|
|
52809
53231
|
async listDraftIds() {
|
|
52810
53232
|
return this.core.listDraftIds();
|
|
@@ -52812,8 +53234,8 @@ var LocalCacheStore = class {
|
|
|
52812
53234
|
async recordDraftLineage(row) {
|
|
52813
53235
|
this.core.recordDraftLineage(row);
|
|
52814
53236
|
}
|
|
52815
|
-
async getDraftLineageById(
|
|
52816
|
-
return this.core.getDraftLineageById(
|
|
53237
|
+
async getDraftLineageById(id2) {
|
|
53238
|
+
return this.core.getDraftLineageById(id2);
|
|
52817
53239
|
}
|
|
52818
53240
|
async getDraftLineageByIds(ids) {
|
|
52819
53241
|
return this.core.getDraftLineageByIds(ids);
|