@focus-daima/gis-workbench 0.0.0-stage → 0.9.9

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.
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: gis-workbench
3
+ name: '@focus-daima/gis-workbench'
package/icon.svg ADDED
@@ -0,0 +1,20 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="GIS workbench">
2
+ <defs>
3
+ <linearGradient id="gw-bg" x1="0" y1="0" x2="1" y2="1">
4
+ <stop offset="0" stop-color="#1d4f4a"/>
5
+ <stop offset="1" stop-color="#0e2f2c"/>
6
+ </linearGradient>
7
+ <linearGradient id="gw-pin" x1="0" y1="0" x2="0" y2="1">
8
+ <stop offset="0" stop-color="#ffd7a8"/>
9
+ <stop offset="1" stop-color="#e8843f"/>
10
+ </linearGradient>
11
+ </defs>
12
+ <rect width="64" height="64" rx="15" fill="url(#gw-bg)"/>
13
+ <path d="M9 41c7-9 12 3 19-4s10 2 17-4 10-3 12-1" fill="none" stroke="#79b7a5" stroke-opacity=".38" stroke-width="1.4"/>
14
+ <path d="M8 49c8-7 13 2 20-3s11 1 16-3 9-2 13 0" fill="none" stroke="#79b7a5" stroke-opacity=".26" stroke-width="1.4"/>
15
+ <path d="M13 22c5-4 9 1 14-2s8 0 12-3 9-2 13 1" fill="none" stroke="#9fd0c1" stroke-opacity=".42" stroke-width="1.4"/>
16
+ <path d="M14 15c3-2 6 0 9-1" fill="none" stroke="#9fd0c1" stroke-opacity=".24" stroke-width="1.2"/>
17
+ <path d="M32 17c-5.5 0-9.5 4.1-9.5 9.3 0 7 9.5 15.7 9.5 15.7s9.5-8.7 9.5-15.7C41.5 21.1 37.5 17 32 17z" fill="url(#gw-pin)" stroke="#2a1206" stroke-opacity=".28" stroke-width="1"/>
18
+ <circle cx="32" cy="26.4" r="3.6" fill="#173f3a"/>
19
+ <path d="M38 48h11M43 43v10" stroke="#eef6f2" stroke-opacity=".82" stroke-width="1.5" stroke-linecap="round"/>
20
+ </svg>
package/index.js ADDED
@@ -0,0 +1,417 @@
1
+ import {
2
+ DEFAULT_ATTRIBUTION,
3
+ DEFAULT_LAYER_NAME,
4
+ DEFAULT_TILE_SIZE,
5
+ DEFAULT_TILE_URL,
6
+ DEFAULT_VIEW_ZOOM,
7
+ PLACE_PRESETS,
8
+ TOOL_NAME,
9
+ VIEW_TOOL_NAME,
10
+ LIST_LAYERS_TOOL_NAME,
11
+ DESCRIBE_LAYER_TOOL_NAME,
12
+ SAMPLE_FIELD_TOOL_NAME,
13
+ MAP_CAPABILITIES_TOOL_NAME,
14
+ UPDATE_STYLE_TOOL_NAME,
15
+ } from './shared.js';
16
+ import { GisStore } from './server/store.js';
17
+ import { createApiHandler } from './server/api.js';
18
+
19
+ export const inject = ['tools'];
20
+
21
+ const PARAMETERS = {
22
+ type: 'object',
23
+ additionalProperties: false,
24
+ properties: {
25
+ name: {
26
+ type: 'string',
27
+ description: 'Layer name shown in the workbench. Defaults to 天地图影像.',
28
+ },
29
+ tileUrl: {
30
+ type: 'string',
31
+ description:
32
+ 'Raster XYZ tile URL template containing {z}, {x}, and {y}. Defaults to the Tianditu image layer at '
33
+ + DEFAULT_TILE_URL
34
+ + '.',
35
+ },
36
+ tileSize: {
37
+ type: 'integer',
38
+ enum: [256, 512],
39
+ description: 'Raster tile size in pixels. Defaults to 256.',
40
+ },
41
+ minzoom: {
42
+ type: 'number',
43
+ description: 'Minimum zoom at which the layer is shown. Defaults to 0.',
44
+ },
45
+ maxzoom: {
46
+ type: 'number',
47
+ description: 'Maximum zoom at which tiles are requested. Defaults to 18.',
48
+ },
49
+ attribution: {
50
+ type: 'string',
51
+ description: 'Attribution text for the layer. Defaults to 天地图.',
52
+ },
53
+ },
54
+ };
55
+
56
+ const OUTPUT_SCHEMA = {
57
+ type: 'object',
58
+ additionalProperties: false,
59
+ required: ['layerId', 'name', 'tileUrl', 'tileSize', 'minzoom', 'maxzoom', 'attribution', 'message'],
60
+ properties: {
61
+ layerId: { type: 'string' },
62
+ name: { type: 'string' },
63
+ tileUrl: { type: 'string' },
64
+ tileSize: { type: 'integer' },
65
+ minzoom: { type: 'number' },
66
+ maxzoom: { type: 'number' },
67
+ attribution: { type: 'string' },
68
+ message: { type: 'string' },
69
+ },
70
+ };
71
+
72
+ function numberInRange(value, fallback, min, max) {
73
+ const number = typeof value === 'number' ? value : Number(value);
74
+ if (!Number.isFinite(number)) return fallback;
75
+ return Math.min(max, Math.max(min, number));
76
+ }
77
+
78
+ function normalize(args) {
79
+ const input = args && typeof args === 'object' && !Array.isArray(args) ? args : {};
80
+ const name = String(input.name || DEFAULT_LAYER_NAME).trim() || DEFAULT_LAYER_NAME;
81
+ const tileUrl = String(input.tileUrl || DEFAULT_TILE_URL).trim() || DEFAULT_TILE_URL;
82
+ if (!tileUrl.includes('{z}') || !tileUrl.includes('{x}') || !tileUrl.includes('{y}')) {
83
+ throw new Error('tileUrl must be an XYZ raster template containing {z}, {x}, and {y}');
84
+ }
85
+ const tileSize = Number(input.tileSize) === 512 ? 512 : DEFAULT_TILE_SIZE;
86
+ const minzoom = numberInRange(input.minzoom, 0, 0, 24);
87
+ const maxzoom = numberInRange(input.maxzoom, 18, minzoom, 24);
88
+ const attribution = String(input.attribution || DEFAULT_ATTRIBUTION).trim() || DEFAULT_ATTRIBUTION;
89
+ return {
90
+ layerId: 'tianditu-image',
91
+ name: name.slice(0, 120),
92
+ tileUrl,
93
+ tileSize,
94
+ minzoom,
95
+ maxzoom,
96
+ attribution,
97
+ message: `Added raster layer "${name.slice(0, 120)}" to the GIS workbench map.`,
98
+ };
99
+ }
100
+
101
+ const VIEW_PARAMETERS = {
102
+ type: 'object',
103
+ additionalProperties: false,
104
+ properties: {
105
+ center: {
106
+ type: 'array',
107
+ items: { type: 'number' },
108
+ description: 'Target center as [longitude, latitude] in WGS84 degrees, e.g. [120.1551, 30.2741] for Hangzhou.',
109
+ },
110
+ place: {
111
+ type: 'string',
112
+ description: 'Optional place key resolved by the workbench gazetteer, e.g. hangzhou, beijing, shanghai, china.',
113
+ },
114
+ zoom: {
115
+ type: 'number',
116
+ description: 'Target zoom level, 0-24. A city view is around 10-12, a country view around 3-4.',
117
+ },
118
+ label: {
119
+ type: 'string',
120
+ description: 'Short human label for the target, shown on the map tool card.',
121
+ },
122
+ },
123
+ };
124
+
125
+ const VIEW_OUTPUT_SCHEMA = {
126
+ type: 'object',
127
+ additionalProperties: false,
128
+ required: ['center', 'zoom', 'label', 'message'],
129
+ properties: {
130
+ center: { type: 'array', items: { type: 'number' } },
131
+ zoom: { type: 'number' },
132
+ label: { type: 'string' },
133
+ message: { type: 'string' },
134
+ },
135
+ };
136
+
137
+ function normalizeView(args) {
138
+ const input = args && typeof args === 'object' && !Array.isArray(args) ? args : {};
139
+ const placeKey = String(input.place || '').trim().toLowerCase();
140
+ const preset = placeKey ? PLACE_PRESETS[placeKey] : undefined;
141
+ let center = null;
142
+ if (Array.isArray(input.center) && input.center.length >= 2) {
143
+ center = [Number(input.center[0]), Number(input.center[1])];
144
+ } else if (preset) {
145
+ center = preset.center.slice();
146
+ }
147
+ if (!center || !center.every((value) => Number.isFinite(value))) {
148
+ throw new Error('A map view request needs either center [lng, lat] or a known place name');
149
+ }
150
+ const lng = Math.min(180, Math.max(-180, center[0]));
151
+ const lat = Math.min(85, Math.max(-85, center[1]));
152
+ const zoom = numberInRange(input.zoom !== undefined ? input.zoom : preset && preset.zoom, DEFAULT_VIEW_ZOOM, 0, 24);
153
+ const label = String(input.label || (preset && preset.label) || (lat.toFixed(4) + '°N, ' + lng.toFixed(4) + '°E')).slice(0, 120);
154
+ return {
155
+ center: [lng, lat],
156
+ zoom,
157
+ label,
158
+ message: `Moved the GIS workbench map to "${label}" (${lat.toFixed(4)}°N, ${lng.toFixed(4)}°E, zoom ${zoom}).`,
159
+ };
160
+ }
161
+
162
+ function toolResultText(values) {
163
+ return [{ type: 'text', text: values.join('\n') }];
164
+ }
165
+
166
+ function registerMapDataTools(scope, tools, store, ready) {
167
+ const register = (definition, label) => {
168
+ scope.effect(() => tools.register(definition), label);
169
+ };
170
+
171
+ register({
172
+ name: LIST_LAYERS_TOOL_NAME,
173
+ description:
174
+ 'List vector/raster layers in GIS projects. Use this first when the user refers to a layer by name such as "building". '
175
+ + 'Returns layerId, projectId, projectName, dataset format/kind, feature count, attribute fields, bbox, visibility, z, and current style. '
176
+ + 'A layerId is required by gis_describe_layer, gis_sample_field, and gis_update_layer_style.',
177
+ parameters: {
178
+ type: 'object',
179
+ additionalProperties: false,
180
+ properties: {
181
+ projectId: { type: 'string', description: 'Optional project id to restrict the search.' },
182
+ query: { type: 'string', description: 'Optional case-insensitive name/field/project filter, e.g. building.' },
183
+ limit: { type: 'integer', description: 'Maximum results, 1-200. Defaults to 100.' },
184
+ },
185
+ },
186
+ output: {
187
+ schema: { type: 'object', additionalProperties: true, required: ['layers', 'message'], properties: { layers: { type: 'array' }, message: { type: 'string' } } },
188
+ render(_args, value) { return toolResultText([value.message]); },
189
+ },
190
+ async execute(args) {
191
+ await ready;
192
+ let layers = store.listAllLayers(args);
193
+ if (args && args.projectId) layers = layers.filter((layer) => layer.projectId === args.projectId);
194
+ return {
195
+ layers,
196
+ message: layers.length === 0
197
+ ? 'No matching layers were found.'
198
+ : 'Found ' + layers.length + ' layer(s): ' + layers.map((layer) => layer.name + ' [' + layer.layerId + ']').join(', '),
199
+ };
200
+ },
201
+ presentCall(args) { return { card: 'generic', title: 'List map layers', kind: 'other', rawInput: args }; },
202
+ isConcurrencySafe() { return true; },
203
+ }, 'gis-workbench: list layers tool');
204
+
205
+ register({
206
+ name: DESCRIBE_LAYER_TOOL_NAME,
207
+ description:
208
+ 'Describe one map layer before styling it. Returns project, geometry/data format, feature count, bbox, attribute fields, current semantic style, and renderability. '
209
+ + 'Use this to verify that a field such as CODE exists before adding a label.',
210
+ parameters: {
211
+ type: 'object',
212
+ additionalProperties: false,
213
+ required: ['layerId'],
214
+ properties: { layerId: { type: 'string', description: 'Layer id returned by gis_list_layers.' } },
215
+ },
216
+ output: {
217
+ schema: { type: 'object', additionalProperties: true, required: ['layer', 'fields', 'message'], properties: { layer: { type: 'object' }, fields: { type: 'array' }, message: { type: 'string' } } },
218
+ render(_args, value) { return toolResultText([value.message]); },
219
+ },
220
+ async execute(args) {
221
+ await ready;
222
+ const info = store.describeLayer(args.layerId);
223
+ return Object.assign({}, info, {
224
+ message: 'Layer "' + info.layer.name + '": ' + info.kind + '/' + info.format
225
+ + ', ' + (info.featureCount || 0) + ' features, fields: ' + (info.fields.length ? info.fields.join(', ') : 'none')
226
+ + ', renderable: ' + info.renderable,
227
+ });
228
+ },
229
+ presentCall(args) { return { card: 'generic', title: 'Describe map layer', kind: 'other', rawInput: args }; },
230
+ isConcurrencySafe() { return true; },
231
+ }, 'gis-workbench: describe layer tool');
232
+
233
+ register({
234
+ name: SAMPLE_FIELD_TOOL_NAME,
235
+ description:
236
+ 'Return distinct values from one attribute field so they can be translated or mapped. Use before creating a Chinese label valueMap. '
237
+ + 'The field must exist on the layer. Limit is capped at 500.',
238
+ parameters: {
239
+ type: 'object',
240
+ additionalProperties: false,
241
+ required: ['layerId', 'field'],
242
+ properties: {
243
+ layerId: { type: 'string' },
244
+ field: { type: 'string', description: 'Attribute field name, e.g. CODE.' },
245
+ limit: { type: 'integer', description: 'Maximum distinct values, 1-500. Defaults to 50.' },
246
+ },
247
+ },
248
+ output: {
249
+ schema: { type: 'object', additionalProperties: true, required: ['values', 'message'], properties: { values: { type: 'array' }, message: { type: 'string' } } },
250
+ render(_args, value) { return toolResultText([value.message]); },
251
+ },
252
+ async execute(args) {
253
+ await ready;
254
+ const result = await store.sampleLayerField(args.layerId, args.field, args.limit);
255
+ return Object.assign({}, result, {
256
+ message: 'Field "' + result.field + '" distinct values' + (result.truncated ? ' (truncated)' : '') + ': '
257
+ + JSON.stringify(result.values),
258
+ });
259
+ },
260
+ presentCall(args) { return { card: 'generic', title: 'Sample field values', kind: 'other', rawInput: args }; },
261
+ isConcurrencySafe() { return true; },
262
+ }, 'gis-workbench: sample field tool');
263
+
264
+ register({
265
+ name: MAP_CAPABILITIES_TOOL_NAME,
266
+ description:
267
+ 'Return the current map style capability schema: supported semantic style keys, label options, fonts, glyph URL, and examples. '
268
+ + 'Call this when unsure which style properties are supported or before a complex label/style request.',
269
+ parameters: { type: 'object', additionalProperties: false, properties: {} },
270
+ output: {
271
+ schema: { type: 'object', additionalProperties: true, required: ['styleSchema', 'message'], properties: { styleSchema: { type: 'object' }, message: { type: 'string' } } },
272
+ render(_args, value) { return toolResultText([value.message]); },
273
+ },
274
+ async execute() {
275
+ await ready;
276
+ const capabilities = store.mapCapabilities();
277
+ return Object.assign({}, capabilities, {
278
+ message: 'Map styling supports: ' + Object.keys(capabilities.styleSchema.properties).join(', ') + '. Labels are supported with valueMap translation.',
279
+ });
280
+ },
281
+ presentCall() { return { card: 'generic', title: 'Map capabilities', kind: 'other' }; },
282
+ isConcurrencySafe() { return true; },
283
+ }, 'gis-workbench: map capabilities tool');
284
+
285
+ register({
286
+ name: UPDATE_STYLE_TOOL_NAME,
287
+ description:
288
+ 'Update the persisted semantic style of one vector layer. Use gis_list_layers + gis_describe_layer + gis_sample_field first. '
289
+ + 'Supported patch keys: fillColor, fillOpacity, lineColor, lineWidth, lineOpacity, circleColor, circleRadius, circleOpacity, lineVisible, circleVisible, categorical, opacity, and label. '
290
+ + 'The label object supports field, valueMap, fallback, size, color, haloColor, haloWidth, minzoom, maxzoom, allowOverlap, font, anchor, and onePerFeature (one centered label per feature). '
291
+ + 'Example for building labels: {"label":{"field":"CODE","valueMap":{"Building":"建筑","Deck":"露台","Patio":"庭院"},"size":12,"minzoom":15}}. '
292
+ + 'To remove a label, set label to null. Unknown keys are rejected. This persists to the layer style and the browser map applies it immediately.',
293
+ parameters: {
294
+ type: 'object',
295
+ additionalProperties: false,
296
+ required: ['layerId', 'stylePatch'],
297
+ properties: {
298
+ layerId: { type: 'string', description: 'Layer id from gis_list_layers.' },
299
+ stylePatch: {
300
+ type: 'object',
301
+ additionalProperties: true,
302
+ description: 'Semantic style patch. Keys are documented in the tool description; unknown keys fail validation.',
303
+ },
304
+ },
305
+ },
306
+ output: {
307
+ schema: {
308
+ type: 'object',
309
+ additionalProperties: true,
310
+ required: ['layerId', 'style', 'message'],
311
+ properties: { layerId: { type: 'string' }, style: { type: 'object' }, layer: { type: 'object' }, message: { type: 'string' } },
312
+ },
313
+ render(_args, value) { return toolResultText([value.message]); },
314
+ },
315
+ async execute(args) {
316
+ await ready;
317
+ const result = store.updateLayerStyle(args.layerId, args.stylePatch);
318
+ return Object.assign({}, result, {
319
+ layerId: args.layerId,
320
+ message: 'Updated style for layer "' + result.layer.name + '": ' + JSON.stringify(result.style),
321
+ });
322
+ },
323
+ presentCall(args) { return { card: 'generic', title: 'Update layer style', kind: 'other', rawInput: args }; },
324
+ isConcurrencySafe() { return false; },
325
+ }, 'gis-workbench: update layer style tool');
326
+ }
327
+
328
+ export function apply(ctx) {
329
+ ctx.effect(() => ctx.tools.register({
330
+ name: TOOL_NAME,
331
+ description:
332
+ 'Add a raster tile layer to the GIS workbench map. Use this when the user asks to add, show, or load a map layer, '
333
+ + 'especially the Tianditu image layer. Call with no arguments to add the default Tianditu imagery layer from '
334
+ + DEFAULT_TILE_URL
335
+ + '. The layer is applied to the workbench map after this tool result settles, and is retained for when the user opens the workbench.',
336
+ parameters: PARAMETERS,
337
+ output: {
338
+ schema: OUTPUT_SCHEMA,
339
+ render(_args, value) {
340
+ return [{ type: 'text', text: value.message }];
341
+ },
342
+ },
343
+ async execute(args) {
344
+ return normalize(args);
345
+ },
346
+ presentCall(args) {
347
+ return {
348
+ card: 'generic',
349
+ title: 'Add map layer',
350
+ kind: 'other',
351
+ rawInput: args,
352
+ };
353
+ },
354
+ isConcurrencySafe() {
355
+ return true;
356
+ },
357
+ }), 'gis-workbench: add layer tool');
358
+
359
+ ctx.effect(() => ctx.tools.register({
360
+ name: VIEW_TOOL_NAME,
361
+ description:
362
+ 'Move the GIS workbench map camera to a place or explicit coordinates. Use this when the user asks to zoom, pan, '
363
+ + 'or fit the map to a city, region, or country — for example 地图缩放到中国杭州范围. The camera moves as soon as '
364
+ + 'the tool result settles, and the view is kept for when the user opens the workbench.',
365
+ parameters: VIEW_PARAMETERS,
366
+ output: {
367
+ schema: VIEW_OUTPUT_SCHEMA,
368
+ render(_args, value) {
369
+ return [{ type: 'text', text: value.message }];
370
+ },
371
+ },
372
+ async execute(args) {
373
+ return normalizeView(args);
374
+ },
375
+ presentCall() {
376
+ return {
377
+ card: 'generic',
378
+ title: 'Move map view',
379
+ kind: 'other',
380
+ };
381
+ },
382
+ isConcurrencySafe() {
383
+ return true;
384
+ },
385
+ }), 'gis-workbench: set view tool');
386
+
387
+ ctx.inject(['webServer', 'workingDirectory'], (scope) => {
388
+ const workspace = scope.workingDirectory.defaultDirectory;
389
+ const store = new GisStore(workspace);
390
+ const ready = store.init().catch((error) => {
391
+ console.error('[gis-workbench] database initialization failed', error);
392
+ throw error;
393
+ });
394
+ registerMapDataTools(scope, ctx.tools, store, ready);
395
+ const handler = createApiHandler(store);
396
+ const guarded = async (req, res) => {
397
+ try {
398
+ await ready;
399
+ } catch (error) {
400
+ res.writeHead(500, { 'content-type': 'application/json; charset=utf-8' });
401
+ res.end(JSON.stringify({ error: 'GIS database is unavailable' }));
402
+ return;
403
+ }
404
+ return handler(req, res);
405
+ };
406
+ const disposeRoute = scope.webServer.register({
407
+ kind: 'prefix',
408
+ path: '/api/gis-workbench',
409
+ handler: guarded,
410
+ });
411
+ scope.effect(() => () => {
412
+ disposeRoute();
413
+ store.close();
414
+ }, 'gis-workbench: SQLite store and HTTP API');
415
+ console.log('[gis-workbench] SQLite store ready at', store.dbPath);
416
+ });
417
+ }
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "GIS workbench",
4
+ "description": "Adds a MapLibre GL JS workbench with an empty map and conversation-driven raster layers."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "GIS 工作台",
4
+ "description": "基于 MapLibre GL JS 的 GIS 工作台,初始无图层,通过右侧对话添加天地图影像等栅格图层。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@focus-daima/gis-workbench",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.9.9",
4
+ "type": "module",
5
+ "description": "MapLibre GIS workbench with PostGIS registration, semantic vector styling, GPKG import, COG rasters, and resumable uploads.",
6
+ "exports": {
7
+ ".": "./index.js",
8
+ "./client": "./client.js",
9
+ "./locale/*.json": "./locale/*.json",
10
+ "./icon": "./icon.svg"
11
+ },
12
+ "files": [
13
+ "index.js",
14
+ "shared.js",
15
+ "client.js",
16
+ "cordis.patch.yml",
17
+ "locale/*.json",
18
+ "icon.svg",
19
+ "src",
20
+ "server",
21
+ "style-schema.js",
22
+ "assets"
23
+ ],
24
+ "dsh": {
25
+ "bundle": {
26
+ "patch": "./cordis.patch.yml"
27
+ },
28
+ "client": {
29
+ "platform": "web",
30
+ "immediately": true,
31
+ "inject": [
32
+ "@deepseek-ai/dsh-client-ui-conversation",
33
+ "@deepseek-ai/dsh-client-ui-sidebar-right",
34
+ "@deepseek-ai/dsh-client-ui-tool"
35
+ ]
36
+ }
37
+ },
38
+ "license": "UNLICENSED",
39
+ "engines": {
40
+ "node": ">=22.5.0"
41
+ },
42
+ "publishConfig": {
43
+ "registry": "https://your-nexus-host/repository/frontend/",
44
+ "access": "public"
45
+ },
46
+ "devDependencies": {
47
+ "esbuild": "^0.28.2",
48
+ "maplibre-gl": "^5.24.1"
49
+ }
50
+ }