bruce-models 7.0.4 → 7.0.6

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.
@@ -5232,92 +5232,96 @@
5232
5232
  }
5233
5233
  for (let i = 0; i < value.values.length; i++) {
5234
5234
  const option = value.values[i];
5235
- let mapValue = option.fieldValue;
5236
- // If mapValue is prefixed with "JS:", we evaluate it as JavaScript.
5237
- // This lets us do things like JS:Boolean("${}") as a quick way to map 'existence' to a target value.
5238
- if (typeof mapValue === "string" && mapValue.startsWith("JS:")) {
5239
- try {
5240
- let jsEval = mapValue.replace("JS:", "").trim();
5241
- const attrPathStr = exports.PathUtils.Wrap(attrPath);
5242
- jsEval = jsEval.replace("${}", "${" + attrPathStr + "}");
5243
- jsEval = exports.BruceVariable.SwapValues({
5244
- str: jsEval,
5245
- entity: entity
5246
- });
5247
- // https://rollupjs.org/guide/en/#avoiding-eval
5248
- // This stops eval warning.
5249
- const eval2 = eval;
5250
- mapValue = eval2(jsEval);
5251
- // We currently expect eval to return a validity bool.
5252
- // So it either matches and we return it, or it doesn't and we continue.
5253
- if (mapValue) {
5254
- return option.appliedValue;
5255
- }
5256
- else {
5257
- continue;
5258
- }
5259
- }
5260
- catch (exception) {
5261
- const e = exception;
5262
- let suppress = false;
5263
- if (e && typeof e == "object") {
5264
- const msg = e.message;
5265
- suppress = !!msg && (msg.includes("Unexpected end") || msg.includes("got end of script"));
5266
- }
5267
- if (!suppress) {
5268
- console.error(e);
5269
- }
5270
- // Eval failed, therefor not a valid mapping-row.
5271
- continue;
5272
- }
5273
- }
5274
- let isMapValueNum = !isNaN(+mapValue);
5275
- if (isMapValueNum == null) {
5276
- isMapValueNum = false;
5277
- }
5278
- if (isValueNum && (isMapValueNum || (typeof mapValue === "string" && mapValue.includes("-")))) {
5279
- if (+mapValue == +eValue) {
5280
- return option.appliedValue;
5281
- }
5282
- const mapSplit = mapValue.split("-");
5283
- if (mapSplit.length == 2) {
5284
- const min = mapSplit[0];
5285
- const max = mapSplit[1];
5286
- if (min != "") {
5287
- if (+eValue < +min) {
5288
- continue;
5235
+ const fieldValues = Array.isArray(option.fieldValue) ? option.fieldValue : [option.fieldValue];
5236
+ // Check each field value in the array.
5237
+ for (let j = 0; j < fieldValues.length; j++) {
5238
+ let mapValue = fieldValues[j];
5239
+ // If mapValue is prefixed with "JS:", we evaluate it as JavaScript.
5240
+ // This lets us do things like JS:Boolean("${}") as a quick way to map 'existence' to a target value.
5241
+ if (typeof mapValue === "string" && mapValue.startsWith("JS:")) {
5242
+ try {
5243
+ let jsEval = mapValue.replace("JS:", "").trim();
5244
+ const attrPathStr = exports.PathUtils.Wrap(attrPath);
5245
+ jsEval = jsEval.replace("${}", "${" + attrPathStr + "}");
5246
+ jsEval = exports.BruceVariable.SwapValues({
5247
+ str: jsEval,
5248
+ entity: entity
5249
+ });
5250
+ // https://rollupjs.org/guide/en/#avoiding-eval
5251
+ // This stops eval warning.
5252
+ const eval2 = eval;
5253
+ mapValue = eval2(jsEval);
5254
+ // We currently expect eval to return a validity bool.
5255
+ // So it either matches and we return it, or it doesn't and we continue.
5256
+ if (mapValue) {
5257
+ return option.appliedValue;
5289
5258
  }
5290
- }
5291
- if (max != "") {
5292
- if (+eValue > +max) {
5259
+ else {
5293
5260
  continue;
5294
5261
  }
5295
5262
  }
5296
- if (min == "" && max == "") {
5263
+ catch (exception) {
5264
+ const e = exception;
5265
+ let suppress = false;
5266
+ if (e && typeof e == "object") {
5267
+ const msg = e.message;
5268
+ suppress = !!msg && (msg.includes("Unexpected end") || msg.includes("got end of script"));
5269
+ }
5270
+ if (!suppress) {
5271
+ console.error(e);
5272
+ }
5273
+ // Eval failed, therefor not a valid mapping-row.
5297
5274
  continue;
5298
5275
  }
5299
- return option.appliedValue;
5300
5276
  }
5301
- }
5302
- else {
5303
- if (mapValue == eValue) {
5304
- return option.appliedValue;
5277
+ let isMapValueNum = !isNaN(+mapValue);
5278
+ if (isMapValueNum == null) {
5279
+ isMapValueNum = false;
5305
5280
  }
5306
- // Case where Entity value is a boolean but the mapping value is a string.
5307
- // Common as mapping value is typically a user-entered string.
5308
- else if (typeof eValue === "boolean" && typeof mapValue === "string") {
5309
- const eValueStr = eValue ? "true" : "false";
5310
- if (mapValue.toLowerCase() == eValueStr) {
5281
+ if (isValueNum && (isMapValueNum || (typeof mapValue === "string" && mapValue.includes("-")))) {
5282
+ if (+mapValue == +eValue) {
5283
+ return option.appliedValue;
5284
+ }
5285
+ const mapSplit = mapValue.split("-");
5286
+ if (mapSplit.length == 2) {
5287
+ const min = mapSplit[0];
5288
+ const max = mapSplit[1];
5289
+ if (min != "") {
5290
+ if (+eValue < +min) {
5291
+ continue;
5292
+ }
5293
+ }
5294
+ if (max != "") {
5295
+ if (+eValue > +max) {
5296
+ continue;
5297
+ }
5298
+ }
5299
+ if (min == "" && max == "") {
5300
+ continue;
5301
+ }
5311
5302
  return option.appliedValue;
5312
5303
  }
5313
5304
  }
5314
- // Handling possible case where the opposite is true.
5315
- // Have not seen this happen yet, but preparing for any future cases.
5316
- else if (typeof mapValue === "boolean" && typeof eValue === "string") {
5317
- const mapValueStr = mapValue ? "true" : "false";
5318
- if (mapValueStr == eValue.toLowerCase()) {
5305
+ else {
5306
+ if (mapValue == eValue) {
5319
5307
  return option.appliedValue;
5320
5308
  }
5309
+ // Case where Entity value is a boolean but the mapping value is a string.
5310
+ // Common as mapping value is typically a user-entered string.
5311
+ else if (typeof eValue === "boolean" && typeof mapValue === "string") {
5312
+ const eValueStr = eValue ? "true" : "false";
5313
+ if (mapValue.toLowerCase() == eValueStr) {
5314
+ return option.appliedValue;
5315
+ }
5316
+ }
5317
+ // Handling possible case where the opposite is true.
5318
+ // Have not seen this happen yet, but preparing for any future cases.
5319
+ else if (typeof mapValue === "boolean" && typeof eValue === "string") {
5320
+ const mapValueStr = mapValue ? "true" : "false";
5321
+ if (mapValueStr == eValue.toLowerCase()) {
5322
+ return option.appliedValue;
5323
+ }
5324
+ }
5321
5325
  }
5322
5326
  }
5323
5327
  }
@@ -16334,7 +16338,7 @@
16334
16338
  })(exports.Tracking || (exports.Tracking = {}));
16335
16339
 
16336
16340
  const DEFAULT_JOB_POLL_INTERVAL_MS = 1000;
16337
- const DEFAULT_JOB_POLL_TIMEOUT_MS = 4 * 60 * 1000; // match server timeout (4 minutes)
16341
+ const DEFAULT_JOB_POLL_TIMEOUT_MS = 10 * 60 * 1000; // match server timeout (10 minutes)
16338
16342
  const DEFAULT_BASE_URL = "http://localhost:8888";
16339
16343
  /**
16340
16344
  * Lightweight client for the Navigator MCP chat HTTP endpoints.
@@ -16417,15 +16421,17 @@
16417
16421
  .map((step, idx) => (Object.assign(Object.assign({}, step), { index: typeof (step === null || step === void 0 ? void 0 : step.index) === "number" ? step.index : idx })));
16418
16422
  }
16419
16423
  waitForJobCompletion(envelope, auth) {
16420
- var _a, _b, _c, _d, _e;
16424
+ var _a, _b, _c, _d, _e, _f;
16421
16425
  return __awaiter(this, void 0, void 0, function* () {
16422
16426
  if (!envelope.jobId) {
16423
16427
  throw new Error("Chat job response did not include a jobId.");
16424
16428
  }
16425
16429
  const pollPath = (_a = envelope.pollUrl) !== null && _a !== void 0 ? _a : `/chat/jobs/${envelope.jobId}`;
16426
16430
  const startedAt = Date.now();
16431
+ let lastStatusPayload = null;
16427
16432
  while (Date.now() - startedAt < this.jobPollTimeoutMs) {
16428
16433
  const statusPayload = yield this.fetchJobStatus(pollPath, auth);
16434
+ lastStatusPayload = statusPayload;
16429
16435
  const status = statusPayload === null || statusPayload === void 0 ? void 0 : statusPayload.status;
16430
16436
  if (!status) {
16431
16437
  yield this.delay(this.jobPollIntervalMs);
@@ -16455,7 +16461,20 @@
16455
16461
  }
16456
16462
  yield this.delay(this.jobPollIntervalMs);
16457
16463
  }
16458
- throw new Error("Chat job polling timed out. Please try again later.");
16464
+ // Timeout: return a response object instead of throwing
16465
+ const combinedSteps = lastStatusPayload ? [
16466
+ ...(Array.isArray(lastStatusPayload.steps) ? lastStatusPayload.steps : []),
16467
+ ...(Array.isArray((_f = lastStatusPayload.result) === null || _f === void 0 ? void 0 : _f.steps) ? lastStatusPayload.result.steps : [])
16468
+ ] : [];
16469
+ const normalizedSteps = this.normalizeSteps(combinedSteps);
16470
+ return {
16471
+ text: "Chat job polling timed out. Please try again later.",
16472
+ steps: normalizedSteps,
16473
+ raw: lastStatusPayload !== null && lastStatusPayload !== void 0 ? lastStatusPayload : {},
16474
+ jobId: envelope.jobId,
16475
+ status: "TIMEOUT",
16476
+ anonymous: Boolean(lastStatusPayload === null || lastStatusPayload === void 0 ? void 0 : lastStatusPayload.anonymous)
16477
+ };
16459
16478
  });
16460
16479
  }
16461
16480
  fetchJobStatus(path, auth) {
@@ -16702,7 +16721,7 @@
16702
16721
  }
16703
16722
 
16704
16723
  // This is updated with the package.json version on build.
16705
- const VERSION = "7.0.4";
16724
+ const VERSION = "7.0.6";
16706
16725
 
16707
16726
  exports.VERSION = VERSION;
16708
16727
  exports.AbstractApi = AbstractApi;