Repository navigation
feat(assistant): improve the chat for daily and heavy use - #249
Merged
Merged
Conversation
The loader was a 3x3 pixel grid with no tie to the brand. It is now the wheat from the Farmer mark: the stalk draws, the grains spring out of it, then they drop. The grains come from the MARK path itself, so the loader and the logo cannot drift apart.
A person who takes data out of an answer had to copy markdown or read values off a bar. Add actions to export the data. A table gets "Download CSV" and "Copy as table" (TSV). A chart gets "Download PNG" and "Download CSV". The actions show on hover or focus and only on a finished answer, so a half table is never exported. The files are built from the parsed blocks, not from the DOM. Inline markdown is removed from each cell. The CSV follows RFC 4180, has a BOM for Excel, and guards a cell that starts with a formula sign unless the cell is a plain number. The chart is HTML and CSS, not SVG. The PNG is drawn again on a canvas at 2x from the chart spec, with the colors of the current theme.
Every turn sends the whole thread again, and old tool results are most of it. The wire copy now replaces a tool result over 400 characters with a short stub when it is older than the last 4 user messages. Stored rows, call ids and the current turn do not change. The thread payload (web and api/v1) now carries promptTokens of the last answer and the contextLength of the thread's model. The web composer and the mobile chat show a note when the chat uses 70% or more of the model's memory, with a New chat action.
An admin could not see what the assistant cost. PostHog held the figures, but the product showed none of them. Add the assistant_usage table. generate() writes one row for each billed call (turn step, retry and title), beside the telemetry event. The cost is null when a stalled attempt has no usage row, so the view counts it as unknown and not as zero. A failed insert is logged and never fails the turn. userId has no foreign key and conversationId is set null, so a removed person or a deleted thread keeps its cost. Add assistantUsageService.summary (admin only). It sums in SQL for the organization, each person and each model over a period. Add Settings -> AI. It holds the assistant settings, moved from Workspace -> Integrations, and a usage panel with a period picker. Update every text that named the old place.
# Conflicts: # packages/core/src/services/assistant.service.ts
The assistant was only reachable from its own page. The empty chat also showed a fixed list of questions, one with a month name. Add Cmd+K and Ctrl+K in the org layout. The shortcut opens a small dialog that starts a new chat in the run store, so the answer keeps streaming after the dialog closes. A removable chip adds one sentence that names the current page, built from the URL only. Add an "Ask about this" button on Reports and a shortcut hint on the Chat nav row. Build the empty-chat questions on the client from the targets, the entries, the unfiled list and the calendar status. Never name a month.
An inline write ran with no way back. A person who saw a wrong entry had to ask the model to fix it, which is a second write. A tool can now set an undo capture. Before the write, the tool reads the old state. After it, the inverse and the new updatedAt go on the tool row (undo, undone_at). assistantService.undo claims the row and runs the inverse through timeEntriesService. It refuses when the entry changed since. The wire copy of an undone result tells the model. Undo exists for create_time_entry, update_time_entry, update_entry_description and set_overtime. The other writes have no exact inverse. replaceLastTurn removes the last question and the rows after it, in one transaction under row locks. It refuses after a write that was not undone. Usage rows stay. Web, the REST API (undo and rewind routes) and the mobile app get Undo, Edit and Retry. The migration is 0085.
# Conflicts: # apps/web/src/routes/$orgSlug/assistant.tsx
A person could not find an old chat, and could not show one to a colleague. Search: assistantService.search matches the title and the text of user and assistant rows in the caller's own chats. It escapes LIKE wildcards, as ledger.ts does. It returns at most 30 chats with a short snippet. Share: a chat gets sharedAt and sharedBy (migration 0086). The owner shares it. Any member of the org can read it, read only, behind a warning, because a chat can hold results that were read with the owner's access. The owner or an Admin stops the share. Both changes write an audit row. Web: a search field in the chat rail, a Share dialog, and a read-only route for a shared chat. REST: search, share and shared-thread routes. Mobile: search on the thread list, Share in the chat header, and a read-only shared chat screen.
After a rewind, the question is gone from the thread. If the resend then failed, the text was lost apart from a toast. The web and the mobile app now put the text back in the composer and focus it. The refusal for a turn with a write that has no inverse said "Undo the change first", which the person cannot do. The core error now depends on the case, in one pure helper (editBlockReason). The API message carries a new `changed` field, so the web app and the mobile app show the same text on the disabled Edit and Retry buttons.
A search snippet was cut from the raw message text. It showed markdown, chart JSON and directive syntax. Turn the message into plain text first. Drop fenced blocks, turn date directives into the date, and strip emphasis, code ticks, links, heading marks and table pipes. A match that sat only in a removed block falls back to the start of the text.
Shorten long comments in the AI settings page, the reports tab link and the sprout loader. Keep each reason, drop the history and the restated code. Remove one stray comma in the integrations doc. No behavior change.
Drop the answer of a turn when its question row was removed while the model wrote. A share lock on the question row makes the check and the insert one step. Refuse the undo of a created entry when it holds commits or reviews. These rows do not change updatedAt, so the staleness guard misses them. Offer no undo for an update of a fill-day entry. The update recomputes the duration, so the inverse is not exact. Count the four refusals that run before a tool as not run, so edit and retry are not blocked. Key the model catalogue cache per organization. Cache a failure for 60 seconds and log the error. Read the sharer name with one query in place of the whole roster. Read only a window around the match in the chat search. Let the CSV guard keep durations such as -1:30 and signed currency amounts such as -EUR 5 unchanged. Correct a comment on the tool result window.
The form was a grid with an auto column, so a long page sentence widened the dialog and made it scroll sideways instead of truncating. Focus also landed on the chip's remove button, not the question field.
Ctrl K opens the same dialog on every page, with the same page sentence, so the button on Reports only took room from the tabs.
The first fix had three gaps. replaceLastTurn locked every thread row in one statement. If it waited on the question row, its snapshot missed an answer that committed meanwhile, and it left that row behind. Lock the question row alone first, then read the thread in a second statement. The question id was read from history at each step. After a rewind it could name the previous turn, or be null and skip the check. Capture the id once when the turn starts, keep it on the turn run state, and drop the answer when the row is missing. A resumed turn uses the last user row. claimCalls could write tool rows for a deleted turn. Check the question row inside its transaction. applyUndo checks commit evidence outside the delete transaction. time-entries remove has no refuse option, so keep the check and note the small window.
Hide tool data from a shared thread. getShared now returns only user and assistant rows, with toolCalls and approval fields set to null. Return the undone row from undo. The route no longer calls the full conversation get, which can call OpenRouter. Return null from contextLengthOf when the assistant is off. Share one catalogue load for each organization. Reset the edit state when the thread changes. Show an error state in the chat search, and limit the search input to 100 characters. Limit the Cmd+K question, report a send failure with a toast, and strip quotes and newlines from the project name in the page sentence. Keep typed text in the mobile composer when a failed send gives text back. Append the failed text below it. Read the first search hit with DISTINCT ON in Postgres. Name the 422 and 404 cases in the OpenAPI text and regenerate the api-client. Revoke the export object URL after a delay.
A shared chat had a web link only. A phone with the app had no way to open the chat in the app. Add an "Open in the app" link to the web page. It shows on a phone only and points to farmer://assistant/shared/<id>?org=&server=. The app compares org and server with the signed-in workspace. On a mismatch it does not fetch. It names the server host and the org, so the person knows which workspace to switch to.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes the assistant chat better for daily use and for heavy use. It changes the web app and the mobile app together.
Changes
assistant_usage, keeps one row for each billed model call.create_time_entry,update_time_entry,update_entry_descriptionandset_overtime.'.Migrations
0084: theassistant_usagetable.0085:undoandundone_atonassistant_message.0086:shared_atandshared_byonassistant_conversation.All three migrations only add a table or a column.
Out of scope
Known gaps
farmer://). A signed-out app loses the link at sign-in.services/ledger.ts. The fix needs a new server function.Tests
bun run check,bun run typecheckandbun run complexitypass.main, and they pass in CI.