Files
baserow/web-frontend/modules/core/plugins/chatRuns.js
Davide Silvestri 362f690b9e feat(chat-runs): per-run-type limits and a core run stream (#6454)
* feat(chat-runs): limit active runs per run type, per user or workspace

Each run type now counts only its own runs. The per-user limit keeps its default of 2, and a run type can add a per-workspace limit.

* feat(chat-runs): follow any run over one core streaming endpoint

GET /api/chat-runs/<run_id>/stream/ relays the output of any run type behind its read check. Helm and the install guides route /api/chat-runs/ to the ASGI service; the guides also gain Kuma's /assistant/ route.

* feat(chat-runs): read the core run stream by default in the frontend

The base ChatRunType reads the core stream, applies the resume baseline and retries once after a token refresh.

* refactor(chat-runs): expose the output fold for lost runs

Run types rebuild a lost run's partial text from the buffered output with fold_output.

* perf(chat-runs): send heartbeat records and skip repeated run reads

While no output arrives, an open stream sends run.heartbeat as a JSON
record, so a follower can tell a quiet stream from a stalled one. The stream
view hands follow_run the run state it read for its permission check,
finish_run returns the ended run instead of letting callers read it again,
and a lease renewal takes one statement while the run goes on. The
per-workspace limit hook receives the workspace, so a run type can set the
limit per plan.

* perf(chat-runs): follow runs from their open stream in the frontend

The store reads a run's status only while it has no stream or the stream
lost its output, and restarts a stream that stays silent for 15 seconds,
also after the computer slept. Following a run opens its stream directly,
and Stop doesn't read a run whose stream is open. Each run type keeps one
chat subscription, released with unsubscribeFromChat; refreshChat runs only
when a subscription is confirmed on a new websocket, and window focus or a
regained network only re-attach followers. The developer guide documents
the subscription and heartbeat contract.

* perf(chat-runs): write a reply's first words at once

- The journal writes output after a quiet moment at once and batches
  what follows, so the first words no longer wait for the 250 ms timer.
- The stream adapter settles when aborted. Chrome can fire the last
  progress event after the request is done, where aborting fires no event.
- A stream refused with 503 is retried with the next status check
  instead of spending every reconnect attempt at once.

* refactor(chat-runs): register the stream route by URL name
2026-10-30 10:35:50 +01:00

26 lines
768 B
JavaScript

import { registerChatRunRealtimeEvents } from '@baserow/modules/core/chatRuns/realtime'
export default defineNuxtPlugin({
name: 'chat-runs',
dependsOn: ['realtime', 'store'],
setup(nuxtApp) {
const store = nuxtApp.$store
registerChatRunRealtimeEvents(nuxtApp.$realtime)
if (import.meta.client) {
const resume = () => {
if (store.getters['auth/isAuthenticated']) {
store.dispatch('chatRuns/resumeFollowers')
}
}
window.addEventListener('focus', resume)
window.addEventListener('online', resume)
store.watch(
(_, getters) => getters['auth/isAuthenticated'],
(authenticated) => {
if (!authenticated) store.dispatch('chatRuns/disconnect')
}
)
}
},
})