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

Cody Web: Polish cody web Prompts #6135

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
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
Loading