Browse Source

fix: chat search matches every prompt of a chat and highlights the matching one; resizing the docked chat sets only the page margin while dragging (the panel width variable once on release) and contains the panel's layout, so Safari no longer recomputes the whole page on every move

pull/16895/head
Igor Kulikov 2 hours ago
parent
commit
631f32dd39
  1. 10
      ui-ngx/src/app/core/services/ai-chats.service.ts
  2. 4
      ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.scss
  3. 13
      ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.ts
  4. 4
      ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts
  5. 14
      ui-ngx/src/app/modules/home/pages/ai-assistant/ai-assistant.component.ts
  6. 1
      ui-ngx/src/app/shared/models/ai-chat.models.ts

10
ui-ngx/src/app/core/services/ai-chats.service.ts

@ -299,6 +299,16 @@ export class AiChatsService {
);
}
addPrompt(chatId: string | undefined, text: string | undefined): void {
const prompt = text?.trim();
if (!chatId || !prompt) {
return;
}
this._chats.update(list => list.map(chat => chat.id === chatId
? {...chat, prompt: chat.prompt ?? prompt, prompts: [...(chat.prompts ?? (chat.prompt ? [chat.prompt] : [])), prompt]}
: chat));
}
setTitle(chatId: string, title: string): void {
this._chats.update(list => list.map(chat => chat.id === chatId ? {...chat, title} : chat));
}

4
ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.scss

@ -20,6 +20,10 @@
transition: none;
}
&.resizing {
contain: layout style;
}
&.restored {
transition: none;
}

13
ui-ngx/src/app/modules/home/components/ai/ai-assistant-panel.component.ts

@ -237,7 +237,8 @@ export class AiAssistantPanelComponent {
this.resizing.set(true);
const grip = event.target as HTMLElement;
const host = this.elementRef.nativeElement as HTMLElement;
const root = document.documentElement;
const page = host.parentElement?.querySelector<HTMLElement>('.tb-site-main.openAiAssistant') ?? null;
const pageFollows = !!page && parseFloat(getComputedStyle(page).marginRight) > 0;
const startX = event.clientX;
const startWidth = this.width();
this.room.set(host.parentElement?.clientWidth ?? window.innerWidth);
@ -250,7 +251,9 @@ export class AiAssistantPanelComponent {
const reflowPage = () => {
pageTimer = undefined;
pageAt = performance.now();
root.style.setProperty('--tb-ai-panel-w', current + 'px');
if (pageFollows) {
page.style.marginRight = current + 'px';
}
};
const paint = () => {
frame = 0;
@ -261,6 +264,7 @@ export class AiAssistantPanelComponent {
};
grip.setPointerCapture(event.pointerId);
document.body.classList.add('tb-ai-resizing');
host.classList.add('resizing');
this.zone.runOutsideAngular(() => {
const move = (e: PointerEvent) => {
const wanted = startWidth + (startX - e.clientX);
@ -281,8 +285,11 @@ export class AiAssistantPanelComponent {
cancelAnimationFrame(frame);
clearTimeout(pageTimer);
document.body.classList.remove('tb-ai-resizing');
host.classList.remove('closing');
host.classList.remove('closing', 'resizing');
host.style.width = '';
if (page) {
page.style.marginRight = '';
}
this.zone.run(() => {
this.resizing.set(false);
if (closing) {

4
ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts

@ -1034,6 +1034,7 @@ export class AiChatComponent implements OnInit, OnDestroy {
private sendWhileWorking(prompt: AiPromptMessage, userMessage: ChatMessage): void {
const chatId = this.chatId();
let ownTurn = false;
this.chats.addPrompt(chatId, prompt.message);
this.aiChat.sendChatMessage(chatId, this.chatRequest(prompt), {ignoreLoading: true, ignoreErrors: true}).pipe(
takeUntil(this.cancelMessage$),
concatMap(event => {
@ -1135,6 +1136,9 @@ export class AiChatComponent implements OnInit, OnDestroy {
return startOrContinue$.pipe(
tap(() => {
this.chats.clearFailure(this.chatId());
if (!again) {
this.chats.addPrompt(this.chatId(), prompt.message);
}
this.startLoading();
}),
switchMap(() => this.aiChat.sendChatMessage(this.chatId(), request, {ignoreLoading: true, ignoreErrors: true})),

14
ui-ngx/src/app/modules/home/pages/ai-assistant/ai-assistant.component.ts

@ -44,6 +44,7 @@ export interface AiRailRow {
pinned: boolean;
pinnedTime?: number;
prompt?: string;
prompts?: string[];
chat?: ChatInfo;
solution?: SolutionInfo;
}
@ -104,7 +105,7 @@ export class AiAssistantComponent implements OnInit, OnDestroy {
rows = computed<AiRailRow[]>(() => [
...this.aiChats.chats().map(chat => ({
id: chat.id, title: chat.title, createdTime: chat.createdTime, pinned: !!chat.pinned, pinnedTime: chat.pinnedTime, prompt: chat.prompt, chat
id: chat.id, title: chat.title, createdTime: chat.createdTime, pinned: !!chat.pinned, pinnedTime: chat.pinnedTime, prompt: chat.prompt, prompts: chat.prompts, chat
})),
...this.aiSolutions.solutions().map(solution => ({
id: solution.id, title: this.aiSolutions.titleOf(solution), createdTime: solution.createdTime ?? 0, pinned: !!solution.pinned, solution
@ -115,7 +116,7 @@ export class AiAssistantComponent implements OnInit, OnDestroy {
const query = this.query().trim().toLowerCase();
const chats = this.rows();
if (query) {
const found = chats.filter(chat => (chat.title ?? '').toLowerCase().includes(query) || (chat.prompt ?? '').toLowerCase().includes(query));
const found = chats.filter(chat => (chat.title ?? '').toLowerCase().includes(query) || !!this.promptWith(chat, query));
return found.length
? [{label: this.translate.instant('ai-assistant.chats-found', {count: found.length}), chats: found}]
: [];
@ -365,8 +366,8 @@ export class AiAssistantComponent implements OnInit, OnDestroy {
snippetOf(row: AiRailRow): {text: string; hit: boolean}[] | null {
const query = this.query().trim().toLowerCase();
const prompt = row.prompt ?? '';
const at = query ? prompt.toLowerCase().indexOf(query) : -1;
const prompt = query ? this.promptWith(row, query) ?? '' : '';
const at = prompt.toLowerCase().indexOf(query);
if (!query || (row.title ?? '').toLowerCase().includes(query) || at < 0) {
return null;
}
@ -382,6 +383,11 @@ export class AiAssistantComponent implements OnInit, OnDestroy {
].filter(part => part.text);
}
private promptWith(row: AiRailRow, query: string): string | undefined {
const prompts = row.prompts?.length ? row.prompts : row.prompt ? [row.prompt] : [];
return prompts.find(prompt => prompt.toLowerCase().includes(query));
}
runAgain(chat: ChatInfo): void {
const start = (prompt: string | undefined) => {
if (!prompt?.trim()) {

1
ui-ngx/src/app/shared/models/ai-chat.models.ts

@ -40,6 +40,7 @@ export interface ChatInfo extends ChatConfiguration {
pinned?: boolean;
pinnedTime?: number;
prompt?: string;
prompts?: string[];
status?: ChatStatus;
statusReason?: string;
updatedTime?: number;

Loading…
Cancel
Save