Skip to content

Conversation

@AdityaHegde
Copy link
Collaborator

@AdityaHegde AdityaHegde commented Oct 3, 2025

Adds a quick way to get info about a particular timestamp.
Design: https://www.figma.com/design/JtG3sbaopjO0xQlyeCjmho/RILL-WIP?node-id=406-60840&t=MjQi7JW86b7DIXcN-0

Adds some very basic WIP context framework. This is subject to change based on the backend refactor PR.

Closes APP-439

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

@AdityaHegde AdityaHegde force-pushed the feat/measure-anomaly-explanation branch from b1d5a3d to 375deff Compare October 6, 2025 05:16
@AdityaHegde AdityaHegde force-pushed the feat/measure-anomaly-explanation branch from d04c949 to 804dc1d Compare October 9, 2025 07:51
@AdityaHegde AdityaHegde marked this pull request as ready for review October 9, 2025 07:52
Copy link
Contributor

@ericpgreen2 ericpgreen2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UXQA:

  1. It doesn't seem as if the "E" click handler has been registered. When I press "E" nothing happens.
  2. After injecting the prompt, we should focus the chat input element. Then it'll be easier for the user to simply press enter to submit the message.
  3. Let's say I focus one data point and see the "Explain" CTA. If I further interact with the chart, like highlighting a time range or panning to a new time range, then the focused data point should be cleared.
  4. The context pill for the below time range shows "Invalid interval"
    image
  5. I've discovered that the "Explain" text is clickable. There should be a hover effect to explicitly signal to the user that it's clickable.
  6. Because the context provided to the AI is provided per-message, we should have UI that shows that a message was sent with context. We can look at Cursor for inspiration.
    image
  7. Along the lines of 6, I think we should put the context pills within the chat input, not outside of it.
    image
  8. We should be able to clear context pills individually, not just as a group.
  9. The context pills have a hover effect, but nothing happens when I click on them.

Comment on lines +32 to +33
// Parse messages and fill in context
$: currentConversation.context.parseMessages(messages);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This UI component should simply be focused on rendering. If the Context class needs to operate on messages, then the class should fetch the messages from the TanStack Query cache directly. (Alternatively, there's a world where the Context class could get the messages from the Conversation class, but, since we're leaning into TanStack Query cache as the source-of-truth, I don't think we're really set-up for this approach.)

Copy link
Collaborator Author

@AdityaHegde AdityaHegde Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is we need a svelte derived store with unsubscribe. So we would have that called somewhere in a component.

Lets keep it simple for now, we can revisit once we have better contexts.

import Markdown from "../../../../components/markdown/Markdown.svelte";
import type { V1Message } from "../../../../runtime-client";

export let message: V1Message;
export let content: string;

$: cleanedContent = ConversationContext.cleanContext(content);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than adding data processing logic to this UI component, can we put this processing in the Conversation class logic in conversation.ts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is displaying a V1Message and has nothing to do with the Conversation class directly. So this makes sense to clean it here itself. In future, context might not be part of the prompt, so easy to clean up as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: rather than "presets", can we call this directory "prompts" or similar?

Comment on lines 255 to 260
if (
hoveredTime &&
measure.name &&
TIME_GRAIN[timeGrain] &&
!hasSubrangeSelected
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a complex conditional. What about an explanatory variable?

}
function onMouseClick() {
function onMouseClick(e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is quite hard to follow now. Mind trying to find a way to clean it up?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, here's what Claude Code flagged:
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm we need a greater scrub refactor to move interactions to a single class. We can use a state machine then. Added comments for now.

Comment on lines +83 to +85
setTimeout(() => {
autoResize();
}, 5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this timeout?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment explaining it.

import type { V1Message } from "@rilldata/web-common/runtime-client";
import { get, type Writable, writable } from "svelte/store";

const contextRegex = /\s*<context>([\s\S]*?)<\/context>/m;
Copy link
Contributor

@ericpgreen2 ericpgreen2 Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your PR comment. I agree– let's build on the backend PR's approach to context.

@AdityaHegde
Copy link
Collaborator Author

Thanks @ericpgreen2 . Have addressed all except 8. Removing certain context without others can get complex. Lets do that in the comprehensive context PR.

@ericpgreen2 ericpgreen2 requested a review from Di7design October 14, 2025 18:03
Copy link

@Di7design Di7design left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UXQA:

  1. The highlighted point or time range on the measures line chart should stay selected after asking AI — don’t auto-clear it. Right now from the screenshot below I don't know which point I'm asking for explanation after the question sent to AI.
Screenshot 2025-10-14 at 2 47 35 PM
  1. Make “Explain” Button Look Clickable, I use link button from the ShadCN component, so it should has a hover effect like the screenshot below.
Screenshot 2025-10-14 at 3 18 49 PM
  1. When drag a time range on the chart, it should be an Explain(E) button display under the selected time range, right now I have to drag a time range, and click on it again to see the Explain(E) button. Follow the interaction guide:
Screenshot 2025-10-14 at 2 57 21 PM
  1. Issue for future fix:
    When a point or especially a time range is selected, the visual isn't emphasized enough, reducing clarity about what’s being analyzed or referenced in the AI query. Might need a better visual highlight in the future.

@AdityaHegde AdityaHegde force-pushed the feat/measure-anomaly-explanation branch from d5b8c77 to 1259f14 Compare October 15, 2025 12:44
Copy link

@Di7design Di7design left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listed UXQA issues addressed.

y={plotBottom + 10 + bodyBuffer}
on:click={onExplain}
>
Explain(E)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: add a space– "Explain (E)"

y={plotBottom + 10 + bodyBuffer}
on:click={onExplain}
>
Explain(E)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, here too

@AdityaHegde
Copy link
Collaborator Author

Closing in favour of #8172

@AdityaHegde AdityaHegde deleted the feat/measure-anomaly-explanation branch October 28, 2025 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants