bruce-models 6.8.9 → 6.9.1

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 JOB_POLL_INTERVAL_MS = 1000;
16159
+ const 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.
@@ -16189,11 +16191,13 @@
16189
16191
  }
16190
16192
  }, auth);
16191
16193
  const data = yield this.parseJson(response);
16194
+ // New async job flow (HTTP 202)
16195
+ if (data && data.jobId && data.status && response.status === 202) {
16196
+ return yield this.waitForJobCompletion(data, auth);
16197
+ }
16198
+ // Legacy synchronous flow fallback
16192
16199
  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 })));
16200
+ const steps = this.normalizeSteps(data === null || data === void 0 ? void 0 : data.steps);
16197
16201
  return {
16198
16202
  text,
16199
16203
  steps,
@@ -16224,6 +16228,73 @@
16224
16228
  // Use URL constructor to properly handle path joining and avoid double slashes
16225
16229
  return new URL(path, this.baseUrl).toString();
16226
16230
  }
16231
+ normalizeSteps(rawSteps) {
16232
+ if (!Array.isArray(rawSteps)) {
16233
+ return [];
16234
+ }
16235
+ return rawSteps
16236
+ .filter((step) => Boolean(step))
16237
+ .map((step, idx) => (Object.assign(Object.assign({}, step), { index: typeof (step === null || step === void 0 ? void 0 : step.index) === "number" ? step.index : idx })));
16238
+ }
16239
+ waitForJobCompletion(envelope, auth) {
16240
+ var _a, _b, _c, _d, _e;
16241
+ return __awaiter(this, void 0, void 0, function* () {
16242
+ if (!envelope.jobId) {
16243
+ throw new Error("Chat job response did not include a jobId.");
16244
+ }
16245
+ const pollPath = (_a = envelope.pollUrl) !== null && _a !== void 0 ? _a : `/chat/jobs/${envelope.jobId}`;
16246
+ const startedAt = Date.now();
16247
+ while (Date.now() - startedAt < JOB_POLL_TIMEOUT_MS) {
16248
+ const statusPayload = yield this.fetchJobStatus(pollPath, auth);
16249
+ const status = statusPayload === null || statusPayload === void 0 ? void 0 : statusPayload.status;
16250
+ if (!status) {
16251
+ yield this.delay(JOB_POLL_INTERVAL_MS);
16252
+ continue;
16253
+ }
16254
+ const combinedSteps = [
16255
+ ...(Array.isArray(statusPayload.steps) ? statusPayload.steps : []),
16256
+ ...(Array.isArray((_b = statusPayload.result) === null || _b === void 0 ? void 0 : _b.steps) ? statusPayload.result.steps : [])
16257
+ ];
16258
+ const normalizedSteps = this.normalizeSteps(combinedSteps);
16259
+ if (status === "COMPLETED") {
16260
+ const result = (_c = statusPayload.result) !== null && _c !== void 0 ? _c : {};
16261
+ const text = (_d = result === null || result === void 0 ? void 0 : result.text) !== null && _d !== void 0 ? _d : "";
16262
+ return {
16263
+ text,
16264
+ steps: normalizedSteps,
16265
+ raw: statusPayload,
16266
+ jobId: envelope.jobId,
16267
+ status,
16268
+ anonymous: Boolean((_e = result === null || result === void 0 ? void 0 : result.anonymous) !== null && _e !== void 0 ? _e : statusPayload.anonymous)
16269
+ };
16270
+ }
16271
+ if (status === "FAILED") {
16272
+ const message = statusPayload.error || "Chat job failed";
16273
+ const error = message.trim() || "Chat job failed";
16274
+ throw new Error(error);
16275
+ }
16276
+ yield this.delay(JOB_POLL_INTERVAL_MS);
16277
+ }
16278
+ throw new Error("Chat job polling timed out. Please try again later.");
16279
+ });
16280
+ }
16281
+ fetchJobStatus(path, auth) {
16282
+ return __awaiter(this, void 0, void 0, function* () {
16283
+ const response = yield this.fetchFromEndpoint(path, {
16284
+ method: "GET"
16285
+ }, auth);
16286
+ const payload = yield this.parseJson(response);
16287
+ if (!payload || !payload.jobId) {
16288
+ throw new Error("Failed to retrieve chat job status.");
16289
+ }
16290
+ return payload;
16291
+ });
16292
+ }
16293
+ delay(ms) {
16294
+ return __awaiter(this, void 0, void 0, function* () {
16295
+ yield new Promise(resolve => setTimeout(resolve, ms));
16296
+ });
16297
+ }
16227
16298
  fetchFromEndpoint(path, init, auth) {
16228
16299
  var _a;
16229
16300
  return __awaiter(this, void 0, void 0, function* () {
@@ -16446,7 +16517,7 @@
16446
16517
  }
16447
16518
 
16448
16519
  // This is updated with the package.json version on build.
16449
- const VERSION = "6.8.9";
16520
+ const VERSION = "6.9.1";
16450
16521
 
16451
16522
  exports.VERSION = VERSION;
16452
16523
  exports.AbstractApi = AbstractApi;