Skip to content

Commit c21258e

Browse files
Allow switching AI mode
1 parent 25376ff commit c21258e

File tree

15 files changed

+279
-218
lines changed

15 files changed

+279
-218
lines changed

newIDE/app/src/AiGeneration/AiRequestChat/index.js

Lines changed: 176 additions & 162 deletions
Large diffs are not rendered by default.

newIDE/app/src/AiGeneration/AskAiEditorContainer.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ type Props = {|
131131
onWillInstallExtension: (extensionNames: Array<string>) => void,
132132
onExtensionInstalled: (extensionNames: Array<string>) => void,
133133
onOpenAskAi: ({|
134-
mode: 'chat' | 'agent',
135134
aiRequestId: string | null,
136135
paneIdentifier: 'left' | 'center' | 'right' | null,
137136
|}) => void,
@@ -164,7 +163,6 @@ export type AskAiEditorInterface = {|
164163
) => void,
165164
startOrOpenChat: (
166165
?{|
167-
mode: 'chat' | 'agent',
168166
aiRequestId: string | null,
169167
|}
170168
) => void,
@@ -255,7 +253,6 @@ export const AskAiEditor = React.memo<Props>(
255253
const {
256254
selectedAiRequest,
257255
selectedAiRequestId,
258-
selectedAiRequestMode,
259256
setAiState,
260257
} = useAiRequestState({ project });
261258
const upToDateSelectedAiRequestId = useStableUpToDateRef(
@@ -430,10 +427,7 @@ export const AskAiEditor = React.memo<Props>(
430427
fileMetadata,
431428
storageProviderName,
432429
mode,
433-
toolsVersion:
434-
mode === 'agent'
435-
? AI_AGENT_TOOLS_VERSION
436-
: AI_CHAT_TOOLS_VERSION,
430+
toolsVersion: AI_CHAT_TOOLS_VERSION,
437431
aiConfiguration: {
438432
presetId: aiConfigurationPresetId,
439433
},
@@ -448,7 +442,6 @@ export const AskAiEditor = React.memo<Props>(
448442
if (!upToDateSelectedAiRequestId.current) {
449443
setAiState({
450444
aiRequestId: aiRequest.id,
451-
mode: selectedAiRequestMode,
452445
});
453446
}
454447

@@ -498,7 +491,6 @@ export const AskAiEditor = React.memo<Props>(
498491
quota,
499492
selectedAiRequestId,
500493
setLastSendError,
501-
selectedAiRequestMode,
502494
setAiState,
503495
setSendingAiRequest,
504496
upToDateSelectedAiRequestId,
@@ -515,11 +507,13 @@ export const AskAiEditor = React.memo<Props>(
515507
createdSceneNames,
516508
createdProject,
517509
editorFunctionCallResults,
510+
mode,
518511
}: {|
519512
userMessage: string,
520513
createdSceneNames?: Array<string>,
521514
createdProject?: ?gdProject,
522515
editorFunctionCallResults: Array<EditorFunctionCallResult>,
516+
mode?: 'chat' | 'agent',
523517
|}) => {
524518
if (
525519
!profile ||
@@ -621,6 +615,13 @@ export const AskAiEditor = React.memo<Props>(
621615
payWithCredits,
622616
userMessage,
623617
paused,
618+
mode,
619+
toolsVersion:
620+
mode === 'agent'
621+
? AI_AGENT_TOOLS_VERSION
622+
: mode === 'chat'
623+
? AI_CHAT_TOOLS_VERSION
624+
: undefined,
624625
})
625626
);
626627
updateAiRequest(aiRequest.id, aiRequest);
@@ -746,7 +747,6 @@ export const AskAiEditor = React.memo<Props>(
746747
if (!profile) {
747748
setAiState({
748749
aiRequestId: null,
749-
mode: selectedAiRequestMode,
750750
});
751751
return;
752752
}
@@ -765,7 +765,6 @@ export const AskAiEditor = React.memo<Props>(
765765
const onStartOrOpenChat = React.useCallback(
766766
(
767767
options: ?{|
768-
mode: 'chat' | 'agent',
769768
aiRequestId: string | null,
770769
|}
771770
) => {
@@ -784,13 +783,11 @@ export const AskAiEditor = React.memo<Props>(
784783
);
785784
const onStartNewChat = React.useCallback(
786785
() => {
787-
// Keep mode, but reset aiRequestId to start a new chat.
788786
onStartOrOpenChat({
789-
mode: selectedAiRequestMode,
790787
aiRequestId: null,
791788
});
792789
},
793-
[onStartOrOpenChat, selectedAiRequestMode]
790+
[onStartOrOpenChat]
794791
);
795792

796793
const updateToolbar = React.useCallback(
@@ -864,11 +861,17 @@ export const AskAiEditor = React.memo<Props>(
864861
project={project}
865862
ref={aiRequestChatRef}
866863
aiRequest={selectedAiRequest}
867-
aiRequestMode={selectedAiRequestMode}
868864
onStartNewAiRequest={startNewAiRequest}
869-
onSendUserMessage={(userMessage: string) =>
865+
onSendUserMessage={({
866+
userMessage,
867+
mode,
868+
}: {|
869+
userMessage: string,
870+
mode: 'chat' | 'agent',
871+
|}) =>
870872
onSendMessage({
871873
userMessage,
874+
mode,
872875
editorFunctionCallResults: selectedAiRequest
873876
? getEditorFunctionCallResults(selectedAiRequest.id) || []
874877
: [],
@@ -923,7 +926,6 @@ export const AskAiEditor = React.memo<Props>(
923926
updateAiRequest(aiRequest.id, aiRequest);
924927
setAiState({
925928
aiRequestId: aiRequest.id,
926-
mode: aiRequest.mode || selectedAiRequestMode,
927929
});
928930
refreshAiRequest(aiRequest.id);
929931
onCloseHistory();

newIDE/app/src/AiGeneration/AskAiStandAloneForm.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import {
4242
useProcessFunctionCalls,
4343
type NewAiRequestOptions,
4444
AI_AGENT_TOOLS_VERSION,
45-
AI_CHAT_TOOLS_VERSION,
4645
} from './Utils';
4746
import { LineStackLayout } from '../UI/Layout';
4847
import RobotIcon from '../ProjectCreation/RobotIcon';
@@ -288,10 +287,7 @@ export const AskAiStandAloneForm = ({
288287
fileMetadata: null, // No file metadata when starting from the standalone form.
289288
storageProviderName,
290289
mode: aiRequestModeForForm,
291-
toolsVersion:
292-
aiRequestModeForForm === 'agent'
293-
? AI_AGENT_TOOLS_VERSION
294-
: AI_CHAT_TOOLS_VERSION,
290+
toolsVersion: AI_AGENT_TOOLS_VERSION,
295291
aiConfiguration: {
296292
presetId: aiConfigurationPresetId,
297293
},
@@ -309,7 +305,6 @@ export const AskAiStandAloneForm = ({
309305
// so that the editor is in sync, when we'll open it.
310306
setAiState({
311307
aiRequestId: aiRequest.id,
312-
mode: aiRequestModeForForm,
313308
});
314309
}
315310

@@ -453,6 +448,8 @@ export const AskAiStandAloneForm = ({
453448
payWithCredits: false,
454449
userMessage: '', // No user message when sending only function call outputs.
455450
paused,
451+
mode: aiRequestModeForForm,
452+
toolsVersion: AI_AGENT_TOOLS_VERSION,
456453
})
457454
);
458455
updateAiRequest(aiRequest.id, aiRequest);
@@ -582,11 +579,17 @@ export const AskAiStandAloneForm = ({
582579
project={project}
583580
ref={aiRequestChatRef}
584581
aiRequest={aiRequestForForm}
585-
aiRequestMode={aiRequestModeForForm}
586582
onStartNewAiRequest={startNewAiRequest}
587-
onSendUserMessage={(userMessage: string) =>
583+
onSendUserMessage={({
584+
userMessage,
585+
mode,
586+
}: {|
587+
userMessage: string,
588+
mode: 'chat' | 'agent',
589+
|}) =>
588590
onSendMessage({
589591
userMessage,
592+
// Mode is forced to agent in standalone.
590593
editorFunctionCallResults: aiRequestForForm
591594
? getEditorFunctionCallResults(aiRequestForForm.id) || []
592595
: [],

newIDE/app/src/AiGeneration/Utils.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ export const useAiRequestState = ({ project }: {| project: ?gdProject |}) => {
259259

260260
const { values, setAiState } = React.useContext(PreferencesContext);
261261
const selectedAiRequestId = values.aiState.aiRequestId;
262-
const selectedAiRequestMode = values.aiState.mode;
263262

264263
const selectedAiRequest =
265264
(selectedAiRequestId && aiRequests[selectedAiRequestId]) || null;
@@ -442,11 +441,10 @@ export const useAiRequestState = ({ project }: {| project: ?gdProject |}) => {
442441
if (!profile) {
443442
setAiState({
444443
aiRequestId: null,
445-
mode: selectedAiRequestMode,
446444
});
447445
}
448446
},
449-
[profile, setAiState, selectedAiRequestMode]
447+
[profile, setAiState]
450448
);
451449

452450
React.useEffect(
@@ -457,24 +455,21 @@ export const useAiRequestState = ({ project }: {| project: ?gdProject |}) => {
457455
if (selectedAiRequestId && !selectedAiRequest) {
458456
setAiState({
459457
aiRequestId: null,
460-
mode: selectedAiRequestMode,
461458
});
462459
}
463460
},
464-
[selectedAiRequestId, selectedAiRequestMode, selectedAiRequest, setAiState]
461+
[selectedAiRequestId, selectedAiRequest, setAiState]
465462
);
466463

467464
return {
468465
selectedAiRequest,
469466
selectedAiRequestId,
470-
selectedAiRequestMode,
471467
setAiState,
472468
};
473469
};
474470

475471
// If any of those props is undefined, the previous value is kept.
476472
export type OpenAskAiOptions = {|
477-
mode?: 'chat' | 'agent',
478473
aiRequestId?: string | null, // If null, a new request will be created.
479474
paneIdentifier?: 'left' | 'center' | 'right',
480475
continueProcessingFunctionCallsOnMount?: boolean,

newIDE/app/src/MainFrame/EditorContainers/HomePage/LearnSection/CoursePage.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ const CoursePage = ({
457457
label={<Trans>Ask the AI</Trans>}
458458
onClick={() =>
459459
onOpenAskAi({
460-
mode: 'chat',
461460
aiRequestId: null,
462461
})
463462
}

newIDE/app/src/MainFrame/EditorContainers/HomePage/LearnSection/MainPage.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ const MainPage = ({
406406
rightIcon={<ArrowRight />}
407407
onClick={() =>
408408
onOpenAskAi({
409-
mode: 'chat',
410409
aiRequestId: null,
411410
})
412411
}

newIDE/app/src/MainFrame/Preferences/PreferencesContext.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export type PreferencesValues = {|
228228
gamesDashboardOrderBy: GamesDashboardOrderBy,
229229
takeScreenshotOnPreview: boolean,
230230
showAiAskButtonInTitleBar: boolean,
231-
aiState: {| aiRequestId: string | null, mode: 'chat' | 'agent' |},
231+
aiState: {| aiRequestId: string | null |},
232232
automaticallyUseCreditsForAiRequests: boolean,
233233
hasSeenInGameEditorWarning: boolean,
234234
|};
@@ -340,7 +340,6 @@ export type Preferences = {|
340340
setShowAiAskButtonInTitleBar: (enabled: boolean) => void,
341341
setAiState: ({|
342342
aiRequestId: string | null,
343-
mode: 'chat' | 'agent',
344343
|}) => void,
345344
setAutomaticallyUseCreditsForAiRequests: (enabled: boolean) => void,
346345
setHasSeenInGameEditorWarning: (enabled: boolean) => void,
@@ -403,7 +402,7 @@ export const initialPreferences = {
403402
gamesDashboardOrderBy: 'lastModifiedAt',
404403
takeScreenshotOnPreview: true,
405404
showAiAskButtonInTitleBar: true,
406-
aiState: { aiRequestId: null, mode: 'agent' },
405+
aiState: { aiRequestId: null },
407406
automaticallyUseCreditsForAiRequests: false,
408407
hasSeenInGameEditorWarning: false,
409408
},
@@ -483,13 +482,7 @@ export const initialPreferences = {
483482
) => {},
484483
setTakeScreenshotOnPreview: (enabled: boolean) => {},
485484
setShowAiAskButtonInTitleBar: (enabled: boolean) => {},
486-
setAiState: ({
487-
aiRequestId,
488-
mode,
489-
}: {|
490-
aiRequestId: string | null,
491-
mode: 'chat' | 'agent',
492-
|}) => {},
485+
setAiState: ({ aiRequestId }: {| aiRequestId: string | null |}) => {},
493486
setAutomaticallyUseCreditsForAiRequests: (enabled: boolean) => {},
494487
setHasSeenInGameEditorWarning: (enabled: boolean) => {},
495488
};

newIDE/app/src/MainFrame/Preferences/PreferencesProvider.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,10 +1092,7 @@ export default class PreferencesProvider extends React.Component<Props, State> {
10921092
);
10931093
}
10941094

1095-
_setAiState(newValue: {|
1096-
aiRequestId: string | null,
1097-
mode: 'chat' | 'agent',
1098-
|}) {
1095+
_setAiState(newValue: {| aiRequestId: string | null |}) {
10991096
this.setState(
11001097
state => ({
11011098
values: {

newIDE/app/src/MainFrame/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,6 @@ const MainFrame = (props: Props) => {
866866
const openAskAi = React.useCallback(
867867
(options: ?OpenAskAiOptions) => {
868868
const {
869-
mode,
870869
aiRequestId,
871870
paneIdentifier,
872871
continueProcessingFunctionCallsOnMount,
@@ -914,11 +913,7 @@ const MainFrame = (props: Props) => {
914913
}).then(state => {
915914
// Wait for the state to be updated before starting/opening the chat,
916915
// as the editor needs to be mounted.
917-
const params =
918-
// Both need to be defined.
919-
mode === undefined || aiRequestId === undefined
920-
? undefined
921-
: { mode, aiRequestId };
916+
const params = aiRequestId === undefined ? undefined : { aiRequestId };
922917
const openedEditor = getOpenedAskAiEditor(state.editorTabs);
923918
if (!openedEditor) {
924919
console.error(

newIDE/app/src/UI/CompactSelectField/CompactSelectField.module.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
align-items: center;
44
min-width: 0px;
55
}
6+
.container.rounded {
7+
border-radius: 24px;
8+
}
69

710
.compactSelectField {
811
border-radius: 4px;
@@ -79,6 +82,10 @@
7982
min-width: 0px;
8083
}
8184

85+
.compactSelectField.withOptionIcon select {
86+
padding-left: 30px;
87+
}
88+
8289
.compactSelectField select::placeholder {
8390
color: var(--theme-text-field-placeholder-color);
8491
}
@@ -146,3 +153,18 @@ svg.leftIcon {
146153
.container:not(.disabled):focus-within .leftIcon {
147154
color: var(--theme-text-default-color);
148155
}
156+
157+
.optionIconContainer {
158+
pointer-events: none;
159+
position: absolute;
160+
top: 2px;
161+
left: 4px;
162+
display: flex;
163+
align-items: center;
164+
}
165+
svg.optionIcon {
166+
font-size: 18px;
167+
}
168+
.container.disabled .optionIcon {
169+
color: var(--theme-text-field-disabled-color);
170+
}

0 commit comments

Comments
 (0)