豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 9d16987

Browse files
jackfranklinDevtools-frontend LUCI CQ
authored andcommitted
AI: make walkthrough CTA differ based on widgets
Fixed: 490348776 Change-Id: Idb36632c66ea633afdf76d130456239c4f1fdb11 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7642854 Commit-Queue: Kateryna Prokopenko <kprokopenko@chromium.org> Auto-Submit: Jack Franklin <jacktfranklin@chromium.org> Reviewed-by: Kateryna Prokopenko <kprokopenko@chromium.org>
1 parent 891ccc1 commit 9d16987

File tree

3 files changed

+76
-7
lines changed

3 files changed

+76
-7
lines changed

front_end/panels/ai_assistance/components/ChatMessage.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import * as Host from '../../../core/host/host.js';
66
import * as Root from '../../../core/root/root.js';
7+
import type * as AIAssistanceModel from '../../../models/ai_assistance/ai_assistance.js';
78
import {assertScreenshot, querySelectorErrorOnMissing, renderElementIntoDOM} from '../../../testing/DOMHelpers.js';
89
import {
910
describeWithEnvironment,
@@ -291,6 +292,58 @@ describeWithEnvironment('ChatMessage', () => {
291292
assert.isNull(target.querySelector('[data-show-walkthrough]'));
292293
});
293294

295+
it('makes the walkthrough button "Show thinking" if there are no widgets', async () => {
296+
const messageNoWidgets: AiAssistance.ChatMessage.ModelChatMessage = {
297+
entity: AiAssistance.ChatMessage.ChatMessageEntity.MODEL,
298+
parts: [{
299+
type: 'step',
300+
step: {
301+
isLoading: false,
302+
title: 'Investigating XYZ',
303+
code: 'console.log("test")',
304+
},
305+
}],
306+
rpcId: 99,
307+
};
308+
const target = renderView({
309+
isLoading: false,
310+
message: messageNoWidgets,
311+
walkthrough: {
312+
...DEFAULT_WALKTHROUGH,
313+
isInlined: false,
314+
}
315+
});
316+
const button = querySelectorErrorOnMissing(target, '[data-show-walkthrough]');
317+
assert.strictEqual(button.innerText, 'Show thinking');
318+
});
319+
320+
it('makes the walkthrough button "Show agent walkthrough" if there are widgets', async () => {
321+
const messageWithWidget: AiAssistance.ChatMessage.ModelChatMessage = {
322+
entity: AiAssistance.ChatMessage.ChatMessageEntity.MODEL,
323+
parts: [{
324+
type: 'step',
325+
step: {
326+
isLoading: false,
327+
title: 'Investigating XYZ',
328+
code: 'console.log("test")',
329+
// Don't need a proper widget for this test
330+
widgets: [{} as AIAssistanceModel.AiAgent.ComputedStyleAiWidget],
331+
},
332+
}],
333+
rpcId: 99,
334+
};
335+
const target = renderView({
336+
isLoading: false,
337+
message: messageWithWidget,
338+
walkthrough: {
339+
...DEFAULT_WALKTHROUGH,
340+
isInlined: false,
341+
}
342+
});
343+
const button = querySelectorErrorOnMissing(target, '[data-show-walkthrough]');
344+
assert.strictEqual(button.innerText, 'Show agent walkthrough');
345+
});
346+
294347
it('renders inline walkthrough when inline', () => {
295348
const target = renderView({
296349
message: stepMessage,

front_end/panels/ai_assistance/components/ChatMessage.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,18 @@ function renderStepDetails({
485485

486486
function renderWalkthroughSidebarButton(
487487
input: ChatMessageViewInput,
488-
lastStep: Step,
488+
steps: Step[],
489489
): Lit.LitTemplate {
490490
const {message, walkthrough} = input;
491-
if (walkthrough.isInlined) {
491+
const lastStep = steps.at(-1);
492+
if (walkthrough.isInlined || !lastStep) {
492493
return Lit.nothing;
493494
}
495+
496+
const hasOneStepWithWidget = steps.some(step => step.widgets?.length);
494497
const title = walkthroughTitle({
495498
isLoading: input.isLoading,
499+
hasWidgets: hasOneStepWithWidget,
496500
lastStep,
497501
});
498502

@@ -537,7 +541,7 @@ function renderWalkthroughUI(input: ChatMessageViewInput, steps: Step[]): Lit.Li
537541
// If the walkthrough is in the sidebar, we render a button into the
538542
// ChatView to open it.
539543
const openWalkThroughSidebarButton =
540-
!input.walkthrough.isInlined ? renderWalkthroughSidebarButton(input, lastStep) : Lit.nothing;
544+
!input.walkthrough.isInlined ? renderWalkthroughSidebarButton(input, steps) : Lit.nothing;
541545

542546
// If there are side-effect steps, and the walkthrough is not open, we render
543547
// those inline so that the user can see them and approve them.

front_end/panels/ai_assistance/components/WalkthroughView.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ const UIStrings = {
2727
*/
2828
title: 'Investigation steps',
2929
/**
30-
* @description Title for the button that shows the thinking process (walkthrough).
30+
* @description Title for the button that shows the walkthrough when there are no widgets in the walkthrough.
3131
*/
3232
showThinking: 'Show thinking',
33+
/**
34+
* @description Title for the button that shows the walkthrough when there are widgets in the walkthrough.
35+
*/
36+
showAgentWalkthrough: 'Show agent walkthrough',
3337
} as const;
3438
const str_ = i18n.i18n.registerUIStrings('panels/ai_assistance/components/WalkthroughView.ts', UIStrings);
3539
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
@@ -46,10 +50,16 @@ export interface ViewInput {
4650

4751
export function walkthroughTitle(input: {
4852
isLoading: boolean,
53+
hasWidgets: boolean,
4954
lastStep: Step,
5055
}): string {
51-
const title = input.isLoading ? titleForStep(input.lastStep) : lockedString(UIStrings.showThinking);
52-
return title;
56+
if (input.isLoading) {
57+
return titleForStep(input.lastStep);
58+
}
59+
if (input.hasWidgets) {
60+
return lockedString(UIStrings.showAgentWalkthrough);
61+
}
62+
return lockedString(UIStrings.showThinking);
5363
}
5464

5565
function renderInlineWalkthrough(input: ViewInput, stepsOutput: Lit.LitTemplate, steps: Step[]): Lit.LitTemplate {
@@ -62,12 +72,14 @@ function renderInlineWalkthrough(input: ViewInput, stepsOutput: Lit.LitTemplate,
6272
input.onToggle((event.target as HTMLDetailsElement).open);
6373
}
6474

75+
const hasWidgets = steps.some(s => s.widgets?.length);
76+
6577
// clang-format off
6678
return html`
6779
<details class="walkthrough-inline" ?open=${input.isExpanded} @toggle=${onToggle}>
6880
<summary>
6981
${input.isLoading ? html`<devtools-spinner></devtools-spinner>` : Lit.nothing}
70-
${walkthroughTitle({isLoading: input.isLoading, lastStep,})}
82+
${walkthroughTitle({isLoading: input.isLoading, lastStep, hasWidgets})}
7183
<devtools-icon name="chevron-down"></devtools-icon>
7284
</summary>
7385
${stepsOutput}

0 commit comments

Comments
 (0)