maplibre-gl-geoagent 0.1.0

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 (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +189 -0
  3. package/dist/GeoAgentControl-CmfTQTkJ.cjs +47680 -0
  4. package/dist/GeoAgentControl-CmfTQTkJ.cjs.map +1 -0
  5. package/dist/GeoAgentControl-c10MBYNG.js +47681 -0
  6. package/dist/GeoAgentControl-c10MBYNG.js.map +1 -0
  7. package/dist/anthropic-C7kTy6A0.js +6505 -0
  8. package/dist/anthropic-C7kTy6A0.js.map +1 -0
  9. package/dist/anthropic-Y4byflsD.cjs +6505 -0
  10. package/dist/anthropic-Y4byflsD.cjs.map +1 -0
  11. package/dist/index-CX7FTecz.js +18878 -0
  12. package/dist/index-CX7FTecz.js.map +1 -0
  13. package/dist/index-CzhifCGI.cjs +254 -0
  14. package/dist/index-CzhifCGI.cjs.map +1 -0
  15. package/dist/index-DC2fUaFo.cjs +9727 -0
  16. package/dist/index-DC2fUaFo.cjs.map +1 -0
  17. package/dist/index-DRJ1yR1n.js +9727 -0
  18. package/dist/index-DRJ1yR1n.js.map +1 -0
  19. package/dist/index-Dta4g9Ff.js +254 -0
  20. package/dist/index-Dta4g9Ff.js.map +1 -0
  21. package/dist/index-m-aZEiVB.cjs +18878 -0
  22. package/dist/index-m-aZEiVB.cjs.map +1 -0
  23. package/dist/index.cjs +12 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.mjs +12 -0
  26. package/dist/index.mjs.map +1 -0
  27. package/dist/maplibre-gl-geoagent.css +1664 -0
  28. package/dist/react.cjs +94 -0
  29. package/dist/react.cjs.map +1 -0
  30. package/dist/react.mjs +94 -0
  31. package/dist/react.mjs.map +1 -0
  32. package/dist/types/index.d.ts +4 -0
  33. package/dist/types/index.d.ts.map +1 -0
  34. package/dist/types/lib/core/GeoAgentControl.d.ts +79 -0
  35. package/dist/types/lib/core/GeoAgentControl.d.ts.map +1 -0
  36. package/dist/types/lib/core/GeoAgentControlReact.d.ts +3 -0
  37. package/dist/types/lib/core/GeoAgentControlReact.d.ts.map +1 -0
  38. package/dist/types/lib/core/maplibre-tools.d.ts +66 -0
  39. package/dist/types/lib/core/maplibre-tools.d.ts.map +1 -0
  40. package/dist/types/lib/core/types.d.ts +101 -0
  41. package/dist/types/lib/core/types.d.ts.map +1 -0
  42. package/dist/types/lib/hooks/index.d.ts +2 -0
  43. package/dist/types/lib/hooks/index.d.ts.map +1 -0
  44. package/dist/types/lib/hooks/useGeoAgentState.d.ts +13 -0
  45. package/dist/types/lib/hooks/useGeoAgentState.d.ts.map +1 -0
  46. package/dist/types/lib/utils/helpers.d.ts +86 -0
  47. package/dist/types/lib/utils/helpers.d.ts.map +1 -0
  48. package/dist/types/lib/utils/index.d.ts +2 -0
  49. package/dist/types/lib/utils/index.d.ts.map +1 -0
  50. package/dist/types/react.d.ts +4 -0
  51. package/dist/types/react.d.ts.map +1 -0
  52. package/package.json +111 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Qiusheng Wu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,189 @@
1
+ # maplibre-gl-geoagent
2
+
3
+ A browser-only GeoAgent control for MapLibre GL JS. The control implements
4
+ MapLibre's `IControl` interface and embeds a Strands TypeScript agent that can
5
+ inspect and operate on the live map through dedicated browser tools.
6
+
7
+ ## Features
8
+
9
+ - Collapsible MapLibre control with a floating chat panel
10
+ - Browser provider UI for OpenAI Responses, OpenAI Chat, Anthropic, Google Gemini, and Amazon Bedrock
11
+ - Map tools for camera movement, projection, basemaps, markers, GeoJSON, XYZ tiles, layer visibility, opacity, feature queries, screenshots, and layer cleanup
12
+ - Optional MapLibre JavaScript execution tool, disabled by default
13
+ - Destructive layer removal tools gated behind a separate toggle
14
+ - Copy the visible conversation log as Markdown
15
+ - React wrapper and state hook
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install maplibre-gl-geoagent maplibre-gl
21
+ ```
22
+
23
+ ## Vanilla Usage
24
+
25
+ ```typescript
26
+ import maplibregl from "maplibre-gl";
27
+ import { GeoAgentControl } from "maplibre-gl-geoagent";
28
+ import "maplibre-gl/dist/maplibre-gl.css";
29
+ import "maplibre-gl-geoagent/style.css";
30
+
31
+ const map = new maplibregl.Map({
32
+ container: "map",
33
+ style: "https://tiles.openfreemap.org/styles/liberty",
34
+ center: [-98.5795, 39.8283],
35
+ zoom: 3,
36
+ maxPitch: 85,
37
+ canvasContextAttributes: { preserveDrawingBuffer: true },
38
+ });
39
+
40
+ map.on("load", () => {
41
+ map.addControl(
42
+ new GeoAgentControl({
43
+ title: "GeoAgent",
44
+ collapsed: false,
45
+ }),
46
+ "top-left",
47
+ );
48
+ });
49
+ ```
50
+
51
+ ## React Usage
52
+
53
+ ```tsx
54
+ import { useEffect, useRef, useState } from "react";
55
+ import maplibregl, { type Map } from "maplibre-gl";
56
+ import {
57
+ GeoAgentControlReact,
58
+ useGeoAgentState,
59
+ } from "maplibre-gl-geoagent/react";
60
+ import "maplibre-gl/dist/maplibre-gl.css";
61
+ import "maplibre-gl-geoagent/style.css";
62
+
63
+ function App() {
64
+ const mapContainer = useRef<HTMLDivElement>(null);
65
+ const [map, setMap] = useState<Map | null>(null);
66
+ const { state, setState } = useGeoAgentState({ collapsed: false });
67
+
68
+ useEffect(() => {
69
+ if (!mapContainer.current) return;
70
+
71
+ const mapInstance = new maplibregl.Map({
72
+ container: mapContainer.current,
73
+ style: "https://tiles.openfreemap.org/styles/liberty",
74
+ center: [-98.5795, 39.8283],
75
+ zoom: 3,
76
+ canvasContextAttributes: { preserveDrawingBuffer: true },
77
+ });
78
+
79
+ mapInstance.on("load", () => setMap(mapInstance));
80
+ return () => mapInstance.remove();
81
+ }, []);
82
+
83
+ return (
84
+ <>
85
+ <div ref={mapContainer} style={{ width: "100vw", height: "100vh" }} />
86
+ {map && (
87
+ <GeoAgentControlReact
88
+ map={map}
89
+ title="GeoAgent"
90
+ collapsed={state.collapsed}
91
+ position="top-left"
92
+ onStateChange={setState}
93
+ />
94
+ )}
95
+ </>
96
+ );
97
+ }
98
+ ```
99
+
100
+ ## Providers
101
+
102
+ Supported providers:
103
+
104
+ - OpenAI Responses
105
+ - OpenAI Chat
106
+ - Anthropic
107
+ - Google Gemini
108
+ - Amazon Bedrock
109
+
110
+ For Bedrock, select `Amazon Bedrock`, enter a Bedrock API key, choose a Bedrock
111
+ Converse model ID, and set the AWS region. The default Bedrock model is
112
+ `global.anthropic.claude-sonnet-4-6`, and the default region is `us-west-2`.
113
+
114
+ ## Options
115
+
116
+ | Option | Type | Default |
117
+ | --- | --- | --- |
118
+ | `collapsed` | `boolean` | `true` |
119
+ | `position` | `'top-left' \| 'top-right' \| 'bottom-left' \| 'bottom-right'` | `'top-right'` |
120
+ | `title` | `string` | `'GeoAgent'` |
121
+ | `panelWidth` | `number` | `390` |
122
+ | `panelMinWidth` | `number` | `320` |
123
+ | `panelMaxWidth` | `number` | `720` |
124
+ | `className` | `string` | `''` |
125
+ | `defaultProvider` | `GeoAgentProviderId` | `'openai-responses'` |
126
+ | `defaultModel` | `string \| Partial<Record<GeoAgentProviderId, string>>` | provider default |
127
+ | `storagePrefix` | `string` | `'geoagent.maplibre'` |
128
+ | `allowCodeExecutionDefault` | `boolean` | `true` |
129
+ | `allowDestructiveToolsDefault` | `boolean` | `true` |
130
+ | `showPermissionToggles` | `boolean` | `false` |
131
+ | `basemaps` | `Record<string, string \| StyleSpecification>` | built-in basemaps |
132
+
133
+ ## Browser Credentials
134
+
135
+ This package runs model SDKs directly in the browser. API keys entered in the
136
+ panel are stored in `sessionStorage` under the configured `storagePrefix` and
137
+ are sent directly from the page to the selected model provider. Use this for
138
+ local development, trusted internal apps, or apps that intentionally expose a
139
+ browser-compatible credential path.
140
+
141
+ For Amazon Bedrock, this browser-only control uses Bedrock API-key bearer-token
142
+ authentication. Do not enter AWS access key IDs, secret access keys, or session
143
+ tokens in this UI. For production Bedrock deployments, prefer a backend proxy
144
+ that calls Bedrock with IAM role credentials.
145
+
146
+ The MapLibre JavaScript tool and layer removal tools are enabled by default.
147
+ Their checkboxes are hidden by default; pass `showPermissionToggles: true` at
148
+ initialization time to let users turn them on or off in the panel. Disable either
149
+ capability at startup with `allowCodeExecutionDefault: false` or
150
+ `allowDestructiveToolsDefault: false`.
151
+
152
+ ## Prompt Examples
153
+
154
+ ```text
155
+ Add a red marker for San Francisco and zoom to it.
156
+ ```
157
+
158
+ ```text
159
+ Change the basemap to dark, then get the current map state.
160
+ ```
161
+
162
+ ```text
163
+ Add the GeoJSON URL https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json as US counties.
164
+ ```
165
+
166
+ ```text
167
+ Hide the US counties layer, then show it again.
168
+ ```
169
+
170
+ ```text
171
+ What features are visible at the center of the current map?
172
+ ```
173
+
174
+ ## API
175
+
176
+ - `GeoAgentControl` implements MapLibre `IControl`
177
+ - `GeoAgentControlReact` mounts and unmounts the control for React apps
178
+ - `useGeoAgentState` provides a small React state helper
179
+ - Types are exported for control options, state, providers, events, and React props
180
+
181
+ ## Development
182
+
183
+ ```bash
184
+ npm install
185
+ npm run dev
186
+ npm test
187
+ npm run build
188
+ npm run build:examples
189
+ ```