bruce-models 6.8.2 → 6.8.3

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,8 +16155,289 @@
16155
16155
  Tracking.GetData = GetData;
16156
16156
  })(exports.Tracking || (exports.Tracking = {}));
16157
16157
 
16158
+ const DEFAULT_BASE_URL = "http://localhost:8888";
16159
+ /**
16160
+ * Lightweight client for the Navigator MCP chat HTTP endpoints.
16161
+ * Encapsulates header construction and error handling so UI layers
16162
+ * can focus on presentation logic.
16163
+ */
16164
+ class NavigatorChatClient {
16165
+ constructor(options = {}) {
16166
+ var _a, _b;
16167
+ this.baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : DEFAULT_BASE_URL;
16168
+ this.fetchImpl = options.fetchImpl;
16169
+ this.defaultHeaders = (_b = options.defaultHeaders) !== null && _b !== void 0 ? _b : {};
16170
+ }
16171
+ /**
16172
+ * Ask a question via the MCP chat endpoint.
16173
+ */
16174
+ ask(request, auth) {
16175
+ var _a, _b;
16176
+ return __awaiter(this, void 0, void 0, function* () {
16177
+ if (!request.question || !request.question.trim()) {
16178
+ throw new Error("NavigatorChatClient.ask requires a non-empty question.");
16179
+ }
16180
+ const response = yield this.fetchFromEndpoint("/chat", {
16181
+ method: "POST",
16182
+ body: JSON.stringify({
16183
+ question: request.question,
16184
+ context: request.context,
16185
+ history: request.history
16186
+ }),
16187
+ headers: {
16188
+ "Content-Type": "application/json"
16189
+ }
16190
+ }, auth);
16191
+ const data = yield this.parseJson(response);
16192
+ 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
+ return {
16194
+ text,
16195
+ raw: data
16196
+ };
16197
+ });
16198
+ }
16199
+ /**
16200
+ * Clear chat history stored on the MCP server.
16201
+ */
16202
+ clear(auth) {
16203
+ return __awaiter(this, void 0, void 0, function* () {
16204
+ yield this.fetchFromEndpoint("/clear", {
16205
+ method: "POST",
16206
+ headers: {
16207
+ "Content-Type": "application/json"
16208
+ }
16209
+ }, auth);
16210
+ });
16211
+ }
16212
+ /**
16213
+ * Build a fully-qualified endpoint relative to the configured base URL.
16214
+ */
16215
+ buildUrl(path) {
16216
+ if (path.startsWith("http://") || path.startsWith("https://")) {
16217
+ return path;
16218
+ }
16219
+ if (!path.startsWith("/")) {
16220
+ path = `/${path}`;
16221
+ }
16222
+ return `${this.baseUrl}${path}`;
16223
+ }
16224
+ fetchFromEndpoint(path, init, auth) {
16225
+ var _a;
16226
+ return __awaiter(this, void 0, void 0, function* () {
16227
+ const fetchImpl = this.resolveFetch();
16228
+ const headers = Object.assign(Object.assign({}, this.defaultHeaders), ((_a = init.headers) !== null && _a !== void 0 ? _a : {}));
16229
+ if (auth === null || auth === void 0 ? void 0 : auth.accountId) {
16230
+ headers["X-Account-Id"] = auth.accountId;
16231
+ }
16232
+ if (auth === null || auth === void 0 ? void 0 : auth.sessionId) {
16233
+ headers["X-Session-Id"] = auth.sessionId;
16234
+ }
16235
+ const response = yield fetchImpl(this.buildUrl(path), Object.assign(Object.assign({}, init), { headers }));
16236
+ if (!response.ok) {
16237
+ const message = yield this.safeReadResponseText(response);
16238
+ throw new Error(`Navigator chat request failed (${response.status} ${response.statusText}): ${message}`);
16239
+ }
16240
+ return response;
16241
+ });
16242
+ }
16243
+ resolveFetch() {
16244
+ if (this.fetchImpl) {
16245
+ return this.fetchImpl;
16246
+ }
16247
+ if (typeof fetch !== "undefined") {
16248
+ return fetch;
16249
+ }
16250
+ // Lazy-load isomorphic-fetch for environments without a native fetch.
16251
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
16252
+ const isomorphicFetch = require("isomorphic-fetch");
16253
+ if (typeof isomorphicFetch !== "function") {
16254
+ throw new Error("isomorphic-fetch did not return a fetch implementation.");
16255
+ }
16256
+ return isomorphicFetch;
16257
+ }
16258
+ parseJson(response) {
16259
+ return __awaiter(this, void 0, void 0, function* () {
16260
+ try {
16261
+ return yield response.json();
16262
+ }
16263
+ catch (_a) {
16264
+ return {};
16265
+ }
16266
+ });
16267
+ }
16268
+ safeReadResponseText(response) {
16269
+ return __awaiter(this, void 0, void 0, function* () {
16270
+ try {
16271
+ return yield response.text();
16272
+ }
16273
+ catch (_a) {
16274
+ return "";
16275
+ }
16276
+ });
16277
+ }
16278
+ }
16279
+
16280
+ const DEFAULT_PORT = 8081;
16281
+ const DEFAULT_PATH = "/ws";
16282
+ /**
16283
+ * Minimal MCP WebSocket transport that handles tool call dispatching.
16284
+ * UI layers can provide their own tool handler while reusing this
16285
+ * connection management logic.
16286
+ */
16287
+ class NavigatorMcpWebSocketClient {
16288
+ constructor(toolHandler, options = {}) {
16289
+ this.ws = null;
16290
+ this.isConnecting = false;
16291
+ this.toolHandler = toolHandler;
16292
+ this.options = options;
16293
+ this.currentAuth = options.auth;
16294
+ if (options.autoConnect) {
16295
+ this.connect();
16296
+ }
16297
+ }
16298
+ connect(auth) {
16299
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
16300
+ if (auth) {
16301
+ this.currentAuth = auth;
16302
+ }
16303
+ if (this.isConnecting || ((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN) {
16304
+ (_c = (_b = this.logger()).debug) === null || _c === void 0 ? void 0 : _c.call(_b, "[NavigatorMcpWS] Connection already active or in-flight; skipping connect.");
16305
+ return;
16306
+ }
16307
+ if (!((_d = this.currentAuth) === null || _d === void 0 ? void 0 : _d.accountId) || !((_e = this.currentAuth) === null || _e === void 0 ? void 0 : _e.sessionId)) {
16308
+ (_g = (_f = this.logger()).debug) === null || _g === void 0 ? void 0 : _g.call(_f, "[NavigatorMcpWS] Missing auth parameters; connection not started.");
16309
+ return;
16310
+ }
16311
+ try {
16312
+ this.isConnecting = true;
16313
+ const url = this.buildUrl();
16314
+ (_j = (_h = this.logger()).log) === null || _j === void 0 ? void 0 : _j.call(_h, "[NavigatorMcpWS] Connecting to", url);
16315
+ this.ws = new WebSocket(url);
16316
+ this.ws.onopen = (event) => {
16317
+ var _a, _b, _c, _d;
16318
+ (_b = (_a = this.logger()).log) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Connected");
16319
+ this.isConnecting = false;
16320
+ this.send({ method: "server_ready" });
16321
+ (_d = (_c = this.options).onOpen) === null || _d === void 0 ? void 0 : _d.call(_c, event);
16322
+ };
16323
+ this.ws.onmessage = (event) => {
16324
+ this.handleMessage(event.data);
16325
+ };
16326
+ this.ws.onerror = (event) => {
16327
+ var _a, _b, _c, _d;
16328
+ (_b = (_a = this.logger()).error) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Error", event);
16329
+ (_d = (_c = this.options).onError) === null || _d === void 0 ? void 0 : _d.call(_c, event);
16330
+ this.isConnecting = false;
16331
+ };
16332
+ this.ws.onclose = (event) => {
16333
+ var _a, _b, _c, _d;
16334
+ (_b = (_a = this.logger()).log) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Disconnected");
16335
+ this.ws = null;
16336
+ this.isConnecting = false;
16337
+ (_d = (_c = this.options).onClose) === null || _d === void 0 ? void 0 : _d.call(_c, event);
16338
+ };
16339
+ }
16340
+ catch (error) {
16341
+ (_l = (_k = this.logger()).error) === null || _l === void 0 ? void 0 : _l.call(_k, "[NavigatorMcpWS] Failed to establish connection", error);
16342
+ this.isConnecting = false;
16343
+ }
16344
+ }
16345
+ disconnect() {
16346
+ var _a, _b;
16347
+ if (this.ws) {
16348
+ (_b = (_a = this.logger()).debug) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Closing connection");
16349
+ this.ws.close();
16350
+ this.ws = null;
16351
+ this.isConnecting = false;
16352
+ }
16353
+ }
16354
+ isConnected() {
16355
+ var _a;
16356
+ return ((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN;
16357
+ }
16358
+ /**
16359
+ * Update the stored authentication parameters without reconnecting.
16360
+ * Call connect() afterwards to establish a connection with the new auth.
16361
+ */
16362
+ setAuth(auth) {
16363
+ this.currentAuth = auth;
16364
+ }
16365
+ logger() {
16366
+ var _a;
16367
+ return (_a = this.options.logger) !== null && _a !== void 0 ? _a : console;
16368
+ }
16369
+ buildUrl() {
16370
+ var _a, _b, _c, _d, _e;
16371
+ if (this.options.url) {
16372
+ return this.appendAuthParams(this.options.url);
16373
+ }
16374
+ const protocol = (_a = this.options.protocol) !== null && _a !== void 0 ? _a : "ws";
16375
+ const host = (_b = this.options.host) !== null && _b !== void 0 ? _b : "localhost";
16376
+ const port = (_c = this.options.port) !== null && _c !== void 0 ? _c : DEFAULT_PORT;
16377
+ const path = ((_d = this.options.path) !== null && _d !== void 0 ? _d : DEFAULT_PATH).startsWith("/") ? (_e = this.options.path) !== null && _e !== void 0 ? _e : DEFAULT_PATH : `/${this.options.path}`;
16378
+ const baseUrl = `${protocol}://${host}:${port}${path}`;
16379
+ return this.appendAuthParams(baseUrl);
16380
+ }
16381
+ appendAuthParams(url) {
16382
+ var _a, _b;
16383
+ if (!((_a = this.currentAuth) === null || _a === void 0 ? void 0 : _a.accountId) || !((_b = this.currentAuth) === null || _b === void 0 ? void 0 : _b.sessionId)) {
16384
+ return url;
16385
+ }
16386
+ const urlInstance = new URL(url);
16387
+ urlInstance.searchParams.set("accountId", this.currentAuth.accountId);
16388
+ urlInstance.searchParams.set("sessionId", this.currentAuth.sessionId);
16389
+ // Preserve the hash (unlikely to be used, but consistent with URL semantics)
16390
+ return urlInstance.toString();
16391
+ }
16392
+ handleMessage(raw) {
16393
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
16394
+ return __awaiter(this, void 0, void 0, function* () {
16395
+ try {
16396
+ const message = typeof raw === "string" ? JSON.parse(raw) : raw;
16397
+ const method = message === null || message === void 0 ? void 0 : message.method;
16398
+ if (method !== "tools/call") {
16399
+ (_b = (_a = this.logger()).debug) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Ignoring non tool-call message", message);
16400
+ return;
16401
+ }
16402
+ const toolName = (_c = message === null || message === void 0 ? void 0 : message.params) === null || _c === void 0 ? void 0 : _c.name;
16403
+ const toolArgs = (_d = message === null || message === void 0 ? void 0 : message.params) === null || _d === void 0 ? void 0 : _d.arguments;
16404
+ const messageId = message === null || message === void 0 ? void 0 : message.id;
16405
+ if (!toolName) {
16406
+ (_f = (_e = this.logger()).warn) === null || _f === void 0 ? void 0 : _f.call(_e, "[NavigatorMcpWS] Received tool call without name", message);
16407
+ return;
16408
+ }
16409
+ let result;
16410
+ try {
16411
+ result = yield this.toolHandler({
16412
+ name: toolName,
16413
+ args: toolArgs,
16414
+ messageId
16415
+ });
16416
+ }
16417
+ catch (error) {
16418
+ (_h = (_g = this.logger()).error) === null || _h === void 0 ? void 0 : _h.call(_g, "[NavigatorMcpWS] Tool handler threw", error);
16419
+ result = `Error: ${error instanceof Error ? error.message : String(error)}`;
16420
+ }
16421
+ this.send({
16422
+ method: "tool_response",
16423
+ id: messageId,
16424
+ result
16425
+ });
16426
+ }
16427
+ catch (error) {
16428
+ (_k = (_j = this.logger()).error) === null || _k === void 0 ? void 0 : _k.call(_j, "[NavigatorMcpWS] Invalid message", error);
16429
+ }
16430
+ });
16431
+ }
16432
+ send(message) {
16433
+ if (this.ws && this.ws.readyState === WebSocket.OPEN) {
16434
+ this.ws.send(JSON.stringify(message));
16435
+ }
16436
+ }
16437
+ }
16438
+
16158
16439
  // This is updated with the package.json version on build.
16159
- const VERSION = "6.8.2";
16440
+ const VERSION = "6.8.3";
16160
16441
 
16161
16442
  exports.VERSION = VERSION;
16162
16443
  exports.AbstractApi = AbstractApi;
@@ -16165,6 +16446,8 @@
16165
16446
  exports.CacheControl = CacheControl;
16166
16447
  exports.DelayQueue = DelayQueue;
16167
16448
  exports.LRUCache = LRUCache;
16449
+ exports.NavigatorChatClient = NavigatorChatClient;
16450
+ exports.NavigatorMcpWebSocketClient = NavigatorMcpWebSocketClient;
16168
16451
 
16169
16452
  Object.defineProperty(exports, '__esModule', { value: true });
16170
16453