posit-dev / posit-dev/shinychat

Store both the UI and chat turns

Open
#61 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
139
Forks
28
Avg merge
23h 44m
Merged PRs (30d)
50

Description

Originally posted by @cpsievert in https://github.com/posit-dev/shinychat/pull/28#discussion_r2105423207

We should probably have a big ol' warning/disclaimer somewhere around here that this currently only works as intended when the UI content matches what is stored in the ellmer turns.

PS. I know we're considering localstorage as a potential long-term solution to this issue, which would be great.

Just throw it out there, something I just thought of is that if the append knew about the chat_client:

chat_append_message("id", chat_client$stream("foo"), chat_client)

Then, when the message ends, we could do something like:

turns <- chat$get_turns()
# When the stream gets exhausted, the last turn represents "this" assistant turn 
last_turn <- turns[[length(turns)]]
key <- rlang::hash(last_turn@contents)
session$userData[[key]] <- final_ui_content_string

Then, when restoring the bookmark, we could do a lookup from session$userData? There is a small risk of hash collisions doing it just based on contents, but we can probably workaround that? Anyway, just wanted to offer it as an idea to consider at this point and see what you think.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing chat_append_message, chat_client$stream, chat$get_turns(), and session$userData during message completion and bookmark restoration. The issue needs an agreed design for retaining both UI content and ellmer turns, with restored conversations remaining consistent even when their displayed content differs.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
full-stack
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.