Commit 27bd83b
[Dashboards in Chat] Sidebar dashboard app integration - enable automatic dashboard attachments in new conversations (elastic#263987)
## Summary
This PR removes `onAttachmentMount` and replaces it with
conversation-level APIs that are a better fit for dashboard/chat
integration.
`onAttachmentMount` worked for persisted attachments that were already
rendered in a conversation, but it turned out to be too narrow for the
dashboard app use case. In particular, dashboard app sync also needs to
work for draft attachments. If a user opens a new dashboard with a new
conversation, the dashboard can be attached as a draft attachment before
it exists as a persisted conversation attachment. In that flow, manual
dashboard changes still need to update the attachment, but
`onAttachmentMount` never fires because there is nothing persisted yet
(attachment has not been mounted).
The old model also pushed dashboard integration toward per-attachment
subscriptions, while the actual behavior we need is conversation-level.
Dashboard sync needs awareness of the full set of conversation
attachments so it can decide which dashboard attachment should own sync,
rather than wiring each attachment independently. It also needs to
preserve some state across conversation switches, such as the current
draft attachment id so we don't create a new attachment every time we
switch to another conversation (because we cannot remove the old one).
To support that, this PR introduces `subscribeToConversationChanges`,
which exposes the active conversation id and attachments whenever the
bound conversation changes, and `chatOpen$`, which lets dashboard
integration activate only when chat is actually open. Together, these
APIs let dashboard integration subscribe once for the active
dashboard/chat session instead of once per mounted attachment.
## What Changed
- removed `onAttachmentMount` from the attachment UI contract
- added `subscribeToConversationChanges` to the `agent_builder` public
start contract
- added `chatOpen$` to the `agent_builder` public start contract
- added internal conversation change notifications for both
embedded/sidebar chat (we don't use full-page chat here, but I think we
will soon) and routed/full-page chat
- updated dashboard integration to activate only when both the dashboard
app and chat are running
- refactored dashboard integration to use conversation-level attachment
state instead of per-attachment mount lifecycle
- added draft attachment id management so draft dashboard attachments
keep a stable id until they are persisted
- extracted shared dashboard state defaults into helpers
- updated and expanded tests around plugin APIs, conversation change
notifications, and dashboard integration flows
## Dashboard Integration Improvements
This change makes dashboard/chat synchronization work for both draft and
persisted dashboard attachments.
It also allows dashboard integration to:
- add and update dashboard attachments for new conversations (!New
attachments can only be created for new conversations!)
- keep manual dashboard edits synced even before the attachment is
persisted
- preserve the current draft attachment id across conversation switches
(so we don't create a new attachment, since we have no ability to remove
the old one)
## Why This Is Better
A conversation-level subscription is a better abstraction for dashboard
integration than an attachment-mount lifecycle hook.
It gives integration code visibility into all attachments for the active
conversation, lets it maintain state across conversation changes, and
covers the important case where dashboard sync must begin before any
persisted attachment exists. It also keeps integration inactive unless
both chat and dashboard are actually present, which reduces unnecessary
subscriptions and avoids running sync logic outside the intended flow.
## Test Plan
- [ ] Open a new dashboard with a new conversation and verify manual
dashboard edits keep updating the draft dashboard attachment
- [ ] Switch between conversations and verify the current draft
attachment id is preserved until the draft is persisted
- [ ] Open a dashboard with an existing conversation and verify manual
dashboard edits keep updating the draft dashboard attachment. When
submitting, new attachment correctly is added to the conversation
- [ ] Complete a round that creates the draft attachment and verify
subsequent new drafts use a new id
- [ ] Save and save as from the dashboard app and verify attachment
origin is updated correctly
- [ ] Verify dashboard integration only becomes active when both the
dashboard app and chat are running
demo:
https://github.com/user-attachments/assets/3c8563db-ca3e-46a8-8f7d-6ff14b5a7c53
---------
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: macroscopeapp[bot] <170038800+macroscopeapp[bot]@users.noreply.github.com>1 parent b0bd61a commit 27bd83b
28 files changed
Lines changed: 1206 additions & 995 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
Lines changed: 0 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | 157 | | |
166 | 158 | | |
167 | 159 | | |
| |||
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
11 | 35 | | |
12 | 36 | | |
13 | 37 | | |
| |||
16 | 40 | | |
17 | 41 | | |
18 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
19 | 47 | | |
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
20 | 25 | | |
21 | 26 | | |
22 | 27 | | |
| |||
Lines changed: 113 additions & 40 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
775 | 775 | | |
776 | 776 | | |
777 | 777 | | |
778 | | - | |
| 778 | + | |
779 | 779 | | |
780 | | - | |
| 780 | + | |
781 | 781 | | |
782 | | - | |
| 782 | + | |
783 | 783 | | |
784 | | - | |
785 | | - | |
786 | | - | |
| 784 | + | |
787 | 785 | | |
788 | | - | |
| 786 | + | |
789 | 787 | | |
790 | | - | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
791 | 802 | | |
792 | 803 | | |
793 | | - | |
794 | | - | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | | - | |
800 | | - | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
801 | 807 | | |
802 | 808 | | |
803 | | - | |
| 809 | + | |
804 | 810 | | |
805 | | - | |
806 | | - | |
807 | | - | |
808 | | - | |
| 811 | + | |
809 | 812 | | |
810 | | - | |
811 | | - | |
812 | | - | |
813 | | - | |
814 | | - | |
815 | | - | |
816 | | - | |
817 | | - | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
818 | 824 | | |
819 | | - | |
820 | | - | |
821 | | - | |
822 | | - | |
823 | | - | |
| 825 | + | |
824 | 826 | | |
825 | | - | |
826 | | - | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
827 | 859 | | |
828 | 860 | | |
829 | | - | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
830 | 895 | | |
831 | | - | |
832 | | - | |
833 | | - | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
834 | 907 | | |
835 | 908 | | |
836 | 909 | | |
| |||
Lines changed: 0 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | 12 | | |
16 | 13 | | |
17 | 14 | | |
| |||
25 | 22 | | |
26 | 23 | | |
27 | 24 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | 25 | | |
38 | 26 | | |
39 | 27 | | |
| |||
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
229 | 230 | | |
230 | 231 | | |
231 | 232 | | |
| 233 | + | |
232 | 234 | | |
233 | 235 | | |
234 | 236 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
150 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
151 | 155 | | |
152 | 156 | | |
0 commit comments