@perspective-dev/viewer 5.0.0 → 5.2.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 (213) hide show
  1. package/dist/cdn/perspective-viewer.js +9 -9
  2. package/dist/cdn/perspective-viewer.js.map +4 -4
  3. package/dist/css/botanical.css +1 -1
  4. package/dist/css/dracula.css +1 -1
  5. package/dist/css/gruvbox-dark.css +1 -1
  6. package/dist/css/gruvbox.css +1 -1
  7. package/dist/css/icons.css +1 -1
  8. package/dist/css/intl/de.css +1 -1
  9. package/dist/css/intl/es.css +1 -1
  10. package/dist/css/intl/fr.css +1 -1
  11. package/dist/css/intl/ja.css +1 -1
  12. package/dist/css/intl/pt.css +1 -1
  13. package/dist/css/intl/zh.css +1 -1
  14. package/dist/css/intl.css +1 -1
  15. package/dist/css/monokai.css +1 -1
  16. package/dist/css/phosphor.css +1 -1
  17. package/dist/css/pro-dark.css +1 -1
  18. package/dist/css/pro.css +1 -1
  19. package/dist/css/solarized-dark.css +1 -1
  20. package/dist/css/solarized.css +1 -1
  21. package/dist/css/themes.css +1 -1
  22. package/dist/css/vaporwave.css +1 -1
  23. package/dist/docs/perspective-docs.json +1 -0
  24. package/dist/esm/column-format.d.ts +19 -28
  25. package/dist/esm/perspective-viewer.d.ts +2 -0
  26. package/dist/esm/perspective-viewer.inline.js +8 -8
  27. package/dist/esm/perspective-viewer.inline.js.map +4 -4
  28. package/dist/esm/perspective-viewer.js +9 -9
  29. package/dist/esm/perspective-viewer.js.map +4 -4
  30. package/dist/esm/providers.d.ts +79 -0
  31. package/dist/esm/ts-rs/CompactDisplay.d.ts +5 -0
  32. package/dist/esm/ts-rs/CurrencyCode.d.ts +1 -0
  33. package/dist/esm/ts-rs/CurrencyDisplay.d.ts +1 -0
  34. package/dist/esm/ts-rs/CurrencyNumberFormatStyle.d.ts +8 -0
  35. package/dist/esm/ts-rs/CurrencySign.d.ts +1 -0
  36. package/dist/esm/ts-rs/CustomDatetimeFormat.d.ts +1 -0
  37. package/dist/esm/ts-rs/CustomDatetimeStyleConfig.d.ts +54 -0
  38. package/dist/esm/ts-rs/CustomNumberFormatConfig.d.ts +34 -0
  39. package/dist/esm/ts-rs/DatetimeColorMode.d.ts +1 -0
  40. package/dist/esm/ts-rs/DatetimeFormatType.d.ts +6 -0
  41. package/dist/esm/ts-rs/FormatMode.d.ts +1 -0
  42. package/dist/esm/ts-rs/FormatUnit.d.ts +1 -0
  43. package/dist/esm/ts-rs/Notation.d.ts +17 -0
  44. package/dist/esm/ts-rs/NumberFormatStyle.d.ts +18 -0
  45. package/dist/esm/ts-rs/PanelViewerConfig.d.ts +43 -1
  46. package/dist/esm/ts-rs/PluginStaticConfig.d.ts +35 -0
  47. package/dist/esm/ts-rs/RestoreOptions.d.ts +19 -0
  48. package/dist/esm/ts-rs/RoundingMode.d.ts +1 -0
  49. package/dist/esm/ts-rs/RoundingPriority.d.ts +1 -0
  50. package/dist/esm/ts-rs/SignDisplay.d.ts +1 -0
  51. package/dist/esm/ts-rs/SimpleDatetimeFormat.d.ts +1 -0
  52. package/dist/esm/ts-rs/SimpleDatetimeStyleConfig.d.ts +24 -0
  53. package/dist/esm/ts-rs/SplitRollupMode.d.ts +9 -0
  54. package/dist/esm/ts-rs/StringColorMode.d.ts +1 -0
  55. package/dist/esm/ts-rs/TrailingZeroDisplay.d.ts +1 -0
  56. package/dist/esm/ts-rs/Unit.d.ts +1 -0
  57. package/dist/esm/ts-rs/UnitDisplay.d.ts +1 -0
  58. package/dist/esm/ts-rs/UnitNumberFormatStyle.d.ts +6 -0
  59. package/dist/esm/ts-rs/UseGrouping.d.ts +1 -0
  60. package/dist/esm/ts-rs/ViewerConfig.d.ts +43 -1
  61. package/dist/esm/ts-rs/ViewerConfigInitial.d.ts +175 -0
  62. package/dist/esm/ts-rs/ViewerConfigUpdate.d.ts +72 -0
  63. package/dist/esm/ts-rs/WindowSort.d.ts +7 -0
  64. package/dist/esm/ts-rs/WindowSortDir.d.ts +6 -0
  65. package/dist/esm/ts-rs/WindowSpec.d.ts +47 -0
  66. package/dist/esm/ts-rs/Windows.d.ts +10 -0
  67. package/dist/esm/ts-rs/WorkspaceConfigUpdate.d.ts +7 -6
  68. package/dist/wasm/perspective-viewer.d.ts +222 -26
  69. package/dist/wasm/perspective-viewer.js +378 -125
  70. package/dist/wasm/perspective-viewer.wasm +0 -0
  71. package/dist/wasm/perspective-viewer.wasm.d.ts +18 -15
  72. package/package.json +2 -1
  73. package/src/css/_viewer_bundle.css +1 -0
  74. package/src/css/column-selector.css +9 -0
  75. package/src/css/column-settings-panel.css +67 -2
  76. package/src/css/column-style.css +4 -3
  77. package/src/css/config-selector.css +60 -4
  78. package/src/css/containers/context-menu.css +12 -6
  79. package/src/css/containers/tabs.css +2 -2
  80. package/src/css/form/code-editor.css +2 -3
  81. package/src/css/form/mirrored-textarea.css +81 -0
  82. package/src/css/viewer.css +336 -0
  83. package/src/rust/agent/client/mod.rs +19 -0
  84. package/src/rust/agent/client/protocol.rs +320 -0
  85. package/src/rust/agent/client/transport.rs +287 -0
  86. package/src/rust/agent/client/turn.rs +174 -0
  87. package/src/rust/agent/config.rs +159 -0
  88. package/src/rust/agent/docs.rs +293 -0
  89. package/src/rust/agent/markdown/block.rs +509 -0
  90. package/src/rust/agent/markdown/entity.rs +52 -0
  91. package/src/rust/agent/markdown/events.rs +71 -0
  92. package/src/rust/agent/markdown/inline.rs +497 -0
  93. package/src/rust/agent/markdown/mod.rs +466 -0
  94. package/src/rust/agent/mod.rs +23 -0
  95. package/src/rust/agent/preamble.md +16 -0
  96. package/src/rust/agent/runtime.rs +201 -0
  97. package/src/rust/agent/slot.rs +236 -0
  98. package/src/rust/agent/tools.rs +1110 -0
  99. package/src/rust/components/chat_panel.rs +289 -0
  100. package/src/rust/components/column_selector/active_column.rs +21 -27
  101. package/src/rust/components/column_selector/column_selector_column_row.rs +73 -0
  102. package/src/rust/components/column_selector/config_selector.rs +83 -8
  103. package/src/rust/components/column_selector/expr_edit_button.rs +7 -1
  104. package/src/rust/components/column_selector/inactive_column.rs +8 -1
  105. package/src/rust/components/column_selector.rs +27 -3
  106. package/src/rust/components/column_settings_sidebar/style_tab.rs +2 -1
  107. package/src/rust/components/column_settings_sidebar/window_tab.rs +34 -0
  108. package/src/rust/components/column_settings_sidebar.rs +163 -16
  109. package/src/rust/components/containers/dragdrop_list.rs +110 -3
  110. package/src/rust/components/containers/sidebar.rs +99 -22
  111. package/src/rust/components/containers/split_panel.rs +6 -0
  112. package/src/rust/components/editable_header.rs +2 -0
  113. package/src/rust/components/form/code_editor.rs +14 -23
  114. package/src/rust/components/form/debug.rs +8 -5
  115. package/src/rust/components/form/mirrored_textarea.rs +165 -0
  116. package/src/rust/components/form/mod.rs +1 -0
  117. package/src/rust/components/main_panel.rs +5 -0
  118. package/src/rust/components/mod.rs +3 -0
  119. package/src/rust/components/panel_menu.rs +7 -0
  120. package/src/rust/components/panel_tab.rs +5 -0
  121. package/src/rust/components/portal.rs +7 -0
  122. package/src/rust/components/settings_panel.rs +80 -2
  123. package/src/rust/components/viewer/msg.rs +2 -0
  124. package/src/rust/components/viewer/panels.rs +9 -14
  125. package/src/rust/components/viewer/render.rs +14 -0
  126. package/src/rust/components/viewer/settings.rs +33 -1
  127. package/src/rust/components/viewer.rs +2 -0
  128. package/src/rust/components/window_editor.rs +985 -0
  129. package/src/rust/config/datetime_column_style/custom.rs +17 -0
  130. package/src/rust/config/datetime_column_style/simple.rs +10 -0
  131. package/src/rust/config/number_string_format.rs +33 -0
  132. package/src/rust/config/options.rs +18 -0
  133. package/src/rust/config/plugin_static_config.rs +120 -5
  134. package/src/rust/config/viewer_config.rs +220 -1
  135. package/src/rust/config/workspace_config.rs +7 -6
  136. package/src/rust/custom_elements/viewer.rs +209 -18
  137. package/src/rust/custom_events.rs +29 -0
  138. package/src/rust/lib.rs +17 -1
  139. package/src/rust/presentation/column_locator.rs +16 -1
  140. package/src/rust/presentation.rs +8 -0
  141. package/src/rust/queries/columns_iter_set.rs +7 -1
  142. package/src/rust/queries/get_viewer_config.rs +5 -1
  143. package/src/rust/renderer/dispatch.rs +85 -58
  144. package/src/rust/renderer.rs +34 -1
  145. package/src/rust/session/column_defaults_update.rs +18 -0
  146. package/src/rust/session/drag_drop_update.rs +18 -0
  147. package/src/rust/session/metadata.rs +64 -9
  148. package/src/rust/session/replace_expression_update.rs +2 -0
  149. package/src/rust/session.rs +7 -5
  150. package/src/rust/tasks/create_panel.rs +18 -8
  151. package/src/rust/tasks/edit_window.rs +155 -0
  152. package/src/rust/tasks/mod.rs +2 -0
  153. package/src/rust/tasks/restore_panel.rs +34 -17
  154. package/src/rust/tasks/sync_update_panels.rs +7 -23
  155. package/src/rust/utils/browser/dragdrop.rs +12 -0
  156. package/src/rust/utils/browser/tests/debounce.rs +49 -0
  157. package/src/rust/utils/debounce.rs +76 -27
  158. package/src/rust/workspace.rs +112 -20
  159. package/src/svg/pin-icon.svg +5 -0
  160. package/src/themes/icons.css +1 -0
  161. package/src/themes/intl/de.css +23 -0
  162. package/src/themes/intl/es.css +23 -0
  163. package/src/themes/intl/fr.css +23 -0
  164. package/src/themes/intl/ja.css +23 -0
  165. package/src/themes/intl/pt.css +23 -0
  166. package/src/themes/intl/zh.css +23 -0
  167. package/src/themes/intl.css +26 -1
  168. package/src/ts/column-format.ts +67 -46
  169. package/src/ts/perspective-viewer.ts +2 -0
  170. package/src/ts/providers.ts +96 -0
  171. package/src/ts/ts-rs/CompactDisplay.ts +3 -0
  172. package/src/ts/ts-rs/CurrencyCode.ts +3 -0
  173. package/src/ts/ts-rs/CurrencyDisplay.ts +3 -0
  174. package/src/ts/ts-rs/CurrencyNumberFormatStyle.ts +6 -0
  175. package/src/ts/ts-rs/CurrencySign.ts +3 -0
  176. package/src/ts/ts-rs/CustomDatetimeFormat.ts +3 -0
  177. package/src/ts/ts-rs/CustomDatetimeStyleConfig.ts +54 -0
  178. package/src/ts/ts-rs/CustomNumberFormatConfig.ts +25 -0
  179. package/src/ts/ts-rs/DatetimeColorMode.ts +3 -0
  180. package/src/ts/ts-rs/DatetimeFormatType.ts +8 -0
  181. package/src/ts/ts-rs/FormatMode.ts +3 -0
  182. package/src/ts/ts-rs/FormatUnit.ts +3 -0
  183. package/src/ts/ts-rs/Notation.ts +11 -0
  184. package/src/ts/ts-rs/NumberFormatStyle.ts +12 -0
  185. package/src/ts/ts-rs/PanelViewerConfig.ts +48 -1
  186. package/src/ts/ts-rs/PluginStaticConfig.ts +36 -1
  187. package/src/ts/ts-rs/RestoreOptions.ts +20 -0
  188. package/src/ts/ts-rs/RoundingMode.ts +3 -0
  189. package/src/ts/ts-rs/RoundingPriority.ts +3 -0
  190. package/src/ts/ts-rs/SignDisplay.ts +3 -0
  191. package/src/ts/ts-rs/SimpleDatetimeFormat.ts +3 -0
  192. package/src/ts/ts-rs/SimpleDatetimeStyleConfig.ts +25 -0
  193. package/src/ts/ts-rs/SplitRollupMode.ts +11 -0
  194. package/src/ts/ts-rs/StringColorMode.ts +3 -0
  195. package/src/ts/ts-rs/TrailingZeroDisplay.ts +3 -0
  196. package/src/ts/ts-rs/Unit.ts +3 -0
  197. package/src/ts/ts-rs/UnitDisplay.ts +3 -0
  198. package/src/ts/ts-rs/UnitNumberFormatStyle.ts +5 -0
  199. package/src/ts/ts-rs/UseGrouping.ts +3 -0
  200. package/src/ts/ts-rs/ViewerConfig.ts +48 -1
  201. package/src/ts/ts-rs/ViewerConfigInitial.ts +164 -0
  202. package/src/ts/ts-rs/ViewerConfigUpdate.ts +81 -2
  203. package/src/ts/ts-rs/WindowSort.ts +9 -0
  204. package/src/ts/ts-rs/WindowSortDir.ts +8 -0
  205. package/src/ts/ts-rs/WindowSpec.ts +47 -0
  206. package/src/ts/ts-rs/Windows.ts +10 -0
  207. package/src/ts/ts-rs/WorkspaceConfigUpdate.ts +7 -6
  208. /package/dist/wasm/snippets/{perspective-viewer-daeef4ceb066e6c7 → perspective-viewer-02e461f3d7062b26}/inline0.js +0 -0
  209. /package/dist/wasm/snippets/{perspective-viewer-daeef4ceb066e6c7 → perspective-viewer-02e461f3d7062b26}/inline1.js +0 -0
  210. /package/dist/wasm/snippets/{perspective-viewer-daeef4ceb066e6c7 → perspective-viewer-02e461f3d7062b26}/inline2.js +0 -0
  211. /package/dist/wasm/snippets/{perspective-viewer-daeef4ceb066e6c7 → perspective-viewer-02e461f3d7062b26}/inline3.js +0 -0
  212. /package/dist/wasm/snippets/{perspective-viewer-daeef4ceb066e6c7 → perspective-viewer-02e461f3d7062b26}/inline4.js +0 -0
  213. /package/dist/wasm/snippets/{perspective-viewer-daeef4ceb066e6c7 → perspective-viewer-02e461f3d7062b26}/inline5.js +0 -0
@@ -14,7 +14,7 @@ use std::collections::BTreeMap;
14
14
 
15
15
  use perspective_client::config::Filter;
16
16
 
17
- use crate::config::{PanelViewerConfig, ViewerConfigUpdate};
17
+ use crate::config::{PanelViewerConfig, ViewerConfigInitial};
18
18
 
19
19
  /// The whole-element config format (`{version, active?, layout, panels}`) —
20
20
  /// the multi-panel counterpart of the single-panel [`ViewerConfig`] — as
@@ -59,10 +59,11 @@ pub struct WorkspaceConfig {
59
59
  }
60
60
 
61
61
  /// The parse target of a whole-element config in
62
- /// [`PerspectiveViewerElement::restore`]. Mirrors [`WorkspaceConfig`],
63
- /// but `panels` entries are full [`ViewerConfigUpdate`]s so a stray per-panel
64
- /// `settings` can be detected (warned, then ignored — `create_panel` strips
65
- /// it).
62
+ /// [`PerspectiveViewerElement::restoreWorkspace`]. Mirrors
63
+ /// [`WorkspaceConfig`], but `panels` entries are [`ViewerConfigInitial`]s —
64
+ /// every entry creates a NEW panel, so `table` is required by type (a
65
+ /// stray per-panel `settings` key is ignored; it is element-level state,
66
+ /// carried by the top-level `active` field).
66
67
  #[derive(serde::Deserialize, ts_rs::TS)]
67
68
  pub struct WorkspaceConfigUpdate {
68
69
  #[serde(default)]
@@ -73,7 +74,7 @@ pub struct WorkspaceConfigUpdate {
73
74
  #[ts(optional)]
74
75
  pub layout: Option<crate::js::Layout>,
75
76
 
76
- pub panels: BTreeMap<String, ViewerConfigUpdate>,
77
+ pub panels: BTreeMap<String, ViewerConfigInitial>,
77
78
 
78
79
  /// The element-level global (master/detail cross-) filters to re-apply as
79
80
  /// a transient overlay on every DETAIL panel. Restored as one
@@ -29,6 +29,8 @@ use wasm_bindgen_futures::JsFuture;
29
29
  use web_sys::HtmlElement;
30
30
  use yew::Callback;
31
31
 
32
+ #[cfg(feature = "llm-agent")]
33
+ use crate::agent::AgentRuntime;
32
34
  use crate::components::viewer::{PerspectiveViewerMsg, PerspectiveViewerProps};
33
35
  use crate::config::*;
34
36
  use crate::custom_events::*;
@@ -59,6 +61,16 @@ extern "C" {
59
61
  #[wasm_bindgen(typescript_type = "PanelOptions")]
60
62
  pub type JsPanelOptions;
61
63
 
64
+ /// `restore()` options dict
65
+ /// (`{ panel?: string, suppress_errors?: boolean }`).
66
+ #[wasm_bindgen(typescript_type = "RestoreOptions")]
67
+ pub type JsRestoreOptions;
68
+
69
+ /// `addPanel()` argument: a new panel's initial config — `table`
70
+ /// REQUIRED.
71
+ #[wasm_bindgen(typescript_type = "ViewerConfigInitial")]
72
+ pub type JsViewerConfigInitial;
73
+
62
74
  /// `download`/`export`/`copy` options dict
63
75
  /// (`{ method?: ExportMethod, panel?: string }`).
64
76
  #[wasm_bindgen(typescript_type = "ExportOptions")]
@@ -919,9 +931,12 @@ impl PerspectiveViewerElement {
919
931
  /// optional `{panel}` selector.
920
932
  ///
921
933
  /// If `panel` names no existing panel, a NEW panel is created with that id
922
- /// and the config restored into it (an upsert), equivalent to
923
- /// [`Self::addPanel`] but with a caller-chosen id. As with a created panel,
934
+ /// and the config restored into it (an upsert). As with a created panel,
924
935
  /// the element-level `settings`/`theme` fields are ignored in that case.
936
+ /// Unlike [`Self::addPanel`], the argument is a PATCH, so a `table` is
937
+ /// optional: creating without one yields a DEFERRED panel that the next
938
+ /// [`Self::load`] binds. Such a panel renders but cannot be serialized —
939
+ /// [`Self::save`] rejects with "Panel has no `table`" until it is bound.
925
940
  ///
926
941
  /// On an empty element with a pending [`Self::load`] whose payload is not
927
942
  /// yet classified, the active-target form (no `panel`) instead claims and
@@ -940,7 +955,15 @@ impl PerspectiveViewerElement {
940
955
  ///
941
956
  /// - `update` - The config to restore to, as returned by [`Self::save`] in
942
957
  /// either "json", "string" or "arraybuffer" format.
943
- /// - `name` - The panel to target, or `None` for the active panel.
958
+ /// - `options.panel` - The panel to target, or the active panel when
959
+ /// omitted.
960
+ /// - `options.suppress_errors` - when `true`, a failed restore only rejects
961
+ /// the returned `Promise`; the error is NOT committed to the viewer's
962
+ /// visible error state and the session remains usable. The view config is
963
+ /// rolled back to its pre-call value, so a rejected patch cannot re-merge
964
+ /// into a later restore. Element-level state the call already applied
965
+ /// (theme, title, a plugin swap) is NOT undone — restore a known-good
966
+ /// config to recover those exactly.
944
967
  ///
945
968
  /// # JavaScript Examples
946
969
  ///
@@ -960,15 +983,62 @@ impl PerspectiveViewerElement {
960
983
  pub fn restore(
961
984
  &self,
962
985
  update: JsViewerConfigUpdate,
963
- options: Option<JsPanelOptions>,
986
+ options: Option<JsRestoreOptions>,
964
987
  ) -> JsVoidPromise {
965
- let PanelOptions { panel: name } = parse_options(options);
988
+ let RestoreOptions {
989
+ panel: name,
990
+ suppress_errors,
991
+ } = parse_options(options);
992
+
993
+ // `suppress_errors` failures reject the returned Promise WITHOUT
994
+ // committing to the viewer's visible error state — for programmatic
995
+ // callers (the agent's `set_view_config`) whose failed patches are
996
+ // caller feedback, not user-facing faults.
997
+ let errors = if suppress_errors.unwrap_or_default() {
998
+ RestoreErrors::Suppress
999
+ } else {
1000
+ RestoreErrors::Publish
1001
+ };
1002
+
966
1003
  let effect = self.workspace.effects().guard();
967
1004
  let this = self.clone();
968
1005
  let fut = ApiFuture::new_throttled(async move {
969
1006
  let _effect = effect;
970
1007
  let id = name.map(PanelId::from);
971
- let update = ViewerConfigUpdate::decode(&update)?;
1008
+ let mut update = ViewerConfigUpdate::decode(&update)?;
1009
+
1010
+ // `settings` is ELEMENT-level chrome, not panel state — it
1011
+ // rides in this object only because the legacy single-panel
1012
+ // `restore()` has always carried it. Apply it HERE and hand
1013
+ // the panel pipeline a purely per-panel update: the
1014
+ // panel-CREATING branch below converts to
1015
+ // `ViewerConfigInitial`, which has no `settings` field at
1016
+ // all, so a `restore()` against an empty element — the first
1017
+ // call every embedding makes — would otherwise drop it
1018
+ // silently. Applied BEFORE the panel work so the plugin
1019
+ // draws once, already at its final size.
1020
+ // BOTH halves move together, or the flag and the chrome
1021
+ // disagree: `set_settings_before_open` writes the persisted
1022
+ // `is_settings_open` (what `save()` reports) and the host
1023
+ // `settings` attribute, while `ToggleSettingsComplete`
1024
+ // performs the component's own toggle. `restore_and_render`
1025
+ // used to do the first for the panel-UPDATING path only —
1026
+ // which the creating path never reaches, since
1027
+ // `ViewerConfigInitial` has no `settings` field to carry.
1028
+ let settings = std::mem::replace(&mut update.settings, OptionalUpdate::Missing);
1029
+ if !matches!(settings, OptionalUpdate::Missing) {
1030
+ if let OptionalUpdate::Update(open) = settings {
1031
+ this.presentation.set_settings_before_open(open);
1032
+ }
1033
+
1034
+ let (sender, receiver) = channel::<()>();
1035
+ this.root.borrow().as_ref().into_apierror()?.send_message(
1036
+ PerspectiveViewerMsg::ToggleSettingsComplete(settings, sender),
1037
+ );
1038
+
1039
+ receiver.await.unwrap_or_log();
1040
+ }
1041
+
972
1042
  match this.workspace.panel_or_active(id.as_ref()) {
973
1043
  // An existing (or the active) panel — update it in place.
974
1044
  Some(panel) => {
@@ -978,9 +1048,9 @@ impl PerspectiveViewerElement {
978
1048
  &panel.renderer,
979
1049
  &this.presentation,
980
1050
  &this.workspace,
981
- Some(&this.root),
982
1051
  RestoreMode::Existing { active },
983
1052
  update,
1053
+ errors,
984
1054
  )
985
1055
  .await
986
1056
  },
@@ -1007,13 +1077,25 @@ impl PerspectiveViewerElement {
1007
1077
  &panel.renderer,
1008
1078
  &this.presentation,
1009
1079
  &this.workspace,
1010
- Some(&this.root),
1011
1080
  RestoreMode::Existing { active: true },
1012
1081
  update,
1082
+ errors,
1013
1083
  )
1014
1084
  .await
1015
1085
  },
1016
1086
  None => {
1087
+ // The panel-creating upsert. `restore`'s
1088
+ // argument is a PATCH, so a `table` is
1089
+ // optional here as it is everywhere else on
1090
+ // this path: an update carrying none creates
1091
+ // a deferred panel, which the next `load()`
1092
+ // binds (it targets `active_panel()` before
1093
+ // reserving one of its own). The
1094
+ // table-required rule belongs to the
1095
+ // CREATION types — `addPanel`,
1096
+ // `restoreWorkspace`'s `panels`, the agent's
1097
+ // `add_panel` — which enforce it in their
1098
+ // own signatures.
1017
1099
  create_panel(
1018
1100
  &this.elem,
1019
1101
  &this.presentation,
@@ -1063,9 +1145,9 @@ impl PerspectiveViewerElement {
1063
1145
  &renderer,
1064
1146
  &presentation,
1065
1147
  &workspace,
1066
- None,
1067
1148
  RestoreMode::Fresh,
1068
1149
  config,
1150
+ crate::tasks::RestoreErrors::Publish,
1069
1151
  )
1070
1152
  .await?;
1071
1153
  if workspace.is_master(&id) {
@@ -1726,27 +1808,32 @@ impl PerspectiveViewerElement {
1726
1808
  }
1727
1809
 
1728
1810
  /// Add a new, independent panel to this viewer's layout, rendering the
1729
- /// supplied [`ViewerConfigUpdate`] into it. The panel uses the default
1730
- /// [`perspective_client::Client`] (the first passed to [`Self::load`]) to
1731
- /// resolve its `table`. Returns the generated panel id.
1732
- ///
1733
- /// Element-level config fields (`settings`, `theme`) in the argument are
1734
- /// ignored — those are shared across the element, not per-panel.
1811
+ /// supplied [`ViewerConfigInitial`] into it. Unlike [`Self::restore`]'s
1812
+ /// update-shaped argument, a new panel has no prior state, so `table`
1813
+ /// is REQUIRED — a table-less call rejects before the layout is
1814
+ /// touched. The panel uses the default [`perspective_client::Client`]
1815
+ /// (the first passed to [`Self::load`]) to resolve its `table`. Returns
1816
+ /// the generated panel id.
1817
+ ///
1818
+ /// The element-level `settings` field does not exist on the argument
1819
+ /// type (it is shared across the element, not per-panel).
1735
1820
  #[wasm_bindgen]
1736
- pub fn addPanel(&self, update: JsViewerConfigUpdate) -> ApiFuture<JsValue> {
1821
+ pub fn addPanel(&self, config: JsViewerConfigInitial) -> ApiFuture<JsValue> {
1737
1822
  clone!(self.elem, self.presentation, self.workspace);
1738
1823
  let effect = workspace.effects().guard();
1739
1824
  let notify = self.layout_changed_notify();
1740
1825
  ApiFuture::new(async move {
1741
1826
  let _effect = effect;
1742
- let update = ViewerConfigUpdate::decode(&update)?;
1827
+ // The table-required guarantee is HERE, in the argument type
1828
+ // and this decode — `create_panel` itself takes a patch.
1829
+ let config = ViewerConfigInitial::decode(&config)?;
1743
1830
  let id = create_panel(
1744
1831
  &elem,
1745
1832
  &presentation,
1746
1833
  &workspace,
1747
1834
  &notify,
1748
1835
  None,
1749
- update,
1836
+ config.into(),
1750
1837
  None,
1751
1838
  )
1752
1839
  .await?;
@@ -1864,3 +1951,107 @@ impl PerspectiveViewerElement {
1864
1951
  })
1865
1952
  }
1866
1953
  }
1954
+
1955
+ #[cfg(feature = "llm-agent")]
1956
+ #[wasm_bindgen]
1957
+ impl PerspectiveViewerElement {
1958
+ /// Configure the embedded LLM agent (see `prompt()`), replacing any prior
1959
+ /// configuration and conversation.
1960
+ ///
1961
+ /// The agent core is provider-agnostic: one OpenAI-chat-completions
1962
+ /// protocol over primitive connection fields. Exactly one of
1963
+ /// `config.url` or `config.engine` is required; the `providers` presets
1964
+ /// exported by this package are plain spreadable collections of these
1965
+ /// fields (`{...providers.anthropic, apiKey}`).
1966
+ ///
1967
+ /// - `config.url` - a full chat-completions endpoint URL (any
1968
+ /// OpenAI-compatible service: Anthropic/Gemini compatibility endpoints,
1969
+ /// LM Studio, Ollama, OpenRouter, a proxy...).
1970
+ /// - `config.engine` - an in-page engine object with an OpenAI-compatible
1971
+ /// `chat.completions.create(request)` method (e.g. WebLLM's `MLCEngine`);
1972
+ /// mutually exclusive with `url`.
1973
+ /// - `config.headers` - extra request headers, sent verbatim.
1974
+ /// - `config.apiKey` - sugar for the `Authorization: Bearer` header.
1975
+ /// - `config.model` - model id sent with each request; local servers and
1976
+ /// engines generally answer with whatever model is loaded.
1977
+ /// - `config.name` - cosmetic label for the chat badge (presets set this).
1978
+ /// - `config.systemPrompt` - extra system-prompt context appended to the
1979
+ /// agent's built-in instructions.
1980
+ /// - `config.maxTurns` - max model turns (tool-call rounds + the final
1981
+ /// answer) per `prompt()` call. Defaults to 16.
1982
+ /// - `config.docs` - the agent metadata bundle, which supplies the
1983
+ /// `search_docs` corpus and the rich tool parameter schemas: the packaged
1984
+ /// `dist/docs/perspective-docs.json` asset as a parsed object (`import
1985
+ /// docs from "…json" with { type: "json" }`), a `fetch()` `Response`, an
1986
+ /// `ArrayBuffer`, a JSON string, or a `Promise` of any of those — and/or
1987
+ /// an inline array of `{title?, text}` entries for host data definitions.
1988
+ /// Omitted, `search_docs` searches an empty corpus and the parameter
1989
+ /// schemas degrade to permissive objects.
1990
+ /// - `config.systemRole` - where the preamble (plus `systemPrompt`) is
1991
+ /// placed: `"system"` (default) or `"user"`. Some engines refuse a system
1992
+ /// message alongside `tools` because they substitute their own — WebLLM's
1993
+ /// Hermes function calling throws `CustomSystemPromptError` on ANY system
1994
+ /// message — and those need `"user"`, which folds the same text into the
1995
+ /// opening user turn.
1996
+ /// - `config.entitlements` - access grants limiting which tools the agent
1997
+ /// is offered (and may call): any of `"read_view"`, `"configure_view"`,
1998
+ /// `"manage_layout"`, `"read_docs"`, `"read_data"`. Omitted, all but
1999
+ /// `"read_data"` are granted; `["read_view", "read_docs"]` yields a
2000
+ /// read-only agent.
2001
+ ///
2002
+ /// # JavaScript Examples
2003
+ ///
2004
+ /// ```javascript
2005
+ /// import { providers } from "@perspective-dev/viewer";
2006
+ ///
2007
+ /// viewer.agentConfig({
2008
+ /// ...providers.anthropic,
2009
+ /// apiKey: "sk-ant-...",
2010
+ /// docs: fetch(
2011
+ /// "node_modules/@perspective-dev/viewer/dist/docs/perspective-docs.json",
2012
+ /// ),
2013
+ /// });
2014
+ /// ```
2015
+ #[wasm_bindgen(js_name = "agentConfig")]
2016
+ pub fn agent_config(&self, config: JsValue) -> ApiResult<()> {
2017
+ let runtime = AgentRuntime::new(&config, self.clone())?;
2018
+ self.presentation.agent.configure(runtime);
2019
+ Ok(())
2020
+ }
2021
+
2022
+ /// Run one conversational turn of the embedded LLM agent (configured via
2023
+ /// `agentConfig()`), resolving with the agent's final text response after
2024
+ /// any tool calls have been applied to this element. Turns share a
2025
+ /// conversation history (and the chat sidebar's transcript) until
2026
+ /// `agentReset()`; a call made while a turn is already running rejects.
2027
+ /// Tool activity is emitted as `perspective-agent-tool` CustomEvents on
2028
+ /// this element.
2029
+ ///
2030
+ /// # JavaScript Examples
2031
+ ///
2032
+ /// ```javascript
2033
+ /// await viewer.agentPrompt("Show me sales by region as a bar chart");
2034
+ /// ```
2035
+ #[wasm_bindgen(js_name = "agentPrompt")]
2036
+ pub fn agent_prompt(&self, prompt: String) -> js_sys::Promise {
2037
+ let presentation = self.presentation.clone();
2038
+ let fut = ApiFuture::new(async move {
2039
+ Ok(JsValue::from(presentation.agent.run_prompt(prompt).await?))
2040
+ });
2041
+
2042
+ js_sys::Promise::from(fut)
2043
+ }
2044
+
2045
+ /// Clear the agent's conversation (history and chat transcript), keeping
2046
+ /// its configuration. Cancels any in-flight turn.
2047
+ #[wasm_bindgen(js_name = "agentReset")]
2048
+ pub fn agent_reset(&self) -> js_sys::Promise {
2049
+ let presentation = self.presentation.clone();
2050
+ let fut = ApiFuture::new(async move {
2051
+ presentation.agent.reset().await;
2052
+ Ok(JsValue::UNDEFINED)
2053
+ });
2054
+
2055
+ js_sys::Promise::from(fut)
2056
+ }
2057
+ }
@@ -261,7 +261,36 @@ pub fn wire_element_events(
261
261
  }
262
262
  });
263
263
 
264
+ let layout_sub = workspace.layout_changed().add_listener({
265
+ clone!(elem);
266
+ move |panels: Vec<crate::workspace::PanelId>| {
267
+ let ids = panels
268
+ .iter()
269
+ .map(|id| JsValue::from_str(id.as_str()))
270
+ .collect::<js_sys::Array>();
271
+
272
+ let detail = js_sys::Object::new();
273
+ let _ = js_sys::Reflect::set(&detail, &JsValue::from_str("panels"), &ids);
274
+ dispatch_event(&elem, "layout-update", JsValue::from(detail)).unwrap();
275
+ }
276
+ });
277
+
278
+ let active_panel_sub = workspace.active_changed().add_listener({
279
+ clone!(elem);
280
+ move |active: Option<crate::workspace::PanelId>| {
281
+ let panel = active
282
+ .map(|id| JsValue::from_str(id.as_str()))
283
+ .unwrap_or(JsValue::NULL);
284
+
285
+ let detail = js_sys::Object::new();
286
+ let _ = js_sys::Reflect::set(&detail, &JsValue::from_str("panel"), &panel);
287
+ dispatch_event(&elem, "active-panel-update", JsValue::from(detail)).unwrap();
288
+ }
289
+ });
290
+
264
291
  vec![
292
+ layout_sub,
293
+ active_panel_sub,
265
294
  theme_sub,
266
295
  before_settings_sub,
267
296
  settings_sub,
package/src/rust/lib.rs CHANGED
@@ -31,6 +31,8 @@
31
31
  // `SESSION_CONFIG_COHERENCE_PLAN.md`) — deny, don't warn.
32
32
  #![deny(clippy::await_holding_refcell_ref)]
33
33
 
34
+ #[cfg(feature = "llm-agent")]
35
+ mod agent;
34
36
  pub mod components;
35
37
  pub mod config;
36
38
  pub mod custom_elements;
@@ -71,34 +73,48 @@ import type {
71
73
  ColumnType,
72
74
  TableInitOptions,
73
75
  ColumnWindow,
74
- ViewWindow,
76
+ ViewWindow,
75
77
  TypedArrayWindow,
76
78
  OnUpdateOptions,
77
79
  JoinOptions,
78
80
  UpdateOptions,
79
81
  DeleteOptions,
82
+ ViewConfig,
80
83
  ViewConfigUpdate,
81
84
  SystemInfo,
85
+ Scalar,
86
+ Features,
82
87
  } from "@perspective-dev/client";
83
88
 
84
89
  export type * from "../../src/ts/ts-rs/ViewerConfig.d.ts";
85
90
  export type * from "../../src/ts/ts-rs/ViewerConfigUpdate.d.ts";
91
+ export type * from "../../src/ts/ts-rs/ViewerConfigInitial.d.ts";
86
92
  export type * from "../../src/ts/ts-rs/PluginStaticConfig.d.ts";
87
93
  export type * from "../../src/ts/ts-rs/WorkspaceConfig.d.ts";
88
94
  export type * from "../../src/ts/ts-rs/WorkspaceConfigUpdate.d.ts";
89
95
  export type * from "../../src/ts/ts-rs/ExportMethod.d.ts";
90
96
  export type * from "../../src/ts/ts-rs/PanelOptions.d.ts";
97
+ export type * from "../../src/ts/ts-rs/RestoreOptions.d.ts";
91
98
  export type * from "../../src/ts/ts-rs/ClientOptions.d.ts";
92
99
  export type * from "../../src/ts/ts-rs/ExportOptions.d.ts";
93
100
  export type * from "../../src/ts/ts-rs/GetTableOptions.d.ts";
94
101
  export type * from "../../src/ts/ts-rs/GetClientOptions.d.ts";
102
+ export type * from "../../src/ts/ts-rs/CustomNumberFormatConfig.d.ts";
103
+ export type * from "../../src/ts/ts-rs/NumberFormatStyle.d.ts";
104
+ export type * from "../../src/ts/ts-rs/Notation.d.ts";
105
+ export type * from "../../src/ts/ts-rs/DatetimeFormatType.d.ts";
106
+ export type * from "../../src/ts/ts-rs/StringColorMode.d.ts";
107
+ export type * from "../../src/ts/ts-rs/DatetimeColorMode.d.ts";
108
+ export type * from "../../src/ts/ts-rs/FormatMode.d.ts";
95
109
  import type {GetTableOptions} from "../../src/ts/ts-rs/GetTableOptions.d.ts";
96
110
  import type {PanelOptions} from "../../src/ts/ts-rs/PanelOptions.d.ts";
111
+ import type {RestoreOptions} from "../../src/ts/ts-rs/RestoreOptions.d.ts";
97
112
  import type {ExportOptions} from "../../src/ts/ts-rs/ExportOptions.d.ts";
98
113
  import type {GetClientOptions} from "../../src/ts/ts-rs/GetClientOptions.d.ts";
99
114
  import type {ClientOptions} from "../../src/ts/ts-rs/ClientOptions.d.ts";
100
115
  import type {ViewerConfig} from "../../src/ts/ts-rs/ViewerConfig.d.ts";
101
116
  import type {ViewerConfigUpdate} from "../../src/ts/ts-rs/ViewerConfigUpdate.d.ts";
117
+ import type {ViewerConfigInitial} from "../../src/ts/ts-rs/ViewerConfigInitial.d.ts";
102
118
  import type {WorkspaceConfig} from "../../src/ts/ts-rs/WorkspaceConfig.d.ts";
103
119
  import type {WorkspaceConfigUpdate} from "../../src/ts/ts-rs/WorkspaceConfigUpdate.d.ts";
104
120
  "#;
@@ -19,6 +19,7 @@ use std::fmt::Display;
19
19
  pub enum ColumnLocator {
20
20
  Table(String),
21
21
  Expression(String),
22
+ Window(String),
22
23
  NewExpression,
23
24
  }
24
25
 
@@ -28,7 +29,7 @@ impl ColumnLocator {
28
29
  /// function will return None.
29
30
  pub fn name(&self) -> Option<&String> {
30
31
  match self {
31
- Self::Table(s) | Self::Expression(s) => Some(s),
32
+ Self::Table(s) | Self::Expression(s) | Self::Window(s) => Some(s),
32
33
  Self::NewExpression => None,
33
34
  }
34
35
  }
@@ -50,6 +51,19 @@ impl ColumnLocator {
50
51
  pub fn is_new_expr(&self) -> bool {
51
52
  matches!(self, ColumnLocator::NewExpression)
52
53
  }
54
+
55
+ #[inline(always)]
56
+ pub fn is_saved_window(&self) -> bool {
57
+ matches!(self, ColumnLocator::Window(_))
58
+ }
59
+
60
+ #[inline(always)]
61
+ pub fn is_window_editable(&self) -> bool {
62
+ matches!(
63
+ self,
64
+ ColumnLocator::Window(_) | ColumnLocator::NewExpression
65
+ )
66
+ }
53
67
  }
54
68
 
55
69
  #[derive(Debug, Default, Clone, Copy, PartialEq)]
@@ -57,6 +71,7 @@ impl ColumnLocator {
57
71
  pub enum ColumnSettingsTab {
58
72
  #[default]
59
73
  Attributes,
74
+ Window,
60
75
  Style,
61
76
  }
62
77
 
@@ -63,6 +63,12 @@ impl DragState {
63
63
  pub struct PresentationHandle {
64
64
  viewer_elem: HtmlElement,
65
65
 
66
+ /// The embedded LLM agent's shared model (runtime + chat transcript) —
67
+ /// carried here so the settings sidebar can render the chat tab without
68
+ /// threading a new prop chain from the element.
69
+ #[cfg(feature = "llm-agent")]
70
+ pub agent: crate::agent::AgentSlot,
71
+
66
72
  /// The available themes as detected in the browser environment or set
67
73
  /// explicitly when CORS prevents detection — a MEMO of a document
68
74
  /// external, not component state. `None` until first parsed (detection
@@ -148,6 +154,8 @@ impl Presentation {
148
154
  pub fn new(elem: &HtmlElement) -> Self {
149
155
  let theme = Self(Rc::new(PresentationHandle {
150
156
  viewer_elem: elem.clone(),
157
+ #[cfg(feature = "llm-agent")]
158
+ agent: Default::default(),
151
159
  themes: Default::default(),
152
160
  theme_init: Default::default(),
153
161
  is_workspace: Default::default(),
@@ -102,7 +102,8 @@ impl<'a> ColumnsIteratorSet<'a> {
102
102
  .get_table_columns()
103
103
  .map(|x: &Vec<String>| x.len())
104
104
  .unwrap_or_default()
105
- + self.config.expressions.len();
105
+ + self.config.expressions.len()
106
+ + self.config.windows.len();
106
107
 
107
108
  match &self.is_dragover_column {
108
109
  Some((to_index, from_column)) => {
@@ -238,6 +239,11 @@ impl<'a> ColumnsIteratorSet<'a> {
238
239
  self.order_columns(self.metadata.get_expression_columns())
239
240
  }
240
241
 
242
+ /// Generate an iterator for inactive window columns.
243
+ pub fn window(&'a self) -> impl Iterator<Item = OrderedColumn<'a>> {
244
+ self.order_columns(self.metadata.get_window_columns())
245
+ }
246
+
241
247
  /// Generate an iterator for inactive columns, which also shows the columns
242
248
  /// in sorted order by type, then name.
243
249
  pub fn inactive(&'a self) -> impl Iterator<Item = OrderedColumn<'a>> {
@@ -51,10 +51,14 @@ pub async fn get_viewer_config(
51
51
  None => presentation.get_selected_theme_name().await,
52
52
  };
53
53
  let title = session.get_title();
54
+ // Placed ⇒ bound (or binding in flight): creation requires a `table`
55
+ // by type, so a panel with neither a bound nor pending table is an
56
+ // invariant violation, not a serializable state.
54
57
  let table = session
55
58
  .get_table()
56
59
  .map(|x| x.get_name().to_owned())
57
- .or_else(|| session.pending_table());
60
+ .or_else(|| session.pending_table())
61
+ .ok_or_else(|| ApiError::from("Panel has no `table`"))?;
58
62
  let columns_config = renderer.all_columns_configs();
59
63
  Ok(ViewerConfig {
60
64
  settings,