Skip to content

Commit 835e17d

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[Freestyler] Add history entry point
This adds the button and ability to navigate different conversations. The history is kept in memory for now. Bug: 351752761 Change-Id: I6585295e149fb12880b116b94312c0cd4a2e11d5 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5973696 Commit-Queue: Nikolay Vitkov <[email protected]> Auto-Submit: Nikolay Vitkov <[email protected]> Reviewed-by: Alex Rudenko <[email protected]>
1 parent b92e8ca commit 835e17d

File tree

15 files changed

+268
-44
lines changed

15 files changed

+268
-44
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ grd_files_release_sources = [
150150
"front_end/Images/heap-snapshot.svg",
151151
"front_end/Images/heap-snapshots.svg",
152152
"front_end/Images/help.svg",
153+
"front_end/Images/history.svg",
153154
"front_end/Images/home.svg",
154155
"front_end/Images/hover.svg",
155156
"front_end/Images/iframe-crossed.svg",

config/gni/devtools_image_files.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ devtools_svg_sources = [
153153
"heap-snapshot.svg",
154154
"heap-snapshots.svg",
155155
"help.svg",
156+
"history.svg",
156157
"home.svg",
157158
"hover.svg",
158159
"iframe-crossed.svg",

front_end/Images/src/history.svg

Lines changed: 3 additions & 0 deletions
Loading

front_end/panels/freestyler/AiAgent.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as Freestyler from './freestyler.js';
1212
const {AiAgent, ResponseType} = Freestyler;
1313

1414
class AiAgentMock extends AiAgent<unknown> {
15+
type = Freestyler.AgentType.FREESTYLER;
1516
override preamble = 'preamble';
1617

1718
// eslint-disable-next-line require-yield

front_end/panels/freestyler/AiAgent.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,21 @@ interface ParsedResponseStep {
118118

119119
export type ParsedResponse = ParsedResponseAnswer|ParsedResponseStep;
120120

121+
export const enum AgentType {
122+
FREESTYLER = 'freestyler',
123+
DRJONES_FILE = 'drjones-file',
124+
DRJONES_NETWORK_REQUEST = 'drjones-network-request',
125+
DRJONES_PERFORMANCE = 'drjones-performance',
126+
}
127+
121128
const MAX_STEP = 10;
122129

123130
export abstract class AiAgent<T> {
124131
static validTemperature(temperature: number|undefined): number|undefined {
125132
return typeof temperature === 'number' && temperature >= 0 ? temperature : undefined;
126133
}
127134

135+
abstract type: AgentType;
128136
readonly #sessionId: string = crypto.randomUUID();
129137
#aidaClient: Host.AidaClient.AidaClient;
130138
#serverSideLoggingEnabled: boolean;
@@ -153,6 +161,20 @@ export abstract class AiAgent<T> {
153161
this.#history = history;
154162
}
155163

164+
get isEmpty(): boolean {
165+
return this.#history.size <= 0;
166+
}
167+
168+
get title(): string|undefined {
169+
return [...this.#history.values()]
170+
.flat()
171+
.filter(response => {
172+
return response.type === ResponseType.USER_QUERY;
173+
})
174+
.at(-1)
175+
?.query;
176+
}
177+
156178
#structuredLog: Array<{
157179
request: Host.AidaClient.AidaRequest,
158180
response: string,

front_end/panels/freestyler/DrJonesFileAgent.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as Bindings from '../../models/bindings/bindings.js';
99
import type * as Workspace from '../../models/workspace/workspace.js';
1010

1111
import {
12+
AgentType,
1213
AiAgent,
1314
type AidaRequestOptions,
1415
type ContextDetail,
@@ -73,6 +74,7 @@ const MAX_FILE_SIZE = 10000;
7374
* instance for a new conversation.
7475
*/
7576
export class DrJonesFileAgent extends AiAgent<Workspace.UISourceCode.UISourceCode> {
77+
override type = AgentType.DRJONES_FILE;
7678
readonly preamble = preamble;
7779
readonly clientFeature = Host.AidaClient.ClientFeature.CHROME_DRJONES_FILE_AGENT;
7880
get userTier(): string|undefined {

front_end/panels/freestyler/DrJonesNetworkAgent.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as Logs from '../../models/logs/logs.js';
1010
import * as Network from '../../panels/network/network.js';
1111

1212
import {
13+
AgentType,
1314
AiAgent,
1415
type AidaRequestOptions,
1516
type ContextDetail,
@@ -101,6 +102,7 @@ const lockedString = i18n.i18n.lockedString;
101102
* instance for a new conversation.
102103
*/
103104
export class DrJonesNetworkAgent extends AiAgent<SDK.NetworkRequest.NetworkRequest> {
105+
override type = AgentType.DRJONES_NETWORK_REQUEST;
104106
readonly preamble = preamble;
105107
readonly clientFeature = Host.AidaClient.ClientFeature.CHROME_DRJONES_NETWORK_AGENT;
106108
get userTier(): string|undefined {

front_end/panels/freestyler/DrJonesPerformanceAgent.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as i18n from '../../core/i18n/i18n.js';
88
import type * as TimelineUtils from '../../panels/timeline/utils/utils.js';
99

1010
import {
11+
AgentType,
1112
AiAgent,
1213
type AidaRequestOptions,
1314
type ContextResponse,
@@ -124,6 +125,7 @@ const lockedString = i18n.i18n.lockedString;
124125
* instance for a new conversation.
125126
*/
126127
export class DrJonesPerformanceAgent extends AiAgent<TimelineUtils.AICallTree.AICallTree> {
128+
override type = AgentType.DRJONES_PERFORMANCE;
127129
readonly preamble = preamble;
128130
readonly clientFeature = Host.AidaClient.ClientFeature.CHROME_DRJONES_PERFORMANCE_AGENT;
129131
get userTier(): string|undefined {

front_end/panels/freestyler/FreestylerAgent.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,6 @@ c`;
755755
const agent = new FreestylerAgent({
756756
aidaClient: mockAidaClient(generateAnswer),
757757
execJs,
758-
759758
});
760759

761760
const responses = await Array.fromAsync(agent.run('test', {selected: element}));

front_end/panels/freestyler/FreestylerAgent.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as UI from '../../ui/legacy/legacy.js';
1212

1313
import {
1414
type ActionResponse,
15+
AgentType,
1516
AiAgent,
1617
type AidaRequestOptions,
1718
type ContextResponse,
@@ -193,6 +194,8 @@ type AgentOptions = {
193194
* instance for a new conversation.
194195
*/
195196
export class FreestylerAgent extends AiAgent<SDK.DOMModel.DOMNode> {
197+
override type = AgentType.FREESTYLER;
198+
196199
readonly preamble = preamble;
197200
readonly clientFeature = Host.AidaClient.ClientFeature.CHROME_FREESTYLER;
198201
get userTier(): string|undefined {

0 commit comments

Comments
 (0)