mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 16:28:31 +00:00
* feat(agent): suggest messages to start a conversation with An agent gets up to four suggested messages, edited in its Instructions. A new conversation shows them as cards, on the agent's page and on its public chat, and a click puts the message in the box, ready to send. * feat(agent): let builders style their public chat page A public chat gets a font, an accent color, a plain or gradient background and a "Powered by Baserow" switch, set in its card. The page, password screen included, uses them; the core chat styles take their accent from CSS variables so the page only sets the color. * feat(agent): introduce an empty public chat with its title and welcome text An empty chat shows a mark in the accent colour, the title, the welcome text and the suggested messages in the middle, like the member chat. The header with the title only appears once a conversation exists. The welcome text is rendered as markdown on the server, so it no longer appears after the page has loaded. * fix(agent): fall back to a generic font family on the public chat A quoted generic family is read as a font name, so the page showed a serif font until the chosen one loaded. * feat(agent): keep a public chat's appearance on a copy A duplicated, restored, exported or templated agent's public chat keeps its font, colours, background and Powered by switch. A value from a file that the API would refuse falls back to the default. * fix(agent): check an imported agent's suggested messages A file could carry suggested messages the API refuses, and a value that isn't a list broke the workspace's application list. An import now keeps them only when the API would accept them. The copy tests also cover suggested messages and a user template. * fix(agent): give public chats a neutral default appearance * fix(agent): label suggested messages and cover when they can be used
148 lines
3.9 KiB
Vue
148 lines
3.9 KiB
Vue
<template>
|
|
<FormGroup
|
|
:label="$t('agent.instructions')"
|
|
:error="Boolean(errors.instructions)"
|
|
:error-message="
|
|
sectionType.getFieldErrorMessage('instructions', errors.instructions)
|
|
"
|
|
:helper-text="$t('agent.instructionsHelper')"
|
|
small-label
|
|
required
|
|
>
|
|
<FormTextarea
|
|
ref="instructionsInput"
|
|
:model-value="configuration.instructions || ''"
|
|
:error="Boolean(errors.instructions)"
|
|
:disabled="!editable"
|
|
:rows="10"
|
|
:maxlength="100000"
|
|
@update:model-value="$emit('change', { instructions: $event })"
|
|
@blur="$emit('flush')"
|
|
/>
|
|
</FormGroup>
|
|
<section class="agent-suggested-messages">
|
|
<div class="agent-suggested-messages__header">
|
|
<h3 class="agent-suggested-messages__title">
|
|
{{ $t('agent.suggestedMessages') }}
|
|
</h3>
|
|
<ButtonText
|
|
v-if="editable && rows.length < AGENT_SUGGESTED_MESSAGES_MAX"
|
|
type="primary"
|
|
size="small"
|
|
button-type="button"
|
|
icon="iconoir-plus"
|
|
class="agent-suggested-messages__add"
|
|
@click="addRow"
|
|
>
|
|
{{ $t('agent.addSuggestedMessage') }}
|
|
</ButtonText>
|
|
</div>
|
|
<p class="agent-suggested-messages__description">
|
|
{{ $t('agent.suggestedMessagesDescription') }}
|
|
</p>
|
|
<p v-if="!rows.length" class="agent-suggested-messages__empty">
|
|
{{ $t('agent.noSuggestedMessages') }}
|
|
</p>
|
|
<ul v-else class="agent-suggested-messages__list">
|
|
<li
|
|
v-for="(row, index) in rows"
|
|
:key="row.id"
|
|
class="agent-suggested-messages__item"
|
|
>
|
|
<FormGroup
|
|
class="agent-suggested-messages__input"
|
|
:label="$t('agent.suggestedMessageLabel', { number: index + 1 })"
|
|
required
|
|
>
|
|
<FormInput
|
|
:ref="(input) => (rowInputs[row.id] = input)"
|
|
:model-value="row.text"
|
|
:disabled="!editable"
|
|
:maxlength="AGENT_SUGGESTED_MESSAGE_MAX_LENGTH"
|
|
@update:model-value="editRow(row, $event)"
|
|
@blur="blurRow(row)"
|
|
/>
|
|
</FormGroup>
|
|
<ButtonIcon
|
|
v-if="editable"
|
|
icon="iconoir-bin"
|
|
:aria-label="$t('agent.removeSuggestedMessage')"
|
|
:title="$t('agent.removeSuggestedMessage')"
|
|
@click="removeRow(row)"
|
|
/>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { nextTick, ref, watch } from 'vue'
|
|
import isEqual from 'lodash/isEqual'
|
|
import { uuid } from '@baserow/modules/core/utils/string'
|
|
import {
|
|
AGENT_SUGGESTED_MESSAGE_MAX_LENGTH,
|
|
AGENT_SUGGESTED_MESSAGES_MAX,
|
|
} from '@baserow/modules/agent/constants'
|
|
|
|
defineOptions({ inheritAttrs: false })
|
|
const props = defineProps({
|
|
configuration: { type: Object, required: true },
|
|
errors: { type: Object, required: true },
|
|
sectionType: { type: Object, required: true },
|
|
editable: Boolean,
|
|
})
|
|
const emit = defineEmits(['change', 'flush'])
|
|
const instructionsInput = ref(null)
|
|
const rowInputs = {}
|
|
|
|
const toRows = (messages) =>
|
|
(messages || []).map((text) => ({ id: uuid(), text }))
|
|
const savedMessages = () =>
|
|
rows.value.map((row) => row.text.trim()).filter(Boolean)
|
|
const rows = ref(toRows(props.configuration.suggested_messages))
|
|
|
|
watch(
|
|
() => props.configuration.suggested_messages,
|
|
(messages = []) => {
|
|
if (!isEqual(messages, savedMessages())) rows.value = toRows(messages)
|
|
}
|
|
)
|
|
|
|
function emitChange() {
|
|
emit('change', { suggested_messages: savedMessages() })
|
|
}
|
|
|
|
function editRow(row, text) {
|
|
row.text = text
|
|
emitChange()
|
|
}
|
|
|
|
function withoutRow(row) {
|
|
rows.value = rows.value.filter((other) => other.id !== row.id)
|
|
}
|
|
|
|
function blurRow(row) {
|
|
if (!row.text.trim()) withoutRow(row)
|
|
emit('flush')
|
|
}
|
|
|
|
function removeRow(row) {
|
|
withoutRow(row)
|
|
emitChange()
|
|
emit('flush')
|
|
}
|
|
|
|
async function addRow() {
|
|
const row = { id: uuid(), text: '' }
|
|
rows.value.push(row)
|
|
await nextTick()
|
|
rowInputs[row.id]?.focus()
|
|
}
|
|
|
|
function focusField() {
|
|
instructionsInput.value?.focus()
|
|
}
|
|
|
|
defineExpose({ focusField })
|
|
</script>
|