Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make it possible to dogfood new prompt editor #7094

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions lib/prompt-editor/src/v2/promptInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,11 @@ const prosemirrorActor = fromCallback<ProseMirrorMachineEvent, ProseMirrorMachin
}
})

function doFocus() {
editor.focus()
editor.dispatch(editor.state.tr.scrollIntoView())
}

receive(event => {
switch (event.type) {
case 'focus':
doFocus()
// HACK(sqs): Needed in VS Code webviews to actually get it to focus
// on initial load, for some reason.
setTimeout(doFocus)
editor.focus()
editor.dispatch(editor.state.tr.scrollIntoView())
break
case 'blur':
editor.dom.blur()
Expand Down
6 changes: 6 additions & 0 deletions vscode/src/chat/chat-view/ChatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
DOTCOM_URL,
type DefaultChatCommands,
type EventSource,
FeatureFlag,
type Guardrails,
ModelUsage,
type NLSSearchDynamicFilter,
Expand All @@ -36,6 +37,7 @@ import {
extractContextFromTraceparent,
featureFlagProvider,
firstResultFromOperation,
firstValueFrom,
forceHydration,
graphqlClient,
hydrateAfterPostMessage,
Expand Down Expand Up @@ -528,6 +530,9 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv

private async getConfigForWebview(): Promise<ConfigurationSubsetForWebview & LocalEnv> {
const { configuration, auth } = await currentResolvedConfig()
const experimentalPromptEditorEnabled = await firstValueFrom(
featureFlagProvider.evaluatedFeatureFlag(FeatureFlag.CodyExperimentalPromptEditor)
)
Comment on lines +533 to +535
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const experimentalPromptEditorEnabled = await firstValueFrom(
featureFlagProvider.evaluatedFeatureFlag(FeatureFlag.CodyExperimentalPromptEditor)
)
const experimentalPromptEditorEnabled = configuration.internalUnstable

If this is only for internal / dev to dogfood, maybe we can use the local editor settings instead of a feature flag? We have a (less-known) configuration used for enabling features for internal dogfood that we could re-use if it helps :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would, but how does this work for Cody web? Would be good to dogfood there too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge this as is since we also want to test it in cody web.

const sidebarViewOnly = this.extensionClient.capabilities?.webviewNativeConfig?.view === 'single'
const isEditorViewType = this.webviewPanelOrView?.viewType === 'cody.editorPanel'
const webviewType = isEditorViewType && !sidebarViewOnly ? 'editor' : 'sidebar'
Expand All @@ -545,6 +550,7 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
multipleWebviewsEnabled: !sidebarViewOnly,
internalDebugContext: configuration.internalDebugContext,
allowEndpointChange: configuration.overrideServerEndpoint === undefined,
experimentalPromptEditorEnabled,
}
}

Expand Down
1 change: 1 addition & 0 deletions vscode/src/chat/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export interface ConfigurationSubsetForWebview
multipleWebviewsEnabled?: boolean | undefined | null
endpointHistory?: string[] | undefined | null
allowEndpointChange: boolean
experimentalPromptEditorEnabled: boolean
}

/**
Expand Down
1 change: 1 addition & 0 deletions vscode/webviews/App.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const dummyVSCodeAPI: VSCodeWrapper = {
smartApply: false,
hasEditCapability: false,
allowEndpointChange: true,
experimentalPromptEditorEnabled: false,
},
clientCapabilities: CLIENT_CAPABILITIES_FIXTURE,
authStatus: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
type ChatMessage,
FAST_CHAT_INPUT_TOKEN_BUDGET,
FeatureFlag,
type Model,
ModelTag,
type SerializedPromptEditorState,
Expand Down Expand Up @@ -33,7 +32,6 @@ import { type ClientActionListener, useClientActionListener } from '../../../../
import { promptModeToIntent } from '../../../../../prompts/PromptsTab'
import { useTelemetryRecorder } from '../../../../../utils/telemetry'
import { useConfig } from '../../../../../utils/useConfig'
import { useFeatureFlag } from '../../../../../utils/useFeatureFlags'
import { useLinkOpener } from '../../../../../utils/useLinkOpener'
import { useOmniBox } from '../../../../../utils/useOmniBox'
import styles from './HumanMessageEditor.module.css'
Expand Down Expand Up @@ -102,7 +100,7 @@ export const HumanMessageEditor: FunctionComponent<{
const telemetryRecorder = useTelemetryRecorder()

const editorRef = useRef<PromptEditorRefAPI>(null)
useImperativeHandle(parentEditorRef, (): PromptEditorRefAPI | null => editorRef.current, [])
useImperativeHandle(parentEditorRef, (): PromptEditorRefAPI | null => editorRef.current)

// The only PromptEditor state we really need to track in our own state is whether it's empty.
const [isEmptyEditorValue, setIsEmptyEditorValue] = useState(
Expand All @@ -124,9 +122,6 @@ export const HumanMessageEditor: FunctionComponent<{
? 'emptyEditorValue'
: 'submittable'

// TODO: Finish implementing "current repo not indexed" handling for v2 editor
const experimentalPromptEditorEnabled = useFeatureFlag(FeatureFlag.CodyExperimentalPromptEditor)

const onSubmitClick = useCallback(
(intent?: ChatMessage['intent'], forceSubmit?: boolean): void => {
if (!forceSubmit && submitState === 'emptyEditorValue') {
Expand Down Expand Up @@ -163,7 +158,10 @@ export const HumanMessageEditor: FunctionComponent<{
)

const omniBoxEnabled = useOmniBox()
const { isDotComUser } = useConfig()
const {
isDotComUser,
config: { experimentalPromptEditorEnabled },
} = useConfig()

const onEditorEnterKey = useCallback(
(event: KeyboardEvent | null): void => {
Expand Down Expand Up @@ -425,6 +423,7 @@ export const HumanMessageEditor: FunctionComponent<{
[linkOpener]
)

// TODO: Finish implementing "current repo not indexed" handling for v2 editor
const Editor = experimentalPromptEditorEnabled ? PromptEditorV2 : PromptEditor

return (
Expand Down
Loading