Skip to content

Commit 39e2a3b

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] Update parser to include the AidaResponse
Moves the function calling parts to parsing and extends the types. Also noticed that the ChildAgents had the same impl as the base so remove it. Bug: 360751542 Change-Id: I859557c2463637391e4fac392d943b8699c234ea Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6074132 Commit-Queue: Alex Rudenko <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]> Reviewed-by: Alex Rudenko <[email protected]> Auto-Submit: Nikolay Vitkov <[email protected]>
1 parent 5532e24 commit 39e2a3b

File tree

7 files changed

+75
-71
lines changed

7 files changed

+75
-71
lines changed

front_end/core/host/AidaClient.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ export interface Content {
3333

3434
export type Part = {
3535
text: string,
36+
}|{
37+
functionCall: {
38+
name: string,
39+
args: Record<string, unknown>,
40+
},
3641
}|{
3742
functionResponse: {
3843
name: string,
@@ -60,12 +65,17 @@ interface BaseFunctionParam {
6065
interface FunctionPrimitiveParams extends BaseFunctionParam {
6166
type: ParametersTypes.BOOLEAN|ParametersTypes.INTEGER|ParametersTypes.STRING|ParametersTypes.BOOLEAN;
6267
}
68+
69+
interface FunctionArrayParam extends BaseFunctionParam {
70+
type: ParametersTypes.ARRAY;
71+
items: FunctionPrimitiveParams[];
72+
}
73+
6374
interface FunctionObjectParam extends BaseFunctionParam {
6475
type: ParametersTypes.OBJECT;
6576
// TODO: this can be also be ObjectParams
66-
properties: {[Key in string]: FunctionPrimitiveParams};
77+
properties: {[Key in string]: FunctionPrimitiveParams|FunctionArrayParam};
6778
}
68-
// TODO: Add FunctionArrayParam
6979

7080
/**
7181
* More about function declaration can be read at

front_end/panels/freestyler/AiAgent.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export abstract class ConversationContext<T> {
156156
}
157157
}
158158

159-
interface AgentFunctionDefinition extends Host.AidaClient.FunctionDeclaration {
159+
export interface AgentFunctionDefinition extends Host.AidaClient.FunctionDeclaration {
160160
method: (...args: any[]) => Record<string, unknown>;
161161
}
162162

@@ -191,7 +191,7 @@ export abstract class AiAgent<T> {
191191
#structuredLog: Array<{
192192
request: Host.AidaClient.AidaRequest,
193193
response: string,
194-
rawResponse?: Host.AidaClient.AidaResponse,
194+
aidaResponse?: Host.AidaClient.AidaResponse,
195195
}> = [];
196196

197197
constructor(opts: AgentOptions) {
@@ -265,34 +265,34 @@ export abstract class AiAgent<T> {
265265
request: Host.AidaClient.AidaRequest,
266266
options?: {signal?: AbortSignal},
267267
): AsyncGenerator<{parsedResponse: ParsedResponse, completed: boolean, rpcId?: number}, void, void> {
268-
let rawResponse: Host.AidaClient.AidaResponse|undefined = undefined;
268+
let aidaResponse: Host.AidaClient.AidaResponse|undefined = undefined;
269269
let response = '';
270270
let rpcId: number|undefined;
271-
for await (rawResponse of this.#aidaClient.fetch(request, options)) {
272-
response = rawResponse.explanation;
273-
rpcId = rawResponse.metadata.rpcGlobalId ?? rpcId;
271+
for await (aidaResponse of this.#aidaClient.fetch(request, options)) {
272+
response = aidaResponse.explanation;
273+
rpcId = aidaResponse.metadata.rpcGlobalId ?? rpcId;
274274

275-
if (rawResponse.functionCall) {
275+
if (aidaResponse.functionCall) {
276276
throw new Error('Function calling not supported yet');
277277
}
278278

279-
const parsedResponse = this.parseResponse(response);
279+
const parsedResponse = this.parseResponse(aidaResponse);
280280
yield {
281281
rpcId,
282282
parsedResponse,
283-
completed: rawResponse.completed,
283+
completed: aidaResponse.completed,
284284
};
285285
}
286286

287287
debugLog({
288288
request,
289-
response: rawResponse,
289+
response: aidaResponse,
290290
});
291291

292292
this.#structuredLog.push({
293293
request: structuredClone(request),
294294
response,
295-
rawResponse,
295+
aidaResponse,
296296
});
297297
localStorage.setItem('freestylerStructuredLog', JSON.stringify(this.#structuredLog));
298298
}
@@ -341,9 +341,12 @@ export abstract class AiAgent<T> {
341341
return query;
342342
}
343343

344-
parseResponse(response: string): ParsedResponse {
344+
parseResponse(response: Host.AidaClient.AidaResponse): ParsedResponse {
345+
if (response.functionCall && response.completed) {
346+
throw new Error('Function calling not supported yet');
347+
}
345348
return {
346-
answer: response,
349+
answer: response.explanation,
347350
};
348351
}
349352

front_end/panels/freestyler/DrJonesFileAgent.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
type ContextDetail,
1616
type ContextResponse,
1717
ConversationContext,
18-
type ParsedResponse,
1918
type RequestOptions,
2019
ResponseType,
2120
} from './AiAgent.js';
@@ -143,12 +142,6 @@ export class DrJonesFileAgent extends AiAgent<Workspace.UISourceCode.UISourceCod
143142
selectedFile ? `# Selected file\n${formatFile(selectedFile.getItem())}\n\n# User request\n\n` : '';
144143
return `${fileEnchantmentQuery}${query}`;
145144
}
146-
147-
override parseResponse(response: string): ParsedResponse {
148-
return {
149-
answer: response,
150-
};
151-
}
152145
}
153146

154147
function createContextDetailsForDrJonesFileAgent(

front_end/panels/freestyler/DrJonesNetworkAgent.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
type ContextDetail,
1717
type ContextResponse,
1818
ConversationContext,
19-
type ParsedResponse,
2019
type RequestOptions,
2120
ResponseType,
2221
} from './AiAgent.js';
@@ -169,12 +168,6 @@ export class DrJonesNetworkAgent extends AiAgent<SDK.NetworkRequest.NetworkReque
169168
'';
170169
return `${networkEnchantmentQuery}${query}`;
171170
}
172-
173-
override parseResponse(response: string): ParsedResponse {
174-
return {
175-
answer: response,
176-
};
177-
}
178171
}
179172

180173
function formatLines(title: string, lines: string[], maxLength: number): string {

front_end/panels/freestyler/DrJonesPerformanceAgent.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
AiAgent,
1414
type ContextResponse,
1515
ConversationContext,
16-
type ParsedResponse,
1716
type RequestOptions,
1817
ResponseType,
1918
} from './AiAgent.js';
@@ -217,10 +216,4 @@ export class DrJonesPerformanceAgent extends AiAgent<TimelineUtils.AICallTree.AI
217216
const perfEnhancementQuery = aiCallTree ? `${treeStr}\n\n# User request\n\n` : '';
218217
return `${perfEnhancementQuery}${query}`;
219218
}
220-
221-
override parseResponse(response: string): ParsedResponse {
222-
return {
223-
answer: response,
224-
};
225-
}
226219
}

0 commit comments

Comments
 (0)