bruce-models 6.8.2 → 6.8.4
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/dist/bruce-models.es5.js +274 -2
- package/dist/bruce-models.es5.js.map +1 -1
- package/dist/bruce-models.umd.js +275 -1
- package/dist/bruce-models.umd.js.map +1 -1
- package/dist/lib/bruce-models.js +3 -1
- package/dist/lib/bruce-models.js.map +1 -1
- package/dist/lib/mcp/navigator-chat.js +135 -0
- package/dist/lib/mcp/navigator-chat.js.map +1 -0
- package/dist/lib/mcp/navigator-mcp-websocket.js +163 -0
- package/dist/lib/mcp/navigator-mcp-websocket.js.map +1 -0
- package/dist/types/bruce-models.d.ts +3 -1
- package/dist/types/mcp/navigator-chat.d.ts +66 -0
- package/dist/types/mcp/navigator-mcp-websocket.d.ts +56 -0
- package/package.json +3 -3
package/dist/bruce-models.umd.js
CHANGED
|
@@ -16155,8 +16155,280 @@
|
|
|
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
|
+
/**
|
|
16281
|
+
* Minimal MCP WebSocket transport that handles tool call dispatching.
|
|
16282
|
+
* UI layers can provide their own tool handler while reusing this
|
|
16283
|
+
* connection management logic.
|
|
16284
|
+
*/
|
|
16285
|
+
class NavigatorMcpWebSocketClient {
|
|
16286
|
+
constructor(toolHandler, options = {}) {
|
|
16287
|
+
this.ws = null;
|
|
16288
|
+
this.isConnecting = false;
|
|
16289
|
+
this.toolHandler = toolHandler;
|
|
16290
|
+
this.options = options;
|
|
16291
|
+
this.currentAuth = options.auth;
|
|
16292
|
+
if (options.autoConnect) {
|
|
16293
|
+
this.connect();
|
|
16294
|
+
}
|
|
16295
|
+
}
|
|
16296
|
+
connect(auth) {
|
|
16297
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
16298
|
+
if (auth) {
|
|
16299
|
+
this.currentAuth = auth;
|
|
16300
|
+
}
|
|
16301
|
+
if (this.isConnecting || ((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN) {
|
|
16302
|
+
(_c = (_b = this.logger()).debug) === null || _c === void 0 ? void 0 : _c.call(_b, "[NavigatorMcpWS] Connection already active or in-flight; skipping connect.");
|
|
16303
|
+
return;
|
|
16304
|
+
}
|
|
16305
|
+
if (!((_d = this.currentAuth) === null || _d === void 0 ? void 0 : _d.accountId) || !((_e = this.currentAuth) === null || _e === void 0 ? void 0 : _e.sessionId)) {
|
|
16306
|
+
(_g = (_f = this.logger()).debug) === null || _g === void 0 ? void 0 : _g.call(_f, "[NavigatorMcpWS] Missing auth parameters; connection not started.");
|
|
16307
|
+
return;
|
|
16308
|
+
}
|
|
16309
|
+
try {
|
|
16310
|
+
this.isConnecting = true;
|
|
16311
|
+
const url = this.buildUrl();
|
|
16312
|
+
(_j = (_h = this.logger()).log) === null || _j === void 0 ? void 0 : _j.call(_h, "[NavigatorMcpWS] Connecting to", url);
|
|
16313
|
+
this.ws = new WebSocket(url);
|
|
16314
|
+
this.ws.onopen = (event) => {
|
|
16315
|
+
var _a, _b, _c, _d;
|
|
16316
|
+
(_b = (_a = this.logger()).log) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Connected");
|
|
16317
|
+
this.isConnecting = false;
|
|
16318
|
+
this.send({ method: "server_ready" });
|
|
16319
|
+
(_d = (_c = this.options).onOpen) === null || _d === void 0 ? void 0 : _d.call(_c, event);
|
|
16320
|
+
};
|
|
16321
|
+
this.ws.onmessage = (event) => {
|
|
16322
|
+
this.handleMessage(event.data);
|
|
16323
|
+
};
|
|
16324
|
+
this.ws.onerror = (event) => {
|
|
16325
|
+
var _a, _b, _c, _d;
|
|
16326
|
+
(_b = (_a = this.logger()).error) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Error", event);
|
|
16327
|
+
(_d = (_c = this.options).onError) === null || _d === void 0 ? void 0 : _d.call(_c, event);
|
|
16328
|
+
this.isConnecting = false;
|
|
16329
|
+
};
|
|
16330
|
+
this.ws.onclose = (event) => {
|
|
16331
|
+
var _a, _b, _c, _d;
|
|
16332
|
+
(_b = (_a = this.logger()).log) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Disconnected");
|
|
16333
|
+
this.ws = null;
|
|
16334
|
+
this.isConnecting = false;
|
|
16335
|
+
(_d = (_c = this.options).onClose) === null || _d === void 0 ? void 0 : _d.call(_c, event);
|
|
16336
|
+
};
|
|
16337
|
+
}
|
|
16338
|
+
catch (error) {
|
|
16339
|
+
(_l = (_k = this.logger()).error) === null || _l === void 0 ? void 0 : _l.call(_k, "[NavigatorMcpWS] Failed to establish connection", error);
|
|
16340
|
+
this.isConnecting = false;
|
|
16341
|
+
}
|
|
16342
|
+
}
|
|
16343
|
+
disconnect() {
|
|
16344
|
+
var _a, _b;
|
|
16345
|
+
if (this.ws) {
|
|
16346
|
+
(_b = (_a = this.logger()).debug) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Closing connection");
|
|
16347
|
+
this.ws.close();
|
|
16348
|
+
this.ws = null;
|
|
16349
|
+
this.isConnecting = false;
|
|
16350
|
+
}
|
|
16351
|
+
}
|
|
16352
|
+
isConnected() {
|
|
16353
|
+
var _a;
|
|
16354
|
+
return ((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN;
|
|
16355
|
+
}
|
|
16356
|
+
/**
|
|
16357
|
+
* Update the stored authentication parameters without reconnecting.
|
|
16358
|
+
* Call connect() afterwards to establish a connection with the new auth.
|
|
16359
|
+
*/
|
|
16360
|
+
setAuth(auth) {
|
|
16361
|
+
this.currentAuth = auth;
|
|
16362
|
+
}
|
|
16363
|
+
logger() {
|
|
16364
|
+
var _a;
|
|
16365
|
+
return (_a = this.options.logger) !== null && _a !== void 0 ? _a : console;
|
|
16366
|
+
}
|
|
16367
|
+
buildUrl() {
|
|
16368
|
+
var _a;
|
|
16369
|
+
const url = (_a = this.options.url) !== null && _a !== void 0 ? _a : "ws://localhost:8081/ws";
|
|
16370
|
+
return this.appendAuthParams(url);
|
|
16371
|
+
}
|
|
16372
|
+
appendAuthParams(url) {
|
|
16373
|
+
var _a, _b;
|
|
16374
|
+
if (!((_a = this.currentAuth) === null || _a === void 0 ? void 0 : _a.accountId) || !((_b = this.currentAuth) === null || _b === void 0 ? void 0 : _b.sessionId)) {
|
|
16375
|
+
return url;
|
|
16376
|
+
}
|
|
16377
|
+
const urlInstance = new URL(url);
|
|
16378
|
+
urlInstance.searchParams.set("accountId", this.currentAuth.accountId);
|
|
16379
|
+
urlInstance.searchParams.set("sessionId", this.currentAuth.sessionId);
|
|
16380
|
+
// Preserve the hash (unlikely to be used, but consistent with URL semantics)
|
|
16381
|
+
return urlInstance.toString();
|
|
16382
|
+
}
|
|
16383
|
+
handleMessage(raw) {
|
|
16384
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
16385
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16386
|
+
try {
|
|
16387
|
+
const message = typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
16388
|
+
const method = message === null || message === void 0 ? void 0 : message.method;
|
|
16389
|
+
if (method !== "tools/call") {
|
|
16390
|
+
(_b = (_a = this.logger()).debug) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Ignoring non tool-call message", message);
|
|
16391
|
+
return;
|
|
16392
|
+
}
|
|
16393
|
+
const toolName = (_c = message === null || message === void 0 ? void 0 : message.params) === null || _c === void 0 ? void 0 : _c.name;
|
|
16394
|
+
const toolArgs = (_d = message === null || message === void 0 ? void 0 : message.params) === null || _d === void 0 ? void 0 : _d.arguments;
|
|
16395
|
+
const messageId = message === null || message === void 0 ? void 0 : message.id;
|
|
16396
|
+
if (!toolName) {
|
|
16397
|
+
(_f = (_e = this.logger()).warn) === null || _f === void 0 ? void 0 : _f.call(_e, "[NavigatorMcpWS] Received tool call without name", message);
|
|
16398
|
+
return;
|
|
16399
|
+
}
|
|
16400
|
+
let result;
|
|
16401
|
+
try {
|
|
16402
|
+
result = yield this.toolHandler({
|
|
16403
|
+
name: toolName,
|
|
16404
|
+
args: toolArgs,
|
|
16405
|
+
messageId
|
|
16406
|
+
});
|
|
16407
|
+
}
|
|
16408
|
+
catch (error) {
|
|
16409
|
+
(_h = (_g = this.logger()).error) === null || _h === void 0 ? void 0 : _h.call(_g, "[NavigatorMcpWS] Tool handler threw", error);
|
|
16410
|
+
result = `Error: ${error instanceof Error ? error.message : String(error)}`;
|
|
16411
|
+
}
|
|
16412
|
+
this.send({
|
|
16413
|
+
method: "tool_response",
|
|
16414
|
+
id: messageId,
|
|
16415
|
+
result
|
|
16416
|
+
});
|
|
16417
|
+
}
|
|
16418
|
+
catch (error) {
|
|
16419
|
+
(_k = (_j = this.logger()).error) === null || _k === void 0 ? void 0 : _k.call(_j, "[NavigatorMcpWS] Invalid message", error);
|
|
16420
|
+
}
|
|
16421
|
+
});
|
|
16422
|
+
}
|
|
16423
|
+
send(message) {
|
|
16424
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
16425
|
+
this.ws.send(JSON.stringify(message));
|
|
16426
|
+
}
|
|
16427
|
+
}
|
|
16428
|
+
}
|
|
16429
|
+
|
|
16158
16430
|
// This is updated with the package.json version on build.
|
|
16159
|
-
const VERSION = "6.8.
|
|
16431
|
+
const VERSION = "6.8.4";
|
|
16160
16432
|
|
|
16161
16433
|
exports.VERSION = VERSION;
|
|
16162
16434
|
exports.AbstractApi = AbstractApi;
|
|
@@ -16165,6 +16437,8 @@
|
|
|
16165
16437
|
exports.CacheControl = CacheControl;
|
|
16166
16438
|
exports.DelayQueue = DelayQueue;
|
|
16167
16439
|
exports.LRUCache = LRUCache;
|
|
16440
|
+
exports.NavigatorChatClient = NavigatorChatClient;
|
|
16441
|
+
exports.NavigatorMcpWebSocketClient = NavigatorMcpWebSocketClient;
|
|
16168
16442
|
|
|
16169
16443
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
16170
16444
|
|