Skip to content

Commit 4ad8e73

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
[DrJones/Perf] require a new conversation for new context
- Each "Ask AI" for the Performance agent results in a new conversation - Context switches by navigation would also require a new conversation (upon the user action). Bug: 370436840, 377601855 Change-Id: Id96454fbaa34fcfe03b9e638c70dbcf9223c7f6a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5999262 Commit-Queue: Paul Irish <[email protected]> Reviewed-by: Paul Irish <[email protected]> Commit-Queue: Alex Rudenko <[email protected]>
1 parent 4cd0256 commit 4ad8e73

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

front_end/panels/freestyler/AiAgent.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export abstract class AiAgent<T> {
172172
* historical conversations.
173173
*/
174174
#origin?: string;
175+
#context?: ConversationContext<T>;
175176

176177
constructor(opts: AgentOptions) {
177178
this.#aidaClient = opts.aidaClient;
@@ -194,6 +195,10 @@ export abstract class AiAgent<T> {
194195
return this.#origin;
195196
}
196197

198+
get context(): ConversationContext<T>|undefined {
199+
return this.#context;
200+
}
201+
197202
get title(): string|undefined {
198203
return [...this.#history.values()]
199204
.flat()
@@ -402,6 +407,10 @@ STOP`;
402407
if (options.selected && this.#origin === undefined && options.selected) {
403408
this.#origin = options.selected.getOrigin();
404409
}
410+
// Remember if the context that is set.
411+
if (options.selected && !this.#context) {
412+
this.#context = options.selected;
413+
}
405414
const id = this.#runId++;
406415

407416
const response = {

front_end/panels/freestyler/FreestylerPanel.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,8 @@ export class FreestylerPanel extends UI.Panel.Panel {
577577
return;
578578
}
579579

580-
if (!this.#currentAgent) {
581-
this.#currentAgent = this.#createAgent(targetAgentType);
582-
} else if (this.#currentAgent.type !== targetAgentType || this.#currentAgent.isHistoryEntry) {
580+
if (!this.#currentAgent || this.#currentAgent.type !== targetAgentType || this.#currentAgent.isHistoryEntry ||
581+
targetAgentType === AgentType.DRJONES_PERFORMANCE) {
583582
this.#currentAgent = this.#createAgent(targetAgentType);
584583
}
585584
this.#viewProps.agentType = this.#currentAgent.type;
@@ -680,11 +679,14 @@ export class FreestylerPanel extends UI.Panel.Panel {
680679
this.#viewProps.selectedContext = currentContext;
681680
if (!currentContext) {
682681
this.#viewProps.blockedByCrossOrigin = false;
682+
this.#viewProps.requiresNewConversation = false;
683683
this.doUpdate();
684684
return;
685685
}
686686
this.#viewProps.blockedByCrossOrigin = !currentContext.isOriginAllowed(this.#currentAgent.origin);
687687
this.#viewProps.isReadOnly = this.#currentAgent.isHistoryEntry;
688+
this.#viewProps.requiresNewConversation = this.#currentAgent.type === AgentType.DRJONES_PERFORMANCE &&
689+
Boolean(this.#currentAgent.context) && this.#currentAgent.context !== currentContext;
688690
this.doUpdate();
689691
}
690692

front_end/panels/freestyler/components/FreestylerChatUi.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ const UIStringsNotTranslate = {
115115
* @description Placeholder text for the input shown when the conversation is blocked because a cross-origin context was selected.
116116
*/
117117
crossOriginError: 'To talk about data from another origin, start a new chat',
118+
/**
119+
* @description Placeholder text for the input shown when the conversation is blocked because a cross-origin context was selected.
120+
*/
121+
newConversationError: 'To talk about this data, start a new chat',
118122
/**
119123
*@description Title for the send icon button.
120124
*/
@@ -276,6 +280,7 @@ export interface Props {
276280
agentType?: AgentType;
277281
isReadOnly: boolean;
278282
blockedByCrossOrigin: boolean;
283+
requiresNewConversation?: boolean;
279284
}
280285

281286
// The model returns multiline code blocks in an erroneous way with the language being in new line.
@@ -363,7 +368,7 @@ export class FreestylerChatUi extends HTMLElement {
363368
}
364369

365370
#isTextInputDisabled = (): boolean => {
366-
if (this.#props.blockedByCrossOrigin) {
371+
if (this.#props.blockedByCrossOrigin || this.#props.requiresNewConversation) {
367372
return true;
368373
}
369374
const isAidaAvailable = this.#props.aidaAvailability === Host.AidaClient.AidaAccessPreconditions.AVAILABLE;
@@ -890,6 +895,9 @@ export class FreestylerChatUi extends HTMLElement {
890895
if (state === State.CONSENT_VIEW || !agentType) {
891896
return i18nString(UIStrings.followTheSteps);
892897
}
898+
if (this.#props.requiresNewConversation) {
899+
return lockedString(UIStringsNotTranslate.newConversationError);
900+
}
893901
if (this.#props.blockedByCrossOrigin) {
894902
return lockedString(UIStringsNotTranslate.crossOriginError);
895903
}
@@ -944,7 +952,7 @@ export class FreestylerChatUi extends HTMLElement {
944952
></devtools-button>`;
945953
// clang-format on
946954
}
947-
if (this.#props.blockedByCrossOrigin) {
955+
if (this.#props.blockedByCrossOrigin || this.#props.requiresNewConversation) {
948956
// clang-format off
949957
return html`<devtools-button
950958
class="chat-input-button"

0 commit comments

Comments
 (0)