fix: address assistant review findings

This commit is contained in:
ajnart committed 2026-08-14 11:32:11 +02:00
1 parent 87f264a286
commit b988e431e8
8 files changed
+71 -180

No files matched your search

-24
View File
@@ -5418,30 +5418,6 @@
"assistant": {
"name": "Assistant",
"description": "Have a complete assistant conversation directly on your board.",
"option": {
"conversationMode": {
"label": "Conversation",
"description": "Follow the conversation used elsewhere in Homarr, or keep this widget attached to a specific conversation.",
"option": {
"current": "Current conversation",
"pinned": "Pinned conversation"
}
},
"conversation": {
"label": "Pinned conversation",
"description": "Choose the saved conversation this widget should keep available.",
"placeholder": "Select a saved conversation"
}
},
"pinned": {
"title": "Pinned conversation",
"description": "This widget is attached to {conversation}. Open it to continue here without silently changing your active conversation.",
"selectTitle": "Choose a conversation",
"selectDescription": "Open the widget settings and select the conversation this widget should keep available.",
"open": "Open conversation",
"opening": "Opening conversation...",
"error": "This conversation could not be opened. It may have been deleted."
},
"unavailable": {
"title": "Assistant unavailable",
"description": "Sign in and ask an administrator to configure the Assistant from the management panel."
@@ -8,16 +8,9 @@ describe("assistant widget definition", () => {
expect(supportsAdvancedFocus(definition)).toBe(false);
});
it("follows the current conversation by default", () => {
it("does not persist private conversation data in board options", () => {
const options = definition.createOptions();
expect(options.conversationMode.defaultValue).toBe("current");
expect(options.conversation.shouldHide?.({ conversationMode: "current", conversation: null }, [])).toBe(true);
});
it("reveals the conversation selector only when a conversation is pinned", () => {
const options = definition.createOptions();
expect(options.conversation.shouldHide?.({ conversationMode: "pinned", conversation: null }, [])).toBe(false);
expect(options).toEqual({});
});
});
+1 -39
View File
@@ -1,50 +1,12 @@
import { IconRobot } from "@tabler/icons-react";
import { clientApi } from "@homarr/api/client";
import { createWidgetDefinition } from "../definition";
import { optionsBuilder } from "../options";
export const { definition, componentLoader } = createWidgetDefinition("assistant", {
icon: IconRobot,
createOptions() {
return optionsBuilder.from(
(factory) => ({
conversationMode: factory.select({
options: (["current", "pinned"] as const).map((value) => ({
value,
label: (t) => t(`widget.assistant.option.conversationMode.option.${value}`),
})),
defaultValue: "current",
withDescription: true,
}),
conversation: factory.dynamicSelect({
withDescription: true,
useOptions(query) {
const { data: threads = [], isPending, isError } = clientApi.assistant.listThreads.useQuery();
const normalizedQuery = query.trim().toLocaleLowerCase();
return {
isPending,
isError,
options: threads
.filter((thread) => {
if (normalizedQuery.length === 0) return true;
return (thread.title ?? "").toLocaleLowerCase().includes(normalizedQuery);
})
.map((thread) => ({
value: thread.id,
label: thread.title?.trim() || thread.id,
})),
};
},
}),
}),
{
conversation: {
shouldHide: (options) => options.conversationMode !== "pinned",
},
},
);
return optionsBuilder.from(() => ({}));
},
}).withDynamicImport(() => import("./component"));