Skip to content

Commit 6c167de

Browse files
author
Connor Clark
committed
[AI] Rename executeJavaScript 'thought' parameter to 'explanation'
Using 'thought' as a parameter name can break parsing within internal tools. Renamed to 'explanation', which matches the name in getStyles. Bug: 469188908, 477493699 Change-Id: I15715abe69cf482a05b0c5994814581fcb60aa67 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7513037 Reviewed-by: Paul Irish <paulirish@chromium.org> Commit-Queue: Paul Irish <paulirish@chromium.org>
1 parent b4a178e commit 6c167de

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

front_end/models/ai_assistance/agents/StylingAgent.snapshot.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Content:
106106
"type": 1,
107107
"description": "JavaScript code snippet to run on the inspected page. Make sure the code is formatted for readability.\n\n# Instructions\n\n* To return data, define a top-level `data` variable and populate it with data you want to get. Only JSON-serializable objects can be assigned to `data`.\n* If you modify styles on an element, ALWAYS call the pre-defined global `async setElementStyles(el: Element, styles: object)` function. This function is an internal mechanism for you and should never be presented as a command/advice to the user.\n* **CRITICAL** Only get styles that might be relevant to the user request.\n* **CRITICAL** Never assume a selector for the elements unless you verified your knowledge.\n* **CRITICAL** Consider that `data` variable from the previous function calls are not available in a new function call.\n\nFor example, the code to change element styles:\n\n```\nawait setElementStyles($0, {\n color: 'blue',\n});\n```\n\nFor example, the code to get overlapping elements:\n\n```\nconst data = {\n overlappingElements: Array.from(document.querySelectorAll('*'))\n .filter(el => {\n const rect = el.getBoundingClientRect();\n const popupRect = $0.getBoundingClientRect();\n return (\n el !== $0 &&\n rect.left < popupRect.right &&\n rect.right > popupRect.left &&\n rect.top < popupRect.bottom &&\n rect.bottom > popupRect.top\n );\n })\n .map(el => ({\n tagName: el.tagName,\n id: el.id,\n className: el.className,\n zIndex: window.getComputedStyle(el)['z-index']\n }))\n};\n```\n"
108108
},
109-
"thought": {
109+
"explanation": {
110110
"type": 1,
111111
"description": "Explain why you want to run this code"
112112
},
@@ -117,7 +117,7 @@ Content:
117117
},
118118
"required": [
119119
"code",
120-
"thought",
120+
"explanation",
121121
"title"
122122
]
123123
}
@@ -155,7 +155,7 @@ Content:
155155
"name": "executeJavaScript",
156156
"args": {
157157
"title": "title2",
158-
"thought": "thought2",
158+
"explanation": "thought2",
159159
"code": "action2"
160160
}
161161
}
@@ -259,7 +259,7 @@ Content:
259259
"name": "executeJavaScript",
260260
"args": {
261261
"code": "const data = {\"test\": \"observation\"}",
262-
"thought": "I am thinking.",
262+
"explanation": "I am thinking.",
263263
"title": "thinking"
264264
}
265265
}
@@ -451,7 +451,7 @@ Content:
451451
"functionCall": {
452452
"name": "executeJavaScript",
453453
"args": {
454-
"thought": "thought 1",
454+
"explanation": "thought 1",
455455
"title": "test",
456456
"code": "console.log('test')"
457457
}
@@ -479,7 +479,7 @@ Content:
479479
"functionCall": {
480480
"name": "executeJavaScript",
481481
"args": {
482-
"thought": "thought 2",
482+
"explanation": "thought 2",
483483
"title": "test",
484484
"code": "console.log('test')"
485485
}
@@ -507,7 +507,7 @@ Content:
507507
"functionCall": {
508508
"name": "executeJavaScript",
509509
"args": {
510-
"thought": "thought 3",
510+
"explanation": "thought 3",
511511
"title": "test",
512512
"code": "console.log('test')"
513513
}

front_end/models/ai_assistance/agents/StylingAgent.test.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ describeWithEnvironment('StylingAgent', function() {
192192
const agent = new StylingAgent.StylingAgent({
193193
aidaClient: mockAidaClient([
194194
[{
195-
functionCalls: [{name: 'executeJavaScript', args: {title: 'title2', thought: 'thought2', code: 'action2'}}],
195+
functionCalls:
196+
[{name: 'executeJavaScript', args: {title: 'title2', explanation: 'thought2', code: 'action2'}}],
196197
explanation: '',
197198
}],
198199
[{explanation: 'answer2'}]
@@ -403,7 +404,7 @@ describeWithEnvironment('StylingAgent', function() {
403404
[{
404405
functionCalls: [{
405406
name: 'executeJavaScript',
406-
args: {code: 'const data = {"test": "observation"}', thought: 'I am thinking.', title: 'thinking'},
407+
args: {code: 'const data = {"test": "observation"}', explanation: 'I am thinking.', title: 'thinking'},
407408
}],
408409
explanation: '',
409410
}],
@@ -528,7 +529,7 @@ describeWithEnvironment('StylingAgent', function() {
528529
[{
529530
functionCalls: [{
530531
name: 'executeJavaScript',
531-
args: {thought: 'I am thinking.', code: 'console.log(\'hello\');'},
532+
args: {explanation: 'I am thinking.', code: 'console.log(\'hello\');'},
532533
}],
533534
explanation: 'this is my text before the actual answer',
534535
}],
@@ -554,21 +555,21 @@ describeWithEnvironment('StylingAgent', function() {
554555
[{
555556
functionCalls: [{
556557
name: 'executeJavaScript',
557-
args: {thought: 'thought 1', title: 'test', code: 'console.log(\'test\')'},
558+
args: {explanation: 'thought 1', title: 'test', code: 'console.log(\'test\')'},
558559
}],
559560
explanation: '',
560561
}],
561562
[{
562563
functionCalls: [{
563564
name: 'executeJavaScript',
564-
args: {thought: 'thought 2', title: 'test', code: 'console.log(\'test\')'},
565+
args: {explanation: 'thought 2', title: 'test', code: 'console.log(\'test\')'},
565566
}],
566567
explanation: '',
567568
}],
568569
[{
569570
functionCalls: [{
570571
name: 'executeJavaScript',
571-
args: {thought: 'thought 3', title: 'test', code: 'console.log(\'test\')'},
572+
args: {explanation: 'thought 3', title: 'test', code: 'console.log(\'test\')'},
572573
}],
573574
explanation: '',
574575
}],
@@ -592,21 +593,21 @@ describeWithEnvironment('StylingAgent', function() {
592593
[{
593594
functionCalls: [{
594595
name: 'executeJavaScript',
595-
args: {thought: 'thought 1', title: 'test', code: 'console.log(\'test\')'},
596+
args: {explanation: 'thought 1', title: 'test', code: 'console.log(\'test\')'},
596597
}],
597598
explanation: '',
598599
}],
599600
[{
600601
functionCalls: [{
601602
name: 'executeJavaScript',
602-
args: {thought: 'thought 2', title: 'test', code: 'console.log(\'test\')'},
603+
args: {explanation: 'thought 2', title: 'test', code: 'console.log(\'test\')'},
603604
}],
604605
explanation: '',
605606
}],
606607
[{
607608
functionCalls: [{
608609
name: 'executeJavaScript',
609-
args: {thought: 'thought 3', title: 'test', code: 'console.log(\'test\')'},
610+
args: {explanation: 'thought 3', title: 'test', code: 'console.log(\'test\')'},
610611
}],
611612
explanation: '',
612613
}],

front_end/models/ai_assistance/agents/StylingAgent.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export class StylingAgent extends AiAgent<SDK.DOMModel.DOMNode> {
330330

331331
this.declareFunction<{
332332
title: string,
333-
thought: string,
333+
explanation: string,
334334
code: string,
335335
}>('executeJavaScript', {
336336
description:
@@ -388,7 +388,7 @@ const data = {
388388
\`\`\`
389389
`,
390390
},
391-
thought: {
391+
explanation: {
392392
type: Host.AidaClient.ParametersTypes.STRING,
393393
description: 'Explain why you want to run this code',
394394
},
@@ -397,12 +397,12 @@ const data = {
397397
description: 'Provide a summary of what the code does. For example, "Checking related element styles".',
398398
},
399399
},
400-
required: ['code', 'thought', 'title']
400+
required: ['code', 'explanation', 'title']
401401
},
402402
displayInfoFromArgs: params => {
403403
return {
404404
title: params.title,
405-
thought: params.thought,
405+
thought: params.explanation,
406406
action: params.code,
407407
};
408408
},

0 commit comments

Comments
 (0)