Skip to content

Commit

Permalink
Cody Web: Polish cody web Prompts (#6135)
Browse files Browse the repository at this point in the history
This PR does a few improvements for the prompts library in Cody Web
- First of all, it fixes recent regression in openctx (apparently
internally openctx library tries to find vs code setting file and with
an empty Cody Web Workspace URI it fails in runtime and therefore
doesn't produce any openctx providers such as remote files or
repositories)
- It fixes prompts editor placeholder appearance (we no longer add
whitespaces to the field unconditionally)
- Disables non-runnable in Cody Web prompts (insert or inline commands)
before we render them and these actions did nothing

## Test plan
- Check that you can use openctx mentions in Cody Web (with Cody Web
linked in sg, check ./web contribution doc to see how to link Cody Web
and sg instance)
- Check that you can't click non-chat prompts in Cody Web and see that
they are disabled
- Check that you can see the prompts library placeholder if you don't
have context (Cody Web standalone page case)
  • Loading branch information
vovakulikov authored Nov 18, 2024
1 parent e0b5464 commit ea4523c
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 12 deletions.
7 changes: 6 additions & 1 deletion lib/prompt-editor/src/PromptEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ export const PromptEditor: FunctionComponent<Props> = ({
const nodesToInsert = lexicalNodesForContextItems(items, {
isFromInitialContext: true,
})
nodesToInsert.push($createTextNode(' '))

// Add whitespace after initial context items chips
if (items.length > 0) {
nodesToInsert.push($createTextNode(' '))
}

$setSelection($getRoot().selectStart()) // insert at start
$insertNodes(nodesToInsert)
$selectEnd()
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/src/configuration/clientCapabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { ContextMentionProviderID } from '../mentions/api'
* {@link ClientCapabilitiesWithLegacyFields.agentIDE} that are inferred in an ad-hoc way from the
* environment and aren't self-reported by the client.
*/
export interface ClientCapabilitiesWithLegacyFields {
export interface ClientCapabilitiesWithLegacyFields extends ClientCapabilities {
/**
* The `agentIDE` value, which is the editor that Cody is being used with. If not set, it
* defaults to {@link CodyIDE.VSCode} to match the previous behavior.
Expand Down
6 changes: 3 additions & 3 deletions vscode/webviews/chat/components/WelcomeMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export const WelcomeMessage: FunctionComponent<WelcomeMessageProps> = ({
<PromptList
showSearch={false}
showFirstNItems={4}
appearanceMode="chips-list"
telemetryLocation="PromptsTab"
recommendedOnly={true}
showCommandOrigins={true}
showOnlyPromptInsertableCommands={false}
showPromptLibraryUnsupportedMessage={false}
recommendedOnly={true}
appearanceMode="chips-list"
telemetryLocation="WelcomeAreaPrompts"
onSelect={item => runAction(item, setView)}
/>

Expand Down
11 changes: 11 additions & 0 deletions vscode/webviews/components/promptList/ActionItem.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
color: inherit;
}
}

&[data-disabled="true"] {
/*
In order to override internal cmdk styles for disabled item.
We need to have events over element to have a tooltip over the
element on hover/focus.
*/
pointer-events: auto !important;
background-color: transparent;
cursor: not-allowed;
}
}

.prompt {
Expand Down
12 changes: 12 additions & 0 deletions vscode/webviews/components/promptList/ActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '../../components/shadcn

import { commandRowValue } from './utils'

import { useConfig } from '../../utils/useConfig'
import styles from './ActionItem.module.css'

interface ActionItemProps {
Expand All @@ -35,11 +36,22 @@ interface ActionItemProps {

export const ActionItem: FC<ActionItemProps> = props => {
const { action, className, onSelect } = props
const { clientCapabilities } = useConfig()
const isEditEnabled = clientCapabilities.edit !== 'none'
const isActionEditLike =
action.actionType === 'prompt' ? action.mode !== 'CHAT' : action.mode !== 'ask'
const isDisabled = !isEditEnabled && isActionEditLike

return (
<CommandItem
value={commandRowValue(action)}
disabled={isDisabled}
className={clsx(className, styles.item)}
tooltip={
isDisabled
? 'Edit-like action is not supported in current read-only environment'
: undefined
}
onSelect={onSelect}
>
{action.actionType === 'prompt' ? (
Expand Down
2 changes: 1 addition & 1 deletion vscode/webviews/components/promptList/PromptList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import styles from './PromptList.module.css'
interface PromptListProps {
showSearch: boolean
showFirstNItems?: number
telemetryLocation: 'PromptSelectField' | 'PromptsTab'
telemetryLocation: 'PromptSelectField' | 'PromptsTab' | 'WelcomeAreaPrompts'
showOnlyPromptInsertableCommands?: boolean
showCommandOrigins?: boolean
showPromptLibraryUnsupportedMessage?: boolean
Expand Down
5 changes: 5 additions & 0 deletions web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.13.0
- Fix openctx mention by mocking Cody Web workspace root
- Disable non-runnable prompts in Cody Web
- Fix prompt editor placeholder

## 0.11.0
- Support an external API for Cody Panel functionality (now you can trigger running prompts outside of Cody Web component)

Expand Down
7 changes: 4 additions & 3 deletions web/lib/agent/agent.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface AgentClientOptions {
serverEndpoint: string
accessToken: string
createAgentWorker: () => Worker
workspaceRootUri: string
telemetryClientName?: string
customHeaders?: Record<string, string>
debug?: boolean
Expand All @@ -30,7 +29,6 @@ export async function createAgentClient({
serverEndpoint,
accessToken,
createAgentWorker,
workspaceRootUri,
customHeaders,
telemetryClientName,
debug = true,
Expand Down Expand Up @@ -70,8 +68,11 @@ export async function createAgentClient({
const serverInfo: ServerInfo = await rpc.sendRequest('initialize', {
name: process.env.CODY_WEB_DEMO ? 'standalone-web' : 'web',
version: '0.0.1',
workspaceRootUri,
// Empty root URI leads to openctx configuration resolution failure, any non-empty
// mock value (Cody Web doesn't really use any workspace related features)
workspaceRootUri: 'sourcegraph/cody',
capabilities: {
edit: 'none',
completions: 'none',
webview: 'agentic',
disabledMentionsProviders: [FILE_CONTEXT_MENTION_PROVIDER.id],
Expand Down
2 changes: 1 addition & 1 deletion web/lib/components/CodyWebChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { ChatSkeleton } from './skeleton/ChatSkeleton'
// the cody agent properly (completely mock data)
setDisplayPathEnvInfo({
isWindows: false,
workspaceFolders: [URI.file('/tmp/foo')],
workspaceFolders: [],
})

export interface CodyWebChatProps {
Expand Down
1 change: 0 additions & 1 deletion web/lib/components/use-cody-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export function useCodyWebAgent(input: UseCodyWebAgentInput): UseCodyWebAgentRes
customHeaders,
telemetryClientName,
createAgentWorker,
workspaceRootUri: '',
serverEndpoint: serverEndpoint,
accessToken: accessToken ?? '',
})
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sourcegraph/cody-web",
"version": "0.12.0",
"version": "0.13.0",
"description": "Cody standalone web app",
"license": "Apache-2.0",
"repository": {
Expand Down

0 comments on commit ea4523c

Please sign in to comment.