mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-06-25 00:52:14 +00:00
FIX: Search discoveries improvements (#1228)
**This update makes a few improvements to search discoveries:** - [x] in search menu panel: search discoveries should still be triggered when no regular results are present - [x] in full page search: search discoveries should still be triggered when no regular results are present - [x] flakiness in search discoveries sometimes not working properly. --------- Co-authored-by: awesomerobot <kris.aubuchon@discourse.org>
This commit is contained in:
parent
28fa723472
commit
f3e78f0d80
@ -11,6 +11,7 @@ import DButton from "discourse/components/d-button";
|
|||||||
import concatClass from "discourse/helpers/concat-class";
|
import concatClass from "discourse/helpers/concat-class";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import { bind } from "discourse/lib/decorators";
|
import { bind } from "discourse/lib/decorators";
|
||||||
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||||
import { i18n } from "discourse-i18n";
|
import { i18n } from "discourse-i18n";
|
||||||
import SmoothStreamer from "../lib/smooth-streamer";
|
import SmoothStreamer from "../lib/smooth-streamer";
|
||||||
import AiBlinkingAnimation from "./ai-blinking-animation";
|
import AiBlinkingAnimation from "./ai-blinking-animation";
|
||||||
@ -23,7 +24,6 @@ export default class AiSearchDiscoveries extends Component {
|
|||||||
@service discobotDiscoveries;
|
@service discobotDiscoveries;
|
||||||
@service appEvents;
|
@service appEvents;
|
||||||
|
|
||||||
@tracked loadingDiscoveries = false;
|
|
||||||
@tracked hideDiscoveries = false;
|
@tracked hideDiscoveries = false;
|
||||||
@tracked fullDiscoveryToggled = false;
|
@tracked fullDiscoveryToggled = false;
|
||||||
@tracked discoveryPreviewLength = this.args.discoveryPreviewLength || 150;
|
@tracked discoveryPreviewLength = this.args.discoveryPreviewLength || 150;
|
||||||
@ -34,8 +34,6 @@ export default class AiSearchDiscoveries extends Component {
|
|||||||
);
|
);
|
||||||
|
|
||||||
discoveryTimeout = null;
|
discoveryTimeout = null;
|
||||||
typingTimer = null;
|
|
||||||
streamedTextLength = 0;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
@ -55,6 +53,34 @@ export default class AiSearchDiscoveries extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@bind
|
||||||
|
detectSearch() {
|
||||||
|
if (
|
||||||
|
this.query?.length === 0 &&
|
||||||
|
this.discobotDiscoveries.discovery?.length > 0
|
||||||
|
) {
|
||||||
|
this.discobotDiscoveries.resetDiscovery();
|
||||||
|
this.smoothStreamer.resetStreaming();
|
||||||
|
}
|
||||||
|
|
||||||
|
withPluginApi((api) => {
|
||||||
|
api.addSearchMenuOnKeyDownCallback((searchMenu, event) => {
|
||||||
|
if (!searchMenu || this.discobotDiscoveries.loadingDiscoveries) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.discobotDiscoveries.lastQuery === this.query) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.key === "Enter" && this.query) {
|
||||||
|
this.triggerDiscovery();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
async _updateDiscovery(update) {
|
async _updateDiscovery(update) {
|
||||||
if (this.query === update.query) {
|
if (this.query === update.query) {
|
||||||
@ -67,7 +93,7 @@ export default class AiSearchDiscoveries extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.discobotDiscoveries.modelUsed = update.model_used;
|
this.discobotDiscoveries.modelUsed = update.model_used;
|
||||||
this.loadingDiscoveries = false;
|
this.discobotDiscoveries.loadingDiscoveries = false;
|
||||||
this.smoothStreamer.updateResult(update, "ai_discover_reply");
|
this.smoothStreamer.updateResult(update, "ai_discover_reply");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,7 +136,7 @@ export default class AiSearchDiscoveries extends Component {
|
|||||||
|
|
||||||
get canShowExpandtoggle() {
|
get canShowExpandtoggle() {
|
||||||
return (
|
return (
|
||||||
!this.loadingDiscoveries &&
|
!this.discobotDiscoveries.loadingDiscoveries &&
|
||||||
this.smoothStreamer.renderedText.length > this.discoveryPreviewLength
|
this.smoothStreamer.renderedText.length > this.discoveryPreviewLength
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -130,7 +156,8 @@ export default class AiSearchDiscoveries extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.hideDiscoveries = false;
|
this.hideDiscoveries = false;
|
||||||
this.loadingDiscoveries = true;
|
this.discobotDiscoveries.loadingDiscoveries = true;
|
||||||
|
|
||||||
this.discoveryTimeout = later(
|
this.discoveryTimeout = later(
|
||||||
this,
|
this,
|
||||||
this.timeoutDiscovery,
|
this.timeoutDiscovery,
|
||||||
@ -139,6 +166,7 @@ export default class AiSearchDiscoveries extends Component {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
this.discobotDiscoveries.lastQuery = this.query;
|
this.discobotDiscoveries.lastQuery = this.query;
|
||||||
|
|
||||||
await ajax("/discourse-ai/ai-bot/discover", {
|
await ajax("/discourse-ai/ai-bot/discover", {
|
||||||
data: { query: this.query },
|
data: { query: this.query },
|
||||||
});
|
});
|
||||||
@ -153,7 +181,7 @@ export default class AiSearchDiscoveries extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
timeoutDiscovery() {
|
timeoutDiscovery() {
|
||||||
this.loadingDiscoveries = false;
|
this.discobotDiscoveries.loadingDiscoveries = false;
|
||||||
this.discobotDiscoveries.discovery = "";
|
this.discobotDiscoveries.discovery = "";
|
||||||
|
|
||||||
this.discobotDiscoveries.discoveryTimedOut = true;
|
this.discobotDiscoveries.discoveryTimedOut = true;
|
||||||
@ -162,13 +190,14 @@ export default class AiSearchDiscoveries extends Component {
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="ai-search-discoveries"
|
class="ai-search-discoveries"
|
||||||
{{didInsert this.subscribe @searchTerm}}
|
{{didInsert this.subscribe this.query}}
|
||||||
{{didUpdate this.subscribe @searchTerm}}
|
{{didUpdate this.subscribe this.query}}
|
||||||
|
{{didUpdate this.detectSearch this.query}}
|
||||||
{{didInsert this.triggerDiscovery this.query}}
|
{{didInsert this.triggerDiscovery this.query}}
|
||||||
{{willDestroy this.unsubscribe}}
|
{{willDestroy this.unsubscribe}}
|
||||||
>
|
>
|
||||||
<div class="ai-search-discoveries__completion">
|
<div class="ai-search-discoveries__completion">
|
||||||
{{#if this.loadingDiscoveries}}
|
{{#if this.discobotDiscoveries.loadingDiscoveries}}
|
||||||
<AiBlinkingAnimation />
|
<AiBlinkingAnimation />
|
||||||
{{else if this.discobotDiscoveries.discoveryTimedOut}}
|
{{else if this.discobotDiscoveries.discoveryTimedOut}}
|
||||||
{{i18n "discourse_ai.discobot_discoveries.timed_out"}}
|
{{i18n "discourse_ai.discobot_discoveries.timed_out"}}
|
||||||
@ -181,9 +210,10 @@ export default class AiSearchDiscoveries extends Component {
|
|||||||
"streamable-content"
|
"streamable-content"
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div class="cooked">
|
<CookText
|
||||||
<CookText @rawText={{this.smoothStreamer.renderedText}} />
|
@rawText={{this.smoothStreamer.renderedText}}
|
||||||
</div>
|
class="cooked"
|
||||||
|
/>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
{{#if this.canShowExpandtoggle}}
|
{{#if this.canShowExpandtoggle}}
|
||||||
|
@ -16,12 +16,8 @@ export default class AiFullPageDiscobotDiscoveries extends Component {
|
|||||||
|
|
||||||
@service discobotDiscoveries;
|
@service discobotDiscoveries;
|
||||||
|
|
||||||
get hasDiscoveries() {
|
|
||||||
return this.args.outletArgs?.model?.topics?.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
{{#if this.hasDiscoveries}}
|
{{#if this.discobotDiscoveries.showDiscoveryTitle}}
|
||||||
<h3
|
<h3
|
||||||
class="ai-search-discoveries__discoveries-title full-page-discoveries"
|
class="ai-search-discoveries__discoveries-title full-page-discoveries"
|
||||||
>
|
>
|
||||||
@ -32,9 +28,10 @@ export default class AiFullPageDiscobotDiscoveries extends Component {
|
|||||||
|
|
||||||
<AiSearchDiscoveriesTooltip />
|
<AiSearchDiscoveriesTooltip />
|
||||||
</h3>
|
</h3>
|
||||||
<div class="full-page-discoveries">
|
|
||||||
<AiSearchDiscoveries @searchTerm={{@outletArgs.search}} />
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
<div class="full-page-discoveries">
|
||||||
|
<AiSearchDiscoveries @searchTerm={{@outletArgs.search}} />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import AiSearchDiscoveriesTooltip from "../../components/ai-search-discoveries-t
|
|||||||
export default class AiDiscobotDiscoveries extends Component {
|
export default class AiDiscobotDiscoveries extends Component {
|
||||||
static shouldRender(args, { siteSettings, currentUser }) {
|
static shouldRender(args, { siteSettings, currentUser }) {
|
||||||
return (
|
return (
|
||||||
args.resultType.type === "topic" &&
|
|
||||||
siteSettings.ai_bot_discover_persona &&
|
siteSettings.ai_bot_discover_persona &&
|
||||||
currentUser?.can_use_ai_bot_discover_persona &&
|
currentUser?.can_use_ai_bot_discover_persona &&
|
||||||
currentUser?.user_option?.ai_search_discoveries
|
currentUser?.user_option?.ai_search_discoveries
|
||||||
@ -16,24 +15,32 @@ export default class AiDiscobotDiscoveries extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@service discobotDiscoveries;
|
@service discobotDiscoveries;
|
||||||
|
@service search;
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="ai-discobot-discoveries">
|
<div class="ai-discobot-discoveries">
|
||||||
<h3 class="ai-search-discoveries__discoveries-title">
|
{{#if this.discobotDiscoveries.showDiscoveryTitle}}
|
||||||
<span>
|
<h3 class="ai-search-discoveries__discoveries-title">
|
||||||
{{icon "discobot"}}
|
<span>
|
||||||
{{i18n "discourse_ai.discobot_discoveries.main_title"}}
|
{{icon "discobot"}}
|
||||||
</span>
|
{{i18n "discourse_ai.discobot_discoveries.main_title"}}
|
||||||
|
</span>
|
||||||
|
|
||||||
<AiSearchDiscoveriesTooltip />
|
<AiSearchDiscoveriesTooltip />
|
||||||
</h3>
|
</h3>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<AiSearchDiscoveries @discoveryPreviewLength={{50}} />
|
<AiSearchDiscoveries
|
||||||
|
@searchTerm={{@outletArgs.searchTerm}}
|
||||||
|
@discoveryPreviewLength={{50}}
|
||||||
|
/>
|
||||||
|
|
||||||
<h3 class="ai-search-discoveries__regular-results-title">
|
{{#if this.search.results.topics.length}}
|
||||||
{{icon "bars-staggered"}}
|
<h3 class="ai-search-discoveries__regular-results-title">
|
||||||
{{i18n "discourse_ai.discobot_discoveries.regular_results"}}
|
{{icon "bars-staggered"}}
|
||||||
</h3>
|
{{i18n "discourse_ai.discobot_discoveries.regular_results"}}
|
||||||
|
</h3>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
}
|
}
|
@ -11,13 +11,19 @@ export default class DiscobotDiscoveries extends Service {
|
|||||||
@tracked lastQuery = "";
|
@tracked lastQuery = "";
|
||||||
@tracked discoveryTimedOut = false;
|
@tracked discoveryTimedOut = false;
|
||||||
@tracked modelUsed = "";
|
@tracked modelUsed = "";
|
||||||
|
@tracked loadingDiscoveries = false;
|
||||||
|
|
||||||
resetDiscovery() {
|
resetDiscovery() {
|
||||||
|
this.loadingDiscoveries = false;
|
||||||
this.discovery = "";
|
this.discovery = "";
|
||||||
this.discoveryTimedOut = false;
|
this.discoveryTimedOut = false;
|
||||||
this.modelUsed = "";
|
this.modelUsed = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get showDiscoveryTitle() {
|
||||||
|
return this.discovery.length > 0 || this.loadingDiscoveries;
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
async disableDiscoveries() {
|
async disableDiscoveries() {
|
||||||
this.currentUser.user_option.ai_search_discoveries = false;
|
this.currentUser.user_option.ai_search_discoveries = false;
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
.ai-search-discoveries {
|
.ai-search-discoveries {
|
||||||
&__regular-results-title {
|
&__regular-results-title {
|
||||||
|
margin-top: 0.5em;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,10 +94,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ai-discobot-discoveries {
|
|
||||||
padding: 0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.full-page-discoveries {
|
.full-page-discoveries {
|
||||||
padding: 1em 10%;
|
padding: 1em 10%;
|
||||||
}
|
}
|
||||||
@ -107,30 +104,43 @@
|
|||||||
width: 1.15em;
|
width: 1.15em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ai-discobot-discoveries {
|
||||||
|
padding-top: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
@include breakpoint("medium", min-width) {
|
@include breakpoint("medium", min-width) {
|
||||||
.search-menu .menu-panel:has(.ai-discobot-discoveries) {
|
.search-menu .menu-panel:has(.ai-search-discoveries__discoveries-title) {
|
||||||
width: 80vw;
|
width: 80vw;
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
transition: width 0.5s;
|
transition: width 0.5s;
|
||||||
|
|
||||||
.search-result-topic {
|
.results {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-areas: "results-title ai-title" "results ai";
|
|
||||||
grid-template-columns: 58% 38%;
|
grid-template-columns: 58% 38%;
|
||||||
|
grid-template-rows: auto auto 1fr;
|
||||||
gap: 0 4%;
|
gap: 0 4%;
|
||||||
|
|
||||||
.list {
|
* {
|
||||||
grid-area: results;
|
// covers all non-discovery content
|
||||||
|
grid-column-start: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ai-discobot-discoveries {
|
.ai-discobot-discoveries {
|
||||||
grid-area: ai;
|
// always in the second column, always spans all rows
|
||||||
|
grid-column-start: 2;
|
||||||
|
grid-row: 1 / -1;
|
||||||
|
padding-top: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ai-search-discoveries {
|
.ai-search-discoveries {
|
||||||
font-size: var(--font-0);
|
font-size: var(--font-0);
|
||||||
color: var(--primary-high);
|
color: var(--primary-high);
|
||||||
|
padding-right: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ai-search-discoveries__discoveries-title {
|
||||||
|
margin-top: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ai-search-discoveries__regular-results-title {
|
.ai-search-discoveries__regular-results-title {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user