@sqlrooms/deck 0.29.0-rc.5 → 0.29.0-rc.7

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 (75) hide show
  1. package/README.md +24 -2
  2. package/dist/DeckJsonMap.d.ts +1 -1
  3. package/dist/DeckJsonMap.d.ts.map +1 -1
  4. package/dist/DeckJsonMap.js +16 -11
  5. package/dist/DeckJsonMap.js.map +1 -1
  6. package/dist/LatitudeSelector.d.ts +11 -0
  7. package/dist/LatitudeSelector.d.ts.map +1 -0
  8. package/dist/LatitudeSelector.js +25 -0
  9. package/dist/LatitudeSelector.js.map +1 -0
  10. package/dist/LongitudeSelector.d.ts +11 -0
  11. package/dist/LongitudeSelector.d.ts.map +1 -0
  12. package/dist/LongitudeSelector.js +27 -0
  13. package/dist/LongitudeSelector.js.map +1 -0
  14. package/dist/MapSettings.d.ts +10 -0
  15. package/dist/MapSettings.d.ts.map +1 -0
  16. package/dist/MapSettings.js +94 -0
  17. package/dist/MapSettings.js.map +1 -0
  18. package/dist/ai.d.ts +168 -0
  19. package/dist/ai.d.ts.map +1 -0
  20. package/dist/ai.js +232 -0
  21. package/dist/ai.js.map +1 -0
  22. package/dist/dashboard.d.ts.map +1 -1
  23. package/dist/dashboard.js +72 -105
  24. package/dist/dashboard.js.map +1 -1
  25. package/dist/dashboardConfig.d.ts +22 -6
  26. package/dist/dashboardConfig.d.ts.map +1 -1
  27. package/dist/dashboardConfig.js +2 -5
  28. package/dist/dashboardConfig.js.map +1 -1
  29. package/dist/dashboardIntegration.d.ts +3 -0
  30. package/dist/dashboardIntegration.d.ts.map +1 -0
  31. package/dist/dashboardIntegration.js +16 -0
  32. package/dist/dashboardIntegration.js.map +1 -0
  33. package/dist/datasets/PreparedDatasetStore.js +2 -1
  34. package/dist/datasets/PreparedDatasetStore.js.map +1 -1
  35. package/dist/index.d.ts +8 -2
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +5 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/json/colorScaleFunction.d.ts +1 -1
  40. package/dist/json/colorScaleFunction.d.ts.map +1 -1
  41. package/dist/json/colorScaleFunction.js +7 -1
  42. package/dist/json/colorScaleFunction.js.map +1 -1
  43. package/dist/json/extractColorScaleLegends.d.ts.map +1 -1
  44. package/dist/json/extractColorScaleLegends.js +0 -1
  45. package/dist/json/extractColorScaleLegends.js.map +1 -1
  46. package/dist/json/layerCompatibility.d.ts.map +1 -1
  47. package/dist/json/layerCompatibility.js +2 -0
  48. package/dist/json/layerCompatibility.js.map +1 -1
  49. package/dist/mapConfigUtils.d.ts +62 -0
  50. package/dist/mapConfigUtils.d.ts.map +1 -0
  51. package/dist/mapConfigUtils.js +233 -0
  52. package/dist/mapConfigUtils.js.map +1 -0
  53. package/dist/mapDataPolicy.d.ts +4 -0
  54. package/dist/mapDataPolicy.d.ts.map +1 -0
  55. package/dist/mapDataPolicy.js +25 -0
  56. package/dist/mapDataPolicy.js.map +1 -0
  57. package/dist/mapLayerConfigUtils.d.ts +38 -0
  58. package/dist/mapLayerConfigUtils.d.ts.map +1 -0
  59. package/dist/mapLayerConfigUtils.js +185 -0
  60. package/dist/mapLayerConfigUtils.js.map +1 -0
  61. package/dist/prepare/wkbDecoder.d.ts.map +1 -1
  62. package/dist/prepare/wkbDecoder.js +266 -67
  63. package/dist/prepare/wkbDecoder.js.map +1 -1
  64. package/dist/prepare/wkbParser.d.ts +19 -0
  65. package/dist/prepare/wkbParser.d.ts.map +1 -0
  66. package/dist/prepare/wkbParser.js +115 -0
  67. package/dist/prepare/wkbParser.js.map +1 -0
  68. package/dist/types.d.ts +8 -0
  69. package/dist/types.d.ts.map +1 -1
  70. package/dist/types.js.map +1 -1
  71. package/package.json +8 -6
  72. package/dist/useDeckLayersReadyRedraw.d.ts +0 -13
  73. package/dist/useDeckLayersReadyRedraw.d.ts.map +0 -1
  74. package/dist/useDeckLayersReadyRedraw.js +0 -35
  75. package/dist/useDeckLayersReadyRedraw.js.map +0 -1
package/dist/ai.d.ts ADDED
@@ -0,0 +1,168 @@
1
+ import { type Tool } from 'ai';
2
+ import { z } from 'zod';
3
+ import { type CreateDashboardAgentToolOptions, type CreateDashboardAiToolsOptions, type DashboardToolDeps } from '@sqlrooms/mosaic';
4
+ export declare const DECK_MAP_AI_INSTRUCTIONS = "\nDeck map tools:\n- create_deck_map_config validates and returns a reusable native Deck JSON map config without requiring a dashboard artifact.\n- create_dashboard_map creates or updates an interactive map panel inside a dashboard from a native Deck JSON map config.\n- Use map tools when the user asks for a map, geospatial/spatial visualization, locations, longitude/latitude data, or geometry columns.\n- Author maps with config.spec.layers using Deck JSON layer classes in @@type, such as GeoArrowScatterplotLayer, GeoArrowHeatmapLayer, GeoArrowPolygonLayer, GeoArrowPathLayer, or GeoArrowArcLayer.\n- Bind layers to datasets with _sqlroomsBinding.dataset and put tableName or sqlQuery sources in config.datasets.\n- For data-driven color, use native Deck JSON accessors with {\"@@function\":\"colorScale\", \"field\":\"...\", \"type\":\"sequential\"|\"diverging\"|\"quantize\"|\"quantile\"|\"categorical\", \"scheme\":\"Viridis\", \"domain\":\"auto\"} on color properties such as getFillColor, getLineColor, getColor, getSourceColor, or getTargetColor.\n- Map panels default to a 100000-row runtime data limit; use config.dataPolicy.maxRows only when the map genuinely needs a panel-specific limit.\n- After calling create_dashboard_map, call list_dashboard_panels before your final response and check the map panel issue. If it has a render-error, repair the map config in place instead of saying the map is complete.\n";
5
+ export declare function getDashboardWithDeckMapAiInstructions(): string;
6
+ export declare function createDashboardWithDeckMapAiTools<TState>(options: CreateDashboardAiToolsOptions<TState>): Record<string, Tool>;
7
+ export declare function createDashboardAgentToolWithDeckMaps<TState>(options: CreateDashboardAgentToolOptions<TState>): Tool;
8
+ export declare const DeckMapDashboardConfigParameter: z.ZodObject<{
9
+ spec: z.ZodObject<{
10
+ initialViewState: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
11
+ viewState: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
12
+ controller: z.ZodOptional<z.ZodUnknown>;
13
+ layers: z.ZodOptional<z.ZodArray<z.ZodObject<{
14
+ '@@type': z.ZodOptional<z.ZodString>;
15
+ id: z.ZodOptional<z.ZodString>;
16
+ _sqlroomsBinding: z.ZodOptional<z.ZodObject<{
17
+ dataset: z.ZodOptional<z.ZodString>;
18
+ geometryColumn: z.ZodOptional<z.ZodString>;
19
+ geometryEncodingHint: z.ZodOptional<z.ZodEnum<{
20
+ geoarrow: "geoarrow";
21
+ wkb: "wkb";
22
+ wkt: "wkt";
23
+ }>>;
24
+ sourceGeometryColumn: z.ZodOptional<z.ZodString>;
25
+ targetGeometryColumn: z.ZodOptional<z.ZodString>;
26
+ timestampColumn: z.ZodOptional<z.ZodString>;
27
+ hexagonColumn: z.ZodOptional<z.ZodString>;
28
+ }, z.core.$loose>>;
29
+ }, z.core.$loose>>>;
30
+ }, z.core.$loose>;
31
+ datasets: z.ZodRecord<z.ZodString, z.ZodObject<{
32
+ source: z.ZodOptional<z.ZodObject<{
33
+ tableName: z.ZodOptional<z.ZodString>;
34
+ sqlQuery: z.ZodOptional<z.ZodString>;
35
+ }, z.core.$loose>>;
36
+ geometryColumn: z.ZodOptional<z.ZodString>;
37
+ geometryEncodingHint: z.ZodOptional<z.ZodEnum<{
38
+ geoarrow: "geoarrow";
39
+ wkb: "wkb";
40
+ wkt: "wkt";
41
+ }>>;
42
+ }, z.core.$loose>>;
43
+ mapStyle: z.ZodOptional<z.ZodString>;
44
+ mapProps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
45
+ showLegends: z.ZodOptional<z.ZodBoolean>;
46
+ interaction: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
47
+ fitToData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
48
+ dataPolicy: z.ZodOptional<z.ZodObject<{
49
+ disabled: z.ZodOptional<z.ZodBoolean>;
50
+ maxRows: z.ZodOptional<z.ZodNumber>;
51
+ reason: z.ZodOptional<z.ZodString>;
52
+ }, z.core.$loose>>;
53
+ settingsOpen: z.ZodOptional<z.ZodBoolean>;
54
+ }, z.core.$loose>;
55
+ export type DeckMapDashboardConfigToolConfig = z.infer<typeof DeckMapDashboardConfigParameter>;
56
+ export declare const DeckMapConfigToolParameters: z.ZodObject<{
57
+ title: z.ZodDefault<z.ZodOptional<z.ZodString>>;
58
+ config: z.ZodObject<{
59
+ spec: z.ZodObject<{
60
+ initialViewState: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
61
+ viewState: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
62
+ controller: z.ZodOptional<z.ZodUnknown>;
63
+ layers: z.ZodOptional<z.ZodArray<z.ZodObject<{
64
+ '@@type': z.ZodOptional<z.ZodString>;
65
+ id: z.ZodOptional<z.ZodString>;
66
+ _sqlroomsBinding: z.ZodOptional<z.ZodObject<{
67
+ dataset: z.ZodOptional<z.ZodString>;
68
+ geometryColumn: z.ZodOptional<z.ZodString>;
69
+ geometryEncodingHint: z.ZodOptional<z.ZodEnum<{
70
+ geoarrow: "geoarrow";
71
+ wkb: "wkb";
72
+ wkt: "wkt";
73
+ }>>;
74
+ sourceGeometryColumn: z.ZodOptional<z.ZodString>;
75
+ targetGeometryColumn: z.ZodOptional<z.ZodString>;
76
+ timestampColumn: z.ZodOptional<z.ZodString>;
77
+ hexagonColumn: z.ZodOptional<z.ZodString>;
78
+ }, z.core.$loose>>;
79
+ }, z.core.$loose>>>;
80
+ }, z.core.$loose>;
81
+ datasets: z.ZodRecord<z.ZodString, z.ZodObject<{
82
+ source: z.ZodOptional<z.ZodObject<{
83
+ tableName: z.ZodOptional<z.ZodString>;
84
+ sqlQuery: z.ZodOptional<z.ZodString>;
85
+ }, z.core.$loose>>;
86
+ geometryColumn: z.ZodOptional<z.ZodString>;
87
+ geometryEncodingHint: z.ZodOptional<z.ZodEnum<{
88
+ geoarrow: "geoarrow";
89
+ wkb: "wkb";
90
+ wkt: "wkt";
91
+ }>>;
92
+ }, z.core.$loose>>;
93
+ mapStyle: z.ZodOptional<z.ZodString>;
94
+ mapProps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
95
+ showLegends: z.ZodOptional<z.ZodBoolean>;
96
+ interaction: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
97
+ fitToData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
98
+ dataPolicy: z.ZodOptional<z.ZodObject<{
99
+ disabled: z.ZodOptional<z.ZodBoolean>;
100
+ maxRows: z.ZodOptional<z.ZodNumber>;
101
+ reason: z.ZodOptional<z.ZodString>;
102
+ }, z.core.$loose>>;
103
+ settingsOpen: z.ZodOptional<z.ZodBoolean>;
104
+ }, z.core.$loose>;
105
+ reasoning: z.ZodString;
106
+ }, z.core.$strip>;
107
+ export type DeckMapConfigToolParams = z.infer<typeof DeckMapConfigToolParameters>;
108
+ export declare const DeckMapDashboardToolParameters: z.ZodObject<{
109
+ title: z.ZodDefault<z.ZodOptional<z.ZodString>>;
110
+ config: z.ZodObject<{
111
+ spec: z.ZodObject<{
112
+ initialViewState: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
113
+ viewState: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
114
+ controller: z.ZodOptional<z.ZodUnknown>;
115
+ layers: z.ZodOptional<z.ZodArray<z.ZodObject<{
116
+ '@@type': z.ZodOptional<z.ZodString>;
117
+ id: z.ZodOptional<z.ZodString>;
118
+ _sqlroomsBinding: z.ZodOptional<z.ZodObject<{
119
+ dataset: z.ZodOptional<z.ZodString>;
120
+ geometryColumn: z.ZodOptional<z.ZodString>;
121
+ geometryEncodingHint: z.ZodOptional<z.ZodEnum<{
122
+ geoarrow: "geoarrow";
123
+ wkb: "wkb";
124
+ wkt: "wkt";
125
+ }>>;
126
+ sourceGeometryColumn: z.ZodOptional<z.ZodString>;
127
+ targetGeometryColumn: z.ZodOptional<z.ZodString>;
128
+ timestampColumn: z.ZodOptional<z.ZodString>;
129
+ hexagonColumn: z.ZodOptional<z.ZodString>;
130
+ }, z.core.$loose>>;
131
+ }, z.core.$loose>>>;
132
+ }, z.core.$loose>;
133
+ datasets: z.ZodRecord<z.ZodString, z.ZodObject<{
134
+ source: z.ZodOptional<z.ZodObject<{
135
+ tableName: z.ZodOptional<z.ZodString>;
136
+ sqlQuery: z.ZodOptional<z.ZodString>;
137
+ }, z.core.$loose>>;
138
+ geometryColumn: z.ZodOptional<z.ZodString>;
139
+ geometryEncodingHint: z.ZodOptional<z.ZodEnum<{
140
+ geoarrow: "geoarrow";
141
+ wkb: "wkb";
142
+ wkt: "wkt";
143
+ }>>;
144
+ }, z.core.$loose>>;
145
+ mapStyle: z.ZodOptional<z.ZodString>;
146
+ mapProps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
147
+ showLegends: z.ZodOptional<z.ZodBoolean>;
148
+ interaction: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
149
+ fitToData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
150
+ dataPolicy: z.ZodOptional<z.ZodObject<{
151
+ disabled: z.ZodOptional<z.ZodBoolean>;
152
+ maxRows: z.ZodOptional<z.ZodNumber>;
153
+ reason: z.ZodOptional<z.ZodString>;
154
+ }, z.core.$loose>>;
155
+ settingsOpen: z.ZodOptional<z.ZodBoolean>;
156
+ }, z.core.$loose>;
157
+ artifactId: z.ZodOptional<z.ZodString>;
158
+ tableName: z.ZodOptional<z.ZodString>;
159
+ createArtifactIfMissing: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
160
+ panelId: z.ZodOptional<z.ZodString>;
161
+ reasoning: z.ZodString;
162
+ }, z.core.$strip>;
163
+ export type DeckMapDashboardToolParams = z.infer<typeof DeckMapDashboardToolParameters>;
164
+ export declare function createDeckMapConfigTool(): Tool;
165
+ export declare function createDeckMapAiTools(): Record<string, Tool>;
166
+ export declare function createDeckMapDashboardTool(deps: DashboardToolDeps): Tool;
167
+ export declare function createDeckMapDashboardAiTools(deps: DashboardToolDeps): Record<string, Tool>;
168
+ //# sourceMappingURL=ai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../src/ai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,IAAI,EAAC,MAAM,IAAI,CAAC;AACnC,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAKL,KAAK,+BAA+B,EACpC,KAAK,6BAA6B,EAClC,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAC;AAO1B,eAAO,MAAM,wBAAwB,u5CAUpC,CAAC;AAWF,wBAAgB,qCAAqC,WAEpD;AAED,wBAAgB,iCAAiC,CAAC,MAAM,EACtD,OAAO,EAAE,6BAA6B,CAAC,MAAM,CAAC,GAC7C,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAKtB;AAED,wBAAgB,oCAAoC,CAAC,MAAM,EACzD,OAAO,EAAE,+BAA+B,CAAC,MAAM,CAAC,GAC/C,IAAI,CAKN;AA0CD,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkB1C,CAAC;AAEH,MAAM,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CACpD,OAAO,+BAA+B,CACvC,CAAC;AAEF,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAQtC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,2BAA2B,CACnC,CAAC;AAEF,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4BvC,CAAC;AAEL,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAC9C,OAAO,8BAA8B,CACtC,CAAC;AAiBF,wBAAgB,uBAAuB,IAAI,IAAI,CAgC9C;AAED,wBAAgB,oBAAoB,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAI3D;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAgFxE;AAED,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,iBAAiB,GACtB,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAItB"}
package/dist/ai.js ADDED
@@ -0,0 +1,232 @@
1
+ import { tool } from 'ai';
2
+ import { z } from 'zod';
3
+ import { DASHBOARD_AI_INSTRUCTIONS, MAP_TOOL_KEY, createDashboardAgentTool, createDashboardAiTools as createMosaicDashboardAiTools, } from '@sqlrooms/mosaic';
4
+ import { createDeckMapDashboardPanelConfig, DECK_MAP_DASHBOARD_PANEL_TYPE, } from './dashboardConfig';
5
+ export const DECK_MAP_AI_INSTRUCTIONS = `
6
+ Deck map tools:
7
+ - create_deck_map_config validates and returns a reusable native Deck JSON map config without requiring a dashboard artifact.
8
+ - create_dashboard_map creates or updates an interactive map panel inside a dashboard from a native Deck JSON map config.
9
+ - Use map tools when the user asks for a map, geospatial/spatial visualization, locations, longitude/latitude data, or geometry columns.
10
+ - Author maps with config.spec.layers using Deck JSON layer classes in @@type, such as GeoArrowScatterplotLayer, GeoArrowHeatmapLayer, GeoArrowPolygonLayer, GeoArrowPathLayer, or GeoArrowArcLayer.
11
+ - Bind layers to datasets with _sqlroomsBinding.dataset and put tableName or sqlQuery sources in config.datasets.
12
+ - For data-driven color, use native Deck JSON accessors with {"@@function":"colorScale", "field":"...", "type":"sequential"|"diverging"|"quantize"|"quantile"|"categorical", "scheme":"Viridis", "domain":"auto"} on color properties such as getFillColor, getLineColor, getColor, getSourceColor, or getTargetColor.
13
+ - Map panels default to a 100000-row runtime data limit; use config.dataPolicy.maxRows only when the map genuinely needs a panel-specific limit.
14
+ - After calling create_dashboard_map, call list_dashboard_panels before your final response and check the map panel issue. If it has a render-error, repair the map config in place instead of saying the map is complete.
15
+ `;
16
+ function createDeckMapDashboardExtraTools(extraTools) {
17
+ return (deps) => ({
18
+ ...createDeckMapDashboardAiTools(deps),
19
+ ...(extraTools?.(deps) ?? {}),
20
+ });
21
+ }
22
+ export function getDashboardWithDeckMapAiInstructions() {
23
+ return `${DASHBOARD_AI_INSTRUCTIONS.trim()}\n\n${DECK_MAP_AI_INSTRUCTIONS.trim()}`;
24
+ }
25
+ export function createDashboardWithDeckMapAiTools(options) {
26
+ return createMosaicDashboardAiTools({
27
+ ...options,
28
+ extraTools: createDeckMapDashboardExtraTools(options.extraTools),
29
+ });
30
+ }
31
+ export function createDashboardAgentToolWithDeckMaps(options) {
32
+ return createDashboardAgentTool({
33
+ ...options,
34
+ extraTools: createDeckMapDashboardExtraTools(options.extraTools),
35
+ });
36
+ }
37
+ const DeckMapLayerBindingConfig = z.looseObject({
38
+ dataset: z.string().optional(),
39
+ geometryColumn: z.string().optional(),
40
+ geometryEncodingHint: z.enum(['geoarrow', 'wkb', 'wkt']).optional(),
41
+ sourceGeometryColumn: z.string().optional(),
42
+ targetGeometryColumn: z.string().optional(),
43
+ timestampColumn: z.string().optional(),
44
+ hexagonColumn: z.string().optional(),
45
+ });
46
+ const DeckMapLayerSpec = z.looseObject({
47
+ '@@type': z.string().optional(),
48
+ id: z.string().optional(),
49
+ _sqlroomsBinding: DeckMapLayerBindingConfig.optional(),
50
+ });
51
+ const DeckMapSpec = z.looseObject({
52
+ initialViewState: z.record(z.string(), z.unknown()).optional(),
53
+ viewState: z.record(z.string(), z.unknown()).optional(),
54
+ controller: z.unknown().optional(),
55
+ layers: z.array(DeckMapLayerSpec).optional(),
56
+ });
57
+ const DeckMapDatasetSource = z.looseObject({
58
+ tableName: z.string().optional(),
59
+ sqlQuery: z.string().optional(),
60
+ });
61
+ const DeckMapDatasetConfig = z.looseObject({
62
+ source: DeckMapDatasetSource.optional(),
63
+ geometryColumn: z.string().optional(),
64
+ geometryEncodingHint: z.enum(['geoarrow', 'wkb', 'wkt']).optional(),
65
+ });
66
+ const DeckMapDataPolicyConfig = z.looseObject({
67
+ disabled: z.boolean().optional(),
68
+ maxRows: z.number().int().min(1).optional(),
69
+ reason: z.string().optional(),
70
+ });
71
+ export const DeckMapDashboardConfigParameter = z.looseObject({
72
+ spec: DeckMapSpec.describe('Deck JSON map spec as an object. Use spec.layers[].@@type for layer classes such as GeoArrowScatterplotLayer, GeoArrowHeatmapLayer, GeoArrowPolygonLayer, GeoArrowPathLayer, or GeoArrowArcLayer.'),
73
+ datasets: z
74
+ .record(z.string(), DeckMapDatasetConfig)
75
+ .describe('Datasets keyed by dataset id. Layers bind to these ids through _sqlroomsBinding.dataset. Each dataset source may use tableName or sqlQuery.'),
76
+ mapStyle: z.string().optional(),
77
+ mapProps: z.record(z.string(), z.unknown()).optional(),
78
+ showLegends: z.boolean().optional(),
79
+ interaction: z.record(z.string(), z.unknown()).optional(),
80
+ fitToData: z.record(z.string(), z.unknown()).optional(),
81
+ dataPolicy: DeckMapDataPolicyConfig.optional().describe('Optional per-map runtime data policy. Maps default to 100000 rows; set maxRows for a panel-specific override or disabled=true to bypass row-count validation.'),
82
+ settingsOpen: z.boolean().optional(),
83
+ });
84
+ export const DeckMapConfigToolParameters = z.object({
85
+ title: z.string().optional().default('Map').describe('Map title.'),
86
+ config: DeckMapDashboardConfigParameter.describe('Native Deck JSON dashboard map config. This is the canonical map representation.'),
87
+ reasoning: z
88
+ .string()
89
+ .describe('Brief rationale for creating the map config.'),
90
+ });
91
+ export const DeckMapDashboardToolParameters = DeckMapConfigToolParameters.extend({
92
+ artifactId: z
93
+ .string()
94
+ .optional()
95
+ .describe('Optional dashboard artifact ID. Defaults to current dashboard.'),
96
+ tableName: z
97
+ .string()
98
+ .optional()
99
+ .describe('Optional table name used only to select/resolve the target dashboard table. Data sources still come from config.datasets.'),
100
+ createArtifactIfMissing: z
101
+ .boolean()
102
+ .optional()
103
+ .default(true)
104
+ .describe('If true, create dashboard artifact if missing.'),
105
+ panelId: z
106
+ .string()
107
+ .optional()
108
+ .describe('Optional panel ID. If provided, updates the existing map panel instead of creating a new one.'),
109
+ reasoning: z
110
+ .string()
111
+ .describe('Brief rationale for creating the map panel.'),
112
+ });
113
+ function cloneConfig(config) {
114
+ return JSON.parse(JSON.stringify(config));
115
+ }
116
+ function createDeckMapPanelFromNativeConfig(params) {
117
+ return createDeckMapDashboardPanelConfig({
118
+ title: params.title || 'Map',
119
+ ...cloneConfig(params.config),
120
+ });
121
+ }
122
+ export function createDeckMapConfigTool() {
123
+ return tool({
124
+ description: `Deck map config: validates and returns a reusable native Deck JSON map configuration without requiring a dashboard artifact.
125
+
126
+ Use when: a chat, agent, or artifact outside a dashboard needs a geospatial map config. Author the map using native Deck JSON: put layer classes in spec.layers[].@@type, bind layers to datasets through _sqlroomsBinding.dataset, and put tableName or sqlQuery sources in config.datasets. For data-driven colors, use color accessors such as getFillColor, getLineColor, getColor, getSourceColor, or getTargetColor with {"@@function":"colorScale", "field":"...", "type":"sequential"|"diverging"|"quantize"|"quantile"|"categorical", "scheme":"Viridis", "domain":"auto"}.`,
127
+ inputSchema: DeckMapConfigToolParameters,
128
+ execute: async (params) => {
129
+ try {
130
+ const panel = createDeckMapPanelFromNativeConfig(params);
131
+ return {
132
+ llmResult: {
133
+ success: true,
134
+ details: `Created deck map config "${panel.title}".`,
135
+ data: {
136
+ kind: 'deck-map-config',
137
+ title: panel.title,
138
+ type: DECK_MAP_DASHBOARD_PANEL_TYPE,
139
+ config: panel.config,
140
+ },
141
+ },
142
+ };
143
+ }
144
+ catch (error) {
145
+ return {
146
+ llmResult: {
147
+ success: false,
148
+ errorMessage: error instanceof Error ? error.message : String(error),
149
+ },
150
+ };
151
+ }
152
+ },
153
+ });
154
+ }
155
+ export function createDeckMapAiTools() {
156
+ return {
157
+ create_deck_map_config: createDeckMapConfigTool(),
158
+ };
159
+ }
160
+ export function createDeckMapDashboardTool(deps) {
161
+ return tool({
162
+ description: `Deck map panel: creates or updates an interactive geospatial map panel in a Mosaic dashboard from a native Deck JSON config.
163
+
164
+ Use when: the user asks for a map in a dashboard. Author the map using native Deck JSON: choose layer classes with spec.layers[].@@type, bind layers to datasets through _sqlroomsBinding.dataset, and put tableName or sqlQuery sources in config.datasets. For data-driven colors, use color accessors such as getFillColor, getLineColor, getColor, getSourceColor, or getTargetColor with {"@@function":"colorScale", "field":"...", "type":"sequential"|"diverging"|"quantize"|"quantile"|"categorical", "scheme":"Viridis", "domain":"auto"}.`,
165
+ inputSchema: DeckMapDashboardToolParameters,
166
+ execute: async (params, context) => {
167
+ try {
168
+ const artifactId = deps.resolveArtifact(params.artifactId, params.createArtifactIfMissing, context);
169
+ if (params.tableName) {
170
+ deps.resolveTable(artifactId, params.tableName);
171
+ }
172
+ const panel = createDeckMapPanelFromNativeConfig(params);
173
+ if (params.panelId) {
174
+ const dashboard = deps.getDashboard(artifactId);
175
+ const existingPanel = dashboard?.panels.find((candidate) => candidate.id === params.panelId);
176
+ if (!existingPanel) {
177
+ throw new Error(`Panel "${params.panelId}" not found in dashboard "${artifactId}". Cannot update.`);
178
+ }
179
+ if (existingPanel.type !== DECK_MAP_DASHBOARD_PANEL_TYPE) {
180
+ throw new Error(`Panel "${params.panelId}" is not a map panel. Cannot update it with ${MAP_TOOL_KEY}.`);
181
+ }
182
+ deps.updatePanel(artifactId, params.panelId, {
183
+ title: panel.title,
184
+ config: panel.config,
185
+ });
186
+ return {
187
+ llmResult: {
188
+ success: true,
189
+ details: `Updated map panel "${panel.title}".`,
190
+ data: {
191
+ panelId: params.panelId,
192
+ artifactId,
193
+ title: panel.title,
194
+ type: DECK_MAP_DASHBOARD_PANEL_TYPE,
195
+ config: panel.config,
196
+ },
197
+ },
198
+ };
199
+ }
200
+ const panelId = deps.addPanel(artifactId, panel);
201
+ deps.setCurrentArtifact(artifactId);
202
+ return {
203
+ llmResult: {
204
+ success: true,
205
+ details: `Created map panel "${panel.title}".`,
206
+ data: {
207
+ panelId,
208
+ artifactId,
209
+ title: panel.title,
210
+ type: DECK_MAP_DASHBOARD_PANEL_TYPE,
211
+ config: panel.config,
212
+ },
213
+ },
214
+ };
215
+ }
216
+ catch (error) {
217
+ return {
218
+ llmResult: {
219
+ success: false,
220
+ errorMessage: error instanceof Error ? error.message : String(error),
221
+ },
222
+ };
223
+ }
224
+ },
225
+ });
226
+ }
227
+ export function createDeckMapDashboardAiTools(deps) {
228
+ return {
229
+ [MAP_TOOL_KEY]: createDeckMapDashboardTool(deps),
230
+ };
231
+ }
232
+ //# sourceMappingURL=ai.js.map
package/dist/ai.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.js","sourceRoot":"","sources":["../src/ai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAY,MAAM,IAAI,CAAC;AACnC,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EACL,yBAAyB,EACzB,YAAY,EACZ,wBAAwB,EACxB,sBAAsB,IAAI,4BAA4B,GAIvD,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,iCAAiC,EACjC,6BAA6B,GAE9B,MAAM,mBAAmB,CAAC;AAE3B,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;;;;;CAUvC,CAAC;AAEF,SAAS,gCAAgC,CACvC,UAA8D;IAE9D,OAAO,CAAC,IAAuB,EAAE,EAAE,CAAC,CAAC;QACnC,GAAG,6BAA6B,CAAC,IAAI,CAAC;QACtC,GAAG,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;KAC9B,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,qCAAqC;IACnD,OAAO,GAAG,yBAAyB,CAAC,IAAI,EAAE,OAAO,wBAAwB,CAAC,IAAI,EAAE,EAAE,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,OAA8C;IAE9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C,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;qBACzD;iBACF,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,IAAuB;IAEvB,OAAO;QACL,CAAC,YAAY,CAAC,EAAE,0BAA0B,CAAC,IAAI,CAAC;KACjD,CAAC;AACJ,CAAC","sourcesContent":["import {tool, type Tool} from 'ai';\nimport {z} from 'zod';\nimport {\n DASHBOARD_AI_INSTRUCTIONS,\n MAP_TOOL_KEY,\n createDashboardAgentTool,\n createDashboardAiTools as createMosaicDashboardAiTools,\n type CreateDashboardAgentToolOptions,\n type CreateDashboardAiToolsOptions,\n type DashboardToolDeps,\n} from '@sqlrooms/mosaic';\nimport {\n createDeckMapDashboardPanelConfig,\n DECK_MAP_DASHBOARD_PANEL_TYPE,\n type DeckMapDashboardPanelConfig,\n} from './dashboardConfig';\n\nexport const DECK_MAP_AI_INSTRUCTIONS = `\nDeck map tools:\n- create_deck_map_config validates and returns a reusable native Deck JSON map config without requiring a dashboard artifact.\n- create_dashboard_map creates or updates an interactive map panel inside a dashboard from a native Deck JSON map config.\n- Use map tools when the user asks for a map, geospatial/spatial visualization, locations, longitude/latitude data, or geometry columns.\n- Author maps with config.spec.layers using Deck JSON layer classes in @@type, such as GeoArrowScatterplotLayer, GeoArrowHeatmapLayer, GeoArrowPolygonLayer, GeoArrowPathLayer, or GeoArrowArcLayer.\n- Bind layers to datasets with _sqlroomsBinding.dataset and put tableName or sqlQuery sources in config.datasets.\n- For data-driven color, use native Deck JSON accessors with {\"@@function\":\"colorScale\", \"field\":\"...\", \"type\":\"sequential\"|\"diverging\"|\"quantize\"|\"quantile\"|\"categorical\", \"scheme\":\"Viridis\", \"domain\":\"auto\"} on color properties such as getFillColor, getLineColor, getColor, getSourceColor, or getTargetColor.\n- Map panels default to a 100000-row runtime data limit; use config.dataPolicy.maxRows only when the map genuinely needs a panel-specific limit.\n- After calling create_dashboard_map, call list_dashboard_panels before your final response and check the map panel issue. If it has a render-error, repair the map config in place instead of saying the map is complete.\n`;\n\nfunction createDeckMapDashboardExtraTools(\n extraTools?: (deps: DashboardToolDeps) => Record<string, Tool>,\n) {\n return (deps: DashboardToolDeps) => ({\n ...createDeckMapDashboardAiTools(deps),\n ...(extraTools?.(deps) ?? {}),\n });\n}\n\nexport function getDashboardWithDeckMapAiInstructions() {\n return `${DASHBOARD_AI_INSTRUCTIONS.trim()}\\n\\n${DECK_MAP_AI_INSTRUCTIONS.trim()}`;\n}\n\nexport function createDashboardWithDeckMapAiTools<TState>(\n options: CreateDashboardAiToolsOptions<TState>,\n): Record<string, Tool> {\n return createMosaicDashboardAiTools({\n ...options,\n extraTools: createDeckMapDashboardExtraTools(options.extraTools),\n });\n}\n\nexport function createDashboardAgentToolWithDeckMaps<TState>(\n options: CreateDashboardAgentToolOptions<TState>,\n): Tool {\n return createDashboardAgentTool({\n ...options,\n extraTools: createDeckMapDashboardExtraTools(options.extraTools),\n }) as Tool;\n}\n\nconst DeckMapLayerBindingConfig = z.looseObject({\n dataset: z.string().optional(),\n geometryColumn: z.string().optional(),\n geometryEncodingHint: z.enum(['geoarrow', 'wkb', 'wkt']).optional(),\n sourceGeometryColumn: z.string().optional(),\n targetGeometryColumn: z.string().optional(),\n timestampColumn: z.string().optional(),\n hexagonColumn: z.string().optional(),\n});\n\nconst DeckMapLayerSpec = z.looseObject({\n '@@type': z.string().optional(),\n id: z.string().optional(),\n _sqlroomsBinding: DeckMapLayerBindingConfig.optional(),\n});\n\nconst DeckMapSpec = z.looseObject({\n initialViewState: z.record(z.string(), z.unknown()).optional(),\n viewState: z.record(z.string(), z.unknown()).optional(),\n controller: z.unknown().optional(),\n layers: z.array(DeckMapLayerSpec).optional(),\n});\n\nconst DeckMapDatasetSource = z.looseObject({\n tableName: z.string().optional(),\n sqlQuery: z.string().optional(),\n});\n\nconst DeckMapDatasetConfig = z.looseObject({\n source: DeckMapDatasetSource.optional(),\n geometryColumn: z.string().optional(),\n geometryEncodingHint: z.enum(['geoarrow', 'wkb', 'wkt']).optional(),\n});\n\nconst DeckMapDataPolicyConfig = z.looseObject({\n disabled: z.boolean().optional(),\n maxRows: z.number().int().min(1).optional(),\n reason: z.string().optional(),\n});\n\nexport const DeckMapDashboardConfigParameter = z.looseObject({\n spec: DeckMapSpec.describe(\n 'Deck JSON map spec as an object. Use spec.layers[].@@type for layer classes such as GeoArrowScatterplotLayer, GeoArrowHeatmapLayer, GeoArrowPolygonLayer, GeoArrowPathLayer, or GeoArrowArcLayer.',\n ),\n datasets: z\n .record(z.string(), DeckMapDatasetConfig)\n .describe(\n 'Datasets keyed by dataset id. Layers bind to these ids through _sqlroomsBinding.dataset. Each dataset source may use tableName or sqlQuery.',\n ),\n mapStyle: z.string().optional(),\n mapProps: z.record(z.string(), z.unknown()).optional(),\n showLegends: z.boolean().optional(),\n interaction: z.record(z.string(), z.unknown()).optional(),\n fitToData: z.record(z.string(), z.unknown()).optional(),\n dataPolicy: DeckMapDataPolicyConfig.optional().describe(\n 'Optional per-map runtime data policy. Maps default to 100000 rows; set maxRows for a panel-specific override or disabled=true to bypass row-count validation.',\n ),\n settingsOpen: z.boolean().optional(),\n});\n\nexport type DeckMapDashboardConfigToolConfig = z.infer<\n typeof DeckMapDashboardConfigParameter\n>;\n\nexport const DeckMapConfigToolParameters = z.object({\n title: z.string().optional().default('Map').describe('Map title.'),\n config: DeckMapDashboardConfigParameter.describe(\n 'Native Deck JSON dashboard map config. This is the canonical map representation.',\n ),\n reasoning: z\n .string()\n .describe('Brief rationale for creating the map config.'),\n});\n\nexport type DeckMapConfigToolParams = z.infer<\n typeof DeckMapConfigToolParameters\n>;\n\nexport const DeckMapDashboardToolParameters =\n DeckMapConfigToolParameters.extend({\n artifactId: z\n .string()\n .optional()\n .describe(\n 'Optional dashboard artifact ID. Defaults to current dashboard.',\n ),\n tableName: z\n .string()\n .optional()\n .describe(\n 'Optional table name used only to select/resolve the target dashboard table. Data sources still come from config.datasets.',\n ),\n createArtifactIfMissing: z\n .boolean()\n .optional()\n .default(true)\n .describe('If true, create dashboard artifact if missing.'),\n panelId: z\n .string()\n .optional()\n .describe(\n 'Optional panel ID. If provided, updates the existing map panel instead of creating a new one.',\n ),\n reasoning: z\n .string()\n .describe('Brief rationale for creating the map panel.'),\n });\n\nexport type DeckMapDashboardToolParams = z.infer<\n typeof DeckMapDashboardToolParameters\n>;\n\nfunction cloneConfig(\n config: DeckMapDashboardConfigToolConfig,\n): DeckMapDashboardPanelConfig {\n return JSON.parse(JSON.stringify(config)) as DeckMapDashboardPanelConfig;\n}\n\nfunction createDeckMapPanelFromNativeConfig(\n params: Pick<DeckMapConfigToolParams, 'title' | 'config'>,\n) {\n return createDeckMapDashboardPanelConfig({\n title: params.title || 'Map',\n ...cloneConfig(params.config),\n });\n}\n\nexport function createDeckMapConfigTool(): Tool {\n return tool({\n description: `Deck map config: validates and returns a reusable native Deck JSON map configuration without requiring a dashboard artifact.\n\nUse when: a chat, agent, or artifact outside a dashboard needs a geospatial map config. Author the map using native Deck JSON: put layer classes in spec.layers[].@@type, bind layers to datasets through _sqlroomsBinding.dataset, and put tableName or sqlQuery sources in config.datasets. For data-driven colors, use color accessors such as getFillColor, getLineColor, getColor, getSourceColor, or getTargetColor with {\"@@function\":\"colorScale\", \"field\":\"...\", \"type\":\"sequential\"|\"diverging\"|\"quantize\"|\"quantile\"|\"categorical\", \"scheme\":\"Viridis\", \"domain\":\"auto\"}.`,\n inputSchema: DeckMapConfigToolParameters,\n execute: async (params) => {\n try {\n const panel = createDeckMapPanelFromNativeConfig(params);\n return {\n llmResult: {\n success: true,\n details: `Created deck map config \"${panel.title}\".`,\n data: {\n kind: 'deck-map-config',\n title: panel.title,\n type: DECK_MAP_DASHBOARD_PANEL_TYPE,\n config: panel.config,\n },\n },\n };\n } catch (error) {\n return {\n llmResult: {\n success: false,\n errorMessage:\n error instanceof Error ? error.message : String(error),\n },\n };\n }\n },\n });\n}\n\nexport function createDeckMapAiTools(): Record<string, Tool> {\n return {\n create_deck_map_config: createDeckMapConfigTool(),\n };\n}\n\nexport function createDeckMapDashboardTool(deps: DashboardToolDeps): Tool {\n return tool({\n description: `Deck map panel: creates or updates an interactive geospatial map panel in a Mosaic dashboard from a native Deck JSON config.\n\nUse when: the user asks for a map in a dashboard. Author the map using native Deck JSON: choose layer classes with spec.layers[].@@type, bind layers to datasets through _sqlroomsBinding.dataset, and put tableName or sqlQuery sources in config.datasets. For data-driven colors, use color accessors such as getFillColor, getLineColor, getColor, getSourceColor, or getTargetColor with {\"@@function\":\"colorScale\", \"field\":\"...\", \"type\":\"sequential\"|\"diverging\"|\"quantize\"|\"quantile\"|\"categorical\", \"scheme\":\"Viridis\", \"domain\":\"auto\"}.`,\n inputSchema: DeckMapDashboardToolParameters,\n execute: async (params, context) => {\n try {\n const artifactId = deps.resolveArtifact(\n params.artifactId,\n params.createArtifactIfMissing,\n context,\n );\n if (params.tableName) {\n deps.resolveTable(artifactId, params.tableName);\n }\n const panel = createDeckMapPanelFromNativeConfig(params);\n\n if (params.panelId) {\n const dashboard = deps.getDashboard(artifactId);\n const existingPanel = dashboard?.panels.find(\n (candidate) => candidate.id === params.panelId,\n );\n if (!existingPanel) {\n throw new Error(\n `Panel \"${params.panelId}\" not found in dashboard \"${artifactId}\". Cannot update.`,\n );\n }\n if (existingPanel.type !== DECK_MAP_DASHBOARD_PANEL_TYPE) {\n throw new Error(\n `Panel \"${params.panelId}\" is not a map panel. Cannot update it with ${MAP_TOOL_KEY}.`,\n );\n }\n deps.updatePanel(artifactId, params.panelId, {\n title: panel.title,\n config: panel.config,\n } as never);\n\n return {\n llmResult: {\n success: true,\n details: `Updated map panel \"${panel.title}\".`,\n data: {\n panelId: params.panelId,\n artifactId,\n title: panel.title,\n type: DECK_MAP_DASHBOARD_PANEL_TYPE,\n config: panel.config,\n },\n },\n };\n }\n\n const panelId = deps.addPanel(artifactId, panel);\n deps.setCurrentArtifact(artifactId);\n\n return {\n llmResult: {\n success: true,\n details: `Created map panel \"${panel.title}\".`,\n data: {\n panelId,\n artifactId,\n title: panel.title,\n type: DECK_MAP_DASHBOARD_PANEL_TYPE,\n config: panel.config,\n },\n },\n };\n } catch (error) {\n return {\n llmResult: {\n success: false,\n errorMessage:\n error instanceof Error ? error.message : String(error),\n },\n };\n }\n },\n });\n}\n\nexport function createDeckMapDashboardAiTools(\n deps: DashboardToolDeps,\n): Record<string, Tool> {\n return {\n [MAP_TOOL_KEY]: createDeckMapDashboardTool(deps),\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"dashboard.d.ts","sourceRoot":"","sources":["../src/dashboard.tsx"],"names":[],"mappings":"AAWA,OAAO,EAIL,KAAK,4BAA4B,EAKlC,MAAM,kBAAkB,CAAC;AAuoB1B,eAAO,MAAM,6BAA6B,EAAE,4BAI3C,CAAC;AAqFF,eAAO,MAAM,8BAA8B,EAAE,OAAO,kBAAkB,EAAE,6BASrE,CAAC"}
1
+ {"version":3,"file":"dashboard.d.ts","sourceRoot":"","sources":["../src/dashboard.tsx"],"names":[],"mappings":"AAUA,OAAO,EAIL,KAAK,4BAA4B,EASlC,MAAM,kBAAkB,CAAC;AAwvB1B,eAAO,MAAM,6BAA6B,EAAE,4BAI3C,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,OAAO,kBAAkB,EAAE,6BAmBrE,CAAC"}