bruce-models 6.8.1 → 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.
@@ -8238,6 +8238,7 @@ var EntityCoords;
8238
8238
  "scale": params.scale || 1
8239
8239
  }
8240
8240
  },
8241
+ "correctHeading": params.correctHeading || false,
8241
8242
  "test": params.test
8242
8243
  }, reqParams);
8243
8244
  if (!params.test) {
@@ -16469,8 +16470,289 @@ var Tracking;
16469
16470
  Tracking.GetData = GetData;
16470
16471
  })(Tracking || (Tracking = {}));
16471
16472
 
16473
+ const DEFAULT_BASE_URL = "http://localhost:8888";
16474
+ /**
16475
+ * Lightweight client for the Navigator MCP chat HTTP endpoints.
16476
+ * Encapsulates header construction and error handling so UI layers
16477
+ * can focus on presentation logic.
16478
+ */
16479
+ class NavigatorChatClient {
16480
+ constructor(options = {}) {
16481
+ var _a, _b;
16482
+ this.baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : DEFAULT_BASE_URL;
16483
+ this.fetchImpl = options.fetchImpl;
16484
+ this.defaultHeaders = (_b = options.defaultHeaders) !== null && _b !== void 0 ? _b : {};
16485
+ }
16486
+ /**
16487
+ * Ask a question via the MCP chat endpoint.
16488
+ */
16489
+ ask(request, auth) {
16490
+ var _a, _b;
16491
+ return __awaiter(this, void 0, void 0, function* () {
16492
+ if (!request.question || !request.question.trim()) {
16493
+ throw new Error("NavigatorChatClient.ask requires a non-empty question.");
16494
+ }
16495
+ const response = yield this.fetchFromEndpoint("/chat", {
16496
+ method: "POST",
16497
+ body: JSON.stringify({
16498
+ question: request.question,
16499
+ context: request.context,
16500
+ history: request.history
16501
+ }),
16502
+ headers: {
16503
+ "Content-Type": "application/json"
16504
+ }
16505
+ }, auth);
16506
+ const data = yield this.parseJson(response);
16507
+ 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 : "";
16508
+ return {
16509
+ text,
16510
+ raw: data
16511
+ };
16512
+ });
16513
+ }
16514
+ /**
16515
+ * Clear chat history stored on the MCP server.
16516
+ */
16517
+ clear(auth) {
16518
+ return __awaiter(this, void 0, void 0, function* () {
16519
+ yield this.fetchFromEndpoint("/clear", {
16520
+ method: "POST",
16521
+ headers: {
16522
+ "Content-Type": "application/json"
16523
+ }
16524
+ }, auth);
16525
+ });
16526
+ }
16527
+ /**
16528
+ * Build a fully-qualified endpoint relative to the configured base URL.
16529
+ */
16530
+ buildUrl(path) {
16531
+ if (path.startsWith("http://") || path.startsWith("https://")) {
16532
+ return path;
16533
+ }
16534
+ if (!path.startsWith("/")) {
16535
+ path = `/${path}`;
16536
+ }
16537
+ return `${this.baseUrl}${path}`;
16538
+ }
16539
+ fetchFromEndpoint(path, init, auth) {
16540
+ var _a;
16541
+ return __awaiter(this, void 0, void 0, function* () {
16542
+ const fetchImpl = this.resolveFetch();
16543
+ const headers = Object.assign(Object.assign({}, this.defaultHeaders), ((_a = init.headers) !== null && _a !== void 0 ? _a : {}));
16544
+ if (auth === null || auth === void 0 ? void 0 : auth.accountId) {
16545
+ headers["X-Account-Id"] = auth.accountId;
16546
+ }
16547
+ if (auth === null || auth === void 0 ? void 0 : auth.sessionId) {
16548
+ headers["X-Session-Id"] = auth.sessionId;
16549
+ }
16550
+ const response = yield fetchImpl(this.buildUrl(path), Object.assign(Object.assign({}, init), { headers }));
16551
+ if (!response.ok) {
16552
+ const message = yield this.safeReadResponseText(response);
16553
+ throw new Error(`Navigator chat request failed (${response.status} ${response.statusText}): ${message}`);
16554
+ }
16555
+ return response;
16556
+ });
16557
+ }
16558
+ resolveFetch() {
16559
+ if (this.fetchImpl) {
16560
+ return this.fetchImpl;
16561
+ }
16562
+ if (typeof fetch !== "undefined") {
16563
+ return fetch;
16564
+ }
16565
+ // Lazy-load isomorphic-fetch for environments without a native fetch.
16566
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
16567
+ const isomorphicFetch = require("isomorphic-fetch");
16568
+ if (typeof isomorphicFetch !== "function") {
16569
+ throw new Error("isomorphic-fetch did not return a fetch implementation.");
16570
+ }
16571
+ return isomorphicFetch;
16572
+ }
16573
+ parseJson(response) {
16574
+ return __awaiter(this, void 0, void 0, function* () {
16575
+ try {
16576
+ return yield response.json();
16577
+ }
16578
+ catch (_a) {
16579
+ return {};
16580
+ }
16581
+ });
16582
+ }
16583
+ safeReadResponseText(response) {
16584
+ return __awaiter(this, void 0, void 0, function* () {
16585
+ try {
16586
+ return yield response.text();
16587
+ }
16588
+ catch (_a) {
16589
+ return "";
16590
+ }
16591
+ });
16592
+ }
16593
+ }
16594
+
16595
+ const DEFAULT_PORT = 8081;
16596
+ const DEFAULT_PATH = "/ws";
16597
+ /**
16598
+ * Minimal MCP WebSocket transport that handles tool call dispatching.
16599
+ * UI layers can provide their own tool handler while reusing this
16600
+ * connection management logic.
16601
+ */
16602
+ class NavigatorMcpWebSocketClient {
16603
+ constructor(toolHandler, options = {}) {
16604
+ this.ws = null;
16605
+ this.isConnecting = false;
16606
+ this.toolHandler = toolHandler;
16607
+ this.options = options;
16608
+ this.currentAuth = options.auth;
16609
+ if (options.autoConnect) {
16610
+ this.connect();
16611
+ }
16612
+ }
16613
+ connect(auth) {
16614
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
16615
+ if (auth) {
16616
+ this.currentAuth = auth;
16617
+ }
16618
+ if (this.isConnecting || ((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN) {
16619
+ (_c = (_b = this.logger()).debug) === null || _c === void 0 ? void 0 : _c.call(_b, "[NavigatorMcpWS] Connection already active or in-flight; skipping connect.");
16620
+ return;
16621
+ }
16622
+ if (!((_d = this.currentAuth) === null || _d === void 0 ? void 0 : _d.accountId) || !((_e = this.currentAuth) === null || _e === void 0 ? void 0 : _e.sessionId)) {
16623
+ (_g = (_f = this.logger()).debug) === null || _g === void 0 ? void 0 : _g.call(_f, "[NavigatorMcpWS] Missing auth parameters; connection not started.");
16624
+ return;
16625
+ }
16626
+ try {
16627
+ this.isConnecting = true;
16628
+ const url = this.buildUrl();
16629
+ (_j = (_h = this.logger()).log) === null || _j === void 0 ? void 0 : _j.call(_h, "[NavigatorMcpWS] Connecting to", url);
16630
+ this.ws = new WebSocket(url);
16631
+ this.ws.onopen = (event) => {
16632
+ var _a, _b, _c, _d;
16633
+ (_b = (_a = this.logger()).log) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Connected");
16634
+ this.isConnecting = false;
16635
+ this.send({ method: "server_ready" });
16636
+ (_d = (_c = this.options).onOpen) === null || _d === void 0 ? void 0 : _d.call(_c, event);
16637
+ };
16638
+ this.ws.onmessage = (event) => {
16639
+ this.handleMessage(event.data);
16640
+ };
16641
+ this.ws.onerror = (event) => {
16642
+ var _a, _b, _c, _d;
16643
+ (_b = (_a = this.logger()).error) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Error", event);
16644
+ (_d = (_c = this.options).onError) === null || _d === void 0 ? void 0 : _d.call(_c, event);
16645
+ this.isConnecting = false;
16646
+ };
16647
+ this.ws.onclose = (event) => {
16648
+ var _a, _b, _c, _d;
16649
+ (_b = (_a = this.logger()).log) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Disconnected");
16650
+ this.ws = null;
16651
+ this.isConnecting = false;
16652
+ (_d = (_c = this.options).onClose) === null || _d === void 0 ? void 0 : _d.call(_c, event);
16653
+ };
16654
+ }
16655
+ catch (error) {
16656
+ (_l = (_k = this.logger()).error) === null || _l === void 0 ? void 0 : _l.call(_k, "[NavigatorMcpWS] Failed to establish connection", error);
16657
+ this.isConnecting = false;
16658
+ }
16659
+ }
16660
+ disconnect() {
16661
+ var _a, _b;
16662
+ if (this.ws) {
16663
+ (_b = (_a = this.logger()).debug) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Closing connection");
16664
+ this.ws.close();
16665
+ this.ws = null;
16666
+ this.isConnecting = false;
16667
+ }
16668
+ }
16669
+ isConnected() {
16670
+ var _a;
16671
+ return ((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN;
16672
+ }
16673
+ /**
16674
+ * Update the stored authentication parameters without reconnecting.
16675
+ * Call connect() afterwards to establish a connection with the new auth.
16676
+ */
16677
+ setAuth(auth) {
16678
+ this.currentAuth = auth;
16679
+ }
16680
+ logger() {
16681
+ var _a;
16682
+ return (_a = this.options.logger) !== null && _a !== void 0 ? _a : console;
16683
+ }
16684
+ buildUrl() {
16685
+ var _a, _b, _c, _d, _e;
16686
+ if (this.options.url) {
16687
+ return this.appendAuthParams(this.options.url);
16688
+ }
16689
+ const protocol = (_a = this.options.protocol) !== null && _a !== void 0 ? _a : "ws";
16690
+ const host = (_b = this.options.host) !== null && _b !== void 0 ? _b : "localhost";
16691
+ const port = (_c = this.options.port) !== null && _c !== void 0 ? _c : DEFAULT_PORT;
16692
+ 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}`;
16693
+ const baseUrl = `${protocol}://${host}:${port}${path}`;
16694
+ return this.appendAuthParams(baseUrl);
16695
+ }
16696
+ appendAuthParams(url) {
16697
+ var _a, _b;
16698
+ if (!((_a = this.currentAuth) === null || _a === void 0 ? void 0 : _a.accountId) || !((_b = this.currentAuth) === null || _b === void 0 ? void 0 : _b.sessionId)) {
16699
+ return url;
16700
+ }
16701
+ const urlInstance = new URL(url);
16702
+ urlInstance.searchParams.set("accountId", this.currentAuth.accountId);
16703
+ urlInstance.searchParams.set("sessionId", this.currentAuth.sessionId);
16704
+ // Preserve the hash (unlikely to be used, but consistent with URL semantics)
16705
+ return urlInstance.toString();
16706
+ }
16707
+ handleMessage(raw) {
16708
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
16709
+ return __awaiter(this, void 0, void 0, function* () {
16710
+ try {
16711
+ const message = typeof raw === "string" ? JSON.parse(raw) : raw;
16712
+ const method = message === null || message === void 0 ? void 0 : message.method;
16713
+ if (method !== "tools/call") {
16714
+ (_b = (_a = this.logger()).debug) === null || _b === void 0 ? void 0 : _b.call(_a, "[NavigatorMcpWS] Ignoring non tool-call message", message);
16715
+ return;
16716
+ }
16717
+ const toolName = (_c = message === null || message === void 0 ? void 0 : message.params) === null || _c === void 0 ? void 0 : _c.name;
16718
+ const toolArgs = (_d = message === null || message === void 0 ? void 0 : message.params) === null || _d === void 0 ? void 0 : _d.arguments;
16719
+ const messageId = message === null || message === void 0 ? void 0 : message.id;
16720
+ if (!toolName) {
16721
+ (_f = (_e = this.logger()).warn) === null || _f === void 0 ? void 0 : _f.call(_e, "[NavigatorMcpWS] Received tool call without name", message);
16722
+ return;
16723
+ }
16724
+ let result;
16725
+ try {
16726
+ result = yield this.toolHandler({
16727
+ name: toolName,
16728
+ args: toolArgs,
16729
+ messageId
16730
+ });
16731
+ }
16732
+ catch (error) {
16733
+ (_h = (_g = this.logger()).error) === null || _h === void 0 ? void 0 : _h.call(_g, "[NavigatorMcpWS] Tool handler threw", error);
16734
+ result = `Error: ${error instanceof Error ? error.message : String(error)}`;
16735
+ }
16736
+ this.send({
16737
+ method: "tool_response",
16738
+ id: messageId,
16739
+ result
16740
+ });
16741
+ }
16742
+ catch (error) {
16743
+ (_k = (_j = this.logger()).error) === null || _k === void 0 ? void 0 : _k.call(_j, "[NavigatorMcpWS] Invalid message", error);
16744
+ }
16745
+ });
16746
+ }
16747
+ send(message) {
16748
+ if (this.ws && this.ws.readyState === WebSocket.OPEN) {
16749
+ this.ws.send(JSON.stringify(message));
16750
+ }
16751
+ }
16752
+ }
16753
+
16472
16754
  // This is updated with the package.json version on build.
16473
- const VERSION = "6.8.1";
16755
+ const VERSION = "6.8.3";
16474
16756
 
16475
- export { VERSION, Assembly, AnnDocument, CustomForm, AbstractApi, Api, BruceApi, GlobalApi, GuardianApi, ApiGetters, Calculator, Bounds, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, BruceVariable, LRUCache, GeoJson, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityLodCategory, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityCoords, EntityAttribute, EntityHistoricData, EntityTableView, Comment, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, ProjectViewLegacy, ProjectViewLegacyBookmark, ProjectViewBookmarkGroup, PendingAction, MessageBroker, HostingLocation, Style, Tileset, Permission, Session, UserGroup, User, UserMfaMethod, Account, AccountInvite, AccountFeatures, AccountLimits, AccountTemplate, AccountType, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, DataLabGroup, ImportAssembly, ImportCad, ImportCsv, ImportJson, ImportGeoJson, ImportKml, ImportedFile, ExportBrz, ExportUsd, Markup, Uploader, Plugin, ENVIRONMENT, DataSource, Scenario, Tracking };
16757
+ export { VERSION, Assembly, AnnDocument, CustomForm, AbstractApi, Api, BruceApi, GlobalApi, GuardianApi, ApiGetters, Calculator, Bounds, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, BruceVariable, LRUCache, GeoJson, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityLodCategory, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityCoords, EntityAttribute, EntityHistoricData, EntityTableView, Comment, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, ProjectViewLegacy, ProjectViewLegacyBookmark, ProjectViewBookmarkGroup, PendingAction, MessageBroker, HostingLocation, Style, Tileset, Permission, Session, UserGroup, User, UserMfaMethod, Account, AccountInvite, AccountFeatures, AccountLimits, AccountTemplate, AccountType, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, DataLabGroup, ImportAssembly, ImportCad, ImportCsv, ImportJson, ImportGeoJson, ImportKml, ImportedFile, ExportBrz, ExportUsd, Markup, Uploader, Plugin, ENVIRONMENT, DataSource, Scenario, Tracking, NavigatorChatClient, NavigatorMcpWebSocketClient };
16476
16758
  //# sourceMappingURL=bruce-models.es5.js.map