Skip to content

feat(appkit): hooks for fetching chat history/messages#389

Open
hubertzub-db wants to merge 6 commits into
databricks:mainfrom
hubertzub-db:agent/v2/chatui/3-chat-history-hook
Open

feat(appkit): hooks for fetching chat history/messages#389
hubertzub-db wants to merge 6 commits into
databricks:mainfrom
hubertzub-db:agent/v2/chatui/3-chat-history-hook

Conversation

@hubertzub-db
Copy link
Copy Markdown

Summary

Adds three reusable hooks for working with chat history: useThreadList, useThread, and useThreadMessages. They let any app built on AppKit show a list of past conversations, load a specific one, and read its messages — without each app having to re-implement the fetching, loading states, and error handling on top of the /threads endpoints.

The dev playground gets a small showcase of the hooks: a thread history sidebar next to the chat. Past conversations appear there ordered by most recent activity, clicking one resumes it in the main panel with its full message history, the list refreshes automatically the moment a turn finishes, and a "+ New" button starts a fresh chat.

chathistory.mov

Try it

Open /agent in the dev playground. Send a message and watch the new thread appear in the left panel. Start a few more chats with "+ New", then click any of them to jump back in and keep chatting.

Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
@hubertzub-db hubertzub-db requested a review from a team as a code owner May 19, 2026 12:12
@hubertzub-db hubertzub-db requested a review from MarioCadenas May 19, 2026 12:12
- responses-api-transport: normalize CRLF to LF in the SSE line parser
  so the "\n\n" frame-boundary split works behind proxies that re-emit
  events with CRLF line endings. Adds a CRLF-stream unit test.

- use-scroll-to-bottom: switch from useRef + listener-attach-on-mount
  to a state-backed ref callback. The listener-attach effect now
  re-runs when the container DOM node changes, so consumers that
  conditionally render the scroll container (e.g. behind a loading
  gate) still get auto-stick. The public ref type changes from
  RefObject<T | null> to (node: T | null) => void; JSX
  `ref={containerRef}` keeps working because React accepts both
  shapes, and no consumer reads `.current` (verified across the repo).

Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Follow-up to the parent fix that switched `useScrollToBottom` from
`useRef` to a state-backed ref callback. `ChatMessages` previously
typed `containerRef` as `RefObject<HTMLDivElement | null>`, which no
longer matches the hook's return shape — the public type signature
needs to follow.

Behavior is unchanged at runtime since the prop is only ever forwarded
to a JSX `ref={...}`, which accepts both ref shapes.

Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
- useChat: ref the `onFinish` callback and pass a stable wrapper to
  `useAiChat`, matching the pattern already used for
  `onData`/`onStreamPart`/`headers`. Consumers can keep passing
  callbacks bound via `useCallback(..., [list, …])` without worrying
  whether the AI SDK rebinds the callback per render.

- agent.route: add a TODO comment on `seedMessages` documenting that
  hydration drops `tool`-role messages and only emits plain `text`
  parts — past tool invocations and approval cards therefore do not
  re-render when a thread is resumed. No behavior change here; the
  proper fix needs a shared Message → UIMessage converter that can be
  reused by `<ChatApp>` as well.

Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
@hubertzub-db hubertzub-db force-pushed the agent/v2/chatui/3-chat-history-hook branch from 63d1c8c to 749ee4b Compare May 21, 2026 11:25
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.

1 participant