@aceshooting/lyra-ui 1.2.0 → 2.0.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/README.md +11 -0
- package/custom-elements.json +23341 -11202
- package/dist/components/app-rail/app-rail.d.ts +171 -0
- package/dist/components/app-rail/app-rail.js +483 -0
- package/dist/components/app-rail/app-rail.styles.d.ts +1 -0
- package/dist/components/app-rail/app-rail.styles.js +125 -0
- package/dist/components/attachment-chip/attachment-chip.d.ts +114 -0
- package/dist/components/attachment-chip/attachment-chip.js +312 -0
- package/dist/components/attachment-chip/attachment-chip.styles.d.ts +1 -0
- package/dist/components/attachment-chip/attachment-chip.styles.js +184 -0
- package/dist/components/attachment-trigger/attachment-trigger.d.ts +83 -0
- package/dist/components/attachment-trigger/attachment-trigger.js +258 -0
- package/dist/components/attachment-trigger/attachment-trigger.styles.d.ts +1 -0
- package/dist/components/attachment-trigger/attachment-trigger.styles.js +68 -0
- package/dist/components/chart/box-plot.js +11 -1
- package/dist/components/chart/chart-loader.d.ts +44 -13
- package/dist/components/chart/chart-loader.js +65 -18
- package/dist/components/chart/chart.d.ts +1 -2
- package/dist/components/chart/chart.js +67 -12
- package/dist/components/chart/histogram-bin.d.ts +4 -1
- package/dist/components/chart/histogram-bin.js +24 -14
- package/dist/components/chart/lite-chart.d.ts +54 -0
- package/dist/components/chart/lite-chart.js +140 -22
- package/dist/components/chart/lite-chart.styles.js +9 -0
- package/dist/components/chat-composer/chat-composer.d.ts +92 -0
- package/dist/components/chat-composer/chat-composer.js +285 -0
- package/dist/components/chat-composer/chat-composer.styles.d.ts +1 -0
- package/dist/components/chat-composer/chat-composer.styles.js +135 -0
- package/dist/components/chat-message/chat-message.d.ts +113 -0
- package/dist/components/chat-message/chat-message.js +291 -0
- package/dist/components/chat-message/chat-message.styles.d.ts +1 -0
- package/dist/components/chat-message/chat-message.styles.js +203 -0
- package/dist/components/checkbox/checkbox.d.ts +59 -0
- package/dist/components/checkbox/checkbox.js +230 -0
- package/dist/components/checkbox/checkbox.styles.d.ts +1 -0
- package/dist/components/checkbox/checkbox.styles.js +70 -0
- package/dist/components/chip/chip-group.d.ts +56 -0
- package/dist/components/chip/chip-group.js +124 -0
- package/dist/components/chip/chip-group.styles.d.ts +1 -0
- package/dist/components/chip/chip-group.styles.js +57 -0
- package/dist/components/chip/chip.d.ts +64 -0
- package/dist/components/chip/chip.js +115 -0
- package/dist/components/chip/chip.styles.d.ts +1 -0
- package/dist/components/chip/chip.styles.js +115 -0
- package/dist/components/citation-badge/citation-badge.d.ts +113 -0
- package/dist/components/citation-badge/citation-badge.js +300 -0
- package/dist/components/citation-badge/citation-badge.styles.d.ts +1 -0
- package/dist/components/citation-badge/citation-badge.styles.js +96 -0
- package/dist/components/code-block/code-block.d.ts +89 -0
- package/dist/components/code-block/code-block.js +317 -0
- package/dist/components/code-block/code-block.styles.d.ts +1 -0
- package/dist/components/code-block/code-block.styles.js +187 -0
- package/dist/components/code-block/code-loader.d.ts +44 -0
- package/dist/components/code-block/code-loader.js +79 -0
- package/dist/components/combobox/combobox.d.ts +19 -1
- package/dist/components/combobox/combobox.js +84 -14
- package/dist/components/combobox/option.d.ts +5 -1
- package/dist/components/combobox/option.js +35 -0
- package/dist/components/context-meter/context-meter.d.ts +53 -0
- package/dist/components/context-meter/context-meter.js +150 -0
- package/dist/components/context-meter/context-meter.styles.d.ts +1 -0
- package/dist/components/context-meter/context-meter.styles.js +120 -0
- package/dist/components/conversation-item/conversation-item.d.ts +128 -0
- package/dist/components/conversation-item/conversation-item.js +322 -0
- package/dist/components/conversation-item/conversation-item.styles.d.ts +1 -0
- package/dist/components/conversation-item/conversation-item.styles.js +155 -0
- package/dist/components/date-picker/date-input.d.ts +24 -0
- package/dist/components/date-picker/date-input.js +134 -22
- package/dist/components/date-picker/date-picker.d.ts +7 -0
- package/dist/components/date-picker/date-picker.js +85 -16
- package/dist/components/dialog/confirm.d.ts +40 -0
- package/dist/components/dialog/confirm.js +79 -0
- package/dist/components/dialog/dialog.d.ts +85 -0
- package/dist/components/dialog/dialog.js +272 -0
- package/dist/components/dialog/dialog.styles.d.ts +1 -0
- package/dist/components/dialog/dialog.styles.js +52 -0
- package/dist/components/dock-panel/dock-panel.d.ts +134 -0
- package/dist/components/dock-panel/dock-panel.js +345 -0
- package/dist/components/dock-panel/dock-panel.styles.d.ts +1 -0
- package/dist/components/dock-panel/dock-panel.styles.js +145 -0
- package/dist/components/document-preview/document-preview.d.ts +135 -0
- package/dist/components/document-preview/document-preview.js +372 -0
- package/dist/components/document-preview/document-preview.styles.d.ts +1 -0
- package/dist/components/document-preview/document-preview.styles.js +191 -0
- package/dist/components/export-button/csv.js +1 -1
- package/dist/components/export-button/export-button.js +2 -0
- package/dist/components/flag/flag.d.ts +29 -13
- package/dist/components/flag/flag.js +39 -13
- package/dist/components/gauge/gauge.js +19 -10
- package/dist/components/generation-status/generation-status.d.ts +109 -0
- package/dist/components/generation-status/generation-status.js +273 -0
- package/dist/components/generation-status/generation-status.styles.d.ts +1 -0
- package/dist/components/generation-status/generation-status.styles.js +84 -0
- package/dist/components/heatmap/calendar-grid.d.ts +4 -1
- package/dist/components/heatmap/calendar-grid.js +25 -12
- package/dist/components/heatmap/heatmap-scale.d.ts +6 -0
- package/dist/components/heatmap/heatmap-scale.js +7 -1
- package/dist/components/heatmap/heatmap.d.ts +74 -0
- package/dist/components/heatmap/heatmap.js +135 -23
- package/dist/components/json-viewer/json-viewer.d.ts +53 -0
- package/dist/components/json-viewer/json-viewer.js +283 -0
- package/dist/components/json-viewer/json-viewer.styles.d.ts +1 -0
- package/dist/components/json-viewer/json-viewer.styles.js +176 -0
- package/dist/components/kbd/kbd.d.ts +77 -0
- package/dist/components/kbd/kbd.js +214 -0
- package/dist/components/kbd/kbd.styles.d.ts +1 -0
- package/dist/components/kbd/kbd.styles.js +52 -0
- package/dist/components/live-region/live-region.d.ts +81 -0
- package/dist/components/live-region/live-region.js +153 -0
- package/dist/components/live-region/live-region.styles.d.ts +1 -0
- package/dist/components/live-region/live-region.styles.js +10 -0
- package/dist/components/map/map.d.ts +8 -6
- package/dist/components/map/map.js +44 -8
- package/dist/components/markdown/markdown-loader.d.ts +34 -0
- package/dist/components/markdown/markdown-loader.js +43 -0
- package/dist/components/markdown/markdown.d.ts +81 -0
- package/dist/components/markdown/markdown.js +284 -0
- package/dist/components/markdown/markdown.styles.d.ts +1 -0
- package/dist/components/markdown/markdown.styles.js +82 -0
- package/dist/components/media-card/media-card.d.ts +122 -0
- package/dist/components/media-card/media-card.js +295 -0
- package/dist/components/media-card/media-card.styles.d.ts +1 -0
- package/dist/components/media-card/media-card.styles.js +132 -0
- package/dist/components/mention-popover/mention-popover.d.ts +200 -0
- package/dist/components/mention-popover/mention-popover.js +475 -0
- package/dist/components/mention-popover/mention-popover.styles.d.ts +1 -0
- package/dist/components/mention-popover/mention-popover.styles.js +101 -0
- package/dist/components/menu/menu-item.d.ts +62 -0
- package/dist/components/menu/menu-item.js +119 -0
- package/dist/components/menu/menu-item.styles.d.ts +1 -0
- package/dist/components/menu/menu-item.styles.js +67 -0
- package/dist/components/menu/menu.d.ts +143 -0
- package/dist/components/menu/menu.js +365 -0
- package/dist/components/menu/menu.styles.d.ts +1 -0
- package/dist/components/menu/menu.styles.js +66 -0
- package/dist/components/model-select/model-select.d.ts +125 -0
- package/dist/components/model-select/model-select.js +490 -0
- package/dist/components/model-select/model-select.styles.d.ts +1 -0
- package/dist/components/model-select/model-select.styles.js +189 -0
- package/dist/components/model-settings-panel/model-settings-panel.d.ts +69 -0
- package/dist/components/model-settings-panel/model-settings-panel.js +145 -0
- package/dist/components/model-settings-panel/model-settings-panel.styles.d.ts +1 -0
- package/dist/components/model-settings-panel/model-settings-panel.styles.js +82 -0
- package/dist/components/playback/playback.d.ts +13 -1
- package/dist/components/playback/playback.js +47 -14
- package/dist/components/responsive-panel/responsive-panel.d.ts +150 -0
- package/dist/components/responsive-panel/responsive-panel.js +365 -0
- package/dist/components/responsive-panel/responsive-panel.styles.d.ts +1 -0
- package/dist/components/responsive-panel/responsive-panel.styles.js +103 -0
- package/dist/components/result-card/result-card.d.ts +44 -0
- package/dist/components/result-card/result-card.js +83 -0
- package/dist/components/result-card/result-card.styles.d.ts +1 -0
- package/dist/components/result-card/result-card.styles.js +50 -0
- package/dist/components/result-card/result-field.d.ts +36 -0
- package/dist/components/result-card/result-field.js +87 -0
- package/dist/components/result-card/result-field.styles.d.ts +1 -0
- package/dist/components/result-card/result-field.styles.js +32 -0
- package/dist/components/select/select.d.ts +43 -2
- package/dist/components/select/select.js +150 -17
- package/dist/components/slider/slider.d.ts +89 -0
- package/dist/components/slider/slider.js +352 -0
- package/dist/components/slider/slider.styles.d.ts +1 -0
- package/dist/components/slider/slider.styles.js +87 -0
- package/dist/components/source-card/source-card.d.ts +92 -0
- package/dist/components/source-card/source-card.js +148 -0
- package/dist/components/source-card/source-card.styles.d.ts +1 -0
- package/dist/components/source-card/source-card.styles.js +69 -0
- package/dist/components/source-list/source-list.d.ts +63 -0
- package/dist/components/source-list/source-list.js +122 -0
- package/dist/components/source-list/source-list.styles.d.ts +1 -0
- package/dist/components/source-list/source-list.styles.js +59 -0
- package/dist/components/sparkline/sparkline.js +27 -13
- package/dist/components/split/split.d.ts +93 -1
- package/dist/components/split/split.js +284 -15
- package/dist/components/split/split.styles.js +30 -0
- package/dist/components/stat/stat.d.ts +6 -1
- package/dist/components/stat/stat.js +8 -2
- package/dist/components/stream-status/stream-status.d.ts +110 -0
- package/dist/components/stream-status/stream-status.js +210 -0
- package/dist/components/stream-status/stream-status.styles.d.ts +1 -0
- package/dist/components/stream-status/stream-status.styles.js +103 -0
- package/dist/components/streaming-text/streaming-text.d.ts +98 -0
- package/dist/components/streaming-text/streaming-text.js +209 -0
- package/dist/components/streaming-text/streaming-text.styles.d.ts +1 -0
- package/dist/components/streaming-text/streaming-text.styles.js +62 -0
- package/dist/components/switch/switch.d.ts +58 -0
- package/dist/components/switch/switch.js +179 -0
- package/dist/components/switch/switch.styles.d.ts +1 -0
- package/dist/components/switch/switch.styles.js +75 -0
- package/dist/components/table/table.d.ts +73 -4
- package/dist/components/table/table.js +169 -20
- package/dist/components/table/table.styles.js +6 -1
- package/dist/components/tabs/tabs.d.ts +51 -0
- package/dist/components/tabs/tabs.js +190 -0
- package/dist/components/tabs/tabs.styles.d.ts +1 -0
- package/dist/components/tabs/tabs.styles.js +63 -0
- package/dist/components/thinking-panel/thinking-panel.d.ts +121 -0
- package/dist/components/thinking-panel/thinking-panel.js +235 -0
- package/dist/components/thinking-panel/thinking-panel.styles.d.ts +1 -0
- package/dist/components/thinking-panel/thinking-panel.styles.js +117 -0
- package/dist/components/toast/toast-item.d.ts +1 -0
- package/dist/components/toast/toast-item.js +31 -6
- package/dist/components/tool-approval-dialog/tool-approval-dialog.d.ts +130 -0
- package/dist/components/tool-approval-dialog/tool-approval-dialog.js +403 -0
- package/dist/components/tool-approval-dialog/tool-approval-dialog.styles.d.ts +1 -0
- package/dist/components/tool-approval-dialog/tool-approval-dialog.styles.js +160 -0
- package/dist/components/tool-call-chip/tool-call-chip.d.ts +89 -0
- package/dist/components/tool-call-chip/tool-call-chip.js +288 -0
- package/dist/components/tool-call-chip/tool-call-chip.styles.d.ts +1 -0
- package/dist/components/tool-call-chip/tool-call-chip.styles.js +203 -0
- package/dist/components/tool-param-form/tool-param-form.d.ts +145 -0
- package/dist/components/tool-param-form/tool-param-form.js +366 -0
- package/dist/components/tool-param-form/tool-param-form.styles.d.ts +1 -0
- package/dist/components/tool-param-form/tool-param-form.styles.js +75 -0
- package/dist/components/tool-result-dialog/tool-result-dialog.d.ts +102 -0
- package/dist/components/tool-result-dialog/tool-result-dialog.js +393 -0
- package/dist/components/tool-result-dialog/tool-result-dialog.styles.d.ts +1 -0
- package/dist/components/tool-result-dialog/tool-result-dialog.styles.js +176 -0
- package/dist/components/tool-result-view/registry.d.ts +81 -0
- package/dist/components/tool-result-view/registry.js +84 -0
- package/dist/components/tool-result-view/tool-result-view.d.ts +55 -0
- package/dist/components/tool-result-view/tool-result-view.js +138 -0
- package/dist/components/tool-result-view/tool-result-view.styles.d.ts +1 -0
- package/dist/components/tool-result-view/tool-result-view.styles.js +13 -0
- package/dist/components/tool-select-dialog/tool-select-dialog.d.ts +151 -0
- package/dist/components/tool-select-dialog/tool-select-dialog.js +439 -0
- package/dist/components/tool-select-dialog/tool-select-dialog.styles.d.ts +1 -0
- package/dist/components/tool-select-dialog/tool-select-dialog.styles.js +182 -0
- package/dist/components/tree/tree-node.d.ts +11 -2
- package/dist/components/tree/tree-node.js +16 -6
- package/dist/components/tree/tree.d.ts +8 -2
- package/dist/components/tree/tree.js +18 -11
- package/dist/components/typing-indicator/typing-indicator.d.ts +60 -0
- package/dist/components/typing-indicator/typing-indicator.js +96 -0
- package/dist/components/typing-indicator/typing-indicator.styles.d.ts +1 -0
- package/dist/components/typing-indicator/typing-indicator.styles.js +132 -0
- package/dist/components/virtual-list/virtual-list.d.ts +173 -0
- package/dist/components/virtual-list/virtual-list.js +461 -0
- package/dist/components/virtual-list/virtual-list.styles.d.ts +1 -0
- package/dist/components/virtual-list/virtual-list.styles.js +44 -0
- package/dist/components/word-cloud/word-cloud-layout.js +14 -1
- package/dist/components/word-cloud/word-cloud.d.ts +6 -0
- package/dist/components/word-cloud/word-cloud.js +25 -14
- package/dist/components/word-cloud/word-cloud.styles.js +3 -2
- package/dist/internal/announcer.d.ts +57 -0
- package/dist/internal/announcer.js +71 -0
- package/dist/internal/form-associated.d.ts +1 -0
- package/dist/internal/form-associated.js +55 -11
- package/dist/internal/group-by-recency.d.ts +50 -0
- package/dist/internal/group-by-recency.js +80 -0
- package/dist/internal/rtl.d.ts +23 -0
- package/dist/internal/rtl.js +28 -0
- package/dist/internal/scroll-lock.d.ts +10 -5
- package/dist/internal/scroll-lock.js +30 -14
- package/dist/internal/tokens.styles.js +6 -0
- package/dist/lyra.d.ts +130 -31
- package/dist/lyra.js +94 -26
- package/llms-full.txt +3836 -17
- package/llms.txt +16 -1
- package/package.json +23 -5
- package/dist/components/chart/bar-chart.stories.d.ts +0 -5
- package/dist/components/chart/bar-chart.stories.js +0 -20
- package/dist/components/chart/box-plot.stories.d.ts +0 -5
- package/dist/components/chart/box-plot.stories.js +0 -29
- package/dist/components/chart/bubble-chart.stories.d.ts +0 -5
- package/dist/components/chart/bubble-chart.stories.js +0 -26
- package/dist/components/chart/chart.stories.d.ts +0 -32
- package/dist/components/chart/chart.stories.js +0 -141
- package/dist/components/chart/doughnut-chart.stories.d.ts +0 -5
- package/dist/components/chart/doughnut-chart.stories.js +0 -26
- package/dist/components/chart/histogram.stories.d.ts +0 -5
- package/dist/components/chart/histogram.stories.js +0 -17
- package/dist/components/chart/line-chart.stories.d.ts +0 -22
- package/dist/components/chart/line-chart.stories.js +0 -99
- package/dist/components/chart/lite-chart.stories.d.ts +0 -14
- package/dist/components/chart/lite-chart.stories.js +0 -114
- package/dist/components/chart/pie-chart.stories.d.ts +0 -5
- package/dist/components/chart/pie-chart.stories.js +0 -26
- package/dist/components/chart/polar-area-chart.stories.d.ts +0 -5
- package/dist/components/chart/polar-area-chart.stories.js +0 -20
- package/dist/components/chart/radar-chart.stories.d.ts +0 -5
- package/dist/components/chart/radar-chart.stories.js +0 -20
- package/dist/components/chart/scatter-chart.stories.d.ts +0 -5
- package/dist/components/chart/scatter-chart.stories.js +0 -31
- package/dist/components/combobox/combobox.stories.d.ts +0 -24
- package/dist/components/combobox/combobox.stories.js +0 -102
- package/dist/components/date-picker/date-input.stories.d.ts +0 -10
- package/dist/components/date-picker/date-input.stories.js +0 -48
- package/dist/components/date-picker/date-picker.stories.d.ts +0 -10
- package/dist/components/date-picker/date-picker.stories.js +0 -25
- package/dist/components/empty/empty.stories.d.ts +0 -7
- package/dist/components/empty/empty.stories.js +0 -34
- package/dist/components/export-button/export-button.stories.d.ts +0 -7
- package/dist/components/export-button/export-button.stories.js +0 -37
- package/dist/components/file-input/file-input.stories.d.ts +0 -7
- package/dist/components/file-input/file-input.stories.js +0 -19
- package/dist/components/flag/flag.stories.d.ts +0 -6
- package/dist/components/flag/flag.stories.js +0 -31
- package/dist/components/gauge/gauge.stories.d.ts +0 -8
- package/dist/components/gauge/gauge.stories.js +0 -19
- package/dist/components/graph/graph.stories.d.ts +0 -8
- package/dist/components/graph/graph.stories.js +0 -68
- package/dist/components/heatmap/heatmap.stories.d.ts +0 -27
- package/dist/components/heatmap/heatmap.stories.js +0 -179
- package/dist/components/map/map.stories.d.ts +0 -15
- package/dist/components/map/map.stories.js +0 -135
- package/dist/components/playback/playback.stories.d.ts +0 -7
- package/dist/components/playback/playback.stories.js +0 -16
- package/dist/components/select/select.stories.d.ts +0 -21
- package/dist/components/select/select.stories.js +0 -91
- package/dist/components/skeleton/skeleton.stories.d.ts +0 -5
- package/dist/components/skeleton/skeleton.stories.js +0 -16
- package/dist/components/sparkline/sparkline.stories.d.ts +0 -11
- package/dist/components/sparkline/sparkline.stories.js +0 -39
- package/dist/components/split/split.stories.d.ts +0 -7
- package/dist/components/split/split.stories.js +0 -36
- package/dist/components/stat/stat.stories.d.ts +0 -9
- package/dist/components/stat/stat.stories.js +0 -81
- package/dist/components/table/table.stories.d.ts +0 -12
- package/dist/components/table/table.stories.js +0 -67
- package/dist/components/time-range/time-range.stories.d.ts +0 -8
- package/dist/components/time-range/time-range.stories.js +0 -26
- package/dist/components/toast/toast.stories.d.ts +0 -8
- package/dist/components/toast/toast.stories.js +0 -72
- package/dist/components/tree/tree.stories.d.ts +0 -9
- package/dist/components/tree/tree.stories.js +0 -52
- package/dist/components/widget/widget.stories.d.ts +0 -9
- package/dist/components/widget/widget.stories.js +0 -74
- package/dist/components/word-cloud/word-cloud.stories.d.ts +0 -10
- package/dist/components/word-cloud/word-cloud.stories.js +0 -55
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { type TemplateResult, type PropertyValues } from 'lit';
|
|
2
|
+
import { LyraElement } from '../../internal/lyra-element.js';
|
|
3
|
+
import '../json-viewer/json-viewer.js';
|
|
4
|
+
/**
|
|
5
|
+
* Reason the dialog was dismissed, forwarded as the `lyra-close` event detail
|
|
6
|
+
* -- mirrors `<lyra-dialog>`'s own `DialogCloseReason` shape. `'escape'`/
|
|
7
|
+
* `'backdrop'` come from the dialog's own built-in dismiss triggers,
|
|
8
|
+
* `'approve'`/`'deny'` from the built-in action buttons (fired in addition
|
|
9
|
+
* to, and immediately after, their own dedicated `lyra-approve`/`lyra-deny`
|
|
10
|
+
* event -- see the class doc), and any other string is whatever a caller
|
|
11
|
+
* passes to `close()` directly.
|
|
12
|
+
*/
|
|
13
|
+
export type ToolApprovalDialogCloseReason = 'escape' | 'backdrop' | 'approve' | 'deny' | 'api' | string;
|
|
14
|
+
/**
|
|
15
|
+
* `<lyra-tool-approval-dialog>` — a human-in-the-loop gate: presents one
|
|
16
|
+
* proposed tool/function call (`toolName` + `args`) and blocks an agent from
|
|
17
|
+
* executing it until a person explicitly approves or denies it, with an
|
|
18
|
+
* optional inline "edit the arguments before approving" step.
|
|
19
|
+
*
|
|
20
|
+
* This is its own standalone overlay implementation (`role="dialog"`,
|
|
21
|
+
* focus-trapped, Escape/backdrop-dismissible, scroll-locking) rather than
|
|
22
|
+
* nesting a `<lyra-dialog>` in its shadow template — see `<lyra-dialog>`'s
|
|
23
|
+
* own header comment for why a new overlay component in this library
|
|
24
|
+
* duplicates that pattern locally instead of composing the previous one.
|
|
25
|
+
*
|
|
26
|
+
* Approve/Deny/Edit are built-in chrome (not a `footer` slot a consumer must
|
|
27
|
+
* assemble) — this component's interaction shape is fixed enough (there is
|
|
28
|
+
* exactly one correct set of actions for "approve this call") that requiring
|
|
29
|
+
* every consumer to re-build it would just be boilerplate. A `footer` slot is
|
|
30
|
+
* still offered for *supplementary* content a consumer wants alongside those
|
|
31
|
+
* buttons (e.g. a "remember this choice for this tool" checkbox) — its
|
|
32
|
+
* content renders to the start of the action row, before Deny/Edit/Approve.
|
|
33
|
+
*
|
|
34
|
+
* Editing: while `editable`, an Edit button swaps the read-only
|
|
35
|
+
* `<lyra-json-viewer>` for a plain `<textarea>` pre-filled with
|
|
36
|
+
* `JSON.stringify(args, null, 2)`. Every keystroke is re-validated with
|
|
37
|
+
* `JSON.parse` — the Approve button is `disabled` for as long as the current
|
|
38
|
+
* textarea content fails to parse, so a malformed edit can never be silently
|
|
39
|
+
* approved as either the broken text or a stale copy of the original args.
|
|
40
|
+
* The same button relabels to "Cancel" while editing; clicking it discards
|
|
41
|
+
* the draft entirely and returns to the read-only view of the *original*
|
|
42
|
+
* `args` — there is no separate "save" step independent of Approve itself.
|
|
43
|
+
* Both `editing` and any in-progress draft reset back to the read-only view
|
|
44
|
+
* every time the dialog transitions from closed to open, so a reused
|
|
45
|
+
* instance never leaks one proposal's half-finished edit into the next.
|
|
46
|
+
*
|
|
47
|
+
* Initial focus deliberately does *not* land on Approve (see `updated()`):
|
|
48
|
+
* approving a tool call is a consequential, potentially irreversible action,
|
|
49
|
+
* so a user who opens this dialog and reflexively presses Enter/Space before
|
|
50
|
+
* reading anything should deny, not approve. Deny gets the initial focus
|
|
51
|
+
* instead — the same "focus the safe action" convention a native destructive-
|
|
52
|
+
* confirmation dialog (delete, discard, etc.) typically follows for its own
|
|
53
|
+
* Cancel button — rather than the inert dialog panel, which would need an
|
|
54
|
+
* extra Tab press before *any* action is reachable at all.
|
|
55
|
+
*
|
|
56
|
+
* @customElement lyra-tool-approval-dialog
|
|
57
|
+
* @slot footer - Optional supplementary content (e.g. a "remember this
|
|
58
|
+
* choice" checkbox), rendered before the built-in Deny/Edit/Approve buttons.
|
|
59
|
+
* @event lyra-approve - The call was approved. `detail: { args }` — the
|
|
60
|
+
* current, already-parsed arguments object: the original `args` prop, or (if
|
|
61
|
+
* an edit was in progress) the user's edited-and-validated version. Always
|
|
62
|
+
* followed by `lyra-close` with reason `'approve'`.
|
|
63
|
+
* @event lyra-deny - The call was denied (no detail). Always followed by
|
|
64
|
+
* `lyra-close` with reason `'deny'`.
|
|
65
|
+
* @event lyra-close - `detail: ToolApprovalDialogCloseReason`. Fired exactly
|
|
66
|
+
* once per dismissal — via Escape, a backdrop click, the Approve/Deny
|
|
67
|
+
* buttons, or a `close()` call — so there is one consistent "this dialog is
|
|
68
|
+
* now closed" signal regardless of which path triggered it.
|
|
69
|
+
* @csspart backdrop - The full-viewport scrim behind the panel.
|
|
70
|
+
* @csspart panel - The dialog panel itself (`role="dialog"` while open).
|
|
71
|
+
* @csspart header - The wrapper around the heading.
|
|
72
|
+
* @csspart tool-name - The `toolName` text within the heading.
|
|
73
|
+
* @csspart body - The wrapper around the args view/editor.
|
|
74
|
+
* @csspart args-view - The read-only `<lyra-json-viewer>` shown while not editing.
|
|
75
|
+
* @csspart args-editor - The raw-JSON `<textarea>` shown while editing.
|
|
76
|
+
* @csspart error - The inline "invalid JSON" message, shown only while editing with unparseable content.
|
|
77
|
+
* @csspart footer - The action row wrapping the `footer` slot and the built-in buttons.
|
|
78
|
+
* @csspart deny-button - The built-in Deny button.
|
|
79
|
+
* @csspart edit-button - The built-in Edit/Cancel toggle button (only rendered while `editable`).
|
|
80
|
+
* @csspart approve-button - The built-in Approve button — `disabled` while an in-progress edit is invalid JSON.
|
|
81
|
+
*/
|
|
82
|
+
export declare class LyraToolApprovalDialog extends LyraElement {
|
|
83
|
+
static styles: import("lit").CSSResultGroup[];
|
|
84
|
+
/** Whether the dialog is open. Set this (or call `close()`) — there is no separate `show()`/`hide()` pair. */
|
|
85
|
+
open: boolean;
|
|
86
|
+
/** The proposed tool/function's name, e.g. `web_search`. Drives the heading and the dialog's accessible name. */
|
|
87
|
+
toolName: string;
|
|
88
|
+
/** The proposed call's arguments — any JSON-serializable value, rendered via `<lyra-json-viewer>` (or, while editing, stringified into the textarea). */
|
|
89
|
+
args: unknown;
|
|
90
|
+
/** Whether an "Edit" affordance is offered at all. When `false`, `args` is always shown read-only and can never be changed before approval. */
|
|
91
|
+
editable: boolean;
|
|
92
|
+
private editing;
|
|
93
|
+
/** The textarea's current raw text while editing — deliberately independent of `args` until Approve is pressed, so a malformed in-progress edit never overwrites it. */
|
|
94
|
+
private draftText;
|
|
95
|
+
/** `JSON.parse` failure message for `draftText`, or `''` while it parses cleanly. Empty string (not `undefined`) so it can drive `?hidden` directly. */
|
|
96
|
+
private draftError;
|
|
97
|
+
private releaseScrollLock?;
|
|
98
|
+
private lastTrigger?;
|
|
99
|
+
private readonly titleId;
|
|
100
|
+
private readonly errorId;
|
|
101
|
+
protected willUpdate(changed: PropertyValues): void;
|
|
102
|
+
protected updated(changed: PropertyValues): void;
|
|
103
|
+
connectedCallback(): void;
|
|
104
|
+
disconnectedCallback(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Close the dialog and return focus to whatever had it before the dialog
|
|
107
|
+
* opened. `reason` is forwarded as the `lyra-close` detail — built-in
|
|
108
|
+
* triggers pass `'escape'`/`'backdrop'`/`'approve'`/`'deny'`; a consumer's
|
|
109
|
+
* own close affordance (e.g. a footer-slotted button) should call this
|
|
110
|
+
* directly with its own reason string, so every dismissal path funnels
|
|
111
|
+
* through the same event instead of the consumer having to also toggle
|
|
112
|
+
* `open` itself.
|
|
113
|
+
*/
|
|
114
|
+
close(reason?: ToolApprovalDialogCloseReason): void;
|
|
115
|
+
private onBackdropClick;
|
|
116
|
+
private onDocKeyDown;
|
|
117
|
+
private getFocusableElements;
|
|
118
|
+
private getActiveElement;
|
|
119
|
+
private stringifyArgs;
|
|
120
|
+
private toggleEdit;
|
|
121
|
+
private onDraftInput;
|
|
122
|
+
private onApprove;
|
|
123
|
+
private onDeny;
|
|
124
|
+
render(): TemplateResult;
|
|
125
|
+
}
|
|
126
|
+
declare global {
|
|
127
|
+
interface HTMLElementTagNameMap {
|
|
128
|
+
'lyra-tool-approval-dialog': LyraToolApprovalDialog;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html, nothing } from 'lit';
|
|
8
|
+
import { property, state } from 'lit/decorators.js';
|
|
9
|
+
import { LyraElement } from '../../internal/lyra-element.js';
|
|
10
|
+
import { defineElement } from '../../internal/prefix.js';
|
|
11
|
+
import { lockScroll } from '../../internal/scroll-lock.js';
|
|
12
|
+
import { nextId } from '../../internal/a11y.js';
|
|
13
|
+
import { styles } from './tool-approval-dialog.styles.js';
|
|
14
|
+
import '../json-viewer/json-viewer.js';
|
|
15
|
+
const FOCUSABLE_SELECTOR = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
16
|
+
// Shadow-piercing so a slotted custom element's real focusable target, and
|
|
17
|
+
// this component's own directly-rendered <lyra-json-viewer>'s internal
|
|
18
|
+
// toggle/copy buttons, are found even though neither the slotted host tag
|
|
19
|
+
// nor <lyra-json-viewer> itself matches FOCUSABLE_SELECTOR. Deliberately
|
|
20
|
+
// duplicated from lyra-dialog's/lyra-tool-select-dialog's identical helper
|
|
21
|
+
// rather than imported/shared -- this component is its own standalone
|
|
22
|
+
// overlay and must not depend on either (see this file's class doc).
|
|
23
|
+
function collectFocusable(el) {
|
|
24
|
+
const result = [];
|
|
25
|
+
if (el.matches(FOCUSABLE_SELECTOR)) {
|
|
26
|
+
result.push(el);
|
|
27
|
+
}
|
|
28
|
+
if (el instanceof HTMLSlotElement) {
|
|
29
|
+
for (const assigned of el.assignedElements({ flatten: true })) {
|
|
30
|
+
result.push(...collectFocusable(assigned));
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
const container = el.shadowRoot ?? el;
|
|
35
|
+
for (const child of Array.from(container.children)) {
|
|
36
|
+
result.push(...collectFocusable(child));
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
/** Whether `el` is actually laid out/paintable -- `checkVisibility()` (falling
|
|
41
|
+
* back to `getClientRects().length` where unsupported) correctly follows
|
|
42
|
+
* flattened-tree/slot assignment, unlike `offsetParent`. Mirrors
|
|
43
|
+
* lyra-dialog's/lyra-tool-select-dialog's identical helper. */
|
|
44
|
+
function isRendered(el) {
|
|
45
|
+
return el.checkVisibility ? el.checkVisibility() : el.getClientRects().length > 0;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* `<lyra-tool-approval-dialog>` — a human-in-the-loop gate: presents one
|
|
49
|
+
* proposed tool/function call (`toolName` + `args`) and blocks an agent from
|
|
50
|
+
* executing it until a person explicitly approves or denies it, with an
|
|
51
|
+
* optional inline "edit the arguments before approving" step.
|
|
52
|
+
*
|
|
53
|
+
* This is its own standalone overlay implementation (`role="dialog"`,
|
|
54
|
+
* focus-trapped, Escape/backdrop-dismissible, scroll-locking) rather than
|
|
55
|
+
* nesting a `<lyra-dialog>` in its shadow template — see `<lyra-dialog>`'s
|
|
56
|
+
* own header comment for why a new overlay component in this library
|
|
57
|
+
* duplicates that pattern locally instead of composing the previous one.
|
|
58
|
+
*
|
|
59
|
+
* Approve/Deny/Edit are built-in chrome (not a `footer` slot a consumer must
|
|
60
|
+
* assemble) — this component's interaction shape is fixed enough (there is
|
|
61
|
+
* exactly one correct set of actions for "approve this call") that requiring
|
|
62
|
+
* every consumer to re-build it would just be boilerplate. A `footer` slot is
|
|
63
|
+
* still offered for *supplementary* content a consumer wants alongside those
|
|
64
|
+
* buttons (e.g. a "remember this choice for this tool" checkbox) — its
|
|
65
|
+
* content renders to the start of the action row, before Deny/Edit/Approve.
|
|
66
|
+
*
|
|
67
|
+
* Editing: while `editable`, an Edit button swaps the read-only
|
|
68
|
+
* `<lyra-json-viewer>` for a plain `<textarea>` pre-filled with
|
|
69
|
+
* `JSON.stringify(args, null, 2)`. Every keystroke is re-validated with
|
|
70
|
+
* `JSON.parse` — the Approve button is `disabled` for as long as the current
|
|
71
|
+
* textarea content fails to parse, so a malformed edit can never be silently
|
|
72
|
+
* approved as either the broken text or a stale copy of the original args.
|
|
73
|
+
* The same button relabels to "Cancel" while editing; clicking it discards
|
|
74
|
+
* the draft entirely and returns to the read-only view of the *original*
|
|
75
|
+
* `args` — there is no separate "save" step independent of Approve itself.
|
|
76
|
+
* Both `editing` and any in-progress draft reset back to the read-only view
|
|
77
|
+
* every time the dialog transitions from closed to open, so a reused
|
|
78
|
+
* instance never leaks one proposal's half-finished edit into the next.
|
|
79
|
+
*
|
|
80
|
+
* Initial focus deliberately does *not* land on Approve (see `updated()`):
|
|
81
|
+
* approving a tool call is a consequential, potentially irreversible action,
|
|
82
|
+
* so a user who opens this dialog and reflexively presses Enter/Space before
|
|
83
|
+
* reading anything should deny, not approve. Deny gets the initial focus
|
|
84
|
+
* instead — the same "focus the safe action" convention a native destructive-
|
|
85
|
+
* confirmation dialog (delete, discard, etc.) typically follows for its own
|
|
86
|
+
* Cancel button — rather than the inert dialog panel, which would need an
|
|
87
|
+
* extra Tab press before *any* action is reachable at all.
|
|
88
|
+
*
|
|
89
|
+
* @customElement lyra-tool-approval-dialog
|
|
90
|
+
* @slot footer - Optional supplementary content (e.g. a "remember this
|
|
91
|
+
* choice" checkbox), rendered before the built-in Deny/Edit/Approve buttons.
|
|
92
|
+
* @event lyra-approve - The call was approved. `detail: { args }` — the
|
|
93
|
+
* current, already-parsed arguments object: the original `args` prop, or (if
|
|
94
|
+
* an edit was in progress) the user's edited-and-validated version. Always
|
|
95
|
+
* followed by `lyra-close` with reason `'approve'`.
|
|
96
|
+
* @event lyra-deny - The call was denied (no detail). Always followed by
|
|
97
|
+
* `lyra-close` with reason `'deny'`.
|
|
98
|
+
* @event lyra-close - `detail: ToolApprovalDialogCloseReason`. Fired exactly
|
|
99
|
+
* once per dismissal — via Escape, a backdrop click, the Approve/Deny
|
|
100
|
+
* buttons, or a `close()` call — so there is one consistent "this dialog is
|
|
101
|
+
* now closed" signal regardless of which path triggered it.
|
|
102
|
+
* @csspart backdrop - The full-viewport scrim behind the panel.
|
|
103
|
+
* @csspart panel - The dialog panel itself (`role="dialog"` while open).
|
|
104
|
+
* @csspart header - The wrapper around the heading.
|
|
105
|
+
* @csspart tool-name - The `toolName` text within the heading.
|
|
106
|
+
* @csspart body - The wrapper around the args view/editor.
|
|
107
|
+
* @csspart args-view - The read-only `<lyra-json-viewer>` shown while not editing.
|
|
108
|
+
* @csspart args-editor - The raw-JSON `<textarea>` shown while editing.
|
|
109
|
+
* @csspart error - The inline "invalid JSON" message, shown only while editing with unparseable content.
|
|
110
|
+
* @csspart footer - The action row wrapping the `footer` slot and the built-in buttons.
|
|
111
|
+
* @csspart deny-button - The built-in Deny button.
|
|
112
|
+
* @csspart edit-button - The built-in Edit/Cancel toggle button (only rendered while `editable`).
|
|
113
|
+
* @csspart approve-button - The built-in Approve button — `disabled` while an in-progress edit is invalid JSON.
|
|
114
|
+
*/
|
|
115
|
+
export class LyraToolApprovalDialog extends LyraElement {
|
|
116
|
+
constructor() {
|
|
117
|
+
super(...arguments);
|
|
118
|
+
/** Whether the dialog is open. Set this (or call `close()`) — there is no separate `show()`/`hide()` pair. */
|
|
119
|
+
this.open = false;
|
|
120
|
+
/** The proposed tool/function's name, e.g. `web_search`. Drives the heading and the dialog's accessible name. */
|
|
121
|
+
this.toolName = '';
|
|
122
|
+
/** The proposed call's arguments — any JSON-serializable value, rendered via `<lyra-json-viewer>` (or, while editing, stringified into the textarea). */
|
|
123
|
+
this.args = {};
|
|
124
|
+
/** Whether an "Edit" affordance is offered at all. When `false`, `args` is always shown read-only and can never be changed before approval. */
|
|
125
|
+
this.editable = true;
|
|
126
|
+
this.editing = false;
|
|
127
|
+
/** The textarea's current raw text while editing — deliberately independent of `args` until Approve is pressed, so a malformed in-progress edit never overwrites it. */
|
|
128
|
+
this.draftText = '';
|
|
129
|
+
/** `JSON.parse` failure message for `draftText`, or `''` while it parses cleanly. Empty string (not `undefined`) so it can drive `?hidden` directly. */
|
|
130
|
+
this.draftError = '';
|
|
131
|
+
this.titleId = nextId('tool-approval-dialog-title');
|
|
132
|
+
this.errorId = nextId('tool-approval-dialog-error');
|
|
133
|
+
this.onBackdropClick = () => {
|
|
134
|
+
this.close('backdrop');
|
|
135
|
+
};
|
|
136
|
+
this.onDocKeyDown = (e) => {
|
|
137
|
+
if (!this.open)
|
|
138
|
+
return;
|
|
139
|
+
if (e.key === 'Escape') {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
this.close('escape');
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (e.key !== 'Tab')
|
|
145
|
+
return;
|
|
146
|
+
const focusable = this.getFocusableElements();
|
|
147
|
+
if (focusable.length === 0) {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const first = focusable[0];
|
|
152
|
+
const last = focusable[focusable.length - 1];
|
|
153
|
+
const active = this.getActiveElement();
|
|
154
|
+
if (e.shiftKey && active === first) {
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
last.focus();
|
|
157
|
+
}
|
|
158
|
+
else if (!e.shiftKey && active === last) {
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
first.focus();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
this.toggleEdit = () => {
|
|
164
|
+
if (this.editing) {
|
|
165
|
+
this.editing = false;
|
|
166
|
+
this.draftText = '';
|
|
167
|
+
this.draftError = '';
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
this.editing = true;
|
|
171
|
+
this.draftText = this.stringifyArgs();
|
|
172
|
+
this.draftError = '';
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
this.onDraftInput = (e) => {
|
|
176
|
+
const value = e.target.value;
|
|
177
|
+
this.draftText = value;
|
|
178
|
+
try {
|
|
179
|
+
JSON.parse(value);
|
|
180
|
+
this.draftError = '';
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
this.draftError = err instanceof Error ? err.message : 'Invalid JSON.';
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
this.onApprove = () => {
|
|
187
|
+
let currentArgs = this.args;
|
|
188
|
+
if (this.editing) {
|
|
189
|
+
// The Approve button is disabled whenever draftError is non-empty, so
|
|
190
|
+
// this should always succeed -- the try/catch is defense-in-depth
|
|
191
|
+
// against a state desync rather than an expected path.
|
|
192
|
+
try {
|
|
193
|
+
currentArgs = JSON.parse(this.draftText);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
this.emit('lyra-approve', { args: currentArgs });
|
|
200
|
+
this.close('approve');
|
|
201
|
+
};
|
|
202
|
+
this.onDeny = () => {
|
|
203
|
+
this.emit('lyra-deny');
|
|
204
|
+
this.close('deny');
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
static { this.styles = [LyraElement.styles, styles]; }
|
|
208
|
+
willUpdate(changed) {
|
|
209
|
+
if (changed.has('open')) {
|
|
210
|
+
if (this.open) {
|
|
211
|
+
// Captured here (before render) rather than from a click event on
|
|
212
|
+
// some specific internal control -- like lyra-dialog, a trigger
|
|
213
|
+
// typically lives *outside* this component entirely, so "whatever
|
|
214
|
+
// had focus right before open" is the only generally correct
|
|
215
|
+
// definition of "the trigger".
|
|
216
|
+
const active = this.getActiveElement();
|
|
217
|
+
this.lastTrigger = active instanceof HTMLElement ? active : undefined;
|
|
218
|
+
this.releaseScrollLock = lockScroll();
|
|
219
|
+
document.addEventListener('keydown', this.onDocKeyDown);
|
|
220
|
+
// Every open starts fresh in the read-only view -- a reused instance
|
|
221
|
+
// must never carry a half-finished edit (or its error state) over
|
|
222
|
+
// from whatever the previous proposal was.
|
|
223
|
+
this.editing = false;
|
|
224
|
+
this.draftText = '';
|
|
225
|
+
this.draftError = '';
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
this.releaseScrollLock?.();
|
|
229
|
+
this.releaseScrollLock = undefined;
|
|
230
|
+
document.removeEventListener('keydown', this.onDocKeyDown);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// A consumer flipping editable off mid-edit (e.g. a policy change
|
|
234
|
+
// pushed while this dialog happens to be open) must not leave an
|
|
235
|
+
// unreachable edit UI on screen with no Edit/Cancel button left to
|
|
236
|
+
// dismiss it.
|
|
237
|
+
if (changed.has('editable') && !this.editable && this.editing) {
|
|
238
|
+
this.editing = false;
|
|
239
|
+
this.draftText = '';
|
|
240
|
+
this.draftError = '';
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// Runs after render (not willUpdate) so [part="panel"]/[part="deny-button"]
|
|
244
|
+
// have already landed in the DOM before the focus calls below can rely on
|
|
245
|
+
// them -- mirrors lyra-dialog's identical ordering rationale.
|
|
246
|
+
updated(changed) {
|
|
247
|
+
if (changed.has('open') && this.open) {
|
|
248
|
+
// Deliberately the Deny button, not "the first focusable element" --
|
|
249
|
+
// see the class doc's focus-management paragraph.
|
|
250
|
+
const deny = this.shadowRoot?.querySelector('[part="deny-button"]');
|
|
251
|
+
if (deny) {
|
|
252
|
+
deny.focus();
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
this.shadowRoot?.querySelector('[part="panel"]')?.focus();
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (changed.has('editing') && this.editing) {
|
|
260
|
+
// Entering edit mode is a deliberate request to start typing --
|
|
261
|
+
// steering focus into the textarea beats leaving it on the Edit
|
|
262
|
+
// button the click already left it on.
|
|
263
|
+
this.shadowRoot?.querySelector('[part="args-editor"]')?.focus();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
connectedCallback() {
|
|
267
|
+
super.connectedCallback();
|
|
268
|
+
// A reconnect (e.g. a drag-and-drop reparent keeping this same element
|
|
269
|
+
// instance) fires disconnectedCallback then connectedCallback
|
|
270
|
+
// synchronously with no update in between, so willUpdate never reruns to
|
|
271
|
+
// notice `open` is still true -- restore the scroll lock/trap it dropped.
|
|
272
|
+
if (this.hasUpdated && this.open && !this.releaseScrollLock) {
|
|
273
|
+
this.releaseScrollLock = lockScroll();
|
|
274
|
+
document.addEventListener('keydown', this.onDocKeyDown);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
disconnectedCallback() {
|
|
278
|
+
super.disconnectedCallback();
|
|
279
|
+
this.releaseScrollLock?.();
|
|
280
|
+
this.releaseScrollLock = undefined;
|
|
281
|
+
document.removeEventListener('keydown', this.onDocKeyDown);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Close the dialog and return focus to whatever had it before the dialog
|
|
285
|
+
* opened. `reason` is forwarded as the `lyra-close` detail — built-in
|
|
286
|
+
* triggers pass `'escape'`/`'backdrop'`/`'approve'`/`'deny'`; a consumer's
|
|
287
|
+
* own close affordance (e.g. a footer-slotted button) should call this
|
|
288
|
+
* directly with its own reason string, so every dismissal path funnels
|
|
289
|
+
* through the same event instead of the consumer having to also toggle
|
|
290
|
+
* `open` itself.
|
|
291
|
+
*/
|
|
292
|
+
close(reason = 'api') {
|
|
293
|
+
if (!this.open)
|
|
294
|
+
return;
|
|
295
|
+
this.open = false;
|
|
296
|
+
this.emit('lyra-close', reason);
|
|
297
|
+
this.lastTrigger?.focus();
|
|
298
|
+
}
|
|
299
|
+
// Bounds Tab/Shift+Tab to the panel while open. Order follows the body
|
|
300
|
+
// (the json-viewer's own toggle/copy buttons, or the textarea, depending
|
|
301
|
+
// on `editing`), then the footer row (the footer slot, then Deny/Edit/
|
|
302
|
+
// Approve) -- the same order the flattened tree already tabs through.
|
|
303
|
+
// collectFocusable()'s own FOCUSABLE_SELECTOR check excludes the Approve
|
|
304
|
+
// button for free while it's `disabled`, so an invalid in-progress edit
|
|
305
|
+
// can't be Tab-trapped into.
|
|
306
|
+
getFocusableElements() {
|
|
307
|
+
const root = this.shadowRoot;
|
|
308
|
+
if (!root)
|
|
309
|
+
return [];
|
|
310
|
+
const body = root.querySelector('[part="body"]');
|
|
311
|
+
const footer = root.querySelector('[part="footer"]');
|
|
312
|
+
return [...(body ? collectFocusable(body) : []), ...(footer ? collectFocusable(footer) : [])].filter(isRendered);
|
|
313
|
+
}
|
|
314
|
+
getActiveElement() {
|
|
315
|
+
let active = document.activeElement;
|
|
316
|
+
while (active) {
|
|
317
|
+
const inner = active.shadowRoot?.activeElement ?? null;
|
|
318
|
+
if (!inner)
|
|
319
|
+
break;
|
|
320
|
+
active = inner;
|
|
321
|
+
}
|
|
322
|
+
return active;
|
|
323
|
+
}
|
|
324
|
+
stringifyArgs() {
|
|
325
|
+
try {
|
|
326
|
+
// JSON.stringify(undefined, ...) returns the *value* undefined, not a
|
|
327
|
+
// string -- the ?? covers that alongside the try/catch's circular-
|
|
328
|
+
// reference case, so the textarea always opens with real text.
|
|
329
|
+
return JSON.stringify(this.args, null, 2) ?? 'null';
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
return 'null';
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
render() {
|
|
336
|
+
const hasError = this.editing && this.draftError.length > 0;
|
|
337
|
+
return html `
|
|
338
|
+
<div part="backdrop" @click=${this.onBackdropClick}></div>
|
|
339
|
+
<div
|
|
340
|
+
part="panel"
|
|
341
|
+
role=${this.open ? 'dialog' : nothing}
|
|
342
|
+
aria-modal=${this.open ? 'true' : nothing}
|
|
343
|
+
aria-labelledby=${this.titleId}
|
|
344
|
+
tabindex="-1"
|
|
345
|
+
>
|
|
346
|
+
<div part="header">
|
|
347
|
+
<h2 id=${this.titleId}>Approve <span part="tool-name">${this.toolName || 'tool'}</span> call?</h2>
|
|
348
|
+
</div>
|
|
349
|
+
<div part="body">
|
|
350
|
+
${this.editing
|
|
351
|
+
? html `
|
|
352
|
+
<textarea
|
|
353
|
+
part="args-editor"
|
|
354
|
+
spellcheck="false"
|
|
355
|
+
autocomplete="off"
|
|
356
|
+
aria-label="Tool call arguments (JSON)"
|
|
357
|
+
aria-invalid=${hasError ? 'true' : 'false'}
|
|
358
|
+
aria-describedby=${hasError ? this.errorId : nothing}
|
|
359
|
+
.value=${this.draftText}
|
|
360
|
+
@input=${this.onDraftInput}
|
|
361
|
+
></textarea>
|
|
362
|
+
<p part="error" id=${this.errorId} role="alert" ?hidden=${!hasError}>${this.draftError}</p>
|
|
363
|
+
`
|
|
364
|
+
: html `<lyra-json-viewer part="args-view" .data=${this.args}></lyra-json-viewer>`}
|
|
365
|
+
</div>
|
|
366
|
+
<div part="footer">
|
|
367
|
+
<slot name="footer"></slot>
|
|
368
|
+
<button part="deny-button" type="button" @click=${this.onDeny}>Deny</button>
|
|
369
|
+
${this.editable
|
|
370
|
+
? html `<button part="edit-button" type="button" @click=${this.toggleEdit}>
|
|
371
|
+
${this.editing ? 'Cancel' : 'Edit'}
|
|
372
|
+
</button>`
|
|
373
|
+
: nothing}
|
|
374
|
+
<button part="approve-button" type="button" ?disabled=${hasError} @click=${this.onApprove}>
|
|
375
|
+
Approve
|
|
376
|
+
</button>
|
|
377
|
+
</div>
|
|
378
|
+
</div>
|
|
379
|
+
`;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
__decorate([
|
|
383
|
+
property({ type: Boolean, reflect: true })
|
|
384
|
+
], LyraToolApprovalDialog.prototype, "open", void 0);
|
|
385
|
+
__decorate([
|
|
386
|
+
property({ attribute: 'tool-name' })
|
|
387
|
+
], LyraToolApprovalDialog.prototype, "toolName", void 0);
|
|
388
|
+
__decorate([
|
|
389
|
+
property({ attribute: false })
|
|
390
|
+
], LyraToolApprovalDialog.prototype, "args", void 0);
|
|
391
|
+
__decorate([
|
|
392
|
+
property({ type: Boolean, reflect: true })
|
|
393
|
+
], LyraToolApprovalDialog.prototype, "editable", void 0);
|
|
394
|
+
__decorate([
|
|
395
|
+
state()
|
|
396
|
+
], LyraToolApprovalDialog.prototype, "editing", void 0);
|
|
397
|
+
__decorate([
|
|
398
|
+
state()
|
|
399
|
+
], LyraToolApprovalDialog.prototype, "draftText", void 0);
|
|
400
|
+
__decorate([
|
|
401
|
+
state()
|
|
402
|
+
], LyraToolApprovalDialog.prototype, "draftError", void 0);
|
|
403
|
+
defineElement('tool-approval-dialog', LyraToolApprovalDialog);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const styles: import("lit").CSSResult;
|