Files
baserow/web-frontend/test/unit/core/components/chatCopyButton.spec.js
Davide Silvestri 4cbe4af199 feat(agent-builder): Agents reply to messages (#6466)
* feat(agent-builder): answer messages with background replies

Each message starts a core chat run that streams the configured model's reply and saves it with its turn: status, error code, model messages, usage, and the provider and model that answered. Messages record their author. One reply runs per conversation, and BASEROW_AGENT_MAX_ACTIVE_RUNS_PER_WORKSPACE caps a workspace (default 5). Copies keep turns and authors and end replies still running.

* feat(agent-builder): stream, stop and resume replies in the chat

The chat follows each reply through the core run stream, shows authors, lets the user stop a reply, resumes after a reload or in another tab, and explains replies that did not finish.

* refactor(agent): keep replies focused on chat

* refactor(agent): keep each reply's outcome on its message

A reply is an assistant message created empty with its prompt, and the run
writing it saves its text, status and error code there, replacing the turn
table. Send responses name the run they started, so a reply that ends before
the response is still followed. Retries read the run before the reply, listed
replies that still look unfinished are read again from the primary, and blank
replies are saved empty.

* feat(chat): add shared chat components

Store-free message, markdown, composer and copy button components styled
after the agent builder designs, so the Agent chat and later Kuma can share
one UI. Replies render markdown without images, which could carry
conversation data to any URL, and app links open in the router.

* feat(agent-builder): show replies with the shared chat components

Replies render in place from the conversation history under the agent's
name and avatar, with Thinking and Writing above the composer while they
run, a note when stopped and an error card when they fail. Stop stays
available while a reply runs, even when the configuration stops being
ready.

* feat(agent): hand finished replies to followers and announce reply runs

A finished run carries the saved reply as the messages list shows it, so
followers can apply it without reading the messages again. Conversations
expose the run writing a reply, and agent_conversation_updated carries that
run's id when a reply starts and null when it ends, with the conversation's
updated_on to order them, so every session can show it without requests.
A blank model answer now ends the reply as failed, and replies reuse
ChatRunStatus. Reply permission checks move to the service, sends check the
agent-builder flag, finishing a reply relies on the engine's run lock
instead of a row lock, and the workspace limit defaults to 10.

* feat(chat): share Kuma's typing and loading indicators

Kuma's bouncing dots and reasoning spinner move to core as ChatTyping and
ChatLoading, and Kuma renders them from there with the same look.
ChatComposer's status prop becomes activity and keeps focus on the input
when Send and Stop swap, ChatMessage drops its author props until
conversations can be shared, and markdown leaves mailto and other non-web
links to the browser.

* feat(agent-builder): show reply progress like Kuma and apply replies in place

A reply shows the typing dots until its first text, then a spinner beside
the streaming text. The finished run's saved reply replaces it in place, a
run's start no longer reads the messages, and a streamed chunk re-renders
only the reply being written. Realtime updates set a listed conversation's
run without reading the list again, so its dot pulses grey while it
replies, in every session, and the page drops its chat subscription when no
conversation is open.

* fix(agent): handle empty replies and legacy message retries

* fix(agent): address reply review feedback

* refactor(chat): share response UI with Kuma

* fix(assistant): separate thinking from streamed answers

* feat(chat): share message footers with Kuma

* fix(chat): keep thinking blue and streamed answers expanded
2026-11-03 17:03:13 +01:00

61 lines
1.8 KiB
JavaScript

import { afterEach, describe, expect, test, vi } from 'vitest'
import { flushPromises, mount } from '@vue/test-utils'
import ChatCopyButton from '@baserow/modules/core/components/chat/ChatCopyButton'
import Copied from '@baserow/modules/core/components/Copied'
const render = () =>
mount(ChatCopyButton, {
props: { text: '**Hello**' },
global: {
components: { Copied },
directives: { tooltip: {} },
mocks: { $t: (key) => key },
},
})
describe('ChatCopyButton', () => {
afterEach(() => vi.restoreAllMocks())
test('copies the original text and shows confirmation', async () => {
const writeText = vi
.spyOn(navigator.clipboard, 'writeText')
.mockResolvedValue()
const wrapper = render()
await wrapper.get('button').trigger('click')
await flushPromises()
expect(writeText).toHaveBeenCalledExactlyOnceWith('**Hello**')
expect(wrapper.find('.copied--show').exists()).toBe(true)
wrapper.unmount()
})
test('lets the caller handle clipboard failure without showing success', async () => {
const error = new Error('Clipboard denied')
vi.spyOn(navigator.clipboard, 'writeText').mockRejectedValue(error)
const wrapper = render()
await wrapper.get('button').trigger('click')
await flushPromises()
expect(wrapper.emitted('error')).toEqual([[error]])
expect(wrapper.find('.copied--show').exists()).toBe(false)
wrapper.unmount()
})
test('allows a copy to finish after the message was unmounted', async () => {
let finish
vi.spyOn(navigator.clipboard, 'writeText').mockImplementation(
() => new Promise((resolve) => (finish = resolve))
)
const wrapper = render()
await wrapper.get('button').trigger('click')
wrapper.unmount()
finish()
await flushPromises()
expect(wrapper.emitted('error')).toBeUndefined()
})
})