maplibre-gl-geoagent 0.4.1 → 0.4.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.
Files changed (35) hide show
  1. package/README.md +19 -0
  2. package/dist/{GeoAgentControl-CfSj1n01.js → GeoAgentControl-D02UP5lT.js} +83 -42
  3. package/dist/{GeoAgentControl-CfSj1n01.js.map → GeoAgentControl-D02UP5lT.js.map} +1 -1
  4. package/dist/{GeoAgentControl-Cc0HuUPf.cjs → GeoAgentControl-wFkbhvbu.cjs} +83 -42
  5. package/dist/{GeoAgentControl-Cc0HuUPf.cjs.map → GeoAgentControl-wFkbhvbu.cjs.map} +1 -1
  6. package/dist/{anthropic-BVBhgJNP.js → anthropic-CqhQTvtC.js} +2 -2
  7. package/dist/{anthropic-BVBhgJNP.js.map → anthropic-CqhQTvtC.js.map} +1 -1
  8. package/dist/{anthropic-BfFYVXzE.cjs → anthropic-S2hd2NQm.cjs} +2 -2
  9. package/dist/{anthropic-BfFYVXzE.cjs.map → anthropic-S2hd2NQm.cjs.map} +1 -1
  10. package/dist/{browser-D437ICBx.js → browser-DT7siLDs.js} +2 -2
  11. package/dist/{browser-D437ICBx.js.map → browser-DT7siLDs.js.map} +1 -1
  12. package/dist/{browser-BtMWNaZj.cjs → browser-wX4BKxTA.cjs} +2 -2
  13. package/dist/{browser-BtMWNaZj.cjs.map → browser-wX4BKxTA.cjs.map} +1 -1
  14. package/dist/{index-DGr_aIvw.cjs → index-9Vl-_b39.cjs} +2 -2
  15. package/dist/{index-DGr_aIvw.cjs.map → index-9Vl-_b39.cjs.map} +1 -1
  16. package/dist/{index-DaOfppi1.cjs → index-B70XIdgV.cjs} +2 -2
  17. package/dist/{index-DaOfppi1.cjs.map → index-B70XIdgV.cjs.map} +1 -1
  18. package/dist/{index-D0hzZEUn.js → index-CvWJMktS.js} +2 -2
  19. package/dist/{index-D0hzZEUn.js.map → index-CvWJMktS.js.map} +1 -1
  20. package/dist/{index-CVvcPs8z.js → index-ITGaM0CV.js} +2 -2
  21. package/dist/{index-CVvcPs8z.js.map → index-ITGaM0CV.js.map} +1 -1
  22. package/dist/{index-DumDV1aY.cjs → index-R5s1nbgn.cjs} +2 -2
  23. package/dist/{index-DumDV1aY.cjs.map → index-R5s1nbgn.cjs.map} +1 -1
  24. package/dist/{index-CeL5qxhv.js → index-_-KavWih.js} +2 -2
  25. package/dist/{index-CeL5qxhv.js.map → index-_-KavWih.js.map} +1 -1
  26. package/dist/index.cjs +1 -1
  27. package/dist/index.mjs +1 -1
  28. package/dist/maplibre-gl-geoagent.css +46 -22
  29. package/dist/react.cjs +1 -1
  30. package/dist/react.mjs +1 -1
  31. package/dist/types/lib/core/GeoAgentControl.d.ts +2 -1
  32. package/dist/types/lib/core/GeoAgentControl.d.ts.map +1 -1
  33. package/dist/types/lib/core/types.d.ts +24 -0
  34. package/dist/types/lib/core/types.d.ts.map +1 -1
  35. package/package.json +1 -1
package/README.md CHANGED
@@ -131,6 +131,7 @@ Converse model ID, and set the AWS region. The default Bedrock model is
131
131
  | `defaultProvider` | `GeoAgentProviderId` | `'openai-responses'` |
132
132
  | `defaultModel` | `string \| Partial<Record<GeoAgentProviderId, string>>` | provider default |
133
133
  | `storagePrefix` | `string` | `'geoagent.maplibre'` |
134
+ | `apiKeys` | `Partial<Record<GeoAgentProviderId, string>>` | `undefined` |
134
135
  | `allowCodeExecutionDefault` | `boolean` | `true` |
135
136
  | `allowDestructiveToolsDefault` | `boolean` | `true` |
136
137
  | `showPermissionToggles` | `boolean` | `false` |
@@ -183,6 +184,24 @@ are sent directly from the page to the selected model provider. Use this for
183
184
  local development, trusted internal apps, or apps that intentionally expose a
184
185
  browser-compatible credential path.
185
186
 
187
+ Host applications can prefill the panel with initial API keys:
188
+
189
+ ```typescript
190
+ new GeoAgentControl({
191
+ apiKeys: {
192
+ "openai-responses": "OPENAI_API_KEY_VALUE",
193
+ "openai-chat": "OPENAI_API_KEY_VALUE",
194
+ anthropic: "ANTHROPIC_API_KEY_VALUE",
195
+ google: "GOOGLE_API_KEY_VALUE",
196
+ bedrock: "AWS_BEARER_TOKEN_BEDROCK_VALUE",
197
+ },
198
+ });
199
+ ```
200
+
201
+ Saved `sessionStorage` values take precedence over `apiKeys`. Initial keys are
202
+ kept in browser memory and are not written to storage unless the user edits the
203
+ API key field.
204
+
186
205
  For Amazon Bedrock, this browser-only control uses Bedrock API-key bearer-token
187
206
  authentication. Do not enter AWS access key IDs, secret access keys, or session
188
207
  tokens in this UI. For production Bedrock deployments, prefer a backend proxy
@@ -3518,7 +3518,7 @@ class HttpProtocol extends SerdeContext {
3518
3518
  });
3519
3519
  }
3520
3520
  async loadEventStreamCapability() {
3521
- const { EventStreamSerde } = await import("./index-CVvcPs8z.js");
3521
+ const { EventStreamSerde } = await import("./index-ITGaM0CV.js");
3522
3522
  return new EventStreamSerde({
3523
3523
  marshaller: this.getEventStreamMarshaller(),
3524
3524
  serializer: this.serializer,
@@ -42664,7 +42664,7 @@ class EarthEngineService {
42664
42664
  }
42665
42665
  async loadEe() {
42666
42666
  if (!this.eePromise) {
42667
- this.eePromise = import("./browser-D437ICBx.js").then((n) => n.b).then((module) => {
42667
+ this.eePromise = import("./browser-DT7siLDs.js").then((n) => n.b).then((module) => {
42668
42668
  const imported = "default" in module ? module.default : module;
42669
42669
  const ee = imported;
42670
42670
  const scope2 = globalThis;
@@ -46024,7 +46024,6 @@ class GeoAgentControl {
46024
46024
  __publicField(this, "eventHandlers", new globalThis.Map());
46025
46025
  __publicField(this, "resizeHandler", null);
46026
46026
  __publicField(this, "mapResizeHandler", null);
46027
- __publicField(this, "clickOutsideHandler", null);
46028
46027
  __publicField(this, "panelResizeMoveHandler", null);
46029
46028
  __publicField(this, "panelResizeUpHandler", null);
46030
46029
  __publicField(this, "activeAbortController", null);
@@ -46036,6 +46035,9 @@ class GeoAgentControl {
46036
46035
  panelWidth: options.panelWidth ?? 390,
46037
46036
  panelMinWidth: options.panelMinWidth ?? 320,
46038
46037
  panelMaxWidth: options.panelMaxWidth ?? 720,
46038
+ panelHeight: options.panelHeight,
46039
+ panelMinHeight: options.panelMinHeight ?? 320,
46040
+ panelMaxHeight: options.panelMaxHeight ?? 2e3,
46039
46041
  className: options.className ?? "",
46040
46042
  defaultProvider: options.defaultProvider ?? DEFAULT_PROVIDER,
46041
46043
  storagePrefix: options.storagePrefix ?? DEFAULT_STORAGE_PREFIX,
@@ -46043,6 +46045,7 @@ class GeoAgentControl {
46043
46045
  allowDestructiveToolsDefault: options.allowDestructiveToolsDefault ?? true,
46044
46046
  showPermissionToggles: options.showPermissionToggles ?? false,
46045
46047
  defaultModel: options.defaultModel,
46048
+ apiKeys: options.apiKeys,
46046
46049
  basemaps: options.basemaps,
46047
46050
  earthEngine: options.earthEngine
46048
46051
  };
@@ -46050,6 +46053,7 @@ class GeoAgentControl {
46050
46053
  this.state = {
46051
46054
  collapsed: this.options.collapsed,
46052
46055
  panelWidth: this.constrainPanelWidth(this.options.panelWidth),
46056
+ panelHeight: this.options.panelHeight !== void 0 ? this.constrainPanelHeight(this.options.panelHeight) : void 0,
46053
46057
  busy: false,
46054
46058
  providerId,
46055
46059
  modelId: this.initialModelId(providerId),
@@ -46097,10 +46101,6 @@ class GeoAgentControl {
46097
46101
  this.map.off("resize", this.mapResizeHandler);
46098
46102
  this.mapResizeHandler = null;
46099
46103
  }
46100
- if (this.clickOutsideHandler) {
46101
- document.removeEventListener("click", this.clickOutsideHandler);
46102
- this.clickOutsideHandler = null;
46103
- }
46104
46104
  this.stopPanelResize();
46105
46105
  (_a3 = this.activeAbortController) == null ? void 0 : _a3.abort();
46106
46106
  (_b3 = this.agent) == null ? void 0 : _b3.cancel();
@@ -46140,6 +46140,11 @@ class GeoAgentControl {
46140
46140
  this.state.panelWidth = panelWidth;
46141
46141
  this.panel.style.width = `${panelWidth}px`;
46142
46142
  }
46143
+ if (newState.panelHeight !== void 0 && this.panel) {
46144
+ const panelHeight = this.constrainPanelHeight(newState.panelHeight);
46145
+ this.state.panelHeight = panelHeight;
46146
+ this.panel.style.height = `${panelHeight}px`;
46147
+ }
46143
46148
  if (collapsedChanged) {
46144
46149
  if (this.state.collapsed) {
46145
46150
  (_a3 = this.panel) == null ? void 0 : _a3.classList.remove("expanded");
@@ -46265,6 +46270,9 @@ class GeoAgentControl {
46265
46270
  const panel = document.createElement("div");
46266
46271
  panel.className = "geoagent-panel";
46267
46272
  panel.style.width = `${this.state.panelWidth}px`;
46273
+ if (this.state.panelHeight !== void 0) {
46274
+ panel.style.height = `${this.state.panelHeight}px`;
46275
+ }
46268
46276
  const header = document.createElement("div");
46269
46277
  header.className = "geoagent-panel-header";
46270
46278
  const title2 = document.createElement("span");
@@ -46278,11 +46286,12 @@ class GeoAgentControl {
46278
46286
  const closeButton = document.createElement("button");
46279
46287
  closeButton.className = "geoagent-icon-button";
46280
46288
  closeButton.type = "button";
46281
- closeButton.title = "Collapse panel";
46282
- closeButton.setAttribute("aria-label", "Collapse panel");
46289
+ closeButton.title = "Close";
46290
+ closeButton.setAttribute("aria-label", "Close");
46283
46291
  closeButton.innerHTML = `
46284
46292
  <svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
46285
- <path d="m18 15-6-6-6 6"></path>
46293
+ <path d="M18 6 6 18"></path>
46294
+ <path d="m6 6 12 12"></path>
46286
46295
  </svg>
46287
46296
  `;
46288
46297
  closeButton.addEventListener("click", () => this.collapse());
@@ -46348,13 +46357,9 @@ class GeoAgentControl {
46348
46357
  </div>
46349
46358
  </form>
46350
46359
  `;
46351
- const resizeHandle = document.createElement("div");
46352
- resizeHandle.className = "geoagent-panel-resize-handle";
46353
- resizeHandle.setAttribute("role", "separator");
46354
- resizeHandle.setAttribute("aria-orientation", "vertical");
46355
- resizeHandle.setAttribute("aria-label", "Resize GeoAgent panel");
46356
- resizeHandle.addEventListener("mousedown", (event) => this.startPanelResize(event));
46357
- panel.append(header, content, resizeHandle);
46360
+ const resizeHandleLeft = this.createResizeHandle("bottom-left");
46361
+ const resizeHandleRight = this.createResizeHandle("bottom-right");
46362
+ panel.append(header, content, resizeHandleLeft, resizeHandleRight);
46358
46363
  this.ui = {
46359
46364
  status,
46360
46365
  providerSelect: this.requiredElement(content, ".geoagent-provider"),
@@ -46377,7 +46382,8 @@ class GeoAgentControl {
46377
46382
  cancelButton: this.requiredElement(content, ".geoagent-cancel"),
46378
46383
  clearButton: this.requiredElement(content, ".geoagent-clear"),
46379
46384
  copyButton: this.requiredElement(content, ".geoagent-copy"),
46380
- resizeHandle,
46385
+ resizeHandleLeft,
46386
+ resizeHandleRight,
46381
46387
  closeButton
46382
46388
  };
46383
46389
  this.ui.permissionRow.hidden = !this.options.showPermissionToggles;
@@ -46574,13 +46580,6 @@ class GeoAgentControl {
46574
46580
  }
46575
46581
  setupEventListeners() {
46576
46582
  var _a3;
46577
- this.clickOutsideHandler = (event) => {
46578
- const target = event.target;
46579
- if (this.container && this.panel && !this.container.contains(target) && !this.panel.contains(target)) {
46580
- this.collapse();
46581
- }
46582
- };
46583
- document.addEventListener("click", this.clickOutsideHandler);
46584
46583
  this.resizeHandler = () => {
46585
46584
  if (!this.state.collapsed) {
46586
46585
  this.updatePanelPosition();
@@ -46653,23 +46652,67 @@ class GeoAgentControl {
46653
46652
  Math.min(this.options.panelMaxWidth, Math.round(width))
46654
46653
  );
46655
46654
  }
46656
- startPanelResize(event) {
46657
- if (!this.panel) {
46655
+ constrainPanelHeight(height) {
46656
+ var _a3;
46657
+ let max = this.options.panelMaxHeight;
46658
+ const mapHeight = ((_a3 = this.mapContainer) == null ? void 0 : _a3.clientHeight) ?? 0;
46659
+ if (mapHeight > 0) {
46660
+ max = Math.min(max, mapHeight - 20);
46661
+ }
46662
+ return Math.max(
46663
+ this.options.panelMinHeight,
46664
+ Math.min(max, Math.round(height))
46665
+ );
46666
+ }
46667
+ createResizeHandle(corner) {
46668
+ const handle = document.createElement("div");
46669
+ const side = corner === "bottom-left" ? "bl" : "br";
46670
+ handle.className = `geoagent-panel-resize-handle geoagent-panel-resize-handle-${side}`;
46671
+ handle.setAttribute("role", "separator");
46672
+ handle.setAttribute("aria-label", "Resize GeoAgent panel");
46673
+ handle.addEventListener("mousedown", (event) => this.startPanelResize(event, corner));
46674
+ return handle;
46675
+ }
46676
+ startPanelResize(event, corner) {
46677
+ if (!this.panel || !this.mapContainer) {
46658
46678
  return;
46659
46679
  }
46660
46680
  event.preventDefault();
46661
46681
  event.stopPropagation();
46662
- const position = this.getControlPosition();
46663
- const resizeDirection = position === "top-left" || position === "bottom-left" ? 1 : -1;
46664
- const startX = event.clientX;
46665
- const startWidth = this.panel.getBoundingClientRect().width || this.state.panelWidth;
46666
46682
  this.stopPanelResize();
46683
+ const panelRect = this.panel.getBoundingClientRect();
46684
+ const mapRect = this.mapContainer.getBoundingClientRect();
46685
+ this.panel.style.top = `${panelRect.top - mapRect.top}px`;
46686
+ this.panel.style.bottom = "";
46687
+ if (corner === "bottom-left") {
46688
+ this.panel.style.right = `${mapRect.right - panelRect.right}px`;
46689
+ this.panel.style.left = "";
46690
+ } else {
46691
+ this.panel.style.left = `${panelRect.left - mapRect.left}px`;
46692
+ this.panel.style.right = "";
46693
+ }
46694
+ const startX = event.clientX;
46695
+ const startY = event.clientY;
46696
+ const startWidth = panelRect.width || this.state.panelWidth;
46697
+ const startHeight = panelRect.height || this.state.panelHeight || this.options.panelMinHeight;
46698
+ const widthDirection = corner === "bottom-left" ? -1 : 1;
46699
+ const gap = 8;
46700
+ const hasLayout = mapRect.width > 0 && mapRect.height > 0;
46701
+ const maxWidth = !hasLayout ? Number.POSITIVE_INFINITY : corner === "bottom-left" ? panelRect.right - mapRect.left - gap : mapRect.right - panelRect.left - gap;
46702
+ const maxHeight = !hasLayout ? Number.POSITIVE_INFINITY : mapRect.bottom - panelRect.top - gap;
46667
46703
  this.panel.classList.add("resizing");
46668
46704
  document.body.classList.add("geoagent-panel-resizing");
46669
46705
  this.panelResizeMoveHandler = (moveEvent) => {
46670
46706
  moveEvent.preventDefault();
46671
- const nextWidth = startWidth + (moveEvent.clientX - startX) * resizeDirection;
46672
- this.setState({ panelWidth: nextWidth });
46707
+ const width = Math.min(
46708
+ maxWidth,
46709
+ startWidth + (moveEvent.clientX - startX) * widthDirection
46710
+ );
46711
+ const height = Math.min(
46712
+ maxHeight,
46713
+ startHeight + (moveEvent.clientY - startY)
46714
+ );
46715
+ this.setState({ panelWidth: width, panelHeight: height });
46673
46716
  };
46674
46717
  this.panelResizeUpHandler = () => this.stopPanelResize();
46675
46718
  document.addEventListener("mousemove", this.panelResizeMoveHandler);
@@ -46700,7 +46743,6 @@ class GeoAgentControl {
46700
46743
  this.ui.bedrockRegionLabel.hidden = this.state.providerId !== "bedrock";
46701
46744
  this.ui.allowCodeInput.checked = this.state.allowCodeExecution;
46702
46745
  this.ui.allowDestructiveInput.checked = this.state.allowDestructiveTools;
46703
- this.ui.closeButton.setAttribute("aria-expanded", String(!this.state.collapsed));
46704
46746
  }
46705
46747
  currentProviderId() {
46706
46748
  var _a3;
@@ -46711,16 +46753,18 @@ class GeoAgentControl {
46711
46753
  return this.providerConfig(this.currentProviderId());
46712
46754
  }
46713
46755
  loadProviderSettings() {
46756
+ var _a3, _b3;
46714
46757
  if (!this.ui) {
46715
46758
  return;
46716
46759
  }
46717
46760
  const provider = this.currentProviderConfig();
46761
+ const initialApiKey = ((_b3 = (_a3 = this.options.apiKeys) == null ? void 0 : _a3[provider.id]) == null ? void 0 : _b3.trim()) ?? "";
46718
46762
  this.state.providerId = provider.id;
46719
46763
  this.state.modelId = storageGet(this.modelStorageKey(provider.id)) || provider.defaultModel;
46720
46764
  this.ui.providerSelect.value = provider.id;
46721
46765
  this.ui.apiKeyLabel.textContent = provider.keyLabel;
46722
46766
  this.ui.apiKeyInput.placeholder = provider.keyPlaceholder;
46723
- this.ui.apiKeyInput.value = storageGet(provider.storageKey) || "";
46767
+ this.ui.apiKeyInput.value = storageGet(provider.storageKey) || initialApiKey;
46724
46768
  this.ui.modelIdInput.value = this.state.modelId;
46725
46769
  this.ui.modelIdInput.placeholder = provider.defaultModel;
46726
46770
  this.state.bedrockRegion = this.initialBedrockRegion();
@@ -46841,7 +46885,7 @@ ${markdown.trim()}`;
46841
46885
  }
46842
46886
  async createProviderModel(providerId, modelId, apiKey, bedrockRegion) {
46843
46887
  if (providerId === "openai-responses" || providerId === "openai-chat") {
46844
- const { OpenAIModel } = await import("./index-CeL5qxhv.js");
46888
+ const { OpenAIModel } = await import("./index-_-KavWih.js");
46845
46889
  return new OpenAIModel({
46846
46890
  api: providerId === "openai-responses" ? "responses" : "chat",
46847
46891
  modelId,
@@ -46852,7 +46896,7 @@ ${markdown.trim()}`;
46852
46896
  });
46853
46897
  }
46854
46898
  if (providerId === "anthropic") {
46855
- const { AnthropicModel } = await import("./anthropic-BVBhgJNP.js");
46899
+ const { AnthropicModel } = await import("./anthropic-CqhQTvtC.js");
46856
46900
  return new AnthropicModel({
46857
46901
  modelId,
46858
46902
  apiKey,
@@ -46862,7 +46906,7 @@ ${markdown.trim()}`;
46862
46906
  });
46863
46907
  }
46864
46908
  if (providerId === "google") {
46865
- const { GoogleModel } = await import("./index-D0hzZEUn.js");
46909
+ const { GoogleModel } = await import("./index-CvWJMktS.js");
46866
46910
  return new GoogleModel({
46867
46911
  modelId,
46868
46912
  apiKey
@@ -47027,7 +47071,6 @@ ${BROWSER_MAPLIBRE_CODE_SYSTEM_PROMPT}` : BROWSER_MAPLIBRE_SYSTEM_PROMPT;
47027
47071
  const buttonRect = button.getBoundingClientRect();
47028
47072
  const mapRect = this.mapContainer.getBoundingClientRect();
47029
47073
  const position = this.getControlPosition();
47030
- const resizeOnLeft = position === "top-right" || position === "bottom-right";
47031
47074
  const buttonTop = buttonRect.top - mapRect.top;
47032
47075
  const buttonBottom = mapRect.bottom - buttonRect.bottom;
47033
47076
  const buttonLeft = buttonRect.left - mapRect.left;
@@ -47037,8 +47080,6 @@ ${BROWSER_MAPLIBRE_CODE_SYSTEM_PROMPT}` : BROWSER_MAPLIBRE_SYSTEM_PROMPT;
47037
47080
  this.panel.style.bottom = "";
47038
47081
  this.panel.style.left = "";
47039
47082
  this.panel.style.right = "";
47040
- this.panel.classList.toggle("resize-left", resizeOnLeft);
47041
- this.panel.classList.toggle("resize-right", !resizeOnLeft);
47042
47083
  switch (position) {
47043
47084
  case "top-left":
47044
47085
  this.panel.style.top = `${buttonTop + buttonRect.height + panelGap}px`;
@@ -47087,4 +47128,4 @@ export {
47087
47128
  toJsonValue as t,
47088
47129
  warnOnce as w
47089
47130
  };
47090
- //# sourceMappingURL=GeoAgentControl-CfSj1n01.js.map
47131
+ //# sourceMappingURL=GeoAgentControl-D02UP5lT.js.map