@perspective-dev/viewer 5.6.1 → 5.7.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 (568) hide show
  1. package/README.md +4 -4
  2. package/dist/cdn/perspective-viewer.js +10 -9
  3. package/dist/cdn/perspective-viewer.js.map +4 -4
  4. package/dist/custom-elements.json +3955 -0
  5. package/dist/docs/perspective-docs.json +1 -1
  6. package/dist/esm/bootstrap.d.ts +48 -1
  7. package/dist/esm/column-format.d.ts +27 -18
  8. package/dist/esm/column-format.js +1 -1
  9. package/dist/esm/column-format.js.map +3 -3
  10. package/dist/esm/extensions.d.ts +127 -10
  11. package/dist/esm/perspective-viewer.d.ts +30 -25
  12. package/dist/esm/perspective-viewer.js +869 -9
  13. package/dist/esm/perspective-viewer.js.map +4 -4
  14. package/dist/esm/plugin.d.ts +1 -1
  15. package/dist/ts-rs/ColumnConfigDefaultsOptions.d.ts +15 -0
  16. package/dist/ts-rs/ColumnType.d.ts +6 -0
  17. package/dist/ts-rs/ConfigDefaultsOptions.d.ts +10 -0
  18. package/{src/ts/ts-rs/CurrencyNumberFormatStyle.ts → dist/ts-rs/CurrencyNumberFormatStyle.d.ts} +3 -3
  19. package/{src/ts/ts-rs/CustomNumberFormatConfig.ts → dist/ts-rs/CustomNumberFormatConfig.d.ts} +5 -5
  20. package/dist/ts-rs/DatetimeFormat.d.ts +61 -0
  21. package/dist/ts-rs/DatetimeMonthPart.d.ts +6 -0
  22. package/dist/ts-rs/DatetimeNumericPart.d.ts +6 -0
  23. package/dist/ts-rs/DatetimeTextPart.d.ts +6 -0
  24. package/{src/ts/ts-rs/DerivedTableConfig.ts → dist/ts-rs/DerivedTableConfig.d.ts} +8 -8
  25. package/{src/ts/ts-rs/ExportOptions.ts → dist/ts-rs/ExportOptions.d.ts} +1 -1
  26. package/{src/ts/ts-rs/Filter.ts → dist/ts-rs/Filter.d.ts} +1 -1
  27. package/{src/ts/ts-rs/FilterTerm.ts → dist/ts-rs/FilterTerm.d.ts} +1 -1
  28. package/dist/ts-rs/FractionalSecondDigits.d.ts +6 -0
  29. package/{src/ts/ts-rs/GetViewOptions.ts → dist/ts-rs/GetViewOptions.d.ts} +1 -1
  30. package/{src/ts/ts-rs/Layout.ts → dist/ts-rs/Layout.d.ts} +2 -2
  31. package/{src/ts/ts-rs/Notation.ts → dist/ts-rs/Notation.d.ts} +1 -1
  32. package/{src/ts/ts-rs/NumberFormatStyle.ts → dist/ts-rs/NumberFormatStyle.d.ts} +2 -2
  33. package/{src/ts/ts-rs/OnUpdateData.ts → dist/ts-rs/OnUpdateData.d.ts} +1 -1
  34. package/{src/ts/ts-rs/PanelViewerConfig.ts → dist/ts-rs/PanelViewerConfig.d.ts} +12 -12
  35. package/{src/ts/ts-rs/PluginStaticConfig.ts → dist/ts-rs/PluginStaticConfig.d.ts} +3 -3
  36. package/{src/ts/ts-rs/SimpleDatetimeFormat.ts → dist/ts-rs/SimpleDatetimeFormat.d.ts} +4 -1
  37. package/{src/ts/ts-rs/Sort.ts → dist/ts-rs/Sort.d.ts} +1 -1
  38. package/{src/ts/ts-rs/SplitLayout.ts → dist/ts-rs/SplitLayout.d.ts} +2 -2
  39. package/{src/ts/ts-rs/TableRef.ts → dist/ts-rs/TableRef.d.ts} +1 -1
  40. package/{src/ts/ts-rs/Unit.ts → dist/ts-rs/Unit.d.ts} +1 -1
  41. package/{src/ts/ts-rs/UnitNumberFormatStyle.ts → dist/ts-rs/UnitNumberFormatStyle.d.ts} +2 -2
  42. package/{src/ts/ts-rs/ViewerConfig.ts → dist/ts-rs/ViewerConfig.d.ts} +12 -12
  43. package/{src/ts/ts-rs/ViewerConfigInitial.ts → dist/ts-rs/ViewerConfigInitial.d.ts} +9 -9
  44. package/{src/ts/ts-rs/ViewerConfigUpdate.ts → dist/ts-rs/ViewerConfigUpdate.d.ts} +13 -13
  45. package/{src/ts/ts-rs/WindowSort.ts → dist/ts-rs/WindowSort.d.ts} +1 -1
  46. package/{src/ts/ts-rs/WindowSpec.ts → dist/ts-rs/WindowSpec.d.ts} +1 -1
  47. package/{src/ts/ts-rs/Windows.ts → dist/ts-rs/Windows.d.ts} +1 -1
  48. package/{src/ts/ts-rs/WorkspaceConfig.ts → dist/ts-rs/WorkspaceConfig.d.ts} +5 -5
  49. package/{src/ts/ts-rs/WorkspaceConfigUpdate.ts → dist/ts-rs/WorkspaceConfigUpdate.d.ts} +10 -5
  50. package/dist/wasm/perspective-viewer.d.ts +192 -65
  51. package/dist/wasm/perspective-viewer.js +331 -118
  52. package/dist/wasm/perspective-viewer.wasm +0 -0
  53. package/dist/wasm/perspective-viewer.wasm.d.ts +24 -16
  54. package/dist/wasm/snippets/{perspective-viewer-7fc45549159e01e4 → perspective-viewer-c26bfdc60d367a99}/inline4.js +0 -6
  55. package/package.json +11 -15
  56. package/dist/esm/ts-rs/AddPanelOptions.d.ts +0 -9
  57. package/dist/esm/ts-rs/Aggregate.d.ts +0 -1
  58. package/dist/esm/ts-rs/ClientOptions.d.ts +0 -7
  59. package/dist/esm/ts-rs/ColumnSelectMode.d.ts +0 -1
  60. package/dist/esm/ts-rs/CompactDisplay.d.ts +0 -5
  61. package/dist/esm/ts-rs/CurrencyCode.d.ts +0 -1
  62. package/dist/esm/ts-rs/CurrencyDisplay.d.ts +0 -1
  63. package/dist/esm/ts-rs/CurrencyNumberFormatStyle.d.ts +0 -8
  64. package/dist/esm/ts-rs/CurrencySign.d.ts +0 -1
  65. package/dist/esm/ts-rs/CustomDatetimeFormat.d.ts +0 -1
  66. package/dist/esm/ts-rs/CustomDatetimeStyleConfig.d.ts +0 -54
  67. package/dist/esm/ts-rs/CustomNumberFormatConfig.d.ts +0 -34
  68. package/dist/esm/ts-rs/DatetimeFormatType.d.ts +0 -6
  69. package/dist/esm/ts-rs/DerivedTableConfig.d.ts +0 -35
  70. package/dist/esm/ts-rs/ExportMethod.d.ts +0 -1
  71. package/dist/esm/ts-rs/ExportOptions.d.ts +0 -9
  72. package/dist/esm/ts-rs/Expressions.d.ts +0 -3
  73. package/dist/esm/ts-rs/Filter.d.ts +0 -2
  74. package/dist/esm/ts-rs/FilterReducer.d.ts +0 -1
  75. package/dist/esm/ts-rs/FilterTerm.d.ts +0 -2
  76. package/dist/esm/ts-rs/FormatUnit.d.ts +0 -1
  77. package/dist/esm/ts-rs/GetClientOptions.d.ts +0 -8
  78. package/dist/esm/ts-rs/GetTableOptions.d.ts +0 -8
  79. package/dist/esm/ts-rs/GetViewMode.d.ts +0 -4
  80. package/dist/esm/ts-rs/GetViewOptions.d.ts +0 -8
  81. package/dist/esm/ts-rs/GroupRollupMode.d.ts +0 -1
  82. package/dist/esm/ts-rs/Layout.d.ts +0 -11
  83. package/dist/esm/ts-rs/Notation.d.ts +0 -17
  84. package/dist/esm/ts-rs/NumberFormatStyle.d.ts +0 -18
  85. package/dist/esm/ts-rs/OnUpdateData.d.ts +0 -6
  86. package/dist/esm/ts-rs/OptionalUpdate.d.ts +0 -1
  87. package/dist/esm/ts-rs/Orientation.d.ts +0 -5
  88. package/dist/esm/ts-rs/PanelOptions.d.ts +0 -7
  89. package/dist/esm/ts-rs/PanelViewerConfig.d.ts +0 -82
  90. package/dist/esm/ts-rs/PluginStaticConfig.d.ts +0 -112
  91. package/dist/esm/ts-rs/RestoreOptions.d.ts +0 -21
  92. package/dist/esm/ts-rs/RestoreWorkspaceOptions.d.ts +0 -9
  93. package/dist/esm/ts-rs/RoundingMode.d.ts +0 -1
  94. package/dist/esm/ts-rs/RoundingPriority.d.ts +0 -1
  95. package/dist/esm/ts-rs/SaveWorkspaceOptions.d.ts +0 -10
  96. package/dist/esm/ts-rs/Scalar.d.ts +0 -5
  97. package/dist/esm/ts-rs/SignDisplay.d.ts +0 -1
  98. package/dist/esm/ts-rs/SimpleDatetimeFormat.d.ts +0 -1
  99. package/dist/esm/ts-rs/SimpleDatetimeStyleConfig.d.ts +0 -24
  100. package/dist/esm/ts-rs/Sort.d.ts +0 -2
  101. package/dist/esm/ts-rs/SortDir.d.ts +0 -1
  102. package/dist/esm/ts-rs/SplitLayout.d.ts +0 -20
  103. package/dist/esm/ts-rs/SplitRollupMode.d.ts +0 -9
  104. package/dist/esm/ts-rs/TabLayout.d.ts +0 -13
  105. package/dist/esm/ts-rs/TableRef.d.ts +0 -9
  106. package/dist/esm/ts-rs/TrailingZeroDisplay.d.ts +0 -1
  107. package/dist/esm/ts-rs/Unit.d.ts +0 -1
  108. package/dist/esm/ts-rs/UnitDisplay.d.ts +0 -1
  109. package/dist/esm/ts-rs/UnitNumberFormatStyle.d.ts +0 -6
  110. package/dist/esm/ts-rs/UseGrouping.d.ts +0 -1
  111. package/dist/esm/ts-rs/ViewOnUpdateResp.d.ts +0 -4
  112. package/dist/esm/ts-rs/ViewerConfig.d.ts +0 -86
  113. package/dist/esm/ts-rs/ViewerConfigInitial.d.ts +0 -175
  114. package/dist/esm/ts-rs/ViewerConfigUpdate.d.ts +0 -182
  115. package/dist/esm/ts-rs/WindowSort.d.ts +0 -7
  116. package/dist/esm/ts-rs/WindowSortDir.d.ts +0 -6
  117. package/dist/esm/ts-rs/WindowSpec.d.ts +0 -47
  118. package/dist/esm/ts-rs/Windows.d.ts +0 -10
  119. package/dist/esm/ts-rs/WorkspaceConfig.d.ts +0 -56
  120. package/dist/esm/ts-rs/WorkspaceConfigUpdate.d.ts +0 -57
  121. package/dist/esm/ts-rs/serde_json/JsonValue.d.ts +0 -3
  122. package/src/css/_column_dropdown.css +0 -14
  123. package/src/css/_context_menu.css +0 -14
  124. package/src/css/_dropdown_menu.css +0 -14
  125. package/src/css/_filter_dropdown.css +0 -14
  126. package/src/css/_function_dropdown.css +0 -14
  127. package/src/css/_viewer_bundle.css +0 -41
  128. package/src/css/aggregate-selector.css +0 -75
  129. package/src/css/column-dropdown.css +0 -106
  130. package/src/css/column-selector.css +0 -729
  131. package/src/css/column-settings-panel.css +0 -164
  132. package/src/css/column-style.css +0 -774
  133. package/src/css/column-symbol-attributes.css +0 -74
  134. package/src/css/config-selector.css +0 -505
  135. package/src/css/containers/pairs-list.css +0 -47
  136. package/src/css/empty-column.css +0 -73
  137. package/src/css/expression-editor.css +0 -153
  138. package/src/css/filter-dropdown.css +0 -54
  139. package/src/css/filter-item.css +0 -127
  140. package/src/css/form/code-editor.css +0 -133
  141. package/src/css/form/debug.css +0 -115
  142. package/src/css/function-dropdown.css +0 -46
  143. package/src/css/panel-tab.css +0 -216
  144. package/src/css/plugin-selector.css +0 -292
  145. package/src/css/render-warning.css +0 -82
  146. package/src/css/status-bar.css +0 -647
  147. package/src/css/type-icon.css +0 -114
  148. package/src/css/ui/containers/context-menu.css +0 -124
  149. package/src/css/ui/containers/dropdown-menu-items.css +0 -95
  150. package/src/css/ui/containers/dropdown-menu.css +0 -50
  151. package/src/css/ui/containers/scroll-panel.css +0 -31
  152. package/src/css/ui/containers/split-panel.css +0 -81
  153. package/src/css/ui/containers/tabs.css +0 -55
  154. package/src/css/ui/dom/checkbox.css +0 -98
  155. package/src/css/ui/dom/scrollbar.css +0 -35
  156. package/src/css/ui/dom/select.css +0 -74
  157. package/src/css/ui/form/mirrored-textarea.css +0 -81
  158. package/src/css/viewer.css +0 -1003
  159. package/src/rust/agent/client/mod.rs +0 -19
  160. package/src/rust/agent/client/protocol.rs +0 -231
  161. package/src/rust/agent/client/transport.rs +0 -287
  162. package/src/rust/agent/client/turn.rs +0 -174
  163. package/src/rust/agent/config.rs +0 -159
  164. package/src/rust/agent/docs.rs +0 -293
  165. package/src/rust/agent/markdown/block.rs +0 -509
  166. package/src/rust/agent/markdown/entity.rs +0 -52
  167. package/src/rust/agent/markdown/events.rs +0 -71
  168. package/src/rust/agent/markdown/inline.rs +0 -497
  169. package/src/rust/agent/markdown/mod.rs +0 -228
  170. package/src/rust/agent/mod.rs +0 -23
  171. package/src/rust/agent/preamble.md +0 -19
  172. package/src/rust/agent/runtime.rs +0 -201
  173. package/src/rust/agent/slot.rs +0 -236
  174. package/src/rust/agent/tools.rs +0 -1482
  175. package/src/rust/components/chat_panel.rs +0 -289
  176. package/src/rust/components/code_editor/highlight.rs +0 -52
  177. package/src/rust/components/code_editor.rs +0 -302
  178. package/src/rust/components/column_dropdown.rs +0 -284
  179. package/src/rust/components/column_selector/active_column.rs +0 -497
  180. package/src/rust/components/column_selector/add_expression_button.rs +0 -48
  181. package/src/rust/components/column_selector/aggregate_selector.rs +0 -193
  182. package/src/rust/components/column_selector/column_selector_column_row.rs +0 -73
  183. package/src/rust/components/column_selector/config_selector.rs +0 -932
  184. package/src/rust/components/column_selector/derived_control.rs +0 -229
  185. package/src/rust/components/column_selector/empty_column.rs +0 -136
  186. package/src/rust/components/column_selector/expr_edit_button.rs +0 -59
  187. package/src/rust/components/column_selector/filter_column.rs +0 -530
  188. package/src/rust/components/column_selector/inactive_column.rs +0 -246
  189. package/src/rust/components/column_selector/invalid_column.rs +0 -22
  190. package/src/rust/components/column_selector/pivot_column.rs +0 -130
  191. package/src/rust/components/column_selector/sort_column.rs +0 -148
  192. package/src/rust/components/column_selector.rs +0 -628
  193. package/src/rust/components/column_settings_sidebar/attributes_tab.rs +0 -34
  194. package/src/rust/components/column_settings_sidebar/save_settings.rs +0 -72
  195. package/src/rust/components/column_settings_sidebar/style_tab/agg_depth_selector.rs +0 -66
  196. package/src/rust/components/column_settings_sidebar/style_tab/alignment_field.rs +0 -90
  197. package/src/rust/components/column_settings_sidebar/style_tab/font_field.rs +0 -267
  198. package/src/rust/components/column_settings_sidebar/style_tab/primitive_field.rs +0 -560
  199. package/src/rust/components/column_settings_sidebar/style_tab/symbol/row_selector.rs +0 -101
  200. package/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs.rs +0 -91
  201. package/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs_item.rs +0 -112
  202. package/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_selector.rs +0 -54
  203. package/src/rust/components/column_settings_sidebar/style_tab/symbol.rs +0 -143
  204. package/src/rust/components/column_settings_sidebar/style_tab.rs +0 -499
  205. package/src/rust/components/column_settings_sidebar/window_tab.rs +0 -34
  206. package/src/rust/components/column_settings_sidebar.rs +0 -622
  207. package/src/rust/components/copy_dropdown.rs +0 -111
  208. package/src/rust/components/datetime_column_style/custom.rs +0 -220
  209. package/src/rust/components/datetime_column_style/simple.rs +0 -131
  210. package/src/rust/components/datetime_column_style.rs +0 -259
  211. package/src/rust/components/debug_panel.rs +0 -350
  212. package/src/rust/components/dragdrop_list.rs +0 -473
  213. package/src/rust/components/editable_header.rs +0 -147
  214. package/src/rust/components/empty_row.rs +0 -166
  215. package/src/rust/components/export_dropdown.rs +0 -132
  216. package/src/rust/components/expression_editor.rs +0 -172
  217. package/src/rust/components/filter_dropdown.rs +0 -288
  218. package/src/rust/components/function_dropdown.rs +0 -224
  219. package/src/rust/components/global_filter_bar.rs +0 -76
  220. package/src/rust/components/main_panel/frame_theme.rs +0 -130
  221. package/src/rust/components/main_panel/msg.rs +0 -68
  222. package/src/rust/components/main_panel/presize.rs +0 -220
  223. package/src/rust/components/main_panel/reconcile.rs +0 -271
  224. package/src/rust/components/main_panel/render.rs +0 -455
  225. package/src/rust/components/main_panel/update.rs +0 -212
  226. package/src/rust/components/main_panel.rs +0 -470
  227. package/src/rust/components/mod.rs +0 -50
  228. package/src/rust/components/new_panel_menu.rs +0 -165
  229. package/src/rust/components/number_series_style.rs +0 -157
  230. package/src/rust/components/panel_menu.rs +0 -518
  231. package/src/rust/components/panel_tab.rs +0 -567
  232. package/src/rust/components/plugin_selector.rs +0 -132
  233. package/src/rust/components/plugin_tab.rs +0 -285
  234. package/src/rust/components/render_warning.rs +0 -128
  235. package/src/rust/components/rows_counter.rs +0 -124
  236. package/src/rust/components/settings_panel.rs +0 -406
  237. package/src/rust/components/status_bar.rs +0 -595
  238. package/src/rust/components/status_indicator.rs +0 -125
  239. package/src/rust/components/style.rs +0 -107
  240. package/src/rust/components/style_controls/mod.rs +0 -15
  241. package/src/rust/components/style_controls/number_string_format/digits_section.rs +0 -150
  242. package/src/rust/components/style_controls/number_string_format/misc_section.rs +0 -60
  243. package/src/rust/components/style_controls/number_string_format/style_section.rs +0 -70
  244. package/src/rust/components/style_controls/number_string_format/types.rs +0 -55
  245. package/src/rust/components/style_controls/number_string_format.rs +0 -258
  246. package/src/rust/components/type_icon.rs +0 -53
  247. package/src/rust/components/viewer/filters.rs +0 -145
  248. package/src/rust/components/viewer/msg.rs +0 -242
  249. package/src/rust/components/viewer/panels.rs +0 -397
  250. package/src/rust/components/viewer/render.rs +0 -266
  251. package/src/rust/components/viewer/settings.rs +0 -621
  252. package/src/rust/components/viewer/snapshots.rs +0 -154
  253. package/src/rust/components/viewer/wiring.rs +0 -500
  254. package/src/rust/components/viewer.rs +0 -429
  255. package/src/rust/components/window_editor.rs +0 -985
  256. package/src/rust/config/column_config_schema.rs +0 -525
  257. package/src/rust/config/columns_config.rs +0 -39
  258. package/src/rust/config/datetime_column_style/custom.rs +0 -138
  259. package/src/rust/config/datetime_column_style/custom_format.rs +0 -90
  260. package/src/rust/config/datetime_column_style/simple.rs +0 -65
  261. package/src/rust/config/datetime_column_style/simple_format.rs +0 -86
  262. package/src/rust/config/datetime_column_style.rs +0 -66
  263. package/src/rust/config/export_method.rs +0 -175
  264. package/src/rust/config/kvpair.rs +0 -47
  265. package/src/rust/config/mod.rs +0 -39
  266. package/src/rust/config/number_series_style.rs +0 -79
  267. package/src/rust/config/number_string_format/enums.rs +0 -298
  268. package/src/rust/config/number_string_format.rs +0 -424
  269. package/src/rust/config/options.rs +0 -145
  270. package/src/rust/config/plugin_static_config.rs +0 -217
  271. package/src/rust/config/view_config.rs +0 -24
  272. package/src/rust/config/viewer_config.rs +0 -461
  273. package/src/rust/config/workspace_config.rs +0 -297
  274. package/src/rust/custom_elements/debug_plugin.rs +0 -122
  275. package/src/rust/custom_elements/mod.rs +0 -17
  276. package/src/rust/custom_elements/viewer.rs +0 -2255
  277. package/src/rust/custom_events.rs +0 -423
  278. package/src/rust/derived.rs +0 -266
  279. package/src/rust/exprtk/cursor.rs +0 -90
  280. package/src/rust/exprtk/mod.rs +0 -19
  281. package/src/rust/exprtk/tokenize/comment.rs +0 -21
  282. package/src/rust/exprtk/tokenize/number.rs +0 -44
  283. package/src/rust/exprtk/tokenize/string.rs +0 -98
  284. package/src/rust/exprtk/tokenize/symbol.rs +0 -26
  285. package/src/rust/exprtk/tokenize.rs +0 -153
  286. package/src/rust/js/clipboard.rs +0 -77
  287. package/src/rust/js/clipboard_item.rs +0 -21
  288. package/src/rust/js/intersection_observer.rs +0 -32
  289. package/src/rust/js/mimetype.rs +0 -37
  290. package/src/rust/js/mod.rs +0 -30
  291. package/src/rust/js/plugin.rs +0 -324
  292. package/src/rust/js/regular_layout.rs +0 -480
  293. package/src/rust/js/resize_observer.rs +0 -37
  294. package/src/rust/lib.rs +0 -204
  295. package/src/rust/presentation/column_locator.rs +0 -115
  296. package/src/rust/presentation/props.rs +0 -47
  297. package/src/rust/presentation/sheets.rs +0 -78
  298. package/src/rust/presentation.rs +0 -825
  299. package/src/rust/queries/column_locator.rs +0 -114
  300. package/src/rust/queries/column_values.rs +0 -59
  301. package/src/rust/queries/columns_iter_set.rs +0 -331
  302. package/src/rust/queries/export_app.rs +0 -59
  303. package/src/rust/queries/exports.rs +0 -96
  304. package/src/rust/queries/fetch_column_stats.rs +0 -94
  305. package/src/rust/queries/get_viewer_config.rs +0 -73
  306. package/src/rust/queries/hosted_tables.rs +0 -38
  307. package/src/rust/queries/is_invalid_drop.rs +0 -36
  308. package/src/rust/queries/mod.rs +0 -48
  309. package/src/rust/queries/palette_set.rs +0 -82
  310. package/src/rust/queries/plugin_column_styles.rs +0 -105
  311. package/src/rust/queries/validate_expression.rs +0 -39
  312. package/src/rust/renderer/activate.rs +0 -90
  313. package/src/rust/renderer/dispatch.rs +0 -564
  314. package/src/rust/renderer/limits.rs +0 -104
  315. package/src/rust/renderer/plugin_config.rs +0 -1129
  316. package/src/rust/renderer/plugin_store.rs +0 -58
  317. package/src/rust/renderer/props.rs +0 -69
  318. package/src/rust/renderer/registry.rs +0 -175
  319. package/src/rust/renderer/render_timer.rs +0 -204
  320. package/src/rust/renderer/state.rs +0 -205
  321. package/src/rust/renderer.rs +0 -868
  322. package/src/rust/root.rs +0 -50
  323. package/src/rust/session/column_defaults_update.rs +0 -194
  324. package/src/rust/session/drag_drop_update.rs +0 -197
  325. package/src/rust/session/metadata.rs +0 -415
  326. package/src/rust/session/op_queue.rs +0 -430
  327. package/src/rust/session/panel_state.rs +0 -327
  328. package/src/rust/session/props.rs +0 -193
  329. package/src/rust/session/replace_expression_update.rs +0 -133
  330. package/src/rust/session/view_subscription.rs +0 -266
  331. package/src/rust/session.rs +0 -1901
  332. package/src/rust/tasks/apply_global_filters.rs +0 -103
  333. package/src/rust/tasks/auto_pause.rs +0 -181
  334. package/src/rust/tasks/copy_export.rs +0 -296
  335. package/src/rust/tasks/create_panel.rs +0 -268
  336. package/src/rust/tasks/derive.rs +0 -312
  337. package/src/rust/tasks/dismiss_render_warning.rs +0 -35
  338. package/src/rust/tasks/edit_expression.rs +0 -92
  339. package/src/rust/tasks/edit_window.rs +0 -153
  340. package/src/rust/tasks/eject.rs +0 -89
  341. package/src/rust/tasks/mod.rs +0 -80
  342. package/src/rust/tasks/pipeline.rs +0 -425
  343. package/src/rust/tasks/presize_panels.rs +0 -386
  344. package/src/rust/tasks/reset_all.rs +0 -119
  345. package/src/rust/tasks/resize_observer.rs +0 -173
  346. package/src/rust/tasks/restore_derived.rs +0 -200
  347. package/src/rust/tasks/restore_panel.rs +0 -271
  348. package/src/rust/tasks/send_column_config.rs +0 -87
  349. package/src/rust/tasks/send_plugin_config.rs +0 -83
  350. package/src/rust/tasks/set_edit_mode.rs +0 -69
  351. package/src/rust/tasks/sync_update_panels.rs +0 -244
  352. package/src/rust/tasks/table_lifecycle.rs +0 -200
  353. package/src/rust/tasks/transactional_restore.rs +0 -387
  354. package/src/rust/tasks/update_theme.rs +0 -139
  355. package/src/rust/tasks/validate_expression.rs +0 -61
  356. package/src/rust/ui/containers/control_group.rs +0 -113
  357. package/src/rust/ui/containers/dropdown_menu.rs +0 -103
  358. package/src/rust/ui/containers/mod.rs +0 -21
  359. package/src/rust/ui/containers/scroll_panel.rs +0 -315
  360. package/src/rust/ui/containers/scroll_panel_item.rs +0 -98
  361. package/src/rust/ui/containers/select.rs +0 -271
  362. package/src/rust/ui/containers/sidebar.rs +0 -125
  363. package/src/rust/ui/containers/sidebar_close_button.rs +0 -30
  364. package/src/rust/ui/containers/split_panel.rs +0 -498
  365. package/src/rust/ui/containers/tab_list.rs +0 -101
  366. package/src/rust/ui/context_menu.rs +0 -264
  367. package/src/rust/ui/dragdrop.rs +0 -201
  368. package/src/rust/ui/font_loader.rs +0 -201
  369. package/src/rust/ui/form/color_selector.rs +0 -58
  370. package/src/rust/ui/form/intl_label.rs +0 -62
  371. package/src/rust/ui/form/mirrored_textarea.rs +0 -100
  372. package/src/rust/ui/form/mod.rs +0 -24
  373. package/src/rust/ui/form/multi_stop_gradient_selector.rs +0 -386
  374. package/src/rust/ui/form/named_value_picker.rs +0 -81
  375. package/src/rust/ui/form/number_field.rs +0 -72
  376. package/src/rust/ui/form/number_input.rs +0 -45
  377. package/src/rust/ui/form/number_range_field.rs +0 -77
  378. package/src/rust/ui/form/optional_field.rs +0 -55
  379. package/src/rust/ui/form/palette_selector.rs +0 -388
  380. package/src/rust/ui/form/select_enum_field.rs +0 -59
  381. package/src/rust/ui/form/select_value_field.rs +0 -64
  382. package/src/rust/ui/mod.rs +0 -56
  383. package/src/rust/ui/modal.rs +0 -61
  384. package/src/rust/ui/portal.rs +0 -374
  385. package/src/rust/ui/style.rs +0 -56
  386. package/src/rust/utils/browser/blob.rs +0 -63
  387. package/src/rust/utils/browser/download.rs +0 -27
  388. package/src/rust/utils/browser/dragdrop.rs +0 -38
  389. package/src/rust/utils/browser/mod.rs +0 -27
  390. package/src/rust/utils/browser/mouse.rs +0 -24
  391. package/src/rust/utils/browser/request_animation_frame.rs +0 -95
  392. package/src/rust/utils/browser/selection.rs +0 -84
  393. package/src/rust/utils/completion.rs +0 -50
  394. package/src/rust/utils/css.rs +0 -525
  395. package/src/rust/utils/css_vars.rs +0 -39
  396. package/src/rust/utils/custom_element.rs +0 -105
  397. package/src/rust/utils/datetime.rs +0 -54
  398. package/src/rust/utils/debounce.rs +0 -232
  399. package/src/rust/utils/hooks/mod.rs +0 -15
  400. package/src/rust/utils/hooks/use_async_callback.rs +0 -43
  401. package/src/rust/utils/in_flight.rs +0 -74
  402. package/src/rust/utils/local_fonts.rs +0 -359
  403. package/src/rust/utils/mod.rs +0 -56
  404. package/src/rust/utils/modal_position.rs +0 -104
  405. package/src/rust/utils/number_format.rs +0 -49
  406. package/src/rust/utils/pending_effects.rs +0 -38
  407. package/src/rust/utils/plugin_host_state.rs +0 -43
  408. package/src/rust/utils/ptr_eq_rc.rs +0 -74
  409. package/src/rust/utils/pubsub.rs +0 -236
  410. package/src/rust/utils/spawn.rs +0 -33
  411. package/src/rust/utils/weak_scope.rs +0 -39
  412. package/src/rust/workspace.rs +0 -1195
  413. package/src/svg/active-indicator.svg +0 -3
  414. package/src/svg/align-scroll-icon.svg +0 -7
  415. package/src/svg/bg-pattern.png +0 -0
  416. package/src/svg/bookmark-icon.svg +0 -4
  417. package/src/svg/boolean-type.svg +0 -4
  418. package/src/svg/checkbox-checked-icon.svg +0 -4
  419. package/src/svg/checkbox-hover.svg +0 -4
  420. package/src/svg/checkbox-off.svg +0 -3
  421. package/src/svg/checkbox-on.svg +0 -4
  422. package/src/svg/checkbox-unchecked-icon.svg +0 -3
  423. package/src/svg/close-icon.svg +0 -6
  424. package/src/svg/column-settings-icon.svg +0 -6
  425. package/src/svg/datagrid-select-column.svg +0 -8
  426. package/src/svg/datagrid-select-region.svg +0 -8
  427. package/src/svg/datagrid-select-row-tree.svg +0 -8
  428. package/src/svg/datagrid-select-row.svg +0 -8
  429. package/src/svg/datagrid.svg +0 -13
  430. package/src/svg/date-type.svg +0 -4
  431. package/src/svg/derived.svg +0 -6
  432. package/src/svg/downloading.gif +0 -0
  433. package/src/svg/drag-handle copy.svg +0 -10
  434. package/src/svg/drag-handle.svg +0 -10
  435. package/src/svg/drawer-bg-pattern-hidpi.png +0 -0
  436. package/src/svg/drawer-tab-hover.svg +0 -4
  437. package/src/svg/drawer-tab-invert-hover.svg +0 -5
  438. package/src/svg/drawer-tab-invert.svg +0 -3
  439. package/src/svg/drawer-tab.svg +0 -5
  440. package/src/svg/dropdown-selector.svg +0 -3
  441. package/src/svg/duplicate-icon.svg +0 -4
  442. package/src/svg/editable-icon.svg +0 -5
  443. package/src/svg/export-icon.svg +0 -4
  444. package/src/svg/expression.svg +0 -10
  445. package/src/svg/free-scroll-icon.svg +0 -5
  446. package/src/svg/inactive-mouseover.svg +0 -4
  447. package/src/svg/lock.svg +0 -7
  448. package/src/svg/mega-menu-icons-candlestick.svg +0 -6
  449. package/src/svg/mega-menu-icons-datagrid.svg +0 -37
  450. package/src/svg/mega-menu-icons-density.svg +0 -23
  451. package/src/svg/mega-menu-icons-heatmap.svg +0 -60
  452. package/src/svg/mega-menu-icons-map-density.svg +0 -24
  453. package/src/svg/mega-menu-icons-map-line.svg +0 -19
  454. package/src/svg/mega-menu-icons-map-scatter.svg +0 -43
  455. package/src/svg/mega-menu-icons-ohlc.svg +0 -5
  456. package/src/svg/mega-menu-icons-sunburst.svg +0 -5
  457. package/src/svg/mega-menu-icons-treemap.svg +0 -4
  458. package/src/svg/mega-menu-icons-x-bar.svg +0 -36
  459. package/src/svg/mega-menu-icons-x-y-line.svg +0 -38
  460. package/src/svg/mega-menu-icons-x-y-scatter.svg +0 -72
  461. package/src/svg/mega-menu-icons-y-area.svg +0 -73
  462. package/src/svg/mega-menu-icons-y-bar.svg +0 -36
  463. package/src/svg/mega-menu-icons-y-line.svg +0 -36
  464. package/src/svg/mega-menu-icons-y-scatter.svg +0 -12
  465. package/src/svg/new-panel-icon.svg +0 -4
  466. package/src/svg/number-type.svg +0 -4
  467. package/src/svg/pin-icon.svg +0 -5
  468. package/src/svg/radio-hover.svg +0 -4
  469. package/src/svg/radio-off.svg +0 -3
  470. package/src/svg/radio-on.svg +0 -4
  471. package/src/svg/read-only-icon.svg +0 -6
  472. package/src/svg/revert-icon.svg +0 -4
  473. package/src/svg/sort-abs-asc-icon.svg +0 -3
  474. package/src/svg/sort-abs-col-asc-icon.svg +0 -3
  475. package/src/svg/sort-abs-col-desc-icon.svg +0 -3
  476. package/src/svg/sort-abs-desc-icon.svg +0 -3
  477. package/src/svg/sort-asc-icon.svg +0 -4
  478. package/src/svg/sort-col-asc-icon.svg +0 -4
  479. package/src/svg/sort-col-desc-icon.svg +0 -4
  480. package/src/svg/sort-desc-icon.svg +0 -4
  481. package/src/svg/sort-none-icon.svg +0 -3
  482. package/src/svg/status_error.svg +0 -70
  483. package/src/svg/status_ok.svg +0 -3
  484. package/src/svg/status_pending.svg +0 -3
  485. package/src/svg/string-type.svg +0 -4
  486. package/src/svg/theme-icon.svg +0 -5
  487. package/src/svg/updating.gif +0 -0
  488. package/src/themes/blueprint.css +0 -133
  489. package/src/themes/botanical.css +0 -97
  490. package/src/themes/defaults.css +0 -68
  491. package/src/themes/dracula.css +0 -167
  492. package/src/themes/eggplant.css +0 -131
  493. package/src/themes/gruvbox-dark.css +0 -183
  494. package/src/themes/gruvbox.css +0 -97
  495. package/src/themes/icons.css +0 -110
  496. package/src/themes/intl/ar.css +0 -209
  497. package/src/themes/intl/de.css +0 -218
  498. package/src/themes/intl/es.css +0 -218
  499. package/src/themes/intl/fr.css +0 -218
  500. package/src/themes/intl/ja.css +0 -218
  501. package/src/themes/intl/pt.css +0 -218
  502. package/src/themes/intl/zh.css +0 -218
  503. package/src/themes/intl.css +0 -220
  504. package/src/themes/ledger.css +0 -137
  505. package/src/themes/monokai.css +0 -181
  506. package/src/themes/nord.css +0 -131
  507. package/src/themes/phosphor.css +0 -125
  508. package/src/themes/pro-dark.css +0 -113
  509. package/src/themes/pro.css +0 -117
  510. package/src/themes/solarized-dark.css +0 -85
  511. package/src/themes/solarized.css +0 -72
  512. package/src/themes/themes.css +0 -28
  513. package/src/themes/vaporwave.css +0 -191
  514. package/src/themes/velvet.css +0 -132
  515. package/src/ts/bootstrap.ts +0 -38
  516. package/src/ts/column-format.ts +0 -233
  517. package/src/ts/extensions.ts +0 -236
  518. package/src/ts/perspective-viewer.cdn.ts +0 -19
  519. package/src/ts/perspective-viewer.ts +0 -72
  520. package/src/ts/perspective-viewer.worker.ts +0 -14
  521. package/src/ts/plugin.ts +0 -296
  522. package/src/ts/providers.ts +0 -96
  523. package/src/ts/select-detail.ts +0 -48
  524. package/src/ts/ts-rs/CustomDatetimeFormat.ts +0 -3
  525. package/src/ts/ts-rs/CustomDatetimeStyleConfig.ts +0 -54
  526. package/src/ts/ts-rs/DatetimeFormatType.ts +0 -8
  527. package/src/ts/ts-rs/FormatUnit.ts +0 -3
  528. package/src/ts/ts-rs/SimpleDatetimeStyleConfig.ts +0 -25
  529. package/tsconfig.json +0 -16
  530. /package/{src/ts/ts-rs/AddPanelOptions.ts → dist/ts-rs/AddPanelOptions.d.ts} +0 -0
  531. /package/{src/ts/ts-rs/Aggregate.ts → dist/ts-rs/Aggregate.d.ts} +0 -0
  532. /package/{src/ts/ts-rs/ClientOptions.ts → dist/ts-rs/ClientOptions.d.ts} +0 -0
  533. /package/{src/ts/ts-rs/ColumnSelectMode.ts → dist/ts-rs/ColumnSelectMode.d.ts} +0 -0
  534. /package/{src/ts/ts-rs/CompactDisplay.ts → dist/ts-rs/CompactDisplay.d.ts} +0 -0
  535. /package/{src/ts/ts-rs/CurrencyCode.ts → dist/ts-rs/CurrencyCode.d.ts} +0 -0
  536. /package/{src/ts/ts-rs/CurrencyDisplay.ts → dist/ts-rs/CurrencyDisplay.d.ts} +0 -0
  537. /package/{src/ts/ts-rs/CurrencySign.ts → dist/ts-rs/CurrencySign.d.ts} +0 -0
  538. /package/{src/ts/ts-rs/ExportMethod.ts → dist/ts-rs/ExportMethod.d.ts} +0 -0
  539. /package/{src/ts/ts-rs/Expressions.ts → dist/ts-rs/Expressions.d.ts} +0 -0
  540. /package/{src/ts/ts-rs/FilterReducer.ts → dist/ts-rs/FilterReducer.d.ts} +0 -0
  541. /package/{src/ts/ts-rs/GetClientOptions.ts → dist/ts-rs/GetClientOptions.d.ts} +0 -0
  542. /package/{src/ts/ts-rs/GetTableOptions.ts → dist/ts-rs/GetTableOptions.d.ts} +0 -0
  543. /package/{src/ts/ts-rs/GetViewMode.ts → dist/ts-rs/GetViewMode.d.ts} +0 -0
  544. /package/{src/ts/ts-rs/GroupRollupMode.ts → dist/ts-rs/GroupRollupMode.d.ts} +0 -0
  545. /package/{src/ts/ts-rs/OptionalUpdate.ts → dist/ts-rs/OptionalUpdate.d.ts} +0 -0
  546. /package/{src/ts/ts-rs/Orientation.ts → dist/ts-rs/Orientation.d.ts} +0 -0
  547. /package/{src/ts/ts-rs/PanelOptions.ts → dist/ts-rs/PanelOptions.d.ts} +0 -0
  548. /package/{src/ts/ts-rs/RestoreOptions.ts → dist/ts-rs/RestoreOptions.d.ts} +0 -0
  549. /package/{src/ts/ts-rs/RestoreWorkspaceOptions.ts → dist/ts-rs/RestoreWorkspaceOptions.d.ts} +0 -0
  550. /package/{src/ts/ts-rs/RoundingMode.ts → dist/ts-rs/RoundingMode.d.ts} +0 -0
  551. /package/{src/ts/ts-rs/RoundingPriority.ts → dist/ts-rs/RoundingPriority.d.ts} +0 -0
  552. /package/{src/ts/ts-rs/SaveWorkspaceOptions.ts → dist/ts-rs/SaveWorkspaceOptions.d.ts} +0 -0
  553. /package/{src/ts/ts-rs/Scalar.ts → dist/ts-rs/Scalar.d.ts} +0 -0
  554. /package/{src/ts/ts-rs/SignDisplay.ts → dist/ts-rs/SignDisplay.d.ts} +0 -0
  555. /package/{src/ts/ts-rs/SortDir.ts → dist/ts-rs/SortDir.d.ts} +0 -0
  556. /package/{src/ts/ts-rs/SplitRollupMode.ts → dist/ts-rs/SplitRollupMode.d.ts} +0 -0
  557. /package/{src/ts/ts-rs/TabLayout.ts → dist/ts-rs/TabLayout.d.ts} +0 -0
  558. /package/{src/ts/ts-rs/TrailingZeroDisplay.ts → dist/ts-rs/TrailingZeroDisplay.d.ts} +0 -0
  559. /package/{src/ts/ts-rs/UnitDisplay.ts → dist/ts-rs/UnitDisplay.d.ts} +0 -0
  560. /package/{src/ts/ts-rs/UseGrouping.ts → dist/ts-rs/UseGrouping.d.ts} +0 -0
  561. /package/{src/ts/ts-rs/ViewOnUpdateResp.ts → dist/ts-rs/ViewOnUpdateResp.d.ts} +0 -0
  562. /package/{src/ts/ts-rs/WindowSortDir.ts → dist/ts-rs/WindowSortDir.d.ts} +0 -0
  563. /package/{src/ts/ts-rs/serde_json/JsonValue.ts → dist/ts-rs/serde_json/JsonValue.d.ts} +0 -0
  564. /package/dist/wasm/snippets/{perspective-viewer-7fc45549159e01e4 → perspective-viewer-c26bfdc60d367a99}/inline0.js +0 -0
  565. /package/dist/wasm/snippets/{perspective-viewer-7fc45549159e01e4 → perspective-viewer-c26bfdc60d367a99}/inline1.js +0 -0
  566. /package/dist/wasm/snippets/{perspective-viewer-7fc45549159e01e4 → perspective-viewer-c26bfdc60d367a99}/inline2.js +0 -0
  567. /package/dist/wasm/snippets/{perspective-viewer-7fc45549159e01e4 → perspective-viewer-c26bfdc60d367a99}/inline3.js +0 -0
  568. /package/dist/wasm/snippets/{perspective-viewer-7fc45549159e01e4 → perspective-viewer-c26bfdc60d367a99}/inline5.js +0 -0
@@ -1,1482 +0,0 @@
1
- // ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2
- // ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3
- // ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4
- // ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5
- // ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6
- // ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7
- // ┃ Copyright (c) 2017, the Perspective Authors. ┃
8
- // ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9
- // ┃ This file is part of the Perspective library, distributed under the terms ┃
10
- // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11
- // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
-
13
- use std::collections::HashMap;
14
- use std::rc::Rc;
15
- use std::str::FromStr;
16
-
17
- use futures::future::LocalBoxFuture;
18
- use perspective_js::utils::ApiError;
19
- use serde::Deserialize;
20
- use serde_json::{Value, json};
21
- use wasm_bindgen::prelude::*;
22
-
23
- use super::client::protocol::{FunctionDef, ToolDef};
24
- use super::docs::{DocsBundle, DocsCell};
25
- use crate::config::{Alignment, ColumnConfigSchema, ControlSpec};
26
- use crate::custom_elements::viewer::PerspectiveViewerElement;
27
- use crate::queries::{
28
- get_column_config_schema, get_plugin_config_schema, get_viewer_config, validate_expr,
29
- };
30
- use crate::workspace::{Panel, PanelId};
31
-
32
- /// Host-grantable access classes (`agentConfig({entitlements})`). A tool
33
- /// whose entitlement is withheld is neither advertised nor dispatchable.
34
- #[derive(Clone, Copy, Debug, PartialEq)]
35
- pub enum Entitlement {
36
- ReadView,
37
- ConfigureView,
38
- ManageLayout,
39
- ReadDocs,
40
-
41
- // TODO(texodus): unused
42
- ReadData,
43
- }
44
-
45
- impl Entitlement {
46
- pub const VALID: &'static str =
47
- "read_view, configure_view, manage_layout, read_docs, read_data";
48
-
49
- /// The default grant: everything except raw data access.
50
- pub fn default_set() -> Vec<Self> {
51
- vec![
52
- Self::ReadView,
53
- Self::ConfigureView,
54
- Self::ManageLayout,
55
- Self::ReadDocs,
56
- ]
57
- }
58
- }
59
-
60
- impl FromStr for Entitlement {
61
- type Err = String;
62
-
63
- fn from_str(value: &str) -> Result<Self, String> {
64
- match value {
65
- "read_view" => Ok(Self::ReadView),
66
- "configure_view" => Ok(Self::ConfigureView),
67
- "manage_layout" => Ok(Self::ManageLayout),
68
- "read_docs" => Ok(Self::ReadDocs),
69
- "read_data" => Ok(Self::ReadData),
70
- other => Err(format!(
71
- "Unknown entitlement `{other}` - valid entitlements: {}",
72
- Self::VALID
73
- )),
74
- }
75
- }
76
- }
77
-
78
- /// Per-turn tool context, constructed by the runtime.
79
- pub struct ToolCtx {
80
- pub docs: Option<Rc<DocsCell>>,
81
- pub bundle: Option<Rc<Result<DocsBundle, String>>>,
82
- pub entitlements: Vec<Entitlement>,
83
- }
84
-
85
- impl ToolCtx {
86
- fn schemas(&self) -> Option<&HashMap<String, Value>> {
87
- self.bundle
88
- .as_ref()
89
- .and_then(|x| x.as_ref().as_ref().ok())
90
- .map(|x| &x.schemas)
91
- }
92
- }
93
-
94
- pub struct Tool {
95
- name: &'static str,
96
- description: &'static str,
97
- entitlement: Entitlement,
98
- available: fn(&ToolCtx) -> bool,
99
- parameters: fn(Option<&HashMap<String, Value>>) -> Value,
100
- call: for<'a> fn(
101
- &'a PerspectiveViewerElement,
102
- &'a ToolCtx,
103
- Value,
104
- ) -> LocalBoxFuture<'a, Result<Value, ToolError>>,
105
- }
106
-
107
- fn always(_: &ToolCtx) -> bool {
108
- true
109
- }
110
-
111
- fn panel_property() -> Value {
112
- json!({
113
- "type": "string",
114
- "description": "Panel id from `list_panels`; omit to target the active panel"
115
- })
116
- }
117
-
118
- /// The `config` property node + root `definitions` for tools taking a
119
- /// config argument (`key` = the generated schema's type name, e.g.
120
- /// `"ViewerConfigUpdate"`): the generated schema (from the docs metadata
121
- /// bundle) when available, else a permissive object. `require` lists
122
- /// config properties the AGENT contract requires beyond the public type
123
- /// (unioned into the definition's `required`, stated outright in the
124
- /// fallback) — the tool body must enforce the same fields at dispatch.
125
- /// `omit` lists public properties the agent contract withholds.
126
- fn spliced_config(
127
- schemas: Option<&HashMap<String, Value>>,
128
- key: &str,
129
- description: &str,
130
- require: &[&str],
131
- omit: &[&str],
132
- ) -> (Value, Option<Value>) {
133
- match schemas.and_then(|x| x.get(key)) {
134
- Some(schema) => {
135
- let mut definitions = schema
136
- .get("definitions")
137
- .and_then(|x| x.as_object())
138
- .cloned()
139
- .unwrap_or_default();
140
-
141
- let original = definitions.remove(key);
142
- let mut config = original
143
- .clone()
144
- .unwrap_or_else(|| json!({ "type": "object" }));
145
-
146
- if let Some(properties) = config["properties"].as_object_mut() {
147
- for field in omit {
148
- properties.remove(*field);
149
- }
150
- }
151
-
152
- let mut required = config["required"].as_array().cloned().unwrap_or_default();
153
- required.retain(|x| !omit.iter().any(|field| x == field));
154
- for field in require {
155
- if !required.iter().any(|x| x == field) {
156
- required.push(json!(field));
157
- }
158
- }
159
-
160
- if !required.is_empty() {
161
- config["required"] = Value::Array(required);
162
- }
163
-
164
- config["description"] = json!(description);
165
-
166
- // A self-recursive config type still needs its own entry.
167
- if let Some(original) = original
168
- && serde_json::to_string(&definitions)
169
- .unwrap_or_default()
170
- .contains(&format!("#/definitions/{key}"))
171
- {
172
- definitions.insert(key.to_owned(), original);
173
- }
174
-
175
- let reachable = reachable_definitions(&config, &definitions);
176
- definitions.retain(|name, _| reachable.contains(name));
177
- let definitions = (!definitions.is_empty()).then(|| Value::Object(definitions));
178
- (config, definitions)
179
- },
180
- None if require.is_empty() => (
181
- json!({ "type": "object", "description": description }),
182
- None,
183
- ),
184
- None => (
185
- json!({ "type": "object", "description": description, "required": require }),
186
- None,
187
- ),
188
- }
189
- }
190
-
191
- fn definition_refs(node: &Value, out: &mut Vec<String>) {
192
- match node {
193
- Value::Object(map) => {
194
- for (key, value) in map {
195
- match value
196
- .as_str()
197
- .and_then(|x| x.strip_prefix("#/definitions/"))
198
- {
199
- Some(name) if key == "$ref" => out.push(name.to_owned()),
200
- _ => definition_refs(value, out),
201
- }
202
- }
203
- },
204
- Value::Array(values) => {
205
- for value in values {
206
- definition_refs(value, out);
207
- }
208
- },
209
- _ => {},
210
- }
211
- }
212
-
213
- fn reachable_definitions(
214
- root: &Value,
215
- definitions: &serde_json::Map<String, Value>,
216
- ) -> Vec<String> {
217
- let mut pending = Vec::new();
218
- definition_refs(root, &mut pending);
219
- let mut reachable = Vec::new();
220
- while let Some(name) = pending.pop() {
221
- if reachable.contains(&name) {
222
- continue;
223
- }
224
-
225
- if let Some(definition) = definitions.get(&name) {
226
- definition_refs(definition, &mut pending);
227
- }
228
-
229
- reachable.push(name);
230
- }
231
-
232
- reachable
233
- }
234
-
235
- fn config_parameters(
236
- schemas: Option<&HashMap<String, Value>>,
237
- key: &str,
238
- description: &str,
239
- with_panel: bool,
240
- require: &[&str],
241
- omit: &[&str],
242
- ) -> Value {
243
- let (config, definitions) = spliced_config(schemas, key, description, require, omit);
244
- let mut properties = json!({ "config": config });
245
- if with_panel {
246
- properties["panel"] = panel_property();
247
- }
248
-
249
- let mut parameters = json!({
250
- "type": "object",
251
- "properties": properties,
252
- "required": ["config"]
253
- });
254
-
255
- if let Some(definitions) = definitions {
256
- parameters["definitions"] = definitions;
257
- }
258
-
259
- parameters
260
- }
261
-
262
- static TOOLS: &[Tool] = &[
263
- Tool {
264
- name: "get_schema",
265
- description: "Get the column schema (column name -> type) and row count of the data \
266
- currently loaded in a panel. Call this before configuring the view - column \
267
- names must match exactly.",
268
- entitlement: Entitlement::ReadView,
269
- available: always,
270
- parameters: |_| {
271
- json!({
272
- "type": "object",
273
- "properties": { "panel": panel_property() }
274
- })
275
- },
276
- call: |elem, ctx, args| Box::pin(elem.tool_get_schema(ctx, args)),
277
- },
278
- Tool {
279
- name: "get_view_config",
280
- description: "Get a panel's current configuration (plugin, group_by, split_by, columns, \
281
- filter, sort, aggregates, expressions).",
282
- entitlement: Entitlement::ReadView,
283
- available: always,
284
- parameters: |_| {
285
- json!({
286
- "type": "object",
287
- "properties": { "panel": panel_property() }
288
- })
289
- },
290
- call: |elem, ctx, args| Box::pin(elem.tool_get_view_config(ctx, args)),
291
- },
292
- Tool {
293
- name: "set_view_config",
294
- description: "Apply a partial configuration update to a panel. Only the fields provided \
295
- are changed. Expression columns must be declared in `expressions` before \
296
- being referenced in `columns`/`group_by`/etc. `columns` is POSITIONAL and \
297
- every plugin reads the positions differently - call `list_plugins` for the \
298
- active plugin's column roles and for what `group_by`/`split_by` draw in it. \
299
- Returns the full configuration after the update is applied and rendered, \
300
- plus `aggregation_changed_types` listing any column whose type CHANGED \
301
- under aggregation (a `date` on the default `count` aggregate becomes an \
302
- integer, so an axis bound to it is no longer a date axis).",
303
- entitlement: Entitlement::ConfigureView,
304
- available: always,
305
- parameters: |schemas| {
306
- config_parameters(
307
- schemas,
308
- "ViewerConfigUpdate",
309
- "A partial ViewerConfigUpdate patch",
310
- true,
311
- &[],
312
- &[],
313
- )
314
- },
315
- call: |elem, ctx, args| Box::pin(elem.tool_set_view_config(ctx, args)),
316
- },
317
- Tool {
318
- name: "list_plugins",
319
- description: "List the visualization plugins registered with this viewer, each with the \
320
- contract it declares: the ROLE each `columns` position fills (`columns[i]` \
321
- fills `roles[i]`; extra columns repeat the last role), how many columns it \
322
- requires, and what `group_by` and `split_by` draw in it. Use one of these \
323
- exact names as the `plugin` field of set_view_config, and read its roles \
324
- before writing `columns` - the same array means different things in \
325
- different plugins.",
326
- entitlement: Entitlement::ReadView,
327
- available: always,
328
- parameters: |_| json!({ "type": "object", "properties": {} }),
329
- call: |elem, ctx, args| Box::pin(elem.tool_list_plugins(ctx, args)),
330
- },
331
- Tool {
332
- name: "validate_expression",
333
- description: "Validate an ExprTK expression against a panel's table without applying it. \
334
- ExprTK examples: `\"Sales\" - \"Profit\"`, `if(\"Discount\" > 0.2, 'High', \
335
- 'Low')`, `bucket(\"Order Date\", 'M')`. Column references are \
336
- double-quoted; string literals are single-quoted. Use this to iterate on an \
337
- expression before committing it via set_view_config's `expressions` field.",
338
- entitlement: Entitlement::ReadView,
339
- available: always,
340
- parameters: |_| {
341
- json!({
342
- "type": "object",
343
- "properties": {
344
- "expression": {
345
- "type": "string",
346
- "description": "The ExprTK expression to validate"
347
- },
348
- "panel": panel_property()
349
- },
350
- "required": ["expression"]
351
- })
352
- },
353
- call: |elem, ctx, args| Box::pin(elem.tool_validate_expression(ctx, args)),
354
- },
355
- Tool {
356
- name: "get_style_schema",
357
- description: "Get the active plugin's DECLARED style schema: the valid `plugin_config` \
358
- keys, and - when `column` is given - the valid `columns_config` keys for \
359
- that column. These are value-dependent (they vary by plugin, column type \
360
- and current state), so call this before writing `plugin_config` or \
361
- `columns_config` via set_view_config. Plugins that declare no schema return \
362
- null sections - keys then pass through unvalidated.",
363
- entitlement: Entitlement::ReadView,
364
- available: always,
365
- parameters: |_| {
366
- json!({
367
- "type": "object",
368
- "properties": {
369
- "column": {
370
- "type": "string",
371
- "description": "An active column name (see get_view_config `columns`)"
372
- },
373
- "panel": panel_property()
374
- }
375
- })
376
- },
377
- call: |elem, ctx, args| Box::pin(elem.tool_get_style_schema(ctx, args)),
378
- },
379
- Tool {
380
- name: "list_panels",
381
- description: "List the panels (independent side-by-side views) in this viewer's dashboard \
382
- layout, and which one is active. View tools target the active panel unless \
383
- given a `panel` argument.",
384
- entitlement: Entitlement::ReadView,
385
- available: always,
386
- parameters: |_| json!({ "type": "object", "properties": {} }),
387
- call: |elem, ctx, args| Box::pin(elem.tool_list_panels(ctx, args)),
388
- },
389
- Tool {
390
- name: "add_panel",
391
- description: "Add a new independent panel to the dashboard layout, configured with the \
392
- given view config - same fields as set_view_config, plus `table`, which is \
393
- REQUIRED (a new panel must bind a data table). `columns` is also REQUIRED: \
394
- omitting it would display every column in the table. Compose the panel's \
395
- COMPLETE configuration (plugin, columns, group_by, expressions, ...) in \
396
- this one call. Returns the new panel's id and resulting configuration. To \
397
- duplicate an existing panel, pass a config obtained from get_view_config. \
398
- `columns` is POSITIONAL - see `list_plugins` for the chosen plugin's roles.",
399
- entitlement: Entitlement::ManageLayout,
400
- available: always,
401
- parameters: |schemas| {
402
- config_parameters(
403
- schemas,
404
- "ViewerConfigInitial",
405
- "The new panel's ViewerConfigInitial (`table` and `columns` required)",
406
- false,
407
- &["table", "columns"],
408
- &[],
409
- )
410
- },
411
- call: |elem, ctx, args| Box::pin(elem.tool_add_panel(ctx, args)),
412
- },
413
- Tool {
414
- name: "remove_panel",
415
- description: "Remove a panel by id, disposing its view. Removing every panel leaves an \
416
- empty viewer.",
417
- entitlement: Entitlement::ManageLayout,
418
- available: always,
419
- parameters: |_| {
420
- json!({
421
- "type": "object",
422
- "properties": {
423
- "panel": {
424
- "type": "string",
425
- "description": "Panel id from `list_panels`"
426
- }
427
- },
428
- "required": ["panel"]
429
- })
430
- },
431
- call: |elem, ctx, args| Box::pin(elem.tool_remove_panel(ctx, args)),
432
- },
433
- Tool {
434
- name: "activate_panel",
435
- description: "Make a panel active: the target of the settings sidebar and of view tools \
436
- called without a `panel` argument.",
437
- entitlement: Entitlement::ManageLayout,
438
- available: always,
439
- parameters: |_| {
440
- json!({
441
- "type": "object",
442
- "properties": {
443
- "panel": {
444
- "type": "string",
445
- "description": "Panel id from `list_panels`"
446
- }
447
- },
448
- "required": ["panel"]
449
- })
450
- },
451
- call: |elem, ctx, args| Box::pin(elem.tool_activate_panel(ctx, args)),
452
- },
453
- Tool {
454
- name: "get_workspace",
455
- description: "Get the dashboard's workspace state: the `layout` tree arranging the \
456
- panels, each panel's `title`, `plugin` and `table`, the active panel, and \
457
- the element-level `derived_tables`, `masters`, `global_filters` and \
458
- `palette`. Call this before `set_workspace` - its `layout` must name every \
459
- panel id listed here.",
460
- entitlement: Entitlement::ReadView,
461
- available: always,
462
- parameters: |_| json!({ "type": "object", "properties": {} }),
463
- call: |elem, ctx, args| Box::pin(elem.tool_get_workspace(ctx, args)),
464
- },
465
- Tool {
466
- name: "set_workspace",
467
- description: "Apply a field-wise update to the dashboard's workspace state; absent fields \
468
- are unchanged and `null` resets. `layout` arranges the panels into a grid: \
469
- nested `split-layout`s (`orientation` `horizontal` = side by side, \
470
- `vertical` = stacked; `sizes` are fractions summing to 1, one per child) \
471
- whose leaves are `tab-layout` stacks of panel ids, naming EVERY panel \
472
- exactly once. `derived_tables` is the COMPLETE set of derived tables (keep \
473
- existing entries), each a pivoted/filtered view of `table` that panels can \
474
- then bind by name via add_panel. `masters` are panels whose row selection \
475
- cross-filters the others through `global_filters`. Panels themselves are \
476
- created and removed with add_panel / remove_panel. Returns the workspace \
477
- state after the update.",
478
- entitlement: Entitlement::ManageLayout,
479
- available: always,
480
- parameters: |schemas| {
481
- config_parameters(
482
- schemas,
483
- "WorkspaceConfigUpdate",
484
- "A partial WorkspaceConfigUpdate (`panels` excluded)",
485
- false,
486
- &[],
487
- &["panels"],
488
- )
489
- },
490
- call: |elem, ctx, args| Box::pin(elem.tool_set_workspace(ctx, args)),
491
- },
492
- Tool {
493
- name: "search_docs",
494
- description: "Search the reference documentation: Perspective features, configuration \
495
- fields, expression syntax, plugin capabilities, and any host-supplied data \
496
- definitions. Queries are keyword-matched - prefer concrete terms (e.g. \
497
- `expressions bucket date`, not full sentences), and re-query with different \
498
- keywords if the results look irrelevant.",
499
- entitlement: Entitlement::ReadDocs,
500
- available: always,
501
- parameters: |_| {
502
- json!({
503
- "type": "object",
504
- "properties": {
505
- "query": {
506
- "type": "string",
507
- "description": "Keyword search query"
508
- },
509
- "limit": {
510
- "type": "integer",
511
- "description": "Maximum results (default 4)"
512
- }
513
- },
514
- "required": ["query"]
515
- })
516
- },
517
- call: |elem, ctx, args| Box::pin(elem.tool_search_docs(ctx, args)),
518
- },
519
- ];
520
-
521
- fn granted(tool: &Tool, ctx: &ToolCtx) -> bool {
522
- ctx.entitlements.contains(&tool.entitlement) && (tool.available)(ctx)
523
- }
524
-
525
- /// The tools advertised to the model for this turn.
526
- pub fn tool_definitions(ctx: &ToolCtx) -> Vec<ToolDef> {
527
- TOOLS
528
- .iter()
529
- .filter(|x| granted(x, ctx))
530
- .map(|x| ToolDef {
531
- kind: "function",
532
- function: FunctionDef {
533
- name: x.name,
534
- description: x.description,
535
- parameters: (x.parameters)(ctx.schemas()),
536
- },
537
- })
538
- .collect()
539
- }
540
-
541
- /// Run one tool call. `arguments` is the model's JSON-encoded argument
542
- /// string; all failures (including undecodable arguments and unknown or
543
- /// withheld names — indistinguishable, so no capability leak) surface as
544
- /// `ToolError` for the model to correct. The transcript/CustomEvent
545
- /// `emit` happens HERE, once, for every tool.
546
- pub async fn tool_dispatch(
547
- elem: &PerspectiveViewerElement,
548
- ctx: &ToolCtx,
549
- name: &str,
550
- arguments: &str,
551
- ) -> Result<Value, ToolError> {
552
- let tool = TOOLS
553
- .iter()
554
- .find(|x| x.name == name && granted(x, ctx))
555
- .ok_or_else(|| ToolError(format!("Unknown tool `{name}`")))?;
556
-
557
- let args: Value = if arguments.trim().is_empty() {
558
- json!({})
559
- } else {
560
- serde_json::from_str(arguments)?
561
- };
562
-
563
- elem.agent_emit(name, &args);
564
- let result = (tool.call)(elem, ctx, args).await;
565
- if let Err(err) = &result {
566
- elem.agent_emit_error(&format!("{err}"));
567
- }
568
-
569
- result
570
- }
571
-
572
- /// Tool failures are returned to the model as error tool-results so it can
573
- /// self-correct (e.g. a rejected `ViewerConfigUpdate` patch).
574
- #[derive(Debug, thiserror::Error)]
575
- #[error("{0}")]
576
- pub struct ToolError(String);
577
-
578
- /// Columns whose type CHANGED under aggregation, reported alongside an
579
- /// applied config.
580
- fn retyped_columns(
581
- session: &crate::session::Session,
582
- config: &crate::config::ViewerConfig<String, String>,
583
- ) -> Vec<Value> {
584
- let metadata = session.metadata();
585
- config
586
- .view_config
587
- .columns
588
- .iter()
589
- .flatten()
590
- .filter_map(|name| {
591
- let view_type = metadata.get_column_view_type(name)?;
592
- let table_type = metadata.get_column_table_type(name)?;
593
- if view_type == table_type {
594
- return None;
595
- }
596
-
597
- Some(json!({
598
- "name": name,
599
- "type": view_type,
600
- "source_type": table_type,
601
- "aggregate": config.view_config.aggregates.get(name),
602
- }))
603
- })
604
- .collect()
605
- }
606
-
607
- /// Append a `search_docs` pointer to a config-application error when a docs
608
- /// corpus is configured — a rejected config is the moment the model most
609
- /// needs the reference, and self-correction errors are the one channel it
610
- /// reliably reads (the preamble's docs step alone was not enough in the
611
- /// field). No-op without docs, where the tool does not exist.
612
- fn with_docs_hint(ctx: &ToolCtx, err: ToolError) -> ToolError {
613
- if ctx.docs.is_some() {
614
- ToolError(format!(
615
- "{} If a field or value was rejected, its reference documentation is available - call \
616
- `search_docs` with the failing field or function name.",
617
- err.0
618
- ))
619
- } else {
620
- err
621
- }
622
- }
623
-
624
- impl From<ApiError> for ToolError {
625
- fn from(err: ApiError) -> Self {
626
- Self(format!("{err}"))
627
- }
628
- }
629
-
630
- impl From<serde_json::Error> for ToolError {
631
- fn from(err: serde_json::Error) -> Self {
632
- Self(format!("{err}"))
633
- }
634
- }
635
-
636
- impl From<JsValue> for ToolError {
637
- fn from(err: JsValue) -> Self {
638
- Self(
639
- err.as_string()
640
- .or_else(|| {
641
- js_sys::Reflect::get(&err, &JsValue::from_str("message"))
642
- .ok()
643
- .and_then(|x| x.as_string())
644
- })
645
- .unwrap_or_else(|| format!("{err:?}")),
646
- )
647
- }
648
- }
649
-
650
- #[derive(Deserialize)]
651
- struct PanelArgs {
652
- panel: Option<String>,
653
- }
654
-
655
- #[derive(Deserialize)]
656
- struct SetViewConfigArgs {
657
- config: Value,
658
- panel: Option<String>,
659
- }
660
-
661
- #[derive(Deserialize)]
662
- struct ValidateExpressionArgs {
663
- expression: String,
664
- panel: Option<String>,
665
- }
666
-
667
- #[derive(Deserialize)]
668
- struct AddPanelArgs {
669
- config: Value,
670
- }
671
-
672
- #[derive(Deserialize)]
673
- struct PanelNameArgs {
674
- panel: String,
675
- }
676
-
677
- #[derive(Deserialize)]
678
- struct SetWorkspaceArgs {
679
- config: serde_json::Map<String, Value>,
680
- }
681
-
682
- #[derive(Deserialize)]
683
- struct SearchDocsArgs {
684
- query: String,
685
- limit: Option<usize>,
686
- }
687
-
688
- #[derive(Deserialize)]
689
- struct StyleSchemaArgs {
690
- column: Option<String>,
691
- panel: Option<String>,
692
- }
693
-
694
- fn control_schema_entries(spec: &ControlSpec) -> Vec<(String, Value)> {
695
- match spec {
696
- ControlSpec::Enum {
697
- key,
698
- variants,
699
- default,
700
- } => vec![(
701
- key.clone(),
702
- json!({
703
- "type": "string",
704
- "enum": variants.iter().map(|x| x.value.clone()).collect::<Vec<_>>(),
705
- "default": default
706
- }),
707
- )],
708
- ControlSpec::Bool { key, default } => vec![(
709
- key.clone(),
710
- json!({ "type": "boolean", "default": default }),
711
- )],
712
- ControlSpec::Number {
713
- key,
714
- default,
715
- min,
716
- max,
717
- ..
718
- } => {
719
- let mut node = json!({ "type": "number", "default": default });
720
- if let Some(min) = min {
721
- node["minimum"] = json!(min);
722
- }
723
-
724
- if let Some(max) = max {
725
- node["maximum"] = json!(max);
726
- }
727
-
728
- vec![(key.clone(), node)]
729
- },
730
- ControlSpec::String { key, default, .. } => {
731
- vec![(key.clone(), json!({ "type": "string", "default": default }))]
732
- },
733
- ControlSpec::Font {
734
- key,
735
- default,
736
- size,
737
- bold,
738
- italic,
739
- } => {
740
- let mut out = vec![(
741
- key.clone(),
742
- json!({
743
- "type": "string",
744
- "description": "A CSS font family: a generic keyword (`inherit`, `monospace`, `sans-serif`, `serif`, `system-ui`) or an installed font name",
745
- "default": default,
746
- }),
747
- )];
748
-
749
- if let Some(size) = size {
750
- let mut node = json!({
751
- "type": "number",
752
- "description": "Font size in CSS pixels",
753
- "default": size.default,
754
- });
755
-
756
- if let Some(min) = size.min {
757
- node["minimum"] = json!(min);
758
- }
759
-
760
- if let Some(max) = size.max {
761
- node["maximum"] = json!(max);
762
- }
763
-
764
- out.push((size.key.clone(), node));
765
- }
766
-
767
- for (toggle, description) in [(bold, "Bold text"), (italic, "Italic text")] {
768
- if let Some(toggle) = toggle {
769
- out.push((
770
- toggle.key.clone(),
771
- json!({ "type": "boolean", "description": description, "default": toggle.default }),
772
- ));
773
- }
774
- }
775
-
776
- out
777
- },
778
- ControlSpec::Alignment {
779
- key,
780
- default,
781
- corners,
782
- } => {
783
- let cells: &[Alignment] = if *corners {
784
- &Alignment::CORNERS
785
- } else {
786
- &Alignment::ALL
787
- };
788
-
789
- let mut node = json!({
790
- "type": "string",
791
- "enum": cells.iter().map(|x| x.as_str()).collect::<Vec<_>>(),
792
- "description": if *corners {
793
- "Anchor corner of a 3×3 grid: `top-left`, `top-right`, `bottom-left` or `bottom-right`"
794
- } else {
795
- "Anchor cell of a 3×3 grid: a corner `top-left|top-right|bottom-left|bottom-right`, an edge `top|left|right|bottom`, or `center`"
796
- },
797
- });
798
-
799
- if let Some(default) = default {
800
- node["default"] = json!(default.as_str());
801
- }
802
-
803
- vec![(key.clone(), node)]
804
- },
805
- ControlSpec::Color { key, default } => vec![(
806
- key.clone(),
807
- json!({
808
- "type": "string",
809
- "description": "A CSS color (`#rrggbb`, `rgb()`), or a host-defined named color `var(--psp-user--color-<name>)`",
810
- "default": default,
811
- }),
812
- )],
813
- ControlSpec::Palette { key, default, max } => {
814
- let mut description = "Ordered discrete color palette, cycled over the column's \
815
- categories/series: a CSS `linear-gradient(to right, #rrggbb, \
816
- #rrggbb, …)` of N colors WITHOUT positions, or a host-defined \
817
- named palette `var(--psp-user--palette-<name>)`"
818
- .to_owned();
819
- if let Some(max) = max {
820
- description.push_str(&format!(" (at most {max} colors)"));
821
- }
822
-
823
- vec![(
824
- key.clone(),
825
- json!({
826
- "type": "string",
827
- "description": description,
828
- "default": default,
829
- }),
830
- )]
831
- },
832
- ControlSpec::GradientStops {
833
- key,
834
- default,
835
- discrete,
836
- } => {
837
- let mut description = "Multi-stop color gradient: a CSS `linear-gradient(to right, \
838
- #rrggbb P%, …)` with positioned stops (direction normalized to \
839
- `to right`; stops[0] maps to the most negative value), or a \
840
- host-defined named gradient `var(--psp-user--gradient-<name>)`"
841
- .to_owned();
842
-
843
- if *discrete {
844
- description.push_str(" — exactly 2 stops (the negative and positive colors)");
845
- }
846
-
847
- vec![(
848
- key.clone(),
849
- json!({
850
- "type": "string",
851
- "description": description,
852
- "default": default,
853
- }),
854
- )]
855
- },
856
- ControlSpec::DatetimeFormat { .. } => vec![(
857
- "date_format".to_owned(),
858
- json!({ "description": "Datetime display format: a style preset or custom format fields" }),
859
- )],
860
- ControlSpec::NumberSeriesStyle { .. } => vec![
861
- (
862
- "chart_type".to_owned(),
863
- json!({ "type": "string", "description": "Per-series glyph override" }),
864
- ),
865
- (
866
- "stack".to_owned(),
867
- json!({ "description": "Series stack group" }),
868
- ),
869
- ],
870
- ControlSpec::Symbols { .. } => vec![(
871
- "symbols".to_owned(),
872
- json!({ "type": "object", "description": "Map of column values to symbol names" }),
873
- )],
874
- ControlSpec::NumberFormat { .. } => vec![(
875
- "number_format".to_owned(),
876
- json!({ "type": "object", "description": "Intl.NumberFormat-style options" }),
877
- )],
878
- ControlSpec::AggregateDepth => vec![(
879
- "aggregate_depth".to_owned(),
880
- json!({ "type": "integer", "description": "Group-by rollup depth override" }),
881
- )],
882
- ControlSpec::Group { fields, .. } => {
883
- fields.iter().flat_map(control_schema_entries).collect()
884
- },
885
- }
886
- }
887
-
888
- fn schema_object(schema: &ColumnConfigSchema) -> Value {
889
- let mut properties = serde_json::Map::new();
890
- for spec in &schema.fields {
891
- for (key, node) in control_schema_entries(spec) {
892
- properties.insert(key, node);
893
- }
894
- }
895
-
896
- json!({ "type": "object", "properties": properties })
897
- }
898
-
899
- const SEARCH_DOCS_LIMIT: usize = 4;
900
-
901
- /// A `restoreWorkspace` update returning each field of `update` to its value
902
- /// in the `saveWorkspace` token `snapshot`.
903
- fn workspace_rollback(snapshot: &Value, update: &serde_json::Map<String, Value>) -> Value {
904
- let mut rollback = serde_json::Map::new();
905
- for key in update.keys() {
906
- let saved = snapshot.get(key).filter(|x| !x.is_null()).cloned();
907
- let value = match key.as_str() {
908
- "layout" => saved,
909
- "derived_tables" => Some(saved.unwrap_or_else(|| json!({}))),
910
- "active" | "masters" | "global_filters" | "palette" => {
911
- Some(saved.unwrap_or(Value::Null))
912
- },
913
- _ => None,
914
- };
915
-
916
- if let Some(value) = value {
917
- rollback.insert(key.clone(), value);
918
- }
919
- }
920
-
921
- Value::Object(rollback)
922
- }
923
-
924
- /// Tool bodies and their shared helpers — plain (non-bindgen) methods.
925
- impl PerspectiveViewerElement {
926
- /// Resolve a tool's panel target: a named panel, or the active panel
927
- /// when `None`. Unknown names error with the current panel list so the
928
- /// model can self-correct.
929
- fn agent_panel(&self, target: Option<&str>) -> Result<Panel, ToolError> {
930
- let id = target.map(|x| PanelId::from(x.to_owned()));
931
- self.workspace
932
- .panel_or_active(id.as_ref())
933
- .ok_or_else(|| match target {
934
- Some(name) => ToolError(format!(
935
- "Unknown panel `{name}` - current panels: {:?}",
936
- self.agent_panel_names()
937
- )),
938
- None => ToolError("No panel - the viewer has no data loaded yet".to_owned()),
939
- })
940
- }
941
-
942
- fn agent_panel_names(&self) -> Vec<String> {
943
- self.workspace
944
- .panel_ids()
945
- .iter()
946
- .map(|x| x.as_str().to_owned())
947
- .collect()
948
- }
949
-
950
- fn agent_active_name(&self) -> Option<String> {
951
- self.workspace.active_id().map(|x| x.as_str().to_owned())
952
- }
953
-
954
- /// Record tool activity on the transcript (chat UI) and notify host
955
- /// listeners (`perspective-agent-tool`).
956
- fn agent_emit_error(&self, message: &str) {
957
- self.presentation.agent.record_tool_error(message);
958
- }
959
-
960
- fn agent_emit(&self, name: &str, args: &Value) {
961
- self.presentation.agent.record_tool(name, args);
962
- let detail: JsValue = json!({ "name": name, "args": args }).to_string().into();
963
- let event_init = web_sys::CustomEventInit::new();
964
- event_init.set_bubbles(true);
965
- event_init.set_detail(&detail);
966
- if let Ok(event) =
967
- web_sys::CustomEvent::new_with_event_init_dict("perspective-agent-tool", &event_init)
968
- {
969
- let _ = self.elem.dispatch_event(&event);
970
- }
971
- }
972
-
973
- async fn tool_get_schema(&self, _ctx: &ToolCtx, args: Value) -> Result<Value, ToolError> {
974
- let args: PanelArgs = serde_json::from_value(args)?;
975
- let panel = self.agent_panel(args.panel.as_deref())?;
976
- let table = panel
977
- .session
978
- .get_table()
979
- .ok_or_else(|| ToolError("No table loaded".to_owned()))?;
980
-
981
- let schema = table.schema().await.map_err(ApiError::from)?;
982
- let size = table.size().await.map_err(ApiError::from)?;
983
- Ok(json!({
984
- "table": table.get_name(),
985
- "columns": serde_json::to_value(&schema)?,
986
- "num_rows": size,
987
- }))
988
- }
989
-
990
- async fn tool_get_view_config(&self, _ctx: &ToolCtx, args: Value) -> Result<Value, ToolError> {
991
- let args: PanelArgs = serde_json::from_value(args)?;
992
- let panel = self.agent_panel(args.panel.as_deref())?;
993
- let config = get_viewer_config(&panel.session, &panel.renderer, &self.presentation).await?;
994
- Ok(serde_json::to_value(&config)?)
995
- }
996
-
997
- /// Applies via the public `restore()` with `suppress_errors: true`.
998
- async fn tool_set_view_config(&self, ctx: &ToolCtx, args: Value) -> Result<Value, ToolError> {
999
- let args: SetViewConfigArgs = serde_json::from_value(args)?;
1000
- let target = args.panel.as_deref();
1001
- self.agent_panel(target)?;
1002
- if let Err(err) = self.agent_restore(target, &args.config).await {
1003
- return Err(with_docs_hint(ctx, err));
1004
- }
1005
-
1006
- let panel = self.agent_panel(target)?;
1007
- let config = get_viewer_config(&panel.session, &panel.renderer, &self.presentation).await?;
1008
- let mut result = serde_json::to_value(&config)?;
1009
- let retyped = retyped_columns(&panel.session, &config);
1010
- if !retyped.is_empty() {
1011
- result["aggregation_changed_types"] = json!(retyped);
1012
- }
1013
-
1014
- Ok(result)
1015
- }
1016
-
1017
- /// One public-API `restore()` call with `suppress_errors: true`.
1018
- async fn agent_restore(&self, target: Option<&str>, config: &Value) -> Result<(), ToolError> {
1019
- let options = js_sys::Object::new();
1020
- js_sys::Reflect::set(
1021
- &options,
1022
- &JsValue::from_str("suppress_errors"),
1023
- &JsValue::TRUE,
1024
- )?;
1025
-
1026
- if let Some(name) = target {
1027
- js_sys::Reflect::set(
1028
- &options,
1029
- &JsValue::from_str("panel"),
1030
- &JsValue::from_str(name),
1031
- )?;
1032
- }
1033
-
1034
- let js_config = js_sys::JSON::parse(&config.to_string())?;
1035
- let restored = self.restore(js_config.unchecked_into(), Some(options.unchecked_into()));
1036
- let promise: js_sys::Promise = JsValue::from(restored).unchecked_into();
1037
- wasm_bindgen_futures::JsFuture::from(promise).await?;
1038
- Ok(())
1039
- }
1040
-
1041
- async fn tool_list_plugins(&self, _ctx: &ToolCtx, _args: Value) -> Result<Value, ToolError> {
1042
- let panel = self.agent_panel(None)?;
1043
- let plugins = panel
1044
- .renderer
1045
- .get_all_plugin_configs()
1046
- .iter()
1047
- .map(|config| {
1048
- let mut value = json!({
1049
- "name": config.name,
1050
- "category": config.category,
1051
- "columns": {
1052
- "roles": config.config_column_names,
1053
- "required": config.min_config_columns.unwrap_or(1),
1054
- "extra_columns": config.tail_column_role(),
1055
- },
1056
- "ordering": if config.connects_row_order {
1057
- json!("connects points in row order - `sort` by the \
1058
- X-axis column unless the table already \
1059
- arrives ordered")
1060
- } else {
1061
- Value::Null
1062
- },
1063
- "select_mode": match config.select_mode {
1064
- crate::config::ColumnSelectMode::Select => "select",
1065
- crate::config::ColumnSelectMode::Toggle => "toggle",
1066
- },
1067
- "supports_column_styles": config.can_render_column_styles,
1068
- });
1069
-
1070
- if let Some(max) = config.max_columns {
1071
- value["columns"]["max"] = json!(max);
1072
- }
1073
-
1074
- value["group_by"] = match &config.group_by_role {
1075
- Some(role) => json!(role),
1076
- None => json!("aggregates rows; no visual role"),
1077
- };
1078
-
1079
- value["split_by"] = match &config.split_by_role {
1080
- Some(role) => json!(role),
1081
- None => json!("aggregates rows; no visual role"),
1082
- };
1083
-
1084
- value
1085
- })
1086
- .collect::<Vec<_>>();
1087
-
1088
- Ok(json!({
1089
- "plugins": plugins,
1090
- "columns_are_positional": "`columns[i]` fills the role at `roles[i]`; columns past the last named role repeat `extra_columns`.",
1091
- }))
1092
- }
1093
-
1094
- async fn tool_validate_expression(
1095
- &self,
1096
- ctx: &ToolCtx,
1097
- args: Value,
1098
- ) -> Result<Value, ToolError> {
1099
- let args: ValidateExpressionArgs = serde_json::from_value(args)?;
1100
- let panel = self.agent_panel(args.panel.as_deref())?;
1101
- match validate_expr(&panel.session, &args.expression).await? {
1102
- None => Ok(json!({ "valid": true })),
1103
- Some(err) => {
1104
- let mut result = json!({
1105
- "valid": false,
1106
- "error": err.error_message,
1107
- "line": err.line,
1108
- "column": err.column,
1109
- });
1110
-
1111
- if ctx.docs.is_some() {
1112
- result["hint"] = json!(
1113
- "ExprTK syntax and functions are documented - call `search_docs` with the \
1114
- function name or feature, e.g. `expressions bucket`."
1115
- );
1116
- }
1117
-
1118
- Ok(result)
1119
- },
1120
- }
1121
- }
1122
-
1123
- async fn tool_list_panels(&self, _ctx: &ToolCtx, _args: Value) -> Result<Value, ToolError> {
1124
- Ok(json!({
1125
- "panels": self.agent_panel_names(),
1126
- "active": self.agent_active_name(),
1127
- }))
1128
- }
1129
-
1130
- async fn tool_add_panel(&self, ctx: &ToolCtx, args: Value) -> Result<Value, ToolError> {
1131
- let args: AddPanelArgs = serde_json::from_value(args)?;
1132
- if let Err(err) =
1133
- serde_json::from_value::<crate::config::ViewerConfigInitial>(args.config.clone())
1134
- {
1135
- let mut message = format!("Invalid panel config: {err}");
1136
- if message.contains("table")
1137
- && let Some(names) = self.agent_hosted_table_names().await
1138
- {
1139
- message.push_str(&format!(" - available tables: {names:?}"));
1140
- }
1141
-
1142
- return Err(with_docs_hint(ctx, ToolError(message)));
1143
- }
1144
-
1145
- match args.config.get("columns") {
1146
- Some(Value::Array(columns)) if !columns.is_empty() => {},
1147
- _ => {
1148
- return Err(ToolError(
1149
- "Invalid panel config: a new panel requires a non-empty `columns` list \
1150
- (omitting it would display every column in the table). Choose the columns - \
1151
- including any `expressions` names - this panel should display."
1152
- .to_owned(),
1153
- ));
1154
- },
1155
- }
1156
-
1157
- let before = self.agent_panel_names();
1158
- let js_config = js_sys::JSON::parse(&args.config.to_string())?;
1159
- let added = self.addPanel(js_config.unchecked_into(), None);
1160
- let result = wasm_bindgen_futures::JsFuture::from(js_sys::Promise::from(added)).await;
1161
- let id = match result {
1162
- Ok(id) => id
1163
- .as_string()
1164
- .ok_or_else(|| ToolError("addPanel returned no id".to_owned()))?,
1165
- Err(err) => {
1166
- for name in self.agent_panel_names() {
1167
- if !before.contains(&name) {
1168
- let removed = self.removePanel(name);
1169
- let _ =
1170
- wasm_bindgen_futures::JsFuture::from(js_sys::Promise::from(removed))
1171
- .await;
1172
- }
1173
- }
1174
-
1175
- return Err(with_docs_hint(ctx, ToolError::from(err)));
1176
- },
1177
- };
1178
-
1179
- let panel = self.agent_panel(Some(&id))?;
1180
- let config = get_viewer_config(&panel.session, &panel.renderer, &self.presentation).await?;
1181
- let mut result = json!({
1182
- "panel": id,
1183
- "config": serde_json::to_value(&config)?,
1184
- });
1185
-
1186
- let retyped = retyped_columns(&panel.session, &config);
1187
- if !retyped.is_empty() {
1188
- result["aggregation_changed_types"] = json!(retyped);
1189
- }
1190
-
1191
- Ok(result)
1192
- }
1193
-
1194
- /// Best-effort list of the active panel's client's hosted table names,
1195
- /// for self-correction error messages.
1196
- async fn agent_hosted_table_names(&self) -> Option<Vec<String>> {
1197
- let panel = self.agent_panel(None).ok()?;
1198
- let client = panel.session.get_client()?;
1199
- client.get_hosted_table_names().await.ok()
1200
- }
1201
-
1202
- async fn tool_get_workspace(&self, _ctx: &ToolCtx, _args: Value) -> Result<Value, ToolError> {
1203
- let token = self.agent_save_workspace().await?;
1204
- Ok(self.agent_workspace_summary(&token))
1205
- }
1206
-
1207
- /// Applies via the public `restoreWorkspace()`, restoring the touched
1208
- /// fields from a `saveWorkspace()` snapshot on failure.
1209
- async fn tool_set_workspace(&self, ctx: &ToolCtx, args: Value) -> Result<Value, ToolError> {
1210
- let args: SetWorkspaceArgs = serde_json::from_value(args)?;
1211
- if args.config.contains_key("panels") {
1212
- return Err(ToolError(
1213
- "`panels` cannot be set with set_workspace - create, configure and remove panels \
1214
- with `add_panel`, `set_view_config` and `remove_panel`, then arrange them with \
1215
- `layout`."
1216
- .to_owned(),
1217
- ));
1218
- }
1219
-
1220
- let snapshot = self.agent_save_workspace().await?;
1221
- if let Some(derived) = args.config.get("derived_tables") {
1222
- self.agent_check_derived(&snapshot, derived).await?;
1223
- }
1224
-
1225
- let update = Value::Object(args.config.clone());
1226
- if let Err(err) = self.agent_restore_workspace(&update).await {
1227
- let rollback = workspace_rollback(&snapshot, &args.config);
1228
- if let Err(rollback_err) = self.agent_restore_workspace(&rollback).await {
1229
- return Err(ToolError(format!(
1230
- "{err} (restoring the previous workspace also failed: {rollback_err})"
1231
- )));
1232
- }
1233
-
1234
- return Err(with_docs_hint(ctx, err));
1235
- }
1236
-
1237
- let token = self.agent_save_workspace().await?;
1238
- Ok(self.agent_workspace_summary(&token))
1239
- }
1240
-
1241
- /// Reject a `derived_tables` set that drops a table a panel reads, or
1242
- /// whose entries read a table that will not exist.
1243
- async fn agent_check_derived(
1244
- &self,
1245
- snapshot: &Value,
1246
- derived: &Value,
1247
- ) -> Result<(), ToolError> {
1248
- let Some(derived) = derived.as_object() else {
1249
- return Ok(());
1250
- };
1251
-
1252
- let current = snapshot["derived_tables"]
1253
- .as_object()
1254
- .map(|x| x.keys().cloned().collect::<Vec<_>>())
1255
- .unwrap_or_default();
1256
-
1257
- let mut dropped = snapshot["panels"]
1258
- .as_object()
1259
- .into_iter()
1260
- .flat_map(|panels| panels.values())
1261
- .filter_map(|config| config["table"].as_str())
1262
- .filter(|table| current.iter().any(|x| x == table) && !derived.contains_key(*table))
1263
- .map(str::to_owned)
1264
- .collect::<Vec<_>>();
1265
-
1266
- dropped.sort();
1267
- dropped.dedup();
1268
- if !dropped.is_empty() {
1269
- return Err(ToolError(format!(
1270
- "`derived_tables` is the COMPLETE set of derived tables, not a patch: {dropped:?} \
1271
- are read by panels and must stay in it (current derived tables: {current:?})"
1272
- )));
1273
- }
1274
-
1275
- let Some(hosted) = self.agent_hosted_table_names().await else {
1276
- return Ok(());
1277
- };
1278
-
1279
- let loaded = hosted
1280
- .into_iter()
1281
- .filter(|x| !current.contains(x))
1282
- .collect::<Vec<_>>();
1283
-
1284
- for (name, config) in derived {
1285
- let Some(parent) = config["table"].as_str() else {
1286
- continue;
1287
- };
1288
-
1289
- if !derived.contains_key(parent) && !loaded.iter().any(|x| x == parent) {
1290
- return Err(ToolError(format!(
1291
- "Derived table `{name}` reads unknown table `{parent}` - its `table` must be \
1292
- a loaded table or another entry in `derived_tables` (loaded tables: \
1293
- {loaded:?})"
1294
- )));
1295
- }
1296
- }
1297
-
1298
- Ok(())
1299
- }
1300
-
1301
- fn agent_workspace_summary(&self, token: &Value) -> Value {
1302
- let panels = token["panels"]
1303
- .as_object()
1304
- .into_iter()
1305
- .flatten()
1306
- .map(|(id, config)| {
1307
- (
1308
- id.clone(),
1309
- json!({
1310
- "title": config["title"],
1311
- "plugin": config["plugin"],
1312
- "table": config["table"],
1313
- }),
1314
- )
1315
- })
1316
- .collect::<serde_json::Map<_, _>>();
1317
-
1318
- let or = |key: &str, default: Value| {
1319
- token
1320
- .get(key)
1321
- .filter(|x| !x.is_null())
1322
- .cloned()
1323
- .unwrap_or(default)
1324
- };
1325
-
1326
- json!({
1327
- "active": self.agent_active_name(),
1328
- "layout": token["layout"],
1329
- "panels": panels,
1330
- "derived_tables": or("derived_tables", json!({})),
1331
- "masters": or("masters", json!([])),
1332
- "global_filters": or("global_filters", json!([])),
1333
- "palette": or("palette", json!({})),
1334
- })
1335
- }
1336
-
1337
- async fn agent_save_workspace(&self) -> Result<Value, ToolError> {
1338
- let options = js_sys::Object::new();
1339
- js_sys::Reflect::set(&options, &JsValue::from_str("full_palette"), &JsValue::TRUE)?;
1340
-
1341
- let saved = self.saveWorkspace(Some(options.unchecked_into()));
1342
- let promise: js_sys::Promise = JsValue::from(saved).unchecked_into();
1343
- let token = wasm_bindgen_futures::JsFuture::from(promise).await?;
1344
- let json = String::from(js_sys::JSON::stringify(&token)?);
1345
- Ok(serde_json::from_str(&json)?)
1346
- }
1347
-
1348
- async fn agent_restore_workspace(&self, update: &Value) -> Result<(), ToolError> {
1349
- let js_update = js_sys::JSON::parse(&update.to_string())?;
1350
- let restored = self.restoreWorkspace(js_update.unchecked_into(), None);
1351
- let promise: js_sys::Promise = JsValue::from(restored).unchecked_into();
1352
- wasm_bindgen_futures::JsFuture::from(promise).await?;
1353
- Ok(())
1354
- }
1355
-
1356
- async fn tool_remove_panel(&self, _ctx: &ToolCtx, args: Value) -> Result<Value, ToolError> {
1357
- let args: PanelNameArgs = serde_json::from_value(args)?;
1358
- self.agent_panel(Some(&args.panel))?;
1359
- let removed = self.removePanel(args.panel);
1360
- wasm_bindgen_futures::JsFuture::from(js_sys::Promise::from(removed)).await?;
1361
- Ok(json!({
1362
- "panels": self.agent_panel_names(),
1363
- "active": self.agent_active_name(),
1364
- }))
1365
- }
1366
-
1367
- async fn tool_activate_panel(&self, _ctx: &ToolCtx, args: Value) -> Result<Value, ToolError> {
1368
- let args: PanelNameArgs = serde_json::from_value(args)?;
1369
- self.agent_panel(Some(&args.panel))?;
1370
- let activated = self.setActivePanel(args.panel);
1371
- wasm_bindgen_futures::JsFuture::from(js_sys::Promise::from(activated)).await?;
1372
- Ok(json!({ "active": self.agent_active_name() }))
1373
- }
1374
-
1375
- async fn tool_get_style_schema(&self, _ctx: &ToolCtx, args: Value) -> Result<Value, ToolError> {
1376
- let args: StyleSchemaArgs = serde_json::from_value(args)?;
1377
- let panel = self.agent_panel(args.panel.as_deref())?;
1378
- let viewer_config =
1379
- get_viewer_config(&panel.session, &panel.renderer, &self.presentation).await?;
1380
-
1381
- let columns_config = serde_json::to_value(&viewer_config.columns_config)?;
1382
- let plugin_schema = {
1383
- let view_config = panel.session.get_view_config();
1384
- get_plugin_config_schema(
1385
- &panel.renderer,
1386
- &view_config,
1387
- Some(&viewer_config.panel.plugin_config),
1388
- )
1389
- .ok()
1390
- };
1391
-
1392
- let column_schema = match &args.column {
1393
- None => None,
1394
- Some(column) => {
1395
- let metadata = panel.session.metadata();
1396
- if metadata.get_column_view_type(column).is_none() {
1397
- let view_config = panel.session.get_view_config();
1398
- let active = view_config
1399
- .columns
1400
- .iter()
1401
- .flatten()
1402
- .cloned()
1403
- .collect::<Vec<_>>();
1404
-
1405
- return Err(ToolError(format!(
1406
- "Unknown or inactive column `{column}` - active columns: {active:?}"
1407
- )));
1408
- }
1409
-
1410
- let current = columns_config.get(column).and_then(|x| x.as_object());
1411
- let view_config = panel.session.get_view_config();
1412
- Some(
1413
- get_column_config_schema(
1414
- &panel.renderer,
1415
- &view_config,
1416
- &metadata,
1417
- column,
1418
- current,
1419
- None,
1420
- )
1421
- .ok(),
1422
- )
1423
- },
1424
- };
1425
-
1426
- let mut out = json!({
1427
- "plugin": viewer_config.plugin,
1428
- "plugin_config": plugin_schema.as_ref().map(schema_object),
1429
- });
1430
-
1431
- if let Some(column) = &args.column {
1432
- out["column"] = json!(column);
1433
- out["column_config"] = json!(column_schema.flatten().as_ref().map(schema_object));
1434
- }
1435
-
1436
- if out["plugin_config"].is_null() && out["column_config"].is_null() {
1437
- out["note"] = json!(
1438
- "The active plugin declares no style schema; `plugin_config` and `columns_config` \
1439
- keys pass through unvalidated."
1440
- );
1441
- }
1442
-
1443
- Ok(out)
1444
- }
1445
-
1446
- async fn tool_search_docs(&self, ctx: &ToolCtx, args: Value) -> Result<Value, ToolError> {
1447
- let args: SearchDocsArgs = serde_json::from_value(args)?;
1448
- let Some(bundle) = ctx.bundle.as_ref() else {
1449
- return Ok(json!({
1450
- "results": [],
1451
- "hint": "No documentation is configured for this viewer",
1452
- }));
1453
- };
1454
-
1455
- match bundle.as_ref() {
1456
- Err(err) => Err(ToolError(format!("Docs failed to load: {err}"))),
1457
- Ok(bundle) => {
1458
- let results = bundle
1459
- .index
1460
- .search(&args.query, args.limit.unwrap_or(SEARCH_DOCS_LIMIT))
1461
- .iter()
1462
- .map(|chunk| {
1463
- json!({
1464
- "title": chunk.title,
1465
- "path": chunk.path,
1466
- "text": chunk.text,
1467
- })
1468
- })
1469
- .collect::<Vec<_>>();
1470
-
1471
- if results.is_empty() {
1472
- Ok(json!({
1473
- "results": [],
1474
- "hint": "No matches - retry with different, more specific keywords",
1475
- }))
1476
- } else {
1477
- Ok(json!({ "results": results }))
1478
- }
1479
- },
1480
- }
1481
- }
1482
- }