@perspective-dev/viewer 5.1.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.
- package/dist/cdn/perspective-viewer.js +9 -9
- package/dist/cdn/perspective-viewer.js.map +4 -4
- package/dist/css/botanical.css +1 -1
- package/dist/css/dracula.css +1 -1
- package/dist/css/gruvbox-dark.css +1 -1
- package/dist/css/gruvbox.css +1 -1
- package/dist/css/intl/de.css +1 -1
- package/dist/css/intl/es.css +1 -1
- package/dist/css/intl/fr.css +1 -1
- package/dist/css/intl/ja.css +1 -1
- package/dist/css/intl/pt.css +1 -1
- package/dist/css/intl/zh.css +1 -1
- package/dist/css/intl.css +1 -1
- package/dist/css/monokai.css +1 -1
- package/dist/css/phosphor.css +1 -1
- package/dist/css/pro-dark.css +1 -1
- package/dist/css/pro.css +1 -1
- package/dist/css/solarized-dark.css +1 -1
- package/dist/css/solarized.css +1 -1
- package/dist/css/themes.css +1 -1
- package/dist/css/vaporwave.css +1 -1
- package/dist/docs/perspective-docs.json +1 -0
- package/dist/esm/column-format.d.ts +19 -28
- package/dist/esm/perspective-viewer.d.ts +2 -0
- package/dist/esm/perspective-viewer.inline.js +8 -8
- package/dist/esm/perspective-viewer.inline.js.map +4 -4
- package/dist/esm/perspective-viewer.js +9 -9
- package/dist/esm/perspective-viewer.js.map +4 -4
- package/dist/esm/providers.d.ts +79 -0
- package/dist/esm/ts-rs/CompactDisplay.d.ts +5 -0
- package/dist/esm/ts-rs/CurrencyCode.d.ts +1 -0
- package/dist/esm/ts-rs/CurrencyDisplay.d.ts +1 -0
- package/dist/esm/ts-rs/CurrencyNumberFormatStyle.d.ts +8 -0
- package/dist/esm/ts-rs/CurrencySign.d.ts +1 -0
- package/dist/esm/ts-rs/CustomDatetimeFormat.d.ts +1 -0
- package/dist/esm/ts-rs/CustomDatetimeStyleConfig.d.ts +54 -0
- package/dist/esm/ts-rs/CustomNumberFormatConfig.d.ts +34 -0
- package/dist/esm/ts-rs/DatetimeColorMode.d.ts +1 -0
- package/dist/esm/ts-rs/DatetimeFormatType.d.ts +6 -0
- package/dist/esm/ts-rs/FormatMode.d.ts +1 -0
- package/dist/esm/ts-rs/FormatUnit.d.ts +1 -0
- package/dist/esm/ts-rs/Notation.d.ts +17 -0
- package/dist/esm/ts-rs/NumberFormatStyle.d.ts +18 -0
- package/dist/esm/ts-rs/PanelViewerConfig.d.ts +41 -1
- package/dist/esm/ts-rs/PluginStaticConfig.d.ts +35 -0
- package/dist/esm/ts-rs/RestoreOptions.d.ts +19 -0
- package/dist/esm/ts-rs/RoundingMode.d.ts +1 -0
- package/dist/esm/ts-rs/RoundingPriority.d.ts +1 -0
- package/dist/esm/ts-rs/SignDisplay.d.ts +1 -0
- package/dist/esm/ts-rs/SimpleDatetimeFormat.d.ts +1 -0
- package/dist/esm/ts-rs/SimpleDatetimeStyleConfig.d.ts +24 -0
- package/dist/esm/ts-rs/SplitRollupMode.d.ts +9 -0
- package/dist/esm/ts-rs/StringColorMode.d.ts +1 -0
- package/dist/esm/ts-rs/TrailingZeroDisplay.d.ts +1 -0
- package/dist/esm/ts-rs/Unit.d.ts +1 -0
- package/dist/esm/ts-rs/UnitDisplay.d.ts +1 -0
- package/dist/esm/ts-rs/UnitNumberFormatStyle.d.ts +6 -0
- package/dist/esm/ts-rs/UseGrouping.d.ts +1 -0
- package/dist/esm/ts-rs/ViewerConfig.d.ts +41 -1
- package/dist/esm/ts-rs/ViewerConfigInitial.d.ts +175 -0
- package/dist/esm/ts-rs/ViewerConfigUpdate.d.ts +63 -0
- package/dist/esm/ts-rs/WindowSpec.d.ts +3 -2
- package/dist/esm/ts-rs/WorkspaceConfigUpdate.d.ts +7 -6
- package/dist/wasm/perspective-viewer.d.ts +134 -25
- package/dist/wasm/perspective-viewer.js +367 -124
- package/dist/wasm/perspective-viewer.wasm +0 -0
- package/dist/wasm/perspective-viewer.wasm.d.ts +18 -15
- package/package.json +2 -1
- package/src/css/_viewer_bundle.css +1 -0
- package/src/css/column-selector.css +8 -0
- package/src/css/config-selector.css +38 -3
- package/src/css/form/code-editor.css +2 -3
- package/src/css/form/mirrored-textarea.css +81 -0
- package/src/css/viewer.css +328 -0
- package/src/rust/agent/client/mod.rs +19 -0
- package/src/rust/agent/client/protocol.rs +320 -0
- package/src/rust/agent/client/transport.rs +287 -0
- package/src/rust/agent/client/turn.rs +174 -0
- package/src/rust/agent/config.rs +159 -0
- package/src/rust/agent/docs.rs +293 -0
- package/src/rust/agent/markdown/block.rs +509 -0
- package/src/rust/agent/markdown/entity.rs +52 -0
- package/src/rust/agent/markdown/events.rs +71 -0
- package/src/rust/agent/markdown/inline.rs +497 -0
- package/src/rust/agent/markdown/mod.rs +466 -0
- package/src/rust/agent/mod.rs +23 -0
- package/src/rust/agent/preamble.md +16 -0
- package/src/rust/agent/runtime.rs +201 -0
- package/src/rust/agent/slot.rs +236 -0
- package/src/rust/agent/tools.rs +1110 -0
- package/src/rust/components/chat_panel.rs +289 -0
- package/src/rust/components/column_selector/config_selector.rs +76 -7
- package/src/rust/components/column_selector.rs +7 -0
- package/src/rust/components/containers/dragdrop_list.rs +37 -0
- package/src/rust/components/form/code_editor.rs +14 -23
- package/src/rust/components/form/debug.rs +8 -5
- package/src/rust/components/form/mirrored_textarea.rs +165 -0
- package/src/rust/components/form/mod.rs +1 -0
- package/src/rust/components/mod.rs +2 -0
- package/src/rust/components/settings_panel.rs +80 -2
- package/src/rust/components/viewer/panels.rs +9 -14
- package/src/rust/components/viewer/render.rs +2 -0
- package/src/rust/components/window_editor.rs +75 -103
- package/src/rust/config/datetime_column_style/custom.rs +17 -0
- package/src/rust/config/datetime_column_style/simple.rs +10 -0
- package/src/rust/config/number_string_format.rs +33 -0
- package/src/rust/config/options.rs +18 -0
- package/src/rust/config/plugin_static_config.rs +120 -5
- package/src/rust/config/viewer_config.rs +220 -1
- package/src/rust/config/workspace_config.rs +7 -6
- package/src/rust/custom_elements/viewer.rs +209 -18
- package/src/rust/custom_events.rs +29 -0
- package/src/rust/lib.rs +13 -0
- package/src/rust/presentation.rs +8 -0
- package/src/rust/queries/get_viewer_config.rs +5 -1
- package/src/rust/session/column_defaults_update.rs +18 -0
- package/src/rust/session/metadata.rs +18 -20
- package/src/rust/session/replace_expression_update.rs +1 -0
- package/src/rust/tasks/create_panel.rs +18 -8
- package/src/rust/tasks/edit_window.rs +1 -1
- package/src/rust/tasks/restore_panel.rs +34 -17
- package/src/rust/tasks/sync_update_panels.rs +7 -23
- package/src/rust/workspace.rs +112 -20
- package/src/themes/intl/de.css +16 -0
- package/src/themes/intl/es.css +16 -0
- package/src/themes/intl/fr.css +16 -0
- package/src/themes/intl/ja.css +16 -0
- package/src/themes/intl/pt.css +16 -0
- package/src/themes/intl/zh.css +16 -0
- package/src/themes/intl.css +16 -0
- package/src/ts/column-format.ts +67 -46
- package/src/ts/perspective-viewer.ts +2 -0
- package/src/ts/providers.ts +96 -0
- package/src/ts/ts-rs/CompactDisplay.ts +3 -0
- package/src/ts/ts-rs/CurrencyCode.ts +3 -0
- package/src/ts/ts-rs/CurrencyDisplay.ts +3 -0
- package/src/ts/ts-rs/CurrencyNumberFormatStyle.ts +6 -0
- package/src/ts/ts-rs/CurrencySign.ts +3 -0
- package/src/ts/ts-rs/CustomDatetimeFormat.ts +3 -0
- package/src/ts/ts-rs/CustomDatetimeStyleConfig.ts +54 -0
- package/src/ts/ts-rs/CustomNumberFormatConfig.ts +25 -0
- package/src/ts/ts-rs/DatetimeColorMode.ts +3 -0
- package/src/ts/ts-rs/DatetimeFormatType.ts +8 -0
- package/src/ts/ts-rs/FormatMode.ts +3 -0
- package/src/ts/ts-rs/FormatUnit.ts +3 -0
- package/src/ts/ts-rs/Notation.ts +11 -0
- package/src/ts/ts-rs/NumberFormatStyle.ts +12 -0
- package/src/ts/ts-rs/PanelViewerConfig.ts +47 -1
- package/src/ts/ts-rs/PluginStaticConfig.ts +36 -1
- package/src/ts/ts-rs/RestoreOptions.ts +20 -0
- package/src/ts/ts-rs/RoundingMode.ts +3 -0
- package/src/ts/ts-rs/RoundingPriority.ts +3 -0
- package/src/ts/ts-rs/SignDisplay.ts +3 -0
- package/src/ts/ts-rs/SimpleDatetimeFormat.ts +3 -0
- package/src/ts/ts-rs/SimpleDatetimeStyleConfig.ts +25 -0
- package/src/ts/ts-rs/SplitRollupMode.ts +11 -0
- package/src/ts/ts-rs/StringColorMode.ts +3 -0
- package/src/ts/ts-rs/TrailingZeroDisplay.ts +3 -0
- package/src/ts/ts-rs/Unit.ts +3 -0
- package/src/ts/ts-rs/UnitDisplay.ts +3 -0
- package/src/ts/ts-rs/UnitNumberFormatStyle.ts +5 -0
- package/src/ts/ts-rs/UseGrouping.ts +3 -0
- package/src/ts/ts-rs/ViewerConfig.ts +47 -1
- package/src/ts/ts-rs/ViewerConfigInitial.ts +164 -0
- package/src/ts/ts-rs/ViewerConfigUpdate.ts +72 -2
- package/src/ts/ts-rs/WindowSpec.ts +3 -2
- package/src/ts/ts-rs/WorkspaceConfigUpdate.ts +7 -6
- package/dist/esm/ts-rs/WindowAggregate.d.ts +0 -1
- package/src/ts/ts-rs/WindowAggregate.ts +0 -3
- /package/dist/wasm/snippets/{perspective-viewer-8a8c7d5d696b43ae → perspective-viewer-02e461f3d7062b26}/inline0.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-8a8c7d5d696b43ae → perspective-viewer-02e461f3d7062b26}/inline1.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-8a8c7d5d696b43ae → perspective-viewer-02e461f3d7062b26}/inline2.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-8a8c7d5d696b43ae → perspective-viewer-02e461f3d7062b26}/inline3.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-8a8c7d5d696b43ae → perspective-viewer-02e461f3d7062b26}/inline4.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-8a8c7d5d696b43ae → perspective-viewer-02e461f3d7062b26}/inline5.js +0 -0
|
@@ -42,12 +42,42 @@ pub struct ViewerConfig<V: TS = String> {
|
|
|
42
42
|
/// whole-element config format.
|
|
43
43
|
#[derive(Debug, Default, Serialize, PartialEq, TS)]
|
|
44
44
|
pub struct PanelViewerConfig<V: TS = String> {
|
|
45
|
+
/// The `@perspective-dev/viewer` version that wrote this config,
|
|
46
|
+
/// stamped on save and used to migrate older tokens. Callers do not
|
|
47
|
+
/// set it.
|
|
45
48
|
pub version: V,
|
|
49
|
+
|
|
50
|
+
/// Per-column styling, keyed by column name. The viewer treats the
|
|
51
|
+
/// values as opaque — their shape is defined by the ACTIVE plugin,
|
|
52
|
+
/// so a config written for one plugin may carry keys another
|
|
53
|
+
/// ignores. Query the live shape with the `get_style_schema` agent
|
|
54
|
+
/// tool, or the plugin's `column_config_schema()`.
|
|
46
55
|
pub columns_config: ColumnConfigMap,
|
|
56
|
+
|
|
57
|
+
/// Name of the visualization plugin, from the set registered on the
|
|
58
|
+
/// page (the `list_plugins` agent tool, or the plugin picker). This
|
|
59
|
+
/// also decides what the view fields MEAN visually: `columns` is
|
|
60
|
+
/// positional and each plugin reads the positions differently, and
|
|
61
|
+
/// `group_by`/`split_by` draw different things per plugin.
|
|
47
62
|
pub plugin: String,
|
|
63
|
+
|
|
64
|
+
/// Plugin-wide settings (as opposed to the per-column
|
|
65
|
+
/// [`Self::columns_config`]). Opaque to the viewer and defined by
|
|
66
|
+
/// the active plugin; see `get_style_schema`.
|
|
48
67
|
pub plugin_config: serde_json::Map<String, Value>,
|
|
49
|
-
|
|
68
|
+
|
|
69
|
+
/// Name of the `Table` this panel renders, as hosted on the panel's
|
|
70
|
+
/// `Client`. Every placed panel has a table binding (creation
|
|
71
|
+
/// requires one by type — [`ViewerConfigInitial`]), so the saved
|
|
72
|
+
/// config carries it unconditionally.
|
|
73
|
+
pub table: String,
|
|
74
|
+
|
|
75
|
+
/// Selected theme NAME (e.g. `"Pro Dark"`) — not a CSS value. Valid
|
|
76
|
+
/// names are the Perspective themes loaded on the page, which
|
|
77
|
+
/// `resetThemes()` re-scans. `None` selects the first available.
|
|
50
78
|
pub theme: Option<String>,
|
|
79
|
+
|
|
80
|
+
/// Panel title, shown in its tab. `None` renders the default title.
|
|
51
81
|
pub title: Option<String>,
|
|
52
82
|
|
|
53
83
|
#[serde(flatten)]
|
|
@@ -93,41 +123,73 @@ impl Deref for PluginConfig {
|
|
|
93
123
|
|
|
94
124
|
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, TS)]
|
|
95
125
|
pub struct ViewerConfigUpdate {
|
|
126
|
+
/// The `@perspective-dev/viewer` version a saved config was written
|
|
127
|
+
/// by, used to migrate older tokens. Omit it — the viewer stamps
|
|
128
|
+
/// the current version on save.
|
|
96
129
|
#[serde(default)]
|
|
97
130
|
#[ts(as = "Option<_>")]
|
|
98
131
|
#[ts(optional)]
|
|
99
132
|
pub version: VersionUpdate,
|
|
100
133
|
|
|
134
|
+
/// Name of the visualization plugin to switch to, from the set
|
|
135
|
+
/// registered on the page (the `list_plugins` agent tool, or the
|
|
136
|
+
/// plugin picker). Changing it changes what the view fields MEAN:
|
|
137
|
+
/// `columns` is positional and every plugin reads the positions
|
|
138
|
+
/// differently, and `group_by`/`split_by` draw different things per
|
|
139
|
+
/// plugin — so read the new plugin's roles before writing `columns`
|
|
140
|
+
/// for it.
|
|
101
141
|
#[serde(default)]
|
|
102
142
|
#[ts(as = "Option<_>")]
|
|
103
143
|
#[ts(optional)]
|
|
104
144
|
pub plugin: PluginUpdate,
|
|
105
145
|
|
|
146
|
+
/// Panel title, shown in its tab. `null` restores the default
|
|
147
|
+
/// title; omitting the field leaves the current one.
|
|
106
148
|
#[serde(default)]
|
|
107
149
|
#[ts(as = "Option<_>")]
|
|
108
150
|
#[ts(optional)]
|
|
109
151
|
pub title: TitleUpdate,
|
|
110
152
|
|
|
153
|
+
/// Name of the `Table` to render, as hosted on this panel's
|
|
154
|
+
/// `Client`. Rebinding an existing panel to another table keeps the
|
|
155
|
+
/// rest of the config, so column names that do not exist in the new
|
|
156
|
+
/// table will fail validation.
|
|
111
157
|
#[serde(default)]
|
|
112
158
|
#[ts(as = "Option<_>")]
|
|
113
159
|
#[ts(optional)]
|
|
114
160
|
pub table: TableUpdate,
|
|
115
161
|
|
|
162
|
+
/// Theme NAME (e.g. `"Pro Dark"`) — not a CSS value. Valid names are
|
|
163
|
+
/// the Perspective themes loaded on the page, re-scanned by
|
|
164
|
+
/// `resetThemes()`. `null` selects the default.
|
|
116
165
|
#[serde(default)]
|
|
117
166
|
#[ts(as = "Option<_>")]
|
|
118
167
|
#[ts(optional)]
|
|
119
168
|
pub theme: ThemeUpdate,
|
|
120
169
|
|
|
170
|
+
/// Whether the settings sidebar is OPEN. Purely cosmetic chrome —
|
|
171
|
+
/// it does not affect what the viewer renders, and it is
|
|
172
|
+
/// element-level rather than per-panel.
|
|
121
173
|
#[serde(default)]
|
|
122
174
|
#[ts(as = "Option<_>")]
|
|
123
175
|
#[ts(optional)]
|
|
124
176
|
pub settings: SettingsUpdate,
|
|
125
177
|
|
|
178
|
+
/// Plugin-wide settings (as opposed to the per-column
|
|
179
|
+
/// [`Self::columns_config`]). The viewer passes these through
|
|
180
|
+
/// opaquely — their valid keys are defined by the ACTIVE plugin and
|
|
181
|
+
/// vary by plugin and by state, so query them with the
|
|
182
|
+
/// `get_style_schema` agent tool rather than guessing.
|
|
126
183
|
#[serde(default)]
|
|
127
184
|
#[ts(as = "Option<_>")]
|
|
128
185
|
#[ts(optional)]
|
|
129
186
|
pub plugin_config: PluginConfigUpdate,
|
|
130
187
|
|
|
188
|
+
/// Per-column styling — formatting, colors, and other per-column
|
|
189
|
+
/// controls — keyed by column name. Opaque to the viewer and
|
|
190
|
+
/// plugin-defined like [`Self::plugin_config`]; `get_style_schema`
|
|
191
|
+
/// reports the valid keys for a given column under the active
|
|
192
|
+
/// plugin.
|
|
131
193
|
#[serde(default)]
|
|
132
194
|
#[ts(as = "Option<_>")]
|
|
133
195
|
#[ts(optional)]
|
|
@@ -150,6 +212,119 @@ impl ViewerConfigUpdate {
|
|
|
150
212
|
}
|
|
151
213
|
}
|
|
152
214
|
|
|
215
|
+
/// The initial configuration of a NEW panel (`addPanel`, `restore`'s
|
|
216
|
+
/// panel-creating upsert, `restoreWorkspace` `panels` entries). Unlike
|
|
217
|
+
/// [`ViewerConfigUpdate`] — a patch against existing state — creation has
|
|
218
|
+
/// no prior state: `table` is REQUIRED (a placed panel without a table
|
|
219
|
+
/// binding would be permanently blank), absent fields mean "default"
|
|
220
|
+
/// rather than "leave unchanged" (so no [`OptionalUpdate`] tri-state), and
|
|
221
|
+
/// there is no `settings` field (element-level, not per-panel).
|
|
222
|
+
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
|
|
223
|
+
pub struct ViewerConfigInitial {
|
|
224
|
+
/// Name of the `Table` the new panel renders, as hosted on the
|
|
225
|
+
/// `Client`. REQUIRED: a placed panel with no table binding would be
|
|
226
|
+
/// permanently blank.
|
|
227
|
+
pub table: String,
|
|
228
|
+
|
|
229
|
+
/// The `@perspective-dev/viewer` version a saved config was written
|
|
230
|
+
/// by. Omit it when creating a panel.
|
|
231
|
+
#[ts(optional)]
|
|
232
|
+
pub version: Option<String>,
|
|
233
|
+
|
|
234
|
+
/// Name of the visualization plugin, from the set registered on the
|
|
235
|
+
/// page (the `list_plugins` agent tool, or the plugin picker).
|
|
236
|
+
/// Decides what the view fields MEAN: `columns` is positional and
|
|
237
|
+
/// every plugin reads the positions differently, and
|
|
238
|
+
/// `group_by`/`split_by` draw different things per plugin. Absent
|
|
239
|
+
/// uses the default plugin.
|
|
240
|
+
#[ts(optional)]
|
|
241
|
+
pub plugin: Option<String>,
|
|
242
|
+
|
|
243
|
+
/// Panel title, shown in its tab. Absent renders the default title.
|
|
244
|
+
#[ts(optional)]
|
|
245
|
+
pub title: Option<String>,
|
|
246
|
+
|
|
247
|
+
/// Theme NAME (e.g. `"Pro Dark"`) — not a CSS value. Valid names are
|
|
248
|
+
/// the Perspective themes loaded on the page. Absent uses the
|
|
249
|
+
/// default.
|
|
250
|
+
#[ts(optional)]
|
|
251
|
+
pub theme: Option<String>,
|
|
252
|
+
|
|
253
|
+
/// Plugin-wide settings (as opposed to the per-column
|
|
254
|
+
/// [`Self::columns_config`]). Opaque to the viewer and defined by
|
|
255
|
+
/// the ACTIVE plugin; query the valid keys with `get_style_schema`
|
|
256
|
+
/// rather than guessing.
|
|
257
|
+
#[ts(optional)]
|
|
258
|
+
pub plugin_config: Option<serde_json::Map<String, Value>>,
|
|
259
|
+
|
|
260
|
+
/// Per-column styling — formatting, colors, and other per-column
|
|
261
|
+
/// controls — keyed by column name. Plugin-defined like
|
|
262
|
+
/// [`Self::plugin_config`]; see `get_style_schema`.
|
|
263
|
+
#[ts(optional)]
|
|
264
|
+
pub columns_config: Option<ColumnConfigMap>,
|
|
265
|
+
|
|
266
|
+
#[serde(flatten)]
|
|
267
|
+
pub view_config: ViewConfigUpdate,
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
impl ViewerConfigInitial {
|
|
271
|
+
/// Decode a `JsValue` by auto-detecting format from JavaScript type.
|
|
272
|
+
pub fn decode(config: &JsValue) -> ApiResult<Self> {
|
|
273
|
+
Ok(config.into_serde_ext()?)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/// A default-config panel bound to `table` (the "New panel" menus).
|
|
277
|
+
/// Exhaustive on purpose — same drift alarm as the `From` impl below.
|
|
278
|
+
pub fn new(table: impl Into<String>) -> Self {
|
|
279
|
+
Self {
|
|
280
|
+
table: table.into(),
|
|
281
|
+
version: None,
|
|
282
|
+
plugin: None,
|
|
283
|
+
title: None,
|
|
284
|
+
theme: None,
|
|
285
|
+
plugin_config: None,
|
|
286
|
+
columns_config: None,
|
|
287
|
+
view_config: ViewConfigUpdate::default(),
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
fn up<T: Clone>(value: Option<T>) -> OptionalUpdate<T> {
|
|
293
|
+
match value {
|
|
294
|
+
Some(value) => OptionalUpdate::Update(value),
|
|
295
|
+
None => OptionalUpdate::Missing,
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Constructed EXHAUSTIVELY on purpose: a field added to
|
|
300
|
+
// `ViewerConfigUpdate` breaks this impl at compile time, forcing the
|
|
301
|
+
// "should creation carry it?" decision (the drift alarm).
|
|
302
|
+
impl From<ViewerConfigInitial> for ViewerConfigUpdate {
|
|
303
|
+
fn from(value: ViewerConfigInitial) -> Self {
|
|
304
|
+
ViewerConfigUpdate {
|
|
305
|
+
version: up(value.version),
|
|
306
|
+
plugin: up(value.plugin),
|
|
307
|
+
title: up(value.title),
|
|
308
|
+
table: OptionalUpdate::Update(value.table),
|
|
309
|
+
theme: up(value.theme),
|
|
310
|
+
settings: OptionalUpdate::Missing,
|
|
311
|
+
plugin_config: up(value.plugin_config),
|
|
312
|
+
columns_config: up(value.columns_config),
|
|
313
|
+
view_config: value.view_config,
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// There is deliberately NO `TryFrom<ViewerConfigUpdate>` here. Requiring a
|
|
319
|
+
// `table` is a property of the CREATION ENTRY POINTS — `addPanel`'s
|
|
320
|
+
// argument type, `WorkspaceConfigUpdate::panels`, and the agent's
|
|
321
|
+
// `add_panel` decode — each of which already has a `ViewerConfigInitial`
|
|
322
|
+
// in hand. An update→initial conversion exists only to let a route holding
|
|
323
|
+
// a PATCH pretend it is creating from scratch, which is how `restore`'s
|
|
324
|
+
// upsert acquired the gate and started rejecting the table-less
|
|
325
|
+
// restore-then-`load` contract. Its absence is what keeps that from
|
|
326
|
+
// recurring: `create_panel` takes an update, so no caller needs one.
|
|
327
|
+
|
|
153
328
|
impl std::fmt::Display for ViewerConfigUpdate {
|
|
154
329
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
155
330
|
write!(
|
|
@@ -185,6 +360,50 @@ pub type VersionUpdate = OptionalUpdate<String>;
|
|
|
185
360
|
pub type ColumnConfigUpdate = OptionalUpdate<ColumnConfigMap>;
|
|
186
361
|
pub type PluginConfigUpdate = OptionalUpdate<serde_json::Map<String, Value>>;
|
|
187
362
|
|
|
363
|
+
#[cfg(test)]
|
|
364
|
+
mod tests {
|
|
365
|
+
use super::*;
|
|
366
|
+
|
|
367
|
+
#[test]
|
|
368
|
+
fn initial_requires_a_table() {
|
|
369
|
+
let json = serde_json::json!({ "group_by": ["State"] });
|
|
370
|
+
let err = serde_json::from_value::<ViewerConfigInitial>(json).unwrap_err();
|
|
371
|
+
assert!(format!("{err}").contains("table"));
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/// The creation → patch direction is the only one that exists (see the
|
|
375
|
+
/// note above the `From` impl); a `table` becomes a concrete update and
|
|
376
|
+
/// the element-level `settings` is not carried.
|
|
377
|
+
#[test]
|
|
378
|
+
fn initial_widens_to_an_update() {
|
|
379
|
+
let json = serde_json::json!({
|
|
380
|
+
"table": "superstore",
|
|
381
|
+
"plugin": "Datagrid",
|
|
382
|
+
"group_by": ["State"],
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
let initial: ViewerConfigInitial = serde_json::from_value(json).unwrap();
|
|
386
|
+
let update = ViewerConfigUpdate::from(initial);
|
|
387
|
+
assert!(matches!(&update.table, OptionalUpdate::Update(x) if x == "superstore"));
|
|
388
|
+
assert!(matches!(&update.settings, OptionalUpdate::Missing));
|
|
389
|
+
assert!(matches!(&update.plugin, OptionalUpdate::Update(x) if x == "Datagrid"));
|
|
390
|
+
assert_eq!(
|
|
391
|
+
update.view_config.group_by.as_deref(),
|
|
392
|
+
Some(&["State".to_owned()][..])
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/// A table-less patch is a legitimate creation input now that
|
|
397
|
+
/// `create_panel` takes an update — the deferred panel a `load()`
|
|
398
|
+
/// binds. Nothing in this module may reject it.
|
|
399
|
+
#[test]
|
|
400
|
+
fn a_table_less_update_is_representable() {
|
|
401
|
+
let json = serde_json::json!({ "group_by": ["State"] });
|
|
402
|
+
let update: ViewerConfigUpdate = serde_json::from_value(json).unwrap();
|
|
403
|
+
assert!(matches!(&update.table, OptionalUpdate::Missing));
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
188
407
|
/// Handles `{}` when included as a field with `#[serde(default)]`.
|
|
189
408
|
impl<T: Clone> Default for OptionalUpdate<T> {
|
|
190
409
|
fn default() -> Self {
|
|
@@ -14,7 +14,7 @@ use std::collections::BTreeMap;
|
|
|
14
14
|
|
|
15
15
|
use perspective_client::config::Filter;
|
|
16
16
|
|
|
17
|
-
use crate::config::{PanelViewerConfig,
|
|
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::
|
|
63
|
-
/// but `panels` entries are
|
|
64
|
-
///
|
|
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,
|
|
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)
|
|
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
|
-
/// - `
|
|
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<
|
|
986
|
+
options: Option<JsRestoreOptions>,
|
|
964
987
|
) -> JsVoidPromise {
|
|
965
|
-
let
|
|
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 [`
|
|
1730
|
-
///
|
|
1731
|
-
///
|
|
1732
|
-
///
|
|
1733
|
-
///
|
|
1734
|
-
///
|
|
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,
|
|
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
|
-
|
|
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
|
¬ify,
|
|
1748
1835
|
None,
|
|
1749
|
-
|
|
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
|
+
}
|