bruce-models 6.9.0 → 6.9.2

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.
@@ -16155,6 +16155,8 @@
16155
16155
  Tracking.GetData = GetData;
16156
16156
  })(exports.Tracking || (exports.Tracking = {}));
16157
16157
 
16158
+ const DEFAULT_JOB_POLL_INTERVAL_MS = 1000;
16159
+ const DEFAULT_JOB_POLL_TIMEOUT_MS = 4 * 60 * 1000; // match server timeout (4 minutes)
16158
16160
  const DEFAULT_BASE_URL = "http://localhost:8888";
16159
16161
  /**
16160
16162
  * Lightweight client for the Navigator MCP chat HTTP endpoints.
@@ -16163,10 +16165,12 @@
16163
16165
  */
16164
16166
  class NavigatorChatClient {
16165
16167
  constructor(options = {}) {
16166
- var _a, _b;
16168
+ var _a, _b, _c, _d;
16167
16169
  this.baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : DEFAULT_BASE_URL;
16168
16170
  this.fetchImpl = options.fetchImpl;
16169
16171
  this.defaultHeaders = (_b = options.defaultHeaders) !== null && _b !== void 0 ? _b : {};
16172
+ this.jobPollIntervalMs = (_c = options.jobPollIntervalMs) !== null && _c !== void 0 ? _c : DEFAULT_JOB_POLL_INTERVAL_MS;
16173
+ this.jobPollTimeoutMs = (_d = options.jobPollTimeoutMs) !== null && _d !== void 0 ? _d : DEFAULT_JOB_POLL_TIMEOUT_MS;
16170
16174
  }
16171
16175
  /**
16172
16176
  * Ask a question via the MCP chat endpoint.
@@ -16189,11 +16193,13 @@
16189
16193
  }
16190
16194
  }, auth);
16191
16195
  const data = yield this.parseJson(response);
16196
+ // New async job flow (HTTP 202)
16197
+ if (data && data.jobId && data.status && response.status === 202) {
16198
+ return yield this.waitForJobCompletion(data, auth);
16199
+ }
16200
+ // Legacy synchronous flow fallback
16192
16201
  const text = (_b = (_a = data === null || data === void 0 ? void 0 : data.Text) !== null && _a !== void 0 ? _a : data === null || data === void 0 ? void 0 : data.text) !== null && _b !== void 0 ? _b : "";
16193
- const rawSteps = Array.isArray(data === null || data === void 0 ? void 0 : data.steps) ? data.steps : [];
16194
- const steps = rawSteps
16195
- .filter((step) => step)
16196
- .map((step, idx) => (Object.assign(Object.assign({}, step), { index: typeof (step === null || step === void 0 ? void 0 : step.index) === "number" ? step.index : idx })));
16202
+ const steps = this.normalizeSteps(data === null || data === void 0 ? void 0 : data.steps);
16197
16203
  return {
16198
16204
  text,
16199
16205
  steps,
@@ -16224,6 +16230,73 @@
16224
16230
  // Use URL constructor to properly handle path joining and avoid double slashes
16225
16231
  return new URL(path, this.baseUrl).toString();
16226
16232
  }
16233
+ normalizeSteps(rawSteps) {
16234
+ if (!Array.isArray(rawSteps)) {
16235
+ return [];
16236
+ }
16237
+ return rawSteps
16238
+ .filter((step) => Boolean(step))
16239
+ .map((step, idx) => (Object.assign(Object.assign({}, step), { index: typeof (step === null || step === void 0 ? void 0 : step.index) === "number" ? step.index : idx })));
16240
+ }
16241
+ waitForJobCompletion(envelope, auth) {
16242
+ var _a, _b, _c, _d, _e;
16243
+ return __awaiter(this, void 0, void 0, function* () {
16244
+ if (!envelope.jobId) {
16245
+ throw new Error("Chat job response did not include a jobId.");
16246
+ }
16247
+ const pollPath = (_a = envelope.pollUrl) !== null && _a !== void 0 ? _a : `/chat/jobs/${envelope.jobId}`;
16248
+ const startedAt = Date.now();
16249
+ while (Date.now() - startedAt < this.jobPollTimeoutMs) {
16250
+ const statusPayload = yield this.fetchJobStatus(pollPath, auth);
16251
+ const status = statusPayload === null || statusPayload === void 0 ? void 0 : statusPayload.status;
16252
+ if (!status) {
16253
+ yield this.delay(this.jobPollIntervalMs);
16254
+ continue;
16255
+ }
16256
+ const combinedSteps = [
16257
+ ...(Array.isArray(statusPayload.steps) ? statusPayload.steps : []),
16258
+ ...(Array.isArray((_b = statusPayload.result) === null || _b === void 0 ? void 0 : _b.steps) ? statusPayload.result.steps : [])
16259
+ ];
16260
+ const normalizedSteps = this.normalizeSteps(combinedSteps);
16261
+ if (status === "COMPLETED") {
16262
+ const result = (_c = statusPayload.result) !== null && _c !== void 0 ? _c : {};
16263
+ const text = (_d = result === null || result === void 0 ? void 0 : result.text) !== null && _d !== void 0 ? _d : "";
16264
+ return {
16265
+ text,
16266
+ steps: normalizedSteps,
16267
+ raw: statusPayload,
16268
+ jobId: envelope.jobId,
16269
+ status,
16270
+ anonymous: Boolean((_e = result === null || result === void 0 ? void 0 : result.anonymous) !== null && _e !== void 0 ? _e : statusPayload.anonymous)
16271
+ };
16272
+ }
16273
+ if (status === "FAILED") {
16274
+ const message = statusPayload.error || "Chat job failed";
16275
+ const error = message.trim() || "Chat job failed";
16276
+ throw new Error(error);
16277
+ }
16278
+ yield this.delay(this.jobPollIntervalMs);
16279
+ }
16280
+ throw new Error("Chat job polling timed out. Please try again later.");
16281
+ });
16282
+ }
16283
+ fetchJobStatus(path, auth) {
16284
+ return __awaiter(this, void 0, void 0, function* () {
16285
+ const response = yield this.fetchFromEndpoint(path, {
16286
+ method: "GET"
16287
+ }, auth);
16288
+ const payload = yield this.parseJson(response);
16289
+ if (!payload || !payload.jobId) {
16290
+ throw new Error("Failed to retrieve chat job status.");
16291
+ }
16292
+ return payload;
16293
+ });
16294
+ }
16295
+ delay(ms) {
16296
+ return __awaiter(this, void 0, void 0, function* () {
16297
+ yield new Promise(resolve => setTimeout(resolve, ms));
16298
+ });
16299
+ }
16227
16300
  fetchFromEndpoint(path, init, auth) {
16228
16301
  var _a;
16229
16302
  return __awaiter(this, void 0, void 0, function* () {
@@ -16446,7 +16519,7 @@
16446
16519
  }
16447
16520
 
16448
16521
  // This is updated with the package.json version on build.
16449
- const VERSION = "6.9.0";
16522
+ const VERSION = "6.9.2";
16450
16523
 
16451
16524
  exports.VERSION = VERSION;
16452
16525
  exports.AbstractApi = AbstractApi;